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