UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines 14.5 kB
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{$ as t,Q as n,ta as r}from"./control-ui-foundation-Cydpkyqa.js";import{As as i,Eo as a,Ls as o,Oo as s,ea as c,oa as l,sa as u,ta as d}from"./control-ui-core-Rwzhj6nO.js";import{J as f,Z as p,at as m}from"./control-ui-core-YphAl4aM.js";import{Yt as h,en as g}from"./control-ui-core-vvcQQV2m.js";import{a as _,r as v}from"./gateway-runtime-Bqqcp9-I.js";import{in as y,rn as b}from"./control-ui-boot-chat-_QSl8fbH.js";import{$s as ee,Qs as x,Zs as S}from"./control-ui-boot-shared-CXVvK2AW.js";import{n as C,r as w,t as T}from"./worktree-preservation-BzBdreYx.js";import{n as E,t as D}from"./cloud-worker-stop.runtime-CEd3IinU.js";function O(e,t,n){let r=d(t.gateway.snapshot,n);return r.allowed?!0:(e.sessionData.publishSessionMutationError(t,r.reason),!1)}function k(e,t){return o(e.key)?.agentId??t.selectedAgentId}async function A(e,t,n){let r=[...new Set(n.map(e=>k(e,t)))],i=e.sidebarSessionStatusFilter()!==`active`;for(let n of r){if(!e.sessionData.isSessionMutationScopeCurrent(t))return`stale`;try{await t.sessions.refreshReplacement(n),i&&e.sessionData.isSessionMutationScopeCurrent(t)&&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 j(e,t,r,i,o={}){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 s=[],c=null;for(let a=0;a<t.length;a+=100){if(!e.sessionData.isSessionMutationScopeCurrent(i))return null;let l=t.slice(a,a+100),u={targets:l.map(e=>({key:e.key,agentId:k(e,i),...e.sessionId?{expectedSessionId:e.sessionId}:{}})),patch:r},f=d(i.gateway.snapshot,{method:`sessions.patchMany`,params:u});if(!f.allowed){if(s.length===0&&f.cause===`method-unavailable`&&_(i.gateway.snapshot,`sessions.patchMany`)===!1&&o.fallback)return o.fallback();c=f.reason,s.length===0&&e.sessionData.publishSessionMutationError(i,f.reason);break}try{let t=r.archived===!0?await i.client.request(`sessions.patchMany`,u,n):await i.client.request(`sessions.patchMany`,u);if(!e.sessionData.isSessionMutationScopeCurrent(i))return null;s.push({rows:l,result:t})}catch(t){c=t,s.length===0&&e.sessionData.publishSessionMutationError(i,t);break}}if(s.length===0||!o.deferListRefresh&&await A(e,i,t)===`stale`||!e.sessionData.isSessionMutationScopeCurrent(i))return null;let l=[],u=s.flatMap(({rows:t,result:n})=>n.outcomes.flatMap((n,i)=>{if(!n.ok)return l.push(`${n.key}: ${a(n.error.message)}`),[];let o=t[i];return o?.pinned&&r.archived===!0&&e.pruneSidebarSessionEntry(o.key),o?[o]:[]})),f=c===null?``:a(c);return f&&l.push(f),l.length>0&&e.sessionData.publishSessionMutationError(i,l.join(`; `)),u}function M(){return(M=e((()=>{t(),s(),v(),c(),i()})))()}async function N(e,t,n){let r=e.knownSessionGroups();if(r.includes(t))return`completed`;if(!e.sessionData.isSessionMutationScopeCurrent(n))return`stale`;if(!O(e,n,{method:`sessions.groups.put`,requiredScope:`operator.write`}))return`failed`;try{return await n.sessions.groupsPut([...r,t])===`completed`&&e.sessionData.isSessionMutationScopeCurrent(n)?`completed`:`stale`}catch(t){return e.sessionData.isSessionMutationScopeCurrent(n)?(e.sessionData.publishSessionMutationError(n,t),`failed`):`stale`}}async function P(e,t,n,r){if(!e.sessionData.isSessionMutationScopeCurrent(r)||!O(e,r,{method:`sessions.groups.rename`,requiredScope:`operator.write`}))return!1;try{return await r.sessions.groupsRename(t,n)===`completed`&&e.sessionData.isSessionMutationScopeCurrent(r)}catch(t){return e.sessionData.publishSessionMutationError(r,t),!1}}async function F(e,t,n){if(!e.sessionData.isSessionMutationScopeCurrent(n)||!O(e,n,{method:`sessions.groups.delete`,requiredScope:`operator.write`}))return!1;let r=await y({title:g(`sessionsView.deleteGroupTitle`,{group:t}),message:g(`sessionsView.deleteGroupConfirm`),confirmLabel:g(`common.delete`),danger:!0,signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n))return u({message:g(`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 I(e,t,n,r){if(!e.sessionData.isSessionMutationScopeCurrent(r))return`stale`;if(!O(e,r,{method:`sessions.groups.update`,requiredScope:`operator.write`}))return`failed`;try{return await r.sessions.groupsUpdate(t,n)===`completed`&&e.sessionData.isSessionMutationScopeCurrent(r)?`completed`:`stale`}catch(t){return e.sessionData.isSessionMutationScopeCurrent(r)?(e.sessionData.publishSessionMutationError(r,t),`failed`):`stale`}}async function L(e,t,n,r,i){if(e.sessionData.isSessionMutationScopeCurrent(i)&&O(e,i,{method:`sessions.groups.put`,requiredScope:`operator.write`}))try{let a=e.knownSessionGroups(),o=e.knownSessionCatalogIds(),s=x(ee(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 R(){return(R=e((()=>{h(),S(),l(),b(),M()})))()}async function z(e,t,n,r,i={}){if(!e.sessionData.isSessionMutationScopeCurrent(r))return`stale`;let a=k(t,r),o={key:t.key,...n,agentId:a,...t.sessionId?{expectedSessionId:t.sessionId}:{}};if(typeof n.archived==`boolean`&&!t.sessionId?.trim())return e.sessionData.publishSessionMutationError(r,`Session lifecycle action requires a durable session identity.`),`failed`;if(!O(e,r,{method:`sessions.patch`,params:o}))return`failed`;try{let o=await r.sessions.patch(t.key,n,{agentId:a,...t.sessionId?{expectedSessionId:t.sessionId}:{},...i.deferListRefresh?{deferListRefresh:!0}:{}});return e.sessionData.isSessionMutationScopeCurrent(r)?o?((n.pinned===!1||n.archived===!0&&t.pinned)&&e.pruneSidebarSessionEntry(t.key),!i.deferListRefresh&&e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(a),!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 B(e,t,n,r){if(!r)return`stale`;if(t.length===0)return`completed`;let i=await j(e,t,n,r,{fallback:()=>V(e,t,n,r)});return i?i.length===t.length?`completed`:`failed`:e.sessionData.isSessionMutationScopeCurrent(r)?`failed`:`stale`}async function V(e,t,n,r,i={}){let a=[];for(let i of t){let t=await z(e,i,n,r,{deferListRefresh:!0});if(t===`stale`)return null;t===`completed`&&a.push(i)}return!i.deferListRefresh&&await A(e,r,t)===`stale`?null:a}async function H(e,t,n){n.sessions.setArchivePending(t.key,!0);let r=await z(e,t,{archived:!0},n);n.sessions.setArchivePending(t.key,!1),!(r!==`completed`||!e.sessionData.isSessionMutationScopeCurrent(n))&&u({message:g(`sessionsView.sessionArchived`),actionLabel:g(`common.undo`),onAction:()=>void W(e,[{session:t,pinned:t.pinned}],n)})}async function U(e,t,n){if(t.length===0)return;let r=await j(e,t,{archived:!0},n,{fallback:()=>V(e,t,{archived:!0},n)});if(!r||r.length===0)return;let i=r.map(e=>({session:e,pinned:e.pinned}));u({message:i.length===1?g(`sessionsView.sessionArchived`):g(`sessionsView.sessionsArchived`,{count:String(i.length)}),actionLabel:g(`common.undo`),onAction:()=>void W(e,i,n)})}async function W(e,t,n){let r=t.map(e=>e.session),i=r.length===1,a=i?await V(e,r,{archived:!1},n,{deferListRefresh:!0}):await j(e,r,{archived:!1},n,{deferListRefresh:!0,fallback:()=>V(e,r,{archived:!1},n,{deferListRefresh:!0})});if(!a)return;let o=t.flatMap(({session:e,pinned:t})=>t&&a.includes(e)?[e]:[]);o.length>0&&!(i?await V(e,o,{pinned:!0},n,{deferListRefresh:!0}):await j(e,o,{pinned:!0},n,{deferListRefresh:!0,fallback:()=>V(e,o,{pinned:!0},n,{deferListRefresh:!0})}))&&!e.sessionData.isSessionMutationScopeCurrent(n)||e.sessionData.isSessionMutationScopeCurrent(n)&&await A(e,n,r)}function G(e){return{skipped:p().sessionDeleteConfirm===!1,remember:()=>{m({sessionDeleteConfirm:!1}),e.context.theme.refresh()}}}async function K(e,t,n){if(t.length===0)return;let r=await y({message:g(`sessionsView.deleteSessionsConfirm`,{count:String(t.length)}),confirmLabel:g(`common.delete`),danger:!0,skipPreference:G(n),signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n)){u({message:g(`sessionsView.deleteSessionsStale`,{count:String(t.length)})});return}if(!r)return;let i=t.map(e=>({key:e.key,agentId:o(e.key)?.agentId??n.selectedAgentId,deleteTranscript:!0,...e.sessionId?{expectedSessionId:e.sessionId}:{},...e.archived===!0?{archivedOnly:!0}:{}}));for(let t of i)if(!O(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&&u({message:C(t.preservedWorktrees)});return}if(e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(n.selectedAgentId),!e.sessionData.isSessionMutationScopeCurrent(n))||t.preservedWorktrees.length>0&&(window.alert(C(t.preservedWorktrees)),!e.sessionData.isSessionMutationScopeCurrent(n)))return;t.errors.length>0&&e.sessionData.publishSessionMutationError(n,t.errors.join(`; `))}catch(t){e.sessionData.publishSessionMutationError(n,t)}}async function q(e,t,n,r,i){switch(t.kind){case`toggle-unread`:await B(e,n,{unread:!r},i);break;case`move-to-group`:await B(e,n.filter(e=>(e.category??null)!==t.category),{category:t.category},i);break;case`toggle-archived`:n.every(e=>e.archived===!0)?await j(e,n,{archived:!1},i,{fallback:()=>V(e,n,{archived:!1},i)}):await U(e,n.filter(e=>e.archived!==!0),i);break;case`delete`:await K(e,n,i)}}async function J(e,t,n,i){await z(e,t,{label:r(n)??null},i)}async function Y(e,t,n,r){if(!O(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:o(t.key)?.agentId??r.selectedAgentId});e.sessionData.isSessionMutationScopeCurrent(r)&&!i&&r.sessions.state.error&&e.sessionData.publishSessionMutationError(r,r.sessions.state.error)}async function X(e,t,n,r){if(n.some(e=>!e.sessionId))return e.sessionData.publishSessionMutationError(r,g(`common.refresh`)),`failed`;let i=await N(e,t,r);return i===`completed`?n.length>0?n.length===1?z(e,n[0],{category:t},r):B(e,n,{category:t},r):e.sessionData.isSessionMutationScopeCurrent(r)?(e.requestUpdate(),`completed`):`stale`:i}async function Z(e,t,n,r,i={},a={}){if(!e.sessionData.isSessionMutationScopeCurrent(r))return;let o=!!(n&&!e.knownSessionGroups().includes(n));if(n&&await N(e,n,r)!==`completed`)return;let s=a.resolveSession?a.resolveSession():t;if(!s){u({message:g(o?`sessionsView.newGroupMoveSkipped`:`common.refresh`)});return}((s.category??null)!==n||i.pinned!==void 0)&&await z(e,s,{category:n,...i},r)}async function Q(e,t,n){if(!e.sessionData.isSessionMutationScopeCurrent(n))return;let r=o(t.key)?.agentId??n.selectedAgentId,i={parentSessionKey:t.key,fork:!0,...t.gatewayHasActiveRun??t.hasActiveRun?{forkFrom:`last-completed`}:{},agentId:r};if(O(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??g(`newSession.createFailed`))}catch(t){e.sessionData.publishSessionMutationError(n,t)}}async function te(e,t,n){let r=t.cloudWorkerStopAction;if(!r||r.blocksActiveRun&&t.hasActiveRun)return;let i=await y({message:g(`sessionsView.stopCloudWorkerConfirm`,{session:t.label}),confirmLabel:g(`sessionsView.stopCloudWorkerConfirmAction`),danger:!0,signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n)){u({message:g(`sessionsView.stopCloudWorkerStale`,{session:t.label})});return}if(i&&O(e,n,r))try{let r=o(t.key)?.agentId??n.selectedAgentId;if(await E(n.client,{key:t.key,agentId:r},n.context.placementStartup),!e.sessionData.isSessionMutationScopeCurrent(n))return;await n.sessions.refreshReplacement(r)}catch(t){e.sessionData.publishSessionMutationError(n,t)}}async function ne(e,t,n,r={}){let i=await y({message:g(`sessionsView.deleteSessionConfirm`,{session:t.label}),confirmLabel:g(`common.delete`),danger:!0,...r.offerSkip?{skipPreference:G(n)}:{},signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n)){u({message:g(`sessionsView.deleteSessionStale`,{session:t.label})});return}if(!i)return;let a=o(t.key)?.agentId??n.selectedAgentId,s={agentId:a,deleteTranscript:!0,...t.sessionId?{expectedSessionId:t.sessionId}:{},...t.archived===!0?{archivedOnly:!0}:{}};if(O(e,n,{method:`sessions.delete`,params:{key:t.key,...s}}))try{let r=await n.sessions.delete(t.key,s);if(!e.sessionData.isSessionMutationScopeCurrent(n)){r.worktreePreserved&&u({message:C([r.worktreePreserved])});return}if(e.sidebarSessionStatusFilter()!==`active`&&(await e.sessionData.refreshSidebarSessions(a),!e.sessionData.isSessionMutationScopeCurrent(n)))return;if(r.worktreePreserved){let t=r.worktreePreserved;if(!d(n.gateway.snapshot,{method:`worktrees.remove`,requiredScope:`operator.admin`}).allowed)window.alert(C([t]));else{let r=await y({message:T(t),confirmLabel:g(`common.remove`),danger:!0,signal:n.signal});if(!e.sessionData.isSessionMutationScopeCurrent(n)){u({message:C([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((()=>{f(),h(),c(),i(),w(),l(),D(),b(),M(),R()})))()}$();export{H as archiveSessionWithUndo,Z as assignSessionCategory,Y as assignSessionOwner,X as createSessionGroup,ne as deleteSession,F as deleteSessionGroup,K as deleteSessionsBatch,Q as forkSession,z as patchSession,B as patchSessions,J as renameSession,P as renameSessionGroup,L as reorderSidebarSection,q as runBatchSessionAction,te as stopCloudWorker,I as updateSessionGroupDefaults}; //# sourceMappingURL=session-organizer-operations.runtime-ESc5IOoL.js.map