mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-16 03:31:10 +00:00
32 lines
778 B
TypeScript
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;
|
|
}
|
|
}
|