mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
feat: add @automaker/model-resolver package
- Extract model string resolution logic - Map model aliases to full model strings (haiku -> claude-haiku-4-5) - Handle multiple model sources with priority - Re-export model constants from @automaker/types Provides centralized model resolution for Claude models. Simplifies model handling across server and UI. Dependencies: @automaker/types 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
21
libs/model-resolver/package.json
Normal file
21
libs/model-resolver/package.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "@automaker/model-resolver",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Model resolution utilities for AutoMaker",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"types": "dist/index.d.ts",
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"watch": "tsc --watch"
|
||||||
|
},
|
||||||
|
"keywords": ["automaker", "model", "resolver"],
|
||||||
|
"author": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@automaker/types": "^1.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^22.10.5",
|
||||||
|
"typescript": "^5.7.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
13
libs/model-resolver/src/index.ts
Normal file
13
libs/model-resolver/src/index.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* @automaker/model-resolver
|
||||||
|
* Model resolution utilities for AutoMaker
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Re-export constants from types
|
||||||
|
export { CLAUDE_MODEL_MAP, DEFAULT_MODELS, type ModelAlias } from '@automaker/types';
|
||||||
|
|
||||||
|
// Export resolver functions
|
||||||
|
export {
|
||||||
|
resolveModelString,
|
||||||
|
getEffectiveModel,
|
||||||
|
} from './resolver';
|
||||||
65
libs/model-resolver/src/resolver.ts
Normal file
65
libs/model-resolver/src/resolver.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* Model resolution utilities for handling model string mapping
|
||||||
|
*
|
||||||
|
* Provides centralized model resolution logic:
|
||||||
|
* - Maps Claude model aliases to full model strings
|
||||||
|
* - Provides default models per provider
|
||||||
|
* - Handles multiple model sources with priority
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { CLAUDE_MODEL_MAP, DEFAULT_MODELS } from '@automaker/types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve a model key/alias to a full model string
|
||||||
|
*
|
||||||
|
* @param modelKey - Model key (e.g., "opus", "gpt-5.2", "claude-sonnet-4-20250514")
|
||||||
|
* @param defaultModel - Fallback model if modelKey is undefined
|
||||||
|
* @returns Full model string
|
||||||
|
*/
|
||||||
|
export function resolveModelString(
|
||||||
|
modelKey?: string,
|
||||||
|
defaultModel: string = DEFAULT_MODELS.claude
|
||||||
|
): string {
|
||||||
|
// No model specified - use default
|
||||||
|
if (!modelKey) {
|
||||||
|
return defaultModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Full Claude model string - pass through unchanged
|
||||||
|
if (modelKey.includes("claude-")) {
|
||||||
|
console.log(`[ModelResolver] Using full Claude model string: ${modelKey}`);
|
||||||
|
return modelKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look up Claude model alias
|
||||||
|
const resolved = CLAUDE_MODEL_MAP[modelKey];
|
||||||
|
if (resolved) {
|
||||||
|
console.log(
|
||||||
|
`[ModelResolver] Resolved model alias: "${modelKey}" -> "${resolved}"`
|
||||||
|
);
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unknown model key - use default
|
||||||
|
console.warn(
|
||||||
|
`[ModelResolver] Unknown model key "${modelKey}", using default: "${defaultModel}"`
|
||||||
|
);
|
||||||
|
return defaultModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the effective model from multiple sources
|
||||||
|
* Priority: explicit model > session model > default
|
||||||
|
*
|
||||||
|
* @param explicitModel - Explicitly provided model (highest priority)
|
||||||
|
* @param sessionModel - Model from session (medium priority)
|
||||||
|
* @param defaultModel - Fallback default model (lowest priority)
|
||||||
|
* @returns Resolved model string
|
||||||
|
*/
|
||||||
|
export function getEffectiveModel(
|
||||||
|
explicitModel?: string,
|
||||||
|
sessionModel?: string,
|
||||||
|
defaultModel?: string
|
||||||
|
): string {
|
||||||
|
return resolveModelString(explicitModel || sessionModel, defaultModel);
|
||||||
|
}
|
||||||
20
libs/model-resolver/tsconfig.json
Normal file
20
libs/model-resolver/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2020",
|
||||||
|
"module": "commonjs",
|
||||||
|
"lib": ["ES2020"],
|
||||||
|
"types": ["node"],
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"outDir": "./dist",
|
||||||
|
"rootDir": "./src",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"moduleResolution": "node"
|
||||||
|
},
|
||||||
|
"include": ["src/**/*"],
|
||||||
|
"exclude": ["node_modules", "dist"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user