@codemation/core 0.6.0 → 0.8.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/{EngineRuntimeRegistration.types-Dm129RJ6.d.ts → EngineRuntimeRegistration.types-BP6tsaNP.d.ts} +4 -2
  3. package/dist/{EngineWorkflowRunnerService-Bf88QtwB.d.cts → EngineWorkflowRunnerService-DzOCa1BW.d.cts} +4 -2
  4. package/dist/{InMemoryRunDataFactory-Dyl4p2s8.d.cts → InMemoryRunDataFactory-1iz7_SnO.d.cts} +27 -7
  5. package/dist/{workflowActivationPolicy-6V3OJD3N.cjs → InMemoryRunEventBusRegistry-B0_C4OnP.cjs} +1 -16
  6. package/dist/InMemoryRunEventBusRegistry-B0_C4OnP.cjs.map +1 -0
  7. package/dist/{workflowActivationPolicy-Td9HTOuD.js → InMemoryRunEventBusRegistry-C2U83Hmv.js} +2 -11
  8. package/dist/InMemoryRunEventBusRegistry-C2U83Hmv.js.map +1 -0
  9. package/dist/{RunIntentService-BDiodxhf.d.ts → RunIntentService-BqhmdoA1.d.ts} +258 -21
  10. package/dist/{RunIntentService-B1Y3v1H6.d.cts → RunIntentService-S-1lW-gS.d.cts} +209 -5
  11. package/dist/bootstrap/index.cjs +4 -2
  12. package/dist/bootstrap/index.d.cts +26 -7
  13. package/dist/bootstrap/index.d.ts +4 -4
  14. package/dist/bootstrap/index.js +3 -3
  15. package/dist/{bootstrap-DVL2ue5v.cjs → bootstrap-BaN6hZ5I.cjs} +7 -4
  16. package/dist/bootstrap-BaN6hZ5I.cjs.map +1 -0
  17. package/dist/{bootstrap-DdeiJ8cd.js → bootstrap-d_BMaDT4.js} +7 -4
  18. package/dist/bootstrap-d_BMaDT4.js.map +1 -0
  19. package/dist/{index-C2af8ssM.d.ts → index-CVs9rVhl.d.ts} +44 -13
  20. package/dist/index.cjs +59 -88
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +47 -22
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.js +33 -75
  25. package/dist/index.js.map +1 -1
  26. package/dist/{runtime-7Xh9z3dw.js → runtime-DUW6tIJ1.js} +454 -64
  27. package/dist/runtime-DUW6tIJ1.js.map +1 -0
  28. package/dist/{runtime-DVBwxFvX.cjs → runtime-Dvo2ru5A.cjs} +589 -73
  29. package/dist/runtime-Dvo2ru5A.cjs.map +1 -0
  30. package/dist/testing.cjs +6 -6
  31. package/dist/testing.cjs.map +1 -1
  32. package/dist/testing.d.cts +2 -2
  33. package/dist/testing.d.ts +2 -2
  34. package/dist/testing.js +3 -3
  35. package/package.json +1 -1
  36. package/src/ai/AgentConfigInspectorFactory.ts +2 -2
  37. package/src/ai/AgentMessageConfigNormalizerFactory.ts +3 -3
  38. package/src/ai/AiHost.ts +4 -2
  39. package/src/ai/CallableToolConfig.ts +28 -3
  40. package/src/authoring/defineNode.types.ts +35 -9
  41. package/src/authoring/index.ts +1 -0
  42. package/src/bootstrap/index.ts +6 -1
  43. package/src/bootstrap/runtime/EngineRuntimeRegistrar.ts +4 -3
  44. package/src/bootstrap/runtime/EngineRuntimeRegistration.types.ts +3 -0
  45. package/src/contracts/CodemationTelemetryAttributeNames.ts +12 -0
  46. package/src/contracts/CodemationTelemetryMetricNames.ts +7 -0
  47. package/src/contracts/CostCatalogContract.ts +16 -0
  48. package/src/contracts/CostTrackingTelemetryContract.ts +47 -0
  49. package/src/contracts/GenAiTelemetryAttributeNames.ts +10 -0
  50. package/src/contracts/NoOpCostTrackingTelemetry.ts +16 -0
  51. package/src/contracts/NoOpCostTrackingTelemetryFactory.ts +9 -0
  52. package/src/contracts/NoOpExecutionTelemetry.ts +26 -0
  53. package/src/contracts/NoOpExecutionTelemetryFactory.ts +16 -0
  54. package/src/contracts/NoOpNodeExecutionTelemetry.ts +15 -0
  55. package/src/contracts/NoOpTelemetryArtifactReference.ts +9 -0
  56. package/src/contracts/NoOpTelemetrySpanScope.ts +22 -0
  57. package/src/contracts/index.ts +3 -1
  58. package/src/contracts/{itemValue.ts → itemExpr.ts} +31 -32
  59. package/src/contracts/params.ts +10 -0
  60. package/src/contracts/runTypes.ts +4 -1
  61. package/src/contracts/runtimeTypes.ts +7 -0
  62. package/src/contracts/telemetryTypes.ts +105 -0
  63. package/src/contracts/workflowTypes.ts +20 -2
  64. package/src/events/EventPublishingWorkflowExecutionRepository.ts +1 -1
  65. package/src/execution/CatalogBackedCostTrackingTelemetry.ts +81 -0
  66. package/src/execution/CatalogBackedCostTrackingTelemetryFactory.ts +12 -0
  67. package/src/execution/DefaultExecutionContextFactory.ts +23 -0
  68. package/src/execution/ExecutionTelemetryCostTrackingDecoratorFactory.ts +84 -0
  69. package/src/execution/{ItemValueResolver.ts → ItemExprResolver.ts} +5 -5
  70. package/src/execution/NodeActivationRequestComposer.ts +1 -0
  71. package/src/execution/NodeExecutionSnapshotFactory.ts +2 -0
  72. package/src/execution/NodeExecutor.ts +6 -6
  73. package/src/execution/StaticCostCatalog.ts +22 -0
  74. package/src/execution/WorkflowRunExecutionContextFactory.ts +2 -0
  75. package/src/execution/index.ts +5 -1
  76. package/src/index.ts +1 -1
  77. package/src/orchestration/NodeExecutionRequestHandlerService.ts +1 -0
  78. package/src/orchestration/RunContinuationService.ts +4 -0
  79. package/src/orchestration/RunStartService.ts +2 -0
  80. package/src/policies/storage/RunPolicySnapshotFactory.ts +9 -0
  81. package/src/runStorage/InMemoryRunData.ts +9 -5
  82. package/src/runStorage/InMemoryWorkflowExecutionRepository.ts +4 -2
  83. package/src/types/index.ts +7 -1
  84. package/src/workflowSnapshots/WorkflowSnapshotCodec.ts +1 -1
  85. package/dist/bootstrap-DVL2ue5v.cjs.map +0 -1
  86. package/dist/bootstrap-DdeiJ8cd.js.map +0 -1
  87. package/dist/runtime-7Xh9z3dw.js.map +0 -1
  88. package/dist/runtime-DVBwxFvX.cjs.map +0 -1
  89. package/dist/workflowActivationPolicy-6V3OJD3N.cjs.map +0 -1
  90. package/dist/workflowActivationPolicy-Td9HTOuD.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @codemation/core
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`782e934`](https://github.com/MadeRelevant/codemation/commit/782e93469ea6eee701d976b8f1dc18649d045c79) Thanks [@cblokland90](https://github.com/cblokland90)! - Add catalog-backed cost tracking contracts and wire AI/OCR usage into telemetry so hosts can aggregate provider-native execution costs.
8
+
9
+ Improve the telemetry dashboard and workflow detail experience with cost breakdowns, richer inspector data, workflow run cost totals, and credential rebinding fixes.
10
+
11
+ ### Patch Changes
12
+
13
+ - [#85](https://github.com/MadeRelevant/codemation/pull/85) [`a250ab8`](https://github.com/MadeRelevant/codemation/commit/a250ab8b973429cdfe708526a205e2565b004868) Thanks [@cblokland90](https://github.com/cblokland90)! - Decouple telemetry retention from run deletion and move node-specific measurements onto metric points.
14
+ - allow telemetry spans, artifacts, and metrics to outlive raw run state through explicit retention timestamps
15
+ - narrow telemetry spans to canonical span fields and persist extensible node-specific measurements as metric points
16
+ - update telemetry queries, docs, and regression coverage around real workflow execution plus agent/tool observability
17
+
18
+ - [#88](https://github.com/MadeRelevant/codemation/pull/88) [`052aba1`](https://github.com/MadeRelevant/codemation/commit/052aba17c9a4faf557bdfaa1a9644a1987ecc25e) Thanks [@cblokland90](https://github.com/cblokland90)! - Add a telemetry-backed node inspector slice for workflow detail and expose run-trace telemetry needed to power it.
19
+
20
+ - [`1a356af`](https://github.com/MadeRelevant/codemation/commit/1a356afae50bd3f982e92c3e9f931e3adbcd131f) - Repair malformed AI tool calls inside the agent loop instead of replaying the whole agent node, and surface clearer debugging details when recovery succeeds or is exhausted.
21
+ - classify repairable validation failures separately from non-repairable tool errors and preserve stable invocation correlation for failed calls
22
+ - persist structured validation details and expose them in next-host inspector fallbacks, timelines, and error views
23
+ - add regression coverage for repaired tool calls, exhaustion behavior, and mixed parallel tool rounds
24
+
25
+ ## 0.7.0
26
+
27
+ ### Minor Changes
28
+
29
+ - [#81](https://github.com/MadeRelevant/codemation/pull/81) [`88844f7`](https://github.com/MadeRelevant/codemation/commit/88844f75a48fe051e4cb895c710408855de14da4) Thanks [@cblokland90](https://github.com/cblokland90)! - Add typed workflow authoring helpers for reusable node params and run-data reads.
30
+ - export `Expr`, `Param`, and `ParamDeep` so helper-defined node params can accept literals or `itemExpr(...)`
31
+ - export `nodeRef<TJson>()` plus generic `RunDataSnapshot` item accessors for typed `ctx.data` reads
32
+ - keep helper-node runtime config resolved while expanding the public authoring surface for expression-style params
33
+
3
34
  ## 0.6.0
4
35
 
5
36
  ### Minor Changes
@@ -1,4 +1,4 @@
1
- import { Mi as DependencyContainer, Zi as EngineExecutionLimitsPolicyConfig, ir as TriggerRuntimeDiagnostics, xr as WebhookTriggerRoutingDiagnostics, yr as WebhookTriggerMatcher } from "./RunIntentService-BDiodxhf.js";
1
+ import { Ar as WebhookTriggerRoutingDiagnostics, Or as WebhookTriggerMatcher, Pa as EngineExecutionLimitsPolicyConfig, ha as DependencyContainer, hn as WorkflowPolicyRuntimeDefaults, pr as TriggerRuntimeDiagnostics } from "./RunIntentService-BqhmdoA1.js";
2
2
 
3
3
  //#region src/bootstrap/runtime/EngineRuntimeRegistration.types.d.ts
4
4
 
@@ -36,7 +36,9 @@ interface EngineRuntimeRegistrationOptions {
36
36
  webhookTriggerMatcherProvider?: WebhookTriggerMatcherProvider;
37
37
  /** Overrides default trigger diagnostics (undefined when omitted). */
38
38
  triggerRuntimeDiagnosticsProvider?: TriggerRuntimeDiagnosticsProvider;
39
+ /** Runtime retention/storage defaults used when workflows omit prune/storage policy fields. */
40
+ workflowPolicyRuntimeDefaults?: WorkflowPolicyRuntimeDefaults;
39
41
  }
40
42
  //#endregion
41
43
  export { TriggerRuntimeDiagnosticsProvider as n, WebhookTriggerMatcherProvider as r, EngineRuntimeRegistrationOptions as t };
42
- //# sourceMappingURL=EngineRuntimeRegistration.types-Dm129RJ6.d.ts.map
44
+ //# sourceMappingURL=EngineRuntimeRegistration.types-BP6tsaNP.d.ts.map
@@ -1,4 +1,4 @@
1
- import { $t as TriggerRuntimeDiagnostics, Dr as DependencyContainer, E as NodeId, Fn as PersistedWorkflowSnapshot, Gn as RunResult, In as PersistedWorkflowSnapshotNode, J as WorkflowDefinition, Kr as EngineExecutionLimitsPolicyConfig, Ln as PersistedWorkflowTokenRegistryLike, P as ParentExecutionRef, an as WorkflowRepository, b as NodeConfigBase, et as WorkflowId, f as Items, gn as WebhookTriggerRoutingDiagnostics, mn as WebhookTriggerMatcher, r as Engine } from "./RunIntentService-B1Y3v1H6.cjs";
1
+ import { E as NodeId, F as ParentExecutionRef, Ln as PersistedWorkflowSnapshot, Rn as PersistedWorkflowSnapshotNode, Si as EngineExecutionLimitsPolicyConfig, Y as WorkflowDefinition, b as NodeConfigBase, f as Items, gn as WebhookTriggerMatcher, qn as RunResult, r as Engine, ri as DependencyContainer, rt as WorkflowPolicyRuntimeDefaults, sn as WorkflowRepository, tn as TriggerRuntimeDiagnostics, tt as WorkflowId, vn as WebhookTriggerRoutingDiagnostics, zn as PersistedWorkflowTokenRegistryLike } from "./RunIntentService-S-1lW-gS.cjs";
2
2
 
3
3
  //#region src/workflowSnapshots/WorkflowSnapshotCodec.d.ts
4
4
  declare class WorkflowSnapshotCodec {
@@ -53,6 +53,8 @@ interface EngineRuntimeRegistrationOptions {
53
53
  webhookTriggerMatcherProvider?: WebhookTriggerMatcherProvider;
54
54
  /** Overrides default trigger diagnostics (undefined when omitted). */
55
55
  triggerRuntimeDiagnosticsProvider?: TriggerRuntimeDiagnosticsProvider;
56
+ /** Runtime retention/storage defaults used when workflows omit prune/storage policy fields. */
57
+ workflowPolicyRuntimeDefaults?: WorkflowPolicyRuntimeDefaults;
56
58
  }
57
59
  //#endregion
58
60
  //#region src/runtime/EngineWorkflowRunnerService.d.ts
@@ -70,4 +72,4 @@ declare class EngineWorkflowRunnerService {
70
72
  }
71
73
  //#endregion
72
74
  export { WorkflowSnapshotCodec as a, WebhookTriggerMatcherProvider as i, EngineRuntimeRegistrationOptions as n, TriggerRuntimeDiagnosticsProvider as r, EngineWorkflowRunnerService as t };
73
- //# sourceMappingURL=EngineWorkflowRunnerService-Bf88QtwB.d.cts.map
75
+ //# sourceMappingURL=EngineWorkflowRunnerService-DzOCa1BW.d.cts.map
@@ -1,5 +1,20 @@
1
- import { Ct as BinaryStorageWriteResult, Dt as ExecutionBinaryService, E as NodeId, L as RunDataFactory, Ot as ExecutionContext, P as ParentExecutionRef, R as RunDataSnapshot, Rt as NodeBinaryAttachmentService, Ut as NodeExecutionStatePublisher, V as RunnableNodeConfig, a as BinaryAttachment, bt as BinaryStorageReadResult, et as WorkflowId, gt as RetryPolicySpec, k as NodeOutputs, kt as ExecutionContextFactory, u as Item, v as MutableRunData, vr as CredentialSessionService, vt as BinaryBody, xt as BinaryStorageStatResult, y as NodeActivationId, yt as BinaryStorage, z as RunId, zt as NodeExecutionContext } from "./RunIntentService-B1Y3v1H6.cjs";
1
+ import { A as NodeOutputs, At as ExecutionContext, B as RunId, Bt as NodeBinaryAttachmentService, Ct as BinaryStorageStatResult, Dr as CostTrackingTelemetryFactory, E as NodeId, F as ParentExecutionRef, Gt as NodeExecutionStatePublisher, H as RunnableNodeConfig, I as PersistedRunPolicySnapshot, Jr as CredentialSessionService, R as RunDataFactory, St as BinaryStorageReadResult, Tt as BinaryStorageWriteResult, Vt as NodeExecutionContext, a as BinaryAttachment, bt as BinaryBody, jt as ExecutionContextFactory, kr as CostTrackingUsageRecord, kt as ExecutionBinaryService, rr as ExecutionTelemetryFactory, tt as WorkflowId, u as Item, v as MutableRunData, vt as RetryPolicySpec, xt as BinaryStorage, y as NodeActivationId, z as RunDataSnapshot } from "./RunIntentService-S-1lW-gS.cjs";
2
2
 
3
+ //#region src/contracts/CostCatalogContract.d.ts
4
+ interface CostCatalogEntry {
5
+ readonly component: CostTrackingUsageRecord["component"];
6
+ readonly provider: string;
7
+ readonly operation: string;
8
+ readonly pricingKey: string;
9
+ readonly usageUnit: string;
10
+ readonly currency: string;
11
+ readonly currencyScale: number;
12
+ readonly pricePerUnitMinor: number;
13
+ }
14
+ interface CostCatalog {
15
+ findEntry(args: CostTrackingUsageRecord): CostCatalogEntry | undefined;
16
+ }
17
+ //#endregion
3
18
  //#region src/execution/CredentialResolverFactory.d.ts
4
19
  declare class CredentialResolverFactory {
5
20
  private readonly credentialSessions;
@@ -20,17 +35,22 @@ declare class DefaultAsyncSleeper implements AsyncSleeper {
20
35
  //#region src/execution/DefaultExecutionContextFactory.d.ts
21
36
  declare class DefaultExecutionContextFactory implements ExecutionContextFactory {
22
37
  private readonly binaryStorage;
38
+ private readonly telemetryFactory;
39
+ private readonly costTrackingFactory;
23
40
  private readonly currentDate;
24
- constructor(binaryStorage?: BinaryStorage, currentDate?: () => Date);
41
+ private readonly telemetryDecoratorFactory;
42
+ constructor(binaryStorage?: BinaryStorage, telemetryFactory?: ExecutionTelemetryFactory, costTrackingFactory?: CostTrackingTelemetryFactory, currentDate?: () => Date);
25
43
  create(args: {
26
44
  runId: RunId;
27
45
  workflowId: WorkflowId;
28
46
  parent?: ParentExecutionRef;
47
+ policySnapshot?: PersistedRunPolicySnapshot;
29
48
  subworkflowDepth: number;
30
49
  engineMaxNodeActivations: number;
31
50
  engineMaxSubworkflowDepth: number;
32
51
  data: RunDataSnapshot;
33
52
  nodeState?: NodeExecutionStatePublisher;
53
+ telemetry?: ExecutionContext["telemetry"];
34
54
  getCredential<TSession = unknown>(slotKey: string): Promise<TSession>;
35
55
  }): ExecutionContext;
36
56
  }
@@ -47,11 +67,11 @@ declare class InProcessRetryRunner {
47
67
  private static assertMultiplier;
48
68
  }
49
69
  //#endregion
50
- //#region src/execution/ItemValueResolver.d.ts
70
+ //#region src/execution/ItemExprResolver.d.ts
51
71
  /**
52
- * Resolves {@link import("../contracts/itemValue").ItemValue} leaves on runnable config before {@link RunnableNode.execute}.
72
+ * Resolves {@link import("../contracts/itemExpr").ItemExpr} leaves on runnable config before {@link RunnableNode.execute}.
53
73
  */
54
- declare class ItemValueResolver {
74
+ declare class ItemExprResolver {
55
75
  resolveConfigForItem<TConfig extends RunnableNodeConfig<any, any>>(ctx: NodeExecutionContext<TConfig>, item: Item, itemIndex: number, items: ReadonlyArray<Item>): Promise<NodeExecutionContext<TConfig>>;
56
76
  }
57
77
  //#endregion
@@ -107,5 +127,5 @@ declare class InMemoryRunDataFactory implements RunDataFactory {
107
127
  create(initial?: Record<NodeId, NodeOutputs>): MutableRunData;
108
128
  }
109
129
  //#endregion
110
- export { RunnableOutputBehavior as a, InProcessRetryRunner as c, AsyncSleeper as d, CredentialResolverFactory as f, UnavailableBinaryStorage as i, DefaultExecutionContextFactory as l, InMemoryBinaryStorage as n, RunnableOutputBehaviorResolver as o, DefaultExecutionBinaryService as r, ItemValueResolver as s, InMemoryRunDataFactory as t, DefaultAsyncSleeper as u };
111
- //# sourceMappingURL=InMemoryRunDataFactory-Dyl4p2s8.d.cts.map
130
+ export { RunnableOutputBehavior as a, InProcessRetryRunner as c, AsyncSleeper as d, CredentialResolverFactory as f, UnavailableBinaryStorage as i, DefaultExecutionContextFactory as l, CostCatalogEntry as m, InMemoryBinaryStorage as n, RunnableOutputBehaviorResolver as o, CostCatalog as p, DefaultExecutionBinaryService as r, ItemExprResolver as s, InMemoryRunDataFactory as t, DefaultAsyncSleeper as u };
131
+ //# sourceMappingURL=InMemoryRunDataFactory-1iz7_SnO.d.cts.map
@@ -235,21 +235,6 @@ var InMemoryRunEventBus = class {
235
235
  };
236
236
 
237
237
  //#endregion
238
- //#region src/contracts/workflowActivationPolicy.ts
239
- /** Default for tests and harnesses: every workflow is treated as active (legacy behavior). */
240
- var AllWorkflowsActiveWorkflowActivationPolicy = class {
241
- isActive(_workflowId) {
242
- return true;
243
- }
244
- };
245
-
246
- //#endregion
247
- Object.defineProperty(exports, 'AllWorkflowsActiveWorkflowActivationPolicy', {
248
- enumerable: true,
249
- get: function () {
250
- return AllWorkflowsActiveWorkflowActivationPolicy;
251
- }
252
- });
253
238
  Object.defineProperty(exports, 'ChainCursor', {
254
239
  enumerable: true,
255
240
  get: function () {
@@ -274,4 +259,4 @@ Object.defineProperty(exports, 'WorkflowBuilder', {
274
259
  return WorkflowBuilder;
275
260
  }
276
261
  });
277
- //# sourceMappingURL=workflowActivationPolicy-6V3OJD3N.cjs.map
262
+ //# sourceMappingURL=InMemoryRunEventBusRegistry-B0_C4OnP.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryRunEventBusRegistry-B0_C4OnP.cjs","names":["wf: WorkflowBuilder","from: NodeRef","branchPort: OutputPortKey","created: NodeRef[]","prev: NodeRef | null","port: OutputPortKey","wf: WorkflowBuilder","endpoints: ReadonlyArray<ChainCursorEndpoint>","port: OutputPortKey","prev: NodeRef | null","nextEndpoints: ChainCursorEndpoint[]","meta: { id: WorkflowId; name: string }","options?: Readonly<Record<string, never>>","onClose: () => void"],"sources":["../src/workflow/dsl/WhenBuilder.ts","../src/workflow/dsl/ChainCursorResolver.ts","../src/workflow/dsl/WorkflowBuilder.ts","../src/events/InMemoryRunEventSubscription.ts","../src/events/InMemoryRunEventBusRegistry.ts"],"sourcesContent":["import type { NodeId, NodeRef, OutputPortKey, UpstreamRefPlaceholder, WorkflowDefinition } from \"../../types\";\n\nimport { WorkflowBuilder } from \"./WorkflowBuilder\";\nimport type { AnyRunnableNodeConfig, BooleanWhenOverloads, ValidStepSequence } from \"./workflowBuilderTypes\";\n\nexport class WhenBuilder<TCurrentJson> {\n constructor(\n private readonly wf: WorkflowBuilder,\n private readonly from: NodeRef,\n private readonly branchPort: OutputPortKey,\n ) {}\n\n addBranch<TSteps extends ReadonlyArray<AnyRunnableNodeConfig>>(\n steps: TSteps & ValidStepSequence<TCurrentJson, TSteps>,\n ): this {\n const created: NodeRef[] = [];\n\n let prev: NodeRef | null = null;\n for (const cfg of steps) {\n const ref = (this.wf as any).add(cfg) as NodeRef;\n created.push(ref);\n if (!prev) (this.wf as any).connect(this.from, ref, this.branchPort, \"in\");\n else (this.wf as any).connect(prev, ref, \"main\", \"in\");\n prev = ref;\n }\n\n for (const cfg of steps) {\n const maybe = cfg as unknown as { upstreamRefs?: Array<{ nodeId: NodeId } | UpstreamRefPlaceholder> };\n if (!Array.isArray(maybe.upstreamRefs) || maybe.upstreamRefs.length === 0) continue;\n\n maybe.upstreamRefs = maybe.upstreamRefs.map((r) => {\n if (typeof r !== \"string\") return r;\n const idx = parseInt(r.slice(1), 10);\n const nodeId = created[idx]?.id;\n return nodeId ? { nodeId } : { nodeId: r };\n });\n }\n\n return this;\n }\n\n readonly when: BooleanWhenOverloads<TCurrentJson, WhenBuilder<TCurrentJson>> = (\n branch: boolean,\n steps: ReadonlyArray<AnyRunnableNodeConfig> | AnyRunnableNodeConfig,\n ...more: AnyRunnableNodeConfig[]\n ): WhenBuilder<TCurrentJson> => {\n const list = Array.isArray(steps) ? steps : [steps, ...more];\n const port: OutputPortKey = branch ? \"true\" : \"false\";\n const b = new WhenBuilder<TCurrentJson>(this.wf, this.from, port);\n b.addBranch(list);\n return b;\n };\n\n build(): WorkflowDefinition {\n return this.wf.build();\n }\n}\n","import type {\n InputPortKey,\n NodeRef,\n OutputPortKey,\n RunnableNodeConfig,\n RunnableNodeOutputJson,\n WorkflowDefinition,\n} from \"../../types\";\n\nimport { WorkflowBuilder } from \"./WorkflowBuilder\";\nimport { WhenBuilder } from \"./WhenBuilder\";\nimport type {\n AnyRunnableNodeConfig,\n BooleanWhenOverloads,\n BranchOutputGuard,\n BranchStepsArg,\n StepSequenceOutput,\n} from \"./workflowBuilderTypes\";\n\ntype ChainCursorEndpoint = Readonly<{ node: NodeRef; output: OutputPortKey; inputPortHint?: InputPortKey }>;\n\ntype ChainCursorWhenOverloads<TCurrentJson> = BooleanWhenOverloads<TCurrentJson, WhenBuilder<TCurrentJson>> & {\n <\n TTrueSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined,\n TFalseSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined,\n >(\n branches: Readonly<{\n true?: TTrueSteps extends ReadonlyArray<AnyRunnableNodeConfig> ? BranchStepsArg<TCurrentJson, TTrueSteps> : never;\n false?: TFalseSteps extends ReadonlyArray<AnyRunnableNodeConfig>\n ? BranchStepsArg<TCurrentJson, TFalseSteps>\n : never;\n }> &\n BranchOutputGuard<TCurrentJson, TTrueSteps, TFalseSteps>,\n ): ChainCursor<StepSequenceOutput<TCurrentJson, TTrueSteps>>;\n};\n\nexport class ChainCursor<TCurrentJson> {\n constructor(\n private readonly wf: WorkflowBuilder,\n private readonly endpoints: ReadonlyArray<ChainCursorEndpoint>,\n ) {}\n\n then<TOutputJson, TConfig extends RunnableNodeConfig<TCurrentJson, TOutputJson>>(\n config: TConfig,\n ): ChainCursor<RunnableNodeOutputJson<TConfig>> {\n const next = (this.wf as any).add(config) as NodeRef;\n const inputPortHint = this.resolveSharedInputPortHint();\n for (const e of this.endpoints) {\n (this.wf as any).connect(e.node, next, e.output);\n }\n return new ChainCursor<RunnableNodeOutputJson<TConfig>>(this.wf, [\n { node: next, output: \"main\", ...(inputPortHint ? { inputPortHint } : {}) },\n ]);\n }\n\n thenIntoInputHints<TOutputJson, TConfig extends RunnableNodeConfig<any, TOutputJson>>(\n config: TConfig,\n ): ChainCursor<RunnableNodeOutputJson<TConfig>> {\n const next = (this.wf as any).add(config) as NodeRef;\n for (const e of this.endpoints) {\n (this.wf as any).connect(e.node, next, e.output, e.inputPortHint ?? \"in\");\n }\n return new ChainCursor<RunnableNodeOutputJson<TConfig>>(this.wf, [{ node: next, output: \"main\" }]);\n }\n\n readonly when: ChainCursorWhenOverloads<TCurrentJson> = ((\n arg1:\n | boolean\n | Readonly<{ true?: ReadonlyArray<AnyRunnableNodeConfig>; false?: ReadonlyArray<AnyRunnableNodeConfig> }>,\n steps?: ReadonlyArray<AnyRunnableNodeConfig> | AnyRunnableNodeConfig,\n ...more: AnyRunnableNodeConfig[]\n ): WhenBuilder<TCurrentJson> | ChainCursor<TCurrentJson> => {\n if (this.endpoints.length !== 1) {\n throw new Error(\"ChainCursor.when(...) is only supported from a single cursor endpoint\");\n }\n const cursor = this.endpoints[0]!.node;\n\n if (typeof arg1 === \"boolean\") {\n const list = Array.isArray(steps) ? steps : steps ? [steps, ...more] : more;\n const port: OutputPortKey = arg1 ? \"true\" : \"false\";\n const b = new WhenBuilder<TCurrentJson>(this.wf, cursor, port);\n b.addBranch(list);\n return b;\n }\n\n const branches = arg1;\n const wfAny = this.wf as any;\n\n const buildBranch = (\n port: OutputPortKey,\n branchSteps: ReadonlyArray<AnyRunnableNodeConfig> | undefined,\n ): Readonly<{ end: NodeRef; endOutput: OutputPortKey; inputPortHint: InputPortKey }> => {\n const list = branchSteps ?? [];\n let prev: NodeRef | null = null;\n for (const cfg of list) {\n const ref = wfAny.add(cfg) as NodeRef;\n if (!prev) wfAny.connect(cursor, ref, port, \"in\");\n else wfAny.connect(prev, ref, \"main\", \"in\");\n prev = ref;\n }\n if (!prev) return { end: cursor, endOutput: port, inputPortHint: port };\n return { end: prev, endOutput: \"main\", inputPortHint: port };\n };\n\n const t = buildBranch(\"true\", branches.true);\n const f = buildBranch(\"false\", branches.false);\n return new ChainCursor<TCurrentJson>(this.wf, [\n { node: t.end, output: t.endOutput, inputPortHint: t.inputPortHint },\n { node: f.end, output: f.endOutput, inputPortHint: f.inputPortHint },\n ]);\n }) as ChainCursorWhenOverloads<TCurrentJson>;\n\n route<TNextJson>(\n branches: Readonly<\n Record<OutputPortKey, (branch: ChainCursor<TCurrentJson>) => ChainCursor<TNextJson> | undefined>\n >,\n ): ChainCursor<TNextJson> {\n if (this.endpoints.length !== 1) {\n throw new Error(\"ChainCursor.route(...) is only supported from a single cursor endpoint\");\n }\n const cursor = this.endpoints[0]!;\n const nextEndpoints: ChainCursorEndpoint[] = [];\n for (const [port, branchFactory] of Object.entries(branches)) {\n if (!branchFactory) {\n continue;\n }\n const branch = new ChainCursor<TCurrentJson>(this.wf, [{ node: cursor.node, output: port, inputPortHint: port }]);\n const builtBranch = branchFactory(branch);\n if (!builtBranch) {\n continue;\n }\n nextEndpoints.push(...builtBranch.endpoints);\n }\n return new ChainCursor<TNextJson>(this.wf, nextEndpoints);\n }\n\n build(): WorkflowDefinition {\n return this.wf.build();\n }\n\n private resolveSharedInputPortHint(): InputPortKey | undefined {\n const first = this.endpoints[0]?.inputPortHint;\n if (!first) {\n return undefined;\n }\n return this.endpoints.every((endpoint) => endpoint.inputPortHint === first) ? first : undefined;\n }\n}\n","import type {\n InputPortKey,\n NodeConfigBase,\n NodeDefinition,\n NodeRef,\n OutputPortKey,\n RunnableNodeOutputJson,\n TriggerNodeOutputJson,\n WorkflowDefinition,\n WorkflowId,\n} from \"../../types\";\n\nimport { ChainCursor } from \"./ChainCursorResolver\";\nimport type { AnyRunnableNodeConfig, AnyTriggerNodeConfig } from \"./workflowBuilderTypes\";\n\nexport class WorkflowBuilder {\n private readonly nodes: NodeDefinition[] = [];\n private readonly edges: WorkflowDefinition[\"edges\"] = [];\n private seq = 0;\n\n constructor(\n private readonly meta: { id: WorkflowId; name: string },\n private readonly options?: Readonly<Record<string, never>>,\n ) {}\n\n private add(config: NodeConfigBase): NodeRef {\n const tokenName = typeof config.type === \"function\" ? config.type.name : String(config.type);\n const id = config.id ?? `${tokenName}:${++this.seq}`;\n this.nodes.push({ id, kind: config.kind, type: config.type, name: config.name, config });\n return { id, kind: config.kind, name: config.name };\n }\n\n private connect(from: NodeRef, to: NodeRef, fromOutput: OutputPortKey = \"main\", toInput: InputPortKey = \"in\"): void {\n this.edges.push({ from: { nodeId: from.id, output: fromOutput }, to: { nodeId: to.id, input: toInput } });\n }\n\n trigger<TConfig extends AnyTriggerNodeConfig>(config: TConfig): ChainCursor<TriggerNodeOutputJson<TConfig>> {\n const ref = this.add(config);\n return new ChainCursor<TriggerNodeOutputJson<TConfig>>(this, [{ node: ref, output: \"main\" }]);\n }\n\n start<TConfig extends AnyRunnableNodeConfig>(config: TConfig): ChainCursor<RunnableNodeOutputJson<TConfig>> {\n const ref = this.add(config);\n return new ChainCursor<RunnableNodeOutputJson<TConfig>>(this, [{ node: ref, output: \"main\" }]);\n }\n\n build(): WorkflowDefinition {\n return { ...this.meta, nodes: this.nodes, edges: this.edges };\n }\n}\n\nexport { ChainCursor } from \"./ChainCursorResolver\";\nexport { WhenBuilder } from \"./WhenBuilder\";\n","import type { RunEventSubscription } from \"./runEvents\";\n\nexport class InMemoryRunEventSubscription implements RunEventSubscription {\n constructor(private readonly onClose: () => void) {}\n\n async close(): Promise<void> {\n this.onClose();\n }\n}\n","import type { WorkflowId } from \"../types\";\n\nimport type { RunEvent, RunEventBus, RunEventSubscription } from \"./runEvents\";\n\nimport { InMemoryRunEventSubscription } from \"./InMemoryRunEventSubscription\";\n\nexport class InMemoryRunEventBus implements RunEventBus {\n private readonly globalListeners = new Set<(event: RunEvent) => void>();\n private readonly listenersByWorkflowId = new Map<WorkflowId, Set<(event: RunEvent) => void>>();\n\n async publish(event: RunEvent): Promise<void> {\n for (const listener of this.globalListeners) listener(event);\n for (const listener of this.listenersByWorkflowId.get(event.workflowId) ?? []) listener(event);\n }\n\n async subscribe(onEvent: (event: RunEvent) => void): Promise<RunEventSubscription> {\n this.globalListeners.add(onEvent);\n return new InMemoryRunEventSubscription(() => {\n this.globalListeners.delete(onEvent);\n });\n }\n\n async subscribeToWorkflow(workflowId: WorkflowId, onEvent: (event: RunEvent) => void): Promise<RunEventSubscription> {\n const existing = this.listenersByWorkflowId.get(workflowId) ?? new Set<(event: RunEvent) => void>();\n existing.add(onEvent);\n this.listenersByWorkflowId.set(workflowId, existing);\n\n return new InMemoryRunEventSubscription(() => {\n const listeners = this.listenersByWorkflowId.get(workflowId);\n if (!listeners) return;\n listeners.delete(onEvent);\n if (listeners.size === 0) this.listenersByWorkflowId.delete(workflowId);\n });\n }\n}\n\nexport { InMemoryRunEventSubscription } from \"./InMemoryRunEventSubscription\";\n"],"mappings":";;AAKA,IAAa,cAAb,MAAa,Y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AE,UAAS,MAAM;;CAGhG,MAAM,UAAU,SAAmE;AACjF,OAAK,gBAAgB,IAAI,QAAQ;AACjC,SAAO,IAAI,mCAAmC;AAC5C,QAAK,gBAAgB,OAAO,QAAQ;IACpC;;CAGJ,MAAM,oBAAoB,YAAwB,SAAmE;EACnH,MAAM,WAAW,KAAK,sBAAsB,IAAI,WAAW,oBAAI,IAAI,KAAgC;AACnG,WAAS,IAAI,QAAQ;AACrB,OAAK,sBAAsB,IAAI,YAAY,SAAS;AAEpD,SAAO,IAAI,mCAAmC;GAC5C,MAAM,YAAY,KAAK,sBAAsB,IAAI,WAAW;AAC5D,OAAI,CAAC,UAAW;AAChB,aAAU,OAAO,QAAQ;AACzB,OAAI,UAAU,SAAS,EAAG,MAAK,sBAAsB,OAAO,WAAW;IACvE"}
@@ -234,14 +234,5 @@ var InMemoryRunEventBus = class {
234
234
  };
235
235
 
236
236
  //#endregion
237
- //#region src/contracts/workflowActivationPolicy.ts
238
- /** Default for tests and harnesses: every workflow is treated as active (legacy behavior). */
239
- var AllWorkflowsActiveWorkflowActivationPolicy = class {
240
- isActive(_workflowId) {
241
- return true;
242
- }
243
- };
244
-
245
- //#endregion
246
- export { WhenBuilder as a, ChainCursor as i, InMemoryRunEventBus as n, WorkflowBuilder as r, AllWorkflowsActiveWorkflowActivationPolicy as t };
247
- //# sourceMappingURL=workflowActivationPolicy-Td9HTOuD.js.map
237
+ export { WhenBuilder as i, WorkflowBuilder as n, ChainCursor as r, InMemoryRunEventBus as t };
238
+ //# sourceMappingURL=InMemoryRunEventBusRegistry-C2U83Hmv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryRunEventBusRegistry-C2U83Hmv.js","names":["wf: WorkflowBuilder","from: NodeRef","branchPort: OutputPortKey","created: NodeRef[]","prev: NodeRef | null","port: OutputPortKey","wf: WorkflowBuilder","endpoints: ReadonlyArray<ChainCursorEndpoint>","port: OutputPortKey","prev: NodeRef | null","nextEndpoints: ChainCursorEndpoint[]","meta: { id: WorkflowId; name: string }","options?: Readonly<Record<string, never>>","onClose: () => void"],"sources":["../src/workflow/dsl/WhenBuilder.ts","../src/workflow/dsl/ChainCursorResolver.ts","../src/workflow/dsl/WorkflowBuilder.ts","../src/events/InMemoryRunEventSubscription.ts","../src/events/InMemoryRunEventBusRegistry.ts"],"sourcesContent":["import type { NodeId, NodeRef, OutputPortKey, UpstreamRefPlaceholder, WorkflowDefinition } from \"../../types\";\n\nimport { WorkflowBuilder } from \"./WorkflowBuilder\";\nimport type { AnyRunnableNodeConfig, BooleanWhenOverloads, ValidStepSequence } from \"./workflowBuilderTypes\";\n\nexport class WhenBuilder<TCurrentJson> {\n constructor(\n private readonly wf: WorkflowBuilder,\n private readonly from: NodeRef,\n private readonly branchPort: OutputPortKey,\n ) {}\n\n addBranch<TSteps extends ReadonlyArray<AnyRunnableNodeConfig>>(\n steps: TSteps & ValidStepSequence<TCurrentJson, TSteps>,\n ): this {\n const created: NodeRef[] = [];\n\n let prev: NodeRef | null = null;\n for (const cfg of steps) {\n const ref = (this.wf as any).add(cfg) as NodeRef;\n created.push(ref);\n if (!prev) (this.wf as any).connect(this.from, ref, this.branchPort, \"in\");\n else (this.wf as any).connect(prev, ref, \"main\", \"in\");\n prev = ref;\n }\n\n for (const cfg of steps) {\n const maybe = cfg as unknown as { upstreamRefs?: Array<{ nodeId: NodeId } | UpstreamRefPlaceholder> };\n if (!Array.isArray(maybe.upstreamRefs) || maybe.upstreamRefs.length === 0) continue;\n\n maybe.upstreamRefs = maybe.upstreamRefs.map((r) => {\n if (typeof r !== \"string\") return r;\n const idx = parseInt(r.slice(1), 10);\n const nodeId = created[idx]?.id;\n return nodeId ? { nodeId } : { nodeId: r };\n });\n }\n\n return this;\n }\n\n readonly when: BooleanWhenOverloads<TCurrentJson, WhenBuilder<TCurrentJson>> = (\n branch: boolean,\n steps: ReadonlyArray<AnyRunnableNodeConfig> | AnyRunnableNodeConfig,\n ...more: AnyRunnableNodeConfig[]\n ): WhenBuilder<TCurrentJson> => {\n const list = Array.isArray(steps) ? steps : [steps, ...more];\n const port: OutputPortKey = branch ? \"true\" : \"false\";\n const b = new WhenBuilder<TCurrentJson>(this.wf, this.from, port);\n b.addBranch(list);\n return b;\n };\n\n build(): WorkflowDefinition {\n return this.wf.build();\n }\n}\n","import type {\n InputPortKey,\n NodeRef,\n OutputPortKey,\n RunnableNodeConfig,\n RunnableNodeOutputJson,\n WorkflowDefinition,\n} from \"../../types\";\n\nimport { WorkflowBuilder } from \"./WorkflowBuilder\";\nimport { WhenBuilder } from \"./WhenBuilder\";\nimport type {\n AnyRunnableNodeConfig,\n BooleanWhenOverloads,\n BranchOutputGuard,\n BranchStepsArg,\n StepSequenceOutput,\n} from \"./workflowBuilderTypes\";\n\ntype ChainCursorEndpoint = Readonly<{ node: NodeRef; output: OutputPortKey; inputPortHint?: InputPortKey }>;\n\ntype ChainCursorWhenOverloads<TCurrentJson> = BooleanWhenOverloads<TCurrentJson, WhenBuilder<TCurrentJson>> & {\n <\n TTrueSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined,\n TFalseSteps extends ReadonlyArray<AnyRunnableNodeConfig> | undefined,\n >(\n branches: Readonly<{\n true?: TTrueSteps extends ReadonlyArray<AnyRunnableNodeConfig> ? BranchStepsArg<TCurrentJson, TTrueSteps> : never;\n false?: TFalseSteps extends ReadonlyArray<AnyRunnableNodeConfig>\n ? BranchStepsArg<TCurrentJson, TFalseSteps>\n : never;\n }> &\n BranchOutputGuard<TCurrentJson, TTrueSteps, TFalseSteps>,\n ): ChainCursor<StepSequenceOutput<TCurrentJson, TTrueSteps>>;\n};\n\nexport class ChainCursor<TCurrentJson> {\n constructor(\n private readonly wf: WorkflowBuilder,\n private readonly endpoints: ReadonlyArray<ChainCursorEndpoint>,\n ) {}\n\n then<TOutputJson, TConfig extends RunnableNodeConfig<TCurrentJson, TOutputJson>>(\n config: TConfig,\n ): ChainCursor<RunnableNodeOutputJson<TConfig>> {\n const next = (this.wf as any).add(config) as NodeRef;\n const inputPortHint = this.resolveSharedInputPortHint();\n for (const e of this.endpoints) {\n (this.wf as any).connect(e.node, next, e.output);\n }\n return new ChainCursor<RunnableNodeOutputJson<TConfig>>(this.wf, [\n { node: next, output: \"main\", ...(inputPortHint ? { inputPortHint } : {}) },\n ]);\n }\n\n thenIntoInputHints<TOutputJson, TConfig extends RunnableNodeConfig<any, TOutputJson>>(\n config: TConfig,\n ): ChainCursor<RunnableNodeOutputJson<TConfig>> {\n const next = (this.wf as any).add(config) as NodeRef;\n for (const e of this.endpoints) {\n (this.wf as any).connect(e.node, next, e.output, e.inputPortHint ?? \"in\");\n }\n return new ChainCursor<RunnableNodeOutputJson<TConfig>>(this.wf, [{ node: next, output: \"main\" }]);\n }\n\n readonly when: ChainCursorWhenOverloads<TCurrentJson> = ((\n arg1:\n | boolean\n | Readonly<{ true?: ReadonlyArray<AnyRunnableNodeConfig>; false?: ReadonlyArray<AnyRunnableNodeConfig> }>,\n steps?: ReadonlyArray<AnyRunnableNodeConfig> | AnyRunnableNodeConfig,\n ...more: AnyRunnableNodeConfig[]\n ): WhenBuilder<TCurrentJson> | ChainCursor<TCurrentJson> => {\n if (this.endpoints.length !== 1) {\n throw new Error(\"ChainCursor.when(...) is only supported from a single cursor endpoint\");\n }\n const cursor = this.endpoints[0]!.node;\n\n if (typeof arg1 === \"boolean\") {\n const list = Array.isArray(steps) ? steps : steps ? [steps, ...more] : more;\n const port: OutputPortKey = arg1 ? \"true\" : \"false\";\n const b = new WhenBuilder<TCurrentJson>(this.wf, cursor, port);\n b.addBranch(list);\n return b;\n }\n\n const branches = arg1;\n const wfAny = this.wf as any;\n\n const buildBranch = (\n port: OutputPortKey,\n branchSteps: ReadonlyArray<AnyRunnableNodeConfig> | undefined,\n ): Readonly<{ end: NodeRef; endOutput: OutputPortKey; inputPortHint: InputPortKey }> => {\n const list = branchSteps ?? [];\n let prev: NodeRef | null = null;\n for (const cfg of list) {\n const ref = wfAny.add(cfg) as NodeRef;\n if (!prev) wfAny.connect(cursor, ref, port, \"in\");\n else wfAny.connect(prev, ref, \"main\", \"in\");\n prev = ref;\n }\n if (!prev) return { end: cursor, endOutput: port, inputPortHint: port };\n return { end: prev, endOutput: \"main\", inputPortHint: port };\n };\n\n const t = buildBranch(\"true\", branches.true);\n const f = buildBranch(\"false\", branches.false);\n return new ChainCursor<TCurrentJson>(this.wf, [\n { node: t.end, output: t.endOutput, inputPortHint: t.inputPortHint },\n { node: f.end, output: f.endOutput, inputPortHint: f.inputPortHint },\n ]);\n }) as ChainCursorWhenOverloads<TCurrentJson>;\n\n route<TNextJson>(\n branches: Readonly<\n Record<OutputPortKey, (branch: ChainCursor<TCurrentJson>) => ChainCursor<TNextJson> | undefined>\n >,\n ): ChainCursor<TNextJson> {\n if (this.endpoints.length !== 1) {\n throw new Error(\"ChainCursor.route(...) is only supported from a single cursor endpoint\");\n }\n const cursor = this.endpoints[0]!;\n const nextEndpoints: ChainCursorEndpoint[] = [];\n for (const [port, branchFactory] of Object.entries(branches)) {\n if (!branchFactory) {\n continue;\n }\n const branch = new ChainCursor<TCurrentJson>(this.wf, [{ node: cursor.node, output: port, inputPortHint: port }]);\n const builtBranch = branchFactory(branch);\n if (!builtBranch) {\n continue;\n }\n nextEndpoints.push(...builtBranch.endpoints);\n }\n return new ChainCursor<TNextJson>(this.wf, nextEndpoints);\n }\n\n build(): WorkflowDefinition {\n return this.wf.build();\n }\n\n private resolveSharedInputPortHint(): InputPortKey | undefined {\n const first = this.endpoints[0]?.inputPortHint;\n if (!first) {\n return undefined;\n }\n return this.endpoints.every((endpoint) => endpoint.inputPortHint === first) ? first : undefined;\n }\n}\n","import type {\n InputPortKey,\n NodeConfigBase,\n NodeDefinition,\n NodeRef,\n OutputPortKey,\n RunnableNodeOutputJson,\n TriggerNodeOutputJson,\n WorkflowDefinition,\n WorkflowId,\n} from \"../../types\";\n\nimport { ChainCursor } from \"./ChainCursorResolver\";\nimport type { AnyRunnableNodeConfig, AnyTriggerNodeConfig } from \"./workflowBuilderTypes\";\n\nexport class WorkflowBuilder {\n private readonly nodes: NodeDefinition[] = [];\n private readonly edges: WorkflowDefinition[\"edges\"] = [];\n private seq = 0;\n\n constructor(\n private readonly meta: { id: WorkflowId; name: string },\n private readonly options?: Readonly<Record<string, never>>,\n ) {}\n\n private add(config: NodeConfigBase): NodeRef {\n const tokenName = typeof config.type === \"function\" ? config.type.name : String(config.type);\n const id = config.id ?? `${tokenName}:${++this.seq}`;\n this.nodes.push({ id, kind: config.kind, type: config.type, name: config.name, config });\n return { id, kind: config.kind, name: config.name };\n }\n\n private connect(from: NodeRef, to: NodeRef, fromOutput: OutputPortKey = \"main\", toInput: InputPortKey = \"in\"): void {\n this.edges.push({ from: { nodeId: from.id, output: fromOutput }, to: { nodeId: to.id, input: toInput } });\n }\n\n trigger<TConfig extends AnyTriggerNodeConfig>(config: TConfig): ChainCursor<TriggerNodeOutputJson<TConfig>> {\n const ref = this.add(config);\n return new ChainCursor<TriggerNodeOutputJson<TConfig>>(this, [{ node: ref, output: \"main\" }]);\n }\n\n start<TConfig extends AnyRunnableNodeConfig>(config: TConfig): ChainCursor<RunnableNodeOutputJson<TConfig>> {\n const ref = this.add(config);\n return new ChainCursor<RunnableNodeOutputJson<TConfig>>(this, [{ node: ref, output: \"main\" }]);\n }\n\n build(): WorkflowDefinition {\n return { ...this.meta, nodes: this.nodes, edges: this.edges };\n }\n}\n\nexport { ChainCursor } from \"./ChainCursorResolver\";\nexport { WhenBuilder } from \"./WhenBuilder\";\n","import type { RunEventSubscription } from \"./runEvents\";\n\nexport class InMemoryRunEventSubscription implements RunEventSubscription {\n constructor(private readonly onClose: () => void) {}\n\n async close(): Promise<void> {\n this.onClose();\n }\n}\n","import type { WorkflowId } from \"../types\";\n\nimport type { RunEvent, RunEventBus, RunEventSubscription } from \"./runEvents\";\n\nimport { InMemoryRunEventSubscription } from \"./InMemoryRunEventSubscription\";\n\nexport class InMemoryRunEventBus implements RunEventBus {\n private readonly globalListeners = new Set<(event: RunEvent) => void>();\n private readonly listenersByWorkflowId = new Map<WorkflowId, Set<(event: RunEvent) => void>>();\n\n async publish(event: RunEvent): Promise<void> {\n for (const listener of this.globalListeners) listener(event);\n for (const listener of this.listenersByWorkflowId.get(event.workflowId) ?? []) listener(event);\n }\n\n async subscribe(onEvent: (event: RunEvent) => void): Promise<RunEventSubscription> {\n this.globalListeners.add(onEvent);\n return new InMemoryRunEventSubscription(() => {\n this.globalListeners.delete(onEvent);\n });\n }\n\n async subscribeToWorkflow(workflowId: WorkflowId, onEvent: (event: RunEvent) => void): Promise<RunEventSubscription> {\n const existing = this.listenersByWorkflowId.get(workflowId) ?? new Set<(event: RunEvent) => void>();\n existing.add(onEvent);\n this.listenersByWorkflowId.set(workflowId, existing);\n\n return new InMemoryRunEventSubscription(() => {\n const listeners = this.listenersByWorkflowId.get(workflowId);\n if (!listeners) return;\n listeners.delete(onEvent);\n if (listeners.size === 0) this.listenersByWorkflowId.delete(workflowId);\n });\n }\n}\n\nexport { InMemoryRunEventSubscription } from \"./InMemoryRunEventSubscription\";\n"],"mappings":";AAKA,IAAa,cAAb,MAAa,YAA0B;CACrC,YACE,AAAiBA,IACjB,AAAiBC,MACjB,AAAiBC,YACjB;EAHiB;EACA;EACA;;CAGnB,UACE,OACM;EACN,MAAMC,UAAqB,EAAE;EAE7B,IAAIC,OAAuB;AAC3B,OAAK,MAAM,OAAO,OAAO;GACvB,MAAM,MAAO,KAAK,GAAW,IAAI,IAAI;AACrC,WAAQ,KAAK,IAAI;AACjB,OAAI,CAAC,KAAM,CAAC,KAAK,GAAW,QAAQ,KAAK,MAAM,KAAK,KAAK,YAAY,KAAK;OACrE,CAAC,KAAK,GAAW,QAAQ,MAAM,KAAK,QAAQ,KAAK;AACtD,UAAO;;AAGT,OAAK,MAAM,OAAO,OAAO;GACvB,MAAM,QAAQ;AACd,OAAI,CAAC,MAAM,QAAQ,MAAM,aAAa,IAAI,MAAM,aAAa,WAAW,EAAG;AAE3E,SAAM,eAAe,MAAM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