@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/ipc/target.js
DELETED
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { fork } from "node:child_process";
|
|
3
|
-
import { DiagnosticForwarder } from "./diagnostic.js";
|
|
4
|
-
import { EXECUTION_ABORTED, HOST_PROCESS_EXITED } from "../errors.js";
|
|
5
|
-
/**
|
|
6
|
-
* 跨进程取消信号占位标记字段名。
|
|
7
|
-
* AbortSignal 不可序列化,序列化 options 时把 signal 字段替换为该标记,
|
|
8
|
-
* 宿主侧识别后重建 AbortController 并接入 abort 消息通知链路。
|
|
9
|
-
*/
|
|
10
|
-
export const IPC_SIGNAL_MARKER = "__ipcSignal";
|
|
11
|
-
/**
|
|
12
|
-
* 判断执行选项中是否携带跨进程取消信号占位标记。
|
|
13
|
-
*
|
|
14
|
-
* @param value 待检查的选项值
|
|
15
|
-
*/
|
|
16
|
-
export function hasIpcSignalMarker(value) {
|
|
17
|
-
return (typeof value === "object" &&
|
|
18
|
-
value !== null &&
|
|
19
|
-
value[IPC_SIGNAL_MARKER] === true);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* 序列化执行选项:剥离不可序列化的 AbortSignal 并写入占位标记。
|
|
23
|
-
* 未携带 signal 时返回浅拷贝,避免消息通道直接持有调用方原始对象。
|
|
24
|
-
*
|
|
25
|
-
* @param options 原始执行选项
|
|
26
|
-
*/
|
|
27
|
-
function markIpcSignal(options) {
|
|
28
|
-
if (!options)
|
|
29
|
-
return undefined;
|
|
30
|
-
const { signal: _signal, ...rest } = options;
|
|
31
|
-
if (!_signal)
|
|
32
|
-
return rest;
|
|
33
|
-
return { ...rest, [IPC_SIGNAL_MARKER]: true };
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* 基于 Node IPC 监督进程通信通道的 ActionDockTarget 实现。
|
|
37
|
-
*
|
|
38
|
-
* 职责:
|
|
39
|
-
* 1. 监督并隔离子进程的生命周期与标准输出,保证父进程标准输入输出通道 100% 纯净。
|
|
40
|
-
* 2. 将子进程标准输出/错误通过 DiagnosticForwarder 进行受控排空与诊断流限流转发。
|
|
41
|
-
* 3. 当子进程异常终止时,立即将当前活跃调用转换为结构化 HOST_PROCESS_EXITED 错误,防止调用方死锁。
|
|
42
|
-
*/
|
|
43
|
-
export class IpcActionDockTarget {
|
|
44
|
-
child;
|
|
45
|
-
forwarder;
|
|
46
|
-
pendingCalls = new Map();
|
|
47
|
-
isClosed = false;
|
|
48
|
-
exitError;
|
|
49
|
-
readyPromise;
|
|
50
|
-
constructor(options) {
|
|
51
|
-
this.forwarder = new DiagnosticForwarder({
|
|
52
|
-
maxBytes: options.maxDiagnosticBytes,
|
|
53
|
-
maxRateBytesPerSec: options.maxDiagnosticRate,
|
|
54
|
-
target: options.diagnosticTarget,
|
|
55
|
-
});
|
|
56
|
-
if (options.childProcess) {
|
|
57
|
-
this.child = options.childProcess;
|
|
58
|
-
}
|
|
59
|
-
else if (options.scriptPath) {
|
|
60
|
-
this.child = fork(options.scriptPath, options.scriptArgs || [], {
|
|
61
|
-
cwd: options.cwd || process.cwd(),
|
|
62
|
-
env: options.env || process.env,
|
|
63
|
-
stdio: ["pipe", "pipe", "pipe", "ipc"],
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
throw new Error("IpcActionDockTarget requires either 'childProcess' or 'scriptPath'");
|
|
68
|
-
}
|
|
69
|
-
// 绑定子进程输出至受控限流排空器,绝不泄露至 process.stdout
|
|
70
|
-
if (this.child.stdout) {
|
|
71
|
-
this.forwarder.attach(this.child.stdout, "stdout");
|
|
72
|
-
}
|
|
73
|
-
if (this.child.stderr) {
|
|
74
|
-
this.forwarder.attach(this.child.stderr, "stderr");
|
|
75
|
-
}
|
|
76
|
-
let resolveReady;
|
|
77
|
-
this.readyPromise = new Promise((r) => {
|
|
78
|
-
resolveReady = r;
|
|
79
|
-
});
|
|
80
|
-
this.child.on("message", (msg) => {
|
|
81
|
-
if (!msg || typeof msg !== "object")
|
|
82
|
-
return;
|
|
83
|
-
if (msg.type === "ready") {
|
|
84
|
-
resolveReady();
|
|
85
|
-
}
|
|
86
|
-
else if (msg.type === "response") {
|
|
87
|
-
const resp = msg;
|
|
88
|
-
const pending = this.pendingCalls.get(resp.id);
|
|
89
|
-
if (pending) {
|
|
90
|
-
this.pendingCalls.delete(resp.id);
|
|
91
|
-
if (resp.ok) {
|
|
92
|
-
pending.resolve(resp.data);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
const err = new Error(resp.error?.message || "IPC Target call failed");
|
|
96
|
-
if (resp.error?.code)
|
|
97
|
-
err.code = resp.error.code;
|
|
98
|
-
if (resp.error?.details)
|
|
99
|
-
err.details = resp.error.details;
|
|
100
|
-
pending.reject(err);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
this.child.on("exit", (code, signal) => {
|
|
106
|
-
const exitMsg = `Host process exited prematurely with code ${code ?? signal ?? "unknown"}`;
|
|
107
|
-
const err = new Error(exitMsg);
|
|
108
|
-
err.code = "HOST_PROCESS_EXITED";
|
|
109
|
-
this.exitError = err;
|
|
110
|
-
this.isClosed = true;
|
|
111
|
-
// 快速失败所有待处理调用
|
|
112
|
-
for (const pending of this.pendingCalls.values()) {
|
|
113
|
-
if (pending.method === "runAction") {
|
|
114
|
-
pending.resolve({
|
|
115
|
-
ok: false,
|
|
116
|
-
runId: randomUUID(),
|
|
117
|
-
error: {
|
|
118
|
-
code: HOST_PROCESS_EXITED,
|
|
119
|
-
message: exitMsg,
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
pending.reject(err);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
this.pendingCalls.clear();
|
|
128
|
-
resolveReady(); // 避免就绪死锁
|
|
129
|
-
});
|
|
130
|
-
this.child.on("error", (err) => {
|
|
131
|
-
this.exitError = err;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* 等待宿主子进程初始化就绪。
|
|
136
|
-
*/
|
|
137
|
-
async waitReady(timeoutMs = 5000) {
|
|
138
|
-
if (this.exitError)
|
|
139
|
-
throw this.exitError;
|
|
140
|
-
let timer;
|
|
141
|
-
const timeout = new Promise((_, reject) => {
|
|
142
|
-
timer = setTimeout(() => reject(new Error(`Timeout waiting for host process ready after ${timeoutMs}ms`)), timeoutMs);
|
|
143
|
-
});
|
|
144
|
-
try {
|
|
145
|
-
await Promise.race([this.readyPromise, timeout]);
|
|
146
|
-
}
|
|
147
|
-
finally {
|
|
148
|
-
if (timer !== undefined) {
|
|
149
|
-
clearTimeout(timer);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* 获取底层子进程实例。
|
|
155
|
-
*/
|
|
156
|
-
get process() {
|
|
157
|
-
return this.child;
|
|
158
|
-
}
|
|
159
|
-
async callRemote(method, args, signal) {
|
|
160
|
-
if (this.isClosed || this.exitError) {
|
|
161
|
-
if (method === "runAction") {
|
|
162
|
-
return {
|
|
163
|
-
ok: false,
|
|
164
|
-
runId: randomUUID(),
|
|
165
|
-
error: {
|
|
166
|
-
code: HOST_PROCESS_EXITED,
|
|
167
|
-
message: this.exitError?.message || "Host process is already closed",
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
throw this.exitError || new Error("Host process is already closed");
|
|
172
|
-
}
|
|
173
|
-
const id = randomUUID();
|
|
174
|
-
const msg = {
|
|
175
|
-
id,
|
|
176
|
-
type: "call",
|
|
177
|
-
method,
|
|
178
|
-
args,
|
|
179
|
-
};
|
|
180
|
-
// 事件驱动跨进程取消:signal 存在且未中止时注册 abort 监听,
|
|
181
|
-
// 触发即向宿主子进程发送 abort 消息,由宿主侧中止同调用控制器;
|
|
182
|
-
// 调用结束(无论成败)后注销监听,避免监听器泄漏
|
|
183
|
-
let onAbort;
|
|
184
|
-
if (signal && !signal.aborted) {
|
|
185
|
-
onAbort = () => {
|
|
186
|
-
this.sendAbort(id);
|
|
187
|
-
};
|
|
188
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
189
|
-
}
|
|
190
|
-
return new Promise((resolve, reject) => {
|
|
191
|
-
this.pendingCalls.set(id, { resolve, reject, method });
|
|
192
|
-
try {
|
|
193
|
-
if (this.child.send) {
|
|
194
|
-
this.child.send(msg);
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
this.pendingCalls.delete(id);
|
|
198
|
-
reject(new Error("IPC channel unavailable on child process"));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
catch (err) {
|
|
202
|
-
this.pendingCalls.delete(id);
|
|
203
|
-
reject(err);
|
|
204
|
-
}
|
|
205
|
-
}).finally(() => {
|
|
206
|
-
if (onAbort && signal) {
|
|
207
|
-
signal.removeEventListener("abort", onAbort);
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* 向宿主子进程发送跨进程取消通知,发送异常不阻断父侧调用链路。
|
|
213
|
-
*
|
|
214
|
-
* @param id 目标调用的唯一标识
|
|
215
|
-
*/
|
|
216
|
-
sendAbort(id) {
|
|
217
|
-
if (this.isClosed)
|
|
218
|
-
return;
|
|
219
|
-
try {
|
|
220
|
-
const abortMsg = { id, type: "abort" };
|
|
221
|
-
if (this.child.send) {
|
|
222
|
-
this.child.send(abortMsg);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
catch (err) {
|
|
226
|
-
// 通道已断开时发送失败属预期场景:宿主退出路径会另行以结构化错误回包
|
|
227
|
-
process.stderr.write(`[IPC Target] Failed to send abort for call '${id}': ${err instanceof Error ? err.message : String(err)}\n`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
async info() {
|
|
231
|
-
return this.callRemote("info", []);
|
|
232
|
-
}
|
|
233
|
-
async listPackages() {
|
|
234
|
-
return this.callRemote("listPackages", []);
|
|
235
|
-
}
|
|
236
|
-
async listActions(options) {
|
|
237
|
-
return this.callRemote("listActions", [options]);
|
|
238
|
-
}
|
|
239
|
-
async describeAction(ref) {
|
|
240
|
-
return this.callRemote("describeAction", [ref]);
|
|
241
|
-
}
|
|
242
|
-
async listPlaybooks(options) {
|
|
243
|
-
return this.callRemote("listPlaybooks", [options]);
|
|
244
|
-
}
|
|
245
|
-
async describePlaybook(id) {
|
|
246
|
-
return this.callRemote("describePlaybook", [id]);
|
|
247
|
-
}
|
|
248
|
-
async runAction(ref, input, options) {
|
|
249
|
-
if (options?.signal?.aborted) {
|
|
250
|
-
return {
|
|
251
|
-
ok: false,
|
|
252
|
-
runId: randomUUID(),
|
|
253
|
-
error: {
|
|
254
|
-
code: EXECUTION_ABORTED,
|
|
255
|
-
message: "Execution was aborted before starting",
|
|
256
|
-
},
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
// AbortSignal 不可序列化:以占位标记替换后随消息通道传递,宿主侧重建控制器
|
|
260
|
-
const serializableOptions = markIpcSignal(options);
|
|
261
|
-
return this.callRemote("runAction", [ref, input, serializableOptions], options?.signal);
|
|
262
|
-
}
|
|
263
|
-
async startAction(ref, input, options) {
|
|
264
|
-
if (options?.signal?.aborted) {
|
|
265
|
-
throw new Error("Execution was aborted before starting");
|
|
266
|
-
}
|
|
267
|
-
// AbortSignal 不可序列化:以占位标记替换后随消息通道传递,宿主侧重建控制器
|
|
268
|
-
const serializableOptions = markIpcSignal(options);
|
|
269
|
-
return this.callRemote("startAction", [ref, input, serializableOptions], options?.signal);
|
|
270
|
-
}
|
|
271
|
-
async getRun(runId) {
|
|
272
|
-
const res = await this.callRemote("getRun", [runId]);
|
|
273
|
-
return res ?? undefined;
|
|
274
|
-
}
|
|
275
|
-
async cancelRun(runId) {
|
|
276
|
-
return this.callRemote("cancelRun", [runId]);
|
|
277
|
-
}
|
|
278
|
-
async listRuns(options) {
|
|
279
|
-
return this.callRemote("listRuns", [options]);
|
|
280
|
-
}
|
|
281
|
-
async *events(_runId, _options) {
|
|
282
|
-
// 基础 IPC 通道暂不流式下发历史事件
|
|
283
|
-
}
|
|
284
|
-
async listConfig(packageId) {
|
|
285
|
-
return this.callRemote("listConfig", [packageId]);
|
|
286
|
-
}
|
|
287
|
-
async getConfig(packageId, key) {
|
|
288
|
-
return this.callRemote("getConfig", [packageId, key]);
|
|
289
|
-
}
|
|
290
|
-
async setConfig(packageId, key, value) {
|
|
291
|
-
return this.callRemote("setConfig", [packageId, key, value]);
|
|
292
|
-
}
|
|
293
|
-
async deleteConfig(packageId, key) {
|
|
294
|
-
return this.callRemote("deleteConfig", [packageId, key]);
|
|
295
|
-
}
|
|
296
|
-
async getState(packageId, actionId, key, options) {
|
|
297
|
-
return this.callRemote("getState", [
|
|
298
|
-
packageId,
|
|
299
|
-
actionId,
|
|
300
|
-
key,
|
|
301
|
-
options,
|
|
302
|
-
]);
|
|
303
|
-
}
|
|
304
|
-
async setState(packageId, actionId, key, value, options) {
|
|
305
|
-
return this.callRemote("setState", [packageId, actionId, key, value, options]);
|
|
306
|
-
}
|
|
307
|
-
async deleteState(packageId, actionId, key, options) {
|
|
308
|
-
return this.callRemote("deleteState", [packageId, actionId, key, options]);
|
|
309
|
-
}
|
|
310
|
-
async listStateKeys(packageId, actionId, options) {
|
|
311
|
-
return this.callRemote("listStateKeys", [packageId, actionId, options]);
|
|
312
|
-
}
|
|
313
|
-
async clearState(packageId, actionId, options) {
|
|
314
|
-
return this.callRemote("clearState", [packageId, actionId, options]);
|
|
315
|
-
}
|
|
316
|
-
async close() {
|
|
317
|
-
if (this.isClosed)
|
|
318
|
-
return;
|
|
319
|
-
if (this.child.exitCode !== null) {
|
|
320
|
-
this.forwarder.detachAll();
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
const exitPromise = new Promise((resolve) => {
|
|
324
|
-
if (this.child.exitCode !== null) {
|
|
325
|
-
resolve();
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
this.child.once("exit", () => resolve());
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
try {
|
|
332
|
-
if (this.child.connected) {
|
|
333
|
-
this.child.send({ type: "close" });
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
catch {
|
|
337
|
-
// 忽略发送关闭消息异常
|
|
338
|
-
}
|
|
339
|
-
// 若子进程超时未退出,先 SIGTERM 再 SIGKILL
|
|
340
|
-
const termTimer = setTimeout(() => {
|
|
341
|
-
if (this.child.exitCode === null) {
|
|
342
|
-
try {
|
|
343
|
-
this.child.kill("SIGTERM");
|
|
344
|
-
}
|
|
345
|
-
catch { }
|
|
346
|
-
}
|
|
347
|
-
}, 1500);
|
|
348
|
-
const killTimer = setTimeout(() => {
|
|
349
|
-
if (this.child.exitCode === null) {
|
|
350
|
-
try {
|
|
351
|
-
this.child.kill("SIGKILL");
|
|
352
|
-
}
|
|
353
|
-
catch { }
|
|
354
|
-
}
|
|
355
|
-
}, 3000);
|
|
356
|
-
try {
|
|
357
|
-
await exitPromise;
|
|
358
|
-
}
|
|
359
|
-
finally {
|
|
360
|
-
clearTimeout(termTimer);
|
|
361
|
-
clearTimeout(killTimer);
|
|
362
|
-
this.forwarder.detachAll();
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ProcessAPI } from "@actiondock/sdk";
|
|
2
|
-
import { type Clock } from "../runtime/clock.js";
|
|
3
|
-
import { type ModuleLoader } from "../runtime/module-loader.js";
|
|
4
|
-
import { ProcessManager } from "../process/process-manager.js";
|
|
5
|
-
import type { ProcessDriver } from "../process/driver.js";
|
|
6
|
-
import type { FileSystem, RuntimePlatform, StorageFactory } from "./types.js";
|
|
7
|
-
/**
|
|
8
|
-
* 默认运行时平台构建选项。
|
|
9
|
-
*/
|
|
10
|
-
export interface DefaultPlatformOptions {
|
|
11
|
-
/** 平台名称覆盖(默认使用 node) */
|
|
12
|
-
name?: "node" | "test";
|
|
13
|
-
/** 自定义文件系统实现(默认使用 NodeFileSystem) */
|
|
14
|
-
files?: FileSystem;
|
|
15
|
-
/** 自定义时间与时钟驱动(默认使用 SystemClock) */
|
|
16
|
-
clock?: Clock;
|
|
17
|
-
/** 自定义进程执行驱动(默认依托 ProcessManager 与对应驱动) */
|
|
18
|
-
process?: ProcessAPI;
|
|
19
|
-
/** 可选注入的底层进程驱动 */
|
|
20
|
-
processDriver?: ProcessDriver;
|
|
21
|
-
/** 可选注入的受管进程管理器 */
|
|
22
|
-
processManager?: ProcessManager;
|
|
23
|
-
/** 自定义源码加载驱动(默认使用 DefaultModuleLoader) */
|
|
24
|
-
modules?: ModuleLoader;
|
|
25
|
-
/** 自定义存储工厂(默认基于 core/storage 构造) */
|
|
26
|
-
storage?: StorageFactory;
|
|
27
|
-
/** 自定义 ActionDock 家目录 */
|
|
28
|
-
customHome?: string;
|
|
29
|
-
/** 自定义全局数据存储目录 */
|
|
30
|
-
dataDir?: string;
|
|
31
|
-
/** 文件系统沙箱根目录 */
|
|
32
|
-
rootDir?: string;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* 创建默认 RuntimePlatform 平台实例。
|
|
36
|
-
* 直接基于 Node 原生与 Core 内核能力组装平台,禁止任何全局单例状态。
|
|
37
|
-
*/
|
|
38
|
-
export declare function createDefaultPlatform(options?: DefaultPlatformOptions): RuntimePlatform;
|
package/dist/platform/default.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { SystemClock } from "../runtime/clock.js";
|
|
2
|
-
import { DefaultModuleLoader } from "../runtime/module-loader.js";
|
|
3
|
-
import { ProcessError, UNSUPPORTED_CAPABILITY } from "../errors.js";
|
|
4
|
-
import { ProcessManager } from "../process/process-manager.js";
|
|
5
|
-
import { createGlobalStorage as coreCreateGlobalStorage, createStorage as coreCreateStorage, } from "../storage/index.js";
|
|
6
|
-
import { NodeFileSystem } from "./node-fs.js";
|
|
7
|
-
/**
|
|
8
|
-
* 构造不支持进程能力的 ProcessAPI:
|
|
9
|
-
* 默认平台不含进程驱动,任何进程操作均抛出明确错误,
|
|
10
|
-
* 指引调用方显式注入 processDriver 或改用 @actiondock/runtime-node 的 createNodePlatform。
|
|
11
|
-
*/
|
|
12
|
-
function createUnsupportedProcessApi() {
|
|
13
|
-
const unsupported = (operation) => Promise.reject(new ProcessError(UNSUPPORTED_CAPABILITY, `The default platform does not bundle a process driver, so process.${operation} is unavailable. ` +
|
|
14
|
-
"Explicitly inject a processDriver (for example MemoryProcessDriver from @actiondock/core for testing) " +
|
|
15
|
-
"or use createNodePlatform from @actiondock/runtime-node, which provides NodeProcessDriver."));
|
|
16
|
-
return {
|
|
17
|
-
run: () => unsupported("run"),
|
|
18
|
-
start: () => unsupported("start"),
|
|
19
|
-
inspect: () => unsupported("inspect"),
|
|
20
|
-
list: () => unsupported("list"),
|
|
21
|
-
acquire: () => unsupported("acquire"),
|
|
22
|
-
renew: () => unsupported("renew"),
|
|
23
|
-
release: () => unsupported("release"),
|
|
24
|
-
write: () => unsupported("write"),
|
|
25
|
-
operation: () => unsupported("operation"),
|
|
26
|
-
read: () => unsupported("read"),
|
|
27
|
-
control: () => unsupported("control"),
|
|
28
|
-
stop: () => unsupported("stop"),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* 创建默认 RuntimePlatform 平台实例。
|
|
33
|
-
* 直接基于 Node 原生与 Core 内核能力组装平台,禁止任何全局单例状态。
|
|
34
|
-
*/
|
|
35
|
-
export function createDefaultPlatform(options = {}) {
|
|
36
|
-
const platformName = options.name ?? "node";
|
|
37
|
-
const clock = options.clock ?? new SystemClock();
|
|
38
|
-
const files = options.files ?? new NodeFileSystem({ rootDir: options.rootDir });
|
|
39
|
-
const modules = options.modules ?? new DefaultModuleLoader();
|
|
40
|
-
// 未注入底层驱动时不静默回退内存模拟驱动:默认平台不提供可用进程能力,
|
|
41
|
-
// 避免默认路径下的进程调用无声挂死或必然超时
|
|
42
|
-
const processDriver = options.processDriver;
|
|
43
|
-
const processManager = options.processManager ??
|
|
44
|
-
(processDriver ? new ProcessManager({ driver: processDriver }) : undefined);
|
|
45
|
-
const process = options.process ??
|
|
46
|
-
(processManager
|
|
47
|
-
? processManager.forOwner({
|
|
48
|
-
tenantId: "default",
|
|
49
|
-
principalId: "default",
|
|
50
|
-
packageInstanceId: "default",
|
|
51
|
-
generationId: "default",
|
|
52
|
-
})
|
|
53
|
-
: createUnsupportedProcessApi());
|
|
54
|
-
const storage = options.storage ?? {
|
|
55
|
-
createStorage(packageId, opts) {
|
|
56
|
-
return coreCreateStorage(packageId, {
|
|
57
|
-
customHome: options.customHome,
|
|
58
|
-
dataDir: options.dataDir,
|
|
59
|
-
...opts,
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
createGlobalStorage(opts) {
|
|
63
|
-
return coreCreateGlobalStorage({
|
|
64
|
-
customHome: options.customHome,
|
|
65
|
-
dataDir: options.dataDir,
|
|
66
|
-
...opts,
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
return {
|
|
71
|
-
name: platformName,
|
|
72
|
-
clock,
|
|
73
|
-
files,
|
|
74
|
-
modules,
|
|
75
|
-
process,
|
|
76
|
-
storage,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { type ActionDockLockfile } from "./lockfile.js";
|
|
2
|
-
import type { ActionDockManifest, PlaybookDefinition } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* 语义化版本元数据结构。
|
|
5
|
-
*/
|
|
6
|
-
export interface SemVer {
|
|
7
|
-
major: number;
|
|
8
|
-
minor: number;
|
|
9
|
-
patch: number;
|
|
10
|
-
prerelease?: string;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* 解析基础 SemVer 版本字符串。
|
|
14
|
-
*/
|
|
15
|
-
export declare function parseSemVer(v: string): SemVer | null;
|
|
16
|
-
/**
|
|
17
|
-
* 校验两个语义化版本范围是否兼容并能收敛为单一解析版本。
|
|
18
|
-
* 遵循设计规范:直接或传递版本范围无法收敛时拒绝并抛出 ACTION_PACKAGE_VERSION_CONFLICT。
|
|
19
|
-
*/
|
|
20
|
-
export declare function areVersionsCompatible(v1: string, v2: string): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* 版本冲突错误。
|
|
23
|
-
*/
|
|
24
|
-
export declare class ActionPackageVersionConflictError extends Error {
|
|
25
|
-
readonly code = "ACTION_PACKAGE_VERSION_CONFLICT";
|
|
26
|
-
readonly packageId: string;
|
|
27
|
-
readonly conflicts: Array<{
|
|
28
|
-
requester: string;
|
|
29
|
-
rangeOrVersion: string;
|
|
30
|
-
}>;
|
|
31
|
-
constructor(packageId: string, conflicts: Array<{
|
|
32
|
-
requester: string;
|
|
33
|
-
rangeOrVersion: string;
|
|
34
|
-
}>);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* 未声明依赖调用拦截错误。
|
|
38
|
-
*/
|
|
39
|
-
export declare class UndeclaredActionDependencyError extends Error {
|
|
40
|
-
readonly code = "UNDECLARED_ACTION_DEPENDENCY";
|
|
41
|
-
readonly targetRef: string;
|
|
42
|
-
readonly caller?: string;
|
|
43
|
-
constructor(targetRef: string, caller?: string, reason?: string);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* 已解析 Action 包信息。
|
|
47
|
-
*/
|
|
48
|
-
export interface ResolvedPackageInfo {
|
|
49
|
-
packageId: string;
|
|
50
|
-
npmPackage: string;
|
|
51
|
-
version: string;
|
|
52
|
-
packageRoot: string;
|
|
53
|
-
manifest: ActionDockManifest;
|
|
54
|
-
manifestDigest: string;
|
|
55
|
-
isDirect: boolean;
|
|
56
|
-
isRoot: boolean;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* 完整 Action 包依赖图结构。
|
|
60
|
-
*/
|
|
61
|
-
export interface DependencyGraph {
|
|
62
|
-
rootPackageId: string;
|
|
63
|
-
packages: Map<string, ResolvedPackageInfo>;
|
|
64
|
-
directDependencyIds: Set<string>;
|
|
65
|
-
transitiveDependencyIds: Set<string>;
|
|
66
|
-
visiblePlaybooks: Map<string, PlaybookDefinition>;
|
|
67
|
-
delegatedActions: Set<string>;
|
|
68
|
-
}
|
|
69
|
-
export interface ActionPackageResolverOptions {
|
|
70
|
-
projectRoot: string;
|
|
71
|
-
manifest?: ActionDockManifest;
|
|
72
|
-
lockfile?: ActionDockLockfile;
|
|
73
|
-
allowDevLinks?: boolean;
|
|
74
|
-
customHome?: string;
|
|
75
|
-
packageRoots?: Record<string, string>;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* 依赖解析器 ActionPackageResolver。
|
|
79
|
-
* 负责从 actiondock.json.dependencies 与 actiondock.lock.json 建立包索引与依赖闭包,
|
|
80
|
-
* 实施版本冲突检测与调用可见性鉴权。
|
|
81
|
-
*/
|
|
82
|
-
export declare class ActionPackageResolver {
|
|
83
|
-
readonly projectRoot: string;
|
|
84
|
-
private options;
|
|
85
|
-
private resolvedGraph?;
|
|
86
|
-
constructor(options: ActionPackageResolverOptions);
|
|
87
|
-
/**
|
|
88
|
-
* 同步解析依赖图。
|
|
89
|
-
*/
|
|
90
|
-
resolveSync(): DependencyGraph;
|
|
91
|
-
/**
|
|
92
|
-
* 异步解析依赖图。
|
|
93
|
-
*/
|
|
94
|
-
resolve(): Promise<DependencyGraph>;
|
|
95
|
-
/**
|
|
96
|
-
* 判定目标 Action 是否允许作为根调用发起。
|
|
97
|
-
* 规则:
|
|
98
|
-
* - 目标属于当前根包;
|
|
99
|
-
* - 目标属于 actiondock.json 直接依赖;
|
|
100
|
-
* - 目标属于可见 Playbook 精确委托点名的 Action。
|
|
101
|
-
*/
|
|
102
|
-
canRootCall(targetPackageId: string, targetActionId: string): boolean;
|
|
103
|
-
/**
|
|
104
|
-
* 校验根调用权限,不合法时抛出 UNDECLARED_ACTION_DEPENDENCY。
|
|
105
|
-
*/
|
|
106
|
-
assertRootCallAllowed(targetPackageId: string, targetActionId: string): void;
|
|
107
|
-
/**
|
|
108
|
-
* 判定跨包级联调用是否合法。
|
|
109
|
-
* 规则:调用者 Action 必须在 actiondock.json 的 uses 中显式声明对目标 Action 的依赖。
|
|
110
|
-
*/
|
|
111
|
-
canCascadeCall(callerPackageId: string, callerActionId: string, targetPackageId: string, targetActionId: string): boolean;
|
|
112
|
-
/**
|
|
113
|
-
* 校验跨包级联调用权限,不合法时抛出 UNDECLARED_ACTION_DEPENDENCY。
|
|
114
|
-
*/
|
|
115
|
-
assertCascadeCallAllowed(callerPackageId: string, callerActionId: string, targetPackageId: string, targetActionId: string): void;
|
|
116
|
-
}
|