openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 9.83 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Fi as t,Ft as n,It as r,Oa as i,Qt as a,Wi as o,Xt as s,au as c,dc as l,ka as u,lc as d,lo as f,vi as p,wa as m,xa as h}from"./control-ui-connection-Bfj9beF_.js";import{$ as g,F as _,I as v,U as y,_t as b,yt as x}from"./solid-runtime-C416s-HC.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 conversation.`,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}`,stopProcess:`Stop process`,stopping:`Stopping…`,stopNotRequested:`The process could not be stopped. Refresh to check its current state.`,expired:`This process is no longer retained. Return to the process list.`,omitted:`This process is not included in the current limited list. Return to Processes or refresh.`,disconnected:`Connect to the Gateway to view processes.`,output:`Recent output`,noOutput:`No output recorded 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(i.chat.processesPanel,S.chat.processesPanel)},{catalog:S})})))()}function T(e,t){if(e?.pendingRead)return!1;if(t?.hello&&!n(t,`sessions.processes.list`,`operator.read`))return!0;let r=e?.snapshot;return!!(r?.hasResult||r?.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(),r()})))()}var O,k,A,j,M;function N(){return(N=e((()=>{l(),h(),w(),a(),p(),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,n){this.context=e,this.input=t,this.changed=n,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:n})=>{if(!c(n))return;let r=t===`sessions.changed`&&[`delete`,`reset`,`sharing`,`profile-identity`,`placement`].includes(String(n.reason));t!==`sessions.processes.changed`&&!r||typeof n.sessionKey!=`string`&&!(r&&n.sessionKey===void 0)||n.agentId!==void 0&&typeof n.agentId!=`string`||!this.current(this.generation)||typeof n.sessionKey==`string`&&!o({assistantAgentId:this.input.agentId,agentsList:e.agents.state.agentsList,hello:e.gateway.snapshot.hello},this.input.sessionKey,n.sessionKey,n.agentId,this.input.agentId)||(this.pending?this.refreshAgain=!0:this.refresh())}),this.stopVisibility=this.visibilityDocument?f(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=t({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 t=this.scope;if(!t||!this.current(this.generation))return Promise.resolve();let n=this.generation,r=!1;this.refreshAgain=!1,this.clearTimer(),this.loading=!0;let i=t.client.request(`sessions.processes.list`,this.target()).then(e=>{if(!this.current(n))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(n)&&(r=e instanceof d&&e.gatewayCode===`FORBIDDEN`,r&&(this.rows=[],this.sessionId=null,this.actionError=null,this.actionInstanceId=null,this.stopping.clear(),this.hasResult=!1,this.truncated=!1),this.readError=s(e),this.readDenied=r)}).finally(()=>{this.pending===i&&(this.pending=null),this.current(n)&&(this.loading=!1,this.changed(),r||(this.refreshAgain?this.refresh():this.timer=setTimeout(()=>void this.refresh(),O)))});return this.pending=i,this.changed(),i}reportStopError(e,t){this.actionError=s(t),this.actionInstanceId=e.instanceId,this.changed()}async stop(e){let t=this.scope,n=this.sessionId,r=this.generation,i=this.rows.find(t=>t.processId===e.processId&&t.instanceId===e.instanceId);if(t&&n&&this.current(r)&&i?.canStop&&!this.stopping.has(e.instanceId)){this.stopping.add(e.instanceId),this.actionError=null,this.actionInstanceId=null,this.changed();try{let i=await t.client.request(`sessions.processes.stop`,{...this.target(),sessionId:n,processId:e.processId,instanceId:e.instanceId});if(!this.current(r))return;if(!i.requested){this.stopping.delete(e.instanceId),this.actionError=m(`chat.processesPanel.stopNotRequested`),this.actionInstanceId=e.instanceId,this.changed();return}await this.pending,this.current(r)&&await this.refresh()}catch(t){if(!this.current(r))return;this.stopping.delete(e.instanceId),this.actionError=s(t),this.actionInstanceId=e.instanceId;let n=t instanceof d&&t.gatewayCode===`FORBIDDEN`;n&&(this.rows=this.rows.map(e=>({...e,canStop:!1}))),this.changed(),n&&(await this.pending,this.current(r)&&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=null,this.readDenied=!1,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};