fix(coding-agent): 识别顶层工具错误标记

This commit is contained in:
jiwangyihao
2026-05-13 02:18:56 +02:00
committed by can1357
parent e043125e11
commit 0f73414d3b
2 changed files with 33 additions and 0 deletions
@@ -20,6 +20,9 @@ type ToolValue =
hasError?: boolean;
};
function toolResultHasError(result: AgentToolResult): boolean {
if ((result as { isError?: unknown }).isError === true) {
return true;
}
if (!(result.details && typeof result.details === "object")) {
return false;
}
@@ -109,6 +109,36 @@ describe("callSessionTool", () => {
]);
});
it("marks results with top-level isError", async () => {
const session = createSession([
createTool(
"custom",
async () =>
({
content: [{ type: "text", text: "preview mismatch" }],
isError: true,
}) as AgentToolResult,
),
]);
const statuses: Array<Record<string, unknown>> = [];
const result = await callSessionTool("custom", {}, { session, emitStatus: event => statuses.push(event) });
expect(result).toEqual({
text: "preview mismatch",
details: undefined,
hasError: true,
});
expect(statuses).toEqual([
expect.objectContaining({
op: "custom",
chars: 16,
hasError: true,
error: "preview mismatch",
}),
]);
});
it("throws when the requested tool is not available in the session registry", async () => {
const session = createSession([]);