← Public packages
@cameronpak/box
Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.
src/list-events.ts
39 lines · 1.0 KB · TypeScriptimport { assertBoxId, boxRequest, failure, type Result } from './client.ts'
import type { BoxEvent, PageInfo } from './types.ts'
export type ListEventsInput = {
boxId: string
/** Maximum items to return, 1 to 200. Defaults to 100. */
limit?: number
cursor?: string | null
sort?: 'asc' | 'desc'
/** Comma-separated event type filter, for example "prompt,response". */
type?: string
}
export type ListEventsOutput = {
id: string
events: Array<BoxEvent>
pageInfo?: PageInfo
}
/**
* Read work and lifecycle events for a box. Long-poll with sort ascending plus a
* cursor to follow a prompt run. Event shapes are extensible; branch on type.
*/
export default async function listEvents(
input: ListEventsInput,
): Promise<Result<ListEventsOutput>> {
const invalid = assertBoxId(input?.boxId)
if (invalid) return failure<ListEventsOutput>(invalid)
return boxRequest<ListEventsOutput>({
path: '/boxes/' + input.boxId + '/events',
query: {
limit: input.limit,
cursor: input.cursor,
sort: input.sort,
type: input.type,
},
})
}