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

@ -3,7 +3,7 @@
*/
import type { Api, Model } from "@mariozechner/pi-ai";
import { getAvailableModels } from "../core/model-config.js";
import { getAvailableModels } from "../core/models-json.js";
import type { SettingsManager } from "../core/settings-manager.js";
import { fuzzyFilter } from "../utils/fuzzy.js";

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";

View file

@ -73,7 +73,7 @@ export {
} from "./core/hooks/index.js";
export { messageTransformer } from "./core/messages.js";
// Model configuration and OAuth
export { findModel, getApiKeyForModel, getAvailableModels } from "./core/model-config.js";
export { findModel, getApiKeyForModel, getAvailableModels } from "./core/models-json.js";
export {
getOAuthProviders,
login,

View file

@ -18,8 +18,8 @@ import type { AgentSession } from "./core/agent-session.js";
import type { LoadedCustomTool } from "./core/custom-tools/index.js";
import { exportFromFile } from "./core/export-html.js";
import type { HookUIContext } from "./core/index.js";
import { findModel } from "./core/model-config.js";
import { resolveModelScope, type ScopedModel } from "./core/model-resolver.js";
import { findModel } from "./core/models-json.js";
import { type CreateAgentSessionOptions, configureOAuthStorage, createAgentSession } from "./core/sdk.js";
import { SessionManager } from "./core/session-manager.js";
import { SettingsManager } from "./core/settings-manager.js";

View file

@ -3,7 +3,7 @@ import type { AssistantMessage } from "@mariozechner/pi-ai";
import { type Component, visibleWidth } from "@mariozechner/pi-tui";
import { existsSync, type FSWatcher, readFileSync, watch } from "fs";
import { dirname, join } from "path";
import { isModelUsingOAuth } from "../../../core/model-config.js";
import { isModelUsingOAuth } from "../../../core/models-json.js";
import { theme } from "../theme/theme.js";
/**

View file

@ -10,7 +10,7 @@ import {
Text,
type TUI,
} from "@mariozechner/pi-tui";
import { getAvailableModels } from "../../../core/model-config.js";
import { getAvailableModels } from "../../../core/models-json.js";
import type { SettingsManager } from "../../../core/settings-manager.js";
import { fuzzyFilter } from "../../../utils/fuzzy.js";
import { theme } from "../theme/theme.js";

View file

@ -30,7 +30,7 @@ import type { AgentSession, AgentSessionEvent } from "../../core/agent-session.j
import type { LoadedCustomTool, SessionEvent as ToolSessionEvent } from "../../core/custom-tools/index.js";
import type { HookUIContext } from "../../core/hooks/index.js";
import { isBashExecutionMessage } from "../../core/messages.js";
import { invalidateOAuthCache } from "../../core/model-config.js";
import { invalidateOAuthCache } from "../../core/models-json.js";
import { listOAuthProviders, login, logout, type OAuthProvider } from "../../core/oauth/index.js";
import {
getLatestCompactionEntry,