({
baseUrl,
apiKey,
model,
models,
modelLabels,
}: OpenCodeConfigInput)
| 39 | labels[modelId] || modelId; |
| 40 | |
| 41 | export const buildOpenCodeProviderConfig = ({ |
| 42 | baseUrl, |
| 43 | apiKey, |
| 44 | model, |
| 45 | models, |
| 46 | modelLabels, |
| 47 | }: OpenCodeConfigInput): Record<string, any> => { |
| 48 | const normalizedBaseUrl = String(baseUrl || "") |
| 49 | .trim() |
| 50 | .replace(/\/+$/, ""); |
| 51 | const normalizedModel = normalizeValue(model); |
| 52 | const normalizedModels = normalizeModels(models); |
| 53 | const normalizedLabels = normalizeModelLabels(modelLabels); |
| 54 | |
| 55 | const uniqueModels = |
| 56 | normalizedModels.length > 0 |
| 57 | ? normalizedModels |
| 58 | : [...new Set([normalizedModel, ...OPENCODE_DEFAULT_MODELS].filter(Boolean))]; |
| 59 | |
| 60 | const modelsRecord: Record<string, { name: string }> = {}; |
| 61 | for (const m of uniqueModels) { |
| 62 | if (m) { |
| 63 | modelsRecord[m] = { name: getModelEntryName(m, normalizedLabels) }; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return { |
| 68 | npm: "@ai-sdk/openai-compatible", |
| 69 | name: "OmniRoute", |
| 70 | options: { |
| 71 | baseURL: normalizedBaseUrl, |
| 72 | apiKey: apiKey || "sk_omniroute", |
| 73 | }, |
| 74 | models: modelsRecord, |
| 75 | }; |
| 76 | }; |
| 77 | |
| 78 | export const buildOpenCodeConfigDocument = (input: OpenCodeConfigInput) => ({ |
| 79 | $schema: "https://opencode.ai/config.json", |
no test coverage detected