@actiondock/core 2.0.11 → 2.0.12

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.
Files changed (119) hide show
  1. package/dist/build/templates.d.ts +19 -0
  2. package/dist/catalog/action-index.d.ts +9 -0
  3. package/dist/catalog/action-resolver.d.ts +20 -0
  4. package/dist/catalog/location-registry.d.ts +15 -0
  5. package/dist/catalog/package-catalog.d.ts +7 -0
  6. package/dist/catalog/types.d.ts +68 -0
  7. package/dist/doctor/doctor.d.ts +6 -0
  8. package/dist/doctor/types.d.ts +23 -0
  9. package/dist/execution/index.d.ts +2 -0
  10. package/dist/execution/service.d.ts +74 -0
  11. package/dist/execution/types.d.ts +74 -0
  12. package/dist/export/templates.d.ts +33 -0
  13. package/dist/filter/intent.d.ts +33 -0
  14. package/{src/index.ts → dist/index.d.ts} +1 -1
  15. package/dist/index.js +8458 -0
  16. package/dist/profile/client.d.ts +116 -0
  17. package/dist/profile/manager.d.ts +47 -0
  18. package/dist/profile/types.d.ts +61 -0
  19. package/dist/project/closure.d.ts +25 -0
  20. package/{src/project/index.ts → dist/project/index.d.ts} +1 -0
  21. package/dist/project/init.d.ts +27 -0
  22. package/dist/project/loader.d.ts +105 -0
  23. package/dist/project/manifest.d.ts +44 -0
  24. package/dist/project/types.d.ts +131 -0
  25. package/dist/registry/registry.d.ts +24 -0
  26. package/dist/registry/types.d.ts +117 -0
  27. package/dist/runtime/clock.d.ts +21 -0
  28. package/dist/runtime/context.d.ts +75 -0
  29. package/dist/runtime/env.d.ts +54 -0
  30. package/dist/runtime/events.d.ts +61 -0
  31. package/dist/runtime/execution-manager.d.ts +48 -0
  32. package/{src/runtime/index.ts → dist/runtime/index.d.ts} +0 -1
  33. package/dist/runtime/module-loader.d.ts +42 -0
  34. package/dist/runtime/process.d.ts +11 -0
  35. package/dist/runtime/runner.d.ts +186 -0
  36. package/dist/runtime/standalone.d.ts +40 -0
  37. package/dist/schema/validator.d.ts +28 -0
  38. package/dist/server/body.d.ts +40 -0
  39. package/{src/server/index.ts → dist/server/index.d.ts} +0 -1
  40. package/dist/server/routes/actions.d.ts +5 -0
  41. package/dist/server/routes/common.d.ts +36 -0
  42. package/dist/server/routes/config.d.ts +5 -0
  43. package/dist/server/routes/doctor.d.ts +5 -0
  44. package/dist/server/routes/health.d.ts +5 -0
  45. package/dist/server/routes/info.d.ts +5 -0
  46. package/dist/server/routes/playbooks.d.ts +5 -0
  47. package/dist/server/routes/runs.d.ts +5 -0
  48. package/dist/server/routes/state.d.ts +5 -0
  49. package/dist/server/runtime-registry.d.ts +78 -0
  50. package/dist/server/security.d.ts +37 -0
  51. package/dist/server/server.d.ts +15 -0
  52. package/dist/server/types.d.ts +59 -0
  53. package/dist/storage/driver.d.ts +15 -0
  54. package/dist/storage/index.d.ts +44 -0
  55. package/{src/storage/mask.ts → dist/storage/mask.d.ts} +5 -20
  56. package/dist/storage/sqlite.d.ts +66 -0
  57. package/dist/storage/types.d.ts +121 -0
  58. package/dist/utils/index.d.ts +29 -0
  59. package/dist/version.d.ts +4 -0
  60. package/package.json +11 -10
  61. package/src/build/templates.ts +0 -59
  62. package/src/catalog/action-index.ts +0 -92
  63. package/src/catalog/action-resolver.ts +0 -120
  64. package/src/catalog/location-registry.ts +0 -134
  65. package/src/catalog/package-catalog.ts +0 -87
  66. package/src/catalog/types.ts +0 -75
  67. package/src/doctor/doctor.ts +0 -419
  68. package/src/doctor/types.ts +0 -25
  69. package/src/execution/index.ts +0 -2
  70. package/src/execution/service.ts +0 -322
  71. package/src/execution/types.ts +0 -73
  72. package/src/export/templates.ts +0 -590
  73. package/src/filter/intent.ts +0 -154
  74. package/src/profile/client.ts +0 -552
  75. package/src/profile/manager.ts +0 -341
  76. package/src/profile/types.ts +0 -71
  77. package/src/project/init.ts +0 -242
  78. package/src/project/loader.ts +0 -479
  79. package/src/project/manifest.ts +0 -299
  80. package/src/project/types.ts +0 -141
  81. package/src/registry/registry.ts +0 -940
  82. package/src/registry/types.ts +0 -127
  83. package/src/runtime/clock.ts +0 -41
  84. package/src/runtime/context.ts +0 -259
  85. package/src/runtime/env.ts +0 -172
  86. package/src/runtime/events.ts +0 -142
  87. package/src/runtime/execution-manager.ts +0 -74
  88. package/src/runtime/module-loader.ts +0 -67
  89. package/src/runtime/process.ts +0 -245
  90. package/src/runtime/runner.ts +0 -527
  91. package/src/runtime/standalone.ts +0 -429
  92. package/src/schema/validator.ts +0 -61
  93. package/src/server/body.ts +0 -112
  94. package/src/server/routes/actions.ts +0 -262
  95. package/src/server/routes/common.ts +0 -126
  96. package/src/server/routes/config.ts +0 -147
  97. package/src/server/routes/doctor.ts +0 -29
  98. package/src/server/routes/health.ts +0 -40
  99. package/src/server/routes/info.ts +0 -221
  100. package/src/server/routes/playbooks.ts +0 -109
  101. package/src/server/routes/runs.ts +0 -301
  102. package/src/server/routes/state.ts +0 -133
  103. package/src/server/runtime-registry.ts +0 -115
  104. package/src/server/security.ts +0 -115
  105. package/src/server/server.ts +0 -251
  106. package/src/server/types.ts +0 -57
  107. package/src/storage/driver.ts +0 -126
  108. package/src/storage/index.ts +0 -81
  109. package/src/storage/sqlite.ts +0 -714
  110. package/src/storage/types.ts +0 -139
  111. package/src/utils/index.ts +0 -62
  112. /package/{src/build/index.ts → dist/build/index.d.ts} +0 -0
  113. /package/{src/catalog/index.ts → dist/catalog/index.d.ts} +0 -0
  114. /package/{src/doctor/index.ts → dist/doctor/index.d.ts} +0 -0
  115. /package/{src/export/index.ts → dist/export/index.d.ts} +0 -0
  116. /package/{src/filter/index.ts → dist/filter/index.d.ts} +0 -0
  117. /package/{src/profile/index.ts → dist/profile/index.d.ts} +0 -0
  118. /package/{src/registry/index.ts → dist/registry/index.d.ts} +0 -0
  119. /package/{src/server/routes/index.ts → dist/server/routes/index.d.ts} +0 -0
@@ -0,0 +1,28 @@
1
+ import type { JsonSchema } from "@actiondock/sdk";
2
+ /**
3
+ * JSON Schema 校验结果对象。
4
+ */
5
+ export interface ValidationResult {
6
+ /** 数据是否完全符合 Schema 规范 */
7
+ valid: boolean;
8
+ /** 校验失败时的具体错误详情列表 */
9
+ errors?: string[];
10
+ }
11
+ /**
12
+ * 递归检查数据中是否包含危险的原型污染属性键名(__proto__、constructor、prototype)。
13
+ */
14
+ export declare function hasDangerousKeys(data: unknown): boolean;
15
+ /**
16
+ * 校验指定数据是否符合给定的 JSON Schema 契约。
17
+ *
18
+ * 行为与策略约定:
19
+ * 1. 严格契约校验:当 Schema 中定义 additionalProperties: false 时,包含未声明属性的输入将被直接拒绝(返回 valid: false),系统不会静默过滤或篡改用户输入。
20
+ * 2. 危险原型键硬拦截:输入数据或其任意嵌套对象中若出现 __proto__、constructor 或 prototype 键名,即使 Schema 允许亦立即拒绝,彻底杜绝原型污染。
21
+ * 3. 布尔 Schema:false 显式拒绝所有输入;true 或未定义时允许所有合法非污染数据。
22
+ * 4. 无原型对象支持:完全支持 Object.create(null) 创建的无原型对象校验。
23
+ *
24
+ * @param schema 期望匹配的 JSON Schema 对象(未提供或为空对象/true 时默认通过;为 false 时拒绝所有数据)
25
+ * @param data 待校验的原始数据
26
+ * @returns 包含 valid 状态与错误信息列表的 ValidationResult
27
+ */
28
+ export declare function validateSchema(schema: JsonSchema | undefined, data: unknown): ValidationResult;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 默认单次 HTTP 请求体最大字节上限(1 MiB)。
3
+ */
4
+ export declare const DEFAULT_MAX_BODY_BYTES: number;
5
+ /**
6
+ * 请求体超出最大允许体积时抛出的异常(对应 HTTP 413 Payload Too Large)。
7
+ */
8
+ export declare class RequestTooLargeError extends Error {
9
+ code: string;
10
+ constructor(message?: string);
11
+ }
12
+ /**
13
+ * 请求体非合法 JSON 格式时抛出的异常(对应 HTTP 400 Bad Request)。
14
+ */
15
+ export declare class InvalidJsonError extends Error {
16
+ code: string;
17
+ constructor(message?: string);
18
+ }
19
+ /**
20
+ * 请求体安全读取选项。
21
+ */
22
+ export interface ReadJsonBodyOptions {
23
+ /** 最大允许的字节数(默认 1 MiB) */
24
+ maxBytes?: number;
25
+ }
26
+ /**
27
+ * 流式安全地读取 HTTP 请求体并解析为 JSON 对象。
28
+ *
29
+ * 防护机制:
30
+ * 1. 快速拒绝(Fast-path):若请求头中存在 `Content-Length` 且超过 `maxBytes`,立即抛出 RequestTooLargeError,不进行内存分配。
31
+ * 2. 流式计数器(Chunk Streaming):在读取 ReadableStream 过程中实时累计字节数,中途超出上限即刻截断并释放流锁,防止大文件 DoS 与内存耗尽(OOM)。
32
+ * 3. 安全解码:处理空请求体与 UTF-8 字符集解码。
33
+ *
34
+ * @param req 传入的 Request 对象
35
+ * @param options 读取配置选项
36
+ * @returns 解析后的 JSON 对象
37
+ * @throws {RequestTooLargeError} 若请求体体积超限
38
+ * @throws {InvalidJsonError} 若请求体非合法 JSON
39
+ */
40
+ export declare function readJsonBody<T = any>(req: Request, options?: ReadJsonBodyOptions): Promise<T>;
@@ -4,4 +4,3 @@ export * from "./body";
4
4
  export * from "./runtime-registry";
5
5
  export * from "./routes";
6
6
  export * from "./server";
7
-
@@ -0,0 +1,5 @@
1
+ import { type RouteContext } from "./common";
2
+ /**
3
+ * 处理 Action 列表、详情查询及同步/异步运行接口。
4
+ */
5
+ export declare function handleActionsRoutes(ctx: RouteContext): Promise<Response | null>;
@@ -0,0 +1,36 @@
1
+ import type { RuntimeStorage } from "../../storage/types";
2
+ import type { RunRecord } from "@actiondock/sdk";
3
+ import type { ServerRuntimeRegistry } from "../runtime-registry";
4
+ import type { ServerOptions } from "../types";
5
+ /**
6
+ * 路由处理统一上下文对象。
7
+ */
8
+ export interface RouteContext {
9
+ req: Request;
10
+ url: URL;
11
+ pathname: string;
12
+ corsHeaders: Record<string, string>;
13
+ projectRoot: string | null;
14
+ customHome?: string;
15
+ runtimeRegistry: ServerRuntimeRegistry;
16
+ options: ServerOptions;
17
+ }
18
+ /**
19
+ * 辅助函数:构造带 CORS 头的标准 JSON HTTP 响应。
20
+ */
21
+ export declare function jsonResponse(data: unknown, status?: number, corsHeaders?: Record<string, string>): Response;
22
+ /**
23
+ * 依据 package 参数或项目上下文解析目标 Storage 实例与根目录。
24
+ */
25
+ export declare function resolveStorageForPackage(packageIdOrPath: string | undefined, runtimeRegistry: ServerRuntimeRegistry, projectRoot?: string | null, customHome?: string): {
26
+ packageId: string;
27
+ storage: RuntimeStorage;
28
+ projectRoot?: string;
29
+ };
30
+ /**
31
+ * 跨活跃连接与所有已知持久化存储全局检索指定 runId 的运行记录。
32
+ */
33
+ export declare function findRunAcrossStorages(runId: string, runtimeRegistry: ServerRuntimeRegistry, projectRoot?: string | null, customHome?: string): {
34
+ storage: RuntimeStorage;
35
+ run: RunRecord;
36
+ } | null;
@@ -0,0 +1,5 @@
1
+ import { type RouteContext } from "./common";
2
+ /**
3
+ * 处理配置元数据与当前值读取、更新及删除接口。
4
+ */
5
+ export declare function handleConfigRoutes(ctx: RouteContext): Promise<Response | null>;
@@ -0,0 +1,5 @@
1
+ import { type RouteContext } from "./common";
2
+ /**
3
+ * 处理环境与依赖诊断接口(GET /api/v1/doctor)。
4
+ */
5
+ export declare function handleDoctorRoute(ctx: RouteContext): Promise<Response | null>;
@@ -0,0 +1,5 @@
1
+ import { type RouteContext } from "./common";
2
+ /**
3
+ * 处理健康检查与就绪状态接口(支持 /api/v1/health 与 /health)。
4
+ */
5
+ export declare function handleHealthRoute(ctx: RouteContext): Promise<Response | null>;
@@ -0,0 +1,5 @@
1
+ import { type RouteContext } from "./common";
2
+ /**
3
+ * 处理系统探索与自省接口(GET /api/v1/info)。
4
+ */
5
+ export declare function handleInfoRoute(ctx: RouteContext): Promise<Response | null>;
@@ -0,0 +1,5 @@
1
+ import { type RouteContext } from "./common";
2
+ /**
3
+ * 处理 Playbook 列表与 SOP 详情接口。
4
+ */
5
+ export declare function handlePlaybooksRoutes(ctx: RouteContext): Promise<Response | null>;
@@ -0,0 +1,5 @@
1
+ import { type RouteContext } from "./common";
2
+ /**
3
+ * 处理历史运行记录检索、清理、详情及 SSE 流式日志接口。
4
+ */
5
+ export declare function handleRunsRoutes(ctx: RouteContext): Promise<Response | null>;
@@ -0,0 +1,5 @@
1
+ import { type RouteContext } from "./common";
2
+ /**
3
+ * 处理状态键名列表、读取、写入、删除及清空接口。
4
+ */
5
+ export declare function handleStateRoutes(ctx: RouteContext): Promise<Response | null>;
@@ -0,0 +1,78 @@
1
+ import type { ActionDefinition } from "@actiondock/sdk";
2
+ import { DefaultExecutionService } from "../execution/service";
3
+ import type { ProjectConfig } from "../project/types";
4
+ import { ExecutionManager } from "../runtime/execution-manager";
5
+ import type { RuntimeStorage } from "../storage/types";
6
+ /**
7
+ * 服务端运行时注册表(ServerRuntimeRegistry)。
8
+ *
9
+ * 职责:
10
+ * 1. 在长期运行的 HTTP 服务端(`ad serve` / `ad mcp serve`)中,跨请求缓存并池化管理 SQLite 数据库存储连接。
11
+ * 2. 集中维护活跃的在途任务执行句柄(ExecutionManager)。
12
+ * 3. 服务端停止或优雅关机(Graceful Shutdown)时,统一中断在途任务并安全关闭所有数据库连接。
13
+ */
14
+ export declare class ServerRuntimeRegistry {
15
+ private customHome?;
16
+ private storages;
17
+ private globalStorage?;
18
+ private listeners;
19
+ private executionServices;
20
+ executionManager: ExecutionManager;
21
+ constructor(customHome?: string);
22
+ /**
23
+ * 订阅指定 runId 的事件(用于 SSE 流式推送)。
24
+ */
25
+ subscribe(runId: string, listener: (event: {
26
+ type: string;
27
+ data: any;
28
+ }) => void): () => void;
29
+ /**
30
+ * 向指定 runId 的订阅者广播事件。
31
+ */
32
+ emit(runId: string, event: {
33
+ type: string;
34
+ data: any;
35
+ }): void;
36
+ /**
37
+ * 获取或懒加载指定 Package 和 projectRoot 的缓存 RuntimeStorage 实例。
38
+ *
39
+ * @param packageId 所属 Package ID
40
+ * @param projectRoot 项目根目录(可选)
41
+ * @returns 缓存或新创建的 RuntimeStorage 实例
42
+ */
43
+ getStorage(packageId: string, projectRoot?: string): RuntimeStorage;
44
+ /**
45
+ * 获取或懒加载统一 ExecutionService 实例。
46
+ */
47
+ getExecutionService(packageId: string, projectRoot?: string, projectConfig?: ProjectConfig, options?: {
48
+ storage?: RuntimeStorage;
49
+ actions?: Map<string, ActionDefinition>;
50
+ configOverrides?: Record<string, unknown>;
51
+ }): DefaultExecutionService;
52
+ /**
53
+ * 获取或懒加载全局共享持久化存储实例(~/.actiondock/global.db)。
54
+ * 实现全局数据库单例池化,避免重复创建连接泄漏。
55
+ *
56
+ * @param customHome 自定义家目录路径(可选)
57
+ */
58
+ getGlobalStorage(customHome?: string): RuntimeStorage;
59
+ /**
60
+ * 获取当前缓存的所有活跃 RuntimeStorage 实例列表。
61
+ */
62
+ getAllStorages(): RuntimeStorage[];
63
+ /**
64
+ * 跨所有已建立的存储连接全局查找指定 runId 的运行记录。
65
+ *
66
+ * @param runId 目标运行 ID
67
+ */
68
+ findRun(runId: string): {
69
+ storage: RuntimeStorage;
70
+ run: import("@actiondock/sdk").RunRecord;
71
+ } | undefined;
72
+ /**
73
+ * 优雅关机:中断所有在途异步任务并安全关闭所有 SQLite 存储连接。
74
+ */
75
+ close(options?: {
76
+ graceMs?: number;
77
+ }): Promise<void>;
78
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 恒定时间字符串比较(Constant-time comparison)。
3
+ * 使用底层的 `crypto.timingSafeEqual` 防范时序攻击(Timing Attack)。
4
+ *
5
+ * @param a 字符串 A
6
+ * @param b 字符串 B
7
+ * @returns 两个字符串内容是否完全一致
8
+ */
9
+ export declare function safeEqual(a: string, b: string): boolean;
10
+ /**
11
+ * 检查指定的主机地址是否为本地回环接口(Loopback Host)。
12
+ * 支持 127.0.0.1, localhost, ::1 等形式。
13
+ *
14
+ * @param host 主机名或 IP 字符串
15
+ */
16
+ export declare function isLoopbackHost(host: string): boolean;
17
+ /**
18
+ * 校验 HTTP 请求中的鉴权令牌是否有效。
19
+ *
20
+ * 支持两种凭证携带模式(均通过恒定时间对比):
21
+ * 1. HTTP 请求头: `Authorization: Bearer <token>`
22
+ * 2. URL 查询参数: `?token=<token>`(便于浏览器/Web 调试)
23
+ *
24
+ * @param req 传入的 HTTP Request 对象
25
+ * @param expectedToken 服务端预期的正确 Token(若未配置 Token 则默认放行)
26
+ * @returns 是否鉴权成功
27
+ */
28
+ export declare function verifyBearerToken(req: Request, expectedToken?: string): boolean;
29
+ /**
30
+ * 根据配置的 CORS 白名单解析并返回跨域响应头。
31
+ * 默认情况下若未配置 corsOrigins,返回空对象(即默认关闭跨域访问,防范 CSRF)。
32
+ *
33
+ * @param origin 请求头中的 Origin 字段
34
+ * @param allowedOrigins 允许跨域的白名单来源数组
35
+ * @returns 包含 Access-Control-* 的响应头对象
36
+ */
37
+ export declare function resolveCorsHeaders(origin: string | null, allowedOrigins?: string[]): Record<string, string>;
@@ -0,0 +1,15 @@
1
+ import type { ActionDockServerInstance, CoreHttpServerFactory, CoreHttpServerInstance, ServerOptions } from "./types";
2
+ /**
3
+ * 注册自定义 HTTP 服务端工厂(用于 Node.js / Bun 运行时环境适配)。
4
+ */
5
+ export declare function setHttpServerFactory(factory: CoreHttpServerFactory): void;
6
+ /**
7
+ * 根据当前运行时环境启动标准 Web Request/Response 兼容的 HTTP 服务。
8
+ */
9
+ export declare function launchHttpServer(port: number, host: string, fetchHandler: (req: Request) => Promise<Response>): Promise<CoreHttpServerInstance>;
10
+ /**
11
+ * 启动 ActionDock 2.0 原生轻量级 HTTP 服务装配中枢。
12
+ *
13
+ * 仅负责中间件流转、认证拦截、路由分发与服务生命周期管理。
14
+ */
15
+ export declare function startActionDockServer(options?: ServerOptions): Promise<ActionDockServerInstance>;
@@ -0,0 +1,59 @@
1
+ import type { ServerRuntimeRegistry } from "./runtime-registry";
2
+ export interface CoreHttpServerInstance {
3
+ port: number;
4
+ stop: (closeActiveConnections?: boolean) => void | Promise<void>;
5
+ ready?: Promise<void>;
6
+ }
7
+ export type CoreHttpServerFactory = (options: {
8
+ port: number;
9
+ host: string;
10
+ fetch: (req: Request) => Promise<Response>;
11
+ }) => CoreHttpServerInstance | Promise<CoreHttpServerInstance>;
12
+ /**
13
+ * 启动 ActionDock HTTP Runner 服务端的配置选项。
14
+ */
15
+ export interface ServerOptions {
16
+ /** 监听端口号(默认 5177) */
17
+ port?: number;
18
+ /** 绑定监听的主机地址(默认 "127.0.0.1") */
19
+ host?: string;
20
+ /** 用于 HTTP Bearer Token 鉴权的密钥令牌 */
21
+ token?: string;
22
+ /** 服务的项目根目录(可选,若未指定则自动向上查找或进入全局 Registry 模式) */
23
+ projectRoot?: string;
24
+ /** 自定义 ActionDock 用户家目录 */
25
+ customHome?: string;
26
+ /** 是否允许非回环地址(如 0.0.0.0)在未配置 Token 的情况下启动(不安全) */
27
+ allowInsecureNoAuth?: boolean;
28
+ /** 允许跨域请求的 CORS Origin 白名单列表 */
29
+ corsOrigins?: string[];
30
+ /** 允许访问执行的 Package ID 白名单列表(为空允许全部) */
31
+ packageAllowlist?: string[];
32
+ /** 最大允许的请求体字节限制(默认 1MB,防 DoS) */
33
+ maxBodyBytes?: number;
34
+ /** 是否在 health 和 info 接口中透传本地 projectRoot 等调试路径 */
35
+ exposeDebugInfo?: boolean;
36
+ /** 是否启用一体化 MCP 协议支持(默认开启) */
37
+ enableMcp?: boolean;
38
+ /** 自定义 MCP 请求处理器钩子(若挂载则 /mcp 路由交由其处理) */
39
+ mcpHandler?: (req: Request) => Promise<Response | null | undefined> | Response | null | undefined;
40
+ }
41
+ /**
42
+ * 已启动的 ActionDock HTTP Runner 实例句柄。
43
+ */
44
+ export interface ActionDockServerInstance {
45
+ /** 实际监听的端口号 */
46
+ port: number;
47
+ /** 实际绑定的主机地址 */
48
+ host: string;
49
+ /** 服务端可访问的基础 URL(如 "http://127.0.0.1:5177") */
50
+ url: string;
51
+ /** 关联的 ServerRuntimeRegistry 运行时注册表 */
52
+ runtimeRegistry?: ServerRuntimeRegistry;
53
+ /** 服务就绪 Promise(可等待端口解析与监听建立) */
54
+ ready?: Promise<void>;
55
+ /** 优雅关闭服务端并释放所有存储连接 */
56
+ stop: (options?: {
57
+ graceMs?: number;
58
+ }) => Promise<void> | void;
59
+ }
@@ -0,0 +1,15 @@
1
+ import type { SqliteDriver } from "./types";
2
+ export type SqliteDriverFactory = (dbPath: string) => SqliteDriver;
3
+ /**
4
+ * 获取当前注册的全局默认 SQLite 驱动工厂。
5
+ */
6
+ export declare function getSqliteDriverFactory(): SqliteDriverFactory | undefined;
7
+ /**
8
+ * 注册全局默认 SQLite 驱动工厂。
9
+ */
10
+ export declare function setSqliteDriverFactory(factory: SqliteDriverFactory): void;
11
+ /**
12
+ * 创建默认 SQLite 驱动实例。
13
+ * 优先使用外部注册的工厂,其次根据当前运行时环境自动适配。
14
+ */
15
+ export declare function createDefaultSqliteDriver(dbPath: string): SqliteDriver;
@@ -0,0 +1,44 @@
1
+ import type { RuntimeStorage } from "./types";
2
+ export * from "./driver";
3
+ export * from "./mask";
4
+ export * from "./sqlite";
5
+ export * from "./types";
6
+ /**
7
+ * 解析并计算目标 SQLite 数据库文件的绝对路径。
8
+ *
9
+ * 优先级规则:
10
+ * 1. inMemory: true -> 返回 ":memory:"
11
+ * 2. 显式指定 dataDir -> 返回 `<dataDir>/<packageId>/runtime.db`
12
+ * 3. 显式指定 projectRoot(开发态项目) -> 返回 `<projectRoot>/.actiondock/runtime.db`
13
+ * 4. 默认独立二进制存储路径 -> 返回 `~/.actiondock/data/<packageId>/runtime.db`
14
+ *
15
+ * @param packageId 所属 Package ID
16
+ * @param options 路径解析选项
17
+ */
18
+ export declare function resolveDatabasePath(packageId: string, options?: {
19
+ projectRoot?: string;
20
+ dataDir?: string;
21
+ inMemory?: boolean;
22
+ }): string;
23
+ /**
24
+ * 工厂函数:为指定 Package 创建或连接 RuntimeStorage 实例。
25
+ *
26
+ * @param packageId 目标 Package ID
27
+ * @param options 存储配置参数(支持 projectRoot, dataDir, inMemory)
28
+ */
29
+ export declare function createStorage(packageId: string, options?: {
30
+ projectRoot?: string;
31
+ dataDir?: string;
32
+ inMemory?: boolean;
33
+ }): RuntimeStorage;
34
+ /**
35
+ * 工厂函数:创建或连接 ActionDock 全局共享数据库(~/.actiondock/global.db)。
36
+ * 用于跨 Package 共享的全局配置项存储。
37
+ *
38
+ * @param customHomeOrOptions 自定义家目录路径或配置对象(可选)
39
+ * @param dataDirArg 自定义数据存储目录(可选)
40
+ */
41
+ export declare function createGlobalStorage(customHomeOrOptions?: string | {
42
+ customHome?: string;
43
+ dataDir?: string;
44
+ }, dataDirArg?: string): RuntimeStorage;
@@ -1,34 +1,19 @@
1
1
  import type { ConfigItemDefinition } from "../project/types";
2
-
3
2
  /**
4
3
  * 检查指定配置项是否为敏感数据(密码、私钥、Token、密钥等)。
5
- *
4
+ *
6
5
  * 判定逻辑:
7
6
  * 1. 若 actiondock.json 中显式声明了 `secret: true`,直接判定为敏感。
8
7
  * 2. 若未显式声明,使用正则探测包含 PASSWORD/SECRET/TOKEN/KEY/PASS/AUTH/CREDENTIAL/PRIVATE_KEY 的通用敏感命名特征。
9
- *
8
+ *
10
9
  * @param key 配置键名
11
10
  * @param declaredItem 项目中声明的配置元数据(可选)
12
11
  */
13
- export function isSecretConfigKey(
14
- key: string,
15
- declaredItem?: ConfigItemDefinition
16
- ): boolean {
17
- if (declaredItem?.secret === true) {
18
- return true;
19
- }
20
- // 匹配常见敏感词命名特征
21
- return /^(.*_)?(PASSWORD|SECRET|TOKEN|KEY|PASS|AUTH|CREDENTIAL|PRIVATE_KEY)(_.*)?$/i.test(key);
22
- }
23
-
12
+ export declare function isSecretConfigKey(key: string, declaredItem?: ConfigItemDefinition): boolean;
24
13
  /**
25
14
  * 对敏感数据的值进行掩码脱敏处理(返回 "********")。
26
- *
15
+ *
27
16
  * @param value 原始数据值
28
17
  * @returns 掩码脱敏后的安全展示字符串
29
18
  */
30
- export function maskSecretValue(value: unknown): string {
31
- if (value === undefined) return "undefined";
32
- if (value === null) return "null";
33
- return "********";
34
- }
19
+ export declare function maskSecretValue(value: unknown): string;
@@ -0,0 +1,66 @@
1
+ import { decodeStateKey, encodeStateKey, escapeStateSegment, unescapeStateSegment, type RuntimeError, type RunRecord } from "@actiondock/sdk";
2
+ import type { RuntimeStorage, StateEntry, StorageOptions, TerminalRunStatus } from "./types";
3
+ export { decodeStateKey, encodeStateKey, escapeStateSegment, unescapeStateSegment, };
4
+ /**
5
+ * 统一 SQLite 运行时存储实现。
6
+ * 通过 SqliteDriver 抽象驱动,解耦底层具体运行时引擎(Node.js / Bun)。
7
+ */
8
+ export declare class SqliteRuntimeStorage implements RuntimeStorage {
9
+ private driver;
10
+ private packageId;
11
+ private clock;
12
+ private isClosed;
13
+ private statementCache;
14
+ get isOpen(): boolean;
15
+ get closed(): boolean;
16
+ constructor(options: StorageOptions);
17
+ /**
18
+ * 初始化数据库结构并执行无损版本升级。
19
+ */
20
+ private init;
21
+ /**
22
+ * 重启恢复:将未正常结算的 running 状态自动收敛为 interrupted
23
+ */
24
+ recoverRunningRuns(): number;
25
+ /**
26
+ * 获取或复用预编译 SQL 语句缓存。
27
+ */
28
+ private getStatement;
29
+ getConfig<T = unknown>(key: string): T | undefined;
30
+ listConfig(): Record<string, unknown>;
31
+ setConfig(key: string, value: unknown): void;
32
+ deleteConfig(key: string): boolean;
33
+ getState<T = unknown>(namespace: string, key: string): Promise<T | undefined>;
34
+ private findMatchingStateRows;
35
+ findState<T = unknown>(targetKey: string, namespace?: string): Promise<StateEntry | undefined>;
36
+ setState<T = unknown>(namespace: string, key: string, value: T, ttl?: number): Promise<void>;
37
+ deleteState(namespace: string, key: string): Promise<boolean>;
38
+ deleteStateSmart(targetKey: string, namespace?: string): Promise<boolean>;
39
+ /**
40
+ * 清理已过期的状态记录
41
+ */
42
+ cleanExpiredState(): Promise<number>;
43
+ clearState(options?: {
44
+ namespace?: string;
45
+ all?: boolean;
46
+ prefix?: string;
47
+ }): Promise<number>;
48
+ listStateKeys(namespace?: string | null, prefix?: string): Promise<string[]>;
49
+ listStateEntries(options?: {
50
+ namespace?: string;
51
+ prefix?: string;
52
+ }): Promise<StateEntry[]>;
53
+ createRun(record: RunRecord | any): void;
54
+ updateRun(id: string, status: TerminalRunStatus, output?: unknown, error?: RuntimeError, finishedAt?: string): void;
55
+ getRun(id: string): RunRecord | null;
56
+ listRuns(options?: {
57
+ actionId?: string;
58
+ limit?: number;
59
+ }): RunRecord[];
60
+ clearRuns(options?: {
61
+ actionId?: string;
62
+ status?: string;
63
+ }): number;
64
+ private mapRunRecord;
65
+ close(): void;
66
+ }
@@ -0,0 +1,121 @@
1
+ import type { RuntimeError, RunRecord } from "@actiondock/sdk";
2
+ import type { Clock } from "../runtime/clock";
3
+ /**
4
+ * SQLite 基础参数值类型。
5
+ */
6
+ export type SqlValue = null | number | string | Uint8Array;
7
+ /**
8
+ * SQLite 位置参数数组。
9
+ */
10
+ export type SqlParams = readonly SqlValue[];
11
+ /**
12
+ * 编译后的 SQLite 参数化语句接口。
13
+ */
14
+ export interface SqliteStatement {
15
+ run(...params: any[]): {
16
+ changes: number;
17
+ lastInsertRowid?: number | bigint;
18
+ };
19
+ get<T>(...params: any[]): T | undefined;
20
+ all<T>(...params: any[]): T[];
21
+ }
22
+ /**
23
+ * 统一 SQLite 驱动层接口。
24
+ */
25
+ export interface SqliteDriver {
26
+ exec(sql: string): void;
27
+ prepare(sql: string): SqliteStatement;
28
+ transaction<T>(fn: () => T extends PromiseLike<unknown> ? never : T): T;
29
+ close(): void;
30
+ }
31
+ /**
32
+ * 数据库中存储的配置条目实体。
33
+ */
34
+ export interface ConfigEntry {
35
+ /** 所属 Package ID */
36
+ packageId: string;
37
+ /** 配置键名 */
38
+ key: string;
39
+ /** 配置值(JSON 序列化存储) */
40
+ value: unknown;
41
+ /** 最近更新时间(ISO 8601 格式) */
42
+ updatedAt: string;
43
+ }
44
+ /**
45
+ * 数据库中存储的状态条目实体。
46
+ */
47
+ export interface StateEntry {
48
+ /** 所属 Package ID */
49
+ packageId: string;
50
+ /** 状态隔离命名空间 */
51
+ namespace: string;
52
+ /** 状态键名 */
53
+ key: string;
54
+ /** 复合完整键名 */
55
+ fullKey: string;
56
+ /** 状态值(JSON 序列化存储) */
57
+ value: unknown;
58
+ /** 最近更新时间(ISO 8601 格式) */
59
+ updatedAt: string;
60
+ /** 自动过期时间戳(ISO 8601 格式,null/undefined 表示不过期) */
61
+ expiresAt?: string;
62
+ }
63
+ /**
64
+ * 初始化存储引擎所需的选项。
65
+ */
66
+ export interface StorageOptions {
67
+ /** SQLite 数据库文件绝对路径,或 ":memory:" 表示内存数据库 */
68
+ dbPath?: string;
69
+ /** 所绑定的 Package ID */
70
+ packageId: string;
71
+ /** 显式注入的 SQLite 底层驱动 */
72
+ driver?: SqliteDriver;
73
+ /** 可选注入的时间提供器,便于与模拟时钟联动 */
74
+ clock?: Clock;
75
+ }
76
+ /**
77
+ * Action 执行终态枚举。
78
+ */
79
+ export type TerminalRunStatus = "success" | "failed" | "cancelled" | "timed_out" | "interrupted";
80
+ /**
81
+ * 统一运行时存储抽象接口。
82
+ */
83
+ export interface RuntimeStorage {
84
+ /** 数据库是否处于打开状态 */
85
+ readonly isOpen?: boolean;
86
+ /** 数据库是否已关闭 */
87
+ readonly closed?: boolean;
88
+ getConfig<T = unknown>(key: string): T | undefined;
89
+ listConfig(): Record<string, unknown>;
90
+ setConfig(key: string, value: unknown): void;
91
+ deleteConfig(key: string): boolean;
92
+ getState<T = unknown>(namespace: string, key: string): Promise<T | undefined>;
93
+ findState<T = unknown>(targetKey: string, namespace?: string): Promise<StateEntry | undefined>;
94
+ setState<T = unknown>(namespace: string, key: string, value: T, ttl?: number): Promise<void>;
95
+ deleteState(namespace: string, key: string): Promise<boolean>;
96
+ deleteStateSmart(targetKey: string, namespace?: string): Promise<boolean>;
97
+ clearState(options?: {
98
+ namespace?: string;
99
+ all?: boolean;
100
+ prefix?: string;
101
+ }): Promise<number>;
102
+ cleanExpiredState?(): Promise<number>;
103
+ listStateKeys(namespace?: string | null, prefix?: string): Promise<string[]>;
104
+ listStateEntries(options?: {
105
+ namespace?: string;
106
+ prefix?: string;
107
+ }): Promise<StateEntry[]>;
108
+ createRun(record: RunRecord): void;
109
+ updateRun(id: string, status: TerminalRunStatus, output?: unknown, error?: RuntimeError, finishedAt?: string): void;
110
+ getRun(id: string): RunRecord | null;
111
+ listRuns(options?: {
112
+ actionId?: string;
113
+ limit?: number;
114
+ }): RunRecord[];
115
+ clearRuns(options?: {
116
+ actionId?: string;
117
+ status?: string;
118
+ }): number;
119
+ /** 关闭底层 SQLite 数据库连接并释放句柄 */
120
+ close(): void;
121
+ }