fix: Model flag parsing and model args (#42)

This commit is contained in:
Devansh Jain
2025-10-30 20:23:21 -07:00
committed by GitHub
parent 77d78c22da
commit 32a3f7c7ab
7 changed files with 106 additions and 60 deletions

64
src/agent/model.ts Normal file
View File

@@ -0,0 +1,64 @@
/**
* Model resolution and handling utilities
*/
import modelsData from "../models.json";
export const models = modelsData;
/**
* Resolve a model by ID or handle
* @param modelIdentifier - Can be either a model ID (e.g., "opus") or a full handle (e.g., "anthropic/claude-opus-4-1-20250805")
* @returns The model handle if found, null otherwise
*/
export function resolveModel(modelIdentifier: string): string | null {
const byId = models.find((m) => m.id === modelIdentifier);
if (byId) return byId.handle;
const byHandle = models.find((m) => m.handle === modelIdentifier);
if (byHandle) return byHandle.handle;
return null;
}
/**
* Get the default model handle
*/
export function getDefaultModel(): string {
const defaultModel = models.find((m) => m.isDefault);
return defaultModel?.handle || models[0].handle;
}
/**
* Format available models for error messages
*/
export function formatAvailableModels(): string {
return models.map((m) => ` ${m.id.padEnd(20)} ${m.handle}`).join("\n");
}
/**
* Get model info by ID or handle
* @param modelIdentifier - Can be either a model ID (e.g., "opus") or a full handle (e.g., "anthropic/claude-opus-4-1-20250805")
* @returns The model info if found, null otherwise
*/
export function getModelInfo(modelIdentifier: string) {
const byId = models.find((m) => m.id === modelIdentifier);
if (byId) return byId;
const byHandle = models.find((m) => m.handle === modelIdentifier);
if (byHandle) return byHandle;
return null;
}
/**
* Get updateArgs for a model by ID or handle
* @param modelIdentifier - Can be either a model ID (e.g., "opus") or a full handle (e.g., "anthropic/claude-opus-4-1-20250805")
* @returns The updateArgs if found, undefined otherwise
*/
export function getModelUpdateArgs(
modelIdentifier?: string,
): Record<string, unknown> | undefined {
if (!modelIdentifier) return undefined;
const modelInfo = getModelInfo(modelIdentifier);
return modelInfo?.updateArgs;
}