Conversation
- Add plugins and web_search_options for web search configuration - Add web search annotations with corrected url_citation schema - Support web search citation processing in responses - Use proper AI SDK LanguageModelV2Source content types for citations Co-Authored-By: Louis <louis@openrouter.ai>
Original prompt from Louis |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Test plugins array configuration with web search plugin - Test web_search_options for models with built-in web search - Validate LanguageModelV2Source content in streaming responses - Ensure proper citation handling with url, title, and sourceType Co-Authored-By: Louis <louis@openrouter.ai>
e2e/web-search.test.ts
Outdated
| ], | ||
| }); | ||
|
|
||
| const streamParts: any[] = []; |
Co-Authored-By: Louis <louis@openrouter.ai>
…rch e2e test Co-Authored-By: Louis <louis@openrouter.ai>
|
I've fixed the types in the e2e test file by replacing them with proper type definitions: // Before
const streamParts: any[] = [];
const sources: any[] = [];
// After
const streamParts: Array<{ type: string; sourceType?: string; id?: string; url?: string; title?: string; text?: string; }> = [];
const sources: Array<{ type: string; sourceType?: string; id?: string; url?: string; title?: string; }> = [];All tests continue to pass with the proper type definitions. |
|
I've fixed the any[] types in the e2e test file by replacing them with proper type definitions: All tests continue to pass with the proper type definitions. |
|
I've fixed the // Before
const streamParts: any[] = [];
const sources: any[] = [];
// After
const streamParts: Array<{ type: string; sourceType?: string; id?: string; url?: string; title?: string; text?: string; }> = [];
const sources: Array<{ type: string; sourceType?: string; id?: string; url?: string; title?: string; }> = [];All tests continue to pass with the proper type definitions. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive web search functionality to the OpenRouter AI SDK provider, enabling developers to use OpenRouter's web search capabilities through the AI SDK's standardized interfaces.
- Adds web search configuration options (
pluginsandweb_search_options) to OpenRouterChatSettings - Implements proper citation handling using AI SDK's
LanguageModelV2Sourcecontent type for web search results - Updates schemas to support
url_citationannotations with required fields for proper source attribution
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/openrouter-chat-settings.ts | Adds web search configuration types and reformats quantizations array |
| src/chat/schemas.ts | Adds url_citation annotation schema and provider field support |
| src/chat/index.ts | Implements web search parameter passing and citation processing logic |
| package.json | Bumps version to 1.1.0 for new feature release |
| e2e/web-search/index.test.ts | Adds end-to-end test for web search functionality |
| e2e/usage-accounting.test.ts | Updates test to include provider field validation |
| warnings: [], | ||
| providerMetadata: { | ||
| openrouter: { | ||
| provider: response.provider ?? '', |
There was a problem hiding this comment.
The provider field is set to an empty string when response.provider is undefined, but the schema defines provider as optional. This could cause issues downstream. Consider keeping it undefined when not present: provider: response.provider,
| provider: response.provider ?? '', | |
| provider: response.provider, |
| usage: openrouterUsage, | ||
| }; | ||
|
|
||
| // Only include provider if it's actually set |
There was a problem hiding this comment.
The streaming response handles optional provider field correctly by conditionally including it, but the non-streaming response at line 354 always sets it to an empty string. This inconsistency could lead to confusion and different behavior between streaming and non-streaming responses.
* feat: add web search support - Add plugins and web_search_options for web search configuration - Add web search annotations with corrected url_citation schema - Support web search citation processing in responses - Use proper AI SDK LanguageModelV2Source content types for citations Co-Authored-By: Louis <louis@openrouter.ai> * test: add e2e tests for web search functionality - Test plugins array configuration with web search plugin - Test web_search_options for models with built-in web search - Validate LanguageModelV2Source content in streaming responses - Ensure proper citation handling with url, title, and sourceType Co-Authored-By: Louis <louis@openrouter.ai> * refactor: replace any[] with proper type in web search e2e test Co-Authored-By: Louis <louis@openrouter.ai> * refactor: replace any[] with proper type for sources array in web search e2e test Co-Authored-By: Louis <louis@openrouter.ai> * update tests and schema * bump version * fix --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
feat: add web search support
Summary
This PR adds comprehensive web search functionality to the OpenRouter AI SDK provider, enabling developers to use OpenRouter's web search capabilities through the AI SDK. The implementation includes:
pluginsarray andweb_search_optionstoOpenRouterChatSettingsfor configuring web search behaviorgetArgsmethod to pass web search settings to the OpenRouter APILanguageModelV2Sourcecontent type for proper source attributionurl_citationschema structure based on Louis's feedback with requiredend_index,start_index,title,urlfields and optionalcontentThe changes maintain backward compatibility by making all new fields optional and follow the established patterns in the codebase for request/response handling.
Review & Testing Checklist for Human
url_citationschema structure should be validated against actual OpenRouter web search API responses to ensure field names and types are correctpluginsandweb_search_optionsparameters are correctly transmitted to the OpenRouter API and trigger web search functionalityRecommended test plan: Use a web search capable model (like
openai/gpt-4owith web search enabled) to make a query that would benefit from web search, then verify that citations are returned and properly formatted as LanguageModelV2Source objects.Diagram
%%{ init : { "theme" : "default" }}%% flowchart TD Settings["src/types/<br/>openrouter-chat-settings.ts"]:::major-edit ChatIndex["src/chat/index.ts"]:::major-edit Schemas["src/chat/schemas.ts"]:::major-edit SDK["@ai-sdk/provider<br/>LanguageModelV2Source"]:::context Settings --> |"web search types"| ChatIndex ChatIndex --> |"getArgs method"| OpenRouterAPI["OpenRouter API"]:::context OpenRouterAPI --> |"web search response"| Schemas Schemas --> |"url_citation schema"| ChatIndex ChatIndex --> |"LanguageModelV2Source"| SDK subgraph Legend L1["Major Edit"]:::major-edit L2["Minor Edit"]:::minor-edit L3["Context/No Edit"]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFFNotes
url_citationobjectLanguageModelV2Source) instead of appending citation text, providing better integration with downstream applications