UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 4.46 kB
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{r as isDeeplyFrozenPlainData}from"./immutable-data-CyaF4H_G.mjs";import{t as runtimeConfigPublication}from"./runtime-config-publication-BbN_OEhM.mjs";import{n as normalizeAgentId}from"./agent-id-cOfqmfln.mjs";import{c as normalizeOptionalAgentId,n as LEGACY_IMPLICIT_AGENT_ID}from"./session-key-BPgKfU2m.mjs"; //!src/system-agent/agent-id.ts const SYSTEM_AGENT_ID=`openclaw`;const SYSTEM_AGENT_ROSTER_ENTRIES=[{id:SYSTEM_AGENT_ID,kind:`system`},{id:`crestodian`,kind:`system`}];const RESERVED_SYSTEM_AGENT_IDS=new Set(SYSTEM_AGENT_ROSTER_ENTRIES.map(e=>normalizeAgentId(e.id)));function isReservedSystemAgentId(e){return RESERVED_SYSTEM_AGENT_IDS.has(normalizeAgentId(e))} //!src/agents/agent-roster.ts let activeAgentRosterFactsBatch;const agentRosterFacts=/* @__PURE__ */ new WeakMap;function withAgentRosterFactsBatch(e,t){const n=activeAgentRosterFactsBatch;activeAgentRosterFactsBatch=n?.config===e?n:{config:e,facts:readAgentRosterFacts(e)??{}};try{return t()}finally{activeAgentRosterFactsBatch=n}}function readAgentRosterFacts(e){if(activeAgentRosterFactsBatch?.config===e)return activeAgentRosterFactsBatch.facts;const t=runtimeConfigPublication.current;const n=t?.config===e?t.revision:void 0;if(n===void 0&&!isDeeplyFrozenPlainData(e))return;let r=agentRosterFacts.get(e);if(!r||r.publication!==n){r={publication:n,facts:{}};agentRosterFacts.set(e,r)}return r.facts}function collectAgentEntries(e,t,n){const r=readAgentRosterProperty(e);if(r?.kind===`entries`&&isRecord(r.value)){const e=[];for(const i in r.value){if(!Object.hasOwn(r.value,i))continue;const a=r.value[i];if(isRecord(a)){const r={...a,id:i};e.push(t?{entry:r,source:{kind:`entries`,key:i}}:r);if(e.length===n)break}}return e}if(r?.kind!==`list`||!Array.isArray(r.value))return[];const i=[];r.value.some((e,t)=>{if(e!==null&&typeof e===`object`)i.push({entry:e,source:{kind:`list`,index:t}});return i.length===n});return t?i:i.map(({entry:e})=>e)}function listAgentEntriesWithSource(e){return collectAgentEntries(e,true)}function listAgentEntries(e){return collectAgentEntries(e,false)}function readAgentRosterProperty(e){if(!isRecord(e))return;const t=e.agents;if(!isRecord(t))return;for(const e of[`entries`,`list`]){const n=t[e];if(Object.hasOwn(t,e)&&n!==void 0)return{kind:e,value:n}}}function hasAgentRosterProperty(e){return readAgentRosterProperty(e)!==void 0}function listAgentIds(e){const t=readAgentRosterFacts(e);if(t?.agentIds)return t.agentIds;const n=listAgentEntries(e);const r=n.length===0&&!hasAgentRosterProperty(e)?[LEGACY_IMPLICIT_AGENT_ID]:[...new Set(n.map(e=>normalizeAgentId(e?.id)))];if(t){Object.freeze(r);t.agentIds=r}return r}function resolveConfiguredAcpHarnessIds(e){const t=/* @__PURE__ */ new Set;for(const n of listAgentEntries(e)){if(n.runtime?.type!==`acp`)continue;t.add(normalizeAgentId(n.id));const e=normalizeOptionalAgentId(n.runtime.acp?.agent);if(e)t.add(e)}const n=[e.acp?.defaultAgent,...(e.acp?.allowedAgents??[]).filter(e=>e.trim()!==`*`)];for(const e of n){const n=normalizeOptionalAgentId(e);if(n)t.add(n)}return t}function resolveConfiguredAcpSubagentTargetIds(e){return/* @__PURE__ */ new Set([...listAgentIds(e),...resolveConfiguredAcpHarnessIds(e)])}function listGatewayOwnedAgentIds(e){return[.../* @__PURE__ */ new Set([...listAgentIds(e),...SYSTEM_AGENT_ROSTER_ENTRIES.map(({id:e})=>e)])]}function tryResolveSoleAgentId(e){const t=collectAgentEntries(e,false,2);if(t.length===0){if(!hasAgentRosterProperty(e))return LEGACY_IMPLICIT_AGENT_ID;return}return t.length===1?normalizeAgentId(t[0].id):void 0}function tryResolveRawLegacyDefaultAgentId(e){if(e.agents?.ownership===`explicit`)return;const t=collectAgentEntries(e,false).filter(e=>e.default===true);return t.length===1?normalizeAgentId(t[0].id):void 0}function tryResolveDefaultAgentId(e){return tryResolveRawLegacyDefaultAgentId(e)??tryResolveSoleAgentId(e)}function tryResolveLegacyDataOwner(e){return tryResolveDefaultAgentId(e)}export{listGatewayOwnedAgentIds as a,resolveConfiguredAcpHarnessIds as c,tryResolveLegacyDataOwner as d,tryResolveRawLegacyDefaultAgentId as f,isReservedSystemAgentId as g,SYSTEM_AGENT_ID as h,listAgentIds as i,resolveConfiguredAcpSubagentTargetIds as l,withAgentRosterFactsBatch as m,listAgentEntries as n,readAgentRosterFacts as o,tryResolveSoleAgentId as p,listAgentEntriesWithSource as r,readAgentRosterProperty as s,hasAgentRosterProperty as t,tryResolveDefaultAgentId as u};