@copilotkit/react-native 2.0.0-rc.54 → 2.0.0-rc.55

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.
@@ -451,7 +451,7 @@ function CopilotChat({ agentName = "default", placeholder = "Type a message...",
451
451
  placeholder,
452
452
  placeholderTextColor: "#999",
453
453
  multiline: true,
454
- numberOfLines: 4,
454
+ numberOfLines: react_native.Platform.OS === "web" ? 1 : void 0,
455
455
  returnKeyType: "send",
456
456
  submitBehavior: "submit",
457
457
  blurOnSubmit: true,
@@ -603,7 +603,7 @@ const styles$1 = react_native.StyleSheet.create({
603
603
  */
604
604
  const CopilotModal = (0, react.forwardRef)(function CopilotModal({ visible, onDismiss, snapPoints: snapPointsProp, initialSnapIndex = 0, enableDismissOnClose = true, backdropOpacity = .5, agentName, placeholder, initialMessages, headerTitle }, ref) {
605
605
  const bottomSheetRef = (0, react.useRef)(null);
606
- const snapPoints = (0, react.useMemo)(() => snapPointsProp ?? ["50%", "90%"], [snapPointsProp]);
606
+ const snapPoints = (0, react.useMemo)(() => snapPointsProp ?? ["90%"], [snapPointsProp]);
607
607
  (0, react.useImperativeHandle)(ref, () => ({
608
608
  open() {
609
609
  bottomSheetRef.current?.snapToIndex(initialSnapIndex);
@@ -644,6 +644,7 @@ const CopilotModal = (0, react.forwardRef)(function CopilotModal({ visible, onDi
644
644
  ref: bottomSheetRef,
645
645
  index: -1,
646
646
  snapPoints,
647
+ enableDynamicSizing: false,
647
648
  enablePanDownToClose: true,
648
649
  backdropComponent: renderBackdrop,
649
650
  onClose: handleClose,
@@ -651,7 +652,7 @@ const CopilotModal = (0, react.forwardRef)(function CopilotModal({ visible, onDi
651
652
  keyboardBlurBehavior: "restore",
652
653
  backgroundStyle: styles.sheetBackground,
653
654
  handleIndicatorStyle: styles.handleIndicator,
654
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_gorhom_bottom_sheet.BottomSheetView, {
655
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
655
656
  style: styles.contentContainer,
656
657
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChat, {
657
658
  ...chatProps,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["Animated","styles","View","StyleSheet","TIMESTAMP_COLOR","useMarkdownRenderer","View","styles","isNativeComponentRenderer","React","CopilotMarkdown","Text","StyleSheet","View","styles","Text","StyleSheet","FlatList","View","styles","Text","Pressable","TextInput","TouchableOpacity","KeyboardAvoidingView","Platform","StyleSheet","BottomSheetBackdrop","BottomSheet","BottomSheetView","BottomSheetFlatList","StyleSheet"],"sources":["../../src/components/messages/TypingIndicator.tsx","../../src/components/messages/utils.ts","../../src/components/messages/AssistantMessage.tsx","../../src/components/messages/UserMessage.tsx","../../src/components/CopilotChat.tsx","../../src/components/CopilotModal.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { View, Animated, StyleSheet } from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\n\n/**\n * Props for the TypingIndicator component.\n */\nexport interface TypingIndicatorProps {\n /** Optional style override for the container */\n style?: ViewStyle;\n}\n\nconst DOT_SIZE = 6;\nconst DOT_SPACING = 4;\nconst ANIMATION_DURATION = 400;\n\n/**\n * Three animated dots that pulse in sequence, suitable for embedding\n * inside an AssistantMessage to indicate the AI is still generating.\n *\n * Uses React Native's built-in `Animated` API (no Reanimated dependency).\n */\nexport function TypingIndicator({ style }: TypingIndicatorProps) {\n const [dot1] = useState(() => new Animated.Value(0));\n const [dot2] = useState(() => new Animated.Value(0));\n const [dot3] = useState(() => new Animated.Value(0));\n\n useEffect(() => {\n const createPulse = (dot: Animated.Value, delay: number) =>\n Animated.sequence([\n Animated.delay(delay),\n Animated.loop(\n Animated.sequence([\n Animated.timing(dot, {\n toValue: 1,\n duration: ANIMATION_DURATION,\n useNativeDriver: true,\n }),\n Animated.timing(dot, {\n toValue: 0,\n duration: ANIMATION_DURATION,\n useNativeDriver: true,\n }),\n ]),\n ),\n ]);\n\n const animation = Animated.parallel([\n createPulse(dot1, 0),\n createPulse(dot2, ANIMATION_DURATION * 0.33),\n createPulse(dot3, ANIMATION_DURATION * 0.66),\n ]);\n\n animation.start();\n\n return () => {\n animation.stop();\n };\n }, [dot1, dot2, dot3]);\n\n const dotStyle = (animatedValue: Animated.Value) => ({\n ...styles.dot,\n opacity: animatedValue.interpolate({\n inputRange: [0, 1],\n outputRange: [0.3, 1],\n }),\n transform: [\n {\n scale: animatedValue.interpolate({\n inputRange: [0, 1],\n outputRange: [0.8, 1.2],\n }),\n },\n ],\n });\n\n return (\n <View\n testID=\"copilot-loading-cursor\"\n style={[styles.container, style]}\n accessibilityLabel=\"Typing indicator\"\n accessibilityRole=\"text\"\n >\n <Animated.View style={dotStyle(dot1)} />\n <Animated.View style={dotStyle(dot2)} />\n <Animated.View style={dotStyle(dot3)} />\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flexDirection: \"row\",\n alignItems: \"center\",\n paddingVertical: 4,\n paddingHorizontal: 2,\n },\n dot: {\n width: DOT_SIZE,\n height: DOT_SIZE,\n borderRadius: DOT_SIZE / 2,\n backgroundColor: \"#999999\",\n marginHorizontal: DOT_SPACING / 2,\n },\n});\n","/**\n * Format a Date as a 12-hour time string (e.g. \"2:05 PM\").\n */\nexport function formatTimestamp(date: Date): string {\n const hours = date.getHours();\n const minutes = date.getMinutes();\n const ampm = hours >= 12 ? \"PM\" : \"AM\";\n const displayHours = hours % 12 || 12;\n const displayMinutes = minutes.toString().padStart(2, \"0\");\n return `${displayHours}:${displayMinutes} ${ampm}`;\n}\n","import React from \"react\";\nimport { View, Text, StyleSheet } from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\nimport { CopilotMarkdown } from \"../Markdown\";\nimport {\n useMarkdownRenderer,\n isNativeComponentRenderer,\n} from \"../MarkdownRendererContext\";\nimport { TypingIndicator } from \"./TypingIndicator\";\nimport { formatTimestamp } from \"./utils\";\n\n// ─── Colors ──────────────────────────────────────────────────────────────────\nconst ASSISTANT_BUBBLE_BG = \"#F0F0F0\";\nconst TIMESTAMP_COLOR = \"#999999\";\n\n/**\n * Props for the AssistantMessage component.\n */\nexport interface AssistantMessageProps {\n /** Markdown content to render inside the bubble */\n content: string;\n /** When true, shows a typing indicator below any content */\n isLoading?: boolean;\n /** Optional timestamp displayed below the bubble */\n timestamp?: Date;\n /** Optional style override for the outer container */\n style?: ViewStyle;\n}\n\n/**\n * Left-aligned chat bubble for AI assistant responses.\n *\n * Renders markdown content via `CopilotMarkdown` and shows an animated\n * typing indicator when `isLoading` is true.\n */\nexport function AssistantMessage({\n content,\n isLoading = false,\n timestamp,\n style,\n}: AssistantMessageProps) {\n // Honor a provider-level markdown renderer (CopilotKitProvider's\n // `markdownRenderer` prop), falling back to the built-in CopilotMarkdown.\n // This is the React Native arm of the slot -> provider -> built-in\n // resolution order documented in the migration guide.\n const provided = useMarkdownRenderer();\n return (\n <View style={[styles.container, style]}>\n <View style={styles.bubble}>\n {content ? (\n isNativeComponentRenderer(provided) ? (\n React.createElement(provided, { content, isStreaming: isLoading })\n ) : provided ? (\n <CopilotMarkdown\n content={content}\n style={provided.style}\n streamingAnimation={provided.animate}\n />\n ) : (\n <CopilotMarkdown content={content} />\n )\n ) : null}\n {isLoading ? <TypingIndicator /> : null}\n </View>\n {timestamp && (\n <Text style={styles.timestamp}>{formatTimestamp(timestamp)}</Text>\n )}\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n alignItems: \"flex-start\",\n marginVertical: 4,\n paddingHorizontal: 12,\n },\n bubble: {\n backgroundColor: ASSISTANT_BUBBLE_BG,\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n borderBottomRightRadius: 16,\n borderBottomLeftRadius: 4,\n paddingHorizontal: 12,\n paddingVertical: 8,\n maxWidth: \"80%\",\n },\n timestamp: {\n color: TIMESTAMP_COLOR,\n fontSize: 11,\n marginTop: 2,\n marginLeft: 4,\n },\n});\n","import React from \"react\";\nimport { View, Text, StyleSheet, type ViewStyle } from \"react-native\";\nimport { formatTimestamp } from \"./utils\";\n\n// ─── Colors ──────────────────────────────────────────────────────────────────\nconst USER_BUBBLE_BG = \"#0066CC\";\nconst USER_TEXT_COLOR = \"#FFFFFF\";\nconst TIMESTAMP_COLOR = \"#999999\";\n\n/**\n * Props for the UserMessage component.\n */\nexport interface UserMessageProps {\n /** Plain text content to display */\n content: string;\n /** Optional timestamp displayed below the bubble */\n timestamp?: Date;\n /** Optional style override for the outer container */\n style?: ViewStyle;\n}\n\n/**\n * Right-aligned chat bubble for user messages.\n *\n * Renders plain text (no markdown) with a primary-color background\n * and white text. Optionally displays a subtle timestamp below.\n */\nexport function UserMessage({ content, timestamp, style }: UserMessageProps) {\n return (\n <View style={[styles.container, style]}>\n <View style={styles.bubble}>\n <Text style={styles.text}>{content}</Text>\n </View>\n {timestamp && (\n <Text style={styles.timestamp}>{formatTimestamp(timestamp)}</Text>\n )}\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n alignItems: \"flex-end\",\n marginVertical: 4,\n paddingHorizontal: 12,\n },\n bubble: {\n backgroundColor: USER_BUBBLE_BG,\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n borderBottomLeftRadius: 16,\n borderBottomRightRadius: 4,\n paddingHorizontal: 12,\n paddingVertical: 8,\n maxWidth: \"80%\",\n },\n text: {\n color: USER_TEXT_COLOR,\n fontSize: 16,\n lineHeight: 22,\n },\n timestamp: {\n color: TIMESTAMP_COLOR,\n fontSize: 11,\n marginTop: 2,\n marginRight: 4,\n },\n});\n","import React, {\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n FlatList,\n KeyboardAvoidingView,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n TextInput,\n TouchableOpacity,\n View,\n} from \"react-native\";\nimport type { ListRenderItemInfo, ViewStyle } from \"react-native\";\nimport { useAgent, useRenderToolCall } from \"@copilotkit/react-core/headless\";\nimport { useCopilotKit } from \"@copilotkit/react-core/context\";\nimport {\n ɵcreateChatSubmitter,\n ɵgetToolResults,\n ɵmessagesFingerprint,\n} from \"@copilotkit/core\";\nimport type { CopilotKitCore } from \"@copilotkit/core\";\nimport { AssistantMessage } from \"./messages/AssistantMessage\";\nimport { UserMessage } from \"./messages/UserMessage\";\nimport type { ToolMessage } from \"@ag-ui/client\";\n\n/** Shape of an assistant message with optional tool calls. */\ninterface AssistantMessageShape {\n id: string;\n role: \"assistant\";\n content?: string;\n toolCalls?: Array<{\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n }>;\n}\n\nexport interface CopilotChatProps {\n /** Agent ID to connect to. Defaults to 'default'. */\n agentName?: string;\n /** Placeholder text for the input field. */\n placeholder?: string;\n /** Suggestion pills shown in the empty state. */\n initialMessages?: string[];\n /** Title shown when there are no messages. */\n emptyStateTitle?: string;\n /** Subtitle shown when there are no messages. */\n emptyStateSubtitle?: string;\n /** Title for the optional header bar. */\n headerTitle?: string;\n /** Whether to show the header bar. Defaults to true. */\n showHeader?: boolean;\n /** Style override for the outermost container. */\n style?: ViewStyle;\n /** Style override for the message list container. */\n messageContainerStyle?: ViewStyle;\n /** Style override for the input bar container. */\n inputContainerStyle?: ViewStyle;\n /** Callback fired when the user sends a message. */\n onSendMessage?: (text: string) => void;\n /** Custom FlatList component (e.g. BottomSheetFlatList for use inside a bottom sheet). */\n FlatListComponent?: React.ComponentType<any>;\n /** When true, skip the KeyboardAvoidingView wrapper (useful when a parent already handles keyboard). */\n disableKeyboardAvoiding?: boolean;\n}\n\ninterface ChatListItem {\n id: string;\n type: \"user\" | \"assistant\" | \"tool-call\" | \"loading\";\n content?: string;\n toolCalls?: Array<{\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n }>;\n}\n\n/**\n * The core as the chat's submitter takes it, with a failed run also passed to\n * `onRunError` so the chat can show it. The submitter logs the failure itself.\n */\nfunction withRunErrorReporting(\n core: CopilotKitCore,\n onRunError: (message: string) => void,\n): Parameters<typeof ɵcreateChatSubmitter>[0][\"core\"] {\n return {\n runAgent: async (params) => {\n try {\n return await core.runAgent(params);\n } catch (err) {\n onRunError(\n err instanceof Error ? err.message : \"An unexpected error occurred\",\n );\n throw err;\n }\n },\n stopAgent: (params) => core.stopAgent(params),\n // This chat does not transcribe, but the submitter's core type covers it.\n get runtimeUrl() {\n return core.runtimeUrl;\n },\n get runtimeTransport() {\n return core.runtimeTransport;\n },\n get credentials() {\n return core.credentials;\n },\n resolveHeaders: () => core.resolveHeaders(),\n };\n}\n\n/**\n * Full-screen chat UI component for React Native.\n *\n * Connects to a CopilotKit agent via `useAgent` and renders messages\n * using platform-appropriate AssistantMessage / UserMessage components.\n *\n * Usage:\n * ```tsx\n * <CopilotChat agentName=\"my-agent\" headerTitle=\"Assistant\" />\n * ```\n */\nexport function CopilotChat({\n agentName = \"default\",\n placeholder = \"Type a message...\",\n initialMessages = [],\n emptyStateTitle = \"How can I help?\",\n emptyStateSubtitle = \"Ask me anything or try a suggestion below.\",\n headerTitle = \"Chat\",\n showHeader = true,\n style,\n messageContainerStyle,\n inputContainerStyle,\n onSendMessage,\n FlatListComponent = FlatList,\n disableKeyboardAvoiding = false,\n}: CopilotChatProps) {\n const [inputText, setInputText] = useState(\"\");\n const [error, setError] = useState<string | null>(null);\n const flatListRef = useRef<FlatList>(null);\n\n const { copilotkit } = useCopilotKit();\n const { agent } = useAgent({ agentId: agentName });\n\n const messages = agent.messages ?? [];\n const isRunning = agent.isRunning;\n\n const renderToolCall = useRenderToolCall();\n\n // useInterrupt publishes its element to core unless renderInChat is false.\n // Draw it after the last message, as the web message view does.\n const [interruptElement, setInterruptElement] =\n useState<React.ReactElement | null>(null);\n useEffect(() => {\n setInterruptElement(copilotkit.interruptElement);\n const subscription = copilotkit.subscribe({\n onInterruptElementChanged: ({ interruptElement: element }) => {\n setInterruptElement(element);\n },\n });\n return () => subscription.unsubscribe();\n }, [copilotkit]);\n\n // Recomputed every render: cheap, and the only honest dependency for the\n // message-derived memos below. The array reference does not track content\n // in either direction: core inserts tool results with an in-place `splice`,\n // `addMessage` pushes, and the AG-UI apply pipeline replaces the array on\n // every streamed delta.\n const messagesKey = ɵmessagesFingerprint(messages);\n\n // toolCallId -> tool result message, so a renderer reports \"complete\" with\n // its `result`.\n const toolMessages = useMemo(() => {\n const byId = new Map<string, ToolMessage>();\n for (const [toolCallId, message] of ɵgetToolResults(messages)) {\n // A copy, so the tool-call renderer's memo sees content that was\n // replaced in place on the same message. Core turns the content into\n // the renderer's `result` string.\n byId.set(toolCallId, { ...message });\n }\n return byId;\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on message content, see messagesKey\n }, [messagesKey]);\n\n // Build flat list items from messages\n const listItems: ChatListItem[] = useMemo(() => {\n const items: ChatListItem[] = [];\n\n for (const msg of messages) {\n if (msg.role === \"user\") {\n items.push({\n id: msg.id,\n type: \"user\",\n content: typeof msg.content === \"string\" ? msg.content : \"\",\n });\n } else if (msg.role === \"assistant\") {\n const assistantMsg = msg as AssistantMessageShape;\n // Add text content if present\n if (assistantMsg.content) {\n items.push({\n id: msg.id,\n type: \"assistant\",\n content: assistantMsg.content,\n });\n }\n // Add tool calls if present\n if (assistantMsg.toolCalls && assistantMsg.toolCalls.length > 0) {\n for (const tc of assistantMsg.toolCalls) {\n items.push({\n id: `${msg.id}-tc-${tc.id}`,\n type: \"tool-call\",\n toolCalls: [tc],\n });\n }\n }\n }\n }\n\n // Show loading indicator when agent is running and the last message\n // is not already the assistant streaming\n if (isRunning) {\n const lastItem = items[items.length - 1];\n if (!lastItem || lastItem.type !== \"assistant\") {\n items.push({ id: \"__loading__\", type: \"loading\" });\n }\n }\n\n return items;\n // Same reasoning as `toolMessages`: keyed on message CONTENT, because the\n // array reference does not track content in either direction — core's\n // in-place `splice` and `addMessage`'s push leave it untouched, while the\n // AG-UI apply pipeline replaces it on every delta. Without this, an\n // assistant message or tool call appended mid-run never reaches the list.\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on message content, see messagesKey\n }, [messagesKey, isRunning]);\n\n // Id of the trailing row. renderItem needs \"is this the last row?\" to place\n // the streaming indicator; deriving it here keeps that a named scalar instead\n // of renderItem closing over `listItems` and index-reading its tail.\n const lastItemId = useMemo(\n () => listItems[listItems.length - 1]?.id,\n [listItems],\n );\n\n // extraData defeats FlatList's PureComponent shallow-compare for the values\n // renderItem CLOSES OVER, as opposed to the ones it receives per row. Those\n // are exactly the four below, and they mirror renderItem's dependency array —\n // keep the two in sync. `listItems` is deliberately absent: renderItem's only\n // read of it is the tail id, now passed as `lastItemId`, and the array itself\n // is already the `data` prop, which invalidates cells on its own (every\n // rebuild allocates fresh item objects, so each cell's `item` prop differs).\n const extraData = useMemo(\n () => ({ isRunning, lastItemId, renderToolCall, toolMessages }),\n [isRunning, lastItemId, renderToolCall, toolMessages],\n );\n\n // The send side lives in core: it builds the message, waits for the run in\n // flight, and runs the agent. A failed run also shows under the list.\n const agentRef = useRef(agent);\n const inputTextRef = useRef(inputText);\n useLayoutEffect(() => {\n agentRef.current = agent;\n inputTextRef.current = inputText;\n });\n const [submitter] = useState(() =>\n ɵcreateChatSubmitter({\n core: withRunErrorReporting(copilotkit, setError),\n getAgent: () => agentRef.current,\n input: {\n get: () => inputTextRef.current,\n set: (value) => {\n inputTextRef.current = value;\n setInputText(value);\n },\n },\n }),\n );\n useEffect(() => () => submitter.showNotice(null), [submitter]);\n\n // Send from the input field\n const handleSend = useCallback(() => {\n const text = inputText.trim();\n if (!text) return;\n setError(null);\n onSendMessage?.(text);\n void submitter.submit(text);\n }, [inputText, onSendMessage, submitter]);\n\n // Handle suggestion pill press. Leaves the typed text alone.\n const handleSuggestion = useCallback(\n (text: string) => {\n setError(null);\n onSendMessage?.(text);\n void submitter.selectSuggestion({ message: text, isLoading: false });\n },\n [onSendMessage, submitter],\n );\n\n // Auto-scroll when content changes\n const handleContentSizeChange = useCallback(() => {\n flatListRef.current?.scrollToEnd({ animated: true });\n }, []);\n\n // Render a single list item\n const renderItem = useCallback(\n ({ item }: ListRenderItemInfo<ChatListItem>) => {\n if (item.type === \"user\") {\n return <UserMessage content={item.content ?? \"\"} />;\n }\n\n if (item.type === \"assistant\") {\n return (\n <AssistantMessage\n content={item.content ?? \"\"}\n isLoading={isRunning && item.id === lastItemId}\n />\n );\n }\n\n if (item.type === \"tool-call\" && item.toolCalls) {\n const tc = item.toolCalls[0];\n // Partial-parses streaming args, resolves the renderer (exact name ->\n // agent-scoped -> wildcard \"*\") and derives status — all in react-core,\n // shared with web. Returns ReactElement | null, which is what\n // renderItem requires.\n const rendered = renderToolCall({\n toolCall: tc,\n toolMessage: toolMessages.get(tc.id),\n });\n if (rendered) return <>{rendered}</>;\n\n // Subtle indicator for unregistered tool calls\n return (\n <View style={styles.toolCallIndicator}>\n <Text style={styles.toolCallText}>Called: {tc.function.name}</Text>\n </View>\n );\n }\n\n if (item.type === \"loading\") {\n return <AssistantMessage content=\"\" isLoading />;\n }\n\n return null;\n },\n [isRunning, lastItemId, renderToolCall, toolMessages],\n );\n\n const keyExtractor = useCallback((item: ChatListItem) => item.id, []);\n\n // Empty state component\n const emptyComponent = useMemo(\n () => (\n <View style={styles.emptyState}>\n <Text style={styles.emptyTitle}>{emptyStateTitle}</Text>\n <Text style={styles.emptySubtitle}>{emptyStateSubtitle}</Text>\n {initialMessages.map((suggestion, i) => (\n <Pressable\n key={`suggestion-${i}`}\n style={styles.suggestionPill}\n onPress={() => handleSuggestion(suggestion)}\n >\n <Text style={styles.suggestionText}>{suggestion}</Text>\n </Pressable>\n ))}\n </View>\n ),\n [emptyStateTitle, emptyStateSubtitle, initialMessages, handleSuggestion],\n );\n\n const sendDisabled = !inputText.trim() || isRunning;\n\n const content = (\n <>\n {showHeader && (\n <View style={styles.header}>\n <Text style={styles.headerTitle}>{headerTitle}</Text>\n </View>\n )}\n\n <FlatListComponent\n ref={flatListRef}\n data={listItems}\n renderItem={renderItem}\n keyExtractor={keyExtractor}\n extraData={extraData}\n contentContainerStyle={[styles.messageList, messageContainerStyle]}\n onContentSizeChange={handleContentSizeChange}\n ListEmptyComponent={emptyComponent}\n ListFooterComponent={interruptElement}\n />\n\n {error && (\n <View style={styles.errorContainer} testID=\"error-message\">\n <Text style={styles.errorText}>{error}</Text>\n </View>\n )}\n\n <View style={[styles.inputContainer, inputContainerStyle]}>\n <TextInput\n style={styles.input}\n value={inputText}\n onChangeText={setInputText}\n placeholder={placeholder}\n placeholderTextColor=\"#999\"\n multiline\n numberOfLines={4}\n returnKeyType=\"send\"\n // A multiline input inserts a newline on Return unless told to\n // submit. React Native 0.73+ reads submitBehavior; older versions and\n // react-native-web read blurOnSubmit. On the web, Shift+Enter still\n // inserts a newline.\n submitBehavior=\"submit\"\n blurOnSubmit\n onSubmitEditing={handleSend}\n />\n <TouchableOpacity\n style={[styles.sendButton, sendDisabled && styles.sendButtonDisabled]}\n onPress={handleSend}\n disabled={sendDisabled}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Send message\"\n accessibilityState={{ disabled: sendDisabled }}\n testID=\"send-button\"\n >\n <Text style={styles.sendButtonIcon}>{\"↑\"}</Text>\n </TouchableOpacity>\n </View>\n </>\n );\n\n if (disableKeyboardAvoiding) {\n return <View style={[styles.container, style]}>{content}</View>;\n }\n\n return (\n <KeyboardAvoidingView\n style={[styles.container, style]}\n behavior={Platform.OS === \"ios\" ? \"padding\" : \"height\"}\n keyboardVerticalOffset={0}\n >\n {content}\n </KeyboardAvoidingView>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n backgroundColor: \"#FFFFFF\",\n },\n header: {\n height: 56,\n justifyContent: \"center\",\n alignItems: \"center\",\n borderBottomWidth: StyleSheet.hairlineWidth,\n borderBottomColor: \"#E0E0E0\",\n backgroundColor: \"#FFFFFF\",\n },\n headerTitle: {\n fontSize: 17,\n fontWeight: \"600\",\n color: \"#1A1A1A\",\n },\n messageList: {\n paddingHorizontal: 16,\n flexGrow: 1,\n },\n inputContainer: {\n flexDirection: \"row\",\n alignItems: \"flex-end\",\n paddingHorizontal: 8,\n paddingVertical: 8,\n borderTopWidth: StyleSheet.hairlineWidth,\n borderTopColor: \"#E0E0E0\",\n backgroundColor: \"#FFFFFF\",\n },\n input: {\n flex: 1,\n backgroundColor: \"#F5F5F5\",\n borderRadius: 20,\n paddingHorizontal: 12,\n paddingVertical: 8,\n fontSize: 15,\n maxHeight: 100,\n color: \"#1A1A1A\",\n },\n sendButton: {\n width: 36,\n height: 36,\n borderRadius: 18,\n backgroundColor: \"#0066CC\",\n justifyContent: \"center\",\n alignItems: \"center\",\n marginLeft: 8,\n },\n sendButtonDisabled: {\n opacity: 0.4,\n },\n sendButtonIcon: {\n color: \"#FFFFFF\",\n fontSize: 18,\n fontWeight: \"700\",\n },\n emptyState: {\n flex: 1,\n justifyContent: \"center\",\n alignItems: \"center\",\n paddingTop: 100,\n gap: 12,\n },\n emptyTitle: {\n fontSize: 22,\n fontWeight: \"700\",\n color: \"#1A1A1A\",\n marginBottom: 4,\n },\n emptySubtitle: {\n fontSize: 15,\n color: \"#666666\",\n marginBottom: 16,\n },\n suggestionPill: {\n backgroundColor: \"#E8F0FE\",\n borderRadius: 20,\n paddingHorizontal: 16,\n paddingVertical: 10,\n },\n suggestionText: {\n color: \"#0066CC\",\n fontWeight: \"600\",\n fontSize: 14,\n },\n toolCallIndicator: {\n alignSelf: \"flex-start\",\n backgroundColor: \"#F0F0F0\",\n borderRadius: 12,\n paddingHorizontal: 12,\n paddingVertical: 6,\n marginBottom: 8,\n },\n toolCallText: {\n fontSize: 12,\n color: \"#999999\",\n fontStyle: \"italic\",\n },\n errorContainer: {\n backgroundColor: \"#FEE2E2\",\n paddingHorizontal: 12,\n paddingVertical: 8,\n marginHorizontal: 8,\n borderRadius: 8,\n },\n errorText: {\n color: \"#DC2626\",\n fontSize: 13,\n },\n});\n","/**\n * CopilotModal — a bottom-sheet chat overlay for React Native.\n *\n * Mobile equivalent of CopilotPopup on web. Wraps CopilotChat inside\n * @gorhom/bottom-sheet so the chat can slide up over any screen.\n */\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from \"react\";\nimport { StyleSheet } from \"react-native\";\nimport BottomSheet, {\n BottomSheetBackdrop,\n BottomSheetFlatList,\n BottomSheetView,\n} from \"@gorhom/bottom-sheet\";\nimport type { BottomSheetBackdropProps } from \"@gorhom/bottom-sheet\";\nimport { CopilotChat } from \"./CopilotChat\";\nimport type { CopilotChatProps } from \"./CopilotChat\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface CopilotModalProps {\n /** Controlled visibility — when true the sheet opens, when false it closes. */\n visible?: boolean;\n\n /** Called when the sheet is dismissed (via backdrop tap, swipe-down, or close()). */\n onDismiss?: () => void;\n\n /**\n * Bottom-sheet snap points.\n * @default ['50%', '90%']\n */\n snapPoints?: (string | number)[];\n\n /**\n * Which snap-point index to open at.\n * @default 0\n */\n initialSnapIndex?: number;\n\n /**\n * Whether closing the sheet fires onDismiss.\n * @default true\n */\n enableDismissOnClose?: boolean;\n\n /**\n * Backdrop opacity when the sheet is open.\n * @default 0.5\n */\n backdropOpacity?: number;\n\n // -- Pass-through to CopilotChat ------------------------------------------\n\n /** Which agent to connect to. */\n agentName?: string;\n\n /** Input placeholder text. */\n placeholder?: string;\n\n /** Seed messages shown on first render. */\n initialMessages?: string[];\n\n /** Title shown in the CopilotChat header area. */\n headerTitle?: string;\n}\n\n/** Imperative handle exposed via ref. */\nexport interface CopilotModalRef {\n /** Programmatically open the bottom sheet. */\n open: () => void;\n /** Programmatically close the bottom sheet. */\n close: () => void;\n}\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\nexport const CopilotModal = forwardRef<CopilotModalRef, CopilotModalProps>(\n function CopilotModal(\n {\n visible,\n onDismiss,\n snapPoints: snapPointsProp,\n initialSnapIndex = 0,\n enableDismissOnClose = true,\n backdropOpacity = 0.5,\n agentName,\n placeholder,\n initialMessages,\n headerTitle,\n },\n ref,\n ) {\n const bottomSheetRef = useRef<BottomSheet>(null);\n\n // Stable snap-points array\n const snapPoints = useMemo(\n () => snapPointsProp ?? [\"50%\", \"90%\"],\n [snapPointsProp],\n );\n\n // ── Imperative API ────────────────────────────────────────────────────\n useImperativeHandle(\n ref,\n () => ({\n open() {\n bottomSheetRef.current?.snapToIndex(initialSnapIndex);\n },\n close() {\n bottomSheetRef.current?.close();\n },\n }),\n [initialSnapIndex],\n );\n\n // ── Controlled visibility ─────────────────────────────────────────────\n useEffect(() => {\n if (visible === undefined) return;\n if (visible) {\n bottomSheetRef.current?.snapToIndex(initialSnapIndex);\n } else {\n bottomSheetRef.current?.close();\n }\n }, [visible, initialSnapIndex]);\n\n // ── Backdrop renderer ─────────────────────────────────────────────────\n const renderBackdrop = useCallback(\n (props: BottomSheetBackdropProps) => (\n <BottomSheetBackdrop\n {...props}\n disappearsOnIndex={-1}\n appearsOnIndex={0}\n opacity={backdropOpacity}\n pressBehavior=\"close\"\n />\n ),\n [backdropOpacity],\n );\n\n // ── Sheet close handler ───────────────────────────────────────────────\n const handleClose = useCallback(() => {\n if (enableDismissOnClose) {\n onDismiss?.();\n }\n }, [enableDismissOnClose, onDismiss]);\n\n // ── Build CopilotChat props ───────────────────────────────────────────\n const chatProps = useMemo(() => {\n const props: Partial<CopilotChatProps> = {};\n if (agentName !== undefined) props.agentName = agentName;\n if (placeholder !== undefined) props.placeholder = placeholder;\n if (initialMessages !== undefined)\n props.initialMessages = initialMessages;\n if (headerTitle !== undefined) props.headerTitle = headerTitle;\n return props;\n }, [agentName, placeholder, initialMessages, headerTitle]);\n\n return (\n <BottomSheet\n ref={bottomSheetRef}\n index={-1}\n snapPoints={snapPoints}\n enablePanDownToClose\n backdropComponent={renderBackdrop}\n onClose={handleClose}\n keyboardBehavior=\"interactive\"\n keyboardBlurBehavior=\"restore\"\n backgroundStyle={styles.sheetBackground}\n handleIndicatorStyle={styles.handleIndicator}\n >\n <BottomSheetView style={styles.contentContainer}>\n <CopilotChat\n {...chatProps}\n FlatListComponent={BottomSheetFlatList}\n disableKeyboardAvoiding\n />\n </BottomSheetView>\n </BottomSheet>\n );\n },\n);\n\n// ---------------------------------------------------------------------------\n// Styles\n// ---------------------------------------------------------------------------\n\nconst styles = StyleSheet.create({\n sheetBackground: {\n backgroundColor: \"#FFFFFF\",\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n },\n handleIndicator: {\n width: 40,\n height: 4,\n backgroundColor: \"#DDDDDD\",\n },\n contentContainer: {\n flex: 1,\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAYA,MAAM,WAAW;AACjB,MAAM,cAAc;AACpB,MAAM,qBAAqB;;;;;;;AAQ3B,SAAgB,gBAAgB,EAAE,SAA+B;CAC/D,MAAM,CAAC,kCAAuB,IAAIA,sBAAS,MAAM,EAAE,CAAC;CACpD,MAAM,CAAC,kCAAuB,IAAIA,sBAAS,MAAM,EAAE,CAAC;CACpD,MAAM,CAAC,kCAAuB,IAAIA,sBAAS,MAAM,EAAE,CAAC;AAEpD,4BAAgB;EACd,MAAM,eAAe,KAAqB,UACxCA,sBAAS,SAAS,CAChBA,sBAAS,MAAM,MAAM,EACrBA,sBAAS,KACPA,sBAAS,SAAS,CAChBA,sBAAS,OAAO,KAAK;GACnB,SAAS;GACT,UAAU;GACV,iBAAiB;GAClB,CAAC,EACFA,sBAAS,OAAO,KAAK;GACnB,SAAS;GACT,UAAU;GACV,iBAAiB;GAClB,CAAC,CACH,CAAC,CACH,CACF,CAAC;EAEJ,MAAM,YAAYA,sBAAS,SAAS;GAClC,YAAY,MAAM,EAAE;GACpB,YAAY,MAAM,qBAAqB,IAAK;GAC5C,YAAY,MAAM,qBAAqB,IAAK;GAC7C,CAAC;AAEF,YAAU,OAAO;AAEjB,eAAa;AACX,aAAU,MAAM;;IAEjB;EAAC;EAAM;EAAM;EAAK,CAAC;CAEtB,MAAM,YAAY,mBAAmC;EACnD,GAAGC,SAAO;EACV,SAAS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AM,SAASC,wBAAW,OAAO;CAC/B,iBAAiB;EACf,iBAAiB;EACjB,qBAAqB;EACrB,sBAAsB;EACvB;CACD,iBAAiB;EACf,OAAO;EACP,QAAQ;EACR,iBAAiB;EAClB;CACD,kBAAkB,EAChB,MAAM,GACP;CACF,CAAC"}
1
+ {"version":3,"file":"index.cjs","names":["Animated","styles","View","StyleSheet","TIMESTAMP_COLOR","useMarkdownRenderer","View","styles","isNativeComponentRenderer","React","CopilotMarkdown","Text","StyleSheet","View","styles","Text","StyleSheet","FlatList","View","styles","Text","Pressable","TextInput","Platform","TouchableOpacity","KeyboardAvoidingView","StyleSheet","BottomSheetBackdrop","BottomSheet","View","BottomSheetFlatList","StyleSheet"],"sources":["../../src/components/messages/TypingIndicator.tsx","../../src/components/messages/utils.ts","../../src/components/messages/AssistantMessage.tsx","../../src/components/messages/UserMessage.tsx","../../src/components/CopilotChat.tsx","../../src/components/CopilotModal.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { View, Animated, StyleSheet } from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\n\n/**\n * Props for the TypingIndicator component.\n */\nexport interface TypingIndicatorProps {\n /** Optional style override for the container */\n style?: ViewStyle;\n}\n\nconst DOT_SIZE = 6;\nconst DOT_SPACING = 4;\nconst ANIMATION_DURATION = 400;\n\n/**\n * Three animated dots that pulse in sequence, suitable for embedding\n * inside an AssistantMessage to indicate the AI is still generating.\n *\n * Uses React Native's built-in `Animated` API (no Reanimated dependency).\n */\nexport function TypingIndicator({ style }: TypingIndicatorProps) {\n const [dot1] = useState(() => new Animated.Value(0));\n const [dot2] = useState(() => new Animated.Value(0));\n const [dot3] = useState(() => new Animated.Value(0));\n\n useEffect(() => {\n const createPulse = (dot: Animated.Value, delay: number) =>\n Animated.sequence([\n Animated.delay(delay),\n Animated.loop(\n Animated.sequence([\n Animated.timing(dot, {\n toValue: 1,\n duration: ANIMATION_DURATION,\n useNativeDriver: true,\n }),\n Animated.timing(dot, {\n toValue: 0,\n duration: ANIMATION_DURATION,\n useNativeDriver: true,\n }),\n ]),\n ),\n ]);\n\n const animation = Animated.parallel([\n createPulse(dot1, 0),\n createPulse(dot2, ANIMATION_DURATION * 0.33),\n createPulse(dot3, ANIMATION_DURATION * 0.66),\n ]);\n\n animation.start();\n\n return () => {\n animation.stop();\n };\n }, [dot1, dot2, dot3]);\n\n const dotStyle = (animatedValue: Animated.Value) => ({\n ...styles.dot,\n opacity: animatedValue.interpolate({\n inputRange: [0, 1],\n outputRange: [0.3, 1],\n }),\n transform: [\n {\n scale: animatedValue.interpolate({\n inputRange: [0, 1],\n outputRange: [0.8, 1.2],\n }),\n },\n ],\n });\n\n return (\n <View\n testID=\"copilot-loading-cursor\"\n style={[styles.container, style]}\n accessibilityLabel=\"Typing indicator\"\n accessibilityRole=\"text\"\n >\n <Animated.View style={dotStyle(dot1)} />\n <Animated.View style={dotStyle(dot2)} />\n <Animated.View style={dotStyle(dot3)} />\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flexDirection: \"row\",\n alignItems: \"center\",\n paddingVertical: 4,\n paddingHorizontal: 2,\n },\n dot: {\n width: DOT_SIZE,\n height: DOT_SIZE,\n borderRadius: DOT_SIZE / 2,\n backgroundColor: \"#999999\",\n marginHorizontal: DOT_SPACING / 2,\n },\n});\n","/**\n * Format a Date as a 12-hour time string (e.g. \"2:05 PM\").\n */\nexport function formatTimestamp(date: Date): string {\n const hours = date.getHours();\n const minutes = date.getMinutes();\n const ampm = hours >= 12 ? \"PM\" : \"AM\";\n const displayHours = hours % 12 || 12;\n const displayMinutes = minutes.toString().padStart(2, \"0\");\n return `${displayHours}:${displayMinutes} ${ampm}`;\n}\n","import React from \"react\";\nimport { View, Text, StyleSheet } from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\nimport { CopilotMarkdown } from \"../Markdown\";\nimport {\n useMarkdownRenderer,\n isNativeComponentRenderer,\n} from \"../MarkdownRendererContext\";\nimport { TypingIndicator } from \"./TypingIndicator\";\nimport { formatTimestamp } from \"./utils\";\n\n// ─── Colors ──────────────────────────────────────────────────────────────────\nconst ASSISTANT_BUBBLE_BG = \"#F0F0F0\";\nconst TIMESTAMP_COLOR = \"#999999\";\n\n/**\n * Props for the AssistantMessage component.\n */\nexport interface AssistantMessageProps {\n /** Markdown content to render inside the bubble */\n content: string;\n /** When true, shows a typing indicator below any content */\n isLoading?: boolean;\n /** Optional timestamp displayed below the bubble */\n timestamp?: Date;\n /** Optional style override for the outer container */\n style?: ViewStyle;\n}\n\n/**\n * Left-aligned chat bubble for AI assistant responses.\n *\n * Renders markdown content via `CopilotMarkdown` and shows an animated\n * typing indicator when `isLoading` is true.\n */\nexport function AssistantMessage({\n content,\n isLoading = false,\n timestamp,\n style,\n}: AssistantMessageProps) {\n // Honor a provider-level markdown renderer (CopilotKitProvider's\n // `markdownRenderer` prop), falling back to the built-in CopilotMarkdown.\n // This is the React Native arm of the slot -> provider -> built-in\n // resolution order documented in the migration guide.\n const provided = useMarkdownRenderer();\n return (\n <View style={[styles.container, style]}>\n <View style={styles.bubble}>\n {content ? (\n isNativeComponentRenderer(provided) ? (\n React.createElement(provided, { content, isStreaming: isLoading })\n ) : provided ? (\n <CopilotMarkdown\n content={content}\n style={provided.style}\n streamingAnimation={provided.animate}\n />\n ) : (\n <CopilotMarkdown content={content} />\n )\n ) : null}\n {isLoading ? <TypingIndicator /> : null}\n </View>\n {timestamp && (\n <Text style={styles.timestamp}>{formatTimestamp(timestamp)}</Text>\n )}\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n alignItems: \"flex-start\",\n marginVertical: 4,\n paddingHorizontal: 12,\n },\n bubble: {\n backgroundColor: ASSISTANT_BUBBLE_BG,\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n borderBottomRightRadius: 16,\n borderBottomLeftRadius: 4,\n paddingHorizontal: 12,\n paddingVertical: 8,\n maxWidth: \"80%\",\n },\n timestamp: {\n color: TIMESTAMP_COLOR,\n fontSize: 11,\n marginTop: 2,\n marginLeft: 4,\n },\n});\n","import React from \"react\";\nimport { View, Text, StyleSheet, type ViewStyle } from \"react-native\";\nimport { formatTimestamp } from \"./utils\";\n\n// ─── Colors ──────────────────────────────────────────────────────────────────\nconst USER_BUBBLE_BG = \"#0066CC\";\nconst USER_TEXT_COLOR = \"#FFFFFF\";\nconst TIMESTAMP_COLOR = \"#999999\";\n\n/**\n * Props for the UserMessage component.\n */\nexport interface UserMessageProps {\n /** Plain text content to display */\n content: string;\n /** Optional timestamp displayed below the bubble */\n timestamp?: Date;\n /** Optional style override for the outer container */\n style?: ViewStyle;\n}\n\n/**\n * Right-aligned chat bubble for user messages.\n *\n * Renders plain text (no markdown) with a primary-color background\n * and white text. Optionally displays a subtle timestamp below.\n */\nexport function UserMessage({ content, timestamp, style }: UserMessageProps) {\n return (\n <View style={[styles.container, style]}>\n <View style={styles.bubble}>\n <Text style={styles.text}>{content}</Text>\n </View>\n {timestamp && (\n <Text style={styles.timestamp}>{formatTimestamp(timestamp)}</Text>\n )}\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n alignItems: \"flex-end\",\n marginVertical: 4,\n paddingHorizontal: 12,\n },\n bubble: {\n backgroundColor: USER_BUBBLE_BG,\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n borderBottomLeftRadius: 16,\n borderBottomRightRadius: 4,\n paddingHorizontal: 12,\n paddingVertical: 8,\n maxWidth: \"80%\",\n },\n text: {\n color: USER_TEXT_COLOR,\n fontSize: 16,\n lineHeight: 22,\n },\n timestamp: {\n color: TIMESTAMP_COLOR,\n fontSize: 11,\n marginTop: 2,\n marginRight: 4,\n },\n});\n","import React, {\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n FlatList,\n KeyboardAvoidingView,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n TextInput,\n TouchableOpacity,\n View,\n} from \"react-native\";\nimport type { ListRenderItemInfo, ViewStyle } from \"react-native\";\nimport { useAgent, useRenderToolCall } from \"@copilotkit/react-core/headless\";\nimport { useCopilotKit } from \"@copilotkit/react-core/context\";\nimport {\n ɵcreateChatSubmitter,\n ɵgetToolResults,\n ɵmessagesFingerprint,\n} from \"@copilotkit/core\";\nimport type { CopilotKitCore } from \"@copilotkit/core\";\nimport { AssistantMessage } from \"./messages/AssistantMessage\";\nimport { UserMessage } from \"./messages/UserMessage\";\nimport type { ToolMessage } from \"@ag-ui/client\";\n\n/** Shape of an assistant message with optional tool calls. */\ninterface AssistantMessageShape {\n id: string;\n role: \"assistant\";\n content?: string;\n toolCalls?: Array<{\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n }>;\n}\n\nexport interface CopilotChatProps {\n /** Agent ID to connect to. Defaults to 'default'. */\n agentName?: string;\n /** Placeholder text for the input field. */\n placeholder?: string;\n /** Suggestion pills shown in the empty state. */\n initialMessages?: string[];\n /** Title shown when there are no messages. */\n emptyStateTitle?: string;\n /** Subtitle shown when there are no messages. */\n emptyStateSubtitle?: string;\n /** Title for the optional header bar. */\n headerTitle?: string;\n /** Whether to show the header bar. Defaults to true. */\n showHeader?: boolean;\n /** Style override for the outermost container. */\n style?: ViewStyle;\n /** Style override for the message list container. */\n messageContainerStyle?: ViewStyle;\n /** Style override for the input bar container. */\n inputContainerStyle?: ViewStyle;\n /** Callback fired when the user sends a message. */\n onSendMessage?: (text: string) => void;\n /** Custom FlatList component (e.g. BottomSheetFlatList for use inside a bottom sheet). */\n FlatListComponent?: React.ComponentType<any>;\n /** When true, skip the KeyboardAvoidingView wrapper (useful when a parent already handles keyboard). */\n disableKeyboardAvoiding?: boolean;\n}\n\ninterface ChatListItem {\n id: string;\n type: \"user\" | \"assistant\" | \"tool-call\" | \"loading\";\n content?: string;\n toolCalls?: Array<{\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n }>;\n}\n\n/**\n * The core as the chat's submitter takes it, with a failed run also passed to\n * `onRunError` so the chat can show it. The submitter logs the failure itself.\n */\nfunction withRunErrorReporting(\n core: CopilotKitCore,\n onRunError: (message: string) => void,\n): Parameters<typeof ɵcreateChatSubmitter>[0][\"core\"] {\n return {\n runAgent: async (params) => {\n try {\n return await core.runAgent(params);\n } catch (err) {\n onRunError(\n err instanceof Error ? err.message : \"An unexpected error occurred\",\n );\n throw err;\n }\n },\n stopAgent: (params) => core.stopAgent(params),\n // This chat does not transcribe, but the submitter's core type covers it.\n get runtimeUrl() {\n return core.runtimeUrl;\n },\n get runtimeTransport() {\n return core.runtimeTransport;\n },\n get credentials() {\n return core.credentials;\n },\n resolveHeaders: () => core.resolveHeaders(),\n };\n}\n\n/**\n * Full-screen chat UI component for React Native.\n *\n * Connects to a CopilotKit agent via `useAgent` and renders messages\n * using platform-appropriate AssistantMessage / UserMessage components.\n *\n * Usage:\n * ```tsx\n * <CopilotChat agentName=\"my-agent\" headerTitle=\"Assistant\" />\n * ```\n */\nexport function CopilotChat({\n agentName = \"default\",\n placeholder = \"Type a message...\",\n initialMessages = [],\n emptyStateTitle = \"How can I help?\",\n emptyStateSubtitle = \"Ask me anything or try a suggestion below.\",\n headerTitle = \"Chat\",\n showHeader = true,\n style,\n messageContainerStyle,\n inputContainerStyle,\n onSendMessage,\n FlatListComponent = FlatList,\n disableKeyboardAvoiding = false,\n}: CopilotChatProps) {\n const [inputText, setInputText] = useState(\"\");\n const [error, setError] = useState<string | null>(null);\n const flatListRef = useRef<FlatList>(null);\n\n const { copilotkit } = useCopilotKit();\n const { agent } = useAgent({ agentId: agentName });\n\n const messages = agent.messages ?? [];\n const isRunning = agent.isRunning;\n\n const renderToolCall = useRenderToolCall();\n\n // useInterrupt publishes its element to core unless renderInChat is false.\n // Draw it after the last message, as the web message view does.\n const [interruptElement, setInterruptElement] =\n useState<React.ReactElement | null>(null);\n useEffect(() => {\n setInterruptElement(copilotkit.interruptElement);\n const subscription = copilotkit.subscribe({\n onInterruptElementChanged: ({ interruptElement: element }) => {\n setInterruptElement(element);\n },\n });\n return () => subscription.unsubscribe();\n }, [copilotkit]);\n\n // Recomputed every render: cheap, and the only honest dependency for the\n // message-derived memos below. The array reference does not track content\n // in either direction: core inserts tool results with an in-place `splice`,\n // `addMessage` pushes, and the AG-UI apply pipeline replaces the array on\n // every streamed delta.\n const messagesKey = ɵmessagesFingerprint(messages);\n\n // toolCallId -> tool result message, so a renderer reports \"complete\" with\n // its `result`.\n const toolMessages = useMemo(() => {\n const byId = new Map<string, ToolMessage>();\n for (const [toolCallId, message] of ɵgetToolResults(messages)) {\n // A copy, so the tool-call renderer's memo sees content that was\n // replaced in place on the same message. Core turns the content into\n // the renderer's `result` string.\n byId.set(toolCallId, { ...message });\n }\n return byId;\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on message content, see messagesKey\n }, [messagesKey]);\n\n // Build flat list items from messages\n const listItems: ChatListItem[] = useMemo(() => {\n const items: ChatListItem[] = [];\n\n for (const msg of messages) {\n if (msg.role === \"user\") {\n items.push({\n id: msg.id,\n type: \"user\",\n content: typeof msg.content === \"string\" ? msg.content : \"\",\n });\n } else if (msg.role === \"assistant\") {\n const assistantMsg = msg as AssistantMessageShape;\n // Add text content if present\n if (assistantMsg.content) {\n items.push({\n id: msg.id,\n type: \"assistant\",\n content: assistantMsg.content,\n });\n }\n // Add tool calls if present\n if (assistantMsg.toolCalls && assistantMsg.toolCalls.length > 0) {\n for (const tc of assistantMsg.toolCalls) {\n items.push({\n id: `${msg.id}-tc-${tc.id}`,\n type: \"tool-call\",\n toolCalls: [tc],\n });\n }\n }\n }\n }\n\n // Show loading indicator when agent is running and the last message\n // is not already the assistant streaming\n if (isRunning) {\n const lastItem = items[items.length - 1];\n if (!lastItem || lastItem.type !== \"assistant\") {\n items.push({ id: \"__loading__\", type: \"loading\" });\n }\n }\n\n return items;\n // Same reasoning as `toolMessages`: keyed on message CONTENT, because the\n // array reference does not track content in either direction — core's\n // in-place `splice` and `addMessage`'s push leave it untouched, while the\n // AG-UI apply pipeline replaces it on every delta. Without this, an\n // assistant message or tool call appended mid-run never reaches the list.\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on message content, see messagesKey\n }, [messagesKey, isRunning]);\n\n // Id of the trailing row. renderItem needs \"is this the last row?\" to place\n // the streaming indicator; deriving it here keeps that a named scalar instead\n // of renderItem closing over `listItems` and index-reading its tail.\n const lastItemId = useMemo(\n () => listItems[listItems.length - 1]?.id,\n [listItems],\n );\n\n // extraData defeats FlatList's PureComponent shallow-compare for the values\n // renderItem CLOSES OVER, as opposed to the ones it receives per row. Those\n // are exactly the four below, and they mirror renderItem's dependency array —\n // keep the two in sync. `listItems` is deliberately absent: renderItem's only\n // read of it is the tail id, now passed as `lastItemId`, and the array itself\n // is already the `data` prop, which invalidates cells on its own (every\n // rebuild allocates fresh item objects, so each cell's `item` prop differs).\n const extraData = useMemo(\n () => ({ isRunning, lastItemId, renderToolCall, toolMessages }),\n [isRunning, lastItemId, renderToolCall, toolMessages],\n );\n\n // The send side lives in core: it builds the message, waits for the run in\n // flight, and runs the agent. A failed run also shows under the list.\n const agentRef = useRef(agent);\n const inputTextRef = useRef(inputText);\n useLayoutEffect(() => {\n agentRef.current = agent;\n inputTextRef.current = inputText;\n });\n const [submitter] = useState(() =>\n ɵcreateChatSubmitter({\n core: withRunErrorReporting(copilotkit, setError),\n getAgent: () => agentRef.current,\n input: {\n get: () => inputTextRef.current,\n set: (value) => {\n inputTextRef.current = value;\n setInputText(value);\n },\n },\n }),\n );\n useEffect(() => () => submitter.showNotice(null), [submitter]);\n\n // Send from the input field\n const handleSend = useCallback(() => {\n const text = inputText.trim();\n if (!text) return;\n setError(null);\n onSendMessage?.(text);\n void submitter.submit(text);\n }, [inputText, onSendMessage, submitter]);\n\n // Handle suggestion pill press. Leaves the typed text alone.\n const handleSuggestion = useCallback(\n (text: string) => {\n setError(null);\n onSendMessage?.(text);\n void submitter.selectSuggestion({ message: text, isLoading: false });\n },\n [onSendMessage, submitter],\n );\n\n // Auto-scroll when content changes\n const handleContentSizeChange = useCallback(() => {\n flatListRef.current?.scrollToEnd({ animated: true });\n }, []);\n\n // Render a single list item\n const renderItem = useCallback(\n ({ item }: ListRenderItemInfo<ChatListItem>) => {\n if (item.type === \"user\") {\n return <UserMessage content={item.content ?? \"\"} />;\n }\n\n if (item.type === \"assistant\") {\n return (\n <AssistantMessage\n content={item.content ?? \"\"}\n isLoading={isRunning && item.id === lastItemId}\n />\n );\n }\n\n if (item.type === \"tool-call\" && item.toolCalls) {\n const tc = item.toolCalls[0];\n // Partial-parses streaming args, resolves the renderer (exact name ->\n // agent-scoped -> wildcard \"*\") and derives status — all in react-core,\n // shared with web. Returns ReactElement | null, which is what\n // renderItem requires.\n const rendered = renderToolCall({\n toolCall: tc,\n toolMessage: toolMessages.get(tc.id),\n });\n if (rendered) return <>{rendered}</>;\n\n // Subtle indicator for unregistered tool calls\n return (\n <View style={styles.toolCallIndicator}>\n <Text style={styles.toolCallText}>Called: {tc.function.name}</Text>\n </View>\n );\n }\n\n if (item.type === \"loading\") {\n return <AssistantMessage content=\"\" isLoading />;\n }\n\n return null;\n },\n [isRunning, lastItemId, renderToolCall, toolMessages],\n );\n\n const keyExtractor = useCallback((item: ChatListItem) => item.id, []);\n\n // Empty state component\n const emptyComponent = useMemo(\n () => (\n <View style={styles.emptyState}>\n <Text style={styles.emptyTitle}>{emptyStateTitle}</Text>\n <Text style={styles.emptySubtitle}>{emptyStateSubtitle}</Text>\n {initialMessages.map((suggestion, i) => (\n <Pressable\n key={`suggestion-${i}`}\n style={styles.suggestionPill}\n onPress={() => handleSuggestion(suggestion)}\n >\n <Text style={styles.suggestionText}>{suggestion}</Text>\n </Pressable>\n ))}\n </View>\n ),\n [emptyStateTitle, emptyStateSubtitle, initialMessages, handleSuggestion],\n );\n\n const sendDisabled = !inputText.trim() || isRunning;\n\n const content = (\n <>\n {showHeader && (\n <View style={styles.header}>\n <Text style={styles.headerTitle}>{headerTitle}</Text>\n </View>\n )}\n\n <FlatListComponent\n ref={flatListRef}\n data={listItems}\n renderItem={renderItem}\n keyExtractor={keyExtractor}\n extraData={extraData}\n contentContainerStyle={[styles.messageList, messageContainerStyle]}\n onContentSizeChange={handleContentSizeChange}\n ListEmptyComponent={emptyComponent}\n ListFooterComponent={interruptElement}\n />\n\n {error && (\n <View style={styles.errorContainer} testID=\"error-message\">\n <Text style={styles.errorText}>{error}</Text>\n </View>\n )}\n\n <View style={[styles.inputContainer, inputContainerStyle]}>\n <TextInput\n style={styles.input}\n value={inputText}\n onChangeText={setInputText}\n placeholder={placeholder}\n placeholderTextColor=\"#999\"\n multiline\n // The input grows with its text up to maxHeight. react-native-web\n // needs a row count, or the browser draws two rows, so start at one\n // row there. On Android a row count pins the height, so set none.\n numberOfLines={Platform.OS === \"web\" ? 1 : undefined}\n returnKeyType=\"send\"\n // A multiline input inserts a newline on Return unless told to\n // submit. React Native 0.73+ reads submitBehavior; older versions and\n // react-native-web read blurOnSubmit. On the web, Shift+Enter still\n // inserts a newline.\n submitBehavior=\"submit\"\n blurOnSubmit\n onSubmitEditing={handleSend}\n />\n <TouchableOpacity\n style={[styles.sendButton, sendDisabled && styles.sendButtonDisabled]}\n onPress={handleSend}\n disabled={sendDisabled}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Send message\"\n accessibilityState={{ disabled: sendDisabled }}\n testID=\"send-button\"\n >\n <Text style={styles.sendButtonIcon}>{\"↑\"}</Text>\n </TouchableOpacity>\n </View>\n </>\n );\n\n if (disableKeyboardAvoiding) {\n return <View style={[styles.container, style]}>{content}</View>;\n }\n\n return (\n <KeyboardAvoidingView\n style={[styles.container, style]}\n behavior={Platform.OS === \"ios\" ? \"padding\" : \"height\"}\n keyboardVerticalOffset={0}\n >\n {content}\n </KeyboardAvoidingView>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n backgroundColor: \"#FFFFFF\",\n },\n header: {\n height: 56,\n justifyContent: \"center\",\n alignItems: \"center\",\n borderBottomWidth: StyleSheet.hairlineWidth,\n borderBottomColor: \"#E0E0E0\",\n backgroundColor: \"#FFFFFF\",\n },\n headerTitle: {\n fontSize: 17,\n fontWeight: \"600\",\n color: \"#1A1A1A\",\n },\n messageList: {\n paddingHorizontal: 16,\n flexGrow: 1,\n },\n inputContainer: {\n flexDirection: \"row\",\n alignItems: \"flex-end\",\n paddingHorizontal: 8,\n paddingVertical: 8,\n borderTopWidth: StyleSheet.hairlineWidth,\n borderTopColor: \"#E0E0E0\",\n backgroundColor: \"#FFFFFF\",\n },\n input: {\n flex: 1,\n backgroundColor: \"#F5F5F5\",\n borderRadius: 20,\n paddingHorizontal: 12,\n paddingVertical: 8,\n fontSize: 15,\n maxHeight: 100,\n color: \"#1A1A1A\",\n },\n sendButton: {\n width: 36,\n height: 36,\n borderRadius: 18,\n backgroundColor: \"#0066CC\",\n justifyContent: \"center\",\n alignItems: \"center\",\n marginLeft: 8,\n },\n sendButtonDisabled: {\n opacity: 0.4,\n },\n sendButtonIcon: {\n color: \"#FFFFFF\",\n fontSize: 18,\n fontWeight: \"700\",\n },\n emptyState: {\n flex: 1,\n justifyContent: \"center\",\n alignItems: \"center\",\n paddingTop: 100,\n gap: 12,\n },\n emptyTitle: {\n fontSize: 22,\n fontWeight: \"700\",\n color: \"#1A1A1A\",\n marginBottom: 4,\n },\n emptySubtitle: {\n fontSize: 15,\n color: \"#666666\",\n marginBottom: 16,\n },\n suggestionPill: {\n backgroundColor: \"#E8F0FE\",\n borderRadius: 20,\n paddingHorizontal: 16,\n paddingVertical: 10,\n },\n suggestionText: {\n color: \"#0066CC\",\n fontWeight: \"600\",\n fontSize: 14,\n },\n toolCallIndicator: {\n alignSelf: \"flex-start\",\n backgroundColor: \"#F0F0F0\",\n borderRadius: 12,\n paddingHorizontal: 12,\n paddingVertical: 6,\n marginBottom: 8,\n },\n toolCallText: {\n fontSize: 12,\n color: \"#999999\",\n fontStyle: \"italic\",\n },\n errorContainer: {\n backgroundColor: \"#FEE2E2\",\n paddingHorizontal: 12,\n paddingVertical: 8,\n marginHorizontal: 8,\n borderRadius: 8,\n },\n errorText: {\n color: \"#DC2626\",\n fontSize: 13,\n },\n});\n","/**\n * CopilotModal — a bottom-sheet chat overlay for React Native.\n *\n * Mobile equivalent of CopilotPopup on web. Wraps CopilotChat inside\n * @gorhom/bottom-sheet so the chat can slide up over any screen.\n */\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from \"react\";\nimport { StyleSheet, View } from \"react-native\";\nimport BottomSheet, {\n BottomSheetBackdrop,\n BottomSheetFlatList,\n} from \"@gorhom/bottom-sheet\";\nimport type { BottomSheetBackdropProps } from \"@gorhom/bottom-sheet\";\nimport { CopilotChat } from \"./CopilotChat\";\nimport type { CopilotChatProps } from \"./CopilotChat\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface CopilotModalProps {\n /** Controlled visibility — when true the sheet opens, when false it closes. */\n visible?: boolean;\n\n /** Called when the sheet is dismissed (via backdrop tap, swipe-down, or close()). */\n onDismiss?: () => void;\n\n /**\n * Bottom-sheet snap points.\n *\n * The default is one snap point because the message input is pinned to the\n * bottom of the chat. The chat always fills the sheet at its highest snap\n * point, so a lower snap point pushes the input below the screen.\n * @default ['90%']\n */\n snapPoints?: (string | number)[];\n\n /**\n * Which snap-point index to open at.\n * @default 0\n */\n initialSnapIndex?: number;\n\n /**\n * Whether closing the sheet fires onDismiss.\n * @default true\n */\n enableDismissOnClose?: boolean;\n\n /**\n * Backdrop opacity when the sheet is open.\n * @default 0.5\n */\n backdropOpacity?: number;\n\n // -- Pass-through to CopilotChat ------------------------------------------\n\n /** Which agent to connect to. */\n agentName?: string;\n\n /** Input placeholder text. */\n placeholder?: string;\n\n /** Seed messages shown on first render. */\n initialMessages?: string[];\n\n /** Title shown in the CopilotChat header area. */\n headerTitle?: string;\n}\n\n/** Imperative handle exposed via ref. */\nexport interface CopilotModalRef {\n /** Programmatically open the bottom sheet. */\n open: () => void;\n /** Programmatically close the bottom sheet. */\n close: () => void;\n}\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\nexport const CopilotModal = forwardRef<CopilotModalRef, CopilotModalProps>(\n function CopilotModal(\n {\n visible,\n onDismiss,\n snapPoints: snapPointsProp,\n initialSnapIndex = 0,\n enableDismissOnClose = true,\n backdropOpacity = 0.5,\n agentName,\n placeholder,\n initialMessages,\n headerTitle,\n },\n ref,\n ) {\n const bottomSheetRef = useRef<BottomSheet>(null);\n\n // Stable snap-points array\n const snapPoints = useMemo(\n () => snapPointsProp ?? [\"90%\"],\n [snapPointsProp],\n );\n\n // ── Imperative API ────────────────────────────────────────────────────\n useImperativeHandle(\n ref,\n () => ({\n open() {\n bottomSheetRef.current?.snapToIndex(initialSnapIndex);\n },\n close() {\n bottomSheetRef.current?.close();\n },\n }),\n [initialSnapIndex],\n );\n\n // ── Controlled visibility ─────────────────────────────────────────────\n useEffect(() => {\n if (visible === undefined) return;\n if (visible) {\n bottomSheetRef.current?.snapToIndex(initialSnapIndex);\n } else {\n bottomSheetRef.current?.close();\n }\n }, [visible, initialSnapIndex]);\n\n // ── Backdrop renderer ─────────────────────────────────────────────────\n const renderBackdrop = useCallback(\n (props: BottomSheetBackdropProps) => (\n <BottomSheetBackdrop\n {...props}\n disappearsOnIndex={-1}\n appearsOnIndex={0}\n opacity={backdropOpacity}\n pressBehavior=\"close\"\n />\n ),\n [backdropOpacity],\n );\n\n // ── Sheet close handler ───────────────────────────────────────────────\n const handleClose = useCallback(() => {\n if (enableDismissOnClose) {\n onDismiss?.();\n }\n }, [enableDismissOnClose, onDismiss]);\n\n // ── Build CopilotChat props ───────────────────────────────────────────\n const chatProps = useMemo(() => {\n const props: Partial<CopilotChatProps> = {};\n if (agentName !== undefined) props.agentName = agentName;\n if (placeholder !== undefined) props.placeholder = placeholder;\n if (initialMessages !== undefined)\n props.initialMessages = initialMessages;\n if (headerTitle !== undefined) props.headerTitle = headerTitle;\n return props;\n }, [agentName, placeholder, initialMessages, headerTitle]);\n\n return (\n <BottomSheet\n ref={bottomSheetRef}\n index={-1}\n snapPoints={snapPoints}\n // The chat fills the sheet (flex: 1), so the sheet cannot take its\n // height from the content. Size it from the snap points instead.\n enableDynamicSizing={false}\n enablePanDownToClose\n backdropComponent={renderBackdrop}\n onClose={handleClose}\n keyboardBehavior=\"interactive\"\n keyboardBlurBehavior=\"restore\"\n backgroundStyle={styles.sheetBackground}\n handleIndicatorStyle={styles.handleIndicator}\n >\n {/* A plain View: BottomSheetView is absolutely positioned with no\n bottom edge, so flex: 1 cannot make it fill the sheet. */}\n <View style={styles.contentContainer}>\n <CopilotChat\n {...chatProps}\n FlatListComponent={BottomSheetFlatList}\n disableKeyboardAvoiding\n />\n </View>\n </BottomSheet>\n );\n },\n);\n\n// ---------------------------------------------------------------------------\n// Styles\n// ---------------------------------------------------------------------------\n\nconst styles = StyleSheet.create({\n sheetBackground: {\n backgroundColor: \"#FFFFFF\",\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n },\n handleIndicator: {\n width: 40,\n height: 4,\n backgroundColor: \"#DDDDDD\",\n },\n contentContainer: {\n flex: 1,\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAYA,MAAM,WAAW;AACjB,MAAM,cAAc;AACpB,MAAM,qBAAqB;;;;;;;AAQ3B,SAAgB,gBAAgB,EAAE,SAA+B;CAC/D,MAAM,CAAC,kCAAuB,IAAIA,sBAAS,MAAM,EAAE,CAAC;CACpD,MAAM,CAAC,kCAAuB,IAAIA,sBAAS,MAAM,EAAE,CAAC;CACpD,MAAM,CAAC,kCAAuB,IAAIA,sBAAS,MAAM,EAAE,CAAC;AAEpD,4BAAgB;EACd,MAAM,eAAe,KAAqB,UACxCA,sBAAS,SAAS,CAChBA,sBAAS,MAAM,MAAM,EACrBA,sBAAS,KACPA,sBAAS,SAAS,CAChBA,sBAAS,OAAO,KAAK;GACnB,SAAS;GACT,UAAU;GACV,iBAAiB;GAClB,CAAC,EACFA,sBAAS,OAAO,KAAK;GACnB,SAAS;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ACtB,OAAM,kBAAkB;AAC1B,MAAI,gBAAgB,OAAW,OAAM,cAAc;AACnD,SAAO;IACN;EAAC;EAAW;EAAa;EAAiB;EAAY,CAAC;AAE1D,QACE,2CAACC;EACC,KAAK;EACL,OAAO;EACK;EAGZ,qBAAqB;EACrB;EACA,mBAAmB;EACnB,SAAS;EACT,kBAAiB;EACjB,sBAAqB;EACrB,iBAAiB,OAAO;EACxB,sBAAsB,OAAO;YAI7B,2CAACC;GAAK,OAAO,OAAO;aAClB,2CAAC;IACC,GAAI;IACJ,mBAAmBC;IACnB;KACA;IACG;GACK;EAGnB;AAMD,MAAM,SAASC,wBAAW,OAAO;CAC/B,iBAAiB;EACf,iBAAiB;EACjB,qBAAqB;EACrB,sBAAsB;EACvB;CACD,iBAAiB;EACf,OAAO;EACP,QAAQ;EACR,iBAAiB;EAClB;CACD,kBAAkB,EAChB,MAAM,GACP;CACF,CAAC"}
@@ -67,7 +67,11 @@ interface CopilotModalProps {
67
67
  onDismiss?: () => void;
68
68
  /**
69
69
  * Bottom-sheet snap points.
70
- * @default ['50%', '90%']
70
+ *
71
+ * The default is one snap point because the message input is pinned to the
72
+ * bottom of the chat. The chat always fills the sheet at its highest snap
73
+ * point, so a lower snap point pushes the input below the screen.
74
+ * @default ['90%']
71
75
  */
72
76
  snapPoints?: (string | number)[];
73
77
  /**
@@ -67,7 +67,11 @@ interface CopilotModalProps {
67
67
  onDismiss?: () => void;
68
68
  /**
69
69
  * Bottom-sheet snap points.
70
- * @default ['50%', '90%']
70
+ *
71
+ * The default is one snap point because the message input is pinned to the
72
+ * bottom of the chat. The chat always fills the sheet at its highest snap
73
+ * point, so a lower snap point pushes the input below the screen.
74
+ * @default ['90%']
71
75
  */
72
76
  snapPoints?: (string | number)[];
73
77
  /**
@@ -7,7 +7,7 @@ import { useAgent, useRenderToolCall } from "@copilotkit/react-core/headless";
7
7
  import { ɵcreateChatSubmitter, ɵgetToolResults, ɵmessagesFingerprint } from "@copilotkit/core";
8
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
9
  import { Animated, FlatList, KeyboardAvoidingView, Platform, Pressable, StyleSheet, Text, TextInput, TouchableOpacity, View } from "react-native";
10
- import BottomSheet, { BottomSheetBackdrop, BottomSheetFlatList, BottomSheetView } from "@gorhom/bottom-sheet";
10
+ import BottomSheet, { BottomSheetBackdrop, BottomSheetFlatList } from "@gorhom/bottom-sheet";
11
11
 
12
12
  //#region src/components/messages/TypingIndicator.tsx
13
13
  const DOT_SIZE = 6;
@@ -447,7 +447,7 @@ function CopilotChat({ agentName = "default", placeholder = "Type a message...",
447
447
  placeholder,
448
448
  placeholderTextColor: "#999",
449
449
  multiline: true,
450
- numberOfLines: 4,
450
+ numberOfLines: Platform.OS === "web" ? 1 : void 0,
451
451
  returnKeyType: "send",
452
452
  submitBehavior: "submit",
453
453
  blurOnSubmit: true,
@@ -599,7 +599,7 @@ const styles$1 = StyleSheet.create({
599
599
  */
600
600
  const CopilotModal = forwardRef(function CopilotModal({ visible, onDismiss, snapPoints: snapPointsProp, initialSnapIndex = 0, enableDismissOnClose = true, backdropOpacity = .5, agentName, placeholder, initialMessages, headerTitle }, ref) {
601
601
  const bottomSheetRef = useRef(null);
602
- const snapPoints = useMemo(() => snapPointsProp ?? ["50%", "90%"], [snapPointsProp]);
602
+ const snapPoints = useMemo(() => snapPointsProp ?? ["90%"], [snapPointsProp]);
603
603
  useImperativeHandle(ref, () => ({
604
604
  open() {
605
605
  bottomSheetRef.current?.snapToIndex(initialSnapIndex);
@@ -640,6 +640,7 @@ const CopilotModal = forwardRef(function CopilotModal({ visible, onDismiss, snap
640
640
  ref: bottomSheetRef,
641
641
  index: -1,
642
642
  snapPoints,
643
+ enableDynamicSizing: false,
643
644
  enablePanDownToClose: true,
644
645
  backdropComponent: renderBackdrop,
645
646
  onClose: handleClose,
@@ -647,7 +648,7 @@ const CopilotModal = forwardRef(function CopilotModal({ visible, onDismiss, snap
647
648
  keyboardBlurBehavior: "restore",
648
649
  backgroundStyle: styles.sheetBackground,
649
650
  handleIndicatorStyle: styles.handleIndicator,
650
- children: /* @__PURE__ */ jsx(BottomSheetView, {
651
+ children: /* @__PURE__ */ jsx(View, {
651
652
  style: styles.contentContainer,
652
653
  children: /* @__PURE__ */ jsx(CopilotChat, {
653
654
  ...chatProps,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["styles","TIMESTAMP_COLOR","styles","styles","styles"],"sources":["../../src/components/messages/TypingIndicator.tsx","../../src/components/messages/utils.ts","../../src/components/messages/AssistantMessage.tsx","../../src/components/messages/UserMessage.tsx","../../src/components/CopilotChat.tsx","../../src/components/CopilotModal.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { View, Animated, StyleSheet } from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\n\n/**\n * Props for the TypingIndicator component.\n */\nexport interface TypingIndicatorProps {\n /** Optional style override for the container */\n style?: ViewStyle;\n}\n\nconst DOT_SIZE = 6;\nconst DOT_SPACING = 4;\nconst ANIMATION_DURATION = 400;\n\n/**\n * Three animated dots that pulse in sequence, suitable for embedding\n * inside an AssistantMessage to indicate the AI is still generating.\n *\n * Uses React Native's built-in `Animated` API (no Reanimated dependency).\n */\nexport function TypingIndicator({ style }: TypingIndicatorProps) {\n const [dot1] = useState(() => new Animated.Value(0));\n const [dot2] = useState(() => new Animated.Value(0));\n const [dot3] = useState(() => new Animated.Value(0));\n\n useEffect(() => {\n const createPulse = (dot: Animated.Value, delay: number) =>\n Animated.sequence([\n Animated.delay(delay),\n Animated.loop(\n Animated.sequence([\n Animated.timing(dot, {\n toValue: 1,\n duration: ANIMATION_DURATION,\n useNativeDriver: true,\n }),\n Animated.timing(dot, {\n toValue: 0,\n duration: ANIMATION_DURATION,\n useNativeDriver: true,\n }),\n ]),\n ),\n ]);\n\n const animation = Animated.parallel([\n createPulse(dot1, 0),\n createPulse(dot2, ANIMATION_DURATION * 0.33),\n createPulse(dot3, ANIMATION_DURATION * 0.66),\n ]);\n\n animation.start();\n\n return () => {\n animation.stop();\n };\n }, [dot1, dot2, dot3]);\n\n const dotStyle = (animatedValue: Animated.Value) => ({\n ...styles.dot,\n opacity: animatedValue.interpolate({\n inputRange: [0, 1],\n outputRange: [0.3, 1],\n }),\n transform: [\n {\n scale: animatedValue.interpolate({\n inputRange: [0, 1],\n outputRange: [0.8, 1.2],\n }),\n },\n ],\n });\n\n return (\n <View\n testID=\"copilot-loading-cursor\"\n style={[styles.container, style]}\n accessibilityLabel=\"Typing indicator\"\n accessibilityRole=\"text\"\n >\n <Animated.View style={dotStyle(dot1)} />\n <Animated.View style={dotStyle(dot2)} />\n <Animated.View style={dotStyle(dot3)} />\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flexDirection: \"row\",\n alignItems: \"center\",\n paddingVertical: 4,\n paddingHorizontal: 2,\n },\n dot: {\n width: DOT_SIZE,\n height: DOT_SIZE,\n borderRadius: DOT_SIZE / 2,\n backgroundColor: \"#999999\",\n marginHorizontal: DOT_SPACING / 2,\n },\n});\n","/**\n * Format a Date as a 12-hour time string (e.g. \"2:05 PM\").\n */\nexport function formatTimestamp(date: Date): string {\n const hours = date.getHours();\n const minutes = date.getMinutes();\n const ampm = hours >= 12 ? \"PM\" : \"AM\";\n const displayHours = hours % 12 || 12;\n const displayMinutes = minutes.toString().padStart(2, \"0\");\n return `${displayHours}:${displayMinutes} ${ampm}`;\n}\n","import React from \"react\";\nimport { View, Text, StyleSheet } from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\nimport { CopilotMarkdown } from \"../Markdown\";\nimport {\n useMarkdownRenderer,\n isNativeComponentRenderer,\n} from \"../MarkdownRendererContext\";\nimport { TypingIndicator } from \"./TypingIndicator\";\nimport { formatTimestamp } from \"./utils\";\n\n// ─── Colors ──────────────────────────────────────────────────────────────────\nconst ASSISTANT_BUBBLE_BG = \"#F0F0F0\";\nconst TIMESTAMP_COLOR = \"#999999\";\n\n/**\n * Props for the AssistantMessage component.\n */\nexport interface AssistantMessageProps {\n /** Markdown content to render inside the bubble */\n content: string;\n /** When true, shows a typing indicator below any content */\n isLoading?: boolean;\n /** Optional timestamp displayed below the bubble */\n timestamp?: Date;\n /** Optional style override for the outer container */\n style?: ViewStyle;\n}\n\n/**\n * Left-aligned chat bubble for AI assistant responses.\n *\n * Renders markdown content via `CopilotMarkdown` and shows an animated\n * typing indicator when `isLoading` is true.\n */\nexport function AssistantMessage({\n content,\n isLoading = false,\n timestamp,\n style,\n}: AssistantMessageProps) {\n // Honor a provider-level markdown renderer (CopilotKitProvider's\n // `markdownRenderer` prop), falling back to the built-in CopilotMarkdown.\n // This is the React Native arm of the slot -> provider -> built-in\n // resolution order documented in the migration guide.\n const provided = useMarkdownRenderer();\n return (\n <View style={[styles.container, style]}>\n <View style={styles.bubble}>\n {content ? (\n isNativeComponentRenderer(provided) ? (\n React.createElement(provided, { content, isStreaming: isLoading })\n ) : provided ? (\n <CopilotMarkdown\n content={content}\n style={provided.style}\n streamingAnimation={provided.animate}\n />\n ) : (\n <CopilotMarkdown content={content} />\n )\n ) : null}\n {isLoading ? <TypingIndicator /> : null}\n </View>\n {timestamp && (\n <Text style={styles.timestamp}>{formatTimestamp(timestamp)}</Text>\n )}\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n alignItems: \"flex-start\",\n marginVertical: 4,\n paddingHorizontal: 12,\n },\n bubble: {\n backgroundColor: ASSISTANT_BUBBLE_BG,\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n borderBottomRightRadius: 16,\n borderBottomLeftRadius: 4,\n paddingHorizontal: 12,\n paddingVertical: 8,\n maxWidth: \"80%\",\n },\n timestamp: {\n color: TIMESTAMP_COLOR,\n fontSize: 11,\n marginTop: 2,\n marginLeft: 4,\n },\n});\n","import React from \"react\";\nimport { View, Text, StyleSheet, type ViewStyle } from \"react-native\";\nimport { formatTimestamp } from \"./utils\";\n\n// ─── Colors ──────────────────────────────────────────────────────────────────\nconst USER_BUBBLE_BG = \"#0066CC\";\nconst USER_TEXT_COLOR = \"#FFFFFF\";\nconst TIMESTAMP_COLOR = \"#999999\";\n\n/**\n * Props for the UserMessage component.\n */\nexport interface UserMessageProps {\n /** Plain text content to display */\n content: string;\n /** Optional timestamp displayed below the bubble */\n timestamp?: Date;\n /** Optional style override for the outer container */\n style?: ViewStyle;\n}\n\n/**\n * Right-aligned chat bubble for user messages.\n *\n * Renders plain text (no markdown) with a primary-color background\n * and white text. Optionally displays a subtle timestamp below.\n */\nexport function UserMessage({ content, timestamp, style }: UserMessageProps) {\n return (\n <View style={[styles.container, style]}>\n <View style={styles.bubble}>\n <Text style={styles.text}>{content}</Text>\n </View>\n {timestamp && (\n <Text style={styles.timestamp}>{formatTimestamp(timestamp)}</Text>\n )}\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n alignItems: \"flex-end\",\n marginVertical: 4,\n paddingHorizontal: 12,\n },\n bubble: {\n backgroundColor: USER_BUBBLE_BG,\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n borderBottomLeftRadius: 16,\n borderBottomRightRadius: 4,\n paddingHorizontal: 12,\n paddingVertical: 8,\n maxWidth: \"80%\",\n },\n text: {\n color: USER_TEXT_COLOR,\n fontSize: 16,\n lineHeight: 22,\n },\n timestamp: {\n color: TIMESTAMP_COLOR,\n fontSize: 11,\n marginTop: 2,\n marginRight: 4,\n },\n});\n","import React, {\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n FlatList,\n KeyboardAvoidingView,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n TextInput,\n TouchableOpacity,\n View,\n} from \"react-native\";\nimport type { ListRenderItemInfo, ViewStyle } from \"react-native\";\nimport { useAgent, useRenderToolCall } from \"@copilotkit/react-core/headless\";\nimport { useCopilotKit } from \"@copilotkit/react-core/context\";\nimport {\n ɵcreateChatSubmitter,\n ɵgetToolResults,\n ɵmessagesFingerprint,\n} from \"@copilotkit/core\";\nimport type { CopilotKitCore } from \"@copilotkit/core\";\nimport { AssistantMessage } from \"./messages/AssistantMessage\";\nimport { UserMessage } from \"./messages/UserMessage\";\nimport type { ToolMessage } from \"@ag-ui/client\";\n\n/** Shape of an assistant message with optional tool calls. */\ninterface AssistantMessageShape {\n id: string;\n role: \"assistant\";\n content?: string;\n toolCalls?: Array<{\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n }>;\n}\n\nexport interface CopilotChatProps {\n /** Agent ID to connect to. Defaults to 'default'. */\n agentName?: string;\n /** Placeholder text for the input field. */\n placeholder?: string;\n /** Suggestion pills shown in the empty state. */\n initialMessages?: string[];\n /** Title shown when there are no messages. */\n emptyStateTitle?: string;\n /** Subtitle shown when there are no messages. */\n emptyStateSubtitle?: string;\n /** Title for the optional header bar. */\n headerTitle?: string;\n /** Whether to show the header bar. Defaults to true. */\n showHeader?: boolean;\n /** Style override for the outermost container. */\n style?: ViewStyle;\n /** Style override for the message list container. */\n messageContainerStyle?: ViewStyle;\n /** Style override for the input bar container. */\n inputContainerStyle?: ViewStyle;\n /** Callback fired when the user sends a message. */\n onSendMessage?: (text: string) => void;\n /** Custom FlatList component (e.g. BottomSheetFlatList for use inside a bottom sheet). */\n FlatListComponent?: React.ComponentType<any>;\n /** When true, skip the KeyboardAvoidingView wrapper (useful when a parent already handles keyboard). */\n disableKeyboardAvoiding?: boolean;\n}\n\ninterface ChatListItem {\n id: string;\n type: \"user\" | \"assistant\" | \"tool-call\" | \"loading\";\n content?: string;\n toolCalls?: Array<{\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n }>;\n}\n\n/**\n * The core as the chat's submitter takes it, with a failed run also passed to\n * `onRunError` so the chat can show it. The submitter logs the failure itself.\n */\nfunction withRunErrorReporting(\n core: CopilotKitCore,\n onRunError: (message: string) => void,\n): Parameters<typeof ɵcreateChatSubmitter>[0][\"core\"] {\n return {\n runAgent: async (params) => {\n try {\n return await core.runAgent(params);\n } catch (err) {\n onRunError(\n err instanceof Error ? err.message : \"An unexpected error occurred\",\n );\n throw err;\n }\n },\n stopAgent: (params) => core.stopAgent(params),\n // This chat does not transcribe, but the submitter's core type covers it.\n get runtimeUrl() {\n return core.runtimeUrl;\n },\n get runtimeTransport() {\n return core.runtimeTransport;\n },\n get credentials() {\n return core.credentials;\n },\n resolveHeaders: () => core.resolveHeaders(),\n };\n}\n\n/**\n * Full-screen chat UI component for React Native.\n *\n * Connects to a CopilotKit agent via `useAgent` and renders messages\n * using platform-appropriate AssistantMessage / UserMessage components.\n *\n * Usage:\n * ```tsx\n * <CopilotChat agentName=\"my-agent\" headerTitle=\"Assistant\" />\n * ```\n */\nexport function CopilotChat({\n agentName = \"default\",\n placeholder = \"Type a message...\",\n initialMessages = [],\n emptyStateTitle = \"How can I help?\",\n emptyStateSubtitle = \"Ask me anything or try a suggestion below.\",\n headerTitle = \"Chat\",\n showHeader = true,\n style,\n messageContainerStyle,\n inputContainerStyle,\n onSendMessage,\n FlatListComponent = FlatList,\n disableKeyboardAvoiding = false,\n}: CopilotChatProps) {\n const [inputText, setInputText] = useState(\"\");\n const [error, setError] = useState<string | null>(null);\n const flatListRef = useRef<FlatList>(null);\n\n const { copilotkit } = useCopilotKit();\n const { agent } = useAgent({ agentId: agentName });\n\n const messages = agent.messages ?? [];\n const isRunning = agent.isRunning;\n\n const renderToolCall = useRenderToolCall();\n\n // useInterrupt publishes its element to core unless renderInChat is false.\n // Draw it after the last message, as the web message view does.\n const [interruptElement, setInterruptElement] =\n useState<React.ReactElement | null>(null);\n useEffect(() => {\n setInterruptElement(copilotkit.interruptElement);\n const subscription = copilotkit.subscribe({\n onInterruptElementChanged: ({ interruptElement: element }) => {\n setInterruptElement(element);\n },\n });\n return () => subscription.unsubscribe();\n }, [copilotkit]);\n\n // Recomputed every render: cheap, and the only honest dependency for the\n // message-derived memos below. The array reference does not track content\n // in either direction: core inserts tool results with an in-place `splice`,\n // `addMessage` pushes, and the AG-UI apply pipeline replaces the array on\n // every streamed delta.\n const messagesKey = ɵmessagesFingerprint(messages);\n\n // toolCallId -> tool result message, so a renderer reports \"complete\" with\n // its `result`.\n const toolMessages = useMemo(() => {\n const byId = new Map<string, ToolMessage>();\n for (const [toolCallId, message] of ɵgetToolResults(messages)) {\n // A copy, so the tool-call renderer's memo sees content that was\n // replaced in place on the same message. Core turns the content into\n // the renderer's `result` string.\n byId.set(toolCallId, { ...message });\n }\n return byId;\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on message content, see messagesKey\n }, [messagesKey]);\n\n // Build flat list items from messages\n const listItems: ChatListItem[] = useMemo(() => {\n const items: ChatListItem[] = [];\n\n for (const msg of messages) {\n if (msg.role === \"user\") {\n items.push({\n id: msg.id,\n type: \"user\",\n content: typeof msg.content === \"string\" ? msg.content : \"\",\n });\n } else if (msg.role === \"assistant\") {\n const assistantMsg = msg as AssistantMessageShape;\n // Add text content if present\n if (assistantMsg.content) {\n items.push({\n id: msg.id,\n type: \"assistant\",\n content: assistantMsg.content,\n });\n }\n // Add tool calls if present\n if (assistantMsg.toolCalls && assistantMsg.toolCalls.length > 0) {\n for (const tc of assistantMsg.toolCalls) {\n items.push({\n id: `${msg.id}-tc-${tc.id}`,\n type: \"tool-call\",\n toolCalls: [tc],\n });\n }\n }\n }\n }\n\n // Show loading indicator when agent is running and the last message\n // is not already the assistant streaming\n if (isRunning) {\n const lastItem = items[items.length - 1];\n if (!lastItem || lastItem.type !== \"assistant\") {\n items.push({ id: \"__loading__\", type: \"loading\" });\n }\n }\n\n return items;\n // Same reasoning as `toolMessages`: keyed on message CONTENT, because the\n // array reference does not track content in either direction — core's\n // in-place `splice` and `addMessage`'s push leave it untouched, while the\n // AG-UI apply pipeline replaces it on every delta. Without this, an\n // assistant message or tool call appended mid-run never reaches the list.\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on message content, see messagesKey\n }, [messagesKey, isRunning]);\n\n // Id of the trailing row. renderItem needs \"is this the last row?\" to place\n // the streaming indicator; deriving it here keeps that a named scalar instead\n // of renderItem closing over `listItems` and index-reading its tail.\n const lastItemId = useMemo(\n () => listItems[listItems.length - 1]?.id,\n [listItems],\n );\n\n // extraData defeats FlatList's PureComponent shallow-compare for the values\n // renderItem CLOSES OVER, as opposed to the ones it receives per row. Those\n // are exactly the four below, and they mirror renderItem's dependency array —\n // keep the two in sync. `listItems` is deliberately absent: renderItem's only\n // read of it is the tail id, now passed as `lastItemId`, and the array itself\n // is already the `data` prop, which invalidates cells on its own (every\n // rebuild allocates fresh item objects, so each cell's `item` prop differs).\n const extraData = useMemo(\n () => ({ isRunning, lastItemId, renderToolCall, toolMessages }),\n [isRunning, lastItemId, renderToolCall, toolMessages],\n );\n\n // The send side lives in core: it builds the message, waits for the run in\n // flight, and runs the agent. A failed run also shows under the list.\n const agentRef = useRef(agent);\n const inputTextRef = useRef(inputText);\n useLayoutEffect(() => {\n agentRef.current = agent;\n inputTextRef.current = inputText;\n });\n const [submitter] = useState(() =>\n ɵcreateChatSubmitter({\n core: withRunErrorReporting(copilotkit, setError),\n getAgent: () => agentRef.current,\n input: {\n get: () => inputTextRef.current,\n set: (value) => {\n inputTextRef.current = value;\n setInputText(value);\n },\n },\n }),\n );\n useEffect(() => () => submitter.showNotice(null), [submitter]);\n\n // Send from the input field\n const handleSend = useCallback(() => {\n const text = inputText.trim();\n if (!text) return;\n setError(null);\n onSendMessage?.(text);\n void submitter.submit(text);\n }, [inputText, onSendMessage, submitter]);\n\n // Handle suggestion pill press. Leaves the typed text alone.\n const handleSuggestion = useCallback(\n (text: string) => {\n setError(null);\n onSendMessage?.(text);\n void submitter.selectSuggestion({ message: text, isLoading: false });\n },\n [onSendMessage, submitter],\n );\n\n // Auto-scroll when content changes\n const handleContentSizeChange = useCallback(() => {\n flatListRef.current?.scrollToEnd({ animated: true });\n }, []);\n\n // Render a single list item\n const renderItem = useCallback(\n ({ item }: ListRenderItemInfo<ChatListItem>) => {\n if (item.type === \"user\") {\n return <UserMessage content={item.content ?? \"\"} />;\n }\n\n if (item.type === \"assistant\") {\n return (\n <AssistantMessage\n content={item.content ?? \"\"}\n isLoading={isRunning && item.id === lastItemId}\n />\n );\n }\n\n if (item.type === \"tool-call\" && item.toolCalls) {\n const tc = item.toolCalls[0];\n // Partial-parses streaming args, resolves the renderer (exact name ->\n // agent-scoped -> wildcard \"*\") and derives status — all in react-core,\n // shared with web. Returns ReactElement | null, which is what\n // renderItem requires.\n const rendered = renderToolCall({\n toolCall: tc,\n toolMessage: toolMessages.get(tc.id),\n });\n if (rendered) return <>{rendered}</>;\n\n // Subtle indicator for unregistered tool calls\n return (\n <View style={styles.toolCallIndicator}>\n <Text style={styles.toolCallText}>Called: {tc.function.name}</Text>\n </View>\n );\n }\n\n if (item.type === \"loading\") {\n return <AssistantMessage content=\"\" isLoading />;\n }\n\n return null;\n },\n [isRunning, lastItemId, renderToolCall, toolMessages],\n );\n\n const keyExtractor = useCallback((item: ChatListItem) => item.id, []);\n\n // Empty state component\n const emptyComponent = useMemo(\n () => (\n <View style={styles.emptyState}>\n <Text style={styles.emptyTitle}>{emptyStateTitle}</Text>\n <Text style={styles.emptySubtitle}>{emptyStateSubtitle}</Text>\n {initialMessages.map((suggestion, i) => (\n <Pressable\n key={`suggestion-${i}`}\n style={styles.suggestionPill}\n onPress={() => handleSuggestion(suggestion)}\n >\n <Text style={styles.suggestionText}>{suggestion}</Text>\n </Pressable>\n ))}\n </View>\n ),\n [emptyStateTitle, emptyStateSubtitle, initialMessages, handleSuggestion],\n );\n\n const sendDisabled = !inputText.trim() || isRunning;\n\n const content = (\n <>\n {showHeader && (\n <View style={styles.header}>\n <Text style={styles.headerTitle}>{headerTitle}</Text>\n </View>\n )}\n\n <FlatListComponent\n ref={flatListRef}\n data={listItems}\n renderItem={renderItem}\n keyExtractor={keyExtractor}\n extraData={extraData}\n contentContainerStyle={[styles.messageList, messageContainerStyle]}\n onContentSizeChange={handleContentSizeChange}\n ListEmptyComponent={emptyComponent}\n ListFooterComponent={interruptElement}\n />\n\n {error && (\n <View style={styles.errorContainer} testID=\"error-message\">\n <Text style={styles.errorText}>{error}</Text>\n </View>\n )}\n\n <View style={[styles.inputContainer, inputContainerStyle]}>\n <TextInput\n style={styles.input}\n value={inputText}\n onChangeText={setInputText}\n placeholder={placeholder}\n placeholderTextColor=\"#999\"\n multiline\n numberOfLines={4}\n returnKeyType=\"send\"\n // A multiline input inserts a newline on Return unless told to\n // submit. React Native 0.73+ reads submitBehavior; older versions and\n // react-native-web read blurOnSubmit. On the web, Shift+Enter still\n // inserts a newline.\n submitBehavior=\"submit\"\n blurOnSubmit\n onSubmitEditing={handleSend}\n />\n <TouchableOpacity\n style={[styles.sendButton, sendDisabled && styles.sendButtonDisabled]}\n onPress={handleSend}\n disabled={sendDisabled}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Send message\"\n accessibilityState={{ disabled: sendDisabled }}\n testID=\"send-button\"\n >\n <Text style={styles.sendButtonIcon}>{\"↑\"}</Text>\n </TouchableOpacity>\n </View>\n </>\n );\n\n if (disableKeyboardAvoiding) {\n return <View style={[styles.container, style]}>{content}</View>;\n }\n\n return (\n <KeyboardAvoidingView\n style={[styles.container, style]}\n behavior={Platform.OS === \"ios\" ? \"padding\" : \"height\"}\n keyboardVerticalOffset={0}\n >\n {content}\n </KeyboardAvoidingView>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n backgroundColor: \"#FFFFFF\",\n },\n header: {\n height: 56,\n justifyContent: \"center\",\n alignItems: \"center\",\n borderBottomWidth: StyleSheet.hairlineWidth,\n borderBottomColor: \"#E0E0E0\",\n backgroundColor: \"#FFFFFF\",\n },\n headerTitle: {\n fontSize: 17,\n fontWeight: \"600\",\n color: \"#1A1A1A\",\n },\n messageList: {\n paddingHorizontal: 16,\n flexGrow: 1,\n },\n inputContainer: {\n flexDirection: \"row\",\n alignItems: \"flex-end\",\n paddingHorizontal: 8,\n paddingVertical: 8,\n borderTopWidth: StyleSheet.hairlineWidth,\n borderTopColor: \"#E0E0E0\",\n backgroundColor: \"#FFFFFF\",\n },\n input: {\n flex: 1,\n backgroundColor: \"#F5F5F5\",\n borderRadius: 20,\n paddingHorizontal: 12,\n paddingVertical: 8,\n fontSize: 15,\n maxHeight: 100,\n color: \"#1A1A1A\",\n },\n sendButton: {\n width: 36,\n height: 36,\n borderRadius: 18,\n backgroundColor: \"#0066CC\",\n justifyContent: \"center\",\n alignItems: \"center\",\n marginLeft: 8,\n },\n sendButtonDisabled: {\n opacity: 0.4,\n },\n sendButtonIcon: {\n color: \"#FFFFFF\",\n fontSize: 18,\n fontWeight: \"700\",\n },\n emptyState: {\n flex: 1,\n justifyContent: \"center\",\n alignItems: \"center\",\n paddingTop: 100,\n gap: 12,\n },\n emptyTitle: {\n fontSize: 22,\n fontWeight: \"700\",\n color: \"#1A1A1A\",\n marginBottom: 4,\n },\n emptySubtitle: {\n fontSize: 15,\n color: \"#666666\",\n marginBottom: 16,\n },\n suggestionPill: {\n backgroundColor: \"#E8F0FE\",\n borderRadius: 20,\n paddingHorizontal: 16,\n paddingVertical: 10,\n },\n suggestionText: {\n color: \"#0066CC\",\n fontWeight: \"600\",\n fontSize: 14,\n },\n toolCallIndicator: {\n alignSelf: \"flex-start\",\n backgroundColor: \"#F0F0F0\",\n borderRadius: 12,\n paddingHorizontal: 12,\n paddingVertical: 6,\n marginBottom: 8,\n },\n toolCallText: {\n fontSize: 12,\n color: \"#999999\",\n fontStyle: \"italic\",\n },\n errorContainer: {\n backgroundColor: \"#FEE2E2\",\n paddingHorizontal: 12,\n paddingVertical: 8,\n marginHorizontal: 8,\n borderRadius: 8,\n },\n errorText: {\n color: \"#DC2626\",\n fontSize: 13,\n },\n});\n","/**\n * CopilotModal — a bottom-sheet chat overlay for React Native.\n *\n * Mobile equivalent of CopilotPopup on web. Wraps CopilotChat inside\n * @gorhom/bottom-sheet so the chat can slide up over any screen.\n */\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from \"react\";\nimport { StyleSheet } from \"react-native\";\nimport BottomSheet, {\n BottomSheetBackdrop,\n BottomSheetFlatList,\n BottomSheetView,\n} from \"@gorhom/bottom-sheet\";\nimport type { BottomSheetBackdropProps } from \"@gorhom/bottom-sheet\";\nimport { CopilotChat } from \"./CopilotChat\";\nimport type { CopilotChatProps } from \"./CopilotChat\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface CopilotModalProps {\n /** Controlled visibility — when true the sheet opens, when false it closes. */\n visible?: boolean;\n\n /** Called when the sheet is dismissed (via backdrop tap, swipe-down, or close()). */\n onDismiss?: () => void;\n\n /**\n * Bottom-sheet snap points.\n * @default ['50%', '90%']\n */\n snapPoints?: (string | number)[];\n\n /**\n * Which snap-point index to open at.\n * @default 0\n */\n initialSnapIndex?: number;\n\n /**\n * Whether closing the sheet fires onDismiss.\n * @default true\n */\n enableDismissOnClose?: boolean;\n\n /**\n * Backdrop opacity when the sheet is open.\n * @default 0.5\n */\n backdropOpacity?: number;\n\n // -- Pass-through to CopilotChat ------------------------------------------\n\n /** Which agent to connect to. */\n agentName?: string;\n\n /** Input placeholder text. */\n placeholder?: string;\n\n /** Seed messages shown on first render. */\n initialMessages?: string[];\n\n /** Title shown in the CopilotChat header area. */\n headerTitle?: string;\n}\n\n/** Imperative handle exposed via ref. */\nexport interface CopilotModalRef {\n /** Programmatically open the bottom sheet. */\n open: () => void;\n /** Programmatically close the bottom sheet. */\n close: () => void;\n}\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\nexport const CopilotModal = forwardRef<CopilotModalRef, CopilotModalProps>(\n function CopilotModal(\n {\n visible,\n onDismiss,\n snapPoints: snapPointsProp,\n initialSnapIndex = 0,\n enableDismissOnClose = true,\n backdropOpacity = 0.5,\n agentName,\n placeholder,\n initialMessages,\n headerTitle,\n },\n ref,\n ) {\n const bottomSheetRef = useRef<BottomSheet>(null);\n\n // Stable snap-points array\n const snapPoints = useMemo(\n () => snapPointsProp ?? [\"50%\", \"90%\"],\n [snapPointsProp],\n );\n\n // ── Imperative API ────────────────────────────────────────────────────\n useImperativeHandle(\n ref,\n () => ({\n open() {\n bottomSheetRef.current?.snapToIndex(initialSnapIndex);\n },\n close() {\n bottomSheetRef.current?.close();\n },\n }),\n [initialSnapIndex],\n );\n\n // ── Controlled visibility ─────────────────────────────────────────────\n useEffect(() => {\n if (visible === undefined) return;\n if (visible) {\n bottomSheetRef.current?.snapToIndex(initialSnapIndex);\n } else {\n bottomSheetRef.current?.close();\n }\n }, [visible, initialSnapIndex]);\n\n // ── Backdrop renderer ─────────────────────────────────────────────────\n const renderBackdrop = useCallback(\n (props: BottomSheetBackdropProps) => (\n <BottomSheetBackdrop\n {...props}\n disappearsOnIndex={-1}\n appearsOnIndex={0}\n opacity={backdropOpacity}\n pressBehavior=\"close\"\n />\n ),\n [backdropOpacity],\n );\n\n // ── Sheet close handler ───────────────────────────────────────────────\n const handleClose = useCallback(() => {\n if (enableDismissOnClose) {\n onDismiss?.();\n }\n }, [enableDismissOnClose, onDismiss]);\n\n // ── Build CopilotChat props ───────────────────────────────────────────\n const chatProps = useMemo(() => {\n const props: Partial<CopilotChatProps> = {};\n if (agentName !== undefined) props.agentName = agentName;\n if (placeholder !== undefined) props.placeholder = placeholder;\n if (initialMessages !== undefined)\n props.initialMessages = initialMessages;\n if (headerTitle !== undefined) props.headerTitle = headerTitle;\n return props;\n }, [agentName, placeholder, initialMessages, headerTitle]);\n\n return (\n <BottomSheet\n ref={bottomSheetRef}\n index={-1}\n snapPoints={snapPoints}\n enablePanDownToClose\n backdropComponent={renderBackdrop}\n onClose={handleClose}\n keyboardBehavior=\"interactive\"\n keyboardBlurBehavior=\"restore\"\n backgroundStyle={styles.sheetBackground}\n handleIndicatorStyle={styles.handleIndicator}\n >\n <BottomSheetView style={styles.contentContainer}>\n <CopilotChat\n {...chatProps}\n FlatListComponent={BottomSheetFlatList}\n disableKeyboardAvoiding\n />\n </BottomSheetView>\n </BottomSheet>\n );\n },\n);\n\n// ---------------------------------------------------------------------------\n// Styles\n// ---------------------------------------------------------------------------\n\nconst styles = StyleSheet.create({\n sheetBackground: {\n backgroundColor: \"#FFFFFF\",\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n },\n handleIndicator: {\n width: 40,\n height: 4,\n backgroundColor: \"#DDDDDD\",\n },\n contentContainer: {\n flex: 1,\n },\n});\n"],"mappings":";;;;;;;;;;;;AAYA,MAAM,WAAW;AACjB,MAAM,cAAc;AACpB,MAAM,qBAAqB;;;;;;;AAQ3B,SAAgB,gBAAgB,EAAE,SAA+B;CAC/D,MAAM,CAAC,QAAQ,eAAe,IAAI,SAAS,MAAM,EAAE,CAAC;CACpD,MAAM,CAAC,QAAQ,eAAe,IAAI,SAAS,MAAM,EAAE,CAAC;CACpD,MAAM,CAAC,QAAQ,eAAe,IAAI,SAAS,MAAM,EAAE,CAAC;AAEpD,iBAAgB;EACd,MAAM,eAAe,KAAqB,UACxC,SAAS,SAAS,CAChB,SAAS,MAAM,MAAM,EACrB,SAAS,KACP,SAAS,SAAS,CAChB,SAAS,OAAO,KAAK;GACnB,SAAS;GACT,UAAU;GACV,iBAAiB;GAClB,CAAC,EACF,SAAS,OAAO,KAAK;GACnB,SAAS;GACT,UAAU;GACV,iBAAiB;GAClB,CAAC,CACH,CAAC,CACH,CACF,CAAC;EAEJ,MAAM,YAAY,SAAS,SAAS;GAClC,YAAY,MAAM,EAAE;GACpB,YAAY,MAAM,qBAAqB,IAAK;GAC5C,YAAY,MAAM,qBAAqB,IAAK;GAC7C,CAAC;AAEF,YAAU,OAAO;AAEjB,eAAa;AACX,aAAU,MAAM;;IAEjB;EAAC;EAAM;EAAM;EAAK,CAAC;CAEtB,MAAM,YAAY,mBAAmC;EACnD,GAAGA,SAAO;EACV,SAAS,cAAc,YAAY;GACjC,YAAY,CAAC,GAAG,EAAE;GAClB,aAAa,CAAC,IAAK,EAAE;GACtB,CAAC;EACF,WAAW,CACT,EACE,OAAO,cAAc,YAAY;GAC/B,YAAY,CAAC,GAAG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AAS,WAAW,OAAO;CAC/B,iBAAiB;EACf,iBAAiB;EACjB,qBAAqB;EACrB,sBAAsB;EACvB;CACD,iBAAiB;EACf,OAAO;EACP,QAAQ;EACR,iBAAiB;EAClB;CACD,kBAAkB,EAChB,MAAM,GACP;CACF,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":["styles","TIMESTAMP_COLOR","styles","styles","styles"],"sources":["../../src/components/messages/TypingIndicator.tsx","../../src/components/messages/utils.ts","../../src/components/messages/AssistantMessage.tsx","../../src/components/messages/UserMessage.tsx","../../src/components/CopilotChat.tsx","../../src/components/CopilotModal.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\nimport { View, Animated, StyleSheet } from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\n\n/**\n * Props for the TypingIndicator component.\n */\nexport interface TypingIndicatorProps {\n /** Optional style override for the container */\n style?: ViewStyle;\n}\n\nconst DOT_SIZE = 6;\nconst DOT_SPACING = 4;\nconst ANIMATION_DURATION = 400;\n\n/**\n * Three animated dots that pulse in sequence, suitable for embedding\n * inside an AssistantMessage to indicate the AI is still generating.\n *\n * Uses React Native's built-in `Animated` API (no Reanimated dependency).\n */\nexport function TypingIndicator({ style }: TypingIndicatorProps) {\n const [dot1] = useState(() => new Animated.Value(0));\n const [dot2] = useState(() => new Animated.Value(0));\n const [dot3] = useState(() => new Animated.Value(0));\n\n useEffect(() => {\n const createPulse = (dot: Animated.Value, delay: number) =>\n Animated.sequence([\n Animated.delay(delay),\n Animated.loop(\n Animated.sequence([\n Animated.timing(dot, {\n toValue: 1,\n duration: ANIMATION_DURATION,\n useNativeDriver: true,\n }),\n Animated.timing(dot, {\n toValue: 0,\n duration: ANIMATION_DURATION,\n useNativeDriver: true,\n }),\n ]),\n ),\n ]);\n\n const animation = Animated.parallel([\n createPulse(dot1, 0),\n createPulse(dot2, ANIMATION_DURATION * 0.33),\n createPulse(dot3, ANIMATION_DURATION * 0.66),\n ]);\n\n animation.start();\n\n return () => {\n animation.stop();\n };\n }, [dot1, dot2, dot3]);\n\n const dotStyle = (animatedValue: Animated.Value) => ({\n ...styles.dot,\n opacity: animatedValue.interpolate({\n inputRange: [0, 1],\n outputRange: [0.3, 1],\n }),\n transform: [\n {\n scale: animatedValue.interpolate({\n inputRange: [0, 1],\n outputRange: [0.8, 1.2],\n }),\n },\n ],\n });\n\n return (\n <View\n testID=\"copilot-loading-cursor\"\n style={[styles.container, style]}\n accessibilityLabel=\"Typing indicator\"\n accessibilityRole=\"text\"\n >\n <Animated.View style={dotStyle(dot1)} />\n <Animated.View style={dotStyle(dot2)} />\n <Animated.View style={dotStyle(dot3)} />\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flexDirection: \"row\",\n alignItems: \"center\",\n paddingVertical: 4,\n paddingHorizontal: 2,\n },\n dot: {\n width: DOT_SIZE,\n height: DOT_SIZE,\n borderRadius: DOT_SIZE / 2,\n backgroundColor: \"#999999\",\n marginHorizontal: DOT_SPACING / 2,\n },\n});\n","/**\n * Format a Date as a 12-hour time string (e.g. \"2:05 PM\").\n */\nexport function formatTimestamp(date: Date): string {\n const hours = date.getHours();\n const minutes = date.getMinutes();\n const ampm = hours >= 12 ? \"PM\" : \"AM\";\n const displayHours = hours % 12 || 12;\n const displayMinutes = minutes.toString().padStart(2, \"0\");\n return `${displayHours}:${displayMinutes} ${ampm}`;\n}\n","import React from \"react\";\nimport { View, Text, StyleSheet } from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\nimport { CopilotMarkdown } from \"../Markdown\";\nimport {\n useMarkdownRenderer,\n isNativeComponentRenderer,\n} from \"../MarkdownRendererContext\";\nimport { TypingIndicator } from \"./TypingIndicator\";\nimport { formatTimestamp } from \"./utils\";\n\n// ─── Colors ──────────────────────────────────────────────────────────────────\nconst ASSISTANT_BUBBLE_BG = \"#F0F0F0\";\nconst TIMESTAMP_COLOR = \"#999999\";\n\n/**\n * Props for the AssistantMessage component.\n */\nexport interface AssistantMessageProps {\n /** Markdown content to render inside the bubble */\n content: string;\n /** When true, shows a typing indicator below any content */\n isLoading?: boolean;\n /** Optional timestamp displayed below the bubble */\n timestamp?: Date;\n /** Optional style override for the outer container */\n style?: ViewStyle;\n}\n\n/**\n * Left-aligned chat bubble for AI assistant responses.\n *\n * Renders markdown content via `CopilotMarkdown` and shows an animated\n * typing indicator when `isLoading` is true.\n */\nexport function AssistantMessage({\n content,\n isLoading = false,\n timestamp,\n style,\n}: AssistantMessageProps) {\n // Honor a provider-level markdown renderer (CopilotKitProvider's\n // `markdownRenderer` prop), falling back to the built-in CopilotMarkdown.\n // This is the React Native arm of the slot -> provider -> built-in\n // resolution order documented in the migration guide.\n const provided = useMarkdownRenderer();\n return (\n <View style={[styles.container, style]}>\n <View style={styles.bubble}>\n {content ? (\n isNativeComponentRenderer(provided) ? (\n React.createElement(provided, { content, isStreaming: isLoading })\n ) : provided ? (\n <CopilotMarkdown\n content={content}\n style={provided.style}\n streamingAnimation={provided.animate}\n />\n ) : (\n <CopilotMarkdown content={content} />\n )\n ) : null}\n {isLoading ? <TypingIndicator /> : null}\n </View>\n {timestamp && (\n <Text style={styles.timestamp}>{formatTimestamp(timestamp)}</Text>\n )}\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n alignItems: \"flex-start\",\n marginVertical: 4,\n paddingHorizontal: 12,\n },\n bubble: {\n backgroundColor: ASSISTANT_BUBBLE_BG,\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n borderBottomRightRadius: 16,\n borderBottomLeftRadius: 4,\n paddingHorizontal: 12,\n paddingVertical: 8,\n maxWidth: \"80%\",\n },\n timestamp: {\n color: TIMESTAMP_COLOR,\n fontSize: 11,\n marginTop: 2,\n marginLeft: 4,\n },\n});\n","import React from \"react\";\nimport { View, Text, StyleSheet, type ViewStyle } from \"react-native\";\nimport { formatTimestamp } from \"./utils\";\n\n// ─── Colors ──────────────────────────────────────────────────────────────────\nconst USER_BUBBLE_BG = \"#0066CC\";\nconst USER_TEXT_COLOR = \"#FFFFFF\";\nconst TIMESTAMP_COLOR = \"#999999\";\n\n/**\n * Props for the UserMessage component.\n */\nexport interface UserMessageProps {\n /** Plain text content to display */\n content: string;\n /** Optional timestamp displayed below the bubble */\n timestamp?: Date;\n /** Optional style override for the outer container */\n style?: ViewStyle;\n}\n\n/**\n * Right-aligned chat bubble for user messages.\n *\n * Renders plain text (no markdown) with a primary-color background\n * and white text. Optionally displays a subtle timestamp below.\n */\nexport function UserMessage({ content, timestamp, style }: UserMessageProps) {\n return (\n <View style={[styles.container, style]}>\n <View style={styles.bubble}>\n <Text style={styles.text}>{content}</Text>\n </View>\n {timestamp && (\n <Text style={styles.timestamp}>{formatTimestamp(timestamp)}</Text>\n )}\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n alignItems: \"flex-end\",\n marginVertical: 4,\n paddingHorizontal: 12,\n },\n bubble: {\n backgroundColor: USER_BUBBLE_BG,\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n borderBottomLeftRadius: 16,\n borderBottomRightRadius: 4,\n paddingHorizontal: 12,\n paddingVertical: 8,\n maxWidth: \"80%\",\n },\n text: {\n color: USER_TEXT_COLOR,\n fontSize: 16,\n lineHeight: 22,\n },\n timestamp: {\n color: TIMESTAMP_COLOR,\n fontSize: 11,\n marginTop: 2,\n marginRight: 4,\n },\n});\n","import React, {\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n FlatList,\n KeyboardAvoidingView,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n TextInput,\n TouchableOpacity,\n View,\n} from \"react-native\";\nimport type { ListRenderItemInfo, ViewStyle } from \"react-native\";\nimport { useAgent, useRenderToolCall } from \"@copilotkit/react-core/headless\";\nimport { useCopilotKit } from \"@copilotkit/react-core/context\";\nimport {\n ɵcreateChatSubmitter,\n ɵgetToolResults,\n ɵmessagesFingerprint,\n} from \"@copilotkit/core\";\nimport type { CopilotKitCore } from \"@copilotkit/core\";\nimport { AssistantMessage } from \"./messages/AssistantMessage\";\nimport { UserMessage } from \"./messages/UserMessage\";\nimport type { ToolMessage } from \"@ag-ui/client\";\n\n/** Shape of an assistant message with optional tool calls. */\ninterface AssistantMessageShape {\n id: string;\n role: \"assistant\";\n content?: string;\n toolCalls?: Array<{\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n }>;\n}\n\nexport interface CopilotChatProps {\n /** Agent ID to connect to. Defaults to 'default'. */\n agentName?: string;\n /** Placeholder text for the input field. */\n placeholder?: string;\n /** Suggestion pills shown in the empty state. */\n initialMessages?: string[];\n /** Title shown when there are no messages. */\n emptyStateTitle?: string;\n /** Subtitle shown when there are no messages. */\n emptyStateSubtitle?: string;\n /** Title for the optional header bar. */\n headerTitle?: string;\n /** Whether to show the header bar. Defaults to true. */\n showHeader?: boolean;\n /** Style override for the outermost container. */\n style?: ViewStyle;\n /** Style override for the message list container. */\n messageContainerStyle?: ViewStyle;\n /** Style override for the input bar container. */\n inputContainerStyle?: ViewStyle;\n /** Callback fired when the user sends a message. */\n onSendMessage?: (text: string) => void;\n /** Custom FlatList component (e.g. BottomSheetFlatList for use inside a bottom sheet). */\n FlatListComponent?: React.ComponentType<any>;\n /** When true, skip the KeyboardAvoidingView wrapper (useful when a parent already handles keyboard). */\n disableKeyboardAvoiding?: boolean;\n}\n\ninterface ChatListItem {\n id: string;\n type: \"user\" | \"assistant\" | \"tool-call\" | \"loading\";\n content?: string;\n toolCalls?: Array<{\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n }>;\n}\n\n/**\n * The core as the chat's submitter takes it, with a failed run also passed to\n * `onRunError` so the chat can show it. The submitter logs the failure itself.\n */\nfunction withRunErrorReporting(\n core: CopilotKitCore,\n onRunError: (message: string) => void,\n): Parameters<typeof ɵcreateChatSubmitter>[0][\"core\"] {\n return {\n runAgent: async (params) => {\n try {\n return await core.runAgent(params);\n } catch (err) {\n onRunError(\n err instanceof Error ? err.message : \"An unexpected error occurred\",\n );\n throw err;\n }\n },\n stopAgent: (params) => core.stopAgent(params),\n // This chat does not transcribe, but the submitter's core type covers it.\n get runtimeUrl() {\n return core.runtimeUrl;\n },\n get runtimeTransport() {\n return core.runtimeTransport;\n },\n get credentials() {\n return core.credentials;\n },\n resolveHeaders: () => core.resolveHeaders(),\n };\n}\n\n/**\n * Full-screen chat UI component for React Native.\n *\n * Connects to a CopilotKit agent via `useAgent` and renders messages\n * using platform-appropriate AssistantMessage / UserMessage components.\n *\n * Usage:\n * ```tsx\n * <CopilotChat agentName=\"my-agent\" headerTitle=\"Assistant\" />\n * ```\n */\nexport function CopilotChat({\n agentName = \"default\",\n placeholder = \"Type a message...\",\n initialMessages = [],\n emptyStateTitle = \"How can I help?\",\n emptyStateSubtitle = \"Ask me anything or try a suggestion below.\",\n headerTitle = \"Chat\",\n showHeader = true,\n style,\n messageContainerStyle,\n inputContainerStyle,\n onSendMessage,\n FlatListComponent = FlatList,\n disableKeyboardAvoiding = false,\n}: CopilotChatProps) {\n const [inputText, setInputText] = useState(\"\");\n const [error, setError] = useState<string | null>(null);\n const flatListRef = useRef<FlatList>(null);\n\n const { copilotkit } = useCopilotKit();\n const { agent } = useAgent({ agentId: agentName });\n\n const messages = agent.messages ?? [];\n const isRunning = agent.isRunning;\n\n const renderToolCall = useRenderToolCall();\n\n // useInterrupt publishes its element to core unless renderInChat is false.\n // Draw it after the last message, as the web message view does.\n const [interruptElement, setInterruptElement] =\n useState<React.ReactElement | null>(null);\n useEffect(() => {\n setInterruptElement(copilotkit.interruptElement);\n const subscription = copilotkit.subscribe({\n onInterruptElementChanged: ({ interruptElement: element }) => {\n setInterruptElement(element);\n },\n });\n return () => subscription.unsubscribe();\n }, [copilotkit]);\n\n // Recomputed every render: cheap, and the only honest dependency for the\n // message-derived memos below. The array reference does not track content\n // in either direction: core inserts tool results with an in-place `splice`,\n // `addMessage` pushes, and the AG-UI apply pipeline replaces the array on\n // every streamed delta.\n const messagesKey = ɵmessagesFingerprint(messages);\n\n // toolCallId -> tool result message, so a renderer reports \"complete\" with\n // its `result`.\n const toolMessages = useMemo(() => {\n const byId = new Map<string, ToolMessage>();\n for (const [toolCallId, message] of ɵgetToolResults(messages)) {\n // A copy, so the tool-call renderer's memo sees content that was\n // replaced in place on the same message. Core turns the content into\n // the renderer's `result` string.\n byId.set(toolCallId, { ...message });\n }\n return byId;\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on message content, see messagesKey\n }, [messagesKey]);\n\n // Build flat list items from messages\n const listItems: ChatListItem[] = useMemo(() => {\n const items: ChatListItem[] = [];\n\n for (const msg of messages) {\n if (msg.role === \"user\") {\n items.push({\n id: msg.id,\n type: \"user\",\n content: typeof msg.content === \"string\" ? msg.content : \"\",\n });\n } else if (msg.role === \"assistant\") {\n const assistantMsg = msg as AssistantMessageShape;\n // Add text content if present\n if (assistantMsg.content) {\n items.push({\n id: msg.id,\n type: \"assistant\",\n content: assistantMsg.content,\n });\n }\n // Add tool calls if present\n if (assistantMsg.toolCalls && assistantMsg.toolCalls.length > 0) {\n for (const tc of assistantMsg.toolCalls) {\n items.push({\n id: `${msg.id}-tc-${tc.id}`,\n type: \"tool-call\",\n toolCalls: [tc],\n });\n }\n }\n }\n }\n\n // Show loading indicator when agent is running and the last message\n // is not already the assistant streaming\n if (isRunning) {\n const lastItem = items[items.length - 1];\n if (!lastItem || lastItem.type !== \"assistant\") {\n items.push({ id: \"__loading__\", type: \"loading\" });\n }\n }\n\n return items;\n // Same reasoning as `toolMessages`: keyed on message CONTENT, because the\n // array reference does not track content in either direction — core's\n // in-place `splice` and `addMessage`'s push leave it untouched, while the\n // AG-UI apply pipeline replaces it on every delta. Without this, an\n // assistant message or tool call appended mid-run never reaches the list.\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- keyed on message content, see messagesKey\n }, [messagesKey, isRunning]);\n\n // Id of the trailing row. renderItem needs \"is this the last row?\" to place\n // the streaming indicator; deriving it here keeps that a named scalar instead\n // of renderItem closing over `listItems` and index-reading its tail.\n const lastItemId = useMemo(\n () => listItems[listItems.length - 1]?.id,\n [listItems],\n );\n\n // extraData defeats FlatList's PureComponent shallow-compare for the values\n // renderItem CLOSES OVER, as opposed to the ones it receives per row. Those\n // are exactly the four below, and they mirror renderItem's dependency array —\n // keep the two in sync. `listItems` is deliberately absent: renderItem's only\n // read of it is the tail id, now passed as `lastItemId`, and the array itself\n // is already the `data` prop, which invalidates cells on its own (every\n // rebuild allocates fresh item objects, so each cell's `item` prop differs).\n const extraData = useMemo(\n () => ({ isRunning, lastItemId, renderToolCall, toolMessages }),\n [isRunning, lastItemId, renderToolCall, toolMessages],\n );\n\n // The send side lives in core: it builds the message, waits for the run in\n // flight, and runs the agent. A failed run also shows under the list.\n const agentRef = useRef(agent);\n const inputTextRef = useRef(inputText);\n useLayoutEffect(() => {\n agentRef.current = agent;\n inputTextRef.current = inputText;\n });\n const [submitter] = useState(() =>\n ɵcreateChatSubmitter({\n core: withRunErrorReporting(copilotkit, setError),\n getAgent: () => agentRef.current,\n input: {\n get: () => inputTextRef.current,\n set: (value) => {\n inputTextRef.current = value;\n setInputText(value);\n },\n },\n }),\n );\n useEffect(() => () => submitter.showNotice(null), [submitter]);\n\n // Send from the input field\n const handleSend = useCallback(() => {\n const text = inputText.trim();\n if (!text) return;\n setError(null);\n onSendMessage?.(text);\n void submitter.submit(text);\n }, [inputText, onSendMessage, submitter]);\n\n // Handle suggestion pill press. Leaves the typed text alone.\n const handleSuggestion = useCallback(\n (text: string) => {\n setError(null);\n onSendMessage?.(text);\n void submitter.selectSuggestion({ message: text, isLoading: false });\n },\n [onSendMessage, submitter],\n );\n\n // Auto-scroll when content changes\n const handleContentSizeChange = useCallback(() => {\n flatListRef.current?.scrollToEnd({ animated: true });\n }, []);\n\n // Render a single list item\n const renderItem = useCallback(\n ({ item }: ListRenderItemInfo<ChatListItem>) => {\n if (item.type === \"user\") {\n return <UserMessage content={item.content ?? \"\"} />;\n }\n\n if (item.type === \"assistant\") {\n return (\n <AssistantMessage\n content={item.content ?? \"\"}\n isLoading={isRunning && item.id === lastItemId}\n />\n );\n }\n\n if (item.type === \"tool-call\" && item.toolCalls) {\n const tc = item.toolCalls[0];\n // Partial-parses streaming args, resolves the renderer (exact name ->\n // agent-scoped -> wildcard \"*\") and derives status — all in react-core,\n // shared with web. Returns ReactElement | null, which is what\n // renderItem requires.\n const rendered = renderToolCall({\n toolCall: tc,\n toolMessage: toolMessages.get(tc.id),\n });\n if (rendered) return <>{rendered}</>;\n\n // Subtle indicator for unregistered tool calls\n return (\n <View style={styles.toolCallIndicator}>\n <Text style={styles.toolCallText}>Called: {tc.function.name}</Text>\n </View>\n );\n }\n\n if (item.type === \"loading\") {\n return <AssistantMessage content=\"\" isLoading />;\n }\n\n return null;\n },\n [isRunning, lastItemId, renderToolCall, toolMessages],\n );\n\n const keyExtractor = useCallback((item: ChatListItem) => item.id, []);\n\n // Empty state component\n const emptyComponent = useMemo(\n () => (\n <View style={styles.emptyState}>\n <Text style={styles.emptyTitle}>{emptyStateTitle}</Text>\n <Text style={styles.emptySubtitle}>{emptyStateSubtitle}</Text>\n {initialMessages.map((suggestion, i) => (\n <Pressable\n key={`suggestion-${i}`}\n style={styles.suggestionPill}\n onPress={() => handleSuggestion(suggestion)}\n >\n <Text style={styles.suggestionText}>{suggestion}</Text>\n </Pressable>\n ))}\n </View>\n ),\n [emptyStateTitle, emptyStateSubtitle, initialMessages, handleSuggestion],\n );\n\n const sendDisabled = !inputText.trim() || isRunning;\n\n const content = (\n <>\n {showHeader && (\n <View style={styles.header}>\n <Text style={styles.headerTitle}>{headerTitle}</Text>\n </View>\n )}\n\n <FlatListComponent\n ref={flatListRef}\n data={listItems}\n renderItem={renderItem}\n keyExtractor={keyExtractor}\n extraData={extraData}\n contentContainerStyle={[styles.messageList, messageContainerStyle]}\n onContentSizeChange={handleContentSizeChange}\n ListEmptyComponent={emptyComponent}\n ListFooterComponent={interruptElement}\n />\n\n {error && (\n <View style={styles.errorContainer} testID=\"error-message\">\n <Text style={styles.errorText}>{error}</Text>\n </View>\n )}\n\n <View style={[styles.inputContainer, inputContainerStyle]}>\n <TextInput\n style={styles.input}\n value={inputText}\n onChangeText={setInputText}\n placeholder={placeholder}\n placeholderTextColor=\"#999\"\n multiline\n // The input grows with its text up to maxHeight. react-native-web\n // needs a row count, or the browser draws two rows, so start at one\n // row there. On Android a row count pins the height, so set none.\n numberOfLines={Platform.OS === \"web\" ? 1 : undefined}\n returnKeyType=\"send\"\n // A multiline input inserts a newline on Return unless told to\n // submit. React Native 0.73+ reads submitBehavior; older versions and\n // react-native-web read blurOnSubmit. On the web, Shift+Enter still\n // inserts a newline.\n submitBehavior=\"submit\"\n blurOnSubmit\n onSubmitEditing={handleSend}\n />\n <TouchableOpacity\n style={[styles.sendButton, sendDisabled && styles.sendButtonDisabled]}\n onPress={handleSend}\n disabled={sendDisabled}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Send message\"\n accessibilityState={{ disabled: sendDisabled }}\n testID=\"send-button\"\n >\n <Text style={styles.sendButtonIcon}>{\"↑\"}</Text>\n </TouchableOpacity>\n </View>\n </>\n );\n\n if (disableKeyboardAvoiding) {\n return <View style={[styles.container, style]}>{content}</View>;\n }\n\n return (\n <KeyboardAvoidingView\n style={[styles.container, style]}\n behavior={Platform.OS === \"ios\" ? \"padding\" : \"height\"}\n keyboardVerticalOffset={0}\n >\n {content}\n </KeyboardAvoidingView>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n backgroundColor: \"#FFFFFF\",\n },\n header: {\n height: 56,\n justifyContent: \"center\",\n alignItems: \"center\",\n borderBottomWidth: StyleSheet.hairlineWidth,\n borderBottomColor: \"#E0E0E0\",\n backgroundColor: \"#FFFFFF\",\n },\n headerTitle: {\n fontSize: 17,\n fontWeight: \"600\",\n color: \"#1A1A1A\",\n },\n messageList: {\n paddingHorizontal: 16,\n flexGrow: 1,\n },\n inputContainer: {\n flexDirection: \"row\",\n alignItems: \"flex-end\",\n paddingHorizontal: 8,\n paddingVertical: 8,\n borderTopWidth: StyleSheet.hairlineWidth,\n borderTopColor: \"#E0E0E0\",\n backgroundColor: \"#FFFFFF\",\n },\n input: {\n flex: 1,\n backgroundColor: \"#F5F5F5\",\n borderRadius: 20,\n paddingHorizontal: 12,\n paddingVertical: 8,\n fontSize: 15,\n maxHeight: 100,\n color: \"#1A1A1A\",\n },\n sendButton: {\n width: 36,\n height: 36,\n borderRadius: 18,\n backgroundColor: \"#0066CC\",\n justifyContent: \"center\",\n alignItems: \"center\",\n marginLeft: 8,\n },\n sendButtonDisabled: {\n opacity: 0.4,\n },\n sendButtonIcon: {\n color: \"#FFFFFF\",\n fontSize: 18,\n fontWeight: \"700\",\n },\n emptyState: {\n flex: 1,\n justifyContent: \"center\",\n alignItems: \"center\",\n paddingTop: 100,\n gap: 12,\n },\n emptyTitle: {\n fontSize: 22,\n fontWeight: \"700\",\n color: \"#1A1A1A\",\n marginBottom: 4,\n },\n emptySubtitle: {\n fontSize: 15,\n color: \"#666666\",\n marginBottom: 16,\n },\n suggestionPill: {\n backgroundColor: \"#E8F0FE\",\n borderRadius: 20,\n paddingHorizontal: 16,\n paddingVertical: 10,\n },\n suggestionText: {\n color: \"#0066CC\",\n fontWeight: \"600\",\n fontSize: 14,\n },\n toolCallIndicator: {\n alignSelf: \"flex-start\",\n backgroundColor: \"#F0F0F0\",\n borderRadius: 12,\n paddingHorizontal: 12,\n paddingVertical: 6,\n marginBottom: 8,\n },\n toolCallText: {\n fontSize: 12,\n color: \"#999999\",\n fontStyle: \"italic\",\n },\n errorContainer: {\n backgroundColor: \"#FEE2E2\",\n paddingHorizontal: 12,\n paddingVertical: 8,\n marginHorizontal: 8,\n borderRadius: 8,\n },\n errorText: {\n color: \"#DC2626\",\n fontSize: 13,\n },\n});\n","/**\n * CopilotModal — a bottom-sheet chat overlay for React Native.\n *\n * Mobile equivalent of CopilotPopup on web. Wraps CopilotChat inside\n * @gorhom/bottom-sheet so the chat can slide up over any screen.\n */\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from \"react\";\nimport { StyleSheet, View } from \"react-native\";\nimport BottomSheet, {\n BottomSheetBackdrop,\n BottomSheetFlatList,\n} from \"@gorhom/bottom-sheet\";\nimport type { BottomSheetBackdropProps } from \"@gorhom/bottom-sheet\";\nimport { CopilotChat } from \"./CopilotChat\";\nimport type { CopilotChatProps } from \"./CopilotChat\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface CopilotModalProps {\n /** Controlled visibility — when true the sheet opens, when false it closes. */\n visible?: boolean;\n\n /** Called when the sheet is dismissed (via backdrop tap, swipe-down, or close()). */\n onDismiss?: () => void;\n\n /**\n * Bottom-sheet snap points.\n *\n * The default is one snap point because the message input is pinned to the\n * bottom of the chat. The chat always fills the sheet at its highest snap\n * point, so a lower snap point pushes the input below the screen.\n * @default ['90%']\n */\n snapPoints?: (string | number)[];\n\n /**\n * Which snap-point index to open at.\n * @default 0\n */\n initialSnapIndex?: number;\n\n /**\n * Whether closing the sheet fires onDismiss.\n * @default true\n */\n enableDismissOnClose?: boolean;\n\n /**\n * Backdrop opacity when the sheet is open.\n * @default 0.5\n */\n backdropOpacity?: number;\n\n // -- Pass-through to CopilotChat ------------------------------------------\n\n /** Which agent to connect to. */\n agentName?: string;\n\n /** Input placeholder text. */\n placeholder?: string;\n\n /** Seed messages shown on first render. */\n initialMessages?: string[];\n\n /** Title shown in the CopilotChat header area. */\n headerTitle?: string;\n}\n\n/** Imperative handle exposed via ref. */\nexport interface CopilotModalRef {\n /** Programmatically open the bottom sheet. */\n open: () => void;\n /** Programmatically close the bottom sheet. */\n close: () => void;\n}\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\nexport const CopilotModal = forwardRef<CopilotModalRef, CopilotModalProps>(\n function CopilotModal(\n {\n visible,\n onDismiss,\n snapPoints: snapPointsProp,\n initialSnapIndex = 0,\n enableDismissOnClose = true,\n backdropOpacity = 0.5,\n agentName,\n placeholder,\n initialMessages,\n headerTitle,\n },\n ref,\n ) {\n const bottomSheetRef = useRef<BottomSheet>(null);\n\n // Stable snap-points array\n const snapPoints = useMemo(\n () => snapPointsProp ?? [\"90%\"],\n [snapPointsProp],\n );\n\n // ── Imperative API ────────────────────────────────────────────────────\n useImperativeHandle(\n ref,\n () => ({\n open() {\n bottomSheetRef.current?.snapToIndex(initialSnapIndex);\n },\n close() {\n bottomSheetRef.current?.close();\n },\n }),\n [initialSnapIndex],\n );\n\n // ── Controlled visibility ─────────────────────────────────────────────\n useEffect(() => {\n if (visible === undefined) return;\n if (visible) {\n bottomSheetRef.current?.snapToIndex(initialSnapIndex);\n } else {\n bottomSheetRef.current?.close();\n }\n }, [visible, initialSnapIndex]);\n\n // ── Backdrop renderer ─────────────────────────────────────────────────\n const renderBackdrop = useCallback(\n (props: BottomSheetBackdropProps) => (\n <BottomSheetBackdrop\n {...props}\n disappearsOnIndex={-1}\n appearsOnIndex={0}\n opacity={backdropOpacity}\n pressBehavior=\"close\"\n />\n ),\n [backdropOpacity],\n );\n\n // ── Sheet close handler ───────────────────────────────────────────────\n const handleClose = useCallback(() => {\n if (enableDismissOnClose) {\n onDismiss?.();\n }\n }, [enableDismissOnClose, onDismiss]);\n\n // ── Build CopilotChat props ───────────────────────────────────────────\n const chatProps = useMemo(() => {\n const props: Partial<CopilotChatProps> = {};\n if (agentName !== undefined) props.agentName = agentName;\n if (placeholder !== undefined) props.placeholder = placeholder;\n if (initialMessages !== undefined)\n props.initialMessages = initialMessages;\n if (headerTitle !== undefined) props.headerTitle = headerTitle;\n return props;\n }, [agentName, placeholder, initialMessages, headerTitle]);\n\n return (\n <BottomSheet\n ref={bottomSheetRef}\n index={-1}\n snapPoints={snapPoints}\n // The chat fills the sheet (flex: 1), so the sheet cannot take its\n // height from the content. Size it from the snap points instead.\n enableDynamicSizing={false}\n enablePanDownToClose\n backdropComponent={renderBackdrop}\n onClose={handleClose}\n keyboardBehavior=\"interactive\"\n keyboardBlurBehavior=\"restore\"\n backgroundStyle={styles.sheetBackground}\n handleIndicatorStyle={styles.handleIndicator}\n >\n {/* A plain View: BottomSheetView is absolutely positioned with no\n bottom edge, so flex: 1 cannot make it fill the sheet. */}\n <View style={styles.contentContainer}>\n <CopilotChat\n {...chatProps}\n FlatListComponent={BottomSheetFlatList}\n disableKeyboardAvoiding\n />\n </View>\n </BottomSheet>\n );\n },\n);\n\n// ---------------------------------------------------------------------------\n// Styles\n// ---------------------------------------------------------------------------\n\nconst styles = StyleSheet.create({\n sheetBackground: {\n backgroundColor: \"#FFFFFF\",\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n },\n handleIndicator: {\n width: 40,\n height: 4,\n backgroundColor: \"#DDDDDD\",\n },\n contentContainer: {\n flex: 1,\n },\n});\n"],"mappings":";;;;;;;;;;;;AAYA,MAAM,WAAW;AACjB,MAAM,cAAc;AACpB,MAAM,qBAAqB;;;;;;;AAQ3B,SAAgB,gBAAgB,EAAE,SAA+B;CAC/D,MAAM,CAAC,QAAQ,eAAe,IAAI,SAAS,MAAM,EAAE,CAAC;CACpD,MAAM,CAAC,QAAQ,eAAe,IAAI,SAAS,MAAM,EAAE,CAAC;CACpD,MAAM,CAAC,QAAQ,eAAe,IAAI,SAAS,MAAM,EAAE,CAAC;AAEpD,iBAAgB;EACd,MAAM,eAAe,KAAqB,UACxC,SAAS,SAAS,CAChB,SAAS,MAAM,MAAM,EACrB,SAAS,KACP,SAAS,SAAS,CAChB,SAAS,OAAO,KAAK;GACnB,SAAS;GACT,UAAU;GACV,iBAAiB;GAClB,CAAC,EACF,SAAS,OAAO,KAAK;GACnB,SAAS;GACT,UAAU;GACV,iBAAiB;GAClB,CAAC,CACH,CAAC,CACH,CACF,CAAC;EAEJ,MAAM,YAAY,SAAS,SAAS;GAClC,YAAY,MAAM,EAAE;GACpB,YAAY,MAAM,qBAAqB,IAAK;GAC5C,YAAY,MAAM,qBAAqB,IAAK;GAC7C,CAAC;AAEF,YAAU,OAAO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;EAAC;EAAW;EAAa;EAAiB;EAAY,CAAC;AAE1D,QACE,oBAAC;EACC,KAAK;EACL,OAAO;EACK;EAGZ,qBAAqB;EACrB;EACA,mBAAmB;EACnB,SAAS;EACT,kBAAiB;EACjB,sBAAqB;EACrB,iBAAiB,OAAO;EACxB,sBAAsB,OAAO;YAI7B,oBAAC;GAAK,OAAO,OAAO;aAClB,oBAAC;IACC,GAAI;IACJ,mBAAmB;IACnB;KACA;IACG;GACK;EAGnB;AAMD,MAAM,SAAS,WAAW,OAAO;CAC/B,iBAAiB;EACf,iBAAiB;EACjB,qBAAqB;EACrB,sBAAsB;EACvB;CACD,iBAAiB;EACf,OAAO;EACP,QAAQ;EACR,iBAAiB;EAClB;CACD,kBAAkB,EAChB,MAAM,GACP;CACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/react-native",
3
- "version": "2.0.0-rc.54",
3
+ "version": "2.0.0-rc.55",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "ai",
@@ -116,10 +116,10 @@
116
116
  },
117
117
  "dependencies": {
118
118
  "@ag-ui/client": "1.0.4",
119
- "@copilotkit/core": "2.0.0-rc.54",
120
- "@copilotkit/markdown": "2.0.0-rc.54",
121
- "@copilotkit/react-core": "2.0.0-rc.54",
122
- "@copilotkit/shared": "2.0.0-rc.54",
119
+ "@copilotkit/core": "2.0.0-rc.55",
120
+ "@copilotkit/markdown": "2.0.0-rc.55",
121
+ "@copilotkit/react-core": "2.0.0-rc.55",
122
+ "@copilotkit/shared": "2.0.0-rc.55",
123
123
  "web-streams-polyfill": "^4.2.0"
124
124
  },
125
125
  "devDependencies": {
@@ -411,7 +411,10 @@ export function CopilotChat({
411
411
  placeholder={placeholder}
412
412
  placeholderTextColor="#999"
413
413
  multiline
414
- numberOfLines={4}
414
+ // The input grows with its text up to maxHeight. react-native-web
415
+ // needs a row count, or the browser draws two rows, so start at one
416
+ // row there. On Android a row count pins the height, so set none.
417
+ numberOfLines={Platform.OS === "web" ? 1 : undefined}
415
418
  returnKeyType="send"
416
419
  // A multiline input inserts a newline on Return unless told to
417
420
  // submit. React Native 0.73+ reads submitBehavior; older versions and
@@ -12,11 +12,10 @@ import React, {
12
12
  useMemo,
13
13
  useRef,
14
14
  } from "react";
15
- import { StyleSheet } from "react-native";
15
+ import { StyleSheet, View } from "react-native";
16
16
  import BottomSheet, {
17
17
  BottomSheetBackdrop,
18
18
  BottomSheetFlatList,
19
- BottomSheetView,
20
19
  } from "@gorhom/bottom-sheet";
21
20
  import type { BottomSheetBackdropProps } from "@gorhom/bottom-sheet";
22
21
  import { CopilotChat } from "./CopilotChat";
@@ -35,7 +34,11 @@ export interface CopilotModalProps {
35
34
 
36
35
  /**
37
36
  * Bottom-sheet snap points.
38
- * @default ['50%', '90%']
37
+ *
38
+ * The default is one snap point because the message input is pinned to the
39
+ * bottom of the chat. The chat always fills the sheet at its highest snap
40
+ * point, so a lower snap point pushes the input below the screen.
41
+ * @default ['90%']
39
42
  */
40
43
  snapPoints?: (string | number)[];
41
44
 
@@ -104,7 +107,7 @@ export const CopilotModal = forwardRef<CopilotModalRef, CopilotModalProps>(
104
107
 
105
108
  // Stable snap-points array
106
109
  const snapPoints = useMemo(
107
- () => snapPointsProp ?? ["50%", "90%"],
110
+ () => snapPointsProp ?? ["90%"],
108
111
  [snapPointsProp],
109
112
  );
110
113
 
@@ -169,6 +172,9 @@ export const CopilotModal = forwardRef<CopilotModalRef, CopilotModalProps>(
169
172
  ref={bottomSheetRef}
170
173
  index={-1}
171
174
  snapPoints={snapPoints}
175
+ // The chat fills the sheet (flex: 1), so the sheet cannot take its
176
+ // height from the content. Size it from the snap points instead.
177
+ enableDynamicSizing={false}
172
178
  enablePanDownToClose
173
179
  backdropComponent={renderBackdrop}
174
180
  onClose={handleClose}
@@ -177,13 +183,15 @@ export const CopilotModal = forwardRef<CopilotModalRef, CopilotModalProps>(
177
183
  backgroundStyle={styles.sheetBackground}
178
184
  handleIndicatorStyle={styles.handleIndicator}
179
185
  >
180
- <BottomSheetView style={styles.contentContainer}>
186
+ {/* A plain View: BottomSheetView is absolutely positioned with no
187
+ bottom edge, so flex: 1 cannot make it fill the sheet. */}
188
+ <View style={styles.contentContainer}>
181
189
  <CopilotChat
182
190
  {...chatProps}
183
191
  FlatListComponent={BottomSheetFlatList}
184
192
  disableKeyboardAvoiding
185
193
  />
186
- </BottomSheetView>
194
+ </View>
187
195
  </BottomSheet>
188
196
  );
189
197
  },
@@ -1,17 +1,27 @@
1
1
  import React from "react";
2
+ import type { ChangeEvent, KeyboardEvent, ReactNode } from "react";
2
3
  import { render, fireEvent, act } from "@testing-library/react";
3
4
  import { describe, it, expect, beforeEach, vi } from "vitest";
5
+ import type { Message } from "@ag-ui/client";
6
+ import type {
7
+ FlatListProps,
8
+ PlatformOSType,
9
+ TextInputProps,
10
+ TouchableOpacityProps,
11
+ } from "react-native";
4
12
 
5
13
  // ─── Hoisted state ─────────────────────────────────────────────────────────────
6
14
 
7
15
  const hoisted = vi.hoisted(() => {
8
16
  return {
9
17
  mockAgent: {
10
- messages: [] as any[],
18
+ messages: [] as Message[],
11
19
  isRunning: false,
12
20
  addMessage: vi.fn(),
13
21
  },
14
22
  mockRunAgent: vi.fn().mockResolvedValue(undefined),
23
+ // Tests set OS to render CopilotChat as it renders on that platform.
24
+ platform: { OS: "ios" as PlatformOSType },
15
25
  };
16
26
  });
17
27
 
@@ -39,7 +49,13 @@ vi.mock("@copilotkit/react-core/context", () => ({
39
49
 
40
50
  // Mock sub-components that B2 builds
41
51
  vi.mock("../messages/AssistantMessage", () => ({
42
- AssistantMessage: ({ content, isLoading }: any) => {
52
+ AssistantMessage: ({
53
+ content,
54
+ isLoading,
55
+ }: {
56
+ content: string;
57
+ isLoading?: boolean;
58
+ }) => {
43
59
  const React = require("react");
44
60
  return React.createElement(
45
61
  "div",
@@ -50,7 +66,7 @@ vi.mock("../messages/AssistantMessage", () => ({
50
66
  }));
51
67
 
52
68
  vi.mock("../messages/UserMessage", () => ({
53
- UserMessage: ({ content }: any) => {
69
+ UserMessage: ({ content }: { content: string }) => {
54
70
  const React = require("react");
55
71
  return React.createElement(
56
72
  "div",
@@ -64,7 +80,12 @@ vi.mock("../messages/UserMessage", () => ({
64
80
  vi.mock("react-native", () => {
65
81
  const React = require("react");
66
82
  return {
67
- FlatList: ({ data, renderItem, ListEmptyComponent, keyExtractor }: any) => {
83
+ FlatList: ({
84
+ data,
85
+ renderItem,
86
+ ListEmptyComponent,
87
+ keyExtractor,
88
+ }: FlatListProps<Message>) => {
68
89
  if (!data || data.length === 0) {
69
90
  return React.createElement(
70
91
  "div",
@@ -75,48 +96,70 @@ vi.mock("react-native", () => {
75
96
  return React.createElement(
76
97
  "div",
77
98
  { "data-testid": "flatlist" },
78
- data.map((item: any, index: number) =>
99
+ Array.from(data, (item, index) =>
79
100
  React.createElement(
80
101
  "div",
81
102
  { key: keyExtractor?.(item, index) ?? index },
82
- renderItem({ item, index }),
103
+ renderItem?.({
104
+ item,
105
+ index,
106
+ separators: {
107
+ highlight: () => {},
108
+ unhighlight: () => {},
109
+ updateProps: () => {},
110
+ },
111
+ }),
83
112
  ),
84
113
  ),
85
114
  );
86
115
  },
87
- KeyboardAvoidingView: ({ children }: any) =>
116
+ KeyboardAvoidingView: ({ children }: { children?: ReactNode }) =>
88
117
  React.createElement("div", { "data-testid": "keyboard-view" }, children),
89
- Platform: { OS: "ios" },
90
- Pressable: ({ children, onPress, ...props }: any) =>
118
+ Platform: hoisted.platform,
119
+ Pressable: ({
120
+ children,
121
+ onPress,
122
+ ...props
123
+ }: {
124
+ children?: ReactNode;
125
+ onPress?: () => void;
126
+ }) =>
91
127
  React.createElement(
92
128
  "button",
93
129
  { onClick: onPress, "data-testid": "pressable", ...props },
94
130
  children,
95
131
  ),
96
132
  StyleSheet: {
97
- create: (styles: any) => styles,
133
+ create: <T,>(styles: T) => styles,
98
134
  hairlineWidth: 1,
99
135
  },
100
- Text: ({ children, ...props }: any) =>
136
+ Text: ({ children, ...props }: { children?: ReactNode }) =>
101
137
  React.createElement("span", props, children),
138
+ // Like react-native-web: a multiline input is a <textarea> whose rows
139
+ // come from numberOfLines.
102
140
  TextInput: ({
103
141
  value,
104
142
  onChangeText,
105
143
  onSubmitEditing,
106
144
  multiline,
145
+ numberOfLines,
107
146
  submitBehavior,
108
147
  blurOnSubmit,
109
- numberOfLines: _numberOfLines,
110
148
  returnKeyType: _returnKeyType,
111
149
  placeholderTextColor: _placeholderTextColor,
112
150
  ...props
113
- }: any) =>
114
- React.createElement("input", {
151
+ }: Omit<TextInputProps, "onSubmitEditing"> & {
152
+ // The mock submits with no native event. CopilotChat reads none.
153
+ onSubmitEditing?: () => void;
154
+ }) =>
155
+ React.createElement(multiline ? "textarea" : "input", {
115
156
  value,
116
- onChange: (e: any) => onChangeText?.(e.target.value),
157
+ rows: multiline ? numberOfLines : undefined,
158
+ onChange: (e: ChangeEvent<HTMLInputElement>) =>
159
+ onChangeText?.(e.target.value),
117
160
  // Like React Native: Return in a multiline input inserts a newline
118
161
  // unless submitBehavior or blurOnSubmit asks it to submit.
119
- onKeyDown: (e: any) => {
162
+ onKeyDown: (e: KeyboardEvent) => {
120
163
  const submits =
121
164
  !multiline || submitBehavior === "submit" || blurOnSubmit === true;
122
165
  if (e.key === "Enter" && !e.shiftKey && submits) onSubmitEditing?.();
@@ -133,7 +176,7 @@ vi.mock("react-native", () => {
133
176
  accessibilityLabel,
134
177
  accessibilityState: _accessibilityState,
135
178
  ...props
136
- }: any) =>
179
+ }: TouchableOpacityProps) =>
137
180
  // react-native-web maps the accessibility props to role and aria-label.
138
181
  React.createElement(
139
182
  accessibilityRole === "button" ? "button" : "div",
@@ -146,7 +189,7 @@ vi.mock("react-native", () => {
146
189
  },
147
190
  children,
148
191
  ),
149
- View: ({ children, ...props }: any) =>
192
+ View: ({ children, ...props }: { children?: ReactNode }) =>
150
193
  React.createElement("div", props, children),
151
194
  };
152
195
  });
@@ -163,6 +206,7 @@ describe("CopilotChat", () => {
163
206
  hoisted.mockAgent.isRunning = false;
164
207
  hoisted.mockAgent.addMessage = vi.fn();
165
208
  hoisted.mockRunAgent.mockResolvedValue(undefined);
209
+ hoisted.platform.OS = "ios";
166
210
  });
167
211
 
168
212
  it("renders empty state when there are no messages", () => {
@@ -392,4 +436,26 @@ describe("CopilotChat", () => {
392
436
  expect(calls[0][0].id).toEqual(expect.any(String));
393
437
  expect(calls[0][0].id).not.toBe(calls[1][0].id);
394
438
  });
439
+
440
+ describe("message input height", () => {
441
+ // Without rows, a browser draws a <textarea> two lines tall.
442
+ it("starts one line tall on the web", () => {
443
+ hoisted.platform.OS = "web";
444
+ const { getByTestId } = render(<CopilotChat />);
445
+
446
+ expect(getByTestId("text-input").getAttribute("rows")).toBe("1");
447
+ });
448
+
449
+ // Android pins a multiline input to numberOfLines, so a fixed count stops
450
+ // the input from growing up to its maxHeight.
451
+ it.each(["android", "ios"] as const)(
452
+ "sets no fixed line count on %s",
453
+ (os) => {
454
+ hoisted.platform.OS = os;
455
+ const { getByTestId } = render(<CopilotChat />);
456
+
457
+ expect(getByTestId("text-input").getAttribute("rows")).toBeNull();
458
+ },
459
+ );
460
+ });
395
461
  });
@@ -1,6 +1,8 @@
1
1
  import React, { createRef } from "react";
2
+ import type { ReactNode } from "react";
2
3
  import { render, act } from "@testing-library/react";
3
4
  import { describe, it, expect, beforeEach, vi } from "vitest";
5
+ import type { BottomSheetProps } from "@gorhom/bottom-sheet";
4
6
 
5
7
  // ---------------------------------------------------------------------------
6
8
  // Mocks
@@ -13,16 +15,14 @@ const hoisted = vi.hoisted(() => {
13
15
  return {
14
16
  snapToIndex,
15
17
  close,
16
- lastOnClose: null as (() => void) | null,
17
- lastSnapPoints: null as (string | number)[] | null,
18
- lastIndex: null as number | null,
18
+ lastSheetProps: null as BottomSheetProps | null,
19
19
  };
20
20
  });
21
21
 
22
22
  // Mock react-native primitives used in CopilotModal
23
23
  vi.mock("react-native", () => ({
24
24
  StyleSheet: {
25
- create: (s: Record<string, unknown>) => s,
25
+ create: <T,>(styles: T) => styles,
26
26
  },
27
27
  View: "View",
28
28
  }));
@@ -33,17 +33,15 @@ vi.mock("@gorhom/bottom-sheet", () => {
33
33
 
34
34
  // BottomSheet stores its ref and captures props for assertions
35
35
  const BottomSheet = React.forwardRef(function MockBottomSheet(
36
- props: any,
37
- ref: any,
36
+ props: BottomSheetProps,
37
+ ref: React.Ref<{ snapToIndex: () => void; close: () => void }>,
38
38
  ) {
39
39
  React.useImperativeHandle(ref, () => ({
40
40
  snapToIndex: hoisted.snapToIndex,
41
41
  close: hoisted.close,
42
42
  }));
43
43
 
44
- hoisted.lastOnClose = props.onClose ?? null;
45
- hoisted.lastSnapPoints = props.snapPoints ?? null;
46
- hoisted.lastIndex = props.index ?? null;
44
+ hoisted.lastSheetProps = props;
47
45
 
48
46
  return React.createElement(
49
47
  "mock-bottom-sheet",
@@ -52,17 +50,16 @@ vi.mock("@gorhom/bottom-sheet", () => {
52
50
  );
53
51
  });
54
52
 
55
- const BottomSheetView = (props: any) =>
53
+ const BottomSheetView = (props: { children?: ReactNode }) =>
56
54
  React.createElement(
57
55
  "mock-bottom-sheet-view",
58
56
  { "data-testid": "bottom-sheet-view" },
59
57
  props.children,
60
58
  );
61
59
 
62
- const BottomSheetBackdrop = (props: any) =>
63
- React.createElement("mock-backdrop", props);
60
+ const BottomSheetBackdrop = () => React.createElement("mock-backdrop");
64
61
 
65
- const BottomSheetFlatList = (props: any) =>
62
+ const BottomSheetFlatList = (props: { children?: ReactNode }) =>
66
63
  React.createElement(
67
64
  "mock-bottom-sheet-flatlist",
68
65
  { "data-testid": "bottom-sheet-flatlist" },
@@ -81,7 +78,7 @@ vi.mock("@gorhom/bottom-sheet", () => {
81
78
  // Mock CopilotChat (B4's component — may not exist yet in this worktree)
82
79
  vi.mock("../CopilotChat", () => {
83
80
  const React = require("react");
84
- const CopilotChat = (props: any) =>
81
+ const CopilotChat = (props: Record<string, unknown>) =>
85
82
  React.createElement("mock-copilot-chat", {
86
83
  "data-testid": "copilot-chat",
87
84
  ...props,
@@ -101,30 +98,36 @@ describe("CopilotModal", () => {
101
98
  beforeEach(() => {
102
99
  hoisted.snapToIndex.mockClear();
103
100
  hoisted.close.mockClear();
104
- hoisted.lastOnClose = null;
105
- hoisted.lastSnapPoints = null;
106
- hoisted.lastIndex = null;
101
+ hoisted.lastSheetProps = null;
107
102
  });
108
103
 
109
104
  // ── Rendering ───────────────────────────────────────────────────────────
110
105
 
111
106
  describe("rendering", () => {
112
- it("renders the bottom sheet with default snap points", () => {
107
+ it("opens to one snap point at 90% by default", () => {
113
108
  render(<CopilotModal />);
114
109
 
115
- expect(hoisted.lastSnapPoints).toEqual(["50%", "90%"]);
110
+ expect(hoisted.lastSheetProps?.snapPoints).toEqual(["90%"]);
111
+ });
112
+
113
+ it("sizes the sheet from its snap points, not from the chat content", () => {
114
+ render(<CopilotModal />);
115
+
116
+ expect(hoisted.lastSheetProps?.enableDynamicSizing).toBe(false);
116
117
  });
117
118
 
118
119
  it("starts closed (index -1)", () => {
119
120
  render(<CopilotModal />);
120
121
 
121
- expect(hoisted.lastIndex).toBe(-1);
122
+ expect(hoisted.lastSheetProps?.index).toBe(-1);
122
123
  });
123
124
 
124
- it("embeds CopilotChat inside the sheet", () => {
125
+ it("puts CopilotChat in a flex: 1 view, not in BottomSheetView", () => {
125
126
  const { getByTestId } = render(<CopilotModal />);
126
127
 
127
- expect(getByTestId("copilot-chat")).toBeTruthy();
128
+ const chat = getByTestId("copilot-chat");
129
+ expect(chat.closest("mock-bottom-sheet-view")).toBeNull();
130
+ expect(chat.parentElement?.style.flexGrow).toBe("1");
128
131
  });
129
132
  });
130
133
 
@@ -159,7 +162,7 @@ describe("CopilotModal", () => {
159
162
 
160
163
  // Simulate bottom-sheet calling onClose
161
164
  act(() => {
162
- hoisted.lastOnClose?.();
165
+ hoisted.lastSheetProps?.onClose?.();
163
166
  });
164
167
 
165
168
  expect(onDismiss).toHaveBeenCalledTimes(1);
@@ -172,7 +175,7 @@ describe("CopilotModal", () => {
172
175
  );
173
176
 
174
177
  act(() => {
175
- hoisted.lastOnClose?.();
178
+ hoisted.lastSheetProps?.onClose?.();
176
179
  });
177
180
 
178
181
  expect(onDismiss).not.toHaveBeenCalled();
@@ -185,7 +188,11 @@ describe("CopilotModal", () => {
185
188
  it("uses provided snap points", () => {
186
189
  render(<CopilotModal snapPoints={["25%", "75%", "100%"]} />);
187
190
 
188
- expect(hoisted.lastSnapPoints).toEqual(["25%", "75%", "100%"]);
191
+ expect(hoisted.lastSheetProps?.snapPoints).toEqual([
192
+ "25%",
193
+ "75%",
194
+ "100%",
195
+ ]);
189
196
  });
190
197
 
191
198
  it("opens at the specified initialSnapIndex", () => {