An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: AI Agent https://github.com/siyuan-note/siyuan/issues/17797
Daniele65d8509ec6b
diff --git a/app/src/layout/dock/AgentChat.ts b/app/src/layout/dock/AgentChat.tsindex 0b994a6a8f..86484ef8b4 100644--- a/app/src/layout/dock/AgentChat.ts+++ b/app/src/layout/dock/AgentChat.ts@@ -469,6 +469,7 @@ export class AgentChat extends Model {}this.sessionCreatedAt = session.createdAt || Date.now();this.sessionTitle = session.title;+ this.titleElement.textContent = session.title || this.defaultTitle;this.entries = this.buildEntriesFromSession(session);this.hasTitled = session.titled !== false;this.currentAIElement = null;@@ -681,19 +682,21 @@ export class AgentChat extends Model {}private async deleteSession(id: string) {- await SessionStore.remove(id);const wasCurrent = id === this.sessionId;if (wasCurrent) {- const result = await SessionStore.list({page: 1, pageSize: 1});- const list = result.sessions;- this.entries = [];+ const result = await SessionStore.list({page: 1, pageSize: 2});+ const list = result.sessions.filter(s => s.id !== id);if (list.length > 0) {- this.sessionId = list[0].id;await this.switchSession(list[0].id);+ await SessionStore.remove(id);} else {+ this.entries = [];this.sessionId = SessionStore.newSessionId();await this.createSession();+ await SessionStore.remove(id);}+ } else {+ await SessionStore.remove(id);}}diff --git a/app/src/layout/dock/AgentSessionPanel.ts b/app/src/layout/dock/AgentSessionPanel.tsindex 3130ff5c09..13993f68af 100644--- a/app/src/layout/dock/AgentSessionPanel.ts+++ b/app/src/layout/dock/AgentSessionPanel.ts@@ -1,6 +1,7 @@import {SessionIndexItem, SessionStore} from "./SessionStore";import {escapeHtml} from "../../util/escape";import {setPosition} from "../../util/setPosition";+import {hasClosestByClassName} from "../../protyle/util/hasClosest";export class AgentSessionPanel {private popup: HTMLElement | null = null;@@ -142,31 +143,31 @@ export class AgentSessionPanel {container.addEventListener("click", (e: MouseEvent) => {const target = e.target as HTMLElement;- const deleteBtn = target.closest(".agent-session-popup__delete");+ const deleteBtn = hasClosestByClassName(target, "agent-session-popup__delete");if (deleteBtn) {e.stopPropagation();- const id = deleteBtn.getAttribute("data-id") || "";+ const id = (deleteBtn as HTMLElement).getAttribute("data-id") || "";if (id) { this.callbacks.onDelete(id).then(() => { this.refresh(); }); }return;}- const renameBtn = target.closest(".agent-session-popup__rename");+ const renameBtn = hasClosestByClassName(target, "agent-session-popup__rename");if (renameBtn) {e.stopPropagation();- const id = renameBtn.getAttribute("data-id") || "";+ const id = (renameBtn as HTMLElement).getAttribute("data-id") || "";if (id) {- const parent = renameBtn.parentElement;+ const parent = (renameBtn as HTMLElement).parentElement;const row = parent ? parent.parentElement as HTMLElement : null;if (row) { this.startRename(id, row); }}return;}- if (target.closest(".agent-session-popup__rename-input")) {+ if (hasClosestByClassName(target, "agent-session-popup__rename-input")) {return;}- const item = target.closest(".b3-menu__item");+ const item = hasClosestByClassName(target, "b3-menu__item");if (item) {const id = (item as HTMLElement).getAttribute("data-id") || "";if (id && id !== this.getCurrentSessionId()) {