({
prompt,
files = [],
model,
engine,
userConfig,
env = process.env,
}: ResolveRunOptionsInput)
| 20 | } |
| 21 | |
| 22 | export function resolveRunOptionsFromConfig({ |
| 23 | prompt, |
| 24 | files = [], |
| 25 | model, |
| 26 | engine, |
| 27 | userConfig, |
| 28 | env = process.env, |
| 29 | }: ResolveRunOptionsInput): ResolvedRunOptions { |
| 30 | const resolvedEngine = resolveEngineWithConfig({ engine, configEngine: userConfig?.engine, env }); |
| 31 | const browserRequested = engine === 'browser'; |
| 32 | |
| 33 | const cliModelArg = normalizeModelOption(model ?? userConfig?.model) || 'gpt-5-pro'; |
| 34 | const resolvedModel = resolvedEngine === 'browser' ? inferModelFromLabel(cliModelArg) : resolveApiModel(cliModelArg); |
| 35 | const isGemini = resolvedModel.startsWith('gemini'); |
| 36 | // Keep the resolved model id alongside the canonical model name so we can log |
| 37 | // and dispatch the exact identifier (useful for Gemini preview aliases). |
| 38 | const effectiveModelId = isGemini ? resolveGeminiModelId(resolvedModel) : resolvedModel; |
| 39 | |
| 40 | if (isGemini && browserRequested) { |
| 41 | throw new Error('Gemini is only supported via API. Use --engine api.'); |
| 42 | } |
| 43 | // When Gemini is selected, always force API engine (overrides config/env auto browser). |
| 44 | const fixedEngine: EngineMode = isGemini ? 'api' : resolvedEngine; |
| 45 | |
| 46 | const promptWithSuffix = |
| 47 | userConfig?.promptSuffix && userConfig.promptSuffix.trim().length > 0 |
| 48 | ? `${prompt.trim()}\n${userConfig.promptSuffix}` |
| 49 | : prompt; |
| 50 | |
| 51 | const search = userConfig?.search !== 'off'; |
| 52 | |
| 53 | const heartbeatIntervalMs = |
| 54 | userConfig?.heartbeatSeconds !== undefined ? userConfig.heartbeatSeconds * 1000 : 30_000; |
| 55 | |
| 56 | const baseUrl = normalizeBaseUrl(userConfig?.apiBaseUrl ?? env.OPENAI_BASE_URL); |
| 57 | |
| 58 | const runOptions: RunOracleOptions = { |
| 59 | prompt: promptWithSuffix, |
| 60 | model: resolvedModel, |
| 61 | file: files ?? [], |
| 62 | search, |
| 63 | heartbeatIntervalMs, |
| 64 | filesReport: userConfig?.filesReport, |
| 65 | background: userConfig?.background, |
| 66 | baseUrl, |
| 67 | effectiveModelId, |
| 68 | }; |
| 69 | |
| 70 | return { runOptions, resolvedEngine: fixedEngine }; |
| 71 | } |
| 72 | |
| 73 | function resolveEngineWithConfig({ |
| 74 | engine, |
no test coverage detected