openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 4.63 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Gl as t,Kl as n,ql as r}from"./control-ui-core-3P365fbR.js";function i(e=new Date){let t=String(e.getMonth()+1).padStart(2,`0`),n=String(e.getDate()).padStart(2,`0`);return`${e.getFullYear()}-${t}-${n}`}function a(e,t){let n=new Date(`${e}T12:00:00`);return n.setDate(n.getDate()+t),i(n)}function o(e){let t=T.get(e);return t||(t={day:i(),dayPinned:!1,status:null,days:[],timeline:null,loading:!1,error:null,expandedCardIds:new Set,framePreviews:new Map,frameLoads:new Set,framePreviewFailed:new Set,standup:null,standupLoading:!1,askQuestion:``,askAnswer:null,askLoading:!1,actionPending:!1,client:null,clientGeneration:0,loadGeneration:0,loadingGeneration:null,backgroundRefresh:null,backgroundRefreshQueued:!1,pollTimer:null,pollClient:null,requestUpdate:null},T.set(e,t)),t}function s(e){e.requestUpdate?.()}function c(e,t,n){return e.client===t&&e.clientGeneration===n}function l(e,t){return t&&e.client===t?e.clientGeneration:null}function u(e,t){e.client!==t&&(e.client=t,e.clientGeneration+=1,e.loadGeneration+=1,e.loadingGeneration=null,e.loading=!1,e.backgroundRefresh=null,e.backgroundRefreshQueued=!1,e.actionPending=!1,e.standupLoading=!1,e.askLoading=!1,e.frameLoads=new Set)}function d(e,t){e.day=t,e.timeline=null,e.standup=null,e.askAnswer=null,e.expandedCardIds=new Set}async function f(e,n,r){let i=l(e,n);if(!n||i===null)return;r?.day?(e.dayPinned=!0,r.day!==e.day&&d(e,r.day)):r?.today&&(e.dayPinned=!1);let a=++e.loadGeneration,o=e.day;r?.silent||(e.loadingGeneration=a,e.loading=!0,e.error=null,s(e));try{let[t,r,s]=await Promise.all([n.request(`logbook.status`,{}),n.request(`logbook.days`,{}),n.request(`logbook.timeline`,{day:o})]);if(!c(e,n,i)||a!==e.loadGeneration||e.day!==o)return;if(e.status=t,e.days=r.days,!e.dayPinned&&t.today!==e.day){d(e,t.today);let r=await n.request(`logbook.timeline`,{day:t.today});if(!c(e,n,i)||a!==e.loadGeneration||e.day!==t.today)return;e.timeline=r}else e.timeline=s;e.error=null}catch(r){c(e,n,i)&&a===e.loadGeneration&&(e.error=t(r))}finally{let t=c(e,n,i)&&a===e.loadGeneration;e.loadingGeneration===a&&(e.loadingGeneration=null,e.loading=!1,t=!0),t&&s(e),p(e)}}function p(e){if(!e.backgroundRefreshQueued||e.loading||e.backgroundRefresh)return;e.backgroundRefreshQueued=!1;let t=e.pollClient;t&&m(e,t,{required:!0})}function m(e,t,n){if(e.pollClient!==t)return Promise.resolve();if(e.loading||e.backgroundRefresh)return n?.required&&(e.backgroundRefreshQueued=!0),e.backgroundRefresh??Promise.resolve();let r=f(e,t,{silent:!0});return e.backgroundRefresh=r,r.finally(()=>{e.backgroundRefresh===r&&(e.backgroundRefresh=null),p(e)}),r}function h(e){let t=T.get(e);t?.pollTimer&&(clearInterval(t.pollTimer),t.pollTimer=null),t&&(t.pollClient=null,t.backgroundRefreshQueued=!1)}function g(e,t,n){if(!n||!t){e.pollTimer&&=(clearInterval(e.pollTimer),null),e.pollClient=null,e.backgroundRefreshQueued=!1,u(e,null);return}e.pollTimer&&e.pollClient===t||(e.pollTimer&&clearInterval(e.pollTimer),u(e,t),e.pollClient=t,e.pollTimer=setInterval(()=>{m(e,t)},w))}async function _(e,t,n){let r=l(e,t);if(!(!t||r===null||e.framePreviews.has(n)||e.frameLoads.has(n)||e.framePreviewFailed.has(n))){e.frameLoads.add(n);try{let i=await t.request(`logbook.frame`,{frameId:n});if(!c(e,t,r))return;if(e.framePreviews.size>=C){let t=e.framePreviews.keys().next().value;t!==void 0&&e.framePreviews.delete(t)}e.framePreviews.set(n,`data:image/${i.format};base64,${i.base64}`)}catch{c(e,t,r)&&e.framePreviewFailed.add(n)}finally{c(e,t,r)&&(e.frameLoads.delete(n),s(e))}}}async function v(e,n,r,i,a){let o=l(e,n);if(!n||o===null||e[r])return;let u=()=>c(e,n,o);e[r]=!0;try{await i(n,u)}catch(n){u()&&(e.error=t(n))}finally{u()&&(e[r]=!1,s(e),a?.(n))}}function y(e,t,n){return v(e,t,`actionPending`,async(t,r)=>{s(e);let i=await t.request(`logbook.capture.set`,{paused:n});r()&&(e.status=i)})}function b(e,t){return v(e,t,`actionPending`,async(t,r)=>{s(e);let i=await t.request(`logbook.analyze.now`,{});r()&&!i.started&&i.reason&&(e.error=n(i.reason))},t=>void m(e,t,{required:!0}))}function x(e,t,n){return v(e,t,`standupLoading`,async(t,r)=>{s(e);let i=e.day,a=await t.request(`logbook.standup`,{day:i,refresh:n});r()&&e.day===i&&(e.standup=a)})}async function S(e,t){let n=e.askQuestion.trim();if(n)return v(e,t,`askLoading`,async(t,r)=>{e.askAnswer=null,s(e);let i=e.day,a=await t.request(`logbook.ask`,{day:i,question:n});r()&&e.day===i&&(e.askAnswer=a.answer)})}var C,w,T;function E(){return(E=e((()=>{r(),C=48,w=3e4,T=new WeakMap})))()}export{f as a,i as c,a as d,h as f,E as i,b as l,g as n,_ as o,o as r,x as s,S as t,y as u};