import { StreamMessageCallback } from '../types'; import { Message, Tool, ToolChoice, ToolSet } from 'ai'; import { OpenAssistantTool } from '@openassistant/utils'; /** * Props for configuring the AI Assistant and useAssistant hook. */ export type UseAssistantProps = { /** The server endpoint for handling chat requests (e.g. '/api/chat'). Required for server-side support. */ chatEndpoint?: string; /** The server endpoint for handling voice/audio requests. */ voiceEndpoint?: string; /** The display name of the assistant. */ name: string; /** * The AI model provider: * * - openai * - anthropic * - google * - deepseek * - xai * - ollama * */ modelProvider: string; /** The specific model identifier to use: * * - openai [models](https://sdk.vercel.ai/providers/ai-sdk-providers/openai#model-capabilities) * - anthropic [models](https://sdk.vercel.ai/providers/ai-sdk-providers/anthropic#model-capabilities) * - google [models](https://sdk.vercel.ai/providers/ai-sdk-providers/google#model-capabilities) * - deepseek [models](https://sdk.vercel.ai/providers/ai-sdk-providers/deepseek#model-capabilities) * - xai [models](https://sdk.vercel.ai/providers/ai-sdk-providers/xai#model-capabilities) * - ollama [models](https://ollama.com/models) */ model: string; /** The authentication key/token for the model provider's API. For example, [how to get the OpenAI API key](https://platform.openai.com/api-keys). */ apiKey: string; /** Optional API version to use. */ version?: string; /** Optional base URL for API requests. */ baseUrl?: string; /** Optional description of the assistant's purpose. */ description?: string; /** Controls randomness in responses (0-1). */ temperature?: number; /** Controls diversity of responses via nucleus sampling (0-1). */ topP?: number; /** System instructions/prompt for the assistant. */ instructions: string; /** The history of messages exchanged with the assistant. */ historyMessages?: Message[]; /** Custom tools the assistant can use. E.g. `{ localQuery: localQueryTool }` */ tools?: Record | Tool>; /** Controls how the assistant selects tools to use. */ toolChoice?: ToolChoice; /** Maximum number of steps/iterations in a conversation. */ maxSteps?: number; /** Whether to stream tool calls. */ toolCallStreaming?: boolean; /** Optional AbortController to cancel requests. */ abortController?: AbortController; /** Optional custom headers to include in API requests. */ headers?: Record; /** Optional raw mode for ollama. */ raw?: boolean; }; /** * Parameters for sending a text message to the assistant. * * @param message - The text message to send to the assistant. * @param streamMessageCallback - Callback function to handle streaming response chunks. * @param onToolFinished - Optional callback triggered when a tool call completes. */ export type SendTextMessageProps = { message: string; streamMessageCallback: StreamMessageCallback; onToolFinished?: (toolCallId: string, additionalData: unknown) => void; }; /** * Parameters for sending an image with optional text to the assistant. * * @param imageBase64String - Base64-encoded image data. * @param message - Optional text message to accompany the image. * @param streamMessageCallback - Callback function to handle streaming response chunks. */ export type SendImageMessageProps = { imageBase64String: string; message: string; streamMessageCallback: StreamMessageCallback; }; /** * A custom hook for managing an AI assistant. * This hook provides functionality to initialize, send messages to, and control an AI assistant. */ export declare function useAssistant(props: UseAssistantProps): { /** * Initializes the AI assistant with the configured settings. * Sets up the model, registers functions, and validates the API key. * @returns {Promise} */ initializeAssistant: () => Promise; /** * Sends a text message to the AI assistant and streams the response. * @param {SendTextMessageProps} props - Object containing the message and stream callback * @returns {Promise} */ sendTextMessage: ({ message, streamMessageCallback, onToolFinished, }: SendTextMessageProps) => Promise; /** * Sends an image along with text to the AI assistant and streams the response. * @param {SendImageMessageProps} props - Object containing the image data, message, and stream callback * @returns {Promise} */ sendImageMessage: ({ imageBase64String, message, streamMessageCallback, }: SendImageMessageProps) => Promise; /** * Converts an audio blob to text using the assistant's speech-to-text capabilities. * @param {Blob} audioBlob - The audio data to transcribe * @returns {Promise} The transcribed text */ audioToText: (audioBlob: Blob) => Promise; /** * Immediately stops the current chat processing and response generation. * @returns {void} */ stopChat: () => void; /** * Restarts the chat by stopping current processing and reinitializing the assistant. * @returns {Promise} */ restartChat: () => Promise; /** * Current status of the API key validation. * 'failed' - The API key is invalid. * 'success' - The API key is valid. * @type {'failed' | 'success'} */ apiKeyStatus: string; /** * Returns the components for the assistant. */ getComponents: () => import("../types").ToolCallComponents | undefined; /** * Sends a one-time prompt to the assistant and returns the response. The prompt and response will not be saved. * @param {Object} params - The text message to send to the assistant. * @returns {Promise} The response from the assistant. */ temporaryPrompt: ({ prompt, temperature, }: { prompt: string; temperature?: number | undefined; }) => Promise; };