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.
Files changed (176) hide show
  1. package/README.md +124 -61
  2. package/dist/index.cjs +6621 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.mts +2633 -0
  5. package/dist/index.d.ts +2633 -0
  6. package/dist/index.mjs +6637 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +84 -48
  9. package/dist/src/adb/adb.d.ts +0 -20
  10. package/dist/src/adb/adb.js +0 -57
  11. package/dist/src/adb/index.d.ts +0 -1
  12. package/dist/src/adb/index.js +0 -17
  13. package/dist/src/agent-bay.d.ts +0 -68
  14. package/dist/src/agent-bay.js +0 -213
  15. package/dist/src/api/client.d.ts +0 -191
  16. package/dist/src/api/client.js +0 -629
  17. package/dist/src/api/index.d.ts +0 -4
  18. package/dist/src/api/index.js +0 -26
  19. package/dist/src/api/models/CallMcpToolRequest.d.ts +0 -21
  20. package/dist/src/api/models/CallMcpToolRequest.js +0 -71
  21. package/dist/src/api/models/CallMcpToolResponse.d.ts +0 -19
  22. package/dist/src/api/models/CallMcpToolResponse.js +0 -68
  23. package/dist/src/api/models/CallMcpToolResponseBody.d.ts +0 -19
  24. package/dist/src/api/models/CallMcpToolResponseBody.js +0 -67
  25. package/dist/src/api/models/CreateMcpSessionRequest.d.ts +0 -19
  26. package/dist/src/api/models/CreateMcpSessionRequest.js +0 -67
  27. package/dist/src/api/models/CreateMcpSessionResponse.d.ts +0 -19
  28. package/dist/src/api/models/CreateMcpSessionResponse.js +0 -68
  29. package/dist/src/api/models/CreateMcpSessionResponseBody.d.ts +0 -20
  30. package/dist/src/api/models/CreateMcpSessionResponseBody.js +0 -71
  31. package/dist/src/api/models/CreateMcpSessionResponseBodyData.d.ts +0 -19
  32. package/dist/src/api/models/CreateMcpSessionResponseBodyData.js +0 -67
  33. package/dist/src/api/models/DeleteContextRequest.d.ts +0 -15
  34. package/dist/src/api/models/DeleteContextRequest.js +0 -59
  35. package/dist/src/api/models/DeleteContextResponse.d.ts +0 -19
  36. package/dist/src/api/models/DeleteContextResponse.js +0 -68
  37. package/dist/src/api/models/DeleteContextResponseBody.d.ts +0 -18
  38. package/dist/src/api/models/DeleteContextResponseBody.js +0 -65
  39. package/dist/src/api/models/GetContextRequest.d.ts +0 -16
  40. package/dist/src/api/models/GetContextRequest.js +0 -61
  41. package/dist/src/api/models/GetContextResponse.d.ts +0 -19
  42. package/dist/src/api/models/GetContextResponse.js +0 -68
  43. package/dist/src/api/models/GetContextResponseBody.d.ts +0 -20
  44. package/dist/src/api/models/GetContextResponseBody.js +0 -71
  45. package/dist/src/api/models/GetContextResponseBodyData.d.ts +0 -19
  46. package/dist/src/api/models/GetContextResponseBodyData.js +0 -67
  47. package/dist/src/api/models/GetLabelRequest.d.ts +0 -17
  48. package/dist/src/api/models/GetLabelRequest.js +0 -63
  49. package/dist/src/api/models/GetLabelResponse.d.ts +0 -19
  50. package/dist/src/api/models/GetLabelResponse.js +0 -68
  51. package/dist/src/api/models/GetLabelResponseBody.d.ts +0 -23
  52. package/dist/src/api/models/GetLabelResponseBody.js +0 -77
  53. package/dist/src/api/models/GetLabelResponseBodyData.d.ts +0 -14
  54. package/dist/src/api/models/GetLabelResponseBodyData.js +0 -57
  55. package/dist/src/api/models/GetLinkRequest.d.ts +0 -15
  56. package/dist/src/api/models/GetLinkRequest.js +0 -59
  57. package/dist/src/api/models/GetLinkResponse.d.ts +0 -19
  58. package/dist/src/api/models/GetLinkResponse.js +0 -68
  59. package/dist/src/api/models/GetLinkResponseBody.d.ts +0 -19
  60. package/dist/src/api/models/GetLinkResponseBody.js +0 -67
  61. package/dist/src/api/models/GetMcpResourceRequest.d.ts +0 -15
  62. package/dist/src/api/models/GetMcpResourceRequest.js +0 -59
  63. package/dist/src/api/models/GetMcpResourceResponse.d.ts +0 -19
  64. package/dist/src/api/models/GetMcpResourceResponse.js +0 -68
  65. package/dist/src/api/models/GetMcpResourceResponseBody.d.ts +0 -20
  66. package/dist/src/api/models/GetMcpResourceResponseBody.js +0 -71
  67. package/dist/src/api/models/GetMcpResourceResponseBodyData.d.ts +0 -17
  68. package/dist/src/api/models/GetMcpResourceResponseBodyData.js +0 -65
  69. package/dist/src/api/models/GetMcpResourceResponseBodyDataDesktopInfo.d.ts +0 -18
  70. package/dist/src/api/models/GetMcpResourceResponseBodyDataDesktopInfo.js +0 -65
  71. package/dist/src/api/models/ListContextsRequest.d.ts +0 -16
  72. package/dist/src/api/models/ListContextsRequest.js +0 -61
  73. package/dist/src/api/models/ListContextsResponse.d.ts +0 -19
  74. package/dist/src/api/models/ListContextsResponse.js +0 -68
  75. package/dist/src/api/models/ListContextsResponseBody.d.ts +0 -23
  76. package/dist/src/api/models/ListContextsResponseBody.js +0 -77
  77. package/dist/src/api/models/ListContextsResponseBodyData.d.ts +0 -19
  78. package/dist/src/api/models/ListContextsResponseBodyData.js +0 -67
  79. package/dist/src/api/models/ListSessionRequest.d.ts +0 -17
  80. package/dist/src/api/models/ListSessionRequest.js +0 -63
  81. package/dist/src/api/models/ListSessionResponse.d.ts +0 -19
  82. package/dist/src/api/models/ListSessionResponse.js +0 -68
  83. package/dist/src/api/models/ListSessionResponseBody.d.ts +0 -23
  84. package/dist/src/api/models/ListSessionResponseBody.js +0 -77
  85. package/dist/src/api/models/ListSessionResponseBodyData.d.ts +0 -14
  86. package/dist/src/api/models/ListSessionResponseBodyData.js +0 -57
  87. package/dist/src/api/models/ModifyContextRequest.d.ts +0 -16
  88. package/dist/src/api/models/ModifyContextRequest.js +0 -61
  89. package/dist/src/api/models/ModifyContextResponse.d.ts +0 -19
  90. package/dist/src/api/models/ModifyContextResponse.js +0 -68
  91. package/dist/src/api/models/ModifyContextResponseBody.d.ts +0 -18
  92. package/dist/src/api/models/ModifyContextResponseBody.js +0 -65
  93. package/dist/src/api/models/ReleaseMcpSessionRequest.d.ts +0 -15
  94. package/dist/src/api/models/ReleaseMcpSessionRequest.js +0 -59
  95. package/dist/src/api/models/ReleaseMcpSessionResponse.d.ts +0 -19
  96. package/dist/src/api/models/ReleaseMcpSessionResponse.js +0 -68
  97. package/dist/src/api/models/ReleaseMcpSessionResponseBody.d.ts +0 -18
  98. package/dist/src/api/models/ReleaseMcpSessionResponseBody.js +0 -65
  99. package/dist/src/api/models/SetLabelRequest.d.ts +0 -16
  100. package/dist/src/api/models/SetLabelRequest.js +0 -61
  101. package/dist/src/api/models/SetLabelResponse.d.ts +0 -19
  102. package/dist/src/api/models/SetLabelResponse.js +0 -68
  103. package/dist/src/api/models/SetLabelResponseBody.d.ts +0 -18
  104. package/dist/src/api/models/SetLabelResponseBody.js +0 -65
  105. package/dist/src/api/models/model.d.ts +0 -43
  106. package/dist/src/api/models/model.js +0 -89
  107. package/dist/src/application/application.d.ts +0 -88
  108. package/dist/src/application/application.js +0 -172
  109. package/dist/src/application/index.d.ts +0 -1
  110. package/dist/src/application/index.js +0 -17
  111. package/dist/src/command/command.d.ts +0 -43
  112. package/dist/src/command/command.js +0 -120
  113. package/dist/src/command/index.d.ts +0 -1
  114. package/dist/src/command/index.js +0 -17
  115. package/dist/src/config.d.ts +0 -15
  116. package/dist/src/config.js +0 -114
  117. package/dist/src/context.d.ts +0 -87
  118. package/dist/src/context.js +0 -208
  119. package/dist/src/exceptions.d.ts +0 -30
  120. package/dist/src/exceptions.js +0 -58
  121. package/dist/src/filesystem/filesystem.d.ts +0 -109
  122. package/dist/src/filesystem/filesystem.js +0 -245
  123. package/dist/src/filesystem/index.d.ts +0 -1
  124. package/dist/src/filesystem/index.js +0 -17
  125. package/dist/src/index.d.ts +0 -10
  126. package/dist/src/index.js +0 -32
  127. package/dist/src/oss/index.d.ts +0 -1
  128. package/dist/src/oss/index.js +0 -5
  129. package/dist/src/oss/oss.d.ts +0 -80
  130. package/dist/src/oss/oss.js +0 -233
  131. package/dist/src/session.d.ts +0 -99
  132. package/dist/src/session.js +0 -226
  133. package/dist/src/ui/index.d.ts +0 -1
  134. package/dist/src/ui/index.js +0 -17
  135. package/dist/src/ui/ui.d.ts +0 -95
  136. package/dist/src/ui/ui.js +0 -206
  137. package/dist/src/utils/logger.d.ts +0 -15
  138. package/dist/src/utils/logger.js +0 -48
  139. package/dist/src/window/index.d.ts +0 -1
  140. package/dist/src/window/index.js +0 -17
  141. package/dist/src/window/window.d.ts +0 -109
  142. package/dist/src/window/window.js +0 -220
  143. package/dist/tests/agent-bay.test.d.ts +0 -1
  144. package/dist/tests/agent-bay.test.js +0 -366
  145. package/dist/tests/integration/context-persistence.test.d.ts +0 -1
  146. package/dist/tests/integration/context-persistence.test.js +0 -226
  147. package/dist/tests/integration/context-session.test.d.ts +0 -1
  148. package/dist/tests/integration/context-session.test.js +0 -223
  149. package/dist/tests/integration/window-operations.test.d.ts +0 -1
  150. package/dist/tests/integration/window-operations.test.js +0 -228
  151. package/dist/tests/unit/adb.test.d.ts +0 -1
  152. package/dist/tests/unit/adb.test.js +0 -60
  153. package/dist/tests/unit/agent-bay.test.d.ts +0 -1
  154. package/dist/tests/unit/agent-bay.test.js +0 -182
  155. package/dist/tests/unit/application.test.d.ts +0 -1
  156. package/dist/tests/unit/application.test.js +0 -260
  157. package/dist/tests/unit/command.test.d.ts +0 -1
  158. package/dist/tests/unit/command.test.js +0 -252
  159. package/dist/tests/unit/context.test.d.ts +0 -1
  160. package/dist/tests/unit/context.test.js +0 -199
  161. package/dist/tests/unit/filesystem.test.d.ts +0 -1
  162. package/dist/tests/unit/filesystem.test.js +0 -493
  163. package/dist/tests/unit/oss.test.d.ts +0 -1
  164. package/dist/tests/unit/oss.test.js +0 -243
  165. package/dist/tests/unit/session-labels.test.d.ts +0 -1
  166. package/dist/tests/unit/session-labels.test.js +0 -138
  167. package/dist/tests/unit/session-params.test.d.ts +0 -1
  168. package/dist/tests/unit/session-params.test.js +0 -78
  169. package/dist/tests/unit/session.test.d.ts +0 -1
  170. package/dist/tests/unit/session.test.js +0 -204
  171. package/dist/tests/unit/ui.test.d.ts +0 -1
  172. package/dist/tests/unit/ui.test.js +0 -158
  173. package/dist/tests/unit/window.test.d.ts +0 -1
  174. package/dist/tests/unit/window.test.js +0 -331
  175. package/dist/tests/utils/test-helpers.d.ts +0 -35
  176. package/dist/tests/utils/test-helpers.js +0 -79
@@ -1,220 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WindowManager = void 0;
4
- const CallMcpToolRequest_1 = require("../api/models/CallMcpToolRequest");
5
- const logger_1 = require("../utils/logger");
6
- const exceptions_1 = require("../exceptions");
7
- /**
8
- * Handles window management operations in the AgentBay cloud environment.
9
- */
10
- class WindowManager {
11
- /**
12
- * Creates a new WindowManager instance.
13
- * @param session The session object that provides access to the AgentBay API.
14
- */
15
- constructor(session) {
16
- this.session = session;
17
- }
18
- /**
19
- * Helper method to call MCP tools and handle common response processing
20
- *
21
- * @param toolName - Name of the MCP tool to call
22
- * @param args - Arguments to pass to the tool
23
- * @param defaultErrorMsg - Default error message if specific error details are not available
24
- * @returns A CallMcpToolResult with the response data
25
- * @throws APIError if the call fails
26
- */
27
- async callMcpTool(toolName, args, defaultErrorMsg) {
28
- try {
29
- const argsJSON = JSON.stringify(args);
30
- const request = new CallMcpToolRequest_1.CallMcpToolRequest({
31
- authorization: `Bearer ${this.session.getAPIKey()}`,
32
- sessionId: this.session.getSessionId(),
33
- name: toolName,
34
- args: argsJSON
35
- });
36
- // Log API request
37
- (0, logger_1.log)(`API Call: CallMcpTool - ${toolName}`);
38
- (0, logger_1.log)(`Request: SessionId=${request.sessionId}, Args=${request.args}`);
39
- const response = await this.session.getClient().callMcpTool(request);
40
- // Log API response
41
- if (response && response.body) {
42
- (0, logger_1.log)(`Response from CallMcpTool - ${toolName}:`, response.body);
43
- }
44
- // Extract data from response
45
- if (!response.body?.data) {
46
- throw new Error('Invalid response data format');
47
- }
48
- const data = response.body.data;
49
- // Create result object
50
- const result = {
51
- data,
52
- statusCode: response.statusCode || 0,
53
- isError: false
54
- };
55
- // Check if there's an error in the response
56
- if (data.isError === true) {
57
- result.isError = true;
58
- // Try to extract the error message from the content field
59
- const contentArray = data.content;
60
- if (contentArray && contentArray.length > 0) {
61
- result.content = contentArray;
62
- // Extract error message from the first content item
63
- if (contentArray[0]?.text) {
64
- result.errorMsg = contentArray[0].text;
65
- throw new Error(contentArray[0].text);
66
- }
67
- }
68
- throw new Error(defaultErrorMsg);
69
- }
70
- // Extract content array if it exists
71
- if (Array.isArray(data.content)) {
72
- result.content = data.content;
73
- }
74
- return result;
75
- }
76
- catch (error) {
77
- (0, logger_1.logError)(`Error calling CallMcpTool - ${toolName}:`, error);
78
- throw new exceptions_1.APIError(`Failed to call ${toolName}: ${error}`);
79
- }
80
- }
81
- /**
82
- * Lists all root windows in the system.
83
- * @returns The content field from the API response
84
- * @throws Error if the operation fails.
85
- */
86
- async listRootWindows() {
87
- const args = {};
88
- const result = await this.callMcpTool('list_root_windows', args, 'Failed to list root windows');
89
- // Return the raw content field for the caller to parse
90
- return result.data.content;
91
- }
92
- /**
93
- * Gets the currently active window.
94
- * @returns The content field from the API response
95
- * @throws Error if the operation fails.
96
- */
97
- async getActiveWindow() {
98
- const args = {};
99
- const result = await this.callMcpTool('get_active_window', args, 'Failed to get active window');
100
- // Return the raw content field for the caller to parse
101
- return result.data.content;
102
- }
103
- /**
104
- * Activates a window by ID.
105
- * @param windowId The ID of the window to activate.
106
- * @returns The content field from the API response
107
- * @throws Error if the operation fails.
108
- */
109
- async activateWindow(windowId) {
110
- const args = {
111
- window_id: windowId
112
- };
113
- const result = await this.callMcpTool('activate_window', args, 'Failed to activate window');
114
- // Return the raw content field for the caller to parse
115
- return result.data.content;
116
- }
117
- /**
118
- * Maximizes a window by ID.
119
- * @param windowId The ID of the window to maximize.
120
- * @returns The content field from the API response
121
- * @throws Error if the operation fails.
122
- */
123
- async maximizeWindow(windowId) {
124
- const args = {
125
- window_id: windowId
126
- };
127
- const result = await this.callMcpTool('maximize_window', args, 'Failed to maximize window');
128
- // Return the raw content field for the caller to parse
129
- return result.data.content;
130
- }
131
- /**
132
- * Minimizes a window by ID.
133
- * @param windowId The ID of the window to minimize.
134
- * @returns The content field from the API response
135
- * @throws Error if the operation fails.
136
- */
137
- async minimizeWindow(windowId) {
138
- const args = {
139
- window_id: windowId
140
- };
141
- const result = await this.callMcpTool('minimize_window', args, 'Failed to minimize window');
142
- // Return the raw content field for the caller to parse
143
- return result.data.content;
144
- }
145
- /**
146
- * Restores a window by ID.
147
- * @param windowId The ID of the window to restore.
148
- * @returns The content field from the API response
149
- * @throws Error if the operation fails.
150
- */
151
- async restoreWindow(windowId) {
152
- const args = {
153
- window_id: windowId
154
- };
155
- const result = await this.callMcpTool('restore_window', args, 'Failed to restore window');
156
- // Return the raw content field for the caller to parse
157
- return result.data.content;
158
- }
159
- /**
160
- * Closes a window by ID.
161
- * @param windowId The ID of the window to close.
162
- * @returns The content field from the API response
163
- * @throws Error if the operation fails.
164
- */
165
- async closeWindow(windowId) {
166
- const args = {
167
- window_id: windowId
168
- };
169
- const result = await this.callMcpTool('close_window', args, 'Failed to close window');
170
- // Return the raw content field for the caller to parse
171
- return result.data.content;
172
- }
173
- /**
174
- * Sets a window to fullscreen mode.
175
- * @param windowId The ID of the window to set to fullscreen.
176
- * @returns The content field from the API response
177
- * @throws Error if the operation fails.
178
- */
179
- async fullscreenWindow(windowId) {
180
- const args = {
181
- window_id: windowId
182
- };
183
- const result = await this.callMcpTool('fullscreen_window', args, 'Failed to set window to fullscreen');
184
- // Return the raw content field for the caller to parse
185
- return result.data.content;
186
- }
187
- /**
188
- * Resizes a window by ID.
189
- * @param windowId The ID of the window to resize.
190
- * @param width The new width of the window.
191
- * @param height The new height of the window.
192
- * @returns The content field from the API response
193
- * @throws Error if the operation fails.
194
- */
195
- async resizeWindow(windowId, width, height) {
196
- const args = {
197
- window_id: windowId,
198
- width,
199
- height
200
- };
201
- const result = await this.callMcpTool('resize_window', args, 'Failed to resize window');
202
- // Return the raw content field for the caller to parse
203
- return result.data.content;
204
- }
205
- /**
206
- * Enables or disables focus mode.
207
- * @param on Whether to enable (true) or disable (false) focus mode.
208
- * @returns The content field from the API response
209
- * @throws Error if the operation fails.
210
- */
211
- async focusMode(on) {
212
- const args = {
213
- on
214
- };
215
- const result = await this.callMcpTool('focus_mode', args, 'Failed to set focus mode');
216
- // Return the raw content field for the caller to parse
217
- return result.data.content;
218
- }
219
- }
220
- exports.WindowManager = WindowManager;
@@ -1 +0,0 @@
1
- import 'dotenv/config';
@@ -1,366 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const src_1 = require("../src");
4
- require("dotenv/config");
5
- /**
6
- * Get API key for testing
7
- */
8
- function getTestApiKey() {
9
- // For Node.js environments
10
- let apiKey;
11
- try {
12
- apiKey = typeof process !== 'undefined' ? process.env.AGENTBAY_API_KEY : undefined;
13
- }
14
- catch (e) {
15
- // process is not defined in some environments
16
- }
17
- if (!apiKey) {
18
- console.log('Warning: Using default API key. Set AGENTBAY_API_KEY environment variable for testing.');
19
- return 'akm-xxx'; // Replace with your test API key
20
- }
21
- return apiKey;
22
- }
23
- describe('AgentBay', () => {
24
- describe('constructor', () => {
25
- it('should initialize with API key from options', () => {
26
- const apiKey = getTestApiKey();
27
- const agentBay = new src_1.AgentBay({ apiKey });
28
- expect(agentBay.apiKey).toBe(apiKey);
29
- });
30
- it('should initialize with API key from environment variable', () => {
31
- const originalEnv = process.env.AGENTBAY_API_KEY;
32
- process.env.AGENTBAY_API_KEY = 'env_api_key';
33
- try {
34
- const agentBay = new src_1.AgentBay();
35
- expect(agentBay.apiKey).toBe('env_api_key');
36
- }
37
- finally {
38
- // Restore original environment
39
- if (originalEnv) {
40
- process.env.AGENTBAY_API_KEY = originalEnv;
41
- }
42
- else {
43
- delete process.env.AGENTBAY_API_KEY;
44
- }
45
- }
46
- });
47
- it('should throw AuthenticationError if no API key is provided', () => {
48
- const originalEnv = process.env.AGENTBAY_API_KEY;
49
- delete process.env.AGENTBAY_API_KEY;
50
- try {
51
- expect(() => new src_1.AgentBay()).toThrow();
52
- }
53
- finally {
54
- // Restore original environment
55
- if (originalEnv) {
56
- process.env.AGENTBAY_API_KEY = originalEnv;
57
- }
58
- }
59
- });
60
- });
61
- describe('create, list, and delete', () => {
62
- let agentBay;
63
- let session;
64
- beforeEach(() => {
65
- const apiKey = getTestApiKey();
66
- agentBay = new src_1.AgentBay({ apiKey });
67
- });
68
- it('should create, list, and delete a session', async () => {
69
- // Create a session
70
- console.log('Creating a new session...');
71
- session = await agentBay.create();
72
- console.log(`Session created with ID: ${session.sessionId}`);
73
- // Ensure session ID is not empty
74
- expect(session.sessionId).toBeDefined();
75
- expect(session.sessionId.length).toBeGreaterThan(0);
76
- // List sessions
77
- console.log('Listing sessions...');
78
- const sessions = agentBay.list();
79
- // Ensure at least one session (the one we just created)
80
- expect(sessions.length).toBeGreaterThanOrEqual(1);
81
- // Check if our created session is in the list
82
- const found = sessions.some(s => s.sessionId === session.sessionId);
83
- expect(found).toBe(true);
84
- // Delete the session
85
- console.log('Deleting the session...');
86
- await agentBay.delete(session);
87
- // List sessions again to ensure it's deleted
88
- const sessionsAfterDelete = agentBay.list();
89
- // Check if the deleted session is not in the list
90
- const stillExists = sessionsAfterDelete.some(s => s.sessionId === session.sessionId);
91
- expect(stillExists).toBe(false);
92
- });
93
- });
94
- });
95
- describe('Session', () => {
96
- let agentBay;
97
- let session;
98
- beforeEach(async () => {
99
- const apiKey = getTestApiKey();
100
- agentBay = new src_1.AgentBay({ apiKey });
101
- // Create a session
102
- console.log('Creating a new session for testing...');
103
- session = await agentBay.create();
104
- console.log(`Session created with ID: ${session.sessionId}`);
105
- });
106
- afterEach(async () => {
107
- // Clean up the session
108
- console.log('Cleaning up: Deleting the session...');
109
- try {
110
- await agentBay.delete(session);
111
- }
112
- catch (error) {
113
- console.log(`Warning: Error deleting session: ${error}`);
114
- }
115
- });
116
- describe('properties', () => {
117
- it('should have valid sessionId', () => {
118
- expect(session.sessionId).toBeDefined();
119
- expect(session.sessionId.length).toBeGreaterThan(0);
120
- });
121
- it('should log resourceUrl', () => {
122
- // ResourceUrl is optional, so we just log it without checking if it's non-empty
123
- console.log(`Session resourceUrl: ${session.resourceUrl}`);
124
- });
125
- it('should have filesystem, command, and adb properties', () => {
126
- expect(session.filesystem).toBeDefined();
127
- expect(session.command).toBeDefined();
128
- expect(session.adb).toBeDefined();
129
- });
130
- });
131
- describe('methods', () => {
132
- it('should return the session ID', () => {
133
- const sessionId = session.getSessionId();
134
- expect(sessionId).toBe(session.sessionId);
135
- });
136
- it('should return the API key', () => {
137
- const apiKey = session.getAPIKey();
138
- expect(apiKey).toBe(agentBay.getAPIKey());
139
- });
140
- it('should return the client', () => {
141
- const client = session.getClient();
142
- expect(client).toBeDefined();
143
- });
144
- });
145
- describe('delete', () => {
146
- it('should delete the session', async () => {
147
- // Create a new session specifically for this test
148
- console.log('Creating a new session for delete testing...');
149
- const testSession = await agentBay.create();
150
- console.log(`Session created with ID: ${testSession.sessionId}`);
151
- // Test delete method
152
- console.log('Testing session.delete method...');
153
- try {
154
- const result = await testSession.delete();
155
- expect(result).toBe(true);
156
- // Verify the session was deleted by checking it's not in the list
157
- const sessions = agentBay.list();
158
- const stillExists = sessions.some(s => s.sessionId === testSession.sessionId);
159
- expect(stillExists).toBe(false);
160
- }
161
- catch (error) {
162
- console.log(`Note: Session deletion failed: ${error}`);
163
- // Clean up if the test failed
164
- try {
165
- await agentBay.delete(testSession);
166
- }
167
- catch {
168
- // Ignore cleanup errors
169
- }
170
- throw error;
171
- }
172
- });
173
- });
174
- describe('command', () => {
175
- it('should execute a command with default timeout', async () => {
176
- if (session.command) {
177
- console.log('Executing command with default timeout...');
178
- try {
179
- const response = await session.command.executeCommand('ls');
180
- console.log(`Command execution result: ${response}`);
181
- expect(response).toBeDefined();
182
- // Check if response contains "tool not found"
183
- expect(response.toLowerCase().includes('tool not found')).toBe(false);
184
- }
185
- catch (error) {
186
- console.log(`Note: Command execution failed: ${error}`);
187
- // Don't fail the test if command execution is not supported
188
- }
189
- }
190
- else {
191
- console.log('Note: Command interface is nil, skipping command test');
192
- }
193
- });
194
- it('should execute a command with custom timeout', async () => {
195
- if (session.command) {
196
- console.log('Executing command with custom timeout...');
197
- try {
198
- const customTimeout = 2000; // 2 seconds
199
- const response = await session.command.executeCommand('ls', customTimeout);
200
- console.log(`Command execution result with custom timeout: ${response}`);
201
- expect(response).toBeDefined();
202
- // Check if response contains "tool not found"
203
- expect(response.toLowerCase().includes('tool not found')).toBe(false);
204
- }
205
- catch (error) {
206
- console.log(`Note: Command execution with custom timeout failed: ${error}`);
207
- // Don't fail the test if command execution is not supported
208
- }
209
- }
210
- else {
211
- console.log('Note: Command interface is nil, skipping command test');
212
- }
213
- });
214
- it('should execute Python code with default timeout', async () => {
215
- if (session.command) {
216
- console.log('Executing Python code with default timeout...');
217
- try {
218
- const pythonCode = `
219
- print("Hello, world!")
220
- x = 1 + 1
221
- print(x)
222
- `;
223
- const response = await session.command.runCode(pythonCode, 'python');
224
- console.log(`Python code execution result: ${response}`);
225
- expect(response).toBeDefined();
226
- // Check if response contains "tool not found"
227
- expect(response.toLowerCase().includes('tool not found')).toBe(false);
228
- // Check if response contains expected output
229
- expect(response.includes('Hello, world!')).toBe(true);
230
- expect(response.includes('2')).toBe(true);
231
- }
232
- catch (error) {
233
- console.log(`Note: Python code execution failed: ${error}`);
234
- // Don't fail the test if code execution is not supported
235
- }
236
- }
237
- else {
238
- console.log('Note: Command interface is nil, skipping code execution test');
239
- }
240
- });
241
- it('should execute JavaScript code with custom timeout', async () => {
242
- if (session.command) {
243
- console.log('Executing JavaScript code with custom timeout...');
244
- try {
245
- const jsCode = `
246
- console.log("Hello, world!");
247
- const x = 1 + 1;
248
- console.log(x);
249
- `;
250
- const customTimeout = 600; // 10 minutes
251
- const response = await session.command.runCode(jsCode, 'javascript', customTimeout);
252
- console.log(`JavaScript code execution result: ${response}`);
253
- expect(response).toBeDefined();
254
- // Check if response contains "tool not found"
255
- expect(response.toLowerCase().includes('tool not found')).toBe(false);
256
- // Check if response contains expected output
257
- expect(response.includes('Hello, world!')).toBe(true);
258
- expect(response.includes('2')).toBe(true);
259
- }
260
- catch (error) {
261
- console.log(`Note: JavaScript code execution failed: ${error}`);
262
- // Don't fail the test if code execution is not supported
263
- }
264
- }
265
- else {
266
- console.log('Note: Command interface is nil, skipping code execution test');
267
- }
268
- });
269
- it('should reject invalid language', async () => {
270
- if (session.command) {
271
- console.log('Testing with invalid language...');
272
- try {
273
- await session.command.runCode('print("test")', 'invalid_language');
274
- // Should not reach here
275
- console.log('Error: Expected error for invalid language, but got success');
276
- expect(false).toBe(true); // Force test to fail
277
- }
278
- catch (error) {
279
- console.log(`Correctly received error for invalid language: ${error}`);
280
- expect(error).toBeDefined();
281
- expect(String(error).includes('Unsupported language')).toBe(true);
282
- }
283
- }
284
- else {
285
- console.log('Note: Command interface is nil, skipping code execution test');
286
- }
287
- });
288
- });
289
- describe('filesystem', () => {
290
- it('should read a file', async () => {
291
- if (session.filesystem) {
292
- console.log('Reading file...');
293
- try {
294
- const content = await session.filesystem.readFile('/etc/hosts');
295
- console.log(`ReadFile result: content='${content}'`);
296
- expect(content).toBeDefined();
297
- // Check if response contains "tool not found"
298
- expect(content.toLowerCase().includes('tool not found')).toBe(false);
299
- console.log('File read successful');
300
- }
301
- catch (error) {
302
- console.log(`Note: File operation failed: ${error}`);
303
- // Don't fail the test if filesystem operations are not supported
304
- }
305
- }
306
- else {
307
- console.log('Note: FileSystem interface is nil, skipping file test');
308
- }
309
- });
310
- });
311
- });
312
- describe('Adb', () => {
313
- let agentBay;
314
- let session;
315
- beforeEach(async () => {
316
- const apiKey = getTestApiKey();
317
- agentBay = new src_1.AgentBay({ apiKey });
318
- // Create a session
319
- console.log('Creating a new session for ADB testing...');
320
- session = await agentBay.create();
321
- console.log(`Session created with ID: ${session.sessionId}`);
322
- });
323
- afterEach(async () => {
324
- // Clean up the session
325
- console.log('Cleaning up: Deleting the session...');
326
- try {
327
- await agentBay.delete(session);
328
- }
329
- catch (error) {
330
- console.log(`Warning: Error deleting session: ${error}`);
331
- }
332
- });
333
- describe('shell', () => {
334
- it('should execute ADB shell commands', async () => {
335
- if (session.adb) {
336
- console.log('Executing ADB shell command...');
337
- try {
338
- const response = await session.adb.shell('ls /sdcard');
339
- console.log(`ADB shell execution result: ${response}`);
340
- expect(response).toBeDefined();
341
- // Check if response contains "tool not found"
342
- expect(response.toLowerCase().includes('tool not found')).toBe(false);
343
- }
344
- catch (error) {
345
- console.log(`Note: ADB shell execution failed: ${error}`);
346
- // Don't fail the test if ADB is not supported
347
- }
348
- // Test another ADB command
349
- try {
350
- console.log('Executing ADB shell command to check device properties...');
351
- const propResponse = await session.adb.shell('getprop');
352
- console.log(`ADB getprop execution result length: ${propResponse.length} bytes`);
353
- expect(propResponse).toBeDefined();
354
- // Check if response contains "tool not found"
355
- expect(propResponse.toLowerCase().includes('tool not found')).toBe(false);
356
- }
357
- catch (error) {
358
- console.log(`Note: ADB getprop execution failed: ${error}`);
359
- }
360
- }
361
- else {
362
- console.log('Note: Adb interface is nil, skipping ADB test');
363
- }
364
- });
365
- });
366
- });
@@ -1 +0,0 @@
1
- export {};