test-wuying-agentbay-sdk 0.13.1-beta.20251224094729 → 0.13.1-beta.20251224103203
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.cjs +293 -160
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +83 -12
- package/dist/index.d.ts +83 -12
- package/dist/index.mjs +248 -115
- package/dist/index.mjs.map +1 -1
- package/docs/api/README.md +1 -0
- package/docs/api/common-features/advanced/agent.md +3 -4
- package/docs/api/common-features/advanced/browser-use-agent.md +42 -42
- package/docs/api/common-features/advanced/computer-use-agent.md +43 -43
- package/docs/api/common-features/advanced/mobile-use-agent.md +57 -71
- package/docs/api/common-features/basics/filesystem.md +91 -27
- package/docs/api/common-features/basics/logging.md +7 -0
- package/package.json +1 -1
package/docs/api/README.md
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
- [Agent Modules Guide](../../../../../docs/guides/common-features/advanced/agent-modules.md) - Learn about agent modules and custom agents
|
|
6
6
|
|
|
7
7
|
An Agent to manipulate applications to complete specific tasks.
|
|
8
|
-
According to the use scenary, The agent can
|
|
9
|
-
specialized for browser automation tasks,
|
|
10
|
-
specialized for multiple applications automation tasks
|
|
11
|
-
which is specialized for mobile device automation tasks.
|
|
8
|
+
According to the use scenary, The agent can a browser use agent which is
|
|
9
|
+
specialized for browser automation tasks, The agent also can be a computer
|
|
10
|
+
use agent which is specialized for multiple applications automation tasks.
|
|
12
11
|
|
|
13
12
|
## Table of contents
|
|
14
13
|
|
|
@@ -1,14 +1,45 @@
|
|
|
1
1
|
# Class: BrowserUseAgent
|
|
2
2
|
|
|
3
|
+
## Hierarchy
|
|
4
|
+
|
|
5
|
+
- `BaseTaskAgent`
|
|
6
|
+
|
|
7
|
+
↳ **`BrowserUseAgent`**
|
|
8
|
+
|
|
3
9
|
## Table of contents
|
|
4
10
|
|
|
5
11
|
|
|
12
|
+
### Properties
|
|
13
|
+
|
|
14
|
+
- [session](#session)
|
|
15
|
+
- [toolPrefix](#toolprefix)
|
|
16
|
+
|
|
6
17
|
### Methods
|
|
7
18
|
|
|
8
19
|
- [executeTask](#executetask)
|
|
9
20
|
- [initialize](#initialize)
|
|
10
21
|
- [terminateTask](#terminatetask)
|
|
11
22
|
|
|
23
|
+
## Properties
|
|
24
|
+
|
|
25
|
+
### session
|
|
26
|
+
|
|
27
|
+
• `Protected` **session**: ``McpSession``
|
|
28
|
+
|
|
29
|
+
#### Inherited from
|
|
30
|
+
|
|
31
|
+
BaseTaskAgent.session
|
|
32
|
+
|
|
33
|
+
___
|
|
34
|
+
|
|
35
|
+
### toolPrefix
|
|
36
|
+
|
|
37
|
+
• `Protected` **toolPrefix**: `string` = `'browser_use'`
|
|
38
|
+
|
|
39
|
+
#### Overrides
|
|
40
|
+
|
|
41
|
+
BaseTaskAgent.toolPrefix
|
|
42
|
+
|
|
12
43
|
## Methods
|
|
13
44
|
|
|
14
45
|
### executeTask
|
|
@@ -19,32 +50,18 @@ Execute a specific task described in human language.
|
|
|
19
50
|
|
|
20
51
|
#### Parameters
|
|
21
52
|
|
|
22
|
-
| Name | Type |
|
|
23
|
-
| :------ | :------ |
|
|
24
|
-
| `task` | `string` |
|
|
25
|
-
| `maxTryTimes` | `number` |
|
|
53
|
+
| Name | Type |
|
|
54
|
+
| :------ | :------ |
|
|
55
|
+
| `task` | `string` |
|
|
56
|
+
| `maxTryTimes` | `number` |
|
|
26
57
|
|
|
27
58
|
#### Returns
|
|
28
59
|
|
|
29
60
|
`Promise`\<``ExecutionResult``\>
|
|
30
61
|
|
|
31
|
-
|
|
32
|
-
error message if any.
|
|
62
|
+
#### Inherited from
|
|
33
63
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
38
|
-
const result = await agentBay.create({ imageId: 'linux_latest' });
|
|
39
|
-
if (result.success) {
|
|
40
|
-
const taskResult = await result.session.agent.browser.executeTask(
|
|
41
|
-
'Navigate to baidu and query the weather of Shanghai',
|
|
42
|
-
10
|
|
43
|
-
);
|
|
44
|
-
console.log(`Task status: ${taskResult.taskStatus}`);
|
|
45
|
-
await result.session.delete();
|
|
46
|
-
}
|
|
47
|
-
```
|
|
64
|
+
BaseTaskAgent.executeTask
|
|
48
65
|
|
|
49
66
|
### initialize
|
|
50
67
|
|
|
@@ -88,31 +105,14 @@ Terminate a task with a specified task ID.
|
|
|
88
105
|
|
|
89
106
|
#### Parameters
|
|
90
107
|
|
|
91
|
-
| Name | Type |
|
|
92
|
-
| :------ | :------ |
|
|
93
|
-
| `taskId` | `string` |
|
|
108
|
+
| Name | Type |
|
|
109
|
+
| :------ | :------ |
|
|
110
|
+
| `taskId` | `string` |
|
|
94
111
|
|
|
95
112
|
#### Returns
|
|
96
113
|
|
|
97
114
|
`Promise`\<``ExecutionResult``\>
|
|
98
115
|
|
|
99
|
-
|
|
100
|
-
error message if any.
|
|
101
|
-
|
|
102
|
-
**`Example`**
|
|
116
|
+
#### Inherited from
|
|
103
117
|
|
|
104
|
-
|
|
105
|
-
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
106
|
-
const result = await agentBay.create({ imageId: 'linux_latest' });
|
|
107
|
-
if (result.success) {
|
|
108
|
-
const taskResult = await result.session.agent.browser.executeTask(
|
|
109
|
-
'Navigate to baidu and query the weather of Shanghai',
|
|
110
|
-
10
|
|
111
|
-
);
|
|
112
|
-
const terminateResult = await result.session.agent.browser.terminateTask(
|
|
113
|
-
taskResult.taskId
|
|
114
|
-
);
|
|
115
|
-
console.log(`Terminated: ${terminateResult.taskStatus}`);
|
|
116
|
-
await result.session.delete();
|
|
117
|
-
}
|
|
118
|
-
```
|
|
118
|
+
BaseTaskAgent.terminateTask
|
|
@@ -2,14 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
An Agent to perform tasks on the computer.
|
|
4
4
|
|
|
5
|
+
## Hierarchy
|
|
6
|
+
|
|
7
|
+
- `BaseTaskAgent`
|
|
8
|
+
|
|
9
|
+
↳ **`ComputerUseAgent`**
|
|
10
|
+
|
|
5
11
|
## Table of contents
|
|
6
12
|
|
|
7
13
|
|
|
14
|
+
### Properties
|
|
15
|
+
|
|
16
|
+
- [session](#session)
|
|
17
|
+
- [toolPrefix](#toolprefix)
|
|
18
|
+
|
|
8
19
|
### Methods
|
|
9
20
|
|
|
10
21
|
- [executeTask](#executetask)
|
|
11
22
|
- [terminateTask](#terminatetask)
|
|
12
23
|
|
|
24
|
+
## Properties
|
|
25
|
+
|
|
26
|
+
### session
|
|
27
|
+
|
|
28
|
+
• `Protected` **session**: ``McpSession``
|
|
29
|
+
|
|
30
|
+
#### Inherited from
|
|
31
|
+
|
|
32
|
+
BaseTaskAgent.session
|
|
33
|
+
|
|
34
|
+
___
|
|
35
|
+
|
|
36
|
+
### toolPrefix
|
|
37
|
+
|
|
38
|
+
• `Protected` **toolPrefix**: `string` = `'flux'`
|
|
39
|
+
|
|
40
|
+
#### Overrides
|
|
41
|
+
|
|
42
|
+
BaseTaskAgent.toolPrefix
|
|
43
|
+
|
|
13
44
|
## Methods
|
|
14
45
|
|
|
15
46
|
### executeTask
|
|
@@ -20,32 +51,18 @@ Execute a specific task described in human language.
|
|
|
20
51
|
|
|
21
52
|
#### Parameters
|
|
22
53
|
|
|
23
|
-
| Name | Type |
|
|
24
|
-
| :------ | :------ |
|
|
25
|
-
| `task` | `string` |
|
|
26
|
-
| `maxTryTimes` | `number` |
|
|
54
|
+
| Name | Type |
|
|
55
|
+
| :------ | :------ |
|
|
56
|
+
| `task` | `string` |
|
|
57
|
+
| `maxTryTimes` | `number` |
|
|
27
58
|
|
|
28
59
|
#### Returns
|
|
29
60
|
|
|
30
61
|
`Promise`\<``ExecutionResult``\>
|
|
31
62
|
|
|
32
|
-
|
|
33
|
-
message if any.
|
|
63
|
+
#### Inherited from
|
|
34
64
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
39
|
-
const result = await agentBay.create({ imageId: 'windows_latest' });
|
|
40
|
-
if (result.success) {
|
|
41
|
-
const taskResult = await result.session.agent.computer.executeTask(
|
|
42
|
-
'Open notepad',
|
|
43
|
-
10
|
|
44
|
-
);
|
|
45
|
-
console.log(`Task status: ${taskResult.taskStatus}`);
|
|
46
|
-
await result.session.delete();
|
|
47
|
-
}
|
|
48
|
-
```
|
|
65
|
+
BaseTaskAgent.executeTask
|
|
49
66
|
|
|
50
67
|
### terminateTask
|
|
51
68
|
|
|
@@ -55,31 +72,14 @@ Terminate a task with a specified task ID.
|
|
|
55
72
|
|
|
56
73
|
#### Parameters
|
|
57
74
|
|
|
58
|
-
| Name | Type |
|
|
59
|
-
| :------ | :------ |
|
|
60
|
-
| `taskId` | `string` |
|
|
75
|
+
| Name | Type |
|
|
76
|
+
| :------ | :------ |
|
|
77
|
+
| `taskId` | `string` |
|
|
61
78
|
|
|
62
79
|
#### Returns
|
|
63
80
|
|
|
64
81
|
`Promise`\<``ExecutionResult``\>
|
|
65
82
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
**`Example`**
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
73
|
-
const result = await agentBay.create({ imageId: 'windows_latest' });
|
|
74
|
-
if (result.success) {
|
|
75
|
-
const taskResult = await result.session.agent.computer.executeTask(
|
|
76
|
-
'Open notepad',
|
|
77
|
-
5
|
|
78
|
-
);
|
|
79
|
-
const terminateResult = await result.session.agent.computer.terminateTask(
|
|
80
|
-
taskResult.taskId
|
|
81
|
-
);
|
|
82
|
-
console.log(`Terminated: ${terminateResult.taskStatus}`);
|
|
83
|
-
await result.session.delete();
|
|
84
|
-
}
|
|
85
|
-
```
|
|
83
|
+
#### Inherited from
|
|
84
|
+
|
|
85
|
+
BaseTaskAgent.terminateTask
|
|
@@ -2,37 +2,70 @@
|
|
|
2
2
|
|
|
3
3
|
An Agent to perform tasks on mobile devices.
|
|
4
4
|
|
|
5
|
+
## Hierarchy
|
|
6
|
+
|
|
7
|
+
- `BaseTaskAgent`
|
|
8
|
+
|
|
9
|
+
↳ **`MobileUseAgent`**
|
|
10
|
+
|
|
5
11
|
## Table of contents
|
|
6
12
|
|
|
7
13
|
|
|
14
|
+
### Properties
|
|
15
|
+
|
|
16
|
+
- [session](#session)
|
|
17
|
+
- [toolPrefix](#toolprefix)
|
|
18
|
+
|
|
8
19
|
### Methods
|
|
9
20
|
|
|
10
21
|
- [executeTask](#executetask)
|
|
11
22
|
- [executeTaskAndWait](#executetaskandwait)
|
|
12
|
-
- [getTaskStatus](#gettaskstatus)
|
|
13
23
|
- [terminateTask](#terminatetask)
|
|
14
24
|
|
|
25
|
+
## Properties
|
|
26
|
+
|
|
27
|
+
### session
|
|
28
|
+
|
|
29
|
+
• `Protected` **session**: ``McpSession``
|
|
30
|
+
|
|
31
|
+
#### Inherited from
|
|
32
|
+
|
|
33
|
+
BaseTaskAgent.session
|
|
34
|
+
|
|
35
|
+
___
|
|
36
|
+
|
|
37
|
+
### toolPrefix
|
|
38
|
+
|
|
39
|
+
• `Protected` **toolPrefix**: `string` = `''`
|
|
40
|
+
|
|
41
|
+
#### Overrides
|
|
42
|
+
|
|
43
|
+
BaseTaskAgent.toolPrefix
|
|
44
|
+
|
|
15
45
|
## Methods
|
|
16
46
|
|
|
17
47
|
### executeTask
|
|
18
48
|
|
|
19
49
|
▸ **executeTask**(`task`, `maxSteps?`, `maxStepRetries?`): `Promise`\<``ExecutionResult``\>
|
|
20
50
|
|
|
21
|
-
Execute a task in human language without waiting for completion
|
|
51
|
+
Execute a task in human language without waiting for completion
|
|
52
|
+
(non-blocking). This is a fire-and-return interface that immediately
|
|
53
|
+
provides a task ID. Call getTaskStatus to check the task status.
|
|
22
54
|
|
|
23
55
|
#### Parameters
|
|
24
56
|
|
|
25
57
|
| Name | Type | Default value | Description |
|
|
26
58
|
| :------ | :------ | :------ | :------ |
|
|
27
|
-
| `task` | `string` |
|
|
28
|
-
| `maxSteps` | `number` | `50` | Maximum number of steps (clicks/swipes/etc.) allowed. Used to prevent infinite loops or excessive resource consumption. |
|
|
29
|
-
| `maxStepRetries` | `number` | `3` | Maximum retry times for MCP tool call failures at SDK level. Used to retry when callMcpTool fails (e.g., network errors, timeouts). |
|
|
59
|
+
| `task` | `string` | `undefined` | Task description in human language. |
|
|
60
|
+
| `maxSteps` | `number` | `50` | Maximum number of steps (clicks/swipes/etc.) allowed. Used to prevent infinite loops or excessive resource consumption. Default is 50. |
|
|
61
|
+
| `maxStepRetries` | `number` | `3` | Maximum retry times for MCP tool call failures at SDK level. Used to retry when callMcpTool fails (e.g., network errors, timeouts). Default is 3. |
|
|
30
62
|
|
|
31
63
|
#### Returns
|
|
32
64
|
|
|
33
65
|
`Promise`\<``ExecutionResult``\>
|
|
34
66
|
|
|
35
|
-
ExecutionResult containing success status, task ID, task status,
|
|
67
|
+
ExecutionResult containing success status, task ID, task status,
|
|
68
|
+
and error message if any.
|
|
36
69
|
|
|
37
70
|
**`Example`**
|
|
38
71
|
|
|
@@ -48,28 +81,36 @@ if (result.success) {
|
|
|
48
81
|
}
|
|
49
82
|
```
|
|
50
83
|
|
|
84
|
+
#### Overrides
|
|
85
|
+
|
|
86
|
+
BaseTaskAgent.executeTask
|
|
87
|
+
|
|
51
88
|
___
|
|
52
89
|
|
|
53
90
|
### executeTaskAndWait
|
|
54
91
|
|
|
55
92
|
▸ **executeTaskAndWait**(`task`, `maxSteps?`, `maxStepRetries?`, `maxTryTimes?`): `Promise`\<``ExecutionResult``\>
|
|
56
93
|
|
|
57
|
-
Execute a specific task described in human language synchronously.
|
|
94
|
+
Execute a specific task described in human language synchronously.
|
|
95
|
+
This is a synchronous interface that blocks until the task is completed or
|
|
96
|
+
an error occurs, or timeout happens. The default polling interval is
|
|
97
|
+
3 seconds.
|
|
58
98
|
|
|
59
99
|
#### Parameters
|
|
60
100
|
|
|
61
101
|
| Name | Type | Default value | Description |
|
|
62
102
|
| :------ | :------ | :------ | :------ |
|
|
63
|
-
| `task` | `string` |
|
|
64
|
-
| `maxSteps` | `number` | `50` | Maximum number of steps (clicks/swipes/etc.) allowed. Used to prevent infinite loops or excessive resource consumption. |
|
|
65
|
-
| `maxStepRetries` | `number` | `3` | Maximum retry times for MCP tool call failures at SDK level. Used to retry when callMcpTool fails (e.g., network errors, timeouts). |
|
|
103
|
+
| `task` | `string` | `undefined` | Task description in human language. |
|
|
104
|
+
| `maxSteps` | `number` | `50` | Maximum number of steps (clicks/swipes/etc.) allowed. Used to prevent infinite loops or excessive resource consumption. Default is 50. |
|
|
105
|
+
| `maxStepRetries` | `number` | `3` | Maximum retry times for MCP tool call failures at SDK level. Used to retry when callMcpTool fails (e.g., network errors, timeouts). Default is 3. |
|
|
66
106
|
| `maxTryTimes` | `number` | `300` | Maximum number of polling attempts (each 3 seconds). Used to control how long to wait for task completion. Default is 300 (about 15 minutes). |
|
|
67
107
|
|
|
68
108
|
#### Returns
|
|
69
109
|
|
|
70
110
|
`Promise`\<``ExecutionResult``\>
|
|
71
111
|
|
|
72
|
-
ExecutionResult containing success status, task ID, task status,
|
|
112
|
+
ExecutionResult containing success status, task ID, task status,
|
|
113
|
+
and error message if any.
|
|
73
114
|
|
|
74
115
|
**`Example`**
|
|
75
116
|
|
|
@@ -85,45 +126,6 @@ if (result.success) {
|
|
|
85
126
|
}
|
|
86
127
|
```
|
|
87
128
|
|
|
88
|
-
___
|
|
89
|
-
|
|
90
|
-
### getTaskStatus
|
|
91
|
-
|
|
92
|
-
▸ **getTaskStatus**(`taskId`): `Promise`\<``QueryResult``\>
|
|
93
|
-
|
|
94
|
-
Get the status of the task with the given task ID.
|
|
95
|
-
|
|
96
|
-
#### Parameters
|
|
97
|
-
|
|
98
|
-
| Name | Type | Description |
|
|
99
|
-
| :------ | :------ | :------ |
|
|
100
|
-
| `taskId` | `string` | The ID of the task. |
|
|
101
|
-
|
|
102
|
-
#### Returns
|
|
103
|
-
|
|
104
|
-
`Promise`\<``QueryResult``\>
|
|
105
|
-
|
|
106
|
-
QueryResult containing task status, task action, and task product.
|
|
107
|
-
|
|
108
|
-
**`Example`**
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
112
|
-
const result = await agentBay.create({ imageId: 'mobile_latest' });
|
|
113
|
-
if (result.success) {
|
|
114
|
-
const execResult = await result.session.agent.mobile.executeTask(
|
|
115
|
-
'Open WeChat app', 100, 5
|
|
116
|
-
);
|
|
117
|
-
const statusResult = await result.session.agent.mobile.getTaskStatus(
|
|
118
|
-
execResult.taskId
|
|
119
|
-
);
|
|
120
|
-
console.log(`Task status: ${statusResult.taskStatus}`);
|
|
121
|
-
await result.session.delete();
|
|
122
|
-
}
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
___
|
|
126
|
-
|
|
127
129
|
### terminateTask
|
|
128
130
|
|
|
129
131
|
▸ **terminateTask**(`taskId`): `Promise`\<``ExecutionResult``\>
|
|
@@ -132,30 +134,14 @@ Terminate a task with a specified task ID.
|
|
|
132
134
|
|
|
133
135
|
#### Parameters
|
|
134
136
|
|
|
135
|
-
| Name | Type |
|
|
136
|
-
| :------ | :------ |
|
|
137
|
-
| `taskId` | `string` |
|
|
137
|
+
| Name | Type |
|
|
138
|
+
| :------ | :------ |
|
|
139
|
+
| `taskId` | `string` |
|
|
138
140
|
|
|
139
141
|
#### Returns
|
|
140
142
|
|
|
141
143
|
`Promise`\<``ExecutionResult``\>
|
|
142
144
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
**`Example`**
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
149
|
-
const result = await agentBay.create({ imageId: 'mobile_latest' });
|
|
150
|
-
if (result.success) {
|
|
151
|
-
const taskResult = await result.session.agent.mobile.executeTask(
|
|
152
|
-
'Open WeChat app', 100, 5
|
|
153
|
-
);
|
|
154
|
-
const terminateResult = await result.session.agent.mobile.terminateTask(
|
|
155
|
-
taskResult.taskId
|
|
156
|
-
);
|
|
157
|
-
console.log(`Terminated: ${terminateResult.taskStatus}`);
|
|
158
|
-
await result.session.delete();
|
|
159
|
-
}
|
|
160
|
-
```
|
|
145
|
+
#### Inherited from
|
|
161
146
|
|
|
147
|
+
BaseTaskAgent.terminateTask
|
|
@@ -197,7 +197,7 @@ if (result.success) {
|
|
|
197
197
|
|
|
198
198
|
### list
|
|
199
199
|
|
|
200
|
-
▸ **list**(`path`): `Promise
|
|
200
|
+
▸ **list**(`path`): `Promise`\<``DirectoryListResult``\>
|
|
201
201
|
|
|
202
202
|
Alias of listDirectory().
|
|
203
203
|
|
|
@@ -209,13 +209,13 @@ Alias of listDirectory().
|
|
|
209
209
|
|
|
210
210
|
#### Returns
|
|
211
211
|
|
|
212
|
-
`Promise
|
|
212
|
+
`Promise`\<``DirectoryListResult``\>
|
|
213
213
|
|
|
214
214
|
___
|
|
215
215
|
|
|
216
216
|
### listDirectory
|
|
217
217
|
|
|
218
|
-
▸ **listDirectory**(`path`): `Promise
|
|
218
|
+
▸ **listDirectory**(`path`): `Promise`\<``DirectoryListResult``\>
|
|
219
219
|
|
|
220
220
|
Lists the contents of a directory.
|
|
221
221
|
|
|
@@ -227,7 +227,7 @@ Lists the contents of a directory.
|
|
|
227
227
|
|
|
228
228
|
#### Returns
|
|
229
229
|
|
|
230
|
-
`Promise
|
|
230
|
+
`Promise`\<``DirectoryListResult``\>
|
|
231
231
|
|
|
232
232
|
Promise resolving to DirectoryListResult containing array of entries.
|
|
233
233
|
|
|
@@ -263,7 +263,7 @@ ___
|
|
|
263
263
|
|
|
264
264
|
### ls
|
|
265
265
|
|
|
266
|
-
▸ **ls**(`path`): `Promise
|
|
266
|
+
▸ **ls**(`path`): `Promise`\<``DirectoryListResult``\>
|
|
267
267
|
|
|
268
268
|
Alias of listDirectory().
|
|
269
269
|
|
|
@@ -275,7 +275,7 @@ Alias of listDirectory().
|
|
|
275
275
|
|
|
276
276
|
#### Returns
|
|
277
277
|
|
|
278
|
-
`Promise
|
|
278
|
+
`Promise`\<``DirectoryListResult``\>
|
|
279
279
|
|
|
280
280
|
___
|
|
281
281
|
|
|
@@ -316,7 +316,7 @@ ___
|
|
|
316
316
|
|
|
317
317
|
### read
|
|
318
318
|
|
|
319
|
-
▸ **read**(`path`): `Promise
|
|
319
|
+
▸ **read**(`path`): `Promise`\<``FileContentResult``\>
|
|
320
320
|
|
|
321
321
|
Alias of readFile().
|
|
322
322
|
|
|
@@ -328,15 +328,15 @@ Alias of readFile().
|
|
|
328
328
|
|
|
329
329
|
#### Returns
|
|
330
330
|
|
|
331
|
-
`Promise
|
|
331
|
+
`Promise`\<``FileContentResult``\>
|
|
332
332
|
|
|
333
333
|
___
|
|
334
334
|
|
|
335
335
|
### readFile
|
|
336
336
|
|
|
337
|
-
▸ **readFile**(`path`): `Promise
|
|
337
|
+
▸ **readFile**(`path`): `Promise`\<``FileContentResult``\>
|
|
338
338
|
|
|
339
|
-
Reads the entire content of a file.
|
|
339
|
+
Reads the entire content of a file (text format, default).
|
|
340
340
|
|
|
341
341
|
#### Parameters
|
|
342
342
|
|
|
@@ -346,7 +346,7 @@ Reads the entire content of a file.
|
|
|
346
346
|
|
|
347
347
|
#### Returns
|
|
348
348
|
|
|
349
|
-
`Promise
|
|
349
|
+
`Promise`\<``FileContentResult``\>
|
|
350
350
|
|
|
351
351
|
Promise resolving to FileContentResult containing:
|
|
352
352
|
- success: Whether the read operation succeeded
|
|
@@ -354,10 +354,6 @@ Promise resolving to FileContentResult containing:
|
|
|
354
354
|
- requestId: Unique identifier for this API request
|
|
355
355
|
- errorMessage: Error description if read failed
|
|
356
356
|
|
|
357
|
-
**`Throws`**
|
|
358
|
-
|
|
359
|
-
Error if the API call fails.
|
|
360
|
-
|
|
361
357
|
**`Example`**
|
|
362
358
|
|
|
363
359
|
```typescript
|
|
@@ -369,11 +365,83 @@ const result = await agentBay.create();
|
|
|
369
365
|
if (result.success) {
|
|
370
366
|
const session = result.session;
|
|
371
367
|
|
|
372
|
-
// Read a text file
|
|
368
|
+
// Read a text file (default)
|
|
373
369
|
const fileResult = await session.fileSystem.readFile('/etc/hostname');
|
|
374
370
|
if (fileResult.success) {
|
|
375
371
|
console.log(`Content: ${fileResult.content}`);
|
|
376
|
-
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
await session.delete();
|
|
375
|
+
}
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
▸ **readFile**(`path`, `opts`): `Promise`\<``FileContentResult``\>
|
|
379
|
+
|
|
380
|
+
Reads the entire content of a file with explicit text format.
|
|
381
|
+
|
|
382
|
+
#### Parameters
|
|
383
|
+
|
|
384
|
+
| Name | Type | Description |
|
|
385
|
+
| :------ | :------ | :------ |
|
|
386
|
+
| `path` | `string` | Absolute path to the file to read. |
|
|
387
|
+
| `opts` | `Object` | Options object with format set to "text". |
|
|
388
|
+
| `opts.format` | ``"text"`` | - |
|
|
389
|
+
|
|
390
|
+
#### Returns
|
|
391
|
+
|
|
392
|
+
`Promise`\<``FileContentResult``\>
|
|
393
|
+
|
|
394
|
+
Promise resolving to FileContentResult containing:
|
|
395
|
+
- success: Whether the read operation succeeded
|
|
396
|
+
- content: String content of the file
|
|
397
|
+
- requestId: Unique identifier for this API request
|
|
398
|
+
- errorMessage: Error description if read failed
|
|
399
|
+
|
|
400
|
+
**`Example`**
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
const fileResult = await session.fileSystem.readFile('/tmp/test.txt', { format: 'text' });
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
▸ **readFile**(`path`, `opts`): `Promise`\<``BinaryFileContentResult``\>
|
|
407
|
+
|
|
408
|
+
Reads the entire content of a file in binary format.
|
|
409
|
+
|
|
410
|
+
#### Parameters
|
|
411
|
+
|
|
412
|
+
| Name | Type | Description |
|
|
413
|
+
| :------ | :------ | :------ |
|
|
414
|
+
| `path` | `string` | Absolute path to the file to read. |
|
|
415
|
+
| `opts` | `Object` | Options object with format set to "bytes". |
|
|
416
|
+
| `opts.format` | ``"bytes"`` | - |
|
|
417
|
+
|
|
418
|
+
#### Returns
|
|
419
|
+
|
|
420
|
+
`Promise`\<``BinaryFileContentResult``\>
|
|
421
|
+
|
|
422
|
+
Promise resolving to BinaryFileContentResult containing:
|
|
423
|
+
- success: Whether the read operation succeeded
|
|
424
|
+
- content: Uint8Array binary content of the file
|
|
425
|
+
- requestId: Unique identifier for this API request
|
|
426
|
+
- errorMessage: Error description if read failed
|
|
427
|
+
- contentType: Optional MIME type of the file
|
|
428
|
+
- size: Optional size of the file in bytes
|
|
429
|
+
|
|
430
|
+
**`Example`**
|
|
431
|
+
|
|
432
|
+
```typescript
|
|
433
|
+
import { AgentBay } from 'wuying-agentbay-sdk';
|
|
434
|
+
|
|
435
|
+
const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
436
|
+
const result = await agentBay.create();
|
|
437
|
+
|
|
438
|
+
if (result.success) {
|
|
439
|
+
const session = result.session;
|
|
440
|
+
|
|
441
|
+
// Read a binary file
|
|
442
|
+
const binaryResult = await session.fileSystem.readFile('/tmp/image.png', { format: 'bytes' });
|
|
443
|
+
if (binaryResult.success) {
|
|
444
|
+
console.log(`File size: ${binaryResult.content.length} bytes`);
|
|
377
445
|
}
|
|
378
446
|
|
|
379
447
|
await session.delete();
|
|
@@ -384,19 +452,15 @@ if (result.success) {
|
|
|
384
452
|
|
|
385
453
|
**Behavior:**
|
|
386
454
|
- Automatically handles large files by reading in 60KB chunks
|
|
387
|
-
- Returns empty
|
|
455
|
+
- Returns empty Uint8Array for empty files
|
|
388
456
|
- Fails if path is a directory or doesn't exist
|
|
389
|
-
- Content is returned as
|
|
390
|
-
|
|
391
|
-
**`See`**
|
|
392
|
-
|
|
393
|
-
[writeFile](#writefile), [listDirectory](#listdirectory)
|
|
457
|
+
- Content is returned as Uint8Array (backend uses base64 encoding internally)
|
|
394
458
|
|
|
395
459
|
___
|
|
396
460
|
|
|
397
461
|
### readMultipleFiles
|
|
398
462
|
|
|
399
|
-
▸ **readMultipleFiles**(`paths`): `Promise
|
|
463
|
+
▸ **readMultipleFiles**(`paths`): `Promise`\<``MultipleFileContentResult``\>
|
|
400
464
|
|
|
401
465
|
Reads the content of multiple files.
|
|
402
466
|
Corresponds to Python's read_multiple_files() method
|
|
@@ -409,7 +473,7 @@ Corresponds to Python's read_multiple_files() method
|
|
|
409
473
|
|
|
410
474
|
#### Returns
|
|
411
475
|
|
|
412
|
-
`Promise
|
|
476
|
+
`Promise`\<``MultipleFileContentResult``\>
|
|
413
477
|
|
|
414
478
|
MultipleFileContentResult with file contents and requestId
|
|
415
479
|
|
|
@@ -467,7 +531,7 @@ ___
|
|
|
467
531
|
|
|
468
532
|
### searchFiles
|
|
469
533
|
|
|
470
|
-
▸ **searchFiles**(`path`, `pattern`, `excludePatterns?`): `Promise
|
|
534
|
+
▸ **searchFiles**(`path`, `pattern`, `excludePatterns?`): `Promise`\<``FileSearchResult``\>
|
|
471
535
|
|
|
472
536
|
Searches for files in a directory that match a wildcard pattern.
|
|
473
537
|
Corresponds to Python's search_files() method
|
|
@@ -482,7 +546,7 @@ Corresponds to Python's search_files() method
|
|
|
482
546
|
|
|
483
547
|
#### Returns
|
|
484
548
|
|
|
485
|
-
`Promise
|
|
549
|
+
`Promise`\<``FileSearchResult``\>
|
|
486
550
|
|
|
487
551
|
FileSearchResult with search results and requestId
|
|
488
552
|
|