import type { ToolApprovalStatus, ToolCallStatus, TaskProgressStepStatus } from './collaboration-blocks'; /** * Message Block Types - 基于 Cherry Studio 的 block-based 消息系统 * * 将消息内容拆分为多个块(blocks),支持: * - 主文本 (Markdown) * - 思考过程 (CoT/Reasoning) * - 工具调用 * - 图片/文件 * - 引用/搜索结果 * - 错误信息 */ export declare enum MessageBlockType { /** 未知类型,用于流式响应开始前 */ UNKNOWN = "unknown", /** 主要文本内容(Markdown) */ MAIN_TEXT = "main_text", /** 思考过程(Claude、DeepSeek R1、OpenAI o-系列等) */ THINKING = "thinking", /** 图片内容 */ IMAGE = "image", /** 代码块(独立可运行) */ CODE = "code", /** 工具调用及响应 */ TOOL = "tool", /** 工具审批卡片 */ TOOL_APPROVAL = "tool_approval", /** 任务进度卡片 */ TASK_PROGRESS = "task_progress", /** 文件内容 */ FILE = "file", /** 错误信息 */ ERROR = "error", /** 引用类型(Web 搜索、知识库等) */ CITATION = "citation" } export declare enum MessageBlockStatus { /** 等待处理 */ PENDING = "pending", /** 正在处理,等待接收 */ PROCESSING = "processing", /** 正在流式接收 */ STREAMING = "streaming", /** 处理成功 */ SUCCESS = "success", /** 处理错误 */ ERROR = "error", /** 处理暂停 */ PAUSED = "paused" } export interface BaseMessageBlock { /** 块 ID */ id: string; /** 所属消息 ID */ messageId: string; /** 块类型 */ type: MessageBlockType; /** 创建时间 */ createdAt: string; /** 更新时间 */ updatedAt?: string; /** 块状态 */ status: MessageBlockStatus; /** 使用的模型 */ model?: { id: string; name: string; provider: string; }; /** 通用元数据 */ metadata?: Record; /** 错误信息 */ error?: { code?: string; message: string; details?: unknown; }; } export interface PlaceholderMessageBlock extends BaseMessageBlock { type: MessageBlockType.UNKNOWN; } export interface MainTextMessageBlock extends BaseMessageBlock { type: MessageBlockType.MAIN_TEXT; /** Markdown 内容 */ content: string; /** 关联的知识库 ID */ knowledgeBaseIds?: string[]; /** 引用参考 */ citationReferences?: Array<{ citationBlockId?: string; url?: string; title?: string; }>; } export interface ThinkingMessageBlock extends BaseMessageBlock { type: MessageBlockType.THINKING; /** 思考内容 */ content: string; /** 思考耗时(毫秒) */ thinkingDuration?: number; } export interface CodeMessageBlock extends BaseMessageBlock { type: MessageBlockType.CODE; /** 代码内容 */ content: string; /** 代码语言 */ language: string; /** 是否可执行 */ executable?: boolean; /** 执行结果 */ executionResult?: { output?: string; error?: string; exitCode?: number; }; } export interface ImageMessageBlock extends BaseMessageBlock { type: MessageBlockType.IMAGE; /** 图片 URL */ url?: string; /** 本地文件路径 */ filePath?: string; /** 图片元数据 */ metadata?: BaseMessageBlock['metadata'] & { /** 生成提示词 */ prompt?: string; /** 负面提示词 */ negativePrompt?: string; /** 原始文件名 */ fileName?: string; /** 文件大小 */ fileSize?: number; /** 宽度 */ width?: number; /** 高度 */ height?: number; }; } export interface ToolMessageBlock extends BaseMessageBlock { type: MessageBlockType.TOOL; /** 协作链路中的工具调用 ID(与 CP0 ToolCallBlock 对齐) */ toolCallId?: string; /** 工具 ID */ toolId: string; /** 工具名称 */ toolName: string; /** 调用参数 */ arguments?: Record; /** 响应内容 */ content?: string | object; /** CP0 协作契约状态(waiting_approval / running / done ...) */ toolStatus?: ToolCallStatus; /** 执行结果(CP0 ToolCallBlock.result) */ result?: unknown; /** 错误信息(CP0 ToolCallBlock.error) */ toolError?: string; /** 耗时(ms) */ duration?: number; /** 工具元数据 */ metadata?: BaseMessageBlock['metadata'] & { /** 是否来自 MCP */ isMcp?: boolean; /** MCP 服务器名称 */ mcpServer?: string; }; } export interface ToolApprovalMessageBlock extends BaseMessageBlock { type: MessageBlockType.TOOL_APPROVAL; toolCallId: string; toolName: string; toolDescription: string; arguments: Record; risk: 'low' | 'medium' | 'high'; approvalStatus: ToolApprovalStatus; approvedBy?: string; approvedAt?: string; decisionBy?: string; decisionRole?: 'human' | 'secretary' | 'system'; onBehalfOf?: string; reason?: string; policyVersion?: string; inboxItemId?: string; } export interface TaskProgressMessageBlock extends BaseMessageBlock { type: MessageBlockType.TASK_PROGRESS; task: string; /** @deprecated Use `task`; retained only for older richContent payloads. */ taskId?: string; title: string; steps: Array<{ id: string; label: string; status: TaskProgressStepStatus; detail?: string; duration?: number; }>; currentStep: number; totalSteps: number; } export interface CitationMessageBlock extends BaseMessageBlock { type: MessageBlockType.CITATION; /** Web 搜索结果 */ webSearch?: { query: string; results: Array<{ title: string; url: string; snippet?: string; favicon?: string; }>; }; /** 知识库引用 */ knowledge?: Array<{ id: string; title: string; content: string; source?: string; }>; } export interface FileMessageBlock extends BaseMessageBlock { type: MessageBlockType.FILE; /** 文件名 */ fileName: string; /** 文件路径或 URL */ fileUrl: string; /** 文件大小 */ fileSize?: number; /** MIME 类型 */ mimeType?: string; } export interface ErrorMessageBlock extends BaseMessageBlock { type: MessageBlockType.ERROR; /** 错误消息 */ message: string; /** 是否可重试 */ retryable?: boolean; } export type MessageBlock = PlaceholderMessageBlock | MainTextMessageBlock | ThinkingMessageBlock | CodeMessageBlock | ImageMessageBlock | ToolMessageBlock | ToolApprovalMessageBlock | TaskProgressMessageBlock | FileMessageBlock | ErrorMessageBlock | CitationMessageBlock; /** * 消息的 richContent JSON 结构 * 存储在 Message.richContent 字段中 */ export interface MessageRichContent { /** 向后兼容:思考内容 */ thought?: string; /** 向后兼容:工具调用 */ toolInvocations?: Array<{ id: string; toolName: string; input: unknown; output?: unknown; error?: string; }>; /** 新的块系统 */ blocks?: MessageBlock[]; } /** * 创建块的工厂函数 */ export declare function createMessageBlock(type: T['type'], messageId: string, partial: Omit): T; /** * 判断块类型 */ export declare function isBlockType(block: MessageBlock, type: T['type']): block is T; /** * 从 richContent JSON 解析块 */ export declare function parseMessageBlocks(richContent: string | null | undefined): MessageBlock[]; /** * 序列化块到 richContent JSON */ export declare function serializeMessageBlocks(blocks: MessageBlock[]): string;