wuying-agentbay-sdk 0.10.1 → 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.
Files changed (104) hide show
  1. package/dist/chunk-E7QC5S76.mjs +3143 -0
  2. package/dist/chunk-E7QC5S76.mjs.map +1 -0
  3. package/dist/chunk-ZUB35HKV.cjs +3134 -0
  4. package/dist/chunk-ZUB35HKV.cjs.map +1 -0
  5. package/dist/index.cjs +3598 -3924
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.mts +2092 -689
  8. package/dist/index.d.ts +2092 -689
  9. package/dist/index.mjs +3562 -3888
  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-2G37RFQQ.cjs +188 -0
  16. package/dist/model-2G37RFQQ.cjs.map +1 -0
  17. package/dist/model-ZFTLKEMC.mjs +197 -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 +181 -0
  25. package/docs/api/common-features/basics/command.md +83 -0
  26. package/docs/api/common-features/basics/context-manager.md +130 -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 +412 -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 +380 -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/mobile-use/mobile-get-adb-url/README.md +92 -0
  85. package/docs/examples/mobile-use/mobile-get-adb-url/index.ts +80 -0
  86. package/docs/examples/mobile-use/mobile-get-adb-url/package-lock.json +279 -0
  87. package/docs/examples/mobile-use/mobile-get-adb-url/package.json +18 -0
  88. package/package.json +18 -11
  89. package/dist/application-KZWXH46T.mjs +0 -17
  90. package/dist/application-LMA7KSRH.cjs +0 -8
  91. package/dist/application-LMA7KSRH.cjs.map +0 -1
  92. package/dist/chunk-BQNGKBQF.mjs +0 -386
  93. package/dist/chunk-BQNGKBQF.mjs.map +0 -1
  94. package/dist/chunk-IOVGAAJL.cjs +0 -558
  95. package/dist/chunk-IOVGAAJL.cjs.map +0 -1
  96. package/dist/chunk-UF2TC2R4.mjs +0 -567
  97. package/dist/chunk-UF2TC2R4.mjs.map +0 -1
  98. package/dist/chunk-X6MS7Z5L.cjs +0 -377
  99. package/dist/chunk-X6MS7Z5L.cjs.map +0 -1
  100. package/dist/window-DH37ZDD5.mjs +0 -17
  101. package/dist/window-DH37ZDD5.mjs.map +0 -1
  102. package/dist/window-U7N3H735.cjs +0 -8
  103. package/dist/window-U7N3H735.cjs.map +0 -1
  104. /package/dist/{application-KZWXH46T.mjs.map → model-ZFTLKEMC.mjs.map} +0 -0
@@ -0,0 +1,412 @@
1
+ # Class: Session
2
+
3
+ ## 🔧 Related Tutorial
4
+
5
+ - [Session Management Guide](../../../../../docs/guides/common-features/basics/session-management.md) - Detailed tutorial on session lifecycle and management
6
+
7
+ Represents a session in the AgentBay cloud environment.
8
+
9
+ ## Table of contents
10
+
11
+
12
+ ### Properties
13
+
14
+
15
+ ### Methods
16
+
17
+ - [callMcpTool](#callmcptool)
18
+ - [delete](#delete)
19
+ - [getLabels](#getlabels)
20
+ - [getLink](#getlink)
21
+ - [getLinkAsync](#getlinkasync)
22
+ - [info](#info)
23
+ - [listMcpTools](#listmcptools)
24
+ - [setLabels](#setlabels)
25
+
26
+ ## Properties
27
+
28
+ ```typescript
29
+ agent: [`Agent`](../advanced/agent.md)
30
+ browser: [`Browser`](../../browser-use/browser.md)
31
+ code: [`Code`](../../codespace/code.md)
32
+ command: [`Command`](command.md)
33
+ computer: [`Computer`](../../computer-use/computer.md)
34
+ context: [`ContextManager`](context-manager.md)
35
+ enableBrowserReplay: `boolean` = `false`
36
+ fileSystem: [`FileSystem`](filesystem.md)
37
+ fileTransferContextId: ``null`` | `string` = `null`
38
+ httpPort: `string` = `""`
39
+ isVpc: `boolean` = `false`
40
+ mcpTools: `McpTool`[] = `[]`
41
+ mobile: [`Mobile`](../../mobile-use/mobile.md)
42
+ networkInterfaceIp: `string` = `""`
43
+ oss: [`Oss`](../advanced/oss.md)
44
+ recordContextId: ``null`` | `string` = `null`
45
+ resourceUrl: `string` = `""`
46
+ sessionId: `string`
47
+ token: `string` = `""`
48
+ ```
49
+
50
+
51
+ ## Methods
52
+
53
+ ### callMcpTool
54
+
55
+ ▸ **callMcpTool**(`toolName`, `args`, `autoGenSession?`): `Promise`\<``McpToolResult``\>
56
+
57
+ Call an MCP tool and return the result in a format compatible with Agent.
58
+
59
+ #### Parameters
60
+
61
+ | Name | Type | Default value | Description |
62
+ | :------ | :------ | :------ | :------ |
63
+ | `toolName` | `string` | `undefined` | Name of the MCP tool to call |
64
+ | `args` | `any` | `undefined` | Arguments to pass to the tool |
65
+ | `autoGenSession` | `boolean` | `false` | Whether to automatically generate session if not exists (default: false) |
66
+
67
+ #### Returns
68
+
69
+ `Promise`\<``McpToolResult``\>
70
+
71
+ McpToolResult containing the response data
72
+
73
+ **`Example`**
74
+
75
+ ```typescript
76
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
77
+ const result = await agentBay.create();
78
+ if (result.success) {
79
+ const shellResult = await result.session.callMcpTool('shell', { command: "echo 'Hello'" });
80
+ console.log(`Output: ${shellResult.data}`);
81
+ await result.session.delete();
82
+ }
83
+ ```
84
+
85
+ **`Remarks`**
86
+
87
+ For press_keys tool, key names are automatically normalized to correct case format.
88
+ This improves case compatibility (e.g., "CTRL" -> "Ctrl", "tab" -> "Tab").
89
+
90
+ ___
91
+
92
+ ### delete
93
+
94
+ ▸ **delete**(`syncContext?`): `Promise`\<``DeleteResult``\>
95
+
96
+ Deletes the session and releases all associated resources.
97
+
98
+ #### Parameters
99
+
100
+ | Name | Type | Default value | Description |
101
+ | :------ | :------ | :------ | :------ |
102
+ | `syncContext` | `boolean` | `false` | Whether to synchronize context data before deletion. If true, uploads all context data to OSS. If false but browser replay is enabled, syncs only the recording context. Defaults to false. |
103
+
104
+ #### Returns
105
+
106
+ `Promise`\<``DeleteResult``\>
107
+
108
+ Promise resolving to DeleteResult containing:
109
+ - success: Whether deletion succeeded
110
+ - requestId: Unique identifier for this API request
111
+ - errorMessage: Error description if deletion failed
112
+
113
+ **`Throws`**
114
+
115
+ Error if the API call fails or network issues occur.
116
+
117
+ **`Example`**
118
+
119
+ ```typescript
120
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
121
+ const result = await agentBay.create();
122
+ if (result.success) {
123
+ await result.session.fileSystem.writeFile('/tmp/data.txt', 'data');
124
+ const deleteResult = await result.session.delete(true);
125
+ console.log('Session deleted:', deleteResult.success);
126
+ }
127
+ ```
128
+
129
+ **`Remarks`**
130
+
131
+ **Behavior:**
132
+ - If `syncContext=true`: Uploads all context data to OSS before deletion
133
+ - If `syncContext=false` but browser replay enabled: Syncs only recording context
134
+ - If `syncContext=false` and no browser replay: Deletes immediately without sync
135
+ - Continues with deletion even if context sync fails
136
+ - Releases all associated resources (browser, computer, mobile, etc.)
137
+
138
+ **Best Practices:**
139
+ - Use `syncContext=true` when you need to preserve context data for later retrieval
140
+ - For temporary sessions, use `syncContext=false` for faster cleanup
141
+ - Always call `delete()` when done to avoid resource leaks
142
+ - Handle deletion errors gracefully in production code
143
+
144
+ **`See`**
145
+
146
+ [info](#info), [ContextManager.sync](context-manager.md#sync)
147
+
148
+ ___
149
+
150
+ ### getLabels
151
+
152
+ ▸ **getLabels**(): `Promise`\<`OperationResult`\>
153
+
154
+ Gets the labels for this session.
155
+
156
+ #### Returns
157
+
158
+ `Promise`\<`OperationResult`\>
159
+
160
+ OperationResult containing the labels as data and request ID
161
+
162
+ **`Throws`**
163
+
164
+ Error if the operation fails (matching Python SessionError)
165
+
166
+ **`Example`**
167
+
168
+ ```typescript
169
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
170
+ const result = await agentBay.create();
171
+ if (result.success) {
172
+ await result.session.setLabels({ project: 'demo', env: 'test' });
173
+ const getResult = await result.session.getLabels();
174
+ console.log('Labels:', JSON.stringify(getResult.data));
175
+ await result.session.delete();
176
+ }
177
+ ```
178
+
179
+ ___
180
+
181
+ ### getLink
182
+
183
+ ▸ **getLink**(`protocolType?`, `port?`, `options?`): `Promise`\<`OperationResult`\>
184
+
185
+ Retrieves an access link for the session.
186
+
187
+ #### Parameters
188
+
189
+ | Name | Type | Description |
190
+ | :------ | :------ | :------ |
191
+ | `protocolType?` | `string` | Protocol type for the link (optional, reserved for future use) |
192
+ | `port?` | `number` | Specific port number to access (must be in range [30100, 30199]). If not specified, returns the default session link. |
193
+ | `options?` | `string` | - |
194
+
195
+ #### Returns
196
+
197
+ `Promise`\<`OperationResult`\>
198
+
199
+ Promise resolving to OperationResult containing:
200
+ - success: Whether the operation succeeded
201
+ - data: String URL for accessing the session
202
+ - requestId: Unique identifier for this API request
203
+ - errorMessage: Error description if operation failed
204
+
205
+ **`Throws`**
206
+
207
+ Error if the API call fails or port is out of valid range.
208
+
209
+ **`Example`**
210
+
211
+ ```typescript
212
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
213
+ const result = await agentBay.create();
214
+ if (result.success) {
215
+ const linkResult = await result.session.getLink();
216
+ console.log(`Session link: ${linkResult.data}`);
217
+ await result.session.delete();
218
+ }
219
+ ```
220
+
221
+ **`Remarks`**
222
+
223
+ **Behavior:**
224
+ - Without port: Returns the default session access URL
225
+ - With port: Returns URL for accessing specific port-mapped service
226
+ - Port must be in range [30100, 30199] for port forwarding
227
+ - For ADB connections, use `session.mobile.getAdbUrl()` with appropriate ADB public key
228
+
229
+ **Best Practices:**
230
+ - Use default link for general session access
231
+ - Use port-specific links when you've started services on specific ports
232
+ - Validate port range before calling to avoid errors
233
+
234
+ **`See`**
235
+
236
+ [info](#info)
237
+
238
+ ___
239
+
240
+ ### getLinkAsync
241
+
242
+ ▸ **getLinkAsync**(`protocolType?`, `port?`, `options?`): `Promise`\<`OperationResult`\>
243
+
244
+ Asynchronously get a link associated with the current session.
245
+
246
+ #### Parameters
247
+
248
+ | Name | Type | Description |
249
+ | :------ | :------ | :------ |
250
+ | `protocolType?` | `string` | Optional protocol type to use for the link |
251
+ | `port?` | `number` | Optional port to use for the link (must be in range [30100, 30199]) |
252
+ | `options?` | `string` | - |
253
+
254
+ #### Returns
255
+
256
+ `Promise`\<`OperationResult`\>
257
+
258
+ OperationResult containing the link as data and request ID
259
+
260
+ **`Throws`**
261
+
262
+ Error if the operation fails (matching Python SessionError)
263
+
264
+ **`Example`**
265
+
266
+ ```typescript
267
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
268
+ const result = await agentBay.create();
269
+ if (result.success) {
270
+ const linkResult = await result.session.getLinkAsync(undefined, 30150);
271
+ console.log(`Port link: ${linkResult.data}`);
272
+ await result.session.delete();
273
+ }
274
+ ```
275
+
276
+ ___
277
+
278
+ ### info
279
+
280
+ ▸ **info**(): `Promise`\<`OperationResult`\>
281
+
282
+ Retrieves detailed information about the current session.
283
+
284
+ #### Returns
285
+
286
+ `Promise`\<`OperationResult`\>
287
+
288
+ Promise resolving to OperationResult containing:
289
+ - success: Whether the operation succeeded (always true if no exception)
290
+ - data: SessionInfo object with the following fields:
291
+ - sessionId (string): The session identifier
292
+ - resourceUrl (string): URL for accessing the session
293
+ - appId (string): Application ID (for desktop sessions)
294
+ - authCode (string): Authentication code
295
+ - connectionProperties (string): Connection configuration
296
+ - resourceId (string): Resource identifier
297
+ - resourceType (string): Type of resource (e.g., "Desktop")
298
+ - ticket (string): Access ticket
299
+ - requestId: Unique identifier for this API request
300
+ - errorMessage: Error description if operation failed
301
+
302
+ **`Throws`**
303
+
304
+ Error if the API request fails or response is invalid.
305
+
306
+ **`Example`**
307
+
308
+ ```typescript
309
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
310
+ const result = await agentBay.create();
311
+ if (result.success) {
312
+ const infoResult = await result.session.info();
313
+ console.log(`Session ID: ${infoResult.data.sessionId}`);
314
+ console.log(`Resource URL: ${infoResult.data.resourceUrl}`);
315
+ await result.session.delete();
316
+ }
317
+ ```
318
+
319
+ **`Remarks`**
320
+
321
+ **Behavior:**
322
+ - This method calls the GetMcpResource API to retrieve session metadata
323
+ - The returned SessionInfo contains:
324
+ - sessionId: The session identifier
325
+ - resourceUrl: URL for accessing the session
326
+ - Desktop-specific fields (appId, authCode, connectionProperties, etc.)
327
+ are populated from the DesktopInfo section of the API response
328
+ - Session info is retrieved from the AgentBay API in real-time
329
+ - The resourceUrl can be used for browser-based access
330
+ - Desktop-specific fields (appId, authCode) are only populated for desktop sessions
331
+ - This method does not modify the session state
332
+
333
+ **`See`**
334
+
335
+ [delete](#delete), [getLink](#getlink)
336
+
337
+ ___
338
+
339
+ ### listMcpTools
340
+
341
+ ▸ **listMcpTools**(`imageId?`): `Promise`\<`McpToolsResult`\>
342
+
343
+ List MCP tools available for this session.
344
+
345
+ #### Parameters
346
+
347
+ | Name | Type | Description |
348
+ | :------ | :------ | :------ |
349
+ | `imageId?` | `string` | Optional image ID, defaults to session's imageId or "linux_latest" |
350
+
351
+ #### Returns
352
+
353
+ `Promise`\<`McpToolsResult`\>
354
+
355
+ McpToolsResult containing tools list and request ID
356
+
357
+ **`Example`**
358
+
359
+ ```typescript
360
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
361
+ const result = await agentBay.create();
362
+ if (result.success) {
363
+ const toolsResult = await result.session.listMcpTools();
364
+ console.log(`Found ${toolsResult.tools.length} MCP tools`);
365
+ await result.session.delete();
366
+ }
367
+ ```
368
+
369
+ ___
370
+
371
+ ### setLabels
372
+
373
+ ▸ **setLabels**(`labels`): `Promise`\<`OperationResult`\>
374
+
375
+ Sets the labels for this session.
376
+
377
+ #### Parameters
378
+
379
+ | Name | Type | Description |
380
+ | :------ | :------ | :------ |
381
+ | `labels` | `Record`\<`string`, `string`\> | The labels to set for the session. |
382
+
383
+ #### Returns
384
+
385
+ `Promise`\<`OperationResult`\>
386
+
387
+ OperationResult indicating success or failure with request ID
388
+
389
+ **`Throws`**
390
+
391
+ Error if the operation fails (matching Python SessionError)
392
+
393
+ **`Example`**
394
+
395
+ ```typescript
396
+ const agentBay = new AgentBay({ apiKey: 'your_api_key' });
397
+ const result = await agentBay.create();
398
+ if (result.success) {
399
+ const setResult = await result.session.setLabels({ project: 'demo', env: 'test' });
400
+ console.log('Labels set:', setResult.success);
401
+ await result.session.delete();
402
+ }
403
+ ```
404
+
405
+ ## Related Resources
406
+
407
+ - [FileSystem API Reference](filesystem.md)
408
+ - [Command API Reference](command.md)
409
+ - [Context API Reference](context.md)
410
+ - [Context Manager API Reference](context-manager.md)
411
+ - [OSS API Reference](../../common-features/advanced/oss.md)
412
+