@sixb/core 0.1.9 → 0.1.10

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 (279) hide show
  1. package/dist/actions/index.js +8 -8
  2. package/dist/agents/index.js +16 -15
  3. package/dist/agents/index.js.map +1 -1
  4. package/dist/bootstrap/index.js +20 -19
  5. package/dist/bootstrap/index.js.map +1 -1
  6. package/dist/broker/in-memory.d.ts +8 -2
  7. package/dist/broker/in-memory.d.ts.map +1 -1
  8. package/dist/broker/index.d.ts +4 -2
  9. package/dist/broker/index.d.ts.map +1 -1
  10. package/dist/broker/index.js +7 -3
  11. package/dist/broker/index.js.map +1 -1
  12. package/dist/broker/retention.d.ts +4 -0
  13. package/dist/broker/retention.d.ts.map +1 -0
  14. package/dist/broker/subscriber.d.ts +10 -0
  15. package/dist/broker/subscriber.d.ts.map +1 -0
  16. package/dist/broker/types.d.ts +14 -1
  17. package/dist/broker/types.d.ts.map +1 -1
  18. package/dist/{chunk-k3cqkkn2.js → chunk-1824gssz.js} +30 -65
  19. package/dist/chunk-1824gssz.js.map +12 -0
  20. package/dist/{chunk-h1gfhhbh.js → chunk-28ja2cjs.js} +1 -1
  21. package/dist/chunk-2c4j899j.js.map +1 -1
  22. package/dist/{chunk-ppytyr6w.js → chunk-358caqf5.js} +4 -4
  23. package/dist/chunk-358caqf5.js.map +12 -0
  24. package/dist/{chunk-kxwa347f.js → chunk-3qms4nax.js} +2 -2
  25. package/dist/{chunk-kxwa347f.js.map → chunk-3qms4nax.js.map} +3 -3
  26. package/dist/{chunk-emyyk7dx.js → chunk-5c7ga8zz.js} +22 -145
  27. package/dist/chunk-5c7ga8zz.js.map +12 -0
  28. package/dist/{chunk-hpr1r6av.js → chunk-5p1v802y.js} +46 -39
  29. package/dist/{chunk-hpr1r6av.js.map → chunk-5p1v802y.js.map} +4 -4
  30. package/dist/{chunk-zcnq6105.js → chunk-85cd7e8c.js} +2 -1
  31. package/dist/chunk-85cd7e8c.js.map +10 -0
  32. package/dist/{chunk-1enhpacz.js → chunk-976rxdpx.js} +5 -5
  33. package/dist/{chunk-3f7veca0.js → chunk-9x8dybsb.js} +3 -3
  34. package/dist/chunk-9x8dybsb.js.map +10 -0
  35. package/dist/{chunk-r29fxdhn.js → chunk-aa6z4a19.js} +160 -44
  36. package/dist/chunk-aa6z4a19.js.map +12 -0
  37. package/dist/{chunk-r4tfx1sf.js → chunk-agbbygvh.js} +4 -4
  38. package/dist/{chunk-jjy0fhrn.js → chunk-b0ec55a1.js} +20 -3
  39. package/dist/chunk-b0ec55a1.js.map +12 -0
  40. package/dist/{chunk-xfbydgzy.js → chunk-bn138h9w.js} +7 -8
  41. package/dist/{chunk-xfbydgzy.js.map → chunk-bn138h9w.js.map} +3 -3
  42. package/dist/{chunk-an5tt9y0.js → chunk-ftv470j8.js} +42 -4
  43. package/dist/{chunk-an5tt9y0.js.map → chunk-ftv470j8.js.map} +7 -7
  44. package/dist/{chunk-0w35wavj.js → chunk-g7knyczr.js} +1 -1
  45. package/dist/{chunk-x57ycxq0.js → chunk-gqh45d2n.js} +42 -3
  46. package/dist/{chunk-x57ycxq0.js.map → chunk-gqh45d2n.js.map} +3 -3
  47. package/dist/{chunk-0rdrecsb.js → chunk-kfee1h52.js} +116 -32
  48. package/dist/chunk-kfee1h52.js.map +13 -0
  49. package/dist/{chunk-ypbtykv6.js → chunk-nmbxcaqx.js} +1 -1
  50. package/dist/{chunk-3tgwrcyh.js → chunk-nt99sxd6.js} +2 -2
  51. package/dist/{chunk-3tgwrcyh.js.map → chunk-nt99sxd6.js.map} +3 -3
  52. package/dist/{chunk-vf691g1r.js → chunk-p5vcsw9c.js} +2 -2
  53. package/dist/{chunk-mjbk2djy.js → chunk-p6a4npdx.js} +211 -106
  54. package/dist/{chunk-mjbk2djy.js.map → chunk-p6a4npdx.js.map} +9 -8
  55. package/dist/{chunk-3frsnm7x.js → chunk-qma80ych.js} +4 -6
  56. package/dist/chunk-qma80ych.js.map +11 -0
  57. package/dist/{chunk-qhcpj9wc.js → chunk-qyeptdyv.js} +96 -2
  58. package/dist/chunk-qyeptdyv.js.map +15 -0
  59. package/dist/{chunk-52hbv0ak.js → chunk-r7fj830t.js} +101 -48
  60. package/dist/chunk-r7fj830t.js.map +36 -0
  61. package/dist/{chunk-xyr8kppc.js → chunk-rtk71jzp.js} +1 -1
  62. package/dist/{chunk-m3z3x9v0.js → chunk-t1f4f1ve.js} +1 -1
  63. package/dist/chunk-v2vcg0w6.js +151 -0
  64. package/dist/chunk-v2vcg0w6.js.map +11 -0
  65. package/dist/connectors/connections/authorizations.d.ts.map +1 -1
  66. package/dist/connectors/connections/contracts.d.ts +3 -0
  67. package/dist/connectors/connections/contracts.d.ts.map +1 -1
  68. package/dist/connectors/connections/internal.js +1 -1
  69. package/dist/connectors/connections/request.d.ts +3 -1
  70. package/dist/connectors/connections/request.d.ts.map +1 -1
  71. package/dist/connectors/connections/runs.d.ts.map +1 -1
  72. package/dist/connectors/connections/tokens.d.ts.map +1 -1
  73. package/dist/connectors/connections/validation.d.ts +5 -1
  74. package/dist/connectors/connections/validation.d.ts.map +1 -1
  75. package/dist/connectors/types.d.ts +19 -4
  76. package/dist/connectors/types.d.ts.map +1 -1
  77. package/dist/events/execution.d.ts +1 -1
  78. package/dist/events/execution.d.ts.map +1 -1
  79. package/dist/events/index.js +1 -1
  80. package/dist/events/service.d.ts +2 -2
  81. package/dist/events/service.d.ts.map +1 -1
  82. package/dist/execution/agent.js +16 -15
  83. package/dist/execution/agent.js.map +1 -1
  84. package/dist/execution/primitive.js +16 -15
  85. package/dist/execution/primitive.js.map +2 -2
  86. package/dist/execution/request.js +16 -15
  87. package/dist/execution/request.js.map +2 -2
  88. package/dist/index.d.ts +3 -3
  89. package/dist/index.d.ts.map +1 -1
  90. package/dist/index.js +30 -28
  91. package/dist/index.js.map +1 -1
  92. package/dist/lake-storage/changes.d.ts +5 -0
  93. package/dist/lake-storage/changes.d.ts.map +1 -0
  94. package/dist/lake-storage/in-memory.d.ts +2 -1
  95. package/dist/lake-storage/in-memory.d.ts.map +1 -1
  96. package/dist/lake-storage/index.d.ts +2 -1
  97. package/dist/lake-storage/index.d.ts.map +1 -1
  98. package/dist/lake-storage/index.js +4 -2
  99. package/dist/lake-storage/index.js.map +1 -1
  100. package/dist/lake-storage/types.d.ts +36 -0
  101. package/dist/lake-storage/types.d.ts.map +1 -1
  102. package/dist/logging/internal.js +1 -1
  103. package/dist/materialization/index.d.ts +1 -1
  104. package/dist/materialization/index.d.ts.map +1 -1
  105. package/dist/materialization/model.d.ts +12 -1
  106. package/dist/materialization/model.d.ts.map +1 -1
  107. package/dist/materializer/index.d.ts +1 -1
  108. package/dist/materializer/index.d.ts.map +1 -1
  109. package/dist/materializer/index.js +5 -5
  110. package/dist/materializer/materializer.d.ts +5 -1
  111. package/dist/materializer/materializer.d.ts.map +1 -1
  112. package/dist/materializer/projections/entry-validator.d.ts +2 -1
  113. package/dist/materializer/projections/entry-validator.d.ts.map +1 -1
  114. package/dist/materializer/projections/replace.d.ts.map +1 -1
  115. package/dist/materializer/projections/source-materialization.d.ts +4 -3
  116. package/dist/materializer/projections/source-materialization.d.ts.map +1 -1
  117. package/dist/materializer/shared/normalize.d.ts +2 -1
  118. package/dist/materializer/shared/normalize.d.ts.map +1 -1
  119. package/dist/models/execution/index.js +5 -5
  120. package/dist/objects/index.js +9 -9
  121. package/dist/objects/query/index.js +5 -5
  122. package/dist/pipelines/index.js +6 -6
  123. package/dist/pipelines/run-dispatch.d.ts.map +1 -1
  124. package/dist/projections/internal.js +6 -8
  125. package/dist/projections/internal.js.map +1 -1
  126. package/dist/projections/run-dispatch.d.ts.map +1 -1
  127. package/dist/queues/in-memory.d.ts +7 -3
  128. package/dist/queues/in-memory.d.ts.map +1 -1
  129. package/dist/queues/index.js +1 -1
  130. package/dist/queues/indexed-heap.d.ts +15 -0
  131. package/dist/queues/indexed-heap.d.ts.map +1 -0
  132. package/dist/runtime/host.d.ts.map +1 -1
  133. package/dist/runtime/internal.js +1 -1
  134. package/dist/runtime/ontology-mutations.d.ts +3 -1
  135. package/dist/runtime/ontology-mutations.d.ts.map +1 -1
  136. package/dist/shares/internal.js +4 -4
  137. package/dist/storage/connector-connections/in-memory.d.ts.map +1 -1
  138. package/dist/storage/connector-connections/provider/runs.d.ts.map +1 -1
  139. package/dist/storage/connector-connections/provider.js +2 -2
  140. package/dist/storage/connector-connections/provider.js.map +3 -3
  141. package/dist/storage/connector-connections/types.d.ts +3 -2
  142. package/dist/storage/connector-connections/types.d.ts.map +1 -1
  143. package/dist/storage/index.d.ts +1 -1
  144. package/dist/storage/index.d.ts.map +1 -1
  145. package/dist/storage/index.js +4 -4
  146. package/dist/storage/internal.js +1 -1
  147. package/dist/storage/ontology/in-memory/materializations-state.d.ts.map +1 -1
  148. package/dist/storage/ontology/in-memory/materializations.d.ts +1 -1
  149. package/dist/storage/ontology/in-memory/materializations.d.ts.map +1 -1
  150. package/dist/storage/ontology/in-memory/shared-state.d.ts +15 -2
  151. package/dist/storage/ontology/in-memory/shared-state.d.ts.map +1 -1
  152. package/dist/storage/ontology/in-memory/source-roots.d.ts +6 -0
  153. package/dist/storage/ontology/in-memory/source-roots.d.ts.map +1 -0
  154. package/dist/storage/ontology/in-memory/sources.d.ts.map +1 -1
  155. package/dist/storage/ontology/index.d.ts +1 -1
  156. package/dist/storage/ontology/index.d.ts.map +1 -1
  157. package/dist/storage/ontology/provider.d.ts +16 -0
  158. package/dist/storage/ontology/provider.d.ts.map +1 -1
  159. package/dist/storage/ontology/provider.js +4 -2
  160. package/dist/storage/ontology/provider.js.map +1 -1
  161. package/dist/storage/ontology/sources.d.ts +13 -4
  162. package/dist/storage/ontology/sources.d.ts.map +1 -1
  163. package/dist/storage/projection-runs/lifecycle.d.ts.map +1 -1
  164. package/dist/storage/projection-runs/provider.js +2 -2
  165. package/dist/storage/projection-runs/types.d.ts +2 -0
  166. package/dist/storage/projection-runs/types.d.ts.map +1 -1
  167. package/dist/syncs/index.js +8 -7
  168. package/dist/syncs/index.js.map +1 -1
  169. package/dist/syncs/run-dispatch.d.ts.map +1 -1
  170. package/dist/testing/broker-contract.d.ts.map +1 -1
  171. package/dist/testing/connector-connection-storage-contract.d.ts.map +1 -1
  172. package/dist/testing/index.d.ts +1 -0
  173. package/dist/testing/index.d.ts.map +1 -1
  174. package/dist/testing/index.js +1459 -951
  175. package/dist/testing/index.js.map +9 -8
  176. package/dist/testing/lake-changes-contract.d.ts +6 -0
  177. package/dist/testing/lake-changes-contract.d.ts.map +1 -0
  178. package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
  179. package/dist/testing/ontology-storage-contract.d.ts.map +1 -1
  180. package/dist/testing/projection-run-storage-contract.d.ts.map +1 -1
  181. package/dist/webhooks/connections.d.ts +6 -0
  182. package/dist/webhooks/connections.d.ts.map +1 -0
  183. package/dist/webhooks/index.d.ts +1 -1
  184. package/dist/webhooks/index.d.ts.map +1 -1
  185. package/dist/webhooks/internal.d.ts +2 -0
  186. package/dist/webhooks/internal.d.ts.map +1 -1
  187. package/dist/webhooks/internal.js +54 -9
  188. package/dist/webhooks/internal.js.map +4 -3
  189. package/dist/webhooks/registry.d.ts +1 -1
  190. package/dist/webhooks/registry.d.ts.map +1 -1
  191. package/dist/webhooks/types.d.ts +15 -4
  192. package/dist/webhooks/types.d.ts.map +1 -1
  193. package/dist/workflows/index.js +17 -16
  194. package/dist/workflows/index.js.map +1 -1
  195. package/dist/workflows/run-dispatch.d.ts +3 -1
  196. package/dist/workflows/run-dispatch.d.ts.map +1 -1
  197. package/package.json +1 -1
  198. package/src/broker/in-memory.ts +104 -39
  199. package/src/broker/index.ts +4 -1
  200. package/src/broker/retention.ts +28 -0
  201. package/src/broker/subscriber.ts +21 -0
  202. package/src/broker/types.ts +15 -1
  203. package/src/connectors/builders.ts +0 -6
  204. package/src/connectors/connections/authorizations.ts +11 -5
  205. package/src/connectors/connections/contracts.ts +3 -0
  206. package/src/connectors/connections/request.ts +56 -22
  207. package/src/connectors/connections/runs.ts +1 -0
  208. package/src/connectors/connections/tokens.ts +4 -0
  209. package/src/connectors/connections/validation.ts +91 -5
  210. package/src/connectors/types.ts +19 -4
  211. package/src/events/execution.ts +2 -2
  212. package/src/events/service.ts +3 -3
  213. package/src/index.ts +10 -2
  214. package/src/lake-storage/changes.ts +43 -0
  215. package/src/lake-storage/in-memory.ts +73 -0
  216. package/src/lake-storage/index.ts +4 -0
  217. package/src/lake-storage/types.ts +40 -0
  218. package/src/logging/service.ts +1 -1
  219. package/src/materialization/index.ts +2 -0
  220. package/src/materialization/model.ts +14 -1
  221. package/src/materializer/index.ts +2 -0
  222. package/src/materializer/materializer.ts +10 -0
  223. package/src/materializer/projections/entry-validator.ts +19 -1
  224. package/src/materializer/projections/replace.ts +36 -1
  225. package/src/materializer/projections/source-materialization.ts +26 -6
  226. package/src/materializer/shared/normalize.ts +1 -1
  227. package/src/pipelines/run-dispatch.ts +21 -1
  228. package/src/projections/run-dispatch.ts +30 -68
  229. package/src/queues/in-memory.ts +105 -62
  230. package/src/queues/indexed-heap.ts +74 -0
  231. package/src/runtime/host.ts +0 -14
  232. package/src/runtime/ontology-mutations.ts +4 -0
  233. package/src/storage/connector-connections/in-memory.ts +3 -1
  234. package/src/storage/connector-connections/provider/runs.ts +3 -1
  235. package/src/storage/connector-connections/types.ts +3 -2
  236. package/src/storage/index.ts +1 -0
  237. package/src/storage/ontology/in-memory/materializations-state.ts +5 -18
  238. package/src/storage/ontology/in-memory/materializations.ts +73 -92
  239. package/src/storage/ontology/in-memory/shared-state.ts +26 -1
  240. package/src/storage/ontology/in-memory/source-roots.ts +123 -0
  241. package/src/storage/ontology/in-memory/sources.ts +78 -23
  242. package/src/storage/ontology/index.ts +1 -0
  243. package/src/storage/ontology/provider.ts +70 -0
  244. package/src/storage/ontology/sources.ts +14 -3
  245. package/src/storage/projection-runs/lifecycle.ts +5 -2
  246. package/src/storage/projection-runs/types.ts +4 -3
  247. package/src/syncs/run-dispatch.ts +19 -1
  248. package/src/testing/broker-contract.ts +95 -0
  249. package/src/testing/connector-connection-storage-contract.ts +18 -1
  250. package/src/testing/index.ts +1 -0
  251. package/src/testing/lake-changes-contract.ts +240 -0
  252. package/src/testing/materializer-storage-contract.ts +172 -1
  253. package/src/testing/ontology-storage-contract.ts +7 -0
  254. package/src/testing/projection-run-storage-contract.ts +34 -0
  255. package/src/webhooks/connections.ts +56 -0
  256. package/src/webhooks/index.ts +2 -0
  257. package/src/webhooks/internal.ts +2 -0
  258. package/src/webhooks/registry.ts +3 -4
  259. package/src/webhooks/types.ts +17 -4
  260. package/src/workflows/run-dispatch.ts +42 -29
  261. package/dist/chunk-0rdrecsb.js.map +0 -11
  262. package/dist/chunk-3f7veca0.js.map +0 -10
  263. package/dist/chunk-3frsnm7x.js.map +0 -11
  264. package/dist/chunk-52hbv0ak.js.map +0 -36
  265. package/dist/chunk-emyyk7dx.js.map +0 -14
  266. package/dist/chunk-jjy0fhrn.js.map +0 -12
  267. package/dist/chunk-k3cqkkn2.js.map +0 -12
  268. package/dist/chunk-ppytyr6w.js.map +0 -12
  269. package/dist/chunk-qhcpj9wc.js.map +0 -14
  270. package/dist/chunk-r29fxdhn.js.map +0 -11
  271. package/dist/chunk-zcnq6105.js.map +0 -10
  272. /package/dist/{chunk-h1gfhhbh.js.map → chunk-28ja2cjs.js.map} +0 -0
  273. /package/dist/{chunk-1enhpacz.js.map → chunk-976rxdpx.js.map} +0 -0
  274. /package/dist/{chunk-r4tfx1sf.js.map → chunk-agbbygvh.js.map} +0 -0
  275. /package/dist/{chunk-0w35wavj.js.map → chunk-g7knyczr.js.map} +0 -0
  276. /package/dist/{chunk-ypbtykv6.js.map → chunk-nmbxcaqx.js.map} +0 -0
  277. /package/dist/{chunk-vf691g1r.js.map → chunk-p5vcsw9c.js.map} +0 -0
  278. /package/dist/{chunk-xyr8kppc.js.map → chunk-rtk71jzp.js.map} +0 -0
  279. /package/dist/{chunk-m3z3x9v0.js.map → chunk-t1f4f1ve.js.map} +0 -0
@@ -1,7 +1,6 @@
1
1
  // @bun
2
2
  import {
3
3
  createSixbError2,
4
- isSixbError2,
5
4
  toSixbFailure2
6
5
  } from "./chunk-f4w3yp4f.js";
7
6
  import {
@@ -9,82 +8,19 @@ import {
9
8
  } from "./chunk-7apz6hg4.js";
10
9
  import {
11
10
  resolveExecutionScopeAuthorization,
12
- AuthorizationError2,
13
- assertAuthorized2,
14
- assertProviderAccess2
11
+ assertAuthorized2
15
12
  } from "./chunk-dz5h08xv.js";
16
13
  import {
17
14
  SYNC_RUN_FAILURE_CODES2
18
- } from "./chunk-mjbk2djy.js";
15
+ } from "./chunk-p6a4npdx.js";
19
16
  import {
20
17
  SyncRunError2
21
18
  } from "./chunk-jmfet9r4.js";
22
- import {
23
- isOAuthConnectorDefinition2
24
- } from "./chunk-3f7veca0.js";
25
19
  import {
26
20
  executionRecordInputFromRuntime,
27
21
  ensureExecutionRecord2,
28
22
  createPrimitiveExecutionRecord
29
23
  } from "./chunk-17kfctj6.js";
30
- import {
31
- ConnectorConnectionStorageError2
32
- } from "./chunk-2c4j899j.js";
33
-
34
- // src/connectors/errors.ts
35
- class ConnectorError2 extends Error {
36
- name = "ConnectorError";
37
- }
38
-
39
- class ConnectorNotFoundError2 extends ConnectorError2 {
40
- connectorId;
41
- name = "ConnectorNotFoundError";
42
- constructor(connectorId) {
43
- super(`Unknown connector '${connectorId}'`);
44
- this.connectorId = connectorId;
45
- }
46
- }
47
-
48
- class ConnectorOAuthError2 extends ConnectorError2 {
49
- kind;
50
- name = "ConnectorOAuthError";
51
- constructor(kind, message, options) {
52
- super(message, options);
53
- this.kind = kind;
54
- }
55
- }
56
- function createConnectorCodedError(code, message, options = {}) {
57
- return createSixbError2(code, message.startsWith("[Sixb]") ? message : `[Sixb] ${message}`, options);
58
- }
59
- function createAmbiguousProviderOperationError(options = {}) {
60
- return createConnectorCodedError("connector.provider_failed", "Connector provider operation outcome is ambiguous.", options);
61
- }
62
- function oauthErrorKind(error) {
63
- return error instanceof ConnectorOAuthError2 ? error.kind : "ambiguous";
64
- }
65
- function providerFailureCode(error) {
66
- return oauthErrorKind(error) === "retryable" ? "connector.provider_unavailable" : "connector.provider_failed";
67
- }
68
- function providerBoundaryError(error, code, message) {
69
- if (isSixbError2(error) && error.code.startsWith("connector."))
70
- return error;
71
- return createConnectorCodedError(code, message, { cause: error });
72
- }
73
- function isConnectorStorageError(error, code) {
74
- return error instanceof ConnectorConnectionStorageError2 && (code === undefined || error.code === code);
75
- }
76
- function storageBoundaryError(error, message) {
77
- return createConnectorCodedError("internal.unexpected", message, { cause: error });
78
- }
79
- async function recoverConnectorFailure(primaryError, message, recovery) {
80
- try {
81
- return await recovery();
82
- } catch (recoveryError) {
83
- throw createConnectorCodedError("internal.unexpected", message, {
84
- cause: new AggregateError([primaryError, recoveryError], message)
85
- });
86
- }
87
- }
88
24
 
89
25
  // src/syncs/errors.ts
90
26
  class SyncValidationError2 extends Error {
@@ -129,7 +65,10 @@ class SyncRunDispatcher2 {
129
65
  }
130
66
  async function dispatchSyncRun(input) {
131
67
  const runId = createSyncRunId(input.runId);
132
- const persisted = await persistSyncRun(input, runId);
68
+ let persisted = await persistSyncRun(input, runId);
69
+ if (!persisted.publish && input.validateExistingRun && persisted.run.status === "queued") {
70
+ persisted = await reuseSyncRun(input, persisted.run);
71
+ }
133
72
  if (!persisted.publish)
134
73
  return existingSyncRunResult(persisted.run);
135
74
  return publishSyncRun(input, persisted);
@@ -178,6 +117,15 @@ async function persistSyncRun(input, runId) {
178
117
  async function reuseSyncRun(input, existing) {
179
118
  assertExistingRunMatchesRequest(existing, input);
180
119
  await input.validateExistingRun?.(existing, input.storage);
120
+ if (input.validateExistingRun && existing.status === "queued") {
121
+ const execution = await input.storage.executions.getById({
122
+ projectId: input.projectId,
123
+ id: existing.executionId
124
+ });
125
+ if (!execution)
126
+ throw new SyncRunError2(`[Sixb] Execution '${existing.executionId}' was not found.`);
127
+ return { publish: true, run: existing, execution, queuedAt: existing.queuedAt, created: false };
128
+ }
181
129
  if (existing.status !== "failed" || existing.error?.code !== "queue.enqueue_failed" || !existing.error.retryable) {
182
130
  return { publish: false, run: existing };
183
131
  }
@@ -215,6 +163,9 @@ async function publishSyncRun(input, persisted) {
215
163
  }
216
164
  ]
217
165
  });
166
+ if (!job || job.id !== persisted.run.id) {
167
+ throw new SyncRunError2(`[Sixb] Queue did not acknowledge Sync run '${persisted.run.id}'.`);
168
+ }
218
169
  return {
219
170
  syncId: persisted.run.syncId,
220
171
  runId: persisted.run.id,
@@ -223,6 +174,8 @@ async function publishSyncRun(input, persisted) {
223
174
  created: persisted.created
224
175
  };
225
176
  } catch (error) {
177
+ if (input.validateExistingRun)
178
+ throw error;
226
179
  const failedAt = new Date;
227
180
  const failure = toEnqueueFailure(error, persisted.run, failedAt);
228
181
  const failed = await requireSyncRunStorage(input.storage).finish({
@@ -325,82 +278,6 @@ async function requestSyncRun2(runtime, execution, sync, options = {}) {
325
278
  });
326
279
  }
327
280
 
328
- // src/connectors/execution.ts
329
- var sourceResolvers = new WeakMap;
330
- function createConnectorRuntime(runtime, execution, service) {
331
- const connector = (definition, selector) => {
332
- if (isOAuthConnectorDefinition2(definition)) {
333
- assertConnectorConnectionAccess(runtime, execution);
334
- if (!selector) {
335
- throw createConnectorCodedError("connector.configuration_invalid", `[Sixb] Connector '${definition.id}' uses persistent connections and requires an explicit owner and slot.`);
336
- }
337
- return service.connectConnection(definition, selector);
338
- }
339
- if (selector) {
340
- throw createConnectorCodedError("connector.configuration_invalid", `[Sixb] Static connector '${definition.id}' does not accept a connection.`);
341
- }
342
- assertProviderAccess2(runtime, execution, "connector.connect");
343
- return service.connect(definition);
344
- };
345
- registerConnectorExecutionSourceResolver(connector, {
346
- async list(definition) {
347
- if (!isOAuthConnectorDefinition2(definition)) {
348
- return [
349
- {
350
- connect: (_signal) => connector(definition)
351
- }
352
- ];
353
- }
354
- assertConnectorConnectionAccess(runtime, execution);
355
- const connections = await service.listExecutionConnections(definition);
356
- return connections.map((connection) => ({
357
- connection: {
358
- id: connection.id,
359
- connectorId: connection.connectorId,
360
- owner: connection.owner,
361
- slot: connection.slot,
362
- account: connection.account
363
- },
364
- connect: (signal) => service.connectExecutionConnection(definition, connection, signal)
365
- }));
366
- }
367
- });
368
- return connector;
369
- }
370
- function registerConnectorExecutionSourceResolver(connector, resolver) {
371
- const registered = sourceResolvers.get(connector);
372
- if (registered && registered !== resolver) {
373
- throw new Error("[Sixb] Connector source resolver is already registered for this execution.");
374
- }
375
- sourceResolvers.set(connector, resolver);
376
- }
377
- function getConnectorExecutionSourceResolver(connector) {
378
- const resolver = sourceResolvers.get(connector);
379
- if (resolver)
380
- return resolver;
381
- return {
382
- async list(definition) {
383
- if (isOAuthConnectorDefinition2(definition)) {
384
- throw createConnectorCodedError("connector.configuration_invalid", `[Sixb] OAuth connector '${definition.id}' cannot be resolved without the managed connection runtime.`);
385
- }
386
- return [
387
- {
388
- connect: (_signal) => connector(definition)
389
- }
390
- ];
391
- }
392
- };
393
- }
394
- function assertConnectorConnectionAccess(runtime, execution) {
395
- const resolved = resolveExecutionScopeAuthorization(runtime.projectId, {
396
- execution,
397
- authorization: runtime.runtimeAuthorization
398
- });
399
- if (resolved.type === "unrestricted" && resolved.ref.type === "trustedPrimitive")
400
- return;
401
- throw new AuthorizationError2("privileged:connector-connection.connect", "[Sixb] Connector connection clients are restricted to trusted primitive executions.");
402
- }
403
-
404
- export { ConnectorError2, ConnectorNotFoundError2, ConnectorOAuthError2, createConnectorCodedError, createAmbiguousProviderOperationError, oauthErrorKind, providerFailureCode, providerBoundaryError, isConnectorStorageError, storageBoundaryError, recoverConnectorFailure, createConnectorRuntime, getConnectorExecutionSourceResolver, SyncValidationError2, SyncRunDispatcher2, requestSyncRun2 };
281
+ export { SyncValidationError2, SyncRunDispatcher2, requestSyncRun2 };
405
282
 
406
- //# debugId=98A5F7B5136CE1F764756E2164756E21
283
+ //# debugId=145F9F0BA5C3020C64756E2164756E21
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/syncs/errors.ts", "../src/syncs/run-dispatch.ts", "../src/syncs/request.ts"],
4
+ "sourcesContent": [
5
+ "export class SyncValidationError extends Error {\n readonly name = \"SyncValidationError\"\n}\n",
6
+ "import { randomUUID } from \"node:crypto\"\nimport { reportRunFailure } from \"../error-reporting/capability\"\nimport { createSixbError, toSixbFailure } from \"../errors/internal\"\nimport type { SixbFailure } from \"../errors/types\"\nimport type { RunDispatcher } from \"../execution/dispatch\"\nimport { createPrimitiveExecutionRecord } from \"../execution/durable\"\nimport type { Queues } from \"../queues\"\nimport type { SixbDefinitions } from \"../runtime/definitions\"\nimport type { CreateExecutionInput, Storage, SyncRunFailureCode, SyncRunRecord } from \"../storage\"\nimport { SYNC_RUN_FAILURE_CODES, SyncRunError } from \"../storage\"\nimport { SyncValidationError } from \"./errors\"\nimport type { SyncRunRequestOptions, SyncRunRequestResult } from \"./request\"\nimport type { SyncDefinition } from \"./types\"\n\nexport type AutomaticSyncExecutionSource =\n | { readonly type: \"schedule\"; readonly eventId: string }\n | { readonly type: \"event\"; readonly eventId: string }\n\nexport interface AutomaticSyncRunDispatchInput extends SyncRunRequestOptions {\n readonly syncId: string\n readonly runId: string\n readonly source: AutomaticSyncExecutionSource\n readonly correlationId: string\n readonly metadata?: Readonly<Record<string, string>>\n}\n\nexport type SyncRunDispatchPort = RunDispatcher<AutomaticSyncRunDispatchInput, SyncRunRequestResult>\n\nexport interface SyncRunDispatcherDependencies {\n readonly id: string\n readonly definitions: Pick<SixbDefinitions, \"syncs\">\n readonly storage: Storage\n readonly queues: Pick<Queues, \"syncRuns\">\n}\n\ninterface DispatchSyncRunInput extends SyncRunRequestOptions {\n readonly errorReporterHost: object\n readonly projectId: string\n readonly sync: SyncDefinition\n readonly storage: Storage\n readonly queue: Queues[\"syncRuns\"]\n readonly metadata?: Readonly<Record<string, string>>\n readonly createExecution: (executionId: string, runId: string) => Promise<CreateExecutionInput>\n readonly validateExistingRun?: (run: SyncRunRecord, storage: Storage) => Promise<void>\n}\n\ntype PersistedSyncRun =\n | { readonly publish: false; readonly run: SyncRunRecord }\n | {\n readonly publish: true\n readonly run: SyncRunRecord\n readonly execution: CreateExecutionInput\n readonly queuedAt: Date\n readonly created: boolean\n }\n\n/** Core-owned durable dispatch boundary used by automatic Sync triggers. */\nexport class SyncRunDispatcher implements SyncRunDispatchPort {\n constructor(private readonly dependencies: SyncRunDispatcherDependencies) {}\n\n async dispatch(input: AutomaticSyncRunDispatchInput): Promise<SyncRunRequestResult> {\n assertAutomaticDispatchInput(input)\n const sync = this.dependencies.definitions.syncs.getById(input.syncId)\n if (!sync) throw new SyncValidationError(`[Sixb] Unknown sync '${input.syncId}'`)\n\n return dispatchSyncRun({\n errorReporterHost: this.dependencies,\n projectId: this.dependencies.id,\n sync,\n storage: this.dependencies.storage,\n queue: this.dependencies.queues.syncRuns,\n runId: input.runId,\n expectedLatestVersionId: input.expectedLatestVersionId,\n commitMessage: input.commitMessage,\n metadata: input.metadata,\n validateExistingRun: (run, storage) =>\n assertAutomaticExecutionIdentity(storage, this.dependencies.id, input, run),\n createExecution: async (executionId, runId) =>\n createPrimitiveExecutionRecord({\n id: executionId,\n primitive: { kind: \"sync\", id: sync.id, runId },\n origin: {\n type: \"automatic\",\n projectId: this.dependencies.id,\n source: input.source,\n correlationId: input.correlationId,\n },\n }),\n })\n }\n}\n\n/** Persist a Sync execution and queued run before publishing its queue job. */\nexport async function dispatchSyncRun(input: DispatchSyncRunInput): Promise<SyncRunRequestResult> {\n const runId = createSyncRunId(input.runId)\n let persisted = await persistSyncRun(input, runId)\n if (!persisted.publish && input.validateExistingRun && persisted.run.status === \"queued\") {\n persisted = await reuseSyncRun(input, persisted.run)\n }\n if (!persisted.publish) return existingSyncRunResult(persisted.run)\n return publishSyncRun(input, persisted)\n}\n\nasync function persistSyncRun(\n input: DispatchSyncRunInput,\n runId: string\n): Promise<PersistedSyncRun> {\n const syncRuns = requireSyncRunStorage(input.storage)\n const existing = await syncRuns.getById({ projectId: input.projectId, id: runId })\n if (existing) return reuseSyncRun(input, existing)\n\n const execution = await input.createExecution(`exec_${randomUUID()}`, runId)\n const queuedAt = new Date()\n try {\n return await input.storage.transaction(\n async (tx): Promise<PersistedSyncRun> => {\n const transactionalRuns = requireSyncRunStorage(tx)\n const raced = await transactionalRuns.getById({ projectId: input.projectId, id: runId })\n if (raced) {\n assertExistingRunMatchesRequest(raced, input)\n await input.validateExistingRun?.(raced, tx)\n return { publish: false, run: raced }\n }\n\n await tx.executions.create(execution)\n const run = await transactionalRuns.queue({\n projectId: input.projectId,\n id: runId,\n executionId: execution.id,\n syncId: input.sync.id,\n datasetId: input.sync.target.dataset.id,\n mode: input.sync.config.mode,\n queuedAt,\n expectedLatestVersionId: input.expectedLatestVersionId,\n commitMessage: input.commitMessage,\n })\n return { publish: true, run, execution, queuedAt, created: true }\n },\n { isolation: \"serializable\" }\n )\n } catch (error) {\n if (!(error instanceof SyncRunError)) throw error\n const raced = await syncRuns.getById({ projectId: input.projectId, id: runId })\n if (!raced) throw error\n assertExistingRunMatchesRequest(raced, input)\n await input.validateExistingRun?.(raced, input.storage)\n return { publish: false, run: raced }\n }\n}\n\nasync function reuseSyncRun(\n input: DispatchSyncRunInput,\n existing: SyncRunRecord\n): Promise<PersistedSyncRun> {\n assertExistingRunMatchesRequest(existing, input)\n await input.validateExistingRun?.(existing, input.storage)\n if (input.validateExistingRun && existing.status === \"queued\") {\n const execution = await input.storage.executions.getById({\n projectId: input.projectId,\n id: existing.executionId,\n })\n if (!execution)\n throw new SyncRunError(`[Sixb] Execution '${existing.executionId}' was not found.`)\n return { publish: true, run: existing, execution, queuedAt: existing.queuedAt, created: false }\n }\n if (\n existing.status !== \"failed\" ||\n existing.error?.code !== \"queue.enqueue_failed\" ||\n !existing.error.retryable\n ) {\n return { publish: false, run: existing }\n }\n\n const execution = await input.storage.executions.getById({\n projectId: input.projectId,\n id: existing.executionId,\n })\n if (!execution) {\n throw new SyncRunError(\n `[Sixb] Execution '${existing.executionId}' for Sync run '${existing.id}' was not found.`\n )\n }\n\n const queuedAt = new Date()\n const run = await requireSyncRunStorage(input.storage).queue({\n projectId: input.projectId,\n id: existing.id,\n executionId: existing.executionId,\n syncId: existing.syncId,\n datasetId: existing.datasetId,\n mode: existing.mode,\n queuedAt,\n expectedLatestVersionId: existing.expectedLatestVersionId,\n commitMessage: existing.commitMessage,\n })\n return { publish: true, run, execution, queuedAt, created: false }\n}\n\nasync function publishSyncRun(\n input: DispatchSyncRunInput,\n persisted: Extract<PersistedSyncRun, { readonly publish: true }>\n): Promise<SyncRunRequestResult> {\n try {\n const [job] = await input.queue.enqueue({\n projectId: input.projectId,\n jobs: [\n {\n id: persisted.run.id,\n type: \"sync.run.requested\",\n payload: { runId: persisted.run.id },\n ...(input.metadata === undefined ? {} : { metadata: input.metadata }),\n },\n ],\n })\n if (!job || job.id !== persisted.run.id) {\n throw new SyncRunError(`[Sixb] Queue did not acknowledge Sync run '${persisted.run.id}'.`)\n }\n return {\n syncId: persisted.run.syncId,\n runId: persisted.run.id,\n queuedAt: persisted.queuedAt.toISOString(),\n ...(job?.id ? { jobId: job.id } : {}),\n created: persisted.created,\n }\n } catch (error) {\n // Automatic consumers retain the batch and retry. Keep uncertain delivery queued:\n // a lost reply does not prove that the queue rejected the job.\n if (input.validateExistingRun) throw error\n const failedAt = new Date()\n const failure = toEnqueueFailure(error, persisted.run, failedAt)\n const failed = await requireSyncRunStorage(input.storage).finish({\n projectId: input.projectId,\n id: persisted.run.id,\n status: \"failed\",\n finishedAt: failedAt,\n error: failure,\n })\n reportRunFailure(input.errorReporterHost, error, {\n projectId: input.projectId,\n runKind: \"sync\",\n run: { runId: failed.id, syncId: failed.syncId },\n failure,\n })\n throw error\n }\n}\n\nfunction assertExistingRunMatchesRequest(\n existing: SyncRunRecord,\n input: Pick<DispatchSyncRunInput, \"sync\" | \"expectedLatestVersionId\" | \"commitMessage\">\n): void {\n if (\n existing.syncId !== input.sync.id ||\n existing.datasetId !== input.sync.target.dataset.id ||\n existing.mode !== input.sync.config.mode ||\n existing.expectedLatestVersionId !== input.expectedLatestVersionId ||\n existing.commitMessage !== input.commitMessage\n ) {\n throw new SyncRunError(\n `[Sixb] Sync run '${existing.id}' already exists with a different request payload.`\n )\n }\n}\n\nfunction existingSyncRunResult(existing: SyncRunRecord): SyncRunRequestResult {\n return {\n syncId: existing.syncId,\n runId: existing.id,\n queuedAt: existing.queuedAt.toISOString(),\n created: false,\n }\n}\n\nfunction requireSyncRunStorage(storage: Storage): NonNullable<Storage[\"syncRuns\"]> {\n if (!storage.syncRuns) throw new SyncValidationError(\"[Sixb] Sync run storage is not configured.\")\n return storage.syncRuns\n}\n\nfunction createSyncRunId(runId: string | undefined): string {\n if (runId === undefined) return `run_${randomUUID()}`\n if (!runId.trim()) throw new SyncValidationError(\"[Sixb] Sync run id must not be empty\")\n return runId\n}\n\nfunction assertAutomaticDispatchInput(input: AutomaticSyncRunDispatchInput): void {\n assertNonBlank(input.syncId, \"Sync id\")\n assertNonBlank(input.runId, \"Sync run id\")\n assertNonBlank(input.source.eventId, \"Sync source event id\")\n assertNonBlank(input.correlationId, \"Sync correlation id\")\n}\n\nasync function assertAutomaticExecutionIdentity(\n storage: Storage,\n projectId: string,\n input: AutomaticSyncRunDispatchInput,\n run: SyncRunRecord\n): Promise<void> {\n const execution = await storage.executions.getById({ projectId, id: run.executionId })\n if (\n !execution ||\n execution.source.type !== input.source.type ||\n execution.source.eventId !== input.source.eventId ||\n execution.correlationId !== input.correlationId ||\n execution.requestedBy !== undefined\n ) {\n throw new SyncValidationError(\n `[Sixb] Sync run '${run.id}' already exists with different automatic provenance.`\n )\n }\n}\n\nfunction toEnqueueFailure(\n error: unknown,\n run: SyncRunRecord,\n at: Date\n): SixbFailure<SyncRunFailureCode> {\n const enqueueError = createSixbError(\n \"queue.enqueue_failed\",\n `[Sixb] Could not enqueue Sync run '${run.id}'.`,\n {\n cause: error,\n details: { syncId: run.syncId, runId: run.id, phase: \"enqueue\" },\n }\n )\n return toSixbFailure(enqueueError, { allowedCodes: SYNC_RUN_FAILURE_CODES, at })\n}\n\nfunction assertNonBlank(value: string, label: string): void {\n if (!value.trim()) throw new SyncValidationError(`[Sixb] ${label} must not be empty.`)\n}\n",
7
+ "import { assertAuthorized } from \"../authorization\"\nimport { resolveExecutionScopeAuthorization } from \"../execution/authorization\"\nimport {\n createPrimitiveExecutionRecord,\n ensureExecutionRecord,\n executionRecordInputFromRuntime,\n} from \"../execution/durable\"\nimport type { ExecutionContext } from \"../execution/types\"\nimport type { SixbRuntimeContext } from \"../runtime/types\"\nimport { SyncValidationError } from \"./errors\"\nimport { dispatchSyncRun } from \"./run-dispatch\"\nimport type { SyncDefinition } from \"./types\"\n\nexport interface SyncRunRequestOptions {\n /** Stable identity used to make dispatch idempotent. */\n readonly runId?: string\n /** Optimistic concurrency guard: fail the run if the dataset moved past this version. */\n readonly expectedLatestVersionId?: string\n readonly commitMessage?: string\n}\n\nexport interface RequestSyncRunInput extends SyncRunRequestOptions {\n readonly syncId: string\n}\n\nexport interface SyncRunRequestResult {\n readonly syncId: string\n readonly runId: string\n /** Durable time at which the run entered the queue. */\n readonly queuedAt: string\n readonly jobId?: string\n readonly created: boolean\n}\n\n/**\n * Authorize and queue a sync run request.\n *\n * Operates on an already-resolved definition and the shared runtime context, so the HTTP route and\n * the runtime verb cannot drift apart.\n *\n * The immutable child execution and queued run are persisted before queue publication.\n */\nexport async function requestSyncRun(\n runtime: SixbRuntimeContext,\n execution: ExecutionContext,\n sync: SyncDefinition,\n options: SyncRunRequestOptions = {}\n): Promise<SyncRunRequestResult> {\n resolveExecutionScopeAuthorization(runtime.projectId, {\n execution,\n authorization: runtime.runtimeAuthorization,\n })\n assertAuthorized(runtime, { kind: \"sync.run\", syncId: sync.id })\n if (!runtime.storage.syncRuns) {\n throw new SyncValidationError(\"[Sixb] Sync run storage is not configured.\")\n }\n\n const queue = runtime.queues.syncRuns\n if (!queue) {\n throw new SyncValidationError(\"[Sixb] Sync run queue is not configured.\")\n }\n\n return dispatchSyncRun({\n errorReporterHost: runtime,\n projectId: runtime.projectId,\n sync,\n storage: runtime.storage,\n queue,\n ...options,\n createExecution: async (executionId, runId) => {\n const caller = await ensureExecutionRecord(\n runtime.storage.executions,\n executionRecordInputFromRuntime({\n execution,\n runtimeAuthorization: runtime.runtimeAuthorization,\n })\n )\n return createPrimitiveExecutionRecord({\n id: executionId,\n primitive: { kind: \"sync\", id: sync.id, runId },\n origin: { type: \"execution\", parent: caller },\n })\n },\n })\n}\n"
8
+ ],
9
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAO,MAAM,6BAA4B,MAAM;AAAA,EACpC,OAAO;AAClB;;;ACFA;AAyDO,MAAM,mBAAiD;AAAA,EAC/B;AAAA,EAA7B,WAAW,CAAkB,cAA6C;AAAA,IAA7C;AAAA;AAAA,OAEvB,SAAQ,CAAC,OAAqE;AAAA,IAClF,6BAA6B,KAAK;AAAA,IAClC,MAAM,OAAO,KAAK,aAAa,YAAY,MAAM,QAAQ,MAAM,MAAM;AAAA,IACrE,IAAI,CAAC;AAAA,MAAM,MAAM,IAAI,qBAAoB,wBAAwB,MAAM,SAAS;AAAA,IAEhF,OAAO,gBAAgB;AAAA,MACrB,mBAAmB,KAAK;AAAA,MACxB,WAAW,KAAK,aAAa;AAAA,MAC7B;AAAA,MACA,SAAS,KAAK,aAAa;AAAA,MAC3B,OAAO,KAAK,aAAa,OAAO;AAAA,MAChC,OAAO,MAAM;AAAA,MACb,yBAAyB,MAAM;AAAA,MAC/B,eAAe,MAAM;AAAA,MACrB,UAAU,MAAM;AAAA,MAChB,qBAAqB,CAAC,KAAK,YACzB,iCAAiC,SAAS,KAAK,aAAa,IAAI,OAAO,GAAG;AAAA,MAC5E,iBAAiB,OAAO,aAAa,UACnC,+BAA+B;AAAA,QAC7B,IAAI;AAAA,QACJ,WAAW,EAAE,MAAM,QAAQ,IAAI,KAAK,IAAI,MAAM;AAAA,QAC9C,QAAQ;AAAA,UACN,M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G,MAAM,IAAI,qBAAoB,UAAU,0BAA0B;AAAA;;;AC9RvF,eAAsB,eAAc,CAClC,SACA,WACA,MACA,UAAiC,CAAC,GACH;AAAA,EAC/B,mCAAmC,QAAQ,WAAW;AAAA,IACpD;AAAA,IACA,eAAe,QAAQ;AAAA,EACzB,CAAC;AAAA,EACD,kBAAiB,SAAS,EAAE,MAAM,YAAY,QAAQ,KAAK,GAAG,CAAC;AAAA,EAC/D,IAAI,CAAC,QAAQ,QAAQ,UAAU;AAAA,IAC7B,MAAM,IAAI,qBAAoB,4CAA4C;AAAA,EAC5E;AAAA,EAEA,MAAM,QAAQ,QAAQ,OAAO;AAAA,EAC7B,IAAI,CAAC,OAAO;AAAA,IACV,MAAM,IAAI,qBAAoB,0CAA0C;AAAA,EAC1E;AAAA,EAEA,OAAO,gBAAgB;AAAA,IACrB,mBAAmB;AAAA,IACnB,WAAW,QAAQ;AAAA,IACnB;AAAA,IACA,SAAS,QAAQ;AAAA,IACjB;AAAA,OACG;AAAA,IACH,iBAAiB,OAAO,aAAa,UAAU;AAAA,MAC7C,MAAM,SAAS,MAAM,uBACnB,QAAQ,QAAQ,YAChB,gCAAgC;AAAA,QAC9B;AAAA,QACA,sBAAsB,QAAQ;AAAA,MAChC,CAAC,CACH;AAAA,MACA,OAAO,+BAA+B;AAAA,QACpC,IAAI;AAAA,QACJ,WAAW,EAAE,MAAM,QAAQ,IAAI,KAAK,IAAI,MAAM;AAAA,QAC9C,QAAQ,EAAE,MAAM,aAAa,QAAQ,OAAO;AAAA,MAC9C,CAAC;AAAA;AAAA,EAEL,CAAC;AAAA;",
10
+ "debugId": "145F9F0BA5C3020C64756E2164756E21",
11
+ "names": []
12
+ }
@@ -60,7 +60,7 @@ import {
60
60
  } from "./chunk-93csa55g.js";
61
61
  import {
62
62
  WORKFLOW_RUN_FAILURE_CODES2
63
- } from "./chunk-mjbk2djy.js";
63
+ } from "./chunk-p6a4npdx.js";
64
64
  import {
65
65
  WorkflowRunError2
66
66
  } from "./chunk-pr2h4bv4.js";
@@ -70,7 +70,7 @@ import {
70
70
  canDelegationAccessActionRun,
71
71
  requestAction3,
72
72
  requestActionAndWait2
73
- } from "./chunk-ypbtykv6.js";
73
+ } from "./chunk-nmbxcaqx.js";
74
74
  import {
75
75
  shareSixbErrorReporter2,
76
76
  reportRunFailure2
@@ -92,19 +92,21 @@ import {
92
92
  registerConnectorConnectionsRuntime
93
93
  } from "./chunk-5a4a52tq.js";
94
94
  import {
95
- createConnectorRuntime,
96
- SyncValidationError2,
97
- requestSyncRun2
98
- } from "./chunk-emyyk7dx.js";
95
+ createConnectorRuntime
96
+ } from "./chunk-v2vcg0w6.js";
99
97
  import {
100
98
  writeDataset2
101
99
  } from "./chunk-mrp7k0pw.js";
102
100
  import {
103
101
  shareOntologyMutationRuntime2
104
- } from "./chunk-zcnq6105.js";
102
+ } from "./chunk-85cd7e8c.js";
105
103
  import {
106
104
  compileShareAccessPlan
107
105
  } from "./chunk-awbhdqyc.js";
106
+ import {
107
+ SyncValidationError2,
108
+ requestSyncRun2
109
+ } from "./chunk-5c7ga8zz.js";
108
110
  import {
109
111
  getTelemetryHistoryBatch2,
110
112
  getLatestTelemetryPoint,
@@ -116,14 +118,14 @@ import {
116
118
  upsertObject3,
117
119
  upsertObjectBatch3,
118
120
  appendTelemetry
119
- } from "./chunk-1enhpacz.js";
121
+ } from "./chunk-976rxdpx.js";
120
122
  import {
121
123
  schemaRecordToJsonSchema2
122
124
  } from "./chunk-7zgecwy1.js";
123
125
  import {
124
126
  PipelineError2,
125
127
  requestPipelineRun2
126
- } from "./chunk-jjy0fhrn.js";
128
+ } from "./chunk-b0ec55a1.js";
127
129
  import {
128
130
  requireAccountingCapabilities,
129
131
  aiModelCallOutputTokenAllowance,
@@ -131,7 +133,7 @@ import {
131
133
  AiModelCallRecorder2,
132
134
  enqueueAiModelCallRecovery2,
133
135
  resolveLanguageModel2
134
- } from "./chunk-h1gfhhbh.js";
136
+ } from "./chunk-28ja2cjs.js";
135
137
  import {
136
138
  getDatasetPrimaryKeyColumns2
137
139
  } from "./chunk-9qsh3p5y.js";
@@ -1160,7 +1162,7 @@ function createEventsRuntime(runtime) {
1160
1162
  return runtime.events.subscribe(input, (events) => {
1161
1163
  const visible = visibleEvents(events);
1162
1164
  if (visible.length > 0)
1163
- handler(visible);
1165
+ return handler(visible);
1164
1166
  });
1165
1167
  }
1166
1168
  };
@@ -3397,7 +3399,7 @@ class WorkflowRunDispatcher2 {
3397
3399
  if (!workflow) {
3398
3400
  throw new WorkflowValidationError2(`[Sixb] Unknown workflow '${input.workflowId}'`);
3399
3401
  }
3400
- const result = await dispatchWorkflowRun({
3402
+ return dispatchWorkflowRun({
3401
3403
  errorReporterHost: this.dependencies,
3402
3404
  projectId: this.dependencies.id,
3403
3405
  workflow,
@@ -3415,6 +3417,7 @@ class WorkflowRunDispatcher2 {
3415
3417
  },
3416
3418
  metadata: input.metadata,
3417
3419
  queueJobId: input.runId,
3420
+ validateExistingRun: (run) => assertAutomaticExecutionIdentity(this.dependencies, input, run),
3418
3421
  createExecution: async (executionId, runId) => createPrimitiveExecutionRecord({
3419
3422
  id: executionId,
3420
3423
  primitive: { kind: "workflow", id: workflow.id, runId },
@@ -3426,17 +3429,18 @@ class WorkflowRunDispatcher2 {
3426
3429
  }
3427
3430
  })
3428
3431
  });
3429
- if (!result.created) {
3430
- await assertAutomaticExecutionIdentity(this.dependencies, input, result.runId);
3431
- }
3432
- return result;
3433
3432
  }
3434
3433
  }
3435
3434
  async function dispatchWorkflowRun(input) {
3436
3435
  const request = prepareWorkflowRun(input);
3437
3436
  const persisted = await persistWorkflowRun(input, request);
3438
- if (!persisted.created)
3437
+ if (!persisted.created) {
3438
+ await input.validateExistingRun?.(persisted.run);
3439
+ if (input.validateExistingRun && persisted.run.status === "queued") {
3440
+ await enqueueWorkflowRun(input, persisted.run);
3441
+ }
3439
3442
  return existingWorkflowRunResult(persisted.run);
3443
+ }
3440
3444
  return publishWorkflowRun(input, persisted);
3441
3445
  }
3442
3446
  function prepareWorkflowRun(input) {
@@ -3505,20 +3509,10 @@ async function persistWorkflowRun(input, request) {
3505
3509
  async function publishWorkflowRun(input, persisted) {
3506
3510
  let job;
3507
3511
  try {
3508
- const jobs = await input.queue.enqueue({
3509
- projectId: input.projectId,
3510
- jobs: [
3511
- {
3512
- ...input.queueJobId === undefined ? {} : { id: input.queueJobId },
3513
- type: "workflow.run.requested",
3514
- payload: { runId: persisted.run.id },
3515
- ...input.metadata === undefined ? {} : { metadata: input.metadata }
3516
- }
3517
- ]
3518
- });
3519
- job = jobs[0];
3512
+ job = await enqueueWorkflowRun(input, persisted.run);
3520
3513
  } catch (error) {
3521
- await failWorkflowRunPublication(input, persisted.run, error);
3514
+ if (!input.validateExistingRun)
3515
+ await failWorkflowRunPublication(input, persisted.run, error);
3522
3516
  throw error;
3523
3517
  }
3524
3518
  await input.events.emit({
@@ -3544,6 +3538,23 @@ async function publishWorkflowRun(input, persisted) {
3544
3538
  created: true
3545
3539
  };
3546
3540
  }
3541
+ async function enqueueWorkflowRun(input, run) {
3542
+ const [job] = await input.queue.enqueue({
3543
+ projectId: input.projectId,
3544
+ jobs: [
3545
+ {
3546
+ ...input.queueJobId === undefined ? {} : { id: input.queueJobId },
3547
+ type: "workflow.run.requested",
3548
+ payload: { runId: run.id },
3549
+ ...input.metadata === undefined ? {} : { metadata: input.metadata }
3550
+ }
3551
+ ]
3552
+ });
3553
+ if (!job || input.queueJobId !== undefined && job.id !== input.queueJobId) {
3554
+ throw new WorkflowRunError2(`[Sixb] Queue did not acknowledge workflow run '${run.id}'.`);
3555
+ }
3556
+ return job;
3557
+ }
3547
3558
  async function failWorkflowRunPublication(input, run, error) {
3548
3559
  const workflowRuns = input.storage.workflowRuns;
3549
3560
  if (!workflowRuns) {
@@ -3595,17 +3606,13 @@ function assertAutomaticDispatchInput(input) {
3595
3606
  assertNonBlank(input.source.eventId, "Workflow source event id");
3596
3607
  assertNonBlank(input.correlationId, "Workflow correlation id");
3597
3608
  }
3598
- async function assertAutomaticExecutionIdentity(dependencies, input, runId) {
3599
- const run = await dependencies.storage.workflowRuns?.getById({
3600
- projectId: dependencies.id,
3601
- id: runId
3602
- });
3603
- const execution = run ? await dependencies.storage.executions.getById({
3609
+ async function assertAutomaticExecutionIdentity(dependencies, input, run) {
3610
+ const execution = await dependencies.storage.executions.getById({
3604
3611
  projectId: dependencies.id,
3605
3612
  id: run.executionId
3606
- }) : null;
3613
+ });
3607
3614
  if (!execution || execution.source.type !== input.source.type || execution.source.eventId !== input.source.eventId || execution.correlationId !== input.correlationId || execution.requestedBy !== undefined) {
3608
- throw new WorkflowValidationError2(`[Sixb] Workflow run '${runId}' already exists with different automatic provenance.`);
3615
+ throw new WorkflowValidationError2(`[Sixb] Workflow run '${run.id}' already exists with different automatic provenance.`);
3609
3616
  }
3610
3617
  }
3611
3618
  function assertNonBlank(value, label) {
@@ -4003,4 +4010,4 @@ function invalidAgentExecution(executionId, runId) {
4003
4010
 
4004
4011
  export { resolveAgentContextParts2, agentRunQueueJobId2, subagentRunQueueJobId2, workflowAgentNodeQueueJobId2, dispatchQueuedAgentRuns2, dispatchQueuedSubagentRuns2, createAgentThreadId2, createAgentRunId2, createSubagentRunId2, createSubagentExecutionId2, createAgentMessageId2, agentContextCheckpointId2, createAgentRunExecutionToken2, runModelLoop2, assertNoAgentDefinitions, bindModelExecutionAttempt, ShareError2, WorkflowDefinitionError2, WorkflowValidationError2, assertNonEmpty, isStepDefinition2, isAgentStepDefinition2, isInterventionDefinition2, isWorkflowDefinition2, validateWorkflowDefinition2, validateWorkflowsAtStartup2, validateWorkflowAgentStepGroupReferences2, validateWorkflowInput2, validateWorkflowStepInput2, validateWorkflowStepOutput2, validateWorkflowInterventionInput2, validateWorkflowInterventionResponse2, validateWorkflowInterventionDefaultResponse2, validateWorkflowAgentStepInput2, validateWorkflowAgentStepOutput2, snapshotWorkflowAgentStepInput2, snapshotWorkflowAgentStepOutput2, snapshotWorkflowInput2, snapshotWorkflowStepInput2, snapshotWorkflowStepOutput2, snapshotWorkflowInterventionInput2, snapshotWorkflowInterventionResponse2, snapshotWorkflowInterventionDefaultResponse2, snapshotWorkflowActionInput2, WorkflowRunDispatcher2, requestWorkflowRun2, createBoundSixb, isBoundSixb, canInheritAgentRequestAuthorization2, createAgentExecutionRecord2, createInheritedAgentExecutionRecord2, bindDurableAgentExecution2, restoreAgentExecutionScope2, assertAgentExecutionRecord2, requestAgentRun2, retryAgentRun2 };
4005
4012
 
4006
- //# debugId=8A992C0F00F3BAC264756E2164756E21
4013
+ //# debugId=54032C3CC8C5EB0064756E2164756E21