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/18589
Vanessafbf6f60b3467
diff --git a/app/src/protyle/hint/createTargetContext.test.ts b/app/src/protyle/hint/createTargetContext.test.tsnew file mode 100644index 0000000000..7725e3718c--- /dev/null+++ b/app/src/protyle/hint/createTargetContext.test.ts@@ -0,0 +1,20 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {getCreateTargetContext, isSameCreateTargetContext} from "./createTargetContext";++describe("create target context", () => {+ it("treats missing lite editor context as empty context", () => {+ const context = getCreateTargetContext({} as IProtyle);++ assert.equal(isSameCreateTargetContext(context, {} as IProtyle), true);+ });++ it("detects document context changes", () => {+ const context = getCreateTargetContext({notebookId: "box", path: "/old.sy"} as IProtyle);++ assert.equal(isSameCreateTargetContext(context, {+ notebookId: "box",+ path: "/new.sy",+ } as IProtyle), false);+ });+});diff --git a/app/src/protyle/hint/createTargetContext.ts b/app/src/protyle/hint/createTargetContext.tsnew file mode 100644index 0000000000..5b82f5f6db--- /dev/null+++ b/app/src/protyle/hint/createTargetContext.ts@@ -0,0 +1,17 @@+export interface CreateTargetContext {+ notebookId: string;+ path: string;+}++export const getCreateTargetContext = (protyle: Pick<IProtyle, "notebookId" | "path">): CreateTargetContext => ({+ notebookId: protyle.notebookId || "",+ path: protyle.path || "",+});++export const isSameCreateTargetContext = (+ context: CreateTargetContext,+ protyle: Pick<IProtyle, "notebookId" | "path">,+) => {+ const current = getCreateTargetContext(protyle);+ return context.notebookId === current.notebookId && context.path === current.path;+};diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.tsindex 6ebfdac028..cc9b5844a7 100644--- a/app/src/protyle/hint/index.ts+++ b/app/src/protyle/hint/index.ts@@ -56,6 +56,7 @@ import {genIconHTML} from "../render/util";import {updateAttrViewCellAnimation} from "../render/av/action";import {setFold} from "../util/blockFold";import {getIconValueKind} from "../../emoji/iconValue";+import {getCreateTargetContext, isSameCreateTargetContext} from "./createTargetContext";const genEmojiInsertHTML = (value: string) => {const kind = getIconValueKind(value);@@ -150,8 +151,7 @@ export class Hint {}public prepareCreateTarget(protyle: IProtyle, type: TCreateTargetType) {- const notebookId = protyle.notebookId || "";- const path = protyle.path || "";+ const {notebookId, path} = getCreateTargetContext(protyle);if (this.element.classList.contains("fn__none") || !this.createTargetSession ||this.createTargetSession.notebookId !== notebookId || this.createTargetSession.path !== path) {this.createTargetSession = {@@ -182,7 +182,7 @@ export class Hint {result: targetState.result,promise: targetState.promise,isCurrent: () => this.createTargetSession === session && session.renderID === renderID &&- session.notebookId === protyle.notebookId && session.path === protyle.path &&+ isSameCreateTargetContext(session, protyle) &&!this.element.classList.contains("fn__none"),};}