wuying-agentbay-sdk 0.1.0 → 0.3.3

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 +7848 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.mts +3174 -0
  5. package/dist/index.d.ts +3174 -0
  6. package/dist/index.mjs +7864 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +86 -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,260 +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
7
- function parseContentArray(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 item.text;
20
- }
21
- }
22
- return content;
23
- }
24
- describe('Application', () => {
25
- let session;
26
- let agentBay;
27
- beforeEach(async () => {
28
- const apiKey = (0, test_helpers_1.getTestApiKey)();
29
- agentBay = await new src_1.AgentBay({ apiKey });
30
- // Create a session with linux_latest image
31
- (0, logger_1.log)('Creating a new session for application testing...');
32
- const sessionParams = { imageId: 'linux_latest' };
33
- session = await agentBay.create(sessionParams);
34
- (0, logger_1.log)(`Session created with ID: ${session.sessionId}`);
35
- });
36
- afterEach(async () => {
37
- (0, logger_1.log)('Cleaning up: Deleting the session...');
38
- try {
39
- await agentBay.delete(session);
40
- (0, logger_1.log)('Session successfully deleted');
41
- }
42
- catch (error) {
43
- (0, logger_1.log)(`Warning: Error deleting session: ${error}`);
44
- }
45
- });
46
- describe('getInstalledApps()', () => {
47
- it.only('should return installed applications with valid properties', async () => {
48
- (0, logger_1.log)('Testing getInstalledApps...');
49
- const content = await session.Application.getInstalledApps(true, false, true);
50
- (0, logger_1.log)(`Retrieved content:`, content);
51
- // Parse content array to get actual applications
52
- const apps = parseContentArray(content);
53
- (0, logger_1.log)(`Found ${Array.isArray(apps) ? apps.length : 0} installed applications`);
54
- // Verify results
55
- expect(content).toBeDefined();
56
- expect(Array.isArray(content)).toBe(true);
57
- if (Array.isArray(apps) && apps.length > 0) {
58
- apps.forEach((app, index) => {
59
- (0, logger_1.log)(`Verifying app ${index + 1}: ${app.name}`);
60
- expect(app.name).toBeTruthy();
61
- expect(app.start_cmd).toBeTruthy();
62
- });
63
- }
64
- });
65
- });
66
- describe('startApp()', () => {
67
- it.only('should start an application and return processes', async () => {
68
- // Get installed apps from the remote system
69
- const appsContent = await session.Application.getInstalledApps(true, false, true);
70
- const apps = parseContentArray(appsContent);
71
- expect(appsContent).toBeDefined();
72
- expect(Array.isArray(appsContent)).toBe(true);
73
- expect(Array.isArray(apps)).toBe(true);
74
- expect(apps.length).toBeGreaterThan(0);
75
- // Try to find Terminal in the installed apps
76
- let startCmd = '';
77
- const terminalApp = apps.find((app) => app.name === 'Terminal');
78
- if (terminalApp) {
79
- startCmd = terminalApp.start_cmd;
80
- (0, logger_1.log)(`Using Terminal with start command: ${startCmd}`);
81
- }
82
- else {
83
- // Fallback to gnome-terminal if Terminal is not found
84
- startCmd = 'gnome-terminal';
85
- (0, logger_1.log)(`Terminal not found in installed apps, using default command: ${startCmd}`);
86
- }
87
- try {
88
- const processesContent = await session.Application.startApp(startCmd, '');
89
- (0, logger_1.log)('processes content:', processesContent);
90
- // Parse content array to get actual processes
91
- const processes = parseContentArray(processesContent);
92
- // Verify results
93
- expect(processesContent).toBeDefined();
94
- expect(Array.isArray(processesContent)).toBe(true);
95
- if (Array.isArray(processes) && processes.length > 0) {
96
- processes.forEach((proc, index) => {
97
- (0, logger_1.log)(`Verifying process ${index + 1}: ${proc.pname} (PID: ${proc.pid})`);
98
- expect(proc.pname).toBeTruthy();
99
- expect(proc.pid).toBeGreaterThan(0);
100
- expect(proc).toHaveProperty('cmdline');
101
- });
102
- }
103
- }
104
- catch (error) {
105
- (0, logger_1.log)(`Note: Failed to start application: ${error}`);
106
- // Skip test if we can't start the application
107
- expect(true).toBe(true);
108
- }
109
- });
110
- });
111
- describe('stopAppByPName()', () => {
112
- it.only('should stop an application by process name', async () => {
113
- try {
114
- // Get installed apps from the remote system
115
- const appsContent = await session.Application.getInstalledApps(true, false, true);
116
- const apps = parseContentArray(appsContent);
117
- expect(appsContent).toBeDefined();
118
- expect(Array.isArray(appsContent)).toBe(true);
119
- expect(Array.isArray(apps)).toBe(true);
120
- expect(apps.length).toBeGreaterThan(0);
121
- // Try to find Terminal in the installed apps
122
- let startCmd = '';
123
- const terminalApp = apps.find((app) => app.name === 'Terminal');
124
- if (terminalApp) {
125
- startCmd = terminalApp.start_cmd;
126
- (0, logger_1.log)(`Using Terminal with start command: ${startCmd}`);
127
- }
128
- else {
129
- // Fallback to gnome-terminal if Terminal is not found
130
- startCmd = 'gnome-terminal';
131
- (0, logger_1.log)(`Terminal not found in installed apps, using default command: ${startCmd}`);
132
- }
133
- const processesContent = await session.Application.startApp(startCmd, '');
134
- const processes = parseContentArray(processesContent);
135
- expect(processesContent).toBeDefined();
136
- expect(Array.isArray(processesContent)).toBe(true);
137
- expect(Array.isArray(processes)).toBe(true);
138
- expect(processes.length).toBeGreaterThan(0);
139
- const pname = processes[0].pname;
140
- (0, logger_1.log)('pname', pname);
141
- const resultContent = await session.Application.stopAppByPName(pname);
142
- (0, logger_1.log)('stopAppByPName Response:', resultContent);
143
- expect(resultContent).toBeDefined();
144
- expect(Array.isArray(resultContent)).toBe(true);
145
- }
146
- catch (error) {
147
- (0, logger_1.log)(`Note: Failed to stop application by process name: ${error}`);
148
- // Skip test if we can't stop the application
149
- expect(true).toBe(true);
150
- }
151
- });
152
- });
153
- describe('stopAppByPID()', () => {
154
- it.only('should stop an application by process ID', async () => {
155
- try {
156
- // Get installed apps from the remote system
157
- const appsContent = await session.Application.getInstalledApps(true, false, true);
158
- const apps = parseContentArray(appsContent);
159
- expect(appsContent).toBeDefined();
160
- expect(Array.isArray(appsContent)).toBe(true);
161
- expect(Array.isArray(apps)).toBe(true);
162
- expect(apps.length).toBeGreaterThan(0);
163
- // Try to find Terminal in the installed apps
164
- let startCmd = '';
165
- const terminalApp = apps.find((app) => app.name === 'Terminal');
166
- if (terminalApp) {
167
- startCmd = terminalApp.start_cmd;
168
- (0, logger_1.log)(`Using Terminal with start command: ${startCmd}`);
169
- }
170
- else {
171
- // Fallback to gnome-terminal if Terminal is not found
172
- startCmd = 'gnome-terminal';
173
- (0, logger_1.log)(`Terminal not found in installed apps, using default command: ${startCmd}`);
174
- }
175
- const processesContent = await session.Application.startApp(startCmd, '');
176
- const processes = parseContentArray(processesContent);
177
- expect(processesContent).toBeDefined();
178
- expect(Array.isArray(processesContent)).toBe(true);
179
- expect(Array.isArray(processes)).toBe(true);
180
- expect(processes.length).toBeGreaterThan(0);
181
- // Wait 5 seconds to give the application time to open
182
- (0, logger_1.log)('Waiting 5 seconds to give applications time to open...');
183
- await new Promise(resolve => setTimeout(resolve, 5000));
184
- const pid = processes[0].pid;
185
- const pname = processes[0].pname;
186
- (0, logger_1.log)(`Stopping application with PID: ${pid} and name: ${pname}`);
187
- const resultContent = await session.Application.stopAppByPID(pid);
188
- (0, logger_1.log)('stopAppByPID Response:', resultContent);
189
- expect(resultContent).toBeDefined();
190
- expect(Array.isArray(resultContent)).toBe(true);
191
- // Wait 5 seconds to ensure the application has time to close
192
- (0, logger_1.log)('Waiting 5 seconds to ensure the application has closed...');
193
- await new Promise(resolve => setTimeout(resolve, 5000));
194
- // Verify the app is no longer visible by using listVisibleApps
195
- const visibleAppsContent = await session.Application.listVisibleApps();
196
- const visibleApps = parseContentArray(visibleAppsContent);
197
- (0, logger_1.log)(`Found ${Array.isArray(visibleApps) ? visibleApps.length : 0} visible applications after stopping`);
198
- // Check that the app with the stopped PID is no longer in the list
199
- const stoppedAppStillVisible = Array.isArray(visibleApps) && visibleApps.some((app) => app.pid === pid);
200
- (0, logger_1.log)(`Is the stopped app still visible? ${stoppedAppStillVisible}`);
201
- expect(stoppedAppStillVisible).toBe(false);
202
- }
203
- catch (error) {
204
- (0, logger_1.log)(`Note: Failed to stop application by PID: ${error}`);
205
- // Skip test if we can't stop the application
206
- expect(true).toBe(true);
207
- }
208
- });
209
- });
210
- describe('listVisibleApps()', () => {
211
- it.only('should list visible applications with valid properties', async () => {
212
- try {
213
- // First, start an application (Terminal) to ensure there's at least one visible app
214
- // Get installed apps from the remote system
215
- const appsContent = await session.Application.getInstalledApps(true, false, true);
216
- const apps = parseContentArray(appsContent);
217
- expect(appsContent).toBeDefined();
218
- expect(Array.isArray(appsContent)).toBe(true);
219
- expect(Array.isArray(apps)).toBe(true);
220
- expect(apps.length).toBeGreaterThan(0);
221
- // Try to find Terminal in the installed apps
222
- let startCmd = '';
223
- const terminalApp = apps.find((app) => app.name === 'Terminal');
224
- if (terminalApp) {
225
- startCmd = terminalApp.start_cmd;
226
- (0, logger_1.log)(`Using Terminal with start command: ${startCmd}`);
227
- }
228
- else {
229
- // Fallback to gnome-terminal if Terminal is not found
230
- startCmd = 'gnome-terminal';
231
- (0, logger_1.log)(`Terminal not found in installed apps, using default command: ${startCmd}`);
232
- }
233
- // Start the application
234
- const startedProcessesContent = await session.Application.startApp(startCmd, '');
235
- const startedProcesses = parseContentArray(startedProcessesContent);
236
- (0, logger_1.log)(`Started application with ${Array.isArray(startedProcesses) ? startedProcesses.length : 0} processes`);
237
- // Wait 5 seconds to give the application time to open
238
- (0, logger_1.log)('Waiting 5 seconds to give applications time to open...');
239
- await new Promise(resolve => setTimeout(resolve, 5000));
240
- // Now list visible applications
241
- const processesContent = await session.Application.listVisibleApps();
242
- const processes = parseContentArray(processesContent);
243
- (0, logger_1.log)(`Found ${Array.isArray(processes) ? processes.length : 0} visible applications`);
244
- expect(processesContent).toBeDefined();
245
- expect(Array.isArray(processesContent)).toBe(true);
246
- if (Array.isArray(processes) && processes.length > 0) {
247
- processes.forEach((proc) => {
248
- expect(proc.pname).toBeTruthy();
249
- expect(proc.pid).toBeGreaterThan(0);
250
- });
251
- }
252
- }
253
- catch (error) {
254
- (0, logger_1.log)(`Note: Failed to list visible applications: ${error}`);
255
- // Skip test if we can't list visible applications
256
- expect(true).toBe(true);
257
- }
258
- });
259
- });
260
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,252 +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 extract text from content array
7
- function extractTextFromContent(content) {
8
- if (!Array.isArray(content) || content.length === 0) {
9
- return '';
10
- }
11
- // Concatenate all text fields from content items
12
- let fullText = '';
13
- for (const item of content) {
14
- if (item && typeof item === 'object' && typeof item.text === 'string') {
15
- fullText += item.text;
16
- }
17
- }
18
- return fullText;
19
- }
20
- // Helper function to check if content has error
21
- function hasErrorInContent(content) {
22
- if (!Array.isArray(content)) {
23
- return true;
24
- }
25
- if (content.length === 0) {
26
- return true;
27
- }
28
- // Check if first content item has error text
29
- return content.some(item => item && typeof item === 'object' &&
30
- item.text && typeof item.text === 'string' &&
31
- (item.text.includes('error') || item.text.includes('Error')));
32
- }
33
- describe('Command', () => {
34
- describe('runCode', () => {
35
- let agentBay;
36
- let session;
37
- beforeEach(async () => {
38
- const apiKey = (0, test_helpers_1.getTestApiKey)();
39
- agentBay = new src_1.AgentBay({ apiKey });
40
- // Create a session with linux_latest image
41
- (0, logger_1.log)('Creating a new session for run_code testing...');
42
- const sessionParams = { imageId: 'code_latest' };
43
- session = await agentBay.create(sessionParams);
44
- (0, logger_1.log)(`Session created with ID: ${session.sessionId}`);
45
- });
46
- afterEach(async () => {
47
- // Clean up the session
48
- (0, logger_1.log)('Cleaning up: Deleting the session...');
49
- try {
50
- if (session && session.sessionId)
51
- await agentBay.delete(session);
52
- }
53
- catch (error) {
54
- (0, logger_1.log)(`Warning: Error deleting session: ${error}`);
55
- }
56
- });
57
- it.only('should execute Python code', async () => {
58
- if (session.command) {
59
- // Test with Python code
60
- (0, logger_1.log)('Executing Python code...');
61
- const pythonCode = `
62
- print("Hello, world!")
63
- x = 1 + 1
64
- print(x)
65
- `;
66
- try {
67
- // Test with default timeout
68
- const content = await session.command.runCode(pythonCode, 'python');
69
- (0, logger_1.log)(`Python code execution content:`, content);
70
- // Check if content has valid format
71
- expect(content).toBeDefined();
72
- expect(Array.isArray(content)).toBe(true);
73
- expect(hasErrorInContent(content)).toBe(false);
74
- // Extract text from content
75
- const outputText = extractTextFromContent(content);
76
- // Verify the response contains expected output
77
- expect(outputText.includes('Hello, world!')).toBe(true);
78
- expect(outputText.includes('2')).toBe(true);
79
- (0, logger_1.log)('Python code execution verified successfully');
80
- }
81
- catch (error) {
82
- (0, logger_1.log)(`Note: Python code execution failed: ${error}`);
83
- // Don't fail the test if code execution is not supported
84
- }
85
- }
86
- else {
87
- (0, logger_1.log)('Note: Command interface is nil, skipping run_code test');
88
- }
89
- });
90
- it.only('should execute JavaScript code with custom timeout', async () => {
91
- if (session.command) {
92
- // Test with JavaScript code
93
- (0, logger_1.log)('Executing JavaScript code with custom timeout...');
94
- const jsCode = `
95
- console.log("Hello, world!");
96
- const x = 1 + 1;
97
- console.log(x);
98
- `;
99
- try {
100
- // Test with custom timeout (10 minutes)
101
- const customTimeout = 600;
102
- const content = await session.command.runCode(jsCode, 'javascript', customTimeout);
103
- (0, logger_1.log)(`JavaScript code execution content:`, content);
104
- // Check if content has valid format
105
- expect(content).toBeDefined();
106
- expect(Array.isArray(content)).toBe(true);
107
- expect(hasErrorInContent(content)).toBe(false);
108
- // Extract text from content
109
- const outputText = extractTextFromContent(content);
110
- // Verify the response contains expected output
111
- expect(outputText.includes('Hello, world!')).toBe(true);
112
- expect(outputText.includes('2')).toBe(true);
113
- (0, logger_1.log)('JavaScript code execution verified successfully');
114
- }
115
- catch (error) {
116
- (0, logger_1.log)(`Note: JavaScript code execution failed: ${error}`);
117
- // Don't fail the test if code execution is not supported
118
- }
119
- }
120
- else {
121
- (0, logger_1.log)('Note: Command interface is nil, skipping run_code test');
122
- }
123
- });
124
- it.only('should handle invalid language', async () => {
125
- if (session.command) {
126
- // Test with invalid language
127
- (0, logger_1.log)('Testing with invalid language...');
128
- try {
129
- await session.command.runCode('print("test")', 'invalid_language');
130
- // If we get here, the test should fail
131
- (0, logger_1.log)('Error: Expected error for invalid language, but got success');
132
- expect(false).toBe(true); // This should fail the test
133
- }
134
- catch (error) {
135
- // This is the expected behavior
136
- (0, logger_1.log)(`Correctly received error for invalid language: ${error}`);
137
- expect(error).toBeDefined();
138
- }
139
- }
140
- else {
141
- (0, logger_1.log)('Note: Command interface is nil, skipping run_code test');
142
- }
143
- });
144
- });
145
- describe('executeCommand', () => {
146
- let agentBay;
147
- let session;
148
- beforeEach(async () => {
149
- const apiKey = (0, test_helpers_1.getTestApiKey)();
150
- agentBay = new src_1.AgentBay({ apiKey });
151
- // Create a session with linux_latest image
152
- (0, logger_1.log)('Creating a new session for command testing...');
153
- const sessionParams = { imageId: 'linux_latest' };
154
- session = await agentBay.create(sessionParams);
155
- (0, logger_1.log)(`Session created with ID: ${session.sessionId}`);
156
- });
157
- afterEach(async () => {
158
- // Clean up the session
159
- (0, logger_1.log)('Cleaning up: Deleting the session...');
160
- try {
161
- if (session && session.sessionId)
162
- await agentBay.delete(session);
163
- }
164
- catch (error) {
165
- (0, logger_1.log)(`Warning: Error deleting session: ${error}`);
166
- }
167
- });
168
- it.only('should execute a command', async () => {
169
- if (session.command) {
170
- // Test with echo command (works on all platforms)
171
- (0, logger_1.log)('Executing echo command...');
172
- const testString = 'AgentBay SDK Test';
173
- const echoCmd = `echo '${testString}'`;
174
- try {
175
- // Increase the command execution timeout to 10 seconds (10000ms)
176
- const content = await session.command.executeCommand(echoCmd, 10000);
177
- (0, logger_1.log)(`Echo command content:`, content);
178
- // Check if content has valid format
179
- expect(content).toBeDefined();
180
- expect(Array.isArray(content)).toBe(true);
181
- expect(hasErrorInContent(content)).toBe(false);
182
- // Extract text from content
183
- const outputText = extractTextFromContent(content);
184
- // Verify the response contains the test string
185
- expect(outputText.includes(testString)).toBe(true);
186
- (0, logger_1.log)('Echo command verified successfully');
187
- }
188
- catch (error) {
189
- (0, logger_1.log)(`Note: Echo command failed: ${error}`);
190
- // Don't fail the test if command execution is not supported
191
- }
192
- }
193
- else {
194
- (0, logger_1.log)('Note: Command interface is nil, skipping command test');
195
- }
196
- });
197
- it.only('should handle command execution errors', async () => {
198
- if (session.command) {
199
- // Test with an invalid command
200
- (0, logger_1.log)('Executing invalid command...');
201
- const invalidCmd = 'invalid_command_that_does_not_exist';
202
- try {
203
- const content = await session.command.executeCommand(invalidCmd);
204
- (0, logger_1.log)(`Invalid command content:`, content);
205
- // Just check that we got a content array back
206
- expect(content).toBeDefined();
207
- expect(Array.isArray(content)).toBe(true);
208
- // For invalid commands, the content may contain error information, which is fine
209
- }
210
- catch (error) {
211
- // If the API rejects the promise, that's also an acceptable behavior for an invalid command
212
- (0, logger_1.log)(`Invalid command failed as expected: ${error}`);
213
- expect(error).toBeDefined();
214
- }
215
- }
216
- else {
217
- (0, logger_1.log)('Note: Command interface is nil, skipping command error test');
218
- }
219
- });
220
- it.only('should execute a command with arguments', async () => {
221
- if (session.command) {
222
- // Test with a command that takes arguments
223
- (0, logger_1.log)('Executing command with arguments...');
224
- const arg1 = 'hello';
225
- const arg2 = 'world';
226
- const cmd = `echo ${arg1} ${arg2}`;
227
- try {
228
- // Increase the command execution timeout to 10 seconds (10000ms)
229
- const content = await session.command.executeCommand(cmd, 10000);
230
- (0, logger_1.log)(`Command with arguments content:`, content);
231
- // Check if content has valid format
232
- expect(content).toBeDefined();
233
- expect(Array.isArray(content)).toBe(true);
234
- expect(hasErrorInContent(content)).toBe(false);
235
- // Extract text from content
236
- const outputText = extractTextFromContent(content);
237
- // Verify the response contains both arguments
238
- expect(outputText.includes(arg1)).toBe(true);
239
- expect(outputText.includes(arg2)).toBe(true);
240
- (0, logger_1.log)('Command with arguments verified successfully');
241
- }
242
- catch (error) {
243
- (0, logger_1.log)(`Note: Command with arguments failed: ${error}`);
244
- // Don't fail the test if command execution is not supported
245
- }
246
- }
247
- else {
248
- (0, logger_1.log)('Note: Command interface is nil, skipping command with arguments test');
249
- }
250
- });
251
- });
252
- });
@@ -1 +0,0 @@
1
- export {};