1212import { env } from "$env/dynamic/public" ;
1313
1414import type {
15+ AttentionItem ,
1516 ApiError ,
1617 BoxUpdateItem ,
1718 BoxUpdateRaw ,
@@ -22,6 +23,7 @@ import type {
2223 DeliveryItem ,
2324 ExecutorItem ,
2425 HeartbeatItem ,
26+ LeaseItem ,
2527 EdgeRegistryItem ,
2628 EdgeSessionItem ,
2729 Me ,
@@ -30,6 +32,7 @@ import type {
3032 QueryResult ,
3133 StructuredQuery ,
3234 SubscriptionItem ,
35+ TaskItem ,
3336} from "./types" ;
3437
3538export type DataMode = "mock" | "live" ;
@@ -131,6 +134,40 @@ export async function readHeartbeats(
131134 } ) ;
132135 return json < ReadEnvelope < HeartbeatItem > > ( res ) ;
133136}
137+ export async function readTasks ( fetchFn : typeof fetch = fetch ) : Promise < ReadEnvelope < TaskItem > > {
138+ let cursor : string | null = null ;
139+ let first : ReadEnvelope < TaskItem > | null = null ;
140+ const items : TaskItem [ ] = [ ] ;
141+ do {
142+ // Cursor pagination is sequential: each request depends on the previous cursor.
143+ // oxlint-disable-next-line no-await-in-loop
144+ const res : Response = await fetchFn (
145+ `${ base ( ) } /tasks?limit=250${ cursor ? `&cursor=${ encodeURIComponent ( cursor ) } ` : "" } ` ,
146+ {
147+ headers : { accept : "application/json" } ,
148+ credentials : "include" ,
149+ } ,
150+ ) ;
151+ // oxlint-disable-next-line no-await-in-loop
152+ const page : ReadEnvelope < TaskItem > = await json < ReadEnvelope < TaskItem > > ( res ) ;
153+ first ??= page ;
154+ items . push ( ...page . items ) ;
155+ cursor = page . next_cursor ;
156+ } while ( cursor ) ;
157+ return {
158+ ...( first as ReadEnvelope < TaskItem > ) ,
159+ items,
160+ next_cursor : null ,
161+ total : first ?. total ?? items . length ,
162+ } ;
163+ }
164+ export async function readLeases ( fetchFn : typeof fetch = fetch ) : Promise < ReadEnvelope < LeaseItem > > {
165+ const res = await fetchFn ( `${ base ( ) } /leases?limit=1000` , {
166+ headers : { accept : "application/json" } ,
167+ credentials : "include" ,
168+ } ) ;
169+ return json < ReadEnvelope < LeaseItem > > ( res ) ;
170+ }
134171
135172/** POST /api/v1/query — scope-filtered structured statistics query, run as the caller. */
136173export async function runQuery (
@@ -212,6 +249,15 @@ export async function readCards(fetchFn: typeof fetch = fetch): Promise<ReadEnve
212249 } ) ;
213250 return json < ReadEnvelope < CardItem > > ( res ) ;
214251}
252+ export async function readAttention (
253+ fetchFn : typeof fetch = fetch ,
254+ ) : Promise < ReadEnvelope < AttentionItem > > {
255+ const res = await fetchFn ( `${ base ( ) } /attention?limit=1000` , {
256+ headers : { accept : "application/json" } ,
257+ credentials : "include" ,
258+ } ) ;
259+ return json < ReadEnvelope < AttentionItem > > ( res ) ;
260+ }
215261export async function readHealth ( fetchFn : typeof fetch = fetch ) : Promise < ConsoleHealth > {
216262 const res = await fetchFn ( `${ base ( ) } /health` , { headers : { accept : "application/json" } } ) ;
217263 return json < ConsoleHealth > ( res ) ;
0 commit comments