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.
- package/dist/chunk-BVWUCG4J.mjs +3402 -0
- package/dist/chunk-BVWUCG4J.mjs.map +1 -0
- package/dist/chunk-SL5GCAQE.cjs +3393 -0
- package/dist/chunk-SL5GCAQE.cjs.map +1 -0
- package/dist/index.cjs +4623 -3978
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +3934 -1964
- package/dist/index.d.ts +3934 -1964
- package/dist/index.mjs +4601 -3956
- 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-CNCGFWJH.cjs +200 -0
- package/dist/model-CNCGFWJH.cjs.map +1 -0
- package/dist/model-LGWQJWKQ.mjs +209 -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 +277 -0
- package/docs/api/common-features/basics/command.md +83 -0
- package/docs/api/common-features/basics/context-manager.md +149 -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 +542 -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 +381 -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/common-features/basics/session-pause-resume/README.md +53 -0
- package/docs/examples/common-features/basics/session-pause-resume/session-pause-resume.ts +237 -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/docs/examples/mobile-use/mobile-simulate-basic-usage.ts +202 -0
- package/docs/examples/mobile-use/mobile-simulate-with-ctx.ts +170 -0
- package/package.json +19 -12
- 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-LGWQJWKQ.mjs.map} +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mobile-get-adb-url-example",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Example demonstrating Mobile.getAdbUrl functionality",
|
|
5
|
+
"main": "index.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "ts-node index.ts"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@aliyun/wuying-agentbay-sdk": "file:../../../"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@types/node": "^20.0.0",
|
|
14
|
+
"ts-node": "^10.9.1",
|
|
15
|
+
"typescript": "^5.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mobile Simulate Example
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to use the mobile simulate feature to simulate
|
|
5
|
+
* different mobile devices across sessions.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// @ts-nocheck
|
|
9
|
+
import { AgentBay, Session, MobileSimulateService, MobileSimulateMode } from 'wuying-agentbay-sdk';
|
|
10
|
+
import { readFileSync } from 'fs';
|
|
11
|
+
import { join } from 'path';
|
|
12
|
+
|
|
13
|
+
let session1: Session | null = null;
|
|
14
|
+
let session2: Session | null = null;
|
|
15
|
+
let mobileSimContextId: string | null = null;
|
|
16
|
+
|
|
17
|
+
async function runOnFirstMobileSession(client: AgentBay): Promise<void> {
|
|
18
|
+
console.log('=== First Mobile Session ===');
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
// Upload mobile info file for first time
|
|
22
|
+
// How to get the mobile info file please contact the support team.
|
|
23
|
+
console.log('Uploading mobile info file for first time...');
|
|
24
|
+
|
|
25
|
+
// Get the path to mobile_info_model_a.json
|
|
26
|
+
// Navigate from typescript/docs/examples/mobile-use/mobile-simulate-example to resource/
|
|
27
|
+
const mobileInfoFilePath = join(
|
|
28
|
+
__dirname,
|
|
29
|
+
'..',
|
|
30
|
+
'..',
|
|
31
|
+
'..',
|
|
32
|
+
'..',
|
|
33
|
+
'resource',
|
|
34
|
+
'mobile_info_model_a.json'
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// Read the mobile info file
|
|
38
|
+
const mobileInfoContent = readFileSync(mobileInfoFilePath, 'utf-8');
|
|
39
|
+
|
|
40
|
+
// Upload mobile info
|
|
41
|
+
const simulateService = new MobileSimulateService(client);
|
|
42
|
+
simulateService.setSimulateEnable(true);
|
|
43
|
+
simulateService.setSimulateMode(MobileSimulateMode.PropertiesOnly);
|
|
44
|
+
const uploadResult = await simulateService.uploadMobileInfo(mobileInfoContent);
|
|
45
|
+
if (!uploadResult.success) {
|
|
46
|
+
throw new Error(`Failed to upload mobile info file: ${uploadResult.errorMessage}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
mobileSimContextId = uploadResult.mobileSimulateContextId!;
|
|
50
|
+
console.log(`Mobile simulate context id uploaded successfully: ${mobileSimContextId}`);
|
|
51
|
+
|
|
52
|
+
// Create session with mobile simulate configuration
|
|
53
|
+
console.log('Creating first session...');
|
|
54
|
+
const sessionResult = await client.create({
|
|
55
|
+
imageId: 'mobile_latest',
|
|
56
|
+
extraConfigs: {
|
|
57
|
+
mobile: {
|
|
58
|
+
// Set mobile simulate config
|
|
59
|
+
simulateConfig: simulateService.getSimulateConfig(),
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!sessionResult.success || !sessionResult.session) {
|
|
65
|
+
throw new Error(`Failed to create session: ${sessionResult.errorMessage}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
session1 = sessionResult.session;
|
|
69
|
+
console.log(`Session created with ID: ${session1!.sessionId}`);
|
|
70
|
+
|
|
71
|
+
// Wait for mobile simulate to complete
|
|
72
|
+
console.log('Waiting for mobile simulate to complete...');
|
|
73
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
74
|
+
|
|
75
|
+
// Get device model after mobile simulate
|
|
76
|
+
console.log('Getting device model after mobile simulate...');
|
|
77
|
+
const result = await session1!.command.executeCommand('getprop ro.product.model');
|
|
78
|
+
if (!result.success) {
|
|
79
|
+
throw new Error(`Failed to get device model: ${result.errorMessage}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const productModel = result.output.trim();
|
|
83
|
+
console.log(`First session device model: ${productModel}`);
|
|
84
|
+
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new Error(`Error during run_on_first_mobile_session: ${error instanceof Error ? error.message : String(error)}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function runOnSecondMobileSession(client: AgentBay): Promise<void> {
|
|
91
|
+
console.log('\n=== Second Mobile Session ===');
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
// Use the same mobile simulate context id as the first session
|
|
95
|
+
console.log('Creating second session...');
|
|
96
|
+
const simulateService = new MobileSimulateService(client);
|
|
97
|
+
simulateService.setSimulateEnable(true);
|
|
98
|
+
simulateService.setSimulateMode(MobileSimulateMode.PropertiesOnly);
|
|
99
|
+
simulateService.setSimulateContextId(mobileSimContextId!);
|
|
100
|
+
const sessionResult = await client.create({
|
|
101
|
+
imageId: 'mobile_latest',
|
|
102
|
+
extraConfigs: {
|
|
103
|
+
mobile: {
|
|
104
|
+
lockResolution: false,
|
|
105
|
+
// Set mobile simulate config
|
|
106
|
+
simulateConfig: simulateService.getSimulateConfig(),
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (!sessionResult.success || !sessionResult.session) {
|
|
112
|
+
throw new Error(`Failed to create session: ${sessionResult.errorMessage}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
session2 = sessionResult.session;
|
|
116
|
+
console.log(`Session created with ID: ${session2!.sessionId}`);
|
|
117
|
+
|
|
118
|
+
// Wait for mobile simulate to complete
|
|
119
|
+
console.log('Waiting for mobile simulate to complete...');
|
|
120
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
121
|
+
|
|
122
|
+
// Get device model after mobile simulate
|
|
123
|
+
console.log('Getting device model after mobile simulate...');
|
|
124
|
+
const result = await session2!.command.executeCommand('getprop ro.product.model');
|
|
125
|
+
if (!result.success) {
|
|
126
|
+
throw new Error(`Failed to get device model: ${result.errorMessage}`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const productModel = result.output.trim();
|
|
130
|
+
console.log(`Second session device model: ${productModel}`);
|
|
131
|
+
|
|
132
|
+
} catch (error) {
|
|
133
|
+
throw new Error(`Error during run_on_second_mobile_session: ${error instanceof Error ? error.message : String(error)}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function main() {
|
|
138
|
+
console.log('=== Mobile Simulate Example ===\n');
|
|
139
|
+
|
|
140
|
+
// Get API key from environment variable
|
|
141
|
+
const apiKey = process.env.AGENTBAY_API_KEY;
|
|
142
|
+
if (!apiKey) {
|
|
143
|
+
console.error('Error: AGENTBAY_API_KEY environment variable is not set');
|
|
144
|
+
console.error('Please set it with: export AGENTBAY_API_KEY=your_api_key');
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Initialize AgentBay client
|
|
149
|
+
const client = new AgentBay({ apiKey });
|
|
150
|
+
console.log('AgentBay client initialized');
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
// Run on first mobile session
|
|
154
|
+
await runOnFirstMobileSession(client);
|
|
155
|
+
|
|
156
|
+
// Delete first session
|
|
157
|
+
console.log('\nDeleting first session...');
|
|
158
|
+
const deleteResult1 = await session1!.delete();
|
|
159
|
+
if (!deleteResult1.success) {
|
|
160
|
+
throw new Error(`Failed to delete first session: ${deleteResult1.errorMessage}`);
|
|
161
|
+
}
|
|
162
|
+
console.log(`First session deleted successfully (RequestID: ${deleteResult1.requestId})`);
|
|
163
|
+
|
|
164
|
+
// Run on second mobile session
|
|
165
|
+
await runOnSecondMobileSession(client);
|
|
166
|
+
|
|
167
|
+
// Delete second session
|
|
168
|
+
console.log('\nDeleting second session...');
|
|
169
|
+
const deleteResult2 = await session2!.delete();
|
|
170
|
+
if (!deleteResult2.success) {
|
|
171
|
+
throw new Error(`Failed to delete second session: ${deleteResult2.errorMessage}`);
|
|
172
|
+
}
|
|
173
|
+
console.log(`Second session deleted successfully (RequestID: ${deleteResult2.requestId})`);
|
|
174
|
+
|
|
175
|
+
console.log('\n=== Example completed successfully ===');
|
|
176
|
+
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.error('Error:', error instanceof Error ? error.message : String(error));
|
|
179
|
+
|
|
180
|
+
// Cleanup sessions on error
|
|
181
|
+
if (session1) {
|
|
182
|
+
try {
|
|
183
|
+
await session1.delete();
|
|
184
|
+
} catch (e) {
|
|
185
|
+
console.warn('Warning: Failed to cleanup first session');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (session2) {
|
|
189
|
+
try {
|
|
190
|
+
await session2.delete();
|
|
191
|
+
} catch (e) {
|
|
192
|
+
console.warn('Warning: Failed to cleanup second session');
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
process.exit(1);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Run the example
|
|
201
|
+
main();
|
|
202
|
+
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mobile Simulate with User Specific Context Example
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to use the mobile simulate feature with a user specific context
|
|
5
|
+
* to simulate mobile devices across sessions.
|
|
6
|
+
*
|
|
7
|
+
* Steps:
|
|
8
|
+
* 1. Get a user specific context
|
|
9
|
+
* 2. Check if the mobile dev info file exists in user's specific context, if not, get a mobile dev info file from DumpSDK or real device
|
|
10
|
+
* 3. Upload mobile dev info file to user's specific context
|
|
11
|
+
* 4. Create a session with mobile simulate configuration and user's specific context
|
|
12
|
+
* 5. Wait for mobile simulate to complete
|
|
13
|
+
* 6. Get device model after mobile simulate
|
|
14
|
+
* 7. Delete session
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// @ts-nocheck
|
|
18
|
+
import { AgentBay, Session, MobileSimulateService, MobileSimulateMode, ContextSync, SyncPolicy, BWList, WhiteList } from 'wuying-agentbay-sdk';
|
|
19
|
+
import { readFileSync } from 'fs';
|
|
20
|
+
import { join } from 'path';
|
|
21
|
+
|
|
22
|
+
let session: Session | null = null;
|
|
23
|
+
|
|
24
|
+
async function runOnMobileSession(client: AgentBay): Promise<void> {
|
|
25
|
+
try {
|
|
26
|
+
console.log('Getting a user specific context...');
|
|
27
|
+
const contextResult = await client.context.get('13000000001', true);
|
|
28
|
+
if (!contextResult.success || !contextResult.context) {
|
|
29
|
+
throw new Error(`Failed to get context: ${contextResult.errorMessage}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const context = contextResult.context;
|
|
33
|
+
console.log(`context.id = ${context.id}, context.name = ${context.name}`);
|
|
34
|
+
|
|
35
|
+
// Create sync policy with white list
|
|
36
|
+
const syncPolicy: SyncPolicy = {
|
|
37
|
+
bwList: {
|
|
38
|
+
whiteLists: [
|
|
39
|
+
{
|
|
40
|
+
path: '/com.wuying.devinfo',
|
|
41
|
+
excludePaths: []
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const contextSync: ContextSync = {
|
|
48
|
+
contextId: context.id,
|
|
49
|
+
path: '/data/data',
|
|
50
|
+
policy: syncPolicy
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
console.log('Checking or uploading mobile dev info file...');
|
|
54
|
+
|
|
55
|
+
const simulateService = new MobileSimulateService(client);
|
|
56
|
+
simulateService.setSimulateEnable(true);
|
|
57
|
+
simulateService.setSimulateMode(MobileSimulateMode.PropertiesOnly);
|
|
58
|
+
|
|
59
|
+
// Check if the mobile dev info file exists in user's specific context
|
|
60
|
+
const hasMobileInfo = await simulateService.hasMobileInfo(contextSync);
|
|
61
|
+
if (!hasMobileInfo) {
|
|
62
|
+
// If not, get a mobile dev info file from DumpSDK or real device
|
|
63
|
+
const mobileInfoFilePath = join(
|
|
64
|
+
__dirname,
|
|
65
|
+
'..',
|
|
66
|
+
'..',
|
|
67
|
+
'..',
|
|
68
|
+
'..',
|
|
69
|
+
'resource',
|
|
70
|
+
'mobile_info_model_a.json'
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const mobileInfoContent = readFileSync(mobileInfoFilePath, 'utf-8');
|
|
74
|
+
|
|
75
|
+
const uploadResult = await simulateService.uploadMobileInfo(mobileInfoContent, contextSync);
|
|
76
|
+
if (!uploadResult.success) {
|
|
77
|
+
throw new Error(`Failed to upload mobile dev info: ${uploadResult.errorMessage}`);
|
|
78
|
+
}
|
|
79
|
+
console.log('Mobile dev info uploaded successfully');
|
|
80
|
+
} else {
|
|
81
|
+
console.log(`Mobile dev info already exists: ${hasMobileInfo}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Create session with mobile simulate configuration and user's specific context
|
|
85
|
+
console.log('Creating session...');
|
|
86
|
+
const sessionResult = await client.create({
|
|
87
|
+
imageId: 'mobile_latest',
|
|
88
|
+
contextSync: [contextSync],
|
|
89
|
+
extraConfigs: {
|
|
90
|
+
mobile: {
|
|
91
|
+
// Set mobile simulate config
|
|
92
|
+
simulateConfig: simulateService.getSimulateConfig(),
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (!sessionResult.success || !sessionResult.session) {
|
|
98
|
+
throw new Error(`Failed to create session: ${sessionResult.errorMessage}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
session = sessionResult.session;
|
|
102
|
+
console.log(`Session created with ID: ${session.sessionId}`);
|
|
103
|
+
|
|
104
|
+
// Wait for mobile simulate to complete
|
|
105
|
+
console.log('Waiting for mobile simulate to complete...');
|
|
106
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
107
|
+
|
|
108
|
+
// Get device model after mobile simulate
|
|
109
|
+
console.log('Getting device model after mobile simulate...');
|
|
110
|
+
const result = await session.command.executeCommand('getprop ro.product.model');
|
|
111
|
+
if (!result.success) {
|
|
112
|
+
throw new Error(`Failed to get device model: ${result.errorMessage}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const productModel = result.output.trim();
|
|
116
|
+
console.log(`Session device model: ${productModel}`);
|
|
117
|
+
|
|
118
|
+
} catch (error) {
|
|
119
|
+
throw new Error(`Error during runOnMobileSession: ${error instanceof Error ? error.message : String(error)}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function main() {
|
|
124
|
+
console.log('=== Mobile Simulate with User Specific Context Example ===\n');
|
|
125
|
+
|
|
126
|
+
// Get API key from environment variable
|
|
127
|
+
const apiKey = process.env.AGENTBAY_API_KEY;
|
|
128
|
+
if (!apiKey) {
|
|
129
|
+
console.error('Error: AGENTBAY_API_KEY environment variable is not set');
|
|
130
|
+
console.error('Please set it with: export AGENTBAY_API_KEY=your_api_key');
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Initialize AgentBay client
|
|
135
|
+
const client = new AgentBay({ apiKey });
|
|
136
|
+
console.log('AgentBay client initialized');
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
// Run on mobile session
|
|
140
|
+
await runOnMobileSession(client);
|
|
141
|
+
|
|
142
|
+
// Delete session
|
|
143
|
+
console.log('\nDeleting session...');
|
|
144
|
+
const deleteResult = await session!.delete({ syncContext: true });
|
|
145
|
+
if (!deleteResult.success) {
|
|
146
|
+
throw new Error(`Failed to delete session: ${deleteResult.errorMessage}`);
|
|
147
|
+
}
|
|
148
|
+
console.log(`Session deleted successfully (RequestID: ${deleteResult.requestId})`);
|
|
149
|
+
|
|
150
|
+
console.log('\n=== Example completed successfully ===');
|
|
151
|
+
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error('Error:', error instanceof Error ? error.message : String(error));
|
|
154
|
+
|
|
155
|
+
// Cleanup session on error
|
|
156
|
+
if (session) {
|
|
157
|
+
try {
|
|
158
|
+
await session.delete({ syncContext: true });
|
|
159
|
+
} catch (e) {
|
|
160
|
+
console.warn('Warning: Failed to cleanup session');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Run the example
|
|
169
|
+
main();
|
|
170
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wuying-agentbay-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "TypeScript SDK for interacting with the Wuying AgentBay cloud runtime environment",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -13,15 +13,17 @@
|
|
|
13
13
|
"./package.json": "./package.json"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "tsup src/index.ts --dts --format cjs,esm",
|
|
16
|
+
"build": "node scripts/run_with_fallback.js tsup tsup@8.5.0 src/index.ts --dts --format cjs,esm",
|
|
17
17
|
"prepublishOnly": "npm run build",
|
|
18
|
-
"test": "jest",
|
|
19
|
-
"test:unit": "jest tests/unit",
|
|
20
|
-
"test:integration": "jest tests/integration",
|
|
21
|
-
"test:coverage": "jest --coverage",
|
|
22
|
-
"lint": "eslint src/**/*.ts",
|
|
23
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
24
|
-
"prepare": "npm run build"
|
|
18
|
+
"test": "node scripts/run_with_fallback.js jest jest@26.6.3",
|
|
19
|
+
"test:unit": "node scripts/run_with_fallback.js jest jest@26.6.3 tests/unit",
|
|
20
|
+
"test:integration": "node scripts/run_with_fallback.js jest jest@26.6.3 tests/integration",
|
|
21
|
+
"test:coverage": "node scripts/run_with_fallback.js jest jest@26.6.3 --coverage",
|
|
22
|
+
"lint": "node scripts/run_with_fallback.js eslint eslint@8.35.0 \"src/**/*.ts\"",
|
|
23
|
+
"format": "node scripts/run_with_fallback.js prettier prettier@2.8.4 --write \"src/**/*.ts\"",
|
|
24
|
+
"prepare": "npm run build",
|
|
25
|
+
"docs:generate": "node scripts/generate_api_docs.js",
|
|
26
|
+
"examples:check": "node scripts/run_with_fallback.js tsc typescript@4.9.5 --project examples/tsconfig.json"
|
|
25
27
|
},
|
|
26
28
|
"author": "Wuying AI Team <wuying-ai-team@alibabacloud.com> (https://github.com/aliyun/wuying-agentbay-sdk)",
|
|
27
29
|
"contributors": [
|
|
@@ -46,8 +48,9 @@
|
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@types/chai": "^5.2.2",
|
|
48
50
|
"@types/jest": "^26.0.24",
|
|
51
|
+
"@types/js-yaml": "^4.0.9",
|
|
49
52
|
"@types/mocha": "^10.0.10",
|
|
50
|
-
"@types/node": "^18.
|
|
53
|
+
"@types/node": "^18.19.130",
|
|
51
54
|
"@types/sinon": "^10.0.0",
|
|
52
55
|
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
53
56
|
"@typescript-eslint/parser": "^5.54.0",
|
|
@@ -57,12 +60,15 @@
|
|
|
57
60
|
"dotenv": "^16.5.0",
|
|
58
61
|
"eslint": "^8.35.0",
|
|
59
62
|
"jest": "^26.6.3",
|
|
63
|
+
"js-yaml": "^4.1.0",
|
|
60
64
|
"prettier": "^2.8.4",
|
|
61
65
|
"sinon": "^15.2.0",
|
|
62
66
|
"ts-jest": "^26.5.6",
|
|
63
67
|
"ts-node": "^10.9.2",
|
|
64
68
|
"tsup": "^8.5.0",
|
|
65
|
-
"
|
|
69
|
+
"typedoc": "^0.25.0",
|
|
70
|
+
"typedoc-plugin-markdown": "^3.16.0",
|
|
71
|
+
"typescript": "4.9.5"
|
|
66
72
|
},
|
|
67
73
|
"dependencies": {
|
|
68
74
|
"@alicloud/openapi-core": "^1.0.4",
|
|
@@ -74,7 +80,8 @@
|
|
|
74
80
|
},
|
|
75
81
|
"sideEffects": false,
|
|
76
82
|
"files": [
|
|
77
|
-
"dist/**/*"
|
|
83
|
+
"dist/**/*",
|
|
84
|
+
"docs/**/*"
|
|
78
85
|
],
|
|
79
86
|
"repository": {
|
|
80
87
|
"type": "git",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
const require = createRequire(import.meta.url);
|
|
4
|
-
(function() {
|
|
5
|
-
if (typeof OpenApi !== 'undefined' && !OpenApi.default) {
|
|
6
|
-
OpenApi.default = OpenApi;
|
|
7
|
-
}
|
|
8
|
-
})();
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
Application
|
|
12
|
-
} from "./chunk-BQNGKBQF.mjs";
|
|
13
|
-
import "./chunk-KNEDRAP6.mjs";
|
|
14
|
-
export {
|
|
15
|
-
Application
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=application-KZWXH46T.mjs.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkX6MS7Z5Lcjs = require('./chunk-X6MS7Z5L.cjs');
|
|
4
|
-
require('./chunk-4IPTHWLM.cjs');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.Application = _chunkX6MS7Z5Lcjs.Application;
|
|
8
|
-
//# sourceMappingURL=application-LMA7KSRH.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/wuying-agentbay-sdk/wuying-agentbay-sdk/typescript/dist/application-LMA7KSRH.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACF,oDAAC","file":"/home/runner/work/wuying-agentbay-sdk/wuying-agentbay-sdk/typescript/dist/application-LMA7KSRH.cjs"}
|