UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

35 lines (34 loc) • 1.58 kB
import { isBigIntObject, isBooleanObject, isNumberObject, isStringObject } from "node:util/types"; //#region src/agents/auth-profiles/clone-value.ts /** Keep immutable credential strings in place while detaching their JSON containers. */ function cloneAuthProfileJsonValue(e) { const t = /* @__PURE__ */ new Set(); const clone = (e, n) => { let r = e; if (r !== null && (typeof r === "object" || typeof r === "bigint")) { const e = Reflect.get(Object(r), "toJSON"); if (typeof e === "function") r = Reflect.apply(e, r, [n]); } if (typeof r === "bigint" || typeof r === "function" || typeof r === "symbol") throw new TypeError(`AuthProfileStore contains non-JSON value: ${typeof r}`); if (isNumberObject(r)) r = Number(r); else if (isStringObject(r)) r = String(r); else if (isBooleanObject(r)) r = Boolean.prototype.valueOf.call(r); else if (isBigIntObject(r)) throw new TypeError("AuthProfileStore contains non-JSON value: bigint"); if (typeof r === "number") return Number.isFinite(r) ? r === 0 ? 0 : r : null; if (r === null || typeof r !== "object") return r; if (t.has(r)) throw new TypeError("AuthProfileStore contains a circular JSON value"); t.add(r); try { if (Array.isArray(r)) return Array.from({ length: r.length }, (e, t) => clone(r[t], `${t}`) ?? null); return Object.fromEntries(Object.keys(r).flatMap((e) => { const t = clone(Reflect.get(r, e), e); return t === void 0 ? [] : [[e, t]]; })); } finally { t.delete(r); } }; return clone(e, ""); } //#endregion export { cloneAuthProfileJsonValue as t };