@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,1263 @@
1
+ import * as dotenv from 'dotenv';
2
+ import * as $AgentRun from '@alicloud/agentrun20250910';
3
+ import * as $OpenApi from '@alicloud/openapi-client';
4
+ import * as $Util from '@alicloud/tea-util';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+
16
+ // src/utils/log.ts
17
+ var LOG_LEVELS, COLORS, Logger, logger;
18
+ var init_log = __esm({
19
+ "src/utils/log.ts"() {
20
+ LOG_LEVELS = {
21
+ debug: 0,
22
+ info: 1,
23
+ warn: 2,
24
+ error: 3
25
+ };
26
+ COLORS = {
27
+ reset: "\x1B[0m",
28
+ bright: "\x1B[1m",
29
+ dim: "\x1B[2m",
30
+ italic: "\x1B[3m",
31
+ blue: "\x1B[34m",
32
+ cyan: "\x1B[36m",
33
+ yellow: "\x1B[33m",
34
+ red: "\x1B[31m"
35
+ };
36
+ Logger = class {
37
+ level = "info";
38
+ // match Python logger name
39
+ prefix = "agentrun-logger";
40
+ setLevel(level) {
41
+ this.level = level;
42
+ }
43
+ shouldLog(level) {
44
+ return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
45
+ }
46
+ getColor(level) {
47
+ switch (level) {
48
+ case "debug":
49
+ return COLORS.cyan;
50
+ case "info":
51
+ return COLORS.blue;
52
+ case "warn":
53
+ return COLORS.yellow;
54
+ case "error":
55
+ return COLORS.red;
56
+ default:
57
+ return COLORS.reset;
58
+ }
59
+ }
60
+ // format timestamp like Python: YYYY-MM-DD HH:mm:ss,SSS
61
+ formatTimestamp(d = /* @__PURE__ */ new Date()) {
62
+ const pad = (n, sz = 2) => n.toString().padStart(sz, "0");
63
+ const year = d.getFullYear();
64
+ const month = pad(d.getMonth() + 1);
65
+ const day = pad(d.getDate());
66
+ const hour = pad(d.getHours());
67
+ const minute = pad(d.getMinutes());
68
+ const second = pad(d.getSeconds());
69
+ const ms = pad(d.getMilliseconds(), 3);
70
+ return `${year}-${month}-${day} ${hour}:${minute}:${second},${ms}`;
71
+ }
72
+ // attempt to infer caller file and line by parsing Error.stack
73
+ // helper: parse a single stack frame into {filepath, line, functionName}
74
+ parseFrame(frame) {
75
+ const m = frame.match(/^(?:at\s+)?(?:(.+?)\s+\()?(.*?):(\d+):(\d+)\)?$/);
76
+ if (!m) return null;
77
+ return {
78
+ functionName: m[1] ? m[1].trim() : void 0,
79
+ filepath: m[2],
80
+ line: parseInt(m[3], 10)
81
+ };
82
+ }
83
+ // get caller by fixed stack offset (used in public log methods)
84
+ getCallerByOffset() {
85
+ const err = new Error();
86
+ const stack = err.stack;
87
+ if (!stack) return {};
88
+ const lines = stack.split("\n").map((l) => l.trim());
89
+ for (let i = 3; i < lines.length; i++) {
90
+ let parsed = this.parseFrame(lines[i]);
91
+ if (!parsed) {
92
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
93
+ if (m) {
94
+ const parts = m[1].split(":");
95
+ parts.pop();
96
+ const ln = Number(parts.pop());
97
+ const fp2 = parts.join(":");
98
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
99
+ }
100
+ }
101
+ if (!parsed) continue;
102
+ const fp = parsed.filepath;
103
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
104
+ continue;
105
+ return { filepath: parsed.filepath, line: parsed.line };
106
+ }
107
+ const cwd = process.cwd();
108
+ for (let i = 0; i < lines.length; i++) {
109
+ let parsed = this.parseFrame(lines[i]);
110
+ if (!parsed) {
111
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
112
+ if (m) {
113
+ const parts = m[1].split(":");
114
+ parts.pop();
115
+ const ln = Number(parts.pop());
116
+ const fp2 = parts.join(":");
117
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
118
+ }
119
+ }
120
+ if (!parsed) continue;
121
+ const fp = parsed.filepath;
122
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
123
+ continue;
124
+ if (fp.includes("/src/utils/log.ts")) continue;
125
+ if (fp.startsWith(cwd)) return { filepath: parsed.filepath, line: parsed.line };
126
+ }
127
+ for (let i = 0; i < lines.length; i++) {
128
+ let parsed = this.parseFrame(lines[i]);
129
+ if (!parsed) {
130
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
131
+ if (m) {
132
+ const parts = m[1].split(":");
133
+ parts.pop();
134
+ const ln = Number(parts.pop());
135
+ const fp2 = parts.join(":");
136
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
137
+ }
138
+ }
139
+ if (!parsed) continue;
140
+ const fp = parsed.filepath;
141
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
142
+ continue;
143
+ if (fp.includes("/src/utils/log.ts")) continue;
144
+ return { filepath: parsed.filepath, line: parsed.line };
145
+ }
146
+ return {};
147
+ }
148
+ formatMessage(level, message, filepath, line) {
149
+ const timestamp = this.formatTimestamp();
150
+ const color = this.getColor(level);
151
+ const reset = COLORS.reset;
152
+ const levelName = level === "warn" ? "WARNING" : level.toUpperCase();
153
+ const levelStr = `${COLORS.bright}${color}${levelName}${reset}`;
154
+ const nameStr = `${color}[${this.prefix}]${reset}`;
155
+ const tsStr = `${color} ${timestamp}${reset}`;
156
+ const pathInfo = filepath && line !== void 0 ? ` ${COLORS.dim}${COLORS.italic}${filepath}:${line}${reset}` : "";
157
+ const msg = level === "debug" ? `${COLORS.dim}${message}${reset}` : message;
158
+ return `
159
+ ${levelStr} ${nameStr}${tsStr}${pathInfo}
160
+ ${msg}
161
+ `;
162
+ }
163
+ debug(message, ...args) {
164
+ if (this.shouldLog("debug")) {
165
+ const caller = this.getCallerByOffset();
166
+ console.debug(this.formatMessage("debug", message, caller.filepath, caller.line), ...args);
167
+ }
168
+ }
169
+ info(message, ...args) {
170
+ if (this.shouldLog("info")) {
171
+ const caller = this.getCallerByOffset();
172
+ console.info(this.formatMessage("info", message, caller.filepath, caller.line), ...args);
173
+ }
174
+ }
175
+ warn(message, ...args) {
176
+ if (this.shouldLog("warn")) {
177
+ const caller = this.getCallerByOffset();
178
+ console.warn(this.formatMessage("warn", message, caller.filepath, caller.line), ...args);
179
+ }
180
+ }
181
+ error(message, ...args) {
182
+ if (this.shouldLog("error")) {
183
+ const caller = this.getCallerByOffset();
184
+ console.error(this.formatMessage("error", message, caller.filepath, caller.line), ...args);
185
+ }
186
+ }
187
+ };
188
+ logger = new Logger();
189
+ if (![void 0, null, "", "False", "FALSE", "false", "0"].includes(process.env["AGENTRUN_SDK_DEBUG"])) {
190
+ logger.setLevel("debug");
191
+ if (!globalThis._AGENTRUN_DEBUG_LOGGED) {
192
+ logger.warn("\u542F\u7528 AgentRun SDK \u8C03\u8BD5\u65E5\u5FD7\uFF0C \u79FB\u9664 AGENTRUN_SDK_DEBUG \u73AF\u5883\u53D8\u91CF\u4EE5\u5173\u95ED");
193
+ globalThis._AGENTRUN_DEBUG_LOGGED = true;
194
+ }
195
+ } else {
196
+ logger.setLevel("info");
197
+ }
198
+ }
199
+ });
200
+
201
+ // src/utils/version-check.ts
202
+ var VERSION;
203
+ var init_version_check = __esm({
204
+ "src/utils/version-check.ts"() {
205
+ init_log();
206
+ VERSION = "0.0.4" ;
207
+ if (!process.env.DISABLE_BREAKING_CHANGES_WARNING && !globalThis._AGENTRUN_VERSION_WARNING_SHOWN) {
208
+ globalThis._AGENTRUN_VERSION_WARNING_SHOWN = true;
209
+ logger.warn(
210
+ `\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
211
+ 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.
212
+ \x1B[2;3m pip install 'agentrun-sdk==${VERSION}' \x1B[0m
213
+
214
+ \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
215
+ Add\x1B[2;3m DISABLE_BREAKING_CHANGES_WARNING=1 \x1B[0mto your environment variables to disable this warning.
216
+
217
+ Releases:\x1B[2;3m https://github.com/Serverless-Devs/agentrun-sdk-python/releases\x1B[0m`
218
+ );
219
+ }
220
+ }
221
+ });
222
+ function getEnvWithDefault(defaultValue, ...keys) {
223
+ for (const key of keys) {
224
+ const value = process.env[key];
225
+ if (value !== void 0 && value !== "") {
226
+ return value;
227
+ }
228
+ }
229
+ return defaultValue;
230
+ }
231
+ var Config;
232
+ var init_config = __esm({
233
+ "src/utils/config.ts"() {
234
+ dotenv.config();
235
+ Config = class _Config {
236
+ _accessKeyId;
237
+ _accessKeySecret;
238
+ _securityToken;
239
+ _accountId;
240
+ _token;
241
+ _regionId;
242
+ _timeout;
243
+ _readTimeout;
244
+ _controlEndpoint;
245
+ _dataEndpoint;
246
+ _devsEndpoint;
247
+ _headers;
248
+ constructor(options = {}) {
249
+ this._accessKeyId = options.accessKeyId ?? getEnvWithDefault("", "AGENTRUN_ACCESS_KEY_ID", "ALIBABA_CLOUD_ACCESS_KEY_ID");
250
+ this._accessKeySecret = options.accessKeySecret ?? getEnvWithDefault("", "AGENTRUN_ACCESS_KEY_SECRET", "ALIBABA_CLOUD_ACCESS_KEY_SECRET");
251
+ this._securityToken = options.securityToken ?? getEnvWithDefault("", "AGENTRUN_SECURITY_TOKEN", "ALIBABA_CLOUD_SECURITY_TOKEN");
252
+ this._accountId = options.accountId ?? getEnvWithDefault("", "AGENTRUN_ACCOUNT_ID", "FC_ACCOUNT_ID");
253
+ this._token = options.token;
254
+ this._regionId = options.regionId ?? getEnvWithDefault("cn-hangzhou", "AGENTRUN_REGION", "FC_REGION");
255
+ this._timeout = options.timeout ?? 6e5;
256
+ this._readTimeout = options.readTimeout ?? 1e8;
257
+ this._controlEndpoint = options.controlEndpoint ?? getEnvWithDefault("", "AGENTRUN_CONTROL_ENDPOINT");
258
+ this._dataEndpoint = options.dataEndpoint ?? getEnvWithDefault("", "AGENTRUN_DATA_ENDPOINT");
259
+ this._devsEndpoint = options.devsEndpoint ?? getEnvWithDefault("", "DEVS_ENDPOINT");
260
+ this._headers = options.headers ?? {};
261
+ }
262
+ /**
263
+ * Create a new Config by merging multiple configs.
264
+ * Later configs take precedence.
265
+ */
266
+ static withConfigs(...configs) {
267
+ return new _Config().update(...configs);
268
+ }
269
+ /**
270
+ * Update this config with values from other configs.
271
+ * Non-undefined values from later configs take precedence.
272
+ */
273
+ update(...configs) {
274
+ for (const config2 of configs) {
275
+ if (!config2) continue;
276
+ if (config2._accessKeyId) this._accessKeyId = config2._accessKeyId;
277
+ if (config2._accessKeySecret) this._accessKeySecret = config2._accessKeySecret;
278
+ if (config2._securityToken) this._securityToken = config2._securityToken;
279
+ if (config2._accountId) this._accountId = config2._accountId;
280
+ if (config2._token) this._token = config2._token;
281
+ if (config2._regionId) this._regionId = config2._regionId;
282
+ if (config2._timeout) this._timeout = config2._timeout;
283
+ if (config2._readTimeout) this._readTimeout = config2._readTimeout;
284
+ if (config2._controlEndpoint) this._controlEndpoint = config2._controlEndpoint;
285
+ if (config2._dataEndpoint) this._dataEndpoint = config2._dataEndpoint;
286
+ if (config2._devsEndpoint) this._devsEndpoint = config2._devsEndpoint;
287
+ if (config2._headers && Object.keys(config2._headers).length > 0) {
288
+ this._headers = { ...this._headers, ...config2._headers };
289
+ }
290
+ }
291
+ return this;
292
+ }
293
+ get accessKeyId() {
294
+ return this._accessKeyId;
295
+ }
296
+ get accessKeySecret() {
297
+ return this._accessKeySecret;
298
+ }
299
+ get securityToken() {
300
+ return this._securityToken;
301
+ }
302
+ get accountId() {
303
+ if (!this._accountId) {
304
+ throw new Error(
305
+ "Account ID is not set. Please add AGENTRUN_ACCOUNT_ID environment variable or set it in code."
306
+ );
307
+ }
308
+ return this._accountId;
309
+ }
310
+ get token() {
311
+ return this._token;
312
+ }
313
+ get regionId() {
314
+ return this._regionId || "cn-hangzhou";
315
+ }
316
+ get timeout() {
317
+ return this._timeout || 6e5;
318
+ }
319
+ get readTimeout() {
320
+ return this._readTimeout || 1e8;
321
+ }
322
+ get controlEndpoint() {
323
+ if (this._controlEndpoint) {
324
+ return this._controlEndpoint;
325
+ }
326
+ return `https://agentrun.${this.regionId}.aliyuncs.com`;
327
+ }
328
+ get dataEndpoint() {
329
+ if (this._dataEndpoint) {
330
+ return this._dataEndpoint;
331
+ }
332
+ return `https://${this.accountId}.agentrun-data.${this.regionId}.aliyuncs.com`;
333
+ }
334
+ get devsEndpoint() {
335
+ if (this._devsEndpoint) {
336
+ return this._devsEndpoint;
337
+ }
338
+ return `https://devs.${this.regionId}.aliyuncs.com`;
339
+ }
340
+ get headers() {
341
+ return this._headers;
342
+ }
343
+ };
344
+ }
345
+ });
346
+
347
+ // src/utils/exception.ts
348
+ var AgentRunError, HTTPError, ClientError, ServerError, ResourceNotExistError, ResourceAlreadyExistError;
349
+ var init_exception = __esm({
350
+ "src/utils/exception.ts"() {
351
+ AgentRunError = class _AgentRunError extends Error {
352
+ constructor(message) {
353
+ super(message);
354
+ this.name = "AgentRunError";
355
+ Object.setPrototypeOf(this, _AgentRunError.prototype);
356
+ }
357
+ };
358
+ HTTPError = class _HTTPError extends AgentRunError {
359
+ statusCode;
360
+ requestId;
361
+ errorCode;
362
+ constructor(statusCode, message, options) {
363
+ super(message);
364
+ this.name = "HTTPError";
365
+ this.statusCode = statusCode;
366
+ this.requestId = options?.requestId;
367
+ this.errorCode = options?.errorCode;
368
+ Object.setPrototypeOf(this, _HTTPError.prototype);
369
+ }
370
+ /**
371
+ * Convert HTTP error to resource-specific error based on status code
372
+ */
373
+ toResourceError(resourceType, resourceId) {
374
+ if (this.statusCode == 404) return new ResourceNotExistError(resourceType, resourceId);
375
+ else if (this.statusCode == 409) return new ResourceAlreadyExistError(resourceType, resourceId);
376
+ else if ((this.statusCode == 400 || this.statusCode == 500) && this.message.includes("already exists"))
377
+ return new ResourceAlreadyExistError(resourceType, resourceId);
378
+ else return this;
379
+ }
380
+ };
381
+ ClientError = class _ClientError extends HTTPError {
382
+ constructor(statusCode, message, options) {
383
+ super(statusCode, message, options);
384
+ this.name = "ClientError";
385
+ Object.setPrototypeOf(this, _ClientError.prototype);
386
+ }
387
+ };
388
+ ServerError = class _ServerError extends HTTPError {
389
+ constructor(statusCode, message, options) {
390
+ super(statusCode, message, options);
391
+ this.name = "ServerError";
392
+ Object.setPrototypeOf(this, _ServerError.prototype);
393
+ }
394
+ };
395
+ ResourceNotExistError = class _ResourceNotExistError extends ClientError {
396
+ resourceType;
397
+ resourceId;
398
+ constructor(resourceType, resourceId, options) {
399
+ const message = resourceId ? `${resourceType} '${resourceId}' does not exist` : `${resourceType} does not exist`;
400
+ super(404, message, options);
401
+ this.name = "ResourceNotExistError";
402
+ this.resourceType = resourceType;
403
+ this.resourceId = resourceId;
404
+ Object.setPrototypeOf(this, _ResourceNotExistError.prototype);
405
+ }
406
+ };
407
+ ResourceAlreadyExistError = class _ResourceAlreadyExistError extends ClientError {
408
+ resourceType;
409
+ resourceId;
410
+ constructor(resourceType, resourceId, options) {
411
+ const message = resourceId ? `${resourceType} '${resourceId}' already exists` : `${resourceType} already exists`;
412
+ super(409, message, options);
413
+ this.name = "ResourceAlreadyExistError";
414
+ this.resourceType = resourceType;
415
+ this.resourceId = resourceId;
416
+ Object.setPrototypeOf(this, _ResourceAlreadyExistError.prototype);
417
+ }
418
+ };
419
+ }
420
+ });
421
+
422
+ // src/utils/data-api.ts
423
+ var init_data_api = __esm({
424
+ "src/utils/data-api.ts"() {
425
+ init_config();
426
+ init_exception();
427
+ init_log();
428
+ }
429
+ });
430
+
431
+ // src/utils/model.ts
432
+ function isFinalStatus(status) {
433
+ return [
434
+ void 0,
435
+ null,
436
+ "",
437
+ ...["READY", "CREATE_FAILED", "UPDATE_FAILED", "DELETE_FAILED"]
438
+ ].includes(status);
439
+ }
440
+ var Status;
441
+ var init_model = __esm({
442
+ "src/utils/model.ts"() {
443
+ Status = {
444
+ CREATING: "CREATING",
445
+ CREATE_FAILED: "CREATE_FAILED",
446
+ READY: "READY",
447
+ UPDATING: "UPDATING",
448
+ UPDATE_FAILED: "UPDATE_FAILED",
449
+ DELETING: "DELETING",
450
+ DELETE_FAILED: "DELETE_FAILED"
451
+ };
452
+ }
453
+ });
454
+
455
+ // src/utils/index.ts
456
+ var init_utils = __esm({
457
+ "src/utils/index.ts"() {
458
+ init_version_check();
459
+ init_config();
460
+ init_data_api();
461
+ init_exception();
462
+ init_log();
463
+ init_model();
464
+ }
465
+ });
466
+ var $AgentRunClient, ControlAPI;
467
+ var init_control_api = __esm({
468
+ "src/utils/control-api.ts"() {
469
+ init_config();
470
+ $AgentRunClient = // @ts-expect-error - ESM interop: default.default exists when imported as ESM namespace
471
+ $AgentRun.default?.default ?? $AgentRun.default ?? $AgentRun;
472
+ ControlAPI = class {
473
+ config;
474
+ constructor(config2) {
475
+ this.config = config2;
476
+ }
477
+ /**
478
+ * Get the underlying AgentRun client instance
479
+ */
480
+ getClient(config2) {
481
+ const cfg = Config.withConfigs(this.config, config2);
482
+ let endpoint = cfg.controlEndpoint;
483
+ if (endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
484
+ endpoint = endpoint.split("://")[1];
485
+ }
486
+ const openApiConfig = new $OpenApi.Config({
487
+ accessKeyId: cfg.accessKeyId,
488
+ accessKeySecret: cfg.accessKeySecret,
489
+ securityToken: cfg.securityToken || void 0,
490
+ regionId: cfg.regionId,
491
+ endpoint,
492
+ connectTimeout: cfg.timeout,
493
+ readTimeout: cfg.readTimeout
494
+ });
495
+ return new $AgentRunClient(openApiConfig);
496
+ }
497
+ };
498
+ }
499
+ });
500
+ var CredentialControlAPI;
501
+ var init_control = __esm({
502
+ "src/credential/api/control.ts"() {
503
+ init_control_api();
504
+ init_exception();
505
+ init_log();
506
+ CredentialControlAPI = class extends ControlAPI {
507
+ constructor(config2) {
508
+ super(config2);
509
+ }
510
+ /**
511
+ * Create credential
512
+ *
513
+ * @param params - Method parameters
514
+ * @param params.input - Credential configuration
515
+ * @param params.headers - Custom request headers
516
+ * @param params.config - Optional config override
517
+ * @returns Created credential object
518
+ */
519
+ createCredential = async (params) => {
520
+ const { input, headers, config: config2 } = params;
521
+ try {
522
+ const client = this.getClient(config2);
523
+ const runtime = new $Util.RuntimeOptions({});
524
+ const response = await client.createCredentialWithOptions(
525
+ new $AgentRun.CreateCredentialRequest({ body: input }),
526
+ headers ?? {},
527
+ runtime
528
+ );
529
+ logger.debug(
530
+ `request api createCredential, request Request ID: ${response.body?.requestId}
531
+ request: ${JSON.stringify([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
+ * Delete 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 Deleted credential object
558
+ */
559
+ deleteCredential = 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.deleteCredentialWithOptions(
565
+ credentialName,
566
+ headers ?? {},
567
+ runtime
568
+ );
569
+ logger.debug(
570
+ `request api deleteCredential, 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
+ * Update credential
592
+ *
593
+ * @param params - Method parameters
594
+ * @param params.credentialName - Credential name
595
+ * @param params.input - Credential configuration
596
+ * @param params.headers - Custom request headers
597
+ * @param params.config - Optional config override
598
+ * @returns Updated credential object
599
+ */
600
+ updateCredential = async (params) => {
601
+ const { credentialName, input, headers, config: config2 } = params;
602
+ try {
603
+ const client = this.getClient(config2);
604
+ const runtime = new $Util.RuntimeOptions({});
605
+ const response = await client.updateCredentialWithOptions(
606
+ credentialName,
607
+ new $AgentRun.UpdateCredentialRequest({ body: input }),
608
+ headers ?? {},
609
+ runtime
610
+ );
611
+ logger.debug(
612
+ `request api updateCredential, request Request ID: ${response.body?.requestId}
613
+ request: ${JSON.stringify([credentialName, input])}
614
+ response: ${JSON.stringify(response.body?.data)}`
615
+ );
616
+ return response.body?.data;
617
+ } catch (error) {
618
+ if (error && typeof error === "object" && "statusCode" in error) {
619
+ const e = error;
620
+ const statusCode = e.statusCode;
621
+ const message = e.message || "Unknown error";
622
+ const requestId = e.data?.requestId;
623
+ if (statusCode >= 400 && statusCode < 500) {
624
+ throw new ClientError(statusCode, message, { requestId });
625
+ } else if (statusCode >= 500) {
626
+ throw new ServerError(statusCode, message, { requestId });
627
+ }
628
+ }
629
+ throw error;
630
+ }
631
+ };
632
+ /**
633
+ * Get credential
634
+ *
635
+ * @param params - Method parameters
636
+ * @param params.credentialName - Credential name
637
+ * @param params.headers - Custom request headers
638
+ * @param params.config - Optional config override
639
+ * @returns Credential object
640
+ */
641
+ getCredential = async (params) => {
642
+ const { credentialName, headers, config: config2 } = params;
643
+ try {
644
+ const client = this.getClient(config2);
645
+ const runtime = new $Util.RuntimeOptions({});
646
+ const response = await client.getCredentialWithOptions(
647
+ credentialName,
648
+ headers ?? {},
649
+ runtime
650
+ );
651
+ logger.debug(
652
+ `request api getCredential, request Request ID: ${response.body?.requestId}
653
+ request: ${JSON.stringify([credentialName])}
654
+ response: ${JSON.stringify(response.body?.data)}`
655
+ );
656
+ return response.body?.data;
657
+ } catch (error) {
658
+ if (error && typeof error === "object" && "statusCode" in error) {
659
+ const e = error;
660
+ const statusCode = e.statusCode;
661
+ const message = e.message || "Unknown error";
662
+ const requestId = e.data?.requestId;
663
+ if (statusCode >= 400 && statusCode < 500) {
664
+ throw new ClientError(statusCode, message, { requestId });
665
+ } else if (statusCode >= 500) {
666
+ throw new ServerError(statusCode, message, { requestId });
667
+ }
668
+ }
669
+ throw error;
670
+ }
671
+ };
672
+ /**
673
+ * List credentials
674
+ *
675
+ * @param params - Method parameters
676
+ * @param params.input - List options
677
+ * @param params.headers - Custom request headers
678
+ * @param params.config - Optional config override
679
+ * @returns List of credential objects
680
+ */
681
+ listCredentials = async (params) => {
682
+ const { input, headers, config: config2 } = params;
683
+ try {
684
+ const client = this.getClient(config2);
685
+ const runtime = new $Util.RuntimeOptions({});
686
+ const response = await client.listCredentialsWithOptions(input, headers ?? {}, runtime);
687
+ logger.debug(
688
+ `request api listCredentials, request Request ID: ${response.body?.requestId}
689
+ request: ${JSON.stringify([input])}
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
+ }
710
+ });
711
+
712
+ // src/utils/resource.ts
713
+ function updateObjectProperties(target, source) {
714
+ for (const key in source) {
715
+ if (Object.prototype.hasOwnProperty.call(source, key) && typeof source[key] !== "function" && !key.startsWith("_")) {
716
+ target[key] = source[key];
717
+ }
718
+ }
719
+ }
720
+ function listAllResourcesFunction(list) {
721
+ return async (params) => {
722
+ const { config: config2, ...restParams } = params ?? {};
723
+ const allResults = [];
724
+ let page = 1;
725
+ const pageSize = 50;
726
+ while (true) {
727
+ const pageResults = await list({
728
+ input: {
729
+ ...restParams,
730
+ pageNumber: page,
731
+ pageSize
732
+ },
733
+ config: config2
734
+ });
735
+ page += 1;
736
+ allResults.push(...pageResults);
737
+ if (pageResults.length < pageSize) break;
738
+ }
739
+ const resultSet = /* @__PURE__ */ new Set();
740
+ const results = [];
741
+ for (const item of allResults) {
742
+ const uniqId = item.uniqIdCallback() || "";
743
+ if (!resultSet.has(uniqId) && uniqId) {
744
+ resultSet.add(uniqId);
745
+ results.push(item);
746
+ }
747
+ }
748
+ return results;
749
+ };
750
+ }
751
+ var ResourceBase;
752
+ var init_resource = __esm({
753
+ "src/utils/resource.ts"() {
754
+ init_exception();
755
+ init_log();
756
+ init_model();
757
+ ResourceBase = class {
758
+ status;
759
+ _config;
760
+ // static async list(params?: {
761
+ // input?: PageableInput;
762
+ // config?: Config;
763
+ // }): Promise<WithUniqIdCallback[]> {
764
+ // return [];
765
+ // }
766
+ waitUntil = async (params) => {
767
+ const { checkFinishedCallback, intervalSeconds = 5, timeoutSeconds = 300 } = params;
768
+ const startTime = Date.now();
769
+ while (true) {
770
+ if (await checkFinishedCallback(this)) return this;
771
+ if (Date.now() - startTime >= timeoutSeconds * 1e3) {
772
+ throw new Error("Timeout waiting for resource to reach desired state");
773
+ }
774
+ await new Promise((resolve) => setTimeout(resolve, intervalSeconds * 1e3));
775
+ }
776
+ };
777
+ waitUntilReadyOrFailed = async (params) => {
778
+ const { callback, intervalSeconds = 5, timeoutSeconds = 300 } = params ?? {};
779
+ async function checkFinishedCallback(resource) {
780
+ await resource.refresh();
781
+ if (callback) await callback(resource);
782
+ logger.debug(`Resource status: ${resource.status}`);
783
+ return isFinalStatus(resource.status);
784
+ }
785
+ return await this.waitUntil({
786
+ checkFinishedCallback,
787
+ intervalSeconds,
788
+ timeoutSeconds
789
+ });
790
+ };
791
+ deleteAndWaitUntilFinished = async (params) => {
792
+ const { callback, intervalSeconds = 5, timeoutSeconds = 300 } = params ?? {};
793
+ try {
794
+ await this.delete();
795
+ } catch (error) {
796
+ if (error instanceof ResourceNotExistError) return;
797
+ }
798
+ async function checkFinishedCallback(resource) {
799
+ try {
800
+ await resource.refresh();
801
+ if (callback) await callback(resource);
802
+ } catch (error) {
803
+ if (error instanceof ResourceNotExistError) return true;
804
+ if (resource.status === Status.DELETING) return false;
805
+ throw Error(`Resource status is ${resource.status}`);
806
+ }
807
+ return false;
808
+ }
809
+ return await this.waitUntil({
810
+ checkFinishedCallback,
811
+ intervalSeconds,
812
+ timeoutSeconds
813
+ });
814
+ };
815
+ refresh = async (params) => await this.get(params);
816
+ /**
817
+ * 更新实例自身的属性 / Update instance properties
818
+ *
819
+ * @param source - 源对象 / Source object
820
+ */
821
+ updateSelf(source) {
822
+ updateObjectProperties(this, source);
823
+ }
824
+ setConfig = (config2) => {
825
+ this._config = config2;
826
+ return this;
827
+ };
828
+ };
829
+ }
830
+ });
831
+
832
+ // src/credential/credential.ts
833
+ var Credential;
834
+ var init_credential = __esm({
835
+ "src/credential/credential.ts"() {
836
+ init_resource();
837
+ init_resource();
838
+ init_client();
839
+ Credential = class _Credential extends ResourceBase {
840
+ credentialName;
841
+ /** 描述 */
842
+ description;
843
+ /** 是否启用 */
844
+ enabled;
845
+ credentialId;
846
+ createdAt;
847
+ updatedAt;
848
+ relatedResources;
849
+ /** 凭证认证类型 */
850
+ credentialAuthType;
851
+ /** 凭证来源类型 */
852
+ credentialSourceType;
853
+ /** 凭证公共配置 */
854
+ credentialPublicConfig;
855
+ /** 凭证密钥 */
856
+ credentialSecret;
857
+ _config;
858
+ constructor(data, config2) {
859
+ super();
860
+ if (data) updateObjectProperties(this, data);
861
+ this._config = config2;
862
+ }
863
+ static getClient = () => {
864
+ return new CredentialClient();
865
+ };
866
+ /**
867
+ * Create a new Credential
868
+ */
869
+ static create = async (paramsOrInput) => {
870
+ const hasInputProp = paramsOrInput && paramsOrInput.input !== void 0;
871
+ const input = hasInputProp ? paramsOrInput.input : paramsOrInput;
872
+ const config2 = hasInputProp ? paramsOrInput.config : void 0;
873
+ return await _Credential.getClient().create({ input, config: config2 });
874
+ };
875
+ /**
876
+ * Delete a Credential by name
877
+ */
878
+ static delete = async (paramsOrName) => {
879
+ const isString = typeof paramsOrName === "string";
880
+ const name = isString ? paramsOrName : paramsOrName.name;
881
+ const config2 = isString ? void 0 : paramsOrName.config;
882
+ return await _Credential.getClient().delete({ name, config: config2 });
883
+ };
884
+ /**
885
+ * Update a Credential by name
886
+ */
887
+ static update = async (paramsOrName) => {
888
+ const name = paramsOrName.name;
889
+ const input = paramsOrName.input;
890
+ const config2 = paramsOrName.config;
891
+ return await _Credential.getClient().update({ name, input, config: config2 });
892
+ };
893
+ /**
894
+ * Get a Credential by name
895
+ */
896
+ static get = async (paramsOrName) => {
897
+ const isString = typeof paramsOrName === "string";
898
+ const name = isString ? paramsOrName : paramsOrName.name;
899
+ const config2 = isString ? void 0 : paramsOrName.config;
900
+ return await _Credential.getClient().get({ name, config: config2 });
901
+ };
902
+ /**
903
+ * List all Credentials (with pagination)
904
+ */
905
+ static list = async (paramsOrUndefined) => {
906
+ const input = paramsOrUndefined?.input ?? paramsOrUndefined;
907
+ const config2 = paramsOrUndefined?.config;
908
+ return await _Credential.getClient().list({ input, config: config2 });
909
+ };
910
+ static listAll = listAllResourcesFunction(this.list);
911
+ /**
912
+ * Delete this credential
913
+ */
914
+ delete = async (params) => {
915
+ const config2 = params?.config;
916
+ if (!this.credentialName) {
917
+ throw new Error("credentialName is required to delete a Credential");
918
+ }
919
+ const result = await _Credential.delete({
920
+ name: this.credentialName,
921
+ config: config2 ?? this._config
922
+ });
923
+ updateObjectProperties(this, result);
924
+ return this;
925
+ };
926
+ /**
927
+ * Update this credential
928
+ */
929
+ update = async (params) => {
930
+ const hasInputProp = params && params.input !== void 0;
931
+ const input = hasInputProp ? params.input : params;
932
+ const config2 = hasInputProp ? params.config : void 0;
933
+ if (!this.credentialName) {
934
+ throw new Error("credentialName is required to update a Credential");
935
+ }
936
+ const result = await _Credential.update({
937
+ name: this.credentialName,
938
+ input,
939
+ config: config2 ?? this._config
940
+ });
941
+ updateObjectProperties(this, result);
942
+ return this;
943
+ };
944
+ /**
945
+ * Refresh this credential's data
946
+ */
947
+ get = async (params) => {
948
+ const config2 = params?.config;
949
+ if (!this.credentialName) {
950
+ throw new Error("credentialName is required to refresh a Credential");
951
+ }
952
+ const result = await _Credential.get({
953
+ name: this.credentialName,
954
+ config: config2 ?? this._config
955
+ });
956
+ updateObjectProperties(this, result);
957
+ return this;
958
+ };
959
+ };
960
+ }
961
+ });
962
+
963
+ // src/credential/model.ts
964
+ var CredentialConfig, CredentialListOutput;
965
+ var init_model2 = __esm({
966
+ "src/credential/model.ts"() {
967
+ init_resource();
968
+ CredentialConfig = class _CredentialConfig {
969
+ constructor(data) {
970
+ if (data) updateObjectProperties(this, data);
971
+ }
972
+ /** 配置访问 AgentRun 的 api key 凭证 */
973
+ static inboundApiKey(params) {
974
+ const { apiKey, headerKey = "Authorization" } = params;
975
+ return new _CredentialConfig({
976
+ credentialSourceType: "internal",
977
+ credentialAuthType: "api_key",
978
+ credentialPublicConfig: { headerKey },
979
+ credentialSecret: apiKey
980
+ });
981
+ }
982
+ /** 配置访问 AgentRun 的静态 JWKS 凭证 */
983
+ static inboundStaticJwt(params) {
984
+ const { jwks } = params;
985
+ return new _CredentialConfig({
986
+ credentialSourceType: "internal",
987
+ credentialAuthType: "jwt",
988
+ credentialPublicConfig: { authType: "static_jwks", jwks },
989
+ credentialSecret: ""
990
+ });
991
+ }
992
+ /** 配置访问 AgentRun 的远程 JWT 凭证 */
993
+ static inboundRemoteJwt(uri, timeout = 3e3, ttl = 3e4, publicConfig) {
994
+ return new _CredentialConfig({
995
+ credentialSourceType: "internal",
996
+ credentialAuthType: "jwt",
997
+ credentialPublicConfig: { uri, timeout, ttl, ...publicConfig },
998
+ credentialSecret: ""
999
+ });
1000
+ }
1001
+ /** 配置访问 AgentRun 的 Basic 凭证 */
1002
+ static inboundBasic(params) {
1003
+ const { users } = params;
1004
+ return new _CredentialConfig({
1005
+ credentialSourceType: "internal",
1006
+ credentialAuthType: "basic",
1007
+ credentialPublicConfig: { users },
1008
+ credentialSecret: ""
1009
+ });
1010
+ }
1011
+ /** 配置访问第三方工具的 api key 凭证 */
1012
+ static outboundLLMApiKey(params) {
1013
+ const { apiKey, provider } = params;
1014
+ return new _CredentialConfig({
1015
+ credentialSourceType: "external_llm",
1016
+ credentialAuthType: "api_key",
1017
+ credentialPublicConfig: { provider },
1018
+ credentialSecret: apiKey
1019
+ });
1020
+ }
1021
+ /** 配置访问第三方工具的 ak/sk 凭证 */
1022
+ static outboundLLMAKSK(provider, accessKeyId, accessKeySecret, accountId) {
1023
+ return new _CredentialConfig({
1024
+ credentialSourceType: "external_tool",
1025
+ credentialAuthType: "aksk",
1026
+ credentialPublicConfig: {
1027
+ provider,
1028
+ authConfig: { accessKey: accessKeyId, accountId }
1029
+ },
1030
+ credentialSecret: accessKeySecret
1031
+ });
1032
+ }
1033
+ /** 配置访问第三方工具的自定义凭证 */
1034
+ static outboundToolAKSKCustom(params) {
1035
+ const { authConfig } = params;
1036
+ return new _CredentialConfig({
1037
+ credentialSourceType: "external_tool",
1038
+ credentialAuthType: "aksk",
1039
+ credentialPublicConfig: { provider: "custom", authConfig },
1040
+ credentialSecret: ""
1041
+ });
1042
+ }
1043
+ /** 配置访问第三方工具的自定义 Header 凭证 */
1044
+ static outboundToolCustomHeader(params) {
1045
+ const { headers } = params;
1046
+ return new _CredentialConfig({
1047
+ credentialSourceType: "external_tool",
1048
+ credentialAuthType: "custom_header",
1049
+ credentialPublicConfig: { authConfig: headers },
1050
+ credentialSecret: ""
1051
+ });
1052
+ }
1053
+ };
1054
+ CredentialListOutput = class {
1055
+ createdAt;
1056
+ credentialAuthType;
1057
+ credentialId;
1058
+ credentialName;
1059
+ credentialSourceType;
1060
+ enabled;
1061
+ relatedResourceCount;
1062
+ updatedAt;
1063
+ constructor(data) {
1064
+ if (data) updateObjectProperties(this, data);
1065
+ }
1066
+ uniqIdCallback = () => this.credentialId;
1067
+ toCredential = async (params) => {
1068
+ const { CredentialClient: CredentialClient2 } = await Promise.resolve().then(() => (init_client(), client_exports));
1069
+ return await new CredentialClient2(params?.config).get({
1070
+ name: this.credentialName || "",
1071
+ config: params?.config
1072
+ });
1073
+ };
1074
+ };
1075
+ }
1076
+ });
1077
+
1078
+ // src/credential/client.ts
1079
+ var client_exports = {};
1080
+ __export(client_exports, {
1081
+ CredentialClient: () => CredentialClient
1082
+ });
1083
+ var CredentialClient;
1084
+ var init_client = __esm({
1085
+ "src/credential/client.ts"() {
1086
+ init_utils();
1087
+ init_config();
1088
+ init_control();
1089
+ init_credential();
1090
+ init_model2();
1091
+ CredentialClient = class {
1092
+ config;
1093
+ controlApi;
1094
+ constructor(config2) {
1095
+ this.config = config2;
1096
+ this.controlApi = new CredentialControlAPI(config2);
1097
+ }
1098
+ /**
1099
+ * Create a Credential
1100
+ */
1101
+ create = async (params) => {
1102
+ try {
1103
+ const { input, config: config2 } = params;
1104
+ const cfg = Config.withConfigs(this.config, config2);
1105
+ const credCfg = input.credentialConfig;
1106
+ const normalized = {
1107
+ ...input,
1108
+ credentialAuthType: credCfg?.credentialAuthType ?? credCfg?.authType,
1109
+ credentialSourceType: credCfg?.credentialSourceType ?? credCfg?.sourceType,
1110
+ credentialPublicConfig: credCfg?.credentialPublicConfig ?? credCfg?.publicConfig,
1111
+ credentialSecret: credCfg?.credentialSecret ?? credCfg?.secret
1112
+ };
1113
+ if (normalized.credentialPublicConfig) {
1114
+ const publicConfig = normalized.credentialPublicConfig;
1115
+ if (!("users" in publicConfig)) {
1116
+ publicConfig.users = [];
1117
+ }
1118
+ }
1119
+ if (normalized.credentialAuthType === "basic") {
1120
+ const pub = normalized.credentialPublicConfig ?? {};
1121
+ if (pub.username) {
1122
+ normalized.credentialPublicConfig = {
1123
+ users: [
1124
+ {
1125
+ username: pub.username,
1126
+ password: normalized.credentialSecret ?? ""
1127
+ }
1128
+ ]
1129
+ };
1130
+ normalized.credentialSecret = "";
1131
+ }
1132
+ }
1133
+ const result = await this.controlApi.createCredential({
1134
+ input: new $AgentRun.CreateCredentialInput(normalized),
1135
+ config: cfg
1136
+ });
1137
+ return new Credential(result);
1138
+ } catch (error) {
1139
+ if (error instanceof HTTPError) {
1140
+ throw error.toResourceError("Credential", params?.input?.credentialName);
1141
+ }
1142
+ throw error;
1143
+ }
1144
+ };
1145
+ /**
1146
+ * Delete a Credential
1147
+ */
1148
+ delete = async (params) => {
1149
+ try {
1150
+ const { name, config: config2 } = params;
1151
+ const cfg = Config.withConfigs(this.config, config2);
1152
+ const result = await this.controlApi.deleteCredential({
1153
+ credentialName: name,
1154
+ config: cfg
1155
+ });
1156
+ return new Credential(result);
1157
+ } catch (error) {
1158
+ if (error instanceof HTTPError) {
1159
+ throw error.toResourceError("Credential", params?.name);
1160
+ }
1161
+ throw error;
1162
+ }
1163
+ };
1164
+ /**
1165
+ * Update a Credential
1166
+ */
1167
+ update = async (params) => {
1168
+ try {
1169
+ const { name, input, config: config2 } = params;
1170
+ const cfg = Config.withConfigs(this.config, config2);
1171
+ const credCfg = input.credentialConfig;
1172
+ const normalized = { ...input };
1173
+ if (credCfg) {
1174
+ normalized.credentialAuthType = credCfg?.credentialAuthType ?? credCfg?.authType;
1175
+ normalized.credentialSourceType = credCfg?.credentialSourceType ?? credCfg?.sourceType;
1176
+ normalized.credentialPublicConfig = credCfg?.credentialPublicConfig ?? credCfg?.publicConfig;
1177
+ normalized.credentialSecret = credCfg?.credentialSecret ?? credCfg?.secret;
1178
+ if (normalized.credentialPublicConfig) {
1179
+ const publicConfig = normalized.credentialPublicConfig;
1180
+ if (!("users" in publicConfig)) {
1181
+ publicConfig.users = [];
1182
+ }
1183
+ }
1184
+ if (normalized.credentialAuthType === "basic") {
1185
+ const pub = normalized.credentialPublicConfig ?? {};
1186
+ if (pub.username) {
1187
+ normalized.credentialPublicConfig = {
1188
+ users: [
1189
+ {
1190
+ username: pub.username,
1191
+ password: normalized.credentialSecret ?? ""
1192
+ }
1193
+ ]
1194
+ };
1195
+ normalized.credentialSecret = "";
1196
+ }
1197
+ }
1198
+ }
1199
+ const result = await this.controlApi.updateCredential({
1200
+ credentialName: name,
1201
+ input: new $AgentRun.UpdateCredentialInput(normalized),
1202
+ config: cfg
1203
+ });
1204
+ return new Credential(result);
1205
+ } catch (error) {
1206
+ if (error instanceof HTTPError) {
1207
+ throw error.toResourceError("Credential", params?.name);
1208
+ }
1209
+ throw error;
1210
+ }
1211
+ };
1212
+ /**
1213
+ * Get a Credential
1214
+ */
1215
+ get = async (params) => {
1216
+ try {
1217
+ const { name, config: config2 } = params;
1218
+ const cfg = Config.withConfigs(this.config, config2);
1219
+ const result = await this.controlApi.getCredential({
1220
+ credentialName: name,
1221
+ config: cfg
1222
+ });
1223
+ return new Credential(result);
1224
+ } catch (error) {
1225
+ if (error instanceof HTTPError) {
1226
+ throw error.toResourceError("Credential", params?.name);
1227
+ }
1228
+ throw error;
1229
+ }
1230
+ };
1231
+ /**
1232
+ * List Credentials
1233
+ */
1234
+ list = async (params) => {
1235
+ try {
1236
+ const { input, config: config2 } = params ?? {};
1237
+ const cfg = Config.withConfigs(this.config, config2);
1238
+ const results = await this.controlApi.listCredentials({
1239
+ input: new $AgentRun.ListCredentialsRequest({ ...input }),
1240
+ config: cfg
1241
+ });
1242
+ return results.items?.map((item) => new CredentialListOutput(item)) ?? [];
1243
+ } catch (error) {
1244
+ if (error instanceof HTTPError) {
1245
+ throw error.toResourceError("Credential");
1246
+ }
1247
+ throw error;
1248
+ }
1249
+ };
1250
+ };
1251
+ }
1252
+ });
1253
+
1254
+ // src/credential/index.ts
1255
+ init_version_check();
1256
+ init_client();
1257
+ init_credential();
1258
+ init_control();
1259
+ init_model2();
1260
+
1261
+ export { Credential, CredentialClient, CredentialConfig, CredentialControlAPI };
1262
+ //# sourceMappingURL=index.js.map
1263
+ //# sourceMappingURL=index.js.map