@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,882 @@
1
+ import * as $AgentRun2 from '@alicloud/agentrun20250910';
2
+ import * as $Util from '@alicloud/tea-util';
3
+ import * as $OpenApi from '@alicloud/openapi-client';
4
+ import * as dotenv from 'dotenv';
5
+
6
+ // src/utils/log.ts
7
+ var LOG_LEVELS = {
8
+ debug: 0,
9
+ info: 1,
10
+ warn: 2,
11
+ error: 3
12
+ };
13
+ var COLORS = {
14
+ reset: "\x1B[0m",
15
+ bright: "\x1B[1m",
16
+ dim: "\x1B[2m",
17
+ italic: "\x1B[3m",
18
+ blue: "\x1B[34m",
19
+ cyan: "\x1B[36m",
20
+ yellow: "\x1B[33m",
21
+ red: "\x1B[31m"
22
+ };
23
+ var Logger = class {
24
+ level = "info";
25
+ // match Python logger name
26
+ prefix = "agentrun-logger";
27
+ setLevel(level) {
28
+ this.level = level;
29
+ }
30
+ shouldLog(level) {
31
+ return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
32
+ }
33
+ getColor(level) {
34
+ switch (level) {
35
+ case "debug":
36
+ return COLORS.cyan;
37
+ case "info":
38
+ return COLORS.blue;
39
+ case "warn":
40
+ return COLORS.yellow;
41
+ case "error":
42
+ return COLORS.red;
43
+ default:
44
+ return COLORS.reset;
45
+ }
46
+ }
47
+ // format timestamp like Python: YYYY-MM-DD HH:mm:ss,SSS
48
+ formatTimestamp(d = /* @__PURE__ */ new Date()) {
49
+ const pad = (n, sz = 2) => n.toString().padStart(sz, "0");
50
+ const year = d.getFullYear();
51
+ const month = pad(d.getMonth() + 1);
52
+ const day = pad(d.getDate());
53
+ const hour = pad(d.getHours());
54
+ const minute = pad(d.getMinutes());
55
+ const second = pad(d.getSeconds());
56
+ const ms = pad(d.getMilliseconds(), 3);
57
+ return `${year}-${month}-${day} ${hour}:${minute}:${second},${ms}`;
58
+ }
59
+ // attempt to infer caller file and line by parsing Error.stack
60
+ // helper: parse a single stack frame into {filepath, line, functionName}
61
+ parseFrame(frame) {
62
+ const m = frame.match(/^(?:at\s+)?(?:(.+?)\s+\()?(.*?):(\d+):(\d+)\)?$/);
63
+ if (!m) return null;
64
+ return {
65
+ functionName: m[1] ? m[1].trim() : void 0,
66
+ filepath: m[2],
67
+ line: parseInt(m[3], 10)
68
+ };
69
+ }
70
+ // get caller by fixed stack offset (used in public log methods)
71
+ getCallerByOffset() {
72
+ const err = new Error();
73
+ const stack = err.stack;
74
+ if (!stack) return {};
75
+ const lines = stack.split("\n").map((l) => l.trim());
76
+ for (let i = 3; i < lines.length; i++) {
77
+ let parsed = this.parseFrame(lines[i]);
78
+ if (!parsed) {
79
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
80
+ if (m) {
81
+ const parts = m[1].split(":");
82
+ parts.pop();
83
+ const ln = Number(parts.pop());
84
+ const fp2 = parts.join(":");
85
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
86
+ }
87
+ }
88
+ if (!parsed) continue;
89
+ const fp = parsed.filepath;
90
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
91
+ continue;
92
+ return { filepath: parsed.filepath, line: parsed.line };
93
+ }
94
+ const cwd = process.cwd();
95
+ for (let i = 0; i < lines.length; i++) {
96
+ let parsed = this.parseFrame(lines[i]);
97
+ if (!parsed) {
98
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
99
+ if (m) {
100
+ const parts = m[1].split(":");
101
+ parts.pop();
102
+ const ln = Number(parts.pop());
103
+ const fp2 = parts.join(":");
104
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
105
+ }
106
+ }
107
+ if (!parsed) continue;
108
+ const fp = parsed.filepath;
109
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
110
+ continue;
111
+ if (fp.includes("/src/utils/log.ts")) continue;
112
+ if (fp.startsWith(cwd)) return { filepath: parsed.filepath, line: parsed.line };
113
+ }
114
+ for (let i = 0; i < lines.length; i++) {
115
+ let parsed = this.parseFrame(lines[i]);
116
+ if (!parsed) {
117
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
118
+ if (m) {
119
+ const parts = m[1].split(":");
120
+ parts.pop();
121
+ const ln = Number(parts.pop());
122
+ const fp2 = parts.join(":");
123
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
124
+ }
125
+ }
126
+ if (!parsed) continue;
127
+ const fp = parsed.filepath;
128
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
129
+ continue;
130
+ if (fp.includes("/src/utils/log.ts")) continue;
131
+ return { filepath: parsed.filepath, line: parsed.line };
132
+ }
133
+ return {};
134
+ }
135
+ formatMessage(level, message, filepath, line) {
136
+ const timestamp = this.formatTimestamp();
137
+ const color = this.getColor(level);
138
+ const reset = COLORS.reset;
139
+ const levelName = level === "warn" ? "WARNING" : level.toUpperCase();
140
+ const levelStr = `${COLORS.bright}${color}${levelName}${reset}`;
141
+ const nameStr = `${color}[${this.prefix}]${reset}`;
142
+ const tsStr = `${color} ${timestamp}${reset}`;
143
+ const pathInfo = filepath && line !== void 0 ? ` ${COLORS.dim}${COLORS.italic}${filepath}:${line}${reset}` : "";
144
+ const msg = level === "debug" ? `${COLORS.dim}${message}${reset}` : message;
145
+ return `
146
+ ${levelStr} ${nameStr}${tsStr}${pathInfo}
147
+ ${msg}
148
+ `;
149
+ }
150
+ debug(message, ...args) {
151
+ if (this.shouldLog("debug")) {
152
+ const caller = this.getCallerByOffset();
153
+ console.debug(this.formatMessage("debug", message, caller.filepath, caller.line), ...args);
154
+ }
155
+ }
156
+ info(message, ...args) {
157
+ if (this.shouldLog("info")) {
158
+ const caller = this.getCallerByOffset();
159
+ console.info(this.formatMessage("info", message, caller.filepath, caller.line), ...args);
160
+ }
161
+ }
162
+ warn(message, ...args) {
163
+ if (this.shouldLog("warn")) {
164
+ const caller = this.getCallerByOffset();
165
+ console.warn(this.formatMessage("warn", message, caller.filepath, caller.line), ...args);
166
+ }
167
+ }
168
+ error(message, ...args) {
169
+ if (this.shouldLog("error")) {
170
+ const caller = this.getCallerByOffset();
171
+ console.error(this.formatMessage("error", message, caller.filepath, caller.line), ...args);
172
+ }
173
+ }
174
+ };
175
+ var logger = new Logger();
176
+ if (![void 0, null, "", "False", "FALSE", "false", "0"].includes(process.env["AGENTRUN_SDK_DEBUG"])) {
177
+ logger.setLevel("debug");
178
+ if (!globalThis._AGENTRUN_DEBUG_LOGGED) {
179
+ logger.warn("\u542F\u7528 AgentRun SDK \u8C03\u8BD5\u65E5\u5FD7\uFF0C \u79FB\u9664 AGENTRUN_SDK_DEBUG \u73AF\u5883\u53D8\u91CF\u4EE5\u5173\u95ED");
180
+ globalThis._AGENTRUN_DEBUG_LOGGED = true;
181
+ }
182
+ } else {
183
+ logger.setLevel("info");
184
+ }
185
+
186
+ // src/utils/version-check.ts
187
+ var VERSION = "0.0.4" ;
188
+ if (!process.env.DISABLE_BREAKING_CHANGES_WARNING && !globalThis._AGENTRUN_VERSION_WARNING_SHOWN) {
189
+ globalThis._AGENTRUN_VERSION_WARNING_SHOWN = true;
190
+ logger.warn(
191
+ `\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
192
+ 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.
193
+ \x1B[2;3m pip install 'agentrun-sdk==${VERSION}' \x1B[0m
194
+
195
+ \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
196
+ Add\x1B[2;3m DISABLE_BREAKING_CHANGES_WARNING=1 \x1B[0mto your environment variables to disable this warning.
197
+
198
+ Releases:\x1B[2;3m https://github.com/Serverless-Devs/agentrun-sdk-python/releases\x1B[0m`
199
+ );
200
+ }
201
+ dotenv.config();
202
+ function getEnvWithDefault(defaultValue, ...keys) {
203
+ for (const key of keys) {
204
+ const value = process.env[key];
205
+ if (value !== void 0 && value !== "") {
206
+ return value;
207
+ }
208
+ }
209
+ return defaultValue;
210
+ }
211
+ var Config = class _Config {
212
+ _accessKeyId;
213
+ _accessKeySecret;
214
+ _securityToken;
215
+ _accountId;
216
+ _token;
217
+ _regionId;
218
+ _timeout;
219
+ _readTimeout;
220
+ _controlEndpoint;
221
+ _dataEndpoint;
222
+ _devsEndpoint;
223
+ _headers;
224
+ constructor(options = {}) {
225
+ this._accessKeyId = options.accessKeyId ?? getEnvWithDefault("", "AGENTRUN_ACCESS_KEY_ID", "ALIBABA_CLOUD_ACCESS_KEY_ID");
226
+ this._accessKeySecret = options.accessKeySecret ?? getEnvWithDefault("", "AGENTRUN_ACCESS_KEY_SECRET", "ALIBABA_CLOUD_ACCESS_KEY_SECRET");
227
+ this._securityToken = options.securityToken ?? getEnvWithDefault("", "AGENTRUN_SECURITY_TOKEN", "ALIBABA_CLOUD_SECURITY_TOKEN");
228
+ this._accountId = options.accountId ?? getEnvWithDefault("", "AGENTRUN_ACCOUNT_ID", "FC_ACCOUNT_ID");
229
+ this._token = options.token;
230
+ this._regionId = options.regionId ?? getEnvWithDefault("cn-hangzhou", "AGENTRUN_REGION", "FC_REGION");
231
+ this._timeout = options.timeout ?? 6e5;
232
+ this._readTimeout = options.readTimeout ?? 1e8;
233
+ this._controlEndpoint = options.controlEndpoint ?? getEnvWithDefault("", "AGENTRUN_CONTROL_ENDPOINT");
234
+ this._dataEndpoint = options.dataEndpoint ?? getEnvWithDefault("", "AGENTRUN_DATA_ENDPOINT");
235
+ this._devsEndpoint = options.devsEndpoint ?? getEnvWithDefault("", "DEVS_ENDPOINT");
236
+ this._headers = options.headers ?? {};
237
+ }
238
+ /**
239
+ * Create a new Config by merging multiple configs.
240
+ * Later configs take precedence.
241
+ */
242
+ static withConfigs(...configs) {
243
+ return new _Config().update(...configs);
244
+ }
245
+ /**
246
+ * Update this config with values from other configs.
247
+ * Non-undefined values from later configs take precedence.
248
+ */
249
+ update(...configs) {
250
+ for (const config2 of configs) {
251
+ if (!config2) continue;
252
+ if (config2._accessKeyId) this._accessKeyId = config2._accessKeyId;
253
+ if (config2._accessKeySecret) this._accessKeySecret = config2._accessKeySecret;
254
+ if (config2._securityToken) this._securityToken = config2._securityToken;
255
+ if (config2._accountId) this._accountId = config2._accountId;
256
+ if (config2._token) this._token = config2._token;
257
+ if (config2._regionId) this._regionId = config2._regionId;
258
+ if (config2._timeout) this._timeout = config2._timeout;
259
+ if (config2._readTimeout) this._readTimeout = config2._readTimeout;
260
+ if (config2._controlEndpoint) this._controlEndpoint = config2._controlEndpoint;
261
+ if (config2._dataEndpoint) this._dataEndpoint = config2._dataEndpoint;
262
+ if (config2._devsEndpoint) this._devsEndpoint = config2._devsEndpoint;
263
+ if (config2._headers && Object.keys(config2._headers).length > 0) {
264
+ this._headers = { ...this._headers, ...config2._headers };
265
+ }
266
+ }
267
+ return this;
268
+ }
269
+ get accessKeyId() {
270
+ return this._accessKeyId;
271
+ }
272
+ get accessKeySecret() {
273
+ return this._accessKeySecret;
274
+ }
275
+ get securityToken() {
276
+ return this._securityToken;
277
+ }
278
+ get accountId() {
279
+ if (!this._accountId) {
280
+ throw new Error(
281
+ "Account ID is not set. Please add AGENTRUN_ACCOUNT_ID environment variable or set it in code."
282
+ );
283
+ }
284
+ return this._accountId;
285
+ }
286
+ get token() {
287
+ return this._token;
288
+ }
289
+ get regionId() {
290
+ return this._regionId || "cn-hangzhou";
291
+ }
292
+ get timeout() {
293
+ return this._timeout || 6e5;
294
+ }
295
+ get readTimeout() {
296
+ return this._readTimeout || 1e8;
297
+ }
298
+ get controlEndpoint() {
299
+ if (this._controlEndpoint) {
300
+ return this._controlEndpoint;
301
+ }
302
+ return `https://agentrun.${this.regionId}.aliyuncs.com`;
303
+ }
304
+ get dataEndpoint() {
305
+ if (this._dataEndpoint) {
306
+ return this._dataEndpoint;
307
+ }
308
+ return `https://${this.accountId}.agentrun-data.${this.regionId}.aliyuncs.com`;
309
+ }
310
+ get devsEndpoint() {
311
+ if (this._devsEndpoint) {
312
+ return this._devsEndpoint;
313
+ }
314
+ return `https://devs.${this.regionId}.aliyuncs.com`;
315
+ }
316
+ get headers() {
317
+ return this._headers;
318
+ }
319
+ };
320
+
321
+ // src/utils/control-api.ts
322
+ var $AgentRunClient = (
323
+ // @ts-expect-error - ESM interop: default.default exists when imported as ESM namespace
324
+ $AgentRun2.default?.default ?? $AgentRun2.default ?? $AgentRun2
325
+ );
326
+ var ControlAPI = class {
327
+ config;
328
+ constructor(config2) {
329
+ this.config = config2;
330
+ }
331
+ /**
332
+ * Get the underlying AgentRun client instance
333
+ */
334
+ getClient(config2) {
335
+ const cfg = Config.withConfigs(this.config, config2);
336
+ let endpoint = cfg.controlEndpoint;
337
+ if (endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
338
+ endpoint = endpoint.split("://")[1];
339
+ }
340
+ const openApiConfig = new $OpenApi.Config({
341
+ accessKeyId: cfg.accessKeyId,
342
+ accessKeySecret: cfg.accessKeySecret,
343
+ securityToken: cfg.securityToken || void 0,
344
+ regionId: cfg.regionId,
345
+ endpoint,
346
+ connectTimeout: cfg.timeout,
347
+ readTimeout: cfg.readTimeout
348
+ });
349
+ return new $AgentRunClient(openApiConfig);
350
+ }
351
+ };
352
+
353
+ // src/utils/exception.ts
354
+ var AgentRunError = class _AgentRunError extends Error {
355
+ constructor(message) {
356
+ super(message);
357
+ this.name = "AgentRunError";
358
+ Object.setPrototypeOf(this, _AgentRunError.prototype);
359
+ }
360
+ };
361
+ var HTTPError = class _HTTPError extends AgentRunError {
362
+ statusCode;
363
+ requestId;
364
+ errorCode;
365
+ constructor(statusCode, message, options) {
366
+ super(message);
367
+ this.name = "HTTPError";
368
+ this.statusCode = statusCode;
369
+ this.requestId = options?.requestId;
370
+ this.errorCode = options?.errorCode;
371
+ Object.setPrototypeOf(this, _HTTPError.prototype);
372
+ }
373
+ /**
374
+ * Convert HTTP error to resource-specific error based on status code
375
+ */
376
+ toResourceError(resourceType, resourceId) {
377
+ if (this.statusCode == 404) return new ResourceNotExistError(resourceType, resourceId);
378
+ else if (this.statusCode == 409) return new ResourceAlreadyExistError(resourceType, resourceId);
379
+ else if ((this.statusCode == 400 || this.statusCode == 500) && this.message.includes("already exists"))
380
+ return new ResourceAlreadyExistError(resourceType, resourceId);
381
+ else return this;
382
+ }
383
+ };
384
+ var ClientError = class _ClientError extends HTTPError {
385
+ constructor(statusCode, message, options) {
386
+ super(statusCode, message, options);
387
+ this.name = "ClientError";
388
+ Object.setPrototypeOf(this, _ClientError.prototype);
389
+ }
390
+ };
391
+ var ServerError = class _ServerError extends HTTPError {
392
+ constructor(statusCode, message, options) {
393
+ super(statusCode, message, options);
394
+ this.name = "ServerError";
395
+ Object.setPrototypeOf(this, _ServerError.prototype);
396
+ }
397
+ };
398
+ var ResourceNotExistError = class _ResourceNotExistError extends ClientError {
399
+ resourceType;
400
+ resourceId;
401
+ constructor(resourceType, resourceId, options) {
402
+ const message = resourceId ? `${resourceType} '${resourceId}' does not exist` : `${resourceType} does not exist`;
403
+ super(404, message, options);
404
+ this.name = "ResourceNotExistError";
405
+ this.resourceType = resourceType;
406
+ this.resourceId = resourceId;
407
+ Object.setPrototypeOf(this, _ResourceNotExistError.prototype);
408
+ }
409
+ };
410
+ var ResourceAlreadyExistError = class _ResourceAlreadyExistError extends ClientError {
411
+ resourceType;
412
+ resourceId;
413
+ constructor(resourceType, resourceId, options) {
414
+ const message = resourceId ? `${resourceType} '${resourceId}' already exists` : `${resourceType} already exists`;
415
+ super(409, message, options);
416
+ this.name = "ResourceAlreadyExistError";
417
+ this.resourceType = resourceType;
418
+ this.resourceId = resourceId;
419
+ Object.setPrototypeOf(this, _ResourceAlreadyExistError.prototype);
420
+ }
421
+ };
422
+
423
+ // src/agent-runtime/api/control.ts
424
+ var AgentRuntimeControlAPI = class extends ControlAPI {
425
+ constructor(config2) {
426
+ super(config2);
427
+ }
428
+ /**
429
+ * Create Agent Runtime
430
+ *
431
+ * @param params - Method parameters
432
+ * @param params.input - Agent Runtime configuration
433
+ * @param params.headers - Custom request headers
434
+ * @param params.config - Optional config override
435
+ * @returns Created Runtime object
436
+ */
437
+ createAgentRuntime = async (params) => {
438
+ const { input, headers, config: config2 } = params;
439
+ try {
440
+ const client = this.getClient(config2);
441
+ const runtime = new $Util.RuntimeOptions({});
442
+ const response = await client.createAgentRuntimeWithOptions(
443
+ new $AgentRun2.CreateAgentRuntimeRequest({ body: input }),
444
+ headers ?? {},
445
+ runtime
446
+ );
447
+ logger.debug(
448
+ `request api createAgentRuntime, request Request ID: ${response.body?.requestId}
449
+ request: ${JSON.stringify([input])}
450
+ response: ${JSON.stringify(response.body?.data)}`
451
+ );
452
+ return response.body?.data;
453
+ } catch (error) {
454
+ if (error && typeof error === "object" && "statusCode" in error) {
455
+ const e = error;
456
+ const statusCode = e.statusCode;
457
+ const message = e.message || "Unknown error";
458
+ const requestId = e.data?.requestId;
459
+ if (statusCode >= 400 && statusCode < 500) {
460
+ throw new ClientError(statusCode, message, { requestId });
461
+ } else if (statusCode >= 500) {
462
+ throw new ServerError(statusCode, message, { requestId });
463
+ }
464
+ }
465
+ throw error;
466
+ }
467
+ };
468
+ /**
469
+ * Delete Agent Runtime
470
+ *
471
+ * @param params - Method parameters
472
+ * @param params.agentId - Agent Runtime ID
473
+ * @param params.headers - Custom request headers
474
+ * @param params.config - Optional config override
475
+ * @returns Deleted Runtime object
476
+ */
477
+ deleteAgentRuntime = async (params) => {
478
+ const { agentId, headers, config: config2 } = params;
479
+ try {
480
+ const client = this.getClient(config2);
481
+ const runtime = new $Util.RuntimeOptions({});
482
+ const response = await client.deleteAgentRuntimeWithOptions(agentId, headers ?? {}, runtime);
483
+ logger.debug(
484
+ `request api deleteAgentRuntime, request Request ID: ${response.body?.requestId}
485
+ request: ${JSON.stringify([agentId])}
486
+ response: ${JSON.stringify(response.body?.data)}`
487
+ );
488
+ return response.body?.data;
489
+ } catch (error) {
490
+ if (error && typeof error === "object" && "statusCode" in error) {
491
+ const e = error;
492
+ const statusCode = e.statusCode;
493
+ const message = e.message || "Unknown error";
494
+ const requestId = e.data?.requestId;
495
+ if (statusCode >= 400 && statusCode < 500) {
496
+ throw new ClientError(statusCode, message, { requestId });
497
+ } else if (statusCode >= 500) {
498
+ throw new ServerError(statusCode, message, { requestId });
499
+ }
500
+ }
501
+ throw error;
502
+ }
503
+ };
504
+ /**
505
+ * Update Agent Runtime
506
+ *
507
+ * @param params - Method parameters
508
+ * @param params.agentId - Agent Runtime ID
509
+ * @param params.input - Agent Runtime configuration
510
+ * @param params.headers - Custom request headers
511
+ * @param params.config - Optional config override
512
+ * @returns Updated Runtime object
513
+ */
514
+ updateAgentRuntime = async (params) => {
515
+ const { agentId, input, headers, config: config2 } = params;
516
+ try {
517
+ const client = this.getClient(config2);
518
+ const runtime = new $Util.RuntimeOptions({});
519
+ const response = await client.updateAgentRuntimeWithOptions(
520
+ agentId,
521
+ new $AgentRun2.UpdateAgentRuntimeRequest({ body: input }),
522
+ headers ?? {},
523
+ runtime
524
+ );
525
+ logger.debug(
526
+ `request api updateAgentRuntime, request Request ID: ${response.body?.requestId}
527
+ request: ${JSON.stringify([agentId, input])}
528
+ response: ${JSON.stringify(response.body?.data)}`
529
+ );
530
+ return response.body?.data;
531
+ } catch (error) {
532
+ if (error && typeof error === "object" && "statusCode" in error) {
533
+ const e = error;
534
+ const statusCode = e.statusCode;
535
+ const message = e.message || "Unknown error";
536
+ const requestId = e.data?.requestId;
537
+ if (statusCode >= 400 && statusCode < 500) {
538
+ throw new ClientError(statusCode, message, { requestId });
539
+ } else if (statusCode >= 500) {
540
+ throw new ServerError(statusCode, message, { requestId });
541
+ }
542
+ }
543
+ throw error;
544
+ }
545
+ };
546
+ /**
547
+ * Get Agent Runtime
548
+ *
549
+ * @param params - Method parameters
550
+ * @param params.agentId - Agent Runtime ID
551
+ * @param params.request - Get request options
552
+ * @param params.headers - Custom request headers
553
+ * @param params.config - Optional config override
554
+ * @returns Runtime object
555
+ */
556
+ getAgentRuntime = async (params) => {
557
+ const { agentId, request, headers, config: config2 } = params;
558
+ try {
559
+ const client = this.getClient(config2);
560
+ const runtime = new $Util.RuntimeOptions({});
561
+ const response = await client.getAgentRuntimeWithOptions(
562
+ agentId,
563
+ request ?? new $AgentRun2.GetAgentRuntimeRequest({}),
564
+ headers ?? {},
565
+ runtime
566
+ );
567
+ logger.debug(
568
+ `request api getAgentRuntime, request Request ID: ${response.body?.requestId}
569
+ request: ${JSON.stringify([agentId, request])}
570
+ response: ${JSON.stringify(response.body?.data)}`
571
+ );
572
+ return response.body?.data;
573
+ } catch (error) {
574
+ if (error && typeof error === "object" && "statusCode" in error) {
575
+ const e = error;
576
+ const statusCode = e.statusCode;
577
+ const message = e.message || "Unknown error";
578
+ const requestId = e.data?.requestId;
579
+ if (statusCode >= 400 && statusCode < 500) {
580
+ throw new ClientError(statusCode, message, { requestId });
581
+ } else if (statusCode >= 500) {
582
+ throw new ServerError(statusCode, message, { requestId });
583
+ }
584
+ }
585
+ throw error;
586
+ }
587
+ };
588
+ /**
589
+ * List Agent Runtimes
590
+ *
591
+ * @param params - Method parameters
592
+ * @param params.input - List options
593
+ * @param params.headers - Custom request headers
594
+ * @param params.config - Optional config override
595
+ * @returns List of Runtime objects
596
+ */
597
+ listAgentRuntimes = async (params) => {
598
+ const { input, headers, config: config2 } = params;
599
+ try {
600
+ const client = this.getClient(config2);
601
+ const runtime = new $Util.RuntimeOptions({});
602
+ const response = await client.listAgentRuntimesWithOptions(input, headers ?? {}, runtime);
603
+ logger.debug(
604
+ `request api listAgentRuntimes, request Request ID: ${response.body?.requestId}
605
+ request: ${JSON.stringify([input])}
606
+ response: ${JSON.stringify(response.body?.data)}`
607
+ );
608
+ return response.body?.data;
609
+ } catch (error) {
610
+ if (error && typeof error === "object" && "statusCode" in error) {
611
+ const e = error;
612
+ const statusCode = e.statusCode;
613
+ const message = e.message || "Unknown error";
614
+ const requestId = e.data?.requestId;
615
+ if (statusCode >= 400 && statusCode < 500) {
616
+ throw new ClientError(statusCode, message, { requestId });
617
+ } else if (statusCode >= 500) {
618
+ throw new ServerError(statusCode, message, { requestId });
619
+ }
620
+ }
621
+ throw error;
622
+ }
623
+ };
624
+ /**
625
+ * Create Agent Runtime Endpoint
626
+ *
627
+ * @param params - Method parameters
628
+ * @param params.agentId - Agent Runtime ID
629
+ * @param params.input - Endpoint configuration
630
+ * @param params.headers - Custom request headers
631
+ * @param params.config - Optional config override
632
+ * @returns Created Endpoint object
633
+ */
634
+ createAgentRuntimeEndpoint = async (params) => {
635
+ const { agentId, input, headers, config: config2 } = params;
636
+ try {
637
+ const client = this.getClient(config2);
638
+ const runtime = new $Util.RuntimeOptions({});
639
+ const response = await client.createAgentRuntimeEndpointWithOptions(
640
+ agentId,
641
+ new $AgentRun2.CreateAgentRuntimeEndpointRequest({ body: input }),
642
+ headers ?? {},
643
+ runtime
644
+ );
645
+ logger.debug(
646
+ `request api createAgentRuntimeEndpoint, request Request ID: ${response.body?.requestId}
647
+ request: ${JSON.stringify([agentId, input])}
648
+ response: ${JSON.stringify(response.body?.data)}`
649
+ );
650
+ return response.body?.data;
651
+ } catch (error) {
652
+ if (error && typeof error === "object" && "statusCode" in error) {
653
+ const e = error;
654
+ const statusCode = e.statusCode;
655
+ const message = e.message || "Unknown error";
656
+ const requestId = e.data?.requestId;
657
+ if (statusCode >= 400 && statusCode < 500) {
658
+ throw new ClientError(statusCode, message, { requestId });
659
+ } else if (statusCode >= 500) {
660
+ throw new ServerError(statusCode, message, { requestId });
661
+ }
662
+ }
663
+ throw error;
664
+ }
665
+ };
666
+ /**
667
+ * Delete Agent Runtime Endpoint
668
+ *
669
+ * @param params - Method parameters
670
+ * @param params.agentId - Agent Runtime ID
671
+ * @param params.endpointId - Endpoint ID
672
+ * @param params.headers - Custom request headers
673
+ * @param params.config - Optional config override
674
+ * @returns Deleted Endpoint object
675
+ */
676
+ deleteAgentRuntimeEndpoint = async (params) => {
677
+ const { agentId, endpointId, headers, config: config2 } = params;
678
+ try {
679
+ const client = this.getClient(config2);
680
+ const runtime = new $Util.RuntimeOptions({});
681
+ const response = await client.deleteAgentRuntimeEndpointWithOptions(
682
+ agentId,
683
+ endpointId,
684
+ headers ?? {},
685
+ runtime
686
+ );
687
+ logger.debug(
688
+ `request api deleteAgentRuntimeEndpoint, request Request ID: ${response.body?.requestId}
689
+ request: ${JSON.stringify([agentId, endpointId])}
690
+ response: ${JSON.stringify(response.body?.data)}`
691
+ );
692
+ return response.body?.data;
693
+ } catch (error) {
694
+ if (error && typeof error === "object" && "statusCode" in error) {
695
+ const e = error;
696
+ const statusCode = e.statusCode;
697
+ const message = e.message || "Unknown error";
698
+ const requestId = e.data?.requestId;
699
+ if (statusCode >= 400 && statusCode < 500) {
700
+ throw new ClientError(statusCode, message, { requestId });
701
+ } else if (statusCode >= 500) {
702
+ throw new ServerError(statusCode, message, { requestId });
703
+ }
704
+ }
705
+ throw error;
706
+ }
707
+ };
708
+ /**
709
+ * Update Agent Runtime Endpoint
710
+ *
711
+ * @param params - Method parameters
712
+ * @param params.agentId - Agent Runtime ID
713
+ * @param params.endpointId - Endpoint ID
714
+ * @param params.input - Endpoint configuration
715
+ * @param params.headers - Custom request headers
716
+ * @param params.config - Optional config override
717
+ * @returns Updated Endpoint object
718
+ */
719
+ updateAgentRuntimeEndpoint = async (params) => {
720
+ const { agentId, endpointId, input, headers, config: config2 } = params;
721
+ try {
722
+ const client = this.getClient(config2);
723
+ const runtime = new $Util.RuntimeOptions({});
724
+ const response = await client.updateAgentRuntimeEndpointWithOptions(
725
+ agentId,
726
+ endpointId,
727
+ new $AgentRun2.UpdateAgentRuntimeEndpointRequest({ body: input }),
728
+ headers ?? {},
729
+ runtime
730
+ );
731
+ logger.debug(
732
+ `request api updateAgentRuntimeEndpoint, request Request ID: ${response.body?.requestId}
733
+ request: ${JSON.stringify([agentId, endpointId, input])}
734
+ response: ${JSON.stringify(response.body?.data)}`
735
+ );
736
+ return response.body?.data;
737
+ } catch (error) {
738
+ if (error && typeof error === "object" && "statusCode" in error) {
739
+ const e = error;
740
+ const statusCode = e.statusCode;
741
+ const message = e.message || "Unknown error";
742
+ const requestId = e.data?.requestId;
743
+ if (statusCode >= 400 && statusCode < 500) {
744
+ throw new ClientError(statusCode, message, { requestId });
745
+ } else if (statusCode >= 500) {
746
+ throw new ServerError(statusCode, message, { requestId });
747
+ }
748
+ }
749
+ throw error;
750
+ }
751
+ };
752
+ /**
753
+ * Get Agent Runtime Endpoint
754
+ *
755
+ * @param params - Method parameters
756
+ * @param params.agentId - Agent Runtime ID
757
+ * @param params.endpointId - Endpoint ID
758
+ * @param params.headers - Custom request headers
759
+ * @param params.config - Optional config override
760
+ * @returns Endpoint object
761
+ */
762
+ getAgentRuntimeEndpoint = async (params) => {
763
+ const { agentId, endpointId, headers, config: config2 } = params;
764
+ try {
765
+ const client = this.getClient(config2);
766
+ const runtime = new $Util.RuntimeOptions({});
767
+ const response = await client.getAgentRuntimeEndpointWithOptions(
768
+ agentId,
769
+ endpointId,
770
+ headers ?? {},
771
+ runtime
772
+ );
773
+ logger.debug(
774
+ `request api getAgentRuntimeEndpoint, request Request ID: ${response.body?.requestId}
775
+ request: ${JSON.stringify([agentId, endpointId])}
776
+ response: ${JSON.stringify(response.body?.data)}`
777
+ );
778
+ return response.body?.data;
779
+ } catch (error) {
780
+ if (error && typeof error === "object" && "statusCode" in error) {
781
+ const e = error;
782
+ const statusCode = e.statusCode;
783
+ const message = e.message || "Unknown error";
784
+ const requestId = e.data?.requestId;
785
+ if (statusCode >= 400 && statusCode < 500) {
786
+ throw new ClientError(statusCode, message, { requestId });
787
+ } else if (statusCode >= 500) {
788
+ throw new ServerError(statusCode, message, { requestId });
789
+ }
790
+ }
791
+ throw error;
792
+ }
793
+ };
794
+ /**
795
+ * List Agent Runtime Endpoints
796
+ *
797
+ * @param params - Method parameters
798
+ * @param params.agentId - Agent Runtime ID
799
+ * @param params.input - List options
800
+ * @param params.headers - Custom request headers
801
+ * @param params.config - Optional config override
802
+ * @returns List of Endpoint objects
803
+ */
804
+ listAgentRuntimeEndpoints = async (params) => {
805
+ const { agentId, input, headers, config: config2 } = params;
806
+ try {
807
+ const client = this.getClient(config2);
808
+ const runtime = new $Util.RuntimeOptions({});
809
+ const response = await client.listAgentRuntimeEndpointsWithOptions(
810
+ agentId,
811
+ input,
812
+ headers ?? {},
813
+ runtime
814
+ );
815
+ logger.debug(
816
+ `request api listAgentRuntimeEndpoints, request Request ID: ${response.body?.requestId}
817
+ request: ${JSON.stringify([agentId, input])}
818
+ response: ${JSON.stringify(response.body?.data)}`
819
+ );
820
+ return response.body?.data;
821
+ } catch (error) {
822
+ if (error && typeof error === "object" && "statusCode" in error) {
823
+ const e = error;
824
+ const statusCode = e.statusCode;
825
+ const message = e.message || "Unknown error";
826
+ const requestId = e.data?.requestId;
827
+ if (statusCode >= 400 && statusCode < 500) {
828
+ throw new ClientError(statusCode, message, { requestId });
829
+ } else if (statusCode >= 500) {
830
+ throw new ServerError(statusCode, message, { requestId });
831
+ }
832
+ }
833
+ throw error;
834
+ }
835
+ };
836
+ /**
837
+ * List Agent Runtime Versions
838
+ *
839
+ * @param params - Method parameters
840
+ * @param params.agentId - Agent Runtime ID
841
+ * @param params.input - List options
842
+ * @param params.headers - Custom request headers
843
+ * @param params.config - Optional config override
844
+ * @returns List of Version objects
845
+ */
846
+ listAgentRuntimeVersions = async (params) => {
847
+ const { agentId, input, headers, config: config2 } = params;
848
+ try {
849
+ const client = this.getClient(config2);
850
+ const runtime = new $Util.RuntimeOptions({});
851
+ const response = await client.listAgentRuntimeVersionsWithOptions(
852
+ agentId,
853
+ input,
854
+ headers ?? {},
855
+ runtime
856
+ );
857
+ logger.debug(
858
+ `request api listAgentRuntimeVersions, request Request ID: ${response.body?.requestId}
859
+ request: ${JSON.stringify([agentId, input])}
860
+ response: ${JSON.stringify(response.body?.data)}`
861
+ );
862
+ return response.body?.data;
863
+ } catch (error) {
864
+ if (error && typeof error === "object" && "statusCode" in error) {
865
+ const e = error;
866
+ const statusCode = e.statusCode;
867
+ const message = e.message || "Unknown error";
868
+ const requestId = e.data?.requestId;
869
+ if (statusCode >= 400 && statusCode < 500) {
870
+ throw new ClientError(statusCode, message, { requestId });
871
+ } else if (statusCode >= 500) {
872
+ throw new ServerError(statusCode, message, { requestId });
873
+ }
874
+ }
875
+ throw error;
876
+ }
877
+ };
878
+ };
879
+
880
+ export { AgentRuntimeControlAPI };
881
+ //# sourceMappingURL=index.js.map
882
+ //# sourceMappingURL=index.js.map