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