@sixb/core 0.1.2 → 0.1.4

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 (383) hide show
  1. package/dist/actions/index.js +19 -17
  2. package/dist/actions/index.js.map +1 -1
  3. package/dist/actions/worker.js +4 -4
  4. package/dist/actions/worker.js.map +1 -1
  5. package/dist/agents/adapters.d.ts +11 -1
  6. package/dist/agents/adapters.d.ts.map +1 -1
  7. package/dist/agents/context-compaction.d.ts +40 -0
  8. package/dist/agents/context-compaction.d.ts.map +1 -0
  9. package/dist/agents/context.js +1 -1
  10. package/dist/agents/errors.d.ts +1 -1
  11. package/dist/agents/errors.d.ts.map +1 -1
  12. package/dist/agents/execution.d.ts +3 -0
  13. package/dist/agents/execution.d.ts.map +1 -1
  14. package/dist/agents/ids.d.ts +2 -0
  15. package/dist/agents/ids.d.ts.map +1 -1
  16. package/dist/agents/index.d.ts +10 -6
  17. package/dist/agents/index.d.ts.map +1 -1
  18. package/dist/agents/index.js +51 -35
  19. package/dist/agents/index.js.map +1 -1
  20. package/dist/agents/request.d.ts.map +1 -1
  21. package/dist/agents/streams.d.ts +17 -1
  22. package/dist/agents/streams.d.ts.map +1 -1
  23. package/dist/agents/streams.js +5 -3
  24. package/dist/agents/streams.js.map +1 -1
  25. package/dist/agents/thread-context-projection.d.ts +19 -0
  26. package/dist/agents/thread-context-projection.d.ts.map +1 -0
  27. package/dist/agents/tool-definition.d.ts.map +1 -1
  28. package/dist/agents/tool-result.d.ts +6 -0
  29. package/dist/agents/tool-result.d.ts.map +1 -0
  30. package/dist/agents/types.d.ts +46 -1
  31. package/dist/agents/types.d.ts.map +1 -1
  32. package/dist/agents/validation.d.ts +2 -2
  33. package/dist/agents/validation.d.ts.map +1 -1
  34. package/dist/auth/index.js +11 -5
  35. package/dist/auth/index.js.map +1 -1
  36. package/dist/authorization/index.js +6 -2
  37. package/dist/authorization/index.js.map +1 -1
  38. package/dist/bootstrap/index.js +33 -31
  39. package/dist/bootstrap/index.js.map +1 -1
  40. package/dist/{chunk-ys1nse2v.js → chunk-1wk20wn3.js} +438 -246
  41. package/dist/{chunk-ys1nse2v.js.map → chunk-1wk20wn3.js.map} +11 -11
  42. package/dist/{chunk-sa4340y1.js → chunk-1yz3x65y.js} +7 -7
  43. package/dist/{chunk-gqdd7508.js → chunk-4rh2m6zg.js} +1 -1
  44. package/dist/{chunk-fmx1sz2h.js → chunk-72q2y8hn.js} +3 -3
  45. package/dist/{chunk-fmx1sz2h.js.map → chunk-72q2y8hn.js.map} +4 -4
  46. package/dist/{chunk-nnyp53zt.js → chunk-7gw7mepb.js} +259 -9
  47. package/dist/chunk-7gw7mepb.js.map +14 -0
  48. package/dist/{chunk-nten49ta.js → chunk-819wnjz8.js} +11 -5
  49. package/dist/chunk-819wnjz8.js.map +12 -0
  50. package/dist/chunk-96swp2wd.js +47 -0
  51. package/dist/chunk-96swp2wd.js.map +10 -0
  52. package/dist/{chunk-4x43bkbp.js → chunk-a09jx26t.js} +1 -1
  53. package/dist/{chunk-st4xgxey.js → chunk-afjpa2hs.js} +205 -48
  54. package/dist/chunk-afjpa2hs.js.map +45 -0
  55. package/dist/{chunk-0mbx247x.js → chunk-c43qr6s0.js} +427 -99
  56. package/dist/chunk-c43qr6s0.js.map +46 -0
  57. package/dist/{chunk-zg9yryhz.js → chunk-cbkm2vam.js} +3 -3
  58. package/dist/{chunk-57zpb99z.js → chunk-dm72y8wt.js} +26 -3
  59. package/dist/chunk-dm72y8wt.js.map +10 -0
  60. package/dist/chunk-drjqm1aa.js +913 -0
  61. package/dist/chunk-drjqm1aa.js.map +15 -0
  62. package/dist/chunk-dysw7nsm.js.map +1 -1
  63. package/dist/{chunk-8ryen3p3.js → chunk-f6erf2vv.js} +1 -1
  64. package/dist/{chunk-34bqh420.js → chunk-f83ka50g.js} +188 -44
  65. package/dist/chunk-f83ka50g.js.map +23 -0
  66. package/dist/{chunk-bct7hmfc.js → chunk-g13869yf.js} +3 -3
  67. package/dist/{chunk-0k4avqr2.js → chunk-hbeh8j9w.js} +2 -2
  68. package/dist/{chunk-qvybnnpe.js → chunk-nzw7sm3b.js} +2 -2
  69. package/dist/{chunk-k9pts48t.js → chunk-pn8n8sba.js} +16 -15
  70. package/dist/{chunk-k9pts48t.js.map → chunk-pn8n8sba.js.map} +3 -3
  71. package/dist/{chunk-63te770v.js → chunk-qewtks41.js} +8 -8
  72. package/dist/{chunk-63te770v.js.map → chunk-qewtks41.js.map} +2 -2
  73. package/dist/{chunk-85j5ybfj.js → chunk-rdeagz6b.js} +2 -2
  74. package/dist/{chunk-85j5ybfj.js.map → chunk-rdeagz6b.js.map} +3 -3
  75. package/dist/chunk-rhrbz7d4.js +36 -0
  76. package/dist/chunk-rhrbz7d4.js.map +10 -0
  77. package/dist/{chunk-bh6k3nc6.js → chunk-rs1wbvy6.js} +1 -1
  78. package/dist/{chunk-88ppkr54.js → chunk-rte5sm3z.js} +26 -2
  79. package/dist/chunk-rte5sm3z.js.map +12 -0
  80. package/dist/{chunk-n8herkry.js → chunk-s31d0qmq.js} +57 -20
  81. package/dist/{chunk-n8herkry.js.map → chunk-s31d0qmq.js.map} +8 -7
  82. package/dist/{chunk-7pc8b818.js → chunk-sxwk41qa.js} +1 -1
  83. package/dist/{chunk-663csy96.js → chunk-t0jjkep3.js} +2 -1
  84. package/dist/chunk-t0jjkep3.js.map +10 -0
  85. package/dist/{chunk-c6qd89g5.js → chunk-tek1qwgm.js} +6 -6
  86. package/dist/{chunk-c6qd89g5.js.map → chunk-tek1qwgm.js.map} +1 -1
  87. package/dist/{chunk-jaj13078.js → chunk-tkdscva6.js} +3 -33
  88. package/dist/{chunk-jaj13078.js.map → chunk-tkdscva6.js.map} +3 -4
  89. package/dist/{chunk-5egfka8j.js → chunk-tycbzedm.js} +2 -2
  90. package/dist/{chunk-g9t3kdtx.js → chunk-x2yw73hy.js} +1 -1
  91. package/dist/{chunk-57r1cpxx.js → chunk-xc7hq65b.js} +3 -2
  92. package/dist/{chunk-57r1cpxx.js.map → chunk-xc7hq65b.js.map} +3 -3
  93. package/dist/chunk-xdf9yswn.js +133 -0
  94. package/dist/chunk-xdf9yswn.js.map +11 -0
  95. package/dist/execution/agent.js +29 -27
  96. package/dist/execution/agent.js.map +1 -1
  97. package/dist/execution/primitive.js +29 -27
  98. package/dist/execution/primitive.js.map +2 -2
  99. package/dist/execution/request.js +30 -28
  100. package/dist/execution/request.js.map +2 -2
  101. package/dist/http/index.js +1 -1
  102. package/dist/index.d.ts +6 -5
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +60 -58
  105. package/dist/index.js.map +1 -1
  106. package/dist/lake-storage/types.d.ts +2 -1
  107. package/dist/lake-storage/types.d.ts.map +1 -1
  108. package/dist/materialization/model.d.ts +4 -0
  109. package/dist/materialization/model.d.ts.map +1 -1
  110. package/dist/materializer/edits/apply.d.ts +6 -1
  111. package/dist/materializer/edits/apply.d.ts.map +1 -1
  112. package/dist/materializer/edits/working-state.d.ts +2 -0
  113. package/dist/materializer/edits/working-state.d.ts.map +1 -1
  114. package/dist/materializer/effective/resolve.d.ts +3 -1
  115. package/dist/materializer/effective/resolve.d.ts.map +1 -1
  116. package/dist/materializer/execution/work-records.d.ts.map +1 -1
  117. package/dist/materializer/index.js +19 -17
  118. package/dist/materializer/index.js.map +1 -1
  119. package/dist/materializer/projections/replacement-plan.d.ts.map +1 -1
  120. package/dist/materializer/shared/normalize.d.ts.map +1 -1
  121. package/dist/models/index.d.ts +40 -0
  122. package/dist/models/index.d.ts.map +1 -0
  123. package/dist/objects/execution.d.ts +6 -1
  124. package/dist/objects/execution.d.ts.map +1 -1
  125. package/dist/objects/index.js +21 -19
  126. package/dist/objects/index.js.map +1 -1
  127. package/dist/objects/link/endpoints.d.ts.map +1 -1
  128. package/dist/objects/query/executor.d.ts +1 -0
  129. package/dist/objects/query/executor.d.ts.map +1 -1
  130. package/dist/objects/query/explain.d.ts +1 -0
  131. package/dist/objects/query/explain.d.ts.map +1 -1
  132. package/dist/objects/query/index.d.ts +3 -1
  133. package/dist/objects/query/index.d.ts.map +1 -1
  134. package/dist/objects/query/index.js +30 -5
  135. package/dist/objects/query/index.js.map +1 -1
  136. package/dist/objects/query/ir.d.ts +14 -1
  137. package/dist/objects/query/ir.d.ts.map +1 -1
  138. package/dist/objects/query/links.d.ts +25 -0
  139. package/dist/objects/query/links.d.ts.map +1 -0
  140. package/dist/objects/query/normalize.d.ts.map +1 -1
  141. package/dist/objects/query/planner.d.ts.map +1 -1
  142. package/dist/objects/query/validate.d.ts +1 -0
  143. package/dist/objects/query/validate.d.ts.map +1 -1
  144. package/dist/pipelines/index.js +16 -15
  145. package/dist/pipelines/index.js.map +1 -1
  146. package/dist/projections/builders.d.ts +52 -10
  147. package/dist/projections/builders.d.ts.map +1 -1
  148. package/dist/projections/index.d.ts +2 -1
  149. package/dist/projections/index.d.ts.map +1 -1
  150. package/dist/projections/internal.d.ts +4 -1
  151. package/dist/projections/internal.d.ts.map +1 -1
  152. package/dist/projections/internal.js +22 -17
  153. package/dist/projections/internal.js.map +1 -1
  154. package/dist/projections/run-dispatch.d.ts +1 -0
  155. package/dist/projections/run-dispatch.d.ts.map +1 -1
  156. package/dist/projections/timestamp.d.ts +3 -0
  157. package/dist/projections/timestamp.d.ts.map +1 -0
  158. package/dist/projections/types.d.ts +21 -9
  159. package/dist/projections/types.d.ts.map +1 -1
  160. package/dist/projections/validation.d.ts +6 -5
  161. package/dist/projections/validation.d.ts.map +1 -1
  162. package/dist/query.d.ts +2 -1
  163. package/dist/query.d.ts.map +1 -1
  164. package/dist/query.js +2 -2
  165. package/dist/queues/index.d.ts +1 -1
  166. package/dist/queues/index.d.ts.map +1 -1
  167. package/dist/queues/types.d.ts +7 -0
  168. package/dist/queues/types.d.ts.map +1 -1
  169. package/dist/runtime/ai-cost.d.ts +8 -0
  170. package/dist/runtime/ai-cost.d.ts.map +1 -0
  171. package/dist/runtime/create.d.ts +3 -0
  172. package/dist/runtime/create.d.ts.map +1 -1
  173. package/dist/runtime/definitions.d.ts +3 -0
  174. package/dist/runtime/definitions.d.ts.map +1 -1
  175. package/dist/runtime/host.d.ts +2 -0
  176. package/dist/runtime/host.d.ts.map +1 -1
  177. package/dist/runtime/resolve-definitions.d.ts +2 -0
  178. package/dist/runtime/resolve-definitions.d.ts.map +1 -1
  179. package/dist/storage/agents/in-memory.d.ts +22 -4
  180. package/dist/storage/agents/in-memory.d.ts.map +1 -1
  181. package/dist/storage/agents/index.d.ts +1 -1
  182. package/dist/storage/agents/index.d.ts.map +1 -1
  183. package/dist/storage/agents/provider.d.ts +31 -0
  184. package/dist/storage/agents/provider.d.ts.map +1 -1
  185. package/dist/storage/agents/provider.js +22 -7
  186. package/dist/storage/agents/provider.js.map +1 -1
  187. package/dist/storage/agents/types.d.ts +75 -4
  188. package/dist/storage/agents/types.d.ts.map +1 -1
  189. package/dist/storage/ai-cost/analytics.d.ts +61 -0
  190. package/dist/storage/ai-cost/analytics.d.ts.map +1 -0
  191. package/dist/storage/ai-cost/codec.d.ts +14 -0
  192. package/dist/storage/ai-cost/codec.d.ts.map +1 -0
  193. package/dist/storage/ai-cost/errors.d.ts +7 -0
  194. package/dist/storage/ai-cost/errors.d.ts.map +1 -0
  195. package/dist/storage/ai-cost/in-memory.d.ts +32 -0
  196. package/dist/storage/ai-cost/in-memory.d.ts.map +1 -0
  197. package/dist/storage/ai-cost/index.d.ts +6 -0
  198. package/dist/storage/ai-cost/index.d.ts.map +1 -0
  199. package/dist/storage/ai-cost/provider.d.ts +7 -0
  200. package/dist/storage/ai-cost/provider.d.ts.map +1 -0
  201. package/dist/storage/ai-cost/provider.js +132 -0
  202. package/dist/storage/ai-cost/provider.js.map +10 -0
  203. package/dist/storage/ai-cost/types.d.ts +154 -0
  204. package/dist/storage/ai-cost/types.d.ts.map +1 -0
  205. package/dist/storage/ai-cost/validation.d.ts +7 -0
  206. package/dist/storage/ai-cost/validation.d.ts.map +1 -0
  207. package/dist/storage/ai-usage/in-memory.d.ts +2 -1
  208. package/dist/storage/ai-usage/in-memory.d.ts.map +1 -1
  209. package/dist/storage/ai-usage/index.d.ts +1 -1
  210. package/dist/storage/ai-usage/index.d.ts.map +1 -1
  211. package/dist/storage/ai-usage/types.d.ts +6 -0
  212. package/dist/storage/ai-usage/types.d.ts.map +1 -1
  213. package/dist/storage/in-memory/index.d.ts +5 -0
  214. package/dist/storage/in-memory/index.d.ts.map +1 -1
  215. package/dist/storage/index.d.ts +6 -3
  216. package/dist/storage/index.d.ts.map +1 -1
  217. package/dist/storage/index.js +33 -21
  218. package/dist/storage/index.js.map +1 -1
  219. package/dist/storage/objects/in-memory.d.ts +6 -3
  220. package/dist/storage/objects/in-memory.d.ts.map +1 -1
  221. package/dist/storage/objects/index.d.ts +3 -1
  222. package/dist/storage/objects/index.d.ts.map +1 -1
  223. package/dist/storage/objects/keys.d.ts +16 -0
  224. package/dist/storage/objects/keys.d.ts.map +1 -0
  225. package/dist/storage/objects/types.d.ts +33 -6
  226. package/dist/storage/objects/types.d.ts.map +1 -1
  227. package/dist/storage/ontology/in-memory/materializations.d.ts.map +1 -1
  228. package/dist/storage/ontology/materializations.d.ts +3 -0
  229. package/dist/storage/ontology/materializations.d.ts.map +1 -1
  230. package/dist/storage/ontology/provider.js +1 -1
  231. package/dist/storage/operation-scope.d.ts.map +1 -1
  232. package/dist/storage/operation-scope.js +1 -1
  233. package/dist/storage/types.d.ts +2 -0
  234. package/dist/storage/types.d.ts.map +1 -1
  235. package/dist/storage/workflow-runs/provider.js +10 -5
  236. package/dist/storage/workflow-runs/provider.js.map +1 -1
  237. package/dist/syncs/index.js +16 -15
  238. package/dist/syncs/index.js.map +1 -1
  239. package/dist/testing/agent-storage-contract.d.ts +3 -2
  240. package/dist/testing/agent-storage-contract.d.ts.map +1 -1
  241. package/dist/testing/ai-cost-storage-contract.d.ts +12 -0
  242. package/dist/testing/ai-cost-storage-contract.d.ts.map +1 -0
  243. package/dist/testing/ai-usage-storage-contract.d.ts.map +1 -1
  244. package/dist/testing/effective-storage-contract.d.ts +1 -1
  245. package/dist/testing/effective-storage-contract.d.ts.map +1 -1
  246. package/dist/testing/index.d.ts +1 -0
  247. package/dist/testing/index.d.ts.map +1 -1
  248. package/dist/testing/index.js +2525 -1480
  249. package/dist/testing/index.js.map +10 -9
  250. package/dist/testing/lake-storage-contract.d.ts.map +1 -1
  251. package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
  252. package/dist/testing/object-query-contract.d.ts +1 -1
  253. package/dist/testing/object-query-contract.d.ts.map +1 -1
  254. package/dist/webhooks/internal.js +14 -13
  255. package/dist/webhooks/internal.js.map +2 -2
  256. package/dist/workers/index.js +12 -2
  257. package/dist/workers/index.js.map +3 -3
  258. package/dist/workers/queue-worker.d.ts +2 -0
  259. package/dist/workers/queue-worker.d.ts.map +1 -1
  260. package/dist/workflows/execution.d.ts +3 -0
  261. package/dist/workflows/execution.d.ts.map +1 -1
  262. package/dist/workflows/index.js +30 -28
  263. package/dist/workflows/index.js.map +1 -1
  264. package/package.json +7 -1
  265. package/src/agents/adapters.ts +64 -23
  266. package/src/agents/builders.ts +3 -3
  267. package/src/agents/context-compaction.ts +261 -0
  268. package/src/agents/errors.ts +2 -2
  269. package/src/agents/execution.ts +14 -2
  270. package/src/agents/ids.ts +5 -0
  271. package/src/agents/index.ts +32 -6
  272. package/src/agents/request.ts +5 -0
  273. package/src/agents/streams.ts +56 -0
  274. package/src/agents/thread-context-projection.ts +93 -0
  275. package/src/agents/tool-definition.ts +17 -2
  276. package/src/agents/tool-result.ts +61 -0
  277. package/src/agents/types.ts +57 -1
  278. package/src/agents/validation.ts +36 -6
  279. package/src/http/api-routes.ts +7 -7
  280. package/src/index.ts +27 -0
  281. package/src/lake-storage/types.ts +2 -1
  282. package/src/materialization/model.ts +4 -0
  283. package/src/materializer/edits/apply.ts +55 -2
  284. package/src/materializer/edits/operations.ts +8 -1
  285. package/src/materializer/edits/working-state.ts +7 -0
  286. package/src/materializer/effective/resolve.ts +78 -9
  287. package/src/materializer/execution/work-records.ts +3 -1
  288. package/src/materializer/projections/entry-validator.ts +23 -1
  289. package/src/materializer/projections/replacement-plan.ts +2 -0
  290. package/src/materializer/shared/normalize.ts +16 -0
  291. package/src/materializer/telemetry/append.ts +33 -16
  292. package/src/models/index.ts +71 -0
  293. package/src/objects/execution.ts +20 -0
  294. package/src/objects/link/endpoints.ts +2 -1
  295. package/src/objects/query/executor.ts +42 -11
  296. package/src/objects/query/explain.ts +11 -0
  297. package/src/objects/query/index.ts +6 -0
  298. package/src/objects/query/ir.ts +16 -0
  299. package/src/objects/query/links.ts +308 -0
  300. package/src/objects/query/normalize.ts +40 -1
  301. package/src/objects/query/planner.ts +5 -0
  302. package/src/objects/query/validate.ts +58 -2
  303. package/src/projections/builders.ts +320 -50
  304. package/src/projections/index.ts +7 -0
  305. package/src/projections/internal.ts +4 -1
  306. package/src/projections/ownership.ts +5 -5
  307. package/src/projections/registry.ts +16 -3
  308. package/src/projections/revision.ts +35 -5
  309. package/src/projections/run-dispatch.ts +10 -1
  310. package/src/projections/timestamp.ts +66 -0
  311. package/src/projections/types.ts +20 -9
  312. package/src/projections/validation.ts +85 -19
  313. package/src/query.ts +2 -0
  314. package/src/queues/index.ts +1 -0
  315. package/src/queues/types.ts +8 -0
  316. package/src/runtime/ai-cost.ts +15 -0
  317. package/src/runtime/create.ts +4 -0
  318. package/src/runtime/definitions.ts +3 -0
  319. package/src/runtime/host.ts +2 -0
  320. package/src/runtime/resolve-definitions.ts +28 -0
  321. package/src/storage/agents/in-memory.ts +186 -4
  322. package/src/storage/agents/index.ts +5 -0
  323. package/src/storage/agents/provider.ts +225 -0
  324. package/src/storage/agents/types.ts +82 -3
  325. package/src/storage/ai-cost/analytics.ts +602 -0
  326. package/src/storage/ai-cost/codec.ts +136 -0
  327. package/src/storage/ai-cost/errors.ts +12 -0
  328. package/src/storage/ai-cost/in-memory.ts +164 -0
  329. package/src/storage/ai-cost/index.ts +35 -0
  330. package/src/storage/ai-cost/provider.ts +20 -0
  331. package/src/storage/ai-cost/types.ts +193 -0
  332. package/src/storage/ai-cost/validation.ts +337 -0
  333. package/src/storage/ai-usage/in-memory.ts +23 -0
  334. package/src/storage/ai-usage/index.ts +1 -0
  335. package/src/storage/ai-usage/types.ts +10 -0
  336. package/src/storage/in-memory/index.ts +50 -0
  337. package/src/storage/index.ts +48 -0
  338. package/src/storage/objects/in-memory.ts +103 -16
  339. package/src/storage/objects/index.ts +9 -0
  340. package/src/storage/objects/keys.ts +36 -0
  341. package/src/storage/objects/types.ts +34 -6
  342. package/src/storage/ontology/in-memory/materializations.ts +1 -0
  343. package/src/storage/ontology/materializations.ts +3 -0
  344. package/src/storage/ontology/provider-header-validation.ts +2 -2
  345. package/src/storage/operation-scope.ts +1 -0
  346. package/src/storage/types.ts +2 -0
  347. package/src/testing/agent-storage-contract.ts +353 -2
  348. package/src/testing/ai-cost-storage-contract.ts +320 -0
  349. package/src/testing/ai-usage-storage-contract.ts +35 -0
  350. package/src/testing/effective-storage-contract.ts +194 -4
  351. package/src/testing/index.ts +5 -0
  352. package/src/testing/lake-storage-contract.ts +56 -0
  353. package/src/testing/materializer-storage-contract.ts +120 -2
  354. package/src/testing/object-query-contract.ts +208 -1
  355. package/src/workers/queue-worker.ts +14 -1
  356. package/src/workflows/execution.ts +31 -10
  357. package/dist/agents/prompt.d.ts +0 -15
  358. package/dist/agents/prompt.d.ts.map +0 -1
  359. package/dist/chunk-0mbx247x.js.map +0 -43
  360. package/dist/chunk-34bqh420.js.map +0 -23
  361. package/dist/chunk-57zpb99z.js.map +0 -10
  362. package/dist/chunk-663csy96.js.map +0 -10
  363. package/dist/chunk-6wetht33.js +0 -89
  364. package/dist/chunk-6wetht33.js.map +0 -10
  365. package/dist/chunk-88ppkr54.js.map +0 -12
  366. package/dist/chunk-nnyp53zt.js.map +0 -13
  367. package/dist/chunk-nten49ta.js.map +0 -12
  368. package/dist/chunk-st4xgxey.js.map +0 -45
  369. package/dist/chunk-vp1vc6ee.js +0 -35
  370. package/dist/chunk-vp1vc6ee.js.map +0 -11
  371. package/src/agents/prompt.ts +0 -57
  372. /package/dist/{chunk-sa4340y1.js.map → chunk-1yz3x65y.js.map} +0 -0
  373. /package/dist/{chunk-gqdd7508.js.map → chunk-4rh2m6zg.js.map} +0 -0
  374. /package/dist/{chunk-4x43bkbp.js.map → chunk-a09jx26t.js.map} +0 -0
  375. /package/dist/{chunk-zg9yryhz.js.map → chunk-cbkm2vam.js.map} +0 -0
  376. /package/dist/{chunk-8ryen3p3.js.map → chunk-f6erf2vv.js.map} +0 -0
  377. /package/dist/{chunk-bct7hmfc.js.map → chunk-g13869yf.js.map} +0 -0
  378. /package/dist/{chunk-0k4avqr2.js.map → chunk-hbeh8j9w.js.map} +0 -0
  379. /package/dist/{chunk-qvybnnpe.js.map → chunk-nzw7sm3b.js.map} +0 -0
  380. /package/dist/{chunk-bh6k3nc6.js.map → chunk-rs1wbvy6.js.map} +0 -0
  381. /package/dist/{chunk-7pc8b818.js.map → chunk-sxwk41qa.js.map} +0 -0
  382. /package/dist/{chunk-5egfka8j.js.map → chunk-tycbzedm.js.map} +0 -0
  383. /package/dist/{chunk-g9t3kdtx.js.map → chunk-x2yw73hy.js.map} +0 -0
@@ -8,7 +8,9 @@ import {
8
8
  } from "./context"
9
9
  import { serializeAgentContextForModel } from "./context-model"
10
10
  import { AgentMessageAdapterError } from "./errors"
11
- import type { AgentMessage, AgentMessagePart, AgentMessageRole } from "./message"
11
+ import type { AgentMessage, AgentMessagePart, AgentMessageRole, AgentToolCallPart } from "./message"
12
+ import { isAgentToolResult } from "./tool-result"
13
+ import type { AgentToolFileContent } from "./types"
12
14
 
13
15
  // ── Inbound (write) — deliberately WIDE ────────────────────────────────────────────────────────
14
16
  //
@@ -159,6 +161,14 @@ export interface AgentFileDataProjection {
159
161
  readonly filename?: string
160
162
  }
161
163
 
164
+ export interface AgentToolResultFileResolverInput<TMessage extends AgentMessage = AgentMessage> {
165
+ readonly message: TMessage
166
+ readonly part: AgentToolCallPart
167
+ readonly partIndex: number
168
+ readonly contentPart: AgentToolFileContent
169
+ readonly contentIndex: number
170
+ }
171
+
162
172
  export interface ToModelMessagesOptions<TMessage extends AgentMessage = AgentMessage> {
163
173
  /**
164
174
  * Convert a stored file reference into model-readable data. When omitted, file parts are skipped
@@ -173,6 +183,10 @@ export interface ToModelMessagesOptions<TMessage extends AgentMessage = AgentMes
173
183
  * models that cannot consume inline files.
174
184
  */
175
185
  readonly fileText?: (input: AgentFileDataResolverInput<TMessage>) => string | undefined
186
+ /** Add current metadata, sandbox paths, and projection notes for a tool-result file. */
187
+ readonly toolResultFileText?: (
188
+ input: AgentToolResultFileResolverInput<TMessage>
189
+ ) => string | undefined
176
190
  }
177
191
 
178
192
  // ── Helpers ─────────────────────────────────────────────────────────────────────────────────────
@@ -337,7 +351,7 @@ function fromUiContextPart(part: AgentInboundUiMessagePart): AgentMessagePart {
337
351
  }
338
352
  }
339
353
 
340
- function fromAiSdkToolPart(part: AgentInboundUiMessagePart): AgentToolCallPartResult {
354
+ function fromAiSdkToolPart(part: AgentInboundUiMessagePart): AgentToolCallPart {
341
355
  const dynamic = part.type === "dynamic-tool"
342
356
  const toolName = toolNameFromInbound(part)
343
357
  assertAdapter(
@@ -373,8 +387,6 @@ function fromAiSdkToolPart(part: AgentInboundUiMessagePart): AgentToolCallPartRe
373
387
  return { ...base, state: "output-error", errorText: part.errorText }
374
388
  }
375
389
 
376
- type AgentToolCallPartResult = Extract<AgentMessagePart, { type: "tool-call" }>
377
-
378
390
  // ── toUiMessage (read) ────────────────────────────────────────────────────────────────────────
379
391
 
380
392
  /** Reconstruct an SDK-shaped UI message from a stored message. Exact inverse of {@link fromAiSdk}. */
@@ -410,7 +422,7 @@ function toUiPart(part: AgentMessagePart): AgentUiMessagePart {
410
422
  }
411
423
  }
412
424
 
413
- function toUiToolPart(part: AgentToolCallPartResult): AgentUiToolPart {
425
+ function toUiToolPart(part: AgentToolCallPart): AgentUiToolPart {
414
426
  const body = {
415
427
  toolCallId: part.toolCallId,
416
428
  ...(part.providerExecuted === undefined ? {} : { providerExecuted: part.providerExecuted }),
@@ -570,17 +582,17 @@ function appendAssistantModelMessages<TMessage extends AgentMessage>(
570
582
  } else if (part.type === "tool-call") {
571
583
  content.push(toolCallModelPart(part))
572
584
  if (part.providerExecuted === true) {
573
- content.push(toolResultModelPart(part, "json"))
585
+ content.push(toolResultModelPart(message, part, partIndex, "json", options))
574
586
  }
575
587
  }
576
588
  }
577
589
  result.push({ role: "assistant", content })
578
590
 
579
- const toolResults = current
580
- .map(({ part }) => part)
581
- .filter(isToolCallPart)
582
- .filter((part) => part.providerExecuted !== true)
583
- .map((part) => toolResultModelPart(part, "text"))
591
+ const toolResults = current.flatMap(({ part, partIndex }) =>
592
+ part.type === "tool-call" && part.providerExecuted !== true
593
+ ? [toolResultModelPart(message, part, partIndex, "text", options)]
594
+ : []
595
+ )
584
596
  if (toolResults.length > 0) {
585
597
  result.push({ role: "tool", content: toolResults })
586
598
  }
@@ -596,7 +608,7 @@ function appendAssistantModelMessages<TMessage extends AgentMessage>(
596
608
  flush()
597
609
  }
598
610
 
599
- function toolCallModelPart(part: AgentToolCallPartResult): AgentModelToolCallPart {
611
+ function toolCallModelPart(part: AgentToolCallPart): AgentModelToolCallPart {
600
612
  return {
601
613
  type: "tool-call",
602
614
  toolCallId: part.toolCallId,
@@ -607,37 +619,66 @@ function toolCallModelPart(part: AgentToolCallPartResult): AgentModelToolCallPar
607
619
  }
608
620
  }
609
621
 
610
- function toolResultModelPart(
611
- part: AgentToolCallPartResult,
612
- errorMode: "text" | "json"
622
+ function toolResultModelPart<TMessage extends AgentMessage>(
623
+ message: TMessage,
624
+ part: AgentToolCallPart,
625
+ partIndex: number,
626
+ errorMode: "text" | "json",
627
+ options: ToModelMessagesOptions<TMessage>
613
628
  ): AgentModelToolResultPart {
614
629
  return {
615
630
  type: "tool-result",
616
631
  toolCallId: part.toolCallId,
617
632
  toolName: part.toolName,
618
- output: toolResultOutput(part, errorMode),
633
+ output: toolResultOutput(message, part, partIndex, errorMode, options),
619
634
  ...(part.providerMetadata === undefined ? {} : { providerOptions: part.providerMetadata }),
620
635
  }
621
636
  }
622
637
 
623
- function toolResultOutput(
624
- part: AgentToolCallPartResult,
625
- errorMode: "text" | "json"
638
+ function toolResultOutput<TMessage extends AgentMessage>(
639
+ message: TMessage,
640
+ part: AgentToolCallPart,
641
+ partIndex: number,
642
+ errorMode: "text" | "json",
643
+ options: ToModelMessagesOptions<TMessage>
626
644
  ): AgentModelToolOutput {
627
645
  if (part.state === "output-error") {
628
646
  return errorMode === "json"
629
647
  ? { type: "error-json", value: part.errorText }
630
648
  : { type: "error-text", value: part.errorText }
631
649
  }
650
+ if (isAgentToolResult(part.output)) {
651
+ const value: string[] = []
652
+ part.output.content.forEach((contentPart, contentIndex) => {
653
+ if (contentPart.type === "text") {
654
+ value.push(contentPart.text)
655
+ return
656
+ }
657
+
658
+ const resolverInput = { message, part, partIndex, contentPart, contentIndex }
659
+ const fileContext = options.toolResultFileText?.(resolverInput)
660
+ if (fileContext) {
661
+ value.push(fileContext)
662
+ } else {
663
+ value.push(toolResultFileFallbackText(contentPart))
664
+ }
665
+ })
666
+ return { type: "text", value: value.join("\n") }
667
+ }
632
668
  return typeof part.output === "string"
633
669
  ? { type: "text", value: part.output }
634
670
  : { type: "json", value: part.output }
635
671
  }
636
672
 
637
- function isTextPart(part: AgentMessagePart): part is Extract<AgentMessagePart, { type: "text" }> {
638
- return part.type === "text"
673
+ function toolResultFileFallbackText(part: AgentToolFileContent): string {
674
+ const attributes = [
675
+ part.fileRef.fileName ? `name=${JSON.stringify(part.fileRef.fileName)}` : undefined,
676
+ part.fileRef.mediaType ? `mediaType=${JSON.stringify(part.fileRef.mediaType)}` : undefined,
677
+ `sizeBytes=${part.fileRef.sizeBytes}`,
678
+ ].filter((value): value is string => value !== undefined)
679
+ return `[Tool-created file: ${attributes.join(" ")}. Contents are not available inline.]`
639
680
  }
640
681
 
641
- function isToolCallPart(part: AgentMessagePart): part is AgentToolCallPartResult {
642
- return part.type === "tool-call"
682
+ function isTextPart(part: AgentMessagePart): part is Extract<AgentMessagePart, { type: "text" }> {
683
+ return part.type === "text"
643
684
  }
@@ -16,10 +16,10 @@ import {
16
16
  assertValidAgentToolDescription,
17
17
  assertValidAgentToolInput,
18
18
  assertValidAgentToolName,
19
- assertValidLoopConfig,
20
19
  assertValidProviderOptions,
21
20
  assertValidReasoningLevel,
22
21
  groupIdsFromDefinitions,
22
+ resolveAgentLoopConfig,
23
23
  } from "./validation"
24
24
 
25
25
  /**
@@ -76,7 +76,7 @@ export function defineAgent<const TId extends string>(
76
76
  }
77
77
  assertValidReasoningLevel(config.reasoning)
78
78
  assertValidProviderOptions(config.providerOptions)
79
- assertValidLoopConfig(config.loop)
79
+ const loop = resolveAgentLoopConfig(config.loop)
80
80
  const groupIds = groupIdsFromDefinitions(id, config.groups)
81
81
  const tools = toolsFromDefinitions(id, config.tools)
82
82
 
@@ -91,6 +91,6 @@ export function defineAgent<const TId extends string>(
91
91
  groupIds,
92
92
  tools,
93
93
  ...(config.description !== undefined ? { description: config.description } : {}),
94
- ...(config.loop !== undefined ? { loop: config.loop } : {}),
94
+ ...(loop !== undefined ? { loop } : {}),
95
95
  })
96
96
  }
@@ -0,0 +1,261 @@
1
+ import { stableJsonStringify } from "../json"
2
+ import type { AgentMessageRecord } from "../storage/agents/types"
3
+ import type { AgentMessage, AgentMessagePart } from "./message"
4
+
5
+ export const AGENT_CONTEXT_ESTIMATOR_VERSION = 1 as const
6
+
7
+ const CHARS_PER_TOKEN = 4
8
+ const REQUEST_OVERHEAD_TOKENS = 8
9
+ const MESSAGE_OVERHEAD_TOKENS = 8
10
+ const TOOL_OVERHEAD_TOKENS = 16
11
+ const STEP_OVERHEAD_TOKENS = 2
12
+ const IMAGE_ALLOWANCE_TOKENS = 1_200
13
+ const FILE_TEXT_INLINE_MAX_BYTES = 50 * 1024
14
+ const FILE_TEXT_INLINE_TOTAL_MAX_BYTES = 200 * 1024
15
+ const TOOL_RESULT_SUMMARY_MAX_CHARS = 2_000
16
+
17
+ export interface AgentContextEstimateTool {
18
+ readonly name: string
19
+ readonly description: string
20
+ /** Deterministic JSON-schema serialization sent for this tool. */
21
+ readonly inputSchema: string
22
+ }
23
+
24
+ export interface EstimateAgentContextRequestTokensInput {
25
+ readonly systemPrompt: string
26
+ readonly tools: readonly AgentContextEstimateTool[]
27
+ readonly messages: readonly AgentMessage[]
28
+ }
29
+
30
+ export interface AgentContextTokenEstimate {
31
+ readonly tokens: number
32
+ readonly estimatorVersion: typeof AGENT_CONTEXT_ESTIMATOR_VERSION
33
+ }
34
+
35
+ export interface AgentContextCompactionBoundary {
36
+ readonly messagesToSummarize: readonly AgentMessageRecord[]
37
+ readonly retainedMessages: readonly AgentMessageRecord[]
38
+ readonly summarizedThroughSeq: number
39
+ }
40
+
41
+ /** Compaction begins only once the estimated request crosses the reserved input budget. */
42
+ export function shouldCompactAgentContext(input: {
43
+ readonly estimatedInputTokens: number
44
+ readonly inputBudgetTokens: number
45
+ }): boolean {
46
+ return input.estimatedInputTokens > input.inputBudgetTokens
47
+ }
48
+
49
+ /** Estimate the provider request shape with one stable, conservative character heuristic. */
50
+ export function estimateAgentContextRequestTokens(
51
+ input: EstimateAgentContextRequestTokensInput
52
+ ): AgentContextTokenEstimate {
53
+ const toolTokens = input.tools.reduce(
54
+ (total, tool) =>
55
+ total +
56
+ TOOL_OVERHEAD_TOKENS +
57
+ textTokens(tool.name) +
58
+ textTokens(tool.description) +
59
+ textTokens(tool.inputSchema),
60
+ 0
61
+ )
62
+ return {
63
+ tokens:
64
+ REQUEST_OVERHEAD_TOKENS +
65
+ textTokens(input.systemPrompt) +
66
+ toolTokens +
67
+ estimateAgentContextMessagesTokens(input.messages).tokens,
68
+ estimatorVersion: AGENT_CONTEXT_ESTIMATOR_VERSION,
69
+ }
70
+ }
71
+
72
+ /** Estimate message-only growth after a provider-usage anchor. */
73
+ export function estimateAgentContextMessagesTokens(
74
+ messages: readonly AgentMessage[]
75
+ ): AgentContextTokenEstimate {
76
+ const attachments = { textBytesRemaining: FILE_TEXT_INLINE_TOTAL_MAX_BYTES }
77
+ let tokens = 0
78
+ for (const message of messages) {
79
+ tokens += estimateMessageTokens(message, attachments)
80
+ }
81
+ return { tokens, estimatorVersion: AGENT_CONTEXT_ESTIMATOR_VERSION }
82
+ }
83
+
84
+ /** Select the safe user boundary whose retained tail is closest to the configured recent budget. */
85
+ export function selectAgentContextCompactionBoundary(input: {
86
+ readonly messages: readonly AgentMessageRecord[]
87
+ readonly keepRecentTokens: number
88
+ }): AgentContextCompactionBoundary | null {
89
+ if (input.messages.length < 2) return null
90
+
91
+ let retainedTokens = 0
92
+ let boundaryIndex: number | null = null
93
+ let closestDistance = Number.POSITIVE_INFINITY
94
+ for (let index = input.messages.length - 1; index > 0; index -= 1) {
95
+ retainedTokens += estimateAgentContextMessagesTokens([input.messages[index]!]).tokens
96
+ if (input.messages[index]?.role !== "user") continue
97
+
98
+ const distance = Math.abs(input.keepRecentTokens - retainedTokens)
99
+ if (distance <= closestDistance) {
100
+ boundaryIndex = index
101
+ closestDistance = distance
102
+ }
103
+ if (retainedTokens >= input.keepRecentTokens) break
104
+ }
105
+
106
+ if (boundaryIndex === null) return null
107
+
108
+ const summarizedThroughSeq = input.messages[boundaryIndex - 1]?.seq
109
+ if (summarizedThroughSeq === undefined) return null
110
+ return {
111
+ messagesToSummarize: input.messages.slice(0, boundaryIndex),
112
+ retainedMessages: input.messages.slice(boundaryIndex),
113
+ summarizedThroughSeq,
114
+ }
115
+ }
116
+
117
+ /** Serialize durable conversation content as escaped quoted data for the summary model. */
118
+ export function serializeAgentMessagesForSummary(messages: readonly AgentMessageRecord[]): string {
119
+ const lines = ["<sixb_conversation_history>"]
120
+ for (const message of messages) {
121
+ lines.push(
122
+ ` <message id="${escapeXml(message.id)}" seq="${message.seq}" role="${message.role}">`
123
+ )
124
+ message.parts.forEach((part, partIndex) => {
125
+ lines.push(...serializeSummaryPart(message, part, partIndex))
126
+ })
127
+ lines.push(" </message>")
128
+ }
129
+ lines.push("</sixb_conversation_history>")
130
+ return lines.join("\n")
131
+ }
132
+
133
+ function estimateMessageTokens(
134
+ message: AgentMessage,
135
+ attachments: { textBytesRemaining: number }
136
+ ): number {
137
+ let tokens = MESSAGE_OVERHEAD_TOKENS
138
+ for (const part of message.parts) {
139
+ switch (part.type) {
140
+ case "text":
141
+ case "reasoning":
142
+ tokens += textTokens(part.text)
143
+ break
144
+ case "step-start":
145
+ tokens += STEP_OVERHEAD_TOKENS
146
+ break
147
+ case "context":
148
+ tokens += textTokens(stableJsonStringify(part.context))
149
+ break
150
+ case "tool-call":
151
+ tokens +=
152
+ TOOL_OVERHEAD_TOKENS +
153
+ textTokens(part.toolName) +
154
+ textTokens(stableJsonStringify(part.input)) +
155
+ (part.state === "output-available"
156
+ ? textTokens(stableJsonStringify(part.output))
157
+ : textTokens(part.errorText))
158
+ break
159
+ case "file": {
160
+ const file = part.fileRef
161
+ tokens += textTokens(
162
+ [file.blobId, file.digest, file.fileName, file.mediaType, file.logicalPath]
163
+ .filter((value): value is string => value !== undefined)
164
+ .join(" ")
165
+ )
166
+ if (message.role !== "assistant") {
167
+ if (looksLikeImage(file.mediaType, file.fileName)) {
168
+ tokens += IMAGE_ALLOWANCE_TOKENS
169
+ } else {
170
+ const inlineBytes = Math.min(
171
+ file.sizeBytes,
172
+ FILE_TEXT_INLINE_MAX_BYTES,
173
+ attachments.textBytesRemaining
174
+ )
175
+ attachments.textBytesRemaining -= inlineBytes
176
+ tokens += Math.ceil(inlineBytes / CHARS_PER_TOKEN)
177
+ }
178
+ }
179
+ break
180
+ }
181
+ }
182
+ }
183
+ return tokens
184
+ }
185
+
186
+ function serializeSummaryPart(
187
+ message: AgentMessageRecord,
188
+ part: AgentMessagePart,
189
+ partIndex: number
190
+ ): string[] {
191
+ const indent = " "
192
+ switch (part.type) {
193
+ case "text":
194
+ return [`${indent}<text>${escapeXml(part.text)}</text>`]
195
+ case "reasoning":
196
+ case "step-start":
197
+ return []
198
+ case "context":
199
+ return part.context.kind === "object"
200
+ ? [
201
+ `${indent}<object_context origin="${part.origin}" object_type_id="${escapeXml(part.context.ref.objectTypeId)}" primary_id="${escapeXml(part.context.ref.primaryId)}" />`,
202
+ ]
203
+ : [
204
+ `${indent}<app_context origin="${part.origin}" id="${escapeXml(part.context.id)}" label="${escapeXml(part.context.label)}">`,
205
+ `${indent} <description>${escapeXml(part.context.description)}</description>`,
206
+ `${indent} <value format="json">${escapeXml(stableJsonStringify(part.context.value))}</value>`,
207
+ `${indent}</app_context>`,
208
+ ]
209
+ case "file": {
210
+ const file = part.fileRef
211
+ const attributes = [
212
+ `message_id="${escapeXml(message.id)}"`,
213
+ `part_index="${partIndex}"`,
214
+ `blob_id="${escapeXml(file.blobId)}"`,
215
+ `digest="${escapeXml(file.digest)}"`,
216
+ `size_bytes="${file.sizeBytes}"`,
217
+ ...(file.fileName === undefined ? [] : [`file_name="${escapeXml(file.fileName)}"`]),
218
+ ...(file.mediaType === undefined ? [] : [`media_type="${escapeXml(file.mediaType)}"`]),
219
+ ...(file.logicalPath === undefined
220
+ ? []
221
+ : [`logical_path="${escapeXml(file.logicalPath)}"`]),
222
+ ]
223
+ return [`${indent}<file ${attributes.join(" ")} />`]
224
+ }
225
+ case "tool-call": {
226
+ const output =
227
+ part.state === "output-available"
228
+ ? truncateToolResult(stableJsonStringify(part.output))
229
+ : truncateToolResult(part.errorText)
230
+ return [
231
+ `${indent}<tool_call id="${escapeXml(part.toolCallId)}" name="${escapeXml(part.toolName)}" state="${part.state}">`,
232
+ `${indent} <input format="json">${escapeXml(stableJsonStringify(part.input))}</input>`,
233
+ `${indent} <result>${escapeXml(output)}</result>`,
234
+ `${indent}</tool_call>`,
235
+ ]
236
+ }
237
+ }
238
+ }
239
+
240
+ function truncateToolResult(value: string): string {
241
+ if (value.length <= TOOL_RESULT_SUMMARY_MAX_CHARS) return value
242
+ return `${value.slice(0, TOOL_RESULT_SUMMARY_MAX_CHARS)}\n[truncated ${value.length - TOOL_RESULT_SUMMARY_MAX_CHARS} characters]`
243
+ }
244
+
245
+ function looksLikeImage(mediaType: string | undefined, fileName: string | undefined): boolean {
246
+ if (mediaType?.toLowerCase().startsWith("image/")) return true
247
+ return /\.(?:avif|gif|jpe?g|png|webp)$/i.test(fileName ?? "")
248
+ }
249
+
250
+ function textTokens(value: string): number {
251
+ return Math.ceil(new TextEncoder().encode(value).byteLength / CHARS_PER_TOKEN)
252
+ }
253
+
254
+ function escapeXml(value: string): string {
255
+ return value
256
+ .replaceAll("&", "&amp;")
257
+ .replaceAll("<", "&lt;")
258
+ .replaceAll(">", "&gt;")
259
+ .replaceAll('"', "&quot;")
260
+ .replaceAll("'", "&apos;")
261
+ }
@@ -25,7 +25,7 @@ export class AgentToolPublicError extends Error {
25
25
  readonly name: string = "AgentToolPublicError"
26
26
  }
27
27
 
28
- /** Raised when an agent tool result cannot cross the durable JSON message boundary. */
28
+ /** Raised when an agent tool result cannot cross the durable message boundary. */
29
29
  export class AgentToolResultValidationError extends Error {
30
30
  readonly name = "AgentToolResultValidationError"
31
31
 
@@ -34,7 +34,7 @@ export class AgentToolResultValidationError extends Error {
34
34
  readonly reason: string,
35
35
  options?: ErrorOptions
36
36
  ) {
37
- super(`[Sixb] Agent tool '${toolName}' result must be a JSON value; ${reason}.`, options)
37
+ super(`[Sixb] Agent tool '${toolName}' returned an invalid result; ${reason}.`, options)
38
38
  }
39
39
  }
40
40
 
@@ -1,6 +1,7 @@
1
1
  import { principalsEqual, SYSTEM_PRINCIPAL } from "../auth"
2
2
  import { assertAuthorized, isAllowed } from "../authorization"
3
3
  import type { AuthorizablePrincipal, ExecutionContext } from "../execution"
4
+ import { resolveExecutionCosts } from "../runtime/ai-cost"
4
5
  import { resolveExecutionUsage } from "../runtime/ai-usage"
5
6
  import type { SixbRuntimeContext } from "../runtime/types"
6
7
  import type { SecurityDefinitionCatalog } from "../security"
@@ -12,6 +13,7 @@ import type {
12
13
  ListAgentThreadsInput,
13
14
  ListAgentThreadsResult,
14
15
  } from "../storage/agents"
16
+ import type { AiCostSummary } from "../storage/ai-cost"
15
17
  import type { AiModelCallUsage } from "../storage/ai-usage"
16
18
  import { AgentRequestError } from "./errors"
17
19
  import { createAgentThreadId } from "./ids"
@@ -56,6 +58,8 @@ export interface AgentRunView extends AgentRunRecord {
56
58
  readonly requestedBy?: AuthorizablePrincipal
57
59
  /** Derived from the model-call ledger; never persisted on the Agent run row. */
58
60
  readonly usage?: AiModelCallUsage
61
+ /** Preferred valuation; omitted when there are no calls or cost storage is unavailable. */
62
+ readonly cost?: AiCostSummary
59
63
  }
60
64
 
61
65
  export interface AgentRunListResult extends Omit<ListAgentRunsResult, "runs"> {
@@ -219,7 +223,8 @@ async function attachRunViews(
219
223
  runtime: SixbRuntimeContext,
220
224
  runs: readonly AgentRunRecord[]
221
225
  ): Promise<readonly AgentRunView[]> {
222
- const [executions, usages] = await Promise.all([
226
+ const executionIds = runs.map((run) => run.executionId)
227
+ const [executions, usages, costs] = await Promise.all([
223
228
  Promise.all(
224
229
  runs.map((run) =>
225
230
  runtime.storage.executions.getById({
@@ -231,7 +236,12 @@ async function attachRunViews(
231
236
  resolveExecutionUsage({
232
237
  storage: runtime.storage.aiUsage,
233
238
  projectId: runtime.projectId,
234
- executionIds: runs.map((run) => run.executionId),
239
+ executionIds,
240
+ }),
241
+ resolveExecutionCosts({
242
+ storage: runtime.storage.aiCosts,
243
+ projectId: runtime.projectId,
244
+ executionIds,
235
245
  }),
236
246
  ])
237
247
 
@@ -243,12 +253,14 @@ async function attachRunViews(
243
253
  )
244
254
  }
245
255
  const usage = usages[index]
256
+ const cost = usage === undefined ? undefined : costs[index]
246
257
  return {
247
258
  ...run,
248
259
  ...(execution.requestedBy === undefined
249
260
  ? {}
250
261
  : { requestedBy: structuredClone(execution.requestedBy) }),
251
262
  ...(usage === undefined ? {} : { usage }),
263
+ ...(cost === undefined ? {} : { cost }),
252
264
  }
253
265
  })
254
266
  }
package/src/agents/ids.ts CHANGED
@@ -18,6 +18,11 @@ export function createAgentMessageId(): string {
18
18
  return `agt_msg_${randomUUID()}`
19
19
  }
20
20
 
21
+ /** One deterministic context-checkpoint identity per conversational run. */
22
+ export function agentContextCheckpointId(runId: string): string {
23
+ return `agt_ctx_${runId}`
24
+ }
25
+
21
26
  /** A queue delivery's fencing token for writes to an `agent_runs` record. */
22
27
  export function createAgentRunExecutionToken(): string {
23
28
  return `agt_exec_${randomUUID()}`
@@ -11,6 +11,7 @@ export type {
11
11
  AgentModelToolCallPart,
12
12
  AgentModelToolOutput,
13
13
  AgentModelToolResultPart,
14
+ AgentToolResultFileResolverInput,
14
15
  AgentUiMessage,
15
16
  AgentUiMessagePart,
16
17
  AgentUiToolPart,
@@ -52,6 +53,20 @@ export {
52
53
  MAX_AGENT_CONTEXT_ENTRIES,
53
54
  normalizeAgentContextEntries,
54
55
  } from "./context"
56
+ export type {
57
+ AgentContextCompactionBoundary,
58
+ AgentContextEstimateTool,
59
+ AgentContextTokenEstimate,
60
+ EstimateAgentContextRequestTokensInput,
61
+ } from "./context-compaction"
62
+ export {
63
+ AGENT_CONTEXT_ESTIMATOR_VERSION,
64
+ estimateAgentContextMessagesTokens,
65
+ estimateAgentContextRequestTokens,
66
+ selectAgentContextCompactionBoundary,
67
+ serializeAgentMessagesForSummary,
68
+ shouldCompactAgentContext,
69
+ } from "./context-compaction"
55
70
  export { serializeAgentContextForModel } from "./context-model"
56
71
  export { resolveAgentContextParts } from "./context-resolution"
57
72
  export type {
@@ -74,6 +89,7 @@ export {
74
89
  AgentToolResultValidationError,
75
90
  } from "./errors"
76
91
  export {
92
+ agentContextCheckpointId,
77
93
  createAgentMessageId,
78
94
  createAgentRunExecutionToken,
79
95
  createAgentRunId,
@@ -92,12 +108,6 @@ export {
92
108
  type AgentToolCallPart,
93
109
  type AgentToolCallState,
94
110
  } from "./message"
95
- export {
96
- type BuildAgentSystemPromptInput,
97
- buildAgentSystemPrompt,
98
- DEFAULT_AGENT_SYSTEM_CONTEXT,
99
- DEFAULT_AGENT_TASK_SYSTEM_CONTEXT,
100
- } from "./prompt"
101
111
  export {
102
112
  type RequestAgentRunInput,
103
113
  type RequestAgentRunResult,
@@ -105,6 +115,7 @@ export {
105
115
  retryAgentRun,
106
116
  } from "./request"
107
117
  export type {
118
+ AgentCompactionFailureCode,
108
119
  AgentRunControlStreamId,
109
120
  AgentRunFailure,
110
121
  AgentRunFinishedEvent,
@@ -112,6 +123,7 @@ export type {
112
123
  AgentRunStreamId,
113
124
  } from "./streams"
114
125
  export {
126
+ AGENT_COMPACTION_FAILURE_CODES,
115
127
  AGENT_RUN_CANCEL_RECORD,
116
128
  AGENT_RUN_STREAM_SCHEMA_VERSION,
117
129
  agentRunControlStreamDefinition,
@@ -127,18 +139,32 @@ export {
127
139
  subscribeAgentRunCancel,
128
140
  } from "./streams"
129
141
  export type {
142
+ AgentThreadModelContextMessage,
143
+ ProjectAgentThreadModelContextInput,
144
+ } from "./thread-context-projection"
145
+ export { projectAgentThreadModelContext } from "./thread-context-projection"
146
+ export { isAgentToolResult } from "./tool-result"
147
+ export type {
148
+ AgentContextConfig,
130
149
  AgentDefinition,
131
150
  AgentLoopConfig,
132
151
  AgentReasoningLevel,
152
+ AgentToolArtifact,
153
+ AgentToolArtifactPutInput,
154
+ AgentToolArtifacts,
155
+ AgentToolContent,
133
156
  AgentToolDefinition,
134
157
  AgentToolDescriptionBuilder,
158
+ AgentToolFileContent,
135
159
  AgentToolHandler,
136
160
  AgentToolHandlerResult,
137
161
  AgentToolInputBuilder,
138
162
  AgentToolInputSchema,
163
+ AgentToolResult,
139
164
  AgentToolRunBuilder,
140
165
  AgentToolRunContext,
141
166
  AgentToolRunInfo,
167
+ AgentToolTextContent,
142
168
  DefineAgentConfig,
143
169
  InferAgentToolInput,
144
170
  InferAgentToolInputSchema,
@@ -205,6 +205,11 @@ export async function retryAgentRun(
205
205
  if (!agents) {
206
206
  throw new AgentRequestError("storage_unavailable", "[Sixb] Agent storage is not configured.")
207
207
  }
208
+ await agents.messages.deleteByRunId({
209
+ projectId: runtime.projectId,
210
+ threadId: failedRun.threadId,
211
+ runId: failedRun.id,
212
+ })
208
213
  await tx.executions.create(durableExecution)
209
214
  return agents.runs.create({
210
215
  id: runId,