@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
@@ -41,6 +41,8 @@ import type {
41
41
  ConversationAgentRunSpec,
42
42
  CreateAgentContextCheckpointInput,
43
43
  CreateSubagentRunInput,
44
+ DeleteAgentContextCheckpointsAfterSeqInput,
45
+ DeleteAgentMessagesFromSeqInput,
44
46
  EnqueueAgentInboxItemInput,
45
47
  FinishAgentRunInput,
46
48
  ForkAgentThreadInput,
@@ -294,17 +296,37 @@ export interface AgentThreadForkPlan {
294
296
  readonly thread: AgentThreadRecord
295
297
  /** The source messages to copy, in `seq` order, with the id of each copy. */
296
298
  readonly messages: readonly { readonly sourceId: string; readonly id: string }[]
299
+ /** The seq of the last message copied, 0 when none: the copy's newest, as copies keep theirs. */
300
+ readonly headSeq: number
297
301
  readonly checkpoint?: AgentContextCheckpointRecord
298
302
  }
299
303
 
300
- /**
301
- * Decide what a fork copies. While a turn is running, the fork copies what came before its trigger
302
- * message, so the copy never has a gap; otherwise it copies everything. Copies keep their `seq`,
303
- * so the latest checkpoint whose observed head was copied projects unchanged.
304
- *
305
- * The plan mints the ids of the copies: which messages are copied is only known here, under the
306
- * provider's lock, so the caller cannot supply them.
307
- */
304
+ /** `fromSeq` names a message of the thread: sequences start at 1. */
305
+ export function assertDeleteAgentMessagesFromSeqInput(
306
+ input: DeleteAgentMessagesFromSeqInput,
307
+ prefix = "Sixb"
308
+ ): void {
309
+ if (!Number.isSafeInteger(input.fromSeq) || input.fromSeq < 1) {
310
+ throw new AgentStorageError(
311
+ "invalid_input",
312
+ `[${prefix}] Agent message 'fromSeq' must be a positive safe integer.`
313
+ )
314
+ }
315
+ }
316
+
317
+ /** `afterSeq` is the last sequence whose summaries stay: 0 keeps none. */
318
+ export function assertDeleteAgentContextCheckpointsAfterSeqInput(
319
+ input: DeleteAgentContextCheckpointsAfterSeqInput,
320
+ prefix = "Sixb"
321
+ ): void {
322
+ if (!Number.isSafeInteger(input.afterSeq) || input.afterSeq < 0) {
323
+ throw new AgentStorageError(
324
+ "invalid_input",
325
+ `[${prefix}] Agent context checkpoint 'afterSeq' must be a non-negative safe integer.`
326
+ )
327
+ }
328
+ }
329
+
308
330
  /**
309
331
  * Whether a message counts in its thread's `messageCount`, which reads as what the conversation
310
332
  * shows. The message Sixb writes to resume a paused turn carries only how its calls ended, which the
@@ -316,6 +338,32 @@ export function countsAsThreadMessage(message: Pick<AgentMessageRecord, "parts">
316
338
  )
317
339
  }
318
340
 
341
+ /**
342
+ * Whether a message past a reader's place is new to them: every Agent answer and every other
343
+ * person's message. What they wrote themselves is not, and neither is a message the thread does
344
+ * not count. An Agent answer carries its requester as author, so only a user message is theirs.
345
+ * The SQL providers say the same in their `unread` count.
346
+ */
347
+ export function isUnreadFor(
348
+ message: Pick<AgentMessageRecord, "role" | "authorPrincipal" | "parts">,
349
+ reader: UserPrincipal
350
+ ): boolean {
351
+ if (!countsAsThreadMessage(message)) return false
352
+
353
+ const author = message.authorPrincipal
354
+ const ownMessage = message.role === "user" && author?.type === "user" && author.id === reader.id
355
+
356
+ return !ownMessage
357
+ }
358
+
359
+ /**
360
+ * Decide what a fork copies. While a turn is running, the fork copies what came before its trigger
361
+ * message, so the copy never has a gap; otherwise it copies everything. Copies keep their `seq`,
362
+ * so the latest checkpoint whose observed head was copied projects unchanged.
363
+ *
364
+ * The plan mints the ids of the copies: which messages are copied is only known here, under the
365
+ * provider's lock, so the caller cannot supply them.
366
+ */
319
367
  export function planAgentThreadFork(
320
368
  input: ForkAgentThreadInput,
321
369
  source: AgentThreadForkSource,
@@ -360,6 +408,7 @@ export function planAgentThreadFork(
360
408
  return {
361
409
  thread,
362
410
  messages: copied.map((message) => ({ sourceId: message.id, id: createAgentMessageId() })),
411
+ headSeq: lastCopiedSeq,
363
412
  ...(checkpoint === undefined
364
413
  ? {}
365
414
  : {
@@ -466,6 +515,12 @@ export function assertConversationAgentRunSpec(
466
515
  }
467
516
  assertApprovalModeField(spec.approvalMode, "Conversational Agent run", prefix)
468
517
  assertRunsOn(spec.runsOn, "Conversational Agent run", prefix)
518
+ if (spec.computer !== undefined) {
519
+ if (spec.runsOn !== "computer") {
520
+ throw new AgentStorageError("invalid_input", `[${prefix}] Only a computer's turn names one.`)
521
+ }
522
+ assertAgentThreadPlace(spec.computer, prefix)
523
+ }
469
524
  }
470
525
 
471
526
  /** Validate where a thread or turn runs: `computer`, or absent for the cloud. */
@@ -478,6 +533,33 @@ export function assertRunsOn(value: unknown, subject: string, prefix = "Sixb"):
478
533
  }
479
534
  }
480
535
 
536
+ /**
537
+ * Validate which computer and folder a turn ran in. Both are shown back to its owner, so neither
538
+ * holds a control character.
539
+ */
540
+ export function assertAgentThreadPlace(
541
+ value: unknown,
542
+ prefix = "Sixb"
543
+ ): asserts value is AgentThreadPlace {
544
+ const place = value as Partial<AgentThreadPlace> | null
545
+ for (const [field, text, max] of [
546
+ ["id", place?.id, 200],
547
+ ["folder", place?.folder, 4096],
548
+ ] as const) {
549
+ if (
550
+ typeof text !== "string" ||
551
+ text.trim() === "" ||
552
+ text.length > max ||
553
+ CONTROL_CHARACTER.test(text)
554
+ ) {
555
+ throw new AgentStorageError(
556
+ "invalid_input",
557
+ `[${prefix}] A turn's computer '${field}' must be a non-blank string of at most ${max} characters, without control characters.`
558
+ )
559
+ }
560
+ }
561
+ }
562
+
481
563
  /**
482
564
  * Validate where on a computer a thread runs: the CLI's id for the computer, its name, and the
483
565
  * folder there. All are shown back to its owner, so none holds a control character.
@@ -595,8 +677,8 @@ export const CONTROL_CHARACTER =
595
677
  /[\u0000-\u001f\u007f-\u009f\u200e\u200f\u202a-\u202e\u2066-\u2069]/
596
678
 
597
679
  /**
598
- * Refuse to assign a computer to a thread that runs in the cloud, or does not exist, or to move one
599
- * while a turn runs in its folder.
680
+ * Refuse to assign a computer to a sub-agent's thread or one that does not exist, to move a cloud
681
+ * thread while a turn holds it, or to move a computer's thread while a turn runs in its folder.
600
682
  */
601
683
  export function assertAssignableComputer(
602
684
  thread: AgentThreadRecord | null,
@@ -608,12 +690,23 @@ export function assertAssignableComputer(
608
690
  if (!thread) {
609
691
  throw new AgentStorageError("thread_not_found", `[${prefix}] Agent thread '${id}' not found.`)
610
692
  }
611
- if (thread.runsOn !== "computer") {
693
+ if (thread.kind !== "conversation") {
612
694
  throw new AgentStorageError(
613
695
  "invalid_input",
614
- `[${prefix}] Agent thread '${id}' runs in the cloud: no computer runs its turns.`
696
+ `[${prefix}] Sub-agent thread '${id}' never runs on a computer.`
615
697
  )
616
698
  }
699
+ if (thread.runsOn !== "computer") {
700
+ // A turn in flight, or one waiting for its computer, would be left where nothing runs it. A
701
+ // turn paused on held calls passes here: the caller refuses that, with its approvals in view.
702
+ if (activeRun?.status === "queued" || activeRun?.status === "running") {
703
+ throw new AgentStorageError(
704
+ "active_run_exists",
705
+ `[${prefix}] A turn of Agent thread '${id}' is in progress in the cloud: stop it, or let it end, first.`
706
+ )
707
+ }
708
+ return
709
+ }
617
710
  if (movesComputerPlace(thread, computer)) assertNoTurnRunning(activeRun, id, prefix)
618
711
  }
619
712
 
@@ -703,15 +796,62 @@ export function queuedTurnInCloud(
703
796
  ): ConversationAgentRunRecord | undefined {
704
797
  if (active?.kind !== "conversation" || active.status !== "queued") return undefined
705
798
  if (active.spec?.runsOn !== "computer") return undefined
706
- const { runsOn: _runsOn, ...cloud } = active.spec
799
+ const { runsOn: _runsOn, computer: _computer, ...cloud } = active.spec
707
800
  return { ...active, spec: cloud }
708
801
  }
709
802
 
803
+ /** The queued turn of a computer's thread that moves to another folder, with its new place. */
804
+ export function queuedTurnOnComputer(
805
+ active: AgentRunRecord | null,
806
+ computer: AgentThreadPlace
807
+ ): ConversationAgentRunRecord | undefined {
808
+ if (active?.kind !== "conversation" || active.status !== "queued") return undefined
809
+ if (active.spec?.runsOn !== "computer" || active.spec.computer === undefined) return undefined
810
+ const place = { id: computer.id, folder: computer.folder }
811
+ if (sameComputerPlace(active.spec.computer, place)) return undefined
812
+ return { ...active, spec: { ...active.spec, computer: place } }
813
+ }
814
+
815
+ /**
816
+ * Mark a paused sub-agent's saved cloud workspace unavailable when its conversation leaves the
817
+ * cloud: a continuation on the computer updates out/, so a later return to the cloud starts fresh.
818
+ */
819
+ export function unavailableChildSandboxState(
820
+ state: AgentThreadSandboxState | undefined
821
+ ): AgentThreadSandboxState | undefined {
822
+ if (!state || (state.status !== "ready" && state.status !== "new")) return undefined
823
+ return { ...state, status: "unavailable" }
824
+ }
825
+
710
826
  /** Whether two places are the same folder of the same computer, whatever they call it. */
711
827
  export function sameComputerPlace(a: AgentThreadPlace, b: AgentThreadPlace): boolean {
712
828
  return a.id === b.id && a.folder === b.folder
713
829
  }
714
830
 
831
+ /** Where a turn runs, as its spec records it: the cloud, or a folder of its owner's computer. */
832
+ export type AgentTurnPlace = Pick<ConversationAgentRunSpec, "runsOn" | "computer">
833
+
834
+ /** The place a turn's spec records, from its thread's: the cloud, or a computer and its folder. */
835
+ export function turnPlace(
836
+ runsOn: "computer" | undefined,
837
+ computer: AgentThreadPlace | undefined
838
+ ): AgentTurnPlace {
839
+ if (runsOn === undefined) return {}
840
+
841
+ return computer
842
+ ? { runsOn, computer: Object.freeze({ id: computer.id, folder: computer.folder }) }
843
+ : { runsOn }
844
+ }
845
+
846
+ /**
847
+ * The same key for two turns that ran in the same workspace: the cloud, or one folder of one
848
+ * computer. A computer's turn from before folders were kept ran in a folder nobody knows.
849
+ */
850
+ export function runPlaceKey(spec: AgentTurnPlace | undefined): string {
851
+ if (spec?.runsOn !== "computer") return "cloud"
852
+ return spec.computer ? `computer:${spec.computer.id}:${spec.computer.folder}` : "computer"
853
+ }
854
+
715
855
  export function isAgentApprovalMode(value: unknown): value is AgentApprovalMode {
716
856
  return (AGENT_APPROVAL_MODES as readonly unknown[]).includes(value)
717
857
  }
@@ -1648,6 +1788,15 @@ export function assertEnqueueAgentInboxItemInput(
1648
1788
  assertAgentInboxParts(input.parts, input.mode, prefix)
1649
1789
  assertAgentInboxSpec(input.spec, prefix)
1650
1790
  if (input.executionId !== undefined) assertNonEmptyText(input.executionId, "executionId", prefix)
1791
+ if (input.replacesMessageId !== undefined) {
1792
+ assertNonEmptyText(input.replacesMessageId, "replacesMessageId", prefix)
1793
+ if (input.mode !== "queue" || input.immediate !== true) {
1794
+ throw new AgentStorageError(
1795
+ "invalid_input",
1796
+ `[${prefix}] An agent inbox item that replaces a message is a queued message sent now.`
1797
+ )
1798
+ }
1799
+ }
1651
1800
  }
1652
1801
 
1653
1802
  /**
@@ -1769,6 +1918,7 @@ export function newAgentInboxItemRecord(
1769
1918
  ...(input.timeZone ? { timeZone: input.timeZone } : {}),
1770
1919
  ...(input.locale ? { locale: input.locale } : {}),
1771
1920
  ...(input.immediate ? { immediate: true } : {}),
1921
+ ...(input.replacesMessageId ? { replacesMessageId: input.replacesMessageId } : {}),
1772
1922
  ...(input.executionId ? { executionId: input.executionId } : {}),
1773
1923
  createdAt,
1774
1924
  updatedAt: new Date(createdAt),
@@ -1794,6 +1944,13 @@ export function updatedAgentInboxItemRecord(
1794
1944
  const nextImmediate = input.immediate === undefined ? current.immediate : input.immediate
1795
1945
  const { spec: _oldSpec, immediate: _oldImmediate, ...base } = current
1796
1946
  const mode = input.mode ?? current.mode
1947
+ // An edit rewinds the thread when it starts: it goes now, after the turn it stopped.
1948
+ if (current.replacesMessageId !== undefined && (mode !== "queue" || nextImmediate !== true)) {
1949
+ throw new AgentStorageError(
1950
+ "invalid_state",
1951
+ `[Sixb] Agent inbox item '${current.id}' edits message '${current.replacesMessageId}': it stays a message sent now.`
1952
+ )
1953
+ }
1797
1954
  const parts =
1798
1955
  input.parts !== undefined ? structuredClone(input.parts) : structuredClone(current.parts)
1799
1956
  // Promoting a message that carries a file to a steer would read bytes a replay cannot send.
@@ -306,6 +306,76 @@ export interface ListAgentThreadParticipantsInput {
306
306
  readonly threadIds: readonly string[]
307
307
  }
308
308
 
309
+ // ── agent_thread_reads — how far each person has read a conversation ──────────────────────────
310
+
311
+ /**
312
+ * How far one person's reading of a conversation has reached, as the `seq` of its last message.
313
+ *
314
+ * A watermark, not a flag: nothing writes here when a message arrives, so new ones sit past it
315
+ * until the reader moves it. A mark never moves it backwards, so two devices converge on the later
316
+ * position and a stale one cannot rewind the other. Only a deletion does: when a retry or an edit
317
+ * takes the newest messages away, every place past what remains comes back to it, because the next
318
+ * messages take those numbers again.
319
+ */
320
+ export interface AgentThreadReadRecord {
321
+ readonly projectId: string
322
+ readonly threadId: string
323
+ readonly principal: UserPrincipal
324
+ /** The highest message `seq` this person's reading has reached. 0 when none has. */
325
+ readonly throughSeq: number
326
+ /** When this person last looked: every mark sets it, even one that leaves `throughSeq` alone. */
327
+ readonly readAt: Date
328
+ }
329
+
330
+ /**
331
+ * One person's place in a conversation, and what arrived past it.
332
+ *
333
+ * `unread` counts the messages past `throughSeq` that are new to them: every Agent answer and
334
+ * every other person's message. What they wrote is not, nor a message that only reports how
335
+ * approved calls ended (`countsAsThreadMessage`).
336
+ */
337
+ export interface AgentThreadReadState {
338
+ readonly threadId: string
339
+ /** Where their reading reached, never past `headSeq`. 0 when they have no row. */
340
+ readonly throughSeq: number
341
+ /** The `seq` of the thread's newest message, 0 when it has none. */
342
+ readonly headSeq: number
343
+ /** Messages past `throughSeq` that someone else wrote. */
344
+ readonly unread: number
345
+ /** When they last looked; absent until they have a row. */
346
+ readonly readAt?: Date
347
+ }
348
+
349
+ export interface MarkAgentThreadReadInput {
350
+ readonly projectId: string
351
+ readonly threadId: string
352
+ readonly principal: UserPrincipal
353
+ /**
354
+ * The last message they read, or the thread's newest when absent. A message the thread no longer
355
+ * holds marks nothing: a retry or an edit took it away, and its number may already name another.
356
+ */
357
+ readonly throughMessageId?: string
358
+ readonly readAt?: Date
359
+ }
360
+
361
+ export interface ListAgentThreadReadsInput {
362
+ readonly projectId: string
363
+ readonly threadIds: readonly string[]
364
+ readonly principal: UserPrincipal
365
+ }
366
+
367
+ export interface AgentThreadReadStore {
368
+ /**
369
+ * Record that this person's reading reached a message, never moving it back, and that they
370
+ * looked now. A participant has a row from the moment they join, and the migration gave one to
371
+ * everyone in the threads that existed before; an owner without one reads as 0 until their
372
+ * first mark. Answers their place afterwards.
373
+ */
374
+ mark(input: MarkAgentThreadReadInput): Promise<AgentThreadReadState>
375
+ /** One person's place in each of these threads; a thread that does not exist is absent. */
376
+ list(input: ListAgentThreadReadsInput): Promise<readonly AgentThreadReadState[]>
377
+ }
378
+
309
379
  // ── agent_runs — one loop execution (the worker job; attribution + fencing) ───────────────────
310
380
 
311
381
  /** Lifecycle shared by every durable agent execution, conversational or workflow-owned. */
@@ -452,6 +522,11 @@ export interface ConversationAgentRunSpec {
452
522
  readonly approvalMode?: AgentApprovalMode
453
523
  /** Its thread's `runsOn` when it was asked for: a computer's turn never reaches the agent queue. */
454
524
  readonly runsOn?: "computer"
525
+ /**
526
+ * Which computer and folder the turn ran in: captured with `runsOn: "computer"` and updated if a
527
+ * queued turn moves to another folder before starting.
528
+ */
529
+ readonly computer?: AgentThreadPlace
455
530
  }
456
531
 
457
532
  /** Immutable, serialisable child configuration captured before dispatch. */
@@ -638,6 +713,8 @@ export interface ListThreadSubagentsInput {
638
713
  readonly threadId: string
639
714
  readonly spawnKey?: string
640
715
  readonly finishReason?: AgentRunFinishReason
716
+ /** Only children spawned by turns whose trigger message is still in the thread. */
717
+ readonly retainedTurnsOnly?: boolean
641
718
  /** At most this many, 100 by default. */
642
719
  readonly limit?: number
643
720
  }
@@ -648,6 +725,11 @@ export interface ListAgentRunsResult {
648
725
  readonly total: number
649
726
  }
650
727
 
728
+ export interface ListLatestAgentRunsInput {
729
+ readonly projectId: string
730
+ readonly threadIds: readonly string[]
731
+ }
732
+
651
733
  // ── agent_messages — one message (assistant messages inserted only once finalized) ─────────────
652
734
 
653
735
  export type { AgentMessageRole }
@@ -688,6 +770,13 @@ export interface AppendAgentMessageInput extends AgentMessage {
688
770
  readonly completedAt?: Date
689
771
  }
690
772
 
773
+ export interface DeleteAgentMessagesFromSeqInput {
774
+ readonly projectId: string
775
+ readonly threadId: string
776
+ /** Delete every message whose per-thread sequence is greater than or equal to this boundary. */
777
+ readonly fromSeq: number
778
+ }
779
+
691
780
  export interface DeleteAgentMessagesByRunInput {
692
781
  readonly projectId: string
693
782
  readonly threadId: string
@@ -796,8 +885,9 @@ export interface AgentThreadStore {
796
885
  /** Whether the user took part until now. */
797
886
  removeParticipant(input: RemoveAgentThreadParticipantInput): Promise<boolean>
798
887
  /**
799
- * Move a computer's thread to another computer or folder, and return the thread after. A cloud
800
- * thread runs on none, and is refused.
888
+ * Move a conversation thread to a computer and folder, from the cloud or from another computer or
889
+ * folder, and return the thread after. Refused while a turn holds a cloud thread or runs on its
890
+ * computer.
801
891
  */
802
892
  assignComputer(input: AssignAgentThreadComputerInput): Promise<AgentThreadRecord>
803
893
  /**
@@ -857,18 +947,35 @@ export interface AgentRunStore {
857
947
  * within a turn the latest admitted first. Read by key (one per turn) or by finish reason.
858
948
  */
859
949
  listThreadSubagents(input: ListThreadSubagentsInput): Promise<readonly SubagentRunRecord[]>
950
+ /** The newest run of each thread, by creation and id; a thread without one is absent. */
951
+ latestByThread(input: ListLatestAgentRunsInput): Promise<readonly AgentRunRecord[]>
860
952
  list(input: ListAgentRunsInput): Promise<ListAgentRunsResult>
861
953
  }
862
954
 
863
955
  export interface AgentMessageStore {
864
956
  /** Insert a message (its `parts` are the canonical content) and bump thread stats. */
865
957
  append(input: AppendAgentMessageInput): Promise<AgentMessageRecord>
866
- /** Delete every message produced by one run and repair the thread's message stats. */
958
+ /**
959
+ * Delete every message produced by one run and repair the thread's message stats. A reader's
960
+ * place past the newest message left comes back to it: the next message reuses those numbers.
961
+ */
867
962
  deleteByRunId(input: DeleteAgentMessagesByRunInput): Promise<number>
963
+ /**
964
+ * Delete every message at or after `fromSeq` and repair the thread's message stats. A reader's
965
+ * place past the newest message left comes back to it: the edit that follows reuses the numbers.
966
+ */
967
+ deleteFromSeq(input: DeleteAgentMessagesFromSeqInput): Promise<number>
868
968
  getById(params: { projectId: string; id: string }): Promise<AgentMessageRecord | null>
869
969
  list(input: ListAgentMessagesInput): Promise<ListAgentMessagesResult>
870
970
  }
871
971
 
972
+ export interface DeleteAgentContextCheckpointsAfterSeqInput {
973
+ readonly projectId: string
974
+ readonly threadId: string
975
+ /** Delete checkpoints whose observed head exceeds this retained sequence boundary. */
976
+ readonly afterSeq: number
977
+ }
978
+
872
979
  export interface AgentContextCheckpointStore {
873
980
  /**
874
981
  * Append one checkpoint after atomically validating run ownership and both transcript anchors.
@@ -885,6 +992,8 @@ export interface AgentContextCheckpointStore {
885
992
  readonly projectId: string
886
993
  readonly threadId: string
887
994
  }): Promise<AgentContextCheckpointRecord | null>
995
+ /** Delete checkpoints that observed messages past `afterSeq`, newest first. */
996
+ deleteAfterSeq(input: DeleteAgentContextCheckpointsAfterSeqInput): Promise<number>
888
997
  }
889
998
 
890
999
  // ── agent_approvals — calls of the Agent that wait for whoever asked ───────────────────────────
@@ -1052,6 +1161,26 @@ export interface StopAgentApprovalsResult {
1052
1161
  readonly stopped: number
1053
1162
  }
1054
1163
 
1164
+ export interface RewindAgentApprovalsInput {
1165
+ readonly projectId: string
1166
+ readonly threadId: string
1167
+ /** Conversation runs removed from the thread: their approvals leave with them. */
1168
+ readonly runIds: readonly string[]
1169
+ /**
1170
+ * Message ids removed by the rewind: an earlier turn's approval reported in one becomes
1171
+ * unreported again so the replacement message carries its outcome.
1172
+ */
1173
+ readonly clearedMessageIds?: readonly string[]
1174
+ readonly cancelledAt?: Date
1175
+ }
1176
+
1177
+ export interface RewindAgentApprovalsResult {
1178
+ /** Pending approvals of the rewound runs, as `cancelled` records to announce. */
1179
+ readonly cancelled: readonly AgentApprovalRecord[]
1180
+ /** Total approvals deleted for the rewound runs. */
1181
+ readonly deleted: number
1182
+ }
1183
+
1055
1184
  /** Where a keyset listing resumes: after this approval, in the order approvals are listed. */
1056
1185
  export interface AgentApprovalCursor {
1057
1186
  readonly createdAt: Date
@@ -1118,6 +1247,11 @@ export interface AgentApprovalStore {
1118
1247
  * stopped: their turn never resumes on them.
1119
1248
  */
1120
1249
  stop(input: StopAgentApprovalsInput): Promise<StopAgentApprovalsResult>
1250
+ /**
1251
+ * Remove approvals belonging to rewound turns and unmark earlier turns' approvals whose
1252
+ * reporting message was removed.
1253
+ */
1254
+ rewind(input: RewindAgentApprovalsInput): Promise<RewindAgentApprovalsResult>
1121
1255
  /** Mark the ones no message reported yet, and return their ids. */
1122
1256
  markReported(input: MarkAgentApprovalsReportedInput): Promise<readonly string[]>
1123
1257
  /**
@@ -1405,6 +1539,11 @@ export interface AgentInboxItemRecord {
1405
1539
  readonly locale?: string
1406
1540
  /** Marked by Send now so `afterAgentRunFinished` dispatches it across a user cancel. */
1407
1541
  readonly immediate?: boolean
1542
+ /**
1543
+ * An edit waiting for the turn it stopped to end: the earlier message it replaces. When it
1544
+ * starts, the thread first rewinds to that message. Always sent now, as a queued message.
1545
+ */
1546
+ readonly replacesMessageId?: string
1408
1547
  /**
1409
1548
  * The execution of the request that sent it. A turn that starts it without a request of its
1410
1549
  * sender's runs as a child of this one, with the sender's grants as they are then.
@@ -1427,6 +1566,11 @@ export interface EnqueueAgentInboxItemInput {
1427
1566
  readonly timeZone?: string
1428
1567
  readonly locale?: string
1429
1568
  readonly immediate?: boolean
1569
+ /**
1570
+ * An edit waiting for the turn it stopped to end: the earlier message it replaces. When it
1571
+ * starts, the thread first rewinds to that message. Always sent now, as a queued message.
1572
+ */
1573
+ readonly replacesMessageId?: string
1430
1574
  readonly executionId?: string
1431
1575
  readonly createdAt?: Date
1432
1576
  }
@@ -1530,6 +1674,7 @@ export interface AgentInboxStore {
1530
1674
 
1531
1675
  export interface AgentStorage {
1532
1676
  readonly threads: AgentThreadStore
1677
+ readonly reads: AgentThreadReadStore
1533
1678
  readonly runs: AgentRunStore
1534
1679
  readonly messages: AgentMessageStore
1535
1680
  readonly checkpoints: AgentContextCheckpointStore
@@ -1,4 +1,6 @@
1
+ import { calendarPeriodStart, calendarPeriods, canonicalTimeZone } from "../../calendar"
1
2
  import { MODEL_KINDS, type ModelKind } from "../../models/definitions"
3
+ import { DEFAULT_PROJECT_TIME_ZONE } from "../../runtime/locale"
2
4
  import { type AiModelCallUsageRecord, normalizeAiModelCallUsage } from "../ai-usage"
3
5
  import type {
4
6
  AiAccountingAgentBreakdown,
@@ -26,7 +28,6 @@ import type {
26
28
 
27
29
  const DEFAULT_MODEL_CALL_PAGE_SIZE = 50
28
30
  const MAX_MODEL_CALL_PAGE_SIZE = 200
29
- const MAX_CHART_BUCKETS = 10_000
30
31
 
31
32
  /** One joined immutable model-call row used by in-memory analytics and bounded SQL pages. */
32
33
  export interface AiAccountingRecordSetItem {
@@ -41,6 +42,8 @@ export interface NormalizedAiAccountingQuery extends AiAccountingFilters {
41
42
  readonly projectId: string
42
43
  readonly from: Date
43
44
  readonly to: Date
45
+ /** The IANA zone whose calendar a series buckets by. */
46
+ readonly timeZone: string
44
47
  }
45
48
 
46
49
  export interface NormalizedAiModelCallAccountingQuery extends NormalizedAiAccountingQuery {
@@ -123,10 +126,21 @@ export function normalizeAiAccountingQuery(
123
126
  assertNonBlank(input.source.workflowId, "accounting source workflowId")
124
127
  }
125
128
  if (input.modelKind !== undefined) aiAccountingModelKind(input.modelKind)
129
+ const requestedTimeZone = "timeZone" in input ? input.timeZone : undefined
130
+ const timeZone =
131
+ requestedTimeZone === undefined
132
+ ? DEFAULT_PROJECT_TIME_ZONE
133
+ : canonicalTimeZone(requestedTimeZone)
134
+ if (timeZone === undefined) {
135
+ throw new TypeError(
136
+ `[Sixb] AI accounting timeZone must be an IANA time zone such as 'Europe/Paris'; received ${JSON.stringify(requestedTimeZone)}.`
137
+ )
138
+ }
126
139
  return {
127
140
  projectId: input.projectId,
128
141
  from: new Date(input.from),
129
142
  to: new Date(input.to),
143
+ timeZone,
130
144
  ...(input.providerId === undefined ? {} : { providerId: input.providerId }),
131
145
  ...(input.modelId === undefined ? {} : { modelId: input.modelId }),
132
146
  ...(input.requester === undefined ? {} : { requester: input.requester }),
@@ -210,7 +224,7 @@ export function buildAiAccountingOverview(
210
224
  const query = normalizeAiAccountingQuery(input)
211
225
  assertAiAccountingBucket(input.bucket)
212
226
  const items = Array.from(source).filter((item) => aiAccountingItemMatchesQuery(item, query))
213
- const periods = accountingPeriods(query.from, query.to, input.bucket)
227
+ const periods = calendarPeriods(query.from, query.to, input.bucket, query.timeZone)
214
228
  const periodItems = new Map<number, AiAccountingRecordSetItem[]>(
215
229
  periods.map((period) => [period.start.getTime(), []])
216
230
  )
@@ -223,7 +237,11 @@ export function buildAiAccountingOverview(
223
237
  const workflowItems = new Map<string, AiAccountingRecordSetItem[]>()
224
238
 
225
239
  for (const item of items) {
226
- const periodStart = aiAccountingBucketStart(item.usage.occurredAt, input.bucket).getTime()
240
+ const periodStart = calendarPeriodStart(
241
+ item.usage.occurredAt,
242
+ input.bucket,
243
+ query.timeZone
244
+ ).getTime()
227
245
  periodItems.get(periodStart)?.push(item)
228
246
  const modelKey = JSON.stringify([item.usage.providerId, item.usage.requestedModelId])
229
247
  appendGrouped(modelItems, modelKey, item)
@@ -334,7 +352,7 @@ export function buildAiAccountingOverviewFromFragments(
334
352
  fragments: Iterable<AiAccountingAggregateFragment>
335
353
  ): AiAccountingOverview {
336
354
  const query = normalizeAiAccountingQuery(input)
337
- const periods = accountingPeriods(query.from, query.to, input.bucket)
355
+ const periods = calendarPeriods(query.from, query.to, input.bucket, query.timeZone)
338
356
  const totals = aggregateFragmentAccumulator()
339
357
  const series = new Map<number, AggregateFragmentAccumulator>(
340
358
  periods.map((period) => [period.start.getTime(), aggregateFragmentAccumulator()])
@@ -509,19 +527,6 @@ export function toAccountingItem(item: AiAccountingRecordSetItem): AiModelCallAc
509
527
  }
510
528
  }
511
529
 
512
- export function aiAccountingBucketStart(at: Date, bucket: AiAccountingBucket): Date {
513
- assertDate(at, "accounting bucket timestamp")
514
- assertAiAccountingBucket(bucket)
515
- const start = new Date(at)
516
- start.setUTCMinutes(0, 0, 0)
517
- if (bucket === "hour") return start
518
- start.setUTCHours(0)
519
- if (bucket === "day") return start
520
- const mondayOffset = (start.getUTCDay() + 6) % 7
521
- start.setUTCDate(start.getUTCDate() - mondayOffset)
522
- return start
523
- }
524
-
525
530
  function aggregateAccountingItems(
526
531
  items: readonly AiAccountingRecordSetItem[]
527
532
  ): AiAccountingAggregate {
@@ -751,32 +756,6 @@ function requiredFragmentDate(value: Date | undefined, field: string): Date {
751
756
  return value
752
757
  }
753
758
 
754
- function accountingPeriods(
755
- from: Date,
756
- to: Date,
757
- bucket: AiAccountingBucket
758
- ): Array<{ start: Date; end: Date }> {
759
- const result: Array<{ start: Date; end: Date }> = []
760
- let cursor = aiAccountingBucketStart(from, bucket)
761
- while (cursor.getTime() < to.getTime()) {
762
- if (result.length >= MAX_CHART_BUCKETS) {
763
- throw new RangeError(`[Sixb] AI accounting query exceeds ${MAX_CHART_BUCKETS} chart buckets.`)
764
- }
765
- const next = nextBucket(cursor, bucket)
766
- result.push({ start: new Date(cursor), end: next })
767
- cursor = next
768
- }
769
- return result
770
- }
771
-
772
- function nextBucket(start: Date, bucket: AiAccountingBucket): Date {
773
- const next = new Date(start)
774
- if (bucket === "hour") next.setUTCHours(next.getUTCHours() + 1)
775
- else if (bucket === "day") next.setUTCDate(next.getUTCDate() + 1)
776
- else next.setUTCDate(next.getUTCDate() + 7)
777
- return next
778
- }
779
-
780
759
  function appendGrouped<TKey extends string | number>(
781
760
  groups: Map<TKey, AiAccountingRecordSetItem[]>,
782
761
  key: TKey,
@@ -1,3 +1,4 @@
1
+ import type { CalendarPeriod } from "../../calendar"
1
2
  import type {
2
3
  AiModelCallUsageInput,
3
4
  AiModelCallUsageRecord,
@@ -127,7 +128,8 @@ export interface AiCostSummary {
127
128
  readonly unvaluedCallCount: number
128
129
  }
129
130
 
130
- export type AiAccountingBucket = "hour" | "day" | "week"
131
+ /** The width of a series period: the calendar period a chart is drawn in. */
132
+ export type AiAccountingBucket = CalendarPeriod
131
133
 
132
134
  /** Inclusive start and exclusive end for project accounting reads. */
133
135
  export interface AiAccountingRange {
@@ -165,6 +167,8 @@ export interface AiAccountingFilters {
165
167
  export interface QueryAiAccountingOverviewInput extends AiAccountingRange, AiAccountingFilters {
166
168
  readonly projectId: string
167
169
  readonly bucket: AiAccountingBucket
170
+ /** The IANA zone whose calendar the buckets follow; UTC when absent. */
171
+ readonly timeZone?: string
168
172
  }
169
173
 
170
174
  export interface ListAiModelCallAccountingInput extends AiAccountingRange, AiAccountingFilters {