The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): preserve localhost URLs with path segments in markdown preprocess
liuhao1024fe417523fe9d
diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.test.ts b/apps/desktop/src/components/assistant-ui/markdown-text.test.tsindex 413a2e24597..cda508bfdd6 100644--- a/apps/desktop/src/components/assistant-ui/markdown-text.test.ts+++ b/apps/desktop/src/components/assistant-ui/markdown-text.test.ts@@ -16,6 +16,7 @@ describe('preprocessMarkdown', () => {expect(output).not.toContain('```')expect(output).toContain("Here's your scene:")+ // Bare localhost URLs (with or without trailing slash) are still stripped.expect(output).not.toContain('http://localhost:8812/')expect(output).toContain('- **Multicolored cube**')})@@ -33,6 +34,7 @@ describe('preprocessMarkdown', () => {const output = preprocessMarkdown(input)expect(output).not.toContain('```')+ // Bare localhost URLs (with or without trailing slash) are still stripped.expect(output).not.toContain('http://localhost:8812/')expect(output).toContain('- **Scroll wheel** - zoom')})@@ -45,9 +47,28 @@ describe('preprocessMarkdown', () => {expect(output).toContain('Server is back.')expect(output).not.toContain('```')+ // Bare localhost URLs (no path after port) are still stripped.expect(output).not.toContain('http://localhost:8812/')})+ it('preserves localhost URLs with paths in fenced blocks', () => {+ const fence = '```'+ const input = ['Open this:', '', fence, 'http://localhost:8080/piwo', fence].join('\n')++ const output = preprocessMarkdown(input)++ expect(output).toContain('Open this:')+ expect(output).not.toContain('```')+ expect(output).toContain('http://localhost:8080/piwo')+ })++ it('preserves localhost URLs with paths in prose', () => {+ const output = preprocessMarkdown('Use this URL:\nhttp://localhost:8080/piwo')++ expect(output).toContain('Use this URL:')+ expect(output).toContain('http://localhost:8080/piwo')+ })+it('demotes prose sentence masquerading as fence info', () => {const input = ['```Heads up - a bunny got added', '- Pure white (`#ffffff`)', '- Ambient dropped to 0.18'].join('\n'diff --git a/apps/desktop/src/lib/markdown-preprocess.ts b/apps/desktop/src/lib/markdown-preprocess.tsindex 2fe3cfa92a3..7b0c606b017 100644--- a/apps/desktop/src/lib/markdown-preprocess.ts+++ b/apps/desktop/src/lib/markdown-preprocess.ts@@ -89,7 +89,9 @@ const MARKDOWN_LINK_SPLIT_RE = new RegExp('gm')-const LOCAL_PREVIEW_URL_RE = /(^|\s)https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(?::\d+)?\/?[^\s<>"'`]*/gi+// Only strip bare localhost root URLs in prose. URLs with actual path segments+// (e.g. http://localhost:8080/piwo) are user-facing content and must survive.+const LOCAL_PREVIEW_URL_RE = /(^|\s)https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(?::\d+)?\/?(?=\s|$)/giconst LOCAL_PREVIEW_ONLY_RE = /^https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(?::\d+)?\/?$/iconst URL_ONLY_LINE_RE = /^\s*https?:\/\/\S+\s*$/iconst CITATION_MARKER_RE = /(?<=[\p{L}\p{N})\].,!?:;"'”’])\[(?:\d+(?:\s*,\s*\d+)*)\](?!\()/gu