@actiondock/core 2.0.1 → 2.0.3
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 +59 -27
- package/package.json +2 -2
- package/src/build/builder.ts +20 -7
- package/src/catalog/action-index.ts +92 -0
- package/src/catalog/action-resolver.ts +120 -0
- package/src/catalog/index.ts +5 -0
- package/src/catalog/location-registry.ts +134 -0
- package/src/catalog/package-catalog.ts +87 -0
- package/src/catalog/types.ts +83 -0
- package/src/doctor/doctor.ts +59 -33
- package/src/execution/index.ts +2 -0
- package/src/execution/service.ts +282 -0
- package/src/execution/types.ts +73 -0
- package/src/export/skill.ts +7 -6
- package/src/export/templates.ts +1 -1
- package/src/index.ts +2 -0
- package/src/profile/client.ts +252 -2
- package/src/project/index.ts +1 -0
- package/src/project/init.ts +80 -33
- package/src/project/loader.ts +11 -12
- package/src/project/manifest.ts +96 -0
- package/src/project/types.ts +30 -0
- package/src/runtime/clock.ts +41 -0
- package/src/runtime/context.ts +24 -2
- package/src/runtime/events.ts +142 -0
- package/src/runtime/index.ts +4 -0
- package/src/runtime/process.ts +244 -0
- package/src/runtime/runner.ts +37 -3
- package/src/server/runtime-registry.ts +35 -0
- package/src/server/server.ts +994 -74
- package/src/server/types.ts +15 -0
- package/src/storage/driver.ts +126 -0
- package/src/storage/index.ts +4 -3
- package/src/storage/sqlite.ts +365 -258
- package/src/storage/types.ts +42 -22
package/src/server/types.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { ServerRuntimeRegistry } from "./runtime-registry";
|
|
2
2
|
|
|
3
|
+
export interface CoreHttpServerInstance {
|
|
4
|
+
port: number;
|
|
5
|
+
stop: (closeActiveConnections?: boolean) => void | Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type CoreHttpServerFactory = (options: {
|
|
9
|
+
port: number;
|
|
10
|
+
host: string;
|
|
11
|
+
fetch: (req: Request) => Promise<Response>;
|
|
12
|
+
}) => CoreHttpServerInstance | Promise<CoreHttpServerInstance>;
|
|
13
|
+
|
|
3
14
|
/**
|
|
4
15
|
* 启动 ActionDock HTTP Runner 服务端的配置选项。
|
|
5
16
|
*/
|
|
@@ -22,6 +33,10 @@ export interface ServerOptions {
|
|
|
22
33
|
maxBodyBytes?: number;
|
|
23
34
|
/** 是否在 health 和 info 接口中透传本地 projectRoot 等调试路径 */
|
|
24
35
|
exposeDebugInfo?: boolean;
|
|
36
|
+
/** 是否启用一体化 MCP 协议支持(默认开启) */
|
|
37
|
+
enableMcp?: boolean;
|
|
38
|
+
/** 自定义 MCP 请求处理器钩子(若挂载则 /mcp 路由交由其处理) */
|
|
39
|
+
mcpHandler?: (req: Request) => Promise<Response | null | undefined> | Response | null | undefined;
|
|
25
40
|
}
|
|
26
41
|
|
|
27
42
|
/**
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import type { SqliteDriver } from "./types";
|
|
3
|
+
|
|
4
|
+
export type SqliteDriverFactory = (dbPath: string) => SqliteDriver;
|
|
5
|
+
|
|
6
|
+
/** ESM 环境下可用的 CommonJS require,用于动态加载 node:sqlite / bun:sqlite */
|
|
7
|
+
const cjsRequire = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
let customDriverFactory: SqliteDriverFactory | undefined;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 注册全局默认 SQLite 驱动工厂。
|
|
13
|
+
*/
|
|
14
|
+
export function setSqliteDriverFactory(factory: SqliteDriverFactory): void {
|
|
15
|
+
customDriverFactory = factory;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 创建默认 SQLite 驱动实例。
|
|
20
|
+
* 优先使用外部注册的工厂,其次根据当前运行时环境自动适配。
|
|
21
|
+
*/
|
|
22
|
+
export function createDefaultSqliteDriver(dbPath: string): SqliteDriver {
|
|
23
|
+
if (customDriverFactory) {
|
|
24
|
+
return customDriverFactory(dbPath);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 检查是否在 Bun 运行时环境
|
|
28
|
+
if (typeof (globalThis as any).Bun !== "undefined") {
|
|
29
|
+
try {
|
|
30
|
+
const { Database } = (globalThis as any).Bun.sqlite || cjsRequire("bun:sqlite");
|
|
31
|
+
const db = new Database(dbPath);
|
|
32
|
+
// bun:sqlite 的 statement 未 finalize 时会一直持有数据库文件句柄,
|
|
33
|
+
// Windows 下导致 db.close() 后文件仍被锁(EBUSY 无法删除)。
|
|
34
|
+
// 跟踪全部 prepared statement,close() 时统一 finalize 释放句柄。
|
|
35
|
+
const openStatements = new Set<any>();
|
|
36
|
+
return {
|
|
37
|
+
exec(sql: string) {
|
|
38
|
+
db.exec(sql);
|
|
39
|
+
},
|
|
40
|
+
prepare(sql: string) {
|
|
41
|
+
const stmt = db.prepare(sql);
|
|
42
|
+
openStatements.add(stmt);
|
|
43
|
+
return {
|
|
44
|
+
run(...args: any[]) {
|
|
45
|
+
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
46
|
+
const res = stmt.run(...params);
|
|
47
|
+
return { changes: res.changes, lastInsertRowid: res.lastInsertRowid };
|
|
48
|
+
},
|
|
49
|
+
get<T>(...args: any[]): T | undefined {
|
|
50
|
+
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
51
|
+
return stmt.get(...params) as T | undefined;
|
|
52
|
+
},
|
|
53
|
+
all<T>(...args: any[]): T[] {
|
|
54
|
+
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
55
|
+
return stmt.all(...params) as T[];
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
transaction<T>(fn: () => T extends PromiseLike<unknown> ? never : T): T {
|
|
60
|
+
return db.transaction(fn)() as T;
|
|
61
|
+
},
|
|
62
|
+
close() {
|
|
63
|
+
for (const stmt of openStatements) {
|
|
64
|
+
try {
|
|
65
|
+
stmt.finalize();
|
|
66
|
+
} catch {
|
|
67
|
+
// 已 finalize 或重复释放时忽略
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
openStatements.clear();
|
|
71
|
+
db.close();
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
} catch {
|
|
75
|
+
// 若在 Bun 下获取 bun:sqlite 失败,回退到标准 Node 驱动尝试
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 在 Node.js 环境下使用 node:sqlite
|
|
80
|
+
try {
|
|
81
|
+
const { DatabaseSync } = cjsRequire("node:sqlite");
|
|
82
|
+
const db = new DatabaseSync(dbPath);
|
|
83
|
+
return {
|
|
84
|
+
exec(sql: string) {
|
|
85
|
+
db.exec(sql);
|
|
86
|
+
},
|
|
87
|
+
prepare(sql: string) {
|
|
88
|
+
const stmt = db.prepare(sql);
|
|
89
|
+
return {
|
|
90
|
+
run(...args: any[]) {
|
|
91
|
+
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
92
|
+
const res = stmt.run(...params);
|
|
93
|
+
return { changes: res.changes, lastInsertRowid: res.lastInsertRowid };
|
|
94
|
+
},
|
|
95
|
+
get<T>(...args: any[]): T | undefined {
|
|
96
|
+
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
97
|
+
return stmt.get(...params) as T | undefined;
|
|
98
|
+
},
|
|
99
|
+
all<T>(...args: any[]): T[] {
|
|
100
|
+
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
101
|
+
return stmt.all(...params) as T[];
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
transaction<T>(fn: () => T extends PromiseLike<unknown> ? never : T): T {
|
|
106
|
+
db.exec("BEGIN");
|
|
107
|
+
try {
|
|
108
|
+
const res = fn();
|
|
109
|
+
if (res && typeof (res as any).then === "function") {
|
|
110
|
+
throw new Error("Async transactions are not allowed in SQLite");
|
|
111
|
+
}
|
|
112
|
+
db.exec("COMMIT");
|
|
113
|
+
return res;
|
|
114
|
+
} catch (e) {
|
|
115
|
+
db.exec("ROLLBACK");
|
|
116
|
+
throw e;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
close() {
|
|
120
|
+
db.close();
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
} catch (err: any) {
|
|
124
|
+
throw new Error(`Failed to initialize SQLite driver: ${err?.message || String(err)}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
package/src/storage/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { homedir } from "node:os";
|
|
2
1
|
import { join } from "node:path";
|
|
2
|
+
import { getActionDockHome } from "../utils";
|
|
3
3
|
import { SqliteRuntimeStorage } from "./sqlite";
|
|
4
4
|
import type { RuntimeStorage, StorageOptions } from "./types";
|
|
5
5
|
|
|
6
|
+
export * from "./driver";
|
|
6
7
|
export * from "./mask";
|
|
7
8
|
export * from "./sqlite";
|
|
8
9
|
export * from "./types";
|
|
@@ -33,7 +34,7 @@ export function resolveDatabasePath(
|
|
|
33
34
|
return join(options.projectRoot, ".actiondock", "runtime.db");
|
|
34
35
|
}
|
|
35
36
|
// 独立执行二进制默认存储路径: ~/.actiondock/data/<package-id>/runtime.db
|
|
36
|
-
return join(
|
|
37
|
+
return join(getActionDockHome(), ".actiondock", "data", packageId, "runtime.db");
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/**
|
|
@@ -57,7 +58,7 @@ export function createStorage(
|
|
|
57
58
|
* @param customHome 自定义家目录路径(可选)
|
|
58
59
|
*/
|
|
59
60
|
export function createGlobalStorage(customHome?: string): RuntimeStorage {
|
|
60
|
-
const baseDir = customHome
|
|
61
|
+
const baseDir = getActionDockHome(customHome);
|
|
61
62
|
const dbPath = join(baseDir, ".actiondock", "global.db");
|
|
62
63
|
return new SqliteRuntimeStorage({ dbPath, packageId: "__global__" });
|
|
63
64
|
}
|