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,158 +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
|
-
// Helper function to parse content array from API response for UI elements
|
|
7
|
-
function parseUIContent(content) {
|
|
8
|
-
if (!Array.isArray(content) || content.length === 0) {
|
|
9
|
-
return [];
|
|
10
|
-
}
|
|
11
|
-
// Try to extract and parse text from the first content item
|
|
12
|
-
const item = content[0];
|
|
13
|
-
if (item && typeof item === 'object' && item.text && typeof item.text === 'string') {
|
|
14
|
-
try {
|
|
15
|
-
return JSON.parse(item.text);
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
(0, logger_1.log)(`Warning: Failed to parse content text as JSON: ${e}`);
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
// Helper function to check if a content array contains base64 image data
|
|
25
|
-
function containsBase64Image(content) {
|
|
26
|
-
if (!Array.isArray(content) || content.length === 0) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
// Look for base64 image data in the text fields
|
|
30
|
-
return content.some(item => item && typeof item === 'object' &&
|
|
31
|
-
typeof item.text === 'string' &&
|
|
32
|
-
(item.text.startsWith('data:image') || item.text.includes('base64')));
|
|
33
|
-
}
|
|
34
|
-
// Type declarations are now in tests/jest.d.ts
|
|
35
|
-
describe('UI', () => {
|
|
36
|
-
let agentBay;
|
|
37
|
-
let session;
|
|
38
|
-
beforeEach(async () => {
|
|
39
|
-
const apiKey = (0, test_helpers_1.getTestApiKey)();
|
|
40
|
-
agentBay = new src_1.AgentBay({ apiKey });
|
|
41
|
-
// Create a session with mobile_latest image (consistent with Go implementation)
|
|
42
|
-
(0, logger_1.log)('Creating a new session for UI testing...');
|
|
43
|
-
session = await agentBay.create({ imageId: 'mobile_latest' });
|
|
44
|
-
(0, logger_1.log)(`Session created with ID: ${session.sessionId}`);
|
|
45
|
-
});
|
|
46
|
-
afterEach(async () => {
|
|
47
|
-
// Clean up the session
|
|
48
|
-
try {
|
|
49
|
-
await agentBay.delete(session);
|
|
50
|
-
(0, logger_1.log)(`Session deleted successfully: ${session.sessionId}`);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
(0, logger_1.log)(`Warning: Error deleting session: ${error}`);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
describe('getClickableUIElements', () => {
|
|
57
|
-
it.only('should retrieve clickable UI elements if implemented', async () => {
|
|
58
|
-
if (session.ui && typeof session.ui.getClickableUIElements === 'function') {
|
|
59
|
-
(0, logger_1.log)('Testing UI.getClickableUIElements method...');
|
|
60
|
-
try {
|
|
61
|
-
const content = await session.ui.getClickableUIElements();
|
|
62
|
-
(0, logger_1.log)(`Retrieved content:`, content);
|
|
63
|
-
// Verify the content
|
|
64
|
-
expect(content).toBeDefined();
|
|
65
|
-
expect(Array.isArray(content)).toBe(true);
|
|
66
|
-
// Try to parse UI elements from content
|
|
67
|
-
const elements = parseUIContent(content);
|
|
68
|
-
(0, logger_1.log)(`Parsed ${elements.length} clickable UI elements`);
|
|
69
|
-
// Additional checks on parsed elements if available
|
|
70
|
-
if (elements.length > 0) {
|
|
71
|
-
(0, logger_1.log)('First UI element:', elements[0]);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
(0, logger_1.log)(`Note: UI.getClickableUIElements execution failed: ${error}`);
|
|
76
|
-
// Don't fail the test if the method is not fully implemented
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
(0, logger_1.log)('Note: UI.getClickableUIElements method is not available, skipping test');
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
describe('getAllUIElements', () => {
|
|
85
|
-
it.only('should retrieve all UI elements if implemented', async () => {
|
|
86
|
-
if (session.ui && typeof session.ui.getAllUIElements === 'function') {
|
|
87
|
-
(0, logger_1.log)('Testing UI.getAllUIElements method...');
|
|
88
|
-
try {
|
|
89
|
-
const content = await session.ui.getAllUIElements();
|
|
90
|
-
(0, logger_1.log)(`Retrieved content:`, content);
|
|
91
|
-
// Verify the content
|
|
92
|
-
expect(content).toBeDefined();
|
|
93
|
-
expect(Array.isArray(content)).toBe(true);
|
|
94
|
-
// Try to parse UI elements from content
|
|
95
|
-
const elements = parseUIContent(content);
|
|
96
|
-
(0, logger_1.log)(`Parsed ${elements.length} UI elements`);
|
|
97
|
-
// Log the first element if available
|
|
98
|
-
if (elements.length > 0) {
|
|
99
|
-
(0, logger_1.log)('First UI element:', elements[0]);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
(0, logger_1.log)(`Note: UI.getAllUIElements execution failed: ${error}`);
|
|
104
|
-
// Don't fail the test if the method is not fully implemented
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
(0, logger_1.log)('Note: UI.getAllUIElements method is not available, skipping test');
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
describe('sendKey', () => {
|
|
113
|
-
it.only('should send key events if implemented', async () => {
|
|
114
|
-
if (session.ui && typeof session.ui.sendKey === 'function') {
|
|
115
|
-
(0, logger_1.log)('Testing UI.sendKey method...');
|
|
116
|
-
try {
|
|
117
|
-
// Try to send HOME key
|
|
118
|
-
const content = await session.ui.sendKey(3); // HOME key
|
|
119
|
-
(0, logger_1.log)(`Send key content:`, content);
|
|
120
|
-
// Verify the content
|
|
121
|
-
expect(content).toBeDefined();
|
|
122
|
-
expect(Array.isArray(content)).toBe(true);
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
(0, logger_1.log)(`Note: UI.sendKey execution failed: ${error}`);
|
|
126
|
-
// Don't fail the test if the method is not fully implemented
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
(0, logger_1.log)('Note: UI.sendKey method is not available, skipping test');
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe('screenshot', () => {
|
|
135
|
-
it.only('should take screenshots if implemented', async () => {
|
|
136
|
-
if (session.ui && typeof session.ui.screenshot === 'function') {
|
|
137
|
-
(0, logger_1.log)('Testing UI.screenshot method...');
|
|
138
|
-
try {
|
|
139
|
-
const content = await session.ui.screenshot();
|
|
140
|
-
(0, logger_1.log)(`Screenshot content length: ${Array.isArray(content) ? content.length : 0} items`);
|
|
141
|
-
// Verify the screenshot content
|
|
142
|
-
expect(content).toBeDefined();
|
|
143
|
-
expect(Array.isArray(content)).toBe(true);
|
|
144
|
-
// Check if the content contains base64 image data
|
|
145
|
-
const hasImageData = containsBase64Image(content);
|
|
146
|
-
expect(hasImageData).toBe(true);
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
(0, logger_1.log)(`Note: UI.screenshot execution failed: ${error}`);
|
|
150
|
-
// Don't fail the test if the method is not fully implemented
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
(0, logger_1.log)('Note: UI.screenshot method is not available, skipping test');
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../../src");
|
|
4
|
-
const window_1 = require("../../src/window/window");
|
|
5
|
-
const test_helpers_1 = require("../utils/test-helpers");
|
|
6
|
-
const logger_1 = require("../../src/utils/logger");
|
|
7
|
-
// Helper function to parse window data from content array
|
|
8
|
-
function parseWindowsContent(content) {
|
|
9
|
-
if (!Array.isArray(content) || content.length === 0) {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
// Try to extract and parse text from the first content item
|
|
13
|
-
const item = content[0];
|
|
14
|
-
if (item && typeof item === 'object' && item.text && typeof item.text === 'string') {
|
|
15
|
-
try {
|
|
16
|
-
return JSON.parse(item.text);
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
(0, logger_1.log)(`Warning: Failed to parse content text as JSON: ${e}`);
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
// Helper function to parse single window data from content array
|
|
26
|
-
function parseWindowContent(content) {
|
|
27
|
-
if (!Array.isArray(content) || content.length === 0) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
// Try to extract and parse text from the first content item
|
|
31
|
-
const item = content[0];
|
|
32
|
-
if (item && typeof item === 'object' && item.text && typeof item.text === 'string') {
|
|
33
|
-
try {
|
|
34
|
-
return JSON.parse(item.text);
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
(0, logger_1.log)(`Warning: Failed to parse content text as JSON: ${e}`);
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
// Helper function to check if content has error
|
|
44
|
-
function hasErrorInContent(content) {
|
|
45
|
-
if (!Array.isArray(content)) {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
if (content.length === 0) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
// Check if first content item has error text
|
|
52
|
-
return content.some(item => item && typeof item === 'object' &&
|
|
53
|
-
item.text && typeof item.text === 'string' &&
|
|
54
|
-
(item.text.includes('error') || item.text.includes('Error')));
|
|
55
|
-
}
|
|
56
|
-
// Type declarations are now in tests/jest.d.ts
|
|
57
|
-
describe('WindowManager', () => {
|
|
58
|
-
let agentBay;
|
|
59
|
-
let session;
|
|
60
|
-
let windowManager;
|
|
61
|
-
beforeEach(async () => {
|
|
62
|
-
// Create a real AgentBay instance with test API key
|
|
63
|
-
const apiKey = (0, test_helpers_1.getTestApiKey)();
|
|
64
|
-
agentBay = new src_1.AgentBay({ apiKey });
|
|
65
|
-
// Create a real session
|
|
66
|
-
(0, logger_1.log)('Creating a new session for window testing...');
|
|
67
|
-
session = await agentBay.create();
|
|
68
|
-
windowManager = new window_1.WindowManager(session);
|
|
69
|
-
});
|
|
70
|
-
afterEach(async () => {
|
|
71
|
-
(0, logger_1.log)('Cleaning up: Deleting the session...');
|
|
72
|
-
try {
|
|
73
|
-
if (session)
|
|
74
|
-
await agentBay.delete(session);
|
|
75
|
-
(0, logger_1.log)('Session successfully deleted');
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
(0, logger_1.log)(`Warning: Error deleting session: ${error}`);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
describe('listRootWindows()', () => {
|
|
82
|
-
it.only('should return a list of root windows', async () => {
|
|
83
|
-
(0, logger_1.log)('Testing listRootWindows...');
|
|
84
|
-
try {
|
|
85
|
-
// Call the method
|
|
86
|
-
const content = await windowManager.listRootWindows();
|
|
87
|
-
(0, logger_1.log)(`Retrieved content:`, content);
|
|
88
|
-
// Verify content format
|
|
89
|
-
expect(content).toBeDefined();
|
|
90
|
-
expect(Array.isArray(content)).toBe(true);
|
|
91
|
-
expect(hasErrorInContent(content)).toBe(false);
|
|
92
|
-
// Parse windows from content
|
|
93
|
-
const windows = parseWindowsContent(content);
|
|
94
|
-
(0, logger_1.log)(`Found ${windows.length} root windows`);
|
|
95
|
-
// Verify the results
|
|
96
|
-
if (windows.length > 0) {
|
|
97
|
-
windows.forEach((window) => {
|
|
98
|
-
expect(window.window_id).toBeDefined();
|
|
99
|
-
expect(window.title).toBeDefined();
|
|
100
|
-
expect(window.pid).toBeDefined();
|
|
101
|
-
expect(window.pname).toBeDefined();
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
(0, logger_1.log)('No windows found, this might be normal in some environments');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
catch (error) {
|
|
109
|
-
(0, logger_1.log)(`Error in listRootWindows test: ${error}`);
|
|
110
|
-
// Skip test if we can't list windows
|
|
111
|
-
expect(true).toBe(true);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
describe('getActiveWindow()', () => {
|
|
116
|
-
it.only('should return the active window', async () => {
|
|
117
|
-
(0, logger_1.log)('Testing getActiveWindow...');
|
|
118
|
-
try {
|
|
119
|
-
const content = await windowManager.getActiveWindow();
|
|
120
|
-
(0, logger_1.log)(`Active window content:`, content);
|
|
121
|
-
// Verify content format
|
|
122
|
-
expect(content).toBeDefined();
|
|
123
|
-
expect(Array.isArray(content)).toBe(true);
|
|
124
|
-
expect(hasErrorInContent(content)).toBe(false);
|
|
125
|
-
// Parse window from content
|
|
126
|
-
const window = parseWindowContent(content);
|
|
127
|
-
if (window) {
|
|
128
|
-
(0, logger_1.log)(`Active window: ${window.title} (ID: ${window.window_id})`);
|
|
129
|
-
// Verify the results
|
|
130
|
-
expect(window.window_id).toBeDefined();
|
|
131
|
-
expect(window.title).toBeDefined();
|
|
132
|
-
expect(window.pid).toBeDefined();
|
|
133
|
-
expect(window.pname).toBeDefined();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
(0, logger_1.log)(`Error in getActiveWindow test: ${error}`);
|
|
138
|
-
// Skip test if we can't get active window
|
|
139
|
-
expect(true).toBe(true);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
describe('activateWindow()', () => {
|
|
144
|
-
it.only('should activate a window', async () => {
|
|
145
|
-
(0, logger_1.log)('Testing activateWindow...');
|
|
146
|
-
try {
|
|
147
|
-
// First get a list of windows
|
|
148
|
-
const listContent = await windowManager.listRootWindows();
|
|
149
|
-
const windows = parseWindowsContent(listContent);
|
|
150
|
-
if (windows.length === 0) {
|
|
151
|
-
(0, logger_1.log)('No windows available for testing activateWindow');
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
// Use the first window for testing
|
|
155
|
-
const windowId = windows[0].window_id;
|
|
156
|
-
(0, logger_1.log)(`Activating window with ID: ${windowId}`);
|
|
157
|
-
// Call the method
|
|
158
|
-
const content = await windowManager.activateWindow(windowId);
|
|
159
|
-
(0, logger_1.log)(`Activate window content:`, content);
|
|
160
|
-
// Verify content format
|
|
161
|
-
expect(content).toBeDefined();
|
|
162
|
-
expect(Array.isArray(content)).toBe(true);
|
|
163
|
-
expect(hasErrorInContent(content)).toBe(false);
|
|
164
|
-
(0, logger_1.log)('Window activated successfully');
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
(0, logger_1.log)(`Error in activateWindow test: ${error}`);
|
|
168
|
-
// Skip test if we can't activate window
|
|
169
|
-
expect(true).toBe(true);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
describe('maximizeWindow()', () => {
|
|
174
|
-
it.only('should maximize a window', async () => {
|
|
175
|
-
(0, logger_1.log)('Testing maximizeWindow...');
|
|
176
|
-
try {
|
|
177
|
-
// First get a list of windows
|
|
178
|
-
const listContent = await windowManager.listRootWindows();
|
|
179
|
-
const windows = parseWindowsContent(listContent);
|
|
180
|
-
if (windows.length === 0) {
|
|
181
|
-
(0, logger_1.log)('No windows available for testing maximizeWindow');
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
// Use the first window for testing
|
|
185
|
-
const windowId = windows[0].window_id;
|
|
186
|
-
(0, logger_1.log)(`Maximizing window with ID: ${windowId}`);
|
|
187
|
-
// Call the method
|
|
188
|
-
const content = await windowManager.maximizeWindow(windowId);
|
|
189
|
-
(0, logger_1.log)(`Maximize window content:`, content);
|
|
190
|
-
// Verify content format
|
|
191
|
-
expect(content).toBeDefined();
|
|
192
|
-
expect(Array.isArray(content)).toBe(true);
|
|
193
|
-
expect(hasErrorInContent(content)).toBe(false);
|
|
194
|
-
(0, logger_1.log)('Window maximized successfully');
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
(0, logger_1.log)(`Error in maximizeWindow test: ${error}`);
|
|
198
|
-
// Skip test if we can't maximize window
|
|
199
|
-
expect(true).toBe(true);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
describe('minimizeWindow()', () => {
|
|
204
|
-
it.only('should minimize a window', async () => {
|
|
205
|
-
(0, logger_1.log)('Testing minimizeWindow...');
|
|
206
|
-
try {
|
|
207
|
-
// First get a list of windows
|
|
208
|
-
const listContent = await windowManager.listRootWindows();
|
|
209
|
-
const windows = parseWindowsContent(listContent);
|
|
210
|
-
if (windows.length === 0) {
|
|
211
|
-
(0, logger_1.log)('No windows available for testing minimizeWindow');
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
// Use the first window for testing
|
|
215
|
-
const windowId = windows[0].window_id;
|
|
216
|
-
(0, logger_1.log)(`Minimizing window with ID: ${windowId}`);
|
|
217
|
-
// Call the method
|
|
218
|
-
const content = await windowManager.minimizeWindow(windowId);
|
|
219
|
-
(0, logger_1.log)(`Minimize window content:`, content);
|
|
220
|
-
// Verify content format
|
|
221
|
-
expect(content).toBeDefined();
|
|
222
|
-
expect(Array.isArray(content)).toBe(true);
|
|
223
|
-
expect(hasErrorInContent(content)).toBe(false);
|
|
224
|
-
(0, logger_1.log)('Window minimized successfully');
|
|
225
|
-
}
|
|
226
|
-
catch (error) {
|
|
227
|
-
(0, logger_1.log)(`Error in minimizeWindow test: ${error}`);
|
|
228
|
-
// Skip test if we can't minimize window
|
|
229
|
-
expect(true).toBe(true);
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
describe('restoreWindow()', () => {
|
|
234
|
-
it.only('should restore a window', async () => {
|
|
235
|
-
(0, logger_1.log)('Testing restoreWindow...');
|
|
236
|
-
try {
|
|
237
|
-
// First get a list of windows
|
|
238
|
-
const listContent = await windowManager.listRootWindows();
|
|
239
|
-
const windows = parseWindowsContent(listContent);
|
|
240
|
-
if (windows.length === 0) {
|
|
241
|
-
(0, logger_1.log)('No windows available for testing restoreWindow');
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
// Use the first window for testing
|
|
245
|
-
const windowId = windows[0].window_id;
|
|
246
|
-
(0, logger_1.log)(`Restoring window with ID: ${windowId}`);
|
|
247
|
-
// Call the method
|
|
248
|
-
const content = await windowManager.restoreWindow(windowId);
|
|
249
|
-
(0, logger_1.log)(`Restore window content:`, content);
|
|
250
|
-
// Verify content format
|
|
251
|
-
expect(content).toBeDefined();
|
|
252
|
-
expect(Array.isArray(content)).toBe(true);
|
|
253
|
-
expect(hasErrorInContent(content)).toBe(false);
|
|
254
|
-
(0, logger_1.log)('Window restored successfully');
|
|
255
|
-
}
|
|
256
|
-
catch (error) {
|
|
257
|
-
(0, logger_1.log)(`Error in restoreWindow test: ${error}`);
|
|
258
|
-
// Skip test if we can't restore window
|
|
259
|
-
expect(true).toBe(true);
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
describe('resizeWindow()', () => {
|
|
264
|
-
it.only('should resize a window', async () => {
|
|
265
|
-
(0, logger_1.log)('Testing resizeWindow...');
|
|
266
|
-
try {
|
|
267
|
-
// First get a list of windows
|
|
268
|
-
const listContent = await windowManager.listRootWindows();
|
|
269
|
-
const windows = parseWindowsContent(listContent);
|
|
270
|
-
if (windows.length === 0) {
|
|
271
|
-
(0, logger_1.log)('No windows available for testing resizeWindow');
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
// Use the first window for testing
|
|
275
|
-
const windowId = windows[0].window_id;
|
|
276
|
-
(0, logger_1.log)(`Resizing window with ID: ${windowId} to 800x600`);
|
|
277
|
-
// Call the method
|
|
278
|
-
const content = await windowManager.resizeWindow(windowId, 800, 600);
|
|
279
|
-
(0, logger_1.log)(`Resize window content:`, content);
|
|
280
|
-
// Verify content format
|
|
281
|
-
expect(content).toBeDefined();
|
|
282
|
-
expect(Array.isArray(content)).toBe(true);
|
|
283
|
-
expect(hasErrorInContent(content)).toBe(false);
|
|
284
|
-
(0, logger_1.log)('Window resized successfully to 800x600');
|
|
285
|
-
}
|
|
286
|
-
catch (error) {
|
|
287
|
-
(0, logger_1.log)(`Error in resizeWindow test: ${error}`);
|
|
288
|
-
// Skip test if we can't resize window
|
|
289
|
-
expect(true).toBe(true);
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
describe('focusMode()', () => {
|
|
294
|
-
it.only('should enable focus mode', async () => {
|
|
295
|
-
(0, logger_1.log)('Testing focusMode enable...');
|
|
296
|
-
try {
|
|
297
|
-
// Call the method
|
|
298
|
-
const content = await windowManager.focusMode(true);
|
|
299
|
-
(0, logger_1.log)(`Focus mode enable content:`, content);
|
|
300
|
-
// Verify content format
|
|
301
|
-
expect(content).toBeDefined();
|
|
302
|
-
expect(Array.isArray(content)).toBe(true);
|
|
303
|
-
expect(hasErrorInContent(content)).toBe(false);
|
|
304
|
-
(0, logger_1.log)('Focus mode enabled successfully');
|
|
305
|
-
}
|
|
306
|
-
catch (error) {
|
|
307
|
-
(0, logger_1.log)(`Error in focusMode enable test: ${error}`);
|
|
308
|
-
// Skip test if we can't enable focus mode
|
|
309
|
-
expect(true).toBe(true);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
it.only('should disable focus mode', async () => {
|
|
313
|
-
(0, logger_1.log)('Testing focusMode disable...');
|
|
314
|
-
try {
|
|
315
|
-
// Call the method
|
|
316
|
-
const content = await windowManager.focusMode(false);
|
|
317
|
-
(0, logger_1.log)(`Focus mode disable content:`, content);
|
|
318
|
-
// Verify content format
|
|
319
|
-
expect(content).toBeDefined();
|
|
320
|
-
expect(Array.isArray(content)).toBe(true);
|
|
321
|
-
expect(hasErrorInContent(content)).toBe(false);
|
|
322
|
-
(0, logger_1.log)('Focus mode disabled successfully');
|
|
323
|
-
}
|
|
324
|
-
catch (error) {
|
|
325
|
-
(0, logger_1.log)(`Error in focusMode disable test: ${error}`);
|
|
326
|
-
// Skip test if we can't disable focus mode
|
|
327
|
-
expect(true).toBe(true);
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
2
|
-
/**
|
|
3
|
-
* Get API key for testing
|
|
4
|
-
* @returns The API key to use for tests
|
|
5
|
-
*/
|
|
6
|
-
export declare function getTestApiKey(): string;
|
|
7
|
-
/**
|
|
8
|
-
* Check if a string contains "tool not found"
|
|
9
|
-
* @param s The string to check
|
|
10
|
-
* @returns True if the string contains "tool not found"
|
|
11
|
-
*/
|
|
12
|
-
export declare function containsToolNotFound(s: string): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Extract resourceId from a URL
|
|
15
|
-
* @param url The URL to extract from
|
|
16
|
-
* @returns The extracted resourceId or empty string if not found
|
|
17
|
-
*/
|
|
18
|
-
export declare function extractResourceId(url: string): string;
|
|
19
|
-
/**
|
|
20
|
-
* Wait for a specified amount of time
|
|
21
|
-
* @param ms Milliseconds to wait
|
|
22
|
-
* @returns A promise that resolves after the specified time
|
|
23
|
-
*/
|
|
24
|
-
export declare function wait(ms: number): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* Generate a random string for test data
|
|
27
|
-
* @param length Length of the string to generate
|
|
28
|
-
* @returns A random string
|
|
29
|
-
*/
|
|
30
|
-
export declare function randomString(length?: number): string;
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @returns A unique ID for testing
|
|
34
|
-
*/
|
|
35
|
-
export declare function generateUniqueId(): string;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTestApiKey = getTestApiKey;
|
|
4
|
-
exports.containsToolNotFound = containsToolNotFound;
|
|
5
|
-
exports.extractResourceId = extractResourceId;
|
|
6
|
-
exports.wait = wait;
|
|
7
|
-
exports.randomString = randomString;
|
|
8
|
-
exports.generateUniqueId = generateUniqueId;
|
|
9
|
-
require("dotenv/config");
|
|
10
|
-
const logger_1 = require("../../src/utils/logger");
|
|
11
|
-
/**
|
|
12
|
-
* Get API key for testing
|
|
13
|
-
* @returns The API key to use for tests
|
|
14
|
-
*/
|
|
15
|
-
function getTestApiKey() {
|
|
16
|
-
// For Node.js environments
|
|
17
|
-
let apiKey;
|
|
18
|
-
try {
|
|
19
|
-
apiKey = process.env.AGENTBAY_API_KEY;
|
|
20
|
-
}
|
|
21
|
-
catch (e) {
|
|
22
|
-
// process is not defined in some environments
|
|
23
|
-
}
|
|
24
|
-
if (!apiKey) {
|
|
25
|
-
(0, logger_1.log)('Warning: Using default API key. Set AGENTBAY_API_KEY environment variable for testing.');
|
|
26
|
-
return 'akm-xxx'; // Replace with your test API key
|
|
27
|
-
}
|
|
28
|
-
return apiKey;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Check if a string contains "tool not found"
|
|
32
|
-
* @param s The string to check
|
|
33
|
-
* @returns True if the string contains "tool not found"
|
|
34
|
-
*/
|
|
35
|
-
function containsToolNotFound(s) {
|
|
36
|
-
return s.toLowerCase().includes('tool not found');
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Extract resourceId from a URL
|
|
40
|
-
* @param url The URL to extract from
|
|
41
|
-
* @returns The extracted resourceId or empty string if not found
|
|
42
|
-
*/
|
|
43
|
-
function extractResourceId(url) {
|
|
44
|
-
const matches = url.match(/resourceId=([^&]+)/);
|
|
45
|
-
if (matches && matches.length > 1) {
|
|
46
|
-
return matches[1];
|
|
47
|
-
}
|
|
48
|
-
return '';
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Wait for a specified amount of time
|
|
52
|
-
* @param ms Milliseconds to wait
|
|
53
|
-
* @returns A promise that resolves after the specified time
|
|
54
|
-
*/
|
|
55
|
-
function wait(ms) {
|
|
56
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Generate a random string for test data
|
|
60
|
-
* @param length Length of the string to generate
|
|
61
|
-
* @returns A random string
|
|
62
|
-
*/
|
|
63
|
-
function randomString(length = 8) {
|
|
64
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
65
|
-
let result = '';
|
|
66
|
-
for (let i = 0; i < length; i++) {
|
|
67
|
-
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
*
|
|
73
|
-
* @returns A unique ID for testing
|
|
74
|
-
*/
|
|
75
|
-
function generateUniqueId() {
|
|
76
|
-
const timestamp = Date.now() * 1000;
|
|
77
|
-
const randomPart = Math.floor(Math.random() * 10001);
|
|
78
|
-
return `${timestamp}-${randomPart}`;
|
|
79
|
-
}
|