export type GetApiWorkflowIdRunsRidHistoryStreamArgs = {id: string, rid: string, includePayloads?: boolean | undefined, lastEventId?: number | undefined}; export type GetApiWorkflowIdRunsRidHistoryStreamOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stream pinned-run workflow history events via Server-Sent Events * * GET /workflow/{id}/runs/{rid}/history/stream */ export const getApiWorkflowIdRunsRidHistoryStream = async (args: GetApiWorkflowIdRunsRidHistoryStreamArgs, options?: GetApiWorkflowIdRunsRidHistoryStreamOptions) => { const {baseUrl = "http://localhost:3001", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/event-stream") if (args.includePayloads != null) query.append("includePayloads", String(args.includePayloads)) if (args.lastEventId != null) query.append("lastEventId", String(args.lastEventId)) const url = `${baseUrl.replace(/\/+$/, '')}/workflow/${encodeURIComponent(String(args.id))}/runs/${encodeURIComponent(String(args.rid))}/history/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() };