UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

49 lines (48 loc) • 2.1 kB
import { t as GATEWAY_OWNER_PROFILE_ID } from "./user-profile-constants-Bj3FwpfE.mjs"; //#region src/infra/active-node-context.ts let activeNodeContexts = /* @__PURE__ */ new Map(); function personProfileId(e) { return e === "gateway-owner" ? void 0 : e; } function getActiveNodeIdentityScope(e) { return personProfileId(e) ? "requester" : "unknown"; } /** Replaces the Gateway's prepared choices; no profile can inherit another person's node. */ function setActiveNodeContexts(e) { activeNodeContexts = new Map(e.map((e) => [personProfileId(e.profileId), { ...e }])); } /** Refresh the keyed pairing fact at the existing asynchronous prompt preparation boundary. */ async function prepareActiveNodeContext(e) { const t = personProfileId(e); const n = activeNodeContexts.get(t); try { await n?.prepare?.(); } catch { if (activeNodeContexts.get(t) === n) activeNodeContexts.delete(t); } } /** Revalidates the published node before projecting it into an agent prompt. */ function getCurrentActiveNodeContext(e) { const t = activeNodeContexts.get(personProfileId(e)); if (!t) return null; try { if (t.isCurrent && !t.isCurrent()) return null; } catch { return null; } return { nodeId: t.nodeId, ...t.pairingGeneration ? { pairingGeneration: t.pairingGeneration } : {} }; } /** Bounds the authenticated id; explicit unknown clears stale hints without injecting labels. */ function formatActiveNodeContextLabel(e) { const t = e?.nodeId; return t && /^[a-zA-Z0-9._:-]{1,128}$/.test(t) ? t : "unknown"; } /** Stable turn context; explicit unknown supersedes a warm runtime's earlier device hint. */ function buildActiveNodeContextText(e) { return `Current active computer (latest reported app/system input, not message origin): active_node=${formatActiveNodeContextLabel(getCurrentActiveNodeContext(e))} active_node_identity=${getActiveNodeIdentityScope(e)}`; } //#endregion export { prepareActiveNodeContext as a, getCurrentActiveNodeContext as i, formatActiveNodeContextLabel as n, setActiveNodeContexts as o, getActiveNodeIdentityScope as r, buildActiveNodeContextText as t };