wuying-agentbay-sdk 0.10.2 → 0.12.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.
Files changed (108) hide show
  1. package/dist/chunk-BVWUCG4J.mjs +3402 -0
  2. package/dist/chunk-BVWUCG4J.mjs.map +1 -0
  3. package/dist/chunk-SL5GCAQE.cjs +3393 -0
  4. package/dist/chunk-SL5GCAQE.cjs.map +1 -0
  5. package/dist/index.cjs +4623 -3978
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.mts +3934 -1964
  8. package/dist/index.d.ts +3934 -1964
  9. package/dist/index.mjs +4601 -3956
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/key-normalizer-AF7APGQZ.cjs +136 -0
  12. package/dist/key-normalizer-AF7APGQZ.cjs.map +1 -0
  13. package/dist/key-normalizer-QDBRLFHF.mjs +145 -0
  14. package/dist/key-normalizer-QDBRLFHF.mjs.map +1 -0
  15. package/dist/model-CNCGFWJH.cjs +200 -0
  16. package/dist/model-CNCGFWJH.cjs.map +1 -0
  17. package/dist/model-LGWQJWKQ.mjs +209 -0
  18. package/docs/api/README.md +26 -0
  19. package/docs/api/browser-use/browser.md +177 -0
  20. package/docs/api/browser-use/extension.md +284 -0
  21. package/docs/api/codespace/code.md +77 -0
  22. package/docs/api/common-features/advanced/agent.md +84 -0
  23. package/docs/api/common-features/advanced/oss.md +221 -0
  24. package/docs/api/common-features/basics/agentbay.md +277 -0
  25. package/docs/api/common-features/basics/command.md +83 -0
  26. package/docs/api/common-features/basics/context-manager.md +149 -0
  27. package/docs/api/common-features/basics/context-sync.md +51 -0
  28. package/docs/api/common-features/basics/context.md +348 -0
  29. package/docs/api/common-features/basics/filesystem.md +499 -0
  30. package/docs/api/common-features/basics/logging.md +77 -0
  31. package/docs/api/common-features/basics/session.md +542 -0
  32. package/docs/api/computer-use/computer.md +786 -0
  33. package/docs/api/mobile-use/mobile.md +395 -0
  34. package/docs/examples/README.md +332 -0
  35. package/docs/examples/basic-usage.ts +86 -0
  36. package/docs/examples/browser-use/browser/README.md +356 -0
  37. package/docs/examples/browser-use/browser/basic-usage.ts +136 -0
  38. package/docs/examples/browser-use/browser/browser-command-args.ts +117 -0
  39. package/docs/examples/browser-use/browser/browser-context-cookie-persistence.ts +348 -0
  40. package/docs/examples/browser-use/browser/browser-fingerprint-basic-usage.ts +121 -0
  41. package/docs/examples/browser-use/browser/browser-fingerprint-construct.ts +114 -0
  42. package/docs/examples/browser-use/browser/browser-fingerprint-local-sync.ts +98 -0
  43. package/docs/examples/browser-use/browser/browser-fingerprint-persistence.ts +242 -0
  44. package/docs/examples/browser-use/browser/browser-proxies.ts +149 -0
  45. package/docs/examples/browser-use/browser/browser-type-example.ts +266 -0
  46. package/docs/examples/browser-use/browser/browser-viewport.ts +129 -0
  47. package/docs/examples/browser-use/browser/call_for_user_jd.ts +184 -0
  48. package/docs/examples/browser-use/browser/captcha_tongcheng.ts +151 -0
  49. package/docs/examples/browser-use/browser/run-2048.ts +209 -0
  50. package/docs/examples/browser-use/browser/run-sudoku.ts +150 -0
  51. package/docs/examples/browser-use/browser/screenshot-example.ts +132 -0
  52. package/docs/examples/browser-use/extension-example/README.md +252 -0
  53. package/docs/examples/browser-use/extension-example/extension-example.ts +381 -0
  54. package/docs/examples/codespace/automation/automation-example.ts +322 -0
  55. package/docs/examples/common-features/advanced/agent-module-example/README.md +40 -0
  56. package/docs/examples/common-features/advanced/agent-module-example.ts +66 -0
  57. package/docs/examples/common-features/advanced/archive-upload-mode-example/README.md +212 -0
  58. package/docs/examples/common-features/advanced/archive-upload-mode-example/archive-upload-mode-example.ts +213 -0
  59. package/docs/examples/common-features/advanced/vpc-session-example/README.md +47 -0
  60. package/docs/examples/common-features/advanced/vpc-session-example.ts +106 -0
  61. package/docs/examples/common-features/basics/archive-upload-mode-example/README.md +236 -0
  62. package/docs/examples/common-features/basics/archive-upload-mode-example/main.ts +236 -0
  63. package/docs/examples/common-features/basics/command-example/README.md +47 -0
  64. package/docs/examples/common-features/basics/command-example/command-example.ts +153 -0
  65. package/docs/examples/common-features/basics/context-management/README.md +55 -0
  66. package/docs/examples/common-features/basics/context-management/context-management.ts +140 -0
  67. package/docs/examples/common-features/basics/data-persistence/README.md +129 -0
  68. package/docs/examples/common-features/basics/data-persistence/context-sync-demo.md +144 -0
  69. package/docs/examples/common-features/basics/data-persistence/context-sync-demo.ts +275 -0
  70. package/docs/examples/common-features/basics/data-persistence/data-persistence.ts +259 -0
  71. package/docs/examples/common-features/basics/data-persistence/recycle-policy-example.ts +294 -0
  72. package/docs/examples/common-features/basics/filesystem-example/README.md +57 -0
  73. package/docs/examples/common-features/basics/filesystem-example/filesystem-example.ts +164 -0
  74. package/docs/examples/common-features/basics/filesystem-example/filesystem-filetransfer-example.ts +153 -0
  75. package/docs/examples/common-features/basics/filesystem-example/watch-directory-example.ts +168 -0
  76. package/docs/examples/common-features/basics/get/README.md +136 -0
  77. package/docs/examples/common-features/basics/get/main.ts +79 -0
  78. package/docs/examples/common-features/basics/list_sessions/README.md +54 -0
  79. package/docs/examples/common-features/basics/list_sessions/main.ts +258 -0
  80. package/docs/examples/common-features/basics/mcp_tool_direct_call/README.md +142 -0
  81. package/docs/examples/common-features/basics/mcp_tool_direct_call/main.ts +135 -0
  82. package/docs/examples/common-features/basics/session-creation/README.md +28 -0
  83. package/docs/examples/common-features/basics/session-creation/session-creation.ts +295 -0
  84. package/docs/examples/common-features/basics/session-pause-resume/README.md +53 -0
  85. package/docs/examples/common-features/basics/session-pause-resume/session-pause-resume.ts +237 -0
  86. package/docs/examples/mobile-use/mobile-get-adb-url/README.md +92 -0
  87. package/docs/examples/mobile-use/mobile-get-adb-url/index.ts +80 -0
  88. package/docs/examples/mobile-use/mobile-get-adb-url/package-lock.json +279 -0
  89. package/docs/examples/mobile-use/mobile-get-adb-url/package.json +18 -0
  90. package/docs/examples/mobile-use/mobile-simulate-basic-usage.ts +202 -0
  91. package/docs/examples/mobile-use/mobile-simulate-with-ctx.ts +170 -0
  92. package/package.json +19 -12
  93. package/dist/application-KZWXH46T.mjs +0 -17
  94. package/dist/application-LMA7KSRH.cjs +0 -8
  95. package/dist/application-LMA7KSRH.cjs.map +0 -1
  96. package/dist/chunk-BQNGKBQF.mjs +0 -386
  97. package/dist/chunk-BQNGKBQF.mjs.map +0 -1
  98. package/dist/chunk-IOVGAAJL.cjs +0 -558
  99. package/dist/chunk-IOVGAAJL.cjs.map +0 -1
  100. package/dist/chunk-UF2TC2R4.mjs +0 -567
  101. package/dist/chunk-UF2TC2R4.mjs.map +0 -1
  102. package/dist/chunk-X6MS7Z5L.cjs +0 -377
  103. package/dist/chunk-X6MS7Z5L.cjs.map +0 -1
  104. package/dist/window-DH37ZDD5.mjs +0 -17
  105. package/dist/window-DH37ZDD5.mjs.map +0 -1
  106. package/dist/window-U7N3H735.cjs +0 -8
  107. package/dist/window-U7N3H735.cjs.map +0 -1
  108. /package/dist/{application-KZWXH46T.mjs.map → model-LGWQJWKQ.mjs.map} +0 -0
@@ -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
+
@@ -0,0 +1,149 @@
1
+ # Class: ContextManager
2
+
3
+ ## 🗂️ Related Tutorial
4
+
5
+ - [Data Persistence Guide](../../../../../docs/guides/common-features/basics/data-persistence.md) - Learn about context management and data persistence
6
+
7
+ ## Table of contents
8
+
9
+
10
+ ### Methods
11
+
12
+ - [info](#info)
13
+ - [infoWithParams](#infowithparams)
14
+ - [sync](#sync)
15
+
16
+ ## Methods
17
+
18
+ ### info
19
+
20
+ ▸ **info**(): `Promise`\<``ContextInfoResult``\>
21
+
22
+ Gets information about context synchronization status for the current session.
23
+
24
+ #### Returns
25
+
26
+ `Promise`\<``ContextInfoResult``\>
27
+
28
+ Promise resolving to ContextInfoResult containing context status data and request ID
29
+
30
+ **`Throws`**
31
+
32
+ Error if the API call fails
33
+
34
+ **`Example`**
35
+
36
+ ```typescript
37
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
38
+ const result = await agentBay.create();
39
+ if (result.success) {
40
+ const info = await result.session.context.info();
41
+ console.log(`Context count: ${info.contextStatusData.length}`);
42
+ await result.session.delete();
43
+ }
44
+ ```
45
+
46
+ ___
47
+
48
+ ### infoWithParams
49
+
50
+ ▸ **infoWithParams**(`contextId?`, `path?`, `taskType?`): `Promise`\<``ContextInfoResult``\>
51
+
52
+ Gets information about context synchronization status with optional filter parameters.
53
+
54
+ #### Parameters
55
+
56
+ | Name | Type | Description |
57
+ | :------ | :------ | :------ |
58
+ | `contextId?` | `string` | Optional context ID to filter results |
59
+ | `path?` | `string` | Optional path to filter results |
60
+ | `taskType?` | `string` | Optional task type to filter results (e.g., "upload", "download") |
61
+
62
+ #### Returns
63
+
64
+ `Promise`\<``ContextInfoResult``\>
65
+
66
+ Promise resolving to ContextInfoResult containing filtered context status data and request ID
67
+
68
+ **`Throws`**
69
+
70
+ Error if the API call fails
71
+
72
+ **`Example`**
73
+
74
+ ```typescript
75
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
76
+ const result = await agentBay.create();
77
+ if (result.success) {
78
+ const info = await result.session.context.infoWithParams('SdkCtx-xxx', '/mnt/persistent');
79
+ console.log(`Context status: ${info.contextStatusData[0]?.status}`);
80
+ await result.session.delete();
81
+ }
82
+ ```
83
+
84
+ ___
85
+
86
+ ### sync
87
+
88
+ ▸ **sync**(`contextId?`, `path?`, `mode?`, `callback?`, `maxRetries?`, `retryInterval?`): `Promise`\<``ContextSyncResult``\>
89
+
90
+ Synchronizes a context with the session. Supports both async and callback modes.
91
+
92
+ #### Parameters
93
+
94
+ | Name | Type | Default value | Description |
95
+ | :------ | :------ | :------ | :------ |
96
+ | `contextId?` | `string` | `undefined` | Optional context ID to synchronize. If provided, `path` must also be provided. |
97
+ | `path?` | `string` | `undefined` | Optional path where the context should be mounted. If provided, `contextId` must also be provided. |
98
+ | `mode?` | `string` | `undefined` | Optional synchronization mode (e.g., "upload", "download") |
99
+ | `callback?` | ``SyncCallback`` | `undefined` | Optional callback function. If provided, runs in background and calls callback when complete |
100
+ | `maxRetries` | `number` | `150` | Maximum number of retries for polling completion status (default: 150) |
101
+ | `retryInterval` | `number` | `1500` | Milliseconds to wait between retries (default: 1500) |
102
+
103
+ #### Returns
104
+
105
+ `Promise`\<``ContextSyncResult``\>
106
+
107
+ Promise resolving to ContextSyncResult with success status and request ID
108
+
109
+ **`Throws`**
110
+
111
+ Error if the API call fails
112
+
113
+ **`Throws`**
114
+
115
+ Error if `contextId` or `path` is provided without the other parameter.
116
+ Both must be provided together, or both must be omitted.
117
+
118
+ **`Example`**
119
+
120
+ Sync all contexts (no parameters):
121
+ ```typescript
122
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
123
+ const result = await agentBay.create();
124
+ if (result.success) {
125
+ const syncResult = await result.session.context.sync();
126
+ console.log(`Sync: ${syncResult.success}`);
127
+ await result.session.delete();
128
+ }
129
+ ```
130
+
131
+ **`Example`**
132
+
133
+ Sync specific context with path:
134
+ ```typescript
135
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
136
+ const result = await agentBay.create();
137
+ if (result.success) {
138
+ const ctxResult = await agentBay.context.get('my-context', true);
139
+ const syncResult = await result.session.context.sync(ctxResult.context!.id, '/mnt/persistent', 'upload');
140
+ console.log(`Sync: ${syncResult.success}`);
141
+ await result.session.delete();
142
+ }
143
+ ```
144
+
145
+ ## Related Resources
146
+
147
+ - [Context API Reference](context.md)
148
+ - [Session API Reference](session.md)
149
+
@@ -0,0 +1,51 @@
1
+ # Interface: ContextSyncResult
2
+
3
+ Base interface for API responses
4
+
5
+ ## Hierarchy
6
+
7
+ - ``ApiResponse``
8
+
9
+ ↳ **`ContextSyncResult`**
10
+
11
+ ## Table of contents
12
+
13
+ ### Properties
14
+
15
+ - `errorMessage`
16
+ - `requestId`
17
+
18
+ ## Properties
19
+
20
+ ```typescript
21
+ success: `boolean`
22
+ ```
23
+
24
+
25
+ ### errorMessage
26
+
27
+ • `Optional` **errorMessage**: `string`
28
+
29
+ Optional error message if the operation failed
30
+
31
+ #### Overrides
32
+
33
+ `ApiResponse`.`errorMessage`
34
+
35
+ ___
36
+
37
+ ### requestId
38
+
39
+ • `Optional` **requestId**: `string`
40
+
41
+ Optional request identifier for tracking API calls
42
+
43
+ #### Inherited from
44
+
45
+ `ApiResponse`.`requestId`
46
+
47
+ ___
48
+
49
+ #### Overrides
50
+
51
+ `ApiResponse`.`success`
@@ -0,0 +1,348 @@
1
+ # Class: ContextService
2
+
3
+ ## 💾 Related Tutorial
4
+
5
+ - [Data Persistence Guide](../../../../../docs/guides/common-features/basics/data-persistence.md) - Learn about context management and data persistence
6
+
7
+ Provides methods to manage persistent contexts in the AgentBay cloud environment.
8
+
9
+ ## Table of contents
10
+
11
+
12
+ ### Methods
13
+
14
+ - [clear](#clear)
15
+ - [clearAsync](#clearasync)
16
+ - [create](#create)
17
+ - [delete](#delete)
18
+ - [deleteFile](#deletefile)
19
+ - [get](#get)
20
+ - [list](#list)
21
+ - [listFiles](#listfiles)
22
+ - [update](#update)
23
+
24
+ ## Methods
25
+
26
+ ### clear
27
+
28
+ ▸ **clear**(`contextId`, `timeout?`, `pollInterval?`): `Promise`\<`ClearContextResult`\>
29
+
30
+ Synchronously clear the context's persistent data and wait for the final result.
31
+
32
+ This method wraps the `clearAsync` and `getClearStatus` polling logic,
33
+ providing the simplest and most direct way to handle clearing tasks.
34
+
35
+ The clearing process transitions through the following states:
36
+ - "clearing": Data clearing is in progress
37
+ - "available": Clearing completed successfully (final success state)
38
+
39
+ #### Parameters
40
+
41
+ | Name | Type | Default value | Description |
42
+ | :------ | :------ | :------ | :------ |
43
+ | `contextId` | `string` | `undefined` | Unique ID of the context to clear. |
44
+ | `timeout` | `number` | `60` | (Optional) Timeout in seconds to wait for task completion, default is 60 seconds. |
45
+ | `pollInterval` | `number` | `2.0` | (Optional) Interval in seconds between status polls, default is 2 seconds. |
46
+
47
+ #### Returns
48
+
49
+ `Promise`\<`ClearContextResult`\>
50
+
51
+ A ClearContextResult object containing the final task result.
52
+ The status field will be "available" on success, or other states if interrupted.
53
+
54
+ **`Throws`**
55
+
56
+ APIError - If the task fails to complete within the specified timeout.
57
+
58
+ **`Example`**
59
+
60
+ ```typescript
61
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
62
+ const getResult = await agentBay.context.get('my-context');
63
+ if (getResult.success) {
64
+ const clearResult = await agentBay.context.clear(getResult.context.id);
65
+ console.log('Context cleared:', clearResult.success);
66
+ console.log('Final status:', clearResult.status);
67
+ }
68
+ ```
69
+
70
+ ___
71
+
72
+ ### clearAsync
73
+
74
+ ▸ **clearAsync**(`contextId`): `Promise`\<`ClearContextResult`\>
75
+
76
+ Asynchronously initiate a task to clear the context's persistent data.
77
+
78
+ This is a non-blocking method that returns immediately after initiating the clearing task
79
+ on the backend. The context's state will transition to "clearing" while the operation
80
+ is in progress.
81
+
82
+ #### Parameters
83
+
84
+ | Name | Type | Description |
85
+ | :------ | :------ | :------ |
86
+ | `contextId` | `string` | Unique ID of the context to clear. |
87
+
88
+ #### Returns
89
+
90
+ `Promise`\<`ClearContextResult`\>
91
+
92
+ A ClearContextResult object indicating the task has been successfully started,
93
+ with status field set to "clearing".
94
+
95
+ **`Throws`**
96
+
97
+ APIError - If the backend API rejects the clearing request (e.g., invalid ID).
98
+
99
+ **`Example`**
100
+
101
+ ```typescript
102
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
103
+ const getResult = await agentBay.context.get('my-context');
104
+ if (getResult.success) {
105
+ const clearResult = await agentBay.context.clearAsync(getResult.context.id);
106
+ console.log('Clear task started:', clearResult.success);
107
+ console.log('Status:', clearResult.status);
108
+ }
109
+ ```
110
+
111
+ ___
112
+
113
+ ### create
114
+
115
+ ▸ **create**(`name`): `Promise`\<`ContextResult`\>
116
+
117
+ Creates a new context with the given name.
118
+ Corresponds to Python's create() method
119
+
120
+ #### Parameters
121
+
122
+ | Name | Type | Description |
123
+ | :------ | :------ | :------ |
124
+ | `name` | `string` | The name for the new context. |
125
+
126
+ #### Returns
127
+
128
+ `Promise`\<`ContextResult`\>
129
+
130
+ ContextResult with created context data and requestId
131
+
132
+ **`Example`**
133
+
134
+ ```typescript
135
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
136
+ const result = await agentBay.context.create('my-new-context');
137
+ if (result.success) {
138
+ console.log(`Context ID: ${result.context.id}`);
139
+ console.log(`Context Name: ${result.context.name}`);
140
+ }
141
+ ```
142
+
143
+ ___
144
+
145
+ ### delete
146
+
147
+ ▸ **delete**(`context`): `Promise`\<`OperationResult`\>
148
+
149
+ Deletes the specified context.
150
+ Corresponds to Python's delete() method
151
+
152
+ #### Parameters
153
+
154
+ | Name | Type | Description |
155
+ | :------ | :------ | :------ |
156
+ | `context` | ``Context`` | The Context object to delete. |
157
+
158
+ #### Returns
159
+
160
+ `Promise`\<`OperationResult`\>
161
+
162
+ OperationResult with requestId
163
+
164
+ **`Example`**
165
+
166
+ ```typescript
167
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
168
+ const getResult = await agentBay.context.get('my-context');
169
+ if (getResult.success && getResult.context) {
170
+ const deleteResult = await agentBay.context.delete(getResult.context);
171
+ console.log('Context deleted:', deleteResult.success);
172
+ }
173
+ ```
174
+
175
+ ___
176
+
177
+ ### deleteFile
178
+
179
+ ▸ **deleteFile**(`contextId`, `filePath`): `Promise`\<`OperationResult`\>
180
+
181
+ Delete a file in a context.
182
+
183
+ #### Parameters
184
+
185
+ | Name | Type | Description |
186
+ | :------ | :------ | :------ |
187
+ | `contextId` | `string` | The ID of the context. |
188
+ | `filePath` | `string` | The path to the file to delete. |
189
+
190
+ #### Returns
191
+
192
+ `Promise`\<`OperationResult`\>
193
+
194
+ OperationResult indicating success or failure.
195
+
196
+ **`Example`**
197
+
198
+ ```typescript
199
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
200
+ const contextResult = await agentBay.context.get('my-context');
201
+ if (contextResult.success) {
202
+ const deleteResult = await agentBay.context.deleteFile(contextResult.context.id, '/data/file.txt');
203
+ console.log('File deleted:', deleteResult.success);
204
+ }
205
+ ```
206
+
207
+ ___
208
+
209
+ ### get
210
+
211
+ ▸ **get**(`name`, `create?`): `Promise`\<`ContextResult`\>
212
+
213
+ Retrieves an existing context or creates a new one.
214
+
215
+ #### Parameters
216
+
217
+ | Name | Type | Default value | Description |
218
+ | :------ | :------ | :------ | :------ |
219
+ | `name` | `string` | `undefined` | The name of the context to retrieve or create. |
220
+ | `create` | `boolean` | `false` | If true, creates the context if it doesn't exist. Defaults to false. |
221
+
222
+ #### Returns
223
+
224
+ `Promise`\<`ContextResult`\>
225
+
226
+ Promise resolving to ContextResult containing the Context object.
227
+
228
+ **`Example`**
229
+
230
+ ```typescript
231
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
232
+ const result = await agentBay.context.get('my-context', true);
233
+ if (result.success) {
234
+ console.log(`Context ID: ${result.context.id}`);
235
+ console.log(`Context Name: ${result.context.name}`);
236
+ }
237
+ ```
238
+
239
+ **`See`**
240
+
241
+ [update](#update), [list](#list)
242
+
243
+ ### list
244
+
245
+ ▸ **list**(`params?`): `Promise`\<`ContextListResult`\>
246
+
247
+ Lists all available contexts with pagination support.
248
+ Corresponds to Python's list() method
249
+
250
+ #### Parameters
251
+
252
+ | Name | Type | Description |
253
+ | :------ | :------ | :------ |
254
+ | `params?` | `ContextListParams` | Optional parameters for listing contexts. |
255
+
256
+ #### Returns
257
+
258
+ `Promise`\<`ContextListResult`\>
259
+
260
+ ContextListResult with contexts list and pagination information
261
+
262
+ **`Example`**
263
+
264
+ ```typescript
265
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
266
+ const result = await agentBay.context.list({ maxResults: 10 });
267
+ if (result.success) {
268
+ console.log(`Total contexts: ${result.totalCount}`);
269
+ console.log(`Page has ${result.contexts.length} contexts`);
270
+ }
271
+ ```
272
+
273
+ ___
274
+
275
+ ### listFiles
276
+
277
+ ▸ **listFiles**(`contextId`, `parentFolderPath`, `pageNumber?`, `pageSize?`): `Promise`\<`ContextFileListResult`\>
278
+
279
+ List files under a specific folder path in a context.
280
+
281
+ #### Parameters
282
+
283
+ | Name | Type | Default value | Description |
284
+ | :------ | :------ | :------ | :------ |
285
+ | `contextId` | `string` | `undefined` | The ID of the context. |
286
+ | `parentFolderPath` | `string` | `undefined` | The parent folder path to list files from. |
287
+ | `pageNumber` | `number` | `1` | Page number for pagination (default: 1). |
288
+ | `pageSize` | `number` | `50` | Number of files per page (default: 50). |
289
+
290
+ #### Returns
291
+
292
+ `Promise`\<`ContextFileListResult`\>
293
+
294
+ ContextFileListResult with file entries and total count.
295
+
296
+ **`Example`**
297
+
298
+ ```typescript
299
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
300
+ const contextResult = await agentBay.context.get('my-context');
301
+ if (contextResult.success) {
302
+ const listResult = await agentBay.context.listFiles(contextResult.context.id, '/data');
303
+ console.log(`Found ${listResult.entries.length} files`);
304
+ console.log(`Total count: ${listResult.count}`);
305
+ }
306
+ ```
307
+
308
+ ___
309
+
310
+ ### update
311
+
312
+ ▸ **update**(`context`): `Promise`\<`OperationResult`\>
313
+
314
+ Updates a context's name.
315
+
316
+ #### Parameters
317
+
318
+ | Name | Type | Description |
319
+ | :------ | :------ | :------ |
320
+ | `context` | ``Context`` | The Context object with updated name. |
321
+
322
+ #### Returns
323
+
324
+ `Promise`\<`OperationResult`\>
325
+
326
+ Promise resolving to OperationResult with success status.
327
+
328
+ **`Example`**
329
+
330
+ ```typescript
331
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
332
+ const getResult = await agentBay.context.get('old-name');
333
+ if (getResult.success && getResult.context) {
334
+ getResult.context.name = 'new-name';
335
+ const updateResult = await agentBay.context.update(getResult.context);
336
+ console.log('Context updated:', updateResult.success);
337
+ }
338
+ ```
339
+
340
+ **`See`**
341
+
342
+ [get](#get), [list](#list)
343
+
344
+ ## Related Resources
345
+
346
+ - [Session API Reference](session.md)
347
+ - [Context Manager API Reference](context-manager.md)
348
+