@copilotkit/react-native 2.0.0-rc.3 → 2.0.0-rc.30

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 (84) 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 +73 -172
  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 +75 -174
  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 +126 -158
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +35 -17
  28. package/dist/index.d.mts +36 -18
  29. package/dist/index.mjs +130 -161
  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 +12 -21
  48. package/scripts/verify-polyfill-barrel.mjs +4 -6
  49. package/src/CopilotChat.tsx +114 -93
  50. package/src/CopilotKitProvider.tsx +87 -130
  51. package/src/CopilotPopup.tsx +2 -2
  52. package/src/CopilotSidebar.tsx +7 -5
  53. package/src/__mocks__/react-native.ts +31 -0
  54. package/src/__mocks__/test-copilotkit.tsx +9 -3
  55. package/src/__tests__/attachments-integration.test.tsx +15 -2
  56. package/src/__tests__/copilot-chat-agentid.test.tsx +15 -2
  57. package/src/__tests__/copilot-chat-attachments.test.tsx +15 -2
  58. package/src/__tests__/copilot-chat-configuration.test.tsx +82 -0
  59. package/src/__tests__/copilot-chat-threads.test.tsx +232 -0
  60. package/src/__tests__/copilot-popup.test.tsx +15 -2
  61. package/src/__tests__/copilot-sidebar.test.tsx +15 -2
  62. package/src/__tests__/copilotkit-provider.test.tsx +68 -73
  63. package/src/__tests__/headless-integration.test.tsx +11 -1
  64. package/src/__tests__/use-attachments.test.ts +27 -2
  65. package/src/components/CopilotChat.tsx +106 -233
  66. package/src/components/CopilotModal.tsx +1 -1
  67. package/src/components/Markdown.tsx +4 -4
  68. package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +5 -1
  69. package/src/components/__tests__/CopilotChat.test.tsx +12 -4
  70. package/src/components/__tests__/CopilotChatInterrupt.test.tsx +208 -0
  71. package/src/components/__tests__/Markdown.code-alias.test.tsx +1 -1
  72. package/src/components/messages/AssistantMessage.tsx +3 -3
  73. package/src/components/messages/TypingIndicator.tsx +4 -4
  74. package/src/hooks/use-attachments.ts +95 -139
  75. package/src/polyfills/__tests__/utf8.test.ts +112 -0
  76. package/src/polyfills/encoding.ts +5 -4
  77. package/src/polyfills/utf8.ts +151 -0
  78. package/src/types.d.ts +0 -13
  79. package/dist/CopilotKitProvider-BWjzCdHN.d.mts +0 -121
  80. package/dist/CopilotKitProvider-Btm10msB.d.cts +0 -121
  81. package/dist/CopilotKitProvider-Byw3cqe2.cjs.map +0 -1
  82. package/dist/CopilotKitProvider-CE4bc6CP.mjs.map +0 -1
  83. package/dist/Markdown-C6AsLHmd.mjs.map +0 -1
  84. package/dist/Markdown-C_9Re36O.cjs.map +0 -1
@@ -1,4 +1,11 @@
1
- import React, { useCallback, useMemo, useRef, useState } from "react";
1
+ import React, {
2
+ useCallback,
3
+ useEffect,
4
+ useLayoutEffect,
5
+ useMemo,
6
+ useRef,
7
+ useState,
8
+ } from "react";
2
9
  import {
3
10
  FlatList,
4
11
  KeyboardAvoidingView,
@@ -13,11 +20,15 @@ import {
13
20
  import type { ListRenderItemInfo, ViewStyle } from "react-native";
14
21
  import { useAgent, useRenderToolCall } from "@copilotkit/react-core/headless";
15
22
  import { useCopilotKit } from "@copilotkit/react-core/context";
23
+ import {
24
+ ɵcreateChatSubmitter,
25
+ ɵgetToolResults,
26
+ ɵmessagesFingerprint,
27
+ } from "@copilotkit/core";
28
+ import type { CopilotKitCore } from "@copilotkit/core";
16
29
  import { AssistantMessage } from "./messages/AssistantMessage";
17
30
  import { UserMessage } from "./messages/UserMessage";
18
- import type { Message } from "@copilotkit/shared";
19
31
  import type { ToolMessage } from "@ag-ui/client";
20
- import { contentToText } from "@ag-ui/client";
21
32
 
22
33
  /** Shape of an assistant message with optional tool calls. */
23
34
  interface AssistantMessageShape {
@@ -72,179 +83,37 @@ interface ChatListItem {
72
83
  }
73
84
 
74
85
  /**
75
- * Lightweight content fingerprint for an agent's message list.
76
- *
77
- * The identity of `agent.messages` is NOT a reliable change signal, and it fails
78
- * in BOTH directions:
79
- *
80
- * - It changes on paths that have nothing to do with what is read below.
81
- * `@ag-ui/client`'s apply pipeline REASSIGNS the array
82
- * (`AbstractAgent.processApplyEvents` does `this.messages = applied.messages`),
83
- * so a streaming run hands down a fresh array — and fresh message, `toolCall`
84
- * and `function` objects — on every applied delta.
85
- * - It does NOT change on the paths these memos exist to serve. Core inserts
86
- * tool results by mutating in place —
87
- * `agent.messages.splice(insertAt, 0, toolMessage)`
88
- * (packages/core/src/core/run-handler.ts:931, :1080) —
89
- * `AbstractAgent.addMessage` is a `this.messages.push(...)`, and `useAgent`
90
- * re-renders with a bare `forceUpdate()` rather than a new array.
91
- *
92
- * (Grepping `packages/core/src` for a `.messages` assignment finds test files
93
- * only, but that proves nothing about identity: the reassignment lives in
94
- * `@ag-ui/client`, outside that tree.)
95
- *
96
- * So anything derived from messages must depend on their CONTENT, not on the
97
- * array reference.
98
- *
99
- * Captures exactly what the derivations below read — id, role, content size,
100
- * `toolCallId` (so an inserted tool result is visible), and each tool call's id
101
- * plus argument length (so streaming args advance).
102
- *
103
- * String and array content contribute their LENGTH rather than their value, so
104
- * large text and base64 attachment payloads are never re-serialized on every
105
- * render. Object content is the deliberate exception and IS serialized: a
106
- * length-based key is a constant 0 for every object, so an in-place content
107
- * replacement that keeps the same message id would otherwise be invisible to
108
- * every memo below.
109
- *
110
- * That object branch is convergence, not a fix for a reachable stale render: the
111
- * producer of same-id object content is an ACTIVITY_SNAPSHOT replace, and
112
- * `role: "activity"` never reaches `listItems`, which builds rows for `user` and
113
- * `assistant` only. It follows the SHAPE of react-core's `messagesMemoKey`
114
- * (react-core #6325). The two are independent implementations of the same idea —
115
- * a change to that key does not propagate here on its own, so treat this as a
116
- * documented parallel rather than a mirror.
117
- */
118
- function messagesFingerprint(messages: readonly unknown[]): string {
119
- return messages
120
- .map((msg) => {
121
- const m = msg as {
122
- id?: string;
123
- role?: string;
124
- content?: unknown;
125
- toolCallId?: string;
126
- toolCalls?: Array<{ id: string; function?: { arguments?: string } }>;
127
- };
128
- const content = m.content;
129
- const contentKey =
130
- typeof content === "string" || Array.isArray(content)
131
- ? content.length
132
- : content && typeof content === "object"
133
- ? objectContentKey(content)
134
- : 0;
135
- const toolCallsKey = Array.isArray(m.toolCalls)
136
- ? m.toolCalls
137
- .map((tc) => `${tc.id}:${tc.function?.arguments?.length ?? 0}`)
138
- .join(";")
139
- : "";
140
- return `${m.id}:${m.role}:${contentKey}:${m.toolCallId ?? ""}:${toolCallsKey}`;
141
- })
142
- .join(",");
143
- }
144
-
145
- /**
146
- * Serializes object content for the fingerprint above.
147
- *
148
- * Guarded because `JSON.stringify` THROWS on a circular structure and
149
- * `messagesFingerprint` runs on EVERY render, so a bare call would take the whole
150
- * chat down on content this component is explicitly required to tolerate —
151
- * `toolResultContent` below documents why non-string content reaches RN at all,
152
- * and "does not throw on tool content that cannot be JSON-serialised" pins that a
153
- * circular tool result must still render.
154
- *
155
- * The fallback is a constant, which means a circular object is invisible to the
156
- * memo exactly as every object used to be. That is the correct trade: it confines
157
- * the old always-equal behaviour to the pathological case instead of letting it
158
- * decide the common one. NOTE: this guard is a deliberate divergence from
159
- * react-core's `messagesMemoKey`, which stringifies unguarded.
160
- */
161
- function objectContentKey(content: object): string {
162
- try {
163
- return JSON.stringify(content) ?? "";
164
- } catch {
165
- return "[unserializable]";
166
- }
167
- }
168
-
169
- /**
170
- * Coerces a tool message's `content` to the `string` the renderer contract
171
- * requires (`ReactToolCallRenderer`'s Complete branch declares `result: string`)
172
- * WITHOUT inventing an empty result.
173
- *
174
- * AG-UI 1.0 models tool content as `string | ContentPart[]`: a plain string, or
175
- * an ordered list of typed parts (text, image, audio, video, document). A
176
- * string passes through; a list of parts is rendered as its text parts
177
- * concatenated — the flattening the spec permits for a string-only consumer —
178
- * and the media parts stay on the message for anything that can show them.
179
- * Neither is malformed, so neither warns.
180
- *
181
- * Anything else is only reachable from a producer that skipped validation —
182
- * restored thread history, a non-SSE transport, or app code casting on
183
- * `addMessage`. Core hedges against that case too (it accepts `unknown` content
184
- * and handles arrays of text parts), so this must not answer it with `""`: an
185
- * empty string is a LEGITIMATE tool result, which makes a dropped result
186
- * indistinguishable from an empty one. Serialise faithfully — the same
187
- * representation core uses for non-string results — and warn in dev.
86
+ * The core as the chat's submitter takes it, with a failed run also passed to
87
+ * `onRunError` so the chat can show it. The submitter logs the failure itself.
188
88
  */
189
- const MEDIA_PART_TYPES = new Set(["image", "audio", "video", "document"]);
190
-
191
- /**
192
- * Whether a value is one of the protocol's content parts: a text part with a
193
- * string `text`, or a media part with a `source` that names its kind and
194
- * value. Anything else — an array of typed records from restored history,
195
- * say — is not parts and keeps the serialise-and-warn path.
196
- */
197
- function isContentPart(part: unknown): boolean {
198
- if (typeof part !== "object" || part === null) return false;
199
- const record = part as { type?: unknown; text?: unknown; source?: unknown };
200
- if (record.type === "text") return typeof record.text === "string";
201
- if (typeof record.type !== "string" || !MEDIA_PART_TYPES.has(record.type))
202
- return false;
203
- const source = record.source as
204
- | { type?: unknown; value?: unknown; mimeType?: unknown }
205
- | undefined;
206
- if (typeof source !== "object" || source === null) return false;
207
- if (typeof source.value !== "string") return false;
208
- // Inline bytes need their type; a URL or a provider file handle (AG-UI 1.0
209
- // `file` source) may leave it out.
210
- if (source.type === "data") return typeof source.mimeType === "string";
211
- return (
212
- (source.type === "url" || source.type === "file") &&
213
- (source.mimeType === undefined || typeof source.mimeType === "string")
214
- );
215
- }
216
-
217
- function toolResultContent(content: unknown, toolCallId: string): string {
218
- if (typeof content === "string") return content;
219
-
220
- if (Array.isArray(content) && content.every(isContentPart)) {
221
- return contentToText(content as ToolMessage["content"]);
222
- }
223
-
224
- // null/undefined carry no payload, so "" loses nothing — but the message is
225
- // still malformed, so it warns below rather than passing silently.
226
- let serialized = "";
227
- if (content !== null && content !== undefined) {
228
- try {
229
- serialized =
230
- JSON.stringify(content) ?? Object.prototype.toString.call(content);
231
- } catch {
232
- // Circular or otherwise non-serialisable: keep SOMETHING over dropping
233
- // the result, and never throw from a render path.
234
- serialized = Object.prototype.toString.call(content);
235
- }
236
- }
237
-
238
- if (typeof __DEV__ === "undefined" || __DEV__) {
239
- console.warn(
240
- `[CopilotChat] Tool message for tool call "${toolCallId}" had non-string ` +
241
- `content (${content === null ? "null" : typeof content}), but renderers ` +
242
- `receive \`result: string\`. Rendering a serialized form instead of ` +
243
- `dropping it: ${serialized === "" ? "<empty>" : serialized}`,
244
- );
245
- }
246
-
247
- return serialized;
89
+ function withRunErrorReporting(
90
+ core: CopilotKitCore,
91
+ onRunError: (message: string) => void,
92
+ ): Parameters<typeof ɵcreateChatSubmitter>[0]["core"] {
93
+ return {
94
+ runAgent: async (params) => {
95
+ try {
96
+ return await core.runAgent(params);
97
+ } catch (err) {
98
+ onRunError(
99
+ err instanceof Error ? err.message : "An unexpected error occurred",
100
+ );
101
+ throw err;
102
+ }
103
+ },
104
+ stopAgent: (params) => core.stopAgent(params),
105
+ // This chat does not transcribe, but the submitter's core type covers it.
106
+ get runtimeUrl() {
107
+ return core.runtimeUrl;
108
+ },
109
+ get runtimeTransport() {
110
+ return core.runtimeTransport;
111
+ },
112
+ get credentials() {
113
+ return core.credentials;
114
+ },
115
+ resolveHeaders: () => core.resolveHeaders(),
116
+ };
248
117
  }
249
118
 
250
119
  /**
@@ -276,7 +145,6 @@ export function CopilotChat({
276
145
  const [inputText, setInputText] = useState("");
277
146
  const [error, setError] = useState<string | null>(null);
278
147
  const flatListRef = useRef<FlatList>(null);
279
- const messageIdCounter = useRef(0);
280
148
 
281
149
  const { copilotkit } = useCopilotKit();
282
150
  const { agent } = useAgent({ agentId: agentName });
@@ -286,34 +154,39 @@ export function CopilotChat({
286
154
 
287
155
  const renderToolCall = useRenderToolCall();
288
156
 
289
- // Recomputed every render — cheap, and the only honest dependency for the
290
- // message-derived memos below. See `messagesFingerprint` for why the array
291
- // reference cannot be trusted as one.
292
- const messagesKey = messagesFingerprint(messages);
293
-
294
- // toolCallId -> tool result message. react-core's renderer reports
295
- // status "complete" with `result` when a tool message exists; RN's chat
296
- // previously never correlated these, so `result` was always undefined.
157
+ // useInterrupt publishes its element to core unless renderInChat is false.
158
+ // Draw it after the last message, as the web message view does.
159
+ const [interruptElement, setInterruptElement] =
160
+ useState<React.ReactElement | null>(null);
161
+ useEffect(() => {
162
+ setInterruptElement(copilotkit.interruptElement);
163
+ const subscription = copilotkit.subscribe({
164
+ onInterruptElementChanged: ({ interruptElement: element }) => {
165
+ setInterruptElement(element);
166
+ },
167
+ });
168
+ return () => subscription.unsubscribe();
169
+ }, [copilotkit]);
170
+
171
+ // Recomputed every render: cheap, and the only honest dependency for the
172
+ // message-derived memos below. The array reference does not track content
173
+ // in either direction: core inserts tool results with an in-place `splice`,
174
+ // `addMessage` pushes, and the AG-UI apply pipeline replaces the array on
175
+ // every streamed delta.
176
+ const messagesKey = ɵmessagesFingerprint(messages);
177
+
178
+ // toolCallId -> tool result message, so a renderer reports "complete" with
179
+ // its `result`.
297
180
  const toolMessages = useMemo(() => {
298
181
  const byId = new Map<string, ToolMessage>();
299
- for (const msg of messages) {
300
- const m = msg as {
301
- role?: string;
302
- id?: string;
303
- toolCallId?: string;
304
- content?: unknown;
305
- };
306
- if (m.role === "tool" && m.toolCallId) {
307
- byId.set(m.toolCallId, {
308
- id: m.id ?? m.toolCallId,
309
- role: "tool",
310
- toolCallId: m.toolCallId,
311
- content: toolResultContent(m.content, m.toolCallId),
312
- });
313
- }
182
+ for (const [toolCallId, message] of ɵgetToolResults(messages)) {
183
+ // A copy, so the tool-call renderer's memo sees content that was
184
+ // replaced in place on the same message. Core turns the content into
185
+ // the renderer's `result` string.
186
+ byId.set(toolCallId, { ...message });
314
187
  }
315
188
  return byId;
316
- // eslint-disable-next-line react-hooks/exhaustive-deps
189
+ // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on message content, see messagesKey
317
190
  }, [messagesKey]);
318
191
 
319
192
  // Build flat list items from messages
@@ -365,7 +238,7 @@ export function CopilotChat({
365
238
  // in-place `splice` and `addMessage`'s push leave it untouched, while the
366
239
  // AG-UI apply pipeline replaces it on every delta. Without this, an
367
240
  // assistant message or tool call appended mid-run never reaches the list.
368
- // eslint-disable-next-line react-hooks/exhaustive-deps
241
+ // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on message content, see messagesKey
369
242
  }, [messagesKey, isRunning]);
370
243
 
371
244
  // Id of the trailing row. renderItem needs "is this the last row?" to place
@@ -388,47 +261,46 @@ export function CopilotChat({
388
261
  [isRunning, lastItemId, renderToolCall, toolMessages],
389
262
  );
390
263
 
391
- // Shared logic for sending a message to the agent
392
- const sendMessage = useCallback(
393
- async (text: string) => {
394
- if (!text || isRunning || !agent) return;
395
-
396
- setError(null);
397
- onSendMessage?.(text);
398
-
399
- const id = `user-${++messageIdCounter.current}`;
400
- agent.addMessage({
401
- id,
402
- role: "user",
403
- content: text,
404
- } as Message);
405
-
406
- try {
407
- await copilotkit.runAgent({ agent });
408
- } catch (err) {
409
- const message =
410
- err instanceof Error ? err.message : "An unexpected error occurred";
411
- console.error("[CopilotChat] runAgent failed:", err);
412
- setError(message);
413
- }
414
- },
415
- [isRunning, agent, copilotkit, onSendMessage],
264
+ // The send side lives in core: it builds the message, waits for the run in
265
+ // flight, and runs the agent. A failed run also shows under the list.
266
+ const agentRef = useRef(agent);
267
+ const inputTextRef = useRef(inputText);
268
+ useLayoutEffect(() => {
269
+ agentRef.current = agent;
270
+ inputTextRef.current = inputText;
271
+ });
272
+ const [submitter] = useState(() =>
273
+ ɵcreateChatSubmitter({
274
+ core: withRunErrorReporting(copilotkit, setError),
275
+ getAgent: () => agentRef.current,
276
+ input: {
277
+ get: () => inputTextRef.current,
278
+ set: (value) => {
279
+ inputTextRef.current = value;
280
+ setInputText(value);
281
+ },
282
+ },
283
+ }),
416
284
  );
285
+ useEffect(() => () => submitter.showNotice(null), [submitter]);
417
286
 
418
287
  // Send from the input field
419
- const handleSend = useCallback(async () => {
288
+ const handleSend = useCallback(() => {
420
289
  const text = inputText.trim();
421
290
  if (!text) return;
422
- setInputText("");
423
- await sendMessage(text);
424
- }, [inputText, sendMessage]);
291
+ setError(null);
292
+ onSendMessage?.(text);
293
+ void submitter.submit(text);
294
+ }, [inputText, onSendMessage, submitter]);
425
295
 
426
- // Handle suggestion pill press
296
+ // Handle suggestion pill press. Leaves the typed text alone.
427
297
  const handleSuggestion = useCallback(
428
298
  (text: string) => {
429
- void sendMessage(text);
299
+ setError(null);
300
+ onSendMessage?.(text);
301
+ void submitter.selectSuggestion({ message: text, isLoading: false });
430
302
  },
431
- [sendMessage],
303
+ [onSendMessage, submitter],
432
304
  );
433
305
 
434
306
  // Auto-scroll when content changes
@@ -522,6 +394,7 @@ export function CopilotChat({
522
394
  contentContainerStyle={[styles.messageList, messageContainerStyle]}
523
395
  onContentSizeChange={handleContentSizeChange}
524
396
  ListEmptyComponent={emptyComponent}
397
+ ListFooterComponent={interruptElement}
525
398
  />
526
399
 
527
400
  {error && (
@@ -12,7 +12,7 @@ import React, {
12
12
  useMemo,
13
13
  useRef,
14
14
  } from "react";
15
- import { StyleSheet, View } from "react-native";
15
+ import { StyleSheet } from "react-native";
16
16
  import BottomSheet, {
17
17
  BottomSheetBackdrop,
18
18
  BottomSheetFlatList,
@@ -2,9 +2,9 @@ import React from "react";
2
2
  import {
3
3
  StreamingMarkdownRenderer,
4
4
  defaultMarkdownStyles as _streamingDefaultStyles,
5
- } from "@copilotkit/markdown-renderer/react-native";
6
- import type { MarkdownStyle as StreamingMarkdownStyle } from "@copilotkit/markdown-renderer/react-native";
7
- import { warnUnsupportedRichSyntaxOnce } from "@copilotkit/markdown-renderer";
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-renderer/react-native`.
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: { runAgent: hoisted.mockRunAgent },
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: { runAgent: hoisted.mockRunAgent },
31
+ copilotkit: {
32
+ runAgent: hoisted.mockRunAgent,
33
+ interruptElement: null,
34
+ subscribe: () => ({ unsubscribe: () => {} }),
35
+ },
32
36
  executingToolCallIds: new Set<string>(),
33
37
  })),
34
38
  }));
@@ -320,7 +324,7 @@ describe("CopilotChat", () => {
320
324
  expect(getByText("Network timeout")).toBeTruthy();
321
325
  });
322
326
 
323
- it("uses incrementing message IDs instead of Date.now()", async () => {
327
+ it("gives every sent message its own id", async () => {
324
328
  const { getByTestId } = render(<CopilotChat />);
325
329
  const input = getByTestId("text-input");
326
330
  const sendBtn = getByTestId("send-button");
@@ -340,7 +344,11 @@ describe("CopilotChat", () => {
340
344
  });
341
345
 
342
346
  const calls = hoisted.mockAgent.addMessage.mock.calls;
343
- expect(calls[0][0].id).toBe("user-1");
344
- expect(calls[1][0].id).toBe("user-2");
347
+ expect(calls.map(([message]) => message.content)).toEqual([
348
+ "first",
349
+ "second",
350
+ ]);
351
+ expect(calls[0][0].id).toEqual(expect.any(String));
352
+ expect(calls[0][0].id).not.toBe(calls[1][0].id);
345
353
  });
346
354
  });