refactor: dedupe lower-parser readers

This commit is contained in:
Peter Steinberger
2026-04-07 08:23:51 +01:00
parent b3e6822ef8
commit 2197ce62bd
9 changed files with 22 additions and 16 deletions

View File

@@ -8,7 +8,7 @@ import {
streamWithPayloadPatch,
} from "openclaw/plugin-sdk/provider-stream-shared";
import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env";
import { readStringValue } from "openclaw/plugin-sdk/text-runtime";
import { normalizeOptionalString, readStringValue } from "openclaw/plugin-sdk/text-runtime";
const log = createSubsystemLogger("anthropic-stream");
@@ -83,7 +83,7 @@ function normalizeAnthropicServiceTier(value: unknown): AnthropicServiceTier | u
if (typeof value !== "string") {
return undefined;
}
const normalized = value.trim().toLowerCase();
const normalized = normalizeOptionalString(value)?.toLowerCase();
if (normalized === "auto" || normalized === "standard_only") {
return normalized;
}

View File

@@ -2,6 +2,7 @@ import {
getChannelStreamingConfigObject,
resolveChannelStreamingNativeTransport,
} from "openclaw/plugin-sdk/channel-streaming";
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
export type StreamingMode = "off" | "partial" | "block" | "progress";
export type SlackLegacyDraftStreamMode = "replace" | "status_final" | "append";
@@ -10,7 +11,7 @@ function normalizeStreamingMode(value: unknown): string | null {
if (typeof value !== "string") {
return null;
}
const normalized = value.trim().toLowerCase();
const normalized = normalizeOptionalString(value)?.toLowerCase();
return normalized || null;
}

View File

@@ -1,4 +1,5 @@
import type { SessionId } from "@agentclientprotocol/sdk";
import { normalizeOptionalString } from "../shared/string-coerce.js";
import { VERSION } from "../version.js";
export const ACP_PROVENANCE_MODE_VALUES = ["off", "meta", "meta+receipt"] as const;
@@ -8,10 +9,10 @@ export type AcpProvenanceMode = (typeof ACP_PROVENANCE_MODE_VALUES)[number];
export function normalizeAcpProvenanceMode(
value: string | undefined,
): AcpProvenanceMode | undefined {
if (!value) {
const normalized = normalizeOptionalString(value)?.toLowerCase();
if (!normalized) {
return undefined;
}
const normalized = value.trim().toLowerCase();
return (ACP_PROVENANCE_MODE_VALUES as readonly string[]).includes(normalized)
? (normalized as AcpProvenanceMode)
: undefined;

View File

@@ -70,7 +70,7 @@ function normalizeOpenAIServiceTier(value: unknown): OpenAIServiceTier | undefin
if (typeof value !== "string") {
return undefined;
}
const normalized = value.trim().toLowerCase();
const normalized = readStringValue(value)?.toLowerCase();
if (
normalized === "auto" ||
normalized === "default" ||
@@ -98,7 +98,7 @@ function normalizeOpenAITextVerbosity(value: unknown): OpenAITextVerbosity | und
if (typeof value !== "string") {
return undefined;
}
const normalized = value.trim().toLowerCase();
const normalized = readStringValue(value)?.toLowerCase();
if (normalized === "low" || normalized === "medium" || normalized === "high") {
return normalized;
}

View File

@@ -1,4 +1,5 @@
import { spawn } from "node:child_process";
import { normalizeOptionalString } from "../shared/string-coerce.js";
import { formatErrorMessage } from "./errors.js";
import { triggerOpenClawRestart } from "./restart.js";
import { detectRespawnSupervisor } from "./supervisor-markers.js";
@@ -12,10 +13,7 @@ export type GatewayRespawnResult = {
};
function isTruthy(value: string | undefined): boolean {
if (!value) {
return false;
}
const normalized = value.trim().toLowerCase();
const normalized = normalizeOptionalString(value)?.toLowerCase();
return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
}

View File

@@ -1,3 +1,5 @@
import { normalizeOptionalString } from "../shared/string-coerce.js";
export type UpdateChannel = "stable" | "beta" | "dev";
export type UpdateChannelSource = "config" | "git-tag" | "git-branch" | "default";
@@ -6,10 +8,10 @@ export const DEFAULT_GIT_CHANNEL: UpdateChannel = "dev";
export const DEV_BRANCH = "main";
export function normalizeUpdateChannel(value?: string | null): UpdateChannel | null {
if (!value) {
const normalized = normalizeOptionalString(value)?.toLowerCase();
if (!normalized) {
return null;
}
const normalized = value.trim().toLowerCase();
if (normalized === "stable" || normalized === "beta" || normalized === "dev") {
return normalized;
}

View File

@@ -7,6 +7,7 @@ import type {
SlackChannelStreamingConfig,
TextChunkMode,
} from "../config/types.base.js";
import { normalizeOptionalString } from "../shared/string-coerce.js";
export type {
ChannelDeliveryStreamingConfig,
@@ -47,7 +48,7 @@ function normalizeStreamingMode(value: unknown): string | null {
if (typeof value !== "string") {
return null;
}
const normalized = value.trim().toLowerCase();
const normalized = normalizeOptionalString(value)?.toLowerCase();
return normalized || null;
}

View File

@@ -1,4 +1,5 @@
import type { TtsAutoMode } from "../config/types.tts.js";
import { normalizeOptionalString } from "../shared/string-coerce.js";
export const TTS_AUTO_MODES = new Set<TtsAutoMode>(["off", "always", "inbound", "tagged"]);
@@ -6,7 +7,7 @@ export function normalizeTtsAutoMode(value: unknown): TtsAutoMode | undefined {
if (typeof value !== "string") {
return undefined;
}
const normalized = value.trim().toLowerCase();
const normalized = normalizeOptionalString(value)?.toLowerCase();
if (TTS_AUTO_MODES.has(normalized as TtsAutoMode)) {
return normalized as TtsAutoMode;
}

View File

@@ -1,3 +1,5 @@
import { normalizeOptionalString } from "../shared/string-coerce.js";
export type BooleanParseOptions = {
truthy?: string[];
falsy?: string[];
@@ -18,7 +20,7 @@ export function parseBooleanValue(
if (typeof value !== "string") {
return undefined;
}
const normalized = value.trim().toLowerCase();
const normalized = normalizeOptionalString(value)?.toLowerCase();
if (!normalized) {
return undefined;
}