/** * `useCopilotChat` is a lightweight React hook for headless chat interactions. * Perfect for controlling the prebuilt chat components programmatically. * * **Open Source Friendly** - Works without requiring a free public license key. * * * Get started with [useCopilotChatHeadless_c](https://docs.copilotkit.ai/reference/v1/hooks/useCopilotChatHeadless_c). * * * ## Use Cases * * - **Programmatic Messaging**: Send messages without displaying chat UI * - **Programmatic control**: Control prebuilt component programmatically * - **Background Operations**: Trigger AI interactions in the background * - **Fire-and-Forget**: Send messages without needing to read responses * * ## Usage * * ```tsx * import { TextMessage, MessageRole } from "@copilotkit/runtime-client-gql"; * * const { appendMessage } = useCopilotChat(); * * // Example usage without naming conflicts * const handleSendMessage = async (content: string) => { * await appendMessage( * new TextMessage({ * role: MessageRole.User, * content, * }) * ); * }; * ``` * * ## Return Values * The following properties are returned from the hook: * * * Array of messages in old non-AG-UI format, use for compatibility only * * * * Append message using old format, use `sendMessage` instead * * * * Regenerate the response for a specific message by ID * * * * Stop the current message generation process * * * * Clear all messages and reset chat state completely * * * * Whether the chat is currently generating a response * * * * Manually trigger chat completion for advanced usage * * * * Array of Model Context Protocol server configurations * * * * Update MCP server configurations for enhanced context * */ import { UseCopilotChatOptions, useCopilotChatInternal, UseCopilotChatReturn as UseCopilotChatReturnInternal, } from "./use-copilot-chat_internal"; // Create a type that excludes message-related properties from the internal type export type UseCopilotChatReturn = Omit< UseCopilotChatReturnInternal, | "messages" | "sendMessage" | "suggestions" | "setSuggestions" | "generateSuggestions" | "isLoadingSuggestions" | "resetSuggestions" | "interrupt" | "setMessages" | "deleteMessage" >; /** * A lightweight React hook for headless chat interactions. * Perfect for programmatic messaging, background operations, and custom UI implementations. * * **Open Source Friendly** - Works without requiring a `publicApiKey`. */ // TODO: Do we need this? If so, does it work properly? test. export function useCopilotChat( options: UseCopilotChatOptions = {}, ): UseCopilotChatReturn { const { visibleMessages, appendMessage, reloadMessages, stopGeneration, reset, isLoading, isAvailable, runChatCompletion, mcpServers, setMcpServers, } = useCopilotChatInternal(options); return { visibleMessages, appendMessage, reloadMessages, stopGeneration, reset, isLoading, isAvailable, runChatCompletion, mcpServers, setMcpServers, }; }