@copilotkit/react-native 2.0.0-rc.38 → 2.0.0-rc.39

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 (82) hide show
  1. package/README.md +334 -2
  2. package/USAGE.md +382 -21
  3. package/dist/{CopilotKitProvider-F7Pn5kp4.d.cts → CopilotKitProvider-Cbfrm_7u.d.mts} +2 -2
  4. package/dist/{CopilotKitProvider-DDPbJkHS.cjs → CopilotKitProvider-CvJYytjn.cjs} +4 -3
  5. package/dist/{CopilotKitProvider-DDPbJkHS.cjs.map → CopilotKitProvider-CvJYytjn.cjs.map} +1 -1
  6. package/dist/{CopilotKitProvider-Khgz5dQo.d.mts → CopilotKitProvider-Dv3ISMKf.d.cts} +2 -2
  7. package/dist/{CopilotKitProvider-BXpkAl1Y.mjs → CopilotKitProvider-oTdmylSY.mjs} +2 -2
  8. package/dist/{CopilotKitProvider-BXpkAl1Y.mjs.map → CopilotKitProvider-oTdmylSY.mjs.map} +1 -1
  9. package/dist/{Markdown-CaYHlD4j.cjs → Markdown-DLopAh5W.cjs} +3 -3
  10. package/dist/{Markdown-CaYHlD4j.cjs.map → Markdown-DLopAh5W.cjs.map} +1 -1
  11. package/dist/{Markdown-a-rdG22_.d.mts → Markdown-Du-b_Qpr.d.mts} +1 -1
  12. package/dist/{Markdown-DzjnSuu5.d.cts → Markdown-UXZdDjzs.d.cts} +1 -1
  13. package/dist/{Markdown-SE9MfY2U.mjs → Markdown-VxtPJ_yh.mjs} +1 -1
  14. package/dist/{Markdown-SE9MfY2U.mjs.map → Markdown-VxtPJ_yh.mjs.map} +1 -1
  15. package/dist/{MarkdownRendererContext-B_AKdPAN.mjs → MarkdownRendererContext-EobUsERg.mjs} +1 -1
  16. package/dist/{MarkdownRendererContext-B_AKdPAN.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 +6 -4
  21. package/dist/components/index.cjs.map +1 -1
  22. package/dist/components/index.d.cts +1 -1
  23. package/dist/components/index.d.mts +1 -1
  24. package/dist/components/index.mjs +3 -2
  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 +2 -3
  33. package/dist/headless.d.cts +2 -2
  34. package/dist/headless.d.mts +2 -2
  35. package/dist/headless.mjs +1 -2
  36. package/dist/index.cjs +8 -7
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts +3 -3
  39. package/dist/index.d.mts +2 -2
  40. package/dist/index.mjs +4 -4
  41. package/dist/polyfills/encoding.cjs +113 -3
  42. package/dist/polyfills/encoding.cjs.map +1 -1
  43. package/dist/polyfills/encoding.d.cts +31 -1
  44. package/dist/polyfills/encoding.d.mts +31 -1
  45. package/dist/polyfills/encoding.mjs +109 -3
  46. package/dist/polyfills/encoding.mjs.map +1 -1
  47. package/dist/polyfills/streams.cjs +1 -1
  48. package/dist/polyfills.cjs +218 -3
  49. package/dist/polyfills.cjs.map +1 -1
  50. package/dist/polyfills.mjs +217 -2
  51. package/dist/polyfills.mjs.map +1 -1
  52. package/package.json +13 -5
  53. package/project.json +6 -1
  54. package/scripts/__tests__/verify-polyfill-barrel.test.mjs +150 -0
  55. package/scripts/verify-polyfill-barrel.mjs +154 -5
  56. package/src/__tests__/generative-ui-harness.tsx +243 -0
  57. package/src/__tests__/generative-ui-provider-props.test-d.tsx +106 -0
  58. package/src/__tests__/generative-ui-rn-mock.tsx +54 -0
  59. package/src/__tests__/generative-ui-wiring.test.tsx +720 -0
  60. package/src/__tests__/generative-ui.test.tsx +1000 -0
  61. package/src/__tests__/headless-entry-surface.test.ts +979 -60
  62. package/src/components/index.ts +6 -0
  63. package/src/generative-ui/GenerativeUIActivity.tsx +235 -0
  64. package/src/generative-ui/GenerativeUIProvider.tsx +171 -0
  65. package/src/generative-ui/GenerativeUISurface.tsx +303 -0
  66. package/src/generative-ui/host.tsx +138 -0
  67. package/src/generative-ui/index.ts +93 -0
  68. package/src/generative-ui/internal.ts +55 -0
  69. package/src/index.ts +8 -3
  70. package/src/polyfills/__tests__/{utf8.test.ts → encoding-utf8.test.ts} +1 -1
  71. package/src/polyfills/encoding.ts +156 -1
  72. package/tsdown.config.ts +1 -0
  73. package/dist/MarkdownRendererContext-BRNe808d.cjs +0 -72
  74. package/dist/streaming-fetch-CLHG3Z1H.mjs +0 -219
  75. package/dist/streaming-fetch-CLHG3Z1H.mjs.map +0 -1
  76. package/dist/streaming-fetch-DbDALGya.cjs +0 -225
  77. package/dist/streaming-fetch-DbDALGya.cjs.map +0 -1
  78. package/dist/utf8-BIN9t4Oy.mjs +0 -113
  79. package/dist/utf8-BIN9t4Oy.mjs.map +0 -1
  80. package/dist/utf8-Cf3Ssy33.cjs +0 -125
  81. package/dist/utf8-Cf3Ssy33.cjs.map +0 -1
  82. package/src/polyfills/utf8.ts +0 -151
@@ -1 +1 @@
1
- {"version":3,"file":"polyfills.mjs","names":[],"sources":["../src/polyfills.ts"],"sourcesContent":["/**\n * All polyfills required for CopilotKit to work in React Native.\n *\n * These are auto-imported when `@copilotkit/react-native` is loaded.\n * A manual `import \"@copilotkit/react-native/polyfills\"` is no longer\n * required but still works for advanced / selective bootstrap scenarios.\n *\n * For granular control, import individual polyfills instead:\n * import \"@copilotkit/react-native/polyfills/streams\";\n * import \"@copilotkit/react-native/polyfills/encoding\";\n * import \"@copilotkit/react-native/polyfills/crypto\";\n * import \"@copilotkit/react-native/polyfills/dom\";\n * import \"@copilotkit/react-native/polyfills/location\";\n */\n\nimport \"./polyfills/streams\";\nimport \"./polyfills/encoding\";\nimport \"./polyfills/crypto\";\nimport \"./polyfills/dom\";\nimport \"./polyfills/location\";\n\nimport { installStreamingFetch } from \"./streaming-fetch\";\ninstallStreamingFetch();\n"],"mappings":";;;;;;;;;AAsBA,uBAAuB"}
1
+ {"version":3,"file":"polyfills.mjs","names":[],"sources":["../src/streaming-fetch.ts","../src/polyfills.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","/**\n * All polyfills required for CopilotKit to work in React Native.\n *\n * These are auto-imported when `@copilotkit/react-native` is loaded.\n * A manual `import \"@copilotkit/react-native/polyfills\"` is no longer\n * required but still works for advanced / selective bootstrap scenarios.\n *\n * For granular control, import individual polyfills instead:\n * import \"@copilotkit/react-native/polyfills/streams\";\n * import \"@copilotkit/react-native/polyfills/encoding\";\n * import \"@copilotkit/react-native/polyfills/crypto\";\n * import \"@copilotkit/react-native/polyfills/dom\";\n * import \"@copilotkit/react-native/polyfills/location\";\n */\n\nimport \"./polyfills/streams\";\nimport \"./polyfills/encoding\";\nimport \"./polyfills/crypto\";\nimport \"./polyfills/dom\";\nimport \"./polyfills/location\";\n\nimport { installStreamingFetch } from \"./streaming-fetch\";\ninstallStreamingFetch();\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;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AY;AACpB,cAAM,IAAI,MACR,qFACD;;OAEJ;AACD,gBAAU;AAIV,cAAQ,KAA4B;;OAErC,EAAE;;AAGP,mBAAgB;AAChB,OAAI,KAAK,QAAQ,KAAK;IACtB;;AAIJ,CAAC,eAAuB,kBAAkB;AAC1C,QAAO,QAAQ;;;;;ACzWjB,uBAAuB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/react-native",
3
- "version": "2.0.0-rc.38",
3
+ "version": "2.0.0-rc.39",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "ai",
@@ -23,10 +23,14 @@
23
23
  "sideEffects": [
24
24
  "./src/index.*",
25
25
  "./src/headless.*",
26
+ "./src/components/index.*",
27
+ "./src/generative-ui/index.*",
26
28
  "./src/polyfills.*",
27
29
  "./src/polyfills/**/*",
28
30
  "./dist/index.*",
29
31
  "./dist/headless.*",
32
+ "./dist/components/index.*",
33
+ "./dist/generative-ui/index.*",
30
34
  "./dist/polyfills.*",
31
35
  "./dist/polyfills/**/*"
32
36
  ],
@@ -42,6 +46,10 @@
42
46
  "import": "./dist/headless.mjs",
43
47
  "require": "./dist/headless.cjs"
44
48
  },
49
+ "./generative-ui": {
50
+ "import": "./dist/generative-ui/index.mjs",
51
+ "require": "./dist/generative-ui/index.cjs"
52
+ },
45
53
  "./polyfills": {
46
54
  "import": "./dist/polyfills.mjs",
47
55
  "require": "./dist/polyfills.cjs"
@@ -77,10 +85,10 @@
77
85
  },
78
86
  "dependencies": {
79
87
  "@ag-ui/client": "1.0.4",
80
- "@copilotkit/core": "2.0.0-rc.38",
81
- "@copilotkit/markdown": "2.0.0-rc.38",
82
- "@copilotkit/react-core": "2.0.0-rc.38",
83
- "@copilotkit/shared": "2.0.0-rc.38",
88
+ "@copilotkit/core": "2.0.0-rc.39",
89
+ "@copilotkit/markdown": "2.0.0-rc.39",
90
+ "@copilotkit/react-core": "2.0.0-rc.39",
91
+ "@copilotkit/shared": "2.0.0-rc.39",
84
92
  "web-streams-polyfill": "^4.2.0"
85
93
  },
86
94
  "devDependencies": {
package/project.json CHANGED
@@ -15,7 +15,12 @@
15
15
  "outputs": ["{projectRoot}/dist/**"]
16
16
  },
17
17
  "test": {
18
- "inputs": ["test", "{projectRoot}/scripts/**"]
18
+ "inputs": [
19
+ "test",
20
+ "{projectRoot}/scripts/**",
21
+ "^production",
22
+ { "dependentTasksOutputFiles": "**/*", "transitive": true }
23
+ ]
19
24
  }
20
25
  }
21
26
  }
@@ -20,6 +20,9 @@ import path from "node:path";
20
20
  import {
21
21
  assertBuilt,
22
22
  BUILD_COMMAND,
23
+ checkEntryOrder,
24
+ firstCjsSpecifier,
25
+ firstEsmSpecifier,
23
26
  GROUPS,
24
27
  isEntrypoint,
25
28
  missingEsmImports,
@@ -32,6 +35,61 @@ const emptyBarrel = path.join(fixtureDir, "dist-empty-barrel");
32
35
  const completeBarrel = path.join(fixtureDir, "dist-complete-barrel");
33
36
  const scriptPath = path.join(here, "..", "verify-polyfill-barrel.mjs");
34
37
 
38
+ // The CLI reads package.json next to dist/. Only the polyfill subpath, so the
39
+ // barrel fixtures are checked on their own.
40
+ const BARREL_ONLY_MANIFEST = JSON.stringify({
41
+ exports: {
42
+ "./polyfills": {
43
+ import: "./dist/polyfills.mjs",
44
+ require: "./dist/polyfills.cjs",
45
+ },
46
+ },
47
+ });
48
+
49
+ /**
50
+ * A package root with one `./generative-ui` code entry built as `esm` / `cjs`,
51
+ * beside the complete barrel.
52
+ */
53
+ function packageWithEntry({ esm, cjs }) {
54
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "rn-entry-order-"));
55
+ fs.cpSync(completeBarrel, path.join(root, "dist"), { recursive: true });
56
+ fs.mkdirSync(path.join(root, "dist", "generative-ui"));
57
+ fs.writeFileSync(path.join(root, "dist", "generative-ui", "index.mjs"), esm);
58
+ fs.writeFileSync(path.join(root, "dist", "generative-ui", "index.cjs"), cjs);
59
+ fs.writeFileSync(
60
+ path.join(root, "package.json"),
61
+ JSON.stringify({
62
+ exports: {
63
+ "./generative-ui": {
64
+ import: "./dist/generative-ui/index.mjs",
65
+ require: "./dist/generative-ui/index.cjs",
66
+ },
67
+ "./polyfills": {
68
+ import: "./dist/polyfills.mjs",
69
+ require: "./dist/polyfills.cjs",
70
+ },
71
+ "./package.json": "./package.json",
72
+ },
73
+ }),
74
+ );
75
+ return root;
76
+ }
77
+
78
+ // What tsdown emitted for the generative UI entry before it imported the
79
+ // polyfills: core-loading modules first, no polyfill barrel at all.
80
+ const UNPOLYFILLED_ESM =
81
+ 'import React from "react";\n' +
82
+ 'import { useCopilotKit } from "@copilotkit/react-core/context";\n';
83
+ const UNPOLYFILLED_CJS =
84
+ "Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n" +
85
+ "const require_chunk = require('../chunk-C0xms8kb.cjs');\n" +
86
+ 'let react = require("react");\n';
87
+ const POLYFILLED_ESM = 'import "../polyfills.mjs";\n' + UNPOLYFILLED_ESM;
88
+ const POLYFILLED_CJS = UNPOLYFILLED_CJS.replace(
89
+ 'let react = require("react");',
90
+ "require('../polyfills.cjs');\nlet react = require(\"react\");",
91
+ );
92
+
35
93
  describe("verifyBarrel", () => {
36
94
  it("rejects the tree-shaken barrel that shipped in 1.69.2", () => {
37
95
  const report = verifyBarrel(emptyBarrel);
@@ -96,6 +154,73 @@ describe("verifyBarrel", () => {
96
154
  });
97
155
  });
98
156
 
157
+ describe("checkEntryOrder", () => {
158
+ it("rejects a published entry that loads CopilotKit before the polyfills", () => {
159
+ const root = packageWithEntry({
160
+ esm: UNPOLYFILLED_ESM,
161
+ cjs: UNPOLYFILLED_CJS,
162
+ });
163
+ const results = checkEntryOrder(root);
164
+ // Both formats, and nothing for the polyfill subpath or the manifest.
165
+ assert.deepEqual(
166
+ results.map(({ file, first, ok }) => ({ file, first, ok })),
167
+ [
168
+ { file: "./dist/generative-ui/index.mjs", first: "react", ok: false },
169
+ { file: "./dist/generative-ui/index.cjs", first: "react", ok: false },
170
+ ],
171
+ );
172
+ fs.rmSync(root, { recursive: true, force: true });
173
+ });
174
+
175
+ it("accepts an entry whose first load is the polyfill barrel", () => {
176
+ const root = packageWithEntry({
177
+ esm: POLYFILLED_ESM,
178
+ cjs: POLYFILLED_CJS,
179
+ });
180
+ const results = checkEntryOrder(root);
181
+ assert.equal(results.length, 2);
182
+ for (const result of results) assert.equal(result.ok, true, result.file);
183
+ fs.rmSync(root, { recursive: true, force: true });
184
+ });
185
+
186
+ it("rejects an entry whose polyfill import is present but not first", () => {
187
+ // The root entry's real regression: the bundler hoisted a shared chunk
188
+ // that loads @copilotkit/react-core above the import of the polyfills.
189
+ const root = packageWithEntry({
190
+ esm: UNPOLYFILLED_ESM + 'import "../polyfills.mjs";\n',
191
+ cjs: UNPOLYFILLED_CJS + "require('../polyfills.cjs');\n",
192
+ });
193
+ for (const result of checkEntryOrder(root)) {
194
+ assert.equal(result.ok, false, result.file);
195
+ }
196
+ fs.rmSync(root, { recursive: true, force: true });
197
+ });
198
+
199
+ it("reports an entry that was not built instead of skipping it", () => {
200
+ const root = packageWithEntry({ esm: POLYFILLED_ESM, cjs: POLYFILLED_CJS });
201
+ fs.rmSync(path.join(root, "dist", "generative-ui", "index.cjs"));
202
+ const missing = checkEntryOrder(root).find((r) => r.file.endsWith(".cjs"));
203
+ assert.equal(missing.ok, false);
204
+ assert.equal(missing.error, "not built");
205
+ fs.rmSync(root, { recursive: true, force: true });
206
+ });
207
+ });
208
+
209
+ describe("firstEsmSpecifier / firstCjsSpecifier", () => {
210
+ it("reads the first module, past comments and rolldown's runtime chunk", () => {
211
+ assert.equal(
212
+ firstEsmSpecifier(
213
+ '//#region x\nimport "./polyfills.mjs";\nimport a from "a";',
214
+ ),
215
+ "./polyfills.mjs",
216
+ );
217
+ assert.equal(firstEsmSpecifier('export * from "./x.mjs";'), "./x.mjs");
218
+ assert.equal(firstEsmSpecifier("const a = 1;"), null);
219
+ assert.equal(firstCjsSpecifier(POLYFILLED_CJS), "../polyfills.cjs");
220
+ assert.equal(firstCjsSpecifier(UNPOLYFILLED_CJS), "react");
221
+ });
222
+ });
223
+
99
224
  describe("missingEsmImports", () => {
100
225
  it("names every group the ESM barrel no longer imports", () => {
101
226
  assert.deepEqual(
@@ -157,6 +282,7 @@ describe("cli", () => {
157
282
  fs.mkdirSync(path.join(fakeRoot, "scripts"));
158
283
  fs.cpSync(scriptPath, path.join(fakeRoot, "scripts", "verify.mjs"));
159
284
  fs.cpSync(emptyBarrel, path.join(fakeRoot, "dist"), { recursive: true });
285
+ fs.writeFileSync(path.join(fakeRoot, "package.json"), BARREL_ONLY_MANIFEST);
160
286
 
161
287
  const result = spawnSync(
162
288
  process.execPath,
@@ -174,6 +300,7 @@ describe("cli", () => {
174
300
  fs.mkdirSync(path.join(fakeRoot, "scripts"));
175
301
  fs.cpSync(scriptPath, path.join(fakeRoot, "scripts", "verify.mjs"));
176
302
  fs.cpSync(completeBarrel, path.join(fakeRoot, "dist"), { recursive: true });
303
+ fs.writeFileSync(path.join(fakeRoot, "package.json"), BARREL_ONLY_MANIFEST);
177
304
 
178
305
  const result = spawnSync(
179
306
  process.execPath,
@@ -184,4 +311,27 @@ describe("cli", () => {
184
311
  assert.equal(JSON.parse(result.stdout).ok, true);
185
312
  fs.rmSync(fakeRoot, { recursive: true, force: true });
186
313
  });
314
+
315
+ it("fails the build when a published entry loads CopilotKit before the polyfills", () => {
316
+ const fakeRoot = packageWithEntry({
317
+ esm: UNPOLYFILLED_ESM,
318
+ cjs: UNPOLYFILLED_CJS,
319
+ });
320
+ fs.mkdirSync(path.join(fakeRoot, "scripts"));
321
+ fs.cpSync(scriptPath, path.join(fakeRoot, "scripts", "verify.mjs"));
322
+
323
+ const result = spawnSync(
324
+ process.execPath,
325
+ [path.join(fakeRoot, "scripts", "verify.mjs")],
326
+ { encoding: "utf8" },
327
+ );
328
+ assert.equal(result.status, 1);
329
+ assert.match(
330
+ result.stdout,
331
+ /FAIL {2}\.\/dist\/generative-ui\/index\.mjs +first loads react/,
332
+ );
333
+ assert.match(result.stderr, /expected \.\.\/polyfills\.cjs/);
334
+ assert.match(result.stderr, /sideEffects/);
335
+ fs.rmSync(fakeRoot, { recursive: true, force: true });
336
+ });
187
337
  });
@@ -21,6 +21,14 @@
21
21
  // polyfill installs its globals. Asserting the five imports survive the
22
22
  // bundler is the part this file exists to protect.
23
23
  //
24
+ // Then a third check, over every published code entry in package.json
25
+ // `exports` (all but the polyfill subpaths): the built import and require
26
+ // files must load the polyfill barrel before anything else. An app can import
27
+ // any entry first, and @copilotkit/core and @ag-ui/client fail at load time on
28
+ // Hermes without the polyfills. It reads dist/ because the bundler decides the
29
+ // emitted order: it hoisted a shared provider chunk above the root entry's
30
+ // `export * from "./headless"`, so the source order alone proved nothing.
31
+ //
24
32
  // Invoked from package.json `build`, so a barrel that installs nothing fails
25
33
  // the build rather than reaching npm.
26
34
  //
@@ -136,7 +144,111 @@ export function verifyBarrel(distDir) {
136
144
  return { ok, cjs, esmMissing };
137
145
  }
138
146
 
139
- export function formatReport({ cjs, esmMissing }) {
147
+ /**
148
+ * Export subpaths that are the polyfills themselves, or carry no code. Every
149
+ * other published entry loads @copilotkit/core or @ag-ui/client, which fail at
150
+ * load time on Hermes without the polyfills, so each must install them first:
151
+ * an app can import any entry before the root one.
152
+ */
153
+ const isPolyfillOrManifestExport = (key) =>
154
+ key === "./package.json" ||
155
+ key === "./polyfills" ||
156
+ key.startsWith("./polyfills/");
157
+
158
+ /** The first module an ESM file imports or re-exports, in order. */
159
+ export function firstEsmSpecifier(source) {
160
+ const m =
161
+ /^\s*(?:import\s*(?:[^;"'`]*?\bfrom\s*)?|export\s[^;"'`]*?\bfrom\s*)["'`]([^"'`]+)["'`]/m.exec(
162
+ source.replace(/\/\*[\s\S]*?\*\/|^\s*\/\/[^\n]*$/gm, ""),
163
+ );
164
+ return m ? m[1] : null;
165
+ }
166
+
167
+ /**
168
+ * The first module a CJS file requires, in order, skipping the bundler's own
169
+ * runtime helper chunk (rolldown's `chunk-*.cjs`: `__toESM` and friends, which
170
+ * requires nothing and touches no global).
171
+ */
172
+ export function firstCjsSpecifier(source) {
173
+ for (const m of source.matchAll(/\brequire\s*\(\s*(["'])([^"']+)\1\s*\)/g)) {
174
+ if (/(?:^|\/)chunk-[\w-]+\.cjs$/.test(m[2])) continue;
175
+ return m[2];
176
+ }
177
+ return null;
178
+ }
179
+
180
+ /**
181
+ * For every published code entry (from package.json `exports`), whether its
182
+ * BUILT import and require targets load the polyfill barrel before anything
183
+ * else. Checked in dist/, because the bundler decides the emitted order: a
184
+ * shared chunk can be hoisted above a re-export that installs the polyfills.
185
+ */
186
+ export function checkEntryOrder(packageDir) {
187
+ const manifestPath = path.join(packageDir, "package.json");
188
+ if (!existsSync(manifestPath)) {
189
+ throw new Error(`No package.json at ${manifestPath}.`);
190
+ }
191
+ const { exports: exportsMap } = JSON.parse(
192
+ readFileSync(manifestPath, "utf8"),
193
+ );
194
+ const results = [];
195
+ for (const [key, value] of Object.entries(exportsMap ?? {})) {
196
+ if (isPolyfillOrManifestExport(key)) continue;
197
+ const targets =
198
+ typeof value === "string" ? { import: value } : (value ?? {});
199
+ for (const [condition, target] of Object.entries(targets)) {
200
+ if (condition !== "import" && condition !== "require") continue;
201
+ const file = path.join(packageDir, target);
202
+ const cjs = file.endsWith(".cjs");
203
+ let expected = path
204
+ .relative(
205
+ path.dirname(file),
206
+ path.join(
207
+ packageDir,
208
+ "dist",
209
+ cjs ? "polyfills.cjs" : "polyfills.mjs",
210
+ ),
211
+ )
212
+ .split(path.sep)
213
+ .join("/");
214
+ if (!expected.startsWith(".")) expected = `./${expected}`;
215
+ if (!existsSync(file)) {
216
+ results.push({
217
+ entry: key,
218
+ file: target,
219
+ expected,
220
+ first: null,
221
+ ok: false,
222
+ error: "not built",
223
+ });
224
+ continue;
225
+ }
226
+ const source = readFileSync(file, "utf8");
227
+ const first = cjs ? firstCjsSpecifier(source) : firstEsmSpecifier(source);
228
+ results.push({
229
+ entry: key,
230
+ file: target,
231
+ expected,
232
+ first,
233
+ ok: first === expected,
234
+ });
235
+ }
236
+ }
237
+ return results;
238
+ }
239
+
240
+ /** The barrel check plus the entry-order check, for a built package. */
241
+ export function verifyPackage(packageDir) {
242
+ const barrel = verifyBarrel(path.join(packageDir, "dist"));
243
+ const entries = checkEntryOrder(packageDir);
244
+ return {
245
+ ...barrel,
246
+ entries,
247
+ ok: barrel.ok && entries.every((entry) => entry.ok),
248
+ };
249
+ }
250
+
251
+ export function formatReport({ cjs, esmMissing, entries = [] }) {
140
252
  const lines = cjs.map(
141
253
  (entry) =>
142
254
  `${entry.missing.length === 0 ? "PASS" : "FAIL"} cjs ${entry.group.padEnd(9)} ` +
@@ -148,10 +260,41 @@ export function formatReport({ cjs, esmMissing }) {
148
260
  `import "./polyfills/${group.name}.mjs"`,
149
261
  );
150
262
  }
263
+ for (const entry of entries) {
264
+ lines.push(
265
+ `${entry.ok ? "PASS" : "FAIL"} ${entry.file.padEnd(32)} ` +
266
+ `first loads ${entry.first ?? `(${entry.error ?? "nothing"})`}`,
267
+ );
268
+ }
151
269
  return lines.join("\n");
152
270
  }
153
271
 
154
- export function failureMessage({ cjs, esmMissing }) {
272
+ export function failureMessage({ cjs, esmMissing, entries = [] }) {
273
+ const misordered = entries.filter((entry) => !entry.ok);
274
+ if (
275
+ misordered.length &&
276
+ cjs.every((entry) => entry.missing.length === 0) &&
277
+ esmMissing.length === 0
278
+ ) {
279
+ return (
280
+ `A published entry does not install the polyfills before anything else.\n` +
281
+ misordered
282
+ .map(
283
+ (entry) =>
284
+ ` ${entry.file} (${entry.entry}) first loads ` +
285
+ `${entry.first ?? `(${entry.error ?? "nothing"})`}, expected ${entry.expected}`,
286
+ )
287
+ .join("\n") +
288
+ `\n\nAn app can import any entry before the root one, and on Hermes\n` +
289
+ `@copilotkit/core and @ag-ui/client fail at load time without the polyfills.\n` +
290
+ `Make \`import "./polyfills"\` (relative) the entry's first import, and list\n` +
291
+ `the entry's src and dist paths in package.json "sideEffects".`
292
+ );
293
+ }
294
+ return failureMessageForBarrel({ cjs, esmMissing }, misordered);
295
+ }
296
+
297
+ function failureMessageForBarrel({ cjs, esmMissing }, misordered) {
155
298
  const dropped = [
156
299
  ...cjs.flatMap((entry) => entry.missing),
157
300
  ...esmMissing.map((name) => `import "./polyfills/${name}.mjs"`),
@@ -161,7 +304,10 @@ export function failureMessage({ cjs, esmMissing }) {
161
304
  `Missing: ${dropped.join(", ")}\n\n` +
162
305
  `The side-effect imports in src/polyfills.ts were tree-shaken away. Check that\n` +
163
306
  `the "sideEffects" globs in package.json match this package's SOURCE paths —\n` +
164
- `globs that only match ./dist/** tell the bundler the src files are pure.`
307
+ `globs that only match ./dist/** tell the bundler the src files are pure.` +
308
+ (misordered.length
309
+ ? `\n\nAlso misordered: ${misordered.map((entry) => entry.file).join(", ")}`
310
+ : "")
165
311
  );
166
312
  }
167
313
 
@@ -194,7 +340,7 @@ if (isEntrypoint(import.meta.url, process.argv[1])) {
194
340
  const jsonMode = process.argv.includes("--json");
195
341
  let report;
196
342
  try {
197
- report = verifyBarrel(path.join(packageRoot, "dist"));
343
+ report = verifyPackage(packageRoot);
198
344
  } catch (error) {
199
345
  if (jsonMode) {
200
346
  process.stdout.write(
@@ -212,7 +358,10 @@ if (isEntrypoint(import.meta.url, process.argv[1])) {
212
358
  process.stdout.write(formatReport(report) + "\n");
213
359
  if (!report.ok) process.stderr.write(`\n${failureMessage(report)}\n`);
214
360
  else
215
- process.stdout.write(`\nAll ${GROUPS.length} polyfill groups install.\n`);
361
+ process.stdout.write(
362
+ `\nAll ${GROUPS.length} polyfill groups install, and all ` +
363
+ `${report.entries.length} published entry files load them first.\n`,
364
+ );
216
365
  }
217
366
  process.exit(report.ok ? 0 : 1);
218
367
  }