@sixb/core 0.1.15 → 0.1.17

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 (585) hide show
  1. package/dist/actions/index.js +25 -25
  2. package/dist/actions/types/context.d.ts +2 -2
  3. package/dist/actions/types/context.d.ts.map +1 -1
  4. package/dist/actions/worker.js +1 -1
  5. package/dist/agents/index.js +41 -40
  6. package/dist/agents/index.js.map +1 -1
  7. package/dist/auth/index.js +5 -5
  8. package/dist/authorization/index.js +2 -2
  9. package/dist/blob-storage/download-urls.d.ts +41 -0
  10. package/dist/blob-storage/download-urls.d.ts.map +1 -0
  11. package/dist/blob-storage/execution.d.ts +9 -1
  12. package/dist/blob-storage/execution.d.ts.map +1 -1
  13. package/dist/blob-storage/index.js +5 -3
  14. package/dist/blob-storage/index.js.map +1 -1
  15. package/dist/blob-storage/internal.d.ts +2 -0
  16. package/dist/blob-storage/internal.d.ts.map +1 -0
  17. package/dist/blob-storage/internal.js +11 -0
  18. package/dist/blob-storage/internal.js.map +9 -0
  19. package/dist/bootstrap/index.js +45 -44
  20. package/dist/bootstrap/index.js.map +1 -1
  21. package/dist/{chunk-wem5vqjw.js → chunk-10styjgk.js} +18 -13
  22. package/dist/{chunk-wem5vqjw.js.map → chunk-10styjgk.js.map} +3 -3
  23. package/dist/{chunk-hgqpcmyr.js → chunk-1hqwggsn.js} +47 -19
  24. package/dist/chunk-1hqwggsn.js.map +12 -0
  25. package/dist/{chunk-q3grgzp1.js → chunk-23xs4qp9.js} +2 -2
  26. package/dist/{chunk-vef6qa14.js → chunk-2am3db31.js} +2 -2
  27. package/dist/{chunk-fj1dvp37.js → chunk-2vhg6ysa.js} +1 -1
  28. package/dist/{chunk-p0nbkys4.js → chunk-33saed7g.js} +1 -1
  29. package/dist/{chunk-mdnw7nj8.js → chunk-3rrezgyc.js} +33 -8
  30. package/dist/chunk-3rrezgyc.js.map +15 -0
  31. package/dist/{chunk-jgwb25gc.js → chunk-4as3wt1c.js} +13 -5
  32. package/dist/chunk-4as3wt1c.js.map +12 -0
  33. package/dist/chunk-4ra628t7.js +88 -0
  34. package/dist/chunk-4ra628t7.js.map +10 -0
  35. package/dist/{chunk-mmac1mp6.js → chunk-52c5zb0z.js} +2 -2
  36. package/dist/{chunk-8fjmqjyx.js → chunk-5be2ath4.js} +1 -1
  37. package/dist/{chunk-2fv8sajb.js → chunk-5thzcb8g.js} +2 -2
  38. package/dist/{chunk-fjw417jf.js → chunk-5yd8cchh.js} +1143 -784
  39. package/dist/chunk-5yd8cchh.js.map +66 -0
  40. package/dist/{chunk-2tz5vnvz.js → chunk-6wbm6ymz.js} +235 -41
  41. package/dist/{chunk-2tz5vnvz.js.map → chunk-6wbm6ymz.js.map} +8 -6
  42. package/dist/{chunk-py2dw8cw.js → chunk-7ecp4v7a.js} +26 -19
  43. package/dist/chunk-7ecp4v7a.js.map +17 -0
  44. package/dist/{chunk-f85hpqnm.js → chunk-99nd4rc1.js} +3 -3
  45. package/dist/{chunk-f85hpqnm.js.map → chunk-99nd4rc1.js.map} +3 -3
  46. package/dist/{chunk-1jvq82rp.js → chunk-9g6jz9kk.js} +5 -5
  47. package/dist/{chunk-39tqv9hz.js → chunk-9se093qz.js} +5 -6
  48. package/dist/{chunk-39tqv9hz.js.map → chunk-9se093qz.js.map} +3 -4
  49. package/dist/{chunk-8w27xf9e.js → chunk-a7er86jd.js} +1 -1
  50. package/dist/{chunk-zdkcdshk.js → chunk-aq39q04r.js} +41 -3
  51. package/dist/{chunk-zdkcdshk.js.map → chunk-aq39q04r.js.map} +4 -3
  52. package/dist/chunk-b9affek3.js +261 -0
  53. package/dist/chunk-b9affek3.js.map +12 -0
  54. package/dist/{chunk-bxx3ms5t.js → chunk-c2rga5cx.js} +2 -2
  55. package/dist/{chunk-dsfw1bdr.js → chunk-cnb5kv05.js} +2 -2
  56. package/dist/chunk-d62kjtbg.js.map +2 -2
  57. package/dist/{chunk-dqkd3kdj.js → chunk-dam456ve.js} +234 -35
  58. package/dist/{chunk-dqkd3kdj.js.map → chunk-dam456ve.js.map} +7 -5
  59. package/dist/{chunk-n5t4mq6z.js → chunk-e67ynxcr.js} +3 -3
  60. package/dist/{chunk-xnx96gfy.js → chunk-ere85b8y.js} +17 -8
  61. package/dist/chunk-ere85b8y.js.map +15 -0
  62. package/dist/{chunk-k4kkp58d.js → chunk-ewqa58h9.js} +12 -2
  63. package/dist/chunk-ewqa58h9.js.map +11 -0
  64. package/dist/{chunk-6q7c68yx.js → chunk-f1xh7a32.js} +3 -3
  65. package/dist/{chunk-z708gemf.js → chunk-fggq3d9k.js} +450 -799
  66. package/dist/chunk-fggq3d9k.js.map +49 -0
  67. package/dist/{chunk-7jc21943.js → chunk-gf7yht60.js} +4 -4
  68. package/dist/chunk-h8teetr0.js +9 -0
  69. package/dist/chunk-h8teetr0.js.map +10 -0
  70. package/dist/chunk-hn2r7z41.js.map +1 -1
  71. package/dist/{chunk-ffwvdgk1.js → chunk-jjrn5v0p.js} +1 -1
  72. package/dist/{chunk-r5sc1d2b.js → chunk-jnfxmr3f.js} +1 -1
  73. package/dist/{chunk-y0zmae99.js → chunk-k4g51s47.js} +3 -3
  74. package/dist/{chunk-a0073121.js → chunk-kpx7jrmn.js} +3 -1
  75. package/dist/chunk-kpx7jrmn.js.map +12 -0
  76. package/dist/{chunk-p1683c0v.js → chunk-kyjcwqz6.js} +5 -2
  77. package/dist/{chunk-p1683c0v.js.map → chunk-kyjcwqz6.js.map} +3 -3
  78. package/dist/{chunk-3c90jvfj.js → chunk-pja9jfz6.js} +742 -583
  79. package/dist/chunk-pja9jfz6.js.map +19 -0
  80. package/dist/chunk-pqajwytd.js.map +1 -1
  81. package/dist/{chunk-mr60an99.js → chunk-qczk96d9.js} +22 -2
  82. package/dist/{chunk-mr60an99.js.map → chunk-qczk96d9.js.map} +3 -3
  83. package/dist/{chunk-s3csryxe.js → chunk-rj69qcrd.js} +8 -2
  84. package/dist/chunk-rj69qcrd.js.map +11 -0
  85. package/dist/{chunk-d8yes9yx.js → chunk-rpxz486p.js} +32 -5
  86. package/dist/{chunk-d8yes9yx.js.map → chunk-rpxz486p.js.map} +4 -4
  87. package/dist/{chunk-drz59ve0.js → chunk-rx7h5fdx.js} +1 -1
  88. package/dist/{chunk-ky7zpbtt.js → chunk-s7ftxrdr.js} +106 -8
  89. package/dist/chunk-s7ftxrdr.js.map +22 -0
  90. package/dist/{chunk-yfppyaty.js → chunk-sk0hcjsz.js} +1 -1
  91. package/dist/{chunk-qne45xqq.js → chunk-svabwqdq.js} +2 -2
  92. package/dist/{chunk-xr7y35yj.js → chunk-t9shqx3w.js} +2 -2
  93. package/dist/{chunk-4jph1t3v.js → chunk-tjjgy3z4.js} +27 -24
  94. package/dist/{chunk-4jph1t3v.js.map → chunk-tjjgy3z4.js.map} +4 -4
  95. package/dist/{chunk-ex8s8wsk.js → chunk-vp3z1ckh.js} +42 -10
  96. package/dist/{chunk-ex8s8wsk.js.map → chunk-vp3z1ckh.js.map} +7 -6
  97. package/dist/{chunk-adbve9zt.js → chunk-vre348sb.js} +2 -2
  98. package/dist/{chunk-a4g5yjm0.js → chunk-w9yycd3t.js} +1 -1
  99. package/dist/{chunk-g4rbm4a6.js → chunk-wt4szfec.js} +379 -331
  100. package/dist/chunk-wt4szfec.js.map +14 -0
  101. package/dist/{chunk-wd34wnsy.js → chunk-xcy5ddha.js} +6 -6
  102. package/dist/{chunk-3nx8vj5a.js → chunk-xyvy73tj.js} +5 -3
  103. package/dist/chunk-xyvy73tj.js.map +12 -0
  104. package/dist/datasets/write.js +1 -1
  105. package/dist/execution/agent.js +38 -37
  106. package/dist/execution/agent.js.map +1 -1
  107. package/dist/execution/authorized-object-reader.d.ts +3 -1
  108. package/dist/execution/authorized-object-reader.d.ts.map +1 -1
  109. package/dist/execution/primitive.js +36 -35
  110. package/dist/execution/primitive.js.map +2 -2
  111. package/dist/execution/request.js +37 -36
  112. package/dist/execution/request.js.map +2 -2
  113. package/dist/index.d.ts +8 -4
  114. package/dist/index.d.ts.map +1 -1
  115. package/dist/index.js +62 -59
  116. package/dist/index.js.map +1 -1
  117. package/dist/lake-storage/in-memory.d.ts +5 -1
  118. package/dist/lake-storage/in-memory.d.ts.map +1 -1
  119. package/dist/lake-storage/index.d.ts +1 -1
  120. package/dist/lake-storage/index.d.ts.map +1 -1
  121. package/dist/lake-storage/index.js +2 -2
  122. package/dist/lake-storage/types.d.ts +26 -0
  123. package/dist/lake-storage/types.d.ts.map +1 -1
  124. package/dist/maintenance/ontology-maintenance.d.ts +5 -1
  125. package/dist/maintenance/ontology-maintenance.d.ts.map +1 -1
  126. package/dist/maintenance/types.d.ts +1 -4
  127. package/dist/maintenance/types.d.ts.map +1 -1
  128. package/dist/materialization/event-envelopes.d.ts +20 -0
  129. package/dist/materialization/event-envelopes.d.ts.map +1 -0
  130. package/dist/materialization/events.d.ts +29 -3
  131. package/dist/materialization/events.d.ts.map +1 -1
  132. package/dist/materialization/index.d.ts +4 -1
  133. package/dist/materialization/index.d.ts.map +1 -1
  134. package/dist/materialization/index.js +9 -3
  135. package/dist/materialization/index.js.map +1 -1
  136. package/dist/materializer/edits/plan.d.ts +2 -10
  137. package/dist/materializer/edits/plan.d.ts.map +1 -1
  138. package/dist/materializer/effective/build-events.d.ts +5 -21
  139. package/dist/materializer/effective/build-events.d.ts.map +1 -1
  140. package/dist/materializer/effective/vector-indexing.d.ts +2 -3
  141. package/dist/materializer/effective/vector-indexing.d.ts.map +1 -1
  142. package/dist/materializer/effective/vectors.d.ts +2 -3
  143. package/dist/materializer/effective/vectors.d.ts.map +1 -1
  144. package/dist/materializer/execution/scope.d.ts +1 -11
  145. package/dist/materializer/execution/scope.d.ts.map +1 -1
  146. package/dist/materializer/execution/work-executor.d.ts +5 -7
  147. package/dist/materializer/execution/work-executor.d.ts.map +1 -1
  148. package/dist/materializer/execution/work-records.d.ts +1 -3
  149. package/dist/materializer/execution/work-records.d.ts.map +1 -1
  150. package/dist/materializer/index.js +31 -32
  151. package/dist/materializer/index.js.map +1 -1
  152. package/dist/materializer/projections/replace.d.ts.map +1 -1
  153. package/dist/materializer/projections/replacement-plan.d.ts +8 -11
  154. package/dist/materializer/projections/replacement-plan.d.ts.map +1 -1
  155. package/dist/materializer/shared/batching.d.ts +5 -0
  156. package/dist/materializer/shared/batching.d.ts.map +1 -1
  157. package/dist/materializer/telemetry/plan.d.ts +2 -8
  158. package/dist/materializer/telemetry/plan.d.ts.map +1 -1
  159. package/dist/models/audio/catalog.d.ts +20 -0
  160. package/dist/models/audio/catalog.d.ts.map +1 -0
  161. package/dist/models/audio/errors.d.ts +8 -0
  162. package/dist/models/audio/errors.d.ts.map +1 -0
  163. package/dist/models/audio/file.d.ts +9 -0
  164. package/dist/models/audio/file.d.ts.map +1 -0
  165. package/dist/models/audio/runtime.d.ts +8 -0
  166. package/dist/models/audio/runtime.d.ts.map +1 -0
  167. package/dist/models/audio/types.d.ts +60 -0
  168. package/dist/models/audio/types.d.ts.map +1 -0
  169. package/dist/models/catalog.d.ts +23 -1
  170. package/dist/models/catalog.d.ts.map +1 -1
  171. package/dist/models/definitions.d.ts +1 -1
  172. package/dist/models/definitions.d.ts.map +1 -1
  173. package/dist/models/embedding-model.d.ts +4 -0
  174. package/dist/models/embedding-model.d.ts.map +1 -1
  175. package/dist/models/events.d.ts +3 -0
  176. package/dist/models/events.d.ts.map +1 -1
  177. package/dist/models/execution/index.js +22 -22
  178. package/dist/models/execution/model-call-admission.d.ts +6 -1
  179. package/dist/models/execution/model-call-admission.d.ts.map +1 -1
  180. package/dist/models/execution/model-call-limits.d.ts.map +1 -1
  181. package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
  182. package/dist/models/execution/reranking.d.ts +4 -0
  183. package/dist/models/execution/reranking.d.ts.map +1 -0
  184. package/dist/models/execution/usage.d.ts.map +1 -1
  185. package/dist/models/execution.d.ts +2 -1
  186. package/dist/models/execution.d.ts.map +1 -1
  187. package/dist/models/generation-types.d.ts +2 -0
  188. package/dist/models/generation-types.d.ts.map +1 -1
  189. package/dist/models/index.d.ts +7 -1
  190. package/dist/models/index.d.ts.map +1 -1
  191. package/dist/models/index.js +7 -3
  192. package/dist/models/index.js.map +1 -1
  193. package/dist/models/pricing.d.ts +2 -2
  194. package/dist/models/pricing.d.ts.map +1 -1
  195. package/dist/models/reranking-model.d.ts +49 -0
  196. package/dist/models/reranking-model.d.ts.map +1 -0
  197. package/dist/objects/index.js +25 -25
  198. package/dist/objects/query/executor.d.ts +2 -1
  199. package/dist/objects/query/executor.d.ts.map +1 -1
  200. package/dist/objects/query/index.d.ts +1 -1
  201. package/dist/objects/query/index.d.ts.map +1 -1
  202. package/dist/objects/query/index.js +24 -24
  203. package/dist/objects/query/index.js.map +1 -1
  204. package/dist/objects/query/ir.d.ts +8 -1
  205. package/dist/objects/query/ir.d.ts.map +1 -1
  206. package/dist/objects/query/normalize.d.ts.map +1 -1
  207. package/dist/objects/query/planner.d.ts +1 -1
  208. package/dist/objects/query/planner.d.ts.map +1 -1
  209. package/dist/objects/query/primary-id.d.ts +7 -0
  210. package/dist/objects/query/primary-id.d.ts.map +1 -0
  211. package/dist/objects/query/reranking-executor.d.ts +13 -0
  212. package/dist/objects/query/reranking-executor.d.ts.map +1 -0
  213. package/dist/objects/query/reranking-limits.d.ts +3 -0
  214. package/dist/objects/query/reranking-limits.d.ts.map +1 -0
  215. package/dist/objects/query/reranking-query.d.ts +4 -0
  216. package/dist/objects/query/reranking-query.d.ts.map +1 -0
  217. package/dist/objects/query/validate.d.ts.map +1 -1
  218. package/dist/objects/sdk/query-builder.d.ts +8 -0
  219. package/dist/objects/sdk/query-builder.d.ts.map +1 -1
  220. package/dist/objects/sdk/query-executor.d.ts +2 -2
  221. package/dist/objects/sdk/query-executor.d.ts.map +1 -1
  222. package/dist/objects/sdk/runtime-query-executor.d.ts.map +1 -1
  223. package/dist/objects/vectors/indexing-dispatch.d.ts +21 -0
  224. package/dist/objects/vectors/indexing-dispatch.d.ts.map +1 -0
  225. package/dist/objects/vectors/indexing-generate.d.ts.map +1 -1
  226. package/dist/objects/vectors/profile.d.ts.map +1 -1
  227. package/dist/objects/vectors/query.d.ts +1 -1
  228. package/dist/objects/vectors/query.d.ts.map +1 -1
  229. package/dist/objects/vectors/resolve-query.d.ts.map +1 -1
  230. package/dist/objects/vectors/types.d.ts +1 -1
  231. package/dist/objects/vectors/types.d.ts.map +1 -1
  232. package/dist/ontology/builders.d.ts +13 -4
  233. package/dist/ontology/builders.d.ts.map +1 -1
  234. package/dist/ontology/index.d.ts +1 -1
  235. package/dist/ontology/index.d.ts.map +1 -1
  236. package/dist/ontology/index.js +3 -3
  237. package/dist/ontology/internal.js +2 -2
  238. package/dist/ontology/query-capabilities.d.ts +1 -0
  239. package/dist/ontology/query-capabilities.d.ts.map +1 -1
  240. package/dist/ontology/types.d.ts +20 -0
  241. package/dist/ontology/types.d.ts.map +1 -1
  242. package/dist/ontology/validation/query.d.ts.map +1 -1
  243. package/dist/ontology/vector-profiles.d.ts.map +1 -1
  244. package/dist/pipelines/index.js +23 -23
  245. package/dist/projections/internal.js +22 -22
  246. package/dist/query.d.ts +4 -2
  247. package/dist/query.d.ts.map +1 -1
  248. package/dist/query.js +2 -2
  249. package/dist/queues/in-memory.d.ts +3 -0
  250. package/dist/queues/in-memory.d.ts.map +1 -1
  251. package/dist/queues/index.js +1 -1
  252. package/dist/queues/types.d.ts +4 -0
  253. package/dist/queues/types.d.ts.map +1 -1
  254. package/dist/runtime/host.d.ts +1 -0
  255. package/dist/runtime/host.d.ts.map +1 -1
  256. package/dist/runtime/index.d.ts +1 -1
  257. package/dist/runtime/index.d.ts.map +1 -1
  258. package/dist/runtime/internal.d.ts +1 -0
  259. package/dist/runtime/internal.d.ts.map +1 -1
  260. package/dist/runtime/internal.js +28 -26
  261. package/dist/runtime/internal.js.map +1 -1
  262. package/dist/runtime/public-origin.d.ts +10 -0
  263. package/dist/runtime/public-origin.d.ts.map +1 -0
  264. package/dist/runtime/sixb.d.ts +1 -0
  265. package/dist/runtime/sixb.d.ts.map +1 -1
  266. package/dist/runtime/types.d.ts +12 -2
  267. package/dist/runtime/types.d.ts.map +1 -1
  268. package/dist/sandboxes/index.js +5 -5
  269. package/dist/shares/internal.js +19 -19
  270. package/dist/storage/agents/provider.js +2 -2
  271. package/dist/storage/ai-cost/analytics.d.ts +1 -0
  272. package/dist/storage/ai-cost/analytics.d.ts.map +1 -1
  273. package/dist/storage/ai-cost/provider.js +3 -3
  274. package/dist/storage/ai-cost/types.d.ts +1 -1
  275. package/dist/storage/ai-cost/types.d.ts.map +1 -1
  276. package/dist/storage/ai-cost/validation.d.ts.map +1 -1
  277. package/dist/storage/ai-limits/enforcement.js +2 -2
  278. package/dist/storage/ai-limits/in-memory.d.ts.map +1 -1
  279. package/dist/storage/ai-limits/provider.d.ts +7 -2
  280. package/dist/storage/ai-limits/provider.d.ts.map +1 -1
  281. package/dist/storage/ai-limits/provider.js +4 -2
  282. package/dist/storage/ai-limits/provider.js.map +1 -1
  283. package/dist/storage/ai-limits/types.d.ts +3 -0
  284. package/dist/storage/ai-limits/types.d.ts.map +1 -1
  285. package/dist/storage/ai-usage/record.d.ts.map +1 -1
  286. package/dist/storage/ai-usage/types.d.ts +8 -4
  287. package/dist/storage/ai-usage/types.d.ts.map +1 -1
  288. package/dist/storage/ai-usage/usage.d.ts.map +1 -1
  289. package/dist/storage/file-download-grants/in-memory.d.ts +11 -0
  290. package/dist/storage/file-download-grants/in-memory.d.ts.map +1 -0
  291. package/dist/storage/file-download-grants/index.d.ts +3 -0
  292. package/dist/storage/file-download-grants/index.d.ts.map +1 -0
  293. package/dist/storage/file-download-grants/record.d.ts +11 -0
  294. package/dist/storage/file-download-grants/record.d.ts.map +1 -0
  295. package/dist/storage/file-download-grants/types.d.ts +44 -0
  296. package/dist/storage/file-download-grants/types.d.ts.map +1 -0
  297. package/dist/storage/file-upload-sessions/provider.js +6 -6
  298. package/dist/storage/in-memory/index.d.ts +4 -0
  299. package/dist/storage/in-memory/index.d.ts.map +1 -1
  300. package/dist/storage/index.d.ts +5 -3
  301. package/dist/storage/index.d.ts.map +1 -1
  302. package/dist/storage/index.js +30 -30
  303. package/dist/storage/index.js.map +1 -1
  304. package/dist/storage/internal.d.ts +1 -0
  305. package/dist/storage/internal.d.ts.map +1 -1
  306. package/dist/storage/internal.js +8 -4
  307. package/dist/storage/internal.js.map +1 -1
  308. package/dist/storage/migrations/index.d.ts +1 -1
  309. package/dist/storage/migrations/index.d.ts.map +1 -1
  310. package/dist/storage/migrations/migrate-storage.d.ts +3 -3
  311. package/dist/storage/migrations/migrate-storage.d.ts.map +1 -1
  312. package/dist/storage/migrations/types.d.ts +7 -0
  313. package/dist/storage/migrations/types.d.ts.map +1 -1
  314. package/dist/storage/objects/in-memory/query.d.ts.map +1 -1
  315. package/dist/storage/objects/in-memory/selected-reader.d.ts.map +1 -1
  316. package/dist/storage/objects/in-memory/storage.d.ts.map +1 -1
  317. package/dist/storage/objects/query-preparation.d.ts +39 -0
  318. package/dist/storage/objects/query-preparation.d.ts.map +1 -0
  319. package/dist/storage/objects/types.d.ts +2 -0
  320. package/dist/storage/objects/types.d.ts.map +1 -1
  321. package/dist/storage/ontology/commits.d.ts +1 -6
  322. package/dist/storage/ontology/commits.d.ts.map +1 -1
  323. package/dist/storage/ontology/in-memory/index.d.ts +4 -2
  324. package/dist/storage/ontology/in-memory/index.d.ts.map +1 -1
  325. package/dist/storage/ontology/in-memory/materializations-state.d.ts +0 -2
  326. package/dist/storage/ontology/in-memory/materializations-state.d.ts.map +1 -1
  327. package/dist/storage/ontology/in-memory/materializations-work.d.ts +1 -3
  328. package/dist/storage/ontology/in-memory/materializations-work.d.ts.map +1 -1
  329. package/dist/storage/ontology/in-memory/materializations.d.ts +23 -57
  330. package/dist/storage/ontology/in-memory/materializations.d.ts.map +1 -1
  331. package/dist/storage/ontology/in-memory/outbox.d.ts +3 -2
  332. package/dist/storage/ontology/in-memory/outbox.d.ts.map +1 -1
  333. package/dist/storage/ontology/in-memory/replacement-plans.d.ts +104 -0
  334. package/dist/storage/ontology/in-memory/replacement-plans.d.ts.map +1 -0
  335. package/dist/storage/ontology/in-memory/shared-state.d.ts +17 -2
  336. package/dist/storage/ontology/in-memory/shared-state.d.ts.map +1 -1
  337. package/dist/storage/ontology/in-memory/source-roots.d.ts +3 -1
  338. package/dist/storage/ontology/in-memory/source-roots.d.ts.map +1 -1
  339. package/dist/storage/ontology/in-memory/sources.d.ts +1 -2
  340. package/dist/storage/ontology/in-memory/sources.d.ts.map +1 -1
  341. package/dist/storage/ontology/in-memory/state-reader.d.ts +25 -0
  342. package/dist/storage/ontology/in-memory/state-reader.d.ts.map +1 -0
  343. package/dist/storage/ontology/index.d.ts +6 -3
  344. package/dist/storage/ontology/index.d.ts.map +1 -1
  345. package/dist/storage/ontology/materializations.d.ts +40 -59
  346. package/dist/storage/ontology/materializations.d.ts.map +1 -1
  347. package/dist/storage/ontology/outbox.d.ts +4 -6
  348. package/dist/storage/ontology/outbox.d.ts.map +1 -1
  349. package/dist/storage/ontology/provider-work.d.ts +114 -3
  350. package/dist/storage/ontology/provider-work.d.ts.map +1 -1
  351. package/dist/storage/ontology/provider.d.ts +14 -39
  352. package/dist/storage/ontology/provider.d.ts.map +1 -1
  353. package/dist/storage/ontology/provider.js +26 -12
  354. package/dist/storage/ontology/provider.js.map +1 -1
  355. package/dist/storage/ontology/replacement-plans.d.ts +103 -0
  356. package/dist/storage/ontology/replacement-plans.d.ts.map +1 -0
  357. package/dist/storage/ontology/sources.d.ts +0 -8
  358. package/dist/storage/ontology/sources.d.ts.map +1 -1
  359. package/dist/storage/operation-scope.d.ts.map +1 -1
  360. package/dist/storage/operation-scope.js +1 -1
  361. package/dist/storage/projection-runs/in-memory.d.ts.map +1 -1
  362. package/dist/storage/projection-runs/types.d.ts +2 -0
  363. package/dist/storage/projection-runs/types.d.ts.map +1 -1
  364. package/dist/storage/types.d.ts +2 -0
  365. package/dist/storage/types.d.ts.map +1 -1
  366. package/dist/storage/workflow-runs/provider.js +6 -6
  367. package/dist/syncs/index.js +24 -24
  368. package/dist/testing/ai-cost-storage-contract.d.ts.map +1 -1
  369. package/dist/testing/ai-limit-storage-contract.d.ts.map +1 -1
  370. package/dist/testing/ai-usage-storage-contract.d.ts.map +1 -1
  371. package/dist/testing/file-download-grant-storage-contract.d.ts +9 -0
  372. package/dist/testing/file-download-grant-storage-contract.d.ts.map +1 -0
  373. package/dist/testing/index.d.ts +1 -0
  374. package/dist/testing/index.d.ts.map +1 -1
  375. package/dist/testing/index.js +2548 -1489
  376. package/dist/testing/index.js.map +14 -13
  377. package/dist/testing/lake-storage-contract.d.ts.map +1 -1
  378. package/dist/testing/materializer-storage-contract.d.ts +14 -0
  379. package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
  380. package/dist/testing/object-read-scope-contract.d.ts.map +1 -1
  381. package/dist/testing/ontology-contract-fixture.d.ts +5 -1
  382. package/dist/testing/ontology-contract-fixture.d.ts.map +1 -1
  383. package/dist/testing/ontology-storage-contract.d.ts.map +1 -1
  384. package/dist/testing/projection-run-storage-contract.d.ts.map +1 -1
  385. package/dist/testing/queues-contract.d.ts.map +1 -1
  386. package/dist/webhooks/internal.js +20 -20
  387. package/dist/workers/index.js +15 -17
  388. package/dist/workers/index.js.map +3 -3
  389. package/dist/workers/queue-worker.d.ts +3 -2
  390. package/dist/workers/queue-worker.d.ts.map +1 -1
  391. package/dist/workflows/index.js +42 -41
  392. package/dist/workflows/index.js.map +1 -1
  393. package/package.json +7 -1
  394. package/src/actions/types/context.ts +5 -2
  395. package/src/blob-storage/download-urls.ts +138 -0
  396. package/src/blob-storage/execution.ts +32 -1
  397. package/src/blob-storage/internal.ts +1 -0
  398. package/src/execution/authorized-object-reader.ts +8 -1
  399. package/src/index.ts +25 -0
  400. package/src/lake-storage/in-memory.ts +38 -9
  401. package/src/lake-storage/index.ts +2 -0
  402. package/src/lake-storage/types.ts +30 -0
  403. package/src/maintenance/ontology-maintenance.ts +50 -23
  404. package/src/maintenance/types.ts +1 -4
  405. package/src/materialization/event-envelopes.ts +168 -0
  406. package/src/materialization/events.ts +40 -4
  407. package/src/materialization/index.ts +9 -1
  408. package/src/materializer/README.md +55 -10
  409. package/src/materializer/edits/commit.ts +3 -19
  410. package/src/materializer/edits/plan.ts +20 -71
  411. package/src/materializer/effective/build-events.ts +42 -136
  412. package/src/materializer/effective/vector-indexing.ts +2 -3
  413. package/src/materializer/effective/vectors.ts +2 -3
  414. package/src/materializer/execution/scope.ts +1 -38
  415. package/src/materializer/execution/work-executor.ts +21 -115
  416. package/src/materializer/execution/work-records.ts +0 -15
  417. package/src/materializer/projections/replace.ts +106 -63
  418. package/src/materializer/projections/replacement-plan.ts +73 -218
  419. package/src/materializer/shared/batching.ts +7 -0
  420. package/src/materializer/telemetry/append.ts +2 -14
  421. package/src/materializer/telemetry/plan.ts +6 -43
  422. package/src/models/audio/catalog.ts +90 -0
  423. package/src/models/audio/errors.ts +19 -0
  424. package/src/models/audio/file.ts +78 -0
  425. package/src/models/audio/runtime.ts +182 -0
  426. package/src/models/audio/types.ts +69 -0
  427. package/src/models/catalog.ts +52 -5
  428. package/src/models/definitions.ts +8 -1
  429. package/src/models/embedding-model.ts +12 -0
  430. package/src/models/events.ts +3 -0
  431. package/src/models/execution/README.md +20 -1
  432. package/src/models/execution/embedding.ts +5 -1
  433. package/src/models/execution/model-call-admission.ts +6 -1
  434. package/src/models/execution/model-call-limits.ts +21 -11
  435. package/src/models/execution/model-call-recorder.ts +1 -0
  436. package/src/models/execution/model-call-recovery.ts +1 -0
  437. package/src/models/execution/reranking.ts +137 -0
  438. package/src/models/execution/usage.ts +1 -0
  439. package/src/models/execution.ts +5 -1
  440. package/src/models/generation-types.ts +2 -0
  441. package/src/models/index.ts +32 -0
  442. package/src/models/pricing.ts +2 -1
  443. package/src/models/reranking-model.ts +114 -0
  444. package/src/objects/query/executor.ts +42 -2
  445. package/src/objects/query/explain.ts +8 -0
  446. package/src/objects/query/index.ts +1 -0
  447. package/src/objects/query/ir.ts +10 -0
  448. package/src/objects/query/normalize.ts +2 -0
  449. package/src/objects/query/planner.ts +12 -1
  450. package/src/objects/query/primary-id.ts +56 -0
  451. package/src/objects/query/reranking-executor.ts +91 -0
  452. package/src/objects/query/reranking-limits.ts +3 -0
  453. package/src/objects/query/reranking-query.ts +8 -0
  454. package/src/objects/query/validate.ts +33 -10
  455. package/src/objects/sdk/query-builder.ts +15 -2
  456. package/src/objects/sdk/query-executor.ts +2 -2
  457. package/src/objects/sdk/runtime-query-executor.ts +7 -4
  458. package/src/objects/vectors/README.md +14 -2
  459. package/src/objects/vectors/handle.ts +1 -1
  460. package/src/objects/vectors/indexing-dispatch.ts +83 -0
  461. package/src/objects/vectors/indexing-generate.ts +5 -1
  462. package/src/objects/vectors/profile.ts +2 -0
  463. package/src/objects/vectors/query.ts +21 -4
  464. package/src/objects/vectors/resolve-query.ts +9 -5
  465. package/src/objects/vectors/types.ts +3 -1
  466. package/src/ontology/builders.ts +22 -7
  467. package/src/ontology/index.ts +2 -0
  468. package/src/ontology/query-capabilities.ts +1 -1
  469. package/src/ontology/types.ts +21 -0
  470. package/src/ontology/validation/query.ts +57 -0
  471. package/src/ontology/vector-profiles.ts +1 -0
  472. package/src/query.ts +4 -0
  473. package/src/queues/in-memory.ts +54 -19
  474. package/src/queues/types.ts +4 -0
  475. package/src/runtime/host.ts +28 -1
  476. package/src/runtime/index.ts +1 -0
  477. package/src/runtime/internal.ts +1 -0
  478. package/src/runtime/public-origin.ts +33 -0
  479. package/src/runtime/sixb.ts +13 -2
  480. package/src/runtime/types.ts +12 -2
  481. package/src/storage/ai-cost/analytics.ts +2 -0
  482. package/src/storage/ai-cost/codec.ts +2 -1
  483. package/src/storage/ai-cost/types.ts +1 -0
  484. package/src/storage/ai-cost/validation.ts +21 -8
  485. package/src/storage/ai-limits/in-memory.ts +10 -2
  486. package/src/storage/ai-limits/provider.ts +29 -2
  487. package/src/storage/ai-limits/types.ts +3 -0
  488. package/src/storage/ai-usage/record.ts +9 -0
  489. package/src/storage/ai-usage/types.ts +8 -4
  490. package/src/storage/ai-usage/usage.ts +2 -0
  491. package/src/storage/file-download-grants/in-memory.ts +73 -0
  492. package/src/storage/file-download-grants/index.ts +8 -0
  493. package/src/storage/file-download-grants/record.ts +47 -0
  494. package/src/storage/file-download-grants/types.ts +48 -0
  495. package/src/storage/in-memory/index.ts +13 -2
  496. package/src/storage/index.ts +31 -13
  497. package/src/storage/internal.ts +1 -0
  498. package/src/storage/migrations/index.ts +1 -0
  499. package/src/storage/migrations/migrate-storage.ts +36 -12
  500. package/src/storage/migrations/types.ts +8 -0
  501. package/src/storage/objects/in-memory/query.ts +2 -0
  502. package/src/storage/objects/in-memory/selected-reader.ts +1 -0
  503. package/src/storage/objects/in-memory/storage.ts +1 -0
  504. package/src/storage/objects/query-preparation.ts +77 -0
  505. package/src/storage/objects/types.ts +2 -0
  506. package/src/storage/ontology/commits.ts +1 -6
  507. package/src/storage/ontology/in-memory/index.ts +28 -9
  508. package/src/storage/ontology/in-memory/materializations-finalization.ts +35 -68
  509. package/src/storage/ontology/in-memory/materializations-state.ts +0 -22
  510. package/src/storage/ontology/in-memory/materializations-work.ts +0 -45
  511. package/src/storage/ontology/in-memory/materializations.ts +172 -653
  512. package/src/storage/ontology/in-memory/outbox.ts +37 -29
  513. package/src/storage/ontology/in-memory/replacement-plans.ts +697 -0
  514. package/src/storage/ontology/in-memory/shared-state.ts +24 -2
  515. package/src/storage/ontology/in-memory/source-roots.ts +7 -2
  516. package/src/storage/ontology/in-memory/sources.ts +7 -33
  517. package/src/storage/ontology/in-memory/state-reader.ts +245 -0
  518. package/src/storage/ontology/index.ts +19 -13
  519. package/src/storage/ontology/materializations.ts +45 -74
  520. package/src/storage/ontology/outbox.ts +4 -7
  521. package/src/storage/ontology/provider-header-validation.ts +0 -57
  522. package/src/storage/ontology/provider-work.ts +381 -90
  523. package/src/storage/ontology/provider.ts +74 -171
  524. package/src/storage/ontology/replacement-plans.ts +117 -0
  525. package/src/storage/ontology/sources.ts +0 -12
  526. package/src/storage/operation-scope.ts +33 -1
  527. package/src/storage/projection-runs/in-memory.ts +7 -1
  528. package/src/storage/projection-runs/types.ts +2 -0
  529. package/src/storage/types.ts +2 -0
  530. package/src/testing/ai-cost-storage-contract.ts +1 -0
  531. package/src/testing/ai-limit-storage-contract.ts +62 -0
  532. package/src/testing/ai-usage-storage-contract.ts +31 -0
  533. package/src/testing/file-download-grant-storage-contract.ts +139 -0
  534. package/src/testing/index.ts +4 -0
  535. package/src/testing/lake-storage-contract.ts +87 -1
  536. package/src/testing/materializer-storage-contract.ts +1008 -1
  537. package/src/testing/object-read-scope-contract.ts +1 -0
  538. package/src/testing/ontology-contract-fixture.ts +11 -87
  539. package/src/testing/ontology-storage-contract.ts +70 -39
  540. package/src/testing/projection-run-storage-contract.ts +14 -0
  541. package/src/testing/queues-contract.ts +59 -0
  542. package/src/workers/queue-worker.ts +19 -16
  543. package/dist/chunk-3c90jvfj.js.map +0 -15
  544. package/dist/chunk-3nx8vj5a.js.map +0 -12
  545. package/dist/chunk-7ytf06d3.js +0 -113
  546. package/dist/chunk-7ytf06d3.js.map +0 -10
  547. package/dist/chunk-a0073121.js.map +0 -12
  548. package/dist/chunk-fjw417jf.js.map +0 -62
  549. package/dist/chunk-g4rbm4a6.js.map +0 -15
  550. package/dist/chunk-hgqpcmyr.js.map +0 -12
  551. package/dist/chunk-jgwb25gc.js.map +0 -12
  552. package/dist/chunk-k4kkp58d.js.map +0 -11
  553. package/dist/chunk-ky7zpbtt.js.map +0 -19
  554. package/dist/chunk-mdnw7nj8.js.map +0 -15
  555. package/dist/chunk-py2dw8cw.js.map +0 -17
  556. package/dist/chunk-s3csryxe.js.map +0 -11
  557. package/dist/chunk-xnx96gfy.js.map +0 -15
  558. package/dist/chunk-z708gemf.js.map +0 -50
  559. package/dist/materializer/execution/plan-stream.d.ts +0 -8
  560. package/dist/materializer/execution/plan-stream.d.ts.map +0 -1
  561. package/src/materializer/execution/plan-stream.ts +0 -121
  562. /package/dist/{chunk-q3grgzp1.js.map → chunk-23xs4qp9.js.map} +0 -0
  563. /package/dist/{chunk-vef6qa14.js.map → chunk-2am3db31.js.map} +0 -0
  564. /package/dist/{chunk-fj1dvp37.js.map → chunk-2vhg6ysa.js.map} +0 -0
  565. /package/dist/{chunk-p0nbkys4.js.map → chunk-33saed7g.js.map} +0 -0
  566. /package/dist/{chunk-mmac1mp6.js.map → chunk-52c5zb0z.js.map} +0 -0
  567. /package/dist/{chunk-8fjmqjyx.js.map → chunk-5be2ath4.js.map} +0 -0
  568. /package/dist/{chunk-2fv8sajb.js.map → chunk-5thzcb8g.js.map} +0 -0
  569. /package/dist/{chunk-1jvq82rp.js.map → chunk-9g6jz9kk.js.map} +0 -0
  570. /package/dist/{chunk-8w27xf9e.js.map → chunk-a7er86jd.js.map} +0 -0
  571. /package/dist/{chunk-bxx3ms5t.js.map → chunk-c2rga5cx.js.map} +0 -0
  572. /package/dist/{chunk-dsfw1bdr.js.map → chunk-cnb5kv05.js.map} +0 -0
  573. /package/dist/{chunk-n5t4mq6z.js.map → chunk-e67ynxcr.js.map} +0 -0
  574. /package/dist/{chunk-6q7c68yx.js.map → chunk-f1xh7a32.js.map} +0 -0
  575. /package/dist/{chunk-7jc21943.js.map → chunk-gf7yht60.js.map} +0 -0
  576. /package/dist/{chunk-ffwvdgk1.js.map → chunk-jjrn5v0p.js.map} +0 -0
  577. /package/dist/{chunk-r5sc1d2b.js.map → chunk-jnfxmr3f.js.map} +0 -0
  578. /package/dist/{chunk-y0zmae99.js.map → chunk-k4g51s47.js.map} +0 -0
  579. /package/dist/{chunk-drz59ve0.js.map → chunk-rx7h5fdx.js.map} +0 -0
  580. /package/dist/{chunk-yfppyaty.js.map → chunk-sk0hcjsz.js.map} +0 -0
  581. /package/dist/{chunk-qne45xqq.js.map → chunk-svabwqdq.js.map} +0 -0
  582. /package/dist/{chunk-xr7y35yj.js.map → chunk-t9shqx3w.js.map} +0 -0
  583. /package/dist/{chunk-adbve9zt.js.map → chunk-vre348sb.js.map} +0 -0
  584. /package/dist/{chunk-a4g5yjm0.js.map → chunk-w9yycd3t.js.map} +0 -0
  585. /package/dist/{chunk-wd34wnsy.js.map → chunk-xcy5ddha.js.map} +0 -0
@@ -0,0 +1,697 @@
1
+ import { stableJsonStringify } from "../../../json"
2
+ import {
3
+ MaterializationConflictError,
4
+ MaterializationValidationError,
5
+ } from "../../../materialization/errors"
6
+ import type {
7
+ OntologyLinkRef,
8
+ OntologyObjectRef,
9
+ ProjectionEntityRef,
10
+ } from "../../../materialization/model"
11
+ import {
12
+ linkRefKey,
13
+ linkRefSortKey,
14
+ linkScopeKey,
15
+ linkScopeSortKey,
16
+ objectRefKey,
17
+ objectRefSortKey,
18
+ projectionEntityKey,
19
+ } from "../../../materialization/refs"
20
+ import {
21
+ getInMemoryObjectMaterializerAdapter,
22
+ type InMemoryObjectStorage,
23
+ } from "../../objects/in-memory"
24
+ import type {
25
+ MaterializationObjectExistence,
26
+ MaterializationPlanWorkItem,
27
+ MaterializationWorkRecord,
28
+ SourceReplacementLinkState,
29
+ SourceReplacementObjectState,
30
+ } from "../materializations"
31
+ import { assertPageRows, duplicateMaterializationWork } from "../provider"
32
+ import { assertNonblank, assertPositiveInteger } from "../provider-validation"
33
+ import {
34
+ assertReplacementPlanCommit,
35
+ prepareReplacementIdentities,
36
+ projectionChangeCounts,
37
+ workUniquenessKey,
38
+ } from "../provider-work"
39
+ import type {
40
+ OntologyReplacementPlanStorage,
41
+ OpenedReplacementPlan,
42
+ OpenReplacementPlanInput,
43
+ PurgeReplacementPlansInput,
44
+ ReplacementPlanRef,
45
+ ReplacementPlanStatePage,
46
+ ReplacementPlanStatus,
47
+ StageReplacementPlanInput,
48
+ StreamReplacementPlanStateInput,
49
+ } from "../replacement-plans"
50
+ import type { AssertSourceMaterializationExecution } from "../sources"
51
+ import {
52
+ findActiveSourceMaterialization,
53
+ linkRef,
54
+ storedSourceLink,
55
+ storedSourceObject,
56
+ } from "./materializations-state"
57
+ import {
58
+ type InMemoryOntologyState,
59
+ type InMemoryOntologyStorageTestHooks,
60
+ type InMemorySourceMaterialization,
61
+ projectEntityKey,
62
+ sourceMaterializationKey,
63
+ } from "./shared-state"
64
+ import { previousSourceRows } from "./source-roots"
65
+ import type { InMemoryMaterializationStateReader } from "./state-reader"
66
+
67
+ export interface InMemoryPlanIdentity {
68
+ readonly entity: ProjectionEntityRef
69
+ readonly sortKey: string
70
+ diffRequired: boolean
71
+ /** Whether link expansion already started from this identity since it was last planned. */
72
+ expanded: boolean
73
+ /** Revision of the inputs the identity's state was last read at. */
74
+ readRevision: string | null
75
+ /** Revision its records were planned from; null while it is still to plan. */
76
+ plannedRevision: string | null
77
+ records: readonly MaterializationWorkRecord[]
78
+ }
79
+
80
+ export interface InMemoryReplacementPlan {
81
+ readonly projectId: string
82
+ readonly sourceId: string
83
+ readonly materializationId: string
84
+ readonly projectionKind: "object" | "link"
85
+ /** The commit the plan's work carries, and its time fixed when the plan opened. */
86
+ readonly commitId: string
87
+ readonly committedAt: string
88
+ /** The active source the plan replaces, null when none was active. */
89
+ readonly replacedMaterializationId: string | null
90
+ readonly replacedLastCommitId: string | null
91
+ /** Commits finalized when every planned identity was last known fresh. */
92
+ watermark: number
93
+ /** Entities this replacement decides: its own rows and those of the roots it replaces. */
94
+ readonly owned: Set<string>
95
+ /** Keyed by `projectionEntityKey`. */
96
+ readonly identities: Map<string, InMemoryPlanIdentity>
97
+ /** Record and uniqueness keys of the planned work, each unique within the plan. */
98
+ readonly workKeys: Set<string>
99
+ }
100
+
101
+ /** The entities whose plan inputs one commit changed, by key. */
102
+ export interface InMemoryCommitTouches {
103
+ readonly projectId: string
104
+ /** `objectRefKey`s, `linkRefKey`s and `linkScopeKey`s. */
105
+ readonly objects: Set<string>
106
+ readonly links: Set<string>
107
+ readonly scopes: Set<string>
108
+ }
109
+
110
+ export function emptyCommitTouches(projectId: string): InMemoryCommitTouches {
111
+ return { projectId, objects: new Set(), links: new Set(), scopes: new Set() }
112
+ }
113
+
114
+ /**
115
+ * Records what applying `item` changes among the inputs a plan reads. The SQL providers derive the
116
+ * same keys from their work tables.
117
+ */
118
+ export function touchPlanItem(touches: InMemoryCommitTouches, item: MaterializationPlanWorkItem) {
119
+ switch (item.kind) {
120
+ case "object-override-upsert":
121
+ case "object-override-delete":
122
+ case "object-delete":
123
+ touches.objects.add(objectRefKey(item.value.ref))
124
+ return
125
+ case "object-upsert":
126
+ touches.objects.add(objectRefKey(item.value.row.ref))
127
+ return
128
+ case "point-upsert":
129
+ touches.objects.add(objectRefKey(item.value.point.series.object))
130
+ return
131
+ case "link-override-upsert":
132
+ case "link-override-delete":
133
+ case "link-delete":
134
+ touches.links.add(linkRefKey(item.value.ref))
135
+ return
136
+ case "link-upsert":
137
+ touches.links.add(linkRefKey(item.value.row.ref))
138
+ return
139
+ case "link-slot-override-upsert":
140
+ case "link-slot-override-delete":
141
+ touches.scopes.add(linkScopeKey(item.value.ref.source, item.value.ref.linkId))
142
+ return
143
+ }
144
+ }
145
+
146
+ export function replacementPlanKey(input: {
147
+ readonly projectId: string
148
+ readonly source: { readonly projectionId: string }
149
+ readonly materializationId: string
150
+ }): string {
151
+ return sourceMaterializationKey(
152
+ input.projectId,
153
+ input.source.projectionId,
154
+ input.materializationId
155
+ )
156
+ }
157
+
158
+ export class InMemoryOntologyReplacementPlanStorage implements OntologyReplacementPlanStorage {
159
+ constructor(
160
+ private readonly state: InMemoryOntologyState,
161
+ private readonly objects: InMemoryObjectStorage,
162
+ private readonly reader: InMemoryMaterializationStateReader,
163
+ private readonly runRootOperation: <T>(run: () => Promise<T> | T) => Promise<T>,
164
+ private readonly assertExecution: AssertSourceMaterializationExecution,
165
+ private readonly hooks: InMemoryOntologyStorageTestHooks = {}
166
+ ) {}
167
+
168
+ async open(input: OpenReplacementPlanInput): Promise<OpenedReplacementPlan> {
169
+ return this.runRootOperation(async () => {
170
+ assertReplacementPlanCommit(input.commit)
171
+ const candidate = await this.requireCandidate(input)
172
+ const key = replacementPlanKey(input)
173
+ const active = findActiveSourceMaterialization(
174
+ this.state,
175
+ input.projectId,
176
+ input.source.projectionId
177
+ )
178
+ const replacedMaterializationId = active?.materializationId ?? null
179
+ const replacedLastCommitId = active?.lastCommitId ?? null
180
+ const existing = this.state.replacementPlans.get(key)
181
+ // A plan decides the entities of the source it replaces: once that moved, it starts over.
182
+ if (
183
+ existing?.replacedMaterializationId === replacedMaterializationId &&
184
+ existing.replacedLastCommitId === replacedLastCommitId
185
+ ) {
186
+ return { committedAt: existing.committedAt }
187
+ }
188
+ const plan: InMemoryReplacementPlan = {
189
+ projectId: input.projectId,
190
+ sourceId: input.source.projectionId,
191
+ materializationId: input.materializationId,
192
+ projectionKind: candidate.projectionKind,
193
+ commitId: input.commit.id,
194
+ committedAt: input.commit.committedAt,
195
+ replacedMaterializationId,
196
+ replacedLastCommitId,
197
+ watermark: this.state.commitsById.size,
198
+ owned: new Set(),
199
+ identities: new Map(),
200
+ workKeys: new Set(),
201
+ }
202
+ for (const rows of [
203
+ previousSourceRows(this.state, candidate),
204
+ candidate.rowsByEntity.values(),
205
+ ]) {
206
+ for (const row of rows) {
207
+ plan.owned.add(projectionEntityKey(row.assertion))
208
+ addIdentity(plan, row.assertion, true)
209
+ }
210
+ }
211
+ this.state.replacementPlans.set(key, plan)
212
+ return { committedAt: plan.committedAt }
213
+ })
214
+ }
215
+
216
+ async *streamState(
217
+ input: StreamReplacementPlanStateInput
218
+ ): AsyncIterable<ReplacementPlanStatePage> {
219
+ assertPageRows(input.pageRows)
220
+ this.hooks.beforeRead?.(`replacement-plan.${input.entityKind}`)
221
+ const pending = await this.runRootOperation(async () => {
222
+ const { plan } = await this.requirePlan(input)
223
+ if (input.entityKind === "object" && plan.projectionKind !== "object") {
224
+ throw new MaterializationConflictError(
225
+ "source-materialization",
226
+ "Link projection replacement cannot stream object state."
227
+ )
228
+ }
229
+ if (input.entityKind === "link") {
230
+ if (unplanned(plan, "object").length > 0) {
231
+ throw new MaterializationConflictError(
232
+ "effective-state",
233
+ "Object projection replacement must plan every object before its links."
234
+ )
235
+ }
236
+ this.expandLinks(plan)
237
+ }
238
+ return unplanned(plan, input.entityKind).map((identity) =>
239
+ projectionEntityKey(identity.entity)
240
+ )
241
+ })
242
+ for (let offset = 0; offset < pending.length; offset += input.pageRows) {
243
+ const keys = pending.slice(offset, offset + input.pageRows)
244
+ const page = await this.runRootOperation(async () => {
245
+ const { plan, candidate } = await this.requirePlan(input)
246
+ // Looked up again: a rolled back transaction restores the plan as copies.
247
+ const selected = keys.flatMap((key) => {
248
+ const identity = plan.identities.get(key)
249
+ return identity?.plannedRevision === null ? [identity] : []
250
+ })
251
+ if (selected.length === 0) return null
252
+ return input.entityKind === "object"
253
+ ? this.objectPage(plan, candidate, selected)
254
+ : this.linkPage(plan, candidate, selected)
255
+ })
256
+ if (!page) continue
257
+ this.hooks.observeBuffer?.(
258
+ `replacement.${input.entityKind}.page`,
259
+ page.objects.length + page.links.length
260
+ )
261
+ yield page
262
+ }
263
+ }
264
+
265
+ async stage(input: StageReplacementPlanInput): Promise<void> {
266
+ await this.runRootOperation(async () => {
267
+ const { plan } = await this.requirePlan(input)
268
+ // Only an identity streamed and still to plan has the revision its work is planned from,
269
+ // and holds no work: unplanning one deletes its work and forgets what it read.
270
+ const updates = prepareReplacementIdentities(input, plan).map((prepared) => {
271
+ const current = plan.identities.get(prepared.entityKey)
272
+ if (!current || current.readRevision === null || current.plannedRevision !== null) {
273
+ throw new MaterializationValidationError(
274
+ `Replacement identity ${prepared.entityKey} is not streamed and still to plan.`
275
+ )
276
+ }
277
+ return { current, records: structuredClone(prepared.records) }
278
+ })
279
+ const claimed = new Set<string>()
280
+ for (const { records } of updates) {
281
+ for (const record of records) {
282
+ for (const key of workKeys(record)) {
283
+ if (claimed.has(key) || plan.workKeys.has(key)) {
284
+ throw duplicateMaterializationWork(record.recordKey)
285
+ }
286
+ claimed.add(key)
287
+ }
288
+ }
289
+ }
290
+ const staged = updates.flatMap(({ records }) => records)
291
+ this.hooks.observeWork?.(staged)
292
+ for (const { current, records } of updates) {
293
+ current.records = records
294
+ current.plannedRevision = current.readRevision
295
+ }
296
+ for (const key of claimed) plan.workKeys.add(key)
297
+ this.hooks.observeBuffer?.("plan.stage", updates.length)
298
+ })
299
+ }
300
+
301
+ async refresh(input: ReplacementPlanRef): Promise<ReplacementPlanStatus> {
302
+ const { plan } = await this.requirePlan(input)
303
+ const pending = [...plan.identities.values()].filter(
304
+ (identity) => identity.plannedRevision === null
305
+ )
306
+ if (pending.length > 0) return { fresh: false, unplanned: pending.length }
307
+ let unplannedCount = 0
308
+ if (this.state.commitsById.size !== plan.watermark) {
309
+ // Purge keeps every commit's touches past the watermark of a ready plan.
310
+ const touched = emptyCommitTouches(plan.projectId)
311
+ for (let ordinal = plan.watermark + 1; ordinal <= this.state.commitsById.size; ordinal += 1) {
312
+ const touches = this.state.commitTouches.get(ordinal)
313
+ if (touches?.projectId !== plan.projectId) continue
314
+ for (const kind of ["objects", "links", "scopes"] as const) {
315
+ for (const key of touches[kind]) touched[kind].add(key)
316
+ }
317
+ }
318
+ for (const identity of plan.identities.values()) {
319
+ if (!touchesIdentity(touched, identity.entity)) continue
320
+ if (this.revision(plan, identity) === identity.plannedRevision) continue
321
+ unplan(plan, identity)
322
+ unplannedCount += 1
323
+ }
324
+ unplannedCount += this.expandTouched(plan, touched)
325
+ plan.watermark = this.state.commitsById.size
326
+ }
327
+ if (unplannedCount > 0) return { fresh: false, unplanned: unplannedCount }
328
+ return {
329
+ fresh: true,
330
+ counts: projectionChangeCounts(
331
+ [...plan.identities.values()].flatMap((identity) => identity.records)
332
+ ),
333
+ }
334
+ }
335
+
336
+ async purge(input: PurgeReplacementPlansInput): Promise<number> {
337
+ assertNonblank(input.projectId, "Replacement plan purge project id")
338
+ assertPositiveInteger(input.limit, "Replacement plan purge limit")
339
+ return this.runRootOperation(() => {
340
+ // Commits and abandons delete their plan at once: only touches outlive what reads them.
341
+ let horizon = this.state.commitsById.size
342
+ for (const plan of this.state.replacementPlans.values()) {
343
+ if (plan.projectId === input.projectId) horizon = Math.min(horizon, plan.watermark)
344
+ }
345
+ let deleted = 0
346
+ for (const [ordinal, touches] of this.state.commitTouches) {
347
+ if (deleted === input.limit) break
348
+ if (ordinal > horizon || touches.projectId !== input.projectId) continue
349
+ this.state.commitTouches.delete(ordinal)
350
+ deleted += 1
351
+ }
352
+ return deleted
353
+ })
354
+ }
355
+
356
+ private async objectPage(
357
+ plan: InMemoryReplacementPlan,
358
+ candidate: InMemorySourceMaterialization,
359
+ selected: readonly InMemoryPlanIdentity[]
360
+ ): Promise<ReplacementPlanStatePage> {
361
+ const objects: SourceReplacementObjectState[] = []
362
+ for (const identity of selected) {
363
+ const ref = identity.entity.ref as OntologyObjectRef
364
+ const base = await this.reader.objectState(plan.projectId, ref)
365
+ objects.push({
366
+ ref: base.ref,
367
+ candidateSource: storedSourceObject(
368
+ plan.sourceId,
369
+ plan.materializationId,
370
+ candidate.rowsByEntity.get(projectionEntityKey(identity.entity))
371
+ ),
372
+ override: base.override,
373
+ effective: base.effective,
374
+ latestTelemetry: base.latestTelemetry,
375
+ })
376
+ identity.readRevision = this.revision(plan, identity)
377
+ }
378
+ return { objects, links: [], endpoints: [] }
379
+ }
380
+
381
+ private async linkPage(
382
+ plan: InMemoryReplacementPlan,
383
+ candidate: InMemorySourceMaterialization,
384
+ selected: readonly InMemoryPlanIdentity[]
385
+ ): Promise<ReplacementPlanStatePage> {
386
+ const links: SourceReplacementLinkState[] = []
387
+ const endpoints = new Map<string, MaterializationObjectExistence>()
388
+ for (const identity of selected) {
389
+ const ref = identity.entity.ref as OntologyLinkRef
390
+ const key = projectionEntityKey(identity.entity)
391
+ const base = await this.reader.linkState(plan.projectId, ref)
392
+ links.push({
393
+ ref: base.ref,
394
+ candidateSource: plan.owned.has(key)
395
+ ? storedSourceLink(plan.sourceId, plan.materializationId, candidate.rowsByEntity.get(key))
396
+ : base.source,
397
+ override: base.override,
398
+ slotOverride: base.slotOverride,
399
+ effective: base.effective,
400
+ diffRequired: identity.diffRequired,
401
+ })
402
+ for (const endpoint of [ref.source, ref.target]) {
403
+ endpoints.set(objectRefKey(endpoint), {
404
+ ref: structuredClone(endpoint),
405
+ exists: this.endpointExists(plan, endpoint),
406
+ })
407
+ }
408
+ identity.readRevision = this.revision(plan, identity)
409
+ }
410
+ return { objects: [], links, endpoints: [...endpoints.values()] }
411
+ }
412
+
413
+ /** An endpoint exists as this plan leaves it when the plan decides it, else as effective. */
414
+ private endpointExists(plan: InMemoryReplacementPlan, ref: OntologyObjectRef): boolean {
415
+ const planned = plan.identities.get(projectionEntityKey({ kind: "object", ref }))
416
+ const existence = planned?.records.find((record) => record.kind === "object-existence")
417
+ if (existence?.kind === "object-existence") return existence.exists
418
+ return (
419
+ getInMemoryObjectMaterializerAdapter(this.objects).getExactObjectRow(
420
+ plan.projectId,
421
+ ref.objectTypeId,
422
+ ref.primaryId
423
+ ) !== null
424
+ )
425
+ }
426
+
427
+ /**
428
+ * The revision of everything an identity's plan reads. An object reads its effective row, its
429
+ * override and its latest telemetry; a link reads its effective row, its edge and slot
430
+ * overrides, the live source asserting it when this replacement does not, and the existence of
431
+ * both endpoints: as planned for an object of this plan, which follows its whole revision, and
432
+ * as it is for any other.
433
+ */
434
+ private revision(plan: InMemoryReplacementPlan, identity: InMemoryPlanIdentity): string {
435
+ if (identity.entity.kind === "object") {
436
+ return stableJsonStringify(this.objectRevision(plan.projectId, identity.entity.ref))
437
+ }
438
+ const ref = identity.entity.ref
439
+ const projectId = plan.projectId
440
+ const row = getInMemoryObjectMaterializerAdapter(this.objects).getExactLinkRow(projectId, {
441
+ sourceTypeId: ref.source.objectTypeId,
442
+ sourceId: ref.source.primaryId,
443
+ linkId: ref.linkId,
444
+ targetTypeId: ref.target.objectTypeId,
445
+ targetId: ref.target.primaryId,
446
+ })
447
+ const live = this.reader.findActiveLinkSource(projectId, ref)
448
+ return stableJsonStringify([
449
+ row?.lastCommitId ?? null,
450
+ this.state.linkOverrides.get(projectEntityKey(projectId, linkRefKey(ref)))?.lastCommitId ??
451
+ null,
452
+ this.state.linkSlotOverrides.get(
453
+ projectEntityKey(projectId, linkScopeKey(ref.source, ref.linkId))
454
+ )?.lastCommitId ?? null,
455
+ live ? [live.source.projectionId, live.materializationId, live.stagingOrdinal] : null,
456
+ this.endpointRevision(plan, ref.source),
457
+ this.endpointRevision(plan, ref.target),
458
+ ])
459
+ }
460
+
461
+ private endpointRevision(plan: InMemoryReplacementPlan, ref: OntologyObjectRef): unknown {
462
+ if (plan.identities.has(projectionEntityKey({ kind: "object", ref }))) {
463
+ return this.objectRevision(plan.projectId, ref)
464
+ }
465
+ return (
466
+ getInMemoryObjectMaterializerAdapter(this.objects).getExactObjectRow(
467
+ plan.projectId,
468
+ ref.objectTypeId,
469
+ ref.primaryId
470
+ ) !== null
471
+ )
472
+ }
473
+
474
+ private objectRevision(projectId: string, ref: OntologyObjectRef): unknown {
475
+ const row = getInMemoryObjectMaterializerAdapter(this.objects).getExactObjectRow(
476
+ projectId,
477
+ ref.objectTypeId,
478
+ ref.primaryId
479
+ )
480
+ return [
481
+ row ? [row.version, row.lastCommitId] : null,
482
+ this.state.objectOverrides.get(projectEntityKey(projectId, objectRefKey(ref)))
483
+ ?.lastCommitId ?? null,
484
+ this.reader
485
+ .latestTelemetry(projectId, ref)
486
+ .map((point) => [point.series.propertyId, point.at, point.lastCommitId]),
487
+ ]
488
+ }
489
+
490
+ /**
491
+ * Adds the links a plan must decide besides its own, from the identities planned since they were
492
+ * last expanded: those incident to an object whose existence it flips, and every member of a
493
+ * scope it changes. Returns how many identities this left to plan, counting an existing one that
494
+ * now needs a diff. What commits add later is found from their touches by `expandTouched`.
495
+ */
496
+ private expandLinks(plan: InMemoryReplacementPlan): number {
497
+ const projectId = plan.projectId
498
+ const incident = new Set<string>()
499
+ for (const identity of plan.identities.values()) {
500
+ if (identity.entity.kind !== "object" || identity.expanded) continue
501
+ if (identity.plannedRevision === null) continue
502
+ identity.expanded = true
503
+ for (const record of identity.records) {
504
+ if (record.kind === "incident-object") incident.add(objectRefKey(record.ref))
505
+ }
506
+ }
507
+ let added = 0
508
+ const consider = (ref: OntologyLinkRef, diffRequired: boolean): void => {
509
+ if (addIdentity(plan, { kind: "link", ref }, diffRequired)) added += 1
510
+ }
511
+ if (incident.size > 0) {
512
+ const index = this.reader.incidentLinkIndex(projectId)
513
+ for (const key of incident) {
514
+ for (const ref of index.get(key) ?? []) consider(ref, true)
515
+ }
516
+ }
517
+ const adapter = getInMemoryObjectMaterializerAdapter(this.objects)
518
+ const scopes = new Map<string, Pick<OntologyLinkRef, "source" | "linkId">>()
519
+ for (const identity of plan.identities.values()) {
520
+ if (identity.entity.kind !== "link" || !identity.diffRequired || identity.expanded) continue
521
+ identity.expanded = true
522
+ const ref = identity.entity.ref
523
+ scopes.set(linkScopeSortKey(ref.source, ref.linkId), ref)
524
+ }
525
+ for (const scope of scopes.values()) {
526
+ adapter.visitExactScopeLinks(
527
+ projectId,
528
+ scope.source.objectTypeId,
529
+ scope.source.primaryId,
530
+ scope.linkId,
531
+ (row) => consider(linkRef(row), false)
532
+ )
533
+ const override = this.state.linkSlotOverrides.get(
534
+ projectEntityKey(projectId, linkScopeKey(scope.source, scope.linkId))
535
+ )
536
+ if (override) consider({ ...scope, target: override.value.target }, false)
537
+ }
538
+ return added
539
+ }
540
+
541
+ /**
542
+ * Adds the links commits brought within the plan's reach, from what they touched: a link that
543
+ * now exists incident to an object the plan flips, or in a scope a planned link changes. It
544
+ * considers the links `expandLinks` would find, among those the commits touched.
545
+ */
546
+ private expandTouched(plan: InMemoryReplacementPlan, touched: InMemoryCommitTouches): number {
547
+ const projectId = plan.projectId
548
+ const incident = new Set<string>()
549
+ const scopes = new Set<string>()
550
+ for (const identity of plan.identities.values()) {
551
+ for (const record of identity.records) {
552
+ if (record.kind === "incident-object") incident.add(objectRefKey(record.ref))
553
+ }
554
+ if (identity.entity.kind === "link" && identity.diffRequired) {
555
+ scopes.add(linkScopeKey(identity.entity.ref.source, identity.entity.ref.linkId))
556
+ }
557
+ }
558
+ let added = 0
559
+ const consider = (ref: OntologyLinkRef, member: boolean): void => {
560
+ if (incident.has(objectRefKey(ref.source)) || incident.has(objectRefKey(ref.target))) {
561
+ if (addIdentity(plan, { kind: "link", ref }, true)) added += 1
562
+ } else if (member && scopes.has(linkScopeKey(ref.source, ref.linkId))) {
563
+ if (addIdentity(plan, { kind: "link", ref }, false)) added += 1
564
+ }
565
+ }
566
+ const adapter = getInMemoryObjectMaterializerAdapter(this.objects)
567
+ for (const key of touched.links) {
568
+ const ref = parseLinkKey(key)
569
+ const effective =
570
+ adapter.getExactLinkRow(projectId, {
571
+ sourceTypeId: ref.source.objectTypeId,
572
+ sourceId: ref.source.primaryId,
573
+ linkId: ref.linkId,
574
+ targetTypeId: ref.target.objectTypeId,
575
+ targetId: ref.target.primaryId,
576
+ }) !== null
577
+ if (
578
+ effective ||
579
+ this.state.linkOverrides.has(projectEntityKey(projectId, key)) ||
580
+ this.state.activeSourceRows.has(
581
+ projectEntityKey(projectId, projectionEntityKey({ kind: "link", ref }))
582
+ )
583
+ ) {
584
+ consider(ref, effective)
585
+ }
586
+ }
587
+ for (const key of touched.scopes) {
588
+ const override = this.state.linkSlotOverrides.get(projectEntityKey(projectId, key))
589
+ if (override) consider({ ...override.ref, target: override.value.target }, true)
590
+ }
591
+ return added
592
+ }
593
+
594
+ private async requireCandidate(
595
+ input: ReplacementPlanRef
596
+ ): Promise<InMemorySourceMaterialization> {
597
+ const candidate = this.state.sourceMaterializations.get(replacementPlanKey(input))
598
+ if (
599
+ !candidate ||
600
+ candidate.status !== "ready" ||
601
+ candidate.projectionRunId !== input.execution.projectionRunId ||
602
+ candidate.executionToken !== input.execution.executionToken
603
+ ) {
604
+ throw new MaterializationConflictError(
605
+ "source-materialization",
606
+ `Candidate source materialization '${input.materializationId}' is missing, not ready, or owned by another execution.`
607
+ )
608
+ }
609
+ await this.assertExecution({
610
+ projectId: input.projectId,
611
+ source: input.source,
612
+ execution: input.execution,
613
+ })
614
+ return candidate
615
+ }
616
+
617
+ private async requirePlan(
618
+ input: ReplacementPlanRef
619
+ ): Promise<{ plan: InMemoryReplacementPlan; candidate: InMemorySourceMaterialization }> {
620
+ const candidate = await this.requireCandidate(input)
621
+ const plan = this.state.replacementPlans.get(replacementPlanKey(input))
622
+ if (!plan) {
623
+ throw new MaterializationConflictError(
624
+ "source-materialization",
625
+ `Candidate source materialization '${input.materializationId}' has no open plan.`
626
+ )
627
+ }
628
+ return { plan, candidate }
629
+ }
630
+ }
631
+
632
+ /** Adds an identity, or makes an existing one need a diff. True when it left one to plan. */
633
+ function addIdentity(
634
+ plan: InMemoryReplacementPlan,
635
+ entity: ProjectionEntityRef,
636
+ diffRequired: boolean
637
+ ): boolean {
638
+ const key = projectionEntityKey(entity)
639
+ const existing = plan.identities.get(key)
640
+ if (existing) {
641
+ if (!diffRequired || existing.diffRequired) return false
642
+ existing.diffRequired = true
643
+ unplan(plan, existing)
644
+ return true
645
+ }
646
+ plan.identities.set(key, {
647
+ entity: structuredClone({ kind: entity.kind, ref: entity.ref } as ProjectionEntityRef),
648
+ sortKey: entity.kind === "object" ? objectRefSortKey(entity.ref) : linkRefSortKey(entity.ref),
649
+ diffRequired,
650
+ expanded: false,
651
+ readRevision: null,
652
+ plannedRevision: null,
653
+ records: [],
654
+ })
655
+ return true
656
+ }
657
+
658
+ function unplan(plan: InMemoryReplacementPlan, identity: InMemoryPlanIdentity): void {
659
+ for (const record of identity.records) {
660
+ for (const key of workKeys(record)) plan.workKeys.delete(key)
661
+ }
662
+ identity.readRevision = null
663
+ identity.plannedRevision = null
664
+ identity.expanded = false
665
+ identity.records = []
666
+ }
667
+
668
+ /** Whether a commit that touched `touched` may have changed an identity's revision. */
669
+ function touchesIdentity(touched: InMemoryCommitTouches, entity: ProjectionEntityRef): boolean {
670
+ if (entity.kind === "object") return touched.objects.has(objectRefKey(entity.ref))
671
+ const { ref } = entity
672
+ return (
673
+ touched.links.has(linkRefKey(ref)) ||
674
+ touched.scopes.has(linkScopeKey(ref.source, ref.linkId)) ||
675
+ touched.objects.has(objectRefKey(ref.source)) ||
676
+ touched.objects.has(objectRefKey(ref.target))
677
+ )
678
+ }
679
+
680
+ function parseLinkKey(key: string): OntologyLinkRef {
681
+ const [sourceTypeId, sourceId, linkId, targetTypeId, targetId] = JSON.parse(key) as string[]
682
+ return {
683
+ source: { objectTypeId: sourceTypeId!, primaryId: sourceId! },
684
+ linkId: linkId!,
685
+ target: { objectTypeId: targetTypeId!, primaryId: targetId! },
686
+ }
687
+ }
688
+
689
+ function workKeys(record: MaterializationWorkRecord): readonly string[] {
690
+ return [`record:${record.recordKey}`, `unique:${workUniquenessKey(record)}`]
691
+ }
692
+
693
+ function unplanned(plan: InMemoryReplacementPlan, kind: "object" | "link"): InMemoryPlanIdentity[] {
694
+ return [...plan.identities.values()]
695
+ .filter((identity) => identity.entity.kind === kind && identity.plannedRevision === null)
696
+ .sort((left, right) => left.sortKey.localeCompare(right.sortKey))
697
+ }