mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-13 22:26:08 +00:00
fix(harness): surface returned tool errors
This commit is contained in:
@@ -1314,17 +1314,20 @@ describe("convertOpenClawToolToSdkTool", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("reports returned OpenClaw error results as observer failures", async () => {
|
||||
it("reports returned OpenClaw error results to both tool observers", async () => {
|
||||
const onAgentToolResult = vi.fn();
|
||||
const onToolCompleted = vi.fn();
|
||||
const sourceResult = {
|
||||
content: [{ text: '{"status":"error","error":"backend unavailable"}', type: "text" }],
|
||||
details: { status: "error", error: "backend unavailable" },
|
||||
};
|
||||
const sdkTool = convertOpenClawToolToSdkTool(makeTool({}, sourceResult), {
|
||||
onAgentToolResult,
|
||||
onToolCompleted,
|
||||
});
|
||||
|
||||
const result = await runSdkTool(sdkTool, {});
|
||||
await flushAsync();
|
||||
|
||||
expect(result).toMatchObject({ resultType: "success" });
|
||||
expect(onAgentToolResult).toHaveBeenCalledWith({
|
||||
@@ -1332,6 +1335,12 @@ describe("convertOpenClawToolToSdkTool", () => {
|
||||
result: sourceResult,
|
||||
isError: true,
|
||||
});
|
||||
expect(onToolCompleted).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
error: "backend unavailable",
|
||||
result: sourceResult,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("joins multiple text blocks with newlines", async () => {
|
||||
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
import {
|
||||
applyEmbeddedAttemptToolsAllow,
|
||||
buildEmbeddedAttemptToolRunContext,
|
||||
extractToolErrorMessage,
|
||||
getPluginToolMeta,
|
||||
isSubagentSessionKey,
|
||||
isToolResultError,
|
||||
@@ -515,15 +516,15 @@ export function convertOpenClawToolToSdkTool(
|
||||
|
||||
const sdkResult = agentToolResultToSdk(result);
|
||||
const sanitizedResult = sanitizeToolResult(result);
|
||||
notifyToolResult(
|
||||
sanitizedResult,
|
||||
sdkResult.resultType === "failure" || isToolResultError(sanitizedResult),
|
||||
);
|
||||
const resultIsError = sdkResult.resultType === "failure" || isToolResultError(sanitizedResult);
|
||||
const resultError = resultIsError ? extractToolErrorMessage(sanitizedResult) : undefined;
|
||||
notifyToolResult(sanitizedResult, resultIsError);
|
||||
notifyToolCompleted({
|
||||
toolName: sourceTool.name,
|
||||
toolCallId: invocation.toolCallId,
|
||||
args: toToolStartArgs(preparedArgs),
|
||||
result: sanitizedResult,
|
||||
...(resultError ? { error: resultError } : {}),
|
||||
startedAt,
|
||||
});
|
||||
return sdkResult;
|
||||
|
||||
@@ -131,6 +131,7 @@ export { isMessagingTool, isMessagingToolSendAction } from "../agents/embedded-a
|
||||
export {
|
||||
extractMessagingToolSend,
|
||||
extractMessagingToolSendResult,
|
||||
extractToolErrorMessage,
|
||||
extractToolResultMediaArtifact,
|
||||
filterToolResultMediaUrls,
|
||||
isToolResultError,
|
||||
|
||||
Reference in New Issue
Block a user