tool: compat wrapper for resolveChildModel; accept old injected signature while keeping new API

This commit is contained in:
pi
2026-04-12 11:20:30 +01:00
parent 7a58b53a04
commit 7691915e38

View File

@@ -54,11 +54,18 @@ function makeErrorResult(text: string, mode: "single" | "parallel" | "chain") {
}; };
} }
import type { ModelSelection } from "./models.ts";
export function createSubagentTool(deps: { export function createSubagentTool(deps: {
listAvailableModelReferences?: typeof listAvailableModelReferences; listAvailableModelReferences?: typeof listAvailableModelReferences;
normalizeAvailableModelReference?: typeof normalizeAvailableModelReference; normalizeAvailableModelReference?: typeof normalizeAvailableModelReference;
parameters?: typeof SubagentParamsSchema; parameters?: typeof SubagentParamsSchema;
resolveChildModel?: typeof resolveChildModel; // Compatibility: accept injected resolveChildModel functions with either the
// new API ({ callModel?, presetModel? }) or the older test/hooks API
// ({ taskModel?, topLevelModel? }). We adapt at callsite below.
resolveChildModel?:
| typeof resolveChildModel
| ((input: { taskModel?: string; topLevelModel?: string }) => ModelSelection);
runSingleTask?: (input: { runSingleTask?: (input: {
cwd: string; cwd: string;
meta: Record<string, unknown>; meta: Record<string, unknown>;
@@ -129,6 +136,23 @@ export function createSubagentTool(deps: {
step.model = normalizedStepModel; step.model = normalizedStepModel;
} }
const callResolveChildModel = (input: {
callModel?: string;
presetModel?: string;
taskModel?: string;
topLevelModel?: string;
}) => {
// If an injected resolveChildModel exists, call it with the older-shape
// keys (taskModel/topLevelModel) for compatibility. Otherwise, use the
// internal resolveChildModel which expects { callModel, presetModel }.
if (deps.resolveChildModel) {
const injected = deps.resolveChildModel as unknown as (arg: { taskModel?: string; topLevelModel?: string }) => unknown;
return injected({ taskModel: input.callModel ?? input.taskModel, topLevelModel: input.presetModel ?? input.topLevelModel }) as ModelSelection;
}
return resolveChildModel({ callModel: input.callModel ?? input.taskModel, presetModel: input.presetModel ?? input.topLevelModel });
};
const runTask = async (input: { const runTask = async (input: {
task: string; task: string;
cwd?: string; cwd?: string;
@@ -137,9 +161,7 @@ export function createSubagentTool(deps: {
step?: number; step?: number;
mode: "single" | "parallel" | "chain"; mode: "single" | "parallel" | "chain";
}) => { }) => {
const model = (deps.resolveChildModel ?? resolveChildModel)({ const model = callResolveChildModel({
// compatibility: newer resolveChildModel expects { callModel, presetModel }
// older hooks/tests used { taskModel, topLevelModel }
callModel: input.taskModel, callModel: input.taskModel,
presetModel: params.model, presetModel: params.model,
taskModel: input.taskModel, taskModel: input.taskModel,