export type GetApiV1ResearchTaskIdStreamArgs = {task_id: string, from_id?: number | undefined}; export type GetApiV1ResearchTaskIdStreamOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stream progress for a background research task * * GET /v1/research/{task_id}/stream */ export const getApiV1ResearchTaskIdStream = async (args: GetApiV1ResearchTaskIdStreamArgs, options?: GetApiV1ResearchTaskIdStreamOptions) => { const {baseUrl = "https://api.you.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/event-stream") if (args.from_id != null) query.append("from_id", String(args.from_id)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/research/${encodeURIComponent(String(args.task_id))}/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() };