openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 4.99 kB
JavaScript
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Do as t,Eo as n,Oo as r}from"./control-ui-core-Rwzhj6nO.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=w.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},w.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,t,r){let i=l(e,t);if(!t||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[n,r,s]=await Promise.all([t.request(`logbook.status`,{}),t.request(`logbook.days`,{}),t.request(`logbook.timeline`,{day:o})]);if(!c(e,t,i)||a!==e.loadGeneration||e.day!==o)return;if(e.status=n,e.days=r.days,!e.dayPinned&&n.today!==e.day){d(e,n.today);let r=await t.request(`logbook.timeline`,{day:n.today});if(!c(e,t,i)||a!==e.loadGeneration||e.day!==n.today)return;e.timeline=r}else e.timeline=s;e.error=null}catch(r){c(e,t,i)&&a===e.loadGeneration&&(e.error=n(r))}finally{let n=c(e,t,i)&&a===e.loadGeneration;e.loadingGeneration===a&&(e.loadingGeneration=null,e.loading=!1,n=!0),n&&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=w.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)},C))}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>=S){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,t,r){let i=l(e,t);if(!(!t||i===null||e.actionPending)){e.actionPending=!0,s(e);try{let n=await t.request(`logbook.capture.set`,{paused:r});c(e,t,i)&&(e.status=n)}catch(r){c(e,t,i)&&(e.error=n(r))}finally{c(e,t,i)&&(e.actionPending=!1,s(e))}}}async function y(e,r){let i=l(e,r);if(!(!r||i===null||e.actionPending)){e.actionPending=!0,s(e);try{let n=await r.request(`logbook.analyze.now`,{});c(e,r,i)&&!n.started&&n.reason&&(e.error=t(n.reason))}catch(t){c(e,r,i)&&(e.error=n(t))}finally{c(e,r,i)&&(e.actionPending=!1,s(e),m(e,r,{required:!0}))}}}async function b(e,t,r){let i=l(e,t);if(!t||i===null||e.standupLoading)return;e.standupLoading=!0,s(e);let a=e.day;try{let n=await t.request(`logbook.standup`,{day:a,refresh:r});c(e,t,i)&&e.day===a&&(e.standup=n)}catch(r){c(e,t,i)&&(e.error=n(r))}finally{c(e,t,i)&&(e.standupLoading=!1,s(e))}}async function x(e,t){let r=e.askQuestion.trim(),i=l(e,t);if(!t||i===null||e.askLoading||r.length===0)return;e.askLoading=!0,e.askAnswer=null,s(e);let a=e.day;try{let n=await t.request(`logbook.ask`,{day:a,question:r});c(e,t,i)&&e.day===a&&(e.askAnswer=n.answer)}catch(r){c(e,t,i)&&(e.error=n(r))}finally{c(e,t,i)&&(e.askLoading=!1,s(e))}}var S,C,w;function T(){return(T=e((()=>{r(),S=48,C=3e4,w=new WeakMap})))()}export{f as a,i as c,a as d,h as f,T as i,y as l,g as n,_ as o,o as r,b as s,x as t,v as u};
//# sourceMappingURL=logbook-controller-Cc6O3lSD.js.map