@copilotkit/react-native 1.83.0 → 2.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/USAGE.md +2 -2
- package/dist/{CopilotKitProvider-BUVBq9LN.d.mts → CopilotKitProvider-BWjzCdHN.d.mts} +29 -2
- package/dist/{CopilotKitProvider-BVPr5t83.d.cts → CopilotKitProvider-Btm10msB.d.cts} +29 -2
- package/dist/{CopilotKitProvider-CjoPnabW.cjs → CopilotKitProvider-Byw3cqe2.cjs} +13 -10
- package/dist/CopilotKitProvider-Byw3cqe2.cjs.map +1 -0
- package/dist/{CopilotKitProvider-D8sn7G_C.mjs → CopilotKitProvider-CE4bc6CP.mjs} +9 -5
- package/dist/CopilotKitProvider-CE4bc6CP.mjs.map +1 -0
- package/dist/Markdown-1ips7myr.d.cts +52 -0
- package/dist/Markdown-C6AsLHmd.mjs +47 -0
- package/dist/Markdown-C6AsLHmd.mjs.map +1 -0
- package/dist/Markdown-C_9Re36O.cjs +60 -0
- package/dist/Markdown-C_9Re36O.cjs.map +1 -0
- package/dist/Markdown-JsYh7oSA.d.mts +52 -0
- package/dist/MarkdownRendererContext-BRNe808d.cjs +72 -0
- package/dist/MarkdownRendererContext-BRNe808d.cjs.map +1 -0
- package/dist/MarkdownRendererContext-CAnuohIS.mjs +21 -0
- package/dist/MarkdownRendererContext-CAnuohIS.mjs.map +1 -0
- package/dist/components/index.cjs +20 -106
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +1 -46
- package/dist/components/index.d.mts +1 -46
- package/dist/components/index.mjs +13 -98
- package/dist/components/index.mjs.map +1 -1
- package/dist/headless.cjs +22 -22
- package/dist/headless.d.cts +4 -3
- package/dist/headless.d.mts +4 -3
- package/dist/headless.mjs +3 -3
- package/dist/index.cjs +32 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +6 -4
- package/dist/index.mjs.map +1 -1
- package/dist/polyfills/encoding.cjs +1 -1
- package/dist/polyfills/streams.cjs +1 -1
- package/package.json +6 -9
- package/scripts/measure-headless.mjs +2 -2
- package/src/CopilotChat.tsx +2 -2
- package/src/CopilotKitProvider.tsx +17 -4
- package/src/__mocks__/test-copilotkit.tsx +3 -3
- package/src/__tests__/attachments-integration.test.tsx +2 -2
- package/src/__tests__/copilot-chat-agentid.test.tsx +2 -2
- package/src/__tests__/copilot-chat-attachments.test.tsx +2 -2
- package/src/__tests__/copilot-popup.test.tsx +2 -2
- package/src/__tests__/copilot-sidebar.test.tsx +2 -2
- package/src/__tests__/copilotkit-provider.test.tsx +2 -2
- package/src/__tests__/headless-entry-surface.test.ts +33 -12
- package/src/__tests__/headless-integration.test.tsx +4 -2
- package/src/__tests__/headless-value-exports.test.ts +2 -2
- package/src/components/CopilotChat.tsx +2 -5
- package/src/components/Markdown.tsx +62 -100
- package/src/components/MarkdownRendererContext.tsx +40 -0
- package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +2 -2
- package/src/components/__tests__/CopilotChat.test.tsx +2 -2
- package/src/components/__tests__/Markdown.code-alias.test.tsx +59 -0
- package/src/components/__tests__/Markdown.test.tsx +6 -75
- package/src/components/messages/AssistantMessage.tsx +22 -1
- package/src/components/messages/__tests__/AssistantMessage.provider-renderer.test.tsx +73 -0
- package/src/components/messages/__tests__/markdown-renderer-config.test.tsx +66 -0
- package/src/headless.ts +8 -8
- package/src/index.ts +19 -2
- package/tsdown.config.ts +0 -1
- package/vitest.config.mjs +0 -7
- package/dist/CopilotKitProvider-CjoPnabW.cjs.map +0 -1
- package/dist/CopilotKitProvider-D8sn7G_C.mjs.map +0 -1
- package/dist/chunk-C0xms8kb.cjs +0 -34
- package/src/__mocks__/react-native-streamdown.ts +0 -16
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["useAgent","useCopilotKit","styles"],"sources":["../src/hooks/use-attachments.ts","../src/CopilotChat.tsx","../src/CopilotModal.tsx","../src/CopilotSidebar.tsx","../src/CopilotPopup.tsx"],"sourcesContent":["// packages/react-native/src/hooks/use-attachments.ts\nimport { useCallback, useRef, useState } from \"react\";\nimport {\n randomUUID,\n getModalityFromMimeType,\n formatFileSize,\n} from \"@copilotkit/shared\";\nimport type {\n Attachment,\n AttachmentUploadResult,\n AttachmentUploadErrorReason,\n} from \"@copilotkit/shared\";\nimport * as DocumentPicker from \"expo-document-picker\";\nimport * as FileSystem from \"expo-file-system\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/**\n * Platform-neutral file descriptor for React Native.\n * Replaces the web `File` object in all attachment APIs.\n */\nexport interface NativeFileInput {\n /** Local file URI (e.g. `file:///path/to/file`). */\n uri: string;\n /** Filename with extension. */\n name: string;\n /** File size in bytes. */\n size: number;\n /** MIME type (e.g. `\"image/jpeg\"`). */\n mimeType: string;\n}\n\n/**\n * React Native variant of AttachmentsConfig.\n * Identical to the shared AttachmentsConfig except `onUpload` receives\n * a `NativeFileInput` instead of a web `File`.\n */\nexport interface NativeAttachmentsConfig {\n /** Enable file attachments in the chat input. */\n enabled: boolean;\n /** MIME type filter for the file picker, default all files. */\n accept?: string;\n /** Maximum file size in bytes, default 20MB (20 * 1024 * 1024). */\n maxSize?: number;\n /** Custom upload handler. Receives the native file descriptor. */\n onUpload?: (\n file: NativeFileInput,\n ) => AttachmentUploadResult | Promise<AttachmentUploadResult>;\n /** Called when an attachment fails validation or upload. */\n onUploadFailed?: (error: {\n reason: AttachmentUploadErrorReason;\n file: NativeFileInput;\n message: string;\n }) => void;\n}\n\nexport interface UseNativeAttachmentsProps {\n config?: NativeAttachmentsConfig;\n}\n\nexport interface UseNativeAttachmentsReturn {\n /** Currently selected attachments (uploading + ready). */\n attachments: Attachment[];\n /** Whether attachments are enabled. */\n enabled: boolean;\n /** Open the native document picker. */\n openPicker: () => Promise<void>;\n /** Process an array of NativeFileInput objects (validate, read, add to state). */\n processFiles: (files: NativeFileInput[]) => Promise<void>;\n /** Remove an attachment by ID. */\n removeAttachment: (id: string) => void;\n /** Consume ready attachments and clear the queue. Returns the consumed attachments. */\n consumeAttachments: () => Attachment[];\n}\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_MAX_SIZE = 20 * 1024 * 1024; // 20 MB\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * React Native hook that manages file attachment state -- picking, uploading,\n * and lifecycle. All returned callbacks are referentially stable via useCallback.\n *\n * This is the RN counterpart of the web `useAttachments` hook from\n * `@copilotkit/react-core`. It replaces web APIs (FileReader, DragEvent,\n * HTMLInputElement) with Expo modules (expo-document-picker, expo-file-system).\n */\nexport function useAttachments({\n config,\n}: UseNativeAttachmentsProps): UseNativeAttachmentsReturn {\n const enabled = config?.enabled ?? false;\n\n const [attachments, setAttachments] = useState<Attachment[]>([]);\n\n // Refs for stable callbacks to read latest values\n const configRef = useRef(config);\n configRef.current = config;\n const attachmentsRef = useRef<Attachment[]>([]);\n attachmentsRef.current = attachments;\n\n /**\n * Simple MIME accept filter for NativeFileInput.\n * Handles wildcards like \"image/*\" and exact types like \"application/pdf\".\n * Comma-separated lists are supported.\n */\n const matchesAccept = useCallback(\n (file: NativeFileInput, accept: string): boolean => {\n if (!accept || accept === \"*/*\") return true;\n const filters = accept.split(\",\").map((f) => f.trim());\n return filters.some((filter) => {\n if (filter.startsWith(\".\")) {\n return file.name.toLowerCase().endsWith(filter.toLowerCase());\n }\n if (filter.endsWith(\"/*\")) {\n const prefix = filter.slice(0, -2);\n return file.mimeType.startsWith(prefix + \"/\");\n }\n return file.mimeType === filter;\n });\n },\n [],\n );\n\n const processFiles = useCallback(\n async (files: NativeFileInput[]) => {\n const cfg = configRef.current;\n const accept = cfg?.accept ?? \"*/*\";\n const maxSize = cfg?.maxSize ?? DEFAULT_MAX_SIZE;\n\n // Filter by accept type\n const rejectedFiles = files.filter((f) => !matchesAccept(f, accept));\n for (const file of rejectedFiles) {\n cfg?.onUploadFailed?.({\n reason: \"invalid-type\",\n file,\n message: `File \"${file.name}\" is not accepted. Supported types: ${accept}`,\n });\n }\n\n const validFiles = files.filter((f) => matchesAccept(f, accept));\n\n for (const file of validFiles) {\n // Size check\n if (file.size > maxSize) {\n cfg?.onUploadFailed?.({\n reason: \"file-too-large\",\n file,\n message: `File \"${file.name}\" exceeds the maximum size of ${formatFileSize(maxSize)}`,\n });\n continue;\n }\n\n const modality = getModalityFromMimeType(file.mimeType);\n const placeholderId = randomUUID();\n const placeholder: Attachment = {\n id: placeholderId,\n type: modality,\n source: { type: \"data\", value: \"\", mimeType: file.mimeType },\n filename: file.name,\n size: file.size,\n status: \"uploading\",\n };\n\n setAttachments((prev) => [...prev, placeholder]);\n\n try {\n let source: Attachment[\"source\"];\n let uploadMetadata: Record<string, unknown> | undefined;\n\n if (cfg?.onUpload) {\n const { metadata: meta, ...uploadSource } =\n await cfg.onUpload(file);\n source = uploadSource;\n uploadMetadata = meta;\n } else {\n // Default: read file as base64 via expo-file-system\n const base64 = await FileSystem.readAsStringAsync(file.uri, {\n encoding: FileSystem.EncodingType.Base64,\n });\n source = { type: \"data\", value: base64, mimeType: file.mimeType };\n }\n\n setAttachments((prev) =>\n prev.map((att) =>\n att.id === placeholderId\n ? {\n ...att,\n source,\n status: \"ready\" as const,\n metadata: uploadMetadata,\n }\n : att,\n ),\n );\n } catch (error) {\n // Remove placeholder on failure\n setAttachments((prev) =>\n prev.filter((att) => att.id !== placeholderId),\n );\n console.error(`[CopilotKit] Failed to upload \"${file.name}\":`, error);\n cfg?.onUploadFailed?.({\n reason: \"upload-failed\",\n file,\n message:\n error instanceof Error\n ? error.message\n : `Failed to upload \"${file.name}\"`,\n });\n }\n }\n },\n [matchesAccept],\n );\n\n const openPicker = useCallback(async () => {\n const cfg = configRef.current;\n const accept = cfg?.accept ?? \"*/*\";\n\n // Convert accept string to array for DocumentPicker\n const typeArray = accept\n .split(\",\")\n .map((t) => t.trim())\n .filter(Boolean);\n\n try {\n const result = await DocumentPicker.getDocumentAsync({\n type: typeArray.length > 0 ? typeArray : [\"*/*\"],\n copyToCacheDirectory: true,\n multiple: true,\n });\n\n if (result.canceled || !result.assets?.length) return;\n\n const nativeFiles: NativeFileInput[] = result.assets.map((asset) => ({\n uri: asset.uri,\n name: asset.name ?? \"unknown\",\n size: asset.size ?? 0,\n mimeType: asset.mimeType ?? \"application/octet-stream\",\n }));\n\n await processFiles(nativeFiles);\n } catch (error) {\n console.error(\"[CopilotKit] Document picker error:\", error);\n }\n }, [processFiles]);\n\n const removeAttachment = useCallback((id: string) => {\n setAttachments((prev) => prev.filter((a) => a.id !== id));\n }, []);\n\n const consumeAttachments = useCallback(() => {\n const ready = attachmentsRef.current.filter((a) => a.status === \"ready\");\n if (ready.length === 0) return ready;\n setAttachments((prev) => prev.filter((a) => a.status !== \"ready\"));\n return ready;\n }, []);\n\n return {\n attachments,\n enabled,\n openPicker,\n processFiles,\n removeAttachment,\n consumeAttachments,\n };\n}\n","import React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n} from \"react\";\nimport type { ReactNode } from \"react\";\nimport { useAgent } from \"@copilotkit/react-core/v2/headless\";\nimport { useCopilotKit } from \"@copilotkit/react-core/v2/context\";\nimport { DEFAULT_AGENT_ID, randomUUID } from \"@copilotkit/shared\";\nimport type { InputContent } from \"@copilotkit/shared\";\nimport type { CopilotKitCoreErrorCode } from \"@copilotkit/core\";\nimport { useAttachments } from \"./hooks/use-attachments\";\nimport type { NativeAttachmentsConfig } from \"./hooks/use-attachments\";\nimport type { Attachment } from \"@copilotkit/shared\";\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\nexport interface CopilotChatContextValue {\n /** The resolved agent instance. */\n agent: any;\n /** Whether the agent is currently running. */\n isRunning: boolean;\n /** Current messages in the conversation. */\n messages: any[];\n /** Currently selected attachments (uploading + ready). */\n attachments: Attachment[];\n /** Whether attachments are enabled. */\n attachmentsEnabled: boolean;\n /** Open the native document picker to add files. */\n openPicker: () => Promise<void>;\n /** Remove an attachment by ID. */\n removeAttachment: (id: string) => void;\n /**\n * Submit a message with optional attachments.\n * Handles consuming ready attachments, building InputContent[],\n * calling agent.addMessage, and running the agent.\n */\n submitMessage: (text: string) => Promise<void>;\n}\n\nconst CopilotChatCtx = createContext<CopilotChatContextValue | null>(null);\n\n/**\n * Hook to access the CopilotChat context from child components.\n * Must be called inside a `<CopilotChat>` component tree.\n */\nexport function useCopilotChatContext(): CopilotChatContextValue {\n const ctx = useContext(CopilotChatCtx);\n if (!ctx) {\n throw new Error(\n \"useCopilotChatContext must be used within a <CopilotChat> component\",\n );\n }\n return ctx;\n}\n\n// ---------------------------------------------------------------------------\n// Props\n// ---------------------------------------------------------------------------\n\nexport interface CopilotChatBaseProps {\n /**\n * The agent ID to use for this chat session.\n * Matches the web SDK's CopilotChat `agentId` prop.\n *\n * Resolution order: `agentId` > `agentName` > `\"default\"`\n */\n agentId?: string;\n\n /**\n * @deprecated Use `agentId` instead. `agentName` is kept for backwards\n * compatibility and will be removed in a future release.\n */\n agentName?: string;\n\n /**\n * Thread ID for this chat session. When provided, the chat will resume\n * the specified thread. Matches the web SDK's CopilotChat `threadId` prop.\n */\n threadId?: string;\n\n /**\n * Error handler scoped to this chat's agent. Fires in addition to the\n * provider-level onError (does not suppress it). Receives only errors\n * whose context.agentId matches this chat's agent.\n */\n onError?: (event: {\n error: Error;\n code: CopilotKitCoreErrorCode;\n context: Record<string, any>;\n }) => void | Promise<void>;\n\n /**\n * Throttle interval (in milliseconds) for re-renders triggered by message\n * change notifications. Overrides the provider-level `defaultThrottleMs`\n * for this chat instance. Forwarded to the internal `useAgent()` hook.\n *\n * @default undefined -- inherits from provider `defaultThrottleMs`;\n * if that is also unset, re-renders are unthrottled.\n */\n throttleMs?: number;\n\n /**\n * Enable multimodal file attachments (images, audio, video, documents).\n * Pass a NativeAttachmentsConfig object to configure file picking behavior.\n */\n attachments?: NativeAttachmentsConfig;\n\n /**\n * Optional children rendered inside the chat context.\n */\n children?: ReactNode;\n}\n\nexport interface CopilotChatProps extends CopilotChatBaseProps {\n /** Passthrough props are forwarded to consumers via the agent context. */\n [key: string]: unknown;\n}\n\n/**\n * Headless CopilotChat component for React Native.\n *\n * Wires up the `useAgent` hook with `agentId` resolution and renders children.\n * Unlike the web SDK's CopilotChat, this component does not render any UI\n * elements -- consumers provide their own React Native views.\n *\n * Children can access chat state via `useCopilotChatContext()`.\n *\n * ```tsx\n * import { CopilotChat, useCopilotChatContext } from \"@copilotkit/react-native\";\n *\n * function MyChatUI() {\n * const { messages, submitMessage, attachments, openPicker } = useCopilotChatContext();\n * // ... render your UI\n * }\n *\n * <CopilotChat agentId=\"my-agent\" attachments={{ enabled: true }}>\n * <MyChatUI />\n * </CopilotChat>\n * ```\n */\nexport function CopilotChat({\n agentId,\n agentName,\n threadId,\n onError,\n throttleMs,\n attachments: attachmentsConfig,\n children,\n ..._rest\n}: CopilotChatProps) {\n const resolvedAgentId = agentId ?? agentName ?? DEFAULT_AGENT_ID;\n\n // Deprecation warning (dev only, fires once per mount)\n const warnedRef = useRef(false);\n useEffect(() => {\n if (\n agentName !== undefined &&\n agentId === undefined &&\n !warnedRef.current\n ) {\n warnedRef.current = true;\n if (typeof __DEV__ === \"undefined\" || __DEV__) {\n console.warn(\n \"[CopilotKit] agentName is deprecated, use agentId instead\",\n );\n }\n }\n }, [agentName, agentId]);\n\n const { agent } = useAgent({ agentId: resolvedAgentId, throttleMs });\n\n // Set threadId on the agent when provided\n useEffect(() => {\n if (threadId) {\n agent.threadId = threadId;\n }\n }, [agent, threadId]);\n\n // onError subscription -- forward core errors scoped to this chat's agent\n const { copilotkit } = useCopilotKit();\n const onErrorRef = useRef(onError);\n useEffect(() => {\n onErrorRef.current = onError;\n }, [onError]);\n\n useEffect(() => {\n if (!onErrorRef.current) return;\n\n const subscription = copilotkit.subscribe({\n onError: (event) => {\n // Only forward errors that match this chat's agent\n if (\n event.context?.agentId === resolvedAgentId ||\n !event.context?.agentId\n ) {\n onErrorRef.current?.({\n error: event.error,\n code: event.code,\n context: event.context,\n });\n }\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n }, [copilotkit, resolvedAgentId]);\n\n // Attachments\n const {\n attachments: selectedAttachments,\n enabled: attachmentsEnabled,\n openPicker,\n removeAttachment,\n consumeAttachments,\n } = useAttachments({ config: attachmentsConfig });\n\n // Submit handler -- mirrors web CopilotChat.tsx lines 234-288\n const submitMessage = useCallback(\n async (value: string) => {\n // Block if uploads in progress\n const hasUploading = selectedAttachments.some(\n (a) => a.status === \"uploading\",\n );\n if (hasUploading) {\n console.error(\n \"[CopilotKit] Cannot send while attachments are uploading\",\n );\n return;\n }\n\n const readyAttachments = consumeAttachments();\n\n if (readyAttachments.length > 0) {\n const contentParts: InputContent[] = [];\n if (value.trim()) {\n contentParts.push({ type: \"text\", text: value });\n }\n for (const att of readyAttachments) {\n contentParts.push({\n type: att.type,\n source: att.source,\n metadata: {\n ...(att.filename ? { filename: att.filename } : {}),\n ...att.metadata,\n },\n } as InputContent);\n }\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: contentParts,\n });\n } else {\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: value,\n });\n }\n\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: runAgent failed\", error);\n }\n },\n // copilotkit is intentionally excluded -- it is a stable ref that never changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent, selectedAttachments, consumeAttachments],\n );\n\n const contextValue: CopilotChatContextValue = {\n agent,\n isRunning: agent.isRunning,\n messages: agent.messages,\n attachments: selectedAttachments,\n attachmentsEnabled,\n openPicker,\n removeAttachment,\n submitMessage,\n };\n\n return (\n <CopilotChatCtx.Provider value={contextValue}>\n {children}\n </CopilotChatCtx.Provider>\n );\n}\n","import React, { type ReactNode } from \"react\";\nimport { CopilotChat, type CopilotChatProps } from \"./CopilotChat\";\n\nexport interface CopilotModalProps extends CopilotChatProps {\n /**\n * Optional children rendered inside the modal context.\n */\n children?: ReactNode;\n}\n\n/**\n * Headless CopilotModal component for React Native.\n *\n * A thin wrapper around CopilotChat that mirrors the web SDK's CopilotModal\n * API surface. On React Native, modal presentation is handled by the consumer\n * (e.g. React Native's `Modal` component) -- this component only provides\n * the agent wiring and prop resolution.\n *\n * ```tsx\n * import { CopilotModal } from \"@copilotkit/react-native\";\n * import { Modal } from \"react-native\";\n *\n * <Modal visible={isOpen}>\n * <CopilotModal agentId=\"my-agent\">\n * <MyChatUI />\n * </CopilotModal>\n * </Modal>\n * ```\n */\nexport function CopilotModal({ children, ...props }: CopilotModalProps) {\n return <CopilotChat {...props}>{children}</CopilotChat>;\n}\n","import React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\";\nimport type { ReactNode } from \"react\";\nimport {\n Animated,\n Dimensions,\n Pressable,\n StyleSheet,\n Text,\n useWindowDimensions,\n View,\n} from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\nimport { CopilotChat } from \"./CopilotChat\";\nimport type { CopilotChatBaseProps } from \"./CopilotChat\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface CopilotSidebarHandle {\n /** Slide the drawer open. */\n open(): void;\n /** Slide the drawer closed. */\n close(): void;\n /** Toggle the drawer open/closed. */\n toggle(): void;\n}\n\nexport interface CopilotSidebarProps extends Omit<\n CopilotChatBaseProps,\n \"children\"\n> {\n /**\n * Start the drawer in the open position.\n * @default false\n */\n defaultOpen?: boolean;\n\n /**\n * Width of the drawer panel. Accepts a number (points) or a percentage\n * string (e.g. `\"85%\"`). Defaults to 85% of the screen width.\n */\n width?: number | string;\n\n /**\n * Title displayed in the drawer header bar.\n * @default \"Copilot\"\n */\n headerTitle?: string;\n\n /**\n * Show a floating action button to toggle the drawer.\n * @default true\n */\n showToggleButton?: boolean;\n\n /** Called after the drawer finishes opening. */\n onOpen?: () => void;\n\n /** Called after the drawer finishes closing. */\n onClose?: () => void;\n\n /** Custom style applied to the drawer container. */\n style?: ViewStyle;\n\n /** Content rendered inside the drawer below the chat area. */\n children?: ReactNode;\n}\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nconst ANIMATION_DURATION_MS = 300;\nconst DEFAULT_HEADER_TITLE = \"Copilot\";\nconst BACKDROP_OPACITY = 0.4;\nconst FAB_SIZE = 56;\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\n/**\n * CopilotSidebar -- a slide-in drawer from the right edge of the screen\n * that wraps CopilotChat for React Native.\n *\n * ```tsx\n * import { CopilotSidebar } from \"@copilotkit/react-native\";\n *\n * const ref = useRef<CopilotSidebarHandle>(null);\n *\n * <CopilotSidebar\n * ref={ref}\n * agentId=\"my-agent\"\n * headerTitle=\"Assistant\"\n * defaultOpen={false}\n * />\n * ```\n */\nexport const CopilotSidebar = forwardRef<\n CopilotSidebarHandle,\n CopilotSidebarProps\n>(function CopilotSidebar(\n {\n agentId,\n agentName,\n threadId,\n onError,\n throttleMs,\n defaultOpen = false,\n width: widthProp,\n headerTitle = DEFAULT_HEADER_TITLE,\n showToggleButton = true,\n onOpen,\n onClose,\n style,\n children,\n ...rest\n },\n ref,\n) {\n const { width: screenWidth } = useWindowDimensions();\n\n // Resolve drawer width ---------------------------------------------------\n const drawerWidth = resolveWidth(widthProp, screenWidth);\n\n // Animation & open state -------------------------------------------------\n const [isOpen, setIsOpen] = useState(defaultOpen);\n const slideAnim = useRef(\n new Animated.Value(defaultOpen ? 0 : drawerWidth),\n ).current;\n\n // Keep the animated value in sync when drawerWidth changes while closed\n useEffect(() => {\n if (!isOpen) {\n slideAnim.setValue(drawerWidth);\n }\n }, [drawerWidth, isOpen, slideAnim]);\n\n const animateTo = useCallback(\n (toValue: number, cb?: () => void) => {\n Animated.timing(slideAnim, {\n toValue,\n duration: ANIMATION_DURATION_MS,\n useNativeDriver: true,\n }).start(({ finished }) => {\n if (finished) cb?.();\n });\n },\n [slideAnim],\n );\n\n const open = useCallback(() => {\n setIsOpen(true);\n animateTo(0, onOpen);\n }, [animateTo, onOpen]);\n\n const close = useCallback(() => {\n animateTo(drawerWidth, () => {\n setIsOpen(false);\n onClose?.();\n });\n }, [animateTo, drawerWidth, onClose]);\n\n const toggle = useCallback(() => {\n if (isOpen) {\n close();\n } else {\n open();\n }\n }, [isOpen, open, close]);\n\n useImperativeHandle(ref, () => ({ open, close, toggle }), [\n open,\n close,\n toggle,\n ]);\n\n // Callbacks stored in refs for stable animation closures -----------------\n const onOpenRef = useRef(onOpen);\n const onCloseRef = useRef(onClose);\n useEffect(() => {\n onOpenRef.current = onOpen;\n }, [onOpen]);\n useEffect(() => {\n onCloseRef.current = onClose;\n }, [onClose]);\n\n // -----------------------------------------------------------------------\n // Render\n // -----------------------------------------------------------------------\n return (\n <>\n {/* Backdrop */}\n {isOpen && (\n <Pressable\n style={styles.backdrop}\n onPress={close}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Close sidebar\"\n testID=\"copilot-sidebar-backdrop\"\n />\n )}\n\n {/* Drawer */}\n {isOpen && (\n <Animated.View\n style={[\n styles.drawer,\n { width: drawerWidth, transform: [{ translateX: slideAnim }] },\n style,\n ]}\n testID=\"copilot-sidebar-drawer\"\n >\n {/* Header */}\n <View style={styles.header}>\n <Text style={styles.headerTitle}>{headerTitle}</Text>\n <Pressable\n onPress={close}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Close\"\n hitSlop={8}\n testID=\"copilot-sidebar-close\"\n >\n <Text style={styles.closeButton}>{\"✕\"}</Text>\n </Pressable>\n </View>\n\n {/* Chat area */}\n <View style={styles.chatContainer}>\n <CopilotChat\n agentId={agentId}\n agentName={agentName}\n threadId={threadId}\n onError={onError}\n throttleMs={throttleMs}\n {...rest}\n >\n {children}\n </CopilotChat>\n </View>\n </Animated.View>\n )}\n\n {/* Floating action button */}\n {showToggleButton && !isOpen && (\n <Pressable\n style={styles.fab}\n onPress={open}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Open sidebar\"\n testID=\"copilot-sidebar-fab\"\n >\n <Text style={styles.fabIcon}>{\"💬\"}</Text>\n </Pressable>\n )}\n </>\n );\n});\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction resolveWidth(\n widthProp: number | string | undefined,\n screenWidth: number,\n): number {\n if (widthProp === undefined) {\n return Math.round(screenWidth * 0.85);\n }\n if (typeof widthProp === \"number\") {\n return widthProp;\n }\n // Percentage string, e.g. \"85%\"\n const pctMatch = String(widthProp).match(/^(\\d+(?:\\.\\d+)?)%$/);\n if (pctMatch) {\n return Math.round(screenWidth * (parseFloat(pctMatch[1]) / 100));\n }\n // Fallback: try parsing as number\n const parsed = parseFloat(widthProp);\n return isNaN(parsed) ? Math.round(screenWidth * 0.85) : parsed;\n}\n\n// ---------------------------------------------------------------------------\n// Styles\n// ---------------------------------------------------------------------------\n\nconst styles = StyleSheet.create({\n backdrop: {\n ...StyleSheet.absoluteFill,\n backgroundColor: `rgba(0, 0, 0, ${BACKDROP_OPACITY})`,\n zIndex: 999,\n },\n drawer: {\n position: \"absolute\",\n top: 0,\n right: 0,\n bottom: 0,\n backgroundColor: \"#ffffff\",\n zIndex: 1000,\n shadowColor: \"#000\",\n shadowOffset: { width: -2, height: 0 },\n shadowOpacity: 0.25,\n shadowRadius: 8,\n elevation: 16,\n },\n header: {\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n paddingHorizontal: 16,\n paddingVertical: 12,\n borderBottomWidth: StyleSheet.hairlineWidth,\n borderBottomColor: \"#e0e0e0\",\n },\n headerTitle: {\n fontSize: 18,\n fontWeight: \"600\",\n color: \"#1a1a1a\",\n },\n closeButton: {\n fontSize: 20,\n color: \"#666\",\n padding: 4,\n },\n chatContainer: {\n flex: 1,\n },\n fab: {\n position: \"absolute\",\n bottom: 24,\n right: 24,\n width: FAB_SIZE,\n height: FAB_SIZE,\n borderRadius: FAB_SIZE / 2,\n backgroundColor: \"#007AFF\",\n alignItems: \"center\",\n justifyContent: \"center\",\n shadowColor: \"#000\",\n shadowOffset: { width: 0, height: 2 },\n shadowOpacity: 0.3,\n shadowRadius: 4,\n elevation: 8,\n zIndex: 998,\n },\n fabIcon: {\n fontSize: 24,\n },\n});\n","// NOTE: This component needs to be exported from index.ts\n// e.g. export { CopilotPopup } from \"./CopilotPopup\";\n// export type { CopilotPopupProps, CopilotPopupHandle } from \"./CopilotPopup\";\n\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\";\nimport type { ReactNode } from \"react\";\nimport {\n Modal,\n Pressable,\n StyleSheet,\n Text,\n TouchableOpacity,\n View,\n useWindowDimensions,\n} from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\nimport { CopilotChat } from \"./CopilotChat\";\nimport type { NativeAttachmentsConfig } from \"./hooks/use-attachments\";\nimport type { CopilotKitCoreErrorCode } from \"@copilotkit/core\";\n\nexport interface CopilotPopupProps {\n /**\n * The agent ID to use for this chat session.\n * Passed through to CopilotChat.\n */\n agentId?: string;\n\n /**\n * @deprecated Use `agentId` instead.\n */\n agentName?: string;\n\n /**\n * Thread ID for this chat session.\n */\n threadId?: string;\n\n /**\n * Throttle interval (ms) for re-renders.\n */\n throttleMs?: number;\n\n /**\n * Whether the popup starts in the open state.\n * @default false\n */\n defaultOpen?: boolean;\n\n /**\n * Height of the popup card. Accepts a number (points) or a percentage\n * string (e.g. \"60%\") relative to the screen height.\n * @default \"60%\"\n */\n height?: number | string;\n\n /**\n * Error handler scoped to this popup's chat agent.\n */\n onError?: (error: Error) => void;\n\n /**\n * Title displayed in the popup header bar.\n * @default \"CopilotKit\"\n */\n headerTitle?: string;\n\n /**\n * Enable multimodal file attachments. Forwarded to the internal CopilotChat.\n * Children access attachment state via `useCopilotChatContext()`.\n */\n attachments?: NativeAttachmentsConfig;\n\n /**\n * Optional children rendered below the CopilotChat content\n * inside the popup card.\n */\n children?: ReactNode;\n\n /**\n * Callback fired when the popup opens.\n */\n onOpen?: () => void;\n\n /**\n * Callback fired when the popup closes.\n */\n onClose?: () => void;\n\n /**\n * Whether tapping the semi-transparent backdrop dismisses the popup.\n * Equivalent to web SDK's `clickOutsideToClose`.\n * @default true\n */\n dismissOnBackdropPress?: boolean;\n\n /**\n * Whether to show the floating action button (FAB) that toggles the popup.\n * @default true\n */\n showToggleButton?: boolean;\n\n /**\n * Custom styles applied to the popup card container.\n */\n style?: ViewStyle;\n}\n\n/**\n * Imperative handle exposed via ref for controlling the popup programmatically.\n */\nexport interface CopilotPopupHandle {\n open: () => void;\n close: () => void;\n toggle: () => void;\n}\n\n/**\n * CopilotPopup for React Native.\n *\n * A floating action button (FAB) that opens a modal chat overlay.\n * The popup appears as a card floating above content with rounded corners,\n * a shadow, and a semi-transparent backdrop.\n *\n * ```tsx\n * import { CopilotPopup } from \"@copilotkit/react-native\";\n *\n * const popupRef = useRef<CopilotPopupHandle>(null);\n *\n * <CopilotPopup\n * ref={popupRef}\n * agentId=\"my-agent\"\n * headerTitle=\"Chat\"\n * defaultOpen={false}\n * />\n * ```\n */\nexport const CopilotPopup = forwardRef<CopilotPopupHandle, CopilotPopupProps>(\n function CopilotPopup(\n {\n agentId,\n agentName,\n threadId,\n throttleMs,\n defaultOpen = false,\n height = \"60%\",\n onError,\n headerTitle = \"CopilotKit\",\n attachments: attachmentsConfig,\n children,\n onOpen,\n onClose,\n dismissOnBackdropPress = true,\n showToggleButton = true,\n style,\n }: CopilotPopupProps,\n ref: React.Ref<CopilotPopupHandle>,\n ) {\n const [visible, setVisible] = useState(defaultOpen);\n const { height: screenHeight } = useWindowDimensions();\n\n // Stable refs for callbacks to avoid effect churn\n const onOpenRef = useRef(onOpen);\n const onCloseRef = useRef(onClose);\n useEffect(() => {\n onOpenRef.current = onOpen;\n }, [onOpen]);\n useEffect(() => {\n onCloseRef.current = onClose;\n }, [onClose]);\n\n const handleOpen = useCallback(() => {\n setVisible(true);\n onOpenRef.current?.();\n }, []);\n\n const handleClose = useCallback(() => {\n setVisible(false);\n onCloseRef.current?.();\n }, []);\n\n const handleToggle = useCallback(() => {\n setVisible((prev) => {\n const next = !prev;\n if (next) {\n onOpenRef.current?.();\n } else {\n onCloseRef.current?.();\n }\n return next;\n });\n }, []);\n\n // Expose imperative methods\n useImperativeHandle(\n ref,\n () => ({\n open: handleOpen,\n close: handleClose,\n toggle: handleToggle,\n }),\n [handleOpen, handleClose, handleToggle],\n );\n\n // Resolve popup height\n const resolvedHeight =\n typeof height === \"string\" && height.endsWith(\"%\")\n ? (parseFloat(height) / 100) * screenHeight\n : typeof height === \"number\"\n ? height\n : 0.6 * screenHeight;\n\n // Wrap onError to match CopilotChat's expected signature\n const chatOnError = onError\n ? (event: {\n error: Error;\n code: CopilotKitCoreErrorCode;\n context: Record<string, any>;\n }) => onError(event.error)\n : undefined;\n\n return (\n <>\n {/* Floating Action Button */}\n {showToggleButton && !visible && (\n <TouchableOpacity\n testID=\"copilot-popup-fab\"\n style={styles.fab}\n onPress={handleToggle}\n activeOpacity={0.8}\n accessibilityLabel=\"Open chat\"\n accessibilityRole=\"button\"\n >\n <Text style={styles.fabIcon}>💬</Text>\n </TouchableOpacity>\n )}\n\n {/* Modal Overlay */}\n <Modal\n testID=\"copilot-popup-modal\"\n visible={visible}\n transparent\n animationType=\"slide\"\n onRequestClose={handleClose}\n >\n {/* Backdrop */}\n <Pressable\n testID=\"copilot-popup-backdrop\"\n style={styles.backdrop}\n onPress={dismissOnBackdropPress ? handleClose : undefined}\n >\n {/* Card — stop propagation so tapping the card doesn't dismiss */}\n <Pressable\n testID=\"copilot-popup-card\"\n style={[styles.card, { height: resolvedHeight }, style]}\n onPress={() => {\n // Prevent backdrop press from firing\n }}\n >\n {/* Header */}\n <View style={styles.header}>\n <Text style={styles.headerTitle}>{headerTitle}</Text>\n <TouchableOpacity\n testID=\"copilot-popup-close\"\n onPress={handleClose}\n hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}\n accessibilityLabel=\"Close chat\"\n accessibilityRole=\"button\"\n >\n <Text style={styles.closeButton}>✕</Text>\n </TouchableOpacity>\n </View>\n\n {/* Chat Content */}\n <View style={styles.chatContainer}>\n <CopilotChat\n agentId={agentId}\n agentName={agentName}\n threadId={threadId}\n throttleMs={throttleMs}\n onError={chatOnError}\n attachments={attachmentsConfig}\n >\n {children}\n </CopilotChat>\n </View>\n </Pressable>\n </Pressable>\n </Modal>\n </>\n );\n },\n);\n\nconst styles = StyleSheet.create({\n fab: {\n position: \"absolute\",\n bottom: 24,\n right: 24,\n width: 56,\n height: 56,\n borderRadius: 28,\n backgroundColor: \"#6366f1\",\n alignItems: \"center\",\n justifyContent: \"center\",\n elevation: 6,\n shadowColor: \"#000\",\n shadowOffset: { width: 0, height: 3 },\n shadowOpacity: 0.27,\n shadowRadius: 4.65,\n },\n fabIcon: {\n fontSize: 24,\n },\n backdrop: {\n flex: 1,\n backgroundColor: \"rgba(0, 0, 0, 0.4)\",\n justifyContent: \"flex-end\",\n },\n card: {\n backgroundColor: \"#ffffff\",\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n overflow: \"hidden\",\n elevation: 10,\n shadowColor: \"#000\",\n shadowOffset: { width: 0, height: -3 },\n shadowOpacity: 0.25,\n shadowRadius: 8,\n },\n header: {\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n paddingHorizontal: 16,\n paddingVertical: 12,\n borderBottomWidth: StyleSheet.hairlineWidth,\n borderBottomColor: \"#e5e7eb\",\n },\n headerTitle: {\n fontSize: 17,\n fontWeight: \"600\",\n color: \"#111827\",\n },\n closeButton: {\n fontSize: 18,\n color: \"#6b7280\",\n fontWeight: \"500\",\n },\n chatContainer: {\n flex: 1,\n },\n});\n"],"mappings":";;;;;;;;;;;;AAiFA,MAAM,mBAAmB,KAAK,OAAO;;;;;;;;;AAcrC,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,OAAO,OAAO;gBAAc;OAAmB,EACrD,oBAAC;MACC,QAAO;MACP,SAAS;MACT,SAAS;OAAE,KAAK;OAAG,QAAQ;OAAG,MAAM;OAAG,OAAO;OAAG;MACjD,oBAAmB;MACnB,mBAAkB;gBAElB,oBAAC;OAAK,OAAO,OAAO;iBAAa;QAAQ;OACxB;MACd,EAGP,oBAAC;KAAK,OAAO,OAAO;eAClB,oBAAC;MACU;MACE;MACD;MACE;MACZ,SAAS;MACT,aAAa;MAEZ;OACW;MACT;KACG;IACF;GACN,IACP;EAGR;AAED,MAAM,SAAS,WAAW,OAAO;CAC/B,KAAK;EACH,UAAU;EACV,QAAQ;EACR,OAAO;EACP,OAAO;EACP,QAAQ;EACR,cAAc;EACd,iBAAiB;EACjB,YAAY;EACZ,gBAAgB;EAChB,WAAW;EACX,aAAa;EACb,cAAc;GAAE,OAAO;GAAG,QAAQ;GAAG;EACrC,eAAe;EACf,cAAc;EACf;CACD,SAAS,EACP,UAAU,IACX;CACD,UAAU;EACR,MAAM;EACN,iBAAiB;EACjB,gBAAgB;EACjB;CACD,MAAM;EACJ,iBAAiB;EACjB,qBAAqB;EACrB,sBAAsB;EACtB,UAAU;EACV,WAAW;EACX,aAAa;EACb,cAAc;GAAE,OAAO;GAAG,QAAQ;GAAI;EACtC,eAAe;EACf,cAAc;EACf;CACD,QAAQ;EACN,eAAe;EACf,YAAY;EACZ,gBAAgB;EAChB,mBAAmB;EACnB,iBAAiB;EACjB,mBAAmB,WAAW;EAC9B,mBAAmB;EACpB;CACD,aAAa;EACX,UAAU;EACV,YAAY;EACZ,OAAO;EACR;CACD,aAAa;EACX,UAAU;EACV,OAAO;EACP,YAAY;EACb;CACD,eAAe,EACb,MAAM,GACP;CACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["useAgent","useCopilotKit","styles"],"sources":["../src/hooks/use-attachments.ts","../src/CopilotChat.tsx","../src/CopilotModal.tsx","../src/CopilotSidebar.tsx","../src/CopilotPopup.tsx"],"sourcesContent":["// packages/react-native/src/hooks/use-attachments.ts\nimport { useCallback, useRef, useState } from \"react\";\nimport {\n randomUUID,\n getModalityFromMimeType,\n formatFileSize,\n} from \"@copilotkit/shared\";\nimport type {\n Attachment,\n AttachmentUploadResult,\n AttachmentUploadErrorReason,\n} from \"@copilotkit/shared\";\nimport * as DocumentPicker from \"expo-document-picker\";\nimport * as FileSystem from \"expo-file-system\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/**\n * Platform-neutral file descriptor for React Native.\n * Replaces the web `File` object in all attachment APIs.\n */\nexport interface NativeFileInput {\n /** Local file URI (e.g. `file:///path/to/file`). */\n uri: string;\n /** Filename with extension. */\n name: string;\n /** File size in bytes. */\n size: number;\n /** MIME type (e.g. `\"image/jpeg\"`). */\n mimeType: string;\n}\n\n/**\n * React Native variant of AttachmentsConfig.\n * Identical to the shared AttachmentsConfig except `onUpload` receives\n * a `NativeFileInput` instead of a web `File`.\n */\nexport interface NativeAttachmentsConfig {\n /** Enable file attachments in the chat input. */\n enabled: boolean;\n /** MIME type filter for the file picker, default all files. */\n accept?: string;\n /** Maximum file size in bytes, default 20MB (20 * 1024 * 1024). */\n maxSize?: number;\n /** Custom upload handler. Receives the native file descriptor. */\n onUpload?: (\n file: NativeFileInput,\n ) => AttachmentUploadResult | Promise<AttachmentUploadResult>;\n /** Called when an attachment fails validation or upload. */\n onUploadFailed?: (error: {\n reason: AttachmentUploadErrorReason;\n file: NativeFileInput;\n message: string;\n }) => void;\n}\n\nexport interface UseNativeAttachmentsProps {\n config?: NativeAttachmentsConfig;\n}\n\nexport interface UseNativeAttachmentsReturn {\n /** Currently selected attachments (uploading + ready). */\n attachments: Attachment[];\n /** Whether attachments are enabled. */\n enabled: boolean;\n /** Open the native document picker. */\n openPicker: () => Promise<void>;\n /** Process an array of NativeFileInput objects (validate, read, add to state). */\n processFiles: (files: NativeFileInput[]) => Promise<void>;\n /** Remove an attachment by ID. */\n removeAttachment: (id: string) => void;\n /** Consume ready attachments and clear the queue. Returns the consumed attachments. */\n consumeAttachments: () => Attachment[];\n}\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_MAX_SIZE = 20 * 1024 * 1024; // 20 MB\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * React Native hook that manages file attachment state -- picking, uploading,\n * and lifecycle. All returned callbacks are referentially stable via useCallback.\n *\n * This is the RN counterpart of the web `useAttachments` hook from\n * `@copilotkit/react-core`. It replaces web APIs (FileReader, DragEvent,\n * HTMLInputElement) with Expo modules (expo-document-picker, expo-file-system).\n */\nexport function useAttachments({\n config,\n}: UseNativeAttachmentsProps): UseNativeAttachmentsReturn {\n const enabled = config?.enabled ?? false;\n\n const [attachments, setAttachments] = useState<Attachment[]>([]);\n\n // Refs for stable callbacks to read latest values\n const configRef = useRef(config);\n configRef.current = config;\n const attachmentsRef = useRef<Attachment[]>([]);\n attachmentsRef.current = attachments;\n\n /**\n * Simple MIME accept filter for NativeFileInput.\n * Handles wildcards like \"image/*\" and exact types like \"application/pdf\".\n * Comma-separated lists are supported.\n */\n const matchesAccept = useCallback(\n (file: NativeFileInput, accept: string): boolean => {\n if (!accept || accept === \"*/*\") return true;\n const filters = accept.split(\",\").map((f) => f.trim());\n return filters.some((filter) => {\n if (filter.startsWith(\".\")) {\n return file.name.toLowerCase().endsWith(filter.toLowerCase());\n }\n if (filter.endsWith(\"/*\")) {\n const prefix = filter.slice(0, -2);\n return file.mimeType.startsWith(prefix + \"/\");\n }\n return file.mimeType === filter;\n });\n },\n [],\n );\n\n const processFiles = useCallback(\n async (files: NativeFileInput[]) => {\n const cfg = configRef.current;\n const accept = cfg?.accept ?? \"*/*\";\n const maxSize = cfg?.maxSize ?? DEFAULT_MAX_SIZE;\n\n // Filter by accept type\n const rejectedFiles = files.filter((f) => !matchesAccept(f, accept));\n for (const file of rejectedFiles) {\n cfg?.onUploadFailed?.({\n reason: \"invalid-type\",\n file,\n message: `File \"${file.name}\" is not accepted. Supported types: ${accept}`,\n });\n }\n\n const validFiles = files.filter((f) => matchesAccept(f, accept));\n\n for (const file of validFiles) {\n // Size check\n if (file.size > maxSize) {\n cfg?.onUploadFailed?.({\n reason: \"file-too-large\",\n file,\n message: `File \"${file.name}\" exceeds the maximum size of ${formatFileSize(maxSize)}`,\n });\n continue;\n }\n\n const modality = getModalityFromMimeType(file.mimeType);\n const placeholderId = randomUUID();\n const placeholder: Attachment = {\n id: placeholderId,\n type: modality,\n source: { type: \"data\", value: \"\", mimeType: file.mimeType },\n filename: file.name,\n size: file.size,\n status: \"uploading\",\n };\n\n setAttachments((prev) => [...prev, placeholder]);\n\n try {\n let source: Attachment[\"source\"];\n let uploadMetadata: Record<string, unknown> | undefined;\n\n if (cfg?.onUpload) {\n const { metadata: meta, ...uploadSource } =\n await cfg.onUpload(file);\n source = uploadSource;\n uploadMetadata = meta;\n } else {\n // Default: read file as base64 via expo-file-system\n const base64 = await FileSystem.readAsStringAsync(file.uri, {\n encoding: FileSystem.EncodingType.Base64,\n });\n source = { type: \"data\", value: base64, mimeType: file.mimeType };\n }\n\n setAttachments((prev) =>\n prev.map((att) =>\n att.id === placeholderId\n ? {\n ...att,\n source,\n status: \"ready\" as const,\n metadata: uploadMetadata,\n }\n : att,\n ),\n );\n } catch (error) {\n // Remove placeholder on failure\n setAttachments((prev) =>\n prev.filter((att) => att.id !== placeholderId),\n );\n console.error(`[CopilotKit] Failed to upload \"${file.name}\":`, error);\n cfg?.onUploadFailed?.({\n reason: \"upload-failed\",\n file,\n message:\n error instanceof Error\n ? error.message\n : `Failed to upload \"${file.name}\"`,\n });\n }\n }\n },\n [matchesAccept],\n );\n\n const openPicker = useCallback(async () => {\n const cfg = configRef.current;\n const accept = cfg?.accept ?? \"*/*\";\n\n // Convert accept string to array for DocumentPicker\n const typeArray = accept\n .split(\",\")\n .map((t) => t.trim())\n .filter(Boolean);\n\n try {\n const result = await DocumentPicker.getDocumentAsync({\n type: typeArray.length > 0 ? typeArray : [\"*/*\"],\n copyToCacheDirectory: true,\n multiple: true,\n });\n\n if (result.canceled || !result.assets?.length) return;\n\n const nativeFiles: NativeFileInput[] = result.assets.map((asset) => ({\n uri: asset.uri,\n name: asset.name ?? \"unknown\",\n size: asset.size ?? 0,\n mimeType: asset.mimeType ?? \"application/octet-stream\",\n }));\n\n await processFiles(nativeFiles);\n } catch (error) {\n console.error(\"[CopilotKit] Document picker error:\", error);\n }\n }, [processFiles]);\n\n const removeAttachment = useCallback((id: string) => {\n setAttachments((prev) => prev.filter((a) => a.id !== id));\n }, []);\n\n const consumeAttachments = useCallback(() => {\n const ready = attachmentsRef.current.filter((a) => a.status === \"ready\");\n if (ready.length === 0) return ready;\n setAttachments((prev) => prev.filter((a) => a.status !== \"ready\"));\n return ready;\n }, []);\n\n return {\n attachments,\n enabled,\n openPicker,\n processFiles,\n removeAttachment,\n consumeAttachments,\n };\n}\n","import React, {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n} from \"react\";\nimport type { ReactNode } from \"react\";\nimport { useAgent } from \"@copilotkit/react-core/headless\";\nimport { useCopilotKit } from \"@copilotkit/react-core/context\";\nimport { DEFAULT_AGENT_ID, randomUUID } from \"@copilotkit/shared\";\nimport type { InputContent } from \"@copilotkit/shared\";\nimport type { CopilotKitCoreErrorCode } from \"@copilotkit/core\";\nimport { useAttachments } from \"./hooks/use-attachments\";\nimport type { NativeAttachmentsConfig } from \"./hooks/use-attachments\";\nimport type { Attachment } from \"@copilotkit/shared\";\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\nexport interface CopilotChatContextValue {\n /** The resolved agent instance. */\n agent: any;\n /** Whether the agent is currently running. */\n isRunning: boolean;\n /** Current messages in the conversation. */\n messages: any[];\n /** Currently selected attachments (uploading + ready). */\n attachments: Attachment[];\n /** Whether attachments are enabled. */\n attachmentsEnabled: boolean;\n /** Open the native document picker to add files. */\n openPicker: () => Promise<void>;\n /** Remove an attachment by ID. */\n removeAttachment: (id: string) => void;\n /**\n * Submit a message with optional attachments.\n * Handles consuming ready attachments, building InputContent[],\n * calling agent.addMessage, and running the agent.\n */\n submitMessage: (text: string) => Promise<void>;\n}\n\nconst CopilotChatCtx = createContext<CopilotChatContextValue | null>(null);\n\n/**\n * Hook to access the CopilotChat context from child components.\n * Must be called inside a `<CopilotChat>` component tree.\n */\nexport function useCopilotChatContext(): CopilotChatContextValue {\n const ctx = useContext(CopilotChatCtx);\n if (!ctx) {\n throw new Error(\n \"useCopilotChatContext must be used within a <CopilotChat> component\",\n );\n }\n return ctx;\n}\n\n// ---------------------------------------------------------------------------\n// Props\n// ---------------------------------------------------------------------------\n\nexport interface CopilotChatBaseProps {\n /**\n * The agent ID to use for this chat session.\n * Matches the web SDK's CopilotChat `agentId` prop.\n *\n * Resolution order: `agentId` > `agentName` > `\"default\"`\n */\n agentId?: string;\n\n /**\n * @deprecated Use `agentId` instead. `agentName` is kept for backwards\n * compatibility and will be removed in a future release.\n */\n agentName?: string;\n\n /**\n * Thread ID for this chat session. When provided, the chat will resume\n * the specified thread. Matches the web SDK's CopilotChat `threadId` prop.\n */\n threadId?: string;\n\n /**\n * Error handler scoped to this chat's agent. Fires in addition to the\n * provider-level onError (does not suppress it). Receives only errors\n * whose context.agentId matches this chat's agent.\n */\n onError?: (event: {\n error: Error;\n code: CopilotKitCoreErrorCode;\n context: Record<string, any>;\n }) => void | Promise<void>;\n\n /**\n * Throttle interval (in milliseconds) for re-renders triggered by message\n * change notifications. Overrides the provider-level `defaultThrottleMs`\n * for this chat instance. Forwarded to the internal `useAgent()` hook.\n *\n * @default undefined -- inherits from provider `defaultThrottleMs`;\n * if that is also unset, re-renders are unthrottled.\n */\n throttleMs?: number;\n\n /**\n * Enable multimodal file attachments (images, audio, video, documents).\n * Pass a NativeAttachmentsConfig object to configure file picking behavior.\n */\n attachments?: NativeAttachmentsConfig;\n\n /**\n * Optional children rendered inside the chat context.\n */\n children?: ReactNode;\n}\n\nexport interface CopilotChatProps extends CopilotChatBaseProps {\n /** Passthrough props are forwarded to consumers via the agent context. */\n [key: string]: unknown;\n}\n\n/**\n * Headless CopilotChat component for React Native.\n *\n * Wires up the `useAgent` hook with `agentId` resolution and renders children.\n * Unlike the web SDK's CopilotChat, this component does not render any UI\n * elements -- consumers provide their own React Native views.\n *\n * Children can access chat state via `useCopilotChatContext()`.\n *\n * ```tsx\n * import { CopilotChat, useCopilotChatContext } from \"@copilotkit/react-native\";\n *\n * function MyChatUI() {\n * const { messages, submitMessage, attachments, openPicker } = useCopilotChatContext();\n * // ... render your UI\n * }\n *\n * <CopilotChat agentId=\"my-agent\" attachments={{ enabled: true }}>\n * <MyChatUI />\n * </CopilotChat>\n * ```\n */\nexport function CopilotChat({\n agentId,\n agentName,\n threadId,\n onError,\n throttleMs,\n attachments: attachmentsConfig,\n children,\n ..._rest\n}: CopilotChatProps) {\n const resolvedAgentId = agentId ?? agentName ?? DEFAULT_AGENT_ID;\n\n // Deprecation warning (dev only, fires once per mount)\n const warnedRef = useRef(false);\n useEffect(() => {\n if (\n agentName !== undefined &&\n agentId === undefined &&\n !warnedRef.current\n ) {\n warnedRef.current = true;\n if (typeof __DEV__ === \"undefined\" || __DEV__) {\n console.warn(\n \"[CopilotKit] agentName is deprecated, use agentId instead\",\n );\n }\n }\n }, [agentName, agentId]);\n\n const { agent } = useAgent({ agentId: resolvedAgentId, throttleMs });\n\n // Set threadId on the agent when provided\n useEffect(() => {\n if (threadId) {\n agent.threadId = threadId;\n }\n }, [agent, threadId]);\n\n // onError subscription -- forward core errors scoped to this chat's agent\n const { copilotkit } = useCopilotKit();\n const onErrorRef = useRef(onError);\n useEffect(() => {\n onErrorRef.current = onError;\n }, [onError]);\n\n useEffect(() => {\n if (!onErrorRef.current) return;\n\n const subscription = copilotkit.subscribe({\n onError: (event) => {\n // Only forward errors that match this chat's agent\n if (\n event.context?.agentId === resolvedAgentId ||\n !event.context?.agentId\n ) {\n onErrorRef.current?.({\n error: event.error,\n code: event.code,\n context: event.context,\n });\n }\n },\n });\n\n return () => {\n subscription.unsubscribe();\n };\n }, [copilotkit, resolvedAgentId]);\n\n // Attachments\n const {\n attachments: selectedAttachments,\n enabled: attachmentsEnabled,\n openPicker,\n removeAttachment,\n consumeAttachments,\n } = useAttachments({ config: attachmentsConfig });\n\n // Submit handler -- mirrors web CopilotChat.tsx lines 234-288\n const submitMessage = useCallback(\n async (value: string) => {\n // Block if uploads in progress\n const hasUploading = selectedAttachments.some(\n (a) => a.status === \"uploading\",\n );\n if (hasUploading) {\n console.error(\n \"[CopilotKit] Cannot send while attachments are uploading\",\n );\n return;\n }\n\n const readyAttachments = consumeAttachments();\n\n if (readyAttachments.length > 0) {\n const contentParts: InputContent[] = [];\n if (value.trim()) {\n contentParts.push({ type: \"text\", text: value });\n }\n for (const att of readyAttachments) {\n contentParts.push({\n type: att.type,\n source: att.source,\n metadata: {\n ...(att.filename ? { filename: att.filename } : {}),\n ...att.metadata,\n },\n } as InputContent);\n }\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: contentParts,\n });\n } else {\n agent.addMessage({\n id: randomUUID(),\n role: \"user\",\n content: value,\n });\n }\n\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: runAgent failed\", error);\n }\n },\n // copilotkit is intentionally excluded -- it is a stable ref that never changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [agent, selectedAttachments, consumeAttachments],\n );\n\n const contextValue: CopilotChatContextValue = {\n agent,\n isRunning: agent.isRunning,\n messages: agent.messages,\n attachments: selectedAttachments,\n attachmentsEnabled,\n openPicker,\n removeAttachment,\n submitMessage,\n };\n\n return (\n <CopilotChatCtx.Provider value={contextValue}>\n {children}\n </CopilotChatCtx.Provider>\n );\n}\n","import React, { type ReactNode } from \"react\";\nimport { CopilotChat, type CopilotChatProps } from \"./CopilotChat\";\n\nexport interface CopilotModalProps extends CopilotChatProps {\n /**\n * Optional children rendered inside the modal context.\n */\n children?: ReactNode;\n}\n\n/**\n * Headless CopilotModal component for React Native.\n *\n * A thin wrapper around CopilotChat that mirrors the web SDK's CopilotModal\n * API surface. On React Native, modal presentation is handled by the consumer\n * (e.g. React Native's `Modal` component) -- this component only provides\n * the agent wiring and prop resolution.\n *\n * ```tsx\n * import { CopilotModal } from \"@copilotkit/react-native\";\n * import { Modal } from \"react-native\";\n *\n * <Modal visible={isOpen}>\n * <CopilotModal agentId=\"my-agent\">\n * <MyChatUI />\n * </CopilotModal>\n * </Modal>\n * ```\n */\nexport function CopilotModal({ children, ...props }: CopilotModalProps) {\n return <CopilotChat {...props}>{children}</CopilotChat>;\n}\n","import React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\";\nimport type { ReactNode } from \"react\";\nimport {\n Animated,\n Dimensions,\n Pressable,\n StyleSheet,\n Text,\n useWindowDimensions,\n View,\n} from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\nimport { CopilotChat } from \"./CopilotChat\";\nimport type { CopilotChatBaseProps } from \"./CopilotChat\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface CopilotSidebarHandle {\n /** Slide the drawer open. */\n open(): void;\n /** Slide the drawer closed. */\n close(): void;\n /** Toggle the drawer open/closed. */\n toggle(): void;\n}\n\nexport interface CopilotSidebarProps extends Omit<\n CopilotChatBaseProps,\n \"children\"\n> {\n /**\n * Start the drawer in the open position.\n * @default false\n */\n defaultOpen?: boolean;\n\n /**\n * Width of the drawer panel. Accepts a number (points) or a percentage\n * string (e.g. `\"85%\"`). Defaults to 85% of the screen width.\n */\n width?: number | string;\n\n /**\n * Title displayed in the drawer header bar.\n * @default \"Copilot\"\n */\n headerTitle?: string;\n\n /**\n * Show a floating action button to toggle the drawer.\n * @default true\n */\n showToggleButton?: boolean;\n\n /** Called after the drawer finishes opening. */\n onOpen?: () => void;\n\n /** Called after the drawer finishes closing. */\n onClose?: () => void;\n\n /** Custom style applied to the drawer container. */\n style?: ViewStyle;\n\n /** Content rendered inside the drawer below the chat area. */\n children?: ReactNode;\n}\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nconst ANIMATION_DURATION_MS = 300;\nconst DEFAULT_HEADER_TITLE = \"Copilot\";\nconst BACKDROP_OPACITY = 0.4;\nconst FAB_SIZE = 56;\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\n/**\n * CopilotSidebar -- a slide-in drawer from the right edge of the screen\n * that wraps CopilotChat for React Native.\n *\n * ```tsx\n * import { CopilotSidebar } from \"@copilotkit/react-native\";\n *\n * const ref = useRef<CopilotSidebarHandle>(null);\n *\n * <CopilotSidebar\n * ref={ref}\n * agentId=\"my-agent\"\n * headerTitle=\"Assistant\"\n * defaultOpen={false}\n * />\n * ```\n */\nexport const CopilotSidebar = forwardRef<\n CopilotSidebarHandle,\n CopilotSidebarProps\n>(function CopilotSidebar(\n {\n agentId,\n agentName,\n threadId,\n onError,\n throttleMs,\n defaultOpen = false,\n width: widthProp,\n headerTitle = DEFAULT_HEADER_TITLE,\n showToggleButton = true,\n onOpen,\n onClose,\n style,\n children,\n ...rest\n },\n ref,\n) {\n const { width: screenWidth } = useWindowDimensions();\n\n // Resolve drawer width ---------------------------------------------------\n const drawerWidth = resolveWidth(widthProp, screenWidth);\n\n // Animation & open state -------------------------------------------------\n const [isOpen, setIsOpen] = useState(defaultOpen);\n const slideAnim = useRef(\n new Animated.Value(defaultOpen ? 0 : drawerWidth),\n ).current;\n\n // Keep the animated value in sync when drawerWidth changes while closed\n useEffect(() => {\n if (!isOpen) {\n slideAnim.setValue(drawerWidth);\n }\n }, [drawerWidth, isOpen, slideAnim]);\n\n const animateTo = useCallback(\n (toValue: number, cb?: () => void) => {\n Animated.timing(slideAnim, {\n toValue,\n duration: ANIMATION_DURATION_MS,\n useNativeDriver: true,\n }).start(({ finished }) => {\n if (finished) cb?.();\n });\n },\n [slideAnim],\n );\n\n const open = useCallback(() => {\n setIsOpen(true);\n animateTo(0, onOpen);\n }, [animateTo, onOpen]);\n\n const close = useCallback(() => {\n animateTo(drawerWidth, () => {\n setIsOpen(false);\n onClose?.();\n });\n }, [animateTo, drawerWidth, onClose]);\n\n const toggle = useCallback(() => {\n if (isOpen) {\n close();\n } else {\n open();\n }\n }, [isOpen, open, close]);\n\n useImperativeHandle(ref, () => ({ open, close, toggle }), [\n open,\n close,\n toggle,\n ]);\n\n // Callbacks stored in refs for stable animation closures -----------------\n const onOpenRef = useRef(onOpen);\n const onCloseRef = useRef(onClose);\n useEffect(() => {\n onOpenRef.current = onOpen;\n }, [onOpen]);\n useEffect(() => {\n onCloseRef.current = onClose;\n }, [onClose]);\n\n // -----------------------------------------------------------------------\n // Render\n // -----------------------------------------------------------------------\n return (\n <>\n {/* Backdrop */}\n {isOpen && (\n <Pressable\n style={styles.backdrop}\n onPress={close}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Close sidebar\"\n testID=\"copilot-sidebar-backdrop\"\n />\n )}\n\n {/* Drawer */}\n {isOpen && (\n <Animated.View\n style={[\n styles.drawer,\n { width: drawerWidth, transform: [{ translateX: slideAnim }] },\n style,\n ]}\n testID=\"copilot-sidebar-drawer\"\n >\n {/* Header */}\n <View style={styles.header}>\n <Text style={styles.headerTitle}>{headerTitle}</Text>\n <Pressable\n onPress={close}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Close\"\n hitSlop={8}\n testID=\"copilot-sidebar-close\"\n >\n <Text style={styles.closeButton}>{\"✕\"}</Text>\n </Pressable>\n </View>\n\n {/* Chat area */}\n <View style={styles.chatContainer}>\n <CopilotChat\n agentId={agentId}\n agentName={agentName}\n threadId={threadId}\n onError={onError}\n throttleMs={throttleMs}\n {...rest}\n >\n {children}\n </CopilotChat>\n </View>\n </Animated.View>\n )}\n\n {/* Floating action button */}\n {showToggleButton && !isOpen && (\n <Pressable\n style={styles.fab}\n onPress={open}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Open sidebar\"\n testID=\"copilot-sidebar-fab\"\n >\n <Text style={styles.fabIcon}>{\"💬\"}</Text>\n </Pressable>\n )}\n </>\n );\n});\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction resolveWidth(\n widthProp: number | string | undefined,\n screenWidth: number,\n): number {\n if (widthProp === undefined) {\n return Math.round(screenWidth * 0.85);\n }\n if (typeof widthProp === \"number\") {\n return widthProp;\n }\n // Percentage string, e.g. \"85%\"\n const pctMatch = String(widthProp).match(/^(\\d+(?:\\.\\d+)?)%$/);\n if (pctMatch) {\n return Math.round(screenWidth * (parseFloat(pctMatch[1]) / 100));\n }\n // Fallback: try parsing as number\n const parsed = parseFloat(widthProp);\n return isNaN(parsed) ? Math.round(screenWidth * 0.85) : parsed;\n}\n\n// ---------------------------------------------------------------------------\n// Styles\n// ---------------------------------------------------------------------------\n\nconst styles = StyleSheet.create({\n backdrop: {\n ...StyleSheet.absoluteFill,\n backgroundColor: `rgba(0, 0, 0, ${BACKDROP_OPACITY})`,\n zIndex: 999,\n },\n drawer: {\n position: \"absolute\",\n top: 0,\n right: 0,\n bottom: 0,\n backgroundColor: \"#ffffff\",\n zIndex: 1000,\n shadowColor: \"#000\",\n shadowOffset: { width: -2, height: 0 },\n shadowOpacity: 0.25,\n shadowRadius: 8,\n elevation: 16,\n },\n header: {\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n paddingHorizontal: 16,\n paddingVertical: 12,\n borderBottomWidth: StyleSheet.hairlineWidth,\n borderBottomColor: \"#e0e0e0\",\n },\n headerTitle: {\n fontSize: 18,\n fontWeight: \"600\",\n color: \"#1a1a1a\",\n },\n closeButton: {\n fontSize: 20,\n color: \"#666\",\n padding: 4,\n },\n chatContainer: {\n flex: 1,\n },\n fab: {\n position: \"absolute\",\n bottom: 24,\n right: 24,\n width: FAB_SIZE,\n height: FAB_SIZE,\n borderRadius: FAB_SIZE / 2,\n backgroundColor: \"#007AFF\",\n alignItems: \"center\",\n justifyContent: \"center\",\n shadowColor: \"#000\",\n shadowOffset: { width: 0, height: 2 },\n shadowOpacity: 0.3,\n shadowRadius: 4,\n elevation: 8,\n zIndex: 998,\n },\n fabIcon: {\n fontSize: 24,\n },\n});\n","// NOTE: This component needs to be exported from index.ts\n// e.g. export { CopilotPopup } from \"./CopilotPopup\";\n// export type { CopilotPopupProps, CopilotPopupHandle } from \"./CopilotPopup\";\n\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\";\nimport type { ReactNode } from \"react\";\nimport {\n Modal,\n Pressable,\n StyleSheet,\n Text,\n TouchableOpacity,\n View,\n useWindowDimensions,\n} from \"react-native\";\nimport type { ViewStyle } from \"react-native\";\nimport { CopilotChat } from \"./CopilotChat\";\nimport type { NativeAttachmentsConfig } from \"./hooks/use-attachments\";\nimport type { CopilotKitCoreErrorCode } from \"@copilotkit/core\";\n\nexport interface CopilotPopupProps {\n /**\n * The agent ID to use for this chat session.\n * Passed through to CopilotChat.\n */\n agentId?: string;\n\n /**\n * @deprecated Use `agentId` instead.\n */\n agentName?: string;\n\n /**\n * Thread ID for this chat session.\n */\n threadId?: string;\n\n /**\n * Throttle interval (ms) for re-renders.\n */\n throttleMs?: number;\n\n /**\n * Whether the popup starts in the open state.\n * @default false\n */\n defaultOpen?: boolean;\n\n /**\n * Height of the popup card. Accepts a number (points) or a percentage\n * string (e.g. \"60%\") relative to the screen height.\n * @default \"60%\"\n */\n height?: number | string;\n\n /**\n * Error handler scoped to this popup's chat agent.\n */\n onError?: (error: Error) => void;\n\n /**\n * Title displayed in the popup header bar.\n * @default \"CopilotKit\"\n */\n headerTitle?: string;\n\n /**\n * Enable multimodal file attachments. Forwarded to the internal CopilotChat.\n * Children access attachment state via `useCopilotChatContext()`.\n */\n attachments?: NativeAttachmentsConfig;\n\n /**\n * Optional children rendered below the CopilotChat content\n * inside the popup card.\n */\n children?: ReactNode;\n\n /**\n * Callback fired when the popup opens.\n */\n onOpen?: () => void;\n\n /**\n * Callback fired when the popup closes.\n */\n onClose?: () => void;\n\n /**\n * Whether tapping the semi-transparent backdrop dismisses the popup.\n * Equivalent to web SDK's `clickOutsideToClose`.\n * @default true\n */\n dismissOnBackdropPress?: boolean;\n\n /**\n * Whether to show the floating action button (FAB) that toggles the popup.\n * @default true\n */\n showToggleButton?: boolean;\n\n /**\n * Custom styles applied to the popup card container.\n */\n style?: ViewStyle;\n}\n\n/**\n * Imperative handle exposed via ref for controlling the popup programmatically.\n */\nexport interface CopilotPopupHandle {\n open: () => void;\n close: () => void;\n toggle: () => void;\n}\n\n/**\n * CopilotPopup for React Native.\n *\n * A floating action button (FAB) that opens a modal chat overlay.\n * The popup appears as a card floating above content with rounded corners,\n * a shadow, and a semi-transparent backdrop.\n *\n * ```tsx\n * import { CopilotPopup } from \"@copilotkit/react-native\";\n *\n * const popupRef = useRef<CopilotPopupHandle>(null);\n *\n * <CopilotPopup\n * ref={popupRef}\n * agentId=\"my-agent\"\n * headerTitle=\"Chat\"\n * defaultOpen={false}\n * />\n * ```\n */\nexport const CopilotPopup = forwardRef<CopilotPopupHandle, CopilotPopupProps>(\n function CopilotPopup(\n {\n agentId,\n agentName,\n threadId,\n throttleMs,\n defaultOpen = false,\n height = \"60%\",\n onError,\n headerTitle = \"CopilotKit\",\n attachments: attachmentsConfig,\n children,\n onOpen,\n onClose,\n dismissOnBackdropPress = true,\n showToggleButton = true,\n style,\n }: CopilotPopupProps,\n ref: React.Ref<CopilotPopupHandle>,\n ) {\n const [visible, setVisible] = useState(defaultOpen);\n const { height: screenHeight } = useWindowDimensions();\n\n // Stable refs for callbacks to avoid effect churn\n const onOpenRef = useRef(onOpen);\n const onCloseRef = useRef(onClose);\n useEffect(() => {\n onOpenRef.current = onOpen;\n }, [onOpen]);\n useEffect(() => {\n onCloseRef.current = onClose;\n }, [onClose]);\n\n const handleOpen = useCallback(() => {\n setVisible(true);\n onOpenRef.current?.();\n }, []);\n\n const handleClose = useCallback(() => {\n setVisible(false);\n onCloseRef.current?.();\n }, []);\n\n const handleToggle = useCallback(() => {\n setVisible((prev) => {\n const next = !prev;\n if (next) {\n onOpenRef.current?.();\n } else {\n onCloseRef.current?.();\n }\n return next;\n });\n }, []);\n\n // Expose imperative methods\n useImperativeHandle(\n ref,\n () => ({\n open: handleOpen,\n close: handleClose,\n toggle: handleToggle,\n }),\n [handleOpen, handleClose, handleToggle],\n );\n\n // Resolve popup height\n const resolvedHeight =\n typeof height === \"string\" && height.endsWith(\"%\")\n ? (parseFloat(height) / 100) * screenHeight\n : typeof height === \"number\"\n ? height\n : 0.6 * screenHeight;\n\n // Wrap onError to match CopilotChat's expected signature\n const chatOnError = onError\n ? (event: {\n error: Error;\n code: CopilotKitCoreErrorCode;\n context: Record<string, any>;\n }) => onError(event.error)\n : undefined;\n\n return (\n <>\n {/* Floating Action Button */}\n {showToggleButton && !visible && (\n <TouchableOpacity\n testID=\"copilot-popup-fab\"\n style={styles.fab}\n onPress={handleToggle}\n activeOpacity={0.8}\n accessibilityLabel=\"Open chat\"\n accessibilityRole=\"button\"\n >\n <Text style={styles.fabIcon}>💬</Text>\n </TouchableOpacity>\n )}\n\n {/* Modal Overlay */}\n <Modal\n testID=\"copilot-popup-modal\"\n visible={visible}\n transparent\n animationType=\"slide\"\n onRequestClose={handleClose}\n >\n {/* Backdrop */}\n <Pressable\n testID=\"copilot-popup-backdrop\"\n style={styles.backdrop}\n onPress={dismissOnBackdropPress ? handleClose : undefined}\n >\n {/* Card — stop propagation so tapping the card doesn't dismiss */}\n <Pressable\n testID=\"copilot-popup-card\"\n style={[styles.card, { height: resolvedHeight }, style]}\n onPress={() => {\n // Prevent backdrop press from firing\n }}\n >\n {/* Header */}\n <View style={styles.header}>\n <Text style={styles.headerTitle}>{headerTitle}</Text>\n <TouchableOpacity\n testID=\"copilot-popup-close\"\n onPress={handleClose}\n hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}\n accessibilityLabel=\"Close chat\"\n accessibilityRole=\"button\"\n >\n <Text style={styles.closeButton}>✕</Text>\n </TouchableOpacity>\n </View>\n\n {/* Chat Content */}\n <View style={styles.chatContainer}>\n <CopilotChat\n agentId={agentId}\n agentName={agentName}\n threadId={threadId}\n throttleMs={throttleMs}\n onError={chatOnError}\n attachments={attachmentsConfig}\n >\n {children}\n </CopilotChat>\n </View>\n </Pressable>\n </Pressable>\n </Modal>\n </>\n );\n },\n);\n\nconst styles = StyleSheet.create({\n fab: {\n position: \"absolute\",\n bottom: 24,\n right: 24,\n width: 56,\n height: 56,\n borderRadius: 28,\n backgroundColor: \"#6366f1\",\n alignItems: \"center\",\n justifyContent: \"center\",\n elevation: 6,\n shadowColor: \"#000\",\n shadowOffset: { width: 0, height: 3 },\n shadowOpacity: 0.27,\n shadowRadius: 4.65,\n },\n fabIcon: {\n fontSize: 24,\n },\n backdrop: {\n flex: 1,\n backgroundColor: \"rgba(0, 0, 0, 0.4)\",\n justifyContent: \"flex-end\",\n },\n card: {\n backgroundColor: \"#ffffff\",\n borderTopLeftRadius: 16,\n borderTopRightRadius: 16,\n overflow: \"hidden\",\n elevation: 10,\n shadowColor: \"#000\",\n shadowOffset: { width: 0, height: -3 },\n shadowOpacity: 0.25,\n shadowRadius: 8,\n },\n header: {\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n paddingHorizontal: 16,\n paddingVertical: 12,\n borderBottomWidth: StyleSheet.hairlineWidth,\n borderBottomColor: \"#e5e7eb\",\n },\n headerTitle: {\n fontSize: 17,\n fontWeight: \"600\",\n color: \"#111827\",\n },\n closeButton: {\n fontSize: 18,\n color: \"#6b7280\",\n fontWeight: \"500\",\n },\n chatContainer: {\n flex: 1,\n },\n});\n"],"mappings":";;;;;;;;;;;;;;AAiFA,MAAM,mBAAmB,KAAK,OAAO;;;;;;;;;AAcrC,SAAgB,eAAe,EAC7B,UACwD;CACxD,MAAM,UAAU,QAAQ,WAAW;CAEnC,MAAM,CAAC,aAA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AAK;OAAG,QAAQ;OAAG,MAAM;OAAG,OAAO;OAAG;MACjD,oBAAmB;MACnB,mBAAkB;gBAElB,oBAAC;OAAK,OAAO,OAAO;iBAAa;QAAQ;OACxB;MACd,EAGP,oBAAC;KAAK,OAAO,OAAO;eAClB,oBAAC;MACU;MACE;MACD;MACE;MACZ,SAAS;MACT,aAAa;MAEZ;OACW;MACT;KACG;IACF;GACN,IACP;EAGR;AAED,MAAM,SAAS,WAAW,OAAO;CAC/B,KAAK;EACH,UAAU;EACV,QAAQ;EACR,OAAO;EACP,OAAO;EACP,QAAQ;EACR,cAAc;EACd,iBAAiB;EACjB,YAAY;EACZ,gBAAgB;EAChB,WAAW;EACX,aAAa;EACb,cAAc;GAAE,OAAO;GAAG,QAAQ;GAAG;EACrC,eAAe;EACf,cAAc;EACf;CACD,SAAS,EACP,UAAU,IACX;CACD,UAAU;EACR,MAAM;EACN,iBAAiB;EACjB,gBAAgB;EACjB;CACD,MAAM;EACJ,iBAAiB;EACjB,qBAAqB;EACrB,sBAAsB;EACtB,UAAU;EACV,WAAW;EACX,aAAa;EACb,cAAc;GAAE,OAAO;GAAG,QAAQ;GAAI;EACtC,eAAe;EACf,cAAc;EACf;CACD,QAAQ;EACN,eAAe;EACf,YAAY;EACZ,gBAAgB;EAChB,mBAAmB;EACnB,iBAAiB;EACjB,mBAAmB,WAAW;EAC9B,mBAAmB;EACpB;CACD,aAAa;EACX,UAAU;EACV,YAAY;EACZ,OAAO;EACR;CACD,aAAa;EACX,UAAU;EACV,OAAO;EACP,YAAY;EACb;CACD,eAAe,EACb,MAAM,GACP;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/react-native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -74,11 +74,12 @@
|
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@ag-ui/client": "1.0.2",
|
|
77
|
+
"@copilotkit/core": "2.0.0-rc.0",
|
|
78
|
+
"@copilotkit/markdown-renderer": "2.0.0-rc.0",
|
|
79
|
+
"@copilotkit/react-core": "2.0.0-rc.0",
|
|
80
|
+
"@copilotkit/shared": "2.0.0-rc.0",
|
|
77
81
|
"text-encoding": "^0.7.0",
|
|
78
|
-
"web-streams-polyfill": "^4.2.0"
|
|
79
|
-
"@copilotkit/core": "1.83.0",
|
|
80
|
-
"@copilotkit/shared": "1.83.0",
|
|
81
|
-
"@copilotkit/react-core": "1.83.0"
|
|
82
|
+
"web-streams-polyfill": "^4.2.0"
|
|
82
83
|
},
|
|
83
84
|
"devDependencies": {
|
|
84
85
|
"@testing-library/react": "^16.3.0",
|
|
@@ -99,7 +100,6 @@
|
|
|
99
100
|
"react-native": ">=0.70",
|
|
100
101
|
"react-native-gesture-handler": ">=2.0.0",
|
|
101
102
|
"react-native-reanimated": ">=3.0.0",
|
|
102
|
-
"react-native-streamdown": ">=0.1.0",
|
|
103
103
|
"zod": ">=3.0.0"
|
|
104
104
|
},
|
|
105
105
|
"peerDependenciesMeta": {
|
|
@@ -118,9 +118,6 @@
|
|
|
118
118
|
"react-native-reanimated": {
|
|
119
119
|
"optional": true
|
|
120
120
|
},
|
|
121
|
-
"react-native-streamdown": {
|
|
122
|
-
"optional": true
|
|
123
|
-
},
|
|
124
121
|
"zod": {
|
|
125
122
|
"optional": true
|
|
126
123
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// esbuild over a synthetic entry, sum the gzipped output, print to the job
|
|
4
4
|
// summary. This is NOT a production Metro figure — it is comparable across PRs.
|
|
5
5
|
//
|
|
6
|
-
// Why this exists: a single import of @copilotkit/react-core
|
|
6
|
+
// Why this exists: a single import of @copilotkit/react-core (instead of
|
|
7
7
|
// /v2/headless) would multiply this number, because Metro does not tree-shake
|
|
8
8
|
// (issue #4893). The structural guards fail first; this makes the magnitude
|
|
9
9
|
// visible if one is ever weakened.
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
//
|
|
27
27
|
// The symbols below are the lean headless API a custom-UI consumer imports.
|
|
28
28
|
// `useRenderToolCall` is included: RN's `src/headless.ts` re-exports it (from
|
|
29
|
-
// `@copilotkit/react-core/
|
|
29
|
+
// `@copilotkit/react-core/headless`) as of the render-tool convergence, so
|
|
30
30
|
// it belongs in the measured surface a custom-UI consumer pulls in.
|
|
31
31
|
//
|
|
32
32
|
// `platform: "browser"` + `target: "es2022"` mirror measure-copilotchat.mjs.
|
package/src/CopilotChat.tsx
CHANGED
|
@@ -6,8 +6,8 @@ import React, {
|
|
|
6
6
|
useRef,
|
|
7
7
|
} from "react";
|
|
8
8
|
import type { ReactNode } from "react";
|
|
9
|
-
import { useAgent } from "@copilotkit/react-core/
|
|
10
|
-
import { useCopilotKit } from "@copilotkit/react-core/
|
|
9
|
+
import { useAgent } from "@copilotkit/react-core/headless";
|
|
10
|
+
import { useCopilotKit } from "@copilotkit/react-core/context";
|
|
11
11
|
import { DEFAULT_AGENT_ID, randomUUID } from "@copilotkit/shared";
|
|
12
12
|
import type { InputContent } from "@copilotkit/shared";
|
|
13
13
|
import type { CopilotKitCoreErrorCode } from "@copilotkit/core";
|
|
@@ -3,18 +3,20 @@ import type { ReactNode } from "react";
|
|
|
3
3
|
import {
|
|
4
4
|
CopilotKitContext,
|
|
5
5
|
LicenseContext,
|
|
6
|
-
} from "@copilotkit/react-core/
|
|
6
|
+
} from "@copilotkit/react-core/context";
|
|
7
7
|
import type {
|
|
8
8
|
CopilotKitContextValue,
|
|
9
9
|
CopilotKitCoreReact as CopilotKitCoreReactInstance,
|
|
10
|
-
} from "@copilotkit/react-core/
|
|
11
|
-
import { CopilotKitCoreReact } from "@copilotkit/react-core/
|
|
10
|
+
} from "@copilotkit/react-core/context";
|
|
11
|
+
import { CopilotKitCoreReact } from "@copilotkit/react-core/headless";
|
|
12
12
|
import type {
|
|
13
13
|
CopilotKitCoreErrorCode,
|
|
14
14
|
CopilotKitMessageFilter,
|
|
15
15
|
} from "@copilotkit/core";
|
|
16
16
|
import type { DebugConfig, RuntimeLicenseStatus } from "@copilotkit/shared";
|
|
17
17
|
import { createLicenseContextValue } from "@copilotkit/shared";
|
|
18
|
+
import { MarkdownRendererProvider } from "./components/MarkdownRendererContext";
|
|
19
|
+
import type { MarkdownRendererValue } from "./components/MarkdownRendererContext";
|
|
18
20
|
|
|
19
21
|
export interface CopilotKitNativeProviderProps {
|
|
20
22
|
children: ReactNode;
|
|
@@ -77,6 +79,14 @@ export interface CopilotKitNativeProviderProps {
|
|
|
77
79
|
* subscriptions. Individual subscriptions can override with their own `throttleMs`.
|
|
78
80
|
*/
|
|
79
81
|
defaultThrottleMs?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Custom markdown renderer for assistant messages. Either a component (escape
|
|
84
|
+
* hatch — receives `content` and an optional `isStreaming` flag) used instead
|
|
85
|
+
* of the built-in renderer, or a `{ style, animate }` config object to
|
|
86
|
+
* configure the built-in React Native renderer (the `CopilotMarkdown` used by
|
|
87
|
+
* the default `AssistantMessage`) without writing a wrapper.
|
|
88
|
+
*/
|
|
89
|
+
markdownRenderer?: MarkdownRendererValue;
|
|
80
90
|
// Cloud features (publicApiKey, licenseToken) — not yet supported on React Native
|
|
81
91
|
}
|
|
82
92
|
|
|
@@ -114,6 +124,7 @@ export const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps> = ({
|
|
|
114
124
|
onError,
|
|
115
125
|
debug,
|
|
116
126
|
defaultThrottleMs,
|
|
127
|
+
markdownRenderer,
|
|
117
128
|
}) => {
|
|
118
129
|
// Resolve headers from function or static object (matches web provider pattern)
|
|
119
130
|
const resolvedHeaders =
|
|
@@ -265,7 +276,9 @@ export const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps> = ({
|
|
|
265
276
|
return (
|
|
266
277
|
<CopilotKitContext.Provider value={contextValue}>
|
|
267
278
|
<LicenseContext.Provider value={licenseContextValue}>
|
|
268
|
-
{
|
|
279
|
+
<MarkdownRendererProvider renderer={markdownRenderer}>
|
|
280
|
+
{children}
|
|
281
|
+
</MarkdownRendererProvider>
|
|
269
282
|
</LicenseContext.Provider>
|
|
270
283
|
</CopilotKitContext.Provider>
|
|
271
284
|
);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Why real, not mocked: `CopilotChat` renders tool calls via react-core's
|
|
6
6
|
* `useRenderToolCall`, which reads the renderer registry off the live
|
|
7
7
|
* `CopilotKitCoreReact` instance and derives streaming status/args in core.
|
|
8
|
-
* Mocking `@copilotkit/react-core/
|
|
8
|
+
* Mocking `@copilotkit/react-core/headless` (as the sibling chat tests do)
|
|
9
9
|
* would stub the very thing under test. Driving a real core exercises the
|
|
10
10
|
* production path end-to-end.
|
|
11
11
|
*
|
|
@@ -25,8 +25,8 @@ import {
|
|
|
25
25
|
CopilotKitContext,
|
|
26
26
|
CopilotKitCoreReact,
|
|
27
27
|
EMPTY_SET,
|
|
28
|
-
} from "@copilotkit/react-core/
|
|
29
|
-
import type { CopilotKitContextValue } from "@copilotkit/react-core/
|
|
28
|
+
} from "@copilotkit/react-core/context";
|
|
29
|
+
import type { CopilotKitContextValue } from "@copilotkit/react-core/context";
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Minimal agent: only holds seeded `messages` for the chat to read. `run()` is
|
|
@@ -82,7 +82,7 @@ function createMockCore() {
|
|
|
82
82
|
|
|
83
83
|
let mockCoreInstance: ReturnType<typeof createMockCore>;
|
|
84
84
|
|
|
85
|
-
vi.mock("@copilotkit/react-core/
|
|
85
|
+
vi.mock("@copilotkit/react-core/headless", () => {
|
|
86
86
|
function CopilotKitCoreReact(this: any, ...args: any[]) {
|
|
87
87
|
hoisted.MockCoreConstructor(...args);
|
|
88
88
|
const instance = hoisted.MockCoreConstructor.mock.results.at(-1)?.value;
|
|
@@ -121,7 +121,7 @@ vi.mock("@copilotkit/react-core/v2/headless", () => {
|
|
|
121
121
|
};
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
vi.mock("@copilotkit/react-core/
|
|
124
|
+
vi.mock("@copilotkit/react-core/context", () => {
|
|
125
125
|
const _React = require("react");
|
|
126
126
|
return {
|
|
127
127
|
CopilotKitContext: hoisted.RealContext,
|
|
@@ -52,7 +52,7 @@ function createMockCore() {
|
|
|
52
52
|
|
|
53
53
|
let mockCoreInstance: ReturnType<typeof createMockCore>;
|
|
54
54
|
|
|
55
|
-
vi.mock("@copilotkit/react-core/
|
|
55
|
+
vi.mock("@copilotkit/react-core/headless", () => {
|
|
56
56
|
function CopilotKitCoreReact(this: any, ...args: any[]) {
|
|
57
57
|
hoisted.MockCoreConstructor(...args);
|
|
58
58
|
const instance = hoisted.MockCoreConstructor.mock.results.at(-1)?.value;
|
|
@@ -92,7 +92,7 @@ vi.mock("@copilotkit/react-core/v2/headless", () => {
|
|
|
92
92
|
};
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
vi.mock("@copilotkit/react-core/
|
|
95
|
+
vi.mock("@copilotkit/react-core/context", () => {
|
|
96
96
|
const _React = require("react");
|
|
97
97
|
return {
|
|
98
98
|
CopilotKitContext: hoisted.RealContext,
|
|
@@ -80,7 +80,7 @@ function createMockCore() {
|
|
|
80
80
|
|
|
81
81
|
let mockCoreInstance: ReturnType<typeof createMockCore>;
|
|
82
82
|
|
|
83
|
-
vi.mock("@copilotkit/react-core/
|
|
83
|
+
vi.mock("@copilotkit/react-core/headless", () => {
|
|
84
84
|
function CopilotKitCoreReact(this: any, ...args: any[]) {
|
|
85
85
|
hoisted.MockCoreConstructor(...args);
|
|
86
86
|
const instance = hoisted.MockCoreConstructor.mock.results.at(-1)?.value;
|
|
@@ -119,7 +119,7 @@ vi.mock("@copilotkit/react-core/v2/headless", () => {
|
|
|
119
119
|
};
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
vi.mock("@copilotkit/react-core/
|
|
122
|
+
vi.mock("@copilotkit/react-core/context", () => {
|
|
123
123
|
const _React = require("react");
|
|
124
124
|
return {
|
|
125
125
|
CopilotKitContext: hoisted.RealContext,
|
|
@@ -52,7 +52,7 @@ function createMockCore() {
|
|
|
52
52
|
|
|
53
53
|
let mockCoreInstance: ReturnType<typeof createMockCore>;
|
|
54
54
|
|
|
55
|
-
vi.mock("@copilotkit/react-core/
|
|
55
|
+
vi.mock("@copilotkit/react-core/headless", () => {
|
|
56
56
|
function CopilotKitCoreReact(this: any, ...args: any[]) {
|
|
57
57
|
hoisted.MockCoreConstructor(...args);
|
|
58
58
|
const instance = hoisted.MockCoreConstructor.mock.results.at(-1)?.value;
|
|
@@ -92,7 +92,7 @@ vi.mock("@copilotkit/react-core/v2/headless", () => {
|
|
|
92
92
|
};
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
vi.mock("@copilotkit/react-core/
|
|
95
|
+
vi.mock("@copilotkit/react-core/context", () => {
|
|
96
96
|
const _React = require("react");
|
|
97
97
|
return {
|
|
98
98
|
CopilotKitContext: hoisted.RealContext,
|
|
@@ -52,7 +52,7 @@ function createMockCore() {
|
|
|
52
52
|
|
|
53
53
|
let mockCoreInstance: ReturnType<typeof createMockCore>;
|
|
54
54
|
|
|
55
|
-
vi.mock("@copilotkit/react-core/
|
|
55
|
+
vi.mock("@copilotkit/react-core/headless", () => {
|
|
56
56
|
function CopilotKitCoreReact(this: any, ...args: any[]) {
|
|
57
57
|
hoisted.MockCoreConstructor(...args);
|
|
58
58
|
const instance = hoisted.MockCoreConstructor.mock.results.at(-1)?.value;
|
|
@@ -92,7 +92,7 @@ vi.mock("@copilotkit/react-core/v2/headless", () => {
|
|
|
92
92
|
};
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
vi.mock("@copilotkit/react-core/
|
|
95
|
+
vi.mock("@copilotkit/react-core/context", () => {
|
|
96
96
|
const _React = require("react");
|
|
97
97
|
return {
|
|
98
98
|
CopilotKitContext: hoisted.RealContext,
|
|
@@ -41,7 +41,7 @@ const keepLastTurn = (messages: any[]) => messages.slice(-1);
|
|
|
41
41
|
/** A second, distinguishable filter, for asserting a swap took effect. */
|
|
42
42
|
const keepLastTwo = (messages: any[]) => messages.slice(-2);
|
|
43
43
|
|
|
44
|
-
vi.mock("@copilotkit/react-core/
|
|
44
|
+
vi.mock("@copilotkit/react-core/headless", () => {
|
|
45
45
|
// Regular function (not arrow) so it's new-able
|
|
46
46
|
function CopilotKitCoreReact(this: any, ...args: any[]) {
|
|
47
47
|
hoisted.MockCoreConstructor(...args);
|
|
@@ -51,7 +51,7 @@ vi.mock("@copilotkit/react-core/v2/headless", () => {
|
|
|
51
51
|
return { CopilotKitCoreReact };
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
vi.mock("@copilotkit/react-core/
|
|
54
|
+
vi.mock("@copilotkit/react-core/context", () => {
|
|
55
55
|
const _React = require("react");
|
|
56
56
|
return {
|
|
57
57
|
CopilotKitContext: hoisted.RealContext,
|