fix: allow extension to load when offline

The model fetch at startup throws and blocks pi from starting when
there's no network. Catch the error and register the provider with
an empty model list instead.
This commit is contained in:
K2
2026-07-23 11:19:04 +01:00
parent 64d538a910
commit 811f908918
2 changed files with 13 additions and 2 deletions
+7 -2
View File
@@ -17,7 +17,7 @@ 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 } from "./src/models.ts"
import { DEFAULT_MODELS_URL, fetchCommandCodeModels, type CommandCodeModel } from "./src/models.ts"
import { getApiKey, login, refreshToken } from "./src/oauth.ts"
const API_BASE = process.env.COMMANDCODE_API_BASE ?? DEFAULT_API_BASE
@@ -79,7 +79,12 @@ const streamCommandCode = createStreamCommandCode({
// ---------------------------------------------------------------------------
export default async function (pi: ExtensionAPI) {
const models = await fetchCommandCodeModels({ url: MODELS_URL })
let models: readonly CommandCodeModel[]
try {
models = await fetchCommandCodeModels({ url: MODELS_URL })
} catch {
models = []
}
pi.registerProvider("commandcode", {
name: "Command Code",