修改特殊注码和打注一体的data格式
This commit is contained in:
+80
-3
@@ -35,10 +35,21 @@ interface ChatStoreState {
|
||||
selectedStrategy: StrategyInstance | null
|
||||
/** 是否已经取过一次策略列表(只取一次的守卫) */
|
||||
policyContextLoaded: boolean
|
||||
/**
|
||||
* 恢复会话时重建 load_skill 工具对用的正文缓存(内存,**不落盘** ——
|
||||
* 技能正文约 6 千字,落盘会撑爆 localStorage)。键 = 技能名。
|
||||
*/
|
||||
skillTextCache: Record<string, string>
|
||||
}
|
||||
|
||||
const TASK_KINDS: TaskKind[] = ['explain', 'modify', 'generate']
|
||||
|
||||
/** 恢复会话时按技能名取正文的重试次数上限(每个页面生命周期);用完不再打 native。 */
|
||||
const SKILL_TEXT_MAX_ATTEMPTS = 3
|
||||
// 模块级而非 state:Promise / Map 不该被 pinia 响应式包装
|
||||
let skillHydrationPromise: Promise<void> | null = null
|
||||
const skillHydrationAttempts = new Map<string, number>()
|
||||
|
||||
/** 只认 3 个合法值;不合法(含旧档位值)⇒ undefined ⇒ 会话不带 taskKind 字段。 */
|
||||
function normalizeTaskKind(value: unknown): TaskKind | undefined {
|
||||
return TASK_KINDS.includes(value as TaskKind) ? (value as TaskKind) : undefined
|
||||
@@ -210,6 +221,7 @@ export const useChatStore = defineStore('chat', {
|
||||
strategyCacheByCategory: { '打法策略': [], '注码策略': [] },
|
||||
selectedStrategy: null,
|
||||
policyContextLoaded: false,
|
||||
skillTextCache: {},
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
@@ -369,6 +381,67 @@ export const useChatStore = defineStore('chat', {
|
||||
if (!targetSession) return
|
||||
targetSession.loopMessages = ledger
|
||||
},
|
||||
/**
|
||||
* 写入会话级「已成功加载过哪些技能」的锚点(落盘)。传空数组 = 清空。
|
||||
* `loadedSkills` 是落盘字段(persistSessions 的 `...session` 展开自然带上),
|
||||
* 这里必须触发一次 localStorage 写入。
|
||||
*/
|
||||
setSessionLoadedSkills(
|
||||
sessionId: string,
|
||||
list: Array<{ name: string; callId: string; anchorUserSeq: number }>,
|
||||
): void {
|
||||
const targetSession = this.sessions.find((session) => session.id === sessionId)
|
||||
if (!targetSession) return
|
||||
targetSession.loadedSkills = list.length ? list : undefined
|
||||
this.persistSessions()
|
||||
},
|
||||
/** 缓存技能正文(内存,不落盘)。空串忽略。 */
|
||||
cacheSkillText(name: string, text: string): void {
|
||||
const trimmed = name.trim()
|
||||
if (!trimmed || !text) return
|
||||
this.skillTextCache[trimmed] = text
|
||||
},
|
||||
/** 仍缺正文、且未超过重试上限的技能名(跨会话并集、去重)。 */
|
||||
missingRestoredSkillNames(): string[] {
|
||||
const names = new Set<string>()
|
||||
for (const session of this.sessions) {
|
||||
for (const entry of session.loadedSkills ?? []) {
|
||||
if (!entry?.name) continue
|
||||
if (this.skillTextCache[entry.name]) continue
|
||||
if ((skillHydrationAttempts.get(entry.name) ?? 0) >= SKILL_TEXT_MAX_ATTEMPTS) continue
|
||||
names.add(entry.name)
|
||||
}
|
||||
}
|
||||
return Array.from(names)
|
||||
},
|
||||
/**
|
||||
* 预热恢复会话所需的技能正文(幂等:并发调用共享同一个 in-flight promise)。
|
||||
* 失败不抛、不阻断 —— 缺正文的 pair 拼接时跳过,模型会自己重新 load。
|
||||
*/
|
||||
async ensureRestoredSkills(): Promise<void> {
|
||||
const missing = this.missingRestoredSkillNames()
|
||||
if (!missing.length) return
|
||||
if (skillHydrationPromise) return skillHydrationPromise
|
||||
skillHydrationPromise = (async () => {
|
||||
const results = await Promise.allSettled(
|
||||
missing.map(async (name) => {
|
||||
const text = await getAiBridge().loadSkill(name)
|
||||
this.cacheSkillText(name, text)
|
||||
}),
|
||||
)
|
||||
for (let index = 0; index < results.length; index += 1) {
|
||||
if (results[index].status === 'rejected') {
|
||||
const name = missing[index]
|
||||
skillHydrationAttempts.set(name, (skillHydrationAttempts.get(name) ?? 0) + 1)
|
||||
}
|
||||
}
|
||||
})()
|
||||
try {
|
||||
await skillHydrationPromise
|
||||
} finally {
|
||||
skillHydrationPromise = null
|
||||
}
|
||||
},
|
||||
switchSession(sessionId: string) {
|
||||
this.activeSessionId = sessionId
|
||||
// 切会话 ⇒ 全局选中恢复成新会话落盘的选择(不恢复的话上一个会话的实例会漏进来)
|
||||
@@ -403,6 +476,8 @@ export const useChatStore = defineStore('chat', {
|
||||
session.messages = []
|
||||
// 消息清了 ⇒ 账本里还是旧对话的序列,留着会对不上 ⇒ 一并清空
|
||||
session.loopMessages = undefined
|
||||
// 消息清了 ⇒ 锚点(「哪个技能在哪个 user 轮之后」)也就没意义 ⇒ 一并清掉
|
||||
session.loadedSkills = undefined
|
||||
// 消息清了 ⇒ 没有上下文可言 ⇒ 已提交的技能声明一并清掉(瞬态,与 savePhase 同生命周期)
|
||||
session.logicSkillName = undefined
|
||||
// 消息清了 ⇒ 历史里的 [任务选项] 行也没了 ⇒ 拼接签名一并清零(下一条按首轮重拼)
|
||||
@@ -601,7 +676,8 @@ export const useChatStore = defineStore('chat', {
|
||||
/**
|
||||
* 置当前会话的保存流程状态(按钮 + 占位行的唯一来源)。
|
||||
* - 由 loop 正常收尾触发(ChatView 的 onLogicComplete 回调):idle → ready
|
||||
* - 由 ChatView.handleSaveStrategy 驱动:ready → generating → saving → idle / ready
|
||||
* - 由 ChatView.handleSaveStrategy 驱动:ready → generating(① 要逻辑 +
|
||||
* ② 交付物生成与审查)→ saving(applyStrategy)→ idle / ready
|
||||
* 幂等:已 ready / 进行中时再 markLogicComplete 不重改。
|
||||
* ⚠️ 已提交的技能声明由 setLogicSkillName 单独维护(loop 返回值触发),这里不碰。
|
||||
* 改造-05/D5:纯信号,无参数 —— 保存落点在 handleSaveStrategy 执行时按当前选择判定。
|
||||
@@ -653,8 +729,9 @@ export const useChatStore = defineStore('chat', {
|
||||
* 切到保存流程的某个阶段(瞬态,不落盘)。按钮显隐 / 禁用 / 文案与占位行
|
||||
* 全部由它派生,调用方只表达「现在到哪一步了」:
|
||||
* - 'ready':可保存(失败 / 用户取消的收场)
|
||||
* - 'generating':① 要逻辑子请求开始(ChatView.handleSaveStrategy)
|
||||
* - 'saving':② 交付物 + applyStrategy 开始
|
||||
* - 'generating':① 要逻辑子请求开始,② 交付物生成 + 审查也在此阶段
|
||||
* (由 runSaveStrategyFlow 的 onPhase 回调驱动)
|
||||
* - 'saving':applyStrategy 开始(含 native 命名对话框)
|
||||
* - 'idle':按钮与占位消失(保存成功 / 用户切了技能类)
|
||||
*/
|
||||
setSavePhase(phase: SavePhase): void {
|
||||
|
||||
Reference in New Issue
Block a user