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/4494
Vanessa86311447d1b6
diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.tsindex e4f8fc4edd..e94fac6712 100644--- a/app/src/layout/Wnd.ts+++ b/app/src/layout/Wnd.ts@@ -94,7 +94,7 @@ export class Wnd {while (target && !target.isEqualNode(this.headersElement)) {if (target.classList.contains("item__close") && target.getAttribute("data-type") === "new") {setPanelFocus(this.headersElement.parentElement.parentElement);- newFile(undefined, undefined, true);+ newFile(undefined, undefined, undefined, true);break;} else if (target.classList.contains("item__close") && target.getAttribute("data-type") === "more") {this.renderTabList(event);diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.tsindex cf69566532..66c9d4ead0 100644--- a/app/src/layout/dock/Files.ts+++ b/app/src/layout/dock/Files.ts@@ -231,7 +231,7 @@ export class Files extends Model {const pathString = target.parentElement.getAttribute("data-path");if (!window.siyuan.config.readonly) {if (type === "new") {- newFile(notebookId, pathString, true);+ newFile(notebookId, pathString);} else if (type === "more-root") {initNavigationMenu(target.parentElement).popup({x: event.clientX, y: event.clientY});}diff --git a/app/src/layout/util.ts b/app/src/layout/util.tsindex 17772986b4..cd2d78ce31 100644--- a/app/src/layout/util.ts+++ b/app/src/layout/util.ts@@ -735,7 +735,7 @@ export const newCenterEmptyTab = () => {newNotebook();});tab.panelElement.querySelector("#editorEmptyFile").addEventListener("click", () => {- newFile(undefined, undefined, true);+ newFile(undefined, undefined, undefined, true);});}}diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.tsindex 0542caf6c8..ac5f0070ac 100644--- a/app/src/menus/navigation.ts+++ b/app/src/menus/navigation.ts@@ -206,7 +206,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:paths.push(item.getAttribute("data-path"));}});- newFile(notebookId, pathPosix().dirname(pathString), true, paths);+ newFile(notebookId, pathPosix().dirname(pathString), paths);}}).element);window.siyuan.menus.menu.append(new MenuItem({@@ -222,7 +222,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:}}});- newFile(notebookId, pathPosix().dirname(pathString), true, paths);+ newFile(notebookId, pathPosix().dirname(pathString), paths);}}).element);window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);diff --git a/app/src/mobile/util/MobileFiles.ts b/app/src/mobile/util/MobileFiles.tsindex 928fa4c060..681068ddd4 100644--- a/app/src/mobile/util/MobileFiles.ts+++ b/app/src/mobile/util/MobileFiles.ts@@ -174,7 +174,7 @@ export class MobileFiles extends Model {const notebookId = ulElement.getAttribute("data-url");if (!window.siyuan.config.readonly) {if (type === "new") {- newFile(notebookId, pathString, true);+ newFile(notebookId, pathString);} else if (type === "more-root") {initNavigationMenu(target.parentElement).popup({x, y});window.siyuan.menus.menu.element.style.zIndex = "310";diff --git a/app/src/mobile/util/setEmpty.ts b/app/src/mobile/util/setEmpty.tsindex 1b68ab2747..b39618c0f7 100644--- a/app/src/mobile/util/setEmpty.ts+++ b/app/src/mobile/util/setEmpty.ts@@ -21,11 +21,11 @@ export const setEmpty = () => {</div>`;document.getElementById("emptyNewFile").addEventListener(getEventName(), () => {if (window.siyuan.mobile.editor) {- newFile(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path, true);+ newFile(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path, undefined, true);} else {window.siyuan.notebooks.find(item => {if (item.closed) {- newFile(item.id, "/", true);+ newFile(item.id, "/", undefined, true);}});}diff --git a/app/src/util/globalShortcut.ts b/app/src/util/globalShortcut.tsindex 4ac287f352..c327f4fa98 100644--- a/app/src/util/globalShortcut.ts+++ b/app/src/util/globalShortcut.ts@@ -597,7 +597,7 @@ export const globalShortcut = () => {return;}if (matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {- newFile(undefined, undefined, true);+ newFile(undefined, undefined, undefined, true);event.preventDefault();return;}diff --git a/app/src/util/newFile.ts b/app/src/util/newFile.tsindex bf6f2640b7..38b8f794a3 100644--- a/app/src/util/newFile.ts+++ b/app/src/util/newFile.ts@@ -11,7 +11,7 @@ import {getDisplayName, getOpenNotebookCount, pathPosix} from "./pathName";import {Constants} from "../constants";import {validateName} from "../editor/rename";-export const newFile = (notebookId?: string, currentPath?: string, open?: boolean, paths?: string[]) => {+export const newFile = (notebookId?: string, currentPath?: string, paths?: string[], useSavePath = false) => {if (getOpenNotebookCount() === 0) {showMessage(window.siyuan.languages.newFileTip);return;@@ -54,27 +54,56 @@ export const newFile = (notebookId?: string, currentPath?: string, open?: boolea});}fetchPost("/api/filetree/getDocCreateSavePath", {notebook: notebookId}, (data) => {- const id = Lute.NewNodeID();- const newPath = pathPosix().join(getDisplayName(currentPath, false, true), id + ".sy");- if (paths) {- paths[paths.indexOf(undefined)] = newPath;- }- if (!validateName(data.data.path)) {- return;- }- fetchPost("/api/filetree/createDoc", {- notebook: notebookId,- path: newPath,- title: data.data.name || "Untitled",- md: "",- sorts: paths- }, () => {- /// #if !MOBILE- if (open) {- openFileById({id, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});+ if (data.data.path.indexOf("/") > -1 && useSavePath) {+ if (data.data.path.startsWith("/")) {+ fetchPost("/api/filetree/createDocWithMd", {+ notebook: notebookId,+ path: data.data.path,+ markdown: ""+ }, response => {+ /// #if !MOBILE+ openFileById({id: response.data, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});+ /// #endif+ });+ } else {+ fetchPost("/api/filetree/getHPathByPath", {+ notebook: notebookId,+ path: currentPath+ }, (responseHPath) => {+ fetchPost("/api/filetree/createDocWithMd", {+ notebook: notebookId,+ path: pathPosix().join(responseHPath.data, data.data.path),+ markdown: ""+ }, response => {+ /// #if !MOBILE+ openFileById({id: response.data, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});+ /// #endif+ });+ });}- /// #endif- });+ } else {+ let title = data.data.path || "Untitled"+ title = title.substring(title.lastIndexOf("/") + 1);+ if (!validateName(title)) {+ return;+ }+ const id = Lute.NewNodeID();+ const newPath = pathPosix().join(getDisplayName(currentPath, false, true), id + ".sy");+ if (paths.length > 0) {+ paths[paths.indexOf(undefined)] = newPath;+ }+ fetchPost("/api/filetree/createDoc", {+ notebook: notebookId,+ path: newPath,+ title,+ md: "",+ sorts: paths+ }, () => {+ /// #if !MOBILE+ openFileById({id, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});+ /// #endif+ });+ }});};