refactor: dedupe trim string helpers

This commit is contained in:
Peter Steinberger
2026-04-07 09:17:29 +01:00
parent 8119915664
commit 365d5a410b
6 changed files with 18 additions and 34 deletions

View File

@@ -1,5 +1,6 @@
import { normalizeChatChannelId } from "../channels/ids.js";
import type { OpenClawConfig } from "../config/config.js";
import { normalizeOptionalString } from "../shared/string-coerce.js";
import { defaultSlotIdForKey } from "./slots.js";
export type NormalizedPluginsConfig = {
@@ -41,10 +42,7 @@ function normalizeList(value: unknown, normalizePluginId: NormalizePluginId): st
}
function normalizeSlotValue(value: unknown): string | null | undefined {
if (typeof value !== "string") {
return undefined;
}
const trimmed = value.trim();
const trimmed = normalizeOptionalString(value);
if (!trimmed) {
return undefined;
}
@@ -97,8 +95,8 @@ function normalizePluginEntries(
),
allowedModels: Array.isArray((subagentRaw as { allowedModels?: unknown }).allowedModels)
? ((subagentRaw as { allowedModels?: unknown }).allowedModels as unknown[])
.map((model) => (typeof model === "string" ? model.trim() : ""))
.filter(Boolean)
.map((model) => normalizeOptionalString(model))
.filter((model): model is string => Boolean(model))
: undefined,
}
: undefined;