feat: chat integration, tenant admin spec, backend chat service, miniprogram updates, DEMO moved to tmp, XCX-TEST removed, migrations & docs

This commit is contained in:
Neo
2026-03-20 09:02:10 +08:00
parent 3d2e5f8165
commit beb88d5bea
388 changed files with 6436 additions and 25458 deletions

View File

@@ -0,0 +1,49 @@
/**
* 对话工具函数
* simulateStreamOutput 为异步函数(使用 setTimeout
* simulateStreamOutputSync 为同步纯函数(用于测试)
*/
/**
* 模拟流式输出:逐字追加调用 callback
* @param text 完整文本
* @param callback 每次追加后的回调,参数为当前已输出的子串
* @returns Promise输出完成后 resolve
*/
export function simulateStreamOutput(
text: string,
callback: (partial: string) => void
): Promise<void> {
return new Promise((resolve) => {
if (text.length === 0) {
callback('')
resolve()
return
}
let index = 0
const tick = () => {
index++
callback(text.slice(0, index))
if (index < text.length) {
setTimeout(tick, 50)
} else {
resolve()
}
}
setTimeout(tick, 50)
})
}
/**
* 同步版流式输出:返回逐字追加的子串数组(用于测试)
* @param text 完整文本
* @returns 逐步增长的子串数组,如 "abc" → ["a", "ab", "abc"]
*/
export function simulateStreamOutputSync(text: string): string[] {
const result: string[] = []
for (let i = 1; i <= text.length; i++) {
result.push(text.slice(0, i))
}
return result
}