@sixb/core 0.1.17 → 0.1.18

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 (454) hide show
  1. package/dist/actions/index.js +22 -19
  2. package/dist/actions/index.js.map +1 -1
  3. package/dist/actions/read-facade.d.ts +1 -1
  4. package/dist/actions/validation.d.ts.map +1 -1
  5. package/dist/actions/worker.js +6 -2
  6. package/dist/actions/worker.js.map +3 -3
  7. package/dist/agents/adapters.d.ts +7 -0
  8. package/dist/agents/adapters.d.ts.map +1 -1
  9. package/dist/agents/authority.d.ts +7 -0
  10. package/dist/agents/authority.d.ts.map +1 -1
  11. package/dist/agents/context/entries.d.ts +10 -1
  12. package/dist/agents/context/entries.d.ts.map +1 -1
  13. package/dist/agents/context/index.d.ts +1 -1
  14. package/dist/agents/context/index.d.ts.map +1 -1
  15. package/dist/agents/context/index.js +4 -2
  16. package/dist/agents/context/index.js.map +1 -1
  17. package/dist/agents/context-compaction.d.ts.map +1 -1
  18. package/dist/agents/errors.d.ts +1 -1
  19. package/dist/agents/errors.d.ts.map +1 -1
  20. package/dist/agents/index.d.ts +6 -4
  21. package/dist/agents/index.d.ts.map +1 -1
  22. package/dist/agents/index.js +44 -37
  23. package/dist/agents/index.js.map +1 -1
  24. package/dist/agents/message.d.ts +8 -1
  25. package/dist/agents/message.d.ts.map +1 -1
  26. package/dist/agents/request.d.ts +19 -5
  27. package/dist/agents/request.d.ts.map +1 -1
  28. package/dist/agents/skills.d.ts +41 -0
  29. package/dist/agents/skills.d.ts.map +1 -0
  30. package/dist/agents/streams/index.js +1 -1
  31. package/dist/agents/streams/internal.js +1 -1
  32. package/dist/agents/types.d.ts +33 -4
  33. package/dist/agents/types.d.ts.map +1 -1
  34. package/dist/auth/index.js +9 -6
  35. package/dist/auth/index.js.map +1 -1
  36. package/dist/auth/runtime.d.ts.map +1 -1
  37. package/dist/auth/types.d.ts +6 -0
  38. package/dist/auth/types.d.ts.map +1 -1
  39. package/dist/authorization/index.js +5 -3
  40. package/dist/authorization/index.js.map +1 -1
  41. package/dist/authorization/resolve.d.ts +1 -1
  42. package/dist/authorization/resolve.d.ts.map +1 -1
  43. package/dist/authorization/types.d.ts +7 -0
  44. package/dist/authorization/types.d.ts.map +1 -1
  45. package/dist/blob-storage/browser.js +1 -1
  46. package/dist/blob-storage/execution.d.ts.map +1 -1
  47. package/dist/blob-storage/file-content.d.ts +18 -0
  48. package/dist/blob-storage/file-content.d.ts.map +1 -0
  49. package/dist/blob-storage/index.d.ts +1 -1
  50. package/dist/blob-storage/index.d.ts.map +1 -1
  51. package/dist/blob-storage/index.js +2 -2
  52. package/dist/blob-storage/internal.d.ts +2 -0
  53. package/dist/blob-storage/internal.d.ts.map +1 -1
  54. package/dist/blob-storage/internal.js +16 -4
  55. package/dist/blob-storage/internal.js.map +1 -1
  56. package/dist/blob-storage/media-type.d.ts +8 -0
  57. package/dist/blob-storage/media-type.d.ts.map +1 -0
  58. package/dist/blob-storage/types.d.ts +12 -1
  59. package/dist/blob-storage/types.d.ts.map +1 -1
  60. package/dist/blob-storage/validation.d.ts +6 -0
  61. package/dist/blob-storage/validation.d.ts.map +1 -1
  62. package/dist/bootstrap/agent-context.d.ts +33 -0
  63. package/dist/bootstrap/agent-context.d.ts.map +1 -0
  64. package/dist/bootstrap/discovery.d.ts +23 -3
  65. package/dist/bootstrap/discovery.d.ts.map +1 -1
  66. package/dist/bootstrap/index.d.ts +2 -1
  67. package/dist/bootstrap/index.d.ts.map +1 -1
  68. package/dist/bootstrap/index.js +284 -73
  69. package/dist/bootstrap/index.js.map +4 -3
  70. package/dist/bootstrap/ontology-type-manifest.d.ts.map +1 -1
  71. package/dist/{chunk-gf7yht60.js → chunk-1b1f2d5f.js} +23 -6
  72. package/dist/chunk-1b1f2d5f.js.map +12 -0
  73. package/dist/{chunk-9vx5e9g1.js → chunk-1sr8ryzk.js} +3 -3
  74. package/dist/chunk-1sr8ryzk.js.map +11 -0
  75. package/dist/{chunk-4gmng3vf.js → chunk-22v5bpz3.js} +1 -1
  76. package/dist/{chunk-s7ftxrdr.js → chunk-29yx306f.js} +20 -3
  77. package/dist/{chunk-s7ftxrdr.js.map → chunk-29yx306f.js.map} +3 -3
  78. package/dist/{chunk-4ra628t7.js → chunk-3zxk45er.js} +70 -6
  79. package/dist/{chunk-4ra628t7.js.map → chunk-3zxk45er.js.map} +5 -4
  80. package/dist/{chunk-2am3db31.js → chunk-48e3cn2d.js} +2 -2
  81. package/dist/{chunk-91kcnbf0.js → chunk-6gmfggss.js} +22 -9
  82. package/dist/chunk-6gmfggss.js.map +10 -0
  83. package/dist/{chunk-svabwqdq.js → chunk-6h5m9xjx.js} +43 -415
  84. package/dist/{chunk-svabwqdq.js.map → chunk-6h5m9xjx.js.map} +7 -11
  85. package/dist/{chunk-f1xh7a32.js → chunk-7hpdd6r9.js} +2 -2
  86. package/dist/{chunk-xyvy73tj.js → chunk-bs7sqkre.js} +8 -3
  87. package/dist/chunk-bs7sqkre.js.map +12 -0
  88. package/dist/{chunk-rb143ggb.js → chunk-bwjcehza.js} +1 -1
  89. package/dist/{chunk-t9shqx3w.js → chunk-d0eb5yy6.js} +143 -7
  90. package/dist/chunk-d0eb5yy6.js.map +14 -0
  91. package/dist/{chunk-vp3z1ckh.js → chunk-de4z2bj6.js} +5 -5
  92. package/dist/{chunk-3rrezgyc.js → chunk-dnmadg9k.js} +2 -2
  93. package/dist/chunk-enpsx8k5.js +127 -0
  94. package/dist/chunk-enpsx8k5.js.map +10 -0
  95. package/dist/{chunk-a7er86jd.js → chunk-ex496vct.js} +1 -1
  96. package/dist/{chunk-jnfxmr3f.js → chunk-f1zxad2t.js} +1 -1
  97. package/dist/{chunk-6wbm6ymz.js → chunk-fe52eczz.js} +271 -83
  98. package/dist/chunk-fe52eczz.js.map +49 -0
  99. package/dist/{chunk-10styjgk.js → chunk-fx93hd2n.js} +71 -29
  100. package/dist/chunk-fx93hd2n.js.map +20 -0
  101. package/dist/{chunk-9se093qz.js → chunk-gc4ntf7d.js} +4 -4
  102. package/dist/{chunk-9se093qz.js.map → chunk-gc4ntf7d.js.map} +1 -1
  103. package/dist/{chunk-98cw09sw.js → chunk-hkc3jct7.js} +4 -2
  104. package/dist/chunk-hkc3jct7.js.map +10 -0
  105. package/dist/{chunk-pja9jfz6.js → chunk-htr6wjmv.js} +115 -53
  106. package/dist/chunk-htr6wjmv.js.map +19 -0
  107. package/dist/{chunk-h3v76ams.js → chunk-jhm3zsa7.js} +25 -2
  108. package/dist/chunk-jhm3zsa7.js.map +12 -0
  109. package/dist/{chunk-52c5zb0z.js → chunk-k6hrnf35.js} +5 -5
  110. package/dist/chunk-k6hrnf35.js.map +10 -0
  111. package/dist/{chunk-c2rga5cx.js → chunk-mfs23znk.js} +1 -1
  112. package/dist/{chunk-7ecp4v7a.js → chunk-ny3xyvcn.js} +8 -2
  113. package/dist/{chunk-7ecp4v7a.js.map → chunk-ny3xyvcn.js.map} +3 -3
  114. package/dist/{chunk-fggq3d9k.js → chunk-p0dqwj3n.js} +5 -5
  115. package/dist/{chunk-cnb5kv05.js → chunk-p844e0rn.js} +23 -8
  116. package/dist/chunk-p844e0rn.js.map +19 -0
  117. package/dist/{chunk-dmn70ztd.js → chunk-pfp1txq2.js} +25 -6
  118. package/dist/chunk-pfp1txq2.js.map +11 -0
  119. package/dist/chunk-pqajwytd.js.map +2 -2
  120. package/dist/{chunk-5be2ath4.js → chunk-qkbx3tf6.js} +17 -128
  121. package/dist/{chunk-5be2ath4.js.map → chunk-qkbx3tf6.js.map} +6 -7
  122. package/dist/{chunk-sk0hcjsz.js → chunk-qkvz64nd.js} +2 -2
  123. package/dist/{chunk-w9yycd3t.js → chunk-qmnnhde6.js} +4 -8
  124. package/dist/{chunk-w9yycd3t.js.map → chunk-qmnnhde6.js.map} +3 -3
  125. package/dist/{chunk-5yd8cchh.js → chunk-qq90g05n.js} +8 -8
  126. package/dist/{chunk-5yd8cchh.js.map → chunk-qq90g05n.js.map} +1 -1
  127. package/dist/{chunk-tjjgy3z4.js → chunk-qxvp5epv.js} +66 -14
  128. package/dist/{chunk-tjjgy3z4.js.map → chunk-qxvp5epv.js.map} +9 -8
  129. package/dist/chunk-rdghfsss.js.map +2 -2
  130. package/dist/{chunk-rx7h5fdx.js → chunk-rt9p8m9t.js} +1 -1
  131. package/dist/{chunk-cd234ba4.js → chunk-rz53yb4v.js} +10 -5
  132. package/dist/chunk-rz53yb4v.js.map +14 -0
  133. package/dist/{chunk-xcy5ddha.js → chunk-s4jhg8a3.js} +351 -296
  134. package/dist/chunk-s4jhg8a3.js.map +15 -0
  135. package/dist/{chunk-69266efg.js → chunk-s54c868q.js} +12 -4
  136. package/dist/chunk-s54c868q.js.map +12 -0
  137. package/dist/{chunk-9g6jz9kk.js → chunk-tffvfy6s.js} +6 -5
  138. package/dist/{chunk-9g6jz9kk.js.map → chunk-tffvfy6s.js.map} +3 -3
  139. package/dist/{chunk-e67ynxcr.js → chunk-v6xpd60t.js} +3 -3
  140. package/dist/{chunk-jjrn5v0p.js → chunk-vgk3hknm.js} +1 -1
  141. package/dist/{chunk-5thzcb8g.js → chunk-vx2yp45y.js} +2 -2
  142. package/dist/{chunk-dam456ve.js → chunk-vz3gc1tm.js} +394 -31
  143. package/dist/{chunk-dam456ve.js.map → chunk-vz3gc1tm.js.map} +10 -7
  144. package/dist/chunk-xt1zt7gv.js +471 -0
  145. package/dist/chunk-xt1zt7gv.js.map +13 -0
  146. package/dist/{chunk-rpxz486p.js → chunk-y05543x6.js} +21 -5
  147. package/dist/{chunk-rpxz486p.js.map → chunk-y05543x6.js.map} +3 -3
  148. package/dist/{chunk-aq39q04r.js → chunk-y9jmd7e5.js} +4 -4
  149. package/dist/{chunk-aq39q04r.js.map → chunk-y9jmd7e5.js.map} +1 -1
  150. package/dist/{chunk-k4g51s47.js → chunk-yv9czyfr.js} +3 -3
  151. package/dist/{chunk-z5rnrmz1.js → chunk-yw9pyg66.js} +5 -3
  152. package/dist/chunk-yw9pyg66.js.map +11 -0
  153. package/dist/{chunk-vre348sb.js → chunk-za5yd58j.js} +2 -2
  154. package/dist/{chunk-23xs4qp9.js → chunk-zb77kjth.js} +3 -3
  155. package/dist/{chunk-33saed7g.js → chunk-zxawp1n2.js} +1 -1
  156. package/dist/datasets/builders.d.ts +12 -1
  157. package/dist/datasets/builders.d.ts.map +1 -1
  158. package/dist/datasets/execution.d.ts +27 -1
  159. package/dist/datasets/execution.d.ts.map +1 -1
  160. package/dist/datasets/index.d.ts +1 -1
  161. package/dist/datasets/index.d.ts.map +1 -1
  162. package/dist/datasets/types.d.ts +2 -0
  163. package/dist/datasets/types.d.ts.map +1 -1
  164. package/dist/datasets/write.d.ts +5 -0
  165. package/dist/datasets/write.d.ts.map +1 -1
  166. package/dist/datasets/write.js +10 -5
  167. package/dist/datasets/write.js.map +1 -1
  168. package/dist/edits/properties.d.ts.map +1 -1
  169. package/dist/events/execution.d.ts +2 -1
  170. package/dist/events/execution.d.ts.map +1 -1
  171. package/dist/events/types/objects.d.ts +5 -0
  172. package/dist/events/types/objects.d.ts.map +1 -1
  173. package/dist/execution/agent.d.ts +10 -0
  174. package/dist/execution/agent.d.ts.map +1 -1
  175. package/dist/execution/agent.js +39 -34
  176. package/dist/execution/agent.js.map +1 -1
  177. package/dist/execution/authorized-object-reader.d.ts +6 -1
  178. package/dist/execution/authorized-object-reader.d.ts.map +1 -1
  179. package/dist/execution/primitive.js +37 -34
  180. package/dist/execution/primitive.js.map +2 -2
  181. package/dist/execution/request.js +38 -35
  182. package/dist/execution/request.js.map +2 -2
  183. package/dist/http/api-routes.d.ts.map +1 -1
  184. package/dist/http/index.js +1 -1
  185. package/dist/index.d.ts +9 -8
  186. package/dist/index.d.ts.map +1 -1
  187. package/dist/index.js +57 -52
  188. package/dist/index.js.map +1 -1
  189. package/dist/lake-storage/index.js +8 -5
  190. package/dist/lake-storage/index.js.map +1 -1
  191. package/dist/materializer/index.js +19 -16
  192. package/dist/materializer/index.js.map +1 -1
  193. package/dist/models/catalog.d.ts +1 -1
  194. package/dist/models/catalog.d.ts.map +1 -1
  195. package/dist/models/execution/binding.d.ts +6 -0
  196. package/dist/models/execution/binding.d.ts.map +1 -1
  197. package/dist/models/execution/index.js +19 -16
  198. package/dist/models/execution/index.js.map +1 -1
  199. package/dist/models/execution/model-call-recorder.d.ts +4 -0
  200. package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
  201. package/dist/models/execution.d.ts.map +1 -1
  202. package/dist/models/index.js +1 -1
  203. package/dist/models/language-model.d.ts +6 -0
  204. package/dist/models/language-model.d.ts.map +1 -1
  205. package/dist/objects/context/index.d.ts +1 -1
  206. package/dist/objects/context/index.d.ts.map +1 -1
  207. package/dist/objects/context/types.d.ts +6 -0
  208. package/dist/objects/context/types.d.ts.map +1 -1
  209. package/dist/objects/execution.d.ts +2 -1
  210. package/dist/objects/execution.d.ts.map +1 -1
  211. package/dist/objects/index.js +23 -19
  212. package/dist/objects/index.js.map +1 -1
  213. package/dist/objects/materializer-adapter.d.ts.map +1 -1
  214. package/dist/objects/object/upsert-batch.d.ts.map +1 -1
  215. package/dist/objects/object/upsert.d.ts.map +1 -1
  216. package/dist/objects/property-clearance.d.ts +41 -0
  217. package/dist/objects/property-clearance.d.ts.map +1 -0
  218. package/dist/objects/query/executor.d.ts +3 -0
  219. package/dist/objects/query/executor.d.ts.map +1 -1
  220. package/dist/objects/query/index.js +18 -15
  221. package/dist/objects/query/index.js.map +1 -1
  222. package/dist/objects/query/validate.d.ts +10 -1
  223. package/dist/objects/query/validate.d.ts.map +1 -1
  224. package/dist/objects/sdk/file-handle.d.ts +6 -0
  225. package/dist/objects/sdk/file-handle.d.ts.map +1 -0
  226. package/dist/objects/sdk/object-handle.d.ts +2 -2
  227. package/dist/objects/sdk/object-handle.d.ts.map +1 -1
  228. package/dist/objects/sdk/object-set.d.ts +2 -0
  229. package/dist/objects/sdk/object-set.d.ts.map +1 -1
  230. package/dist/ontology/builders.d.ts +12 -1
  231. package/dist/ontology/builders.d.ts.map +1 -1
  232. package/dist/ontology/docs-markdown.d.ts +35 -0
  233. package/dist/ontology/docs-markdown.d.ts.map +1 -0
  234. package/dist/ontology/docs.d.ts +50 -0
  235. package/dist/ontology/docs.d.ts.map +1 -0
  236. package/dist/ontology/index.js +7 -4
  237. package/dist/ontology/index.js.map +1 -1
  238. package/dist/ontology/inference/index.d.ts +19 -0
  239. package/dist/ontology/inference/index.d.ts.map +1 -1
  240. package/dist/ontology/internal.d.ts +3 -1
  241. package/dist/ontology/internal.d.ts.map +1 -1
  242. package/dist/ontology/internal.js +276 -3
  243. package/dist/ontology/internal.js.map +4 -3
  244. package/dist/ontology/tokens.d.ts +8 -1
  245. package/dist/ontology/tokens.d.ts.map +1 -1
  246. package/dist/ontology/types.d.ts +5 -0
  247. package/dist/ontology/types.d.ts.map +1 -1
  248. package/dist/ontology/validation/index.d.ts +1 -1
  249. package/dist/ontology/validation/index.d.ts.map +1 -1
  250. package/dist/ontology/validation/schema.d.ts +7 -0
  251. package/dist/ontology/validation/schema.d.ts.map +1 -1
  252. package/dist/pipelines/index.js +21 -18
  253. package/dist/pipelines/index.js.map +1 -1
  254. package/dist/projections/internal.js +19 -16
  255. package/dist/projections/internal.js.map +1 -1
  256. package/dist/runtime/create.d.ts +11 -2
  257. package/dist/runtime/create.d.ts.map +1 -1
  258. package/dist/runtime/definitions.d.ts +3 -1
  259. package/dist/runtime/definitions.d.ts.map +1 -1
  260. package/dist/runtime/host.d.ts +13 -2
  261. package/dist/runtime/host.d.ts.map +1 -1
  262. package/dist/runtime/index.d.ts +1 -1
  263. package/dist/runtime/index.d.ts.map +1 -1
  264. package/dist/runtime/internal.js +21 -18
  265. package/dist/runtime/internal.js.map +1 -1
  266. package/dist/runtime/locale.d.ts +9 -0
  267. package/dist/runtime/locale.d.ts.map +1 -0
  268. package/dist/runtime/resolve-definitions.d.ts +4 -2
  269. package/dist/runtime/resolve-definitions.d.ts.map +1 -1
  270. package/dist/runtime/types.d.ts +30 -3
  271. package/dist/runtime/types.d.ts.map +1 -1
  272. package/dist/sandboxes/index.js +7 -6
  273. package/dist/sandboxes/index.js.map +1 -1
  274. package/dist/scheduler/index.js +1 -1
  275. package/dist/scheduler/runtime.d.ts +3 -0
  276. package/dist/scheduler/runtime.d.ts.map +1 -1
  277. package/dist/security/builders.d.ts +11 -2
  278. package/dist/security/builders.d.ts.map +1 -1
  279. package/dist/security/index.d.ts +4 -4
  280. package/dist/security/index.d.ts.map +1 -1
  281. package/dist/security/markings.d.ts +19 -0
  282. package/dist/security/markings.d.ts.map +1 -0
  283. package/dist/security/redactions.d.ts +4 -0
  284. package/dist/security/redactions.d.ts.map +1 -0
  285. package/dist/security/registry.d.ts +7 -1
  286. package/dist/security/registry.d.ts.map +1 -1
  287. package/dist/security/types.d.ts +25 -0
  288. package/dist/security/types.d.ts.map +1 -1
  289. package/dist/security/validation.d.ts +4 -1
  290. package/dist/security/validation.d.ts.map +1 -1
  291. package/dist/shares/internal.js +18 -15
  292. package/dist/shares/internal.js.map +2 -2
  293. package/dist/storage/agents/provider.d.ts.map +1 -1
  294. package/dist/storage/agents/provider.js +5 -4
  295. package/dist/storage/agents/provider.js.map +1 -1
  296. package/dist/storage/agents/types.d.ts +15 -9
  297. package/dist/storage/agents/types.d.ts.map +1 -1
  298. package/dist/storage/file-upload-sessions/provider.js +10 -7
  299. package/dist/storage/file-upload-sessions/provider.js.map +1 -1
  300. package/dist/storage/index.d.ts +1 -0
  301. package/dist/storage/index.d.ts.map +1 -1
  302. package/dist/storage/index.js +18 -15
  303. package/dist/storage/index.js.map +1 -1
  304. package/dist/storage/internal.js +4 -3
  305. package/dist/storage/internal.js.map +1 -1
  306. package/dist/storage/objects/types.d.ts +7 -0
  307. package/dist/storage/objects/types.d.ts.map +1 -1
  308. package/dist/storage/workflow-runs/provider.js +10 -7
  309. package/dist/storage/workflow-runs/provider.js.map +1 -1
  310. package/dist/syncs/index.js +22 -19
  311. package/dist/syncs/index.js.map +1 -1
  312. package/dist/testing/index.js +55 -53
  313. package/dist/testing/index.js.map +2 -2
  314. package/dist/webhooks/internal.js +19 -16
  315. package/dist/webhooks/internal.js.map +2 -2
  316. package/dist/workflows/builders.d.ts.map +1 -1
  317. package/dist/workflows/index.js +41 -38
  318. package/dist/workflows/index.js.map +1 -1
  319. package/dist/workflows/request.d.ts.map +1 -1
  320. package/dist/workflows/types.d.ts +6 -3
  321. package/dist/workflows/types.d.ts.map +1 -1
  322. package/dist/workflows/validation.d.ts +2 -1
  323. package/dist/workflows/validation.d.ts.map +1 -1
  324. package/package.json +1 -1
  325. package/src/actions/read-facade.ts +2 -1
  326. package/src/actions/validation.ts +4 -1
  327. package/src/agents/adapters.ts +15 -0
  328. package/src/agents/authority.ts +15 -0
  329. package/src/agents/context/entries.ts +48 -4
  330. package/src/agents/context/index.ts +1 -0
  331. package/src/agents/context-compaction.ts +6 -0
  332. package/src/agents/errors.ts +3 -0
  333. package/src/agents/index.ts +13 -1
  334. package/src/agents/message.ts +9 -0
  335. package/src/agents/request.ts +178 -22
  336. package/src/agents/skills.ts +63 -0
  337. package/src/agents/types.ts +35 -5
  338. package/src/auth/runtime.ts +14 -0
  339. package/src/auth/types.ts +6 -0
  340. package/src/authorization/resolve.ts +6 -1
  341. package/src/authorization/types.ts +7 -0
  342. package/src/blob-storage/execution.ts +12 -0
  343. package/src/blob-storage/file-content.ts +106 -0
  344. package/src/blob-storage/index.ts +1 -0
  345. package/src/blob-storage/internal.ts +7 -0
  346. package/src/blob-storage/media-type.ts +29 -0
  347. package/src/blob-storage/types.ts +13 -1
  348. package/src/blob-storage/validation.ts +13 -0
  349. package/src/bootstrap/agent-context.ts +356 -0
  350. package/src/bootstrap/discovery.ts +100 -33
  351. package/src/bootstrap/index.ts +1 -1
  352. package/src/bootstrap/ontology-type-manifest.ts +3 -38
  353. package/src/datasets/builders.ts +17 -1
  354. package/src/datasets/execution.ts +110 -2
  355. package/src/datasets/index.ts +7 -1
  356. package/src/datasets/types.ts +2 -0
  357. package/src/datasets/write.ts +21 -2
  358. package/src/edits/properties.ts +3 -0
  359. package/src/events/execution.ts +15 -16
  360. package/src/events/types/objects.ts +5 -0
  361. package/src/execution/agent.ts +27 -0
  362. package/src/execution/authorization.ts +1 -0
  363. package/src/execution/authorized-object-reader.ts +96 -34
  364. package/src/execution/scopes.ts +2 -6
  365. package/src/http/api-routes.ts +4 -3
  366. package/src/index.ts +27 -2
  367. package/src/models/catalog.ts +26 -2
  368. package/src/models/execution/README.md +4 -3
  369. package/src/models/execution/binding.ts +6 -0
  370. package/src/models/execution/model-call-recorder.ts +10 -0
  371. package/src/models/execution/session.ts +2 -2
  372. package/src/models/execution.ts +6 -2
  373. package/src/models/language-model.ts +6 -0
  374. package/src/objects/context/index.ts +1 -0
  375. package/src/objects/context/types.ts +7 -0
  376. package/src/objects/execution.ts +4 -1
  377. package/src/objects/materializer-adapter.ts +3 -0
  378. package/src/objects/object/upsert-batch.ts +4 -1
  379. package/src/objects/object/upsert.ts +3 -1
  380. package/src/objects/property-clearance.ts +209 -0
  381. package/src/objects/query/executor.ts +43 -36
  382. package/src/objects/query/validate.ts +133 -14
  383. package/src/objects/sdk/file-handle.ts +77 -0
  384. package/src/objects/sdk/object-handle.ts +8 -4
  385. package/src/objects/sdk/object-set.ts +5 -2
  386. package/src/ontology/builders.ts +18 -2
  387. package/src/ontology/docs-markdown.ts +394 -0
  388. package/src/ontology/docs.ts +196 -0
  389. package/src/ontology/inference/index.ts +25 -0
  390. package/src/ontology/internal.ts +7 -0
  391. package/src/ontology/tokens.ts +13 -2
  392. package/src/ontology/types.ts +5 -0
  393. package/src/ontology/validation/index.ts +1 -0
  394. package/src/ontology/validation/schema.ts +26 -1
  395. package/src/runtime/create.ts +34 -4
  396. package/src/runtime/definitions.ts +3 -1
  397. package/src/runtime/host.ts +45 -1
  398. package/src/runtime/index.ts +3 -0
  399. package/src/runtime/locale.ts +26 -0
  400. package/src/runtime/resolve-definitions.ts +28 -1
  401. package/src/runtime/sixb.ts +1 -1
  402. package/src/runtime/types.ts +39 -3
  403. package/src/scheduler/runtime.ts +11 -2
  404. package/src/security/builders.ts +49 -5
  405. package/src/security/index.ts +6 -1
  406. package/src/security/markings.ts +313 -0
  407. package/src/security/redactions.ts +6 -0
  408. package/src/security/registry.ts +21 -1
  409. package/src/security/types.ts +26 -0
  410. package/src/security/validation.ts +59 -2
  411. package/src/storage/agents/provider.ts +11 -0
  412. package/src/storage/agents/types.ts +15 -7
  413. package/src/storage/index.ts +1 -0
  414. package/src/storage/objects/types.ts +7 -0
  415. package/src/workflows/builders.ts +24 -1
  416. package/src/workflows/request.ts +3 -0
  417. package/src/workflows/types.ts +6 -3
  418. package/src/workflows/validation.ts +32 -4
  419. package/dist/chunk-10styjgk.js.map +0 -20
  420. package/dist/chunk-52c5zb0z.js.map +0 -10
  421. package/dist/chunk-69266efg.js.map +0 -12
  422. package/dist/chunk-6wbm6ymz.js.map +0 -48
  423. package/dist/chunk-91kcnbf0.js.map +0 -10
  424. package/dist/chunk-98cw09sw.js.map +0 -10
  425. package/dist/chunk-9vx5e9g1.js.map +0 -11
  426. package/dist/chunk-cd234ba4.js.map +0 -14
  427. package/dist/chunk-cnb5kv05.js.map +0 -19
  428. package/dist/chunk-dmn70ztd.js.map +0 -11
  429. package/dist/chunk-gf7yht60.js.map +0 -12
  430. package/dist/chunk-h3v76ams.js.map +0 -11
  431. package/dist/chunk-pja9jfz6.js.map +0 -19
  432. package/dist/chunk-t9shqx3w.js.map +0 -12
  433. package/dist/chunk-xcy5ddha.js.map +0 -15
  434. package/dist/chunk-xyvy73tj.js.map +0 -12
  435. package/dist/chunk-z5rnrmz1.js.map +0 -11
  436. /package/dist/{chunk-4gmng3vf.js.map → chunk-22v5bpz3.js.map} +0 -0
  437. /package/dist/{chunk-2am3db31.js.map → chunk-48e3cn2d.js.map} +0 -0
  438. /package/dist/{chunk-f1xh7a32.js.map → chunk-7hpdd6r9.js.map} +0 -0
  439. /package/dist/{chunk-rb143ggb.js.map → chunk-bwjcehza.js.map} +0 -0
  440. /package/dist/{chunk-vp3z1ckh.js.map → chunk-de4z2bj6.js.map} +0 -0
  441. /package/dist/{chunk-3rrezgyc.js.map → chunk-dnmadg9k.js.map} +0 -0
  442. /package/dist/{chunk-a7er86jd.js.map → chunk-ex496vct.js.map} +0 -0
  443. /package/dist/{chunk-jnfxmr3f.js.map → chunk-f1zxad2t.js.map} +0 -0
  444. /package/dist/{chunk-c2rga5cx.js.map → chunk-mfs23znk.js.map} +0 -0
  445. /package/dist/{chunk-fggq3d9k.js.map → chunk-p0dqwj3n.js.map} +0 -0
  446. /package/dist/{chunk-sk0hcjsz.js.map → chunk-qkvz64nd.js.map} +0 -0
  447. /package/dist/{chunk-rx7h5fdx.js.map → chunk-rt9p8m9t.js.map} +0 -0
  448. /package/dist/{chunk-e67ynxcr.js.map → chunk-v6xpd60t.js.map} +0 -0
  449. /package/dist/{chunk-jjrn5v0p.js.map → chunk-vgk3hknm.js.map} +0 -0
  450. /package/dist/{chunk-5thzcb8g.js.map → chunk-vx2yp45y.js.map} +0 -0
  451. /package/dist/{chunk-k4g51s47.js.map → chunk-yv9czyfr.js.map} +0 -0
  452. /package/dist/{chunk-vre348sb.js.map → chunk-za5yd58j.js.map} +0 -0
  453. /package/dist/{chunk-23xs4qp9.js.map → chunk-zb77kjth.js.map} +0 -0
  454. /package/dist/{chunk-33saed7g.js.map → chunk-zxawp1n2.js.map} +0 -0
@@ -5,10 +5,10 @@ import {
5
5
  } from "./chunk-e1c18xjx.js";
6
6
  import {
7
7
  isDatasetDefinition2
8
- } from "./chunk-cd234ba4.js";
8
+ } from "./chunk-rz53yb4v.js";
9
9
  import {
10
10
  PipelineError2
11
- } from "./chunk-e67ynxcr.js";
11
+ } from "./chunk-v6xpd60t.js";
12
12
 
13
13
  // src/lake-storage/sql-transforms.ts
14
14
  var SQL_DIALECT = {
@@ -3,7 +3,7 @@ import {
3
3
  createPrincipalRuntimeAuthorization,
4
4
  createDisabledRuntimeAuthorization,
5
5
  createDelegatedRuntimeAuthorization
6
- } from "./chunk-5be2ath4.js";
6
+ } from "./chunk-qkbx3tf6.js";
7
7
 
8
8
  // src/execution/scopes.ts
9
9
  import { randomUUID } from "crypto";
@@ -60,12 +60,8 @@ function createTestingScope(input) {
60
60
  });
61
61
  }
62
62
  function withoutSession(context) {
63
- return {
64
- principal: context.principal,
65
- groupIds: context.groupIds,
66
- roleIds: context.roleIds,
67
- grants: context.grants
68
- };
63
+ const { sessionId: _sessionId, ...withoutSessionId } = context;
64
+ return withoutSessionId;
69
65
  }
70
66
  function createRequestExecution(input) {
71
67
  assertNonEmpty(input.projectId, "Execution project id");
@@ -103,4 +99,4 @@ function assertNonEmpty(value, label) {
103
99
 
104
100
  export { createPrincipalRequestScope, createDisabledRequestScope, createDelegatedRequestScope, createTestingScope };
105
101
 
106
- //# debugId=D67EDA8B3AA3264264756E2164756E21
102
+ //# debugId=1E19649F1CE57F6964756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/execution/scopes.ts"],
4
4
  "sourcesContent": [
5
- "import { randomUUID } from \"node:crypto\"\nimport type { AuthorizationContext } from \"../authorization\"\nimport type { ObjectReadExecutionLimits, SelectedObjectReadScope } from \"../storage\"\nimport {\n createDelegatedRuntimeAuthorization,\n createDisabledRuntimeAuthorization,\n createKernelRuntimeAuthorization,\n createPrincipalRuntimeAuthorization,\n type DelegatedActionApplyTarget,\n} from \"./authorization\"\nimport type {\n AuthorizablePrincipal,\n AuthorizationRef,\n ExecutionContext,\n ExecutionScope,\n ExecutionSource,\n KernelOperation,\n} from \"./types\"\n\nexport function createPrincipalRequestScope(input: {\n readonly projectId: string\n readonly requestId: string\n readonly correlationId: string\n readonly context: AuthorizationContext\n readonly credential?: Extract<AuthorizationRef, { readonly type: \"principal\" }>[\"credential\"]\n}): ExecutionScope {\n const execution = createRequestExecution({\n projectId: input.projectId,\n requestId: input.requestId,\n correlationId: input.correlationId,\n requestedBy: asAuthorizablePrincipal(input.context.principal),\n })\n\n return Object.freeze({\n execution,\n authorization: createPrincipalRuntimeAuthorization({\n execution,\n context: input.context,\n ...(input.credential === undefined ? {} : { credential: input.credential }),\n }),\n })\n}\n\nexport function createDisabledRequestScope(input: {\n readonly projectId: string\n readonly requestId: string\n readonly correlationId: string\n}): ExecutionScope {\n const execution = createRequestExecution(input)\n return Object.freeze({\n execution,\n authorization: createDisabledRuntimeAuthorization(execution),\n })\n}\n\n/** Internal request scope carrying only a finite object-read selection. */\nexport function createDelegatedRequestScope(input: {\n readonly projectId: string\n readonly requestId: string\n readonly correlationId: string\n readonly objectRead: {\n readonly selection: SelectedObjectReadScope\n readonly limits: ObjectReadExecutionLimits\n }\n readonly actionApply?: readonly DelegatedActionApplyTarget[]\n readonly delegation?: Extract<AuthorizationRef, { readonly type: \"delegated\" }>[\"delegation\"]\n}): ExecutionScope {\n const execution = createRequestExecution(input)\n const actionApply = input.actionApply\n const delegation = input.delegation\n return Object.freeze({\n execution,\n authorization: createDelegatedRuntimeAuthorization({\n execution,\n objectRead: input.objectRead,\n ...(actionApply === undefined ? {} : { actionApply }),\n ...(delegation === undefined ? {} : { delegation }),\n }),\n })\n}\n\nexport function createKernelScope(input: {\n readonly projectId: string\n readonly operation: KernelOperation\n readonly source: ExecutionSource\n readonly correlationId?: string\n}): ExecutionScope {\n const operation = Object.freeze({ ...input.operation })\n const execution = createKernelExecution({\n projectId: input.projectId,\n operation,\n source: input.source,\n correlationId: input.correlationId,\n })\n return Object.freeze({\n execution,\n authorization: createKernelRuntimeAuthorization({ execution, operation }),\n })\n}\n\nfunction createKernelExecution(input: {\n readonly projectId: string\n readonly operation: KernelOperation\n readonly source: ExecutionSource\n readonly correlationId?: string\n}): ExecutionContext {\n const source = snapshotExecutionSource(input.source)\n assertNestedProvenance(source, input.correlationId)\n return freezeExecution({\n id: `exec_${randomUUID()}`,\n projectId: input.projectId,\n executor: Object.freeze({ type: \"kernel\", operation: input.operation }),\n source,\n correlationId: input.correlationId ?? `corr_${randomUUID()}`,\n })\n}\n\nfunction assertNestedProvenance(source: ExecutionSource, correlationId: string | undefined): void {\n if (source.type === \"execution\" && correlationId === undefined) {\n throw new Error(\"[Sixb] Nested execution must preserve its parent correlation id.\")\n }\n}\n\nexport function createTestingScope(input: {\n readonly projectId: string\n readonly context?: AuthorizationContext\n readonly executionId?: string\n readonly requestId?: string\n readonly correlationId?: string\n}): ExecutionScope {\n const context = input.context ? withoutSession(input.context) : undefined\n const requestId = input.requestId ?? `test_request_${randomUUID()}`\n const execution = createRequestExecution({\n projectId: input.projectId,\n requestId,\n correlationId: input.correlationId ?? `test_correlation_${randomUUID()}`,\n ...(context === undefined ? {} : { requestedBy: asAuthorizablePrincipal(context.principal) }),\n executionId: input.executionId,\n })\n return Object.freeze({\n execution,\n authorization: context\n ? createPrincipalRuntimeAuthorization({ execution, context })\n : createDisabledRuntimeAuthorization(execution),\n })\n}\n\nfunction withoutSession(context: AuthorizationContext): AuthorizationContext {\n return {\n principal: context.principal,\n groupIds: context.groupIds,\n roleIds: context.roleIds,\n grants: context.grants,\n }\n}\n\nfunction createRequestExecution(input: {\n readonly projectId: string\n readonly requestId: string\n readonly correlationId: string\n readonly requestedBy?: AuthorizablePrincipal\n readonly executionId?: string\n}): ExecutionContext {\n assertNonEmpty(input.projectId, \"Execution project id\")\n assertNonEmpty(input.requestId, \"Execution request id\")\n assertNonEmpty(input.correlationId, \"Execution correlation id\")\n const id = input.executionId ?? `exec_${randomUUID()}`\n assertNonEmpty(id, \"Execution id\")\n return freezeExecution({\n id,\n projectId: input.projectId,\n ...(input.requestedBy === undefined ? {} : { requestedBy: input.requestedBy }),\n executor: Object.freeze({ type: \"request\", requestId: input.requestId }),\n source: Object.freeze({ type: \"http\", requestId: input.requestId }),\n correlationId: input.correlationId,\n })\n}\n\nfunction freezeExecution(execution: ExecutionContext): ExecutionContext {\n assertNonEmpty(execution.id, \"Execution id\")\n assertNonEmpty(execution.projectId, \"Execution project id\")\n assertNonEmpty(execution.correlationId, \"Execution correlation id\")\n return Object.freeze(execution)\n}\n\nfunction snapshotExecutionSource(source: ExecutionSource): ExecutionSource {\n const field = sourceIdentifier(source)\n assertNonEmpty(field.value, field.label)\n if (source.type === \"datasetVersion\") {\n assertNonEmpty(source.datasetId, \"Execution source dataset id\")\n }\n return Object.freeze({ ...source })\n}\n\nfunction sourceIdentifier(source: ExecutionSource): {\n readonly label: string\n readonly value: string\n} {\n switch (source.type) {\n case \"ontologyCommit\":\n return { label: \"Execution source commit id\", value: source.commitId }\n case \"http\":\n return { label: \"Execution source request id\", value: source.requestId }\n case \"webhook\":\n return { label: \"Execution source delivery id\", value: source.deliveryId }\n case \"schedule\":\n case \"event\":\n return { label: \"Execution source event id\", value: source.eventId }\n case \"datasetVersion\":\n return { label: \"Execution source dataset version id\", value: source.versionId }\n case \"execution\":\n return { label: \"Execution source execution id\", value: source.executionId }\n }\n}\n\nfunction asAuthorizablePrincipal(\n principal: AuthorizationContext[\"principal\"]\n): AuthorizablePrincipal {\n if (principal.type !== \"user\" && principal.type !== \"serviceAccount\") {\n throw new Error(`[Sixb] Principal type '${principal.type}' cannot hold runtime authorization.`)\n }\n assertNonEmpty(principal.id, \"Execution principal id\")\n return Object.freeze({ type: principal.type, id: principal.id })\n}\n\nfunction assertNonEmpty(value: string, label: string): void {\n if (!value.trim()) {\n throw new Error(`[Sixb] ${label} must not be empty.`)\n }\n}\n"
5
+ "import { randomUUID } from \"node:crypto\"\nimport type { AuthorizationContext } from \"../authorization\"\nimport type { ObjectReadExecutionLimits, SelectedObjectReadScope } from \"../storage\"\nimport {\n createDelegatedRuntimeAuthorization,\n createDisabledRuntimeAuthorization,\n createKernelRuntimeAuthorization,\n createPrincipalRuntimeAuthorization,\n type DelegatedActionApplyTarget,\n} from \"./authorization\"\nimport type {\n AuthorizablePrincipal,\n AuthorizationRef,\n ExecutionContext,\n ExecutionScope,\n ExecutionSource,\n KernelOperation,\n} from \"./types\"\n\nexport function createPrincipalRequestScope(input: {\n readonly projectId: string\n readonly requestId: string\n readonly correlationId: string\n readonly context: AuthorizationContext\n readonly credential?: Extract<AuthorizationRef, { readonly type: \"principal\" }>[\"credential\"]\n}): ExecutionScope {\n const execution = createRequestExecution({\n projectId: input.projectId,\n requestId: input.requestId,\n correlationId: input.correlationId,\n requestedBy: asAuthorizablePrincipal(input.context.principal),\n })\n\n return Object.freeze({\n execution,\n authorization: createPrincipalRuntimeAuthorization({\n execution,\n context: input.context,\n ...(input.credential === undefined ? {} : { credential: input.credential }),\n }),\n })\n}\n\nexport function createDisabledRequestScope(input: {\n readonly projectId: string\n readonly requestId: string\n readonly correlationId: string\n}): ExecutionScope {\n const execution = createRequestExecution(input)\n return Object.freeze({\n execution,\n authorization: createDisabledRuntimeAuthorization(execution),\n })\n}\n\n/** Internal request scope carrying only a finite object-read selection. */\nexport function createDelegatedRequestScope(input: {\n readonly projectId: string\n readonly requestId: string\n readonly correlationId: string\n readonly objectRead: {\n readonly selection: SelectedObjectReadScope\n readonly limits: ObjectReadExecutionLimits\n }\n readonly actionApply?: readonly DelegatedActionApplyTarget[]\n readonly delegation?: Extract<AuthorizationRef, { readonly type: \"delegated\" }>[\"delegation\"]\n}): ExecutionScope {\n const execution = createRequestExecution(input)\n const actionApply = input.actionApply\n const delegation = input.delegation\n return Object.freeze({\n execution,\n authorization: createDelegatedRuntimeAuthorization({\n execution,\n objectRead: input.objectRead,\n ...(actionApply === undefined ? {} : { actionApply }),\n ...(delegation === undefined ? {} : { delegation }),\n }),\n })\n}\n\nexport function createKernelScope(input: {\n readonly projectId: string\n readonly operation: KernelOperation\n readonly source: ExecutionSource\n readonly correlationId?: string\n}): ExecutionScope {\n const operation = Object.freeze({ ...input.operation })\n const execution = createKernelExecution({\n projectId: input.projectId,\n operation,\n source: input.source,\n correlationId: input.correlationId,\n })\n return Object.freeze({\n execution,\n authorization: createKernelRuntimeAuthorization({ execution, operation }),\n })\n}\n\nfunction createKernelExecution(input: {\n readonly projectId: string\n readonly operation: KernelOperation\n readonly source: ExecutionSource\n readonly correlationId?: string\n}): ExecutionContext {\n const source = snapshotExecutionSource(input.source)\n assertNestedProvenance(source, input.correlationId)\n return freezeExecution({\n id: `exec_${randomUUID()}`,\n projectId: input.projectId,\n executor: Object.freeze({ type: \"kernel\", operation: input.operation }),\n source,\n correlationId: input.correlationId ?? `corr_${randomUUID()}`,\n })\n}\n\nfunction assertNestedProvenance(source: ExecutionSource, correlationId: string | undefined): void {\n if (source.type === \"execution\" && correlationId === undefined) {\n throw new Error(\"[Sixb] Nested execution must preserve its parent correlation id.\")\n }\n}\n\nexport function createTestingScope(input: {\n readonly projectId: string\n readonly context?: AuthorizationContext\n readonly executionId?: string\n readonly requestId?: string\n readonly correlationId?: string\n}): ExecutionScope {\n const context = input.context ? withoutSession(input.context) : undefined\n const requestId = input.requestId ?? `test_request_${randomUUID()}`\n const execution = createRequestExecution({\n projectId: input.projectId,\n requestId,\n correlationId: input.correlationId ?? `test_correlation_${randomUUID()}`,\n ...(context === undefined ? {} : { requestedBy: asAuthorizablePrincipal(context.principal) }),\n executionId: input.executionId,\n })\n return Object.freeze({\n execution,\n authorization: context\n ? createPrincipalRuntimeAuthorization({ execution, context })\n : createDisabledRuntimeAuthorization(execution),\n })\n}\n\nfunction withoutSession(context: AuthorizationContext): AuthorizationContext {\n const { sessionId: _sessionId, ...withoutSessionId } = context\n return withoutSessionId\n}\n\nfunction createRequestExecution(input: {\n readonly projectId: string\n readonly requestId: string\n readonly correlationId: string\n readonly requestedBy?: AuthorizablePrincipal\n readonly executionId?: string\n}): ExecutionContext {\n assertNonEmpty(input.projectId, \"Execution project id\")\n assertNonEmpty(input.requestId, \"Execution request id\")\n assertNonEmpty(input.correlationId, \"Execution correlation id\")\n const id = input.executionId ?? `exec_${randomUUID()}`\n assertNonEmpty(id, \"Execution id\")\n return freezeExecution({\n id,\n projectId: input.projectId,\n ...(input.requestedBy === undefined ? {} : { requestedBy: input.requestedBy }),\n executor: Object.freeze({ type: \"request\", requestId: input.requestId }),\n source: Object.freeze({ type: \"http\", requestId: input.requestId }),\n correlationId: input.correlationId,\n })\n}\n\nfunction freezeExecution(execution: ExecutionContext): ExecutionContext {\n assertNonEmpty(execution.id, \"Execution id\")\n assertNonEmpty(execution.projectId, \"Execution project id\")\n assertNonEmpty(execution.correlationId, \"Execution correlation id\")\n return Object.freeze(execution)\n}\n\nfunction snapshotExecutionSource(source: ExecutionSource): ExecutionSource {\n const field = sourceIdentifier(source)\n assertNonEmpty(field.value, field.label)\n if (source.type === \"datasetVersion\") {\n assertNonEmpty(source.datasetId, \"Execution source dataset id\")\n }\n return Object.freeze({ ...source })\n}\n\nfunction sourceIdentifier(source: ExecutionSource): {\n readonly label: string\n readonly value: string\n} {\n switch (source.type) {\n case \"ontologyCommit\":\n return { label: \"Execution source commit id\", value: source.commitId }\n case \"http\":\n return { label: \"Execution source request id\", value: source.requestId }\n case \"webhook\":\n return { label: \"Execution source delivery id\", value: source.deliveryId }\n case \"schedule\":\n case \"event\":\n return { label: \"Execution source event id\", value: source.eventId }\n case \"datasetVersion\":\n return { label: \"Execution source dataset version id\", value: source.versionId }\n case \"execution\":\n return { label: \"Execution source execution id\", value: source.executionId }\n }\n}\n\nfunction asAuthorizablePrincipal(\n principal: AuthorizationContext[\"principal\"]\n): AuthorizablePrincipal {\n if (principal.type !== \"user\" && principal.type !== \"serviceAccount\") {\n throw new Error(`[Sixb] Principal type '${principal.type}' cannot hold runtime authorization.`)\n }\n assertNonEmpty(principal.id, \"Execution principal id\")\n return Object.freeze({ type: principal.type, id: principal.id })\n}\n\nfunction assertNonEmpty(value: string, label: string): void {\n if (!value.trim()) {\n throw new Error(`[Sixb] ${label} must not be empty.`)\n }\n}\n"
6
6
  ],
7
- "mappings": "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",
8
- "debugId": "D67EDA8B3AA3264264756E2164756E21",
7
+ "mappings": "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",
8
+ "debugId": "1E19649F1CE57F6964756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -15,13 +15,13 @@ import {
15
15
  paginate,
16
16
  InMemoryAuthStorage2,
17
17
  principalsEqual2
18
- } from "./chunk-svabwqdq.js";
18
+ } from "./chunk-6h5m9xjx.js";
19
19
  import {
20
20
  ObjectReadLimitExceededError2,
21
21
  snapshotObjectReadExecutionLimits2,
22
22
  assertObjectReadFacetCount2,
23
23
  assertObjectReadOutputWithinLimit2
24
- } from "./chunk-5be2ath4.js";
24
+ } from "./chunk-qkbx3tf6.js";
25
25
  import {
26
26
  assertObjectReaderProject2
27
27
  } from "./chunk-v4jbb3rs.js";
@@ -29,7 +29,7 @@ import {
29
29
  queryScalarKindForSchema,
30
30
  resolvePropertyQueryCapabilities2,
31
31
  resolveQuerySchema
32
- } from "./chunk-rpxz486p.js";
32
+ } from "./chunk-y05543x6.js";
33
33
  import {
34
34
  AgentStorageError2,
35
35
  transitionAgentThreadSandbox2,
@@ -44,7 +44,7 @@ import {
44
44
  assertAgentContextCheckpointAnchors2,
45
45
  assertAgentContextCheckpointReplayState2,
46
46
  agentContextCheckpointMatchesCreateInput2
47
- } from "./chunk-69266efg.js";
47
+ } from "./chunk-s54c868q.js";
48
48
  import {
49
49
  InMemoryAiUsageStorage2,
50
50
  buildAiAccountingOverview,
@@ -86,7 +86,7 @@ import {
86
86
  } from "./chunk-h89wz928.js";
87
87
  import {
88
88
  DurableFileUploadSessions2
89
- } from "./chunk-33saed7g.js";
89
+ } from "./chunk-zxawp1n2.js";
90
90
  import {
91
91
  ExecutionStorageError2,
92
92
  prepareExecutionRecord2,
@@ -203,7 +203,7 @@ import {
203
203
  WorkflowRunError2,
204
204
  assertWorkflowRunExecution2,
205
205
  assertWorkflowAgentNodeRunExecution2
206
- } from "./chunk-t9shqx3w.js";
206
+ } from "./chunk-d0eb5yy6.js";
207
207
  import {
208
208
  ShareGrantStorageError2,
209
209
  normalizeShareGrantCreate2,
@@ -237,7 +237,7 @@ import {
237
237
  canRequeueSyncRunAfterEnqueueFailure2,
238
238
  createTransactionStorageProxy2,
239
239
  throwNestedStorageTransaction2
240
- } from "./chunk-aq39q04r.js";
240
+ } from "./chunk-y9jmd7e5.js";
241
241
  import {
242
242
  assertPinnedDatasetWatermark2
243
243
  } from "./chunk-6aawea28.js";
@@ -247,7 +247,7 @@ import {
247
247
  } from "./chunk-96yw3pwd.js";
248
248
  import {
249
249
  AGENT_RUN_FAILURE_CODES2
250
- } from "./chunk-98cw09sw.js";
250
+ } from "./chunk-hkc3jct7.js";
251
251
  import {
252
252
  compareDecimalValues2
253
253
  } from "./chunk-3bh94gbw.js";
@@ -3,7 +3,7 @@
3
3
  "sources": ["../src/storage/action-runs/in-memory.ts", "../src/agents/message.ts", "../src/storage/agents/in-memory.ts", "../src/storage/ai-cost/errors.ts", "../src/storage/ai-cost/in-memory.ts", "../src/storage/ai-limits/in-memory.ts", "../src/storage/connector-connections/in-memory.ts", "../src/storage/file-upload-sessions/in-memory.ts", "../src/storage/in-memory/index.ts", "../src/storage/executions/in-memory.ts", "../src/storage/file-download-grants/in-memory.ts", "../src/objects/vectors/query.ts", "../src/storage/objects/keys.ts", "../src/storage/objects/in-memory/keys.ts", "../src/objects/query/scalar-values.ts", "../src/objects/vectors/profile.ts", "../src/storage/objects/in-memory/query.ts", "../src/storage/objects/in-memory/read-scope.ts", "../src/storage/objects/in-memory/selected-reader.ts", "../src/storage/objects/in-memory/storage.ts", "../src/storage/ontology/in-memory/shared-state.ts", "../src/storage/ontology/in-memory/commits.ts", "../src/storage/timeseries/store.ts", "../src/storage/ontology/in-memory/materializations-state.ts", "../src/storage/ontology/in-memory/materializations-work.ts", "../src/storage/ontology/in-memory/materializations-finalization.ts", "../src/storage/ontology/in-memory/source-roots.ts", "../src/storage/ontology/in-memory/replacement-plans.ts", "../src/storage/ontology/in-memory/vectors.ts", "../src/storage/ontology/in-memory/materializations.ts", "../src/storage/ontology/in-memory/outbox.ts", "../src/storage/ontology/in-memory/sources.ts", "../src/storage/ontology/in-memory/state-reader.ts", "../src/storage/ontology/in-memory/testing.ts", "../src/storage/ontology/in-memory/vector-indexing.ts", "../src/storage/ontology/in-memory/index.ts", "../src/storage/run-listing.ts", "../src/storage/pipeline-runs/types.ts", "../src/storage/pipeline-runs/in-memory.ts", "../src/storage/projection-runs/in-memory.ts", "../src/storage/rules/in-memory.ts", "../src/storage/share-grants/in-memory.ts", "../src/storage/share-sessions/in-memory.ts", "../src/storage/sync-runs/types.ts", "../src/storage/sync-runs/in-memory.ts", "../src/storage/webhook-runs/types.ts", "../src/storage/webhook-runs/in-memory.ts", "../src/storage/workflow-interventions/errors.ts", "../src/storage/workflow-interventions/in-memory.ts", "../src/storage/workflow-runs/types.ts", "../src/storage/workflow-runs/in-memory.ts", "../src/storage/in-memory/testing.ts", "../src/storage/objects/query-preparation.ts", "../src/storage/migrations/migrate-storage.ts", "../src/storage/migrations/check-schema.ts", "../src/storage/migrations/migration-set.ts", "../src/storage/ontology/vector-indexing.ts"],
4
4
  "sourcesContent": [
5
5
  "import type { ExecutionStorage } from \"../executions\"\nimport { ActionRunError } from \"./errors\"\nimport { parseActionRunFailure } from \"./failure\"\nimport {\n actionRunPhaseRecordsEqual,\n actionSubjectsEqual,\n canRequeueActionRunAfterEnqueueFailure,\n isTerminalActionRun,\n} from \"./idempotency\"\nimport { assertActionRunExecution } from \"./provider\"\nimport type {\n ActionRunEffectsRecord,\n ActionRunFailure,\n ActionRunParams,\n ActionRunPhase,\n ActionRunRecord,\n ActionRunStorage,\n ActionRunWritebackRecord,\n EnterActionRunPhaseInput,\n FinishActionRunInput,\n ListActionRunsInput,\n ListActionRunsResult,\n LockActionMaterializationRunInput,\n QueueActionRunInput,\n RecordActionEffectsInput,\n RecordActionWritebackInput,\n StartActionRunInput,\n} from \"./types\"\n\ntype RunRootOperation = <T>(run: () => Promise<T> | T) => Promise<T>\n\nconst runDirectly: RunRootOperation = async <T>(run: () => Promise<T> | T): Promise<T> => run()\n\nfunction actionRunKey(projectId: string, id: string): string {\n return JSON.stringify([projectId, id])\n}\n\nfunction assertNonBlank(value: string, fieldName: string): void {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new ActionRunError(`[Sixb] Action materialization ${fieldName} must be nonblank.`)\n }\n}\n\nfunction cloneActionRunRecord(record: ActionRunRecord): ActionRunRecord {\n return structuredClone(record)\n}\n\nfunction normalizeParams(params: ActionRunParams): ActionRunParams {\n return structuredClone(params)\n}\n\nfunction normalizeSubject(subject: QueueActionRunInput[\"subject\"]): QueueActionRunInput[\"subject\"] {\n return structuredClone(subject)\n}\n\nfunction normalizeError<TPhase extends ActionRunPhase>(\n error: ActionRunFailure<TPhase>,\n expectedPhase?: TPhase\n): ActionRunFailure<TPhase> {\n return expectedPhase === undefined\n ? (parseActionRunFailure(error) as ActionRunFailure<TPhase>)\n : parseActionRunFailure(error, expectedPhase)\n}\n\nfunction normalizeWriteback(\n input: RecordActionWritebackInput,\n completedAt: Date\n): ActionRunWritebackRecord {\n if (input.status === \"succeeded\") {\n return {\n status: \"succeeded\",\n completedAt,\n result: structuredClone(input.result),\n }\n }\n\n return {\n status: \"failed\",\n completedAt,\n error: normalizeError(input.error, \"writeback\"),\n }\n}\n\nfunction normalizeEffects(\n input: RecordActionEffectsInput,\n completedAt: Date\n): ActionRunEffectsRecord {\n if (input.status === \"succeeded\") {\n return {\n status: \"succeeded\",\n completedAt,\n }\n }\n\n return {\n status: \"failed\",\n completedAt,\n error: normalizeError(input.error, \"effects\"),\n }\n}\n\nfunction compareRuns(a: ActionRunRecord, b: ActionRunRecord, order: \"asc\" | \"desc\"): number {\n const leftAt = a.startedAt ?? a.queuedAt\n const rightAt = b.startedAt ?? b.queuedAt\n const delta = leftAt.getTime() - rightAt.getTime()\n if (delta !== 0) {\n return order === \"asc\" ? delta : -delta\n }\n\n if (a.id === b.id) {\n return 0\n }\n\n return order === \"asc\" ? a.id.localeCompare(b.id) : b.id.localeCompare(a.id)\n}\n\nexport class InMemoryActionRunStorage implements ActionRunStorage {\n private readonly rows = new Map<string, ActionRunRecord>()\n private readonly runRootOperation: RunRootOperation\n\n constructor(\n private readonly executions: ExecutionStorage,\n input: { readonly runRootOperation?: RunRootOperation } = {}\n ) {\n this.runRootOperation = input.runRootOperation ?? runDirectly\n }\n\n snapshot(): InMemoryActionRunStorageSnapshot {\n return structuredClone(this.rows)\n }\n\n restore(snapshot: InMemoryActionRunStorageSnapshot): void {\n this.rows.clear()\n for (const [key, record] of structuredClone(snapshot)) {\n this.rows.set(key, record)\n }\n }\n\n async lockForMaterialization(input: LockActionMaterializationRunInput): Promise<ActionRunRecord> {\n return this.runRootOperation(() => cloneActionRunRecord(this.requireMaterializationRun(input)))\n }\n\n async queue(input: QueueActionRunInput): Promise<ActionRunRecord> {\n return this.runRootOperation(async () => {\n const key = actionRunKey(input.projectId, input.id)\n const existing = this.rows.get(key)\n if (existing && !canRequeueActionRunAfterEnqueueFailure(existing, input)) {\n throw new ActionRunError(\n `[Sixb] Action run '${input.id}' already exists for project '${input.projectId}'.`\n )\n }\n if (\n [...this.rows.values()].some(\n (run) =>\n run.projectId === input.projectId &&\n run.id !== input.id &&\n run.executionId === input.executionId\n )\n ) {\n throw new ActionRunError(\n `[Sixb] Execution '${input.executionId}' already belongs to another Action run.`\n )\n }\n await assertActionRunExecution({\n executions: this.executions,\n projectId: input.projectId,\n executionId: input.executionId,\n runId: input.id,\n actionId: input.actionId,\n })\n\n const record: ActionRunRecord = {\n id: input.id,\n projectId: input.projectId,\n executionId: input.executionId,\n actionId: input.actionId,\n subject: normalizeSubject(input.subject),\n status: \"queued\",\n phase: \"request\",\n queuedAt: new Date(input.queuedAt ?? new Date()),\n params: normalizeParams(input.params),\n idempotencyKey: input.idempotencyKey,\n }\n\n if (existing) {\n const next: ActionRunRecord = {\n ...existing,\n status: \"queued\",\n phase: \"request\",\n queuedAt: record.queuedAt,\n startedAt: undefined,\n finishedAt: undefined,\n error: undefined,\n writeback: undefined,\n effects: undefined,\n }\n this.rows.set(key, structuredClone(next))\n return cloneActionRunRecord(next)\n }\n\n this.rows.set(key, structuredClone(record))\n return cloneActionRunRecord(record)\n })\n }\n\n async start(input: StartActionRunInput): Promise<ActionRunRecord> {\n return this.runRootOperation(() => {\n const key = actionRunKey(input.projectId, input.id)\n const existing = this.rows.get(key)\n\n if (!existing) {\n throw new ActionRunError(\n `[Sixb] Action run '${input.id}' not found for project '${input.projectId}'.`\n )\n }\n\n if (existing.status !== \"queued\") {\n throw new ActionRunError(\n `[Sixb] Action run '${input.id}' cannot start from status '${existing.status}'.`\n )\n }\n\n const next: ActionRunRecord = {\n ...existing,\n status: \"running\",\n phase: input.phase ?? \"validation\",\n startedAt: new Date(input.startedAt ?? new Date()),\n error: undefined,\n }\n\n this.rows.set(key, structuredClone(next))\n return cloneActionRunRecord(next)\n })\n }\n\n async enterPhase(input: EnterActionRunPhaseInput): Promise<ActionRunRecord> {\n return this.runRootOperation(() => {\n const key = actionRunKey(input.projectId, input.id)\n const existing = this.requireRunningRun(key, input.projectId, input.id, \"enter phase\")\n const next: ActionRunRecord = {\n ...existing,\n phase: input.phase,\n }\n\n this.rows.set(key, structuredClone(next))\n return cloneActionRunRecord(next)\n })\n }\n\n async recordWriteback(input: RecordActionWritebackInput): Promise<ActionRunRecord> {\n return this.runRootOperation(() => {\n const key = actionRunKey(input.projectId, input.id)\n const existing = this.requireRunningRun(key, input.projectId, input.id, \"record writeback\")\n const writeback = normalizeWriteback(input, new Date(input.completedAt ?? new Date()))\n\n if (existing.writeback) {\n if (actionRunPhaseRecordsEqual(existing.writeback, writeback)) {\n return cloneActionRunRecord(existing)\n }\n\n throw new ActionRunError(\n `[Sixb] Action run '${input.id}' already has a different writeback record.`\n )\n }\n\n const next: ActionRunRecord = {\n ...existing,\n phase: \"writeback\",\n writeback,\n }\n\n this.rows.set(key, structuredClone(next))\n return cloneActionRunRecord(next)\n })\n }\n\n async recordEffects(input: RecordActionEffectsInput): Promise<ActionRunRecord> {\n return this.runRootOperation(() => {\n const key = actionRunKey(input.projectId, input.id)\n const existing = this.requireRunningRun(key, input.projectId, input.id, \"record effects\")\n const effects = normalizeEffects(input, new Date(input.completedAt ?? new Date()))\n\n if (existing.effects) {\n if (actionRunPhaseRecordsEqual(existing.effects, effects)) {\n return cloneActionRunRecord(existing)\n }\n\n throw new ActionRunError(\n `[Sixb] Action run '${input.id}' already has a different effects record.`\n )\n }\n\n const next: ActionRunRecord = {\n ...existing,\n phase: \"effects\",\n effects,\n }\n\n this.rows.set(key, structuredClone(next))\n return cloneActionRunRecord(next)\n })\n }\n\n async finish(input: FinishActionRunInput): Promise<ActionRunRecord> {\n return this.runRootOperation(() => {\n const key = actionRunKey(input.projectId, input.id)\n const existing = this.rows.get(key)\n\n if (!existing) {\n throw new ActionRunError(\n `[Sixb] Action run '${input.id}' not found for project '${input.projectId}'.`\n )\n }\n\n if (isTerminalActionRun(existing)) {\n throw new ActionRunError(\n `[Sixb] Action run '${input.id}' cannot finish from terminal status '${existing.status}'.`\n )\n }\n\n const phase =\n input.status === \"succeeded\" ? (input.phase ?? existing.phase) : input.error.details.phase\n\n const base: ActionRunRecord = {\n ...existing,\n status: input.status,\n phase,\n finishedAt: new Date(input.finishedAt ?? new Date()),\n }\n\n const next: ActionRunRecord =\n input.status === \"succeeded\"\n ? {\n ...base,\n error: undefined,\n }\n : {\n ...base,\n error: normalizeError(input.error),\n }\n\n this.rows.set(key, structuredClone(next))\n return cloneActionRunRecord(next)\n })\n }\n\n private requireRunningRun(\n key: string,\n projectId: string,\n id: string,\n operation: string\n ): ActionRunRecord {\n const existing = this.rows.get(key)\n\n if (!existing) {\n throw new ActionRunError(`[Sixb] Action run '${id}' not found for project '${projectId}'.`)\n }\n\n if (existing.status !== \"running\") {\n throw new ActionRunError(\n `[Sixb] Action run '${id}' cannot ${operation} from status '${existing.status}'.`\n )\n }\n\n return existing\n }\n\n async getById(params: { projectId: string; id: string }): Promise<ActionRunRecord | null> {\n return this.runRootOperation(() => {\n const record = this.rows.get(actionRunKey(params.projectId, params.id))\n return record ? cloneActionRunRecord(record) : null\n })\n }\n\n async list(input: ListActionRunsInput): Promise<ListActionRunsResult> {\n return this.runRootOperation(() => {\n if (input.actionIds?.length === 0) {\n return { runs: [], hasMore: false, total: 0 }\n }\n\n const order = input.order ?? \"desc\"\n const offset = input.offset ?? 0\n const limit = input.limit ?? this.rows.size\n const actionIds = input.actionIds ? new Set(input.actionIds) : null\n const objectTypeIds = input.objectTypeIds ? new Set(input.objectTypeIds) : null\n const statuses = input.statuses ? new Set(input.statuses) : null\n\n const filtered = [...this.rows.values()]\n .filter((record) => record.projectId === input.projectId)\n .filter((record) => (input.actionId ? record.actionId === input.actionId : true))\n .filter((record) => (actionIds ? actionIds.has(record.actionId) : true))\n .filter((record) =>\n objectTypeIds\n ? record.subject.kind !== \"object\" || objectTypeIds.has(record.subject.objectTypeId)\n : true\n )\n .filter((record) =>\n input.subject ? actionSubjectsEqual(record.subject, input.subject) : true\n )\n .filter((record) =>\n input.objectTypeId\n ? record.subject.kind === \"object\" && record.subject.objectTypeId === input.objectTypeId\n : true\n )\n .filter((record) =>\n input.primaryId\n ? record.subject.kind === \"object\" && record.subject.primaryId === input.primaryId\n : true\n )\n .filter((record) => (statuses ? statuses.has(record.status) : true))\n .filter((record) =>\n input.startedAfter ? (record.startedAt ?? record.queuedAt) >= input.startedAfter : true\n )\n .filter((record) =>\n input.startedBefore ? (record.startedAt ?? record.queuedAt) <= input.startedBefore : true\n )\n .sort((a, b) => compareRuns(a, b, order))\n\n const total = filtered.length\n const runs = filtered.slice(offset, offset + limit).map(cloneActionRunRecord)\n return { runs, hasMore: offset + runs.length < total, total }\n })\n }\n\n private requireMaterializationRun(input: LockActionMaterializationRunInput): ActionRunRecord {\n assertNonBlank(input.projectId, \"projectId\")\n assertNonBlank(input.runId, \"runId\")\n assertNonBlank(input.actionId, \"actionId\")\n\n const existing = this.rows.get(actionRunKey(input.projectId, input.runId))\n if (!existing) {\n throw new ActionRunError(\n `[Sixb] Action run '${input.runId}' not found for project '${input.projectId}'.`\n )\n }\n if (existing.actionId !== input.actionId) {\n throw new ActionRunError(\n `[Sixb] Action run '${input.runId}' does not belong to action '${input.actionId}'.`\n )\n }\n if (existing.status !== \"running\") {\n throw new ActionRunError(\n `[Sixb] Action run '${input.runId}' cannot materialize from status '${existing.status}'.`\n )\n }\n return existing\n }\n}\n\nexport type InMemoryActionRunStorageSnapshot = Map<string, ActionRunRecord>\n",
6
- "import type { FileRef } from \"../blob-storage\"\nimport type { JsonValue } from \"../json\"\nimport type { ProviderData } from \"../models\"\nimport type { AgentContextPart } from \"./context/entries\"\n\n/**\n * The agent's own, SDK-independent message. We store messages and threads — not an SDK transport —\n * so a message is just a `role` plus structured `parts` (and optional `metadata`). There is no\n * self-describing wrapper: the storage row owns the message's identity, and `contentVersion` (a\n * column) versions the parts shape so it can be migrated.\n *\n * The part union is intentionally focused on what agent runs actually produce (text, reasoning, step\n * boundaries, tool calls). The model loop validates and normalizes output before its steps are\n * projected into this union; storage validates the durable write contract independently.\n */\nexport const AGENT_MESSAGE_CONTENT_VERSION = 2 as const\n\nexport type AgentMessageRole = \"system\" | \"user\" | \"assistant\"\n\n/** A plain text part (assistant output, user input, or system text). */\nexport interface AgentTextPart {\n readonly type: \"text\"\n readonly text: string\n /** Provider passthrough (kept because some providers require it on the next turn). */\n readonly providerMetadata?: ProviderData\n}\n\n/**\n * A reasoning (\"thinking\") part. `providerMetadata` is load-bearing here: some providers require\n * the reasoning signature back on the following turn, so dropping it would break multi-step loops.\n */\nexport interface AgentReasoningPart {\n readonly type: \"reasoning\"\n readonly text: string\n readonly providerMetadata?: ProviderData\n}\n\n/** A step boundary between assistant loop iterations. */\nexport interface AgentStepStartPart {\n readonly type: \"step-start\"\n}\n\n/** A blob-backed file attached to a user message or produced by an agent/tool. */\nexport interface AgentFilePart {\n readonly type: \"file\"\n readonly fileRef: FileRef\n /** Provider passthrough for future model-specific file handling. */\n readonly providerMetadata?: ProviderData\n}\n\ninterface AgentToolCallBase {\n readonly type: \"tool-call\"\n readonly toolCallId: string\n readonly toolName: string\n /** `true` when the model identifies the call as a dynamic tool. */\n readonly dynamic?: boolean\n /** `true` when the provider executed the tool inline (steers model projection). */\n readonly providerExecuted?: boolean\n readonly input: JsonValue\n readonly providerMetadata?: ProviderData\n}\n\n/** Ordered, hidden provider state required to replay a model response losslessly. */\nexport interface AgentProviderStatePart {\n readonly type: \"provider-state\"\n readonly providerId: string\n readonly data: JsonValue\n}\n\n/**\n * A completed tool call. Only terminal states are modelled — transient states\n * (`input-streaming`, `input-available`, `approval-*`) are never persisted because messages are\n * written only once a run finishes.\n */\nexport type AgentToolCallPart = AgentToolCallBase &\n (\n | { readonly state: \"output-available\"; readonly output: JsonValue }\n | { readonly state: \"output-error\"; readonly errorText: string }\n )\n\nexport type AgentMessagePart =\n | AgentTextPart\n | AgentReasoningPart\n | AgentStepStartPart\n | AgentFilePart\n | AgentContextPart\n | AgentToolCallPart\n | AgentProviderStatePart\n\nexport type AgentMessagePartType = AgentMessagePart[\"type\"]\nexport type AgentToolCallState = AgentToolCallPart[\"state\"]\n\n/** The logical agent message the adapters speak and the store persists (as columns). */\nexport interface AgentMessage {\n readonly role: AgentMessageRole\n readonly parts: readonly AgentMessagePart[]\n /** Optional JSON metadata associated with the message. */\n readonly metadata?: JsonValue\n}\n",
6
+ "import type { FileRef } from \"../blob-storage\"\nimport type { JsonValue } from \"../json\"\nimport type { ProviderData } from \"../models\"\nimport type { AgentContextPart } from \"./context/entries\"\n\n/**\n * The agent's own, SDK-independent message. We store messages and threads — not an SDK transport —\n * so a message is just a `role` plus structured `parts` (and optional `metadata`). There is no\n * self-describing wrapper: the storage row owns the message's identity, and `contentVersion` (a\n * column) versions the parts shape so it can be migrated.\n *\n * The part union is intentionally focused on what agent runs actually produce (text, reasoning, step\n * boundaries, tool calls). The model loop validates and normalizes output before its steps are\n * projected into this union; storage validates the durable write contract independently.\n */\nexport const AGENT_MESSAGE_CONTENT_VERSION = 2 as const\n\nexport type AgentMessageRole = \"system\" | \"user\" | \"assistant\"\n\n/** A plain text part (assistant output, user input, or system text). */\nexport interface AgentTextPart {\n readonly type: \"text\"\n readonly text: string\n /** Provider passthrough (kept because some providers require it on the next turn). */\n readonly providerMetadata?: ProviderData\n}\n\n/**\n * A reasoning (\"thinking\") part. `providerMetadata` is load-bearing here: some providers require\n * the reasoning signature back on the following turn, so dropping it would break multi-step loops.\n */\nexport interface AgentReasoningPart {\n readonly type: \"reasoning\"\n readonly text: string\n readonly providerMetadata?: ProviderData\n}\n\n/** A step boundary between assistant loop iterations. */\nexport interface AgentStepStartPart {\n readonly type: \"step-start\"\n}\n\n/** A blob-backed file attached to a user message or produced by an agent/tool. */\nexport interface AgentFilePart {\n readonly type: \"file\"\n readonly fileRef: FileRef\n /** Provider passthrough for future model-specific file handling. */\n readonly providerMetadata?: ProviderData\n}\n\ninterface AgentToolCallBase {\n readonly type: \"tool-call\"\n readonly toolCallId: string\n readonly toolName: string\n /** `true` when the model identifies the call as a dynamic tool. */\n readonly dynamic?: boolean\n /** `true` when the provider executed the tool inline (steers model projection). */\n readonly providerExecuted?: boolean\n readonly input: JsonValue\n readonly providerMetadata?: ProviderData\n}\n\n/**\n * The user asked the Agent to continue an answer the turn limit cut short. Sixb writes the\n * instruction the model reads; chats show no message for it.\n */\nexport interface AgentContinuationPart {\n readonly type: \"continuation\"\n}\n\n/** Ordered, hidden provider state required to replay a model response losslessly. */\nexport interface AgentProviderStatePart {\n readonly type: \"provider-state\"\n readonly providerId: string\n readonly data: JsonValue\n}\n\n/**\n * A completed tool call. Only terminal states are modelled — transient states\n * (`input-streaming`, `input-available`, `approval-*`) are never persisted because messages are\n * written only once a run finishes.\n */\nexport type AgentToolCallPart = AgentToolCallBase &\n (\n | { readonly state: \"output-available\"; readonly output: JsonValue }\n | { readonly state: \"output-error\"; readonly errorText: string }\n )\n\nexport type AgentMessagePart =\n | AgentTextPart\n | AgentReasoningPart\n | AgentStepStartPart\n | AgentFilePart\n | AgentContextPart\n | AgentContinuationPart\n | AgentToolCallPart\n | AgentProviderStatePart\n\nexport type AgentMessagePartType = AgentMessagePart[\"type\"]\nexport type AgentToolCallState = AgentToolCallPart[\"state\"]\n\n/** The logical agent message the adapters speak and the store persists (as columns). */\nexport interface AgentMessage {\n readonly role: AgentMessageRole\n readonly parts: readonly AgentMessagePart[]\n /** Optional JSON metadata associated with the message. */\n readonly metadata?: JsonValue\n}\n",
7
7
  "import { AGENT_MESSAGE_CONTENT_VERSION } from \"../../agents/message\"\nimport { principalsEqual } from \"../../auth\"\nimport { parseSixbFailure } from \"../../errors/internal\"\nimport type { SixbFailure } from \"../../errors/types\"\nimport type { ExecutionStorage } from \"../executions\"\nimport { AgentStorageError } from \"./errors\"\nimport {\n agentContextCheckpointMatchesCreateInput,\n assertAgentContextCheckpointAnchors,\n assertAgentContextCheckpointAuthority,\n assertAgentContextCheckpointReplayState,\n assertAgentRunExecution,\n assertConversationAgentRunSpec,\n assertCreateAgentContextCheckpointInput,\n assertCreateSubagentRunInput,\n assertSubagentRunResult,\n snapshotAgentThreadSandboxParams,\n subagentRunMatchesCreateInput,\n transitionAgentThreadSandbox,\n} from \"./provider\"\nimport type {\n AgentContextCheckpointRecord,\n AgentContextCheckpointStore,\n AgentMessageRecord,\n AgentMessageStore,\n AgentRunFailureCode,\n AgentRunRecord,\n AgentRunStore,\n AgentStorage,\n AgentThreadRecord,\n AgentThreadSandboxState,\n AgentThreadStore,\n AppendAgentMessageInput,\n ConfirmAgentRunExecutionOwnershipInput,\n ConversationAgentRunRecord,\n CreateAgentContextCheckpointInput,\n CreateAgentRunInput,\n CreateAgentThreadInput,\n CreateSubagentRunInput,\n DeleteAgentMessagesByRunInput,\n FinishAgentRunInput,\n FinishQueuedAgentRunInput,\n ListAgentMessagesInput,\n ListAgentMessagesResult,\n ListAgentRunsInput,\n ListAgentRunsResult,\n ListAgentThreadsInput,\n ListAgentThreadsResult,\n ReclaimAgentRunInput,\n StartAgentRunInput,\n SubagentRunRecord,\n TransitionAgentThreadSandboxInput,\n} from \"./types\"\nimport { AGENT_RUN_FAILURE_CODES } from \"./types\"\n\nfunction normalizeFailure(\n failure: SixbFailure<AgentRunFailureCode> | undefined\n): SixbFailure<AgentRunFailureCode> | undefined {\n return failure ? parseSixbFailure(failure, AGENT_RUN_FAILURE_CODES) : undefined\n}\n\nfunction key(projectId: string, id: string): string {\n return JSON.stringify([projectId, id])\n}\n\nfunction clone<T>(value: T): T {\n return structuredClone(value)\n}\n\nfunction compareByDate(\n left: Date | undefined,\n right: Date | undefined,\n leftId: string,\n rightId: string,\n order: \"asc\" | \"desc\"\n): number {\n const delta = (left?.getTime() ?? 0) - (right?.getTime() ?? 0)\n if (delta !== 0) {\n return order === \"asc\" ? delta : -delta\n }\n if (leftId === rightId) {\n return 0\n }\n return order === \"asc\" ? leftId.localeCompare(rightId) : rightId.localeCompare(leftId)\n}\n\ninterface Window<T> {\n readonly page: T[]\n readonly hasMore: boolean\n readonly total: number\n}\n\nfunction applyWindow<T>(rows: T[], offset = 0, limit?: number): Window<T> {\n const total = rows.length\n const end = limit === undefined ? total : offset + limit\n const page = rows.slice(offset, end)\n return { page, hasMore: offset + page.length < total, total }\n}\n\n/**\n * Shared in-memory state behind the four sub-stores. They are tiered for ergonomics\n * (`storage.runs.create(...)`), but several operations span tables — creating/finishing a run\n * updates the thread anchor, appending a message bumps thread stats, and checkpoint creation reads\n * run/thread/message anchors — so they all read and write the same maps through this object.\n */\ninterface AgentStoreState {\n readonly threads: Map<string, AgentThreadRecord>\n readonly runs: Map<string, AgentRunRecord>\n readonly messages: Map<string, AgentMessageRecord>\n readonly checkpoints: Map<string, AgentContextCheckpointRecord>\n}\n\nexport interface InMemoryAgentStorageSnapshot {\n readonly threads: Map<string, AgentThreadRecord>\n readonly runs: Map<string, AgentRunRecord>\n readonly messages: Map<string, AgentMessageRecord>\n readonly checkpoints: Map<string, AgentContextCheckpointRecord>\n}\n\n// ── threads ───────────────────────────────────────────────────────────────────────────────────\n\nclass InMemoryAgentThreadStore implements AgentThreadStore {\n constructor(private readonly state: AgentStoreState) {}\n\n async transitionSandbox(\n input: TransitionAgentThreadSandboxInput\n ): Promise<AgentThreadSandboxState> {\n const threadKey = key(input.projectId, input.id)\n const thread = this.state.threads.get(threadKey) ?? null\n const run =\n input.action === \"recreate\"\n ? null\n : (this.state.runs.get(key(input.projectId, input.runId)) ?? null)\n const sandboxState = transitionAgentThreadSandbox(thread, run, input)\n if (!thread) throw new AgentStorageError(\"thread_not_found\", \"[Sixb] Thread not found.\")\n this.state.threads.set(threadKey, { ...thread, sandboxState: clone(sandboxState) })\n return clone(sandboxState)\n }\n\n async create(input: CreateAgentThreadInput): Promise<AgentThreadRecord> {\n const sandboxParams =\n input.sandboxParams === undefined\n ? undefined\n : snapshotAgentThreadSandboxParams(input.sandboxParams)\n const threadKey = key(input.projectId, input.id)\n if (this.state.threads.has(threadKey)) {\n throw new AgentStorageError(\n \"duplicate_id\",\n `[Sixb] Agent thread '${input.id}' already exists for project '${input.projectId}'.`\n )\n }\n\n const createdAt = new Date(input.createdAt ?? new Date())\n const record: AgentThreadRecord = {\n id: input.id,\n projectId: input.projectId,\n ownerPrincipal: clone(input.ownerPrincipal),\n ...(sandboxParams === undefined ? {} : { sandboxParams }),\n ...(input.title === undefined ? {} : { title: input.title }),\n status: input.status ?? \"active\",\n activeRunId: null,\n messageCount: 0,\n createdAt,\n updatedAt: new Date(input.updatedAt ?? createdAt),\n }\n\n this.state.threads.set(threadKey, clone(record))\n return clone(record)\n }\n\n async getById(params: { projectId: string; id: string }): Promise<AgentThreadRecord | null> {\n const record = this.state.threads.get(key(params.projectId, params.id))\n return record ? clone(record) : null\n }\n\n async list(input: ListAgentThreadsInput): Promise<ListAgentThreadsResult> {\n const order = input.order ?? \"desc\"\n const statuses = input.statuses ? new Set(input.statuses) : null\n const filtered = [...this.state.threads.values()]\n .filter((thread) => thread.projectId === input.projectId)\n .filter((thread) => (statuses ? statuses.has(thread.status) : true))\n .filter((thread) =>\n input.ownerPrincipal ? principalsEqual(thread.ownerPrincipal, input.ownerPrincipal) : true\n )\n .sort((a, b) =>\n compareByDate(\n a.lastMessageAt ?? a.createdAt,\n b.lastMessageAt ?? b.createdAt,\n a.id,\n b.id,\n order\n )\n )\n\n const { page, hasMore, total } = applyWindow(filtered, input.offset, input.limit)\n return { threads: page.map(clone), hasMore, total }\n }\n}\n\n// ── runs ──────────────────────────────────────────────────────────────────────────────────────\n\nclass InMemoryAgentRunStore implements AgentRunStore {\n constructor(\n private readonly state: AgentStoreState,\n private readonly executions: ExecutionStorage\n ) {}\n\n async create(input: CreateAgentRunInput): Promise<ConversationAgentRunRecord> {\n assertConversationAgentRunSpec(input.spec)\n await assertAgentRunExecution({\n executions: this.executions,\n projectId: input.projectId,\n executionId: input.executionId,\n runId: input.id,\n })\n // No `await` between read and write: the in-memory critical section is atomic, so two concurrent\n // queued runs on the same thread cannot both win — the second observes `activeRunId` set.\n const threadKey = key(input.projectId, input.threadId)\n const thread = this.state.threads.get(threadKey)\n if (!thread) {\n throw new AgentStorageError(\n \"thread_not_found\",\n `[Sixb] Agent thread '${input.threadId}' not found for project '${input.projectId}'.`\n )\n }\n if (thread.activeRunId !== null) {\n throw new AgentStorageError(\n \"active_run_exists\",\n `[Sixb] Agent thread '${input.threadId}' already has an active run '${thread.activeRunId}'.`\n )\n }\n\n const runKey = key(input.projectId, input.id)\n if (this.state.runs.has(runKey)) {\n throw new AgentStorageError(\n \"duplicate_id\",\n `[Sixb] Agent run '${input.id}' already exists for project '${input.projectId}'.`\n )\n }\n if (\n [...this.state.runs.values()].some(\n (run) => run.projectId === input.projectId && run.executionId === input.executionId\n )\n ) {\n throw new AgentStorageError(\n \"duplicate_id\",\n `[Sixb] Execution '${input.executionId}' already belongs to another Agent run.`\n )\n }\n\n const createdAt = new Date(input.createdAt ?? new Date())\n const run: ConversationAgentRunRecord = {\n kind: \"conversation\",\n id: input.id,\n projectId: input.projectId,\n executionId: input.executionId,\n threadId: input.threadId,\n triggerMessageId: input.triggerMessageId,\n spec: clone(input.spec),\n status: \"queued\",\n attempt: 0,\n createdAt,\n }\n this.state.runs.set(runKey, clone(run))\n\n const updatedThread: AgentThreadRecord = {\n ...thread,\n activeRunId: run.id,\n updatedAt: createdAt,\n }\n this.state.threads.set(threadKey, clone(updatedThread))\n\n return clone(run)\n }\n\n async createSubagent(input: CreateSubagentRunInput): Promise<SubagentRunRecord> {\n assertCreateSubagentRunInput(input)\n const execution = await assertAgentRunExecution({\n executions: this.executions,\n projectId: input.projectId,\n executionId: input.executionId,\n runId: input.id,\n })\n\n const runKey = key(input.projectId, input.id)\n const existing = this.state.runs.get(runKey)\n if (existing) {\n if (subagentRunMatchesCreateInput(existing, input)) return clone(existing)\n throw new AgentStorageError(\n \"duplicate_id\",\n `[Sixb] Subagent run '${input.id}' already exists with different immutable inputs.`\n )\n }\n\n const parent = this.state.runs.get(key(input.projectId, input.parentRunId))\n if (!parent || parent.kind !== \"conversation\") {\n throw new AgentStorageError(\n \"run_not_found\",\n `[Sixb] Parent Agent run '${input.parentRunId}' was not found.`\n )\n }\n if (parent.status !== \"running\") {\n throw new AgentStorageError(\n \"invalid_state\",\n `[Sixb] Parent Agent run '${parent.id}' is not running (status '${parent.status}').`\n )\n }\n if (\n execution.source.type !== \"execution\" ||\n execution.source.executionId !== parent.executionId\n ) {\n throw new AgentStorageError(\n \"invalid_input\",\n `[Sixb] Subagent execution '${execution.id}' is not a child of parent execution '${parent.executionId}'.`\n )\n }\n if (parent.execution?.token !== input.parentExecutionToken) {\n throw new AgentStorageError(\n \"execution_lost\",\n `[Sixb] Parent Agent run '${parent.id}' is no longer owned by this execution.`\n )\n }\n const activeChildren = [...this.state.runs.values()].filter(\n (run) =>\n run.kind === \"subagent\" &&\n run.projectId === input.projectId &&\n run.parentRunId === parent.id &&\n (run.status === \"queued\" || run.status === \"running\")\n ).length\n if (activeChildren >= input.maxActiveChildren) {\n throw new AgentStorageError(\n \"active_child_limit\",\n `[Sixb] Agent run '${parent.id}' already has ${activeChildren} active subagents.`\n )\n }\n if (\n [...this.state.runs.values()].some(\n (run) => run.projectId === input.projectId && run.executionId === input.executionId\n )\n ) {\n throw new AgentStorageError(\n \"duplicate_id\",\n `[Sixb] Execution '${input.executionId}' already belongs to another Agent run.`\n )\n }\n\n const run: SubagentRunRecord = {\n kind: \"subagent\",\n id: input.id,\n projectId: input.projectId,\n executionId: input.executionId,\n parentRunId: input.parentRunId,\n spawnKey: input.spawnKey,\n spec: clone(input.spec),\n status: \"queued\",\n attempt: 0,\n createdAt: new Date(input.createdAt ?? new Date()),\n }\n this.state.runs.set(runKey, clone(run))\n return clone(run)\n }\n\n async start(input: StartAgentRunInput): Promise<AgentRunRecord> {\n const run = this.requireStatus(input.projectId, input.id, \"queued\")\n const startedAt = new Date(input.startedAt ?? new Date())\n const next: AgentRunRecord = {\n ...run,\n status: \"running\",\n ...(input.modelId === undefined ? {} : { modelId: input.modelId }),\n attempt: 1,\n execution: clone(input.execution),\n startedAt,\n }\n this.state.runs.set(key(input.projectId, input.id), clone(next))\n return clone(next)\n }\n\n async finishQueued(input: FinishQueuedAgentRunInput): Promise<AgentRunRecord> {\n const run = this.requireStatus(input.projectId, input.id, \"queued\")\n const completedAt = new Date(input.completedAt ?? new Date())\n const next: AgentRunRecord = {\n ...run,\n status: input.status,\n ...(input.error === undefined ? {} : { error: normalizeFailure(input.error) }),\n completedAt,\n }\n this.state.runs.set(key(input.projectId, input.id), clone(next))\n this.releaseThread(run, completedAt)\n return clone(next)\n }\n\n async reclaim(input: ReclaimAgentRunInput): Promise<AgentRunRecord> {\n const run = this.requireRunning(input.projectId, input.id)\n const next: AgentRunRecord = {\n ...run,\n attempt: run.attempt + 1,\n execution: clone(input.execution),\n }\n this.state.runs.set(key(input.projectId, input.id), clone(next))\n return clone(next)\n }\n\n async confirmExecutionOwnership(\n input: ConfirmAgentRunExecutionOwnershipInput\n ): Promise<AgentRunRecord> {\n const run = this.requireRunning(input.projectId, input.id)\n if (!run.execution || run.execution.token !== input.executionToken) {\n throw new AgentStorageError(\n \"execution_lost\",\n `[Sixb] Execution token is no longer current on agent run '${input.id}'.`\n )\n }\n\n const next: AgentRunRecord = {\n ...run,\n execution: {\n ...run.execution,\n queueLeaseExpiresAt: new Date(\n Math.max(run.execution.queueLeaseExpiresAt.getTime(), input.queueLeaseExpiresAt.getTime())\n ),\n },\n }\n this.state.runs.set(key(input.projectId, input.id), clone(next))\n return clone(next)\n }\n\n async finish(input: FinishAgentRunInput): Promise<AgentRunRecord> {\n const run = this.requireRunning(input.projectId, input.id)\n if (!run.execution || run.execution.token !== input.executionToken) {\n throw new AgentStorageError(\n \"execution_lost\",\n `[Sixb] Execution token is no longer current on agent run '${input.id}'.`\n )\n }\n if (input.status === \"succeeded\" && run.kind === \"subagent\") {\n assertSubagentRunResult(input.result, run.id)\n }\n if (input.status === \"succeeded\" && run.kind === \"conversation\" && input.result !== undefined) {\n throw new AgentStorageError(\n \"invalid_input\",\n `[Sixb] Conversational Agent run '${run.id}' cannot persist a subagent result.`\n )\n }\n\n const completedAt = new Date(input.completedAt ?? new Date())\n const next: AgentRunRecord = {\n ...run,\n status: input.status,\n ...(input.modelId === undefined ? {} : { modelId: input.modelId }),\n ...(input.finishReason === undefined ? {} : { finishReason: input.finishReason }),\n ...(input.diagnostics === undefined ? {} : { diagnostics: clone(input.diagnostics) }),\n ...(input.status === \"succeeded\" && input.result !== undefined\n ? { result: clone(input.result) }\n : {}),\n ...(input.status === \"succeeded\" || input.error === undefined\n ? {}\n : { error: normalizeFailure(input.error) }),\n execution: undefined,\n completedAt,\n }\n this.state.runs.set(key(input.projectId, input.id), clone(next))\n\n this.releaseThread(run, completedAt)\n\n return clone(next)\n }\n\n async getById(params: { projectId: string; id: string }): Promise<AgentRunRecord | null> {\n const record = this.state.runs.get(key(params.projectId, params.id))\n return record ? clone(record) : null\n }\n\n async getByIds(params: {\n projectId: string\n ids: readonly string[]\n }): Promise<readonly AgentRunRecord[]> {\n return [...new Set(params.ids)]\n .map((id) => this.state.runs.get(key(params.projectId, id)))\n .filter((record): record is AgentRunRecord => record !== undefined)\n .map(clone)\n }\n\n async list(input: ListAgentRunsInput): Promise<ListAgentRunsResult> {\n const order = input.order ?? \"desc\"\n const statuses = input.statuses ? new Set(input.statuses) : null\n const kinds = input.kinds ? new Set(input.kinds) : null\n\n const filtered = [...this.state.runs.values()]\n .filter((run) => run.projectId === input.projectId)\n .filter((run) => (kinds ? kinds.has(run.kind) : true))\n .filter((run) =>\n input.threadId ? run.kind === \"conversation\" && run.threadId === input.threadId : true\n )\n .filter((run) =>\n input.parentRunId ? run.kind === \"subagent\" && run.parentRunId === input.parentRunId : true\n )\n .filter((run) => (statuses ? statuses.has(run.status) : true))\n .filter((run) =>\n input.startedAfter ? (run.startedAt ?? run.createdAt) >= input.startedAfter : true\n )\n .filter((run) =>\n input.startedBefore ? (run.startedAt ?? run.createdAt) <= input.startedBefore : true\n )\n .sort((a, b) =>\n compareByDate(a.startedAt ?? a.createdAt, b.startedAt ?? b.createdAt, a.id, b.id, order)\n )\n\n const { page, hasMore, total } = applyWindow(filtered, input.offset, input.limit)\n return { runs: page.map(clone), hasMore, total }\n }\n\n private requireRunning(projectId: string, id: string): AgentRunRecord {\n return this.requireStatus(projectId, id, \"running\")\n }\n\n private requireStatus(\n projectId: string,\n id: string,\n status: AgentRunRecord[\"status\"]\n ): AgentRunRecord {\n const run = this.state.runs.get(key(projectId, id))\n if (!run) {\n throw new AgentStorageError(\n \"run_not_found\",\n `[Sixb] Agent run '${id}' not found for project '${projectId}'.`\n )\n }\n if (run.status !== status) {\n throw new AgentStorageError(\n \"invalid_state\",\n `[Sixb] Agent run '${id}' is not ${status} (status '${run.status}').`\n )\n }\n return run\n }\n\n private releaseThread(run: AgentRunRecord, completedAt: Date): void {\n if (run.kind !== \"conversation\") return\n const threadKey = key(run.projectId, run.threadId)\n const thread = this.state.threads.get(threadKey)\n if (thread && thread.activeRunId === run.id) {\n this.state.threads.set(\n threadKey,\n clone({ ...thread, activeRunId: null, updatedAt: completedAt })\n )\n }\n }\n}\n\n// ── messages ──────────────────────────────────────────────────────────────────────────────────\n\nclass InMemoryAgentMessageStore implements AgentMessageStore {\n constructor(private readonly state: AgentStoreState) {}\n\n async append(input: AppendAgentMessageInput): Promise<AgentMessageRecord> {\n const threadKey = key(input.projectId, input.threadId)\n const thread = this.state.threads.get(threadKey)\n if (!thread) {\n throw new AgentStorageError(\n \"thread_not_found\",\n `[Sixb] Agent thread '${input.threadId}' not found for project '${input.projectId}'.`\n )\n }\n\n const messageKey = key(input.projectId, input.id)\n if (this.state.messages.has(messageKey)) {\n throw new AgentStorageError(\n \"duplicate_id\",\n `[Sixb] Agent message '${input.id}' already exists for project '${input.projectId}'.`\n )\n }\n\n if (input.runId !== null && !this.state.runs.has(key(input.projectId, input.runId))) {\n throw new AgentStorageError(\n \"run_not_found\",\n `[Sixb] Agent run '${input.runId}' not found for project '${input.projectId}'.`\n )\n }\n\n const createdAt = new Date(input.createdAt ?? new Date())\n const seq = this.nextSeq(input.projectId, input.threadId)\n const message: AgentMessageRecord = {\n id: input.id,\n projectId: input.projectId,\n threadId: input.threadId,\n runId: input.runId,\n role: input.role,\n ...(input.authorPrincipal === undefined\n ? {}\n : { authorPrincipal: clone(input.authorPrincipal) }),\n seq,\n parts: clone(input.parts),\n ...(input.metadata === undefined ? {} : { metadata: clone(input.metadata) }),\n contentVersion: AGENT_MESSAGE_CONTENT_VERSION,\n createdAt,\n ...(input.completedAt === undefined ? {} : { completedAt: new Date(input.completedAt) }),\n }\n this.state.messages.set(messageKey, clone(message))\n\n this.state.threads.set(\n threadKey,\n clone({\n ...thread,\n messageCount: thread.messageCount + 1,\n lastMessageAt: createdAt,\n updatedAt: createdAt,\n })\n )\n\n return clone(message)\n }\n\n async deleteByRunId(input: DeleteAgentMessagesByRunInput): Promise<number> {\n const threadKey = key(input.projectId, input.threadId)\n const thread = this.state.threads.get(threadKey)\n if (!thread) {\n throw new AgentStorageError(\n \"thread_not_found\",\n `[Sixb] Agent thread '${input.threadId}' not found for project '${input.projectId}'.`\n )\n }\n\n const messages = [...this.state.messages.entries()].filter(\n ([, message]) =>\n message.projectId === input.projectId &&\n message.threadId === input.threadId &&\n message.runId === input.runId\n )\n if (messages.length === 0) {\n return 0\n }\n\n for (const [messageKey] of messages) {\n this.state.messages.delete(messageKey)\n }\n\n const remainingMessages = [...this.state.messages.values()]\n .filter(\n (message) => message.projectId === input.projectId && message.threadId === input.threadId\n )\n .sort((left, right) => right.seq - left.seq)\n const latestMessage = remainingMessages[0]\n const updatedAt = new Date()\n this.state.threads.set(\n threadKey,\n clone({\n ...thread,\n messageCount: remainingMessages.length,\n lastMessageAt: latestMessage?.createdAt,\n updatedAt,\n })\n )\n\n return messages.length\n }\n\n async getById(params: { projectId: string; id: string }): Promise<AgentMessageRecord | null> {\n const record = this.state.messages.get(key(params.projectId, params.id))\n return record ? clone(record) : null\n }\n\n async list(input: ListAgentMessagesInput): Promise<ListAgentMessagesResult> {\n const order = input.order ?? \"asc\"\n const roles = input.roles ? new Set(input.roles) : null\n\n const filtered = [...this.state.messages.values()]\n .filter((message) => message.projectId === input.projectId)\n .filter((message) => message.threadId === input.threadId)\n .filter((message) => (input.afterSeq === undefined ? true : message.seq > input.afterSeq))\n .filter((message) => (roles ? roles.has(message.role) : true))\n .sort((a, b) => (order === \"asc\" ? a.seq - b.seq : b.seq - a.seq))\n\n const { page, hasMore, total } = applyWindow(filtered, input.offset, input.limit)\n return { messages: page.map(clone), hasMore, total }\n }\n\n private nextSeq(projectId: string, threadId: string): number {\n let max = 0\n for (const message of this.state.messages.values()) {\n if (message.projectId === projectId && message.threadId === threadId && message.seq > max) {\n max = message.seq\n }\n }\n return max + 1\n }\n}\n\n// ── context checkpoints ──────────────────────────────────────────────────────────────────────\n\nclass InMemoryAgentContextCheckpointStore implements AgentContextCheckpointStore {\n constructor(private readonly state: AgentStoreState) {}\n\n async create(input: CreateAgentContextCheckpointInput): Promise<AgentContextCheckpointRecord> {\n assertCreateAgentContextCheckpointInput(input)\n\n // No `await` between authority checks and append: this is one in-memory critical section.\n const run = this.state.runs.get(key(input.projectId, input.createdByRunId)) ?? null\n const thread = this.state.threads.get(key(input.projectId, input.threadId)) ?? null\n assertAgentContextCheckpointAuthority({ create: input, run, thread })\n\n const messages = [...this.state.messages.values()].filter(\n (message) => message.projectId === input.projectId && message.threadId === input.threadId\n )\n const headSeq = messages.reduce((head, message) => Math.max(head, message.seq), 0)\n const latest = this.findLatest(input.projectId, input.threadId)\n\n const existingForRun = [...this.state.checkpoints.values()].find(\n (checkpoint) =>\n checkpoint.projectId === input.projectId &&\n checkpoint.createdByRunId === input.createdByRunId\n )\n if (existingForRun) {\n if (agentContextCheckpointMatchesCreateInput(existingForRun, input)) {\n assertAgentContextCheckpointReplayState({\n create: input,\n existing: existingForRun,\n latest,\n headSeq,\n })\n return clone(existingForRun)\n }\n throw new AgentStorageError(\n \"invalid_state\",\n `[Sixb] Agent run '${input.createdByRunId}' already created a different context checkpoint.`\n )\n }\n\n if (this.state.checkpoints.has(key(input.projectId, input.id))) {\n throw new AgentStorageError(\n \"duplicate_id\",\n `[Sixb] Agent context checkpoint '${input.id}' already exists for project '${input.projectId}'.`\n )\n }\n\n const firstRetained =\n messages\n .filter((message) => message.seq > input.summarizedThroughSeq)\n .sort((left, right) => left.seq - right.seq)[0] ?? null\n assertAgentContextCheckpointAnchors({\n create: input,\n latest,\n headSeq,\n firstRetained,\n })\n\n const record: AgentContextCheckpointRecord = {\n id: input.id,\n projectId: input.projectId,\n threadId: input.threadId,\n createdByRunId: input.createdByRunId,\n ...(input.expectedPreviousCheckpointId === null\n ? {}\n : { previousCheckpointId: input.expectedPreviousCheckpointId }),\n reason: input.reason,\n summary: input.summary,\n summaryFormatVersion: input.summaryFormatVersion,\n summarizedThroughSeq: input.summarizedThroughSeq,\n observedHeadSeq: input.observedHeadSeq,\n estimatedInputTokensBefore: input.estimatedInputTokensBefore,\n estimatedInputTokensAfter: input.estimatedInputTokensAfter,\n summaryModelId: input.summaryModelId,\n createdAt: new Date(input.createdAt ?? new Date()),\n }\n this.state.checkpoints.set(key(input.projectId, input.id), clone(record))\n return clone(record)\n }\n\n async getLatest(input: {\n readonly projectId: string\n readonly threadId: string\n }): Promise<AgentContextCheckpointRecord | null> {\n const record = this.findLatest(input.projectId, input.threadId)\n return record ? clone(record) : null\n }\n\n async getByRunIds(input: {\n readonly projectId: string\n readonly runIds: readonly string[]\n }): Promise<readonly AgentContextCheckpointRecord[]> {\n const byRunId = new Map(\n [...this.state.checkpoints.values()]\n .filter((checkpoint) => checkpoint.projectId === input.projectId)\n .map((checkpoint) => [checkpoint.createdByRunId, checkpoint] as const)\n )\n return [...new Set(input.runIds)].flatMap((runId) => {\n const checkpoint = byRunId.get(runId)\n return checkpoint ? [clone(checkpoint)] : []\n })\n }\n\n private findLatest(projectId: string, threadId: string): AgentContextCheckpointRecord | null {\n return (\n [...this.state.checkpoints.values()]\n .filter(\n (checkpoint) => checkpoint.projectId === projectId && checkpoint.threadId === threadId\n )\n .sort(\n (left, right) =>\n right.summarizedThroughSeq - left.summarizedThroughSeq ||\n right.createdAt.getTime() - left.createdAt.getTime() ||\n right.id.localeCompare(left.id)\n )[0] ?? null\n )\n }\n}\n\nexport class InMemoryAgentStorage implements AgentStorage {\n private readonly state: AgentStoreState = {\n threads: new Map(),\n runs: new Map(),\n messages: new Map(),\n checkpoints: new Map(),\n }\n\n readonly threads: InMemoryAgentThreadStore\n readonly runs: InMemoryAgentRunStore\n readonly messages: InMemoryAgentMessageStore\n readonly checkpoints: InMemoryAgentContextCheckpointStore\n\n constructor(executions: ExecutionStorage) {\n this.threads = new InMemoryAgentThreadStore(this.state)\n this.runs = new InMemoryAgentRunStore(this.state, executions)\n this.messages = new InMemoryAgentMessageStore(this.state)\n this.checkpoints = new InMemoryAgentContextCheckpointStore(this.state)\n }\n\n snapshot(): InMemoryAgentStorageSnapshot {\n return {\n threads: structuredClone(this.state.threads),\n runs: structuredClone(this.state.runs),\n messages: structuredClone(this.state.messages),\n checkpoints: structuredClone(this.state.checkpoints),\n }\n }\n\n restore(snapshot: InMemoryAgentStorageSnapshot): void {\n replace(this.state.threads, snapshot.threads)\n replace(this.state.runs, snapshot.runs)\n replace(this.state.messages, snapshot.messages)\n replace(this.state.checkpoints, snapshot.checkpoints)\n }\n}\n\nfunction replace<T>(target: Map<string, T>, source: Map<string, T>): void {\n target.clear()\n for (const [k, value] of structuredClone(source)) {\n target.set(k, value)\n }\n}\n",
8
8
  "export type AiCostStorageErrorCode = \"missing_usage\" | \"cost_mismatch\"\n\nexport class AiCostStorageError extends Error {\n readonly name = \"AiCostStorageError\"\n\n constructor(\n readonly code: AiCostStorageErrorCode,\n message: string\n ) {\n super(message)\n }\n}\n",
9
9
  "import type { AiModelCallUsageRecord, InMemoryAiUsageStorageSnapshot } from \"../ai-usage\"\nimport type { AiAccountingRecordSetItem } from \"./analytics\"\nimport { buildAiAccountingOverview, buildAiModelCallAccountingList } from \"./analytics\"\nimport { AiCostStorageError } from \"./errors\"\nimport { type AiAccountingGroupIdentity, buildAiModelCallGroups } from \"./groups\"\nimport type {\n AiAccountingAttribution,\n AiAccountingOverview,\n AiCostStorage,\n AiCostSummary,\n AiModelCallCostRecord,\n AiMoney,\n ListAiModelCallAccountingInput,\n ListAiModelCallAccountingResult,\n ListAiModelCallGroupsInput,\n ListAiModelCallGroupsResult,\n QueryAiAccountingOverviewInput,\n SummarizeAiCostExecutionsInput,\n} from \"./types\"\nimport { aiModelCallCostMatchesUsage, normalizeAiModelCallCostRecord } from \"./validation\"\n\nexport interface InMemoryAiCostStorageSnapshot {\n readonly recordsByUsage: Map<string, AiModelCallCostRecord>\n}\n\ninterface InMemoryAiCostUsageSource {\n snapshot(): InMemoryAiUsageStorageSnapshot\n}\n\nexport interface InMemoryAiAccountingAttributionSource {\n resolveGroup?(input: {\n readonly projectId: string\n readonly executionId: string\n }): Promise<{ readonly executionId: string; readonly attribution?: AiAccountingAttribution }>\n resolve(input: {\n readonly projectId: string\n readonly executionId: string\n }): Promise<AiAccountingAttribution | undefined>\n}\n\n/** In-memory immutable model-call costs and accounting reads. */\nexport class InMemoryAiCostStorage implements AiCostStorage {\n private readonly recordsByUsage = new Map<string, AiModelCallCostRecord>()\n\n constructor(\n private readonly usage: InMemoryAiCostUsageSource,\n private readonly attribution?: InMemoryAiAccountingAttributionSource\n ) {}\n\n async recordModelCallCost(input: AiModelCallCostRecord): Promise<void> {\n const record = normalizeAiModelCallCostRecord(input)\n const usage = this.usageRecord(record.projectId, record.usageRecordId)\n if (!usage) throw missingUsage(record)\n if (!aiModelCallCostMatchesUsage(record, usage)) {\n throw new AiCostStorageError(\n \"cost_mismatch\",\n `[Sixb] AI valuation for usage '${record.usageRecordId}' does not match its usage record.`\n )\n }\n const key = usageRecordKey(record.projectId, record.usageRecordId)\n if (!this.recordsByUsage.has(key)) this.recordsByUsage.set(key, structuredClone(record))\n }\n\n async summarizeExecutions(\n input: SummarizeAiCostExecutionsInput\n ): Promise<readonly AiCostSummary[]> {\n assertNonBlank(input.projectId, \"cost summary projectId\")\n for (const id of input.executionIds) assertNonBlank(id, \"cost summary executionId\")\n const requested = new Set(input.executionIds)\n const usageByExecution = new Map(input.executionIds.map((id) => [id, [] as string[]]))\n for (const usage of this.usage.snapshot().records.values()) {\n if (usage.projectId === input.projectId && requested.has(usage.executionId)) {\n usageByExecution.get(usage.executionId)!.push(usage.id)\n }\n }\n return input.executionIds.map((id) =>\n this.summarizeUsageIds(input.projectId, usageByExecution.get(id) ?? [])\n )\n }\n\n async queryProjectOverview(input: QueryAiAccountingOverviewInput): Promise<AiAccountingOverview> {\n return buildAiAccountingOverview(input, await this.accountingItems())\n }\n\n async listModelCalls(\n input: ListAiModelCallAccountingInput\n ): Promise<ListAiModelCallAccountingResult> {\n return buildAiModelCallAccountingList(input, await this.accountingItems())\n }\n\n snapshot(): InMemoryAiCostStorageSnapshot {\n return structuredClone({ recordsByUsage: this.recordsByUsage })\n }\n\n async listModelCallGroups(\n input: ListAiModelCallGroupsInput\n ): Promise<ListAiModelCallGroupsResult> {\n const items = await this.accountingItems()\n const roots = new Map<string, Promise<AiAccountingGroupIdentity>>()\n return buildAiModelCallGroups(\n input,\n await Promise.all(\n items.map(async (item) => {\n const key = usageRecordKey(item.usage.projectId, item.usage.executionId)\n let root = roots.get(key)\n if (!root) {\n root =\n this.attribution?.resolveGroup?.({\n projectId: item.usage.projectId,\n executionId: item.usage.executionId,\n }) ??\n Promise.resolve({\n executionId: item.usage.executionId,\n attribution: item.attribution,\n })\n roots.set(key, root)\n }\n return { ...item, root: await root }\n })\n )\n )\n }\n\n restore(snapshot: InMemoryAiCostStorageSnapshot): void {\n replaceMap(this.recordsByUsage, snapshot.recordsByUsage)\n }\n\n /** @internal Immutable accounting source used by in-memory AI limit enforcement. */\n getRecord(projectId: string, usageRecordId: string): AiModelCallCostRecord | null {\n const record = this.recordsByUsage.get(usageRecordKey(projectId, usageRecordId))\n return record ? structuredClone(record) : null\n }\n\n private usageRecord(projectId: string, id: string): AiModelCallUsageRecord | undefined {\n return [...this.usage.snapshot().records.values()].find(\n (record) => record.projectId === projectId && record.id === id\n )\n }\n\n private async accountingItems(): Promise<readonly AiAccountingRecordSetItem[]> {\n return Promise.all(\n [...this.usage.snapshot().records.values()].map(async (usage) => {\n const cost = this.recordsByUsage.get(usageRecordKey(usage.projectId, usage.id))\n const attribution = await this.attribution?.resolve({\n projectId: usage.projectId,\n executionId: usage.executionId,\n })\n return {\n usage,\n ...(attribution ? { attribution } : {}),\n ...(cost ? { cost } : {}),\n }\n })\n )\n }\n\n private summarizeUsageIds(projectId: string, ids: readonly string[]): AiCostSummary {\n const amounts = new Map<string, bigint>()\n let ratedCallCount = 0\n let unpriceableCallCount = 0\n let unvaluedCallCount = 0\n for (const id of ids) {\n const cost = this.recordsByUsage.get(usageRecordKey(projectId, id))\n if (!cost) unvaluedCallCount += 1\n else if (cost.status === \"unpriceable\") unpriceableCallCount += 1\n else {\n ratedCallCount += 1\n addMoney(amounts, cost.money)\n }\n }\n return {\n amounts: [...amounts]\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([currency, amount]) => ({ currency, amountNanos: amount.toString() })),\n ratedCallCount,\n unpriceableCallCount,\n unvaluedCallCount,\n }\n }\n}\n\nfunction missingUsage(record: { readonly projectId: string; readonly usageRecordId: string }) {\n return new AiCostStorageError(\n \"missing_usage\",\n `[Sixb] AI usage '${record.usageRecordId}' does not exist in project '${record.projectId}'.`\n )\n}\n\nfunction addMoney(amounts: Map<string, bigint>, money: AiMoney): void {\n amounts.set(money.currency, (amounts.get(money.currency) ?? 0n) + BigInt(money.amountNanos))\n}\n\nfunction usageRecordKey(projectId: string, id: string): string {\n return JSON.stringify([projectId, id])\n}\n\nfunction assertNonBlank(value: string, field: string): void {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new TypeError(`[Sixb] AI ${field} must be nonblank.`)\n }\n}\n\nfunction replaceMap<TKey, TValue>(target: Map<TKey, TValue>, source: Map<TKey, TValue>): void {\n target.clear()\n for (const [key, value] of structuredClone(source)) target.set(key, value)\n}\n",
@@ -1,15 +1,16 @@
1
1
  // @bun
2
+ import {
3
+ createSixbError2
4
+ } from "./chunk-6fsr7y93.js";
2
5
  import {
3
6
  resolveRuntimeAuthorizationForProject,
4
7
  AuthorizationError2,
5
8
  assertAuthorized2,
6
9
  assertCanEdit2,
7
10
  assertCanAppendTelemetry2
8
- } from "./chunk-5be2ath4.js";
9
- import {
10
- createSixbError2
11
- } from "./chunk-6fsr7y93.js";
11
+ } from "./chunk-qkbx3tf6.js";
12
12
  import {
13
+ assertValidFileRefs2,
13
14
  normalizeObjectProperties2,
14
15
  assertPropertyTokenBelongsToObjectType2,
15
16
  assertLinkTokenBelongsToObjectType2,
@@ -19,7 +20,7 @@ import {
19
20
  normalizeLinkProperties2,
20
21
  validateLinkProperties2,
21
22
  assertTelemetryProperty2
22
- } from "./chunk-rpxz486p.js";
23
+ } from "./chunk-y05543x6.js";
23
24
  import {
24
25
  linkRefKey2,
25
26
  telemetryPointKey2
@@ -29,27 +30,32 @@ import {
29
30
  vectorConfiguration,
30
31
  vectorSources,
31
32
  normalizeVector2
32
- } from "./chunk-5yd8cchh.js";
33
+ } from "./chunk-qq90g05n.js";
33
34
  import {
34
35
  validateObjectQuery2,
35
36
  explainObjectQuery2
36
- } from "./chunk-pja9jfz6.js";
37
+ } from "./chunk-htr6wjmv.js";
37
38
  import {
38
39
  assertAuthorizedObjectReaderBinding,
39
40
  getAuthorizedOntologyView,
40
41
  requestAction3,
41
42
  requestActionAndWait2
42
- } from "./chunk-10styjgk.js";
43
+ } from "./chunk-fx93hd2n.js";
43
44
  import {
44
45
  shareSixbErrorReporter2
45
46
  } from "./chunk-vjcd8d27.js";
46
47
  import {
47
48
  normalizeJsonProperties2
48
- } from "./chunk-fggq3d9k.js";
49
+ } from "./chunk-p0dqwj3n.js";
49
50
  import {
50
51
  getOntologyMutationRuntime2,
51
52
  shareOntologyMutationRuntime2
52
53
  } from "./chunk-85cd7e8c.js";
54
+ import {
55
+ resolveFileRefAtPath2,
56
+ openFileRef2,
57
+ jsonPointerSegment2
58
+ } from "./chunk-3zxk45er.js";
53
59
  import {
54
60
  createObjectQueryBuilder2
55
61
  } from "./chunk-ewqa58h9.js";
@@ -58,7 +64,7 @@ import {
58
64
  } from "./chunk-kpx7jrmn.js";
59
65
  import {
60
66
  ObjectNotFoundError2
61
- } from "./chunk-aq39q04r.js";
67
+ } from "./chunk-y9jmd7e5.js";
62
68
  import {
63
69
  MaterializationValidationError2,
64
70
  MaterializationObjectNotFoundError2
@@ -166,6 +172,7 @@ function normalizeRuntimeObject(input) {
166
172
  const { objectType, primaryPropertyId, properties, valueTypesById } = input;
167
173
  assertKnownProperties2(objectType, properties);
168
174
  validateObjectProperties2(objectType, properties, valueTypesById);
175
+ assertValidFileRefs2(properties, objectType.id);
169
176
  const primaryValue = properties[primaryPropertyId];
170
177
  if (primaryValue === undefined || primaryValue === null) {
171
178
  throw new OntologyValidationError2(`[Sixb] Missing primary property '${primaryPropertyId}' in upsert for '${objectType.id}'`);
@@ -181,6 +188,7 @@ function normalizeRuntimeLink(input) {
181
188
  const { objectType, linkDefinition, linkId, targetTypeId, properties, valueTypesById } = input;
182
189
  assertLinkTargetType2(objectType.id, linkId, linkDefinition, targetTypeId, input.isValidLinkTarget);
183
190
  validateLinkProperties2(objectType, linkDefinition, properties, undefined, valueTypesById);
191
+ assertValidFileRefs2(properties, `${objectType.id}.${linkId}`);
184
192
  const normalized = normalizeLinkProperties2(objectType, linkDefinition, properties, valueTypesById);
185
193
  if (normalized === undefined)
186
194
  return;
@@ -469,7 +477,7 @@ async function upsertObject2(ctx, properties) {
469
477
  const commit = await commitRuntimeOperations(ctx, [
470
478
  objectUpsertOperation({ id: runtimeOperationId(0), ref, properties: normalized.properties })
471
479
  ]);
472
- return toObjectRow(ctx.projectId, requireEffectiveObject(commit.outcomes[0]));
480
+ return ctx.objectReader.redactWrittenRow(toObjectRow(ctx.projectId, requireEffectiveObject(commit.outcomes[0])));
473
481
  }
474
482
 
475
483
  // src/objects/object/upsert-batch.ts
@@ -501,7 +509,7 @@ async function upsertObjectBatch2(ctx, items) {
501
509
  ]
502
510
  };
503
511
  },
504
- value: ([outcome]) => toObjectRow(ctx.projectId, requireEffectiveObject(outcome))
512
+ value: ([outcome]) => ctx.objectReader.redactWrittenRow(toObjectRow(ctx.projectId, requireEffectiveObject(outcome)))
505
513
  });
506
514
  }
507
515
  // src/objects/telemetry/write-batch.ts
@@ -842,6 +850,48 @@ function createObjectVectorHandle(ctx, primaryId, profileName) {
842
850
  });
843
851
  }
844
852
 
853
+ // src/objects/sdk/file-handle.ts
854
+ function createObjectFileHandle(ctx, primaryId, property, index) {
855
+ const { objectType } = ctx;
856
+ assertPropertyTokenBelongsToObjectType2(objectType, property);
857
+ const registered = ctx.ontology.resolveObjectType(objectType.id).properties.find((candidate) => candidate.id === property.id);
858
+ if (!registered) {
859
+ throw new OntologyValidationError2(`[Sixb] Unknown property '${property.id}' for object type '${objectType.id}'`);
860
+ }
861
+ const path = filePropertyPath(objectType.id, registered, index);
862
+ return {
863
+ async open() {
864
+ const row = await ctx.objectReader.getByPrimaryId({ objectTypeId: objectType.id, primaryId });
865
+ if (!row)
866
+ return null;
867
+ if (row.redactions?.[property.id]) {
868
+ const markings = registered.markings ?? [];
869
+ const marking = markings.find((markingId) => !ctx.authorization?.clearances?.has(markingId)) ?? markings[0];
870
+ throw new AuthorizationError2(`clearance:marking:${marking}`, `[Sixb] Cannot open file '${objectType.id}.${property.id}': it requires clearance for marking '${marking}'.`);
871
+ }
872
+ const fileRef = resolveFileRefAtPath2(row, path);
873
+ return fileRef ? openFileRef2(ctx.blobStorage, fileRef) : null;
874
+ }
875
+ };
876
+ }
877
+ function filePropertyPath(objectTypeId, property, index) {
878
+ const { schema } = property;
879
+ const name = `${objectTypeId}.${property.id}`;
880
+ if (schema === "fileRef") {
881
+ if (index !== undefined) {
882
+ throw new OntologyValidationError2(`[Sixb] Property ${name} holds one file; omit the index.`);
883
+ }
884
+ return `/properties/${jsonPointerSegment2(property.id)}`;
885
+ }
886
+ if (typeof schema === "object" && schema.type === "array" && schema.items === "fileRef") {
887
+ if (index === undefined || !Number.isSafeInteger(index) || index < 0) {
888
+ throw new OntologyValidationError2(`[Sixb] Property ${name} holds a list of files; pass the index of the file to open.`);
889
+ }
890
+ return `/properties/${jsonPointerSegment2(property.id)}/${index}`;
891
+ }
892
+ throw new OntologyValidationError2(`[Sixb] Property ${name} is not a file: file() takes a "fileRef" property or a list of them.`);
893
+ }
894
+
845
895
  // src/objects/sdk/telemetry-channel.ts
846
896
  function createTelemetryChannel(ctx, primaryId) {
847
897
  return (property) => {
@@ -969,7 +1019,8 @@ function createObjectByIdHandle(ctx, primaryId) {
969
1019
  }
970
1020
  });
971
1021
  },
972
- telemetry: createTelemetryChannel(ctx, primaryId)
1022
+ telemetry: createTelemetryChannel(ctx, primaryId),
1023
+ file: (property, index) => createObjectFileHandle(ctx, primaryId, property, index)
973
1024
  };
974
1025
  return objectHandle;
975
1026
  }
@@ -1069,6 +1120,7 @@ function createObjectSet2(params) {
1069
1120
  runtimeAuthorization,
1070
1121
  authorization,
1071
1122
  execution,
1123
+ blobStorage: params.blobStorage,
1072
1124
  objectType,
1073
1125
  primaryPropertyId
1074
1126
  };
@@ -1274,4 +1326,4 @@ async function appendTelemetry(runtime, objectTypeId, items) {
1274
1326
  }
1275
1327
  export { requestAction2, ObjectError2, removeLink2, upsertLink2, upsertLinkBatch2, deleteObject2, restoreObject2, upsertObject2, upsertObjectBatch2, writeTelemetryBatch2, appendTelemetryBatch2, getTelemetryHistoryBatch2, getLatestTelemetryPoint, requireLinkDefinition2, resolveObjectContext2, resolveLinkContext2, createObjectSet2, upsertLink3, upsertLinkBatch3, removeLink3, listObjects, upsertObject3, upsertObjectBatch3, appendTelemetry, exports_service };
1276
1328
 
1277
- //# debugId=85F4AA13E1233E8364756E2164756E21
1329
+ //# debugId=90347800675626DB64756E2164756E21