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
Danielb8d6fa5d3876
diff --git a/app/src/layout/dock/AgentChat.ts b/app/src/layout/dock/AgentChat.tsindex 429484db0d..c66191fe6d 100644--- a/app/src/layout/dock/AgentChat.ts+++ b/app/src/layout/dock/AgentChat.ts@@ -4,6 +4,7 @@ import {App} from "../../index";import {fetchAgentSSE, ISSEResult} from "../../util/agentSSE";import {mountComposer} from "./AgentComposer";import {AgentSession, SessionStore} from "./SessionStore";+import {getDockByType} from "../tabUtil";interface IAgentMessage {role: "user" | "assistant";@@ -149,6 +150,10 @@ export class AgentChat extends Model {if (t.closest(".agent-chat__msg")) { return; }if (t.closest(".agent-chat__header")) { return; }if (t.closest(".agent-session-popup")) { return; }+ if (t.closest('[data-type="min"]')) {+ getDockByType("agentChat").toggleModel("agentChat", false, true);+ return;+ }if (self.composer) { self.composer.focus(); }});}@@ -432,13 +437,16 @@ export class AgentChat extends Model {}private async deleteSession(id: string) {- this.closeSessionMenu();await SessionStore.remove(id);+ this.closeSessionMenu();if (id === this.sessionId) {const list = await SessionStore.list();+ this.messages = [];if (list.length > 0) {+ this.sessionId = list[0].id;await this.switchSession(list[0].id);} else {+ this.sessionId = SessionStore.newSessionId();await this.createSession();}}diff --git a/kernel/agent/agent.go b/kernel/agent/agent.goindex 2fc68731a7..203e3cf955 100644--- a/kernel/agent/agent.go+++ b/kernel/agent/agent.go@@ -380,7 +380,7 @@ func needsConfirm(toolName string, action string) bool {}func buildMessages(history []UserMessage, language string, references []Reference) []openai.ChatCompletionMessage {- var prompt = systemPrompt + "\n\nReply in " + langName(language) + "."+ var prompt = systemPrompt + "\n\n<env>\nWorkspace: " + util.WorkspaceDir + "\nVersion: " + util.Ver + "\nToday's date: " + time.Now().Format("2006-01-02 Mon") + "\nContainer: " + util.Container + "\n</env>\n\nReply in " + langName(language) + "."if len(references) > 0 {prompt += "\n\nThe user has referenced the following content blocks:\n"for _, ref := range references {diff --git a/kernel/util/websearch.go b/kernel/util/websearch.goindex 8f62b0d9ca..312b565da4 100644--- a/kernel/util/websearch.go+++ b/kernel/util/websearch.go@@ -19,6 +19,8 @@ package utilimport ("encoding/json""errors"+ "io"+ "net/url""strings""github.com/siyuan-note/httpclient"@@ -55,9 +57,9 @@ type mcpContent struct {}func WebSearch(query, exaApiKey string) (string, error) {- url := defaultExaURL+ exaURL := defaultExaURLif exaApiKey != "" {- url += "?exaApiKey=" + exaApiKey+ exaURL += "?exaApiKey=" + url.QueryEscape(exaApiKey)}reqBody := mcpRequest{@@ -75,13 +77,17 @@ func WebSearch(query, exaApiKey string) (string, error) {},}- resp, err := httpclient.NewBrowserRequest().SetBody(reqBody).Post(url)+ resp, err := httpclient.NewBrowserRequest().SetBody(reqBody).Post(exaURL)if err != nil {return "", errors.New("web search failed: " + err.Error())}defer resp.Body.Close()- body := resp.String()+ bodyBytes, err := io.ReadAll(resp.Body)+ if err != nil {+ return "", errors.New("web search read response failed: " + err.Error())+ }+ body := string(bodyBytes)text := parseMcpResponse(body)if text == "" {return "No search results found. Please try a different query.", nil