mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
refactor: dedupe provider lowercase helpers
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
} from "openclaw/plugin-sdk/reply-payload";
|
||||
import { isPrivateNetworkOptInEnabled } from "openclaw/plugin-sdk/ssrf-runtime";
|
||||
import {
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeOptionalLowercaseString,
|
||||
normalizeOptionalString,
|
||||
} from "openclaw/plugin-sdk/text-runtime";
|
||||
@@ -319,7 +320,7 @@ function consumePendingOutboundMessageId(params: {
|
||||
}): PendingOutboundMessageId | null {
|
||||
prunePendingOutboundMessageIds();
|
||||
const bodyNorm = normalizeSnippet(params.body);
|
||||
const isMediaBody = params.body.trim().toLowerCase().startsWith("<media:");
|
||||
const isMediaBody = normalizeLowercaseStringOrEmpty(params.body).startsWith("<media:");
|
||||
|
||||
for (let i = 0; i < pendingOutboundMessageIds.length; i++) {
|
||||
const entry = pendingOutboundMessageIds[i];
|
||||
|
||||
@@ -3,6 +3,7 @@ import { type OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { makeProxyFetch } from "openclaw/plugin-sdk/infra-runtime";
|
||||
import { danger } from "openclaw/plugin-sdk/runtime-env";
|
||||
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
||||
import type { ResolvedDiscordAccount } from "./accounts.js";
|
||||
|
||||
export function resolveDiscordProxyUrl(
|
||||
@@ -71,7 +72,7 @@ export function validateDiscordProxyUrl(proxyUrl: string): string {
|
||||
}
|
||||
|
||||
function isLoopbackProxyHostname(hostname: string): boolean {
|
||||
const normalized = hostname.trim().toLowerCase();
|
||||
const normalized = normalizeLowercaseStringOrEmpty(hostname);
|
||||
if (!normalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
export const DEFAULT_DDG_SAFE_SEARCH = "moderate";
|
||||
|
||||
@@ -33,7 +34,7 @@ export function resolveDdgRegion(config?: OpenClawConfig): string | undefined {
|
||||
|
||||
export function resolveDdgSafeSearch(config?: OpenClawConfig): DdgSafeSearch {
|
||||
const safeSearch = resolveDdgWebSearchConfig(config)?.safeSearch;
|
||||
const normalized = typeof safeSearch === "string" ? safeSearch.trim().toLowerCase() : "";
|
||||
const normalized = normalizeLowercaseStringOrEmpty(safeSearch);
|
||||
if (normalized === "strict" || normalized === "off") {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ import {
|
||||
type SsrFPolicy,
|
||||
ssrfPolicyFromDangerouslyAllowPrivateNetwork,
|
||||
} from "openclaw/plugin-sdk/ssrf-runtime";
|
||||
import {
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeOptionalLowercaseString,
|
||||
} from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
const DEFAULT_FAL_BASE_URL = "https://fal.run";
|
||||
const DEFAULT_FAL_IMAGE_MODEL = "fal-ai/flux/dev";
|
||||
@@ -81,8 +85,8 @@ function mergeSsrFPolicies(...policies: Array<SsrFPolicy | undefined>): SsrFPoli
|
||||
}
|
||||
|
||||
function matchesTrustedHostSuffix(hostname: string, trustedSuffix: string): boolean {
|
||||
const normalizedHost = hostname.trim().toLowerCase();
|
||||
const normalizedSuffix = trustedSuffix.trim().toLowerCase();
|
||||
const normalizedHost = normalizeLowercaseStringOrEmpty(hostname);
|
||||
const normalizedSuffix = normalizeLowercaseStringOrEmpty(trustedSuffix);
|
||||
return normalizedHost === normalizedSuffix || normalizedHost.endsWith(`.${normalizedSuffix}`);
|
||||
}
|
||||
|
||||
@@ -97,7 +101,7 @@ function resolveFalNetworkPolicy(params: {
|
||||
return {};
|
||||
}
|
||||
|
||||
const hostSuffix = parsedBaseUrl.hostname.trim().toLowerCase();
|
||||
const hostSuffix = normalizeLowercaseStringOrEmpty(parsedBaseUrl.hostname);
|
||||
if (!hostSuffix || !params.allowPrivateNetwork) {
|
||||
return {};
|
||||
}
|
||||
@@ -241,7 +245,7 @@ function toDataUri(buffer: Buffer, mimeType: string): string {
|
||||
}
|
||||
|
||||
function fileExtensionForMimeType(mimeType: string | undefined): string {
|
||||
const normalized = mimeType?.toLowerCase().trim();
|
||||
const normalized = normalizeOptionalLowercaseString(mimeType);
|
||||
if (!normalized) {
|
||||
return "png";
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
type SsrFPolicy,
|
||||
ssrfPolicyFromDangerouslyAllowPrivateNetwork,
|
||||
} from "openclaw/plugin-sdk/ssrf-runtime";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
||||
import type {
|
||||
GeneratedVideoAsset,
|
||||
VideoGenerationProvider,
|
||||
@@ -107,7 +108,7 @@ function resolveFalQueueBaseUrl(baseUrl: string): string {
|
||||
}
|
||||
|
||||
function isFalMiniMaxLiveModel(model: string): boolean {
|
||||
return model.trim().toLowerCase() === DEFAULT_FAL_VIDEO_MODEL;
|
||||
return normalizeLowercaseStringOrEmpty(model) === DEFAULT_FAL_VIDEO_MODEL;
|
||||
}
|
||||
|
||||
function buildFalVideoRequestBody(params: {
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
type SecretInput,
|
||||
} from "openclaw/plugin-sdk/provider-auth";
|
||||
import type { ModelApi, ModelProviderConfig } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
export const PROVIDER_ID = "microsoft-foundry";
|
||||
export const DEFAULT_API = "openai-completions";
|
||||
@@ -111,7 +112,7 @@ type FoundryConfigShape = {
|
||||
};
|
||||
|
||||
export function normalizeFoundryModelName(value?: string | null): string | undefined {
|
||||
const trimmed = typeof value === "string" ? value.trim().toLowerCase() : "";
|
||||
const trimmed = normalizeLowercaseStringOrEmpty(value);
|
||||
return trimmed || undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
type WizardPrompter,
|
||||
} from "openclaw/plugin-sdk/setup-runtime";
|
||||
import { formatDocsLink } from "openclaw/plugin-sdk/setup-tools";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { applyAccountNameToChannelSection, patchScopedAccountConfig } from "../runtime-api.js";
|
||||
import { resolveDefaultNextcloudTalkAccountId, resolveNextcloudTalkAccount } from "./accounts.js";
|
||||
import type { CoreConfig } from "./types.js";
|
||||
@@ -124,14 +125,14 @@ async function promptNextcloudTalkAllowFrom(params: {
|
||||
parseEntries: (raw) => ({
|
||||
entries: String(raw)
|
||||
.split(/[\n,;]+/g)
|
||||
.map((value) => value.trim().toLowerCase())
|
||||
.map(normalizeLowercaseStringOrEmpty)
|
||||
.filter(Boolean),
|
||||
}),
|
||||
getExistingAllowFrom: ({ cfg, accountId }) =>
|
||||
resolveNextcloudTalkAccount({ cfg, accountId }).config.allowFrom ?? [],
|
||||
mergeEntries: ({ existing, parsed }) =>
|
||||
mergeAllowFromEntries(
|
||||
existing.map((value) => String(value).trim().toLowerCase()),
|
||||
existing.map((value) => normalizeLowercaseStringOrEmpty(String(value))),
|
||||
parsed,
|
||||
),
|
||||
applyAllowFrom: ({ cfg, accountId, allowFrom }) =>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
|
||||
import type {
|
||||
QaBusConversation,
|
||||
QaBusEvent,
|
||||
@@ -103,7 +104,7 @@ export function searchQaBusMessages(params: {
|
||||
}) {
|
||||
const accountId = normalizeAccountId(params.input.accountId);
|
||||
const limit = Math.max(1, Math.min(params.input.limit ?? 20, 100));
|
||||
const query = params.input.query?.trim().toLowerCase();
|
||||
const query = normalizeOptionalLowercaseString(params.input.query);
|
||||
return Array.from(params.messages.values())
|
||||
.filter((message) => message.accountId === accountId)
|
||||
.filter((message) =>
|
||||
|
||||
Reference in New Issue
Block a user