@copilotkit/react-native 1.63.2-canary.1784918757 → 1.63.3-canary.rc-1
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/USAGE.md +30 -0
- package/dist/{RenderToolContext-CszHyes6.mjs → RenderToolContext-D8M-JhD1.mjs} +1 -1
- package/dist/{RenderToolContext-CszHyes6.mjs.map → RenderToolContext-D8M-JhD1.mjs.map} +1 -1
- package/dist/components/index.mjs +1 -1
- package/dist/headless.cjs +100 -0
- package/dist/headless.d.cts +6 -0
- package/dist/headless.d.mts +6 -0
- package/dist/headless.mjs +6 -0
- package/dist/index.cjs +3 -158
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -163
- package/dist/index.d.mts +5 -163
- package/dist/index.mjs +7 -161
- package/dist/index.mjs.map +1 -1
- package/dist/polyfills.cjs +2 -204
- package/dist/polyfills.cjs.map +1 -1
- package/dist/polyfills.mjs +1 -202
- package/dist/polyfills.mjs.map +1 -1
- package/dist/streaming-fetch-BTESzLKX.cjs +211 -0
- package/dist/streaming-fetch-BTESzLKX.cjs.map +1 -0
- package/dist/streaming-fetch-BnQh3vBz.mjs +205 -0
- package/dist/streaming-fetch-BnQh3vBz.mjs.map +1 -0
- package/dist/useRenderTool-9YDIfZ0D.d.mts +164 -0
- package/dist/useRenderTool-BugVTDoM.d.cts +164 -0
- package/dist/useRenderTool-DLavcsVB.cjs +176 -0
- package/dist/useRenderTool-DLavcsVB.cjs.map +1 -0
- package/dist/useRenderTool-DUqpS97B.mjs +164 -0
- package/dist/useRenderTool-DUqpS97B.mjs.map +1 -0
- package/package.json +9 -4
- package/src/__tests__/headless-entry-surface.test.ts +151 -0
- package/src/headless.ts +110 -0
- package/src/index.ts +19 -89
- package/tsdown.config.ts +1 -0
|
@@ -0,0 +1,205 @@
|
|
|
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 originalFetch = global.fetch;
|
|
13
|
+
const TextEncoder = global.TextEncoder;
|
|
14
|
+
const streamingFetch = function streamingFetch(input, init) {
|
|
15
|
+
const request = typeof input !== "string" && !(input instanceof URL) ? input : null;
|
|
16
|
+
let url;
|
|
17
|
+
if (typeof input === "string") url = input;
|
|
18
|
+
else if (input instanceof URL) url = input.href;
|
|
19
|
+
else url = input.url;
|
|
20
|
+
const method = init?.method || request?.method || "GET";
|
|
21
|
+
const headers = init?.headers || (request ? request.headers : {});
|
|
22
|
+
const body = init?.body ?? request?.body;
|
|
23
|
+
const signal = init?.signal || request?.signal;
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
if (signal?.aborted) {
|
|
26
|
+
reject(createAbortError());
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const xhr = new XMLHttpRequest();
|
|
30
|
+
xhr.open(method, url);
|
|
31
|
+
xhr.timeout = 6e4;
|
|
32
|
+
let headerEntries;
|
|
33
|
+
if (headers instanceof Headers) headerEntries = Array.from(headers.entries());
|
|
34
|
+
else if (Array.isArray(headers)) headerEntries = headers;
|
|
35
|
+
else headerEntries = Object.entries(headers);
|
|
36
|
+
for (const [key, value] of headerEntries) xhr.setRequestHeader(key, value);
|
|
37
|
+
xhr.responseType = "text";
|
|
38
|
+
let streamController = null;
|
|
39
|
+
let lastIndex = 0;
|
|
40
|
+
let streamClosed = false;
|
|
41
|
+
let settled = false;
|
|
42
|
+
const encoder = new TextEncoder();
|
|
43
|
+
let resolveFullText;
|
|
44
|
+
let rejectFullText;
|
|
45
|
+
const fullTextPromise = new Promise((res, rej) => {
|
|
46
|
+
resolveFullText = res;
|
|
47
|
+
rejectFullText = rej;
|
|
48
|
+
});
|
|
49
|
+
fullTextPromise.catch(() => {});
|
|
50
|
+
function closeStream() {
|
|
51
|
+
if (streamController && !streamClosed) {
|
|
52
|
+
streamClosed = true;
|
|
53
|
+
streamController.close();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function errorStream(err) {
|
|
57
|
+
if (streamController && !streamClosed) {
|
|
58
|
+
streamClosed = true;
|
|
59
|
+
streamController.error(err);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function flushChunks() {
|
|
63
|
+
if (streamController && !streamClosed && xhr.responseText.length > lastIndex) {
|
|
64
|
+
const newData = xhr.responseText.slice(lastIndex);
|
|
65
|
+
lastIndex = xhr.responseText.length;
|
|
66
|
+
streamController.enqueue(encoder.encode(newData));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Centralized error handler — errors the stream, rejects fullTextPromise,
|
|
70
|
+
* and rejects the outer fetch promise if not yet settled. */
|
|
71
|
+
function fail(err) {
|
|
72
|
+
cleanupAbortListener();
|
|
73
|
+
errorStream(err);
|
|
74
|
+
rejectFullText(err);
|
|
75
|
+
if (!settled) {
|
|
76
|
+
settled = true;
|
|
77
|
+
reject(err);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const onAbort = () => {
|
|
81
|
+
fail(createAbortError());
|
|
82
|
+
xhr.abort();
|
|
83
|
+
};
|
|
84
|
+
if (signal) signal.addEventListener("abort", onAbort);
|
|
85
|
+
function cleanupAbortListener() {
|
|
86
|
+
if (signal) signal.removeEventListener("abort", onAbort);
|
|
87
|
+
}
|
|
88
|
+
const stream = new ReadableStream({
|
|
89
|
+
start(controller) {
|
|
90
|
+
streamController = controller;
|
|
91
|
+
},
|
|
92
|
+
cancel() {
|
|
93
|
+
xhr.abort();
|
|
94
|
+
rejectFullText(createAbortError());
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
xhr.onprogress = function() {
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
try {
|
|
100
|
+
flushChunks();
|
|
101
|
+
} catch (err) {
|
|
102
|
+
fail(err instanceof Error ? err : new Error(String(err)));
|
|
103
|
+
xhr.abort();
|
|
104
|
+
}
|
|
105
|
+
}, 0);
|
|
106
|
+
};
|
|
107
|
+
xhr.onload = function() {
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
cleanupAbortListener();
|
|
110
|
+
try {
|
|
111
|
+
flushChunks();
|
|
112
|
+
} catch (err) {
|
|
113
|
+
fail(err instanceof Error ? err : new Error(String(err)));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
closeStream();
|
|
117
|
+
resolveFullText(xhr.responseText);
|
|
118
|
+
}, 0);
|
|
119
|
+
};
|
|
120
|
+
xhr.onerror = function() {
|
|
121
|
+
setTimeout(() => {
|
|
122
|
+
fail(/* @__PURE__ */ new TypeError("Network request failed"));
|
|
123
|
+
}, 0);
|
|
124
|
+
};
|
|
125
|
+
xhr.ontimeout = function() {
|
|
126
|
+
setTimeout(() => {
|
|
127
|
+
fail(/* @__PURE__ */ new TypeError("Network request timed out"));
|
|
128
|
+
}, 0);
|
|
129
|
+
};
|
|
130
|
+
let resp = null;
|
|
131
|
+
xhr.onreadystatechange = function() {
|
|
132
|
+
const readyState = xhr.readyState;
|
|
133
|
+
const xhrStatus = xhr.status;
|
|
134
|
+
const xhrStatusText = xhr.statusText;
|
|
135
|
+
const rawHeaders = xhr.getAllResponseHeaders() || "";
|
|
136
|
+
setTimeout(() => {
|
|
137
|
+
if (readyState === 4 && !settled && !resp) {
|
|
138
|
+
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.`));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (readyState >= 2 && !resp && xhrStatus !== 0) {
|
|
142
|
+
const respHeaders = {};
|
|
143
|
+
for (const line of rawHeaders.trim().split("\r\n")) {
|
|
144
|
+
const idx = line.indexOf(": ");
|
|
145
|
+
if (idx > 0) respHeaders[line.slice(0, idx).toLowerCase()] = line.slice(idx + 2);
|
|
146
|
+
}
|
|
147
|
+
const responseHeaders = new Headers(respHeaders);
|
|
148
|
+
let bodyUsed = false;
|
|
149
|
+
resp = {
|
|
150
|
+
ok: xhrStatus >= 200 && xhrStatus < 300,
|
|
151
|
+
status: xhrStatus,
|
|
152
|
+
statusText: xhrStatusText,
|
|
153
|
+
url,
|
|
154
|
+
type: "basic",
|
|
155
|
+
redirected: false,
|
|
156
|
+
get bodyUsed() {
|
|
157
|
+
return bodyUsed;
|
|
158
|
+
},
|
|
159
|
+
headers: responseHeaders,
|
|
160
|
+
body: stream,
|
|
161
|
+
json: async () => {
|
|
162
|
+
bodyUsed = true;
|
|
163
|
+
const text = await fullTextPromise;
|
|
164
|
+
try {
|
|
165
|
+
return JSON.parse(text);
|
|
166
|
+
} catch (e) {
|
|
167
|
+
throw new TypeError(`Failed to parse JSON from ${method} ${url} (status ${xhrStatus}): ${text.length > 200 ? text.slice(0, 200) + "..." : text}`, { cause: e });
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
text: async () => {
|
|
171
|
+
bodyUsed = true;
|
|
172
|
+
return fullTextPromise;
|
|
173
|
+
},
|
|
174
|
+
arrayBuffer: async () => {
|
|
175
|
+
bodyUsed = true;
|
|
176
|
+
return encoder.encode(await fullTextPromise).buffer;
|
|
177
|
+
},
|
|
178
|
+
blob: async () => {
|
|
179
|
+
bodyUsed = true;
|
|
180
|
+
const buf = encoder.encode(await fullTextPromise);
|
|
181
|
+
if (typeof Blob !== "undefined") return new Blob([buf], { type: responseHeaders.get("content-type") || "" });
|
|
182
|
+
throw new Error("Blob is not available in this React Native environment.");
|
|
183
|
+
},
|
|
184
|
+
clone: () => {
|
|
185
|
+
throw new Error("Response.clone() is not supported by the React Native streaming fetch polyfill.");
|
|
186
|
+
},
|
|
187
|
+
formData: async () => {
|
|
188
|
+
throw new Error("Response.formData() is not supported by the React Native streaming fetch polyfill.");
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
settled = true;
|
|
192
|
+
resolve(resp);
|
|
193
|
+
}
|
|
194
|
+
}, 0);
|
|
195
|
+
};
|
|
196
|
+
xhr.send(body ?? null);
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
streamingFetch.__originalFetch = originalFetch;
|
|
200
|
+
global.fetch = streamingFetch;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
export { installStreamingFetch as t };
|
|
205
|
+
//# sourceMappingURL=streaming-fetch-BnQh3vBz.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming-fetch-BnQh3vBz.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 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 // Default 60s timeout to prevent hanging on stalled mobile connections\n // (WiFi→cellular transitions, tunnels, serverless cold starts).\n // Callers can still use AbortSignal.timeout() for finer control.\n xhr.timeout = 60_000;\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 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 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 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 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 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 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,KAA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Q,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,OAAI,KAAK,QAAQ,KAAK;IACtB;;AAIJ,CAAC,eAAuB,kBAAkB;AAC1C,QAAO,QAAQ"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { DebugConfig, StandardSchemaV1 } from "@copilotkit/shared";
|
|
3
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
|
+
import { CopilotKitCoreErrorCode } from "@copilotkit/core";
|
|
5
|
+
|
|
6
|
+
//#region src/CopilotKitProvider.d.ts
|
|
7
|
+
interface CopilotKitNativeProviderProps {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
/** URL of the CopilotKit runtime endpoint */
|
|
10
|
+
runtimeUrl: string;
|
|
11
|
+
/** Custom headers sent with every request */
|
|
12
|
+
headers?: Record<string, string> | (() => Record<string, string>);
|
|
13
|
+
/**
|
|
14
|
+
* Credentials mode for fetch requests (e.g., "include" for HTTP-only cookies in cross-origin requests).
|
|
15
|
+
*/
|
|
16
|
+
credentials?: RequestCredentials;
|
|
17
|
+
/** Whether the runtime uses a single-route endpoint */
|
|
18
|
+
useSingleEndpoint?: boolean;
|
|
19
|
+
/** Custom properties forwarded to agents */
|
|
20
|
+
properties?: Record<string, unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* Error handler called when CopilotKit encounters an error.
|
|
23
|
+
* Fires for all error types (runtime connection failures, agent errors, tool errors).
|
|
24
|
+
* If not provided, errors are logged to console.error.
|
|
25
|
+
*/
|
|
26
|
+
onError?: (event: {
|
|
27
|
+
error: Error;
|
|
28
|
+
code: CopilotKitCoreErrorCode;
|
|
29
|
+
context: Record<string, any>;
|
|
30
|
+
}) => void | Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Enable debug logging for the client-side event pipeline.
|
|
33
|
+
* When `true`, enables verbose logging from the core instance.
|
|
34
|
+
*/
|
|
35
|
+
debug?: DebugConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Default throttle interval (ms) for `onMessagesChanged` / `onStateChanged`
|
|
38
|
+
* subscriptions. Individual subscriptions can override with their own `throttleMs`.
|
|
39
|
+
*/
|
|
40
|
+
defaultThrottleMs?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* CopilotKit provider for React Native.
|
|
44
|
+
*
|
|
45
|
+
* A lightweight alternative to the web CopilotKitProvider that avoids
|
|
46
|
+
* web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
|
|
47
|
+
*
|
|
48
|
+
* Polyfills are auto-imported when `@copilotkit/react-native` is loaded,
|
|
49
|
+
* so a separate `import "@copilotkit/react-native/polyfills"` is no longer
|
|
50
|
+
* required (though it remains available for advanced use).
|
|
51
|
+
*
|
|
52
|
+
* Usage:
|
|
53
|
+
* ```tsx
|
|
54
|
+
* import { CopilotKitProvider } from "@copilotkit/react-native";
|
|
55
|
+
*
|
|
56
|
+
* function App() {
|
|
57
|
+
* return (
|
|
58
|
+
* <CopilotKitProvider runtimeUrl="https://your-runtime/api/copilotkit">
|
|
59
|
+
* <ChatScreen />
|
|
60
|
+
* </CopilotKitProvider>
|
|
61
|
+
* );
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps>;
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/hooks/RenderToolContext.d.ts
|
|
68
|
+
/**
|
|
69
|
+
* Props passed to a render tool function.
|
|
70
|
+
*/
|
|
71
|
+
interface RenderToolProps<T = Record<string, unknown>> {
|
|
72
|
+
args: T;
|
|
73
|
+
status: "executing" | "complete";
|
|
74
|
+
result?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A render function that returns a React Native element for a tool call.
|
|
78
|
+
* Returns `ReactElement | null` (not ReactNode) because React Native's
|
|
79
|
+
* FlatList cannot render strings or portals.
|
|
80
|
+
*/
|
|
81
|
+
type RenderToolFunction<T = Record<string, unknown>> = (props: RenderToolProps<T>) => React.ReactElement | null;
|
|
82
|
+
/**
|
|
83
|
+
* The registry maps tool names to their render functions.
|
|
84
|
+
*/
|
|
85
|
+
type RenderToolRegistry = Map<string, RenderToolFunction>;
|
|
86
|
+
/**
|
|
87
|
+
* Provider that maintains the render tool registry.
|
|
88
|
+
* Should be nested inside CopilotKitProvider.
|
|
89
|
+
*/
|
|
90
|
+
declare function RenderToolProvider({
|
|
91
|
+
children
|
|
92
|
+
}: {
|
|
93
|
+
children: React.ReactNode;
|
|
94
|
+
}): react_jsx_runtime0.JSX.Element;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the current render tool registry (a Map of tool name to render function).
|
|
97
|
+
* Re-renders when the registry changes.
|
|
98
|
+
*
|
|
99
|
+
* @throws if called outside of RenderToolProvider
|
|
100
|
+
*/
|
|
101
|
+
declare function useRenderToolRegistry(): RenderToolRegistry;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/hooks/useRenderTool.d.ts
|
|
104
|
+
/**
|
|
105
|
+
* Options for the useRenderTool hook.
|
|
106
|
+
*/
|
|
107
|
+
interface UseRenderToolOptions<T extends Record<string, unknown>> {
|
|
108
|
+
/** Unique name for the tool. Must match what the agent calls. */
|
|
109
|
+
name: string;
|
|
110
|
+
/** Human-readable description shown to the agent. */
|
|
111
|
+
description: string;
|
|
112
|
+
/**
|
|
113
|
+
* Schema describing the tool's parameters.
|
|
114
|
+
* Accepts any StandardSchemaV1-compatible schema (Zod, Valibot, ArkType, etc.).
|
|
115
|
+
*/
|
|
116
|
+
parameters: StandardSchemaV1<unknown, T>;
|
|
117
|
+
/**
|
|
118
|
+
* Render function that returns a React Native element for the tool call.
|
|
119
|
+
* Called by CopilotChat when it encounters a tool call message for this tool.
|
|
120
|
+
*
|
|
121
|
+
* Returns ReactElement | null (not ReactNode) because React Native's
|
|
122
|
+
* FlatList cannot render strings or portals.
|
|
123
|
+
*/
|
|
124
|
+
render: RenderToolFunction<T>;
|
|
125
|
+
/**
|
|
126
|
+
* Optional handler executed when the tool is called.
|
|
127
|
+
* If omitted, the tool is render-only (the render function shows UI
|
|
128
|
+
* but the tool returns no result to the agent).
|
|
129
|
+
*/
|
|
130
|
+
handler?: (args: T) => Promise<unknown>;
|
|
131
|
+
/**
|
|
132
|
+
* Optional agent ID to scope this tool to a specific agent.
|
|
133
|
+
*/
|
|
134
|
+
agentId?: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Hook that registers a frontend tool AND a render function for it.
|
|
138
|
+
*
|
|
139
|
+
* This bridges `useFrontendTool` (which handles tool registration and
|
|
140
|
+
* handler execution) with a render registry so that CopilotChat can
|
|
141
|
+
* render React Native elements inline when it encounters tool call messages.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```tsx
|
|
145
|
+
* useRenderTool({
|
|
146
|
+
* name: "showWeather",
|
|
147
|
+
* description: "Display weather information",
|
|
148
|
+
* parameters: z.object({ city: z.string(), temp: z.number() }),
|
|
149
|
+
* render: ({ args, status }) => (
|
|
150
|
+
* <View>
|
|
151
|
+
* <Text>{args.city}: {args.temp}</Text>
|
|
152
|
+
* {status === "executing" && <ActivityIndicator />}
|
|
153
|
+
* </View>
|
|
154
|
+
* ),
|
|
155
|
+
* handler: async ({ city }) => {
|
|
156
|
+
* return { forecast: "sunny" };
|
|
157
|
+
* },
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
declare function useRenderTool<T extends Record<string, unknown> = Record<string, unknown>>(options: UseRenderToolOptions<T>, deps?: ReadonlyArray<unknown>): void;
|
|
162
|
+
//#endregion
|
|
163
|
+
export { useRenderToolRegistry as a, RenderToolProvider as i, useRenderTool as n, CopilotKitNativeProviderProps as o, RenderToolProps as r, CopilotKitProvider as s, UseRenderToolOptions as t };
|
|
164
|
+
//# sourceMappingURL=useRenderTool-9YDIfZ0D.d.mts.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
+
import React, { ReactNode } from "react";
|
|
3
|
+
import { CopilotKitCoreErrorCode } from "@copilotkit/core";
|
|
4
|
+
import { DebugConfig, StandardSchemaV1 } from "@copilotkit/shared";
|
|
5
|
+
|
|
6
|
+
//#region src/CopilotKitProvider.d.ts
|
|
7
|
+
interface CopilotKitNativeProviderProps {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
/** URL of the CopilotKit runtime endpoint */
|
|
10
|
+
runtimeUrl: string;
|
|
11
|
+
/** Custom headers sent with every request */
|
|
12
|
+
headers?: Record<string, string> | (() => Record<string, string>);
|
|
13
|
+
/**
|
|
14
|
+
* Credentials mode for fetch requests (e.g., "include" for HTTP-only cookies in cross-origin requests).
|
|
15
|
+
*/
|
|
16
|
+
credentials?: RequestCredentials;
|
|
17
|
+
/** Whether the runtime uses a single-route endpoint */
|
|
18
|
+
useSingleEndpoint?: boolean;
|
|
19
|
+
/** Custom properties forwarded to agents */
|
|
20
|
+
properties?: Record<string, unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* Error handler called when CopilotKit encounters an error.
|
|
23
|
+
* Fires for all error types (runtime connection failures, agent errors, tool errors).
|
|
24
|
+
* If not provided, errors are logged to console.error.
|
|
25
|
+
*/
|
|
26
|
+
onError?: (event: {
|
|
27
|
+
error: Error;
|
|
28
|
+
code: CopilotKitCoreErrorCode;
|
|
29
|
+
context: Record<string, any>;
|
|
30
|
+
}) => void | Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Enable debug logging for the client-side event pipeline.
|
|
33
|
+
* When `true`, enables verbose logging from the core instance.
|
|
34
|
+
*/
|
|
35
|
+
debug?: DebugConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Default throttle interval (ms) for `onMessagesChanged` / `onStateChanged`
|
|
38
|
+
* subscriptions. Individual subscriptions can override with their own `throttleMs`.
|
|
39
|
+
*/
|
|
40
|
+
defaultThrottleMs?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* CopilotKit provider for React Native.
|
|
44
|
+
*
|
|
45
|
+
* A lightweight alternative to the web CopilotKitProvider that avoids
|
|
46
|
+
* web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
|
|
47
|
+
*
|
|
48
|
+
* Polyfills are auto-imported when `@copilotkit/react-native` is loaded,
|
|
49
|
+
* so a separate `import "@copilotkit/react-native/polyfills"` is no longer
|
|
50
|
+
* required (though it remains available for advanced use).
|
|
51
|
+
*
|
|
52
|
+
* Usage:
|
|
53
|
+
* ```tsx
|
|
54
|
+
* import { CopilotKitProvider } from "@copilotkit/react-native";
|
|
55
|
+
*
|
|
56
|
+
* function App() {
|
|
57
|
+
* return (
|
|
58
|
+
* <CopilotKitProvider runtimeUrl="https://your-runtime/api/copilotkit">
|
|
59
|
+
* <ChatScreen />
|
|
60
|
+
* </CopilotKitProvider>
|
|
61
|
+
* );
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps>;
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/hooks/RenderToolContext.d.ts
|
|
68
|
+
/**
|
|
69
|
+
* Props passed to a render tool function.
|
|
70
|
+
*/
|
|
71
|
+
interface RenderToolProps<T = Record<string, unknown>> {
|
|
72
|
+
args: T;
|
|
73
|
+
status: "executing" | "complete";
|
|
74
|
+
result?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A render function that returns a React Native element for a tool call.
|
|
78
|
+
* Returns `ReactElement | null` (not ReactNode) because React Native's
|
|
79
|
+
* FlatList cannot render strings or portals.
|
|
80
|
+
*/
|
|
81
|
+
type RenderToolFunction<T = Record<string, unknown>> = (props: RenderToolProps<T>) => React.ReactElement | null;
|
|
82
|
+
/**
|
|
83
|
+
* The registry maps tool names to their render functions.
|
|
84
|
+
*/
|
|
85
|
+
type RenderToolRegistry = Map<string, RenderToolFunction>;
|
|
86
|
+
/**
|
|
87
|
+
* Provider that maintains the render tool registry.
|
|
88
|
+
* Should be nested inside CopilotKitProvider.
|
|
89
|
+
*/
|
|
90
|
+
declare function RenderToolProvider({
|
|
91
|
+
children
|
|
92
|
+
}: {
|
|
93
|
+
children: React.ReactNode;
|
|
94
|
+
}): react_jsx_runtime0.JSX.Element;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the current render tool registry (a Map of tool name to render function).
|
|
97
|
+
* Re-renders when the registry changes.
|
|
98
|
+
*
|
|
99
|
+
* @throws if called outside of RenderToolProvider
|
|
100
|
+
*/
|
|
101
|
+
declare function useRenderToolRegistry(): RenderToolRegistry;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/hooks/useRenderTool.d.ts
|
|
104
|
+
/**
|
|
105
|
+
* Options for the useRenderTool hook.
|
|
106
|
+
*/
|
|
107
|
+
interface UseRenderToolOptions<T extends Record<string, unknown>> {
|
|
108
|
+
/** Unique name for the tool. Must match what the agent calls. */
|
|
109
|
+
name: string;
|
|
110
|
+
/** Human-readable description shown to the agent. */
|
|
111
|
+
description: string;
|
|
112
|
+
/**
|
|
113
|
+
* Schema describing the tool's parameters.
|
|
114
|
+
* Accepts any StandardSchemaV1-compatible schema (Zod, Valibot, ArkType, etc.).
|
|
115
|
+
*/
|
|
116
|
+
parameters: StandardSchemaV1<unknown, T>;
|
|
117
|
+
/**
|
|
118
|
+
* Render function that returns a React Native element for the tool call.
|
|
119
|
+
* Called by CopilotChat when it encounters a tool call message for this tool.
|
|
120
|
+
*
|
|
121
|
+
* Returns ReactElement | null (not ReactNode) because React Native's
|
|
122
|
+
* FlatList cannot render strings or portals.
|
|
123
|
+
*/
|
|
124
|
+
render: RenderToolFunction<T>;
|
|
125
|
+
/**
|
|
126
|
+
* Optional handler executed when the tool is called.
|
|
127
|
+
* If omitted, the tool is render-only (the render function shows UI
|
|
128
|
+
* but the tool returns no result to the agent).
|
|
129
|
+
*/
|
|
130
|
+
handler?: (args: T) => Promise<unknown>;
|
|
131
|
+
/**
|
|
132
|
+
* Optional agent ID to scope this tool to a specific agent.
|
|
133
|
+
*/
|
|
134
|
+
agentId?: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Hook that registers a frontend tool AND a render function for it.
|
|
138
|
+
*
|
|
139
|
+
* This bridges `useFrontendTool` (which handles tool registration and
|
|
140
|
+
* handler execution) with a render registry so that CopilotChat can
|
|
141
|
+
* render React Native elements inline when it encounters tool call messages.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```tsx
|
|
145
|
+
* useRenderTool({
|
|
146
|
+
* name: "showWeather",
|
|
147
|
+
* description: "Display weather information",
|
|
148
|
+
* parameters: z.object({ city: z.string(), temp: z.number() }),
|
|
149
|
+
* render: ({ args, status }) => (
|
|
150
|
+
* <View>
|
|
151
|
+
* <Text>{args.city}: {args.temp}</Text>
|
|
152
|
+
* {status === "executing" && <ActivityIndicator />}
|
|
153
|
+
* </View>
|
|
154
|
+
* ),
|
|
155
|
+
* handler: async ({ city }) => {
|
|
156
|
+
* return { forecast: "sunny" };
|
|
157
|
+
* },
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
declare function useRenderTool<T extends Record<string, unknown> = Record<string, unknown>>(options: UseRenderToolOptions<T>, deps?: ReadonlyArray<unknown>): void;
|
|
162
|
+
//#endregion
|
|
163
|
+
export { useRenderToolRegistry as a, RenderToolProvider as i, useRenderTool as n, CopilotKitNativeProviderProps as o, RenderToolProps as r, CopilotKitProvider as s, UseRenderToolOptions as t };
|
|
164
|
+
//# sourceMappingURL=useRenderTool-BugVTDoM.d.cts.map
|