UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 9.82 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{El as t,Ju as n,Ol as r,Qo as i,Wo as a,X as o,Z as s,hs as c,li as l,mi as u,oi as d,pi as f,ws as p}from"./_4____________________________.js";import{AN as m,EN as h}from"./_2_____________________________.js";import{$ as g,F as _,I as v,U as y,_t as b,yt as x}from"./_6____________________.js";var S,C;function w(){return(w=e((()=>{u(),S={chat:{processesPanel:{back:`Back to processes`,backToDetails:`Back to details`,running:`Running ({count})`,finished:`Finished ({count})`,runningDesktop:`Running {count}`,finishedDesktop:`Finished {count}`,empty:`No background processes in this session yet.`,viewAll:`View all processes`,openOutput:`Open output`,cannotStop:`Can’t be stopped`,runningFor:`Running for`,emptyTitle:`No processes`,noOutputTitle:`No output yet`,noRunning:`No running processes`,stop:`Stop {name}`,stopping:`Stopping…`,stopNotRequested:`Couldn’t stop the process. Refresh to check its current state.`,expired:`This process is no longer retained. Return to the process list.`,omitted:`This process isn’t in the current list. Return to processes or refresh.`,disconnected:`Reconnect to view processes.`,output:`Recent output`,noOutput:`No output yet.`,exitCode:`Exit {code}`,retention:`Process output is retained temporarily. Viewing it does not consume the agent’s output.`,outputTruncated:`Earlier output is omitted from this retained tail.`,listTruncated:`Only a bounded process list is shown; running processes take priority.`,status:{running:`Running`,completed:`Completed`,failed:`Failed`,killed:`Stopped`}}}},C=Object.assign(()=>{Object.assign(f.chat.processesPanel,S.chat.processesPanel)},{catalog:S})})))()}function T(e,t){if(e?.pendingRead)return!1;if(t?.hello&&!o(t,`sessions.processes.list`,`operator.read`))return!0;let n=e?.snapshot;return!!(n?.hasResult||n?.errorKind)}function E(e,t=!1){let n=_(()=>({completion:e()?.pendingRead??null}),{equals:(e,t)=>e.completion===t.completion}),r=_(()=>{let t=e();return t?{owner:t,retired:t.retired,connectionRetired:t.connectionRetired}:void 0},{equals:(e,t)=>e?.owner===t?.owner&&e?.retired===t?.retired&&e?.connectionRetired===t?.connectionRetired}),i=t=>{let n=e();return t.owner===n&&t.retired===n?.retired&&t.connectionRetired===n?.connectionRetired},a=_(()=>{let e=r(),a=n().completion;return e?.connectionRetired?Promise.race([a??Promise.resolve(),e.retired,e.connectionRetired]).then(()=>{let n=e.owner.snapshot;if(i(e)&&n.readError&&(!t||!n.rows.length))throw Error(n.readError)}):Promise.resolve()});function o(t){let n=_(()=>{let e=r();if(!e?.connectionRetired)return;let[t,n]=v(!1);return{...e,saving:t,setSaving:n}}),o=x(function*(e,t,n){i(e)&&(e.setSaving(!0),g(a)),yield Promise.race([t,n]),i(e)&&(yield b(a))});return{stopping:()=>!!n()?.saving()||!!e()?.snapshot.stopping.has(t().instanceId),async stop(){let e=n(),r=t();if(!e||!i(e))return;let a=Promise.race([e.retired,e.connectionRetired]),s=e.owner.stop(r);await Promise.resolve();try{await o(e,s,a)}catch(t){i(e)&&!e.owner.snapshot.readError&&e.owner.reportStopError(r,t)}}}}return{read:a,scope:r,createStop:o}}function D(){return(D=e((()=>{y(),s()})))()}var O,k,A,j,M;function N(){return(N=e((()=>{r(),d(),w(),m(),i(),C(),O=6e4,k={rows:[],loading:!1,hasResult:!1,truncated:!1,error:null,readError:null,errorKind:null,stopping:new Set},A=new WeakMap,j=class{constructor(e,t){this.context=e,this.changed=t,this.entry=null,this.key=null,this.lifetime=Promise.withResolvers();let n=A.get(e.sessions);n||(n=new Map,A.set(e.sessions,n)),this.entries=n}get snapshot(){return this.entry?.data??k}get pendingRead(){return this.entry?.data.pendingRead??null}get retired(){return this.lifetime.promise}get connectionRetired(){return this.entry?.data.retired}sync(e){let t=e.presented&&e.sessionKey?JSON.stringify([e.agentId,e.sessionKey]):null;if(t!==this.key){if(this.dispose(),t!==null){let n=this.entries.get(t);if(!n){let r=new Set;n={data:new M(this.context,e,()=>{r.forEach(e=>e())}),listeners:r},this.entries.set(t,n)}this.key=t,this.entry=n,n.listeners.add(this.changed)}this.changed()}}refresh(){return this.entry?.data.refresh(!0)??Promise.resolve()}stop(e){return this.entry?.data.stop(e)??Promise.resolve()}reportStopError(e,t){this.entry?.data.reportStopError(e,t)}dispose(){this.lifetime.resolve(),this.lifetime=Promise.withResolvers(),this.entry&&(this.entry.listeners.delete(this.changed),this.entry.listeners.size===0&&(this.entry.data.dispose(),this.entries.delete(this.key))),this.entry=null,this.key=null}},M=class{get error(){return this.readDenied?this.readError:this.actionError??this.readError}get errorKind(){return this.readDenied?`access`:this.actionError?`action`:this.readError?`read`:null}get pendingRead(){return this.pending}get retired(){return this.scope?this.lifetime.promise:void 0}constructor(e,t,r){this.context=e,this.input=t,this.changed=r,this.rows=[],this.loading=!1,this.hasResult=!1,this.truncated=!1,this.readError=null,this.readDenied=!1,this.actionError=null,this.actionInstanceId=null,this.stopping=new Set,this.sessionId=null,this.scope=null,this.generation=0,this.disposed=!1,this.pending=null,this.lifetime=Promise.withResolvers(),this.refreshAgain=!1,this.timer=null,this.visibilityDocument=globalThis.document,this.visibilityChanged=()=>this.reconcile(),this.unsubscribe=e.gateway.subscribe(()=>this.reconcile()),this.unsubscribeEvents=e.gateway.subscribeEvents(({event:t,payload:r})=>{if(!n(r))return;let i=t===`sessions.changed`&&[`delete`,`reset`,`sharing`,`profile-identity`,`placement`].includes(String(r.reason));t!==`sessions.processes.changed`&&!i||typeof r.sessionKey!=`string`&&!(i&&r.sessionKey===void 0)||r.agentId!==void 0&&typeof r.agentId!=`string`||!this.current(this.generation)||typeof r.sessionKey==`string`&&!p({assistantAgentId:this.input.agentId,agentsList:e.agents.state.agentsList,hello:e.gateway.snapshot.hello},this.input.sessionKey,r.sessionKey,r.agentId,this.input.agentId)||(this.pending?this.refreshAgain=!0:this.refresh())}),this.stopVisibility=this.visibilityDocument?a(this.visibilityDocument,`visibilitychange`,this.visibilityChanged):void 0,this.reconcile()}reconcile(){if(this.disposed)return;let e=this.visibilityDocument?.visibilityState===`hidden`?null:this.context.sessions.captureConnectionScope();e?(this.scope&&!this.context.sessions.isConnectionScopeCurrent(this.scope)&&this.retire(),this.scope||(this.scope=e,this.refresh())):(this.retire(),this.changed())}target(){let e=c({assistantAgentId:this.input.agentId,agentsList:this.context.agents.state.agentsList,hello:this.context.gateway.snapshot.hello},this.input.sessionKey,this.input.agentId);return{key:e.sessionKey,agentId:e.agentId}}refresh(e=!1){if(e&&(this.actionError=null,this.actionInstanceId=null,this.changed()),this.pending)return this.pending;let n=this.scope;if(!n||!this.current(this.generation))return Promise.resolve();let r=this.generation,i=!1;this.refreshAgain=!1,this.clearTimer(),this.loading=!0;let a=n.client.request(`sessions.processes.list`,this.target()).then(e=>{if(!this.current(r))return;this.readError=null,this.readDenied=!1,this.sessionId=e.sessionId,this.rows=e.processes,this.truncated=e.truncated,this.hasResult=!0;let t=this.rows.find(e=>e.instanceId===this.actionInstanceId);this.actionError&&(t?t.status!==`running`:!e.truncated)&&(this.actionError=null,this.actionInstanceId=null);for(let e of this.stopping)this.rows.some(t=>t.instanceId===e&&t.status===`running`)||this.stopping.delete(e)}).catch(e=>{this.current(r)&&(i=e instanceof t&&e.gatewayCode===`FORBIDDEN`,i&&(this.rows=[],this.sessionId=null,this.actionError=null,this.actionInstanceId=null,this.stopping.clear(),this.hasResult=!1,this.truncated=!1),this.readError=h(e),this.readDenied||=i)}).finally(()=>{this.pending===a&&(this.pending=null),this.current(r)&&(this.loading=!1,this.changed(),i||(this.refreshAgain?this.refresh():this.timer=setTimeout(()=>void this.refresh(),O)))});return this.pending=a,this.changed(),a}reportStopError(e,t){this.actionError=h(t),this.actionInstanceId=e.instanceId,this.changed()}async stop(e){let n=this.scope,r=this.sessionId,i=this.generation,a=this.rows.find(t=>t.processId===e.processId&&t.instanceId===e.instanceId);if(n&&r&&this.current(i)&&a?.canStop&&!this.stopping.has(e.instanceId)){this.stopping.add(e.instanceId),this.actionError=null,this.actionInstanceId=null,this.changed();try{let t=await n.client.request(`sessions.processes.stop`,{...this.target(),sessionId:r,processId:e.processId,instanceId:e.instanceId});if(!this.current(i))return;if(!t.requested){this.stopping.delete(e.instanceId),this.actionError=l(`chat.processesPanel.stopNotRequested`),this.actionInstanceId=e.instanceId,this.changed();return}await this.pending,this.current(i)&&await this.refresh()}catch(n){if(!this.current(i))return;this.stopping.delete(e.instanceId),this.actionError=h(n),this.actionInstanceId=e.instanceId;let r=n instanceof t&&n.gatewayCode===`FORBIDDEN`;r&&(this.rows=this.rows.map(e=>({...e,canStop:!1}))),this.changed(),r&&(await this.pending,this.current(i)&&await this.refresh())}}}current(e){return!this.disposed&&e===this.generation&&!!(this.scope&&this.context.sessions.isConnectionScopeCurrent(this.scope))}clearTimer(){this.timer!==null&&clearTimeout(this.timer),this.timer=null}retire(){this.lifetime.resolve(),this.lifetime=Promise.withResolvers(),this.generation+=1,this.clearTimer(),this.scope=null,this.pending=null,this.refreshAgain=!1,this.rows=[],this.sessionId=null,this.stopping.clear(),this.loading=!1,this.hasResult=!1,this.truncated=!1,this.readError=this.readDenied?this.readError:null,this.actionError=null,this.actionInstanceId=null}dispose(){this.disposed=!0,this.retire(),this.unsubscribe(),this.unsubscribeEvents(),this.stopVisibility?.()}}})))()}export{T as a,D as i,N as n,w as o,E as r,C as s,j as t};