openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 1.07 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Ji as t,Xi as n,du as r,pu as i,qi as a}from"./control-ui-core-BncvAZjR.js";import{n as o,r as s,s as c,t as l}from"./request-usage-snapshot-DoCj0VT1.js";function u(e){return n(e)?a(`usage`):r(e,`request failed`)}async function d(e,t,n){let{gateway:r,gatewaySnapshot:i,agentId:a,date:c}=n,l={...s(c),scope:`family`,timeZone:`local`,agentId:a},d={gateway:r,gatewaySnapshot:i,query:l,result:null,costSummary:null,providerUsage:{state:`pending`},loadedAtMs:null,error:null};if(i.phase!==`connected`||!i.client)return d;try{let n=r.snapshot;if(!t.shouldRun()||n.phase!==`connected`||n.client!==i.client||n.hello!==i.hello||e.agentSelection.state.scopeId!==l.agentId)return d;let a=await o(i.client,{...l,agentId:l.agentId??void 0},t.signal);return a.ok?{...d,...a.value,gatewaySnapshot:n,loadedAtMs:Date.now()}:{...d,gatewaySnapshot:n,providerUsage:a.error.providerUsage,error:u(a.error.cause)}}catch(e){return{...d,error:u(e)}}}function f(){return(f=e((()=>{i(),t(),c(),l()})))()}f();export{d as loadUsageRouteData};