mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 20:03:05 +00:00
WIP: Rename model-config.ts to models-json.ts
- loadCustomModels now takes file path instead of agentDir
This commit is contained in:
parent
0ae23f19fe
commit
1c31d91c83
10 changed files with 18 additions and 19 deletions
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue