From 57d6182ca3f20be86d1c62d092e03abfdd82e44f Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Wed, 22 Jul 2026 19:35:04 +0200 Subject: [PATCH] feat: parse run citation tokens --- surfsense_web/lib/citations/citation-parser.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/surfsense_web/lib/citations/citation-parser.ts b/surfsense_web/lib/citations/citation-parser.ts index 533c644c2..3c2f0196c 100644 --- a/surfsense_web/lib/citations/citation-parser.ts +++ b/surfsense_web/lib/citations/citation-parser.ts @@ -11,18 +11,20 @@ import { FENCED_OR_INLINE_CODE } from "@/lib/markdown/code-regions"; /** * Matches `[citation:...]` with numeric IDs (incl. negative, doc- prefix, - * comma-separated), URL-based IDs from live web search, or `urlciteN` - * placeholders produced by `preprocessCitationMarkdown`. + * comma-separated), URL-based IDs from live web search, `urlciteN` + * placeholders produced by `preprocessCitationMarkdown`, or a scraper-run + * handle (`run_`). * * Also matches Chinese brackets 【】 and zero-width spaces that LLMs * sometimes emit. */ export const CITATION_REGEX = - /[[【]\u200B?citation:\s*(https?:\/\/[^\]】\u200B]+|urlcite\d+|(?:doc-)?-?\d+(?:\s*,\s*(?:doc-)?-?\d+)*)\s*\u200B?[\]】]/g; + /[[【]\u200B?citation:\s*(https?:\/\/[^\]】\u200B]+|urlcite\d+|run_[0-9a-fA-F-]+|(?:doc-)?-?\d+(?:\s*,\s*(?:doc-)?-?\d+)*)\s*\u200B?[\]】]/g; /** A single parsed citation reference. */ export type CitationToken = | { kind: "url"; url: string } + | { kind: "run"; runId: string } | { kind: "chunk"; chunkId: number; isDocsChunk: boolean }; /** Output of `parseTextWithCitations` — interleaved text + citation tokens. */ @@ -102,6 +104,8 @@ export function parseTextWithCitations(text: string, urlMap: CitationUrlMap): Pa if (url) { segments.push({ kind: "url", url }); } + } else if (captured.startsWith("run_")) { + segments.push({ kind: "run", runId: captured.trim() }); } else { const rawIds = captured.split(",").map((s) => s.trim()); for (const rawId of rawIds) {