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
package/dist/src/index.js DELETED
@@ -1,32 +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
- exports.ContextService = exports.Context = exports.Session = exports.AgentBay = void 0;
18
- // Export all public classes and interfaces
19
- var agent_bay_1 = require("./agent-bay");
20
- Object.defineProperty(exports, "AgentBay", { enumerable: true, get: function () { return agent_bay_1.AgentBay; } });
21
- var session_1 = require("./session");
22
- Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return session_1.Session; } });
23
- var context_1 = require("./context");
24
- Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } });
25
- Object.defineProperty(exports, "ContextService", { enumerable: true, get: function () { return context_1.ContextService; } });
26
- __exportStar(require("./exceptions"), exports);
27
- __exportStar(require("./filesystem"), exports);
28
- __exportStar(require("./command"), exports);
29
- __exportStar(require("./oss"), exports);
30
- __exportStar(require("./api"), exports);
31
- __exportStar(require("./application"), exports);
32
- __exportStar(require("./ui"), exports);
@@ -1 +0,0 @@
1
- export { Oss } from './oss';
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Oss = void 0;
4
- var oss_1 = require("./oss");
5
- Object.defineProperty(exports, "Oss", { enumerable: true, get: function () { return oss_1.Oss; } });
@@ -1,80 +0,0 @@
1
- import { Session } from '../session';
2
- /**
3
- * Handles Object Storage Service operations in the AgentBay cloud environment.
4
- */
5
- export declare class Oss {
6
- private session;
7
- private client;
8
- private baseUrl;
9
- /**
10
- * Initialize an Oss object.
11
- *
12
- * @param session - The Session instance that this Oss 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
- * Initialize OSS environment variables with the specified credentials.
27
- *
28
- * @param accessKeyId - The Access Key ID for OSS authentication.
29
- * @param accessKeySecret - The Access Key Secret for OSS authentication.
30
- * @param securityToken - The security token for OSS authentication.
31
- * @param endpoint - The OSS service endpoint. If not specified, the default is used.
32
- * @param region - The OSS region. If not specified, the default is used.
33
- * @returns The content field from the API response
34
- */
35
- envInit(accessKeyId: string, accessKeySecret: string, securityToken: string, endpoint?: string, region?: string): Promise<any>;
36
- /**
37
- * Create an OSS client with the provided credentials.
38
- *
39
- * @param accessKeyId - The Access Key ID for OSS authentication.
40
- * @param accessKeySecret - The Access Key Secret for OSS authentication.
41
- * @param endpoint - The OSS service endpoint. If not specified, the default is used.
42
- * @param region - The OSS region. If not specified, the default is used.
43
- * @returns The content field from the API response
44
- */
45
- createClient(accessKeyId: string, accessKeySecret: string, endpoint?: string, region?: string): Promise<any>;
46
- /**
47
- * Upload a local file or directory to OSS.
48
- *
49
- * @param bucket - OSS bucket name.
50
- * @param object - Object key in OSS.
51
- * @param path - Local file or directory path to upload.
52
- * @returns The content field from the API response
53
- */
54
- upload(bucket: string, object: string, path: string): Promise<any>;
55
- /**
56
- * Upload a local file or directory to a URL anonymously.
57
- *
58
- * @param url - The HTTP/HTTPS URL to upload the file to.
59
- * @param path - Local file or directory path to upload.
60
- * @returns The content field from the API response
61
- */
62
- uploadAnonymous(url: string, path: string): Promise<any>;
63
- /**
64
- * Download an object from OSS to a local file.
65
- *
66
- * @param bucket - OSS bucket name.
67
- * @param object - Object key in OSS.
68
- * @param path - Local path to save the downloaded file.
69
- * @returns The content field from the API response
70
- */
71
- download(bucket: string, object: string, path: string): Promise<any>;
72
- /**
73
- * Download a file from a URL anonymously to a local file.
74
- *
75
- * @param url - The HTTP/HTTPS URL to download the file from.
76
- * @param path - The full local file path to save the downloaded file.
77
- * @returns The content field from the API response
78
- */
79
- downloadAnonymous(url: string, path: string): Promise<any>;
80
- }
@@ -1,233 +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.Oss = void 0;
37
- const exceptions_1 = require("../exceptions");
38
- const logger_1 = require("../utils/logger");
39
- const $_client = __importStar(require("../api"));
40
- /**
41
- * Handles Object Storage Service operations in the AgentBay cloud environment.
42
- */
43
- class Oss {
44
- /**
45
- * Initialize an Oss object.
46
- *
47
- * @param session - The Session instance that this Oss belongs to.
48
- */
49
- constructor(session) {
50
- this.session = session;
51
- }
52
- /**
53
- * Helper method to call MCP tools and handle common response processing
54
- *
55
- * @param toolName - Name of the MCP tool to call
56
- * @param args - Arguments to pass to the tool
57
- * @param defaultErrorMsg - Default error message if specific error details are not available
58
- * @returns A CallMcpToolResult with the response data
59
- * @throws APIError if the call fails
60
- */
61
- async callMcpTool(toolName, args, defaultErrorMsg) {
62
- try {
63
- const callToolRequest = new $_client.CallMcpToolRequest({
64
- authorization: `Bearer ${this.session.getAPIKey()}`,
65
- sessionId: this.session.getSessionId(),
66
- name: toolName,
67
- args: JSON.stringify(args)
68
- });
69
- // Log API request
70
- (0, logger_1.log)(`API Call: CallMcpTool - ${toolName}`);
71
- (0, logger_1.log)(`Request: SessionId=${this.session.getSessionId()}, Args=${JSON.stringify(args)}`);
72
- const response = await this.session.getClient().callMcpTool(callToolRequest);
73
- // Log API response
74
- (0, logger_1.log)(`Response from CallMcpTool - ${toolName}:`, response.body);
75
- if (!response.body?.data) {
76
- throw new Error('Invalid response data format');
77
- }
78
- // Extract data from response
79
- const data = response.body.data;
80
- // Create result object
81
- const result = {
82
- data,
83
- statusCode: response.statusCode || 0,
84
- isError: false
85
- };
86
- // Check if there's an error in the response
87
- if (data.isError === true) {
88
- result.isError = true;
89
- // Try to extract the error message from the content field
90
- const contentArray = data.content;
91
- if (contentArray && contentArray.length > 0) {
92
- result.content = contentArray;
93
- // Extract error message from the first content item
94
- if (contentArray[0]?.text) {
95
- result.errorMsg = contentArray[0].text;
96
- throw new Error(contentArray[0].text);
97
- }
98
- }
99
- throw new Error(defaultErrorMsg);
100
- }
101
- // Extract content array if it exists
102
- if (Array.isArray(data.content)) {
103
- result.content = data.content;
104
- }
105
- return result;
106
- }
107
- catch (error) {
108
- (0, logger_1.logError)(`Error calling CallMcpTool - ${toolName}:`, error);
109
- throw new exceptions_1.APIError(`Failed to call ${toolName}: ${error}`);
110
- }
111
- }
112
- /**
113
- * Initialize OSS environment variables with the specified credentials.
114
- *
115
- * @param accessKeyId - The Access Key ID for OSS authentication.
116
- * @param accessKeySecret - The Access Key Secret for OSS authentication.
117
- * @param securityToken - The security token for OSS authentication.
118
- * @param endpoint - The OSS service endpoint. If not specified, the default is used.
119
- * @param region - The OSS region. If not specified, the default is used.
120
- * @returns The content field from the API response
121
- */
122
- async envInit(accessKeyId, accessKeySecret, securityToken, endpoint, region) {
123
- const args = {
124
- access_key_id: accessKeyId,
125
- access_key_secret: accessKeySecret,
126
- security_token: securityToken
127
- };
128
- // Add optional parameters if provided
129
- if (endpoint) {
130
- args.endpoint = endpoint;
131
- }
132
- if (region) {
133
- args.region = region;
134
- }
135
- const result = await this.callMcpTool('oss_env_init', args, 'error initializing OSS environment');
136
- // Return the raw content field for the caller to parse
137
- return result.data.content;
138
- }
139
- /**
140
- * Create an OSS client with the provided credentials.
141
- *
142
- * @param accessKeyId - The Access Key ID for OSS authentication.
143
- * @param accessKeySecret - The Access Key Secret for OSS authentication.
144
- * @param endpoint - The OSS service endpoint. If not specified, the default is used.
145
- * @param region - The OSS region. If not specified, the default is used.
146
- * @returns The content field from the API response
147
- */
148
- async createClient(accessKeyId, accessKeySecret, endpoint, region) {
149
- const args = {
150
- access_key_id: accessKeyId,
151
- access_key_secret: accessKeySecret
152
- };
153
- // Add optional parameters if provided
154
- if (endpoint) {
155
- args.endpoint = endpoint;
156
- }
157
- if (region) {
158
- args.region = region;
159
- }
160
- const result = await this.callMcpTool('oss_client_create', args, 'error creating OSS client');
161
- // Return the raw content field for the caller to parse
162
- return result.data.content;
163
- }
164
- /**
165
- * Upload a local file or directory to OSS.
166
- *
167
- * @param bucket - OSS bucket name.
168
- * @param object - Object key in OSS.
169
- * @param path - Local file or directory path to upload.
170
- * @returns The content field from the API response
171
- */
172
- async upload(bucket, object, path) {
173
- const args = {
174
- bucket,
175
- object,
176
- path
177
- };
178
- const result = await this.callMcpTool('oss_upload', args, 'error uploading to OSS');
179
- // Return the raw content field for the caller to parse
180
- return result.data.content;
181
- }
182
- /**
183
- * Upload a local file or directory to a URL anonymously.
184
- *
185
- * @param url - The HTTP/HTTPS URL to upload the file to.
186
- * @param path - Local file or directory path to upload.
187
- * @returns The content field from the API response
188
- */
189
- async uploadAnonymous(url, path) {
190
- const args = {
191
- url,
192
- path
193
- };
194
- const result = await this.callMcpTool('oss_upload_annon', args, 'error uploading anonymously');
195
- // Return the raw content field for the caller to parse
196
- return result.data.content;
197
- }
198
- /**
199
- * Download an object from OSS to a local file.
200
- *
201
- * @param bucket - OSS bucket name.
202
- * @param object - Object key in OSS.
203
- * @param path - Local path to save the downloaded file.
204
- * @returns The content field from the API response
205
- */
206
- async download(bucket, object, path) {
207
- const args = {
208
- bucket,
209
- object,
210
- path
211
- };
212
- const result = await this.callMcpTool('oss_download', args, 'error downloading from OSS');
213
- // Return the raw content field for the caller to parse
214
- return result.data.content;
215
- }
216
- /**
217
- * Download a file from a URL anonymously to a local file.
218
- *
219
- * @param url - The HTTP/HTTPS URL to download the file from.
220
- * @param path - The full local file path to save the downloaded file.
221
- * @returns The content field from the API response
222
- */
223
- async downloadAnonymous(url, path) {
224
- const args = {
225
- url,
226
- path
227
- };
228
- const result = await this.callMcpTool('oss_download_annon', args, 'error downloading anonymously');
229
- // Return the raw content field for the caller to parse
230
- return result.data.content;
231
- }
232
- }
233
- exports.Oss = Oss;
@@ -1,99 +0,0 @@
1
- import { AgentBay } from './agent-bay';
2
- import { FileSystem } from './filesystem';
3
- import { Command } from './command';
4
- import { Oss } from './oss';
5
- import { Application } from './application';
6
- import { WindowManager } from './window';
7
- import { UI } from './ui';
8
- import Client from './api/client';
9
- /**
10
- * Contains information about a session.
11
- */
12
- export interface SessionInfo {
13
- sessionId: string;
14
- resourceUrl: string;
15
- appId?: string;
16
- authCode?: string;
17
- connectionProperties?: string;
18
- resourceId?: string;
19
- resourceType?: string;
20
- }
21
- /**
22
- * Represents a session in the AgentBay cloud environment.
23
- */
24
- export declare class Session {
25
- private agentBay;
26
- client: Client;
27
- sessionId: string;
28
- resourceUrl: string;
29
- filesystem: FileSystem;
30
- command: Command;
31
- oss: Oss;
32
- Application: Application;
33
- window: WindowManager;
34
- ui: UI;
35
- /**
36
- * Initialize a Session object.
37
- *
38
- * @param agentBay - The AgentBay instance that created this session.
39
- * @param sessionId - The ID of this session.
40
- */
41
- constructor(agentBay: AgentBay, sessionId: string);
42
- /**
43
- * Get information about this session.
44
- *
45
- * @returns Session information.
46
- */
47
- /**
48
- * Delete this session.
49
- *
50
- * @returns True if the session was successfully deleted.
51
- */
52
- delete(): Promise<boolean>;
53
- /**
54
- * Sets the labels for this session.
55
- *
56
- * @param labels - The labels to set for the session.
57
- * @throws APIError if the operation fails.
58
- */
59
- setLabels(labels: Record<string, string>): Promise<void>;
60
- /**
61
- * Gets the labels for this session.
62
- *
63
- * @returns The labels for the session.
64
- * @throws APIError if the operation fails.
65
- */
66
- getLabels(): Promise<Record<string, string>>;
67
- /**
68
- * Get the API key.
69
- *
70
- * @returns The API key.
71
- */
72
- getAPIKey(): string;
73
- /**
74
- * Get the client.
75
- *
76
- * @returns The client.
77
- */
78
- getClient(): Client;
79
- /**
80
- * Get the session ID.
81
- *
82
- * @returns The session ID.
83
- */
84
- getSessionId(): string;
85
- /**
86
- * Gets information about this session.
87
- *
88
- * @returns Information about the session.
89
- * @throws APIError if the operation fails.
90
- */
91
- info(): Promise<SessionInfo>;
92
- /**
93
- * Gets the link for this session.
94
- *
95
- * @returns The link for the session.
96
- * @throws APIError if the operation fails.
97
- */
98
- getLink(): Promise<string>;
99
- }
@@ -1,226 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Session = void 0;
4
- const exceptions_1 = require("./exceptions");
5
- const filesystem_1 = require("./filesystem");
6
- const command_1 = require("./command");
7
- const oss_1 = require("./oss");
8
- const application_1 = require("./application");
9
- const window_1 = require("./window");
10
- const ui_1 = require("./ui");
11
- const model_1 = require("./api/models/model");
12
- const logger_1 = require("./utils/logger");
13
- /**
14
- * Represents a session in the AgentBay cloud environment.
15
- */
16
- class Session {
17
- /**
18
- * Initialize a Session object.
19
- *
20
- * @param agentBay - The AgentBay instance that created this session.
21
- * @param sessionId - The ID of this session.
22
- */
23
- constructor(agentBay, sessionId) {
24
- this.resourceUrl = "";
25
- this.agentBay = agentBay;
26
- this.sessionId = sessionId;
27
- this.client = agentBay.getClient();
28
- (0, logger_1.log)(`Session created with ID: ${sessionId}`);
29
- // Initialize filesystem, command, and oss handlers
30
- this.filesystem = new filesystem_1.FileSystem(this);
31
- this.command = new command_1.Command(this);
32
- this.oss = new oss_1.Oss(this);
33
- // Initialize application, window, and UI managers
34
- this.Application = new application_1.Application(this);
35
- this.window = new window_1.WindowManager(this);
36
- this.ui = new ui_1.UI(this);
37
- }
38
- /**
39
- * Get information about this session.
40
- *
41
- * @returns Session information.
42
- */
43
- // async get_info(): Promise<Record<string, any>> {
44
- // // TODO: Implement the API call to get session info
45
- // try {
46
- // const response = await this.client.get(this.baseUrl);
47
- // return response.data;
48
- // } catch (error) {
49
- // throw new APIError(`Failed to get session info: ${error}`);
50
- // }
51
- // }
52
- /**
53
- * Delete this session.
54
- *
55
- * @returns True if the session was successfully deleted.
56
- */
57
- async delete() {
58
- try {
59
- const releaseSessionRequest = new model_1.ReleaseMcpSessionRequest({
60
- authorization: `Bearer ${this.getAPIKey()}`,
61
- sessionId: this.sessionId
62
- });
63
- // Log API request
64
- (0, logger_1.log)("API Call: ReleaseMcpSession");
65
- (0, logger_1.log)(`Request: SessionId=${this.sessionId}`);
66
- const response = await this.client.releaseMcpSession(releaseSessionRequest);
67
- // Log API response
68
- (0, logger_1.log)(`Response from ReleaseMcpSession:`, response.body);
69
- this.agentBay.removeSession(this.sessionId);
70
- return true;
71
- }
72
- catch (error) {
73
- (0, logger_1.logError)("Error calling ReleaseMcpSession:", error);
74
- throw new exceptions_1.APIError(`Failed to delete session: ${error}`);
75
- }
76
- }
77
- /**
78
- * Sets the labels for this session.
79
- *
80
- * @param labels - The labels to set for the session.
81
- * @throws APIError if the operation fails.
82
- */
83
- async setLabels(labels) {
84
- try {
85
- // Convert labels to JSON string
86
- const labelsJSON = JSON.stringify(labels);
87
- const request = new model_1.SetLabelRequest({
88
- authorization: `Bearer ${this.getAPIKey()}`,
89
- sessionId: this.sessionId,
90
- labels: labelsJSON
91
- });
92
- // Log API request
93
- (0, logger_1.log)("API Call: SetLabel");
94
- (0, logger_1.log)(`Request: SessionId=${this.sessionId}, Labels=${labelsJSON}`);
95
- const response = await this.client.setLabel(request);
96
- // Log API response
97
- (0, logger_1.log)(`Response from SetLabel:`, response.body);
98
- }
99
- catch (error) {
100
- (0, logger_1.logError)("Error calling SetLabel:", error);
101
- throw new exceptions_1.APIError(`Failed to set labels for session: ${error}`);
102
- }
103
- }
104
- /**
105
- * Gets the labels for this session.
106
- *
107
- * @returns The labels for the session.
108
- * @throws APIError if the operation fails.
109
- */
110
- async getLabels() {
111
- try {
112
- const request = new model_1.GetLabelRequest({
113
- authorization: `Bearer ${this.getAPIKey()}`,
114
- sessionId: this.sessionId
115
- });
116
- // Log API request
117
- (0, logger_1.log)("API Call: GetLabel");
118
- (0, logger_1.log)(`Request: SessionId=${this.sessionId}`);
119
- const response = await this.client.getLabel(request);
120
- // Log API response
121
- (0, logger_1.log)(`Response from GetLabel:`, response.body);
122
- // Extract labels from response
123
- const labelsJSON = response.body?.data?.labels;
124
- if (labelsJSON) {
125
- return JSON.parse(labelsJSON);
126
- }
127
- return {};
128
- }
129
- catch (error) {
130
- (0, logger_1.logError)("Error calling GetLabel:", error);
131
- throw new exceptions_1.APIError(`Failed to get labels for session: ${error}`);
132
- }
133
- }
134
- /**
135
- * Get the API key.
136
- *
137
- * @returns The API key.
138
- */
139
- getAPIKey() {
140
- return this.agentBay.getAPIKey();
141
- }
142
- /**
143
- * Get the client.
144
- *
145
- * @returns The client.
146
- */
147
- getClient() {
148
- return this.client;
149
- }
150
- /**
151
- * Get the session ID.
152
- *
153
- * @returns The session ID.
154
- */
155
- getSessionId() {
156
- return this.sessionId;
157
- }
158
- /**
159
- * Gets information about this session.
160
- *
161
- * @returns Information about the session.
162
- * @throws APIError if the operation fails.
163
- */
164
- async info() {
165
- try {
166
- const request = new model_1.GetMcpResourceRequest({
167
- authorization: `Bearer ${this.getAPIKey()}`,
168
- sessionId: this.sessionId
169
- });
170
- (0, logger_1.log)("API Call: GetMcpResource");
171
- (0, logger_1.log)(`Request: SessionId=${this.sessionId}`);
172
- const response = await this.client.getMcpResource(request);
173
- (0, logger_1.log)(`Response from GetMcpResource:`, response.body);
174
- // Extract session info from response
175
- const sessionInfo = {
176
- sessionId: response.body?.data?.sessionId || "",
177
- resourceUrl: response.body?.data?.resourceUrl || ""
178
- };
179
- // Update the session's resourceUrl with the latest value
180
- if (response.body?.data?.resourceUrl) {
181
- this.resourceUrl = response.body.data.resourceUrl;
182
- }
183
- // Transfer DesktopInfo fields to SessionInfo
184
- if (response.body?.data?.desktopInfo) {
185
- const desktopInfo = response.body.data.desktopInfo;
186
- sessionInfo.appId = desktopInfo.appId;
187
- sessionInfo.authCode = desktopInfo.authCode;
188
- sessionInfo.connectionProperties = desktopInfo.connectionProperties;
189
- sessionInfo.resourceId = desktopInfo.resourceId;
190
- sessionInfo.resourceType = desktopInfo.resourceType;
191
- }
192
- return sessionInfo;
193
- }
194
- catch (error) {
195
- (0, logger_1.logError)("Error calling GetMcpResource:", error);
196
- throw new exceptions_1.APIError(`Failed to get session info for session ${this.sessionId}: ${error}`);
197
- }
198
- }
199
- /**
200
- * Gets the link for this session.
201
- *
202
- * @returns The link for the session.
203
- * @throws APIError if the operation fails.
204
- */
205
- async getLink() {
206
- try {
207
- const request = new model_1.GetLinkRequest({
208
- authorization: `Bearer ${this.getAPIKey()}`,
209
- sessionId: this.sessionId
210
- });
211
- (0, logger_1.log)("API Call: GetLink");
212
- (0, logger_1.log)(`Request: SessionId=${this.sessionId}`);
213
- const response = await this.client.getLink(request);
214
- (0, logger_1.log)(`Response from GetLink:`, response.body);
215
- if (response.body?.data) {
216
- return response.body.data;
217
- }
218
- return "";
219
- }
220
- catch (error) {
221
- (0, logger_1.logError)("Error calling GetLink:", error);
222
- throw new exceptions_1.APIError(`Failed to get link for session ${this.sessionId}: ${error}`);
223
- }
224
- }
225
- }
226
- exports.Session = Session;
@@ -1 +0,0 @@
1
- export * from './ui';