WIP: Rename model-config.ts to models-json.ts

- loadCustomModels now takes file path instead of agentDir
This commit is contained in:
Mario Zechner 2025-12-25 01:15:17 +01:00
parent 0ae23f19fe
commit 1c31d91c83
10 changed files with 18 additions and 19 deletions

View file

@ -23,7 +23,7 @@ import type { LoadedCustomTool, SessionEvent as ToolSessionEvent } from "./custo
import { exportSessionToHtml } from "./export-html.js";
import type { HookRunner, SessionEventResult, TurnEndEvent, TurnStartEvent } from "./hooks/index.js";
import type { BashExecutionMessage } from "./messages.js";
import { getApiKeyForModel, getAvailableModels } from "./model-config.js";
import { getApiKeyForModel, getAvailableModels } from "./models-json.js";
import type { CompactionEntry, SessionManager } from "./session-manager.js";
import type { SettingsManager, SkillsSettings } from "./settings-manager.js";
import { expandSlashCommand, type FileSlashCommand } from "./slash-commands.js";

View file

@ -6,7 +6,7 @@ import type { ThinkingLevel } from "@mariozechner/pi-agent-core";
import type { Api, KnownProvider, Model } from "@mariozechner/pi-ai";
import chalk from "chalk";
import { isValidThinkingLevel } from "../cli/args.js";
import { findModel, getApiKeyForModel, getAvailableModels } from "./model-config.js";
import { findModel, getApiKeyForModel, getAvailableModels } from "./models-json.js";
import type { SettingsManager } from "./settings-manager.js";
/** Default model IDs for each known provider */

View file

@ -95,17 +95,16 @@ export function resolveApiKey(keyConfig: string): string | undefined {
}
/**
* Load custom models from models.json in agent config dir
* Load custom models from a models.json file
* Returns { models, error } - either models array or error message
*/
function loadCustomModels(agentDir: string = getAgentDir()): { models: Model<Api>[]; error: string | null } {
const configPath = join(agentDir, "models.json");
if (!existsSync(configPath)) {
function loadCustomModels(modelsJsonPath: string): { models: Model<Api>[]; error: string | null } {
if (!existsSync(modelsJsonPath)) {
return { models: [], error: null };
}
try {
const content = readFileSync(configPath, "utf-8");
const content = readFileSync(modelsJsonPath, "utf-8");
const config: ModelsConfig = JSON.parse(content);
// Validate schema
@ -117,7 +116,7 @@ function loadCustomModels(agentDir: string = getAgentDir()): { models: Model<Api
"Unknown schema error";
return {
models: [],
error: `Invalid models.json schema:\n${errors}\n\nFile: ${configPath}`,
error: `Invalid models.json schema:\n${errors}\n\nFile: ${modelsJsonPath}`,
};
}
@ -127,7 +126,7 @@ function loadCustomModels(agentDir: string = getAgentDir()): { models: Model<Api
} catch (error) {
return {
models: [],
error: `Invalid models.json: ${error instanceof Error ? error.message : error}\n\nFile: ${configPath}`,
error: `Invalid models.json: ${error instanceof Error ? error.message : error}\n\nFile: ${modelsJsonPath}`,
};
}
@ -137,12 +136,12 @@ function loadCustomModels(agentDir: string = getAgentDir()): { models: Model<Api
if (error instanceof SyntaxError) {
return {
models: [],
error: `Failed to parse models.json: ${error.message}\n\nFile: ${configPath}`,
error: `Failed to parse models.json: ${error.message}\n\nFile: ${modelsJsonPath}`,
};
}
return {
models: [],
error: `Failed to load models.json: ${error instanceof Error ? error.message : error}\n\nFile: ${configPath}`,
error: `Failed to load models.json: ${error instanceof Error ? error.message : error}\n\nFile: ${modelsJsonPath}`,
};
}
}
@ -244,7 +243,7 @@ export function loadAndMergeModels(agentDir: string = getAgentDir()): { models:
}
// Load custom models
const { models: customModels, error } = loadCustomModels(agentDir);
const { models: customModels, error } = loadCustomModels(join(agentDir, "models.json"));
if (error) {
return { models: [], error };

View file

@ -45,7 +45,7 @@ import {
getApiKeyForModel,
getAvailableModels,
loadAndMergeModels,
} from "./model-config.js";
} from "./models-json.js";
import { SessionManager } from "./session-manager.js";
import { type Settings, SettingsManager, type SkillsSettings } from "./settings-manager.js";
import { loadSkills as loadSkillsInternal, type Skill } from "./skills.js";