@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,655 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var $AgentRun = require('@alicloud/agentrun20250910');
|
|
4
|
+
var $Util = require('@alicloud/tea-util');
|
|
5
|
+
var $OpenApi = require('@alicloud/openapi-client');
|
|
6
|
+
var dotenv = require('dotenv');
|
|
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 $AgentRun__namespace = /*#__PURE__*/_interopNamespace($AgentRun);
|
|
27
|
+
var $Util__namespace = /*#__PURE__*/_interopNamespace($Util);
|
|
28
|
+
var $OpenApi__namespace = /*#__PURE__*/_interopNamespace($OpenApi);
|
|
29
|
+
var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
|
|
30
|
+
|
|
31
|
+
// src/utils/log.ts
|
|
32
|
+
var LOG_LEVELS = {
|
|
33
|
+
debug: 0,
|
|
34
|
+
info: 1,
|
|
35
|
+
warn: 2,
|
|
36
|
+
error: 3
|
|
37
|
+
};
|
|
38
|
+
var COLORS = {
|
|
39
|
+
reset: "\x1B[0m",
|
|
40
|
+
bright: "\x1B[1m",
|
|
41
|
+
dim: "\x1B[2m",
|
|
42
|
+
italic: "\x1B[3m",
|
|
43
|
+
blue: "\x1B[34m",
|
|
44
|
+
cyan: "\x1B[36m",
|
|
45
|
+
yellow: "\x1B[33m",
|
|
46
|
+
red: "\x1B[31m"
|
|
47
|
+
};
|
|
48
|
+
var Logger = class {
|
|
49
|
+
level = "info";
|
|
50
|
+
// match Python logger name
|
|
51
|
+
prefix = "agentrun-logger";
|
|
52
|
+
setLevel(level) {
|
|
53
|
+
this.level = level;
|
|
54
|
+
}
|
|
55
|
+
shouldLog(level) {
|
|
56
|
+
return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
|
|
57
|
+
}
|
|
58
|
+
getColor(level) {
|
|
59
|
+
switch (level) {
|
|
60
|
+
case "debug":
|
|
61
|
+
return COLORS.cyan;
|
|
62
|
+
case "info":
|
|
63
|
+
return COLORS.blue;
|
|
64
|
+
case "warn":
|
|
65
|
+
return COLORS.yellow;
|
|
66
|
+
case "error":
|
|
67
|
+
return COLORS.red;
|
|
68
|
+
default:
|
|
69
|
+
return COLORS.reset;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// format timestamp like Python: YYYY-MM-DD HH:mm:ss,SSS
|
|
73
|
+
formatTimestamp(d = /* @__PURE__ */ new Date()) {
|
|
74
|
+
const pad = (n, sz = 2) => n.toString().padStart(sz, "0");
|
|
75
|
+
const year = d.getFullYear();
|
|
76
|
+
const month = pad(d.getMonth() + 1);
|
|
77
|
+
const day = pad(d.getDate());
|
|
78
|
+
const hour = pad(d.getHours());
|
|
79
|
+
const minute = pad(d.getMinutes());
|
|
80
|
+
const second = pad(d.getSeconds());
|
|
81
|
+
const ms = pad(d.getMilliseconds(), 3);
|
|
82
|
+
return `${year}-${month}-${day} ${hour}:${minute}:${second},${ms}`;
|
|
83
|
+
}
|
|
84
|
+
// attempt to infer caller file and line by parsing Error.stack
|
|
85
|
+
// helper: parse a single stack frame into {filepath, line, functionName}
|
|
86
|
+
parseFrame(frame) {
|
|
87
|
+
const m = frame.match(/^(?:at\s+)?(?:(.+?)\s+\()?(.*?):(\d+):(\d+)\)?$/);
|
|
88
|
+
if (!m) return null;
|
|
89
|
+
return {
|
|
90
|
+
functionName: m[1] ? m[1].trim() : void 0,
|
|
91
|
+
filepath: m[2],
|
|
92
|
+
line: parseInt(m[3], 10)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// get caller by fixed stack offset (used in public log methods)
|
|
96
|
+
getCallerByOffset() {
|
|
97
|
+
const err = new Error();
|
|
98
|
+
const stack = err.stack;
|
|
99
|
+
if (!stack) return {};
|
|
100
|
+
const lines = stack.split("\n").map((l) => l.trim());
|
|
101
|
+
for (let i = 3; i < lines.length; i++) {
|
|
102
|
+
let parsed = this.parseFrame(lines[i]);
|
|
103
|
+
if (!parsed) {
|
|
104
|
+
const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
|
|
105
|
+
if (m) {
|
|
106
|
+
const parts = m[1].split(":");
|
|
107
|
+
parts.pop();
|
|
108
|
+
const ln = Number(parts.pop());
|
|
109
|
+
const fp2 = parts.join(":");
|
|
110
|
+
parsed = { filepath: fp2, line: ln, functionName: void 0 };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!parsed) continue;
|
|
114
|
+
const fp = parsed.filepath;
|
|
115
|
+
if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
|
|
116
|
+
continue;
|
|
117
|
+
return { filepath: parsed.filepath, line: parsed.line };
|
|
118
|
+
}
|
|
119
|
+
const cwd = process.cwd();
|
|
120
|
+
for (let i = 0; i < lines.length; i++) {
|
|
121
|
+
let parsed = this.parseFrame(lines[i]);
|
|
122
|
+
if (!parsed) {
|
|
123
|
+
const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
|
|
124
|
+
if (m) {
|
|
125
|
+
const parts = m[1].split(":");
|
|
126
|
+
parts.pop();
|
|
127
|
+
const ln = Number(parts.pop());
|
|
128
|
+
const fp2 = parts.join(":");
|
|
129
|
+
parsed = { filepath: fp2, line: ln, functionName: void 0 };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!parsed) continue;
|
|
133
|
+
const fp = parsed.filepath;
|
|
134
|
+
if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
|
|
135
|
+
continue;
|
|
136
|
+
if (fp.includes("/src/utils/log.ts")) continue;
|
|
137
|
+
if (fp.startsWith(cwd)) return { filepath: parsed.filepath, line: parsed.line };
|
|
138
|
+
}
|
|
139
|
+
for (let i = 0; i < lines.length; i++) {
|
|
140
|
+
let parsed = this.parseFrame(lines[i]);
|
|
141
|
+
if (!parsed) {
|
|
142
|
+
const m = lines[i].match(/(\/[^:\s]+:\d+:\d+)/);
|
|
143
|
+
if (m) {
|
|
144
|
+
const parts = m[1].split(":");
|
|
145
|
+
parts.pop();
|
|
146
|
+
const ln = Number(parts.pop());
|
|
147
|
+
const fp2 = parts.join(":");
|
|
148
|
+
parsed = { filepath: fp2, line: ln, functionName: void 0 };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!parsed) continue;
|
|
152
|
+
const fp = parsed.filepath;
|
|
153
|
+
if (fp.includes("node_modules") || fp.includes("internal") || fp.includes("<anonymous>") || fp.includes("native"))
|
|
154
|
+
continue;
|
|
155
|
+
if (fp.includes("/src/utils/log.ts")) continue;
|
|
156
|
+
return { filepath: parsed.filepath, line: parsed.line };
|
|
157
|
+
}
|
|
158
|
+
return {};
|
|
159
|
+
}
|
|
160
|
+
formatMessage(level, message, filepath, line) {
|
|
161
|
+
const timestamp = this.formatTimestamp();
|
|
162
|
+
const color = this.getColor(level);
|
|
163
|
+
const reset = COLORS.reset;
|
|
164
|
+
const levelName = level === "warn" ? "WARNING" : level.toUpperCase();
|
|
165
|
+
const levelStr = `${COLORS.bright}${color}${levelName}${reset}`;
|
|
166
|
+
const nameStr = `${color}[${this.prefix}]${reset}`;
|
|
167
|
+
const tsStr = `${color} ${timestamp}${reset}`;
|
|
168
|
+
const pathInfo = filepath && line !== void 0 ? ` ${COLORS.dim}${COLORS.italic}${filepath}:${line}${reset}` : "";
|
|
169
|
+
const msg = level === "debug" ? `${COLORS.dim}${message}${reset}` : message;
|
|
170
|
+
return `
|
|
171
|
+
${levelStr} ${nameStr}${tsStr}${pathInfo}
|
|
172
|
+
${msg}
|
|
173
|
+
`;
|
|
174
|
+
}
|
|
175
|
+
debug(message, ...args) {
|
|
176
|
+
if (this.shouldLog("debug")) {
|
|
177
|
+
const caller = this.getCallerByOffset();
|
|
178
|
+
console.debug(this.formatMessage("debug", message, caller.filepath, caller.line), ...args);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
info(message, ...args) {
|
|
182
|
+
if (this.shouldLog("info")) {
|
|
183
|
+
const caller = this.getCallerByOffset();
|
|
184
|
+
console.info(this.formatMessage("info", message, caller.filepath, caller.line), ...args);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
warn(message, ...args) {
|
|
188
|
+
if (this.shouldLog("warn")) {
|
|
189
|
+
const caller = this.getCallerByOffset();
|
|
190
|
+
console.warn(this.formatMessage("warn", message, caller.filepath, caller.line), ...args);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
error(message, ...args) {
|
|
194
|
+
if (this.shouldLog("error")) {
|
|
195
|
+
const caller = this.getCallerByOffset();
|
|
196
|
+
console.error(this.formatMessage("error", message, caller.filepath, caller.line), ...args);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
var logger = new Logger();
|
|
201
|
+
if (![void 0, null, "", "False", "FALSE", "false", "0"].includes(process.env["AGENTRUN_SDK_DEBUG"])) {
|
|
202
|
+
logger.setLevel("debug");
|
|
203
|
+
if (!globalThis._AGENTRUN_DEBUG_LOGGED) {
|
|
204
|
+
logger.warn("\u542F\u7528 AgentRun SDK \u8C03\u8BD5\u65E5\u5FD7\uFF0C \u79FB\u9664 AGENTRUN_SDK_DEBUG \u73AF\u5883\u53D8\u91CF\u4EE5\u5173\u95ED");
|
|
205
|
+
globalThis._AGENTRUN_DEBUG_LOGGED = true;
|
|
206
|
+
}
|
|
207
|
+
} else {
|
|
208
|
+
logger.setLevel("info");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/utils/version-check.ts
|
|
212
|
+
var VERSION = "0.0.4" ;
|
|
213
|
+
if (!process.env.DISABLE_BREAKING_CHANGES_WARNING && !globalThis._AGENTRUN_VERSION_WARNING_SHOWN) {
|
|
214
|
+
globalThis._AGENTRUN_VERSION_WARNING_SHOWN = true;
|
|
215
|
+
logger.warn(
|
|
216
|
+
`\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
|
|
217
|
+
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.
|
|
218
|
+
\x1B[2;3m pip install 'agentrun-sdk==${VERSION}' \x1B[0m
|
|
219
|
+
|
|
220
|
+
\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
|
|
221
|
+
Add\x1B[2;3m DISABLE_BREAKING_CHANGES_WARNING=1 \x1B[0mto your environment variables to disable this warning.
|
|
222
|
+
|
|
223
|
+
Releases:\x1B[2;3m https://github.com/Serverless-Devs/agentrun-sdk-python/releases\x1B[0m`
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
dotenv__namespace.config();
|
|
227
|
+
function getEnvWithDefault(defaultValue, ...keys) {
|
|
228
|
+
for (const key of keys) {
|
|
229
|
+
const value = process.env[key];
|
|
230
|
+
if (value !== void 0 && value !== "") {
|
|
231
|
+
return value;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return defaultValue;
|
|
235
|
+
}
|
|
236
|
+
var Config = class _Config {
|
|
237
|
+
_accessKeyId;
|
|
238
|
+
_accessKeySecret;
|
|
239
|
+
_securityToken;
|
|
240
|
+
_accountId;
|
|
241
|
+
_token;
|
|
242
|
+
_regionId;
|
|
243
|
+
_timeout;
|
|
244
|
+
_readTimeout;
|
|
245
|
+
_controlEndpoint;
|
|
246
|
+
_dataEndpoint;
|
|
247
|
+
_devsEndpoint;
|
|
248
|
+
_headers;
|
|
249
|
+
constructor(options = {}) {
|
|
250
|
+
this._accessKeyId = options.accessKeyId ?? getEnvWithDefault("", "AGENTRUN_ACCESS_KEY_ID", "ALIBABA_CLOUD_ACCESS_KEY_ID");
|
|
251
|
+
this._accessKeySecret = options.accessKeySecret ?? getEnvWithDefault("", "AGENTRUN_ACCESS_KEY_SECRET", "ALIBABA_CLOUD_ACCESS_KEY_SECRET");
|
|
252
|
+
this._securityToken = options.securityToken ?? getEnvWithDefault("", "AGENTRUN_SECURITY_TOKEN", "ALIBABA_CLOUD_SECURITY_TOKEN");
|
|
253
|
+
this._accountId = options.accountId ?? getEnvWithDefault("", "AGENTRUN_ACCOUNT_ID", "FC_ACCOUNT_ID");
|
|
254
|
+
this._token = options.token;
|
|
255
|
+
this._regionId = options.regionId ?? getEnvWithDefault("cn-hangzhou", "AGENTRUN_REGION", "FC_REGION");
|
|
256
|
+
this._timeout = options.timeout ?? 6e5;
|
|
257
|
+
this._readTimeout = options.readTimeout ?? 1e8;
|
|
258
|
+
this._controlEndpoint = options.controlEndpoint ?? getEnvWithDefault("", "AGENTRUN_CONTROL_ENDPOINT");
|
|
259
|
+
this._dataEndpoint = options.dataEndpoint ?? getEnvWithDefault("", "AGENTRUN_DATA_ENDPOINT");
|
|
260
|
+
this._devsEndpoint = options.devsEndpoint ?? getEnvWithDefault("", "DEVS_ENDPOINT");
|
|
261
|
+
this._headers = options.headers ?? {};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Create a new Config by merging multiple configs.
|
|
265
|
+
* Later configs take precedence.
|
|
266
|
+
*/
|
|
267
|
+
static withConfigs(...configs) {
|
|
268
|
+
return new _Config().update(...configs);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Update this config with values from other configs.
|
|
272
|
+
* Non-undefined values from later configs take precedence.
|
|
273
|
+
*/
|
|
274
|
+
update(...configs) {
|
|
275
|
+
for (const config2 of configs) {
|
|
276
|
+
if (!config2) continue;
|
|
277
|
+
if (config2._accessKeyId) this._accessKeyId = config2._accessKeyId;
|
|
278
|
+
if (config2._accessKeySecret) this._accessKeySecret = config2._accessKeySecret;
|
|
279
|
+
if (config2._securityToken) this._securityToken = config2._securityToken;
|
|
280
|
+
if (config2._accountId) this._accountId = config2._accountId;
|
|
281
|
+
if (config2._token) this._token = config2._token;
|
|
282
|
+
if (config2._regionId) this._regionId = config2._regionId;
|
|
283
|
+
if (config2._timeout) this._timeout = config2._timeout;
|
|
284
|
+
if (config2._readTimeout) this._readTimeout = config2._readTimeout;
|
|
285
|
+
if (config2._controlEndpoint) this._controlEndpoint = config2._controlEndpoint;
|
|
286
|
+
if (config2._dataEndpoint) this._dataEndpoint = config2._dataEndpoint;
|
|
287
|
+
if (config2._devsEndpoint) this._devsEndpoint = config2._devsEndpoint;
|
|
288
|
+
if (config2._headers && Object.keys(config2._headers).length > 0) {
|
|
289
|
+
this._headers = { ...this._headers, ...config2._headers };
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return this;
|
|
293
|
+
}
|
|
294
|
+
get accessKeyId() {
|
|
295
|
+
return this._accessKeyId;
|
|
296
|
+
}
|
|
297
|
+
get accessKeySecret() {
|
|
298
|
+
return this._accessKeySecret;
|
|
299
|
+
}
|
|
300
|
+
get securityToken() {
|
|
301
|
+
return this._securityToken;
|
|
302
|
+
}
|
|
303
|
+
get accountId() {
|
|
304
|
+
if (!this._accountId) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
"Account ID is not set. Please add AGENTRUN_ACCOUNT_ID environment variable or set it in code."
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
return this._accountId;
|
|
310
|
+
}
|
|
311
|
+
get token() {
|
|
312
|
+
return this._token;
|
|
313
|
+
}
|
|
314
|
+
get regionId() {
|
|
315
|
+
return this._regionId || "cn-hangzhou";
|
|
316
|
+
}
|
|
317
|
+
get timeout() {
|
|
318
|
+
return this._timeout || 6e5;
|
|
319
|
+
}
|
|
320
|
+
get readTimeout() {
|
|
321
|
+
return this._readTimeout || 1e8;
|
|
322
|
+
}
|
|
323
|
+
get controlEndpoint() {
|
|
324
|
+
if (this._controlEndpoint) {
|
|
325
|
+
return this._controlEndpoint;
|
|
326
|
+
}
|
|
327
|
+
return `https://agentrun.${this.regionId}.aliyuncs.com`;
|
|
328
|
+
}
|
|
329
|
+
get dataEndpoint() {
|
|
330
|
+
if (this._dataEndpoint) {
|
|
331
|
+
return this._dataEndpoint;
|
|
332
|
+
}
|
|
333
|
+
return `https://${this.accountId}.agentrun-data.${this.regionId}.aliyuncs.com`;
|
|
334
|
+
}
|
|
335
|
+
get devsEndpoint() {
|
|
336
|
+
if (this._devsEndpoint) {
|
|
337
|
+
return this._devsEndpoint;
|
|
338
|
+
}
|
|
339
|
+
return `https://devs.${this.regionId}.aliyuncs.com`;
|
|
340
|
+
}
|
|
341
|
+
get headers() {
|
|
342
|
+
return this._headers;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// src/utils/control-api.ts
|
|
347
|
+
var $AgentRunClient = (
|
|
348
|
+
// @ts-expect-error - ESM interop: default.default exists when imported as ESM namespace
|
|
349
|
+
$AgentRun__namespace.default?.default ?? $AgentRun__namespace.default ?? $AgentRun__namespace
|
|
350
|
+
);
|
|
351
|
+
var ControlAPI = class {
|
|
352
|
+
config;
|
|
353
|
+
constructor(config2) {
|
|
354
|
+
this.config = config2;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Get the underlying AgentRun client instance
|
|
358
|
+
*/
|
|
359
|
+
getClient(config2) {
|
|
360
|
+
const cfg = Config.withConfigs(this.config, config2);
|
|
361
|
+
let endpoint = cfg.controlEndpoint;
|
|
362
|
+
if (endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
|
|
363
|
+
endpoint = endpoint.split("://")[1];
|
|
364
|
+
}
|
|
365
|
+
const openApiConfig = new $OpenApi__namespace.Config({
|
|
366
|
+
accessKeyId: cfg.accessKeyId,
|
|
367
|
+
accessKeySecret: cfg.accessKeySecret,
|
|
368
|
+
securityToken: cfg.securityToken || void 0,
|
|
369
|
+
regionId: cfg.regionId,
|
|
370
|
+
endpoint,
|
|
371
|
+
connectTimeout: cfg.timeout,
|
|
372
|
+
readTimeout: cfg.readTimeout
|
|
373
|
+
});
|
|
374
|
+
return new $AgentRunClient(openApiConfig);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// src/utils/exception.ts
|
|
379
|
+
var AgentRunError = class _AgentRunError extends Error {
|
|
380
|
+
constructor(message) {
|
|
381
|
+
super(message);
|
|
382
|
+
this.name = "AgentRunError";
|
|
383
|
+
Object.setPrototypeOf(this, _AgentRunError.prototype);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
var HTTPError = class _HTTPError extends AgentRunError {
|
|
387
|
+
statusCode;
|
|
388
|
+
requestId;
|
|
389
|
+
errorCode;
|
|
390
|
+
constructor(statusCode, message, options) {
|
|
391
|
+
super(message);
|
|
392
|
+
this.name = "HTTPError";
|
|
393
|
+
this.statusCode = statusCode;
|
|
394
|
+
this.requestId = options?.requestId;
|
|
395
|
+
this.errorCode = options?.errorCode;
|
|
396
|
+
Object.setPrototypeOf(this, _HTTPError.prototype);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Convert HTTP error to resource-specific error based on status code
|
|
400
|
+
*/
|
|
401
|
+
toResourceError(resourceType, resourceId) {
|
|
402
|
+
if (this.statusCode == 404) return new ResourceNotExistError(resourceType, resourceId);
|
|
403
|
+
else if (this.statusCode == 409) return new ResourceAlreadyExistError(resourceType, resourceId);
|
|
404
|
+
else if ((this.statusCode == 400 || this.statusCode == 500) && this.message.includes("already exists"))
|
|
405
|
+
return new ResourceAlreadyExistError(resourceType, resourceId);
|
|
406
|
+
else return this;
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
var ClientError = class _ClientError extends HTTPError {
|
|
410
|
+
constructor(statusCode, message, options) {
|
|
411
|
+
super(statusCode, message, options);
|
|
412
|
+
this.name = "ClientError";
|
|
413
|
+
Object.setPrototypeOf(this, _ClientError.prototype);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
var ServerError = class _ServerError extends HTTPError {
|
|
417
|
+
constructor(statusCode, message, options) {
|
|
418
|
+
super(statusCode, message, options);
|
|
419
|
+
this.name = "ServerError";
|
|
420
|
+
Object.setPrototypeOf(this, _ServerError.prototype);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
var ResourceNotExistError = class _ResourceNotExistError extends ClientError {
|
|
424
|
+
resourceType;
|
|
425
|
+
resourceId;
|
|
426
|
+
constructor(resourceType, resourceId, options) {
|
|
427
|
+
const message = resourceId ? `${resourceType} '${resourceId}' does not exist` : `${resourceType} does not exist`;
|
|
428
|
+
super(404, message, options);
|
|
429
|
+
this.name = "ResourceNotExistError";
|
|
430
|
+
this.resourceType = resourceType;
|
|
431
|
+
this.resourceId = resourceId;
|
|
432
|
+
Object.setPrototypeOf(this, _ResourceNotExistError.prototype);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
var ResourceAlreadyExistError = class _ResourceAlreadyExistError extends ClientError {
|
|
436
|
+
resourceType;
|
|
437
|
+
resourceId;
|
|
438
|
+
constructor(resourceType, resourceId, options) {
|
|
439
|
+
const message = resourceId ? `${resourceType} '${resourceId}' already exists` : `${resourceType} already exists`;
|
|
440
|
+
super(409, message, options);
|
|
441
|
+
this.name = "ResourceAlreadyExistError";
|
|
442
|
+
this.resourceType = resourceType;
|
|
443
|
+
this.resourceId = resourceId;
|
|
444
|
+
Object.setPrototypeOf(this, _ResourceAlreadyExistError.prototype);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
// src/credential/api/control.ts
|
|
449
|
+
var CredentialControlAPI = class extends ControlAPI {
|
|
450
|
+
constructor(config2) {
|
|
451
|
+
super(config2);
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Create credential
|
|
455
|
+
*
|
|
456
|
+
* @param params - Method parameters
|
|
457
|
+
* @param params.input - Credential configuration
|
|
458
|
+
* @param params.headers - Custom request headers
|
|
459
|
+
* @param params.config - Optional config override
|
|
460
|
+
* @returns Created credential object
|
|
461
|
+
*/
|
|
462
|
+
createCredential = async (params) => {
|
|
463
|
+
const { input, headers, config: config2 } = params;
|
|
464
|
+
try {
|
|
465
|
+
const client = this.getClient(config2);
|
|
466
|
+
const runtime = new $Util__namespace.RuntimeOptions({});
|
|
467
|
+
const response = await client.createCredentialWithOptions(
|
|
468
|
+
new $AgentRun__namespace.CreateCredentialRequest({ body: input }),
|
|
469
|
+
headers ?? {},
|
|
470
|
+
runtime
|
|
471
|
+
);
|
|
472
|
+
logger.debug(
|
|
473
|
+
`request api createCredential, request Request ID: ${response.body?.requestId}
|
|
474
|
+
request: ${JSON.stringify([input])}
|
|
475
|
+
response: ${JSON.stringify(response.body?.data)}`
|
|
476
|
+
);
|
|
477
|
+
return response.body?.data;
|
|
478
|
+
} catch (error) {
|
|
479
|
+
if (error && typeof error === "object" && "statusCode" in error) {
|
|
480
|
+
const e = error;
|
|
481
|
+
const statusCode = e.statusCode;
|
|
482
|
+
const message = e.message || "Unknown error";
|
|
483
|
+
const requestId = e.data?.requestId;
|
|
484
|
+
if (statusCode >= 400 && statusCode < 500) {
|
|
485
|
+
throw new ClientError(statusCode, message, { requestId });
|
|
486
|
+
} else if (statusCode >= 500) {
|
|
487
|
+
throw new ServerError(statusCode, message, { requestId });
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
throw error;
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* Delete credential
|
|
495
|
+
*
|
|
496
|
+
* @param params - Method parameters
|
|
497
|
+
* @param params.credentialName - Credential name
|
|
498
|
+
* @param params.headers - Custom request headers
|
|
499
|
+
* @param params.config - Optional config override
|
|
500
|
+
* @returns Deleted credential object
|
|
501
|
+
*/
|
|
502
|
+
deleteCredential = async (params) => {
|
|
503
|
+
const { credentialName, headers, config: config2 } = params;
|
|
504
|
+
try {
|
|
505
|
+
const client = this.getClient(config2);
|
|
506
|
+
const runtime = new $Util__namespace.RuntimeOptions({});
|
|
507
|
+
const response = await client.deleteCredentialWithOptions(
|
|
508
|
+
credentialName,
|
|
509
|
+
headers ?? {},
|
|
510
|
+
runtime
|
|
511
|
+
);
|
|
512
|
+
logger.debug(
|
|
513
|
+
`request api deleteCredential, request Request ID: ${response.body?.requestId}
|
|
514
|
+
request: ${JSON.stringify([credentialName])}
|
|
515
|
+
response: ${JSON.stringify(response.body?.data)}`
|
|
516
|
+
);
|
|
517
|
+
return response.body?.data;
|
|
518
|
+
} catch (error) {
|
|
519
|
+
if (error && typeof error === "object" && "statusCode" in error) {
|
|
520
|
+
const e = error;
|
|
521
|
+
const statusCode = e.statusCode;
|
|
522
|
+
const message = e.message || "Unknown error";
|
|
523
|
+
const requestId = e.data?.requestId;
|
|
524
|
+
if (statusCode >= 400 && statusCode < 500) {
|
|
525
|
+
throw new ClientError(statusCode, message, { requestId });
|
|
526
|
+
} else if (statusCode >= 500) {
|
|
527
|
+
throw new ServerError(statusCode, message, { requestId });
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
throw error;
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
/**
|
|
534
|
+
* Update credential
|
|
535
|
+
*
|
|
536
|
+
* @param params - Method parameters
|
|
537
|
+
* @param params.credentialName - Credential name
|
|
538
|
+
* @param params.input - Credential configuration
|
|
539
|
+
* @param params.headers - Custom request headers
|
|
540
|
+
* @param params.config - Optional config override
|
|
541
|
+
* @returns Updated credential object
|
|
542
|
+
*/
|
|
543
|
+
updateCredential = async (params) => {
|
|
544
|
+
const { credentialName, input, headers, config: config2 } = params;
|
|
545
|
+
try {
|
|
546
|
+
const client = this.getClient(config2);
|
|
547
|
+
const runtime = new $Util__namespace.RuntimeOptions({});
|
|
548
|
+
const response = await client.updateCredentialWithOptions(
|
|
549
|
+
credentialName,
|
|
550
|
+
new $AgentRun__namespace.UpdateCredentialRequest({ body: input }),
|
|
551
|
+
headers ?? {},
|
|
552
|
+
runtime
|
|
553
|
+
);
|
|
554
|
+
logger.debug(
|
|
555
|
+
`request api updateCredential, request Request ID: ${response.body?.requestId}
|
|
556
|
+
request: ${JSON.stringify([credentialName, 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
|
+
* Get 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 Credential object
|
|
583
|
+
*/
|
|
584
|
+
getCredential = 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.getCredentialWithOptions(
|
|
590
|
+
credentialName,
|
|
591
|
+
headers ?? {},
|
|
592
|
+
runtime
|
|
593
|
+
);
|
|
594
|
+
logger.debug(
|
|
595
|
+
`request api getCredential, 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
|
+
* List credentials
|
|
617
|
+
*
|
|
618
|
+
* @param params - Method parameters
|
|
619
|
+
* @param params.input - List options
|
|
620
|
+
* @param params.headers - Custom request headers
|
|
621
|
+
* @param params.config - Optional config override
|
|
622
|
+
* @returns List of credential objects
|
|
623
|
+
*/
|
|
624
|
+
listCredentials = async (params) => {
|
|
625
|
+
const { input, headers, config: config2 } = params;
|
|
626
|
+
try {
|
|
627
|
+
const client = this.getClient(config2);
|
|
628
|
+
const runtime = new $Util__namespace.RuntimeOptions({});
|
|
629
|
+
const response = await client.listCredentialsWithOptions(input, headers ?? {}, runtime);
|
|
630
|
+
logger.debug(
|
|
631
|
+
`request api listCredentials, request Request ID: ${response.body?.requestId}
|
|
632
|
+
request: ${JSON.stringify([input])}
|
|
633
|
+
response: ${JSON.stringify(response.body?.data)}`
|
|
634
|
+
);
|
|
635
|
+
return response.body?.data;
|
|
636
|
+
} catch (error) {
|
|
637
|
+
if (error && typeof error === "object" && "statusCode" in error) {
|
|
638
|
+
const e = error;
|
|
639
|
+
const statusCode = e.statusCode;
|
|
640
|
+
const message = e.message || "Unknown error";
|
|
641
|
+
const requestId = e.data?.requestId;
|
|
642
|
+
if (statusCode >= 400 && statusCode < 500) {
|
|
643
|
+
throw new ClientError(statusCode, message, { requestId });
|
|
644
|
+
} else if (statusCode >= 500) {
|
|
645
|
+
throw new ServerError(statusCode, message, { requestId });
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
throw error;
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
exports.CredentialControlAPI = CredentialControlAPI;
|
|
654
|
+
//# sourceMappingURL=index.cjs.map
|
|
655
|
+
//# sourceMappingURL=index.cjs.map
|