@copilotkit/react-native 1.57.1 → 1.57.2

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/dist/index.d.mts CHANGED
@@ -1,7 +1,11 @@
1
1
  import React, { ReactNode } from "react";
2
2
  import { CopilotKitContext, CopilotKitContextValue, useCopilotKit, useLicenseContext } from "@copilotkit/react-core/v2/context";
3
- import { UseAgentUpdate, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useFrontendTool, useHumanInTheLoop, useInterrupt, useSuggestions, useThreads } from "@copilotkit/react-core/v2/headless";
4
- import { CopilotKitCoreErrorCode, CopilotKitCoreErrorCode as CopilotKitCoreErrorCode$1, CopilotKitCoreRuntimeConnectionStatus } from "@copilotkit/core";
3
+ import { AgentContextInput, CopilotChatConfigurationValue, CopilotChatDefaultLabels, CopilotChatLabels, InterruptEvent, InterruptHandlerProps, InterruptRenderProps, JsonSerializable, ReactFrontendTool, ReactHumanInTheLoop, RenderToolCompleteProps, RenderToolExecutingProps, RenderToolInProgressProps, RenderToolProps, Thread, UseAgentUpdate, UseInterruptConfig, UseThreadsInput, UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useFrontendTool, useHumanInTheLoop, useInterrupt, useRenderTool, useSuggestions, useThreads } from "@copilotkit/react-core/v2/headless";
4
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
5
+ import { Attachment, AttachmentUploadErrorReason, AttachmentUploadResult, DebugConfig } from "@copilotkit/shared";
6
+ import { ViewStyle } from "react-native";
7
+ import { CopilotKitCoreErrorCode, CopilotKitCoreErrorCode as CopilotKitCoreErrorCode$1, CopilotKitCoreRuntimeConnectionStatus, FrontendTool, Suggestion, ToolCallStatus } from "@copilotkit/core";
8
+ import { AbstractAgent, AgentCapabilities, AssistantMessage, Message, ToolCall, ToolMessage } from "@ag-ui/client";
5
9
 
6
10
  //#region src/CopilotKitProvider.d.ts
7
11
  interface CopilotKitNativeProviderProps {
@@ -9,7 +13,11 @@ interface CopilotKitNativeProviderProps {
9
13
  /** URL of the CopilotKit runtime endpoint */
10
14
  runtimeUrl: string;
11
15
  /** Custom headers sent with every request */
12
- headers?: Record<string, string>;
16
+ headers?: Record<string, string> | (() => Record<string, string>);
17
+ /**
18
+ * Credentials mode for fetch requests (e.g., "include" for HTTP-only cookies in cross-origin requests).
19
+ */
20
+ credentials?: RequestCredentials;
13
21
  /** Whether the runtime uses a single-route endpoint */
14
22
  useSingleEndpoint?: boolean;
15
23
  /** Custom properties forwarded to agents */
@@ -23,7 +31,17 @@ interface CopilotKitNativeProviderProps {
23
31
  error: Error;
24
32
  code: CopilotKitCoreErrorCode$1;
25
33
  context: Record<string, any>;
26
- }) => void;
34
+ }) => void | Promise<void>;
35
+ /**
36
+ * Enable debug logging for the client-side event pipeline.
37
+ * When `true`, enables verbose logging from the core instance.
38
+ */
39
+ debug?: DebugConfig;
40
+ /**
41
+ * Default throttle interval (ms) for `onMessagesChanged` / `onStateChanged`
42
+ * subscriptions. Individual subscriptions can override with their own `throttleMs`.
43
+ */
44
+ defaultThrottleMs?: number;
27
45
  }
28
46
  /**
29
47
  * CopilotKit provider for React Native.
@@ -31,9 +49,12 @@ interface CopilotKitNativeProviderProps {
31
49
  * A lightweight alternative to the web CopilotKitProvider that avoids
32
50
  * web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
33
51
  *
52
+ * Polyfills are auto-imported when `@copilotkit/react-native` is loaded,
53
+ * so a separate `import "@copilotkit/react-native/polyfills"` is no longer
54
+ * required (though it remains available for advanced use).
55
+ *
34
56
  * Usage:
35
57
  * ```tsx
36
- * import "@copilotkit/react-native/polyfills";
37
58
  * import { CopilotKitProvider } from "@copilotkit/react-native";
38
59
  *
39
60
  * function App() {
@@ -47,5 +68,372 @@ interface CopilotKitNativeProviderProps {
47
68
  */
48
69
  declare const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps>;
49
70
  //#endregion
50
- export { CopilotKitContext, type CopilotKitContextValue, type CopilotKitCoreErrorCode, type CopilotKitCoreRuntimeConnectionStatus, type CopilotKitNativeProviderProps, CopilotKitProvider, type UseAgentUpdate, useAgent, useAgentContext, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useSuggestions, useThreads };
71
+ //#region src/hooks/use-attachments.d.ts
72
+ /**
73
+ * Platform-neutral file descriptor for React Native.
74
+ * Replaces the web `File` object in all attachment APIs.
75
+ */
76
+ interface NativeFileInput {
77
+ /** Local file URI (e.g. `file:///path/to/file`). */
78
+ uri: string;
79
+ /** Filename with extension. */
80
+ name: string;
81
+ /** File size in bytes. */
82
+ size: number;
83
+ /** MIME type (e.g. `"image/jpeg"`). */
84
+ mimeType: string;
85
+ }
86
+ /**
87
+ * React Native variant of AttachmentsConfig.
88
+ * Identical to the shared AttachmentsConfig except `onUpload` receives
89
+ * a `NativeFileInput` instead of a web `File`.
90
+ */
91
+ interface NativeAttachmentsConfig {
92
+ /** Enable file attachments in the chat input. */
93
+ enabled: boolean;
94
+ /** MIME type filter for the file picker, default all files. */
95
+ accept?: string;
96
+ /** Maximum file size in bytes, default 20MB (20 * 1024 * 1024). */
97
+ maxSize?: number;
98
+ /** Custom upload handler. Receives the native file descriptor. */
99
+ onUpload?: (file: NativeFileInput) => AttachmentUploadResult | Promise<AttachmentUploadResult>;
100
+ /** Called when an attachment fails validation or upload. */
101
+ onUploadFailed?: (error: {
102
+ reason: AttachmentUploadErrorReason;
103
+ file: NativeFileInput;
104
+ message: string;
105
+ }) => void;
106
+ }
107
+ interface UseNativeAttachmentsProps {
108
+ config?: NativeAttachmentsConfig;
109
+ }
110
+ interface UseNativeAttachmentsReturn {
111
+ /** Currently selected attachments (uploading + ready). */
112
+ attachments: Attachment[];
113
+ /** Whether attachments are enabled. */
114
+ enabled: boolean;
115
+ /** Open the native document picker. */
116
+ openPicker: () => Promise<void>;
117
+ /** Process an array of NativeFileInput objects (validate, read, add to state). */
118
+ processFiles: (files: NativeFileInput[]) => Promise<void>;
119
+ /** Remove an attachment by ID. */
120
+ removeAttachment: (id: string) => void;
121
+ /** Consume ready attachments and clear the queue. Returns the consumed attachments. */
122
+ consumeAttachments: () => Attachment[];
123
+ }
124
+ /**
125
+ * React Native hook that manages file attachment state -- picking, uploading,
126
+ * and lifecycle. All returned callbacks are referentially stable via useCallback.
127
+ *
128
+ * This is the RN counterpart of the web `useAttachments` hook from
129
+ * `@copilotkit/react-core`. It replaces web APIs (FileReader, DragEvent,
130
+ * HTMLInputElement) with Expo modules (expo-document-picker, expo-file-system).
131
+ */
132
+ declare function useAttachments({
133
+ config
134
+ }: UseNativeAttachmentsProps): UseNativeAttachmentsReturn;
135
+ //#endregion
136
+ //#region src/CopilotChat.d.ts
137
+ interface CopilotChatContextValue {
138
+ /** The resolved agent instance. */
139
+ agent: any;
140
+ /** Whether the agent is currently running. */
141
+ isRunning: boolean;
142
+ /** Current messages in the conversation. */
143
+ messages: any[];
144
+ /** Currently selected attachments (uploading + ready). */
145
+ attachments: Attachment[];
146
+ /** Whether attachments are enabled. */
147
+ attachmentsEnabled: boolean;
148
+ /** Open the native document picker to add files. */
149
+ openPicker: () => Promise<void>;
150
+ /** Remove an attachment by ID. */
151
+ removeAttachment: (id: string) => void;
152
+ /**
153
+ * Submit a message with optional attachments.
154
+ * Handles consuming ready attachments, building InputContent[],
155
+ * calling agent.addMessage, and running the agent.
156
+ */
157
+ submitMessage: (text: string) => Promise<void>;
158
+ }
159
+ /**
160
+ * Hook to access the CopilotChat context from child components.
161
+ * Must be called inside a `<CopilotChat>` component tree.
162
+ */
163
+ declare function useCopilotChatContext(): CopilotChatContextValue;
164
+ interface CopilotChatProps {
165
+ /**
166
+ * The agent ID to use for this chat session.
167
+ * Matches the web SDK's CopilotChat `agentId` prop.
168
+ *
169
+ * Resolution order: `agentId` > `agentName` > `"default"`
170
+ */
171
+ agentId?: string;
172
+ /**
173
+ * @deprecated Use `agentId` instead. `agentName` is kept for backwards
174
+ * compatibility and will be removed in a future release.
175
+ */
176
+ agentName?: string;
177
+ /**
178
+ * Thread ID for this chat session. When provided, the chat will resume
179
+ * the specified thread. Matches the web SDK's CopilotChat `threadId` prop.
180
+ */
181
+ threadId?: string;
182
+ /**
183
+ * Error handler scoped to this chat's agent. Fires in addition to the
184
+ * provider-level onError (does not suppress it). Receives only errors
185
+ * whose context.agentId matches this chat's agent.
186
+ */
187
+ onError?: (event: {
188
+ error: Error;
189
+ code: CopilotKitCoreErrorCode$1;
190
+ context: Record<string, any>;
191
+ }) => void | Promise<void>;
192
+ /**
193
+ * Throttle interval (in milliseconds) for re-renders triggered by message
194
+ * change notifications. Overrides the provider-level `defaultThrottleMs`
195
+ * for this chat instance. Forwarded to the internal `useAgent()` hook.
196
+ *
197
+ * @default undefined -- inherits from provider `defaultThrottleMs`;
198
+ * if that is also unset, re-renders are unthrottled.
199
+ */
200
+ throttleMs?: number;
201
+ /**
202
+ * Enable multimodal file attachments (images, audio, video, documents).
203
+ * Pass a NativeAttachmentsConfig object to configure file picking behavior.
204
+ */
205
+ attachments?: NativeAttachmentsConfig;
206
+ /**
207
+ * Optional children rendered inside the chat context.
208
+ */
209
+ children?: ReactNode;
210
+ /** Passthrough props are forwarded to consumers via the agent context. */
211
+ [key: string]: unknown;
212
+ }
213
+ /**
214
+ * Headless CopilotChat component for React Native.
215
+ *
216
+ * Wires up the `useAgent` hook with `agentId` resolution and renders children.
217
+ * Unlike the web SDK's CopilotChat, this component does not render any UI
218
+ * elements -- consumers provide their own React Native views.
219
+ *
220
+ * Children can access chat state via `useCopilotChatContext()`.
221
+ *
222
+ * ```tsx
223
+ * import { CopilotChat, useCopilotChatContext } from "@copilotkit/react-native";
224
+ *
225
+ * function MyChatUI() {
226
+ * const { messages, submitMessage, attachments, openPicker } = useCopilotChatContext();
227
+ * // ... render your UI
228
+ * }
229
+ *
230
+ * <CopilotChat agentId="my-agent" attachments={{ enabled: true }}>
231
+ * <MyChatUI />
232
+ * </CopilotChat>
233
+ * ```
234
+ */
235
+ declare function CopilotChat({
236
+ agentId,
237
+ agentName,
238
+ threadId,
239
+ onError,
240
+ throttleMs,
241
+ attachments: attachmentsConfig,
242
+ children,
243
+ ..._rest
244
+ }: CopilotChatProps): react_jsx_runtime0.JSX.Element;
245
+ //#endregion
246
+ //#region src/CopilotModal.d.ts
247
+ interface CopilotModalProps extends CopilotChatProps {
248
+ /**
249
+ * Optional children rendered inside the modal context.
250
+ */
251
+ children?: ReactNode;
252
+ }
253
+ /**
254
+ * Headless CopilotModal component for React Native.
255
+ *
256
+ * A thin wrapper around CopilotChat that mirrors the web SDK's CopilotModal
257
+ * API surface. On React Native, modal presentation is handled by the consumer
258
+ * (e.g. React Native's `Modal` component) -- this component only provides
259
+ * the agent wiring and prop resolution.
260
+ *
261
+ * ```tsx
262
+ * import { CopilotModal } from "@copilotkit/react-native";
263
+ * import { Modal } from "react-native";
264
+ *
265
+ * <Modal visible={isOpen}>
266
+ * <CopilotModal agentId="my-agent">
267
+ * <MyChatUI />
268
+ * </CopilotModal>
269
+ * </Modal>
270
+ * ```
271
+ */
272
+ declare function CopilotModal({
273
+ children,
274
+ ...props
275
+ }: CopilotModalProps): react_jsx_runtime0.JSX.Element;
276
+ //#endregion
277
+ //#region src/CopilotSidebar.d.ts
278
+ interface CopilotSidebarHandle {
279
+ /** Slide the drawer open. */
280
+ open(): void;
281
+ /** Slide the drawer closed. */
282
+ close(): void;
283
+ /** Toggle the drawer open/closed. */
284
+ toggle(): void;
285
+ }
286
+ interface CopilotSidebarProps extends Omit<CopilotChatProps, "children"> {
287
+ /**
288
+ * Start the drawer in the open position.
289
+ * @default false
290
+ */
291
+ defaultOpen?: boolean;
292
+ /**
293
+ * Width of the drawer panel. Accepts a number (points) or a percentage
294
+ * string (e.g. `"85%"`). Defaults to 85% of the screen width.
295
+ */
296
+ width?: number | string;
297
+ /**
298
+ * Title displayed in the drawer header bar.
299
+ * @default "Copilot"
300
+ */
301
+ headerTitle?: string;
302
+ /**
303
+ * Show a floating action button to toggle the drawer.
304
+ * @default true
305
+ */
306
+ showToggleButton?: boolean;
307
+ /** Called after the drawer finishes opening. */
308
+ onOpen?: () => void;
309
+ /** Called after the drawer finishes closing. */
310
+ onClose?: () => void;
311
+ /** Custom style applied to the drawer container. */
312
+ style?: ViewStyle;
313
+ /** Content rendered inside the drawer below the chat area. */
314
+ children?: ReactNode;
315
+ }
316
+ /**
317
+ * CopilotSidebar -- a slide-in drawer from the right edge of the screen
318
+ * that wraps CopilotChat for React Native.
319
+ *
320
+ * ```tsx
321
+ * import { CopilotSidebar } from "@copilotkit/react-native";
322
+ *
323
+ * const ref = useRef<CopilotSidebarHandle>(null);
324
+ *
325
+ * <CopilotSidebar
326
+ * ref={ref}
327
+ * agentId="my-agent"
328
+ * headerTitle="Assistant"
329
+ * defaultOpen={false}
330
+ * />
331
+ * ```
332
+ */
333
+ declare const CopilotSidebar: React.ForwardRefExoticComponent<Omit<CopilotSidebarProps, "ref"> & React.RefAttributes<CopilotSidebarHandle>>;
334
+ //#endregion
335
+ //#region src/CopilotPopup.d.ts
336
+ interface CopilotPopupProps {
337
+ /**
338
+ * The agent ID to use for this chat session.
339
+ * Passed through to CopilotChat.
340
+ */
341
+ agentId?: string;
342
+ /**
343
+ * @deprecated Use `agentId` instead.
344
+ */
345
+ agentName?: string;
346
+ /**
347
+ * Thread ID for this chat session.
348
+ */
349
+ threadId?: string;
350
+ /**
351
+ * Throttle interval (ms) for re-renders.
352
+ */
353
+ throttleMs?: number;
354
+ /**
355
+ * Whether the popup starts in the open state.
356
+ * @default false
357
+ */
358
+ defaultOpen?: boolean;
359
+ /**
360
+ * Height of the popup card. Accepts a number (points) or a percentage
361
+ * string (e.g. "60%") relative to the screen height.
362
+ * @default "60%"
363
+ */
364
+ height?: number | string;
365
+ /**
366
+ * Error handler scoped to this popup's chat agent.
367
+ */
368
+ onError?: (error: Error) => void;
369
+ /**
370
+ * Title displayed in the popup header bar.
371
+ * @default "CopilotKit"
372
+ */
373
+ headerTitle?: string;
374
+ /**
375
+ * Enable multimodal file attachments. Forwarded to the internal CopilotChat.
376
+ * Children access attachment state via `useCopilotChatContext()`.
377
+ */
378
+ attachments?: NativeAttachmentsConfig;
379
+ /**
380
+ * Optional children rendered below the CopilotChat content
381
+ * inside the popup card.
382
+ */
383
+ children?: ReactNode;
384
+ /**
385
+ * Callback fired when the popup opens.
386
+ */
387
+ onOpen?: () => void;
388
+ /**
389
+ * Callback fired when the popup closes.
390
+ */
391
+ onClose?: () => void;
392
+ /**
393
+ * Whether tapping the semi-transparent backdrop dismisses the popup.
394
+ * Equivalent to web SDK's `clickOutsideToClose`.
395
+ * @default true
396
+ */
397
+ dismissOnBackdropPress?: boolean;
398
+ /**
399
+ * Whether to show the floating action button (FAB) that toggles the popup.
400
+ * @default true
401
+ */
402
+ showToggleButton?: boolean;
403
+ /**
404
+ * Custom styles applied to the popup card container.
405
+ */
406
+ style?: ViewStyle;
407
+ }
408
+ /**
409
+ * Imperative handle exposed via ref for controlling the popup programmatically.
410
+ */
411
+ interface CopilotPopupHandle {
412
+ open: () => void;
413
+ close: () => void;
414
+ toggle: () => void;
415
+ }
416
+ /**
417
+ * CopilotPopup for React Native.
418
+ *
419
+ * A floating action button (FAB) that opens a modal chat overlay.
420
+ * The popup appears as a card floating above content with rounded corners,
421
+ * a shadow, and a semi-transparent backdrop.
422
+ *
423
+ * ```tsx
424
+ * import { CopilotPopup } from "@copilotkit/react-native";
425
+ *
426
+ * const popupRef = useRef<CopilotPopupHandle>(null);
427
+ *
428
+ * <CopilotPopup
429
+ * ref={popupRef}
430
+ * agentId="my-agent"
431
+ * headerTitle="Chat"
432
+ * defaultOpen={false}
433
+ * />
434
+ * ```
435
+ */
436
+ declare const CopilotPopup: React.ForwardRefExoticComponent<CopilotPopupProps & React.RefAttributes<CopilotPopupHandle>>;
437
+ //#endregion
438
+ export { type AbstractAgent, type AgentCapabilities, type AgentContextInput, type AssistantMessage, CopilotChat, type CopilotChatConfigurationValue, type CopilotChatContextValue, CopilotChatDefaultLabels, type CopilotChatLabels, type CopilotChatProps, CopilotKitContext, type CopilotKitContextValue, type CopilotKitCoreErrorCode, type CopilotKitCoreRuntimeConnectionStatus, type CopilotKitNativeProviderProps, type CopilotKitNativeProviderProps as CopilotKitProviderProps, CopilotKitProvider, CopilotModal, type CopilotModalProps, CopilotPopup, type CopilotPopupHandle, type CopilotPopupProps, CopilotSidebar, type CopilotSidebarHandle, type CopilotSidebarProps, type FrontendTool, type InterruptEvent, type InterruptHandlerProps, type InterruptRenderProps, type JsonSerializable, type Message, type NativeAttachmentsConfig, type NativeFileInput, type ReactFrontendTool, type ReactHumanInTheLoop, type RenderToolCompleteProps, type RenderToolExecutingProps, type RenderToolInProgressProps, type RenderToolProps, type Suggestion, type Thread, type ToolCall, type ToolCallStatus, type ToolMessage, type UseAgentUpdate, type UseInterruptConfig, type UseNativeAttachmentsProps, type UseNativeAttachmentsReturn, type UseThreadsInput, type UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useAttachments, useCapabilities, useComponent, useConfigureSuggestions, useCopilotChatContext, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useRenderTool, useSuggestions, useThreads };
51
439
  //# sourceMappingURL=index.d.mts.map