(config: any, entry: CustomProviderEntry, opts?: { setDefault?: boolean; defaultModel?: string })
| 228 | * exists, it's replaced in place (no duplicates). |
| 229 | */ |
| 230 | export function mergeCustomProvider(config: any, entry: CustomProviderEntry, opts?: { setDefault?: boolean; defaultModel?: string }): any { |
| 231 | const cfg = config && typeof config === 'object' ? config : {}; |
| 232 | cfg.providers = cfg.providers && typeof cfg.providers === 'object' ? cfg.providers : {}; |
| 233 | const custom: CustomProviderEntry[] = Array.isArray(cfg.providers.custom) ? cfg.providers.custom : []; |
| 234 | |
| 235 | const idx = custom.findIndex(c => c && c.name === entry.name); |
| 236 | if (idx >= 0) custom[idx] = entry; |
| 237 | else custom.push(entry); |
| 238 | cfg.providers.custom = custom; |
| 239 | |
| 240 | if (opts?.setDefault) { |
| 241 | cfg.defaults = cfg.defaults && typeof cfg.defaults === 'object' ? cfg.defaults : {}; |
| 242 | cfg.defaults.provider = entry.name; |
| 243 | const model = opts.defaultModel ?? entry.models?.[0]?.id; |
| 244 | if (model) cfg.defaults.model = model; |
| 245 | } |
| 246 | return cfg; |
| 247 | } |
no test coverage detected