@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
package/dist/server/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ActionDockTarget } from "../target/types.js";
|
|
1
|
+
import type { ActionDockService } from "../service/types.js";
|
|
3
2
|
export interface CoreHttpServerInstance {
|
|
4
3
|
port: number;
|
|
5
4
|
stop: (closeActiveConnections?: boolean) => void | Promise<void>;
|
|
@@ -19,26 +18,52 @@ export interface ServerTlsOptions {
|
|
|
19
18
|
/** 私钥密码口令(若私钥被密码加密) */
|
|
20
19
|
passphrase?: string;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
/**
|
|
22
|
+
* 单个虚拟投影视图(Virtual View)的配置选项。
|
|
23
|
+
*/
|
|
24
|
+
export interface ServerViewOptions {
|
|
25
|
+
/** 视图唯一标识名称(若在 views 对象中配置则键名作为默认名称) */
|
|
26
|
+
name?: string;
|
|
27
|
+
/** 该视图独立的 Bearer Token 鉴权令牌 */
|
|
28
|
+
token?: string;
|
|
29
|
+
/** 该视图允许访问执行的 Package ID 白名单列表(为空允许全部) */
|
|
30
|
+
packageAllowlist?: string[];
|
|
31
|
+
/** 该视图允许访问执行的 Action 标识白名单列表(为空允许全部,支持短名或 packageId/actionId) */
|
|
32
|
+
actionAllowlist?: string[];
|
|
33
|
+
/** 该视图是否开启配置与状态管理路由能力(默认关闭) */
|
|
34
|
+
enableManagement?: boolean;
|
|
35
|
+
/** 该视图是否启用一体化 MCP 协议支持(默认开启) */
|
|
36
|
+
enableMcp?: boolean;
|
|
37
|
+
/** 该视图自定义的 MCP 请求处理器钩子(可选,支持请求处理函数或接收视图策略的工厂函数) */
|
|
38
|
+
mcpHandler?: ((req: Request, view?: EffectiveServerPolicy) => Promise<Response | null | undefined> | Response | null | undefined) | ((view: EffectiveServerPolicy) => ((req: Request) => Promise<Response | null | undefined> | Response | null | undefined));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 当前请求上下文生效的统一服务端安全策略。
|
|
42
|
+
*/
|
|
43
|
+
export interface EffectiveServerPolicy {
|
|
44
|
+
/** 当前生效的视图名称(默认视图为 "default") */
|
|
45
|
+
viewName?: string;
|
|
46
|
+
/** 当前生效的 Bearer Token 鉴权令牌 */
|
|
47
|
+
token?: string;
|
|
48
|
+
/** 当前生效的 Package ID 白名单列表 */
|
|
49
|
+
packageAllowlist?: string[];
|
|
50
|
+
/** 当前生效的 Action 标识白名单列表 */
|
|
51
|
+
actionAllowlist?: string[];
|
|
52
|
+
/** 当前生效的管理能力开关 */
|
|
53
|
+
enableManagement?: boolean;
|
|
54
|
+
}
|
|
28
55
|
/**
|
|
29
56
|
* 启动 ActionDock HTTP Runner 服务端的配置选项。
|
|
30
57
|
*/
|
|
31
58
|
export interface ServerOptions {
|
|
32
59
|
/** 监听端口号(默认 5177) */
|
|
33
60
|
port?: number;
|
|
34
|
-
/** 绑定监听的主机地址(默认 "127.0.0.1"
|
|
35
|
-
host?: string | ActionDockHost;
|
|
36
|
-
/** 显式绑定的 ActionDockHost 宿主实例(向前兼容别名) */
|
|
37
|
-
hostInstance?: ActionDockHost;
|
|
38
|
-
/** 关联的目标 ActionDockTarget 门面实例 */
|
|
39
|
-
target?: ActionDockTarget;
|
|
40
|
-
/** 显式绑定的主机地址(当 host 传入 ActionDockHost 时的可选覆盖项) */
|
|
61
|
+
/** 绑定监听的主机地址(默认 "127.0.0.1") */
|
|
41
62
|
hostname?: string;
|
|
63
|
+
/** 绑定监听的主机地址(hostname 的字符串别名) */
|
|
64
|
+
host?: string;
|
|
65
|
+
/** 关联的标准 ActionDockService 服务端口实例 */
|
|
66
|
+
service?: ActionDockService;
|
|
42
67
|
/** 用于 HTTP Bearer Token 鉴权的密钥令牌 */
|
|
43
68
|
token?: string;
|
|
44
69
|
/** 是否允许通过 URL 查询参数携带 Token 进行鉴权(默认 false,关闭以防泄露) */
|
|
@@ -57,14 +82,18 @@ export interface ServerOptions {
|
|
|
57
82
|
corsOrigins?: string[];
|
|
58
83
|
/** 允许访问执行的 Package ID 白名单列表(为空允许全部) */
|
|
59
84
|
packageAllowlist?: string[];
|
|
85
|
+
/** 允许访问执行的 Action 标识白名单列表(为空允许全部,支持短名或 packageId/actionId) */
|
|
86
|
+
actionAllowlist?: string[];
|
|
60
87
|
/** 最大允许的请求体字节限制(默认 1MB,防 DoS) */
|
|
61
88
|
maxBodyBytes?: number;
|
|
62
89
|
/** 是否在 health 和 info 接口中透传本地 projectRoot 等调试路径 */
|
|
63
90
|
exposeDebugInfo?: boolean;
|
|
64
91
|
/** 是否启用一体化 MCP 协议支持(默认开启) */
|
|
65
92
|
enableMcp?: boolean;
|
|
66
|
-
/** 自定义 MCP 请求处理器钩子(若挂载则 /mcp
|
|
67
|
-
mcpHandler?: (req: Request) => Promise<Response | null | undefined> | Response | null | undefined;
|
|
93
|
+
/** 自定义 MCP 请求处理器钩子(若挂载则 /mcp 路由交由其处理,支持处理函数或接收视图策略的工厂函数) */
|
|
94
|
+
mcpHandler?: ((req: Request, view?: EffectiveServerPolicy) => Promise<Response | null | undefined> | Response | null | undefined) | ((view: EffectiveServerPolicy) => ((req: Request) => Promise<Response | null | undefined> | Response | null | undefined));
|
|
95
|
+
/** 自定义 MCP 处理器工厂函数(可选,为每个视图创建独立处理器) */
|
|
96
|
+
mcpHandlerFactory?: (view: EffectiveServerPolicy) => ((req: Request) => Promise<Response | null | undefined> | Response | null | undefined);
|
|
68
97
|
/** 可选注入的统一运行时底层平台 */
|
|
69
98
|
platform?: import("../platform/types.js").RuntimePlatform;
|
|
70
99
|
/** 是否显式开启配置与状态管理路由能力(默认关闭,关闭时返回 403) */
|
|
@@ -73,6 +102,26 @@ export interface ServerOptions {
|
|
|
73
102
|
scanLinkedPackages?: boolean;
|
|
74
103
|
/** 服务端 TLS/HTTPS 安全传输选项 */
|
|
75
104
|
tls?: ServerTlsOptions;
|
|
105
|
+
/**
|
|
106
|
+
* 虚拟投影视图配置。
|
|
107
|
+
* 支持对象字典形式 Record<string, ServerViewOptions> 或数组形式 ServerViewOptions[]。
|
|
108
|
+
* 单端口上支持多视图独立隔离 Token、白名单与管理权限。
|
|
109
|
+
*/
|
|
110
|
+
views?: Record<string, ServerViewOptions> | ServerViewOptions[];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 路由处理统一上下文对象。
|
|
114
|
+
*/
|
|
115
|
+
export interface RouteContext {
|
|
116
|
+
req: Request;
|
|
117
|
+
url: URL;
|
|
118
|
+
pathname: string;
|
|
119
|
+
corsHeaders: Record<string, string>;
|
|
120
|
+
projectRoot: string | null;
|
|
121
|
+
customHome?: string;
|
|
122
|
+
service: ActionDockService;
|
|
123
|
+
options: ServerOptions;
|
|
124
|
+
activePolicy: EffectiveServerPolicy;
|
|
76
125
|
}
|
|
77
126
|
/**
|
|
78
127
|
* 已启动的 ActionDock HTTP Runner 实例句柄。
|
|
@@ -80,10 +129,8 @@ export interface ServerOptions {
|
|
|
80
129
|
export interface ActionDockServerInstance {
|
|
81
130
|
/** 实际监听的端口号 */
|
|
82
131
|
port: number;
|
|
83
|
-
/** 关联的
|
|
84
|
-
|
|
85
|
-
/** 关联的 ActionDockTarget 目标门面实例 */
|
|
86
|
-
target?: ActionDockTarget;
|
|
132
|
+
/** 关联的 ActionDockService 服务端口实例 */
|
|
133
|
+
service: ActionDockService;
|
|
87
134
|
/** 服务端可访问的基础 URL(如 "http://127.0.0.1:5177") */
|
|
88
135
|
url: string;
|
|
89
136
|
/** 服务就绪 Promise(可等待端口解析与监听建立) */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RemoteActionDockService } from "./remote.js";
|
|
2
|
+
import type { ActionDockService, ConnectActionDockOptions, CreateActionDockOptions, RemoteServiceOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* 工厂函数:创建本地 ActionDock 服务实例。
|
|
5
|
+
* 遵循标准 Service Ports 体系,屏蔽底层多包协调或单包存储细节。
|
|
6
|
+
*/
|
|
7
|
+
export declare function createActionDock(options?: CreateActionDockOptions): Promise<ActionDockService>;
|
|
8
|
+
/**
|
|
9
|
+
* 工厂函数:连接远端 ActionDock 服务实例。
|
|
10
|
+
* 支持传入目标 HTTP 根地址、Profile 别名或完整连接配置选项。
|
|
11
|
+
*/
|
|
12
|
+
export declare function connectActionDock(urlOrProfile: string | RemoteServiceOptions, options?: ConnectActionDockOptions): Promise<RemoteActionDockService>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createActionDockHost } from "../host/host.js";
|
|
2
|
+
import { LocalActionDockService } from "./local.js";
|
|
3
|
+
import { RemoteActionDockService } from "./remote.js";
|
|
4
|
+
import { ActionDockError, INVALID_ARGUMENT, NOT_FOUND } from "../errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* 工厂函数:创建本地 ActionDock 服务实例。
|
|
7
|
+
* 遵循标准 Service Ports 体系,屏蔽底层多包协调或单包存储细节。
|
|
8
|
+
*/
|
|
9
|
+
export async function createActionDock(options = {}) {
|
|
10
|
+
if (options.runtimeOptions) {
|
|
11
|
+
const inMemory = options.inMemory ?? options.runtimeOptions.inMemory;
|
|
12
|
+
const host = await createActionDockHost({
|
|
13
|
+
packages: [options.runtimeOptions],
|
|
14
|
+
autoLoadCurrentProject: false,
|
|
15
|
+
scanLinkedPackages: false,
|
|
16
|
+
inMemory,
|
|
17
|
+
dataDir: options.dataDir ?? options.runtimeOptions.dataDir,
|
|
18
|
+
customHome: options.customHome ?? options.runtimeOptions.customHome,
|
|
19
|
+
platform: options.platform ?? options.runtimeOptions.platform,
|
|
20
|
+
clock: options.runtimeOptions.clock,
|
|
21
|
+
process: options.runtimeOptions.process,
|
|
22
|
+
logger: options.runtimeOptions.logger,
|
|
23
|
+
recoverOrphans: options.recoverOrphans,
|
|
24
|
+
});
|
|
25
|
+
return new LocalActionDockService(host, { enableManagement: options.enableManagement });
|
|
26
|
+
}
|
|
27
|
+
const host = await createActionDockHost({
|
|
28
|
+
scanLinkedPackages: options.scanLinkedPackages ?? true,
|
|
29
|
+
...options,
|
|
30
|
+
recoverOrphans: options.recoverOrphans ?? true,
|
|
31
|
+
...(options.hostOptions || {}),
|
|
32
|
+
});
|
|
33
|
+
return new LocalActionDockService(host, { enableManagement: options.enableManagement });
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 工厂函数:连接远端 ActionDock 服务实例。
|
|
37
|
+
* 支持传入目标 HTTP 根地址、Profile 别名或完整连接配置选项。
|
|
38
|
+
*/
|
|
39
|
+
export async function connectActionDock(urlOrProfile, options) {
|
|
40
|
+
let targetUrl;
|
|
41
|
+
let token = options?.token;
|
|
42
|
+
let insecure = options?.insecure;
|
|
43
|
+
let allowInsecureHttp = options?.allowInsecureHttp;
|
|
44
|
+
let dispatcher = options?.dispatcher;
|
|
45
|
+
let timeoutMs = options?.timeoutMs;
|
|
46
|
+
let baseTimeoutMs = options?.baseTimeoutMs;
|
|
47
|
+
if (typeof urlOrProfile === "object" && urlOrProfile !== null) {
|
|
48
|
+
targetUrl = urlOrProfile.serverUrl;
|
|
49
|
+
token = urlOrProfile.token ?? token;
|
|
50
|
+
insecure = urlOrProfile.insecure ?? insecure;
|
|
51
|
+
allowInsecureHttp = urlOrProfile.allowInsecureHttp ?? allowInsecureHttp;
|
|
52
|
+
dispatcher = urlOrProfile.dispatcher ?? dispatcher;
|
|
53
|
+
timeoutMs = urlOrProfile.timeoutMs ?? timeoutMs;
|
|
54
|
+
baseTimeoutMs = urlOrProfile.baseTimeoutMs ?? baseTimeoutMs;
|
|
55
|
+
}
|
|
56
|
+
else if (typeof urlOrProfile === "string") {
|
|
57
|
+
if (urlOrProfile.startsWith("http://") || urlOrProfile.startsWith("https://")) {
|
|
58
|
+
targetUrl = urlOrProfile;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const { resolveTarget } = await import("../profile/manager.js");
|
|
62
|
+
const resolved = resolveTarget({ profile: urlOrProfile }, options?.customHome);
|
|
63
|
+
if (resolved.type !== "remote" || !resolved.serverUrl) {
|
|
64
|
+
throw new ActionDockError(NOT_FOUND, `Profile '${urlOrProfile}' not found or is not a remote profile`);
|
|
65
|
+
}
|
|
66
|
+
targetUrl = resolved.serverUrl;
|
|
67
|
+
token = resolved.token ?? token;
|
|
68
|
+
insecure = resolved.insecure ?? insecure;
|
|
69
|
+
allowInsecureHttp = resolved.allowInsecureHttp ?? allowInsecureHttp;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new ActionDockError(INVALID_ARGUMENT, "Invalid urlOrProfile argument for connectActionDock");
|
|
74
|
+
}
|
|
75
|
+
return new RemoteActionDockService({
|
|
76
|
+
serverUrl: targetUrl,
|
|
77
|
+
token,
|
|
78
|
+
insecure,
|
|
79
|
+
allowInsecureHttp,
|
|
80
|
+
dispatcher,
|
|
81
|
+
timeoutMs,
|
|
82
|
+
baseTimeoutMs,
|
|
83
|
+
enableManagement: options?.enableManagement,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PackageInfo } from "../package/types.js";
|
|
2
|
+
import type { ActionDockHost } from "../host/types.js";
|
|
3
|
+
import type { ActionDockService, ConfigPort, DiscoveryPort, EventsPort, ExecutionPort, RunsPort, StatePort } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* 本地 ActionDockService 实现。
|
|
6
|
+
* 遵循标准 Service Ports 体系,面向 ActionDockHost 协调中枢提供结构化服务端口,
|
|
7
|
+
* 严禁暴露 unwrap 穿透到内部领域对象。
|
|
8
|
+
*/
|
|
9
|
+
export declare class LocalActionDockService implements ActionDockService {
|
|
10
|
+
protected readonly host: ActionDockHost;
|
|
11
|
+
readonly discovery: DiscoveryPort;
|
|
12
|
+
readonly execution: ExecutionPort;
|
|
13
|
+
readonly runs: RunsPort;
|
|
14
|
+
readonly events: EventsPort;
|
|
15
|
+
readonly management?: {
|
|
16
|
+
config: ConfigPort;
|
|
17
|
+
state: StatePort;
|
|
18
|
+
};
|
|
19
|
+
constructor(host: ActionDockHost, options?: {
|
|
20
|
+
enableManagement?: boolean;
|
|
21
|
+
});
|
|
22
|
+
info(): Promise<PackageInfo[]>;
|
|
23
|
+
close(options?: {
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
graceMs?: number;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { parseActionRef } from "../catalog/resolve-action.js";
|
|
2
|
+
import { CloseTimeoutError, } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* 本地 ActionDockService 实现。
|
|
5
|
+
* 遵循标准 Service Ports 体系,面向 ActionDockHost 协调中枢提供结构化服务端口,
|
|
6
|
+
* 严禁暴露 unwrap 穿透到内部领域对象。
|
|
7
|
+
*/
|
|
8
|
+
export class LocalActionDockService {
|
|
9
|
+
host;
|
|
10
|
+
discovery;
|
|
11
|
+
execution;
|
|
12
|
+
runs;
|
|
13
|
+
events;
|
|
14
|
+
management;
|
|
15
|
+
constructor(host, options) {
|
|
16
|
+
this.host = host;
|
|
17
|
+
const self = this;
|
|
18
|
+
this.discovery = {
|
|
19
|
+
async listPackages() {
|
|
20
|
+
return self.host.info();
|
|
21
|
+
},
|
|
22
|
+
async listActions(opts) {
|
|
23
|
+
return self.host.listActions(opts);
|
|
24
|
+
},
|
|
25
|
+
async describeAction(ref) {
|
|
26
|
+
return self.host.describeAction(ref);
|
|
27
|
+
},
|
|
28
|
+
async listPlaybooks(opts) {
|
|
29
|
+
return self.host.listPlaybooks(opts);
|
|
30
|
+
},
|
|
31
|
+
async describePlaybook(id) {
|
|
32
|
+
return self.host.describePlaybook(id);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
this.execution = {
|
|
36
|
+
async run(ref, input, opts) {
|
|
37
|
+
const actionRef = typeof ref === "string" ? parseActionRef(ref) : ref;
|
|
38
|
+
const cleanOpts = {
|
|
39
|
+
signal: opts?.signal,
|
|
40
|
+
timeoutMs: opts?.timeoutMs,
|
|
41
|
+
config: opts?.config,
|
|
42
|
+
requestId: opts?.requestId,
|
|
43
|
+
};
|
|
44
|
+
return self.host.runAction(actionRef, (input ?? {}), cleanOpts);
|
|
45
|
+
},
|
|
46
|
+
async start(ref, input, opts) {
|
|
47
|
+
const actionRef = typeof ref === "string" ? parseActionRef(ref) : ref;
|
|
48
|
+
const cleanOpts = {
|
|
49
|
+
signal: opts?.signal,
|
|
50
|
+
timeoutMs: opts?.timeoutMs,
|
|
51
|
+
config: opts?.config,
|
|
52
|
+
requestId: opts?.requestId,
|
|
53
|
+
};
|
|
54
|
+
return self.host.startAction(actionRef, (input ?? {}), cleanOpts);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
this.runs = {
|
|
58
|
+
async list(query) {
|
|
59
|
+
return self.host.listRuns(query);
|
|
60
|
+
},
|
|
61
|
+
async get(runId) {
|
|
62
|
+
return self.host.getRun(runId);
|
|
63
|
+
},
|
|
64
|
+
async cancel(runId, reason) {
|
|
65
|
+
return self.host.cancelRun(runId, reason);
|
|
66
|
+
},
|
|
67
|
+
async clear(opts) {
|
|
68
|
+
return self.host.clearRuns(opts);
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
this.events = {
|
|
72
|
+
events(runId, opts) {
|
|
73
|
+
return self.host.events(runId, opts);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
if (options?.enableManagement !== false) {
|
|
77
|
+
this.management = {
|
|
78
|
+
config: {
|
|
79
|
+
async get(packageId, key) {
|
|
80
|
+
return self.host.getConfig(packageId, key);
|
|
81
|
+
},
|
|
82
|
+
async set(packageId, key, value) {
|
|
83
|
+
return self.host.setConfig(packageId, key, value);
|
|
84
|
+
},
|
|
85
|
+
async delete(packageId, key) {
|
|
86
|
+
return self.host.deleteConfig(packageId, key);
|
|
87
|
+
},
|
|
88
|
+
async list(packageId) {
|
|
89
|
+
return self.host.listConfig(packageId);
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
state: {
|
|
93
|
+
async get(packageId, actionId, key, opts) {
|
|
94
|
+
return self.host.getState(packageId, actionId, key, opts);
|
|
95
|
+
},
|
|
96
|
+
async set(packageId, actionId, key, value, opts) {
|
|
97
|
+
return self.host.setState(packageId, actionId, key, value, opts);
|
|
98
|
+
},
|
|
99
|
+
async delete(packageId, actionId, key, opts) {
|
|
100
|
+
return self.host.deleteState(packageId, actionId, key, opts);
|
|
101
|
+
},
|
|
102
|
+
async list(packageId, actionId, opts) {
|
|
103
|
+
return self.host.listStateKeys(packageId, actionId, opts);
|
|
104
|
+
},
|
|
105
|
+
async clear(packageId, actionId, opts) {
|
|
106
|
+
return self.host.clearState(packageId, actionId, opts);
|
|
107
|
+
},
|
|
108
|
+
async listEntries(packageId, opts) {
|
|
109
|
+
return self.host.listStateEntries(packageId, opts);
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async info() {
|
|
116
|
+
return this.discovery.listPackages();
|
|
117
|
+
}
|
|
118
|
+
async close(options) {
|
|
119
|
+
const timeout = options?.timeoutMs ?? options?.graceMs;
|
|
120
|
+
if (timeout && timeout > 0) {
|
|
121
|
+
let timer;
|
|
122
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
123
|
+
timer = setTimeout(() => {
|
|
124
|
+
reject(new CloseTimeoutError(`Service close operation timed out after ${timeout}ms`));
|
|
125
|
+
}, timeout);
|
|
126
|
+
});
|
|
127
|
+
try {
|
|
128
|
+
await Promise.race([this.host.close(options), timeoutPromise]);
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
if (timer)
|
|
132
|
+
clearTimeout(timer);
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
return this.host.close(options);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -2,20 +2,17 @@
|
|
|
2
2
|
* 远端通信错误翻译层。
|
|
3
3
|
*
|
|
4
4
|
* 职责单一:将 profile/client 传输层抛出的底层异常翻译为统一的
|
|
5
|
-
*
|
|
5
|
+
* 结构化异常,供 RemoteActionDockService 各操作边界复用;
|
|
6
6
|
* 优先读取传输层透传的结构化错误码,无法识别时原样透传。
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* 将远端通信异常包装翻译为统一的异常。
|
|
10
10
|
*
|
|
11
11
|
* 无法识别的异常按防御与透明原则原样抛出,严禁静默吞没。
|
|
12
12
|
*/
|
|
13
13
|
export declare function wrapRemoteError(err: any): never;
|
|
14
14
|
/**
|
|
15
15
|
* 判定远端状态键访问异常是否为键不存在。
|
|
16
|
-
*
|
|
17
|
-
* 优先读取传输层透传的结构化错误码(fetchRemoteJson 会将响应体 error.code
|
|
18
|
-
* 附加到抛出异常的 code 字段),仅当旧版服务器未透传 code 时回退到
|
|
19
|
-
* HTTP 状态与消息文本兼容嗅探。
|
|
16
|
+
* 读取结构化错误码与 HTTP 状态码。
|
|
20
17
|
*/
|
|
21
18
|
export declare function isRemoteStateKeyNotFound(err: any): boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 远端通信错误翻译层。
|
|
3
|
+
*
|
|
4
|
+
* 职责单一:将 profile/client 传输层抛出的底层异常翻译为统一的
|
|
5
|
+
* 结构化异常,供 RemoteActionDockService 各操作边界复用;
|
|
6
|
+
* 优先读取传输层透传的结构化错误码,无法识别时原样透传。
|
|
7
|
+
*/
|
|
8
|
+
import { CAPABILITY_UNAVAILABLE, STATE_KEY_NOT_FOUND } from "../errors.js";
|
|
9
|
+
import { PROTOCOL_UNSUPPORTED, SERVICE_RESULT_UNKNOWN, ServiceError, } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* 将远端通信异常包装翻译为统一的异常。
|
|
12
|
+
*
|
|
13
|
+
* 无法识别的异常按防御与透明原则原样抛出,严禁静默吞没。
|
|
14
|
+
*/
|
|
15
|
+
export function wrapRemoteError(err) {
|
|
16
|
+
const code = err?.code || "";
|
|
17
|
+
if (code === "CAPABILITY_UNAVAILABLE" ||
|
|
18
|
+
code === "TARGET_CAPABILITY_UNAVAILABLE") {
|
|
19
|
+
throw new ServiceError(CAPABILITY_UNAVAILABLE, `CAPABILITY_UNAVAILABLE: Management APIs are not enabled on remote service`, { originalMessage: err?.message });
|
|
20
|
+
}
|
|
21
|
+
if (code === "PROTOCOL_UNSUPPORTED" ||
|
|
22
|
+
code === "TARGET_PROTOCOL_UNSUPPORTED") {
|
|
23
|
+
throw new ServiceError(PROTOCOL_UNSUPPORTED, `PROTOCOL_UNSUPPORTED: ${err?.message || ""}`, { originalMessage: err?.message });
|
|
24
|
+
}
|
|
25
|
+
if (code === "SERVICE_RESULT_UNKNOWN" ||
|
|
26
|
+
code === "TARGET_RESULT_UNKNOWN" ||
|
|
27
|
+
code === "RESULT_UNKNOWN") {
|
|
28
|
+
throw new ServiceError(SERVICE_RESULT_UNKNOWN, `SERVICE_RESULT_UNKNOWN: ${err?.message || ""}`, { originalMessage: err?.message });
|
|
29
|
+
}
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 判定远端状态键访问异常是否为键不存在。
|
|
34
|
+
* 读取结构化错误码与 HTTP 状态码。
|
|
35
|
+
*/
|
|
36
|
+
export function isRemoteStateKeyNotFound(err) {
|
|
37
|
+
return err?.code === STATE_KEY_NOT_FOUND || err?.code === "NOT_FOUND" || err?.status === 404;
|
|
38
|
+
}
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { ExecutionResult, RunRecord } from "@actiondock/sdk";
|
|
9
9
|
/**
|
|
10
|
-
* 轮询依赖上下文:由
|
|
11
|
-
*
|
|
10
|
+
* 轮询依赖上下文:由 RemoteActionDockService 门面注入自身能力,
|
|
11
|
+
* 保持本模块与门面实现解耦。
|
|
12
12
|
*/
|
|
13
13
|
export interface RunPollingContext {
|
|
14
14
|
/** 轮询等待基准底线超时时间(毫秒,默认 60000ms) */
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* 运行详情直至终态、取消或超时上限;并将终态运行记录翻译为统一
|
|
6
6
|
* ExecutionResult 结构。不感知 SSE 通道与门面生命周期。
|
|
7
7
|
*/
|
|
8
|
-
import { ACTION_CANCELLED, EXECUTION_FAILED, TIMEOUT } from "../errors.js";
|
|
8
|
+
import { ACTION_CANCELLED, EXECUTION_FAILED, RUN_INTERRUPTED, TIMEOUT } from "../errors.js";
|
|
9
9
|
import { isTerminalRunStatus } from "../storage/types.js";
|
|
10
|
-
import {
|
|
10
|
+
import { SERVICE_CLOSED } from "./types.js";
|
|
11
11
|
/**
|
|
12
12
|
* 将终态运行记录翻译为统一 ExecutionResult 结构。
|
|
13
13
|
*/
|
|
@@ -20,7 +20,7 @@ export function formatTerminalRunResult(run, runId) {
|
|
|
20
20
|
ok: false,
|
|
21
21
|
runId,
|
|
22
22
|
error: run.error || {
|
|
23
|
-
code:
|
|
23
|
+
code: RUN_INTERRUPTED,
|
|
24
24
|
message: `Run '${runId}' was interrupted`,
|
|
25
25
|
},
|
|
26
26
|
};
|
|
@@ -55,8 +55,8 @@ export async function pollRunCompletion(ctx, runId, signal, timeoutMs, startTime
|
|
|
55
55
|
ok: false,
|
|
56
56
|
runId,
|
|
57
57
|
error: {
|
|
58
|
-
code:
|
|
59
|
-
message: "
|
|
58
|
+
code: SERVICE_CLOSED,
|
|
59
|
+
message: "RemoteActionDockService is closed",
|
|
60
60
|
},
|
|
61
61
|
};
|
|
62
62
|
}
|
|
@@ -77,13 +77,13 @@ export async function pollRunCompletion(ctx, runId, signal, timeoutMs, startTime
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
catch (err) {
|
|
80
|
-
if (err?.code ===
|
|
80
|
+
if (err?.code === SERVICE_CLOSED || ctx.isClosed()) {
|
|
81
81
|
return {
|
|
82
82
|
ok: false,
|
|
83
83
|
runId,
|
|
84
84
|
error: {
|
|
85
|
-
code:
|
|
86
|
-
message: "
|
|
85
|
+
code: SERVICE_CLOSED,
|
|
86
|
+
message: "RemoteActionDockService is closed",
|
|
87
87
|
},
|
|
88
88
|
};
|
|
89
89
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PackageInfo } from "../package/types.js";
|
|
2
|
+
import { type RemoteServiceOptions } from "./types.js";
|
|
3
|
+
import type { ActionDockService, ConfigPort, ConnectActionDockOptions, DiscoveryPort, EventsPort, ExecutionPort, RunsPort, StatePort } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* 远程 ActionDockService 端口实现。
|
|
6
|
+
* 封装与远端 ActionDock 服务的 HTTP / SSE 协议交互,
|
|
7
|
+
* 遵循统一的 Service Ports 契约。
|
|
8
|
+
*/
|
|
9
|
+
export declare class RemoteActionDockService implements ActionDockService {
|
|
10
|
+
readonly serverUrl: string;
|
|
11
|
+
readonly token?: string;
|
|
12
|
+
readonly timeoutMs?: number;
|
|
13
|
+
readonly baseTimeoutMs: number;
|
|
14
|
+
readonly allowInsecureHttp?: boolean;
|
|
15
|
+
readonly insecure?: boolean;
|
|
16
|
+
readonly dispatcher?: unknown;
|
|
17
|
+
private isClosed;
|
|
18
|
+
readonly discovery: DiscoveryPort;
|
|
19
|
+
readonly execution: ExecutionPort;
|
|
20
|
+
readonly runs: RunsPort;
|
|
21
|
+
readonly events: EventsPort;
|
|
22
|
+
readonly management?: {
|
|
23
|
+
config: ConfigPort;
|
|
24
|
+
state: StatePort;
|
|
25
|
+
};
|
|
26
|
+
constructor(options: ConnectActionDockOptions | RemoteServiceOptions);
|
|
27
|
+
private assertNotClosed;
|
|
28
|
+
info(): Promise<PackageInfo[]>;
|
|
29
|
+
private waitForRunCompletion;
|
|
30
|
+
close(_options?: {
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
graceMs?: number;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
}
|