@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
@@ -1,322 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import type {
3
- ActionDefinition,
4
- ActionRef,
5
- ExecutionEvent,
6
- ExecutionResult,
7
- JsonValue,
8
- Logger,
9
- ProgressReporter,
10
- RunRecord,
11
- RunStatus,
12
- } from "@actiondock/sdk";
13
- import type { ProjectConfig } from "../project/types";
14
- import { type EventSink, getDefaultEventSink } from "../runtime/events";
15
- import { ActionRunner, type ExecutionHandle } from "../runtime/runner";
16
- import type { RuntimeStorage } from "../storage/types";
17
- import type {
18
- CancelResult,
19
- ExecuteOptions,
20
- ExecutionService,
21
- ExecutionTicket,
22
- } from "./types";
23
-
24
- export interface ExecutionServiceOptions {
25
- packageId: string;
26
- storage: RuntimeStorage;
27
- projectConfig?: ProjectConfig;
28
- eventSink?: EventSink;
29
- maxActiveRuns?: number;
30
- ownerId?: string;
31
- actionResolver?: (ref: ActionRef) => ActionDefinition | undefined | Promise<ActionDefinition | undefined>;
32
- }
33
-
34
- interface ActiveRun {
35
- runId: string;
36
- handle: ExecutionHandle;
37
- controller: AbortController;
38
- status: RunStatus;
39
- startedAt: string;
40
- }
41
-
42
- /**
43
- * 统一执行协调服务实现。
44
- */
45
- export class DefaultExecutionService implements ExecutionService {
46
- private packageId: string;
47
- private storage: RuntimeStorage;
48
- private projectConfig?: ProjectConfig;
49
- private eventSink: EventSink;
50
- private maxActiveRuns: number;
51
- private ownerId: string;
52
- private runner: ActionRunner;
53
- private actionResolver?: (ref: ActionRef) => ActionDefinition | undefined | Promise<ActionDefinition | undefined>;
54
- private activeRuns = new Map<string, ActiveRun>();
55
- private isClosing = false;
56
-
57
- constructor(options: ExecutionServiceOptions) {
58
- this.packageId = options.packageId;
59
- this.storage = options.storage;
60
- this.projectConfig = options.projectConfig;
61
- this.eventSink = options.eventSink || getDefaultEventSink();
62
- this.maxActiveRuns = options.maxActiveRuns || 32;
63
- this.ownerId = options.ownerId || `host-${randomUUID().slice(0, 8)}`;
64
- this.actionResolver = options.actionResolver;
65
-
66
- this.runner = new ActionRunner({
67
- packageId: this.packageId,
68
- storage: this.storage,
69
- projectConfig: this.projectConfig,
70
- });
71
- }
72
-
73
- public registerAction(action: ActionDefinition): void {
74
- this.runner.registerAction(action);
75
- }
76
-
77
- private async resolveTargetAction(ref: ActionRef): Promise<ActionDefinition | undefined> {
78
- const fromRunner = this.runner.getAction(ref.actionId);
79
- if (fromRunner) return fromRunner;
80
- if (this.actionResolver) {
81
- return this.actionResolver(ref);
82
- }
83
- return undefined;
84
- }
85
-
86
- async execute(
87
- ref: ActionRef,
88
- input: JsonValue,
89
- options: ExecuteOptions = {}
90
- ): Promise<ExecutionResult> {
91
- const ticket = await this.start(ref, input, options);
92
- const active = this.activeRuns.get(ticket.runId);
93
- if (!active) {
94
- const record = await this.get(ticket.runId);
95
- if (record && record.status === "success") {
96
- return { ok: true, runId: ticket.runId, data: record.output ?? null };
97
- }
98
- return {
99
- ok: false,
100
- runId: ticket.runId,
101
- error: record?.error || {
102
- code: "RUN_TERMINATED_EARLY",
103
- message: `Run ${ticket.runId} terminated without result`,
104
- },
105
- };
106
- }
107
- return active.handle.result;
108
- }
109
-
110
- async start(
111
- ref: ActionRef,
112
- input: JsonValue,
113
- options: ExecuteOptions = {}
114
- ): Promise<ExecutionTicket> {
115
- if (this.isClosing) {
116
- throw new Error("ExecutionService is closing: new tasks rejected");
117
- }
118
-
119
- if (this.activeRuns.size >= this.maxActiveRuns) {
120
- throw new Error(
121
- `Concurrency limit reached: ${this.activeRuns.size}/${this.maxActiveRuns} active runs`
122
- );
123
- }
124
-
125
- const action = await this.resolveTargetAction(ref);
126
- if (!action) {
127
- const runId = randomUUID();
128
- const errEvt: ExecutionEvent = {
129
- runId,
130
- rootRunId: runId,
131
- sequence: 0,
132
- timestamp: new Date().toISOString(),
133
- type: "finish",
134
- result: {
135
- ok: false,
136
- runId,
137
- error: {
138
- code: "ACTION_NOT_FOUND",
139
- message: `Action '${ref.actionId}' not found in package '${ref.packageId || this.packageId}'`,
140
- },
141
- },
142
- };
143
- this.eventSink.emit(errEvt);
144
- return {
145
- runId,
146
- status: "failed",
147
- };
148
- }
149
-
150
- const controller = new AbortController();
151
- if (options.signal) {
152
- if (options.signal.aborted) {
153
- controller.abort(options.signal.reason);
154
- } else {
155
- options.signal.addEventListener(
156
- "abort",
157
- () => controller.abort(options.signal?.reason),
158
- { once: true }
159
- );
160
- }
161
- }
162
-
163
- const runId = randomUUID();
164
- let sequence = 0;
165
- type EventPayload =
166
- | { type: "log"; level: "debug" | "info" | "warn" | "error"; message: string; data?: JsonValue }
167
- | { type: "progress"; current?: number; total?: number; message?: string }
168
- | { type: "status"; status: RunStatus }
169
- | { type: "finish"; result: ExecutionResult };
170
-
171
- const emitEvent = (payload: EventPayload) => {
172
- const evt: ExecutionEvent = {
173
- ...payload,
174
- runId,
175
- rootRunId: runId,
176
- sequence: sequence++,
177
- timestamp: new Date().toISOString(),
178
- };
179
- this.eventSink.emit(evt);
180
- };
181
-
182
- const progressReporter: ProgressReporter = {
183
- report(current: number, total?: number, message?: string) {
184
- emitEvent({
185
- type: "progress",
186
- current,
187
- total,
188
- message,
189
- });
190
- },
191
- };
192
-
193
- const executionLogger: Logger = {
194
- debug(message: string, data?: unknown) {
195
- emitEvent({
196
- type: "log",
197
- level: "debug",
198
- message,
199
- data: data as JsonValue | undefined,
200
- });
201
- },
202
- info(message: string, data?: unknown) {
203
- emitEvent({
204
- type: "log",
205
- level: "info",
206
- message,
207
- data: data as JsonValue | undefined,
208
- });
209
- },
210
- warn(message: string, data?: unknown) {
211
- emitEvent({
212
- type: "log",
213
- level: "warn",
214
- message,
215
- data: data as JsonValue | undefined,
216
- });
217
- },
218
- error(message: string, data?: unknown) {
219
- emitEvent({
220
- type: "log",
221
- level: "error",
222
- message,
223
- data: data as JsonValue | undefined,
224
- });
225
- },
226
- };
227
-
228
- const handle = this.runner.start(action, input, {
229
- runId,
230
- signal: controller.signal,
231
- timeoutMs: options.timeoutMs,
232
- progress: progressReporter,
233
- logger: executionLogger,
234
- });
235
-
236
- const activeItem: ActiveRun = {
237
- runId: handle.runId,
238
- handle,
239
- controller,
240
- status: "running",
241
- startedAt: new Date().toISOString(),
242
- };
243
-
244
- this.activeRuns.set(handle.runId, activeItem);
245
- emitEvent({ type: "status", status: "running" });
246
-
247
- handle.result
248
- .then((result: ExecutionResult) => {
249
- activeItem.status = result.ok ? "success" : "failed";
250
- emitEvent({ type: "finish", result });
251
- })
252
- .catch((err: any) => {
253
- activeItem.status = "failed";
254
- emitEvent({
255
- type: "finish",
256
- result: {
257
- ok: false,
258
- runId: handle.runId,
259
- error: {
260
- code: "UNHANDLED_EXECUTION_ERROR",
261
- message: err?.message || String(err),
262
- },
263
- },
264
- });
265
- })
266
- .finally(() => {
267
- this.activeRuns.delete(handle.runId);
268
- });
269
-
270
- return {
271
- runId: handle.runId,
272
- status: "running",
273
- };
274
- }
275
-
276
- async get(runId: string): Promise<RunRecord | undefined> {
277
- const record = this.storage.getRun(runId);
278
- return record || undefined;
279
- }
280
-
281
- async cancel(runId: string, reason?: string): Promise<CancelResult> {
282
- const active = this.activeRuns.get(runId);
283
- if (!active) {
284
- const record = await this.get(runId);
285
- if (record) {
286
- return { outcome: "already_terminal", runId, status: record.status };
287
- }
288
- return { outcome: "not_found", runId };
289
- }
290
-
291
- active.controller.abort(new Error(reason || "Execution cancelled"));
292
- active.handle.cancel(reason);
293
- return { outcome: "requested", runId };
294
- }
295
-
296
- events(
297
- runId: string,
298
- options: { after?: number; signal?: AbortSignal } = {}
299
- ): AsyncIterable<ExecutionEvent> {
300
- return this.eventSink.subscribe(runId, options);
301
- }
302
-
303
- async close(options: { graceMs?: number } = {}): Promise<void> {
304
- this.isClosing = true;
305
- const graceMs = options.graceMs ?? 5000;
306
-
307
- for (const [_, active] of this.activeRuns) {
308
- active.controller.abort(new Error("Service shutting down"));
309
- active.handle.cancel("Service shutting down");
310
- }
311
-
312
- if (this.activeRuns.size > 0) {
313
- const waitPromise = Promise.all(
314
- Array.from(this.activeRuns.values()).map((a) => a.handle.result.catch(() => {}))
315
- );
316
- const timeoutPromise = new Promise((resolve) => setTimeout(resolve, graceMs));
317
- await Promise.race([waitPromise, timeoutPromise]);
318
- }
319
-
320
- this.activeRuns.clear();
321
- }
322
- }
@@ -1,73 +0,0 @@
1
- import type {
2
- ActionRef,
3
- ExecutionEvent,
4
- ExecutionResult,
5
- JsonValue,
6
- RunRecord,
7
- RunStatus,
8
- } from "@actiondock/sdk";
9
-
10
- /**
11
- * 执行参数选项。
12
- */
13
- export interface ExecuteOptions {
14
- /** 外部取消信号 */
15
- signal?: AbortSignal;
16
- /** 超时时间(毫秒) */
17
- timeoutMs?: number;
18
- /** 配置临时覆盖字典 */
19
- config?: Record<string, JsonValue>;
20
- }
21
-
22
- /**
23
- * 异步任务执行票据。
24
- */
25
- export interface ExecutionTicket {
26
- /** 运行标识 */
27
- runId: string;
28
- /** 当前状态 */
29
- status: RunStatus;
30
- }
31
-
32
- /**
33
- * 取消操作结果枚举。
34
- */
35
- export type CancelResult =
36
- | { outcome: "requested"; runId: string }
37
- | { outcome: "already_terminal"; runId: string; status: RunStatus }
38
- | { outcome: "not_found"; runId: string }
39
- | { outcome: "not_owner"; runId: string };
40
-
41
- /**
42
- * 统一执行协调服务接口。
43
- */
44
- export interface ExecutionService {
45
- /** 同步执行 Action 并等待终态结果 */
46
- execute(
47
- ref: ActionRef,
48
- input: JsonValue,
49
- options?: ExecuteOptions
50
- ): Promise<ExecutionResult>;
51
-
52
- /** 异步启动 Action 并立即返回任务票据 */
53
- start(
54
- ref: ActionRef,
55
- input: JsonValue,
56
- options?: ExecuteOptions
57
- ): Promise<ExecutionTicket>;
58
-
59
- /** 根据 ID 获取运行记录 */
60
- get(runId: string): Promise<RunRecord | undefined>;
61
-
62
- /** 取消指定的在运行任务 */
63
- cancel(runId: string, reason?: string): Promise<CancelResult>;
64
-
65
- /** 订阅执行事件流 */
66
- events(
67
- runId: string,
68
- options?: { after?: number; signal?: AbortSignal }
69
- ): AsyncIterable<ExecutionEvent>;
70
-
71
- /** 优雅关闭服务并等待活跃任务收尾 */
72
- close(options?: { graceMs?: number }): Promise<void>;
73
- }