Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: AI Agent https://github.com/siyuan-note/siyuan/issues/17797

Daniel23ce6151d8fe
diff --git a/app/appearance/langs/ar_SA.json b/app/appearance/langs/ar_SA.json
index fe8d9c90cb..2a143cc397 100644
--- a/app/appearance/langs/ar_SA.json
+++ b/app/appearance/langs/ar_SA.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "البحث عن جلسات...",
"agentWelcomeGreeting": "مرحبًا، ما الذي يدور في ذهنك؟ سأتولى الأمر",
"agentExample1": "البحث عن ملاحظات الاجتماعات الأخيرة",
"agentExample2": "إنشاء مذكرة يومية جديدة",
diff --git a/app/appearance/langs/de_DE.json b/app/appearance/langs/de_DE.json
index 205cb34213..71d68ca23a 100644
--- a/app/appearance/langs/de_DE.json
+++ b/app/appearance/langs/de_DE.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Sitzungen suchen...",
"agentWelcomeGreeting": "Hey, was hast du vor? Ich kümmere mich drum",
"agentExample1": "Durchsuche meine letzten Besprechungsnotizen",
"agentExample2": "Erstelle ein neues Tagebuch",
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index 8f381bc7c9..ffe68991e1 100644
--- a/app/appearance/langs/en_US.json
+++ b/app/appearance/langs/en_US.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Search sessions",
"agentWelcomeGreeting": "Hey, what do you have in mind? I've got you covered",
"agentExample1": "Search my recent meeting notes",
"agentExample2": "Create a new daily journal",
diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json
index 42a7949595..4bed970b31 100644
--- a/app/appearance/langs/es_ES.json
+++ b/app/appearance/langs/es_ES.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Buscar sesiones...",
"agentWelcomeGreeting": "Oye, ¿qué tienes en mente? Yo me encargo",
"agentExample1": "Buscar mis notas de reuniones recientes",
"agentExample2": "Crear un nuevo diario",
diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json
index bf54002412..161a051b62 100644
--- a/app/appearance/langs/fr_FR.json
+++ b/app/appearance/langs/fr_FR.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Rechercher des sessions...",
"agentWelcomeGreeting": "Dis-moi tout, je m'en occupe",
"agentExample1": "Rechercher mes notes de réunion récentes",
"agentExample2": "Créer un nouveau journal",
diff --git a/app/appearance/langs/he_IL.json b/app/appearance/langs/he_IL.json
index 60ee4d8cb3..dc7f80f3b4 100644
--- a/app/appearance/langs/he_IL.json
+++ b/app/appearance/langs/he_IL.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "חיפוש הפעלות...",
"agentWelcomeGreeting": "היי, מה בראש? אני אטפל בזה",
"agentExample1": "חפש את הערות הפגישות האחרונות שלי",
"agentExample2": "צור יומן חדש",
diff --git a/app/appearance/langs/hi_IN.json b/app/appearance/langs/hi_IN.json
index 3f5c66999f..3d089d12d3 100644
--- a/app/appearance/langs/hi_IN.json
+++ b/app/appearance/langs/hi_IN.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "सत्र खोजें...",
"agentWelcomeGreeting": "अरे, क्या सोच रहे हो? मैं संभाल लूंगा",
"agentExample1": "मेरी हाल की बैठक के नोट्स खोजें",
"agentExample2": "एक नई डायरी बनाएं",
diff --git a/app/appearance/langs/id_ID.json b/app/appearance/langs/id_ID.json
index dbf50f55da..ae7ec7401c 100644
--- a/app/appearance/langs/id_ID.json
+++ b/app/appearance/langs/id_ID.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Cari sesi...",
"agentWelcomeGreeting": "Hei, ada rencana apa? Serahkan padaku",
"agentExample1": "Cari catatan rapat terbaru saya",
"agentExample2": "Buat jurnal harian baru",
diff --git a/app/appearance/langs/it_IT.json b/app/appearance/langs/it_IT.json
index 17cfbb6fa6..e2f4926ea2 100644
--- a/app/appearance/langs/it_IT.json
+++ b/app/appearance/langs/it_IT.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Cerca sessioni...",
"agentWelcomeGreeting": "Ehi, cosa hai in mente? Ci penso io",
"agentExample1": "Cerca i miei appunti delle riunioni recenti",
"agentExample2": "Crea un nuovo diario",
diff --git a/app/appearance/langs/ja_JP.json b/app/appearance/langs/ja_JP.json
index 183ccfe5b0..3499d2ad9d 100644
--- a/app/appearance/langs/ja_JP.json
+++ b/app/appearance/langs/ja_JP.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "セッションを検索...",
"agentWelcomeGreeting": "ねえ、何か考えてる?任せて",
"agentExample1": "最近の会議メモを検索",
"agentExample2": "新しい日記を作成",
diff --git a/app/appearance/langs/ko_KR.json b/app/appearance/langs/ko_KR.json
index 213488c63b..a9b725dee5 100644
--- a/app/appearance/langs/ko_KR.json
+++ b/app/appearance/langs/ko_KR.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "세션 검색...",
"agentWelcomeGreeting": "뭐든 말해 봐, 내가 해결할게",
"agentExample1": "최근 회의록 검색",
"agentExample2": "새 일기 작성",
diff --git a/app/appearance/langs/nl_NL.json b/app/appearance/langs/nl_NL.json
index 56cab423bc..132ba48ac5 100644
--- a/app/appearance/langs/nl_NL.json
+++ b/app/appearance/langs/nl_NL.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Sessies zoeken...",
"agentWelcomeGreeting": "Hé, wat heb je in gedachten? Ik regel het",
"agentExample1": "Doorzoek mijn recente vergadernotities",
"agentExample2": "Maak een nieuw dagboek",
diff --git a/app/appearance/langs/pl_PL.json b/app/appearance/langs/pl_PL.json
index 583826054b..7cf93eb54d 100644
--- a/app/appearance/langs/pl_PL.json
+++ b/app/appearance/langs/pl_PL.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Szukaj sesji...",
"agentWelcomeGreeting": "Hej, co masz na myśli? Zajmę się tym",
"agentExample1": "Wyszukaj moje ostatnie notatki ze spotkań",
"agentExample2": "Utwórz nowy dziennik",
diff --git a/app/appearance/langs/pt_BR.json b/app/appearance/langs/pt_BR.json
index c1122975c5..670a861747 100644
--- a/app/appearance/langs/pt_BR.json
+++ b/app/appearance/langs/pt_BR.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Pesquisar sessões...",
"agentWelcomeGreeting": "Ei, o que tem em mente? Deixa comigo",
"agentExample1": "Pesquisar minhas anotações de reuniões recentes",
"agentExample2": "Criar um novo diário",
diff --git a/app/appearance/langs/ru_RU.json b/app/appearance/langs/ru_RU.json
index 1bf738481e..55be342e98 100644
--- a/app/appearance/langs/ru_RU.json
+++ b/app/appearance/langs/ru_RU.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Поиск сессий...",
"agentWelcomeGreeting": "Привет, что задумал? Я всё устрою",
"agentExample1": "Найти мои недавние заметки о встречах",
"agentExample2": "Создать новый дневник",
diff --git a/app/appearance/langs/sk_SK.json b/app/appearance/langs/sk_SK.json
index 4caf451fbd..493a8307fa 100644
--- a/app/appearance/langs/sk_SK.json
+++ b/app/appearance/langs/sk_SK.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Vyhľadať relácie...",
"agentWelcomeGreeting": "Hej, čo máš na mysli? Postarám sa o to",
"agentExample1": "Vyhľadať moje nedávne poznámky zo stretnutí",
"agentExample2": "Vytvoriť nový denník",
diff --git a/app/appearance/langs/th_TH.json b/app/appearance/langs/th_TH.json
index 11e5a56ef6..7736bb7073 100644
--- a/app/appearance/langs/th_TH.json
+++ b/app/appearance/langs/th_TH.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "ค้นหาเซสชัน...",
"agentWelcomeGreeting": "ว่าไง คิดอะไรอยู่? จัดการให้เอง",
"agentExample1": "ค้นหาบันทึกการประชุมล่าสุดของฉัน",
"agentExample2": "สร้างบันทึกประจำวันใหม่",
diff --git a/app/appearance/langs/tr_TR.json b/app/appearance/langs/tr_TR.json
index 9c96d57bdf..a3fe5349aa 100644
--- a/app/appearance/langs/tr_TR.json
+++ b/app/appearance/langs/tr_TR.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Oturum ara...",
"agentWelcomeGreeting": "Selam, aklında ne var? Hallederim",
"agentExample1": "Son toplantı notlarımı ara",
"agentExample2": "Yeni bir günlük oluştur",
diff --git a/app/appearance/langs/uk_UA.json b/app/appearance/langs/uk_UA.json
index 4b3300250c..f5264143b4 100644
--- a/app/appearance/langs/uk_UA.json
+++ b/app/appearance/langs/uk_UA.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "Пошук сесій...",
"agentWelcomeGreeting": "Привіт, що на думці? Я все влаштую",
"agentExample1": "Знайти мої нещодавні нотатки про зустрічі",
"agentExample2": "Створити новий щоденник",
diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json
index 44826b31cc..d221a976ef 100644
--- a/app/appearance/langs/zh_CHT.json
+++ b/app/appearance/langs/zh_CHT.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "搜尋會話...",
"agentWelcomeGreeting": "嗨,有什麼想法?我來幫你搞定",
"agentExample1": "搜尋最近的會議記錄",
"agentExample2": "幫我寫一篇日記",
diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json
index 4010e5fe23..5f6096da56 100644
--- a/app/appearance/langs/zh_CN.json
+++ b/app/appearance/langs/zh_CN.json
@@ -1,4 +1,5 @@
{
+ "agentSessionSearch": "搜索会话...",
"agentWelcomeGreeting": "嗨,有什么想法?我来帮你搞定",
"agentExample1": "搜索最近的会议记录",
"agentExample2": "帮我写一篇日记",
diff --git a/app/src/assets/scss/business/_agentChat.scss b/app/src/assets/scss/business/_agentChat.scss
index cd13d9b54f..2f02a5cf71 100644
--- a/app/src/assets/scss/business/_agentChat.scss
+++ b/app/src/assets/scss/business/_agentChat.scss
@@ -597,6 +597,12 @@
max-height: 300px;
}
+.agent-session-popup__search {
+ width: calc(100% - 16px);
+ margin: 0 8px 4px;
+ box-sizing: border-box;
+}
+
.agent-session-popup__actions {
display: flex;
align-items: center;
diff --git a/app/src/layout/dock/AgentChat.ts b/app/src/layout/dock/AgentChat.ts
index 7daaf85aa4..8780f0dbae 100644
--- a/app/src/layout/dock/AgentChat.ts
+++ b/app/src/layout/dock/AgentChat.ts
@@ -3,7 +3,7 @@ import {Model} from "../Model";
import {App} from "../../index";
import {fetchAgentSSE, ISSEResult} from "../../util/agentSSE";
import {mountComposer} from "./AgentComposer";
-import {AgentSession, SessionStore} from "./SessionStore";
+import {AgentSession, SessionIndexItem, SessionStore} from "./SessionStore";
import {getDockByType} from "../tabUtil";
import {updateHotkeyAfterTip} from "../../protyle/util/compatibility";
import {setPosition} from "../../util/setPosition";
@@ -42,6 +42,8 @@ export class AgentChat extends Model {
private currentToolCalls: Array<{name: string; arguments: Record<string, unknown>; result?: string}> = [];
private abortController: AbortController | null = null;
private isRenderingSessionList = false;
+ private sessionListItems: SessionIndexItem[] = [];
+ private currentSearchKeyword = "";
private currentThinkingText = "";
private currentThinkingReasoning = "";
private currentThinkingReasoningContent = "";
@@ -237,39 +239,82 @@ export class AgentChat extends Model {
private closeSessionMenu() {
document.querySelectorAll(".agent-session-popup").forEach(function (el) { el.remove(); });
this.sessionPopup = null;
+ this.currentSearchKeyword = "";
+ this.sessionListItems = [];
}
private async renderSessionList() {
this.isRenderingSessionList = true;
this.closeSessionMenu();
try {
- const list = await SessionStore.list();
- list.sort((a, b) => b.createdAt - a.createdAt);
+ this.sessionListItems = await SessionStore.list();
+ this.sessionListItems.sort((a, b) => b.createdAt - a.createdAt);
+
+ this.sessionPopup = document.createElement("div");
+ this.sessionPopup.className = "agent-session-popup b3-menu";
+
+ const L = window.siyuan.languages;
+
+ let html = '<input class="b3-text-field agent-session-popup__search" placeholder="' + L.agentSessionSearch + '">';
+ html += '<div class="b3-menu__items"></div>';
+
+ this.sessionPopup.innerHTML = html;
+
+ const itemsContainer = this.sessionPopup.querySelector(".b3-menu__items") as HTMLElement;
+ this.rebuildSessionItems(itemsContainer);
+
+ const searchInput = this.sessionPopup.querySelector(".agent-session-popup__search") as HTMLInputElement;
+ searchInput.addEventListener("input", () => {
+ this.filterSessionList(searchInput.value, itemsContainer);
+ });
+ searchInput.addEventListener("click", (e: MouseEvent) => {
+ e.stopPropagation();
+ });
- this.sessionPopup = document.createElement("div");
- this.sessionPopup.className = "agent-session-popup b3-menu";
+ this.parent.panelElement.appendChild(this.sessionPopup);
- let html = '<div class="b3-menu__items">';
+ const btnRect = this.sessionMenuBtn.getBoundingClientRect();
+ setPosition(this.sessionPopup, btnRect.right - 280, btnRect.bottom, btnRect.height, btnRect.width);
+
+ this.sessionPopup.addEventListener("click", (e: MouseEvent) => {
+ e.stopPropagation();
+ });
+ const closeOut = () => {
+ this.closeSessionMenu();
+ document.removeEventListener("click", closeOut);
+ };
+ setTimeout(() => {
+ document.addEventListener("click", closeOut);
+ }, 10);
+ } finally {
+ this.isRenderingSessionList = false;
+ }
+ }
+
+ private rebuildSessionItems(container: HTMLElement) {
+ const list = this.sessionListItems;
+ let html = "";
if (list.length === 0) {
html += '<div class="b3-menu__item"><span class="b3-menu__label" style="text-align:center;color:var(--b3-theme-on-surface-light)">' + (window.siyuan.languages.emptyContent || "No sessions") + "</span></div>";
} else {
for (let i = 0; i < list.length; i++) {
const s = list[i];
- const isActive = s.id === this.sessionId;
- html += '<div class="b3-menu__item' + (isActive ? " b3-menu__item--current" : "") + '" data-id="' + s.id + '">' +
- '<span class="b3-menu__label ariaLabel" data-position="east" aria-label="' + this.escapeHtml(s.title || this.defaultTitle) + '">' + this.escapeHtml(s.title || this.defaultTitle) + "</span>" +
- '<span class="agent-session-popup__actions">' +
- '<svg class="agent-session-popup__rename ariaLabel" data-position="north" data-id="' + s.id + '" aria-label="' + window.siyuan.languages.rename + '"><use xlink:href="#iconEdit"></use></svg>' +
- '<svg class="agent-session-popup__delete ariaLabel" data-position="north" data-id="' + s.id + '" aria-label="' + window.siyuan.languages.delete + '"><use xlink:href="#iconTrashcan"></use></svg>' +
- "</span>" +
- "</div>";
+ const isActive = s.id === this.sessionId;
+ html += '<div class="b3-menu__item' + (isActive ? " b3-menu__item--current" : "") + '" data-id="' + s.id + '">' +
+ '<span class="b3-menu__label ariaLabel" data-position="east" aria-label="' + this.escapeHtml(s.title || this.defaultTitle) + '">' + this.escapeHtml(s.title || this.defaultTitle) + "</span>" +
+ '<span class="agent-session-popup__actions">' +
+ '<svg class="agent-session-popup__rename ariaLabel" data-position="north" data-id="' + s.id + '" aria-label="' + window.siyuan.languages.rename + '"><use xlink:href="#iconEdit"></use></svg>' +
+ '<svg class="agent-session-popup__delete ariaLabel" data-position="north" data-id="' + s.id + '" aria-label="' + window.siyuan.languages.delete + '"><use xlink:href="#iconTrashcan"></use></svg>' +
+ "</span>" +
+ "</div>";
}
}
- html += "</div>";
-
- this.sessionPopup.innerHTML = html;
+ container.innerHTML = html;
+ this.bindSessionItemEvents(container);
+ }
- this.sessionPopup.querySelectorAll(".b3-menu__item").forEach((item) => {
+ private bindSessionItemEvents(container: HTMLElement) {
+ container.querySelectorAll(".b3-menu__item").forEach((item) => {
item.addEventListener("click", () => {
const id = item.getAttribute("data-id") || "";
if (id && id !== this.sessionId) {
@@ -278,14 +323,14 @@ export class AgentChat extends Model {
}
});
});
- this.sessionPopup.querySelectorAll(".agent-session-popup__delete").forEach((btn) => {
+ container.querySelectorAll(".agent-session-popup__delete").forEach((btn) => {
btn.addEventListener("click", (e: MouseEvent) => {
e.stopPropagation();
const id = btn.getAttribute("data-id") || "";
if (id) { this.deleteSession(id); }
});
});
- this.sessionPopup.querySelectorAll(".agent-session-popup__rename").forEach((btn) => {
+ container.querySelectorAll(".agent-session-popup__rename").forEach((btn) => {
btn.addEventListener("click", (e: MouseEvent) => {
e.stopPropagation();
const id = btn.getAttribute("data-id") || "";
@@ -296,25 +341,33 @@ export class AgentChat extends Model {
}
});
});
+ }
- this.parent.panelElement.appendChild(this.sessionPopup);
-
- const btnRect = this.sessionMenuBtn.getBoundingClientRect();
- setPosition(this.sessionPopup, btnRect.right - 280, btnRect.bottom, btnRect.height, btnRect.width);
-
- this.sessionPopup.addEventListener("click", (e: MouseEvent) => {
- e.stopPropagation();
- });
- const closeOut = () => {
- this.closeSessionMenu();
- document.removeEventListener("click", closeOut);
- };
- setTimeout(() => {
- document.addEventListener("click", closeOut);
- }, 10);
- } finally {
- this.isRenderingSessionList = false;
+ private filterSessionList(keyword: string, container: HTMLElement) {
+ this.currentSearchKeyword = keyword.trim();
+ if (!this.currentSearchKeyword) {
+ this.rebuildSessionItems(container);
+ return;
}
+ const kw = this.currentSearchKeyword.toLowerCase();
+ let hasVisible = false;
+ const items = container.querySelectorAll(".b3-menu__item[data-id]");
+ for (let i = 0; i < items.length; i++) {
+ const item = items[i] as HTMLElement;
+ const id = item.getAttribute("data-id") || "";
+ const session = this.sessionListItems.find((s) => s.id === id);
+ const title = (session ? session.title : "") || this.defaultTitle;
+ if (title.toLowerCase().indexOf(kw) >= 0) {
+ item.style.display = "";
+ hasVisible = true;
+ } else {
+ item.style.display = "none";
+ }
+ }
+ if (!hasVisible) {
+ container.innerHTML = '<div class="b3-menu__item"><span class="b3-menu__label" style="text-align:center;color:var(--b3-theme-on-surface-light)">' + (window.siyuan.languages.emptyContent || "No sessions") + "</span></div>";
+ }
+ this.highlightCurrentSession();
}
private startRename(id: string, rowEl: HTMLElement) {
@@ -339,6 +392,8 @@ export class AgentChat extends Model {
input.replaceWith(titleEl);
titleEl.textContent = title;
await SessionStore.rename(id, title);
+ const listItem = this.sessionListItems.find((s) => s.id === id);
+ if (listItem) { listItem.title = title; }
if (id === this.sessionId) {
this.sessionTitle = title;
this.titleElement.textContent = title;
@@ -479,9 +534,11 @@ export class AgentChat extends Model {
private async deleteSession(id: string) {
await SessionStore.remove(id);
+ this.sessionListItems = this.sessionListItems.filter((item) => item.id !== id);
const wasCurrent = id === this.sessionId;
if (wasCurrent) {
const list = await SessionStore.list();
+ this.sessionListItems = list;
this.entries = [];
if (list.length > 0) {
this.sessionId = list[0].id;
@@ -492,21 +549,14 @@ export class AgentChat extends Model {
}
}
- // Remove the deleted row from popup DOM directly (no re-render flash)
- const row = this.sessionPopup?.querySelector('.b3-menu__item[data-id="' + id + '"]');
- if (row) {
- row.remove();
- }
- const items = this.sessionPopup?.querySelectorAll(".b3-menu__item");
- if (items && items.length === 0) {
- const listEl = this.sessionPopup?.querySelector(".b3-menu__items");
- if (listEl) {
- listEl.innerHTML = '<div class="b3-menu__item"><span class="b3-menu__label" style="text-align:center;color:var(--b3-theme-on-surface-light)">' + (window.siyuan.languages.emptyContent || "No sessions") + "</span></div>";
+ const itemsContainer = this.sessionPopup?.querySelector(".b3-menu__items") as HTMLElement;
+ if (itemsContainer) {
+ if (this.currentSearchKeyword) {
+ this.filterSessionList(this.currentSearchKeyword, itemsContainer);
+ } else {
+ this.rebuildSessionItems(itemsContainer);
}
}
- if (wasCurrent && this.sessionPopup) {
- this.highlightCurrentSession();
- }
}
private highlightCurrentSession() {
diff --git a/app/src/layout/dock/SessionStore.ts b/app/src/layout/dock/SessionStore.ts
index 6a0792fcec..d81888feaa 100644
--- a/app/src/layout/dock/SessionStore.ts
+++ b/app/src/layout/dock/SessionStore.ts
@@ -2,7 +2,7 @@ import {fetchSyncPost} from "../../util/fetch";
const SESSIONS_DIR = "data/storage/ai/agent/sessions/";
-interface SessionIndexItem {
+export interface SessionIndexItem {
id: string;
title: string;
model?: string;