perf(models): lazy-load heavy deps in models list

This commit is contained in:
Peter Steinberger
2026-02-15 19:18:15 +00:00
parent 5c5af2b14e
commit 38f430e133
2 changed files with 7 additions and 3 deletions

View File

@@ -99,6 +99,10 @@ describe("models cli", () => {
it("shows help for models auth without error exit", async () => {
const program = new Command();
program.exitOverride();
program.configureOutput({
writeOut: () => {},
writeErr: () => {},
});
registerModelsCli(program);
try {

View File

@@ -2,11 +2,8 @@ import type { Api, Model } from "@mariozechner/pi-ai";
import type { ModelRegistry } from "../../agents/pi-model-discovery.js";
import type { RuntimeEnv } from "../../runtime.js";
import type { ModelRow } from "./list.types.js";
import { ensureAuthProfileStore } from "../../agents/auth-profiles.js";
import { resolveForwardCompatModel } from "../../agents/model-forward-compat.js";
import { parseModelRef } from "../../agents/model-selection.js";
import { resolveModel } from "../../agents/pi-embedded-runner/model.js";
import { loadConfig } from "../../config/config.js";
import { resolveConfiguredEntries } from "./list.configured.js";
import { formatErrorWithStack } from "./list.errors.js";
import { loadModelRegistry, toModelRow } from "./list.registry.js";
@@ -24,6 +21,8 @@ export async function modelsListCommand(
runtime: RuntimeEnv,
) {
ensureFlagCompatibility(opts);
const { loadConfig } = await import("../../config/config.js");
const { ensureAuthProfileStore } = await import("../../agents/auth-profiles.js");
const cfg = loadConfig();
const authStore = ensureAuthProfileStore();
const providerFilter = (() => {
@@ -111,6 +110,7 @@ export async function modelsListCommand(
}
}
if (!model) {
const { resolveModel } = await import("../../agents/pi-embedded-runner/model.js");
model = resolveModel(entry.ref.provider, entry.ref.model, undefined, cfg).model;
}
if (opts.local && model && !isLocalBaseUrl(model.baseUrl)) {