@copilotkit/react-native 2.0.0-rc.5 → 2.0.0-rc.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +334 -2
  2. package/USAGE.md +382 -21
  3. package/dist/CopilotKitProvider-CBVQLdzn.d.cts +77 -0
  4. package/dist/{CopilotKitProvider-CE4bc6CP.mjs → CopilotKitProvider-CCBBonxr.mjs} +63 -43
  5. package/dist/CopilotKitProvider-CCBBonxr.mjs.map +1 -0
  6. package/dist/CopilotKitProvider-CtQg_0S-.d.mts +77 -0
  7. package/dist/{CopilotKitProvider-Byw3cqe2.cjs → CopilotKitProvider-QdcQrrSA.cjs} +69 -42
  8. package/dist/CopilotKitProvider-QdcQrrSA.cjs.map +1 -0
  9. package/dist/{Markdown-C_9Re36O.cjs → Markdown-DLopAh5W.cjs} +10 -10
  10. package/dist/Markdown-DLopAh5W.cjs.map +1 -0
  11. package/dist/{Markdown-JsYh7oSA.d.mts → Markdown-Du-b_Qpr.d.mts} +3 -3
  12. package/dist/{Markdown-1ips7myr.d.cts → Markdown-UXZdDjzs.d.cts} +3 -3
  13. package/dist/{Markdown-C6AsLHmd.mjs → Markdown-VxtPJ_yh.mjs} +4 -4
  14. package/dist/Markdown-VxtPJ_yh.mjs.map +1 -0
  15. package/dist/{MarkdownRendererContext-CAnuohIS.mjs → MarkdownRendererContext-EobUsERg.mjs} +1 -1
  16. package/dist/{MarkdownRendererContext-CAnuohIS.mjs.map → MarkdownRendererContext-EobUsERg.mjs.map} +1 -1
  17. package/dist/MarkdownRendererContext-cDEHvbw9.cjs +40 -0
  18. package/dist/{MarkdownRendererContext-BRNe808d.cjs.map → MarkdownRendererContext-cDEHvbw9.cjs.map} +1 -1
  19. package/dist/chunk-C0xms8kb.cjs +34 -0
  20. package/dist/components/index.cjs +78 -175
  21. package/dist/components/index.cjs.map +1 -1
  22. package/dist/components/index.d.cts +2 -2
  23. package/dist/components/index.d.mts +2 -2
  24. package/dist/components/index.mjs +76 -174
  25. package/dist/components/index.mjs.map +1 -1
  26. package/dist/generative-ui/index.cjs +612 -0
  27. package/dist/generative-ui/index.cjs.map +1 -0
  28. package/dist/generative-ui/index.d.cts +341 -0
  29. package/dist/generative-ui/index.d.mts +341 -0
  30. package/dist/generative-ui/index.mjs +549 -0
  31. package/dist/generative-ui/index.mjs.map +1 -0
  32. package/dist/headless.cjs +3 -2
  33. package/dist/headless.d.cts +3 -3
  34. package/dist/headless.d.mts +3 -3
  35. package/dist/headless.mjs +2 -2
  36. package/dist/index.cjs +132 -162
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts +37 -19
  39. package/dist/index.d.mts +37 -19
  40. package/dist/index.mjs +131 -162
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/polyfills/encoding.cjs +115 -5
  43. package/dist/polyfills/encoding.cjs.map +1 -1
  44. package/dist/polyfills/encoding.d.cts +31 -1
  45. package/dist/polyfills/encoding.d.mts +31 -1
  46. package/dist/polyfills/encoding.mjs +113 -6
  47. package/dist/polyfills/encoding.mjs.map +1 -1
  48. package/dist/polyfills/streams.cjs +1 -1
  49. package/dist/polyfills.cjs +218 -2
  50. package/dist/polyfills.cjs.map +1 -1
  51. package/dist/polyfills.mjs +217 -1
  52. package/dist/polyfills.mjs.map +1 -1
  53. package/package.json +51 -21
  54. package/project.json +6 -1
  55. package/scripts/__tests__/verify-polyfill-barrel.test.mjs +150 -0
  56. package/scripts/verify-polyfill-barrel.mjs +158 -11
  57. package/src/CopilotChat.tsx +114 -93
  58. package/src/CopilotKitProvider.tsx +101 -130
  59. package/src/CopilotPopup.tsx +2 -2
  60. package/src/CopilotSidebar.tsx +7 -5
  61. package/src/__mocks__/react-native.ts +31 -0
  62. package/src/__mocks__/test-copilotkit.tsx +9 -3
  63. package/src/__tests__/attachments-integration.test.tsx +15 -2
  64. package/src/__tests__/copilot-chat-agentid.test.tsx +15 -2
  65. package/src/__tests__/copilot-chat-attachments.test.tsx +15 -2
  66. package/src/__tests__/copilot-chat-configuration.test.tsx +82 -0
  67. package/src/__tests__/copilot-chat-threads.test.tsx +232 -0
  68. package/src/__tests__/copilot-popup.test.tsx +15 -2
  69. package/src/__tests__/copilot-sidebar.test.tsx +15 -2
  70. package/src/__tests__/copilotkit-alias-exports.test.ts +16 -0
  71. package/src/__tests__/copilotkit-provider.test.tsx +68 -73
  72. package/src/__tests__/generative-ui-harness.tsx +243 -0
  73. package/src/__tests__/generative-ui-provider-props.test-d.tsx +106 -0
  74. package/src/__tests__/generative-ui-rn-mock.tsx +54 -0
  75. package/src/__tests__/generative-ui-wiring.test.tsx +720 -0
  76. package/src/__tests__/generative-ui.test.tsx +1000 -0
  77. package/src/__tests__/headless-entry-surface.test.ts +979 -61
  78. package/src/__tests__/headless-integration.test.tsx +11 -1
  79. package/src/__tests__/use-attachments.test.ts +27 -2
  80. package/src/components/CopilotChat.tsx +106 -233
  81. package/src/components/CopilotModal.tsx +1 -1
  82. package/src/components/Markdown.tsx +4 -4
  83. package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +5 -1
  84. package/src/components/__tests__/CopilotChat.test.tsx +12 -4
  85. package/src/components/__tests__/CopilotChatInterrupt.test.tsx +208 -0
  86. package/src/components/__tests__/Markdown.code-alias.test.tsx +1 -1
  87. package/src/components/index.ts +6 -0
  88. package/src/components/messages/AssistantMessage.tsx +3 -3
  89. package/src/components/messages/TypingIndicator.tsx +4 -4
  90. package/src/generative-ui/GenerativeUIActivity.tsx +235 -0
  91. package/src/generative-ui/GenerativeUIProvider.tsx +171 -0
  92. package/src/generative-ui/GenerativeUISurface.tsx +303 -0
  93. package/src/generative-ui/host.tsx +138 -0
  94. package/src/generative-ui/index.ts +93 -0
  95. package/src/generative-ui/internal.ts +55 -0
  96. package/src/headless.ts +4 -0
  97. package/src/hooks/use-attachments.ts +95 -139
  98. package/src/index.ts +10 -4
  99. package/src/polyfills/__tests__/encoding-utf8.test.ts +112 -0
  100. package/src/polyfills/encoding.ts +160 -4
  101. package/src/types.d.ts +0 -13
  102. package/tsdown.config.ts +1 -0
  103. package/dist/CopilotKitProvider-BWjzCdHN.d.mts +0 -121
  104. package/dist/CopilotKitProvider-Btm10msB.d.cts +0 -121
  105. package/dist/CopilotKitProvider-Byw3cqe2.cjs.map +0 -1
  106. package/dist/CopilotKitProvider-CE4bc6CP.mjs.map +0 -1
  107. package/dist/Markdown-C6AsLHmd.mjs.map +0 -1
  108. package/dist/Markdown-C_9Re36O.cjs.map +0 -1
  109. package/dist/MarkdownRendererContext-BRNe808d.cjs +0 -72
  110. package/dist/streaming-fetch-Bm91EsRc.cjs +0 -225
  111. package/dist/streaming-fetch-Bm91EsRc.cjs.map +0 -1
  112. package/dist/streaming-fetch-Dm1oN4f2.mjs +0 -219
  113. package/dist/streaming-fetch-Dm1oN4f2.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"streaming-fetch-Bm91EsRc.cjs","names":[],"sources":["../src/streaming-fetch.ts"],"sourcesContent":["/**\n * Streaming fetch implementation for React Native.\n *\n * React Native's built-in fetch doesn't support response.body.getReader()\n * (ReadableStream). This replaces global.fetch with an XHR-based\n * implementation that streams chunks via ReadableStream, enabling\n * CopilotKit's SSE-based agent communication.\n *\n * If native fetch already supports ReadableStream bodies (newer RN / Hermes),\n * the replacement is skipped entirely.\n *\n * THREADING NOTE: In React Native, XHR callbacks (onprogress, onload, etc.)\n * may fire on a native networking thread. Pushing data into the ReadableStream\n * from that thread can trigger downstream React setState calls on the wrong\n * thread, causing iOS to kill the process with \"deleted thread with uncommitted\n * CATransaction\". All stream-mutating operations are therefore deferred via\n * setTimeout(fn, 0) to bounce back to the JS thread (main thread in Hermes).\n *\n * Call `installStreamingFetch()` once at app startup after polyfills.\n */\n\ndeclare const global: typeof globalThis;\n\n/** Subset of the Response interface implemented by the streaming fetch polyfill. */\ninterface StreamingFetchResponse {\n readonly ok: boolean;\n readonly status: number;\n readonly statusText: string;\n readonly url: string;\n readonly type: string;\n readonly redirected: boolean;\n readonly bodyUsed: boolean;\n readonly headers: Headers;\n readonly body: ReadableStream<Uint8Array>;\n json(): Promise<unknown>;\n text(): Promise<string>;\n arrayBuffer(): Promise<ArrayBuffer>;\n blob(): Promise<Blob>;\n clone(): never;\n formData(): Promise<never>;\n}\n\nfunction createAbortError(): DOMException {\n return new (global as any).DOMException(\n \"The operation was aborted.\",\n \"AbortError\",\n );\n}\n\nexport function installStreamingFetch(): void {\n // Skip if native fetch already supports ReadableStream body.\n // Newer React Native versions (Hermes) may support this natively.\n try {\n const testResponse = new Response(\"\");\n if (\n testResponse.body != null &&\n typeof testResponse.body.getReader === \"function\"\n ) {\n return;\n }\n } catch (e) {\n // Response constructor unavailable — expected in older RN environments.\n if (\n __DEV__ &&\n e instanceof Error &&\n !(e instanceof ReferenceError) &&\n !(e instanceof TypeError)\n ) {\n console.warn(\n \"[CopilotKit] Unexpected error during streaming fetch feature detection, \" +\n \"installing XHR-based polyfill:\",\n e,\n );\n }\n }\n\n const IDLE_TIMEOUT_MS = 60_000;\n const originalFetch = global.fetch;\n const TextEncoder = global.TextEncoder;\n\n const streamingFetch = function streamingFetch(\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> {\n // Extract defaults from Request object when input is a Request\n const request =\n typeof input !== \"string\" && !(input instanceof URL) ? input : null;\n let url: string;\n if (typeof input === \"string\") {\n url = input;\n } else if (input instanceof URL) {\n url = input.href;\n } else {\n url = (input as Request).url;\n }\n const method = init?.method || request?.method || \"GET\";\n const headers = init?.headers || (request ? request.headers : {});\n const body = (init?.body ?? request?.body) as string | null | undefined;\n const signal = init?.signal || request?.signal;\n\n return new Promise((resolve, reject) => {\n // Reject immediately if signal is already aborted (per fetch spec)\n if (signal?.aborted) {\n reject(createAbortError());\n return;\n }\n\n const xhr = new XMLHttpRequest();\n xhr.open(method, url);\n\n // Fail after 60s with no data, to avoid hanging on stalled mobile\n // connections (WiFi→cellular transitions, tunnels, serverless cold\n // starts). This is an idle timeout, not xhr.timeout: a total limit would\n // also cut a healthy stream that runs longer than a minute (#7951).\n // To cap the total time, callers can pass the signal of an AbortController\n // and abort it from a timer (React Native's polyfill has no AbortSignal.timeout()).\n let idleTimer: ReturnType<typeof setTimeout> | undefined;\n function resetIdleTimer() {\n clearTimeout(idleTimer);\n idleTimer = setTimeout(() => {\n fail(new TypeError(\"Network request timed out\"));\n xhr.abort();\n }, IDLE_TIMEOUT_MS);\n }\n\n let headerEntries: [string, string][];\n if (headers instanceof Headers) {\n headerEntries = Array.from(headers.entries());\n } else if (Array.isArray(headers)) {\n headerEntries = headers as [string, string][];\n } else {\n headerEntries = Object.entries(headers as Record<string, string>);\n }\n for (const [key, value] of headerEntries) {\n xhr.setRequestHeader(key, value as string);\n }\n\n xhr.responseType = \"text\";\n\n let streamController: ReadableStreamDefaultController<Uint8Array> | null =\n null;\n let lastIndex = 0;\n let streamClosed = false;\n let settled = false;\n const encoder = new TextEncoder();\n\n // Promise that resolves/rejects when XHR completes or fails\n let resolveFullText: (text: string) => void;\n let rejectFullText: (error: Error) => void;\n const fullTextPromise = new Promise<string>((res, rej) => {\n resolveFullText = res;\n rejectFullText = rej;\n });\n // Prevent unhandled rejection when error occurs but .text()/.json() is never called\n fullTextPromise.catch(() => {});\n\n function closeStream() {\n if (streamController && !streamClosed) {\n streamClosed = true;\n streamController.close();\n }\n }\n\n function errorStream(err: Error) {\n if (streamController && !streamClosed) {\n streamClosed = true;\n streamController.error(err);\n }\n }\n\n function flushChunks() {\n if (\n streamController &&\n !streamClosed &&\n xhr.responseText.length > lastIndex\n ) {\n const newData = xhr.responseText.slice(lastIndex);\n lastIndex = xhr.responseText.length;\n streamController.enqueue(encoder.encode(newData));\n }\n }\n\n /** Centralized error handler — errors the stream, rejects fullTextPromise,\n * and rejects the outer fetch promise if not yet settled. */\n function fail(err: Error) {\n clearTimeout(idleTimer);\n cleanupAbortListener();\n errorStream(err);\n rejectFullText(err);\n if (!settled) {\n settled = true;\n reject(err);\n }\n }\n\n const onAbort = () => {\n fail(createAbortError());\n xhr.abort();\n };\n\n if (signal) {\n signal.addEventListener(\"abort\", onAbort);\n }\n\n function cleanupAbortListener() {\n if (signal) {\n signal.removeEventListener(\"abort\", onAbort);\n }\n }\n\n const stream = new ReadableStream<Uint8Array>({\n start(controller) {\n streamController = controller;\n },\n cancel() {\n clearTimeout(idleTimer);\n xhr.abort();\n rejectFullText(createAbortError());\n },\n });\n\n // All XHR callbacks are wrapped with setTimeout(fn, 0) to ensure they\n // run on the JS thread. In React Native, XHR callbacks may fire on a\n // native networking thread; calling streamController.enqueue() there\n // triggers downstream React setState on the wrong thread, which causes\n // iOS to kill the process (\"deleted thread with uncommitted CATransaction\").\n // setTimeout(fn, 0) defers execution to the JS event loop (main thread\n // in Hermes) with negligible latency — streaming still feels real-time.\n\n xhr.onprogress = function () {\n resetIdleTimer();\n setTimeout(() => {\n try {\n flushChunks();\n } catch (err) {\n fail(err instanceof Error ? err : new Error(String(err)));\n xhr.abort();\n }\n }, 0);\n };\n\n xhr.onload = function () {\n clearTimeout(idleTimer);\n setTimeout(() => {\n cleanupAbortListener();\n try {\n flushChunks();\n } catch (err) {\n fail(err instanceof Error ? err : new Error(String(err)));\n return;\n }\n closeStream();\n resolveFullText(xhr.responseText);\n }, 0);\n };\n\n xhr.onerror = function () {\n setTimeout(() => {\n fail(new TypeError(\"Network request failed\"));\n }, 0);\n };\n\n xhr.ontimeout = function () {\n setTimeout(() => {\n fail(new TypeError(\"Network request timed out\"));\n }, 0);\n };\n\n // Resolve with Response once headers arrive.\n // Guard against status === 0 which XHR produces for CORS failures,\n // DNS errors, and mixed-content blocks — let onerror handle those.\n let resp: StreamingFetchResponse | null = null;\n xhr.onreadystatechange = function () {\n // Capture XHR state synchronously before deferring — XHR properties\n // may change between now and when setTimeout fires.\n const readyState = xhr.readyState;\n if (readyState < 4) resetIdleTimer();\n const xhrStatus = xhr.status;\n const xhrStatusText = xhr.statusText;\n const rawHeaders = xhr.getAllResponseHeaders() || \"\";\n\n setTimeout(() => {\n // Safety net: if XHR completed but we never resolved/rejected, fail explicitly.\n // This can happen when status === 0 and onerror doesn't fire (some RN networking impls).\n if (readyState === 4 && !settled && !resp) {\n fail(\n new TypeError(\n `Network request to ${url} completed with status ${xhrStatus} but no response was produced. ` +\n `This may indicate a CORS failure, DNS error, or React Native networking issue.`,\n ),\n );\n return;\n }\n\n if (readyState >= 2 && !resp && xhrStatus !== 0) {\n const respHeaders: Record<string, string> = {};\n for (const line of rawHeaders.trim().split(\"\\r\\n\")) {\n const idx = line.indexOf(\": \");\n if (idx > 0) {\n respHeaders[line.slice(0, idx).toLowerCase()] = line.slice(\n idx + 2,\n );\n }\n }\n\n const responseHeaders = new Headers(respHeaders);\n\n let bodyUsed = false;\n\n resp = {\n // Duck-typed Response object (not a native Response instance)\n ok: xhrStatus >= 200 && xhrStatus < 300,\n status: xhrStatus,\n statusText: xhrStatusText,\n url: url,\n type: \"basic\",\n redirected: false,\n get bodyUsed() {\n return bodyUsed;\n },\n headers: responseHeaders,\n body: stream,\n json: async () => {\n bodyUsed = true;\n const text = await fullTextPromise;\n try {\n return JSON.parse(text);\n } catch (e) {\n throw new TypeError(\n `Failed to parse JSON from ${method} ${url} (status ${xhrStatus}): ${\n text.length > 200 ? text.slice(0, 200) + \"...\" : text\n }`,\n { cause: e },\n );\n }\n },\n text: async () => {\n bodyUsed = true;\n return fullTextPromise;\n },\n arrayBuffer: async () => {\n bodyUsed = true;\n return encoder.encode(await fullTextPromise).buffer;\n },\n blob: async () => {\n bodyUsed = true;\n const buf = encoder.encode(await fullTextPromise);\n if (typeof Blob !== \"undefined\") {\n return new Blob([buf], {\n type: responseHeaders.get(\"content-type\") || \"\",\n });\n }\n throw new Error(\n \"Blob is not available in this React Native environment.\",\n );\n },\n clone: () => {\n throw new Error(\n \"Response.clone() is not supported by the React Native streaming fetch polyfill.\",\n );\n },\n formData: async () => {\n throw new Error(\n \"Response.formData() is not supported by the React Native streaming fetch polyfill.\",\n );\n },\n };\n settled = true;\n // NOTE: abort listener is NOT removed here — the signal must remain\n // wired to xhr.abort() for mid-stream cancellation. Cleanup happens\n // in terminal handlers (onload, onerror, ontimeout) or onAbort itself.\n resolve(resp as unknown as Response);\n }\n }, 0);\n };\n\n resetIdleTimer();\n xhr.send(body ?? null);\n });\n };\n\n // Expose original fetch for opt-out (e.g., third-party libs that need native behavior)\n (streamingFetch as any).__originalFetch = originalFetch;\n global.fetch = streamingFetch as typeof fetch;\n}\n"],"mappings":";;AA0CA,SAAS,mBAAiC;AACxC,QAAO,IAAK,OAAe,aACzB,8BACA,aACD;;AAGH,SAAgB,wBAA8B;AAG5C,KAAI;EACF,MAAM,eAAe,IAAI,SAAS,GAAG;AACrC,MACE,aAAa,QAAQ,QACrB,OAAO,aAAa,KAAK,cAAc,WAEvC;UAEK,GAAG;AAEV,MACE,WACA,aAAa,SACb,EAAE,aAAa,mBACf,EAAE,aAAa,WAEf,SAAQ,KACN,0GAEA,EACD;;CAIL,MAAM,kBAAkB;CACxB,MAAM,gBAAgB,OAAO;CAC7B,MAAM,cAAc,OAAO;CAE3B,MAAM,iBAAiB,SAAS,eAC9B,OACA,MACmB;EAEnB,MAAM,UACJ,OAAO,UAAU,YAAY,EAAE,iBAAiB,OAAO,QAAQ;EACjE,IAAI;AACJ,MAAI,OAAO,UAAU,SACnB,OAAM;WACG,iBAAiB,IAC1B,OAAM,MAAM;MAEZ,OAAO,MAAkB;EAE3B,MAAM,SAAS,MAAM,UAAU,SAAS,UAAU;EAClD,MAAM,UAAU,MAAM,YAAY,UAAU,QAAQ,UAAU,EAAE;EAChE,MAAM,OAAQ,MAAM,QAAQ,SAAS;EACrC,MAAM,SAAS,MAAM,UAAU,SAAS;AAExC,SAAO,IAAI,SAAS,SAAS,WAAW;AAEtC,OAAI,QAAQ,SAAS;AACnB,WAAO,kBAAkB,CAAC;AAC1B;;GAGF,MAAM,MAAM,IAAI,gBAAgB;AAChC,OAAI,KAAK,QAAQ,IAAI;GAQrB,IAAI;GACJ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IJ,CAAC,eAAuB,kBAAkB;AAC1C,QAAO,QAAQ"}
@@ -1,219 +0,0 @@
1
- //#region src/streaming-fetch.ts
2
- function createAbortError() {
3
- return new global.DOMException("The operation was aborted.", "AbortError");
4
- }
5
- function installStreamingFetch() {
6
- try {
7
- const testResponse = new Response("");
8
- if (testResponse.body != null && typeof testResponse.body.getReader === "function") return;
9
- } catch (e) {
10
- if (__DEV__ && e instanceof Error && !(e instanceof ReferenceError) && !(e instanceof TypeError)) console.warn("[CopilotKit] Unexpected error during streaming fetch feature detection, installing XHR-based polyfill:", e);
11
- }
12
- const IDLE_TIMEOUT_MS = 6e4;
13
- const originalFetch = global.fetch;
14
- const TextEncoder = global.TextEncoder;
15
- const streamingFetch = function streamingFetch(input, init) {
16
- const request = typeof input !== "string" && !(input instanceof URL) ? input : null;
17
- let url;
18
- if (typeof input === "string") url = input;
19
- else if (input instanceof URL) url = input.href;
20
- else url = input.url;
21
- const method = init?.method || request?.method || "GET";
22
- const headers = init?.headers || (request ? request.headers : {});
23
- const body = init?.body ?? request?.body;
24
- const signal = init?.signal || request?.signal;
25
- return new Promise((resolve, reject) => {
26
- if (signal?.aborted) {
27
- reject(createAbortError());
28
- return;
29
- }
30
- const xhr = new XMLHttpRequest();
31
- xhr.open(method, url);
32
- let idleTimer;
33
- function resetIdleTimer() {
34
- clearTimeout(idleTimer);
35
- idleTimer = setTimeout(() => {
36
- fail(/* @__PURE__ */ new TypeError("Network request timed out"));
37
- xhr.abort();
38
- }, IDLE_TIMEOUT_MS);
39
- }
40
- let headerEntries;
41
- if (headers instanceof Headers) headerEntries = Array.from(headers.entries());
42
- else if (Array.isArray(headers)) headerEntries = headers;
43
- else headerEntries = Object.entries(headers);
44
- for (const [key, value] of headerEntries) xhr.setRequestHeader(key, value);
45
- xhr.responseType = "text";
46
- let streamController = null;
47
- let lastIndex = 0;
48
- let streamClosed = false;
49
- let settled = false;
50
- const encoder = new TextEncoder();
51
- let resolveFullText;
52
- let rejectFullText;
53
- const fullTextPromise = new Promise((res, rej) => {
54
- resolveFullText = res;
55
- rejectFullText = rej;
56
- });
57
- fullTextPromise.catch(() => {});
58
- function closeStream() {
59
- if (streamController && !streamClosed) {
60
- streamClosed = true;
61
- streamController.close();
62
- }
63
- }
64
- function errorStream(err) {
65
- if (streamController && !streamClosed) {
66
- streamClosed = true;
67
- streamController.error(err);
68
- }
69
- }
70
- function flushChunks() {
71
- if (streamController && !streamClosed && xhr.responseText.length > lastIndex) {
72
- const newData = xhr.responseText.slice(lastIndex);
73
- lastIndex = xhr.responseText.length;
74
- streamController.enqueue(encoder.encode(newData));
75
- }
76
- }
77
- /** Centralized error handler — errors the stream, rejects fullTextPromise,
78
- * and rejects the outer fetch promise if not yet settled. */
79
- function fail(err) {
80
- clearTimeout(idleTimer);
81
- cleanupAbortListener();
82
- errorStream(err);
83
- rejectFullText(err);
84
- if (!settled) {
85
- settled = true;
86
- reject(err);
87
- }
88
- }
89
- const onAbort = () => {
90
- fail(createAbortError());
91
- xhr.abort();
92
- };
93
- if (signal) signal.addEventListener("abort", onAbort);
94
- function cleanupAbortListener() {
95
- if (signal) signal.removeEventListener("abort", onAbort);
96
- }
97
- const stream = new ReadableStream({
98
- start(controller) {
99
- streamController = controller;
100
- },
101
- cancel() {
102
- clearTimeout(idleTimer);
103
- xhr.abort();
104
- rejectFullText(createAbortError());
105
- }
106
- });
107
- xhr.onprogress = function() {
108
- resetIdleTimer();
109
- setTimeout(() => {
110
- try {
111
- flushChunks();
112
- } catch (err) {
113
- fail(err instanceof Error ? err : new Error(String(err)));
114
- xhr.abort();
115
- }
116
- }, 0);
117
- };
118
- xhr.onload = function() {
119
- clearTimeout(idleTimer);
120
- setTimeout(() => {
121
- cleanupAbortListener();
122
- try {
123
- flushChunks();
124
- } catch (err) {
125
- fail(err instanceof Error ? err : new Error(String(err)));
126
- return;
127
- }
128
- closeStream();
129
- resolveFullText(xhr.responseText);
130
- }, 0);
131
- };
132
- xhr.onerror = function() {
133
- setTimeout(() => {
134
- fail(/* @__PURE__ */ new TypeError("Network request failed"));
135
- }, 0);
136
- };
137
- xhr.ontimeout = function() {
138
- setTimeout(() => {
139
- fail(/* @__PURE__ */ new TypeError("Network request timed out"));
140
- }, 0);
141
- };
142
- let resp = null;
143
- xhr.onreadystatechange = function() {
144
- const readyState = xhr.readyState;
145
- if (readyState < 4) resetIdleTimer();
146
- const xhrStatus = xhr.status;
147
- const xhrStatusText = xhr.statusText;
148
- const rawHeaders = xhr.getAllResponseHeaders() || "";
149
- setTimeout(() => {
150
- if (readyState === 4 && !settled && !resp) {
151
- fail(/* @__PURE__ */ new TypeError(`Network request to ${url} completed with status ${xhrStatus} but no response was produced. This may indicate a CORS failure, DNS error, or React Native networking issue.`));
152
- return;
153
- }
154
- if (readyState >= 2 && !resp && xhrStatus !== 0) {
155
- const respHeaders = {};
156
- for (const line of rawHeaders.trim().split("\r\n")) {
157
- const idx = line.indexOf(": ");
158
- if (idx > 0) respHeaders[line.slice(0, idx).toLowerCase()] = line.slice(idx + 2);
159
- }
160
- const responseHeaders = new Headers(respHeaders);
161
- let bodyUsed = false;
162
- resp = {
163
- ok: xhrStatus >= 200 && xhrStatus < 300,
164
- status: xhrStatus,
165
- statusText: xhrStatusText,
166
- url,
167
- type: "basic",
168
- redirected: false,
169
- get bodyUsed() {
170
- return bodyUsed;
171
- },
172
- headers: responseHeaders,
173
- body: stream,
174
- json: async () => {
175
- bodyUsed = true;
176
- const text = await fullTextPromise;
177
- try {
178
- return JSON.parse(text);
179
- } catch (e) {
180
- throw new TypeError(`Failed to parse JSON from ${method} ${url} (status ${xhrStatus}): ${text.length > 200 ? text.slice(0, 200) + "..." : text}`, { cause: e });
181
- }
182
- },
183
- text: async () => {
184
- bodyUsed = true;
185
- return fullTextPromise;
186
- },
187
- arrayBuffer: async () => {
188
- bodyUsed = true;
189
- return encoder.encode(await fullTextPromise).buffer;
190
- },
191
- blob: async () => {
192
- bodyUsed = true;
193
- const buf = encoder.encode(await fullTextPromise);
194
- if (typeof Blob !== "undefined") return new Blob([buf], { type: responseHeaders.get("content-type") || "" });
195
- throw new Error("Blob is not available in this React Native environment.");
196
- },
197
- clone: () => {
198
- throw new Error("Response.clone() is not supported by the React Native streaming fetch polyfill.");
199
- },
200
- formData: async () => {
201
- throw new Error("Response.formData() is not supported by the React Native streaming fetch polyfill.");
202
- }
203
- };
204
- settled = true;
205
- resolve(resp);
206
- }
207
- }, 0);
208
- };
209
- resetIdleTimer();
210
- xhr.send(body ?? null);
211
- });
212
- };
213
- streamingFetch.__originalFetch = originalFetch;
214
- global.fetch = streamingFetch;
215
- }
216
-
217
- //#endregion
218
- export { installStreamingFetch as t };
219
- //# sourceMappingURL=streaming-fetch-Dm1oN4f2.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"streaming-fetch-Dm1oN4f2.mjs","names":[],"sources":["../src/streaming-fetch.ts"],"sourcesContent":["/**\n * Streaming fetch implementation for React Native.\n *\n * React Native's built-in fetch doesn't support response.body.getReader()\n * (ReadableStream). This replaces global.fetch with an XHR-based\n * implementation that streams chunks via ReadableStream, enabling\n * CopilotKit's SSE-based agent communication.\n *\n * If native fetch already supports ReadableStream bodies (newer RN / Hermes),\n * the replacement is skipped entirely.\n *\n * THREADING NOTE: In React Native, XHR callbacks (onprogress, onload, etc.)\n * may fire on a native networking thread. Pushing data into the ReadableStream\n * from that thread can trigger downstream React setState calls on the wrong\n * thread, causing iOS to kill the process with \"deleted thread with uncommitted\n * CATransaction\". All stream-mutating operations are therefore deferred via\n * setTimeout(fn, 0) to bounce back to the JS thread (main thread in Hermes).\n *\n * Call `installStreamingFetch()` once at app startup after polyfills.\n */\n\ndeclare const global: typeof globalThis;\n\n/** Subset of the Response interface implemented by the streaming fetch polyfill. */\ninterface StreamingFetchResponse {\n readonly ok: boolean;\n readonly status: number;\n readonly statusText: string;\n readonly url: string;\n readonly type: string;\n readonly redirected: boolean;\n readonly bodyUsed: boolean;\n readonly headers: Headers;\n readonly body: ReadableStream<Uint8Array>;\n json(): Promise<unknown>;\n text(): Promise<string>;\n arrayBuffer(): Promise<ArrayBuffer>;\n blob(): Promise<Blob>;\n clone(): never;\n formData(): Promise<never>;\n}\n\nfunction createAbortError(): DOMException {\n return new (global as any).DOMException(\n \"The operation was aborted.\",\n \"AbortError\",\n );\n}\n\nexport function installStreamingFetch(): void {\n // Skip if native fetch already supports ReadableStream body.\n // Newer React Native versions (Hermes) may support this natively.\n try {\n const testResponse = new Response(\"\");\n if (\n testResponse.body != null &&\n typeof testResponse.body.getReader === \"function\"\n ) {\n return;\n }\n } catch (e) {\n // Response constructor unavailable — expected in older RN environments.\n if (\n __DEV__ &&\n e instanceof Error &&\n !(e instanceof ReferenceError) &&\n !(e instanceof TypeError)\n ) {\n console.warn(\n \"[CopilotKit] Unexpected error during streaming fetch feature detection, \" +\n \"installing XHR-based polyfill:\",\n e,\n );\n }\n }\n\n const IDLE_TIMEOUT_MS = 60_000;\n const originalFetch = global.fetch;\n const TextEncoder = global.TextEncoder;\n\n const streamingFetch = function streamingFetch(\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> {\n // Extract defaults from Request object when input is a Request\n const request =\n typeof input !== \"string\" && !(input instanceof URL) ? input : null;\n let url: string;\n if (typeof input === \"string\") {\n url = input;\n } else if (input instanceof URL) {\n url = input.href;\n } else {\n url = (input as Request).url;\n }\n const method = init?.method || request?.method || \"GET\";\n const headers = init?.headers || (request ? request.headers : {});\n const body = (init?.body ?? request?.body) as string | null | undefined;\n const signal = init?.signal || request?.signal;\n\n return new Promise((resolve, reject) => {\n // Reject immediately if signal is already aborted (per fetch spec)\n if (signal?.aborted) {\n reject(createAbortError());\n return;\n }\n\n const xhr = new XMLHttpRequest();\n xhr.open(method, url);\n\n // Fail after 60s with no data, to avoid hanging on stalled mobile\n // connections (WiFi→cellular transitions, tunnels, serverless cold\n // starts). This is an idle timeout, not xhr.timeout: a total limit would\n // also cut a healthy stream that runs longer than a minute (#7951).\n // To cap the total time, callers can pass the signal of an AbortController\n // and abort it from a timer (React Native's polyfill has no AbortSignal.timeout()).\n let idleTimer: ReturnType<typeof setTimeout> | undefined;\n function resetIdleTimer() {\n clearTimeout(idleTimer);\n idleTimer = setTimeout(() => {\n fail(new TypeError(\"Network request timed out\"));\n xhr.abort();\n }, IDLE_TIMEOUT_MS);\n }\n\n let headerEntries: [string, string][];\n if (headers instanceof Headers) {\n headerEntries = Array.from(headers.entries());\n } else if (Array.isArray(headers)) {\n headerEntries = headers as [string, string][];\n } else {\n headerEntries = Object.entries(headers as Record<string, string>);\n }\n for (const [key, value] of headerEntries) {\n xhr.setRequestHeader(key, value as string);\n }\n\n xhr.responseType = \"text\";\n\n let streamController: ReadableStreamDefaultController<Uint8Array> | null =\n null;\n let lastIndex = 0;\n let streamClosed = false;\n let settled = false;\n const encoder = new TextEncoder();\n\n // Promise that resolves/rejects when XHR completes or fails\n let resolveFullText: (text: string) => void;\n let rejectFullText: (error: Error) => void;\n const fullTextPromise = new Promise<string>((res, rej) => {\n resolveFullText = res;\n rejectFullText = rej;\n });\n // Prevent unhandled rejection when error occurs but .text()/.json() is never called\n fullTextPromise.catch(() => {});\n\n function closeStream() {\n if (streamController && !streamClosed) {\n streamClosed = true;\n streamController.close();\n }\n }\n\n function errorStream(err: Error) {\n if (streamController && !streamClosed) {\n streamClosed = true;\n streamController.error(err);\n }\n }\n\n function flushChunks() {\n if (\n streamController &&\n !streamClosed &&\n xhr.responseText.length > lastIndex\n ) {\n const newData = xhr.responseText.slice(lastIndex);\n lastIndex = xhr.responseText.length;\n streamController.enqueue(encoder.encode(newData));\n }\n }\n\n /** Centralized error handler — errors the stream, rejects fullTextPromise,\n * and rejects the outer fetch promise if not yet settled. */\n function fail(err: Error) {\n clearTimeout(idleTimer);\n cleanupAbortListener();\n errorStream(err);\n rejectFullText(err);\n if (!settled) {\n settled = true;\n reject(err);\n }\n }\n\n const onAbort = () => {\n fail(createAbortError());\n xhr.abort();\n };\n\n if (signal) {\n signal.addEventListener(\"abort\", onAbort);\n }\n\n function cleanupAbortListener() {\n if (signal) {\n signal.removeEventListener(\"abort\", onAbort);\n }\n }\n\n const stream = new ReadableStream<Uint8Array>({\n start(controller) {\n streamController = controller;\n },\n cancel() {\n clearTimeout(idleTimer);\n xhr.abort();\n rejectFullText(createAbortError());\n },\n });\n\n // All XHR callbacks are wrapped with setTimeout(fn, 0) to ensure they\n // run on the JS thread. In React Native, XHR callbacks may fire on a\n // native networking thread; calling streamController.enqueue() there\n // triggers downstream React setState on the wrong thread, which causes\n // iOS to kill the process (\"deleted thread with uncommitted CATransaction\").\n // setTimeout(fn, 0) defers execution to the JS event loop (main thread\n // in Hermes) with negligible latency — streaming still feels real-time.\n\n xhr.onprogress = function () {\n resetIdleTimer();\n setTimeout(() => {\n try {\n flushChunks();\n } catch (err) {\n fail(err instanceof Error ? err : new Error(String(err)));\n xhr.abort();\n }\n }, 0);\n };\n\n xhr.onload = function () {\n clearTimeout(idleTimer);\n setTimeout(() => {\n cleanupAbortListener();\n try {\n flushChunks();\n } catch (err) {\n fail(err instanceof Error ? err : new Error(String(err)));\n return;\n }\n closeStream();\n resolveFullText(xhr.responseText);\n }, 0);\n };\n\n xhr.onerror = function () {\n setTimeout(() => {\n fail(new TypeError(\"Network request failed\"));\n }, 0);\n };\n\n xhr.ontimeout = function () {\n setTimeout(() => {\n fail(new TypeError(\"Network request timed out\"));\n }, 0);\n };\n\n // Resolve with Response once headers arrive.\n // Guard against status === 0 which XHR produces for CORS failures,\n // DNS errors, and mixed-content blocks — let onerror handle those.\n let resp: StreamingFetchResponse | null = null;\n xhr.onreadystatechange = function () {\n // Capture XHR state synchronously before deferring — XHR properties\n // may change between now and when setTimeout fires.\n const readyState = xhr.readyState;\n if (readyState < 4) resetIdleTimer();\n const xhrStatus = xhr.status;\n const xhrStatusText = xhr.statusText;\n const rawHeaders = xhr.getAllResponseHeaders() || \"\";\n\n setTimeout(() => {\n // Safety net: if XHR completed but we never resolved/rejected, fail explicitly.\n // This can happen when status === 0 and onerror doesn't fire (some RN networking impls).\n if (readyState === 4 && !settled && !resp) {\n fail(\n new TypeError(\n `Network request to ${url} completed with status ${xhrStatus} but no response was produced. ` +\n `This may indicate a CORS failure, DNS error, or React Native networking issue.`,\n ),\n );\n return;\n }\n\n if (readyState >= 2 && !resp && xhrStatus !== 0) {\n const respHeaders: Record<string, string> = {};\n for (const line of rawHeaders.trim().split(\"\\r\\n\")) {\n const idx = line.indexOf(\": \");\n if (idx > 0) {\n respHeaders[line.slice(0, idx).toLowerCase()] = line.slice(\n idx + 2,\n );\n }\n }\n\n const responseHeaders = new Headers(respHeaders);\n\n let bodyUsed = false;\n\n resp = {\n // Duck-typed Response object (not a native Response instance)\n ok: xhrStatus >= 200 && xhrStatus < 300,\n status: xhrStatus,\n statusText: xhrStatusText,\n url: url,\n type: \"basic\",\n redirected: false,\n get bodyUsed() {\n return bodyUsed;\n },\n headers: responseHeaders,\n body: stream,\n json: async () => {\n bodyUsed = true;\n const text = await fullTextPromise;\n try {\n return JSON.parse(text);\n } catch (e) {\n throw new TypeError(\n `Failed to parse JSON from ${method} ${url} (status ${xhrStatus}): ${\n text.length > 200 ? text.slice(0, 200) + \"...\" : text\n }`,\n { cause: e },\n );\n }\n },\n text: async () => {\n bodyUsed = true;\n return fullTextPromise;\n },\n arrayBuffer: async () => {\n bodyUsed = true;\n return encoder.encode(await fullTextPromise).buffer;\n },\n blob: async () => {\n bodyUsed = true;\n const buf = encoder.encode(await fullTextPromise);\n if (typeof Blob !== \"undefined\") {\n return new Blob([buf], {\n type: responseHeaders.get(\"content-type\") || \"\",\n });\n }\n throw new Error(\n \"Blob is not available in this React Native environment.\",\n );\n },\n clone: () => {\n throw new Error(\n \"Response.clone() is not supported by the React Native streaming fetch polyfill.\",\n );\n },\n formData: async () => {\n throw new Error(\n \"Response.formData() is not supported by the React Native streaming fetch polyfill.\",\n );\n },\n };\n settled = true;\n // NOTE: abort listener is NOT removed here — the signal must remain\n // wired to xhr.abort() for mid-stream cancellation. Cleanup happens\n // in terminal handlers (onload, onerror, ontimeout) or onAbort itself.\n resolve(resp as unknown as Response);\n }\n }, 0);\n };\n\n resetIdleTimer();\n xhr.send(body ?? null);\n });\n };\n\n // Expose original fetch for opt-out (e.g., third-party libs that need native behavior)\n (streamingFetch as any).__originalFetch = originalFetch;\n global.fetch = streamingFetch as typeof fetch;\n}\n"],"mappings":";AA0CA,SAAS,mBAAiC;AACxC,QAAO,IAAK,OAAe,aACzB,8BACA,aACD;;AAGH,SAAgB,wBAA8B;AAG5C,KAAI;EACF,MAAM,eAAe,IAAI,SAAS,GAAG;AACrC,MACE,aAAa,QAAQ,QACrB,OAAO,aAAa,KAAK,cAAc,WAEvC;UAEK,GAAG;AAEV,MACE,WACA,aAAa,SACb,EAAE,aAAa,mBACf,EAAE,aAAa,WAEf,SAAQ,KACN,0GAEA,EACD;;CAIL,MAAM,kBAAkB;CACxB,MAAM,gBAAgB,OAAO;CAC7B,MAAM,cAAc,OAAO;CAE3B,MAAM,iBAAiB,SAAS,eAC9B,OACA,MACmB;EAEnB,MAAM,UACJ,OAAO,UAAU,YAAY,EAAE,iBAAiB,OAAO,QAAQ;EACjE,IAAI;AACJ,MAAI,OAAO,UAAU,SACnB,OAAM;WACG,iBAAiB,IAC1B,OAAM,MAAM;MAEZ,OAAO,MAAkB;EAE3B,MAAM,SAAS,MAAM,UAAU,SAAS,UAAU;EAClD,MAAM,UAAU,MAAM,YAAY,UAAU,QAAQ,UAAU,EAAE;EAChE,MAAM,OAAQ,MAAM,QAAQ,SAAS;EACrC,MAAM,SAAS,MAAM,UAAU,SAAS;AAExC,SAAO,IAAI,SAAS,SAAS,WAAW;AAEtC,OAAI,QAAQ,SAAS;AACnB,WAAO,kBAAkB,CAAC;AAC1B;;GAGF,MAAM,MAAM,IAAI,gBAAgB;AAChC,OAAI,KAAK,QAAQ,IAAI;GAQrB,IAAI;GACJ,SAAS,iBAAiB;AACxB,iBAAa,UAAU;AACvB,gBAAY,iBAAiB;AAC3B,0BAAK,IAAI,UA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