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