fix(chat): render Codex source citations #9605
Closedjuliusmarmingewants to merge 2 commits into
main fromt3code/fix-citation-markdown-renderingopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- packages/client-runtime/src/codexCitations.ts lines 61 to 61OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +41,21 @@41+ type?: string;42+ value?: string;43+ position?: { readonly start: MarkdownPoint; readonly end: MarkdownPoint };44+ data?: {45+ codexCitationMarkdown?: string;46+ hName?: string;47+ hProperties?: Record<string, unknown>;48+ };49+ children?: MarkdownNode[];50+}51+52+const citationTokens = new WeakMap<MarkdownNode, string>();53+54+export const CODEX_CITATION_HAST_PROPERTIES = ["dataCodexCitation"] as const;55+56+function parseCitation(raw: string) {57+ if (!raw.startsWith(PREFIX) || !raw.endsWith(END)) return null;58+ const ids = raw.slice(PREFIX.length, -END.length).split(SEPARATOR);59+ if (!ids.every((id) => SOURCE_ID.test(id))) return null;60+ const last = ids.at(-1);61+ const locator = last !== undefined && LOCATOR.test(last) ? ids.pop() : undefined;apps/web/src/components/chat/CodexCitationChip.tsx line 24Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +4,21 @@4+ type CodexCitation,5+} from "@t3tools/client-runtime/codex-citations";6+import { cn } from "~/lib/utils";7+import { CHAT_INLINE_CHIP_CLASS_NAME } from "../composerInlineChip";8+import {9+ Popover,10+ PopoverDescription,11+ PopoverPopup,12+ PopoverTitle,13+ PopoverTrigger,14+} from "../ui/popover";15+16+/** A source reference stays inspectable even when Codex does not supply its destination. */17+export function CodexCitationChip({ citation }: { citation: CodexCitation }) {18+ const sourceNumbers = citation.sources.map((source) => source.number).join(", ");19+ const label = `${citation.sources.length === 1 ? "Source" : "Sources"} ${sourceNumbers}`;20+21+ return (22+ <span23+ className="chat-markdown-source-citation"24+ data-markdown-copy={codexCitationMarkdown(citation)}
juliusmarminge added labelsmacroscope-review
juliusmarminge assignedjuliusmarminge
juliusmarminge closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed