Jelajahi Sumber

feat: 采访保存支持 agentSnapshot 持久化

Mochocyang 3 bulan lalu
induk
melakukan
032993c60f

+ 4 - 0
src/components/novel/story-simulation/story-simulation-view.tsx

@@ -559,9 +559,13 @@ export function StorySimulationView() {
         agentName: activeChatAgent.name,
         messages: agentChatMessages,
       }
+      const agentSnapshot = lastSimulationStateRef.current && lastAgentsRef.current.length > 0
+        ? serializeSimulationState(lastSimulationStateRef.current, lastAgentsRef.current)
+        : undefined
       await saveInterview(projectPath, session, {
         frameworkId: currentFramework?.id,
         frameworkTitle: currentFramework?.title,
+        agentSnapshot,
       })
       setError(`采访对话已保存(${agentChatMessages.length}条消息)`)
       setTimeout(() => setError(null), 3000)

+ 5 - 0
src/lib/novel/story-simulation/interview-store.ts

@@ -9,6 +9,7 @@ import { createDirectory, writeFileAtomic, listDirectory, deleteFile, readFile }
 import { normalizePath } from "@/lib/path-utils"
 import type { FileNode } from "@/types/wiki"
 import type { AgentChatSession } from "./types"
+import type { SerializedSimulationSnapshot } from "./simulation-serializer"
 
 const INTERVIEWS_DIR = ".qmai/simulations/interviews"
 
@@ -28,6 +29,8 @@ export interface SavedInterview {
   createdAt: string
   updatedAt: string
   session: AgentChatSession
+  /** 推演时的 agent 快照,用于继续对话时恢复角色状态 */
+  agentSnapshot?: SerializedSimulationSnapshot
 }
 
 /**
@@ -41,6 +44,7 @@ export async function saveInterview(
     frameworkId?: string
     frameworkTitle?: string
     existingId?: string
+    agentSnapshot?: SerializedSimulationSnapshot
   },
 ): Promise<string> {
   const dir = interviewsDir(projectPath)
@@ -56,6 +60,7 @@ export async function saveInterview(
     createdAt: now,
     updatedAt: now,
     session,
+    agentSnapshot: options?.agentSnapshot,
   }
 
   // 如果已存在,保留原始 createdAt