@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;" />
178 lines (175 loc) • 5.51 kB
TypeScript
import { SystemMessageFunction } from '../types/system-message.js';
import { Message as Message$1 } from '@copilotkit/runtime-client-gql';
import { Message } from '@copilotkit/shared';
import { AppendMessageOptions } from './use-chat.js';
import { S as SuggestionItem } from '../index-08c43df1.js';
import 'react';
import '../copilot-context-256f9020.js';
import '../types/frontend-action.js';
import './use-tree.js';
import '../types/document-pointer.js';
import '../types/chat-suggestion-configuration.js';
import '../types/coagent-action.js';
import '../types/coagent-state.js';
interface UseCopilotChatOptions {
/**
* A unique identifier for the chat. If not provided, a random one will be
* generated. When provided, the `useChat` hook with the same `id` will
* have shared states across components.
*/
id?: string;
/**
* HTTP headers to be sent with the API request.
*/
headers?: Record<string, string> | Headers;
/**
* Initial messages to populate the chat with.
*/
initialMessages?: Message[];
/**
* A function to generate the system message. Defaults to `defaultSystemMessage`.
*/
makeSystemMessage?: SystemMessageFunction;
}
interface MCPServerConfig {
endpoint: string;
apiKey?: string;
}
interface UseCopilotChatReturn {
/**
* @deprecated use `messages` instead, this is an old non ag-ui version of the messages
* Array of messages currently visible in the chat interface
*
* This is the visible messages, not the raw messages from the runtime client.
*/
visibleMessages: Message$1[];
/**
* The messages that are currently in the chat in AG-UI format.
*/
messages: Message[];
/** @deprecated use `sendMessage` instead */
appendMessage: (message: Message$1, options?: AppendMessageOptions) => Promise<void>;
/**
* Send a new message to the chat
*
* ```tsx
* await sendMessage({
* id: "123",
* role: "user",
* content: "Hello, process this request",
* });
* ```
*/
sendMessage: (message: Message, options?: AppendMessageOptions) => Promise<void>;
/**
* Replace all messages in the chat
*
* ```tsx
* setMessages([
* { id: "123", role: "user", content: "Hello, process this request" },
* { id: "456", role: "assistant", content: "Hello, I'm the assistant" },
* ]);
* ```
*
* **Deprecated** non-ag-ui version:
*
* ```tsx
* setMessages([
* new TextMessage({
* content: "Hello, process this request",
* role: gqlRole.User,
* }),
* new TextMessage({
* content: "Hello, I'm the assistant",
* role: gqlRole.Assistant,
* ]);
* ```
*
*/
setMessages: (messages: Message[] | Message$1[]) => void;
/**
* Remove a specific message by ID
*
* ```tsx
* deleteMessage("123");
* ```
*/
deleteMessage: (messageId: string) => void;
/**
* Regenerate the response for a specific message
*
* ```tsx
* reloadMessages("123");
* ```
*/
reloadMessages: (messageId: string) => Promise<void>;
/**
* Stop the current message generation
*
* ```tsx
* if (isLoading) {
* stopGeneration();
* }
* ```
*/
stopGeneration: () => void;
/**
* Clear all messages and reset chat state
*
* ```tsx
* reset();
* console.log(messages); // []
* ```
*/
reset: () => void;
/**
* Whether the chat is currently generating a response
*
* ```tsx
* if (isLoading) {
* console.log("Loading...");
* } else {
* console.log("Not loading");
* }
*/
isLoading: boolean;
/** Manually trigger chat completion (advanced usage) */
runChatCompletion: () => Promise<Message[]>;
/** MCP (Model Context Protocol) server configurations */
mcpServers: MCPServerConfig[];
/** Update MCP server configurations */
setMcpServers: (mcpServers: MCPServerConfig[]) => void;
/**
* Current suggestions array
* Use this to read the current suggestions or in conjunction with setSuggestions for manual control
*/
suggestions: SuggestionItem[];
/**
* Manually set suggestions
* Useful for manual mode or custom suggestion workflows
*/
setSuggestions: (suggestions: SuggestionItem[]) => void;
/**
* Trigger AI-powered suggestion generation
* Uses configurations from useCopilotChatSuggestions hooks
* Respects global debouncing - only one generation can run at a time
*
* ```tsx
* generateSuggestions();
* console.log(suggestions); // [suggestion1, suggestion2, suggestion3]
* ```
*/
generateSuggestions: () => Promise<void>;
/**
* Clear all current suggestions
* Also resets suggestion generation state
*/
resetSuggestions: () => void;
/** Whether suggestions are currently being generated */
isLoadingSuggestions: boolean;
/** Interrupt content for human-in-the-loop workflows */
interrupt: string | React.ReactElement | null;
}
declare function useCopilotChat(options?: UseCopilotChatOptions): UseCopilotChatReturn;
declare function defaultSystemMessage(contextString: string, additionalInstructions?: string): string;
export { MCPServerConfig, UseCopilotChatOptions, UseCopilotChatReturn, defaultSystemMessage, useCopilotChat };