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

Danielaea4e14b5c6e
diff --git a/app/src/layout/dock/AgentChat.ts b/app/src/layout/dock/AgentChat.ts
index 9da86110b8..126cc9f158 100644
--- a/app/src/layout/dock/AgentChat.ts
+++ b/app/src/layout/dock/AgentChat.ts
@@ -818,7 +818,7 @@ export class AgentChat extends Model {
}
el.innerHTML = '<div class="agent-chat__body">' + (this.lute.MarkdownStr("", content) || escapeHtml(content)) + "</div>";
this.messagesContainer.appendChild(el);
- postRender(el);
+ postRender(el, this.app);
// entry.duration 存的是秒,addCopyButton 期望毫秒。
this.addCopyButton(el, content, promptTokens, completionTokens, duration ? duration * 1000 : undefined, timestamp);
}
@@ -1461,7 +1461,7 @@ export class AgentChat extends Model {
thinkBody.appendChild(chatEl);
}
chatEl.innerHTML = this.lute.MarkdownStr("", this.currentContent) || escapeHtml(this.currentContent);
- postRender(chatEl);
+ postRender(chatEl, this.app);
this.scrollToBottom();
return;
}
@@ -1477,7 +1477,7 @@ export class AgentChat extends Model {
const bodyEl = this.currentAIElement?.querySelector(".agent-chat__body") as HTMLElement;
if (bodyEl) {
bodyEl.innerHTML = this.lute.MarkdownStr("", this.currentContent) || escapeHtml(this.currentContent);
- postRender(bodyEl);
+ postRender(bodyEl, this.app);
void bodyEl.offsetHeight; // force reflow
this.scrollToBottom();
}
@@ -1492,7 +1492,7 @@ export class AgentChat extends Model {
const bodyEl = this.currentAIElement?.querySelector(".agent-chat__body") as HTMLElement;
if (bodyEl) {
bodyEl.innerHTML = this.lute.MarkdownStr("", this.currentContent) || escapeHtml(this.currentContent);
- postRender(bodyEl);
+ postRender(bodyEl, this.app);
}
}
}
@@ -1844,7 +1844,7 @@ export class AgentChat extends Model {
el.setAttribute("data-message-id", this.currentAssistantEntryId);
el.innerHTML = '<div class="agent-chat__body">' + (this.lute.MarkdownStr("", savedContent) || escapeHtml(savedContent)) + "</div>";
this.messagesContainer.appendChild(el);
- postRender(el);
+ postRender(el, this.app);
this.currentAIElement = el;
this.currentContent = savedContent;
this.fullContent = savedFullContent;
@@ -2061,7 +2061,7 @@ export class AgentChat extends Model {
el.setAttribute("data-message-id", this.currentAssistantEntryId);
el.innerHTML = '<div class="agent-chat__body">' + (this.lute.MarkdownStr("", savedContent) || escapeHtml(savedContent)) + "</div>";
this.messagesContainer.appendChild(el);
- postRender(el);
+ postRender(el, this.app);
this.currentAIElement = el;
this.currentContent = savedContent;
this.fullContent = savedFullContent;
@@ -2394,7 +2394,7 @@ export class AgentChat extends Model {
bindThinkingCardToggle(el);
this.messagesContainer.appendChild(el);
- postRender(el);
+ postRender(el, this.app);
}
// 由 duration 经 i18n 生成"已思考:Xs"标题文本;无 duration 时回退到"思考中..."。
diff --git a/app/src/layout/dock/AgentMessageRenderer.ts b/app/src/layout/dock/AgentMessageRenderer.ts
index bb40b99a94..bb913ec5cb 100644
--- a/app/src/layout/dock/AgentMessageRenderer.ts
+++ b/app/src/layout/dock/AgentMessageRenderer.ts
@@ -4,6 +4,8 @@ import {addScript} from "../../protyle/util/addScript";
import {Constants} from "../../constants";
import {mathRender} from "../../protyle/render/mathRender";
import {showMessage} from "../../dialog/message";
+import {processSYLink} from "../../editor/openLink";
+import type {App} from "../../index";
export const renderTodoList = (result: string): string => {
const L = window.siyuan.languages;
@@ -216,7 +218,7 @@ export const addCopyButtons = (container: HTMLElement): void => {
});
};
-export const postRender = (container: HTMLElement): void => {
+export const postRender = (container: HTMLElement, app?: App): void => {
container.querySelectorAll(".language-math").forEach((el) => {
if (el.hasAttribute("data-subtype")) { return; }
const content = el.textContent || "";
@@ -245,4 +247,19 @@ export const postRender = (container: HTMLElement): void => {
highlightCodeBlocks(container);
mathRender(container);
addCopyButtons(container);
+ if (!app) {
+ return;
+ }
+ // MarkdownStr 渲染出的 siyuan:// 块链接只是普通 <a href>,需补全 data-type/data-href
+ // 才能接入全局 popover 浮窗系统;dock 内无 protyle 点击链路,需自行绑定点击打开块。
+ container.querySelectorAll<HTMLAnchorElement>('a[href^="siyuan://"]').forEach((a) => {
+ const href = a.getAttribute("href") || "";
+ a.setAttribute("data-type", "a");
+ a.setAttribute("data-href", href);
+ a.addEventListener("click", (event: MouseEvent) => {
+ event.preventDefault();
+ event.stopPropagation();
+ void processSYLink(app, href);
+ });
+ });
};
diff --git a/kernel/agent/agent.go b/kernel/agent/agent.go
index 11c98dbb1f..486d466c52 100644
--- a/kernel/agent/agent.go
+++ b/kernel/agent/agent.go
@@ -57,7 +57,7 @@ const systemPrompt = `You are a SiYuan AI assistant. You help users manage their
- Attributes: attr.get/set on any block. Database/attribute views: database.item_add (rows), database.key_add (columns), database.render (view). Create database blocks via database tools, never via the file tool.
## Response Guidelines
-- Reply in the user's language. When mentioning documents/blocks, include titles and IDs.
+- Reply in the user's language. When mentioning documents/blocks the user can open, format them as markdown links: [title](siyuan://blocks/<blockID>). Only use block IDs actually returned by a tool call (block.get/get_children/breadcrumb/batch_get/search); never fabricate IDs. For general mentions without a specific block, plain text is fine.
- Be concise: summarize rather than repeat large content.
- For choices (which notebook/document/action), use the question tool — never a plain text list.
- Use markdown; for code blocks always specify the language (e.g. python, go); use $...$ for inline and $...$ for block formulas.