/** * useAssistant Hook * * React hook for OpenAI Assistants API compatible interfaces. * * @module */ import type { Message } from 'ai.matey.react.core'; /** * Assistant message with additional metadata. */ export interface AssistantMessage extends Message { /** Thread ID */ threadId?: string; /** Run ID */ runId?: string; /** File annotations */ annotations?: Annotation[]; } /** * File annotation. */ export interface Annotation { /** Annotation type */ type: 'file_citation' | 'file_path'; /** Text content */ text: string; /** File citation details */ file_citation?: { file_id: string; quote?: string; }; /** File path details */ file_path?: { file_id: string; }; /** Start index */ start_index: number; /** End index */ end_index: number; } /** * Assistant run status. */ export type AssistantStatus = 'awaiting_message' | 'in_progress' | 'requires_action' | 'cancelling' | 'cancelled' | 'failed' | 'completed' | 'expired'; /** * Assistant hook options. */ export interface UseAssistantOptions { /** API endpoint */ api?: string; /** Assistant ID */ assistantId?: string; /** Thread ID for continuing a conversation */ threadId?: string; /** Request headers */ headers?: Record; /** Request body extras */ body?: Record; /** Called when status changes */ onStatus?: (status: AssistantStatus) => void; /** Called on error */ onError?: (error: Error) => void; } /** * Assistant hook return value. */ export interface UseAssistantReturn { /** Chat messages */ messages: AssistantMessage[]; /** Current input value */ input: string; /** Set input value */ setInput: (input: string) => void; /** Handle input change */ handleInputChange: (e: React.ChangeEvent) => void; /** Handle form submit */ handleSubmit: (e?: React.FormEvent) => void; /** Submit message programmatically */ append: (message: string | Message) => Promise; /** Thread ID */ threadId: string | undefined; /** Current status */ status: AssistantStatus; /** Stop the current run */ stop: () => void; /** Set messages */ setMessages: (messages: AssistantMessage[]) => void; /** Error if any */ error: Error | undefined; } /** * useAssistant - React hook for OpenAI Assistants API. * * Provides state management for conversations with OpenAI Assistants, * including thread management and run status tracking. * * @example * ```tsx * import { useAssistant } from 'ai.matey.react.hooks'; * * function AssistantChat() { * const { messages, input, handleInputChange, handleSubmit, status } = useAssistant({ * api: '/api/assistant', * assistantId: 'asst_xxx', * }); * * return ( *
* {messages.map((m) => ( *
{m.role}: {m.content}
* ))} *
* * *
*
* ); * } * ``` */ export declare function useAssistant(options?: UseAssistantOptions): UseAssistantReturn; //# sourceMappingURL=use-assistant.d.ts.map