An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/18151
Vanessab991bc53f7e4
diff --git a/app/src/layout/dock/agent/AgentChat.ts b/app/src/layout/dock/agent/AgentChat.tsindex a4efd96cd8..926445cb28 100644--- a/app/src/layout/dock/agent/AgentChat.ts+++ b/app/src/layout/dock/agent/AgentChat.ts@@ -15,8 +15,7 @@ import {getAgentLute} from "../../../protyle/render/setLute";import {setPanelFocus} from "../../util";import {escapeAriaLabel, escapeHtml} from "../../../util/escape";import {setPosition} from "../../../util/setPosition";-import {fetchPost, fetchSyncPost} from "../../../util/fetch";-import {Constants} from "../../../constants";+import {fetchPost} from "../../../util/fetch";import {confirmDialog} from "../../../dialog/confirmDialog";import {showMessage} from "../../../dialog/message";import * as dayjs from "dayjs";@@ -302,8 +301,7 @@ export class AgentChat extends Model {// 内容变化时刷新发送按钮可用性(含用户输入、IME、程序化 clear 等所有 doc 变更)。this.updateSendButtonState();});- // 支持从编辑器块标或文档面板拖拽块到输入框,效果等同于 @ 引用。- this.bindComposerDragDrop();+ // 块拖拽由 protyle 统一处理(复制块/引用/嵌入块→引用),无需自定义 drop handler。this.sessionPanel = new AgentSessionPanel(this.sessionMenuBtn,this.parent.panelElement,@@ -369,65 +367,6 @@ export class AgentChat extends Model {}}- // 绑定输入框的块拖拽:从编辑器块标或文档面板拖拽块到输入框,插入 @ 引用(mention chip)。- // 与 @ 搜索的 label 来源一致——用 getRefText API 按 block ID 查询引用文本。- private bindComposerDragDrop() {- this.composerHost.addEventListener("dragover", (e: DragEvent) => {- if (!e.dataTransfer) { return; }- // 仅接受块标拖拽(SIYUAN_DROP_GUTTER)和文档面板拖拽(SIYUAN_DROP_FILE)。- let canDrop = false;- for (const type of e.dataTransfer.types) {- if (type.startsWith(Constants.SIYUAN_DROP_GUTTER) || type === Constants.SIYUAN_DROP_FILE) {- canDrop = true;- break;- }- }- if (canDrop) {- e.preventDefault();- e.dataTransfer.dropEffect = "copy";- }- });- this.composerHost.addEventListener("drop", async (e: DragEvent) => {- if (!e.dataTransfer || !this.composer) { return; }- const blockIds: string[] = [];- // 块标拖拽:从 MIME type key 提取所有 block ID(gutterTypes[2])。- for (const type of e.dataTransfer.types) {- if (type.startsWith(Constants.SIYUAN_DROP_GUTTER)) {- const gutterTypes = type.replace(Constants.SIYUAN_DROP_GUTTER, "").split(Constants.ZWSP);- const ids = (gutterTypes[2] || "").split(",").filter(Boolean);- blockIds.push(...ids);- break;- }- }- // 文档面板拖拽:数据值是逗号分隔的 doc ID,全部收集。- if (blockIds.length === 0) {- const fileData = e.dataTransfer.getData(Constants.SIYUAN_DROP_FILE);- if (fileData) {- blockIds.push(...fileData.split(",").filter(Boolean));- }- }- if (blockIds.length === 0) { return; }- e.preventDefault();- e.stopPropagation();- // 用 getRefText API 并行获取每个块的引用文本作为 label(与 @ 搜索一致),- // 失败时回退到 blockId。- const mentions: Array<{id: string; label: string}> = [];- await Promise.all(blockIds.map(async (id) => {- let label = id;- try {- const resp = await fetchSyncPost("/api/block/getRefText", {id});- if (resp && resp.data) {- label = resp.data;- }- } catch {- label = id;- }- mentions.push({id, label});- }));- this.composer.insertMentions(mentions);- });- }-// 将外部块引用以 mention chip 形式追加到发送框末尾,等价于拖拽块到发送框或在框内 @ 搜索选块。public insertBlockMentions(mentions: Array<{ id: string; label: string }>) {if (this.composer && mentions.length > 0) {diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.tsindex 52dd323f11..9cd26f0799 100644--- a/app/src/protyle/util/editorCommonEvent.ts+++ b/app/src/protyle/util/editorCommonEvent.ts@@ -767,6 +767,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {document.onmouseup = null;});editorElement.addEventListener("drop", async (event: DragEvent & { target: HTMLElement }) => {+ // lite 模式不落盘,拖拽块时强制复制语义(避免移动操作删除源块)。+ const isCopyDrag = protyle.lite || event.ctrlKey;counter = 0;hideDragTip();window.siyuan.dragTitle = "";@@ -828,7 +830,9 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {}}}- if (event.altKey) {+ if (event.altKey || (event.shiftKey && protyle.lite)) {+ // 引用:getRefText → Md2BlockDOM((id 'text'))+ // lite 模式下 Shift(原嵌入块)也走引用,避免依赖后端 SQL 查询的嵌入块。let html = "";for (let i = 0; i < selectedIds.length; i++) {const response = await fetchSyncPost("/api/block/getRefText", {id: selectedIds[i]});@@ -1204,9 +1208,9 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {const anchorBlock = contentBlocks.length > 0 ? contentBlocks[contentBlocks.length - 1] : null;if (anchorBlock) {// 插到最后一个内容块之后:moveTo 会把段落放在子列表之前,形成列表项内容- dragSame(protyle, sourceElements, anchorBlock, true, event.ctrlKey);+ dragSame(protyle, sourceElements, anchorBlock, true, isCopyDrag);} else {- dragSame(protyle, sourceElements, contentLi, isBottom, event.ctrlKey);+ dragSame(protyle, sourceElements, contentLi, isBottom, isCopyDrag);}liGapIntercepted = true;}@@ -1226,7 +1230,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {if (nestedTarget) {// 拖拽自身子列表项到父项位置时,nestedTarget 可能就是源项自身,需跳过避免自己拖到自己if (!sourceElements.includes(nestedTarget)) {- dragSame(protyle, sourceElements, nestedTarget, isBottom, event.ctrlKey);+ dragSame(protyle, sourceElements, nestedTarget, isBottom, isCopyDrag);}} else {// 目标列表项无嵌套子列表:定位其最后一个内容块,在其后插入,@@ -1236,18 +1240,18 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {const lastContentBlock = contentBlocks[contentBlocks.length - 1];if (lastContentBlock) {// 嵌套列表始终创建在最后一个内容块之后- dragSame(protyle, sourceElements, lastContentBlock, true, event.ctrlKey);+ dragSame(protyle, sourceElements, lastContentBlock, true, isCopyDrag);} else {- dragSame(protyle, sourceElements, targetElement, isBottom, event.ctrlKey);+ dragSame(protyle, sourceElements, targetElement, isBottom, isCopyDrag);}}} else if (targetElement.parentElement.getAttribute("data-type") === "NodeSuperBlock" &&targetElement.parentElement.getAttribute("data-sb-layout") === "col") {if (targetClass.includes("dragover__left") || targetClass.includes("dragover__right")) {// Mac 上 ⌘ 无法进行拖拽- dragSame(protyle, sourceElements, targetElement, targetClass.includes("dragover__right"), event.ctrlKey);+ dragSame(protyle, sourceElements, targetElement, targetClass.includes("dragover__right"), isCopyDrag);} else {- dragSb(protyle, sourceElements, targetElement, isBottom, "row", event.ctrlKey);+ dragSb(protyle, sourceElements, targetElement, isBottom, "row", isCopyDrag);}} else {// 列表项拖到列表容器边缘时禁止形成横向超级块(列表块拖到列表边缘可形成超级块)@@ -1257,9 +1261,9 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {(targetClass.includes("dragover__left") || targetClass.includes("dragover__right"))) {// 列表项拖到列表左右边缘:无操作} else if (targetClass.includes("dragover__left") || targetClass.includes("dragover__right")) {- dragSb(protyle, sourceElements, targetElement, targetClass.includes("dragover__right"), "col", event.ctrlKey);+ dragSb(protyle, sourceElements, targetElement, targetClass.includes("dragover__right"), "col", isCopyDrag);} else {- dragSame(protyle, sourceElements, targetElement, isBottom, event.ctrlKey);+ dragSame(protyle, sourceElements, targetElement, isBottom, isCopyDrag);}}@@ -1535,11 +1539,13 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {// 提示文案:修饰键显示对应操作,无修饰键显示插入位置const targetText = (getContenteditableElement(htmlTarget)?.textContent?.trim() || "").slice(0, 20);let action: string;- if (event.altKey) {+ if (event.altKey || (event.shiftKey && protyle.lite)) {+ // Alt=引用;lite 模式 Shift 也为引用action = window.siyuan.languages.dragTipRef;} else if (event.shiftKey) {action = window.siyuan.languages.dragTipEmbed;- } else if (event.ctrlKey) {+ } else if (event.ctrlKey || protyle.lite) {+ // Ctrl=创建副本;lite 模式无修饰键也为复制action = window.siyuan.languages.duplicate;} else if (isChild) {action = window.siyuan.languages.dragTipListItemChild.replace("${x}", targetText);@@ -1594,13 +1600,14 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {if (isAvTarget) {// 拖到数据库视图:绑定为记录action = window.siyuan.languages.addToDatabase;- } else if (event.ctrlKey) {- // Ctrl=创建副本- action = window.siyuan.languages.duplicate;- } else if (event.altKey) {+ } else if (event.altKey || (event.shiftKey && protyle.lite)) {+ // Alt=引用;lite 模式 Shift 也为引用(原嵌入块改为引用)action = window.siyuan.languages.dragTipRef;} else if (event.shiftKey) {action = window.siyuan.languages.dragTipEmbed;+ } else if (event.ctrlKey || protyle.lite) {+ // Ctrl=创建副本;lite 模式无修饰键也为复制(不移动源块)+ action = window.siyuan.languages.duplicate;} else {action = window.siyuan.languages.move;}