export type GetApiRealtimeRunsRunIdEventsArgs = {run_id: string, 'Last-Event-ID'?: string | undefined, token?: string | undefined}; export type GetApiRealtimeRunsRunIdEventsOptions = {baseUrl: string, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stream a run's events * * GET /realtime/runs/{run_id}/events */ export const getApiRealtimeRunsRunIdEvents = async (args: GetApiRealtimeRunsRunIdEventsArgs, options: GetApiRealtimeRunsRunIdEventsOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/event-stream") if (args['Last-Event-ID'] != null) headers.set("Last-Event-ID", String(args['Last-Event-ID'])) if (args.token != null) query.append("token", String(args.token)) if (apiKeyAuth !== undefined) headers.set("X-Axilio-Api-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/realtime/runs/${encodeURIComponent(String(args.run_id))}/events${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };