fix(models): cache catalog for offline startup

Persist the last valid Command Code model catalog and use it when live model discovery fails. Keep first-time offline startup non-fatal, surface clear warnings, and cover cached model selection with unit and pi integration regression tests.
This commit is contained in:
Patrick Wozniak
2026-08-02 01:16:39 +02:00
parent 811f908918
commit 070ef3c07a
6 changed files with 381 additions and 76 deletions
+8 -7
View File
@@ -17,11 +17,12 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"
import { COMMAND_CODE_CLI_VERSION, createStreamCommandCode, DEFAULT_API_BASE } from "./src/core.ts"
import { calculateCommandCodeCost } from "./src/cost.ts"
import { DEFAULT_MODELS_URL, fetchCommandCodeModels, type CommandCodeModel } from "./src/models.ts"
import { DEFAULT_MODELS_URL, loadCommandCodeModels } from "./src/models.ts"
import { getApiKey, login, refreshToken } from "./src/oauth.ts"
const API_BASE = process.env.COMMANDCODE_API_BASE ?? DEFAULT_API_BASE
const MODELS_URL = process.env.COMMANDCODE_MODELS_URL ?? DEFAULT_MODELS_URL
const MODELS_CACHE_PATH = process.env.COMMANDCODE_MODELS_CACHE
type CommandCodeModelCost = {
input: number
@@ -79,12 +80,12 @@ const streamCommandCode = createStreamCommandCode({
// ---------------------------------------------------------------------------
export default async function (pi: ExtensionAPI) {
let models: readonly CommandCodeModel[]
try {
models = await fetchCommandCodeModels({ url: MODELS_URL })
} catch {
models = []
}
const { models, warning } = await loadCommandCodeModels({
url: MODELS_URL,
cachePath: MODELS_CACHE_PATH,
})
if (warning) console.warn(`[commandcode] ${warning}`)
pi.registerProvider("commandcode", {
name: "Command Code",