Files
copilotkit__copilotkit/packages/react-native/src/index.ts
Alem Tuzlak 43fdba74aa feat: AG-UI standard interrupt support in useInterrupt + BuiltInAgent
Adds the AG-UI standard interrupt flow (RUN_FINISHED outcome:interrupt + resume array) alongside the legacy on_interrupt path.

- core: forward the standard resume array through runAgent.
- react-core / vue / react-native: useInterrupt handles standard interrupts with resolve()/cancel(), surfaces the primary + full interrupt set, and persists each resolved tool-backed interrupt as a tool-result message so multi-turn conversations stay well-formed (no dangling tool call -> no tool-call loop).
- runtime BuiltInAgent: native interrupts for the aisdk + tanstack factory paths via each SDK's needsApproval primitive (tool-approval-request / CUSTOM approval-requested -> outcome:interrupt); classic interrupt-tool emission + ctx.interrupt() factory primitive; idempotent resume injection mapped to each SDK's native tool-result; getCapabilities advertises humanInTheLoop.interrupts.
- docs: document standard interrupt support.

Verified across core/react-core/runtime unit suites and a real-model multi-turn run on both aisdk and tanstack.
2026-06-23 20:14:17 +02:00

129 lines
4.1 KiB
TypeScript

/**
* @copilotkit/react-native
*
* React Native bindings for CopilotKit. Provides a lightweight provider
* and re-exports platform-agnostic hooks from @copilotkit/react-core.
*
* Polyfills (DOMException, ReadableStream, TextEncoder, etc.) are
* auto-imported when this module loads -- no manual
* `import "@copilotkit/react-native/polyfills"` needed.
*
* Quick start:
* ```tsx
* import { CopilotKitProvider, useAgent, useCopilotKit } from "@copilotkit/react-native";
* ```
*/
// Auto-install polyfills so consumers don't need a manual import.
// Must run before any CopilotKit code that relies on ReadableStream / fetch streaming.
import "./polyfills";
// React Native provider (no web dependencies)
export { CopilotKitProvider } from "./CopilotKitProvider";
export type { CopilotKitNativeProviderProps } from "./CopilotKitProvider";
// Provider props alias (mirrors web's CopilotKitProviderProps)
export type { CopilotKitNativeProviderProps as CopilotKitProviderProps } from "./CopilotKitProvider";
// Headless chat components (no DOM, consumer provides UI)
export { CopilotChat, useCopilotChatContext } from "./CopilotChat";
export type { CopilotChatProps, CopilotChatContextValue } from "./CopilotChat";
export { CopilotModal } from "./CopilotModal";
export type { CopilotModalProps } from "./CopilotModal";
// Native attachments hook and types
export { useAttachments } from "./hooks/use-attachments";
export type {
NativeAttachmentsConfig,
NativeFileInput,
UseNativeAttachmentsProps,
UseNativeAttachmentsReturn,
} from "./hooks/use-attachments";
// Pre-built UI components
export { CopilotSidebar } from "./CopilotSidebar";
export type {
CopilotSidebarProps,
CopilotSidebarHandle,
} from "./CopilotSidebar";
export { CopilotPopup } from "./CopilotPopup";
export type { CopilotPopupProps, CopilotPopupHandle } from "./CopilotPopup";
// Re-export context and hooks from react-core (platform-agnostic)
export {
useCopilotKit,
useLicenseContext,
CopilotKitContext,
type CopilotKitContextValue,
} from "@copilotkit/react-core/v2/context";
// Re-export hooks that work without web deps
// These consume the CopilotKitContext which our provider sets
export {
useAgent,
useFrontendTool,
useComponent,
useHumanInTheLoop,
useInterrupt,
useSuggestions,
useConfigureSuggestions,
useAgentContext,
useThreads,
useCapabilities,
defineToolCallRenderer,
CopilotChatDefaultLabels,
type UseAgentUpdate,
type UseInterruptConfig,
type AgentContextInput,
type JsonSerializable,
type Thread,
type UseThreadsInput,
type UseThreadsResult,
type CopilotChatLabels,
type CopilotChatConfigurationValue,
type InterruptEvent,
type InterruptHandlerProps,
type InterruptRenderProps,
type Interrupt,
type ResumeEntry,
type ResumeStatus,
type ReactFrontendTool,
type ReactHumanInTheLoop,
type RenderToolInProgressProps,
type RenderToolExecutingProps,
type RenderToolCompleteProps,
} from "@copilotkit/react-core/v2/headless";
// useRenderToolCall — web-specific (depends on DOM elements via DefaultToolCallRenderer)
// useRenderCustomMessages — web-specific (tightly coupled to web chat UI rendering pipeline)
// useRenderActivityMessage — web-specific (tightly coupled to web chat UI rendering pipeline)
// useDefaultRenderTool — web-specific (DefaultToolCallRenderer uses <div>, <svg>, etc.)
// Re-export core types commonly needed
export type {
CopilotKitCoreRuntimeConnectionStatus,
CopilotKitCoreErrorCode,
Suggestion,
FrontendTool,
ToolCallStatus,
} from "@copilotkit/core";
// Re-export AG-UI types for consumer convenience (matches web SDK surface)
export type {
Message,
AssistantMessage as AssistantMessageType,
ToolCall,
ToolMessage,
AbstractAgent,
AgentCapabilities,
} from "@ag-ui/client";
// Render tool hook (React Native version with render registry integration)
export { useRenderTool } from "./hooks/useRenderTool";
export type { UseRenderToolOptions } from "./hooks/useRenderTool";
export {
RenderToolProvider,
useRenderToolRegistry,
} from "./hooks/RenderToolContext";
export type { RenderToolProps } from "./hooks/RenderToolContext";