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,172 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Application = 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 application management operations in the AgentBay cloud environment.
9
- */
10
- class Application {
11
- /**
12
- * Creates a new Application 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 client = this.session.getClient();
40
- const response = await client.callMcpTool(request);
41
- // Log API response
42
- if (response && response.body) {
43
- (0, logger_1.log)(`Response from CallMcpTool - ${toolName}:`, response.body);
44
- }
45
- // Extract data from response
46
- if (!response.body?.data) {
47
- throw new Error('Invalid response data format');
48
- }
49
- const data = response.body.data;
50
- // Create result object
51
- const result = {
52
- data,
53
- statusCode: response.statusCode || 0,
54
- isError: false
55
- };
56
- // Check if there's an error in the response
57
- if (data.isError === true) {
58
- result.isError = true;
59
- // Try to extract the error message from the content field
60
- const contentArray = data.content;
61
- if (contentArray && contentArray.length > 0) {
62
- result.content = contentArray;
63
- // Extract error message from the first content item
64
- if (contentArray[0]?.text) {
65
- result.errorMsg = contentArray[0].text;
66
- throw new Error(contentArray[0].text);
67
- }
68
- }
69
- throw new Error(defaultErrorMsg);
70
- }
71
- // Extract content array if it exists
72
- if (Array.isArray(data.content)) {
73
- result.content = data.content;
74
- }
75
- return result;
76
- }
77
- catch (error) {
78
- (0, logger_1.logError)(`Error calling CallMcpTool - ${toolName}:`, error);
79
- throw new exceptions_1.APIError(`Failed to call ${toolName}: ${error}`);
80
- }
81
- }
82
- /**
83
- * Retrieves a list of installed applications.
84
- * @param startMenu Whether to include applications from the start menu. Defaults to true.
85
- * @param desktop Whether to include applications from the desktop. Defaults to true.
86
- * @param ignoreSystemApps Whether to ignore system applications. Defaults to true.
87
- * @returns The content field from the API response
88
- * @throws Error if the operation fails.
89
- */
90
- async getInstalledApps(startMenu = true, desktop = true, ignoreSystemApps = true) {
91
- const args = {
92
- start_menu: startMenu,
93
- desktop,
94
- ignore_system_apps: ignoreSystemApps
95
- };
96
- const result = await this.callMcpTool('get_installed_apps', args, 'Failed to get installed apps');
97
- // Return the raw content field for the caller to parse
98
- return result.data.content;
99
- }
100
- /**
101
- * Starts an application with the given command and optional working directory.
102
- * @param startCmd The command to start the application.
103
- * @param workDirectory The working directory for the application. Defaults to an empty string.
104
- * @returns The content field from the API response
105
- * @throws Error if the operation fails.
106
- */
107
- async startApp(startCmd, workDirectory = '') {
108
- const args = {
109
- start_cmd: startCmd
110
- };
111
- if (workDirectory) {
112
- args.work_directory = workDirectory;
113
- }
114
- const result = await this.callMcpTool('start_app', args, 'Failed to start app');
115
- // Return the raw content field for the caller to parse
116
- return result.data.content;
117
- }
118
- /**
119
- * Stops an application by process name.
120
- * @param pname The name of the process to stop.
121
- * @returns The content field from the API response
122
- * @throws Error if the operation fails.
123
- */
124
- async stopAppByPName(pname) {
125
- const args = {
126
- pname
127
- };
128
- const result = await this.callMcpTool('stop_app_by_pname', args, 'Failed to stop app by pname');
129
- // Return the raw content field for the caller to parse
130
- return result.data.content;
131
- }
132
- /**
133
- * Stops an application by process ID.
134
- * @param pid The ID of the process to stop.
135
- * @returns The content field from the API response
136
- * @throws Error if the operation fails.
137
- */
138
- async stopAppByPID(pid) {
139
- const args = {
140
- pid
141
- };
142
- const result = await this.callMcpTool('stop_app_by_pid', args, 'Failed to stop app by pid');
143
- // Return the raw content field for the caller to parse
144
- return result.data.content;
145
- }
146
- /**
147
- * Stops an application by stop command.
148
- * @param stopCmd The command to stop the application.
149
- * @returns The content field from the API response
150
- * @throws Error if the operation fails.
151
- */
152
- async stopAppByCmd(stopCmd) {
153
- const args = {
154
- stop_cmd: stopCmd
155
- };
156
- const result = await this.callMcpTool('stop_app_by_cmd', args, 'Failed to stop app by command');
157
- // Return the raw content field for the caller to parse
158
- return result.data.content;
159
- }
160
- /**
161
- * Lists all currently visible applications.
162
- * @returns The content field from the API response
163
- * @throws Error if the operation fails.
164
- */
165
- async listVisibleApps() {
166
- const args = {};
167
- const result = await this.callMcpTool('list_visible_apps', args, 'Failed to list visible apps');
168
- // Return the raw content field for the caller to parse
169
- return result.data.content;
170
- }
171
- }
172
- exports.Application = Application;
@@ -1 +0,0 @@
1
- export * from './application';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./application"), exports);
@@ -1,43 +0,0 @@
1
- import { Session } from '../session';
2
- /**
3
- * Handles command execution operations in the AgentBay cloud environment.
4
- */
5
- export declare class Command {
6
- private session;
7
- private client;
8
- private baseUrl;
9
- /**
10
- * Initialize a Command object.
11
- *
12
- * @param session - The Session instance that this Command belongs to.
13
- */
14
- constructor(session: Session);
15
- /**
16
- * Helper method to call MCP tools and handle common response processing
17
- *
18
- * @param toolName - Name of the MCP tool to call
19
- * @param args - Arguments to pass to the tool
20
- * @param defaultErrorMsg - Default error message if specific error details are not available
21
- * @returns A CallMcpToolResult with the response data
22
- * @throws APIError if the call fails
23
- */
24
- private callMcpTool;
25
- /**
26
- * Execute a command in the cloud environment with a specified timeout.
27
- *
28
- * @param command - The command to execute.
29
- * @param timeoutMs - The timeout for the command execution in milliseconds. Default is 1000ms.
30
- * @returns The content field from the API response
31
- */
32
- executeCommand(command: string, timeoutMs?: number): Promise<any>;
33
- /**
34
- * Execute code in the specified language with a timeout.
35
- *
36
- * @param code - The code to execute.
37
- * @param language - The programming language of the code. Must be either 'python' or 'javascript'.
38
- * @param timeoutS - The timeout for the code execution in seconds. Default is 300s.
39
- * @returns The content field from the API response
40
- * @throws APIError if the code execution fails or if an unsupported language is specified.
41
- */
42
- runCode(code: string, language: string, timeoutS?: number): Promise<any>;
43
- }
@@ -1,120 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Command = void 0;
4
- const exceptions_1 = require("../exceptions");
5
- const model_1 = require("../api/models/model");
6
- const logger_1 = require("../utils/logger");
7
- /**
8
- * Handles command execution operations in the AgentBay cloud environment.
9
- */
10
- class Command {
11
- /**
12
- * Initialize a Command object.
13
- *
14
- * @param session - The Session instance that this Command belongs to.
15
- */
16
- constructor(session) {
17
- this.session = session;
18
- }
19
- /**
20
- * Helper method to call MCP tools and handle common response processing
21
- *
22
- * @param toolName - Name of the MCP tool to call
23
- * @param args - Arguments to pass to the tool
24
- * @param defaultErrorMsg - Default error message if specific error details are not available
25
- * @returns A CallMcpToolResult with the response data
26
- * @throws APIError if the call fails
27
- */
28
- async callMcpTool(toolName, args, defaultErrorMsg) {
29
- try {
30
- const argsJSON = JSON.stringify(args);
31
- const callToolRequest = new model_1.CallMcpToolRequest({
32
- authorization: `Bearer ${this.session.getAPIKey()}`,
33
- sessionId: this.session.getSessionId(),
34
- name: toolName,
35
- args: argsJSON
36
- });
37
- // Log API request
38
- (0, logger_1.log)(`API Call: CallMcpTool - ${toolName}`);
39
- (0, logger_1.log)(`Request: SessionId=${this.session.getSessionId()}, Args=${argsJSON}`);
40
- const response = await this.session.getClient().callMcpTool(callToolRequest);
41
- // Log API response
42
- (0, logger_1.log)(`Response from CallMcpTool - ${toolName}:`, response.body);
43
- if (!response.body?.data) {
44
- throw new Error('Invalid response data format');
45
- }
46
- // Extract data from response
47
- const data = response.body.data;
48
- // Create result object
49
- const result = {
50
- data,
51
- statusCode: response.statusCode || 0,
52
- isError: false
53
- };
54
- // Check if there's an error in the response
55
- if (data.isError === true) {
56
- result.isError = true;
57
- // Try to extract the error message from the content field
58
- const contentArray = data.content;
59
- if (contentArray && contentArray.length > 0) {
60
- result.content = contentArray;
61
- // Extract error message from the first content item
62
- if (contentArray[0]?.text) {
63
- result.errorMsg = contentArray[0].text;
64
- throw new Error(contentArray[0].text);
65
- }
66
- }
67
- throw new Error(defaultErrorMsg);
68
- }
69
- // Extract content array if it exists
70
- if (Array.isArray(data.content)) {
71
- result.content = data.content;
72
- }
73
- return result;
74
- }
75
- catch (error) {
76
- (0, logger_1.logError)(`Error calling CallMcpTool - ${toolName}:`, error);
77
- throw new exceptions_1.APIError(`Failed to call ${toolName}: ${error}`);
78
- }
79
- }
80
- /**
81
- * Execute a command in the cloud environment with a specified timeout.
82
- *
83
- * @param command - The command to execute.
84
- * @param timeoutMs - The timeout for the command execution in milliseconds. Default is 1000ms.
85
- * @returns The content field from the API response
86
- */
87
- async executeCommand(command, timeoutMs = 1000) {
88
- const args = {
89
- command,
90
- timeout_ms: timeoutMs
91
- };
92
- const result = await this.callMcpTool('shell', args, 'Failed to execute command');
93
- // Return the raw content field for the caller to parse
94
- return result.data.content;
95
- }
96
- /**
97
- * Execute code in the specified language with a timeout.
98
- *
99
- * @param code - The code to execute.
100
- * @param language - The programming language of the code. Must be either 'python' or 'javascript'.
101
- * @param timeoutS - The timeout for the code execution in seconds. Default is 300s.
102
- * @returns The content field from the API response
103
- * @throws APIError if the code execution fails or if an unsupported language is specified.
104
- */
105
- async runCode(code, language, timeoutS = 300) {
106
- // Validate language
107
- if (language !== 'python' && language !== 'javascript') {
108
- throw new Error(`Unsupported language: ${language}. Supported languages are 'python' and 'javascript'`);
109
- }
110
- const args = {
111
- code,
112
- language,
113
- timeout_s: timeoutS
114
- };
115
- const result = await this.callMcpTool('run_code', args, 'Failed to execute code');
116
- // Return the raw content field for the caller to parse
117
- return result.data.content;
118
- }
119
- }
120
- exports.Command = Command;
@@ -1 +0,0 @@
1
- export * from './command';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./command"), exports);
@@ -1,15 +0,0 @@
1
- import 'dotenv/config';
2
- interface Config {
3
- region_id: string;
4
- endpoint: string;
5
- timeout_ms: number;
6
- }
7
- /**
8
- * Returns the default configuration
9
- */
10
- export declare function defaultConfig(): Config;
11
- /**
12
- * Loads configuration from file
13
- */
14
- export declare function loadConfig(): Config;
15
- export {};
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.defaultConfig = defaultConfig;
37
- exports.loadConfig = loadConfig;
38
- const fs = __importStar(require("fs"));
39
- const path = __importStar(require("path"));
40
- require("dotenv/config");
41
- const logger_1 = require("./utils/logger");
42
- /**
43
- * Returns the default configuration
44
- */
45
- function defaultConfig() {
46
- return {
47
- region_id: 'cn-shanghai',
48
- endpoint: 'wuyingai.cn-shanghai.aliyuncs.com',
49
- timeout_ms: 60000
50
- };
51
- }
52
- /**
53
- * Loads configuration from file
54
- */
55
- function loadConfig() {
56
- // First check if the config file path is specified in environment variables
57
- let configPath = process.env.AGENTBAY_CONFIG_PATH;
58
- if (!configPath) {
59
- try {
60
- // Try to find the config file by traversing up from the current directory
61
- let dirPath = process.cwd();
62
- let found = false;
63
- // Start from current directory and traverse up to find .config.json
64
- // This will check current dir, parent, grandparent, etc. up to filesystem root
65
- for (let i = 0; i < 10; i++) { // Limit search depth to prevent infinite loop
66
- const possibleConfigPath = path.join(dirPath, '.config.json');
67
- if (fs.existsSync(possibleConfigPath)) {
68
- configPath = possibleConfigPath;
69
- found = true;
70
- (0, logger_1.log)(`Found config file at: ${possibleConfigPath}`);
71
- break;
72
- }
73
- // Move up one directory
74
- const parentDir = path.dirname(dirPath);
75
- if (parentDir === dirPath) {
76
- // We've reached the filesystem root
77
- break;
78
- }
79
- dirPath = parentDir;
80
- }
81
- if (!found) {
82
- // Config file not found, return default config
83
- (0, logger_1.log)('Warning: Configuration file not found, using default values');
84
- return defaultConfig();
85
- }
86
- }
87
- catch (error) {
88
- (0, logger_1.log)(`Warning: Failed to search for configuration file: ${error}, using default values`);
89
- return defaultConfig();
90
- }
91
- }
92
- try {
93
- // Make sure configPath is defined
94
- if (!configPath) {
95
- (0, logger_1.log)('Warning: Configuration file path is undefined, using default values');
96
- return defaultConfig();
97
- }
98
- // Read the config file
99
- const data = fs.readFileSync(configPath, 'utf8');
100
- const config = JSON.parse(data);
101
- // Allow environment variables to override config file values
102
- if (process.env.AGENTBAY_REGION_ID) {
103
- config.region_id = process.env.AGENTBAY_REGION_ID;
104
- }
105
- if (process.env.AGENTBAY_ENDPOINT) {
106
- config.endpoint = process.env.AGENTBAY_ENDPOINT;
107
- }
108
- return config;
109
- }
110
- catch (error) {
111
- (0, logger_1.log)(`Warning: Failed to read configuration file: ${error}, using default values`);
112
- return defaultConfig();
113
- }
114
- }
@@ -1,87 +0,0 @@
1
- import { AgentBay } from './agent-bay';
2
- /**
3
- * Represents a persistent storage context in the AgentBay cloud environment.
4
- */
5
- export declare class Context {
6
- /**
7
- * The unique identifier of the context.
8
- */
9
- id: string;
10
- /**
11
- * The name of the context.
12
- */
13
- name: string;
14
- /**
15
- * The current state of the context (e.g., "available", "in-use").
16
- */
17
- state: string;
18
- /**
19
- * Date and time when the Context was created.
20
- */
21
- createdAt?: string;
22
- /**
23
- * Date and time when the Context was last used.
24
- */
25
- lastUsedAt?: string;
26
- /**
27
- * The operating system type this context is bound to.
28
- */
29
- osType?: string;
30
- /**
31
- * Initialize a Context object.
32
- *
33
- * @param id - The unique identifier of the context.
34
- * @param name - The name of the context.
35
- * @param state - The current state of the context.
36
- * @param createdAt - Date and time when the Context was created.
37
- * @param lastUsedAt - Date and time when the Context was last used.
38
- * @param osType - The operating system type this context is bound to.
39
- */
40
- constructor(id: string, name: string, state?: string, createdAt?: string, lastUsedAt?: string, osType?: string);
41
- }
42
- /**
43
- * Provides methods to manage persistent contexts in the AgentBay cloud environment.
44
- */
45
- export declare class ContextService {
46
- private agentBay;
47
- /**
48
- * Initialize the ContextService.
49
- *
50
- * @param agentBay - The AgentBay instance.
51
- */
52
- constructor(agentBay: AgentBay);
53
- /**
54
- * Lists all available contexts.
55
- *
56
- * @returns A list of Context objects.
57
- */
58
- list(): Promise<Context[]>;
59
- /**
60
- * Gets a context by name. Optionally creates it if it doesn't exist.
61
- *
62
- * @param name - The name of the context to get.
63
- * @param create - Whether to create the context if it doesn't exist.
64
- * @returns The Context object if found or created, null if not found and create is false.
65
- */
66
- get(name: string, create?: boolean): Promise<Context | null>;
67
- /**
68
- * Creates a new context with the given name.
69
- *
70
- * @param name - The name for the new context.
71
- * @returns The created Context object.
72
- */
73
- create(name: string): Promise<Context>;
74
- /**
75
- * Updates the specified context.
76
- *
77
- * @param context - The Context object to update.
78
- * @returns The updated Context object.
79
- */
80
- update(context: Context): Promise<Context>;
81
- /**
82
- * Deletes the specified context.
83
- *
84
- * @param context - The Context object to delete.
85
- */
86
- delete(context: Context): Promise<void>;
87
- }