import { type Dispatch, type SetStateAction } from 'react'; import type { Message } from './message'; export type { Message }; /** * Use chat * @param {object} body - The body of the chat. * @param {function} onError - The function to call when an error occurs. * @param {function} onFinish - The function to call when the chat is finished. * @returns {UseChatReturn} The chat. */ export type UseChatProps = { body?: object; onError?: (e: unknown) => void; onFinish?: (message: Message) => void; /** 消息分页大小,不传时不分页 */ pageSize?: number; }; /** * Use chat return * @param {Message[]} messages - 消息列表 * @param {string} status - 状态 * @param {Error} error - 错误 * @param {function} append - 添加消息 * @param {function} regenerate - 重新生成最后一条回答 * @param {function} continueGenerate - 让AI继续说 * @param {function} stop - 停止对话 * @param {function} setMessages - 设置消息 * @param {function} input - 用户输入 * @param {function} setInput - 设置输入 * @param {function} handleSubmit - 提交用户输入,让AI回答 * @param {function} setSwipe - 设置Swipe * @param {function} editMessage - 编辑消息 * @param {function} deleteMessage - 删除消息 * @param {function} loadMoreMessage - 加载更多消息 * @param {string} messagesStatus - 消息状态 */ export type UseChatReturn = { messages: Message[]; status: 'uninitialized' | 'ready' | 'streaming' | 'error'; error?: unknown; /** 提交用户输入,让AI回答 */ append: (query: string) => Promise; /** 重新生成最后一条回答 */ regenerate: () => Promise; /** 让AI继续说 */ continueGenerate: () => Promise; stop: () => void; setMessages: Dispatch>; input: string; setInput: Dispatch>; handleSubmit: () => void; setSwipe: (messageId: string, swipeId: number) => Promise; editMessage: (messageId: string, content: string) => Promise; deleteMessage: (messageId: string) => Promise; loadMoreMessage: () => Promise; messagesStatus: 'all-loaded' | 'loading' | 'has-more' | 'error'; }; /** * Use chat common * @param {object} body - The body of the chat. * @returns {UseChatCommon} The chat. */ export type UseChatCommon = { body?: object; }; /** * Use chat * @param {UseChatProps} props - The props of the chat. * @param {object} props.body - The body of the chat. * @param {function} props.onError - The function to call when an error occurs. * @param {function} props.onFinish - The function to call when the chat is finished. * @param {number} props.pageSize - The page size of the chat. * @returns {UseChatReturn} The chat. * @example * const { messages, status, error, append, regenerate, continueGenerate, stop, setMessages, input, setInput, handleSubmit, setSwipe, editMessage, deleteMessage, loadMoreMessage, messagesStatus } = useChat({ * body: { * model: 'gpt-4o-mini', * }, * }); */ export declare const useChat: ({ body, onError, onFinish, pageSize, }: UseChatProps) => UseChatReturn;