openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 4.38 kB
JavaScript
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{t as stableStringify}from"./stable-stringify-Cy0VZ0ci.mjs";import{o as getGatewayToolCallerIdentity}from"./gateway-caller-context-Dw9IijqV.mjs";import{f as COMPUTER_USE_V1_ACTION_NAMES,p as COMPUTER_USE_V2_ACTION_NAMES,r as parseComputerUseCapabilityDescriptor}from"./computer-use-contract-CaYMDN7U.mjs";import{s as shouldUseInProcessGatewayTool,t as callGatewayTool}from"./gateway-Bf9f0Pcc.mjs";import{t as createAgentRuntimeIdentity}from"./agent-runtime-identity-token-DO1DKFFX.mjs";import{i as SCREEN_SNAPSHOT_COMMAND,t as COMPUTER_ACT_COMMAND}from"./computer-tool-shared-CEBWlIuY.mjs";import{n as listNodes}from"./nodes-utils-Bgm8PZ2e.mjs";
//!src/agents/tools/computer-tool-gateway.ts
async function loadGatewayComputerStatus(e,t,n=false){const r=await callGatewayTool(`computer.status`,e,{probe:n},{signal:t});if(!isRecord(r)||typeof r.configured!==`boolean`)throw new Error(`COMPUTER_CONTRACT_MISMATCH: invalid Gateway computer status`);if(!r.configured)return{configured:false,available:false};if(r.available!==true)return{configured:true,available:false,...r.computerUse?{computerUse:parseComputerUseCapabilityDescriptor(r.computerUse)}:{},...typeof r.error===`string`?{error:r.error}:{}};return{configured:true,available:true,computerUse:parseComputerUseCapabilityDescriptor(r.computerUse)}}async function bindGatewayComputerCleanup(e){const t=getGatewayToolCallerIdentity();if(!shouldUseInProcessGatewayTool(e.options)||!t?.operationalRunInstance)return;const n=await createAgentRuntimeIdentity({...t,operationalRunInstance:t.operationalRunInstance});if(!n)throw new Error(`Gateway computer cleanup requires the admitted run identity`);const{bindAgentToolGatewayRequest:r,runWithGatewayToolCleanupContext:i,withAgentToolGatewayRuntimeIdentity:a}=await import(`./in-process-gateway-DxSLSn2a.mjs`);const o=i(()=>r({resolveGatewayContext:t.gatewayContextResolver}),t.gatewayContextResolver);return async t=>{return(await o(a({method:`computer.invoke`,params:{generation:e.generation,command:`computer.act`,params:{action:`__close_execution`,executionId:e.executionId,reason:t},idempotencyKey:`computer.close:${e.executionId}:gateway`},timeoutMs:e.options.timeoutMs},n))).payload}}
//!src/agents/computer-use-node-capabilities.ts
async function readLocalComputerNodes(e){if(!e)throw new Error(`Gateway context is no longer available`);const{readKnownNodeCatalog:t}=await import(`./node-catalog-read-B7LCjpuz.mjs`);return(await t(e.nodeRegistry)).nodes}async function readLocalComputerStatus(e){if(!e)throw new Error(`Gateway context is no longer available`);const t=await e.gatewayComputerService?.status({probe:false});if(!t?.configured)return{configured:false,available:false};return t.available&&t.computerUse?{configured:true,available:true,computerUse:t.computerUse}:{configured:true,available:false,computerUse:t.computerUse,error:t.error}}async function loadPairedComputerUseAvailabilityForSurface(e){if(!e.computerAllowed||e.modelHasVision===false||e.embeddedMode===true||e.computerTransport!==void 0)return;const{signal:t}=e;const n=shouldUseInProcessGatewayTool({});const r=n?getGatewayToolCallerIdentity()?.gatewayContextResolver?.():void 0;const[i,a]=await Promise.all([(n?readLocalComputerNodes(r):listNodes({},t)).catch(()=>{t?.throwIfAborted();return[]}),(n?readLocalComputerStatus(r):loadGatewayComputerStatus({},t)).catch(e=>{t?.throwIfAborted();return{configured:true,available:false,error:e instanceof Error?e.message:`Gateway computer discovery failed`}})]);t?.throwIfAborted();const o=i.filter(isEligibleComputerNode);const s=stableStringify({gateway:a,nodes:o.sort((e,t)=>e.nodeId.localeCompare(t.nodeId)).map(({nodeId:e,computerUse:t})=>({nodeId:e,computerUse:t}))});const c=[...o.map(e=>e.computerUse),...a.configured&&a.computerUse?[a.computerUse]:[]];const l=new Set(c.flatMap(e=>e?.actions??COMPUTER_USE_V1_ACTION_NAMES));return{cacheKey:s,prepared:{actions:COMPUTER_USE_V2_ACTION_NAMES.filter(e=>l.has(e)),gateway:a,guidanceCapabilities:c.length===1?c[0]:void 0}}}function isEligibleComputerNode(e){const t=Array.isArray(e.commands)?e.commands:[];return e.connected===true&&t.includes(`computer.act`)&&t.includes(`screen.snapshot`)}export{loadGatewayComputerStatus as i,loadPairedComputerUseAvailabilityForSurface as n,bindGatewayComputerCleanup as r,isEligibleComputerNode as t};