mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-02 18:40:22 +00:00
refactor: dedupe lowercase string helpers
This commit is contained in:
@@ -428,10 +428,10 @@ function buildArtifactContext(
|
||||
}
|
||||
|
||||
const artifactContext = {
|
||||
agentId: normalizeContextString(context.agentId),
|
||||
sessionId: normalizeContextString(context.sessionId),
|
||||
messageChannel: normalizeContextString(context.messageChannel),
|
||||
agentAccountId: normalizeContextString(context.agentAccountId),
|
||||
agentId: normalizeOptionalString(context.agentId),
|
||||
sessionId: normalizeOptionalString(context.sessionId),
|
||||
messageChannel: normalizeOptionalString(context.messageChannel),
|
||||
agentAccountId: normalizeOptionalString(context.agentAccountId),
|
||||
};
|
||||
|
||||
return Object.values(artifactContext).some((value) => value !== undefined)
|
||||
@@ -439,11 +439,6 @@ function buildArtifactContext(
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function normalizeContextString(value: string | undefined): string | undefined {
|
||||
const normalized = normalizeOptionalString(value);
|
||||
return normalized ? normalized : undefined;
|
||||
}
|
||||
|
||||
function normalizeDiffInput(params: DiffsToolParams): DiffInput {
|
||||
const patch = params.patch?.trim();
|
||||
const before = params.before;
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
deliverTextOrMediaReply,
|
||||
resolveSendableOutboundReplyParts,
|
||||
} from "openclaw/plugin-sdk/reply-payload";
|
||||
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
|
||||
import type { OpenClawConfig } from "../runtime-api.js";
|
||||
import {
|
||||
createChannelReplyPipeline,
|
||||
@@ -73,7 +73,7 @@ export function registerGoogleChatWebhookTarget(target: WebhookTarget): () => vo
|
||||
}
|
||||
|
||||
function normalizeAudienceType(value?: string | null): GoogleChatAudienceType | undefined {
|
||||
const normalized = normalizeOptionalString(value)?.toLowerCase();
|
||||
const normalized = normalizeOptionalLowercaseString(value);
|
||||
if (normalized === "app-url" || normalized === "app_url" || normalized === "app") {
|
||||
return "app-url";
|
||||
}
|
||||
|
||||
@@ -114,11 +114,6 @@ const STATUS_REACTION_EMOJI_KEYS: StatusReactionEmojiKey[] = [
|
||||
"compacting",
|
||||
];
|
||||
|
||||
function normalizeEmoji(value: string | undefined): string | undefined {
|
||||
const trimmed = normalizeOptionalString(value);
|
||||
return trimmed ? trimmed : undefined;
|
||||
}
|
||||
|
||||
function toUniqueNonEmpty(values: string[]): string[] {
|
||||
return Array.from(new Set(values.map((value) => value.trim()).filter(Boolean)));
|
||||
}
|
||||
@@ -128,18 +123,18 @@ export function resolveTelegramStatusReactionEmojis(params: {
|
||||
overrides?: StatusReactionEmojis;
|
||||
}): Required<StatusReactionEmojis> {
|
||||
const { overrides } = params;
|
||||
const queuedFallback = normalizeEmoji(params.initialEmoji) ?? DEFAULT_EMOJIS.queued;
|
||||
const queuedFallback = normalizeOptionalString(params.initialEmoji) ?? DEFAULT_EMOJIS.queued;
|
||||
return {
|
||||
queued: normalizeEmoji(overrides?.queued) ?? queuedFallback,
|
||||
thinking: normalizeEmoji(overrides?.thinking) ?? DEFAULT_EMOJIS.thinking,
|
||||
tool: normalizeEmoji(overrides?.tool) ?? DEFAULT_EMOJIS.tool,
|
||||
coding: normalizeEmoji(overrides?.coding) ?? DEFAULT_EMOJIS.coding,
|
||||
web: normalizeEmoji(overrides?.web) ?? DEFAULT_EMOJIS.web,
|
||||
done: normalizeEmoji(overrides?.done) ?? DEFAULT_EMOJIS.done,
|
||||
error: normalizeEmoji(overrides?.error) ?? DEFAULT_EMOJIS.error,
|
||||
stallSoft: normalizeEmoji(overrides?.stallSoft) ?? DEFAULT_EMOJIS.stallSoft,
|
||||
stallHard: normalizeEmoji(overrides?.stallHard) ?? DEFAULT_EMOJIS.stallHard,
|
||||
compacting: normalizeEmoji(overrides?.compacting) ?? DEFAULT_EMOJIS.compacting,
|
||||
queued: normalizeOptionalString(overrides?.queued) ?? queuedFallback,
|
||||
thinking: normalizeOptionalString(overrides?.thinking) ?? DEFAULT_EMOJIS.thinking,
|
||||
tool: normalizeOptionalString(overrides?.tool) ?? DEFAULT_EMOJIS.tool,
|
||||
coding: normalizeOptionalString(overrides?.coding) ?? DEFAULT_EMOJIS.coding,
|
||||
web: normalizeOptionalString(overrides?.web) ?? DEFAULT_EMOJIS.web,
|
||||
done: normalizeOptionalString(overrides?.done) ?? DEFAULT_EMOJIS.done,
|
||||
error: normalizeOptionalString(overrides?.error) ?? DEFAULT_EMOJIS.error,
|
||||
stallSoft: normalizeOptionalString(overrides?.stallSoft) ?? DEFAULT_EMOJIS.stallSoft,
|
||||
stallHard: normalizeOptionalString(overrides?.stallHard) ?? DEFAULT_EMOJIS.stallHard,
|
||||
compacting: normalizeOptionalString(overrides?.compacting) ?? DEFAULT_EMOJIS.compacting,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -148,7 +143,7 @@ export function buildTelegramStatusReactionVariants(
|
||||
): Map<string, string[]> {
|
||||
const variantsByRequested = new Map<string, string[]>();
|
||||
for (const key of STATUS_REACTION_EMOJI_KEYS) {
|
||||
const requested = normalizeEmoji(emojis[key]);
|
||||
const requested = normalizeOptionalString(emojis[key]);
|
||||
if (!requested) {
|
||||
continue;
|
||||
}
|
||||
@@ -225,7 +220,7 @@ export function resolveTelegramReactionVariant(params: {
|
||||
variantsByRequestedEmoji: Map<string, string[]>;
|
||||
allowedEmojiReactions?: Set<TelegramReactionEmoji> | null;
|
||||
}): TelegramReactionEmoji | undefined {
|
||||
const requestedEmoji = normalizeEmoji(params.requestedEmoji);
|
||||
const requestedEmoji = normalizeOptionalString(params.requestedEmoji);
|
||||
if (!requestedEmoji) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user