openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 4.83 kB
JavaScript
import{n as e,r as t}from"./rolldown-runtime-8BhlS34s.js";import{bu as n,xu as r,yu as i}from"./control-ui-core-CBJ5efDh.js";var a=t({askLogbook:()=>w,configureLogbookPolling:()=>v,getLogbookState:()=>c,loadLogbook:()=>p,loadLogbookFramePreview:()=>y,loadLogbookStandup:()=>C,localDayKey:()=>o,runLogbookAnalysisNow:()=>S,setLogbookCapturePaused:()=>x,shiftDay:()=>s,stopLogbookPolling:()=>_});function o(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 s(e,t){let n=new Date(`${e}T12:00:00`);return n.setDate(n.getDate()+t),o(n)}function c(e){let t=D.get(e);return t||(t={day:o(),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},D.set(e,t)),t}function l(e,t,n){return e.client===t&&e.clientGeneration===n}function u(e,t){return t&&e.client===t?e.clientGeneration:null}function d(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 f(e,t){e.day=t,e.timeline=null,e.standup=null,e.askAnswer=null,e.expandedCardIds=new Set}async function p(e,t,n){let r=u(e,t);if(!t||r===null)return;n?.day?(e.dayPinned=!0,n.day!==e.day&&f(e,n.day)):n?.today&&(e.dayPinned=!1);let a=++e.loadGeneration,o=()=>l(e,t,r)&&a===e.loadGeneration,s=e.day;n?.silent||(e.loadingGeneration=a,e.loading=!0,e.error=null,e.requestUpdate?.());try{let[n,r,i]=await Promise.all([t.request(`logbook.status`,{}),t.request(`logbook.days`,{}),t.request(`logbook.timeline`,{day:s})]);if(!o()||e.day!==s)return;if(e.status=n,e.days=r.days,!e.dayPinned&&n.today!==e.day){f(e,n.today);let r=await t.request(`logbook.timeline`,{day:n.today});if(!o()||e.day!==n.today)return;e.timeline=r}else e.timeline=i;e.error=null}catch(t){o()&&(e.error=i(t))}finally{let t=o();e.loadingGeneration===a&&(e.loadingGeneration=null,e.loading=!1,t=!0),t&&e.requestUpdate?.(),m(e)}}function m(e){if(!e.backgroundRefreshQueued||e.loading||e.backgroundRefresh)return;e.backgroundRefreshQueued=!1;let t=e.pollClient;t&&h(e,t,{required:!0})}function h(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=p(e,t,{silent:!0});return e.backgroundRefresh=r,r.finally(()=>{e.backgroundRefresh===r&&(e.backgroundRefresh=null),m(e)}),r}function g(e){e.pollTimer&&=(clearInterval(e.pollTimer),null),e.pollClient=null,e.backgroundRefreshQueued=!1}function _(e){let t=D.get(e);t&&g(t)}function v(e,t){if(!t){g(e),d(e,null);return}e.pollTimer&&e.pollClient===t||(e.pollTimer&&clearInterval(e.pollTimer),d(e,t),e.pollClient=t,e.pollTimer=setInterval(()=>{h(e,t)},E))}async function y(e,t,n){let r=u(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(!l(e,t,r))return;if(e.framePreviews.size>=T){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{l(e,t,r)&&e.framePreviewFailed.add(n)}finally{l(e,t,r)&&(e.frameLoads.delete(n),e.requestUpdate?.())}}}async function b(e,t,n,r,a){let o=u(e,t);if(!t||o===null||e[n])return;let s=()=>l(e,t,o);e[n]=!0;try{await r(t,s)}catch(t){s()&&(e.error=i(t))}finally{s()&&(e[n]=!1,e.requestUpdate?.(),a?.(t))}}function x(e,t,n){return b(e,t,`actionPending`,async(t,r)=>{e.requestUpdate?.();let i=await t.request(`logbook.capture.set`,{paused:n});r()&&(e.status=i)})}function S(e,t){return b(e,t,`actionPending`,async(t,r)=>{e.requestUpdate?.();let i=await t.request(`logbook.analyze.now`,{});r()&&!i.started&&i.reason&&(e.error=n(i.reason))},t=>void h(e,t,{required:!0}))}function C(e,t,n){return b(e,t,`standupLoading`,async(t,r)=>{e.requestUpdate?.();let i=e.day,a=await t.request(`logbook.standup`,{day:i,refresh:n});r()&&e.day===i&&(e.standup=a)})}async function w(e,t){let n=e.askQuestion.trim();if(n)return b(e,t,`askLoading`,async(t,r)=>{e.askAnswer=null,e.requestUpdate?.();let i=e.day,a=await t.request(`logbook.ask`,{day:i,question:n});r()&&e.day===i&&(e.askAnswer=a.answer)})}var T,E,D;function O(){return(O=e((()=>{r(),T=48,E=3e4,D=new WeakMap})))()}export{p as a,o as c,x as d,s as f,O as i,a as l,v as n,y as o,c as r,C as s,w as t,S as u};