fix(websearch): handle blocked domains conditionally in web search (#10374)

fix(websearch): handle blocked domains conditionally in web search configurations

- Updated the handling of blocked domains in both Google Vertex and Anthropic web search configurations to only include them if they are present, improving robustness and preventing unnecessary parameters from being passed.
This commit is contained in:
MyPrototypeWhat 2025-09-26 12:10:28 +08:00 committed by GitHub
parent 3b7ab2aec8
commit 52a980f751
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -134,9 +134,10 @@ export async function buildStreamTextParams(
if (aiSdkProviderId === 'google-vertex') {
tools.google_search = vertex.tools.googleSearch({}) as ProviderDefinedTool
} else if (aiSdkProviderId === 'google-vertex-anthropic') {
const blockedDomains = mapRegexToPatterns(webSearchConfig.excludeDomains)
tools.web_search = vertexAnthropic.tools.webSearch_20250305({
maxUses: webSearchConfig.maxResults,
blockedDomains: mapRegexToPatterns(webSearchConfig.excludeDomains)
blockedDomains: blockedDomains.length > 0 ? blockedDomains : undefined
}) as ProviderDefinedTool
}
}

View File

@ -61,9 +61,10 @@ export function buildProviderBuiltinWebSearchConfig(
}
}
case 'anthropic': {
const blockedDomains = mapRegexToPatterns(webSearchConfig.excludeDomains)
const anthropicSearchOptions: AnthropicSearchConfig = {
maxUses: webSearchConfig.maxResults,
blockedDomains: mapRegexToPatterns(webSearchConfig.excludeDomains)
blockedDomains: blockedDomains.length > 0 ? blockedDomains : undefined
}
return {
anthropic: anthropicSearchOptions