1616import type { OcxConfig } from "../../types" ;
1717import { AUTH_SLOT_MODELS , resolveSidecarAuth } from "../../sidecar/auth" ;
1818import { pickerVisibleSidecarCandidates , type SidecarCandidate } from "../../sidecar/candidates" ;
19- import { isWebSearchAuthSlotModel , webSearchSidecarCandidates } from "../../web-search/backends" ;
19+ import { WEB_SEARCH_BACKENDS , webSearchSidecarCandidates } from "../../web-search/backends" ;
20+
21+ export type WebSearchBackend = "openai" | "anthropic" ;
22+
23+ export interface WebSearchCandidateRow extends SidecarCandidate {
24+ /** Executor backend that admitted this exact candidate row. */
25+ backend : WebSearchBackend ;
26+ }
2027
2128export interface WebSearchModelOption {
2229 value : string ;
2330 label : string ;
31+ /** Exact runnable pair represented by this picker row. */
32+ backend : WebSearchBackend ;
33+ model : string ;
2434 /** True when the row is an auth-slot entitlement rather than a picker row. */
2535 authSlot ?: boolean ;
2636}
2737
2838/** The candidate rows the web-search executors can actually run right now. */
29- export async function webSearchCandidateRows ( config : OcxConfig ) : Promise < SidecarCandidate [ ] > {
39+ export async function webSearchCandidateRows ( config : OcxConfig ) : Promise < WebSearchCandidateRow [ ] > {
3040 const auth = resolveSidecarAuth ( config ) ;
3141 const all = await pickerVisibleSidecarCandidates ( config , auth ) ;
32- return webSearchSidecarCandidates ( config , auth , all ) ;
42+ return webSearchSidecarCandidates ( config , auth , all ) . flatMap ( candidate => {
43+ const descriptor = WEB_SEARCH_BACKENDS . find ( entry =>
44+ entry . isActive ( auth ) && entry . eligibleModel ( candidate , auth ) ) ;
45+ return descriptor ? [ { ...candidate , backend : descriptor . backend } ] : [ ] ;
46+ } ) ;
3347}
3448
3549/**
@@ -39,20 +53,27 @@ export async function webSearchCandidateRows(config: OcxConfig): Promise<Sidecar
3953 */
4054export function webSearchModelOptionsFrom (
4155 config : Pick < OcxConfig , "webSearchSidecar" > ,
42- candidates : readonly SidecarCandidate [ ] ,
56+ candidates : readonly WebSearchCandidateRow [ ] ,
4357) : WebSearchModelOption [ ] {
4458 const byValue = new Map < string , WebSearchModelOption > ( ) ;
4559 for ( const candidate of candidates ) {
4660 if ( byValue . has ( candidate . id ) ) continue ;
4761 byValue . set ( candidate . id , {
4862 value : candidate . id ,
4963 label : candidate . id ,
64+ backend : candidate . backend ,
65+ model : candidate . id ,
5066 ...( candidate . authSlot ? { authSlot : true } : { } ) ,
5167 } ) ;
5268 }
5369 const persisted = config . webSearchSidecar ?. model ;
5470 if ( persisted && ! byValue . has ( persisted ) ) {
55- byValue . set ( persisted , { value : persisted , label : persisted } ) ;
71+ byValue . set ( persisted , {
72+ value : persisted ,
73+ label : persisted ,
74+ backend : config . webSearchSidecar ?. backend ?? "openai" ,
75+ model : persisted ,
76+ } ) ;
5677 }
5778 return [ ...byValue . values ( ) ] . sort ( ( a , b ) => a . value . localeCompare ( b . value ) ) ;
5879}
@@ -64,26 +85,32 @@ export function webSearchModelOptionsFrom(
6485 * and refusing it would make settings order-dependent on login state.
6586 */
6687export function webSearchModelIsRejected (
88+ backend : WebSearchBackend ,
6789 requested : string ,
68- candidates : readonly SidecarCandidate [ ] ,
90+ candidates : readonly WebSearchCandidateRow [ ] ,
6991) : boolean {
70- if ( isWebSearchAuthSlotModel ( requested ) ) return false ;
71- return ! candidates . some ( candidate => candidate . id === requested ) ;
92+ if ( requested === AUTH_SLOT_MODELS . codex ) return backend !== "openai" ;
93+ if ( requested === AUTH_SLOT_MODELS . anthropic ) return backend !== "anthropic" ;
94+ return ! candidates . some ( candidate => candidate . backend === backend && candidate . id === requested ) ;
7295}
7396
7497/** Uniform 400 payload naming the filter, mirroring visionDescriberRejection's shape. */
7598export function webSearchModelRejection (
7699 field : string ,
100+ backend : WebSearchBackend ,
77101 requested : string ,
78- candidates : readonly SidecarCandidate [ ] ,
102+ candidates : readonly WebSearchCandidateRow [ ] ,
79103) : { error : string ; allowedModels : string [ ] } {
80- const allowed = new Set ( candidates . map ( candidate => candidate . id ) ) ;
81- // The gate accepts auth slots unconditionally, so the legal set must list them.
104+ const allowed = new Set ( candidates
105+ . filter ( candidate => candidate . backend === backend )
106+ . map ( candidate => candidate . id ) ) ;
107+ // Preserve the response contract: allowedModels lists both always-configurable
108+ // auth-slot ids even though the pair gate below binds each to its own backend.
82109 allowed . add ( AUTH_SLOT_MODELS . codex ) ;
83110 allowed . add ( AUTH_SLOT_MODELS . anthropic ) ;
84111 return {
85- error : `${ field } : "${ requested } " is not a web-search sidecar candidate — the model must be ` +
86- "picker-visible and runnable by an active executor-backed backend (or an auth-slot model)" ,
112+ error : `${ field } : backend/model pair "${ backend } / ${ requested } " is not a web-search sidecar candidate — ` +
113+ "the model must be picker-visible and runnable by that executor-backed backend (or its auth-slot model)" ,
87114 allowedModels : [ ...allowed ] . sort ( ) ,
88115 } ;
89116}
0 commit comments