chore: format models CLI
This commit is contained in:
@@ -6,13 +6,13 @@ import {
|
||||
DEFAULT_PROVIDER,
|
||||
} from "../agents/defaults.js";
|
||||
import { loadModelCatalog } from "../agents/model-catalog.js";
|
||||
import { runWithModelFallback } from "../agents/model-fallback.js";
|
||||
import {
|
||||
buildAllowedModelSet,
|
||||
modelKey,
|
||||
resolveConfiguredModelRef,
|
||||
resolveThinkingDefault,
|
||||
} from "../agents/model-selection.js";
|
||||
import { runWithModelFallback } from "../agents/model-fallback.js";
|
||||
import { runEmbeddedPiAgent } from "../agents/pi-embedded.js";
|
||||
import { buildWorkspaceSkillSnapshot } from "../agents/skills.js";
|
||||
import {
|
||||
@@ -443,8 +443,7 @@ export async function agentCommand(
|
||||
// Update token+model fields in the session store.
|
||||
if (sessionStore && sessionKey) {
|
||||
const usage = result.meta.agentMeta?.usage;
|
||||
const modelUsed =
|
||||
result.meta.agentMeta?.model ?? fallbackModel ?? model;
|
||||
const modelUsed = result.meta.agentMeta?.model ?? fallbackModel ?? model;
|
||||
const providerUsed =
|
||||
result.meta.agentMeta?.provider ?? fallbackProvider ?? provider;
|
||||
const contextTokens =
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export { modelsListCommand, modelsStatusCommand } from "./models/list.js";
|
||||
export {
|
||||
modelsAliasesAddCommand,
|
||||
modelsAliasesListCommand,
|
||||
@@ -10,5 +9,6 @@ export {
|
||||
modelsFallbacksListCommand,
|
||||
modelsFallbacksRemoveCommand,
|
||||
} from "./models/fallbacks.js";
|
||||
export { modelsListCommand, modelsStatusCommand } from "./models/list.js";
|
||||
export { modelsScanCommand } from "./models/scan.js";
|
||||
export { modelsSetCommand } from "./models/set.js";
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
CONFIG_PATH_CLAWDBOT,
|
||||
loadConfig,
|
||||
} from "../../config/config.js";
|
||||
import { CONFIG_PATH_CLAWDBOT, loadConfig } from "../../config/config.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import {
|
||||
ensureFlagCompatibility,
|
||||
@@ -47,7 +44,7 @@ export async function modelsAliasesAddCommand(
|
||||
const alias = normalizeAlias(aliasRaw);
|
||||
const updated = await updateConfig((cfg) => {
|
||||
const resolved = resolveModelTarget({ raw: modelRaw, cfg });
|
||||
const nextAliases = { ...(cfg.agent?.modelAliases ?? {}) };
|
||||
const nextAliases = { ...cfg.agent?.modelAliases };
|
||||
nextAliases[alias] = `${resolved.provider}/${resolved.model}`;
|
||||
return {
|
||||
...cfg,
|
||||
@@ -68,7 +65,7 @@ export async function modelsAliasesRemoveCommand(
|
||||
) {
|
||||
const alias = normalizeAlias(aliasRaw);
|
||||
const updated = await updateConfig((cfg) => {
|
||||
const nextAliases = { ...(cfg.agent?.modelAliases ?? {}) };
|
||||
const nextAliases = { ...cfg.agent?.modelAliases };
|
||||
if (!nextAliases[alias]) {
|
||||
throw new Error(`Alias not found: ${alias}`);
|
||||
}
|
||||
@@ -83,7 +80,10 @@ export async function modelsAliasesRemoveCommand(
|
||||
});
|
||||
|
||||
runtime.log(`Updated ${CONFIG_PATH_CLAWDBOT}`);
|
||||
if (!updated.agent?.modelAliases || Object.keys(updated.agent.modelAliases).length === 0) {
|
||||
if (
|
||||
!updated.agent?.modelAliases ||
|
||||
Object.keys(updated.agent.modelAliases).length === 0
|
||||
) {
|
||||
runtime.log("No aliases configured.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import {
|
||||
CONFIG_PATH_CLAWDBOT,
|
||||
loadConfig,
|
||||
} from "../../config/config.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import {
|
||||
buildModelAliasIndex,
|
||||
resolveModelRefFromString,
|
||||
} from "../../agents/model-selection.js";
|
||||
import { CONFIG_PATH_CLAWDBOT, loadConfig } from "../../config/config.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import {
|
||||
DEFAULT_PROVIDER,
|
||||
ensureFlagCompatibility,
|
||||
@@ -60,8 +57,8 @@ export async function modelsFallbacksAddCommand(
|
||||
aliasIndex,
|
||||
}),
|
||||
)
|
||||
.filter(Boolean)
|
||||
.map((entry) => modelKey(entry!.ref.provider, entry!.ref.model));
|
||||
.filter((entry): entry is NonNullable<typeof entry> => Boolean(entry))
|
||||
.map((entry) => modelKey(entry.ref.provider, entry.ref.model));
|
||||
|
||||
if (existingKeys.includes(targetKey)) return cfg;
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import chalk from "chalk";
|
||||
import { type Api, getEnvApiKey, type Model } from "@mariozechner/pi-ai";
|
||||
import {
|
||||
discoverAuthStorage,
|
||||
discoverModels,
|
||||
} from "@mariozechner/pi-coding-agent";
|
||||
import { getEnvApiKey, type Api, type Model } from "@mariozechner/pi-ai";
|
||||
import chalk from "chalk";
|
||||
|
||||
import { resolveClawdbotAgentDir } from "../../agents/agent-paths.js";
|
||||
import { ensureClawdbotModelsJson } from "../../agents/models-config.js";
|
||||
import {
|
||||
buildModelAliasIndex,
|
||||
parseModelRef,
|
||||
resolveModelRefFromString,
|
||||
resolveConfiguredModelRef,
|
||||
resolveModelRefFromString,
|
||||
} from "../../agents/model-selection.js";
|
||||
import { ensureClawdbotModelsJson } from "../../agents/models-config.js";
|
||||
import {
|
||||
type ClawdbotConfig,
|
||||
CONFIG_PATH_CLAWDBOT,
|
||||
loadConfig,
|
||||
type ClawdbotConfig,
|
||||
} from "../../config/config.js";
|
||||
import { info } from "../../globals.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
@@ -35,7 +35,9 @@ const LOCAL_PAD = 5;
|
||||
const AUTH_PAD = 5;
|
||||
|
||||
const isRich = (opts?: { json?: boolean; plain?: boolean }) =>
|
||||
Boolean(process.stdout.isTTY && chalk.level > 0 && !opts?.json && !opts?.plain);
|
||||
Boolean(
|
||||
process.stdout.isTTY && chalk.level > 0 && !opts?.json && !opts?.plain,
|
||||
);
|
||||
|
||||
const pad = (value: string, size: number) => value.padEnd(size);
|
||||
|
||||
|
||||
@@ -3,9 +3,10 @@ import { discoverAuthStorage } from "@mariozechner/pi-coding-agent";
|
||||
|
||||
import { resolveClawdbotAgentDir } from "../../agents/agent-paths.js";
|
||||
import {
|
||||
scanOpenRouterModels,
|
||||
type ModelScanResult,
|
||||
scanOpenRouterModels,
|
||||
} from "../../agents/model-scan.js";
|
||||
import { CONFIG_PATH_CLAWDBOT } from "../../config/config.js";
|
||||
import { warn } from "../../globals.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import {
|
||||
@@ -14,7 +15,6 @@ import {
|
||||
formatTokenK,
|
||||
updateConfig,
|
||||
} from "./shared.js";
|
||||
import { CONFIG_PATH_CLAWDBOT } from "../../config/config.js";
|
||||
|
||||
const MODEL_PAD = 42;
|
||||
const CTX_PAD = 8;
|
||||
@@ -27,7 +27,6 @@ const truncate = (value: string, max: number) => {
|
||||
return `${value.slice(0, max - 3)}...`;
|
||||
};
|
||||
|
||||
|
||||
function sortScanResults(results: ModelScanResult[]): ModelScanResult[] {
|
||||
return results.slice().sort((a, b) => {
|
||||
const aImage = a.image.ok ? 1 : 0;
|
||||
@@ -133,16 +132,20 @@ export async function modelsScanCommand(
|
||||
runtime: RuntimeEnv,
|
||||
) {
|
||||
const minParams = opts.minParams ? Number(opts.minParams) : undefined;
|
||||
if (minParams !== undefined && (!Number.isFinite(minParams) || minParams < 0)) {
|
||||
if (
|
||||
minParams !== undefined &&
|
||||
(!Number.isFinite(minParams) || minParams < 0)
|
||||
) {
|
||||
throw new Error("--min-params must be >= 0");
|
||||
}
|
||||
const maxAgeDays = opts.maxAgeDays ? Number(opts.maxAgeDays) : undefined;
|
||||
if (maxAgeDays !== undefined && (!Number.isFinite(maxAgeDays) || maxAgeDays < 0)) {
|
||||
if (
|
||||
maxAgeDays !== undefined &&
|
||||
(!Number.isFinite(maxAgeDays) || maxAgeDays < 0)
|
||||
) {
|
||||
throw new Error("--max-age-days must be >= 0");
|
||||
}
|
||||
const maxCandidates = opts.maxCandidates
|
||||
? Number(opts.maxCandidates)
|
||||
: 6;
|
||||
const maxCandidates = opts.maxCandidates ? Number(opts.maxCandidates) : 6;
|
||||
if (!Number.isFinite(maxCandidates) || maxCandidates <= 0) {
|
||||
throw new Error("--max-candidates must be > 0");
|
||||
}
|
||||
@@ -151,7 +154,10 @@ export async function modelsScanCommand(
|
||||
throw new Error("--timeout must be > 0");
|
||||
}
|
||||
const concurrency = opts.concurrency ? Number(opts.concurrency) : undefined;
|
||||
if (concurrency !== undefined && (!Number.isFinite(concurrency) || concurrency <= 0)) {
|
||||
if (
|
||||
concurrency !== undefined &&
|
||||
(!Number.isFinite(concurrency) || concurrency <= 0)
|
||||
) {
|
||||
throw new Error("--concurrency must be > 0");
|
||||
}
|
||||
|
||||
@@ -226,9 +232,7 @@ export async function modelsScanCommand(
|
||||
|
||||
const allowlist = buildAllowlistSet(updated);
|
||||
const allowlistMissing =
|
||||
allowlist.size > 0
|
||||
? selected.filter((entry) => !allowlist.has(entry))
|
||||
: [];
|
||||
allowlist.size > 0 ? selected.filter((entry) => !allowlist.has(entry)) : [];
|
||||
|
||||
if (opts.json) {
|
||||
runtime.log(
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { CONFIG_PATH_CLAWDBOT } from "../../config/config.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import { buildAllowlistSet, modelKey, resolveModelTarget, updateConfig } from "./shared.js";
|
||||
import {
|
||||
buildAllowlistSet,
|
||||
modelKey,
|
||||
resolveModelTarget,
|
||||
updateConfig,
|
||||
} from "./shared.js";
|
||||
|
||||
export async function modelsSetCommand(
|
||||
modelRaw: string,
|
||||
runtime: RuntimeEnv,
|
||||
) {
|
||||
export async function modelsSetCommand(modelRaw: string, runtime: RuntimeEnv) {
|
||||
const updated = await updateConfig((cfg) => {
|
||||
const resolved = resolveModelTarget({ raw: modelRaw, cfg });
|
||||
const allowlist = buildAllowlistSet(cfg);
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
DEFAULT_MODEL,
|
||||
DEFAULT_PROVIDER,
|
||||
} from "../../agents/defaults.js";
|
||||
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../../agents/defaults.js";
|
||||
import {
|
||||
buildModelAliasIndex,
|
||||
modelKey,
|
||||
@@ -9,9 +6,9 @@ import {
|
||||
resolveModelRefFromString,
|
||||
} from "../../agents/model-selection.js";
|
||||
import {
|
||||
type ClawdbotConfig,
|
||||
readConfigFileSnapshot,
|
||||
writeConfigFile,
|
||||
type ClawdbotConfig,
|
||||
} from "../../config/config.js";
|
||||
|
||||
export const ensureFlagCompatibility = (opts: {
|
||||
|
||||
Reference in New Issue
Block a user