UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

53 lines (52 loc) • 1.95 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { i as asOptionalObjectRecord, r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs"; //#region src/node-host/invoke-payload.ts const MAX_INVOKE_INPUT_BYTES = 16384; function decodeNodeInvokeParams(e) { if (!e) throw new Error("INVALID_REQUEST: paramsJSON required"); try { return JSON.parse(e); } catch { throw new Error("INVALID_REQUEST: paramsJSON malformed JSON"); } } function coerceNodeInvokePayload(e) { const t = asOptionalObjectRecord(e); if (!t) return null; const n = normalizeOptionalString(t.id); const r = normalizeOptionalString(t.nodeId); const i = normalizeOptionalString(t.command); if (!n || !r || !i) return null; const a = typeof t.paramsJSON === "string" ? t.paramsJSON : t.params !== void 0 ? JSON.stringify(t.params) : null; const o = typeof t.timeoutMs === "number" ? t.timeoutMs : null; const s = typeof t.idempotencyKey === "string" ? t.idempotencyKey : null; const c = normalizeOptionalString(t.sessionKey); return { id: n, nodeId: r, command: i, paramsJSON: a, timeoutMs: o, idempotencyKey: s, ...c ? { sessionKey: c } : {} }; } function coerceNodeInvokeCancelPayload(e) { const t = asNullableRecord(e); return t && typeof t.invokeId === "string" && typeof t.nodeId === "string" ? { invokeId: t.invokeId, nodeId: t.nodeId } : null; } function coerceNodeInvokeInputPayload(e) { const t = asNullableRecord(e); if (!t || typeof t.id !== "string" || typeof t.nodeId !== "string" || !Number.isInteger(t.seq) || t.seq < 0 || typeof t.payloadJSON !== "string" || Buffer.byteLength(t.payloadJSON, "utf8") > MAX_INVOKE_INPUT_BYTES) return null; return { invokeId: t.id, nodeId: t.nodeId, seq: t.seq, payloadJSON: t.payloadJSON }; } //#endregion export { decodeNodeInvokeParams as i, coerceNodeInvokeInputPayload as n, coerceNodeInvokePayload as r, coerceNodeInvokeCancelPayload as t };