@sixb/core 0.2.5 → 0.2.6

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 (385) hide show
  1. package/dist/actions/index.js +36 -35
  2. package/dist/actions/index.js.map +1 -1
  3. package/dist/actions/validation.d.ts.map +1 -1
  4. package/dist/agents/errors.d.ts +1 -1
  5. package/dist/agents/errors.d.ts.map +1 -1
  6. package/dist/agents/execution.d.ts +17 -2
  7. package/dist/agents/execution.d.ts.map +1 -1
  8. package/dist/agents/index.d.ts +2 -2
  9. package/dist/agents/index.d.ts.map +1 -1
  10. package/dist/agents/index.js +50 -44
  11. package/dist/agents/index.js.map +1 -1
  12. package/dist/agents/model-routing.d.ts +5 -2
  13. package/dist/agents/model-routing.d.ts.map +1 -1
  14. package/dist/agents/request.d.ts +45 -4
  15. package/dist/agents/request.d.ts.map +1 -1
  16. package/dist/agents/run-events.d.ts +4 -0
  17. package/dist/agents/run-events.d.ts.map +1 -1
  18. package/dist/agents/run-session-children.d.ts.map +1 -1
  19. package/dist/agents/run-turn.d.ts +9 -1
  20. package/dist/agents/run-turn.d.ts.map +1 -1
  21. package/dist/agents/streams/index.d.ts +1 -1
  22. package/dist/agents/streams/index.d.ts.map +1 -1
  23. package/dist/agents/streams/index.js +1 -1
  24. package/dist/agents/streams/internal.d.ts +2 -1
  25. package/dist/agents/streams/internal.d.ts.map +1 -1
  26. package/dist/agents/streams/internal.js +22 -2
  27. package/dist/agents/streams/internal.js.map +1 -1
  28. package/dist/agents/streams/protocol.d.ts +37 -0
  29. package/dist/agents/streams/protocol.d.ts.map +1 -1
  30. package/dist/agents/streams/steps.d.ts +24 -0
  31. package/dist/agents/streams/steps.d.ts.map +1 -0
  32. package/dist/agents/thread-access.d.ts +44 -2
  33. package/dist/agents/thread-access.d.ts.map +1 -1
  34. package/dist/artifacts/live/server.js +19 -18
  35. package/dist/artifacts/live/server.js.map +1 -1
  36. package/dist/artifacts/publish/index.js +18 -17
  37. package/dist/artifacts/publish/index.js.map +1 -1
  38. package/dist/artifacts/publish/merge.d.ts +2 -1
  39. package/dist/artifacts/publish/merge.d.ts.map +1 -1
  40. package/dist/artifacts/run-query.d.ts.map +1 -1
  41. package/dist/auth/index.js +6 -6
  42. package/dist/authorization/index.js +2 -2
  43. package/dist/bootstrap/index.js +40 -38
  44. package/dist/bootstrap/index.js.map +2 -2
  45. package/dist/calendar.d.ts +55 -0
  46. package/dist/calendar.d.ts.map +1 -0
  47. package/dist/calendar.js +19 -0
  48. package/dist/calendar.js.map +9 -0
  49. package/dist/{chunk-5a4a52tq.js → chunk-0pmpwn3g.js} +18 -2
  50. package/dist/chunk-0pmpwn3g.js.map +10 -0
  51. package/dist/{chunk-xcrnrpfh.js → chunk-394zjzjs.js} +20 -10
  52. package/dist/{chunk-xcrnrpfh.js.map → chunk-394zjzjs.js.map} +5 -5
  53. package/dist/{chunk-stmxh0hv.js → chunk-3neam1y5.js} +2 -2
  54. package/dist/{chunk-zeykm8my.js → chunk-3qtk0070.js} +16 -42
  55. package/dist/chunk-3qtk0070.js.map +14 -0
  56. package/dist/{chunk-0mvjpgvm.js → chunk-425ydk65.js} +4 -4
  57. package/dist/{chunk-s5pj68fa.js → chunk-5sswe5ej.js} +2 -2
  58. package/dist/chunk-6hfbz4d0.js +98 -0
  59. package/dist/chunk-6hfbz4d0.js.map +10 -0
  60. package/dist/{chunk-3zagkr6w.js → chunk-7mhbs9yy.js} +4 -4
  61. package/dist/{chunk-3zagkr6w.js.map → chunk-7mhbs9yy.js.map} +1 -1
  62. package/dist/{chunk-fpf57gca.js → chunk-7r9mqpva.js} +273 -66
  63. package/dist/{chunk-fpf57gca.js.map → chunk-7r9mqpva.js.map} +5 -5
  64. package/dist/{chunk-ewqn51gr.js → chunk-88xeh6zx.js} +6 -4
  65. package/dist/{chunk-ewqn51gr.js.map → chunk-88xeh6zx.js.map} +4 -4
  66. package/dist/chunk-90nqenq8.js +386 -0
  67. package/dist/chunk-90nqenq8.js.map +14 -0
  68. package/dist/{chunk-gjhrz66x.js → chunk-9c9yknwt.js} +247 -20
  69. package/dist/{chunk-gjhrz66x.js.map → chunk-9c9yknwt.js.map} +6 -6
  70. package/dist/{chunk-q9nkpr8k.js → chunk-9tpmfh3n.js} +1 -1
  71. package/dist/chunk-9wr3yajk.js.map +2 -2
  72. package/dist/{chunk-z1njfqqs.js → chunk-ats8y3d9.js} +721 -156
  73. package/dist/{chunk-z1njfqqs.js.map → chunk-ats8y3d9.js.map} +13 -13
  74. package/dist/{chunk-68hm50qh.js → chunk-bcz9dxtf.js} +16 -46
  75. package/dist/chunk-bcz9dxtf.js.map +12 -0
  76. package/dist/{chunk-naxjka9v.js → chunk-brhp9d97.js} +2 -2
  77. package/dist/{chunk-8a8k38tz.js → chunk-brybqw5k.js} +1 -1
  78. package/dist/{chunk-s1mqyqmm.js → chunk-bs1sd0e0.js} +12 -8
  79. package/dist/chunk-bs1sd0e0.js.map +18 -0
  80. package/dist/{chunk-vehcr9eb.js → chunk-cg7cygfj.js} +1 -1
  81. package/dist/chunk-dq3t5sr3.js +114 -0
  82. package/dist/chunk-dq3t5sr3.js.map +11 -0
  83. package/dist/{chunk-r2psmn42.js → chunk-eg6xqef7.js} +1 -1
  84. package/dist/{chunk-zxhym8tr.js → chunk-f05994as.js} +1 -1
  85. package/dist/{chunk-5t9gm5tt.js → chunk-fmgf9h5e.js} +38 -14
  86. package/dist/chunk-fmgf9h5e.js.map +22 -0
  87. package/dist/{chunk-ey1p8w68.js → chunk-gaj8djsw.js} +80 -4
  88. package/dist/chunk-gaj8djsw.js.map +13 -0
  89. package/dist/{chunk-1yh6jgtz.js → chunk-grt2j5vp.js} +2 -2
  90. package/dist/{chunk-zft9bzbc.js → chunk-hkbks1xm.js} +2 -1
  91. package/dist/{chunk-zft9bzbc.js.map → chunk-hkbks1xm.js.map} +3 -3
  92. package/dist/{chunk-rtdrm592.js → chunk-htdzx40w.js} +2 -2
  93. package/dist/{chunk-bc3y6gff.js → chunk-jka26v8c.js} +1 -1
  94. package/dist/{chunk-m3qx2pns.js → chunk-jt012fxq.js} +28 -12
  95. package/dist/{chunk-m3qx2pns.js.map → chunk-jt012fxq.js.map} +5 -5
  96. package/dist/{chunk-k3jh8gsg.js → chunk-kft7mp7z.js} +20 -3
  97. package/dist/chunk-kft7mp7z.js.map +10 -0
  98. package/dist/{chunk-qavwr628.js → chunk-n1hbwc6y.js} +5 -6
  99. package/dist/chunk-n1hbwc6y.js.map +12 -0
  100. package/dist/chunk-nxysqbt0.js.map +2 -2
  101. package/dist/{chunk-pqvvqc65.js → chunk-pqj8vff9.js} +3 -3
  102. package/dist/{chunk-wqe9shx2.js → chunk-qbd282aa.js} +2 -2
  103. package/dist/{chunk-e91fmg6t.js → chunk-qsa7nw6f.js} +2 -1
  104. package/dist/{chunk-e91fmg6t.js.map → chunk-qsa7nw6f.js.map} +3 -3
  105. package/dist/{chunk-rg725hry.js → chunk-s8xxef60.js} +83 -33
  106. package/dist/{chunk-rg725hry.js.map → chunk-s8xxef60.js.map} +5 -5
  107. package/dist/{chunk-fzae1jpq.js → chunk-t19wjmnc.js} +5 -5
  108. package/dist/{chunk-paxabbqd.js → chunk-tapdssb5.js} +1 -1
  109. package/dist/{chunk-dhkc9b23.js → chunk-v8a1qjzp.js} +1 -1
  110. package/dist/{chunk-q8d9p0tb.js → chunk-wzcjhv54.js} +8 -1
  111. package/dist/{chunk-q8d9p0tb.js.map → chunk-wzcjhv54.js.map} +3 -3
  112. package/dist/{chunk-pc7kra3k.js → chunk-xavet0qs.js} +1 -1
  113. package/dist/{chunk-0hkdtwqk.js → chunk-xf76csps.js} +5 -5
  114. package/dist/{chunk-m9ketb51.js → chunk-ygvay56w.js} +1 -1
  115. package/dist/{chunk-b4escq4c.js → chunk-ykchk644.js} +6 -6
  116. package/dist/{chunk-k29n4176.js → chunk-ym1bqd98.js} +6 -6
  117. package/dist/connectors/connections/capability.d.ts +11 -0
  118. package/dist/connectors/connections/capability.d.ts.map +1 -1
  119. package/dist/connectors/connections/internal.d.ts +2 -1
  120. package/dist/connectors/connections/internal.d.ts.map +1 -1
  121. package/dist/connectors/connections/internal.js +8 -4
  122. package/dist/connectors/connections/internal.js.map +1 -1
  123. package/dist/connectors/connections/service.d.ts +9 -1
  124. package/dist/connectors/connections/service.d.ts.map +1 -1
  125. package/dist/connectors/execution.d.ts +7 -1
  126. package/dist/connectors/execution.d.ts.map +1 -1
  127. package/dist/connectors/service.d.ts +5 -1
  128. package/dist/connectors/service.d.ts.map +1 -1
  129. package/dist/deploy/types.d.ts +4 -1
  130. package/dist/deploy/types.d.ts.map +1 -1
  131. package/dist/events/execution.d.ts +8 -1
  132. package/dist/events/execution.d.ts.map +1 -1
  133. package/dist/events/types/syncs.d.ts +4 -0
  134. package/dist/events/types/syncs.d.ts.map +1 -1
  135. package/dist/execution/agent.js +37 -36
  136. package/dist/execution/agent.js.map +1 -1
  137. package/dist/execution/authorized-object-reader.d.ts +4 -0
  138. package/dist/execution/authorized-object-reader.d.ts.map +1 -1
  139. package/dist/execution/object-reader-ontology.d.ts +3 -0
  140. package/dist/execution/object-reader-ontology.d.ts.map +1 -1
  141. package/dist/execution/primitive.js +36 -35
  142. package/dist/execution/primitive.js.map +1 -1
  143. package/dist/execution/request.d.ts +1 -1
  144. package/dist/execution/request.d.ts.map +1 -1
  145. package/dist/execution/request.js +33 -32
  146. package/dist/execution/request.js.map +3 -3
  147. package/dist/http/api-routes.d.ts.map +1 -1
  148. package/dist/http/index.js +1 -1
  149. package/dist/index.d.ts +5 -5
  150. package/dist/index.d.ts.map +1 -1
  151. package/dist/index.js +61 -59
  152. package/dist/index.js.map +1 -1
  153. package/dist/maintenance/index.js +1 -1
  154. package/dist/materializer/index.js +22 -21
  155. package/dist/materializer/index.js.map +1 -1
  156. package/dist/models/audio/runtime.d.ts.map +1 -1
  157. package/dist/models/audio/types.d.ts +19 -0
  158. package/dist/models/audio/types.d.ts.map +1 -1
  159. package/dist/models/execution/index.js +20 -19
  160. package/dist/models/execution/index.js.map +1 -1
  161. package/dist/models/index.d.ts +1 -1
  162. package/dist/models/index.d.ts.map +1 -1
  163. package/dist/objects/index.js +36 -35
  164. package/dist/objects/index.js.map +1 -1
  165. package/dist/objects/query/executor.d.ts +3 -1
  166. package/dist/objects/query/executor.d.ts.map +1 -1
  167. package/dist/objects/query/explain.d.ts +3 -1
  168. package/dist/objects/query/explain.d.ts.map +1 -1
  169. package/dist/objects/query/index.d.ts +1 -1
  170. package/dist/objects/query/index.d.ts.map +1 -1
  171. package/dist/objects/query/index.js +19 -18
  172. package/dist/objects/query/index.js.map +1 -1
  173. package/dist/objects/query/link-query-clearance.d.ts +3 -0
  174. package/dist/objects/query/link-query-clearance.d.ts.map +1 -1
  175. package/dist/objects/query/links.d.ts +1 -1
  176. package/dist/objects/query/links.d.ts.map +1 -1
  177. package/dist/objects/query/validate.d.ts +17 -0
  178. package/dist/objects/query/validate.d.ts.map +1 -1
  179. package/dist/objects/sdk/runtime-query-executor.d.ts +1 -1
  180. package/dist/objects/sdk/runtime-query-executor.d.ts.map +1 -1
  181. package/dist/ontology/index.js +3 -3
  182. package/dist/ontology/internal.js +3 -3
  183. package/dist/pipelines/index.js +21 -20
  184. package/dist/pipelines/index.js.map +1 -1
  185. package/dist/projections/internal.js +20 -19
  186. package/dist/projections/internal.js.map +1 -1
  187. package/dist/queues/in-memory.d.ts +1 -1
  188. package/dist/queues/in-memory.d.ts.map +1 -1
  189. package/dist/runtime/host.d.ts.map +1 -1
  190. package/dist/runtime/internal.js +24 -23
  191. package/dist/runtime/internal.js.map +2 -2
  192. package/dist/runtime/locale.d.ts +0 -2
  193. package/dist/runtime/locale.d.ts.map +1 -1
  194. package/dist/runtime/sixb.d.ts.map +1 -1
  195. package/dist/sandboxes/auth.d.ts +26 -4
  196. package/dist/sandboxes/auth.d.ts.map +1 -1
  197. package/dist/sandboxes/index.d.ts +3 -1
  198. package/dist/sandboxes/index.d.ts.map +1 -1
  199. package/dist/sandboxes/index.js +5 -5
  200. package/dist/security/view-conditions.d.ts.map +1 -1
  201. package/dist/shares/internal.js +16 -15
  202. package/dist/shares/internal.js.map +2 -2
  203. package/dist/storage/agents/in-memory.d.ts +18 -1
  204. package/dist/storage/agents/in-memory.d.ts.map +1 -1
  205. package/dist/storage/agents/index.d.ts +1 -1
  206. package/dist/storage/agents/index.d.ts.map +1 -1
  207. package/dist/storage/agents/provider.d.ts +43 -9
  208. package/dist/storage/agents/provider.d.ts.map +1 -1
  209. package/dist/storage/agents/provider.js +18 -2
  210. package/dist/storage/agents/provider.js.map +1 -1
  211. package/dist/storage/agents/types.d.ts +136 -3
  212. package/dist/storage/agents/types.d.ts.map +1 -1
  213. package/dist/storage/ai-cost/analytics.d.ts +3 -2
  214. package/dist/storage/ai-cost/analytics.d.ts.map +1 -1
  215. package/dist/storage/ai-cost/provider.js +4 -3
  216. package/dist/storage/ai-cost/provider.js.map +1 -1
  217. package/dist/storage/ai-cost/types.d.ts +5 -1
  218. package/dist/storage/ai-cost/types.d.ts.map +1 -1
  219. package/dist/storage/artifacts/in-memory.d.ts.map +1 -1
  220. package/dist/storage/artifacts/record.d.ts +3 -1
  221. package/dist/storage/artifacts/record.d.ts.map +1 -1
  222. package/dist/storage/artifacts/types.d.ts +7 -0
  223. package/dist/storage/artifacts/types.d.ts.map +1 -1
  224. package/dist/storage/file-upload-sessions/provider.js +7 -7
  225. package/dist/storage/index.d.ts +2 -2
  226. package/dist/storage/index.d.ts.map +1 -1
  227. package/dist/storage/index.js +22 -21
  228. package/dist/storage/index.js.map +1 -1
  229. package/dist/storage/internal.js +8 -8
  230. package/dist/storage/operation-scope.d.ts.map +1 -1
  231. package/dist/storage/operation-scope.js +1 -1
  232. package/dist/storage/sync-runs/idempotency.d.ts.map +1 -1
  233. package/dist/storage/sync-runs/in-memory.d.ts +2 -1
  234. package/dist/storage/sync-runs/in-memory.d.ts.map +1 -1
  235. package/dist/storage/sync-runs/index.d.ts +1 -1
  236. package/dist/storage/sync-runs/index.d.ts.map +1 -1
  237. package/dist/storage/sync-runs/types.d.ts +27 -2
  238. package/dist/storage/sync-runs/types.d.ts.map +1 -1
  239. package/dist/storage/workflow-runs/provider.js +7 -7
  240. package/dist/syncs/accounts.d.ts +36 -0
  241. package/dist/syncs/accounts.d.ts.map +1 -0
  242. package/dist/syncs/builders.d.ts.map +1 -1
  243. package/dist/syncs/connections.d.ts +36 -0
  244. package/dist/syncs/connections.d.ts.map +1 -0
  245. package/dist/syncs/execution.d.ts +14 -4
  246. package/dist/syncs/execution.d.ts.map +1 -1
  247. package/dist/syncs/index.d.ts +2 -1
  248. package/dist/syncs/index.d.ts.map +1 -1
  249. package/dist/syncs/index.js +22 -21
  250. package/dist/syncs/index.js.map +1 -1
  251. package/dist/syncs/request.d.ts +16 -2
  252. package/dist/syncs/request.d.ts.map +1 -1
  253. package/dist/syncs/run-dispatch.d.ts +14 -2
  254. package/dist/syncs/run-dispatch.d.ts.map +1 -1
  255. package/dist/testing/agent-approval-storage-contract.d.ts.map +1 -1
  256. package/dist/testing/agent-inbox-storage-contract.d.ts.map +1 -1
  257. package/dist/testing/agent-storage-contract.d.ts.map +1 -1
  258. package/dist/testing/ai-cost-storage-contract.d.ts.map +1 -1
  259. package/dist/testing/artifact-storage-contract.d.ts.map +1 -1
  260. package/dist/testing/index.js +1051 -58
  261. package/dist/testing/index.js.map +8 -8
  262. package/dist/testing/run-claim-storage-contract.d.ts.map +1 -1
  263. package/dist/webhooks/internal.js +17 -16
  264. package/dist/webhooks/internal.js.map +2 -2
  265. package/dist/workers/index.js +66 -13
  266. package/dist/workers/index.js.map +4 -4
  267. package/dist/workers/queue-worker.d.ts +5 -0
  268. package/dist/workers/queue-worker.d.ts.map +1 -1
  269. package/dist/workers/worker.d.ts +8 -0
  270. package/dist/workers/worker.d.ts.map +1 -1
  271. package/dist/workflows/index.js +42 -40
  272. package/dist/workflows/index.js.map +1 -1
  273. package/package.json +7 -1
  274. package/src/actions/validation.ts +3 -1
  275. package/src/agents/children.ts +6 -0
  276. package/src/agents/errors.ts +3 -0
  277. package/src/agents/execution.ts +170 -20
  278. package/src/agents/index.ts +4 -0
  279. package/src/agents/model-routing.ts +25 -9
  280. package/src/agents/request.ts +759 -40
  281. package/src/agents/run-events.ts +235 -38
  282. package/src/agents/run-session-children.ts +13 -2
  283. package/src/agents/run-turn.ts +140 -23
  284. package/src/agents/streams/index.ts +2 -0
  285. package/src/agents/streams/internal.ts +12 -0
  286. package/src/agents/streams/protocol.ts +69 -1
  287. package/src/agents/streams/steps.ts +131 -0
  288. package/src/agents/thread-access.ts +57 -2
  289. package/src/artifacts/publish/merge.ts +14 -3
  290. package/src/artifacts/run-query.ts +5 -2
  291. package/src/calendar.ts +195 -0
  292. package/src/connectors/connections/capability.ts +40 -0
  293. package/src/connectors/connections/internal.ts +3 -0
  294. package/src/connectors/connections/service.ts +74 -5
  295. package/src/connectors/execution.ts +5 -6
  296. package/src/connectors/service.ts +23 -0
  297. package/src/deploy/types.ts +4 -1
  298. package/src/events/execution.ts +42 -2
  299. package/src/events/types/syncs.ts +4 -0
  300. package/src/execution/authorized-object-reader.ts +33 -5
  301. package/src/execution/object-reader-ontology.ts +6 -0
  302. package/src/execution/request.ts +1 -0
  303. package/src/http/api-routes.ts +8 -0
  304. package/src/index.ts +18 -2
  305. package/src/models/audio/runtime.ts +57 -14
  306. package/src/models/audio/types.ts +20 -0
  307. package/src/models/index.ts +1 -0
  308. package/src/objects/query/executor.ts +4 -0
  309. package/src/objects/query/explain.ts +5 -0
  310. package/src/objects/query/index.ts +1 -0
  311. package/src/objects/query/link-query-clearance.ts +4 -1
  312. package/src/objects/query/links.ts +5 -1
  313. package/src/objects/query/validate.ts +33 -1
  314. package/src/objects/sdk/runtime-query-executor.ts +7 -3
  315. package/src/runtime/host.ts +13 -7
  316. package/src/runtime/locale.ts +0 -10
  317. package/src/runtime/sixb.ts +12 -2
  318. package/src/sandboxes/README.md +3 -1
  319. package/src/sandboxes/auth.ts +32 -4
  320. package/src/sandboxes/index.ts +15 -1
  321. package/src/security/view-conditions.ts +2 -1
  322. package/src/storage/agents/in-memory.ts +271 -6
  323. package/src/storage/agents/index.ts +10 -0
  324. package/src/storage/agents/provider.ts +170 -13
  325. package/src/storage/agents/types.ts +148 -3
  326. package/src/storage/ai-cost/analytics.ts +22 -43
  327. package/src/storage/ai-cost/types.ts +5 -1
  328. package/src/storage/artifacts/in-memory.ts +20 -5
  329. package/src/storage/artifacts/record.ts +8 -2
  330. package/src/storage/artifacts/types.ts +7 -0
  331. package/src/storage/index.ts +11 -0
  332. package/src/storage/operation-scope.ts +1 -0
  333. package/src/storage/sync-runs/idempotency.ts +1 -0
  334. package/src/storage/sync-runs/in-memory.ts +43 -1
  335. package/src/storage/sync-runs/index.ts +1 -0
  336. package/src/storage/sync-runs/types.ts +30 -1
  337. package/src/syncs/accounts.ts +85 -0
  338. package/src/syncs/builders.ts +18 -1
  339. package/src/syncs/connections.ts +123 -0
  340. package/src/syncs/execution.ts +64 -22
  341. package/src/syncs/index.ts +3 -0
  342. package/src/syncs/request.ts +81 -23
  343. package/src/syncs/run-dispatch.ts +69 -7
  344. package/src/testing/agent-approval-storage-contract.ts +123 -0
  345. package/src/testing/agent-inbox-storage-contract.ts +59 -0
  346. package/src/testing/agent-storage-contract.ts +767 -8
  347. package/src/testing/ai-cost-storage-contract.ts +80 -0
  348. package/src/testing/artifact-storage-contract.ts +129 -0
  349. package/src/testing/run-claim-storage-contract.ts +116 -0
  350. package/src/workers/README.md +4 -1
  351. package/src/workers/lost-runs.ts +1 -0
  352. package/src/workers/queue-worker.ts +16 -5
  353. package/src/workers/worker.ts +67 -7
  354. package/dist/chunk-5a4a52tq.js.map +0 -10
  355. package/dist/chunk-5t9gm5tt.js.map +0 -22
  356. package/dist/chunk-68hm50qh.js.map +0 -13
  357. package/dist/chunk-aw1z0gre.js +0 -234
  358. package/dist/chunk-aw1z0gre.js.map +0 -12
  359. package/dist/chunk-ey1p8w68.js.map +0 -13
  360. package/dist/chunk-k3jh8gsg.js.map +0 -10
  361. package/dist/chunk-qavwr628.js.map +0 -12
  362. package/dist/chunk-s1mqyqmm.js.map +0 -18
  363. package/dist/chunk-zeykm8my.js.map +0 -14
  364. /package/dist/{chunk-stmxh0hv.js.map → chunk-3neam1y5.js.map} +0 -0
  365. /package/dist/{chunk-0mvjpgvm.js.map → chunk-425ydk65.js.map} +0 -0
  366. /package/dist/{chunk-s5pj68fa.js.map → chunk-5sswe5ej.js.map} +0 -0
  367. /package/dist/{chunk-q9nkpr8k.js.map → chunk-9tpmfh3n.js.map} +0 -0
  368. /package/dist/{chunk-naxjka9v.js.map → chunk-brhp9d97.js.map} +0 -0
  369. /package/dist/{chunk-8a8k38tz.js.map → chunk-brybqw5k.js.map} +0 -0
  370. /package/dist/{chunk-vehcr9eb.js.map → chunk-cg7cygfj.js.map} +0 -0
  371. /package/dist/{chunk-r2psmn42.js.map → chunk-eg6xqef7.js.map} +0 -0
  372. /package/dist/{chunk-zxhym8tr.js.map → chunk-f05994as.js.map} +0 -0
  373. /package/dist/{chunk-1yh6jgtz.js.map → chunk-grt2j5vp.js.map} +0 -0
  374. /package/dist/{chunk-rtdrm592.js.map → chunk-htdzx40w.js.map} +0 -0
  375. /package/dist/{chunk-bc3y6gff.js.map → chunk-jka26v8c.js.map} +0 -0
  376. /package/dist/{chunk-pqvvqc65.js.map → chunk-pqj8vff9.js.map} +0 -0
  377. /package/dist/{chunk-wqe9shx2.js.map → chunk-qbd282aa.js.map} +0 -0
  378. /package/dist/{chunk-fzae1jpq.js.map → chunk-t19wjmnc.js.map} +0 -0
  379. /package/dist/{chunk-paxabbqd.js.map → chunk-tapdssb5.js.map} +0 -0
  380. /package/dist/{chunk-dhkc9b23.js.map → chunk-v8a1qjzp.js.map} +0 -0
  381. /package/dist/{chunk-pc7kra3k.js.map → chunk-xavet0qs.js.map} +0 -0
  382. /package/dist/{chunk-0hkdtwqk.js.map → chunk-xf76csps.js.map} +0 -0
  383. /package/dist/{chunk-m9ketb51.js.map → chunk-ygvay56w.js.map} +0 -0
  384. /package/dist/{chunk-b4escq4c.js.map → chunk-ykchk644.js.map} +0 -0
  385. /package/dist/{chunk-k29n4176.js.map → chunk-ym1bqd98.js.map} +0 -0
@@ -8,27 +8,40 @@ import type {
8
8
  ListSyncRunsResult,
9
9
  SyncRunRecord,
10
10
  } from "../storage/sync-runs"
11
+ import { createSyncAccountsRuntime, type SyncAccountsRuntime } from "./accounts"
12
+ import { type SyncConnections, visibleSyncConnectionIds } from "./connections"
11
13
  import { SyncValidationError } from "./errors"
12
- import { type RequestSyncRunInput, requestSyncRun, type SyncRunRequestResult } from "./request"
14
+ import { type RequestSyncRunInput, requestSyncRun, type SyncRunRequestResults } from "./request"
13
15
  import type { SyncDefinition } from "./types"
14
16
 
17
+ /**
18
+ * The runs of the syncs you may run. On a sync of an OAuth connector, only the runs of the
19
+ * connections you may run as well: the project's and your own, or everyone's with `can.manage` on
20
+ * the connector.
21
+ */
15
22
  export interface SyncRunsRuntime {
16
23
  getById(runId: string): Promise<SyncRunRecord | null>
17
- list(input?: Omit<ListSyncRunsInput, "projectId" | "syncIds">): Promise<ListSyncRunsResult>
24
+ list(
25
+ input?: Omit<ListSyncRunsInput, "projectId" | "syncIds" | "visibleConnectionIds">
26
+ ): Promise<ListSyncRunsResult>
18
27
  listLatest(syncIds: readonly string[]): Promise<ListLatestSyncRunsResult>
19
28
  }
20
29
 
21
30
  export interface SyncsRuntime {
22
31
  list(): readonly SyncDefinition[]
23
32
  getById(syncId: string): SyncDefinition | null
24
- request(input: RequestSyncRunInput): Promise<SyncRunRequestResult>
33
+ /** Queue a run, or on a sync of an OAuth connector one run per connection the caller may run. */
34
+ request(input: RequestSyncRunInput): Promise<SyncRunRequestResults>
25
35
  readonly runs: SyncRunsRuntime
36
+ /** Where each connected account stands, on a sync of an OAuth connector. */
37
+ readonly accounts: SyncAccountsRuntime
26
38
  }
27
39
 
28
40
  export function createSyncsRuntime(
29
41
  runtime: SixbRuntimeContext,
30
42
  execution: ExecutionContext,
31
- source: Pick<SyncsRuntime, "list" | "getById">
43
+ source: Pick<SyncsRuntime, "list" | "getById">,
44
+ connections?: SyncConnections
32
45
  ): SyncsRuntime {
33
46
  const authority = resolveRuntimeAuthorizationForProject(runtime)
34
47
  const allowed = (syncId: string) => isRuntimeAllowed(runtime, { kind: "sync.run", syncId })
@@ -44,21 +57,34 @@ export function createSyncsRuntime(
44
57
  ? visibleIds()
45
58
  : []
46
59
 
60
+ const getById = (syncId: string) => {
61
+ if (authority.type === "denied" || authority.type === "delegated") return null
62
+ const sync = source.getById(syncId)
63
+ return sync && allowed(syncId) ? sync : null
64
+ }
65
+
66
+ const visibleConnectionIds = (syncs: readonly (SyncDefinition | null)[]) =>
67
+ visibleSyncConnectionIds(runtime, execution, syncs, connections)
68
+
47
69
  return {
48
70
  list: () =>
49
71
  authority.type === "denied" || authority.type === "delegated"
50
72
  ? []
51
73
  : source.list().filter((sync) => allowed(sync.id)),
52
- getById: (syncId) => {
53
- if (authority.type === "denied" || authority.type === "delegated") return null
54
- const sync = source.getById(syncId)
55
- return sync && allowed(syncId) ? sync : null
56
- },
74
+ getById,
75
+ accounts: createSyncAccountsRuntime({
76
+ runtime,
77
+ execution,
78
+ syncs: () => source.list(),
79
+ runnable: getById,
80
+ ...(connections === undefined ? {} : { connections }),
81
+ }),
57
82
  request: async (input) => {
58
83
  assertAuthorized(runtime, { kind: "sync.run", syncId: input.syncId })
59
84
  const sync = source.getById(input.syncId)
60
85
  if (!sync) throw new SyncValidationError(`[Sixb] Unknown sync '${input.syncId}'`)
61
- return requestSyncRun(runtime, execution, sync, input)
86
+ const { syncId: _syncId, ...options } = input
87
+ return requestSyncRun(runtime, execution, sync, options, connections)
62
88
  },
63
89
  runs: {
64
90
  getById: async (runId) => {
@@ -68,30 +94,46 @@ export function createSyncsRuntime(
68
94
  projectId: runtime.projectId,
69
95
  id: runId,
70
96
  })) ?? null
71
- return run && allowed(run.syncId) ? run : null
97
+ if (!run || !allowed(run.syncId)) return null
98
+
99
+ const visible = await visibleConnectionIds([source.getById(run.syncId)])
100
+ const hidden =
101
+ run.connectionId !== undefined && visible?.includes(run.connectionId) === false
102
+ return hidden ? null : run
72
103
  },
73
- list: (input = {}) => {
104
+ list: async (input = {}) => {
74
105
  if (authority.type === "denied" || authority.type === "delegated") {
75
- return Promise.resolve({ runs: [], hasMore: false, total: 0 })
106
+ return { runs: [], hasMore: false, total: 0 }
76
107
  }
77
108
  const storage = runtime.storage.syncRuns
78
- if (!storage) return Promise.resolve({ runs: [], hasMore: false, total: 0 })
109
+ if (!storage) return { runs: [], hasMore: false, total: 0 }
110
+
111
+ const syncs =
112
+ input.syncId === undefined
113
+ ? source.list().filter((sync) => allowed(sync.id))
114
+ : [getById(input.syncId)]
115
+ const visible = await visibleConnectionIds(syncs)
79
116
  return storage.list({
80
117
  ...input,
81
118
  syncIds: historyFilterIds(),
119
+ ...(visible === undefined ? {} : { visibleConnectionIds: visible }),
82
120
  projectId: runtime.projectId,
83
121
  })
84
122
  },
85
- listLatest: (syncIds) => {
86
- if (authority.type === "denied" || authority.type === "delegated") {
87
- return Promise.resolve({ runs: [] })
88
- }
123
+ listLatest: async (syncIds) => {
124
+ if (authority.type === "denied" || authority.type === "delegated") return { runs: [] }
89
125
  const storage = runtime.storage.syncRuns
90
- if (!storage || syncIds.length === 0) return Promise.resolve({ runs: [] })
91
126
  const allowedIds = syncIds.filter(allowed)
92
- return allowedIds.length === 0
93
- ? Promise.resolve({ runs: [] })
94
- : storage.listLatestBySyncIds({ projectId: runtime.projectId, syncIds: allowedIds })
127
+ if (!storage || allowedIds.length === 0) return { runs: [] }
128
+
129
+ const visible = await visibleConnectionIds(
130
+ allowedIds.map((syncId) => source.getById(syncId))
131
+ )
132
+ return storage.listLatestBySyncIds({
133
+ projectId: runtime.projectId,
134
+ syncIds: allowedIds,
135
+ ...(visible === undefined ? {} : { visibleConnectionIds: visible }),
136
+ })
95
137
  },
96
138
  },
97
139
  }
@@ -1,9 +1,12 @@
1
+ export type { SyncAccount, SyncAccountsRuntime } from "./accounts"
1
2
  export { defineSync } from "./builders"
2
3
  export { SyncValidationError } from "./errors"
3
4
  export type {
4
5
  RequestSyncRunInput,
6
+ RequestSyncRunOptions,
5
7
  SyncRunRequestOptions,
6
8
  SyncRunRequestResult,
9
+ SyncRunRequestResults,
7
10
  } from "./request"
8
11
  export { requestSyncRun } from "./request"
9
12
  export {
@@ -1,4 +1,5 @@
1
1
  import { assertAuthorized } from "../authorization"
2
+ import { isOAuthConnectorDefinition } from "../connectors"
2
3
  import { resolveExecutionScopeAuthorization } from "../execution/authorization"
3
4
  import {
4
5
  createPrimitiveExecutionRecord,
@@ -7,6 +8,7 @@ import {
7
8
  } from "../execution/durable"
8
9
  import type { ExecutionContext } from "../execution/types"
9
10
  import type { SixbRuntimeContext } from "../runtime/types"
11
+ import { mayRunConnection, type SyncConnections } from "./connections"
10
12
  import { SyncValidationError } from "./errors"
11
13
  import { dispatchSyncRun } from "./run-dispatch"
12
14
  import type { SyncDefinition } from "./types"
@@ -19,19 +21,34 @@ export interface SyncRunRequestOptions {
19
21
  readonly commitMessage?: string
20
22
  }
21
23
 
22
- export interface RequestSyncRunInput extends SyncRunRequestOptions {
24
+ export interface RequestSyncRunOptions extends SyncRunRequestOptions {
25
+ /**
26
+ * The one connection to run, on a sync of an OAuth connector. Without it, the request runs every
27
+ * connection the caller may run.
28
+ */
29
+ readonly connectionId?: string
30
+ }
31
+
32
+ export interface RequestSyncRunInput extends RequestSyncRunOptions {
23
33
  readonly syncId: string
24
34
  }
25
35
 
26
36
  export interface SyncRunRequestResult {
27
37
  readonly syncId: string
28
38
  readonly runId: string
39
+ /** The connection the run reads, on a sync of an OAuth connector. */
40
+ readonly connectionId?: string
29
41
  /** Durable time at which the run entered the queue. */
30
42
  readonly queuedAt: string
31
43
  readonly jobId?: string
32
44
  readonly created: boolean
33
45
  }
34
46
 
47
+ /** A static connector's sync queues one run; an OAuth connector's sync one per connection. */
48
+ export interface SyncRunRequestResults {
49
+ readonly runs: readonly SyncRunRequestResult[]
50
+ }
51
+
35
52
  /**
36
53
  * Authorize and queue a sync run request.
37
54
  *
@@ -44,8 +61,9 @@ export async function requestSyncRun(
44
61
  runtime: SixbRuntimeContext,
45
62
  execution: ExecutionContext,
46
63
  sync: SyncDefinition,
47
- options: SyncRunRequestOptions = {}
48
- ): Promise<SyncRunRequestResult> {
64
+ options: RequestSyncRunOptions = {},
65
+ connections?: SyncConnections
66
+ ): Promise<SyncRunRequestResults> {
49
67
  resolveExecutionScopeAuthorization(runtime.projectId, {
50
68
  execution,
51
69
  authorization: runtime.runtimeAuthorization,
@@ -60,26 +78,66 @@ export async function requestSyncRun(
60
78
  throw new SyncValidationError("[Sixb] Sync run queue is not configured.")
61
79
  }
62
80
 
63
- return dispatchSyncRun({
64
- errorReporterHost: runtime,
65
- projectId: runtime.projectId,
66
- sync,
67
- storage: runtime.storage,
68
- queue,
69
- ...options,
70
- createExecution: async (executionId, runId) => {
71
- const caller = await ensureExecutionRecord(
72
- runtime.storage.executions,
73
- executionRecordInputFromRuntime({
74
- execution,
75
- runtimeAuthorization: runtime.runtimeAuthorization,
81
+ const { connectionId, ...request } = options
82
+ const dispatch = (runId: string | undefined, connection?: string) =>
83
+ dispatchSyncRun({
84
+ errorReporterHost: runtime,
85
+ projectId: runtime.projectId,
86
+ sync,
87
+ storage: runtime.storage,
88
+ queue,
89
+ ...request,
90
+ ...(runId === undefined ? {} : { runId }),
91
+ // A run that has not started reads its connection when it starts: a request that arrives
92
+ // meanwhile, like a burst of a person's notifications, is already covered by it.
93
+ ...(connection === undefined ? {} : { connectionId: connection, joinQueuedRun: true }),
94
+ createExecution: async (executionId, queuedRunId) => {
95
+ const caller = await ensureExecutionRecord(
96
+ runtime.storage.executions,
97
+ executionRecordInputFromRuntime({
98
+ execution,
99
+ runtimeAuthorization: runtime.runtimeAuthorization,
100
+ })
101
+ )
102
+ return createPrimitiveExecutionRecord({
103
+ id: executionId,
104
+ primitive: { kind: "sync", id: sync.id, runId: queuedRunId },
105
+ origin: { type: "execution", parent: caller },
76
106
  })
107
+ },
108
+ })
109
+
110
+ if (!isOAuthConnectorDefinition(sync.connector)) {
111
+ if (connectionId !== undefined) {
112
+ throw new SyncValidationError(
113
+ `[Sixb] Sync '${sync.id}' reads static connector '${sync.connector.id}', which has no connections.`
77
114
  )
78
- return createPrimitiveExecutionRecord({
79
- id: executionId,
80
- primitive: { kind: "sync", id: sync.id, runId },
81
- origin: { type: "execution", parent: caller },
82
- })
83
- },
84
- })
115
+ }
116
+ return { runs: [await dispatch(request.runId)] }
117
+ }
118
+
119
+ if (!connections) {
120
+ throw new SyncValidationError(
121
+ `[Sixb] Sync '${sync.id}' reads OAuth connector '${sync.connector.id}', whose connections this runtime cannot list.`
122
+ )
123
+ }
124
+ const runnable = (await connections.list(sync.connector)).filter((connection) =>
125
+ mayRunConnection(runtime, execution, connection)
126
+ )
127
+
128
+ if (connectionId !== undefined) {
129
+ if (!runnable.some((connection) => connection.id === connectionId)) {
130
+ throw new SyncValidationError(
131
+ `[Sixb] Sync '${sync.id}' has no connection '${connectionId}' you can run.`
132
+ )
133
+ }
134
+ return { runs: [await dispatch(request.runId, connectionId)] }
135
+ }
136
+
137
+ const runs: SyncRunRequestResult[] = []
138
+ for (const connection of runnable) {
139
+ const runId = request.runId === undefined ? undefined : `${request.runId}:${connection.id}`
140
+ runs.push(await dispatch(runId, connection.id))
141
+ }
142
+ return { runs }
85
143
  }
@@ -1,3 +1,4 @@
1
+ import { isOAuthConnectorDefinition } from "../connectors"
1
2
  import { reportRunFailure } from "../error-reporting/capability"
2
3
  import { toSixbFailure } from "../errors/internal"
3
4
  import type { RunDispatcher } from "../execution/dispatch"
@@ -13,6 +14,7 @@ import {
13
14
  type QueuedRunStore,
14
15
  type RunPublication,
15
16
  } from "../workers/queued-run-dispatch"
17
+ import { findSyncConnections } from "./connections"
16
18
  import { SyncValidationError } from "./errors"
17
19
  import type { SyncRunRequestOptions, SyncRunRequestResult } from "./request"
18
20
  import type { SyncDefinition } from "./types"
@@ -27,9 +29,18 @@ export interface AutomaticSyncRunDispatchInput extends SyncRunRequestOptions {
27
29
  readonly source: AutomaticSyncExecutionSource
28
30
  readonly correlationId: string
29
31
  readonly metadata?: Readonly<Record<string, string>>
32
+ /**
33
+ * The connection the triggering event is about. A sync of that connection's connector runs for
34
+ * it alone; any other sync runs for every connection as usual.
35
+ */
36
+ readonly connection?: { readonly id: string; readonly connectorId: string }
30
37
  }
31
38
 
32
- export type SyncRunDispatchPort = RunDispatcher<AutomaticSyncRunDispatchInput, SyncRunRequestResult>
39
+ /** A sync of a static connector queues one run; a sync of an OAuth connector one per connection. */
40
+ export type SyncRunDispatchPort = RunDispatcher<
41
+ AutomaticSyncRunDispatchInput,
42
+ readonly SyncRunRequestResult[]
43
+ >
33
44
 
34
45
  export interface SyncRunDispatcherDependencies {
35
46
  readonly id: string
@@ -42,6 +53,8 @@ interface DispatchSyncRunInput extends SyncRunRequestOptions {
42
53
  readonly errorReporterHost: object
43
54
  readonly projectId: string
44
55
  readonly sync: SyncDefinition
56
+ /** The connection this run reads, on a sync of an OAuth connector. */
57
+ readonly connectionId?: string
45
58
  readonly storage: Storage
46
59
  readonly queue: Queues["syncRuns"]
47
60
  readonly metadata?: Readonly<Record<string, string>>
@@ -57,18 +70,45 @@ interface DispatchSyncRunInput extends SyncRunRequestOptions {
57
70
  export class SyncRunDispatcher implements SyncRunDispatchPort {
58
71
  constructor(private readonly dependencies: SyncRunDispatcherDependencies) {}
59
72
 
60
- async dispatch(input: AutomaticSyncRunDispatchInput): Promise<SyncRunRequestResult> {
73
+ async dispatch(input: AutomaticSyncRunDispatchInput): Promise<readonly SyncRunRequestResult[]> {
61
74
  assertAutomaticDispatchInput(input)
62
75
  const sync = this.dependencies.definitions.syncs.getById(input.syncId)
63
76
  if (!sync) throw new SyncValidationError(`[Sixb] Unknown sync '${input.syncId}'`)
64
77
 
78
+ if (!isOAuthConnectorDefinition(sync.connector)) {
79
+ return [await this.dispatchRun(sync, input, input.runId)]
80
+ }
81
+
82
+ const connectionIds =
83
+ input.connection?.connectorId === sync.connector.id
84
+ ? [input.connection.id]
85
+ : await listSyncConnectionIds(this.dependencies, sync)
86
+
87
+ // Each run id comes from the trigger's and the connection's, so a redelivered trigger, or one
88
+ // retried after some of its runs were queued, queues nothing twice.
89
+ const results: SyncRunRequestResult[] = []
90
+ for (const connectionId of connectionIds) {
91
+ results.push(
92
+ await this.dispatchRun(sync, input, `${input.runId}:${connectionId}`, connectionId)
93
+ )
94
+ }
95
+ return results
96
+ }
97
+
98
+ private dispatchRun(
99
+ sync: SyncDefinition,
100
+ input: AutomaticSyncRunDispatchInput,
101
+ runId: string,
102
+ connectionId?: string
103
+ ): Promise<SyncRunRequestResult> {
65
104
  return dispatchSyncRun({
66
105
  errorReporterHost: this.dependencies,
67
106
  projectId: this.dependencies.id,
68
107
  sync,
108
+ ...(connectionId === undefined ? {} : { connectionId }),
69
109
  storage: this.dependencies.storage,
70
110
  queue: this.dependencies.queues.syncRuns,
71
- runId: input.runId,
111
+ runId,
72
112
  expectedLatestVersionId: input.expectedLatestVersionId,
73
113
  commitMessage: input.commitMessage,
74
114
  metadata: input.metadata,
@@ -76,10 +116,10 @@ export class SyncRunDispatcher implements SyncRunDispatchPort {
76
116
  validateExistingRun: (run, storage) =>
77
117
  assertAutomaticExecutionIdentity(storage, this.dependencies.id, input, run),
78
118
  joinQueuedRun: true,
79
- createExecution: async (executionId, runId) =>
119
+ createExecution: async (executionId, queuedRunId) =>
80
120
  createPrimitiveExecutionRecord({
81
121
  id: executionId,
82
- primitive: { kind: "sync", id: sync.id, runId },
122
+ primitive: { kind: "sync", id: sync.id, runId: queuedRunId },
83
123
  origin: {
84
124
  type: "automatic",
85
125
  projectId: this.dependencies.id,
@@ -170,6 +210,7 @@ function syncRunStore(
170
210
  const { runs: queued } = await runs.list({
171
211
  projectId,
172
212
  syncId: sync.id,
213
+ connectionId: input.connectionId ?? null,
173
214
  statuses: ["queued"],
174
215
  order: "asc",
175
216
  limit: 1,
@@ -184,6 +225,7 @@ function syncRunStore(
184
225
  id: run.id,
185
226
  executionId: run.executionId,
186
227
  syncId: sync.id,
228
+ ...(input.connectionId === undefined ? {} : { connectionId: input.connectionId }),
187
229
  datasetId: sync.target.dataset.id,
188
230
  mode: sync.config.mode,
189
231
  queuedAt: run.queuedAt,
@@ -197,6 +239,7 @@ function syncRunStore(
197
239
  id: run.id,
198
240
  executionId: run.executionId,
199
241
  syncId: run.syncId,
242
+ ...(run.connectionId === undefined ? {} : { connectionId: run.connectionId }),
200
243
  datasetId: run.datasetId,
201
244
  mode: run.mode,
202
245
  queuedAt,
@@ -208,14 +251,18 @@ function syncRunStore(
208
251
 
209
252
  /**
210
253
  * A run that has not started reads its source when it starts, so it already covers a trigger that
211
- * arrives now. One queued with another request payload is not joined.
254
+ * arrives now. One queued for another connection, or with another request payload, is not joined.
212
255
  */
213
256
  function runMatchesRequest(
214
257
  existing: SyncRunRecord,
215
- input: Pick<DispatchSyncRunInput, "sync" | "expectedLatestVersionId" | "commitMessage">
258
+ input: Pick<
259
+ DispatchSyncRunInput,
260
+ "sync" | "connectionId" | "expectedLatestVersionId" | "commitMessage"
261
+ >
216
262
  ): boolean {
217
263
  return (
218
264
  existing.syncId === input.sync.id &&
265
+ existing.connectionId === input.connectionId &&
219
266
  existing.datasetId === input.sync.target.dataset.id &&
220
267
  existing.mode === input.sync.config.mode &&
221
268
  existing.expectedLatestVersionId === input.expectedLatestVersionId &&
@@ -227,12 +274,27 @@ function toRequestResult(run: SyncRunRecord, publication?: RunPublication): Sync
227
274
  return {
228
275
  syncId: run.syncId,
229
276
  runId: run.id,
277
+ ...(run.connectionId === undefined ? {} : { connectionId: run.connectionId }),
230
278
  queuedAt: (publication?.queuedAt ?? run.queuedAt).toISOString(),
231
279
  ...(publication ? { jobId: publication.jobId } : {}),
232
280
  created: publication?.created ?? false,
233
281
  }
234
282
  }
235
283
 
284
+ async function listSyncConnectionIds(
285
+ host: object,
286
+ sync: SyncDefinition
287
+ ): Promise<readonly string[]> {
288
+ if (!isOAuthConnectorDefinition(sync.connector)) return []
289
+ const connections = findSyncConnections(host)
290
+ if (!connections) {
291
+ throw new SyncValidationError(
292
+ `[Sixb] Sync '${sync.id}' reads OAuth connector '${sync.connector.id}', whose connections this host cannot list.`
293
+ )
294
+ }
295
+ return (await connections.list(sync.connector)).map((connection) => connection.id)
296
+ }
297
+
236
298
  function requireSyncRunStorage(storage: Storage): NonNullable<Storage["syncRuns"]> {
237
299
  if (!storage.syncRuns) throw new SyncValidationError("[Sixb] Sync run storage is not configured.")
238
300
  return storage.syncRuns
@@ -978,6 +978,129 @@ export function runAgentApprovalStorageContractSuite<
978
978
  )
979
979
  })
980
980
  })
981
+
982
+ test("rewinds approvals of truncated turns, unmarks earlier ones, and filters rewound subagents", async () => {
983
+ // Removal proof: skip clearing reported_in_message_id in approvals.rewind, or omit
984
+ // retainedTurnsOnly in listThreadSubagents.
985
+ await withStorage(async (storage) => {
986
+ const t1 = new Date(t0.getTime() + 1_000)
987
+ await startTurn(storage)
988
+ await storage.agents.messages.append({
989
+ id: "msg_1",
990
+ projectId,
991
+ threadId: "thr_1",
992
+ runId: null,
993
+ role: "user",
994
+ parts: [{ type: "text", text: "Turn 1" }],
995
+ createdAt: t0,
996
+ })
997
+ await storage.agents.approvals.request(approvalInput({ id: "apr_early" }))
998
+ await storage.agents.approvals.decide({ ...decision("denied"), id: "apr_early" })
999
+ await finishTurn(storage, "cancelled")
1000
+
1001
+ await storage.agents.messages.append({
1002
+ id: "msg_2",
1003
+ projectId,
1004
+ threadId: "thr_1",
1005
+ runId: null,
1006
+ role: "user",
1007
+ parts: [{ type: "text", text: "Turn 2" }],
1008
+ createdAt: t1,
1009
+ })
1010
+ await storage.agents.approvals.markReported({
1011
+ projectId,
1012
+ threadId: "thr_1",
1013
+ ids: ["apr_early"],
1014
+ messageId: "msg_2",
1015
+ })
1016
+
1017
+ const laterExec = await createTestAgentExecution(storage, { projectId, runId: "run_later" })
1018
+ await storage.agents.runs.create({
1019
+ ...runInput("run_later"),
1020
+ executionId: laterExec,
1021
+ triggerMessageId: "msg_2",
1022
+ createdAt: t1,
1023
+ })
1024
+ await storage.agents.runs.start({
1025
+ projectId,
1026
+ id: "run_later",
1027
+ execution: { token: "tok_later", queueLeaseExpiresAt: new Date(t1.getTime() + 60_000) },
1028
+ startedAt: t1,
1029
+ })
1030
+ await storage.agents.approvals.request(
1031
+ approvalInput({
1032
+ id: "apr_rewound",
1033
+ runId: "run_later",
1034
+ callerRunId: "run_later",
1035
+ executionToken: "tok_later",
1036
+ call: sendReminders,
1037
+ })
1038
+ )
1039
+ const childExec = await createTestAgentExecution(storage, {
1040
+ projectId,
1041
+ runId: "child_rewound",
1042
+ sourceExecutionId: laterExec,
1043
+ })
1044
+ await storage.agents.runs.createSubagent({
1045
+ id: "child_rewound",
1046
+ projectId,
1047
+ executionId: childExec,
1048
+ parentRunId: "run_later",
1049
+ parentExecutionToken: "tok_later",
1050
+ spawnKey: "west",
1051
+ spec: { model: { provider: "test", modelId: "fast" }, task: "Ask west.", toolNames: [] },
1052
+ thread: { id: "thr_child_rewound", create: true },
1053
+ trigger: { id: "msg_child_rewound", parts: [{ type: "text", text: "Ask west." }] },
1054
+ maxActiveChildren: 4,
1055
+ createdAt: t1,
1056
+ })
1057
+ await storage.agents.runs.start({
1058
+ projectId,
1059
+ id: "child_rewound",
1060
+ execution: { token: "tok_c", queueLeaseExpiresAt: new Date(t1.getTime() + 60_000) },
1061
+ startedAt: t1,
1062
+ })
1063
+ await storage.agents.runs.finish({
1064
+ projectId,
1065
+ id: "child_rewound",
1066
+ executionToken: "tok_c",
1067
+ status: "succeeded",
1068
+ finishReason: "awaiting_answer",
1069
+ result: { text: "" },
1070
+ })
1071
+ await storage.agents.runs.finish({
1072
+ projectId,
1073
+ id: "run_later",
1074
+ executionToken: "tok_later",
1075
+ status: "succeeded",
1076
+ finishReason: "awaiting_approval",
1077
+ })
1078
+
1079
+ const rewound = await storage.agents.approvals.rewind({
1080
+ projectId,
1081
+ threadId: "thr_1",
1082
+ runIds: ["run_later"],
1083
+ clearedMessageIds: ["msg_2"],
1084
+ })
1085
+ await storage.agents.messages.deleteFromSeq({ projectId, threadId: "thr_1", fromSeq: 2 })
1086
+
1087
+ expect(rewound).toEqual({
1088
+ cancelled: [expect.objectContaining({ id: "apr_rewound", status: "cancelled" })],
1089
+ deleted: 1,
1090
+ })
1091
+ expect(await storage.agents.approvals.getById({ projectId, id: "apr_rewound" })).toBeNull()
1092
+ const earlyAfter = await storage.agents.approvals.getById({ projectId, id: "apr_early" })
1093
+ expect(earlyAfter?.reportedInMessageId).toBeUndefined()
1094
+
1095
+ expect(
1096
+ await storage.agents.runs.listThreadSubagents({
1097
+ projectId,
1098
+ threadId: "thr_1",
1099
+ retainedTurnsOnly: true,
1100
+ })
1101
+ ).toEqual([])
1102
+ })
1103
+ })
981
1104
  })
982
1105
  }
983
1106
 
@@ -648,6 +648,65 @@ export function runAgentInboxStorageContractSuite<
648
648
  })
649
649
  })
650
650
 
651
+ test("an edit waiting for its turn keeps the message it replaces, and stays a message sent now", async () => {
652
+ await withStorage(async (storage) => {
653
+ await storage.agents.threads.create({
654
+ id: "thr_edit",
655
+ projectId,
656
+ ownerPrincipal: alice,
657
+ createdAt: t0,
658
+ })
659
+ await startConversationRun(storage, "thr_edit", "run_stopping", "tok_stopping")
660
+
661
+ const edit = {
662
+ id: "inb_edit",
663
+ projectId,
664
+ threadId: "thr_edit",
665
+ messageId: "msg_edited",
666
+ authorPrincipal: alice,
667
+ mode: "queue",
668
+ immediate: true,
669
+ replacesMessageId: "msg_original",
670
+ parts: [{ type: "text", text: "Only the breaking changes" }],
671
+ } as const
672
+
673
+ // An edit rewinds when it starts: it is never a steer, nor kept for a later turn.
674
+ for (const invalid of [
675
+ { ...edit, mode: "steer" },
676
+ { ...edit, immediate: false },
677
+ ] as const) {
678
+ const error = await storage.agents.inbox.enqueue(invalid).catch((caught) => caught)
679
+ expect(error).toBeInstanceOf(AgentStorageError)
680
+ expect(error.code).toBe("invalid_input")
681
+ }
682
+
683
+ const { item } = await storage.agents.inbox.enqueue(edit)
684
+ expect(item.replacesMessageId).toBe("msg_original")
685
+ const [listed] = await storage.agents.inbox.list({ projectId, threadId: "thr_edit" })
686
+ expect(listed?.replacesMessageId).toBe("msg_original")
687
+
688
+ const demoted = await storage.agents.inbox
689
+ .update({ projectId, threadId: "thr_edit", id: "inb_edit", immediate: false })
690
+ .catch((caught) => caught)
691
+ expect(demoted).toBeInstanceOf(AgentStorageError)
692
+ expect(demoted.code).toBe("invalid_state")
693
+
694
+ await storage.agents.runs.finish({
695
+ projectId,
696
+ id: "run_stopping",
697
+ executionToken: "tok_stopping",
698
+ status: "cancelled",
699
+ })
700
+ const popped = await storage.agents.inbox.takeNextQueued({
701
+ projectId,
702
+ threadId: "thr_edit",
703
+ onlyImmediate: true,
704
+ })
705
+ expect(popped?.id).toBe("inb_edit")
706
+ expect(popped?.replacesMessageId).toBe("msg_original")
707
+ })
708
+ })
709
+
651
710
  test("takeNextQueued waits for idle and orders immediate, steer, then queue", async () => {
652
711
  await withStorage(async (storage) => {
653
712
  await storage.agents.threads.create({