UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 11 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Hi as t,Qt as n,Xt as r,in as i,ln as a,sn as o,vi as s,wa as c,wi as l,xa as u}from"./control-ui-connection-Bfj9beF_.js";import{Mf as d,bD as f,ch as p,jf as m,lh as ee,nD as h,sh as g,tD as _,vD as v}from"./control-ui-boot-shared-DFTSUQQ0.js";import{gr as y,mr as b}from"./deferred-ui-support-D-VedBtc.js";import{vt as te,yt as ne}from"./control-ui-boot-new-BsNYv3zK.js";import{n as re,t as ie}from"./en-session-organization-D0fXDuFy.js";import{r as ae,t as oe}from"./input-dialog-V5Go5DXN.js";import{a as se,i as ce,n as le,o as x,r as S,t as C}from"./session-workspace-recovery.runtime-ONPZ4H21.js";import{a as w,c as T,d as E,f as D,i as O,l as k,n as A,p as j,r as M,s as N,t as P,u as F}from"./session-organizer-archive.runtime-XUifPv-F.js";import{n as I,r as L,t as R}from"./worktree-preservation-D3o1Fypf.js";import{n as z,t as B}from"./cloud-worker-stop.runtime-DpL9jcws.js";async function V(e,t,n){let r=e.knownSessionGroups();return r.includes(t)?`completed`:G(e,n,`sessions.groups.put`,()=>n.sessions.groupsPut([...r,t]))}async function H(e,t,n,r){return await G(e,r,`sessions.groups.rename`,()=>r.sessions.groupsRename(t,n))===`completed`}async function U(e,t,n){if(!e.sessionData.isSessionMutationScopeCurrent(n)||!D(e,n,{method:`sessions.groups.delete`,requiredScope:`operator.write`}))return!1;let r=await y({title:c(`sessionsView.deleteGroupTitle`,{group:t}),message:c(`sessionsView.deleteGroupConfirm`),confirmLabel:c(`common.delete`),danger:!0,signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n))return f({message:c(`sessionsView.deleteGroupStale`,{group:t})}),!1;if(!r)return!1;try{return await n.sessions.groupsDelete(t)===`completed`&&e.sessionData.isSessionMutationScopeCurrent(n)}catch(t){return e.sessionData.publishSessionMutationError(n,t),!1}}function W(e,t,n,r){return G(e,r,`sessions.groups.update`,()=>r.sessions.groupsUpdate(t,n))}async function G(e,t,n,r){if(!e.sessionData.isSessionMutationScopeCurrent(t))return`stale`;if(!D(e,t,{method:n,requiredScope:`operator.write`}))return`failed`;try{return await r()===`completed`&&e.sessionData.isSessionMutationScopeCurrent(t)?`completed`:`stale`}catch(n){return e.sessionData.isSessionMutationScopeCurrent(t)?(e.sessionData.publishSessionMutationError(t,n),`failed`):`stale`}}async function ue(e,t,n,r,i,a){if(e.sessionData.isSessionMutationScopeCurrent(i)&&D(e,i,{method:`sessions.groups.put`,requiredScope:`operator.write`}))try{let o=e.knownSessionGroups(),s=e.knownSessionCatalogIds(),c=p(ee(e.knownSectionOrder(),o,s),t,n,r),l=c.flatMap(e=>e.startsWith(`category:`)?[e.slice(9)]:[]);await i.sessions.groupsPut(l,c),e.sessionData.isSessionMutationScopeCurrent(i)&&a()}catch(t){e.sessionData.publishSessionMutationError(i,t)}}function K(){return(K=e((()=>{u(),g(),v(),b(),F()})))()}function q(e){return{skipped:o().sessionDeleteConfirm===!1,remember:()=>{a({sessionDeleteConfirm:!1}),e.context.theme.refresh()}}}function J(e,t,n){let r={...t,confirmLabel:c(`common.delete`),danger:!0,signal:n.signal};return ce({action:`delete`,sessions:e,gateway:n.gateway,selectedAgentId:n.selectedAgentId,signal:n.signal},e=>y(e?x(r,e):r),Boolean)}async function Y(e,n,r){if(n.length===0)return;let i=await J(n,{message:c(`sessionsView.deleteSessionsConfirm`,{count:String(n.length)}),skipPreference:q(r)},r);if(!e.sessionData.isSessionMutationScopeCurrent(r)){f({message:c(`sessionsView.deleteSessionsStale`,{count:String(n.length)})});return}if(!i)return;let a=n.map(e=>({key:e.key,agentId:t(e,r.selectedAgentId),deleteTranscript:!0,...e.sessionId?{expectedSessionId:e.sessionId}:{},...e.archived===!0?{archivedOnly:!0}:{}}));for(let t of a)if(!D(e,r,{method:`sessions.delete`,params:t,allowDeferred:!0}))return;try{let t=await r.sessions.deleteMany(a);if(t.queued?.length)return;if(!e.sessionData.isSessionMutationScopeCurrent(r)){t.preservedWorktrees.length>0&&f({message:I(t.preservedWorktrees)});return}if(e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(r.selectedAgentId),!e.sessionData.isSessionMutationScopeCurrent(r))||t.preservedWorktrees.length>0&&(window.alert(I(t.preservedWorktrees)),!e.sessionData.isSessionMutationScopeCurrent(r)))return;t.errors.length>0&&e.sessionData.publishSessionMutationError(r,t.errors.map(({error:e})=>C(e)).join(`; `))}catch(t){e.sessionData.publishSessionMutationError(r,t)}}async function de(e,t,n){let r=new Set(t.map(e=>e.key)),i=new Map;for(let e of t.flatMap(e=>e.subagentSummary?.unreadHiddenRuns??[]))r.has(e.key)||i.set(e.key,e);e.sessionData.isSessionMutationScopeCurrent(n)&&await n.sessions.acknowledgeHiddenRuns([...i.values()],{agentId:n.selectedAgentId??void 0,publishErrors:!0})}function X(e){return!l(e.key)&&!e.sidebarRoot&&(e.isChild===!0||e.pinnable===!1)}async function Z(e,t,n,r){let i=[];for(let a=0;a<t.length;){let o=X(t[a]),s=a+1;for(;s<t.length&&X(t[s])===o;)s+=1;let c=await E(e,t.slice(a,s),{category:n,...o?{sidebarRoot:!0}:{}},r);if(!c)return null;i.push(...c),a=s}return i}async function fe(e,t,n,r,i){switch(t.kind){case`toggle-unread`:await E(e,n,{unread:!r},i,{sessionScope:!0}),r&&await de(e,n,i);break;case`move-to-group`:await Z(e,n.filter(e=>(e.category??null)!==t.category||X(e)),t.category,i);break;case`toggle-archived`:n.every(e=>e.archived===!0)?await E(e,n,{archived:!1},i,{sessionScope:!0}):await A(e,n.filter(e=>e.archived!==!0),i);break;case`delete`:await Y(e,n,i)}}async function pe(e,t,n){e.sessionData.isSessionMutationScopeCurrent(n)&&await ae({signal:e.sessionData.sessionDraftSignal,gateway:n.gateway,canSubmit:()=>h(n.gateway.snapshot,{method:`sessions.patch`,params:{key:t.key,label:null},sessionScope:!0,session:t,allowDeferred:!0}).allowed,title:c(`sessionsView.renameSessionPrompt`),defaultValue:t.renameValue,submit:async n=>{let i=d(n,t.renameValue,t.userLabel);if(!i)return null;let a=e.sessionData.beginSessionMutation(!0);if(!a)return c(`sessionsView.actionRequiresConnection`);let o=null,s=await k(e,t,i,a,{sessionScope:!0,handleError:e=>{let t=r(e),n=/^label already in use:/iu.test(t);return o=n?c(`sessionsView.sessionNameInUse`):t,n}});return s===`completed`?null:o??e.sessionData.sessionMutationError??c(s===`stale`?`sessionsView.renameSessionStale`:`sessionsView.renameSessionFailed`)}})}async function me(e,n,r,i){if(D(e,i,{method:`sessions.assignOwner`,params:{key:n.key,owner:r},requiredScope:`operator.write`}))try{await i.sessions.assignOwner(n.key,r,{agentId:t(n,i.selectedAgentId)})}catch(t){e.sessionData.isSessionMutationScopeCurrent(i)&&e.sessionData.publishSessionMutationError(i,t)}}async function he(e,t,n,r){if(n.some(e=>!e.sessionId))return e.sessionData.publishSessionMutationError(r,c(`common.refresh`)),`failed`;let i=await V(e,t,r);if(i!==`completed`)return i;if(n.length>0){if(n.length===1)return k(e,n[0],{category:t,...X(n[0])?{sidebarRoot:!0}:{}},r);let i=await Z(e,n,t,r);return i?i.length===n.length?`completed`:`failed`:e.sessionData.isSessionMutationScopeCurrent(r)?`failed`:`stale`}return e.sessionData.isSessionMutationScopeCurrent(r)?`completed`:`stale`}async function ge(e,t,n,r,i={}){if(!e.sessionData.isSessionMutationScopeCurrent(r))return`stale`;let a=!(!n||e.knownSessionGroups().includes(n));if(n){let t=await V(e,n,r);if(t!==`completed`)return t}let o=i.resolveSession?i.resolveSession():t;return o?(o.category??null)===n&&!X(o)?`completed`:k(e,o,{category:n,...X(o)?{sidebarRoot:!0}:{}},r):(f({message:c(a?`sessionsView.newGroupMoveSkipped`:`common.refresh`)}),`failed`)}async function _e(e,n,r){if(!e.sessionData.isSessionMutationScopeCurrent(r))return;let i=t(n,r.selectedAgentId),a={parentSessionKey:n.key,fork:!0,...n.gatewayHasActiveRun??n.hasActiveRun?{forkFrom:`last-completed`}:{},agentId:i};if(D(e,r,{method:`sessions.create`,params:a,sessionScope:!0,session:n}))try{let t=await r.sessions.create(a,{signal:r.signal});if(!e.sessionData.isSessionMutationScopeCurrent(r))return;t?e.selectSession(t):e.sessionData.publishSessionMutationError(r,r.sessions.state.error??c(`newSession.createFailed`))}catch(t){e.sessionData.publishSessionMutationError(r,t)}}async function Q(e,n,r){let i=n.cloudWorkerStopAction;if(!i||i.blocksActiveRun&&n.hasActiveRun)return;let a=await y({message:c(`sessionsView.stopCloudWorkerConfirm`,{session:n.label}),confirmLabel:c(`sessionsView.stopCloudWorkerConfirmAction`),danger:!0,signal:r.signal});if(!e.sessionData.isSessionMutationScopeCurrent(r))f({message:c(`sessionsView.stopCloudWorkerStale`,{session:n.label})});else if(a&&D(e,r,i))try{let i=t(n,r.selectedAgentId);if(await z(r.client,{key:n.key,agentId:i},r.context.placementStartup),!e.sessionData.isSessionMutationScopeCurrent(r))return;let a=await r.sessions.reconcileMutation(i);a.status===`failed`&&e.sessionData.isSessionMutationScopeCurrent(r)&&e.sessionData.publishSessionMutationError(r,a.error)}catch(t){e.sessionData.publishSessionMutationError(r,t)}}async function ve(e,n,r,i={}){let a=await J([n],{message:c(`sessionsView.deleteSessionConfirm`,{session:n.label}),...i.offerSkip?{skipPreference:q(r)}:{}},r);if(!e.sessionData.isSessionMutationScopeCurrent(r)){f({message:c(`sessionsView.deleteSessionStale`,{session:n.label})});return}if(!a)return;let o=t(n,r.selectedAgentId),s={agentId:o,deleteTranscript:!0,...n.sessionId?{expectedSessionId:n.sessionId}:{},...n.archived===!0?{archivedOnly:!0}:{}};if(D(e,r,{method:`sessions.delete`,params:{key:n.key,...s},allowDeferred:!0}))try{let t=await S({action:`delete`,session:{...n,agentId:o},scope:r,isCurrent:()=>e.sessionData.isSessionMutationScopeCurrent(r),request:()=>r.sessions.delete(n.key,s)});if(!t||t.queued)return;if(!e.sessionData.isSessionMutationScopeCurrent(r)){t.worktreePreserved&&f({message:I([t.worktreePreserved])});return}if(e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(o),!e.sessionData.isSessionMutationScopeCurrent(r)))return;if(t.worktreePreserved){let n=t.worktreePreserved;if(!h(r.gateway.snapshot,{method:`worktrees.remove`,requiredScope:`operator.admin`}).allowed)window.alert(I([n]));else{let t=await y({message:R(n),confirmLabel:c(`common.remove`),danger:!0,signal:r.signal});if(!e.sessionData.isSessionMutationScopeCurrent(r)){f({message:I([n])});return}if(t){let t=await r.client.request(`worktrees.remove`,{id:n.id,force:!0});t.snapshotError&&e.sessionData.publishSessionMutationError(r,t.snapshotError)}}}}catch(t){e.sessionData.publishSessionMutationError(r,t)}}function $(){return($=e((()=>{i(),u(),te(),ie(),n(),_(),m(),s(),L(),v(),B(),b(),oe(),se(),O(),F(),K(),T(),le(),re(),ne()})))()}$();export{P as archiveSessionWithUndo,ge as assignSessionCategory,me as assignSessionOwner,M as confirmRunningSessionsArchive,he as createSessionGroup,ve as deleteSession,U as deleteSessionGroup,Y as deleteSessionsBatch,_e as forkSession,k as patchSession,w as promoteSession,pe as renameSession,H as renameSessionGroup,ue as reorderSidebarSection,fe as runBatchSessionAction,j as setSessionInvolvement,N as snoozeSessionWithUndo,Q as stopCloudWorker,W as updateSessionGroupDefaults};