From 8ae4af4e43ec7699c8e0f2572b5087f2bdbca03b Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 6 Jun 2026 22:02:42 +0800 Subject: [PATCH] :sparkles: AI Agent https://github.com/siyuan-note/siyuan/issues/17797 Signed-off-by: Daniel <845765@qq.com> --- app/src/layout/dock/AgentChat.ts | 3 +++ app/src/layout/dock/SessionStore.ts | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/layout/dock/AgentChat.ts b/app/src/layout/dock/AgentChat.ts index 995ac2bd7..373d5981f 100644 --- a/app/src/layout/dock/AgentChat.ts +++ b/app/src/layout/dock/AgentChat.ts @@ -219,6 +219,7 @@ export class AgentChat extends Model { this.sessionPromptTokens = session.promptTokens || 0; this.sessionCompletionTokens = session.completionTokens || 0; this.sessionTotalDuration = session.totalDuration || 0; + if (session.model) { this.modelSelect.value = session.model; } if (this.composer) { this.composer.restoreHistory(session.messageHistory || []); } @@ -372,6 +373,7 @@ export class AgentChat extends Model { updatedAt: Date.now(), messageHistory: this.composer?.getHistory() || [], thinkingSteps: this.thinkingSteps, + model: this.getSelectedModel(), }; await SessionStore.save(session); } @@ -398,6 +400,7 @@ export class AgentChat extends Model { this.sessionPromptTokens = session.promptTokens || 0; this.sessionCompletionTokens = session.completionTokens || 0; this.sessionTotalDuration = session.totalDuration || 0; + if (session.model) { this.modelSelect.value = session.model; } if (this.tokenDisplayEl) { this.updateTokenDisplay(); } diff --git a/app/src/layout/dock/SessionStore.ts b/app/src/layout/dock/SessionStore.ts index 29f6dea0d..cb5f4db3c 100644 --- a/app/src/layout/dock/SessionStore.ts +++ b/app/src/layout/dock/SessionStore.ts @@ -6,6 +6,7 @@ const SESSIONS_INDEX = SESSIONS_DIR + "index.json"; interface SessionIndexItem { id: string; title: string; + model?: string; createdAt: number; updatedAt: number; } @@ -13,6 +14,7 @@ interface SessionIndexItem { export interface AgentSession { id: string; title: string; + model?: string; messages: Array<{ role: string; content: string; @@ -97,6 +99,7 @@ async function rebuildIndex(): Promise { list.push({ id: id, title: session.title || "AI Agent", + model: session.model || "", createdAt: session.createdAt || entries[i].updated || Date.now(), updatedAt: session.updatedAt || entries[i].updated || Date.now(), }); @@ -136,17 +139,18 @@ export const SessionStore = { await writeJsonFile(SESSIONS_DIR + session.id + ".json", session); const list = await this.list(); - let found = false; + let foundIdx = -1; for (let i = 0; i < list.length; i++) { if (list[i].id === session.id) { list[i].title = session.title; list[i].updatedAt = session.updatedAt; - found = true; + list[i].model = session.model; + foundIdx = i; break; } } - if (!found) { - list.unshift({id: session.id, title: session.title, createdAt: session.createdAt, updatedAt: session.updatedAt}); + if (foundIdx < 0) { + list.unshift({id: session.id, title: session.title, model: session.model, createdAt: session.createdAt, updatedAt: session.updatedAt}); } await writeIndex(list); },