From 741e74972b820cf1c42b241450d290c00c6e9e73 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 2 Mar 2026 14:35:40 +0000 Subject: [PATCH] refactor(plugin-sdk): share boolean action param parsing --- extensions/bluebubbles/src/actions.ts | 18 +----------------- src/infra/outbound/message-action-params.ts | 21 ++------------------- src/plugin-sdk/boolean-param.ts | 19 +++++++++++++++++++ src/plugin-sdk/index.ts | 1 + 4 files changed, 23 insertions(+), 36 deletions(-) create mode 100644 src/plugin-sdk/boolean-param.ts diff --git a/extensions/bluebubbles/src/actions.ts b/extensions/bluebubbles/src/actions.ts index e774ef6c85e..0c6f0630ed0 100644 --- a/extensions/bluebubbles/src/actions.ts +++ b/extensions/bluebubbles/src/actions.ts @@ -5,6 +5,7 @@ import { extractToolSend, jsonResult, readNumberParam, + readBooleanParam, readReactionParams, readStringParam, type ChannelMessageActionAdapter, @@ -52,23 +53,6 @@ function readMessageText(params: Record): string | undefined { return readStringParam(params, "text") ?? readStringParam(params, "message"); } -function readBooleanParam(params: Record, key: string): boolean | undefined { - const raw = params[key]; - if (typeof raw === "boolean") { - return raw; - } - if (typeof raw === "string") { - const trimmed = raw.trim().toLowerCase(); - if (trimmed === "true") { - return true; - } - if (trimmed === "false") { - return false; - } - } - return undefined; -} - /** Supported action names for BlueBubbles */ const SUPPORTED_ACTIONS = new Set(BLUEBUBBLES_ACTION_NAMES); const PRIVATE_API_ACTIONS = new Set([ diff --git a/src/infra/outbound/message-action-params.ts b/src/infra/outbound/message-action-params.ts index bdc1cdedc6a..037a7806f16 100644 --- a/src/infra/outbound/message-action-params.ts +++ b/src/infra/outbound/message-action-params.ts @@ -10,29 +10,12 @@ import type { import type { OpenClawConfig } from "../../config/config.js"; import { createRootScopedReadFile } from "../../infra/fs-safe.js"; import { extensionForMime } from "../../media/mime.js"; +import { readBooleanParam as readBooleanParamShared } from "../../plugin-sdk/boolean-param.js"; import { parseSlackTarget } from "../../slack/targets.js"; import { parseTelegramTarget } from "../../telegram/targets.js"; import { loadWebMedia } from "../../web/media.js"; -export function readBooleanParam( - params: Record, - key: string, -): boolean | undefined { - const raw = params[key]; - if (typeof raw === "boolean") { - return raw; - } - if (typeof raw === "string") { - const trimmed = raw.trim().toLowerCase(); - if (trimmed === "true") { - return true; - } - if (trimmed === "false") { - return false; - } - } - return undefined; -} +export const readBooleanParam = readBooleanParamShared; export function resolveSlackAutoThreadId(params: { to: string; diff --git a/src/plugin-sdk/boolean-param.ts b/src/plugin-sdk/boolean-param.ts new file mode 100644 index 00000000000..4616eaec3b8 --- /dev/null +++ b/src/plugin-sdk/boolean-param.ts @@ -0,0 +1,19 @@ +export function readBooleanParam( + params: Record, + key: string, +): boolean | undefined { + const raw = params[key]; + if (typeof raw === "boolean") { + return raw; + } + if (typeof raw === "string") { + const trimmed = raw.trim().toLowerCase(); + if (trimmed === "true") { + return true; + } + if (trimmed === "false") { + return false; + } + } + return undefined; +} diff --git a/src/plugin-sdk/index.ts b/src/plugin-sdk/index.ts index 8ee1467be3b..10a482d6d29 100644 --- a/src/plugin-sdk/index.ts +++ b/src/plugin-sdk/index.ts @@ -244,6 +244,7 @@ export { buildMediaPayload } from "../channels/plugins/media-payload.js"; export type { MediaPayload, MediaPayloadInput } from "../channels/plugins/media-payload.js"; export { createLoggerBackedRuntime } from "./runtime.js"; export { chunkTextForOutbound } from "./text-chunking.js"; +export { readBooleanParam } from "./boolean-param.js"; export { readJsonFileWithFallback, writeJsonFileAtomically } from "./json-store.js"; export { generatePkceVerifierChallenge, toFormUrlEncoded } from "./oauth-utils.js"; export { buildRandomTempFilePath, withTempDownloadPath } from "./temp-path.js";