mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-25 23:47:20 +00:00
refactor: dedupe trim reader aliases
This commit is contained in:
@@ -91,10 +91,6 @@ export function _setComfyFetchGuardForTesting(impl: typeof fetchWithSsrFGuard |
|
||||
comfyFetchGuard = impl ?? fetchWithSsrFGuard;
|
||||
}
|
||||
|
||||
function readConfigString(config: ComfyProviderConfig, key: string): string | undefined {
|
||||
return normalizeOptionalString(config[key]);
|
||||
}
|
||||
|
||||
function readConfigBoolean(config: ComfyProviderConfig, key: string): boolean | undefined {
|
||||
const value = config[key];
|
||||
return typeof value === "boolean" ? value : undefined;
|
||||
@@ -554,9 +550,9 @@ export function isComfyCapabilityConfigured(params: {
|
||||
const capabilityConfig = getComfyCapabilityConfig(config, params.capability);
|
||||
const hasWorkflow = Boolean(
|
||||
resolveComfyWorkflowSource(capabilityConfig).workflow ||
|
||||
readConfigString(capabilityConfig, "workflowPath"),
|
||||
normalizeOptionalString(capabilityConfig.workflowPath),
|
||||
);
|
||||
const hasPromptNode = Boolean(readConfigString(capabilityConfig, "promptNodeId"));
|
||||
const hasPromptNode = Boolean(normalizeOptionalString(capabilityConfig.promptNodeId));
|
||||
if (!hasWorkflow || !hasPromptNode) {
|
||||
return false;
|
||||
}
|
||||
@@ -586,11 +582,11 @@ export async function runComfyWorkflow(params: {
|
||||
const workflow = await loadComfyWorkflow(capabilityConfig);
|
||||
const promptNodeId = getRequiredConfigString(capabilityConfig, "promptNodeId");
|
||||
const promptInputName =
|
||||
readConfigString(capabilityConfig, "promptInputName") ?? DEFAULT_PROMPT_INPUT_NAME;
|
||||
const inputImageNodeId = readConfigString(capabilityConfig, "inputImageNodeId");
|
||||
normalizeOptionalString(capabilityConfig.promptInputName) ?? DEFAULT_PROMPT_INPUT_NAME;
|
||||
const inputImageNodeId = normalizeOptionalString(capabilityConfig.inputImageNodeId);
|
||||
const inputImageInputName =
|
||||
readConfigString(capabilityConfig, "inputImageInputName") ?? DEFAULT_INPUT_IMAGE_INPUT_NAME;
|
||||
const outputNodeId = readConfigString(capabilityConfig, "outputNodeId");
|
||||
normalizeOptionalString(capabilityConfig.inputImageInputName) ?? DEFAULT_INPUT_IMAGE_INPUT_NAME;
|
||||
const outputNodeId = normalizeOptionalString(capabilityConfig.outputNodeId);
|
||||
const pollIntervalMs =
|
||||
readConfigInteger(capabilityConfig, "pollIntervalMs") ?? DEFAULT_POLL_INTERVAL_MS;
|
||||
const timeoutMs =
|
||||
@@ -619,7 +615,7 @@ export async function runComfyWorkflow(params: {
|
||||
|
||||
const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } =
|
||||
resolveProviderHttpRequestConfig({
|
||||
baseUrl: readConfigString(capabilityConfig, "baseUrl"),
|
||||
baseUrl: normalizeOptionalString(capabilityConfig.baseUrl),
|
||||
defaultBaseUrl:
|
||||
mode === "cloud" ? DEFAULT_COMFY_CLOUD_BASE_URL : DEFAULT_COMFY_LOCAL_BASE_URL,
|
||||
allowPrivateNetwork:
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
createComputedAccountStatusAdapter,
|
||||
createDefaultChannelRuntimeState,
|
||||
} from "openclaw/plugin-sdk/status-helpers";
|
||||
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { mattermostApprovalAuth } from "./approval-auth.js";
|
||||
import {
|
||||
chunkTextForOutbound,
|
||||
@@ -242,25 +243,18 @@ const mattermostMessageActions: ChannelMessageActionAdapter = {
|
||||
},
|
||||
};
|
||||
|
||||
function readTrimmedString(value: unknown): string | undefined {
|
||||
if (typeof value !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed || undefined;
|
||||
}
|
||||
|
||||
function parseMattermostReactActionParams(params: Record<string, unknown>): {
|
||||
postId: string;
|
||||
emojiName: string;
|
||||
remove: boolean;
|
||||
} {
|
||||
const postId = readTrimmedString(params.messageId) ?? readTrimmedString(params.postId);
|
||||
const postId =
|
||||
normalizeOptionalString(params.messageId) ?? normalizeOptionalString(params.postId);
|
||||
if (!postId) {
|
||||
throw new Error("Mattermost react requires messageId (post id)");
|
||||
}
|
||||
|
||||
const emojiName = readTrimmedString(params.emoji)?.replace(/^:+|:+$/g, "");
|
||||
const emojiName = normalizeOptionalString(params.emoji)?.replace(/^:+|:+$/g, "");
|
||||
if (!emojiName) {
|
||||
throw new Error("Mattermost react requires emoji");
|
||||
}
|
||||
@@ -273,7 +267,7 @@ function parseMattermostReactActionParams(params: Record<string, unknown>): {
|
||||
}
|
||||
|
||||
function readMattermostReplyToId(params: Record<string, unknown>): string | undefined {
|
||||
return readTrimmedString(params.replyToId) ?? readTrimmedString(params.replyTo);
|
||||
return normalizeOptionalString(params.replyToId) ?? normalizeOptionalString(params.replyTo);
|
||||
}
|
||||
|
||||
export const mattermostPlugin: ChannelPlugin<ResolvedMattermostAccount> = createChatChannelPlugin({
|
||||
|
||||
Reference in New Issue
Block a user