fix: align pi model discovery with auth storage

This commit is contained in:
Peter Steinberger
2025-12-26 11:49:13 +01:00
parent d31c5d7a2c
commit 82ced33747
6 changed files with 90 additions and 63 deletions

View File

@@ -10,10 +10,15 @@ type ModelEntry = { id: string; contextWindow?: number };
const MODEL_CACHE = new Map<string, number>();
const loadPromise = (async () => {
try {
const { discoverModels } = await import("@mariozechner/pi-coding-agent");
const { discoverAuthStorage, discoverModels } = await import(
"@mariozechner/pi-coding-agent"
);
const cfg = loadConfig();
await ensureClawdisModelsJson(cfg);
const models = discoverModels(resolveClawdisAgentDir()) as ModelEntry[];
const agentDir = resolveClawdisAgentDir();
const authStorage = discoverAuthStorage(agentDir);
const modelRegistry = discoverModels(authStorage, agentDir);
const models = modelRegistry.getAll() as ModelEntry[];
for (const m of models) {
if (!m?.id) continue;
if (typeof m.contextWindow === "number" && m.contextWindow > 0) {