@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,4 +1,4 @@
1
- import type { Broker } from "../broker"
1
+ import type { Broker, BrokerStreamDefinition } from "../broker"
2
2
  import { createSixbError } from "../errors/internal"
3
3
  import type { JsonValue } from "../json"
4
4
  import type {
@@ -9,17 +9,27 @@ import type {
9
9
  import type {
10
10
  AgentCompactionFailureCode,
11
11
  AgentInboxReadMessage,
12
+ AgentRunStepsRead,
12
13
  AgentRunStreamEvent,
13
14
  ModelUiChunk,
14
15
  } from "./streams"
15
16
  import {
16
17
  agentRunFinishedEvent,
18
+ agentRunStepsStreamDefinition,
19
+ agentRunStepsStreamId,
17
20
  agentRunStreamDefinition,
18
21
  agentRunStreamEventBase,
19
22
  agentRunStreamId,
20
23
  agentRunStreamIdempotencyKey,
21
24
  publishAgentRunActivity,
22
25
  } from "./streams/protocol"
26
+ import {
27
+ appendCompacted,
28
+ continuesDelta,
29
+ type DeltaChunk,
30
+ isDeltaChunk,
31
+ mergeDeltas,
32
+ } from "./streams/steps"
23
33
 
24
34
  export interface CompactionStartedInput {
25
35
  /** A conversation's turn, or a child compacting its own thread. */
@@ -78,8 +88,14 @@ export const NOOP_STREAM_SINK: StreamSink = {
78
88
  export function createBrokerStreamSink(input: {
79
89
  readonly broker: Broker
80
90
  readonly projectId: string
91
+ /** How long deltas of one span wait to go out as one record; 0 publishes each as it comes. */
92
+ readonly deltaWindowMs?: number
81
93
  }): StreamSink {
82
- return new BrokerStreamSink(input.broker, input.projectId)
94
+ return new BrokerStreamSink(
95
+ input.broker,
96
+ input.projectId,
97
+ input.deltaWindowMs ?? AGENT_RUN_STREAM_DELTA_WINDOW_MS
98
+ )
83
99
  }
84
100
 
85
101
  /** Keeps stream delivery observational so sink failures never fail a turn. */
@@ -143,16 +159,44 @@ async function publishLifecycle(deliveries: readonly Promise<void>[]): Promise<v
143
159
  if (failure?.status === "rejected") throw failure.reason
144
160
  }
145
161
 
162
+ /** How long the deltas of one span wait to go out as one record. */
163
+ export const AGENT_RUN_STREAM_DELTA_WINDOW_MS = 50
164
+
165
+ /** Runs one sink keeps stream state for at once: one that never finished here is dropped first. */
166
+ const MAX_TRACKED_RUNS = 256
167
+
168
+ /** What a sink keeps about one run while it streams. */
169
+ interface RunStream {
170
+ readonly attempt: number
171
+ /** Every record of the run goes out through this chain, so they keep their order. */
172
+ tail: Promise<void>
173
+ /** Deltas of one span not published yet, under the index of the first. */
174
+ pending: {
175
+ run: AgentRunRecord
176
+ readonly chunkIndex: number
177
+ chunk: DeltaChunk
178
+ } | null
179
+ timer: ReturnType<typeof setTimeout> | undefined
180
+ /** The chunks published since the last step was logged, compacted. */
181
+ step: ModelUiChunk[]
182
+ /** What the turn read from its inbox since then, each after the first `at` chunks of `step`. */
183
+ reads: AgentRunStepsRead[]
184
+ /** The index of the last chunk published. */
185
+ lastChunkIndex: number | undefined
186
+ }
187
+
146
188
  class BrokerStreamSink implements StreamSink {
147
189
  private readonly ensured = new Set<string>()
190
+ private readonly runs = new Map<string, RunStream>()
148
191
 
149
192
  constructor(
150
193
  private readonly broker: Broker,
151
- private readonly projectId: string
194
+ private readonly projectId: string,
195
+ private readonly deltaWindowMs: number
152
196
  ) {}
153
197
 
154
198
  async publishStarted(run: AgentRunRecord): Promise<void> {
155
- await this.publish({
199
+ await this.publishInOrder(run, {
156
200
  ...agentRunStreamEventBase(run),
157
201
  type: "agent.run.started",
158
202
  ...(run.modelId === undefined ? {} : { modelId: run.modelId }),
@@ -160,7 +204,7 @@ class BrokerStreamSink implements StreamSink {
160
204
  }
161
205
 
162
206
  async publishCompactionStarted(input: CompactionStartedInput): Promise<void> {
163
- await this.publish({
207
+ await this.publishInOrder(input.run, {
164
208
  ...agentRunStreamEventBase(input.run),
165
209
  type: "agent.compaction.started",
166
210
  reason: input.reason,
@@ -169,7 +213,7 @@ class BrokerStreamSink implements StreamSink {
169
213
  }
170
214
 
171
215
  async publishCompactionCompleted(input: CompactionCompletedInput): Promise<void> {
172
- await this.publish({
216
+ await this.publishInOrder(input.run, {
173
217
  ...agentRunStreamEventBase(input.run),
174
218
  type: "agent.compaction.completed",
175
219
  reason: input.reason,
@@ -180,7 +224,7 @@ class BrokerStreamSink implements StreamSink {
180
224
  }
181
225
 
182
226
  async publishCompactionFailed(input: CompactionFailedInput): Promise<void> {
183
- await this.publish({
227
+ await this.publishInOrder(input.run, {
184
228
  ...agentRunStreamEventBase(input.run),
185
229
  type: "agent.compaction.failed",
186
230
  reason: input.reason,
@@ -188,7 +232,11 @@ class BrokerStreamSink implements StreamSink {
188
232
  })
189
233
  }
190
234
 
191
- /** Publishes one live UI chunk; awaited per chunk so broker backpressure throttles the token stream. */
235
+ /**
236
+ * Publishes one live UI chunk. Deltas of one span arriving within the window go out as one record:
237
+ * a model streams a few characters per delta, far more often than anyone reads. Anything else
238
+ * first sends the deltas held, and is awaited, so broker backpressure throttles the token stream.
239
+ */
192
240
  async publishUiChunk(input: {
193
241
  readonly run: AgentRunRecord
194
242
  readonly chunkIndex: number
@@ -205,28 +253,45 @@ class BrokerStreamSink implements StreamSink {
205
253
  return
206
254
  }
207
255
 
208
- // `chunk` is already validated JSON and every other field is a JSON primitive, so the event is
209
- // JSON as-built. Publish it pre-validated so the chunk — the highest-frequency agent event, one
210
- // per streamed token batch — is not serialized a second time inside `publish`.
211
- await this.publish(
212
- {
213
- ...agentRunStreamEventBase(input.run),
214
- type: "agent.ui.chunk",
215
- chunkIndex: input.chunkIndex,
216
- chunk,
217
- },
218
- { prevalidated: true }
219
- )
256
+ const stream = this.stream(input.run)
257
+ const pending = stream.pending
258
+ if (pending && continuesDelta(pending.chunk, chunk)) {
259
+ pending.chunk = mergeDeltas(pending.chunk, chunk)
260
+ pending.run = input.run
261
+ return
262
+ }
263
+
264
+ const flushed = this.flush(stream)
265
+ if (isDeltaChunk(chunk) && this.deltaWindowMs > 0) {
266
+ stream.pending = { run: input.run, chunkIndex: input.chunkIndex, chunk }
267
+ stream.timer = setTimeout(() => void this.flush(stream), this.deltaWindowMs)
268
+ await flushed
269
+ return
270
+ }
271
+ await this.enqueue(stream, () => this.appendChunk(input.run, stream, input.chunkIndex, chunk))
220
272
  }
221
273
 
274
+ /**
275
+ * Publishes what the turn read, after every chunk it streamed before. Its step keeps it too, so
276
+ * whoever opens the turn later reads it where the turn did.
277
+ */
222
278
  async publishInboxRead(input: {
223
279
  readonly run: ConversationAgentRunRecord
224
280
  readonly messages: readonly AgentInboxReadMessage[]
225
281
  }): Promise<void> {
226
- await this.publish({
227
- ...agentRunStreamEventBase(input.run),
228
- type: "agent.inbox.read",
229
- messages: input.messages,
282
+ const stream = this.stream(input.run)
283
+ void this.flush(stream)
284
+
285
+ await this.enqueue(stream, async () => {
286
+ const afterChunkIndex = stream.lastChunkIndex
287
+ await this.publish({
288
+ ...agentRunStreamEventBase(input.run),
289
+ type: "agent.inbox.read",
290
+ messages: input.messages,
291
+ ...(afterChunkIndex === undefined ? {} : { afterChunkIndex }),
292
+ })
293
+
294
+ stream.reads.push({ at: stream.step.length, messages: input.messages })
230
295
  })
231
296
  }
232
297
 
@@ -234,7 +299,7 @@ class BrokerStreamSink implements StreamSink {
234
299
  readonly run: ConversationAgentRunRecord
235
300
  readonly messageId: string
236
301
  }): Promise<void> {
237
- await this.publish({
302
+ await this.publishInOrder(input.run, {
238
303
  ...agentRunStreamEventBase(input.run),
239
304
  type: "agent.message.finalized",
240
305
  messageId: input.messageId,
@@ -245,17 +310,153 @@ class BrokerStreamSink implements StreamSink {
245
310
  if (run.status === "queued" || run.status === "running") {
246
311
  return
247
312
  }
248
- await this.publish(agentRunFinishedEvent(run))
249
- // This is the last event for the run, so drop its ensured-stream marker to bound the Set over a
250
- // long-lived worker. Evict only after a successful append, and only on the terminal path.
251
- this.ensured.delete(agentRunStreamId(run.id))
313
+ try {
314
+ await this.publishInOrder(run, agentRunFinishedEvent(run))
315
+ } finally {
316
+ // This is the last event for the run: drop what the sink kept for it, to bound a long-lived
317
+ // worker's memory.
318
+ this.forget(run.id)
319
+ }
320
+ }
321
+
322
+ /** The run's stream state, started over for a new attempt. */
323
+ private stream(run: AgentRunRecord): RunStream {
324
+ const known = this.runs.get(run.id)
325
+ if (known && known.attempt === run.attempt) return known
326
+ if (known) clearTimeout(known.timer)
327
+ else if (this.runs.size >= MAX_TRACKED_RUNS) {
328
+ const [oldest] = this.runs.keys()
329
+ if (oldest !== undefined) this.forget(oldest)
330
+ }
331
+
332
+ const stream: RunStream = {
333
+ attempt: run.attempt,
334
+ tail: Promise.resolve(),
335
+ pending: null,
336
+ timer: undefined,
337
+ step: [],
338
+ reads: [],
339
+ lastChunkIndex: undefined,
340
+ }
341
+ this.runs.set(run.id, stream)
342
+ return stream
343
+ }
344
+
345
+ private forget(runId: string): void {
346
+ clearTimeout(this.runs.get(runId)?.timer)
347
+ this.runs.delete(runId)
348
+ this.ensured.delete(agentRunStreamId(runId))
349
+ this.ensured.delete(agentRunStepsStreamId(runId))
350
+ }
351
+
352
+ /** Runs `task` after every record the run sent before it. */
353
+ private enqueue(stream: RunStream, task: () => Promise<void>): Promise<void> {
354
+ const next = stream.tail.then(task)
355
+ stream.tail = next.catch(() => {})
356
+ return next
357
+ }
358
+
359
+ /** Sends the deltas held, if any. Never rejects: a failed send is logged, as for any chunk. */
360
+ private flush(stream: RunStream): Promise<void> {
361
+ clearTimeout(stream.timer)
362
+ stream.timer = undefined
363
+ const pending = stream.pending
364
+ if (!pending) return stream.tail
365
+ stream.pending = null
366
+ return this.enqueue(stream, () =>
367
+ this.appendChunk(pending.run, stream, pending.chunkIndex, pending.chunk)
368
+ ).catch((error: unknown) => {
369
+ console.error(`[Sixb] Agent run '${pending.run.id}' ui chunk stream publish failed:`, error)
370
+ })
371
+ }
372
+
373
+ private async publishInOrder(run: AgentRunRecord, event: AgentRunStreamEvent): Promise<void> {
374
+ const stream = this.stream(run)
375
+ void this.flush(stream)
376
+ await this.enqueue(stream, () => this.publish(event))
377
+ }
378
+
379
+ private async appendChunk(
380
+ run: AgentRunRecord,
381
+ stream: RunStream,
382
+ chunkIndex: number,
383
+ chunk: ModelUiChunk
384
+ ): Promise<void> {
385
+ const startsStep = chunk.type === "start-step" && !chunk.retry
386
+ // A new step: the one before is finished, and logged for whoever opens the turn later.
387
+ if (startsStep && (stream.step.length > 0 || stream.reads.length > 0)) {
388
+ await this.logStep(run, stream)
389
+ }
390
+
391
+ // `chunk` is already validated JSON and every other field is a JSON primitive, so the event is
392
+ // JSON as-built. Publish it pre-validated so the chunk — the highest-frequency agent event — is
393
+ // not serialized a second time inside `publish`.
394
+ await this.publish(
395
+ {
396
+ ...agentRunStreamEventBase(run),
397
+ type: "agent.ui.chunk",
398
+ chunkIndex,
399
+ chunk,
400
+ },
401
+ { prevalidated: true }
402
+ )
403
+
404
+ stream.lastChunkIndex = chunkIndex
405
+ if (chunk.type === "start-step" && chunk.retry) {
406
+ // A step asked again drops what its first call streamed, as a reader does. What the turn read
407
+ // as the step started stays: the step reads it again.
408
+ const [head] = stream.step
409
+ stream.step = head?.type === "start-step" ? [head] : []
410
+ stream.reads = stream.reads.filter((read) => read.at <= stream.step.length)
411
+ return
412
+ }
413
+
414
+ // A chunk after a read starts a span of its own: the read sits between the two.
415
+ if (stream.reads.at(-1)?.at === stream.step.length) stream.step.push(chunk)
416
+ else appendCompacted(stream.step, chunk)
417
+ }
418
+
419
+ /**
420
+ * Appends the chunks since the last step logged to the run's steps stream. A failed append keeps
421
+ * them, so they go out with the next step: the live record is published either way.
422
+ */
423
+ private async logStep(run: AgentRunRecord, stream: RunStream): Promise<void> {
424
+ if (stream.lastChunkIndex === undefined) return
425
+ const event: AgentRunStreamEvent = {
426
+ ...agentRunStreamEventBase(run),
427
+ type: "agent.ui.steps",
428
+ throughChunkIndex: stream.lastChunkIndex,
429
+ chunks: stream.step,
430
+ ...(stream.reads.length === 0 ? {} : { reads: stream.reads }),
431
+ }
432
+ try {
433
+ const definition = agentRunStepsStreamDefinition(run.id)
434
+ await this.ensure(definition)
435
+ await this.broker.append({
436
+ projectId: this.projectId,
437
+ streamId: definition.id,
438
+ records: [
439
+ {
440
+ name: event.type,
441
+ key: run.id,
442
+ // Its chunks were validated as they were published.
443
+ payload: event as unknown as JsonValue,
444
+ idempotencyKey: agentRunStreamIdempotencyKey(event),
445
+ },
446
+ ],
447
+ })
448
+ stream.step = []
449
+ stream.reads = []
450
+ } catch (error) {
451
+ console.error(`[Sixb] Agent run '${run.id}' step log publish failed:`, error)
452
+ }
252
453
  }
253
454
 
254
455
  private async publish(
255
456
  event: AgentRunStreamEvent,
256
457
  options: { readonly prevalidated?: boolean } = {}
257
458
  ): Promise<void> {
258
- await this.ensure(event.runId)
459
+ await this.ensure(agentRunStreamDefinition(event.runId))
259
460
  // Broker payloads are plain JSON; keep SDK-specific chunk shapes opaque at this boundary. A
260
461
  // pre-validated event (its only opaque field, the chunk, was already encoded by the caller) is
261
462
  // already JSON, so it is forwarded as-is instead of being serialized a second time.
@@ -278,16 +479,12 @@ class BrokerStreamSink implements StreamSink {
278
479
  })
279
480
  }
280
481
 
281
- private async ensure(runId: string): Promise<void> {
282
- const streamId = agentRunStreamId(runId)
283
- if (this.ensured.has(streamId)) {
482
+ private async ensure(stream: BrokerStreamDefinition): Promise<void> {
483
+ if (this.ensured.has(stream.id)) {
284
484
  return
285
485
  }
286
- await this.broker.ensureStream({
287
- projectId: this.projectId,
288
- stream: agentRunStreamDefinition(runId),
289
- })
290
- this.ensured.add(streamId)
486
+ await this.broker.ensureStream({ projectId: this.projectId, stream })
487
+ this.ensured.add(stream.id)
291
488
  }
292
489
  }
293
490
 
@@ -177,8 +177,19 @@ export function agentRunChildren(
177
177
  const included = await Promise.all(found.map((each) => scope.includes(each.threadId)))
178
178
  return found.filter((_, index) => included[index])
179
179
  },
180
- inConversation: (input) =>
181
- agents.runs.listThreadSubagents({ ...input, projectId, threadId: run.threadId }),
180
+ inConversation: async (input) => {
181
+ const { total } = await agents.messages.list({
182
+ projectId,
183
+ threadId: run.threadId,
184
+ limit: 1,
185
+ })
186
+ return agents.runs.listThreadSubagents({
187
+ ...input,
188
+ projectId,
189
+ threadId: run.threadId,
190
+ ...(total > 0 ? { retainedTurnsOnly: true } : {}),
191
+ })
192
+ },
182
193
  async threadRuns(threadId) {
183
194
  if (!(await scope.includes(threadId))) return []
184
195
  return listSubagentThreadRuns(agents, { projectId, threadId })
@@ -6,8 +6,10 @@ import type {
6
6
  AgentRunRecord,
7
7
  AgentThreadParticipantRecord,
8
8
  AgentThreadRecord,
9
+ ConversationAgentRunRecord,
9
10
  SubagentRunRecord,
10
11
  } from "../storage/agents"
12
+ import { runPlaceKey } from "../storage/agents/provider"
11
13
  import type { AiModelCallUsageRecord } from "../storage/ai-usage"
12
14
  import type { ExecutionRecord } from "../storage/executions/types"
13
15
  import { isPausedSubagentRun } from "./approvals"
@@ -50,6 +52,12 @@ export interface AgentTurnHistory {
50
52
  * project that predates it.
51
53
  */
52
54
  readonly sentLocales?: Readonly<Record<string, string>>
55
+ /**
56
+ * Retained user messages where the conversation changed workspace (between the cloud, computers
57
+ * or folders) since the message before. Stored run history decides it, so the system prompt
58
+ * carries no move timestamp and cached prefixes hold across round-trip moves.
59
+ */
60
+ readonly movedMessageIds?: readonly string[]
53
61
  /**
54
62
  * The model call that ended the latest assistant message after the checkpoint: what a token
55
63
  * estimate anchors on, as the provider counted it. None when that message's run compacted the
@@ -106,11 +114,17 @@ export interface AgentTurnHistoryHost {
106
114
  /** A conversation's history: its latest checkpoint and the messages after it. */
107
115
  export async function readAgentTurnHistory(
108
116
  host: AgentTurnHistoryHost,
109
- threadId: string
117
+ threadId: string,
118
+ options?: { readonly thread?: AgentThreadRecord | null }
110
119
  ): Promise<AgentTurnHistory> {
111
- const { checkpoint, messages } = await readRetainedHistory(host, threadId)
120
+ const [{ checkpoint, messages }, thread] = await Promise.all([
121
+ readRetainedHistory(host, threadId),
122
+ options && "thread" in options
123
+ ? Promise.resolve(options.thread ?? null)
124
+ : host.storage.agents.threads.getById({ projectId: host.projectId, id: threadId }),
125
+ ])
112
126
  const [sent, usageAnchor] = await Promise.all([
113
- readSentSettings(host, threadId, messages),
127
+ readSentSettings(host, threadId, messages, checkpoint, thread),
114
128
  readUsageAnchor(host, messages, checkpoint),
115
129
  ])
116
130
  return { checkpoint, messages, ...sent, ...(usageAnchor ? { usageAnchor } : {}) }
@@ -148,10 +162,10 @@ async function readTurnContext(
148
162
  execution: ExecutionRecord | null
149
163
  ): Promise<AgentTurnContext> {
150
164
  const { projectId } = host
151
- const [thread, participants, history] = await Promise.all([
152
- host.storage.agents.threads.getById({ projectId, id: run.threadId }),
165
+ const thread = await host.storage.agents.threads.getById({ projectId, id: run.threadId })
166
+ const [participants, history] = await Promise.all([
153
167
  host.storage.agents.threads.listParticipants({ projectId, threadIds: [run.threadId] }),
154
- readAgentTurnHistory(host, run.threadId),
168
+ readAgentTurnHistory(host, run.threadId, { thread }),
155
169
  ])
156
170
  const readers = await readReaders(host, participants)
157
171
  const named: Principal[] = [
@@ -180,10 +194,10 @@ async function readChildContext(
180
194
  ): Promise<AgentChildContext> {
181
195
  const { projectId } = host
182
196
  const agents = host.storage.agents
183
- const [parent, thread, history, runs] = await Promise.all([
197
+ const thread = await agents.threads.getById({ projectId, id: run.threadId })
198
+ const [parent, history, runs] = await Promise.all([
184
199
  agents.runs.getById({ projectId, id: run.parentRunId }),
185
- agents.threads.getById({ projectId, id: run.threadId }),
186
- readAgentTurnHistory(host, run.threadId),
200
+ readAgentTurnHistory(host, run.threadId, { thread }),
187
201
  listSubagentThreadRuns(agents, { projectId, threadId: run.threadId }),
188
202
  ])
189
203
  const [conversation, task] = await Promise.all([
@@ -259,28 +273,44 @@ function readUser(host: AgentRunSessionHost, id: string) {
259
273
  }
260
274
 
261
275
  /**
262
- * The time zone and locale each retained user message was sent in: those of the run that answered
263
- * it, as its requester's settings froze them.
276
+ * The time zone, locale and workspace transitions of each retained user message: read from the
277
+ * runs that answered them, so every later turn replays the exact same bytes.
264
278
  */
265
279
  async function readSentSettings(
266
280
  host: AgentTurnHistoryHost,
267
281
  threadId: string,
268
- messages: readonly AgentMessageRecord[]
269
- ): Promise<Pick<AgentTurnHistory, "sentTimeZones" | "sentLocales">> {
282
+ messages: readonly AgentMessageRecord[],
283
+ checkpoint: AgentContextCheckpointRecord | null,
284
+ thread: AgentThreadRecord | null
285
+ ): Promise<Pick<AgentTurnHistory, "sentTimeZones" | "sentLocales" | "movedMessageIds">> {
270
286
  const userMessages = messages.filter((message) => message.role === "user")
271
287
  const oldest = userMessages[0]
272
- if (!oldest) return { sentTimeZones: {}, sentLocales: {} }
288
+ if (!oldest || thread?.kind === "subagent") return { sentTimeZones: {}, sentLocales: {} }
273
289
 
274
- // A run starts after its trigger message, so this window holds every run that answered one.
275
- const { runs } = await host.storage.agents.runs.list({
276
- projectId: host.projectId,
277
- threadId,
278
- kinds: ["conversation"],
279
- startedAfter: new Date(oldest.createdAt.getTime() - 1),
280
- })
290
+ // A run starts after its trigger message, so this window holds every run that answered one;
291
+ // after a compaction, also check the latest summarized turn to catch a move right across it.
292
+ const [{ runs }, earlier] = await Promise.all([
293
+ host.storage.agents.runs.list({
294
+ projectId: host.projectId,
295
+ threadId,
296
+ kinds: ["conversation"],
297
+ startedAfter: new Date(oldest.createdAt.getTime() - 1),
298
+ }),
299
+ checkpoint
300
+ ? host.storage.agents.runs.list({
301
+ projectId: host.projectId,
302
+ threadId,
303
+ kinds: ["conversation"],
304
+ startedBefore: new Date(oldest.createdAt.getTime()),
305
+ order: "desc",
306
+ limit: 5,
307
+ })
308
+ : Promise.resolve({ runs: [] }),
309
+ ])
281
310
  const retained = new Set(userMessages.map((message) => message.id))
282
311
  const zones: Record<string, string> = {}
283
312
  const locales: Record<string, string> = {}
313
+ const places: Record<string, string> = {}
284
314
  for (const message of userMessages) {
285
315
  // A message a turn read mid-run keeps the settings it was rendered with, so a later turn closes
286
316
  // it with the same `<sixb_current_time>`.
@@ -288,13 +318,100 @@ async function readSentSettings(
288
318
  if (typeof metadata?.timeZone === "string") zones[message.id] = metadata.timeZone
289
319
  if (typeof metadata?.locale === "string") locales[message.id] = metadata.locale
290
320
  }
291
- for (const run of runs) {
321
+ // Oldest first so a retried turn's latest run records where the message ultimately ran.
322
+ for (const run of [...runs].reverse()) {
292
323
  if (run.kind !== "conversation" || !retained.has(run.triggerMessageId)) continue
293
324
 
294
325
  if (run.spec?.timeZone) zones[run.triggerMessageId] = run.spec.timeZone
295
326
  if (run.spec?.locale) locales[run.triggerMessageId] = run.spec.locale
327
+ places[run.triggerMessageId] = runPlaceKey(run.spec)
328
+ }
329
+
330
+ // The latest turn the summary holds. It may have started after the oldest message kept, one sent
331
+ // while it waited: look for it in both lists.
332
+ const priorRun = await latestSummarizedRun(host, [...runs, ...earlier.runs], retained)
333
+ const movedMessageIds = detectMovedMessages({
334
+ userMessages,
335
+ checkpoint,
336
+ places,
337
+ priorPlace: priorRun ? runPlaceKey(priorRun.spec) : undefined,
338
+ })
339
+ return {
340
+ sentTimeZones: zones,
341
+ sentLocales: locales,
342
+ ...(movedMessageIds.length > 0 ? { movedMessageIds } : {}),
343
+ }
344
+ }
345
+
346
+ /**
347
+ * The newest turn whose trigger message the summary holds. A turn whose message isn't kept is
348
+ * either summarized, its message still stored, or rewound by an edit, its message deleted: only the
349
+ * first tells where the conversation ran before its oldest kept message.
350
+ */
351
+ async function latestSummarizedRun(
352
+ host: AgentTurnHistoryHost,
353
+ runs: readonly AgentRunRecord[],
354
+ retained: ReadonlySet<string>
355
+ ): Promise<ConversationAgentRunRecord | undefined> {
356
+ const candidates = runs
357
+ .filter(
358
+ (run): run is ConversationAgentRunRecord =>
359
+ run.kind === "conversation" && !retained.has(run.triggerMessageId)
360
+ )
361
+ .sort((left, right) => startOf(right) - startOf(left))
362
+
363
+ const rewound = new Set<string>()
364
+ for (const run of candidates) {
365
+ if (rewound.has(run.triggerMessageId)) continue
366
+
367
+ const trigger = await host.storage.agents.messages.getById({
368
+ projectId: host.projectId,
369
+ id: run.triggerMessageId,
370
+ })
371
+ if (trigger) return run
372
+ rewound.add(run.triggerMessageId)
373
+ }
374
+ return undefined
375
+ }
376
+
377
+ /** When a run started, or was admitted when it never did: the order the run lists sort by. */
378
+ function startOf(run: AgentRunRecord): number {
379
+ return (run.startedAt ?? run.createdAt).getTime()
380
+ }
381
+
382
+ /**
383
+ * The user messages that ran in another workspace than the one before them. Only runs decide it,
384
+ * never the thread's latest move, so a message keeps its note, or its lack of one, at every later
385
+ * turn: a round trip with no turn in between changes nothing, and the workspace it comes back to
386
+ * reads its cached prefix again.
387
+ */
388
+ function detectMovedMessages(input: {
389
+ readonly userMessages: readonly AgentMessageRecord[]
390
+ readonly checkpoint: AgentContextCheckpointRecord | null
391
+ readonly places: Readonly<Record<string, string>>
392
+ readonly priorPlace: string | undefined
393
+ }): readonly string[] {
394
+ const moved: string[] = []
395
+ let previous = input.priorPlace
396
+
397
+ // A message with no run of its own, such as one sent into a turn that runs, decides nothing.
398
+ // Before any run of the thread, though, such messages are a fork's copies, answered in its
399
+ // source's workspace, as is a summary with no run before it: the fork's first turn starts
400
+ // elsewhere.
401
+ let inherited = previous === undefined && input.checkpoint !== null
402
+
403
+ for (const message of input.userMessages) {
404
+ const place = input.places[message.id]
405
+ if (place === undefined) {
406
+ inherited = true
407
+ continue
408
+ }
409
+
410
+ const crossed = previous === undefined ? inherited : previous !== place
411
+ if (crossed) moved.push(message.id)
412
+ previous = place
296
413
  }
297
- return { sentTimeZones: zones, sentLocales: locales }
414
+ return moved
298
415
  }
299
416
 
300
417
  /**
@@ -10,6 +10,8 @@ export type {
10
10
  AgentRunControlStreamId,
11
11
  AgentRunFailure,
12
12
  AgentRunFinishedEvent,
13
+ AgentRunStepsEvent,
14
+ AgentRunStepsRead,
13
15
  AgentRunStreamEvent,
14
16
  AgentRunStreamId,
15
17
  AgentThreadMovedEvent,
@@ -6,11 +6,14 @@ export {
6
6
  agentRunControlStreamDefinition,
7
7
  agentRunControlStreamId,
8
8
  agentRunFinishedEvent,
9
+ agentRunStepsStreamDefinition,
10
+ agentRunStepsStreamId,
9
11
  agentRunStreamDefinition,
10
12
  agentRunStreamEventBase,
11
13
  agentRunStreamId,
12
14
  agentRunStreamIdempotencyKey,
13
15
  DEFAULT_AGENT_ACTIVITY_STREAM_RETENTION,
16
+ DEFAULT_AGENT_RUN_STEPS_RETENTION,
14
17
  DEFAULT_AGENT_RUN_STREAM_RETENTION,
15
18
  publishAgentComputerActivity,
16
19
  publishAgentRunActivity,
@@ -19,3 +22,12 @@ export {
19
22
  publishAgentThreadMoved,
20
23
  subscribeAgentRunCancel,
21
24
  } from "./protocol"
25
+ export {
26
+ appendCompacted,
27
+ continuesDelta,
28
+ coveredBySteps,
29
+ type DeltaChunk,
30
+ isDeltaChunk,
31
+ mergeDeltas,
32
+ readAgentRunSteps,
33
+ } from "./steps"