@copilotkit/react-native 1.61.1 → 1.61.2
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/dist/index.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -5
- package/dist/index.d.mts +8 -6
- package/dist/index.mjs +10 -10
- package/dist/index.mjs.map +1 -1
- package/dist/polyfills.cjs +1 -1
- package/dist/polyfills.cjs.map +1 -1
- package/dist/polyfills.mjs +1 -1
- package/dist/polyfills.mjs.map +1 -1
- package/package.json +4 -4
- package/src/CopilotChat.tsx +3 -1
- package/src/CopilotKitProvider.tsx +20 -12
- package/src/CopilotSidebar.tsx +3 -3
- package/src/__tests__/copilot-sidebar.test.tsx +1 -1
- package/src/__tests__/headless-integration.test.tsx +2 -5
- package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +1 -1
- package/src/components/__tests__/CopilotChat.test.tsx +1 -1
- package/src/index.ts +3 -0
- package/src/streaming-fetch.ts +2 -1
|
@@ -4,10 +4,14 @@ import {
|
|
|
4
4
|
CopilotKitContext,
|
|
5
5
|
LicenseContext,
|
|
6
6
|
} from "@copilotkit/react-core/v2/context";
|
|
7
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
CopilotKitContextValue,
|
|
9
|
+
CopilotKitCoreReact as CopilotKitCoreReactInstance,
|
|
10
|
+
} from "@copilotkit/react-core/v2/context";
|
|
8
11
|
import { CopilotKitCoreReact } from "@copilotkit/react-core/v2/headless";
|
|
9
12
|
import type { CopilotKitCoreErrorCode } from "@copilotkit/core";
|
|
10
|
-
import type { DebugConfig } from "@copilotkit/shared";
|
|
13
|
+
import type { DebugConfig, RuntimeLicenseStatus } from "@copilotkit/shared";
|
|
14
|
+
import { createLicenseContextValue } from "@copilotkit/shared";
|
|
11
15
|
import { RenderToolProvider } from "./hooks/RenderToolContext";
|
|
12
16
|
|
|
13
17
|
export interface CopilotKitNativeProviderProps {
|
|
@@ -98,10 +102,10 @@ export const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps> = ({
|
|
|
98
102
|
[JSON.stringify(properties)],
|
|
99
103
|
);
|
|
100
104
|
|
|
101
|
-
const copilotkitRef = useRef<
|
|
105
|
+
const copilotkitRef = useRef<CopilotKitCoreReactInstance | null>(null);
|
|
102
106
|
|
|
103
107
|
if (copilotkitRef.current === null) {
|
|
104
|
-
|
|
108
|
+
const instance: CopilotKitCoreReactInstance = new CopilotKitCoreReact({
|
|
105
109
|
runtimeUrl,
|
|
106
110
|
runtimeTransport:
|
|
107
111
|
useSingleEndpoint === true
|
|
@@ -117,8 +121,9 @@ export const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps> = ({
|
|
|
117
121
|
// Set initial defaultThrottleMs synchronously so child hooks see the
|
|
118
122
|
// correct value on their first render (before useEffect fires).
|
|
119
123
|
if (defaultThrottleMs !== undefined) {
|
|
120
|
-
|
|
124
|
+
instance.setDefaultThrottleMs(defaultThrottleMs);
|
|
121
125
|
}
|
|
126
|
+
copilotkitRef.current = instance;
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
const copilotkit = copilotkitRef.current;
|
|
@@ -161,6 +166,10 @@ export const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps> = ({
|
|
|
161
166
|
ReadonlySet<string>
|
|
162
167
|
>(() => new Set());
|
|
163
168
|
|
|
169
|
+
const [runtimeLicenseStatus, setRuntimeLicenseStatus] = useState<
|
|
170
|
+
RuntimeLicenseStatus | undefined
|
|
171
|
+
>(undefined);
|
|
172
|
+
|
|
164
173
|
// Use ref to avoid subscription churn when onError changes
|
|
165
174
|
const onErrorRef = useRef(onError);
|
|
166
175
|
useEffect(() => {
|
|
@@ -199,6 +208,9 @@ export const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps> = ({
|
|
|
199
208
|
);
|
|
200
209
|
}
|
|
201
210
|
},
|
|
211
|
+
onRuntimeConnectionStatusChanged: () => {
|
|
212
|
+
setRuntimeLicenseStatus(copilotkit.licenseStatus);
|
|
213
|
+
},
|
|
202
214
|
});
|
|
203
215
|
return () => subscription.unsubscribe();
|
|
204
216
|
}, [copilotkit]);
|
|
@@ -211,14 +223,10 @@ export const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps> = ({
|
|
|
211
223
|
[copilotkit, executingToolCallIds],
|
|
212
224
|
);
|
|
213
225
|
|
|
226
|
+
// License context — driven by server-reported status via /info endpoint
|
|
214
227
|
const licenseContextValue = useMemo(
|
|
215
|
-
() => (
|
|
216
|
-
|
|
217
|
-
license: null as null,
|
|
218
|
-
checkFeature: () => true,
|
|
219
|
-
getLimit: () => null,
|
|
220
|
-
}),
|
|
221
|
-
[],
|
|
228
|
+
() => createLicenseContextValue(runtimeLicenseStatus),
|
|
229
|
+
[runtimeLicenseStatus],
|
|
222
230
|
);
|
|
223
231
|
|
|
224
232
|
return (
|
package/src/CopilotSidebar.tsx
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from "react-native";
|
|
19
19
|
import type { ViewStyle } from "react-native";
|
|
20
20
|
import { CopilotChat } from "./CopilotChat";
|
|
21
|
-
import type {
|
|
21
|
+
import type { CopilotChatBaseProps } from "./CopilotChat";
|
|
22
22
|
|
|
23
23
|
// ---------------------------------------------------------------------------
|
|
24
24
|
// Types
|
|
@@ -34,7 +34,7 @@ export interface CopilotSidebarHandle {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export interface CopilotSidebarProps extends Omit<
|
|
37
|
-
|
|
37
|
+
CopilotChatBaseProps,
|
|
38
38
|
"children"
|
|
39
39
|
> {
|
|
40
40
|
/**
|
|
@@ -295,7 +295,7 @@ function resolveWidth(
|
|
|
295
295
|
|
|
296
296
|
const styles = StyleSheet.create({
|
|
297
297
|
backdrop: {
|
|
298
|
-
...StyleSheet.
|
|
298
|
+
...StyleSheet.absoluteFill,
|
|
299
299
|
backgroundColor: `rgba(0, 0, 0, ${BACKDROP_OPACITY})`,
|
|
300
300
|
zIndex: 999,
|
|
301
301
|
},
|
|
@@ -286,7 +286,6 @@ describe("Headless integration", () => {
|
|
|
286
286
|
useFrontendTool({
|
|
287
287
|
name: "test-tool",
|
|
288
288
|
description: "A test tool",
|
|
289
|
-
parameters: {},
|
|
290
289
|
handler: async () => "done",
|
|
291
290
|
});
|
|
292
291
|
return null;
|
|
@@ -342,7 +341,6 @@ describe("Headless integration", () => {
|
|
|
342
341
|
useFrontendTool({
|
|
343
342
|
name: "multi-tool",
|
|
344
343
|
description: "Another tool",
|
|
345
|
-
parameters: {},
|
|
346
344
|
handler: async () => "ok",
|
|
347
345
|
});
|
|
348
346
|
return null;
|
|
@@ -385,7 +383,6 @@ describe("Headless integration", () => {
|
|
|
385
383
|
useFrontendTool({
|
|
386
384
|
name: "orphan-tool",
|
|
387
385
|
description: "No provider",
|
|
388
|
-
parameters: {},
|
|
389
386
|
handler: async () => "fail",
|
|
390
387
|
});
|
|
391
388
|
return null;
|
|
@@ -417,7 +414,7 @@ describe("Headless integration", () => {
|
|
|
417
414
|
|
|
418
415
|
it("useHumanInTheLoop throws when called outside CopilotKitProvider", () => {
|
|
419
416
|
function TestComponent() {
|
|
420
|
-
useHumanInTheLoop();
|
|
417
|
+
useHumanInTheLoop({ name: "orphan-hitl", render: () => null });
|
|
421
418
|
return null;
|
|
422
419
|
}
|
|
423
420
|
|
|
@@ -432,7 +429,7 @@ describe("Headless integration", () => {
|
|
|
432
429
|
|
|
433
430
|
it("useInterrupt throws when called outside CopilotKitProvider", () => {
|
|
434
431
|
function TestComponent() {
|
|
435
|
-
useInterrupt();
|
|
432
|
+
useInterrupt({ render: () => <></> });
|
|
436
433
|
return null;
|
|
437
434
|
}
|
|
438
435
|
|
|
@@ -53,7 +53,7 @@ vi.mock("../messages/UserMessage", () => ({
|
|
|
53
53
|
}));
|
|
54
54
|
|
|
55
55
|
vi.mock("../../hooks/RenderToolContext", () => ({
|
|
56
|
-
useRenderToolRegistry: (
|
|
56
|
+
useRenderToolRegistry: () => hoisted.mockToolRegistry(),
|
|
57
57
|
}));
|
|
58
58
|
|
|
59
59
|
// Mock react-native components with testable DOM elements
|
|
@@ -54,7 +54,7 @@ vi.mock("../messages/UserMessage", () => ({
|
|
|
54
54
|
|
|
55
55
|
// Mock RenderToolContext (B3)
|
|
56
56
|
vi.mock("../../hooks/RenderToolContext", () => ({
|
|
57
|
-
useRenderToolRegistry: (
|
|
57
|
+
useRenderToolRegistry: () => hoisted.mockToolRegistry(),
|
|
58
58
|
}));
|
|
59
59
|
|
|
60
60
|
// Mock react-native components with testable DOM elements
|
package/src/index.ts
CHANGED
package/src/streaming-fetch.ts
CHANGED
|
@@ -314,6 +314,7 @@ export function installStreamingFetch(): void {
|
|
|
314
314
|
`Failed to parse JSON from ${method} ${url} (status ${xhrStatus}): ${
|
|
315
315
|
text.length > 200 ? text.slice(0, 200) + "..." : text
|
|
316
316
|
}`,
|
|
317
|
+
{ cause: e },
|
|
317
318
|
);
|
|
318
319
|
}
|
|
319
320
|
},
|
|
@@ -363,5 +364,5 @@ export function installStreamingFetch(): void {
|
|
|
363
364
|
|
|
364
365
|
// Expose original fetch for opt-out (e.g., third-party libs that need native behavior)
|
|
365
366
|
(streamingFetch as any).__originalFetch = originalFetch;
|
|
366
|
-
global.fetch = streamingFetch;
|
|
367
|
+
global.fetch = streamingFetch as typeof fetch;
|
|
367
368
|
}
|