refactor: dedupe extension lower readers

This commit is contained in:
Peter Steinberger
2026-04-07 11:04:02 +01:00
parent 6bd6f4d27c
commit 967ecddfed
5 changed files with 15 additions and 6 deletions

View File

@@ -11,7 +11,7 @@ import { normalizeResolvedSecretInputString } from "./secret-input.js";
import type { CoreConfig, NextcloudTalkAccountConfig } from "./types.js";
function isTruthyEnvValue(value?: string): boolean {
const normalized = (value ?? "").trim().toLowerCase();
const normalized = normalizeOptionalString(value)?.toLowerCase() ?? "";
return normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on";
}

View File

@@ -1,5 +1,6 @@
import fs from "node:fs/promises";
import path from "node:path";
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
import {
definePluginEntry,
type OpenClawPluginApi,
@@ -259,7 +260,7 @@ function formatHelp(): string {
}
function parseGroup(raw: string | undefined): ArmGroup | null {
const value = (raw ?? "").trim().toLowerCase();
const value = normalizeOptionalString(raw)?.toLowerCase() ?? "";
if (!value) {
return null;
}

View File

@@ -327,7 +327,9 @@ export function resolveTtsConfig(cfg: OpenClawConfig): ResolvedTtsConfig {
mode: raw.mode ?? "final",
provider:
normalizeConfiguredSpeechProviderId(raw.provider) ??
(providerSource === "config" ? raw.provider?.trim().toLowerCase() || "" : ""),
(providerSource === "config"
? (normalizeOptionalString(raw.provider)?.toLowerCase() ?? "")
: ""),
providerSource,
summaryModel: normalizeOptionalString(raw.summaryModel),
modelOverrides: resolveModelOverridePolicy(raw.modelOverrides),

View File

@@ -1,6 +1,7 @@
import { resolveActiveTalkProviderConfig } from "openclaw/plugin-sdk/config-runtime";
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import type { SpeechVoiceOption } from "openclaw/plugin-sdk/speech";
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
import { definePluginEntry, type OpenClawPluginApi } from "./api.js";
function mask(s: string, keep: number = 6): string {
@@ -79,11 +80,15 @@ function findVoice(voices: SpeechVoiceOption[], query: string): SpeechVoiceOptio
if (byId) {
return byId;
}
const exactName = voices.find((v) => (v.name ?? "").trim().toLowerCase() === lower);
const exactName = voices.find(
(v) => (normalizeOptionalString(v.name)?.toLowerCase() ?? "") === lower,
);
if (exactName) {
return exactName;
}
const partial = voices.find((v) => (v.name ?? "").trim().toLowerCase().includes(lower));
const partial = voices.find((v) =>
(normalizeOptionalString(v.name)?.toLowerCase() ?? "").includes(lower),
);
return partial ?? null;
}

View File

@@ -1,5 +1,6 @@
import type { AssistantMessage } from "@mariozechner/pi-ai";
import type { OpenClawConfig } from "../../config/config.js";
import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js";
import { findNormalizedProviderValue } from "../model-selection.js";
import { extractAssistantText } from "../pi-embedded-utils.js";
import { coerceToolModelConfig, type ToolModelConfig } from "./model-config.helpers.js";
@@ -16,7 +17,7 @@ export function decodeDataUrl(dataUrl: string): {
if (!match) {
throw new Error("Invalid data URL (expected base64 data: URL).");
}
const mimeType = (match[1] ?? "").trim().toLowerCase();
const mimeType = normalizeLowercaseStringOrEmpty(match[1]);
if (!mimeType.startsWith("image/")) {
throw new Error(`Unsupported data URL type: ${mimeType || "unknown"}`);
}