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
Daniel1006e773790f
diff --git a/app/src/assets/scss/business/_ai_agent.scss b/app/src/assets/scss/business/_ai_agent.scssindex 0ea5a04bbc..0cd75a9288 100644--- a/app/src/assets/scss/business/_ai_agent.scss+++ b/app/src/assets/scss/business/_ai_agent.scss@@ -437,6 +437,9 @@.agent-chat__thinking-body--preview {max-height: 120px;overflow-y: auto;+ contain: none; // 覆盖 base 的 contain:layout paint,该值会阻止 overflow 滚动生效+ display: flex;+ flex-direction: column;// 隐藏滚动条,保持预览态视觉干净(内容通过 JS 自动滚到底部)。scrollbar-width: none;@@ -444,6 +447,11 @@&::-webkit-scrollbar {display: none;}++ // 内容元素弹性填充,滚动发生在 body 容器上。+ > .agent-chat__thinking-chat {+ flex-shrink: 0;+ }}.agent-chat__thinking-body--expanded {diff --git a/app/src/layout/dock/agent/AgentChat.ts b/app/src/layout/dock/agent/AgentChat.tsindex 27df3ad818..f8f0a4cf5a 100644--- a/app/src/layout/dock/agent/AgentChat.ts+++ b/app/src/layout/dock/agent/AgentChat.ts@@ -1661,6 +1661,7 @@ export class AgentChat extends Model {}private pendingTokenUpdate = false;+ private pendingReasoningUpdate = false;private rafId = 0;private appendToken(token: string) {@@ -1675,11 +1676,20 @@ export class AgentChat extends Model {chatEl.className = "agent-chat__thinking-chat b3-typography agent-chat__thinking-chat--streaming";thinkBody.appendChild(chatEl);}- chatEl.innerHTML = this.lute.ProtylePreviewStr("", this.currentContent) || escapeHtml(this.currentContent);- postRender(chatEl, this.app);- // 预览态固定高度,滚动到底部让最新流式内容可见。- thinkBody.scrollTop = thinkBody.scrollHeight;- this.scrollToBottom();+ if (!this.pendingTokenUpdate) {+ this.pendingTokenUpdate = true;+ // 用 RAF 合并更新(与普通 AI 消息一致),减少重建频率。+ this.rafId = requestAnimationFrame(() => {+ this.pendingTokenUpdate = false;+ chatEl.innerHTML = this.lute.ProtylePreviewStr("", this.currentContent) || escapeHtml(this.currentContent);+ postRender(chatEl, this.app);+ const body = chatEl.closest(".agent-chat__thinking-body") as HTMLElement | null;+ if (body) {+ body.scrollTop = body.scrollHeight;+ }+ this.scrollToBottom();+ });+ }return;}@@ -1706,6 +1716,17 @@ export class AgentChat extends Model {if (this.pendingTokenUpdate) {this.pendingTokenUpdate = false;cancelAnimationFrame(this.rafId);+ // 思考卡片流式:更新 chatEl 并滚到底部(与 appendToken 思考分支一致)。+ const thinkChat = this.messagesContainer.querySelector(".agent-chat__msg--thinking:not(.agent-chat__msg--thinking-done) .agent-chat__thinking-chat--streaming") as HTMLElement;+ if (thinkChat) {+ thinkChat.innerHTML = this.lute.ProtylePreviewStr("", this.currentContent) || escapeHtml(this.currentContent);+ postRender(thinkChat, this.app);+ const thinkBody = thinkChat.parentElement;+ if (thinkBody) {+ thinkBody.scrollTop = thinkBody.scrollHeight;+ }+ return;+ }const bodyEl = this.currentAIElement?.querySelector(".agent-chat__body") as HTMLElement;if (bodyEl) {bodyEl.innerHTML = this.lute.ProtylePreviewStr("", this.currentContent) || escapeHtml(this.currentContent);@@ -1900,21 +1921,28 @@ export class AgentChat extends Model {return;}const thinking = thinkingElems[thinkingElems.length - 1];- let reasoningEl: HTMLElement;+ // 新轮次立即创建 reasoning 元素(保证多轮顺序),文本内容用 RAF 合并追加(减少 reflow)。if (isNewRound) {- reasoningEl = document.createElement("div");+ const reasoningEl = document.createElement("div");reasoningEl.className = "agent-chat__thinking-reasoning-text";thinking.appendChild(reasoningEl);- } else {- const allReasoning = thinking.querySelectorAll(".agent-chat__thinking-reasoning-text");- reasoningEl = allReasoning[allReasoning.length - 1] as HTMLElement;- if (!reasoningEl) {- reasoningEl = document.createElement("div");- reasoningEl.className = "agent-chat__thinking-reasoning-text";- thinking.appendChild(reasoningEl);- }}- reasoningEl.textContent += token;+ if (!this.pendingReasoningUpdate) {+ this.pendingReasoningUpdate = true;+ requestAnimationFrame(() => {+ this.pendingReasoningUpdate = false;+ const allReasoning = thinking.querySelectorAll(".agent-chat__thinking-reasoning-text");+ const reasoningEl = allReasoning[allReasoning.length - 1] as HTMLElement;+ if (reasoningEl) {+ reasoningEl.textContent = this.currentThinkingReasoningContent;+ // 预览态固定高度,滚到底部让最新 reasoning 内容可见。+ const body = reasoningEl.closest(".agent-chat__thinking-body") as HTMLElement | null;+ if (body) {+ body.scrollTop = body.scrollHeight;+ }+ }+ });+ }}private addCopyButton(el: HTMLElement, contentOverride?: string, timestamp?: number) {