@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,630 @@
1
+ import * as $AgentRun 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
+ $AgentRun.default?.default ?? $AgentRun.default ?? $AgentRun
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/credential/api/control.ts
424
+ var CredentialControlAPI = class extends ControlAPI {
425
+ constructor(config2) {
426
+ super(config2);
427
+ }
428
+ /**
429
+ * Create credential
430
+ *
431
+ * @param params - Method parameters
432
+ * @param params.input - Credential configuration
433
+ * @param params.headers - Custom request headers
434
+ * @param params.config - Optional config override
435
+ * @returns Created credential object
436
+ */
437
+ createCredential = 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.createCredentialWithOptions(
443
+ new $AgentRun.CreateCredentialRequest({ body: input }),
444
+ headers ?? {},
445
+ runtime
446
+ );
447
+ logger.debug(
448
+ `request api createCredential, 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 credential
470
+ *
471
+ * @param params - Method parameters
472
+ * @param params.credentialName - Credential name
473
+ * @param params.headers - Custom request headers
474
+ * @param params.config - Optional config override
475
+ * @returns Deleted credential object
476
+ */
477
+ deleteCredential = async (params) => {
478
+ const { credentialName, headers, config: config2 } = params;
479
+ try {
480
+ const client = this.getClient(config2);
481
+ const runtime = new $Util.RuntimeOptions({});
482
+ const response = await client.deleteCredentialWithOptions(
483
+ credentialName,
484
+ headers ?? {},
485
+ runtime
486
+ );
487
+ logger.debug(
488
+ `request api deleteCredential, request Request ID: ${response.body?.requestId}
489
+ request: ${JSON.stringify([credentialName])}
490
+ response: ${JSON.stringify(response.body?.data)}`
491
+ );
492
+ return response.body?.data;
493
+ } catch (error) {
494
+ if (error && typeof error === "object" && "statusCode" in error) {
495
+ const e = error;
496
+ const statusCode = e.statusCode;
497
+ const message = e.message || "Unknown error";
498
+ const requestId = e.data?.requestId;
499
+ if (statusCode >= 400 && statusCode < 500) {
500
+ throw new ClientError(statusCode, message, { requestId });
501
+ } else if (statusCode >= 500) {
502
+ throw new ServerError(statusCode, message, { requestId });
503
+ }
504
+ }
505
+ throw error;
506
+ }
507
+ };
508
+ /**
509
+ * Update credential
510
+ *
511
+ * @param params - Method parameters
512
+ * @param params.credentialName - Credential name
513
+ * @param params.input - Credential configuration
514
+ * @param params.headers - Custom request headers
515
+ * @param params.config - Optional config override
516
+ * @returns Updated credential object
517
+ */
518
+ updateCredential = async (params) => {
519
+ const { credentialName, input, headers, config: config2 } = params;
520
+ try {
521
+ const client = this.getClient(config2);
522
+ const runtime = new $Util.RuntimeOptions({});
523
+ const response = await client.updateCredentialWithOptions(
524
+ credentialName,
525
+ new $AgentRun.UpdateCredentialRequest({ body: input }),
526
+ headers ?? {},
527
+ runtime
528
+ );
529
+ logger.debug(
530
+ `request api updateCredential, request Request ID: ${response.body?.requestId}
531
+ request: ${JSON.stringify([credentialName, input])}
532
+ response: ${JSON.stringify(response.body?.data)}`
533
+ );
534
+ return response.body?.data;
535
+ } catch (error) {
536
+ if (error && typeof error === "object" && "statusCode" in error) {
537
+ const e = error;
538
+ const statusCode = e.statusCode;
539
+ const message = e.message || "Unknown error";
540
+ const requestId = e.data?.requestId;
541
+ if (statusCode >= 400 && statusCode < 500) {
542
+ throw new ClientError(statusCode, message, { requestId });
543
+ } else if (statusCode >= 500) {
544
+ throw new ServerError(statusCode, message, { requestId });
545
+ }
546
+ }
547
+ throw error;
548
+ }
549
+ };
550
+ /**
551
+ * Get credential
552
+ *
553
+ * @param params - Method parameters
554
+ * @param params.credentialName - Credential name
555
+ * @param params.headers - Custom request headers
556
+ * @param params.config - Optional config override
557
+ * @returns Credential object
558
+ */
559
+ getCredential = async (params) => {
560
+ const { credentialName, headers, config: config2 } = params;
561
+ try {
562
+ const client = this.getClient(config2);
563
+ const runtime = new $Util.RuntimeOptions({});
564
+ const response = await client.getCredentialWithOptions(
565
+ credentialName,
566
+ headers ?? {},
567
+ runtime
568
+ );
569
+ logger.debug(
570
+ `request api getCredential, request Request ID: ${response.body?.requestId}
571
+ request: ${JSON.stringify([credentialName])}
572
+ response: ${JSON.stringify(response.body?.data)}`
573
+ );
574
+ return response.body?.data;
575
+ } catch (error) {
576
+ if (error && typeof error === "object" && "statusCode" in error) {
577
+ const e = error;
578
+ const statusCode = e.statusCode;
579
+ const message = e.message || "Unknown error";
580
+ const requestId = e.data?.requestId;
581
+ if (statusCode >= 400 && statusCode < 500) {
582
+ throw new ClientError(statusCode, message, { requestId });
583
+ } else if (statusCode >= 500) {
584
+ throw new ServerError(statusCode, message, { requestId });
585
+ }
586
+ }
587
+ throw error;
588
+ }
589
+ };
590
+ /**
591
+ * List credentials
592
+ *
593
+ * @param params - Method parameters
594
+ * @param params.input - List options
595
+ * @param params.headers - Custom request headers
596
+ * @param params.config - Optional config override
597
+ * @returns List of credential objects
598
+ */
599
+ listCredentials = async (params) => {
600
+ const { input, headers, config: config2 } = params;
601
+ try {
602
+ const client = this.getClient(config2);
603
+ const runtime = new $Util.RuntimeOptions({});
604
+ const response = await client.listCredentialsWithOptions(input, headers ?? {}, runtime);
605
+ logger.debug(
606
+ `request api listCredentials, request Request ID: ${response.body?.requestId}
607
+ request: ${JSON.stringify([input])}
608
+ response: ${JSON.stringify(response.body?.data)}`
609
+ );
610
+ return response.body?.data;
611
+ } catch (error) {
612
+ if (error && typeof error === "object" && "statusCode" in error) {
613
+ const e = error;
614
+ const statusCode = e.statusCode;
615
+ const message = e.message || "Unknown error";
616
+ const requestId = e.data?.requestId;
617
+ if (statusCode >= 400 && statusCode < 500) {
618
+ throw new ClientError(statusCode, message, { requestId });
619
+ } else if (statusCode >= 500) {
620
+ throw new ServerError(statusCode, message, { requestId });
621
+ }
622
+ }
623
+ throw error;
624
+ }
625
+ };
626
+ };
627
+
628
+ export { CredentialControlAPI };
629
+ //# sourceMappingURL=index.js.map
630
+ //# sourceMappingURL=index.js.map