UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

52 lines (51 loc) • 2.29 kB
import { o as resolveSessionStorePathForScope } from "./session-store-path-BIJyO4vM.mjs"; import { J as captureGatewaySessionControllerWork } from "./session-controller.lifecycle-C_Z3sybN.mjs"; import { r as isExactAttachedEnvironment } from "./placement-target-pO1cgncb.mjs"; import { t as DEVICE_WORKER_PROVIDER_ID } from "./device-provider-identity-v6nXqNq_.mjs"; //#region 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; } /** Projects admitted session work without turning idle placements into slot reservations. */ 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(); }; } //#endregion export { createDevicePlacementDemandReader, createDevicePlacementDemandReaderAsync };