UNPKG

react-use-chat

Version:

一个用于构建对话式引导流程的 React Hook,支持单选、多选和嵌套分支处理

69 lines 2.37 kB
/** * 对话系统类型定义 */ export interface DialogAnswer { answer_id: string; answer_text: string; next_node_id: string | null; plan_trigger: string | null; execution_order?: number; mutually_exclusive?: boolean; } export type AnswerType = "single_select" | "multi_select" | "auto_complete"; export interface DialogNode { node_id: string; question_text: string; answer_type: AnswerType; answers: DialogAnswer[]; default_next_node_id?: string | null; default_plan_trigger?: string | null; execute_by_config_order?: boolean; is_branch_end?: boolean; } export interface HistoryItem { nodeId: string; question: string; answer: string | null; answerId: string; multiSelected?: string[]; type?: 'message' | 'learning_plan'; planData?: string[]; } export interface SelectionBranch { answer_id: string; next_node_id: string; plan_trigger: string | null; } export interface UseDialogOptions { /** 初始节点 ID,如果不提供则使用数据源的第一个节点 */ initialNodeId?: string; /** 自定义节点查找函数 */ findNodeById?: (nodeId: string) => DialogNode | null; /** 自动完成节点的延迟时间(毫秒) */ autoCompleteDelay?: number; } export interface UseDialogReturn { /** 当前显示的对话节点 */ currentNode: DialogNode | null; /** 用户的对话历史记录 */ history: HistoryItem[]; /** 收集到的学习计划触发器列表 */ learningPlan: string[]; /** 在多选模式下,当前用户勾选的答案ID列表 */ selectedAnswers: string[]; /** 管理嵌套多选分支的栈 */ multiSelectBranchStack: SelectionBranch[][]; /** 对应 multiSelectBranchStack 中每个层级当前已处理到的分支索引的栈 */ currentBranchIndices: number[]; /** 在对话流程结束前,临时收集的所有计划触发器 */ pendingPlanTriggers: string[]; /** 处理单选答案选择 */ handleSelection: (answerId: string) => void; /** 处理多选答案勾选/取消勾选 */ handleMultiSelect: (answerId: string) => void; /** 用户在多选模式下确认选择后调用 */ confirmSelections: () => void; /** 重置整个对话状态到初始状态 */ resetDialog: () => void; } //# sourceMappingURL=types.d.ts.map