mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 04:17:42 +00:00
26 lines
724 B
TypeScript
26 lines
724 B
TypeScript
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
|
|
|
export function extractToolPayload(result: AgentToolResult<unknown>): unknown {
|
|
if (result.details !== undefined) {
|
|
return result.details;
|
|
}
|
|
const textBlock = Array.isArray(result.content)
|
|
? result.content.find(
|
|
(block) =>
|
|
block &&
|
|
typeof block === "object" &&
|
|
(block as { type?: unknown }).type === "text" &&
|
|
typeof (block as { text?: unknown }).text === "string",
|
|
)
|
|
: undefined;
|
|
const text = (textBlock as { text?: string } | undefined)?.text;
|
|
if (text) {
|
|
try {
|
|
return JSON.parse(text);
|
|
} catch {
|
|
return text;
|
|
}
|
|
}
|
|
return result.content ?? result;
|
|
}
|