@copilotkit/react-native 1.57.3 → 1.58.0-canary.thread-id-propagation

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 (48) hide show
  1. package/USAGE.md +116 -0
  2. package/dist/RenderToolContext-CBNKcJqz.cjs +126 -0
  3. package/dist/RenderToolContext-CBNKcJqz.cjs.map +1 -0
  4. package/dist/RenderToolContext-CszHyes6.mjs +75 -0
  5. package/dist/RenderToolContext-CszHyes6.mjs.map +1 -0
  6. package/dist/components/index.cjs +722 -0
  7. package/dist/components/index.cjs.map +1 -0
  8. package/dist/components/index.d.cts +203 -0
  9. package/dist/components/index.d.mts +203 -0
  10. package/dist/components/index.mjs +714 -0
  11. package/dist/components/index.mjs.map +1 -0
  12. package/dist/index.cjs +53 -38
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +102 -6
  15. package/dist/index.d.mts +100 -4
  16. package/dist/index.mjs +49 -3
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/polyfills/encoding.cjs +1 -1
  19. package/dist/polyfills/streams.cjs +1 -1
  20. package/package.json +24 -4
  21. package/src/CopilotKitProvider.tsx +2 -1
  22. package/src/__mocks__/react-native-streamdown.ts +16 -0
  23. package/src/__mocks__/react-native.ts +52 -0
  24. package/src/__tests__/headless-integration.test.tsx +16 -0
  25. package/src/components/CopilotChat.tsx +465 -0
  26. package/src/components/CopilotModal.tsx +210 -0
  27. package/src/components/Markdown.tsx +124 -0
  28. package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +418 -0
  29. package/src/components/__tests__/CopilotChat.test.tsx +390 -0
  30. package/src/components/__tests__/CopilotModal.test.tsx +257 -0
  31. package/src/components/__tests__/Markdown.test.tsx +106 -0
  32. package/src/components/index.ts +18 -0
  33. package/src/components/messages/AssistantMessage.tsx +73 -0
  34. package/src/components/messages/TypingIndicator.tsx +103 -0
  35. package/src/components/messages/UserMessage.tsx +68 -0
  36. package/src/components/messages/__tests__/messages-edge-cases.test.tsx +179 -0
  37. package/src/components/messages/__tests__/messages.test.tsx +189 -0
  38. package/src/components/messages/__tests__/utils.test.ts +39 -0
  39. package/src/components/messages/index.ts +8 -0
  40. package/src/components/messages/utils.ts +11 -0
  41. package/src/hooks/RenderToolContext.tsx +150 -0
  42. package/src/hooks/__tests__/RenderToolContext.test.tsx +264 -0
  43. package/src/hooks/__tests__/useRenderTool.test.tsx +334 -0
  44. package/src/hooks/index.ts +9 -0
  45. package/src/hooks/useRenderTool.ts +96 -0
  46. package/src/index.ts +10 -3
  47. package/tsdown.config.ts +9 -0
  48. package/vitest.config.mjs +10 -0
@@ -0,0 +1,722 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_RenderToolContext = require('../RenderToolContext-CBNKcJqz.cjs');
3
+ let react = require("react");
4
+ react = require_RenderToolContext.__toESM(react);
5
+ let _copilotkit_react_core_v2_context = require("@copilotkit/react-core/v2/context");
6
+ let _copilotkit_react_core_v2_headless = require("@copilotkit/react-core/v2/headless");
7
+ let react_jsx_runtime = require("react/jsx-runtime");
8
+ let react_native = require("react-native");
9
+ let react_native_streamdown = require("react-native-streamdown");
10
+ let _gorhom_bottom_sheet = require("@gorhom/bottom-sheet");
11
+ _gorhom_bottom_sheet = require_RenderToolContext.__toESM(_gorhom_bottom_sheet);
12
+
13
+ //#region src/components/Markdown.tsx
14
+ /**
15
+ * Default markdown styles tuned for chat bubble display.
16
+ *
17
+ * Exported so consumers can spread and extend:
18
+ * ```ts
19
+ * import { defaultMarkdownStyles } from "@copilotkit/react-native";
20
+ * const custom = { ...defaultMarkdownStyles, h1: { fontSize: 28 } };
21
+ * ```
22
+ */
23
+ const defaultMarkdownStyles = {
24
+ paragraph: {
25
+ fontSize: 16,
26
+ lineHeight: 24,
27
+ color: "#1a1a1a",
28
+ marginTop: 4,
29
+ marginBottom: 4
30
+ },
31
+ h1: {
32
+ fontSize: 24,
33
+ fontWeight: "bold",
34
+ marginTop: 12,
35
+ marginBottom: 8,
36
+ color: "#111111"
37
+ },
38
+ h2: {
39
+ fontSize: 20,
40
+ fontWeight: "bold",
41
+ marginTop: 10,
42
+ marginBottom: 6,
43
+ color: "#111111"
44
+ },
45
+ h3: {
46
+ fontSize: 18,
47
+ fontWeight: "600",
48
+ marginTop: 8,
49
+ marginBottom: 4,
50
+ color: "#222222"
51
+ },
52
+ strong: { fontWeight: "bold" },
53
+ em: { fontStyle: "italic" },
54
+ link: {
55
+ color: "#0066cc",
56
+ underline: true
57
+ },
58
+ blockquote: {
59
+ backgroundColor: "#f5f5f5",
60
+ borderWidth: 4,
61
+ borderColor: "#cccccc",
62
+ gapWidth: 12
63
+ },
64
+ code: {
65
+ backgroundColor: "#f0f0f0",
66
+ fontFamily: "monospace",
67
+ fontSize: 14
68
+ },
69
+ codeBlock: {
70
+ backgroundColor: "#f0f0f0",
71
+ borderRadius: 8,
72
+ padding: 12,
73
+ fontFamily: "monospace",
74
+ fontSize: 14
75
+ },
76
+ list: {
77
+ marginTop: 4,
78
+ marginBottom: 4
79
+ }
80
+ };
81
+ /**
82
+ * Renders markdown content using `react-native-streamdown` with
83
+ * pre-configured styles suited for CopilotKit chat bubbles.
84
+ *
85
+ * `react-native-streamdown` processes incomplete streaming markdown in the
86
+ * background, rendering incrementally without visual glitches — ideal for
87
+ * displaying LLM output as it arrives.
88
+ *
89
+ * Custom styles are merged on top of the defaults so callers only need
90
+ * to override what they want to change.
91
+ */
92
+ function CopilotMarkdown({ content, style, streamingAnimation = true }) {
93
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native_streamdown.StreamdownText, {
94
+ markdown: content,
95
+ markdownStyle: (0, react.useMemo)(() => {
96
+ if (!style) return defaultMarkdownStyles;
97
+ return {
98
+ ...defaultMarkdownStyles,
99
+ ...style
100
+ };
101
+ }, [style]),
102
+ streamingAnimation
103
+ });
104
+ }
105
+
106
+ //#endregion
107
+ //#region src/components/messages/TypingIndicator.tsx
108
+ const DOT_SIZE = 6;
109
+ const DOT_SPACING = 4;
110
+ const ANIMATION_DURATION = 400;
111
+ /**
112
+ * Three animated dots that pulse in sequence, suitable for embedding
113
+ * inside an AssistantMessage to indicate the AI is still generating.
114
+ *
115
+ * Uses React Native's built-in `Animated` API (no Reanimated dependency).
116
+ */
117
+ function TypingIndicator({ style }) {
118
+ const dot1 = (0, react.useRef)(new react_native.Animated.Value(0)).current;
119
+ const dot2 = (0, react.useRef)(new react_native.Animated.Value(0)).current;
120
+ const dot3 = (0, react.useRef)(new react_native.Animated.Value(0)).current;
121
+ (0, react.useEffect)(() => {
122
+ const createPulse = (dot, delay) => react_native.Animated.sequence([react_native.Animated.delay(delay), react_native.Animated.loop(react_native.Animated.sequence([react_native.Animated.timing(dot, {
123
+ toValue: 1,
124
+ duration: ANIMATION_DURATION,
125
+ useNativeDriver: true
126
+ }), react_native.Animated.timing(dot, {
127
+ toValue: 0,
128
+ duration: ANIMATION_DURATION,
129
+ useNativeDriver: true
130
+ })]))]);
131
+ const animation = react_native.Animated.parallel([
132
+ createPulse(dot1, 0),
133
+ createPulse(dot2, ANIMATION_DURATION * .33),
134
+ createPulse(dot3, ANIMATION_DURATION * .66)
135
+ ]);
136
+ animation.start();
137
+ return () => {
138
+ animation.stop();
139
+ };
140
+ }, [
141
+ dot1,
142
+ dot2,
143
+ dot3
144
+ ]);
145
+ const dotStyle = (animatedValue) => ({
146
+ ...styles$4.dot,
147
+ opacity: animatedValue.interpolate({
148
+ inputRange: [0, 1],
149
+ outputRange: [.3, 1]
150
+ }),
151
+ transform: [{ scale: animatedValue.interpolate({
152
+ inputRange: [0, 1],
153
+ outputRange: [.8, 1.2]
154
+ }) }]
155
+ });
156
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_native.View, {
157
+ style: [styles$4.container, style],
158
+ accessibilityLabel: "Typing indicator",
159
+ accessibilityRole: "text",
160
+ children: [
161
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Animated.View, { style: dotStyle(dot1) }),
162
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Animated.View, { style: dotStyle(dot2) }),
163
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Animated.View, { style: dotStyle(dot3) })
164
+ ]
165
+ });
166
+ }
167
+ const styles$4 = react_native.StyleSheet.create({
168
+ container: {
169
+ flexDirection: "row",
170
+ alignItems: "center",
171
+ paddingVertical: 4,
172
+ paddingHorizontal: 2
173
+ },
174
+ dot: {
175
+ width: DOT_SIZE,
176
+ height: DOT_SIZE,
177
+ borderRadius: DOT_SIZE / 2,
178
+ backgroundColor: "#999999",
179
+ marginHorizontal: DOT_SPACING / 2
180
+ }
181
+ });
182
+
183
+ //#endregion
184
+ //#region src/components/messages/utils.ts
185
+ /**
186
+ * Format a Date as a 12-hour time string (e.g. "2:05 PM").
187
+ */
188
+ function formatTimestamp(date) {
189
+ const hours = date.getHours();
190
+ const minutes = date.getMinutes();
191
+ const ampm = hours >= 12 ? "PM" : "AM";
192
+ return `${hours % 12 || 12}:${minutes.toString().padStart(2, "0")} ${ampm}`;
193
+ }
194
+
195
+ //#endregion
196
+ //#region src/components/messages/AssistantMessage.tsx
197
+ const ASSISTANT_BUBBLE_BG = "#F0F0F0";
198
+ const TIMESTAMP_COLOR$1 = "#999999";
199
+ /**
200
+ * Left-aligned chat bubble for AI assistant responses.
201
+ *
202
+ * Renders markdown content via `CopilotMarkdown` and shows an animated
203
+ * typing indicator when `isLoading` is true.
204
+ */
205
+ function AssistantMessage({ content, isLoading = false, timestamp, style }) {
206
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_native.View, {
207
+ style: [styles$3.container, style],
208
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_native.View, {
209
+ style: styles$3.bubble,
210
+ children: [content ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotMarkdown, { content }) : null, isLoading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TypingIndicator, {}) : null]
211
+ }), timestamp && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Text, {
212
+ style: styles$3.timestamp,
213
+ children: formatTimestamp(timestamp)
214
+ })]
215
+ });
216
+ }
217
+ const styles$3 = react_native.StyleSheet.create({
218
+ container: {
219
+ alignItems: "flex-start",
220
+ marginVertical: 4,
221
+ paddingHorizontal: 12
222
+ },
223
+ bubble: {
224
+ backgroundColor: ASSISTANT_BUBBLE_BG,
225
+ borderTopLeftRadius: 16,
226
+ borderTopRightRadius: 16,
227
+ borderBottomRightRadius: 16,
228
+ borderBottomLeftRadius: 4,
229
+ paddingHorizontal: 12,
230
+ paddingVertical: 8,
231
+ maxWidth: "80%"
232
+ },
233
+ timestamp: {
234
+ color: TIMESTAMP_COLOR$1,
235
+ fontSize: 11,
236
+ marginTop: 2,
237
+ marginLeft: 4
238
+ }
239
+ });
240
+
241
+ //#endregion
242
+ //#region src/components/messages/UserMessage.tsx
243
+ const USER_BUBBLE_BG = "#0066CC";
244
+ const USER_TEXT_COLOR = "#FFFFFF";
245
+ const TIMESTAMP_COLOR = "#999999";
246
+ /**
247
+ * Right-aligned chat bubble for user messages.
248
+ *
249
+ * Renders plain text (no markdown) with a primary-color background
250
+ * and white text. Optionally displays a subtle timestamp below.
251
+ */
252
+ function UserMessage({ content, timestamp, style }) {
253
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_native.View, {
254
+ style: [styles$2.container, style],
255
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
256
+ style: styles$2.bubble,
257
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Text, {
258
+ style: styles$2.text,
259
+ children: content
260
+ })
261
+ }), timestamp && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Text, {
262
+ style: styles$2.timestamp,
263
+ children: formatTimestamp(timestamp)
264
+ })]
265
+ });
266
+ }
267
+ const styles$2 = react_native.StyleSheet.create({
268
+ container: {
269
+ alignItems: "flex-end",
270
+ marginVertical: 4,
271
+ paddingHorizontal: 12
272
+ },
273
+ bubble: {
274
+ backgroundColor: USER_BUBBLE_BG,
275
+ borderTopLeftRadius: 16,
276
+ borderTopRightRadius: 16,
277
+ borderBottomLeftRadius: 16,
278
+ borderBottomRightRadius: 4,
279
+ paddingHorizontal: 12,
280
+ paddingVertical: 8,
281
+ maxWidth: "80%"
282
+ },
283
+ text: {
284
+ color: USER_TEXT_COLOR,
285
+ fontSize: 16,
286
+ lineHeight: 22
287
+ },
288
+ timestamp: {
289
+ color: TIMESTAMP_COLOR,
290
+ fontSize: 11,
291
+ marginTop: 2,
292
+ marginRight: 4
293
+ }
294
+ });
295
+
296
+ //#endregion
297
+ //#region src/components/CopilotChat.tsx
298
+ /**
299
+ * Full-screen chat UI component for React Native.
300
+ *
301
+ * Connects to a CopilotKit agent via `useAgent` and renders messages
302
+ * using platform-appropriate AssistantMessage / UserMessage components.
303
+ *
304
+ * Usage:
305
+ * ```tsx
306
+ * <CopilotChat agentName="my-agent" headerTitle="Assistant" />
307
+ * ```
308
+ */
309
+ function CopilotChat({ agentName = "default", placeholder = "Type a message...", initialMessages = [], emptyStateTitle = "How can I help?", emptyStateSubtitle = "Ask me anything or try a suggestion below.", headerTitle = "Chat", showHeader = true, style, messageContainerStyle, inputContainerStyle, onSendMessage, FlatListComponent = react_native.FlatList, disableKeyboardAvoiding = false }) {
310
+ const [inputText, setInputText] = (0, react.useState)("");
311
+ const [error, setError] = (0, react.useState)(null);
312
+ const flatListRef = (0, react.useRef)(null);
313
+ const messageIdCounter = (0, react.useRef)(0);
314
+ const { copilotkit, executingToolCallIds } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
315
+ const { agent } = (0, _copilotkit_react_core_v2_headless.useAgent)({ agentId: agentName });
316
+ const messages = agent.messages ?? [];
317
+ const isRunning = agent.isRunning;
318
+ const toolRenderers = require_RenderToolContext.useRenderToolRegistry();
319
+ const extraData = (0, react.useMemo)(() => ({
320
+ isRunning,
321
+ executingToolCallIds,
322
+ toolRenderers
323
+ }), [
324
+ isRunning,
325
+ executingToolCallIds,
326
+ toolRenderers
327
+ ]);
328
+ const listItems = (0, react.useMemo)(() => {
329
+ const items = [];
330
+ for (const msg of messages) if (msg.role === "user") items.push({
331
+ id: msg.id,
332
+ type: "user",
333
+ content: typeof msg.content === "string" ? msg.content : ""
334
+ });
335
+ else if (msg.role === "assistant") {
336
+ const assistantMsg = msg;
337
+ if (assistantMsg.content) items.push({
338
+ id: msg.id,
339
+ type: "assistant",
340
+ content: assistantMsg.content
341
+ });
342
+ if (assistantMsg.toolCalls && assistantMsg.toolCalls.length > 0) for (const tc of assistantMsg.toolCalls) items.push({
343
+ id: `${msg.id}-tc-${tc.id}`,
344
+ type: "tool-call",
345
+ toolCalls: [tc]
346
+ });
347
+ }
348
+ if (isRunning) {
349
+ const lastItem = items[items.length - 1];
350
+ if (!lastItem || lastItem.type !== "assistant") items.push({
351
+ id: "__loading__",
352
+ type: "loading"
353
+ });
354
+ }
355
+ return items;
356
+ }, [messages, isRunning]);
357
+ const sendMessage = (0, react.useCallback)(async (text) => {
358
+ if (!text || isRunning || !agent) return;
359
+ setError(null);
360
+ onSendMessage?.(text);
361
+ const id = `user-${++messageIdCounter.current}`;
362
+ agent.addMessage({
363
+ id,
364
+ role: "user",
365
+ content: text
366
+ });
367
+ try {
368
+ await copilotkit.runAgent({ agent });
369
+ } catch (err) {
370
+ const message = err instanceof Error ? err.message : "An unexpected error occurred";
371
+ console.error("[CopilotChat] runAgent failed:", err);
372
+ setError(message);
373
+ }
374
+ }, [
375
+ isRunning,
376
+ agent,
377
+ copilotkit,
378
+ onSendMessage
379
+ ]);
380
+ const handleSend = (0, react.useCallback)(async () => {
381
+ const text = inputText.trim();
382
+ if (!text) return;
383
+ setInputText("");
384
+ await sendMessage(text);
385
+ }, [inputText, sendMessage]);
386
+ const handleSuggestion = (0, react.useCallback)((text) => {
387
+ sendMessage(text);
388
+ }, [sendMessage]);
389
+ const handleContentSizeChange = (0, react.useCallback)(() => {
390
+ flatListRef.current?.scrollToEnd({ animated: true });
391
+ }, []);
392
+ const renderItem = (0, react.useCallback)(({ item }) => {
393
+ if (item.type === "user") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UserMessage, { content: item.content ?? "" });
394
+ if (item.type === "assistant") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AssistantMessage, {
395
+ content: item.content ?? "",
396
+ isLoading: isRunning && item.id === listItems[listItems.length - 1]?.id
397
+ });
398
+ if (item.type === "tool-call" && item.toolCalls) {
399
+ const tc = item.toolCalls[0];
400
+ const renderer = toolRenderers.get(tc.function.name);
401
+ if (renderer) {
402
+ let args = {};
403
+ try {
404
+ args = JSON.parse(tc.function.arguments || "{}");
405
+ } catch (e) {
406
+ console.warn(`[CopilotChat] Failed to parse tool call arguments for ${tc.function.name}:`, e);
407
+ }
408
+ const status = executingToolCallIds.has(tc.id) ? "executing" : "complete";
409
+ return renderer({
410
+ args,
411
+ status
412
+ });
413
+ }
414
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
415
+ style: styles$1.toolCallIndicator,
416
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_native.Text, {
417
+ style: styles$1.toolCallText,
418
+ children: ["Called: ", tc.function.name]
419
+ })
420
+ });
421
+ }
422
+ if (item.type === "loading") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AssistantMessage, {
423
+ content: "",
424
+ isLoading: true
425
+ });
426
+ return null;
427
+ }, [
428
+ isRunning,
429
+ listItems,
430
+ toolRenderers,
431
+ executingToolCallIds
432
+ ]);
433
+ const keyExtractor = (0, react.useCallback)((item) => item.id, []);
434
+ const emptyComponent = (0, react.useMemo)(() => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_native.View, {
435
+ style: styles$1.emptyState,
436
+ children: [
437
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Text, {
438
+ style: styles$1.emptyTitle,
439
+ children: emptyStateTitle
440
+ }),
441
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Text, {
442
+ style: styles$1.emptySubtitle,
443
+ children: emptyStateSubtitle
444
+ }),
445
+ initialMessages.map((suggestion, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Pressable, {
446
+ style: styles$1.suggestionPill,
447
+ onPress: () => handleSuggestion(suggestion),
448
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Text, {
449
+ style: styles$1.suggestionText,
450
+ children: suggestion
451
+ })
452
+ }, `suggestion-${i}`))
453
+ ]
454
+ }), [
455
+ emptyStateTitle,
456
+ emptyStateSubtitle,
457
+ initialMessages,
458
+ handleSuggestion
459
+ ]);
460
+ const sendDisabled = !inputText.trim() || isRunning;
461
+ const content = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
462
+ showHeader && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
463
+ style: styles$1.header,
464
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Text, {
465
+ style: styles$1.headerTitle,
466
+ children: headerTitle
467
+ })
468
+ }),
469
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FlatListComponent, {
470
+ ref: flatListRef,
471
+ data: listItems,
472
+ renderItem,
473
+ keyExtractor,
474
+ extraData,
475
+ contentContainerStyle: [styles$1.messageList, messageContainerStyle],
476
+ onContentSizeChange: handleContentSizeChange,
477
+ ListEmptyComponent: emptyComponent
478
+ }),
479
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
480
+ style: styles$1.errorContainer,
481
+ testID: "error-message",
482
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Text, {
483
+ style: styles$1.errorText,
484
+ children: error
485
+ })
486
+ }),
487
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_native.View, {
488
+ style: [styles$1.inputContainer, inputContainerStyle],
489
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.TextInput, {
490
+ style: styles$1.input,
491
+ value: inputText,
492
+ onChangeText: setInputText,
493
+ placeholder,
494
+ placeholderTextColor: "#999",
495
+ multiline: true,
496
+ numberOfLines: 4,
497
+ returnKeyType: "send",
498
+ onSubmitEditing: handleSend
499
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.TouchableOpacity, {
500
+ style: [styles$1.sendButton, sendDisabled && styles$1.sendButtonDisabled],
501
+ onPress: handleSend,
502
+ disabled: sendDisabled,
503
+ testID: "send-button",
504
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.Text, {
505
+ style: styles$1.sendButtonIcon,
506
+ children: "↑"
507
+ })
508
+ })]
509
+ })
510
+ ] });
511
+ if (disableKeyboardAvoiding) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
512
+ style: [styles$1.container, style],
513
+ children: content
514
+ });
515
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.KeyboardAvoidingView, {
516
+ style: [styles$1.container, style],
517
+ behavior: react_native.Platform.OS === "ios" ? "padding" : "height",
518
+ keyboardVerticalOffset: 0,
519
+ children: content
520
+ });
521
+ }
522
+ const styles$1 = react_native.StyleSheet.create({
523
+ container: {
524
+ flex: 1,
525
+ backgroundColor: "#FFFFFF"
526
+ },
527
+ header: {
528
+ height: 56,
529
+ justifyContent: "center",
530
+ alignItems: "center",
531
+ borderBottomWidth: react_native.StyleSheet.hairlineWidth,
532
+ borderBottomColor: "#E0E0E0",
533
+ backgroundColor: "#FFFFFF"
534
+ },
535
+ headerTitle: {
536
+ fontSize: 17,
537
+ fontWeight: "600",
538
+ color: "#1A1A1A"
539
+ },
540
+ messageList: {
541
+ paddingHorizontal: 16,
542
+ flexGrow: 1
543
+ },
544
+ inputContainer: {
545
+ flexDirection: "row",
546
+ alignItems: "flex-end",
547
+ paddingHorizontal: 8,
548
+ paddingVertical: 8,
549
+ borderTopWidth: react_native.StyleSheet.hairlineWidth,
550
+ borderTopColor: "#E0E0E0",
551
+ backgroundColor: "#FFFFFF"
552
+ },
553
+ input: {
554
+ flex: 1,
555
+ backgroundColor: "#F5F5F5",
556
+ borderRadius: 20,
557
+ paddingHorizontal: 12,
558
+ paddingVertical: 8,
559
+ fontSize: 15,
560
+ maxHeight: 100,
561
+ color: "#1A1A1A"
562
+ },
563
+ sendButton: {
564
+ width: 36,
565
+ height: 36,
566
+ borderRadius: 18,
567
+ backgroundColor: "#0066CC",
568
+ justifyContent: "center",
569
+ alignItems: "center",
570
+ marginLeft: 8
571
+ },
572
+ sendButtonDisabled: { opacity: .4 },
573
+ sendButtonIcon: {
574
+ color: "#FFFFFF",
575
+ fontSize: 18,
576
+ fontWeight: "700"
577
+ },
578
+ emptyState: {
579
+ flex: 1,
580
+ justifyContent: "center",
581
+ alignItems: "center",
582
+ paddingTop: 100,
583
+ gap: 12
584
+ },
585
+ emptyTitle: {
586
+ fontSize: 22,
587
+ fontWeight: "700",
588
+ color: "#1A1A1A",
589
+ marginBottom: 4
590
+ },
591
+ emptySubtitle: {
592
+ fontSize: 15,
593
+ color: "#666666",
594
+ marginBottom: 16
595
+ },
596
+ suggestionPill: {
597
+ backgroundColor: "#E8F0FE",
598
+ borderRadius: 20,
599
+ paddingHorizontal: 16,
600
+ paddingVertical: 10
601
+ },
602
+ suggestionText: {
603
+ color: "#0066CC",
604
+ fontWeight: "600",
605
+ fontSize: 14
606
+ },
607
+ toolCallIndicator: {
608
+ alignSelf: "flex-start",
609
+ backgroundColor: "#F0F0F0",
610
+ borderRadius: 12,
611
+ paddingHorizontal: 12,
612
+ paddingVertical: 6,
613
+ marginBottom: 8
614
+ },
615
+ toolCallText: {
616
+ fontSize: 12,
617
+ color: "#999999",
618
+ fontStyle: "italic"
619
+ },
620
+ errorContainer: {
621
+ backgroundColor: "#FEE2E2",
622
+ paddingHorizontal: 12,
623
+ paddingVertical: 8,
624
+ marginHorizontal: 8,
625
+ borderRadius: 8
626
+ },
627
+ errorText: {
628
+ color: "#DC2626",
629
+ fontSize: 13
630
+ }
631
+ });
632
+
633
+ //#endregion
634
+ //#region src/components/CopilotModal.tsx
635
+ /**
636
+ * CopilotModal — a bottom-sheet chat overlay for React Native.
637
+ *
638
+ * Mobile equivalent of CopilotPopup on web. Wraps CopilotChat inside
639
+ * @gorhom/bottom-sheet so the chat can slide up over any screen.
640
+ */
641
+ const CopilotModal = (0, react.forwardRef)(function CopilotModal({ visible, onDismiss, snapPoints: snapPointsProp, initialSnapIndex = 0, enableDismissOnClose = true, backdropOpacity = .5, agentName, placeholder, initialMessages, headerTitle }, ref) {
642
+ const bottomSheetRef = (0, react.useRef)(null);
643
+ const snapPoints = (0, react.useMemo)(() => snapPointsProp ?? ["50%", "90%"], [snapPointsProp]);
644
+ (0, react.useImperativeHandle)(ref, () => ({
645
+ open() {
646
+ bottomSheetRef.current?.snapToIndex(initialSnapIndex);
647
+ },
648
+ close() {
649
+ bottomSheetRef.current?.close();
650
+ }
651
+ }), [initialSnapIndex]);
652
+ (0, react.useEffect)(() => {
653
+ if (visible === void 0) return;
654
+ if (visible) bottomSheetRef.current?.snapToIndex(initialSnapIndex);
655
+ else bottomSheetRef.current?.close();
656
+ }, [visible, initialSnapIndex]);
657
+ const renderBackdrop = (0, react.useCallback)((props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gorhom_bottom_sheet.BottomSheetBackdrop, {
658
+ ...props,
659
+ disappearsOnIndex: -1,
660
+ appearsOnIndex: 0,
661
+ opacity: backdropOpacity,
662
+ pressBehavior: "close"
663
+ }), [backdropOpacity]);
664
+ const handleClose = (0, react.useCallback)(() => {
665
+ if (enableDismissOnClose) onDismiss?.();
666
+ }, [enableDismissOnClose, onDismiss]);
667
+ const chatProps = (0, react.useMemo)(() => {
668
+ const props = {};
669
+ if (agentName !== void 0) props.agentName = agentName;
670
+ if (placeholder !== void 0) props.placeholder = placeholder;
671
+ if (initialMessages !== void 0) props.initialMessages = initialMessages;
672
+ if (headerTitle !== void 0) props.headerTitle = headerTitle;
673
+ return props;
674
+ }, [
675
+ agentName,
676
+ placeholder,
677
+ initialMessages,
678
+ headerTitle
679
+ ]);
680
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gorhom_bottom_sheet.default, {
681
+ ref: bottomSheetRef,
682
+ index: -1,
683
+ snapPoints,
684
+ enablePanDownToClose: true,
685
+ backdropComponent: renderBackdrop,
686
+ onClose: handleClose,
687
+ keyboardBehavior: "interactive",
688
+ keyboardBlurBehavior: "restore",
689
+ backgroundStyle: styles.sheetBackground,
690
+ handleIndicatorStyle: styles.handleIndicator,
691
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gorhom_bottom_sheet.BottomSheetView, {
692
+ style: styles.contentContainer,
693
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChat, {
694
+ ...chatProps,
695
+ FlatListComponent: _gorhom_bottom_sheet.BottomSheetFlatList,
696
+ disableKeyboardAvoiding: true
697
+ })
698
+ })
699
+ });
700
+ });
701
+ const styles = react_native.StyleSheet.create({
702
+ sheetBackground: {
703
+ backgroundColor: "#FFFFFF",
704
+ borderTopLeftRadius: 16,
705
+ borderTopRightRadius: 16
706
+ },
707
+ handleIndicator: {
708
+ width: 40,
709
+ height: 4,
710
+ backgroundColor: "#DDDDDD"
711
+ },
712
+ contentContainer: { flex: 1 }
713
+ });
714
+
715
+ //#endregion
716
+ exports.AssistantMessage = AssistantMessage;
717
+ exports.CopilotChat = CopilotChat;
718
+ exports.CopilotMarkdown = CopilotMarkdown;
719
+ exports.CopilotModal = CopilotModal;
720
+ exports.UserMessage = UserMessage;
721
+ exports.defaultMarkdownStyles = defaultMarkdownStyles;
722
+ //# sourceMappingURL=index.cjs.map