@copilotkit/react-native 1.57.0-canary.1778116520
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/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/index.cjs +203 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +51 -0
- package/dist/index.d.mts +51 -0
- package/dist/index.mjs +101 -0
- package/dist/index.mjs.map +1 -0
- package/dist/polyfills/crypto.cjs +15 -0
- package/dist/polyfills/crypto.cjs.map +1 -0
- package/dist/polyfills/crypto.d.cts +1 -0
- package/dist/polyfills/crypto.d.mts +1 -0
- package/dist/polyfills/crypto.mjs +15 -0
- package/dist/polyfills/crypto.mjs.map +1 -0
- package/dist/polyfills/dom.cjs +59 -0
- package/dist/polyfills/dom.cjs.map +1 -0
- package/dist/polyfills/dom.d.cts +1 -0
- package/dist/polyfills/dom.d.mts +1 -0
- package/dist/polyfills/dom.mjs +59 -0
- package/dist/polyfills/dom.mjs.map +1 -0
- package/dist/polyfills/encoding.cjs +19 -0
- package/dist/polyfills/encoding.cjs.map +1 -0
- package/dist/polyfills/encoding.d.cts +1 -0
- package/dist/polyfills/encoding.d.mts +1 -0
- package/dist/polyfills/encoding.mjs +19 -0
- package/dist/polyfills/encoding.mjs.map +1 -0
- package/dist/polyfills/location.cjs +18 -0
- package/dist/polyfills/location.cjs.map +1 -0
- package/dist/polyfills/location.d.cts +1 -0
- package/dist/polyfills/location.d.mts +1 -0
- package/dist/polyfills/location.mjs +18 -0
- package/dist/polyfills/location.mjs.map +1 -0
- package/dist/polyfills/streams.cjs +20 -0
- package/dist/polyfills/streams.cjs.map +1 -0
- package/dist/polyfills/streams.d.cts +1 -0
- package/dist/polyfills/streams.d.mts +1 -0
- package/dist/polyfills/streams.mjs +20 -0
- package/dist/polyfills/streams.mjs.map +1 -0
- package/dist/polyfills.cjs +196 -0
- package/dist/polyfills.cjs.map +1 -0
- package/dist/polyfills.d.cts +1 -0
- package/dist/polyfills.d.mts +1 -0
- package/dist/polyfills.mjs +196 -0
- package/dist/polyfills.mjs.map +1 -0
- package/package.json +92 -0
- package/project.json +18 -0
- package/src/CopilotKitProvider.tsx +188 -0
- package/src/__tests__/copilotkit-provider.test.tsx +424 -0
- package/src/__tests__/headless-integration.test.tsx +378 -0
- package/src/__tests__/polyfills.test.ts +242 -0
- package/src/__tests__/setup.ts +9 -0
- package/src/__tests__/streaming-fetch.test.ts +486 -0
- package/src/index.ts +44 -0
- package/src/polyfills/crypto.ts +34 -0
- package/src/polyfills/dom.ts +85 -0
- package/src/polyfills/encoding.ts +20 -0
- package/src/polyfills/location.ts +30 -0
- package/src/polyfills/streams.ts +27 -0
- package/src/polyfills.ts +22 -0
- package/src/streaming-fetch.ts +336 -0
- package/src/types.d.ts +23 -0
- package/tsconfig.json +16 -0
- package/tsdown.config.ts +25 -0
- package/vitest.config.mjs +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Atai Barkai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @copilotkit/react-native
|
|
2
|
+
|
|
3
|
+
Headless React Native bindings for CopilotKit. Provides a lightweight provider and re-exports platform-agnostic hooks -- no DOM, CSS, or web framework dependencies. You build the chat UI with standard React Native components.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @copilotkit/react-native
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Polyfills
|
|
12
|
+
|
|
13
|
+
React Native's JS runtime (Hermes) lacks several Web APIs that CopilotKit depends on. Import the polyfills **before any other code** in your entry point:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// index.js
|
|
17
|
+
import "@copilotkit/react-native/polyfills";
|
|
18
|
+
|
|
19
|
+
import { AppRegistry } from "react-native";
|
|
20
|
+
import App from "./App";
|
|
21
|
+
import { name as appName } from "./app.json";
|
|
22
|
+
|
|
23
|
+
AppRegistry.registerComponent(appName, () => App);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If you already polyfill some of these APIs, you can import only what you need:
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import "@copilotkit/react-native/polyfills/streams";
|
|
30
|
+
import "@copilotkit/react-native/polyfills/encoding";
|
|
31
|
+
import "@copilotkit/react-native/polyfills/crypto";
|
|
32
|
+
import "@copilotkit/react-native/polyfills/dom";
|
|
33
|
+
import "@copilotkit/react-native/polyfills/location";
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { CopilotKitProvider, useAgent, useCopilotKit } from "@copilotkit/react-native";
|
|
40
|
+
|
|
41
|
+
export default function App() {
|
|
42
|
+
return (
|
|
43
|
+
<CopilotKitProvider runtimeUrl="https://your-server/api/copilotkit">
|
|
44
|
+
<ChatScreen />
|
|
45
|
+
</CopilotKitProvider>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Re-exports hooks from `@copilotkit/react-core`: `useAgent`, `useFrontendTool`, `useComponent`, `useHumanInTheLoop`, `useInterrupt`, `useSuggestions`, `useConfigureSuggestions`, `useAgentContext`, `useThreads`, and `useCopilotKit`.
|
|
51
|
+
|
|
52
|
+
## Documentation
|
|
53
|
+
|
|
54
|
+
For full setup instructions, usage examples, and troubleshooting, see the [React Native docs](https://docs.copilotkit.ai/react-native).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
let react = require("react");
|
|
30
|
+
react = __toESM(react);
|
|
31
|
+
let _copilotkit_react_core_v2_context = require("@copilotkit/react-core/v2/context");
|
|
32
|
+
let _copilotkit_react_core_v2_headless = require("@copilotkit/react-core/v2/headless");
|
|
33
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
|
|
35
|
+
//#region src/CopilotKitProvider.tsx
|
|
36
|
+
/**
|
|
37
|
+
* CopilotKit provider for React Native.
|
|
38
|
+
*
|
|
39
|
+
* A lightweight alternative to the web CopilotKitProvider that avoids
|
|
40
|
+
* web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
|
|
41
|
+
*
|
|
42
|
+
* Usage:
|
|
43
|
+
* ```tsx
|
|
44
|
+
* import "@copilotkit/react-native/polyfills";
|
|
45
|
+
* import { CopilotKitProvider } from "@copilotkit/react-native";
|
|
46
|
+
*
|
|
47
|
+
* function App() {
|
|
48
|
+
* return (
|
|
49
|
+
* <CopilotKitProvider runtimeUrl="https://your-runtime/api/copilotkit">
|
|
50
|
+
* <ChatScreen />
|
|
51
|
+
* </CopilotKitProvider>
|
|
52
|
+
* );
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
const CopilotKitProvider = ({ children, runtimeUrl, headers, useSingleEndpoint, properties, onError }) => {
|
|
57
|
+
const stableHeaders = (0, react.useMemo)(() => headers ?? {}, [JSON.stringify(headers)]);
|
|
58
|
+
const stableProperties = (0, react.useMemo)(() => properties ?? {}, [JSON.stringify(properties)]);
|
|
59
|
+
const copilotkitRef = (0, react.useRef)(null);
|
|
60
|
+
if (copilotkitRef.current === null) copilotkitRef.current = new _copilotkit_react_core_v2_headless.CopilotKitCoreReact({
|
|
61
|
+
runtimeUrl,
|
|
62
|
+
runtimeTransport: useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto",
|
|
63
|
+
headers: stableHeaders,
|
|
64
|
+
properties: stableProperties
|
|
65
|
+
});
|
|
66
|
+
const copilotkit = copilotkitRef.current;
|
|
67
|
+
(0, react.useEffect)(() => {
|
|
68
|
+
copilotkit.setRuntimeUrl(runtimeUrl);
|
|
69
|
+
copilotkit.setRuntimeTransport(useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto");
|
|
70
|
+
copilotkit.setHeaders(stableHeaders);
|
|
71
|
+
copilotkit.setProperties(stableProperties);
|
|
72
|
+
}, [
|
|
73
|
+
runtimeUrl,
|
|
74
|
+
useSingleEndpoint,
|
|
75
|
+
stableHeaders,
|
|
76
|
+
stableProperties,
|
|
77
|
+
copilotkit
|
|
78
|
+
]);
|
|
79
|
+
const [executingToolCallIds, setExecutingToolCallIds] = (0, react.useState)(() => /* @__PURE__ */ new Set());
|
|
80
|
+
const onErrorRef = (0, react.useRef)(onError);
|
|
81
|
+
(0, react.useEffect)(() => {
|
|
82
|
+
onErrorRef.current = onError;
|
|
83
|
+
}, [onError]);
|
|
84
|
+
(0, react.useEffect)(() => {
|
|
85
|
+
const subscription = copilotkit.subscribe({
|
|
86
|
+
onToolExecutionStart: ({ toolCallId }) => {
|
|
87
|
+
setExecutingToolCallIds((prev) => {
|
|
88
|
+
if (prev.has(toolCallId)) return prev;
|
|
89
|
+
const next = new Set(prev);
|
|
90
|
+
next.add(toolCallId);
|
|
91
|
+
return next;
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
onToolExecutionEnd: ({ toolCallId }) => {
|
|
95
|
+
setExecutingToolCallIds((prev) => {
|
|
96
|
+
if (!prev.has(toolCallId)) return prev;
|
|
97
|
+
const next = new Set(prev);
|
|
98
|
+
next.delete(toolCallId);
|
|
99
|
+
return next;
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
onError: (event) => {
|
|
103
|
+
if (onErrorRef.current) onErrorRef.current(event);
|
|
104
|
+
else console.error(`[CopilotKit] Error (${event.code}):`, event.error, event.context ?? {});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return () => subscription.unsubscribe();
|
|
108
|
+
}, [copilotkit]);
|
|
109
|
+
const contextValue = (0, react.useMemo)(() => ({
|
|
110
|
+
copilotkit,
|
|
111
|
+
executingToolCallIds
|
|
112
|
+
}), [copilotkit, executingToolCallIds]);
|
|
113
|
+
const licenseContextValue = (0, react.useMemo)(() => ({
|
|
114
|
+
status: null,
|
|
115
|
+
license: null,
|
|
116
|
+
checkFeature: () => true,
|
|
117
|
+
getLimit: () => null
|
|
118
|
+
}), []);
|
|
119
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_copilotkit_react_core_v2_context.CopilotKitContext.Provider, {
|
|
120
|
+
value: contextValue,
|
|
121
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_copilotkit_react_core_v2_context.LicenseContext.Provider, {
|
|
122
|
+
value: licenseContextValue,
|
|
123
|
+
children
|
|
124
|
+
})
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
Object.defineProperty(exports, 'CopilotKitContext', {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function () {
|
|
132
|
+
return _copilotkit_react_core_v2_context.CopilotKitContext;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
exports.CopilotKitProvider = CopilotKitProvider;
|
|
136
|
+
exports.__toESM = __toESM;
|
|
137
|
+
Object.defineProperty(exports, 'useAgent', {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
get: function () {
|
|
140
|
+
return _copilotkit_react_core_v2_headless.useAgent;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(exports, 'useAgentContext', {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
get: function () {
|
|
146
|
+
return _copilotkit_react_core_v2_headless.useAgentContext;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(exports, 'useComponent', {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
get: function () {
|
|
152
|
+
return _copilotkit_react_core_v2_headless.useComponent;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
Object.defineProperty(exports, 'useConfigureSuggestions', {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
get: function () {
|
|
158
|
+
return _copilotkit_react_core_v2_headless.useConfigureSuggestions;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
Object.defineProperty(exports, 'useCopilotKit', {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
get: function () {
|
|
164
|
+
return _copilotkit_react_core_v2_context.useCopilotKit;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
Object.defineProperty(exports, 'useFrontendTool', {
|
|
168
|
+
enumerable: true,
|
|
169
|
+
get: function () {
|
|
170
|
+
return _copilotkit_react_core_v2_headless.useFrontendTool;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
Object.defineProperty(exports, 'useHumanInTheLoop', {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
get: function () {
|
|
176
|
+
return _copilotkit_react_core_v2_headless.useHumanInTheLoop;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
Object.defineProperty(exports, 'useInterrupt', {
|
|
180
|
+
enumerable: true,
|
|
181
|
+
get: function () {
|
|
182
|
+
return _copilotkit_react_core_v2_headless.useInterrupt;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
Object.defineProperty(exports, 'useLicenseContext', {
|
|
186
|
+
enumerable: true,
|
|
187
|
+
get: function () {
|
|
188
|
+
return _copilotkit_react_core_v2_context.useLicenseContext;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
Object.defineProperty(exports, 'useSuggestions', {
|
|
192
|
+
enumerable: true,
|
|
193
|
+
get: function () {
|
|
194
|
+
return _copilotkit_react_core_v2_headless.useSuggestions;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(exports, 'useThreads', {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
get: function () {
|
|
200
|
+
return _copilotkit_react_core_v2_headless.useThreads;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["CopilotKitCoreReact","CopilotKitContext","LicenseContext"],"sources":["../src/CopilotKitProvider.tsx"],"sourcesContent":["import React, {\n type ReactNode,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n CopilotKitContext,\n type CopilotKitContextValue,\n LicenseContext,\n} from \"@copilotkit/react-core/v2/context\";\nimport { CopilotKitCoreReact } from \"@copilotkit/react-core/v2/headless\";\nimport type { CopilotKitCoreErrorCode } from \"@copilotkit/core\";\n\nexport interface CopilotKitNativeProviderProps {\n children: ReactNode;\n /** URL of the CopilotKit runtime endpoint */\n runtimeUrl: string;\n /** Custom headers sent with every request */\n headers?: Record<string, string>;\n /** Whether the runtime uses a single-route endpoint */\n useSingleEndpoint?: boolean;\n /** Custom properties forwarded to agents */\n properties?: Record<string, unknown>;\n /**\n * Error handler called when CopilotKit encounters an error.\n * Fires for all error types (runtime connection failures, agent errors, tool errors).\n * If not provided, errors are logged to console.error.\n */\n onError?: (event: {\n error: Error;\n code: CopilotKitCoreErrorCode;\n context: Record<string, any>;\n }) => void;\n}\n\n/**\n * CopilotKit provider for React Native.\n *\n * A lightweight alternative to the web CopilotKitProvider that avoids\n * web-only dependencies (DOM, CSS, Radix UI, Lit, etc).\n *\n * Usage:\n * ```tsx\n * import \"@copilotkit/react-native/polyfills\";\n * import { CopilotKitProvider } from \"@copilotkit/react-native\";\n *\n * function App() {\n * return (\n * <CopilotKitProvider runtimeUrl=\"https://your-runtime/api/copilotkit\">\n * <ChatScreen />\n * </CopilotKitProvider>\n * );\n * }\n * ```\n */\nexport const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps> = ({\n children,\n runtimeUrl,\n headers,\n useSingleEndpoint,\n properties,\n onError,\n}) => {\n // Stabilize headers/properties references to avoid effect churn when callers\n // pass inline object literals (e.g. headers={{}} or the undefined default).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableHeaders = useMemo(() => headers ?? {}, [JSON.stringify(headers)]);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableProperties = useMemo(\n () => properties ?? {},\n [JSON.stringify(properties)],\n );\n\n const copilotkitRef = useRef<CopilotKitCoreReact | null>(null);\n\n if (copilotkitRef.current === null) {\n copilotkitRef.current = new CopilotKitCoreReact({\n runtimeUrl,\n runtimeTransport:\n useSingleEndpoint === true\n ? \"single\"\n : useSingleEndpoint === false\n ? \"rest\"\n : \"auto\",\n headers: stableHeaders,\n properties: stableProperties,\n });\n }\n\n const copilotkit = copilotkitRef.current;\n\n // Sync props to core instance\n useEffect(() => {\n copilotkit.setRuntimeUrl(runtimeUrl);\n copilotkit.setRuntimeTransport(\n useSingleEndpoint === true\n ? \"single\"\n : useSingleEndpoint === false\n ? \"rest\"\n : \"auto\",\n );\n copilotkit.setHeaders(stableHeaders);\n copilotkit.setProperties(stableProperties);\n }, [\n runtimeUrl,\n useSingleEndpoint,\n stableHeaders,\n stableProperties,\n copilotkit,\n ]);\n\n // Track executing tool call IDs at the provider level.\n // Critical for HITL reconnection: onToolExecutionStart fires before child\n // components mount, so we must capture the state here.\n const [executingToolCallIds, setExecutingToolCallIds] = useState<\n ReadonlySet<string>\n >(() => new Set());\n\n // Use ref to avoid subscription churn when onError changes\n const onErrorRef = useRef(onError);\n useEffect(() => {\n onErrorRef.current = onError;\n }, [onError]);\n\n // Single subscription for tool execution tracking and error handling.\n // Tool call IDs are tracked at the provider level because onToolExecutionStart\n // fires before child components mount — critical for HITL reconnection.\n useEffect(() => {\n const subscription = copilotkit.subscribe({\n onToolExecutionStart: ({ toolCallId }) => {\n setExecutingToolCallIds((prev) => {\n if (prev.has(toolCallId)) return prev;\n const next = new Set(prev);\n next.add(toolCallId);\n return next;\n });\n },\n onToolExecutionEnd: ({ toolCallId }) => {\n setExecutingToolCallIds((prev) => {\n if (!prev.has(toolCallId)) return prev;\n const next = new Set(prev);\n next.delete(toolCallId);\n return next;\n });\n },\n onError: (event) => {\n if (onErrorRef.current) {\n onErrorRef.current(event);\n } else {\n console.error(\n `[CopilotKit] Error (${event.code}):`,\n event.error,\n event.context ?? {},\n );\n }\n },\n });\n return () => subscription.unsubscribe();\n }, [copilotkit]);\n\n const contextValue: CopilotKitContextValue = useMemo(\n () => ({\n copilotkit,\n executingToolCallIds,\n }),\n [copilotkit, executingToolCallIds],\n );\n\n const licenseContextValue = useMemo(\n () => ({\n status: null as null,\n license: null as null,\n checkFeature: () => true,\n getLimit: () => null,\n }),\n [],\n );\n\n return (\n <CopilotKitContext.Provider value={contextValue}>\n <LicenseContext.Provider value={licenseContextValue}>\n {children}\n </LicenseContext.Provider>\n </CopilotKitContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAa,sBAA+D,EAC1E,UACA,YACA,SACA,mBACA,YACA,cACI;CAIJ,MAAM,yCAA8B,WAAW,EAAE,EAAE,CAAC,KAAK,UAAU,QAAQ,CAAC,CAAC;CAE7E,MAAM,4CACE,cAAc,EAAE,EACtB,CAAC,KAAK,UAAU,WAAW,CAAC,CAC7B;CAED,MAAM,kCAAmD,KAAK;AAE9D,KAAI,cAAc,YAAY,KAC5B,eAAc,UAAU,IAAIA,uDAAoB;EAC9C;EACA,kBACE,sBAAsB,OAClB,WACA,sBAAsB,QACpB,SACA;EACR,SAAS;EACT,YAAY;EACb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 +1,51 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { CopilotKitCoreErrorCode, CopilotKitCoreErrorCode as CopilotKitCoreErrorCode$1, CopilotKitCoreRuntimeConnectionStatus } from "@copilotkit/core";
|
|
3
|
+
import { CopilotKitContext, CopilotKitContextValue, useCopilotKit, useLicenseContext } from "@copilotkit/react-core/v2/context";
|
|
4
|
+
import { UseAgentUpdate, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useFrontendTool, useHumanInTheLoop, useInterrupt, useSuggestions, useThreads } from "@copilotkit/react-core/v2/headless";
|
|
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>;
|
|
13
|
+
/** Whether the runtime uses a single-route endpoint */
|
|
14
|
+
useSingleEndpoint?: boolean;
|
|
15
|
+
/** Custom properties forwarded to agents */
|
|
16
|
+
properties?: Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* Error handler called when CopilotKit encounters an error.
|
|
19
|
+
* Fires for all error types (runtime connection failures, agent errors, tool errors).
|
|
20
|
+
* If not provided, errors are logged to console.error.
|
|
21
|
+
*/
|
|
22
|
+
onError?: (event: {
|
|
23
|
+
error: Error;
|
|
24
|
+
code: CopilotKitCoreErrorCode$1;
|
|
25
|
+
context: Record<string, any>;
|
|
26
|
+
}) => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* CopilotKit provider for React Native.
|
|
30
|
+
*
|
|
31
|
+
* A lightweight alternative to the web CopilotKitProvider that avoids
|
|
32
|
+
* web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
|
|
33
|
+
*
|
|
34
|
+
* Usage:
|
|
35
|
+
* ```tsx
|
|
36
|
+
* import "@copilotkit/react-native/polyfills";
|
|
37
|
+
* import { CopilotKitProvider } from "@copilotkit/react-native";
|
|
38
|
+
*
|
|
39
|
+
* function App() {
|
|
40
|
+
* return (
|
|
41
|
+
* <CopilotKitProvider runtimeUrl="https://your-runtime/api/copilotkit">
|
|
42
|
+
* <ChatScreen />
|
|
43
|
+
* </CopilotKitProvider>
|
|
44
|
+
* );
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps>;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { CopilotKitContext, type CopilotKitContextValue, type CopilotKitCoreErrorCode, type CopilotKitCoreRuntimeConnectionStatus, type CopilotKitNativeProviderProps, CopilotKitProvider, type UseAgentUpdate, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useSuggestions, useThreads };
|
|
51
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { CopilotKitContext, CopilotKitContextValue, useCopilotKit, useLicenseContext } from "@copilotkit/react-core/v2/context";
|
|
3
|
+
import { UseAgentUpdate, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useFrontendTool, useHumanInTheLoop, useInterrupt, useSuggestions, useThreads } from "@copilotkit/react-core/v2/headless";
|
|
4
|
+
import { CopilotKitCoreErrorCode, CopilotKitCoreErrorCode as CopilotKitCoreErrorCode$1, CopilotKitCoreRuntimeConnectionStatus } 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>;
|
|
13
|
+
/** Whether the runtime uses a single-route endpoint */
|
|
14
|
+
useSingleEndpoint?: boolean;
|
|
15
|
+
/** Custom properties forwarded to agents */
|
|
16
|
+
properties?: Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* Error handler called when CopilotKit encounters an error.
|
|
19
|
+
* Fires for all error types (runtime connection failures, agent errors, tool errors).
|
|
20
|
+
* If not provided, errors are logged to console.error.
|
|
21
|
+
*/
|
|
22
|
+
onError?: (event: {
|
|
23
|
+
error: Error;
|
|
24
|
+
code: CopilotKitCoreErrorCode$1;
|
|
25
|
+
context: Record<string, any>;
|
|
26
|
+
}) => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* CopilotKit provider for React Native.
|
|
30
|
+
*
|
|
31
|
+
* A lightweight alternative to the web CopilotKitProvider that avoids
|
|
32
|
+
* web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
|
|
33
|
+
*
|
|
34
|
+
* Usage:
|
|
35
|
+
* ```tsx
|
|
36
|
+
* import "@copilotkit/react-native/polyfills";
|
|
37
|
+
* import { CopilotKitProvider } from "@copilotkit/react-native";
|
|
38
|
+
*
|
|
39
|
+
* function App() {
|
|
40
|
+
* return (
|
|
41
|
+
* <CopilotKitProvider runtimeUrl="https://your-runtime/api/copilotkit">
|
|
42
|
+
* <ChatScreen />
|
|
43
|
+
* </CopilotKitProvider>
|
|
44
|
+
* );
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps>;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { CopilotKitContext, type CopilotKitContextValue, type CopilotKitCoreErrorCode, type CopilotKitCoreRuntimeConnectionStatus, type CopilotKitNativeProviderProps, CopilotKitProvider, type UseAgentUpdate, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useSuggestions, useThreads };
|
|
51
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { CopilotKitContext, CopilotKitContext as CopilotKitContext$1, LicenseContext, useCopilotKit, useLicenseContext } from "@copilotkit/react-core/v2/context";
|
|
3
|
+
import { CopilotKitCoreReact, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useFrontendTool, useHumanInTheLoop, useInterrupt, useSuggestions, useThreads } from "@copilotkit/react-core/v2/headless";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/CopilotKitProvider.tsx
|
|
7
|
+
/**
|
|
8
|
+
* CopilotKit provider for React Native.
|
|
9
|
+
*
|
|
10
|
+
* A lightweight alternative to the web CopilotKitProvider that avoids
|
|
11
|
+
* web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import "@copilotkit/react-native/polyfills";
|
|
16
|
+
* import { CopilotKitProvider } from "@copilotkit/react-native";
|
|
17
|
+
*
|
|
18
|
+
* function App() {
|
|
19
|
+
* return (
|
|
20
|
+
* <CopilotKitProvider runtimeUrl="https://your-runtime/api/copilotkit">
|
|
21
|
+
* <ChatScreen />
|
|
22
|
+
* </CopilotKitProvider>
|
|
23
|
+
* );
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
const CopilotKitProvider = ({ children, runtimeUrl, headers, useSingleEndpoint, properties, onError }) => {
|
|
28
|
+
const stableHeaders = useMemo(() => headers ?? {}, [JSON.stringify(headers)]);
|
|
29
|
+
const stableProperties = useMemo(() => properties ?? {}, [JSON.stringify(properties)]);
|
|
30
|
+
const copilotkitRef = useRef(null);
|
|
31
|
+
if (copilotkitRef.current === null) copilotkitRef.current = new CopilotKitCoreReact({
|
|
32
|
+
runtimeUrl,
|
|
33
|
+
runtimeTransport: useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto",
|
|
34
|
+
headers: stableHeaders,
|
|
35
|
+
properties: stableProperties
|
|
36
|
+
});
|
|
37
|
+
const copilotkit = copilotkitRef.current;
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
copilotkit.setRuntimeUrl(runtimeUrl);
|
|
40
|
+
copilotkit.setRuntimeTransport(useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto");
|
|
41
|
+
copilotkit.setHeaders(stableHeaders);
|
|
42
|
+
copilotkit.setProperties(stableProperties);
|
|
43
|
+
}, [
|
|
44
|
+
runtimeUrl,
|
|
45
|
+
useSingleEndpoint,
|
|
46
|
+
stableHeaders,
|
|
47
|
+
stableProperties,
|
|
48
|
+
copilotkit
|
|
49
|
+
]);
|
|
50
|
+
const [executingToolCallIds, setExecutingToolCallIds] = useState(() => /* @__PURE__ */ new Set());
|
|
51
|
+
const onErrorRef = useRef(onError);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
onErrorRef.current = onError;
|
|
54
|
+
}, [onError]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const subscription = copilotkit.subscribe({
|
|
57
|
+
onToolExecutionStart: ({ toolCallId }) => {
|
|
58
|
+
setExecutingToolCallIds((prev) => {
|
|
59
|
+
if (prev.has(toolCallId)) return prev;
|
|
60
|
+
const next = new Set(prev);
|
|
61
|
+
next.add(toolCallId);
|
|
62
|
+
return next;
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
onToolExecutionEnd: ({ toolCallId }) => {
|
|
66
|
+
setExecutingToolCallIds((prev) => {
|
|
67
|
+
if (!prev.has(toolCallId)) return prev;
|
|
68
|
+
const next = new Set(prev);
|
|
69
|
+
next.delete(toolCallId);
|
|
70
|
+
return next;
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
onError: (event) => {
|
|
74
|
+
if (onErrorRef.current) onErrorRef.current(event);
|
|
75
|
+
else console.error(`[CopilotKit] Error (${event.code}):`, event.error, event.context ?? {});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return () => subscription.unsubscribe();
|
|
79
|
+
}, [copilotkit]);
|
|
80
|
+
const contextValue = useMemo(() => ({
|
|
81
|
+
copilotkit,
|
|
82
|
+
executingToolCallIds
|
|
83
|
+
}), [copilotkit, executingToolCallIds]);
|
|
84
|
+
const licenseContextValue = useMemo(() => ({
|
|
85
|
+
status: null,
|
|
86
|
+
license: null,
|
|
87
|
+
checkFeature: () => true,
|
|
88
|
+
getLimit: () => null
|
|
89
|
+
}), []);
|
|
90
|
+
return /* @__PURE__ */ jsx(CopilotKitContext$1.Provider, {
|
|
91
|
+
value: contextValue,
|
|
92
|
+
children: /* @__PURE__ */ jsx(LicenseContext.Provider, {
|
|
93
|
+
value: licenseContextValue,
|
|
94
|
+
children
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
//#endregion
|
|
100
|
+
export { CopilotKitContext, CopilotKitProvider, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useSuggestions, useThreads };
|
|
101
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["CopilotKitContext"],"sources":["../src/CopilotKitProvider.tsx"],"sourcesContent":["import React, {\n type ReactNode,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n CopilotKitContext,\n type CopilotKitContextValue,\n LicenseContext,\n} from \"@copilotkit/react-core/v2/context\";\nimport { CopilotKitCoreReact } from \"@copilotkit/react-core/v2/headless\";\nimport type { CopilotKitCoreErrorCode } from \"@copilotkit/core\";\n\nexport interface CopilotKitNativeProviderProps {\n children: ReactNode;\n /** URL of the CopilotKit runtime endpoint */\n runtimeUrl: string;\n /** Custom headers sent with every request */\n headers?: Record<string, string>;\n /** Whether the runtime uses a single-route endpoint */\n useSingleEndpoint?: boolean;\n /** Custom properties forwarded to agents */\n properties?: Record<string, unknown>;\n /**\n * Error handler called when CopilotKit encounters an error.\n * Fires for all error types (runtime connection failures, agent errors, tool errors).\n * If not provided, errors are logged to console.error.\n */\n onError?: (event: {\n error: Error;\n code: CopilotKitCoreErrorCode;\n context: Record<string, any>;\n }) => void;\n}\n\n/**\n * CopilotKit provider for React Native.\n *\n * A lightweight alternative to the web CopilotKitProvider that avoids\n * web-only dependencies (DOM, CSS, Radix UI, Lit, etc).\n *\n * Usage:\n * ```tsx\n * import \"@copilotkit/react-native/polyfills\";\n * import { CopilotKitProvider } from \"@copilotkit/react-native\";\n *\n * function App() {\n * return (\n * <CopilotKitProvider runtimeUrl=\"https://your-runtime/api/copilotkit\">\n * <ChatScreen />\n * </CopilotKitProvider>\n * );\n * }\n * ```\n */\nexport const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps> = ({\n children,\n runtimeUrl,\n headers,\n useSingleEndpoint,\n properties,\n onError,\n}) => {\n // Stabilize headers/properties references to avoid effect churn when callers\n // pass inline object literals (e.g. headers={{}} or the undefined default).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableHeaders = useMemo(() => headers ?? {}, [JSON.stringify(headers)]);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableProperties = useMemo(\n () => properties ?? {},\n [JSON.stringify(properties)],\n );\n\n const copilotkitRef = useRef<CopilotKitCoreReact | null>(null);\n\n if (copilotkitRef.current === null) {\n copilotkitRef.current = new CopilotKitCoreReact({\n runtimeUrl,\n runtimeTransport:\n useSingleEndpoint === true\n ? \"single\"\n : useSingleEndpoint === false\n ? \"rest\"\n : \"auto\",\n headers: stableHeaders,\n properties: stableProperties,\n });\n }\n\n const copilotkit = copilotkitRef.current;\n\n // Sync props to core instance\n useEffect(() => {\n copilotkit.setRuntimeUrl(runtimeUrl);\n copilotkit.setRuntimeTransport(\n useSingleEndpoint === true\n ? \"single\"\n : useSingleEndpoint === false\n ? \"rest\"\n : \"auto\",\n );\n copilotkit.setHeaders(stableHeaders);\n copilotkit.setProperties(stableProperties);\n }, [\n runtimeUrl,\n useSingleEndpoint,\n stableHeaders,\n stableProperties,\n copilotkit,\n ]);\n\n // Track executing tool call IDs at the provider level.\n // Critical for HITL reconnection: onToolExecutionStart fires before child\n // components mount, so we must capture the state here.\n const [executingToolCallIds, setExecutingToolCallIds] = useState<\n ReadonlySet<string>\n >(() => new Set());\n\n // Use ref to avoid subscription churn when onError changes\n const onErrorRef = useRef(onError);\n useEffect(() => {\n onErrorRef.current = onError;\n }, [onError]);\n\n // Single subscription for tool execution tracking and error handling.\n // Tool call IDs are tracked at the provider level because onToolExecutionStart\n // fires before child components mount — critical for HITL reconnection.\n useEffect(() => {\n const subscription = copilotkit.subscribe({\n onToolExecutionStart: ({ toolCallId }) => {\n setExecutingToolCallIds((prev) => {\n if (prev.has(toolCallId)) return prev;\n const next = new Set(prev);\n next.add(toolCallId);\n return next;\n });\n },\n onToolExecutionEnd: ({ toolCallId }) => {\n setExecutingToolCallIds((prev) => {\n if (!prev.has(toolCallId)) return prev;\n const next = new Set(prev);\n next.delete(toolCallId);\n return next;\n });\n },\n onError: (event) => {\n if (onErrorRef.current) {\n onErrorRef.current(event);\n } else {\n console.error(\n `[CopilotKit] Error (${event.code}):`,\n event.error,\n event.context ?? {},\n );\n }\n },\n });\n return () => subscription.unsubscribe();\n }, [copilotkit]);\n\n const contextValue: CopilotKitContextValue = useMemo(\n () => ({\n copilotkit,\n executingToolCallIds,\n }),\n [copilotkit, executingToolCallIds],\n );\n\n const licenseContextValue = useMemo(\n () => ({\n status: null as null,\n license: null as null,\n checkFeature: () => true,\n getLimit: () => null,\n }),\n [],\n );\n\n return (\n <CopilotKitContext.Provider value={contextValue}>\n <LicenseContext.Provider value={licenseContextValue}>\n {children}\n </LicenseContext.Provider>\n </CopilotKitContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;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Q,MAAM;QAEzB,SAAQ,MACN,uBAAuB,MAAM,KAAK,KAClC,MAAM,OACN,MAAM,WAAW,EAAE,CACpB;;GAGN,CAAC;AACF,eAAa,aAAa,aAAa;IACtC,CAAC,WAAW,CAAC;CAEhB,MAAM,eAAuC,eACpC;EACL;EACA;EACD,GACD,CAAC,YAAY,qBAAqB,CACnC;CAED,MAAM,sBAAsB,eACnB;EACL,QAAQ;EACR,SAAS;EACT,oBAAoB;EACpB,gBAAgB;EACjB,GACD,EAAE,CACH;AAED,QACE,oBAACA,oBAAkB;EAAS,OAAO;YACjC,oBAAC,eAAe;GAAS,OAAO;GAC7B;IACuB;GACC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/polyfills/crypto.ts
|
|
3
|
+
const g = globalThis;
|
|
4
|
+
if (typeof g.crypto === "undefined") g.crypto = {};
|
|
5
|
+
const cryptoObj = g.crypto;
|
|
6
|
+
if (!cryptoObj.getRandomValues) {
|
|
7
|
+
console.warn("[CopilotKit] Installing non-cryptographic crypto.getRandomValues polyfill (Math.random). This is NOT secure for cryptographic operations. Install 'react-native-get-random-values' for a secure implementation.");
|
|
8
|
+
cryptoObj.getRandomValues = function(array) {
|
|
9
|
+
for (let i = 0; i < array.length; i++) array[i] = Math.floor(Math.random() * 256);
|
|
10
|
+
return array;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//# sourceMappingURL=crypto.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.cjs","names":[],"sources":["../../src/polyfills/crypto.ts"],"sourcesContent":["/**\n * Polyfill: crypto.getRandomValues\n *\n * Required by uuid generation in CopilotKit. Uses Math.random — NOT\n * cryptographically secure. For secure randomness, install\n * react-native-get-random-values before this polyfill.\n *\n * Skipped if crypto.getRandomValues is already defined.\n *\n * Usage:\n * import \"@copilotkit/react-native/polyfills/crypto\";\n */\n\nexport {};\n\nconst g = globalThis as Record<string, unknown>;\n\nif (typeof g.crypto === \"undefined\") {\n g.crypto = {};\n}\nconst cryptoObj = g.crypto as Record<string, unknown>;\nif (!cryptoObj.getRandomValues) {\n console.warn(\n \"[CopilotKit] Installing non-cryptographic crypto.getRandomValues polyfill (Math.random). \" +\n \"This is NOT secure for cryptographic operations. Install 'react-native-get-random-values' \" +\n \"for a secure implementation.\",\n );\n cryptoObj.getRandomValues = function (array: Uint8Array): Uint8Array {\n for (let i = 0; i < array.length; i++) {\n array[i] = Math.floor(Math.random() * 256);\n }\n return array;\n };\n}\n"],"mappings":";;AAeA,MAAM,IAAI;AAEV,IAAI,OAAO,EAAE,WAAW,YACtB,GAAE,SAAS,EAAE;AAEf,MAAM,YAAY,EAAE;AACpB,IAAI,CAAC,UAAU,iBAAiB;AAC9B,SAAQ,KACN,kNAGD;AACD,WAAU,kBAAkB,SAAU,OAA+B;AACnE,OAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,OAAM,KAAK,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI;AAE5C,SAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/polyfills/crypto.ts
|
|
2
|
+
const g = globalThis;
|
|
3
|
+
if (typeof g.crypto === "undefined") g.crypto = {};
|
|
4
|
+
const cryptoObj = g.crypto;
|
|
5
|
+
if (!cryptoObj.getRandomValues) {
|
|
6
|
+
console.warn("[CopilotKit] Installing non-cryptographic crypto.getRandomValues polyfill (Math.random). This is NOT secure for cryptographic operations. Install 'react-native-get-random-values' for a secure implementation.");
|
|
7
|
+
cryptoObj.getRandomValues = function(array) {
|
|
8
|
+
for (let i = 0; i < array.length; i++) array[i] = Math.floor(Math.random() * 256);
|
|
9
|
+
return array;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { };
|
|
15
|
+
//# sourceMappingURL=crypto.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.mjs","names":[],"sources":["../../src/polyfills/crypto.ts"],"sourcesContent":["/**\n * Polyfill: crypto.getRandomValues\n *\n * Required by uuid generation in CopilotKit. Uses Math.random — NOT\n * cryptographically secure. For secure randomness, install\n * react-native-get-random-values before this polyfill.\n *\n * Skipped if crypto.getRandomValues is already defined.\n *\n * Usage:\n * import \"@copilotkit/react-native/polyfills/crypto\";\n */\n\nexport {};\n\nconst g = globalThis as Record<string, unknown>;\n\nif (typeof g.crypto === \"undefined\") {\n g.crypto = {};\n}\nconst cryptoObj = g.crypto as Record<string, unknown>;\nif (!cryptoObj.getRandomValues) {\n console.warn(\n \"[CopilotKit] Installing non-cryptographic crypto.getRandomValues polyfill (Math.random). \" +\n \"This is NOT secure for cryptographic operations. Install 'react-native-get-random-values' \" +\n \"for a secure implementation.\",\n );\n cryptoObj.getRandomValues = function (array: Uint8Array): Uint8Array {\n for (let i = 0; i < array.length; i++) {\n array[i] = Math.floor(Math.random() * 256);\n }\n return array;\n };\n}\n"],"mappings":";AAeA,MAAM,IAAI;AAEV,IAAI,OAAO,EAAE,WAAW,YACtB,GAAE,SAAS,EAAE;AAEf,MAAM,YAAY,EAAE;AACpB,IAAI,CAAC,UAAU,iBAAiB;AAC9B,SAAQ,KACN,kNAGD;AACD,WAAU,kBAAkB,SAAU,OAA+B;AACnE,OAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,OAAM,KAAK,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI;AAE5C,SAAO"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/polyfills/dom.ts
|
|
3
|
+
const g = globalThis;
|
|
4
|
+
if (typeof g.DOMException === "undefined") {
|
|
5
|
+
class DOMExceptionPolyfill extends Error {
|
|
6
|
+
code;
|
|
7
|
+
constructor(message, name) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = name || "DOMException";
|
|
10
|
+
this.code = 0;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
g.DOMException = DOMExceptionPolyfill;
|
|
14
|
+
}
|
|
15
|
+
if (typeof g.Headers === "undefined") {
|
|
16
|
+
class HeadersPolyfill {
|
|
17
|
+
_map = {};
|
|
18
|
+
constructor(init) {
|
|
19
|
+
if (init) if (init instanceof HeadersPolyfill) this._map = { ...init._map };
|
|
20
|
+
else for (const [key, value] of Object.entries(init)) this._map[key.toLowerCase()] = value;
|
|
21
|
+
}
|
|
22
|
+
get(name) {
|
|
23
|
+
return this._map[name.toLowerCase()] ?? null;
|
|
24
|
+
}
|
|
25
|
+
set(name, value) {
|
|
26
|
+
this._map[name.toLowerCase()] = value;
|
|
27
|
+
}
|
|
28
|
+
has(name) {
|
|
29
|
+
return name.toLowerCase() in this._map;
|
|
30
|
+
}
|
|
31
|
+
delete(name) {
|
|
32
|
+
delete this._map[name.toLowerCase()];
|
|
33
|
+
}
|
|
34
|
+
append(name, value) {
|
|
35
|
+
const key = name.toLowerCase();
|
|
36
|
+
if (key in this._map) this._map[key] += ", " + value;
|
|
37
|
+
else this._map[key] = value;
|
|
38
|
+
}
|
|
39
|
+
entries() {
|
|
40
|
+
return Object.entries(this._map)[Symbol.iterator]();
|
|
41
|
+
}
|
|
42
|
+
keys() {
|
|
43
|
+
return Object.keys(this._map)[Symbol.iterator]();
|
|
44
|
+
}
|
|
45
|
+
values() {
|
|
46
|
+
return Object.values(this._map)[Symbol.iterator]();
|
|
47
|
+
}
|
|
48
|
+
forEach(callback) {
|
|
49
|
+
for (const [key, value] of Object.entries(this._map)) callback(value, key, this);
|
|
50
|
+
}
|
|
51
|
+
[Symbol.iterator]() {
|
|
52
|
+
return this.entries();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
g.Headers = HeadersPolyfill;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//# sourceMappingURL=dom.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.cjs","names":[],"sources":["../../src/polyfills/dom.ts"],"sourcesContent":["/**\n * Polyfill: DOMException, Headers\n *\n * DOMException is used by CopilotKit's isAbortError check.\n * Headers is used by CopilotKit's request construction.\n * Skipped if the globals are already defined.\n *\n * Usage:\n * import \"@copilotkit/react-native/polyfills/dom\";\n */\n\nexport {};\n\nconst g = globalThis as Record<string, unknown>;\n\n// DOMException\nif (typeof g.DOMException === \"undefined\") {\n class DOMExceptionPolyfill extends Error {\n code: number;\n constructor(message?: string, name?: string) {\n super(message);\n this.name = name || \"DOMException\";\n this.code = 0;\n }\n }\n g.DOMException = DOMExceptionPolyfill;\n}\n\n// Headers\nif (typeof g.Headers === \"undefined\") {\n class HeadersPolyfill {\n private _map: Record<string, string> = {};\n constructor(init?: Record<string, string> | HeadersPolyfill) {\n if (init) {\n if (init instanceof HeadersPolyfill) {\n this._map = { ...init._map };\n } else {\n for (const [key, value] of Object.entries(init)) {\n this._map[key.toLowerCase()] = value;\n }\n }\n }\n }\n get(name: string): string | null {\n return this._map[name.toLowerCase()] ?? null;\n }\n set(name: string, value: string): void {\n this._map[name.toLowerCase()] = value;\n }\n has(name: string): boolean {\n return name.toLowerCase() in this._map;\n }\n delete(name: string): void {\n delete this._map[name.toLowerCase()];\n }\n append(name: string, value: string): void {\n const key = name.toLowerCase();\n if (key in this._map) {\n this._map[key] += \", \" + value;\n } else {\n this._map[key] = value;\n }\n }\n entries(): IterableIterator<[string, string]> {\n return Object.entries(this._map)[Symbol.iterator]();\n }\n keys(): IterableIterator<string> {\n return Object.keys(this._map)[Symbol.iterator]();\n }\n values(): IterableIterator<string> {\n return Object.values(this._map)[Symbol.iterator]();\n }\n forEach(\n callback: (value: string, key: string, parent: HeadersPolyfill) => void,\n ): void {\n for (const [key, value] of Object.entries(this._map)) {\n callback(value, key, this);\n }\n }\n [Symbol.iter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