@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
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from "bun:test"
2
2
  import { createHash } from "node:crypto"
3
- import { AGENT_MESSAGE_CONTENT_VERSION } from "../agents/message"
3
+ import { AGENT_MESSAGE_CONTENT_VERSION, type AgentMessagePart } from "../agents/message"
4
4
  import { projectAgentThreadModelContext } from "../agents/thread-context-projection"
5
5
  import type { Principal } from "../auth"
6
6
  import type { FileRef } from "../blob-storage/types"
@@ -108,6 +108,10 @@ function participant(userId: string, addedAt: Date): AgentThreadParticipantRecor
108
108
  }
109
109
  }
110
110
 
111
+ function user(id: string): { readonly type: "user"; readonly id: string } {
112
+ return { type: "user", id }
113
+ }
114
+
111
115
  function execution(
112
116
  token: string,
113
117
  queueLeaseExpiresAt = at("2026-06-23T10:05:00.000Z")
@@ -908,11 +912,15 @@ export function runAgentStorageContractSuite<TStorage extends AgentStorageContra
908
912
  })
909
913
 
910
914
  // Guard proof: drop `movesComputerPlace` from a store's assignComputer; a rename on the same
911
- // folder records a move.
912
- test("moves a computer's thread to another computer or folder, and says when", async () => {
913
- await withStorage(async (storage) => {
915
+ // folder records a move. Drop `runs_on = 'computer'` from assignComputer; a cloud thread gets a
916
+ // computer without running on one. Drop `running` from assertAssignableComputer's cloud check;
917
+ // a running cloud turn loses its thread to the laptop.
918
+ test("moves a thread between the cloud, computers and folders back and forth", async () => {
919
+ await withStorage(async (storage, fixture) => {
914
920
  await storage.threads.create(threadInput({ runsOn: "computer", computer: laptop }))
915
- await storage.threads.create(threadInput({ id: "thr_cloud" }))
921
+ await storage.threads.create(
922
+ threadInput({ id: "thr_cloud", sandboxParams: { repo: "app" } })
923
+ )
916
924
  const thread = { projectId, id: "thr_1" }
917
925
 
918
926
  // The same folder under a new name is no move.
@@ -931,14 +939,109 @@ export function runAgentStorageContractSuite<TStorage extends AgentStorageContra
931
939
  movedAt: at("2026-06-23T12:00:00.000Z"),
932
940
  })
933
941
  await expect(storage.threads.getById(thread)).resolves.toMatchObject({
942
+ runsOn: "computer",
934
943
  computer: elsewhere,
935
944
  movedAt: at("2026-06-23T12:00:00.000Z"),
936
945
  })
937
946
 
947
+ // A cloud turn keeps the thread in the cloud until it finishes, queued or running.
948
+ await createRun(
949
+ storage,
950
+ fixture,
951
+ runInput({
952
+ id: "run_cloud",
953
+ threadId: "thr_cloud",
954
+ spec: { model: { provider: "test", modelId: "large" } },
955
+ execution: execution("cloud"),
956
+ })
957
+ )
938
958
  await expectAgentError(
939
959
  storage.threads.assignComputer({ projectId, id: "thr_cloud", computer: laptop }),
940
- "invalid_input"
960
+ "active_run_exists"
961
+ )
962
+
963
+ await storage.runs.start({ projectId, id: "run_cloud", execution: execution("cloud") })
964
+ await expectAgentError(
965
+ storage.threads.assignComputer({ projectId, id: "thr_cloud", computer: laptop }),
966
+ "active_run_exists"
967
+ )
968
+ await storage.runs.finish({
969
+ projectId,
970
+ id: "run_cloud",
971
+ executionToken: "cloud",
972
+ status: "cancelled",
973
+ })
974
+
975
+ // Idle in the cloud, it moves to the computer, back to the cloud, and to another folder,
976
+ // keeping its cloud sandbox binding for when it returns.
977
+ const toLaptop = await storage.threads.assignComputer({
978
+ projectId,
979
+ id: "thr_cloud",
980
+ computer: laptop,
981
+ movedAt: at("2026-06-23T13:00:00.000Z"),
982
+ })
983
+ expect(toLaptop).toMatchObject({
984
+ runsOn: "computer",
985
+ computer: laptop,
986
+ sandboxParams: { repo: "app" },
987
+ movedAt: at("2026-06-23T13:00:00.000Z"),
988
+ })
989
+ const backToCloud = await storage.threads.moveToCloud({
990
+ projectId,
991
+ id: "thr_cloud",
992
+ movedAt: at("2026-06-23T14:00:00.000Z"),
993
+ })
994
+ expect(backToCloud.thread).not.toHaveProperty("runsOn")
995
+ expect(backToCloud.thread).not.toHaveProperty("computer")
996
+ expect(backToCloud.thread).toMatchObject({
997
+ sandboxParams: { repo: "app" },
998
+ movedAt: at("2026-06-23T14:00:00.000Z"),
999
+ })
1000
+ const backToElsewhere = await storage.threads.assignComputer({
1001
+ projectId,
1002
+ id: "thr_cloud",
1003
+ computer: elsewhere,
1004
+ movedAt: at("2026-06-23T15:00:00.000Z"),
1005
+ })
1006
+ expect(backToElsewhere).toMatchObject({
1007
+ runsOn: "computer",
1008
+ computer: elsewhere,
1009
+ movedAt: at("2026-06-23T15:00:00.000Z"),
1010
+ })
1011
+
1012
+ // A queued computer turn carries its new place across a folder move, and drops it on cloud.
1013
+ await createRun(
1014
+ storage,
1015
+ fixture,
1016
+ runInput({
1017
+ id: "run_with_place",
1018
+ threadId: "thr_cloud",
1019
+ spec: {
1020
+ model: { provider: "test", modelId: "large" },
1021
+ runsOn: "computer",
1022
+ computer: { id: elsewhere.id, folder: elsewhere.folder },
1023
+ },
1024
+ execution: execution("with_place"),
1025
+ })
941
1026
  )
1027
+ await storage.threads.assignComputer({
1028
+ projectId,
1029
+ id: "thr_cloud",
1030
+ computer: laptop,
1031
+ movedAt: at("2026-06-23T16:00:00.000Z"),
1032
+ })
1033
+ expect((await storage.runs.getById({ projectId, id: "run_with_place" }))?.spec).toEqual({
1034
+ model: { provider: "test", modelId: "large" },
1035
+ runsOn: "computer",
1036
+ computer: { id: laptop.id, folder: laptop.folder },
1037
+ })
1038
+ const cloudAgain = await storage.threads.moveToCloud({
1039
+ projectId,
1040
+ id: "thr_cloud",
1041
+ movedAt: at("2026-06-23T17:00:00.000Z"),
1042
+ })
1043
+ expect(cloudAgain.queued?.spec).toEqual({ model: { provider: "test", modelId: "large" } })
1044
+
942
1045
  await expectAgentError(
943
1046
  storage.threads.assignComputer({ projectId, id: "thr_none", computer: laptop }),
944
1047
  "thread_not_found"
@@ -947,9 +1050,101 @@ export function runAgentStorageContractSuite<TStorage extends AgentStorageContra
947
1050
  storage.threads.assignComputer({ ...thread, computer: { ...laptop, id: " " } }),
948
1051
  "invalid_input"
949
1052
  )
950
- expect(await storage.threads.getById({ projectId, id: "thr_cloud" })).not.toHaveProperty(
951
- "computer"
1053
+ })
1054
+ })
1055
+
1056
+ // Guard proof: drop the child-state update from a store's assignComputer; a continuation on
1057
+ // the computer hands its child its out/ back, and a later return to the cloud resumes a
1058
+ // workspace that never saw the computer's work. Drop `parent_thread_id` from that update (sqlite,
1059
+ // pg) or the parent check (in-memory); another conversation's ready workspace is retired too.
1060
+ test("retires a paused child's cloud workspace when its conversation moves to a computer", async () => {
1061
+ await withStorage(async (storage, fixture) => {
1062
+ // Another conversation of the project, idle with a ready workspace of its own.
1063
+ await storage.threads.create(threadInput({ id: "thr_neighbour", sandboxParams: {} }))
1064
+ await createAndStartRun(
1065
+ storage,
1066
+ fixture,
1067
+ runInput({
1068
+ id: "run_neighbour",
1069
+ threadId: "thr_neighbour",
1070
+ execution: execution("neighbour_token", new Date("2099-01-01")),
1071
+ })
952
1072
  )
1073
+ const acquireNeighbour = {
1074
+ projectId,
1075
+ id: "thr_neighbour",
1076
+ action: "acquire" as const,
1077
+ runId: "run_neighbour",
1078
+ executionToken: "neighbour_token",
1079
+ name: "neighbour-workspace",
1080
+ sourceFingerprint: "c".repeat(64),
1081
+ }
1082
+ await storage.threads.transitionSandbox(acquireNeighbour)
1083
+ await storage.threads.transitionSandbox({
1084
+ ...acquireNeighbour,
1085
+ action: "settle",
1086
+ status: "ready",
1087
+ initialized: true,
1088
+ })
1089
+ await storage.runs.finish({
1090
+ projectId,
1091
+ id: "run_neighbour",
1092
+ executionToken: "neighbour_token",
1093
+ status: "succeeded",
1094
+ })
1095
+
1096
+ await createRunningParent(storage, fixture)
1097
+ await createSubagent(storage, fixture)
1098
+ await storage.runs.start({
1099
+ projectId,
1100
+ id: "child_1",
1101
+ execution: execution("child_token", new Date("2099-01-01")),
1102
+ })
1103
+ const acquire = {
1104
+ projectId,
1105
+ id: "thread_child_1",
1106
+ action: "acquire" as const,
1107
+ runId: "child_1",
1108
+ executionToken: "child_token",
1109
+ name: "child-workspace",
1110
+ sourceFingerprint: "b".repeat(64),
1111
+ }
1112
+ await storage.threads.transitionSandbox(acquire)
1113
+ await storage.threads.transitionSandbox({
1114
+ ...acquire,
1115
+ action: "settle",
1116
+ status: "ready",
1117
+ initialized: true,
1118
+ })
1119
+ await storage.runs.finish({
1120
+ projectId,
1121
+ id: "child_1",
1122
+ executionToken: "child_token",
1123
+ status: "succeeded",
1124
+ result: { text: "Looked west." },
1125
+ })
1126
+ await storage.runs.finish({
1127
+ projectId,
1128
+ id: "parent_1",
1129
+ executionToken: "parent_token",
1130
+ status: "succeeded",
1131
+ })
1132
+
1133
+ await storage.threads.assignComputer({
1134
+ projectId,
1135
+ id: "parent_thread",
1136
+ computer: laptop,
1137
+ })
1138
+ await expect(
1139
+ storage.threads.getById({ projectId, id: "thread_child_1" })
1140
+ ).resolves.toMatchObject({
1141
+ sandboxState: { name: "child-workspace", status: "unavailable" },
1142
+ })
1143
+ await expect(
1144
+ storage.threads.getById({ projectId, id: "thr_neighbour" })
1145
+ ).resolves.toMatchObject({
1146
+ sandboxState: { name: "neighbour-workspace", status: "ready" },
1147
+ })
953
1148
  })
954
1149
  })
955
1150
 
@@ -1584,6 +1779,400 @@ export function runAgentStorageContractSuite<TStorage extends AgentStorageContra
1584
1779
  })
1585
1780
  })
1586
1781
 
1782
+ // ── read state ─────────────────────────────────────────────────────────────────────────────
1783
+
1784
+ test("marks how far one person has read, never backwards, by message", async () => {
1785
+ await withStorage(async (storage) => {
1786
+ await storage.threads.create(threadInput())
1787
+ for (const id of ["m1", "m2", "m3"]) {
1788
+ await storage.messages.append({
1789
+ id,
1790
+ projectId,
1791
+ threadId: "thr_1",
1792
+ runId: null,
1793
+ role: "user",
1794
+ authorPrincipal: user("usr_bob"),
1795
+ parts: [{ type: "text", text: id }],
1796
+ createdAt: at("2026-06-23T10:00:00.000Z"),
1797
+ })
1798
+ }
1799
+ const mark = (input: {
1800
+ readonly principal?: { readonly type: "user"; readonly id: string }
1801
+ readonly throughMessageId?: string
1802
+ readonly readAt?: Date
1803
+ }) =>
1804
+ storage.reads.mark({
1805
+ projectId,
1806
+ threadId: "thr_1",
1807
+ principal: input.principal ?? user("usr_1"),
1808
+ ...(input.throughMessageId === undefined
1809
+ ? {}
1810
+ : { throughMessageId: input.throughMessageId }),
1811
+ ...(input.readAt === undefined ? {} : { readAt: input.readAt }),
1812
+ })
1813
+
1814
+ expect(
1815
+ await mark({ throughMessageId: "m2", readAt: at("2026-06-23T11:00:00.000Z") })
1816
+ ).toEqual({
1817
+ threadId: "thr_1",
1818
+ throughSeq: 2,
1819
+ headSeq: 3,
1820
+ unread: 1,
1821
+ readAt: at("2026-06-23T11:00:00.000Z"),
1822
+ })
1823
+
1824
+ // Regression proof: replace the GREATEST/MAX on `through_seq` with a plain assignment;
1825
+ // the stale mark rewinds the phone that read further. Looking still counts: replace the
1826
+ // one on `read_at` with the old value and it keeps 11:00.
1827
+ const back = await mark({ throughMessageId: "m1", readAt: at("2026-06-23T12:00:00.000Z") })
1828
+ expect(back.throughSeq).toBe(2)
1829
+ expect(back.readAt?.toISOString()).toBe("2026-06-23T12:00:00.000Z")
1830
+
1831
+ const earlier = await mark({
1832
+ throughMessageId: "m2",
1833
+ readAt: at("2026-06-23T09:00:00.000Z"),
1834
+ })
1835
+ expect(earlier.readAt?.toISOString()).toBe("2026-06-23T12:00:00.000Z")
1836
+
1837
+ // Done: the newest.
1838
+ expect(await mark({})).toMatchObject({ throughSeq: 3, headSeq: 3, unread: 0 })
1839
+
1840
+ // A message the thread does not hold marks nothing.
1841
+ const other = await mark({ principal: user("usr_2"), throughMessageId: "m_gone" })
1842
+ expect(other).toEqual({ threadId: "thr_1", throughSeq: 0, headSeq: 3, unread: 3 })
1843
+
1844
+ expect(
1845
+ await storage.reads.list({
1846
+ projectId,
1847
+ threadIds: ["thr_1", "thr_1", "thr_missing"],
1848
+ principal: user("usr_2"),
1849
+ })
1850
+ ).toEqual([{ threadId: "thr_1", throughSeq: 0, headSeq: 3, unread: 3 }])
1851
+ await expectAgentError(
1852
+ storage.reads.mark({ projectId, threadId: "thr_missing", principal: user("usr_1") }),
1853
+ "thread_not_found"
1854
+ )
1855
+ })
1856
+ })
1857
+
1858
+ test("counts as unread what someone else wrote", async () => {
1859
+ await withStorage(async (storage) => {
1860
+ const alice = user("usr_1")
1861
+ const bob = user("usr_bob")
1862
+ await storage.threads.create(threadInput())
1863
+
1864
+ const message = (
1865
+ id: string,
1866
+ role: "user" | "assistant",
1867
+ author: Principal,
1868
+ parts: readonly AgentMessagePart[]
1869
+ ) =>
1870
+ storage.messages.append({
1871
+ id,
1872
+ projectId,
1873
+ threadId: "thr_1",
1874
+ runId: null,
1875
+ role,
1876
+ authorPrincipal: author,
1877
+ parts,
1878
+ })
1879
+
1880
+ // Alice asks (1). The answer carries its requester as author (2). Alice resumes a paused
1881
+ // call with approval outcomes only (3). Bob writes (4).
1882
+ await message("m1", "user", alice, [{ type: "text", text: "question" }])
1883
+ await message("m2", "assistant", alice, [{ type: "text", text: "answer" }])
1884
+ await message("m3", "user", alice, [
1885
+ {
1886
+ type: "approval-outcome",
1887
+ approvalId: "apr_1",
1888
+ status: "approved",
1889
+ call: {
1890
+ kind: "action",
1891
+ actionId: "mark-paid",
1892
+ subject: { kind: "object", objectTypeId: "invoice", primaryId: "INV-2041" },
1893
+ },
1894
+ },
1895
+ ])
1896
+ await message("m4", "user", bob, [{ type: "text", text: "hello" }])
1897
+
1898
+ // Removal proof: count `headSeq - throughSeq` instead; Alice reads 4 new where 2 are.
1899
+ const place = (principal: { readonly type: "user"; readonly id: string }) =>
1900
+ storage.reads.list({ projectId, threadIds: ["thr_1"], principal })
1901
+ expect(await place(alice)).toEqual([
1902
+ { threadId: "thr_1", throughSeq: 0, headSeq: 4, unread: 2 },
1903
+ ])
1904
+ expect(await place(bob)).toMatchObject([{ unread: 2 }])
1905
+
1906
+ await storage.reads.mark({
1907
+ projectId,
1908
+ threadId: "thr_1",
1909
+ principal: alice,
1910
+ throughMessageId: "m2",
1911
+ })
1912
+ expect(await place(alice)).toMatchObject([{ throughSeq: 2, unread: 1 }])
1913
+ })
1914
+ })
1915
+
1916
+ test("a retried turn's new answer is unread to whoever read the failed one", async () => {
1917
+ await withStorage(async (storage, fixture) => {
1918
+ // Bob read the failed answer (2). The retry deletes it and its answer takes seq 2 again.
1919
+ // Removal proof: skip the clamp in `deleteByRunId`; Bob stays at 2 and never sees it.
1920
+ const bob = user("usr_bob")
1921
+ await storage.threads.create(threadInput())
1922
+ await storage.messages.append({
1923
+ id: "m1",
1924
+ projectId,
1925
+ threadId: "thr_1",
1926
+ runId: null,
1927
+ role: "user",
1928
+ authorPrincipal: owner,
1929
+ parts: [{ type: "text", text: "first" }],
1930
+ })
1931
+ await createAndStartRun(storage, fixture, runInput({ triggerMessageId: "m1" }))
1932
+ await storage.messages.append({
1933
+ id: "m2",
1934
+ projectId,
1935
+ threadId: "thr_1",
1936
+ runId: "run_1",
1937
+ role: "assistant",
1938
+ authorPrincipal: owner,
1939
+ parts: [{ type: "text", text: "failed answer" }],
1940
+ })
1941
+ await storage.threads.addParticipants(participantsInput(["usr_bob"]))
1942
+ await storage.runs.finish({
1943
+ id: "run_1",
1944
+ projectId,
1945
+ executionToken: "exec_1",
1946
+ status: "failed",
1947
+ })
1948
+
1949
+ await storage.messages.deleteByRunId({ projectId, threadId: "thr_1", runId: "run_1" })
1950
+ const retried = await storage.messages.append({
1951
+ id: "m3",
1952
+ projectId,
1953
+ threadId: "thr_1",
1954
+ runId: null,
1955
+ role: "assistant",
1956
+ authorPrincipal: owner,
1957
+ parts: [{ type: "text", text: "retried answer" }],
1958
+ })
1959
+
1960
+ expect(retried.seq).toBe(2)
1961
+ expect(
1962
+ await storage.reads.list({ projectId, threadIds: ["thr_1"], principal: bob })
1963
+ ).toMatchObject([{ throughSeq: 1, headSeq: 2, unread: 1 }])
1964
+
1965
+ // A stale screen that still shows the failed answer cannot mark the new one read.
1966
+ await storage.reads.mark({
1967
+ projectId,
1968
+ threadId: "thr_1",
1969
+ principal: bob,
1970
+ throughMessageId: "m2",
1971
+ })
1972
+ expect(
1973
+ await storage.reads.list({ projectId, threadIds: ["thr_1"], principal: bob })
1974
+ ).toMatchObject([{ throughSeq: 1, unread: 1 }])
1975
+ })
1976
+ })
1977
+
1978
+ test("retrying an older turn leaves what came after it read", async () => {
1979
+ await withStorage(async (storage, fixture) => {
1980
+ // Run 1 failed after answering (2); Alice asked again (3) and was answered (4); Bob read
1981
+ // through 4. Retrying run 1 deletes 2, which no later message takes: 3 and 4 stay read.
1982
+ // Removal proof: pull places back to before the first deleted message; Bob reads 3 and 4
1983
+ // as new again.
1984
+ const bob = user("usr_bob")
1985
+ await storage.threads.create(threadInput())
1986
+ const message = (id: string, role: "user" | "assistant", runId: string | null) =>
1987
+ storage.messages.append({
1988
+ id,
1989
+ projectId,
1990
+ threadId: "thr_1",
1991
+ runId,
1992
+ role,
1993
+ authorPrincipal: owner,
1994
+ parts: [{ type: "text", text: id }],
1995
+ })
1996
+
1997
+ await message("m1", "user", null)
1998
+ await createAndStartRun(storage, fixture, runInput({ triggerMessageId: "m1" }))
1999
+ await message("m2", "assistant", "run_1")
2000
+ await storage.runs.finish({
2001
+ id: "run_1",
2002
+ projectId,
2003
+ executionToken: "exec_1",
2004
+ status: "failed",
2005
+ })
2006
+ await message("m3", "user", null)
2007
+ await message("m4", "assistant", null)
2008
+ await storage.threads.addParticipants(participantsInput(["usr_bob"]))
2009
+
2010
+ await storage.messages.deleteByRunId({ projectId, threadId: "thr_1", runId: "run_1" })
2011
+
2012
+ expect(
2013
+ await storage.reads.list({ projectId, threadIds: ["thr_1"], principal: bob })
2014
+ ).toMatchObject([{ throughSeq: 4, headSeq: 4, unread: 0 }])
2015
+ })
2016
+ })
2017
+
2018
+ test("an edited message is unread to whoever read past it", async () => {
2019
+ await withStorage(async (storage) => {
2020
+ // Removal proof: skip the clamp in `deleteFromSeq`; Bob stays at 3 and the edit, which
2021
+ // takes seq 2 again, reads as read.
2022
+ const bob = user("usr_bob")
2023
+ await storage.threads.create(threadInput())
2024
+ for (const id of ["m1", "m2", "m3"]) {
2025
+ await storage.messages.append({
2026
+ id,
2027
+ projectId,
2028
+ threadId: "thr_1",
2029
+ runId: null,
2030
+ role: "user",
2031
+ authorPrincipal: owner,
2032
+ parts: [{ type: "text", text: id }],
2033
+ })
2034
+ }
2035
+ await storage.threads.addParticipants(participantsInput(["usr_bob"]))
2036
+ await storage.reads.mark({ projectId, threadId: "thr_1", principal: user("usr_1") })
2037
+
2038
+ await storage.messages.deleteFromSeq({ projectId, threadId: "thr_1", fromSeq: 2 })
2039
+ await storage.messages.append({
2040
+ id: "m2_edited",
2041
+ projectId,
2042
+ threadId: "thr_1",
2043
+ runId: null,
2044
+ role: "user",
2045
+ authorPrincipal: owner,
2046
+ parts: [{ type: "text", text: "edited" }],
2047
+ })
2048
+
2049
+ expect(
2050
+ await storage.reads.list({ projectId, threadIds: ["thr_1"], principal: bob })
2051
+ ).toMatchObject([{ throughSeq: 1, headSeq: 2, unread: 1 }])
2052
+ // The editor's own message is not new to them.
2053
+ expect(
2054
+ await storage.reads.list({ projectId, threadIds: ["thr_1"], principal: user("usr_1") })
2055
+ ).toMatchObject([{ throughSeq: 1, unread: 0 }])
2056
+ })
2057
+ })
2058
+
2059
+ test("starts a participant caught up and drops their row when they leave", async () => {
2060
+ await withStorage(async (storage) => {
2061
+ await storage.threads.create(threadInput())
2062
+ for (const id of ["m1", "m2"]) {
2063
+ await storage.messages.append({
2064
+ id,
2065
+ projectId,
2066
+ threadId: "thr_1",
2067
+ runId: null,
2068
+ role: "user",
2069
+ authorPrincipal: owner,
2070
+ parts: [{ type: "text", text: id }],
2071
+ createdAt: at("2026-06-23T10:00:00.000Z"),
2072
+ })
2073
+ }
2074
+
2075
+ await storage.threads.addParticipants(
2076
+ participantsInput(["usr_bob"], at("2026-06-23T11:00:00.000Z"))
2077
+ )
2078
+ const bobsPlace = () =>
2079
+ storage.reads.list({ projectId, threadIds: ["thr_1"], principal: user("usr_bob") })
2080
+ expect(await bobsPlace()).toEqual([
2081
+ {
2082
+ threadId: "thr_1",
2083
+ throughSeq: 2,
2084
+ headSeq: 2,
2085
+ unread: 0,
2086
+ readAt: at("2026-06-23T11:00:00.000Z"),
2087
+ },
2088
+ ])
2089
+
2090
+ await storage.threads.removeParticipant({
2091
+ projectId,
2092
+ threadId: "thr_1",
2093
+ principal: user("usr_bob"),
2094
+ })
2095
+ expect(await bobsPlace()).toEqual([
2096
+ { threadId: "thr_1", throughSeq: 0, headSeq: 2, unread: 2 },
2097
+ ])
2098
+
2099
+ // A mark that raced his removal leaves a row behind; joining again starts him caught up.
2100
+ // Removal proof: keep `DO NOTHING` on the join's insert; Bob stays at 1.
2101
+ await storage.reads.mark({
2102
+ projectId,
2103
+ threadId: "thr_1",
2104
+ principal: user("usr_bob"),
2105
+ throughMessageId: "m1",
2106
+ })
2107
+ await storage.threads.addParticipants(
2108
+ participantsInput(["usr_bob"], at("2026-06-23T12:00:00.000Z"))
2109
+ )
2110
+ expect(await bobsPlace()).toMatchObject([{ throughSeq: 2, unread: 0 }])
2111
+ })
2112
+ })
2113
+
2114
+ test("a fork keeps its owner's place, clamped to what it copied", async () => {
2115
+ await withStorage(async (storage, fixture) => {
2116
+ await prepareForkSource(storage, fixture)
2117
+ await storage.reads.mark({
2118
+ projectId,
2119
+ threadId: "thr_1",
2120
+ principal: user("usr_2"),
2121
+ throughMessageId: "m4",
2122
+ })
2123
+
2124
+ await storage.threads.fork(forkInput())
2125
+
2126
+ expect(
2127
+ await storage.reads.list({
2128
+ projectId,
2129
+ threadIds: ["thr_fork"],
2130
+ principal: user("usr_2"),
2131
+ })
2132
+ ).toMatchObject([{ throughSeq: 4 }])
2133
+ })
2134
+ })
2135
+
2136
+ test("reads each thread's newest run, by creation then id", async () => {
2137
+ await withStorage(async (storage, fixture) => {
2138
+ for (const id of ["thr_1", "thr_2", "thr_3"]) {
2139
+ await storage.threads.create(threadInput({ id }))
2140
+ }
2141
+
2142
+ const run = async (
2143
+ id: string,
2144
+ threadId: string,
2145
+ createdAt: string,
2146
+ status: "succeeded" | "failed"
2147
+ ) => {
2148
+ await createAndStartRun(
2149
+ storage,
2150
+ fixture,
2151
+ runInput({ id, threadId, createdAt: at(createdAt), execution: execution(`exec_${id}`) })
2152
+ )
2153
+ await storage.runs.finish({ id, projectId, executionToken: `exec_${id}`, status })
2154
+ }
2155
+
2156
+ // A failed turn, then its retry: the retry is newest, so nothing reads as failed.
2157
+ await run("run_1", "thr_1", "2026-06-23T10:00:10.000Z", "failed")
2158
+ await run("run_2", "thr_1", "2026-06-23T10:00:20.000Z", "succeeded")
2159
+ // Created in the same millisecond: the id decides.
2160
+ await run("run_b", "thr_2", "2026-06-23T10:00:30.000Z", "failed")
2161
+ await run("run_c", "thr_2", "2026-06-23T10:00:30.000Z", "succeeded")
2162
+
2163
+ // Removal proof: order by `created_at` ascending; thr_1 reads run_1 and stays failed.
2164
+ const latest = await storage.runs.latestByThread({
2165
+ projectId,
2166
+ threadIds: ["thr_1", "thr_2", "thr_3", "thr_missing"],
2167
+ })
2168
+ expect(latest.map((entry) => [entry.threadId, entry.id, entry.status]).sort()).toEqual([
2169
+ ["thr_1", "run_2", "succeeded"],
2170
+ ["thr_2", "run_c", "succeeded"],
2171
+ ])
2172
+ expect(await storage.runs.latestByThread({ projectId, threadIds: [] })).toEqual([])
2173
+ })
2174
+ })
2175
+
1587
2176
  // ── durable queued runs ────────────────────────────────────────────────────────────────────
1588
2177
 
1589
2178
  test("creates a queued run before execution and claims the thread", async () => {
@@ -3636,5 +4225,175 @@ export function runAgentStorageContractSuite<TStorage extends AgentStorageContra
3636
4225
  expect(await storage.checkpoints.getLatest({ projectId, threadId: "thr_fork" })).toBeNull()
3637
4226
  })
3638
4227
  })
4228
+
4229
+ test("deletes messages from a sequence onward, repairs thread stats, and reuses the sequence", async () => {
4230
+ // Removal proof: skip recounting countsAsThreadMessage in deleteFromSeq; uncounted resume
4231
+ // messages subtract from messageCount and leave it wrong.
4232
+ await withStorage(async (storage) => {
4233
+ await storage.threads.create(threadInput({ id: "thr_rewind" }))
4234
+ const t1 = at("2026-06-23T10:00:00.000Z")
4235
+ const t2 = at("2026-06-23T10:01:00.000Z")
4236
+ const t3 = at("2026-06-23T10:02:00.000Z")
4237
+ await storage.messages.append({
4238
+ id: "m1",
4239
+ projectId,
4240
+ threadId: "thr_rewind",
4241
+ runId: null,
4242
+ role: "user",
4243
+ parts: [{ type: "text", text: "First" }],
4244
+ createdAt: t1,
4245
+ })
4246
+ await storage.messages.append({
4247
+ id: "m2",
4248
+ projectId,
4249
+ threadId: "thr_rewind",
4250
+ runId: null,
4251
+ role: "user",
4252
+ parts: [
4253
+ {
4254
+ type: "approval-outcome",
4255
+ approvalId: "apr_1",
4256
+ status: "denied",
4257
+ call: { kind: "workflow", workflowId: "wf_1" },
4258
+ },
4259
+ ],
4260
+ createdAt: t2,
4261
+ })
4262
+ await storage.messages.append({
4263
+ id: "m3",
4264
+ projectId,
4265
+ threadId: "thr_rewind",
4266
+ runId: null,
4267
+ role: "user",
4268
+ parts: [{ type: "text", text: "Second" }],
4269
+ createdAt: t3,
4270
+ })
4271
+ expect(await storage.threads.getById({ projectId, id: "thr_rewind" })).toMatchObject({
4272
+ messageCount: 2,
4273
+ lastMessageAt: t3,
4274
+ })
4275
+
4276
+ await expectAgentError(
4277
+ storage.messages.deleteFromSeq({ projectId, threadId: "thr_rewind", fromSeq: 0 }),
4278
+ "invalid_input"
4279
+ )
4280
+ await expectAgentError(
4281
+ storage.messages.deleteFromSeq({ projectId, threadId: "missing", fromSeq: 1 }),
4282
+ "thread_not_found"
4283
+ )
4284
+
4285
+ expect(
4286
+ await storage.messages.deleteFromSeq({ projectId, threadId: "thr_rewind", fromSeq: 2 })
4287
+ ).toBe(2)
4288
+ expect(await storage.threads.getById({ projectId, id: "thr_rewind" })).toMatchObject({
4289
+ messageCount: 1,
4290
+ lastMessageAt: t1,
4291
+ })
4292
+
4293
+ const replacement = await storage.messages.append({
4294
+ id: "m2_next",
4295
+ projectId,
4296
+ threadId: "thr_rewind",
4297
+ runId: null,
4298
+ role: "user",
4299
+ parts: [{ type: "text", text: "Edited second" }],
4300
+ createdAt: at("2026-06-23T10:05:00.000Z"),
4301
+ })
4302
+ expect(replacement.seq).toBe(2)
4303
+
4304
+ expect(
4305
+ await storage.messages.deleteFromSeq({ projectId, threadId: "thr_rewind", fromSeq: 1 })
4306
+ ).toBe(2)
4307
+ expect(await storage.threads.getById({ projectId, id: "thr_rewind" })).toMatchObject({
4308
+ messageCount: 0,
4309
+ lastMessageAt: undefined,
4310
+ })
4311
+ })
4312
+ })
4313
+
4314
+ test("deletes chained checkpoints past a retained sequence without violating chain foreign keys", async () => {
4315
+ // Removal proof: delete checkpoints in ascending order on SQLite/Postgres; previous_checkpoint_id
4316
+ // ON DELETE RESTRICT rejects deleting checkpoint_1 while checkpoint_2 references it.
4317
+ await withStorage(async (storage, fixture) => {
4318
+ await storage.threads.create(threadInput({ id: "thr_cp" }))
4319
+ for (let i = 1; i <= 3; i += 1) {
4320
+ await storage.messages.append({
4321
+ id: `u_${i}`,
4322
+ projectId,
4323
+ threadId: "thr_cp",
4324
+ runId: null,
4325
+ role: "user",
4326
+ parts: [{ type: "text", text: `Prompt ${i}` }],
4327
+ })
4328
+ const runId = `run_cp_${i}`
4329
+ await createAndStartRun(
4330
+ storage,
4331
+ fixture,
4332
+ runInput({
4333
+ id: runId,
4334
+ threadId: "thr_cp",
4335
+ triggerMessageId: `u_${i}`,
4336
+ execution: execution(`tok_${i}`),
4337
+ })
4338
+ )
4339
+ if (i >= 2) {
4340
+ const headSeq = (i - 1) * 2 + 1
4341
+ await storage.checkpoints.create({
4342
+ id: `cp_${i - 1}`,
4343
+ projectId,
4344
+ threadId: "thr_cp",
4345
+ createdByRunId: runId,
4346
+ expectedPreviousCheckpointId: i === 2 ? null : `cp_${i - 2}`,
4347
+ expectedHeadSeq: headSeq,
4348
+ executionToken: `tok_${i}`,
4349
+ reason: "threshold",
4350
+ summary: `Summary through turn ${i - 1}`,
4351
+ summaryFormatVersion: 1,
4352
+ summarizedThroughSeq: headSeq - 1,
4353
+ observedHeadSeq: headSeq,
4354
+ estimatedInputTokensBefore: 1000,
4355
+ estimatedInputTokensAfter: 300,
4356
+ summaryModelId: "test-model",
4357
+ })
4358
+ }
4359
+ await storage.messages.append({
4360
+ id: `a_${i}`,
4361
+ projectId,
4362
+ threadId: "thr_cp",
4363
+ runId,
4364
+ role: "assistant",
4365
+ parts: [{ type: "text", text: `Reply ${i}` }],
4366
+ })
4367
+ await storage.runs.finish({
4368
+ projectId,
4369
+ id: runId,
4370
+ executionToken: `tok_${i}`,
4371
+ status: "succeeded",
4372
+ })
4373
+ }
4374
+
4375
+ // Rewinding to seq 5 (u_3) deletes cp_2 (observedHeadSeq 5) and keeps cp_1 (observedHeadSeq 3).
4376
+ expect(
4377
+ await storage.checkpoints.deleteAfterSeq({
4378
+ projectId,
4379
+ threadId: "thr_cp",
4380
+ afterSeq: 4,
4381
+ })
4382
+ ).toBe(1)
4383
+ expect((await storage.checkpoints.getLatest({ projectId, threadId: "thr_cp" }))?.id).toBe(
4384
+ "cp_1"
4385
+ )
4386
+
4387
+ // Rewinding to seq 1 deletes the remaining chain cleanly.
4388
+ expect(
4389
+ await storage.checkpoints.deleteAfterSeq({
4390
+ projectId,
4391
+ threadId: "thr_cp",
4392
+ afterSeq: 0,
4393
+ })
4394
+ ).toBe(1)
4395
+ expect(await storage.checkpoints.getLatest({ projectId, threadId: "thr_cp" })).toBeNull()
4396
+ })
4397
+ })
3639
4398
  })
3640
4399
  }