refactor: AI session managed server-side, sessionId returned from API

This commit is contained in:
2026-06-15 11:23:14 +08:00
parent 33357650c7
commit 0aac429908
4 changed files with 42 additions and 25 deletions

View File

@@ -11,7 +11,7 @@ export const useEditorStore = defineStore('editor', () => {
const deepseekKey = ref(localStorage.getItem('deepseek_key') || '')
const showAIPanel = ref(false)
const aiResult = ref('')
const aiSessionId = ref(localStorage.getItem('editor_ai_session') || '')
const aiSessionId = ref('')
const selectedScene = computed(() => {
if (!selectedNodeId.value) return null
@@ -138,17 +138,9 @@ export const useEditorStore = defineStore('editor', () => {
function setDeepseekKey(k: string) { deepseekKey.value = k; localStorage.setItem('deepseek_key', k) }
function ensureAISession() {
if (!aiSessionId.value) {
aiSessionId.value = crypto.randomUUID()
localStorage.setItem('editor_ai_session', aiSessionId.value)
}
}
function setAISessionId(id: string) { aiSessionId.value = id; localStorage.setItem('editor_ai_session', id) }
function newAISession() {
aiSessionId.value = crypto.randomUUID()
localStorage.setItem('editor_ai_session', aiSessionId.value)
}
function clearAISession() { aiSessionId.value = ''; localStorage.removeItem('editor_ai_session') }
function setAIResult(r: string) { aiResult.value = r }
@@ -167,6 +159,6 @@ export const useEditorStore = defineStore('editor', () => {
deepseekKey, showAIPanel, aiResult, aiSessionId,
markDirty, loadJSON, exportJSON, addScene, deleteScene,
updateScene, addChoice, updateChoice, deleteChoice, generateId,
setSourcePath, setDeepseekKey, ensureAISession, newAISession, setAIResult, autoSave,
setSourcePath, setDeepseekKey, setAISessionId, clearAISession, setAIResult, autoSave,
}
})