refactor(plugin-sdk): share tool payload extraction

This commit is contained in:
Vincent Koc
2026-04-08 08:45:08 +01:00
parent a04b9a27fb
commit be530f085d
10 changed files with 104 additions and 92 deletions

View File

@@ -1,31 +1 @@
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;
}
}
export { extractToolPayload as extractQaToolPayload } from "openclaw/plugin-sdk/tool-payload";