UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 11.6 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Ct as t,Qo as n,Ss as r,Tt as i,bt as a,is as o,li as s,oi as c}from"./_4____________________________.js";import{AN as l,EN as u,JO as d,YO as f,eh as p,fk as m,ig as h,mk as g,ng as _,rg as v,th as y}from"./_2_____________________________.js";import{Bi as b,Hi as x}from"./deferred-ui-support-DZEPWjAk.js";import{Et as ee,Tt as te}from"./control-ui-boot-new-pHXPNTZp.js";import{r as ne,t as re}from"./input-dialog-CxtPbrlW.js";import{n as ie,t as ae}from"./session-management-english-BXruTz7H.js";import{a as oe,i as se,n as ce,o as S,r as C,t as w}from"./session-workspace-recovery.runtime-CrnLuShq.js";import{a as T,c as E,d as D,f as O,i as k,l as A,n as j,p as M,r as N,s as P,t as F,u as I}from"./session-organizer-archive.runtime-D9IrcuJA.js";import{n as L,t as R}from"./session-delete-confirmation-BMC3FI34.js";import{n as z,r as B,t as V}from"./worktree-preservation-DD3484QD.js";import{n as le,t as H}from"./cloud-worker-stop.runtime-C_o44RQn.js";async function U(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 W(e,t,n,r){return await G(e,r,`sessions.groups.rename`,()=>r.sessions.groupsRename(t,n))===`completed`}async function ue(e,t,n){if(!e.sessionData.isSessionMutationScopeCurrent(n)||!O(e,n,{method:`sessions.groups.delete`,requiredScope:`operator.write`}))return!1;let r=await x({title:s(`sessionsView.deleteGroupTitle`,{group:t}),message:s(`sessionsView.deleteGroupConfirm`),confirmLabel:s(`common.delete`),danger:!0,signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n))return g({severity:`error`,message:s(`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 de(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(!O(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 fe(e,t,n,r,i,a){if(e.sessionData.isSessionMutationScopeCurrent(i)&&O(e,i,{method:`sessions.groups.put`,requiredScope:`operator.write`}))try{let o=e.knownSessionGroups(),s=e.knownSessionCatalogIds(),c=v(h(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((()=>{c(),_(),m(),b(),I()})))()}function q(e){return{skipped:t().sessionDeleteConfirm===!1,remember:()=>{i({sessionDeleteConfirm:!1}),e.context.theme.refresh()}}}function J(e,t,n){let r={...t,confirmLabel:s(`common.delete`),danger:!0,signal:n.signal};return se({action:`delete`,sessions:e,gateway:n.gateway,selectedAgentId:n.selectedAgentId,signal:n.signal},e=>x(e?S(r,e):r),Boolean)}async function Y(e,t,n){if(t.length===0)return;let i=await J(t,{title:s(`sessionsView.deleteSessionsTitle`,{count:String(t.length)}),message:L(t),skipPreference:q(n)},n);if(!e.sessionData.isSessionMutationScopeCurrent(n)){g({severity:`error`,message:s(`sessionsView.deleteSessionsStale`,{count:String(t.length)})});return}if(!i)return;let a=t.map(e=>({key:e.key,agentId:r(e,n.selectedAgentId),deleteTranscript:!0,...e.sessionId?{expectedSessionId:e.sessionId}:{},...e.archived===!0?{archivedOnly:!0}:{}}));for(let t of a)if(!O(e,n,{method:`sessions.delete`,params:t,allowDeferred:!0}))return;try{let t=await n.sessions.deleteMany(a);if(t.queued?.length)return;if(!e.sessionData.isSessionMutationScopeCurrent(n)){t.preservedWorktrees.length>0&&g({severity:void 0,message:z(t.preservedWorktrees)});return}if(e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(n.selectedAgentId),!e.sessionData.isSessionMutationScopeCurrent(n))||t.preservedWorktrees.length>0&&(window.alert(z(t.preservedWorktrees)),!e.sessionData.isSessionMutationScopeCurrent(n)))return;t.errors.length>0&&e.sessionData.publishSessionMutationError(n,t.errors.map(({error:e})=>w(e)).join(`; `))}catch(t){e.sessionData.publishSessionMutationError(n,t)}}async function pe(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!o(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 D(e,t.slice(a,s),{category:n,...o?{sidebarRoot:!0}:{}},r);if(!c)return null;i.push(...c),a=s}return i}async function me(e,t,n,r,i){switch(t.kind){case`toggle-unread`:await D(e,n,{unread:!r},i,{sessionScope:!0}),r&&await pe(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 D(e,n,{archived:!1},i,{sessionScope:!0}):await j(e,n.filter(e=>e.archived!==!0),i);break;case`delete`:await Y(e,n,i)}}async function Q(e,t,n){if(!e.sessionData.isSessionMutationScopeCurrent(n))return;let r=()=>f(n.gateway.snapshot,{method:`sessions.patch`,params:{key:t.key,label:null},sessionScope:!0,session:t,allowDeferred:!0}).allowed;r()&&await ne({signal:e.sessionData.sessionDraftSignal,gateway:n.gateway,canSubmit:r,title:s(`sessionsView.renameSessionPrompt`),defaultValue:t.renameValue,submit:async n=>{let r=y(n,t.renameValue,t.userLabel);if(!r)return null;let i=e.sessionData.beginSessionMutation(!0);if(!i)return s(`sessionsView.actionRequiresConnection`);let a=null,o=await A(e,t,r,i,{sessionScope:!0,handleError:e=>{let t=u(e),n=/^label already in use:/iu.test(t);return a=n?s(`sessionsView.sessionNameInUse`):t,n}});return o===`completed`?null:a??e.sessionData.sessionMutationError??s(o===`stale`?`sessionsView.renameSessionStale`:`sessionsView.renameSessionFailed`)}})}async function he(e,t,n,i){if(O(e,i,{method:`sessions.assignOwner`,params:{key:t.key,owner:n},requiredScope:`operator.write`}))try{await i.sessions.assignOwner(t.key,n,{agentId:r(t,i.selectedAgentId)})}catch(t){e.sessionData.isSessionMutationScopeCurrent(i)&&e.sessionData.publishSessionMutationError(i,t)}}async function ge(e,t,n,r){if(n.some(e=>!e.sessionId))return e.sessionData.publishSessionMutationError(r,s(`common.refresh`)),`failed`;let i=await U(e,t,r);if(i!==`completed`)return i;if(n.length>0){if(n.length===1)return A(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 _e(e,t,n,r,i={}){if(!e.sessionData.isSessionMutationScopeCurrent(r))return`stale`;let a=!(!n||e.knownSessionGroups().includes(n));if(n){let t=await U(e,n,r);if(t!==`completed`)return t}let o=i.resolveSession?i.resolveSession():t;return o?(o.category??null)===n&&!X(o)?`completed`:A(e,o,{category:n,...X(o)?{sidebarRoot:!0}:{}},r):(g({severity:a?`error`:void 0,message:s(a?`sessionsView.newGroupMoveSkipped`:`common.refresh`)}),`failed`)}async function ve(e,t,n,i){if(!e.sessionData.isSessionMutationScopeCurrent(n))return`stale`;let a=r(t,n.selectedAgentId),o={parentSessionKey:t.key,...i.title?.trim()?{label:i.title.trim()}:{},...i.fork?{fork:!0,...t.gatewayHasActiveRun??t.hasActiveRun?{forkFrom:`last-completed`}:{}}:{},agentId:a};if(!O(e,n,{method:`sessions.create`,params:o,sessionScope:!0,session:t}))return`failed`;try{let t=await n.sessions.create(o,{signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n))return`stale`;if(t)return e.selectSession(t),`completed`;e.sessionData.publishSessionMutationError(n,n.sessions.state.error??s(`newSession.createFailed`))}catch(t){e.sessionData.publishSessionMutationError(n,t)}return`failed`}async function ye(e,t,n){let i=t.cloudWorkerStopAction;if(!i||i.blocksActiveRun&&t.hasActiveRun)return;let a=await x({title:s(`${i.copyKey}Confirm`,{session:t.label}),message:s(`${i.copyKey}Description`),details:s(`sessionsView.stopCloudWorkerTarget`,{session:t.label}),confirmLabel:s(`sessionsView.stopCloudWorkerConfirmAction`),danger:!0,signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n))g({severity:`error`,message:s(`sessionsView.stopCloudWorkerStale`,{session:t.label})});else if(a&&O(e,n,i))try{let i=r(t,n.selectedAgentId);if(await le(n.client,{key:t.key,agentId:i},n.context.placementStartup),!e.sessionData.isSessionMutationScopeCurrent(n))return;let a=await n.sessions.reconcileMutation(i);a.status===`failed`&&e.sessionData.isSessionMutationScopeCurrent(n)&&e.sessionData.publishSessionMutationError(n,a.error)}catch(t){e.sessionData.publishSessionMutationError(n,t)}}async function be(e,t,n,i={}){let a=await J([t],{title:s(`sessionsView.deleteSessionTitle`,{session:t.label}),message:L([t]),...i.offerSkip?{skipPreference:q(n)}:{}},n);if(!e.sessionData.isSessionMutationScopeCurrent(n)){g({severity:`error`,message:s(`sessionsView.deleteSessionStale`,{session:t.label})});return}if(!a)return;let o=r(t,n.selectedAgentId),c={agentId:o,deleteTranscript:!0,...t.sessionId?{expectedSessionId:t.sessionId}:{},...t.archived===!0?{archivedOnly:!0}:{}};if(O(e,n,{method:`sessions.delete`,params:{key:t.key,...c},allowDeferred:!0}))try{let r=await C({action:`delete`,session:{...t,agentId:o},scope:n,isCurrent:()=>e.sessionData.isSessionMutationScopeCurrent(n),request:()=>n.sessions.delete(t.key,c)});if(!r||r.queued)return;if(!e.sessionData.isSessionMutationScopeCurrent(n)){r.worktreePreserved&&g({severity:void 0,message:z([r.worktreePreserved])});return}if(e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(o),!e.sessionData.isSessionMutationScopeCurrent(n)))return;if(r.worktreePreserved){let t=r.worktreePreserved;if(!f(n.gateway.snapshot,{method:`worktrees.remove`,requiredScope:`operator.admin`}).allowed)window.alert(z([t]));else{let r=await x({title:s(`sessionsView.removePreservedWorktreeTitle`,{branch:t.branch}),message:V(t),confirmLabel:s(`common.remove`),danger:!0,signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n)){g({severity:void 0,message:z([t])});return}if(r){let r=await n.client.request(`worktrees.remove`,{id:t.id,force:!0});r.snapshotError&&e.sessionData.publishSessionMutationError(n,r.snapshotError)}}}}catch(t){e.sessionData.publishSessionMutationError(n,t)}}function $(){return($=e((()=>{a(),c(),te(),ae(),l(),d(),p(),R(),n(),B(),m(),H(),b(),re(),oe(),k(),I(),K(),E(),ce(),ie(),ee()})))()}$();export{F as archiveSessionWithUndo,_e as assignSessionCategory,he as assignSessionOwner,N as confirmRunningSessionsArchive,ve as createChildSession,ge as createSessionGroup,be as deleteSession,ue as deleteSessionGroup,Y as deleteSessionsBatch,A as patchSession,T as promoteSession,Q as renameSession,W as renameSessionGroup,fe as reorderSidebarSection,me as runBatchSessionAction,M as setSessionInvolvement,P as snoozeSessionWithUndo,ye as stopCloudWorker,de as updateSessionGroupDefaults};