(params: {
model: string
runId: string
clientSessionId: string
providerOptions?: Record<string, JSONObject>
agentProviderOptions?: OpenRouterProviderRoutingOptions
n?: number
costMode?: string
cacheDebugCorrelation?: string
extraCodebuffMetadata?: Record<string, string>
})
| 67 | } |
| 68 | |
| 69 | export function getProviderOptions(params: { |
| 70 | model: string |
| 71 | runId: string |
| 72 | clientSessionId: string |
| 73 | providerOptions?: Record<string, JSONObject> |
| 74 | agentProviderOptions?: OpenRouterProviderRoutingOptions |
| 75 | n?: number |
| 76 | costMode?: string |
| 77 | cacheDebugCorrelation?: string |
| 78 | extraCodebuffMetadata?: Record<string, string> |
| 79 | }): { codebuff: JSONObject } { |
| 80 | const { |
| 81 | model, |
| 82 | runId, |
| 83 | clientSessionId, |
| 84 | providerOptions, |
| 85 | agentProviderOptions, |
| 86 | n, |
| 87 | costMode, |
| 88 | cacheDebugCorrelation, |
| 89 | extraCodebuffMetadata, |
| 90 | } = params |
| 91 | |
| 92 | let providerConfig: Record<string, any> |
| 93 | |
| 94 | // Use agent's provider options if provided, otherwise use defaults |
| 95 | if (agentProviderOptions) { |
| 96 | providerConfig = agentProviderOptions |
| 97 | } else { |
| 98 | // Set allow_fallbacks based on whether model is explicitly defined |
| 99 | const isExplicitlyDefined = isExplicitlyDefinedModel(model) |
| 100 | |
| 101 | providerConfig = { |
| 102 | order: providerOrder[model as keyof typeof providerOrder], |
| 103 | allow_fallbacks: !isExplicitlyDefined, |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return { |
| 108 | ...providerOptions, |
| 109 | // Could either be "codebuff" or "openaiCompatible" |
| 110 | codebuff: { |
| 111 | ...providerOptions?.codebuff, |
| 112 | // All values here get appended to the request body |
| 113 | codebuff_metadata: { |
| 114 | // Caller-supplied keys go first so they can't override reserved |
| 115 | // identifiers like run_id/client_id/cost_mode that the server trusts. |
| 116 | ...(extraCodebuffMetadata ?? {}), |
| 117 | run_id: runId, |
| 118 | client_id: clientSessionId, |
| 119 | ...(n && { n }), |
| 120 | ...(costMode && { cost_mode: costMode }), |
| 121 | ...(cacheDebugCorrelation && { |
| 122 | cache_debug_correlation: cacheDebugCorrelation, |
| 123 | }), |
| 124 | }, |
| 125 | provider: providerConfig, |
| 126 | }, |
no test coverage detected