wuying-agentbay-sdk 0.1.0 → 0.3.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 +24 -4
  2. package/dist/index.cjs +4534 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.mts +1837 -0
  5. package/dist/index.d.ts +1837 -0
  6. package/dist/index.mjs +4550 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +16 -8
  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/index.mjs ADDED
@@ -0,0 +1,4550 @@
1
+
2
+ if (typeof OpenApi !== 'undefined' && !OpenApi.default) {
3
+ OpenApi.default = OpenApi;
4
+ }
5
+
6
+ import { createRequire } from 'module';
7
+ const require = createRequire(import.meta.url);
8
+ (function() {
9
+ if (typeof OpenApi !== 'undefined' && !OpenApi.default) {
10
+ OpenApi.default = OpenApi;
11
+ }
12
+ })();
13
+
14
+ var __defProp = Object.defineProperty;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
18
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
19
+ }) : x)(function(x) {
20
+ if (typeof require !== "undefined") return require.apply(this, arguments);
21
+ throw Error('Dynamic require of "' + x + '" is not supported');
22
+ });
23
+ var __esm = (fn, res) => function __init() {
24
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
25
+ };
26
+ var __commonJS = (cb, mod) => function __require2() {
27
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
28
+ };
29
+
30
+ // node_modules/tsup/assets/esm_shims.js
31
+ import path from "path";
32
+ import { fileURLToPath } from "url";
33
+ var init_esm_shims = __esm({
34
+ "node_modules/tsup/assets/esm_shims.js"() {
35
+ "use strict";
36
+ }
37
+ });
38
+
39
+ // node_modules/dotenv/package.json
40
+ var require_package = __commonJS({
41
+ "node_modules/dotenv/package.json"(exports, module) {
42
+ module.exports = {
43
+ name: "dotenv",
44
+ version: "16.5.0",
45
+ description: "Loads environment variables from .env file",
46
+ main: "lib/main.js",
47
+ types: "lib/main.d.ts",
48
+ exports: {
49
+ ".": {
50
+ types: "./lib/main.d.ts",
51
+ require: "./lib/main.js",
52
+ default: "./lib/main.js"
53
+ },
54
+ "./config": "./config.js",
55
+ "./config.js": "./config.js",
56
+ "./lib/env-options": "./lib/env-options.js",
57
+ "./lib/env-options.js": "./lib/env-options.js",
58
+ "./lib/cli-options": "./lib/cli-options.js",
59
+ "./lib/cli-options.js": "./lib/cli-options.js",
60
+ "./package.json": "./package.json"
61
+ },
62
+ scripts: {
63
+ "dts-check": "tsc --project tests/types/tsconfig.json",
64
+ lint: "standard",
65
+ pretest: "npm run lint && npm run dts-check",
66
+ test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
67
+ "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=lcov",
68
+ prerelease: "npm test",
69
+ release: "standard-version"
70
+ },
71
+ repository: {
72
+ type: "git",
73
+ url: "git://github.com/motdotla/dotenv.git"
74
+ },
75
+ homepage: "https://github.com/motdotla/dotenv#readme",
76
+ funding: "https://dotenvx.com",
77
+ keywords: [
78
+ "dotenv",
79
+ "env",
80
+ ".env",
81
+ "environment",
82
+ "variables",
83
+ "config",
84
+ "settings"
85
+ ],
86
+ readmeFilename: "README.md",
87
+ license: "BSD-2-Clause",
88
+ devDependencies: {
89
+ "@types/node": "^18.11.3",
90
+ decache: "^4.6.2",
91
+ sinon: "^14.0.1",
92
+ standard: "^17.0.0",
93
+ "standard-version": "^9.5.0",
94
+ tap: "^19.2.0",
95
+ typescript: "^4.8.4"
96
+ },
97
+ engines: {
98
+ node: ">=12"
99
+ },
100
+ browser: {
101
+ fs: false
102
+ }
103
+ };
104
+ }
105
+ });
106
+
107
+ // node_modules/dotenv/lib/main.js
108
+ var require_main = __commonJS({
109
+ "node_modules/dotenv/lib/main.js"(exports, module) {
110
+ "use strict";
111
+ init_esm_shims();
112
+ var fs2 = __require("fs");
113
+ var path3 = __require("path");
114
+ var os = __require("os");
115
+ var crypto = __require("crypto");
116
+ var packageJson = require_package();
117
+ var version = packageJson.version;
118
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
119
+ function parse(src) {
120
+ const obj = {};
121
+ let lines = src.toString();
122
+ lines = lines.replace(/\r\n?/mg, "\n");
123
+ let match;
124
+ while ((match = LINE.exec(lines)) != null) {
125
+ const key = match[1];
126
+ let value = match[2] || "";
127
+ value = value.trim();
128
+ const maybeQuote = value[0];
129
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
130
+ if (maybeQuote === '"') {
131
+ value = value.replace(/\\n/g, "\n");
132
+ value = value.replace(/\\r/g, "\r");
133
+ }
134
+ obj[key] = value;
135
+ }
136
+ return obj;
137
+ }
138
+ __name(parse, "parse");
139
+ function _parseVault(options) {
140
+ const vaultPath = _vaultPath(options);
141
+ const result = DotenvModule.configDotenv({ path: vaultPath });
142
+ if (!result.parsed) {
143
+ const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
144
+ err.code = "MISSING_DATA";
145
+ throw err;
146
+ }
147
+ const keys = _dotenvKey(options).split(",");
148
+ const length = keys.length;
149
+ let decrypted;
150
+ for (let i = 0; i < length; i++) {
151
+ try {
152
+ const key = keys[i].trim();
153
+ const attrs = _instructions(result, key);
154
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
155
+ break;
156
+ } catch (error) {
157
+ if (i + 1 >= length) {
158
+ throw error;
159
+ }
160
+ }
161
+ }
162
+ return DotenvModule.parse(decrypted);
163
+ }
164
+ __name(_parseVault, "_parseVault");
165
+ function _warn(message) {
166
+ console.log(`[dotenv@${version}][WARN] ${message}`);
167
+ }
168
+ __name(_warn, "_warn");
169
+ function _debug(message) {
170
+ console.log(`[dotenv@${version}][DEBUG] ${message}`);
171
+ }
172
+ __name(_debug, "_debug");
173
+ function _dotenvKey(options) {
174
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
175
+ return options.DOTENV_KEY;
176
+ }
177
+ if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
178
+ return process.env.DOTENV_KEY;
179
+ }
180
+ return "";
181
+ }
182
+ __name(_dotenvKey, "_dotenvKey");
183
+ function _instructions(result, dotenvKey) {
184
+ let uri;
185
+ try {
186
+ uri = new URL(dotenvKey);
187
+ } catch (error) {
188
+ if (error.code === "ERR_INVALID_URL") {
189
+ const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
190
+ err.code = "INVALID_DOTENV_KEY";
191
+ throw err;
192
+ }
193
+ throw error;
194
+ }
195
+ const key = uri.password;
196
+ if (!key) {
197
+ const err = new Error("INVALID_DOTENV_KEY: Missing key part");
198
+ err.code = "INVALID_DOTENV_KEY";
199
+ throw err;
200
+ }
201
+ const environment = uri.searchParams.get("environment");
202
+ if (!environment) {
203
+ const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
204
+ err.code = "INVALID_DOTENV_KEY";
205
+ throw err;
206
+ }
207
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
208
+ const ciphertext = result.parsed[environmentKey];
209
+ if (!ciphertext) {
210
+ const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
211
+ err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
212
+ throw err;
213
+ }
214
+ return { ciphertext, key };
215
+ }
216
+ __name(_instructions, "_instructions");
217
+ function _vaultPath(options) {
218
+ let possibleVaultPath = null;
219
+ if (options && options.path && options.path.length > 0) {
220
+ if (Array.isArray(options.path)) {
221
+ for (const filepath of options.path) {
222
+ if (fs2.existsSync(filepath)) {
223
+ possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
224
+ }
225
+ }
226
+ } else {
227
+ possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
228
+ }
229
+ } else {
230
+ possibleVaultPath = path3.resolve(process.cwd(), ".env.vault");
231
+ }
232
+ if (fs2.existsSync(possibleVaultPath)) {
233
+ return possibleVaultPath;
234
+ }
235
+ return null;
236
+ }
237
+ __name(_vaultPath, "_vaultPath");
238
+ function _resolveHome(envPath) {
239
+ return envPath[0] === "~" ? path3.join(os.homedir(), envPath.slice(1)) : envPath;
240
+ }
241
+ __name(_resolveHome, "_resolveHome");
242
+ function _configVault(options) {
243
+ const debug = Boolean(options && options.debug);
244
+ if (debug) {
245
+ _debug("Loading env from encrypted .env.vault");
246
+ }
247
+ const parsed = DotenvModule._parseVault(options);
248
+ let processEnv = process.env;
249
+ if (options && options.processEnv != null) {
250
+ processEnv = options.processEnv;
251
+ }
252
+ DotenvModule.populate(processEnv, parsed, options);
253
+ return { parsed };
254
+ }
255
+ __name(_configVault, "_configVault");
256
+ function configDotenv(options) {
257
+ const dotenvPath = path3.resolve(process.cwd(), ".env");
258
+ let encoding = "utf8";
259
+ const debug = Boolean(options && options.debug);
260
+ if (options && options.encoding) {
261
+ encoding = options.encoding;
262
+ } else {
263
+ if (debug) {
264
+ _debug("No encoding is specified. UTF-8 is used by default");
265
+ }
266
+ }
267
+ let optionPaths = [dotenvPath];
268
+ if (options && options.path) {
269
+ if (!Array.isArray(options.path)) {
270
+ optionPaths = [_resolveHome(options.path)];
271
+ } else {
272
+ optionPaths = [];
273
+ for (const filepath of options.path) {
274
+ optionPaths.push(_resolveHome(filepath));
275
+ }
276
+ }
277
+ }
278
+ let lastError;
279
+ const parsedAll = {};
280
+ for (const path4 of optionPaths) {
281
+ try {
282
+ const parsed = DotenvModule.parse(fs2.readFileSync(path4, { encoding }));
283
+ DotenvModule.populate(parsedAll, parsed, options);
284
+ } catch (e) {
285
+ if (debug) {
286
+ _debug(`Failed to load ${path4} ${e.message}`);
287
+ }
288
+ lastError = e;
289
+ }
290
+ }
291
+ let processEnv = process.env;
292
+ if (options && options.processEnv != null) {
293
+ processEnv = options.processEnv;
294
+ }
295
+ DotenvModule.populate(processEnv, parsedAll, options);
296
+ if (lastError) {
297
+ return { parsed: parsedAll, error: lastError };
298
+ } else {
299
+ return { parsed: parsedAll };
300
+ }
301
+ }
302
+ __name(configDotenv, "configDotenv");
303
+ function config(options) {
304
+ if (_dotenvKey(options).length === 0) {
305
+ return DotenvModule.configDotenv(options);
306
+ }
307
+ const vaultPath = _vaultPath(options);
308
+ if (!vaultPath) {
309
+ _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
310
+ return DotenvModule.configDotenv(options);
311
+ }
312
+ return DotenvModule._configVault(options);
313
+ }
314
+ __name(config, "config");
315
+ function decrypt(encrypted, keyStr) {
316
+ const key = Buffer.from(keyStr.slice(-64), "hex");
317
+ let ciphertext = Buffer.from(encrypted, "base64");
318
+ const nonce = ciphertext.subarray(0, 12);
319
+ const authTag = ciphertext.subarray(-16);
320
+ ciphertext = ciphertext.subarray(12, -16);
321
+ try {
322
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
323
+ aesgcm.setAuthTag(authTag);
324
+ return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
325
+ } catch (error) {
326
+ const isRange = error instanceof RangeError;
327
+ const invalidKeyLength = error.message === "Invalid key length";
328
+ const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
329
+ if (isRange || invalidKeyLength) {
330
+ const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
331
+ err.code = "INVALID_DOTENV_KEY";
332
+ throw err;
333
+ } else if (decryptionFailed) {
334
+ const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
335
+ err.code = "DECRYPTION_FAILED";
336
+ throw err;
337
+ } else {
338
+ throw error;
339
+ }
340
+ }
341
+ }
342
+ __name(decrypt, "decrypt");
343
+ function populate(processEnv, parsed, options = {}) {
344
+ const debug = Boolean(options && options.debug);
345
+ const override = Boolean(options && options.override);
346
+ if (typeof parsed !== "object") {
347
+ const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
348
+ err.code = "OBJECT_REQUIRED";
349
+ throw err;
350
+ }
351
+ for (const key of Object.keys(parsed)) {
352
+ if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
353
+ if (override === true) {
354
+ processEnv[key] = parsed[key];
355
+ }
356
+ if (debug) {
357
+ if (override === true) {
358
+ _debug(`"${key}" is already defined and WAS overwritten`);
359
+ } else {
360
+ _debug(`"${key}" is already defined and was NOT overwritten`);
361
+ }
362
+ }
363
+ } else {
364
+ processEnv[key] = parsed[key];
365
+ }
366
+ }
367
+ }
368
+ __name(populate, "populate");
369
+ var DotenvModule = {
370
+ configDotenv,
371
+ _configVault,
372
+ _parseVault,
373
+ config,
374
+ decrypt,
375
+ parse,
376
+ populate
377
+ };
378
+ module.exports.configDotenv = DotenvModule.configDotenv;
379
+ module.exports._configVault = DotenvModule._configVault;
380
+ module.exports._parseVault = DotenvModule._parseVault;
381
+ module.exports.config = DotenvModule.config;
382
+ module.exports.decrypt = DotenvModule.decrypt;
383
+ module.exports.parse = DotenvModule.parse;
384
+ module.exports.populate = DotenvModule.populate;
385
+ module.exports = DotenvModule;
386
+ }
387
+ });
388
+
389
+ // node_modules/dotenv/lib/env-options.js
390
+ var require_env_options = __commonJS({
391
+ "node_modules/dotenv/lib/env-options.js"(exports, module) {
392
+ "use strict";
393
+ init_esm_shims();
394
+ var options = {};
395
+ if (process.env.DOTENV_CONFIG_ENCODING != null) {
396
+ options.encoding = process.env.DOTENV_CONFIG_ENCODING;
397
+ }
398
+ if (process.env.DOTENV_CONFIG_PATH != null) {
399
+ options.path = process.env.DOTENV_CONFIG_PATH;
400
+ }
401
+ if (process.env.DOTENV_CONFIG_DEBUG != null) {
402
+ options.debug = process.env.DOTENV_CONFIG_DEBUG;
403
+ }
404
+ if (process.env.DOTENV_CONFIG_OVERRIDE != null) {
405
+ options.override = process.env.DOTENV_CONFIG_OVERRIDE;
406
+ }
407
+ if (process.env.DOTENV_CONFIG_DOTENV_KEY != null) {
408
+ options.DOTENV_KEY = process.env.DOTENV_CONFIG_DOTENV_KEY;
409
+ }
410
+ module.exports = options;
411
+ }
412
+ });
413
+
414
+ // node_modules/dotenv/lib/cli-options.js
415
+ var require_cli_options = __commonJS({
416
+ "node_modules/dotenv/lib/cli-options.js"(exports, module) {
417
+ "use strict";
418
+ init_esm_shims();
419
+ var re = /^dotenv_config_(encoding|path|debug|override|DOTENV_KEY)=(.+)$/;
420
+ module.exports = /* @__PURE__ */ __name(function optionMatcher(args) {
421
+ return args.reduce(function(acc, cur) {
422
+ const matches = cur.match(re);
423
+ if (matches) {
424
+ acc[matches[1]] = matches[2];
425
+ }
426
+ return acc;
427
+ }, {});
428
+ }, "optionMatcher");
429
+ }
430
+ });
431
+
432
+ // src/index.ts
433
+ init_esm_shims();
434
+
435
+ // src/agent-bay.ts
436
+ init_esm_shims();
437
+
438
+ // src/session.ts
439
+ init_esm_shims();
440
+
441
+ // src/exceptions.ts
442
+ init_esm_shims();
443
+ var _AgentBayError = class _AgentBayError extends (Error.default || Error) {
444
+ constructor(message) {
445
+ super(message);
446
+ this.name = "AgentBayError";
447
+ Object.setPrototypeOf(this, _AgentBayError.prototype);
448
+ }
449
+ };
450
+ __name(_AgentBayError, "AgentBayError");
451
+ var AgentBayError = _AgentBayError;
452
+ var _AuthenticationError = class _AuthenticationError extends (AgentBayError.default || AgentBayError) {
453
+ constructor(message) {
454
+ super(message);
455
+ this.name = "AuthenticationError";
456
+ Object.setPrototypeOf(this, _AuthenticationError.prototype);
457
+ }
458
+ };
459
+ __name(_AuthenticationError, "AuthenticationError");
460
+ var AuthenticationError = _AuthenticationError;
461
+ var _APIError = class _APIError extends (AgentBayError.default || AgentBayError) {
462
+ constructor(message) {
463
+ super(message);
464
+ this.name = "APIError";
465
+ Object.setPrototypeOf(this, _APIError.prototype);
466
+ }
467
+ };
468
+ __name(_APIError, "APIError");
469
+ var APIError = _APIError;
470
+ var _FileError = class _FileError extends (AgentBayError.default || AgentBayError) {
471
+ constructor(message) {
472
+ super(message);
473
+ this.name = "FileError";
474
+ Object.setPrototypeOf(this, _FileError.prototype);
475
+ }
476
+ };
477
+ __name(_FileError, "FileError");
478
+ var FileError = _FileError;
479
+ var _CommandError = class _CommandError extends (AgentBayError.default || AgentBayError) {
480
+ constructor(message) {
481
+ super(message);
482
+ this.name = "CommandError";
483
+ Object.setPrototypeOf(this, _CommandError.prototype);
484
+ }
485
+ };
486
+ __name(_CommandError, "CommandError");
487
+ var CommandError = _CommandError;
488
+
489
+ // src/filesystem/filesystem.ts
490
+ init_esm_shims();
491
+
492
+ // src/api/models/model.ts
493
+ init_esm_shims();
494
+
495
+ // src/api/models/CreateMcpSessionResponseBodyData.ts
496
+ init_esm_shims();
497
+ import * as $dara from "@darabonba/typescript";
498
+ var _CreateMcpSessionResponseBodyData = class _CreateMcpSessionResponseBodyData extends $dara.Model {
499
+ static names() {
500
+ return {
501
+ appInstanceId: "AppInstanceId",
502
+ errMsg: "ErrMsg",
503
+ resourceId: "ResourceId",
504
+ resourceUrl: "ResourceUrl",
505
+ sessionId: "SessionId",
506
+ success: "Success"
507
+ };
508
+ }
509
+ static types() {
510
+ return {
511
+ appInstanceId: "string",
512
+ errMsg: "string",
513
+ resourceId: "string",
514
+ resourceUrl: "string",
515
+ sessionId: "string",
516
+ success: "boolean"
517
+ };
518
+ }
519
+ validate() {
520
+ super.validate();
521
+ }
522
+ constructor(map) {
523
+ super(map);
524
+ }
525
+ };
526
+ __name(_CreateMcpSessionResponseBodyData, "CreateMcpSessionResponseBodyData");
527
+ var CreateMcpSessionResponseBodyData = _CreateMcpSessionResponseBodyData;
528
+
529
+ // src/api/models/GetContextResponseBodyData.ts
530
+ init_esm_shims();
531
+ import * as $dara2 from "@darabonba/typescript";
532
+ var _GetContextResponseBodyData = class _GetContextResponseBodyData extends $dara2.Model {
533
+ static names() {
534
+ return {
535
+ createTime: "CreateTime",
536
+ id: "Id",
537
+ lastUsedTime: "LastUsedTime",
538
+ name: "Name",
539
+ osType: "OsType",
540
+ state: "State"
541
+ };
542
+ }
543
+ static types() {
544
+ return {
545
+ createTime: "string",
546
+ id: "string",
547
+ lastUsedTime: "string",
548
+ name: "string",
549
+ osType: "string",
550
+ state: "string"
551
+ };
552
+ }
553
+ validate() {
554
+ super.validate();
555
+ }
556
+ constructor(map) {
557
+ super(map);
558
+ }
559
+ };
560
+ __name(_GetContextResponseBodyData, "GetContextResponseBodyData");
561
+ var GetContextResponseBodyData = _GetContextResponseBodyData;
562
+
563
+ // src/api/models/GetLabelResponseBodyData.ts
564
+ init_esm_shims();
565
+ import * as $dara3 from "@darabonba/typescript";
566
+ var _GetLabelResponseBodyData = class _GetLabelResponseBodyData extends $dara3.Model {
567
+ static names() {
568
+ return {
569
+ labels: "Labels"
570
+ };
571
+ }
572
+ static types() {
573
+ return {
574
+ labels: "string"
575
+ };
576
+ }
577
+ validate() {
578
+ super.validate();
579
+ }
580
+ constructor(map) {
581
+ super(map);
582
+ }
583
+ };
584
+ __name(_GetLabelResponseBodyData, "GetLabelResponseBodyData");
585
+ var GetLabelResponseBodyData = _GetLabelResponseBodyData;
586
+
587
+ // src/api/models/GetMcpResourceResponseBodyDataDesktopInfo.ts
588
+ init_esm_shims();
589
+ import * as $dara4 from "@darabonba/typescript";
590
+ var _GetMcpResourceResponseBodyDataDesktopInfo = class _GetMcpResourceResponseBodyDataDesktopInfo extends $dara4.Model {
591
+ static names() {
592
+ return {
593
+ appId: "AppId",
594
+ authCode: "AuthCode",
595
+ connectionProperties: "ConnectionProperties",
596
+ resourceId: "ResourceId",
597
+ resourceType: "ResourceType"
598
+ };
599
+ }
600
+ static types() {
601
+ return {
602
+ appId: "string",
603
+ authCode: "string",
604
+ connectionProperties: "string",
605
+ resourceId: "string",
606
+ resourceType: "string"
607
+ };
608
+ }
609
+ validate() {
610
+ super.validate();
611
+ }
612
+ constructor(map) {
613
+ super(map);
614
+ }
615
+ };
616
+ __name(_GetMcpResourceResponseBodyDataDesktopInfo, "GetMcpResourceResponseBodyDataDesktopInfo");
617
+ var GetMcpResourceResponseBodyDataDesktopInfo = _GetMcpResourceResponseBodyDataDesktopInfo;
618
+
619
+ // src/api/models/GetMcpResourceResponseBodyData.ts
620
+ init_esm_shims();
621
+ import * as $dara5 from "@darabonba/typescript";
622
+ var _GetMcpResourceResponseBodyData = class _GetMcpResourceResponseBodyData extends $dara5.Model {
623
+ static names() {
624
+ return {
625
+ desktopInfo: "DesktopInfo",
626
+ resourceUrl: "ResourceUrl",
627
+ sessionId: "SessionId"
628
+ };
629
+ }
630
+ static types() {
631
+ return {
632
+ desktopInfo: GetMcpResourceResponseBodyDataDesktopInfo,
633
+ resourceUrl: "string",
634
+ sessionId: "string"
635
+ };
636
+ }
637
+ validate() {
638
+ if (this.desktopInfo && typeof this.desktopInfo.validate === "function") {
639
+ this.desktopInfo.validate();
640
+ }
641
+ super.validate();
642
+ }
643
+ constructor(map) {
644
+ super(map);
645
+ }
646
+ };
647
+ __name(_GetMcpResourceResponseBodyData, "GetMcpResourceResponseBodyData");
648
+ var GetMcpResourceResponseBodyData = _GetMcpResourceResponseBodyData;
649
+
650
+ // src/api/models/ListContextsResponseBodyData.ts
651
+ init_esm_shims();
652
+ import * as $dara6 from "@darabonba/typescript";
653
+ var _ListContextsResponseBodyData = class _ListContextsResponseBodyData extends $dara6.Model {
654
+ static names() {
655
+ return {
656
+ createTime: "CreateTime",
657
+ id: "Id",
658
+ lastUsedTime: "LastUsedTime",
659
+ name: "Name",
660
+ osType: "OsType",
661
+ state: "State"
662
+ };
663
+ }
664
+ static types() {
665
+ return {
666
+ createTime: "string",
667
+ id: "string",
668
+ lastUsedTime: "string",
669
+ name: "string",
670
+ osType: "string",
671
+ state: "string"
672
+ };
673
+ }
674
+ validate() {
675
+ super.validate();
676
+ }
677
+ constructor(map) {
678
+ super(map);
679
+ }
680
+ };
681
+ __name(_ListContextsResponseBodyData, "ListContextsResponseBodyData");
682
+ var ListContextsResponseBodyData = _ListContextsResponseBodyData;
683
+
684
+ // src/api/models/ListSessionResponseBodyData.ts
685
+ init_esm_shims();
686
+ import * as $dara7 from "@darabonba/typescript";
687
+ var _ListSessionResponseBodyData = class _ListSessionResponseBodyData extends $dara7.Model {
688
+ static names() {
689
+ return {
690
+ sessionId: "SessionId"
691
+ };
692
+ }
693
+ static types() {
694
+ return {
695
+ sessionId: "string"
696
+ };
697
+ }
698
+ validate() {
699
+ super.validate();
700
+ }
701
+ constructor(map) {
702
+ super(map);
703
+ }
704
+ };
705
+ __name(_ListSessionResponseBodyData, "ListSessionResponseBodyData");
706
+ var ListSessionResponseBodyData = _ListSessionResponseBodyData;
707
+
708
+ // src/api/models/CallMcpToolRequest.ts
709
+ init_esm_shims();
710
+ import * as $dara8 from "@darabonba/typescript";
711
+ var _CallMcpToolRequest = class _CallMcpToolRequest extends $dara8.Model {
712
+ static names() {
713
+ return {
714
+ args: "Args",
715
+ authorization: "Authorization",
716
+ externalUserId: "ExternalUserId",
717
+ imageId: "ImageId",
718
+ name: "Name",
719
+ server: "Server",
720
+ sessionId: "SessionId",
721
+ tool: "Tool"
722
+ };
723
+ }
724
+ static types() {
725
+ return {
726
+ args: "string",
727
+ authorization: "string",
728
+ externalUserId: "string",
729
+ imageId: "string",
730
+ name: "string",
731
+ server: "string",
732
+ sessionId: "string",
733
+ tool: "string"
734
+ };
735
+ }
736
+ validate() {
737
+ super.validate();
738
+ }
739
+ constructor(map) {
740
+ super(map);
741
+ }
742
+ };
743
+ __name(_CallMcpToolRequest, "CallMcpToolRequest");
744
+ var CallMcpToolRequest = _CallMcpToolRequest;
745
+
746
+ // src/api/models/CallMcpToolResponseBody.ts
747
+ init_esm_shims();
748
+ import * as $dara9 from "@darabonba/typescript";
749
+ var _CallMcpToolResponseBody = class _CallMcpToolResponseBody extends $dara9.Model {
750
+ static names() {
751
+ return {
752
+ code: "Code",
753
+ data: "Data",
754
+ httpStatusCode: "HttpStatusCode",
755
+ message: "Message",
756
+ requestId: "RequestId",
757
+ success: "Success"
758
+ };
759
+ }
760
+ static types() {
761
+ return {
762
+ code: "string",
763
+ data: "any",
764
+ httpStatusCode: "number",
765
+ message: "string",
766
+ requestId: "string",
767
+ success: "boolean"
768
+ };
769
+ }
770
+ validate() {
771
+ super.validate();
772
+ }
773
+ constructor(map) {
774
+ super(map);
775
+ }
776
+ };
777
+ __name(_CallMcpToolResponseBody, "CallMcpToolResponseBody");
778
+ var CallMcpToolResponseBody = _CallMcpToolResponseBody;
779
+
780
+ // src/api/models/CallMcpToolResponse.ts
781
+ init_esm_shims();
782
+ import * as $dara10 from "@darabonba/typescript";
783
+ var _CallMcpToolResponse = class _CallMcpToolResponse extends $dara10.Model {
784
+ static names() {
785
+ return {
786
+ headers: "headers",
787
+ statusCode: "statusCode",
788
+ body: "body"
789
+ };
790
+ }
791
+ static types() {
792
+ return {
793
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
794
+ statusCode: "number",
795
+ body: CallMcpToolResponseBody
796
+ };
797
+ }
798
+ validate() {
799
+ if (this.headers) {
800
+ $dara10.Model.validateMap(this.headers);
801
+ }
802
+ if (this.body && typeof this.body.validate === "function") {
803
+ this.body.validate();
804
+ }
805
+ super.validate();
806
+ }
807
+ constructor(map) {
808
+ super(map);
809
+ }
810
+ };
811
+ __name(_CallMcpToolResponse, "CallMcpToolResponse");
812
+ var CallMcpToolResponse = _CallMcpToolResponse;
813
+
814
+ // src/api/models/CreateMcpSessionRequest.ts
815
+ init_esm_shims();
816
+ import * as $dara11 from "@darabonba/typescript";
817
+ var _CreateMcpSessionRequest = class _CreateMcpSessionRequest extends $dara11.Model {
818
+ static names() {
819
+ return {
820
+ authorization: "Authorization",
821
+ contextId: "ContextId",
822
+ externalUserId: "ExternalUserId",
823
+ imageId: "ImageId",
824
+ labels: "Labels",
825
+ sessionId: "SessionId"
826
+ };
827
+ }
828
+ static types() {
829
+ return {
830
+ authorization: "string",
831
+ contextId: "string",
832
+ externalUserId: "string",
833
+ imageId: "string",
834
+ labels: "string",
835
+ sessionId: "string"
836
+ };
837
+ }
838
+ validate() {
839
+ super.validate();
840
+ }
841
+ constructor(map) {
842
+ super(map);
843
+ }
844
+ };
845
+ __name(_CreateMcpSessionRequest, "CreateMcpSessionRequest");
846
+ var CreateMcpSessionRequest = _CreateMcpSessionRequest;
847
+
848
+ // src/api/models/CreateMcpSessionResponseBody.ts
849
+ init_esm_shims();
850
+ import * as $dara12 from "@darabonba/typescript";
851
+ var _CreateMcpSessionResponseBody = class _CreateMcpSessionResponseBody extends $dara12.Model {
852
+ static names() {
853
+ return {
854
+ code: "Code",
855
+ data: "Data",
856
+ httpStatusCode: "HttpStatusCode",
857
+ message: "Message",
858
+ requestId: "RequestId",
859
+ success: "Success"
860
+ };
861
+ }
862
+ static types() {
863
+ return {
864
+ code: "string",
865
+ data: CreateMcpSessionResponseBodyData,
866
+ httpStatusCode: "number",
867
+ message: "string",
868
+ requestId: "string",
869
+ success: "boolean"
870
+ };
871
+ }
872
+ validate() {
873
+ if (this.data && typeof this.data.validate === "function") {
874
+ this.data.validate();
875
+ }
876
+ super.validate();
877
+ }
878
+ constructor(map) {
879
+ super(map);
880
+ }
881
+ };
882
+ __name(_CreateMcpSessionResponseBody, "CreateMcpSessionResponseBody");
883
+ var CreateMcpSessionResponseBody = _CreateMcpSessionResponseBody;
884
+
885
+ // src/api/models/CreateMcpSessionResponse.ts
886
+ init_esm_shims();
887
+ import * as $dara13 from "@darabonba/typescript";
888
+ var _CreateMcpSessionResponse = class _CreateMcpSessionResponse extends $dara13.Model {
889
+ static names() {
890
+ return {
891
+ headers: "headers",
892
+ statusCode: "statusCode",
893
+ body: "body"
894
+ };
895
+ }
896
+ static types() {
897
+ return {
898
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
899
+ statusCode: "number",
900
+ body: CreateMcpSessionResponseBody
901
+ };
902
+ }
903
+ validate() {
904
+ if (this.headers) {
905
+ $dara13.Model.validateMap(this.headers);
906
+ }
907
+ if (this.body && typeof this.body.validate === "function") {
908
+ this.body.validate();
909
+ }
910
+ super.validate();
911
+ }
912
+ constructor(map) {
913
+ super(map);
914
+ }
915
+ };
916
+ __name(_CreateMcpSessionResponse, "CreateMcpSessionResponse");
917
+ var CreateMcpSessionResponse = _CreateMcpSessionResponse;
918
+
919
+ // src/api/models/DeleteContextRequest.ts
920
+ init_esm_shims();
921
+ import * as $dara14 from "@darabonba/typescript";
922
+ var _DeleteContextRequest = class _DeleteContextRequest extends $dara14.Model {
923
+ static names() {
924
+ return {
925
+ authorization: "Authorization",
926
+ id: "Id"
927
+ };
928
+ }
929
+ static types() {
930
+ return {
931
+ authorization: "string",
932
+ id: "string"
933
+ };
934
+ }
935
+ validate() {
936
+ super.validate();
937
+ }
938
+ constructor(map) {
939
+ super(map);
940
+ }
941
+ };
942
+ __name(_DeleteContextRequest, "DeleteContextRequest");
943
+ var DeleteContextRequest = _DeleteContextRequest;
944
+
945
+ // src/api/models/DeleteContextResponseBody.ts
946
+ init_esm_shims();
947
+ import * as $dara15 from "@darabonba/typescript";
948
+ var _DeleteContextResponseBody = class _DeleteContextResponseBody extends $dara15.Model {
949
+ static names() {
950
+ return {
951
+ code: "Code",
952
+ httpStatusCode: "HttpStatusCode",
953
+ message: "Message",
954
+ requestId: "RequestId",
955
+ success: "Success"
956
+ };
957
+ }
958
+ static types() {
959
+ return {
960
+ code: "string",
961
+ httpStatusCode: "number",
962
+ message: "string",
963
+ requestId: "string",
964
+ success: "boolean"
965
+ };
966
+ }
967
+ validate() {
968
+ super.validate();
969
+ }
970
+ constructor(map) {
971
+ super(map);
972
+ }
973
+ };
974
+ __name(_DeleteContextResponseBody, "DeleteContextResponseBody");
975
+ var DeleteContextResponseBody = _DeleteContextResponseBody;
976
+
977
+ // src/api/models/DeleteContextResponse.ts
978
+ init_esm_shims();
979
+ import * as $dara16 from "@darabonba/typescript";
980
+ var _DeleteContextResponse = class _DeleteContextResponse extends $dara16.Model {
981
+ static names() {
982
+ return {
983
+ headers: "headers",
984
+ statusCode: "statusCode",
985
+ body: "body"
986
+ };
987
+ }
988
+ static types() {
989
+ return {
990
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
991
+ statusCode: "number",
992
+ body: DeleteContextResponseBody
993
+ };
994
+ }
995
+ validate() {
996
+ if (this.headers) {
997
+ $dara16.Model.validateMap(this.headers);
998
+ }
999
+ if (this.body && typeof this.body.validate === "function") {
1000
+ this.body.validate();
1001
+ }
1002
+ super.validate();
1003
+ }
1004
+ constructor(map) {
1005
+ super(map);
1006
+ }
1007
+ };
1008
+ __name(_DeleteContextResponse, "DeleteContextResponse");
1009
+ var DeleteContextResponse = _DeleteContextResponse;
1010
+
1011
+ // src/api/models/GetContextRequest.ts
1012
+ init_esm_shims();
1013
+ import * as $dara17 from "@darabonba/typescript";
1014
+ var _GetContextRequest = class _GetContextRequest extends $dara17.Model {
1015
+ static names() {
1016
+ return {
1017
+ allowCreate: "AllowCreate",
1018
+ authorization: "Authorization",
1019
+ name: "Name"
1020
+ };
1021
+ }
1022
+ static types() {
1023
+ return {
1024
+ allowCreate: "boolean",
1025
+ authorization: "string",
1026
+ name: "string"
1027
+ };
1028
+ }
1029
+ validate() {
1030
+ super.validate();
1031
+ }
1032
+ constructor(map) {
1033
+ super(map);
1034
+ }
1035
+ };
1036
+ __name(_GetContextRequest, "GetContextRequest");
1037
+ var GetContextRequest = _GetContextRequest;
1038
+
1039
+ // src/api/models/GetContextResponseBody.ts
1040
+ init_esm_shims();
1041
+ import * as $dara18 from "@darabonba/typescript";
1042
+ var _GetContextResponseBody = class _GetContextResponseBody extends $dara18.Model {
1043
+ static names() {
1044
+ return {
1045
+ code: "Code",
1046
+ data: "Data",
1047
+ httpStatusCode: "HttpStatusCode",
1048
+ message: "Message",
1049
+ requestId: "RequestId",
1050
+ success: "Success"
1051
+ };
1052
+ }
1053
+ static types() {
1054
+ return {
1055
+ code: "string",
1056
+ data: GetContextResponseBodyData,
1057
+ httpStatusCode: "number",
1058
+ message: "string",
1059
+ requestId: "string",
1060
+ success: "boolean"
1061
+ };
1062
+ }
1063
+ validate() {
1064
+ if (this.data && typeof this.data.validate === "function") {
1065
+ this.data.validate();
1066
+ }
1067
+ super.validate();
1068
+ }
1069
+ constructor(map) {
1070
+ super(map);
1071
+ }
1072
+ };
1073
+ __name(_GetContextResponseBody, "GetContextResponseBody");
1074
+ var GetContextResponseBody = _GetContextResponseBody;
1075
+
1076
+ // src/api/models/GetContextResponse.ts
1077
+ init_esm_shims();
1078
+ import * as $dara19 from "@darabonba/typescript";
1079
+ var _GetContextResponse = class _GetContextResponse extends $dara19.Model {
1080
+ static names() {
1081
+ return {
1082
+ headers: "headers",
1083
+ statusCode: "statusCode",
1084
+ body: "body"
1085
+ };
1086
+ }
1087
+ static types() {
1088
+ return {
1089
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
1090
+ statusCode: "number",
1091
+ body: GetContextResponseBody
1092
+ };
1093
+ }
1094
+ validate() {
1095
+ if (this.headers) {
1096
+ $dara19.Model.validateMap(this.headers);
1097
+ }
1098
+ if (this.body && typeof this.body.validate === "function") {
1099
+ this.body.validate();
1100
+ }
1101
+ super.validate();
1102
+ }
1103
+ constructor(map) {
1104
+ super(map);
1105
+ }
1106
+ };
1107
+ __name(_GetContextResponse, "GetContextResponse");
1108
+ var GetContextResponse = _GetContextResponse;
1109
+
1110
+ // src/api/models/GetLabelRequest.ts
1111
+ init_esm_shims();
1112
+ import * as $dara20 from "@darabonba/typescript";
1113
+ var _GetLabelRequest = class _GetLabelRequest extends $dara20.Model {
1114
+ static names() {
1115
+ return {
1116
+ authorization: "Authorization",
1117
+ maxResults: "MaxResults",
1118
+ nextToken: "NextToken",
1119
+ sessionId: "SessionId"
1120
+ };
1121
+ }
1122
+ static types() {
1123
+ return {
1124
+ authorization: "string",
1125
+ maxResults: "number",
1126
+ nextToken: "string",
1127
+ sessionId: "string"
1128
+ };
1129
+ }
1130
+ validate() {
1131
+ super.validate();
1132
+ }
1133
+ constructor(map) {
1134
+ super(map);
1135
+ }
1136
+ };
1137
+ __name(_GetLabelRequest, "GetLabelRequest");
1138
+ var GetLabelRequest = _GetLabelRequest;
1139
+
1140
+ // src/api/models/GetLabelResponseBody.ts
1141
+ init_esm_shims();
1142
+ import * as $dara21 from "@darabonba/typescript";
1143
+ var _GetLabelResponseBody = class _GetLabelResponseBody extends $dara21.Model {
1144
+ static names() {
1145
+ return {
1146
+ code: "Code",
1147
+ data: "Data",
1148
+ httpStatusCode: "HttpStatusCode",
1149
+ maxResults: "MaxResults",
1150
+ message: "Message",
1151
+ nextToken: "NextToken",
1152
+ requestId: "RequestId",
1153
+ success: "Success",
1154
+ totalCount: "TotalCount"
1155
+ };
1156
+ }
1157
+ static types() {
1158
+ return {
1159
+ code: "string",
1160
+ data: GetLabelResponseBodyData,
1161
+ httpStatusCode: "number",
1162
+ maxResults: "number",
1163
+ message: "string",
1164
+ nextToken: "string",
1165
+ requestId: "string",
1166
+ success: "boolean",
1167
+ totalCount: "number"
1168
+ };
1169
+ }
1170
+ validate() {
1171
+ if (this.data && typeof this.data.validate === "function") {
1172
+ this.data.validate();
1173
+ }
1174
+ super.validate();
1175
+ }
1176
+ constructor(map) {
1177
+ super(map);
1178
+ }
1179
+ };
1180
+ __name(_GetLabelResponseBody, "GetLabelResponseBody");
1181
+ var GetLabelResponseBody = _GetLabelResponseBody;
1182
+
1183
+ // src/api/models/GetLabelResponse.ts
1184
+ init_esm_shims();
1185
+ import * as $dara22 from "@darabonba/typescript";
1186
+ var _GetLabelResponse = class _GetLabelResponse extends $dara22.Model {
1187
+ static names() {
1188
+ return {
1189
+ headers: "headers",
1190
+ statusCode: "statusCode",
1191
+ body: "body"
1192
+ };
1193
+ }
1194
+ static types() {
1195
+ return {
1196
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
1197
+ statusCode: "number",
1198
+ body: GetLabelResponseBody
1199
+ };
1200
+ }
1201
+ validate() {
1202
+ if (this.headers) {
1203
+ $dara22.Model.validateMap(this.headers);
1204
+ }
1205
+ if (this.body && typeof this.body.validate === "function") {
1206
+ this.body.validate();
1207
+ }
1208
+ super.validate();
1209
+ }
1210
+ constructor(map) {
1211
+ super(map);
1212
+ }
1213
+ };
1214
+ __name(_GetLabelResponse, "GetLabelResponse");
1215
+ var GetLabelResponse = _GetLabelResponse;
1216
+
1217
+ // src/api/models/GetLinkRequest.ts
1218
+ init_esm_shims();
1219
+ import * as $dara23 from "@darabonba/typescript";
1220
+ var _GetLinkRequest = class _GetLinkRequest extends $dara23.Model {
1221
+ static names() {
1222
+ return {
1223
+ authorization: "Authorization",
1224
+ sessionId: "SessionId"
1225
+ };
1226
+ }
1227
+ static types() {
1228
+ return {
1229
+ authorization: "string",
1230
+ sessionId: "string"
1231
+ };
1232
+ }
1233
+ validate() {
1234
+ super.validate();
1235
+ }
1236
+ constructor(map) {
1237
+ super(map);
1238
+ }
1239
+ };
1240
+ __name(_GetLinkRequest, "GetLinkRequest");
1241
+ var GetLinkRequest = _GetLinkRequest;
1242
+
1243
+ // src/api/models/GetLinkResponseBody.ts
1244
+ init_esm_shims();
1245
+ import * as $dara24 from "@darabonba/typescript";
1246
+ var _GetLinkResponseBody = class _GetLinkResponseBody extends $dara24.Model {
1247
+ static names() {
1248
+ return {
1249
+ code: "Code",
1250
+ data: "Data",
1251
+ httpStatusCode: "HttpStatusCode",
1252
+ message: "Message",
1253
+ requestId: "RequestId",
1254
+ success: "Success"
1255
+ };
1256
+ }
1257
+ static types() {
1258
+ return {
1259
+ code: "string",
1260
+ data: "string",
1261
+ httpStatusCode: "number",
1262
+ message: "string",
1263
+ requestId: "string",
1264
+ success: "boolean"
1265
+ };
1266
+ }
1267
+ validate() {
1268
+ super.validate();
1269
+ }
1270
+ constructor(map) {
1271
+ super(map);
1272
+ }
1273
+ };
1274
+ __name(_GetLinkResponseBody, "GetLinkResponseBody");
1275
+ var GetLinkResponseBody = _GetLinkResponseBody;
1276
+
1277
+ // src/api/models/GetLinkResponse.ts
1278
+ init_esm_shims();
1279
+ import * as $dara25 from "@darabonba/typescript";
1280
+ var _GetLinkResponse = class _GetLinkResponse extends $dara25.Model {
1281
+ static names() {
1282
+ return {
1283
+ headers: "headers",
1284
+ statusCode: "statusCode",
1285
+ body: "body"
1286
+ };
1287
+ }
1288
+ static types() {
1289
+ return {
1290
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
1291
+ statusCode: "number",
1292
+ body: GetLinkResponseBody
1293
+ };
1294
+ }
1295
+ validate() {
1296
+ if (this.headers) {
1297
+ $dara25.Model.validateMap(this.headers);
1298
+ }
1299
+ if (this.body && typeof this.body.validate === "function") {
1300
+ this.body.validate();
1301
+ }
1302
+ super.validate();
1303
+ }
1304
+ constructor(map) {
1305
+ super(map);
1306
+ }
1307
+ };
1308
+ __name(_GetLinkResponse, "GetLinkResponse");
1309
+ var GetLinkResponse = _GetLinkResponse;
1310
+
1311
+ // src/api/models/GetMcpResourceRequest.ts
1312
+ init_esm_shims();
1313
+ import * as $dara26 from "@darabonba/typescript";
1314
+ var _GetMcpResourceRequest = class _GetMcpResourceRequest extends $dara26.Model {
1315
+ static names() {
1316
+ return {
1317
+ authorization: "Authorization",
1318
+ sessionId: "SessionId"
1319
+ };
1320
+ }
1321
+ static types() {
1322
+ return {
1323
+ authorization: "string",
1324
+ sessionId: "string"
1325
+ };
1326
+ }
1327
+ validate() {
1328
+ super.validate();
1329
+ }
1330
+ constructor(map) {
1331
+ super(map);
1332
+ }
1333
+ };
1334
+ __name(_GetMcpResourceRequest, "GetMcpResourceRequest");
1335
+ var GetMcpResourceRequest = _GetMcpResourceRequest;
1336
+
1337
+ // src/api/models/GetMcpResourceResponseBody.ts
1338
+ init_esm_shims();
1339
+ import * as $dara27 from "@darabonba/typescript";
1340
+ var _GetMcpResourceResponseBody = class _GetMcpResourceResponseBody extends $dara27.Model {
1341
+ static names() {
1342
+ return {
1343
+ code: "Code",
1344
+ data: "Data",
1345
+ httpStatusCode: "HttpStatusCode",
1346
+ message: "Message",
1347
+ requestId: "RequestId",
1348
+ success: "Success"
1349
+ };
1350
+ }
1351
+ static types() {
1352
+ return {
1353
+ code: "string",
1354
+ data: GetMcpResourceResponseBodyData,
1355
+ httpStatusCode: "number",
1356
+ message: "string",
1357
+ requestId: "string",
1358
+ success: "boolean"
1359
+ };
1360
+ }
1361
+ validate() {
1362
+ if (this.data && typeof this.data.validate === "function") {
1363
+ this.data.validate();
1364
+ }
1365
+ super.validate();
1366
+ }
1367
+ constructor(map) {
1368
+ super(map);
1369
+ }
1370
+ };
1371
+ __name(_GetMcpResourceResponseBody, "GetMcpResourceResponseBody");
1372
+ var GetMcpResourceResponseBody = _GetMcpResourceResponseBody;
1373
+
1374
+ // src/api/models/GetMcpResourceResponse.ts
1375
+ init_esm_shims();
1376
+ import * as $dara28 from "@darabonba/typescript";
1377
+ var _GetMcpResourceResponse = class _GetMcpResourceResponse extends $dara28.Model {
1378
+ static names() {
1379
+ return {
1380
+ headers: "headers",
1381
+ statusCode: "statusCode",
1382
+ body: "body"
1383
+ };
1384
+ }
1385
+ static types() {
1386
+ return {
1387
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
1388
+ statusCode: "number",
1389
+ body: GetMcpResourceResponseBody
1390
+ };
1391
+ }
1392
+ validate() {
1393
+ if (this.headers) {
1394
+ $dara28.Model.validateMap(this.headers);
1395
+ }
1396
+ if (this.body && typeof this.body.validate === "function") {
1397
+ this.body.validate();
1398
+ }
1399
+ super.validate();
1400
+ }
1401
+ constructor(map) {
1402
+ super(map);
1403
+ }
1404
+ };
1405
+ __name(_GetMcpResourceResponse, "GetMcpResourceResponse");
1406
+ var GetMcpResourceResponse = _GetMcpResourceResponse;
1407
+
1408
+ // src/api/models/ListContextsRequest.ts
1409
+ init_esm_shims();
1410
+ import * as $dara29 from "@darabonba/typescript";
1411
+ var _ListContextsRequest = class _ListContextsRequest extends $dara29.Model {
1412
+ static names() {
1413
+ return {
1414
+ authorization: "Authorization",
1415
+ maxResults: "MaxResults",
1416
+ nextToken: "NextToken"
1417
+ };
1418
+ }
1419
+ static types() {
1420
+ return {
1421
+ authorization: "string",
1422
+ maxResults: "number",
1423
+ nextToken: "string"
1424
+ };
1425
+ }
1426
+ validate() {
1427
+ super.validate();
1428
+ }
1429
+ constructor(map) {
1430
+ super(map);
1431
+ }
1432
+ };
1433
+ __name(_ListContextsRequest, "ListContextsRequest");
1434
+ var ListContextsRequest = _ListContextsRequest;
1435
+
1436
+ // src/api/models/ListContextsResponseBody.ts
1437
+ init_esm_shims();
1438
+ import * as $dara30 from "@darabonba/typescript";
1439
+ var _ListContextsResponseBody = class _ListContextsResponseBody extends $dara30.Model {
1440
+ static names() {
1441
+ return {
1442
+ code: "Code",
1443
+ data: "Data",
1444
+ httpStatusCode: "HttpStatusCode",
1445
+ maxResults: "MaxResults",
1446
+ message: "Message",
1447
+ nextToken: "NextToken",
1448
+ requestId: "RequestId",
1449
+ success: "Success",
1450
+ totalCount: "TotalCount"
1451
+ };
1452
+ }
1453
+ static types() {
1454
+ return {
1455
+ code: "string",
1456
+ data: { "type": "array", "itemType": ListContextsResponseBodyData },
1457
+ httpStatusCode: "number",
1458
+ maxResults: "number",
1459
+ message: "string",
1460
+ nextToken: "string",
1461
+ requestId: "string",
1462
+ success: "boolean",
1463
+ totalCount: "number"
1464
+ };
1465
+ }
1466
+ validate() {
1467
+ if (Array.isArray(this.data)) {
1468
+ $dara30.Model.validateArray(this.data);
1469
+ }
1470
+ super.validate();
1471
+ }
1472
+ constructor(map) {
1473
+ super(map);
1474
+ }
1475
+ };
1476
+ __name(_ListContextsResponseBody, "ListContextsResponseBody");
1477
+ var ListContextsResponseBody = _ListContextsResponseBody;
1478
+
1479
+ // src/api/models/ListContextsResponse.ts
1480
+ init_esm_shims();
1481
+ import * as $dara31 from "@darabonba/typescript";
1482
+ var _ListContextsResponse = class _ListContextsResponse extends $dara31.Model {
1483
+ static names() {
1484
+ return {
1485
+ headers: "headers",
1486
+ statusCode: "statusCode",
1487
+ body: "body"
1488
+ };
1489
+ }
1490
+ static types() {
1491
+ return {
1492
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
1493
+ statusCode: "number",
1494
+ body: ListContextsResponseBody
1495
+ };
1496
+ }
1497
+ validate() {
1498
+ if (this.headers) {
1499
+ $dara31.Model.validateMap(this.headers);
1500
+ }
1501
+ if (this.body && typeof this.body.validate === "function") {
1502
+ this.body.validate();
1503
+ }
1504
+ super.validate();
1505
+ }
1506
+ constructor(map) {
1507
+ super(map);
1508
+ }
1509
+ };
1510
+ __name(_ListContextsResponse, "ListContextsResponse");
1511
+ var ListContextsResponse = _ListContextsResponse;
1512
+
1513
+ // src/api/models/ListSessionRequest.ts
1514
+ init_esm_shims();
1515
+ import * as $dara32 from "@darabonba/typescript";
1516
+ var _ListSessionRequest = class _ListSessionRequest extends $dara32.Model {
1517
+ static names() {
1518
+ return {
1519
+ authorization: "Authorization",
1520
+ labels: "Labels",
1521
+ maxResults: "MaxResults",
1522
+ nextToken: "NextToken"
1523
+ };
1524
+ }
1525
+ static types() {
1526
+ return {
1527
+ authorization: "string",
1528
+ labels: "string",
1529
+ maxResults: "number",
1530
+ nextToken: "string"
1531
+ };
1532
+ }
1533
+ validate() {
1534
+ super.validate();
1535
+ }
1536
+ constructor(map) {
1537
+ super(map);
1538
+ }
1539
+ };
1540
+ __name(_ListSessionRequest, "ListSessionRequest");
1541
+ var ListSessionRequest = _ListSessionRequest;
1542
+
1543
+ // src/api/models/ListSessionResponseBody.ts
1544
+ init_esm_shims();
1545
+ import * as $dara33 from "@darabonba/typescript";
1546
+ var _ListSessionResponseBody = class _ListSessionResponseBody extends $dara33.Model {
1547
+ static names() {
1548
+ return {
1549
+ code: "Code",
1550
+ data: "Data",
1551
+ httpStatusCode: "HttpStatusCode",
1552
+ maxResults: "MaxResults",
1553
+ message: "Message",
1554
+ nextToken: "NextToken",
1555
+ requestId: "RequestId",
1556
+ success: "Success",
1557
+ totalCount: "TotalCount"
1558
+ };
1559
+ }
1560
+ static types() {
1561
+ return {
1562
+ code: "string",
1563
+ data: { "type": "array", "itemType": ListSessionResponseBodyData },
1564
+ httpStatusCode: "number",
1565
+ maxResults: "number",
1566
+ message: "string",
1567
+ nextToken: "string",
1568
+ requestId: "string",
1569
+ success: "boolean",
1570
+ totalCount: "number"
1571
+ };
1572
+ }
1573
+ validate() {
1574
+ if (Array.isArray(this.data)) {
1575
+ $dara33.Model.validateArray(this.data);
1576
+ }
1577
+ super.validate();
1578
+ }
1579
+ constructor(map) {
1580
+ super(map);
1581
+ }
1582
+ };
1583
+ __name(_ListSessionResponseBody, "ListSessionResponseBody");
1584
+ var ListSessionResponseBody = _ListSessionResponseBody;
1585
+
1586
+ // src/api/models/ListSessionResponse.ts
1587
+ init_esm_shims();
1588
+ import * as $dara34 from "@darabonba/typescript";
1589
+ var _ListSessionResponse = class _ListSessionResponse extends $dara34.Model {
1590
+ static names() {
1591
+ return {
1592
+ headers: "headers",
1593
+ statusCode: "statusCode",
1594
+ body: "body"
1595
+ };
1596
+ }
1597
+ static types() {
1598
+ return {
1599
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
1600
+ statusCode: "number",
1601
+ body: ListSessionResponseBody
1602
+ };
1603
+ }
1604
+ validate() {
1605
+ if (this.headers) {
1606
+ $dara34.Model.validateMap(this.headers);
1607
+ }
1608
+ if (this.body && typeof this.body.validate === "function") {
1609
+ this.body.validate();
1610
+ }
1611
+ super.validate();
1612
+ }
1613
+ constructor(map) {
1614
+ super(map);
1615
+ }
1616
+ };
1617
+ __name(_ListSessionResponse, "ListSessionResponse");
1618
+ var ListSessionResponse = _ListSessionResponse;
1619
+
1620
+ // src/api/models/ModifyContextRequest.ts
1621
+ init_esm_shims();
1622
+ import * as $dara35 from "@darabonba/typescript";
1623
+ var _ModifyContextRequest = class _ModifyContextRequest extends $dara35.Model {
1624
+ static names() {
1625
+ return {
1626
+ authorization: "Authorization",
1627
+ id: "Id",
1628
+ name: "Name"
1629
+ };
1630
+ }
1631
+ static types() {
1632
+ return {
1633
+ authorization: "string",
1634
+ id: "string",
1635
+ name: "string"
1636
+ };
1637
+ }
1638
+ validate() {
1639
+ super.validate();
1640
+ }
1641
+ constructor(map) {
1642
+ super(map);
1643
+ }
1644
+ };
1645
+ __name(_ModifyContextRequest, "ModifyContextRequest");
1646
+ var ModifyContextRequest = _ModifyContextRequest;
1647
+
1648
+ // src/api/models/ModifyContextResponseBody.ts
1649
+ init_esm_shims();
1650
+ import * as $dara36 from "@darabonba/typescript";
1651
+ var _ModifyContextResponseBody = class _ModifyContextResponseBody extends $dara36.Model {
1652
+ static names() {
1653
+ return {
1654
+ code: "Code",
1655
+ httpStatusCode: "HttpStatusCode",
1656
+ message: "Message",
1657
+ requestId: "RequestId",
1658
+ success: "Success"
1659
+ };
1660
+ }
1661
+ static types() {
1662
+ return {
1663
+ code: "string",
1664
+ httpStatusCode: "number",
1665
+ message: "string",
1666
+ requestId: "string",
1667
+ success: "boolean"
1668
+ };
1669
+ }
1670
+ validate() {
1671
+ super.validate();
1672
+ }
1673
+ constructor(map) {
1674
+ super(map);
1675
+ }
1676
+ };
1677
+ __name(_ModifyContextResponseBody, "ModifyContextResponseBody");
1678
+ var ModifyContextResponseBody = _ModifyContextResponseBody;
1679
+
1680
+ // src/api/models/ModifyContextResponse.ts
1681
+ init_esm_shims();
1682
+ import * as $dara37 from "@darabonba/typescript";
1683
+ var _ModifyContextResponse = class _ModifyContextResponse extends $dara37.Model {
1684
+ static names() {
1685
+ return {
1686
+ headers: "headers",
1687
+ statusCode: "statusCode",
1688
+ body: "body"
1689
+ };
1690
+ }
1691
+ static types() {
1692
+ return {
1693
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
1694
+ statusCode: "number",
1695
+ body: ModifyContextResponseBody
1696
+ };
1697
+ }
1698
+ validate() {
1699
+ if (this.headers) {
1700
+ $dara37.Model.validateMap(this.headers);
1701
+ }
1702
+ if (this.body && typeof this.body.validate === "function") {
1703
+ this.body.validate();
1704
+ }
1705
+ super.validate();
1706
+ }
1707
+ constructor(map) {
1708
+ super(map);
1709
+ }
1710
+ };
1711
+ __name(_ModifyContextResponse, "ModifyContextResponse");
1712
+ var ModifyContextResponse = _ModifyContextResponse;
1713
+
1714
+ // src/api/models/ReleaseMcpSessionRequest.ts
1715
+ init_esm_shims();
1716
+ import * as $dara38 from "@darabonba/typescript";
1717
+ var _ReleaseMcpSessionRequest = class _ReleaseMcpSessionRequest extends $dara38.Model {
1718
+ static names() {
1719
+ return {
1720
+ authorization: "Authorization",
1721
+ sessionId: "SessionId"
1722
+ };
1723
+ }
1724
+ static types() {
1725
+ return {
1726
+ authorization: "string",
1727
+ sessionId: "string"
1728
+ };
1729
+ }
1730
+ validate() {
1731
+ super.validate();
1732
+ }
1733
+ constructor(map) {
1734
+ super(map);
1735
+ }
1736
+ };
1737
+ __name(_ReleaseMcpSessionRequest, "ReleaseMcpSessionRequest");
1738
+ var ReleaseMcpSessionRequest = _ReleaseMcpSessionRequest;
1739
+
1740
+ // src/api/models/ReleaseMcpSessionResponseBody.ts
1741
+ init_esm_shims();
1742
+ import * as $dara39 from "@darabonba/typescript";
1743
+ var _ReleaseMcpSessionResponseBody = class _ReleaseMcpSessionResponseBody extends $dara39.Model {
1744
+ static names() {
1745
+ return {
1746
+ code: "Code",
1747
+ httpStatusCode: "HttpStatusCode",
1748
+ message: "Message",
1749
+ requestId: "RequestId",
1750
+ success: "Success"
1751
+ };
1752
+ }
1753
+ static types() {
1754
+ return {
1755
+ code: "string",
1756
+ httpStatusCode: "number",
1757
+ message: "string",
1758
+ requestId: "string",
1759
+ success: "boolean"
1760
+ };
1761
+ }
1762
+ validate() {
1763
+ super.validate();
1764
+ }
1765
+ constructor(map) {
1766
+ super(map);
1767
+ }
1768
+ };
1769
+ __name(_ReleaseMcpSessionResponseBody, "ReleaseMcpSessionResponseBody");
1770
+ var ReleaseMcpSessionResponseBody = _ReleaseMcpSessionResponseBody;
1771
+
1772
+ // src/api/models/ReleaseMcpSessionResponse.ts
1773
+ init_esm_shims();
1774
+ import * as $dara40 from "@darabonba/typescript";
1775
+ var _ReleaseMcpSessionResponse = class _ReleaseMcpSessionResponse extends $dara40.Model {
1776
+ static names() {
1777
+ return {
1778
+ headers: "headers",
1779
+ statusCode: "statusCode",
1780
+ body: "body"
1781
+ };
1782
+ }
1783
+ static types() {
1784
+ return {
1785
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
1786
+ statusCode: "number",
1787
+ body: ReleaseMcpSessionResponseBody
1788
+ };
1789
+ }
1790
+ validate() {
1791
+ if (this.headers) {
1792
+ $dara40.Model.validateMap(this.headers);
1793
+ }
1794
+ if (this.body && typeof this.body.validate === "function") {
1795
+ this.body.validate();
1796
+ }
1797
+ super.validate();
1798
+ }
1799
+ constructor(map) {
1800
+ super(map);
1801
+ }
1802
+ };
1803
+ __name(_ReleaseMcpSessionResponse, "ReleaseMcpSessionResponse");
1804
+ var ReleaseMcpSessionResponse = _ReleaseMcpSessionResponse;
1805
+
1806
+ // src/api/models/SetLabelRequest.ts
1807
+ init_esm_shims();
1808
+ import * as $dara41 from "@darabonba/typescript";
1809
+ var _SetLabelRequest = class _SetLabelRequest extends $dara41.Model {
1810
+ static names() {
1811
+ return {
1812
+ authorization: "Authorization",
1813
+ labels: "Labels",
1814
+ sessionId: "SessionId"
1815
+ };
1816
+ }
1817
+ static types() {
1818
+ return {
1819
+ authorization: "string",
1820
+ labels: "string",
1821
+ sessionId: "string"
1822
+ };
1823
+ }
1824
+ validate() {
1825
+ super.validate();
1826
+ }
1827
+ constructor(map) {
1828
+ super(map);
1829
+ }
1830
+ };
1831
+ __name(_SetLabelRequest, "SetLabelRequest");
1832
+ var SetLabelRequest = _SetLabelRequest;
1833
+
1834
+ // src/api/models/SetLabelResponseBody.ts
1835
+ init_esm_shims();
1836
+ import * as $dara42 from "@darabonba/typescript";
1837
+ var _SetLabelResponseBody = class _SetLabelResponseBody extends $dara42.Model {
1838
+ static names() {
1839
+ return {
1840
+ code: "Code",
1841
+ httpStatusCode: "HttpStatusCode",
1842
+ message: "Message",
1843
+ requestId: "RequestId",
1844
+ success: "Success"
1845
+ };
1846
+ }
1847
+ static types() {
1848
+ return {
1849
+ code: "string",
1850
+ httpStatusCode: "number",
1851
+ message: "string",
1852
+ requestId: "string",
1853
+ success: "boolean"
1854
+ };
1855
+ }
1856
+ validate() {
1857
+ super.validate();
1858
+ }
1859
+ constructor(map) {
1860
+ super(map);
1861
+ }
1862
+ };
1863
+ __name(_SetLabelResponseBody, "SetLabelResponseBody");
1864
+ var SetLabelResponseBody = _SetLabelResponseBody;
1865
+
1866
+ // src/api/models/SetLabelResponse.ts
1867
+ init_esm_shims();
1868
+ import * as $dara43 from "@darabonba/typescript";
1869
+ var _SetLabelResponse = class _SetLabelResponse extends $dara43.Model {
1870
+ static names() {
1871
+ return {
1872
+ headers: "headers",
1873
+ statusCode: "statusCode",
1874
+ body: "body"
1875
+ };
1876
+ }
1877
+ static types() {
1878
+ return {
1879
+ headers: { "type": "map", "keyType": "string", "valueType": "string" },
1880
+ statusCode: "number",
1881
+ body: SetLabelResponseBody
1882
+ };
1883
+ }
1884
+ validate() {
1885
+ if (this.headers) {
1886
+ $dara43.Model.validateMap(this.headers);
1887
+ }
1888
+ if (this.body && typeof this.body.validate === "function") {
1889
+ this.body.validate();
1890
+ }
1891
+ super.validate();
1892
+ }
1893
+ constructor(map) {
1894
+ super(map);
1895
+ }
1896
+ };
1897
+ __name(_SetLabelResponse, "SetLabelResponse");
1898
+ var SetLabelResponse = _SetLabelResponse;
1899
+
1900
+ // src/utils/logger.ts
1901
+ init_esm_shims();
1902
+ function log(message, ...args) {
1903
+ process.stdout.write(message + "\n");
1904
+ if (args.length > 0) {
1905
+ for (const arg of args) {
1906
+ if (typeof arg === "object") {
1907
+ process.stdout.write(JSON.stringify(arg, null, 2) + "\n");
1908
+ } else {
1909
+ process.stdout.write(String(arg) + "\n");
1910
+ }
1911
+ }
1912
+ }
1913
+ }
1914
+ __name(log, "log");
1915
+ function logError(message, error) {
1916
+ process.stderr.write(`ERROR: ${message}
1917
+ `);
1918
+ if (error) {
1919
+ if (error instanceof Error) {
1920
+ process.stderr.write(`${error.message}
1921
+ `);
1922
+ } else if (typeof error === "object") {
1923
+ process.stderr.write(JSON.stringify(error, null, 2) + "\n");
1924
+ } else {
1925
+ process.stderr.write(String(error) + "\n");
1926
+ }
1927
+ }
1928
+ }
1929
+ __name(logError, "logError");
1930
+
1931
+ // src/filesystem/filesystem.ts
1932
+ var DEFAULT_CHUNK_SIZE = 60 * 1024;
1933
+ var FILE_OPERATIONS = {
1934
+ "read_file": true,
1935
+ "write_file": true,
1936
+ "read_multiple_files": true
1937
+ };
1938
+ function isFileOperation(toolName) {
1939
+ return FILE_OPERATIONS[toolName] === true;
1940
+ }
1941
+ __name(isFileOperation, "isFileOperation");
1942
+ function truncateContentForLogging(args) {
1943
+ const truncatedArgs = { ...args };
1944
+ if (typeof truncatedArgs.content === "string") {
1945
+ const contentLength = truncatedArgs.content.length;
1946
+ truncatedArgs.content = `[Content length: ${contentLength} bytes]`;
1947
+ }
1948
+ if (Array.isArray(truncatedArgs.paths) && truncatedArgs.paths.length > 3) {
1949
+ truncatedArgs.paths = `[${truncatedArgs.paths.length} paths, first few: ${truncatedArgs.paths[0]}, ${truncatedArgs.paths[1]}, ${truncatedArgs.paths[2]}, ...]`;
1950
+ }
1951
+ return truncatedArgs;
1952
+ }
1953
+ __name(truncateContentForLogging, "truncateContentForLogging");
1954
+ function parseFileInfo(fileInfoStr) {
1955
+ const result = {
1956
+ name: "",
1957
+ path: "",
1958
+ size: 0,
1959
+ isDirectory: false,
1960
+ modTime: "",
1961
+ mode: ""
1962
+ };
1963
+ const lines = fileInfoStr.split("\n");
1964
+ for (const line of lines) {
1965
+ if (line.includes(":")) {
1966
+ const [key, value] = line.split(":", 2).map((part) => part.trim());
1967
+ switch (key) {
1968
+ case "name":
1969
+ result.name = value;
1970
+ break;
1971
+ case "path":
1972
+ result.path = value;
1973
+ break;
1974
+ case "size":
1975
+ result.size = parseInt(value, 10);
1976
+ break;
1977
+ case "isDirectory":
1978
+ result.isDirectory = value === "true";
1979
+ break;
1980
+ case "modTime":
1981
+ result.modTime = value;
1982
+ break;
1983
+ case "mode":
1984
+ result.mode = value;
1985
+ break;
1986
+ case "owner":
1987
+ result.owner = value;
1988
+ break;
1989
+ case "group":
1990
+ result.group = value;
1991
+ break;
1992
+ }
1993
+ }
1994
+ }
1995
+ return result;
1996
+ }
1997
+ __name(parseFileInfo, "parseFileInfo");
1998
+ function parseDirectoryListing(text) {
1999
+ const result = [];
2000
+ const lines = text.split("\n");
2001
+ for (const line of lines) {
2002
+ const trimmedLine = line.trim();
2003
+ if (trimmedLine === "") {
2004
+ continue;
2005
+ }
2006
+ if (trimmedLine.startsWith("[DIR]")) {
2007
+ result.push({
2008
+ isDirectory: true,
2009
+ name: trimmedLine.replace("[DIR]", "").trim()
2010
+ });
2011
+ } else if (trimmedLine.startsWith("[FILE]")) {
2012
+ result.push({
2013
+ isDirectory: false,
2014
+ name: trimmedLine.replace("[FILE]", "").trim()
2015
+ });
2016
+ }
2017
+ }
2018
+ return result;
2019
+ }
2020
+ __name(parseDirectoryListing, "parseDirectoryListing");
2021
+ var _FileSystem = class _FileSystem {
2022
+ /**
2023
+ * Initialize a FileSystem object.
2024
+ *
2025
+ * @param session - The Session instance that this FileSystem belongs to.
2026
+ */
2027
+ constructor(session) {
2028
+ this.session = session;
2029
+ }
2030
+ /**
2031
+ * Helper method to call MCP tools and handle common response processing
2032
+ *
2033
+ * @param toolName - Name of the MCP tool to call
2034
+ * @param args - Arguments to pass to the tool
2035
+ * @param defaultErrorMsg - Default error message if specific error details are not available
2036
+ * @returns A CallMcpToolResult with the response data
2037
+ * @throws APIError if the call fails
2038
+ */
2039
+ async callMcpTool(toolName, args, defaultErrorMsg) {
2040
+ try {
2041
+ let loggableArgs = args;
2042
+ if (isFileOperation(toolName)) {
2043
+ loggableArgs = truncateContentForLogging(args);
2044
+ }
2045
+ const argsJSON = JSON.stringify(args);
2046
+ const loggableArgsJSON = JSON.stringify(loggableArgs);
2047
+ const callToolRequest = new CallMcpToolRequest({
2048
+ authorization: `Bearer ${this.session.getAPIKey()}`,
2049
+ sessionId: this.session.getSessionId(),
2050
+ name: toolName,
2051
+ args: argsJSON
2052
+ });
2053
+ log(`API Call: CallMcpTool - ${toolName}`);
2054
+ log(`Request: SessionId=${this.session.getSessionId()}, Args=${loggableArgsJSON}`);
2055
+ const response = await this.session.getClient().callMcpTool(callToolRequest);
2056
+ if (isFileOperation(toolName)) {
2057
+ log(`Response from CallMcpTool - ${toolName} - status: ${response.statusCode}`);
2058
+ if (response.body?.data) {
2059
+ const data2 = response.body.data;
2060
+ if (data2.isError === true) {
2061
+ log(`Response contains error: ${data2.isError}`);
2062
+ } else {
2063
+ log("Response successful, content length info provided separately");
2064
+ if (Array.isArray(data2.content) && data2.content.length > 0) {
2065
+ let totalSize = 0;
2066
+ for (const item of data2.content) {
2067
+ if (item && typeof item === "object" && item.text && typeof item.text === "string") {
2068
+ totalSize += item.text.length;
2069
+ }
2070
+ }
2071
+ log(`Content size: ${totalSize} bytes`);
2072
+ }
2073
+ }
2074
+ }
2075
+ } else {
2076
+ const sanitizedBody = { ...response.body };
2077
+ if (sanitizedBody.data && typeof sanitizedBody.data === "object") {
2078
+ const sanitizedData = { ...sanitizedBody.data };
2079
+ if (Array.isArray(sanitizedData.content)) {
2080
+ sanitizedData.content = `[Array with ${sanitizedData.content.length} items]`;
2081
+ }
2082
+ sanitizedBody.data = sanitizedData;
2083
+ }
2084
+ log(`Response from CallMcpTool - ${toolName}:`, sanitizedBody);
2085
+ }
2086
+ if (!response.body?.data) {
2087
+ throw new Error("Invalid response data format");
2088
+ }
2089
+ const data = response.body.data;
2090
+ const result = {
2091
+ data,
2092
+ statusCode: response.statusCode || 0,
2093
+ isError: false
2094
+ };
2095
+ if (data.isError === true) {
2096
+ result.isError = true;
2097
+ const contentArray = data.content;
2098
+ if (contentArray && contentArray.length > 0) {
2099
+ result.content = contentArray;
2100
+ if (contentArray[0]?.text) {
2101
+ result.errorMsg = contentArray[0].text;
2102
+ throw new Error(contentArray[0].text);
2103
+ }
2104
+ }
2105
+ throw new Error(defaultErrorMsg);
2106
+ }
2107
+ if (Array.isArray(data.content)) {
2108
+ result.content = data.content;
2109
+ if (result.content.length > 0) {
2110
+ const textParts = [];
2111
+ for (const item of result.content) {
2112
+ if (item && typeof item === "object" && item.text && typeof item.text === "string") {
2113
+ textParts.push(item.text);
2114
+ }
2115
+ }
2116
+ result.textContent = textParts.join("\n");
2117
+ }
2118
+ }
2119
+ return result;
2120
+ } catch (error) {
2121
+ logError(`Error calling CallMcpTool - ${toolName}:`, error);
2122
+ throw new APIError(`Failed to call ${toolName}: ${error}`);
2123
+ }
2124
+ }
2125
+ /**
2126
+ * Creates a new directory at the specified path.
2127
+ *
2128
+ * @param path - Path to the directory to create.
2129
+ * @returns The extracted text content from the API response
2130
+ * @throws APIError if the operation fails.
2131
+ */
2132
+ async createDirectory(path3) {
2133
+ const args = {
2134
+ path: path3
2135
+ };
2136
+ const result = await this.callMcpTool("create_directory", args, "Failed to create directory");
2137
+ return result.textContent || "";
2138
+ }
2139
+ /**
2140
+ * Edits a file by replacing occurrences of oldText with newText.
2141
+ *
2142
+ * @param path - Path to the file to edit.
2143
+ * @param edits - Array of edit operations, each containing oldText and newText.
2144
+ * @param dryRun - Optional: If true, preview changes without applying them.
2145
+ * @returns The extracted text content from the API response
2146
+ * @throws APIError if the operation fails.
2147
+ */
2148
+ async editFile(path3, edits, dryRun = false) {
2149
+ const args = {
2150
+ path: path3,
2151
+ edits,
2152
+ dryRun
2153
+ };
2154
+ const result = await this.callMcpTool("edit_file", args, "Failed to edit file");
2155
+ return result.textContent || "";
2156
+ }
2157
+ /**
2158
+ * Gets information about a file or directory.
2159
+ *
2160
+ * @param path - Path to the file or directory to inspect.
2161
+ * @returns The extracted text content from the API response
2162
+ * @throws APIError if the operation fails.
2163
+ */
2164
+ async getFileInfo(path3) {
2165
+ const args = {
2166
+ path: path3
2167
+ };
2168
+ const result = await this.callMcpTool("get_file_info", args, "Failed to get file info");
2169
+ if (!result.textContent) {
2170
+ throw new APIError("Empty response from get_file_info");
2171
+ }
2172
+ return parseFileInfo(result.textContent);
2173
+ }
2174
+ /**
2175
+ * Lists the contents of a directory.
2176
+ *
2177
+ * @param path - Path to the directory to list.
2178
+ * @returns Array of directory entries with properties like name, isDirectory
2179
+ * @throws APIError if the operation fails.
2180
+ */
2181
+ async listDirectory(path3) {
2182
+ const args = {
2183
+ path: path3
2184
+ };
2185
+ const result = await this.callMcpTool("list_directory", args, "Failed to list directory");
2186
+ if (!result.textContent) {
2187
+ return [];
2188
+ }
2189
+ return parseDirectoryListing(result.textContent);
2190
+ }
2191
+ /**
2192
+ * Moves a file or directory from source to destination.
2193
+ *
2194
+ * @param source - Path to the source file or directory.
2195
+ * @param destination - Path to the destination file or directory.
2196
+ * @returns The extracted text content from the API response
2197
+ * @throws APIError if the operation fails.
2198
+ */
2199
+ async moveFile(source, destination) {
2200
+ const args = {
2201
+ source,
2202
+ destination
2203
+ };
2204
+ const result = await this.callMcpTool("move_file", args, "Failed to move file");
2205
+ return result.textContent || "";
2206
+ }
2207
+ /**
2208
+ * Reads the content of a file.
2209
+ *
2210
+ * @param path - Path to the file to read.
2211
+ * @param offset - Optional: Line offset to start reading from.
2212
+ * @param length - Optional: Number of lines to read. If 0, reads the entire file.
2213
+ * @returns The extracted text content from the API response
2214
+ * @throws APIError if the operation fails.
2215
+ */
2216
+ async readFile(path3, offset = 0, length = 0) {
2217
+ const args = {
2218
+ path: path3
2219
+ };
2220
+ if (offset > 0) {
2221
+ args.offset = offset;
2222
+ }
2223
+ if (length > 0) {
2224
+ args.length = length;
2225
+ }
2226
+ const result = await this.callMcpTool("read_file", args, "Failed to read file");
2227
+ return result.textContent || "";
2228
+ }
2229
+ /**
2230
+ * Reads the content of multiple files.
2231
+ *
2232
+ * @param paths - Array of file paths to read.
2233
+ * @returns The extracted text content from the API response
2234
+ * @throws APIError if the operation fails.
2235
+ */
2236
+ async readMultipleFiles(paths) {
2237
+ const args = {
2238
+ paths
2239
+ };
2240
+ const result = await this.callMcpTool("read_multiple_files", args, "Failed to read multiple files");
2241
+ if (!result.textContent) {
2242
+ return {};
2243
+ }
2244
+ const fileContents = {};
2245
+ const lines = result.textContent.split("\n");
2246
+ let currentPath = "";
2247
+ let currentContent = [];
2248
+ for (const line of lines) {
2249
+ const colonIndex = line.indexOf(":");
2250
+ if (colonIndex > 0 && currentPath === "" && !line.substring(0, colonIndex).includes(" ")) {
2251
+ const path3 = line.substring(0, colonIndex).trim();
2252
+ currentPath = path3;
2253
+ if (line.length > colonIndex + 1) {
2254
+ const contentStart = line.substring(colonIndex + 1).trim();
2255
+ if (contentStart) {
2256
+ currentContent.push(contentStart);
2257
+ }
2258
+ }
2259
+ } else if (line === "---") {
2260
+ if (currentPath) {
2261
+ fileContents[currentPath] = currentContent.join("\n");
2262
+ currentPath = "";
2263
+ currentContent = [];
2264
+ }
2265
+ } else if (currentPath) {
2266
+ currentContent.push(line);
2267
+ }
2268
+ }
2269
+ if (currentPath) {
2270
+ fileContents[currentPath] = currentContent.join("\n");
2271
+ }
2272
+ for (const path3 in fileContents) {
2273
+ fileContents[path3] = fileContents[path3].replace(/\n+$/, "");
2274
+ }
2275
+ return fileContents;
2276
+ }
2277
+ /**
2278
+ * Searches for files in a directory that match a pattern.
2279
+ *
2280
+ * @param path - Path to the directory to search in.
2281
+ * @param pattern - Pattern to search for. Supports glob patterns.
2282
+ * @param excludePatterns - Optional: Array of patterns to exclude.
2283
+ * @returns Array of search results with properties like path
2284
+ * @throws APIError if the operation fails.
2285
+ */
2286
+ async searchFiles(path3, pattern, excludePatterns = []) {
2287
+ const args = {
2288
+ path: path3,
2289
+ pattern
2290
+ };
2291
+ if (excludePatterns.length > 0) {
2292
+ args.exclude_patterns = excludePatterns;
2293
+ }
2294
+ const result = await this.callMcpTool("search_files", args, "Failed to search files");
2295
+ if (!result.textContent) {
2296
+ return [];
2297
+ }
2298
+ return result.textContent.split("\n").map((line) => line.trim()).filter((line) => line !== "");
2299
+ }
2300
+ /**
2301
+ * Writes content to a file.
2302
+ *
2303
+ * @param path - Path to the file to write.
2304
+ * @param content - Content to write to the file.
2305
+ * @param mode - Optional: Write mode. One of "overwrite", "append", or "create_new". Default is "overwrite".
2306
+ * @returns The extracted text content from the API response
2307
+ * @throws APIError if the operation fails.
2308
+ */
2309
+ async writeFile(path3, content, mode = "overwrite") {
2310
+ const validModes = ["overwrite", "append", "create_new"];
2311
+ if (!validModes.includes(mode)) {
2312
+ throw new APIError(`Invalid mode: ${mode}. Must be one of ${validModes.join(", ")}`);
2313
+ }
2314
+ const args = {
2315
+ path: path3,
2316
+ content,
2317
+ mode
2318
+ };
2319
+ const result = await this.callMcpTool("write_file", args, "Failed to write file");
2320
+ return result.textContent || "";
2321
+ }
2322
+ /**
2323
+ * Reads a large file in chunks to handle size limitations of the underlying API.
2324
+ * It automatically splits the read operation into multiple requests of chunkSize bytes each.
2325
+ *
2326
+ * @param path - Path to the file to read.
2327
+ * @param chunkSize - Optional: Size of each chunk in bytes. Default is 60KB.
2328
+ * @returns The complete file content as a string
2329
+ * @throws APIError if the operation fails.
2330
+ */
2331
+ async readLargeFile(path3, chunkSize = DEFAULT_CHUNK_SIZE) {
2332
+ const fileInfo = await this.getFileInfo(path3);
2333
+ const fileSize = fileInfo.size;
2334
+ if (fileSize === 0) {
2335
+ throw new APIError("Couldn't determine file size");
2336
+ }
2337
+ let result = "";
2338
+ let offset = 0;
2339
+ log(`ReadLargeFile: Starting chunked read of ${path3} (total size: ${fileSize} bytes, chunk size: ${chunkSize} bytes)`);
2340
+ let chunkCount = 0;
2341
+ while (offset < fileSize) {
2342
+ let length = chunkSize;
2343
+ if (offset + length > fileSize) {
2344
+ length = fileSize - offset;
2345
+ }
2346
+ log(`ReadLargeFile: Reading chunk ${chunkCount + 1} (${length} bytes at offset ${offset}/${fileSize})`);
2347
+ try {
2348
+ const chunk = await this.readFile(path3, offset, length);
2349
+ result += chunk;
2350
+ offset += length;
2351
+ chunkCount++;
2352
+ } catch (error) {
2353
+ logError(`Error reading chunk at offset ${offset}: ${error}`);
2354
+ throw new APIError(`Error reading chunk at offset ${offset}: ${error}`);
2355
+ }
2356
+ }
2357
+ log(`ReadLargeFile: Successfully read ${path3} in ${chunkCount} chunks (total: ${fileSize} bytes)`);
2358
+ return result;
2359
+ }
2360
+ /**
2361
+ * Writes a large file in chunks to handle size limitations of the underlying API.
2362
+ * It automatically splits the write operation into multiple requests of chunkSize bytes each.
2363
+ *
2364
+ * @param path - Path to the file to write.
2365
+ * @param content - Content to write to the file.
2366
+ * @param chunkSize - Optional: Size of each chunk in bytes. Default is 60KB.
2367
+ * @returns True if the operation was successful
2368
+ * @throws APIError if the operation fails.
2369
+ */
2370
+ async writeLargeFile(path3, content, chunkSize = DEFAULT_CHUNK_SIZE) {
2371
+ const contentLen = content.length;
2372
+ log(`WriteLargeFile: Starting chunked write to ${path3} (total size: ${contentLen} bytes, chunk size: ${chunkSize} bytes)`);
2373
+ if (contentLen <= chunkSize) {
2374
+ log(`WriteLargeFile: Content size (${contentLen} bytes) is smaller than chunk size, using normal WriteFile`);
2375
+ await this.writeFile(path3, content, "overwrite");
2376
+ return true;
2377
+ }
2378
+ const firstChunkEnd = Math.min(chunkSize, contentLen);
2379
+ log(`WriteLargeFile: Writing first chunk (0-${firstChunkEnd} bytes) with overwrite mode`);
2380
+ await this.writeFile(path3, content.substring(0, firstChunkEnd), "overwrite");
2381
+ let chunkCount = 1;
2382
+ for (let offset = firstChunkEnd; offset < contentLen; ) {
2383
+ const end = Math.min(offset + chunkSize, contentLen);
2384
+ log(`WriteLargeFile: Writing chunk ${chunkCount + 1} (${offset}-${end} bytes) with append mode`);
2385
+ await this.writeFile(path3, content.substring(offset, end), "append");
2386
+ offset = end;
2387
+ chunkCount++;
2388
+ }
2389
+ log(`WriteLargeFile: Successfully wrote ${path3} in ${chunkCount} chunks (total: ${contentLen} bytes)`);
2390
+ return true;
2391
+ }
2392
+ };
2393
+ __name(_FileSystem, "FileSystem");
2394
+ var FileSystem = _FileSystem;
2395
+
2396
+ // src/command/command.ts
2397
+ init_esm_shims();
2398
+ var _Command = class _Command {
2399
+ /**
2400
+ * Initialize a Command object.
2401
+ *
2402
+ * @param session - The Session instance that this Command belongs to.
2403
+ */
2404
+ constructor(session) {
2405
+ this.session = session;
2406
+ }
2407
+ /**
2408
+ * Helper method to call MCP tools and handle common response processing
2409
+ *
2410
+ * @param toolName - Name of the MCP tool to call
2411
+ * @param args - Arguments to pass to the tool
2412
+ * @param defaultErrorMsg - Default error message if specific error details are not available
2413
+ * @returns A CallMcpToolResult with the response data
2414
+ * @throws APIError if the call fails
2415
+ */
2416
+ async callMcpTool(toolName, args, defaultErrorMsg) {
2417
+ try {
2418
+ const argsJSON = JSON.stringify(args);
2419
+ const callToolRequest = new CallMcpToolRequest({
2420
+ authorization: `Bearer ${this.session.getAPIKey()}`,
2421
+ sessionId: this.session.getSessionId(),
2422
+ name: toolName,
2423
+ args: argsJSON
2424
+ });
2425
+ log(`API Call: CallMcpTool - ${toolName}`);
2426
+ log(`Request: SessionId=${this.session.getSessionId()}, Args=${argsJSON}`);
2427
+ const response = await this.session.getClient().callMcpTool(callToolRequest);
2428
+ log(`Response from CallMcpTool - ${toolName}:`, response.body);
2429
+ if (!response.body?.data) {
2430
+ throw new Error("Invalid response data format");
2431
+ }
2432
+ const data = response.body.data;
2433
+ const result = {
2434
+ data,
2435
+ statusCode: response.statusCode || 0,
2436
+ isError: false
2437
+ };
2438
+ if (data.isError === true) {
2439
+ result.isError = true;
2440
+ const contentArray = data.content;
2441
+ if (contentArray && contentArray.length > 0) {
2442
+ result.content = contentArray;
2443
+ if (contentArray[0]?.text) {
2444
+ result.errorMsg = contentArray[0].text;
2445
+ throw new Error(contentArray[0].text);
2446
+ }
2447
+ }
2448
+ throw new Error(defaultErrorMsg);
2449
+ }
2450
+ if (Array.isArray(data.content)) {
2451
+ result.content = data.content;
2452
+ if (result.content.length > 0) {
2453
+ const textParts = [];
2454
+ for (const item of result.content) {
2455
+ if (item && typeof item === "object" && item.text && typeof item.text === "string") {
2456
+ textParts.push(item.text);
2457
+ }
2458
+ }
2459
+ result.textContent = textParts.join("\n");
2460
+ }
2461
+ }
2462
+ return result;
2463
+ } catch (error) {
2464
+ logError(`Error calling CallMcpTool - ${toolName}:`, error);
2465
+ throw new APIError(`Failed to call ${toolName}: ${error}`);
2466
+ }
2467
+ }
2468
+ /**
2469
+ * Helper method to parse JSON string or return a simple object with output
2470
+ */
2471
+ parseCommandResult(text) {
2472
+ try {
2473
+ return JSON.parse(text);
2474
+ } catch (error) {
2475
+ return { output: text };
2476
+ }
2477
+ }
2478
+ /**
2479
+ * Execute a command in the cloud environment with a specified timeout.
2480
+ *
2481
+ * @param command - The command to execute.
2482
+ * @param timeoutMs - The timeout for the command execution in milliseconds. Default is 1000ms.
2483
+ * @returns A string containing the command output
2484
+ */
2485
+ async executeCommand(command, timeoutMs = 1e3) {
2486
+ const args = {
2487
+ command,
2488
+ timeout_ms: timeoutMs
2489
+ };
2490
+ const result = await this.callMcpTool("shell", args, "Failed to execute command");
2491
+ return result.textContent || "";
2492
+ }
2493
+ /**
2494
+ * Helper method to parse JSON string or return a simple object with output
2495
+ */
2496
+ parseCodeExecutionResult(text) {
2497
+ try {
2498
+ return JSON.parse(text);
2499
+ } catch (error) {
2500
+ return { output: text };
2501
+ }
2502
+ }
2503
+ /**
2504
+ * Execute code in the specified language with a timeout.
2505
+ *
2506
+ * @param code - The code to execute.
2507
+ * @param language - The programming language of the code. Must be either 'python' or 'javascript'.
2508
+ * @param timeoutS - The timeout for the code execution in seconds. Default is 300s.
2509
+ * @returns A string containing the code execution output
2510
+ * @throws APIError if the code execution fails or if an unsupported language is specified.
2511
+ */
2512
+ async runCode(code, language, timeoutS = 300) {
2513
+ if (language !== "python" && language !== "javascript") {
2514
+ throw new Error(`Unsupported language: ${language}. Supported languages are 'python' and 'javascript'`);
2515
+ }
2516
+ const args = {
2517
+ code,
2518
+ language,
2519
+ timeout_s: timeoutS
2520
+ };
2521
+ const result = await this.callMcpTool("run_code", args, "Failed to execute code");
2522
+ return result.textContent || "";
2523
+ }
2524
+ };
2525
+ __name(_Command, "Command");
2526
+ var Command = _Command;
2527
+
2528
+ // src/oss/index.ts
2529
+ init_esm_shims();
2530
+
2531
+ // src/oss/oss.ts
2532
+ init_esm_shims();
2533
+
2534
+ // src/api/index.ts
2535
+ init_esm_shims();
2536
+
2537
+ // src/api/client.ts
2538
+ init_esm_shims();
2539
+ import * as $dara44 from "@darabonba/typescript";
2540
+ import { OpenApiUtil, $OpenApiUtil } from "@alicloud/openapi-core";
2541
+ import * as OpenApiDefault from "@alicloud/openapi-core";
2542
+ var OpenApi = OpenApiDefault.default || OpenApiDefault;
2543
+ var _Client = class _Client extends (OpenApi.default || OpenApi) {
2544
+ constructor(config) {
2545
+ super(config);
2546
+ this._signatureAlgorithm = "v2";
2547
+ this._endpointRule = "";
2548
+ this.checkConfig(config);
2549
+ this._endpoint = this.getEndpoint("wuyingai", this._regionId, this._endpointRule, this._network, this._suffix, this._endpointMap, this._endpoint);
2550
+ }
2551
+ getEndpoint(productId, regionId, endpointRule, network, suffix, endpointMap, endpoint) {
2552
+ if (!$dara44.isNull(endpoint)) {
2553
+ return endpoint;
2554
+ }
2555
+ if (!$dara44.isNull(endpointMap) && !$dara44.isNull(endpointMap[regionId])) {
2556
+ return endpointMap[regionId];
2557
+ }
2558
+ return OpenApiUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
2559
+ }
2560
+ /**
2561
+ * 调用mcp工具
2562
+ *
2563
+ * @param request - CallMcpToolRequest
2564
+ * @param runtime - runtime options for this request RuntimeOptions
2565
+ * @returns CallMcpToolResponse
2566
+ */
2567
+ async callMcpToolWithOptions(request, runtime) {
2568
+ request.validate();
2569
+ let body = {};
2570
+ if (!$dara44.isNull(request.args)) {
2571
+ body["Args"] = request.args;
2572
+ }
2573
+ if (!$dara44.isNull(request.authorization)) {
2574
+ body["Authorization"] = request.authorization;
2575
+ }
2576
+ if (!$dara44.isNull(request.externalUserId)) {
2577
+ body["ExternalUserId"] = request.externalUserId;
2578
+ }
2579
+ if (!$dara44.isNull(request.imageId)) {
2580
+ body["ImageId"] = request.imageId;
2581
+ }
2582
+ if (!$dara44.isNull(request.name)) {
2583
+ body["Name"] = request.name;
2584
+ }
2585
+ if (!$dara44.isNull(request.server)) {
2586
+ body["Server"] = request.server;
2587
+ }
2588
+ if (!$dara44.isNull(request.sessionId)) {
2589
+ body["SessionId"] = request.sessionId;
2590
+ }
2591
+ if (!$dara44.isNull(request.tool)) {
2592
+ body["Tool"] = request.tool;
2593
+ }
2594
+ let req = new $OpenApiUtil.OpenApiRequest({
2595
+ body: OpenApiUtil.parseToMap(body)
2596
+ });
2597
+ let params = new $OpenApiUtil.Params({
2598
+ action: "CallMcpTool",
2599
+ version: "2025-05-06",
2600
+ protocol: "HTTPS",
2601
+ pathname: "/",
2602
+ method: "POST",
2603
+ authType: "Anonymous",
2604
+ style: "RPC",
2605
+ reqBodyType: "formData",
2606
+ bodyType: "json"
2607
+ });
2608
+ return $dara44.cast(await this.callApi(params, req, runtime), new CallMcpToolResponse({}));
2609
+ }
2610
+ /**
2611
+ * 调用mcp工具
2612
+ *
2613
+ * @param request - CallMcpToolRequest
2614
+ * @returns CallMcpToolResponse
2615
+ */
2616
+ async callMcpTool(request) {
2617
+ let runtime = new $dara44.RuntimeOptions({});
2618
+ return await this.callMcpToolWithOptions(request, runtime);
2619
+ }
2620
+ /**
2621
+ * 创建 mcp session
2622
+ *
2623
+ * @param request - CreateMcpSessionRequest
2624
+ * @param runtime - runtime options for this request RuntimeOptions
2625
+ * @returns CreateMcpSessionResponse
2626
+ */
2627
+ async createMcpSessionWithOptions(request, runtime) {
2628
+ request.validate();
2629
+ let body = {};
2630
+ if (!$dara44.isNull(request.authorization)) {
2631
+ body["Authorization"] = request.authorization;
2632
+ }
2633
+ if (!$dara44.isNull(request.contextId)) {
2634
+ body["ContextId"] = request.contextId;
2635
+ }
2636
+ if (!$dara44.isNull(request.externalUserId)) {
2637
+ body["ExternalUserId"] = request.externalUserId;
2638
+ }
2639
+ if (!$dara44.isNull(request.imageId)) {
2640
+ body["ImageId"] = request.imageId;
2641
+ }
2642
+ if (!$dara44.isNull(request.labels)) {
2643
+ body["Labels"] = request.labels;
2644
+ }
2645
+ if (!$dara44.isNull(request.sessionId)) {
2646
+ body["SessionId"] = request.sessionId;
2647
+ }
2648
+ if (!$dara44.isNull(request.imageId)) {
2649
+ body["ImageId"] = request.imageId;
2650
+ }
2651
+ let req = new $OpenApiUtil.OpenApiRequest({
2652
+ body: OpenApiUtil.parseToMap(body)
2653
+ });
2654
+ let params = new $OpenApiUtil.Params({
2655
+ action: "CreateMcpSession",
2656
+ version: "2025-05-06",
2657
+ protocol: "HTTPS",
2658
+ pathname: "/",
2659
+ method: "POST",
2660
+ authType: "Anonymous",
2661
+ style: "RPC",
2662
+ reqBodyType: "formData",
2663
+ bodyType: "json"
2664
+ });
2665
+ return $dara44.cast(await this.callApi(params, req, runtime), new CreateMcpSessionResponse({}));
2666
+ }
2667
+ /**
2668
+ * 创建 mcp session
2669
+ *
2670
+ * @param request - CreateMcpSessionRequest
2671
+ * @returns CreateMcpSessionResponse
2672
+ */
2673
+ async createMcpSession(request) {
2674
+ let runtime = new $dara44.RuntimeOptions({});
2675
+ return await this.createMcpSessionWithOptions(request, runtime);
2676
+ }
2677
+ /**
2678
+ * 删除持久化上下文
2679
+ *
2680
+ * @param request - DeleteContextRequest
2681
+ * @param runtime - runtime options for this request RuntimeOptions
2682
+ * @returns DeleteContextResponse
2683
+ */
2684
+ async deleteContextWithOptions(request, runtime) {
2685
+ request.validate();
2686
+ let body = {};
2687
+ if (!$dara44.isNull(request.authorization)) {
2688
+ body["Authorization"] = request.authorization;
2689
+ }
2690
+ if (!$dara44.isNull(request.id)) {
2691
+ body["Id"] = request.id;
2692
+ }
2693
+ let req = new $OpenApiUtil.OpenApiRequest({
2694
+ body: OpenApiUtil.parseToMap(body)
2695
+ });
2696
+ let params = new $OpenApiUtil.Params({
2697
+ action: "DeleteContext",
2698
+ version: "2025-05-06",
2699
+ protocol: "HTTPS",
2700
+ pathname: "/",
2701
+ method: "POST",
2702
+ authType: "Anonymous",
2703
+ style: "RPC",
2704
+ reqBodyType: "formData",
2705
+ bodyType: "json"
2706
+ });
2707
+ return $dara44.cast(await this.callApi(params, req, runtime), new DeleteContextResponse({}));
2708
+ }
2709
+ /**
2710
+ * 删除持久化上下文
2711
+ *
2712
+ * @param request - DeleteContextRequest
2713
+ * @returns DeleteContextResponse
2714
+ */
2715
+ async deleteContext(request) {
2716
+ let runtime = new $dara44.RuntimeOptions({});
2717
+ return await this.deleteContextWithOptions(request, runtime);
2718
+ }
2719
+ /**
2720
+ * 获取上下文
2721
+ *
2722
+ * @param request - GetContextRequest
2723
+ * @param runtime - runtime options for this request RuntimeOptions
2724
+ * @returns GetContextResponse
2725
+ */
2726
+ async getContextWithOptions(request, runtime) {
2727
+ request.validate();
2728
+ let body = {};
2729
+ if (!$dara44.isNull(request.allowCreate)) {
2730
+ body["AllowCreate"] = request.allowCreate;
2731
+ }
2732
+ if (!$dara44.isNull(request.authorization)) {
2733
+ body["Authorization"] = request.authorization;
2734
+ }
2735
+ if (!$dara44.isNull(request.name)) {
2736
+ body["Name"] = request.name;
2737
+ }
2738
+ let req = new $OpenApiUtil.OpenApiRequest({
2739
+ body: OpenApiUtil.parseToMap(body)
2740
+ });
2741
+ let params = new $OpenApiUtil.Params({
2742
+ action: "GetContext",
2743
+ version: "2025-05-06",
2744
+ protocol: "HTTPS",
2745
+ pathname: "/",
2746
+ method: "POST",
2747
+ authType: "Anonymous",
2748
+ style: "RPC",
2749
+ reqBodyType: "formData",
2750
+ bodyType: "json"
2751
+ });
2752
+ return $dara44.cast(await this.callApi(params, req, runtime), new GetContextResponse({}));
2753
+ }
2754
+ /**
2755
+ * 获取上下文
2756
+ *
2757
+ * @param request - GetContextRequest
2758
+ * @returns GetContextResponse
2759
+ */
2760
+ async getContext(request) {
2761
+ let runtime = new $dara44.RuntimeOptions({});
2762
+ return await this.getContextWithOptions(request, runtime);
2763
+ }
2764
+ /**
2765
+ * 获取标签
2766
+ *
2767
+ * @param request - GetLabelRequest
2768
+ * @param runtime - runtime options for this request RuntimeOptions
2769
+ * @returns GetLabelResponse
2770
+ */
2771
+ async getLabelWithOptions(request, runtime) {
2772
+ request.validate();
2773
+ let body = {};
2774
+ if (!$dara44.isNull(request.authorization)) {
2775
+ body["Authorization"] = request.authorization;
2776
+ }
2777
+ if (!$dara44.isNull(request.maxResults)) {
2778
+ body["MaxResults"] = request.maxResults;
2779
+ }
2780
+ if (!$dara44.isNull(request.nextToken)) {
2781
+ body["NextToken"] = request.nextToken;
2782
+ }
2783
+ if (!$dara44.isNull(request.sessionId)) {
2784
+ body["SessionId"] = request.sessionId;
2785
+ }
2786
+ let req = new $OpenApiUtil.OpenApiRequest({
2787
+ body: OpenApiUtil.parseToMap(body)
2788
+ });
2789
+ let params = new $OpenApiUtil.Params({
2790
+ action: "GetLabel",
2791
+ version: "2025-05-06",
2792
+ protocol: "HTTPS",
2793
+ pathname: "/",
2794
+ method: "POST",
2795
+ authType: "Anonymous",
2796
+ style: "RPC",
2797
+ reqBodyType: "formData",
2798
+ bodyType: "json"
2799
+ });
2800
+ return $dara44.cast(await this.callApi(params, req, runtime), new GetLabelResponse({}));
2801
+ }
2802
+ /**
2803
+ * 获取标签
2804
+ *
2805
+ * @param request - GetLabelRequest
2806
+ * @returns GetLabelResponse
2807
+ */
2808
+ async getLabel(request) {
2809
+ let runtime = new $dara44.RuntimeOptions({});
2810
+ return await this.getLabelWithOptions(request, runtime);
2811
+ }
2812
+ /**
2813
+ * 获取特定端口的转发链接
2814
+ *
2815
+ * @param request - GetLinkRequest
2816
+ * @param runtime - runtime options for this request RuntimeOptions
2817
+ * @returns GetLinkResponse
2818
+ */
2819
+ async getLinkWithOptions(request, runtime) {
2820
+ request.validate();
2821
+ let body = {};
2822
+ if (!$dara44.isNull(request.authorization)) {
2823
+ body["Authorization"] = request.authorization;
2824
+ }
2825
+ if (!$dara44.isNull(request.sessionId)) {
2826
+ body["SessionId"] = request.sessionId;
2827
+ }
2828
+ let req = new $OpenApiUtil.OpenApiRequest({
2829
+ body: OpenApiUtil.parseToMap(body)
2830
+ });
2831
+ let params = new $OpenApiUtil.Params({
2832
+ action: "GetLink",
2833
+ version: "2025-05-06",
2834
+ protocol: "HTTPS",
2835
+ pathname: "/",
2836
+ method: "POST",
2837
+ authType: "Anonymous",
2838
+ style: "RPC",
2839
+ reqBodyType: "formData",
2840
+ bodyType: "json"
2841
+ });
2842
+ return $dara44.cast(await this.callApi(params, req, runtime), new GetLinkResponse({}));
2843
+ }
2844
+ /**
2845
+ * 获取特定端口的转发链接
2846
+ *
2847
+ * @param request - GetLinkRequest
2848
+ * @returns GetLinkResponse
2849
+ */
2850
+ async getLink(request) {
2851
+ let runtime = new $dara44.RuntimeOptions({});
2852
+ return await this.getLinkWithOptions(request, runtime);
2853
+ }
2854
+ /**
2855
+ * 获取mcp资源信息
2856
+ *
2857
+ * @param request - GetMcpResourceRequest
2858
+ * @param runtime - runtime options for this request RuntimeOptions
2859
+ * @returns GetMcpResourceResponse
2860
+ */
2861
+ async getMcpResourceWithOptions(request, runtime) {
2862
+ request.validate();
2863
+ let body = {};
2864
+ if (!$dara44.isNull(request.authorization)) {
2865
+ body["Authorization"] = request.authorization;
2866
+ }
2867
+ if (!$dara44.isNull(request.sessionId)) {
2868
+ body["SessionId"] = request.sessionId;
2869
+ }
2870
+ let req = new $OpenApiUtil.OpenApiRequest({
2871
+ body: OpenApiUtil.parseToMap(body)
2872
+ });
2873
+ let params = new $OpenApiUtil.Params({
2874
+ action: "GetMcpResource",
2875
+ version: "2025-05-06",
2876
+ protocol: "HTTPS",
2877
+ pathname: "/",
2878
+ method: "POST",
2879
+ authType: "Anonymous",
2880
+ style: "RPC",
2881
+ reqBodyType: "formData",
2882
+ bodyType: "json"
2883
+ });
2884
+ return $dara44.cast(await this.callApi(params, req, runtime), new GetMcpResourceResponse({}));
2885
+ }
2886
+ /**
2887
+ * 获取mcp资源信息
2888
+ *
2889
+ * @param request - GetMcpResourceRequest
2890
+ * @returns GetMcpResourceResponse
2891
+ */
2892
+ async getMcpResource(request) {
2893
+ let runtime = new $dara44.RuntimeOptions({});
2894
+ return await this.getMcpResourceWithOptions(request, runtime);
2895
+ }
2896
+ /**
2897
+ * 获取上下文列表
2898
+ *
2899
+ * @param request - ListContextsRequest
2900
+ * @param runtime - runtime options for this request RuntimeOptions
2901
+ * @returns ListContextsResponse
2902
+ */
2903
+ async listContextsWithOptions(request, runtime) {
2904
+ request.validate();
2905
+ let body = {};
2906
+ if (!$dara44.isNull(request.authorization)) {
2907
+ body["Authorization"] = request.authorization;
2908
+ }
2909
+ if (!$dara44.isNull(request.maxResults)) {
2910
+ body["MaxResults"] = request.maxResults;
2911
+ }
2912
+ if (!$dara44.isNull(request.nextToken)) {
2913
+ body["NextToken"] = request.nextToken;
2914
+ }
2915
+ let req = new $OpenApiUtil.OpenApiRequest({
2916
+ body: OpenApiUtil.parseToMap(body)
2917
+ });
2918
+ let params = new $OpenApiUtil.Params({
2919
+ action: "ListContexts",
2920
+ version: "2025-05-06",
2921
+ protocol: "HTTPS",
2922
+ pathname: "/",
2923
+ method: "POST",
2924
+ authType: "Anonymous",
2925
+ style: "RPC",
2926
+ reqBodyType: "formData",
2927
+ bodyType: "json"
2928
+ });
2929
+ return $dara44.cast(await this.callApi(params, req, runtime), new ListContextsResponse({}));
2930
+ }
2931
+ /**
2932
+ * 获取上下文列表
2933
+ *
2934
+ * @param request - ListContextsRequest
2935
+ * @returns ListContextsResponse
2936
+ */
2937
+ async listContexts(request) {
2938
+ let runtime = new $dara44.RuntimeOptions({});
2939
+ return await this.listContextsWithOptions(request, runtime);
2940
+ }
2941
+ /**
2942
+ * 根据Lable查询Session列表
2943
+ *
2944
+ * @param request - ListSessionRequest
2945
+ * @param runtime - runtime options for this request RuntimeOptions
2946
+ * @returns ListSessionResponse
2947
+ */
2948
+ async listSessionWithOptions(request, runtime) {
2949
+ request.validate();
2950
+ let body = {};
2951
+ if (!$dara44.isNull(request.authorization)) {
2952
+ body["Authorization"] = request.authorization;
2953
+ }
2954
+ if (!$dara44.isNull(request.labels)) {
2955
+ body["Labels"] = request.labels;
2956
+ }
2957
+ if (!$dara44.isNull(request.maxResults)) {
2958
+ body["MaxResults"] = request.maxResults;
2959
+ }
2960
+ if (!$dara44.isNull(request.nextToken)) {
2961
+ body["NextToken"] = request.nextToken;
2962
+ }
2963
+ let req = new $OpenApiUtil.OpenApiRequest({
2964
+ body: OpenApiUtil.parseToMap(body)
2965
+ });
2966
+ let params = new $OpenApiUtil.Params({
2967
+ action: "ListSession",
2968
+ version: "2025-05-06",
2969
+ protocol: "HTTPS",
2970
+ pathname: "/",
2971
+ method: "POST",
2972
+ authType: "Anonymous",
2973
+ style: "RPC",
2974
+ reqBodyType: "formData",
2975
+ bodyType: "json"
2976
+ });
2977
+ return $dara44.cast(await this.callApi(params, req, runtime), new ListSessionResponse({}));
2978
+ }
2979
+ /**
2980
+ * 根据Lable查询Session列表
2981
+ *
2982
+ * @param request - ListSessionRequest
2983
+ * @returns ListSessionResponse
2984
+ */
2985
+ async listSession(request) {
2986
+ let runtime = new $dara44.RuntimeOptions({});
2987
+ return await this.listSessionWithOptions(request, runtime);
2988
+ }
2989
+ /**
2990
+ * 修改上下文
2991
+ *
2992
+ * @param request - ModifyContextRequest
2993
+ * @param runtime - runtime options for this request RuntimeOptions
2994
+ * @returns ModifyContextResponse
2995
+ */
2996
+ async modifyContextWithOptions(request, runtime) {
2997
+ request.validate();
2998
+ let body = {};
2999
+ if (!$dara44.isNull(request.authorization)) {
3000
+ body["Authorization"] = request.authorization;
3001
+ }
3002
+ if (!$dara44.isNull(request.id)) {
3003
+ body["Id"] = request.id;
3004
+ }
3005
+ if (!$dara44.isNull(request.name)) {
3006
+ body["Name"] = request.name;
3007
+ }
3008
+ let req = new $OpenApiUtil.OpenApiRequest({
3009
+ body: OpenApiUtil.parseToMap(body)
3010
+ });
3011
+ let params = new $OpenApiUtil.Params({
3012
+ action: "ModifyContext",
3013
+ version: "2025-05-06",
3014
+ protocol: "HTTPS",
3015
+ pathname: "/",
3016
+ method: "POST",
3017
+ authType: "Anonymous",
3018
+ style: "RPC",
3019
+ reqBodyType: "formData",
3020
+ bodyType: "json"
3021
+ });
3022
+ return $dara44.cast(await this.callApi(params, req, runtime), new ModifyContextResponse({}));
3023
+ }
3024
+ /**
3025
+ * 修改上下文
3026
+ *
3027
+ * @param request - ModifyContextRequest
3028
+ * @returns ModifyContextResponse
3029
+ */
3030
+ async modifyContext(request) {
3031
+ let runtime = new $dara44.RuntimeOptions({});
3032
+ return await this.modifyContextWithOptions(request, runtime);
3033
+ }
3034
+ /**
3035
+ * 释放 mcp session
3036
+ *
3037
+ * @param request - ReleaseMcpSessionRequest
3038
+ * @param runtime - runtime options for this request RuntimeOptions
3039
+ * @returns ReleaseMcpSessionResponse
3040
+ */
3041
+ async releaseMcpSessionWithOptions(request, runtime) {
3042
+ request.validate();
3043
+ let body = {};
3044
+ if (!$dara44.isNull(request.authorization)) {
3045
+ body["Authorization"] = request.authorization;
3046
+ }
3047
+ if (!$dara44.isNull(request.sessionId)) {
3048
+ body["SessionId"] = request.sessionId;
3049
+ }
3050
+ let req = new $OpenApiUtil.OpenApiRequest({
3051
+ body: OpenApiUtil.parseToMap(body)
3052
+ });
3053
+ let params = new $OpenApiUtil.Params({
3054
+ action: "ReleaseMcpSession",
3055
+ version: "2025-05-06",
3056
+ protocol: "HTTPS",
3057
+ pathname: "/",
3058
+ method: "POST",
3059
+ authType: "Anonymous",
3060
+ style: "RPC",
3061
+ reqBodyType: "formData",
3062
+ bodyType: "json"
3063
+ });
3064
+ return $dara44.cast(await this.callApi(params, req, runtime), new ReleaseMcpSessionResponse({}));
3065
+ }
3066
+ /**
3067
+ * 释放 mcp session
3068
+ *
3069
+ * @param request - ReleaseMcpSessionRequest
3070
+ * @returns ReleaseMcpSessionResponse
3071
+ */
3072
+ async releaseMcpSession(request) {
3073
+ let runtime = new $dara44.RuntimeOptions({});
3074
+ return await this.releaseMcpSessionWithOptions(request, runtime);
3075
+ }
3076
+ /**
3077
+ * 设置标签
3078
+ *
3079
+ * @param request - SetLabelRequest
3080
+ * @param runtime - runtime options for this request RuntimeOptions
3081
+ * @returns SetLabelResponse
3082
+ */
3083
+ async setLabelWithOptions(request, runtime) {
3084
+ request.validate();
3085
+ let body = {};
3086
+ if (!$dara44.isNull(request.authorization)) {
3087
+ body["Authorization"] = request.authorization;
3088
+ }
3089
+ if (!$dara44.isNull(request.labels)) {
3090
+ body["Labels"] = request.labels;
3091
+ }
3092
+ if (!$dara44.isNull(request.sessionId)) {
3093
+ body["SessionId"] = request.sessionId;
3094
+ }
3095
+ let req = new $OpenApiUtil.OpenApiRequest({
3096
+ body: OpenApiUtil.parseToMap(body)
3097
+ });
3098
+ let params = new $OpenApiUtil.Params({
3099
+ action: "SetLabel",
3100
+ version: "2025-05-06",
3101
+ protocol: "HTTPS",
3102
+ pathname: "/",
3103
+ method: "POST",
3104
+ authType: "Anonymous",
3105
+ style: "RPC",
3106
+ reqBodyType: "formData",
3107
+ bodyType: "json"
3108
+ });
3109
+ return $dara44.cast(await this.callApi(params, req, runtime), new SetLabelResponse({}));
3110
+ }
3111
+ /**
3112
+ * 设置标签
3113
+ *
3114
+ * @param request - SetLabelRequest
3115
+ * @returns SetLabelResponse
3116
+ */
3117
+ async setLabel(request) {
3118
+ let runtime = new $dara44.RuntimeOptions({});
3119
+ return await this.setLabelWithOptions(request, runtime);
3120
+ }
3121
+ };
3122
+ __name(_Client, "Client");
3123
+ var Client = _Client;
3124
+
3125
+ // src/oss/oss.ts
3126
+ var _Oss = class _Oss {
3127
+ /**
3128
+ * Initialize an Oss object.
3129
+ *
3130
+ * @param session - The Session instance that this Oss belongs to.
3131
+ */
3132
+ constructor(session) {
3133
+ this.session = session;
3134
+ }
3135
+ /**
3136
+ * Helper method to call MCP tools and handle common response processing
3137
+ *
3138
+ * @param toolName - Name of the MCP tool to call
3139
+ * @param args - Arguments to pass to the tool
3140
+ * @param defaultErrorMsg - Default error message if specific error details are not available
3141
+ * @returns A CallMcpToolResult with the response data
3142
+ * @throws APIError if the call fails
3143
+ */
3144
+ async callMcpTool(toolName, args, defaultErrorMsg) {
3145
+ try {
3146
+ const callToolRequest = new CallMcpToolRequest({
3147
+ authorization: `Bearer ${this.session.getAPIKey()}`,
3148
+ sessionId: this.session.getSessionId(),
3149
+ name: toolName,
3150
+ args: JSON.stringify(args)
3151
+ });
3152
+ log(`API Call: CallMcpTool - ${toolName}`);
3153
+ log(`Request: SessionId=${this.session.getSessionId()}, Args=${JSON.stringify(args)}`);
3154
+ const response = await this.session.getClient().callMcpTool(callToolRequest);
3155
+ log(`Response from CallMcpTool - ${toolName}:`, response.body);
3156
+ if (!response.body?.data) {
3157
+ throw new Error("Invalid response data format");
3158
+ }
3159
+ const data = response.body.data;
3160
+ const result = {
3161
+ data,
3162
+ statusCode: response.statusCode || 0,
3163
+ isError: false
3164
+ };
3165
+ if (data.isError === true) {
3166
+ result.isError = true;
3167
+ const contentArray = data.content;
3168
+ if (contentArray && contentArray.length > 0) {
3169
+ result.content = contentArray;
3170
+ if (contentArray[0]?.text) {
3171
+ result.errorMsg = contentArray[0].text;
3172
+ throw new Error(contentArray[0].text);
3173
+ }
3174
+ }
3175
+ throw new Error(defaultErrorMsg);
3176
+ }
3177
+ if (Array.isArray(data.content)) {
3178
+ result.content = data.content;
3179
+ if (result.content.length > 0) {
3180
+ const textParts = [];
3181
+ for (const item of result.content) {
3182
+ if (item && typeof item === "object" && item.text && typeof item.text === "string") {
3183
+ textParts.push(item.text);
3184
+ }
3185
+ }
3186
+ result.textContent = textParts.join("\n");
3187
+ }
3188
+ }
3189
+ return result;
3190
+ } catch (error) {
3191
+ logError(`Error calling CallMcpTool - ${toolName}:`, error);
3192
+ throw new APIError(`Failed to call ${toolName}: ${error}`);
3193
+ }
3194
+ }
3195
+ /**
3196
+ * Initialize OSS environment variables with the specified credentials.
3197
+ *
3198
+ * @param accessKeyId - The Access Key ID for OSS authentication.
3199
+ * @param accessKeySecret - The Access Key Secret for OSS authentication.
3200
+ * @param securityToken - The security token for OSS authentication.
3201
+ * @param endpoint - The OSS service endpoint. If not specified, the default is used.
3202
+ * @param region - The OSS region. If not specified, the default is used.
3203
+ * @returns The extracted text content from the API response
3204
+ */
3205
+ async envInit(accessKeyId, accessKeySecret, securityToken, endpoint, region) {
3206
+ const args = {
3207
+ access_key_id: accessKeyId,
3208
+ access_key_secret: accessKeySecret,
3209
+ security_token: securityToken
3210
+ };
3211
+ if (endpoint) {
3212
+ args.endpoint = endpoint;
3213
+ }
3214
+ if (region) {
3215
+ args.region = region;
3216
+ }
3217
+ const result = await this.callMcpTool("oss_env_init", args, "error initializing OSS environment");
3218
+ return result.textContent || "";
3219
+ }
3220
+ /**
3221
+ * Create an OSS client with the provided credentials.
3222
+ *
3223
+ * @param accessKeyId - The Access Key ID for OSS authentication.
3224
+ * @param accessKeySecret - The Access Key Secret for OSS authentication.
3225
+ * @param endpoint - The OSS service endpoint. If not specified, the default is used.
3226
+ * @param region - The OSS region. If not specified, the default is used.
3227
+ * @returns The extracted text content from the API response
3228
+ */
3229
+ async createClient(accessKeyId, accessKeySecret, endpoint, region) {
3230
+ const args = {
3231
+ access_key_id: accessKeyId,
3232
+ access_key_secret: accessKeySecret
3233
+ };
3234
+ if (endpoint) {
3235
+ args.endpoint = endpoint;
3236
+ }
3237
+ if (region) {
3238
+ args.region = region;
3239
+ }
3240
+ const result = await this.callMcpTool("oss_client_create", args, "error creating OSS client");
3241
+ return result.textContent || "";
3242
+ }
3243
+ /**
3244
+ * Upload a local file or directory to OSS.
3245
+ *
3246
+ * @param bucket - OSS bucket name.
3247
+ * @param object - Object key in OSS.
3248
+ * @param path - Local file or directory path to upload.
3249
+ * @returns The extracted text content from the API response
3250
+ */
3251
+ async upload(bucket, object, path3) {
3252
+ const args = {
3253
+ bucket,
3254
+ object,
3255
+ path: path3
3256
+ };
3257
+ const result = await this.callMcpTool("oss_upload", args, "error uploading to OSS");
3258
+ return result.textContent || "";
3259
+ }
3260
+ /**
3261
+ * Upload a local file or directory to OSS using a pre-signed URL.
3262
+ *
3263
+ * @param url - Pre-signed URL for anonymous upload.
3264
+ * @param path - Local file or directory path to upload.
3265
+ * @returns The extracted text content from the API response
3266
+ */
3267
+ async uploadAnonymous(url, path3) {
3268
+ const args = {
3269
+ url,
3270
+ path: path3
3271
+ };
3272
+ const result = await this.callMcpTool("oss_upload_annon", args, "error uploading anonymously");
3273
+ return result.textContent || "";
3274
+ }
3275
+ /**
3276
+ * Download an object from OSS to a local file or directory.
3277
+ *
3278
+ * @param bucket - OSS bucket name.
3279
+ * @param object - Object key in OSS.
3280
+ * @param path - Local file or directory path to save the downloaded content.
3281
+ * @returns The extracted text content from the API response
3282
+ */
3283
+ async download(bucket, object, path3) {
3284
+ const args = {
3285
+ bucket,
3286
+ object,
3287
+ path: path3
3288
+ };
3289
+ const result = await this.callMcpTool("oss_download", args, "error downloading from OSS");
3290
+ return result.textContent || "";
3291
+ }
3292
+ /**
3293
+ * Download an object from OSS using a pre-signed URL.
3294
+ *
3295
+ * @param url - Pre-signed URL for anonymous download.
3296
+ * @param path - Local file or directory path to save the downloaded content.
3297
+ * @returns The extracted text content from the API response
3298
+ */
3299
+ async downloadAnonymous(url, path3) {
3300
+ const args = {
3301
+ url,
3302
+ path: path3
3303
+ };
3304
+ const result = await this.callMcpTool("oss_download_annon", args, "error downloading anonymously");
3305
+ return result.textContent || "";
3306
+ }
3307
+ };
3308
+ __name(_Oss, "Oss");
3309
+ var Oss = _Oss;
3310
+
3311
+ // src/application/application.ts
3312
+ init_esm_shims();
3313
+ var _Application = class _Application {
3314
+ /**
3315
+ * Creates a new Application instance.
3316
+ * @param session The session object that provides access to the AgentBay API.
3317
+ */
3318
+ constructor(session) {
3319
+ this.session = session;
3320
+ }
3321
+ /**
3322
+ * Helper method to call MCP tools and handle common response processing
3323
+ *
3324
+ * @param toolName - Name of the MCP tool to call
3325
+ * @param args - Arguments to pass to the tool
3326
+ * @param defaultErrorMsg - Default error message if specific error details are not available
3327
+ * @returns A CallMcpToolResult with the response data
3328
+ * @throws APIError if the call fails
3329
+ */
3330
+ async callMcpTool(toolName, args, defaultErrorMsg) {
3331
+ try {
3332
+ const argsJSON = JSON.stringify(args);
3333
+ const request = new CallMcpToolRequest({
3334
+ authorization: `Bearer ${this.session.getAPIKey()}`,
3335
+ sessionId: this.session.getSessionId(),
3336
+ name: toolName,
3337
+ args: argsJSON
3338
+ });
3339
+ log(`API Call: CallMcpTool - ${toolName}`);
3340
+ log(`Request: SessionId=${request.sessionId}, Args=${request.args}`);
3341
+ const client = this.session.getClient();
3342
+ const response = await client.callMcpTool(request);
3343
+ if (response && response.body) {
3344
+ log(`Response from CallMcpTool - ${toolName}:`, response.body);
3345
+ }
3346
+ if (!response.body?.data) {
3347
+ throw new Error("Invalid response data format");
3348
+ }
3349
+ const data = response.body.data;
3350
+ const result = {
3351
+ data,
3352
+ statusCode: response.statusCode || 0,
3353
+ isError: false
3354
+ };
3355
+ if (data.isError === true) {
3356
+ result.isError = true;
3357
+ const contentArray = data.content;
3358
+ if (contentArray && contentArray.length > 0) {
3359
+ result.content = contentArray;
3360
+ if (contentArray[0]?.text) {
3361
+ result.errorMsg = contentArray[0].text;
3362
+ throw new Error(contentArray[0].text);
3363
+ }
3364
+ }
3365
+ throw new Error(defaultErrorMsg);
3366
+ }
3367
+ if (Array.isArray(data.content)) {
3368
+ result.content = data.content;
3369
+ if (result.content.length > 0) {
3370
+ const textParts = [];
3371
+ for (const item of result.content) {
3372
+ if (item && typeof item === "object" && item.text && typeof item.text === "string") {
3373
+ textParts.push(item.text);
3374
+ }
3375
+ }
3376
+ result.textContent = textParts.join("\n");
3377
+ }
3378
+ }
3379
+ return result;
3380
+ } catch (error) {
3381
+ logError(`Error calling CallMcpTool - ${toolName}:`, error);
3382
+ throw new APIError(`Failed to call ${toolName}: ${error}`);
3383
+ }
3384
+ }
3385
+ /**
3386
+ * Helper method to parse JSON string into objects
3387
+ */
3388
+ parseJSON(jsonString) {
3389
+ try {
3390
+ return JSON.parse(jsonString);
3391
+ } catch (error) {
3392
+ throw new Error(`Failed to parse JSON: ${error}`);
3393
+ }
3394
+ }
3395
+ /**
3396
+ * Retrieves a list of installed applications.
3397
+ * @param startMenu Whether to include applications from the start menu. Defaults to true.
3398
+ * @param desktop Whether to include applications from the desktop. Defaults to true.
3399
+ * @param ignoreSystemApps Whether to ignore system applications. Defaults to true.
3400
+ * @returns Array of InstalledApp objects
3401
+ * @throws Error if the operation fails.
3402
+ */
3403
+ async getInstalledApps(startMenu = true, desktop = true, ignoreSystemApps = true) {
3404
+ const args = {
3405
+ start_menu: startMenu,
3406
+ desktop,
3407
+ ignore_system_apps: ignoreSystemApps
3408
+ };
3409
+ const result = await this.callMcpTool("get_installed_apps", args, "Failed to get installed apps");
3410
+ if (!result.textContent) {
3411
+ return [];
3412
+ }
3413
+ return this.parseJSON(result.textContent);
3414
+ }
3415
+ /**
3416
+ * Starts an application with the given command and optional working directory.
3417
+ * @param startCmd The command to start the application.
3418
+ * @param workDirectory The working directory for the application. Defaults to an empty string.
3419
+ * @returns Array of Process objects representing the started processes
3420
+ * @throws Error if the operation fails.
3421
+ */
3422
+ async startApp(startCmd, workDirectory = "") {
3423
+ const args = {
3424
+ start_cmd: startCmd
3425
+ };
3426
+ if (workDirectory) {
3427
+ args.work_directory = workDirectory;
3428
+ }
3429
+ const result = await this.callMcpTool("start_app", args, "Failed to start app");
3430
+ if (!result.textContent) {
3431
+ return [];
3432
+ }
3433
+ return this.parseJSON(result.textContent);
3434
+ }
3435
+ /**
3436
+ * Stops an application by process name.
3437
+ * @param pname The name of the process to stop.
3438
+ * @throws Error if the operation fails.
3439
+ */
3440
+ async stopAppByPName(pname) {
3441
+ const args = {
3442
+ pname
3443
+ };
3444
+ await this.callMcpTool("stop_app_by_pname", args, "Failed to stop app by pname");
3445
+ }
3446
+ /**
3447
+ * Stops an application by process ID.
3448
+ * @param pid The ID of the process to stop.
3449
+ * @throws Error if the operation fails.
3450
+ */
3451
+ async stopAppByPID(pid) {
3452
+ const args = {
3453
+ pid
3454
+ };
3455
+ await this.callMcpTool("stop_app_by_pid", args, "Failed to stop app by pid");
3456
+ }
3457
+ /**
3458
+ * Stops an application by stop command.
3459
+ * @param stopCmd The command to stop the application.
3460
+ * @throws Error if the operation fails.
3461
+ */
3462
+ async stopAppByCmd(stopCmd) {
3463
+ const args = {
3464
+ stop_cmd: stopCmd
3465
+ };
3466
+ await this.callMcpTool("stop_app_by_cmd", args, "Failed to stop app by command");
3467
+ }
3468
+ /**
3469
+ * Lists all currently visible applications.
3470
+ * @returns Array of Process objects representing the visible processes
3471
+ * @throws Error if the operation fails.
3472
+ */
3473
+ async listVisibleApps() {
3474
+ const args = {};
3475
+ const result = await this.callMcpTool("list_visible_apps", args, "Failed to list visible apps");
3476
+ if (!result.textContent) {
3477
+ return [];
3478
+ }
3479
+ return this.parseJSON(result.textContent);
3480
+ }
3481
+ };
3482
+ __name(_Application, "Application");
3483
+ var Application = _Application;
3484
+
3485
+ // src/window/window.ts
3486
+ init_esm_shims();
3487
+ var _WindowManager = class _WindowManager {
3488
+ /**
3489
+ * Creates a new WindowManager instance.
3490
+ * @param session The session object that provides access to the AgentBay API.
3491
+ */
3492
+ constructor(session) {
3493
+ this.session = session;
3494
+ }
3495
+ /**
3496
+ * Helper method to call MCP tools and handle common response processing
3497
+ *
3498
+ * @param toolName - Name of the MCP tool to call
3499
+ * @param args - Arguments to pass to the tool
3500
+ * @param defaultErrorMsg - Default error message if specific error details are not available
3501
+ * @returns A CallMcpToolResult with the response data
3502
+ * @throws APIError if the call fails
3503
+ */
3504
+ async callMcpTool(toolName, args, defaultErrorMsg) {
3505
+ try {
3506
+ const argsJSON = JSON.stringify(args);
3507
+ const request = new CallMcpToolRequest({
3508
+ authorization: `Bearer ${this.session.getAPIKey()}`,
3509
+ sessionId: this.session.getSessionId(),
3510
+ name: toolName,
3511
+ args: argsJSON
3512
+ });
3513
+ log(`API Call: CallMcpTool - ${toolName}`);
3514
+ log(`Request: SessionId=${request.sessionId}, Args=${request.args}`);
3515
+ const response = await this.session.getClient().callMcpTool(request);
3516
+ if (response && response.body) {
3517
+ log(`Response from CallMcpTool - ${toolName}:`, response.body);
3518
+ }
3519
+ if (!response.body?.data) {
3520
+ throw new Error("Invalid response data format");
3521
+ }
3522
+ const data = response.body.data;
3523
+ const result = {
3524
+ data,
3525
+ statusCode: response.statusCode || 0,
3526
+ isError: false
3527
+ };
3528
+ if (data.isError === true) {
3529
+ result.isError = true;
3530
+ const contentArray = data.content;
3531
+ if (contentArray && contentArray.length > 0) {
3532
+ result.content = contentArray;
3533
+ if (contentArray[0]?.text) {
3534
+ result.errorMsg = contentArray[0].text;
3535
+ throw new Error(contentArray[0].text);
3536
+ }
3537
+ }
3538
+ throw new Error(defaultErrorMsg);
3539
+ }
3540
+ if (Array.isArray(data.content)) {
3541
+ result.content = data.content;
3542
+ if (result.content.length > 0) {
3543
+ const textParts = [];
3544
+ for (const item of result.content) {
3545
+ if (item && typeof item === "object" && item.text && typeof item.text === "string") {
3546
+ textParts.push(item.text);
3547
+ }
3548
+ }
3549
+ result.textContent = textParts.join("\n");
3550
+ }
3551
+ }
3552
+ return result;
3553
+ } catch (error) {
3554
+ logError(`Error calling CallMcpTool - ${toolName}:`, error);
3555
+ throw new APIError(`Failed to call ${toolName}: ${error}`);
3556
+ }
3557
+ }
3558
+ /**
3559
+ * Helper method to parse JSON string into Window objects
3560
+ * @param jsonStr - JSON string to parse
3561
+ * @returns Array of Window objects or single Window object
3562
+ */
3563
+ parseWindowsFromJSON(jsonStr) {
3564
+ try {
3565
+ const parsed = JSON.parse(jsonStr);
3566
+ return Array.isArray(parsed) ? parsed : [parsed];
3567
+ } catch (error) {
3568
+ throw new Error(`Failed to parse window data: ${error}`);
3569
+ }
3570
+ }
3571
+ /**
3572
+ * Lists all root windows in the system.
3573
+ * @returns Array of Window objects
3574
+ * @throws Error if the operation fails.
3575
+ */
3576
+ async listRootWindows() {
3577
+ const args = {};
3578
+ const result = await this.callMcpTool("list_root_windows", args, "Failed to list root windows");
3579
+ if (!result.textContent) {
3580
+ return [];
3581
+ }
3582
+ return this.parseWindowsFromJSON(result.textContent);
3583
+ }
3584
+ /**
3585
+ * Gets the currently active window.
3586
+ * @returns Window object or null if no active window
3587
+ * @throws Error if the operation fails.
3588
+ */
3589
+ async getActiveWindow() {
3590
+ const args = {};
3591
+ const result = await this.callMcpTool("get_active_window", args, "Failed to get active window");
3592
+ if (!result.textContent) {
3593
+ return null;
3594
+ }
3595
+ const windows = this.parseWindowsFromJSON(result.textContent);
3596
+ return windows.length > 0 ? windows[0] : null;
3597
+ }
3598
+ /**
3599
+ * Activates a window by ID.
3600
+ * @param windowId The ID of the window to activate.
3601
+ * @throws Error if the operation fails.
3602
+ */
3603
+ async activateWindow(windowId) {
3604
+ const args = {
3605
+ window_id: windowId
3606
+ };
3607
+ await this.callMcpTool("activate_window", args, "Failed to activate window");
3608
+ }
3609
+ /**
3610
+ * Maximizes a window by ID.
3611
+ * @param windowId The ID of the window to maximize.
3612
+ * @throws Error if the operation fails.
3613
+ */
3614
+ async maximizeWindow(windowId) {
3615
+ const args = {
3616
+ window_id: windowId
3617
+ };
3618
+ await this.callMcpTool("maximize_window", args, "Failed to maximize window");
3619
+ }
3620
+ /**
3621
+ * Minimizes a window by ID.
3622
+ * @param windowId The ID of the window to minimize.
3623
+ * @throws Error if the operation fails.
3624
+ */
3625
+ async minimizeWindow(windowId) {
3626
+ const args = {
3627
+ window_id: windowId
3628
+ };
3629
+ await this.callMcpTool("minimize_window", args, "Failed to minimize window");
3630
+ }
3631
+ /**
3632
+ * Restores a window by ID.
3633
+ * @param windowId The ID of the window to restore.
3634
+ * @throws Error if the operation fails.
3635
+ */
3636
+ async restoreWindow(windowId) {
3637
+ const args = {
3638
+ window_id: windowId
3639
+ };
3640
+ await this.callMcpTool("restore_window", args, "Failed to restore window");
3641
+ }
3642
+ /**
3643
+ * Closes a window by ID.
3644
+ * @param windowId The ID of the window to close.
3645
+ * @throws Error if the operation fails.
3646
+ */
3647
+ async closeWindow(windowId) {
3648
+ const args = {
3649
+ window_id: windowId
3650
+ };
3651
+ await this.callMcpTool("close_window", args, "Failed to close window");
3652
+ }
3653
+ /**
3654
+ * Sets a window to fullscreen by ID.
3655
+ * @param windowId The ID of the window to set to fullscreen.
3656
+ * @throws Error if the operation fails.
3657
+ */
3658
+ async fullscreenWindow(windowId) {
3659
+ const args = {
3660
+ window_id: windowId
3661
+ };
3662
+ await this.callMcpTool("fullscreen_window", args, "Failed to set window to fullscreen");
3663
+ }
3664
+ /**
3665
+ * Resizes a window by ID.
3666
+ * @param windowId The ID of the window to resize.
3667
+ * @param width The new width of the window.
3668
+ * @param height The new height of the window.
3669
+ * @throws Error if the operation fails.
3670
+ */
3671
+ async resizeWindow(windowId, width, height) {
3672
+ const args = {
3673
+ window_id: windowId,
3674
+ width,
3675
+ height
3676
+ };
3677
+ await this.callMcpTool("resize_window", args, "Failed to resize window");
3678
+ }
3679
+ /**
3680
+ * Enables or disables focus mode.
3681
+ * @param on Whether to enable focus mode.
3682
+ * @throws Error if the operation fails.
3683
+ */
3684
+ async focusMode(on) {
3685
+ const args = {
3686
+ on
3687
+ };
3688
+ await this.callMcpTool("focus_mode", args, "Failed to set focus mode");
3689
+ }
3690
+ };
3691
+ __name(_WindowManager, "WindowManager");
3692
+ var WindowManager = _WindowManager;
3693
+
3694
+ // src/ui/ui.ts
3695
+ init_esm_shims();
3696
+ var KeyCode = {
3697
+ HOME: 3,
3698
+ BACK: 4,
3699
+ VOLUME_UP: 24,
3700
+ VOLUME_DOWN: 25,
3701
+ POWER: 26,
3702
+ MENU: 82
3703
+ };
3704
+ var _UI = class _UI {
3705
+ /**
3706
+ * Initialize a UI object.
3707
+ *
3708
+ * @param session - The Session instance that this UI belongs to.
3709
+ */
3710
+ constructor(session) {
3711
+ this.session = session;
3712
+ }
3713
+ /**
3714
+ * Helper method to call MCP tools and handle common response processing
3715
+ *
3716
+ * @param toolName - Name of the MCP tool to call
3717
+ * @param args - Arguments to pass to the tool
3718
+ * @param defaultErrorMsg - Default error message if specific error details are not available
3719
+ * @returns A CallMcpToolResult with the response data
3720
+ * @throws APIError if the call fails
3721
+ */
3722
+ async callMcpTool(toolName, args, defaultErrorMsg) {
3723
+ try {
3724
+ const argsJSON = JSON.stringify(args);
3725
+ const callToolRequest = new CallMcpToolRequest({
3726
+ authorization: `Bearer ${this.session.getAPIKey()}`,
3727
+ sessionId: this.session.getSessionId(),
3728
+ name: toolName,
3729
+ args: argsJSON
3730
+ });
3731
+ log(`API Call: CallMcpTool - ${toolName}`);
3732
+ log(`Request: SessionId=${this.session.getSessionId()}, Args=${argsJSON}`);
3733
+ const response = await this.session.getClient().callMcpTool(callToolRequest);
3734
+ log(`Response from CallMcpTool - ${toolName}:`, response.body);
3735
+ if (!response.body?.data) {
3736
+ throw new Error("Invalid response data format");
3737
+ }
3738
+ const data = response.body.data;
3739
+ const result = {
3740
+ data,
3741
+ statusCode: response.statusCode || 0,
3742
+ isError: false
3743
+ };
3744
+ if (data.isError === true) {
3745
+ result.isError = true;
3746
+ const contentArray = data.content;
3747
+ if (contentArray && contentArray.length > 0) {
3748
+ result.content = contentArray;
3749
+ if (contentArray[0]?.text) {
3750
+ result.errorMsg = contentArray[0].text;
3751
+ throw new Error(contentArray[0].text);
3752
+ }
3753
+ }
3754
+ throw new Error(defaultErrorMsg);
3755
+ }
3756
+ if (Array.isArray(data.content)) {
3757
+ result.content = data.content;
3758
+ if (result.content.length > 0) {
3759
+ const textParts = [];
3760
+ for (const item of result.content) {
3761
+ if (item && typeof item === "object" && item.text && typeof item.text === "string") {
3762
+ textParts.push(item.text);
3763
+ }
3764
+ }
3765
+ result.textContent = textParts.join("\n");
3766
+ }
3767
+ }
3768
+ return result;
3769
+ } catch (error) {
3770
+ logError(`Error calling CallMcpTool - ${toolName}:`, error);
3771
+ throw new APIError(`Failed to call ${toolName}: ${error}`);
3772
+ }
3773
+ }
3774
+ /**
3775
+ * Retrieves all clickable UI elements within the specified timeout.
3776
+ *
3777
+ * @param timeoutMs - The timeout in milliseconds. Default is 2000ms.
3778
+ * @returns An array of UIElement objects
3779
+ * @throws Error if the operation fails.
3780
+ */
3781
+ async getClickableUIElements(timeoutMs = 2e3) {
3782
+ const args = {
3783
+ timeout_ms: timeoutMs
3784
+ };
3785
+ const result = await this.callMcpTool("get_clickable_ui_elements", args, "Failed to get clickable UI elements");
3786
+ if (!result.textContent) {
3787
+ return [];
3788
+ }
3789
+ try {
3790
+ return JSON.parse(result.textContent);
3791
+ } catch (error) {
3792
+ logError("Failed to parse clickable UI elements:", error);
3793
+ throw new APIError(`Failed to parse clickable UI elements: ${error}`);
3794
+ }
3795
+ }
3796
+ /**
3797
+ * Retrieves all UI elements within the specified timeout.
3798
+ *
3799
+ * @param timeoutMs - The timeout in milliseconds. Default is 2000ms.
3800
+ * @returns An array of UIElement objects
3801
+ * @throws Error if the operation fails.
3802
+ */
3803
+ async getAllUIElements(timeoutMs = 2e3) {
3804
+ const args = {
3805
+ timeout_ms: timeoutMs
3806
+ };
3807
+ const result = await this.callMcpTool("get_all_ui_elements", args, "Failed to get all UI elements");
3808
+ if (!result.textContent) {
3809
+ return [];
3810
+ }
3811
+ try {
3812
+ return JSON.parse(result.textContent);
3813
+ } catch (error) {
3814
+ logError("Failed to parse all UI elements:", error);
3815
+ throw new APIError(`Failed to parse all UI elements: ${error}`);
3816
+ }
3817
+ }
3818
+ /**
3819
+ * Sends a key press event.
3820
+ *
3821
+ * @param key - The key code to send.
3822
+ * @returns The extracted text content from the API response
3823
+ * @throws Error if the operation fails.
3824
+ */
3825
+ async sendKey(key) {
3826
+ const args = {
3827
+ key
3828
+ };
3829
+ const result = await this.callMcpTool("send_key", args, "Failed to send key");
3830
+ return result.textContent || "";
3831
+ }
3832
+ /**
3833
+ * Inputs text into the active field.
3834
+ *
3835
+ * @param text - The text to input.
3836
+ * @returns The extracted text content from the API response
3837
+ * @throws Error if the operation fails.
3838
+ */
3839
+ async inputText(text) {
3840
+ const args = {
3841
+ text
3842
+ };
3843
+ const result = await this.callMcpTool("input_text", args, "Failed to input text");
3844
+ return result.textContent || "";
3845
+ }
3846
+ /**
3847
+ * Performs a swipe gesture on the screen.
3848
+ *
3849
+ * @param startX - The starting X coordinate.
3850
+ * @param startY - The starting Y coordinate.
3851
+ * @param endX - The ending X coordinate.
3852
+ * @param endY - The ending Y coordinate.
3853
+ * @param durationMs - The duration of the swipe in milliseconds. Default is 300ms.
3854
+ * @returns The extracted text content from the API response
3855
+ * @throws Error if the operation fails.
3856
+ */
3857
+ async swipe(startX, startY, endX, endY, durationMs = 300) {
3858
+ const args = {
3859
+ start_x: startX,
3860
+ start_y: startY,
3861
+ end_x: endX,
3862
+ end_y: endY,
3863
+ duration_ms: durationMs
3864
+ };
3865
+ const result = await this.callMcpTool("swipe", args, "Failed to perform swipe");
3866
+ return result.textContent || "";
3867
+ }
3868
+ /**
3869
+ * Performs a click at the specified coordinates.
3870
+ *
3871
+ * @param x - The X coordinate.
3872
+ * @param y - The Y coordinate.
3873
+ * @param button - The mouse button to click. Default is 'left'.
3874
+ * @returns The extracted text content from the API response
3875
+ * @throws Error if the operation fails.
3876
+ */
3877
+ async click(x, y, button = "left") {
3878
+ const args = {
3879
+ x,
3880
+ y,
3881
+ button
3882
+ };
3883
+ const result = await this.callMcpTool("click", args, "Failed to perform click");
3884
+ return result.textContent || "";
3885
+ }
3886
+ /**
3887
+ * Takes a screenshot of the current screen.
3888
+ *
3889
+ * @returns The extracted text content from the API response (usually a base64-encoded image)
3890
+ * @throws Error if the operation fails.
3891
+ */
3892
+ async screenshot() {
3893
+ const args = {};
3894
+ const result = await this.callMcpTool("system_screenshot", args, "Failed to take screenshot");
3895
+ return result.textContent || "";
3896
+ }
3897
+ };
3898
+ __name(_UI, "UI");
3899
+ var UI = _UI;
3900
+
3901
+ // src/session.ts
3902
+ var _Session = class _Session {
3903
+ /**
3904
+ * Initialize a Session object.
3905
+ *
3906
+ * @param agentBay - The AgentBay instance that created this session.
3907
+ * @param sessionId - The ID of this session.
3908
+ */
3909
+ constructor(agentBay, sessionId) {
3910
+ this.resourceUrl = "";
3911
+ this.agentBay = agentBay;
3912
+ this.sessionId = sessionId;
3913
+ this.client = agentBay.getClient();
3914
+ log(`Session created with ID: ${sessionId}`);
3915
+ this.filesystem = new FileSystem(this);
3916
+ this.command = new Command(this);
3917
+ this.oss = new Oss(this);
3918
+ this.Application = new Application(this);
3919
+ this.window = new WindowManager(this);
3920
+ this.ui = new UI(this);
3921
+ }
3922
+ /**
3923
+ * Get information about this session.
3924
+ *
3925
+ * @returns Session information.
3926
+ */
3927
+ // async get_info(): Promise<Record<string, any>> {
3928
+ // // TODO: Implement the API call to get session info
3929
+ // try {
3930
+ // const response = await this.client.get(this.baseUrl);
3931
+ // return response.data;
3932
+ // } catch (error) {
3933
+ // throw new APIError(`Failed to get session info: ${error}`);
3934
+ // }
3935
+ // }
3936
+ /**
3937
+ * Delete this session.
3938
+ *
3939
+ * @returns True if the session was successfully deleted.
3940
+ */
3941
+ async delete() {
3942
+ try {
3943
+ const releaseSessionRequest = new ReleaseMcpSessionRequest({
3944
+ authorization: `Bearer ${this.getAPIKey()}`,
3945
+ sessionId: this.sessionId
3946
+ });
3947
+ console.log("API Call delete: ReleaseMcpSession", this.sessionId);
3948
+ log("API Call: ReleaseMcpSession");
3949
+ log(`Request: SessionId=${this.sessionId}`);
3950
+ const response = await this.client.releaseMcpSession(releaseSessionRequest);
3951
+ log(`Response from ReleaseMcpSession:`, response.body);
3952
+ this.agentBay.removeSession(this.sessionId);
3953
+ return true;
3954
+ } catch (error) {
3955
+ logError("Error calling ReleaseMcpSession:", error);
3956
+ throw new APIError(`Failed to delete session: ${error}`);
3957
+ }
3958
+ }
3959
+ /**
3960
+ * Sets the labels for this session.
3961
+ *
3962
+ * @param labels - The labels to set for the session.
3963
+ * @throws APIError if the operation fails.
3964
+ */
3965
+ async setLabels(labels) {
3966
+ try {
3967
+ const labelsJSON = JSON.stringify(labels);
3968
+ const request = new SetLabelRequest({
3969
+ authorization: `Bearer ${this.getAPIKey()}`,
3970
+ sessionId: this.sessionId,
3971
+ labels: labelsJSON
3972
+ });
3973
+ log("API Call: SetLabel");
3974
+ log(`Request: SessionId=${this.sessionId}, Labels=${labelsJSON}`);
3975
+ const response = await this.client.setLabel(request);
3976
+ log(`Response from SetLabel:`, response.body);
3977
+ } catch (error) {
3978
+ logError("Error calling SetLabel:", error);
3979
+ throw new APIError(`Failed to set labels for session: ${error}`);
3980
+ }
3981
+ }
3982
+ /**
3983
+ * Gets the labels for this session.
3984
+ *
3985
+ * @returns The labels for the session.
3986
+ * @throws APIError if the operation fails.
3987
+ */
3988
+ async getLabels() {
3989
+ try {
3990
+ const request = new GetLabelRequest({
3991
+ authorization: `Bearer ${this.getAPIKey()}`,
3992
+ sessionId: this.sessionId
3993
+ });
3994
+ log("API Call: GetLabel");
3995
+ log(`Request: SessionId=${this.sessionId}`);
3996
+ const response = await this.client.getLabel(request);
3997
+ console.log(`Response from GetLabel: ${JSON.stringify(response)}`);
3998
+ log(`Response from GetLabel:`, response.body);
3999
+ const labelsJSON = response.body?.data?.labels;
4000
+ if (labelsJSON) {
4001
+ return JSON.parse(labelsJSON);
4002
+ }
4003
+ return {};
4004
+ } catch (error) {
4005
+ logError("Error calling GetLabel:", error);
4006
+ throw new APIError(`Failed to get labels for session: ${error}`);
4007
+ }
4008
+ }
4009
+ /**
4010
+ * Get the API key.
4011
+ *
4012
+ * @returns The API key.
4013
+ */
4014
+ getAPIKey() {
4015
+ return this.agentBay.getAPIKey();
4016
+ }
4017
+ /**
4018
+ * Get the client.
4019
+ *
4020
+ * @returns The client.
4021
+ */
4022
+ getClient() {
4023
+ return this.client;
4024
+ }
4025
+ /**
4026
+ * Get the session ID.
4027
+ *
4028
+ * @returns The session ID.
4029
+ */
4030
+ getSessionId() {
4031
+ return this.sessionId;
4032
+ }
4033
+ /**
4034
+ * Gets information about this session.
4035
+ *
4036
+ * @returns Information about the session.
4037
+ * @throws APIError if the operation fails.
4038
+ */
4039
+ async info() {
4040
+ try {
4041
+ const request = new GetMcpResourceRequest({
4042
+ authorization: `Bearer ${this.getAPIKey()}`,
4043
+ sessionId: this.sessionId
4044
+ });
4045
+ log("API Call: GetMcpResource");
4046
+ log(`Request: SessionId=${this.sessionId}`);
4047
+ const response = await this.client.getMcpResource(request);
4048
+ log(`Response from GetMcpResource:`, response.body);
4049
+ const sessionInfo = {
4050
+ sessionId: response.body?.data?.sessionId || "",
4051
+ resourceUrl: response.body?.data?.resourceUrl || ""
4052
+ };
4053
+ if (response.body?.data?.resourceUrl) {
4054
+ this.resourceUrl = response.body.data.resourceUrl;
4055
+ }
4056
+ if (response.body?.data?.desktopInfo) {
4057
+ const desktopInfo = response.body.data.desktopInfo;
4058
+ sessionInfo.appId = desktopInfo.appId;
4059
+ sessionInfo.authCode = desktopInfo.authCode;
4060
+ sessionInfo.connectionProperties = desktopInfo.connectionProperties;
4061
+ sessionInfo.resourceId = desktopInfo.resourceId;
4062
+ sessionInfo.resourceType = desktopInfo.resourceType;
4063
+ }
4064
+ return sessionInfo;
4065
+ } catch (error) {
4066
+ logError("Error calling GetMcpResource:", error);
4067
+ throw new APIError(`Failed to get session info for session ${this.sessionId}: ${error}`);
4068
+ }
4069
+ }
4070
+ /**
4071
+ * Gets the link for this session.
4072
+ *
4073
+ * @returns The link for the session.
4074
+ * @throws APIError if the operation fails.
4075
+ */
4076
+ async getLink() {
4077
+ try {
4078
+ const request = new GetLinkRequest({
4079
+ authorization: `Bearer ${this.getAPIKey()}`,
4080
+ sessionId: this.sessionId
4081
+ });
4082
+ log("API Call: GetLink");
4083
+ log(`Request: SessionId=${this.sessionId}`);
4084
+ const response = await this.client.getLink(request);
4085
+ log(`Response from GetLink:`, response.body);
4086
+ if (response.body?.data) {
4087
+ return response.body.data;
4088
+ }
4089
+ return "";
4090
+ } catch (error) {
4091
+ logError("Error calling GetLink:", error);
4092
+ throw new APIError(`Failed to get link for session ${this.sessionId}: ${error}`);
4093
+ }
4094
+ }
4095
+ };
4096
+ __name(_Session, "Session");
4097
+ var Session = _Session;
4098
+
4099
+ // src/context.ts
4100
+ init_esm_shims();
4101
+ var _Context = class _Context {
4102
+ /**
4103
+ * Initialize a Context object.
4104
+ *
4105
+ * @param id - The unique identifier of the context.
4106
+ * @param name - The name of the context.
4107
+ * @param state - The current state of the context.
4108
+ * @param createdAt - Date and time when the Context was created.
4109
+ * @param lastUsedAt - Date and time when the Context was last used.
4110
+ * @param osType - The operating system type this context is bound to.
4111
+ */
4112
+ constructor(id, name, state = "available", createdAt, lastUsedAt, osType) {
4113
+ this.id = id;
4114
+ this.name = name;
4115
+ this.state = state;
4116
+ this.createdAt = createdAt;
4117
+ this.lastUsedAt = lastUsedAt;
4118
+ this.osType = osType;
4119
+ }
4120
+ };
4121
+ __name(_Context, "Context");
4122
+ var Context = _Context;
4123
+ var _ContextService = class _ContextService {
4124
+ /**
4125
+ * Initialize the ContextService.
4126
+ *
4127
+ * @param agentBay - The AgentBay instance.
4128
+ */
4129
+ constructor(agentBay) {
4130
+ this.agentBay = agentBay;
4131
+ }
4132
+ /**
4133
+ * Lists all available contexts.
4134
+ *
4135
+ * @returns A list of Context objects.
4136
+ */
4137
+ async list() {
4138
+ try {
4139
+ const request = new ListContextsRequest({
4140
+ authorization: `Bearer ${this.agentBay.getAPIKey()}`
4141
+ });
4142
+ log("API Call: ListContexts");
4143
+ log("Request: No parameters");
4144
+ const response = await this.agentBay.getClient().listContexts(request);
4145
+ log(`Response from ListContexts:`, response.body);
4146
+ const contexts = [];
4147
+ if (response.body?.data) {
4148
+ for (const contextData of response.body.data) {
4149
+ contexts.push(new Context(
4150
+ contextData.id || "",
4151
+ contextData.name || "",
4152
+ contextData.state || "available",
4153
+ contextData.createTime,
4154
+ contextData.lastUsedTime,
4155
+ contextData.osType
4156
+ ));
4157
+ }
4158
+ }
4159
+ return contexts;
4160
+ } catch (error) {
4161
+ logError("Error calling ListContexts:", error);
4162
+ throw new APIError(`Failed to list contexts: ${error}`);
4163
+ }
4164
+ }
4165
+ /**
4166
+ * Gets a context by name. Optionally creates it if it doesn't exist.
4167
+ *
4168
+ * @param name - The name of the context to get.
4169
+ * @param create - Whether to create the context if it doesn't exist.
4170
+ * @returns The Context object if found or created, null if not found and create is false.
4171
+ */
4172
+ async get(name, create = false) {
4173
+ try {
4174
+ const request = new GetContextRequest({
4175
+ name,
4176
+ allowCreate: create ? "true" : "false",
4177
+ authorization: `Bearer ${this.agentBay.getAPIKey()}`
4178
+ });
4179
+ log("API Call: GetContext");
4180
+ log(`Request: Name=${name}, AllowCreate=${create}`);
4181
+ const response = await this.agentBay.getClient().getContext(request);
4182
+ log(`Response from GetContext:`, response.body);
4183
+ const contextId = response.body?.data?.id;
4184
+ if (!contextId) {
4185
+ return null;
4186
+ }
4187
+ const contexts = await this.list();
4188
+ for (const context of contexts) {
4189
+ if (context.id === contextId) {
4190
+ return context;
4191
+ }
4192
+ }
4193
+ return new Context(contextId, name);
4194
+ } catch (error) {
4195
+ logError("Error calling GetContext:", error);
4196
+ throw new APIError(`Failed to get context ${name}: ${error}`);
4197
+ }
4198
+ }
4199
+ /**
4200
+ * Creates a new context with the given name.
4201
+ *
4202
+ * @param name - The name for the new context.
4203
+ * @returns The created Context object.
4204
+ */
4205
+ async create(name) {
4206
+ const context = await this.get(name, true);
4207
+ if (!context) {
4208
+ throw new APIError(`Failed to create context ${name}`);
4209
+ }
4210
+ return context;
4211
+ }
4212
+ /**
4213
+ * Updates the specified context.
4214
+ *
4215
+ * @param context - The Context object to update.
4216
+ * @returns The updated Context object.
4217
+ */
4218
+ async update(context) {
4219
+ try {
4220
+ const request = new ModifyContextRequest({
4221
+ id: context.id,
4222
+ name: context.name,
4223
+ authorization: `Bearer ${this.agentBay.getAPIKey()}`
4224
+ });
4225
+ log("API Call: ModifyContext");
4226
+ log(`Request: Id=${context.id}, Name=${context.name}`);
4227
+ const response = await this.agentBay.getClient().modifyContext(request);
4228
+ log(`Response from ModifyContext:`, response.body);
4229
+ return context;
4230
+ } catch (error) {
4231
+ logError("Error calling ModifyContext:", error);
4232
+ throw new APIError(`Failed to update context ${context.id}: ${error}`);
4233
+ }
4234
+ }
4235
+ /**
4236
+ * Deletes the specified context.
4237
+ *
4238
+ * @param context - The Context object to delete.
4239
+ */
4240
+ async delete(context) {
4241
+ try {
4242
+ const request = new DeleteContextRequest({
4243
+ id: context.id,
4244
+ authorization: `Bearer ${this.agentBay.getAPIKey()}`
4245
+ });
4246
+ log("API Call: DeleteContext");
4247
+ log(`Request: Id=${context.id}`);
4248
+ const response = await this.agentBay.getClient().deleteContext(request);
4249
+ log(`Response from DeleteContext:`, response.body);
4250
+ } catch (error) {
4251
+ logError("Error calling DeleteContext:", error);
4252
+ throw new APIError(`Failed to delete context ${context.id}: ${error}`);
4253
+ }
4254
+ }
4255
+ };
4256
+ __name(_ContextService, "ContextService");
4257
+ var ContextService = _ContextService;
4258
+
4259
+ // src/agent-bay.ts
4260
+ import { $OpenApiUtil as $OpenApiUtil2 } from "@alicloud/openapi-core";
4261
+
4262
+ // src/config.ts
4263
+ init_esm_shims();
4264
+ import * as fs from "fs";
4265
+ import * as path2 from "path";
4266
+
4267
+ // node_modules/dotenv/config.js
4268
+ init_esm_shims();
4269
+ (function() {
4270
+ require_main().config(
4271
+ Object.assign(
4272
+ {},
4273
+ require_env_options(),
4274
+ require_cli_options()(process.argv)
4275
+ )
4276
+ );
4277
+ })();
4278
+
4279
+ // src/config.ts
4280
+ function defaultConfig() {
4281
+ return {
4282
+ region_id: "cn-shanghai",
4283
+ endpoint: "wuyingai.cn-shanghai.aliyuncs.com",
4284
+ timeout_ms: 3e5
4285
+ };
4286
+ }
4287
+ __name(defaultConfig, "defaultConfig");
4288
+ function loadConfig() {
4289
+ let configPath = process.env.AGENTBAY_CONFIG_PATH;
4290
+ if (!configPath) {
4291
+ try {
4292
+ let dirPath = process.cwd();
4293
+ let found = false;
4294
+ for (let i = 0; i < 10; i++) {
4295
+ const possibleConfigPath = path2.join(dirPath, ".config.json");
4296
+ if (fs.existsSync(possibleConfigPath)) {
4297
+ configPath = possibleConfigPath;
4298
+ found = true;
4299
+ log(`Found config file at: ${possibleConfigPath}`);
4300
+ break;
4301
+ }
4302
+ const parentDir = path2.dirname(dirPath);
4303
+ if (parentDir === dirPath) {
4304
+ break;
4305
+ }
4306
+ dirPath = parentDir;
4307
+ }
4308
+ if (!found) {
4309
+ log("Warning: Configuration file not found, using default values");
4310
+ return defaultConfig();
4311
+ }
4312
+ } catch (error) {
4313
+ log(`Warning: Failed to search for configuration file: ${error}, using default values`);
4314
+ return defaultConfig();
4315
+ }
4316
+ }
4317
+ try {
4318
+ if (!configPath) {
4319
+ log("Warning: Configuration file path is undefined, using default values");
4320
+ return defaultConfig();
4321
+ }
4322
+ const data = fs.readFileSync(configPath, "utf8");
4323
+ const config = JSON.parse(data);
4324
+ if (process.env.AGENTBAY_REGION_ID) {
4325
+ config.region_id = process.env.AGENTBAY_REGION_ID;
4326
+ }
4327
+ if (process.env.AGENTBAY_ENDPOINT) {
4328
+ config.endpoint = process.env.AGENTBAY_ENDPOINT;
4329
+ }
4330
+ return config;
4331
+ } catch (error) {
4332
+ log(`Warning: Failed to read configuration file: ${error}, using default values`);
4333
+ return defaultConfig();
4334
+ }
4335
+ }
4336
+ __name(loadConfig, "loadConfig");
4337
+
4338
+ // src/agent-bay.ts
4339
+ var _AgentBay = class _AgentBay {
4340
+ /**
4341
+ * Initialize the AgentBay client.
4342
+ *
4343
+ * @param options - Configuration options
4344
+ * @param options.apiKey - API key for authentication. If not provided, will look for AGENTBAY_API_KEY environment variable.
4345
+ */
4346
+ constructor(options = {}) {
4347
+ this.sessions = /* @__PURE__ */ new Map();
4348
+ this.apiKey = options.apiKey || process.env.AGENTBAY_API_KEY || "";
4349
+ if (!this.apiKey) {
4350
+ throw new AuthenticationError(
4351
+ "API key is required. Provide it as a parameter or set the AGENTBAY_API_KEY environment variable."
4352
+ );
4353
+ }
4354
+ const configData = loadConfig();
4355
+ this.regionId = configData.region_id;
4356
+ this.endpoint = configData.endpoint;
4357
+ const config = new $OpenApiUtil2.Config({
4358
+ regionId: this.regionId,
4359
+ endpoint: this.endpoint
4360
+ });
4361
+ config.readTimeout = configData.timeout_ms;
4362
+ config.connectTimeout = configData.timeout_ms;
4363
+ try {
4364
+ this.client = new Client(config);
4365
+ this.context = new ContextService(this);
4366
+ } catch (error) {
4367
+ logError(`Failed to constructor:`, error);
4368
+ throw new AuthenticationError(`Failed to constructor: ${error}`);
4369
+ }
4370
+ }
4371
+ /**
4372
+ * Create a new session in the AgentBay cloud environment.
4373
+ *
4374
+ * @param options - Optional parameters for creating the session
4375
+ * @param options.contextId - ID of the context to bind to the session
4376
+ * @param options.labels - Custom labels for the session
4377
+ * @returns A new Session object.
4378
+ */
4379
+ async create(options = {}) {
4380
+ try {
4381
+ const createSessionRequest = new CreateMcpSessionRequest({
4382
+ authorization: "Bearer " + this.apiKey,
4383
+ imageId: options.imageId
4384
+ });
4385
+ if (options.contextId) {
4386
+ createSessionRequest.contextId = options.contextId;
4387
+ }
4388
+ if (options.labels) {
4389
+ createSessionRequest.labels = JSON.stringify(options.labels);
4390
+ }
4391
+ log("API Call: CreateMcpSession");
4392
+ log(`Request: ${options.contextId ? `ContextId=${options.contextId}, ` : ""}${options.labels ? `Labels=${JSON.stringify(options.labels)}, ` : ""}${options.imageId ? `ImageId=${options.imageId}` : ""}`);
4393
+ const response = await this.client.createMcpSession(createSessionRequest);
4394
+ log(`Response from CreateMcpSession:`, response.body);
4395
+ const sessionId = response.body?.data?.sessionId;
4396
+ if (!sessionId) {
4397
+ throw new APIError("Invalid session ID in response");
4398
+ }
4399
+ const resourceUrl = response.body?.data?.resourceUrl;
4400
+ const session = new Session(this, sessionId);
4401
+ if (resourceUrl) {
4402
+ session.resourceUrl = resourceUrl;
4403
+ }
4404
+ this.sessions.set(session.sessionId, session);
4405
+ return session;
4406
+ } catch (error) {
4407
+ logError("Error calling CreateMcpSession:", error);
4408
+ throw new APIError(`Failed to create session: ${error}`);
4409
+ }
4410
+ }
4411
+ /**
4412
+ * List all available sessions.
4413
+ *
4414
+ * @returns A list of session objects.
4415
+ */
4416
+ list() {
4417
+ return Array.from(this.sessions.values());
4418
+ }
4419
+ /**
4420
+ * List sessions filtered by the provided labels.
4421
+ * It returns sessions that match all the specified labels.
4422
+ *
4423
+ * @param labels - The labels to filter by.
4424
+ * @returns A list of session objects that match the labels.
4425
+ */
4426
+ async listByLabels(labels) {
4427
+ try {
4428
+ const labelsJSON = JSON.stringify(labels);
4429
+ const listSessionRequest = new ListSessionRequest({
4430
+ authorization: `Bearer ${this.apiKey}`,
4431
+ labels: labelsJSON
4432
+ });
4433
+ log("API Call: ListSession");
4434
+ log(`Request: Labels=${labelsJSON}`);
4435
+ const response = await this.client.listSession(listSessionRequest);
4436
+ log(`Response from ListSession:`, response.body);
4437
+ const sessions = [];
4438
+ if (response.body?.data) {
4439
+ for (const sessionData of response.body.data) {
4440
+ if (sessionData.sessionId) {
4441
+ const session = new Session(this, sessionData.sessionId);
4442
+ sessions.push(session);
4443
+ this.sessions.set(sessionData.sessionId, session);
4444
+ }
4445
+ }
4446
+ }
4447
+ return sessions;
4448
+ } catch (error) {
4449
+ logError("Error calling ListSession:", error);
4450
+ throw new APIError(`Failed to list sessions by labels: ${error}`);
4451
+ }
4452
+ }
4453
+ /**
4454
+ * Delete a session by ID.
4455
+ *
4456
+ * @param sessionId - The ID of the session to delete.
4457
+ * @returns True if the session was successfully deleted.
4458
+ */
4459
+ async delete(session) {
4460
+ const getSession = this.sessions.get(session.sessionId);
4461
+ if (!getSession) {
4462
+ throw new Error(`Session with ID ${session.sessionId} not found`);
4463
+ }
4464
+ try {
4465
+ await session.delete();
4466
+ return true;
4467
+ } catch (error) {
4468
+ throw new APIError(`Failed to delete session: ${error}`);
4469
+ }
4470
+ }
4471
+ /**
4472
+ *
4473
+ * @param sessionId - The ID of the session to remove.
4474
+ */
4475
+ removeSession(sessionId) {
4476
+ this.sessions.delete(sessionId);
4477
+ }
4478
+ // For internal use by the Session class
4479
+ getClient() {
4480
+ return this.client;
4481
+ }
4482
+ getAPIKey() {
4483
+ return this.apiKey;
4484
+ }
4485
+ };
4486
+ __name(_AgentBay, "AgentBay");
4487
+ var AgentBay = _AgentBay;
4488
+ export {
4489
+ APIError,
4490
+ AgentBay,
4491
+ AgentBayError,
4492
+ Application,
4493
+ AuthenticationError,
4494
+ CallMcpToolRequest,
4495
+ CallMcpToolResponse,
4496
+ CallMcpToolResponseBody,
4497
+ Client,
4498
+ Command,
4499
+ CommandError,
4500
+ Context,
4501
+ ContextService,
4502
+ CreateMcpSessionRequest,
4503
+ CreateMcpSessionResponse,
4504
+ CreateMcpSessionResponseBody,
4505
+ CreateMcpSessionResponseBodyData,
4506
+ DeleteContextRequest,
4507
+ DeleteContextResponse,
4508
+ DeleteContextResponseBody,
4509
+ FileError,
4510
+ FileSystem,
4511
+ GetContextRequest,
4512
+ GetContextResponse,
4513
+ GetContextResponseBody,
4514
+ GetContextResponseBodyData,
4515
+ GetLabelRequest,
4516
+ GetLabelResponse,
4517
+ GetLabelResponseBody,
4518
+ GetLabelResponseBodyData,
4519
+ GetLinkRequest,
4520
+ GetLinkResponse,
4521
+ GetLinkResponseBody,
4522
+ GetMcpResourceRequest,
4523
+ GetMcpResourceResponse,
4524
+ GetMcpResourceResponseBody,
4525
+ GetMcpResourceResponseBodyData,
4526
+ GetMcpResourceResponseBodyDataDesktopInfo,
4527
+ KeyCode,
4528
+ ListContextsRequest,
4529
+ ListContextsResponse,
4530
+ ListContextsResponseBody,
4531
+ ListContextsResponseBodyData,
4532
+ ListSessionRequest,
4533
+ ListSessionResponse,
4534
+ ListSessionResponseBody,
4535
+ ListSessionResponseBodyData,
4536
+ ModifyContextRequest,
4537
+ ModifyContextResponse,
4538
+ ModifyContextResponseBody,
4539
+ Oss,
4540
+ ReleaseMcpSessionRequest,
4541
+ ReleaseMcpSessionResponse,
4542
+ ReleaseMcpSessionResponseBody,
4543
+ Session,
4544
+ SetLabelRequest,
4545
+ SetLabelResponse,
4546
+ SetLabelResponseBody,
4547
+ UI
4548
+ };
4549
+ //# sourceMappingURL=index.mjs.map
4550
+