@copilotkit/react-native 2.0.0-rc.2 → 2.0.0-rc.21

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.
Files changed (78) hide show
  1. package/dist/{CopilotKitProvider-CE4bc6CP.mjs → CopilotKitProvider-BXpkAl1Y.mjs} +55 -42
  2. package/dist/CopilotKitProvider-BXpkAl1Y.mjs.map +1 -0
  3. package/dist/{CopilotKitProvider-Byw3cqe2.cjs → CopilotKitProvider-DDPbJkHS.cjs} +53 -40
  4. package/dist/CopilotKitProvider-DDPbJkHS.cjs.map +1 -0
  5. package/dist/CopilotKitProvider-F7Pn5kp4.d.cts +65 -0
  6. package/dist/CopilotKitProvider-Khgz5dQo.d.mts +65 -0
  7. package/dist/{Markdown-C_9Re36O.cjs → Markdown-CaYHlD4j.cjs} +8 -8
  8. package/dist/Markdown-CaYHlD4j.cjs.map +1 -0
  9. package/dist/{Markdown-1ips7myr.d.cts → Markdown-DzjnSuu5.d.cts} +3 -3
  10. package/dist/{Markdown-C6AsLHmd.mjs → Markdown-SE9MfY2U.mjs} +4 -4
  11. package/dist/Markdown-SE9MfY2U.mjs.map +1 -0
  12. package/dist/{Markdown-JsYh7oSA.d.mts → Markdown-a-rdG22_.d.mts} +3 -3
  13. package/dist/{MarkdownRendererContext-CAnuohIS.mjs → MarkdownRendererContext-B_AKdPAN.mjs} +1 -1
  14. package/dist/{MarkdownRendererContext-CAnuohIS.mjs.map → MarkdownRendererContext-B_AKdPAN.mjs.map} +1 -1
  15. package/dist/components/index.cjs +13 -4
  16. package/dist/components/index.cjs.map +1 -1
  17. package/dist/components/index.d.cts +2 -2
  18. package/dist/components/index.d.mts +2 -2
  19. package/dist/components/index.mjs +14 -5
  20. package/dist/components/index.mjs.map +1 -1
  21. package/dist/headless.cjs +2 -1
  22. package/dist/headless.d.cts +2 -2
  23. package/dist/headless.d.mts +2 -2
  24. package/dist/headless.mjs +2 -1
  25. package/dist/index.cjs +22 -6
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +22 -8
  28. package/dist/index.d.mts +23 -9
  29. package/dist/index.mjs +24 -8
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/polyfills/encoding.cjs +5 -5
  32. package/dist/polyfills/encoding.cjs.map +1 -1
  33. package/dist/polyfills/encoding.mjs +5 -4
  34. package/dist/polyfills/encoding.mjs.map +1 -1
  35. package/dist/polyfills.cjs +2 -1
  36. package/dist/polyfills.cjs.map +1 -1
  37. package/dist/polyfills.mjs +2 -1
  38. package/dist/polyfills.mjs.map +1 -1
  39. package/dist/{streaming-fetch-Dm1oN4f2.mjs → streaming-fetch-CLHG3Z1H.mjs} +1 -1
  40. package/dist/{streaming-fetch-Dm1oN4f2.mjs.map → streaming-fetch-CLHG3Z1H.mjs.map} +1 -1
  41. package/dist/{streaming-fetch-Bm91EsRc.cjs → streaming-fetch-DbDALGya.cjs} +1 -1
  42. package/dist/{streaming-fetch-Bm91EsRc.cjs.map → streaming-fetch-DbDALGya.cjs.map} +1 -1
  43. package/dist/utf8-BIN9t4Oy.mjs +113 -0
  44. package/dist/utf8-BIN9t4Oy.mjs.map +1 -0
  45. package/dist/utf8-Cf3Ssy33.cjs +125 -0
  46. package/dist/utf8-Cf3Ssy33.cjs.map +1 -0
  47. package/package.json +11 -20
  48. package/scripts/verify-polyfill-barrel.mjs +4 -6
  49. package/src/CopilotChat.tsx +36 -9
  50. package/src/CopilotKitProvider.tsx +87 -130
  51. package/src/CopilotPopup.tsx +2 -2
  52. package/src/CopilotSidebar.tsx +4 -1
  53. package/src/__mocks__/test-copilotkit.tsx +9 -3
  54. package/src/__tests__/attachments-integration.test.tsx +15 -2
  55. package/src/__tests__/copilot-chat-agentid.test.tsx +15 -2
  56. package/src/__tests__/copilot-chat-attachments.test.tsx +15 -2
  57. package/src/__tests__/copilot-chat-configuration.test.tsx +82 -0
  58. package/src/__tests__/copilot-popup.test.tsx +15 -2
  59. package/src/__tests__/copilot-sidebar.test.tsx +15 -2
  60. package/src/__tests__/copilotkit-provider.test.tsx +68 -73
  61. package/src/__tests__/headless-integration.test.tsx +11 -1
  62. package/src/components/CopilotChat.tsx +24 -3
  63. package/src/components/Markdown.tsx +4 -4
  64. package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +5 -1
  65. package/src/components/__tests__/CopilotChat.test.tsx +5 -1
  66. package/src/components/__tests__/CopilotChatInterrupt.test.tsx +208 -0
  67. package/src/components/__tests__/Markdown.code-alias.test.tsx +1 -1
  68. package/src/components/messages/AssistantMessage.tsx +3 -2
  69. package/src/polyfills/__tests__/utf8.test.ts +112 -0
  70. package/src/polyfills/encoding.ts +5 -4
  71. package/src/polyfills/utf8.ts +151 -0
  72. package/src/types.d.ts +0 -13
  73. package/dist/CopilotKitProvider-BWjzCdHN.d.mts +0 -121
  74. package/dist/CopilotKitProvider-Btm10msB.d.cts +0 -121
  75. package/dist/CopilotKitProvider-Byw3cqe2.cjs.map +0 -1
  76. package/dist/CopilotKitProvider-CE4bc6CP.mjs.map +0 -1
  77. package/dist/Markdown-C6AsLHmd.mjs.map +0 -1
  78. package/dist/Markdown-C_9Re36O.cjs.map +0 -1
@@ -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-renderer/react-native", () => ({
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, type ViewStyle } from "react-native";
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 instead of content */
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 { TextEncoder, TextDecoder } from "text-encoding";
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 = TextEncoder;
17
+ g.TextEncoder = Utf8TextEncoder;
17
18
  }
18
19
  if (typeof g.TextDecoder === "undefined") {
19
- g.TextDecoder = 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,121 +0,0 @@
1
- import { r as MarkdownStyle } from "./Markdown-JsYh7oSA.mjs";
2
- import React, { ReactNode } from "react";
3
- import { DebugConfig } from "@copilotkit/shared";
4
- import { CopilotKitCoreErrorCode, CopilotKitMessageFilter } from "@copilotkit/core";
5
-
6
- //#region src/components/MarkdownRendererContext.d.ts
7
- interface NativeMarkdownRendererProps {
8
- content: string;
9
- isStreaming?: boolean;
10
- }
11
- type NativeMarkdownRenderer = React.ComponentType<NativeMarkdownRendererProps>;
12
- /** Config for the built-in RN renderer (pass instead of a component). */
13
- interface DefaultMarkdownRendererProps {
14
- style?: MarkdownStyle;
15
- animate?: boolean;
16
- }
17
- type MarkdownRendererValue = NativeMarkdownRenderer | DefaultMarkdownRendererProps;
18
- declare const MarkdownRendererProvider: React.FC<{
19
- renderer?: MarkdownRendererValue;
20
- children: React.ReactNode;
21
- }>;
22
- declare function useMarkdownRenderer(): MarkdownRendererValue | undefined;
23
- //#endregion
24
- //#region src/CopilotKitProvider.d.ts
25
- interface CopilotKitNativeProviderProps {
26
- children: ReactNode;
27
- /** URL of the CopilotKit runtime endpoint */
28
- runtimeUrl: string;
29
- /** Custom headers sent with every request */
30
- headers?: Record<string, string> | (() => Record<string, string>);
31
- /**
32
- * Credentials mode for fetch requests (e.g., "include" for HTTP-only cookies in cross-origin requests).
33
- */
34
- credentials?: RequestCredentials;
35
- /**
36
- * Rewrites the message list sent to runtime agents on every run.
37
- *
38
- * CopilotKit sends the whole thread each time. When your agent already
39
- * stores the conversation, most of that payload is waste, and an agent that
40
- * merges the inbound list with its own store can show the model every turn
41
- * twice. Return the messages to send:
42
- *
43
- * ```tsx
44
- * <CopilotKitProvider
45
- * runtimeUrl="/api/copilotkit"
46
- * messageFilter={(messages) => messages.slice(-1)}
47
- * />
48
- * ```
49
- *
50
- * The filter changes the request body only. The transcript the UI renders is
51
- * untouched. Broken tool-call pairs are repaired before the request is sent,
52
- * so a filter this blunt cannot strand a tool result mid-HITL.
53
- *
54
- * Agents reached through your CopilotRuntime honor this. An agent your app
55
- * passes in directly does not, and neither Intelligence runs nor suggestion
56
- * runs are ever filtered.
57
- *
58
- * Prefer a stable reference (`useCallback`). An inline arrow re-registers the
59
- * filter on every render, which is harmless but needless.
60
- */
61
- messageFilter?: CopilotKitMessageFilter;
62
- /** Whether the runtime uses a single-route endpoint */
63
- useSingleEndpoint?: boolean;
64
- /** Custom properties forwarded to agents */
65
- properties?: Record<string, unknown>;
66
- /**
67
- * Error handler called when CopilotKit encounters an error.
68
- * Fires for all error types (runtime connection failures, agent errors, tool errors).
69
- * If not provided, errors are logged to console.error.
70
- */
71
- onError?: (event: {
72
- error: Error;
73
- code: CopilotKitCoreErrorCode;
74
- context: Record<string, any>;
75
- }) => void | Promise<void>;
76
- /**
77
- * Enable debug logging for the client-side event pipeline.
78
- * When `true`, enables verbose logging from the core instance.
79
- */
80
- debug?: DebugConfig;
81
- /**
82
- * Default throttle interval (ms) for `onMessagesChanged` / `onStateChanged`
83
- * subscriptions. Individual subscriptions can override with their own `throttleMs`.
84
- */
85
- defaultThrottleMs?: number;
86
- /**
87
- * Custom markdown renderer for assistant messages. Either a component (escape
88
- * hatch — receives `content` and an optional `isStreaming` flag) used instead
89
- * of the built-in renderer, or a `{ style, animate }` config object to
90
- * configure the built-in React Native renderer (the `CopilotMarkdown` used by
91
- * the default `AssistantMessage`) without writing a wrapper.
92
- */
93
- markdownRenderer?: MarkdownRendererValue;
94
- }
95
- /**
96
- * CopilotKit provider for React Native.
97
- *
98
- * A lightweight alternative to the web CopilotKitProvider that avoids
99
- * web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
100
- *
101
- * Polyfills are auto-imported when `@copilotkit/react-native` is loaded,
102
- * so a separate `import "@copilotkit/react-native/polyfills"` is no longer
103
- * required (though it remains available for advanced use).
104
- *
105
- * Usage:
106
- * ```tsx
107
- * import { CopilotKitProvider } from "@copilotkit/react-native";
108
- *
109
- * function App() {
110
- * return (
111
- * <CopilotKitProvider runtimeUrl="https://your-runtime/api/copilotkit">
112
- * <ChatScreen />
113
- * </CopilotKitProvider>
114
- * );
115
- * }
116
- * ```
117
- */
118
- declare const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps>;
119
- //#endregion
120
- export { NativeMarkdownRendererProps as a, NativeMarkdownRenderer as i, CopilotKitProvider as n, useMarkdownRenderer as o, MarkdownRendererProvider as r, CopilotKitNativeProviderProps as t };
121
- //# sourceMappingURL=CopilotKitProvider-BWjzCdHN.d.mts.map