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