UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 4.11 kB
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./_1____________________________.css","./_0____________________________________.css"])))=>i.map(i=>d[i]); import{n as e,r as t}from"./rolldown-runtime-CNOWq4Kh.js";import{$u as n,Dl as r,Ju as i,Ko as a,Ol as o,Qo as s,Qu as c,hs as l,li as u,oi as d,v as f,y as p}from"./_4____________________________.js";import{AN as m,EN as h,Fs as g,Ms as _}from"./_2_____________________________.js";import{Li as v,Ri as y,ci as b,fi as x,li as S,si as C,ui as w}from"./control-ui-boot-chat-CqvkfPXD.js";var T=t({confirmChatGoalReplacement:()=>O,executeChatGoalOperation:()=>D});function E(e){let t=e instanceof f&&i(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,n,o,s,c){let{sessionKey:d,agentId:p,sessionId:m,signature:g,storageKey:v,storage:b,operations:x}=t,S=t.client;if(!o()||!s())return!1;let C=async t=>{let r=e.sessions,i=r.captureConnectionScope(),c=l(e,d);if(!i||!c.agentId)return!1;let u=()=>o()&&e.sessions===r&&r.isConnectionScopeCurrent(i)&&s()&&t===n,f;try{if(!u())return!1;let t=await r.reconcileMutation(p);if(!u())return!1;f=r.observeRow({key:c.sessionKey,agentId:c.agentId},()=>{},{onInvalidate:()=>{}});let n=f.captureReconcile(),i=await r.describe({key:d,...p?{agentId:p}:{}},{client:S,refresh:!0,timeoutMs:k});if(!u())return!1;let o=i.session;if(!o||!a(o.key,c.sessionKey)||m&&o.sessionId!==m)return!1;let s=n(o);return!u()||s.status!==`current`||!s.row||m&&s.row.sessionId!==m?!1:t.status===`refreshed`||(t.status===`failed`&&y(e,t.error),!1)}finally{f?.dispose()}};if(n?.retired){let t=JSON.stringify(n.retired);try{return!await C(n)||b&&b.getItem(v)!==t?!1:(b?.removeItem(v),x.delete(g),y(e,null),!0)}catch(t){return o()&&y(e,h(t)),!1}}let T=n.params;if(!T)return!1;let D=e=>{let t=JSON.parse(b?.getItem(v)??`null`);i(t)&&t.operationId===T.operationId&&(e?b?.setItem(v,JSON.stringify(e)):b?.removeItem(v))};try{let t=()=>S.request(`action`in T?`sessions.goal.update`:`sessions.goal.clear`,T,{timeoutMs:k}),i;try{i=await t()}catch(e){if(!(`action`in T&&T.action===`resume`)||!o()||E(e)!==void 0||!(e instanceof r||e instanceof f&&e.code===`UNAVAILABLE`)||(await new Promise(e=>{setTimeout(e,1e3)}),!o()||!s()||_(T.issuedAtMs)))throw e;i=await t()}if(i.replayed&&!await C(n))return!1;x.delete(g);try{D()}catch{}if(o()){if(i.replayed)return!0;let t=e.sessionsResult?.sessions.find(e=>a(e.key,d)&&e.sessionId===m&&(e.agentId===void 0||e.agentId===c));t?.goal?.id===T.goalId&&(!i.goal||i.goal.updatedAt>=t.goal.updatedAt)&&(c&&m&&e.sessions.patchRowLocal(t.key,{goal:i.goal},{agentId:c,sessionId:m}),i.status===`started`&&i.runId&&(w(e,i.runId,Date.now()),x.recordStartedExecution(T.goalId,i.runId,o)))}return!0}catch(t){let r=E(t),i=r!==void 0;if(i){let e=r===`expired`||r===`goal-expired`?`expired`:void 0;e?x.expire(n):x.delete(g);try{D(e)}catch{}}return o()&&y(e,i?h(t):`${u(`chat.goals.outcomeUnknown`)} ${h(t)}`),!1}}async function O(e,t,n){let{goalId:r,previousObjective:i,status:a,updatedAt:o,expectedRunId:s,scopeIsCurrent:l,currentGoal:d,unavailable:f,runId:p}=n,{showConfirmDialog:m}=await c(async()=>{let{showConfirmDialog:e}=await import(`./deferred-ui-support-DZEPWjAk.js`).then(e=>(e.Bi(),e.zi));return{showConfirmDialog:e}},__vite__mapDeps([0,1]),import.meta.url);if(!l()||!await m({title:u(`chat.goals.replaceTitle`),message:u(s?`chat.goals.replaceRunningMessage`:`chat.goals.replaceMessage`),details:t,confirmLabel:u(`chat.goals.replace`)})||!l())return!1;let h=d();if(h?.id!==r||h.objective!==i||h.status!==a||h.updatedAt!==o)return S(e,u(`chat.goals.goalChanged`));let g=f();return g?S(e,g):p()===s?await b(e,s?{action:`replace`,goalId:r,objective:t,expectedRunId:s,expectedGoalUpdatedAt:o}:{action:`edit`,goalId:r,objective:t}):S(e,u(`chat.goals.goalChanged`))}var k,A;function j(){return(j=e((()=>{o(),p(),d(),g(),m(),s(),C(),v(),x(),n(),k=3e4,A=new Set([`expired`,`operation-conflict`,`session-rebound`,`session-busy`,`goal-rebound`,`capacity`,`invalid`])})))()}export{j as n,T as t};