@cascade-flow/runner 0.1.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/README.md +104 -0
- package/dist/discovery.d.ts +25 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13085 -0
- package/dist/index.js.map +80 -0
- package/dist/step-executor.d.ts +25 -0
- package/dist/step-executor.d.ts.map +1 -0
- package/dist/subprocess-executor.d.ts +26 -0
- package/dist/subprocess-executor.d.ts.map +1 -0
- package/dist/types.d.ts +127 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validation.d.ts +13 -0
- package/dist/validation.d.ts.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Runner
|
|
2
|
+
|
|
3
|
+
Core workflow execution engine for direct (non-queue) execution.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { runAll, defineStep, baseDefineStep } from "runner";
|
|
15
|
+
|
|
16
|
+
// Execute workflow
|
|
17
|
+
const results = await runAll({
|
|
18
|
+
workflow: "my-workflow",
|
|
19
|
+
input: { userId: "123" },
|
|
20
|
+
only: ["step1", "step2"], // Optional: run subset
|
|
21
|
+
resume: true, // Optional: resume from previous run
|
|
22
|
+
runId: "previous-run-id", // Optional: specific run to resume
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Defining Steps
|
|
27
|
+
|
|
28
|
+
### Basic Step
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
// workflows/my-workflow/steps/my-step/step.ts
|
|
32
|
+
import { defineStep } from "runner";
|
|
33
|
+
import { step as dependency } from "../other-step/step.ts";
|
|
34
|
+
|
|
35
|
+
export const step = defineStep({
|
|
36
|
+
dependencies: { dependency },
|
|
37
|
+
exportOutput: true,
|
|
38
|
+
fn: async ({ dependencies, ctx }) => {
|
|
39
|
+
return { result: dependencies.dependency.value * 2 };
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Typed Workflow Input
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// workflows/my-workflow/input-schema.ts
|
|
48
|
+
import { z } from "zod";
|
|
49
|
+
export const inputSchema = z.object({
|
|
50
|
+
userId: z.string(),
|
|
51
|
+
count: z.number()
|
|
52
|
+
});
|
|
53
|
+
export type WorkflowInput = z.infer<typeof inputSchema>;
|
|
54
|
+
|
|
55
|
+
// workflows/my-workflow/defineStep.ts
|
|
56
|
+
import { baseDefineStep } from "runner";
|
|
57
|
+
import type { WorkflowInput } from "./input-schema";
|
|
58
|
+
export const defineStep = baseDefineStep<WorkflowInput>();
|
|
59
|
+
|
|
60
|
+
// workflows/my-workflow/steps/my-step/step.ts
|
|
61
|
+
import { defineStep } from "../../defineStep";
|
|
62
|
+
|
|
63
|
+
export const step = defineStep({
|
|
64
|
+
fn: async ({ ctx }) => {
|
|
65
|
+
const userId = ctx.input.userId; // Fully typed!
|
|
66
|
+
return { processed: true };
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Workflow Structure
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
workflows/my-workflow/
|
|
75
|
+
├── workflow.json # {"name": "My Workflow"}
|
|
76
|
+
├── input-schema.ts # Optional: Zod schema
|
|
77
|
+
├── defineStep.ts # Optional: Typed helper
|
|
78
|
+
└── steps/
|
|
79
|
+
├── step-1/step.ts
|
|
80
|
+
└── step-2/step.ts
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Key Features
|
|
84
|
+
|
|
85
|
+
- **Promise caching** - Automatic parallelization via cached promises
|
|
86
|
+
- **Type-safe dependencies** - Import step objects for full TypeScript inference
|
|
87
|
+
- **Cycle detection** - DFS validation prevents circular dependencies
|
|
88
|
+
- **Resume capability** - Continue from previous runs
|
|
89
|
+
- **Pluggable backend** - Abstract persistence layer
|
|
90
|
+
|
|
91
|
+
## Exports
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// Main execution
|
|
95
|
+
runAll(options: RunAllOptions): Promise<WorkflowOutput>;
|
|
96
|
+
|
|
97
|
+
// Step helpers
|
|
98
|
+
defineStep(config: StepConfig): StepDefinition;
|
|
99
|
+
baseDefineStep<TInput>(): typeof defineStep;
|
|
100
|
+
|
|
101
|
+
// Discovery
|
|
102
|
+
discoverWorkflows(dir?: string): Promise<WorkflowMetadata[]>;
|
|
103
|
+
discoverSteps(workflowDir: string): Promise<LoadedStep[]>;
|
|
104
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type LoadedStep, type WorkflowConfig, type LocalWorkflowMetadata } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Loads and validates a workflow.json configuration file using Zod
|
|
4
|
+
*
|
|
5
|
+
* @param workflowDir - Path to the workflow directory
|
|
6
|
+
* @returns Parsed and validated workflow configuration
|
|
7
|
+
* @throws Error if workflow.json is missing or invalid
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadWorkflowConfig(workflowDir: string): Promise<WorkflowConfig>;
|
|
10
|
+
/**
|
|
11
|
+
* Discovers all workflows in the workflows directory
|
|
12
|
+
*
|
|
13
|
+
* @param workflowsRoot - Root directory containing workflow subdirectories (defaults to "./workflows")
|
|
14
|
+
* @returns Array of local workflow metadata for all discovered workflows
|
|
15
|
+
* @throws Error if workflows directory doesn't exist
|
|
16
|
+
*/
|
|
17
|
+
export declare function discoverWorkflows(workflowsRoot?: string): Promise<LocalWorkflowMetadata[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Discovers and loads all steps from a directory
|
|
20
|
+
*
|
|
21
|
+
* @param root - Root directory containing step subdirectories (defaults to "./steps")
|
|
22
|
+
* @returns Array of loaded steps with wired dependencies
|
|
23
|
+
*/
|
|
24
|
+
export declare function discoverSteps(root?: string): Promise<LoadedStep[]>;
|
|
25
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAMA,OAAO,EAA0C,KAAK,UAAU,EAAyB,KAAK,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAG1J;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,cAAc,CAAC,CA0BzB;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,aAAa,SAA4B,GACxC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAyElC;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,IAAI,SAAwB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CA2FvB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Backend, LogEntry } from "@cascade-flow/backend-interface";
|
|
2
|
+
import type { StepOutput, LoadedStep, RunnerContext } from "./types";
|
|
3
|
+
export type { LoadedStep };
|
|
4
|
+
/**
|
|
5
|
+
* Execute a step in an isolated child process
|
|
6
|
+
*
|
|
7
|
+
* Wrapper around executeStepInSubprocess that generates the output path.
|
|
8
|
+
*/
|
|
9
|
+
export declare function executeStepInProcess(stepFile: string, stepId: string, dependencies: Record<string, unknown>, ctx: RunnerContext, attemptNumber: number, backend: Backend, onLog?: (log: LogEntry) => void | Promise<void>, options?: {
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
result: StepOutput;
|
|
13
|
+
logs: LogEntry[];
|
|
14
|
+
}>;
|
|
15
|
+
export declare function runAll(options: {
|
|
16
|
+
workflow: string;
|
|
17
|
+
only?: string[];
|
|
18
|
+
ctx?: Partial<RunnerContext>;
|
|
19
|
+
resume?: boolean;
|
|
20
|
+
runId?: string;
|
|
21
|
+
backend: Backend;
|
|
22
|
+
input?: unknown;
|
|
23
|
+
}): Promise<Record<string, StepOutput>>;
|
|
24
|
+
export { discoverWorkflows, discoverSteps } from "./discovery";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAa,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAMpF,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACd,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,GAAG,EAAE,aAAa,EAClB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC/C,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACjC,OAAO,CAAC;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,QAAQ,EAAE,CAAA;CAAE,CAAC,CAoBnD;AAED,wBAAsB,MAAM,CAAC,OAAO,EAAE;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CA4ZtC;AAGD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|