@ironflow/node 0.1.0-test.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/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # @ironflow/node
2
+
3
+ Node.js SDK for [Ironflow](https://github.com/anthropics/ironflow) workflow engine. Provides workers, serve handlers, and step execution for serverless and long-running functions.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @ironflow/node
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ### Define a Function
14
+
15
+ ```typescript
16
+ import { ironflow } from '@ironflow/node';
17
+
18
+ const processOrder = ironflow.createFunction(
19
+ {
20
+ id: 'process-order',
21
+ triggers: [{ event: 'order.placed' }],
22
+ },
23
+ async ({ event, step }) => {
24
+ const validated = await step.run('validate', async () => {
25
+ return validateOrder(event.data);
26
+ });
27
+
28
+ await step.sleep('wait', '5m');
29
+
30
+ const result = await step.run('process', async () => {
31
+ return processPayment(validated);
32
+ });
33
+
34
+ return { success: true, receiptId: result.id };
35
+ }
36
+ );
37
+ ```
38
+
39
+ ### Push Mode (Serverless)
40
+
41
+ ```typescript
42
+ // app/api/ironflow/route.ts (Next.js App Router)
43
+ import { serve } from '@ironflow/node';
44
+
45
+ export const POST = serve({
46
+ functions: [processOrder],
47
+ signingKey: process.env.IRONFLOW_SIGNING_KEY,
48
+ });
49
+ ```
50
+
51
+ ### Pull Mode (Worker)
52
+
53
+ ```typescript
54
+ import { createWorker } from '@ironflow/node';
55
+
56
+ const worker = createWorker({
57
+ serverUrl: 'http://localhost:9123',
58
+ functions: [processOrder],
59
+ maxConcurrentJobs: 4,
60
+ });
61
+
62
+ await worker.start();
63
+ ```
64
+
65
+ ## Features
66
+
67
+ - **Durable step execution** with automatic memoization
68
+ - **Push mode** for serverless (Next.js, Lambda, Vercel)
69
+ - **Pull mode** for long-running workers (no timeout limits)
70
+ - **Step primitives**: `run`, `sleep`, `sleepUntil`, `waitForEvent`, `parallel`, `map`
71
+ - **Type-safe** API with full TypeScript support
72
+
73
+ ## Key APIs
74
+
75
+ | API | Description |
76
+ |-----|-------------|
77
+ | `ironflow.createFunction(config, handler)` | Define a workflow function |
78
+ | `serve({ functions })` | Create HTTP handler for push mode |
79
+ | `createWorker({ functions })` | Create pull mode worker |
80
+ | `step.run(id, fn)` | Execute memoized step |
81
+ | `step.sleep(id, duration)` | Durable sleep |
82
+ | `step.waitForEvent(id, options)` | Wait for external event |
83
+ | `step.parallel(steps)` | Execute steps in parallel |
84
+ | `step.map(id, items, fn)` | Map over items in parallel |
85
+
86
+ ## Environment Variables
87
+
88
+ | Variable | Description | Default |
89
+ |----------|-------------|---------|
90
+ | `IRONFLOW_SERVER_URL` | Server URL | `http://localhost:9123` |
91
+ | `IRONFLOW_SIGNING_KEY` | Request signing key | - |
92
+ | `IRONFLOW_LOG_LEVEL` | Log level | `info` |
93
+
94
+ ## Requirements
95
+
96
+ - Node.js 22+
97
+
98
+ ## Documentation
99
+
100
+ For the full API reference, see the [Node Package Documentation](https://ironflow.dev/docs/api-reference/js-sdk/node).
101
+
102
+ ## License
103
+
104
+ MIT
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Function definition helper for Ironflow workflows
3
+ */
4
+ import type { FunctionConfig, FunctionHandler, IronflowFunction } from "@ironflow/core";
5
+ import type { z } from "zod";
6
+ /**
7
+ * Function definition helper with full type inference
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { ironflow } from "@ironflow/node";
12
+ * import { z } from "zod";
13
+ *
14
+ * const processOrder = ironflow.createFunction(
15
+ * {
16
+ * id: "process-order",
17
+ * triggers: [{ event: "order.placed" }],
18
+ * schema: z.object({
19
+ * orderId: z.string(),
20
+ * amount: z.number(),
21
+ * }),
22
+ * },
23
+ * async ({ event, step }) => {
24
+ * // event.data is typed as { orderId: string, amount: number }
25
+ * const result = await step.run("process", async () => {
26
+ * return { processed: true };
27
+ * });
28
+ * return result;
29
+ * }
30
+ * );
31
+ * ```
32
+ */
33
+ export declare function createFunction<TEventSchema extends z.ZodType = z.ZodType<unknown>, TResult = unknown>(config: FunctionConfig<TEventSchema>, handler: FunctionHandler<z.infer<TEventSchema>, TResult>): IronflowFunction<z.infer<TEventSchema>, TResult>;
34
+ /**
35
+ * Ironflow function factory singleton
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * import { ironflow } from "@ironflow/node";
40
+ *
41
+ * const myFunction = ironflow.createFunction(
42
+ * { id: "my-function", triggers: [{ event: "my.event" }] },
43
+ * async ({ event, step }) => {
44
+ * // ...
45
+ * }
46
+ * );
47
+ * ```
48
+ */
49
+ export declare const ironflow: {
50
+ createFunction: typeof createFunction;
51
+ };
52
+ export default ironflow;
53
+ //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../src/function.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,cAAc,CAC5B,YAAY,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EACnD,OAAO,GAAG,OAAO,EAEjB,MAAM,EAAE,cAAc,CAAC,YAAY,CAAC,EACpC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,GACvD,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,CAKlD;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ;;CAEpB,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Function definition helper for Ironflow workflows
3
+ */
4
+ /**
5
+ * Function definition helper with full type inference
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { ironflow } from "@ironflow/node";
10
+ * import { z } from "zod";
11
+ *
12
+ * const processOrder = ironflow.createFunction(
13
+ * {
14
+ * id: "process-order",
15
+ * triggers: [{ event: "order.placed" }],
16
+ * schema: z.object({
17
+ * orderId: z.string(),
18
+ * amount: z.number(),
19
+ * }),
20
+ * },
21
+ * async ({ event, step }) => {
22
+ * // event.data is typed as { orderId: string, amount: number }
23
+ * const result = await step.run("process", async () => {
24
+ * return { processed: true };
25
+ * });
26
+ * return result;
27
+ * }
28
+ * );
29
+ * ```
30
+ */
31
+ export function createFunction(config, handler) {
32
+ return {
33
+ config,
34
+ handler,
35
+ };
36
+ }
37
+ /**
38
+ * Ironflow function factory singleton
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * import { ironflow } from "@ironflow/node";
43
+ *
44
+ * const myFunction = ironflow.createFunction(
45
+ * { id: "my-function", triggers: [{ event: "my.event" }] },
46
+ * async ({ event, step }) => {
47
+ * // ...
48
+ * }
49
+ * );
50
+ * ```
51
+ */
52
+ export const ironflow = {
53
+ createFunction,
54
+ };
55
+ export default ironflow;
56
+ //# sourceMappingURL=function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.js","sourceRoot":"","sources":["../src/function.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,cAAc,CAI5B,MAAoC,EACpC,OAAwD;IAExD,OAAO;QACL,MAAM;QACN,OAAO;KAC4C,CAAC;AACxD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,cAAc;CACf,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @ironflow/node
3
+ *
4
+ * Node.js SDK for Ironflow workflow engine.
5
+ * Provides workers, serve handlers, and step execution for serverless and long-running functions.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Define a workflow function
10
+ * import { ironflow } from "@ironflow/node";
11
+ *
12
+ * const processOrder = ironflow.createFunction(
13
+ * {
14
+ * id: "process-order",
15
+ * triggers: [{ event: "order.placed" }],
16
+ * },
17
+ * async ({ event, step }) => {
18
+ * const result = await step.run("process", async () => {
19
+ * return { processed: true };
20
+ * });
21
+ * return result;
22
+ * }
23
+ * );
24
+ *
25
+ * // Push mode (serverless)
26
+ * import { serve } from "@ironflow/node/serve";
27
+ * export const POST = serve({ functions: [processOrder] });
28
+ *
29
+ * // Pull mode (worker)
30
+ * import { createWorker } from "@ironflow/node/worker";
31
+ * const worker = createWorker({
32
+ * serverUrl: "http://localhost:9123",
33
+ * functions: [processOrder],
34
+ * });
35
+ * await worker.start();
36
+ * ```
37
+ *
38
+ * @packageDocumentation
39
+ */
40
+ export { ironflow, createFunction } from "./function.js";
41
+ export { serve, createHandler } from "./serve.js";
42
+ export { createWorker, createStreamingWorker } from "./worker.js";
43
+ export type { ServeConfig, HandlerOptions, HandlerContext, WorkerConfig, Worker, CreateFunctionConfig, } from "./types.js";
44
+ export type { Branded, RunId, FunctionId, StepId, EventId, JobId, WorkerId, SubscriptionId, FunctionConfig, FunctionContext, FunctionHandler, IronflowFunction, Trigger, RetryConfig, ConcurrencyConfig, ExecutionMode, IronflowEvent, EventFilter, StepClient, Duration, ParallelOptions, RunInfo, Run, RunStatus, ListRunsOptions, ListRunsResult, TriggerResult, TriggerSyncOptions, TriggerSyncResult, EmitOptions, EmitResult, Logger, PushRequest, PushResponse, CompletedStep, ResumeContext, StepResult, YieldInfo, SleepYield, WaitEventYield, } from "@ironflow/core";
45
+ export { createRunId, createFunctionId, createStepId, createEventId, createJobId, createWorkerId, createSubscriptionId, } from "@ironflow/core";
46
+ export { IronflowError, StepError, TimeoutError, ValidationError, SchemaValidationError, SignatureError, FunctionNotFoundError, RunNotFoundError, NonRetryableError, isRetryable, isIronflowError, } from "@ironflow/core";
47
+ export { parseDuration, calculateBackoff, sleep, generateId, createLogger, createNoopLogger, type LogLevel, type LoggerConfig, } from "@ironflow/core";
48
+ export { DEFAULT_PORT, DEFAULT_HOST, DEFAULT_SERVER_URL, DEFAULT_TIMEOUTS, DEFAULT_RETRY, DEFAULT_WORKER, ENV_VARS, getServerUrl, } from "@ironflow/core";
49
+ export { PushRequestSchema, RunStatusSchema, parseAndValidate, validate, } from "@ironflow/core";
50
+ declare const _default: {
51
+ ironflow: {
52
+ createFunction: typeof import("./function.js").createFunction;
53
+ };
54
+ };
55
+ export default _default;
56
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAIH,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGlE,YAAY,EACV,WAAW,EACX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,MAAM,EACN,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAGpB,YAAY,EAEV,OAAO,EACP,KAAK,EACL,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,EACL,QAAQ,EACR,cAAc,EAGd,cAAc,EACd,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,aAAa,EAGb,aAAa,EACb,WAAW,EAGX,UAAU,EACV,QAAQ,EACR,eAAe,EAGf,OAAO,EACP,GAAG,EACH,SAAS,EACT,eAAe,EACf,cAAc,EAGd,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EAGjB,WAAW,EACX,UAAU,EAGV,MAAM,EAGN,WAAW,EACX,YAAY,EACZ,aAAa,EACb,aAAa,EACb,UAAU,EACV,SAAS,EACT,UAAU,EACV,cAAc,GACf,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,cAAc,EACd,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,aAAa,EACb,SAAS,EACT,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,KAAK,QAAQ,EACb,KAAK,YAAY,GAClB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,QAAQ,EACR,YAAY,GACb,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,QAAQ,GACT,MAAM,gBAAgB,CAAC;;;;;;AAGxB,wBAA4B"}
package/dist/index.js ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @ironflow/node
3
+ *
4
+ * Node.js SDK for Ironflow workflow engine.
5
+ * Provides workers, serve handlers, and step execution for serverless and long-running functions.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Define a workflow function
10
+ * import { ironflow } from "@ironflow/node";
11
+ *
12
+ * const processOrder = ironflow.createFunction(
13
+ * {
14
+ * id: "process-order",
15
+ * triggers: [{ event: "order.placed" }],
16
+ * },
17
+ * async ({ event, step }) => {
18
+ * const result = await step.run("process", async () => {
19
+ * return { processed: true };
20
+ * });
21
+ * return result;
22
+ * }
23
+ * );
24
+ *
25
+ * // Push mode (serverless)
26
+ * import { serve } from "@ironflow/node/serve";
27
+ * export const POST = serve({ functions: [processOrder] });
28
+ *
29
+ * // Pull mode (worker)
30
+ * import { createWorker } from "@ironflow/node/worker";
31
+ * const worker = createWorker({
32
+ * serverUrl: "http://localhost:9123",
33
+ * functions: [processOrder],
34
+ * });
35
+ * await worker.start();
36
+ * ```
37
+ *
38
+ * @packageDocumentation
39
+ */
40
+ // Main exports
41
+ import { ironflow } from "./function.js";
42
+ export { ironflow, createFunction } from "./function.js";
43
+ export { serve, createHandler } from "./serve.js";
44
+ export { createWorker, createStreamingWorker } from "./worker.js";
45
+ // Re-export branded ID creators
46
+ export { createRunId, createFunctionId, createStepId, createEventId, createJobId, createWorkerId, createSubscriptionId, } from "@ironflow/core";
47
+ // Re-export errors
48
+ export { IronflowError, StepError, TimeoutError, ValidationError, SchemaValidationError, SignatureError, FunctionNotFoundError, RunNotFoundError, NonRetryableError, isRetryable, isIronflowError, } from "@ironflow/core";
49
+ // Re-export utilities
50
+ export { parseDuration, calculateBackoff, sleep, generateId, createLogger, createNoopLogger, } from "@ironflow/core";
51
+ // Re-export constants
52
+ export { DEFAULT_PORT, DEFAULT_HOST, DEFAULT_SERVER_URL, DEFAULT_TIMEOUTS, DEFAULT_RETRY, DEFAULT_WORKER, ENV_VARS, getServerUrl, } from "@ironflow/core";
53
+ // Re-export schemas for advanced usage
54
+ export { PushRequestSchema, RunStatusSchema, parseAndValidate, validate, } from "@ironflow/core";
55
+ // Default export
56
+ export default { ironflow };
57
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,eAAe;AACf,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAyElE,gCAAgC;AAChC,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,cAAc,EACd,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAExB,mBAAmB;AACnB,OAAO,EACL,aAAa,EACb,SAAS,EACT,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,sBAAsB;AACtB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,UAAU,EACV,YAAY,EACZ,gBAAgB,GAGjB,MAAM,gBAAgB,CAAC;AAExB,sBAAsB;AACtB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,QAAQ,EACR,YAAY,GACb,MAAM,gBAAgB,CAAC;AAExB,uCAAuC;AACvC,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,QAAQ,GACT,MAAM,gBAAgB,CAAC;AAExB,iBAAiB;AACjB,eAAe,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Internal Execution Context
3
+ *
4
+ * Manages step memoization and resume state during function execution.
5
+ */
6
+ import type { IronflowEvent, Logger, RunInfo, PushRequest, CompletedStep, StepResult } from "@ironflow/core";
7
+ /**
8
+ * Execution context for a function invocation
9
+ */
10
+ export declare class ExecutionContext {
11
+ /** The run ID */
12
+ readonly runId: string;
13
+ /** The function ID */
14
+ readonly functionId: string;
15
+ /** Current attempt number */
16
+ readonly attempt: number;
17
+ /** The triggering event */
18
+ readonly event: IronflowEvent;
19
+ /** Run information */
20
+ readonly runInfo: RunInfo;
21
+ /** Logger instance */
22
+ readonly logger: Logger;
23
+ /** Step counters for generating unique step IDs */
24
+ private stepCounters;
25
+ /** Completed steps from previous execution (memoized) */
26
+ private completedSteps;
27
+ /** Steps executed in this invocation */
28
+ private executedSteps;
29
+ /** Resume context for sleep/waitForEvent */
30
+ private resumeContext?;
31
+ /** Whether we've processed the resume */
32
+ private resumeProcessed;
33
+ constructor(request: PushRequest, logger?: Logger);
34
+ /**
35
+ * Generate a unique step ID
36
+ */
37
+ generateStepId(name: string): string;
38
+ /**
39
+ * Create a scoped context for a parallel branch
40
+ */
41
+ createBranchContext(parallelName: string, branchIndex: number): BranchContext;
42
+ /**
43
+ * Check if a step is already completed (memoized)
44
+ */
45
+ getCompletedStep(stepId: string): CompletedStep | undefined;
46
+ /**
47
+ * Check if we should skip step execution due to memoization
48
+ */
49
+ shouldSkipStep(stepId: string): boolean;
50
+ /**
51
+ * Get the memoized output for a step
52
+ */
53
+ getMemoizedOutput<T>(stepId: string): T | undefined;
54
+ /**
55
+ * Check if we're resuming from a specific step
56
+ */
57
+ isResumingFrom(stepId: string, type: "sleep" | "wait_for_event"): boolean;
58
+ /**
59
+ * Get the resume data (for waitForEvent)
60
+ */
61
+ getResumeData<T>(): T | undefined;
62
+ /**
63
+ * Mark the resume as processed
64
+ */
65
+ markResumeProcessed(): void;
66
+ /**
67
+ * Check if the resume has been processed
68
+ */
69
+ hasResumeBeenProcessed(): boolean;
70
+ /**
71
+ * Record a step execution result
72
+ */
73
+ recordStep(step: StepResult): void;
74
+ /**
75
+ * Get all steps executed in this invocation
76
+ */
77
+ getExecutedSteps(): StepResult[];
78
+ }
79
+ /**
80
+ * A scoped context for parallel branch execution
81
+ */
82
+ export declare class BranchContext {
83
+ private readonly parent;
84
+ private readonly scopePrefix;
85
+ private stepCounters;
86
+ get logger(): Logger;
87
+ get runId(): string;
88
+ constructor(parent: ExecutionContext, scopePrefix: string);
89
+ generateStepId(name: string): string;
90
+ shouldSkipStep(stepId: string): boolean;
91
+ getMemoizedOutput<T>(stepId: string): T | undefined;
92
+ isResumingFrom(stepId: string, type: "sleep" | "wait_for_event"): boolean;
93
+ getResumeData<T>(): T | undefined;
94
+ markResumeProcessed(): void;
95
+ recordStep(step: StepResult): void;
96
+ createBranchContext(parallelName: string, branchIndex: number): BranchContext;
97
+ }
98
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/internal/context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,MAAM,EACN,OAAO,EACP,WAAW,EACX,aAAa,EAEb,UAAU,EACX,MAAM,gBAAgB,CAAC;AAExB;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,iBAAiB;IACjB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,sBAAsB;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,6BAA6B;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,2BAA2B;IAC3B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,sBAAsB;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,mDAAmD;IACnD,OAAO,CAAC,YAAY,CAAkC;IACtD,yDAAyD;IACzD,OAAO,CAAC,cAAc,CAAyC;IAC/D,wCAAwC;IACxC,OAAO,CAAC,aAAa,CAAoB;IACzC,4CAA4C;IAC5C,OAAO,CAAC,aAAa,CAAC,CAAgB;IACtC,yCAAyC;IACzC,OAAO,CAAC,eAAe,CAAS;gBAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,MAAM;IAoCjD;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMpC;;OAEG;IACH,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,aAAa;IAK7E;;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;IAIlC,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,aAAa;CAI9E"}
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Internal Execution Context
3
+ *
4
+ * Manages step memoization and resume state during function execution.
5
+ */
6
+ /**
7
+ * Execution context for a function invocation
8
+ */
9
+ export class ExecutionContext {
10
+ /** The run ID */
11
+ runId;
12
+ /** The function ID */
13
+ functionId;
14
+ /** Current attempt number */
15
+ attempt;
16
+ /** The triggering event */
17
+ event;
18
+ /** Run information */
19
+ runInfo;
20
+ /** Logger instance */
21
+ logger;
22
+ /** Step counters for generating unique step IDs */
23
+ stepCounters = new Map();
24
+ /** Completed steps from previous execution (memoized) */
25
+ completedSteps = new Map();
26
+ /** Steps executed in this invocation */
27
+ executedSteps = [];
28
+ /** Resume context for sleep/waitForEvent */
29
+ resumeContext;
30
+ /** Whether we've processed the resume */
31
+ resumeProcessed = false;
32
+ constructor(request, logger) {
33
+ this.runId = request.run_id;
34
+ this.functionId = request.function_id;
35
+ this.attempt = request.attempt;
36
+ // Parse event
37
+ this.event = {
38
+ id: request.event.id,
39
+ name: request.event.name,
40
+ data: request.event.data,
41
+ timestamp: new Date(request.event.timestamp),
42
+ idempotencyKey: request.event.idempotency_key,
43
+ source: request.event.source,
44
+ metadata: request.event.metadata,
45
+ };
46
+ // Build run info
47
+ this.runInfo = {
48
+ id: this.runId,
49
+ functionId: this.functionId,
50
+ attempt: this.attempt,
51
+ startedAt: new Date(),
52
+ };
53
+ // Store completed steps for memoization
54
+ for (const step of request.steps) {
55
+ this.completedSteps.set(step.id, step);
56
+ }
57
+ // Store resume context
58
+ this.resumeContext = request.resume;
59
+ // Use provided logger or create default
60
+ this.logger = logger ?? createDefaultLogger(this.runId);
61
+ }
62
+ /**
63
+ * Generate a unique step ID
64
+ */
65
+ generateStepId(name) {
66
+ const index = this.stepCounters.get(name) ?? 0;
67
+ this.stepCounters.set(name, index + 1);
68
+ return `${this.runId}:${name}:${index}`;
69
+ }
70
+ /**
71
+ * Create a scoped context for a parallel branch
72
+ */
73
+ createBranchContext(parallelName, branchIndex) {
74
+ const scopePrefix = `${this.runId}:${parallelName}:${branchIndex}`;
75
+ return new BranchContext(this, scopePrefix);
76
+ }
77
+ /**
78
+ * Check if a step is already completed (memoized)
79
+ */
80
+ getCompletedStep(stepId) {
81
+ return this.completedSteps.get(stepId);
82
+ }
83
+ /**
84
+ * Check if we should skip step execution due to memoization
85
+ */
86
+ shouldSkipStep(stepId) {
87
+ const completed = this.completedSteps.get(stepId);
88
+ return completed?.status === "completed";
89
+ }
90
+ /**
91
+ * Get the memoized output for a step
92
+ */
93
+ getMemoizedOutput(stepId) {
94
+ const completed = this.completedSteps.get(stepId);
95
+ if (completed?.status === "completed") {
96
+ return completed.output;
97
+ }
98
+ return undefined;
99
+ }
100
+ /**
101
+ * Check if we're resuming from a specific step
102
+ */
103
+ isResumingFrom(stepId, type) {
104
+ if (!this.resumeContext) {
105
+ return false;
106
+ }
107
+ return (this.resumeContext.step_id === stepId && this.resumeContext.type === type);
108
+ }
109
+ /**
110
+ * Get the resume data (for waitForEvent)
111
+ */
112
+ getResumeData() {
113
+ return this.resumeContext?.data;
114
+ }
115
+ /**
116
+ * Mark the resume as processed
117
+ */
118
+ markResumeProcessed() {
119
+ this.resumeProcessed = true;
120
+ }
121
+ /**
122
+ * Check if the resume has been processed
123
+ */
124
+ hasResumeBeenProcessed() {
125
+ return this.resumeProcessed;
126
+ }
127
+ /**
128
+ * Record a step execution result
129
+ */
130
+ recordStep(step) {
131
+ this.executedSteps.push(step);
132
+ }
133
+ /**
134
+ * Get all steps executed in this invocation
135
+ */
136
+ getExecutedSteps() {
137
+ return [...this.executedSteps];
138
+ }
139
+ }
140
+ /**
141
+ * A scoped context for parallel branch execution
142
+ */
143
+ export class BranchContext {
144
+ parent;
145
+ scopePrefix;
146
+ stepCounters = new Map();
147
+ get logger() {
148
+ return this.parent.logger;
149
+ }
150
+ get runId() {
151
+ return this.parent.runId;
152
+ }
153
+ constructor(parent, scopePrefix) {
154
+ this.parent = parent;
155
+ this.scopePrefix = scopePrefix;
156
+ }
157
+ generateStepId(name) {
158
+ const index = this.stepCounters.get(name) ?? 0;
159
+ this.stepCounters.set(name, index + 1);
160
+ return `${this.scopePrefix}:${name}:${index}`;
161
+ }
162
+ shouldSkipStep(stepId) {
163
+ return this.parent.shouldSkipStep(stepId);
164
+ }
165
+ getMemoizedOutput(stepId) {
166
+ return this.parent.getMemoizedOutput(stepId);
167
+ }
168
+ isResumingFrom(stepId, type) {
169
+ return this.parent.isResumingFrom(stepId, type);
170
+ }
171
+ getResumeData() {
172
+ return this.parent.getResumeData();
173
+ }
174
+ markResumeProcessed() {
175
+ this.parent.markResumeProcessed();
176
+ }
177
+ recordStep(step) {
178
+ this.parent.recordStep(step);
179
+ }
180
+ createBranchContext(parallelName, branchIndex) {
181
+ const nestedPrefix = `${this.scopePrefix}:${parallelName}:${branchIndex}`;
182
+ return new BranchContext(this.parent, nestedPrefix);
183
+ }
184
+ }
185
+ /**
186
+ * Create a default logger that logs to console
187
+ */
188
+ function createDefaultLogger(runId) {
189
+ const prefix = `[ironflow:${runId.slice(-8)}]`;
190
+ return {
191
+ debug(message, data) {
192
+ if (process.env["IRONFLOW_DEBUG"]) {
193
+ // eslint-disable-next-line no-console
194
+ console.debug(prefix, message, data ?? "");
195
+ }
196
+ },
197
+ info(message, data) {
198
+ // eslint-disable-next-line no-console
199
+ console.info(prefix, message, data ?? "");
200
+ },
201
+ warn(message, data) {
202
+ // eslint-disable-next-line no-console
203
+ console.warn(prefix, message, data ?? "");
204
+ },
205
+ error(message, data) {
206
+ // eslint-disable-next-line no-console
207
+ console.error(prefix, message, data ?? "");
208
+ },
209
+ };
210
+ }
211
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/internal/context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH;;GAEG;AACH,MAAM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