refactor(agents): dedupe model and tool test helpers

This commit is contained in:
Peter Steinberger
2026-03-02 21:30:12 +00:00
parent 067855e623
commit ab8b8dae70
13 changed files with 302 additions and 374 deletions

View File

@@ -410,56 +410,47 @@ export async function spawnSubagentDirect(
}
thinkingOverride = normalized;
}
try {
await callGateway({
method: "sessions.patch",
params: { key: childSessionKey, spawnDepth: childDepth },
timeoutMs: 10_000,
});
} catch (err) {
const messageText =
err instanceof Error ? err.message : typeof err === "string" ? err : "error";
const patchChildSession = async (patch: Record<string, unknown>): Promise<string | undefined> => {
try {
await callGateway({
method: "sessions.patch",
params: { key: childSessionKey, ...patch },
timeoutMs: 10_000,
});
return undefined;
} catch (err) {
return err instanceof Error ? err.message : typeof err === "string" ? err : "error";
}
};
const spawnDepthPatchError = await patchChildSession({ spawnDepth: childDepth });
if (spawnDepthPatchError) {
return {
status: "error",
error: messageText,
error: spawnDepthPatchError,
childSessionKey,
};
}
if (resolvedModel) {
try {
await callGateway({
method: "sessions.patch",
params: { key: childSessionKey, model: resolvedModel },
timeoutMs: 10_000,
});
modelApplied = true;
} catch (err) {
const messageText =
err instanceof Error ? err.message : typeof err === "string" ? err : "error";
const modelPatchError = await patchChildSession({ model: resolvedModel });
if (modelPatchError) {
return {
status: "error",
error: messageText,
error: modelPatchError,
childSessionKey,
};
}
modelApplied = true;
}
if (thinkingOverride !== undefined) {
try {
await callGateway({
method: "sessions.patch",
params: {
key: childSessionKey,
thinkingLevel: thinkingOverride === "off" ? null : thinkingOverride,
},
timeoutMs: 10_000,
});
} catch (err) {
const messageText =
err instanceof Error ? err.message : typeof err === "string" ? err : "error";
const thinkingPatchError = await patchChildSession({
thinkingLevel: thinkingOverride === "off" ? null : thinkingOverride,
});
if (thinkingPatchError) {
return {
status: "error",
error: messageText,
error: thinkingPatchError,
childSessionKey,
};
}