From ce3b3290ea2fd8f75a19c9f70ec656add9e9e1ee Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 20 Aug 2026 10:31:58 -0700 Subject: [PATCH] Feat: Append web citations in Claude streaming Co-authored-by: gemini-3.7-flash --- providers.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/providers.js b/providers.js index 7dbc497..7137f3d 100644 --- a/providers.js +++ b/providers.js @@ -258,6 +258,7 @@ export async function streamClaude({ apiKey, body, signal, onDelta, isRunning }) const includeThoughts = body.reasoning?.exclude !== true let hasThinking = false, hasContent = false + const sources = new Set() const stream = client.messages.stream(payload) try { @@ -272,11 +273,19 @@ export async function streamClaude({ apiKey, body, signal, onDelta, isRunning }) if (hasThinking && !hasContent) onDelta('\n') onDelta(delta.text) hasContent = true + } else if (delta.type === 'citations_delta' && delta.citation) { + const uri = delta.citation.url || delta.citation.source + if (uri) sources.add(uri) } } } finally { try { stream.controller?.abort() } catch {} } + + if (sources.size && isRunning()) { + const list = [...sources].map((uri, i) => `${i + 1}. [${uri}](${uri})`).join('\n') + onDelta(`\n\n---\n\n**Sources**\n\n${list}\n`) + } } export async function streamGoogle({ apiKey, body, signal, onDelta, isRunning }) {