openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 4.11 kB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./control-ui-connection-D5QrEAFW.css","./control-ui-boot-shared-styles-BorAdMVO.css"])))=>i.map(i=>d[i]);
import{n as e,r as t}from"./rolldown-runtime-CNOWq4Kh.js";import{Fi as n,Qt as r,Xt as i,au as a,dc as o,et as s,fi as c,lu as l,tt as u,uc as d,uu as f,vi as p,wa as m,xa as h}from"./control-ui-connection-Bfj9beF_.js";import{Qo as g,ts as _}from"./control-ui-boot-shared-DFTSUQQ0.js";import{Ua as v,Wa as y,_a as b,ga as x,ha as S,ma as C,ya as w}from"./control-ui-boot-chat-DewxEbIm.js";var T=t({confirmChatGoalReplacement:()=>O,executeChatGoalOperation:()=>D});function E(e){let t=e instanceof s&&a(e.details)?e.details:null,n=t?.reason;if(typeof n==`string`&&(t?.code===`GOAL_OPERATION_REJECTED`&&A.has(n)||n.startsWith(`goal-`)&&A.has(n.slice(5))))return n}async function D(e,t,r,o,l,u){let{sessionKey:f,agentId:p,sessionId:h,signature:_,storageKey:v,storage:x,operations:S}=t,C=t.client;if(!o()||!l())return!1;let w=async t=>{let i=e.sessions,a=i.captureConnectionScope(),s=n(e,f);if(!a||!s.agentId)return!1;let u=()=>o()&&e.sessions===i&&i.isConnectionScopeCurrent(a)&&l()&&t===r,d;try{if(!u())return!1;let t=await i.reconcileMutation(p);if(!u())return!1;d=i.observeRow({key:s.sessionKey,agentId:s.agentId},()=>{},{onInvalidate:()=>{}});let n=d.captureReconcile(),r=await i.describe({key:f,...p?{agentId:p}:{}},{client:C,refresh:!0,timeoutMs:k});if(!u())return!1;let a=r.session;if(!a||!c(a.key,s.sessionKey)||h&&a.sessionId!==h)return!1;let o=n(a);return!u()||o.status!==`current`||!o.row||h&&o.row.sessionId!==h?!1:t.status===`refreshed`||(t.status===`failed`&&y(e,t.error),!1)}finally{d?.dispose()}};if(r?.retired){let t=JSON.stringify(r.retired);try{return!await w(r)||x&&x.getItem(v)!==t?!1:(x?.removeItem(v),S.delete(_),y(e,null),!0)}catch(t){return o()&&y(e,i(t)),!1}}let T=r.params;if(!T)return!1;let D=e=>{let t=JSON.parse(x?.getItem(v)??`null`);a(t)&&t.operationId===T.operationId&&(e?x?.setItem(v,JSON.stringify(e)):x?.removeItem(v))};try{let t=()=>C.request(`action`in T?`sessions.goal.update`:`sessions.goal.clear`,T,{timeoutMs:k}),n;try{n=await t()}catch(e){if(!(`action`in T&&T.action===`resume`)||!o()||E(e)!==void 0||!(e instanceof d||e instanceof s&&e.code===`UNAVAILABLE`)||(await new Promise(e=>{setTimeout(e,1e3)}),!o()||!l()||g(T.issuedAtMs)))throw e;n=await t()}if(n.replayed&&!await w(r))return!1;S.delete(_);try{D()}catch{}if(o()){if(n.replayed)return!0;let t=e.sessionsResult?.sessions.find(e=>c(e.key,f)&&e.sessionId===h&&(e.agentId===void 0||e.agentId===u));t?.goal?.id===T.goalId&&(!n.goal||n.goal.updatedAt>=t.goal.updatedAt)&&(u&&h&&e.sessions.patchRowLocal(t.key,{goal:n.goal},{agentId:u,sessionId:h}),n.status===`started`&&n.runId&&(b(e,n.runId,Date.now()),S.recordStartedExecution(T.goalId,n.runId,o)))}return!0}catch(t){let n=E(t),a=n!==void 0;if(a){let e=n===`expired`||n===`goal-expired`?`expired`:void 0;e?S.expire(r):S.delete(_);try{D(e)}catch{}}return o()&&y(e,a?i(t):`${m(`chat.goals.outcomeUnknown`)} ${i(t)}`),!1}}async function O(e,t,n){let{goalId:r,previousObjective:i,status:a,updatedAt:o,expectedRunId:s,scopeIsCurrent:c,currentGoal:u,unavailable:d,runId:f}=n,{showConfirmDialog:p}=await l(async()=>{let{showConfirmDialog:e}=await import(`./deferred-ui-support-D-VedBtc.js`).then(e=>(e.mr(),e.pr));return{showConfirmDialog:e}},__vite__mapDeps([0,1]),import.meta.url);if(!c()||!await p({title:m(`chat.goals.replaceTitle`),message:m(s?`chat.goals.replaceRunningMessage`:`chat.goals.replaceMessage`),details:t,confirmLabel:m(`chat.goals.replace`)})||!c())return!1;let h=u();if(h?.id!==r||h.objective!==i||h.status!==a||h.updatedAt!==o)return x(e,m(`chat.goals.goalChanged`));let g=d();return g?x(e,g):f()===s?await S(e,s?{action:`replace`,goalId:r,objective:t,expectedRunId:s,expectedGoalUpdatedAt:o}:{action:`edit`,goalId:r,objective:t}):x(e,m(`chat.goals.goalChanged`))}var k,A;function j(){return(j=e((()=>{o(),u(),h(),_(),r(),p(),C(),v(),w(),f(),k=3e4,A=new Set([`expired`,`operation-conflict`,`session-rebound`,`session-busy`,`goal-rebound`,`capacity`,`invalid`])})))()}export{j as n,T as t};