@lcap/wave-sandbox-sdk 0.0.1

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.
@@ -0,0 +1,64 @@
1
+ import { type Socket } from 'socket.io-client';
2
+ import { ExecModule } from './modules/exec.js';
3
+ import { FileSystemModule } from './modules/file-system.js';
4
+ import { PortModule } from './modules/port.js';
5
+ import { ProjectModule } from './modules/project.js';
6
+ import { AgentModule } from './modules/agent.js';
7
+ import type { SDKOptions } from './types/index.js';
8
+ /**
9
+ * Wave Sandbox SDK 客户端
10
+ */
11
+ export declare class WaveSandboxClient {
12
+ private socket;
13
+ readonly exec: ExecModule;
14
+ readonly fileSystem: FileSystemModule;
15
+ /** 文件系统模块的简写别名 */
16
+ get fs(): FileSystemModule;
17
+ readonly port: PortModule;
18
+ readonly project: ProjectModule;
19
+ readonly agent: AgentModule;
20
+ constructor(options: SDKOptions);
21
+ /**
22
+ * 连接到服务器
23
+ */
24
+ connect(): void;
25
+ /**
26
+ * 断开连接
27
+ */
28
+ disconnect(): void;
29
+ /**
30
+ * 检查是否已连接
31
+ */
32
+ get connected(): boolean;
33
+ /**
34
+ * 获取 Socket ID
35
+ */
36
+ get id(): string | undefined;
37
+ /**
38
+ * 监听连接事件
39
+ */
40
+ onConnect(callback: () => void): () => void;
41
+ /**
42
+ * 监听断开连接事件
43
+ */
44
+ onDisconnect(callback: () => void): () => void;
45
+ /**
46
+ * 监听错误事件
47
+ */
48
+ onError(callback: (error: Error) => void): () => void;
49
+ /**
50
+ * 监听重连尝试事件
51
+ * @param callback 回调函数,参数为当前重连尝试次数
52
+ */
53
+ onReconnectAttempt(callback: (attempt: number) => void): () => void;
54
+ /**
55
+ * 监听重连成功事件
56
+ * @param callback 回调函数,参数为重连尝试次数
57
+ */
58
+ onReconnect(callback: (attempt: number) => void): () => void;
59
+ /**
60
+ * 监听重连失败事件(达到最大重连次数后触发)
61
+ */
62
+ onReconnectFailed(callback: () => void): () => void;
63
+ getSocket(): Socket;
64
+ }
package/dist/client.js ADDED
@@ -0,0 +1,126 @@
1
+ import { io } from 'socket.io-client';
2
+ import { ExecModule } from './modules/exec.js';
3
+ import { FileSystemModule } from './modules/file-system.js';
4
+ import { PortModule } from './modules/port.js';
5
+ import { ProjectModule } from './modules/project.js';
6
+ import { AgentModule } from './modules/agent.js';
7
+ /**
8
+ * Wave Sandbox SDK 客户端
9
+ */
10
+ export class WaveSandboxClient {
11
+ /** 文件系统模块的简写别名 */
12
+ get fs() {
13
+ return this.fileSystem;
14
+ }
15
+ constructor(options) {
16
+ const { url, projectId, options: socketOptions } = options;
17
+ const uri = new URL(url);
18
+ let pathname = uri.pathname;
19
+ if (pathname.endsWith('/')) {
20
+ pathname = pathname.slice(0, pathname.length - 1);
21
+ }
22
+ pathname = pathname + '/socket.io/';
23
+ // 构建 Socket.IO 连接选项
24
+ const connectOptions = {
25
+ autoConnect: socketOptions?.autoConnect ?? true,
26
+ reconnection: socketOptions?.reconnection ?? true,
27
+ reconnectionDelay: socketOptions?.reconnectionDelay ?? 1000,
28
+ reconnectionAttempts: socketOptions?.reconnectionAttempts ?? 5,
29
+ query: projectId ? { projectId } : undefined,
30
+ path: pathname,
31
+ };
32
+ // 创建 Socket.IO 连接
33
+ this.socket = io(uri.host, connectOptions);
34
+ // 初始化各个模块
35
+ this.exec = new ExecModule(this.socket);
36
+ this.fileSystem = new FileSystemModule(this.socket, url, projectId);
37
+ this.port = new PortModule(this.socket);
38
+ this.project = new ProjectModule(this.socket, url, projectId);
39
+ this.agent = new AgentModule(this.socket, url, projectId);
40
+ }
41
+ /**
42
+ * 连接到服务器
43
+ */
44
+ connect() {
45
+ if (!this.socket.connected) {
46
+ this.socket.connect();
47
+ }
48
+ }
49
+ /**
50
+ * 断开连接
51
+ */
52
+ disconnect() {
53
+ this.socket.disconnect();
54
+ }
55
+ /**
56
+ * 检查是否已连接
57
+ */
58
+ get connected() {
59
+ return this.socket.connected;
60
+ }
61
+ /**
62
+ * 获取 Socket ID
63
+ */
64
+ get id() {
65
+ return this.socket.id;
66
+ }
67
+ /**
68
+ * 监听连接事件
69
+ */
70
+ onConnect(callback) {
71
+ this.socket.on('connect', callback);
72
+ return () => {
73
+ this.socket.off('connect', callback);
74
+ };
75
+ }
76
+ /**
77
+ * 监听断开连接事件
78
+ */
79
+ onDisconnect(callback) {
80
+ this.socket.on('disconnect', callback);
81
+ return () => {
82
+ this.socket.off('disconnect', callback);
83
+ };
84
+ }
85
+ /**
86
+ * 监听错误事件
87
+ */
88
+ onError(callback) {
89
+ this.socket.on('error', callback);
90
+ return () => {
91
+ this.socket.off('error', callback);
92
+ };
93
+ }
94
+ /**
95
+ * 监听重连尝试事件
96
+ * @param callback 回调函数,参数为当前重连尝试次数
97
+ */
98
+ onReconnectAttempt(callback) {
99
+ this.socket.io.on('reconnect_attempt', callback);
100
+ return () => {
101
+ this.socket.io.off('reconnect_attempt', callback);
102
+ };
103
+ }
104
+ /**
105
+ * 监听重连成功事件
106
+ * @param callback 回调函数,参数为重连尝试次数
107
+ */
108
+ onReconnect(callback) {
109
+ this.socket.io.on('reconnect', callback);
110
+ return () => {
111
+ this.socket.io.off('reconnect', callback);
112
+ };
113
+ }
114
+ /**
115
+ * 监听重连失败事件(达到最大重连次数后触发)
116
+ */
117
+ onReconnectFailed(callback) {
118
+ this.socket.io.on('reconnect_failed', callback);
119
+ return () => {
120
+ this.socket.io.off('reconnect_failed', callback);
121
+ };
122
+ }
123
+ getSocket() {
124
+ return this.socket;
125
+ }
126
+ }
@@ -0,0 +1,9 @@
1
+ export { WaveSandboxClient } from './client.js';
2
+ export type { SDKOptions } from './types/index.js';
3
+ export type { HttpSuccessResponse, HttpErrorResponse, HttpResponse, SocketSuccessResponse, SocketErrorResponse, SocketResponse, FileType, FileStat, DirectoryItem, FileChangeType, FileChangeEvent, PortStatusType, PortStatusChangedEvent, ProjectInfo, ProjectFile, TextBlock, ToolBlock, ErrorBlock, SubagentBlock, McpServerConfig, McpServerStatus, } from './types/index.js';
4
+ export { ExecModule } from './modules/exec.js';
5
+ export { FileSystemModule } from './modules/file-system.js';
6
+ export { PortModule } from './modules/port.js';
7
+ export { ProjectModule } from './modules/project.js';
8
+ export { AgentModule } from './modules/agent.js';
9
+ export type { Attachment, SendMessageOptions, ProcessQueueItem, MessageQueueChangedEvent, MessageSendEvent, MessageRunningEvent, MessageFinishedEvent, InitializingEvent, InitializedEvent, MessageBlockAddedEvent, MessageBlockUpdatedEvent, MessageToolBlockUpdatedEvent, MessageSubagentBlockAddEvent, MessageSubagentBlockStatusUpdatedEvent, MessageSubagentBlockContentUpdatedEvent, MessageSubagentToolBlockUpdatedEvent, MessageErrorBlockAddedEvent, MessageCommandOutputMessageAddedEvent, MessageCommandOutputMessageUpdatedEvent, MessageCommandOutputMessageCompletedEvent, McpServersChangeEvent, DocumentParseStartEvent, DocumentParseCompleteEvent, DocumentParseErrorEvent, AgentEventMap, AgentEventName, } from './modules/agent.js';
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { WaveSandboxClient } from './client.js';
2
+ // 导出各个模块(可选,用于高级用法)
3
+ export { ExecModule } from './modules/exec.js';
4
+ export { FileSystemModule } from './modules/file-system.js';
5
+ export { PortModule } from './modules/port.js';
6
+ export { ProjectModule } from './modules/project.js';
7
+ export { AgentModule } from './modules/agent.js';
@@ -0,0 +1,448 @@
1
+ import type { Socket } from 'socket.io-client';
2
+ import type { TextBlock, ToolBlock, ErrorBlock, SubagentBlock, McpServerStatus, AssistantMessage } from '../types/agent-types.js';
3
+ /**
4
+ * 附件接口
5
+ */
6
+ export interface Attachment {
7
+ url?: string;
8
+ path?: string;
9
+ mimeType: string;
10
+ content?: string;
11
+ }
12
+ /**
13
+ * 发送消息选项
14
+ */
15
+ export interface SendMessageOptions {
16
+ id: string;
17
+ sessionId: string;
18
+ message: string;
19
+ attachments?: Attachment[];
20
+ }
21
+ /**
22
+ * 消息队列项
23
+ */
24
+ export interface ProcessQueueItem {
25
+ options: SendMessageOptions;
26
+ assistantMessageId: string;
27
+ }
28
+ /**
29
+ * 消息队列变化事件数据
30
+ */
31
+ export interface MessageQueueChangedEvent {
32
+ queue: ProcessQueueItem[];
33
+ current: {
34
+ sessionId: string;
35
+ assistantMessageId?: string;
36
+ senderMessageId: string;
37
+ message?: AssistantMessage;
38
+ } | null;
39
+ }
40
+ /**
41
+ * 消息发送事件数据
42
+ */
43
+ export interface MessageSendEvent {
44
+ sessionId: string;
45
+ assistantMessageId: string;
46
+ senderMessageId: string;
47
+ options: SendMessageOptions;
48
+ }
49
+ /**
50
+ * 消息运行事件数据
51
+ */
52
+ export interface MessageRunningEvent {
53
+ sessionId: string;
54
+ assistantMessageId: string;
55
+ senderMessageId: string;
56
+ }
57
+ /**
58
+ * 消息完成事件数据
59
+ */
60
+ export interface MessageFinishedEvent {
61
+ sessionId: string;
62
+ assistantMessageId?: string;
63
+ senderMessageId: string;
64
+ status: 'pending' | 'running' | 'finished' | 'error' | 'aborted';
65
+ }
66
+ /**
67
+ * 初始化事件数据
68
+ */
69
+ export interface InitializingEvent {
70
+ sessionId: string;
71
+ }
72
+ /**
73
+ * 初始化完成事件数据
74
+ */
75
+ export interface InitializedEvent {
76
+ sessionId: string;
77
+ restoreSessionId?: string;
78
+ }
79
+ /**
80
+ * 消息块添加事件数据
81
+ */
82
+ export interface MessageBlockAddedEvent {
83
+ sessionId: string;
84
+ assistantMessageId?: string;
85
+ senderMessageId: string;
86
+ data: {
87
+ blocks: Array<TextBlock | ToolBlock | ErrorBlock | SubagentBlock>;
88
+ };
89
+ }
90
+ /**
91
+ * 消息块更新事件数据(用于流式更新)
92
+ */
93
+ export interface MessageBlockUpdatedEvent {
94
+ sessionId: string;
95
+ assistantMessageId?: string;
96
+ senderMessageId: string;
97
+ data: {
98
+ type: 'text';
99
+ content: string;
100
+ };
101
+ }
102
+ /**
103
+ * 工具块更新事件数据
104
+ */
105
+ export interface MessageToolBlockUpdatedEvent {
106
+ sessionId: string;
107
+ assistantMessageId?: string;
108
+ senderMessageId: string;
109
+ data: ToolBlock;
110
+ }
111
+ /**
112
+ * 子代理块添加事件数据
113
+ */
114
+ export interface MessageSubagentBlockAddEvent {
115
+ sessionId: string;
116
+ assistantMessageId?: string;
117
+ senderMessageId: string;
118
+ data: {
119
+ subagentId: string;
120
+ blocks: Array<TextBlock | ToolBlock | ErrorBlock>;
121
+ };
122
+ }
123
+ /**
124
+ * 子代理块状态更新事件数据
125
+ */
126
+ export interface MessageSubagentBlockStatusUpdatedEvent {
127
+ sessionId: string;
128
+ assistantMessageId?: string;
129
+ senderMessageId: string;
130
+ data: {
131
+ subagentId: string;
132
+ status: 'active' | 'completed' | 'error' | 'aborted';
133
+ };
134
+ }
135
+ /**
136
+ * 子代理块内容更新事件数据
137
+ */
138
+ export interface MessageSubagentBlockContentUpdatedEvent {
139
+ sessionId: string;
140
+ assistantMessageId?: string;
141
+ senderMessageId: string;
142
+ data: {
143
+ subagentId: string;
144
+ type: 'text';
145
+ content: string;
146
+ };
147
+ }
148
+ /**
149
+ * 子代理工具块更新事件数据
150
+ */
151
+ export interface MessageSubagentToolBlockUpdatedEvent {
152
+ sessionId: string;
153
+ assistantMessageId?: string;
154
+ senderMessageId: string;
155
+ data: {
156
+ subagentId: string;
157
+ toolBlock: ToolBlock;
158
+ };
159
+ }
160
+ /**
161
+ * 错误块添加事件数据
162
+ */
163
+ export interface MessageErrorBlockAddedEvent {
164
+ sessionId: string;
165
+ assistantMessageId?: string;
166
+ senderMessageId: string;
167
+ data: ErrorBlock;
168
+ }
169
+ /**
170
+ * 命令输出消息添加事件数据
171
+ */
172
+ export interface MessageCommandOutputMessageAddedEvent {
173
+ sessionId: string;
174
+ assistantMessageId?: string;
175
+ senderMessageId: string;
176
+ data: {
177
+ command: string;
178
+ };
179
+ }
180
+ /**
181
+ * 命令输出消息更新事件数据
182
+ */
183
+ export interface MessageCommandOutputMessageUpdatedEvent {
184
+ sessionId: string;
185
+ assistantMessageId?: string;
186
+ senderMessageId: string;
187
+ data: {
188
+ command: string;
189
+ output: string;
190
+ };
191
+ }
192
+ /**
193
+ * 命令输出消息完成事件数据
194
+ */
195
+ export interface MessageCommandOutputMessageCompletedEvent {
196
+ sessionId: string;
197
+ assistantMessageId?: string;
198
+ senderMessageId: string;
199
+ data: {
200
+ command: string;
201
+ exitCode: number;
202
+ };
203
+ }
204
+ /**
205
+ * MCP 服务器变化事件数据
206
+ */
207
+ export interface McpServersChangeEvent {
208
+ sessionId: string;
209
+ servers: McpServerStatus[];
210
+ }
211
+ /**
212
+ * 文档解析开始事件数据
213
+ */
214
+ export interface DocumentParseStartEvent {
215
+ sessionId: string;
216
+ senderMessageId: string;
217
+ index: number;
218
+ url: string;
219
+ mimeType: string;
220
+ }
221
+ /**
222
+ * 文档解析完成事件数据
223
+ */
224
+ export interface DocumentParseCompleteEvent {
225
+ sessionId: string;
226
+ senderMessageId: string;
227
+ index: number;
228
+ url: string;
229
+ mimeType: string;
230
+ outputPath: string;
231
+ contentLength?: number;
232
+ pageCount?: number;
233
+ }
234
+ /**
235
+ * 文档解析错误事件数据
236
+ */
237
+ export interface DocumentParseErrorEvent {
238
+ sessionId: string;
239
+ senderMessageId: string;
240
+ index: number;
241
+ url: string;
242
+ mimeType: string;
243
+ error: string;
244
+ }
245
+ /**
246
+ * Agent 事件名称映射
247
+ */
248
+ export type AgentEventMap = {
249
+ 'agent:message-send': MessageSendEvent;
250
+ 'agent:message-running': MessageRunningEvent;
251
+ 'agent:message-finished': MessageFinishedEvent;
252
+ 'agent:message-queue-changed': MessageQueueChangedEvent;
253
+ 'agent:initializing': InitializingEvent;
254
+ 'agent:initialized': InitializedEvent;
255
+ 'agent:message-block-added': MessageBlockAddedEvent;
256
+ 'agent:message-block-updated': MessageBlockUpdatedEvent;
257
+ 'agent:message-tool-block-updated': MessageToolBlockUpdatedEvent;
258
+ 'agent:message-subagent-block-add': MessageSubagentBlockAddEvent;
259
+ 'agent:message-subagent-block-status-updated': MessageSubagentBlockStatusUpdatedEvent;
260
+ 'agent:message-subagent-block-content-updated': MessageSubagentBlockContentUpdatedEvent;
261
+ 'agent:message-subagent-tool-block-updated': MessageSubagentToolBlockUpdatedEvent;
262
+ 'agent:message-error-block-added': MessageErrorBlockAddedEvent;
263
+ 'agent:message-command-output-message-added': MessageCommandOutputMessageAddedEvent;
264
+ 'agent:message-command-output-message-updated': MessageCommandOutputMessageUpdatedEvent;
265
+ 'agent:message-command-output-message-completed': MessageCommandOutputMessageCompletedEvent;
266
+ 'agent:mcp-servers-change': McpServersChangeEvent;
267
+ 'agent:document-parse-start': DocumentParseStartEvent;
268
+ 'agent:document-parse-complete': DocumentParseCompleteEvent;
269
+ 'agent:document-parse-error': DocumentParseErrorEvent;
270
+ };
271
+ /**
272
+ * Agent 事件名称类型
273
+ */
274
+ export type AgentEventName = keyof AgentEventMap;
275
+ /**
276
+ * Agent 模块
277
+ */
278
+ export declare class AgentModule {
279
+ private socket;
280
+ private baseUrl;
281
+ private projectId?;
282
+ constructor(socket: Socket, baseUrl: string, projectId?: string | undefined);
283
+ /**
284
+ * 获取查询参数
285
+ */
286
+ private getQueryParams;
287
+ /**
288
+ * 发送消息
289
+ * @param options 发送消息选项
290
+ * @returns Promise<string> 返回 assistantMessageId
291
+ */
292
+ sendMessage(options: SendMessageOptions): Promise<string>;
293
+ /**
294
+ * 中止消息
295
+ * @param messageId 消息 ID
296
+ */
297
+ abortMessage(messageId: string): Promise<void>;
298
+ /**
299
+ * 删除 session,包括日志记录和 agent 对象
300
+ * @param sessionId 会话 ID
301
+ * @throws 如果当前正在处理该 session 的消息,则抛出错误
302
+ */
303
+ removeSession(sessionId: string): Promise<void>;
304
+ /**
305
+ * 获取指定 session 的消息日志文件列表
306
+ * @param sessionId 会话 ID
307
+ * @returns Promise<string[] | null> 返回文件列表(倒序,最新的在前),如果没有文件则返回 null
308
+ */
309
+ getSessionFiles(sessionId: string): Promise<string[] | null>;
310
+ /**
311
+ * 获取当前 wave-agent 的完整状态
312
+ * @returns Promise<MessageQueueChangedEvent | null> 返回当前状态,如果没有活动状态则返回 null
313
+ */
314
+ getCurrentState(): Promise<MessageQueueChangedEvent | null>;
315
+ /**
316
+ * 监听消息发送事件
317
+ * @param callback 回调函数
318
+ * @returns 取消监听的函数
319
+ */
320
+ onMessageSend(callback: (event: MessageSendEvent) => void): () => void;
321
+ /**
322
+ * 监听消息运行事件
323
+ * @param callback 回调函数
324
+ * @returns 取消监听的函数
325
+ */
326
+ onMessageRunning(callback: (event: MessageRunningEvent) => void): () => void;
327
+ /**
328
+ * 监听消息完成事件
329
+ * @param callback 回调函数
330
+ * @returns 取消监听的函数
331
+ */
332
+ onMessageFinished(callback: (event: MessageFinishedEvent) => void): () => void;
333
+ /**
334
+ * 监听消息队列变化事件
335
+ * @param callback 回调函数
336
+ * @returns 取消监听的函数
337
+ */
338
+ onMessageQueueChanged(callback: (event: MessageQueueChangedEvent) => void): () => void;
339
+ /**
340
+ * 监听初始化事件
341
+ * @param callback 回调函数
342
+ * @returns 取消监听的函数
343
+ */
344
+ onInitializing(callback: (event: InitializingEvent) => void): () => void;
345
+ /**
346
+ * 监听初始化完成事件
347
+ * @param callback 回调函数
348
+ * @returns 取消监听的函数
349
+ */
350
+ onInitialized(callback: (event: InitializedEvent) => void): () => void;
351
+ /**
352
+ * 监听消息块添加事件
353
+ * @param callback 回调函数
354
+ * @returns 取消监听的函数
355
+ */
356
+ onMessageBlockAdded(callback: (event: MessageBlockAddedEvent) => void): () => void;
357
+ /**
358
+ * 监听消息块更新事件(用于流式内容更新)
359
+ * @param callback 回调函数
360
+ * @returns 取消监听的函数
361
+ */
362
+ onMessageBlockUpdated(callback: (event: MessageBlockUpdatedEvent) => void): () => void;
363
+ /**
364
+ * 监听工具块更新事件
365
+ * @param callback 回调函数
366
+ * @returns 取消监听的函数
367
+ */
368
+ onMessageToolBlockUpdated(callback: (event: MessageToolBlockUpdatedEvent) => void): () => void;
369
+ /**
370
+ * 监听子代理块添加事件
371
+ * @param callback 回调函数
372
+ * @returns 取消监听的函数
373
+ */
374
+ onMessageSubagentBlockAdd(callback: (event: MessageSubagentBlockAddEvent) => void): () => void;
375
+ /**
376
+ * 监听子代理块状态更新事件
377
+ * @param callback 回调函数
378
+ * @returns 取消监听的函数
379
+ */
380
+ onMessageSubagentBlockStatusUpdated(callback: (event: MessageSubagentBlockStatusUpdatedEvent) => void): () => void;
381
+ /**
382
+ * 监听子代理块内容更新事件
383
+ * @param callback 回调函数
384
+ * @returns 取消监听的函数
385
+ */
386
+ onMessageSubagentBlockContentUpdated(callback: (event: MessageSubagentBlockContentUpdatedEvent) => void): () => void;
387
+ /**
388
+ * 监听子代理工具块更新事件
389
+ * @param callback 回调函数
390
+ * @returns 取消监听的函数
391
+ */
392
+ onMessageSubagentToolBlockUpdated(callback: (event: MessageSubagentToolBlockUpdatedEvent) => void): () => void;
393
+ /**
394
+ * 监听错误块添加事件
395
+ * @param callback 回调函数
396
+ * @returns 取消监听的函数
397
+ */
398
+ onMessageErrorBlockAdded(callback: (event: MessageErrorBlockAddedEvent) => void): () => void;
399
+ /**
400
+ * 监听命令输出消息添加事件
401
+ * @param callback 回调函数
402
+ * @returns 取消监听的函数
403
+ */
404
+ onMessageCommandOutputMessageAdded(callback: (event: MessageCommandOutputMessageAddedEvent) => void): () => void;
405
+ /**
406
+ * 监听命令输出消息更新事件
407
+ * @param callback 回调函数
408
+ * @returns 取消监听的函数
409
+ */
410
+ onMessageCommandOutputMessageUpdated(callback: (event: MessageCommandOutputMessageUpdatedEvent) => void): () => void;
411
+ /**
412
+ * 监听命令输出消息完成事件
413
+ * @param callback 回调函数
414
+ * @returns 取消监听的函数
415
+ */
416
+ onMessageCommandOutputMessageCompleted(callback: (event: MessageCommandOutputMessageCompletedEvent) => void): () => void;
417
+ /**
418
+ * 监听 MCP 服务器变化事件
419
+ * @param callback 回调函数
420
+ * @returns 取消监听的函数
421
+ */
422
+ onMcpServersChange(callback: (event: McpServersChangeEvent) => void): () => void;
423
+ /**
424
+ * 监听文档解析开始事件
425
+ * @param callback 回调函数
426
+ * @returns 取消监听的函数
427
+ */
428
+ onDocumentParseStart(callback: (event: DocumentParseStartEvent) => void): () => void;
429
+ /**
430
+ * 监听文档解析完成事件
431
+ * @param callback 回调函数
432
+ * @returns 取消监听的函数
433
+ */
434
+ onDocumentParseComplete(callback: (event: DocumentParseCompleteEvent) => void): () => void;
435
+ /**
436
+ * 监听文档解析错误事件
437
+ * @param callback 回调函数
438
+ * @returns 取消监听的函数
439
+ */
440
+ onDocumentParseError(callback: (event: DocumentParseErrorEvent) => void): () => void;
441
+ /**
442
+ * 通用事件监听方法,用于监听自定义事件
443
+ * @param eventName 事件名称(必须以 'agent:' 开头)
444
+ * @param callback 回调函数
445
+ * @returns 取消监听的函数
446
+ */
447
+ on<T = unknown>(eventName: string, callback: (event: T) => void): () => void;
448
+ }