mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-15 23:24:03 -06:00
refactor: consolidate coercion contracts (#122458)
* refactor: consolidate coercion contracts Centralize exact string, record, numeric, date, Boolean, argument, and structured-error coercions while preserving call-site semantics. Migrate canonical-name collisions and deprecated internal SDK bypasses, deleting 55 net production/tooling lines. Expand declaration ownership enforcement to 101 allowed helpers and add a narrow export-completeness audit. * fix: preserve standalone script coercions Keep copied Control UI tooling self-contained and retain the trusted release harness module-relative source seam when the harness runs against an old target cwd.
This commit is contained in:
committed by
GitHub
parent
66fe424590
commit
b080dd1e76
@@ -1,3 +1,4 @@
|
||||
import { asFiniteNumber } from "@openclaw/normalization-core/number-coercion";
|
||||
import { normalizeNullableString } from "@openclaw/normalization-core/string-coerce";
|
||||
import type { ContextEngineHostSupport } from "./host-compat.js";
|
||||
import type {
|
||||
@@ -25,10 +26,6 @@ const RUNTIME_REASON_PATTERNS: Array<[ContextEngineRuntimeReasonCode, RegExp]> =
|
||||
["provider_unavailable", /provider|primary|unavailable/iu],
|
||||
];
|
||||
|
||||
function normalizeNullableNumber(value: number | null | undefined): number | null {
|
||||
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
||||
}
|
||||
|
||||
function normalizeReasonCode(value: OptionalString): ContextEngineRuntimeReasonCode | null {
|
||||
const normalized = normalizeNullableString(value);
|
||||
if (!normalized) {
|
||||
@@ -95,8 +92,8 @@ export function buildContextEngineRuntimeSettings(params: {
|
||||
label: normalizeNullableString(params.contextEngineHost.label),
|
||||
},
|
||||
limits: {
|
||||
promptTokenBudget: normalizeNullableNumber(params.promptTokenBudget),
|
||||
maxOutputTokens: normalizeNullableNumber(params.maxOutputTokens),
|
||||
promptTokenBudget: asFiniteNumber(params.promptTokenBudget) ?? null,
|
||||
maxOutputTokens: asFiniteNumber(params.maxOutputTokens) ?? null,
|
||||
},
|
||||
diagnostics: {
|
||||
fallbackReason,
|
||||
|
||||
Reference in New Issue
Block a user