export type GetApiV1RunsRunIdEventsArgs = {'Last-Event-ID'?: number | undefined, after?: number | undefined}; export type GetApiV1RunsRunIdEventsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stream run events (SSE) * * GET /v1/runs/{run_id}/events * * Also accepts auth: bearerAuth */ export const getApiV1RunsRunIdEvents = async (args: GetApiV1RunsRunIdEventsArgs, options?: GetApiV1RunsRunIdEventsOptions) => { const {baseUrl = "https://coasty.ai", fetch: fetchFn = fetch, apiKey} = 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.after != null) query.append("after", String(args.after)) if (apiKey !== undefined) headers.set("X-API-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/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() };