mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 23:40:21 +00:00
refactor(plugin-sdk): share tool payload extraction
This commit is contained in:
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user