@actiondock/core 2.0.2 → 2.0.4

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.
@@ -1,4 +1,33 @@
1
- import type { RuntimeError, RunRecord } from "@actiondock/sdk";
1
+ import type { JsonValue, RuntimeError, RunRecord } from "@actiondock/sdk";
2
+
3
+ /**
4
+ * SQLite 基础参数值类型。
5
+ */
6
+ export type SqlValue = null | number | string | Uint8Array;
7
+
8
+ /**
9
+ * SQLite 位置参数数组。
10
+ */
11
+ export type SqlParams = readonly SqlValue[];
12
+
13
+ /**
14
+ * 编译后的 SQLite 参数化语句接口。
15
+ */
16
+ export interface SqliteStatement {
17
+ run(...params: any[]): { changes: number; lastInsertRowid?: number | bigint };
18
+ get<T>(...params: any[]): T | undefined;
19
+ all<T>(...params: any[]): T[];
20
+ }
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
+ }
2
31
 
3
32
  /**
4
33
  * 数据库中存储的配置条目实体。
@@ -24,7 +53,7 @@ export interface StateEntry {
24
53
  namespace: string;
25
54
  /** 状态键名 */
26
55
  key: string;
27
- /** 复合完整键名(例如 namespace 为空时为 "key",非空时为 "namespace:key") */
56
+ /** 复合完整键名 */
28
57
  fullKey: string;
29
58
  /** 状态值(JSON 序列化存储) */
30
59
  value: unknown;
@@ -42,58 +71,50 @@ export interface StorageOptions {
42
71
  dbPath?: string;
43
72
  /** 所绑定的 Package ID */
44
73
  packageId: string;
74
+ /** 显式注入的 SQLite 底层驱动 */
75
+ driver?: SqliteDriver;
45
76
  }
46
77
 
47
78
  /**
48
- * Action 执行终态枚举(已结束状态)。
79
+ * Action 执行终态枚举。
49
80
  */
50
- export type TerminalRunStatus = "success" | "failed" | "cancelled";
81
+ export type TerminalRunStatus =
82
+ | "success"
83
+ | "failed"
84
+ | "cancelled"
85
+ | "timed_out"
86
+ | "interrupted";
51
87
 
52
88
  /**
53
- * 统一运行时存储抽象接口(RuntimeStorage)。
54
- * 集中管理单个 Package 下的 Config(配置)、State(状态与 TTL)、Runs(执行历史记录)。
89
+ * 统一运行时存储抽象接口。
55
90
  */
56
91
  export interface RuntimeStorage {
57
92
  // --- Config 配置管理 ---
58
- /** 读取指定配置键的值 */
59
93
  getConfig<T = unknown>(key: string): T | undefined;
60
- /** 列出该 Package 存储的所有配置键值映射 */
61
94
  listConfig(): Record<string, unknown>;
62
- /** 设置或更新配置键值 */
63
95
  setConfig(key: string, value: unknown): void;
64
- /** 删除指定配置键,返回是否成功删除 */
65
96
  deleteConfig(key: string): boolean;
66
97
 
67
98
  // --- State 状态管理 ---
68
- /** 读取指定命名空间下的状态值(已过期则自动清除并返回 undefined) */
69
99
  getState<T = unknown>(namespace: string, key: string): Promise<T | undefined>;
70
- /** 智能查找状态实体(支持 namespace 显式定位,或复合 key "namespace:key" 自动定位) */
71
100
  findState<T = unknown>(
72
101
  targetKey: string,
73
102
  namespace?: string
74
103
  ): Promise<StateEntry | undefined>;
75
- /** 写入状态值,可指定 TTL 存活秒数 */
76
104
  setState<T = unknown>(
77
105
  namespace: string,
78
106
  key: string,
79
107
  value: T,
80
108
  ttl?: number
81
109
  ): Promise<void>;
82
- /** 删除指定命名空间下的状态数据,返回是否实际删除了数据 */
83
110
  deleteState(namespace: string, key: string): Promise<boolean>;
84
- /** 智能删除状态(支持显式 namespace,或复合 key "namespace:key" 自动定位),返回是否实际删除 */
85
111
  deleteStateSmart(targetKey: string, namespace?: string): Promise<boolean>;
86
- /** 批量清理状态数据,返回实际清理的条数 */
87
112
  clearState(options?: { namespace?: string; all?: boolean; prefix?: string }): Promise<number>;
88
- /** 列出状态键名。当 namespace 为 null/undefined 时扫描全量 namespace 并返回 fullKey,否则只返回指定 namespace 下的 key */
89
113
  listStateKeys(namespace?: string | null, prefix?: string): Promise<string[]>;
90
- /** 列出状态条目富信息实体列表 */
91
114
  listStateEntries(options?: { namespace?: string; prefix?: string }): Promise<StateEntry[]>;
92
115
 
93
116
  // --- Runs 运行记录管理 ---
94
- /** 创建并记录一条初始运行记录(status: running) */
95
117
  createRun(record: RunRecord): void;
96
- /** 更新运行记录至终态(success/failed/cancelled)并记录输出或错误 */
97
118
  updateRun(
98
119
  id: string,
99
120
  status: TerminalRunStatus,
@@ -101,11 +122,8 @@ export interface RuntimeStorage {
101
122
  error?: RuntimeError,
102
123
  finishedAt?: string
103
124
  ): void;
104
- /** 根据 ID 查询单条运行记录 */
105
125
  getRun(id: string): RunRecord | null;
106
- /** 分页或按 Action 查询历史运行记录列表(按 startedAt 倒序排列) */
107
126
  listRuns(options?: { actionId?: string; limit?: number }): RunRecord[];
108
- /** 批量清理历史运行记录,返回实际清理的条数 */
109
127
  clearRuns(options?: { actionId?: string; status?: string }): number;
110
128
 
111
129
  /** 关闭底层 SQLite 数据库连接并释放句柄 */