@undefineds.co/models 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -515
- package/dist/core/file/file.schema.d.ts +1 -1
- package/dist/core/file/file.schema.js +1 -1
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +3 -3
- package/dist/core/schema.d.ts +1 -1
- package/dist/core/schema.js +1 -1
- package/dist/core/types/{collaboration-blocks.d.ts → collaboration-rich-content.d.ts} +7 -7
- package/dist/core/types/collaboration-rich-content.js +7 -0
- package/dist/core/types/message-rich-content.d.ts +121 -0
- package/dist/core/types/message-rich-content.js +85 -0
- package/dist/fixtures/contracts-chat-contact.d.ts +4 -4
- package/dist/fixtures/contracts-chat-contact.js +8 -4
- package/dist/governance/index.d.ts +1 -0
- package/dist/governance/index.js +1 -0
- package/dist/{sidecar/persistence-mapping.d.ts → governance/runtime-projections.d.ts} +3 -3
- package/dist/{sidecar/persistence-mapping.js → governance/runtime-projections.js} +1 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.js +11 -8
- package/dist/protocols/index.d.ts +1 -0
- package/dist/protocols/index.js +1 -0
- package/dist/{sidecar/sidecar-events.d.ts → protocols/runtime-events.d.ts} +11 -11
- package/dist/{sidecar/sidecar-events.js → protocols/runtime-events.js} +4 -21
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +1 -1
- package/dist/types/{collaboration-blocks.d.ts → collaboration-rich-content.d.ts} +7 -7
- package/dist/types/collaboration-rich-content.js +7 -0
- package/dist/types/message-rich-content.d.ts +121 -0
- package/dist/types/message-rich-content.js +85 -0
- package/package.json +9 -2
- package/dist/core/types/collaboration-blocks.js +0 -7
- package/dist/core/types/message-block.d.ts +0 -270
- package/dist/core/types/message-block.js +0 -125
- package/dist/sidecar/index.d.ts +0 -2
- package/dist/sidecar/index.js +0 -2
- package/dist/types/collaboration-blocks.js +0 -7
- package/dist/types/message-block.d.ts +0 -270
- package/dist/types/message-block.js +0 -125
- /package/dist/core/vocab/{sidecar.vocab.d.ts → governance.vocab.d.ts} +0 -0
- /package/dist/core/vocab/{sidecar.vocab.js → governance.vocab.js} +0 -0
- /package/dist/vocab/{sidecar.vocab.d.ts → governance.vocab.d.ts} +0 -0
- /package/dist/vocab/{sidecar.vocab.js → governance.vocab.js} +0 -0
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import type { ToolApprovalStatus, ToolCallStatus, TaskProgressStepStatus } from './collaboration-blocks.js';
|
|
2
|
-
/**
|
|
3
|
-
* Message Block Types - 基于 Cherry Studio 的 block-based 消息系统
|
|
4
|
-
*
|
|
5
|
-
* 将消息内容拆分为多个块(blocks),支持:
|
|
6
|
-
* - 主文本 (Markdown)
|
|
7
|
-
* - 思考过程 (CoT/Reasoning)
|
|
8
|
-
* - 工具调用
|
|
9
|
-
* - 图片/文件
|
|
10
|
-
* - 引用/搜索结果
|
|
11
|
-
* - 错误信息
|
|
12
|
-
*/
|
|
13
|
-
export declare enum MessageBlockType {
|
|
14
|
-
/** 未知类型,用于流式响应开始前 */
|
|
15
|
-
UNKNOWN = "unknown",
|
|
16
|
-
/** 主要文本内容(Markdown) */
|
|
17
|
-
MAIN_TEXT = "main_text",
|
|
18
|
-
/** 思考过程(Claude、DeepSeek R1、OpenAI o-系列等) */
|
|
19
|
-
THINKING = "thinking",
|
|
20
|
-
/** 图片内容 */
|
|
21
|
-
IMAGE = "image",
|
|
22
|
-
/** 代码块(独立可运行) */
|
|
23
|
-
CODE = "code",
|
|
24
|
-
/** 工具调用及响应 */
|
|
25
|
-
TOOL = "tool",
|
|
26
|
-
/** 工具审批卡片 */
|
|
27
|
-
TOOL_APPROVAL = "tool_approval",
|
|
28
|
-
/** 任务进度卡片 */
|
|
29
|
-
TASK_PROGRESS = "task_progress",
|
|
30
|
-
/** 文件内容 */
|
|
31
|
-
FILE = "file",
|
|
32
|
-
/** 错误信息 */
|
|
33
|
-
ERROR = "error",
|
|
34
|
-
/** 引用类型(Web 搜索、知识库等) */
|
|
35
|
-
CITATION = "citation"
|
|
36
|
-
}
|
|
37
|
-
export declare enum MessageBlockStatus {
|
|
38
|
-
/** 等待处理 */
|
|
39
|
-
PENDING = "pending",
|
|
40
|
-
/** 正在处理,等待接收 */
|
|
41
|
-
PROCESSING = "processing",
|
|
42
|
-
/** 正在流式接收 */
|
|
43
|
-
STREAMING = "streaming",
|
|
44
|
-
/** 处理成功 */
|
|
45
|
-
SUCCESS = "success",
|
|
46
|
-
/** 处理错误 */
|
|
47
|
-
ERROR = "error",
|
|
48
|
-
/** 处理暂停 */
|
|
49
|
-
PAUSED = "paused"
|
|
50
|
-
}
|
|
51
|
-
export interface BaseMessageBlock {
|
|
52
|
-
/** 块 ID */
|
|
53
|
-
id: string;
|
|
54
|
-
/** 所属消息 ID */
|
|
55
|
-
messageId: string;
|
|
56
|
-
/** 块类型 */
|
|
57
|
-
type: MessageBlockType;
|
|
58
|
-
/** 创建时间 */
|
|
59
|
-
createdAt: string;
|
|
60
|
-
/** 更新时间 */
|
|
61
|
-
updatedAt?: string;
|
|
62
|
-
/** 块状态 */
|
|
63
|
-
status: MessageBlockStatus;
|
|
64
|
-
/** 使用的模型 */
|
|
65
|
-
model?: {
|
|
66
|
-
id: string;
|
|
67
|
-
name: string;
|
|
68
|
-
provider: string;
|
|
69
|
-
};
|
|
70
|
-
/** 通用元数据 */
|
|
71
|
-
metadata?: Record<string, unknown>;
|
|
72
|
-
/** 错误信息 */
|
|
73
|
-
error?: {
|
|
74
|
-
code?: string;
|
|
75
|
-
message: string;
|
|
76
|
-
details?: unknown;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
export interface PlaceholderMessageBlock extends BaseMessageBlock {
|
|
80
|
-
type: MessageBlockType.UNKNOWN;
|
|
81
|
-
}
|
|
82
|
-
export interface MainTextMessageBlock extends BaseMessageBlock {
|
|
83
|
-
type: MessageBlockType.MAIN_TEXT;
|
|
84
|
-
/** Markdown 内容 */
|
|
85
|
-
content: string;
|
|
86
|
-
/** 关联的知识库 ID */
|
|
87
|
-
knowledgeBaseIds?: string[];
|
|
88
|
-
/** 引用参考 */
|
|
89
|
-
citationReferences?: Array<{
|
|
90
|
-
citationBlockId?: string;
|
|
91
|
-
url?: string;
|
|
92
|
-
title?: string;
|
|
93
|
-
}>;
|
|
94
|
-
}
|
|
95
|
-
export interface ThinkingMessageBlock extends BaseMessageBlock {
|
|
96
|
-
type: MessageBlockType.THINKING;
|
|
97
|
-
/** 思考内容 */
|
|
98
|
-
content: string;
|
|
99
|
-
/** 思考耗时(毫秒) */
|
|
100
|
-
thinkingDuration?: number;
|
|
101
|
-
}
|
|
102
|
-
export interface CodeMessageBlock extends BaseMessageBlock {
|
|
103
|
-
type: MessageBlockType.CODE;
|
|
104
|
-
/** 代码内容 */
|
|
105
|
-
content: string;
|
|
106
|
-
/** 代码语言 */
|
|
107
|
-
language: string;
|
|
108
|
-
/** 是否可执行 */
|
|
109
|
-
executable?: boolean;
|
|
110
|
-
/** 执行结果 */
|
|
111
|
-
executionResult?: {
|
|
112
|
-
output?: string;
|
|
113
|
-
error?: string;
|
|
114
|
-
exitCode?: number;
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
export interface ImageMessageBlock extends BaseMessageBlock {
|
|
118
|
-
type: MessageBlockType.IMAGE;
|
|
119
|
-
/** 图片 URL */
|
|
120
|
-
url?: string;
|
|
121
|
-
/** 本地文件路径 */
|
|
122
|
-
filePath?: string;
|
|
123
|
-
/** 图片元数据 */
|
|
124
|
-
metadata?: BaseMessageBlock['metadata'] & {
|
|
125
|
-
/** 生成提示词 */
|
|
126
|
-
prompt?: string;
|
|
127
|
-
/** 负面提示词 */
|
|
128
|
-
negativePrompt?: string;
|
|
129
|
-
/** 原始文件名 */
|
|
130
|
-
fileName?: string;
|
|
131
|
-
/** 文件大小 */
|
|
132
|
-
fileSize?: number;
|
|
133
|
-
/** 宽度 */
|
|
134
|
-
width?: number;
|
|
135
|
-
/** 高度 */
|
|
136
|
-
height?: number;
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
export interface ToolMessageBlock extends BaseMessageBlock {
|
|
140
|
-
type: MessageBlockType.TOOL;
|
|
141
|
-
/** 协作链路中的工具调用 ID(与 CP0 ToolCallBlock 对齐) */
|
|
142
|
-
toolCallId?: string;
|
|
143
|
-
/** 工具 ID */
|
|
144
|
-
toolId: string;
|
|
145
|
-
/** 工具名称 */
|
|
146
|
-
toolName: string;
|
|
147
|
-
/** 调用参数 */
|
|
148
|
-
arguments?: Record<string, unknown>;
|
|
149
|
-
/** 响应内容 */
|
|
150
|
-
content?: string | object;
|
|
151
|
-
/** CP0 协作契约状态(waiting_approval / running / done ...) */
|
|
152
|
-
toolStatus?: ToolCallStatus;
|
|
153
|
-
/** 执行结果(CP0 ToolCallBlock.result) */
|
|
154
|
-
result?: unknown;
|
|
155
|
-
/** 错误信息(CP0 ToolCallBlock.error) */
|
|
156
|
-
toolError?: string;
|
|
157
|
-
/** 耗时(ms) */
|
|
158
|
-
duration?: number;
|
|
159
|
-
/** 工具元数据 */
|
|
160
|
-
metadata?: BaseMessageBlock['metadata'] & {
|
|
161
|
-
/** 是否来自 MCP */
|
|
162
|
-
isMcp?: boolean;
|
|
163
|
-
/** MCP 服务器名称 */
|
|
164
|
-
mcpServer?: string;
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
export interface ToolApprovalMessageBlock extends BaseMessageBlock {
|
|
168
|
-
type: MessageBlockType.TOOL_APPROVAL;
|
|
169
|
-
toolCallId: string;
|
|
170
|
-
toolName: string;
|
|
171
|
-
toolDescription: string;
|
|
172
|
-
arguments: Record<string, unknown>;
|
|
173
|
-
risk: 'low' | 'medium' | 'high';
|
|
174
|
-
approvalStatus: ToolApprovalStatus;
|
|
175
|
-
approvedBy?: string;
|
|
176
|
-
approvedAt?: string;
|
|
177
|
-
decisionBy?: string;
|
|
178
|
-
decisionRole?: 'human' | 'secretary' | 'system';
|
|
179
|
-
onBehalfOf?: string;
|
|
180
|
-
reason?: string;
|
|
181
|
-
policyVersion?: string;
|
|
182
|
-
inboxItemId?: string;
|
|
183
|
-
}
|
|
184
|
-
export interface TaskProgressMessageBlock extends BaseMessageBlock {
|
|
185
|
-
type: MessageBlockType.TASK_PROGRESS;
|
|
186
|
-
taskId: string;
|
|
187
|
-
title: string;
|
|
188
|
-
steps: Array<{
|
|
189
|
-
id: string;
|
|
190
|
-
label: string;
|
|
191
|
-
status: TaskProgressStepStatus;
|
|
192
|
-
detail?: string;
|
|
193
|
-
duration?: number;
|
|
194
|
-
}>;
|
|
195
|
-
currentStep: number;
|
|
196
|
-
totalSteps: number;
|
|
197
|
-
}
|
|
198
|
-
export interface CitationMessageBlock extends BaseMessageBlock {
|
|
199
|
-
type: MessageBlockType.CITATION;
|
|
200
|
-
/** Web 搜索结果 */
|
|
201
|
-
webSearch?: {
|
|
202
|
-
query: string;
|
|
203
|
-
results: Array<{
|
|
204
|
-
title: string;
|
|
205
|
-
url: string;
|
|
206
|
-
snippet?: string;
|
|
207
|
-
favicon?: string;
|
|
208
|
-
}>;
|
|
209
|
-
};
|
|
210
|
-
/** 知识库引用 */
|
|
211
|
-
knowledge?: Array<{
|
|
212
|
-
id: string;
|
|
213
|
-
title: string;
|
|
214
|
-
content: string;
|
|
215
|
-
source?: string;
|
|
216
|
-
}>;
|
|
217
|
-
}
|
|
218
|
-
export interface FileMessageBlock extends BaseMessageBlock {
|
|
219
|
-
type: MessageBlockType.FILE;
|
|
220
|
-
/** 文件名 */
|
|
221
|
-
fileName: string;
|
|
222
|
-
/** 文件路径或 URL */
|
|
223
|
-
fileUrl: string;
|
|
224
|
-
/** 文件大小 */
|
|
225
|
-
fileSize?: number;
|
|
226
|
-
/** MIME 类型 */
|
|
227
|
-
mimeType?: string;
|
|
228
|
-
}
|
|
229
|
-
export interface ErrorMessageBlock extends BaseMessageBlock {
|
|
230
|
-
type: MessageBlockType.ERROR;
|
|
231
|
-
/** 错误消息 */
|
|
232
|
-
message: string;
|
|
233
|
-
/** 是否可重试 */
|
|
234
|
-
retryable?: boolean;
|
|
235
|
-
}
|
|
236
|
-
export type MessageBlock = PlaceholderMessageBlock | MainTextMessageBlock | ThinkingMessageBlock | CodeMessageBlock | ImageMessageBlock | ToolMessageBlock | ToolApprovalMessageBlock | TaskProgressMessageBlock | FileMessageBlock | ErrorMessageBlock | CitationMessageBlock;
|
|
237
|
-
/**
|
|
238
|
-
* 消息的 richContent JSON 结构
|
|
239
|
-
* 存储在 Message.richContent 字段中
|
|
240
|
-
*/
|
|
241
|
-
export interface MessageRichContent {
|
|
242
|
-
/** 向后兼容:思考内容 */
|
|
243
|
-
thought?: string;
|
|
244
|
-
/** 向后兼容:工具调用 */
|
|
245
|
-
toolInvocations?: Array<{
|
|
246
|
-
id: string;
|
|
247
|
-
toolName: string;
|
|
248
|
-
input: unknown;
|
|
249
|
-
output?: unknown;
|
|
250
|
-
error?: string;
|
|
251
|
-
}>;
|
|
252
|
-
/** 新的块系统 */
|
|
253
|
-
blocks?: MessageBlock[];
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* 创建块的工厂函数
|
|
257
|
-
*/
|
|
258
|
-
export declare function createMessageBlock<T extends MessageBlock>(type: T['type'], messageId: string, partial: Omit<T, 'id' | 'messageId' | 'type' | 'createdAt' | 'status'>): T;
|
|
259
|
-
/**
|
|
260
|
-
* 判断块类型
|
|
261
|
-
*/
|
|
262
|
-
export declare function isBlockType<T extends MessageBlock>(block: MessageBlock, type: T['type']): block is T;
|
|
263
|
-
/**
|
|
264
|
-
* 从 richContent JSON 解析块
|
|
265
|
-
*/
|
|
266
|
-
export declare function parseMessageBlocks(richContent: string | null | undefined): MessageBlock[];
|
|
267
|
-
/**
|
|
268
|
-
* 序列化块到 richContent JSON
|
|
269
|
-
*/
|
|
270
|
-
export declare function serializeMessageBlocks(blocks: MessageBlock[]): string;
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Message Block Types - 基于 Cherry Studio 的 block-based 消息系统
|
|
3
|
-
*
|
|
4
|
-
* 将消息内容拆分为多个块(blocks),支持:
|
|
5
|
-
* - 主文本 (Markdown)
|
|
6
|
-
* - 思考过程 (CoT/Reasoning)
|
|
7
|
-
* - 工具调用
|
|
8
|
-
* - 图片/文件
|
|
9
|
-
* - 引用/搜索结果
|
|
10
|
-
* - 错误信息
|
|
11
|
-
*/
|
|
12
|
-
// 块类型枚举
|
|
13
|
-
export var MessageBlockType;
|
|
14
|
-
(function (MessageBlockType) {
|
|
15
|
-
/** 未知类型,用于流式响应开始前 */
|
|
16
|
-
MessageBlockType["UNKNOWN"] = "unknown";
|
|
17
|
-
/** 主要文本内容(Markdown) */
|
|
18
|
-
MessageBlockType["MAIN_TEXT"] = "main_text";
|
|
19
|
-
/** 思考过程(Claude、DeepSeek R1、OpenAI o-系列等) */
|
|
20
|
-
MessageBlockType["THINKING"] = "thinking";
|
|
21
|
-
/** 图片内容 */
|
|
22
|
-
MessageBlockType["IMAGE"] = "image";
|
|
23
|
-
/** 代码块(独立可运行) */
|
|
24
|
-
MessageBlockType["CODE"] = "code";
|
|
25
|
-
/** 工具调用及响应 */
|
|
26
|
-
MessageBlockType["TOOL"] = "tool";
|
|
27
|
-
/** 工具审批卡片 */
|
|
28
|
-
MessageBlockType["TOOL_APPROVAL"] = "tool_approval";
|
|
29
|
-
/** 任务进度卡片 */
|
|
30
|
-
MessageBlockType["TASK_PROGRESS"] = "task_progress";
|
|
31
|
-
/** 文件内容 */
|
|
32
|
-
MessageBlockType["FILE"] = "file";
|
|
33
|
-
/** 错误信息 */
|
|
34
|
-
MessageBlockType["ERROR"] = "error";
|
|
35
|
-
/** 引用类型(Web 搜索、知识库等) */
|
|
36
|
-
MessageBlockType["CITATION"] = "citation";
|
|
37
|
-
})(MessageBlockType || (MessageBlockType = {}));
|
|
38
|
-
// 块状态定义
|
|
39
|
-
export var MessageBlockStatus;
|
|
40
|
-
(function (MessageBlockStatus) {
|
|
41
|
-
/** 等待处理 */
|
|
42
|
-
MessageBlockStatus["PENDING"] = "pending";
|
|
43
|
-
/** 正在处理,等待接收 */
|
|
44
|
-
MessageBlockStatus["PROCESSING"] = "processing";
|
|
45
|
-
/** 正在流式接收 */
|
|
46
|
-
MessageBlockStatus["STREAMING"] = "streaming";
|
|
47
|
-
/** 处理成功 */
|
|
48
|
-
MessageBlockStatus["SUCCESS"] = "success";
|
|
49
|
-
/** 处理错误 */
|
|
50
|
-
MessageBlockStatus["ERROR"] = "error";
|
|
51
|
-
/** 处理暂停 */
|
|
52
|
-
MessageBlockStatus["PAUSED"] = "paused";
|
|
53
|
-
})(MessageBlockStatus || (MessageBlockStatus = {}));
|
|
54
|
-
/**
|
|
55
|
-
* 创建块的工厂函数
|
|
56
|
-
*/
|
|
57
|
-
export function createMessageBlock(type, messageId, partial) {
|
|
58
|
-
const id = `block-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
59
|
-
return {
|
|
60
|
-
id,
|
|
61
|
-
messageId,
|
|
62
|
-
type,
|
|
63
|
-
createdAt: new Date().toISOString(),
|
|
64
|
-
status: MessageBlockStatus.PENDING,
|
|
65
|
-
...partial,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* 判断块类型
|
|
70
|
-
*/
|
|
71
|
-
export function isBlockType(block, type) {
|
|
72
|
-
return block.type === type;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* 从 richContent JSON 解析块
|
|
76
|
-
*/
|
|
77
|
-
export function parseMessageBlocks(richContent) {
|
|
78
|
-
if (!richContent)
|
|
79
|
-
return [];
|
|
80
|
-
try {
|
|
81
|
-
const parsed = JSON.parse(richContent);
|
|
82
|
-
// 如果有新的块系统,直接返回
|
|
83
|
-
if (parsed.blocks && parsed.blocks.length > 0) {
|
|
84
|
-
return parsed.blocks;
|
|
85
|
-
}
|
|
86
|
-
// 向后兼容:转换旧格式
|
|
87
|
-
const blocks = [];
|
|
88
|
-
if (parsed.thought) {
|
|
89
|
-
blocks.push({
|
|
90
|
-
id: 'legacy-thought',
|
|
91
|
-
messageId: '',
|
|
92
|
-
type: MessageBlockType.THINKING,
|
|
93
|
-
content: parsed.thought,
|
|
94
|
-
createdAt: new Date().toISOString(),
|
|
95
|
-
status: MessageBlockStatus.SUCCESS,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
if (parsed.toolInvocations) {
|
|
99
|
-
parsed.toolInvocations.forEach((ti, index) => {
|
|
100
|
-
blocks.push({
|
|
101
|
-
id: `legacy-tool-${index}`,
|
|
102
|
-
messageId: '',
|
|
103
|
-
type: MessageBlockType.TOOL,
|
|
104
|
-
toolId: ti.id,
|
|
105
|
-
toolName: ti.toolName,
|
|
106
|
-
arguments: ti.input,
|
|
107
|
-
content: ti.output ?? ti.error,
|
|
108
|
-
createdAt: new Date().toISOString(),
|
|
109
|
-
status: ti.error ? MessageBlockStatus.ERROR : MessageBlockStatus.SUCCESS,
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
return blocks;
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
return [];
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* 序列化块到 richContent JSON
|
|
121
|
-
*/
|
|
122
|
-
export function serializeMessageBlocks(blocks) {
|
|
123
|
-
const content = { blocks };
|
|
124
|
-
return JSON.stringify(content);
|
|
125
|
-
}
|
package/dist/sidecar/index.d.ts
DELETED
package/dist/sidecar/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wave A CP0: collaboration-related richContent block contracts.
|
|
3
|
-
*
|
|
4
|
-
* These are minimal JSON shapes stored in MessageRow.richContent and consumed by downstream UIs.
|
|
5
|
-
* They intentionally do NOT include UI block runtime fields (id/createdAt/status, etc.).
|
|
6
|
-
*/
|
|
7
|
-
export {};
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import type { ToolApprovalStatus, ToolCallStatus, TaskProgressStepStatus } from './collaboration-blocks.js';
|
|
2
|
-
/**
|
|
3
|
-
* Message Block Types - 基于 Cherry Studio 的 block-based 消息系统
|
|
4
|
-
*
|
|
5
|
-
* 将消息内容拆分为多个块(blocks),支持:
|
|
6
|
-
* - 主文本 (Markdown)
|
|
7
|
-
* - 思考过程 (CoT/Reasoning)
|
|
8
|
-
* - 工具调用
|
|
9
|
-
* - 图片/文件
|
|
10
|
-
* - 引用/搜索结果
|
|
11
|
-
* - 错误信息
|
|
12
|
-
*/
|
|
13
|
-
export declare enum MessageBlockType {
|
|
14
|
-
/** 未知类型,用于流式响应开始前 */
|
|
15
|
-
UNKNOWN = "unknown",
|
|
16
|
-
/** 主要文本内容(Markdown) */
|
|
17
|
-
MAIN_TEXT = "main_text",
|
|
18
|
-
/** 思考过程(Claude、DeepSeek R1、OpenAI o-系列等) */
|
|
19
|
-
THINKING = "thinking",
|
|
20
|
-
/** 图片内容 */
|
|
21
|
-
IMAGE = "image",
|
|
22
|
-
/** 代码块(独立可运行) */
|
|
23
|
-
CODE = "code",
|
|
24
|
-
/** 工具调用及响应 */
|
|
25
|
-
TOOL = "tool",
|
|
26
|
-
/** 工具审批卡片 */
|
|
27
|
-
TOOL_APPROVAL = "tool_approval",
|
|
28
|
-
/** 任务进度卡片 */
|
|
29
|
-
TASK_PROGRESS = "task_progress",
|
|
30
|
-
/** 文件内容 */
|
|
31
|
-
FILE = "file",
|
|
32
|
-
/** 错误信息 */
|
|
33
|
-
ERROR = "error",
|
|
34
|
-
/** 引用类型(Web 搜索、知识库等) */
|
|
35
|
-
CITATION = "citation"
|
|
36
|
-
}
|
|
37
|
-
export declare enum MessageBlockStatus {
|
|
38
|
-
/** 等待处理 */
|
|
39
|
-
PENDING = "pending",
|
|
40
|
-
/** 正在处理,等待接收 */
|
|
41
|
-
PROCESSING = "processing",
|
|
42
|
-
/** 正在流式接收 */
|
|
43
|
-
STREAMING = "streaming",
|
|
44
|
-
/** 处理成功 */
|
|
45
|
-
SUCCESS = "success",
|
|
46
|
-
/** 处理错误 */
|
|
47
|
-
ERROR = "error",
|
|
48
|
-
/** 处理暂停 */
|
|
49
|
-
PAUSED = "paused"
|
|
50
|
-
}
|
|
51
|
-
export interface BaseMessageBlock {
|
|
52
|
-
/** 块 ID */
|
|
53
|
-
id: string;
|
|
54
|
-
/** 所属消息 ID */
|
|
55
|
-
messageId: string;
|
|
56
|
-
/** 块类型 */
|
|
57
|
-
type: MessageBlockType;
|
|
58
|
-
/** 创建时间 */
|
|
59
|
-
createdAt: string;
|
|
60
|
-
/** 更新时间 */
|
|
61
|
-
updatedAt?: string;
|
|
62
|
-
/** 块状态 */
|
|
63
|
-
status: MessageBlockStatus;
|
|
64
|
-
/** 使用的模型 */
|
|
65
|
-
model?: {
|
|
66
|
-
id: string;
|
|
67
|
-
name: string;
|
|
68
|
-
provider: string;
|
|
69
|
-
};
|
|
70
|
-
/** 通用元数据 */
|
|
71
|
-
metadata?: Record<string, unknown>;
|
|
72
|
-
/** 错误信息 */
|
|
73
|
-
error?: {
|
|
74
|
-
code?: string;
|
|
75
|
-
message: string;
|
|
76
|
-
details?: unknown;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
export interface PlaceholderMessageBlock extends BaseMessageBlock {
|
|
80
|
-
type: MessageBlockType.UNKNOWN;
|
|
81
|
-
}
|
|
82
|
-
export interface MainTextMessageBlock extends BaseMessageBlock {
|
|
83
|
-
type: MessageBlockType.MAIN_TEXT;
|
|
84
|
-
/** Markdown 内容 */
|
|
85
|
-
content: string;
|
|
86
|
-
/** 关联的知识库 ID */
|
|
87
|
-
knowledgeBaseIds?: string[];
|
|
88
|
-
/** 引用参考 */
|
|
89
|
-
citationReferences?: Array<{
|
|
90
|
-
citationBlockId?: string;
|
|
91
|
-
url?: string;
|
|
92
|
-
title?: string;
|
|
93
|
-
}>;
|
|
94
|
-
}
|
|
95
|
-
export interface ThinkingMessageBlock extends BaseMessageBlock {
|
|
96
|
-
type: MessageBlockType.THINKING;
|
|
97
|
-
/** 思考内容 */
|
|
98
|
-
content: string;
|
|
99
|
-
/** 思考耗时(毫秒) */
|
|
100
|
-
thinkingDuration?: number;
|
|
101
|
-
}
|
|
102
|
-
export interface CodeMessageBlock extends BaseMessageBlock {
|
|
103
|
-
type: MessageBlockType.CODE;
|
|
104
|
-
/** 代码内容 */
|
|
105
|
-
content: string;
|
|
106
|
-
/** 代码语言 */
|
|
107
|
-
language: string;
|
|
108
|
-
/** 是否可执行 */
|
|
109
|
-
executable?: boolean;
|
|
110
|
-
/** 执行结果 */
|
|
111
|
-
executionResult?: {
|
|
112
|
-
output?: string;
|
|
113
|
-
error?: string;
|
|
114
|
-
exitCode?: number;
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
export interface ImageMessageBlock extends BaseMessageBlock {
|
|
118
|
-
type: MessageBlockType.IMAGE;
|
|
119
|
-
/** 图片 URL */
|
|
120
|
-
url?: string;
|
|
121
|
-
/** 本地文件路径 */
|
|
122
|
-
filePath?: string;
|
|
123
|
-
/** 图片元数据 */
|
|
124
|
-
metadata?: BaseMessageBlock['metadata'] & {
|
|
125
|
-
/** 生成提示词 */
|
|
126
|
-
prompt?: string;
|
|
127
|
-
/** 负面提示词 */
|
|
128
|
-
negativePrompt?: string;
|
|
129
|
-
/** 原始文件名 */
|
|
130
|
-
fileName?: string;
|
|
131
|
-
/** 文件大小 */
|
|
132
|
-
fileSize?: number;
|
|
133
|
-
/** 宽度 */
|
|
134
|
-
width?: number;
|
|
135
|
-
/** 高度 */
|
|
136
|
-
height?: number;
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
export interface ToolMessageBlock extends BaseMessageBlock {
|
|
140
|
-
type: MessageBlockType.TOOL;
|
|
141
|
-
/** 协作链路中的工具调用 ID(与 CP0 ToolCallBlock 对齐) */
|
|
142
|
-
toolCallId?: string;
|
|
143
|
-
/** 工具 ID */
|
|
144
|
-
toolId: string;
|
|
145
|
-
/** 工具名称 */
|
|
146
|
-
toolName: string;
|
|
147
|
-
/** 调用参数 */
|
|
148
|
-
arguments?: Record<string, unknown>;
|
|
149
|
-
/** 响应内容 */
|
|
150
|
-
content?: string | object;
|
|
151
|
-
/** CP0 协作契约状态(waiting_approval / running / done ...) */
|
|
152
|
-
toolStatus?: ToolCallStatus;
|
|
153
|
-
/** 执行结果(CP0 ToolCallBlock.result) */
|
|
154
|
-
result?: unknown;
|
|
155
|
-
/** 错误信息(CP0 ToolCallBlock.error) */
|
|
156
|
-
toolError?: string;
|
|
157
|
-
/** 耗时(ms) */
|
|
158
|
-
duration?: number;
|
|
159
|
-
/** 工具元数据 */
|
|
160
|
-
metadata?: BaseMessageBlock['metadata'] & {
|
|
161
|
-
/** 是否来自 MCP */
|
|
162
|
-
isMcp?: boolean;
|
|
163
|
-
/** MCP 服务器名称 */
|
|
164
|
-
mcpServer?: string;
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
export interface ToolApprovalMessageBlock extends BaseMessageBlock {
|
|
168
|
-
type: MessageBlockType.TOOL_APPROVAL;
|
|
169
|
-
toolCallId: string;
|
|
170
|
-
toolName: string;
|
|
171
|
-
toolDescription: string;
|
|
172
|
-
arguments: Record<string, unknown>;
|
|
173
|
-
risk: 'low' | 'medium' | 'high';
|
|
174
|
-
approvalStatus: ToolApprovalStatus;
|
|
175
|
-
approvedBy?: string;
|
|
176
|
-
approvedAt?: string;
|
|
177
|
-
decisionBy?: string;
|
|
178
|
-
decisionRole?: 'human' | 'secretary' | 'system';
|
|
179
|
-
onBehalfOf?: string;
|
|
180
|
-
reason?: string;
|
|
181
|
-
policyVersion?: string;
|
|
182
|
-
inboxItemId?: string;
|
|
183
|
-
}
|
|
184
|
-
export interface TaskProgressMessageBlock extends BaseMessageBlock {
|
|
185
|
-
type: MessageBlockType.TASK_PROGRESS;
|
|
186
|
-
taskId: string;
|
|
187
|
-
title: string;
|
|
188
|
-
steps: Array<{
|
|
189
|
-
id: string;
|
|
190
|
-
label: string;
|
|
191
|
-
status: TaskProgressStepStatus;
|
|
192
|
-
detail?: string;
|
|
193
|
-
duration?: number;
|
|
194
|
-
}>;
|
|
195
|
-
currentStep: number;
|
|
196
|
-
totalSteps: number;
|
|
197
|
-
}
|
|
198
|
-
export interface CitationMessageBlock extends BaseMessageBlock {
|
|
199
|
-
type: MessageBlockType.CITATION;
|
|
200
|
-
/** Web 搜索结果 */
|
|
201
|
-
webSearch?: {
|
|
202
|
-
query: string;
|
|
203
|
-
results: Array<{
|
|
204
|
-
title: string;
|
|
205
|
-
url: string;
|
|
206
|
-
snippet?: string;
|
|
207
|
-
favicon?: string;
|
|
208
|
-
}>;
|
|
209
|
-
};
|
|
210
|
-
/** 知识库引用 */
|
|
211
|
-
knowledge?: Array<{
|
|
212
|
-
id: string;
|
|
213
|
-
title: string;
|
|
214
|
-
content: string;
|
|
215
|
-
source?: string;
|
|
216
|
-
}>;
|
|
217
|
-
}
|
|
218
|
-
export interface FileMessageBlock extends BaseMessageBlock {
|
|
219
|
-
type: MessageBlockType.FILE;
|
|
220
|
-
/** 文件名 */
|
|
221
|
-
fileName: string;
|
|
222
|
-
/** 文件路径或 URL */
|
|
223
|
-
fileUrl: string;
|
|
224
|
-
/** 文件大小 */
|
|
225
|
-
fileSize?: number;
|
|
226
|
-
/** MIME 类型 */
|
|
227
|
-
mimeType?: string;
|
|
228
|
-
}
|
|
229
|
-
export interface ErrorMessageBlock extends BaseMessageBlock {
|
|
230
|
-
type: MessageBlockType.ERROR;
|
|
231
|
-
/** 错误消息 */
|
|
232
|
-
message: string;
|
|
233
|
-
/** 是否可重试 */
|
|
234
|
-
retryable?: boolean;
|
|
235
|
-
}
|
|
236
|
-
export type MessageBlock = PlaceholderMessageBlock | MainTextMessageBlock | ThinkingMessageBlock | CodeMessageBlock | ImageMessageBlock | ToolMessageBlock | ToolApprovalMessageBlock | TaskProgressMessageBlock | FileMessageBlock | ErrorMessageBlock | CitationMessageBlock;
|
|
237
|
-
/**
|
|
238
|
-
* 消息的 richContent JSON 结构
|
|
239
|
-
* 存储在 Message.richContent 字段中
|
|
240
|
-
*/
|
|
241
|
-
export interface MessageRichContent {
|
|
242
|
-
/** 向后兼容:思考内容 */
|
|
243
|
-
thought?: string;
|
|
244
|
-
/** 向后兼容:工具调用 */
|
|
245
|
-
toolInvocations?: Array<{
|
|
246
|
-
id: string;
|
|
247
|
-
toolName: string;
|
|
248
|
-
input: unknown;
|
|
249
|
-
output?: unknown;
|
|
250
|
-
error?: string;
|
|
251
|
-
}>;
|
|
252
|
-
/** 新的块系统 */
|
|
253
|
-
blocks?: MessageBlock[];
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* 创建块的工厂函数
|
|
257
|
-
*/
|
|
258
|
-
export declare function createMessageBlock<T extends MessageBlock>(type: T['type'], messageId: string, partial: Omit<T, 'id' | 'messageId' | 'type' | 'createdAt' | 'status'>): T;
|
|
259
|
-
/**
|
|
260
|
-
* 判断块类型
|
|
261
|
-
*/
|
|
262
|
-
export declare function isBlockType<T extends MessageBlock>(block: MessageBlock, type: T['type']): block is T;
|
|
263
|
-
/**
|
|
264
|
-
* 从 richContent JSON 解析块
|
|
265
|
-
*/
|
|
266
|
-
export declare function parseMessageBlocks(richContent: string | null | undefined): MessageBlock[];
|
|
267
|
-
/**
|
|
268
|
-
* 序列化块到 richContent JSON
|
|
269
|
-
*/
|
|
270
|
-
export declare function serializeMessageBlocks(blocks: MessageBlock[]): string;
|