UNPKG

@copilotkit/react-core

Version:

<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />

775 lines (774 loc) 30.1 kB
import React$1, { ComponentType, ReactNode } from "react"; import { InferSchemaOutput, StandardSchemaV1 } from "@copilotkit/shared"; import { CopilotKitCore, CopilotKitCoreConfig, CopilotKitCoreSubscriber, CopilotKitCoreSubscription, DynamicSuggestionsConfig, FrontendTool, StaticSuggestionsConfig, Suggestion, ToolCallStatus } from "@copilotkit/core"; import { ActivityMessage, AgentCapabilities, Message } from "@ag-ui/core"; import { AbstractAgent, Interrupt, ResumeEntry, ResumeStatus, RunAgentResult } from "@ag-ui/client"; //#region src/v2/types/react-tool-call-renderer.d.ts interface ReactToolCallRenderer<T = unknown> { name: string; /** * Schema describing the tool arguments. Optional — renderers registered for * tools without parameters (e.g. HITL confirm dialogs) have no schema. */ args?: StandardSchemaV1<any, T>; /** * Optional agent ID to constrain this tool renderer to a specific agent. * If specified, this renderer will only be used for the specified agent. */ agentId?: string; render: React.ComponentType<{ name: string; toolCallId: string; args: Partial<T>; status: ToolCallStatus.InProgress; result: undefined; } | { name: string; toolCallId: string; args: T; status: ToolCallStatus.Executing; result: undefined; } | { name: string; toolCallId: string; args: T; status: ToolCallStatus.Complete; result: string; }>; } //#endregion //#region src/v2/types/react-activity-message-renderer.d.ts interface ReactActivityMessageRenderer<TActivityContent> { /** * Activity type to match when rendering. Use "*" as a wildcard renderer. */ activityType: string; /** * Optional agent ID to scope the renderer to a particular agent. */ agentId?: string; /** * Schema describing the activity content payload. */ content: StandardSchemaV1<any, TActivityContent>; /** * React component invoked to render the activity message. */ render: React.ComponentType<{ activityType: string; content: TActivityContent; message: ActivityMessage; agent: AbstractAgent | undefined; }>; } //#endregion //#region src/v2/types/react-custom-message-renderer.d.ts type ReactCustomMessageRendererPosition = "before" | "after"; interface ReactCustomMessageRenderer { agentId?: string; render: React.ComponentType<{ message: Message; position: ReactCustomMessageRendererPosition; runId: string; messageIndex: number; messageIndexInRun: number; numberOfMessagesInRun: number; agentId: string; stateSnapshot: any; }> | null; } //#endregion //#region src/v2/types/frontend-tool.d.ts type ReactFrontendTool<T extends Record<string, unknown> = Record<string, unknown>> = FrontendTool<T> & { render?: ReactToolCallRenderer<T>["render"]; }; //#endregion //#region src/v2/types/human-in-the-loop.d.ts type ReactHumanInTheLoop<T extends Record<string, unknown> = Record<string, unknown>> = Omit<FrontendTool<T>, "handler"> & { /** * Render the human-in-the-loop UI for this tool call. * * Beyond the tool call's `args`/`status`/`result`, the render props carry * attribution: * - `toolCallId` — the AG-UI tool call id, unique per interrupt. It is the * stable key for correlating this interrupt with runtime (sub)agent * attribution — e.g. the `agentId` reported by `onToolExecutionStart`, or * per-run attribution stamped on the event stream — so the UI can label * the interrupt with the agent that actually raised it. * - `agentId` — the agent this tool was *registered* to (the tool's own * `agentId`), or `undefined` for an unscoped tool. This is the static * registration scope; it is NOT necessarily the runtime (sub)agent that * raised the interrupt. For runtime attribution, correlate `toolCallId` * with the event-stream/`onToolExecutionStart` agent id. */ render: React$1.ComponentType<{ name: string; description: string; toolCallId: string; agentId?: string; args: Partial<T>; status: ToolCallStatus.InProgress; result: undefined; respond: undefined; } | { name: string; description: string; toolCallId: string; agentId?: string; args: T; status: ToolCallStatus.Executing; result: undefined; respond: (result: unknown) => Promise<void>; } | { name: string; description: string; toolCallId: string; agentId?: string; args: T; status: ToolCallStatus.Complete; result: string; respond: undefined; }>; }; //#endregion //#region src/v2/types/defineToolCallRenderer.d.ts /** * Helper to define a type-safe tool call renderer entry. * - Accepts a single object whose keys match ReactToolCallRenderer's fields: { name, args, render, agentId? }. * - Derives `args` type from the provided schema (any Standard Schema V1 compatible library). * - Ensures the render function param type exactly matches ReactToolCallRenderer<T>["render"]'s param. * - For wildcard tools (name: "*"), args is optional and defaults to z.any() */ type RenderProps<T> = { name: string; toolCallId: string; args: Partial<T>; status: ToolCallStatus.InProgress; result: undefined; } | { name: string; toolCallId: string; args: T; status: ToolCallStatus.Executing; result: undefined; } | { name: string; toolCallId: string; args: T; status: ToolCallStatus.Complete; result: string; }; declare function defineToolCallRenderer(def: { name: "*"; render: (props: RenderProps<any>) => React$1.ReactElement; agentId?: string; }): ReactToolCallRenderer<any>; declare function defineToolCallRenderer<S extends StandardSchemaV1>(def: { name: string; args: S; render: (props: RenderProps<InferSchemaOutput<S>>) => React$1.ReactElement; agentId?: string; }): ReactToolCallRenderer<InferSchemaOutput<S>>; //#endregion //#region src/v2/types/interrupt.d.ts /** Legacy custom-event interrupt payload (agent emits a custom `on_interrupt` event). */ interface InterruptEvent<TValue = unknown> { name: string; value: TValue; } /** * Resolve the agent with user input for an interrupt. * * - Standard interrupts: records `{ status: "resolved", payload }` for the target * interrupt (defaults to the primary one). Resumes once every open interrupt is * addressed; returns the resume run result, or `void` while still awaiting others. * - Legacy interrupts: resumes immediately via `command.resume = payload`. */ type InterruptResolveFn = (payload?: unknown, interruptId?: string) => Promise<RunAgentResult | void>; /** * Cancel an interrupt. * * - Standard interrupts: records `{ status: "cancelled" }` for the target interrupt * (defaults to the primary one), then resumes once all are addressed. * - Legacy interrupts: dismisses the pending interrupt without resuming. */ type InterruptCancelFn = (interruptId?: string) => Promise<RunAgentResult | void>; interface InterruptHandlerProps<TValue = unknown> { /** * Legacy event shape (`{ name, value }`). Always present for back-compat: for * standard interrupts, `value` is the primary `Interrupt` and `name` is `"on_interrupt"`. * Prefer `interrupt` / `interrupts` for standard interrupts. */ event: InterruptEvent<TValue>; /** Primary standard interrupt (`interrupts[0]`), or `null` for legacy interrupts. */ interrupt: Interrupt | null; /** All open standard interrupts (empty array for legacy interrupts). */ interrupts: Interrupt[]; resolve: InterruptResolveFn; cancel: InterruptCancelFn; } interface InterruptRenderProps<TValue = unknown, TResult = unknown> { event: InterruptEvent<TValue>; interrupt: Interrupt | null; interrupts: Interrupt[]; result: TResult; resolve: InterruptResolveFn; cancel: InterruptCancelFn; } //#endregion //#region src/v2/lib/react-core.d.ts interface CopilotKitCoreReactConfig extends CopilotKitCoreConfig { renderToolCalls?: ReactToolCallRenderer<any>[]; renderActivityMessages?: ReactActivityMessageRenderer<any>[]; renderCustomMessages?: ReactCustomMessageRenderer[]; } interface CopilotKitCoreReactSubscriber extends CopilotKitCoreSubscriber { onRenderToolCallsChanged?: (event: { copilotkit: CopilotKitCore; renderToolCalls: ReactToolCallRenderer<any>[]; }) => void | Promise<void>; onInterruptElementChanged?: (event: { copilotkit: CopilotKitCore; interruptElement: React$1.ReactElement | null; }) => void | Promise<void>; } declare class CopilotKitCoreReact extends CopilotKitCore { private _renderToolCalls; private _hookRenderToolCalls; private _cachedMergedRenderToolCalls; private _renderCustomMessages; private _renderActivityMessages; private _interruptElement; constructor(config: CopilotKitCoreReactConfig); get renderCustomMessages(): Readonly<ReactCustomMessageRenderer[]>; get renderActivityMessages(): Readonly<ReactActivityMessageRenderer<any>>[]; get renderToolCalls(): Readonly<ReactToolCallRenderer<any>>[]; setRenderActivityMessages(renderers: ReactActivityMessageRenderer<any>[]): void; setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void; setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void; addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void; removeHookRenderToolCall(name: string, agentId?: string): void; private _notifyRenderToolCallsChanged; get interruptElement(): React$1.ReactElement | null; setInterruptElement(element: React$1.ReactElement | null): void; subscribe(subscriber: CopilotKitCoreReactSubscriber): CopilotKitCoreSubscription; /** * Wait for pending React state updates before the follow-up agent run. * * When a frontend tool handler calls setState(), React 18 batches the update * and schedules a commit via its internal scheduler (MessageChannel). The * useAgentContext hook registers context via useLayoutEffect, which runs * synchronously after React commits that batch. * * Awaiting a zero-delay timeout yields to the macrotask queue. React's * MessageChannel task runs first, committing the pending state and running * useLayoutEffect (which updates the context store). The follow-up runAgent * call then reads fresh context. */ waitForPendingFrameworkUpdates(): Promise<void>; } //#endregion //#region src/v2/providers/CopilotChatConfigurationProvider.d.ts declare const CopilotChatDefaultLabels: { chatInputPlaceholder: string; chatInputToolbarStartTranscribeButtonLabel: string; chatInputToolbarCancelTranscribeButtonLabel: string; chatInputToolbarFinishTranscribeButtonLabel: string; chatInputToolbarAddButtonLabel: string; chatInputToolbarToolsButtonLabel: string; assistantMessageToolbarCopyCodeLabel: string; assistantMessageToolbarCopyCodeCopiedLabel: string; assistantMessageToolbarCopyMessageLabel: string; assistantMessageToolbarThumbsUpLabel: string; assistantMessageToolbarThumbsDownLabel: string; assistantMessageToolbarReadAloudLabel: string; assistantMessageToolbarRegenerateLabel: string; userMessageToolbarCopyMessageLabel: string; userMessageToolbarEditMessageLabel: string; chatDisclaimerText: string; chatToggleOpenLabel: string; chatToggleCloseLabel: string; modalHeaderTitle: string; welcomeMessageText: string; }; type CopilotChatLabels = typeof CopilotChatDefaultLabels; interface CopilotChatConfigurationValue { labels: CopilotChatLabels; agentId: string; threadId: string; isModalOpen: boolean; setModalOpen: (open: boolean) => void; hasExplicitThreadId: boolean; } interface CopilotChatConfigurationProviderProps { children: ReactNode; labels?: Partial<CopilotChatLabels>; agentId?: string; threadId?: string; hasExplicitThreadId?: boolean; isModalDefaultOpen?: boolean; } declare const CopilotChatConfigurationProvider: React$1.FC<CopilotChatConfigurationProviderProps>; declare const useCopilotChatConfiguration: () => CopilotChatConfigurationValue | null; //#endregion //#region src/v2/hooks/use-agent.d.ts declare enum UseAgentUpdate { OnMessagesChanged = "OnMessagesChanged", OnStateChanged = "OnStateChanged", OnRunStatusChanged = "OnRunStatusChanged" } interface UseAgentProps { agentId?: string; updates?: UseAgentUpdate[]; /** * Throttle interval (in milliseconds) for re-renders triggered by * `onMessagesChanged` and `onStateChanged` notifications. Useful to reduce * re-render frequency during high-frequency streaming updates. * * Uses a leading+trailing pattern with a shared window — first update * fires immediately, subsequent updates within the window are coalesced, * and a trailing timer ensures the most recent update fires after the * window expires. See `CopilotKitCore.subscribeToAgentWithOptions` in `@copilotkit/core` * for details. * * Resolved as: `throttleMs ?? provider defaultThrottleMs ?? 0`. * Passing `throttleMs={0}` explicitly disables throttling even when the * provider specifies a non-zero `defaultThrottleMs`. * * Run lifecycle callbacks (`onRunInitialized`, `onRunFinalized`, * `onRunFailed`, `onRunErrorEvent`) always fire immediately. * * @default undefined * When unset, inherits from the provider's `defaultThrottleMs`; * if that is also unset, the effective value is `0` (no throttle). */ throttleMs?: number; } declare function useAgent({ agentId, updates, throttleMs }?: UseAgentProps): { agent: AbstractAgent; }; //#endregion //#region src/v2/hooks/use-frontend-tool.d.ts declare function useFrontendTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: ReactFrontendTool<T>, deps?: ReadonlyArray<unknown>): void; //#endregion //#region src/v2/hooks/use-component.d.ts type InferRenderProps<T> = T extends StandardSchemaV1 ? InferSchemaOutput<T> : any; /** * Registers a React component as a frontend tool renderer in chat. * * This hook is a convenience wrapper around `useFrontendTool` that: * - builds a model-facing tool description, * - forwards optional schema parameters (any Standard Schema V1 compatible library), * - renders your component with tool call parameters. * * Use this when you want to display a typed visual component for a tool call * without manually wiring a full frontend tool object. * * When `parameters` is provided, render props are inferred from the schema. * When omitted, the render component may accept any props. * * @typeParam TSchema - Schema describing tool parameters, or `undefined` when no schema is given. * @param config - Tool registration config. * @param deps - Optional dependencies to refresh registration (same semantics as `useEffect`). * * @example * ```tsx * // Without parameters — render accepts any props * useComponent({ * name: "showGreeting", * render: ({ message }: { message: string }) => <div>{message}</div>, * }); * ``` * * @example * ```tsx * // With parameters — render props inferred from schema * useComponent({ * name: "showWeatherCard", * parameters: z.object({ city: z.string() }), * render: ({ city }) => <div>{city}</div>, * }); * ``` * * @example * ```tsx * useComponent( * { * name: "renderProfile", * parameters: z.object({ userId: z.string() }), * render: ProfileCard, * agentId: "support-agent", * }, * [selectedAgentId], * ); * ``` */ declare function useComponent<TSchema extends StandardSchemaV1<any, Record<string, unknown>> | undefined = undefined>(config: { name: string; description?: string; parameters?: TSchema; render: ComponentType<NoInfer<InferRenderProps<TSchema>>>; agentId?: string; followUp?: boolean; }, deps?: ReadonlyArray<unknown>): void; //#endregion //#region src/v2/hooks/use-human-in-the-loop.d.ts declare function useHumanInTheLoop<T extends Record<string, unknown> = Record<string, unknown>>(tool: ReactHumanInTheLoop<T>, deps?: ReadonlyArray<unknown>): void; //#endregion //#region src/v2/hooks/use-interrupt.d.ts type InterruptHandlerFn<TValue, TResult> = (props: InterruptHandlerProps<TValue>) => TResult | PromiseLike<TResult>; type InterruptResultFromHandler<THandler> = THandler extends ((...args: never[]) => infer TResult) ? TResult extends PromiseLike<infer TResolved> ? TResolved | null : TResult | null : null; type InterruptResult<TValue, TResult> = InterruptResultFromHandler<InterruptHandlerFn<TValue, TResult>>; type InterruptRenderInChat = boolean | undefined; type UseInterruptReturn<TRenderInChat extends InterruptRenderInChat> = TRenderInChat extends false ? React$1.ReactElement | null : TRenderInChat extends true | undefined ? void : React$1.ReactElement | null | void; /** * Configuration options for `useInterrupt`. */ interface UseInterruptConfigBase<TValue = unknown, TResult = never> { /** * Render function for the interrupt UI. * * Receives both the standard `interrupt`/`interrupts` and the legacy `event`. * Call `resolve(payload)` to resume with user input, or `cancel()` to cancel. */ render: (props: InterruptRenderProps<TValue, InterruptResult<TValue, TResult>>) => React$1.ReactElement; /** * Optional pre-render handler invoked when an interrupt is received. * Return a sync or async value to expose as `result` in `render`. * Rejecting/throwing falls back to `result = null`. */ handler?: InterruptHandlerFn<TValue, TResult>; /** * Optional predicate to filter which interrupts this hook handles. * Receives the legacy-compatible event (for standard interrupts, `value` is * the primary `Interrupt`). Return `false` to ignore. */ enabled?: (event: InterruptEvent<TValue>) => boolean; /** Optional agent id. Defaults to the current configured chat agent. */ agentId?: string; } type UseInterruptConfig<TValue = unknown, TResult = never, TRenderInChat extends InterruptRenderInChat = undefined> = UseInterruptConfigBase<TValue, TResult> & { /** When true (default), the interrupt UI renders inside `<CopilotChat>` automatically. */renderInChat?: TRenderInChat; }; /** * Handles agent interrupts with optional filtering, preprocessing, and resume behavior. * * Supports both the AG-UI standard interrupt flow (`RUN_FINISHED` with * `outcome.type === "interrupt"`) and the legacy custom-event flow * (`on_interrupt`). For standard interrupts, `render` receives `interrupt` * (the primary one) and `interrupts` (the full open set); call `resolve(payload)` * to resume or `cancel()` to cancel. Resuming addresses the targeted interrupt * and, once every open interrupt is addressed, submits a single spec `resume` * array via `copilotkit.runAgent`. * * - `renderInChat: true` (default): the element is published into `<CopilotChat>`; returns `void`. * - `renderInChat: false`: the hook returns the interrupt element for manual placement. * * @example * ```tsx * useInterrupt({ * render: ({ interrupt, resolve, cancel }) => ( * <div> * <p>{interrupt?.message}</p> * <button onClick={() => resolve({ approved: true })}>Approve</button> * <button onClick={() => cancel()}>Cancel</button> * </div> * ), * }); * ``` */ declare function useInterrupt<TResult = never, TRenderInChat extends InterruptRenderInChat = undefined>(config: UseInterruptConfig<any, TResult, TRenderInChat>): UseInterruptReturn<TRenderInChat>; //#endregion //#region src/v2/hooks/use-suggestions.d.ts interface UseSuggestionsOptions { agentId?: string; } interface UseSuggestionsResult { suggestions: Suggestion[]; reloadSuggestions: () => void; clearSuggestions: () => void; isLoading: boolean; } declare function useSuggestions({ agentId }?: UseSuggestionsOptions): UseSuggestionsResult; //#endregion //#region src/v2/hooks/use-configure-suggestions.d.ts type StaticSuggestionInput = Omit<Suggestion, "isLoading"> & Partial<Pick<Suggestion, "isLoading">>; type StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, "suggestions"> & { suggestions: StaticSuggestionInput[]; }; type SuggestionsConfigInput = DynamicSuggestionsConfig | StaticSuggestionsConfigInput; declare function useConfigureSuggestions(config: SuggestionsConfigInput | null | undefined, deps?: ReadonlyArray<unknown>): void; //#endregion //#region src/v2/hooks/use-agent-context.d.ts /** * Represents any value that can be serialized to JSON. */ type JsonSerializable = string | number | boolean | null | JsonSerializable[] | { [key: string]: JsonSerializable; }; /** * Context configuration for useAgentContext. * Accepts any JSON-serializable value which will be converted to a string. */ interface AgentContextInput { /** A human-readable description of what this context represents */ description: string; /** The context value - will be converted to a JSON string if not already a string */ value: JsonSerializable; } declare function useAgentContext(context: AgentContextInput): void; //#endregion //#region src/v2/hooks/use-threads.d.ts /** * A conversation thread managed by the Intelligence platform. * * Each thread has a unique `id`, an optional human-readable `name`, and * timestamp fields tracking creation and update times. */ interface Thread { id: string; agentId: string; name: string | null; archived: boolean; createdAt: string; updatedAt: string; /** * ISO-8601 timestamp of the most recent agent run on this thread. Absent * when the thread has never been run. Prefer this over `updatedAt` for * user-facing "last activity" displays — it is not bumped by metadata-only * actions like rename or archive. */ lastRunAt?: string; } /** * Configuration for the {@link useThreads} hook. * * Thread operations are scoped to the runtime-authenticated user and the * provided agent on the Intelligence platform. */ interface UseThreadsInput { /** The ID of the agent whose threads to list and manage. */ agentId: string; /** When `true`, archived threads are included in the list. Defaults to `false`. */ includeArchived?: boolean; /** Maximum number of threads to fetch per page. When set, enables cursor-based pagination. */ limit?: number; } /** * Return value of the {@link useThreads} hook. * * The `threads` array is kept in sync with the platform via a realtime * WebSocket subscription (when available) and is sorted most-recently-updated * first. Mutations reject with an `Error` if the platform request fails. */ interface UseThreadsResult { /** * Threads for the current user/agent pair, sorted by most recently * updated first. Updated in realtime when the platform pushes metadata * events. Includes archived threads only when `includeArchived` is set. */ threads: Thread[]; /** * `true` while the initial thread list is being fetched from the platform. * Subsequent realtime updates do not re-enter the loading state. */ isLoading: boolean; /** * The most recent error from fetching threads or executing a mutation, * or `null` when there is no error. Reset to `null` on the next * successful fetch. */ error: Error | null; /** * `true` when there are more threads available to fetch via * {@link fetchMoreThreads}. Only meaningful when `limit` is set. */ hasMoreThreads: boolean; /** * `true` while a subsequent page of threads is being fetched. */ isFetchingMoreThreads: boolean; /** * Fetch the next page of threads. No-op when {@link hasMoreThreads} is * `false` or a fetch is already in progress. */ fetchMoreThreads: () => void; /** * Rename a thread on the platform. * Resolves when the server confirms the update; rejects on failure. */ renameThread: (threadId: string, name: string) => Promise<void>; /** * Archive a thread on the platform. * Archived threads are excluded from subsequent list results. * Resolves when the server confirms the update; rejects on failure. */ archiveThread: (threadId: string) => Promise<void>; /** * Restore a previously archived thread on the platform. * The thread re-appears in default (non-archived) list results. * Resolves when the server confirms the update; rejects on failure. */ unarchiveThread: (threadId: string) => Promise<void>; /** * Permanently delete a thread from the platform. * This is irreversible. Resolves when the server confirms deletion; * rejects on failure. */ deleteThread: (threadId: string) => Promise<void>; } /** * React hook for listing and managing Intelligence platform threads. * * On mount the hook fetches the thread list for the runtime-authenticated user * and the given `agentId`. When the Intelligence platform exposes a WebSocket * URL, it also opens a realtime subscription so the `threads` array stays * current without polling — thread creates, renames, archives, and deletes * from any client are reflected immediately. * * Mutation methods (`renameThread`, `archiveThread`, `unarchiveThread`, * `deleteThread`) return promises that resolve once the platform confirms the * operation and reject with an `Error` on failure. * * @param input - Agent identifier and optional list controls. * @returns Thread list state and stable mutation callbacks. * * @example * ```tsx * import { useThreads } from "@copilotkit/react-core"; * * function ThreadList() { * const { threads, isLoading, renameThread, deleteThread } = useThreads({ * agentId: "agent-1", * }); * * if (isLoading) return <p>Loading…</p>; * * return ( * <ul> * {threads.map((t) => ( * <li key={t.id}> * {t.name ?? "Untitled"} * <button onClick={() => renameThread(t.id, "New name")}>Rename</button> * <button onClick={() => deleteThread(t.id)}>Delete</button> * </li> * ))} * </ul> * ); * } * ``` */ declare function useThreads({ agentId, includeArchived, limit }: UseThreadsInput): UseThreadsResult; //#endregion //#region src/v2/hooks/use-render-tool.d.ts interface RenderToolInProgressProps<S extends StandardSchemaV1> { name: string; toolCallId: string; parameters: Partial<InferSchemaOutput<S>>; status: "inProgress"; result: undefined; } interface RenderToolExecutingProps<S extends StandardSchemaV1> { name: string; toolCallId: string; parameters: InferSchemaOutput<S>; status: "executing"; result: undefined; } interface RenderToolCompleteProps<S extends StandardSchemaV1> { name: string; toolCallId: string; parameters: InferSchemaOutput<S>; status: "complete"; result: string; } type RenderToolProps<S extends StandardSchemaV1> = RenderToolInProgressProps<S> | RenderToolExecutingProps<S> | RenderToolCompleteProps<S>; /** * Registers a wildcard (`"*"`) renderer for tool calls. * * The wildcard renderer is used as a fallback when no exact name-matched * renderer is registered for a tool call. * * @param config - Wildcard renderer configuration. * @param deps - Optional dependencies to refresh registration. * * @example * ```tsx * useRenderTool( * { * name: "*", * render: ({ name, status }) => ( * <div> * {status === "complete" ? "✓" : "⏳"} {name} * </div> * ), * }, * [], * ); * ``` */ declare function useRenderTool(config: { name: "*"; render: (props: any) => React.ReactElement; agentId?: string; }, deps?: ReadonlyArray<unknown>): void; /** * Registers a name-scoped renderer for tool calls. * * The provided `parameters` schema defines the typed shape of `props.parameters` * in `render` for `executing` and `complete` states. Accepts any Standard Schema V1 * compatible library (Zod, Valibot, ArkType, etc.). * * @typeParam S - Schema type describing tool call parameters. * @param config - Named renderer configuration. * @param deps - Optional dependencies to refresh registration. * * @example * ```tsx * useRenderTool( * { * name: "searchDocs", * parameters: z.object({ query: z.string() }), * render: ({ status, parameters, result }) => { * if (status === "inProgress") return <div>Preparing...</div>; * if (status === "executing") return <div>Searching {parameters.query}</div>; * return <div>{result}</div>; * }, * }, * [], * ); * ``` */ declare function useRenderTool<S extends StandardSchemaV1>(config: { name: string; parameters: S; render: (props: RenderToolProps<S>) => React.ReactElement; agentId?: string; }, deps?: ReadonlyArray<unknown>): void; //#endregion //#region src/v2/hooks/use-capabilities.d.ts /** * Returns the capabilities declared by the given agent (or the default agent). * Capabilities are populated from the runtime `/info` response at connection * time. The hook reads them synchronously from the agent instance — there is * no separate loading state, but the value will be `undefined` until the * runtime handshake completes. * * @param agentId - Optional agent ID. If omitted, uses the default agent. * @returns The agent's capabilities, or `undefined` if the agent doesn't * declare capabilities. */ declare function useCapabilities(agentId?: string): AgentCapabilities | undefined; //#endregion export { type AgentContextInput, CopilotChatConfigurationProvider, type CopilotChatConfigurationProviderProps, type CopilotChatConfigurationValue, CopilotChatDefaultLabels, type CopilotChatLabels, CopilotKitCoreReact, type CopilotKitCoreReactConfig, type Interrupt, type InterruptEvent, type InterruptHandlerProps, type InterruptRenderProps, type JsonSerializable, type ReactFrontendTool, type ReactHumanInTheLoop, type RenderToolCompleteProps, type RenderToolExecutingProps, type RenderToolInProgressProps, type RenderToolProps, type ResumeEntry, type ResumeStatus, type Thread, type UseAgentUpdate, type UseInterruptConfig, type UseThreadsInput, type UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useCopilotChatConfiguration, useFrontendTool, useHumanInTheLoop, useInterrupt, useRenderTool, useSuggestions, useThreads }; //# sourceMappingURL=headless.d.cts.map