refactor: dedupe reply lowercase helpers

This commit is contained in:
Peter Steinberger
2026-04-07 10:21:32 +01:00
parent 434d56a948
commit 74ea9de6f2
14 changed files with 67 additions and 42 deletions

View File

@@ -3,7 +3,10 @@ import { getChannelPlugin } from "../../channels/plugins/index.js";
import type { ChannelId, ChannelThreadingToolContext } from "../../channels/plugins/types.js";
import { normalizeAnyChannelId, normalizeChannelId } from "../../channels/registry.js";
import type { OpenClawConfig } from "../../config/config.js";
import { normalizeOptionalString } from "../../shared/string-coerce.js";
import {
normalizeOptionalLowercaseString,
normalizeOptionalString,
} from "../../shared/string-coerce.js";
import { isReasoningTagProvider } from "../../utils/provider-utils.js";
import type { TemplateContext } from "../templating.js";
import {
@@ -39,7 +42,7 @@ export function buildThreadingToolContext(params: {
currentMessageId,
};
}
const rawProvider = normalizeOptionalString(originProvider)?.toLowerCase();
const rawProvider = normalizeOptionalLowercaseString(originProvider);
if (!rawProvider) {
return {
currentMessageId,

View File

@@ -14,7 +14,10 @@ import { formatErrorMessage } from "../../infra/errors.js";
import { generateSecureUuid } from "../../infra/secure-random.js";
import { prefixSystemMessage } from "../../infra/system-message.js";
import { resolveAgentIdFromSessionKey } from "../../routing/session-key.js";
import { normalizeOptionalString } from "../../shared/string-coerce.js";
import {
normalizeOptionalLowercaseString,
normalizeOptionalString,
} from "../../shared/string-coerce.js";
import { resolveStatusTtsSnapshot } from "../../tts/status-config.js";
import { resolveConfiguredTtsMode } from "../../tts/tts-config.js";
import type { FinalizedMsgContext } from "../templating.js";
@@ -113,23 +116,21 @@ async function hasBoundConversationForSession(params: {
channelRaw: string | undefined;
accountIdRaw: string | undefined;
}): Promise<boolean> {
const channel = normalizeOptionalString(params.channelRaw)?.toLowerCase() ?? "";
const channel = normalizeOptionalLowercaseString(params.channelRaw) ?? "";
if (!channel) {
return false;
}
const accountId = normalizeOptionalString(params.accountIdRaw)?.toLowerCase() ?? "";
const accountId = normalizeOptionalLowercaseString(params.accountIdRaw) ?? "";
const channels = params.cfg.channels as Record<string, { defaultAccount?: unknown } | undefined>;
const configuredDefaultAccountId = channels?.[channel]?.defaultAccount;
const normalizedAccountId =
accountId || normalizeOptionalString(configuredDefaultAccountId)?.toLowerCase() || "default";
accountId || normalizeOptionalLowercaseString(configuredDefaultAccountId) || "default";
const { getSessionBindingService } = await loadDispatchAcpManagerRuntime();
const bindingService = getSessionBindingService();
const bindings = bindingService.listBySession(params.sessionKey);
return bindings.some((binding) => {
const bindingChannel =
normalizeOptionalString(binding.conversation.channel)?.toLowerCase() ?? "";
const bindingAccountId =
normalizeOptionalString(binding.conversation.accountId)?.toLowerCase() ?? "";
const bindingChannel = normalizeOptionalLowercaseString(binding.conversation.channel) ?? "";
const bindingAccountId = normalizeOptionalLowercaseString(binding.conversation.accountId) ?? "";
const conversationId = normalizeOptionalString(binding.conversation.conversationId) ?? "";
return (
bindingChannel === channel &&

View File

@@ -4,7 +4,7 @@ import {
type ExecTarget,
normalizeExecTarget,
} from "../../../infra/exec-approvals.js";
import { normalizeOptionalString } from "../../../shared/string-coerce.js";
import { normalizeOptionalLowercaseString } from "../../../shared/string-coerce.js";
import { skipDirectiveArgPrefix, takeDirectiveToken } from "../directive-parsing.js";
type ExecDirectiveParse = {
@@ -26,7 +26,7 @@ type ExecDirectiveParse = {
};
function normalizeExecSecurity(value?: string): ExecSecurity | undefined {
const normalized = normalizeOptionalString(value)?.toLowerCase();
const normalized = normalizeOptionalLowercaseString(value);
if (normalized === "deny" || normalized === "allowlist" || normalized === "full") {
return normalized;
}
@@ -34,7 +34,7 @@ function normalizeExecSecurity(value?: string): ExecSecurity | undefined {
}
function normalizeExecAsk(value?: string): ExecAsk | undefined {
const normalized = normalizeOptionalString(value)?.toLowerCase();
const normalized = normalizeOptionalLowercaseString(value);
if (normalized === "off" || normalized === "on-miss" || normalized === "always") {
return normalized as ExecAsk;
}

View File

@@ -1,7 +1,10 @@
import type { OpenClawConfig } from "../../config/config.js";
import { resolveChannelGroupRequireMention } from "../../config/group-policy.js";
import type { GroupKeyResolution, SessionEntry } from "../../config/sessions.js";
import { normalizeOptionalString } from "../../shared/string-coerce.js";
import {
normalizeOptionalLowercaseString,
normalizeOptionalString,
} from "../../shared/string-coerce.js";
import { isInternalMessageChannel } from "../../utils/message-channel.js";
import { normalizeGroupActivation } from "../group-activation.js";
import type { TemplateContext } from "../templating.js";
@@ -15,7 +18,7 @@ function loadGroupsRuntime() {
}
async function resolveRuntimeChannelId(raw?: string | null): Promise<string | null> {
const normalized = normalizeOptionalString(raw)?.toLowerCase();
const normalized = normalizeOptionalLowercaseString(raw);
if (!normalized) {
return null;
}
@@ -80,7 +83,7 @@ export function defaultGroupActivation(requireMention: boolean): "always" | "men
}
function resolveProviderLabel(rawProvider: string | undefined): string {
const providerKey = normalizeOptionalString(rawProvider)?.toLowerCase() ?? "";
const providerKey = normalizeOptionalLowercaseString(rawProvider) ?? "";
if (!providerKey) {
return "chat";
}

View File

@@ -1,6 +1,6 @@
import { getChannelPlugin } from "../../../channels/plugins/index.js";
import type { InboundDebounceByProvider } from "../../../config/types.messages.js";
import { normalizeOptionalString } from "../../../shared/string-coerce.js";
import { normalizeOptionalLowercaseString } from "../../../shared/string-coerce.js";
import { normalizeQueueDropPolicy, normalizeQueueMode } from "./normalize.js";
import { DEFAULT_QUEUE_CAP, DEFAULT_QUEUE_DEBOUNCE_MS, DEFAULT_QUEUE_DROP } from "./state.js";
import type { QueueMode, QueueSettings, ResolveQueueSettingsParams } from "./types.js";
@@ -31,7 +31,7 @@ function resolvePluginDebounce(channelKey: string | undefined): number | undefin
}
export function resolveQueueSettings(params: ResolveQueueSettingsParams): QueueSettings {
const channelKey = normalizeOptionalString(params.channel)?.toLowerCase();
const channelKey = normalizeOptionalLowercaseString(params.channel);
const queueCfg = params.cfg.messages?.queue;
const providerModeRaw =
channelKey && queueCfg?.byChannel

View File

@@ -33,7 +33,10 @@ import { createSubsystemLogger } from "../../logging/subsystem.js";
import { getGlobalHookRunner } from "../../plugins/hook-runner-global.js";
import type { PluginHookSessionEndReason } from "../../plugins/types.js";
import { normalizeMainKey } from "../../routing/session-key.js";
import { normalizeOptionalString } from "../../shared/string-coerce.js";
import {
normalizeOptionalLowercaseString,
normalizeOptionalString,
} from "../../shared/string-coerce.js";
import { normalizeSessionDeliveryFields } from "../../utils/delivery-context.js";
import { isInternalMessageChannel } from "../../utils/message-channel.js";
import { resolveCommandAuthorization } from "../command-auth.js";
@@ -79,7 +82,7 @@ function resolveSessionDefaultAccountId(params: {
if (persisted) {
return persisted;
}
const channel = normalizeOptionalString(params.channelRaw)?.toLowerCase();
const channel = normalizeOptionalLowercaseString(params.channelRaw);
if (!channel) {
return undefined;
}