@lcap/wave-sandbox-sdk 0.0.1 → 0.0.3

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 CHANGED
@@ -232,6 +232,28 @@ items.forEach(([name, type]) => {
232
232
  });
233
233
  ```
234
234
 
235
+ ##### `files(dirPath: string): Promise<Record<string, ProjectFile>>`
236
+
237
+ 获取指定目录下的所有文件(递归)。
238
+
239
+ **参数:**
240
+ - `dirPath`: 目录路径
241
+
242
+ **返回:** Promise<Record<string, ProjectFile>> 文件路径到文件信息的映射
243
+
244
+ **示例:**
245
+ ```typescript
246
+ const files = await client.fs.files('.');
247
+ Object.entries(files).forEach(([path, file]) => {
248
+ console.log(`文件路径: ${path}`);
249
+ console.log(`文件名: ${file.name}`);
250
+ console.log(`MIME类型: ${file.type}`);
251
+ console.log(`是否二进制: ${file.isBinary}`);
252
+ console.log(`最后修改时间: ${new Date(file.lastModified)}`);
253
+ console.log(`文件大小: ${file.size} 字节`);
254
+ });
255
+ ```
256
+
235
257
  ##### `writeFile(filePath: string, data: string | Blob | ArrayBuffer | Uint8Array, chunkSize?: number): Promise<void>`
236
258
 
237
259
  写入文件(流式)。
@@ -427,7 +449,7 @@ console.log('工作空间模式:', info.workspace);
427
449
 
428
450
  ##### `getFiles(): Promise<ProjectFile[]>`
429
451
 
430
- 获取项目文件列表。
452
+ 获取项目文件列表(仅返回文件,不包含目录)。
431
453
 
432
454
  **返回:** Promise<ProjectFile[]> 项目文件数组
433
455
 
@@ -435,7 +457,12 @@ console.log('工作空间模式:', info.workspace);
435
457
  ```typescript
436
458
  const files = await client.project.getFiles();
437
459
  files.forEach((file) => {
438
- console.log('文件:', file.path);
460
+ console.log('文件路径:', file.path);
461
+ console.log('文件名:', file.name);
462
+ console.log('MIME类型:', file.type);
463
+ console.log('是否二进制:', file.isBinary);
464
+ console.log('最后修改时间:', new Date(file.lastModified));
465
+ console.log('文件大小:', file.size, '字节');
439
466
  });
440
467
  ```
441
468
 
@@ -860,6 +887,12 @@ enum FileType {
860
887
  interface FileChangeEvent {
861
888
  type: 'add' | 'change' | 'unlink' | 'addDir' | 'unlinkDir';
862
889
  path: string;
890
+ /** 是否为二进制文件(仅在 add 和 change 事件中存在) */
891
+ isBinary?: boolean;
892
+ /** 最后修改时间(毫秒时间戳,仅在文件事件中存在) */
893
+ lastModified?: number;
894
+ /** 文件大小(字节,仅在文件事件中存在) */
895
+ size?: number;
863
896
  }
864
897
  ```
865
898
 
@@ -882,6 +915,19 @@ interface ProjectInfo {
882
915
  }
883
916
  ```
884
917
 
918
+ ### ProjectFile
919
+
920
+ ```typescript
921
+ interface ProjectFile {
922
+ path: string; // 文件相对路径
923
+ name: string; // 文件名
924
+ type: string; // MIME 类型
925
+ isBinary: boolean; // 是否为二进制文件
926
+ lastModified: number; // 最后修改时间(毫秒时间戳)
927
+ size: number; // 文件大小(字节)
928
+ }
929
+ ```
930
+
885
931
  ### SendMessageOptions
886
932
 
887
933
  ```typescript
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, ClientCallBackOptions, AgentEventMap, AgentEventName, } from './modules/agent.js';
@@ -242,6 +242,32 @@ 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
+ * 客户端回调选项
265
+ */
266
+ export interface ClientCallBackOptions<T> {
267
+ event: string;
268
+ id: string;
269
+ data: T;
270
+ }
245
271
  /**
246
272
  * Agent 事件名称映射
247
273
  */
@@ -267,6 +293,7 @@ export type AgentEventMap = {
267
293
  'agent:document-parse-start': DocumentParseStartEvent;
268
294
  'agent:document-parse-complete': DocumentParseCompleteEvent;
269
295
  'agent:document-parse-error': DocumentParseErrorEvent;
296
+ 'agent:ask-user-question': AskUserQuestionEvent;
270
297
  };
271
298
  /**
272
299
  * Agent 事件名称类型
@@ -438,6 +465,17 @@ export declare class AgentModule {
438
465
  * @returns 取消监听的函数
439
466
  */
440
467
  onDocumentParseError(callback: (event: DocumentParseErrorEvent) => void): () => void;
468
+ /**
469
+ * 监听询问用户问题事件
470
+ * @param callback 回调函数
471
+ * @returns 取消监听的函数
472
+ */
473
+ onAskUserQuestion(callback: (event: AskUserQuestionEvent) => void): () => void;
474
+ /**
475
+ * 发送客户端回调
476
+ * @param options 客户端回调选项
477
+ */
478
+ clientCallBack<T = unknown>(options: ClientCallBackOptions<T>): Promise<void>;
441
479
  /**
442
480
  * 通用事件监听方法,用于监听自定义事件
443
481
  * @param eventName 事件名称(必须以 'agent:' 开头)
@@ -236,6 +236,21 @@ export class AgentModule {
236
236
  onDocumentParseError(callback) {
237
237
  return onSocketEvent(this.socket, 'agent:document-parse-error', callback);
238
238
  }
239
+ /**
240
+ * 监听询问用户问题事件
241
+ * @param callback 回调函数
242
+ * @returns 取消监听的函数
243
+ */
244
+ onAskUserQuestion(callback) {
245
+ return onSocketEvent(this.socket, 'agent:ask-user-question', callback);
246
+ }
247
+ /**
248
+ * 发送客户端回调
249
+ * @param options 客户端回调选项
250
+ */
251
+ async clientCallBack(options) {
252
+ return createSocketHandler(this.socket, 'agent:clientCallBack', () => options);
253
+ }
239
254
  /**
240
255
  * 通用事件监听方法,用于监听自定义事件
241
256
  * @param eventName 事件名称(必须以 'agent:' 开头)
@@ -1,5 +1,5 @@
1
1
  import type { Socket } from 'socket.io-client';
2
- import type { FileStat, DirectoryItem, FileChangeEvent } from '../types/index.js';
2
+ import type { FileStat, DirectoryItem, FileChangeEvent, ProjectFile } from '../types/index.js';
3
3
  /**
4
4
  * 文件系统模块
5
5
  */
@@ -12,6 +12,10 @@ export declare class FileSystemModule {
12
12
  * 获取查询参数
13
13
  */
14
14
  private getQueryParams;
15
+ /**
16
+ * 获取查询参数(用于目录路径)
17
+ */
18
+ private getDirQueryParams;
15
19
  /**
16
20
  * 获取文件状态
17
21
  */
@@ -34,6 +38,12 @@ export declare class FileSystemModule {
34
38
  * 读取目录
35
39
  */
36
40
  readdir(filePath: string): Promise<DirectoryItem[]>;
41
+ /**
42
+ * 获取指定目录下的所有文件
43
+ * @param dirPath 目录路径
44
+ * @returns Promise<Record<string, ProjectFile>> 文件路径到文件信息的映射
45
+ */
46
+ files(dirPath: string): Promise<Record<string, ProjectFile>>;
37
47
  /**
38
48
  * 写入文件(流式)
39
49
  * @param filePath 文件路径
@@ -18,6 +18,16 @@ export class FileSystemModule {
18
18
  }
19
19
  return params.toString();
20
20
  }
21
+ /**
22
+ * 获取查询参数(用于目录路径)
23
+ */
24
+ getDirQueryParams(dirPath) {
25
+ const params = new URLSearchParams({ dirPath });
26
+ if (this.projectId) {
27
+ params.set('projectId', this.projectId);
28
+ }
29
+ return params.toString();
30
+ }
21
31
  /**
22
32
  * 获取文件状态
23
33
  */
@@ -71,6 +81,20 @@ export class FileSystemModule {
71
81
  }
72
82
  return result.data;
73
83
  }
84
+ /**
85
+ * 获取指定目录下的所有文件
86
+ * @param dirPath 目录路径
87
+ * @returns Promise<Record<string, ProjectFile>> 文件路径到文件信息的映射
88
+ */
89
+ async files(dirPath) {
90
+ const url = `${this.baseUrl}/api/fs/files?${this.getDirQueryParams(dirPath)}`;
91
+ const response = await fetch(url);
92
+ const result = await response.json();
93
+ if (result.status === 'error') {
94
+ throw new Error(result.message);
95
+ }
96
+ return result.data;
97
+ }
74
98
  /**
75
99
  * 写入文件(流式)
76
100
  * @param filePath 文件路径
@@ -56,6 +56,10 @@ export interface FileChangeEvent {
56
56
  path: string;
57
57
  /** 是否为二进制文件(仅在 add 和 change 事件中存在) */
58
58
  isBinary?: boolean;
59
+ /** 最后修改时间(毫秒时间戳,仅在文件事件中存在) */
60
+ lastModified?: number;
61
+ /** 文件大小(字节,仅在文件事件中存在) */
62
+ size?: number;
59
63
  }
60
64
  /**
61
65
  * 端口状态类型
@@ -81,6 +85,11 @@ export interface ProjectInfo {
81
85
  */
82
86
  export interface ProjectFile {
83
87
  path: string;
88
+ name: string;
89
+ type: string;
90
+ isBinary: boolean;
91
+ lastModified: number;
92
+ size: number;
84
93
  }
85
94
  /**
86
95
  * SDK 配置选项
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lcap/wave-sandbox-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "SDK for Wave Sandbox Client",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "README.md"
12
12
  ],
13
13
  "dependencies": {
14
- "socket.io-client": "^4.8.1"
14
+ "socket.io-client": "^4.8.3"
15
15
  },
16
16
  "devDependencies": {
17
17
  "rimraf": "^6.1.2",
package/src/index.ts CHANGED
@@ -55,6 +55,8 @@ export type {
55
55
  DocumentParseStartEvent,
56
56
  DocumentParseCompleteEvent,
57
57
  DocumentParseErrorEvent,
58
+ AskUserQuestionEvent,
59
+ ClientCallBackOptions,
58
60
  AgentEventMap,
59
61
  AgentEventName,
60
62
  } from './modules/agent.js';
@@ -276,6 +276,36 @@ 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
+ * 客户端回调选项
302
+ */
303
+ export interface ClientCallBackOptions<T> {
304
+ event: string;
305
+ id: string;
306
+ data: T;
307
+ }
308
+
279
309
  /**
280
310
  * Agent 事件名称映射
281
311
  */
@@ -301,6 +331,7 @@ export type AgentEventMap = {
301
331
  'agent:document-parse-start': DocumentParseStartEvent;
302
332
  'agent:document-parse-complete': DocumentParseCompleteEvent;
303
333
  'agent:document-parse-error': DocumentParseErrorEvent;
334
+ 'agent:ask-user-question': AskUserQuestionEvent;
304
335
  };
305
336
 
306
337
  /**
@@ -609,6 +640,23 @@ export class AgentModule {
609
640
  return onSocketEvent<DocumentParseErrorEvent>(this.socket, 'agent:document-parse-error', callback);
610
641
  }
611
642
 
643
+ /**
644
+ * 监听询问用户问题事件
645
+ * @param callback 回调函数
646
+ * @returns 取消监听的函数
647
+ */
648
+ onAskUserQuestion(callback: (event: AskUserQuestionEvent) => void): () => void {
649
+ return onSocketEvent<AskUserQuestionEvent>(this.socket, 'agent:ask-user-question', callback);
650
+ }
651
+
652
+ /**
653
+ * 发送客户端回调
654
+ * @param options 客户端回调选项
655
+ */
656
+ async clientCallBack<T = unknown>(options: ClientCallBackOptions<T>): Promise<void> {
657
+ return createSocketHandler<ClientCallBackOptions<T>, void>(this.socket, 'agent:clientCallBack', () => options);
658
+ }
659
+
612
660
  /**
613
661
  * 通用事件监听方法,用于监听自定义事件
614
662
  * @param eventName 事件名称(必须以 'agent:' 开头)
@@ -1,6 +1,6 @@
1
1
  import type { Socket } from 'socket.io-client';
2
2
  import { createSocketHandler, onSocketEvent } from '../utils/socket.js';
3
- import type { FileStat, DirectoryItem, FileChangeEvent, HttpResponse } from '../types/index.js';
3
+ import type { FileStat, DirectoryItem, FileChangeEvent, HttpResponse, ProjectFile } from '../types/index.js';
4
4
 
5
5
  /**
6
6
  * 文件系统模块
@@ -23,6 +23,17 @@ export class FileSystemModule {
23
23
  return params.toString();
24
24
  }
25
25
 
26
+ /**
27
+ * 获取查询参数(用于目录路径)
28
+ */
29
+ private getDirQueryParams(dirPath: string): string {
30
+ const params = new URLSearchParams({ dirPath });
31
+ if (this.projectId) {
32
+ params.set('projectId', this.projectId);
33
+ }
34
+ return params.toString();
35
+ }
36
+
26
37
  /**
27
38
  * 获取文件状态
28
39
  */
@@ -93,6 +104,23 @@ export class FileSystemModule {
93
104
  return result.data;
94
105
  }
95
106
 
107
+ /**
108
+ * 获取指定目录下的所有文件
109
+ * @param dirPath 目录路径
110
+ * @returns Promise<Record<string, ProjectFile>> 文件路径到文件信息的映射
111
+ */
112
+ async files(dirPath: string): Promise<Record<string, ProjectFile>> {
113
+ const url = `${this.baseUrl}/api/fs/files?${this.getDirQueryParams(dirPath)}`;
114
+ const response = await fetch(url);
115
+ const result: HttpResponse<Record<string, ProjectFile>> = await response.json();
116
+
117
+ if (result.status === 'error') {
118
+ throw new Error(result.message);
119
+ }
120
+
121
+ return result.data;
122
+ }
123
+
96
124
  /**
97
125
  * 写入文件(流式)
98
126
  * @param filePath 文件路径
@@ -66,6 +66,10 @@ export interface FileChangeEvent {
66
66
  path: string;
67
67
  /** 是否为二进制文件(仅在 add 和 change 事件中存在) */
68
68
  isBinary?: boolean;
69
+ /** 最后修改时间(毫秒时间戳,仅在文件事件中存在) */
70
+ lastModified?: number;
71
+ /** 文件大小(字节,仅在文件事件中存在) */
72
+ size?: number;
69
73
  }
70
74
 
71
75
  /**
@@ -95,7 +99,11 @@ export interface ProjectInfo {
95
99
  */
96
100
  export interface ProjectFile {
97
101
  path: string;
98
- // 可以根据实际需要添加更多字段
102
+ name: string;
103
+ type: string;
104
+ isBinary: boolean;
105
+ lastModified: number;
106
+ size: number;
99
107
  }
100
108
 
101
109
  /**