mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
refactor(plugin-sdk): share boolean action param parsing
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
extractToolSend,
|
extractToolSend,
|
||||||
jsonResult,
|
jsonResult,
|
||||||
readNumberParam,
|
readNumberParam,
|
||||||
|
readBooleanParam,
|
||||||
readReactionParams,
|
readReactionParams,
|
||||||
readStringParam,
|
readStringParam,
|
||||||
type ChannelMessageActionAdapter,
|
type ChannelMessageActionAdapter,
|
||||||
@@ -52,23 +53,6 @@ function readMessageText(params: Record<string, unknown>): string | undefined {
|
|||||||
return readStringParam(params, "text") ?? readStringParam(params, "message");
|
return readStringParam(params, "text") ?? readStringParam(params, "message");
|
||||||
}
|
}
|
||||||
|
|
||||||
function readBooleanParam(params: Record<string, unknown>, 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 */
|
/** Supported action names for BlueBubbles */
|
||||||
const SUPPORTED_ACTIONS = new Set<ChannelMessageActionName>(BLUEBUBBLES_ACTION_NAMES);
|
const SUPPORTED_ACTIONS = new Set<ChannelMessageActionName>(BLUEBUBBLES_ACTION_NAMES);
|
||||||
const PRIVATE_API_ACTIONS = new Set<ChannelMessageActionName>([
|
const PRIVATE_API_ACTIONS = new Set<ChannelMessageActionName>([
|
||||||
|
|||||||
@@ -10,29 +10,12 @@ import type {
|
|||||||
import type { OpenClawConfig } from "../../config/config.js";
|
import type { OpenClawConfig } from "../../config/config.js";
|
||||||
import { createRootScopedReadFile } from "../../infra/fs-safe.js";
|
import { createRootScopedReadFile } from "../../infra/fs-safe.js";
|
||||||
import { extensionForMime } from "../../media/mime.js";
|
import { extensionForMime } from "../../media/mime.js";
|
||||||
|
import { readBooleanParam as readBooleanParamShared } from "../../plugin-sdk/boolean-param.js";
|
||||||
import { parseSlackTarget } from "../../slack/targets.js";
|
import { parseSlackTarget } from "../../slack/targets.js";
|
||||||
import { parseTelegramTarget } from "../../telegram/targets.js";
|
import { parseTelegramTarget } from "../../telegram/targets.js";
|
||||||
import { loadWebMedia } from "../../web/media.js";
|
import { loadWebMedia } from "../../web/media.js";
|
||||||
|
|
||||||
export function readBooleanParam(
|
export const readBooleanParam = readBooleanParamShared;
|
||||||
params: Record<string, unknown>,
|
|
||||||
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 function resolveSlackAutoThreadId(params: {
|
export function resolveSlackAutoThreadId(params: {
|
||||||
to: string;
|
to: string;
|
||||||
|
|||||||
19
src/plugin-sdk/boolean-param.ts
Normal file
19
src/plugin-sdk/boolean-param.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
export function readBooleanParam(
|
||||||
|
params: Record<string, unknown>,
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -244,6 +244,7 @@ export { buildMediaPayload } from "../channels/plugins/media-payload.js";
|
|||||||
export type { MediaPayload, MediaPayloadInput } from "../channels/plugins/media-payload.js";
|
export type { MediaPayload, MediaPayloadInput } from "../channels/plugins/media-payload.js";
|
||||||
export { createLoggerBackedRuntime } from "./runtime.js";
|
export { createLoggerBackedRuntime } from "./runtime.js";
|
||||||
export { chunkTextForOutbound } from "./text-chunking.js";
|
export { chunkTextForOutbound } from "./text-chunking.js";
|
||||||
|
export { readBooleanParam } from "./boolean-param.js";
|
||||||
export { readJsonFileWithFallback, writeJsonFileAtomically } from "./json-store.js";
|
export { readJsonFileWithFallback, writeJsonFileAtomically } from "./json-store.js";
|
||||||
export { generatePkceVerifierChallenge, toFormUrlEncoded } from "./oauth-utils.js";
|
export { generatePkceVerifierChallenge, toFormUrlEncoded } from "./oauth-utils.js";
|
||||||
export { buildRandomTempFilePath, withTempDownloadPath } from "./temp-path.js";
|
export { buildRandomTempFilePath, withTempDownloadPath } from "./temp-path.js";
|
||||||
|
|||||||
Reference in New Issue
Block a user