chore: v1 整理 — 清理历史文件、DDL 合并、文档归档
- 清理 1155 个已删除的历史文件(废弃 prompt_logs、tmp、旧 ops 脚本) - export/ 数据文件从 git 移除(已在 .gitignore) - demo-miniprogram 从 tmp/ 移入 apps/,添加 CLAUDE.md 注解 - DDL 合并:完整 schema 定义填充到 db/*/schemas/(从 docs/database/ddl/ 复制) - 39 个 v1 迁移脚本归档到 db/_archived/migrations_v1_merged/ - 4 个迁移变更类 BD_Manual 文档归档到 docs/database/_archived/ - .gitignore 补充 .vite/ 和 apps/*.zip - settings.json 添加 effortLevel 默认配置 - scripts/ops/ 新增运维脚本入库 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
49
apps/demo-miniprogram/miniprogram/utils/chat.ts
Normal file
49
apps/demo-miniprogram/miniprogram/utils/chat.ts
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user