UNPKG

jamis

Version:

一种支持通过JSON配置方式生成页面的组件库

168 lines (167 loc) 4.94 kB
import type { ISendChatCompletionsAction, ReactPropsBase, RendererProps, SchemaBoolean, SchemaClassName, SchemaExpression } from 'jamis-core'; import type { ActionSchema, BaseSchema, SchemaCollection, SchemaObject } from '../types'; export interface IConversationItem { id: string; name: string; type?: ConversationType; deleted?: boolean; created: string | Date | number; className?: SchemaClassName; [key: string]: any; } /** * AI 对话类型 */ export type ConversationType = 'default' | 'deepseek' | 'yuanqi' | 'huanyuan' | 'chatgpt' | (string & {}); type ISendChatCompletionsActionArgs = Omit<ISendChatCompletionsAction['args'], 'onEventStream'>; /** * AI 对话类型配置 */ export interface ConversationTypeConfig extends ISendChatCompletionsActionArgs { type: ConversationType; answerFormat?: 'markdown' | 'html' | 'text' | (string & {}); /** 是否流式输出, 默认为true */ stream?: boolean; chatAdvices?: ConversationChatAdvices; } export interface ConversationListProps extends ReactPropsBase { conversationList: IConversationItem[]; renderConversationCreation: () => JSX.Element; renderConversationItem: (item: IConversationItem, index: number, onEdit: (item: IConversationItem) => void) => JSX.Element; onUpdate: (conversation: IConversationItem) => void; } interface IChatItemBase { /** * 一次聊天的唯一标识 */ id: string; query: string; answer: string; /** * 会话类型 */ type?: ConversationType; format?: 'html' | 'markdown' | 'text' | (string & {}); /** * 是否有错 */ error?: boolean | string; className?: SchemaClassName; } export type IChatItem<T extends Record<string, any> = Record<string, any>> = IChatItemBase & T; export interface AIChatBoxRendererProps extends RendererProps, AIChatBoxSchema { } export interface AIChatBoxSchema extends BaseSchema { type: 'ai-chatbox'; source?: SchemaExpression; items?: IConversationItem[]; /** * 会话类型配置 */ conversationTypes: ConversationTypeConfig[]; /** 简单模式, 只会一个会话, 不会显示会话列表 */ lite?: SchemaBoolean; /** 激活的会话id或者索引 */ activeConversationId?: SchemaExpression | number; /** * 创建会话时的默认名称 */ conversationNamePlaceholder?: string; /** * 元素`.ai-chat-content`的类名 */ contentClassName?: SchemaClassName; /** * 元素`.ai-chat-list`的类名 */ chatListClassName?: SchemaClassName; /** * 聊天项元素`.ai-chat-item`的类名 */ chatItemClassName?: SchemaClassName; /** * 元素`.ai-conversation-list`的类名 */ conversationListClassName?: SchemaClassName; /** * 会话项元素`.ai-conversation-item`的类名 */ conversationItemClassName?: SchemaClassName; /** * 空状态占位符 */ chatListPlaceholder?: SchemaExpression | SchemaCollection; /** * 提问相关配置 */ chatAskConfig?: { /** * 元素`.ai-chat-ask`的类名 */ className: SchemaClassName; schemaConfig?: SchemaCollection; /** * 头像的 schema 配置, 默认是一个 button */ avatarSchema?: Partial<ActionSchema>; }; /** * 聊天AI回复配置 */ chatAnswerConfig?: { /** * 元素`.ai-chat-answer`的类名 */ className?: SchemaClassName; /** * 默认是`markdown` */ format?: 'html' | 'text' | 'markdown'; /** * 自定义schema */ schemaConfig?: SchemaCollection; /** * AI 回复记录下的工具栏 */ toolbarConfig?: ChatAnswerToolbar[]; toolbarClassName?: SchemaClassName; /** * 头像的 schema 配置, 默认是一个 button */ avatarSchema?: Partial<ActionSchema>; }; /** * 聊天的建议问题配置 */ chatAdvices?: ConversationChatAdvices; /** * 聊天工具栏配置 */ chatToolbarSchema?: SchemaCollection; chatToolbarClassName?: SchemaClassName; } export type ChatAnswerToolbar = 'debug' | 'copy' | 'regenerate' | SchemaObject; export interface ConversationChatAdvices { title: SchemaExpression; questions: SchemaExpression[]; disabled?: SchemaBoolean; } export interface IOperationButtonsProps { chatItem: IChatItem; children: JSX.Element[]; } export interface IDebugButtonProps { isLastChat: boolean; chatItem: IChatItem; isFetching: boolean; } export interface IContentChatProps { chatList: IChatItem[]; conversation?: IConversationItem; /** * 单条聊天记录的操作按钮 */ renderChatOperateBtns: (item: IChatItem, index: number) => JSX.Element; } export {};