@actiondock/core 2.6.0 → 2.8.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 -68
- package/dist/catalog/action-catalog.d.ts +56 -0
- package/dist/catalog/action-catalog.js +202 -0
- package/dist/catalog/discovery.d.ts +60 -0
- package/dist/catalog/discovery.js +119 -0
- package/dist/catalog/graph.d.ts +190 -0
- package/dist/catalog/graph.js +589 -0
- package/dist/catalog/index.d.ts +5 -5
- package/dist/catalog/index.js +5 -5
- package/dist/catalog/resolve-action.d.ts +43 -0
- package/dist/catalog/resolve-action.js +119 -0
- package/dist/catalog/resolve-playbook.d.ts +26 -0
- package/dist/catalog/resolve-playbook.js +114 -0
- package/dist/doctor/checks/project.js +27 -8
- package/dist/doctor/checks/registry.js +2 -2
- package/dist/doctor/checks/runtime.js +34 -1
- package/dist/errors.d.ts +122 -10
- package/dist/errors.js +123 -10
- package/dist/execution/service.d.ts +18 -16
- package/dist/execution/service.js +183 -252
- package/dist/execution/types.d.ts +25 -69
- package/dist/execution/types.js +2 -1
- package/dist/filter/intent.d.ts +8 -9
- package/dist/filter/intent.js +49 -10
- package/dist/graph/index.d.ts +4 -0
- package/dist/graph/index.js +4 -0
- package/dist/host/host.d.ts +74 -32
- package/dist/host/host.js +585 -336
- package/dist/host/routing.d.ts +15 -48
- package/dist/host/routing.js +90 -153
- package/dist/host/types.d.ts +50 -17
- package/dist/index.d.ts +21 -22
- package/dist/index.js +19 -21
- package/dist/input/advice.d.ts +104 -0
- package/dist/input/advice.js +716 -0
- package/dist/input/describe.d.ts +106 -0
- package/dist/input/describe.js +176 -0
- package/dist/input/file-input.d.ts +54 -0
- package/dist/input/file-input.js +124 -0
- package/dist/input/flat-decode.d.ts +11 -0
- package/dist/input/flat-decode.js +13 -0
- package/dist/input/flat-errors.d.ts +71 -0
- package/dist/input/flat-errors.js +87 -0
- package/dist/input/flat-materializer.d.ts +29 -0
- package/dist/input/flat-materializer.js +177 -0
- package/dist/input/flat-parser.d.ts +50 -0
- package/dist/input/flat-parser.js +169 -0
- package/dist/input/flat-predicates.d.ts +34 -0
- package/dist/input/flat-predicates.js +50 -0
- package/dist/input/index.d.ts +14 -0
- package/dist/input/index.js +14 -0
- package/dist/input/input-resolver.d.ts +63 -0
- package/dist/input/input-resolver.js +254 -0
- package/dist/input/json-depth-scanner.d.ts +17 -0
- package/dist/input/json-depth-scanner.js +49 -0
- package/dist/input/metadata.d.ts +99 -0
- package/dist/input/metadata.js +99 -0
- package/dist/input/stdin-input.d.ts +26 -0
- package/dist/input/stdin-input.js +125 -0
- package/dist/input/utf8.d.ts +19 -0
- package/dist/input/utf8.js +36 -0
- package/dist/input/validation-mapper.d.ts +27 -0
- package/dist/input/validation-mapper.js +144 -0
- package/dist/invocation/index.d.ts +2 -0
- package/dist/invocation/index.js +2 -0
- package/dist/invocation/policy.d.ts +157 -0
- package/dist/invocation/policy.js +231 -0
- package/dist/invocation/types.d.ts +172 -0
- package/dist/invocation/types.js +97 -0
- package/dist/ipc/diagnostic.d.ts +0 -12
- package/dist/ipc/diagnostic.js +0 -21
- package/dist/ipc/host.d.ts +4 -4
- package/dist/ipc/host.js +44 -47
- package/dist/ipc/index.d.ts +1 -1
- package/dist/ipc/index.js +1 -1
- package/dist/ipc/service.d.ts +40 -0
- package/dist/ipc/service.js +349 -0
- package/dist/ipc/types.d.ts +21 -15
- package/dist/json/index.d.ts +1 -0
- package/dist/json/index.js +1 -0
- package/dist/json/value-validator.d.ts +88 -0
- package/dist/json/value-validator.js +330 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/module-loader.d.ts +63 -0
- package/dist/node/module-loader.js +112 -0
- package/dist/package/index.d.ts +23 -0
- package/dist/package/index.js +18 -0
- package/dist/{app/app.d.ts → package/runtime.d.ts} +41 -20
- package/dist/{app/app.js → package/runtime.js} +140 -95
- package/dist/{app → package}/static-index.js +58 -41
- package/dist/package/storage-view.d.ts +13 -0
- package/dist/package/storage-view.js +22 -0
- package/dist/{app → package}/types.d.ts +76 -57
- package/dist/package/types.js +22 -0
- package/dist/platform/index.d.ts +1 -1
- package/dist/platform/index.js +1 -1
- package/dist/platform/node.d.ts +48 -0
- package/dist/platform/node.js +96 -0
- package/dist/platform/types.d.ts +0 -9
- package/dist/process/control-arbiter.d.ts +2 -1
- package/dist/process/control-arbiter.js +1 -2
- package/dist/process/driver.d.ts +9 -8
- package/dist/process/driver.js +11 -22
- package/dist/process/index.d.ts +2 -0
- package/dist/process/index.js +2 -0
- package/dist/process/managed-record.d.ts +2 -2
- package/dist/process/process-driver.d.ts +109 -0
- package/dist/process/process-driver.js +650 -0
- package/dist/process/process-executor.d.ts +47 -0
- package/dist/process/process-executor.js +296 -0
- package/dist/process/process-manager.js +48 -26
- package/dist/process/run-executor.js +12 -12
- package/dist/profile/client-actions.js +2 -2
- package/dist/profile/client-health.js +3 -2
- package/dist/profile/client-query.js +5 -6
- package/dist/profile/client-transport.d.ts +19 -17
- package/dist/profile/client-transport.js +48 -80
- package/dist/profile/client.d.ts +2 -2
- package/dist/profile/client.js +1 -1
- package/dist/profile/index.d.ts +1 -0
- package/dist/profile/index.js +1 -0
- package/dist/profile/manager.d.ts +5 -0
- package/dist/profile/manager.js +41 -6
- package/dist/project/closure.js +2 -2
- package/dist/project/index.d.ts +8 -1
- package/dist/project/index.js +10 -1
- package/dist/project/init.js +2 -2
- package/dist/project/loader.d.ts +1 -1
- package/dist/project/loader.js +26 -29
- package/dist/project/transactions.js +5 -10
- package/dist/registry/index.d.ts +3 -1
- package/dist/registry/index.js +2 -1
- package/dist/registry/lock.d.ts +28 -7
- package/dist/registry/lock.js +136 -16
- package/dist/registry/registry.d.ts +1 -5
- package/dist/registry/registry.js +1 -53
- package/dist/registry/scan.d.ts +0 -15
- package/dist/registry/scan.js +0 -59
- package/dist/registry/store.d.ts +42 -0
- package/dist/registry/store.js +43 -0
- package/dist/registry/types.d.ts +0 -24
- package/dist/runtime/action-collection.d.ts +1 -1
- package/dist/runtime/action-registry.d.ts +0 -4
- package/dist/runtime/action-registry.js +0 -7
- package/dist/runtime/context.js +5 -11
- package/dist/runtime/events.js +3 -6
- package/dist/runtime/identity.d.ts +22 -0
- package/dist/runtime/identity.js +10 -0
- package/dist/runtime/index.d.ts +1 -2
- package/dist/runtime/index.js +1 -2
- package/dist/runtime/module-loader.d.ts +2 -34
- package/dist/runtime/module-loader.js +1 -16
- package/dist/runtime/process.d.ts +6 -24
- package/dist/runtime/process.js +1 -118
- package/dist/runtime/run-persistence.js +2 -5
- package/dist/runtime/runner.d.ts +33 -103
- package/dist/runtime/runner.js +142 -404
- package/dist/runtime/standalone.d.ts +37 -9
- package/dist/runtime/standalone.js +195 -136
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +1 -0
- package/dist/schema/validator.d.ts +10 -0
- package/dist/schema/validator.js +48 -54
- package/dist/server/body.d.ts +16 -8
- package/dist/server/body.js +33 -16
- package/dist/server/dispatcher.d.ts +6 -10
- package/dist/server/dispatcher.js +24 -32
- package/dist/server/http-server.d.ts +87 -0
- package/dist/server/http-server.js +304 -0
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.js +10 -0
- package/dist/server/mcp-endpoint.d.ts +61 -0
- package/dist/server/mcp-endpoint.js +118 -0
- package/dist/server/routes/actions.js +34 -28
- package/dist/server/routes/common.d.ts +10 -14
- package/dist/server/routes/common.js +32 -56
- package/dist/server/routes/config.js +54 -64
- package/dist/server/routes/doctor.d.ts +1 -1
- package/dist/server/routes/doctor.js +10 -18
- package/dist/server/routes/health.d.ts +1 -1
- package/dist/server/routes/health.js +2 -3
- package/dist/server/routes/info.d.ts +2 -2
- package/dist/server/routes/info.js +12 -13
- package/dist/server/routes/playbooks.js +16 -29
- package/dist/server/routes/runs.js +95 -117
- package/dist/server/routes/state.js +63 -62
- package/dist/server/server.d.ts +2 -2
- package/dist/server/server.js +43 -227
- package/dist/server/types.d.ts +8 -19
- package/dist/service/factory.d.ts +12 -0
- package/dist/service/factory.js +85 -0
- package/dist/{target → service}/index.d.ts +1 -1
- package/dist/{target → service}/index.js +1 -1
- package/dist/service/local.d.ts +27 -0
- package/dist/service/local.js +138 -0
- package/dist/{target → service}/remote-errors.d.ts +3 -6
- package/dist/service/remote-errors.js +38 -0
- package/dist/{target → service}/remote-polling.d.ts +2 -2
- package/dist/{target → service}/remote-polling.js +8 -8
- package/dist/service/remote.d.ts +34 -0
- package/dist/service/remote.js +634 -0
- package/dist/service/sse-stream.d.ts +24 -0
- package/dist/service/sse-stream.js +139 -0
- package/dist/service/types.d.ts +272 -0
- package/dist/service/types.js +32 -0
- package/dist/storage/data-dir-lock.js +10 -5
- package/dist/storage/driver.d.ts +2 -1
- package/dist/storage/driver.js +3 -52
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +1 -0
- package/dist/storage/lock-core.d.ts +2 -6
- package/dist/storage/lock-core.js +4 -17
- package/dist/storage/params.d.ts +2 -8
- package/dist/storage/params.js +2 -8
- package/dist/storage/sqlite-driver.d.ts +40 -0
- package/dist/storage/sqlite-driver.js +116 -0
- package/dist/storage/sqlite.js +21 -6
- package/dist/storage/types.d.ts +4 -4
- package/dist/storage/types.js +2 -2
- package/dist/utils/index.d.ts +53 -0
- package/dist/utils/index.js +99 -4
- package/dist/utils/process.d.ts +10 -0
- package/dist/utils/process.js +21 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +41 -3
- package/dist/app/index.d.ts +0 -2
- package/dist/app/index.js +0 -2
- package/dist/app/types.js +0 -1
- package/dist/catalog/action-index.d.ts +0 -9
- package/dist/catalog/action-index.js +0 -95
- package/dist/catalog/action-resolver.d.ts +0 -20
- package/dist/catalog/action-resolver.js +0 -95
- package/dist/catalog/location-registry.d.ts +0 -15
- package/dist/catalog/location-registry.js +0 -138
- package/dist/catalog/package-catalog.d.ts +0 -7
- package/dist/catalog/package-catalog.js +0 -77
- package/dist/catalog/types.d.ts +0 -68
- package/dist/catalog/types.js +0 -1
- package/dist/export/index.d.ts +0 -1
- package/dist/export/index.js +0 -1
- package/dist/export/templates.d.ts +0 -71
- package/dist/export/templates.js +0 -623
- package/dist/ipc/target.d.ts +0 -74
- package/dist/ipc/target.js +0 -365
- package/dist/platform/default.d.ts +0 -38
- package/dist/platform/default.js +0 -78
- package/dist/project/resolver.d.ts +0 -116
- package/dist/project/resolver.js +0 -376
- package/dist/registry/resolve.d.ts +0 -62
- package/dist/registry/resolve.js +0 -195
- package/dist/runtime/execution-manager.d.ts +0 -48
- package/dist/runtime/execution-manager.js +0 -66
- package/dist/runtime/package-runner-factory.d.ts +0 -82
- package/dist/runtime/package-runner-factory.js +0 -186
- package/dist/target/local.d.ts +0 -53
- package/dist/target/local.js +0 -349
- package/dist/target/remote-errors.js +0 -51
- package/dist/target/remote.d.ts +0 -86
- package/dist/target/remote.js +0 -818
- package/dist/target/target.d.ts +0 -6
- package/dist/target/target.js +0 -37
- package/dist/target/types.d.ts +0 -261
- package/dist/target/types.js +0 -35
- /package/dist/{app → package}/static-index.d.ts +0 -0
- /package/dist/{target → service}/sse-parser.d.ts +0 -0
- /package/dist/{target → service}/sse-parser.js +0 -0
package/dist/target/remote.js
DELETED
|
@@ -1,818 +0,0 @@
|
|
|
1
|
-
import { ActionResolver } from "../catalog/action-resolver.js";
|
|
2
|
-
import { cancelRemoteRun, clearRemoteRuns, clearRemoteState, deleteRemoteConfig, deleteRemoteStateKey, executeRemoteAction, fetchRemoteActionShow, fetchRemoteActions, fetchRemoteConfig, fetchRemoteInfo, fetchRemotePlaybookShow, fetchRemotePlaybooks, fetchRemoteRun, fetchRemoteRuns, fetchRemoteStateList, getRemoteStateKey, setRemoteConfig, setRemoteStateKey, assertSecureTransport, } from "../profile/client.js";
|
|
3
|
-
import { normalizeServerUrl } from "../profile/manager.js";
|
|
4
|
-
import { isTerminalRunStatus } from "../storage/types.js";
|
|
5
|
-
import { ACTIONDOCK_PROTOCOL_VERSION, TargetError, TARGET_PROTOCOL_UNSUPPORTED, TARGET_CAPABILITY_UNAVAILABLE, TARGET_CLOSED, } from "./types.js";
|
|
6
|
-
import { ACTION_CANCELLED, REMOTE_STREAM_UNAVAILABLE, TIMEOUT } from "../errors.js";
|
|
7
|
-
import { getInsecureDispatcher } from "../server/dispatcher.js";
|
|
8
|
-
import { listProtocolRouteCandidates } from "../profile/client.js";
|
|
9
|
-
import { isRemoteStateKeyNotFound, wrapRemoteError } from "./remote-errors.js";
|
|
10
|
-
import { formatTerminalRunResult, pollRunCompletion } from "./remote-polling.js";
|
|
11
|
-
import { parseSseMessages } from "./sse-parser.js";
|
|
12
|
-
/**
|
|
13
|
-
* 读取并解析远端 SSE 事件流。
|
|
14
|
-
*
|
|
15
|
-
* 候选路由依次尝试:v2 /events -> v2 /stream -> v1 /stream;
|
|
16
|
-
* 全部候选均不可用(网络异常或非流式响应)时抛出携带各候选 URL 与
|
|
17
|
-
* 失败原因的 REMOTE_STREAM_UNAVAILABLE 聚合错误,严禁以空流伪装正常。
|
|
18
|
-
*/
|
|
19
|
-
export async function* streamRemoteEvents(serverUrl, runId, token, options) {
|
|
20
|
-
assertSecureTransport(serverUrl, token, {
|
|
21
|
-
allowInsecureHttp: options?.allowInsecureHttp,
|
|
22
|
-
insecure: options?.insecure,
|
|
23
|
-
});
|
|
24
|
-
const base = normalizeServerUrl(serverUrl);
|
|
25
|
-
const runRoute = `runs/${encodeURIComponent(runId)}`;
|
|
26
|
-
// 候选优先级:v2 /events -> v2 /stream -> v1 /stream(后两者经共享协议候选工具展开)
|
|
27
|
-
const candidateUrls = [
|
|
28
|
-
`${base}/api/v2/${runRoute}/events`,
|
|
29
|
-
...listProtocolRouteCandidates(base, `/api/v2/${runRoute}/stream`),
|
|
30
|
-
];
|
|
31
|
-
const headers = {
|
|
32
|
-
Accept: "text/event-stream",
|
|
33
|
-
};
|
|
34
|
-
if (token && token.trim()) {
|
|
35
|
-
headers.Authorization = `Bearer ${token.trim()}`;
|
|
36
|
-
}
|
|
37
|
-
if (options?.after !== undefined) {
|
|
38
|
-
headers["Last-Event-ID"] = String(options.after);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* 依次尝试全部候选路由,返回首个可用响应。
|
|
42
|
-
*
|
|
43
|
-
* 单个候选失败(网络异常或非流式响应)时记录原因继续尝试后续候选;
|
|
44
|
-
* 所有候选均失败时返回汇总后的失败原因列表供上层抛出聚合错误。
|
|
45
|
-
*/
|
|
46
|
-
async function resolveStreamCandidate() {
|
|
47
|
-
const candidateFailures = [];
|
|
48
|
-
for (const url of candidateUrls) {
|
|
49
|
-
const fetchInit = {
|
|
50
|
-
headers,
|
|
51
|
-
signal: options?.signal,
|
|
52
|
-
};
|
|
53
|
-
if (options?.dispatcher) {
|
|
54
|
-
fetchInit.dispatcher = options.dispatcher;
|
|
55
|
-
}
|
|
56
|
-
else if (options?.insecure) {
|
|
57
|
-
fetchInit.dispatcher = getInsecureDispatcher();
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
const resp = await fetch(url, fetchInit);
|
|
61
|
-
if (resp.status === 410) {
|
|
62
|
-
let errJson;
|
|
63
|
-
try {
|
|
64
|
-
errJson = await resp.json();
|
|
65
|
-
}
|
|
66
|
-
catch { }
|
|
67
|
-
const err = new Error(errJson?.error?.message || "Event cursor has expired");
|
|
68
|
-
err.code = errJson?.error?.code || "EVENT_CURSOR_EXPIRED";
|
|
69
|
-
err.details = errJson?.error?.details;
|
|
70
|
-
throw err;
|
|
71
|
-
}
|
|
72
|
-
if (resp.ok && resp.body) {
|
|
73
|
-
return { ok: true, body: resp.body };
|
|
74
|
-
}
|
|
75
|
-
candidateFailures.push({
|
|
76
|
-
url,
|
|
77
|
-
reason: `HTTP ${resp.status} ${resp.statusText || ""}`.trim(),
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
catch (err) {
|
|
81
|
-
if (err?.code === "EVENT_CURSOR_EXPIRED") {
|
|
82
|
-
throw err;
|
|
83
|
-
}
|
|
84
|
-
candidateFailures.push({
|
|
85
|
-
url,
|
|
86
|
-
reason: err?.message ? `${err.name || "Error"}: ${err.message}` : String(err),
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return { ok: false, candidateFailures };
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* 构造全部候选路由均不可用时的聚合错误。
|
|
94
|
-
*/
|
|
95
|
-
function buildStreamUnavailableError(candidateFailures) {
|
|
96
|
-
const summary = candidateFailures
|
|
97
|
-
.map((f) => `${f.url} (${f.reason})`)
|
|
98
|
-
.join(", ");
|
|
99
|
-
const err = new Error(`REMOTE_STREAM_UNAVAILABLE: All event stream candidates failed for run '${runId}': ${summary}`);
|
|
100
|
-
err.code = REMOTE_STREAM_UNAVAILABLE;
|
|
101
|
-
err.details = {
|
|
102
|
-
runId,
|
|
103
|
-
candidates: candidateFailures.map((f) => ({ url: f.url, reason: f.reason })),
|
|
104
|
-
};
|
|
105
|
-
return err;
|
|
106
|
-
}
|
|
107
|
-
const res = await resolveStreamCandidate();
|
|
108
|
-
if (!res.ok) {
|
|
109
|
-
throw buildStreamUnavailableError(res.candidateFailures);
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
for await (const msg of parseSseMessages(res.body, { signal: options?.signal })) {
|
|
113
|
-
const evt = decodeExecutionEvent(msg, runId);
|
|
114
|
-
if (evt)
|
|
115
|
-
yield evt;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch (err) {
|
|
119
|
-
if (err.name === "AbortError" || options?.signal?.aborted) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
throw err;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* 将 SSE 消息载荷解码为统一执行事件。
|
|
127
|
-
*
|
|
128
|
-
* 非 JSON 数据行直接忽略;finish 事件取 data.result 字段,其余事件字段展开合并。
|
|
129
|
-
*/
|
|
130
|
-
function decodeExecutionEvent(msg, runId) {
|
|
131
|
-
try {
|
|
132
|
-
const data = JSON.parse(msg.data);
|
|
133
|
-
if (msg.event === "finish") {
|
|
134
|
-
return {
|
|
135
|
-
eventId: msg.id ?? data.eventId,
|
|
136
|
-
type: "finish",
|
|
137
|
-
runId,
|
|
138
|
-
timestamp: new Date().toISOString(),
|
|
139
|
-
result: data.result || data,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
return {
|
|
144
|
-
eventId: msg.id ?? data.eventId,
|
|
145
|
-
type: (msg.event || "message"),
|
|
146
|
-
runId,
|
|
147
|
-
timestamp: new Date().toISOString(),
|
|
148
|
-
...data,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
catch {
|
|
153
|
-
// 忽略非 JSON 数据行
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* 远程 ActionDockTarget 门面实现。
|
|
159
|
-
* 内部封装基于 HTTP/SSE 协议与远端 ActionDock 服务端的通信管道。
|
|
160
|
-
*/
|
|
161
|
-
export class RemoteActionDockTarget {
|
|
162
|
-
serverUrl;
|
|
163
|
-
token;
|
|
164
|
-
timeoutMs;
|
|
165
|
-
baseTimeoutMs;
|
|
166
|
-
allowInsecureHttp;
|
|
167
|
-
insecure;
|
|
168
|
-
dispatcher;
|
|
169
|
-
isClosed = false;
|
|
170
|
-
constructor(options) {
|
|
171
|
-
this.serverUrl = options.serverUrl;
|
|
172
|
-
this.token = options.token;
|
|
173
|
-
this.timeoutMs = options.timeoutMs;
|
|
174
|
-
this.baseTimeoutMs = options.baseTimeoutMs ?? 60000;
|
|
175
|
-
this.allowInsecureHttp = options.allowInsecureHttp;
|
|
176
|
-
this.insecure = options.insecure;
|
|
177
|
-
this.dispatcher = options.dispatcher;
|
|
178
|
-
}
|
|
179
|
-
assertNotClosed() {
|
|
180
|
-
if (this.isClosed) {
|
|
181
|
-
throw new TargetError(TARGET_CLOSED, "RemoteActionDockTarget is closed");
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
async info() {
|
|
185
|
-
this.assertNotClosed();
|
|
186
|
-
let raw;
|
|
187
|
-
try {
|
|
188
|
-
raw = await fetchRemoteInfo(this.serverUrl, this.token, {
|
|
189
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
190
|
-
insecure: this.insecure,
|
|
191
|
-
dispatcher: this.dispatcher,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
catch (err) {
|
|
195
|
-
wrapRemoteError(err);
|
|
196
|
-
}
|
|
197
|
-
const protocolVersion = (raw && typeof raw === "object" && raw.protocolVersion) || ACTIONDOCK_PROTOCOL_VERSION;
|
|
198
|
-
if (protocolVersion && typeof protocolVersion === "string") {
|
|
199
|
-
const [remoteMajor] = protocolVersion.split(".");
|
|
200
|
-
const [currentMajor] = ACTIONDOCK_PROTOCOL_VERSION.split(".");
|
|
201
|
-
if (remoteMajor !== currentMajor) {
|
|
202
|
-
throw new TargetError(TARGET_PROTOCOL_UNSUPPORTED, `TARGET_PROTOCOL_UNSUPPORTED: Remote server protocol version '${protocolVersion}' is incompatible with expected '${ACTIONDOCK_PROTOCOL_VERSION}'`);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
let packages = [];
|
|
206
|
-
if (Array.isArray(raw)) {
|
|
207
|
-
packages = raw;
|
|
208
|
-
}
|
|
209
|
-
else if (raw && typeof raw === "object") {
|
|
210
|
-
if (Array.isArray(raw.packages)) {
|
|
211
|
-
packages = raw.packages;
|
|
212
|
-
}
|
|
213
|
-
else if (raw.packages && typeof raw.packages === "object") {
|
|
214
|
-
packages = Object.values(raw.packages);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return {
|
|
218
|
-
id: (raw && typeof raw === "object" && raw.id) || "remote-target",
|
|
219
|
-
name: (raw && typeof raw === "object" && raw.name) || "Remote ActionDock Server",
|
|
220
|
-
protocolVersion,
|
|
221
|
-
packages,
|
|
222
|
-
capabilities: (raw && typeof raw === "object" && Array.isArray(raw.capabilities))
|
|
223
|
-
? raw.capabilities
|
|
224
|
-
: ["actions", "playbooks", "runs", "events", "management.config", "management.state"],
|
|
225
|
-
idempotencyPolicy: raw && typeof raw === "object" ? raw.idempotencyPolicy : undefined,
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
async listPackages() {
|
|
229
|
-
this.assertNotClosed();
|
|
230
|
-
const info = await this.info();
|
|
231
|
-
return info.packages;
|
|
232
|
-
}
|
|
233
|
-
async listActions(options) {
|
|
234
|
-
this.assertNotClosed();
|
|
235
|
-
const rawList = await fetchRemoteActions(this.serverUrl, this.token, options?.query, {
|
|
236
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
237
|
-
insecure: this.insecure,
|
|
238
|
-
dispatcher: this.dispatcher,
|
|
239
|
-
});
|
|
240
|
-
let summaries = rawList.map((item) => ({
|
|
241
|
-
id: item.id,
|
|
242
|
-
description: item.description,
|
|
243
|
-
tags: item.tags,
|
|
244
|
-
inputSchema: item.inputSchema,
|
|
245
|
-
outputSchema: item.outputSchema,
|
|
246
|
-
packageId: item.packageId,
|
|
247
|
-
}));
|
|
248
|
-
if (options?.prefix) {
|
|
249
|
-
summaries = summaries.filter((s) => s.id.startsWith(options.prefix));
|
|
250
|
-
}
|
|
251
|
-
if (options?.tags && options.tags.length > 0) {
|
|
252
|
-
summaries = summaries.filter((s) => options.tags.every((t) => s.tags?.includes(t)));
|
|
253
|
-
}
|
|
254
|
-
return summaries;
|
|
255
|
-
}
|
|
256
|
-
async describeAction(ref) {
|
|
257
|
-
this.assertNotClosed();
|
|
258
|
-
let parsed;
|
|
259
|
-
try {
|
|
260
|
-
parsed = ActionResolver.parseRef(ref);
|
|
261
|
-
}
|
|
262
|
-
catch {
|
|
263
|
-
parsed = typeof ref === "object" ? ref : { actionId: ref };
|
|
264
|
-
}
|
|
265
|
-
const actionId = parsed.packageId
|
|
266
|
-
? `${parsed.packageId}/${parsed.actionId}`
|
|
267
|
-
: parsed.actionId;
|
|
268
|
-
const raw = await fetchRemoteActionShow(this.serverUrl, actionId, this.token, {
|
|
269
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
270
|
-
insecure: this.insecure,
|
|
271
|
-
dispatcher: this.dispatcher,
|
|
272
|
-
});
|
|
273
|
-
return {
|
|
274
|
-
id: raw.id,
|
|
275
|
-
description: raw.description,
|
|
276
|
-
inputSchema: raw.inputSchema,
|
|
277
|
-
outputSchema: raw.outputSchema,
|
|
278
|
-
tags: raw.tags,
|
|
279
|
-
annotations: raw.annotations,
|
|
280
|
-
uses: raw.uses,
|
|
281
|
-
entry: raw.entry,
|
|
282
|
-
filePath: raw.filePath,
|
|
283
|
-
packageId: raw.packageId ?? parsed.packageId,
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
async listPlaybooks(options) {
|
|
287
|
-
this.assertNotClosed();
|
|
288
|
-
const rawList = await fetchRemotePlaybooks(this.serverUrl, this.token, {
|
|
289
|
-
...options,
|
|
290
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
291
|
-
insecure: this.insecure,
|
|
292
|
-
dispatcher: this.dispatcher,
|
|
293
|
-
});
|
|
294
|
-
return rawList.map((item) => ({
|
|
295
|
-
id: item.id,
|
|
296
|
-
description: item.description,
|
|
297
|
-
actions: item.actions,
|
|
298
|
-
packageId: item.packageId,
|
|
299
|
-
filePath: item.filePath,
|
|
300
|
-
}));
|
|
301
|
-
}
|
|
302
|
-
async describePlaybook(id) {
|
|
303
|
-
this.assertNotClosed();
|
|
304
|
-
const raw = await fetchRemotePlaybookShow(this.serverUrl, id, this.token, {
|
|
305
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
306
|
-
insecure: this.insecure,
|
|
307
|
-
dispatcher: this.dispatcher,
|
|
308
|
-
});
|
|
309
|
-
const parsedPkgId = id.includes("/") ? id.slice(0, id.lastIndexOf("/")) : undefined;
|
|
310
|
-
return {
|
|
311
|
-
id: raw.id,
|
|
312
|
-
description: raw.description,
|
|
313
|
-
actions: raw.actions,
|
|
314
|
-
filePath: raw.filePath,
|
|
315
|
-
content: raw.content,
|
|
316
|
-
packageId: raw.packageId ?? parsedPkgId,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
async runAction(ref, input, options) {
|
|
320
|
-
this.assertNotClosed();
|
|
321
|
-
let parsed;
|
|
322
|
-
try {
|
|
323
|
-
parsed = ActionResolver.parseRef(ref);
|
|
324
|
-
}
|
|
325
|
-
catch {
|
|
326
|
-
parsed = typeof ref === "object" ? ref : { actionId: ref };
|
|
327
|
-
}
|
|
328
|
-
const actionId = parsed.packageId
|
|
329
|
-
? `${parsed.packageId}/${parsed.actionId}`
|
|
330
|
-
: parsed.actionId;
|
|
331
|
-
return executeRemoteAction(this.serverUrl, actionId, input, {
|
|
332
|
-
configOverrides: options?.config,
|
|
333
|
-
token: this.token,
|
|
334
|
-
timeoutMs: options?.timeoutMs ?? this.timeoutMs,
|
|
335
|
-
signal: options?.signal,
|
|
336
|
-
requestId: options?.requestId,
|
|
337
|
-
async: false,
|
|
338
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
339
|
-
insecure: this.insecure,
|
|
340
|
-
dispatcher: this.dispatcher,
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
async startAction(ref, input, options) {
|
|
344
|
-
this.assertNotClosed();
|
|
345
|
-
let parsed;
|
|
346
|
-
try {
|
|
347
|
-
parsed = ActionResolver.parseRef(ref);
|
|
348
|
-
}
|
|
349
|
-
catch {
|
|
350
|
-
parsed = typeof ref === "object" ? ref : { actionId: ref };
|
|
351
|
-
}
|
|
352
|
-
const actionId = parsed.packageId
|
|
353
|
-
? `${parsed.packageId}/${parsed.actionId}`
|
|
354
|
-
: parsed.actionId;
|
|
355
|
-
const res = await executeRemoteAction(this.serverUrl, actionId, input, {
|
|
356
|
-
configOverrides: options?.config,
|
|
357
|
-
token: this.token,
|
|
358
|
-
timeoutMs: options?.timeoutMs ?? this.timeoutMs,
|
|
359
|
-
signal: options?.signal,
|
|
360
|
-
requestId: options?.requestId,
|
|
361
|
-
async: true,
|
|
362
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
363
|
-
insecure: this.insecure,
|
|
364
|
-
dispatcher: this.dispatcher,
|
|
365
|
-
});
|
|
366
|
-
if (!res.ok) {
|
|
367
|
-
return {
|
|
368
|
-
runId: res.runId,
|
|
369
|
-
status: "failed",
|
|
370
|
-
result: Promise.resolve(res),
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
const runId = res.runId || res.data?.runId;
|
|
374
|
-
const status = res.status || res.data?.status || "running";
|
|
375
|
-
return {
|
|
376
|
-
runId,
|
|
377
|
-
status,
|
|
378
|
-
result: this.waitForRunCompletion(runId, options?.signal, options?.timeoutMs),
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* 等待远端运行抵达终态:优先监听 SSE 事件流,失败后按指数退避轮询运行详情。
|
|
383
|
-
*
|
|
384
|
-
* @param runId 运行标识
|
|
385
|
-
* @param signal 外部取消信号
|
|
386
|
-
* @param timeoutMs 运行自身声明的超时(等待上限取该值与默认上限中的较大者)
|
|
387
|
-
*/
|
|
388
|
-
async waitForRunCompletion(runId, signal, timeoutMs) {
|
|
389
|
-
const startTime = Date.now();
|
|
390
|
-
const maxWaitMs = Math.max(this.baseTimeoutMs, timeoutMs ?? 0);
|
|
391
|
-
if (signal?.aborted) {
|
|
392
|
-
return {
|
|
393
|
-
ok: false,
|
|
394
|
-
runId,
|
|
395
|
-
error: {
|
|
396
|
-
code: ACTION_CANCELLED,
|
|
397
|
-
message: "Action execution was cancelled",
|
|
398
|
-
},
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
if (this.isClosed) {
|
|
402
|
-
return {
|
|
403
|
-
ok: false,
|
|
404
|
-
runId,
|
|
405
|
-
error: {
|
|
406
|
-
code: TARGET_CLOSED,
|
|
407
|
-
message: "RemoteActionDockTarget is closed",
|
|
408
|
-
},
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
const internalController = new AbortController();
|
|
412
|
-
let sseTimedOut = false;
|
|
413
|
-
let timer;
|
|
414
|
-
if (maxWaitMs > 0 && maxWaitMs !== Infinity) {
|
|
415
|
-
timer = setTimeout(() => {
|
|
416
|
-
sseTimedOut = true;
|
|
417
|
-
internalController.abort();
|
|
418
|
-
}, maxWaitMs);
|
|
419
|
-
}
|
|
420
|
-
const onAbort = () => {
|
|
421
|
-
internalController.abort();
|
|
422
|
-
};
|
|
423
|
-
if (signal) {
|
|
424
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
425
|
-
}
|
|
426
|
-
// 优先尝试监听 SSE 事件流终态事件
|
|
427
|
-
try {
|
|
428
|
-
for await (const evt of this.events(runId, { signal: internalController.signal })) {
|
|
429
|
-
if (evt.type === "finish") {
|
|
430
|
-
const res = evt.result || evt.data || evt;
|
|
431
|
-
if (typeof res?.ok === "boolean") {
|
|
432
|
-
return res;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
catch (err) {
|
|
438
|
-
if (err?.code === TARGET_CLOSED || this.isClosed) {
|
|
439
|
-
return {
|
|
440
|
-
ok: false,
|
|
441
|
-
runId,
|
|
442
|
-
error: {
|
|
443
|
-
code: TARGET_CLOSED,
|
|
444
|
-
message: "RemoteActionDockTarget is closed",
|
|
445
|
-
},
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
if (!signal?.aborted && !sseTimedOut) {
|
|
449
|
-
// SSE 通道异常视为不可用:记录后按指数退避进入轮询兜底
|
|
450
|
-
console.warn(`[ActionDock] SSE event stream unavailable for run '${runId}', falling back to polling: ${err?.message || String(err)}`);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
finally {
|
|
454
|
-
if (timer) {
|
|
455
|
-
clearTimeout(timer);
|
|
456
|
-
}
|
|
457
|
-
if (signal) {
|
|
458
|
-
signal.removeEventListener("abort", onAbort);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
if (signal?.aborted) {
|
|
462
|
-
return {
|
|
463
|
-
ok: false,
|
|
464
|
-
runId,
|
|
465
|
-
error: {
|
|
466
|
-
code: ACTION_CANCELLED,
|
|
467
|
-
message: "Action execution was cancelled",
|
|
468
|
-
},
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
const remainingWaitMs = Math.max(0, maxWaitMs - (Date.now() - startTime));
|
|
472
|
-
if (remainingWaitMs <= 0) {
|
|
473
|
-
if (this.isClosed) {
|
|
474
|
-
return {
|
|
475
|
-
ok: false,
|
|
476
|
-
runId,
|
|
477
|
-
error: {
|
|
478
|
-
code: TARGET_CLOSED,
|
|
479
|
-
message: "RemoteActionDockTarget is closed",
|
|
480
|
-
},
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
try {
|
|
484
|
-
const run = await this.getRun(runId);
|
|
485
|
-
if (run && isTerminalRunStatus(run.status)) {
|
|
486
|
-
return this.formatTerminalRunResult(run, runId);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
catch (err) {
|
|
490
|
-
if (err?.code === TARGET_CLOSED || this.isClosed) {
|
|
491
|
-
return {
|
|
492
|
-
ok: false,
|
|
493
|
-
runId,
|
|
494
|
-
error: {
|
|
495
|
-
code: TARGET_CLOSED,
|
|
496
|
-
message: "RemoteActionDockTarget is closed",
|
|
497
|
-
},
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
throw err;
|
|
501
|
-
}
|
|
502
|
-
const waitedMs = Date.now() - startTime;
|
|
503
|
-
return {
|
|
504
|
-
ok: false,
|
|
505
|
-
runId,
|
|
506
|
-
error: {
|
|
507
|
-
code: TIMEOUT,
|
|
508
|
-
message: `Timed out waiting for run '${runId}' completion after ${waitedMs}ms`,
|
|
509
|
-
},
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
// 剩余时间继续通过 pollRunCompletion 进行轮询兜底
|
|
513
|
-
return this.pollRunCompletion(runId, signal, remainingWaitMs, startTime, maxWaitMs);
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* 指数退避轮询远端运行详情直至终态、取消或超时上限。
|
|
517
|
-
*/
|
|
518
|
-
async pollRunCompletion(runId, signal, timeoutMs, startTime = Date.now(), totalMaxWaitMs) {
|
|
519
|
-
return pollRunCompletion({
|
|
520
|
-
baseTimeoutMs: this.baseTimeoutMs,
|
|
521
|
-
isClosed: () => this.isClosed,
|
|
522
|
-
getRun: (id) => this.getRun(id),
|
|
523
|
-
}, runId, signal, timeoutMs, startTime, totalMaxWaitMs);
|
|
524
|
-
}
|
|
525
|
-
formatTerminalRunResult(run, runId) {
|
|
526
|
-
return formatTerminalRunResult(run, runId);
|
|
527
|
-
}
|
|
528
|
-
async listRuns(options) {
|
|
529
|
-
this.assertNotClosed();
|
|
530
|
-
try {
|
|
531
|
-
const res = await fetchRemoteRuns(this.serverUrl, this.token, {
|
|
532
|
-
packageId: options?.packageId,
|
|
533
|
-
actionId: options?.actionId,
|
|
534
|
-
status: options?.status,
|
|
535
|
-
intent: options?.intent,
|
|
536
|
-
limit: options?.limit,
|
|
537
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
538
|
-
insecure: this.insecure,
|
|
539
|
-
dispatcher: this.dispatcher,
|
|
540
|
-
});
|
|
541
|
-
return res.items || [];
|
|
542
|
-
}
|
|
543
|
-
catch (err) {
|
|
544
|
-
wrapRemoteError(err);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
async clearRuns(options) {
|
|
548
|
-
this.assertNotClosed();
|
|
549
|
-
try {
|
|
550
|
-
const res = await clearRemoteRuns(this.serverUrl, this.token, {
|
|
551
|
-
...options,
|
|
552
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
553
|
-
insecure: this.insecure,
|
|
554
|
-
dispatcher: this.dispatcher,
|
|
555
|
-
});
|
|
556
|
-
return res.clearedCount ?? 0;
|
|
557
|
-
}
|
|
558
|
-
catch (err) {
|
|
559
|
-
wrapRemoteError(err);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
async getRun(runId) {
|
|
563
|
-
this.assertNotClosed();
|
|
564
|
-
try {
|
|
565
|
-
return await fetchRemoteRun(this.serverUrl, runId, this.token, {
|
|
566
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
567
|
-
insecure: this.insecure,
|
|
568
|
-
dispatcher: this.dispatcher,
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
catch (err) {
|
|
572
|
-
const msg = String(err?.message || "");
|
|
573
|
-
if (msg.includes("404") || msg.includes("not found") || msg.includes("RUN_NOT_FOUND")) {
|
|
574
|
-
return undefined;
|
|
575
|
-
}
|
|
576
|
-
throw err;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
async cancelRun(runId, reason) {
|
|
580
|
-
this.assertNotClosed();
|
|
581
|
-
try {
|
|
582
|
-
const res = await cancelRemoteRun(this.serverUrl, runId, this.token, reason, {
|
|
583
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
584
|
-
insecure: this.insecure,
|
|
585
|
-
dispatcher: this.dispatcher,
|
|
586
|
-
});
|
|
587
|
-
return { outcome: "requested", runId: res.runId };
|
|
588
|
-
}
|
|
589
|
-
catch (err) {
|
|
590
|
-
const msg = String(err?.message || "");
|
|
591
|
-
const code = String(err?.code || "");
|
|
592
|
-
if (code === "RUN_ALREADY_FINISHED" ||
|
|
593
|
-
msg.includes("already finished") ||
|
|
594
|
-
msg.includes("RUN_ALREADY_FINISHED")) {
|
|
595
|
-
let status = err?.errorData?.status || err?.details?.status;
|
|
596
|
-
if (!status) {
|
|
597
|
-
try {
|
|
598
|
-
const run = await this.getRun(runId);
|
|
599
|
-
if (run?.status) {
|
|
600
|
-
status = run.status;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
catch { }
|
|
604
|
-
}
|
|
605
|
-
return { outcome: "already_terminal", runId, status: status || "failed" };
|
|
606
|
-
}
|
|
607
|
-
if (code === "RUN_NOT_FOUND" ||
|
|
608
|
-
msg.includes("not found") ||
|
|
609
|
-
msg.includes("RUN_NOT_FOUND") ||
|
|
610
|
-
msg.includes("404")) {
|
|
611
|
-
return { outcome: "not_found", runId };
|
|
612
|
-
}
|
|
613
|
-
throw err;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
events(runId, options) {
|
|
617
|
-
this.assertNotClosed();
|
|
618
|
-
const self = this;
|
|
619
|
-
async function* stream() {
|
|
620
|
-
self.assertNotClosed();
|
|
621
|
-
for await (const event of streamRemoteEvents(self.serverUrl, runId, self.token, {
|
|
622
|
-
...options,
|
|
623
|
-
allowInsecureHttp: self.allowInsecureHttp,
|
|
624
|
-
insecure: self.insecure,
|
|
625
|
-
dispatcher: self.dispatcher,
|
|
626
|
-
})) {
|
|
627
|
-
self.assertNotClosed();
|
|
628
|
-
yield event;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
return stream();
|
|
632
|
-
}
|
|
633
|
-
async getConfig(packageId, key) {
|
|
634
|
-
this.assertNotClosed();
|
|
635
|
-
try {
|
|
636
|
-
const list = await this.listConfig(packageId);
|
|
637
|
-
const found = list.find((c) => c.key === key);
|
|
638
|
-
if (found) {
|
|
639
|
-
return found;
|
|
640
|
-
}
|
|
641
|
-
return {
|
|
642
|
-
key,
|
|
643
|
-
configured: false,
|
|
644
|
-
secret: false,
|
|
645
|
-
source: "default",
|
|
646
|
-
value: undefined,
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
catch (err) {
|
|
650
|
-
wrapRemoteError(err);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
async setConfig(packageId, key, value) {
|
|
654
|
-
this.assertNotClosed();
|
|
655
|
-
try {
|
|
656
|
-
await setRemoteConfig(this.serverUrl, key, value, this.token, packageId || undefined, {
|
|
657
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
658
|
-
insecure: this.insecure,
|
|
659
|
-
dispatcher: this.dispatcher,
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
catch (err) {
|
|
663
|
-
wrapRemoteError(err);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
async deleteConfig(packageId, key) {
|
|
667
|
-
this.assertNotClosed();
|
|
668
|
-
try {
|
|
669
|
-
const res = await deleteRemoteConfig(this.serverUrl, key, this.token, packageId || undefined, {
|
|
670
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
671
|
-
insecure: this.insecure,
|
|
672
|
-
dispatcher: this.dispatcher,
|
|
673
|
-
});
|
|
674
|
-
return Boolean(res?.deleted ?? true);
|
|
675
|
-
}
|
|
676
|
-
catch (err) {
|
|
677
|
-
wrapRemoteError(err);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
async listConfig(packageId) {
|
|
681
|
-
this.assertNotClosed();
|
|
682
|
-
try {
|
|
683
|
-
const res = await fetchRemoteConfig(this.serverUrl, this.token, packageId || undefined, {
|
|
684
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
685
|
-
insecure: this.insecure,
|
|
686
|
-
dispatcher: this.dispatcher,
|
|
687
|
-
});
|
|
688
|
-
if (Array.isArray(res))
|
|
689
|
-
return res;
|
|
690
|
-
if (Array.isArray(res?.items))
|
|
691
|
-
return res.items;
|
|
692
|
-
if (Array.isArray(res?.config))
|
|
693
|
-
return res.config;
|
|
694
|
-
const values = res?.values || {};
|
|
695
|
-
const declared = res?.declared || {};
|
|
696
|
-
const defaultSource = packageId === "global" ? "global" : "package";
|
|
697
|
-
return Object.entries(values).map(([k, v]) => ({
|
|
698
|
-
key: k,
|
|
699
|
-
configured: v !== undefined,
|
|
700
|
-
secret: Boolean(declared[k]?.secret),
|
|
701
|
-
source: defaultSource,
|
|
702
|
-
value: v,
|
|
703
|
-
}));
|
|
704
|
-
}
|
|
705
|
-
catch (err) {
|
|
706
|
-
wrapRemoteError(err);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
async getState(packageId, actionId, key, options) {
|
|
710
|
-
this.assertNotClosed();
|
|
711
|
-
try {
|
|
712
|
-
const res = await getRemoteStateKey(this.serverUrl, key, this.token, {
|
|
713
|
-
package: packageId || undefined,
|
|
714
|
-
action: actionId || undefined,
|
|
715
|
-
namespace: options?.namespace,
|
|
716
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
717
|
-
insecure: this.insecure,
|
|
718
|
-
dispatcher: this.dispatcher,
|
|
719
|
-
});
|
|
720
|
-
if (res === undefined)
|
|
721
|
-
return undefined;
|
|
722
|
-
if (options?.detail) {
|
|
723
|
-
return res;
|
|
724
|
-
}
|
|
725
|
-
return (res?.value !== undefined ? res.value : res);
|
|
726
|
-
}
|
|
727
|
-
catch (err) {
|
|
728
|
-
if (isRemoteStateKeyNotFound(err)) {
|
|
729
|
-
return undefined;
|
|
730
|
-
}
|
|
731
|
-
wrapRemoteError(err);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
async setState(packageId, actionId, key, value, options) {
|
|
735
|
-
this.assertNotClosed();
|
|
736
|
-
try {
|
|
737
|
-
await setRemoteStateKey(this.serverUrl, key, value, this.token, {
|
|
738
|
-
package: packageId || undefined,
|
|
739
|
-
action: actionId || undefined,
|
|
740
|
-
namespace: options?.namespace,
|
|
741
|
-
ttl: options?.ttl,
|
|
742
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
743
|
-
insecure: this.insecure,
|
|
744
|
-
dispatcher: this.dispatcher,
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
catch (err) {
|
|
748
|
-
wrapRemoteError(err);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
async deleteState(packageId, actionId, key, options) {
|
|
752
|
-
this.assertNotClosed();
|
|
753
|
-
try {
|
|
754
|
-
const res = await deleteRemoteStateKey(this.serverUrl, key, this.token, {
|
|
755
|
-
package: packageId || undefined,
|
|
756
|
-
action: actionId || undefined,
|
|
757
|
-
namespace: options?.namespace,
|
|
758
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
759
|
-
insecure: this.insecure,
|
|
760
|
-
dispatcher: this.dispatcher,
|
|
761
|
-
});
|
|
762
|
-
return Boolean(res?.deleted ?? true);
|
|
763
|
-
}
|
|
764
|
-
catch (err) {
|
|
765
|
-
if (isRemoteStateKeyNotFound(err)) {
|
|
766
|
-
return false;
|
|
767
|
-
}
|
|
768
|
-
wrapRemoteError(err);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
async listStateKeys(packageId, actionId, options) {
|
|
772
|
-
this.assertNotClosed();
|
|
773
|
-
try {
|
|
774
|
-
const res = await fetchRemoteStateList(this.serverUrl, this.token, {
|
|
775
|
-
package: packageId || undefined,
|
|
776
|
-
action: actionId || undefined,
|
|
777
|
-
namespace: options?.namespace,
|
|
778
|
-
prefix: options?.prefix,
|
|
779
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
780
|
-
insecure: this.insecure,
|
|
781
|
-
dispatcher: this.dispatcher,
|
|
782
|
-
});
|
|
783
|
-
return res.keys || [];
|
|
784
|
-
}
|
|
785
|
-
catch (err) {
|
|
786
|
-
wrapRemoteError(err);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
async clearState(packageId, actionId, options) {
|
|
790
|
-
this.assertNotClosed();
|
|
791
|
-
try {
|
|
792
|
-
const res = await clearRemoteState(this.serverUrl, this.token, {
|
|
793
|
-
package: packageId || undefined,
|
|
794
|
-
action: actionId || undefined,
|
|
795
|
-
namespace: options?.namespace,
|
|
796
|
-
prefix: options?.prefix,
|
|
797
|
-
all: options?.all,
|
|
798
|
-
allowInsecureHttp: this.allowInsecureHttp,
|
|
799
|
-
insecure: this.insecure,
|
|
800
|
-
dispatcher: this.dispatcher,
|
|
801
|
-
});
|
|
802
|
-
return res.clearedCount ?? 0;
|
|
803
|
-
}
|
|
804
|
-
catch (err) {
|
|
805
|
-
wrapRemoteError(err);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
async listStateEntries(packageId, options) {
|
|
809
|
-
this.assertNotClosed();
|
|
810
|
-
throw new TargetError(TARGET_CAPABILITY_UNAVAILABLE, "TARGET_CAPABILITY_UNAVAILABLE: listStateEntries is not supported on remote target");
|
|
811
|
-
}
|
|
812
|
-
async close(_options) {
|
|
813
|
-
if (this.isClosed) {
|
|
814
|
-
return;
|
|
815
|
-
}
|
|
816
|
-
this.isClosed = true;
|
|
817
|
-
}
|
|
818
|
-
}
|