@codemation/core 0.0.5 → 0.0.7

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.
@@ -0,0 +1,1172 @@
1
+ import { ReadableStream } from "node:stream/web";
2
+ import { DependencyContainer, DependencyContainer as Container, Disposable, InjectionToken, InjectionToken as TypeToken, Lifecycle, RegistrationOptions, container, delay, inject, injectAll, injectable, instanceCachingFactory, instancePerContainerCachingFactory, predicateAwareClassFactory, registry, singleton } from "tsyringe";
3
+
4
+ //#region src/contracts/retryPolicySpec.types.d.ts
5
+
6
+ /**
7
+ * In-process retry policy for runnable nodes. Serialized configs use the same
8
+ * `kind` discriminator (`JSON.stringify` / persisted workflows).
9
+ *
10
+ * `maxAttempts` is the total number of tries including the first (e.g. 3 means up to 2 delays after failures).
11
+ */
12
+ type RetryPolicySpec = NoneRetryPolicySpec | FixedRetryPolicySpec | ExponentialRetryPolicySpec;
13
+ interface NoneRetryPolicySpec {
14
+ readonly kind: "none";
15
+ }
16
+ interface FixedRetryPolicySpec {
17
+ readonly kind: "fixed";
18
+ /** Total attempts including the first execution. Must be >= 1. */
19
+ readonly maxAttempts: number;
20
+ readonly delayMs: number;
21
+ }
22
+ interface ExponentialRetryPolicySpec {
23
+ readonly kind: "exponential";
24
+ /** Total attempts including the first execution. Must be >= 1. */
25
+ readonly maxAttempts: number;
26
+ readonly initialDelayMs: number;
27
+ readonly multiplier: number;
28
+ readonly maxDelayMs?: number;
29
+ /** When true, each delay is multiplied by a random factor in [1, 1.2). */
30
+ readonly jitter?: boolean;
31
+ }
32
+ //#endregion
33
+ //#region src/events/runEvents.d.ts
34
+ type RunEvent = Readonly<{
35
+ kind: "runCreated";
36
+ runId: RunId;
37
+ workflowId: WorkflowId;
38
+ parent?: ParentExecutionRef;
39
+ at: string;
40
+ }> | Readonly<{
41
+ kind: "runSaved";
42
+ runId: RunId;
43
+ workflowId: WorkflowId;
44
+ parent?: ParentExecutionRef;
45
+ at: string;
46
+ state: PersistedRunState;
47
+ }> | Readonly<{
48
+ kind: "nodeQueued";
49
+ runId: RunId;
50
+ workflowId: WorkflowId;
51
+ parent?: ParentExecutionRef;
52
+ at: string;
53
+ snapshot: NodeExecutionSnapshot;
54
+ }> | Readonly<{
55
+ kind: "nodeStarted";
56
+ runId: RunId;
57
+ workflowId: WorkflowId;
58
+ parent?: ParentExecutionRef;
59
+ at: string;
60
+ snapshot: NodeExecutionSnapshot;
61
+ }> | Readonly<{
62
+ kind: "nodeCompleted";
63
+ runId: RunId;
64
+ workflowId: WorkflowId;
65
+ parent?: ParentExecutionRef;
66
+ at: string;
67
+ snapshot: NodeExecutionSnapshot;
68
+ }> | Readonly<{
69
+ kind: "nodeFailed";
70
+ runId: RunId;
71
+ workflowId: WorkflowId;
72
+ parent?: ParentExecutionRef;
73
+ at: string;
74
+ snapshot: NodeExecutionSnapshot;
75
+ }>;
76
+ interface RunEventSubscription {
77
+ close(): Promise<void>;
78
+ }
79
+ interface RunEventBus {
80
+ publish(event: RunEvent): Promise<void>;
81
+ subscribe(onEvent: (event: RunEvent) => void): Promise<RunEventSubscription>;
82
+ subscribeToWorkflow(workflowId: WorkflowId, onEvent: (event: RunEvent) => void): Promise<RunEventSubscription>;
83
+ }
84
+ //#endregion
85
+ //#region src/policies/executionLimits/EngineExecutionLimitsPolicy.d.ts
86
+ interface EngineExecutionLimitsPolicyConfig {
87
+ readonly defaultMaxNodeActivations: number;
88
+ readonly hardMaxNodeActivations: number;
89
+ readonly defaultMaxSubworkflowDepth: number;
90
+ readonly hardMaxSubworkflowDepth: number;
91
+ }
92
+ /** Framework defaults for {@link EngineExecutionLimitsPolicy} (merged with host `runtime.engineExecutionLimits`). */
93
+ declare const ENGINE_EXECUTION_LIMITS_DEFAULTS: EngineExecutionLimitsPolicyConfig;
94
+ /**
95
+ * Resolves per-run execution limits: defaults, hard ceilings, and subworkflow depth for new runs.
96
+ */
97
+ declare class EngineExecutionLimitsPolicy {
98
+ private readonly config;
99
+ constructor(config?: EngineExecutionLimitsPolicyConfig);
100
+ /**
101
+ * Effective options for a new root run (depth 0): defaults merged with engine ceilings.
102
+ * Replaces a separate one-method factory for root-run bootstrap.
103
+ */
104
+ createRootExecutionOptions(): RunExecutionOptions;
105
+ mergeExecutionOptionsForNewRun(parent: ParentExecutionRef | undefined, user: RunExecutionOptions | undefined): RunExecutionOptions;
106
+ private capNumber;
107
+ }
108
+ //#endregion
109
+ //#region src/di/CoreTokens.d.ts
110
+ declare const CoreTokens: {
111
+ readonly PersistedWorkflowTokenRegistry: TypeToken<PersistedWorkflowTokenRegistryLike>;
112
+ readonly CredentialSessionService: TypeToken<CredentialSessionService>;
113
+ readonly CredentialTypeRegistry: TypeToken<CredentialTypeRegistry>;
114
+ readonly WorkflowRunnerService: TypeToken<WorkflowRunnerService>;
115
+ readonly LiveWorkflowRepository: TypeToken<LiveWorkflowRepository>;
116
+ readonly WorkflowRepository: TypeToken<WorkflowRepository>;
117
+ readonly NodeResolver: TypeToken<NodeResolver>;
118
+ readonly WorkflowNodeInstanceFactory: TypeToken<WorkflowNodeInstanceFactory>;
119
+ readonly RunIdFactory: TypeToken<RunIdFactory>;
120
+ readonly ActivationIdFactory: TypeToken<ActivationIdFactory>;
121
+ readonly WorkflowExecutionRepository: TypeToken<WorkflowExecutionRepository>;
122
+ readonly TriggerSetupStateRepository: TypeToken<TriggerSetupStateRepository>;
123
+ readonly NodeActivationScheduler: TypeToken<NodeActivationScheduler>;
124
+ readonly RunDataFactory: TypeToken<RunDataFactory>;
125
+ readonly ExecutionContextFactory: TypeToken<ExecutionContextFactory>;
126
+ readonly RunEventBus: TypeToken<RunEventBus>;
127
+ readonly BinaryStorage: TypeToken<BinaryStorage>;
128
+ readonly WebhookBasePath: TypeToken<string>;
129
+ /** Engine execution limits (defaults + optional host overrides). Consumers may bind a custom instance to override. */
130
+ readonly EngineExecutionLimitsPolicy: TypeToken<EngineExecutionLimitsPolicy>;
131
+ readonly WorkflowActivationPolicy: TypeToken<WorkflowActivationPolicy>;
132
+ };
133
+ //#endregion
134
+ //#region src/contracts/runTypes.d.ts
135
+ interface RunExecutionOptions {
136
+ /** Run-intent override: force the inline scheduler and bypass node-level offload decisions. */
137
+ localOnly?: boolean;
138
+ /** Marks runs started from webhook handling so orchestration can apply webhook-specific continuation rules. */
139
+ webhook?: boolean;
140
+ mode?: "manual" | "debug";
141
+ sourceWorkflowId?: WorkflowId;
142
+ sourceRunId?: RunId;
143
+ derivedFromRunId?: RunId;
144
+ isMutable?: boolean;
145
+ /** Set by the engine for this run: 0 = root, 1 = first child subworkflow, … */
146
+ subworkflowDepth?: number;
147
+ /** Effective cap after engine policy merge (successful node completions per run). */
148
+ maxNodeActivations?: number;
149
+ /** Effective cap after engine policy merge (subworkflow nesting). */
150
+ maxSubworkflowDepth?: number;
151
+ }
152
+ /** Engine-owned counters persisted with the run (worker-safe). */
153
+ interface EngineRunCounters {
154
+ completedNodeActivations: number;
155
+ }
156
+ type RunStopCondition = Readonly<{
157
+ kind: "workflowCompleted";
158
+ }> | Readonly<{
159
+ kind: "nodeCompleted";
160
+ nodeId: NodeId;
161
+ }>;
162
+ interface RunStateResetRequest {
163
+ clearFromNodeId: NodeId;
164
+ }
165
+ interface PersistedRunControlState {
166
+ stopCondition?: RunStopCondition;
167
+ }
168
+ interface PersistedWorkflowSnapshotNode {
169
+ id: NodeId;
170
+ kind: NodeKind;
171
+ name?: string;
172
+ nodeTokenId: PersistedTokenId;
173
+ configTokenId: PersistedTokenId;
174
+ tokenName?: string;
175
+ configTokenName?: string;
176
+ config: unknown;
177
+ }
178
+ interface PersistedWorkflowSnapshot {
179
+ id: WorkflowId;
180
+ name: string;
181
+ nodes: ReadonlyArray<PersistedWorkflowSnapshotNode>;
182
+ edges: ReadonlyArray<Edge>;
183
+ /** When the snapshot was built from a live workflow definition that configured a workflow error handler. */
184
+ workflowErrorHandlerConfigured?: boolean;
185
+ /** Connection metadata for child nodes not in the execution graph (e.g. AI agent attachments). */
186
+ connections?: ReadonlyArray<WorkflowNodeConnection>;
187
+ }
188
+ type PinnedNodeOutputsByPort = Readonly<Record<OutputPortKey, Items>>;
189
+ interface PersistedMutableNodeState {
190
+ pinnedOutputsByPort?: PinnedNodeOutputsByPort;
191
+ lastDebugInput?: Items;
192
+ }
193
+ interface PersistedMutableRunState {
194
+ nodesById: Readonly<Record<NodeId, PersistedMutableNodeState>>;
195
+ }
196
+ type NodeInputsByPort = Readonly<Record<InputPortKey, Items>>;
197
+ interface RunQueueEntry {
198
+ nodeId: NodeId;
199
+ input: Items;
200
+ toInput?: InputPortKey;
201
+ batchId?: string;
202
+ from?: Readonly<{
203
+ nodeId: NodeId;
204
+ output: OutputPortKey;
205
+ }>;
206
+ collect?: Readonly<{
207
+ expectedInputs: ReadonlyArray<InputPortKey>;
208
+ received: Readonly<Record<InputPortKey, Items>>;
209
+ }>;
210
+ }
211
+ type NodeExecutionStatus = "pending" | "queued" | "running" | "completed" | "failed" | "skipped";
212
+ interface NodeExecutionError {
213
+ message: string;
214
+ name?: string;
215
+ stack?: string;
216
+ }
217
+ interface NodeExecutionSnapshot {
218
+ runId: RunId;
219
+ workflowId: WorkflowId;
220
+ nodeId: NodeId;
221
+ activationId?: NodeActivationId;
222
+ parent?: ParentExecutionRef;
223
+ status: NodeExecutionStatus;
224
+ usedPinnedOutput?: boolean;
225
+ queuedAt?: string;
226
+ startedAt?: string;
227
+ finishedAt?: string;
228
+ updatedAt: string;
229
+ inputsByPort?: NodeInputsByPort;
230
+ outputs?: NodeOutputs;
231
+ error?: NodeExecutionError;
232
+ }
233
+ /** Stable id for a single connection invocation row in {@link ConnectionInvocationRecord}. */
234
+ type ConnectionInvocationId = string;
235
+ /**
236
+ * One logical LLM or tool call under an owning workflow node (e.g. AI agent).
237
+ * The owning node defines what {@link managedInput} and {@link managedOutput} contain.
238
+ */
239
+ interface ConnectionInvocationRecord {
240
+ readonly invocationId: ConnectionInvocationId;
241
+ readonly runId: RunId;
242
+ readonly workflowId: WorkflowId;
243
+ readonly connectionNodeId: NodeId;
244
+ readonly parentAgentNodeId: NodeId;
245
+ readonly parentAgentActivationId: NodeActivationId;
246
+ readonly status: NodeExecutionStatus;
247
+ readonly managedInput?: JsonValue;
248
+ readonly managedOutput?: JsonValue;
249
+ readonly error?: NodeExecutionError;
250
+ readonly queuedAt?: string;
251
+ readonly startedAt?: string;
252
+ readonly finishedAt?: string;
253
+ readonly updatedAt: string;
254
+ }
255
+ /** Arguments for appending a {@link ConnectionInvocationRecord} (engine fills run/workflow ids and timestamps). */
256
+ type ConnectionInvocationAppendArgs = Readonly<{
257
+ invocationId: ConnectionInvocationId;
258
+ connectionNodeId: NodeId;
259
+ parentAgentNodeId: NodeId;
260
+ parentAgentActivationId: NodeActivationId;
261
+ status: NodeExecutionStatus;
262
+ managedInput?: JsonValue;
263
+ managedOutput?: JsonValue;
264
+ error?: NodeExecutionError;
265
+ queuedAt?: string;
266
+ startedAt?: string;
267
+ finishedAt?: string;
268
+ }>;
269
+ interface RunCurrentState {
270
+ outputsByNode: Record<NodeId, NodeOutputs>;
271
+ nodeSnapshotsByNodeId: Record<NodeId, NodeExecutionSnapshot>;
272
+ /** Append-only history of connection-scoped invocations (LLM/tool) for inspector and canvas. */
273
+ connectionInvocations?: ReadonlyArray<ConnectionInvocationRecord>;
274
+ mutableState?: PersistedMutableRunState;
275
+ }
276
+ interface CurrentStateExecutionRequest {
277
+ workflow: WorkflowDefinition;
278
+ items?: Items;
279
+ parent?: ParentExecutionRef;
280
+ executionOptions?: RunExecutionOptions;
281
+ workflowSnapshot?: PersistedWorkflowSnapshot;
282
+ mutableState?: PersistedMutableRunState;
283
+ currentState?: RunCurrentState;
284
+ stopCondition?: RunStopCondition;
285
+ reset?: RunStateResetRequest;
286
+ }
287
+ interface ExecutionFrontierPlan {
288
+ rootNodeId?: NodeId;
289
+ rootNodeInput?: Items;
290
+ queue: RunQueueEntry[];
291
+ currentState: RunCurrentState;
292
+ stopCondition: RunStopCondition;
293
+ satisfiedNodeIds: ReadonlyArray<NodeId>;
294
+ skippedNodeIds: ReadonlyArray<NodeId>;
295
+ clearedNodeIds: ReadonlyArray<NodeId>;
296
+ preservedPinnedNodeIds: ReadonlyArray<NodeId>;
297
+ }
298
+ type RunStatus = "running" | "pending" | "completed" | "failed";
299
+ interface RunSummary {
300
+ runId: RunId;
301
+ workflowId: WorkflowId;
302
+ startedAt: string;
303
+ status: RunStatus;
304
+ /** ISO timestamp when the run finished (derived from node snapshots or store `updatedAt`); omit while running/pending. */
305
+ finishedAt?: string;
306
+ parent?: ParentExecutionRef;
307
+ executionOptions?: RunExecutionOptions;
308
+ }
309
+ interface PendingNodeExecution {
310
+ runId: RunId;
311
+ activationId: NodeActivationId;
312
+ workflowId: WorkflowId;
313
+ nodeId: NodeId;
314
+ itemsIn: number;
315
+ inputsByPort: NodeInputsByPort;
316
+ receiptId: string;
317
+ queue?: string;
318
+ batchId?: string;
319
+ enqueuedAt: string;
320
+ }
321
+ interface PersistedRunState {
322
+ runId: RunId;
323
+ workflowId: WorkflowId;
324
+ startedAt: string;
325
+ parent?: ParentExecutionRef;
326
+ executionOptions?: RunExecutionOptions;
327
+ control?: PersistedRunControlState;
328
+ workflowSnapshot?: PersistedWorkflowSnapshot;
329
+ mutableState?: PersistedMutableRunState;
330
+ /** Frozen at createRun from workflow + runtime defaults for prune/storage decisions. */
331
+ policySnapshot?: PersistedRunPolicySnapshot;
332
+ /** Successful node completions so far (for activation budget). */
333
+ engineCounters?: EngineRunCounters;
334
+ status: RunStatus;
335
+ pending?: PendingNodeExecution;
336
+ queue: RunQueueEntry[];
337
+ outputsByNode: Record<NodeId, NodeOutputs>;
338
+ nodeSnapshotsByNodeId: Record<NodeId, NodeExecutionSnapshot>;
339
+ /** Append-only history of connection invocations (LLM/tool) nested under owning nodes. */
340
+ connectionInvocations?: ReadonlyArray<ConnectionInvocationRecord>;
341
+ }
342
+ interface WorkflowExecutionRepository {
343
+ createRun(args: {
344
+ runId: RunId;
345
+ workflowId: WorkflowId;
346
+ startedAt: string;
347
+ parent?: ParentExecutionRef;
348
+ executionOptions?: RunExecutionOptions;
349
+ control?: PersistedRunControlState;
350
+ workflowSnapshot?: PersistedWorkflowSnapshot;
351
+ mutableState?: PersistedMutableRunState;
352
+ policySnapshot?: PersistedRunPolicySnapshot;
353
+ engineCounters?: EngineRunCounters;
354
+ }): Promise<void>;
355
+ load(runId: RunId): Promise<PersistedRunState | undefined>;
356
+ save(state: PersistedRunState): Promise<void>;
357
+ deleteRun?(runId: RunId): Promise<void>;
358
+ }
359
+ interface WorkflowExecutionListingRepository {
360
+ listRuns(args?: Readonly<{
361
+ workflowId?: WorkflowId;
362
+ limit?: number;
363
+ }>): Promise<ReadonlyArray<RunSummary>>;
364
+ }
365
+ /** Runs eligible for retention-based pruning (completed or failed, older than cutoff). */
366
+ interface RunPruneCandidate {
367
+ readonly runId: RunId;
368
+ readonly workflowId: WorkflowId;
369
+ readonly startedAt: string;
370
+ readonly finishedAt: string;
371
+ }
372
+ interface WorkflowExecutionPruneRepository {
373
+ listRunsOlderThan(args: Readonly<{
374
+ beforeIso: string;
375
+ limit?: number;
376
+ }>): Promise<ReadonlyArray<RunPruneCandidate>>;
377
+ }
378
+ type RunResult = {
379
+ runId: RunId;
380
+ workflowId: WorkflowId;
381
+ startedAt: string;
382
+ status: "completed";
383
+ outputs: Items;
384
+ } | {
385
+ runId: RunId;
386
+ workflowId: WorkflowId;
387
+ startedAt: string;
388
+ status: "pending";
389
+ pending: PendingNodeExecution;
390
+ } | {
391
+ runId: RunId;
392
+ workflowId: WorkflowId;
393
+ startedAt: string;
394
+ status: "failed";
395
+ error: {
396
+ message: string;
397
+ };
398
+ };
399
+ type WebhookRunResult = Readonly<{
400
+ runId: RunId;
401
+ workflowId: WorkflowId;
402
+ startedAt: string;
403
+ runStatus: "pending" | "completed";
404
+ response: Items;
405
+ }>;
406
+ interface PersistedWorkflowTokenRegistryLike {
407
+ register(type: TypeToken<unknown>, packageId: string, persistedNameOverride?: string): string;
408
+ getTokenId(type: TypeToken<unknown>): string | undefined;
409
+ resolve(tokenId: string): TypeToken<unknown> | undefined;
410
+ registerFromWorkflows?(workflows: ReadonlyArray<WorkflowDefinition>): void;
411
+ }
412
+ interface RunCompletionNotifier {
413
+ resolveRunCompletion(result: RunResult): void;
414
+ resolveWebhookResponse(result: WebhookRunResult): void;
415
+ }
416
+ interface RunEventPublisherDeps {
417
+ eventBus?: RunEventBus;
418
+ }
419
+ //#endregion
420
+ //#region src/contracts/workflowActivationPolicy.d.ts
421
+ /**
422
+ * Host-controlled policy: when false, trigger {@link TriggerNode} setup is skipped and webhook routes
423
+ * for that workflow are not registered (see engine trigger runtime + webhook matcher).
424
+ */
425
+ interface WorkflowActivationPolicy {
426
+ isActive(workflowId: WorkflowId): boolean;
427
+ }
428
+ /** Default for tests and harnesses: every workflow is treated as active (legacy behavior). */
429
+ declare class AllWorkflowsActiveWorkflowActivationPolicy implements WorkflowActivationPolicy {
430
+ isActive(_workflowId: WorkflowId): boolean;
431
+ }
432
+ //#endregion
433
+ //#region src/contracts/webhookTypes.d.ts
434
+ type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
435
+ interface WebhookControlSignal {
436
+ readonly __webhookControl: true;
437
+ readonly kind: "respondNow" | "respondNowAndContinue";
438
+ readonly responseItems: Items;
439
+ readonly continueItems?: Items;
440
+ }
441
+ interface WebhookTriggerRoutingDiagnostics {
442
+ warn(message: string): void;
443
+ /** Inactive workflows omitted from the webhook route index (optional; host should wire for clarity at boot/reload). */
444
+ info?(message: string): void;
445
+ }
446
+ interface TriggerInstanceId {
447
+ workflowId: WorkflowId;
448
+ nodeId: NodeId;
449
+ }
450
+ /** Match for an incoming HTTP request: user-defined URL segment + workflow trigger node. */
451
+ interface WebhookInvocationMatch {
452
+ /** Same value as the webhook trigger's configured endpoint key (URL segment under the webhook base path). */
453
+ endpointPath: string;
454
+ workflowId: WorkflowId;
455
+ nodeId: NodeId;
456
+ methods: ReadonlyArray<HttpMethod>;
457
+ parseJsonBody?: (body: unknown) => unknown;
458
+ }
459
+ /** Result of resolving an HTTP method + endpoint path against the catalog webhook index (404 vs 405 vs match). */
460
+ type WebhookTriggerResolution = {
461
+ status: "notFound";
462
+ } | {
463
+ status: "methodNotAllowed";
464
+ match: WebhookInvocationMatch;
465
+ } | {
466
+ status: "ok";
467
+ match: WebhookInvocationMatch;
468
+ };
469
+ /**
470
+ * Resolves webhook routes from workflow definitions (catalog-backed index, no registration at trigger setup).
471
+ */
472
+ interface WebhookTriggerMatcher {
473
+ match(args: {
474
+ endpointPath: string;
475
+ method: HttpMethod;
476
+ }): WebhookInvocationMatch | undefined;
477
+ lookup(endpointPath: string): WebhookInvocationMatch | undefined;
478
+ onEngineWorkflowsLoaded?(): void;
479
+ onEngineStopped?(): void;
480
+ /** Rebuild route index after activation changes without stopping the engine. */
481
+ reloadWebhookRoutes?(): void;
482
+ }
483
+ //#endregion
484
+ //#region src/contracts/runtimeTypes.d.ts
485
+ interface WorkflowRunnerService {
486
+ runById(args: {
487
+ workflowId: WorkflowId;
488
+ startAt?: NodeId;
489
+ items: Items;
490
+ parent?: ParentExecutionRef;
491
+ }): Promise<RunResult>;
492
+ }
493
+ interface WorkflowRunnerResolver {
494
+ resolve(): WorkflowRunnerService | undefined;
495
+ }
496
+ interface WorkflowRepository {
497
+ list(): ReadonlyArray<WorkflowDefinition>;
498
+ get(workflowId: WorkflowId): WorkflowDefinition | undefined;
499
+ }
500
+ interface LiveWorkflowRepository extends WorkflowRepository {
501
+ setWorkflows(workflows: ReadonlyArray<WorkflowDefinition>): void;
502
+ }
503
+ interface NodeResolver {
504
+ resolve<T>(token: TypeToken<T>): T;
505
+ }
506
+ interface NodeExecutionStatePublisher {
507
+ markQueued(args: {
508
+ nodeId: NodeId;
509
+ activationId?: NodeActivationId;
510
+ inputsByPort?: NodeInputsByPort;
511
+ }): Promise<void>;
512
+ markRunning(args: {
513
+ nodeId: NodeId;
514
+ activationId?: NodeActivationId;
515
+ inputsByPort?: NodeInputsByPort;
516
+ }): Promise<void>;
517
+ markCompleted(args: {
518
+ nodeId: NodeId;
519
+ activationId?: NodeActivationId;
520
+ inputsByPort?: NodeInputsByPort;
521
+ outputs?: NodeOutputs;
522
+ }): Promise<void>;
523
+ markFailed(args: {
524
+ nodeId: NodeId;
525
+ activationId?: NodeActivationId;
526
+ inputsByPort?: NodeInputsByPort;
527
+ error: Error;
528
+ }): Promise<void>;
529
+ appendConnectionInvocation(args: ConnectionInvocationAppendArgs): Promise<void>;
530
+ }
531
+ type BinaryBody = ReadableStream<Uint8Array> | AsyncIterable<Uint8Array> | Uint8Array | ArrayBuffer;
532
+ interface BinaryStorageWriteRequest {
533
+ storageKey: string;
534
+ body: BinaryBody;
535
+ }
536
+ interface BinaryStorageWriteResult {
537
+ storageKey: string;
538
+ size: number;
539
+ sha256?: string;
540
+ }
541
+ interface BinaryStorageReadResult {
542
+ body: ReadableStream<Uint8Array>;
543
+ size?: number;
544
+ }
545
+ interface BinaryStorageStatResult {
546
+ exists: boolean;
547
+ size?: number;
548
+ }
549
+ interface BinaryStorage {
550
+ readonly driverName: string;
551
+ write(args: BinaryStorageWriteRequest): Promise<BinaryStorageWriteResult>;
552
+ openReadStream(storageKey: string): Promise<BinaryStorageReadResult | undefined>;
553
+ stat(storageKey: string): Promise<BinaryStorageStatResult>;
554
+ delete(storageKey: string): Promise<void>;
555
+ }
556
+ interface BinaryAttachmentCreateRequest {
557
+ name: string;
558
+ body: BinaryBody;
559
+ mimeType: string;
560
+ filename?: string;
561
+ previewKind?: BinaryAttachment["previewKind"];
562
+ }
563
+ interface NodeBinaryAttachmentService extends ExecutionBinaryService {
564
+ attach(args: BinaryAttachmentCreateRequest): Promise<BinaryAttachment>;
565
+ withAttachment<TJson>(item: Item<TJson>, name: string, attachment: BinaryAttachment): Item<TJson>;
566
+ }
567
+ interface ExecutionBinaryService {
568
+ forNode(args: {
569
+ nodeId: NodeId;
570
+ activationId: NodeActivationId;
571
+ }): NodeBinaryAttachmentService;
572
+ openReadStream(attachment: BinaryAttachment): Promise<BinaryStorageReadResult | undefined>;
573
+ }
574
+ interface ExecutionContext {
575
+ runId: RunId;
576
+ workflowId: WorkflowId;
577
+ parent?: ParentExecutionRef;
578
+ /** This run's subworkflow depth (0 = root). */
579
+ subworkflowDepth: number;
580
+ /** Effective activation budget cap for this run (after policy merge). */
581
+ engineMaxNodeActivations: number;
582
+ /** Effective subworkflow nesting cap for this run (after policy merge). */
583
+ engineMaxSubworkflowDepth: number;
584
+ now: () => Date;
585
+ data: RunDataSnapshot;
586
+ nodeState?: NodeExecutionStatePublisher;
587
+ binary: ExecutionBinaryService;
588
+ getCredential<TSession = unknown>(slotKey: string): Promise<TSession>;
589
+ }
590
+ interface ExecutionContextFactory {
591
+ create(args: {
592
+ runId: RunId;
593
+ workflowId: WorkflowId;
594
+ parent?: ParentExecutionRef;
595
+ subworkflowDepth: number;
596
+ engineMaxNodeActivations: number;
597
+ engineMaxSubworkflowDepth: number;
598
+ data: RunDataSnapshot;
599
+ nodeState?: NodeExecutionStatePublisher;
600
+ getCredential<TSession = unknown>(slotKey: string): Promise<TSession>;
601
+ }): ExecutionContext;
602
+ }
603
+ interface NodeExecutionContext<TConfig extends NodeConfigBase = NodeConfigBase> extends ExecutionContext {
604
+ nodeId: NodeId;
605
+ activationId: NodeActivationId;
606
+ config: TConfig;
607
+ binary: NodeBinaryAttachmentService;
608
+ }
609
+ interface TriggerSetupContext<TConfig extends TriggerNodeConfig<any, any> = TriggerNodeConfig<any, any>, TSetupState$1 extends JsonValue | undefined = TriggerNodeSetupState<TConfig>> extends ExecutionContext {
610
+ trigger: TriggerInstanceId;
611
+ config: TConfig;
612
+ previousState: TSetupState$1;
613
+ registerCleanup(cleanup: TriggerCleanupHandle): void;
614
+ emit(items: Items): Promise<void>;
615
+ }
616
+ interface TriggerTestItemsContext<TConfig extends TriggerNodeConfig<any, any> = TriggerNodeConfig<any, any>, TSetupState$1 extends JsonValue | undefined = TriggerNodeSetupState<TConfig>> extends ExecutionContext {
617
+ trigger: TriggerInstanceId;
618
+ nodeId: NodeId;
619
+ config: TConfig;
620
+ previousState: TSetupState$1;
621
+ }
622
+ /**
623
+ * Trigger setup state is intentionally engine-owned so future ownership and
624
+ * leader-election metadata can be coordinated centrally rather than pushed into
625
+ * package-level setup code.
626
+ */
627
+ interface PersistedTriggerSetupState<TState extends JsonValue | undefined = JsonValue | undefined> {
628
+ trigger: TriggerInstanceId;
629
+ updatedAt: string;
630
+ state: TState;
631
+ }
632
+ interface TriggerSetupStateRepository {
633
+ load(trigger: TriggerInstanceId): Promise<PersistedTriggerSetupState | undefined>;
634
+ save(state: PersistedTriggerSetupState): Promise<void>;
635
+ delete(trigger: TriggerInstanceId): Promise<void>;
636
+ }
637
+ interface TriggerCleanupHandle {
638
+ stop(): Promise<void> | void;
639
+ }
640
+ interface EngineHost {
641
+ credentialSessions: CredentialSessionService;
642
+ workflows?: WorkflowRunnerService;
643
+ }
644
+ interface Node<TConfig extends NodeConfigBase = NodeConfigBase> {
645
+ kind: "node";
646
+ outputPorts: ReadonlyArray<OutputPortKey>;
647
+ execute(items: Items, ctx: NodeExecutionContext<TConfig>): Promise<NodeOutputs>;
648
+ }
649
+ interface MultiInputNode<TConfig extends NodeConfigBase = NodeConfigBase> {
650
+ kind: "node";
651
+ outputPorts: ReadonlyArray<OutputPortKey>;
652
+ executeMulti(inputsByPort: NodeInputsByPort, ctx: NodeExecutionContext<TConfig>): Promise<NodeOutputs>;
653
+ }
654
+ type TriggerSetupStateFor<TConfig extends TriggerNodeConfig<any, any>> = TriggerNodeSetupState<TConfig>;
655
+ interface TriggerNode<TConfig extends TriggerNodeConfig<any, any> = TriggerNodeConfig<any, any>> {
656
+ kind: "trigger";
657
+ outputPorts: readonly ["main"];
658
+ setup(ctx: TriggerSetupContext<TConfig>): Promise<TriggerSetupStateFor<TConfig>>;
659
+ execute(items: Items, ctx: NodeExecutionContext<TConfig>): Promise<NodeOutputs>;
660
+ }
661
+ interface TestableTriggerNode<TConfig extends TriggerNodeConfig<any, any> = TriggerNodeConfig<any, any>> extends TriggerNode<TConfig> {
662
+ getTestItems(ctx: TriggerTestItemsContext<TConfig>): Promise<Items>;
663
+ }
664
+ type ExecutableTriggerNode<TConfig extends TriggerNodeConfig<any, any> = TriggerNodeConfig<any, any>> = TriggerNode<TConfig>;
665
+ interface NodeExecutionRequest {
666
+ runId: RunId;
667
+ activationId: NodeActivationId;
668
+ workflowId: WorkflowId;
669
+ nodeId: NodeId;
670
+ input: Items;
671
+ parent?: ParentExecutionRef;
672
+ queue?: string;
673
+ executionOptions?: RunExecutionOptions;
674
+ }
675
+ interface NodeExecutionScheduler {
676
+ enqueue(request: NodeExecutionRequest): Promise<{
677
+ receiptId: string;
678
+ }>;
679
+ cancel?(receiptId: string): Promise<void>;
680
+ }
681
+ interface NodeExecutionRequestHandler {
682
+ handleNodeExecutionRequest(request: NodeExecutionRequest): Promise<void>;
683
+ }
684
+ type NodeActivationRequestBase = Readonly<{
685
+ runId: RunId;
686
+ activationId: NodeActivationId;
687
+ workflowId: WorkflowId;
688
+ nodeId: NodeId;
689
+ parent?: ParentExecutionRef;
690
+ executionOptions?: RunExecutionOptions;
691
+ batchId?: string;
692
+ ctx: NodeExecutionContext;
693
+ }>;
694
+ type NodeActivationRequest = (NodeActivationRequestBase & Readonly<{
695
+ kind: "single";
696
+ input: Items;
697
+ }>) | (NodeActivationRequestBase & Readonly<{
698
+ kind: "multi";
699
+ inputsByPort: NodeInputsByPort;
700
+ }>);
701
+ interface NodeActivationReceipt {
702
+ receiptId: string;
703
+ mode?: "local" | "worker";
704
+ queue?: string;
705
+ }
706
+ interface NodeActivationContinuation {
707
+ markNodeRunning(args: {
708
+ runId: RunId;
709
+ activationId: NodeActivationId;
710
+ nodeId: NodeId;
711
+ inputsByPort: NodeInputsByPort;
712
+ }): Promise<void>;
713
+ resumeFromNodeResult(args: {
714
+ runId: RunId;
715
+ activationId: NodeActivationId;
716
+ nodeId: NodeId;
717
+ outputs: NodeOutputs;
718
+ }): Promise<RunResult>;
719
+ resumeFromNodeError(args: {
720
+ runId: RunId;
721
+ activationId: NodeActivationId;
722
+ nodeId: NodeId;
723
+ error: Error;
724
+ }): Promise<RunResult>;
725
+ }
726
+ interface NodeActivationScheduler {
727
+ setContinuation?(continuation: NodeActivationContinuation): void;
728
+ enqueue(request: NodeActivationRequest): Promise<NodeActivationReceipt>;
729
+ notifyPendingStatePersisted?(runId: RunId): void;
730
+ cancel?(receiptId: string): Promise<void>;
731
+ }
732
+ interface WorkflowNodeInstanceFactory {
733
+ createNodes(workflow: WorkflowDefinition): ReadonlyMap<NodeId, unknown>;
734
+ createByType(type: TypeToken<unknown>): unknown;
735
+ }
736
+ interface NodeExecutor {
737
+ execute(request: NodeActivationRequest): Promise<NodeOutputs>;
738
+ }
739
+ interface WorkflowSnapshotFactory {
740
+ create(workflow: WorkflowDefinition): PersistedWorkflowSnapshot;
741
+ }
742
+ interface WorkflowSnapshotResolver {
743
+ resolve(args: {
744
+ workflowId: WorkflowId;
745
+ workflowSnapshot?: PersistedWorkflowSnapshot;
746
+ }): WorkflowDefinition | undefined;
747
+ }
748
+ /** Optional host wiring for trigger lifecycle logs (boot skip + activation sync). */
749
+ interface TriggerRuntimeDiagnostics {
750
+ info(message: string): void;
751
+ warn(message: string): void;
752
+ }
753
+ interface EngineDeps {
754
+ credentialSessions: CredentialSessionService;
755
+ liveWorkflowRepository: LiveWorkflowRepository;
756
+ workflowRepository: WorkflowRepository;
757
+ /** When {@link AllWorkflowsActiveWorkflowActivationPolicy}, all workflows behave as active (tests). */
758
+ workflowActivationPolicy: WorkflowActivationPolicy;
759
+ nodeResolver: NodeResolver;
760
+ triggerSetupStateRepository: TriggerSetupStateRepository;
761
+ webhookTriggerMatcher: WebhookTriggerMatcher;
762
+ runIdFactory: RunIdFactory;
763
+ activationIdFactory: ActivationIdFactory;
764
+ workflowExecutionRepository: WorkflowExecutionRepository;
765
+ activationScheduler: NodeActivationScheduler;
766
+ runDataFactory: RunDataFactory;
767
+ executionContextFactory: ExecutionContextFactory;
768
+ nodeExecutor: NodeExecutor;
769
+ eventBus?: RunEventBus;
770
+ tokenRegistry: PersistedWorkflowTokenRegistryLike;
771
+ workflowNodeInstanceFactory: WorkflowNodeInstanceFactory;
772
+ /** Defaults for prune/storage snapshot when workflow omits explicit policy fields. */
773
+ workflowPolicyRuntimeDefaults?: WorkflowPolicyRuntimeDefaults;
774
+ /** When set, logs inactive-workflow skips at boot and trigger start/stop on activation changes. */
775
+ triggerRuntimeDiagnostics?: TriggerRuntimeDiagnostics;
776
+ }
777
+ //#endregion
778
+ //#region src/contracts/workflowTypes.d.ts
779
+ type WorkflowId = string;
780
+ type NodeId = string;
781
+ type OutputPortKey = string;
782
+ type InputPortKey = string;
783
+ type PersistedTokenId = string;
784
+ type NodeKind = "trigger" | "node";
785
+ type JsonPrimitive = string | number | boolean | null;
786
+ interface JsonObject {
787
+ readonly [key: string]: JsonValue;
788
+ }
789
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
790
+ type JsonArray = ReadonlyArray<JsonValue>;
791
+ interface Edge {
792
+ from: {
793
+ nodeId: NodeId;
794
+ output: OutputPortKey;
795
+ };
796
+ to: {
797
+ nodeId: NodeId;
798
+ input: InputPortKey;
799
+ };
800
+ }
801
+ type NodeConnectionName = string;
802
+ /**
803
+ * Named connection from an executable parent node to child nodes that exist in {@link WorkflowDefinition.nodes}
804
+ * but are not traversed by the main execution graph.
805
+ */
806
+ interface WorkflowNodeConnection {
807
+ readonly parentNodeId: NodeId;
808
+ readonly connectionName: NodeConnectionName;
809
+ readonly childNodeIds: ReadonlyArray<NodeId>;
810
+ }
811
+ interface WorkflowDefinition {
812
+ id: WorkflowId;
813
+ name: string;
814
+ nodes: NodeDefinition[];
815
+ edges: Edge[];
816
+ /**
817
+ * Optional metadata: which nodes are connection-owned children (e.g. AI agent `llm` / `tools` slots).
818
+ * When omitted, all nodes in {@link nodes} are treated as executable for topology.
819
+ */
820
+ readonly connections?: ReadonlyArray<WorkflowNodeConnection>;
821
+ /** Directory + file-stem path under a workflow discovery root (for UI grouping only). */
822
+ discoveryPathSegments?: readonly string[];
823
+ /** Retention for run JSON and binaries (seconds). Host/env may supply defaults when omitted. */
824
+ readonly prunePolicy?: WorkflowPrunePolicySpec;
825
+ /** Whether to keep run data after completion. Host/env may supply defaults when omitted. */
826
+ readonly storagePolicy?: WorkflowStoragePolicySpec;
827
+ /** Invoked after a node fails permanently (retries exhausted) and node error handler did not recover. */
828
+ readonly workflowErrorHandler?: WorkflowErrorHandlerSpec;
829
+ }
830
+ interface WorkflowGraph {
831
+ next(nodeId: NodeId, output: OutputPortKey): ReadonlyArray<Readonly<{
832
+ nodeId: NodeId;
833
+ input: InputPortKey;
834
+ }>>;
835
+ }
836
+ interface WorkflowGraphFactory {
837
+ create(def: WorkflowDefinition): WorkflowGraph;
838
+ }
839
+ interface NodeConfigBase {
840
+ readonly kind: NodeKind;
841
+ readonly type: TypeToken<unknown>;
842
+ readonly name?: string;
843
+ readonly id?: NodeId;
844
+ readonly icon?: string;
845
+ readonly execution?: Readonly<{
846
+ hint?: "local" | "worker";
847
+ queue?: string;
848
+ }>;
849
+ /** In-process execute retries (runnable nodes). Triggers typically omit this. */
850
+ readonly retryPolicy?: RetryPolicySpec;
851
+ /** Recover from execute failures; return outputs to continue, or rethrow to fail the node. */
852
+ readonly nodeErrorHandler?: NodeErrorHandlerSpec;
853
+ /**
854
+ * When true, edges carrying zero items on an output port still schedule single-input downstream nodes.
855
+ * Decided from the **source** node that produced the (empty) output. Default (false/undefined): empty
856
+ * main batches skip downstream execution and propagate the empty path.
857
+ */
858
+ readonly continueWhenEmptyOutput?: boolean;
859
+ getCredentialRequirements?(): ReadonlyArray<CredentialRequirement>;
860
+ }
861
+ declare const runnableNodeInputType: unique symbol;
862
+ declare const runnableNodeOutputType: unique symbol;
863
+ declare const triggerNodeOutputType: unique symbol;
864
+ interface RunnableNodeConfig<TInputJson$1 = unknown, TOutputJson$1 = unknown> extends NodeConfigBase {
865
+ readonly kind: "node";
866
+ readonly [runnableNodeInputType]?: TInputJson$1;
867
+ readonly [runnableNodeOutputType]?: TOutputJson$1;
868
+ }
869
+ declare const triggerNodeSetupStateType: unique symbol;
870
+ interface TriggerNodeConfig<TOutputJson$1 = unknown, TSetupState$1 extends JsonValue | undefined = undefined> extends NodeConfigBase {
871
+ readonly kind: "trigger";
872
+ readonly [triggerNodeOutputType]?: TOutputJson$1;
873
+ readonly [triggerNodeSetupStateType]?: TSetupState$1;
874
+ }
875
+ type RunnableNodeInputJson<TConfig extends RunnableNodeConfig<any, any>> = TConfig extends RunnableNodeConfig<infer TInputJson, any> ? TInputJson : never;
876
+ type RunnableNodeOutputJson<TConfig extends RunnableNodeConfig<any, any>> = TConfig extends RunnableNodeConfig<any, infer TOutputJson> ? TOutputJson : never;
877
+ type TriggerNodeOutputJson<TConfig extends TriggerNodeConfig<any, any>> = TConfig extends TriggerNodeConfig<infer TOutputJson, any> ? TOutputJson : never;
878
+ type TriggerNodeSetupState<TConfig extends TriggerNodeConfig<any, any>> = TConfig extends TriggerNodeConfig<any, infer TSetupState> ? TSetupState : never;
879
+ interface NodeDefinition {
880
+ id: NodeId;
881
+ kind: NodeKind;
882
+ type: TypeToken<unknown>;
883
+ name?: string;
884
+ config: NodeConfigBase;
885
+ }
886
+ interface NodeRef {
887
+ id: NodeId;
888
+ kind: NodeKind;
889
+ name?: string;
890
+ }
891
+ type PairedItemRef = Readonly<{
892
+ nodeId: NodeId;
893
+ output: OutputPortKey;
894
+ itemIndex: number;
895
+ }>;
896
+ type BinaryPreviewKind = "image" | "audio" | "video" | "download";
897
+ type BinaryAttachment = Readonly<{
898
+ id: string;
899
+ storageKey: string;
900
+ mimeType: string;
901
+ size: number;
902
+ storageDriver: string;
903
+ previewKind: BinaryPreviewKind;
904
+ createdAt: string;
905
+ runId: RunId;
906
+ workflowId: WorkflowId;
907
+ nodeId: NodeId;
908
+ activationId: NodeActivationId;
909
+ filename?: string;
910
+ sha256?: string;
911
+ }>;
912
+ type ItemBinary = Readonly<Record<string, BinaryAttachment>>;
913
+ type Item<TJson = unknown> = Readonly<{
914
+ json: TJson;
915
+ binary?: ItemBinary;
916
+ meta?: Readonly<Record<string, unknown>>;
917
+ paired?: ReadonlyArray<PairedItemRef>;
918
+ }>;
919
+ type Items<TJson = unknown> = ReadonlyArray<Item<TJson>>;
920
+ type NodeOutputs = Partial<Record<OutputPortKey, Items>>;
921
+ type RunId = string;
922
+ type NodeActivationId = string;
923
+ interface ParentExecutionRef {
924
+ runId: RunId;
925
+ workflowId: WorkflowId;
926
+ nodeId: NodeId;
927
+ /** Subworkflow depth of the **spawning** run (0 = root). Passed when starting a child run. */
928
+ subworkflowDepth?: number;
929
+ /** Effective max node activations from the parent run (propagated to child policy merge). */
930
+ engineMaxNodeActivations?: number;
931
+ /** Effective max subworkflow depth from the parent run (propagated to child policy merge). */
932
+ engineMaxSubworkflowDepth?: number;
933
+ }
934
+ interface RunDataSnapshot {
935
+ getOutputs(nodeId: NodeId): NodeOutputs | undefined;
936
+ getOutputItems(nodeId: NodeId, output?: OutputPortKey): Items;
937
+ getOutputItem(nodeId: NodeId, itemIndex: number, output?: OutputPortKey): Item | undefined;
938
+ }
939
+ interface MutableRunData extends RunDataSnapshot {
940
+ setOutputs(nodeId: NodeId, outputs: NodeOutputs): void;
941
+ dump(): Record<NodeId, NodeOutputs>;
942
+ }
943
+ interface RunDataFactory {
944
+ create(initial?: Record<NodeId, NodeOutputs>): MutableRunData;
945
+ }
946
+ interface RunIdFactory {
947
+ makeRunId(): RunId;
948
+ }
949
+ interface ActivationIdFactory {
950
+ makeActivationId(): NodeActivationId;
951
+ }
952
+ type UpstreamRefPlaceholder = `$${number}`;
953
+ declare const branchRef: (index: number) => UpstreamRefPlaceholder;
954
+ type ExecutionMode = "local" | "worker";
955
+ interface NodeSchedulerDecision {
956
+ mode: ExecutionMode;
957
+ queue?: string;
958
+ }
959
+ interface NodeOffloadPolicy {
960
+ decide(args: {
961
+ workflowId: WorkflowId;
962
+ nodeId: NodeId;
963
+ config: NodeConfigBase;
964
+ }): NodeSchedulerDecision;
965
+ }
966
+ /** Whether to persist run execution data after the workflow finishes. */
967
+ type WorkflowStoragePolicyMode = "ALL" | "SUCCESS" | "ERROR" | "NEVER";
968
+ type WorkflowStoragePolicySpec = WorkflowStoragePolicyMode | TypeToken<WorkflowStoragePolicyResolver>;
969
+ interface WorkflowStoragePolicyResolver {
970
+ shouldPersist(args: WorkflowStoragePolicyDecisionArgs): boolean | Promise<boolean>;
971
+ }
972
+ interface WorkflowStoragePolicyDecisionArgs {
973
+ readonly runId: RunId;
974
+ readonly workflowId: WorkflowId;
975
+ readonly workflow: WorkflowDefinition;
976
+ readonly finalStatus: "completed" | "failed";
977
+ readonly startedAt: string;
978
+ readonly finishedAt: string;
979
+ }
980
+ interface WorkflowPrunePolicySpec {
981
+ readonly runDataRetentionSeconds?: number;
982
+ readonly binaryRetentionSeconds?: number;
983
+ }
984
+ interface PersistedRunPolicySnapshot {
985
+ readonly retentionSeconds?: number;
986
+ readonly binaryRetentionSeconds?: number;
987
+ readonly storagePolicy: WorkflowStoragePolicyMode;
988
+ }
989
+ interface WorkflowErrorHandler {
990
+ onError(ctx: WorkflowErrorContext): void | Promise<void>;
991
+ }
992
+ interface WorkflowErrorContext {
993
+ readonly runId: RunId;
994
+ readonly workflowId: WorkflowId;
995
+ readonly workflow: WorkflowDefinition;
996
+ readonly failedNodeId: NodeId;
997
+ readonly error: Error;
998
+ readonly startedAt: string;
999
+ readonly finishedAt: string;
1000
+ }
1001
+ type WorkflowErrorHandlerSpec = TypeToken<WorkflowErrorHandler> | WorkflowErrorHandler;
1002
+ interface NodeErrorHandlerArgs<TConfig extends NodeConfigBase = NodeConfigBase> {
1003
+ readonly kind: "single" | "multi";
1004
+ readonly items: Items;
1005
+ readonly inputsByPort: Readonly<Record<InputPortKey, Items>> | undefined;
1006
+ readonly ctx: NodeExecutionContext<TConfig>;
1007
+ readonly error: Error;
1008
+ }
1009
+ interface NodeErrorHandler {
1010
+ handle<TConfig extends NodeConfigBase>(args: NodeErrorHandlerArgs<TConfig>): Promise<NodeOutputs>;
1011
+ }
1012
+ type NodeErrorHandlerSpec = TypeToken<NodeErrorHandler> | NodeErrorHandler;
1013
+ /** Runtime defaults when workflow omits prune/storage fields (typically from host env). */
1014
+ interface WorkflowPolicyRuntimeDefaults {
1015
+ readonly retentionSeconds?: number;
1016
+ readonly binaryRetentionSeconds?: number;
1017
+ readonly storagePolicy?: WorkflowStoragePolicyMode;
1018
+ }
1019
+ //#endregion
1020
+ //#region src/contracts/credentialTypes.d.ts
1021
+ type CredentialTypeId = string;
1022
+ type CredentialInstanceId = string;
1023
+ type CredentialMaterialSourceKind = "db" | "env" | "code";
1024
+ type CredentialSetupStatus = "draft" | "ready";
1025
+ type CredentialHealthStatus = "unknown" | "healthy" | "failing";
1026
+ type CredentialFieldSchema = Readonly<{
1027
+ key: string;
1028
+ label: string;
1029
+ type: "string" | "password" | "textarea" | "json" | "boolean";
1030
+ required?: true;
1031
+ order?: number;
1032
+ placeholder?: string;
1033
+ helpText?: string;
1034
+ /** When set, host resolves this field from process.env at runtime; env wins over stored values. */
1035
+ envVarName?: string;
1036
+ /**
1037
+ * When set, the dialog shows a copy action for this exact string (e.g. a static OAuth redirect URI
1038
+ * pattern or documentation URL). Do not use for secret values.
1039
+ */
1040
+ copyValue?: string;
1041
+ /** Accessible label for the copy control (default: Copy). */
1042
+ copyButtonLabel?: string;
1043
+ }>;
1044
+ type CredentialRequirement = Readonly<{
1045
+ slotKey: string;
1046
+ label: string;
1047
+ acceptedTypes: ReadonlyArray<CredentialTypeId>;
1048
+ optional?: true;
1049
+ helpText?: string;
1050
+ helpUrl?: string;
1051
+ }>;
1052
+ type CredentialBindingKey = Readonly<{
1053
+ workflowId: WorkflowId;
1054
+ nodeId: NodeId;
1055
+ slotKey: string;
1056
+ }>;
1057
+ type CredentialBinding = Readonly<{
1058
+ key: CredentialBindingKey;
1059
+ instanceId: CredentialInstanceId;
1060
+ updatedAt: string;
1061
+ }>;
1062
+ type CredentialHealth = Readonly<{
1063
+ status: CredentialHealthStatus;
1064
+ message?: string;
1065
+ testedAt?: string;
1066
+ expiresAt?: string;
1067
+ details?: Readonly<Record<string, unknown>>;
1068
+ }>;
1069
+ type OAuth2ProviderFromPublicConfig = Readonly<{
1070
+ authorizeUrlFieldKey: string;
1071
+ tokenUrlFieldKey: string;
1072
+ userInfoUrlFieldKey?: string;
1073
+ }>;
1074
+ type CredentialOAuth2AuthDefinition = Readonly<{
1075
+ kind: "oauth2";
1076
+ providerId: string;
1077
+ scopes: ReadonlyArray<string>;
1078
+ clientIdFieldKey?: string;
1079
+ clientSecretFieldKey?: string;
1080
+ } | {
1081
+ kind: "oauth2";
1082
+ providerFromPublicConfig: OAuth2ProviderFromPublicConfig;
1083
+ scopes: ReadonlyArray<string>;
1084
+ clientIdFieldKey?: string;
1085
+ clientSecretFieldKey?: string;
1086
+ }>;
1087
+ type CredentialAuthDefinition = CredentialOAuth2AuthDefinition;
1088
+ type CredentialTypeDefinition = Readonly<{
1089
+ typeId: CredentialTypeId;
1090
+ displayName: string;
1091
+ description?: string;
1092
+ publicFields?: ReadonlyArray<CredentialFieldSchema>;
1093
+ secretFields?: ReadonlyArray<CredentialFieldSchema>;
1094
+ supportedSourceKinds?: ReadonlyArray<CredentialMaterialSourceKind>;
1095
+ auth?: CredentialAuthDefinition;
1096
+ }>;
1097
+ /**
1098
+ * JSON-shaped credential field bag (public config, resolved secret material, etc.).
1099
+ */
1100
+ type CredentialJsonRecord = Readonly<Record<string, unknown>>;
1101
+ /**
1102
+ * Persisted credential instance with typed `publicConfig`.
1103
+ * Hosts may specialize `secretRef` with a stricter union while remaining
1104
+ * assignable here for session/test callbacks.
1105
+ */
1106
+ type CredentialInstanceRecord<TPublicConfig extends CredentialJsonRecord = CredentialJsonRecord> = Readonly<{
1107
+ instanceId: CredentialInstanceId;
1108
+ typeId: CredentialTypeId;
1109
+ displayName: string;
1110
+ sourceKind: CredentialMaterialSourceKind;
1111
+ publicConfig: TPublicConfig;
1112
+ secretRef: CredentialJsonRecord;
1113
+ tags: ReadonlyArray<string>;
1114
+ setupStatus: CredentialSetupStatus;
1115
+ createdAt: string;
1116
+ updatedAt: string;
1117
+ }>;
1118
+ /**
1119
+ * Arguments passed to `CredentialType.createSession` and `CredentialType.test`.
1120
+ * Declare `TPublicConfig` / `TMaterial` on `CredentialType` so implementations are checked
1121
+ * against your credential shapes (similar to `NodeExecutionContext.config` for nodes).
1122
+ */
1123
+ type CredentialSessionFactoryArgs<TPublicConfig extends CredentialJsonRecord = CredentialJsonRecord, TMaterial extends CredentialJsonRecord = CredentialJsonRecord> = Readonly<{
1124
+ instance: CredentialInstanceRecord<TPublicConfig>;
1125
+ material: TMaterial;
1126
+ publicConfig: TPublicConfig;
1127
+ }>;
1128
+ type CredentialSessionFactory<TPublicConfig extends CredentialJsonRecord = CredentialJsonRecord, TMaterial extends CredentialJsonRecord = CredentialJsonRecord, TSession = unknown> = (args: CredentialSessionFactoryArgs<TPublicConfig, TMaterial>) => Promise<TSession>;
1129
+ type CredentialHealthTester<TPublicConfig extends CredentialJsonRecord = CredentialJsonRecord, TMaterial extends CredentialJsonRecord = CredentialJsonRecord> = (args: CredentialSessionFactoryArgs<TPublicConfig, TMaterial>) => Promise<CredentialHealth>;
1130
+ /**
1131
+ * Full credential type implementation: `definition` (UI/schema), `createSession`, and `test`.
1132
+ * Use this at registration and config boundaries; `CredentialTypeDefinition` is only the schema slice.
1133
+ */
1134
+ type CredentialType<TPublicConfig extends CredentialJsonRecord = CredentialJsonRecord, TMaterial extends CredentialJsonRecord = CredentialJsonRecord, TSession = unknown> = Readonly<{
1135
+ definition: CredentialTypeDefinition;
1136
+ createSession: CredentialSessionFactory<TPublicConfig, TMaterial, TSession>;
1137
+ test: CredentialHealthTester<TPublicConfig, TMaterial>;
1138
+ }>;
1139
+ /**
1140
+ * Credential type with unspecified generics — used for `CodemationConfig.credentialTypes`, the host registry,
1141
+ * and anywhere a concrete `CredentialType<YourPublic, YourMaterial, YourSession>` is placed in a heterogeneous list.
1142
+ * Using `any` here avoids unsafe `as` casts while keeping typed `satisfies CredentialType<…>` definitions.
1143
+ */
1144
+ type AnyCredentialType = CredentialType<any, any, unknown>;
1145
+ interface CredentialSessionService {
1146
+ getSession<TSession = unknown>(args: Readonly<{
1147
+ workflowId: WorkflowId;
1148
+ nodeId: NodeId;
1149
+ slotKey: string;
1150
+ }>): Promise<TSession>;
1151
+ }
1152
+ interface CredentialTypeRegistry {
1153
+ listTypes(): ReadonlyArray<CredentialTypeDefinition>;
1154
+ getType(typeId: CredentialTypeId): CredentialTypeDefinition | undefined;
1155
+ }
1156
+ declare class CredentialUnboundError extends Error {
1157
+ readonly bindingKey: CredentialBindingKey;
1158
+ readonly acceptedTypes: ReadonlyArray<CredentialTypeId>;
1159
+ constructor(bindingKey: CredentialBindingKey, acceptedTypes?: ReadonlyArray<CredentialTypeId>);
1160
+ private static createMessage;
1161
+ }
1162
+ //#endregion
1163
+ //#region src/runtime/InMemoryLiveWorkflowRepository.d.ts
1164
+ declare class InMemoryLiveWorkflowRepository implements LiveWorkflowRepository {
1165
+ private readonly workflowsById;
1166
+ setWorkflows(workflows: ReadonlyArray<WorkflowDefinition>): void;
1167
+ list(): ReadonlyArray<WorkflowDefinition>;
1168
+ get(workflowId: WorkflowId): WorkflowDefinition | undefined;
1169
+ }
1170
+ //#endregion
1171
+ export { OutputPortKey as $, RunCurrentState as $n, NodeActivationRequestBase as $t, ExecutionMode as A, WebhookTriggerRoutingDiagnostics as An, CoreTokens as Ar, runnableNodeInputType as At, NodeActivationId as B, NodeExecutionSnapshot as Bn, RetryPolicySpec as Br, BinaryStorageWriteResult as Bt, CredentialTypeRegistry as C, WorkflowSnapshotResolver as Cn, injectAll as Cr, WorkflowPolicyRuntimeDefaults as Ct, BinaryAttachment as D, WebhookInvocationMatch as Dn, predicateAwareClassFactory as Dr, WorkflowStoragePolicyResolver as Dt, ActivationIdFactory as E, WebhookControlSignal as En, instancePerContainerCachingFactory as Er, WorkflowStoragePolicyMode as Et, JsonArray as F, ConnectionInvocationRecord as Fn, RunEventBus as Fr, BinaryBody as Ft, NodeErrorHandlerArgs as G, PersistedMutableRunState as Gn, ExecutionContext as Gt, NodeConnectionName as H, NodeInputsByPort as Hn, EngineHost as Ht, JsonObject as I, CurrentStateExecutionRequest as In, RunEventSubscription as Ir, BinaryStorage as It, NodeKind as J, PersistedWorkflowSnapshot as Jn, MultiInputNode as Jt, NodeErrorHandlerSpec as K, PersistedRunControlState as Kn, ExecutionContextFactory as Kt, JsonPrimitive as L, EngineRunCounters as Ln, ExponentialRetryPolicySpec as Lr, BinaryStorageReadResult as Lt, Item as M, WorkflowActivationPolicy as Mn, EngineExecutionLimitsPolicy as Mr, triggerNodeOutputType as Mt, ItemBinary as N, ConnectionInvocationAppendArgs as Nn, EngineExecutionLimitsPolicyConfig as Nr, triggerNodeSetupStateType as Nt, BinaryPreviewKind as O, WebhookTriggerMatcher as On, registry as Or, WorkflowStoragePolicySpec as Ot, Items as P, ConnectionInvocationId as Pn, RunEvent as Pr, BinaryAttachmentCreateRequest as Pt, NodeSchedulerDecision as Q, RunCompletionNotifier as Qn, NodeActivationRequest as Qt, JsonValue as R, ExecutionFrontierPlan as Rn, FixedRetryPolicySpec as Rr, BinaryStorageStatResult as Rt, CredentialTypeId as S, WorkflowSnapshotFactory as Sn, inject as Sr, WorkflowNodeConnection as St, OAuth2ProviderFromPublicConfig as T, TriggerInstanceId as Tn, instanceCachingFactory as Tr, WorkflowStoragePolicyDecisionArgs as Tt, NodeDefinition as U, PendingNodeExecution as Un, ExecutableTriggerNode as Ut, NodeConfigBase as V, NodeExecutionStatus as Vn, EngineDeps as Vt, NodeErrorHandler as W, PersistedMutableNodeState as Wn, ExecutionBinaryService as Wt, NodeOutputs as X, PersistedWorkflowTokenRegistryLike as Xn, NodeActivationContinuation as Xt, NodeOffloadPolicy as Y, PersistedWorkflowSnapshotNode as Yn, Node as Yt, NodeRef as Z, PinnedNodeOutputsByPort as Zn, NodeActivationReceipt as Zt, CredentialSessionFactoryArgs as _, TriggerTestItemsContext as _n, Lifecycle as _r, WorkflowErrorHandler as _t, CredentialBindingKey as a, NodeExecutionScheduler as an, RunStateResetRequest as ar, RunDataSnapshot as at, CredentialType as b, WorkflowRunnerResolver as bn, container as br, WorkflowGraphFactory as bt, CredentialHealthStatus as c, NodeResolver as cn, RunSummary as cr, RunnableNodeConfig as ct, CredentialInstanceRecord as d, TriggerCleanupHandle as dn, WorkflowExecutionPruneRepository as dr, TriggerNodeConfig as dt, NodeActivationScheduler as en, RunEventPublisherDeps as er, PairedItemRef as et, CredentialJsonRecord as f, TriggerNode as fn, WorkflowExecutionRepository as fr, TriggerNodeOutputJson as ft, CredentialSessionFactory as g, TriggerSetupStateRepository as gn, InjectionToken as gr, WorkflowErrorContext as gt, CredentialRequirement as h, TriggerSetupStateFor as hn, Disposable as hr, WorkflowDefinition as ht, CredentialBinding as i, NodeExecutionRequestHandler as in, RunResult as ir, RunDataFactory as it, InputPortKey as j, AllWorkflowsActiveWorkflowActivationPolicy as jn, ENGINE_EXECUTION_LIMITS_DEFAULTS as jr, runnableNodeOutputType as jt, Edge as k, WebhookTriggerResolution as kn, singleton as kr, branchRef as kt, CredentialHealthTester as l, PersistedTriggerSetupState as ln, WebhookRunResult as lr, RunnableNodeInputJson as lt, CredentialOAuth2AuthDefinition as m, TriggerSetupContext as mn, DependencyContainer as mr, UpstreamRefPlaceholder as mt, AnyCredentialType as n, NodeExecutionContext as nn, RunPruneCandidate as nr, PersistedRunPolicySnapshot as nt, CredentialFieldSchema as o, NodeExecutionStatePublisher as on, RunStatus as or, RunId as ot, CredentialMaterialSourceKind as p, TriggerRuntimeDiagnostics as pn, Container as pr, TriggerNodeSetupState as pt, NodeId as q, PersistedRunState as qn, LiveWorkflowRepository as qt, CredentialAuthDefinition as r, NodeExecutionRequest as rn, RunQueueEntry as rr, PersistedTokenId as rt, CredentialHealth as s, NodeExecutor as sn, RunStopCondition as sr, RunIdFactory as st, InMemoryLiveWorkflowRepository as t, NodeBinaryAttachmentService as tn, RunExecutionOptions as tr, ParentExecutionRef as tt, CredentialInstanceId as u, TestableTriggerNode as un, WorkflowExecutionListingRepository as ur, RunnableNodeOutputJson as ut, CredentialSessionService as v, WorkflowNodeInstanceFactory as vn, RegistrationOptions as vr, WorkflowErrorHandlerSpec as vt, CredentialUnboundError as w, HttpMethod as wn, injectable as wr, WorkflowPrunePolicySpec as wt, CredentialTypeDefinition as x, WorkflowRunnerService as xn, delay as xr, WorkflowId as xt, CredentialSetupStatus as y, WorkflowRepository as yn, TypeToken as yr, WorkflowGraph as yt, MutableRunData as z, NodeExecutionError as zn, NoneRetryPolicySpec as zr, BinaryStorageWriteRequest as zt };
1172
+ //# sourceMappingURL=InMemoryLiveWorkflowRepository-orY1VsWG.d.cts.map