mirror of
https://github.com/sune-org/us.proxy.sune.chat.git
synced 2026-08-28 09:35:42 +00:00
Feat: Append web citations in Claude streaming
Co-authored-by: gemini-3.7-flash <noreply@google.com>
This commit is contained in:
@@ -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 }) {
|
||||
|
||||
Reference in New Issue
Block a user