UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

53 lines (52 loc) • 2.59 kB
import { a as validateDecisionResult, i as validateDecisionBatch, n as validateDecisionResultV2, o as finiteJson, r as DecisionContractError, t as validateDecisionBatchV2 } from "./validation-v2-60LJzO-m.mjs"; //#region src/decisions/compatibility.ts /** Malformed input throws; unsupported size or unrepresentable data returns undefined. */ function decisionBatchV1ToV2(e) { if (finiteJson(e, { rejectProxies: true }) === "invalid") throw new DecisionContractError(); if (!validateDecisionBatch(e)) return; const t = { state: typeof e.state === "string" ? { type: "text", text: e.state } : { type: "json", value: e.state }, questions: e.questions }; return validateDecisionBatchV2(t) ? t : void 0; } /** Never sends native-only inputs to V1, or changes explicit JSON strings into text. */ function decisionBatchV2ToV1(e) { if (!validateDecisionBatchV2(e)) return; if (e.state.type !== "text" && e.state.type !== "json") return; if (Object.values(e.questions).some((e) => e.type === "sort" || e.type === "tags" || e.type === "box")) return; const t = e.state.type === "text" ? e.state.text : e.state.value; if (e.state.type === "json" && t !== null && typeof t !== "object") return; const n = { state: t, questions: e.questions }; return validateDecisionBatch(n) ? n : void 0; } /** Preserve provider estimates and labels verbatim; never threshold or take an argmax. */ function decisionResultV1ToV2(e, t) { const n = decisionBatchV1ToV2(e); if (!n || finiteJson(t, { rejectProxies: true }) !== "valid" || !validateDecisionResult(e, t)) return; return validateDecisionResultV2(n, t) ? t : void 0; } /** Narrow only losslessly: V1 cannot carry explicit decisions, errors, or extra usage/metadata. */ function decisionResultV2ToV1(e, t) { const n = decisionBatchV2ToV1(e); if (!n || !validateDecisionResultV2(e, t) || t.metadata !== void 0) return; if (t.usage !== void 0 && Object.keys(t.usage).some((e) => e !== "inputTokens" && e !== "outputTokens")) return; for (const e of Object.values(t.answers)) { if (e.type === "error" || e.type === "sort" || e.type === "tags" || e.type === "box" || e.metadata !== void 0) return; if (e.type === "boolean") { if (e.answer !== void 0) return; } else if (e.confidence === null || e.type === "choice" && (e.choice === null || e.probability !== void 0) || e.type === "score" && e.probabilities === void 0) return; } return validateDecisionResult(n, t) ? t : void 0; } //#endregion export { decisionResultV2ToV1 as i, decisionBatchV2ToV1 as n, decisionResultV1ToV2 as r, decisionBatchV1ToV2 as t };