@agentrun/sdk 0.0.3 → 0.0.4

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 (130) hide show
  1. package/README.md +20 -15
  2. package/dist/agent-runtime/api/index.cjs +907 -0
  3. package/dist/agent-runtime/api/index.cjs.map +1 -0
  4. package/dist/agent-runtime/api/index.d.cts +193 -0
  5. package/dist/agent-runtime/api/index.d.ts +193 -0
  6. package/dist/agent-runtime/api/index.js +882 -0
  7. package/dist/agent-runtime/api/index.js.map +1 -0
  8. package/dist/agent-runtime/index.cjs +2528 -0
  9. package/dist/agent-runtime/index.cjs.map +1 -0
  10. package/dist/agent-runtime/index.d.cts +778 -0
  11. package/dist/agent-runtime/index.d.ts +778 -0
  12. package/dist/agent-runtime/index.js +2496 -0
  13. package/dist/agent-runtime/index.js.map +1 -0
  14. package/dist/base-K1GMfJbH.d.ts +59 -0
  15. package/dist/base-xcWt5bua.d.cts +59 -0
  16. package/dist/client-DHXxjuo3.d.ts +58 -0
  17. package/dist/client-DPUTs69s.d.cts +58 -0
  18. package/dist/config-07gMelJP.d.cts +125 -0
  19. package/dist/config-07gMelJP.d.ts +125 -0
  20. package/dist/control-api-BWD4eua5.d.cts +27 -0
  21. package/dist/control-api-d-82Sgpr.d.ts +27 -0
  22. package/dist/credential/api/index.cjs +655 -0
  23. package/dist/credential/api/index.cjs.map +1 -0
  24. package/dist/credential/api/index.d.cts +93 -0
  25. package/dist/credential/api/index.d.ts +93 -0
  26. package/dist/credential/api/index.js +630 -0
  27. package/dist/credential/api/index.js.map +1 -0
  28. package/dist/credential/index.cjs +1286 -0
  29. package/dist/credential/index.cjs.map +1 -0
  30. package/dist/credential/index.d.cts +246 -0
  31. package/dist/credential/index.d.ts +246 -0
  32. package/dist/credential/index.js +1263 -0
  33. package/dist/credential/index.js.map +1 -0
  34. package/dist/data-api-B-4h9_Vf.d.ts +166 -0
  35. package/dist/data-api-DsG-8JRQ.d.cts +166 -0
  36. package/dist/exception-DM9H2Rpo.d.cts +68 -0
  37. package/dist/exception-DM9H2Rpo.d.ts +68 -0
  38. package/dist/index.cjs +29281 -1427
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.cts +38 -4485
  41. package/dist/index.d.ts +38 -4485
  42. package/dist/index.js +29259 -1426
  43. package/dist/index.js.map +1 -1
  44. package/dist/integration/builtin/index.cjs +9399 -0
  45. package/dist/integration/builtin/index.cjs.map +1 -0
  46. package/dist/integration/builtin/index.d.cts +692 -0
  47. package/dist/integration/builtin/index.d.ts +692 -0
  48. package/dist/integration/builtin/index.js +9363 -0
  49. package/dist/integration/builtin/index.js.map +1 -0
  50. package/dist/integration/index.cjs +9524 -0
  51. package/dist/integration/index.cjs.map +1 -0
  52. package/dist/integration/index.d.cts +98 -0
  53. package/dist/integration/index.d.ts +98 -0
  54. package/dist/integration/index.js +9481 -0
  55. package/dist/integration/index.js.map +1 -0
  56. package/dist/integration/mastra/index.cjs +9383 -0
  57. package/dist/integration/mastra/index.cjs.map +1 -0
  58. package/dist/integration/mastra/index.d.cts +186 -0
  59. package/dist/integration/mastra/index.d.ts +186 -0
  60. package/dist/integration/mastra/index.js +9348 -0
  61. package/dist/integration/mastra/index.js.map +1 -0
  62. package/dist/model/index.cjs +2392 -0
  63. package/dist/model/index.cjs.map +1 -0
  64. package/dist/model/index.d.cts +97 -0
  65. package/dist/model/index.d.ts +97 -0
  66. package/dist/model/index.js +2368 -0
  67. package/dist/model/index.js.map +1 -0
  68. package/dist/model--I90nCqy.d.cts +66 -0
  69. package/dist/model--I90nCqy.d.ts +66 -0
  70. package/dist/model-BV7A6Trb.d.cts +512 -0
  71. package/dist/model-DGBy-o_L.d.cts +176 -0
  72. package/dist/model-DGBy-o_L.d.ts +176 -0
  73. package/dist/model-RiiiZnou.d.ts +512 -0
  74. package/dist/model-service-D-P2FZNi.d.ts +540 -0
  75. package/dist/model-service-VpzBb7rV.d.cts +540 -0
  76. package/dist/resource-CQovFUeh.d.cts +44 -0
  77. package/dist/resource-DnE_DEka.d.ts +44 -0
  78. package/dist/sandbox/index.cjs +3557 -0
  79. package/dist/sandbox/index.cjs.map +1 -0
  80. package/dist/sandbox/index.d.cts +1598 -0
  81. package/dist/sandbox/index.d.ts +1598 -0
  82. package/dist/sandbox/index.js +3532 -0
  83. package/dist/sandbox/index.js.map +1 -0
  84. package/dist/server/adapter/index.cjs +24886 -0
  85. package/dist/server/adapter/index.cjs.map +1 -0
  86. package/dist/server/adapter/index.d.cts +68 -0
  87. package/dist/server/adapter/index.d.ts +68 -0
  88. package/dist/server/adapter/index.js +24883 -0
  89. package/dist/server/adapter/index.js.map +1 -0
  90. package/dist/server/core/index.cjs +313 -0
  91. package/dist/server/core/index.cjs.map +1 -0
  92. package/dist/server/core/index.d.cts +58 -0
  93. package/dist/server/core/index.d.ts +58 -0
  94. package/dist/server/core/index.js +309 -0
  95. package/dist/server/core/index.js.map +1 -0
  96. package/dist/server/index.cjs +25098 -0
  97. package/dist/server/index.cjs.map +1 -0
  98. package/dist/server/index.d.cts +73 -0
  99. package/dist/server/index.d.ts +73 -0
  100. package/dist/server/index.js +25067 -0
  101. package/dist/server/index.js.map +1 -0
  102. package/dist/server/protocol/index.cjs +1057 -0
  103. package/dist/server/protocol/index.cjs.map +1 -0
  104. package/dist/server/protocol/index.d.cts +135 -0
  105. package/dist/server/protocol/index.d.ts +135 -0
  106. package/dist/server/protocol/index.js +1053 -0
  107. package/dist/server/protocol/index.js.map +1 -0
  108. package/dist/tool-CG0LY-ov.d.cts +155 -0
  109. package/dist/tool-JJHam0ms.d.ts +155 -0
  110. package/dist/toolset/api/index.cjs +754 -0
  111. package/dist/toolset/api/index.cjs.map +1 -0
  112. package/dist/toolset/api/index.d.cts +207 -0
  113. package/dist/toolset/api/index.d.ts +207 -0
  114. package/dist/toolset/api/index.js +727 -0
  115. package/dist/toolset/api/index.js.map +1 -0
  116. package/dist/toolset/index.cjs +1945 -0
  117. package/dist/toolset/index.cjs.map +1 -0
  118. package/dist/toolset/index.d.cts +182 -0
  119. package/dist/toolset/index.d.ts +182 -0
  120. package/dist/toolset/index.js +1920 -0
  121. package/dist/toolset/index.js.map +1 -0
  122. package/dist/toolset-BYDvhwRp.d.cts +394 -0
  123. package/dist/toolset-CSRsJxCb.d.ts +394 -0
  124. package/dist/utils/index.cjs +994 -0
  125. package/dist/utils/index.cjs.map +1 -0
  126. package/dist/utils/index.d.cts +30 -0
  127. package/dist/utils/index.d.ts +30 -0
  128. package/dist/utils/index.js +951 -0
  129. package/dist/utils/index.js.map +1 -0
  130. package/package.json +65 -13
@@ -0,0 +1,2528 @@
1
+ 'use strict';
2
+
3
+ var dotenv = require('dotenv');
4
+ var $AgentRun3 = require('@alicloud/agentrun20250910');
5
+ var $OpenApi = require('@alicloud/openapi-client');
6
+ var $Util = require('@alicloud/tea-util');
7
+ var http = require('http');
8
+ var https = require('https');
9
+ var fs2 = require('fs');
10
+ var path = require('path');
11
+ var url = require('url');
12
+ var crc64Lib = require('crc64-ecma182.js');
13
+
14
+ function _interopNamespace(e) {
15
+ if (e && e.__esModule) return e;
16
+ var n = Object.create(null);
17
+ if (e) {
18
+ Object.keys(e).forEach(function (k) {
19
+ if (k !== 'default') {
20
+ var d = Object.getOwnPropertyDescriptor(e, k);
21
+ Object.defineProperty(n, k, d.get ? d : {
22
+ enumerable: true,
23
+ get: function () { return e[k]; }
24
+ });
25
+ }
26
+ });
27
+ }
28
+ n.default = e;
29
+ return Object.freeze(n);
30
+ }
31
+
32
+ var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
33
+ var $AgentRun3__namespace = /*#__PURE__*/_interopNamespace($AgentRun3);
34
+ var $OpenApi__namespace = /*#__PURE__*/_interopNamespace($OpenApi);
35
+ var $Util__namespace = /*#__PURE__*/_interopNamespace($Util);
36
+ var http__namespace = /*#__PURE__*/_interopNamespace(http);
37
+ var https__namespace = /*#__PURE__*/_interopNamespace(https);
38
+ var fs2__namespace = /*#__PURE__*/_interopNamespace(fs2);
39
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
40
+ var crc64Lib__namespace = /*#__PURE__*/_interopNamespace(crc64Lib);
41
+
42
+ var __defProp = Object.defineProperty;
43
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
44
+ var __getOwnPropNames = Object.getOwnPropertyNames;
45
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
46
+ var __esm = (fn, res) => function __init() {
47
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
48
+ };
49
+ var __export = (target, all) => {
50
+ for (var name in all)
51
+ __defProp(target, name, { get: all[name], enumerable: true });
52
+ };
53
+ var __copyProps = (to, from, except, desc) => {
54
+ if (from && typeof from === "object" || typeof from === "function") {
55
+ for (let key of __getOwnPropNames(from))
56
+ if (!__hasOwnProp.call(to, key) && key !== except)
57
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
58
+ }
59
+ return to;
60
+ };
61
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
62
+
63
+ // src/utils/log.ts
64
+ var LOG_LEVELS, COLORS, Logger, logger;
65
+ var init_log = __esm({
66
+ "src/utils/log.ts"() {
67
+ LOG_LEVELS = {
68
+ debug: 0,
69
+ info: 1,
70
+ warn: 2,
71
+ error: 3
72
+ };
73
+ COLORS = {
74
+ reset: "\x1B[0m",
75
+ bright: "\x1B[1m",
76
+ dim: "\x1B[2m",
77
+ italic: "\x1B[3m",
78
+ blue: "\x1B[34m",
79
+ cyan: "\x1B[36m",
80
+ yellow: "\x1B[33m",
81
+ red: "\x1B[31m"
82
+ };
83
+ Logger = class {
84
+ level = "info";
85
+ // match Python logger name
86
+ prefix = "agentrun-logger";
87
+ setLevel(level) {
88
+ this.level = level;
89
+ }
90
+ shouldLog(level) {
91
+ return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
92
+ }
93
+ getColor(level) {
94
+ switch (level) {
95
+ case "debug":
96
+ return COLORS.cyan;
97
+ case "info":
98
+ return COLORS.blue;
99
+ case "warn":
100
+ return COLORS.yellow;
101
+ case "error":
102
+ return COLORS.red;
103
+ default:
104
+ return COLORS.reset;
105
+ }
106
+ }
107
+ // format timestamp like Python: YYYY-MM-DD HH:mm:ss,SSS
108
+ formatTimestamp(d = /* @__PURE__ */ new Date()) {
109
+ const pad = (n, sz = 2) => n.toString().padStart(sz, "0");
110
+ const year = d.getFullYear();
111
+ const month = pad(d.getMonth() + 1);
112
+ const day = pad(d.getDate());
113
+ const hour = pad(d.getHours());
114
+ const minute = pad(d.getMinutes());
115
+ const second = pad(d.getSeconds());
116
+ const ms = pad(d.getMilliseconds(), 3);
117
+ return `${year}-${month}-${day} ${hour}:${minute}:${second},${ms}`;
118
+ }
119
+ // attempt to infer caller file and line by parsing Error.stack
120
+ // helper: parse a single stack frame into {filepath, line, functionName}
121
+ parseFrame(frame) {
122
+ const m = frame.match(/^(?:at\s+)?(?:(.+?)\s+\()?(.*?):(\d+):(\d+)\)?$/);
123
+ if (!m) return null;
124
+ return {
125
+ functionName: m[1] ? m[1].trim() : void 0,
126
+ filepath: m[2],
127
+ line: parseInt(m[3], 10)
128
+ };
129
+ }
130
+ // get caller by fixed stack offset (used in public log methods)
131
+ getCallerByOffset() {
132
+ const err = new Error();
133
+ const stack = err.stack;
134
+ if (!stack) return {};
135
+ const lines = stack.split("\n").map((l) => l.trim());
136
+ for (let i = 3; i < lines.length; i++) {
137
+ let parsed = this.parseFrame(lines[i]);
138
+ if (!parsed) {
139
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
140
+ if (m) {
141
+ const parts = m[1].split(":");
142
+ parts.pop();
143
+ const ln = Number(parts.pop());
144
+ const fp2 = parts.join(":");
145
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
146
+ }
147
+ }
148
+ if (!parsed) continue;
149
+ const fp = parsed.filepath;
150
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
151
+ continue;
152
+ return { filepath: parsed.filepath, line: parsed.line };
153
+ }
154
+ const cwd = process.cwd();
155
+ for (let i = 0; i < lines.length; i++) {
156
+ let parsed = this.parseFrame(lines[i]);
157
+ if (!parsed) {
158
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
159
+ if (m) {
160
+ const parts = m[1].split(":");
161
+ parts.pop();
162
+ const ln = Number(parts.pop());
163
+ const fp2 = parts.join(":");
164
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
165
+ }
166
+ }
167
+ if (!parsed) continue;
168
+ const fp = parsed.filepath;
169
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
170
+ continue;
171
+ if (fp.includes("/src/utils/log.ts")) continue;
172
+ if (fp.startsWith(cwd)) return { filepath: parsed.filepath, line: parsed.line };
173
+ }
174
+ for (let i = 0; i < lines.length; i++) {
175
+ let parsed = this.parseFrame(lines[i]);
176
+ if (!parsed) {
177
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
178
+ if (m) {
179
+ const parts = m[1].split(":");
180
+ parts.pop();
181
+ const ln = Number(parts.pop());
182
+ const fp2 = parts.join(":");
183
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
184
+ }
185
+ }
186
+ if (!parsed) continue;
187
+ const fp = parsed.filepath;
188
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
189
+ continue;
190
+ if (fp.includes("/src/utils/log.ts")) continue;
191
+ return { filepath: parsed.filepath, line: parsed.line };
192
+ }
193
+ return {};
194
+ }
195
+ formatMessage(level, message, filepath, line) {
196
+ const timestamp = this.formatTimestamp();
197
+ const color = this.getColor(level);
198
+ const reset = COLORS.reset;
199
+ const levelName = level === "warn" ? "WARNING" : level.toUpperCase();
200
+ const levelStr = `${COLORS.bright}${color}${levelName}${reset}`;
201
+ const nameStr = `${color}[${this.prefix}]${reset}`;
202
+ const tsStr = `${color} ${timestamp}${reset}`;
203
+ const pathInfo = filepath && line !== void 0 ? ` ${COLORS.dim}${COLORS.italic}${filepath}:${line}${reset}` : "";
204
+ const msg = level === "debug" ? `${COLORS.dim}${message}${reset}` : message;
205
+ return `
206
+ ${levelStr} ${nameStr}${tsStr}${pathInfo}
207
+ ${msg}
208
+ `;
209
+ }
210
+ debug(message, ...args) {
211
+ if (this.shouldLog("debug")) {
212
+ const caller = this.getCallerByOffset();
213
+ console.debug(this.formatMessage("debug", message, caller.filepath, caller.line), ...args);
214
+ }
215
+ }
216
+ info(message, ...args) {
217
+ if (this.shouldLog("info")) {
218
+ const caller = this.getCallerByOffset();
219
+ console.info(this.formatMessage("info", message, caller.filepath, caller.line), ...args);
220
+ }
221
+ }
222
+ warn(message, ...args) {
223
+ if (this.shouldLog("warn")) {
224
+ const caller = this.getCallerByOffset();
225
+ console.warn(this.formatMessage("warn", message, caller.filepath, caller.line), ...args);
226
+ }
227
+ }
228
+ error(message, ...args) {
229
+ if (this.shouldLog("error")) {
230
+ const caller = this.getCallerByOffset();
231
+ console.error(this.formatMessage("error", message, caller.filepath, caller.line), ...args);
232
+ }
233
+ }
234
+ };
235
+ logger = new Logger();
236
+ if (![void 0, null, "", "False", "FALSE", "false", "0"].includes(process.env["AGENTRUN_SDK_DEBUG"])) {
237
+ logger.setLevel("debug");
238
+ if (!globalThis._AGENTRUN_DEBUG_LOGGED) {
239
+ logger.warn("\u542F\u7528 AgentRun SDK \u8C03\u8BD5\u65E5\u5FD7\uFF0C \u79FB\u9664 AGENTRUN_SDK_DEBUG \u73AF\u5883\u53D8\u91CF\u4EE5\u5173\u95ED");
240
+ globalThis._AGENTRUN_DEBUG_LOGGED = true;
241
+ }
242
+ } else {
243
+ logger.setLevel("info");
244
+ }
245
+ }
246
+ });
247
+ function getEnvWithDefault(defaultValue, ...keys) {
248
+ for (const key of keys) {
249
+ const value = process.env[key];
250
+ if (value !== void 0 && value !== "") {
251
+ return value;
252
+ }
253
+ }
254
+ return defaultValue;
255
+ }
256
+ var Config;
257
+ var init_config = __esm({
258
+ "src/utils/config.ts"() {
259
+ dotenv__namespace.config();
260
+ Config = class _Config {
261
+ _accessKeyId;
262
+ _accessKeySecret;
263
+ _securityToken;
264
+ _accountId;
265
+ _token;
266
+ _regionId;
267
+ _timeout;
268
+ _readTimeout;
269
+ _controlEndpoint;
270
+ _dataEndpoint;
271
+ _devsEndpoint;
272
+ _headers;
273
+ constructor(options = {}) {
274
+ this._accessKeyId = options.accessKeyId ?? getEnvWithDefault("", "AGENTRUN_ACCESS_KEY_ID", "ALIBABA_CLOUD_ACCESS_KEY_ID");
275
+ this._accessKeySecret = options.accessKeySecret ?? getEnvWithDefault("", "AGENTRUN_ACCESS_KEY_SECRET", "ALIBABA_CLOUD_ACCESS_KEY_SECRET");
276
+ this._securityToken = options.securityToken ?? getEnvWithDefault("", "AGENTRUN_SECURITY_TOKEN", "ALIBABA_CLOUD_SECURITY_TOKEN");
277
+ this._accountId = options.accountId ?? getEnvWithDefault("", "AGENTRUN_ACCOUNT_ID", "FC_ACCOUNT_ID");
278
+ this._token = options.token;
279
+ this._regionId = options.regionId ?? getEnvWithDefault("cn-hangzhou", "AGENTRUN_REGION", "FC_REGION");
280
+ this._timeout = options.timeout ?? 6e5;
281
+ this._readTimeout = options.readTimeout ?? 1e8;
282
+ this._controlEndpoint = options.controlEndpoint ?? getEnvWithDefault("", "AGENTRUN_CONTROL_ENDPOINT");
283
+ this._dataEndpoint = options.dataEndpoint ?? getEnvWithDefault("", "AGENTRUN_DATA_ENDPOINT");
284
+ this._devsEndpoint = options.devsEndpoint ?? getEnvWithDefault("", "DEVS_ENDPOINT");
285
+ this._headers = options.headers ?? {};
286
+ }
287
+ /**
288
+ * Create a new Config by merging multiple configs.
289
+ * Later configs take precedence.
290
+ */
291
+ static withConfigs(...configs) {
292
+ return new _Config().update(...configs);
293
+ }
294
+ /**
295
+ * Update this config with values from other configs.
296
+ * Non-undefined values from later configs take precedence.
297
+ */
298
+ update(...configs) {
299
+ for (const config2 of configs) {
300
+ if (!config2) continue;
301
+ if (config2._accessKeyId) this._accessKeyId = config2._accessKeyId;
302
+ if (config2._accessKeySecret) this._accessKeySecret = config2._accessKeySecret;
303
+ if (config2._securityToken) this._securityToken = config2._securityToken;
304
+ if (config2._accountId) this._accountId = config2._accountId;
305
+ if (config2._token) this._token = config2._token;
306
+ if (config2._regionId) this._regionId = config2._regionId;
307
+ if (config2._timeout) this._timeout = config2._timeout;
308
+ if (config2._readTimeout) this._readTimeout = config2._readTimeout;
309
+ if (config2._controlEndpoint) this._controlEndpoint = config2._controlEndpoint;
310
+ if (config2._dataEndpoint) this._dataEndpoint = config2._dataEndpoint;
311
+ if (config2._devsEndpoint) this._devsEndpoint = config2._devsEndpoint;
312
+ if (config2._headers && Object.keys(config2._headers).length > 0) {
313
+ this._headers = { ...this._headers, ...config2._headers };
314
+ }
315
+ }
316
+ return this;
317
+ }
318
+ get accessKeyId() {
319
+ return this._accessKeyId;
320
+ }
321
+ get accessKeySecret() {
322
+ return this._accessKeySecret;
323
+ }
324
+ get securityToken() {
325
+ return this._securityToken;
326
+ }
327
+ get accountId() {
328
+ if (!this._accountId) {
329
+ throw new Error(
330
+ "Account ID is not set. Please add AGENTRUN_ACCOUNT_ID environment variable or set it in code."
331
+ );
332
+ }
333
+ return this._accountId;
334
+ }
335
+ get token() {
336
+ return this._token;
337
+ }
338
+ get regionId() {
339
+ return this._regionId || "cn-hangzhou";
340
+ }
341
+ get timeout() {
342
+ return this._timeout || 6e5;
343
+ }
344
+ get readTimeout() {
345
+ return this._readTimeout || 1e8;
346
+ }
347
+ get controlEndpoint() {
348
+ if (this._controlEndpoint) {
349
+ return this._controlEndpoint;
350
+ }
351
+ return `https://agentrun.${this.regionId}.aliyuncs.com`;
352
+ }
353
+ get dataEndpoint() {
354
+ if (this._dataEndpoint) {
355
+ return this._dataEndpoint;
356
+ }
357
+ return `https://${this.accountId}.agentrun-data.${this.regionId}.aliyuncs.com`;
358
+ }
359
+ get devsEndpoint() {
360
+ if (this._devsEndpoint) {
361
+ return this._devsEndpoint;
362
+ }
363
+ return `https://devs.${this.regionId}.aliyuncs.com`;
364
+ }
365
+ get headers() {
366
+ return this._headers;
367
+ }
368
+ };
369
+ }
370
+ });
371
+
372
+ // src/utils/exception.ts
373
+ var AgentRunError, HTTPError, ClientError, ServerError, ResourceNotExistError, ResourceAlreadyExistError;
374
+ var init_exception = __esm({
375
+ "src/utils/exception.ts"() {
376
+ AgentRunError = class _AgentRunError extends Error {
377
+ constructor(message) {
378
+ super(message);
379
+ this.name = "AgentRunError";
380
+ Object.setPrototypeOf(this, _AgentRunError.prototype);
381
+ }
382
+ };
383
+ HTTPError = class _HTTPError extends AgentRunError {
384
+ statusCode;
385
+ requestId;
386
+ errorCode;
387
+ constructor(statusCode, message, options) {
388
+ super(message);
389
+ this.name = "HTTPError";
390
+ this.statusCode = statusCode;
391
+ this.requestId = options?.requestId;
392
+ this.errorCode = options?.errorCode;
393
+ Object.setPrototypeOf(this, _HTTPError.prototype);
394
+ }
395
+ /**
396
+ * Convert HTTP error to resource-specific error based on status code
397
+ */
398
+ toResourceError(resourceType, resourceId) {
399
+ if (this.statusCode == 404) return new ResourceNotExistError(resourceType, resourceId);
400
+ else if (this.statusCode == 409) return new ResourceAlreadyExistError(resourceType, resourceId);
401
+ else if ((this.statusCode == 400 || this.statusCode == 500) && this.message.includes("already exists"))
402
+ return new ResourceAlreadyExistError(resourceType, resourceId);
403
+ else return this;
404
+ }
405
+ };
406
+ ClientError = class _ClientError extends HTTPError {
407
+ constructor(statusCode, message, options) {
408
+ super(statusCode, message, options);
409
+ this.name = "ClientError";
410
+ Object.setPrototypeOf(this, _ClientError.prototype);
411
+ }
412
+ };
413
+ ServerError = class _ServerError extends HTTPError {
414
+ constructor(statusCode, message, options) {
415
+ super(statusCode, message, options);
416
+ this.name = "ServerError";
417
+ Object.setPrototypeOf(this, _ServerError.prototype);
418
+ }
419
+ };
420
+ ResourceNotExistError = class _ResourceNotExistError extends ClientError {
421
+ resourceType;
422
+ resourceId;
423
+ constructor(resourceType, resourceId, options) {
424
+ const message = resourceId ? `${resourceType} '${resourceId}' does not exist` : `${resourceType} does not exist`;
425
+ super(404, message, options);
426
+ this.name = "ResourceNotExistError";
427
+ this.resourceType = resourceType;
428
+ this.resourceId = resourceId;
429
+ Object.setPrototypeOf(this, _ResourceNotExistError.prototype);
430
+ }
431
+ };
432
+ ResourceAlreadyExistError = class _ResourceAlreadyExistError extends ClientError {
433
+ resourceType;
434
+ resourceId;
435
+ constructor(resourceType, resourceId, options) {
436
+ const message = resourceId ? `${resourceType} '${resourceId}' already exists` : `${resourceType} already exists`;
437
+ super(409, message, options);
438
+ this.name = "ResourceAlreadyExistError";
439
+ this.resourceType = resourceType;
440
+ this.resourceId = resourceId;
441
+ Object.setPrototypeOf(this, _ResourceAlreadyExistError.prototype);
442
+ }
443
+ };
444
+ }
445
+ });
446
+
447
+ // src/utils/model.ts
448
+ function isFinalStatus(status) {
449
+ return [
450
+ void 0,
451
+ null,
452
+ "",
453
+ ...["READY", "CREATE_FAILED", "UPDATE_FAILED", "DELETE_FAILED"]
454
+ ].includes(status);
455
+ }
456
+ var Status, NetworkMode;
457
+ var init_model = __esm({
458
+ "src/utils/model.ts"() {
459
+ Status = {
460
+ CREATING: "CREATING",
461
+ CREATE_FAILED: "CREATE_FAILED",
462
+ READY: "READY",
463
+ UPDATING: "UPDATING",
464
+ UPDATE_FAILED: "UPDATE_FAILED",
465
+ DELETING: "DELETING",
466
+ DELETE_FAILED: "DELETE_FAILED"
467
+ };
468
+ NetworkMode = {
469
+ PUBLIC: "PUBLIC",
470
+ PRIVATE: "PRIVATE",
471
+ PUBLIC_AND_PRIVATE: "PUBLIC_AND_PRIVATE"
472
+ };
473
+ }
474
+ });
475
+
476
+ // src/utils/control-api.ts
477
+ var control_api_exports = {};
478
+ __export(control_api_exports, {
479
+ $AgentRun: () => $AgentRun3__namespace,
480
+ ControlAPI: () => ControlAPI
481
+ });
482
+ var $AgentRunClient, ControlAPI;
483
+ var init_control_api = __esm({
484
+ "src/utils/control-api.ts"() {
485
+ init_config();
486
+ $AgentRunClient = // @ts-expect-error - ESM interop: default.default exists when imported as ESM namespace
487
+ $AgentRun3__namespace.default?.default ?? $AgentRun3__namespace.default ?? $AgentRun3__namespace;
488
+ ControlAPI = class {
489
+ config;
490
+ constructor(config2) {
491
+ this.config = config2;
492
+ }
493
+ /**
494
+ * Get the underlying AgentRun client instance
495
+ */
496
+ getClient(config2) {
497
+ const cfg = Config.withConfigs(this.config, config2);
498
+ let endpoint = cfg.controlEndpoint;
499
+ if (endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
500
+ endpoint = endpoint.split("://")[1];
501
+ }
502
+ const openApiConfig = new $OpenApi__namespace.Config({
503
+ accessKeyId: cfg.accessKeyId,
504
+ accessKeySecret: cfg.accessKeySecret,
505
+ securityToken: cfg.securityToken || void 0,
506
+ regionId: cfg.regionId,
507
+ endpoint,
508
+ connectTimeout: cfg.timeout,
509
+ readTimeout: cfg.readTimeout
510
+ });
511
+ return new $AgentRunClient(openApiConfig);
512
+ }
513
+ };
514
+ }
515
+ });
516
+ exports.AgentRuntimeControlAPI = void 0;
517
+ var init_control = __esm({
518
+ "src/agent-runtime/api/control.ts"() {
519
+ init_control_api();
520
+ init_exception();
521
+ init_log();
522
+ exports.AgentRuntimeControlAPI = class extends ControlAPI {
523
+ constructor(config2) {
524
+ super(config2);
525
+ }
526
+ /**
527
+ * Create Agent Runtime
528
+ *
529
+ * @param params - Method parameters
530
+ * @param params.input - Agent Runtime configuration
531
+ * @param params.headers - Custom request headers
532
+ * @param params.config - Optional config override
533
+ * @returns Created Runtime object
534
+ */
535
+ createAgentRuntime = async (params) => {
536
+ const { input, headers, config: config2 } = params;
537
+ try {
538
+ const client = this.getClient(config2);
539
+ const runtime = new $Util__namespace.RuntimeOptions({});
540
+ const response = await client.createAgentRuntimeWithOptions(
541
+ new $AgentRun3__namespace.CreateAgentRuntimeRequest({ body: input }),
542
+ headers ?? {},
543
+ runtime
544
+ );
545
+ logger.debug(
546
+ `request api createAgentRuntime, request Request ID: ${response.body?.requestId}
547
+ request: ${JSON.stringify([input])}
548
+ response: ${JSON.stringify(response.body?.data)}`
549
+ );
550
+ return response.body?.data;
551
+ } catch (error) {
552
+ if (error && typeof error === "object" && "statusCode" in error) {
553
+ const e = error;
554
+ const statusCode = e.statusCode;
555
+ const message = e.message || "Unknown error";
556
+ const requestId = e.data?.requestId;
557
+ if (statusCode >= 400 && statusCode < 500) {
558
+ throw new ClientError(statusCode, message, { requestId });
559
+ } else if (statusCode >= 500) {
560
+ throw new ServerError(statusCode, message, { requestId });
561
+ }
562
+ }
563
+ throw error;
564
+ }
565
+ };
566
+ /**
567
+ * Delete Agent Runtime
568
+ *
569
+ * @param params - Method parameters
570
+ * @param params.agentId - Agent Runtime ID
571
+ * @param params.headers - Custom request headers
572
+ * @param params.config - Optional config override
573
+ * @returns Deleted Runtime object
574
+ */
575
+ deleteAgentRuntime = async (params) => {
576
+ const { agentId, headers, config: config2 } = params;
577
+ try {
578
+ const client = this.getClient(config2);
579
+ const runtime = new $Util__namespace.RuntimeOptions({});
580
+ const response = await client.deleteAgentRuntimeWithOptions(agentId, headers ?? {}, runtime);
581
+ logger.debug(
582
+ `request api deleteAgentRuntime, request Request ID: ${response.body?.requestId}
583
+ request: ${JSON.stringify([agentId])}
584
+ response: ${JSON.stringify(response.body?.data)}`
585
+ );
586
+ return response.body?.data;
587
+ } catch (error) {
588
+ if (error && typeof error === "object" && "statusCode" in error) {
589
+ const e = error;
590
+ const statusCode = e.statusCode;
591
+ const message = e.message || "Unknown error";
592
+ const requestId = e.data?.requestId;
593
+ if (statusCode >= 400 && statusCode < 500) {
594
+ throw new ClientError(statusCode, message, { requestId });
595
+ } else if (statusCode >= 500) {
596
+ throw new ServerError(statusCode, message, { requestId });
597
+ }
598
+ }
599
+ throw error;
600
+ }
601
+ };
602
+ /**
603
+ * Update Agent Runtime
604
+ *
605
+ * @param params - Method parameters
606
+ * @param params.agentId - Agent Runtime ID
607
+ * @param params.input - Agent Runtime configuration
608
+ * @param params.headers - Custom request headers
609
+ * @param params.config - Optional config override
610
+ * @returns Updated Runtime object
611
+ */
612
+ updateAgentRuntime = async (params) => {
613
+ const { agentId, input, headers, config: config2 } = params;
614
+ try {
615
+ const client = this.getClient(config2);
616
+ const runtime = new $Util__namespace.RuntimeOptions({});
617
+ const response = await client.updateAgentRuntimeWithOptions(
618
+ agentId,
619
+ new $AgentRun3__namespace.UpdateAgentRuntimeRequest({ body: input }),
620
+ headers ?? {},
621
+ runtime
622
+ );
623
+ logger.debug(
624
+ `request api updateAgentRuntime, request Request ID: ${response.body?.requestId}
625
+ request: ${JSON.stringify([agentId, input])}
626
+ response: ${JSON.stringify(response.body?.data)}`
627
+ );
628
+ return response.body?.data;
629
+ } catch (error) {
630
+ if (error && typeof error === "object" && "statusCode" in error) {
631
+ const e = error;
632
+ const statusCode = e.statusCode;
633
+ const message = e.message || "Unknown error";
634
+ const requestId = e.data?.requestId;
635
+ if (statusCode >= 400 && statusCode < 500) {
636
+ throw new ClientError(statusCode, message, { requestId });
637
+ } else if (statusCode >= 500) {
638
+ throw new ServerError(statusCode, message, { requestId });
639
+ }
640
+ }
641
+ throw error;
642
+ }
643
+ };
644
+ /**
645
+ * Get Agent Runtime
646
+ *
647
+ * @param params - Method parameters
648
+ * @param params.agentId - Agent Runtime ID
649
+ * @param params.request - Get request options
650
+ * @param params.headers - Custom request headers
651
+ * @param params.config - Optional config override
652
+ * @returns Runtime object
653
+ */
654
+ getAgentRuntime = async (params) => {
655
+ const { agentId, request, headers, config: config2 } = params;
656
+ try {
657
+ const client = this.getClient(config2);
658
+ const runtime = new $Util__namespace.RuntimeOptions({});
659
+ const response = await client.getAgentRuntimeWithOptions(
660
+ agentId,
661
+ request ?? new $AgentRun3__namespace.GetAgentRuntimeRequest({}),
662
+ headers ?? {},
663
+ runtime
664
+ );
665
+ logger.debug(
666
+ `request api getAgentRuntime, request Request ID: ${response.body?.requestId}
667
+ request: ${JSON.stringify([agentId, request])}
668
+ response: ${JSON.stringify(response.body?.data)}`
669
+ );
670
+ return response.body?.data;
671
+ } catch (error) {
672
+ if (error && typeof error === "object" && "statusCode" in error) {
673
+ const e = error;
674
+ const statusCode = e.statusCode;
675
+ const message = e.message || "Unknown error";
676
+ const requestId = e.data?.requestId;
677
+ if (statusCode >= 400 && statusCode < 500) {
678
+ throw new ClientError(statusCode, message, { requestId });
679
+ } else if (statusCode >= 500) {
680
+ throw new ServerError(statusCode, message, { requestId });
681
+ }
682
+ }
683
+ throw error;
684
+ }
685
+ };
686
+ /**
687
+ * List Agent Runtimes
688
+ *
689
+ * @param params - Method parameters
690
+ * @param params.input - List options
691
+ * @param params.headers - Custom request headers
692
+ * @param params.config - Optional config override
693
+ * @returns List of Runtime objects
694
+ */
695
+ listAgentRuntimes = async (params) => {
696
+ const { input, headers, config: config2 } = params;
697
+ try {
698
+ const client = this.getClient(config2);
699
+ const runtime = new $Util__namespace.RuntimeOptions({});
700
+ const response = await client.listAgentRuntimesWithOptions(input, headers ?? {}, runtime);
701
+ logger.debug(
702
+ `request api listAgentRuntimes, request Request ID: ${response.body?.requestId}
703
+ request: ${JSON.stringify([input])}
704
+ response: ${JSON.stringify(response.body?.data)}`
705
+ );
706
+ return response.body?.data;
707
+ } catch (error) {
708
+ if (error && typeof error === "object" && "statusCode" in error) {
709
+ const e = error;
710
+ const statusCode = e.statusCode;
711
+ const message = e.message || "Unknown error";
712
+ const requestId = e.data?.requestId;
713
+ if (statusCode >= 400 && statusCode < 500) {
714
+ throw new ClientError(statusCode, message, { requestId });
715
+ } else if (statusCode >= 500) {
716
+ throw new ServerError(statusCode, message, { requestId });
717
+ }
718
+ }
719
+ throw error;
720
+ }
721
+ };
722
+ /**
723
+ * Create Agent Runtime Endpoint
724
+ *
725
+ * @param params - Method parameters
726
+ * @param params.agentId - Agent Runtime ID
727
+ * @param params.input - Endpoint configuration
728
+ * @param params.headers - Custom request headers
729
+ * @param params.config - Optional config override
730
+ * @returns Created Endpoint object
731
+ */
732
+ createAgentRuntimeEndpoint = async (params) => {
733
+ const { agentId, input, headers, config: config2 } = params;
734
+ try {
735
+ const client = this.getClient(config2);
736
+ const runtime = new $Util__namespace.RuntimeOptions({});
737
+ const response = await client.createAgentRuntimeEndpointWithOptions(
738
+ agentId,
739
+ new $AgentRun3__namespace.CreateAgentRuntimeEndpointRequest({ body: input }),
740
+ headers ?? {},
741
+ runtime
742
+ );
743
+ logger.debug(
744
+ `request api createAgentRuntimeEndpoint, request Request ID: ${response.body?.requestId}
745
+ request: ${JSON.stringify([agentId, input])}
746
+ response: ${JSON.stringify(response.body?.data)}`
747
+ );
748
+ return response.body?.data;
749
+ } catch (error) {
750
+ if (error && typeof error === "object" && "statusCode" in error) {
751
+ const e = error;
752
+ const statusCode = e.statusCode;
753
+ const message = e.message || "Unknown error";
754
+ const requestId = e.data?.requestId;
755
+ if (statusCode >= 400 && statusCode < 500) {
756
+ throw new ClientError(statusCode, message, { requestId });
757
+ } else if (statusCode >= 500) {
758
+ throw new ServerError(statusCode, message, { requestId });
759
+ }
760
+ }
761
+ throw error;
762
+ }
763
+ };
764
+ /**
765
+ * Delete Agent Runtime Endpoint
766
+ *
767
+ * @param params - Method parameters
768
+ * @param params.agentId - Agent Runtime ID
769
+ * @param params.endpointId - Endpoint ID
770
+ * @param params.headers - Custom request headers
771
+ * @param params.config - Optional config override
772
+ * @returns Deleted Endpoint object
773
+ */
774
+ deleteAgentRuntimeEndpoint = async (params) => {
775
+ const { agentId, endpointId, headers, config: config2 } = params;
776
+ try {
777
+ const client = this.getClient(config2);
778
+ const runtime = new $Util__namespace.RuntimeOptions({});
779
+ const response = await client.deleteAgentRuntimeEndpointWithOptions(
780
+ agentId,
781
+ endpointId,
782
+ headers ?? {},
783
+ runtime
784
+ );
785
+ logger.debug(
786
+ `request api deleteAgentRuntimeEndpoint, request Request ID: ${response.body?.requestId}
787
+ request: ${JSON.stringify([agentId, endpointId])}
788
+ response: ${JSON.stringify(response.body?.data)}`
789
+ );
790
+ return response.body?.data;
791
+ } catch (error) {
792
+ if (error && typeof error === "object" && "statusCode" in error) {
793
+ const e = error;
794
+ const statusCode = e.statusCode;
795
+ const message = e.message || "Unknown error";
796
+ const requestId = e.data?.requestId;
797
+ if (statusCode >= 400 && statusCode < 500) {
798
+ throw new ClientError(statusCode, message, { requestId });
799
+ } else if (statusCode >= 500) {
800
+ throw new ServerError(statusCode, message, { requestId });
801
+ }
802
+ }
803
+ throw error;
804
+ }
805
+ };
806
+ /**
807
+ * Update Agent Runtime Endpoint
808
+ *
809
+ * @param params - Method parameters
810
+ * @param params.agentId - Agent Runtime ID
811
+ * @param params.endpointId - Endpoint ID
812
+ * @param params.input - Endpoint configuration
813
+ * @param params.headers - Custom request headers
814
+ * @param params.config - Optional config override
815
+ * @returns Updated Endpoint object
816
+ */
817
+ updateAgentRuntimeEndpoint = async (params) => {
818
+ const { agentId, endpointId, input, headers, config: config2 } = params;
819
+ try {
820
+ const client = this.getClient(config2);
821
+ const runtime = new $Util__namespace.RuntimeOptions({});
822
+ const response = await client.updateAgentRuntimeEndpointWithOptions(
823
+ agentId,
824
+ endpointId,
825
+ new $AgentRun3__namespace.UpdateAgentRuntimeEndpointRequest({ body: input }),
826
+ headers ?? {},
827
+ runtime
828
+ );
829
+ logger.debug(
830
+ `request api updateAgentRuntimeEndpoint, request Request ID: ${response.body?.requestId}
831
+ request: ${JSON.stringify([agentId, endpointId, input])}
832
+ response: ${JSON.stringify(response.body?.data)}`
833
+ );
834
+ return response.body?.data;
835
+ } catch (error) {
836
+ if (error && typeof error === "object" && "statusCode" in error) {
837
+ const e = error;
838
+ const statusCode = e.statusCode;
839
+ const message = e.message || "Unknown error";
840
+ const requestId = e.data?.requestId;
841
+ if (statusCode >= 400 && statusCode < 500) {
842
+ throw new ClientError(statusCode, message, { requestId });
843
+ } else if (statusCode >= 500) {
844
+ throw new ServerError(statusCode, message, { requestId });
845
+ }
846
+ }
847
+ throw error;
848
+ }
849
+ };
850
+ /**
851
+ * Get Agent Runtime Endpoint
852
+ *
853
+ * @param params - Method parameters
854
+ * @param params.agentId - Agent Runtime ID
855
+ * @param params.endpointId - Endpoint ID
856
+ * @param params.headers - Custom request headers
857
+ * @param params.config - Optional config override
858
+ * @returns Endpoint object
859
+ */
860
+ getAgentRuntimeEndpoint = async (params) => {
861
+ const { agentId, endpointId, headers, config: config2 } = params;
862
+ try {
863
+ const client = this.getClient(config2);
864
+ const runtime = new $Util__namespace.RuntimeOptions({});
865
+ const response = await client.getAgentRuntimeEndpointWithOptions(
866
+ agentId,
867
+ endpointId,
868
+ headers ?? {},
869
+ runtime
870
+ );
871
+ logger.debug(
872
+ `request api getAgentRuntimeEndpoint, request Request ID: ${response.body?.requestId}
873
+ request: ${JSON.stringify([agentId, endpointId])}
874
+ response: ${JSON.stringify(response.body?.data)}`
875
+ );
876
+ return response.body?.data;
877
+ } catch (error) {
878
+ if (error && typeof error === "object" && "statusCode" in error) {
879
+ const e = error;
880
+ const statusCode = e.statusCode;
881
+ const message = e.message || "Unknown error";
882
+ const requestId = e.data?.requestId;
883
+ if (statusCode >= 400 && statusCode < 500) {
884
+ throw new ClientError(statusCode, message, { requestId });
885
+ } else if (statusCode >= 500) {
886
+ throw new ServerError(statusCode, message, { requestId });
887
+ }
888
+ }
889
+ throw error;
890
+ }
891
+ };
892
+ /**
893
+ * List Agent Runtime Endpoints
894
+ *
895
+ * @param params - Method parameters
896
+ * @param params.agentId - Agent Runtime ID
897
+ * @param params.input - List options
898
+ * @param params.headers - Custom request headers
899
+ * @param params.config - Optional config override
900
+ * @returns List of Endpoint objects
901
+ */
902
+ listAgentRuntimeEndpoints = async (params) => {
903
+ const { agentId, input, headers, config: config2 } = params;
904
+ try {
905
+ const client = this.getClient(config2);
906
+ const runtime = new $Util__namespace.RuntimeOptions({});
907
+ const response = await client.listAgentRuntimeEndpointsWithOptions(
908
+ agentId,
909
+ input,
910
+ headers ?? {},
911
+ runtime
912
+ );
913
+ logger.debug(
914
+ `request api listAgentRuntimeEndpoints, request Request ID: ${response.body?.requestId}
915
+ request: ${JSON.stringify([agentId, input])}
916
+ response: ${JSON.stringify(response.body?.data)}`
917
+ );
918
+ return response.body?.data;
919
+ } catch (error) {
920
+ if (error && typeof error === "object" && "statusCode" in error) {
921
+ const e = error;
922
+ const statusCode = e.statusCode;
923
+ const message = e.message || "Unknown error";
924
+ const requestId = e.data?.requestId;
925
+ if (statusCode >= 400 && statusCode < 500) {
926
+ throw new ClientError(statusCode, message, { requestId });
927
+ } else if (statusCode >= 500) {
928
+ throw new ServerError(statusCode, message, { requestId });
929
+ }
930
+ }
931
+ throw error;
932
+ }
933
+ };
934
+ /**
935
+ * List Agent Runtime Versions
936
+ *
937
+ * @param params - Method parameters
938
+ * @param params.agentId - Agent Runtime ID
939
+ * @param params.input - List options
940
+ * @param params.headers - Custom request headers
941
+ * @param params.config - Optional config override
942
+ * @returns List of Version objects
943
+ */
944
+ listAgentRuntimeVersions = async (params) => {
945
+ const { agentId, input, headers, config: config2 } = params;
946
+ try {
947
+ const client = this.getClient(config2);
948
+ const runtime = new $Util__namespace.RuntimeOptions({});
949
+ const response = await client.listAgentRuntimeVersionsWithOptions(
950
+ agentId,
951
+ input,
952
+ headers ?? {},
953
+ runtime
954
+ );
955
+ logger.debug(
956
+ `request api listAgentRuntimeVersions, request Request ID: ${response.body?.requestId}
957
+ request: ${JSON.stringify([agentId, input])}
958
+ response: ${JSON.stringify(response.body?.data)}`
959
+ );
960
+ return response.body?.data;
961
+ } catch (error) {
962
+ if (error && typeof error === "object" && "statusCode" in error) {
963
+ const e = error;
964
+ const statusCode = e.statusCode;
965
+ const message = e.message || "Unknown error";
966
+ const requestId = e.data?.requestId;
967
+ if (statusCode >= 400 && statusCode < 500) {
968
+ throw new ClientError(statusCode, message, { requestId });
969
+ } else if (statusCode >= 500) {
970
+ throw new ServerError(statusCode, message, { requestId });
971
+ }
972
+ }
973
+ throw error;
974
+ }
975
+ };
976
+ };
977
+ }
978
+ });
979
+ var DataAPI;
980
+ var init_data_api = __esm({
981
+ "src/utils/data-api.ts"() {
982
+ init_config();
983
+ init_exception();
984
+ init_log();
985
+ DataAPI = class {
986
+ resourceName;
987
+ resourceType;
988
+ accessToken = null;
989
+ config;
990
+ namespace;
991
+ /**
992
+ * Initialize the Data API Client.
993
+ *
994
+ * @param resourceName - Resource name for access token
995
+ * @param resourceType - Resource type for access token
996
+ * @param config - Configuration options
997
+ * @param namespace - API namespace (default: "agents")
998
+ */
999
+ constructor(resourceName, resourceType, config2, namespace = "agents") {
1000
+ this.resourceName = resourceName;
1001
+ this.resourceType = resourceType;
1002
+ this.config = Config.withConfigs(config2);
1003
+ this.namespace = namespace;
1004
+ const token = this.config.token;
1005
+ if (token) {
1006
+ logger.debug(`Using provided access token from config`);
1007
+ this.accessToken = token;
1008
+ }
1009
+ }
1010
+ /**
1011
+ * Get the base URL for API requests.
1012
+ */
1013
+ getBaseUrl() {
1014
+ return this.config.dataEndpoint;
1015
+ }
1016
+ /**
1017
+ * Construct full URL with the given path and query parameters.
1018
+ *
1019
+ * @param path - API path (may include query string)
1020
+ * @param query - Query parameters to add/merge
1021
+ * @returns Complete URL string with query parameters
1022
+ */
1023
+ withPath(path2, query) {
1024
+ path2 = path2.replace(/^\//, "");
1025
+ const parts = [this.getBaseUrl(), this.namespace, path2].filter(Boolean).map((part) => part.replace(/^\/|\/$/g, ""));
1026
+ const baseUrl = parts.join("/");
1027
+ if (!query || Object.keys(query).length === 0) {
1028
+ return baseUrl;
1029
+ }
1030
+ const urlObj = new url.URL(baseUrl);
1031
+ const existingParams = urlObj.searchParams;
1032
+ for (const key in query) {
1033
+ if (Object.prototype.hasOwnProperty.call(query, key)) {
1034
+ const value = query[key];
1035
+ if (Array.isArray(value)) {
1036
+ value.forEach((v) => existingParams.append(key, String(v)));
1037
+ } else if (value !== void 0 && value !== null) {
1038
+ existingParams.set(key, String(value));
1039
+ }
1040
+ }
1041
+ }
1042
+ urlObj.search = existingParams.toString();
1043
+ return urlObj.toString();
1044
+ }
1045
+ /**
1046
+ * Authenticate and prepare headers for the request.
1047
+ *
1048
+ * @param url - Request URL
1049
+ * @param headers - Request headers
1050
+ * @param query - Query parameters
1051
+ * @param config - Optional config override
1052
+ * @returns Tuple of [url, headers, query]
1053
+ */
1054
+ async auth(url, headers, query, config2) {
1055
+ const cfg = Config.withConfigs(this.config, config2);
1056
+ if (this.accessToken === null && this.resourceName && this.resourceType && !cfg.token) {
1057
+ try {
1058
+ const { ControlAPI: ControlAPI2 } = await Promise.resolve().then(() => (init_control_api(), control_api_exports));
1059
+ const $AgentRun4 = await import('@alicloud/agentrun20250910');
1060
+ const cli = new ControlAPI2(this.config).getClient();
1061
+ const input = this.resourceType === "sandbox" /* Sandbox */ ? new $AgentRun4.GetAccessTokenRequest({
1062
+ resourceId: this.resourceName,
1063
+ resourceType: this.resourceType
1064
+ }) : new $AgentRun4.GetAccessTokenRequest({
1065
+ resourceName: this.resourceName,
1066
+ resourceType: this.resourceType
1067
+ });
1068
+ const resp = await cli.getAccessToken(input);
1069
+ this.accessToken = resp.body?.data?.accessToken || null;
1070
+ logger.debug(
1071
+ `Fetched access token for resource ${this.resourceName} of type ${this.resourceType}`
1072
+ );
1073
+ } catch (e) {
1074
+ logger.warn(
1075
+ `Failed to get access token for ${this.resourceType}(${this.resourceName}): ${e}`
1076
+ );
1077
+ }
1078
+ }
1079
+ const authHeaders = {
1080
+ "Agentrun-Access-Token": cfg.token || this.accessToken || "",
1081
+ ...cfg.headers,
1082
+ ...headers
1083
+ };
1084
+ return [url, authHeaders, query];
1085
+ }
1086
+ /**
1087
+ * Prepare the HTTP request.
1088
+ */
1089
+ async prepareRequest(method, url$1, data, headers, query, config2) {
1090
+ const reqHeaders = {
1091
+ "Content-Type": "application/json",
1092
+ "User-Agent": "AgentRunDataClient/1.0"
1093
+ };
1094
+ const cfg = Config.withConfigs(this.config, config2);
1095
+ Object.assign(reqHeaders, cfg.headers);
1096
+ if (headers) {
1097
+ Object.assign(reqHeaders, headers);
1098
+ }
1099
+ const [authUrl, authHeaders, authQuery] = await this.auth(url$1, reqHeaders, query, cfg);
1100
+ let finalUrl = authUrl;
1101
+ if (authQuery && Object.keys(authQuery).length > 0) {
1102
+ const urlObj = new url.URL(authUrl);
1103
+ for (const key in authQuery) {
1104
+ if (Object.prototype.hasOwnProperty.call(authQuery, key)) {
1105
+ const value = authQuery[key];
1106
+ if (value !== void 0 && value !== null) {
1107
+ urlObj.searchParams.set(key, String(value));
1108
+ }
1109
+ }
1110
+ }
1111
+ finalUrl = urlObj.toString();
1112
+ }
1113
+ let body;
1114
+ if (data !== void 0) {
1115
+ if (Buffer.isBuffer(data)) {
1116
+ body = data;
1117
+ } else if (typeof data === "object") {
1118
+ body = JSON.stringify(data);
1119
+ } else {
1120
+ body = data;
1121
+ }
1122
+ }
1123
+ logger.debug(`${method} ${finalUrl} headers=${JSON.stringify(authHeaders)}`);
1124
+ return { method, url: finalUrl, headers: authHeaders, body };
1125
+ }
1126
+ /**
1127
+ * Make an HTTP request.
1128
+ */
1129
+ async makeRequest(method, path2, data, query, headers, config2) {
1130
+ const fullUrl = this.withPath(path2, query);
1131
+ const {
1132
+ method: reqMethod,
1133
+ url: reqUrl,
1134
+ headers: reqHeaders,
1135
+ body: reqBody
1136
+ } = await this.prepareRequest(method, fullUrl, data, headers, void 0, config2);
1137
+ const client = reqUrl.startsWith("https") ? https__namespace : http__namespace;
1138
+ const urlObj = new url.URL(reqUrl);
1139
+ const options = {
1140
+ hostname: urlObj.hostname,
1141
+ port: urlObj.port || (reqUrl.startsWith("https") ? 443 : 80),
1142
+ path: urlObj.pathname + urlObj.search,
1143
+ method: reqMethod,
1144
+ headers: reqHeaders,
1145
+ timeout: this.config.timeout
1146
+ };
1147
+ return new Promise((resolve, reject) => {
1148
+ const req = client.request(options, (res) => {
1149
+ let responseData = "";
1150
+ res.on("data", (chunk) => responseData += chunk);
1151
+ res.on("end", () => {
1152
+ logger.debug(`Response: ${responseData}`);
1153
+ if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
1154
+ try {
1155
+ resolve(responseData ? JSON.parse(responseData) : {});
1156
+ } catch (e) {
1157
+ const errorMsg = `Failed to parse JSON response: ${e}`;
1158
+ logger.error(errorMsg);
1159
+ reject(new ClientError(res.statusCode || 0, errorMsg));
1160
+ }
1161
+ } else {
1162
+ const errorMsg = responseData || res.statusMessage || "Unknown error";
1163
+ reject(new ClientError(res.statusCode || 0, errorMsg));
1164
+ }
1165
+ });
1166
+ });
1167
+ req.on("error", (e) => {
1168
+ reject(new ClientError(0, `Request error: ${e.message}`));
1169
+ });
1170
+ req.on("timeout", () => {
1171
+ req.destroy();
1172
+ reject(new ClientError(0, "Request timeout"));
1173
+ });
1174
+ if (reqBody) {
1175
+ req.write(reqBody);
1176
+ }
1177
+ req.end();
1178
+ });
1179
+ }
1180
+ /**
1181
+ * Make a GET request.
1182
+ *
1183
+ * @param path - API path
1184
+ * @param query - Query parameters
1185
+ * @param headers - Additional headers
1186
+ * @param config - Optional config override
1187
+ */
1188
+ async get(path2, query, headers, config2) {
1189
+ return this.makeRequest("GET", path2, void 0, query, headers, config2);
1190
+ }
1191
+ /**
1192
+ * Make a POST request.
1193
+ *
1194
+ * @param path - API path
1195
+ * @param data - Request body
1196
+ * @param query - Query parameters
1197
+ * @param headers - Additional headers
1198
+ * @param config - Optional config override
1199
+ */
1200
+ async post(path2, data, query, headers, config2) {
1201
+ return this.makeRequest("POST", path2, data, query, headers, config2);
1202
+ }
1203
+ /**
1204
+ * Make a PUT request.
1205
+ *
1206
+ * @param path - API path
1207
+ * @param data - Request body
1208
+ * @param query - Query parameters
1209
+ * @param headers - Additional headers
1210
+ * @param config - Optional config override
1211
+ */
1212
+ async put(path2, data, query, headers, config2) {
1213
+ return this.makeRequest("PUT", path2, data, query, headers, config2);
1214
+ }
1215
+ /**
1216
+ * Make a PATCH request.
1217
+ *
1218
+ * @param path - API path
1219
+ * @param data - Request body
1220
+ * @param query - Query parameters
1221
+ * @param headers - Additional headers
1222
+ * @param config - Optional config override
1223
+ */
1224
+ async patch(path2, data, query, headers, config2) {
1225
+ return this.makeRequest("PATCH", path2, data, query, headers, config2);
1226
+ }
1227
+ /**
1228
+ * Make a DELETE request.
1229
+ *
1230
+ * @param path - API path
1231
+ * @param query - Query parameters
1232
+ * @param headers - Additional headers
1233
+ * @param config - Optional config override
1234
+ */
1235
+ async delete(path2, query, headers, config2) {
1236
+ return this.makeRequest("DELETE", path2, void 0, query, headers, config2);
1237
+ }
1238
+ /**
1239
+ * Upload a file using multipart/form-data.
1240
+ *
1241
+ * @param path - API path
1242
+ * @param localFilePath - Local file path to upload
1243
+ * @param targetFilePath - Target file path on the server
1244
+ * @param formData - Additional form data fields
1245
+ * @param query - Query parameters
1246
+ * @param headers - Additional headers
1247
+ * @param config - Optional config override
1248
+ */
1249
+ async postFile(path2, localFilePath, targetFilePath, formData, query, headers, config2) {
1250
+ const fullUrl = this.withPath(path2, query);
1251
+ const { url: reqUrl, headers: reqHeaders } = await this.prepareRequest(
1252
+ "POST",
1253
+ fullUrl,
1254
+ void 0,
1255
+ headers,
1256
+ void 0,
1257
+ config2
1258
+ );
1259
+ const client = reqUrl.startsWith("https") ? https__namespace : http__namespace;
1260
+ const urlObj = new url.URL(reqUrl);
1261
+ return new Promise((resolve, reject) => {
1262
+ const boundary = `----WebKitFormBoundary${Math.random().toString(36).substring(2)}`;
1263
+ const contentHeaders = {
1264
+ ...reqHeaders,
1265
+ "Content-Type": `multipart/form-data; boundary=${boundary}`
1266
+ };
1267
+ const options = {
1268
+ hostname: urlObj.hostname,
1269
+ port: urlObj.port || (reqUrl.startsWith("https") ? 443 : 80),
1270
+ path: urlObj.pathname + urlObj.search,
1271
+ method: "POST",
1272
+ headers: contentHeaders,
1273
+ timeout: this.config.timeout
1274
+ };
1275
+ const req = client.request(options, (res) => {
1276
+ let responseData = "";
1277
+ res.on("data", (chunk) => responseData += chunk);
1278
+ res.on("end", () => {
1279
+ if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
1280
+ try {
1281
+ resolve(responseData ? JSON.parse(responseData) : {});
1282
+ } catch (e) {
1283
+ logger.error(`Failed to parse JSON response: ${e}`);
1284
+ reject(new ClientError(res.statusCode || 0, `Failed to parse JSON: ${e}`));
1285
+ }
1286
+ } else {
1287
+ reject(new ClientError(res.statusCode || 0, responseData || "Unknown error"));
1288
+ }
1289
+ });
1290
+ });
1291
+ req.on("error", (e) => {
1292
+ reject(new ClientError(0, `Request error: ${e.message}`));
1293
+ });
1294
+ const appendField = (name, value) => {
1295
+ req.write(`--${boundary}\r
1296
+ `);
1297
+ req.write(`Content-Disposition: form-data; name="${name}"\r
1298
+ `);
1299
+ req.write("\r\n");
1300
+ req.write(`${value}\r
1301
+ `);
1302
+ };
1303
+ if (formData) {
1304
+ for (const key in formData) {
1305
+ if (Object.prototype.hasOwnProperty.call(formData, key)) {
1306
+ appendField(key, formData[key]);
1307
+ }
1308
+ }
1309
+ }
1310
+ appendField("path", targetFilePath);
1311
+ const filename = path__namespace.basename(localFilePath);
1312
+ req.write(`--${boundary}\r
1313
+ `);
1314
+ req.write(`Content-Disposition: form-data; name="file"; filename="${filename}"\r
1315
+ `);
1316
+ req.write("Content-Type: application/octet-stream\r\n");
1317
+ req.write("\r\n");
1318
+ const fileStream = fs2__namespace.createReadStream(localFilePath);
1319
+ fileStream.pipe(req, { end: false });
1320
+ fileStream.on("end", () => {
1321
+ req.write(`\r
1322
+ --${boundary}--\r
1323
+ `);
1324
+ req.end();
1325
+ });
1326
+ fileStream.on("error", (e) => {
1327
+ reject(new ClientError(0, `File stream error: ${e.message}`));
1328
+ });
1329
+ });
1330
+ }
1331
+ /**
1332
+ * Download a file and save it to local path.
1333
+ *
1334
+ * @param path - API path
1335
+ * @param savePath - Local file path to save the downloaded file
1336
+ * @param query - Query parameters
1337
+ * @param headers - Additional headers
1338
+ * @param config - Optional config override
1339
+ */
1340
+ async getFile(path2, savePath, query, headers, config2) {
1341
+ const fullUrl = this.withPath(path2, query);
1342
+ const { url: reqUrl, headers: reqHeaders } = await this.prepareRequest(
1343
+ "GET",
1344
+ fullUrl,
1345
+ void 0,
1346
+ headers,
1347
+ void 0,
1348
+ config2
1349
+ );
1350
+ const client = reqUrl.startsWith("https") ? https__namespace : http__namespace;
1351
+ const urlObj = new url.URL(reqUrl);
1352
+ return new Promise((resolve, reject) => {
1353
+ const options = {
1354
+ hostname: urlObj.hostname,
1355
+ port: urlObj.port || (reqUrl.startsWith("https") ? 443 : 80),
1356
+ path: urlObj.pathname + urlObj.search,
1357
+ method: "GET",
1358
+ headers: reqHeaders,
1359
+ timeout: this.config.timeout
1360
+ };
1361
+ const req = client.request(options, (res) => {
1362
+ if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
1363
+ const fileStream = fs2__namespace.createWriteStream(savePath);
1364
+ let downloadedSize = 0;
1365
+ res.on("data", (chunk) => {
1366
+ fileStream.write(chunk);
1367
+ downloadedSize += chunk.length;
1368
+ });
1369
+ res.on("end", () => {
1370
+ fileStream.end();
1371
+ resolve({ savedPath: savePath, size: downloadedSize });
1372
+ });
1373
+ res.on("error", (e) => {
1374
+ fileStream.end();
1375
+ reject(new ClientError(0, `Response error: ${e.message}`));
1376
+ });
1377
+ } else {
1378
+ let errorData = "";
1379
+ res.on("data", (chunk) => errorData += chunk);
1380
+ res.on("end", () => {
1381
+ reject(new ClientError(res.statusCode || 0, errorData || "Download failed"));
1382
+ });
1383
+ }
1384
+ });
1385
+ req.on("error", (e) => {
1386
+ reject(new ClientError(0, `Request error: ${e.message}`));
1387
+ });
1388
+ req.end();
1389
+ });
1390
+ }
1391
+ /**
1392
+ * Download a video file and save it to local path.
1393
+ *
1394
+ * @param path - API path
1395
+ * @param savePath - Local file path to save the downloaded video
1396
+ * @param query - Query parameters
1397
+ * @param headers - Additional headers
1398
+ * @param config - Optional config override
1399
+ */
1400
+ async getVideo(path2, savePath, query, headers, config2) {
1401
+ return this.getFile(path2, savePath, query, headers, config2);
1402
+ }
1403
+ };
1404
+ }
1405
+ });
1406
+
1407
+ // src/agent-runtime/api/data.ts
1408
+ exports.AgentRuntimeDataAPI = void 0;
1409
+ var init_data = __esm({
1410
+ "src/agent-runtime/api/data.ts"() {
1411
+ init_config();
1412
+ init_data_api();
1413
+ exports.AgentRuntimeDataAPI = class extends DataAPI {
1414
+ constructor(agentRuntimeName, agentRuntimeEndpointName = "Default", config2) {
1415
+ super(
1416
+ agentRuntimeName,
1417
+ "runtime" /* Runtime */,
1418
+ config2,
1419
+ `agent-runtimes/${agentRuntimeName}/endpoints/${agentRuntimeEndpointName}/invocations`
1420
+ );
1421
+ }
1422
+ /**
1423
+ * Invoke agent runtime using OpenAI-compatible API
1424
+ */
1425
+ async invokeOpenai(args) {
1426
+ const { messages, stream = false, config: config2 } = args;
1427
+ const cfg = Config.withConfigs(this.getConfig(), config2);
1428
+ const apiBase = this.withPath("openai/v1");
1429
+ const [, headers] = await this.getAuthHeaders(apiBase, {}, cfg);
1430
+ const { default: OpenAI } = await import('openai');
1431
+ const client = new OpenAI({
1432
+ apiKey: "",
1433
+ // Empty API key, we use custom headers for auth
1434
+ baseURL: apiBase,
1435
+ defaultHeaders: headers,
1436
+ timeout: cfg.timeout
1437
+ });
1438
+ return client.chat.completions.create({
1439
+ model: this.getResourceName(),
1440
+ messages,
1441
+ stream
1442
+ });
1443
+ }
1444
+ // Expose protected methods for use in this subclass
1445
+ getConfig() {
1446
+ return this.config;
1447
+ }
1448
+ getResourceName() {
1449
+ return this.resourceName;
1450
+ }
1451
+ async getAuthHeaders(url, headers, config2) {
1452
+ const [authUrl, authHeaders] = await this.auth(url, headers, void 0, config2);
1453
+ return [authUrl, authHeaders];
1454
+ }
1455
+ };
1456
+ }
1457
+ });
1458
+
1459
+ // src/utils/resource.ts
1460
+ function updateObjectProperties(target, source) {
1461
+ for (const key in source) {
1462
+ if (Object.prototype.hasOwnProperty.call(source, key) && typeof source[key] !== "function" && !key.startsWith("_")) {
1463
+ target[key] = source[key];
1464
+ }
1465
+ }
1466
+ }
1467
+ function listAllResourcesFunction(list) {
1468
+ return async (params) => {
1469
+ const { config: config2, ...restParams } = params ?? {};
1470
+ const allResults = [];
1471
+ let page = 1;
1472
+ const pageSize = 50;
1473
+ while (true) {
1474
+ const pageResults = await list({
1475
+ input: {
1476
+ ...restParams,
1477
+ pageNumber: page,
1478
+ pageSize
1479
+ },
1480
+ config: config2
1481
+ });
1482
+ page += 1;
1483
+ allResults.push(...pageResults);
1484
+ if (pageResults.length < pageSize) break;
1485
+ }
1486
+ const resultSet = /* @__PURE__ */ new Set();
1487
+ const results = [];
1488
+ for (const item of allResults) {
1489
+ const uniqId = item.uniqIdCallback() || "";
1490
+ if (!resultSet.has(uniqId) && uniqId) {
1491
+ resultSet.add(uniqId);
1492
+ results.push(item);
1493
+ }
1494
+ }
1495
+ return results;
1496
+ };
1497
+ }
1498
+ var ResourceBase;
1499
+ var init_resource = __esm({
1500
+ "src/utils/resource.ts"() {
1501
+ init_exception();
1502
+ init_log();
1503
+ init_model();
1504
+ ResourceBase = class {
1505
+ status;
1506
+ _config;
1507
+ // static async list(params?: {
1508
+ // input?: PageableInput;
1509
+ // config?: Config;
1510
+ // }): Promise<WithUniqIdCallback[]> {
1511
+ // return [];
1512
+ // }
1513
+ waitUntil = async (params) => {
1514
+ const { checkFinishedCallback, intervalSeconds = 5, timeoutSeconds = 300 } = params;
1515
+ const startTime = Date.now();
1516
+ while (true) {
1517
+ if (await checkFinishedCallback(this)) return this;
1518
+ if (Date.now() - startTime >= timeoutSeconds * 1e3) {
1519
+ throw new Error("Timeout waiting for resource to reach desired state");
1520
+ }
1521
+ await new Promise((resolve) => setTimeout(resolve, intervalSeconds * 1e3));
1522
+ }
1523
+ };
1524
+ waitUntilReadyOrFailed = async (params) => {
1525
+ const { callback, intervalSeconds = 5, timeoutSeconds = 300 } = params ?? {};
1526
+ async function checkFinishedCallback(resource) {
1527
+ await resource.refresh();
1528
+ if (callback) await callback(resource);
1529
+ logger.debug(`Resource status: ${resource.status}`);
1530
+ return isFinalStatus(resource.status);
1531
+ }
1532
+ return await this.waitUntil({
1533
+ checkFinishedCallback,
1534
+ intervalSeconds,
1535
+ timeoutSeconds
1536
+ });
1537
+ };
1538
+ deleteAndWaitUntilFinished = async (params) => {
1539
+ const { callback, intervalSeconds = 5, timeoutSeconds = 300 } = params ?? {};
1540
+ try {
1541
+ await this.delete();
1542
+ } catch (error) {
1543
+ if (error instanceof ResourceNotExistError) return;
1544
+ }
1545
+ async function checkFinishedCallback(resource) {
1546
+ try {
1547
+ await resource.refresh();
1548
+ if (callback) await callback(resource);
1549
+ } catch (error) {
1550
+ if (error instanceof ResourceNotExistError) return true;
1551
+ if (resource.status === Status.DELETING) return false;
1552
+ throw Error(`Resource status is ${resource.status}`);
1553
+ }
1554
+ return false;
1555
+ }
1556
+ return await this.waitUntil({
1557
+ checkFinishedCallback,
1558
+ intervalSeconds,
1559
+ timeoutSeconds
1560
+ });
1561
+ };
1562
+ refresh = async (params) => await this.get(params);
1563
+ /**
1564
+ * 更新实例自身的属性 / Update instance properties
1565
+ *
1566
+ * @param source - 源对象 / Source object
1567
+ */
1568
+ updateSelf(source) {
1569
+ updateObjectProperties(this, source);
1570
+ }
1571
+ setConfig = (config2) => {
1572
+ this._config = config2;
1573
+ return this;
1574
+ };
1575
+ };
1576
+ }
1577
+ });
1578
+
1579
+ // src/agent-runtime/endpoint.ts
1580
+ exports.AgentRuntimeEndpoint = void 0;
1581
+ var init_endpoint = __esm({
1582
+ "src/agent-runtime/endpoint.ts"() {
1583
+ init_config();
1584
+ init_resource();
1585
+ init_data();
1586
+ exports.AgentRuntimeEndpoint = class _AgentRuntimeEndpoint extends ResourceBase {
1587
+ // System properties
1588
+ agentRuntimeEndpointArn;
1589
+ agentRuntimeEndpointId;
1590
+ agentRuntimeEndpointName;
1591
+ agentRuntimeId;
1592
+ description;
1593
+ endpointPublicUrl;
1594
+ resourceName;
1595
+ routingConfiguration;
1596
+ statusReason;
1597
+ tags;
1598
+ targetVersion;
1599
+ _config;
1600
+ _dataApi;
1601
+ _agentRuntimeName;
1602
+ constructor(data, config2) {
1603
+ super();
1604
+ if (data) {
1605
+ updateObjectProperties(this, data);
1606
+ }
1607
+ this._config = config2;
1608
+ }
1609
+ uniqIdCallback = () => this.agentRuntimeEndpointId;
1610
+ static getClient() {
1611
+ const { AgentRuntimeClient: AgentRuntimeClient2 } = (init_client(), __toCommonJS(client_exports));
1612
+ return new AgentRuntimeClient2();
1613
+ }
1614
+ /**
1615
+ * Create an endpoint by Agent Runtime ID
1616
+ */
1617
+ static async create(params) {
1618
+ const { agentRuntimeId, input, config: config2 } = params;
1619
+ return await _AgentRuntimeEndpoint.getClient().createEndpoint({
1620
+ agentRuntimeId,
1621
+ input,
1622
+ config: config2
1623
+ });
1624
+ }
1625
+ /**
1626
+ * Delete an endpoint by ID
1627
+ */
1628
+ static async delete(params) {
1629
+ const { agentRuntimeId, endpointId, config: config2 } = params;
1630
+ return await _AgentRuntimeEndpoint.getClient().deleteEndpoint({
1631
+ agentRuntimeId,
1632
+ endpointId,
1633
+ config: config2
1634
+ });
1635
+ }
1636
+ /**
1637
+ * Update an endpoint by ID
1638
+ */
1639
+ static async update(params) {
1640
+ const { agentRuntimeId, endpointId, input, config: config2 } = params;
1641
+ return await _AgentRuntimeEndpoint.getClient().updateEndpoint({
1642
+ agentRuntimeId,
1643
+ endpointId,
1644
+ input,
1645
+ config: config2
1646
+ });
1647
+ }
1648
+ /**
1649
+ * Get an endpoint by ID
1650
+ */
1651
+ static async get(params) {
1652
+ const { agentRuntimeId, endpointId, config: config2 } = params;
1653
+ return await _AgentRuntimeEndpoint.getClient().getEndpoint({
1654
+ agentRuntimeId,
1655
+ endpointId,
1656
+ config: config2
1657
+ });
1658
+ }
1659
+ /**
1660
+ * List endpoints by Agent Runtime ID
1661
+ */
1662
+ static async list(params) {
1663
+ const { agentRuntimeId, input, config: config2 } = params;
1664
+ return await _AgentRuntimeEndpoint.getClient().listEndpoints({
1665
+ agentRuntimeId,
1666
+ input,
1667
+ config: config2
1668
+ });
1669
+ }
1670
+ static listAll = async (params) => {
1671
+ const { agentRuntimeId, ...restParams } = params;
1672
+ return await listAllResourcesFunction(
1673
+ (params2) => this.list({ ...params2, agentRuntimeId })
1674
+ )(restParams);
1675
+ };
1676
+ get = async (params) => {
1677
+ return await _AgentRuntimeEndpoint.get({
1678
+ agentRuntimeId: this.agentRuntimeId,
1679
+ endpointId: this.agentRuntimeEndpointId,
1680
+ config: params?.config
1681
+ });
1682
+ };
1683
+ /**
1684
+ * Delete this endpoint
1685
+ */
1686
+ delete = async (params) => {
1687
+ const config2 = params?.config;
1688
+ if (!this.agentRuntimeId || !this.agentRuntimeEndpointId) {
1689
+ throw new Error(
1690
+ "agentRuntimeId and agentRuntimeEndpointId are required to delete an endpoint"
1691
+ );
1692
+ }
1693
+ const result = await _AgentRuntimeEndpoint.delete({
1694
+ agentRuntimeId: this.agentRuntimeId,
1695
+ endpointId: this.agentRuntimeEndpointId,
1696
+ config: config2 ?? this._config
1697
+ });
1698
+ updateObjectProperties(this, result);
1699
+ return this;
1700
+ };
1701
+ /**
1702
+ * Update this endpoint
1703
+ */
1704
+ update = async (params) => {
1705
+ const { input, config: config2 } = params;
1706
+ if (!this.agentRuntimeId || !this.agentRuntimeEndpointId) {
1707
+ throw new Error(
1708
+ "agentRuntimeId and agentRuntimeEndpointId are required to update an endpoint"
1709
+ );
1710
+ }
1711
+ const result = await _AgentRuntimeEndpoint.update({
1712
+ agentRuntimeId: this.agentRuntimeId,
1713
+ endpointId: this.agentRuntimeEndpointId,
1714
+ input,
1715
+ config: config2 ?? this._config
1716
+ });
1717
+ updateObjectProperties(this, result);
1718
+ return this;
1719
+ };
1720
+ /**
1721
+ * Refresh this endpoint's data
1722
+ */
1723
+ refresh = async (params) => {
1724
+ const config2 = params?.config;
1725
+ if (!this.agentRuntimeId || !this.agentRuntimeEndpointId) {
1726
+ throw new Error(
1727
+ "agentRuntimeId and agentRuntimeEndpointId are required to refresh an endpoint"
1728
+ );
1729
+ }
1730
+ const result = await _AgentRuntimeEndpoint.get({
1731
+ agentRuntimeId: this.agentRuntimeId,
1732
+ endpointId: this.agentRuntimeEndpointId,
1733
+ config: config2 ?? this._config
1734
+ });
1735
+ updateObjectProperties(this, result);
1736
+ return this;
1737
+ };
1738
+ /**
1739
+ * Invoke agent runtime using OpenAI-compatible API through this endpoint
1740
+ *
1741
+ * This method provides an OpenAI-compatible interface to invoke the agent runtime
1742
+ * through this specific endpoint.
1743
+ *
1744
+ * @param args - Invocation arguments
1745
+ * @returns OpenAI chat completion response
1746
+ *
1747
+ * @example
1748
+ * ```typescript
1749
+ * const endpoint = await AgentRuntimeEndpoint.get({
1750
+ * agentRuntimeId: "runtime-id",
1751
+ * endpointId: "endpoint-id"
1752
+ * });
1753
+ * const response = await endpoint.invokeOpenai({
1754
+ * messages: [{ role: "user", content: "Hello" }],
1755
+ * stream: false
1756
+ * });
1757
+ * ```
1758
+ */
1759
+ invokeOpenai = async (args) => {
1760
+ const { messages, stream, config: config2 } = args;
1761
+ const cfg = Config.withConfigs(this._config, config2);
1762
+ if (!this._dataApi) {
1763
+ if (!this._agentRuntimeName && this.agentRuntimeId) {
1764
+ const client = _AgentRuntimeEndpoint.getClient();
1765
+ const runtime = await client.get({
1766
+ id: this.agentRuntimeId,
1767
+ config: cfg
1768
+ });
1769
+ this._agentRuntimeName = runtime.agentRuntimeName;
1770
+ }
1771
+ if (!this._agentRuntimeName) {
1772
+ throw new Error("Unable to determine agent runtime name for this endpoint");
1773
+ }
1774
+ this._dataApi = new exports.AgentRuntimeDataAPI(
1775
+ this._agentRuntimeName,
1776
+ this.agentRuntimeEndpointName || "",
1777
+ cfg
1778
+ );
1779
+ }
1780
+ return this._dataApi.invokeOpenai({
1781
+ messages,
1782
+ stream,
1783
+ config: cfg
1784
+ });
1785
+ };
1786
+ };
1787
+ }
1788
+ });
1789
+ async function codeFromZipFile(language, command, zipFilePath) {
1790
+ const data = await fs2__namespace.promises.readFile(zipFilePath);
1791
+ const checksum = crc64Lib__namespace.crc64(data);
1792
+ return {
1793
+ language,
1794
+ command,
1795
+ zipFile: data.toString("base64"),
1796
+ checksum
1797
+ };
1798
+ }
1799
+ function codeFromOss(language, command, bucket, object) {
1800
+ return {
1801
+ language,
1802
+ command,
1803
+ ossBucketName: bucket,
1804
+ ossObjectName: object
1805
+ };
1806
+ }
1807
+ async function codeFromFile(language, command, filePath) {
1808
+ const archiver = await import('archiver').catch(() => null);
1809
+ if (!archiver) {
1810
+ throw new Error(
1811
+ "archiver package is required for codeFromFile. Install it with: npm install archiver"
1812
+ );
1813
+ }
1814
+ const stats = await fs2__namespace.promises.stat(filePath);
1815
+ const zipFilePath = path__namespace.join(path__namespace.dirname(filePath), `${Date.now()}.zip`);
1816
+ const output = fs2__namespace.createWriteStream(zipFilePath);
1817
+ const archive = archiver.default("zip", { zlib: { level: 9 } });
1818
+ await new Promise((resolve, reject) => {
1819
+ output.on("close", resolve);
1820
+ archive.on("error", reject);
1821
+ archive.pipe(output);
1822
+ if (stats.isDirectory()) {
1823
+ archive.directory(filePath, false);
1824
+ } else {
1825
+ archive.file(filePath, { name: path__namespace.basename(filePath) });
1826
+ }
1827
+ archive.finalize();
1828
+ });
1829
+ const code = await codeFromZipFile(language, command, zipFilePath);
1830
+ await fs2__namespace.promises.unlink(zipFilePath);
1831
+ return code;
1832
+ }
1833
+ exports.AgentRuntimeArtifact = void 0; exports.AgentRuntimeLanguage = void 0; exports.AgentRuntimeProtocolType = void 0;
1834
+ var init_model2 = __esm({
1835
+ "src/agent-runtime/model.ts"() {
1836
+ init_model();
1837
+ exports.AgentRuntimeArtifact = {
1838
+ CODE: "Code",
1839
+ CONTAINER: "Container"
1840
+ };
1841
+ exports.AgentRuntimeLanguage = {
1842
+ PYTHON310: "python3.10",
1843
+ PYTHON312: "python3.12",
1844
+ NODEJS18: "nodejs18",
1845
+ NODEJS20: "nodejs20",
1846
+ JAVA8: "java8",
1847
+ JAVA11: "java11"
1848
+ };
1849
+ exports.AgentRuntimeProtocolType = {
1850
+ HTTP: "HTTP",
1851
+ MCP: "MCP"
1852
+ };
1853
+ }
1854
+ });
1855
+
1856
+ // src/agent-runtime/runtime.ts
1857
+ exports.AgentRuntime = void 0;
1858
+ var init_runtime = __esm({
1859
+ "src/agent-runtime/runtime.ts"() {
1860
+ init_config();
1861
+ init_resource();
1862
+ init_data();
1863
+ init_endpoint();
1864
+ exports.AgentRuntime = class _AgentRuntime extends ResourceBase {
1865
+ // System properties
1866
+ agentRuntimeArn;
1867
+ agentRuntimeId;
1868
+ agentRuntimeName;
1869
+ agentRuntimeVersion;
1870
+ artifactType;
1871
+ codeConfiguration;
1872
+ containerConfiguration;
1873
+ cpu;
1874
+ createdAt;
1875
+ credentialName;
1876
+ description;
1877
+ environmentVariables;
1878
+ executionRoleArn;
1879
+ healthCheckConfiguration;
1880
+ lastUpdatedAt;
1881
+ logConfiguration;
1882
+ memory;
1883
+ networkConfiguration;
1884
+ port;
1885
+ protocolConfiguration;
1886
+ resourceName;
1887
+ sessionConcurrencyLimitPerInstance;
1888
+ sessionIdleTimeoutSeconds;
1889
+ statusReason;
1890
+ tags;
1891
+ _config;
1892
+ _dataApiCache = {};
1893
+ constructor(data, config2) {
1894
+ super();
1895
+ if (data) {
1896
+ updateObjectProperties(this, data);
1897
+ }
1898
+ this._config = config2;
1899
+ }
1900
+ uniqIdCallback = () => this.agentRuntimeId;
1901
+ static getClient() {
1902
+ const { AgentRuntimeClient: AgentRuntimeClient2 } = (init_client(), __toCommonJS(client_exports));
1903
+ return new AgentRuntimeClient2();
1904
+ }
1905
+ /**
1906
+ * Create a new Agent Runtime
1907
+ */
1908
+ static async create(params) {
1909
+ const { input, config: config2 } = params;
1910
+ return await _AgentRuntime.getClient().create({ input, config: config2 });
1911
+ }
1912
+ /**
1913
+ * Delete an Agent Runtime by ID
1914
+ */
1915
+ static async delete(params) {
1916
+ const { id, config: config2 } = params;
1917
+ return await _AgentRuntime.getClient().delete({ id, config: config2 });
1918
+ }
1919
+ /**
1920
+ * Update an Agent Runtime by ID
1921
+ */
1922
+ static async update(params) {
1923
+ const { id, input, config: config2 } = params;
1924
+ return await _AgentRuntime.getClient().update({ id, input, config: config2 });
1925
+ }
1926
+ /**
1927
+ * Get an Agent Runtime by ID
1928
+ */
1929
+ static async get(params) {
1930
+ const { id, config: config2 } = params;
1931
+ return await _AgentRuntime.getClient().get({ id, config: config2 });
1932
+ }
1933
+ /**
1934
+ * List Agent Runtimes
1935
+ */
1936
+ static async list(params) {
1937
+ const { input, config: config2 } = params ?? {};
1938
+ return await _AgentRuntime.getClient().list({ input, config: config2 });
1939
+ }
1940
+ static listAll = listAllResourcesFunction(this.list);
1941
+ /**
1942
+ * List Agent Runtime versions by ID
1943
+ */
1944
+ static async listVersionsById(params) {
1945
+ const { agentRuntimeId, input, config: config2 } = params;
1946
+ const client = _AgentRuntime.getClient();
1947
+ return await client.listVersions({ agentRuntimeId, input, config: config2 });
1948
+ }
1949
+ /**
1950
+ * Delete this runtime
1951
+ */
1952
+ delete = async (params) => {
1953
+ const config2 = params?.config;
1954
+ if (!this.agentRuntimeId) {
1955
+ throw new Error("agentRuntimeId is required to delete an Agent Runtime");
1956
+ }
1957
+ const result = await _AgentRuntime.delete({
1958
+ id: this.agentRuntimeId,
1959
+ config: config2 ?? this._config
1960
+ });
1961
+ updateObjectProperties(this, result);
1962
+ return this;
1963
+ };
1964
+ /**
1965
+ * Update this runtime
1966
+ */
1967
+ update = async (params) => {
1968
+ const { input, config: config2 } = params;
1969
+ if (!this.agentRuntimeId) {
1970
+ throw new Error("agentRuntimeId is required to update an Agent Runtime");
1971
+ }
1972
+ const result = await _AgentRuntime.update({
1973
+ id: this.agentRuntimeId,
1974
+ input,
1975
+ config: config2 ?? this._config
1976
+ });
1977
+ updateObjectProperties(this, result);
1978
+ return this;
1979
+ };
1980
+ /**
1981
+ * Refresh this runtime's data
1982
+ */
1983
+ get = async (params) => {
1984
+ const config2 = params?.config;
1985
+ if (!this.agentRuntimeId) {
1986
+ throw new Error("agentRuntimeId is required to refresh an Agent Runtime");
1987
+ }
1988
+ const result = await _AgentRuntime.get({
1989
+ id: this.agentRuntimeId,
1990
+ config: config2 ?? this._config
1991
+ });
1992
+ updateObjectProperties(this, result);
1993
+ return this;
1994
+ };
1995
+ /**
1996
+ * Create an endpoint for this runtime
1997
+ */
1998
+ createEndpoint = async (params) => {
1999
+ const { input, config: config2 } = params;
2000
+ if (!this.agentRuntimeId) {
2001
+ throw new Error("agentRuntimeId is required to create an endpoint");
2002
+ }
2003
+ return exports.AgentRuntimeEndpoint.create({
2004
+ agentRuntimeId: this.agentRuntimeId,
2005
+ input,
2006
+ config: config2 ?? this._config
2007
+ });
2008
+ };
2009
+ /**
2010
+ * Delete an endpoint from this runtime
2011
+ */
2012
+ deleteEndpoint = async (params) => {
2013
+ const { endpointId, config: config2 } = params;
2014
+ if (!this.agentRuntimeId) {
2015
+ throw new Error("agentRuntimeId is required to delete an endpoint");
2016
+ }
2017
+ return exports.AgentRuntimeEndpoint.delete({
2018
+ agentRuntimeId: this.agentRuntimeId,
2019
+ endpointId,
2020
+ config: config2 ?? this._config
2021
+ });
2022
+ };
2023
+ /**
2024
+ * Update an endpoint of this runtime
2025
+ */
2026
+ updateEndpoint = async (params) => {
2027
+ const { endpointId, input, config: config2 } = params;
2028
+ if (!this.agentRuntimeId) {
2029
+ throw new Error("agentRuntimeId is required to update an endpoint");
2030
+ }
2031
+ return exports.AgentRuntimeEndpoint.update({
2032
+ agentRuntimeId: this.agentRuntimeId,
2033
+ endpointId,
2034
+ input,
2035
+ config: config2 ?? this._config
2036
+ });
2037
+ };
2038
+ /**
2039
+ * Get an endpoint of this runtime
2040
+ */
2041
+ getEndpoint = async (params) => {
2042
+ const { endpointId, config: config2 } = params;
2043
+ if (!this.agentRuntimeId) {
2044
+ throw new Error("agentRuntimeId is required to get an endpoint");
2045
+ }
2046
+ return exports.AgentRuntimeEndpoint.get({
2047
+ agentRuntimeId: this.agentRuntimeId,
2048
+ endpointId,
2049
+ config: config2 ?? this._config
2050
+ });
2051
+ };
2052
+ /**
2053
+ * List endpoints of this runtime
2054
+ */
2055
+ listEndpoints = async (params) => {
2056
+ const config2 = params?.config;
2057
+ if (!this.agentRuntimeId) {
2058
+ throw new Error("agentRuntimeId is required to list endpoints");
2059
+ }
2060
+ return exports.AgentRuntimeEndpoint.list({
2061
+ agentRuntimeId: this.agentRuntimeId,
2062
+ config: config2 ?? this._config
2063
+ });
2064
+ };
2065
+ /**
2066
+ * List versions of this runtime
2067
+ */
2068
+ listVersions = async (params) => {
2069
+ const config2 = params?.config;
2070
+ if (!this.agentRuntimeId) {
2071
+ throw new Error("agentRuntimeId is required to list versions");
2072
+ }
2073
+ return _AgentRuntime.listVersionsById({
2074
+ agentRuntimeId: this.agentRuntimeId,
2075
+ config: config2 ?? this._config
2076
+ });
2077
+ };
2078
+ /**
2079
+ * Invoke agent runtime using OpenAI-compatible API
2080
+ *
2081
+ * This method provides an OpenAI-compatible interface to invoke the agent runtime.
2082
+ * It creates a Data API client and forwards the invocation request.
2083
+ *
2084
+ * @param args - Invocation arguments
2085
+ * @returns OpenAI chat completion response
2086
+ *
2087
+ * @example
2088
+ * ```typescript
2089
+ * const runtime = await AgentRuntime.get({ id: "runtime-id" });
2090
+ * const response = await runtime.invokeOpenai({
2091
+ * agentRuntimeEndpointName: "Default",
2092
+ * messages: [{ role: "user", content: "Hello" }],
2093
+ * stream: false
2094
+ * });
2095
+ * ```
2096
+ */
2097
+ invokeOpenai = async (args) => {
2098
+ const { agentRuntimeEndpointName = "Default", messages, stream, config: config2 } = args;
2099
+ if (!this.agentRuntimeName) {
2100
+ throw new Error("agentRuntimeName is required to invoke OpenAI");
2101
+ }
2102
+ const cfg = Config.withConfigs(this._config, config2);
2103
+ if (!this._dataApiCache[agentRuntimeEndpointName]) {
2104
+ this._dataApiCache[agentRuntimeEndpointName] = new exports.AgentRuntimeDataAPI(
2105
+ this.agentRuntimeName,
2106
+ agentRuntimeEndpointName,
2107
+ cfg
2108
+ );
2109
+ }
2110
+ return this._dataApiCache[agentRuntimeEndpointName].invokeOpenai({
2111
+ messages,
2112
+ stream,
2113
+ config: cfg
2114
+ });
2115
+ };
2116
+ };
2117
+ }
2118
+ });
2119
+
2120
+ // src/agent-runtime/client.ts
2121
+ var client_exports = {};
2122
+ __export(client_exports, {
2123
+ AgentRuntimeClient: () => exports.AgentRuntimeClient
2124
+ });
2125
+ exports.AgentRuntimeClient = void 0;
2126
+ var init_client = __esm({
2127
+ "src/agent-runtime/client.ts"() {
2128
+ init_config();
2129
+ init_exception();
2130
+ init_model();
2131
+ init_control();
2132
+ init_data();
2133
+ init_endpoint();
2134
+ init_model2();
2135
+ init_runtime();
2136
+ exports.AgentRuntimeClient = class {
2137
+ config;
2138
+ controlApi;
2139
+ constructor(config2) {
2140
+ this.config = config2;
2141
+ this.controlApi = new exports.AgentRuntimeControlAPI(config2);
2142
+ }
2143
+ /**
2144
+ * Create an Agent Runtime
2145
+ */
2146
+ create = async (params) => {
2147
+ const { input, config: config2 } = params;
2148
+ const cfg = Config.withConfigs(this.config, config2);
2149
+ try {
2150
+ if (!input.networkConfiguration) {
2151
+ input.networkConfiguration = {};
2152
+ }
2153
+ if (!input.artifactType) {
2154
+ if (input.codeConfiguration) {
2155
+ input.artifactType = exports.AgentRuntimeArtifact.CODE;
2156
+ } else if (input.containerConfiguration) {
2157
+ input.artifactType = exports.AgentRuntimeArtifact.CONTAINER;
2158
+ } else {
2159
+ throw new Error("Either codeConfiguration or containerConfiguration must be provided");
2160
+ }
2161
+ }
2162
+ const result = await this.controlApi.createAgentRuntime({
2163
+ input: new $AgentRun3__namespace.CreateAgentRuntimeInput({
2164
+ ...input,
2165
+ codeConfiguration: input.codeConfiguration ? new $AgentRun3__namespace.CodeConfiguration({
2166
+ ...input.codeConfiguration
2167
+ }) : void 0,
2168
+ containerConfiguration: input.containerConfiguration ? new $AgentRun3__namespace.ContainerConfiguration({
2169
+ ...input.containerConfiguration
2170
+ }) : void 0,
2171
+ networkConfiguration: input.networkConfiguration ? new $AgentRun3__namespace.NetworkConfiguration({
2172
+ networkMode: input.networkConfiguration.networkMode || NetworkMode.PUBLIC,
2173
+ securityGroupId: input.networkConfiguration.securityGroupId,
2174
+ vpcId: input.networkConfiguration.vpcId,
2175
+ vswitchIds: input.networkConfiguration.vSwitchIds
2176
+ }) : void 0
2177
+ }),
2178
+ config: cfg
2179
+ });
2180
+ return new exports.AgentRuntime(result, cfg);
2181
+ } catch (error) {
2182
+ if (error instanceof HTTPError) {
2183
+ throw error.toResourceError("AgentRuntime", input.agentRuntimeName);
2184
+ }
2185
+ throw error;
2186
+ }
2187
+ };
2188
+ /**
2189
+ * Delete an Agent Runtime
2190
+ */
2191
+ delete = async (params) => {
2192
+ const { id, config: config2 } = params;
2193
+ const cfg = Config.withConfigs(this.config, config2);
2194
+ try {
2195
+ const endpoints = await this.listEndpoints({
2196
+ agentRuntimeId: id,
2197
+ config: cfg
2198
+ });
2199
+ for (const endpoint of endpoints) {
2200
+ await endpoint.delete({ config: cfg });
2201
+ }
2202
+ let remaining = await this.listEndpoints({
2203
+ agentRuntimeId: id,
2204
+ config: cfg
2205
+ });
2206
+ while (remaining.length > 0) {
2207
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
2208
+ remaining = await this.listEndpoints({
2209
+ agentRuntimeId: id,
2210
+ config: cfg
2211
+ });
2212
+ }
2213
+ const result = await this.controlApi.deleteAgentRuntime({
2214
+ agentId: id,
2215
+ config: cfg
2216
+ });
2217
+ return new exports.AgentRuntime(result, cfg);
2218
+ } catch (error) {
2219
+ if (error instanceof HTTPError) {
2220
+ throw error.toResourceError("AgentRuntime", id);
2221
+ }
2222
+ throw error;
2223
+ }
2224
+ };
2225
+ /**
2226
+ * Update an Agent Runtime
2227
+ */
2228
+ update = async (params) => {
2229
+ const { id, input, config: config2 } = params;
2230
+ const cfg = Config.withConfigs(this.config, config2);
2231
+ try {
2232
+ const result = await this.controlApi.updateAgentRuntime({
2233
+ agentId: id,
2234
+ input: new $AgentRun3__namespace.UpdateAgentRuntimeInput({
2235
+ ...input,
2236
+ codeConfiguration: input.codeConfiguration ? new $AgentRun3__namespace.CodeConfiguration({
2237
+ ...input.codeConfiguration
2238
+ }) : void 0,
2239
+ containerConfiguration: input.containerConfiguration ? new $AgentRun3__namespace.ContainerConfiguration({
2240
+ ...input.containerConfiguration
2241
+ }) : void 0
2242
+ }),
2243
+ config: cfg
2244
+ });
2245
+ return new exports.AgentRuntime(result, cfg);
2246
+ } catch (error) {
2247
+ if (error instanceof HTTPError) {
2248
+ throw error.toResourceError("AgentRuntime", id);
2249
+ }
2250
+ throw error;
2251
+ }
2252
+ };
2253
+ /**
2254
+ * Get an Agent Runtime
2255
+ */
2256
+ get = async (params) => {
2257
+ const { id, config: config2 } = params;
2258
+ const cfg = Config.withConfigs(this.config, config2);
2259
+ try {
2260
+ const result = await this.controlApi.getAgentRuntime({
2261
+ agentId: id,
2262
+ config: cfg
2263
+ });
2264
+ return new exports.AgentRuntime(result, cfg);
2265
+ } catch (error) {
2266
+ if (error instanceof HTTPError) {
2267
+ throw error.toResourceError("AgentRuntime", id);
2268
+ }
2269
+ throw error;
2270
+ }
2271
+ };
2272
+ /**
2273
+ * List Agent Runtimes
2274
+ */
2275
+ list = async (params) => {
2276
+ const { input, config: config2 } = params ?? {};
2277
+ const cfg = Config.withConfigs(this.config, config2);
2278
+ const request = new $AgentRun3__namespace.ListAgentRuntimesRequest({
2279
+ ...input
2280
+ });
2281
+ const result = await this.controlApi.listAgentRuntimes({
2282
+ input: request,
2283
+ config: cfg
2284
+ });
2285
+ return (result.items || []).map((item) => new exports.AgentRuntime(item, cfg));
2286
+ };
2287
+ // /**
2288
+ // * List all Agent Runtimes (with pagination)
2289
+ // */
2290
+ // listAll = async (params?: {
2291
+ // options?: {
2292
+ // agentRuntimeName?: string;
2293
+ // tags?: string;
2294
+ // searchMode?: string;
2295
+ // };
2296
+ // config?: Config;
2297
+ // }): Promise<AgentRuntime[]> => {
2298
+ // const { options, config } = params ?? {};
2299
+ // return AgentRuntime.listAll(options, config ?? this.config);
2300
+ // };
2301
+ /**
2302
+ * Create an endpoint for an Agent Runtime
2303
+ */
2304
+ createEndpoint = async (params) => {
2305
+ const { agentRuntimeId, input, config: config2 } = params;
2306
+ const cfg = Config.withConfigs(this.config, config2);
2307
+ try {
2308
+ const targetVersion = input.targetVersion || "LATEST";
2309
+ const result = await this.controlApi.createAgentRuntimeEndpoint({
2310
+ agentId: agentRuntimeId,
2311
+ input: new $AgentRun3__namespace.CreateAgentRuntimeEndpointInput({
2312
+ ...input,
2313
+ targetVersion
2314
+ }),
2315
+ config: cfg
2316
+ });
2317
+ return new exports.AgentRuntimeEndpoint(result, cfg);
2318
+ } catch (error) {
2319
+ if (error instanceof HTTPError) {
2320
+ throw error.toResourceError(
2321
+ "AgentRuntimeEndpoint",
2322
+ `${agentRuntimeId}/${input.agentRuntimeEndpointName}`
2323
+ );
2324
+ }
2325
+ throw error;
2326
+ }
2327
+ };
2328
+ /**
2329
+ * Delete an endpoint
2330
+ */
2331
+ deleteEndpoint = async (params) => {
2332
+ const { agentRuntimeId, endpointId, config: config2 } = params;
2333
+ const cfg = Config.withConfigs(this.config, config2);
2334
+ try {
2335
+ const result = await this.controlApi.deleteAgentRuntimeEndpoint({
2336
+ agentId: agentRuntimeId,
2337
+ endpointId,
2338
+ config: cfg
2339
+ });
2340
+ return new exports.AgentRuntimeEndpoint(result, cfg);
2341
+ } catch (error) {
2342
+ if (error instanceof HTTPError) {
2343
+ throw error.toResourceError("AgentRuntimeEndpoint", `${agentRuntimeId}/${endpointId}`);
2344
+ }
2345
+ throw error;
2346
+ }
2347
+ };
2348
+ /**
2349
+ * Update an endpoint
2350
+ */
2351
+ updateEndpoint = async (params) => {
2352
+ const { agentRuntimeId, endpointId, input, config: config2 } = params;
2353
+ const cfg = Config.withConfigs(this.config, config2);
2354
+ try {
2355
+ const result = await this.controlApi.updateAgentRuntimeEndpoint({
2356
+ agentId: agentRuntimeId,
2357
+ endpointId,
2358
+ input: new $AgentRun3__namespace.UpdateAgentRuntimeEndpointInput({
2359
+ ...input
2360
+ }),
2361
+ config: cfg
2362
+ });
2363
+ return new exports.AgentRuntimeEndpoint(result, cfg);
2364
+ } catch (error) {
2365
+ if (error instanceof HTTPError) {
2366
+ throw error.toResourceError("AgentRuntimeEndpoint", `${agentRuntimeId}/${endpointId}`);
2367
+ }
2368
+ throw error;
2369
+ }
2370
+ };
2371
+ /**
2372
+ * Get an endpoint
2373
+ */
2374
+ getEndpoint = async (params) => {
2375
+ const { agentRuntimeId, endpointId, config: config2 } = params;
2376
+ const cfg = Config.withConfigs(this.config, config2);
2377
+ try {
2378
+ const result = await this.controlApi.getAgentRuntimeEndpoint({
2379
+ agentId: agentRuntimeId,
2380
+ endpointId,
2381
+ config: cfg
2382
+ });
2383
+ return new exports.AgentRuntimeEndpoint(result, cfg);
2384
+ } catch (error) {
2385
+ if (error instanceof HTTPError) {
2386
+ throw error.toResourceError("AgentRuntimeEndpoint", `${agentRuntimeId}/${endpointId}`);
2387
+ }
2388
+ throw error;
2389
+ }
2390
+ };
2391
+ /**
2392
+ * List endpoints for an Agent Runtime
2393
+ */
2394
+ listEndpoints = async (params) => {
2395
+ const { agentRuntimeId, input, config: config2 } = params;
2396
+ const cfg = Config.withConfigs(this.config, config2);
2397
+ try {
2398
+ const request = new $AgentRun3__namespace.ListAgentRuntimeEndpointsRequest({
2399
+ ...input
2400
+ });
2401
+ const result = await this.controlApi.listAgentRuntimeEndpoints({
2402
+ agentId: agentRuntimeId,
2403
+ input: request,
2404
+ config: cfg
2405
+ });
2406
+ return (result.items || []).map((item) => new exports.AgentRuntimeEndpoint(item, cfg));
2407
+ } catch (error) {
2408
+ if (error instanceof HTTPError) {
2409
+ throw error.toResourceError("AgentRuntime", agentRuntimeId);
2410
+ }
2411
+ throw error;
2412
+ }
2413
+ };
2414
+ /**
2415
+ * List versions for an Agent Runtime
2416
+ */
2417
+ listVersions = async (params) => {
2418
+ const { agentRuntimeId, input, config: config2 } = params;
2419
+ const cfg = Config.withConfigs(this.config, config2);
2420
+ const versions = [];
2421
+ let page = 1;
2422
+ const pageSize = 50;
2423
+ while (true) {
2424
+ const request = new $AgentRun3__namespace.ListAgentRuntimeVersionsRequest({
2425
+ ...input,
2426
+ pageNumber: input?.pageNumber ?? page,
2427
+ pageSize: input?.pageSize ?? pageSize
2428
+ });
2429
+ const result = await this.controlApi.listAgentRuntimeVersions({
2430
+ agentId: agentRuntimeId,
2431
+ input: request,
2432
+ config: cfg
2433
+ });
2434
+ if (result.items) {
2435
+ for (const item of result.items) {
2436
+ versions.push({
2437
+ agentRuntimeArn: item.agentRuntimeArn,
2438
+ agentRuntimeId: item.agentRuntimeId,
2439
+ agentRuntimeName: item.agentRuntimeName,
2440
+ agentRuntimeVersion: item.agentRuntimeVersion,
2441
+ description: item.description,
2442
+ lastUpdatedAt: item.lastUpdatedAt
2443
+ });
2444
+ }
2445
+ }
2446
+ if (!result.items || result.items.length < pageSize) {
2447
+ break;
2448
+ }
2449
+ page++;
2450
+ }
2451
+ const seen = /* @__PURE__ */ new Set();
2452
+ return versions.filter((v) => {
2453
+ if (!v.agentRuntimeVersion || seen.has(v.agentRuntimeVersion)) {
2454
+ return false;
2455
+ }
2456
+ seen.add(v.agentRuntimeVersion);
2457
+ return true;
2458
+ });
2459
+ };
2460
+ /**
2461
+ * Invoke agent runtime using OpenAI-compatible API
2462
+ *
2463
+ * This method provides an OpenAI-compatible interface to invoke the agent runtime.
2464
+ *
2465
+ * @param params - Parameters including agent runtime name, endpoint name, and invocation args
2466
+ * @returns OpenAI chat completion response
2467
+ *
2468
+ * @example
2469
+ * ```typescript
2470
+ * const client = new AgentRuntimeClient();
2471
+ * const response = await client.invokeOpenai({
2472
+ * agentRuntimeName: "my-runtime",
2473
+ * agentRuntimeEndpointName: "Default",
2474
+ * messages: [{ role: "user", content: "Hello" }],
2475
+ * stream: false
2476
+ * });
2477
+ * ```
2478
+ */
2479
+ invokeOpenai = async (params) => {
2480
+ const {
2481
+ agentRuntimeName,
2482
+ agentRuntimeEndpointName = "Default",
2483
+ messages,
2484
+ stream,
2485
+ config: config2
2486
+ } = params;
2487
+ const cfg = Config.withConfigs(this.config, config2);
2488
+ const dataApi = new exports.AgentRuntimeDataAPI(agentRuntimeName, agentRuntimeEndpointName, cfg);
2489
+ return dataApi.invokeOpenai({
2490
+ messages,
2491
+ stream,
2492
+ config: cfg
2493
+ });
2494
+ };
2495
+ };
2496
+ }
2497
+ });
2498
+
2499
+ // src/utils/version-check.ts
2500
+ init_log();
2501
+ var VERSION = "0.0.4" ;
2502
+ if (!process.env.DISABLE_BREAKING_CHANGES_WARNING && !globalThis._AGENTRUN_VERSION_WARNING_SHOWN) {
2503
+ globalThis._AGENTRUN_VERSION_WARNING_SHOWN = true;
2504
+ logger.warn(
2505
+ `\u5F53\u524D\u60A8\u6B63\u5728\u4F7F\u7528 AgentRun Python SDK \u7248\u672C ${VERSION}\u3002\u65E9\u671F\u7248\u672C\u901A\u5E38\u5305\u542B\u8BB8\u591A\u65B0\u529F\u80FD\uFF0C\u8FD9\u4E9B\u529F\u80FD\x1B[1;33m \u53EF\u80FD\u5F15\u5165\u4E0D\u517C\u5BB9\u7684\u53D8\u66F4 \x1B[0m\u3002\u4E3A\u907F\u514D\u6F5C\u5728\u95EE\u9898\uFF0C\u6211\u4EEC\u5F3A\u70C8\u5EFA\u8BAE\x1B[1;32m \u5C06\u4F9D\u8D56\u9501\u5B9A\u4E3A\u6B64\u7248\u672C \x1B[0m\u3002
2506
+ You are currently using AgentRun Python SDK version ${VERSION}. Early versions often include many new features, which\x1B[1;33m may introduce breaking changes\x1B[0m. To avoid potential issues, we strongly recommend \x1B[1;32mpinning the dependency to this version\x1B[0m.
2507
+ \x1B[2;3m pip install 'agentrun-sdk==${VERSION}' \x1B[0m
2508
+
2509
+ \u589E\u52A0\x1B[2;3m DISABLE_BREAKING_CHANGES_WARNING=1 \x1B[0m\u5230\u60A8\u7684\u73AF\u5883\u53D8\u91CF\u4EE5\u5173\u95ED\u6B64\u8B66\u544A\u3002
2510
+ Add\x1B[2;3m DISABLE_BREAKING_CHANGES_WARNING=1 \x1B[0mto your environment variables to disable this warning.
2511
+
2512
+ Releases:\x1B[2;3m https://github.com/Serverless-Devs/agentrun-sdk-python/releases\x1B[0m`
2513
+ );
2514
+ }
2515
+
2516
+ // src/agent-runtime/index.ts
2517
+ init_client();
2518
+ init_runtime();
2519
+ init_endpoint();
2520
+ init_control();
2521
+ init_data();
2522
+ init_model2();
2523
+
2524
+ exports.codeFromFile = codeFromFile;
2525
+ exports.codeFromOss = codeFromOss;
2526
+ exports.codeFromZipFile = codeFromZipFile;
2527
+ //# sourceMappingURL=index.cjs.map
2528
+ //# sourceMappingURL=index.cjs.map