infernoflow 0.32.3 → 0.32.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -234,3 +234,62 @@ export function detectAvailableProviders(cwd) {
|
|
|
234
234
|
ollama: false, // checked async — doctor runs its own check
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Resolve which provider + IDE is available for the `run` command.
|
|
240
|
+
* Returns a structured object that run.mjs uses to decide how to proceed.
|
|
241
|
+
*
|
|
242
|
+
* @param {string} providerRequested - "auto"|"anthropic"|"openai"|etc.
|
|
243
|
+
* @param {string} ideRequested - "auto"|"vscode"|"cursor"|etc.
|
|
244
|
+
* @returns {{ providerResolved: string, ideDetected: string, agentAvailable: boolean, reasonCodes: string[], error?: string }}
|
|
245
|
+
*/
|
|
246
|
+
export async function resolveProvider(providerRequested = "auto", ideRequested = "auto") {
|
|
247
|
+
const cwd = process.cwd();
|
|
248
|
+
const config = readAiConfig(cwd);
|
|
249
|
+
const reasons = [];
|
|
250
|
+
|
|
251
|
+
// Detect IDE
|
|
252
|
+
const inVsCode = !!process.env.VSCODE_PID || !!process.env.TERM_PROGRAM?.includes("vscode");
|
|
253
|
+
const inCursor = !!process.env.CURSOR_TRACE_ID || !!process.env.CURSOR_CHANNEL;
|
|
254
|
+
const ideDetected = inCursor ? "cursor" : inVsCode ? "vscode" : "terminal";
|
|
255
|
+
|
|
256
|
+
// Detect available providers
|
|
257
|
+
const available = {
|
|
258
|
+
anthropic: !!(process.env.ANTHROPIC_API_KEY || config.anthropic?.apiKey),
|
|
259
|
+
openai: !!(process.env.OPENAI_API_KEY || config.openai?.apiKey),
|
|
260
|
+
gemini: !!(process.env.GOOGLE_AI_API_KEY || process.env.GEMINI_API_KEY || config.gemini?.apiKey),
|
|
261
|
+
openrouter: !!(process.env.OPENROUTER_API_KEY || config.openrouter?.apiKey),
|
|
262
|
+
ollama: false,
|
|
263
|
+
vscode: inVsCode || inCursor,
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// Check Ollama quickly (sync port probe via env hint)
|
|
267
|
+
if (process.env.OLLAMA_HOST || config.ollama?.host) {
|
|
268
|
+
available.ollama = true;
|
|
269
|
+
reasons.push("ollama_env");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Resolve which provider to use
|
|
273
|
+
let providerResolved = "none";
|
|
274
|
+
const forced = (providerRequested || "auto").toLowerCase();
|
|
275
|
+
|
|
276
|
+
if (forced !== "auto" && forced !== "prompt" && available[forced]) {
|
|
277
|
+
providerResolved = forced;
|
|
278
|
+
reasons.push(`forced_${forced}`);
|
|
279
|
+
} else {
|
|
280
|
+
// Priority order: vscode/cursor IDE → anthropic → openai → gemini → openrouter → ollama
|
|
281
|
+
const priority = ["vscode", "anthropic", "openai", "gemini", "openrouter", "ollama"];
|
|
282
|
+
for (const p of priority) {
|
|
283
|
+
if (available[p]) { providerResolved = p; reasons.push(`auto_${p}`); break; }
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const agentAvailable = providerResolved !== "none";
|
|
288
|
+
|
|
289
|
+
if (!agentAvailable) {
|
|
290
|
+
reasons.push("no_provider");
|
|
291
|
+
return { providerResolved: "none", ideDetected, agentAvailable: false, reasonCodes: reasons, error: "agent_unavailable" };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return { providerResolved, ideDetected, agentAvailable: true, reasonCodes: reasons };
|
|
295
|
+
}
|