wuying-agentbay-sdk 0.10.2 → 0.11.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/dist/chunk-E7QC5S76.mjs +3143 -0
- package/dist/chunk-E7QC5S76.mjs.map +1 -0
- package/dist/chunk-ZUB35HKV.cjs +3134 -0
- package/dist/chunk-ZUB35HKV.cjs.map +1 -0
- package/dist/index.cjs +3588 -3921
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2088 -687
- package/dist/index.d.ts +2088 -687
- package/dist/index.mjs +3556 -3889
- package/dist/index.mjs.map +1 -1
- package/dist/key-normalizer-AF7APGQZ.cjs +136 -0
- package/dist/key-normalizer-AF7APGQZ.cjs.map +1 -0
- package/dist/key-normalizer-QDBRLFHF.mjs +145 -0
- package/dist/key-normalizer-QDBRLFHF.mjs.map +1 -0
- package/dist/model-2G37RFQQ.cjs +188 -0
- package/dist/model-2G37RFQQ.cjs.map +1 -0
- package/dist/model-ZFTLKEMC.mjs +197 -0
- package/docs/api/README.md +26 -0
- package/docs/api/browser-use/browser.md +177 -0
- package/docs/api/browser-use/extension.md +284 -0
- package/docs/api/codespace/code.md +77 -0
- package/docs/api/common-features/advanced/agent.md +84 -0
- package/docs/api/common-features/advanced/oss.md +221 -0
- package/docs/api/common-features/basics/agentbay.md +181 -0
- package/docs/api/common-features/basics/command.md +83 -0
- package/docs/api/common-features/basics/context-manager.md +130 -0
- package/docs/api/common-features/basics/context-sync.md +51 -0
- package/docs/api/common-features/basics/context.md +348 -0
- package/docs/api/common-features/basics/filesystem.md +499 -0
- package/docs/api/common-features/basics/logging.md +77 -0
- package/docs/api/common-features/basics/session.md +412 -0
- package/docs/api/computer-use/computer.md +786 -0
- package/docs/api/mobile-use/mobile.md +395 -0
- package/docs/examples/README.md +332 -0
- package/docs/examples/basic-usage.ts +86 -0
- package/docs/examples/browser-use/browser/README.md +356 -0
- package/docs/examples/browser-use/browser/basic-usage.ts +136 -0
- package/docs/examples/browser-use/browser/browser-command-args.ts +117 -0
- package/docs/examples/browser-use/browser/browser-context-cookie-persistence.ts +348 -0
- package/docs/examples/browser-use/browser/browser-fingerprint-basic-usage.ts +121 -0
- package/docs/examples/browser-use/browser/browser-fingerprint-construct.ts +114 -0
- package/docs/examples/browser-use/browser/browser-fingerprint-local-sync.ts +98 -0
- package/docs/examples/browser-use/browser/browser-fingerprint-persistence.ts +242 -0
- package/docs/examples/browser-use/browser/browser-proxies.ts +149 -0
- package/docs/examples/browser-use/browser/browser-type-example.ts +266 -0
- package/docs/examples/browser-use/browser/browser-viewport.ts +129 -0
- package/docs/examples/browser-use/browser/call_for_user_jd.ts +184 -0
- package/docs/examples/browser-use/browser/captcha_tongcheng.ts +151 -0
- package/docs/examples/browser-use/browser/run-2048.ts +209 -0
- package/docs/examples/browser-use/browser/run-sudoku.ts +150 -0
- package/docs/examples/browser-use/browser/screenshot-example.ts +132 -0
- package/docs/examples/browser-use/extension-example/README.md +252 -0
- package/docs/examples/browser-use/extension-example/extension-example.ts +380 -0
- package/docs/examples/codespace/automation/automation-example.ts +322 -0
- package/docs/examples/common-features/advanced/agent-module-example/README.md +40 -0
- package/docs/examples/common-features/advanced/agent-module-example.ts +66 -0
- package/docs/examples/common-features/advanced/archive-upload-mode-example/README.md +212 -0
- package/docs/examples/common-features/advanced/archive-upload-mode-example/archive-upload-mode-example.ts +213 -0
- package/docs/examples/common-features/advanced/vpc-session-example/README.md +47 -0
- package/docs/examples/common-features/advanced/vpc-session-example.ts +106 -0
- package/docs/examples/common-features/basics/archive-upload-mode-example/README.md +236 -0
- package/docs/examples/common-features/basics/archive-upload-mode-example/main.ts +236 -0
- package/docs/examples/common-features/basics/command-example/README.md +47 -0
- package/docs/examples/common-features/basics/command-example/command-example.ts +153 -0
- package/docs/examples/common-features/basics/context-management/README.md +55 -0
- package/docs/examples/common-features/basics/context-management/context-management.ts +140 -0
- package/docs/examples/common-features/basics/data-persistence/README.md +129 -0
- package/docs/examples/common-features/basics/data-persistence/context-sync-demo.md +144 -0
- package/docs/examples/common-features/basics/data-persistence/context-sync-demo.ts +275 -0
- package/docs/examples/common-features/basics/data-persistence/data-persistence.ts +259 -0
- package/docs/examples/common-features/basics/data-persistence/recycle-policy-example.ts +294 -0
- package/docs/examples/common-features/basics/filesystem-example/README.md +57 -0
- package/docs/examples/common-features/basics/filesystem-example/filesystem-example.ts +164 -0
- package/docs/examples/common-features/basics/filesystem-example/filesystem-filetransfer-example.ts +153 -0
- package/docs/examples/common-features/basics/filesystem-example/watch-directory-example.ts +168 -0
- package/docs/examples/common-features/basics/get/README.md +136 -0
- package/docs/examples/common-features/basics/get/main.ts +79 -0
- package/docs/examples/common-features/basics/list_sessions/README.md +54 -0
- package/docs/examples/common-features/basics/list_sessions/main.ts +258 -0
- package/docs/examples/common-features/basics/mcp_tool_direct_call/README.md +142 -0
- package/docs/examples/common-features/basics/mcp_tool_direct_call/main.ts +135 -0
- package/docs/examples/common-features/basics/session-creation/README.md +28 -0
- package/docs/examples/common-features/basics/session-creation/session-creation.ts +295 -0
- package/docs/examples/mobile-use/mobile-get-adb-url/README.md +92 -0
- package/docs/examples/mobile-use/mobile-get-adb-url/index.ts +80 -0
- package/docs/examples/mobile-use/mobile-get-adb-url/package-lock.json +279 -0
- package/docs/examples/mobile-use/mobile-get-adb-url/package.json +18 -0
- package/package.json +18 -11
- package/dist/application-KZWXH46T.mjs +0 -17
- package/dist/application-LMA7KSRH.cjs +0 -8
- package/dist/application-LMA7KSRH.cjs.map +0 -1
- package/dist/chunk-BQNGKBQF.mjs +0 -386
- package/dist/chunk-BQNGKBQF.mjs.map +0 -1
- package/dist/chunk-IOVGAAJL.cjs +0 -558
- package/dist/chunk-IOVGAAJL.cjs.map +0 -1
- package/dist/chunk-UF2TC2R4.mjs +0 -567
- package/dist/chunk-UF2TC2R4.mjs.map +0 -1
- package/dist/chunk-X6MS7Z5L.cjs +0 -377
- package/dist/chunk-X6MS7Z5L.cjs.map +0 -1
- package/dist/window-DH37ZDD5.mjs +0 -17
- package/dist/window-DH37ZDD5.mjs.map +0 -1
- package/dist/window-U7N3H735.cjs +0 -8
- package/dist/window-U7N3H735.cjs.map +0 -1
- /package/dist/{application-KZWXH46T.mjs.map → model-ZFTLKEMC.mjs.map} +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Class: Code
|
|
2
|
+
|
|
3
|
+
## 💻 Related Tutorial
|
|
4
|
+
|
|
5
|
+
- [Code Execution Guide](../../../../docs/guides/codespace/code-execution.md) - Execute code in isolated environments
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The Code module provides secure code execution capabilities in isolated environments.
|
|
10
|
+
It supports multiple programming languages including Python, JavaScript, and more.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- Requires `code_latest` image for code execution features
|
|
16
|
+
|
|
17
|
+
Handles code execution operations in the AgentBay cloud environment.
|
|
18
|
+
|
|
19
|
+
## Table of contents
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Methods
|
|
23
|
+
|
|
24
|
+
- [runCode](#runcode)
|
|
25
|
+
|
|
26
|
+
## Methods
|
|
27
|
+
|
|
28
|
+
### runCode
|
|
29
|
+
|
|
30
|
+
▸ **runCode**(`code`, `language`, `timeoutS?`): `Promise`\<`CodeExecutionResult`\>
|
|
31
|
+
|
|
32
|
+
Execute code in the specified language with a timeout.
|
|
33
|
+
Corresponds to Python's run_code() method
|
|
34
|
+
|
|
35
|
+
#### Parameters
|
|
36
|
+
|
|
37
|
+
| Name | Type | Default value | Description |
|
|
38
|
+
| :------ | :------ | :------ | :------ |
|
|
39
|
+
| `code` | `string` | `undefined` | The code to execute. |
|
|
40
|
+
| `language` | `string` | `undefined` | The programming language of the code. Must be either 'python' or 'javascript'. |
|
|
41
|
+
| `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
|
+
|
|
43
|
+
#### Returns
|
|
44
|
+
|
|
45
|
+
`Promise`\<`CodeExecutionResult`\>
|
|
46
|
+
|
|
47
|
+
CodeExecutionResult with code execution output and requestId
|
|
48
|
+
|
|
49
|
+
**`Throws`**
|
|
50
|
+
|
|
51
|
+
Error if an unsupported language is specified.
|
|
52
|
+
|
|
53
|
+
**`Example`**
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
57
|
+
const result = await agentBay.create({ imageId: "code_latest" });
|
|
58
|
+
if (result.success) {
|
|
59
|
+
const codeResult = await result.session.code.runCode('print("Hello")', "python");
|
|
60
|
+
console.log(codeResult.result);
|
|
61
|
+
await result.session.delete();
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Best Practices
|
|
66
|
+
|
|
67
|
+
1. Validate code syntax before execution
|
|
68
|
+
2. Set appropriate execution timeouts
|
|
69
|
+
3. Handle execution errors and exceptions
|
|
70
|
+
4. Use proper resource limits to prevent resource exhaustion
|
|
71
|
+
5. Clean up temporary files after code execution
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## Related Resources
|
|
75
|
+
|
|
76
|
+
- [Session API Reference](../common-features/basics/session.md)
|
|
77
|
+
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Class: Agent
|
|
2
|
+
|
|
3
|
+
## 🤖 Related Tutorial
|
|
4
|
+
|
|
5
|
+
- [Agent Modules Guide](../../../../../docs/guides/common-features/advanced/agent-modules.md) - Learn about agent modules and custom agents
|
|
6
|
+
|
|
7
|
+
An Agent to manipulate applications to complete specific tasks.
|
|
8
|
+
|
|
9
|
+
## Table of contents
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Methods
|
|
13
|
+
|
|
14
|
+
- [executeTask](#executetask)
|
|
15
|
+
- [terminateTask](#terminatetask)
|
|
16
|
+
|
|
17
|
+
## Methods
|
|
18
|
+
|
|
19
|
+
### executeTask
|
|
20
|
+
|
|
21
|
+
▸ **executeTask**(`task`, `maxTryTimes`): `Promise`\<``ExecutionResult``\>
|
|
22
|
+
|
|
23
|
+
Execute a specific task described in human language.
|
|
24
|
+
|
|
25
|
+
#### Parameters
|
|
26
|
+
|
|
27
|
+
| Name | Type | Description |
|
|
28
|
+
| :------ | :------ | :------ |
|
|
29
|
+
| `task` | `string` | Task description in human language. |
|
|
30
|
+
| `maxTryTimes` | `number` | Maximum number of retry attempts. |
|
|
31
|
+
|
|
32
|
+
#### Returns
|
|
33
|
+
|
|
34
|
+
`Promise`\<``ExecutionResult``\>
|
|
35
|
+
|
|
36
|
+
ExecutionResult containing success status, task output, and error message if any.
|
|
37
|
+
|
|
38
|
+
**`Example`**
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
42
|
+
const result = await agentBay.create({ imageId: 'windows_latest' });
|
|
43
|
+
if (result.success) {
|
|
44
|
+
const taskResult = await result.session.agent.executeTask('Open notepad', 10);
|
|
45
|
+
console.log(`Task status: ${taskResult.taskStatus}`);
|
|
46
|
+
await result.session.delete();
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### terminateTask
|
|
51
|
+
|
|
52
|
+
▸ **terminateTask**(`taskId`): `Promise`\<``ExecutionResult``\>
|
|
53
|
+
|
|
54
|
+
Terminate a task with a specified task ID.
|
|
55
|
+
|
|
56
|
+
#### Parameters
|
|
57
|
+
|
|
58
|
+
| Name | Type | Description |
|
|
59
|
+
| :------ | :------ | :------ |
|
|
60
|
+
| `taskId` | `string` | The ID of the running task. |
|
|
61
|
+
|
|
62
|
+
#### Returns
|
|
63
|
+
|
|
64
|
+
`Promise`\<``ExecutionResult``\>
|
|
65
|
+
|
|
66
|
+
ExecutionResult containing success status, task output, and error message if any.
|
|
67
|
+
|
|
68
|
+
**`Example`**
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
72
|
+
const result = await agentBay.create({ imageId: 'windows_latest' });
|
|
73
|
+
if (result.success) {
|
|
74
|
+
const taskResult = await result.session.agent.executeTask('Open notepad', 5);
|
|
75
|
+
const terminateResult = await result.session.agent.terminateTask(taskResult.taskId);
|
|
76
|
+
console.log(`Terminated: ${terminateResult.taskStatus}`);
|
|
77
|
+
await result.session.delete();
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Related Resources
|
|
82
|
+
|
|
83
|
+
- [Session API Reference](../../common-features/basics/session.md)
|
|
84
|
+
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# Class: Oss
|
|
2
|
+
|
|
3
|
+
## ☁️ Related Tutorial
|
|
4
|
+
|
|
5
|
+
- [OSS Integration Guide](../../../../../docs/guides/common-features/advanced/oss-integration.md) - Integrate with Alibaba Cloud OSS for file storage
|
|
6
|
+
|
|
7
|
+
Handles OSS operations in the AgentBay cloud environment.
|
|
8
|
+
|
|
9
|
+
## Table of contents
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Methods
|
|
13
|
+
|
|
14
|
+
- [download](#download)
|
|
15
|
+
- [downloadAnonymous](#downloadanonymous)
|
|
16
|
+
- [envInit](#envinit)
|
|
17
|
+
- [upload](#upload)
|
|
18
|
+
- [uploadAnonymous](#uploadanonymous)
|
|
19
|
+
|
|
20
|
+
## Methods
|
|
21
|
+
|
|
22
|
+
### download
|
|
23
|
+
|
|
24
|
+
▸ **download**(`bucket`, `object`, `path`): `Promise`\<`OSSDownloadResult`\>
|
|
25
|
+
|
|
26
|
+
Download a file from OSS.
|
|
27
|
+
Corresponds to Python's download() method
|
|
28
|
+
|
|
29
|
+
#### Parameters
|
|
30
|
+
|
|
31
|
+
| Name | Type | Description |
|
|
32
|
+
| :------ | :------ | :------ |
|
|
33
|
+
| `bucket` | `string` | The OSS bucket name |
|
|
34
|
+
| `object` | `string` | The OSS object key |
|
|
35
|
+
| `path` | `string` | The local file path to save the downloaded file |
|
|
36
|
+
|
|
37
|
+
#### Returns
|
|
38
|
+
|
|
39
|
+
`Promise`\<`OSSDownloadResult`\>
|
|
40
|
+
|
|
41
|
+
OSSDownloadResult with download result and requestId
|
|
42
|
+
|
|
43
|
+
**`Throws`**
|
|
44
|
+
|
|
45
|
+
APIError if the operation fails.
|
|
46
|
+
|
|
47
|
+
**`Example`**
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
51
|
+
const createResult = await agentBay.create();
|
|
52
|
+
if (createResult.success) {
|
|
53
|
+
await createResult.session.oss.envInit('key_id', 'key_secret', 'token', 'oss-cn-hangzhou.aliyuncs.com', 'cn-hangzhou');
|
|
54
|
+
const result = await createResult.session.oss.download('my-bucket', 'my-folder/file.txt', '/path/to/save/file.txt');
|
|
55
|
+
console.log('Download success:', result.success);
|
|
56
|
+
await createResult.session.delete();
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
___
|
|
61
|
+
|
|
62
|
+
### downloadAnonymous
|
|
63
|
+
|
|
64
|
+
▸ **downloadAnonymous**(`url`, `path`): `Promise`\<`OSSDownloadResult`\>
|
|
65
|
+
|
|
66
|
+
Download a file from OSS using an anonymous URL.
|
|
67
|
+
Corresponds to Python's download_anonymous() method
|
|
68
|
+
|
|
69
|
+
#### Parameters
|
|
70
|
+
|
|
71
|
+
| Name | Type | Description |
|
|
72
|
+
| :------ | :------ | :------ |
|
|
73
|
+
| `url` | `string` | The anonymous download URL |
|
|
74
|
+
| `path` | `string` | The local file path to save the downloaded file |
|
|
75
|
+
|
|
76
|
+
#### Returns
|
|
77
|
+
|
|
78
|
+
`Promise`\<`OSSDownloadResult`\>
|
|
79
|
+
|
|
80
|
+
OSSDownloadResult with download result and requestId
|
|
81
|
+
|
|
82
|
+
**`Throws`**
|
|
83
|
+
|
|
84
|
+
APIError if the operation fails.
|
|
85
|
+
|
|
86
|
+
**`Example`**
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
90
|
+
const createResult = await agentBay.create();
|
|
91
|
+
if (createResult.success) {
|
|
92
|
+
const result = await createResult.session.oss.downloadAnonymous('https://example.com/file.txt', '/path/to/save/file.txt');
|
|
93
|
+
console.log('Anonymous download success:', result.success);
|
|
94
|
+
await createResult.session.delete();
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
___
|
|
99
|
+
|
|
100
|
+
### envInit
|
|
101
|
+
|
|
102
|
+
▸ **envInit**(`accessKeyId`, `accessKeySecret`, `securityToken`, `endpoint?`, `region?`): `Promise`\<`OSSClientResult`\>
|
|
103
|
+
|
|
104
|
+
Initialize OSS environment variables with the specified STS temporary credentials.
|
|
105
|
+
Corresponds to Python's env_init() method
|
|
106
|
+
|
|
107
|
+
#### Parameters
|
|
108
|
+
|
|
109
|
+
| Name | Type | Description |
|
|
110
|
+
| :------ | :------ | :------ |
|
|
111
|
+
| `accessKeyId` | `string` | The access key ID from STS temporary credentials |
|
|
112
|
+
| `accessKeySecret` | `string` | The access key secret from STS temporary credentials |
|
|
113
|
+
| `securityToken` | `string` | The security token from STS temporary credentials (required) |
|
|
114
|
+
| `endpoint?` | `string` | The OSS endpoint (optional) |
|
|
115
|
+
| `region?` | `string` | The OSS region (optional) |
|
|
116
|
+
|
|
117
|
+
#### Returns
|
|
118
|
+
|
|
119
|
+
`Promise`\<`OSSClientResult`\>
|
|
120
|
+
|
|
121
|
+
OSSClientResult with client configuration and requestId
|
|
122
|
+
|
|
123
|
+
**`Throws`**
|
|
124
|
+
|
|
125
|
+
APIError if the operation fails.
|
|
126
|
+
|
|
127
|
+
**`Example`**
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
131
|
+
const createResult = await agentBay.create();
|
|
132
|
+
if (createResult.success) {
|
|
133
|
+
const result = await createResult.session.oss.envInit('sts_key_id', 'sts_key_secret', 'sts_token', 'oss-cn-hangzhou.aliyuncs.com', 'cn-hangzhou');
|
|
134
|
+
console.log('OSS initialized:', result.success);
|
|
135
|
+
await createResult.session.delete();
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
___
|
|
140
|
+
|
|
141
|
+
### upload
|
|
142
|
+
|
|
143
|
+
▸ **upload**(`bucket`, `object`, `path`): `Promise`\<`OSSUploadResult`\>
|
|
144
|
+
|
|
145
|
+
Upload a file to OSS.
|
|
146
|
+
Corresponds to Python's upload() method
|
|
147
|
+
|
|
148
|
+
#### Parameters
|
|
149
|
+
|
|
150
|
+
| Name | Type | Description |
|
|
151
|
+
| :------ | :------ | :------ |
|
|
152
|
+
| `bucket` | `string` | The OSS bucket name |
|
|
153
|
+
| `object` | `string` | The OSS object key |
|
|
154
|
+
| `path` | `string` | The local file path to upload |
|
|
155
|
+
|
|
156
|
+
#### Returns
|
|
157
|
+
|
|
158
|
+
`Promise`\<`OSSUploadResult`\>
|
|
159
|
+
|
|
160
|
+
OSSUploadResult with upload result and requestId
|
|
161
|
+
|
|
162
|
+
**`Throws`**
|
|
163
|
+
|
|
164
|
+
APIError if the operation fails.
|
|
165
|
+
|
|
166
|
+
**`Example`**
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
170
|
+
const createResult = await agentBay.create();
|
|
171
|
+
if (createResult.success) {
|
|
172
|
+
await createResult.session.oss.envInit('key_id', 'key_secret', 'token', 'oss-cn-hangzhou.aliyuncs.com', 'cn-hangzhou');
|
|
173
|
+
const result = await createResult.session.oss.upload('my-bucket', 'my-folder/file.txt', '/path/to/local/file.txt');
|
|
174
|
+
console.log('Upload success:', result.success);
|
|
175
|
+
await createResult.session.delete();
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
___
|
|
180
|
+
|
|
181
|
+
### uploadAnonymous
|
|
182
|
+
|
|
183
|
+
▸ **uploadAnonymous**(`url`, `path`): `Promise`\<`OSSUploadResult`\>
|
|
184
|
+
|
|
185
|
+
Upload a file to OSS using an anonymous URL.
|
|
186
|
+
Corresponds to Python's upload_anonymous() method
|
|
187
|
+
|
|
188
|
+
#### Parameters
|
|
189
|
+
|
|
190
|
+
| Name | Type | Description |
|
|
191
|
+
| :------ | :------ | :------ |
|
|
192
|
+
| `url` | `string` | The anonymous upload URL |
|
|
193
|
+
| `path` | `string` | The local file path to upload |
|
|
194
|
+
|
|
195
|
+
#### Returns
|
|
196
|
+
|
|
197
|
+
`Promise`\<`OSSUploadResult`\>
|
|
198
|
+
|
|
199
|
+
OSSUploadResult with upload result and requestId
|
|
200
|
+
|
|
201
|
+
**`Throws`**
|
|
202
|
+
|
|
203
|
+
APIError if the operation fails.
|
|
204
|
+
|
|
205
|
+
**`Example`**
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
209
|
+
const createResult = await agentBay.create();
|
|
210
|
+
if (createResult.success) {
|
|
211
|
+
const result = await createResult.session.oss.uploadAnonymous('https://example.com/upload', '/path/to/local/file.txt');
|
|
212
|
+
console.log('Anonymous upload success:', result.success);
|
|
213
|
+
await createResult.session.delete();
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Related Resources
|
|
218
|
+
|
|
219
|
+
- [Session API Reference](../../common-features/basics/session.md)
|
|
220
|
+
- [FileSystem API Reference](../../common-features/basics/filesystem.md)
|
|
221
|
+
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Class: AgentBay
|
|
2
|
+
|
|
3
|
+
## 🚀 Related Tutorial
|
|
4
|
+
|
|
5
|
+
- [First Session Tutorial](../../../../../docs/quickstart/first-session.md) - Get started with creating your first AgentBay session
|
|
6
|
+
|
|
7
|
+
Main class for interacting with the AgentBay cloud runtime environment.
|
|
8
|
+
|
|
9
|
+
## Table of contents
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Properties
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Methods
|
|
16
|
+
|
|
17
|
+
- [create](#create)
|
|
18
|
+
- [delete](#delete)
|
|
19
|
+
- [get](#get)
|
|
20
|
+
- [list](#list)
|
|
21
|
+
|
|
22
|
+
## Properties
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
context: [`ContextService`](context.md)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Methods
|
|
30
|
+
|
|
31
|
+
### create
|
|
32
|
+
|
|
33
|
+
▸ **create**(`params?`): `Promise`\<`SessionResult`\>
|
|
34
|
+
|
|
35
|
+
Creates a new AgentBay session with specified configuration.
|
|
36
|
+
|
|
37
|
+
#### Parameters
|
|
38
|
+
|
|
39
|
+
| Name | Type | Description |
|
|
40
|
+
| :------ | :------ | :------ |
|
|
41
|
+
| `params` | ``CreateSessionParams`` | Configuration parameters for the session: - labels: Key-value pairs for session metadata - imageId: Custom image ID for the session environment - contextSync: Array of context synchronization configurations - browserContext: Browser-specific context configuration - isVpc: Whether to create a VPC session - policyId: Security policy ID - enableBrowserReplay: Enable browser session recording - extraConfigs: Additional configuration options - framework: Framework identifier for tracking |
|
|
42
|
+
|
|
43
|
+
#### Returns
|
|
44
|
+
|
|
45
|
+
`Promise`\<`SessionResult`\>
|
|
46
|
+
|
|
47
|
+
Promise resolving to SessionResult containing:
|
|
48
|
+
- success: Whether session creation succeeded
|
|
49
|
+
- session: Session object for interacting with the environment
|
|
50
|
+
- requestId: Unique identifier for this API request
|
|
51
|
+
- errorMessage: Error description if creation failed
|
|
52
|
+
|
|
53
|
+
**`Throws`**
|
|
54
|
+
|
|
55
|
+
Error if API call fails or authentication is invalid.
|
|
56
|
+
|
|
57
|
+
**`Example`**
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
61
|
+
const result = await agentBay.create({ labels: { project: 'demo' } });
|
|
62
|
+
if (result.success) {
|
|
63
|
+
await result.session.filesystem.readFile('/etc/hostname');
|
|
64
|
+
await result.session.delete();
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**`Remarks`**
|
|
69
|
+
|
|
70
|
+
**Behavior:**
|
|
71
|
+
- Creates a new isolated cloud runtime environment
|
|
72
|
+
- Automatically creates file transfer context if not provided
|
|
73
|
+
- Waits for context synchronization if contextSync is specified
|
|
74
|
+
- For VPC sessions, includes VPC-specific configuration
|
|
75
|
+
- Browser replay creates a separate recording context
|
|
76
|
+
|
|
77
|
+
**`See`**
|
|
78
|
+
|
|
79
|
+
[get](#get), [list](#list), [Session.delete](session.md#delete)
|
|
80
|
+
|
|
81
|
+
___
|
|
82
|
+
|
|
83
|
+
### delete
|
|
84
|
+
|
|
85
|
+
▸ **delete**(`session`, `syncContext?`): `Promise`\<``DeleteResult``\>
|
|
86
|
+
|
|
87
|
+
Delete a session by session object.
|
|
88
|
+
|
|
89
|
+
#### Parameters
|
|
90
|
+
|
|
91
|
+
| Name | Type | Default value | Description |
|
|
92
|
+
| :------ | :------ | :------ | :------ |
|
|
93
|
+
| `session` | [`Session`](session.md) | `undefined` | The session to delete. |
|
|
94
|
+
| `syncContext` | `boolean` | `false` | Whether to sync context data (trigger file uploads) before deleting the session. Defaults to false. |
|
|
95
|
+
|
|
96
|
+
#### Returns
|
|
97
|
+
|
|
98
|
+
`Promise`\<``DeleteResult``\>
|
|
99
|
+
|
|
100
|
+
DeleteResult indicating success or failure and request ID
|
|
101
|
+
|
|
102
|
+
**`Example`**
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
106
|
+
const result = await agentBay.create();
|
|
107
|
+
if (result.success) {
|
|
108
|
+
await agentBay.delete(result.session);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
___
|
|
113
|
+
|
|
114
|
+
### get
|
|
115
|
+
|
|
116
|
+
▸ **get**(`sessionId`): `Promise`\<`SessionResult`\>
|
|
117
|
+
|
|
118
|
+
Get a session by its ID.
|
|
119
|
+
|
|
120
|
+
This method retrieves a session by calling the GetSession API
|
|
121
|
+
and returns a SessionResult containing the Session object and request ID.
|
|
122
|
+
|
|
123
|
+
#### Parameters
|
|
124
|
+
|
|
125
|
+
| Name | Type | Description |
|
|
126
|
+
| :------ | :------ | :------ |
|
|
127
|
+
| `sessionId` | `string` | The ID of the session to retrieve |
|
|
128
|
+
|
|
129
|
+
#### Returns
|
|
130
|
+
|
|
131
|
+
`Promise`\<`SessionResult`\>
|
|
132
|
+
|
|
133
|
+
Promise resolving to SessionResult with the Session instance, request ID, and success status
|
|
134
|
+
|
|
135
|
+
**`Example`**
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
139
|
+
const createResult = await agentBay.create();
|
|
140
|
+
if (createResult.success) {
|
|
141
|
+
const result = await agentBay.get(createResult.session.sessionId);
|
|
142
|
+
await result.session?.filesystem.readFile('/etc/hostname');
|
|
143
|
+
await result.session?.delete();
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### list
|
|
148
|
+
|
|
149
|
+
▸ **list**(`labels?`, `page?`, `limit?`): `Promise`\<``SessionListResult``\>
|
|
150
|
+
|
|
151
|
+
Returns paginated list of session IDs filtered by labels.
|
|
152
|
+
|
|
153
|
+
#### Parameters
|
|
154
|
+
|
|
155
|
+
| Name | Type | Default value | Description |
|
|
156
|
+
| :------ | :------ | :------ | :------ |
|
|
157
|
+
| `labels` | `Record`\<`string`, `string`\> | `{}` | Optional labels to filter sessions (defaults to empty object) |
|
|
158
|
+
| `page?` | `number` | `undefined` | Optional page number for pagination (starting from 1, defaults to 1) |
|
|
159
|
+
| `limit` | `number` | `10` | Optional maximum number of items per page (defaults to 10) |
|
|
160
|
+
|
|
161
|
+
#### Returns
|
|
162
|
+
|
|
163
|
+
`Promise`\<``SessionListResult``\>
|
|
164
|
+
|
|
165
|
+
SessionListResult - Paginated list of session IDs that match the labels
|
|
166
|
+
|
|
167
|
+
**`Example`**
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const agentBay = new AgentBay({ apiKey: "your_api_key" });
|
|
171
|
+
const result = await agentBay.list({ project: "demo" }, 1, 10);
|
|
172
|
+
if (result.success) {
|
|
173
|
+
console.log(`Found ${result.sessionIds.length} sessions`);
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Related Resources
|
|
178
|
+
|
|
179
|
+
- [Session API Reference](session.md)
|
|
180
|
+
- [Context API Reference](context.md)
|
|
181
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Class: Command
|
|
2
|
+
|
|
3
|
+
## ⚡ Related Tutorial
|
|
4
|
+
|
|
5
|
+
- [Command Execution Guide](../../../../../docs/guides/common-features/basics/command-execution.md) - Learn how to execute commands in sessions
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The Command module provides methods for executing shell commands within a session in the AgentBay cloud environment.
|
|
10
|
+
It supports both synchronous command execution with configurable timeouts.
|
|
11
|
+
|
|
12
|
+
Handles command execution operations in the AgentBay cloud environment.
|
|
13
|
+
|
|
14
|
+
## Table of contents
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Methods
|
|
18
|
+
|
|
19
|
+
- [executeCommand](#executecommand)
|
|
20
|
+
|
|
21
|
+
## Methods
|
|
22
|
+
|
|
23
|
+
### executeCommand
|
|
24
|
+
|
|
25
|
+
▸ **executeCommand**(`command`, `timeoutMs?`): `Promise`\<`CommandResult`\>
|
|
26
|
+
|
|
27
|
+
Executes a shell command in the session environment.
|
|
28
|
+
|
|
29
|
+
#### Parameters
|
|
30
|
+
|
|
31
|
+
| Name | Type | Default value | Description |
|
|
32
|
+
| :------ | :------ | :------ | :------ |
|
|
33
|
+
| `command` | `string` | `undefined` | The shell command to execute. |
|
|
34
|
+
| `timeoutMs` | `number` | `1000` | Timeout in milliseconds. Defaults to 1000ms. |
|
|
35
|
+
|
|
36
|
+
#### Returns
|
|
37
|
+
|
|
38
|
+
`Promise`\<`CommandResult`\>
|
|
39
|
+
|
|
40
|
+
Promise resolving to CommandResult containing:
|
|
41
|
+
- success: Whether the command executed successfully
|
|
42
|
+
- output: Combined stdout and stderr output
|
|
43
|
+
- requestId: Unique identifier for this API request
|
|
44
|
+
- errorMessage: Error description if execution failed
|
|
45
|
+
|
|
46
|
+
**`Example`**
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
50
|
+
const result = await agentBay.create();
|
|
51
|
+
if (result.success) {
|
|
52
|
+
const cmdResult = await result.session.command.executeCommand('echo "Hello"', 3000);
|
|
53
|
+
console.log('Command output:', cmdResult.output);
|
|
54
|
+
await result.session.delete();
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**`Remarks`**
|
|
59
|
+
|
|
60
|
+
**Behavior:**
|
|
61
|
+
- Executes in a Linux shell environment
|
|
62
|
+
- Combines stdout and stderr in the output
|
|
63
|
+
- Default timeout is 1000ms (1 second)
|
|
64
|
+
- Command runs with session user permissions
|
|
65
|
+
|
|
66
|
+
**`See`**
|
|
67
|
+
|
|
68
|
+
[FileSystem.readFile](filesystem.md#readfile), [FileSystem.writeFile](filesystem.md#writefile)
|
|
69
|
+
|
|
70
|
+
## Best Practices
|
|
71
|
+
|
|
72
|
+
1. Always specify appropriate timeout values based on expected command duration
|
|
73
|
+
2. Handle command execution errors gracefully
|
|
74
|
+
3. Use absolute paths when referencing files in commands
|
|
75
|
+
4. Be aware that commands run with session user permissions
|
|
76
|
+
5. Clean up temporary files created by commands
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## Related Resources
|
|
80
|
+
|
|
81
|
+
- [Session API Reference](session.md)
|
|
82
|
+
- [FileSystem API Reference](filesystem.md)
|
|
83
|
+
|