* refactor(shared): unify binary downloader and session path storage - Create binary-downloader.ts for common download/extract logic - Create session-injected-paths.ts for unified path tracking - Refactor comment-checker, ast-grep, grep downloaders to use shared util - Consolidate directory injector types into shared module * feat(shared): implement unified model resolution pipeline - Create ModelResolutionPipeline for centralized model selection - Refactor model-resolver to use pipeline - Update delegate-task and config-handler to use unified logic - Ensure consistent model resolution across all agent types * refactor(agents): simplify agent utils and metadata management - Extract helper functions for config merging and env context - Register prompt metadata for all agents - Simplify agent variant detection logic * cleanup: inline utilities and remove unused exports - Remove case-insensitive.ts (inline with native JS) - Simplify opencode-version helpers - Remove unused getModelLimit, createCompactionContextInjector exports - Inline transcript entry creation in claude-code-hooks - Update tests accordingly --------- Co-authored-by: justsisyphus <justsisyphus@users.noreply.github.com>
65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
import { log } from "./logger"
|
|
import type { FallbackEntry } from "./model-requirements"
|
|
import { resolveModelPipeline } from "./model-resolution-pipeline"
|
|
|
|
export type ModelResolutionInput = {
|
|
userModel?: string
|
|
inheritedModel?: string
|
|
systemDefault?: string
|
|
}
|
|
|
|
export type ModelSource =
|
|
| "override"
|
|
| "category-default"
|
|
| "provider-fallback"
|
|
| "system-default"
|
|
|
|
export type ModelResolutionResult = {
|
|
model: string
|
|
source: ModelSource
|
|
variant?: string
|
|
}
|
|
|
|
export type ExtendedModelResolutionInput = {
|
|
uiSelectedModel?: string
|
|
userModel?: string
|
|
categoryDefaultModel?: string
|
|
fallbackChain?: FallbackEntry[]
|
|
availableModels: Set<string>
|
|
systemDefaultModel?: string
|
|
}
|
|
|
|
function normalizeModel(model?: string): string | undefined {
|
|
const trimmed = model?.trim()
|
|
return trimmed || undefined
|
|
}
|
|
|
|
export function resolveModel(input: ModelResolutionInput): string | undefined {
|
|
return (
|
|
normalizeModel(input.userModel) ??
|
|
normalizeModel(input.inheritedModel) ??
|
|
input.systemDefault
|
|
)
|
|
}
|
|
|
|
export function resolveModelWithFallback(
|
|
input: ExtendedModelResolutionInput,
|
|
): ModelResolutionResult | undefined {
|
|
const { uiSelectedModel, userModel, categoryDefaultModel, fallbackChain, availableModels, systemDefaultModel } = input
|
|
const resolved = resolveModelPipeline({
|
|
intent: { uiSelectedModel, userModel, categoryDefaultModel },
|
|
constraints: { availableModels },
|
|
policy: { fallbackChain, systemDefaultModel },
|
|
})
|
|
|
|
if (!resolved) {
|
|
return undefined
|
|
}
|
|
|
|
return {
|
|
model: resolved.model,
|
|
source: resolved.provenance,
|
|
variant: resolved.variant,
|
|
}
|
|
}
|