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

Daniele77f49db0704
diff --git a/app/src/assets/scss/business/_agentChat.scss b/app/src/assets/scss/business/_agentChat.scss
index 8140d59761..89ec29c7c1 100644
--- a/app/src/assets/scss/business/_agentChat.scss
+++ b/app/src/assets/scss/business/_agentChat.scss
@@ -110,8 +110,8 @@
align-items: flex-end;
}
-.agent-chat__msg--user .agent-chat__bubble {
- @extend .agent-chat__bubble-content;
+.agent-chat__msg--user .agent-chat__body {
+ @extend .agent-chat__body-content;
background: var(--b3-theme-surface);
border: 1px solid var(--b3-border-color);
color: var(--b3-theme-on-surface);
@@ -138,8 +138,9 @@
opacity: 1;
}
-.agent-chat__msg--ai .agent-chat__bubble {
- @extend .agent-chat__bubble-content;
+.agent-chat__msg--ai .agent-chat__body {
+ @extend .agent-chat__body-content;
+ min-width: 0;
background: transparent;
border: none;
color: var(--b3-theme-on-surface);
@@ -148,17 +149,35 @@
line-height: 1.5;
}
-.agent-chat__bubble--streaming {
+.agent-chat__body--streaming {
min-height: 20px;
}
-.agent-chat__bubble {
+.agent-chat__body {
user-select: text;
}
-.agent-chat__bubble-content {
+.agent-chat__body-content {
+ word-wrap: break-word;
+ overflow: auto;
+ word-break: break-word;
+
+ img {
+ max-width: 100%;
+ margin: 0 auto;
+ }
+
+ video, audio, canvas {
+ max-width: 100%;
+ }
+
ol, ul {
padding-left: 1.5em;
+ margin: 0.5em 0;
+ }
+
+ ul {
+ list-style-type: disc;
}
pre, table {
@@ -191,6 +210,8 @@
font-size: 85%;
border-radius: var(--b3-border-radius);
font-family: var(--b3-font-family-code);
+ word-break: break-word;
+ overflow-wrap: break-word;
}
pre {
@@ -215,10 +236,20 @@
table {
border-collapse: collapse;
+ empty-cells: show;
+ margin: 0;
+ border-spacing: 0;
+
+ colgroup col {
+ width: auto !important;
+ }
td, th {
padding: 4px 8px;
border: 1px solid var(--b3-theme-surface-lighter);
+ box-sizing: border-box;
+ max-width: 620px;
+ word-wrap: break-word;
}
thead th {
@@ -245,7 +276,9 @@
}
.protyle-task {
- list-style: none;
+ list-style: none !important;
+ word-break: break-word;
+ overflow-wrap: break-word;
input {
position: absolute;
@@ -272,6 +305,9 @@
li {
margin-bottom: 0.2em;
+ word-break: break-word;
+ overflow-wrap: break-word;
+ line-height: 1.5;
}
}
@@ -289,7 +325,7 @@
50% { opacity: 0; }
}
-.agent-chat__msg--error .agent-chat__bubble {
+.agent-chat__msg--error .agent-chat__body {
background: var(--b3-theme-error-light);
color: var(--b3-theme-error);
border-radius: var(--b3-border-radius-b);
@@ -339,7 +375,7 @@
.agent-chat__thinking-card {
border: 1px solid var(--b3-border-color);
border-radius: var(--b3-border-radius);
- overflow: hidden;
+ overflow: auto;
background: transparent;
}
@@ -405,6 +441,7 @@
}
.agent-chat__thinking-chat {
+ @extend .agent-chat__body-content;
color: var(--b3-theme-on-surface);
line-height: 1.5;
margin-bottom: 8px;
diff --git a/app/src/layout/dock/AgentChat.ts b/app/src/layout/dock/AgentChat.ts
index af499d0ba4..09893df715 100644
--- a/app/src/layout/dock/AgentChat.ts
+++ b/app/src/layout/dock/AgentChat.ts
@@ -494,7 +494,7 @@ export class AgentChat extends Model {
if (!content || !content.trim()) { return; }
const el = document.createElement("div");
el.className = "agent-chat__msg agent-chat__msg--ai";
- el.innerHTML = '<div class="agent-chat__bubble">' + (this.lute.MarkdownStr("", content) || this.escapeHtml(content)) + "</div>";
+ el.innerHTML = '<div class="agent-chat__body">' + (this.lute.MarkdownStr("", content) || this.escapeHtml(content)) + "</div>";
this.messagesContainer.appendChild(el);
this.addCopyButton(el, content);
}
@@ -772,7 +772,7 @@ export class AgentChat extends Model {
private appendUserMessage(text: string) {
const el = document.createElement("div");
el.className = "agent-chat__msg agent-chat__msg--user";
- el.innerHTML = '<div class="agent-chat__bubble">' + this.escapeHtml(text) + "</div>";
+ el.innerHTML = '<div class="agent-chat__body">' + this.escapeHtml(text) + "</div>";
this.messagesContainer.appendChild(el);
this.scrollToBottom();
}
@@ -781,7 +781,7 @@ export class AgentChat extends Model {
this.currentContent = "";
const el = document.createElement("div");
el.className = "agent-chat__msg agent-chat__msg--ai";
- el.innerHTML = '<div class="agent-chat__bubble agent-chat__bubble--streaming"></div>';
+ el.innerHTML = '<div class="agent-chat__body agent-chat__body--streaming"></div>';
this.messagesContainer.appendChild(el);
this.scrollToBottom();
return el;
@@ -816,9 +816,9 @@ export class AgentChat extends Model {
this.pendingTokenUpdate = true;
this.rafId = requestAnimationFrame(() => {
this.pendingTokenUpdate = false;
- const bubble = this.currentAIElement?.querySelector(".agent-chat__bubble") as HTMLElement;
- if (bubble) {
- bubble.innerHTML = this.lute.MarkdownStr("", this.currentContent) || this.escapeHtml(this.currentContent);
+ const bodyEl = this.currentAIElement?.querySelector(".agent-chat__body") as HTMLElement;
+ if (bodyEl) {
+ bodyEl.innerHTML = this.lute.MarkdownStr("", this.currentContent) || this.escapeHtml(this.currentContent);
}
});
}
@@ -828,9 +828,9 @@ export class AgentChat extends Model {
if (this.pendingTokenUpdate) {
this.pendingTokenUpdate = false;
cancelAnimationFrame(this.rafId);
- const bubble = this.currentAIElement?.querySelector(".agent-chat__bubble") as HTMLElement;
- if (bubble) {
- bubble.innerHTML = this.lute.MarkdownStr("", this.currentContent) || this.escapeHtml(this.currentContent);
+ const bodyEl = this.currentAIElement?.querySelector(".agent-chat__body") as HTMLElement;
+ if (bodyEl) {
+ bodyEl.innerHTML = this.lute.MarkdownStr("", this.currentContent) || this.escapeHtml(this.currentContent);
}
}
}
@@ -922,8 +922,8 @@ export class AgentChat extends Model {
if (reasoning === "processing" && this.currentAIElement) {
if (this.currentContent) {
- const bubble = this.currentAIElement.querySelector(".agent-chat__bubble") as HTMLElement;
- if (bubble) { bubble.classList.remove("agent-chat__bubble--streaming"); }
+ const bodyEl = this.currentAIElement.querySelector(".agent-chat__body") as HTMLElement;
+ if (bodyEl) { bodyEl.classList.remove("agent-chat__body--streaming"); }
this.currentThinkingStepContent = this.currentContent;
this.currentAIElement.remove();
} else {
@@ -1047,7 +1047,7 @@ export class AgentChat extends Model {
}
private addCopyButton(el: HTMLElement, contentOverride?: string) {
- const content = contentOverride || this.fullContent || el.querySelector(".agent-chat__bubble")?.textContent || "";
+ const content = contentOverride || this.fullContent || el.querySelector(".agent-chat__body")?.textContent || "";
const L = window.siyuan.languages;
const actions = document.createElement("div");
@@ -1139,7 +1139,7 @@ export class AgentChat extends Model {
}
const el = document.createElement("div");
el.className = "agent-chat__msg agent-chat__msg--ai";
- el.innerHTML = '<div class="agent-chat__bubble">' + (this.lute.MarkdownStr("", savedContent) || this.escapeHtml(savedContent)) + "</div>";
+ el.innerHTML = '<div class="agent-chat__body">' + (this.lute.MarkdownStr("", savedContent) || this.escapeHtml(savedContent)) + "</div>";
this.messagesContainer.appendChild(el);
this.currentAIElement = el;
this.currentContent = savedContent;
@@ -1221,7 +1221,7 @@ export class AgentChat extends Model {
this.currentAIElement = null;
const el = document.createElement("div");
el.className = "agent-chat__msg agent-chat__msg--error";
- el.innerHTML = '<div class="agent-chat__bubble agent-chat__bubble--error">' + this.escapeHtml(message) + "</div>";
+ el.innerHTML = '<div class="agent-chat__body agent-chat__body--error">' + this.escapeHtml(message) + "</div>";
this.messagesContainer.appendChild(el);
this.scrollToBottom();
this.flushThinkingStep();
@@ -1263,7 +1263,7 @@ export class AgentChat extends Model {
}
const el = document.createElement("div");
el.className = "agent-chat__msg agent-chat__msg--ai";
- el.innerHTML = '<div class="agent-chat__bubble">' + (this.lute.MarkdownStr("", savedContent) || this.escapeHtml(savedContent)) + "</div>";
+ el.innerHTML = '<div class="agent-chat__body">' + (this.lute.MarkdownStr("", savedContent) || this.escapeHtml(savedContent)) + "</div>";
this.messagesContainer.appendChild(el);
this.currentAIElement = el;
this.currentContent = savedContent;
diff --git a/app/src/layout/dock/AgentComposer.ts b/app/src/layout/dock/AgentComposer.ts
index da4597015c..0f67b85bec 100644
--- a/app/src/layout/dock/AgentComposer.ts
+++ b/app/src/layout/dock/AgentComposer.ts
@@ -123,6 +123,8 @@ export function mountComposer(host: HTMLElement, onSend: () => void): ComposerHa
},
suggestion: {
char: "@",
+ allowToIncludeChar: true,
+ allowedPrefixes: null,
items: async function ({query}): Promise<BlockHit[]> {
try {
const resp = await fetch("/api/search/searchRefBlock", {