@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
@@ -10,13 +10,13 @@ import {
10
10
  AuthStorageError2,
11
11
  toUserProfile,
12
12
  SYSTEM_PRINCIPAL2
13
- } from "../chunk-xcrnrpfh.js";
13
+ } from "../chunk-394zjzjs.js";
14
14
  import"../chunk-d7v97qxq.js";
15
15
  import {
16
16
  agentServiceAccountId2,
17
17
  MAX_OBJECT_READ_FACETS2,
18
18
  defineProjection2
19
- } from "../chunk-paxabbqd.js";
19
+ } from "../chunk-tapdssb5.js";
20
20
  import"../chunk-7j4yydm2.js";
21
21
  import {
22
22
  compileSelectedObjectReadScope2,
@@ -28,11 +28,11 @@ import {
28
28
  } from "../chunk-wkv3h3q7.js";
29
29
  import {
30
30
  UNIQUE_VALUE_KEY_VERSION
31
- } from "../chunk-3zagkr6w.js";
31
+ } from "../chunk-7mhbs9yy.js";
32
32
  import"../chunk-frsz8wxd.js";
33
33
  import {
34
34
  ref2
35
- } from "../chunk-8a8k38tz.js";
35
+ } from "../chunk-brybqw5k.js";
36
36
  import {
37
37
  OntologyRegistry2,
38
38
  defineObjectType2,
@@ -41,7 +41,7 @@ import {
41
41
  link2,
42
42
  valueTypeRef2,
43
43
  stringEnum2
44
- } from "../chunk-dhkc9b23.js";
44
+ } from "../chunk-v8a1qjzp.js";
45
45
  import {
46
46
  createEventId2
47
47
  } from "../chunk-zrvhsq7f.js";
@@ -50,8 +50,9 @@ import"../chunk-az95tsh3.js";
50
50
  import"../chunk-qttqe1ah.js";
51
51
  import {
52
52
  AgentStorageError2
53
- } from "../chunk-ey1p8w68.js";
54
- import"../chunk-zeykm8my.js";
53
+ } from "../chunk-gaj8djsw.js";
54
+ import"../chunk-dq3t5sr3.js";
55
+ import"../chunk-3qtk0070.js";
55
56
  import {
56
57
  aiLimitCalendarMonth2
57
58
  } from "../chunk-c4nrycdy.js";
@@ -61,10 +62,10 @@ import {
61
62
  import {
62
63
  DEFAULT_FILE_UPLOAD_TERMINAL_SESSION_TTL_MS2
63
64
  } from "../chunk-h89wz928.js";
64
- import"../chunk-vehcr9eb.js";
65
+ import"../chunk-cg7cygfj.js";
65
66
  import {
66
67
  ArtifactStorageError
67
- } from "../chunk-ewqn51gr.js";
68
+ } from "../chunk-88xeh6zx.js";
68
69
  import {
69
70
  ARTIFACT_STATE_LIMITS2,
70
71
  ARTIFACT_RESTORE_POINTS2,
@@ -90,9 +91,9 @@ import {
90
91
  WorkflowInterventionError2,
91
92
  InMemoryStorage2,
92
93
  migrateStorage2
93
- } from "../chunk-gjhrz66x.js";
94
+ } from "../chunk-9c9yknwt.js";
94
95
  import"../chunk-61zptves.js";
95
- import"../chunk-zft9bzbc.js";
96
+ import"../chunk-hkbks1xm.js";
96
97
  import {
97
98
  ORPHANED_RUN_AFTER_MS2,
98
99
  planRunClaim2
@@ -105,7 +106,7 @@ import {
105
106
  import"../chunk-jmfet9r4.js";
106
107
  import"../chunk-qf954wje.js";
107
108
  import"../chunk-x0v3jd47.js";
108
- import"../chunk-s5pj68fa.js";
109
+ import"../chunk-5sswe5ej.js";
109
110
  import {
110
111
  planObjectQuery2,
111
112
  executeObjectQuery2,
@@ -113,25 +114,25 @@ import {
113
114
  existsObjects2,
114
115
  facetObjects2,
115
116
  executeObjectQueryLinks2
116
- } from "../chunk-s1mqyqmm.js";
117
- import"../chunk-5t9gm5tt.js";
117
+ } from "../chunk-bs1sd0e0.js";
118
+ import"../chunk-fmgf9h5e.js";
118
119
  import"../chunk-vs2s3p8n.js";
119
120
  import"../chunk-bz5bnjjt.js";
120
121
  import"../chunk-bqr703h4.js";
121
- import"../chunk-m3qx2pns.js";
122
+ import"../chunk-jt012fxq.js";
122
123
  import"../chunk-60662fyv.js";
123
124
  import {
124
125
  bindModelExecutionAttempt,
125
126
  isBoundSixb
126
- } from "../chunk-z1njfqqs.js";
127
+ } from "../chunk-ats8y3d9.js";
127
128
  import"../chunk-czct88ht.js";
128
- import"../chunk-k29n4176.js";
129
- import"../chunk-k3jh8gsg.js";
129
+ import"../chunk-ym1bqd98.js";
130
+ import"../chunk-kft7mp7z.js";
130
131
  import"../chunk-5qqmndhm.js";
131
132
  import"../chunk-sgx82nnt.js";
132
133
  import"../chunk-8ncg20rd.js";
133
- import"../chunk-5a4a52tq.js";
134
- import"../chunk-qavwr628.js";
134
+ import"../chunk-0pmpwn3g.js";
135
+ import"../chunk-n1hbwc6y.js";
135
136
  import {
136
137
  col2,
137
138
  defineDataset2,
@@ -141,13 +142,14 @@ import {
141
142
  writeDataset2
142
143
  } from "../chunk-ppxf7gw2.js";
143
144
  import"../chunk-191jz8a6.js";
144
- import"../chunk-1yh6jgtz.js";
145
- import"../chunk-q9nkpr8k.js";
145
+ import"../chunk-grt2j5vp.js";
146
+ import"../chunk-9tpmfh3n.js";
146
147
  import {
147
148
  ProjectionRegistry2,
148
149
  createLinkScopeFingerprint2,
149
150
  createOntologyMaterializer2
150
- } from "../chunk-b4escq4c.js";
151
+ } from "../chunk-ykchk644.js";
152
+ import"../chunk-90nqenq8.js";
151
153
  import"../chunk-1vg43g9q.js";
152
154
  import"../chunk-m427qgq0.js";
153
155
  import {
@@ -163,50 +165,49 @@ import {
163
165
  QueueError2,
164
166
  InMemoryQueues2
165
167
  } from "../chunk-8tv3qd65.js";
166
- import"../chunk-r2psmn42.js";
167
- import"../chunk-68hm50qh.js";
168
+ import"../chunk-eg6xqef7.js";
169
+ import"../chunk-bcz9dxtf.js";
168
170
  import"../chunk-92wrka15.js";
169
171
  import {
170
172
  projectAgentThreadModelContext2
171
- } from "../chunk-fpf57gca.js";
172
- import"../chunk-zxhym8tr.js";
173
+ } from "../chunk-7r9mqpva.js";
174
+ import"../chunk-f05994as.js";
173
175
  import"../chunk-de5sfbc3.js";
174
- import"../chunk-bc3y6gff.js";
175
- import"../chunk-q8d9p0tb.js";
176
+ import"../chunk-jka26v8c.js";
177
+ import"../chunk-wzcjhv54.js";
176
178
  import {
177
179
  workflowAgentStepActorId2
178
- } from "../chunk-0mvjpgvm.js";
180
+ } from "../chunk-425ydk65.js";
179
181
  import"../chunk-c69nj7se.js";
180
182
  import"../chunk-whbwf3np.js";
181
- import"../chunk-fzae1jpq.js";
183
+ import"../chunk-t19wjmnc.js";
182
184
  import {
183
185
  SixbHost2
184
- } from "../chunk-rg725hry.js";
186
+ } from "../chunk-s8xxef60.js";
185
187
  import {
186
188
  findDatasetIngestRuntime2,
187
189
  getDatasetIngestRuntime2
188
- } from "../chunk-0hkdtwqk.js";
189
- import"../chunk-naxjka9v.js";
190
+ } from "../chunk-xf76csps.js";
191
+ import"../chunk-brhp9d97.js";
190
192
  import"../chunk-3ba89vm7.js";
191
193
  import {
192
194
  createTestingScope
193
- } from "../chunk-m9ketb51.js";
195
+ } from "../chunk-ygvay56w.js";
194
196
  import {
195
197
  datasetSequenceChange2,
196
198
  DatasetSequenceConflictError2
197
199
  } from "../chunk-dmnd9ea6.js";
198
200
  import"../chunk-7qe46788.js";
199
- import"../chunk-aw1z0gre.js";
200
- import"../chunk-wqe9shx2.js";
201
+ import"../chunk-qbd282aa.js";
202
+ import"../chunk-pqj8vff9.js";
203
+ import"../chunk-y8fwm3z2.js";
201
204
  import {
202
205
  SandboxNotRunningError2
203
- } from "../chunk-rtdrm592.js";
204
- import"../chunk-3723kgba.js";
205
- import"../chunk-pqvvqc65.js";
206
- import"../chunk-y8fwm3z2.js";
206
+ } from "../chunk-htdzx40w.js";
207
207
  import {
208
208
  restoreTrustedPrimitiveExecutionScope
209
- } from "../chunk-pc7kra3k.js";
209
+ } from "../chunk-xavet0qs.js";
210
+ import"../chunk-3723kgba.js";
210
211
  import"../chunk-d9xbwh3h.js";
211
212
  import"../chunk-w3t94hm6.js";
212
213
  import {
@@ -222,12 +223,13 @@ import {
222
223
  import {
223
224
  ObjectQueryPlanningError2
224
225
  } from "../chunk-0k1h5hmr.js";
225
- import"../chunk-stmxh0hv.js";
226
+ import"../chunk-3neam1y5.js";
226
227
  import {
227
228
  MaterializationValidationError2,
228
229
  UniqueValueViolationError2,
229
230
  MaterializationConflictError2
230
231
  } from "../chunk-y7dbmaqh.js";
232
+ import"../chunk-6hfbz4d0.js";
231
233
  import {
232
234
  AGENT_TOKEN_RATE_SAMPLES2,
233
235
  AGENT_THREAD_INBOX_MAX_ITEMS2
@@ -1993,6 +1995,117 @@ function runAgentApprovalStorageContractSuite(label, options) {
1993
1995
  expect3(stored?.kind === "conversation" ? stored.spec?.approvalMode : null).toBe("accept-edits");
1994
1996
  });
1995
1997
  });
1998
+ test3("rewinds approvals of truncated turns, unmarks earlier ones, and filters rewound subagents", async () => {
1999
+ await withStorage(async (storage) => {
2000
+ const t1 = new Date(t0.getTime() + 1000);
2001
+ await startTurn(storage);
2002
+ await storage.agents.messages.append({
2003
+ id: "msg_1",
2004
+ projectId: projectId3,
2005
+ threadId: "thr_1",
2006
+ runId: null,
2007
+ role: "user",
2008
+ parts: [{ type: "text", text: "Turn 1" }],
2009
+ createdAt: t0
2010
+ });
2011
+ await storage.agents.approvals.request(approvalInput({ id: "apr_early" }));
2012
+ await storage.agents.approvals.decide({ ...decision("denied"), id: "apr_early" });
2013
+ await finishTurn(storage, "cancelled");
2014
+ await storage.agents.messages.append({
2015
+ id: "msg_2",
2016
+ projectId: projectId3,
2017
+ threadId: "thr_1",
2018
+ runId: null,
2019
+ role: "user",
2020
+ parts: [{ type: "text", text: "Turn 2" }],
2021
+ createdAt: t1
2022
+ });
2023
+ await storage.agents.approvals.markReported({
2024
+ projectId: projectId3,
2025
+ threadId: "thr_1",
2026
+ ids: ["apr_early"],
2027
+ messageId: "msg_2"
2028
+ });
2029
+ const laterExec = await createTestAgentExecution(storage, { projectId: projectId3, runId: "run_later" });
2030
+ await storage.agents.runs.create({
2031
+ ...runInput("run_later"),
2032
+ executionId: laterExec,
2033
+ triggerMessageId: "msg_2",
2034
+ createdAt: t1
2035
+ });
2036
+ await storage.agents.runs.start({
2037
+ projectId: projectId3,
2038
+ id: "run_later",
2039
+ execution: { token: "tok_later", queueLeaseExpiresAt: new Date(t1.getTime() + 60000) },
2040
+ startedAt: t1
2041
+ });
2042
+ await storage.agents.approvals.request(approvalInput({
2043
+ id: "apr_rewound",
2044
+ runId: "run_later",
2045
+ callerRunId: "run_later",
2046
+ executionToken: "tok_later",
2047
+ call: sendReminders
2048
+ }));
2049
+ const childExec = await createTestAgentExecution(storage, {
2050
+ projectId: projectId3,
2051
+ runId: "child_rewound",
2052
+ sourceExecutionId: laterExec
2053
+ });
2054
+ await storage.agents.runs.createSubagent({
2055
+ id: "child_rewound",
2056
+ projectId: projectId3,
2057
+ executionId: childExec,
2058
+ parentRunId: "run_later",
2059
+ parentExecutionToken: "tok_later",
2060
+ spawnKey: "west",
2061
+ spec: { model: { provider: "test", modelId: "fast" }, task: "Ask west.", toolNames: [] },
2062
+ thread: { id: "thr_child_rewound", create: true },
2063
+ trigger: { id: "msg_child_rewound", parts: [{ type: "text", text: "Ask west." }] },
2064
+ maxActiveChildren: 4,
2065
+ createdAt: t1
2066
+ });
2067
+ await storage.agents.runs.start({
2068
+ projectId: projectId3,
2069
+ id: "child_rewound",
2070
+ execution: { token: "tok_c", queueLeaseExpiresAt: new Date(t1.getTime() + 60000) },
2071
+ startedAt: t1
2072
+ });
2073
+ await storage.agents.runs.finish({
2074
+ projectId: projectId3,
2075
+ id: "child_rewound",
2076
+ executionToken: "tok_c",
2077
+ status: "succeeded",
2078
+ finishReason: "awaiting_answer",
2079
+ result: { text: "" }
2080
+ });
2081
+ await storage.agents.runs.finish({
2082
+ projectId: projectId3,
2083
+ id: "run_later",
2084
+ executionToken: "tok_later",
2085
+ status: "succeeded",
2086
+ finishReason: "awaiting_approval"
2087
+ });
2088
+ const rewound = await storage.agents.approvals.rewind({
2089
+ projectId: projectId3,
2090
+ threadId: "thr_1",
2091
+ runIds: ["run_later"],
2092
+ clearedMessageIds: ["msg_2"]
2093
+ });
2094
+ await storage.agents.messages.deleteFromSeq({ projectId: projectId3, threadId: "thr_1", fromSeq: 2 });
2095
+ expect3(rewound).toEqual({
2096
+ cancelled: [expect3.objectContaining({ id: "apr_rewound", status: "cancelled" })],
2097
+ deleted: 1
2098
+ });
2099
+ expect3(await storage.agents.approvals.getById({ projectId: projectId3, id: "apr_rewound" })).toBeNull();
2100
+ const earlyAfter = await storage.agents.approvals.getById({ projectId: projectId3, id: "apr_early" });
2101
+ expect3(earlyAfter?.reportedInMessageId).toBeUndefined();
2102
+ expect3(await storage.agents.runs.listThreadSubagents({
2103
+ projectId: projectId3,
2104
+ threadId: "thr_1",
2105
+ retainedTurnsOnly: true
2106
+ })).toEqual([]);
2107
+ });
2108
+ });
1996
2109
  });
1997
2110
  }
1998
2111
  function approvalInput(overrides = {}) {
@@ -2603,6 +2716,56 @@ function runAgentInboxStorageContractSuite(label, options) {
2603
2716
  ]);
2604
2717
  });
2605
2718
  });
2719
+ test4("an edit waiting for its turn keeps the message it replaces, and stays a message sent now", async () => {
2720
+ await withStorage(async (storage) => {
2721
+ await storage.agents.threads.create({
2722
+ id: "thr_edit",
2723
+ projectId: projectId4,
2724
+ ownerPrincipal: alice,
2725
+ createdAt: t02
2726
+ });
2727
+ await startConversationRun(storage, "thr_edit", "run_stopping", "tok_stopping");
2728
+ const edit = {
2729
+ id: "inb_edit",
2730
+ projectId: projectId4,
2731
+ threadId: "thr_edit",
2732
+ messageId: "msg_edited",
2733
+ authorPrincipal: alice,
2734
+ mode: "queue",
2735
+ immediate: true,
2736
+ replacesMessageId: "msg_original",
2737
+ parts: [{ type: "text", text: "Only the breaking changes" }]
2738
+ };
2739
+ for (const invalid of [
2740
+ { ...edit, mode: "steer" },
2741
+ { ...edit, immediate: false }
2742
+ ]) {
2743
+ const error = await storage.agents.inbox.enqueue(invalid).catch((caught) => caught);
2744
+ expect4(error).toBeInstanceOf(AgentStorageError2);
2745
+ expect4(error.code).toBe("invalid_input");
2746
+ }
2747
+ const { item } = await storage.agents.inbox.enqueue(edit);
2748
+ expect4(item.replacesMessageId).toBe("msg_original");
2749
+ const [listed] = await storage.agents.inbox.list({ projectId: projectId4, threadId: "thr_edit" });
2750
+ expect4(listed?.replacesMessageId).toBe("msg_original");
2751
+ const demoted = await storage.agents.inbox.update({ projectId: projectId4, threadId: "thr_edit", id: "inb_edit", immediate: false }).catch((caught) => caught);
2752
+ expect4(demoted).toBeInstanceOf(AgentStorageError2);
2753
+ expect4(demoted.code).toBe("invalid_state");
2754
+ await storage.agents.runs.finish({
2755
+ projectId: projectId4,
2756
+ id: "run_stopping",
2757
+ executionToken: "tok_stopping",
2758
+ status: "cancelled"
2759
+ });
2760
+ const popped = await storage.agents.inbox.takeNextQueued({
2761
+ projectId: projectId4,
2762
+ threadId: "thr_edit",
2763
+ onlyImmediate: true
2764
+ });
2765
+ expect4(popped?.id).toBe("inb_edit");
2766
+ expect4(popped?.replacesMessageId).toBe("msg_original");
2767
+ });
2768
+ });
2606
2769
  test4("takeNextQueued waits for idle and orders immediate, steer, then queue", async () => {
2607
2770
  await withStorage(async (storage) => {
2608
2771
  await storage.agents.threads.create({
@@ -3106,6 +3269,9 @@ function participant(userId, addedAt) {
3106
3269
  addedBy: owner
3107
3270
  };
3108
3271
  }
3272
+ function user(id) {
3273
+ return { type: "user", id };
3274
+ }
3109
3275
  function execution(token, queueLeaseExpiresAt = at2("2026-06-23T10:05:00.000Z")) {
3110
3276
  return { token, queueLeaseExpiresAt };
3111
3277
  }
@@ -3720,10 +3886,10 @@ function runAgentStorageContractSuite(label, options) {
3720
3886
  })), "invalid_input");
3721
3887
  });
3722
3888
  });
3723
- test6("moves a computer's thread to another computer or folder, and says when", async () => {
3724
- await withStorage(async (storage) => {
3889
+ test6("moves a thread between the cloud, computers and folders back and forth", async () => {
3890
+ await withStorage(async (storage, fixture) => {
3725
3891
  await storage.threads.create(threadInput({ runsOn: "computer", computer: laptop }));
3726
- await storage.threads.create(threadInput({ id: "thr_cloud" }));
3892
+ await storage.threads.create(threadInput({ id: "thr_cloud", sandboxParams: { repo: "app" } }));
3727
3893
  const thread = { projectId: projectId6, id: "thr_1" };
3728
3894
  const renamed = await storage.threads.assignComputer({
3729
3895
  ...thread,
@@ -3739,13 +3905,167 @@ function runAgentStorageContractSuite(label, options) {
3739
3905
  movedAt: at2("2026-06-23T12:00:00.000Z")
3740
3906
  });
3741
3907
  await expect6(storage.threads.getById(thread)).resolves.toMatchObject({
3908
+ runsOn: "computer",
3742
3909
  computer: elsewhere,
3743
3910
  movedAt: at2("2026-06-23T12:00:00.000Z")
3744
3911
  });
3745
- await expectAgentError2(storage.threads.assignComputer({ projectId: projectId6, id: "thr_cloud", computer: laptop }), "invalid_input");
3912
+ await createRun(storage, fixture, runInput2({
3913
+ id: "run_cloud",
3914
+ threadId: "thr_cloud",
3915
+ spec: { model: { provider: "test", modelId: "large" } },
3916
+ execution: execution("cloud")
3917
+ }));
3918
+ await expectAgentError2(storage.threads.assignComputer({ projectId: projectId6, id: "thr_cloud", computer: laptop }), "active_run_exists");
3919
+ await storage.runs.start({ projectId: projectId6, id: "run_cloud", execution: execution("cloud") });
3920
+ await expectAgentError2(storage.threads.assignComputer({ projectId: projectId6, id: "thr_cloud", computer: laptop }), "active_run_exists");
3921
+ await storage.runs.finish({
3922
+ projectId: projectId6,
3923
+ id: "run_cloud",
3924
+ executionToken: "cloud",
3925
+ status: "cancelled"
3926
+ });
3927
+ const toLaptop = await storage.threads.assignComputer({
3928
+ projectId: projectId6,
3929
+ id: "thr_cloud",
3930
+ computer: laptop,
3931
+ movedAt: at2("2026-06-23T13:00:00.000Z")
3932
+ });
3933
+ expect6(toLaptop).toMatchObject({
3934
+ runsOn: "computer",
3935
+ computer: laptop,
3936
+ sandboxParams: { repo: "app" },
3937
+ movedAt: at2("2026-06-23T13:00:00.000Z")
3938
+ });
3939
+ const backToCloud = await storage.threads.moveToCloud({
3940
+ projectId: projectId6,
3941
+ id: "thr_cloud",
3942
+ movedAt: at2("2026-06-23T14:00:00.000Z")
3943
+ });
3944
+ expect6(backToCloud.thread).not.toHaveProperty("runsOn");
3945
+ expect6(backToCloud.thread).not.toHaveProperty("computer");
3946
+ expect6(backToCloud.thread).toMatchObject({
3947
+ sandboxParams: { repo: "app" },
3948
+ movedAt: at2("2026-06-23T14:00:00.000Z")
3949
+ });
3950
+ const backToElsewhere = await storage.threads.assignComputer({
3951
+ projectId: projectId6,
3952
+ id: "thr_cloud",
3953
+ computer: elsewhere,
3954
+ movedAt: at2("2026-06-23T15:00:00.000Z")
3955
+ });
3956
+ expect6(backToElsewhere).toMatchObject({
3957
+ runsOn: "computer",
3958
+ computer: elsewhere,
3959
+ movedAt: at2("2026-06-23T15:00:00.000Z")
3960
+ });
3961
+ await createRun(storage, fixture, runInput2({
3962
+ id: "run_with_place",
3963
+ threadId: "thr_cloud",
3964
+ spec: {
3965
+ model: { provider: "test", modelId: "large" },
3966
+ runsOn: "computer",
3967
+ computer: { id: elsewhere.id, folder: elsewhere.folder }
3968
+ },
3969
+ execution: execution("with_place")
3970
+ }));
3971
+ await storage.threads.assignComputer({
3972
+ projectId: projectId6,
3973
+ id: "thr_cloud",
3974
+ computer: laptop,
3975
+ movedAt: at2("2026-06-23T16:00:00.000Z")
3976
+ });
3977
+ expect6((await storage.runs.getById({ projectId: projectId6, id: "run_with_place" }))?.spec).toEqual({
3978
+ model: { provider: "test", modelId: "large" },
3979
+ runsOn: "computer",
3980
+ computer: { id: laptop.id, folder: laptop.folder }
3981
+ });
3982
+ const cloudAgain = await storage.threads.moveToCloud({
3983
+ projectId: projectId6,
3984
+ id: "thr_cloud",
3985
+ movedAt: at2("2026-06-23T17:00:00.000Z")
3986
+ });
3987
+ expect6(cloudAgain.queued?.spec).toEqual({ model: { provider: "test", modelId: "large" } });
3746
3988
  await expectAgentError2(storage.threads.assignComputer({ projectId: projectId6, id: "thr_none", computer: laptop }), "thread_not_found");
3747
3989
  await expectAgentError2(storage.threads.assignComputer({ ...thread, computer: { ...laptop, id: " " } }), "invalid_input");
3748
- expect6(await storage.threads.getById({ projectId: projectId6, id: "thr_cloud" })).not.toHaveProperty("computer");
3990
+ });
3991
+ });
3992
+ test6("retires a paused child's cloud workspace when its conversation moves to a computer", async () => {
3993
+ await withStorage(async (storage, fixture) => {
3994
+ await storage.threads.create(threadInput({ id: "thr_neighbour", sandboxParams: {} }));
3995
+ await createAndStartRun(storage, fixture, runInput2({
3996
+ id: "run_neighbour",
3997
+ threadId: "thr_neighbour",
3998
+ execution: execution("neighbour_token", new Date("2099-01-01"))
3999
+ }));
4000
+ const acquireNeighbour = {
4001
+ projectId: projectId6,
4002
+ id: "thr_neighbour",
4003
+ action: "acquire",
4004
+ runId: "run_neighbour",
4005
+ executionToken: "neighbour_token",
4006
+ name: "neighbour-workspace",
4007
+ sourceFingerprint: "c".repeat(64)
4008
+ };
4009
+ await storage.threads.transitionSandbox(acquireNeighbour);
4010
+ await storage.threads.transitionSandbox({
4011
+ ...acquireNeighbour,
4012
+ action: "settle",
4013
+ status: "ready",
4014
+ initialized: true
4015
+ });
4016
+ await storage.runs.finish({
4017
+ projectId: projectId6,
4018
+ id: "run_neighbour",
4019
+ executionToken: "neighbour_token",
4020
+ status: "succeeded"
4021
+ });
4022
+ await createRunningParent(storage, fixture);
4023
+ await createSubagent(storage, fixture);
4024
+ await storage.runs.start({
4025
+ projectId: projectId6,
4026
+ id: "child_1",
4027
+ execution: execution("child_token", new Date("2099-01-01"))
4028
+ });
4029
+ const acquire = {
4030
+ projectId: projectId6,
4031
+ id: "thread_child_1",
4032
+ action: "acquire",
4033
+ runId: "child_1",
4034
+ executionToken: "child_token",
4035
+ name: "child-workspace",
4036
+ sourceFingerprint: "b".repeat(64)
4037
+ };
4038
+ await storage.threads.transitionSandbox(acquire);
4039
+ await storage.threads.transitionSandbox({
4040
+ ...acquire,
4041
+ action: "settle",
4042
+ status: "ready",
4043
+ initialized: true
4044
+ });
4045
+ await storage.runs.finish({
4046
+ projectId: projectId6,
4047
+ id: "child_1",
4048
+ executionToken: "child_token",
4049
+ status: "succeeded",
4050
+ result: { text: "Looked west." }
4051
+ });
4052
+ await storage.runs.finish({
4053
+ projectId: projectId6,
4054
+ id: "parent_1",
4055
+ executionToken: "parent_token",
4056
+ status: "succeeded"
4057
+ });
4058
+ await storage.threads.assignComputer({
4059
+ projectId: projectId6,
4060
+ id: "parent_thread",
4061
+ computer: laptop
4062
+ });
4063
+ await expect6(storage.threads.getById({ projectId: projectId6, id: "thread_child_1" })).resolves.toMatchObject({
4064
+ sandboxState: { name: "child-workspace", status: "unavailable" }
4065
+ });
4066
+ await expect6(storage.threads.getById({ projectId: projectId6, id: "thr_neighbour" })).resolves.toMatchObject({
4067
+ sandboxState: { name: "neighbour-workspace", status: "ready" }
4068
+ });
3749
4069
  });
3750
4070
  });
3751
4071
  test6("moves a computer's thread to the cloud with its queued turn, never while one runs", async () => {
@@ -4152,6 +4472,293 @@ function runAgentStorageContractSuite(label, options) {
4152
4472
  expect6(await storage.threads.listParticipants({ projectId: projectId6, threadIds: ["thr_1"] })).toEqual([]);
4153
4473
  });
4154
4474
  });
4475
+ test6("marks how far one person has read, never backwards, by message", async () => {
4476
+ await withStorage(async (storage) => {
4477
+ await storage.threads.create(threadInput());
4478
+ for (const id of ["m1", "m2", "m3"]) {
4479
+ await storage.messages.append({
4480
+ id,
4481
+ projectId: projectId6,
4482
+ threadId: "thr_1",
4483
+ runId: null,
4484
+ role: "user",
4485
+ authorPrincipal: user("usr_bob"),
4486
+ parts: [{ type: "text", text: id }],
4487
+ createdAt: at2("2026-06-23T10:00:00.000Z")
4488
+ });
4489
+ }
4490
+ const mark = (input) => storage.reads.mark({
4491
+ projectId: projectId6,
4492
+ threadId: "thr_1",
4493
+ principal: input.principal ?? user("usr_1"),
4494
+ ...input.throughMessageId === undefined ? {} : { throughMessageId: input.throughMessageId },
4495
+ ...input.readAt === undefined ? {} : { readAt: input.readAt }
4496
+ });
4497
+ expect6(await mark({ throughMessageId: "m2", readAt: at2("2026-06-23T11:00:00.000Z") })).toEqual({
4498
+ threadId: "thr_1",
4499
+ throughSeq: 2,
4500
+ headSeq: 3,
4501
+ unread: 1,
4502
+ readAt: at2("2026-06-23T11:00:00.000Z")
4503
+ });
4504
+ const back = await mark({ throughMessageId: "m1", readAt: at2("2026-06-23T12:00:00.000Z") });
4505
+ expect6(back.throughSeq).toBe(2);
4506
+ expect6(back.readAt?.toISOString()).toBe("2026-06-23T12:00:00.000Z");
4507
+ const earlier = await mark({
4508
+ throughMessageId: "m2",
4509
+ readAt: at2("2026-06-23T09:00:00.000Z")
4510
+ });
4511
+ expect6(earlier.readAt?.toISOString()).toBe("2026-06-23T12:00:00.000Z");
4512
+ expect6(await mark({})).toMatchObject({ throughSeq: 3, headSeq: 3, unread: 0 });
4513
+ const other = await mark({ principal: user("usr_2"), throughMessageId: "m_gone" });
4514
+ expect6(other).toEqual({ threadId: "thr_1", throughSeq: 0, headSeq: 3, unread: 3 });
4515
+ expect6(await storage.reads.list({
4516
+ projectId: projectId6,
4517
+ threadIds: ["thr_1", "thr_1", "thr_missing"],
4518
+ principal: user("usr_2")
4519
+ })).toEqual([{ threadId: "thr_1", throughSeq: 0, headSeq: 3, unread: 3 }]);
4520
+ await expectAgentError2(storage.reads.mark({ projectId: projectId6, threadId: "thr_missing", principal: user("usr_1") }), "thread_not_found");
4521
+ });
4522
+ });
4523
+ test6("counts as unread what someone else wrote", async () => {
4524
+ await withStorage(async (storage) => {
4525
+ const alice = user("usr_1");
4526
+ const bob = user("usr_bob");
4527
+ await storage.threads.create(threadInput());
4528
+ const message = (id, role, author, parts) => storage.messages.append({
4529
+ id,
4530
+ projectId: projectId6,
4531
+ threadId: "thr_1",
4532
+ runId: null,
4533
+ role,
4534
+ authorPrincipal: author,
4535
+ parts
4536
+ });
4537
+ await message("m1", "user", alice, [{ type: "text", text: "question" }]);
4538
+ await message("m2", "assistant", alice, [{ type: "text", text: "answer" }]);
4539
+ await message("m3", "user", alice, [
4540
+ {
4541
+ type: "approval-outcome",
4542
+ approvalId: "apr_1",
4543
+ status: "approved",
4544
+ call: {
4545
+ kind: "action",
4546
+ actionId: "mark-paid",
4547
+ subject: { kind: "object", objectTypeId: "invoice", primaryId: "INV-2041" }
4548
+ }
4549
+ }
4550
+ ]);
4551
+ await message("m4", "user", bob, [{ type: "text", text: "hello" }]);
4552
+ const place = (principal) => storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal });
4553
+ expect6(await place(alice)).toEqual([
4554
+ { threadId: "thr_1", throughSeq: 0, headSeq: 4, unread: 2 }
4555
+ ]);
4556
+ expect6(await place(bob)).toMatchObject([{ unread: 2 }]);
4557
+ await storage.reads.mark({
4558
+ projectId: projectId6,
4559
+ threadId: "thr_1",
4560
+ principal: alice,
4561
+ throughMessageId: "m2"
4562
+ });
4563
+ expect6(await place(alice)).toMatchObject([{ throughSeq: 2, unread: 1 }]);
4564
+ });
4565
+ });
4566
+ test6("a retried turn's new answer is unread to whoever read the failed one", async () => {
4567
+ await withStorage(async (storage, fixture) => {
4568
+ const bob = user("usr_bob");
4569
+ await storage.threads.create(threadInput());
4570
+ await storage.messages.append({
4571
+ id: "m1",
4572
+ projectId: projectId6,
4573
+ threadId: "thr_1",
4574
+ runId: null,
4575
+ role: "user",
4576
+ authorPrincipal: owner,
4577
+ parts: [{ type: "text", text: "first" }]
4578
+ });
4579
+ await createAndStartRun(storage, fixture, runInput2({ triggerMessageId: "m1" }));
4580
+ await storage.messages.append({
4581
+ id: "m2",
4582
+ projectId: projectId6,
4583
+ threadId: "thr_1",
4584
+ runId: "run_1",
4585
+ role: "assistant",
4586
+ authorPrincipal: owner,
4587
+ parts: [{ type: "text", text: "failed answer" }]
4588
+ });
4589
+ await storage.threads.addParticipants(participantsInput(["usr_bob"]));
4590
+ await storage.runs.finish({
4591
+ id: "run_1",
4592
+ projectId: projectId6,
4593
+ executionToken: "exec_1",
4594
+ status: "failed"
4595
+ });
4596
+ await storage.messages.deleteByRunId({ projectId: projectId6, threadId: "thr_1", runId: "run_1" });
4597
+ const retried = await storage.messages.append({
4598
+ id: "m3",
4599
+ projectId: projectId6,
4600
+ threadId: "thr_1",
4601
+ runId: null,
4602
+ role: "assistant",
4603
+ authorPrincipal: owner,
4604
+ parts: [{ type: "text", text: "retried answer" }]
4605
+ });
4606
+ expect6(retried.seq).toBe(2);
4607
+ expect6(await storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: bob })).toMatchObject([{ throughSeq: 1, headSeq: 2, unread: 1 }]);
4608
+ await storage.reads.mark({
4609
+ projectId: projectId6,
4610
+ threadId: "thr_1",
4611
+ principal: bob,
4612
+ throughMessageId: "m2"
4613
+ });
4614
+ expect6(await storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: bob })).toMatchObject([{ throughSeq: 1, unread: 1 }]);
4615
+ });
4616
+ });
4617
+ test6("retrying an older turn leaves what came after it read", async () => {
4618
+ await withStorage(async (storage, fixture) => {
4619
+ const bob = user("usr_bob");
4620
+ await storage.threads.create(threadInput());
4621
+ const message = (id, role, runId) => storage.messages.append({
4622
+ id,
4623
+ projectId: projectId6,
4624
+ threadId: "thr_1",
4625
+ runId,
4626
+ role,
4627
+ authorPrincipal: owner,
4628
+ parts: [{ type: "text", text: id }]
4629
+ });
4630
+ await message("m1", "user", null);
4631
+ await createAndStartRun(storage, fixture, runInput2({ triggerMessageId: "m1" }));
4632
+ await message("m2", "assistant", "run_1");
4633
+ await storage.runs.finish({
4634
+ id: "run_1",
4635
+ projectId: projectId6,
4636
+ executionToken: "exec_1",
4637
+ status: "failed"
4638
+ });
4639
+ await message("m3", "user", null);
4640
+ await message("m4", "assistant", null);
4641
+ await storage.threads.addParticipants(participantsInput(["usr_bob"]));
4642
+ await storage.messages.deleteByRunId({ projectId: projectId6, threadId: "thr_1", runId: "run_1" });
4643
+ expect6(await storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: bob })).toMatchObject([{ throughSeq: 4, headSeq: 4, unread: 0 }]);
4644
+ });
4645
+ });
4646
+ test6("an edited message is unread to whoever read past it", async () => {
4647
+ await withStorage(async (storage) => {
4648
+ const bob = user("usr_bob");
4649
+ await storage.threads.create(threadInput());
4650
+ for (const id of ["m1", "m2", "m3"]) {
4651
+ await storage.messages.append({
4652
+ id,
4653
+ projectId: projectId6,
4654
+ threadId: "thr_1",
4655
+ runId: null,
4656
+ role: "user",
4657
+ authorPrincipal: owner,
4658
+ parts: [{ type: "text", text: id }]
4659
+ });
4660
+ }
4661
+ await storage.threads.addParticipants(participantsInput(["usr_bob"]));
4662
+ await storage.reads.mark({ projectId: projectId6, threadId: "thr_1", principal: user("usr_1") });
4663
+ await storage.messages.deleteFromSeq({ projectId: projectId6, threadId: "thr_1", fromSeq: 2 });
4664
+ await storage.messages.append({
4665
+ id: "m2_edited",
4666
+ projectId: projectId6,
4667
+ threadId: "thr_1",
4668
+ runId: null,
4669
+ role: "user",
4670
+ authorPrincipal: owner,
4671
+ parts: [{ type: "text", text: "edited" }]
4672
+ });
4673
+ expect6(await storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: bob })).toMatchObject([{ throughSeq: 1, headSeq: 2, unread: 1 }]);
4674
+ expect6(await storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: user("usr_1") })).toMatchObject([{ throughSeq: 1, unread: 0 }]);
4675
+ });
4676
+ });
4677
+ test6("starts a participant caught up and drops their row when they leave", async () => {
4678
+ await withStorage(async (storage) => {
4679
+ await storage.threads.create(threadInput());
4680
+ for (const id of ["m1", "m2"]) {
4681
+ await storage.messages.append({
4682
+ id,
4683
+ projectId: projectId6,
4684
+ threadId: "thr_1",
4685
+ runId: null,
4686
+ role: "user",
4687
+ authorPrincipal: owner,
4688
+ parts: [{ type: "text", text: id }],
4689
+ createdAt: at2("2026-06-23T10:00:00.000Z")
4690
+ });
4691
+ }
4692
+ await storage.threads.addParticipants(participantsInput(["usr_bob"], at2("2026-06-23T11:00:00.000Z")));
4693
+ const bobsPlace = () => storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: user("usr_bob") });
4694
+ expect6(await bobsPlace()).toEqual([
4695
+ {
4696
+ threadId: "thr_1",
4697
+ throughSeq: 2,
4698
+ headSeq: 2,
4699
+ unread: 0,
4700
+ readAt: at2("2026-06-23T11:00:00.000Z")
4701
+ }
4702
+ ]);
4703
+ await storage.threads.removeParticipant({
4704
+ projectId: projectId6,
4705
+ threadId: "thr_1",
4706
+ principal: user("usr_bob")
4707
+ });
4708
+ expect6(await bobsPlace()).toEqual([
4709
+ { threadId: "thr_1", throughSeq: 0, headSeq: 2, unread: 2 }
4710
+ ]);
4711
+ await storage.reads.mark({
4712
+ projectId: projectId6,
4713
+ threadId: "thr_1",
4714
+ principal: user("usr_bob"),
4715
+ throughMessageId: "m1"
4716
+ });
4717
+ await storage.threads.addParticipants(participantsInput(["usr_bob"], at2("2026-06-23T12:00:00.000Z")));
4718
+ expect6(await bobsPlace()).toMatchObject([{ throughSeq: 2, unread: 0 }]);
4719
+ });
4720
+ });
4721
+ test6("a fork keeps its owner's place, clamped to what it copied", async () => {
4722
+ await withStorage(async (storage, fixture) => {
4723
+ await prepareForkSource(storage, fixture);
4724
+ await storage.reads.mark({
4725
+ projectId: projectId6,
4726
+ threadId: "thr_1",
4727
+ principal: user("usr_2"),
4728
+ throughMessageId: "m4"
4729
+ });
4730
+ await storage.threads.fork(forkInput());
4731
+ expect6(await storage.reads.list({
4732
+ projectId: projectId6,
4733
+ threadIds: ["thr_fork"],
4734
+ principal: user("usr_2")
4735
+ })).toMatchObject([{ throughSeq: 4 }]);
4736
+ });
4737
+ });
4738
+ test6("reads each thread's newest run, by creation then id", async () => {
4739
+ await withStorage(async (storage, fixture) => {
4740
+ for (const id of ["thr_1", "thr_2", "thr_3"]) {
4741
+ await storage.threads.create(threadInput({ id }));
4742
+ }
4743
+ const run = async (id, threadId, createdAt, status) => {
4744
+ await createAndStartRun(storage, fixture, runInput2({ id, threadId, createdAt: at2(createdAt), execution: execution(`exec_${id}`) }));
4745
+ await storage.runs.finish({ id, projectId: projectId6, executionToken: `exec_${id}`, status });
4746
+ };
4747
+ await run("run_1", "thr_1", "2026-06-23T10:00:10.000Z", "failed");
4748
+ await run("run_2", "thr_1", "2026-06-23T10:00:20.000Z", "succeeded");
4749
+ await run("run_b", "thr_2", "2026-06-23T10:00:30.000Z", "failed");
4750
+ await run("run_c", "thr_2", "2026-06-23T10:00:30.000Z", "succeeded");
4751
+ const latest = await storage.runs.latestByThread({
4752
+ projectId: projectId6,
4753
+ threadIds: ["thr_1", "thr_2", "thr_3", "thr_missing"]
4754
+ });
4755
+ expect6(latest.map((entry) => [entry.threadId, entry.id, entry.status]).sort()).toEqual([
4756
+ ["thr_1", "run_2", "succeeded"],
4757
+ ["thr_2", "run_c", "succeeded"]
4758
+ ]);
4759
+ expect6(await storage.runs.latestByThread({ projectId: projectId6, threadIds: [] })).toEqual([]);
4760
+ });
4761
+ });
4155
4762
  test6("creates a queued run before execution and claims the thread", async () => {
4156
4763
  await withStorage(async (storage, fixture) => {
4157
4764
  await storage.threads.create(threadInput());
@@ -5656,6 +6263,142 @@ function runAgentStorageContractSuite(label, options) {
5656
6263
  expect6(await storage.checkpoints.getLatest({ projectId: projectId6, threadId: "thr_fork" })).toBeNull();
5657
6264
  });
5658
6265
  });
6266
+ test6("deletes messages from a sequence onward, repairs thread stats, and reuses the sequence", async () => {
6267
+ await withStorage(async (storage) => {
6268
+ await storage.threads.create(threadInput({ id: "thr_rewind" }));
6269
+ const t1 = at2("2026-06-23T10:00:00.000Z");
6270
+ const t2 = at2("2026-06-23T10:01:00.000Z");
6271
+ const t3 = at2("2026-06-23T10:02:00.000Z");
6272
+ await storage.messages.append({
6273
+ id: "m1",
6274
+ projectId: projectId6,
6275
+ threadId: "thr_rewind",
6276
+ runId: null,
6277
+ role: "user",
6278
+ parts: [{ type: "text", text: "First" }],
6279
+ createdAt: t1
6280
+ });
6281
+ await storage.messages.append({
6282
+ id: "m2",
6283
+ projectId: projectId6,
6284
+ threadId: "thr_rewind",
6285
+ runId: null,
6286
+ role: "user",
6287
+ parts: [
6288
+ {
6289
+ type: "approval-outcome",
6290
+ approvalId: "apr_1",
6291
+ status: "denied",
6292
+ call: { kind: "workflow", workflowId: "wf_1" }
6293
+ }
6294
+ ],
6295
+ createdAt: t2
6296
+ });
6297
+ await storage.messages.append({
6298
+ id: "m3",
6299
+ projectId: projectId6,
6300
+ threadId: "thr_rewind",
6301
+ runId: null,
6302
+ role: "user",
6303
+ parts: [{ type: "text", text: "Second" }],
6304
+ createdAt: t3
6305
+ });
6306
+ expect6(await storage.threads.getById({ projectId: projectId6, id: "thr_rewind" })).toMatchObject({
6307
+ messageCount: 2,
6308
+ lastMessageAt: t3
6309
+ });
6310
+ await expectAgentError2(storage.messages.deleteFromSeq({ projectId: projectId6, threadId: "thr_rewind", fromSeq: 0 }), "invalid_input");
6311
+ await expectAgentError2(storage.messages.deleteFromSeq({ projectId: projectId6, threadId: "missing", fromSeq: 1 }), "thread_not_found");
6312
+ expect6(await storage.messages.deleteFromSeq({ projectId: projectId6, threadId: "thr_rewind", fromSeq: 2 })).toBe(2);
6313
+ expect6(await storage.threads.getById({ projectId: projectId6, id: "thr_rewind" })).toMatchObject({
6314
+ messageCount: 1,
6315
+ lastMessageAt: t1
6316
+ });
6317
+ const replacement = await storage.messages.append({
6318
+ id: "m2_next",
6319
+ projectId: projectId6,
6320
+ threadId: "thr_rewind",
6321
+ runId: null,
6322
+ role: "user",
6323
+ parts: [{ type: "text", text: "Edited second" }],
6324
+ createdAt: at2("2026-06-23T10:05:00.000Z")
6325
+ });
6326
+ expect6(replacement.seq).toBe(2);
6327
+ expect6(await storage.messages.deleteFromSeq({ projectId: projectId6, threadId: "thr_rewind", fromSeq: 1 })).toBe(2);
6328
+ expect6(await storage.threads.getById({ projectId: projectId6, id: "thr_rewind" })).toMatchObject({
6329
+ messageCount: 0,
6330
+ lastMessageAt: undefined
6331
+ });
6332
+ });
6333
+ });
6334
+ test6("deletes chained checkpoints past a retained sequence without violating chain foreign keys", async () => {
6335
+ await withStorage(async (storage, fixture) => {
6336
+ await storage.threads.create(threadInput({ id: "thr_cp" }));
6337
+ for (let i = 1;i <= 3; i += 1) {
6338
+ await storage.messages.append({
6339
+ id: `u_${i}`,
6340
+ projectId: projectId6,
6341
+ threadId: "thr_cp",
6342
+ runId: null,
6343
+ role: "user",
6344
+ parts: [{ type: "text", text: `Prompt ${i}` }]
6345
+ });
6346
+ const runId = `run_cp_${i}`;
6347
+ await createAndStartRun(storage, fixture, runInput2({
6348
+ id: runId,
6349
+ threadId: "thr_cp",
6350
+ triggerMessageId: `u_${i}`,
6351
+ execution: execution(`tok_${i}`)
6352
+ }));
6353
+ if (i >= 2) {
6354
+ const headSeq = (i - 1) * 2 + 1;
6355
+ await storage.checkpoints.create({
6356
+ id: `cp_${i - 1}`,
6357
+ projectId: projectId6,
6358
+ threadId: "thr_cp",
6359
+ createdByRunId: runId,
6360
+ expectedPreviousCheckpointId: i === 2 ? null : `cp_${i - 2}`,
6361
+ expectedHeadSeq: headSeq,
6362
+ executionToken: `tok_${i}`,
6363
+ reason: "threshold",
6364
+ summary: `Summary through turn ${i - 1}`,
6365
+ summaryFormatVersion: 1,
6366
+ summarizedThroughSeq: headSeq - 1,
6367
+ observedHeadSeq: headSeq,
6368
+ estimatedInputTokensBefore: 1000,
6369
+ estimatedInputTokensAfter: 300,
6370
+ summaryModelId: "test-model"
6371
+ });
6372
+ }
6373
+ await storage.messages.append({
6374
+ id: `a_${i}`,
6375
+ projectId: projectId6,
6376
+ threadId: "thr_cp",
6377
+ runId,
6378
+ role: "assistant",
6379
+ parts: [{ type: "text", text: `Reply ${i}` }]
6380
+ });
6381
+ await storage.runs.finish({
6382
+ projectId: projectId6,
6383
+ id: runId,
6384
+ executionToken: `tok_${i}`,
6385
+ status: "succeeded"
6386
+ });
6387
+ }
6388
+ expect6(await storage.checkpoints.deleteAfterSeq({
6389
+ projectId: projectId6,
6390
+ threadId: "thr_cp",
6391
+ afterSeq: 4
6392
+ })).toBe(1);
6393
+ expect6((await storage.checkpoints.getLatest({ projectId: projectId6, threadId: "thr_cp" }))?.id).toBe("cp_1");
6394
+ expect6(await storage.checkpoints.deleteAfterSeq({
6395
+ projectId: projectId6,
6396
+ threadId: "thr_cp",
6397
+ afterSeq: 0
6398
+ })).toBe(1);
6399
+ expect6(await storage.checkpoints.getLatest({ projectId: projectId6, threadId: "thr_cp" })).toBeNull();
6400
+ });
6401
+ });
5659
6402
  });
5660
6403
  }
5661
6404
  // src/testing/agent-token-rate-storage-contract.ts
@@ -6121,6 +6864,45 @@ function runAiCostStorageContractSuite(name, options) {
6121
6864
  await options.cleanup?.(storage);
6122
6865
  }
6123
6866
  });
6867
+ test8("buckets a series on the calendar of the query's time zone", async () => {
6868
+ const storage = await fixture();
6869
+ try {
6870
+ const august = {
6871
+ from: new Date("2026-08-03T00:00:00.000Z"),
6872
+ to: new Date("2026-08-05T00:00:00.000Z")
6873
+ };
6874
+ const callsIn = async (query) => (await storage.queryProjectOverview({ projectId: projectId8, ...august, bucket: "day", ...query })).series.map((period) => period.modelCallCount);
6875
+ expect8(await callsIn({})).toEqual([1, 0]);
6876
+ expect8(await callsIn({ timeZone: "Pacific/Kiritimati" })).toEqual([0, 1, 0]);
6877
+ const november = await storage.queryProjectOverview({
6878
+ projectId: projectId8,
6879
+ from: new Date("2026-11-01T04:00:00.000Z"),
6880
+ to: new Date("2026-11-03T05:00:00.000Z"),
6881
+ bucket: "day",
6882
+ timeZone: "America/New_York"
6883
+ });
6884
+ expect8(november.series.map((period) => [period.start.toISOString(), period.modelCallCount])).toEqual([
6885
+ ["2026-11-01T04:00:00.000Z", 1],
6886
+ ["2026-11-02T05:00:00.000Z", 1]
6887
+ ]);
6888
+ const santiago = await storage.queryProjectOverview({
6889
+ projectId: projectId8,
6890
+ from: new Date("2026-09-05T04:00:00.000Z"),
6891
+ to: new Date("2026-11-03T03:00:00.000Z"),
6892
+ bucket: "day",
6893
+ timeZone: "America/Santiago",
6894
+ providerId: "gateway",
6895
+ modelId: "clock/model"
6896
+ });
6897
+ expect8(santiago.series).toHaveLength(59);
6898
+ expect8(santiago.series.filter((period) => period.modelCallCount > 0).map((period) => [period.start.toISOString(), period.modelCallCount])).toEqual([
6899
+ ["2026-11-01T03:00:00.000Z", 1],
6900
+ ["2026-11-02T03:00:00.000Z", 1]
6901
+ ]);
6902
+ } finally {
6903
+ await options.cleanup?.(storage);
6904
+ }
6905
+ });
6124
6906
  test8("rejects missing usage and mismatched billed quantities", async () => {
6125
6907
  const storage = await fixture();
6126
6908
  try {
@@ -6232,6 +7014,25 @@ async function seedAiCostStorageContractUsage(executions, usage) {
6232
7014
  occurredAt: new Date("2026-08-03T12:00:00.000Z"),
6233
7015
  recordedAt: new Date("2026-08-03T12:00:00.100Z")
6234
7016
  });
7017
+ for (const [index, occurredAt] of [
7018
+ "2026-11-01T12:00:00.000Z",
7019
+ "2026-11-02T12:00:00.000Z"
7020
+ ].entries()) {
7021
+ await usage.recordModelCall({
7022
+ id: `clock_${index}`,
7023
+ projectId: projectId8,
7024
+ executionId: otherExecutionId,
7025
+ attempt: 1,
7026
+ callId: `clock_${index}`,
7027
+ responseId: `response_clock_${index}`,
7028
+ requesterGroupIds: [],
7029
+ providerId: "gateway",
7030
+ requestedModelId: "clock/model",
7031
+ usage: { inputTokens: 1, outputTokens: 1 },
7032
+ occurredAt: new Date(occurredAt),
7033
+ recordedAt: new Date(occurredAt)
7034
+ });
7035
+ }
6235
7036
  for (const [day, calls, complete, tokens] of [
6236
7037
  [16, 87, 84, 4013782],
6237
7038
  [18, 29, 28, 334815]
@@ -6279,7 +7080,7 @@ var projectId9 = "ai-limit-contract";
6279
7080
  var executionId2 = "exec_ai_limit_1";
6280
7081
  var project = { type: "project" };
6281
7082
  var support = { type: "group", id: "support" };
6282
- var user = { type: "user", id: "user-1" };
7083
+ var user2 = { type: "user", id: "user-1" };
6283
7084
  function at4(value) {
6284
7085
  return new Date(value);
6285
7086
  }
@@ -6289,7 +7090,7 @@ function reservation(callId, tokens, overrides = {}) {
6289
7090
  executionId: executionId2,
6290
7091
  attempt: 1,
6291
7092
  callId,
6292
- subjects: [support, user],
7093
+ subjects: [support, user2],
6293
7094
  estimates: [{ meter: "tokens.total", amount: tokens }],
6294
7095
  reservedAt: at4("2026-08-15T12:00:00.000Z"),
6295
7096
  ...overrides
@@ -6367,7 +7168,7 @@ function runAiLimitStorageContractSuite(label, options) {
6367
7168
  for (const [id, subject, amount] of [
6368
7169
  ["project", project, 10],
6369
7170
  ["support", support, 8],
6370
- ["user", user, 100]
7171
+ ["user", user2, 100]
6371
7172
  ]) {
6372
7173
  await aiLimits.createPolicy({
6373
7174
  id,
@@ -6510,7 +7311,7 @@ function runAiLimitStorageContractSuite(label, options) {
6510
7311
  await aiLimits.createPolicy({
6511
7312
  id: "user-cost",
6512
7313
  projectId: projectId9,
6513
- subject: user,
7314
+ subject: user2,
6514
7315
  limit: {
6515
7316
  meter: "cost.catalogEstimated",
6516
7317
  amount: { currency: "USD", amountNanos: "100" }
@@ -6531,7 +7332,7 @@ function runAiLimitStorageContractSuite(label, options) {
6531
7332
  buckets: [
6532
7333
  { subject: project, estimate: { meter: "tokens.total", amount: 5 } },
6533
7334
  {
6534
- subject: user,
7335
+ subject: user2,
6535
7336
  estimate: {
6536
7337
  meter: "cost.catalogEstimated",
6537
7338
  amount: { currency: "USD", amountNanos: "7" }
@@ -6909,7 +7710,7 @@ function runAiLimitStorageContractSuite(label, options) {
6909
7710
  ["project-subject", project],
6910
7711
  ["support-subject", support],
6911
7712
  ["engineering-subject", engineering],
6912
- ["user-subject", user],
7713
+ ["user-subject", user2],
6913
7714
  ["service-account-subject", serviceAccount]
6914
7715
  ]) {
6915
7716
  await storage.aiLimits.createPolicy({
@@ -7155,9 +7956,9 @@ function runAiLimitStorageContractSuite(label, options) {
7155
7956
  });
7156
7957
  }
7157
7958
  async function seedAiLimitStorageContractExecution(auth, executions) {
7158
- if (!await auth.users.getById({ projectId: projectId9, id: user.id })) {
7959
+ if (!await auth.users.getById({ projectId: projectId9, id: user2.id })) {
7159
7960
  await auth.users.create({
7160
- id: user.id,
7961
+ id: user2.id,
7161
7962
  projectId: projectId9,
7162
7963
  email: "ai-limit-user@example.test",
7163
7964
  createdAt: at4("2026-08-01T00:00:00.000Z"),
@@ -7170,7 +7971,7 @@ async function seedAiLimitStorageContractExecution(auth, executions) {
7170
7971
  await executions.create({
7171
7972
  id: executionId2,
7172
7973
  projectId: projectId9,
7173
- requestedBy: user,
7974
+ requestedBy: user2,
7174
7975
  executor: { type: "primitive", kind: primitive.kind, runId: primitive.runId },
7175
7976
  source: { type: "event", eventId: `test_event:${executionId2}` },
7176
7977
  correlationId: `test_correlation:${executionId2}`,
@@ -9872,6 +10673,103 @@ function runArtifactStorageContractSuite(label, options) {
9872
10673
  expect13((await artifacts.listComments({ projectId: projectId12, id: "art_reviewed" })).map(({ id }) => id)).toEqual(["cmt_other"]);
9873
10674
  });
9874
10675
  });
10676
+ test13("undoes later turns with a turn, back to before the first, as an edit takes them back", async () => {
10677
+ await withStorage(async (artifacts) => {
10678
+ const turnA = { threadId: "thr_a", runId: "run_a" };
10679
+ const turnB = { threadId: "thr_b", runId: "run_b" };
10680
+ const write = (artifactId, turn, updatedAt) => artifacts.publish({
10681
+ ...publishInput({ title: `Turn ${turn.runId}`, origin: turn, updatedAt }, artifactId),
10682
+ turnRunId: turn.runId
10683
+ });
10684
+ await artifacts.create(createInput({ id: "art_plan" }));
10685
+ await write("art_plan", turnA, at6(1));
10686
+ await write("art_plan", turnB, at6(2));
10687
+ await artifacts.create({
10688
+ ...createInput({ id: "art_draft", version: versionInput({ origin: turnA }) }),
10689
+ turnRunId: "run_a"
10690
+ });
10691
+ await write("art_draft", turnB, at6(2));
10692
+ await artifacts.createComment({
10693
+ projectId: projectId12,
10694
+ artifactId: "art_draft",
10695
+ id: "cmt_turn_b",
10696
+ anchor: { revision: 2 },
10697
+ body: "Turn B's note",
10698
+ author: otherOwner,
10699
+ origin: turnB,
10700
+ createdAt: at6(3)
10701
+ });
10702
+ const undone = await artifacts.undoTurnWrites({
10703
+ projectId: projectId12,
10704
+ turnRunId: "run_a",
10705
+ laterTurnRunIds: ["run_b"],
10706
+ requester: owner2
10707
+ });
10708
+ expect13(undone.deleted).toEqual(["art_draft"]);
10709
+ expect13(undone.restored.map(({ artifact }) => artifact.id)).toEqual(["art_plan"]);
10710
+ expect13(await artifacts.get({ projectId: projectId12, id: "art_draft" })).toBeNull();
10711
+ expect13(await artifacts.get({ projectId: projectId12, id: "art_plan" })).toMatchObject({
10712
+ title: "Q3 report",
10713
+ revision: 4,
10714
+ updatedAt: t05
10715
+ });
10716
+ expect13(await artifacts.listRestorePoints({ projectId: projectId12, id: "art_plan" })).toEqual([]);
10717
+ expect13(await artifacts.listTurnWrites({ projectId: projectId12, turnRunId: "run_b" })).toEqual([]);
10718
+ expect13(await artifacts.listThreadIds({ projectId: projectId12, id: "art_plan" })).toEqual(["thr_1"]);
10719
+ expect13(await artifacts.undoTurnWrites({ projectId: projectId12, turnRunId: "run_b" })).toEqual({
10720
+ restored: [],
10721
+ deleted: []
10722
+ });
10723
+ });
10724
+ });
10725
+ test13("keeps what anyone wrote between turns undone together, and the later turn's own undo", async () => {
10726
+ await withStorage(async (artifacts) => {
10727
+ const write = (artifactId, runId, updatedAt) => artifacts.publish({
10728
+ ...publishInput({ title: `Turn ${runId}`, origin: { threadId: "thr_turn", runId }, updatedAt }, artifactId),
10729
+ turnRunId: runId
10730
+ });
10731
+ const person = (artifactId) => artifacts.publish(publishInput({ title: "Person's", origin: undefined, updatedAt: at6(2) }, artifactId));
10732
+ await artifacts.create(createInput({ id: "art_plan" }));
10733
+ await write("art_plan", "run_a", at6(1));
10734
+ await person("art_plan");
10735
+ await write("art_plan", "run_b", at6(3));
10736
+ await artifacts.create({
10737
+ ...createInput({
10738
+ id: "art_draft",
10739
+ version: versionInput({ origin: { threadId: "thr_turn", runId: "run_a" } })
10740
+ }),
10741
+ turnRunId: "run_a"
10742
+ });
10743
+ await person("art_draft");
10744
+ await write("art_draft", "run_b", at6(3));
10745
+ expect13(await artifacts.undoTurnWrites({
10746
+ projectId: projectId12,
10747
+ turnRunId: "run_a",
10748
+ laterTurnRunIds: ["run_b"]
10749
+ })).toEqual({ restored: [], deleted: [] });
10750
+ expect13(await artifacts.get({ projectId: projectId12, id: "art_plan" })).toMatchObject({
10751
+ title: "Turn run_b",
10752
+ revision: 4
10753
+ });
10754
+ expect13(await artifacts.get({ projectId: projectId12, id: "art_draft" })).toMatchObject({
10755
+ title: "Turn run_b",
10756
+ revision: 3
10757
+ });
10758
+ const undone = await artifacts.undoTurnWrites({ projectId: projectId12, turnRunId: "run_b" });
10759
+ expect13(undone.restored.map(({ artifact }) => artifact.id).sort()).toEqual([
10760
+ "art_draft",
10761
+ "art_plan"
10762
+ ]);
10763
+ expect13(await artifacts.get({ projectId: projectId12, id: "art_plan" })).toMatchObject({
10764
+ title: "Person's",
10765
+ revision: 5
10766
+ });
10767
+ expect13(await artifacts.get({ projectId: projectId12, id: "art_draft" })).toMatchObject({
10768
+ title: "Person's",
10769
+ revision: 4
10770
+ });
10771
+ });
10772
+ });
9875
10773
  test13("keeps comments and their replies, oldest first, and resolves and deletes them", async () => {
9876
10774
  await withStorage(async (artifacts) => {
9877
10775
  await artifacts.create(createInput());
@@ -26103,6 +27001,101 @@ function runRunClaimStorageContractSuite(label, options) {
26103
27001
  await expect38(runs.startOrReclaim({ projectId: projectId27, id: "second", execution: held("second"), claimedAt })).resolves.toMatchObject({ outcome: "started" });
26104
27002
  });
26105
27003
  });
27004
+ test38("Sync: runs of every connection of one Sync run one at a time", async () => {
27005
+ await withStorage(async (storage) => {
27006
+ const runs = requireRuns(storage.syncRuns);
27007
+ const queue = (id, connectionId) => queueTestSyncRun(storage, {
27008
+ id,
27009
+ projectId: projectId27,
27010
+ syncId: "inbox",
27011
+ ...connectionId === undefined ? {} : { connectionId },
27012
+ datasetId: "inbox",
27013
+ mode: "merge"
27014
+ });
27015
+ await queue("ada-1", "conn_ada");
27016
+ await queue("grace-1", "conn_grace");
27017
+ await queue("whole-1");
27018
+ await expect38(runs.startOrReclaim({ projectId: projectId27, id: "ada-1", execution: held("ada-1"), claimedAt })).resolves.toMatchObject({ outcome: "started", run: { connectionId: "conn_ada" } });
27019
+ await expect38(runs.startOrReclaim({ projectId: projectId27, id: "grace-1", execution: held("grace-1"), claimedAt })).resolves.toMatchObject({ outcome: "waiting", sibling: { id: "ada-1" } });
27020
+ const ada = await runs.list({ projectId: projectId27, syncId: "inbox", connectionId: "conn_ada" });
27021
+ expect38(ada.runs.map((run) => run.id)).toEqual(["ada-1"]);
27022
+ const whole = await runs.list({ projectId: projectId27, syncId: "inbox", connectionId: null });
27023
+ expect38(whole.runs.map((run) => run.id)).toEqual(["whole-1"]);
27024
+ expect38(whole.runs[0]?.connectionId).toBeUndefined();
27025
+ });
27026
+ });
27027
+ test38("Sync: lists the latest run of each sync and connection", async () => {
27028
+ await withStorage(async (storage) => {
27029
+ const runs = requireRuns(storage.syncRuns);
27030
+ const queue = (id, syncId, minute, connectionId) => queueTestSyncRun(storage, {
27031
+ id,
27032
+ projectId: projectId27,
27033
+ syncId,
27034
+ ...connectionId === undefined ? {} : { connectionId },
27035
+ datasetId: syncId,
27036
+ mode: "merge",
27037
+ queuedAt: new Date(`2100-06-01T12:0${minute}:00.000Z`)
27038
+ });
27039
+ await queue("inbox-ada-old", "inbox", 1, "conn_ada");
27040
+ await queue("inbox-ada-new", "inbox", 2, "conn_ada");
27041
+ await queue("inbox-grace", "inbox", 1, "conn_grace");
27042
+ await queue("calendar-ada", "calendar", 3, "conn_ada");
27043
+ await queue("inbox-whole", "inbox", 4);
27044
+ await queue("other-ada", "other", 5, "conn_ada");
27045
+ const ids = async (input) => (await runs.listLatestByConnection(input)).runs.map((run) => run.id).sort();
27046
+ expect38(await ids({ projectId: projectId27, syncIds: ["inbox", "calendar"] })).toEqual([
27047
+ "calendar-ada",
27048
+ "inbox-ada-new",
27049
+ "inbox-grace"
27050
+ ]);
27051
+ expect38(await ids({ projectId: projectId27, syncIds: ["inbox", "calendar"], connectionIds: ["conn_ada"] })).toEqual(["calendar-ada", "inbox-ada-new"]);
27052
+ expect38(await ids({ projectId: projectId27, syncIds: [] })).toEqual([]);
27053
+ });
27054
+ });
27055
+ test38("Sync: lists only the runs of visible connections, and every run that reads none", async () => {
27056
+ await withStorage(async (storage) => {
27057
+ const runs = requireRuns(storage.syncRuns);
27058
+ const queue = (id, minute, connectionId) => queueTestSyncRun(storage, {
27059
+ id,
27060
+ projectId: projectId27,
27061
+ syncId: "inbox",
27062
+ ...connectionId === undefined ? {} : { connectionId },
27063
+ datasetId: "inbox",
27064
+ mode: "merge",
27065
+ queuedAt: new Date(`2100-06-01T12:0${minute}:00.000Z`)
27066
+ });
27067
+ await queue("whole", 1);
27068
+ await queue("project", 2, "conn_project");
27069
+ await queue("ada", 3, "conn_ada");
27070
+ await queue("grace", 4, "conn_grace");
27071
+ const listed = async (visibleConnectionIds) => {
27072
+ const page = await runs.list({
27073
+ projectId: projectId27,
27074
+ syncId: "inbox",
27075
+ visibleConnectionIds,
27076
+ limit: 2
27077
+ });
27078
+ return { ids: page.runs.map((run) => run.id), total: page.total, hasMore: page.hasMore };
27079
+ };
27080
+ const latest = async (visibleConnectionIds) => {
27081
+ const { runs: found } = await runs.listLatestBySyncIds({
27082
+ projectId: projectId27,
27083
+ syncIds: ["inbox"],
27084
+ ...visibleConnectionIds === undefined ? {} : { visibleConnectionIds }
27085
+ });
27086
+ return found.map((run) => run.id);
27087
+ };
27088
+ expect38(await listed(["conn_project", "conn_ada"])).toEqual({
27089
+ ids: ["ada", "project"],
27090
+ total: 3,
27091
+ hasMore: true
27092
+ });
27093
+ expect38(await listed([])).toEqual({ ids: ["whole"], total: 1, hasMore: false });
27094
+ expect38(await latest(["conn_project", "conn_ada"])).toEqual(["ada"]);
27095
+ expect38(await latest([])).toEqual(["whole"]);
27096
+ expect38(await latest()).toEqual(["grace"]);
27097
+ });
27098
+ });
26106
27099
  test38("Sync: a run of an older version holds no later run back", async () => {
26107
27100
  await withStorage(async (storage) => {
26108
27101
  const runs = requireRuns(storage.syncRuns);
@@ -28785,4 +29778,4 @@ export {
28785
29778
  testRunExecution
28786
29779
  };
28787
29780
 
28788
- //# debugId=B76AB7F7E98C8D4764756E2164756E21
29781
+ //# debugId=B6BCB4EF64FE35B164756E2164756E21