@phi-code-admin/phi-code 0.61.3 → 0.61.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.
@@ -351,9 +351,10 @@ function getProviderConfigs(): ProviderConfig[] {
351
351
  ];
352
352
  }
353
353
 
354
- function getAvailableModels(): Array<{ id: string; provider: string; baseUrl: string; apiKey: string }> {
354
+ async function getAvailableModels(): Promise<Array<{ id: string; provider: string; baseUrl: string; apiKey: string }>> {
355
355
  const models: Array<{ id: string; provider: string; baseUrl: string; apiKey: string }> = [];
356
356
 
357
+ // 1. Cloud providers via env vars
357
358
  for (const provider of getProviderConfigs()) {
358
359
  const apiKey = process.env[provider.envVar];
359
360
  if (!apiKey) continue;
@@ -368,6 +369,60 @@ function getAvailableModels(): Array<{ id: string; provider: string; baseUrl: st
368
369
  }
369
370
  }
370
371
 
372
+ // 2. Local providers (LM Studio, Ollama) — auto-detect via models.json
373
+ const { join } = await import("node:path");
374
+ const { homedir } = await import("node:os");
375
+ const { readFileSync, existsSync } = await import("node:fs");
376
+
377
+ const modelsJsonPath = join(homedir(), ".phi", "agent", "models.json");
378
+ if (existsSync(modelsJsonPath)) {
379
+ try {
380
+ const config = JSON.parse(readFileSync(modelsJsonPath, "utf-8"));
381
+ if (config.providers) {
382
+ for (const [id, providerConfig] of Object.entries<any>(config.providers)) {
383
+ const baseUrl = providerConfig.baseUrl || "";
384
+ const apiKey = providerConfig.apiKey || "local";
385
+ if (providerConfig.models?.length > 0) {
386
+ for (const m of providerConfig.models) {
387
+ const modelId = typeof m === "string" ? m : m.id;
388
+ // Skip if already added from env vars
389
+ if (!models.some(existing => existing.id === modelId && existing.baseUrl === baseUrl)) {
390
+ models.push({ id: modelId, provider: id, baseUrl, apiKey });
391
+ }
392
+ }
393
+ }
394
+ }
395
+ }
396
+ } catch { /* ignore parse errors */ }
397
+ }
398
+
399
+ // 3. Try to detect LM Studio (port 1234) and Ollama (port 11434) directly
400
+ for (const local of [
401
+ { name: "lm-studio", port: 1234, baseUrl: "http://localhost:1234/v1" },
402
+ { name: "ollama", port: 11434, baseUrl: "http://localhost:11434/v1" },
403
+ ]) {
404
+ // Skip if already discovered via models.json
405
+ if (models.some(m => m.baseUrl === local.baseUrl)) continue;
406
+
407
+ try {
408
+ const controller = new AbortController();
409
+ const timeout = setTimeout(() => controller.abort(), 2000);
410
+ const resp = await fetch(`${local.baseUrl}/models`, { signal: controller.signal });
411
+ clearTimeout(timeout);
412
+
413
+ if (resp.ok) {
414
+ const data = await resp.json() as any;
415
+ const modelList = data?.data || [];
416
+ for (const m of modelList) {
417
+ const modelId = m.id || m.name;
418
+ if (modelId && !models.some(existing => existing.id === modelId)) {
419
+ models.push({ id: modelId, provider: local.name, baseUrl: local.baseUrl, apiKey: "local" });
420
+ }
421
+ }
422
+ }
423
+ } catch { /* not running */ }
424
+ }
425
+
371
426
  return models;
372
427
  }
373
428
 
@@ -626,7 +681,7 @@ Scoring: S (80+), A (65+), B (50+), C (35+), D (<35)`, "info");
626
681
  }
627
682
 
628
683
  // Get available models (validates API keys are non-empty and reasonable length)
629
- const available = getAvailableModels();
684
+ const available = await getAvailableModels();
630
685
  if (available.length === 0) {
631
686
  const providers = getProviderConfigs();
632
687
  const hint = providers.map(p => ` ${p.envVar}: ${process.env[p.envVar] ? "set but no models configured" : "not set"}`).join("\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phi-code-admin/phi-code",
3
- "version": "0.61.3",
3
+ "version": "0.61.4",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "piConfig": {