export type GetApiAgentRunsRunIdEventsStreamArgs = {run_id: string, after?: number | undefined, 'Last-Event-ID'?: string | undefined, principal_id?: string | undefined}; export type GetApiAgentRunsRunIdEventsStreamOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stream persisted agent run events * * GET /agent/runs/{run_id}/events/stream */ export const getApiAgentRunsRunIdEventsStream = async (args: GetApiAgentRunsRunIdEventsStreamArgs, options?: GetApiAgentRunsRunIdEventsStreamOptions) => { const {baseUrl = "https://developer.qaip.com/api/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/event-stream") if (args.after != null) query.append("after", String(args.after)) if (args['Last-Event-ID'] != null) headers.set("Last-Event-ID", String(args['Last-Event-ID'])) if (args.principal_id != null) query.append("principal_id", String(args.principal_id)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/agent/runs/${encodeURIComponent(String(args.run_id))}/events/stream${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() };