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/11782
Vanessad10b25c2ca93
diff --git a/.gitignore b/.gitignoreindex 7becaebeb4..1902cebe8b 100644--- a/.gitignore+++ b/.gitignore@@ -11,6 +11,7 @@app/node_modulesapp/stage/buildapp/build+app/src/types/distapp/kernel*iospprofdiff --git a/app/.eslintignore b/app/.eslintignoreindex 55ab40b0b0..10a626b12f 100644--- a/app/.eslintignore+++ b/app/.eslintignore@@ -1,7 +1,6 @@build-distnode_modules-publicsrc/asset/pdf+src/types/diststageappearancediff --git a/app/src/block/util.ts b/app/src/block/util.tsindex ec34570a62..272c2422d4 100644--- a/app/src/block/util.ts+++ b/app/src/block/util.ts@@ -85,10 +85,10 @@ export const jumpToParent = (protyle: IProtyle, nodeElement: Element, type: "paropenFileById({app: protyle.app,id: targetId,- action: [Constants.CB_GET_FOCUS, targetId !== protyle.block.rootID && protyle.block.showAll ? Constants.CB_GET_ALL : ""]+ action: targetId !== protyle.block.rootID && protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS]});/// #else- openMobileFileById(protyle.app, targetId, [Constants.CB_GET_FOCUS, targetId !== protyle.block.rootID && protyle.block.showAll ? Constants.CB_GET_ALL : ""]);+ openMobileFileById(protyle.app, targetId, targetId !== protyle.block.rootID && protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS]);/// #endif});};diff --git a/app/src/boot/globalEvent/command/global.ts b/app/src/boot/globalEvent/command/global.tsindex 726ec33e96..356f57132f 100644--- a/app/src/boot/globalEvent/command/global.ts+++ b/app/src/boot/globalEvent/command/global.ts@@ -262,10 +262,10 @@ export const globalCommand = (command: string, app: App) => {if (command === "closeTab") {const activeTabElement = document.querySelector(".layout__tab--active");if (activeTabElement && activeTabElement.getBoundingClientRect().width > 0) {- let type = "";+ let type: TDock;Array.from(activeTabElement.classList).find(item => {if (item.startsWith("sy__")) {- type = item.replace("sy__", "");+ type = item.replace("sy__", "") as TDock;return true;}});diff --git a/app/src/editor/util.ts b/app/src/editor/util.tsindex 26a47bc5bb..03e34e2439 100644--- a/app/src/editor/util.ts+++ b/app/src/editor/util.ts@@ -41,7 +41,7 @@ export const openFileById = async (options: {id: string,position?: string,mode?: TEditorMode,- action?: string[]+ action?: TProtyleAction[]keepCursor?: booleanzoomIn?: booleanremoveCurrentTab?: booleandiff --git a/app/src/layout/dock/Bookmark.ts b/app/src/layout/dock/Bookmark.tsindex 0b0d0c5a70..c655882d76 100644--- a/app/src/layout/dock/Bookmark.ts+++ b/app/src/layout/dock/Bookmark.ts@@ -85,7 +85,7 @@ export class Bookmark extends Model {}}const id = element.getAttribute("data-node-id");- checkFold(id, (zoomIn, action: string[]) => {+ checkFold(id, (zoomIn, action: TProtyleAction[]) => {openFileById({app,id,@@ -111,7 +111,7 @@ export class Bookmark extends Model {},altClick: (element: HTMLElement,) => {const id = element.getAttribute("data-node-id");- checkFold(id, (zoomIn, action: string[]) => {+ checkFold(id, (zoomIn, action: TProtyleAction[]) => {openFileById({app,id,@@ -123,7 +123,7 @@ export class Bookmark extends Model {},shiftClick: (element: HTMLElement) => {const id = element.getAttribute("data-node-id");- checkFold(id, (zoomIn, action: string[]) => {+ checkFold(id, (zoomIn, action: TProtyleAction[]) => {openFileById({app,id,diff --git a/app/src/layout/dock/Graph.ts b/app/src/layout/dock/Graph.tsindex 43faa20f03..99c3d7f2b2 100644--- a/app/src/layout/dock/Graph.ts+++ b/app/src/layout/dock/Graph.ts@@ -667,7 +667,7 @@ export class Graph extends Model {return;}if (window.siyuan.shiftIsPressed) {- checkFold(node.id, (zoomIn, action: string[]) => {+ checkFold(node.id, (zoomIn, action: TProtyleAction[]) => {openFileById({app: this.app,id: node.id,@@ -677,7 +677,7 @@ export class Graph extends Model {});});} else if (window.siyuan.altIsPressed) {- checkFold(node.id, (zoomIn, action: string[]) => {+ checkFold(node.id, (zoomIn, action: TProtyleAction[]) => {openFileById({app: this.app,id: node.id,@@ -695,7 +695,7 @@ export class Graph extends Model {nodeIds: [node.id],}));} else {- checkFold(node.id, (zoomIn, action: string[]) => {+ checkFold(node.id, (zoomIn, action: TProtyleAction[]) => {openFileById({app: this.app,id: node.id,diff --git a/app/src/layout/dock/index.ts b/app/src/layout/dock/index.tsindex eaf289b2e5..aa8d5d930a 100644--- a/app/src/layout/dock/index.ts+++ b/app/src/layout/dock/index.ts@@ -29,7 +29,7 @@ export class Dock {private app: App;public resizeElement: HTMLElement;public pin = true;- public data: { [key: string]: Model | boolean };+ public data: { [key in TDock | string]?: Model | boolean };private hideResizeTimeout: number;constructor(options: {@@ -112,13 +112,13 @@ export class Dock {this.resizeElement.classList.add("fn__none");} else {activeElements.forEach(item => {- this.toggleModel(item.getAttribute("data-type"), true, false, false, false);+ this.toggleModel(item.getAttribute("data-type") as TDock, true, false, false, false);});}this.element.addEventListener("click", (event) => {let target = event.target as HTMLElement;while (target && !target.isEqualNode(this.element)) {- const type = target.getAttribute("data-type");+ const type = target.getAttribute("data-type") as TDock;if (type) {this.toggleModel(type, false, true);event.preventDefault();@@ -359,7 +359,7 @@ export class Dock {documentSelf.onselect = null;this.setSize();this.element.querySelectorAll(".dock__item--active").forEach(item => {- const customModel = this.data[item.getAttribute("data-type")];+ const customModel = this.data[item.getAttribute("data-type") as TDock];if (customModel && customModel instanceof Custom && customModel.resize) {customModel.resize();}@@ -491,7 +491,7 @@ export class Dock {this.layout.element.querySelector(".layout__tab--active")?.classList.remove("layout__tab--active");}- public toggleModel(type: string, show = false, close = false, hide = false, isSaveLayout = true) {+ public toggleModel(type: TDock | string, show = false, close = false, hide = false, isSaveLayout = true) {if (!type) {return;}@@ -757,7 +757,7 @@ export class Dock {public add(index: number, sourceElement: Element, previousType?: string) {sourceElement.setAttribute("data-height", "");sourceElement.setAttribute("data-width", "");- const type = sourceElement.getAttribute("data-type");+ const type = sourceElement.getAttribute("data-type") as TDock;const sourceDock = getDockByType(type);if (sourceDock.element.querySelectorAll(".dock__item").length === 2) {sourceDock.element.classList.add("fn__none");@@ -794,7 +794,7 @@ export class Dock {saveLayout();}- public remove(key: string) {+ public remove(key: TDock|string) {this.toggleModel(key, false, true, true);this.element.querySelector(`[data-type="${key}"]`).remove();const custom = this.data[key] as Custom;@@ -809,12 +809,12 @@ export class Dock {activesElement.forEach((item) => {if (this.position === "Left" || this.position === "Right") {if (item.getAttribute("data-index") === "1" && activesElement.length > 1) {- item.setAttribute("data-height", (this.data[item.getAttribute("data-type")] as Model).parent.parent.element.clientHeight.toString());+ item.setAttribute("data-height", (this.data[item.getAttribute("data-type") as TDock] as Model).parent.parent.element.clientHeight.toString());}item.setAttribute("data-width", this.layout.element.clientWidth.toString());} else {if (item.getAttribute("data-index") === "1" && activesElement.length > 1) {- item.setAttribute("data-width", (this.data[item.getAttribute("data-type")] as Model).parent.parent.element.clientWidth.toString());+ item.setAttribute("data-width", (this.data[item.getAttribute("data-type") as TDock] as Model).parent.parent.element.clientWidth.toString());}item.setAttribute("data-height", this.layout.element.clientHeight.toString());}diff --git a/app/src/layout/tabUtil.ts b/app/src/layout/tabUtil.tsindex 20e9a06614..dce287d716 100644--- a/app/src/layout/tabUtil.ts+++ b/app/src/layout/tabUtil.ts@@ -66,7 +66,7 @@ export const switchTabByIndex = (index: number) => {indexElement = activeDockIcoElement.parentElement.firstElementChild;}}- const type = indexElement?.getAttribute("data-type");+ const type = indexElement?.getAttribute("data-type") as TDock;if (type) {getDockByType(type)?.toggleModel(type, true, false);}@@ -142,7 +142,7 @@ export const resizeTabs = (isSaveLayout = true) => {}, 200);};-export const getDockByType = (type: string) => {+export const getDockByType = (type: TDock | string) => {if (!window.siyuan.layout.leftDock) {return undefined;}@@ -253,7 +253,7 @@ export const copyTab = (app: App, tab: Tab) => {callback(newTab: Tab) {let model: Model;if (tab.model instanceof Editor) {- const newAction: string[] = [];+ const newAction: TProtyleAction[] = [];// https://github.com/siyuan-note/siyuan/issues/12132tab.model.editor.protyle.block.action.forEach(item => {if (item !== Constants.CB_GET_APPEND && item !== Constants.CB_GET_BEFORE && item !== Constants.CB_GET_HTML) {diff --git a/app/src/plugin/API.ts b/app/src/plugin/API.tsindex 4fd55ab9f8..be984db7ea 100644--- a/app/src/plugin/API.ts+++ b/app/src/plugin/API.ts@@ -18,6 +18,7 @@ import {Protyle} from "../protyle";import {openMobileFileById} from "../mobile/editor";import {lockScreen, exitSiYuan} from "../dialog/processSystem";import {Model} from "../layout/Model";+import {getDockByType} from "../layout/tabUtil";let openTab;let openWindow;@@ -52,7 +53,7 @@ openTab = (options: {app: App,doc?: {id: string, // 块 id- action?: string [] // cb-get-all:获取所有内容;cb-get-focus:打开后光标定位在 id 所在的块;cb-get-hl: 打开后 id 块高亮+ action?: TProtyleAction [] // cb-get-all:获取所有内容;cb-get-focus:打开后光标定位在 id 所在的块;cb-get-hl: 打开后 id 块高亮zoomIn?: boolean // 是否缩放},pdf?: {@@ -166,23 +167,24 @@ openTab = (options: {/// #endifexport const API = {+ adaptHotkey: updateHotkeyTip,confirm: confirmDialog,+ Constants,showMessage,- adaptHotkey: updateHotkeyTip,fetchPost,fetchSyncPost,fetchGet,getFrontend,getBackend,- lockScreen,- exitSiYuan,- openMobileFileById,+ getDockByType,openTab,openWindow,+ openMobileFileById,+ lockScreen,+ exitSiYuan,Protyle,Plugin,Dialog,Menu,Setting,- Constants,};diff --git a/app/src/plugin/EventBus.ts b/app/src/plugin/EventBus.tsindex 591d40b4a4..40ea3f9f80 100644--- a/app/src/plugin/EventBus.ts+++ b/app/src/plugin/EventBus.ts@@ -8,9 +8,6 @@ export class EventBus<DetailType = any> {}on(type: TEventBus, listener: (event: CustomEvent<DetailType>) => void) {- if (type ==="loaded-protyle") {- console.warn("0.8.8 将移除 loaded-protyle, 请使用 loaded-protyle-static 进行替代");- }this.eventTarget.addEventListener(type, listener);}diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.tsindex e5e10f5b37..8504816b24 100644--- a/app/src/protyle/scroll/saveScroll.ts+++ b/app/src/protyle/scroll/saveScroll.ts@@ -56,7 +56,7 @@ export const getDocByScroll = (options: {focus?: boolean,updateReadonly?: boolean}) => {- let actions: string[] = [];+ let actions: TProtyleAction[] = [];if (options.mergedOptions) {actions = options.mergedOptions.action;} else {diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.tsindex c882af144e..212af95a9e 100644--- a/app/src/protyle/util/onGet.ts+++ b/app/src/protyle/util/onGet.ts@@ -24,7 +24,7 @@ import {getContenteditableElement} from "../wysiwyg/getBlock";export const onGet = (options: {data: IWebSocketData,protyle: IProtyle,- action?: string[],+ action?: TProtyleAction[],scrollAttr?: IScrollAttrupdateReadonly?: booleanafterCB?: () => void@@ -290,7 +290,6 @@ const setHTML = (options: {}protyle.app.plugins.forEach(item => {- item.eventBus.emit("loaded-protyle", protyle); // 准备废弃item.eventBus.emit("loaded-protyle-static", {protyle});});};diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.tsindex 9bebba93fc..1f2676dad8 100644--- a/app/src/types/config.d.ts+++ b/app/src/types/config.d.ts@@ -1646,7 +1646,7 @@ declare namespace Config {/*** Tab type*/- type: string;+ type: TDock | string;}/**diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex 7bd5e7370d..5c1fd76be3 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -1,6 +1,7 @@type TPluginDockPosition = "LeftTop" | "LeftBottom" | "RightTop" | "RightBottom" | "BottomLeft" | "BottomRight"type TDockPosition = "Left" | "Right" | "Bottom"type TWS = "main" | "filetree" | "protyle"+type TDock = "file" | "outline" | "inbox" | "bookmark" | "tag" | "graph" | "globalGraph" | "backlink"type TOperation ="insert"| "update"@@ -63,7 +64,7 @@ type TEventBus = "ws-main" | "sync-start" | "sync-end" | "sync-fail" |"closed-notebook" |"paste" |"input-search" |- "loaded-protyle" | "loaded-protyle-dynamic" | "loaded-protyle-static" |+ "loaded-protyle-dynamic" | "loaded-protyle-static" |"switch-protyle" |"destroy-protyle" |"lock-screen" |@@ -316,7 +317,7 @@ interface IBackStack {notebookId: string},scrollTop?: number,- callback?: string[],+ callback?: TProtyleAction[],position?: {start: number,end: number@@ -543,7 +544,7 @@ interface IOpenFileOptions {position?: string, // file 或者 asset,打开位置page?: number | string, // assetmode?: TEditorMode // file- action?: string[]+ action?: TProtyleAction[]keepCursor?: boolean // file,是否跳转到新 tab 上zoomIn?: boolean // 是否缩放removeCurrentTab?: boolean // 在当前页签打开时需移除原有页签diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.tsindex c6dc2ff626..0ba62b5afd 100644--- a/app/src/types/protyle.d.ts+++ b/app/src/types/protyle.d.ts@@ -498,7 +498,7 @@ interface IProtyle {showAll?: booleanmode?: numberblockCount?: number- action?: string[]+ action?: TProtyleAction[]},disabled: boolean,selectElement?: HTMLElement,diff --git a/app/src/util/noRelyPCFunction.ts b/app/src/util/noRelyPCFunction.tsindex b82a18f28e..4d9e29bb4a 100644--- a/app/src/util/noRelyPCFunction.ts+++ b/app/src/util/noRelyPCFunction.ts@@ -35,7 +35,7 @@ export const getWorkspaceName = () => {return pathPosix().basename(window.siyuan.config.system.workspaceDir.replace(/\\/g, "/"));};-export const checkFold = (id: string, cb: (zoomIn: boolean, action: string[], isRoot: boolean) => void) => {+export const checkFold = (id: string, cb: (zoomIn: boolean, action: TProtyleAction[], isRoot: boolean) => void) => {if (!id) {return;}diff --git a/app/tsconfig.json b/app/tsconfig.jsonindex 9480e89536..47999d51a6 100644--- a/app/tsconfig.json+++ b/app/tsconfig.json@@ -1,6 +1,6 @@{"compilerOptions": {- "outDir": "./dist/",+ "outDir": "./src/types/dist","noImplicitAny": true,"module": "commonjs","target": "es6",