UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 16.4 kB
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Eu as t,Gr as n,Hr as r,Sl as i,Ul as a,Ur as o,du as s,ju as c,lu as l,pu as u,uu as d,xo as f,yo as p}from"./control-ui-core-BncvAZjR.js";import{Cn as ee,Xn as m,Zn as h,gn as g,mn as _}from"./control-ui-core-9qYjK5B2.js";import{Fo as te,Io as v}from"./control-ui-boot-shared-DJkUdZmL.js";import{Bi as y,zi as b}from"./control-ui-boot-shared-xfDhIVun.js";import{a as x,i as S,n as C,o as w,r as T,t as E}from"./session-workspace-recovery.runtime-sCzaBa0p.js";import{Fc as ne,Gc as re,Nc as ie,Pc as ae,Wc as oe,mc as D,pc as O}from"./control-ui-boot-shared-D3oo_6Fq.js";import{r as k,t as A}from"./input-dialog-OAeQnraY.js";import{n as j,t as M}from"./cloud-worker-stop.runtime-BR0jZ8bp.js";function N(e,t,n){let r=o(t.gateway.snapshot,n);return r.allowed?!0:(e.sessionData.publishSessionMutationError(t,r.reason),!1)}async function P(e,t,n){let r=[...new Set(n.map(e=>a(e,t.selectedAgentId)))],i=e.sidebarSessionStatusFilter()!==`active`;for(let n of r){if(!e.sessionData.isSessionMutationScopeCurrent(t))return`stale`;try{let r=await t.sessions.reconcileMutation(n);if(!e.sessionData.isSessionMutationScopeCurrent(t))return`stale`;if(r.status!==`refreshed`)return r.status===`failed`&&e.sessionData.publishSessionMutationError(t,r.error),r.status;i&&await e.sessionData.refreshSidebarSessions(n)}catch(n){return e.sessionData.isSessionMutationScopeCurrent(t)?(e.sessionData.publishSessionMutationError(t,n),`failed`):`stale`}}return e.sessionData.isSessionMutationScopeCurrent(t)?`completed`:`stale`}async function F(e,t,r,i,c={}){if(typeof r.archived==`boolean`&&t.some(e=>!e.sessionId?.trim()))return e.sessionData.publishSessionMutationError(i,`Session lifecycle action requires a durable session identity.`),null;let l=[],u=null;for(let s=0;s<t.length;s+=100){if(!e.sessionData.isSessionMutationScopeCurrent(i))return null;let d=t.slice(s,s+100),f={targets:d.map(e=>({key:e.key,agentId:a(e,i.selectedAgentId),...e.sessionId?{expectedSessionId:e.sessionId}:{}})),patch:r},p=o(i.gateway.snapshot,{method:`sessions.patchMany`,params:f,sessionScope:c.sessionScope,session:n(d)});if(!p.allowed){u=p.reason,l.length===0&&e.sessionData.publishSessionMutationError(i,p.reason);break}try{let t=await i.sessions.patchMany(f.targets,f.patch);if(!t||!e.sessionData.isSessionMutationScopeCurrent(i))return null;l.push({rows:d,result:t})}catch(t){u=t,l.length===0&&e.sessionData.publishSessionMutationError(i,t);break}}if(l.length===0||!c.deferListRefresh&&await P(e,i,t)===`stale`||!e.sessionData.isSessionMutationScopeCurrent(i))return null;let d=[],f=l.flatMap(({rows:t,result:n})=>n.outcomes.flatMap((n,i)=>{if(!n.ok)return d.push(`${n.key}: ${E(new m(n.error))}`),[];let a=t[i];return a?.pinned&&r.archived===!0&&e.pruneSidebarSessionEntry(a.key),a?[a]:[]})),p=u===null?``:s(u);return p&&d.push(p),d.length>0&&e.sessionData.publishSessionMutationError(i,d.join(`; `)),f}async function I(e,t,n,r){if(!e.sessionData.isSessionMutationScopeCurrent(r)||!t.sessionId)return;let i=a(t,r.selectedAgentId);if(N(e,r,{method:`sessions.setInvolvement`,requiredScope:`operator.read`}))try{if(await f(r.client,{key:t.key,agentId:i,expectedSessionId:t.sessionId,hidden:n}),!e.sessionData.isSessionMutationScopeCurrent(r))return;r.sessions.patchRowLocal(t.key,{hiddenFromInvolvingMe:n},{agentId:i,sessionId:t.sessionId}),await e.sessionData.refreshSidebarSessions(i)}catch(t){e.sessionData.isSessionMutationScopeCurrent(r)&&e.sessionData.publishSessionMutationError(r,t)}}function L(){return(L=e((()=>{h(),u(),r(),i(),p(),C()})))()}async function R(e,t,n){let r=e.knownSessionGroups();return r.includes(t)?`completed`:H(e,n,`sessions.groups.put`,()=>n.sessions.groupsPut([...r,t]))}async function z(e,t,n,r){return await H(e,r,`sessions.groups.rename`,()=>r.sessions.groupsRename(t,n))===`completed`}async function B(e,t,n){if(!e.sessionData.isSessionMutationScopeCurrent(n)||!N(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 d({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}}async function V(e,t,n,r){return H(e,r,`sessions.groups.update`,()=>r.sessions.groupsUpdate(t,n))}async function H(e,t,n,r){if(!e.sessionData.isSessionMutationScopeCurrent(t))return`stale`;if(!N(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 U(e,t,n,r,i){if(e.sessionData.isSessionMutationScopeCurrent(i)&&N(e,i,{method:`sessions.groups.put`,requiredScope:`operator.write`}))try{let a=e.knownSessionGroups(),o=e.knownSessionCatalogIds(),s=ae(ne(e.knownSectionOrder(),a,o),t,n,r),c=s.flatMap(e=>e.startsWith(`category:`)?[e.slice(9)]:[]);if(await i.sessions.groupsPut(c,s),!e.sessionData.isSessionMutationScopeCurrent(i))return;e.requestUpdate()}catch(t){e.sessionData.publishSessionMutationError(i,t)}}function W(){return(W=e((()=>{t(),ie(),l(),b(),L()})))()}async function G(e,t,n,r,i={}){if(!e.sessionData.isSessionMutationScopeCurrent(r))return`stale`;let o=a(t,r.selectedAgentId),s={key:t.key,...n,agentId:o,...t.sessionId?{expectedSessionId:t.sessionId}:{}};if((typeof n.archived==`boolean`||n.snoozedUntil!==void 0)&&!t.sessionId?.trim())return e.sessionData.publishSessionMutationError(r,`Session lifecycle action requires a durable session identity.`),`failed`;if(!N(e,r,{method:`sessions.patch`,params:s,sessionScope:i.sessionScope,session:t}))return`failed`;try{let a=()=>r.sessions.patch(t.key,n,{agentId:o,...t.sessionId?{expectedSessionId:t.sessionId}:{},...i.deferListRefresh?{deferListRefresh:!0}:{}}),s=n.archived===!0?await T({action:`archive`,session:{...t,agentId:o},scope:r,isCurrent:()=>e.sessionData.isSessionMutationScopeCurrent(r),request:a}):await a();return e.sessionData.isSessionMutationScopeCurrent(r)?s?((n.pinned===!1||n.archived===!0&&t.pinned)&&e.pruneSidebarSessionEntry(t.key),!i.deferListRefresh&&e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(o),!e.sessionData.isSessionMutationScopeCurrent(r))?`stale`:`completed`):(r.sessions.state.error&&e.sessionData.publishSessionMutationError(r,r.sessions.state.error),`failed`):`stale`}catch(t){return e.sessionData.isSessionMutationScopeCurrent(r)?(e.sessionData.publishSessionMutationError(r,t),`failed`):`stale`}}async function K(e,t,n,r){if(await G(e,t,{snoozedUntil:n},r,{sessionScope:!0})!==`completed`||!e.sessionData.isSessionMutationScopeCurrent(r))return;let i=Y(e,r);d({message:c(`sessionsView.sessionSnoozed`,{time:oe(n)}),actionLabel:c(`common.undo`),onAction:()=>void G(i,t,{snoozedUntil:null},r,{sessionScope:!0})})}async function q(e,t,n){if(!e.sessionData.isSessionMutationScopeCurrent(n))return;let r=n.sessions.beginArchive(t.key,t.sessionId);if(!r)return;let i;try{i=await G(e,t,{archived:!0},n,{sessionScope:!0})}finally{r()}i===`completed`&&e.sessionData.isSessionMutationScopeCurrent(n)&&d({message:c(`sessionsView.sessionArchived`),actionLabel:c(`common.undo`),onAction:J(e,[{session:t,pinned:t.pinned}],n)})}async function se(e,t,n){if(t.length===0||!e.sessionData.isSessionMutationScopeCurrent(n))return;let r=t.flatMap(e=>{let t=n.sessions.beginArchive(e.key,e.sessionId);return t?[{row:e,finish:t}]:[]});if(r.length===0)return;let i=r.map(({row:e})=>e),a;try{a=await F(e,i,{archived:!0},n,{sessionScope:!0})}finally{for(let{finish:e}of r)e()}if(!a||a.length===0)return;let o=a.map(e=>({session:e,pinned:e.pinned}));d({message:o.length===1?c(`sessionsView.sessionArchived`):c(`sessionsView.sessionsArchived`,{count:String(o.length)}),actionLabel:c(`common.undo`),onAction:J(e,o,n)})}function J(e,t,n){let r=Y(e,n);return()=>void ce(r,t,n)}function Y(e,t){let n=t.sessions.captureConnectionScope();return{pruneSidebarSessionEntry:t=>e.pruneSidebarSessionEntry(t),selectSession:t=>e.selectSession(t),sidebarSessionStatusFilter:()=>e.sidebarSessionStatusFilter(),sessionData:{refreshSidebarSessions:t=>e.sessionData.refreshSidebarSessions(t),isSessionMutationScopeCurrent:()=>n!==null&&t.sessions.isConnectionScopeCurrent(n),publishSessionMutationError:(r,i)=>{e.sessionData.isSessionMutationScopeCurrent(r)?e.sessionData.publishSessionMutationError(r,i):n&&t.sessions.isConnectionScopeCurrent(n)&&d({message:s(i)})}}}}async function ce(e,t,n){let r=t.map(e=>e.session);if(t.length===1){let{session:r,pinned:i}=t[0];if(await G(e,r,{archived:!1,...i?{pinned:!0}:{}},n,{deferListRefresh:!0,sessionScope:!0})===`stale`)return}else{let i=await F(e,r,{archived:!1},n,{deferListRefresh:!0,sessionScope:!0});if(!i)return;let a=t.flatMap(({session:e,pinned:t})=>t&&i.includes(e)?[e]:[]);if(a.length>0&&!await F(e,a,{pinned:!0},n,{deferListRefresh:!0,sessionScope:!0})&&!e.sessionData.isSessionMutationScopeCurrent(n))return}if(e.sessionData.isSessionMutationScopeCurrent(n)){n.sessions.invalidate();try{let t=await n.sessions.refreshReplacement();if(!e.sessionData.isSessionMutationScopeCurrent(n))return;!t&&n.sessions.state.error&&e.sessionData.publishSessionMutationError(n,n.sessions.state.error)}catch(t){e.sessionData.isSessionMutationScopeCurrent(n)&&e.sessionData.publishSessionMutationError(n,t)}}}function X(e){return{skipped:g().sessionDeleteConfirm===!1,remember:()=>{ee({sessionDeleteConfirm:!1}),e.context.theme.refresh()}}}async function Z(e,t,n){if(t.length===0)return;let r=await y({message:c(`sessionsView.deleteSessionsConfirm`,{count:String(t.length)}),confirmLabel:c(`common.delete`),danger:!0,skipPreference:X(n),signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n)){d({message:c(`sessionsView.deleteSessionsStale`,{count:String(t.length)})});return}if(!r)return;let i=t.map(e=>({key:e.key,agentId:a(e,n.selectedAgentId),deleteTranscript:!0,...e.sessionId?{expectedSessionId:e.sessionId}:{},...e.archived===!0?{archivedOnly:!0}:{}}));for(let t of i)if(!N(e,n,{method:`sessions.delete`,params:t}))return;try{let t=await n.sessions.deleteMany(i);if(!e.sessionData.isSessionMutationScopeCurrent(n)){t.preservedWorktrees.length>0&&d({message:x(t.preservedWorktrees)});return}if(e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(n.selectedAgentId),!e.sessionData.isSessionMutationScopeCurrent(n))||t.preservedWorktrees.length>0&&(window.alert(x(t.preservedWorktrees)),!e.sessionData.isSessionMutationScopeCurrent(n)))return;t.errors.length>0&&e.sessionData.publishSessionMutationError(n,t.errors.map(({error:e})=>E(e)).join(`; `))}catch(t){e.sessionData.publishSessionMutationError(n,t)}}async function le(e,t,n,r,i){switch(t.kind){case`toggle-unread`:await F(e,n,{unread:!r},i);break;case`move-to-group`:await F(e,n.filter(e=>(e.category??null)!==t.category),{category:t.category},i);break;case`toggle-archived`:n.every(e=>e.archived===!0)?await F(e,n,{archived:!1},i,{sessionScope:!0}):await se(e,n.filter(e=>e.archived!==!0),i);break;case`delete`:await Z(e,n,i)}}async function ue(e,t,n){let r=await k({signal:n.signal,title:c(`sessionsView.renameSessionPrompt`),defaultValue:t.renameValue});if(r===null)return;let i=D(r,t.renameValue,t.userLabel);i&&await G(e,t,i,n,{sessionScope:!0})}async function de(e,t,n,r){if(!N(e,r,{method:`sessions.assignOwner`,params:{key:t.key,owner:n},requiredScope:`operator.write`}))return;let i=await r.sessions.assignOwner(t.key,n,{agentId:a(t,r.selectedAgentId)});e.sessionData.isSessionMutationScopeCurrent(r)&&!i&&r.sessions.state.error&&e.sessionData.publishSessionMutationError(r,r.sessions.state.error)}async function Q(e,t,n,r){if(n.some(e=>!e.sessionId))return e.sessionData.publishSessionMutationError(r,c(`common.refresh`)),`failed`;let i=await R(e,t,r);if(i!==`completed`)return i;if(n.length>0){if(n.length===1)return G(e,n[0],{category:t},r);let i=await F(e,n,{category:t},r);return i?i.length===n.length?`completed`:`failed`:e.sessionData.isSessionMutationScopeCurrent(r)?`failed`:`stale`}return e.sessionData.isSessionMutationScopeCurrent(r)?(e.requestUpdate(),`completed`):`stale`}async function fe(e,t,n,r,i={},a={}){if(!e.sessionData.isSessionMutationScopeCurrent(r))return;let o=!(!n||e.knownSessionGroups().includes(n));if(n&&await R(e,n,r)!==`completed`)return;let s=a.resolveSession?a.resolveSession():t;if(!s){d({message:c(o?`sessionsView.newGroupMoveSkipped`:`common.refresh`)});return}((s.category??null)!==n||i.pinned!==void 0)&&await G(e,s,{category:n,...i},r)}async function pe(e,t,n){if(!e.sessionData.isSessionMutationScopeCurrent(n))return;let r=a(t,n.selectedAgentId),i={parentSessionKey:t.key,fork:!0,...t.gatewayHasActiveRun??t.hasActiveRun?{forkFrom:`last-completed`}:{},agentId:r};if(N(e,n,{method:`sessions.create`,params:i}))try{let t=await n.sessions.create(i);if(!e.sessionData.isSessionMutationScopeCurrent(n))return;t?e.selectSession(t):e.sessionData.publishSessionMutationError(n,n.sessions.state.error??c(`newSession.createFailed`))}catch(t){e.sessionData.publishSessionMutationError(n,t)}}async function me(e,t,n){let r=t.cloudWorkerStopAction;if(!r||r.blocksActiveRun&&t.hasActiveRun)return;let i=await y({message:c(`sessionsView.stopCloudWorkerConfirm`,{session:t.label}),confirmLabel:c(`sessionsView.stopCloudWorkerConfirmAction`),danger:!0,signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n)){d({message:c(`sessionsView.stopCloudWorkerStale`,{session:t.label})});return}if(i&&N(e,n,r))try{let r=a(t,n.selectedAgentId);if(await j(n.client,{key:t.key,agentId:r},n.context.placementStartup),!e.sessionData.isSessionMutationScopeCurrent(n))return;let i=await n.sessions.reconcileMutation(r);i.status===`failed`&&e.sessionData.isSessionMutationScopeCurrent(n)&&e.sessionData.publishSessionMutationError(n,i.error)}catch(t){e.sessionData.publishSessionMutationError(n,t)}}async function he(e,t,n,r={}){let i=await y({message:c(`sessionsView.deleteSessionConfirm`,{session:t.label}),confirmLabel:c(`common.delete`),danger:!0,...r.offerSkip?{skipPreference:X(n)}:{},signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n)){d({message:c(`sessionsView.deleteSessionStale`,{session:t.label})});return}if(!i)return;let s=a(t,n.selectedAgentId),l={agentId:s,deleteTranscript:!0,...t.sessionId?{expectedSessionId:t.sessionId}:{},...t.archived===!0?{archivedOnly:!0}:{}};if(N(e,n,{method:`sessions.delete`,params:{key:t.key,...l}}))try{let r=await T({action:`delete`,session:{...t,agentId:s},scope:n,isCurrent:()=>e.sessionData.isSessionMutationScopeCurrent(n),request:()=>n.sessions.delete(t.key,l)});if(!r)return;if(!e.sessionData.isSessionMutationScopeCurrent(n)){r.worktreePreserved&&d({message:x([r.worktreePreserved])});return}if(e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(s),!e.sessionData.isSessionMutationScopeCurrent(n)))return;if(r.worktreePreserved){let t=r.worktreePreserved;if(!o(n.gateway.snapshot,{method:`worktrees.remove`,requiredScope:`operator.admin`}).allowed)window.alert(x([t]));else{let r=await y({message:S(t),confirmLabel:c(`common.remove`),danger:!0,signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n)){d({message:x([t])});return}if(r)try{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)}}}}catch(t){e.sessionData.publishSessionMutationError(n,t)}}function $(){return($=e((()=>{_(),t(),te(),u(),r(),O(),i(),re(),w(),l(),M(),b(),A(),L(),W(),C(),v()})))()}$();export{q as archiveSessionWithUndo,fe as assignSessionCategory,de as assignSessionOwner,Q as createSessionGroup,he as deleteSession,B as deleteSessionGroup,Z as deleteSessionsBatch,pe as forkSession,G as patchSession,ue as renameSession,z as renameSessionGroup,U as reorderSidebarSection,le as runBatchSessionAction,I as setSessionInvolvement,K as snoozeSessionWithUndo,me as stopCloudWorker,V as updateSessionGroupDefaults};