Files
openclaw/extensions/qa-lab/src/extract-tool-payload.ts
2026-04-05 23:21:56 +01:00

32 lines
778 B
TypeScript

type ResultWithDetails = {
details?: unknown;
content?: unknown;
};
export function extractQaToolPayload(result: ResultWithDetails | null | undefined): unknown {
if (!result) {
return undefined;
}
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) {
return result.content ?? result;
}
try {
return JSON.parse(text);
} catch {
return text;
}
}