@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,2392 @@
1
+ 'use strict';
2
+
3
+ var dotenv = require('dotenv');
4
+ var $AgentRun5 = require('@alicloud/agentrun20250910');
5
+ var $OpenApi = require('@alicloud/openapi-client');
6
+ var $Util = require('@alicloud/tea-util');
7
+ var openaiCompatible = require('@ai-sdk/openai-compatible');
8
+ var _2 = require('lodash');
9
+
10
+ function _interopNamespace(e) {
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
29
+ var $AgentRun5__namespace = /*#__PURE__*/_interopNamespace($AgentRun5);
30
+ var $OpenApi__namespace = /*#__PURE__*/_interopNamespace($OpenApi);
31
+ var $Util__namespace = /*#__PURE__*/_interopNamespace($Util);
32
+ var _2__namespace = /*#__PURE__*/_interopNamespace(_2);
33
+
34
+ var __defProp = Object.defineProperty;
35
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
36
+ var __getOwnPropNames = Object.getOwnPropertyNames;
37
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
38
+ var __esm = (fn, res) => function __init() {
39
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
40
+ };
41
+ var __export = (target, all) => {
42
+ for (var name in all)
43
+ __defProp(target, name, { get: all[name], enumerable: true });
44
+ };
45
+ var __copyProps = (to, from, except, desc) => {
46
+ if (from && typeof from === "object" || typeof from === "function") {
47
+ for (let key of __getOwnPropNames(from))
48
+ if (!__hasOwnProp.call(to, key) && key !== except)
49
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
50
+ }
51
+ return to;
52
+ };
53
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
54
+
55
+ // src/utils/log.ts
56
+ var LOG_LEVELS, COLORS, Logger, logger;
57
+ var init_log = __esm({
58
+ "src/utils/log.ts"() {
59
+ LOG_LEVELS = {
60
+ debug: 0,
61
+ info: 1,
62
+ warn: 2,
63
+ error: 3
64
+ };
65
+ COLORS = {
66
+ reset: "\x1B[0m",
67
+ bright: "\x1B[1m",
68
+ dim: "\x1B[2m",
69
+ italic: "\x1B[3m",
70
+ blue: "\x1B[34m",
71
+ cyan: "\x1B[36m",
72
+ yellow: "\x1B[33m",
73
+ red: "\x1B[31m"
74
+ };
75
+ Logger = class {
76
+ level = "info";
77
+ // match Python logger name
78
+ prefix = "agentrun-logger";
79
+ setLevel(level) {
80
+ this.level = level;
81
+ }
82
+ shouldLog(level) {
83
+ return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
84
+ }
85
+ getColor(level) {
86
+ switch (level) {
87
+ case "debug":
88
+ return COLORS.cyan;
89
+ case "info":
90
+ return COLORS.blue;
91
+ case "warn":
92
+ return COLORS.yellow;
93
+ case "error":
94
+ return COLORS.red;
95
+ default:
96
+ return COLORS.reset;
97
+ }
98
+ }
99
+ // format timestamp like Python: YYYY-MM-DD HH:mm:ss,SSS
100
+ formatTimestamp(d = /* @__PURE__ */ new Date()) {
101
+ const pad = (n, sz = 2) => n.toString().padStart(sz, "0");
102
+ const year = d.getFullYear();
103
+ const month = pad(d.getMonth() + 1);
104
+ const day = pad(d.getDate());
105
+ const hour = pad(d.getHours());
106
+ const minute = pad(d.getMinutes());
107
+ const second = pad(d.getSeconds());
108
+ const ms = pad(d.getMilliseconds(), 3);
109
+ return `${year}-${month}-${day} ${hour}:${minute}:${second},${ms}`;
110
+ }
111
+ // attempt to infer caller file and line by parsing Error.stack
112
+ // helper: parse a single stack frame into {filepath, line, functionName}
113
+ parseFrame(frame) {
114
+ const m = frame.match(/^(?:at\s+)?(?:(.+?)\s+\()?(.*?):(\d+):(\d+)\)?$/);
115
+ if (!m) return null;
116
+ return {
117
+ functionName: m[1] ? m[1].trim() : void 0,
118
+ filepath: m[2],
119
+ line: parseInt(m[3], 10)
120
+ };
121
+ }
122
+ // get caller by fixed stack offset (used in public log methods)
123
+ getCallerByOffset() {
124
+ const err = new Error();
125
+ const stack = err.stack;
126
+ if (!stack) return {};
127
+ const lines = stack.split("\n").map((l) => l.trim());
128
+ for (let i = 3; i < lines.length; i++) {
129
+ let parsed = this.parseFrame(lines[i]);
130
+ if (!parsed) {
131
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
132
+ if (m) {
133
+ const parts = m[1].split(":");
134
+ parts.pop();
135
+ const ln = Number(parts.pop());
136
+ const fp2 = parts.join(":");
137
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
138
+ }
139
+ }
140
+ if (!parsed) continue;
141
+ const fp = parsed.filepath;
142
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
143
+ continue;
144
+ return { filepath: parsed.filepath, line: parsed.line };
145
+ }
146
+ const cwd = process.cwd();
147
+ for (let i = 0; i < lines.length; i++) {
148
+ let parsed = this.parseFrame(lines[i]);
149
+ if (!parsed) {
150
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
151
+ if (m) {
152
+ const parts = m[1].split(":");
153
+ parts.pop();
154
+ const ln = Number(parts.pop());
155
+ const fp2 = parts.join(":");
156
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
157
+ }
158
+ }
159
+ if (!parsed) continue;
160
+ const fp = parsed.filepath;
161
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
162
+ continue;
163
+ if (fp.includes("/src/utils/log.ts")) continue;
164
+ if (fp.startsWith(cwd)) return { filepath: parsed.filepath, line: parsed.line };
165
+ }
166
+ for (let i = 0; i < lines.length; i++) {
167
+ let parsed = this.parseFrame(lines[i]);
168
+ if (!parsed) {
169
+ const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
170
+ if (m) {
171
+ const parts = m[1].split(":");
172
+ parts.pop();
173
+ const ln = Number(parts.pop());
174
+ const fp2 = parts.join(":");
175
+ parsed = { filepath: fp2, line: ln, functionName: void 0 };
176
+ }
177
+ }
178
+ if (!parsed) continue;
179
+ const fp = parsed.filepath;
180
+ if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
181
+ continue;
182
+ if (fp.includes("/src/utils/log.ts")) continue;
183
+ return { filepath: parsed.filepath, line: parsed.line };
184
+ }
185
+ return {};
186
+ }
187
+ formatMessage(level, message, filepath, line) {
188
+ const timestamp = this.formatTimestamp();
189
+ const color = this.getColor(level);
190
+ const reset = COLORS.reset;
191
+ const levelName = level === "warn" ? "WARNING" : level.toUpperCase();
192
+ const levelStr = `${COLORS.bright}${color}${levelName}${reset}`;
193
+ const nameStr = `${color}[${this.prefix}]${reset}`;
194
+ const tsStr = `${color} ${timestamp}${reset}`;
195
+ const pathInfo = filepath && line !== void 0 ? ` ${COLORS.dim}${COLORS.italic}${filepath}:${line}${reset}` : "";
196
+ const msg = level === "debug" ? `${COLORS.dim}${message}${reset}` : message;
197
+ return `
198
+ ${levelStr} ${nameStr}${tsStr}${pathInfo}
199
+ ${msg}
200
+ `;
201
+ }
202
+ debug(message, ...args) {
203
+ if (this.shouldLog("debug")) {
204
+ const caller = this.getCallerByOffset();
205
+ console.debug(this.formatMessage("debug", message, caller.filepath, caller.line), ...args);
206
+ }
207
+ }
208
+ info(message, ...args) {
209
+ if (this.shouldLog("info")) {
210
+ const caller = this.getCallerByOffset();
211
+ console.info(this.formatMessage("info", message, caller.filepath, caller.line), ...args);
212
+ }
213
+ }
214
+ warn(message, ...args) {
215
+ if (this.shouldLog("warn")) {
216
+ const caller = this.getCallerByOffset();
217
+ console.warn(this.formatMessage("warn", message, caller.filepath, caller.line), ...args);
218
+ }
219
+ }
220
+ error(message, ...args) {
221
+ if (this.shouldLog("error")) {
222
+ const caller = this.getCallerByOffset();
223
+ console.error(this.formatMessage("error", message, caller.filepath, caller.line), ...args);
224
+ }
225
+ }
226
+ };
227
+ logger = new Logger();
228
+ if (![void 0, null, "", "False", "FALSE", "false", "0"].includes(process.env["AGENTRUN_SDK_DEBUG"])) {
229
+ logger.setLevel("debug");
230
+ if (!globalThis._AGENTRUN_DEBUG_LOGGED) {
231
+ logger.warn("\u542F\u7528 AgentRun SDK \u8C03\u8BD5\u65E5\u5FD7\uFF0C \u79FB\u9664 AGENTRUN_SDK_DEBUG \u73AF\u5883\u53D8\u91CF\u4EE5\u5173\u95ED");
232
+ globalThis._AGENTRUN_DEBUG_LOGGED = true;
233
+ }
234
+ } else {
235
+ logger.setLevel("info");
236
+ }
237
+ }
238
+ });
239
+
240
+ // src/utils/version-check.ts
241
+ var VERSION;
242
+ var init_version_check = __esm({
243
+ "src/utils/version-check.ts"() {
244
+ init_log();
245
+ VERSION = "0.0.4" ;
246
+ if (!process.env.DISABLE_BREAKING_CHANGES_WARNING && !globalThis._AGENTRUN_VERSION_WARNING_SHOWN) {
247
+ globalThis._AGENTRUN_VERSION_WARNING_SHOWN = true;
248
+ logger.warn(
249
+ `\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
250
+ 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.
251
+ \x1B[2;3m pip install 'agentrun-sdk==${VERSION}' \x1B[0m
252
+
253
+ \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
254
+ Add\x1B[2;3m DISABLE_BREAKING_CHANGES_WARNING=1 \x1B[0mto your environment variables to disable this warning.
255
+
256
+ Releases:\x1B[2;3m https://github.com/Serverless-Devs/agentrun-sdk-python/releases\x1B[0m`
257
+ );
258
+ }
259
+ }
260
+ });
261
+ function getEnvWithDefault(defaultValue, ...keys) {
262
+ for (const key of keys) {
263
+ const value = process.env[key];
264
+ if (value !== void 0 && value !== "") {
265
+ return value;
266
+ }
267
+ }
268
+ return defaultValue;
269
+ }
270
+ var Config;
271
+ var init_config = __esm({
272
+ "src/utils/config.ts"() {
273
+ dotenv__namespace.config();
274
+ Config = class _Config {
275
+ _accessKeyId;
276
+ _accessKeySecret;
277
+ _securityToken;
278
+ _accountId;
279
+ _token;
280
+ _regionId;
281
+ _timeout;
282
+ _readTimeout;
283
+ _controlEndpoint;
284
+ _dataEndpoint;
285
+ _devsEndpoint;
286
+ _headers;
287
+ constructor(options = {}) {
288
+ this._accessKeyId = options.accessKeyId ?? getEnvWithDefault("", "AGENTRUN_ACCESS_KEY_ID", "ALIBABA_CLOUD_ACCESS_KEY_ID");
289
+ this._accessKeySecret = options.accessKeySecret ?? getEnvWithDefault("", "AGENTRUN_ACCESS_KEY_SECRET", "ALIBABA_CLOUD_ACCESS_KEY_SECRET");
290
+ this._securityToken = options.securityToken ?? getEnvWithDefault("", "AGENTRUN_SECURITY_TOKEN", "ALIBABA_CLOUD_SECURITY_TOKEN");
291
+ this._accountId = options.accountId ?? getEnvWithDefault("", "AGENTRUN_ACCOUNT_ID", "FC_ACCOUNT_ID");
292
+ this._token = options.token;
293
+ this._regionId = options.regionId ?? getEnvWithDefault("cn-hangzhou", "AGENTRUN_REGION", "FC_REGION");
294
+ this._timeout = options.timeout ?? 6e5;
295
+ this._readTimeout = options.readTimeout ?? 1e8;
296
+ this._controlEndpoint = options.controlEndpoint ?? getEnvWithDefault("", "AGENTRUN_CONTROL_ENDPOINT");
297
+ this._dataEndpoint = options.dataEndpoint ?? getEnvWithDefault("", "AGENTRUN_DATA_ENDPOINT");
298
+ this._devsEndpoint = options.devsEndpoint ?? getEnvWithDefault("", "DEVS_ENDPOINT");
299
+ this._headers = options.headers ?? {};
300
+ }
301
+ /**
302
+ * Create a new Config by merging multiple configs.
303
+ * Later configs take precedence.
304
+ */
305
+ static withConfigs(...configs) {
306
+ return new _Config().update(...configs);
307
+ }
308
+ /**
309
+ * Update this config with values from other configs.
310
+ * Non-undefined values from later configs take precedence.
311
+ */
312
+ update(...configs) {
313
+ for (const config2 of configs) {
314
+ if (!config2) continue;
315
+ if (config2._accessKeyId) this._accessKeyId = config2._accessKeyId;
316
+ if (config2._accessKeySecret) this._accessKeySecret = config2._accessKeySecret;
317
+ if (config2._securityToken) this._securityToken = config2._securityToken;
318
+ if (config2._accountId) this._accountId = config2._accountId;
319
+ if (config2._token) this._token = config2._token;
320
+ if (config2._regionId) this._regionId = config2._regionId;
321
+ if (config2._timeout) this._timeout = config2._timeout;
322
+ if (config2._readTimeout) this._readTimeout = config2._readTimeout;
323
+ if (config2._controlEndpoint) this._controlEndpoint = config2._controlEndpoint;
324
+ if (config2._dataEndpoint) this._dataEndpoint = config2._dataEndpoint;
325
+ if (config2._devsEndpoint) this._devsEndpoint = config2._devsEndpoint;
326
+ if (config2._headers && Object.keys(config2._headers).length > 0) {
327
+ this._headers = { ...this._headers, ...config2._headers };
328
+ }
329
+ }
330
+ return this;
331
+ }
332
+ get accessKeyId() {
333
+ return this._accessKeyId;
334
+ }
335
+ get accessKeySecret() {
336
+ return this._accessKeySecret;
337
+ }
338
+ get securityToken() {
339
+ return this._securityToken;
340
+ }
341
+ get accountId() {
342
+ if (!this._accountId) {
343
+ throw new Error(
344
+ "Account ID is not set. Please add AGENTRUN_ACCOUNT_ID environment variable or set it in code."
345
+ );
346
+ }
347
+ return this._accountId;
348
+ }
349
+ get token() {
350
+ return this._token;
351
+ }
352
+ get regionId() {
353
+ return this._regionId || "cn-hangzhou";
354
+ }
355
+ get timeout() {
356
+ return this._timeout || 6e5;
357
+ }
358
+ get readTimeout() {
359
+ return this._readTimeout || 1e8;
360
+ }
361
+ get controlEndpoint() {
362
+ if (this._controlEndpoint) {
363
+ return this._controlEndpoint;
364
+ }
365
+ return `https://agentrun.${this.regionId}.aliyuncs.com`;
366
+ }
367
+ get dataEndpoint() {
368
+ if (this._dataEndpoint) {
369
+ return this._dataEndpoint;
370
+ }
371
+ return `https://${this.accountId}.agentrun-data.${this.regionId}.aliyuncs.com`;
372
+ }
373
+ get devsEndpoint() {
374
+ if (this._devsEndpoint) {
375
+ return this._devsEndpoint;
376
+ }
377
+ return `https://devs.${this.regionId}.aliyuncs.com`;
378
+ }
379
+ get headers() {
380
+ return this._headers;
381
+ }
382
+ };
383
+ }
384
+ });
385
+
386
+ // src/utils/exception.ts
387
+ var AgentRunError, HTTPError, ClientError, ServerError, ResourceNotExistError, ResourceAlreadyExistError;
388
+ var init_exception = __esm({
389
+ "src/utils/exception.ts"() {
390
+ AgentRunError = class _AgentRunError extends Error {
391
+ constructor(message) {
392
+ super(message);
393
+ this.name = "AgentRunError";
394
+ Object.setPrototypeOf(this, _AgentRunError.prototype);
395
+ }
396
+ };
397
+ HTTPError = class _HTTPError extends AgentRunError {
398
+ statusCode;
399
+ requestId;
400
+ errorCode;
401
+ constructor(statusCode, message, options) {
402
+ super(message);
403
+ this.name = "HTTPError";
404
+ this.statusCode = statusCode;
405
+ this.requestId = options?.requestId;
406
+ this.errorCode = options?.errorCode;
407
+ Object.setPrototypeOf(this, _HTTPError.prototype);
408
+ }
409
+ /**
410
+ * Convert HTTP error to resource-specific error based on status code
411
+ */
412
+ toResourceError(resourceType, resourceId) {
413
+ if (this.statusCode == 404) return new ResourceNotExistError(resourceType, resourceId);
414
+ else if (this.statusCode == 409) return new ResourceAlreadyExistError(resourceType, resourceId);
415
+ else if ((this.statusCode == 400 || this.statusCode == 500) && this.message.includes("already exists"))
416
+ return new ResourceAlreadyExistError(resourceType, resourceId);
417
+ else return this;
418
+ }
419
+ };
420
+ ClientError = class _ClientError extends HTTPError {
421
+ constructor(statusCode, message, options) {
422
+ super(statusCode, message, options);
423
+ this.name = "ClientError";
424
+ Object.setPrototypeOf(this, _ClientError.prototype);
425
+ }
426
+ };
427
+ ServerError = class _ServerError extends HTTPError {
428
+ constructor(statusCode, message, options) {
429
+ super(statusCode, message, options);
430
+ this.name = "ServerError";
431
+ Object.setPrototypeOf(this, _ServerError.prototype);
432
+ }
433
+ };
434
+ ResourceNotExistError = class _ResourceNotExistError extends ClientError {
435
+ resourceType;
436
+ resourceId;
437
+ constructor(resourceType, resourceId, options) {
438
+ const message = resourceId ? `${resourceType} '${resourceId}' does not exist` : `${resourceType} does not exist`;
439
+ super(404, message, options);
440
+ this.name = "ResourceNotExistError";
441
+ this.resourceType = resourceType;
442
+ this.resourceId = resourceId;
443
+ Object.setPrototypeOf(this, _ResourceNotExistError.prototype);
444
+ }
445
+ };
446
+ ResourceAlreadyExistError = class _ResourceAlreadyExistError extends ClientError {
447
+ resourceType;
448
+ resourceId;
449
+ constructor(resourceType, resourceId, options) {
450
+ const message = resourceId ? `${resourceType} '${resourceId}' already exists` : `${resourceType} already exists`;
451
+ super(409, message, options);
452
+ this.name = "ResourceAlreadyExistError";
453
+ this.resourceType = resourceType;
454
+ this.resourceId = resourceId;
455
+ Object.setPrototypeOf(this, _ResourceAlreadyExistError.prototype);
456
+ }
457
+ };
458
+ }
459
+ });
460
+ var $AgentRunClient; exports.ModelControlAPI = void 0;
461
+ var init_control_api = __esm({
462
+ "src/utils/control-api.ts"() {
463
+ init_config();
464
+ $AgentRunClient = // @ts-expect-error - ESM interop: default.default exists when imported as ESM namespace
465
+ $AgentRun5__namespace.default?.default ?? $AgentRun5__namespace.default ?? $AgentRun5__namespace;
466
+ exports.ModelControlAPI = class {
467
+ config;
468
+ constructor(config2) {
469
+ this.config = config2;
470
+ }
471
+ /**
472
+ * Get the underlying AgentRun client instance
473
+ */
474
+ getClient(config2) {
475
+ const cfg = Config.withConfigs(this.config, config2);
476
+ let endpoint = cfg.controlEndpoint;
477
+ if (endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
478
+ endpoint = endpoint.split("://")[1];
479
+ }
480
+ const openApiConfig = new $OpenApi__namespace.Config({
481
+ accessKeyId: cfg.accessKeyId,
482
+ accessKeySecret: cfg.accessKeySecret,
483
+ securityToken: cfg.securityToken || void 0,
484
+ regionId: cfg.regionId,
485
+ endpoint,
486
+ connectTimeout: cfg.timeout,
487
+ readTimeout: cfg.readTimeout
488
+ });
489
+ return new $AgentRunClient(openApiConfig);
490
+ }
491
+ };
492
+ }
493
+ });
494
+ var ModelControlAPI;
495
+ var init_control = __esm({
496
+ "src/model/api/control.ts"() {
497
+ init_control_api();
498
+ init_exception();
499
+ init_log();
500
+ ModelControlAPI = class extends exports.ModelControlAPI {
501
+ constructor(config2) {
502
+ super(config2);
503
+ }
504
+ /**
505
+ * Create model service
506
+ *
507
+ * @param params - Method parameters
508
+ * @param params.input - Model service configuration
509
+ * @param params.headers - Custom request headers
510
+ * @param params.config - Optional config override
511
+ * @returns Created model service object
512
+ */
513
+ createModelService = async (params) => {
514
+ const { input, headers, config: config2 } = params;
515
+ try {
516
+ const client = this.getClient(config2);
517
+ const runtime = new $Util__namespace.RuntimeOptions({});
518
+ const response = await client.createModelServiceWithOptions(
519
+ new $AgentRun5__namespace.CreateModelServiceRequest({ body: input }),
520
+ headers ?? {},
521
+ runtime
522
+ );
523
+ logger.debug(
524
+ `request api createModelService, request Request ID: ${response.body?.requestId}
525
+ request: ${JSON.stringify([input])}
526
+ response: ${JSON.stringify(response.body?.data)}`
527
+ );
528
+ return response.body?.data;
529
+ } catch (error) {
530
+ if (error && typeof error === "object" && "statusCode" in error) {
531
+ const e = error;
532
+ const statusCode = e.statusCode;
533
+ const message = e.message || "Unknown error";
534
+ const requestId = e.data?.requestId;
535
+ if (statusCode >= 400 && statusCode < 500) {
536
+ throw new ClientError(statusCode, message, { requestId });
537
+ } else if (statusCode >= 500) {
538
+ throw new ServerError(statusCode, message, { requestId });
539
+ }
540
+ }
541
+ throw error;
542
+ }
543
+ };
544
+ /**
545
+ * Delete model service
546
+ *
547
+ * @param params - Method parameters
548
+ * @param params.modelServiceName - Model service name
549
+ * @param params.headers - Custom request headers
550
+ * @param params.config - Optional config override
551
+ * @returns Deleted model service object
552
+ */
553
+ deleteModelService = async (params) => {
554
+ const { modelServiceName, headers, config: config2 } = params;
555
+ try {
556
+ const client = this.getClient(config2);
557
+ const runtime = new $Util__namespace.RuntimeOptions({});
558
+ const response = await client.deleteModelServiceWithOptions(
559
+ modelServiceName,
560
+ headers ?? {},
561
+ runtime
562
+ );
563
+ logger.debug(
564
+ `request api deleteModelService, request Request ID: ${response.body?.requestId}
565
+ request: ${JSON.stringify([modelServiceName])}
566
+ response: ${JSON.stringify(response.body?.data)}`
567
+ );
568
+ return response.body?.data;
569
+ } catch (error) {
570
+ if (error && typeof error === "object" && "statusCode" in error) {
571
+ const e = error;
572
+ const statusCode = e.statusCode;
573
+ const message = e.message || "Unknown error";
574
+ const requestId = e.data?.requestId;
575
+ if (statusCode >= 400 && statusCode < 500) {
576
+ throw new ClientError(statusCode, message, { requestId });
577
+ } else if (statusCode >= 500) {
578
+ throw new ServerError(statusCode, message, { requestId });
579
+ }
580
+ }
581
+ throw error;
582
+ }
583
+ };
584
+ /**
585
+ * Update model service
586
+ *
587
+ * @param params - Method parameters
588
+ * @param params.modelServiceName - Model service name
589
+ * @param params.input - Model service configuration
590
+ * @param params.headers - Custom request headers
591
+ * @param params.config - Optional config override
592
+ * @returns Updated model service object
593
+ */
594
+ updateModelService = async (params) => {
595
+ const { modelServiceName, input, headers, config: config2 } = params;
596
+ try {
597
+ const client = this.getClient(config2);
598
+ const runtime = new $Util__namespace.RuntimeOptions({});
599
+ const response = await client.updateModelServiceWithOptions(
600
+ modelServiceName,
601
+ new $AgentRun5__namespace.UpdateModelServiceRequest({ body: input }),
602
+ headers ?? {},
603
+ runtime
604
+ );
605
+ logger.debug(
606
+ `request api updateModelService, request Request ID: ${response.body?.requestId}
607
+ request: ${JSON.stringify([modelServiceName, 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
+ * Get model service
628
+ *
629
+ * @param params - Method parameters
630
+ * @param params.modelServiceName - Model service name
631
+ * @param params.headers - Custom request headers
632
+ * @param params.config - Optional config override
633
+ * @returns Model service object
634
+ */
635
+ getModelService = async (params) => {
636
+ const { modelServiceName, headers, config: config2 } = params;
637
+ try {
638
+ const client = this.getClient(config2);
639
+ const runtime = new $Util__namespace.RuntimeOptions({});
640
+ const response = await client.getModelServiceWithOptions(
641
+ modelServiceName,
642
+ headers ?? {},
643
+ runtime
644
+ );
645
+ logger.debug(
646
+ `request api getModelService, request Request ID: ${response.body?.requestId}
647
+ request: ${JSON.stringify([modelServiceName])}
648
+ response: ${JSON.stringify(response.body?.data)}`
649
+ );
650
+ return response.body?.data;
651
+ } catch (error) {
652
+ if (error && typeof error === "object" && "statusCode" in error) {
653
+ const e = error;
654
+ const statusCode = e.statusCode;
655
+ const message = e.message || "Unknown error";
656
+ const requestId = e.data?.requestId;
657
+ if (statusCode >= 400 && statusCode < 500) {
658
+ throw new ClientError(statusCode, message, { requestId });
659
+ } else if (statusCode >= 500) {
660
+ throw new ServerError(statusCode, message, { requestId });
661
+ }
662
+ }
663
+ throw error;
664
+ }
665
+ };
666
+ /**
667
+ * List model services
668
+ *
669
+ * @param params - Method parameters
670
+ * @param params.input - List options
671
+ * @param params.headers - Custom request headers
672
+ * @param params.config - Optional config override
673
+ * @returns List of model service objects
674
+ */
675
+ listModelServices = async (params) => {
676
+ const { input, headers, config: config2 } = params;
677
+ try {
678
+ const client = this.getClient(config2);
679
+ const runtime = new $Util__namespace.RuntimeOptions({});
680
+ const response = await client.listModelServicesWithOptions(input, headers ?? {}, runtime);
681
+ logger.debug(
682
+ `request api listModelServices, request Request ID: ${response.body?.requestId}
683
+ request: ${JSON.stringify([input])}
684
+ response: ${JSON.stringify(response.body?.data)}`
685
+ );
686
+ return response.body?.data;
687
+ } catch (error) {
688
+ if (error && typeof error === "object" && "statusCode" in error) {
689
+ const e = error;
690
+ const statusCode = e.statusCode;
691
+ const message = e.message || "Unknown error";
692
+ const requestId = e.data?.requestId;
693
+ if (statusCode >= 400 && statusCode < 500) {
694
+ throw new ClientError(statusCode, message, { requestId });
695
+ } else if (statusCode >= 500) {
696
+ throw new ServerError(statusCode, message, { requestId });
697
+ }
698
+ }
699
+ throw error;
700
+ }
701
+ };
702
+ /**
703
+ * Create model proxy
704
+ *
705
+ * @param params - Method parameters
706
+ * @param params.input - Model proxy configuration
707
+ * @param params.headers - Custom request headers
708
+ * @param params.config - Optional config override
709
+ * @returns Created model proxy object
710
+ */
711
+ createModelProxy = async (params) => {
712
+ const { input, headers, config: config2 } = params;
713
+ try {
714
+ const client = this.getClient(config2);
715
+ const runtime = new $Util__namespace.RuntimeOptions({});
716
+ const response = await client.createModelProxyWithOptions(
717
+ new $AgentRun5__namespace.CreateModelProxyRequest({ body: input }),
718
+ headers ?? {},
719
+ runtime
720
+ );
721
+ logger.debug(
722
+ `request api createModelProxy, request Request ID: ${response.body?.requestId}
723
+ request: ${JSON.stringify([input])}
724
+ response: ${JSON.stringify(response.body?.data)}`
725
+ );
726
+ return response.body?.data;
727
+ } catch (error) {
728
+ if (error && typeof error === "object" && "statusCode" in error) {
729
+ const e = error;
730
+ const statusCode = e.statusCode;
731
+ const message = e.message || "Unknown error";
732
+ const requestId = e.data?.requestId;
733
+ if (statusCode >= 400 && statusCode < 500) {
734
+ throw new ClientError(statusCode, message, { requestId });
735
+ } else if (statusCode >= 500) {
736
+ throw new ServerError(statusCode, message, { requestId });
737
+ }
738
+ }
739
+ throw error;
740
+ }
741
+ };
742
+ /**
743
+ * Delete model proxy
744
+ *
745
+ * @param params - Method parameters
746
+ * @param params.modelProxyName - Model proxy name
747
+ * @param params.headers - Custom request headers
748
+ * @param params.config - Optional config override
749
+ * @returns Deleted model proxy object
750
+ */
751
+ deleteModelProxy = async (params) => {
752
+ const { modelProxyName, headers, config: config2 } = params;
753
+ try {
754
+ const client = this.getClient(config2);
755
+ const runtime = new $Util__namespace.RuntimeOptions({});
756
+ const response = await client.deleteModelProxyWithOptions(
757
+ modelProxyName,
758
+ headers ?? {},
759
+ runtime
760
+ );
761
+ logger.debug(
762
+ `request api deleteModelProxy, request Request ID: ${response.body?.requestId}
763
+ request: ${JSON.stringify([modelProxyName])}
764
+ response: ${JSON.stringify(response.body?.data)}`
765
+ );
766
+ return response.body?.data;
767
+ } catch (error) {
768
+ if (error && typeof error === "object" && "statusCode" in error) {
769
+ const e = error;
770
+ const statusCode = e.statusCode;
771
+ const message = e.message || "Unknown error";
772
+ const requestId = e.data?.requestId;
773
+ if (statusCode >= 400 && statusCode < 500) {
774
+ throw new ClientError(statusCode, message, { requestId });
775
+ } else if (statusCode >= 500) {
776
+ throw new ServerError(statusCode, message, { requestId });
777
+ }
778
+ }
779
+ throw error;
780
+ }
781
+ };
782
+ /**
783
+ * Update model proxy
784
+ *
785
+ * @param params - Method parameters
786
+ * @param params.modelProxyName - Model proxy name
787
+ * @param params.input - Model proxy configuration
788
+ * @param params.headers - Custom request headers
789
+ * @param params.config - Optional config override
790
+ * @returns Updated model proxy object
791
+ */
792
+ updateModelProxy = async (params) => {
793
+ const { modelProxyName, input, headers, config: config2 } = params;
794
+ try {
795
+ const client = this.getClient(config2);
796
+ const runtime = new $Util__namespace.RuntimeOptions({});
797
+ const response = await client.updateModelProxyWithOptions(
798
+ modelProxyName,
799
+ new $AgentRun5__namespace.UpdateModelProxyRequest({ body: input }),
800
+ headers ?? {},
801
+ runtime
802
+ );
803
+ logger.debug(
804
+ `request api updateModelProxy, request Request ID: ${response.body?.requestId}
805
+ request: ${JSON.stringify([modelProxyName, input])}
806
+ response: ${JSON.stringify(response.body?.data)}`
807
+ );
808
+ return response.body?.data;
809
+ } catch (error) {
810
+ if (error && typeof error === "object" && "statusCode" in error) {
811
+ const e = error;
812
+ const statusCode = e.statusCode;
813
+ const message = e.message || "Unknown error";
814
+ const requestId = e.data?.requestId;
815
+ if (statusCode >= 400 && statusCode < 500) {
816
+ throw new ClientError(statusCode, message, { requestId });
817
+ } else if (statusCode >= 500) {
818
+ throw new ServerError(statusCode, message, { requestId });
819
+ }
820
+ }
821
+ throw error;
822
+ }
823
+ };
824
+ /**
825
+ * Get model proxy
826
+ *
827
+ * @param params - Method parameters
828
+ * @param params.modelProxyName - Model proxy name
829
+ * @param params.headers - Custom request headers
830
+ * @param params.config - Optional config override
831
+ * @returns Model proxy object
832
+ */
833
+ getModelProxy = async (params) => {
834
+ const { modelProxyName, headers, config: config2 } = params;
835
+ try {
836
+ const client = this.getClient(config2);
837
+ const runtime = new $Util__namespace.RuntimeOptions({});
838
+ const response = await client.getModelProxyWithOptions(
839
+ modelProxyName,
840
+ headers ?? {},
841
+ runtime
842
+ );
843
+ logger.debug(
844
+ `request api getModelProxy, request Request ID: ${response.body?.requestId}
845
+ request: ${JSON.stringify([modelProxyName])}
846
+ response: ${JSON.stringify(response.body?.data)}`
847
+ );
848
+ return response.body?.data;
849
+ } catch (error) {
850
+ if (error && typeof error === "object" && "statusCode" in error) {
851
+ const e = error;
852
+ const statusCode = e.statusCode;
853
+ const message = e.message || "Unknown error";
854
+ const requestId = e.data?.requestId;
855
+ if (statusCode >= 400 && statusCode < 500) {
856
+ throw new ClientError(statusCode, message, { requestId });
857
+ } else if (statusCode >= 500) {
858
+ throw new ServerError(statusCode, message, { requestId });
859
+ }
860
+ }
861
+ throw error;
862
+ }
863
+ };
864
+ /**
865
+ * List model proxies
866
+ *
867
+ * @param params - Method parameters
868
+ * @param params.input - List options
869
+ * @param params.headers - Custom request headers
870
+ * @param params.config - Optional config override
871
+ * @returns List of model proxy objects
872
+ */
873
+ listModelProxies = async (params) => {
874
+ const { input, headers, config: config2 } = params;
875
+ try {
876
+ const client = this.getClient(config2);
877
+ const runtime = new $Util__namespace.RuntimeOptions({});
878
+ const response = await client.listModelProxiesWithOptions(input, headers ?? {}, runtime);
879
+ logger.debug(
880
+ `request api listModelProxies, request Request ID: ${response.body?.requestId}
881
+ request: ${JSON.stringify([input])}
882
+ response: ${JSON.stringify(response.body?.data)}`
883
+ );
884
+ return response.body?.data;
885
+ } catch (error) {
886
+ if (error && typeof error === "object" && "statusCode" in error) {
887
+ const e = error;
888
+ const statusCode = e.statusCode;
889
+ const message = e.message || "Unknown error";
890
+ const requestId = e.data?.requestId;
891
+ if (statusCode >= 400 && statusCode < 500) {
892
+ throw new ClientError(statusCode, message, { requestId });
893
+ } else if (statusCode >= 500) {
894
+ throw new ServerError(statusCode, message, { requestId });
895
+ }
896
+ }
897
+ throw error;
898
+ }
899
+ };
900
+ };
901
+ }
902
+ });
903
+
904
+ // src/utils/model.ts
905
+ function isFinalStatus(status) {
906
+ return [
907
+ void 0,
908
+ null,
909
+ "",
910
+ ...["READY", "CREATE_FAILED", "UPDATE_FAILED", "DELETE_FAILED"]
911
+ ].includes(status);
912
+ }
913
+ var Status;
914
+ var init_model = __esm({
915
+ "src/utils/model.ts"() {
916
+ Status = {
917
+ CREATING: "CREATING",
918
+ CREATE_FAILED: "CREATE_FAILED",
919
+ READY: "READY",
920
+ UPDATING: "UPDATING",
921
+ UPDATE_FAILED: "UPDATE_FAILED",
922
+ DELETING: "DELETING",
923
+ DELETE_FAILED: "DELETE_FAILED"
924
+ };
925
+ }
926
+ });
927
+
928
+ // src/utils/resource.ts
929
+ function updateObjectProperties(target, source) {
930
+ for (const key in source) {
931
+ if (Object.prototype.hasOwnProperty.call(source, key) && typeof source[key] !== "function" && !key.startsWith("_")) {
932
+ target[key] = source[key];
933
+ }
934
+ }
935
+ }
936
+ function listAllResourcesFunction(list) {
937
+ return async (params) => {
938
+ const { config: config2, ...restParams } = params ?? {};
939
+ const allResults = [];
940
+ let page = 1;
941
+ const pageSize = 50;
942
+ while (true) {
943
+ const pageResults = await list({
944
+ input: {
945
+ ...restParams,
946
+ pageNumber: page,
947
+ pageSize
948
+ },
949
+ config: config2
950
+ });
951
+ page += 1;
952
+ allResults.push(...pageResults);
953
+ if (pageResults.length < pageSize) break;
954
+ }
955
+ const resultSet = /* @__PURE__ */ new Set();
956
+ const results = [];
957
+ for (const item of allResults) {
958
+ const uniqId = item.uniqIdCallback() || "";
959
+ if (!resultSet.has(uniqId) && uniqId) {
960
+ resultSet.add(uniqId);
961
+ results.push(item);
962
+ }
963
+ }
964
+ return results;
965
+ };
966
+ }
967
+ var ResourceBase;
968
+ var init_resource = __esm({
969
+ "src/utils/resource.ts"() {
970
+ init_exception();
971
+ init_log();
972
+ init_model();
973
+ ResourceBase = class {
974
+ status;
975
+ _config;
976
+ // static async list(params?: {
977
+ // input?: PageableInput;
978
+ // config?: Config;
979
+ // }): Promise<WithUniqIdCallback[]> {
980
+ // return [];
981
+ // }
982
+ waitUntil = async (params) => {
983
+ const { checkFinishedCallback, intervalSeconds = 5, timeoutSeconds = 300 } = params;
984
+ const startTime = Date.now();
985
+ while (true) {
986
+ if (await checkFinishedCallback(this)) return this;
987
+ if (Date.now() - startTime >= timeoutSeconds * 1e3) {
988
+ throw new Error("Timeout waiting for resource to reach desired state");
989
+ }
990
+ await new Promise((resolve) => setTimeout(resolve, intervalSeconds * 1e3));
991
+ }
992
+ };
993
+ waitUntilReadyOrFailed = async (params) => {
994
+ const { callback, intervalSeconds = 5, timeoutSeconds = 300 } = params ?? {};
995
+ async function checkFinishedCallback(resource) {
996
+ await resource.refresh();
997
+ if (callback) await callback(resource);
998
+ logger.debug(`Resource status: ${resource.status}`);
999
+ return isFinalStatus(resource.status);
1000
+ }
1001
+ return await this.waitUntil({
1002
+ checkFinishedCallback,
1003
+ intervalSeconds,
1004
+ timeoutSeconds
1005
+ });
1006
+ };
1007
+ deleteAndWaitUntilFinished = async (params) => {
1008
+ const { callback, intervalSeconds = 5, timeoutSeconds = 300 } = params ?? {};
1009
+ try {
1010
+ await this.delete();
1011
+ } catch (error) {
1012
+ if (error instanceof ResourceNotExistError) return;
1013
+ }
1014
+ async function checkFinishedCallback(resource) {
1015
+ try {
1016
+ await resource.refresh();
1017
+ if (callback) await callback(resource);
1018
+ } catch (error) {
1019
+ if (error instanceof ResourceNotExistError) return true;
1020
+ if (resource.status === Status.DELETING) return false;
1021
+ throw Error(`Resource status is ${resource.status}`);
1022
+ }
1023
+ return false;
1024
+ }
1025
+ return await this.waitUntil({
1026
+ checkFinishedCallback,
1027
+ intervalSeconds,
1028
+ timeoutSeconds
1029
+ });
1030
+ };
1031
+ refresh = async (params) => await this.get(params);
1032
+ /**
1033
+ * 更新实例自身的属性 / Update instance properties
1034
+ *
1035
+ * @param source - 源对象 / Source object
1036
+ */
1037
+ updateSelf(source) {
1038
+ updateObjectProperties(this, source);
1039
+ }
1040
+ setConfig = (config2) => {
1041
+ this._config = config2;
1042
+ return this;
1043
+ };
1044
+ };
1045
+ }
1046
+ });
1047
+ var ModelAPI;
1048
+ var init_model_api = __esm({
1049
+ "src/model/api/model-api.ts"() {
1050
+ ModelAPI = class {
1051
+ getModelInfo;
1052
+ constructor(getModelInfo) {
1053
+ this.getModelInfo = getModelInfo;
1054
+ }
1055
+ // abstract modelInfo(params: { config?: Config }): Promise<ModelInfo>;
1056
+ getProvider = async (params) => {
1057
+ const { model, config: config2 } = params;
1058
+ const info = await this.getModelInfo({ config: config2 });
1059
+ const provider = openaiCompatible.createOpenAICompatible({
1060
+ name: model || info.model || "",
1061
+ apiKey: info.apiKey,
1062
+ baseURL: info.baseUrl || "",
1063
+ headers: info.headers
1064
+ });
1065
+ return { provider, model: model || info.model || "" };
1066
+ };
1067
+ getModel = async (params) => {
1068
+ const { provider, model } = await this.getProvider(params);
1069
+ return provider(model);
1070
+ };
1071
+ getEmbeddingModel = async (params) => {
1072
+ const { provider, model } = await this.getProvider(params);
1073
+ return provider.embeddingModel(model);
1074
+ };
1075
+ completion = async (params) => {
1076
+ const { messages, model, stream = false, config: config2, ...kwargs } = params;
1077
+ const { streamText, generateText } = await import('ai');
1078
+ return await (stream ? streamText : generateText)({
1079
+ model: await this.getModel({ model, config: config2 }),
1080
+ messages,
1081
+ ...kwargs
1082
+ });
1083
+ };
1084
+ embedding = async (params) => {
1085
+ const { values, model, config: config2, ...kwargs } = params;
1086
+ const { embedMany } = await import('ai');
1087
+ return await embedMany({
1088
+ model: await this.getEmbeddingModel({ model, config: config2 }),
1089
+ values,
1090
+ ...kwargs
1091
+ });
1092
+ };
1093
+ };
1094
+ }
1095
+ });
1096
+
1097
+ // src/model/model.ts
1098
+ exports.BackendType = void 0; exports.ModelType = void 0; exports.Provider = void 0;
1099
+ var init_model2 = __esm({
1100
+ "src/model/model.ts"() {
1101
+ exports.BackendType = {
1102
+ PROXY: "proxy",
1103
+ SERVICE: "service"
1104
+ };
1105
+ exports.ModelType = {
1106
+ LLM: "llm",
1107
+ TEXT_EMBEDDING: "text-embedding",
1108
+ SPEECH2TEXT: "speech2text",
1109
+ TTS: "tts",
1110
+ RERANK: "rerank",
1111
+ MODERATION: "moderation"
1112
+ };
1113
+ exports.Provider = {
1114
+ OPENAI: "openai",
1115
+ ANTHROPIC: "anthropic",
1116
+ BAICHUAN: "baichuan",
1117
+ DEEPSEEK: "deepseek",
1118
+ GEMINI: "gemini",
1119
+ HUNYUAN: "hunyuan",
1120
+ MINIMAX: "minimax",
1121
+ MOONSHOT: "moonshot",
1122
+ SPARK: "spark",
1123
+ STEPFUN: "stepfun",
1124
+ TONGYI: "tongyi",
1125
+ VERTEX_AI: "vertex_ai",
1126
+ WENXIN: "wenxin",
1127
+ YI: "yi",
1128
+ ZHIPUAI: "zhipuai",
1129
+ CUSTOM: "custom"
1130
+ };
1131
+ }
1132
+ });
1133
+
1134
+ // src/utils/data-api.ts
1135
+ var init_data_api = __esm({
1136
+ "src/utils/data-api.ts"() {
1137
+ init_config();
1138
+ init_exception();
1139
+ init_log();
1140
+ }
1141
+ });
1142
+
1143
+ // src/utils/index.ts
1144
+ var init_utils = __esm({
1145
+ "src/utils/index.ts"() {
1146
+ init_version_check();
1147
+ init_config();
1148
+ init_data_api();
1149
+ init_exception();
1150
+ init_log();
1151
+ init_model();
1152
+ }
1153
+ });
1154
+ var CredentialControlAPI;
1155
+ var init_control2 = __esm({
1156
+ "src/credential/api/control.ts"() {
1157
+ init_control_api();
1158
+ init_exception();
1159
+ init_log();
1160
+ CredentialControlAPI = class extends exports.ModelControlAPI {
1161
+ constructor(config2) {
1162
+ super(config2);
1163
+ }
1164
+ /**
1165
+ * Create credential
1166
+ *
1167
+ * @param params - Method parameters
1168
+ * @param params.input - Credential configuration
1169
+ * @param params.headers - Custom request headers
1170
+ * @param params.config - Optional config override
1171
+ * @returns Created credential object
1172
+ */
1173
+ createCredential = async (params) => {
1174
+ const { input, headers, config: config2 } = params;
1175
+ try {
1176
+ const client = this.getClient(config2);
1177
+ const runtime = new $Util__namespace.RuntimeOptions({});
1178
+ const response = await client.createCredentialWithOptions(
1179
+ new $AgentRun5__namespace.CreateCredentialRequest({ body: input }),
1180
+ headers ?? {},
1181
+ runtime
1182
+ );
1183
+ logger.debug(
1184
+ `request api createCredential, request Request ID: ${response.body?.requestId}
1185
+ request: ${JSON.stringify([input])}
1186
+ response: ${JSON.stringify(response.body?.data)}`
1187
+ );
1188
+ return response.body?.data;
1189
+ } catch (error) {
1190
+ if (error && typeof error === "object" && "statusCode" in error) {
1191
+ const e = error;
1192
+ const statusCode = e.statusCode;
1193
+ const message = e.message || "Unknown error";
1194
+ const requestId = e.data?.requestId;
1195
+ if (statusCode >= 400 && statusCode < 500) {
1196
+ throw new ClientError(statusCode, message, { requestId });
1197
+ } else if (statusCode >= 500) {
1198
+ throw new ServerError(statusCode, message, { requestId });
1199
+ }
1200
+ }
1201
+ throw error;
1202
+ }
1203
+ };
1204
+ /**
1205
+ * Delete credential
1206
+ *
1207
+ * @param params - Method parameters
1208
+ * @param params.credentialName - Credential name
1209
+ * @param params.headers - Custom request headers
1210
+ * @param params.config - Optional config override
1211
+ * @returns Deleted credential object
1212
+ */
1213
+ deleteCredential = async (params) => {
1214
+ const { credentialName, headers, config: config2 } = params;
1215
+ try {
1216
+ const client = this.getClient(config2);
1217
+ const runtime = new $Util__namespace.RuntimeOptions({});
1218
+ const response = await client.deleteCredentialWithOptions(
1219
+ credentialName,
1220
+ headers ?? {},
1221
+ runtime
1222
+ );
1223
+ logger.debug(
1224
+ `request api deleteCredential, request Request ID: ${response.body?.requestId}
1225
+ request: ${JSON.stringify([credentialName])}
1226
+ response: ${JSON.stringify(response.body?.data)}`
1227
+ );
1228
+ return response.body?.data;
1229
+ } catch (error) {
1230
+ if (error && typeof error === "object" && "statusCode" in error) {
1231
+ const e = error;
1232
+ const statusCode = e.statusCode;
1233
+ const message = e.message || "Unknown error";
1234
+ const requestId = e.data?.requestId;
1235
+ if (statusCode >= 400 && statusCode < 500) {
1236
+ throw new ClientError(statusCode, message, { requestId });
1237
+ } else if (statusCode >= 500) {
1238
+ throw new ServerError(statusCode, message, { requestId });
1239
+ }
1240
+ }
1241
+ throw error;
1242
+ }
1243
+ };
1244
+ /**
1245
+ * Update credential
1246
+ *
1247
+ * @param params - Method parameters
1248
+ * @param params.credentialName - Credential name
1249
+ * @param params.input - Credential configuration
1250
+ * @param params.headers - Custom request headers
1251
+ * @param params.config - Optional config override
1252
+ * @returns Updated credential object
1253
+ */
1254
+ updateCredential = async (params) => {
1255
+ const { credentialName, input, headers, config: config2 } = params;
1256
+ try {
1257
+ const client = this.getClient(config2);
1258
+ const runtime = new $Util__namespace.RuntimeOptions({});
1259
+ const response = await client.updateCredentialWithOptions(
1260
+ credentialName,
1261
+ new $AgentRun5__namespace.UpdateCredentialRequest({ body: input }),
1262
+ headers ?? {},
1263
+ runtime
1264
+ );
1265
+ logger.debug(
1266
+ `request api updateCredential, request Request ID: ${response.body?.requestId}
1267
+ request: ${JSON.stringify([credentialName, input])}
1268
+ response: ${JSON.stringify(response.body?.data)}`
1269
+ );
1270
+ return response.body?.data;
1271
+ } catch (error) {
1272
+ if (error && typeof error === "object" && "statusCode" in error) {
1273
+ const e = error;
1274
+ const statusCode = e.statusCode;
1275
+ const message = e.message || "Unknown error";
1276
+ const requestId = e.data?.requestId;
1277
+ if (statusCode >= 400 && statusCode < 500) {
1278
+ throw new ClientError(statusCode, message, { requestId });
1279
+ } else if (statusCode >= 500) {
1280
+ throw new ServerError(statusCode, message, { requestId });
1281
+ }
1282
+ }
1283
+ throw error;
1284
+ }
1285
+ };
1286
+ /**
1287
+ * Get credential
1288
+ *
1289
+ * @param params - Method parameters
1290
+ * @param params.credentialName - Credential name
1291
+ * @param params.headers - Custom request headers
1292
+ * @param params.config - Optional config override
1293
+ * @returns Credential object
1294
+ */
1295
+ getCredential = async (params) => {
1296
+ const { credentialName, headers, config: config2 } = params;
1297
+ try {
1298
+ const client = this.getClient(config2);
1299
+ const runtime = new $Util__namespace.RuntimeOptions({});
1300
+ const response = await client.getCredentialWithOptions(
1301
+ credentialName,
1302
+ headers ?? {},
1303
+ runtime
1304
+ );
1305
+ logger.debug(
1306
+ `request api getCredential, request Request ID: ${response.body?.requestId}
1307
+ request: ${JSON.stringify([credentialName])}
1308
+ response: ${JSON.stringify(response.body?.data)}`
1309
+ );
1310
+ return response.body?.data;
1311
+ } catch (error) {
1312
+ if (error && typeof error === "object" && "statusCode" in error) {
1313
+ const e = error;
1314
+ const statusCode = e.statusCode;
1315
+ const message = e.message || "Unknown error";
1316
+ const requestId = e.data?.requestId;
1317
+ if (statusCode >= 400 && statusCode < 500) {
1318
+ throw new ClientError(statusCode, message, { requestId });
1319
+ } else if (statusCode >= 500) {
1320
+ throw new ServerError(statusCode, message, { requestId });
1321
+ }
1322
+ }
1323
+ throw error;
1324
+ }
1325
+ };
1326
+ /**
1327
+ * List credentials
1328
+ *
1329
+ * @param params - Method parameters
1330
+ * @param params.input - List options
1331
+ * @param params.headers - Custom request headers
1332
+ * @param params.config - Optional config override
1333
+ * @returns List of credential objects
1334
+ */
1335
+ listCredentials = async (params) => {
1336
+ const { input, headers, config: config2 } = params;
1337
+ try {
1338
+ const client = this.getClient(config2);
1339
+ const runtime = new $Util__namespace.RuntimeOptions({});
1340
+ const response = await client.listCredentialsWithOptions(input, headers ?? {}, runtime);
1341
+ logger.debug(
1342
+ `request api listCredentials, request Request ID: ${response.body?.requestId}
1343
+ request: ${JSON.stringify([input])}
1344
+ response: ${JSON.stringify(response.body?.data)}`
1345
+ );
1346
+ return response.body?.data;
1347
+ } catch (error) {
1348
+ if (error && typeof error === "object" && "statusCode" in error) {
1349
+ const e = error;
1350
+ const statusCode = e.statusCode;
1351
+ const message = e.message || "Unknown error";
1352
+ const requestId = e.data?.requestId;
1353
+ if (statusCode >= 400 && statusCode < 500) {
1354
+ throw new ClientError(statusCode, message, { requestId });
1355
+ } else if (statusCode >= 500) {
1356
+ throw new ServerError(statusCode, message, { requestId });
1357
+ }
1358
+ }
1359
+ throw error;
1360
+ }
1361
+ };
1362
+ };
1363
+ }
1364
+ });
1365
+
1366
+ // src/credential/model.ts
1367
+ var CredentialListOutput;
1368
+ var init_model3 = __esm({
1369
+ "src/credential/model.ts"() {
1370
+ init_resource();
1371
+ CredentialListOutput = class {
1372
+ createdAt;
1373
+ credentialAuthType;
1374
+ credentialId;
1375
+ credentialName;
1376
+ credentialSourceType;
1377
+ enabled;
1378
+ relatedResourceCount;
1379
+ updatedAt;
1380
+ constructor(data) {
1381
+ if (data) updateObjectProperties(this, data);
1382
+ }
1383
+ uniqIdCallback = () => this.credentialId;
1384
+ toCredential = async (params) => {
1385
+ const { CredentialClient: CredentialClient2 } = await Promise.resolve().then(() => (init_client(), client_exports));
1386
+ return await new CredentialClient2(params?.config).get({
1387
+ name: this.credentialName || "",
1388
+ config: params?.config
1389
+ });
1390
+ };
1391
+ };
1392
+ }
1393
+ });
1394
+
1395
+ // src/credential/client.ts
1396
+ var client_exports = {};
1397
+ __export(client_exports, {
1398
+ CredentialClient: () => CredentialClient
1399
+ });
1400
+ var CredentialClient;
1401
+ var init_client = __esm({
1402
+ "src/credential/client.ts"() {
1403
+ init_utils();
1404
+ init_config();
1405
+ init_control2();
1406
+ init_credential();
1407
+ init_model3();
1408
+ CredentialClient = class {
1409
+ config;
1410
+ controlApi;
1411
+ constructor(config2) {
1412
+ this.config = config2;
1413
+ this.controlApi = new CredentialControlAPI(config2);
1414
+ }
1415
+ /**
1416
+ * Create a Credential
1417
+ */
1418
+ create = async (params) => {
1419
+ try {
1420
+ const { input, config: config2 } = params;
1421
+ const cfg = Config.withConfigs(this.config, config2);
1422
+ const credCfg = input.credentialConfig;
1423
+ const normalized = {
1424
+ ...input,
1425
+ credentialAuthType: credCfg?.credentialAuthType ?? credCfg?.authType,
1426
+ credentialSourceType: credCfg?.credentialSourceType ?? credCfg?.sourceType,
1427
+ credentialPublicConfig: credCfg?.credentialPublicConfig ?? credCfg?.publicConfig,
1428
+ credentialSecret: credCfg?.credentialSecret ?? credCfg?.secret
1429
+ };
1430
+ if (normalized.credentialPublicConfig) {
1431
+ const publicConfig = normalized.credentialPublicConfig;
1432
+ if (!("users" in publicConfig)) {
1433
+ publicConfig.users = [];
1434
+ }
1435
+ }
1436
+ if (normalized.credentialAuthType === "basic") {
1437
+ const pub = normalized.credentialPublicConfig ?? {};
1438
+ if (pub.username) {
1439
+ normalized.credentialPublicConfig = {
1440
+ users: [
1441
+ {
1442
+ username: pub.username,
1443
+ password: normalized.credentialSecret ?? ""
1444
+ }
1445
+ ]
1446
+ };
1447
+ normalized.credentialSecret = "";
1448
+ }
1449
+ }
1450
+ const result = await this.controlApi.createCredential({
1451
+ input: new $AgentRun5__namespace.CreateCredentialInput(normalized),
1452
+ config: cfg
1453
+ });
1454
+ return new Credential(result);
1455
+ } catch (error) {
1456
+ if (error instanceof HTTPError) {
1457
+ throw error.toResourceError("Credential", params?.input?.credentialName);
1458
+ }
1459
+ throw error;
1460
+ }
1461
+ };
1462
+ /**
1463
+ * Delete a Credential
1464
+ */
1465
+ delete = async (params) => {
1466
+ try {
1467
+ const { name, config: config2 } = params;
1468
+ const cfg = Config.withConfigs(this.config, config2);
1469
+ const result = await this.controlApi.deleteCredential({
1470
+ credentialName: name,
1471
+ config: cfg
1472
+ });
1473
+ return new Credential(result);
1474
+ } catch (error) {
1475
+ if (error instanceof HTTPError) {
1476
+ throw error.toResourceError("Credential", params?.name);
1477
+ }
1478
+ throw error;
1479
+ }
1480
+ };
1481
+ /**
1482
+ * Update a Credential
1483
+ */
1484
+ update = async (params) => {
1485
+ try {
1486
+ const { name, input, config: config2 } = params;
1487
+ const cfg = Config.withConfigs(this.config, config2);
1488
+ const credCfg = input.credentialConfig;
1489
+ const normalized = { ...input };
1490
+ if (credCfg) {
1491
+ normalized.credentialAuthType = credCfg?.credentialAuthType ?? credCfg?.authType;
1492
+ normalized.credentialSourceType = credCfg?.credentialSourceType ?? credCfg?.sourceType;
1493
+ normalized.credentialPublicConfig = credCfg?.credentialPublicConfig ?? credCfg?.publicConfig;
1494
+ normalized.credentialSecret = credCfg?.credentialSecret ?? credCfg?.secret;
1495
+ if (normalized.credentialPublicConfig) {
1496
+ const publicConfig = normalized.credentialPublicConfig;
1497
+ if (!("users" in publicConfig)) {
1498
+ publicConfig.users = [];
1499
+ }
1500
+ }
1501
+ if (normalized.credentialAuthType === "basic") {
1502
+ const pub = normalized.credentialPublicConfig ?? {};
1503
+ if (pub.username) {
1504
+ normalized.credentialPublicConfig = {
1505
+ users: [
1506
+ {
1507
+ username: pub.username,
1508
+ password: normalized.credentialSecret ?? ""
1509
+ }
1510
+ ]
1511
+ };
1512
+ normalized.credentialSecret = "";
1513
+ }
1514
+ }
1515
+ }
1516
+ const result = await this.controlApi.updateCredential({
1517
+ credentialName: name,
1518
+ input: new $AgentRun5__namespace.UpdateCredentialInput(normalized),
1519
+ config: cfg
1520
+ });
1521
+ return new Credential(result);
1522
+ } catch (error) {
1523
+ if (error instanceof HTTPError) {
1524
+ throw error.toResourceError("Credential", params?.name);
1525
+ }
1526
+ throw error;
1527
+ }
1528
+ };
1529
+ /**
1530
+ * Get a Credential
1531
+ */
1532
+ get = async (params) => {
1533
+ try {
1534
+ const { name, config: config2 } = params;
1535
+ const cfg = Config.withConfigs(this.config, config2);
1536
+ const result = await this.controlApi.getCredential({
1537
+ credentialName: name,
1538
+ config: cfg
1539
+ });
1540
+ return new Credential(result);
1541
+ } catch (error) {
1542
+ if (error instanceof HTTPError) {
1543
+ throw error.toResourceError("Credential", params?.name);
1544
+ }
1545
+ throw error;
1546
+ }
1547
+ };
1548
+ /**
1549
+ * List Credentials
1550
+ */
1551
+ list = async (params) => {
1552
+ try {
1553
+ const { input, config: config2 } = params ?? {};
1554
+ const cfg = Config.withConfigs(this.config, config2);
1555
+ const results = await this.controlApi.listCredentials({
1556
+ input: new $AgentRun5__namespace.ListCredentialsRequest({ ...input }),
1557
+ config: cfg
1558
+ });
1559
+ return results.items?.map((item) => new CredentialListOutput(item)) ?? [];
1560
+ } catch (error) {
1561
+ if (error instanceof HTTPError) {
1562
+ throw error.toResourceError("Credential");
1563
+ }
1564
+ throw error;
1565
+ }
1566
+ };
1567
+ };
1568
+ }
1569
+ });
1570
+
1571
+ // src/credential/credential.ts
1572
+ var credential_exports = {};
1573
+ __export(credential_exports, {
1574
+ Credential: () => Credential
1575
+ });
1576
+ var Credential;
1577
+ var init_credential = __esm({
1578
+ "src/credential/credential.ts"() {
1579
+ init_resource();
1580
+ init_resource();
1581
+ init_client();
1582
+ Credential = class _Credential extends ResourceBase {
1583
+ credentialName;
1584
+ /** 描述 */
1585
+ description;
1586
+ /** 是否启用 */
1587
+ enabled;
1588
+ credentialId;
1589
+ createdAt;
1590
+ updatedAt;
1591
+ relatedResources;
1592
+ /** 凭证认证类型 */
1593
+ credentialAuthType;
1594
+ /** 凭证来源类型 */
1595
+ credentialSourceType;
1596
+ /** 凭证公共配置 */
1597
+ credentialPublicConfig;
1598
+ /** 凭证密钥 */
1599
+ credentialSecret;
1600
+ _config;
1601
+ constructor(data, config2) {
1602
+ super();
1603
+ if (data) updateObjectProperties(this, data);
1604
+ this._config = config2;
1605
+ }
1606
+ static getClient = () => {
1607
+ return new CredentialClient();
1608
+ };
1609
+ /**
1610
+ * Create a new Credential
1611
+ */
1612
+ static create = async (paramsOrInput) => {
1613
+ const hasInputProp = paramsOrInput && paramsOrInput.input !== void 0;
1614
+ const input = hasInputProp ? paramsOrInput.input : paramsOrInput;
1615
+ const config2 = hasInputProp ? paramsOrInput.config : void 0;
1616
+ return await _Credential.getClient().create({ input, config: config2 });
1617
+ };
1618
+ /**
1619
+ * Delete a Credential by name
1620
+ */
1621
+ static delete = async (paramsOrName) => {
1622
+ const isString = typeof paramsOrName === "string";
1623
+ const name = isString ? paramsOrName : paramsOrName.name;
1624
+ const config2 = isString ? void 0 : paramsOrName.config;
1625
+ return await _Credential.getClient().delete({ name, config: config2 });
1626
+ };
1627
+ /**
1628
+ * Update a Credential by name
1629
+ */
1630
+ static update = async (paramsOrName) => {
1631
+ const name = paramsOrName.name;
1632
+ const input = paramsOrName.input;
1633
+ const config2 = paramsOrName.config;
1634
+ return await _Credential.getClient().update({ name, input, config: config2 });
1635
+ };
1636
+ /**
1637
+ * Get a Credential by name
1638
+ */
1639
+ static get = async (paramsOrName) => {
1640
+ const isString = typeof paramsOrName === "string";
1641
+ const name = isString ? paramsOrName : paramsOrName.name;
1642
+ const config2 = isString ? void 0 : paramsOrName.config;
1643
+ return await _Credential.getClient().get({ name, config: config2 });
1644
+ };
1645
+ /**
1646
+ * List all Credentials (with pagination)
1647
+ */
1648
+ static list = async (paramsOrUndefined) => {
1649
+ const input = paramsOrUndefined?.input ?? paramsOrUndefined;
1650
+ const config2 = paramsOrUndefined?.config;
1651
+ return await _Credential.getClient().list({ input, config: config2 });
1652
+ };
1653
+ static listAll = listAllResourcesFunction(this.list);
1654
+ /**
1655
+ * Delete this credential
1656
+ */
1657
+ delete = async (params) => {
1658
+ const config2 = params?.config;
1659
+ if (!this.credentialName) {
1660
+ throw new Error("credentialName is required to delete a Credential");
1661
+ }
1662
+ const result = await _Credential.delete({
1663
+ name: this.credentialName,
1664
+ config: config2 ?? this._config
1665
+ });
1666
+ updateObjectProperties(this, result);
1667
+ return this;
1668
+ };
1669
+ /**
1670
+ * Update this credential
1671
+ */
1672
+ update = async (params) => {
1673
+ const hasInputProp = params && params.input !== void 0;
1674
+ const input = hasInputProp ? params.input : params;
1675
+ const config2 = hasInputProp ? params.config : void 0;
1676
+ if (!this.credentialName) {
1677
+ throw new Error("credentialName is required to update a Credential");
1678
+ }
1679
+ const result = await _Credential.update({
1680
+ name: this.credentialName,
1681
+ input,
1682
+ config: config2 ?? this._config
1683
+ });
1684
+ updateObjectProperties(this, result);
1685
+ return this;
1686
+ };
1687
+ /**
1688
+ * Refresh this credential's data
1689
+ */
1690
+ get = async (params) => {
1691
+ const config2 = params?.config;
1692
+ if (!this.credentialName) {
1693
+ throw new Error("credentialName is required to refresh a Credential");
1694
+ }
1695
+ const result = await _Credential.get({
1696
+ name: this.credentialName,
1697
+ config: config2 ?? this._config
1698
+ });
1699
+ updateObjectProperties(this, result);
1700
+ return this;
1701
+ };
1702
+ };
1703
+ }
1704
+ });
1705
+ exports.ModelProxy = void 0;
1706
+ var init_model_proxy = __esm({
1707
+ "src/model/model-proxy.ts"() {
1708
+ init_config();
1709
+ init_resource();
1710
+ init_model_api();
1711
+ init_model2();
1712
+ exports.ModelProxy = class _ModelProxy extends ResourceBase {
1713
+ // ImmutableProps
1714
+ modelType;
1715
+ // MutableProps
1716
+ credentialName;
1717
+ description;
1718
+ networkConfiguration;
1719
+ tags;
1720
+ cpu;
1721
+ litellmVersion;
1722
+ memory;
1723
+ modelProxyName;
1724
+ proxyModel;
1725
+ serviceRegionId;
1726
+ proxyConfig;
1727
+ executionRoleArn;
1728
+ // SystemProps
1729
+ endpoint;
1730
+ functionName;
1731
+ modelProxyId;
1732
+ createdAt;
1733
+ lastUpdatedAt;
1734
+ modelApi;
1735
+ constructor() {
1736
+ super();
1737
+ this.modelApi = new ModelAPI(this.modelInfo);
1738
+ this.completion = this.modelApi.completion;
1739
+ this.embedding = this.modelApi.embedding;
1740
+ }
1741
+ completion;
1742
+ embedding;
1743
+ /**
1744
+ * 获取客户端 / Get client
1745
+ *
1746
+ * @returns ModelClient 实例
1747
+ */
1748
+ static getClient() {
1749
+ const { ModelClient: ModelClient2 } = (init_client2(), __toCommonJS(client_exports2));
1750
+ return new ModelClient2();
1751
+ }
1752
+ uniqIdCallback = () => this.modelProxyId;
1753
+ /**
1754
+ * 创建模型代理 / Create model proxy
1755
+ *
1756
+ * @param params - 参数 / Parameters
1757
+ * @returns 创建的模型代理对象 / Created model proxy object
1758
+ */
1759
+ static async create(params) {
1760
+ const { input, config: config2 } = params;
1761
+ return await this.getClient().create({ input, config: config2 });
1762
+ }
1763
+ /**
1764
+ * 根据名称删除模型代理 / Delete model proxy by name
1765
+ *
1766
+ * @param params - 参数 / Parameters
1767
+ * @returns 删除的模型代理对象 / Deleted model proxy object
1768
+ */
1769
+ static async delete(params) {
1770
+ const { name, config: config2 } = params;
1771
+ return await this.getClient().delete({
1772
+ name,
1773
+ backendType: exports.BackendType.PROXY,
1774
+ config: config2
1775
+ });
1776
+ }
1777
+ /**
1778
+ * 根据名称更新模型代理 / Update model proxy by name
1779
+ *
1780
+ * @param params - 参数 / Parameters
1781
+ * @returns 更新后的模型代理对象 / Updated model proxy object
1782
+ */
1783
+ static async update(params) {
1784
+ const { name, input, config: config2 } = params;
1785
+ return await this.getClient().update({ name, input, config: config2 });
1786
+ }
1787
+ /**
1788
+ * 根据名称获取模型代理 / Get model proxy by name
1789
+ *
1790
+ * @param params - 参数 / Parameters
1791
+ * @returns 模型代理对象 / Model proxy object
1792
+ */
1793
+ static async get(params) {
1794
+ const { name, config: config2 } = params;
1795
+ return await this.getClient().get({
1796
+ name,
1797
+ backendType: exports.BackendType.PROXY,
1798
+ config: config2
1799
+ });
1800
+ }
1801
+ /**
1802
+ * 列出模型代理(分页)/ List model proxies (paginated)
1803
+ *
1804
+ * @param pageInput - 分页参数 / Pagination parameters
1805
+ * @param config - 配置 / Configuration
1806
+ * @param kwargs - 其他查询参数 / Other query parameters
1807
+ * @returns 模型代理列表 / Model proxy list
1808
+ */
1809
+ static list = async (params) => {
1810
+ const { input, config: config2 } = params ?? {};
1811
+ return await this.getClient().list({
1812
+ input: {
1813
+ modelProxyName: void 0,
1814
+ // 标识这是 ModelProxyListInput
1815
+ ...input
1816
+ },
1817
+ config: config2
1818
+ });
1819
+ };
1820
+ static listAll = listAllResourcesFunction(this.list);
1821
+ /**
1822
+ * 更新模型代理 / Update model proxy
1823
+ *
1824
+ * @param input - 模型代理更新输入参数 / Model proxy update input parameters
1825
+ * @param config - 配置 / Configuration
1826
+ * @returns 更新后的模型代理对象 / Updated model proxy object
1827
+ */
1828
+ update = async (params) => {
1829
+ const { input, config: config2 } = params;
1830
+ if (!this.modelProxyName) {
1831
+ throw new Error("modelProxyName is required to update a ModelProxy");
1832
+ }
1833
+ const result = await _ModelProxy.update({
1834
+ name: this.modelProxyName,
1835
+ input,
1836
+ config: config2
1837
+ });
1838
+ this.updateSelf(result);
1839
+ return this;
1840
+ };
1841
+ /**
1842
+ * 删除模型代理 / Delete model proxy
1843
+ *
1844
+ * @param params - 参数 / Parameters
1845
+ * @returns 删除的模型代理对象 / Deleted model proxy object
1846
+ */
1847
+ delete = async (params) => {
1848
+ if (!this.modelProxyName) {
1849
+ throw new Error("modelProxyName is required to delete a ModelProxy");
1850
+ }
1851
+ return await _ModelProxy.delete({
1852
+ name: this.modelProxyName,
1853
+ config: params?.config
1854
+ });
1855
+ };
1856
+ /**
1857
+ * 刷新模型代理信息 / Refresh model proxy information
1858
+ *
1859
+ * @param params - 参数 / Parameters
1860
+ * @returns 刷新后的模型代理对象 / Refreshed model proxy object
1861
+ */
1862
+ get = async (params) => {
1863
+ if (!this.modelProxyName) {
1864
+ throw new Error("modelProxyName is required to refresh a ModelProxy");
1865
+ }
1866
+ const result = await _ModelProxy.get({
1867
+ name: this.modelProxyName,
1868
+ config: params?.config
1869
+ });
1870
+ this.updateSelf(result);
1871
+ return this;
1872
+ };
1873
+ /**
1874
+ * 获取模型信息 / Get model information
1875
+ *
1876
+ * @param params - 参数 / Parameters
1877
+ * @param params.config - 配置 / Configuration
1878
+ * @returns 模型基本信息 / Model base information
1879
+ */
1880
+ modelInfo = async (params) => {
1881
+ const cfg = Config.withConfigs(this._config, params?.config);
1882
+ if (!this.modelProxyName) {
1883
+ throw new Error("modelProxyName is required");
1884
+ }
1885
+ if (!this.endpoint) {
1886
+ throw new Error("endpoint is required");
1887
+ }
1888
+ let apiKey = "";
1889
+ if (this.credentialName) {
1890
+ const { Credential: Credential2 } = (init_credential(), __toCommonJS(credential_exports));
1891
+ const credential = await Credential2.get({
1892
+ name: this.credentialName,
1893
+ config: cfg
1894
+ });
1895
+ apiKey = credential.credentialSecret || "";
1896
+ }
1897
+ const defaultModel = this.proxyModel === "single" ? _2__namespace.get(this.proxyConfig, "endpoints[0].modelNames[0]") : this.modelProxyName;
1898
+ return {
1899
+ apiKey,
1900
+ baseUrl: this.endpoint,
1901
+ model: defaultModel,
1902
+ headers: cfg.headers
1903
+ };
1904
+ };
1905
+ };
1906
+ }
1907
+ });
1908
+
1909
+ // src/model/model-service.ts
1910
+ exports.ModelService = void 0;
1911
+ var init_model_service = __esm({
1912
+ "src/model/model-service.ts"() {
1913
+ init_config();
1914
+ init_resource();
1915
+ init_model_api();
1916
+ init_model2();
1917
+ exports.ModelService = class _ModelService extends ResourceBase {
1918
+ // ImmutableProps
1919
+ modelInfoConfigs;
1920
+ modelServiceName;
1921
+ provider;
1922
+ // MutableProps
1923
+ credentialName;
1924
+ description;
1925
+ networkConfiguration;
1926
+ tags;
1927
+ providerSettings;
1928
+ // SystemProps
1929
+ modelServiceId;
1930
+ createdAt;
1931
+ lastUpdatedAt;
1932
+ // CommonProps
1933
+ modelType;
1934
+ modelApi;
1935
+ constructor() {
1936
+ super();
1937
+ this.modelApi = new ModelAPI(this.modelInfo);
1938
+ this.completion = this.modelApi.completion;
1939
+ this.embedding = this.modelApi.embedding;
1940
+ }
1941
+ completion;
1942
+ embedding;
1943
+ /**
1944
+ * 获取客户端 / Get client
1945
+ *
1946
+ * @returns ModelClient 实例
1947
+ */
1948
+ static getClient() {
1949
+ const { ModelClient: ModelClient2 } = (init_client2(), __toCommonJS(client_exports2));
1950
+ return new ModelClient2();
1951
+ }
1952
+ uniqIdCallback = () => this.modelServiceId;
1953
+ /**
1954
+ * 创建模型服务 / Create model service
1955
+ *
1956
+ * @param params - 参数 / Parameters
1957
+ * @returns 创建的模型服务对象 / Created model service object
1958
+ */
1959
+ static async create(params) {
1960
+ const { input, config: config2 } = params;
1961
+ return await this.getClient().create({ input, config: config2 });
1962
+ }
1963
+ /**
1964
+ * 根据名称删除模型服务 / Delete model service by name
1965
+ *
1966
+ * @param params - 参数 / Parameters
1967
+ * @returns 删除的模型服务对象 / Deleted model service object
1968
+ */
1969
+ static async delete(params) {
1970
+ const { name, config: config2 } = params;
1971
+ return await this.getClient().delete({
1972
+ name,
1973
+ backendType: exports.BackendType.SERVICE,
1974
+ config: config2
1975
+ });
1976
+ }
1977
+ /**
1978
+ * 根据名称更新模型服务 / Update model service by name
1979
+ *
1980
+ * @param params - 参数 / Parameters
1981
+ * @returns 更新后的模型服务对象 / Updated model service object
1982
+ */
1983
+ static async update(params) {
1984
+ const { name, input, config: config2 } = params;
1985
+ return await this.getClient().update({ name, input, config: config2 });
1986
+ }
1987
+ /**
1988
+ * 根据名称获取模型服务 / Get model service by name
1989
+ *
1990
+ * @param params - 参数 / Parameters
1991
+ * @returns 模型服务对象 / Model service object
1992
+ */
1993
+ static async get(params) {
1994
+ const { name, config: config2 } = params;
1995
+ return await this.getClient().get({
1996
+ name,
1997
+ backendType: exports.BackendType.SERVICE,
1998
+ config: config2
1999
+ });
2000
+ }
2001
+ /**
2002
+ * 列出模型服务(分页)/ List model services (paginated)
2003
+ *
2004
+ * @param pageInput - 分页参数 / Pagination parameters
2005
+ * @param config - 配置 / Configuration
2006
+ * @param kwargs - 其他查询参数 / Other query parameters
2007
+ * @returns 模型服务列表 / Model service list
2008
+ */
2009
+ static list = async (params) => {
2010
+ const { input, config: config2 } = params ?? {};
2011
+ return await this.getClient().list({
2012
+ input: {
2013
+ ...input
2014
+ },
2015
+ config: config2
2016
+ });
2017
+ };
2018
+ static listAll = listAllResourcesFunction(this.list);
2019
+ /**
2020
+ * 更新模型服务 / Update model service
2021
+ *
2022
+ * @param params - 参数 / Parameters
2023
+ * @returns 更新后的模型服务对象 / Updated model service object
2024
+ */
2025
+ update = async (params) => {
2026
+ const { input, config: config2 } = params;
2027
+ if (!this.modelServiceName) {
2028
+ throw new Error("modelServiceName is required to update a ModelService");
2029
+ }
2030
+ const result = await _ModelService.update({
2031
+ name: this.modelServiceName,
2032
+ input,
2033
+ config: config2
2034
+ });
2035
+ this.updateSelf(result);
2036
+ return this;
2037
+ };
2038
+ /**
2039
+ * 删除模型服务 / Delete model service
2040
+ *
2041
+ * @param config - 配置 / Configuration
2042
+ * @returns 删除的模型服务对象 / Deleted model service object
2043
+ */
2044
+ delete = async (params) => {
2045
+ if (!this.modelServiceName) {
2046
+ throw new Error("modelServiceName is required to delete a ModelService");
2047
+ }
2048
+ return await _ModelService.delete({
2049
+ name: this.modelServiceName,
2050
+ config: params?.config
2051
+ });
2052
+ };
2053
+ /**
2054
+ * 刷新模型服务信息 / Refresh model service information
2055
+ *
2056
+ * @param config - 配置 / Configuration
2057
+ * @returns 刷新后的模型服务对象 / Refreshed model service object
2058
+ */
2059
+ get = async (params) => {
2060
+ if (!this.modelServiceName) {
2061
+ throw new Error("modelServiceName is required to refresh a ModelService");
2062
+ }
2063
+ const result = await _ModelService.get({
2064
+ name: this.modelServiceName,
2065
+ config: params?.config
2066
+ });
2067
+ this.updateSelf(result);
2068
+ return this;
2069
+ };
2070
+ /**
2071
+ * 获取模型信息 / Get model information
2072
+ *
2073
+ * @param params - 参数 / Parameters
2074
+ * @param params.config - 配置 / Configuration
2075
+ * @returns 模型基本信息 / Model base information
2076
+ */
2077
+ modelInfo = async (params) => {
2078
+ const cfg = Config.withConfigs(this._config, params?.config);
2079
+ if (!this.providerSettings) {
2080
+ throw new Error("providerSettings is required");
2081
+ }
2082
+ if (!this.providerSettings.baseUrl) {
2083
+ throw new Error("providerSettings.baseUrl is required");
2084
+ }
2085
+ let apiKey = this.providerSettings.apiKey || "";
2086
+ if (!apiKey && this.credentialName) {
2087
+ const { Credential: Credential2 } = (init_credential(), __toCommonJS(credential_exports));
2088
+ const credential = await Credential2.get({
2089
+ name: this.credentialName,
2090
+ config: cfg
2091
+ });
2092
+ apiKey = credential.credentialSecret || "";
2093
+ }
2094
+ const defaultModel = this.providerSettings.modelNames && this.providerSettings.modelNames.length > 0 ? this.providerSettings.modelNames[0] : void 0;
2095
+ return {
2096
+ apiKey,
2097
+ baseUrl: this.providerSettings.baseUrl,
2098
+ model: defaultModel,
2099
+ headers: cfg.headers,
2100
+ provider: this.provider
2101
+ };
2102
+ };
2103
+ };
2104
+ }
2105
+ });
2106
+
2107
+ // src/model/client.ts
2108
+ var client_exports2 = {};
2109
+ __export(client_exports2, {
2110
+ ModelClient: () => exports.ModelClient
2111
+ });
2112
+ exports.ModelClient = void 0;
2113
+ var init_client2 = __esm({
2114
+ "src/model/client.ts"() {
2115
+ init_config();
2116
+ init_exception();
2117
+ init_control();
2118
+ init_model_proxy();
2119
+ init_model_service();
2120
+ exports.ModelClient = class {
2121
+ config;
2122
+ controlApi;
2123
+ /**
2124
+ * 初始化客户端 / Initialize client
2125
+ *
2126
+ * @param config - 配置对象,可选 / Configuration object, optional
2127
+ */
2128
+ constructor(config2) {
2129
+ this.config = config2;
2130
+ this.controlApi = new ModelControlAPI(config2);
2131
+ }
2132
+ /**
2133
+ * 创建模型服务
2134
+ * Create model service
2135
+ *
2136
+ * @param params - 参数 / Parameters
2137
+ * @returns 创建的对象 / Created object
2138
+ */
2139
+ create = async (params) => {
2140
+ const { input, config: config2 } = params;
2141
+ const cfg = Config.withConfigs(this.config, config2);
2142
+ try {
2143
+ if ("modelProxyName" in input) {
2144
+ const modelProxyInput = input;
2145
+ if (!modelProxyInput.proxyModel) {
2146
+ const endpoints = _2__namespace.get(modelProxyInput, "proxyConfig.endpoints", []);
2147
+ modelProxyInput.proxyModel = endpoints.length > 1 ? "multi" : "single";
2148
+ }
2149
+ const createInput = new $AgentRun5__namespace.CreateModelProxyInput({
2150
+ ...modelProxyInput,
2151
+ cpu: modelProxyInput.cpu ?? 2,
2152
+ // 默认值 2
2153
+ memory: modelProxyInput.memory ?? 4096,
2154
+ // 默认值 4096
2155
+ proxyMode: modelProxyInput.proxyModel
2156
+ });
2157
+ const result = await this.controlApi.createModelProxy({
2158
+ input: createInput,
2159
+ config: cfg
2160
+ });
2161
+ const proxy = new exports.ModelProxy();
2162
+ Object.assign(proxy, result);
2163
+ return proxy;
2164
+ } else {
2165
+ const modelServiceInput = input;
2166
+ const createInput = new $AgentRun5__namespace.CreateModelServiceInput({
2167
+ ...modelServiceInput
2168
+ });
2169
+ const result = await this.controlApi.createModelService({
2170
+ input: createInput,
2171
+ config: cfg
2172
+ });
2173
+ const service = new exports.ModelService();
2174
+ Object.assign(service, result);
2175
+ return service;
2176
+ }
2177
+ } catch (e) {
2178
+ if (e instanceof HTTPError) {
2179
+ const name = "modelProxyName" in input ? input.modelProxyName : input.modelServiceName;
2180
+ throw e.toResourceError("Model", name);
2181
+ }
2182
+ throw e;
2183
+ }
2184
+ };
2185
+ /**
2186
+ * 删除模型服务
2187
+ * Delete model service
2188
+ *
2189
+ * @param params - 参数 / Parameters
2190
+ * @returns 删除的对象 / Deleted object
2191
+ *
2192
+ * @throws ResourceNotExistError - 模型服务不存在 / Model service does not exist
2193
+ */
2194
+ delete = async (params) => {
2195
+ const { name, backendType, config: config2 } = params;
2196
+ const cfg = Config.withConfigs(this.config, config2);
2197
+ let error = null;
2198
+ if (backendType === "proxy" || backendType === void 0) {
2199
+ try {
2200
+ const result = await this.controlApi.deleteModelProxy({
2201
+ modelProxyName: name,
2202
+ config: cfg
2203
+ });
2204
+ const proxy = new exports.ModelProxy();
2205
+ Object.assign(proxy, result);
2206
+ return proxy;
2207
+ } catch (e) {
2208
+ if (e instanceof HTTPError) {
2209
+ error = e;
2210
+ } else {
2211
+ throw e;
2212
+ }
2213
+ }
2214
+ }
2215
+ if (backendType === "proxy" && error !== null) {
2216
+ throw error.toResourceError("Model", name);
2217
+ }
2218
+ try {
2219
+ const result = await this.controlApi.deleteModelService({
2220
+ modelServiceName: name,
2221
+ config: cfg
2222
+ });
2223
+ const service = new exports.ModelService();
2224
+ Object.assign(service, result);
2225
+ return service;
2226
+ } catch (e) {
2227
+ if (e instanceof HTTPError) {
2228
+ throw e.toResourceError("Model", name);
2229
+ }
2230
+ throw e;
2231
+ }
2232
+ };
2233
+ /**
2234
+ * 更新模型服务
2235
+ * Update model service
2236
+ *
2237
+ * @param params - 参数 / Parameters
2238
+ * @returns 更新后的模型服务对象 / Updated model service object
2239
+ *
2240
+ * @throws ResourceNotExistError - 模型服务不存在 / Model service does not exist
2241
+ */
2242
+ update = async (params) => {
2243
+ const { name, input, config: config2 } = params;
2244
+ const cfg = Config.withConfigs(this.config, config2);
2245
+ if ("proxyModel" in input || "executionRoleArn" in input) {
2246
+ const modelProxyInput = input;
2247
+ try {
2248
+ if (!modelProxyInput.proxyModel && modelProxyInput.proxyModel !== void 0) {
2249
+ const endpoints = _2__namespace.get(modelProxyInput, "proxyConfig.endpoints", []);
2250
+ modelProxyInput.proxyModel = endpoints.length > 1 ? "multi" : "single";
2251
+ }
2252
+ const updateInput = new $AgentRun5__namespace.UpdateModelProxyInput({
2253
+ ...modelProxyInput,
2254
+ proxyMode: modelProxyInput.proxyModel
2255
+ });
2256
+ const result = await this.controlApi.updateModelProxy({
2257
+ modelProxyName: name,
2258
+ input: updateInput,
2259
+ config: cfg
2260
+ });
2261
+ const proxy = new exports.ModelProxy();
2262
+ Object.assign(proxy, result);
2263
+ return proxy;
2264
+ } catch (e) {
2265
+ if (e instanceof HTTPError) {
2266
+ throw e.toResourceError("Model", name);
2267
+ }
2268
+ throw e;
2269
+ }
2270
+ } else {
2271
+ const modelServiceInput = input;
2272
+ try {
2273
+ const updateInput = new $AgentRun5__namespace.UpdateModelServiceInput({
2274
+ ...modelServiceInput
2275
+ });
2276
+ const result = await this.controlApi.updateModelService({
2277
+ modelServiceName: name,
2278
+ input: updateInput,
2279
+ config: cfg
2280
+ });
2281
+ const service = new exports.ModelService();
2282
+ Object.assign(service, result);
2283
+ return service;
2284
+ } catch (e) {
2285
+ if (e instanceof HTTPError) {
2286
+ throw e.toResourceError("Model", name);
2287
+ }
2288
+ throw e;
2289
+ }
2290
+ }
2291
+ };
2292
+ /**
2293
+ * 获取模型服务
2294
+ * Get model service
2295
+ *
2296
+ * @param params - 参数 / Parameters
2297
+ * @returns 模型服务对象 / Model service object
2298
+ *
2299
+ * @throws ResourceNotExistError - 模型服务不存在 / Model service does not exist
2300
+ */
2301
+ get = async (params) => {
2302
+ const { name, backendType, config: config2 } = params;
2303
+ const cfg = Config.withConfigs(this.config, config2);
2304
+ let error = null;
2305
+ if (backendType === "proxy" || backendType === void 0) {
2306
+ try {
2307
+ const result = await this.controlApi.getModelProxy({
2308
+ modelProxyName: name,
2309
+ config: cfg
2310
+ });
2311
+ const proxy = new exports.ModelProxy();
2312
+ Object.assign(proxy, result);
2313
+ return proxy;
2314
+ } catch (e) {
2315
+ if (e instanceof HTTPError) {
2316
+ error = e;
2317
+ } else {
2318
+ throw e;
2319
+ }
2320
+ }
2321
+ }
2322
+ if (backendType === "proxy" && error !== null) {
2323
+ throw error.toResourceError("Model", name);
2324
+ }
2325
+ try {
2326
+ const result = await this.controlApi.getModelService({
2327
+ modelServiceName: name,
2328
+ config: cfg
2329
+ });
2330
+ const service = new exports.ModelService();
2331
+ Object.assign(service, result);
2332
+ return service;
2333
+ } catch (e) {
2334
+ if (e instanceof HTTPError) {
2335
+ throw e.toResourceError("Model", name);
2336
+ }
2337
+ throw e;
2338
+ }
2339
+ };
2340
+ /**
2341
+ * 列出模型服务
2342
+ * List model services
2343
+ *
2344
+ * @param params - 参数 / Parameters
2345
+ * @returns 模型服务列表 / Model service list
2346
+ */
2347
+ list = async (params) => {
2348
+ const { input, config: config2 } = params ?? {};
2349
+ const cfg = Config.withConfigs(this.config, config2);
2350
+ if (input && "modelProxyName" in input) {
2351
+ const modelProxyInput = input;
2352
+ const request = new $AgentRun5__namespace.ListModelProxiesRequest({
2353
+ ...modelProxyInput
2354
+ });
2355
+ const result = await this.controlApi.listModelProxies({
2356
+ input: request,
2357
+ config: cfg
2358
+ });
2359
+ return (result.items || []).map((item) => {
2360
+ const proxy = new exports.ModelProxy();
2361
+ Object.assign(proxy, item);
2362
+ return proxy;
2363
+ });
2364
+ } else {
2365
+ const modelServiceInput = input ?? {};
2366
+ const request = new $AgentRun5__namespace.ListModelServicesRequest({
2367
+ ...modelServiceInput
2368
+ });
2369
+ const result = await this.controlApi.listModelServices({
2370
+ input: request,
2371
+ config: cfg
2372
+ });
2373
+ return (result.items || []).map((item) => {
2374
+ const service = new exports.ModelService();
2375
+ Object.assign(service, item);
2376
+ return service;
2377
+ });
2378
+ }
2379
+ };
2380
+ };
2381
+ }
2382
+ });
2383
+
2384
+ // src/model/index.ts
2385
+ init_version_check();
2386
+ init_client2();
2387
+ init_model_service();
2388
+ init_model_proxy();
2389
+ init_control_api();
2390
+ init_model2();
2391
+ //# sourceMappingURL=index.cjs.map
2392
+ //# sourceMappingURL=index.cjs.map