@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.
- package/README.md +334 -2
- package/USAGE.md +382 -21
- package/dist/CopilotKitProvider-CBVQLdzn.d.cts +77 -0
- package/dist/{CopilotKitProvider-CE4bc6CP.mjs → CopilotKitProvider-CCBBonxr.mjs} +63 -43
- package/dist/CopilotKitProvider-CCBBonxr.mjs.map +1 -0
- package/dist/CopilotKitProvider-CtQg_0S-.d.mts +77 -0
- package/dist/{CopilotKitProvider-Byw3cqe2.cjs → CopilotKitProvider-QdcQrrSA.cjs} +69 -42
- package/dist/CopilotKitProvider-QdcQrrSA.cjs.map +1 -0
- package/dist/{Markdown-C_9Re36O.cjs → Markdown-DLopAh5W.cjs} +10 -10
- package/dist/Markdown-DLopAh5W.cjs.map +1 -0
- package/dist/{Markdown-JsYh7oSA.d.mts → Markdown-Du-b_Qpr.d.mts} +3 -3
- package/dist/{Markdown-1ips7myr.d.cts → Markdown-UXZdDjzs.d.cts} +3 -3
- package/dist/{Markdown-C6AsLHmd.mjs → Markdown-VxtPJ_yh.mjs} +4 -4
- package/dist/Markdown-VxtPJ_yh.mjs.map +1 -0
- package/dist/{MarkdownRendererContext-CAnuohIS.mjs → MarkdownRendererContext-EobUsERg.mjs} +1 -1
- package/dist/{MarkdownRendererContext-CAnuohIS.mjs.map → MarkdownRendererContext-EobUsERg.mjs.map} +1 -1
- package/dist/MarkdownRendererContext-cDEHvbw9.cjs +40 -0
- package/dist/{MarkdownRendererContext-BRNe808d.cjs.map → MarkdownRendererContext-cDEHvbw9.cjs.map} +1 -1
- package/dist/chunk-C0xms8kb.cjs +34 -0
- package/dist/components/index.cjs +78 -175
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +76 -174
- package/dist/components/index.mjs.map +1 -1
- package/dist/generative-ui/index.cjs +612 -0
- package/dist/generative-ui/index.cjs.map +1 -0
- package/dist/generative-ui/index.d.cts +341 -0
- package/dist/generative-ui/index.d.mts +341 -0
- package/dist/generative-ui/index.mjs +549 -0
- package/dist/generative-ui/index.mjs.map +1 -0
- package/dist/headless.cjs +3 -2
- package/dist/headless.d.cts +3 -3
- package/dist/headless.d.mts +3 -3
- package/dist/headless.mjs +2 -2
- package/dist/index.cjs +132 -162
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -19
- package/dist/index.d.mts +37 -19
- package/dist/index.mjs +131 -162
- package/dist/index.mjs.map +1 -1
- package/dist/polyfills/encoding.cjs +115 -5
- package/dist/polyfills/encoding.cjs.map +1 -1
- package/dist/polyfills/encoding.d.cts +31 -1
- package/dist/polyfills/encoding.d.mts +31 -1
- package/dist/polyfills/encoding.mjs +113 -6
- package/dist/polyfills/encoding.mjs.map +1 -1
- package/dist/polyfills/streams.cjs +1 -1
- package/dist/polyfills.cjs +218 -2
- package/dist/polyfills.cjs.map +1 -1
- package/dist/polyfills.mjs +217 -1
- package/dist/polyfills.mjs.map +1 -1
- package/package.json +51 -21
- package/project.json +6 -1
- package/scripts/__tests__/verify-polyfill-barrel.test.mjs +150 -0
- package/scripts/verify-polyfill-barrel.mjs +158 -11
- package/src/CopilotChat.tsx +114 -93
- package/src/CopilotKitProvider.tsx +101 -130
- package/src/CopilotPopup.tsx +2 -2
- package/src/CopilotSidebar.tsx +7 -5
- package/src/__mocks__/react-native.ts +31 -0
- package/src/__mocks__/test-copilotkit.tsx +9 -3
- package/src/__tests__/attachments-integration.test.tsx +15 -2
- package/src/__tests__/copilot-chat-agentid.test.tsx +15 -2
- package/src/__tests__/copilot-chat-attachments.test.tsx +15 -2
- package/src/__tests__/copilot-chat-configuration.test.tsx +82 -0
- package/src/__tests__/copilot-chat-threads.test.tsx +232 -0
- package/src/__tests__/copilot-popup.test.tsx +15 -2
- package/src/__tests__/copilot-sidebar.test.tsx +15 -2
- package/src/__tests__/copilotkit-alias-exports.test.ts +16 -0
- package/src/__tests__/copilotkit-provider.test.tsx +68 -73
- package/src/__tests__/generative-ui-harness.tsx +243 -0
- package/src/__tests__/generative-ui-provider-props.test-d.tsx +106 -0
- package/src/__tests__/generative-ui-rn-mock.tsx +54 -0
- package/src/__tests__/generative-ui-wiring.test.tsx +720 -0
- package/src/__tests__/generative-ui.test.tsx +1000 -0
- package/src/__tests__/headless-entry-surface.test.ts +979 -61
- package/src/__tests__/headless-integration.test.tsx +11 -1
- package/src/__tests__/use-attachments.test.ts +27 -2
- package/src/components/CopilotChat.tsx +106 -233
- package/src/components/CopilotModal.tsx +1 -1
- package/src/components/Markdown.tsx +4 -4
- package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +5 -1
- package/src/components/__tests__/CopilotChat.test.tsx +12 -4
- package/src/components/__tests__/CopilotChatInterrupt.test.tsx +208 -0
- package/src/components/__tests__/Markdown.code-alias.test.tsx +1 -1
- package/src/components/index.ts +6 -0
- package/src/components/messages/AssistantMessage.tsx +3 -3
- package/src/components/messages/TypingIndicator.tsx +4 -4
- package/src/generative-ui/GenerativeUIActivity.tsx +235 -0
- package/src/generative-ui/GenerativeUIProvider.tsx +171 -0
- package/src/generative-ui/GenerativeUISurface.tsx +303 -0
- package/src/generative-ui/host.tsx +138 -0
- package/src/generative-ui/index.ts +93 -0
- package/src/generative-ui/internal.ts +55 -0
- package/src/headless.ts +4 -0
- package/src/hooks/use-attachments.ts +95 -139
- package/src/index.ts +10 -4
- package/src/polyfills/__tests__/encoding-utf8.test.ts +112 -0
- package/src/polyfills/encoding.ts +160 -4
- package/src/types.d.ts +0 -13
- package/tsdown.config.ts +1 -0
- package/dist/CopilotKitProvider-BWjzCdHN.d.mts +0 -121
- package/dist/CopilotKitProvider-Btm10msB.d.cts +0 -121
- package/dist/CopilotKitProvider-Byw3cqe2.cjs.map +0 -1
- package/dist/CopilotKitProvider-CE4bc6CP.mjs.map +0 -1
- package/dist/Markdown-C6AsLHmd.mjs.map +0 -1
- package/dist/Markdown-C_9Re36O.cjs.map +0 -1
- package/dist/MarkdownRendererContext-BRNe808d.cjs +0 -72
- package/dist/streaming-fetch-Bm91EsRc.cjs +0 -225
- package/dist/streaming-fetch-Bm91EsRc.cjs.map +0 -1
- package/dist/streaming-fetch-Dm1oN4f2.mjs +0 -219
- package/dist/streaming-fetch-Dm1oN4f2.mjs.map +0 -1
package/dist/polyfills.mjs
CHANGED
|
@@ -3,8 +3,224 @@ import "./polyfills/encoding.mjs";
|
|
|
3
3
|
import "./polyfills/crypto.mjs";
|
|
4
4
|
import "./polyfills/dom.mjs";
|
|
5
5
|
import "./polyfills/location.mjs";
|
|
6
|
-
import { t as installStreamingFetch } from "./streaming-fetch-Dm1oN4f2.mjs";
|
|
7
6
|
|
|
7
|
+
//#region src/streaming-fetch.ts
|
|
8
|
+
function createAbortError() {
|
|
9
|
+
return new global.DOMException("The operation was aborted.", "AbortError");
|
|
10
|
+
}
|
|
11
|
+
function installStreamingFetch() {
|
|
12
|
+
try {
|
|
13
|
+
const testResponse = new Response("");
|
|
14
|
+
if (testResponse.body != null && typeof testResponse.body.getReader === "function") return;
|
|
15
|
+
} catch (e) {
|
|
16
|
+
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);
|
|
17
|
+
}
|
|
18
|
+
const IDLE_TIMEOUT_MS = 6e4;
|
|
19
|
+
const originalFetch = global.fetch;
|
|
20
|
+
const TextEncoder = global.TextEncoder;
|
|
21
|
+
const streamingFetch = function streamingFetch(input, init) {
|
|
22
|
+
const request = typeof input !== "string" && !(input instanceof URL) ? input : null;
|
|
23
|
+
let url;
|
|
24
|
+
if (typeof input === "string") url = input;
|
|
25
|
+
else if (input instanceof URL) url = input.href;
|
|
26
|
+
else url = input.url;
|
|
27
|
+
const method = init?.method || request?.method || "GET";
|
|
28
|
+
const headers = init?.headers || (request ? request.headers : {});
|
|
29
|
+
const body = init?.body ?? request?.body;
|
|
30
|
+
const signal = init?.signal || request?.signal;
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
if (signal?.aborted) {
|
|
33
|
+
reject(createAbortError());
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const xhr = new XMLHttpRequest();
|
|
37
|
+
xhr.open(method, url);
|
|
38
|
+
let idleTimer;
|
|
39
|
+
function resetIdleTimer() {
|
|
40
|
+
clearTimeout(idleTimer);
|
|
41
|
+
idleTimer = setTimeout(() => {
|
|
42
|
+
fail(/* @__PURE__ */ new TypeError("Network request timed out"));
|
|
43
|
+
xhr.abort();
|
|
44
|
+
}, IDLE_TIMEOUT_MS);
|
|
45
|
+
}
|
|
46
|
+
let headerEntries;
|
|
47
|
+
if (headers instanceof Headers) headerEntries = Array.from(headers.entries());
|
|
48
|
+
else if (Array.isArray(headers)) headerEntries = headers;
|
|
49
|
+
else headerEntries = Object.entries(headers);
|
|
50
|
+
for (const [key, value] of headerEntries) xhr.setRequestHeader(key, value);
|
|
51
|
+
xhr.responseType = "text";
|
|
52
|
+
let streamController = null;
|
|
53
|
+
let lastIndex = 0;
|
|
54
|
+
let streamClosed = false;
|
|
55
|
+
let settled = false;
|
|
56
|
+
const encoder = new TextEncoder();
|
|
57
|
+
let resolveFullText;
|
|
58
|
+
let rejectFullText;
|
|
59
|
+
const fullTextPromise = new Promise((res, rej) => {
|
|
60
|
+
resolveFullText = res;
|
|
61
|
+
rejectFullText = rej;
|
|
62
|
+
});
|
|
63
|
+
fullTextPromise.catch(() => {});
|
|
64
|
+
function closeStream() {
|
|
65
|
+
if (streamController && !streamClosed) {
|
|
66
|
+
streamClosed = true;
|
|
67
|
+
streamController.close();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function errorStream(err) {
|
|
71
|
+
if (streamController && !streamClosed) {
|
|
72
|
+
streamClosed = true;
|
|
73
|
+
streamController.error(err);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function flushChunks() {
|
|
77
|
+
if (streamController && !streamClosed && xhr.responseText.length > lastIndex) {
|
|
78
|
+
const newData = xhr.responseText.slice(lastIndex);
|
|
79
|
+
lastIndex = xhr.responseText.length;
|
|
80
|
+
streamController.enqueue(encoder.encode(newData));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Centralized error handler — errors the stream, rejects fullTextPromise,
|
|
84
|
+
* and rejects the outer fetch promise if not yet settled. */
|
|
85
|
+
function fail(err) {
|
|
86
|
+
clearTimeout(idleTimer);
|
|
87
|
+
cleanupAbortListener();
|
|
88
|
+
errorStream(err);
|
|
89
|
+
rejectFullText(err);
|
|
90
|
+
if (!settled) {
|
|
91
|
+
settled = true;
|
|
92
|
+
reject(err);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const onAbort = () => {
|
|
96
|
+
fail(createAbortError());
|
|
97
|
+
xhr.abort();
|
|
98
|
+
};
|
|
99
|
+
if (signal) signal.addEventListener("abort", onAbort);
|
|
100
|
+
function cleanupAbortListener() {
|
|
101
|
+
if (signal) signal.removeEventListener("abort", onAbort);
|
|
102
|
+
}
|
|
103
|
+
const stream = new ReadableStream({
|
|
104
|
+
start(controller) {
|
|
105
|
+
streamController = controller;
|
|
106
|
+
},
|
|
107
|
+
cancel() {
|
|
108
|
+
clearTimeout(idleTimer);
|
|
109
|
+
xhr.abort();
|
|
110
|
+
rejectFullText(createAbortError());
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
xhr.onprogress = function() {
|
|
114
|
+
resetIdleTimer();
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
try {
|
|
117
|
+
flushChunks();
|
|
118
|
+
} catch (err) {
|
|
119
|
+
fail(err instanceof Error ? err : new Error(String(err)));
|
|
120
|
+
xhr.abort();
|
|
121
|
+
}
|
|
122
|
+
}, 0);
|
|
123
|
+
};
|
|
124
|
+
xhr.onload = function() {
|
|
125
|
+
clearTimeout(idleTimer);
|
|
126
|
+
setTimeout(() => {
|
|
127
|
+
cleanupAbortListener();
|
|
128
|
+
try {
|
|
129
|
+
flushChunks();
|
|
130
|
+
} catch (err) {
|
|
131
|
+
fail(err instanceof Error ? err : new Error(String(err)));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
closeStream();
|
|
135
|
+
resolveFullText(xhr.responseText);
|
|
136
|
+
}, 0);
|
|
137
|
+
};
|
|
138
|
+
xhr.onerror = function() {
|
|
139
|
+
setTimeout(() => {
|
|
140
|
+
fail(/* @__PURE__ */ new TypeError("Network request failed"));
|
|
141
|
+
}, 0);
|
|
142
|
+
};
|
|
143
|
+
xhr.ontimeout = function() {
|
|
144
|
+
setTimeout(() => {
|
|
145
|
+
fail(/* @__PURE__ */ new TypeError("Network request timed out"));
|
|
146
|
+
}, 0);
|
|
147
|
+
};
|
|
148
|
+
let resp = null;
|
|
149
|
+
xhr.onreadystatechange = function() {
|
|
150
|
+
const readyState = xhr.readyState;
|
|
151
|
+
if (readyState < 4) resetIdleTimer();
|
|
152
|
+
const xhrStatus = xhr.status;
|
|
153
|
+
const xhrStatusText = xhr.statusText;
|
|
154
|
+
const rawHeaders = xhr.getAllResponseHeaders() || "";
|
|
155
|
+
setTimeout(() => {
|
|
156
|
+
if (readyState === 4 && !settled && !resp) {
|
|
157
|
+
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.`));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (readyState >= 2 && !resp && xhrStatus !== 0) {
|
|
161
|
+
const respHeaders = {};
|
|
162
|
+
for (const line of rawHeaders.trim().split("\r\n")) {
|
|
163
|
+
const idx = line.indexOf(": ");
|
|
164
|
+
if (idx > 0) respHeaders[line.slice(0, idx).toLowerCase()] = line.slice(idx + 2);
|
|
165
|
+
}
|
|
166
|
+
const responseHeaders = new Headers(respHeaders);
|
|
167
|
+
let bodyUsed = false;
|
|
168
|
+
resp = {
|
|
169
|
+
ok: xhrStatus >= 200 && xhrStatus < 300,
|
|
170
|
+
status: xhrStatus,
|
|
171
|
+
statusText: xhrStatusText,
|
|
172
|
+
url,
|
|
173
|
+
type: "basic",
|
|
174
|
+
redirected: false,
|
|
175
|
+
get bodyUsed() {
|
|
176
|
+
return bodyUsed;
|
|
177
|
+
},
|
|
178
|
+
headers: responseHeaders,
|
|
179
|
+
body: stream,
|
|
180
|
+
json: async () => {
|
|
181
|
+
bodyUsed = true;
|
|
182
|
+
const text = await fullTextPromise;
|
|
183
|
+
try {
|
|
184
|
+
return JSON.parse(text);
|
|
185
|
+
} catch (e) {
|
|
186
|
+
throw new TypeError(`Failed to parse JSON from ${method} ${url} (status ${xhrStatus}): ${text.length > 200 ? text.slice(0, 200) + "..." : text}`, { cause: e });
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
text: async () => {
|
|
190
|
+
bodyUsed = true;
|
|
191
|
+
return fullTextPromise;
|
|
192
|
+
},
|
|
193
|
+
arrayBuffer: async () => {
|
|
194
|
+
bodyUsed = true;
|
|
195
|
+
return encoder.encode(await fullTextPromise).buffer;
|
|
196
|
+
},
|
|
197
|
+
blob: async () => {
|
|
198
|
+
bodyUsed = true;
|
|
199
|
+
const buf = encoder.encode(await fullTextPromise);
|
|
200
|
+
if (typeof Blob !== "undefined") return new Blob([buf], { type: responseHeaders.get("content-type") || "" });
|
|
201
|
+
throw new Error("Blob is not available in this React Native environment.");
|
|
202
|
+
},
|
|
203
|
+
clone: () => {
|
|
204
|
+
throw new Error("Response.clone() is not supported by the React Native streaming fetch polyfill.");
|
|
205
|
+
},
|
|
206
|
+
formData: async () => {
|
|
207
|
+
throw new Error("Response.formData() is not supported by the React Native streaming fetch polyfill.");
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
settled = true;
|
|
211
|
+
resolve(resp);
|
|
212
|
+
}
|
|
213
|
+
}, 0);
|
|
214
|
+
};
|
|
215
|
+
resetIdleTimer();
|
|
216
|
+
xhr.send(body ?? null);
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
streamingFetch.__originalFetch = originalFetch;
|
|
220
|
+
global.fetch = streamingFetch;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
//#endregion
|
|
8
224
|
//#region src/polyfills.ts
|
|
9
225
|
installStreamingFetch();
|
|
10
226
|
|
package/dist/polyfills.mjs.map
CHANGED
|
@@ -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,M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AAChB,mBAAW;QACX,MAAM,OAAO,MAAM;AACnB,YAAI;AACF,gBAAO,KAAK,MAAM,KAAK;iBAChB,GAAG;AACV,eAAM,IAAI,UACR,6BAA6B,OAAO,GAAG,IAAI,WAAW,UAAU,KAC9D,KAAK,SAAS,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,QAAQ,QAEnD,EAAE,OAAO,GAAG,CACb;;;OAGL,MAAM,YAAY;AAChB,mBAAW;AACX,eAAO;;OAET,aAAa,YAAY;AACvB,mBAAW;AACX,eAAO,QAAQ,OAAO,MAAM,gBAAgB,CAAC;;OAE/C,MAAM,YAAY;AAChB,mBAAW;QACX,MAAM,MAAM,QAAQ,OAAO,MAAM,gBAAgB;AACjD,YAAI,OAAO,SAAS,YAClB,QAAO,IAAI,KAAK,CAAC,IAAI,EAAE,EACrB,MAAM,gBAAgB,IAAI,eAAe,IAAI,IAC9C,CAAC;AAEJ,cAAM,IAAI,MACR,0DACD;;OAEH,aAAa;AACX,cAAM,IAAI,MACR,kFACD;;OAEH,UAAU,YAAY;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.
|
|
3
|
+
"version": "2.0.0-rc.50",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
],
|
|
13
13
|
"homepage": "https://github.com/CopilotKit/CopilotKit",
|
|
14
14
|
"license": "MIT",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20"
|
|
17
|
+
},
|
|
15
18
|
"repository": {
|
|
16
19
|
"type": "git",
|
|
17
20
|
"url": "https://github.com/CopilotKit/CopilotKit.git"
|
|
@@ -20,16 +23,51 @@
|
|
|
20
23
|
"sideEffects": [
|
|
21
24
|
"./src/index.*",
|
|
22
25
|
"./src/headless.*",
|
|
26
|
+
"./src/components/index.*",
|
|
27
|
+
"./src/generative-ui/index.*",
|
|
23
28
|
"./src/polyfills.*",
|
|
24
29
|
"./src/polyfills/**/*",
|
|
25
30
|
"./dist/index.*",
|
|
26
31
|
"./dist/headless.*",
|
|
32
|
+
"./dist/components/index.*",
|
|
33
|
+
"./dist/generative-ui/index.*",
|
|
27
34
|
"./dist/polyfills.*",
|
|
28
35
|
"./dist/polyfills/**/*"
|
|
29
36
|
],
|
|
30
37
|
"main": "./dist/index.cjs",
|
|
31
38
|
"module": "./dist/index.mjs",
|
|
32
39
|
"types": "./dist/index.d.cts",
|
|
40
|
+
"typesVersions": {
|
|
41
|
+
"*": {
|
|
42
|
+
"headless": [
|
|
43
|
+
"./dist/headless.d.cts"
|
|
44
|
+
],
|
|
45
|
+
"generative-ui": [
|
|
46
|
+
"./dist/generative-ui/index.d.cts"
|
|
47
|
+
],
|
|
48
|
+
"polyfills": [
|
|
49
|
+
"./dist/polyfills.d.cts"
|
|
50
|
+
],
|
|
51
|
+
"polyfills/streams": [
|
|
52
|
+
"./dist/polyfills/streams.d.cts"
|
|
53
|
+
],
|
|
54
|
+
"polyfills/encoding": [
|
|
55
|
+
"./dist/polyfills/encoding.d.cts"
|
|
56
|
+
],
|
|
57
|
+
"polyfills/crypto": [
|
|
58
|
+
"./dist/polyfills/crypto.d.cts"
|
|
59
|
+
],
|
|
60
|
+
"polyfills/dom": [
|
|
61
|
+
"./dist/polyfills/dom.d.cts"
|
|
62
|
+
],
|
|
63
|
+
"polyfills/location": [
|
|
64
|
+
"./dist/polyfills/location.d.cts"
|
|
65
|
+
],
|
|
66
|
+
"components": [
|
|
67
|
+
"./dist/components/index.d.cts"
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
},
|
|
33
71
|
"exports": {
|
|
34
72
|
".": {
|
|
35
73
|
"import": "./dist/index.mjs",
|
|
@@ -39,6 +77,10 @@
|
|
|
39
77
|
"import": "./dist/headless.mjs",
|
|
40
78
|
"require": "./dist/headless.cjs"
|
|
41
79
|
},
|
|
80
|
+
"./generative-ui": {
|
|
81
|
+
"import": "./dist/generative-ui/index.mjs",
|
|
82
|
+
"require": "./dist/generative-ui/index.cjs"
|
|
83
|
+
},
|
|
42
84
|
"./polyfills": {
|
|
43
85
|
"import": "./dist/polyfills.mjs",
|
|
44
86
|
"require": "./dist/polyfills.cjs"
|
|
@@ -73,12 +115,11 @@
|
|
|
73
115
|
"access": "public"
|
|
74
116
|
},
|
|
75
117
|
"dependencies": {
|
|
76
|
-
"@ag-ui/client": "1.0.
|
|
77
|
-
"@copilotkit/core": "2.0.0-rc.
|
|
78
|
-
"@copilotkit/markdown
|
|
79
|
-
"@copilotkit/react-core": "2.0.0-rc.
|
|
80
|
-
"@copilotkit/shared": "2.0.0-rc.
|
|
81
|
-
"text-encoding": "^0.7.0",
|
|
118
|
+
"@ag-ui/client": "1.0.4",
|
|
119
|
+
"@copilotkit/core": "2.0.0-rc.50",
|
|
120
|
+
"@copilotkit/markdown": "2.0.0-rc.50",
|
|
121
|
+
"@copilotkit/react-core": "2.0.0-rc.50",
|
|
122
|
+
"@copilotkit/shared": "2.0.0-rc.50",
|
|
82
123
|
"web-streams-polyfill": "^4.2.0"
|
|
83
124
|
},
|
|
84
125
|
"devDependencies": {
|
|
@@ -90,17 +131,15 @@
|
|
|
90
131
|
"react-dom": "^19.1.0",
|
|
91
132
|
"tsdown": "^0.20.3",
|
|
92
133
|
"typescript": "^5.8.3",
|
|
93
|
-
"vitest": "^3.2.4"
|
|
134
|
+
"vitest": "^3.2.4",
|
|
135
|
+
"zod": "^4.2.0"
|
|
94
136
|
},
|
|
95
137
|
"peerDependencies": {
|
|
96
138
|
"@gorhom/bottom-sheet": "^5.0.0",
|
|
97
139
|
"expo-document-picker": ">=12.0.0",
|
|
98
140
|
"expo-file-system": ">=17.0.0",
|
|
99
141
|
"react": "^18 || ^19",
|
|
100
|
-
"react-native": ">=0.70"
|
|
101
|
-
"react-native-gesture-handler": ">=2.0.0",
|
|
102
|
-
"react-native-reanimated": ">=3.0.0",
|
|
103
|
-
"zod": ">=3.0.0"
|
|
142
|
+
"react-native": ">=0.70"
|
|
104
143
|
},
|
|
105
144
|
"peerDependenciesMeta": {
|
|
106
145
|
"@gorhom/bottom-sheet": {
|
|
@@ -111,15 +150,6 @@
|
|
|
111
150
|
},
|
|
112
151
|
"expo-file-system": {
|
|
113
152
|
"optional": true
|
|
114
|
-
},
|
|
115
|
-
"react-native-gesture-handler": {
|
|
116
|
-
"optional": true
|
|
117
|
-
},
|
|
118
|
-
"react-native-reanimated": {
|
|
119
|
-
"optional": true
|
|
120
|
-
},
|
|
121
|
-
"zod": {
|
|
122
|
-
"optional": true
|
|
123
153
|
}
|
|
124
154
|
},
|
|
125
155
|
"scripts": {
|
package/project.json
CHANGED
|
@@ -15,7 +15,12 @@
|
|
|
15
15
|
"outputs": ["{projectRoot}/dist/**"]
|
|
16
16
|
},
|
|
17
17
|
"test": {
|
|
18
|
-
"inputs": [
|
|
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
|
});
|