@copilotkit/react-native 2.0.0-rc.2 → 2.0.0-rc.20
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/{CopilotKitProvider-Byw3cqe2.cjs → CopilotKitProvider-DbI3aQam.cjs} +1 -1
- package/dist/CopilotKitProvider-DbI3aQam.cjs.map +1 -0
- package/dist/{CopilotKitProvider-CE4bc6CP.mjs → CopilotKitProvider-DlP73sLt.mjs} +2 -2
- package/dist/CopilotKitProvider-DlP73sLt.mjs.map +1 -0
- package/dist/{CopilotKitProvider-BWjzCdHN.d.mts → CopilotKitProvider-lfVMYSby.d.cts} +5 -4
- package/dist/{CopilotKitProvider-Btm10msB.d.cts → CopilotKitProvider-mVDI6DLx.d.mts} +5 -4
- package/dist/{Markdown-C_9Re36O.cjs → Markdown-CaYHlD4j.cjs} +8 -8
- package/dist/Markdown-CaYHlD4j.cjs.map +1 -0
- package/dist/{Markdown-1ips7myr.d.cts → Markdown-DzjnSuu5.d.cts} +3 -3
- package/dist/{Markdown-C6AsLHmd.mjs → Markdown-SE9MfY2U.mjs} +4 -4
- package/dist/Markdown-SE9MfY2U.mjs.map +1 -0
- package/dist/{Markdown-JsYh7oSA.d.mts → Markdown-a-rdG22_.d.mts} +3 -3
- package/dist/{MarkdownRendererContext-CAnuohIS.mjs → MarkdownRendererContext-B_AKdPAN.mjs} +1 -1
- package/dist/{MarkdownRendererContext-CAnuohIS.mjs.map → MarkdownRendererContext-B_AKdPAN.mjs.map} +1 -1
- package/dist/components/index.cjs +13 -4
- 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 +14 -5
- package/dist/components/index.mjs.map +1 -1
- package/dist/headless.cjs +2 -1
- package/dist/headless.d.cts +2 -2
- package/dist/headless.d.mts +2 -2
- package/dist/headless.mjs +2 -1
- package/dist/index.cjs +22 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -8
- package/dist/index.d.mts +22 -8
- package/dist/index.mjs +24 -8
- package/dist/index.mjs.map +1 -1
- package/dist/polyfills/encoding.cjs +5 -5
- package/dist/polyfills/encoding.cjs.map +1 -1
- package/dist/polyfills/encoding.mjs +5 -4
- package/dist/polyfills/encoding.mjs.map +1 -1
- package/dist/polyfills.cjs +2 -1
- package/dist/polyfills.cjs.map +1 -1
- package/dist/polyfills.mjs +2 -1
- package/dist/polyfills.mjs.map +1 -1
- package/dist/{streaming-fetch-Dm1oN4f2.mjs → streaming-fetch-CLHG3Z1H.mjs} +1 -1
- package/dist/{streaming-fetch-Dm1oN4f2.mjs.map → streaming-fetch-CLHG3Z1H.mjs.map} +1 -1
- package/dist/{streaming-fetch-Bm91EsRc.cjs → streaming-fetch-DbDALGya.cjs} +1 -1
- package/dist/{streaming-fetch-Bm91EsRc.cjs.map → streaming-fetch-DbDALGya.cjs.map} +1 -1
- package/dist/utf8-BIN9t4Oy.mjs +113 -0
- package/dist/utf8-BIN9t4Oy.mjs.map +1 -0
- package/dist/utf8-Cf3Ssy33.cjs +125 -0
- package/dist/utf8-Cf3Ssy33.cjs.map +1 -0
- package/package.json +11 -20
- package/scripts/verify-polyfill-barrel.mjs +4 -6
- package/src/CopilotChat.tsx +36 -9
- package/src/CopilotKitProvider.tsx +3 -2
- package/src/CopilotPopup.tsx +2 -2
- package/src/CopilotSidebar.tsx +4 -1
- package/src/__mocks__/test-copilotkit.tsx +9 -3
- package/src/__tests__/copilot-chat-configuration.test.tsx +82 -0
- package/src/components/CopilotChat.tsx +24 -3
- 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 +5 -1
- package/src/components/__tests__/CopilotChatInterrupt.test.tsx +208 -0
- package/src/components/__tests__/Markdown.code-alias.test.tsx +1 -1
- package/src/components/messages/AssistantMessage.tsx +3 -2
- package/src/polyfills/__tests__/utf8.test.ts +112 -0
- package/src/polyfills/encoding.ts +5 -4
- package/src/polyfills/utf8.ts +151 -0
- package/src/types.d.ts +0 -13
- 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
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from "react";
|
|
2
8
|
import {
|
|
3
9
|
FlatList,
|
|
4
10
|
KeyboardAvoidingView,
|
|
@@ -286,6 +292,20 @@ export function CopilotChat({
|
|
|
286
292
|
|
|
287
293
|
const renderToolCall = useRenderToolCall();
|
|
288
294
|
|
|
295
|
+
// useInterrupt publishes its element to core unless renderInChat is false.
|
|
296
|
+
// Draw it after the last message, as the web message view does.
|
|
297
|
+
const [interruptElement, setInterruptElement] =
|
|
298
|
+
useState<React.ReactElement | null>(null);
|
|
299
|
+
useEffect(() => {
|
|
300
|
+
setInterruptElement(copilotkit.interruptElement);
|
|
301
|
+
const subscription = copilotkit.subscribe({
|
|
302
|
+
onInterruptElementChanged: ({ interruptElement: element }) => {
|
|
303
|
+
setInterruptElement(element);
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
return () => subscription.unsubscribe();
|
|
307
|
+
}, [copilotkit]);
|
|
308
|
+
|
|
289
309
|
// Recomputed every render — cheap, and the only honest dependency for the
|
|
290
310
|
// message-derived memos below. See `messagesFingerprint` for why the array
|
|
291
311
|
// reference cannot be trusted as one.
|
|
@@ -416,11 +436,11 @@ export function CopilotChat({
|
|
|
416
436
|
);
|
|
417
437
|
|
|
418
438
|
// Send from the input field
|
|
419
|
-
const handleSend = useCallback(
|
|
439
|
+
const handleSend = useCallback(() => {
|
|
420
440
|
const text = inputText.trim();
|
|
421
441
|
if (!text) return;
|
|
422
442
|
setInputText("");
|
|
423
|
-
|
|
443
|
+
void sendMessage(text);
|
|
424
444
|
}, [inputText, sendMessage]);
|
|
425
445
|
|
|
426
446
|
// Handle suggestion pill press
|
|
@@ -522,6 +542,7 @@ export function CopilotChat({
|
|
|
522
542
|
contentContainerStyle={[styles.messageList, messageContainerStyle]}
|
|
523
543
|
onContentSizeChange={handleContentSizeChange}
|
|
524
544
|
ListEmptyComponent={emptyComponent}
|
|
545
|
+
ListFooterComponent={interruptElement}
|
|
525
546
|
/>
|
|
526
547
|
|
|
527
548
|
{error && (
|
|
@@ -2,9 +2,9 @@ import React from "react";
|
|
|
2
2
|
import {
|
|
3
3
|
StreamingMarkdownRenderer,
|
|
4
4
|
defaultMarkdownStyles as _streamingDefaultStyles,
|
|
5
|
-
} from "@copilotkit/markdown
|
|
6
|
-
import type { MarkdownStyle as StreamingMarkdownStyle } from "@copilotkit/markdown
|
|
7
|
-
import { warnUnsupportedRichSyntaxOnce } from "@copilotkit/markdown
|
|
5
|
+
} from "@copilotkit/markdown/react-native";
|
|
6
|
+
import type { MarkdownStyle as StreamingMarkdownStyle } from "@copilotkit/markdown/react-native";
|
|
7
|
+
import { warnUnsupportedRichSyntaxOnce } from "@copilotkit/markdown";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Style map for CopilotMarkdown. Each key maps a node type to a React Native
|
|
@@ -45,7 +45,7 @@ export interface CopilotMarkdownProps {
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* GFM markdown renderer for React Native. Delegates to the shared
|
|
48
|
-
* `StreamingMarkdownRenderer` from `@copilotkit/markdown
|
|
48
|
+
* `StreamingMarkdownRenderer` from `@copilotkit/markdown/react-native`.
|
|
49
49
|
*
|
|
50
50
|
* Public API is backward-compatible with the previous basic renderer:
|
|
51
51
|
* - `CopilotMarkdownProps` — same shape.
|
|
@@ -29,7 +29,11 @@ vi.mock("@copilotkit/react-core/headless", () => ({
|
|
|
29
29
|
|
|
30
30
|
vi.mock("@copilotkit/react-core/context", () => ({
|
|
31
31
|
useCopilotKit: vi.fn(() => ({
|
|
32
|
-
copilotkit: {
|
|
32
|
+
copilotkit: {
|
|
33
|
+
runAgent: hoisted.mockRunAgent,
|
|
34
|
+
interruptElement: null,
|
|
35
|
+
subscribe: () => ({ unsubscribe: () => {} }),
|
|
36
|
+
},
|
|
33
37
|
executingToolCallIds: hoisted.mockExecutingToolCallIds,
|
|
34
38
|
})),
|
|
35
39
|
}));
|
|
@@ -28,7 +28,11 @@ vi.mock("@copilotkit/react-core/headless", () => ({
|
|
|
28
28
|
|
|
29
29
|
vi.mock("@copilotkit/react-core/context", () => ({
|
|
30
30
|
useCopilotKit: vi.fn(() => ({
|
|
31
|
-
copilotkit: {
|
|
31
|
+
copilotkit: {
|
|
32
|
+
runAgent: hoisted.mockRunAgent,
|
|
33
|
+
interruptElement: null,
|
|
34
|
+
subscribe: () => ({ unsubscribe: () => {} }),
|
|
35
|
+
},
|
|
32
36
|
executingToolCallIds: new Set<string>(),
|
|
33
37
|
})),
|
|
34
38
|
}));
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
act,
|
|
4
|
+
fireEvent,
|
|
5
|
+
render,
|
|
6
|
+
screen,
|
|
7
|
+
waitFor,
|
|
8
|
+
} from "@testing-library/react";
|
|
9
|
+
import { describe, expect, it, vi } from "vitest";
|
|
10
|
+
import { EventType, HttpAgent } from "@ag-ui/client";
|
|
11
|
+
import type { RunAgentInput } from "@ag-ui/client";
|
|
12
|
+
import { useCopilotKit } from "@copilotkit/react-core/context";
|
|
13
|
+
import type { CopilotKitCoreReact } from "@copilotkit/react-core/context";
|
|
14
|
+
|
|
15
|
+
// The shared react-native stub passes FlatList props through unused. This one
|
|
16
|
+
// renders the rows and then the footer, which is where CopilotChat draws the
|
|
17
|
+
// interrupt element.
|
|
18
|
+
vi.mock("react-native", async () => {
|
|
19
|
+
const actual = await vi.importActual<any>("../../__mocks__/react-native");
|
|
20
|
+
return {
|
|
21
|
+
...actual,
|
|
22
|
+
FlatList: ({
|
|
23
|
+
data,
|
|
24
|
+
renderItem,
|
|
25
|
+
keyExtractor,
|
|
26
|
+
ListEmptyComponent,
|
|
27
|
+
ListFooterComponent,
|
|
28
|
+
}: any) =>
|
|
29
|
+
React.createElement(
|
|
30
|
+
"div",
|
|
31
|
+
{ "data-testid": "flatlist" },
|
|
32
|
+
data?.length
|
|
33
|
+
? data.map((item: any, index: number) =>
|
|
34
|
+
React.createElement(
|
|
35
|
+
"div",
|
|
36
|
+
{ key: keyExtractor?.(item) ?? index },
|
|
37
|
+
renderItem({ item, index, separators: {} }),
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
: ListEmptyComponent,
|
|
41
|
+
ListFooterComponent,
|
|
42
|
+
),
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
import { CopilotChat } from "../CopilotChat";
|
|
47
|
+
import { useInterrupt } from "../../headless";
|
|
48
|
+
import { TestCopilotKit } from "../../__mocks__/test-copilotkit";
|
|
49
|
+
|
|
50
|
+
function CoreProbe({
|
|
51
|
+
coreRef,
|
|
52
|
+
}: {
|
|
53
|
+
coreRef: { current: CopilotKitCoreReact | null };
|
|
54
|
+
}) {
|
|
55
|
+
coreRef.current = useCopilotKit().copilotkit;
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* An agent whose first run stops on an approval interrupt and whose later runs
|
|
61
|
+
* finish normally. It streams real AG-UI events over SSE, so core and
|
|
62
|
+
* useInterrupt see the same run lifecycle as in an app.
|
|
63
|
+
*/
|
|
64
|
+
function createInterruptingAgent() {
|
|
65
|
+
const inputs: RunAgentInput[] = [];
|
|
66
|
+
const agent = new HttpAgent({
|
|
67
|
+
url: "http://localhost/agent",
|
|
68
|
+
fetch: async (_url, init) => {
|
|
69
|
+
const input = JSON.parse(String(init.body)) as RunAgentInput;
|
|
70
|
+
inputs.push(input);
|
|
71
|
+
const { threadId, runId } = input;
|
|
72
|
+
const events = [
|
|
73
|
+
{ type: EventType.RUN_STARTED, threadId, runId },
|
|
74
|
+
{
|
|
75
|
+
type: EventType.RUN_FINISHED,
|
|
76
|
+
threadId,
|
|
77
|
+
runId,
|
|
78
|
+
...(inputs.length === 1
|
|
79
|
+
? {
|
|
80
|
+
outcome: {
|
|
81
|
+
type: "interrupt",
|
|
82
|
+
interrupts: [
|
|
83
|
+
{ id: "approve", reason: "approval", message: "Deploy?" },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
: {}),
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
return new Response(
|
|
91
|
+
events.map((event) => `data: ${JSON.stringify(event)}\n\n`).join(""),
|
|
92
|
+
{ headers: { "Content-Type": "text/event-stream" } },
|
|
93
|
+
);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
return { agent, inputs };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Uses useInterrupt with the default renderInChat: true. */
|
|
100
|
+
function Approval() {
|
|
101
|
+
useInterrupt({
|
|
102
|
+
render: ({ interrupt, resolve }) => (
|
|
103
|
+
<button
|
|
104
|
+
data-testid="interrupt-ui"
|
|
105
|
+
onClick={() => void resolve({ approved: true })}
|
|
106
|
+
>
|
|
107
|
+
{interrupt?.message}
|
|
108
|
+
</button>
|
|
109
|
+
),
|
|
110
|
+
});
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const messages = [
|
|
115
|
+
{ id: "u1", role: "user", content: "Deploy the app" },
|
|
116
|
+
{ id: "a1", role: "assistant", content: "I need your approval first." },
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
function Chat({
|
|
120
|
+
agent,
|
|
121
|
+
coreRef,
|
|
122
|
+
withApproval = true,
|
|
123
|
+
}: {
|
|
124
|
+
agent: HttpAgent;
|
|
125
|
+
coreRef: { current: CopilotKitCoreReact | null };
|
|
126
|
+
withApproval?: boolean;
|
|
127
|
+
}) {
|
|
128
|
+
return (
|
|
129
|
+
<TestCopilotKit messages={messages} agent={agent}>
|
|
130
|
+
<CoreProbe coreRef={coreRef} />
|
|
131
|
+
{withApproval && <Approval />}
|
|
132
|
+
<CopilotChat />
|
|
133
|
+
</TestCopilotKit>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Mounts the chat and runs the agent until it stops on the interrupt. */
|
|
138
|
+
async function renderInterruptedChat() {
|
|
139
|
+
const { agent, inputs } = createInterruptingAgent();
|
|
140
|
+
const coreRef: { current: CopilotKitCoreReact | null } = { current: null };
|
|
141
|
+
const view = render(<Chat agent={agent} coreRef={coreRef} />);
|
|
142
|
+
expect(screen.queryByTestId("interrupt-ui")).toBeNull();
|
|
143
|
+
|
|
144
|
+
await act(async () => {
|
|
145
|
+
await coreRef.current!.runAgent({ agent });
|
|
146
|
+
});
|
|
147
|
+
await waitFor(() => expect(screen.getByTestId("interrupt-ui")).toBeTruthy());
|
|
148
|
+
return { ...view, agent, inputs, coreRef };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
describe("CopilotChat interrupt rendering", () => {
|
|
152
|
+
it("draws the interrupt element that useInterrupt publishes to core", () => {
|
|
153
|
+
const coreRef: { current: CopilotKitCoreReact | null } = { current: null };
|
|
154
|
+
render(
|
|
155
|
+
<TestCopilotKit messages={[]}>
|
|
156
|
+
<CoreProbe coreRef={coreRef} />
|
|
157
|
+
<CopilotChat />
|
|
158
|
+
</TestCopilotKit>,
|
|
159
|
+
);
|
|
160
|
+
expect(screen.queryByTestId("interrupt-ui")).toBeNull();
|
|
161
|
+
|
|
162
|
+
act(() => {
|
|
163
|
+
coreRef.current!.setInterruptElement(
|
|
164
|
+
<div data-testid="interrupt-ui">Approve?</div>,
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
expect(screen.getByTestId("interrupt-ui").textContent).toBe("Approve?");
|
|
168
|
+
|
|
169
|
+
act(() => {
|
|
170
|
+
coreRef.current!.setInterruptElement(null);
|
|
171
|
+
});
|
|
172
|
+
expect(screen.queryByTestId("interrupt-ui")).toBeNull();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("draws a useInterrupt element after the last message and removes it once resolved", async () => {
|
|
176
|
+
const { inputs } = await renderInterruptedChat();
|
|
177
|
+
|
|
178
|
+
const interrupt = screen.getByTestId("interrupt-ui");
|
|
179
|
+
expect(interrupt.textContent).toBe("Deploy?");
|
|
180
|
+
const lastMessage = screen.getByText("I need your approval first.");
|
|
181
|
+
expect(
|
|
182
|
+
lastMessage.compareDocumentPosition(interrupt) &
|
|
183
|
+
Node.DOCUMENT_POSITION_FOLLOWING,
|
|
184
|
+
).toBeTruthy();
|
|
185
|
+
|
|
186
|
+
await act(async () => {
|
|
187
|
+
fireEvent.click(interrupt);
|
|
188
|
+
});
|
|
189
|
+
await waitFor(() => expect(inputs).toHaveLength(2));
|
|
190
|
+
expect(inputs[1]!.resume).toEqual([
|
|
191
|
+
{
|
|
192
|
+
interruptId: "approve",
|
|
193
|
+
status: "resolved",
|
|
194
|
+
payload: { approved: true },
|
|
195
|
+
},
|
|
196
|
+
]);
|
|
197
|
+
await waitFor(() =>
|
|
198
|
+
expect(screen.queryByTestId("interrupt-ui")).toBeNull(),
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("removes the useInterrupt element when its component unmounts", async () => {
|
|
203
|
+
const { agent, coreRef, rerender } = await renderInterruptedChat();
|
|
204
|
+
|
|
205
|
+
rerender(<Chat agent={agent} coreRef={coreRef} withApproval={false} />);
|
|
206
|
+
expect(screen.queryByTestId("interrupt-ui")).toBeNull();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
@@ -14,7 +14,7 @@ vi.mock("react-native", () => ({
|
|
|
14
14
|
// Capture the props handed to the underlying streaming renderer so we can
|
|
15
15
|
// assert how CopilotMarkdown translates its public style map.
|
|
16
16
|
const capturedProps: any[] = [];
|
|
17
|
-
vi.mock("@copilotkit/markdown
|
|
17
|
+
vi.mock("@copilotkit/markdown/react-native", () => ({
|
|
18
18
|
StreamingMarkdownRenderer: (props: any) => {
|
|
19
19
|
capturedProps.push(props);
|
|
20
20
|
return null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { View, Text, StyleSheet
|
|
2
|
+
import { View, Text, StyleSheet } from "react-native";
|
|
3
|
+
import type { ViewStyle } from "react-native";
|
|
3
4
|
import { CopilotMarkdown } from "../Markdown";
|
|
4
5
|
import {
|
|
5
6
|
useMarkdownRenderer,
|
|
@@ -19,7 +20,7 @@ const TIMESTAMP_COLOR = "#999999";
|
|
|
19
20
|
export interface AssistantMessageProps {
|
|
20
21
|
/** Markdown content to render inside the bubble */
|
|
21
22
|
content: string;
|
|
22
|
-
/** When true, shows a typing indicator
|
|
23
|
+
/** When true, shows a typing indicator below any content */
|
|
23
24
|
isLoading?: boolean;
|
|
24
25
|
/** Optional timestamp displayed below the bubble */
|
|
25
26
|
timestamp?: Date;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { Utf8TextDecoder, Utf8TextEncoder } from "../utf8";
|
|
3
|
+
|
|
4
|
+
// Node's built-in classes are the reference: the polyfill must give the same
|
|
5
|
+
// output on the runtimes that lack them.
|
|
6
|
+
const NativeEncoder = globalThis.TextEncoder;
|
|
7
|
+
const NativeDecoder = globalThis.TextDecoder;
|
|
8
|
+
|
|
9
|
+
const strings = [
|
|
10
|
+
"",
|
|
11
|
+
"hello",
|
|
12
|
+
"Grüße, 東京, emoji 🚀🧪",
|
|
13
|
+
"\u0000\u007f\u0080߿ࠀ",
|
|
14
|
+
"🚀 pair, \ud800 lone high, \udc00 lone low",
|
|
15
|
+
"starts with a BOM",
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const byteSequences: number[][] = [
|
|
19
|
+
[0xe2, 0x82, 0xac],
|
|
20
|
+
[0xc3],
|
|
21
|
+
[0xc0, 0x80],
|
|
22
|
+
[0xed, 0xa0, 0x80],
|
|
23
|
+
[0xf4, 0x90, 0x80, 0x80],
|
|
24
|
+
[0xf0, 0x9f, 0x9a],
|
|
25
|
+
[0xe0, 0x80, 0x41],
|
|
26
|
+
[0x80, 0xbf, 0x41],
|
|
27
|
+
[0xff, 0xfe, 0x41],
|
|
28
|
+
[0xef, 0xbb, 0xbf, 0x41],
|
|
29
|
+
[0xf0, 0x9f, 0x98, 0x80, 0xe2, 0x82],
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
function splits(bytes: Uint8Array): Uint8Array[][] {
|
|
33
|
+
const out: Uint8Array[][] = [[bytes]];
|
|
34
|
+
for (let at = 0; at <= bytes.length; at++) {
|
|
35
|
+
out.push([bytes.subarray(0, at), bytes.subarray(at)]);
|
|
36
|
+
}
|
|
37
|
+
out.push([...bytes].map((byte) => new Uint8Array([byte])));
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function streamDecode(
|
|
42
|
+
decoder: {
|
|
43
|
+
decode: (input?: Uint8Array, options?: { stream?: boolean }) => string;
|
|
44
|
+
},
|
|
45
|
+
chunks: Uint8Array[],
|
|
46
|
+
): string {
|
|
47
|
+
return (
|
|
48
|
+
chunks.map((chunk) => decoder.decode(chunk, { stream: true })).join("") +
|
|
49
|
+
decoder.decode()
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("Utf8TextEncoder", () => {
|
|
54
|
+
it.each(strings)("encodes %j like the built-in encoder", (input) => {
|
|
55
|
+
expect([...new Utf8TextEncoder().encode(input)]).toEqual([
|
|
56
|
+
...new NativeEncoder().encode(input),
|
|
57
|
+
]);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("Utf8TextDecoder", () => {
|
|
62
|
+
const inputs = [
|
|
63
|
+
...strings.map((input) => new NativeEncoder().encode(input)),
|
|
64
|
+
...byteSequences.map((bytes) => new Uint8Array(bytes)),
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
it.each(inputs.map((bytes) => [[...bytes].join(","), bytes] as const))(
|
|
68
|
+
"decodes [%s] like the built-in decoder, in every chunk split",
|
|
69
|
+
(_, bytes) => {
|
|
70
|
+
for (const chunks of splits(bytes)) {
|
|
71
|
+
for (const ignoreBOM of [false, true]) {
|
|
72
|
+
expect(
|
|
73
|
+
streamDecode(new Utf8TextDecoder("utf-8", { ignoreBOM }), chunks),
|
|
74
|
+
).toBe(
|
|
75
|
+
streamDecode(new NativeDecoder("utf-8", { ignoreBOM }), chunks),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
it("throws on invalid bytes when fatal is set", () => {
|
|
83
|
+
for (const bytes of byteSequences.map((b) => new Uint8Array(b))) {
|
|
84
|
+
const native = () =>
|
|
85
|
+
new NativeDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
86
|
+
const polyfill = () =>
|
|
87
|
+
new Utf8TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
88
|
+
let nativeThrew = false;
|
|
89
|
+
try {
|
|
90
|
+
native();
|
|
91
|
+
} catch {
|
|
92
|
+
nativeThrew = true;
|
|
93
|
+
}
|
|
94
|
+
if (nativeThrew) expect(polyfill).toThrow(TypeError);
|
|
95
|
+
else expect(polyfill()).toBe(native());
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("decodes an ArrayBuffer and a view into a larger buffer", () => {
|
|
100
|
+
const buffer = new NativeEncoder().encode("xx東京xx").buffer;
|
|
101
|
+
expect(new Utf8TextDecoder().decode(buffer)).toBe("xx東京xx");
|
|
102
|
+
expect(new Utf8TextDecoder().decode(new Uint8Array(buffer, 2, 6))).toBe(
|
|
103
|
+
"東京",
|
|
104
|
+
);
|
|
105
|
+
expect(new Utf8TextDecoder().decode()).toBe("");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("supports only UTF-8", () => {
|
|
109
|
+
expect(new Utf8TextDecoder("UTF8").encoding).toBe("utf-8");
|
|
110
|
+
expect(() => new Utf8TextDecoder("latin1")).toThrow(RangeError);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Polyfill: TextEncoder, TextDecoder
|
|
3
3
|
*
|
|
4
|
-
* Required for stream chunk processing in CopilotKit.
|
|
4
|
+
* Required for stream chunk processing in CopilotKit. The polyfill supports
|
|
5
|
+
* UTF-8, the only encoding that CopilotKit uses.
|
|
5
6
|
* Skipped if the globals are already defined.
|
|
6
7
|
*
|
|
7
8
|
* Usage:
|
|
8
9
|
* import "@copilotkit/react-native/polyfills/encoding";
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
|
-
import {
|
|
12
|
+
import { Utf8TextDecoder, Utf8TextEncoder } from "./utf8";
|
|
12
13
|
|
|
13
14
|
const g = globalThis as Record<string, unknown>;
|
|
14
15
|
|
|
15
16
|
if (typeof g.TextEncoder === "undefined") {
|
|
16
|
-
g.TextEncoder =
|
|
17
|
+
g.TextEncoder = Utf8TextEncoder;
|
|
17
18
|
}
|
|
18
19
|
if (typeof g.TextDecoder === "undefined") {
|
|
19
|
-
g.TextDecoder =
|
|
20
|
+
g.TextDecoder = Utf8TextDecoder;
|
|
20
21
|
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UTF-8 `TextEncoder` and `TextDecoder`, for runtimes that have neither.
|
|
3
|
+
*
|
|
4
|
+
* CopilotKit only reads and writes UTF-8, so these classes support only that
|
|
5
|
+
* encoding. The decoder follows the WHATWG UTF-8 decode algorithm, so its
|
|
6
|
+
* output, including U+FFFD for invalid bytes and `{ stream: true }` chunks,
|
|
7
|
+
* matches the built-in `TextDecoder`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const REPLACEMENT = 0xfffd;
|
|
11
|
+
|
|
12
|
+
export class Utf8TextEncoder {
|
|
13
|
+
readonly encoding = "utf-8";
|
|
14
|
+
|
|
15
|
+
encode(input = ""): Uint8Array {
|
|
16
|
+
const bytes: number[] = [];
|
|
17
|
+
for (const char of input) {
|
|
18
|
+
let codePoint = char.codePointAt(0)!;
|
|
19
|
+
// A lone surrogate is not a Unicode scalar value.
|
|
20
|
+
if (codePoint >= 0xd800 && codePoint <= 0xdfff) codePoint = REPLACEMENT;
|
|
21
|
+
if (codePoint < 0x80) bytes.push(codePoint);
|
|
22
|
+
else if (codePoint < 0x800)
|
|
23
|
+
bytes.push(0xc0 | (codePoint >> 6), 0x80 | (codePoint & 0x3f));
|
|
24
|
+
else if (codePoint < 0x10000)
|
|
25
|
+
bytes.push(
|
|
26
|
+
0xe0 | (codePoint >> 12),
|
|
27
|
+
0x80 | ((codePoint >> 6) & 0x3f),
|
|
28
|
+
0x80 | (codePoint & 0x3f),
|
|
29
|
+
);
|
|
30
|
+
else
|
|
31
|
+
bytes.push(
|
|
32
|
+
0xf0 | (codePoint >> 18),
|
|
33
|
+
0x80 | ((codePoint >> 12) & 0x3f),
|
|
34
|
+
0x80 | ((codePoint >> 6) & 0x3f),
|
|
35
|
+
0x80 | (codePoint & 0x3f),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return new Uint8Array(bytes);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class Utf8TextDecoder {
|
|
43
|
+
readonly encoding = "utf-8";
|
|
44
|
+
readonly fatal: boolean;
|
|
45
|
+
readonly ignoreBOM: boolean;
|
|
46
|
+
|
|
47
|
+
#codePoint = 0;
|
|
48
|
+
#bytesNeeded = 0;
|
|
49
|
+
#bytesSeen = 0;
|
|
50
|
+
#lowerBoundary = 0x80;
|
|
51
|
+
#upperBoundary = 0xbf;
|
|
52
|
+
#atStart = true;
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
label = "utf-8",
|
|
56
|
+
options: { fatal?: boolean; ignoreBOM?: boolean } = {},
|
|
57
|
+
) {
|
|
58
|
+
const normalized = String(label).trim().toLowerCase();
|
|
59
|
+
if (normalized !== "utf-8" && normalized !== "utf8") {
|
|
60
|
+
throw new RangeError(`The "${label}" encoding is not supported.`);
|
|
61
|
+
}
|
|
62
|
+
this.fatal = options.fatal ?? false;
|
|
63
|
+
this.ignoreBOM = options.ignoreBOM ?? false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
decode(
|
|
67
|
+
input?: ArrayBuffer | ArrayBufferView,
|
|
68
|
+
options: { stream?: boolean } = {},
|
|
69
|
+
): string {
|
|
70
|
+
const bytes =
|
|
71
|
+
input === undefined
|
|
72
|
+
? new Uint8Array(0)
|
|
73
|
+
: ArrayBuffer.isView(input)
|
|
74
|
+
? new Uint8Array(input.buffer, input.byteOffset, input.byteLength)
|
|
75
|
+
: new Uint8Array(input);
|
|
76
|
+
const codePoints: number[] = [];
|
|
77
|
+
|
|
78
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
79
|
+
const byte = bytes[i];
|
|
80
|
+
if (this.#bytesNeeded === 0) {
|
|
81
|
+
if (byte <= 0x7f) codePoints.push(byte);
|
|
82
|
+
else if (byte >= 0xc2 && byte <= 0xdf) this.#start(1, byte & 0x1f);
|
|
83
|
+
else if (byte >= 0xe0 && byte <= 0xef) {
|
|
84
|
+
if (byte === 0xe0) this.#lowerBoundary = 0xa0;
|
|
85
|
+
if (byte === 0xed) this.#upperBoundary = 0x9f;
|
|
86
|
+
this.#start(2, byte & 0x0f);
|
|
87
|
+
} else if (byte >= 0xf0 && byte <= 0xf4) {
|
|
88
|
+
if (byte === 0xf0) this.#lowerBoundary = 0x90;
|
|
89
|
+
if (byte === 0xf4) this.#upperBoundary = 0x8f;
|
|
90
|
+
this.#start(3, byte & 0x07);
|
|
91
|
+
} else codePoints.push(this.#error());
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (byte < this.#lowerBoundary || byte > this.#upperBoundary) {
|
|
95
|
+
// The sequence ends early. Read this byte again as a new sequence.
|
|
96
|
+
this.#reset();
|
|
97
|
+
codePoints.push(this.#error());
|
|
98
|
+
i--;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
this.#lowerBoundary = 0x80;
|
|
102
|
+
this.#upperBoundary = 0xbf;
|
|
103
|
+
this.#codePoint = (this.#codePoint << 6) | (byte & 0x3f);
|
|
104
|
+
if (++this.#bytesSeen === this.#bytesNeeded) {
|
|
105
|
+
codePoints.push(this.#codePoint);
|
|
106
|
+
this.#reset();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!options.stream && this.#bytesNeeded > 0) {
|
|
111
|
+
this.#reset();
|
|
112
|
+
codePoints.push(this.#error());
|
|
113
|
+
}
|
|
114
|
+
if (this.#atStart && codePoints.length > 0) {
|
|
115
|
+
this.#atStart = false;
|
|
116
|
+
if (!this.ignoreBOM && codePoints[0] === 0xfeff) codePoints.shift();
|
|
117
|
+
}
|
|
118
|
+
if (!options.stream) this.#atStart = true;
|
|
119
|
+
return codePointsToString(codePoints);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
#start(bytesNeeded: number, codePoint: number): void {
|
|
123
|
+
this.#bytesNeeded = bytesNeeded;
|
|
124
|
+
this.#codePoint = codePoint;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#reset(): void {
|
|
128
|
+
this.#codePoint = 0;
|
|
129
|
+
this.#bytesNeeded = 0;
|
|
130
|
+
this.#bytesSeen = 0;
|
|
131
|
+
this.#lowerBoundary = 0x80;
|
|
132
|
+
this.#upperBoundary = 0xbf;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#error(): number {
|
|
136
|
+
if (this.fatal) {
|
|
137
|
+
this.#atStart = true;
|
|
138
|
+
throw new TypeError("The encoded data was not valid utf-8.");
|
|
139
|
+
}
|
|
140
|
+
return REPLACEMENT;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function codePointsToString(codePoints: number[]): string {
|
|
145
|
+
let out = "";
|
|
146
|
+
// Stay under the engine's limit on function arguments.
|
|
147
|
+
for (let i = 0; i < codePoints.length; i += 0x8000) {
|
|
148
|
+
out += String.fromCodePoint(...codePoints.slice(i, i + 0x8000));
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
package/src/types.d.ts
CHANGED
|
@@ -8,16 +8,3 @@ declare const __DEV__: boolean;
|
|
|
8
8
|
// (`g`) instead of repeating `(globalThis as any)` on every line — same pattern as
|
|
9
9
|
// packages/angular/src/test-setup.ts. Files without imports add `export {}` so
|
|
10
10
|
// TypeScript treats them as modules with isolated scope.
|
|
11
|
-
|
|
12
|
-
declare module "text-encoding" {
|
|
13
|
-
export class TextEncoder {
|
|
14
|
-
encode(input?: string): Uint8Array;
|
|
15
|
-
}
|
|
16
|
-
export class TextDecoder {
|
|
17
|
-
constructor(label?: string, options?: { fatal?: boolean });
|
|
18
|
-
decode(
|
|
19
|
-
input?: ArrayBufferView | ArrayBuffer,
|
|
20
|
-
options?: { stream?: boolean },
|
|
21
|
-
): string;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CopilotKitProvider-Byw3cqe2.cjs","names":["CopilotKitCoreReact","CopilotKitContext","LicenseContext","MarkdownRendererProvider"],"sources":["../src/CopilotKitProvider.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport {\n CopilotKitContext,\n LicenseContext,\n} from \"@copilotkit/react-core/context\";\nimport type {\n CopilotKitContextValue,\n CopilotKitCoreReact as CopilotKitCoreReactInstance,\n} from \"@copilotkit/react-core/context\";\nimport { CopilotKitCoreReact } from \"@copilotkit/react-core/headless\";\nimport type {\n CopilotKitCoreErrorCode,\n CopilotKitMessageFilter,\n} from \"@copilotkit/core\";\nimport type { DebugConfig, RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport { createLicenseContextValue } from \"@copilotkit/shared\";\nimport { MarkdownRendererProvider } from \"./components/MarkdownRendererContext\";\nimport type { MarkdownRendererValue } from \"./components/MarkdownRendererContext\";\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> | (() => Record<string, string>);\n /**\n * Credentials mode for fetch requests (e.g., \"include\" for HTTP-only cookies in cross-origin requests).\n */\n credentials?: RequestCredentials;\n /**\n * Rewrites the message list sent to runtime agents on every run.\n *\n * CopilotKit sends the whole thread each time. When your agent already\n * stores the conversation, most of that payload is waste, and an agent that\n * merges the inbound list with its own store can show the model every turn\n * twice. Return the messages to send:\n *\n * ```tsx\n * <CopilotKitProvider\n * runtimeUrl=\"/api/copilotkit\"\n * messageFilter={(messages) => messages.slice(-1)}\n * />\n * ```\n *\n * The filter changes the request body only. The transcript the UI renders is\n * untouched. Broken tool-call pairs are repaired before the request is sent,\n * so a filter this blunt cannot strand a tool result mid-HITL.\n *\n * Agents reached through your CopilotRuntime honor this. An agent your app\n * passes in directly does not, and neither Intelligence runs nor suggestion\n * runs are ever filtered.\n *\n * Prefer a stable reference (`useCallback`). An inline arrow re-registers the\n * filter on every render, which is harmless but needless.\n */\n messageFilter?: CopilotKitMessageFilter;\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 | Promise<void>;\n /**\n * Enable debug logging for the client-side event pipeline.\n * When `true`, enables verbose logging from the core instance.\n */\n debug?: DebugConfig;\n /**\n * Default throttle interval (ms) for `onMessagesChanged` / `onStateChanged`\n * subscriptions. Individual subscriptions can override with their own `throttleMs`.\n */\n defaultThrottleMs?: number;\n /**\n * Custom markdown renderer for assistant messages. Either a component (escape\n * hatch — receives `content` and an optional `isStreaming` flag) used instead\n * of the built-in renderer, or a `{ style, animate }` config object to\n * configure the built-in React Native renderer (the `CopilotMarkdown` used by\n * the default `AssistantMessage`) without writing a wrapper.\n */\n markdownRenderer?: MarkdownRendererValue;\n // Cloud features (publicApiKey, licenseToken) — not yet supported on React Native\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 * Polyfills are auto-imported when `@copilotkit/react-native` is loaded,\n * so a separate `import \"@copilotkit/react-native/polyfills\"` is no longer\n * required (though it remains available for advanced use).\n *\n * Usage:\n * ```tsx\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: headersProp,\n credentials,\n messageFilter,\n useSingleEndpoint,\n properties,\n onError,\n debug,\n defaultThrottleMs,\n markdownRenderer,\n}) => {\n // Resolve headers from function or static object (matches web provider pattern)\n const resolvedHeaders =\n typeof headersProp === \"function\" ? headersProp() : headersProp;\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(\n () => resolvedHeaders ?? {},\n [JSON.stringify(resolvedHeaders)],\n );\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<CopilotKitCoreReactInstance | null>(null);\n\n if (copilotkitRef.current === null) {\n const instance: CopilotKitCoreReactInstance = new CopilotKitCoreReact({\n runtimeUrl,\n runtimeTransport:\n useSingleEndpoint === true\n ? \"single\"\n : useSingleEndpoint === false\n ? \"rest\"\n : \"auto\",\n headers: stableHeaders,\n credentials,\n messageFilter,\n properties: stableProperties,\n debug,\n });\n // Set initial defaultThrottleMs synchronously so child hooks see the\n // correct value on their first render (before useEffect fires).\n if (defaultThrottleMs !== undefined) {\n instance.setDefaultThrottleMs(defaultThrottleMs);\n }\n copilotkitRef.current = instance;\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.setCredentials(credentials);\n copilotkit.setMessageFilter(messageFilter);\n copilotkit.setProperties(stableProperties);\n copilotkit.setDebug(debug);\n }, [\n runtimeUrl,\n useSingleEndpoint,\n stableHeaders,\n credentials,\n messageFilter,\n stableProperties,\n debug,\n copilotkit,\n ]);\n\n // Sync defaultThrottleMs to the core instance on prop changes.\n // Initial value is set synchronously during instance creation (inside the\n // ref guard above), so this only handles subsequent updates.\n useEffect(() => {\n copilotkit.setDefaultThrottleMs(defaultThrottleMs);\n }, [copilotkit, defaultThrottleMs]);\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 const [runtimeLicenseStatus, setRuntimeLicenseStatus] = useState<\n RuntimeLicenseStatus | undefined\n >(undefined);\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 onRuntimeConnectionStatusChanged: () => {\n setRuntimeLicenseStatus(copilotkit.licenseStatus);\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 // License context — driven by server-reported status via /info endpoint\n const licenseContextValue = useMemo(\n () => createLicenseContextValue(runtimeLicenseStatus),\n [runtimeLicenseStatus],\n );\n\n return (\n <CopilotKitContext.Provider value={contextValue}>\n <LicenseContext.Provider value={licenseContextValue}>\n <MarkdownRendererProvider renderer={markdownRenderer}>\n {children}\n </MarkdownRendererProvider>\n </LicenseContext.Provider>\n </CopilotKitContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmHA,MAAa,sBAA+D,EAC1E,UACA,YACA,SAAS,aACT,aACA,eACA,mBACA,YACA,SACA,OACA,mBACA,uBACI;CAEJ,MAAM,kBACJ,OAAO,gBAAgB,aAAa,aAAa,GAAG;CAKtD,MAAM,yCACE,mBAAmB,EAAE,EAC3B,CAAC,KAAK,UAAU,gBAAgB,CAAC,CAClC;CAED,MAAM,4CACE,cAAc,EAAE,EACtB,CAAC,KAAK,UAAU,WAAW,CAAC,CAC7B;CAED,MAAM,kCAA2D,KAAK;AAEtE,KAAI,cAAc,YAAY,MAAM;EAClC,MAAM,WAAwC,IAAIA,oDAAoB;GACpE;GACA,kBACE,sBAAsB,OAClB,WACA,sBAAsB,QACpB,SACA;GACR,SAAS;GACT;GACA;GACA,YAAY;GACZ;GACD,CAAC;AAGF,MAAI,sBAAsB,OACxB,UAAS,qBAAqB,kBAAkB;AAElD,gBAAc,UAAU;;CAG1B,MAAM,aAAa,cAAc;AAGjC,4BAAgB;AACd,aAAW,cAAc,WAAW;AACpC,aAAW,oBACT,sBAAsB,OAClB,WACA,sBAAsB,QACpB,SACA,OACP;AACD,aAAW,WAAW,cAAc;AACpC,aAAW,eAAe,YAAY;AACtC,aAAW,iBAAiB,cAAc;AAC1C,aAAW,cAAc,iBAAiB;AAC1C,aAAW,SAAS,MAAM;IACzB;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAKF,4BAAgB;AACd,aAAW,qBAAqB,kBAAkB;IACjD,CAAC,YAAY,kBAAkB,CAAC;CAKnC,MAAM,CAAC,sBAAsB,qEAErB,IAAI,KAAK,CAAC;CAElB,MAAM,CAAC,sBAAsB,+CAE3B,OAAU;CAGZ,MAAM,+BAAoB,QAAQ;AAClC,4BAAgB;AACd,aAAW,UAAU;IACpB,CAAC,QAAQ,CAAC;AAKb,4BAAgB;EACd,MAAM,eAAe,WAAW,UAAU;GACxC,uBAAuB,EAAE,iBAAiB;AACxC,6BAAyB,SAAS;AAChC,SAAI,KAAK,IAAI,WAAW,CAAE,QAAO;KACjC,MAAM,OAAO,IAAI,IAAI,KAAK;AAC1B,UAAK,IAAI,WAAW;AACpB,YAAO;MACP;;GAEJ,qBAAqB,EAAE,iBAAiB;AACtC,6BAAyB,SAAS;AAChC,SAAI,CAAC,KAAK,IAAI,WAAW,CAAE,QAAO;KAClC,MAAM,OAAO,IAAI,IAAI,KAAK;AAC1B,UAAK,OAAO,WAAW;AACvB,YAAO;MACP;;GAEJ,UAAU,UAAU;AAClB,QAAI,WAAW,QACb,YAAW,QAAQ,MAAM;QAEzB,SAAQ,MACN,uBAAuB,MAAM,KAAK,KAClC,MAAM,OACN,MAAM,WAAW,EAAE,CACpB;;GAGL,wCAAwC;AACtC,4BAAwB,WAAW,cAAc;;GAEpD,CAAC;AACF,eAAa,aAAa,aAAa;IACtC,CAAC,WAAW,CAAC;CAEhB,MAAM,yCACG;EACL;EACA;EACD,GACD,CAAC,YAAY,qBAAqB,CACnC;CAGD,MAAM,iGAC4B,qBAAqB,EACrD,CAAC,qBAAqB,CACvB;AAED,QACE,2CAACC,iDAAkB;EAAS,OAAO;YACjC,2CAACC,8CAAe;GAAS,OAAO;aAC9B,2CAACC;IAAyB,UAAU;IACjC;KACwB;IACH;GACC"}
|