import React, { ReactNode } from "react"; import { ReactToolCallRenderer } from "@copilotkit/react-core/v2/headless"; import { DebugConfig, StandardSchemaV1 } from "@copilotkit/shared"; import { CopilotKitCoreErrorCode } from "@copilotkit/core"; //#region src/CopilotKitProvider.d.ts interface CopilotKitNativeProviderProps { children: ReactNode; /** URL of the CopilotKit runtime endpoint */ runtimeUrl: string; /** Custom headers sent with every request */ headers?: Record | (() => Record); /** * Credentials mode for fetch requests (e.g., "include" for HTTP-only cookies in cross-origin requests). */ credentials?: RequestCredentials; /** Whether the runtime uses a single-route endpoint */ useSingleEndpoint?: boolean; /** Custom properties forwarded to agents */ properties?: Record; /** * Error handler called when CopilotKit encounters an error. * Fires for all error types (runtime connection failures, agent errors, tool errors). * If not provided, errors are logged to console.error. */ onError?: (event: { error: Error; code: CopilotKitCoreErrorCode; context: Record; }) => void | Promise; /** * Enable debug logging for the client-side event pipeline. * When `true`, enables verbose logging from the core instance. */ debug?: DebugConfig; /** * Default throttle interval (ms) for `onMessagesChanged` / `onStateChanged` * subscriptions. Individual subscriptions can override with their own `throttleMs`. */ defaultThrottleMs?: number; } /** * CopilotKit provider for React Native. * * A lightweight alternative to the web CopilotKitProvider that avoids * web-only dependencies (DOM, CSS, Radix UI, Lit, etc). * * Polyfills are auto-imported when `@copilotkit/react-native` is loaded, * so a separate `import "@copilotkit/react-native/polyfills"` is no longer * required (though it remains available for advanced use). * * Usage: * ```tsx * import { CopilotKitProvider } from "@copilotkit/react-native"; * * function App() { * return ( * * * * ); * } * ``` */ declare const CopilotKitProvider: React.FC; //#endregion //#region src/hooks/render-tool-types.d.ts /** * Props a React Native render function receives for a tool call. * * DERIVED from react-core's canonical `ReactToolCallRenderer` contract rather * than declared separately. This is deliberate: RN previously declared its own * shape and drifted from that contract — RN's `status` was a two-member * `"executing" | "complete"` union with no in-progress state, RN omitted * `name`/`toolCallId` entirely, and RN's `args` was unconditionally the full * `T`, promising complete arguments even before they had finished streaming. * * What the derivation buys, precisely: RN's props cannot drift from * `ReactToolCallRenderer` — the contract every registered renderer is * actually invoked against, and the type this alias reads through * `React.ComponentProps`. Change that contract and RN's public type changes * with it, so `check-types` names every RN renderer the change breaks. * * What it does NOT buy: parity with the type react-core *publicly exports* * under this same name. Web's `RenderToolProps` * (react-core `src/v2/hooks/use-render-tool.tsx`) is a separate union, generic * over a schema rather than over the parsed args, carrying arguments under * `parameters` (not `args`) and declaring `status` as the string literals * `"inProgress"` / `"executing"` / `"complete"` rather than as `ToolCallStatus` * members. Both divergences are live today and nothing type-checks them shut: * the two types share no structural relation, and the one place they meet — * react-core's own bridge, which spreads the enum-typed renderer props into * the literal-typed slot — compiles because a string-enum member is * assignable to its own literal type (not the reverse). Web's `status` is a * widening of the canonical contract, not a derivation from it. RN's entry * point also re-exports web's three `RenderTool*Props` arms, so both shapes * ship under confusingly similar names. * * `status` is the discriminant of a three-arm union, typed as the * `ToolCallStatus` enum (`@copilotkit/core`), so narrow with the enum members * rather than the raw strings: `args` is `Partial` only on * `ToolCallStatus.InProgress`, and `result` is a string only on * `ToolCallStatus.Complete`. */ type RenderToolProps> = React.ComponentProps["render"]>; /** * A render function returning a React Native element. * * This is the one place RN legitimately narrows `ReactToolCallRenderer`: * `FlatList`'s `renderItem` cannot render strings or portals, so RN requires * `ReactElement | null` where that contract permits any `ReactNode`. The PROPS * come from it unchanged; only the return type is platform-specific. */ type RenderToolFunction> = (props: RenderToolProps) => React.ReactElement | null; //#endregion //#region src/hooks/useRenderTool.d.ts /** * Options for the useRenderTool hook. */ interface UseRenderToolOptions> { /** Unique name for the tool. Must match what the agent calls. */ name: string; /** Human-readable description shown to the agent. */ description: string; /** Schema describing the tool's parameters (any StandardSchemaV1 library). */ parameters: StandardSchemaV1; /** * Render function returning a React Native element for the tool call. * Rendered by `CopilotChat` inline, and by `useRenderToolCall()` anywhere else. * * Arguments STREAM: on `status: "inProgress"` the props are partial, because * the model has not finished writing the JSON. Write renderers that tolerate * missing fields — that is what makes UI build progressively. */ render: RenderToolFunction; /** Optional handler. Omit for render-only (display IS the effect). */ handler?: (args: T) => Promise; /** Scope this tool to a single agent. */ agentId?: string; } /** * Registers a frontend tool AND its renderer. * * Registration goes through react-core's `useFrontendTool`, which writes the * renderer into `CopilotKitCoreReact.renderToolCalls` — the canonical registry * that RN's provider already instantiates. There is deliberately NO React * Native-local registry: this package previously kept its own Map, which meant * `useComponent` (registering into core's) rendered nowhere on RN, and renderers * were dropped from chat history on unmount. */ /** * @param deps Optional dependency array. The `render` function is captured at * registration and only refreshed when `deps` change — it does NOT re-read the * latest closure on every render. If your `render` closes over component state * or props that change over time, you MUST pass those values in `deps`, or the * chat will keep painting with the stale closure. */ declare function useRenderTool = Record>(options: UseRenderToolOptions, deps?: ReadonlyArray): void; //#endregion export { CopilotKitNativeProviderProps as a, RenderToolProps as i, useRenderTool as n, CopilotKitProvider as o, RenderToolFunction as r, UseRenderToolOptions as t }; //# sourceMappingURL=useRenderTool-BBxnOOeJ.d.mts.map