@actiondock/core 2.0.1 → 2.0.2
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/package.json +1 -1
- package/src/profile/client.ts +252 -2
- package/src/server/runtime-registry.ts +35 -0
- package/src/server/server.ts +892 -66
- package/src/server/types.ts +4 -0
- package/src/storage/sqlite.ts +43 -16
- package/src/storage/types.ts +2 -0
package/src/server/types.ts
CHANGED
|
@@ -22,6 +22,10 @@ export interface ServerOptions {
|
|
|
22
22
|
maxBodyBytes?: number;
|
|
23
23
|
/** 是否在 health 和 info 接口中透传本地 projectRoot 等调试路径 */
|
|
24
24
|
exposeDebugInfo?: boolean;
|
|
25
|
+
/** 是否启用一体化 MCP 协议支持(默认开启) */
|
|
26
|
+
enableMcp?: boolean;
|
|
27
|
+
/** 自定义 MCP 请求处理器钩子(若挂载则 /mcp 路由交由其处理) */
|
|
28
|
+
mcpHandler?: (req: Request) => Promise<Response | null | undefined> | Response | null | undefined;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
/**
|
package/src/storage/sqlite.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type { RuntimeStorage, StateEntry, StorageOptions, TerminalRunStatus } fr
|
|
|
17
17
|
export class SqliteRuntimeStorage implements RuntimeStorage {
|
|
18
18
|
private db: Database;
|
|
19
19
|
private packageId: string;
|
|
20
|
+
private isClosed = false;
|
|
20
21
|
|
|
21
22
|
constructor(options: StorageOptions) {
|
|
22
23
|
this.packageId = options.packageId;
|
|
@@ -486,21 +487,26 @@ export class SqliteRuntimeStorage implements RuntimeStorage {
|
|
|
486
487
|
error?: RuntimeError,
|
|
487
488
|
finishedAt?: string
|
|
488
489
|
): void {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
490
|
+
if (this.isClosed) return;
|
|
491
|
+
try {
|
|
492
|
+
const stmt = this.db.prepare(`
|
|
493
|
+
UPDATE runs SET
|
|
494
|
+
status = ?,
|
|
495
|
+
output_json = ?,
|
|
496
|
+
error_json = ?,
|
|
497
|
+
finished_at = ?
|
|
498
|
+
WHERE id = ?
|
|
499
|
+
`);
|
|
500
|
+
stmt.run(
|
|
501
|
+
status,
|
|
502
|
+
output !== undefined ? JSON.stringify(output) : null,
|
|
503
|
+
error ? JSON.stringify(error) : null,
|
|
504
|
+
finishedAt || new Date().toISOString(),
|
|
505
|
+
id
|
|
506
|
+
);
|
|
507
|
+
} catch {
|
|
508
|
+
// 数据库已关闭,安全忽略
|
|
509
|
+
}
|
|
504
510
|
}
|
|
505
511
|
|
|
506
512
|
getRun(id: string): RunRecord | null {
|
|
@@ -535,6 +541,22 @@ export class SqliteRuntimeStorage implements RuntimeStorage {
|
|
|
535
541
|
return rows.map((r) => this.mapRunRecord(r));
|
|
536
542
|
}
|
|
537
543
|
|
|
544
|
+
clearRuns(options: { actionId?: string; status?: string } = {}): number {
|
|
545
|
+
let sql = "DELETE FROM runs WHERE package_id = ?";
|
|
546
|
+
const params: any[] = [this.packageId];
|
|
547
|
+
if (options.actionId) {
|
|
548
|
+
sql += " AND action_id = ?";
|
|
549
|
+
params.push(options.actionId);
|
|
550
|
+
}
|
|
551
|
+
if (options.status) {
|
|
552
|
+
sql += " AND status = ?";
|
|
553
|
+
params.push(options.status);
|
|
554
|
+
}
|
|
555
|
+
const stmt = this.db.prepare(sql);
|
|
556
|
+
const res = stmt.run(...params);
|
|
557
|
+
return res.changes;
|
|
558
|
+
}
|
|
559
|
+
|
|
538
560
|
private mapRunRecord(row: any): RunRecord {
|
|
539
561
|
let input: unknown;
|
|
540
562
|
let output: unknown;
|
|
@@ -573,6 +595,11 @@ export class SqliteRuntimeStorage implements RuntimeStorage {
|
|
|
573
595
|
}
|
|
574
596
|
|
|
575
597
|
close(): void {
|
|
576
|
-
this.
|
|
598
|
+
this.isClosed = true;
|
|
599
|
+
try {
|
|
600
|
+
this.db.close();
|
|
601
|
+
} catch {
|
|
602
|
+
// 忽略重复关闭异常
|
|
603
|
+
}
|
|
577
604
|
}
|
|
578
605
|
}
|
package/src/storage/types.ts
CHANGED
|
@@ -105,6 +105,8 @@ export interface RuntimeStorage {
|
|
|
105
105
|
getRun(id: string): RunRecord | null;
|
|
106
106
|
/** 分页或按 Action 查询历史运行记录列表(按 startedAt 倒序排列) */
|
|
107
107
|
listRuns(options?: { actionId?: string; limit?: number }): RunRecord[];
|
|
108
|
+
/** 批量清理历史运行记录,返回实际清理的条数 */
|
|
109
|
+
clearRuns(options?: { actionId?: string; status?: string }): number;
|
|
108
110
|
|
|
109
111
|
/** 关闭底层 SQLite 数据库连接并释放句柄 */
|
|
110
112
|
close(): void;
|