UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

70 lines (69 loc) • 3.4 kB
import { Gr as validateComputerInvokeParams, Kr as validateComputerStatusParams } from "./src-BX8OAe1J.mjs"; import { t as ErrorCodes } from "./gateway-error-details-B69XiHdh.mjs"; import { p as errorShape } from "./error-codes-BzF7aRQ0.mjs"; import { t as hasCurrentPersonalGatewaySource } from "./gateway-personal-caller-_qqOw6oy.mjs"; import { r as respondUnavailableOnThrow } from "./response-C7fEiIN1.mjs"; import { t as assertValidParams } from "./validation-DwNk6A-B.mjs"; import { t as computerRunOwner } from "./computer-owner-C12-KMGp.mjs"; //#region src/gateway/server-methods/computer.ts function resolveComputerCaller(e, t) { const { client: n, context: r, hasCurrentClientAuthority: i, sessionMutationCommitGuard: a } = e; const o = n?.internal?.agentRuntimeIdentity; const s = n?.internal?.remoteIngressPrincipal; const c = t === "status" && n?.internal?.syntheticClient === true; if (!n || !n.connId && !s && !c || n.internal?.syntheticClient && !o && !c) throw new Error("Gateway computer requires an authenticated operator or admitted agent run"); const l = n.connId; const u = [e.signal, n.connectionSignal].filter((e) => e !== void 0); const d = u.length > 0 ? AbortSignal.any(u) : void 0; return { owner: o ? computerRunOwner(o.delegatedAuthority) : s ? JSON.stringify(["ingress", s.bindingId]) : JSON.stringify([c ? "discovery" : "operator", l]), signal: d, ...!o && !n.internal?.syntheticClient && n.connectionSignal ? { ownerSignal: s?.signal ?? n.connectionSignal } : {}, assertCurrent: () => { a?.(); d?.throwIfAborted(); if (n.invalidated || i?.() === false) throw new Error("Gateway computer requester authority is no longer current"); if (s && !hasCurrentPersonalGatewaySource(n, r)) throw new Error("Gateway computer requester grant is no longer current"); if (o && t === "invoke") { if (r.validateAgentRuntimeApprovalAuthority?.(o) !== true) throw new Error("Gateway computer agent run authority is no longer current"); n.internal?.agentToolCaller?.assertCurrent?.(); } else if (!n.internal?.syntheticClient && l && r.isConnectionActive?.(l) === false) throw new Error("Gateway computer requester connection is no longer active"); } }; } const computerHandlers = { "computer.status": async (e) => { const { params: t, respond: n, context: r } = e; if (!assertValidParams(t, validateComputerStatusParams, "computer.status", n)) return; await respondUnavailableOnThrow(n, async () => { const i = resolveComputerCaller(e, "status"); i.assertCurrent(); const a = r.gatewayComputerService ? await r.gatewayComputerService.status(t) : { available: false, configured: false }; i.assertCurrent(); n(true, a); }); }, "computer.invoke": async (e) => { const { params: t, respond: n, context: r } = e; if (!assertValidParams(t, validateComputerInvokeParams, "computer.invoke", n)) return; const i = r.gatewayComputerService; if (!i) { n(false, void 0, errorShape(ErrorCodes.UNAVAILABLE, "Gateway computer is unavailable")); return; } await respondUnavailableOnThrow(n, async () => { const r = resolveComputerCaller(e, t.command === "computer.act" && t.params.action === "__close_execution" ? "close" : "invoke"); r.assertCurrent(); const a = await i.invoke({ ...t, ...r }); n(true, { payload: a }); }); } }; //#endregion export { computerHandlers };