openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 4.91 kB
JavaScript
import{n as e,r as t}from"./rolldown-runtime-8BhlS34s.js";import{du as n,fu as r,pu as i}from"./control-ui-core-BncvAZjR.js";var a=t({askLogbook:()=>w,configureLogbookPolling:()=>v,getLogbookState:()=>c,loadLogbook:()=>m,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){e.requestUpdate?.()}function u(e,t,n){return e.client===t&&e.clientGeneration===n}function d(e,t){return t&&e.client===t?e.clientGeneration:null}function f(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 p(e,t){e.day=t,e.timeline=null,e.standup=null,e.askAnswer=null,e.expandedCardIds=new Set}async function m(e,t,r){let i=d(e,t);if(!t||i===null)return;r?.day?(e.dayPinned=!0,r.day!==e.day&&p(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,l(e));try{let[n,r,s]=await Promise.all([t.request(`logbook.status`,{}),t.request(`logbook.days`,{}),t.request(`logbook.timeline`,{day:o})]);if(!u(e,t,i)||a!==e.loadGeneration||e.day!==o)return;if(e.status=n,e.days=r.days,!e.dayPinned&&n.today!==e.day){p(e,n.today);let r=await t.request(`logbook.timeline`,{day:n.today});if(!u(e,t,i)||a!==e.loadGeneration||e.day!==n.today)return;e.timeline=r}else e.timeline=s;e.error=null}catch(r){u(e,t,i)&&a===e.loadGeneration&&(e.error=n(r))}finally{let n=u(e,t,i)&&a===e.loadGeneration;e.loadingGeneration===a&&(e.loadingGeneration=null,e.loading=!1,n=!0),n&&l(e),h(e)}}function h(e){if(!e.backgroundRefreshQueued||e.loading||e.backgroundRefresh)return;e.backgroundRefreshQueued=!1;let t=e.pollClient;t&&g(e,t,{required:!0})}function g(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=m(e,t,{silent:!0});return e.backgroundRefresh=r,r.finally(()=>{e.backgroundRefresh===r&&(e.backgroundRefresh=null),h(e)}),r}function _(e){let t=D.get(e);t?.pollTimer&&(clearInterval(t.pollTimer),t.pollTimer=null),t&&(t.pollClient=null,t.backgroundRefreshQueued=!1)}function v(e,t,n){if(!n||!t){e.pollTimer&&=(clearInterval(e.pollTimer),null),e.pollClient=null,e.backgroundRefreshQueued=!1,f(e,null);return}e.pollTimer&&e.pollClient===t||(e.pollTimer&&clearInterval(e.pollTimer),f(e,t),e.pollClient=t,e.pollTimer=setInterval(()=>{g(e,t)},E))}async function y(e,t,n){let r=d(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(!u(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{u(e,t,r)&&e.framePreviewFailed.add(n)}finally{u(e,t,r)&&(e.frameLoads.delete(n),l(e))}}}async function b(e,t,r,i,a){let o=d(e,t);if(!t||o===null||e[r])return;let s=()=>u(e,t,o);e[r]=!0;try{await i(t,s)}catch(t){s()&&(e.error=n(t))}finally{s()&&(e[r]=!1,l(e),a?.(t))}}function x(e,t,n){return b(e,t,`actionPending`,async(t,r)=>{l(e);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,n)=>{l(e);let i=await t.request(`logbook.analyze.now`,{});n()&&!i.started&&i.reason&&(e.error=r(i.reason))},t=>void g(e,t,{required:!0}))}function C(e,t,n){return b(e,t,`standupLoading`,async(t,r)=>{l(e);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,l(e);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((()=>{i(),T=48,E=3e4,D=new WeakMap})))()}export{m 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};