@actiondock/core 2.7.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 +102 -10
- package/dist/errors.js +103 -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 -24
- package/dist/index.js +19 -23
- package/dist/input/advice.d.ts +5 -1
- package/dist/input/advice.js +163 -214
- package/dist/input/describe.d.ts +1 -1
- package/dist/input/flat-errors.d.ts +5 -6
- package/dist/input/flat-errors.js +6 -6
- package/dist/input/flat-materializer.js +42 -44
- 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/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 +2 -2
- package/dist/profile/client-query.js +5 -6
- package/dist/profile/client-transport.d.ts +19 -17
- package/dist/profile/client-transport.js +47 -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 -93
- package/dist/runtime/runner.js +132 -364
- package/dist/runtime/standalone.d.ts +23 -8
- package/dist/runtime/standalone.js +100 -147
- 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 -635
- 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
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 内存中活跃执行句柄(In-flight Execution Handles)生命周期管理器。
|
|
3
|
-
*
|
|
4
|
-
* 职责:
|
|
5
|
-
* 1. 集中追踪正在执行的异步 Action 任务句柄。
|
|
6
|
-
* 2. 任务完成(无论成功或失败)后通过 Promise.finally 自动注销,防止内存泄漏。
|
|
7
|
-
* 3. 支持依据 runId 查询、遍历或主动发送取消信号(cancel)。
|
|
8
|
-
*/
|
|
9
|
-
export class ExecutionManager {
|
|
10
|
-
active = new Map();
|
|
11
|
-
/**
|
|
12
|
-
* 注册一个活跃的执行句柄。
|
|
13
|
-
* 当底层 Promise 完成结算(resolve/reject)时,自动从活跃映射表中移除。
|
|
14
|
-
*
|
|
15
|
-
* @param handle 执行句柄对象
|
|
16
|
-
*/
|
|
17
|
-
register(handle) {
|
|
18
|
-
this.active.set(handle.runId, handle);
|
|
19
|
-
handle.result.finally(() => {
|
|
20
|
-
this.active.delete(handle.runId);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* 根据 runId 检索正在执行的任务句柄。
|
|
25
|
-
*
|
|
26
|
-
* @param runId 运行 ID
|
|
27
|
-
* @returns 匹配的 ExecutionHandle 或 undefined
|
|
28
|
-
*/
|
|
29
|
-
get(runId) {
|
|
30
|
-
return this.active.get(runId);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 向指定 runId 的在途执行任务发送取消信号。
|
|
34
|
-
*
|
|
35
|
-
* @param runId 目标运行 ID
|
|
36
|
-
* @param reason 取消原因描述
|
|
37
|
-
* @returns 若句柄存在且成功触发中断返回 true;若任务不存在或已完成返回 false
|
|
38
|
-
*/
|
|
39
|
-
cancel(runId, reason) {
|
|
40
|
-
const handle = this.active.get(runId);
|
|
41
|
-
if (!handle) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
return handle.cancel(reason);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* 手动从活跃集合中移除执行句柄。
|
|
48
|
-
*
|
|
49
|
-
* @param runId 运行 ID
|
|
50
|
-
*/
|
|
51
|
-
remove(runId) {
|
|
52
|
-
this.active.delete(runId);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* 获取当前系统中所有正在执行的活跃句柄列表。
|
|
56
|
-
*/
|
|
57
|
-
list() {
|
|
58
|
-
return Array.from(this.active.values());
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* 清空所有活跃执行句柄。
|
|
62
|
-
*/
|
|
63
|
-
clear() {
|
|
64
|
-
this.active.clear();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { ProcessAPI } from "@actiondock/sdk";
|
|
2
|
-
import type { RuntimeStorage } from "../storage/types.js";
|
|
3
|
-
import type { RuntimePlatform } from "../platform/types.js";
|
|
4
|
-
import type { Clock } from "./clock.js";
|
|
5
|
-
import type { ActionRunner, PackageContextResolver, RunnerOptions } from "./runner.js";
|
|
6
|
-
/**
|
|
7
|
-
* 跨包 Runner 构建工厂参数(Runner 编排层注入的宿主执行环境快照)。
|
|
8
|
-
*/
|
|
9
|
-
export interface PackageRunnerFactoryOptions {
|
|
10
|
-
/** 全局共享持久化存储实例(传递给子包 Runner 复用) */
|
|
11
|
-
globalStorage?: RuntimeStorage;
|
|
12
|
-
/** 项目根目录绝对路径 */
|
|
13
|
-
projectRoot?: string;
|
|
14
|
-
/** 外部注入的进程执行器 */
|
|
15
|
-
process?: ProcessAPI;
|
|
16
|
-
/** 可选的时间与时钟源 */
|
|
17
|
-
clock?: Clock;
|
|
18
|
-
/** 可选的底层运行时平台契约 */
|
|
19
|
-
platform?: RuntimePlatform;
|
|
20
|
-
/** 最大调用嵌套深度限制 */
|
|
21
|
-
maxCallDepth: number;
|
|
22
|
-
/** 最大并发子任务数限制 */
|
|
23
|
-
maxSubRuns: number;
|
|
24
|
-
/** 动态解析 Action 的委托函数 */
|
|
25
|
-
actionResolver?: RunnerOptions["actionResolver"];
|
|
26
|
-
/** 跨包存储工厂 */
|
|
27
|
-
getStorageForPackage?: (packageId: string, projectRoot?: string) => RuntimeStorage;
|
|
28
|
-
/** 跨包运行上下文解析委托函数 */
|
|
29
|
-
packageContextResolver?: PackageContextResolver;
|
|
30
|
-
/** 自定义 ActionDock 用户家目录 */
|
|
31
|
-
customHome?: string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 跨包 Runner 构建工厂与缓存(单一职责模块)。
|
|
35
|
-
*
|
|
36
|
-
* 收敛 ActionRunner 原内联的跨包执行域:已解析子包 Runner 缓存、构建中 in-flight
|
|
37
|
-
* Promise 去重(消除并发 check-then-act 竞态)、本工厂直接创建的子包存储清单与
|
|
38
|
-
* dispose 级联释放。子 Runner 实例构造委托 ActionRunner 公共构造器,形成单向
|
|
39
|
-
* 依赖:factory -> runner,不产生环。
|
|
40
|
-
*/
|
|
41
|
-
export declare class PackageRunnerFactory {
|
|
42
|
-
private readonly options;
|
|
43
|
-
private packageRunners;
|
|
44
|
-
/** 跨包 Runner 构建中的 in-flight Promise:并发调用 await 同一构建任务,消除 check-then-act 竞态 */
|
|
45
|
-
private pendingPackageRunners;
|
|
46
|
-
/** 本工厂直接为子包创建的存储连接(dispose 时级联关闭;外部注入存储不在此列) */
|
|
47
|
-
private packageStorages;
|
|
48
|
-
/** dispose 幂等守卫:并发调用复用同一次释放任务 */
|
|
49
|
-
private disposePromise;
|
|
50
|
-
/** 子包 Runner 构造委托(由 runner.ts 注入,避免本模块反向依赖 runner.ts) */
|
|
51
|
-
private readonly createRunner;
|
|
52
|
-
constructor(options: PackageRunnerFactoryOptions, createRunner: (options: RunnerOptions) => ActionRunner);
|
|
53
|
-
/**
|
|
54
|
-
* 已解析子包 Runner 缓存视图(调用方只读遍历使用)。
|
|
55
|
-
*/
|
|
56
|
-
get runners(): Map<string, ActionRunner>;
|
|
57
|
-
/**
|
|
58
|
-
* 注入或更新跨包运行上下文解析委托。
|
|
59
|
-
*/
|
|
60
|
-
setPackageContextResolver(resolver: PackageContextResolver): void;
|
|
61
|
-
/**
|
|
62
|
-
* 跨包运行时解析与获取(确保跨包执行具备独立的配置、存储、状态与 Action 注册表)。
|
|
63
|
-
*
|
|
64
|
-
* 缓存 miss 后存在长异步窗口(加载配置、扫描 Action、打开存储),并发调用会重复构建
|
|
65
|
-
* Runner、重复打开 SQLite 连接且子任务限流计数分裂;故以 in-flight Promise 去重,
|
|
66
|
-
* 并发方 await 同一构建任务,构建失败时移除该 Promise 以便后续重试。
|
|
67
|
-
*/
|
|
68
|
-
resolveTargetPackageRunner(targetPackageId: string): Promise<ActionRunner | undefined>;
|
|
69
|
-
/**
|
|
70
|
-
* 实际构建跨包 Runner(仅由 resolveTargetPackageRunner 串行调度)。
|
|
71
|
-
*/
|
|
72
|
-
private buildTargetPackageRunner;
|
|
73
|
-
/**
|
|
74
|
-
* 释放跨包资源:遍历关闭全部子包 Runner 及其独立创建的存储连接。
|
|
75
|
-
*
|
|
76
|
-
* 幂等且并发安全:重复调用直接复用首次 Promise;子包存储异常不阻断其余释放;
|
|
77
|
-
* 仅关闭由本工厂构建子包 Runner 时独立创建的存储,外部注入的存储(如经
|
|
78
|
-
* packageContextResolver 传入的目标包自身存储)生命周期归所有者管理,不在此误关。
|
|
79
|
-
*/
|
|
80
|
-
dispose(): Promise<void>;
|
|
81
|
-
private disposeInternal;
|
|
82
|
-
}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { loadActions, loadProjectConfig } from "../project/loader.js";
|
|
3
|
-
import { resolvePackageRoot } from "../registry/registry.js";
|
|
4
|
-
/**
|
|
5
|
-
* 跨包 Runner 构建工厂与缓存(单一职责模块)。
|
|
6
|
-
*
|
|
7
|
-
* 收敛 ActionRunner 原内联的跨包执行域:已解析子包 Runner 缓存、构建中 in-flight
|
|
8
|
-
* Promise 去重(消除并发 check-then-act 竞态)、本工厂直接创建的子包存储清单与
|
|
9
|
-
* dispose 级联释放。子 Runner 实例构造委托 ActionRunner 公共构造器,形成单向
|
|
10
|
-
* 依赖:factory -> runner,不产生环。
|
|
11
|
-
*/
|
|
12
|
-
export class PackageRunnerFactory {
|
|
13
|
-
options;
|
|
14
|
-
packageRunners = new Map();
|
|
15
|
-
/** 跨包 Runner 构建中的 in-flight Promise:并发调用 await 同一构建任务,消除 check-then-act 竞态 */
|
|
16
|
-
pendingPackageRunners = new Map();
|
|
17
|
-
/** 本工厂直接为子包创建的存储连接(dispose 时级联关闭;外部注入存储不在此列) */
|
|
18
|
-
packageStorages = new Set();
|
|
19
|
-
/** dispose 幂等守卫:并发调用复用同一次释放任务 */
|
|
20
|
-
disposePromise;
|
|
21
|
-
/** 子包 Runner 构造委托(由 runner.ts 注入,避免本模块反向依赖 runner.ts) */
|
|
22
|
-
createRunner;
|
|
23
|
-
constructor(options, createRunner) {
|
|
24
|
-
this.options = options;
|
|
25
|
-
this.createRunner = createRunner;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* 已解析子包 Runner 缓存视图(调用方只读遍历使用)。
|
|
29
|
-
*/
|
|
30
|
-
get runners() {
|
|
31
|
-
return this.packageRunners;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 注入或更新跨包运行上下文解析委托。
|
|
35
|
-
*/
|
|
36
|
-
setPackageContextResolver(resolver) {
|
|
37
|
-
this.options.packageContextResolver = resolver;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 跨包运行时解析与获取(确保跨包执行具备独立的配置、存储、状态与 Action 注册表)。
|
|
41
|
-
*
|
|
42
|
-
* 缓存 miss 后存在长异步窗口(加载配置、扫描 Action、打开存储),并发调用会重复构建
|
|
43
|
-
* Runner、重复打开 SQLite 连接且子任务限流计数分裂;故以 in-flight Promise 去重,
|
|
44
|
-
* 并发方 await 同一构建任务,构建失败时移除该 Promise 以便后续重试。
|
|
45
|
-
*/
|
|
46
|
-
async resolveTargetPackageRunner(targetPackageId) {
|
|
47
|
-
const cached = this.packageRunners.get(targetPackageId);
|
|
48
|
-
if (cached) {
|
|
49
|
-
return cached;
|
|
50
|
-
}
|
|
51
|
-
const inFlight = this.pendingPackageRunners.get(targetPackageId);
|
|
52
|
-
if (inFlight) {
|
|
53
|
-
return inFlight;
|
|
54
|
-
}
|
|
55
|
-
const building = this.buildTargetPackageRunner(targetPackageId).finally(() => {
|
|
56
|
-
// 无论成败均移除 in-flight 记录:成功者已写入正式缓存,失败者允许重试
|
|
57
|
-
this.pendingPackageRunners.delete(targetPackageId);
|
|
58
|
-
});
|
|
59
|
-
this.pendingPackageRunners.set(targetPackageId, building);
|
|
60
|
-
return building;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* 实际构建跨包 Runner(仅由 resolveTargetPackageRunner 串行调度)。
|
|
64
|
-
*/
|
|
65
|
-
async buildTargetPackageRunner(targetPackageId) {
|
|
66
|
-
const opts = this.options;
|
|
67
|
-
if (opts.packageContextResolver) {
|
|
68
|
-
const resolved = await opts.packageContextResolver(targetPackageId);
|
|
69
|
-
if (resolved) {
|
|
70
|
-
const runner = this.createRunner({
|
|
71
|
-
packageId: targetPackageId,
|
|
72
|
-
packageInstanceId: resolved.packageInstanceId || resolved.projectConfig?.packageInstanceId || targetPackageId,
|
|
73
|
-
generationId: resolved.generationId || resolved.projectConfig?.generationId || "1",
|
|
74
|
-
storage: resolved.storage,
|
|
75
|
-
globalStorage: opts.globalStorage,
|
|
76
|
-
projectRoot: resolved.projectRoot,
|
|
77
|
-
projectConfig: resolved.projectConfig,
|
|
78
|
-
actions: resolved.actions,
|
|
79
|
-
process: opts.process,
|
|
80
|
-
clock: opts.clock,
|
|
81
|
-
platform: opts.platform,
|
|
82
|
-
maxCallDepth: opts.maxCallDepth,
|
|
83
|
-
maxSubRuns: opts.maxSubRuns,
|
|
84
|
-
actionResolver: opts.actionResolver,
|
|
85
|
-
getStorageForPackage: opts.getStorageForPackage,
|
|
86
|
-
packageContextResolver: opts.packageContextResolver,
|
|
87
|
-
});
|
|
88
|
-
this.packageRunners.set(targetPackageId, runner);
|
|
89
|
-
return runner;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const root = resolvePackageRoot(targetPackageId, opts.projectRoot, opts.customHome);
|
|
93
|
-
if (root && existsSync(root)) {
|
|
94
|
-
const config = loadProjectConfig(root);
|
|
95
|
-
let storage;
|
|
96
|
-
let ownsPackageStorage = false;
|
|
97
|
-
if (opts.getStorageForPackage) {
|
|
98
|
-
storage = opts.getStorageForPackage(targetPackageId, root);
|
|
99
|
-
}
|
|
100
|
-
else if (opts.platform) {
|
|
101
|
-
storage = opts.platform.storage.createStorage(targetPackageId, {
|
|
102
|
-
projectRoot: root,
|
|
103
|
-
customHome: opts.customHome,
|
|
104
|
-
// 跨包子包存储由当前执行宿主持有,打开时收割遗留孤儿运行
|
|
105
|
-
recoverOrphans: true,
|
|
106
|
-
});
|
|
107
|
-
ownsPackageStorage = true;
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
// 回退分支与主路径共用 createStorage 单一事实源,确保 run 记录落在统一解析的库文件
|
|
111
|
-
const { createStorage } = await import("../storage/index.js");
|
|
112
|
-
storage = createStorage(targetPackageId, { projectRoot: root, customHome: opts.customHome, recoverOrphans: true });
|
|
113
|
-
ownsPackageStorage = true;
|
|
114
|
-
}
|
|
115
|
-
// 由本工厂直接创建的子包存储纳入级联释放清单(getStorageForPackage 注入方自管理生命周期)
|
|
116
|
-
if (ownsPackageStorage) {
|
|
117
|
-
this.packageStorages.add(storage);
|
|
118
|
-
}
|
|
119
|
-
const actionsMap = await loadActions(root, config.actionsDir, {
|
|
120
|
-
loader: opts.platform?.modules,
|
|
121
|
-
});
|
|
122
|
-
const runner = this.createRunner({
|
|
123
|
-
packageId: targetPackageId,
|
|
124
|
-
packageInstanceId: config.packageInstanceId || targetPackageId,
|
|
125
|
-
generationId: config.generationId || "1",
|
|
126
|
-
storage,
|
|
127
|
-
globalStorage: opts.globalStorage,
|
|
128
|
-
projectRoot: root,
|
|
129
|
-
projectConfig: config,
|
|
130
|
-
actions: actionsMap,
|
|
131
|
-
process: opts.process,
|
|
132
|
-
clock: opts.clock,
|
|
133
|
-
platform: opts.platform,
|
|
134
|
-
maxCallDepth: opts.maxCallDepth,
|
|
135
|
-
maxSubRuns: opts.maxSubRuns,
|
|
136
|
-
actionResolver: opts.actionResolver,
|
|
137
|
-
getStorageForPackage: opts.getStorageForPackage,
|
|
138
|
-
packageContextResolver: opts.packageContextResolver,
|
|
139
|
-
customHome: opts.customHome,
|
|
140
|
-
});
|
|
141
|
-
this.packageRunners.set(targetPackageId, runner);
|
|
142
|
-
return runner;
|
|
143
|
-
}
|
|
144
|
-
return undefined;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* 释放跨包资源:遍历关闭全部子包 Runner 及其独立创建的存储连接。
|
|
148
|
-
*
|
|
149
|
-
* 幂等且并发安全:重复调用直接复用首次 Promise;子包存储异常不阻断其余释放;
|
|
150
|
-
* 仅关闭由本工厂构建子包 Runner 时独立创建的存储,外部注入的存储(如经
|
|
151
|
-
* packageContextResolver 传入的目标包自身存储)生命周期归所有者管理,不在此误关。
|
|
152
|
-
*/
|
|
153
|
-
async dispose() {
|
|
154
|
-
if (this.disposePromise) {
|
|
155
|
-
return this.disposePromise;
|
|
156
|
-
}
|
|
157
|
-
this.disposePromise = this.disposeInternal();
|
|
158
|
-
return this.disposePromise;
|
|
159
|
-
}
|
|
160
|
-
async disposeInternal() {
|
|
161
|
-
// 深度优先递归释放子包 Runner(子 Runner 可能又构建了孙 Runner)
|
|
162
|
-
const children = Array.from(this.packageRunners.values());
|
|
163
|
-
this.packageRunners.clear();
|
|
164
|
-
await Promise.all(children.map(async (child) => {
|
|
165
|
-
try {
|
|
166
|
-
await child.dispose();
|
|
167
|
-
}
|
|
168
|
-
catch {
|
|
169
|
-
// 单个子 Runner 释放异常不阻断其余释放
|
|
170
|
-
}
|
|
171
|
-
}));
|
|
172
|
-
// 关闭由本工厂直接创建的子包存储(buildTargetPackageRunner 回退分支)
|
|
173
|
-
for (const storage of this.packageStorages) {
|
|
174
|
-
try {
|
|
175
|
-
const res = storage.close();
|
|
176
|
-
if (res && typeof res.then === "function") {
|
|
177
|
-
await res;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
catch {
|
|
181
|
-
// 存储重复关闭或已失效时忽略,保持释放链路继续
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
this.packageStorages.clear();
|
|
185
|
-
}
|
|
186
|
-
}
|
package/dist/target/local.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { ActionRef, ExecutionEvent, ExecutionResult, JsonValue, RunRecord } from "@actiondock/sdk";
|
|
2
|
-
import type { ActionDockApp, ActionSpec, ActionSummary, ListActionsOptions, PackageInfo, PlaybookSpec, PlaybookSummary } from "../app/types.js";
|
|
3
|
-
import type { CancelResult, ExecuteOptions, ExecutionTicket } from "../execution/types.js";
|
|
4
|
-
import type { ActionDockHost } from "../host/types.js";
|
|
5
|
-
import type { StateEntry } from "../storage/types.js";
|
|
6
|
-
import { type ActionDockTarget, type ConfigValueView, type ListRunsOptions, type StateScopeOptions, type TargetInfo } from "./types.js";
|
|
7
|
-
/**
|
|
8
|
-
* 本地 ActionDockTarget 门面实现。
|
|
9
|
-
* 内部包装 ActionDockHost 或 ActionDockApp,将统一调用直接转交给 Host 或 App。
|
|
10
|
-
*/
|
|
11
|
-
export declare class LocalActionDockTarget implements ActionDockTarget {
|
|
12
|
-
readonly target: ActionDockHost | ActionDockApp;
|
|
13
|
-
constructor(target: ActionDockHost | ActionDockApp);
|
|
14
|
-
unwrap(): ActionDockHost | ActionDockApp;
|
|
15
|
-
info(): Promise<TargetInfo>;
|
|
16
|
-
listPackages(): Promise<PackageInfo[]>;
|
|
17
|
-
listActions(options?: ListActionsOptions): Promise<ActionSummary[]>;
|
|
18
|
-
describeAction(ref: ActionRef | string): Promise<ActionSpec>;
|
|
19
|
-
listPlaybooks(): Promise<PlaybookSummary[]>;
|
|
20
|
-
describePlaybook(id: string): Promise<PlaybookSpec>;
|
|
21
|
-
runAction(ref: ActionRef | string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionResult>;
|
|
22
|
-
startAction(ref: ActionRef | string, input: JsonValue, options?: ExecuteOptions): Promise<ExecutionTicket>;
|
|
23
|
-
listRuns(options?: ListRunsOptions): Promise<RunRecord[]>;
|
|
24
|
-
clearRuns(options?: {
|
|
25
|
-
packageId?: string;
|
|
26
|
-
actionId?: string;
|
|
27
|
-
status?: string;
|
|
28
|
-
}): Promise<number>;
|
|
29
|
-
getRun(runId: string): Promise<RunRecord | undefined>;
|
|
30
|
-
cancelRun(runId: string, reason?: string): Promise<CancelResult>;
|
|
31
|
-
events(runId: string, options?: {
|
|
32
|
-
after?: number | string;
|
|
33
|
-
signal?: AbortSignal;
|
|
34
|
-
maxQueueSize?: number;
|
|
35
|
-
}): AsyncIterable<ExecutionEvent>;
|
|
36
|
-
private resolveApp;
|
|
37
|
-
private fallbackGlobalStorage?;
|
|
38
|
-
private getGlobalStorage;
|
|
39
|
-
private findDeclaredConfigItem;
|
|
40
|
-
getConfig(packageId: string, key: string): Promise<ConfigValueView>;
|
|
41
|
-
setConfig(packageId: string, key: string, value: JsonValue): Promise<void>;
|
|
42
|
-
deleteConfig(packageId: string, key: string): Promise<boolean>;
|
|
43
|
-
listConfig(packageId: string): Promise<ConfigValueView[]>;
|
|
44
|
-
getState<T extends JsonValue = JsonValue>(packageId: string, actionId: string, key: string, options?: StateScopeOptions): Promise<T | undefined>;
|
|
45
|
-
setState<T extends JsonValue = JsonValue>(packageId: string, actionId: string, key: string, value: T, options?: StateScopeOptions): Promise<void>;
|
|
46
|
-
deleteState(packageId: string, actionId: string, key: string, options?: StateScopeOptions): Promise<boolean>;
|
|
47
|
-
listStateKeys(packageId: string, actionId: string, options?: StateScopeOptions): Promise<string[]>;
|
|
48
|
-
clearState(packageId: string, actionId: string, options?: StateScopeOptions): Promise<number>;
|
|
49
|
-
listStateEntries(packageId: string, options?: any): Promise<StateEntry[]>;
|
|
50
|
-
close(options?: {
|
|
51
|
-
timeoutMs?: number;
|
|
52
|
-
}): Promise<void>;
|
|
53
|
-
}
|