@makaio/framework 1.0.0-dev-1781517341920 → 1.0.0-dev-1781729807808

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 (132) hide show
  1. package/dist/.makaio-build.json +2 -2
  2. package/dist/adapter-Cxcqmp04.mjs +1 -0
  3. package/dist/adapters/stream-session/index.d.mts +2 -0
  4. package/dist/await-trigger-Cjfj0yp_.mjs +1 -0
  5. package/dist/bus/index.mjs +1 -1
  6. package/dist/{canonical-model-BE7t86yt.mjs → canonical-model-C-jhofjd.mjs} +1 -1
  7. package/dist/compression-BPOKUc6y.mjs +1 -0
  8. package/dist/contracts/adapter/index.d.mts +2 -2
  9. package/dist/contracts/adapter/index.mjs +1 -1
  10. package/dist/contracts/adapter/schemas/session-lineage.d.mts +1 -1
  11. package/dist/contracts/artifact/index.d.mts +1 -1
  12. package/dist/contracts/canonical-model/index.mjs +1 -1
  13. package/dist/contracts/client/index.d.mts +1 -1
  14. package/dist/contracts/config/index.d.mts +12 -12
  15. package/dist/contracts/extension/index.d.mts +2 -2
  16. package/dist/contracts/extension/index.mjs +1 -1
  17. package/dist/contracts/facet/index.d.mts +1 -1
  18. package/dist/contracts/harness/index.d.mts +1 -1
  19. package/dist/contracts/index.d.mts +261 -65
  20. package/dist/contracts/index.mjs +1 -1
  21. package/dist/contracts/materialization/index.d.mts +3 -3
  22. package/dist/contracts/provider/index.d.mts +3 -3
  23. package/dist/contracts/provider/index.mjs +1 -1
  24. package/dist/contracts/session/index.d.mts +3 -3
  25. package/dist/contracts/session/index.mjs +1 -1
  26. package/dist/contracts/variant/index.d.mts +1 -1
  27. package/dist/definition-BJ_975aA.mjs +1 -0
  28. package/dist/{definition-CPc6oKaF.d.mts → definition-CZcVOhXZ.d.mts} +1 -1
  29. package/dist/{definition-B2FH_eOh.d.mts → definition-GOb_oOmb.d.mts} +13 -2
  30. package/dist/drizzle/0020_m_mqf47r9j.sql +1 -0
  31. package/dist/drizzle/meta/_journal.json +7 -0
  32. package/dist/{extension-DNrcv3V7.mjs → extension-CkU_hqra.mjs} +1 -1
  33. package/dist/{handlers-Cpy9Q8ho.mjs → handlers-dnpT_hsm.mjs} +1 -1
  34. package/dist/{index-C7vAbtvS.d.mts → index-BFW1X6SW.d.mts} +85 -46
  35. package/dist/{index-fTBtQ5fK.d.mts → index-BuaP2Q0b.d.mts} +16 -16
  36. package/dist/{index-BBteExwv.d.mts → index-ByRAbcZd.d.mts} +4 -2
  37. package/dist/{index-GuspCNLR.d.mts → index-C2XLjebs.d.mts} +8 -8
  38. package/dist/{index-Dun5uQwE.d.mts → index-CUYDEQvN.d.mts} +24 -3
  39. package/dist/{index-I6pLxh17.d.mts → index-CkpGuNLe.d.mts} +15 -15
  40. package/dist/{index-DWqgo739.d.mts → index-Cy75lJ1O.d.mts} +34 -34
  41. package/dist/{index-WKF5BHsw.d.mts → index-DUI1W-zN.d.mts} +8 -8
  42. package/dist/{index-BDnI2oqX.d.mts → index-Dbd0Tgba.d.mts} +2 -2
  43. package/dist/{index-CsP4Ckem.d.mts → index-Dn73XrXA.d.mts} +8 -8
  44. package/dist/{index-dFTsZFlh.d.mts → index-Dpu4e9NK.d.mts} +1 -1
  45. package/dist/{index-B8v52gGb.d.mts → index-HiAth5G0.d.mts} +60 -60
  46. package/dist/{index-BoI86whU.d.mts → index-WWYQEH0q.d.mts} +18 -18
  47. package/dist/{index-DVz3a2jZ.d.mts → index-XcnFGiKL.d.mts} +4 -4
  48. package/dist/{index-BM_y78ZA2.d.mts → index-cN4DkU5Y2.d.mts} +9 -9
  49. package/dist/kernel/extension/index.d.mts +1 -1
  50. package/dist/kernel/index.d.mts +2 -2
  51. package/dist/kernel/observability/index.d.mts +1 -1
  52. package/dist/{lib-DkLlhp9Z.mjs → lib-B-R6VZW0.mjs} +2 -2
  53. package/dist/{lib-jOuIcSs9.mjs → lib-BwYODPdd.mjs} +1 -1
  54. package/dist/mcp-http-server/index.mjs +1 -1
  55. package/dist/{namespace-CEqkI6Zu.d.mts → namespace-B091meTj.d.mts} +6 -6
  56. package/dist/{namespace-CN2TfSCY.d.mts → namespace-Ba1gUpUu.d.mts} +4 -4
  57. package/dist/{namespace-BAJTZXWc.d.mts → namespace-CO3DK1v_.d.mts} +60 -23
  58. package/dist/{namespace-H9A39Mx8.d.mts → namespace-CZgcOQTh.d.mts} +56 -56
  59. package/dist/{namespace-Cj7k5UH7.d.mts → namespace-Daq_-170.d.mts} +7 -7
  60. package/dist/package-DP8lk0-a.mjs +1 -0
  61. package/dist/package.json +1 -1
  62. package/dist/primitive-runtime-Dw6OC8w5.mjs +1 -0
  63. package/dist/{providers-namespace-C0C-Sb4N.d.mts → providers-namespace-B4INLPUc.d.mts} +7 -7
  64. package/dist/{registry-udUhXSIC.mjs → registry-CwjZvH2s.mjs} +2 -1
  65. package/dist/runtime-node/index.d.mts +1 -1
  66. package/dist/runtime-node/index.mjs +1 -1
  67. package/dist/runtime-node/workflow-worker/index.d.mts +1 -1
  68. package/dist/runtime-node/workflow-worker/index.mjs +1 -1
  69. package/dist/runtime-node/workflow-worker/worker-entry.mjs +1 -1
  70. package/dist/{schema-msWs4YhT.d.mts → schema-DcZifH6p.d.mts} +27 -1
  71. package/dist/{schemas-DMl7IKG-.d.mts → schemas-BbFAwUpf.d.mts} +5 -5
  72. package/dist/{schemas-Cae5dubB.d.mts → schemas-BqscWIoC.d.mts} +6 -6
  73. package/dist/{schemas-DuQ9EcLu2.d.mts → schemas-CTIaU6Rt2.d.mts} +12 -12
  74. package/dist/{schemas-CN9hprME.d.mts → schemas-IDGAJ_zv.d.mts} +6 -6
  75. package/dist/schemas-dNCdjOLB.mjs +1 -0
  76. package/dist/services/adapter-subsystem/index.d.mts +2 -2
  77. package/dist/services/adapter-subsystem/namespace.d.mts +1 -1
  78. package/dist/services/context-rules/index.d.mts +3 -3
  79. package/dist/services/execution-target/index.d.mts +2 -2
  80. package/dist/services/execution-target/namespace.d.mts +1 -1
  81. package/dist/services/execution-target/schemas.d.mts +1 -1
  82. package/dist/services/filesystem/namespace.d.mts +6 -6
  83. package/dist/services/filesystem/schemas.d.mts +3 -3
  84. package/dist/services/harness/index.d.mts +3 -3
  85. package/dist/services/index.d.mts +57 -57
  86. package/dist/services/index.mjs +1 -1
  87. package/dist/services/session/handlers/index.mjs +1 -1
  88. package/dist/services/session/index.d.mts +4 -4
  89. package/dist/services/session/index.mjs +1 -1
  90. package/dist/services/session/messages/namespace.d.mts +1 -1
  91. package/dist/services/session/storage/namespace.d.mts +1 -1
  92. package/dist/services/session/storage/schema.d.mts +1 -1
  93. package/dist/services/session/storage/schema.mjs +1 -1
  94. package/dist/services/session/testing/index.mjs +2 -1
  95. package/dist/services/settings/index.d.mts +1 -1
  96. package/dist/services/settings/namespace.d.mts +12 -12
  97. package/dist/services/settings/storage/extension-configs/namespace.d.mts +3 -3
  98. package/dist/services/settings/storage/index.d.mts +1 -1
  99. package/dist/services/settings/storage/providers-namespace.d.mts +1 -1
  100. package/dist/services/settings/storage/providers-namespace.mjs +1 -1
  101. package/dist/services/subagent-template/index.d.mts +1 -1
  102. package/dist/services/subagent-template/schemas.d.mts +1 -1
  103. package/dist/services/tool-approval/index.mjs +1 -1
  104. package/dist/services/tools/index.mjs +1 -1
  105. package/dist/services/tray-menu/index.d.mts +2 -2
  106. package/dist/services/tray-menu/namespace.d.mts +1 -1
  107. package/dist/services/tray-menu/schemas.d.mts +1 -1
  108. package/dist/session-DApMcL_0.mjs +1 -0
  109. package/dist/session-R-wciAdJ.mjs +39 -0
  110. package/dist/{session-lineage-DFkJgYt5.d.mts → session-lineage-D_8W1MI0.d.mts} +1 -1
  111. package/dist/storage/drizzle/client.mjs +1 -1
  112. package/dist/storage/drizzle/index.mjs +1 -1
  113. package/dist/{tool-approval-service-B_28RhuK.mjs → tool-approval-service-DhAqQqev.mjs} +1 -1
  114. package/dist/tools/index.d.mts +8 -0
  115. package/dist/tools-DeZIVtxe.mjs +1 -0
  116. package/dist/{types-DUNA749O.d.mts → types-CCsvoUTA.d.mts} +33 -15
  117. package/dist/workflow-engine/index.d.mts +49 -25
  118. package/dist/workflow-engine/index.mjs +1 -1
  119. package/dist/workflow-engine/package.mjs +1 -1
  120. package/dist/workflow-engine/workflow-orchestrator.mjs +1 -1
  121. package/dist/{workflow-worker-CjuRYLmJ.mjs → workflow-worker-DMFhz1q_.mjs} +1 -1
  122. package/package.json +1 -1
  123. package/dist/adapter-ux2xaQ6H.mjs +0 -1
  124. package/dist/await-trigger-uKEHY8E4.mjs +0 -1
  125. package/dist/compression-Cy9DIqyr.mjs +0 -1
  126. package/dist/definition-Bija4lGr.mjs +0 -1
  127. package/dist/package-lxB0vpby.mjs +0 -1
  128. package/dist/primitive-runtime-BSg8J7VX.mjs +0 -1
  129. package/dist/schemas-Dvm_0GDr.mjs +0 -1
  130. package/dist/session-Is5VSP2V.mjs +0 -1
  131. package/dist/session-ZAJrcudH.mjs +0 -39
  132. package/dist/tools-BpzJterj.mjs +0 -1
@@ -70,9 +70,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
70
70
  name: _$zod.ZodString;
71
71
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
72
72
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
73
- enabled: "enabled";
74
- disabled: "disabled";
75
73
  visible: "visible";
74
+ disabled: "disabled";
75
+ enabled: "enabled";
76
76
  }>>>;
77
77
  modelFilterMode: _$zod.ZodEnum<{
78
78
  allowlist: "allowlist";
@@ -97,9 +97,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
97
97
  name: _$zod.ZodString;
98
98
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
99
99
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
100
- enabled: "enabled";
101
- disabled: "disabled";
102
100
  visible: "visible";
101
+ disabled: "disabled";
102
+ enabled: "enabled";
103
103
  }>>>;
104
104
  modelFilterMode: _$zod.ZodEnum<{
105
105
  allowlist: "allowlist";
@@ -124,9 +124,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
124
124
  name: _$zod.ZodString;
125
125
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
126
126
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
127
- enabled: "enabled";
128
- disabled: "disabled";
129
127
  visible: "visible";
128
+ disabled: "disabled";
129
+ enabled: "enabled";
130
130
  }>>>;
131
131
  modelFilterMode: _$zod.ZodEnum<{
132
132
  allowlist: "allowlist";
@@ -188,9 +188,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
188
188
  name: _$zod.ZodString;
189
189
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
190
190
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
191
- enabled: "enabled";
192
- disabled: "disabled";
193
191
  visible: "visible";
192
+ disabled: "disabled";
193
+ enabled: "enabled";
194
194
  }>>>;
195
195
  modelFilterMode: _$zod.ZodEnum<{
196
196
  allowlist: "allowlist";
@@ -219,7 +219,7 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
219
219
  credentialRefs: _$zod.ZodRecord<_$zod.ZodString, _$zod_v4_core0.$ZodBranded<_$zod.ZodString, "CredentialRef", "out">>;
220
220
  credentialEnvVars: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
221
221
  ambientCredentialEnvVars: _$zod.ZodOptional<_$zod.ZodArray<_$zod.ZodString>>;
222
- capabilities: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodUnknown>>;
222
+ capabilities: _$zod.ZodOptional<_$zod.ZodType<Record<string, unknown>, Record<string, unknown>, _$zod_v4_core0.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>>;
223
223
  }, _$zod_v4_core0.$strip>>;
224
224
  }, _$zod_v4_core0.$strict>;
225
225
  };
@@ -323,7 +323,7 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
323
323
  "show-all": "show-all";
324
324
  }>>;
325
325
  credentialEnvVars: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
326
- capabilities: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodUnknown>>;
326
+ capabilities: _$zod.ZodOptional<_$zod.ZodType<Record<string, unknown>, Record<string, unknown>, _$zod_v4_core0.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>>;
327
327
  }, _$zod_v4_core0.$strip>>;
328
328
  }, _$zod_v4_core0.$strict>;
329
329
  };
@@ -337,9 +337,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
337
337
  openai: _$zod.ZodOptional<_$zod.ZodString>;
338
338
  }, _$zod_v4_core0.$strip>>;
339
339
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
340
- enabled: "enabled";
341
- disabled: "disabled";
342
340
  visible: "visible";
341
+ disabled: "disabled";
342
+ enabled: "enabled";
343
343
  }>>>;
344
344
  modelFilterMode: _$zod.ZodOptional<_$zod.ZodEnum<{
345
345
  allowlist: "allowlist";
@@ -354,9 +354,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
354
354
  name: _$zod.ZodString;
355
355
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
356
356
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
357
- enabled: "enabled";
358
- disabled: "disabled";
359
357
  visible: "visible";
358
+ disabled: "disabled";
359
+ enabled: "enabled";
360
360
  }>>>;
361
361
  modelFilterMode: _$zod.ZodEnum<{
362
362
  allowlist: "allowlist";
@@ -380,9 +380,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
380
380
  openai: _$zod.ZodOptional<_$zod.ZodString>;
381
381
  }, _$zod_v4_core0.$strip>>>;
382
382
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
383
- enabled: "enabled";
384
- disabled: "disabled";
385
383
  visible: "visible";
384
+ disabled: "disabled";
385
+ enabled: "enabled";
386
386
  }>>>;
387
387
  enabled: _$zod.ZodOptional<_$zod.ZodBoolean>;
388
388
  }, _$zod_v4_core0.$strict>;
@@ -394,9 +394,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
394
394
  name: _$zod.ZodString;
395
395
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
396
396
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
397
- enabled: "enabled";
398
- disabled: "disabled";
399
397
  visible: "visible";
398
+ disabled: "disabled";
399
+ enabled: "enabled";
400
400
  }>>>;
401
401
  modelFilterMode: _$zod.ZodEnum<{
402
402
  allowlist: "allowlist";
@@ -422,9 +422,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
422
422
  name: _$zod.ZodString;
423
423
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
424
424
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
425
- enabled: "enabled";
426
- disabled: "disabled";
427
425
  visible: "visible";
426
+ disabled: "disabled";
427
+ enabled: "enabled";
428
428
  }>>>;
429
429
  modelFilterMode: _$zod.ZodEnum<{
430
430
  allowlist: "allowlist";
@@ -457,9 +457,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
457
457
  name: _$zod.ZodString;
458
458
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
459
459
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
460
- enabled: "enabled";
461
- disabled: "disabled";
462
460
  visible: "visible";
461
+ disabled: "disabled";
462
+ enabled: "enabled";
463
463
  }>>>;
464
464
  modelFilterMode: _$zod.ZodEnum<{
465
465
  allowlist: "allowlist";
@@ -489,9 +489,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
489
489
  name: _$zod.ZodString;
490
490
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
491
491
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
492
- enabled: "enabled";
493
- disabled: "disabled";
494
492
  visible: "visible";
493
+ disabled: "disabled";
494
+ enabled: "enabled";
495
495
  }>>>;
496
496
  modelFilterMode: _$zod.ZodEnum<{
497
497
  allowlist: "allowlist";
@@ -594,9 +594,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
594
594
  name: _$zod.ZodString;
595
595
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
596
596
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
597
- enabled: "enabled";
598
- disabled: "disabled";
599
597
  visible: "visible";
598
+ disabled: "disabled";
599
+ enabled: "enabled";
600
600
  }>>>;
601
601
  modelFilterMode: _$zod.ZodEnum<{
602
602
  allowlist: "allowlist";
@@ -614,9 +614,9 @@ declare const AdapterSubsystemNamespace: _$_makaio_core0.BusNamespaceDefinition<
614
614
  name: _$zod.ZodString;
615
615
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
616
616
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
617
- enabled: "enabled";
618
- disabled: "disabled";
619
617
  visible: "visible";
618
+ disabled: "disabled";
619
+ enabled: "enabled";
620
620
  }>>>;
621
621
  modelFilterMode: _$zod.ZodEnum<{
622
622
  allowlist: "allowlist";
@@ -725,9 +725,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
725
725
  name: _$zod.ZodString;
726
726
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
727
727
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
728
- enabled: "enabled";
729
- disabled: "disabled";
730
728
  visible: "visible";
729
+ disabled: "disabled";
730
+ enabled: "enabled";
731
731
  }>>>;
732
732
  modelFilterMode: _$zod.ZodEnum<{
733
733
  allowlist: "allowlist";
@@ -752,9 +752,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
752
752
  name: _$zod.ZodString;
753
753
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
754
754
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
755
- enabled: "enabled";
756
- disabled: "disabled";
757
755
  visible: "visible";
756
+ disabled: "disabled";
757
+ enabled: "enabled";
758
758
  }>>>;
759
759
  modelFilterMode: _$zod.ZodEnum<{
760
760
  allowlist: "allowlist";
@@ -779,9 +779,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
779
779
  name: _$zod.ZodString;
780
780
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
781
781
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
782
- enabled: "enabled";
783
- disabled: "disabled";
784
782
  visible: "visible";
783
+ disabled: "disabled";
784
+ enabled: "enabled";
785
785
  }>>>;
786
786
  modelFilterMode: _$zod.ZodEnum<{
787
787
  allowlist: "allowlist";
@@ -843,9 +843,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
843
843
  name: _$zod.ZodString;
844
844
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
845
845
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
846
- enabled: "enabled";
847
- disabled: "disabled";
848
846
  visible: "visible";
847
+ disabled: "disabled";
848
+ enabled: "enabled";
849
849
  }>>>;
850
850
  modelFilterMode: _$zod.ZodEnum<{
851
851
  allowlist: "allowlist";
@@ -874,7 +874,7 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
874
874
  credentialRefs: _$zod.ZodRecord<_$zod.ZodString, _$zod_v4_core0.$ZodBranded<_$zod.ZodString, "CredentialRef", "out">>;
875
875
  credentialEnvVars: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
876
876
  ambientCredentialEnvVars: _$zod.ZodOptional<_$zod.ZodArray<_$zod.ZodString>>;
877
- capabilities: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodUnknown>>;
877
+ capabilities: _$zod.ZodOptional<_$zod.ZodType<Record<string, unknown>, Record<string, unknown>, _$zod_v4_core0.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>>;
878
878
  }, _$zod_v4_core0.$strip>>;
879
879
  }, _$zod_v4_core0.$strict>;
880
880
  };
@@ -978,7 +978,7 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
978
978
  "show-all": "show-all";
979
979
  }>>;
980
980
  credentialEnvVars: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
981
- capabilities: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodUnknown>>;
981
+ capabilities: _$zod.ZodOptional<_$zod.ZodType<Record<string, unknown>, Record<string, unknown>, _$zod_v4_core0.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>>;
982
982
  }, _$zod_v4_core0.$strip>>;
983
983
  }, _$zod_v4_core0.$strict>;
984
984
  };
@@ -992,9 +992,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
992
992
  openai: _$zod.ZodOptional<_$zod.ZodString>;
993
993
  }, _$zod_v4_core0.$strip>>;
994
994
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
995
- enabled: "enabled";
996
- disabled: "disabled";
997
995
  visible: "visible";
996
+ disabled: "disabled";
997
+ enabled: "enabled";
998
998
  }>>>;
999
999
  modelFilterMode: _$zod.ZodOptional<_$zod.ZodEnum<{
1000
1000
  allowlist: "allowlist";
@@ -1009,9 +1009,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
1009
1009
  name: _$zod.ZodString;
1010
1010
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
1011
1011
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
1012
- enabled: "enabled";
1013
- disabled: "disabled";
1014
1012
  visible: "visible";
1013
+ disabled: "disabled";
1014
+ enabled: "enabled";
1015
1015
  }>>>;
1016
1016
  modelFilterMode: _$zod.ZodEnum<{
1017
1017
  allowlist: "allowlist";
@@ -1035,9 +1035,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
1035
1035
  openai: _$zod.ZodOptional<_$zod.ZodString>;
1036
1036
  }, _$zod_v4_core0.$strip>>>;
1037
1037
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
1038
- enabled: "enabled";
1039
- disabled: "disabled";
1040
1038
  visible: "visible";
1039
+ disabled: "disabled";
1040
+ enabled: "enabled";
1041
1041
  }>>>;
1042
1042
  enabled: _$zod.ZodOptional<_$zod.ZodBoolean>;
1043
1043
  }, _$zod_v4_core0.$strict>;
@@ -1049,9 +1049,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
1049
1049
  name: _$zod.ZodString;
1050
1050
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
1051
1051
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
1052
- enabled: "enabled";
1053
- disabled: "disabled";
1054
1052
  visible: "visible";
1053
+ disabled: "disabled";
1054
+ enabled: "enabled";
1055
1055
  }>>>;
1056
1056
  modelFilterMode: _$zod.ZodEnum<{
1057
1057
  allowlist: "allowlist";
@@ -1077,9 +1077,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
1077
1077
  name: _$zod.ZodString;
1078
1078
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
1079
1079
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
1080
- enabled: "enabled";
1081
- disabled: "disabled";
1082
1080
  visible: "visible";
1081
+ disabled: "disabled";
1082
+ enabled: "enabled";
1083
1083
  }>>>;
1084
1084
  modelFilterMode: _$zod.ZodEnum<{
1085
1085
  allowlist: "allowlist";
@@ -1112,9 +1112,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
1112
1112
  name: _$zod.ZodString;
1113
1113
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
1114
1114
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
1115
- enabled: "enabled";
1116
- disabled: "disabled";
1117
1115
  visible: "visible";
1116
+ disabled: "disabled";
1117
+ enabled: "enabled";
1118
1118
  }>>>;
1119
1119
  modelFilterMode: _$zod.ZodEnum<{
1120
1120
  allowlist: "allowlist";
@@ -1144,9 +1144,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
1144
1144
  name: _$zod.ZodString;
1145
1145
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
1146
1146
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
1147
- enabled: "enabled";
1148
- disabled: "disabled";
1149
1147
  visible: "visible";
1148
+ disabled: "disabled";
1149
+ enabled: "enabled";
1150
1150
  }>>>;
1151
1151
  modelFilterMode: _$zod.ZodEnum<{
1152
1152
  allowlist: "allowlist";
@@ -1249,9 +1249,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
1249
1249
  name: _$zod.ZodString;
1250
1250
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
1251
1251
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
1252
- enabled: "enabled";
1253
- disabled: "disabled";
1254
1252
  visible: "visible";
1253
+ disabled: "disabled";
1254
+ enabled: "enabled";
1255
1255
  }>>>;
1256
1256
  modelFilterMode: _$zod.ZodEnum<{
1257
1257
  allowlist: "allowlist";
@@ -1269,9 +1269,9 @@ declare const AdapterSubsystemSubjects: _$_makaio_core0.BusSubjects<_$_makaio_co
1269
1269
  name: _$zod.ZodString;
1270
1270
  endpointOverrides: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodString>>;
1271
1271
  modelVisibility: _$zod.ZodOptional<_$zod.ZodRecord<_$zod.ZodString, _$zod.ZodEnum<{
1272
- enabled: "enabled";
1273
- disabled: "disabled";
1274
1272
  visible: "visible";
1273
+ disabled: "disabled";
1274
+ enabled: "enabled";
1275
1275
  }>>>;
1276
1276
  modelFilterMode: _$zod.ZodEnum<{
1277
1277
  allowlist: "allowlist";
@@ -334,10 +334,10 @@ declare const MessageStorageNamespace$1: {
334
334
  output: _$zod.ZodString;
335
335
  isError: _$zod.ZodOptional<_$zod.ZodBoolean>;
336
336
  }, _$zod_v4_core0.$strip>], "type">>;
337
- timestamp: _$zod.ZodNumber;
338
337
  agentId: _$zod.ZodOptional<_$zod.ZodString>;
339
- turnId: _$zod.ZodNullable<_$zod.ZodString>;
338
+ timestamp: _$zod.ZodNumber;
340
339
  adapterSessionId: _$zod.ZodOptional<_$zod.ZodString>;
340
+ turnId: _$zod.ZodNullable<_$zod.ZodString>;
341
341
  contentText: _$zod.ZodString;
342
342
  adapterMessageId: _$zod.ZodOptional<_$zod.ZodString>;
343
343
  editOf: _$zod.ZodOptional<_$zod.ZodString>;
@@ -1119,10 +1119,10 @@ declare const MessageStorageNamespace$1: {
1119
1119
  output: _$zod.ZodString;
1120
1120
  isError: _$zod.ZodOptional<_$zod.ZodBoolean>;
1121
1121
  }, _$zod_v4_core0.$strip>], "type">>;
1122
- timestamp: _$zod.ZodNumber;
1123
1122
  agentId: _$zod.ZodOptional<_$zod.ZodString>;
1124
- turnId: _$zod.ZodNullable<_$zod.ZodString>;
1123
+ timestamp: _$zod.ZodNumber;
1125
1124
  adapterSessionId: _$zod.ZodOptional<_$zod.ZodString>;
1125
+ turnId: _$zod.ZodNullable<_$zod.ZodString>;
1126
1126
  contentText: _$zod.ZodString;
1127
1127
  adapterMessageId: _$zod.ZodOptional<_$zod.ZodString>;
1128
1128
  editOf: _$zod.ZodOptional<_$zod.ZodString>;
@@ -2029,12 +2029,12 @@ declare const MessageStorageNamespace$1: {
2029
2029
  isError?: boolean | undefined;
2030
2030
  })[];
2031
2031
  messageId: string;
2032
+ agentId: never;
2032
2033
  timestamp: number;
2033
- limit: never;
2034
2034
  query: string;
2035
- agentId: never;
2036
- turnId: string | null;
2035
+ limit: never;
2037
2036
  adapterSessionId: never;
2037
+ turnId: string | null;
2038
2038
  contentText: string;
2039
2039
  adapterMessageId: string;
2040
2040
  emitEvent: never;
@@ -0,0 +1 @@
1
+ import{A as e,B as t,C as n,D as r,E as i,F as a,G as o,H as s,I as c,J as l,K as u,L as d,M as f,N as ee,O as te,P as ne,R as re,S as ie,T as ae,U as oe,V as se,W as ce,_ as le,a as ue,b as de,c as fe,f as pe,g as me,h as he,i as ge,j as _e,k as ve,l as ye,m as p,n as be,p as xe,q as Se,s as Ce,t as we,u as Te,v as Ee,w as De,x as m,y as Oe,z as ke}from"./primitive-runtime-Dw6OC8w5.mjs";import{matchesFilter as Ae,matchesSubscription as je}from"@makaio/framework/bus";import{ArtifactSubjects as Me,EXECUTION_LIST_DEFAULT_LIMIT as Ne,EXECUTION_LIST_MAX_LIMIT as h,EXECUTION_LIST_MIN_LIMIT as g,ExecutionHintsSchema as Pe,ExecutionsByArtifactRefsQuerySchema as Fe,JsonPatchOperationSchema as Ie,JsonValueSchema as Le,SessionSubjects as Re,WORKFLOW_CANCELLED_REASON as _,WorkflowError as v,WorkflowErrorCode as ze,WorkflowNamespace as Be,WorkflowSubjects as y,createWorkflowCancelSubject as Ve,dep as He,extensionToken as Ue,serializeArtifactRef as We}from"@makaio/framework/contracts";import{BaseService as Ge}from"@makaio/framework/service-base";import{defineDialectSchema as Ke,executeTransaction as b,getDatabaseDialect as qe,registerDrizzleHandlers as Je,resolveSchema as x}from"@makaio/framework/storage/drizzle";import{and as S,asc as C,count as Ye,desc as w,eq as T,getTableColumns as Xe,gte as Ze,isNotNull as Qe,lt as $e,lte as et,or as tt,sql as E,sum as D}from"drizzle-orm";import{compile as nt}from"@makaio/framework/expression";import*as rt from"node:os";import{SessionToken as it}from"@makaio/framework/services";const at=n.postgres,ot=ee.postgres,st=ae.postgres,ct=a.postgres,lt=ke.postgres,ut=r.postgres,dt=d.postgres,ft=Se.postgres,pt=oe.postgres,mt=se.postgres,ht=o.postgres,gt=ve.postgres,_t=_e.postgres,O=Ke({workflowDefinitions:ie,workflowExecutions:f,workflowExecutionFrames:De,workflowGateInstances:ne,workflowStepSpans:re,workflowExecutionLinks:i,workflowRunContexts:c,worklogSummaries:u,worklogFrameEntries:s,worklogArtifactWrites:t,worklogGateEvents:ce,workflowExecutionState:te,workflowExecutionStateEvents:e},{workflowDefinitions:at,workflowExecutions:ot,workflowExecutionFrames:st,workflowGateInstances:ct,workflowStepSpans:lt,workflowExecutionLinks:ut,workflowRunContexts:dt,worklogSummaries:ft,worklogFrameEntries:pt,worklogArtifactWrites:mt,worklogGateEvents:ht,workflowExecutionState:gt,workflowExecutionStateEvents:_t});function k(e){return e.type===`global`?{scopeType:`global`,scopeKind:``,scopeId:``}:e.type===`external`?{scopeType:`external`,scopeKind:e.kind,scopeId:e.id}:{scopeType:e.type,scopeKind:``,scopeId:e.id}}function A(e){switch(e.scopeType){case`global`:return{type:`global`};case`external`:if(!e.scopeKind||!e.scopeId)throw Error(`Invalid external workflow scope row: scopeKind and scopeId are required`);return{type:`external`,kind:e.scopeKind,id:e.scopeId};case`workspace`:case`session`:if(!e.scopeId)throw Error(`Invalid ${e.scopeType} workflow scope row: scopeId is required`);return{type:e.scopeType,id:e.scopeId};default:{let t=e.scopeType;throw Error(`Unknown scope type: ${String(t)}`)}}}function vt(e,t){let{scopeType:n,scopeKind:r,scopeId:i}=k(t);return[T(e.scopeType,n),T(e.scopeKind,r),T(e.scopeId,i)]}function j(e){return{id:e.id,name:e.name,description:e.description??void 0,root:e.root,inputSchema:e.inputSchema??void 0,configSchema:e.configSchema??void 0,outputSchema:e.outputSchema??void 0,state:e.state??void 0,artifact:e.artifact??void 0,triggers:e.triggers??void 0,scope:A(e),canvasLayout:e.canvasLayout??void 0,source:e.source??void 0,executionHints:e.executionHints??void 0}}function yt(e,t){let n=k(e.scope);return{id:e.id,name:e.name??e.id,root:e.root,description:e.description??null,inputSchema:e.inputSchema??null,configSchema:e.configSchema??null,outputSchema:e.outputSchema??null,state:e.state??null,artifact:e.artifact??null,triggers:e.triggers??null,canvasLayout:e.canvasLayout??null,source:e.source??null,executionHints:e.executionHints??null,createdAt:t,updatedAt:t,...n}}function bt(e,t){let{workflowDefinitions:n}=x(t,O),r=Xe(n),i=e.on(m.get,async e=>{let r=await t.select().from(n).where(T(n.id,e.payload.id)).limit(1);e.setResult({workflow:r[0]?j(r[0]):null})}),a=e.on(m.set,async i=>{let a=i.payload.workflow,o=Date.now(),s=yt(a,o),c=await t.insert(n).values(s).onConflictDoNothing({target:n.id}).returning();if(c.length>0){await e.emit(l.definition.created,j(c[0])),i.setResult({id:a.id});return}let[u]=await t.update(n).set({name:s.name,root:s.root,updatedAt:o,createdAt:E`COALESCE(${r.createdAt}, ${o})`,description:s.description===null?E`${r.description}`:s.description,inputSchema:s.inputSchema===null?E`${r.inputSchema}`:s.inputSchema,configSchema:s.configSchema===null?E`${r.configSchema}`:s.configSchema,outputSchema:s.outputSchema===null?E`${r.outputSchema}`:s.outputSchema,state:s.state,artifact:s.artifact===null?E`${r.artifact}`:s.artifact,triggers:s.triggers===null?E`${r.triggers}`:s.triggers,canvasLayout:s.canvasLayout===null?E`${r.canvasLayout}`:s.canvasLayout,source:s.source===null?E`${r.source}`:s.source,executionHints:s.executionHints===null?E`${r.executionHints}`:s.executionHints,...k(a.scope)}).where(T(n.id,a.id)).returning();u&&await e.emit(l.definition.updated,j(u)),i.setResult({id:a.id})}),o=e.on(m.delete,async r=>{let i=(await t.delete(n).where(T(n.id,r.payload.id)).returning()).length>0;i&&await e.emit(l.definition.deleted,{id:r.payload.id}),r.setResult({deleted:i})}),s=e.on(m.list,async e=>{let r=e.payload,i=r.scope?vt(n,r.scope):[],a=i.length>0?await t.select().from(n).where(S(...i)):await t.select().from(n);e.setResult({workflows:a.map(j)})});return()=>{i(),a(),o(),s()}}function xt(e){return{frameId:e.frameId,nodeId:e.nodeId,nodeType:e.nodeType,path:e.path,parentFrameId:e.parentFrameId??void 0,status:e.status,attempt:e.attempt,iteration:e.iteration??void 0,branchKey:e.branchKey??void 0,...e.outputPresent?{output:e.output}:{},error:e.error??void 0,startedAt:e.startedAt??void 0,completedAt:e.completedAt??void 0}}function St(e,t){return{frameId:t.frameId,executionId:e,nodeId:t.nodeId,nodeType:t.nodeType,path:t.path,parentFrameId:t.parentFrameId??null,status:t.status,attempt:t.attempt,iteration:t.iteration??null,branchKey:t.branchKey??null,output:t.output===void 0?null:t.output,outputPresent:t.output!==void 0,error:t.error??null,startedAt:t.startedAt??null,completedAt:t.completedAt??null}}function Ct(e,t){let{workflowExecutionFrames:n}=x(t,O),r=e.on(m.setFrame,async e=>{let{executionId:r,frame:i}=e.payload,a=St(r,i);await t.insert(n).values(a).onConflictDoUpdate({target:n.frameId,set:a}),e.setResult({frameId:i.frameId})}),i=e.on(m.getFrame,async e=>{let r=await t.select().from(n).where(T(n.frameId,e.payload.frameId)).limit(1);e.setResult({frame:r[0]?xt(r[0]):null})}),a=e.on(m.listFrames,async e=>{let r=await t.select().from(n).where(T(n.executionId,e.payload.executionId)).orderBy(C(n.startedAt),C(n.frameId));e.setResult({frames:r.map(xt)})});return()=>{r(),i(),a()}}function wt(e){return`${e.executionId}:${e.nodeId}:${e.frameId}`}function M(e){return{executionId:e.executionId,nodeId:e.nodeId,frameId:e.frameId,schema:e.schema,prompt:e.prompt??void 0,status:e.status,autoAction:e.autoAction,timeoutMs:e.timeoutMs??null,...e.resumeDataPresent?{resumeData:e.resumeData}:{},...e.reason===null?{}:{reason:e.reason},createdAt:e.createdAt,resolvedAt:e.resolvedAt??void 0}}function N(e){return{id:wt(e),executionId:e.executionId,nodeId:e.nodeId,frameId:e.frameId,schema:e.schema,prompt:e.prompt??null,status:e.status,autoAction:e.autoAction,timeoutMs:e.timeoutMs,resumeData:e.resumeData===void 0?null:e.resumeData,reason:e.reason??null,resumeDataPresent:e.resumeData!==void 0,createdAt:e.createdAt,resolvedAt:e.resolvedAt??null}}function Tt(e,t,n,r){if(e===void 0&&t===void 0)throw Error(`Either executionId or status is required to list gate instances.`);let i=n??Ne;if(!Number.isInteger(i)||i<g||i>h)throw Error(`Gate instance list limit must be an integer between ${g} and ${h}.`);return{resolvedLimit:i,predicates:[...e===void 0?[]:[T(r.executionId,e)],...t===void 0?[]:[T(r.status,t)]]}}function Et(e,t){let{workflowExecutions:n,workflowGateInstances:r}=x(t,O),i=e.on(m.setGateInstance,async e=>{let n=e.payload.gate,i=N(n);await t.insert(r).values(i).onConflictDoUpdate({target:r.id,set:i}),e.setResult({id:i.id})}),a=e.on(m.resolveWaitingGateInstance,async e=>{let n=e.payload.gate,i=N(n),a=await t.update(r).set(i).where(S(T(r.id,i.id),T(r.status,`waiting`))).returning({id:r.id});e.setResult({accepted:a.length===1})}),o=e.on(m.getGateInstance,async e=>{let{executionId:n,nodeId:i,frameId:a}=e.payload,o=[T(r.executionId,n),T(r.nodeId,i)];a!==void 0&&o.push(T(r.frameId,a));let s=await t.select().from(r).where(S(...o)).limit(1);e.setResult({gate:s[0]?M(s[0]):null})}),s=e.on(m.listGateInstances,async e=>{let{executionId:n,status:i,limit:a}=e.payload,{resolvedLimit:o,predicates:s}=Tt(n,i,a,r),c=await t.select().from(r).where(S(...s)).orderBy(w(r.createdAt),w(r.id)).limit(o);e.setResult({gates:c.map(M)})}),c=e.on(m.listPausedGateTimeouts,async e=>{let i=await t.select({gate:r}).from(r).innerJoin(n,T(r.executionId,n.id)).where(S(T(r.status,`waiting`),T(n.status,`paused`),Qe(r.timeoutMs)));e.setResult({gates:i.map(e=>M(e.gate))})});return()=>{i(),a(),o(),s(),c()}}function Dt(e){return{executionId:e.executionId,frameId:e.frameId,stepId:e.stepId,stepType:e.stepType,status:e.status,startedAt:e.startedAt??void 0,completedAt:e.completedAt??void 0,durationMs:e.durationMs??void 0,inputTokens:e.inputTokens??void 0,outputTokens:e.outputTokens??void 0,estimatedCost:e.estimatedCost??void 0,toolCallCount:e.toolCallCount??void 0,input:e.input??void 0,output:e.output??void 0}}function Ot(e){return{sourceExecutionId:e.sourceExecutionId,targetExecutionId:e.targetExecutionId,linkType:e.linkType,metadata:e.metadata??void 0}}function kt(e,t){let{workflowStepSpans:n,workflowExecutionLinks:r}=x(t,O),i=e.on(m.setSpan,async e=>{let{span:r}=e.payload;await t.insert(n).values(r).onConflictDoUpdate({target:[n.executionId,n.frameId],set:r}),e.setResult({id:`${r.executionId}:${r.frameId}`})}),a=e.on(m.listSpans,async e=>{let r=await t.select().from(n).where(T(n.executionId,e.payload.executionId)).orderBy(C(n.startedAt),C(n.stepId),C(n.frameId));e.setResult({spans:r.map(Dt)})}),o=e.on(m.setExecutionLink,async e=>{let{link:n}=e.payload;await t.insert(r).values(n).onConflictDoUpdate({target:[r.sourceExecutionId,r.targetExecutionId],set:n}),e.setResult({id:`${n.sourceExecutionId}:${n.targetExecutionId}`})}),s=e.on(m.listExecutionLinks,async e=>{let{sourceExecutionId:n,targetExecutionId:i}=e.payload;if(n===void 0&&i===void 0)throw Error(`Either sourceExecutionId or targetExecutionId is required to list execution links.`);let a=[...n===void 0?[]:[T(r.sourceExecutionId,n)],...i===void 0?[]:[T(r.targetExecutionId,i)]],o=t.select().from(r).where(S(...a));e.setResult({links:(await o).map(Ot)})});return()=>{i(),a(),o(),s()}}function At(e){switch(e.kind){case`path`:return{sourceKind:`path`,sourcePath:e.path,sourceFilename:null,sourceCode:null};case`source`:return{sourceKind:`source`,sourcePath:null,sourceFilename:e.filename,sourceCode:e.source};case`definition`:return{sourceKind:`definition`,sourcePath:null,sourceFilename:null,sourceCode:null}}}function jt(e){switch(e.sourceKind){case`path`:if(!e.sourcePath)throw Error(`Invalid run context row: sourcePath required for kind=path`);return{kind:`path`,path:e.sourcePath};case`source`:if(!e.sourceFilename)throw Error(`Invalid run context row: sourceFilename required for kind=source`);return{kind:`source`,filename:e.sourceFilename,source:e.sourceCode??``};case`definition`:return{kind:`definition`,workflowId:e.workflowId};default:throw Error(`Unknown run context source kind: ${String(e.sourceKind)}`)}}function Mt(e){return{executionId:e.executionId,workflowId:e.workflowId,coordinatorSessionId:e.coordinatorSessionId,source:jt(e),definitionSnapshot:e.definitionSnapshot??void 0,workerManifest:e.workerManifest,inputs:e.inputs,config:e.config??{},triggerPayload:e.triggerPayload,...e.artifactRef===null?{}:{artifactRef:e.artifactRef},scope:A(e),...e.executionHints===null?{}:{executionHints:e.executionHints},...e.dispatchMetadata===null?{}:{dispatchMetadata:e.dispatchMetadata},cancelSubject:e.cancelSubject,context:e.context,env:e.env,createdAt:e.createdAt,suspensionStrategy:e.suspensionStrategy??`wait-in-process`}}function Nt(e){let t=At(e.source),n=k(e.scope);return{executionId:e.executionId,workflowId:e.workflowId,coordinatorSessionId:e.coordinatorSessionId,...t,definitionSnapshot:e.definitionSnapshot??null,workerManifest:e.workerManifest,inputs:e.inputs,config:e.config??{},triggerPayload:e.triggerPayload,artifactRef:e.artifactRef??null,executionHints:e.executionHints??null,dispatchMetadata:e.dispatchMetadata??null,...n,cancelSubject:e.cancelSubject,context:e.context,env:e.env,createdAt:e.createdAt,suspensionStrategy:e.suspensionStrategy}}async function Pt(e,t,n){let r=Nt(t);await e.insert(n).values(r).onConflictDoUpdate({target:n.executionId,set:r})}function Ft(e,t){let{workflowRunContexts:n}=x(t,O),r=e.on(m.setRunContext,async e=>{let r=e.payload.runContext;await Pt(t,r,n),e.setResult({executionId:r.executionId})}),i=e.on(m.getRunContext,async e=>{let{executionId:r}=e.payload,i=await t.select().from(n).where(T(n.executionId,r)),a=i[0]?Mt(i[0]):null;e.setResult({runContext:a})});return()=>{r(),i()}}function P(e,t){return t===null?qe(e)===`postgres`?E`'null'::jsonb`:E`'null'`:t}async function It(e,t,n){let{workflowExecutionState:r,workflowExecutionStateEvents:i}=x(e,O),a=Date.now(),o=P(e,n);await b(e,async e=>{await e.insert(r).values({executionId:t,sequence:0,value:o,updatedAt:a}).onConflictDoNothing(),await e.insert(i).values({executionId:t,sequence:0,patch:[],value:o,createdAt:a}).onConflictDoNothing()})}async function Lt(e,t){let{workflowExecutionState:n}=x(e,O),r=(await e.select().from(n).where(T(n.executionId,t)).limit(1))[0];return r?{executionId:r.executionId,sequence:r.sequence,value:r.value}:null}async function Rt(e,t){let{workflowExecutionState:n,workflowExecutionStateEvents:r}=x(e,O),i=Date.now(),a=P(e,t.nextValue);return b(e,async e=>{let o=(await e.select().from(n).where(T(n.executionId,t.executionId)).limit(1))[0];if(!o)throw Error(`no workflow state for execution ${t.executionId}`);if(t.expectedSequence===void 0)throw Error(`expectedSequence is required to patch workflow state`);let s=o.sequence+1,c=Oe(o.value,t.nextValue);if((await e.update(n).set({sequence:s,value:a,updatedAt:i}).where(S(T(n.executionId,t.executionId),T(n.sequence,t.expectedSequence))).returning()).length===0)throw Error(`state sequence conflict: expected ${String(t.expectedSequence)}, got ${String(o.sequence)}`);return await e.insert(r).values({executionId:t.executionId,sequence:s,patch:c,value:a,createdAt:i}),{executionId:t.executionId,sequence:s,patch:c,value:t.nextValue}})}function zt(e,t){let n=e.on(m.initializeState,async e=>{let{executionId:n,initialValue:r}=e.payload;await It(t,n,r),e.setResult({})}),r=e.on(m.getState,async e=>{let{executionId:n}=e.payload,r=await Lt(t,n);e.setResult({state:r})}),i=e.on(m.patchState,async e=>{let{executionId:n,expectedSequence:r,nextValue:i}=e.payload,a=await Rt(t,{executionId:n,expectedSequence:r,nextValue:i});e.setResult(a)});return()=>{n(),r(),i()}}function Bt(e){return{executionId:e.executionId,workflowId:e.workflowId,workflowName:e.workflowName??void 0,status:e.status,startedAt:e.startedAt,completedAt:e.completedAt??void 0,durationMs:e.durationMs??void 0,totalInputTokens:e.totalInputTokens??void 0,totalOutputTokens:e.totalOutputTokens??void 0,totalEstimatedCost:e.totalEstimatedCost??void 0,error:e.error??void 0,failedNodeId:e.failedNodeId??void 0}}async function F(e,t){let{worklogSummaries:n}=x(e,O);await e.insert(n).values(t).onConflictDoUpdate({target:n.executionId,set:t})}async function I(e,t){let{worklogSummaries:n}=x(e,O),r=await e.select().from(n).where(T(n.executionId,t)).limit(1);return r[0]?Bt(r[0]):null}async function Vt(e,t={}){let{worklogSummaries:n}=x(e,O),{workflowId:r,status:i,limit:a=50,offset:o=0}=t,s=[...r===void 0?[]:[T(n.workflowId,r)],...i===void 0?[]:[T(n.status,i)]],c=s.length>0?S(...s):void 0,[l,u]=await Promise.all([e.select().from(n).where(c).orderBy(w(n.startedAt)).limit(a).offset(o),e.select({count:Ye()}).from(n).where(c)]);return{items:l.map(Bt),total:u[0]?.count??0}}async function L(e,t){let{worklogFrameEntries:n}=x(e,O);await e.insert(n).values(t).onConflictDoUpdate({target:n.frameId,set:t})}async function R(e,t){let{worklogFrameEntries:n}=x(e,O);return(await e.select().from(n).where(T(n.frameId,t)).limit(1))[0]??null}async function Ht(e,t){let{worklogArtifactWrites:n}=x(e,O);await e.insert(n).values(t).onConflictDoUpdate({target:n.id,set:t})}function Ut(e,t,n,r,i){return`${e}:${t}:${n}:${r}:${i}`}async function z(e,t){let{worklogGateEvents:n}=x(e,O);await e.insert(n).values(t).onConflictDoUpdate({target:n.id,set:t})}async function Wt(e,t){let{worklogGateEvents:n}=x(e,O);return(await e.select().from(n).where(T(n.id,t)).limit(1))[0]??null}function B(e,t,n){return`${e}:${t}:${n}`}async function Gt(e,t){let{worklogFrameEntries:n}=x(e,O),[r]=await e.select({totalInputTokens:D(n.inputTokens),totalOutputTokens:D(n.outputTokens),totalEstimatedCost:D(n.estimatedCost)}).from(n).where(T(n.executionId,t));return{totalInputTokens:r?.totalInputTokens===null?0:Number(r?.totalInputTokens),totalOutputTokens:r?.totalOutputTokens===null?0:Number(r?.totalOutputTokens),totalEstimatedCost:r?.totalEstimatedCost===null?0:Number(r?.totalEstimatedCost)}}async function Kt(e,t={}){let{worklogSummaries:n}=x(e,O),{workflowId:r,since:i,until:a}=t,o=[...r===void 0?[]:[T(n.workflowId,r)],...i===void 0?[]:[Ze(n.startedAt,i)],...a===void 0?[]:[et(n.startedAt,a)]],s=o.length>0?S(...o):void 0,[c,l]=await Promise.all([e.select({status:n.status,count:Ye()}).from(n).where(s).groupBy(n.status),e.select({totalDurationMs:D(n.durationMs),totalInputTokens:D(n.totalInputTokens),totalOutputTokens:D(n.totalOutputTokens),totalEstimatedCost:D(n.totalEstimatedCost)}).from(n).where(s)]),u={pending:0,running:0,paused:0,completed:0,failed:0,cancelled:0},d=0;for(let e of c)u[e.status]=e.count,d+=e.count;let f=l[0];return{total:d,byStatus:u,totalDurationMs:Number(f?.totalDurationMs??0),totalInputTokens:Number(f?.totalInputTokens??0),totalOutputTokens:Number(f?.totalOutputTokens??0),totalEstimatedCost:Number(f?.totalEstimatedCost??0)}}async function qt(e,t,n,r,i){let a=await R(t,n);if(a===null||i===void 0)return null;let o=await e.requestOptional(Me.resolve,{ref:{refClass:`artifact`,kind:r.kind,id:r.id,revision:i}}).catch(()=>void 0);if(o===void 0||!o.handled||o.data.artifact===null)return null;let{kind:s,schemaVersion:c,scope:l}=o.data.artifact;return{nodeId:a.nodeId,artifact:{kind:s,schemaVersion:c,scope:l}}}async function V(e,t){try{await t()}catch(t){console.error(`[WorklogProjection] Write failed (${e}):`,t)}}async function H(e,t){try{await e.emit(l.worklog.changed,{executionId:t})}catch(e){console.error(`[WorklogProjection] worklog.changed emit failed for ${t}:`,e)}}async function Jt(e,t,n){await F(t,{executionId:n.executionId,workflowId:n.workflowId,workflowName:null,status:`running`,startedAt:n.startedAt??Date.now(),completedAt:null,durationMs:null,totalInputTokens:null,totalOutputTokens:null,totalEstimatedCost:null,error:null,failedNodeId:null}),await H(e,n.executionId)}async function Yt(e,t,n){let r=n.completedAt??Date.now(),i=await I(t,n.executionId);await F(t,{executionId:n.executionId,workflowId:i?.workflowId??n.executionId,workflowName:i?.workflowName??null,status:`completed`,startedAt:i?.startedAt??r-n.totalDuration,completedAt:r,durationMs:n.totalDuration,totalInputTokens:i?.totalInputTokens??null,totalOutputTokens:i?.totalOutputTokens??null,totalEstimatedCost:i?.totalEstimatedCost??null,error:null,failedNodeId:null}),await H(e,n.executionId)}async function Xt(e,t,n,r,i,a,o){let s=await I(t,n),c=s?.startedAt??o;await F(t,{executionId:n,workflowId:s?.workflowId??n,workflowName:s?.workflowName??null,status:r,startedAt:c,completedAt:o,durationMs:o-c,totalInputTokens:s?.totalInputTokens??null,totalOutputTokens:s?.totalOutputTokens??null,totalEstimatedCost:s?.totalEstimatedCost??null,error:i,failedNodeId:a}),await H(e,n)}async function Zt(e,t,n){let r=await Gt(t,n);if(r.totalInputTokens>0||r.totalOutputTokens>0||r.totalEstimatedCost>0){let e=await I(t,n);e&&await F(t,{executionId:n,workflowId:e.workflowId,workflowName:e.workflowName??null,status:e.status,startedAt:e.startedAt,completedAt:e.completedAt??null,durationMs:e.durationMs??null,totalInputTokens:r.totalInputTokens,totalOutputTokens:r.totalOutputTokens,totalEstimatedCost:r.totalEstimatedCost,error:e.error??null,failedNodeId:e.failedNodeId??null})}}function Qt(e,t){return[e.on(l.execution.started,async n=>{let{executionId:r}=n.payload;await V(`execution.started[${r}]`,()=>Jt(e,t,n.payload))}),e.on(l.execution.completed,async n=>{let{executionId:r}=n.payload;await V(`execution.completed[${r}]`,()=>Yt(e,t,n.payload))}),e.on(l.execution.failed,async n=>{let{executionId:r,error:i,failedStepId:a}=n.payload,o=n.payload.completedAt??Date.now();await V(`execution.failed[${r}]`,()=>Xt(e,t,r,`failed`,i,a??null,o))}),e.on(l.execution.cancelled,async n=>{let{executionId:r}=n.payload,i=n.payload.completedAt??Date.now();await V(`execution.cancelled[${r}]`,()=>Xt(e,t,r,`cancelled`,null,null,i))})]}function $t(e,t,n){return e===null?{nodeId:t,nodeType:`station`,path:[],attempt:0,iteration:null,branchKey:null,startedAt:n,inputTokens:null,outputTokens:null,estimatedCost:null}:{nodeId:e.nodeId,nodeType:e.nodeType,path:e.path,attempt:e.attempt,iteration:e.iteration,branchKey:e.branchKey,startedAt:e.startedAt,inputTokens:e.inputTokens,outputTokens:e.outputTokens,estimatedCost:e.estimatedCost}}async function en(e,t,n,r,i,a,o){let s=o??Date.now();await L(t,{frameId:r,executionId:n,...$t(await R(t,r),i,a===void 0?null:s-a),status:`completed`,completedAt:s,durationMs:a??null,error:null}),await Zt(e,t,n),await H(e,n)}async function tn(e,t,n,r,i,a,o,s){let c=s??Date.now();await L(t,{frameId:r,executionId:n,...$t(await R(t,r),i,o===void 0?null:c-o),status:`failed`,completedAt:c,durationMs:o??null,error:a}),await H(e,n)}function nn(e,t){return[e.on(l.frame.started,async n=>{let{executionId:r,frameId:i,nodeId:a,nodeType:o,path:s,startedAt:c}=n.payload;await V(`frame.started[${i}]`,async()=>{await L(t,{frameId:i,executionId:r,nodeId:a,nodeType:o,path:s,status:`running`,attempt:0,iteration:null,branchKey:null,startedAt:c??Date.now(),completedAt:null,durationMs:null,inputTokens:null,outputTokens:null,estimatedCost:null,error:null}),await H(e,r)})}),e.on(l.frame.completed,async n=>{let{executionId:r,frameId:i,nodeId:a,duration:o,completedAt:s}=n.payload;await V(`frame.completed[${i}]`,()=>en(e,t,r,i,a,o,s))}),e.on(l.frame.failed,async n=>{let{executionId:r,frameId:i,nodeId:a,error:o,duration:s,completedAt:c}=n.payload;await V(`frame.failed[${i}]`,()=>tn(e,t,r,i,a,o,s,c))})]}const rn={user:`rejected`,timeout:`timed-out`,cancelled:`cancelled`};function an(e,t){return[e.on(l.gate.suspended,async n=>{let{executionId:r,frameId:i,nodeId:a,prompt:o}=n.payload;await V(`gate.suspended[${i}]`,async()=>{await z(t,{id:B(r,a,i),executionId:r,nodeId:a,frameId:i,status:`waiting`,prompt:o??null,openedAt:Date.now(),resolvedAt:null,resumeData:null}),await H(e,r)})}),e.on(l.gate.resumed,async n=>{let{executionId:r,frameId:i,nodeId:a,resumeData:o}=n.payload;await V(`gate.resumed[${i}]`,async()=>{let n=B(r,a,i),s=await Wt(t,n),c=Date.now();await z(t,{id:n,executionId:r,nodeId:a,frameId:i,status:`resumed`,prompt:s?.prompt??null,openedAt:s?.openedAt??c,resolvedAt:c,resumeData:o}),await H(e,r)})}),e.on(l.gate.resolved,async n=>on(n.payload,e,t)),e.on(l.artifact.updated,async n=>{let{executionId:r,frameId:i,artifactRef:a,revision:o}=n.payload;await V(`artifact.updated[${r}:${i}]`,async()=>{let n=await qt(e,t,i,a,o);if(n===null)return;let s=Date.now();await Ht(t,{id:Ut(r,i,a.kind,a.id,s),executionId:r,frameId:i,nodeId:n.nodeId,artifact:n.artifact,revision:o??null,writtenAt:s}),await H(e,r)})})]}async function on(e,t,n){let{executionId:r,frameId:i,stepId:a,source:o}=e;o===`user`&&e.action===`approve`||await V(`gate.resolved[${i}]`,async()=>{let s=B(r,a,i),c=await Wt(n,s),l=Date.now();await z(n,{id:s,executionId:r,nodeId:a,frameId:i,status:o!==`cancelled`&&e.action===`approve`?`resumed`:rn[o],prompt:c?.prompt??null,openedAt:c?.openedAt??l,resolvedAt:l,resumeData:c?.resumeData??null}),await H(t,r)})}function sn(e,t){let n=[...Qt(e,t),...nn(e,t),...an(e,t),e.on(l.worklog.get,async e=>{let{executionId:n}=e.payload,r=await I(t,n);e.setResult({summary:r})}),e.on(l.worklog.list,async e=>{let{workflowId:n,status:r,limit:i,offset:a}=e.payload,o=await Vt(t,{workflowId:n,status:r,limit:i,offset:a});e.setResult(o)}),e.on(l.worklog.stats,async e=>{let{workflowId:n,since:r,until:i}=e.payload,a=await Kt(t,{workflowId:n,since:r,until:i});e.setResult({stats:a})})];return()=>{for(let e of n)e()}}function U(e){return{id:e.id,workflowId:e.workflowId,coordinatorSessionId:e.coordinatorSessionId??void 0,status:e.status,inputs:e.inputs,config:{},error:e.error??void 0,reason:e.reason??void 0,startedAt:e.startedAt,completedAt:e.completedAt??void 0,triggerPayload:e.triggerPayload??void 0,...e.artifactKind!==null&&e.artifactId!==null?{artifactRef:{kind:e.artifactKind,id:e.artifactId}}:{},scope:A(e)}}function W(e){let t=k(e.scope);return{id:e.id,workflowId:e.workflowId,coordinatorSessionId:e.coordinatorSessionId??null,status:e.status,inputs:e.inputs,error:e.error??null,reason:e.reason??null,startedAt:e.startedAt,completedAt:e.completedAt??null,triggerPayload:e.triggerPayload??null,artifactKind:e.artifactRef?.kind??null,artifactId:e.artifactRef?.id??null,...t}}function cn(e,t,n,r,i,a){let o=[...e?[T(a.workflowId,e)]:[],...n?[T(a.status,n)]:[],...i===void 0?[]:[T(a.artifactKind,i.kind),T(a.artifactId,i.id)]];if(t&&o.push(...vt(a,t)),r){let e=tt($e(a.startedAt,r.startedAt),S(T(a.startedAt,r.startedAt),$e(a.id,r.id)));e&&o.push(e)}return o}async function ln(e,t,n,r,i){if(n.executionId!==t.id)throw Error(`setExecutionStart requires execution.id to match runContext.executionId`);for(let e of i??[])if(e.targetExecutionId!==t.id)throw Error(`setExecutionStart requires executionLinks.targetExecutionId to match execution.id`);let{workflowExecutions:a,workflowRunContexts:o,workflowExecutionState:s,workflowExecutionStateEvents:c,workflowExecutionLinks:l}=x(e,O),u=W(t);await b(e,async d=>{await d.insert(a).values(u).onConflictDoUpdate({target:a.id,set:u});let f=(n.dispatchMetadata===void 0?await d.select({dispatchMetadata:o.dispatchMetadata}).from(o).where(T(o.executionId,n.executionId)).limit(1):[])[0]?.dispatchMetadata;if(await Pt(d,n.dispatchMetadata===void 0&&f!=null?{...n,dispatchMetadata:f}:n,o),r!==void 0){let n=Date.now(),i=P(e,r);await d.insert(s).values({executionId:t.id,sequence:0,value:i,updatedAt:n}).onConflictDoNothing(),await d.insert(c).values({executionId:t.id,sequence:0,patch:[],value:i,createdAt:n}).onConflictDoNothing()}for(let e of i??[])await d.insert(l).values(e).onConflictDoUpdate({target:[l.sourceExecutionId,l.targetExecutionId],set:e})})}async function un(e,t,n){if(n.executionId!==t.id)throw Error(`restorePausedGateResumeState requires execution.id to match gate.executionId`);if(t.status!==`paused`||n.status!==`waiting`)throw Error(`restorePausedGateResumeState requires a paused execution and waiting gate`);let{workflowExecutions:r,workflowGateInstances:i}=x(e,O),a=W(t),o=N(n);await b(e,async e=>{await e.insert(r).values(a).onConflictDoUpdate({target:r.id,set:a}),await e.insert(i).values(o).onConflictDoUpdate({target:i.id,set:o})})}async function dn(e,t,n,r){let{workflowExecutions:i,workflowGateInstances:a}=x(e,O);return b(e,async e=>{if((await e.select().from(i).where(T(i.id,t)).limit(1))[0]?.status!==`paused`)return{cancelled:!1,gates:[]};let o=(await e.select().from(a).where(S(T(a.executionId,t),T(a.status,`waiting`)))).map(e=>({...M(e),status:`cancelled`,resolvedAt:n}));await e.update(i).set({status:`cancelled`,completedAt:n,reason:r??null}).where(T(i.id,t));for(let t of o){let n=N(t);await e.update(a).set(n).where(T(a.id,n.id))}return{cancelled:!0,gates:o}})}async function fn(e,t,n,r,i,a){let{workflowExecutions:o}=x(e,O);return b(e,async e=>{if((await e.select({id:o.id}).from(o).where(T(o.id,t)).limit(1))[0]===void 0)return!1;let s={};return n!==void 0&&(s.status=n),r!==void 0&&(s.error=r),i!==void 0&&(s.reason=i),a!==void 0&&(s.completedAt=a),Object.keys(s).length>0&&await e.update(o).set(s).where(T(o.id,t)),!0})}function pn(e,t){let{workflowExecutions:n}=x(t,O),r=e.on(m.getExecution,async e=>{let{executionId:r}=e.payload,i=await t.select().from(n).where(T(n.id,r));e.setResult({execution:i[0]?U(i[0]):null})}),i=e.on(m.setExecution,async e=>{let r=e.payload.execution,i=W(r);await t.insert(n).values(i).onConflictDoUpdate({target:n.id,set:i}),e.setResult({id:r.id})}),a=e.on(m.setExecutionStart,async e=>{let n=e.payload.execution,r=e.payload.runContext;await ln(t,n,r,e.payload.initialState,e.payload.executionLinks),e.setResult({id:n.id,executionId:n.id})}),o=e.on(m.restorePausedGateResumeState,async e=>{let n=e.payload.execution,r=e.payload.gate;await un(t,n,r),e.setResult({executionId:n.id,gateId:r.nodeId})}),s=e.on(m.updateExecution,async e=>{let{executionId:n,status:r,error:i,reason:a,completedAt:o}=e.payload,s=await fn(t,n,r,i,a,o);e.setResult({success:s})}),c=e.on(m.cancelPausedExecution,async e=>{let{executionId:n,completedAt:r,reason:i}=e.payload;e.setResult(await dn(t,n,r,i))});return()=>{r(),i(),a(),o(),s(),c()}}function mn(e,t){let{workflowExecutions:n}=x(t,O),r=e.on(m.listExecutions,async e=>{let{workflowId:r,scope:i,status:a,limit:o,cursor:s,artifactRef:c}=e.payload;if(r===void 0&&i===void 0&&c===void 0)throw Error(`Either workflowId, scope, or artifactRef is required to list executions.`);let l=cn(r,i,a,s,c,n),u=o??Ne;if(!Number.isInteger(u)||u<g||u>h)throw Error(`Execution list limit must be an integer between ${g} and ${h}.`);let d=await t.select().from(n).where(S(...l)).orderBy(w(n.startedAt),w(n.id)).limit(u);e.setResult({executions:d.map(U)})}),i=e.on(m.listExecutionsByArtifactRefs,async e=>{let r=Fe.safeParse(e.payload);if(!r.success)throw Error(`Invalid listExecutionsByArtifactRefs query: ${r.error.message}`);let{refs:i,limitPerRef:a}=r.data,o={};for(let e of i){let r=await t.select().from(n).where(S(T(n.artifactKind,e.kind),T(n.artifactId,e.id))).orderBy(w(n.startedAt),w(n.id)).limit(a);r.length>0&&(o[We(e)]=r.map(U))}e.setResult({executionsByRef:o})});return()=>{r(),i()}}function G(e,t){let n=bt(e,t),r=pn(e,t),i=mn(e,t),a=Ct(e,t),o=Et(e,t),s=kt(e,t),c=Ft(e,t),l=zt(e,t),u=sn(e,t);return()=>{n(),r(),i(),a(),o(),s(),c(),l(),u()}}function K(e,t){if(e.origin.local)return!0;let n=e.transport?.peer;return n?.authenticated!==!0||n.id!==t?!1:n.kind===`workflow-execution`?!0:n.kind===`e2e`&&n.encrypted===!0}async function hn(e,t){let{runContext:n}=await e.request(m.getRunContext,{executionId:t});if(n===null)throw Error(`Run context not found for execution: ${t}`);if(n.definitionSnapshot!==void 0)return n.definitionSnapshot;let{workflow:r}=await e.request(m.get,{id:n.workflowId});return r??void 0}function gn(e){return[e.on(l.getDefinition,async t=>{let n=await e.request(m.get,{id:t.payload.id});t.setResult(n)}),e.on(l.setDefinition,async t=>{let n=await e.request(m.set,{workflow:t.payload.workflow});t.setResult(n)}),e.on(l.deleteDefinition,async t=>{let n=await e.request(m.delete,{id:t.payload.id});t.setResult(n)}),e.on(l.listDefinitions,async t=>{let n=await e.request(m.list,t.payload);t.setResult(n)}),e.on(l.getExecution,async t=>{let n=await e.request(m.getExecution,{executionId:t.payload.executionId});t.setResult(n)}),e.on(l.listExecutions,async t=>{let n=await e.request(m.listExecutions,t.payload);t.setResult(n)}),e.on(l.listExecutionsByArtifactRefs,async t=>{let n=await e.request(m.listExecutionsByArtifactRefs,t.payload);t.setResult(n)}),e.on(l.listSpans,async t=>{let n=await e.request(m.listSpans,{executionId:t.payload.executionId});t.setResult(n)}),e.on(l.listFrames,async t=>{let n=await e.request(m.listFrames,{executionId:t.payload.executionId});t.setResult(n)}),e.on(l.listGateInstances,async t=>{let n=await e.request(m.listGateInstances,t.payload);t.setResult(n)}),e.on(l.setExecutionLink,async t=>{let n=await e.request(m.setExecutionLink,{link:t.payload.link});t.setResult(n)}),e.on(l.listExecutionLinks,async t=>{let n=await e.request(m.listExecutionLinks,t.payload);t.setResult(n)}),e.on(l.getRunContext,async t=>{let{executionId:n}=t.payload;if(!K(t,n))throw Error(`Unauthorized: caller is not permitted to read run context for execution: ${n}`);let{runContext:r}=await e.request(m.getRunContext,{executionId:n});if(!r)throw Error(`Run context not found for execution: ${n}`);t.setResult(r)})]}function _n(e){return[e.on(l.state.get,async t=>{let{executionId:n}=t.payload;if(!K(t,n))throw Error(`Unauthorized: caller is not permitted to read state for execution: ${n}`);let{state:r}=await e.request(m.getState,{executionId:n});if(r===null)throw Error(`no workflow state for execution ${n}`);t.setResult(r)}),e.on(l.state.patch,async t=>{let{executionId:n,expectedSequence:r,patch:i,nextValue:a}=t.payload;if(!K(t,n))throw Error(`Unauthorized: caller is not permitted to patch state for execution: ${n}`);if(r===void 0)throw Error(`expectedSequence is required to patch workflow state`);let o=await hn(e,n);o!==void 0&&le(o,a,`next`),Ie.array().parse(i);let s=await e.request(m.patchState,{executionId:n,expectedSequence:r,nextValue:a});e.emit(l.state.updated,{executionId:s.executionId,sequence:s.sequence,patch:s.patch,value:s.value,updatedAt:Date.now()}).catch(()=>{}),t.setResult({executionId:s.executionId,sequence:s.sequence,value:s.value})})]}function vn(e,t){return[e.on(l.listTriggerTypes,e=>{let n=t()?.getAll()??[];e.setResult({triggerTypes:n})})]}async function yn(e,t){let{runContext:n}=await e.bus.request(m.getRunContext,{executionId:t});if(n===null)throw new v(ze.RUN_CONTEXT_NOT_FOUND,`Run context not found for workflow execution '${t}'.`);return n}function bn(e,t){return t===void 0?{mode:e}:{mode:e,reason:t}}async function xn(e,t){let n=await yn(e,t.executionId),r=t.input===void 0?n.inputs:t.input,i=t.config??n.config??{},a=t.triggerPayload??n.triggerPayload,o=t.artifactRef??n.artifactRef,s=t.executionHints??(t.mode===`snapshot`?n.executionHints:void 0),c=t.scopeOverride??n.scope,l={input:r,config:i,parentSessionId:t.parentSessionId,triggerPayload:a,artifactRef:o,executionHints:s,scopeOverride:c,executionLinks:e=>[{sourceExecutionId:t.executionId,targetExecutionId:e,linkType:`rerun-of`,metadata:bn(t.mode,t.reason)}]};return t.mode===`snapshot`?await Tn(e,n,l):Cn(n)?await En(e,n,l):await Ce(e,n.workflowId,l)}function Sn(e,t){return Cn(e)?t.id:e.workflowId}function Cn(e){return e.source.kind!==`definition`&&e.workflowId===e.executionId}function wn(e){let t=e.definitionSnapshot;if(t===void 0)throw new v(ze.SNAPSHOT_UNAVAILABLE,`Workflow execution '${e.executionId}' does not have a definition snapshot.`);return t}async function Tn(e,t,n){let r=wn(t);return ye(e,Sn(t,r),{workflow:r,executionSource:t.source,definitionSnapshot:r,input:n.input,config:n.config,parentSessionId:n.parentSessionId,triggerPayload:n.triggerPayload,artifactRef:n.artifactRef,executionHints:n.executionHints,scopeOverride:n.scopeOverride,executionLinks:n.executionLinks})}async function En(e,t,n){if(t.definitionSnapshot===void 0&&t.source.kind===`path`)return fe(e,t.source.path,n);let r=wn(t);return ye(e,r.id,{workflow:r,executionSource:t.source,input:n.input,config:n.config,parentSessionId:n.parentSessionId,triggerPayload:n.triggerPayload,artifactRef:n.artifactRef,executionHints:n.executionHints,scopeOverride:n.scopeOverride,executionLinks:n.executionLinks})}var Dn=class{bus;resumePausedExecution;handles=new Map;constructor(e,t){this.bus=e,this.resumePausedExecution=t}dispose(){for(let e of this.handles.values())clearTimeout(e);this.handles.clear()}clear(e,t,n){let r=this.makeKey(e,t,n),i=this.handles.get(r);i!==void 0&&(clearTimeout(i),this.handles.delete(r))}schedule(e){e.timeoutMs!==null&&(this.clear(e.executionId,e.nodeId,e.frameId),this.scheduleNextWakeup({...e,timeoutMs:e.timeoutMs}))}scheduleNextWakeup(e){let t=this.makeKey(e.executionId,e.nodeId,e.frameId),n=Math.max(0,e.openedAt+e.timeoutMs-Date.now()),r=setTimeout(()=>{if(this.handles.delete(t),Date.now()<e.openedAt+e.timeoutMs){this.scheduleNextWakeup(e);return}this.handleExpiredWakeup(e)},Math.min(n,2147483647));this.handles.set(t,r)}scheduleNextWakeupAfterDelay(e,t){let n=this.makeKey(e.executionId,e.nodeId,e.frameId),r=setTimeout(()=>{this.handles.delete(n),this.handleExpiredWakeup(e)},t);this.handles.set(n,r)}async handleExpiredWakeup(e){try{await this.resumeTimedOutPausedGate(e)===`retry`&&this.scheduleNextWakeupAfterDelay(e,25)}catch(t){this.scheduleFailedWakeupRetry(e,t)}}scheduleFailedWakeupRetry(e,t){let n=(e.failedWakeupAttempts??0)+1;if(n>4){console.error(`[WorkflowExecutor] Giving up on timed-out gate '${e.nodeId}' after 4 failed wakeup retries:`,t);return}let r=Math.min(250*2**(n-1),2e3);console.error(`[WorkflowExecutor] Failed to resume timed-out gate '${e.nodeId}', retrying in ${r} ms:`,t),this.scheduleNextWakeupAfterDelay({...e,failedWakeupAttempts:n},r)}makeKey(e,t,n){return`${e}:${t}:${n}`}async resumeTimedOutPausedGate(e){this.clear(e.executionId,e.nodeId,e.frameId);let{gate:t}=await this.bus.request(m.getGateInstance,{executionId:e.executionId,nodeId:e.nodeId,frameId:e.frameId});if(t===null||t.status!==`waiting`)return`settled`;let{execution:n}=await this.bus.request(m.getExecution,{executionId:e.executionId});return n?.status===`running`?`retry`:n?.status===`paused`?(await this.resumePausedExecution(e.executionId),`resumed`):`settled`}};function On(e){if(e!==void 0)return kn(e)?e:{}}function kn(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function An(e){if(e!==void 0)return Le.parse(e)}function jn(e){if(e!==void 0)return Pe.parse(e)}function Mn(e,t){return{repoPath:t,makaioHome:e.makaioHome??process.env.MAKAIO_HOME??`${rt.homedir()}/.makaio`,os:xe(process.platform),arch:process.arch}}function Nn(e,t){return{executionId:e.executionId,workflowId:e.workflowId,source:e.source,...e.definitionSnapshot===void 0?{}:{definitionSnapshot:e.definitionSnapshot},workerManifest:{packages:[]},inputs:e.inputs,config:e.config,scope:e.scope,triggerPayload:e.triggerPayload,...e.artifactRef===void 0?{}:{artifactRef:e.artifactRef},...e.executionHints===void 0?{}:{executionHints:e.executionHints},coordinatorSessionId:e.coordinatorSessionId,cancelSubject:`workflow.${e.executionId}.cancel`,context:Mn(t,e.workspaceRoot),env:t.platformDefaults.env??{},createdAt:Date.now(),suspensionStrategy:e.suspensionStrategy??`wait-in-process`}}function Pn(e){return e?.status===`paused`}function Fn(e){return e?.status===`waiting`}async function In(e,t,n,r,i,a,o){t.delete(i.id),n.delete(i.id),r.delete(i.id);try{await e.request(m.restorePausedGateResumeState,{execution:i,gate:a})}catch(e){console.error(`[WorkflowExecutor] Failed to restore paused gate '${o}' after resume launch failure:`,e)}}async function Ln(e,t){if(t.suspensionStrategy===`wait-in-process`)return;let{frames:n}=await e.request(m.listFrames,{executionId:t.executionId});if(n.length===0)throw Error(`[WorkflowExecutor] Missing resume frames for paused execution: ${t.executionId}`)}function Rn(e){return{executionId:e.executionId,nodeId:e.nodeId,frameId:e.frameId,timeoutMs:e.timeoutMs,openedAt:e.createdAt}}async function zn(e,t){if(t.frameId!==void 0){let{gate:n}=await e.request(m.getGateInstance,t);return Fn(n)?n:null}let{gates:n}=await e.request(m.listGateInstances,{executionId:t.executionId}),r=n.filter(e=>e.nodeId===t.nodeId&&e.status===`waiting`);return r.length===1?r[0]:null}var Bn=class extends Ge{static storage={drizzle:G};config;activeExecutions=new Map;executionTasks=new Map;shellAbortControllers=new Map;activeRunnerSteps=new Map;gateTimeoutScheduler;resumeDispatches=new Set;workflowAbortControllers=new Map;workflowRunner;triggerTypeRegistry;constructor(e,t,n){super(e),this.config={...Ee,...t},this.workflowRunner=n,this.gateTimeoutScheduler=new Dn(e,e=>this.resumePausedExecution(e))}setTriggerTypeRegistry(e){this.triggerTypeRegistry=e}getTriggerTypeRegistry(){return this.triggerTypeRegistry}async onInit(){this.registerExecutionHandlers();for(let e of gn(this.bus))this.addCleanup(e);for(let e of _n(this.bus))this.addCleanup(e);for(let e of vn(this.bus,()=>this.triggerTypeRegistry))this.addCleanup(e);await this.rehydratePausedGateTimeouts()}async onDestroy(){let e=this.buildFinalizerDeps();await Promise.allSettled([...this.activeExecutions.keys()].map(async t=>{await p(e,t,`Workflow engine shutdown`)&&(this.workflowAbortControllers.get(t)?.abort(),this.workflowAbortControllers.delete(t))}));for(let e of this.workflowAbortControllers.values())e.abort();this.workflowAbortControllers.clear(),await Promise.allSettled(this.executionTasks.values());for(let e of this.shellAbortControllers.values())e.abort();this.shellAbortControllers.clear();for(let e of this.activeRunnerSteps.values())e.hardKillTimer&&clearTimeout(e.hardKillTimer);this.activeRunnerSteps.clear(),this.gateTimeoutScheduler.dispose(),await this.workflowRunner?.dispose?.(),this.activeExecutions.clear()}buildFinalizerDeps(){return{bus:this.bus,activeExecutions:this.activeExecutions,shellAbortControllers:this.shellAbortControllers,activeRunnerSteps:this.activeRunnerSteps,cancelTimeoutMs:this.config.cancelTimeoutMs}}buildRunnerTaskDeps(e){return{workflowRunner:e,workflowAbortControllers:this.workflowAbortControllers,executionTasks:this.executionTasks,activeExecutions:this.activeExecutions,buildFinalizerDeps:()=>this.buildFinalizerDeps(),resolveWorkflowContext:e=>Mn(this.config,e),config:this.config}}async resolveExecutionWorkspaceRoot(e){if(!e)return this.config.platformDefaults.cwd;let{session:t}=await this.bus.request(Re.get,{sessionId:e});return t?.targetWorkingDirectory??this.config.platformDefaults.cwd}buildStartDeps(){return{bus:this.bus,config:this.config,activeExecutions:this.activeExecutions,executionTasks:this.executionTasks,workflowRunner:this.workflowRunner,buildRunContext:e=>Nn(e,this.config),buildRunnerTaskDeps:e=>this.buildRunnerTaskDeps(e),buildFinalizerDeps:()=>this.buildFinalizerDeps(),resolveExecutionWorkspaceRoot:e=>this.resolveExecutionWorkspaceRoot(e),runExecution:e=>this.runExecution(e)}}registerExecutionHandlers(){this.registerHandler(l.start,async e=>{let{workflowId:t,input:n,config:r,parentSessionId:i,triggerPayload:a,artifactRef:o,scope:s,executionHints:c}=e.payload;try{let l=await Ce(this.buildStartDeps(),t,{input:An(n),config:On(r)??{},parentSessionId:i,triggerPayload:a,artifactRef:o,executionHints:jn(c),scopeOverride:s});e.setResult({executionId:l})}catch(e){if(e instanceof v)throw e;let t=e instanceof Error?e.message:String(e);throw Error(`Failed to start workflow: ${t}`)}}),this.registerHandler(l.rerun,async e=>{let{executionId:t,mode:n,input:r,config:i,parentSessionId:a,triggerPayload:o,artifactRef:s,scope:c,executionHints:l,reason:u}=e.payload;try{let d=await xn(this.buildStartDeps(),{executionId:t,mode:n,input:An(r),config:On(i),parentSessionId:a,triggerPayload:o,artifactRef:s,executionHints:jn(l),scopeOverride:c,reason:u});e.setResult({executionId:d})}catch(e){if(e instanceof v)throw e;let t=e instanceof Error?e.message:String(e);throw Error(`Failed to rerun workflow: ${t}`)}}),this.registerHandler(l.runFile,async e=>{if(this.workflowRunner===void 0)throw Error(`workflow.runFile requires a workflow runner — configure a ThinWorkflowPiscinaRunner or equivalent.`);let{filePath:t,triggerPayload:n,scope:r}=e.payload;try{let i=await fe(this.buildStartDeps(),t,{triggerPayload:n,scopeOverride:r});e.setResult({executionId:i})}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Failed to start workflow file: ${t}`)}}),this.registerHandler(l.cancel,async e=>{let{executionId:t,reason:n}=e.payload;await this.bus.emit(Ve(`workflow.${t}.cancel`),{executionId:t,reason:n}).catch(e=>{console.error(`[WorkflowExecutor] Failed to emit workflow cancel for ${t}:`,e)});let r=this.workflowAbortControllers.get(t);if(r){r.abort(n??_);let i=await p(this.buildFinalizerDeps(),t,n);e.setResult({cancelled:i});return}let i=await p(this.buildFinalizerDeps(),t,n);e.setResult({cancelled:i})}),this.registerGateTimeoutHandlers(),this.addCleanup(this.bus.on(l.gate.respond,async e=>{let{executionId:t,gateId:n,frameId:r,action:i,resumeData:a,reason:o}=e.payload,s=await this.respondToPausedGate({executionId:t,gateId:n,frameId:r,action:i,resumeData:a,reason:o});e.setResult({accepted:s})},{priority:-100}))}registerGateTimeoutHandlers(){this.addCleanup(this.bus.on(l.gate.suspended,e=>{this.gateTimeoutScheduler.schedule(e.payload)})),this.addCleanup(this.bus.on(l.gate.resolved,e=>{this.gateTimeoutScheduler.clear(e.payload.executionId,e.payload.stepId,e.payload.frameId)}))}async rehydratePausedGateTimeouts(){let{gates:e}=await this.bus.request(m.listPausedGateTimeouts,{});for(let t of e)this.gateTimeoutScheduler.schedule(Rn(t))}async runExecution(e){let t=this.activeExecutions.get(e);if(!t)return;let n=new AbortController;this.workflowAbortControllers.set(e,n);try{let r;try{let i=await ge({definition:t.workflow,execution:t.execution,runContext:t.runContext,bus:this.bus}),a=new ue(e,t.workflow.id,t.workflow,t.execution,t.runtimeHandlers,this.bus,n.signal,void 0,i,{context:t.runContext.context,env:t.runContext.env}),o=a.buildExpressionContext();r=await we(t.workflow.root,a,o)}catch(r){if(n.signal.aborted||t.execution.status===`cancelled`){await p(this.buildFinalizerDeps(),e,_);return}let i=r instanceof Error?r.message:String(r);await he(this.buildFinalizerDeps(),t.execution,e,i);return}let i=this.buildFinalizerDeps();r.status===`cancelled`||n.signal.aborted||t.execution.status===`cancelled`?await p(i,e,_):r.status===`failed`?await he(i,t.execution,e,r.error):r.status===`paused`?(t.execution.status=`paused`,await this.bus.request(m.setExecution,{execution:t.execution}),this.activeExecutions.delete(e)):await me(i,t.execution,e,t.execution.startedAt)}finally{this.workflowAbortControllers.delete(e)}}async respondToPausedGate(e){let{executionId:t,gateId:n,frameId:r,resumeData:i,reason:a}=e,{execution:o}=await this.bus.request(m.getExecution,{executionId:t});if(!Pn(o))return!1;let s=await zn(this.bus,{executionId:t,nodeId:n,frameId:r});if(s===null||!be(n,s.schema,i).valid)return!1;let{runContext:c}=await this.bus.request(m.getRunContext,{executionId:t});if(c===null)throw Error(`[WorkflowExecutor] Run context not found for paused execution: ${t}`);await Ln(this.bus,c);let{accepted:l}=await this.bus.request(m.resolveWaitingGateInstance,{gate:{...s,status:e.action===`reject`?`rejected`:`resumed`,resumeData:i,...a===void 0?{}:{reason:a},resolvedAt:Date.now()}});if(!l)return!1;try{await this.resumePausedExecution(o.id)}catch(e){throw await In(this.bus,this.activeExecutions,this.executionTasks,this.workflowAbortControllers,o,s,n),e}return this.gateTimeoutScheduler.clear(t,n,s.frameId),!0}async resumePausedExecution(e){if(!this.resumeDispatches.has(e)){this.resumeDispatches.add(e);try{await this.dispatchPausedExecutionResume(e)||this.resumeDispatches.delete(e)}catch(t){throw this.resumeDispatches.delete(e),t}}}async dispatchPausedExecutionResume(e){let{runContext:t}=await this.bus.request(m.getRunContext,{executionId:e});if(t===null)throw Error(`[WorkflowExecutor] Run context not found for paused execution: ${e}`);let n=t.definitionSnapshot??(await this.bus.request(m.get,{id:t.workflowId})).workflow??(()=>{throw Error(`[WorkflowExecutor] Workflow definition not found for paused execution: ${e}`)})(),{execution:r}=await this.bus.request(m.getExecution,{executionId:e});if(r===null)throw Error(`[WorkflowExecutor] Execution not found for paused execution: ${e}`);if(r.status!==`paused`)return!1;await Ln(this.bus,t),await this.bus.request(m.setExecution,{execution:{...r,status:`running`}}),this.activeExecutions.set(e,{execution:{...r,status:`running`},workflow:n,runContext:t,runtimeHandlers:new Map});let i=pe(t,n,{resume:!0}),a=Te(this.buildStartDeps(),i).finally(()=>{this.resumeDispatches.delete(e)});return this.executionTasks.set(e,a),!0}};function Vn(e,t){try{return nt(e)}catch(n){console.error(`[BusEventTriggerEvaluator] Invalid trigger.filterExpression for workflow "${t}": "${e}"`,n);return}}function Hn(e){let t=e.indexOf(`.`),n=e.indexOf(`:`),r=t===-1?n:n===-1?t:Math.min(t,n);return r===-1?e:e.slice(0,r)}function Un(e){return{subject:`*`,$meta:{namespace:e,isRequest:!1}}}var Wn=class{bus;cleanupFns=[];initialized=!1;triggerIndex=new Map;subscribedNamespaces=new Set;constructor(e){this.bus=e}async init(){if(!this.initialized)try{this.cleanupFns.push(this.bus.on(y.definition.created,e=>{this.indexWorkflow(e.payload)}),this.bus.on(y.definition.updated,e=>{this.removeWorkflow(e.payload.id),this.indexWorkflow(e.payload)}),this.bus.on(y.definition.deleted,e=>{this.removeWorkflow(e.payload.id)})),await this.loadExistingTriggers(),this.initialized=!0}catch(e){throw this.cleanupFns.forEach(e=>e()),this.cleanupFns.length=0,this.triggerIndex.clear(),this.subscribedNamespaces.clear(),e}}destroy(){this.initialized&&=(this.cleanupFns.forEach(e=>e()),this.cleanupFns.length=0,this.triggerIndex.clear(),this.subscribedNamespaces.clear(),!1)}getTestState(){return{initialized:this.initialized,cleanupFns:[...this.cleanupFns],subscribedNamespaces:new Set(this.subscribedNamespaces)}}async loadExistingTriggers(){let{workflows:e}=await this.bus.request(m.list,{});for(let t of e)this.indexWorkflow(t)}indexWorkflow(e){let t=e.triggers??[],n=[];for(let r of t){if(r.type!==`bus-event`)continue;let t=typeof r.filterExpression==`string`?Vn(r.filterExpression,e.id):void 0;typeof r.filterExpression==`string`&&t===void 0||(n.push({workflowId:e.id,subject:r.subject,filter:r.filter,compiledFilterExpr:t}),this.ensureNamespaceSubscribed(Hn(r.subject)))}n.length>0&&this.triggerIndex.set(e.id,n)}removeWorkflow(e){this.triggerIndex.delete(e)}ensureNamespaceSubscribed(e){if(this.subscribedNamespaces.has(e))return;let t=Un(e),n=this.bus.on(t,e=>{if(e.isRequest)return;let t=typeof e.payload==`object`&&e.payload!==null?e.payload:{};this.handleBusEvent(e.subject,t)});this.cleanupFns.push(n),this.subscribedNamespaces.add(e)}handleBusEvent(e,t){for(let n of this.triggerIndex.values())for(let r of n)if(je(e,r.subject)&&!(r.filter&&!Ae(t,r.filter))){if(r.compiledFilterExpr){let n;try{n=r.compiledFilterExpr.evalSync({payload:t})}catch(n){console.error(`[BusEventTriggerEvaluator] filterExpression eval failed for workflow "${r.workflowId}" on subject "${e}" payload keys: [${Object.keys(t).join(`, `)}]`,n);continue}if(!n)continue}this.bus.request(y.start,{workflowId:r.workflowId,triggerPayload:t}).catch(t=>{console.error(`[BusEventTriggerEvaluator] Failed to start workflow "${r.workflowId}" triggered by "${e}":`,t)})}}};function q(e,t,n,r,i,a,o,s){return q.fromTZ(q.tp(e,t,n,r,i,a,o),s)}q.fromTZISO=(e,t,n)=>q.fromTZ(Gn(e,t),n),q.fromTZ=function(e,t){let n=new Date(Date.UTC(e.y,e.m-1,e.d,e.h,e.i,e.s)),r=J(e.tz,n),i=new Date(n.getTime()-r),a=J(e.tz,i);if(a-r===0)return i;{let r=new Date(n.getTime()-a),o=J(e.tz,r);if(o-a===0||!t&&o-a>0)return r;if(t)throw Error(`Invalid date passed to fromTZ()`);return i}},q.toTZ=function(e,t){let n=e.toLocaleString(`en-US`,{timeZone:t}).replace(/[\u202f]/,` `),r=new Date(n);return{y:r.getFullYear(),m:r.getMonth()+1,d:r.getDate(),h:r.getHours(),i:r.getMinutes(),s:r.getSeconds(),tz:t}},q.tp=(e,t,n,r,i,a,o)=>({y:e,m:t,d:n,h:r,i,s:a,tz:o});function J(e,t=new Date){let n=t.toLocaleString(`en-US`,{timeZone:e,timeZoneName:`shortOffset`}).split(` `).slice(-1)[0],r=t.toLocaleString(`en-US`).replace(/[\u202f]/,` `);return Date.parse(`${r} GMT`)-Date.parse(`${r} ${n}`)}function Gn(e,t){let n=new Date(Date.parse(e));if(isNaN(n))throw Error(`minitz: Invalid ISO8601 passed to parser.`);let r=e.substring(9);return e.includes(`Z`)||r.includes(`-`)||r.includes(`+`)?q.tp(n.getUTCFullYear(),n.getUTCMonth()+1,n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),`Etc/UTC`):q.tp(n.getFullYear(),n.getMonth()+1,n.getDate(),n.getHours(),n.getMinutes(),n.getSeconds(),t)}q.minitz=q;var Kn=32,Y=31|Kn,qn=[1,2,4,8,16],Jn=class{pattern;timezone;second;minute;hour;day;month;dayOfWeek;lastDayOfMonth;starDOM;starDOW;constructor(e,t){this.pattern=e,this.timezone=t,this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.lastDayOfMonth=!1,this.starDOM=!1,this.starDOW=!1,this.parse()}parse(){if(!(typeof this.pattern==`string`||this.pattern instanceof String))throw TypeError(`CronPattern: Pattern has to be of type string.`);this.pattern.indexOf(`@`)>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.replace(/\s+/g,` `).split(` `);if(e.length<5||e.length>6)throw TypeError(`CronPattern: invalid configuration format ('`+this.pattern+`'), exactly five or six space separated parts are required.`);if(e.length===5&&e.unshift(`0`),e[3].indexOf(`L`)>=0&&(e[3]=e[3].replace(`L`,``),this.lastDayOfMonth=!0),e[3]==`*`&&(this.starDOM=!0),e[4].length>=3&&(e[4]=this.replaceAlphaMonths(e[4])),e[5].length>=3&&(e[5]=this.replaceAlphaDays(e[5])),e[5]==`*`&&(this.starDOW=!0),this.pattern.indexOf(`?`)>=0){let t=new Z(new Date,this.timezone).getDate(!0);e[0]=e[0].replace(`?`,t.getSeconds().toString()),e[1]=e[1].replace(`?`,t.getMinutes().toString()),e[2]=e[2].replace(`?`,t.getHours().toString()),this.starDOM||(e[3]=e[3].replace(`?`,t.getDate().toString())),e[4]=e[4].replace(`?`,(t.getMonth()+1).toString()),this.starDOW||(e[5]=e[5].replace(`?`,t.getDay().toString()))}this.throwAtIllegalCharacters(e),this.partToArray(`second`,e[0],0,1),this.partToArray(`minute`,e[1],0,1),this.partToArray(`hour`,e[2],0,1),this.partToArray(`day`,e[3],-1,1),this.partToArray(`month`,e[4],-1,1),this.partToArray(`dayOfWeek`,e[5],0,Y),this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,n,r){let i=this[e],a=e===`day`&&this.lastDayOfMonth;if(t===``&&!a)throw TypeError(`CronPattern: configuration entry `+e+` (`+t+`) is empty, check for trailing spaces.`);if(t===`*`)return i.fill(r);let o=t.split(`,`);if(o.length>1)for(let t=0;t<o.length;t++)this.partToArray(e,o[t],n,r);else t.indexOf(`-`)!==-1&&t.indexOf(`/`)!==-1?this.handleRangeWithStepping(t,e,n,r):t.indexOf(`-`)===-1?t.indexOf(`/`)===-1?t!==``&&this.handleNumber(t,e,n,r):this.handleStepping(t,e,n,r):this.handleRange(t,e,n,r)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===5?/[^/*0-9,\-#L]+/:/[^/*0-9,-]+/).test(e[t]))throw TypeError(`CronPattern: configuration entry `+t+` (`+e[t]+`) contains illegal characters.`)}handleNumber(e,t,n,r){let i=this.extractNth(e,t),a=parseInt(i[0],10)+n;if(isNaN(a))throw TypeError(`CronPattern: `+t+` is not a number: '`+e+`'`);this.setPart(t,a,i[1]||r)}setPart(e,t,n){if(!Object.prototype.hasOwnProperty.call(this,e))throw TypeError(`CronPattern: Invalid part specified: `+e);if(e===`dayOfWeek`){if(t===7&&(t=0),t<0||t>6)throw RangeError(`CronPattern: Invalid value for dayOfWeek: `+t);this.setNthWeekdayOfMonth(t,n);return}if(e===`second`||e===`minute`){if(t<0||t>=60)throw RangeError(`CronPattern: Invalid value for `+e+`: `+t)}else if(e===`hour`){if(t<0||t>=24)throw RangeError(`CronPattern: Invalid value for `+e+`: `+t)}else if(e===`day`){if(t<0||t>=31)throw RangeError(`CronPattern: Invalid value for `+e+`: `+t)}else if(e===`month`&&(t<0||t>=12))throw RangeError(`CronPattern: Invalid value for `+e+`: `+t);this[e][t]=n}handleRangeWithStepping(e,t,n,r){let i=this.extractNth(e,t),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw TypeError(`CronPattern: Syntax error, illegal range with stepping: '`+e+`'`);let[,o,s,c]=a,l=parseInt(o,10)+n,u=parseInt(s,10)+n,d=parseInt(c,10);if(isNaN(l))throw TypeError(`CronPattern: Syntax error, illegal lower range (NaN)`);if(isNaN(u))throw TypeError(`CronPattern: Syntax error, illegal upper range (NaN)`);if(isNaN(d))throw TypeError(`CronPattern: Syntax error, illegal stepping: (NaN)`);if(d===0)throw TypeError(`CronPattern: Syntax error, illegal stepping: 0`);if(d>this[t].length)throw TypeError(`CronPattern: Syntax error, steps cannot be greater than maximum value of part (`+this[t].length+`)`);if(l>u)throw TypeError(`CronPattern: From value is larger than to value: '`+e+`'`);for(let e=l;e<=u;e+=d)this.setPart(t,e,i[1]||r)}extractNth(e,t){let n=e,r;if(n.includes(`#`)){if(t!==`dayOfWeek`)throw Error(`CronPattern: nth (#) only allowed in day-of-week field`);r=n.split(`#`)[1],n=n.split(`#`)[0]}return[n,r]}handleRange(e,t,n,r){let i=this.extractNth(e,t),a=i[0].split(`-`);if(a.length!==2)throw TypeError(`CronPattern: Syntax error, illegal range: '`+e+`'`);let o=parseInt(a[0],10)+n,s=parseInt(a[1],10)+n;if(isNaN(o))throw TypeError(`CronPattern: Syntax error, illegal lower range (NaN)`);if(isNaN(s))throw TypeError(`CronPattern: Syntax error, illegal upper range (NaN)`);if(o>s)throw TypeError(`CronPattern: From value is larger than to value: '`+e+`'`);for(let e=o;e<=s;e++)this.setPart(t,e,i[1]||r)}handleStepping(e,t,n,r){let i=this.extractNth(e,t),a=i[0].split(`/`);if(a.length!==2)throw TypeError(`CronPattern: Syntax error, illegal stepping: '`+e+`'`);a[0]===``&&(a[0]=`*`);let o=0;a[0]!==`*`&&(o=parseInt(a[0],10)+n);let s=parseInt(a[1],10);if(isNaN(s))throw TypeError(`CronPattern: Syntax error, illegal stepping: (NaN)`);if(s===0)throw TypeError(`CronPattern: Syntax error, illegal stepping: 0`);if(s>this[t].length)throw TypeError(`CronPattern: Syntax error, max steps for part is (`+this[t].length+`)`);for(let e=o;e<this[t].length;e+=s)this.setPart(t,e,i[1]||r)}replaceAlphaDays(e){return e.replace(/-sun/gi,`-7`).replace(/sun/gi,`0`).replace(/mon/gi,`1`).replace(/tue/gi,`2`).replace(/wed/gi,`3`).replace(/thu/gi,`4`).replace(/fri/gi,`5`).replace(/sat/gi,`6`)}replaceAlphaMonths(e){return e.replace(/jan/gi,`1`).replace(/feb/gi,`2`).replace(/mar/gi,`3`).replace(/apr/gi,`4`).replace(/may/gi,`5`).replace(/jun/gi,`6`).replace(/jul/gi,`7`).replace(/aug/gi,`8`).replace(/sep/gi,`9`).replace(/oct/gi,`10`).replace(/nov/gi,`11`).replace(/dec/gi,`12`)}handleNicknames(e){let t=e.trim().toLowerCase();return t===`@yearly`||t===`@annually`?`0 0 1 1 *`:t===`@monthly`?`0 0 1 * *`:t===`@weekly`?`0 0 * * 0`:t===`@daily`?`0 0 * * *`:t===`@hourly`?`0 * * * *`:e}setNthWeekdayOfMonth(e,t){if(typeof t!=`number`&&t===`L`)this.dayOfWeek[e]=this.dayOfWeek[e]|Kn;else if(t===Y)this.dayOfWeek[e]=Y;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|qn[t-1];else throw TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}},Yn=[31,28,31,30,31,30,31,31,30,31,30,31],X=[[`month`,`year`,0],[`day`,`month`,-1],[`hour`,`day`,0],[`minute`,`hour`,0],[`second`,`minute`,0]],Z=class e{tz;ms;second;minute;hour;day;month;year;constructor(t,n){if(this.tz=n,t&&t instanceof Date)if(!isNaN(t))this.fromDate(t);else throw TypeError(`CronDate: Invalid date passed to CronDate constructor`);else if(t===void 0)this.fromDate(new Date);else if(t&&typeof t==`string`)this.fromString(t);else if(t instanceof e)this.fromCronDate(t);else throw TypeError(`CronDate: Invalid type (`+typeof t+`) passed to CronDate constructor`)}isNthWeekdayOfMonth(e,t,n,r){let i=new Date(Date.UTC(e,t,n)).getUTCDay(),a=0;for(let r=1;r<=n;r++)new Date(Date.UTC(e,t,r)).getUTCDay()===i&&a++;if(r&Y&&qn[a-1]&r)return!0;if(r&Kn){let r=new Date(Date.UTC(e,t+1,0)).getUTCDate();for(let a=n+1;a<=r;a++)if(new Date(Date.UTC(e,t,a)).getUTCDay()===i)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz==`number`)this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else{let t=q.toTZ(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear()}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms}apply(){if(this.month>11||this.day>Yn[this.month]||this.hour>59||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz==`number`){let t=q.fromTZISO(e);this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(q.fromTZISO(e,this.tz))}findNext(e,t,n,r){let i=this[t],a;n.lastDayOfMonth&&(a=this.month===1?new Date(Date.UTC(this.year,this.month+1,0,0,0,0,0)).getUTCDate():Yn[this.month]);let o=!n.starDOW&&t==`day`?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0;for(let s=this[t]+r;s<n[t].length;s++){let c=n[t][s];if(t===`day`&&n.lastDayOfMonth&&s-r==a&&(c=1),t===`day`&&!n.starDOW){let t=n.dayOfWeek[(o+(s-r-1))%7];if(t&&t&Y)t=+!!this.isNthWeekdayOfMonth(this.year,this.month,s-r,t);else if(t)throw Error(`CronDate: Invalid value for dayOfWeek encountered. ${t}`);e.legacyMode&&!n.starDOM?c||=t:c&&=t}if(c)return this[t]=s-r,i===this[t]?1:2}return 3}recurse(e,t,n){let r=this.findNext(t,X[n][0],e,X[n][2]);if(r>1){let i=n+1;for(;i<X.length;)this[X[i][0]]=-X[i][2],i++;if(r===3)return this[X[n][1]]++,this[X[n][0]]=-X[n][2],this.apply(),this.recurse(e,t,0);if(this.apply())return this.recurse(e,t,n-1)}return n+=1,n>=X.length?this:this.year>=3e3?null:this.recurse(e,t,n)}increment(e,t,n){return this.second+=t.interval!==void 0&&t.interval>1&&n?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}getDate(e){return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz==`number`?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):q.fromTZ(q.tp(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}};function Xn(e){if(e===void 0&&(e={}),delete e.name,e.legacyMode=e.legacyMode===void 0?!0:e.legacyMode,e.paused=e.paused===void 0?!1:e.paused,e.maxRuns=e.maxRuns===void 0?1/0:e.maxRuns,e.catch=e.catch===void 0?!1:e.catch,e.interval=e.interval===void 0?0:parseInt(e.interval.toString(),10),e.utcOffset=e.utcOffset===void 0?void 0:parseInt(e.utcOffset.toString(),10),e.unref=e.unref===void 0?!1:e.unref,e.startAt&&=new Z(e.startAt,e.timezone),e.stopAt&&=new Z(e.stopAt,e.timezone),e.interval!==null){if(isNaN(e.interval))throw Error(`CronOptions: Supplied value for interval is not a number`);if(e.interval<0)throw Error(`CronOptions: Supplied value for interval can not be negative`)}if(e.utcOffset!==void 0){if(isNaN(e.utcOffset))throw Error(`CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.`);if(e.utcOffset<-870||e.utcOffset>870)throw Error(`CronOptions: utcOffset out of bounds.`);if(e.utcOffset!==void 0&&e.timezone)throw Error(`CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.`)}if(e.unref!==!0&&e.unref!==!1)throw Error(`CronOptions: Unref should be either true, false or undefined(false).`);return e}function Q(e){return Object.prototype.toString.call(e)===`[object Function]`||typeof e==`function`||e instanceof Function}function Zn(e){return Q(e)}function Qn(e){typeof Deno<`u`&&typeof Deno.unrefTimer<`u`?Deno.unrefTimer(e):e&&typeof e.unref<`u`&&e.unref()}var $n=30*1e3,$=[],er=class{name;options;_states;fn;constructor(e,t,n){let r,i;if(Q(t))i=t;else if(typeof t==`object`)r=t;else if(t!==void 0)throw Error(`Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).`);if(Q(n))i=n;else if(typeof n==`object`)r=n;else if(n!==void 0)throw Error(`Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).`);if(this.name=r?.name,this.options=Xn(r),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:r?r.maxRuns:void 0,paused:r?r.paused:!1,pattern:new Jn(`* * * * *`)},e&&(e instanceof Date||typeof e==`string`&&e.indexOf(`:`)>0)?this._states.once=new Z(e,this.options.timezone||this.options.utcOffset):this._states.pattern=new Jn(e,this.options.timezone),this.name){if($.find(e=>e.name===this.name))throw Error(`Cron: Tried to initialize new named job '`+this.name+`', but name already taken.`);$.push(this)}return i!==void 0&&Zn(i)&&(this.fn=i,this.schedule()),this}nextRun(e){let t=this._next(e);return t?t.getDate(!1):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let n=[],r=t||this._states.currentRun||void 0;for(;e--&&(r=this.nextRun(r));)n.push(r);return n}getPattern(){return this._states.pattern?this._states.pattern.pattern:void 0}isRunning(){let e=this.nextRun(this._states.currentRun),t=!this._states.paused,n=this.fn!==void 0,r=!this._states.kill;return t&&n&&r&&e!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=this._next(e);return t?e instanceof Z||e instanceof Date?t.getTime()-e.getTime():t.getTime()-new Z(e).getTime():null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=$.indexOf(this);e>=0&&$.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){if(e&&this.fn)throw Error(`Cron: It is not allowed to schedule two functions using the same Croner instance.`);e&&(this.fn=e);let t=this.msToNext(),n=this.nextRun(this._states.currentRun);return t==null||isNaN(t)||n===null?this:(t>$n&&(t=$n),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(n),t),this._states.currentTimeout&&this.options.unref&&Qn(this._states.currentTimeout),this)}async _trigger(e){if(this._states.blocking=!0,this._states.currentRun=new Z(void 0,this.options.timezone||this.options.utcOffset),this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(e){Q(this.options.catch)&&this.options.catch(e,this)}else this.fn!==void 0&&await this.fn(this,this.options.context);this._states.previousRun=new Z(e,this.options.timezone||this.options.utcOffset),this._states.blocking=!1}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,n=!this._states.paused&&t.getTime()>=e.getTime(),r=this._states.blocking&&this.options.protect;n&&!r?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger()):n&&r&&Q(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this.schedule()}_next(e){let t=!!(e||this._states.currentRun),n=!1;!e&&this.options.startAt&&this.options.interval&&([e,t]=this._calculatePreviousRun(e,t),n=!e),e=new Z(e,this.options.timezone||this.options.utcOffset),this.options.startAt&&e&&e.getTime()<this.options.startAt.getTime()&&(e=this.options.startAt);let r=this._states.once||new Z(e,this.options.timezone||this.options.utcOffset);return!n&&r!==this._states.once&&(r=r.increment(this._states.pattern,this.options,t)),this._states.once&&this._states.once.getTime()<=e.getTime()||r===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||this.options.stopAt&&r.getTime()>=this.options.stopAt.getTime()?null:r}_calculatePreviousRun(e,t){let n=new Z(void 0,this.options.timezone||this.options.utcOffset),r=e;if(this.options.startAt.getTime()<=n.getTime()){r=this.options.startAt;let e=r.getTime()+this.options.interval*1e3;for(;e<=n.getTime();)r=new Z(r,this.options.timezone||this.options.utcOffset).increment(this._states.pattern,this.options,!0),e=r.getTime()+this.options.interval*1e3;t=!0}return r===null&&(r=void 0),[r,t]}};function tr(e,t){return`${e}:${t}`}function nr(e){return e??`UTC`}var rr=class{bus;cleanupFns=[];initialized=!1;jobs=new Map;constructor(e){this.bus=e}async init(){if(!this.initialized)try{this.cleanupFns.push(this.bus.on(y.definition.created,e=>{this.scheduleWorkflow(e.payload)}),this.bus.on(y.definition.updated,e=>{this.unscheduleWorkflow(e.payload.id),this.scheduleWorkflow(e.payload)}),this.bus.on(y.definition.deleted,e=>{this.unscheduleWorkflow(e.payload.id)})),await this.loadExistingTriggers(),this.initialized=!0}catch(e){throw this.cleanupFns.forEach(e=>e()),this.cleanupFns.length=0,this.stopAllJobs(),e}}destroy(){this.initialized&&=(this.cleanupFns.forEach(e=>e()),this.cleanupFns.length=0,this.stopAllJobs(),!1)}activeJobCount(){return this.jobs.size}async loadExistingTriggers(){let{workflows:e}=await this.bus.request(m.list,{});for(let t of e)this.scheduleWorkflow(t)}scheduleWorkflow(e){if(e.scope.type===`global`)return;let t=e.triggers??[];for(let n=0;n<t.length;n++){let r=t[n];if(r.type!==`cron`)continue;let i=tr(e.id,n);this.stopJob(i);try{let t=nr(r.timezone),a=new er(r.schedule,{timezone:t},()=>{this.fireTrigger(e.id,n)});this.jobs.set(i,{workflowId:e.id,triggerIndex:n,job:a})}catch(t){console.warn(`[CronTriggerEvaluator] Skipping invalid cron trigger key="${i}" workflowId="${e.id}" triggerIndex=${n} schedule="${r.schedule}" timezone="${r.timezone??`UTC`}"`,t)}}}unscheduleWorkflow(e){for(let[t,n]of this.jobs)n.workflowId===e&&(n.job.stop(),this.jobs.delete(t))}stopJob(e){let t=this.jobs.get(e);t&&(t.job.stop(),this.jobs.delete(e))}stopAllJobs(){for(let e of this.jobs.values())e.job.stop();this.jobs.clear()}fireTrigger(e,t){this.bus.request(y.start,{workflowId:e,triggerPayload:{firedAt:Date.now(),triggerIndex:t}}).catch(n=>{console.error(`[CronTriggerEvaluator] Failed to start workflow "${e}" for cron trigger index ${t}:`,n)})}},ir=class extends Ge{workflowExecutor;busEventTriggerEvaluator;cronTriggerEvaluator;constructor(e,t){super(e),this.workflowExecutor=new Bn(e,t?.executorConfig,t?.workflowRunner),this.busEventTriggerEvaluator=new Wn(e),this.cronTriggerEvaluator=new rr(e)}get executor(){return this.workflowExecutor}get cronTriggers(){return this.cronTriggerEvaluator}setTriggerTypeRegistry(e){this.workflowExecutor.setTriggerTypeRegistry(e)}getTriggerTypeRegistry(){return this.workflowExecutor.getTriggerTypeRegistry()}async onInit(){this.addCleanup(()=>this.destroyOwnedServices()),await this.workflowExecutor.init(),await this.busEventTriggerEvaluator.init(),await this.cronTriggerEvaluator.init()}async destroyOwnedServices(){let e=[];for(let t of[()=>this.cronTriggerEvaluator.destroy(),()=>this.busEventTriggerEvaluator.destroy(),()=>this.workflowExecutor.destroy()])try{await t()}catch(t){e.push(t)}if(e.length===1)throw e[0];if(e.length>1)throw AggregateError(e,`Workflow engine service teardown failed`)}};const ar=Ue(`makaio.workflow-engine`);function or(e){return{name:ar.name,displayName:`Workflow Engine`,version:`0.1.0`,dependencies:[He(it.name)],critical:!0,namespaces:[Be,de],storage:{registerHandlers:Je(G)},create:t=>new ir(t.bus,e)}}const sr=or();export{Bn as a,It as c,ir as i,Rt as l,or as n,G as o,sr as r,Lt as s,ar as t};
package/dist/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@makaio/framework",
3
- "version": "1.0.0-dev-1781517341920",
3
+ "version": "1.0.0-dev-1781729807808",
4
4
  "type": "module"
5
5
  }