AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(ai): open generated note URLs in workspace
tianma-ifa91174a9c8cb
diff --git a/apps/desktop/src/main/acp-host.mjs b/apps/desktop/src/main/acp-host.mjsindex 736432ca..1b7438d2 100644--- a/apps/desktop/src/main/acp-host.mjs+++ b/apps/desktop/src/main/acp-host.mjs@@ -943,7 +943,7 @@ export function createAcpHostRuntime(options = {}) {if (mcpBridge) {content.blocks.splice(input.adapterId === "codex" ? 1 : 0, 0, {type: "text",- text: "For EdgeEver note operations in this conversation, use only the session-provided MCP server named edgeever-current-workspace. It is connected to the account currently signed in to EdgeEver. Ignore any EdgeEver MCP server from your persistent configuration, which may target a different instance or account. When you create a note, include a clickable Markdown link to it in your final answer: [note title](#memo=exact_memo_id_from_tool_result). Do not show the note ID as plain text.",+ text: "For EdgeEver note operations in this conversation, use only the session-provided MCP server named edgeever-current-workspace. It is connected to the account currently signed in to EdgeEver. Ignore any EdgeEver MCP server from your persistent configuration, which may target a different instance or account. When you create a note, include a clickable Markdown link to it in your final answer: [note title](#memo=exact_memo_id_from_tool_result). Do not show the note ID as plain text or use an https://edgeever.ai/memo/ URL; that URL opens an external website instead of the current workspace.",});}} catch (error) {diff --git a/apps/web/src/components/CompanionCreatedNoteLinks.test.mjs b/apps/web/src/components/CompanionCreatedNoteLinks.test.mjsindex 7a079c62..9eb9520b 100644--- a/apps/web/src/components/CompanionCreatedNoteLinks.test.mjs+++ b/apps/web/src/components/CompanionCreatedNoteLinks.test.mjs@@ -24,6 +24,12 @@ describe("created note links", () => {expect(missingCreatedNoteLinks("[note:memo_abc]", [created])).toEqual([]);});+ test("does not duplicate a created note linked through a legacy absolute URL", () => {+ const id = "memo_328cb20d4b4040edb3ecb24638abc2d5";+ const tool = { ...created, effects: [{ kind: "created", memoId: id, title: "流程图" }] };+ expect(missingCreatedNoteLinks(`[流程图](https://edgeever.ai/memo/${id})`, [tool])).toEqual([]);+ });+test("ignores failed tools and links each successful creation once", () => {expect(missingCreatedNoteLinks("", [{ ...created, status: "error" }, created, created,diff --git a/apps/web/src/components/CompanionCreatedNoteLinks.tsx b/apps/web/src/components/CompanionCreatedNoteLinks.tsxindex 54ad6a95..cc385c3b 100644--- a/apps/web/src/components/CompanionCreatedNoteLinks.tsx+++ b/apps/web/src/components/CompanionCreatedNoteLinks.tsx@@ -1,9 +1,10 @@-import { createMemoLinkHref, parseMemoLinkHref, type CompanionToolCall } from "@edgeever/shared";+import { createMemoLinkHref, type CompanionToolCall } from "@edgeever/shared";+import { parseAssistantNoteLinkHref } from "@/lib/assistant-note-links";export function missingCreatedNoteLinks(response: string, tools: CompanionToolCall[]) {const linkedIds = new Set<string>();for (const match of response.matchAll(/\[[^\]\n]+\]\(([^)\s]+)\)/g)) {- const memoId = parseMemoLinkHref(match[1]);+ const memoId = parseAssistantNoteLinkHref(match[1]);if (memoId) linkedIds.add(memoId);}for (const match of response.matchAll(/\[note:([^\]]+)\]/g)) linkedIds.add(match[1]);diff --git a/apps/web/src/components/CompanionNoteText.tsx b/apps/web/src/components/CompanionNoteText.tsxindex 91313c3f..265e3cfe 100644--- a/apps/web/src/components/CompanionNoteText.tsx+++ b/apps/web/src/components/CompanionNoteText.tsx@@ -1,7 +1,8 @@import type { CompanionSource } from "@edgeever/shared";-import { createMemoLinkHref, parseMemoLinkHref } from "@edgeever/shared";+import { createMemoLinkHref } from "@edgeever/shared";import { marked } from "marked";import { useMemo, type MouseEvent } from "react";+import { parseAssistantNoteLinkHref } from "@/lib/assistant-note-links";const NOTE_TOKEN = /\[note:([^\]]+)\]/g;@@ -33,9 +34,9 @@ export function CompanionNoteText({if (!(target instanceof Element)) return;const link = target.closest("a");if (!(link instanceof HTMLAnchorElement)) return;- const memoId = parseMemoLinkHref(link.getAttribute("href"))- ?? parseMemoLinkHref(link.hash)- ?? parseMemoLinkHref(link.href);+ const memoId = parseAssistantNoteLinkHref(link.getAttribute("href"))+ ?? parseAssistantNoteLinkHref(link.hash)+ ?? parseAssistantNoteLinkHref(link.href);if (!memoId) return;event.preventDefault();event.stopPropagation();diff --git a/apps/web/src/components/ai-sidebar/sidebar-note-links.test.mjs b/apps/web/src/components/ai-sidebar/sidebar-note-links.test.mjsindex 6bfe60df..5c76745a 100644--- a/apps/web/src/components/ai-sidebar/sidebar-note-links.test.mjs+++ b/apps/web/src/components/ai-sidebar/sidebar-note-links.test.mjs@@ -45,4 +45,15 @@ describe("sidebar note links", () => {expect(rewritten).toContain(`\`\`\`\n${id}\n\`\`\``);expect(render(markdown)).toContain(`href="#memo=${id}"`);});++ test("opens an agent's EdgeEver URL inside the current workspace", () => {+ const id = "memo_328cb20d4b4040edb3ecb24638abc2d5";+ const markdown = `已创建 [大模型蒸馏流程图](https://edgeever.ai/memo/${id})。`;+ const rewritten = rewriteSidebarNoteLinks(markdown);+ expect(rewritten).toContain(`<edgeever-note data-memo-id="${id}">大模型蒸馏流程图</edgeever-note>`);+ const markup = render(markdown);+ expect(markup).toContain(`href="#memo=${id}"`);+ expect(markup).not.toContain("Open external link");+ expect(markup).not.toContain("https://edgeever.ai/memo/");+ });});diff --git a/apps/web/src/components/ai-sidebar/sidebar-note-links.tsx b/apps/web/src/components/ai-sidebar/sidebar-note-links.tsxindex a5790418..838895c3 100644--- a/apps/web/src/components/ai-sidebar/sidebar-note-links.tsx+++ b/apps/web/src/components/ai-sidebar/sidebar-note-links.tsx@@ -1,5 +1,6 @@-import { createMemoLinkHref, parseMemoLinkHref } from "@edgeever/shared";+import { createMemoLinkHref } from "@edgeever/shared";import type { ComponentProps, ReactNode } from "react";+import { parseAssistantNoteLinkHref } from "@/lib/assistant-note-links";const CODE_REGION = /(```[\s\S]*?```|```[\s\S]*$|`[^`\n]*`)/g;const MARKDOWN_LINK = /\[([^\]\n]+)\]\(([^)\s]+)\)/g;@@ -25,7 +26,7 @@ export function rewriteSidebarNoteLinks(markdown: string): string {return memoId ? `<edgeever-note data-memo-id="${memoId}">${memoId}</edgeever-note>` : part;}return part.replace(MARKDOWN_LINK, (match, label: string, href: string) => {- const memoId = parseMemoLinkHref(href);+ const memoId = parseAssistantNoteLinkHref(href);if (!memoId) return match;return `<edgeever-note data-memo-id="${escapeAttr(memoId)}">${escapeAttr(label)}</edgeever-note>`;});@@ -72,9 +73,9 @@ export function memoIdFromSidebarLinkEvent(event: {if (!(target instanceof Element)) return "";const link = target.closest("a");if (!(link instanceof HTMLAnchorElement)) return "";- const linkedId = parseMemoLinkHref(link.getAttribute("href"))- ?? parseMemoLinkHref(link.hash)- ?? parseMemoLinkHref(link.href);+ const linkedId = parseAssistantNoteLinkHref(link.getAttribute("href"))+ ?? parseAssistantNoteLinkHref(link.hash)+ ?? parseAssistantNoteLinkHref(link.href);if (!linkedId) return "";event.preventDefault();return linkedId;diff --git a/apps/web/src/lib/assistant-note-links.test.mjs b/apps/web/src/lib/assistant-note-links.test.mjsnew file mode 100644index 00000000..9ebd8d82--- /dev/null+++ b/apps/web/src/lib/assistant-note-links.test.mjs@@ -0,0 +1,20 @@+import { describe, expect, test } from "bun:test";+import { parseAssistantNoteLinkHref } from "./assistant-note-links.ts";++const id = "memo_328cb20d4b4040edb3ecb24638abc2d5";++describe("assistant note links", () => {+ test("recognizes a workspace hash and the legacy EdgeEver note URL", () => {+ expect(parseAssistantNoteLinkHref(`#memo=${id}`)).toBe(id);+ expect(parseAssistantNoteLinkHref(`https://edgeever.ai/memo/${id}`)).toBe(id);+ expect(parseAssistantNoteLinkHref(`https://edgeever.ai/memo/${id}/`)).toBe(id);+ });++ test("leaves external and ambiguous URLs external", () => {+ expect(parseAssistantNoteLinkHref(`https://other.example/memo/${id}`)).toBeNull();+ expect(parseAssistantNoteLinkHref(`https://edgeever.ai.evil.example/memo/${id}`)).toBeNull();+ expect(parseAssistantNoteLinkHref(`http://edgeever.ai/memo/${id}`)).toBeNull();+ expect(parseAssistantNoteLinkHref(`https://edgeever.ai/memo/${id}?workspace=other`)).toBeNull();+ expect(parseAssistantNoteLinkHref("https://edgeever.ai/memo/not-a-note-id")).toBeNull();+ });+});diff --git a/apps/web/src/lib/assistant-note-links.ts b/apps/web/src/lib/assistant-note-links.tsnew file mode 100644index 00000000..bedf6f7c--- /dev/null+++ b/apps/web/src/lib/assistant-note-links.ts@@ -0,0 +1,16 @@+import { parseMemoLinkHref } from "@edgeever/shared";++/** Recognize the legacy URL agents sometimes invent for a workspace note. */+export function parseAssistantNoteLinkHref(href: unknown): string | null {+ const memoId = parseMemoLinkHref(href);+ if (memoId) return memoId;+ if (typeof href !== "string") return null;++ try {+ const url = new URL(href);+ if (url.origin !== "https://edgeever.ai" || url.search || url.hash) return null;+ return /^\/memo\/(memo_[0-9a-f]{32})\/?$/i.exec(url.pathname)?.[1] ?? null;+ } catch {+ return null;+ }+}