UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.18 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Ho as t,It as n,Pi as r,Pt as i,Qt as a,Xt as o,in as s,ln as c,ss as l,vi as u,wa as d,xa as f,zs as p}from"./control-ui-connection-Bfj9beF_.js";import{XO as m,bD as h,dk as g,nk as _,uk as v,vD as y}from"./control-ui-boot-shared-DFTSUQQ0.js";import{n as b,t as x}from"./en-agent-creation-Cv8MHRu_.js";import{r as S,t as C}from"./creation-recovery.runtime-DAE8W5Ma.js";async function w(e,t){if(!i(e.gateway.snapshot,`agents.create`,`operator.admin`)){h({message:d(`agentChip.creationUnavailable`),durationMs:12e3});return}let n=e.gateway.snapshot.client,a=e.gateway.connection.gatewayUrl,s=e.router.getState().location,u=l(s.pathname,e.basePath),f=s,m=e.agentSelection.intentRevision,v={sessionKey:``,admitted:!1},y=()=>{},b=!1,x=()=>e.router.getState().location===f&&e.agentSelection.intentRevision===m,S=()=>{v.sessionKey&&x()&&u&&e.replace(u,s)};try{let i=t?.name.trim()||d(`agentChip.newAgent`),o=await e.agents.create(i,t=>{v.sessionKey=p({agentId:t,mainKey:r({agentsList:e.agents.state.agentsList,hello:e.gateway.snapshot.hello})});let a=_({context:e,face:`chat`,sessionKey:v.sessionKey,agentId:t,preferenceDerivedFace:!0,exactKey:!0});y=e.chatSubmissions.beginCreate({creation:v,message:null,displayName:i,canDisplay:()=>e.gateway.snapshot.client===n&&e.router.getState().location.pathname===a.options.pathname}),e.navigate(`chat`,a.options),f=e.router.getState().location},t?.avatar?{avatar:t.avatar}:void 0);if(!o||e.gateway.snapshot.client!==n||!n){e.gateway.snapshot.client===n&&S();return}b=!0;let{agentId:s,onboarding:l}=o,u=l.sessionKey;v.admitted=!0;let m=x();if(c({gatewayUrl:a,sidebarRecentlyCreatedAgentId:s,...m?{sidebarAgentsMode:`chip`}:{}},{selectGateway:!1}),m&&g({selection:e.agentSelection,gateway:e.gateway,sessionKey:u,agentId:s}),l.status===`error`)throw Error(l.error)}catch(t){if(e.gateway.snapshot.client!==n)return;b||S(),h({message:t instanceof C?t.message:d(b?`agentChip.chatStartFailed`:`agentChip.creationFailed`,{error:o(t)}),durationMs:12e3})}finally{y()}}function T(){return(T=e((()=>{t(),f(),x(),S(),a(),n(),m(),u(),y(),v(),s(),b()})))()}T();export{w as createApplicationAgent};