openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.59 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";var t,n,r;function i(){return(i=e((()=>{t=3e5,n=3,r=class{constructor(e){this.options=e,this.lastLoadedAtMs=null,this.pendingAutomaticRefresh=!1,this.publicationPending=!1,this.reloadPending=!1,this.retryTimer=null,this.retryInFlight=null,this.pendingIncomplete=!1,this.retryAttempts=0,this.retryCycle=0,this.exhaustionReported=!1}get incompleteUsageExhausted(){return this.exhaustionReported}setLastLoadedAtMs(e,t){this.applyLoadState(e,t?.incomplete===!0,t?.connection)}markProviderUsage(e,t,n){let r=e?.ok===!1||e?.ok===!0&&e.value.refreshing===!0;this.applyLoadState(t,r,n)}resetPayload(){this.applyLoadState(null,!1),this.reloadPending=!1,this.publicationPending=!1}dispose(){this.resetRetryCycle()}applyLoadState(e,t,n){n!==this.connection&&(this.connection=n,this.resetRetryCycle()),t?this.retryInFlight===null?this.retryTimer===null&&this.armRetry():this.pendingIncomplete=!0:this.resetRetryCycle(),this.lastLoadedAtMs=t?null:e}armRetry(){if(this.retryAttempts>=n){this.exhaustionReported||(this.exhaustionReported=!0,this.options.onIncompleteUsageExhausted?.());return}this.retryAttempts+=1,this.pendingIncomplete=!1;let e=this.retryCycle;this.retryTimer=window.setTimeout(()=>{this.retryTimer=null;let t=this.requestAndWait(`poll`).catch(()=>void 0);this.retryInFlight=t,t.finally(()=>{this.retryCycle===e&&this.retryInFlight===t&&(this.retryInFlight=null,this.pendingIncomplete&&(this.pendingIncomplete=!1,this.armRetry()))})},5e3*2**(this.retryAttempts-1))}resetRetryCycle(){this.retryCycle+=1,this.retryAttempts=0,this.pendingIncomplete=!1,this.retryInFlight=null,this.exhaustionReported=!1,this.retryTimer!==null&&(window.clearTimeout(this.retryTimer),this.retryTimer=null)}interrupt(){this.reloadPending||=this.options.isLoading()}markLoadDeferred(){this.reloadPending=!0}beginLoad(){this.reloadPending=!1}request(e){this.requestAndWait(e)}async requestAndWait(e){if(e===`publication`&&(this.publicationPending=!0,this.reloadPending=!0),this.options.isLoading()&&e!==`manual`){this.pendingAutomaticRefresh=!0;return}this.pendingAutomaticRefresh=!1,!(e!==`manual`&&(document.visibilityState!==`visible`||!document.hasFocus()||!this.reloadPending&&this.lastLoadedAtMs!==null&&Date.now()-this.lastLoadedAtMs<t))&&((e===`manual`||e!==`poll`&&!this.publicationPending)&&this.resetRetryCycle(),this.publicationPending=!1,await this.options.reload(e))}flushPending(){this.pendingAutomaticRefresh&&(this.pendingAutomaticRefresh=!1,this.request(`focus`))}}})))()}function a(){return(a=e((()=>{})))()}export{r as n,i as r,a as t};