2026-03-16 19:40:30 +00:00
|
|
|
/**
|
|
|
|
|
* Models.json resolution with fallback to ~/.pi/agent/models.json
|
|
|
|
|
*
|
2026-04-15 15:37:12 +02:00
|
|
|
* SF uses ~/.sf/agent/models.json, but for a smooth migration/development
|
2026-03-16 19:40:30 +00:00
|
|
|
* experience, this module provides resolution logic that:
|
|
|
|
|
*
|
2026-04-15 15:37:12 +02:00
|
|
|
* 1. Reads ~/.sf/agent/models.json if it exists
|
2026-04-15 14:54:20 +02:00
|
|
|
* 2. Falls back to ~/.pi/agent/models.json if SF file doesn't exist
|
|
|
|
|
* 3. Merges both files if both exist (SF takes precedence)
|
2026-03-16 19:40:30 +00:00
|
|
|
*/
|
|
|
|
|
|
2026-04-29 12:42:31 +02:00
|
|
|
import { existsSync } from "node:fs";
|
|
|
|
|
import { homedir } from "node:os";
|
|
|
|
|
import { join } from "node:path";
|
|
|
|
|
import { agentDir } from "./app-paths.js";
|
2026-03-16 19:40:30 +00:00
|
|
|
|
2026-04-29 12:42:31 +02:00
|
|
|
const SF_MODELS_PATH = join(agentDir, "models.json");
|
|
|
|
|
const PI_MODELS_PATH = join(homedir(), ".pi", "agent", "models.json");
|
2026-03-16 19:40:30 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resolve the path to models.json with fallback logic.
|
|
|
|
|
*
|
|
|
|
|
* Priority:
|
2026-04-15 15:37:12 +02:00
|
|
|
* 1. ~/.sf/agent/models.json (exists) → return this path
|
2026-03-16 19:40:30 +00:00
|
|
|
* 2. ~/.pi/agent/models.json (exists) → return this path (fallback)
|
2026-04-15 14:54:20 +02:00
|
|
|
* 3. Neither exists → return SF path (will be created)
|
2026-03-16 19:40:30 +00:00
|
|
|
*
|
|
|
|
|
* @returns The path to use for models.json
|
|
|
|
|
*/
|
|
|
|
|
export function resolveModelsJsonPath(): string {
|
2026-04-29 12:42:31 +02:00
|
|
|
if (existsSync(SF_MODELS_PATH)) {
|
|
|
|
|
return SF_MODELS_PATH;
|
|
|
|
|
}
|
|
|
|
|
if (existsSync(PI_MODELS_PATH)) {
|
|
|
|
|
return PI_MODELS_PATH;
|
|
|
|
|
}
|
|
|
|
|
return SF_MODELS_PATH;
|
2026-03-16 19:40:30 +00:00
|
|
|
}
|