@actiondock/core 2.7.0 → 2.9.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 +77 -64
- 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 +106 -10
- package/dist/errors.js +105 -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/project/types.d.ts +5 -0
- 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 +12 -0
- package/dist/server/index.js +11 -0
- package/dist/server/mcp-endpoint.d.ts +61 -0
- package/dist/server/mcp-endpoint.js +118 -0
- package/dist/server/policy.d.ts +138 -0
- package/dist/server/policy.js +368 -0
- package/dist/server/routes/actions.js +114 -64
- package/dist/server/routes/common.d.ts +18 -33
- package/dist/server/routes/common.js +45 -65
- package/dist/server/routes/config.d.ts +1 -1
- package/dist/server/routes/config.js +55 -65
- package/dist/server/routes/doctor.d.ts +1 -1
- package/dist/server/routes/doctor.js +13 -21
- package/dist/server/routes/health.d.ts +1 -1
- package/dist/server/routes/health.js +4 -5
- package/dist/server/routes/info.d.ts +2 -2
- package/dist/server/routes/info.js +17 -24
- package/dist/server/routes/playbooks.js +23 -36
- package/dist/server/routes/runs.js +151 -141
- package/dist/server/routes/state.d.ts +1 -1
- package/dist/server/routes/state.js +64 -63
- package/dist/server/security.d.ts +11 -0
- package/dist/server/security.js +36 -19
- package/dist/server/server.d.ts +2 -2
- package/dist/server/server.js +224 -238
- package/dist/server/types.d.ts +68 -21
- 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,12 +1,14 @@
|
|
|
1
|
-
import type { ActionDefinition,
|
|
2
|
-
import type {
|
|
1
|
+
import type { ActionDefinition, ExecutionEvent, ExecutionResult, JsonValue, Logger, ProcessAPI, RunRecord } from "@actiondock/sdk";
|
|
2
|
+
import type { ActionInvoker, CancelResult, ExecutionTicket, LocalActionResolver } from "../execution/types.js";
|
|
3
|
+
import type { InvocationContext, RunOptions } from "../invocation/types.js";
|
|
3
4
|
import type { ConfigItemDefinition, ProjectConfig } from "../project/types.js";
|
|
4
|
-
import type { Clock } from "../runtime/clock.js";
|
|
5
5
|
import type { EventSink } from "../runtime/events.js";
|
|
6
6
|
import type { RuntimePlatform, StorageFactory, StorageFactoryOptions } from "../platform/types.js";
|
|
7
|
-
import type { RuntimeStorage } from "../storage/types.js";
|
|
8
|
-
import type {
|
|
9
|
-
|
|
7
|
+
import type { RuntimeStorage, StateEntry } from "../storage/types.js";
|
|
8
|
+
import type { Clock } from "../storage/clock.js";
|
|
9
|
+
import type { ConfigValueView, ListRunsOptions, StateScopeOptions } from "../service/types.js";
|
|
10
|
+
import type { PackageIdentity } from "../runtime/identity.js";
|
|
11
|
+
export type { ConfigValueView, ListRunsOptions, PackageIdentity, RuntimePlatform, StateScopeOptions, StorageFactory, StorageFactoryOptions };
|
|
10
12
|
/**
|
|
11
13
|
* 宏包信息契约。
|
|
12
14
|
*/
|
|
@@ -95,6 +97,18 @@ export interface ListActionsOptions {
|
|
|
95
97
|
/** 标识前缀过滤 */
|
|
96
98
|
prefix?: string;
|
|
97
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* 对 Action 摘要列表应用统一的检索过滤(标签、模糊关键词与标识前缀)。
|
|
102
|
+
*
|
|
103
|
+
* PackageRuntime 与 Host 两级列表查询的单一事实源:
|
|
104
|
+
* 两处过滤块逐字相同,收敛后调用方仅需在外层叠加各自的特有逻辑
|
|
105
|
+
* (Host 版在过滤前额外完成可见性筛选与跨包限定名改写)。
|
|
106
|
+
*/
|
|
107
|
+
export declare function applyActionSummaryFilters<T extends {
|
|
108
|
+
id: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
tags?: string[];
|
|
111
|
+
}>(summaries: readonly T[], options?: ListActionsOptions): T[];
|
|
98
112
|
/**
|
|
99
113
|
* Playbook 规程简要摘要条目。
|
|
100
114
|
*/
|
|
@@ -137,21 +151,13 @@ export interface StateOptions {
|
|
|
137
151
|
ttl?: number;
|
|
138
152
|
}
|
|
139
153
|
/**
|
|
140
|
-
*
|
|
154
|
+
* PackageRuntime 初始化公开配置选项(面向用户与外部配置)。
|
|
141
155
|
*/
|
|
142
|
-
export interface
|
|
156
|
+
export interface PackageRuntimeOptions {
|
|
143
157
|
/** 项目根目录绝对物理路径 */
|
|
144
158
|
packageRoot?: string;
|
|
145
159
|
/** 项目配置文件 (actiondock.json) 对象 */
|
|
146
160
|
projectConfig?: ProjectConfig;
|
|
147
|
-
/** 显式注入的运行时平台适配 */
|
|
148
|
-
platform?: RuntimePlatform;
|
|
149
|
-
/** 显式注入的项目级运行时存储实例 */
|
|
150
|
-
storage?: RuntimeStorage;
|
|
151
|
-
/** 显式注入的全局运行时存储实例 */
|
|
152
|
-
globalStorage?: RuntimeStorage;
|
|
153
|
-
/** 显式注入的事件接收器 */
|
|
154
|
-
eventSink?: EventSink;
|
|
155
161
|
/** 数据持久化存储目录 */
|
|
156
162
|
dataDir?: string;
|
|
157
163
|
/** 自定义家目录绝对路径 */
|
|
@@ -165,31 +171,11 @@ export interface ActionDockAppOptions {
|
|
|
165
171
|
} | (ActionDefinition & {
|
|
166
172
|
id: string;
|
|
167
173
|
})> | Record<string, ActionDefinition>;
|
|
168
|
-
/**
|
|
169
|
-
actionResolver?:
|
|
170
|
-
/** 跨包运行上下文解析委托函数 */
|
|
171
|
-
packageContextResolver?: (packageId: string) => Promise<{
|
|
172
|
-
projectRoot?: string;
|
|
173
|
-
projectConfig?: ProjectConfig;
|
|
174
|
-
storage: RuntimeStorage;
|
|
175
|
-
actions?: Map<string, ActionDefinition>;
|
|
176
|
-
packageInstanceId?: string;
|
|
177
|
-
generationId?: string;
|
|
178
|
-
} | undefined> | {
|
|
179
|
-
projectRoot?: string;
|
|
180
|
-
projectConfig?: ProjectConfig;
|
|
181
|
-
storage: RuntimeStorage;
|
|
182
|
-
actions?: Map<string, ActionDefinition>;
|
|
183
|
-
packageInstanceId?: string;
|
|
184
|
-
generationId?: string;
|
|
185
|
-
} | undefined;
|
|
186
|
-
/** 包物理实例标识 */
|
|
187
|
-
packageInstanceId?: string;
|
|
188
|
-
/** 快照代次标识 */
|
|
189
|
-
generationId?: string;
|
|
174
|
+
/** 仅支持当前包局部 Action 的动态解析委托函数 */
|
|
175
|
+
actionResolver?: LocalActionResolver;
|
|
190
176
|
/**
|
|
191
177
|
* 是否以数据目录持有者身份打开存储:true 时构造阶段收割遗留非终态运行记录。
|
|
192
|
-
* 默认 true(
|
|
178
|
+
* 默认 true(PackageRuntime 主路径即持有者);外部工具创建旁观视图时置 false。
|
|
193
179
|
*/
|
|
194
180
|
recoverOrphans?: boolean;
|
|
195
181
|
/** 临时配置覆写字典 */
|
|
@@ -202,8 +188,8 @@ export interface ActionDockAppOptions {
|
|
|
202
188
|
maxCallDepth?: number;
|
|
203
189
|
/** 最大子任务数限制 */
|
|
204
190
|
maxSubRuns?: number;
|
|
205
|
-
/**
|
|
206
|
-
|
|
191
|
+
/** 显式注入的运行时平台适配 */
|
|
192
|
+
platform?: RuntimePlatform;
|
|
207
193
|
/** 日志记录器 */
|
|
208
194
|
logger?: Logger;
|
|
209
195
|
/** 时钟源 */
|
|
@@ -214,11 +200,34 @@ export interface ActionDockAppOptions {
|
|
|
214
200
|
exposeDebugInfo?: boolean;
|
|
215
201
|
}
|
|
216
202
|
/**
|
|
217
|
-
*
|
|
218
|
-
*
|
|
203
|
+
* PackageRuntime 内部装配选项(框架内部接线与依赖注入)。
|
|
204
|
+
*
|
|
205
|
+
* 普通公开 API 仅暴露 PackageRuntimeOptions,此选项仅在 Host 容器或核心测试装配时使用。
|
|
219
206
|
*/
|
|
220
|
-
export interface
|
|
221
|
-
/**
|
|
207
|
+
export interface PackageRuntimeInternalOptions extends PackageRuntimeOptions {
|
|
208
|
+
/** 显式注入的包物理与快照身份标识值对象 */
|
|
209
|
+
identity?: PackageIdentity;
|
|
210
|
+
/** 显式注入的项目级运行时存储实例 */
|
|
211
|
+
storage?: RuntimeStorage;
|
|
212
|
+
/** 显式注入的全局运行时存储实例 */
|
|
213
|
+
globalStorage?: RuntimeStorage;
|
|
214
|
+
/** 显式注入的事件接收器 */
|
|
215
|
+
eventSink?: EventSink;
|
|
216
|
+
/** 子任务动作调用委托器 */
|
|
217
|
+
actionInvoker?: ActionInvoker;
|
|
218
|
+
/** 执行宿主会话标识 */
|
|
219
|
+
hostSessionId?: string;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* 单个 Action Package 的运行时领域契约(PackageRuntime)。
|
|
223
|
+
*
|
|
224
|
+
* 铁律 1 执行主链核心节点:
|
|
225
|
+
* Host -> Resolution -> PackageRuntime -> ExecutionService -> ActionRunner -> Action
|
|
226
|
+
*/
|
|
227
|
+
export interface PackageRuntime {
|
|
228
|
+
/** 包唯一物理与快照身份标识值对象(只在创建时生成一次) */
|
|
229
|
+
readonly identity: PackageIdentity;
|
|
230
|
+
/** 包唯一逻辑标识 */
|
|
222
231
|
readonly packageId: string;
|
|
223
232
|
/** 包物理实例标识 */
|
|
224
233
|
readonly packageInstanceId?: string;
|
|
@@ -228,16 +237,11 @@ export interface ActionDockApp {
|
|
|
228
237
|
readonly packageRoot?: string;
|
|
229
238
|
/** 项目配置对象(actiondock.json 解析结果) */
|
|
230
239
|
readonly projectConfig: ProjectConfig;
|
|
231
|
-
/**
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
readonly globalStorage?: RuntimeStorage;
|
|
237
|
-
/** 统一执行协调服务实例 */
|
|
238
|
-
readonly executionService: ExecutionService;
|
|
239
|
-
/** 预加载的 Action 定义映射表(短标识至定义) */
|
|
240
|
-
readonly actionsMap: Map<string, ActionDefinition>;
|
|
240
|
+
/**
|
|
241
|
+
* 受信任内部调用方法(Host 或子任务执行主链调用入口)。
|
|
242
|
+
* 委托内部 ExecutionService 执行,确保全生命周期指标与事件不发生分裂。
|
|
243
|
+
*/
|
|
244
|
+
startInvocation(actionId: string, input: JsonValue, context: InvocationContext): Promise<ExecutionTicket>;
|
|
241
245
|
/** 获取当前包元数据信息 */
|
|
242
246
|
info(options?: {
|
|
243
247
|
exposeDebugInfo?: boolean;
|
|
@@ -251,13 +255,20 @@ export interface ActionDockApp {
|
|
|
251
255
|
/** 静态查询并返回指定 Playbook 的规范内容与操作指南 */
|
|
252
256
|
describePlaybook(id: string): Promise<PlaybookSpec>;
|
|
253
257
|
/** 同步执行指定 Action 并等待终态结果(仅接受本包短标识) */
|
|
254
|
-
runAction(id: string, input: JsonValue, options?:
|
|
258
|
+
runAction(id: string, input: JsonValue, options?: RunOptions): Promise<ExecutionResult>;
|
|
255
259
|
/** 异步启动指定 Action 并立即返回任务执行票据(仅接受本包短标识) */
|
|
256
|
-
startAction(id: string, input: JsonValue, options?:
|
|
260
|
+
startAction(id: string, input: JsonValue, options?: RunOptions): Promise<ExecutionTicket>;
|
|
261
|
+
/** 查询任务执行记录列表 */
|
|
262
|
+
listRuns(options?: ListRunsOptions): Promise<RunRecord[]>;
|
|
257
263
|
/** 查询指定运行标识的记录详情 */
|
|
258
264
|
getRun(runId: string): Promise<RunRecord | undefined>;
|
|
259
265
|
/** 取消指定在运行的任务 */
|
|
260
266
|
cancelRun(runId: string, reason?: string): Promise<CancelResult>;
|
|
267
|
+
/** 清空历史任务运行记录 */
|
|
268
|
+
clearRuns(options?: {
|
|
269
|
+
actionId?: string;
|
|
270
|
+
status?: string;
|
|
271
|
+
}): Promise<number>;
|
|
261
272
|
/** 订阅指定运行的事件流 */
|
|
262
273
|
events(runId: string, options?: {
|
|
263
274
|
after?: number | string;
|
|
@@ -293,8 +304,16 @@ export interface ActionDockApp {
|
|
|
293
304
|
/** 清空指定持久化状态项 */
|
|
294
305
|
clearState(options?: StateScopeOptions): Promise<number>;
|
|
295
306
|
clearState(actionId: string, options?: StateScopeOptions): Promise<number>;
|
|
307
|
+
/** 列出当前包在存储中的状态条目(含完整元数据) */
|
|
308
|
+
listStateEntries?(options?: any): Promise<StateEntry[]>;
|
|
296
309
|
/** 优雅关闭应用并收尾清理所有底层资源 */
|
|
297
310
|
close(options?: {
|
|
298
311
|
graceMs?: number;
|
|
299
312
|
}): Promise<void>;
|
|
300
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* 宿主托管专用内部运行时契约。
|
|
316
|
+
*/
|
|
317
|
+
export interface HostManagedPackageRuntime extends PackageRuntime {
|
|
318
|
+
setActionInvoker(invoker?: ActionInvoker): void;
|
|
319
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 对 Action 摘要列表应用统一的检索过滤(标签、模糊关键词与标识前缀)。
|
|
3
|
+
*
|
|
4
|
+
* PackageRuntime 与 Host 两级列表查询的单一事实源:
|
|
5
|
+
* 两处过滤块逐字相同,收敛后调用方仅需在外层叠加各自的特有逻辑
|
|
6
|
+
* (Host 版在过滤前额外完成可见性筛选与跨包限定名改写)。
|
|
7
|
+
*/
|
|
8
|
+
export function applyActionSummaryFilters(summaries, options) {
|
|
9
|
+
let results = summaries;
|
|
10
|
+
if (options?.tags && options.tags.length > 0) {
|
|
11
|
+
results = results.filter((s) => options.tags.every((t) => s.tags?.includes(t)));
|
|
12
|
+
}
|
|
13
|
+
if (options?.query) {
|
|
14
|
+
const q = options.query.toLowerCase();
|
|
15
|
+
results = results.filter((s) => s.id.toLowerCase().includes(q) ||
|
|
16
|
+
(s.description && s.description.toLowerCase().includes(q)));
|
|
17
|
+
}
|
|
18
|
+
if (options?.prefix) {
|
|
19
|
+
results = results.filter((s) => s.id.startsWith(options.prefix));
|
|
20
|
+
}
|
|
21
|
+
return results;
|
|
22
|
+
}
|
package/dist/platform/index.d.ts
CHANGED
package/dist/platform/index.js
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ProcessAPI } from "@actiondock/sdk";
|
|
2
|
+
import { type Clock } from "../runtime/clock.js";
|
|
3
|
+
import { type ModuleLoader } from "../node/module-loader.js";
|
|
4
|
+
import { ProcessManager } from "../process/process-manager.js";
|
|
5
|
+
import type { ProcessDriver } from "../process/driver.js";
|
|
6
|
+
import { type SqliteDriver } from "../storage/index.js";
|
|
7
|
+
import type { FileSystem, RuntimePlatform, StorageFactory } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Node 平台构建配置选项。
|
|
10
|
+
*/
|
|
11
|
+
export interface NodePlatformOptions {
|
|
12
|
+
/** 平台名称覆盖(默认使用 node) */
|
|
13
|
+
name?: "node" | "test";
|
|
14
|
+
/** 自定义全局数据存储目录 */
|
|
15
|
+
dataDir?: string;
|
|
16
|
+
/** 自定义家目录路径 */
|
|
17
|
+
customHome?: string;
|
|
18
|
+
/** 文件系统安全沙箱根路径 */
|
|
19
|
+
rootDir?: string;
|
|
20
|
+
/** 自定义 SQLite 驱动工厂函数(必须返回满足同步契约的 SqliteDriver,默认实例化 NodeSqliteDriver) */
|
|
21
|
+
driverFactory?: (dbPath: string) => SqliteDriver;
|
|
22
|
+
/** 自定义进程执行驱动(默认依托基于 NodeProcessDriver 的 ProcessManager) */
|
|
23
|
+
process?: ProcessAPI;
|
|
24
|
+
/** 可选注入的底层进程驱动 */
|
|
25
|
+
processDriver?: ProcessDriver;
|
|
26
|
+
/** 可选注入的受管进程管理器 */
|
|
27
|
+
processManager?: ProcessManager;
|
|
28
|
+
/** 自定义源码加载驱动(默认实例化 NodeModuleLoader) */
|
|
29
|
+
modules?: ModuleLoader;
|
|
30
|
+
/** 自定义文件系统实现(默认实例化 NodeFileSystem) */
|
|
31
|
+
files?: FileSystem;
|
|
32
|
+
/** 自定义时钟驱动(默认实例化 SystemClock) */
|
|
33
|
+
clock?: Clock;
|
|
34
|
+
/** 自定义存储工厂(默认基于 NodeSqliteDriver 构造) */
|
|
35
|
+
storage?: StorageFactory;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 创建 Node 运行时平台实例。
|
|
39
|
+
* 组装 Node 原生核心组件:
|
|
40
|
+
* - NodeSqliteDriver 同步持久化存储驱动
|
|
41
|
+
* - NodeProcessDriver 原生进程驱动与 ProcessManager 受管进程引擎
|
|
42
|
+
* - NodeModuleLoader 原生源码加载器
|
|
43
|
+
* - NodeFileSystem 文件系统
|
|
44
|
+
* - SystemClock 系统时钟
|
|
45
|
+
*
|
|
46
|
+
* @param options 平台配置选项
|
|
47
|
+
*/
|
|
48
|
+
export declare function createNodePlatform(options?: NodePlatformOptions): RuntimePlatform;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { SystemClock } from "../runtime/clock.js";
|
|
4
|
+
import { NodeModuleLoader } from "../node/module-loader.js";
|
|
5
|
+
import { NodeProcessDriver } from "../process/process-driver.js";
|
|
6
|
+
import { ProcessManager } from "../process/process-manager.js";
|
|
7
|
+
import { NodeSqliteDriver } from "../storage/sqlite-driver.js";
|
|
8
|
+
import { resolveDatabasePath, resolveGlobalDatabasePath, SqliteRuntimeStorage, } from "../storage/index.js";
|
|
9
|
+
import { NodeFileSystem } from "./node-fs.js";
|
|
10
|
+
function ensureDirectoryForDb(dbPath) {
|
|
11
|
+
if (dbPath !== ":memory:") {
|
|
12
|
+
const dir = dirname(dbPath);
|
|
13
|
+
if (!existsSync(dir)) {
|
|
14
|
+
try {
|
|
15
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
if (err?.code === "EEXIST" || err?.code === "EISDIR") {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`Failed to create data directory '${dir}' for database '${dbPath}': ${err?.message || String(err)}`, { cause: err });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 创建 Node 运行时平台实例。
|
|
28
|
+
* 组装 Node 原生核心组件:
|
|
29
|
+
* - NodeSqliteDriver 同步持久化存储驱动
|
|
30
|
+
* - NodeProcessDriver 原生进程驱动与 ProcessManager 受管进程引擎
|
|
31
|
+
* - NodeModuleLoader 原生源码加载器
|
|
32
|
+
* - NodeFileSystem 文件系统
|
|
33
|
+
* - SystemClock 系统时钟
|
|
34
|
+
*
|
|
35
|
+
* @param options 平台配置选项
|
|
36
|
+
*/
|
|
37
|
+
export function createNodePlatform(options = {}) {
|
|
38
|
+
const platformName = options.name ?? "node";
|
|
39
|
+
const clock = options.clock ?? new SystemClock();
|
|
40
|
+
const files = options.files ?? new NodeFileSystem({ rootDir: options.rootDir });
|
|
41
|
+
const modules = options.modules ?? new NodeModuleLoader();
|
|
42
|
+
const processDriver = options.processDriver ?? new NodeProcessDriver();
|
|
43
|
+
const processManager = options.processManager ?? new ProcessManager({ driver: processDriver });
|
|
44
|
+
const process = options.process ??
|
|
45
|
+
processManager.forOwner({
|
|
46
|
+
tenantId: "default",
|
|
47
|
+
principalId: "default",
|
|
48
|
+
packageInstanceId: "default",
|
|
49
|
+
generationId: "default",
|
|
50
|
+
});
|
|
51
|
+
const createDriver = options.driverFactory ?? ((dbPath) => new NodeSqliteDriver(dbPath));
|
|
52
|
+
const storage = options.storage ?? {
|
|
53
|
+
createStorage(packageId, opts) {
|
|
54
|
+
const mergedOpts = {
|
|
55
|
+
customHome: options.customHome,
|
|
56
|
+
dataDir: options.dataDir,
|
|
57
|
+
...opts,
|
|
58
|
+
};
|
|
59
|
+
const dbPath = resolveDatabasePath(packageId, mergedOpts);
|
|
60
|
+
ensureDirectoryForDb(dbPath);
|
|
61
|
+
return new SqliteRuntimeStorage({
|
|
62
|
+
dbPath,
|
|
63
|
+
packageId,
|
|
64
|
+
clock,
|
|
65
|
+
driver: createDriver(dbPath),
|
|
66
|
+
recoverOrphans: opts?.recoverOrphans === true,
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
createGlobalStorage(opts) {
|
|
70
|
+
const mergedOpts = {
|
|
71
|
+
customHome: options.customHome,
|
|
72
|
+
dataDir: options.dataDir,
|
|
73
|
+
...opts,
|
|
74
|
+
};
|
|
75
|
+
const dbPath = mergedOpts.inMemory
|
|
76
|
+
? ":memory:"
|
|
77
|
+
: resolveGlobalDatabasePath({ dataDir: mergedOpts.dataDir, customHome: mergedOpts.customHome });
|
|
78
|
+
ensureDirectoryForDb(dbPath);
|
|
79
|
+
return new SqliteRuntimeStorage({
|
|
80
|
+
dbPath,
|
|
81
|
+
packageId: "__global__",
|
|
82
|
+
clock,
|
|
83
|
+
driver: createDriver(dbPath),
|
|
84
|
+
recoverOrphans: opts?.recoverOrphans === true,
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
name: platformName,
|
|
90
|
+
clock,
|
|
91
|
+
files,
|
|
92
|
+
modules,
|
|
93
|
+
process,
|
|
94
|
+
storage,
|
|
95
|
+
};
|
|
96
|
+
}
|
package/dist/platform/types.d.ts
CHANGED
|
@@ -82,15 +82,6 @@ export interface StorageFactory {
|
|
|
82
82
|
*/
|
|
83
83
|
createGlobalStorage(options?: GlobalStorageFactoryOptions): RuntimeStorage;
|
|
84
84
|
}
|
|
85
|
-
/**
|
|
86
|
-
* 跨运行时 HTTP 服务启动工厂契约。
|
|
87
|
-
*/
|
|
88
|
-
export interface HttpServerFactory {
|
|
89
|
-
/**
|
|
90
|
-
* 启动 HTTP 服务端实例。
|
|
91
|
-
*/
|
|
92
|
-
launchHttpServer(options: any): Promise<any>;
|
|
93
|
-
}
|
|
94
85
|
/**
|
|
95
86
|
* 运行时底层环境核心标准契约。
|
|
96
87
|
* 提供统一的运行时契约,屏蔽宿主平台与测试沙箱环境的实现差异。
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ControlGrant } from "@actiondock/sdk";
|
|
2
|
+
import { type ErrorCode } from "../errors.js";
|
|
2
3
|
import type { ManagedProcessRecord, ProcessOwner } from "./managed-record.js";
|
|
3
4
|
import type { StoredProcessRecord } from "./metadata-store.js";
|
|
4
5
|
/**
|
|
@@ -97,7 +98,7 @@ export declare class ControlArbiter {
|
|
|
97
98
|
* 禁止直接操作 acquireWaiters 数组。
|
|
98
99
|
*/
|
|
99
100
|
revokeAllWaiters(proc: ManagedProcessRecord, reason: {
|
|
100
|
-
code:
|
|
101
|
+
code: ErrorCode;
|
|
101
102
|
message: string;
|
|
102
103
|
}): void;
|
|
103
104
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
1
|
import { ACCESS_DENIED, CONTROL_BUSY, CONTROL_EXPIRED, CONTROL_REVOKED, PROCESS_QUARANTINED, QUOTA_EXCEEDED, ProcessError, } from "../errors.js";
|
|
3
2
|
/**
|
|
4
3
|
* 控制权仲裁器。
|
|
@@ -103,7 +102,7 @@ export class ControlArbiter {
|
|
|
103
102
|
*/
|
|
104
103
|
grantControl(proc, requestId, ttlMs, runId) {
|
|
105
104
|
proc.controlEpoch += 1;
|
|
106
|
-
const token = `tok_${proc.info.id}_${proc.controlEpoch}_${randomUUID().replace(/-/g, "")}`;
|
|
105
|
+
const token = `tok_${proc.info.id}_${proc.controlEpoch}_${crypto.randomUUID().replace(/-/g, "")}`;
|
|
107
106
|
const expiresAt = new Date(Date.now() + ttlMs).toISOString();
|
|
108
107
|
proc.info.control = "held";
|
|
109
108
|
proc.currentGrant = {
|
package/dist/process/driver.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ import type { Capabilities, LaunchSpec } from "@actiondock/sdk";
|
|
|
3
3
|
* 进程驱动实例底层控制句柄接口。
|
|
4
4
|
*/
|
|
5
5
|
export interface ProcessDriverHandle {
|
|
6
|
+
/**
|
|
7
|
+
* 进程系统标识符(若底层为操作系统子进程)。
|
|
8
|
+
*/
|
|
9
|
+
pid?: number;
|
|
6
10
|
/**
|
|
7
11
|
* 向受管进程标准输入通道写入原始字节数据。
|
|
8
12
|
*
|
|
@@ -82,6 +86,8 @@ export declare function resolveProcessEnv(envConfig?: LaunchSpec["env"], hostEnv
|
|
|
82
86
|
* 进程观察者接口,接收来自底层驱动的流输出与生命周期通知。
|
|
83
87
|
*/
|
|
84
88
|
export interface ProcessObserver {
|
|
89
|
+
/** 期望关联的受管进程标识(若有) */
|
|
90
|
+
processId?: string;
|
|
85
91
|
/**
|
|
86
92
|
* 接收来自进程的输出数据。
|
|
87
93
|
*
|
|
@@ -135,10 +141,6 @@ export interface ProcessDriver {
|
|
|
135
141
|
* @param observer 进程生命周期与输出观察者
|
|
136
142
|
*/
|
|
137
143
|
spawn(spec: LaunchSpec, observer: ProcessObserver): Promise<ProcessHandle>;
|
|
138
|
-
/**
|
|
139
|
-
* 兼容旧版基于 processId 派生新进程签名。
|
|
140
|
-
*/
|
|
141
|
-
spawn(processId: string, spec: LaunchSpec, callbacks: ProcessDriverCallbacks): Promise<ProcessDriverHandle>;
|
|
142
144
|
/**
|
|
143
145
|
* 向受管进程标准输入写入字节数据。
|
|
144
146
|
*
|
|
@@ -162,7 +164,6 @@ export interface ProcessDriver {
|
|
|
162
164
|
* 优雅终止或强制终止底层进程。
|
|
163
165
|
*/
|
|
164
166
|
terminate(handle: ProcessHandle, graceMs: number): Promise<void>;
|
|
165
|
-
terminate(processId: string, graceMs: number): Promise<void>;
|
|
166
167
|
/**
|
|
167
168
|
* 销毁进程句柄并清理关联资源。
|
|
168
169
|
*/
|
|
@@ -174,12 +175,12 @@ export interface ProcessDriver {
|
|
|
174
175
|
export declare class MemoryProcessDriver implements ProcessDriver {
|
|
175
176
|
private capabilities;
|
|
176
177
|
handles: Map<string, MemoryProcessDriverHandle>;
|
|
177
|
-
spawnHook?: (
|
|
178
|
+
spawnHook?: (spec: LaunchSpec, observer: ProcessObserver) => Promise<MemoryProcessDriverHandle | void> | MemoryProcessDriverHandle | void;
|
|
178
179
|
constructor(capabilities?: Partial<Capabilities>);
|
|
179
180
|
getCapabilities(): Capabilities;
|
|
180
181
|
setCapabilities(caps: Partial<Capabilities>): void;
|
|
181
|
-
spawn(
|
|
182
|
-
terminate(
|
|
182
|
+
spawn(spec: LaunchSpec, observer: ProcessObserver): Promise<ProcessHandle>;
|
|
183
|
+
terminate(handle: ProcessHandle, graceMs: number): Promise<void>;
|
|
183
184
|
}
|
|
184
185
|
/**
|
|
185
186
|
* 内存模拟进程驱动句柄实现。
|
package/dist/process/driver.js
CHANGED
|
@@ -93,25 +93,15 @@ export class MemoryProcessDriver {
|
|
|
93
93
|
setCapabilities(caps) {
|
|
94
94
|
this.capabilities = { ...this.capabilities, ...caps };
|
|
95
95
|
}
|
|
96
|
-
async spawn(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (customHandle) {
|
|
104
|
-
this.handles.set(processId, customHandle);
|
|
105
|
-
return customHandle;
|
|
106
|
-
}
|
|
96
|
+
async spawn(spec, observer) {
|
|
97
|
+
const processId = observer.processId ?? `mem-${Math.random().toString(36).slice(2, 10)}`;
|
|
98
|
+
if (this.spawnHook) {
|
|
99
|
+
const customHandle = await this.spawnHook(spec, observer);
|
|
100
|
+
if (customHandle) {
|
|
101
|
+
this.handles.set(customHandle.id, customHandle);
|
|
102
|
+
return customHandle;
|
|
107
103
|
}
|
|
108
|
-
const handle = new MemoryProcessDriverHandle(processId, spec, callbacks);
|
|
109
|
-
this.handles.set(processId, handle);
|
|
110
|
-
return handle;
|
|
111
104
|
}
|
|
112
|
-
const spec = specOrProcessId;
|
|
113
|
-
const observer = observerOrSpec;
|
|
114
|
-
const processId = `mem-${Math.random().toString(36).slice(2, 10)}`;
|
|
115
105
|
const callbacks = {
|
|
116
106
|
onOutput(stream, data) {
|
|
117
107
|
observer.output(stream, data);
|
|
@@ -130,11 +120,10 @@ export class MemoryProcessDriver {
|
|
|
130
120
|
this.handles.set(processId, handle);
|
|
131
121
|
return handle;
|
|
132
122
|
}
|
|
133
|
-
async terminate(
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
await handle.terminate(graceMs);
|
|
123
|
+
async terminate(handle, graceMs) {
|
|
124
|
+
const instance = this.handles.get(handle.id);
|
|
125
|
+
if (instance) {
|
|
126
|
+
await instance.terminate(graceMs);
|
|
138
127
|
}
|
|
139
128
|
}
|
|
140
129
|
}
|
package/dist/process/index.d.ts
CHANGED
package/dist/process/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ControlGrant, Limits, OperationReceipt, ProcessControlAction, ProcessInfo } from "@actiondock/sdk";
|
|
2
|
-
import type { ProcessDriverHandle } from "./driver.js";
|
|
2
|
+
import type { ProcessDriverHandle, ProcessHandle } from "./driver.js";
|
|
3
3
|
import type { ProcessRequestKey } from "./metadata-store.js";
|
|
4
4
|
import type { ProcessOutputLog } from "./output-log.js";
|
|
5
5
|
import type { EvictedOutputTombstone } from "./terminal-output-cache.js";
|
|
@@ -50,7 +50,7 @@ export interface ManagedProcessRecord {
|
|
|
50
50
|
info: ProcessInfo;
|
|
51
51
|
owner: ProcessOwner;
|
|
52
52
|
scope: string;
|
|
53
|
-
handle?: ProcessDriverHandle;
|
|
53
|
+
handle?: ProcessHandle & ProcessDriverHandle;
|
|
54
54
|
outputLog: ProcessOutputLog;
|
|
55
55
|
outputUnavailable?: boolean;
|
|
56
56
|
outputTombstone?: EvictedOutputTombstone;
|