Feat: Add web search support for Claude :online models

This commit is contained in:
2026-02-27 18:51:05 -08:00
parent b0a82212fb
commit aa4908af04

View File

@@ -129,12 +129,15 @@ export async function streamOpenAI({ apiKey, body, signal, onDelta, isRunning })
export async function streamClaude({ apiKey, body, signal, onDelta, isRunning }) { export async function streamClaude({ apiKey, body, signal, onDelta, isRunning }) {
const client = new Anthropic({ apiKey }) const client = new Anthropic({ apiKey })
const online = (body.model ?? '').endsWith(':online')
const model = online ? body.model.slice(0, -7) : body.model
const system = body.messages const system = body.messages
.filter(m => m.role === 'system') .filter(m => m.role === 'system')
.map(extractText) .map(extractText)
.join('\n\n') || body.system .join('\n\n') || body.system
const payload = { const payload = {
model: body.model, model,
messages: body.messages.filter(m => m.role !== 'system').map(m => ({ messages: body.messages.filter(m => m.role !== 'system').map(m => ({
role: m.role, role: m.role,
content: typeof m.content === 'string' ? m.content : (m.content || []).map(p => { content: typeof m.content === 'string' ? m.content : (m.content || []).map(p => {
@@ -157,6 +160,12 @@ export async function streamClaude({ apiKey, body, signal, onDelta, isRunning })
...(body.reasoning.budget && { max_thinking_tokens: body.reasoning.budget }), ...(body.reasoning.budget && { max_thinking_tokens: body.reasoning.budget }),
} }
} }
if (online) {
payload.tools = [
...(payload.tools || []),
{ type: 'web_search_20260209', name: 'web_search' },
]
}
const stream = client.messages.stream(payload) const stream = client.messages.stream(payload)
stream.on('text', text => { if (isRunning()) onDelta(text) }) stream.on('text', text => { if (isRunning()) onDelta(text) })