@drej/core 0.2.0 → 0.3.0
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/dist/errors.d.ts +9 -0
- package/dist/index.d.ts +6 -6
- package/dist/ledger.d.ts +37 -2
- package/dist/steps/control-flow.d.ts +19 -0
- package/dist/steps/exec.d.ts +8 -0
- package/dist/steps/file.d.ts +35 -0
- package/dist/steps/index.d.ts +7 -0
- package/dist/steps/sandbox.d.ts +8 -0
- package/dist/steps/snapshot.d.ts +6 -0
- package/dist/steps/types.d.ts +178 -0
- package/dist/steps/utils.d.ts +5 -0
- package/dist/validate.d.ts +1 -1
- package/dist/workflow.d.ts +43 -36
- package/package.json +10 -5
- package/dist/steps.d.ts +0 -100
package/dist/errors.d.ts
CHANGED
|
@@ -29,3 +29,12 @@ export declare class CommandError extends WorkflowError {
|
|
|
29
29
|
readonly sandboxId: string;
|
|
30
30
|
constructor(exitCode: number, command: string, sandboxId: string);
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Thrown when a step exceeds its `timeoutMs` limit (either set per-step or
|
|
34
|
+
* via `RunOptions.stepTimeoutMs`). The workflow will roll back after this error.
|
|
35
|
+
*/
|
|
36
|
+
export declare class StepTimeoutError extends WorkflowError {
|
|
37
|
+
readonly stepId: string;
|
|
38
|
+
readonly timeoutMs: number;
|
|
39
|
+
constructor(stepId: string, timeoutMs: number);
|
|
40
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { LedgerEvent } from "./ledger";
|
|
2
|
-
export type { LedgerEntry, IStorageAdapter } from "./ledger";
|
|
1
|
+
export { LedgerEvent, RunStatus } from "./ledger";
|
|
2
|
+
export type { LedgerEntry, IStorageAdapter, RunDetails, ListRunsOptions } from "./ledger";
|
|
3
3
|
export { LogLevel, ConsoleLogger, noopLogger } from "./logger";
|
|
4
4
|
export type { ILogger } from "./logger";
|
|
5
|
-
export { Workflow, WorkflowStatus } from "./workflow";
|
|
6
|
-
export type { WorkflowRunContext, WorkflowStep, WorkflowCheckpoint, WorkflowDeps, WorkflowHooks, } from "./workflow";
|
|
7
|
-
export { buildStep, resolveExecClient, shouldSnapshot, waitForSnapshot } from "./steps";
|
|
5
|
+
export { Workflow, WorkflowStatus, mergeHooks } from "./workflow";
|
|
6
|
+
export type { WorkflowRunContext, WorkflowStep, WorkflowCheckpoint, WorkflowDeps, WorkflowHooks, WorkflowHookInfo, StepHookInfo, StepCompleteHookInfo, StepFailedHookInfo, WorkflowCompleteHookInfo, WorkflowFailedHookInfo, } from "./workflow";
|
|
7
|
+
export { buildStep, resolveExecClient, shouldSnapshot, waitForSnapshot, StepType, Encoding, Backoff } from "./steps";
|
|
8
8
|
export type { StepDef, Predicate, WorkflowState, SnapshotConfig } from "./steps";
|
|
9
9
|
export { validateWorkflow } from "./validate";
|
|
10
|
-
export { WorkflowError, SandboxError, ExecConnectionError, CommandError } from "./errors";
|
|
10
|
+
export { WorkflowError, SandboxError, ExecConnectionError, CommandError, StepTimeoutError } from "./errors";
|
package/dist/ledger.d.ts
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
/** Status of a workflow run derived from its ledger events. */
|
|
2
|
+
export declare enum RunStatus {
|
|
3
|
+
Running = "running",
|
|
4
|
+
Completed = "completed",
|
|
5
|
+
Failed = "failed",
|
|
6
|
+
Cancelled = "cancelled"
|
|
7
|
+
}
|
|
8
|
+
/** Derived metadata for a workflow run, computed from its ledger events. */
|
|
9
|
+
export interface RunDetails {
|
|
10
|
+
workflowName: string;
|
|
11
|
+
runId: string;
|
|
12
|
+
status: RunStatus;
|
|
13
|
+
/** Unix timestamp (ms) of the `run_started` event. */
|
|
14
|
+
startedAt: number;
|
|
15
|
+
/** Unix timestamp (ms) of the terminal event, if the run has ended. */
|
|
16
|
+
completedAt?: number;
|
|
17
|
+
/** Number of steps that completed successfully. */
|
|
18
|
+
stepCount: number;
|
|
19
|
+
/** Error message, present when status is `Failed`. */
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Options for filtering run listings. */
|
|
23
|
+
export interface ListRunsOptions {
|
|
24
|
+
status?: RunStatus;
|
|
25
|
+
/** Max number of results to return. */
|
|
26
|
+
limit?: number;
|
|
27
|
+
/** Return only runs that started before this Unix timestamp (ms). */
|
|
28
|
+
before?: number;
|
|
29
|
+
}
|
|
1
30
|
/** Events emitted during workflow execution and stored in the ledger. */
|
|
2
31
|
export declare enum LedgerEvent {
|
|
3
32
|
/** Emitted once when a workflow run starts, before any steps execute. */
|
|
@@ -62,6 +91,12 @@ export interface IStorageAdapter {
|
|
|
62
91
|
readAll(workflowName: string, runId: string): Promise<LedgerEntry[]>;
|
|
63
92
|
/** Return the most recent checkpoint entry for a run, or `null` if none exists. */
|
|
64
93
|
lastCheckpoint(workflowName: string, runId: string): Promise<LedgerEntry | null>;
|
|
65
|
-
/** Return
|
|
66
|
-
|
|
94
|
+
/** Return details for all runs of a workflow, newest first. */
|
|
95
|
+
listRunDetails(workflowName: string, opts?: ListRunsOptions): Promise<RunDetails[]>;
|
|
96
|
+
/** Return details for runs across all workflows, newest first. */
|
|
97
|
+
listAllRunDetails(opts?: ListRunsOptions): Promise<RunDetails[]>;
|
|
98
|
+
/** Return details for a single run, or `null` if not found. */
|
|
99
|
+
getRunDetails(workflowName: string, runId: string): Promise<RunDetails | null>;
|
|
100
|
+
/** Delete all ledger events for a run. */
|
|
101
|
+
deleteRun(workflowName: string, runId: string): Promise<void>;
|
|
67
102
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WorkflowStep } from "../workflow";
|
|
2
|
+
import { StepType, type StepDef } from "./types";
|
|
3
|
+
type BuildStepFn = (def: StepDef) => WorkflowStep;
|
|
4
|
+
export declare function buildRetryStep(def: Extract<StepDef, {
|
|
5
|
+
type: StepType.Retry;
|
|
6
|
+
}>, buildStepFn: BuildStepFn): WorkflowStep;
|
|
7
|
+
export declare function buildConditionalStep(def: Extract<StepDef, {
|
|
8
|
+
type: StepType.Conditional;
|
|
9
|
+
}>, buildStepFn: BuildStepFn): WorkflowStep;
|
|
10
|
+
export declare function buildLoopStep(def: Extract<StepDef, {
|
|
11
|
+
type: StepType.Loop;
|
|
12
|
+
}>, buildStepFn: BuildStepFn): WorkflowStep;
|
|
13
|
+
export declare function buildParallelStep(def: Extract<StepDef, {
|
|
14
|
+
type: StepType.Parallel;
|
|
15
|
+
}>, buildStepFn: BuildStepFn): WorkflowStep;
|
|
16
|
+
export declare function buildSequenceStep(def: Extract<StepDef, {
|
|
17
|
+
type: StepType.Sequence;
|
|
18
|
+
}>, buildStepFn: BuildStepFn): WorkflowStep;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { WorkflowStep } from "../workflow";
|
|
2
|
+
import { StepType, type StepDef } from "./types";
|
|
3
|
+
export declare function buildExecCommandStep(def: Extract<StepDef, {
|
|
4
|
+
type: StepType.ExecCommand;
|
|
5
|
+
}>): WorkflowStep;
|
|
6
|
+
export declare function buildExecCodeStep(def: Extract<StepDef, {
|
|
7
|
+
type: StepType.ExecCode;
|
|
8
|
+
}>): WorkflowStep;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { WorkflowStep } from "../workflow";
|
|
2
|
+
import { StepType, type StepDef } from "./types";
|
|
3
|
+
export declare function buildWriteFileStep(def: Extract<StepDef, {
|
|
4
|
+
type: StepType.WriteFile;
|
|
5
|
+
}>): WorkflowStep;
|
|
6
|
+
export declare function buildReadFileStep(def: Extract<StepDef, {
|
|
7
|
+
type: StepType.ReadFile;
|
|
8
|
+
}>): WorkflowStep;
|
|
9
|
+
export declare function buildDeleteFileStep(def: Extract<StepDef, {
|
|
10
|
+
type: StepType.DeleteFile;
|
|
11
|
+
}>): WorkflowStep;
|
|
12
|
+
export declare function buildMoveFileStep(def: Extract<StepDef, {
|
|
13
|
+
type: StepType.MoveFile;
|
|
14
|
+
}>): WorkflowStep;
|
|
15
|
+
export declare function buildListDirectoryStep(def: Extract<StepDef, {
|
|
16
|
+
type: StepType.ListDirectory;
|
|
17
|
+
}>): WorkflowStep;
|
|
18
|
+
export declare function buildSearchFilesStep(def: Extract<StepDef, {
|
|
19
|
+
type: StepType.SearchFiles;
|
|
20
|
+
}>): WorkflowStep;
|
|
21
|
+
export declare function buildCreateDirectoryStep(def: Extract<StepDef, {
|
|
22
|
+
type: StepType.CreateDirectory;
|
|
23
|
+
}>): WorkflowStep;
|
|
24
|
+
export declare function buildDeleteDirectoryStep(def: Extract<StepDef, {
|
|
25
|
+
type: StepType.DeleteDirectory;
|
|
26
|
+
}>): WorkflowStep;
|
|
27
|
+
export declare function buildSetPermissionsStep(def: Extract<StepDef, {
|
|
28
|
+
type: StepType.SetPermissions;
|
|
29
|
+
}>): WorkflowStep;
|
|
30
|
+
export declare function buildReplaceInFilesStep(def: Extract<StepDef, {
|
|
31
|
+
type: StepType.ReplaceInFiles;
|
|
32
|
+
}>): WorkflowStep;
|
|
33
|
+
export declare function buildGetFileInfoStep(def: Extract<StepDef, {
|
|
34
|
+
type: StepType.GetFileInfo;
|
|
35
|
+
}>): WorkflowStep;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { WorkflowStep } from "../workflow";
|
|
2
|
+
import { type StepDef } from "./types";
|
|
3
|
+
export declare function buildStep(def: StepDef): WorkflowStep;
|
|
4
|
+
export { StepType, Encoding, Backoff } from "./types";
|
|
5
|
+
export type { StepDef, Predicate, WorkflowState, SnapshotConfig } from "./types";
|
|
6
|
+
export { resolveExecClient } from "./sandbox";
|
|
7
|
+
export { shouldSnapshot, waitForSnapshot } from "./snapshot";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ControlClient, ExecClient } from "@drej/opensandbox";
|
|
2
|
+
import type { WorkflowStep } from "../workflow";
|
|
3
|
+
import { StepType, type StepDef } from "./types";
|
|
4
|
+
export declare function resolveExecClient(control: ControlClient, sandboxId: string, retries?: number, delayMs?: number): Promise<ExecClient>;
|
|
5
|
+
export declare function buildCreateSandboxStep(def: Extract<StepDef, {
|
|
6
|
+
type: StepType.CreateSandbox;
|
|
7
|
+
}>): WorkflowStep;
|
|
8
|
+
export declare function buildDeleteSandboxStep(): WorkflowStep;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ControlClient } from "@drej/opensandbox";
|
|
2
|
+
import type { WorkflowStep } from "../workflow";
|
|
3
|
+
import { type SnapshotConfig } from "./types";
|
|
4
|
+
export declare function shouldSnapshot(config: SnapshotConfig, stepIndex: number): boolean;
|
|
5
|
+
export declare function waitForSnapshot(control: ControlClient, snapshotId: string, timeoutMs?: number): Promise<void>;
|
|
6
|
+
export declare function buildSnapshotStep(): WorkflowStep;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { CodeLanguage } from "@drej/opensandbox";
|
|
2
|
+
export type Predicate = {
|
|
3
|
+
op: "eq" | "neq";
|
|
4
|
+
field: string;
|
|
5
|
+
value: unknown;
|
|
6
|
+
} | {
|
|
7
|
+
op: "gt" | "lt" | "gte" | "lte";
|
|
8
|
+
field: string;
|
|
9
|
+
value: number;
|
|
10
|
+
} | {
|
|
11
|
+
op: "exists" | "not_exists";
|
|
12
|
+
field: string;
|
|
13
|
+
} | {
|
|
14
|
+
op: "and" | "or";
|
|
15
|
+
predicates: Predicate[];
|
|
16
|
+
};
|
|
17
|
+
export declare enum StepType {
|
|
18
|
+
CreateSandbox = "create_sandbox",
|
|
19
|
+
ExecCode = "exec_code",
|
|
20
|
+
ExecCommand = "exec_command",
|
|
21
|
+
DeleteSandbox = "delete_sandbox",
|
|
22
|
+
WriteFile = "write_file",
|
|
23
|
+
ReadFile = "read_file",
|
|
24
|
+
DeleteFile = "delete_file",
|
|
25
|
+
MoveFile = "move_file",
|
|
26
|
+
ListDirectory = "list_directory",
|
|
27
|
+
SearchFiles = "search_files",
|
|
28
|
+
CreateDirectory = "create_directory",
|
|
29
|
+
DeleteDirectory = "delete_directory",
|
|
30
|
+
SetPermissions = "set_permissions",
|
|
31
|
+
ReplaceInFiles = "replace_in_files",
|
|
32
|
+
GetFileInfo = "get_file_info",
|
|
33
|
+
Snapshot = "snapshot",
|
|
34
|
+
Retry = "retry",
|
|
35
|
+
Conditional = "conditional",
|
|
36
|
+
Loop = "loop",
|
|
37
|
+
Parallel = "parallel",
|
|
38
|
+
Sequence = "sequence"
|
|
39
|
+
}
|
|
40
|
+
export declare enum Encoding {
|
|
41
|
+
UTF8 = "utf8",
|
|
42
|
+
Base64 = "base64"
|
|
43
|
+
}
|
|
44
|
+
export declare enum Backoff {
|
|
45
|
+
Fixed = "fixed",
|
|
46
|
+
Exponential = "exponential"
|
|
47
|
+
}
|
|
48
|
+
export type StepDef = {
|
|
49
|
+
type: StepType.CreateSandbox;
|
|
50
|
+
image?: {
|
|
51
|
+
uri: string;
|
|
52
|
+
auth?: {
|
|
53
|
+
username: string;
|
|
54
|
+
password: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
snapshotId?: string;
|
|
58
|
+
timeout?: number;
|
|
59
|
+
entrypoint?: string[];
|
|
60
|
+
env?: Record<string, string>;
|
|
61
|
+
metadata?: Record<string, string>;
|
|
62
|
+
resourceLimits?: {
|
|
63
|
+
cpu?: string;
|
|
64
|
+
memory?: string;
|
|
65
|
+
gpu?: string;
|
|
66
|
+
};
|
|
67
|
+
} | {
|
|
68
|
+
type: StepType.ExecCode;
|
|
69
|
+
code: string;
|
|
70
|
+
context?: {
|
|
71
|
+
id: string;
|
|
72
|
+
language: CodeLanguage;
|
|
73
|
+
};
|
|
74
|
+
timeoutMs?: number;
|
|
75
|
+
} | {
|
|
76
|
+
type: StepType.ExecCommand;
|
|
77
|
+
command: string;
|
|
78
|
+
cwd?: string;
|
|
79
|
+
envs?: Record<string, string>;
|
|
80
|
+
capture?: string;
|
|
81
|
+
strict?: boolean;
|
|
82
|
+
timeoutMs?: number;
|
|
83
|
+
} | {
|
|
84
|
+
type: StepType.DeleteSandbox;
|
|
85
|
+
} | {
|
|
86
|
+
type: StepType.WriteFile;
|
|
87
|
+
path: string;
|
|
88
|
+
content: string;
|
|
89
|
+
encoding?: Encoding;
|
|
90
|
+
timeoutMs?: number;
|
|
91
|
+
} | {
|
|
92
|
+
type: StepType.ReadFile;
|
|
93
|
+
path: string;
|
|
94
|
+
as: string;
|
|
95
|
+
encoding?: Encoding;
|
|
96
|
+
timeoutMs?: number;
|
|
97
|
+
} | {
|
|
98
|
+
type: StepType.DeleteFile;
|
|
99
|
+
path: string;
|
|
100
|
+
timeoutMs?: number;
|
|
101
|
+
} | {
|
|
102
|
+
type: StepType.MoveFile;
|
|
103
|
+
from: string;
|
|
104
|
+
to: string;
|
|
105
|
+
timeoutMs?: number;
|
|
106
|
+
} | {
|
|
107
|
+
type: StepType.ListDirectory;
|
|
108
|
+
path: string;
|
|
109
|
+
as: string;
|
|
110
|
+
depth?: number;
|
|
111
|
+
timeoutMs?: number;
|
|
112
|
+
} | {
|
|
113
|
+
type: StepType.SearchFiles;
|
|
114
|
+
pattern: string;
|
|
115
|
+
as: string;
|
|
116
|
+
dir?: string;
|
|
117
|
+
timeoutMs?: number;
|
|
118
|
+
} | {
|
|
119
|
+
type: StepType.CreateDirectory;
|
|
120
|
+
path: string;
|
|
121
|
+
timeoutMs?: number;
|
|
122
|
+
} | {
|
|
123
|
+
type: StepType.DeleteDirectory;
|
|
124
|
+
path: string;
|
|
125
|
+
timeoutMs?: number;
|
|
126
|
+
} | {
|
|
127
|
+
type: StepType.SetPermissions;
|
|
128
|
+
path: string;
|
|
129
|
+
mode: string;
|
|
130
|
+
timeoutMs?: number;
|
|
131
|
+
} | {
|
|
132
|
+
type: StepType.ReplaceInFiles;
|
|
133
|
+
replacements: Array<{
|
|
134
|
+
path: string;
|
|
135
|
+
old: string;
|
|
136
|
+
new: string;
|
|
137
|
+
}>;
|
|
138
|
+
timeoutMs?: number;
|
|
139
|
+
} | {
|
|
140
|
+
type: StepType.GetFileInfo;
|
|
141
|
+
path: string;
|
|
142
|
+
as: string;
|
|
143
|
+
timeoutMs?: number;
|
|
144
|
+
} | {
|
|
145
|
+
type: StepType.Snapshot;
|
|
146
|
+
} | {
|
|
147
|
+
type: StepType.Retry;
|
|
148
|
+
step: StepDef;
|
|
149
|
+
maxAttempts: number;
|
|
150
|
+
delayMs?: number;
|
|
151
|
+
backoff?: Backoff;
|
|
152
|
+
} | {
|
|
153
|
+
type: StepType.Conditional;
|
|
154
|
+
condition: Predicate;
|
|
155
|
+
then: StepDef[];
|
|
156
|
+
else?: StepDef[];
|
|
157
|
+
} | {
|
|
158
|
+
type: StepType.Loop;
|
|
159
|
+
over?: string;
|
|
160
|
+
items?: unknown[];
|
|
161
|
+
as: string;
|
|
162
|
+
steps: StepDef[];
|
|
163
|
+
maxConcurrency?: number;
|
|
164
|
+
} | {
|
|
165
|
+
type: StepType.Parallel;
|
|
166
|
+
steps: StepDef[];
|
|
167
|
+
maxConcurrency?: number;
|
|
168
|
+
} | {
|
|
169
|
+
type: StepType.Sequence;
|
|
170
|
+
steps: StepDef[];
|
|
171
|
+
};
|
|
172
|
+
export type WorkflowState = Record<string, unknown> & {
|
|
173
|
+
sandboxId?: string;
|
|
174
|
+
};
|
|
175
|
+
export interface SnapshotConfig {
|
|
176
|
+
afterSteps?: number[];
|
|
177
|
+
everyNSteps?: number;
|
|
178
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Predicate, WorkflowState } from "./types";
|
|
2
|
+
export declare function getPath(obj: unknown, path: string): unknown;
|
|
3
|
+
export declare function interpolate(template: string, state: WorkflowState): string;
|
|
4
|
+
export declare function evaluate(predicate: Predicate, state: unknown): boolean;
|
|
5
|
+
export declare function runWithConcurrency<T>(tasks: Array<() => Promise<T>>, max: number): Promise<T[]>;
|
package/dist/validate.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type StepDef } from "./steps";
|
|
2
2
|
export declare function validateWorkflow(name: string, steps: StepDef[]): void;
|
package/dist/workflow.d.ts
CHANGED
|
@@ -11,6 +11,13 @@ export interface WorkflowRunContext {
|
|
|
11
11
|
}
|
|
12
12
|
export interface WorkflowStep {
|
|
13
13
|
readonly id: string;
|
|
14
|
+
/**
|
|
15
|
+
* Maximum milliseconds this step may run. When exceeded, an `AbortSignal`
|
|
16
|
+
* fires on the step's execution context and `StepTimeoutError` is thrown.
|
|
17
|
+
* Set per-step in the builder (`exec("cmd", { timeoutMs: 5000 })`) or as a
|
|
18
|
+
* global default via `RunOptions.stepTimeoutMs`.
|
|
19
|
+
*/
|
|
20
|
+
readonly timeoutMs?: number;
|
|
14
21
|
run(input: unknown, ctx: WorkflowRunContext): Promise<unknown>;
|
|
15
22
|
rollback?(output: unknown, ctx: WorkflowRunContext): Promise<void>;
|
|
16
23
|
}
|
|
@@ -31,50 +38,50 @@ export declare enum WorkflowStatus {
|
|
|
31
38
|
Failed = "failed",
|
|
32
39
|
RolledBack = "rolled_back"
|
|
33
40
|
}
|
|
41
|
+
export interface WorkflowHookInfo {
|
|
42
|
+
workflowName: string;
|
|
43
|
+
runId: string;
|
|
44
|
+
}
|
|
45
|
+
export interface StepHookInfo extends WorkflowHookInfo {
|
|
46
|
+
stepIndex: number;
|
|
47
|
+
stepId: string;
|
|
48
|
+
}
|
|
49
|
+
export interface StepCompleteHookInfo extends StepHookInfo {
|
|
50
|
+
output: unknown;
|
|
51
|
+
}
|
|
52
|
+
export interface StepFailedHookInfo extends StepHookInfo {
|
|
53
|
+
error: Error;
|
|
54
|
+
}
|
|
55
|
+
export interface WorkflowCompleteHookInfo extends WorkflowHookInfo {
|
|
56
|
+
output: unknown;
|
|
57
|
+
}
|
|
58
|
+
export interface WorkflowFailedHookInfo extends WorkflowHookInfo {
|
|
59
|
+
error: Error;
|
|
60
|
+
}
|
|
34
61
|
export interface WorkflowHooks {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
workflowName: string;
|
|
43
|
-
runId: string;
|
|
44
|
-
stepIndex: number;
|
|
45
|
-
stepId: string;
|
|
46
|
-
output: unknown;
|
|
47
|
-
}): void | Promise<void>;
|
|
48
|
-
onStepFailed?(info: {
|
|
49
|
-
workflowName: string;
|
|
50
|
-
runId: string;
|
|
51
|
-
stepIndex: number;
|
|
52
|
-
stepId: string;
|
|
53
|
-
error: Error;
|
|
54
|
-
}): void | Promise<void>;
|
|
55
|
-
onStepRolledBack?(info: {
|
|
56
|
-
workflowName: string;
|
|
57
|
-
runId: string;
|
|
58
|
-
stepIndex: number;
|
|
59
|
-
stepId: string;
|
|
60
|
-
}): void | Promise<void>;
|
|
61
|
-
onWorkflowComplete?(info: {
|
|
62
|
-
workflowName: string;
|
|
63
|
-
runId: string;
|
|
64
|
-
output: unknown;
|
|
65
|
-
}): void | Promise<void>;
|
|
66
|
-
onWorkflowFailed?(info: {
|
|
67
|
-
workflowName: string;
|
|
68
|
-
runId: string;
|
|
69
|
-
error: Error;
|
|
70
|
-
}): void | Promise<void>;
|
|
62
|
+
onWorkflowStart?(info: WorkflowHookInfo): void | Promise<void>;
|
|
63
|
+
onStepStart?(info: StepHookInfo): void | Promise<void>;
|
|
64
|
+
onStepComplete?(info: StepCompleteHookInfo): void | Promise<void>;
|
|
65
|
+
onStepFailed?(info: StepFailedHookInfo): void | Promise<void>;
|
|
66
|
+
onStepRolledBack?(info: StepHookInfo): void | Promise<void>;
|
|
67
|
+
onWorkflowComplete?(info: WorkflowCompleteHookInfo): void | Promise<void>;
|
|
68
|
+
onWorkflowFailed?(info: WorkflowFailedHookInfo): void | Promise<void>;
|
|
71
69
|
}
|
|
70
|
+
export declare function mergeHooks(...hooks: (WorkflowHooks | undefined)[]): WorkflowHooks;
|
|
72
71
|
export interface WorkflowDeps {
|
|
73
72
|
control: ControlClient;
|
|
74
73
|
resolveExec: (sandboxId: string) => Promise<ExecClient>;
|
|
75
74
|
adapter: IStorageAdapter;
|
|
76
75
|
logger?: ILogger;
|
|
77
76
|
hooks?: WorkflowHooks;
|
|
77
|
+
/** Global per-step timeout in ms. Applied to any step that does not set its own `timeoutMs`. */
|
|
78
|
+
stepTimeoutMs?: number;
|
|
79
|
+
/**
|
|
80
|
+
* External abort signal. When fired, the current in-flight step is aborted
|
|
81
|
+
* via its per-step `AbortController` and `StepTimeoutError` (or the signal's
|
|
82
|
+
* reason) propagates out of `Workflow.run()`.
|
|
83
|
+
*/
|
|
84
|
+
signal?: AbortSignal;
|
|
78
85
|
}
|
|
79
86
|
export declare class Workflow {
|
|
80
87
|
private readonly steps;
|
package/package.json
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drej/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"main": "./src/index.ts",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
|
-
"publishConfig": {
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
10
12
|
"scripts": {
|
|
11
|
-
"build:types": "tsc --project tsconfig.build.json"
|
|
13
|
+
"build:types": "tsc --project tsconfig.build.json",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:watch": "vitest"
|
|
12
16
|
},
|
|
13
17
|
"dependencies": {
|
|
14
18
|
"@drej/opensandbox": "workspace:*"
|
|
15
19
|
},
|
|
16
20
|
"devDependencies": {
|
|
17
|
-
"bun-types": "
|
|
18
|
-
"typescript": "
|
|
21
|
+
"bun-types": "1.3.14",
|
|
22
|
+
"typescript": "6.0.3",
|
|
23
|
+
"vitest": "4.1.9"
|
|
19
24
|
}
|
|
20
25
|
}
|
package/dist/steps.d.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { ControlClient, ExecClient } from "@drej/opensandbox";
|
|
2
|
-
import type { WorkflowStep } from "./workflow";
|
|
3
|
-
export type Predicate = {
|
|
4
|
-
op: "eq" | "neq";
|
|
5
|
-
field: string;
|
|
6
|
-
value: unknown;
|
|
7
|
-
} | {
|
|
8
|
-
op: "gt" | "lt" | "gte" | "lte";
|
|
9
|
-
field: string;
|
|
10
|
-
value: number;
|
|
11
|
-
} | {
|
|
12
|
-
op: "exists" | "not_exists";
|
|
13
|
-
field: string;
|
|
14
|
-
} | {
|
|
15
|
-
op: "and" | "or";
|
|
16
|
-
predicates: Predicate[];
|
|
17
|
-
};
|
|
18
|
-
export type StepDef = {
|
|
19
|
-
type: "create_sandbox";
|
|
20
|
-
image?: {
|
|
21
|
-
uri: string;
|
|
22
|
-
auth?: {
|
|
23
|
-
username: string;
|
|
24
|
-
password: string;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
snapshotId?: string;
|
|
28
|
-
timeout?: number;
|
|
29
|
-
entrypoint?: string[];
|
|
30
|
-
env?: Record<string, string>;
|
|
31
|
-
metadata?: Record<string, string>;
|
|
32
|
-
resourceLimits?: {
|
|
33
|
-
cpu?: string;
|
|
34
|
-
memory?: string;
|
|
35
|
-
gpu?: string;
|
|
36
|
-
};
|
|
37
|
-
} | {
|
|
38
|
-
type: "exec_code";
|
|
39
|
-
code: string;
|
|
40
|
-
context?: {
|
|
41
|
-
id: string;
|
|
42
|
-
language: string;
|
|
43
|
-
};
|
|
44
|
-
} | {
|
|
45
|
-
type: "exec_command";
|
|
46
|
-
command: string;
|
|
47
|
-
cwd?: string;
|
|
48
|
-
envs?: Record<string, string>;
|
|
49
|
-
capture?: string;
|
|
50
|
-
strict?: boolean;
|
|
51
|
-
} | {
|
|
52
|
-
type: "delete_sandbox";
|
|
53
|
-
} | {
|
|
54
|
-
type: "write_file";
|
|
55
|
-
path: string;
|
|
56
|
-
content: string;
|
|
57
|
-
encoding?: "utf8" | "base64";
|
|
58
|
-
} | {
|
|
59
|
-
type: "read_file";
|
|
60
|
-
path: string;
|
|
61
|
-
as: string;
|
|
62
|
-
encoding?: "utf8" | "base64";
|
|
63
|
-
} | {
|
|
64
|
-
type: "snapshot";
|
|
65
|
-
} | {
|
|
66
|
-
type: "retry";
|
|
67
|
-
step: StepDef;
|
|
68
|
-
maxAttempts: number;
|
|
69
|
-
delayMs?: number;
|
|
70
|
-
backoff?: "fixed" | "exponential";
|
|
71
|
-
} | {
|
|
72
|
-
type: "conditional";
|
|
73
|
-
condition: Predicate;
|
|
74
|
-
then: StepDef[];
|
|
75
|
-
else?: StepDef[];
|
|
76
|
-
} | {
|
|
77
|
-
type: "loop";
|
|
78
|
-
over?: string;
|
|
79
|
-
items?: unknown[];
|
|
80
|
-
as: string;
|
|
81
|
-
steps: StepDef[];
|
|
82
|
-
concurrently?: boolean;
|
|
83
|
-
} | {
|
|
84
|
-
type: "parallel";
|
|
85
|
-
steps: StepDef[];
|
|
86
|
-
} | {
|
|
87
|
-
type: "sequence";
|
|
88
|
-
steps: StepDef[];
|
|
89
|
-
};
|
|
90
|
-
export type WorkflowState = Record<string, unknown> & {
|
|
91
|
-
sandboxId?: string;
|
|
92
|
-
};
|
|
93
|
-
export interface SnapshotConfig {
|
|
94
|
-
afterSteps?: number[];
|
|
95
|
-
everyNSteps?: number;
|
|
96
|
-
}
|
|
97
|
-
export declare function resolveExecClient(control: ControlClient, sandboxId: string, retries?: number, delayMs?: number): Promise<ExecClient>;
|
|
98
|
-
export declare function shouldSnapshot(config: SnapshotConfig, stepIndex: number): boolean;
|
|
99
|
-
export declare function waitForSnapshot(control: ControlClient, snapshotId: string, timeoutMs?: number): Promise<void>;
|
|
100
|
-
export declare function buildStep(def: StepDef): WorkflowStep;
|