Map a provider NAME to its OpenAI-compatible {baseUrl, apiKey}, or undefined if it * isn't an OpenAI-compatible HTTP provider with a key set. (anthropic/ollama/lm-studio * are intentionally excluded — they're handled by their own dedicated backends.)
(cfg: any, providerName?: string)
| 105 | * isn't an OpenAI-compatible HTTP provider with a key set. (anthropic/ollama/lm-studio |
| 106 | * are intentionally excluded — they're handled by their own dedicated backends.) */ |
| 107 | function resolveProviderEndpoint(cfg: any, providerName?: string): { baseUrl: string; apiKey: string } | undefined { |
| 108 | if (!providerName) return undefined; |
| 109 | const norm = (u: string) => u.replace(/\/+$/, ''); |
| 110 | const custom = (cfg.providers?.custom ?? []).find((c: any) => c?.name === providerName); |
| 111 | if (custom?.baseUrl && custom?.apiKeyEnv && /^https?:\/\//.test(custom.baseUrl)) { |
| 112 | const key = process.env[custom.apiKeyEnv]; |
| 113 | if (key) return { baseUrl: norm(custom.baseUrl), apiKey: key }; |
| 114 | } |
| 115 | if (providerName === 'openai') { |
| 116 | const key = process.env[cfg.providers?.openai?.apiKeyEnv ?? 'OPENAI_API_KEY']; |
| 117 | const baseUrl = cfg.providers?.openai?.baseUrl ?? 'https://api.openai.com/v1'; |
| 118 | if (key && /^https?:\/\//.test(baseUrl)) return { baseUrl: norm(baseUrl), apiKey: key }; |
| 119 | } |
| 120 | return undefined; |
| 121 | } |
| 122 | |
| 123 | const VisionAnalyzeArgs = z.object({ |
| 124 | image_path: z.string().min(1).describe('Path to a PNG/JPEG/WebP file on disk. Often the result of browser_screenshot.'), |
no test coverage detected