mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-11 07:56:11 +00:00
* refactor: consolidate string reader mechanics * fix: declare model catalog normalization dependency * fix: keep model catalog dependency-free * refactor(core): keep string readers internal
45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
import {
|
|
normalizeOptionalString,
|
|
readStringValue,
|
|
} from "@openclaw/normalization-core/string-coerce";
|
|
|
|
type StringOptions<T extends string> = readonly T[] | ReadonlySet<T>;
|
|
|
|
export function isStringOption<T extends string>(
|
|
value: unknown,
|
|
options: StringOptions<T>,
|
|
): value is T {
|
|
return (
|
|
typeof value === "string" &&
|
|
(Array.isArray(options)
|
|
? (options as readonly string[]).includes(value)
|
|
: (options as ReadonlySet<string>).has(value))
|
|
);
|
|
}
|
|
|
|
export function readStringAlias(
|
|
record: Readonly<Record<string, unknown>>,
|
|
keys: readonly string[],
|
|
): string | undefined {
|
|
for (const key of keys) {
|
|
const value = readStringValue(record[key]);
|
|
if (value !== undefined) {
|
|
return value;
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function readTrimmedStringAlias(
|
|
record: Readonly<Record<string, unknown>>,
|
|
keys: readonly string[],
|
|
): string | undefined {
|
|
for (const key of keys) {
|
|
const value = normalizeOptionalString(record[key]);
|
|
if (value !== undefined) {
|
|
return value;
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|