@actiondock/core 2.0.12 → 2.2.0
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 +61 -30
- package/dist/app/app.d.ts +73 -0
- package/dist/app/app.js +700 -0
- package/dist/app/index.d.ts +2 -0
- package/dist/app/index.js +2 -0
- package/dist/app/types.d.ts +283 -0
- package/dist/app/types.js +1 -0
- package/dist/catalog/action-index.d.ts +1 -1
- package/dist/catalog/action-index.js +93 -0
- package/dist/catalog/action-resolver.d.ts +2 -2
- package/dist/catalog/action-resolver.js +95 -0
- package/dist/catalog/index.d.ts +5 -5
- package/dist/catalog/index.js +5 -0
- package/dist/catalog/location-registry.d.ts +5 -5
- package/dist/catalog/location-registry.js +138 -0
- package/dist/catalog/package-catalog.d.ts +2 -2
- package/dist/catalog/package-catalog.js +76 -0
- package/dist/catalog/types.d.ts +2 -2
- package/dist/catalog/types.js +1 -0
- package/dist/doctor/doctor.d.ts +2 -1
- package/dist/doctor/doctor.js +613 -0
- package/dist/doctor/index.d.ts +2 -2
- package/dist/doctor/index.js +2 -0
- package/dist/doctor/types.js +1 -0
- package/dist/errors.d.ts +122 -0
- package/dist/errors.js +123 -0
- package/dist/execution/index.d.ts +2 -2
- package/dist/execution/index.js +2 -0
- package/dist/execution/service.d.ts +46 -41
- package/dist/execution/service.js +633 -0
- package/dist/execution/types.d.ts +59 -2
- package/dist/execution/types.js +1 -0
- package/dist/export/index.d.ts +1 -1
- package/dist/export/index.js +1 -0
- package/dist/export/templates.d.ts +45 -7
- package/dist/export/templates.js +621 -0
- package/dist/filter/index.d.ts +1 -1
- package/dist/filter/index.js +1 -0
- package/dist/filter/intent.js +123 -0
- package/dist/host/host.d.ts +55 -0
- package/dist/host/host.js +740 -0
- package/dist/host/index.d.ts +2 -0
- package/dist/host/index.js +2 -0
- package/dist/host/types.d.ts +81 -0
- package/dist/host/types.js +1 -0
- package/dist/index.d.ts +21 -16
- package/dist/index.js +20 -8458
- package/dist/ipc/diagnostic.d.ts +65 -0
- package/dist/ipc/diagnostic.js +129 -0
- package/dist/ipc/host.d.ts +7 -0
- package/dist/ipc/host.js +93 -0
- package/dist/ipc/index.d.ts +4 -0
- package/dist/ipc/index.js +4 -0
- package/dist/ipc/target.d.ts +56 -0
- package/dist/ipc/target.js +297 -0
- package/dist/ipc/types.d.ts +42 -0
- package/dist/ipc/types.js +1 -0
- package/dist/platform/default.d.ts +32 -0
- package/dist/platform/default.js +40 -0
- package/dist/platform/index.d.ts +3 -0
- package/dist/platform/index.js +3 -0
- package/dist/platform/node-fs.d.ts +37 -0
- package/dist/platform/node-fs.js +81 -0
- package/dist/platform/types.d.ts +104 -0
- package/dist/platform/types.js +1 -0
- package/dist/profile/client.d.ts +58 -12
- package/dist/profile/client.js +467 -0
- package/dist/profile/index.d.ts +3 -3
- package/dist/profile/index.js +3 -0
- package/dist/profile/manager.d.ts +2 -2
- package/dist/profile/manager.js +294 -0
- package/dist/profile/types.d.ts +1 -1
- package/dist/profile/types.js +1 -0
- package/dist/project/closure.js +68 -0
- package/dist/project/digest.d.ts +29 -0
- package/dist/project/digest.js +324 -0
- package/dist/project/index.d.ts +10 -5
- package/dist/project/index.js +10 -0
- package/dist/project/init.d.ts +3 -4
- package/dist/project/init.js +175 -0
- package/dist/project/loader.d.ts +21 -27
- package/dist/project/loader.js +484 -0
- package/dist/project/lockfile.d.ts +55 -0
- package/dist/project/lockfile.js +175 -0
- package/dist/project/manifest.d.ts +6 -28
- package/dist/project/manifest.js +220 -0
- package/dist/project/resolver.d.ts +116 -0
- package/dist/project/resolver.js +376 -0
- package/dist/project/transactions.d.ts +103 -0
- package/dist/project/transactions.js +1203 -0
- package/dist/project/types-generator.d.ts +33 -0
- package/dist/project/types-generator.js +168 -0
- package/dist/project/types.d.ts +58 -82
- package/dist/project/types.js +1 -0
- package/dist/registry/index.d.ts +5 -2
- package/dist/registry/index.js +5 -0
- package/dist/registry/lock.d.ts +27 -0
- package/dist/registry/lock.js +93 -0
- package/dist/registry/registry.d.ts +32 -11
- package/dist/registry/registry.js +611 -0
- package/dist/registry/resolve.d.ts +62 -0
- package/dist/registry/resolve.js +195 -0
- package/dist/registry/scan.d.ts +38 -0
- package/dist/registry/scan.js +135 -0
- package/dist/registry/types.d.ts +1 -1
- package/dist/registry/types.js +1 -0
- package/dist/runtime/action-collection.d.ts +27 -0
- package/dist/runtime/action-collection.js +57 -0
- package/dist/runtime/clock.d.ts +0 -2
- package/dist/runtime/clock.js +17 -0
- package/dist/runtime/context.d.ts +16 -5
- package/dist/runtime/context.js +242 -0
- package/dist/runtime/env.d.ts +3 -1
- package/dist/runtime/env.js +159 -0
- package/dist/runtime/events.d.ts +46 -14
- package/dist/runtime/events.js +604 -0
- package/dist/runtime/execution-manager.d.ts +1 -1
- package/dist/runtime/execution-manager.js +66 -0
- package/dist/runtime/index.d.ts +10 -9
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/module-loader.d.ts +0 -8
- package/dist/runtime/module-loader.js +16 -0
- package/dist/runtime/process.d.ts +2 -4
- package/dist/runtime/process.js +146 -0
- package/dist/runtime/runner.d.ts +117 -10
- package/dist/runtime/runner.js +984 -0
- package/dist/runtime/standalone.d.ts +68 -19
- package/dist/runtime/standalone.js +536 -0
- package/dist/schema/validator.js +116 -0
- package/dist/server/body.js +93 -0
- package/dist/server/index.d.ts +5 -6
- package/dist/server/index.js +5 -0
- package/dist/server/routes/actions.d.ts +2 -2
- package/dist/server/routes/actions.js +298 -0
- package/dist/server/routes/common.d.ts +28 -17
- package/dist/server/routes/common.js +104 -0
- package/dist/server/routes/config.d.ts +2 -1
- package/dist/server/routes/config.js +173 -0
- package/dist/server/routes/doctor.d.ts +2 -2
- package/dist/server/routes/doctor.js +63 -0
- package/dist/server/routes/health.d.ts +2 -2
- package/dist/server/routes/health.js +35 -0
- package/dist/server/routes/index.d.ts +9 -9
- package/dist/server/routes/index.js +9 -0
- package/dist/server/routes/info.d.ts +4 -2
- package/dist/server/routes/info.js +158 -0
- package/dist/server/routes/playbooks.d.ts +2 -2
- package/dist/server/routes/playbooks.js +134 -0
- package/dist/server/routes/runs.d.ts +2 -2
- package/dist/server/routes/runs.js +343 -0
- package/dist/server/routes/state.d.ts +2 -1
- package/dist/server/routes/state.js +169 -0
- package/dist/server/security.d.ts +11 -4
- package/dist/server/security.js +101 -0
- package/dist/server/server.d.ts +6 -6
- package/dist/server/server.js +355 -0
- package/dist/server/types.d.ts +27 -8
- package/dist/server/types.js +1 -0
- package/dist/storage/data-dir-lock.d.ts +119 -0
- package/dist/storage/data-dir-lock.js +1016 -0
- package/dist/storage/driver.d.ts +4 -10
- package/dist/storage/driver.js +59 -0
- package/dist/storage/index.d.ts +30 -10
- package/dist/storage/index.js +98 -0
- package/dist/storage/lazy.d.ts +8 -0
- package/dist/storage/lazy.js +44 -0
- package/dist/storage/mask.d.ts +12 -5
- package/dist/storage/mask.js +48 -0
- package/dist/storage/params.d.ts +13 -0
- package/dist/storage/params.js +32 -0
- package/dist/storage/sqlite.d.ts +19 -6
- package/dist/storage/sqlite.js +689 -0
- package/dist/storage/types.d.ts +57 -6
- package/dist/storage/types.js +14 -0
- package/dist/target/index.d.ts +4 -0
- package/dist/target/index.js +4 -0
- package/dist/target/local.d.ts +52 -0
- package/dist/target/local.js +343 -0
- package/dist/target/remote.d.ts +76 -0
- package/dist/target/remote.js +839 -0
- package/dist/target/target.d.ts +6 -0
- package/dist/target/target.js +35 -0
- package/dist/target/types.d.ts +246 -0
- package/dist/target/types.js +34 -0
- package/dist/utils/index.d.ts +22 -2
- package/dist/utils/index.js +180 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +4 -0
- package/package.json +6 -7
- package/dist/build/index.d.ts +0 -1
- package/dist/build/templates.d.ts +0 -19
- package/dist/server/runtime-registry.d.ts +0 -78
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { normalizeServerUrl } from "./manager.js";
|
|
3
|
+
import { ACTION_CANCELLED, NETWORK_ERROR } from "../errors.js";
|
|
4
|
+
import { isLoopbackHost } from "../server/security.js";
|
|
5
|
+
/**
|
|
6
|
+
* 校验在携带认证 Token 时传输层协议是否安全。
|
|
7
|
+
* 若请求携带认证 Token 且目标为非本地回环的明文 http://,默认报错拒绝。
|
|
8
|
+
* 可通过 allowInsecureHttp 选项、ACTIONDOCK_ALLOW_INSECURE_HTTP 环境变量或 --allow-insecure-http 命令行参数豁免。
|
|
9
|
+
*/
|
|
10
|
+
export function assertSecureTransport(serverUrl, token, allowInsecureHttp) {
|
|
11
|
+
if (!token || !token.trim()) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const allow = allowInsecureHttp === true ||
|
|
15
|
+
(typeof process !== "undefined" &&
|
|
16
|
+
(process.env?.ACTIONDOCK_ALLOW_INSECURE_HTTP === "true" ||
|
|
17
|
+
process.env?.ACTIONDOCK_ALLOW_INSECURE_HTTP === "1" ||
|
|
18
|
+
process.argv?.includes("--allow-insecure-http")));
|
|
19
|
+
if (allow) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const base = normalizeServerUrl(serverUrl);
|
|
23
|
+
if (base.startsWith("http://")) {
|
|
24
|
+
try {
|
|
25
|
+
const parsed = new URL(base);
|
|
26
|
+
if (!isLoopbackHost(parsed.hostname)) {
|
|
27
|
+
const err = new Error(`Insecure HTTP connection with authentication token to non-loopback host '${parsed.hostname}' is prohibited. Use HTTPS or pass --allow-insecure-http to override.`);
|
|
28
|
+
err.code = "INSECURE_TRANSPORT";
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
if (e.code === "INSECURE_TRANSPORT") {
|
|
34
|
+
throw e;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function buildHeaders(token) {
|
|
40
|
+
const headers = {
|
|
41
|
+
Accept: "application/json",
|
|
42
|
+
};
|
|
43
|
+
if (token && token.trim()) {
|
|
44
|
+
headers.Authorization = `Bearer ${token.trim()}`;
|
|
45
|
+
}
|
|
46
|
+
return headers;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 探测指定远端 ActionDock 服务的健康状态与网络延迟。
|
|
50
|
+
*
|
|
51
|
+
* @param serverUrl 目标服务端地址
|
|
52
|
+
* @param token 鉴权 Token(可选)
|
|
53
|
+
* @param timeoutMs 探测超时时间(默认 5000ms)
|
|
54
|
+
*/
|
|
55
|
+
export async function checkRemoteHealth(serverUrl, token, timeoutMs = 5000, options) {
|
|
56
|
+
const startTime = Date.now();
|
|
57
|
+
let timer;
|
|
58
|
+
try {
|
|
59
|
+
assertSecureTransport(serverUrl, token, options?.allowInsecureHttp);
|
|
60
|
+
const base = normalizeServerUrl(serverUrl);
|
|
61
|
+
const v2Url = `${base}/api/v2/health`;
|
|
62
|
+
const controller = new AbortController();
|
|
63
|
+
timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
64
|
+
let res = await fetch(v2Url, {
|
|
65
|
+
method: "GET",
|
|
66
|
+
headers: buildHeaders(token),
|
|
67
|
+
signal: controller.signal,
|
|
68
|
+
});
|
|
69
|
+
if (res.status === 404) {
|
|
70
|
+
try {
|
|
71
|
+
const v1Res = await fetch(`${base}/api/v1/health`, {
|
|
72
|
+
method: "GET",
|
|
73
|
+
headers: buildHeaders(token),
|
|
74
|
+
signal: controller.signal,
|
|
75
|
+
});
|
|
76
|
+
if (v1Res.ok || v1Res.status !== 404) {
|
|
77
|
+
res = v1Res;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch { }
|
|
81
|
+
}
|
|
82
|
+
const latencyMs = Date.now() - startTime;
|
|
83
|
+
if (!res.ok) {
|
|
84
|
+
const text = await res.text().catch(() => "");
|
|
85
|
+
return {
|
|
86
|
+
ok: false,
|
|
87
|
+
latencyMs,
|
|
88
|
+
error: `Server responded with status ${res.status}: ${text || res.statusText}`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const data = (await res.json().catch(() => ({})));
|
|
92
|
+
return {
|
|
93
|
+
ok: true,
|
|
94
|
+
status: data.status || "healthy",
|
|
95
|
+
version: data.version,
|
|
96
|
+
uptime: data.uptime,
|
|
97
|
+
latencyMs,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
const latencyMs = Date.now() - startTime;
|
|
102
|
+
return {
|
|
103
|
+
ok: false,
|
|
104
|
+
latencyMs,
|
|
105
|
+
error: err.name === "AbortError" ? "Connection timed out" : err.message,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
if (timer !== undefined) {
|
|
110
|
+
clearTimeout(timer);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export async function executeRemoteAction(serverUrl, actionId, input = {}, configOverridesOrOptions, tokenArg) {
|
|
115
|
+
// Parse options / backwards compatibility
|
|
116
|
+
let configOverrides;
|
|
117
|
+
let token = tokenArg;
|
|
118
|
+
let timeoutMs;
|
|
119
|
+
let signal;
|
|
120
|
+
let isAsync = false;
|
|
121
|
+
let requestId;
|
|
122
|
+
let allowInsecureHttp;
|
|
123
|
+
if (configOverridesOrOptions && typeof configOverridesOrOptions === "object") {
|
|
124
|
+
if ("token" in configOverridesOrOptions ||
|
|
125
|
+
"timeoutMs" in configOverridesOrOptions ||
|
|
126
|
+
"signal" in configOverridesOrOptions ||
|
|
127
|
+
"async" in configOverridesOrOptions ||
|
|
128
|
+
"requestId" in configOverridesOrOptions ||
|
|
129
|
+
"configOverrides" in configOverridesOrOptions ||
|
|
130
|
+
"allowInsecureHttp" in configOverridesOrOptions) {
|
|
131
|
+
const opts = configOverridesOrOptions;
|
|
132
|
+
configOverrides = opts.configOverrides;
|
|
133
|
+
token = opts.token ?? tokenArg;
|
|
134
|
+
timeoutMs = opts.timeoutMs;
|
|
135
|
+
signal = opts.signal;
|
|
136
|
+
isAsync = Boolean(opts.async);
|
|
137
|
+
requestId = opts.requestId;
|
|
138
|
+
allowInsecureHttp = opts.allowInsecureHttp;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
configOverrides = configOverridesOrOptions;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
assertSecureTransport(serverUrl, token, allowInsecureHttp);
|
|
145
|
+
const base = normalizeServerUrl(serverUrl);
|
|
146
|
+
const v2Url = `${base}/api/v2/actions/${encodeURIComponent(actionId)}/run`;
|
|
147
|
+
const executionPayload = {};
|
|
148
|
+
if (isAsync) {
|
|
149
|
+
executionPayload.mode = "async";
|
|
150
|
+
}
|
|
151
|
+
if (typeof timeoutMs === "number" && timeoutMs > 0) {
|
|
152
|
+
executionPayload.timeoutMs = timeoutMs;
|
|
153
|
+
}
|
|
154
|
+
if (requestId) {
|
|
155
|
+
executionPayload.requestId = requestId;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const headers = {
|
|
159
|
+
...buildHeaders(token),
|
|
160
|
+
"Content-Type": "application/json",
|
|
161
|
+
};
|
|
162
|
+
if (requestId) {
|
|
163
|
+
headers["Idempotency-Key"] = requestId;
|
|
164
|
+
headers["x-request-id"] = requestId;
|
|
165
|
+
}
|
|
166
|
+
const reqBody = JSON.stringify({
|
|
167
|
+
input,
|
|
168
|
+
config: configOverrides,
|
|
169
|
+
execution: Object.keys(executionPayload).length > 0 ? executionPayload : undefined,
|
|
170
|
+
});
|
|
171
|
+
let res = await fetch(v2Url, {
|
|
172
|
+
method: "POST",
|
|
173
|
+
headers,
|
|
174
|
+
body: reqBody,
|
|
175
|
+
signal,
|
|
176
|
+
});
|
|
177
|
+
if (res.status === 404) {
|
|
178
|
+
try {
|
|
179
|
+
const v1Res = await fetch(`${base}/api/v1/actions/${encodeURIComponent(actionId)}/run`, {
|
|
180
|
+
method: "POST",
|
|
181
|
+
headers,
|
|
182
|
+
body: reqBody,
|
|
183
|
+
signal,
|
|
184
|
+
});
|
|
185
|
+
if (v1Res.ok || v1Res.status !== 404) {
|
|
186
|
+
res = v1Res;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch { }
|
|
190
|
+
}
|
|
191
|
+
const data = (await res.json().catch(() => null));
|
|
192
|
+
if (data && typeof data === "object" && typeof data.ok === "boolean") {
|
|
193
|
+
return data;
|
|
194
|
+
}
|
|
195
|
+
if (!res.ok) {
|
|
196
|
+
return {
|
|
197
|
+
ok: false,
|
|
198
|
+
runId: randomUUID(),
|
|
199
|
+
error: {
|
|
200
|
+
code: res.status === 401 ? "UNAUTHORIZED" : "REMOTE_EXECUTION_FAILED",
|
|
201
|
+
message: `Remote server HTTP ${res.status}: ${res.statusText}`,
|
|
202
|
+
details: data,
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
ok: true,
|
|
208
|
+
runId: randomUUID(),
|
|
209
|
+
data,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
if (err.name === "AbortError" || signal?.aborted) {
|
|
214
|
+
return {
|
|
215
|
+
ok: false,
|
|
216
|
+
runId: randomUUID(),
|
|
217
|
+
error: {
|
|
218
|
+
code: ACTION_CANCELLED,
|
|
219
|
+
message: "Action execution was cancelled",
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
ok: false,
|
|
225
|
+
runId: randomUUID(),
|
|
226
|
+
error: {
|
|
227
|
+
code: NETWORK_ERROR,
|
|
228
|
+
message: `Failed to connect to remote ActionDock server at ${serverUrl}: ${err.message}`,
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async function fetchRemoteJson(serverUrl, path, token, options = {}) {
|
|
234
|
+
assertSecureTransport(serverUrl, token, options.allowInsecureHttp);
|
|
235
|
+
const base = normalizeServerUrl(serverUrl);
|
|
236
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
237
|
+
const url = `${base}${normalizedPath}`;
|
|
238
|
+
const method = options.method || "GET";
|
|
239
|
+
const headers = {
|
|
240
|
+
...buildHeaders(token),
|
|
241
|
+
};
|
|
242
|
+
if (options.body !== undefined) {
|
|
243
|
+
headers["Content-Type"] = "application/json";
|
|
244
|
+
}
|
|
245
|
+
let res = await fetch(url, {
|
|
246
|
+
method,
|
|
247
|
+
headers,
|
|
248
|
+
body: options.body !== undefined ? JSON.stringify(options.body) : undefined,
|
|
249
|
+
});
|
|
250
|
+
if (res.status === 404 && normalizedPath.startsWith("/api/v2/")) {
|
|
251
|
+
const v1Path = normalizedPath.replace("/api/v2/", "/api/v1/");
|
|
252
|
+
try {
|
|
253
|
+
const v1Res = await fetch(`${base}${v1Path}`, {
|
|
254
|
+
method,
|
|
255
|
+
headers,
|
|
256
|
+
body: options.body !== undefined ? JSON.stringify(options.body) : undefined,
|
|
257
|
+
});
|
|
258
|
+
if (v1Res.ok || v1Res.status !== 404) {
|
|
259
|
+
res = v1Res;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
catch { }
|
|
263
|
+
}
|
|
264
|
+
const data = (await res.json().catch(() => ({})));
|
|
265
|
+
if (!res.ok || (options.method === "POST" && data && data.ok === false)) {
|
|
266
|
+
const errorPrefix = options.errorPrefix || "Remote request failed";
|
|
267
|
+
const msg = data?.error?.message || `${errorPrefix} (${res.status}): ${res.statusText}`;
|
|
268
|
+
const err = new Error(msg);
|
|
269
|
+
if (data?.error?.code) {
|
|
270
|
+
err.code = data.error.code;
|
|
271
|
+
}
|
|
272
|
+
err.status = res.status;
|
|
273
|
+
err.errorData = data?.error;
|
|
274
|
+
err.details = data?.error?.details ?? data?.error;
|
|
275
|
+
throw err;
|
|
276
|
+
}
|
|
277
|
+
return data;
|
|
278
|
+
}
|
|
279
|
+
export async function fetchRemoteRun(serverUrl, runId, token, options) {
|
|
280
|
+
return fetchRemoteJson(serverUrl, `/api/v2/runs/${encodeURIComponent(runId)}`, token, {
|
|
281
|
+
errorPrefix: `Failed to fetch remote run '${runId}'`,
|
|
282
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
export async function cancelRemoteRun(serverUrl, runId, token, reason, options) {
|
|
286
|
+
return fetchRemoteJson(serverUrl, `/api/v2/runs/${encodeURIComponent(runId)}/cancel`, token, {
|
|
287
|
+
method: "POST",
|
|
288
|
+
body: { reason },
|
|
289
|
+
errorPrefix: `Failed to cancel remote run '${runId}'`,
|
|
290
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
export async function fetchRemoteActions(serverUrl, token, intent, options) {
|
|
294
|
+
const query = intent ? `?intent=${encodeURIComponent(intent)}` : "";
|
|
295
|
+
return fetchRemoteJson(serverUrl, `/api/v2/actions${query}`, token, {
|
|
296
|
+
errorPrefix: "Failed to fetch remote actions",
|
|
297
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
export async function fetchRemoteActionShow(serverUrl, actionId, token, options) {
|
|
301
|
+
return fetchRemoteJson(serverUrl, `/api/v2/actions/${encodeURIComponent(actionId)}`, token, {
|
|
302
|
+
errorPrefix: `Failed to fetch remote action '${actionId}'`,
|
|
303
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
export async function fetchRemoteInfo(serverUrl, token, options) {
|
|
307
|
+
const params = new URLSearchParams();
|
|
308
|
+
if (options?.intent)
|
|
309
|
+
params.set("intent", options.intent);
|
|
310
|
+
if (options?.package)
|
|
311
|
+
params.set("package", options.package);
|
|
312
|
+
if (options?.tree)
|
|
313
|
+
params.set("tree", "true");
|
|
314
|
+
const qs = params.toString() ? `?${params.toString()}` : "";
|
|
315
|
+
return fetchRemoteJson(serverUrl, `/api/v2/info${qs}`, token, {
|
|
316
|
+
errorPrefix: "Failed to fetch remote info",
|
|
317
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
export async function fetchRemoteDoctor(serverUrl, token, targetPackage, options) {
|
|
321
|
+
const query = targetPackage ? `?package=${encodeURIComponent(targetPackage)}` : "";
|
|
322
|
+
return fetchRemoteJson(serverUrl, `/api/v2/doctor${query}`, token, {
|
|
323
|
+
errorPrefix: "Failed to fetch remote doctor report",
|
|
324
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
export async function fetchRemotePlaybooks(serverUrl, token, options) {
|
|
328
|
+
const params = new URLSearchParams();
|
|
329
|
+
if (options?.intent)
|
|
330
|
+
params.set("intent", options.intent);
|
|
331
|
+
if (options?.package)
|
|
332
|
+
params.set("package", options.package);
|
|
333
|
+
const qs = params.toString() ? `?${params.toString()}` : "";
|
|
334
|
+
return fetchRemoteJson(serverUrl, `/api/v2/playbooks${qs}`, token, {
|
|
335
|
+
errorPrefix: "Failed to fetch remote playbooks",
|
|
336
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
export async function fetchRemotePlaybookShow(serverUrl, playbookId, token, options) {
|
|
340
|
+
return fetchRemoteJson(serverUrl, `/api/v2/playbooks/${encodeURIComponent(playbookId)}`, token, {
|
|
341
|
+
errorPrefix: `Failed to fetch remote playbook '${playbookId}'`,
|
|
342
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
export async function fetchRemoteRuns(serverUrl, token, options) {
|
|
346
|
+
const params = new URLSearchParams();
|
|
347
|
+
if (options?.status)
|
|
348
|
+
params.set("status", options.status);
|
|
349
|
+
if (options?.actionId)
|
|
350
|
+
params.set("actionId", options.actionId);
|
|
351
|
+
if (options?.packageId)
|
|
352
|
+
params.set("packageId", options.packageId);
|
|
353
|
+
if (options?.intent)
|
|
354
|
+
params.set("intent", options.intent);
|
|
355
|
+
if (options?.limit)
|
|
356
|
+
params.set("limit", String(options.limit));
|
|
357
|
+
const qs = params.toString() ? `?${params.toString()}` : "";
|
|
358
|
+
return fetchRemoteJson(serverUrl, `/api/v2/runs${qs}`, token, {
|
|
359
|
+
errorPrefix: "Failed to fetch remote runs",
|
|
360
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
export async function clearRemoteRuns(serverUrl, token, options) {
|
|
364
|
+
return fetchRemoteJson(serverUrl, "/api/v2/runs/clear", token, {
|
|
365
|
+
method: "POST",
|
|
366
|
+
body: options || {},
|
|
367
|
+
errorPrefix: "Failed to clear remote runs",
|
|
368
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
export async function fetchRemoteStateList(serverUrl, token, options) {
|
|
372
|
+
const params = new URLSearchParams();
|
|
373
|
+
if (options?.package)
|
|
374
|
+
params.set("package", options.package);
|
|
375
|
+
if (options?.action)
|
|
376
|
+
params.set("action", options.action);
|
|
377
|
+
if (options?.namespace !== undefined)
|
|
378
|
+
params.set("namespace", options.namespace);
|
|
379
|
+
if (options?.prefix)
|
|
380
|
+
params.set("prefix", options.prefix);
|
|
381
|
+
const qs = params.toString() ? `?${params.toString()}` : "";
|
|
382
|
+
return fetchRemoteJson(serverUrl, `/api/v2/state${qs}`, token, {
|
|
383
|
+
errorPrefix: "Failed to list remote state keys",
|
|
384
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
export async function getRemoteStateKey(serverUrl, key, token, options) {
|
|
388
|
+
const params = new URLSearchParams();
|
|
389
|
+
if (options?.package)
|
|
390
|
+
params.set("package", options.package);
|
|
391
|
+
if (options?.action)
|
|
392
|
+
params.set("action", options.action);
|
|
393
|
+
if (options?.namespace !== undefined)
|
|
394
|
+
params.set("namespace", options.namespace);
|
|
395
|
+
const qs = params.toString() ? `?${params.toString()}` : "";
|
|
396
|
+
return fetchRemoteJson(serverUrl, `/api/v2/state/${encodeURIComponent(key)}${qs}`, token, {
|
|
397
|
+
errorPrefix: `Failed to fetch remote state key '${key}'`,
|
|
398
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
export async function setRemoteStateKey(serverUrl, key, value, token, options) {
|
|
402
|
+
return fetchRemoteJson(serverUrl, `/api/v2/state/${encodeURIComponent(key)}`, token, {
|
|
403
|
+
method: "PUT",
|
|
404
|
+
body: {
|
|
405
|
+
value,
|
|
406
|
+
package: options?.package,
|
|
407
|
+
action: options?.action,
|
|
408
|
+
namespace: options?.namespace,
|
|
409
|
+
ttl: options?.ttl,
|
|
410
|
+
},
|
|
411
|
+
errorPrefix: `Failed to set remote state key '${key}'`,
|
|
412
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
export async function deleteRemoteStateKey(serverUrl, key, token, options) {
|
|
416
|
+
const params = new URLSearchParams();
|
|
417
|
+
if (options?.package)
|
|
418
|
+
params.set("package", options.package);
|
|
419
|
+
if (options?.action)
|
|
420
|
+
params.set("action", options.action);
|
|
421
|
+
if (options?.namespace !== undefined)
|
|
422
|
+
params.set("namespace", options.namespace);
|
|
423
|
+
const qs = params.toString() ? `?${params.toString()}` : "";
|
|
424
|
+
return fetchRemoteJson(serverUrl, `/api/v2/state/${encodeURIComponent(key)}${qs}`, token, {
|
|
425
|
+
method: "DELETE",
|
|
426
|
+
errorPrefix: `Failed to delete remote state key '${key}'`,
|
|
427
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
export async function clearRemoteState(serverUrl, token, options) {
|
|
431
|
+
return fetchRemoteJson(serverUrl, "/api/v2/state/clear", token, {
|
|
432
|
+
method: "POST",
|
|
433
|
+
body: options || {},
|
|
434
|
+
errorPrefix: "Failed to clear remote state",
|
|
435
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
export async function fetchRemoteConfig(serverUrl, token, packageId, options) {
|
|
439
|
+
const query = packageId ? `?package=${encodeURIComponent(packageId)}` : "";
|
|
440
|
+
return fetchRemoteJson(serverUrl, `/api/v2/config${query}`, token, {
|
|
441
|
+
errorPrefix: "Failed to fetch remote config",
|
|
442
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
export async function setRemoteConfig(serverUrl, key, value, token, packageId, options) {
|
|
446
|
+
return fetchRemoteJson(serverUrl, "/api/v2/config", token, {
|
|
447
|
+
method: "PUT",
|
|
448
|
+
body: { key, value, package: packageId },
|
|
449
|
+
errorPrefix: `Failed to set remote config '${key}'`,
|
|
450
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
export async function deleteRemoteConfig(serverUrl, key, token, packageId, options) {
|
|
454
|
+
const query = packageId ? `?package=${encodeURIComponent(packageId)}` : "";
|
|
455
|
+
return fetchRemoteJson(serverUrl, `/api/v2/config/${encodeURIComponent(key)}${query}`, token, {
|
|
456
|
+
method: "DELETE",
|
|
457
|
+
errorPrefix: `Failed to delete remote config '${key}'`,
|
|
458
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
export async function fetchRemoteConfigEnv(serverUrl, token, packageId, options) {
|
|
462
|
+
const query = packageId ? `?package=${encodeURIComponent(packageId)}` : "";
|
|
463
|
+
return fetchRemoteJson(serverUrl, `/api/v2/config/env${query}`, token, {
|
|
464
|
+
errorPrefix: "Failed to fetch remote config env checks",
|
|
465
|
+
allowInsecureHttp: options?.allowInsecureHttp,
|
|
466
|
+
});
|
|
467
|
+
}
|
package/dist/profile/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./types";
|
|
2
|
-
export * from "./manager";
|
|
3
|
-
export * from "./client";
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./manager.js";
|
|
3
|
+
export * from "./client.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { ProfileEntry, ProfilesConfig, ResolvedTarget, TokenResolutionSource } from "./types";
|
|
1
|
+
import type { ProfileEntry, ProfilesConfig, ResolvedTarget, TokenResolutionSource } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* 默认初始 Profiles 配置(预设 local 本地环境)。
|
|
4
4
|
*/
|
|
5
5
|
export declare const DEFAULT_PROFILES_CONFIG: ProfilesConfig;
|
|
6
6
|
/**
|
|
7
|
-
* 格式化并规范化 Server URL
|
|
7
|
+
* 格式化并规范化 Server URL 地址(若未指定协议,本地回环地址默认使用 http://,非本地回环地址默认使用 https://,并移除末尾斜杠)。
|
|
8
8
|
*/
|
|
9
9
|
export declare function normalizeServerUrl(url: string): string;
|
|
10
10
|
/**
|