import React from "react"; /** 快捷键触发的列表项 */ export interface QuickListOption { id: string; label: string; description?: string; icon?: React.ReactNode; /** 分组名(用于聚合列表,子分组通过下划线分割) */ group?: string; [key: string]: any; } /** 快捷键配置 */ export interface QuickKeyConfig { /** 触发字符,如 '@', '#', '$' */ key: string; /** 选中后写入 MentionTag.type 的语义类型,不传时回退为 key */ mentionType?: string; /** @deprecated 请使用 mentionType。 */ tagType?: string; /** 列表标题 */ title?: string; /** 列表数据 */ options: QuickListOption[]; /** 自定义列表项渲染 */ renderItem?: (option: QuickListOption) => React.ReactNode; /** 选中回调 */ onSelect?: (option: QuickListOption) => void; } /** 输入框内的资源引用。SDK 只理解通用 Mention,业务语义可放入 data 或可选语义字段。 */ export interface MentionTag { id: string; label: string; /** Mention 类型,如 'knowledge', 'skill', 'plugin', 'agent' */ type: string; /** 资源 URI,如 skill://skillNo、kb://kb/knNo/dir/docs/2024 */ uri?: string; /** 业务资源 ID,如 skillNo、knowledgeNo */ targetId?: string; /** 展示名;不传时回退 label */ displayName?: string; /** 提交为纯文本/Markdown/XML 时使用的业务值,不传时回退 uri/targetId/label */ value?: string; /** 触发字符,如 '@', '#', '$',用于业务方区分来源 */ trigger?: string; color?: string; icon?: React.ReactNode; /** 业务扩展上下文,例如知识库目录 scope */ scope?: any; /** 原始数据 */ data?: any; } /** @deprecated 请使用 MentionTag。 */ export type InputTag = MentionTag; export interface InlineTagRenderInfo { onRemove: () => void; } export type XAdkSenderSubmitFormat = "text" | "structured" | "markdown" | "xml"; export type XAdkSenderSubmitPart = { type: "text"; text: string; } | { type: "mention"; mention: MentionTag; }; /** @deprecated 旧 tag part,仅用于兼容 defaultInputParts 历史传入。 */ export type XAdkSenderLegacyTagPart = { type: "tag"; tag: MentionTag; }; /** 输入框文本/Mention 有序片段,表示用户正在编辑的输入内容 */ export type XAdkSenderInputPart = XAdkSenderSubmitPart | XAdkSenderLegacyTagPart; export interface XAdkSenderFormatMentionContext { format: Exclude; index: number; } /** @deprecated 请使用 XAdkSenderFormatMentionContext。 */ export type XAdkSenderFormatTagContext = XAdkSenderFormatMentionContext; export interface XAdkSenderSubmitData { /** 根据 submitFormat 生成的最终内容,默认是纯文本 */ text: string; /** 去掉标签后的用户原始输入文本 */ rawText: string; /** 当前提交格式 */ format: XAdkSenderSubmitFormat; /** 文本与 Mention 的有序片段,inlineTags 模式下可还原资源引用在输入框中的位置 */ parts: XAdkSenderSubmitPart[]; files: ServerFile[]; /** 当前 Mention 列表 */ mentions?: MentionTag[]; /** @deprecated 请使用 mentions。 */ tags?: MentionTag[]; /** 业务方通过 transformSubmitData 派生出的自定义提交结构 */ payload?: TPayload; } export interface UploadFileResult { fileName?: string; fileId?: string | number; tempUrl?: string; url?: string; fileUrl?: string; fileType?: string; fileSize?: number; mimeType?: string; [key: string]: any; } export interface UploadSuccessResponse { data?: UploadFileResult | UploadFileResult[]; [key: string]: any; } interface uploadRequestProps { (options: { file: File; onProgress?: (e: { percent: number; }) => void; onSuccess?: (response: UploadFileResult | UploadFileResult[] | UploadSuccessResponse) => void; onError?: (error: Error) => void; }): Promise | void; } export type UploadRequestFn = uploadRequestProps; export interface ServerFile { fileName: string; fileId: string | number; tempUrl: string; type: string; size?: number; mimeType: string; raw?: UploadFileResult; } export interface LocalFile { id: string; uid: string; name: string; file: File; size: number; type: string; progress: number; status: "pending" | "uploading" | "success" | "error"; fileId?: string | number; tempUrl?: string; response?: any; errorMessage?: string; } export type FileValidator = (file: File, context: { files: LocalFile[]; }) => string | null; export interface ActionsComponents { SendButton: React.ComponentType; ClearButton: React.ComponentType; } export type SlotRenderFunction = (oriNode: React.ReactNode, info: { components: ActionsComponents; }) => React.ReactNode | false; export interface UploaderCoreProps { uploadRequest?: uploadRequestProps; maxFileSize?: number; allowedFileTypes?: string[]; maxFiles?: number; validators?: FileValidator[]; onFilesChange?: (files: LocalFile[]) => void; onUploadSuccess?: (file: LocalFile) => void; onUploadError?: (file: LocalFile, error: Error) => void; } export interface SenderUIProps { clearBtnShow?: boolean; /** * 是否启用 Sender 自身的拖拽上传。 * 拖拽产生的文件通过 onFileSelect 回调交给业务/外层处理; * 默认 false,由外层(如 DefaultLayout)管理拖拽时无需开启。 */ draggable?: boolean; /** * 拖拽文件回调:当 draggable 为 true 且用户向输入区拖拽文件时触发。 * 业务/外层在此回调中决定如何处理文件(通常调用 senderRef.addFiles 注入)。 */ onFileSelect?: (files: File[]) => void; loading?: boolean; disabled?: boolean; placeholder?: string; /** 受控:输入框的值 */ value?: string; /** 非受控:输入框默认值 */ defaultValue?: string; onClear?: () => void; onChange?: (value: string) => void; onSubmit?: (data: XAdkSenderSubmitData) => void; onStop?: () => void; /** 自定义发送按钮渲染 */ sendButtonRender?: (info: { loading: boolean; disabled: boolean; /** 当前是否可以发送(文本非空或有已上传的文件) */ canSend: boolean; onSend: () => void; onStop?: () => void; }) => React.ReactNode; /** 后缀内容,默认展示操作按钮,设为 false 时不显示 */ suffix?: React.ReactNode | false | SlotRenderFunction; /** 输入主体内部的头部内容 */ header?: React.ReactNode | false | SlotRenderFunction; /** 前缀内容 */ prefix?: React.ReactNode | false | SlotRenderFunction; /** 底部内容 */ footer?: React.ReactNode | false | SlotRenderFunction; /** 底部左侧拓展区域,不传时 footer 保持原有居中布局 */ footerLeft?: React.ReactNode | false | SlotRenderFunction; /** 快捷键配置列表 */ quickKeys?: QuickKeyConfig[]; /** 是否把 Mention 以内联 token 形式展示在输入区内;默认 false 保持历史 textarea 行为 */ inlineTags?: boolean; /** 自定义内联 Mention 渲染 */ renderMention?: (mention: MentionTag, info: InlineTagRenderInfo) => React.ReactNode; /** @deprecated 请使用 renderMention。 */ renderTag?: (mention: MentionTag, info: InlineTagRenderInfo) => React.ReactNode; /** 受控:Mention 列表 */ mentions?: MentionTag[]; /** @deprecated 请使用 mentions。 */ tags?: MentionTag[]; /** 非受控:默认 Mention 列表 */ defaultMentions?: MentionTag[]; /** @deprecated 请使用 defaultMentions。 */ defaultTags?: MentionTag[]; /** 非受控:默认输入内容片段,用于初始化内联 Mention 输入区 */ defaultInputParts?: XAdkSenderInputPart[]; /** Mention 变化回调 */ onMentionsChange?: (mentions: MentionTag[]) => void; /** @deprecated 请使用 onMentionsChange。 */ onTagsChange?: (mentions: MentionTag[]) => void; /** 快捷键触发回调(业务方可在此处理搜索等逻辑) */ onQuickKeyTrigger?: (key: string, keyword: string) => void; /** * 提交内容格式: * - text: 默认,输出文字 + Mention 文本(如 @生图技能) * - structured: 保留 parts/mentions/files 结构化数据,text 为 rawText * - markdown/xml: 输出对应标记文本 */ submitFormat?: XAdkSenderSubmitFormat; /** 自定义 Mention 在 text/markdown/xml 格式中的序列化结果 */ formatMention?: (mention: MentionTag, context: XAdkSenderFormatMentionContext) => string; /** @deprecated 请使用 formatMention。 */ formatTag?: (mention: MentionTag, context: XAdkSenderFormatMentionContext) => string; /** * 基于 SDK 标准提交结构派生业务 payload。 * SDK 不理解 knowledge/skill/agent 等业务字段,只负责把 payload 原样放入 onSubmit 数据中。 */ transformSubmitData?: (data: Omit) => unknown; } export type XAdkSenderProps = SenderUIProps & UploaderCoreProps; export interface XAdkSenderHandle { addFiles: (files: File[]) => void; /** 向当前光标位置插入一个内联 Mention;未启用 inlineTags 时会退化为追加 Mention。 */ insertMention: (mention: MentionTag) => void; /** @deprecated 请使用 insertMention。 */ insertTag: (mention: MentionTag) => void; /** 聚焦输入区 */ focus: () => void; } export {};