Files
openclaw/src/plugin-sdk/boolean-param.ts
2026-04-07 13:01:23 +01:00

21 lines
562 B
TypeScript

import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js";
/** Read loose boolean params from tool input that may arrive as booleans or "true"/"false" strings. */
export function readBooleanParam(
params: Record<string, unknown>,
key: string,
): boolean | undefined {
const raw = params[key];
if (typeof raw === "boolean") {
return raw;
}
const normalized = normalizeOptionalLowercaseString(raw);
if (normalized === "true") {
return true;
}
if (normalized === "false") {
return false;
}
return undefined;
}