test-wuying-agentbay-sdk 0.13.1-beta.20251223155807 → 0.13.1-beta.20251223194518

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.
@@ -21,10 +21,52 @@ Handles code execution operations in the AgentBay cloud environment.
21
21
 
22
22
  ### Methods
23
23
 
24
+ - [execute](#execute)
25
+ - [run](#run)
24
26
  - [runCode](#runcode)
25
27
 
26
28
  ## Methods
27
29
 
30
+ ### execute
31
+
32
+ ▸ **execute**(`code`, `language`, `timeoutS?`): `Promise`\<`CodeExecutionResult`\>
33
+
34
+ Alias of runCode().
35
+
36
+ #### Parameters
37
+
38
+ | Name | Type | Default value |
39
+ | :------ | :------ | :------ |
40
+ | `code` | `string` | `undefined` |
41
+ | `language` | `string` | `undefined` |
42
+ | `timeoutS` | `number` | `60` |
43
+
44
+ #### Returns
45
+
46
+ `Promise`\<`CodeExecutionResult`\>
47
+
48
+ ___
49
+
50
+ ### run
51
+
52
+ ▸ **run**(`code`, `language`, `timeoutS?`): `Promise`\<`CodeExecutionResult`\>
53
+
54
+ Alias of runCode().
55
+
56
+ #### Parameters
57
+
58
+ | Name | Type | Default value |
59
+ | :------ | :------ | :------ |
60
+ | `code` | `string` | `undefined` |
61
+ | `language` | `string` | `undefined` |
62
+ | `timeoutS` | `number` | `60` |
63
+
64
+ #### Returns
65
+
66
+ `Promise`\<`CodeExecutionResult`\>
67
+
68
+ ___
69
+
28
70
  ### runCode
29
71
 
30
72
  ▸ **runCode**(`code`, `language`, `timeoutS?`): `Promise`\<`CodeExecutionResult`\>
@@ -37,7 +79,7 @@ Corresponds to Python's run_code() method
37
79
  | Name | Type | Default value | Description |
38
80
  | :------ | :------ | :------ | :------ |
39
81
  | `code` | `string` | `undefined` | The code to execute. |
40
- | `language` | `string` | `undefined` | The programming language of the code. Must be either 'python' or 'javascript'. |
82
+ | `language` | `string` | `undefined` | The programming language of the code. Case-insensitive. Supported values: 'python', 'javascript', 'r', 'java'. |
41
83
  | `timeoutS` | `number` | `60` | The timeout for the code execution in seconds. Default is 60s. Note: Due to gateway limitations, each request cannot exceed 60 seconds. |
42
84
 
43
85
  #### Returns
@@ -16,10 +16,33 @@ Handles command execution operations in the AgentBay cloud environment.
16
16
 
17
17
  ### Methods
18
18
 
19
+ - [exec](#exec)
19
20
  - [executeCommand](#executecommand)
21
+ - [run](#run)
20
22
 
21
23
  ## Methods
22
24
 
25
+ ### exec
26
+
27
+ ▸ **exec**(`command`, `timeoutMs?`, `cwd?`, `envs?`): `Promise`\<`CommandResult`\>
28
+
29
+ Alias of executeCommand().
30
+
31
+ #### Parameters
32
+
33
+ | Name | Type | Default value |
34
+ | :------ | :------ | :------ |
35
+ | `command` | `string` | `undefined` |
36
+ | `timeoutMs` | `number` | `1000` |
37
+ | `cwd?` | `string` | `undefined` |
38
+ | `envs?` | `Record`\<`string`, `string`\> | `undefined` |
39
+
40
+ #### Returns
41
+
42
+ `Promise`\<`CommandResult`\>
43
+
44
+ ___
45
+
23
46
  ### executeCommand
24
47
 
25
48
  ▸ **executeCommand**(`command`, `timeoutMs?`, `cwd?`, `envs?`): `Promise`\<`CommandResult`\>
@@ -84,6 +107,27 @@ if (result.success) {
84
107
  }
85
108
  ```
86
109
 
110
+ ___
111
+
112
+ ### run
113
+
114
+ ▸ **run**(`command`, `timeoutMs?`, `cwd?`, `envs?`): `Promise`\<`CommandResult`\>
115
+
116
+ Alias of executeCommand().
117
+
118
+ #### Parameters
119
+
120
+ | Name | Type | Default value |
121
+ | :------ | :------ | :------ |
122
+ | `command` | `string` | `undefined` |
123
+ | `timeoutMs` | `number` | `1000` |
124
+ | `cwd?` | `string` | `undefined` |
125
+ | `envs?` | `Record`\<`string`, `string`\> | `undefined` |
126
+
127
+ #### Returns
128
+
129
+ `Promise`\<`CommandResult`\>
130
+
87
131
  ## Best Practices
88
132
 
89
133
  1. Always specify appropriate timeout values based on expected command duration
@@ -12,16 +12,23 @@ Handles file operations in the AgentBay cloud environment.
12
12
  ### Methods
13
13
 
14
14
  - [createDirectory](#createdirectory)
15
+ - [delete](#delete)
15
16
  - [deleteFile](#deletefile)
16
17
  - [downloadFile](#downloadfile)
17
18
  - [editFile](#editfile)
19
+ - [list](#list)
18
20
  - [listDirectory](#listdirectory)
21
+ - [ls](#ls)
19
22
  - [moveFile](#movefile)
23
+ - [read](#read)
20
24
  - [readFile](#readfile)
21
25
  - [readMultipleFiles](#readmultiplefiles)
26
+ - [remove](#remove)
27
+ - [rm](#rm)
22
28
  - [searchFiles](#searchfiles)
23
29
  - [uploadFile](#uploadfile)
24
30
  - [watchDirectory](#watchdirectory)
31
+ - [write](#write)
25
32
  - [writeFile](#writefile)
26
33
 
27
34
  ## Methods
@@ -59,6 +66,24 @@ if (result.success) {
59
66
 
60
67
  ___
61
68
 
69
+ ### delete
70
+
71
+ ▸ **delete**(`path`): `Promise`\<`BoolResult`\>
72
+
73
+ Alias of deleteFile().
74
+
75
+ #### Parameters
76
+
77
+ | Name | Type |
78
+ | :------ | :------ |
79
+ | `path` | `string` |
80
+
81
+ #### Returns
82
+
83
+ `Promise`\<`BoolResult`\>
84
+
85
+ ___
86
+
62
87
  ### deleteFile
63
88
 
64
89
  ▸ **deleteFile**(`path`): `Promise`\<`BoolResult`\>
@@ -170,6 +195,24 @@ if (result.success) {
170
195
  }
171
196
  ```
172
197
 
198
+ ### list
199
+
200
+ ▸ **list**(`path`): `Promise`\<`DirectoryListResult`\>
201
+
202
+ Alias of listDirectory().
203
+
204
+ #### Parameters
205
+
206
+ | Name | Type |
207
+ | :------ | :------ |
208
+ | `path` | `string` |
209
+
210
+ #### Returns
211
+
212
+ `Promise`\<`DirectoryListResult`\>
213
+
214
+ ___
215
+
173
216
  ### listDirectory
174
217
 
175
218
  ▸ **listDirectory**(`path`): `Promise`\<`DirectoryListResult`\>
@@ -218,6 +261,24 @@ if (result.success) {
218
261
 
219
262
  ___
220
263
 
264
+ ### ls
265
+
266
+ ▸ **ls**(`path`): `Promise`\<`DirectoryListResult`\>
267
+
268
+ Alias of listDirectory().
269
+
270
+ #### Parameters
271
+
272
+ | Name | Type |
273
+ | :------ | :------ |
274
+ | `path` | `string` |
275
+
276
+ #### Returns
277
+
278
+ `Promise`\<`DirectoryListResult`\>
279
+
280
+ ___
281
+
221
282
  ### moveFile
222
283
 
223
284
  ▸ **moveFile**(`source`, `destination`): `Promise`\<`BoolResult`\>
@@ -253,6 +314,24 @@ if (result.success) {
253
314
 
254
315
  ___
255
316
 
317
+ ### read
318
+
319
+ ▸ **read**(`path`): `Promise`\<`FileContentResult`\>
320
+
321
+ Alias of readFile().
322
+
323
+ #### Parameters
324
+
325
+ | Name | Type |
326
+ | :------ | :------ |
327
+ | `path` | `string` |
328
+
329
+ #### Returns
330
+
331
+ `Promise`\<`FileContentResult`\>
332
+
333
+ ___
334
+
256
335
  ### readFile
257
336
 
258
337
  ▸ **readFile**(`path`): `Promise`\<`FileContentResult`\>
@@ -350,6 +429,42 @@ if (result.success) {
350
429
 
351
430
  ___
352
431
 
432
+ ### remove
433
+
434
+ ▸ **remove**(`path`): `Promise`\<`BoolResult`\>
435
+
436
+ Alias of deleteFile().
437
+
438
+ #### Parameters
439
+
440
+ | Name | Type |
441
+ | :------ | :------ |
442
+ | `path` | `string` |
443
+
444
+ #### Returns
445
+
446
+ `Promise`\<`BoolResult`\>
447
+
448
+ ___
449
+
450
+ ### rm
451
+
452
+ ▸ **rm**(`path`): `Promise`\<`BoolResult`\>
453
+
454
+ Alias of deleteFile().
455
+
456
+ #### Parameters
457
+
458
+ | Name | Type |
459
+ | :------ | :------ |
460
+ | `path` | `string` |
461
+
462
+ #### Returns
463
+
464
+ `Promise`\<`BoolResult`\>
465
+
466
+ ___
467
+
353
468
  ### searchFiles
354
469
 
355
470
  ▸ **searchFiles**(`path`, `pattern`, `excludePatterns?`): `Promise`\<`FileSearchResult`\>
@@ -465,6 +580,26 @@ if (result.success) {
465
580
 
466
581
  ___
467
582
 
583
+ ### write
584
+
585
+ ▸ **write**(`path`, `content`, `mode?`): `Promise`\<`BoolResult`\>
586
+
587
+ Alias of writeFile().
588
+
589
+ #### Parameters
590
+
591
+ | Name | Type | Default value |
592
+ | :------ | :------ | :------ |
593
+ | `path` | `string` | `undefined` |
594
+ | `content` | `string` | `undefined` |
595
+ | `mode` | `string` | `"overwrite"` |
596
+
597
+ #### Returns
598
+
599
+ `Promise`\<`BoolResult`\>
600
+
601
+ ___
602
+
468
603
  ### writeFile
469
604
 
470
605
  ▸ **writeFile**(`path`, `content`, `mode?`): `Promise`\<`BoolResult`\>
@@ -67,7 +67,7 @@ ___
67
67
 
68
68
  • `Optional` **enableBrowserReplay**: `boolean`
69
69
 
70
- Whether to enable browser recording for the session. Defaults to undefined (use default behavior, enabled by default).
70
+ Whether to enable browser recording for the session. Defaults to true.
71
71
 
72
72
  #### Implementation of
73
73
 
@@ -12,6 +12,12 @@ Represents a session in the AgentBay cloud environment.
12
12
  ### Properties
13
13
 
14
14
 
15
+ ### Accessors
16
+
17
+ - [files](#files)
18
+ - [filesystem](#filesystem)
19
+ - [fs](#fs)
20
+
15
21
  ### Methods
16
22
 
17
23
  - [callMcpTool](#callmcptool)
@@ -48,6 +54,42 @@ token: `string` = `""`
48
54
  ```
49
55
 
50
56
 
57
+ ## Accessors
58
+
59
+ ### files
60
+
61
+ • `get` **files**(): [`FileSystem`](filesystem.md)
62
+
63
+ Alias of fileSystem.
64
+
65
+ #### Returns
66
+
67
+ [`FileSystem`](filesystem.md)
68
+
69
+ ___
70
+
71
+ ### filesystem
72
+
73
+ • `get` **filesystem**(): [`FileSystem`](filesystem.md)
74
+
75
+ Alias of fileSystem.
76
+
77
+ #### Returns
78
+
79
+ [`FileSystem`](filesystem.md)
80
+
81
+ ___
82
+
83
+ ### fs
84
+
85
+ • `get` **fs**(): [`FileSystem`](filesystem.md)
86
+
87
+ Alias of fileSystem.
88
+
89
+ #### Returns
90
+
91
+ [`FileSystem`](filesystem.md)
92
+
51
93
  ## Methods
52
94
 
53
95
  ### callMcpTool
@@ -30,7 +30,9 @@ examples/
30
30
  ├── mobile-use/ # Mobile UI automation (mobile_latest)
31
31
  │ └── mobile-get-adb-url/ # ADB URL retrieval
32
32
  └── codespace/ # Code execution (code_latest)
33
- └── automation/ # Automation workflows
33
+ ├── automation/ # Automation workflows
34
+ ├── enhanced_code/ # Enhanced runCode() output (logs/results/error)
35
+ └── jupyter_context_persistence_r_java/ # Jupyter-like context persistence for R and Java
34
36
  ```
35
37
 
36
38
  ## 🚀 Quick Start
@@ -261,6 +263,8 @@ await browser.close();
261
263
 
262
264
  **Code Execution:**
263
265
  - Automation: `codespace/automation/automation-example.ts`
266
+ - Enhanced code result: `codespace/enhanced_code/index.ts`
267
+ - Jupyter-like context persistence (R/Java): `codespace/jupyter_context_persistence_r_java/index.ts`
264
268
 
265
269
  **Data Management:**
266
270
  - File operations: `common-features/basics/filesystem-example/filesystem-example.ts`
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * This example demonstrates how to use AgentBay SDK automation features in codespace environment, including:
5
5
  * - Command execution
6
- * - Code execution (Python and JavaScript)
6
+ * - Code execution (Python, JavaScript, R, and Java)
7
7
  * - Workflow orchestration
8
8
  */
9
9
 
@@ -0,0 +1,85 @@
1
+ /**
2
+ * AgentBay SDK - Jupyter Context Persistence (R & Java) Example (TypeScript)
3
+ *
4
+ * This example demonstrates that consecutive `session.code.runCode()` calls within the same
5
+ * session can share an execution context (Jupyter-like behavior) for R and Java, so variables
6
+ * defined in one call can be reused in subsequent calls.
7
+ */
8
+
9
+ import { AgentBay } from "wuying-agentbay-sdk";
10
+
11
+ async function main(): Promise<void> {
12
+ const apiKey = process.env.AGENTBAY_API_KEY;
13
+ if (!apiKey) {
14
+ console.error("Error: AGENTBAY_API_KEY environment variable not set");
15
+ process.exit(1);
16
+ }
17
+
18
+ const agentBay = new AgentBay({ apiKey });
19
+ const sessionResult = await agentBay.create({ imageId: "code_latest" });
20
+ if (!sessionResult.success || !sessionResult.session) {
21
+ throw new Error(`Failed to create session: ${sessionResult.errorMessage}`);
22
+ }
23
+
24
+ const session = sessionResult.session;
25
+ console.log(`Session created: ${session.sessionId}`);
26
+
27
+ try {
28
+ console.log("\n===== R: Jupyter-like context persistence =====");
29
+ const rSetup = `
30
+ x <- 41
31
+ cat("R_CONTEXT_SETUP_DONE\\n")
32
+ `.trim();
33
+ const rSetupRes = await session.code.runCode(rSetup, "R");
34
+ if (!rSetupRes.success) {
35
+ throw new Error(`R setup failed: ${rSetupRes.errorMessage}`);
36
+ }
37
+ console.log(rSetupRes.result);
38
+
39
+ const rUse = `cat(paste0("R_CONTEXT_VALUE:", x + 1, "\\n"))\n`;
40
+ const rUseRes = await session.code.runCode(rUse, "r");
41
+ if (!rUseRes.success) {
42
+ throw new Error(`R context use failed: ${rUseRes.errorMessage}`);
43
+ }
44
+ console.log(rUseRes.result);
45
+
46
+ if (!rUseRes.result.includes("R_CONTEXT_VALUE:42")) {
47
+ throw new Error("R context persistence verification failed");
48
+ }
49
+
50
+ console.log("\n===== Java: Jupyter-like context persistence =====");
51
+ const javaSetup = `
52
+ int x = 41;
53
+ System.out.println("JAVA_CONTEXT_SETUP_DONE");
54
+ `.trim();
55
+ const javaSetupRes = await session.code.runCode(javaSetup, "JAVA");
56
+ if (!javaSetupRes.success) {
57
+ throw new Error(`Java setup failed: ${javaSetupRes.errorMessage}`);
58
+ }
59
+ console.log(javaSetupRes.result);
60
+
61
+ const javaUse = `System.out.println("JAVA_CONTEXT_VALUE:" + (x + 1));\n`;
62
+ const javaUseRes = await session.code.runCode(javaUse, "java");
63
+ if (!javaUseRes.success) {
64
+ throw new Error(`Java context use failed: ${javaUseRes.errorMessage}`);
65
+ }
66
+ console.log(javaUseRes.result);
67
+
68
+ if (!javaUseRes.result.includes("JAVA_CONTEXT_VALUE:42")) {
69
+ throw new Error("Java context persistence verification failed");
70
+ }
71
+ } finally {
72
+ await session.delete();
73
+ }
74
+ }
75
+
76
+ if (require.main === module) {
77
+ main().catch((err) => {
78
+ console.error(err);
79
+ process.exit(1);
80
+ });
81
+ }
82
+
83
+ export { main };
84
+
85
+
@@ -40,7 +40,7 @@ async function main() {
40
40
  log('\n1. Executing simple shell command (echo)...');
41
41
  try {
42
42
  const echoCommand = "echo 'Hello from AgentBay SDK!'";
43
- const echoResponse = await session.command.executeCommand(echoCommand);
43
+ const echoResponse = await session.command.run(echoCommand);
44
44
  log(`Echo command output:\n${echoResponse.output}`);
45
45
  log(`Execute Command RequestId: ${echoResponse.requestId}`);
46
46
  } catch (error) {
@@ -52,7 +52,7 @@ async function main() {
52
52
  try {
53
53
  const lsCommand = "ls -la /etc";
54
54
  const timeoutMs = 5000; // 5 seconds timeout
55
- const lsResponse = await session.command.executeCommand(lsCommand, timeoutMs);
55
+ const lsResponse = await session.command.run(lsCommand, timeoutMs);
56
56
  log(`Directory listing (first few lines):\n${truncateOutput(lsResponse.output, 5)}`);
57
57
  log(`Execute Command with Timeout RequestId: ${lsResponse.requestId}`);
58
58
  } catch (error) {
@@ -72,7 +72,7 @@ print("Working with numbers in Python:")
72
72
  for i in range(1, 6):
73
73
  print(f"{i} squared is {i*i}")
74
74
  `;
75
- const pythonResponse = await session.code.runCode(pythonCode, "python");
75
+ const pythonResponse = await session.code.run(pythonCode, "python");
76
76
  log(`Python code output:\n${pythonResponse.result}`);
77
77
  log(`Run Python Code RequestId: ${pythonResponse.requestId}`);
78
78
 
@@ -104,7 +104,7 @@ const sum = numbers.reduce((total, n) => total + n, 0);
104
104
  console.log("Sum of array:", sum);
105
105
  `;
106
106
  const timeoutS = 10; // 10 seconds timeout
107
- const jsResponse = await session.code.runCode(jsCode, "javascript", timeoutS);
107
+ const jsResponse = await session.code.run(jsCode, "javascript", timeoutS);
108
108
  log(`JavaScript code output:\n${jsResponse.result}`);
109
109
  log(`Run JavaScript Code RequestId: ${jsResponse.requestId}`);
110
110
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-wuying-agentbay-sdk",
3
- "version": "0.13.1-beta.20251223155807",
3
+ "version": "0.13.1-beta.20251223194518",
4
4
  "description": "TypeScript SDK for interacting with the Wuying AgentBay cloud runtime environment",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",