@lcap/wave-sandbox-sdk 0.0.2 → 0.0.4

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/dist/index.d.ts CHANGED
@@ -6,4 +6,4 @@ export { FileSystemModule } from './modules/file-system.js';
6
6
  export { PortModule } from './modules/port.js';
7
7
  export { ProjectModule } from './modules/project.js';
8
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';
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, AskUserQuestionEvent, AskInfo, ClientCallBackOptions, AskUserQuestion, AskUserQuestionOption, AgentEventMap, AgentEventName, } from './modules/agent.js';
@@ -242,6 +242,43 @@ export interface DocumentParseErrorEvent {
242
242
  mimeType: string;
243
243
  error: string;
244
244
  }
245
+ export interface AskUserQuestionOption {
246
+ label: string;
247
+ description?: string;
248
+ isRecommended?: boolean;
249
+ }
250
+ export interface AskUserQuestion {
251
+ question: string;
252
+ header: string;
253
+ options: AskUserQuestionOption[];
254
+ multiSelect?: boolean;
255
+ }
256
+ /**
257
+ * 询问用户问题事件数据
258
+ */
259
+ export interface AskUserQuestionEvent {
260
+ questionId: string;
261
+ questions: AskUserQuestion[];
262
+ }
263
+ /**
264
+ * Ask 信息状态
265
+ */
266
+ export interface AskInfo {
267
+ questionId: string;
268
+ sessionId: string;
269
+ questions: AskUserQuestion[];
270
+ createdAt: number;
271
+ answered: boolean;
272
+ answer?: string;
273
+ }
274
+ /**
275
+ * 客户端回调选项
276
+ */
277
+ export interface ClientCallBackOptions<T> {
278
+ event: string;
279
+ id: string;
280
+ data: T;
281
+ }
245
282
  /**
246
283
  * Agent 事件名称映射
247
284
  */
@@ -267,6 +304,7 @@ export type AgentEventMap = {
267
304
  'agent:document-parse-start': DocumentParseStartEvent;
268
305
  'agent:document-parse-complete': DocumentParseCompleteEvent;
269
306
  'agent:document-parse-error': DocumentParseErrorEvent;
307
+ 'agent:ask-user-question': AskUserQuestionEvent;
270
308
  };
271
309
  /**
272
310
  * Agent 事件名称类型
@@ -312,6 +350,12 @@ export declare class AgentModule {
312
350
  * @returns Promise<MessageQueueChangedEvent | null> 返回当前状态,如果没有活动状态则返回 null
313
351
  */
314
352
  getCurrentState(): Promise<MessageQueueChangedEvent | null>;
353
+ /**
354
+ * 获取指定 session 的 ask 信息
355
+ * @param sessionId 会话 ID
356
+ * @returns Promise<AskInfo | null> 返回 ask 信息,如果不存在则返回 null
357
+ */
358
+ getAskInfo(sessionId: string): Promise<AskInfo | null>;
315
359
  /**
316
360
  * 监听消息发送事件
317
361
  * @param callback 回调函数
@@ -438,6 +482,17 @@ export declare class AgentModule {
438
482
  * @returns 取消监听的函数
439
483
  */
440
484
  onDocumentParseError(callback: (event: DocumentParseErrorEvent) => void): () => void;
485
+ /**
486
+ * 监听询问用户问题事件
487
+ * @param callback 回调函数
488
+ * @returns 取消监听的函数
489
+ */
490
+ onAskUserQuestion(callback: (event: AskUserQuestionEvent) => void): () => void;
491
+ /**
492
+ * 发送客户端回调
493
+ * @param options 客户端回调选项
494
+ */
495
+ clientCallBack<T = unknown>(options: ClientCallBackOptions<T>): Promise<void>;
441
496
  /**
442
497
  * 通用事件监听方法,用于监听自定义事件
443
498
  * @param eventName 事件名称(必须以 'agent:' 开头)
@@ -68,6 +68,23 @@ export class AgentModule {
68
68
  }
69
69
  return result.data;
70
70
  }
71
+ /**
72
+ * 获取指定 session 的 ask 信息
73
+ * @param sessionId 会话 ID
74
+ * @returns Promise<AskInfo | null> 返回 ask 信息,如果不存在则返回 null
75
+ */
76
+ async getAskInfo(sessionId) {
77
+ const queryParams = this.getQueryParams();
78
+ const sessionIdParam = `sessionId=${encodeURIComponent(sessionId)}`;
79
+ const params = queryParams ? `${queryParams}&${sessionIdParam}` : sessionIdParam;
80
+ const url = `${this.baseUrl}/api/agent/askInfo?${params}`;
81
+ const response = await fetch(url);
82
+ const result = await response.json();
83
+ if (result.status === 'error') {
84
+ throw new Error(result.message);
85
+ }
86
+ return result.data;
87
+ }
71
88
  /**
72
89
  * 监听消息发送事件
73
90
  * @param callback 回调函数
@@ -236,6 +253,21 @@ export class AgentModule {
236
253
  onDocumentParseError(callback) {
237
254
  return onSocketEvent(this.socket, 'agent:document-parse-error', callback);
238
255
  }
256
+ /**
257
+ * 监听询问用户问题事件
258
+ * @param callback 回调函数
259
+ * @returns 取消监听的函数
260
+ */
261
+ onAskUserQuestion(callback) {
262
+ return onSocketEvent(this.socket, 'agent:ask-user-question', callback);
263
+ }
264
+ /**
265
+ * 发送客户端回调
266
+ * @param options 客户端回调选项
267
+ */
268
+ async clientCallBack(options) {
269
+ return createSocketHandler(this.socket, 'agent:clientCallBack', () => options);
270
+ }
239
271
  /**
240
272
  * 通用事件监听方法,用于监听自定义事件
241
273
  * @param eventName 事件名称(必须以 'agent:' 开头)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lcap/wave-sandbox-sdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "SDK for Wave Sandbox Client",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,15 +10,6 @@
10
10
  "src",
11
11
  "README.md"
12
12
  ],
13
- "scripts": {
14
- "build": "rimraf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
15
- "type-check": "tsc --noEmit",
16
- "dev": "tsc -p tsconfig.build.json --watch & tsc-alias -p tsconfig.build.json --watch",
17
- "test": "vitest run",
18
- "lint": "eslint --cache",
19
- "format": "prettier --write .",
20
- "prepublishOnly": "pnpm run build"
21
- },
22
13
  "dependencies": {
23
14
  "socket.io-client": "^4.8.3"
24
15
  },
@@ -31,5 +22,13 @@
31
22
  "engines": {
32
23
  "node": ">=16.0.0"
33
24
  },
34
- "license": "MIT"
35
- }
25
+ "license": "MIT",
26
+ "scripts": {
27
+ "build": "rimraf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
28
+ "type-check": "tsc --noEmit",
29
+ "dev": "tsc -p tsconfig.build.json --watch & tsc-alias -p tsconfig.build.json --watch",
30
+ "test": "vitest run",
31
+ "lint": "eslint --cache",
32
+ "format": "prettier --write ."
33
+ }
34
+ }
package/src/index.ts CHANGED
@@ -55,6 +55,11 @@ export type {
55
55
  DocumentParseStartEvent,
56
56
  DocumentParseCompleteEvent,
57
57
  DocumentParseErrorEvent,
58
+ AskUserQuestionEvent,
59
+ AskInfo,
60
+ ClientCallBackOptions,
61
+ AskUserQuestion,
62
+ AskUserQuestionOption,
58
63
  AgentEventMap,
59
64
  AgentEventName,
60
65
  } from './modules/agent.js';
@@ -276,6 +276,48 @@ export interface DocumentParseErrorEvent {
276
276
  error: string;
277
277
  }
278
278
 
279
+ export interface AskUserQuestionOption {
280
+ label: string;
281
+ description?: string;
282
+ isRecommended?: boolean;
283
+ }
284
+
285
+ export interface AskUserQuestion {
286
+ question: string;
287
+ header: string;
288
+ options: AskUserQuestionOption[];
289
+ multiSelect?: boolean;
290
+ }
291
+
292
+ /**
293
+ * 询问用户问题事件数据
294
+ */
295
+ export interface AskUserQuestionEvent {
296
+ questionId: string;
297
+ questions: AskUserQuestion[];
298
+ }
299
+
300
+ /**
301
+ * Ask 信息状态
302
+ */
303
+ export interface AskInfo {
304
+ questionId: string;
305
+ sessionId: string;
306
+ questions: AskUserQuestion[];
307
+ createdAt: number; // 时间戳(毫秒)
308
+ answered: boolean;
309
+ answer?: string;
310
+ }
311
+
312
+ /**
313
+ * 客户端回调选项
314
+ */
315
+ export interface ClientCallBackOptions<T> {
316
+ event: string;
317
+ id: string;
318
+ data: T;
319
+ }
320
+
279
321
  /**
280
322
  * Agent 事件名称映射
281
323
  */
@@ -301,6 +343,7 @@ export type AgentEventMap = {
301
343
  'agent:document-parse-start': DocumentParseStartEvent;
302
344
  'agent:document-parse-complete': DocumentParseCompleteEvent;
303
345
  'agent:document-parse-error': DocumentParseErrorEvent;
346
+ 'agent:ask-user-question': AskUserQuestionEvent;
304
347
  };
305
348
 
306
349
  /**
@@ -394,6 +437,26 @@ export class AgentModule {
394
437
  return result.data;
395
438
  }
396
439
 
440
+ /**
441
+ * 获取指定 session 的 ask 信息
442
+ * @param sessionId 会话 ID
443
+ * @returns Promise<AskInfo | null> 返回 ask 信息,如果不存在则返回 null
444
+ */
445
+ async getAskInfo(sessionId: string): Promise<AskInfo | null> {
446
+ const queryParams = this.getQueryParams();
447
+ const sessionIdParam = `sessionId=${encodeURIComponent(sessionId)}`;
448
+ const params = queryParams ? `${queryParams}&${sessionIdParam}` : sessionIdParam;
449
+ const url = `${this.baseUrl}/api/agent/askInfo?${params}`;
450
+ const response = await fetch(url);
451
+ const result: HttpResponse<AskInfo | null> = await response.json();
452
+
453
+ if (result.status === 'error') {
454
+ throw new Error(result.message);
455
+ }
456
+
457
+ return result.data;
458
+ }
459
+
397
460
  /**
398
461
  * 监听消息发送事件
399
462
  * @param callback 回调函数
@@ -609,6 +672,23 @@ export class AgentModule {
609
672
  return onSocketEvent<DocumentParseErrorEvent>(this.socket, 'agent:document-parse-error', callback);
610
673
  }
611
674
 
675
+ /**
676
+ * 监听询问用户问题事件
677
+ * @param callback 回调函数
678
+ * @returns 取消监听的函数
679
+ */
680
+ onAskUserQuestion(callback: (event: AskUserQuestionEvent) => void): () => void {
681
+ return onSocketEvent<AskUserQuestionEvent>(this.socket, 'agent:ask-user-question', callback);
682
+ }
683
+
684
+ /**
685
+ * 发送客户端回调
686
+ * @param options 客户端回调选项
687
+ */
688
+ async clientCallBack<T = unknown>(options: ClientCallBackOptions<T>): Promise<void> {
689
+ return createSocketHandler<ClientCallBackOptions<T>, void>(this.socket, 'agent:clientCallBack', () => options);
690
+ }
691
+
612
692
  /**
613
693
  * 通用事件监听方法,用于监听自定义事件
614
694
  * @param eventName 事件名称(必须以 'agent:' 开头)