openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.91 kB
JavaScript
import{o as resolveSessionStorePathForScope}from"./session-store-path-Co-EGagp.mjs";import{Y as captureGatewaySessionControllerWork}from"./session-controller.lifecycle-M3NLAkoz.mjs";import{r as isExactAttachedEnvironment}from"./placement-target-L09iynDq.mjs";import{t as DEVICE_WORKER_PROVIDER_ID}from"./device-provider-identity-0id_Gtsu.mjs";
//!src/gateway/worker-environments/device-placement-demand.ts
function captureDemand(e){const t=e.resolveGatewayContext();const n=captureGatewaySessionControllerWork(e.resolveGatewayContext);const r=/* @__PURE__ */ new Set;if(t)for(const e of n.targets.values())for(const t of e)r.add(t);return{admissions:n,targets:[...r],gatewayContext:t}}function projectDemand(e,t,n,r){const i=e.resolveGatewayContext()?.getRuntimeConfig();const a=/* @__PURE__ */ new Map;const o=/* @__PURE__ */ new Set;for(const[s,c]of t.targets)for(const l of c){const c=n.get(l);if(!c||s!==resolveSessionStorePathForScope(c,i)||c.sessionId===r||c.state!==`active`||c.executionMode!==`worker-turn`||o.has(c.environmentId)||!t.isActive({scope:s,sessionKey:c.sessionKey,sessionId:c.sessionId}))continue;const u=e.environments.get(c.environmentId);if(u?.providerId!==`device`||!u.nodeDeviceId||!isExactAttachedEnvironment(u,c))continue;o.add(u.environmentId);a.set(u.nodeDeviceId,(a.get(u.nodeDeviceId)??0)+1)}return a}function createDevicePlacementDemandReader(e){return t=>{const{admissions:n,targets:r}=captureDemand(e);return r.length?projectDemand(e,n,e.placements.getMany(r),t):/* @__PURE__ */ new Map}}function createDevicePlacementDemandReaderAsync(e){return async t=>{const{admissions:n,targets:r,gatewayContext:i}=captureDemand(e);if(!r.length)return/* @__PURE__ */ new Map;const a=await e.placements.getManyAsync(r);return e.resolveGatewayContext()===i?projectDemand(e,n,a,t):/* @__PURE__ */ new Map}}export{createDevicePlacementDemandReader,createDevicePlacementDemandReaderAsync};