wuying-agentbay-sdk 0.1.0 → 0.4.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/README.md +124 -61
- package/dist/index.cjs +6621 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +2633 -0
- package/dist/index.d.ts +2633 -0
- package/dist/index.mjs +6637 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +84 -48
- package/dist/src/adb/adb.d.ts +0 -20
- package/dist/src/adb/adb.js +0 -57
- package/dist/src/adb/index.d.ts +0 -1
- package/dist/src/adb/index.js +0 -17
- package/dist/src/agent-bay.d.ts +0 -68
- package/dist/src/agent-bay.js +0 -213
- package/dist/src/api/client.d.ts +0 -191
- package/dist/src/api/client.js +0 -629
- package/dist/src/api/index.d.ts +0 -4
- package/dist/src/api/index.js +0 -26
- package/dist/src/api/models/CallMcpToolRequest.d.ts +0 -21
- package/dist/src/api/models/CallMcpToolRequest.js +0 -71
- package/dist/src/api/models/CallMcpToolResponse.d.ts +0 -19
- package/dist/src/api/models/CallMcpToolResponse.js +0 -68
- package/dist/src/api/models/CallMcpToolResponseBody.d.ts +0 -19
- package/dist/src/api/models/CallMcpToolResponseBody.js +0 -67
- package/dist/src/api/models/CreateMcpSessionRequest.d.ts +0 -19
- package/dist/src/api/models/CreateMcpSessionRequest.js +0 -67
- package/dist/src/api/models/CreateMcpSessionResponse.d.ts +0 -19
- package/dist/src/api/models/CreateMcpSessionResponse.js +0 -68
- package/dist/src/api/models/CreateMcpSessionResponseBody.d.ts +0 -20
- package/dist/src/api/models/CreateMcpSessionResponseBody.js +0 -71
- package/dist/src/api/models/CreateMcpSessionResponseBodyData.d.ts +0 -19
- package/dist/src/api/models/CreateMcpSessionResponseBodyData.js +0 -67
- package/dist/src/api/models/DeleteContextRequest.d.ts +0 -15
- package/dist/src/api/models/DeleteContextRequest.js +0 -59
- package/dist/src/api/models/DeleteContextResponse.d.ts +0 -19
- package/dist/src/api/models/DeleteContextResponse.js +0 -68
- package/dist/src/api/models/DeleteContextResponseBody.d.ts +0 -18
- package/dist/src/api/models/DeleteContextResponseBody.js +0 -65
- package/dist/src/api/models/GetContextRequest.d.ts +0 -16
- package/dist/src/api/models/GetContextRequest.js +0 -61
- package/dist/src/api/models/GetContextResponse.d.ts +0 -19
- package/dist/src/api/models/GetContextResponse.js +0 -68
- package/dist/src/api/models/GetContextResponseBody.d.ts +0 -20
- package/dist/src/api/models/GetContextResponseBody.js +0 -71
- package/dist/src/api/models/GetContextResponseBodyData.d.ts +0 -19
- package/dist/src/api/models/GetContextResponseBodyData.js +0 -67
- package/dist/src/api/models/GetLabelRequest.d.ts +0 -17
- package/dist/src/api/models/GetLabelRequest.js +0 -63
- package/dist/src/api/models/GetLabelResponse.d.ts +0 -19
- package/dist/src/api/models/GetLabelResponse.js +0 -68
- package/dist/src/api/models/GetLabelResponseBody.d.ts +0 -23
- package/dist/src/api/models/GetLabelResponseBody.js +0 -77
- package/dist/src/api/models/GetLabelResponseBodyData.d.ts +0 -14
- package/dist/src/api/models/GetLabelResponseBodyData.js +0 -57
- package/dist/src/api/models/GetLinkRequest.d.ts +0 -15
- package/dist/src/api/models/GetLinkRequest.js +0 -59
- package/dist/src/api/models/GetLinkResponse.d.ts +0 -19
- package/dist/src/api/models/GetLinkResponse.js +0 -68
- package/dist/src/api/models/GetLinkResponseBody.d.ts +0 -19
- package/dist/src/api/models/GetLinkResponseBody.js +0 -67
- package/dist/src/api/models/GetMcpResourceRequest.d.ts +0 -15
- package/dist/src/api/models/GetMcpResourceRequest.js +0 -59
- package/dist/src/api/models/GetMcpResourceResponse.d.ts +0 -19
- package/dist/src/api/models/GetMcpResourceResponse.js +0 -68
- package/dist/src/api/models/GetMcpResourceResponseBody.d.ts +0 -20
- package/dist/src/api/models/GetMcpResourceResponseBody.js +0 -71
- package/dist/src/api/models/GetMcpResourceResponseBodyData.d.ts +0 -17
- package/dist/src/api/models/GetMcpResourceResponseBodyData.js +0 -65
- package/dist/src/api/models/GetMcpResourceResponseBodyDataDesktopInfo.d.ts +0 -18
- package/dist/src/api/models/GetMcpResourceResponseBodyDataDesktopInfo.js +0 -65
- package/dist/src/api/models/ListContextsRequest.d.ts +0 -16
- package/dist/src/api/models/ListContextsRequest.js +0 -61
- package/dist/src/api/models/ListContextsResponse.d.ts +0 -19
- package/dist/src/api/models/ListContextsResponse.js +0 -68
- package/dist/src/api/models/ListContextsResponseBody.d.ts +0 -23
- package/dist/src/api/models/ListContextsResponseBody.js +0 -77
- package/dist/src/api/models/ListContextsResponseBodyData.d.ts +0 -19
- package/dist/src/api/models/ListContextsResponseBodyData.js +0 -67
- package/dist/src/api/models/ListSessionRequest.d.ts +0 -17
- package/dist/src/api/models/ListSessionRequest.js +0 -63
- package/dist/src/api/models/ListSessionResponse.d.ts +0 -19
- package/dist/src/api/models/ListSessionResponse.js +0 -68
- package/dist/src/api/models/ListSessionResponseBody.d.ts +0 -23
- package/dist/src/api/models/ListSessionResponseBody.js +0 -77
- package/dist/src/api/models/ListSessionResponseBodyData.d.ts +0 -14
- package/dist/src/api/models/ListSessionResponseBodyData.js +0 -57
- package/dist/src/api/models/ModifyContextRequest.d.ts +0 -16
- package/dist/src/api/models/ModifyContextRequest.js +0 -61
- package/dist/src/api/models/ModifyContextResponse.d.ts +0 -19
- package/dist/src/api/models/ModifyContextResponse.js +0 -68
- package/dist/src/api/models/ModifyContextResponseBody.d.ts +0 -18
- package/dist/src/api/models/ModifyContextResponseBody.js +0 -65
- package/dist/src/api/models/ReleaseMcpSessionRequest.d.ts +0 -15
- package/dist/src/api/models/ReleaseMcpSessionRequest.js +0 -59
- package/dist/src/api/models/ReleaseMcpSessionResponse.d.ts +0 -19
- package/dist/src/api/models/ReleaseMcpSessionResponse.js +0 -68
- package/dist/src/api/models/ReleaseMcpSessionResponseBody.d.ts +0 -18
- package/dist/src/api/models/ReleaseMcpSessionResponseBody.js +0 -65
- package/dist/src/api/models/SetLabelRequest.d.ts +0 -16
- package/dist/src/api/models/SetLabelRequest.js +0 -61
- package/dist/src/api/models/SetLabelResponse.d.ts +0 -19
- package/dist/src/api/models/SetLabelResponse.js +0 -68
- package/dist/src/api/models/SetLabelResponseBody.d.ts +0 -18
- package/dist/src/api/models/SetLabelResponseBody.js +0 -65
- package/dist/src/api/models/model.d.ts +0 -43
- package/dist/src/api/models/model.js +0 -89
- package/dist/src/application/application.d.ts +0 -88
- package/dist/src/application/application.js +0 -172
- package/dist/src/application/index.d.ts +0 -1
- package/dist/src/application/index.js +0 -17
- package/dist/src/command/command.d.ts +0 -43
- package/dist/src/command/command.js +0 -120
- package/dist/src/command/index.d.ts +0 -1
- package/dist/src/command/index.js +0 -17
- package/dist/src/config.d.ts +0 -15
- package/dist/src/config.js +0 -114
- package/dist/src/context.d.ts +0 -87
- package/dist/src/context.js +0 -208
- package/dist/src/exceptions.d.ts +0 -30
- package/dist/src/exceptions.js +0 -58
- package/dist/src/filesystem/filesystem.d.ts +0 -109
- package/dist/src/filesystem/filesystem.js +0 -245
- package/dist/src/filesystem/index.d.ts +0 -1
- package/dist/src/filesystem/index.js +0 -17
- package/dist/src/index.d.ts +0 -10
- package/dist/src/index.js +0 -32
- package/dist/src/oss/index.d.ts +0 -1
- package/dist/src/oss/index.js +0 -5
- package/dist/src/oss/oss.d.ts +0 -80
- package/dist/src/oss/oss.js +0 -233
- package/dist/src/session.d.ts +0 -99
- package/dist/src/session.js +0 -226
- package/dist/src/ui/index.d.ts +0 -1
- package/dist/src/ui/index.js +0 -17
- package/dist/src/ui/ui.d.ts +0 -95
- package/dist/src/ui/ui.js +0 -206
- package/dist/src/utils/logger.d.ts +0 -15
- package/dist/src/utils/logger.js +0 -48
- package/dist/src/window/index.d.ts +0 -1
- package/dist/src/window/index.js +0 -17
- package/dist/src/window/window.d.ts +0 -109
- package/dist/src/window/window.js +0 -220
- package/dist/tests/agent-bay.test.d.ts +0 -1
- package/dist/tests/agent-bay.test.js +0 -366
- package/dist/tests/integration/context-persistence.test.d.ts +0 -1
- package/dist/tests/integration/context-persistence.test.js +0 -226
- package/dist/tests/integration/context-session.test.d.ts +0 -1
- package/dist/tests/integration/context-session.test.js +0 -223
- package/dist/tests/integration/window-operations.test.d.ts +0 -1
- package/dist/tests/integration/window-operations.test.js +0 -228
- package/dist/tests/unit/adb.test.d.ts +0 -1
- package/dist/tests/unit/adb.test.js +0 -60
- package/dist/tests/unit/agent-bay.test.d.ts +0 -1
- package/dist/tests/unit/agent-bay.test.js +0 -182
- package/dist/tests/unit/application.test.d.ts +0 -1
- package/dist/tests/unit/application.test.js +0 -260
- package/dist/tests/unit/command.test.d.ts +0 -1
- package/dist/tests/unit/command.test.js +0 -252
- package/dist/tests/unit/context.test.d.ts +0 -1
- package/dist/tests/unit/context.test.js +0 -199
- package/dist/tests/unit/filesystem.test.d.ts +0 -1
- package/dist/tests/unit/filesystem.test.js +0 -493
- package/dist/tests/unit/oss.test.d.ts +0 -1
- package/dist/tests/unit/oss.test.js +0 -243
- package/dist/tests/unit/session-labels.test.d.ts +0 -1
- package/dist/tests/unit/session-labels.test.js +0 -138
- package/dist/tests/unit/session-params.test.d.ts +0 -1
- package/dist/tests/unit/session-params.test.js +0 -78
- package/dist/tests/unit/session.test.d.ts +0 -1
- package/dist/tests/unit/session.test.js +0 -204
- package/dist/tests/unit/ui.test.d.ts +0 -1
- package/dist/tests/unit/ui.test.js +0 -158
- package/dist/tests/unit/window.test.d.ts +0 -1
- package/dist/tests/unit/window.test.js +0 -331
- package/dist/tests/utils/test-helpers.d.ts +0 -35
- package/dist/tests/utils/test-helpers.js +0 -79
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../../src");
|
|
4
|
-
const test_helpers_1 = require("../utils/test-helpers");
|
|
5
|
-
const logger_1 = require("../../src/utils/logger");
|
|
6
|
-
describe('Window Operations Integration', () => {
|
|
7
|
-
let agentBay;
|
|
8
|
-
let session;
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
const apiKey = (0, test_helpers_1.getTestApiKey)();
|
|
11
|
-
agentBay = new src_1.AgentBay({ apiKey });
|
|
12
|
-
// Create a session with linux_latest image
|
|
13
|
-
(0, logger_1.log)('Creating a new session for window operations testing...');
|
|
14
|
-
const sessionParams = { imageId: 'linux_latest' };
|
|
15
|
-
session = await agentBay.create(sessionParams);
|
|
16
|
-
(0, logger_1.log)(`Session created with ID: ${session.sessionId}`);
|
|
17
|
-
});
|
|
18
|
-
afterEach(async () => {
|
|
19
|
-
// Clean up the session
|
|
20
|
-
(0, logger_1.log)('Cleaning up: Deleting the session...');
|
|
21
|
-
try {
|
|
22
|
-
if (session)
|
|
23
|
-
await agentBay.delete(session);
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
(0, logger_1.log)(`Warning: Error deleting session: ${error}`);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
describe('Window Operations', () => {
|
|
30
|
-
it('should perform various window operations', async () => {
|
|
31
|
-
// Set timeout to 2 minutes (120000 ms)
|
|
32
|
-
jest.setTimeout(120000);
|
|
33
|
-
// Test window operations
|
|
34
|
-
if (session.window && session.Application) {
|
|
35
|
-
// Start Terminal application (using Linux default)
|
|
36
|
-
(0, logger_1.log)('Starting Terminal application...');
|
|
37
|
-
const startCmd = 'gnome-terminal';
|
|
38
|
-
let processes;
|
|
39
|
-
try {
|
|
40
|
-
processes = await session.Application.startApp(startCmd, '');
|
|
41
|
-
(0, logger_1.log)(`Terminal started successfully, returned ${processes.length} processes`);
|
|
42
|
-
// Give Terminal some time to initialize
|
|
43
|
-
await (0, test_helpers_1.wait)(20000);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
(0, logger_1.log)(`Note: Failed to start Terminal: ${error}`);
|
|
47
|
-
(0, logger_1.log)('Continuing with existing windows...');
|
|
48
|
-
}
|
|
49
|
-
// Clean up Terminal processes at the end if we successfully started them
|
|
50
|
-
if (processes && processes.length > 0) {
|
|
51
|
-
// Register cleanup function
|
|
52
|
-
const cleanupTerminal = async () => {
|
|
53
|
-
for (const process of processes) {
|
|
54
|
-
if (process.pid > 0) {
|
|
55
|
-
(0, logger_1.log)(`Attempting to stop Terminal process (PID: ${process.pid})...`);
|
|
56
|
-
try {
|
|
57
|
-
await session.Application.stopAppByPID(process.pid);
|
|
58
|
-
(0, logger_1.log)(`Successfully stopped Terminal process (PID: ${process.pid})`);
|
|
59
|
-
}
|
|
60
|
-
catch (stopError) {
|
|
61
|
-
(0, logger_1.log)(`Warning: Failed to stop Terminal process: ${stopError}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
// Make sure to call the cleanup function at the end of the test
|
|
67
|
-
try {
|
|
68
|
-
// Get a list of root windows
|
|
69
|
-
const rootWindows = await session.window.listRootWindows();
|
|
70
|
-
if (!rootWindows || rootWindows.length === 0) {
|
|
71
|
-
(0, logger_1.log)('No windows available for testing window operations');
|
|
72
|
-
await cleanupTerminal();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// Try to find a Terminal window for testing
|
|
76
|
-
let windowId = 0;
|
|
77
|
-
let windowFound = false;
|
|
78
|
-
for (const window of rootWindows) {
|
|
79
|
-
if (window.pname?.toLowerCase().includes('terminal') || window.pname?.toLowerCase().includes('gnome')) {
|
|
80
|
-
windowId = window.window_id;
|
|
81
|
-
windowFound = true;
|
|
82
|
-
(0, logger_1.log)(`Found Terminal window with ID ${windowId} for testing window operations`);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// If no Terminal window found, use the first window
|
|
87
|
-
if (!windowFound && rootWindows.length > 0) {
|
|
88
|
-
windowId = rootWindows[0].window_id;
|
|
89
|
-
(0, logger_1.log)(`No Terminal window found, using window with ID ${windowId} for testing window operations`);
|
|
90
|
-
}
|
|
91
|
-
if (windowId === 0) {
|
|
92
|
-
(0, logger_1.log)('No suitable window found for testing');
|
|
93
|
-
await cleanupTerminal();
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
// Test RestoreWindow
|
|
97
|
-
(0, logger_1.log)(`Restoring window with ID ${windowId}...`);
|
|
98
|
-
try {
|
|
99
|
-
await session.window.restoreWindow(windowId);
|
|
100
|
-
(0, logger_1.log)('Window restored successfully');
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
(0, logger_1.log)(`Note: RestoreWindow failed: ${error}`);
|
|
104
|
-
}
|
|
105
|
-
// Wait for 3 seconds to allow user to see the result
|
|
106
|
-
await (0, test_helpers_1.wait)(3000);
|
|
107
|
-
// Test ResizeWindow
|
|
108
|
-
(0, logger_1.log)(`Resizing window with ID ${windowId} to 800x600...`);
|
|
109
|
-
try {
|
|
110
|
-
await session.window.resizeWindow(windowId, 800, 600);
|
|
111
|
-
(0, logger_1.log)('Window resized successfully');
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
(0, logger_1.log)(`Note: ResizeWindow failed: ${error}`);
|
|
115
|
-
}
|
|
116
|
-
// Wait for 3 seconds to allow user to see the result
|
|
117
|
-
await (0, test_helpers_1.wait)(3000);
|
|
118
|
-
// Test MinimizeWindow
|
|
119
|
-
(0, logger_1.log)(`Minimizing window with ID ${windowId}...`);
|
|
120
|
-
try {
|
|
121
|
-
await session.window.minimizeWindow(windowId);
|
|
122
|
-
(0, logger_1.log)('Window minimized successfully');
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
(0, logger_1.log)(`Note: MinimizeWindow failed: ${error}`);
|
|
126
|
-
}
|
|
127
|
-
// Wait for 3 seconds to allow user to see the result
|
|
128
|
-
await (0, test_helpers_1.wait)(3000);
|
|
129
|
-
// Test MaximizeWindow
|
|
130
|
-
(0, logger_1.log)(`Maximizing window with ID ${windowId}...`);
|
|
131
|
-
try {
|
|
132
|
-
await session.window.maximizeWindow(windowId);
|
|
133
|
-
(0, logger_1.log)('Window maximized successfully');
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
(0, logger_1.log)(`Note: MaximizeWindow failed: ${error}`);
|
|
137
|
-
}
|
|
138
|
-
// Wait for 3 seconds to allow user to see the result
|
|
139
|
-
await (0, test_helpers_1.wait)(3000);
|
|
140
|
-
// Start a terminal
|
|
141
|
-
(0, logger_1.log)('Starting terminal...');
|
|
142
|
-
let terminalCmd = 'gnome-terminal';
|
|
143
|
-
// Adjust command based on platform
|
|
144
|
-
if (process.platform === 'darwin') {
|
|
145
|
-
terminalCmd = 'open -a Terminal';
|
|
146
|
-
}
|
|
147
|
-
else if (process.platform === 'win32') {
|
|
148
|
-
terminalCmd = 'start cmd';
|
|
149
|
-
}
|
|
150
|
-
let terminalProcesses = [];
|
|
151
|
-
try {
|
|
152
|
-
terminalProcesses = await session.Application.startApp(terminalCmd, '');
|
|
153
|
-
(0, logger_1.log)(`Terminal started successfully, returned ${terminalProcesses.length} processes`);
|
|
154
|
-
// Give terminal some time to initialize
|
|
155
|
-
await (0, test_helpers_1.wait)(3000);
|
|
156
|
-
// Clean up terminal processes at the end
|
|
157
|
-
const cleanupTerminal = async () => {
|
|
158
|
-
for (const process of terminalProcesses) {
|
|
159
|
-
if (process.pid > 0) {
|
|
160
|
-
(0, logger_1.log)(`Attempting to stop terminal process (PID: ${process.pid})...`);
|
|
161
|
-
try {
|
|
162
|
-
await session.Application.stopAppByPID(process.pid);
|
|
163
|
-
(0, logger_1.log)(`Successfully stopped terminal process (PID: ${process.pid})`);
|
|
164
|
-
}
|
|
165
|
-
catch (stopError) {
|
|
166
|
-
(0, logger_1.log)(`Warning: Failed to stop terminal process: ${stopError}`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
// Register cleanup for terminal
|
|
172
|
-
try {
|
|
173
|
-
// Activate the Terminal window again
|
|
174
|
-
(0, logger_1.log)(`Activating Terminal window with ID ${windowId} again...`);
|
|
175
|
-
try {
|
|
176
|
-
await session.window.activateWindow(windowId);
|
|
177
|
-
(0, logger_1.log)('Window activated successfully');
|
|
178
|
-
}
|
|
179
|
-
catch (error) {
|
|
180
|
-
(0, logger_1.log)(`Note: ActivateWindow failed: ${error}`);
|
|
181
|
-
}
|
|
182
|
-
// Wait for 3 seconds to allow user to see the result
|
|
183
|
-
await (0, test_helpers_1.wait)(3000);
|
|
184
|
-
// Test FullscreenWindow
|
|
185
|
-
(0, logger_1.log)(`Fullscreening window with ID ${windowId}...`);
|
|
186
|
-
try {
|
|
187
|
-
await session.window.fullscreenWindow(windowId);
|
|
188
|
-
(0, logger_1.log)('Window fullscreened successfully');
|
|
189
|
-
}
|
|
190
|
-
catch (error) {
|
|
191
|
-
(0, logger_1.log)(`Note: FullscreenWindow failed: ${error}`);
|
|
192
|
-
}
|
|
193
|
-
// Wait for 3 seconds to allow user to see the result
|
|
194
|
-
await (0, test_helpers_1.wait)(3000);
|
|
195
|
-
// Test CloseWindow
|
|
196
|
-
(0, logger_1.log)(`Closing window with ID ${windowId}...`);
|
|
197
|
-
try {
|
|
198
|
-
await session.window.closeWindow(windowId);
|
|
199
|
-
(0, logger_1.log)('Window closed successfully');
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
(0, logger_1.log)(`Note: CloseWindow failed: ${error}`);
|
|
203
|
-
}
|
|
204
|
-
// Wait for 3 seconds to allow user to see the result
|
|
205
|
-
await (0, test_helpers_1.wait)(3000);
|
|
206
|
-
}
|
|
207
|
-
finally {
|
|
208
|
-
await cleanupTerminal();
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
(0, logger_1.log)(`Note: Failed to start terminal: ${error}`);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
finally {
|
|
216
|
-
await cleanupTerminal();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
(0, logger_1.log)('No Terminal processes to test with, skipping window operations');
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
(0, logger_1.log)('Note: Window or Application interface is nil, skipping window operations test');
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../../src");
|
|
4
|
-
const test_helpers_1 = require("../utils/test-helpers");
|
|
5
|
-
describe('Adb', () => {
|
|
6
|
-
let agentBay;
|
|
7
|
-
let session;
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
const apiKey = (0, test_helpers_1.getTestApiKey)();
|
|
10
|
-
agentBay = new src_1.AgentBay({ apiKey });
|
|
11
|
-
session = await agentBay.create();
|
|
12
|
-
});
|
|
13
|
-
afterEach(async () => {
|
|
14
|
-
// Clean up the session
|
|
15
|
-
try {
|
|
16
|
-
await agentBay.delete(session);
|
|
17
|
-
console.log(`Session deleted successfully: ${session.sessionId}`);
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
console.log(`Warning: Error deleting session: ${error}`);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
describe('shell', () => {
|
|
24
|
-
it('should execute ADB shell commands', async () => {
|
|
25
|
-
if (session.adb) {
|
|
26
|
-
console.log('Executing ADB shell command...');
|
|
27
|
-
try {
|
|
28
|
-
const response = await session.adb.shell('ls /sdcard');
|
|
29
|
-
console.log(`ADB shell execution result: ${response}`);
|
|
30
|
-
// Check if response contains "tool not found"
|
|
31
|
-
expect((0, test_helpers_1.containsToolNotFound)(response)).toBe(false);
|
|
32
|
-
// We don't check the specific content as it depends on the device
|
|
33
|
-
expect(response).toBeDefined();
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.log(`Note: ADB shell execution failed: ${error}`);
|
|
37
|
-
// Don't fail the test if ADB is not supported
|
|
38
|
-
}
|
|
39
|
-
// Test another ADB command
|
|
40
|
-
try {
|
|
41
|
-
console.log('Executing ADB shell command to check device properties...');
|
|
42
|
-
const propResponse = await session.adb.shell('getprop');
|
|
43
|
-
console.log(`ADB getprop execution result length: ${propResponse.length} bytes`);
|
|
44
|
-
// Check if response contains "tool not found"
|
|
45
|
-
expect((0, test_helpers_1.containsToolNotFound)(propResponse)).toBe(false);
|
|
46
|
-
// We don't check the specific content as it depends on the device
|
|
47
|
-
expect(propResponse).toBeDefined();
|
|
48
|
-
expect(propResponse.length).toBeGreaterThan(0);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
console.log(`Note: ADB getprop execution failed: ${error}`);
|
|
52
|
-
// Don't fail the test if ADB is not supported
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
console.log('Note: Adb interface is nil, skipping ADB test');
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../../src");
|
|
4
|
-
const test_helpers_1 = require("../utils/test-helpers");
|
|
5
|
-
const logger_1 = require("../../src/utils/logger");
|
|
6
|
-
describe('AgentBay', () => {
|
|
7
|
-
describe('constructor', () => {
|
|
8
|
-
it.only('should initialize with API key from options', () => {
|
|
9
|
-
const apiKey = (0, test_helpers_1.getTestApiKey)();
|
|
10
|
-
const agentBay = new src_1.AgentBay({ apiKey });
|
|
11
|
-
(0, logger_1.log)(apiKey);
|
|
12
|
-
expect(agentBay.getAPIKey()).toBe(apiKey);
|
|
13
|
-
});
|
|
14
|
-
it.only('should initialize with API key from environment variable', () => {
|
|
15
|
-
const originalEnv = process.env.AGENTBAY_API_KEY;
|
|
16
|
-
process.env.AGENTBAY_API_KEY = 'env_api_key';
|
|
17
|
-
try {
|
|
18
|
-
const agentBay = new src_1.AgentBay();
|
|
19
|
-
expect(agentBay.getAPIKey()).toBe('env_api_key');
|
|
20
|
-
}
|
|
21
|
-
finally {
|
|
22
|
-
// Restore original environment
|
|
23
|
-
if (originalEnv) {
|
|
24
|
-
process.env.AGENTBAY_API_KEY = originalEnv;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
delete process.env.AGENTBAY_API_KEY;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
it.only('should throw AuthenticationError if no API key is provided', () => {
|
|
32
|
-
const originalEnv = process.env.AGENTBAY_API_KEY;
|
|
33
|
-
delete process.env.AGENTBAY_API_KEY;
|
|
34
|
-
try {
|
|
35
|
-
expect(() => new src_1.AgentBay()).toThrow(src_1.AuthenticationError);
|
|
36
|
-
}
|
|
37
|
-
finally {
|
|
38
|
-
// Restore original environment
|
|
39
|
-
if (originalEnv) {
|
|
40
|
-
process.env.AGENTBAY_API_KEY = originalEnv;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
describe('create, list, and delete', () => {
|
|
46
|
-
let agentBay;
|
|
47
|
-
let session;
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
const apiKey = (0, test_helpers_1.getTestApiKey)();
|
|
50
|
-
agentBay = new src_1.AgentBay({ apiKey });
|
|
51
|
-
});
|
|
52
|
-
it.only('should create, list, and delete a session', async () => {
|
|
53
|
-
// Create a session
|
|
54
|
-
(0, logger_1.log)('Creating a new session...');
|
|
55
|
-
session = await agentBay.create();
|
|
56
|
-
(0, logger_1.log)(`Session created with ID: ${session.sessionId}`);
|
|
57
|
-
// Ensure session ID is not empty
|
|
58
|
-
expect(session.sessionId).toBeDefined();
|
|
59
|
-
expect(session.sessionId.length).toBeGreaterThan(0);
|
|
60
|
-
// List sessions
|
|
61
|
-
(0, logger_1.log)('Listing sessions...');
|
|
62
|
-
const sessions = agentBay.list();
|
|
63
|
-
// Ensure at least one session (the one we just created)
|
|
64
|
-
expect(sessions.length).toBeGreaterThanOrEqual(1);
|
|
65
|
-
// Check if our created session is in the list
|
|
66
|
-
const found = sessions.some(s => s.sessionId === session.sessionId);
|
|
67
|
-
expect(found).toBe(true);
|
|
68
|
-
// Delete the session
|
|
69
|
-
(0, logger_1.log)('Deleting the session...');
|
|
70
|
-
await agentBay.delete(session);
|
|
71
|
-
// List sessions again to ensure it's deleted
|
|
72
|
-
const sessionsAfterDelete = agentBay.list();
|
|
73
|
-
// Check if the deleted session is not in the list
|
|
74
|
-
const stillExists = sessionsAfterDelete.some(s => s.sessionId === session.sessionId);
|
|
75
|
-
expect(stillExists).toBe(false);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
describe('listByLabels', () => {
|
|
79
|
-
let agentBay;
|
|
80
|
-
let sessionA;
|
|
81
|
-
let sessionB;
|
|
82
|
-
beforeEach(async () => {
|
|
83
|
-
try {
|
|
84
|
-
const apiKey = (0, test_helpers_1.getTestApiKey)();
|
|
85
|
-
agentBay = new src_1.AgentBay({ apiKey });
|
|
86
|
-
const labelsA = {
|
|
87
|
-
environment: 'development',
|
|
88
|
-
owner: 'team-a',
|
|
89
|
-
project: 'project-x'
|
|
90
|
-
};
|
|
91
|
-
const labelsB = {
|
|
92
|
-
environment: 'testing',
|
|
93
|
-
owner: 'team-b',
|
|
94
|
-
project: 'project-y'
|
|
95
|
-
};
|
|
96
|
-
// Create session with labels A
|
|
97
|
-
(0, logger_1.log)('Creating session with labels A...');
|
|
98
|
-
sessionA = await agentBay.create({ labels: labelsA });
|
|
99
|
-
(0, logger_1.log)(`Session created with ID: ${sessionA.sessionId}`);
|
|
100
|
-
// Create session with labels B
|
|
101
|
-
sessionB = await agentBay.create({ labels: labelsB });
|
|
102
|
-
(0, logger_1.log)(`Session created with ID: ${sessionB.sessionId}`);
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
(0, logger_1.log)(`Failed to constructor: ${error}`);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
afterEach(async () => {
|
|
109
|
-
// Clean up sessions
|
|
110
|
-
(0, logger_1.log)('Cleaning up sessions...');
|
|
111
|
-
if (sessionA) {
|
|
112
|
-
try {
|
|
113
|
-
await agentBay.delete(sessionA);
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
(0, logger_1.log)(`Warning: Error deleting session A: ${error}`);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (sessionB) {
|
|
120
|
-
try {
|
|
121
|
-
await agentBay.delete(sessionB);
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
(0, logger_1.log)(`Warning: Error deleting session B: ${error}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
it.only('should list sessions by labels ', async () => {
|
|
129
|
-
// Test 1: List all sessions
|
|
130
|
-
const allSessions = agentBay.list();
|
|
131
|
-
(0, logger_1.log)(`Found ${allSessions.length} sessions in total`);
|
|
132
|
-
// Test 2: List sessions by environment=development label
|
|
133
|
-
try {
|
|
134
|
-
const devSessions = await agentBay.listByLabels({ environment: 'development' });
|
|
135
|
-
// Verify that session A is in the results
|
|
136
|
-
const foundSessionA = devSessions.some(s => s.sessionId === sessionA.sessionId);
|
|
137
|
-
expect(foundSessionA).toBe(true);
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
(0, logger_1.log)(`Error listing sessions by environment=development: ${error}`);
|
|
141
|
-
}
|
|
142
|
-
// Test 3: List sessions by owner=team-b label
|
|
143
|
-
try {
|
|
144
|
-
const teamBSessions = await agentBay.listByLabels({ owner: 'team-b' });
|
|
145
|
-
// Verify that session B is in the results
|
|
146
|
-
const foundSessionB = teamBSessions.some(s => s.sessionId === sessionB.sessionId);
|
|
147
|
-
expect(foundSessionB).toBe(true);
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
(0, logger_1.log)(`Error listing sessions by owner=team-b: ${error}`);
|
|
151
|
-
}
|
|
152
|
-
// Test 4: List sessions with multiple labels (environment=testing AND project=project-y)
|
|
153
|
-
try {
|
|
154
|
-
const multiLabelSessions = await agentBay.listByLabels({
|
|
155
|
-
environment: 'testing',
|
|
156
|
-
project: 'project-y'
|
|
157
|
-
});
|
|
158
|
-
(0, logger_1.log)(`Found ${multiLabelSessions.length} sessions with environment=testing AND project=project-y`);
|
|
159
|
-
// Verify that session B is in the results and session A is not
|
|
160
|
-
const foundSessionA = multiLabelSessions.some(s => s.sessionId === sessionA.sessionId);
|
|
161
|
-
const foundSessionB = multiLabelSessions.some(s => s.sessionId === sessionB.sessionId);
|
|
162
|
-
expect(foundSessionA).toBe(false);
|
|
163
|
-
expect(foundSessionB).toBe(true);
|
|
164
|
-
}
|
|
165
|
-
catch (error) {
|
|
166
|
-
(0, logger_1.log)(`Error listing sessions by multiple labels: ${error}`);
|
|
167
|
-
}
|
|
168
|
-
// Test 5: List sessions with non-existent label
|
|
169
|
-
try {
|
|
170
|
-
const nonExistentSessions = await agentBay.listByLabels({ 'non-existent': 'value' });
|
|
171
|
-
(0, logger_1.log)(`Found ${nonExistentSessions.length} sessions with non-existent label`);
|
|
172
|
-
if (nonExistentSessions.length > 0) {
|
|
173
|
-
(0, logger_1.log)('Warning: Found sessions with non-existent label, this might indicate an issue');
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
catch (error) {
|
|
177
|
-
(0, logger_1.log)(`Error listing sessions by non-existent label: ${error}`);
|
|
178
|
-
}
|
|
179
|
-
(0, logger_1.log)('Test completed successfully');
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|