@sixb/core 0.1.21 → 0.1.22

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 (1263) hide show
  1. package/dist/actions/commit-edits.d.ts +3 -1
  2. package/dist/actions/commit-edits.d.ts.map +1 -1
  3. package/dist/actions/execution.d.ts.map +1 -1
  4. package/dist/actions/index.js +63 -59
  5. package/dist/actions/index.js.map +1 -1
  6. package/dist/actions/read-facade.d.ts +9 -1
  7. package/dist/actions/read-facade.d.ts.map +1 -1
  8. package/dist/actions/request.d.ts +15 -1
  9. package/dist/actions/request.d.ts.map +1 -1
  10. package/dist/actions/run/context.d.ts +1 -0
  11. package/dist/actions/run/context.d.ts.map +1 -1
  12. package/dist/actions/run/execute.d.ts +2 -3
  13. package/dist/actions/run/execute.d.ts.map +1 -1
  14. package/dist/actions/run/executor.d.ts +3 -0
  15. package/dist/actions/run/executor.d.ts.map +1 -1
  16. package/dist/actions/run/normalize.d.ts +2 -1
  17. package/dist/actions/run/normalize.d.ts.map +1 -1
  18. package/dist/actions/run/signals.d.ts +1 -3
  19. package/dist/actions/run/signals.d.ts.map +1 -1
  20. package/dist/actions/run/types.d.ts +16 -1
  21. package/dist/actions/run/types.d.ts.map +1 -1
  22. package/dist/actions/run-authorization.d.ts +14 -0
  23. package/dist/actions/run-authorization.d.ts.map +1 -1
  24. package/dist/actions/types/context.d.ts +17 -1
  25. package/dist/actions/types/context.d.ts.map +1 -1
  26. package/dist/actions/validators.d.ts.map +1 -1
  27. package/dist/activity/timeline.d.ts +8 -1
  28. package/dist/activity/timeline.d.ts.map +1 -1
  29. package/dist/agents/accounting.d.ts +15 -0
  30. package/dist/agents/accounting.d.ts.map +1 -0
  31. package/dist/agents/adapters.d.ts.map +1 -1
  32. package/dist/agents/agent-mail.d.ts +9 -0
  33. package/dist/agents/agent-mail.d.ts.map +1 -0
  34. package/dist/agents/api-gateway.d.ts +5 -0
  35. package/dist/agents/api-gateway.d.ts.map +1 -1
  36. package/dist/agents/approval-continuation.d.ts +23 -0
  37. package/dist/agents/approval-continuation.d.ts.map +1 -0
  38. package/dist/agents/approval-executor.d.ts +56 -0
  39. package/dist/agents/approval-executor.d.ts.map +1 -0
  40. package/dist/agents/approval-outcome.d.ts +8 -0
  41. package/dist/agents/approval-outcome.d.ts.map +1 -0
  42. package/dist/agents/approvals.d.ts +210 -0
  43. package/dist/agents/approvals.d.ts.map +1 -0
  44. package/dist/agents/authority.d.ts +10 -0
  45. package/dist/agents/authority.d.ts.map +1 -1
  46. package/dist/agents/builders.d.ts.map +1 -1
  47. package/dist/agents/cancel.d.ts +23 -0
  48. package/dist/agents/cancel.d.ts.map +1 -0
  49. package/dist/agents/child-question.d.ts +18 -0
  50. package/dist/agents/child-question.d.ts.map +1 -0
  51. package/dist/agents/children.d.ts +99 -0
  52. package/dist/agents/children.d.ts.map +1 -0
  53. package/dist/agents/context/index.js +1 -1
  54. package/dist/agents/context-compaction.d.ts.map +1 -1
  55. package/dist/agents/errors.d.ts +13 -1
  56. package/dist/agents/errors.d.ts.map +1 -1
  57. package/dist/agents/execution.d.ts +180 -14
  58. package/dist/agents/execution.d.ts.map +1 -1
  59. package/dist/agents/fork.d.ts +16 -0
  60. package/dist/agents/fork.d.ts.map +1 -0
  61. package/dist/agents/ids.d.ts +7 -0
  62. package/dist/agents/ids.d.ts.map +1 -1
  63. package/dist/agents/index.d.ts +19 -8
  64. package/dist/agents/index.d.ts.map +1 -1
  65. package/dist/agents/index.js +159 -86
  66. package/dist/agents/index.js.map +1 -1
  67. package/dist/agents/memory-execution.d.ts +57 -0
  68. package/dist/agents/memory-execution.d.ts.map +1 -0
  69. package/dist/agents/memory.d.ts +49 -0
  70. package/dist/agents/memory.d.ts.map +1 -0
  71. package/dist/agents/message.d.ts +50 -1
  72. package/dist/agents/message.d.ts.map +1 -1
  73. package/dist/agents/model-loop.d.ts +19 -0
  74. package/dist/agents/model-loop.d.ts.map +1 -1
  75. package/dist/agents/model-routing.d.ts +19 -0
  76. package/dist/agents/model-routing.d.ts.map +1 -0
  77. package/dist/agents/participants.d.ts +18 -0
  78. package/dist/agents/participants.d.ts.map +1 -0
  79. package/dist/agents/reference.d.ts.map +1 -1
  80. package/dist/agents/request.d.ts +36 -2
  81. package/dist/agents/request.d.ts.map +1 -1
  82. package/dist/agents/run-scope.d.ts +51 -0
  83. package/dist/agents/run-scope.d.ts.map +1 -0
  84. package/dist/agents/streams/index.d.ts +3 -2
  85. package/dist/agents/streams/index.d.ts.map +1 -1
  86. package/dist/agents/streams/index.js +7 -3
  87. package/dist/agents/streams/index.js.map +1 -1
  88. package/dist/agents/streams/internal.d.ts +1 -1
  89. package/dist/agents/streams/internal.d.ts.map +1 -1
  90. package/dist/agents/streams/internal.js +5 -3
  91. package/dist/agents/streams/internal.js.map +1 -1
  92. package/dist/agents/streams/protocol.d.ts +122 -3
  93. package/dist/agents/streams/protocol.d.ts.map +1 -1
  94. package/dist/agents/subagent-runs.d.ts +12 -0
  95. package/dist/agents/subagent-runs.d.ts.map +1 -0
  96. package/dist/agents/thread-access.d.ts +53 -0
  97. package/dist/agents/thread-access.d.ts.map +1 -0
  98. package/dist/agents/tool-definition.d.ts +5 -4
  99. package/dist/agents/tool-definition.d.ts.map +1 -1
  100. package/dist/agents/types.d.ts +23 -4
  101. package/dist/agents/types.d.ts.map +1 -1
  102. package/dist/agents/validation.d.ts +1 -1
  103. package/dist/agents/validation.d.ts.map +1 -1
  104. package/dist/artifacts/access.d.ts +52 -0
  105. package/dist/artifacts/access.d.ts.map +1 -0
  106. package/dist/artifacts/canvas.d.ts +92 -0
  107. package/dist/artifacts/canvas.d.ts.map +1 -0
  108. package/dist/artifacts/csv.d.ts +5 -0
  109. package/dist/artifacts/csv.d.ts.map +1 -1
  110. package/dist/artifacts/errors.d.ts +7 -2
  111. package/dist/artifacts/errors.d.ts.map +1 -1
  112. package/dist/artifacts/execution.d.ts +102 -7
  113. package/dist/artifacts/execution.d.ts.map +1 -1
  114. package/dist/artifacts/formula/check.d.ts +24 -0
  115. package/dist/artifacts/formula/check.d.ts.map +1 -0
  116. package/dist/artifacts/formula/evaluate.d.ts +32 -0
  117. package/dist/artifacts/formula/evaluate.d.ts.map +1 -0
  118. package/dist/artifacts/formula/index.d.ts +38 -0
  119. package/dist/artifacts/formula/index.d.ts.map +1 -0
  120. package/dist/artifacts/formula/parser.d.ts +67 -0
  121. package/dist/artifacts/formula/parser.d.ts.map +1 -0
  122. package/dist/artifacts/frames/assets.d.ts +11 -9
  123. package/dist/artifacts/frames/assets.d.ts.map +1 -1
  124. package/dist/artifacts/frames/entries.d.ts +19 -0
  125. package/dist/artifacts/frames/entries.d.ts.map +1 -0
  126. package/dist/artifacts/frames/grants.d.ts +6 -6
  127. package/dist/artifacts/frames/grants.d.ts.map +1 -1
  128. package/dist/artifacts/frames/index.d.ts +4 -2
  129. package/dist/artifacts/frames/index.d.ts.map +1 -1
  130. package/dist/artifacts/frames/index.js +444 -51
  131. package/dist/artifacts/frames/index.js.map +10 -8
  132. package/dist/artifacts/frames/kit.d.ts +10 -5
  133. package/dist/artifacts/frames/kit.d.ts.map +1 -1
  134. package/dist/artifacts/frames/probe.d.ts +16 -12
  135. package/dist/artifacts/frames/probe.d.ts.map +1 -1
  136. package/dist/artifacts/frames/protocol.d.ts +79 -10
  137. package/dist/artifacts/frames/protocol.d.ts.map +1 -1
  138. package/dist/artifacts/frames/runtime.d.ts +27 -9
  139. package/dist/artifacts/frames/runtime.d.ts.map +1 -1
  140. package/dist/artifacts/index.d.ts +11 -5
  141. package/dist/artifacts/index.d.ts.map +1 -1
  142. package/dist/artifacts/index.js +128 -6
  143. package/dist/artifacts/index.js.map +3 -3
  144. package/dist/artifacts/kinds.d.ts +1 -1
  145. package/dist/artifacts/kinds.d.ts.map +1 -1
  146. package/dist/artifacts/limits.d.ts +30 -0
  147. package/dist/artifacts/limits.d.ts.map +1 -1
  148. package/dist/artifacts/live-sheet.d.ts +65 -0
  149. package/dist/artifacts/live-sheet.d.ts.map +1 -0
  150. package/dist/artifacts/outline.d.ts +27 -1
  151. package/dist/artifacts/outline.d.ts.map +1 -1
  152. package/dist/artifacts/publish/index.d.ts +2 -0
  153. package/dist/artifacts/publish/index.d.ts.map +1 -1
  154. package/dist/artifacts/publish/index.js +59 -19
  155. package/dist/artifacts/publish/index.js.map +1 -1
  156. package/dist/artifacts/publish/publish.d.ts +43 -11
  157. package/dist/artifacts/publish/publish.d.ts.map +1 -1
  158. package/dist/artifacts/publish/queries.d.ts +33 -0
  159. package/dist/artifacts/publish/queries.d.ts.map +1 -0
  160. package/dist/artifacts/publish/references.d.ts +6 -3
  161. package/dist/artifacts/publish/references.d.ts.map +1 -1
  162. package/dist/artifacts/publish/validate/canvas.d.ts +18 -0
  163. package/dist/artifacts/publish/validate/canvas.d.ts.map +1 -0
  164. package/dist/artifacts/publish/validate/html.d.ts +20 -0
  165. package/dist/artifacts/publish/validate/html.d.ts.map +1 -0
  166. package/dist/artifacts/publish/validate/page.d.ts +15 -0
  167. package/dist/artifacts/publish/validate/page.d.ts.map +1 -0
  168. package/dist/artifacts/publish/validate/sheet.d.ts +11 -3
  169. package/dist/artifacts/publish/validate/sheet.d.ts.map +1 -1
  170. package/dist/artifacts/publish/validate/slides.d.ts +1 -7
  171. package/dist/artifacts/publish/validate/slides.d.ts.map +1 -1
  172. package/dist/artifacts/queries.d.ts +95 -0
  173. package/dist/artifacts/queries.d.ts.map +1 -0
  174. package/dist/artifacts/resolve.d.ts +6 -0
  175. package/dist/artifacts/resolve.d.ts.map +1 -1
  176. package/dist/artifacts/run-query.d.ts +26 -0
  177. package/dist/artifacts/run-query.d.ts.map +1 -0
  178. package/dist/artifacts/serialize-query.d.ts +12 -0
  179. package/dist/artifacts/serialize-query.d.ts.map +1 -0
  180. package/dist/artifacts/sheet-rules.d.ts +26 -0
  181. package/dist/artifacts/sheet-rules.d.ts.map +1 -0
  182. package/dist/artifacts/tones.d.ts +8 -0
  183. package/dist/artifacts/tones.d.ts.map +1 -0
  184. package/dist/artifacts/workbook.d.ts +76 -5
  185. package/dist/artifacts/workbook.d.ts.map +1 -1
  186. package/dist/auth/index.d.ts +1 -1
  187. package/dist/auth/index.d.ts.map +1 -1
  188. package/dist/auth/index.js +14 -11
  189. package/dist/auth/index.js.map +1 -1
  190. package/dist/auth/member-events.d.ts +13 -0
  191. package/dist/auth/member-events.d.ts.map +1 -0
  192. package/dist/auth/profile.d.ts +11 -0
  193. package/dist/auth/profile.d.ts.map +1 -0
  194. package/dist/auth/runtime.d.ts +31 -3
  195. package/dist/auth/runtime.d.ts.map +1 -1
  196. package/dist/auth/strategy.d.ts +3 -1
  197. package/dist/auth/strategy.d.ts.map +1 -1
  198. package/dist/auth/strategy.js +7 -3
  199. package/dist/auth/strategy.js.map +1 -1
  200. package/dist/auth/types.d.ts +30 -1
  201. package/dist/auth/types.d.ts.map +1 -1
  202. package/dist/authorization/decision.d.ts +15 -0
  203. package/dist/authorization/decision.d.ts.map +1 -1
  204. package/dist/authorization/event-visibility.d.ts +5 -1
  205. package/dist/authorization/event-visibility.d.ts.map +1 -1
  206. package/dist/authorization/grant-kinds.d.ts +2 -2
  207. package/dist/authorization/grant-kinds.d.ts.map +1 -1
  208. package/dist/authorization/index.d.ts +2 -2
  209. package/dist/authorization/index.d.ts.map +1 -1
  210. package/dist/authorization/index.js +12 -7
  211. package/dist/authorization/index.js.map +1 -1
  212. package/dist/authorization/resolve.d.ts +19 -1
  213. package/dist/authorization/resolve.d.ts.map +1 -1
  214. package/dist/authorization/run-visibility.d.ts +8 -1
  215. package/dist/authorization/run-visibility.d.ts.map +1 -1
  216. package/dist/authorization/types.d.ts +14 -0
  217. package/dist/authorization/types.d.ts.map +1 -1
  218. package/dist/bootstrap/index.js +69 -65
  219. package/dist/bootstrap/index.js.map +2 -2
  220. package/dist/{chunk-ky3j490c.js → chunk-02bzjgnt.js} +6 -6
  221. package/dist/{chunk-ky3j490c.js.map → chunk-02bzjgnt.js.map} +1 -1
  222. package/dist/{chunk-mfs23znk.js → chunk-07kkp2e1.js} +1 -1
  223. package/dist/{chunk-c1rxbz5y.js → chunk-098anw4f.js} +21 -19
  224. package/dist/chunk-098anw4f.js.map +12 -0
  225. package/dist/{chunk-z58tm0hm.js → chunk-0phpbbvm.js} +3 -3
  226. package/dist/{chunk-ere85b8y.js → chunk-0xmt5p5y.js} +116 -27
  227. package/dist/chunk-0xmt5p5y.js.map +14 -0
  228. package/dist/{chunk-t6f3tdnr.js → chunk-16a9dmfy.js} +33 -2
  229. package/dist/{chunk-t6f3tdnr.js.map → chunk-16a9dmfy.js.map} +5 -4
  230. package/dist/chunk-18sk89cg.js +47 -0
  231. package/dist/chunk-18sk89cg.js.map +10 -0
  232. package/dist/{chunk-e17zdm62.js → chunk-1t6k1avb.js} +1 -1
  233. package/dist/chunk-2626mh4m.js +693 -0
  234. package/dist/chunk-2626mh4m.js.map +19 -0
  235. package/dist/{chunk-qczk96d9.js → chunk-2adz0h75.js} +13 -4
  236. package/dist/chunk-2adz0h75.js.map +11 -0
  237. package/dist/{chunk-kge7k6ey.js → chunk-2fn60nvs.js} +2 -2
  238. package/dist/{chunk-99nd4rc1.js → chunk-2gjj5dx3.js} +5 -4
  239. package/dist/{chunk-99nd4rc1.js.map → chunk-2gjj5dx3.js.map} +3 -3
  240. package/dist/{chunk-mjddfa7k.js → chunk-3fqxbn31.js} +2 -24
  241. package/dist/{chunk-mjddfa7k.js.map → chunk-3fqxbn31.js.map} +3 -4
  242. package/dist/{chunk-y0c4e6ex.js → chunk-3gbefjg5.js} +1 -1
  243. package/dist/{chunk-5hx48dnn.js → chunk-45ngkxkp.js} +52 -31
  244. package/dist/chunk-45ngkxkp.js.map +13 -0
  245. package/dist/{chunk-cy4mbddw.js → chunk-48jezz3j.js} +1 -1
  246. package/dist/{chunk-561r0yc9.js → chunk-4b26qwbg.js} +13 -13
  247. package/dist/{chunk-561r0yc9.js.map → chunk-4b26qwbg.js.map} +1 -1
  248. package/dist/{chunk-9k93ah50.js → chunk-4f3ydv7t.js} +33 -69
  249. package/dist/chunk-4f3ydv7t.js.map +10 -0
  250. package/dist/chunk-4y26vs3v.js +97 -0
  251. package/dist/chunk-4y26vs3v.js.map +10 -0
  252. package/dist/{chunk-4as3wt1c.js → chunk-4ymrcdbm.js} +7 -3
  253. package/dist/chunk-4ymrcdbm.js.map +12 -0
  254. package/dist/{chunk-hcbyfxbe.js → chunk-5grk14e5.js} +76 -2
  255. package/dist/{chunk-hcbyfxbe.js.map → chunk-5grk14e5.js.map} +4 -3
  256. package/dist/{chunk-8frc8a4j.js → chunk-65pyhyas.js} +90 -83
  257. package/dist/chunk-65pyhyas.js.map +20 -0
  258. package/dist/{chunk-hwksyjks.js → chunk-661ezhks.js} +182 -6
  259. package/dist/chunk-661ezhks.js.map +11 -0
  260. package/dist/{chunk-447a5c0p.js → chunk-6n69k945.js} +2 -2
  261. package/dist/{chunk-0bphap9y.js → chunk-6p0pastb.js} +5 -5
  262. package/dist/{chunk-9j4jw7as.js → chunk-6rrtzea3.js} +18 -5
  263. package/dist/chunk-6rrtzea3.js.map +14 -0
  264. package/dist/{chunk-431pyp2c.js → chunk-6y0mkhex.js} +2 -2
  265. package/dist/{chunk-f4pamkt9.js → chunk-73v685wb.js} +10 -10
  266. package/dist/{chunk-f4pamkt9.js.map → chunk-73v685wb.js.map} +3 -3
  267. package/dist/{chunk-akzryx9h.js → chunk-7gr4j2eq.js} +7836 -5047
  268. package/dist/chunk-7gr4j2eq.js.map +120 -0
  269. package/dist/{chunk-bk9svbcq.js → chunk-7mc2wkre.js} +386 -86
  270. package/dist/chunk-7mc2wkre.js.map +50 -0
  271. package/dist/{chunk-6rqgmkde.js → chunk-7z5p905k.js} +335 -703
  272. package/dist/chunk-7z5p905k.js.map +22 -0
  273. package/dist/{chunk-yxd3nnqt.js → chunk-9mab3dvg.js} +26 -2
  274. package/dist/chunk-9mab3dvg.js.map +11 -0
  275. package/dist/chunk-9wr3yajk.js +42 -0
  276. package/dist/chunk-9wr3yajk.js.map +10 -0
  277. package/dist/chunk-az47zep4.js +41 -0
  278. package/dist/chunk-az47zep4.js.map +10 -0
  279. package/dist/{chunk-s7jg7pmn.js → chunk-bab05bhg.js} +1 -1
  280. package/dist/{chunk-858emn8m.js → chunk-bktev1ds.js} +14 -11
  281. package/dist/{chunk-858emn8m.js.map → chunk-bktev1ds.js.map} +3 -3
  282. package/dist/{chunk-dhcv7yxc.js → chunk-c0vk1djt.js} +5 -3
  283. package/dist/chunk-c0vk1djt.js.map +11 -0
  284. package/dist/chunk-c69nj7se.js +3 -0
  285. package/dist/{chunk-7n30ybym.js.map → chunk-c69nj7se.js.map} +1 -1
  286. package/dist/{chunk-q5e5tv4b.js → chunk-c844dkwd.js} +1 -1
  287. package/dist/{chunk-g257jwnc.js → chunk-cdk3egjj.js} +17 -4
  288. package/dist/chunk-cdk3egjj.js.map +12 -0
  289. package/dist/chunk-cswhawa2.js +113 -0
  290. package/dist/chunk-cswhawa2.js.map +10 -0
  291. package/dist/{chunk-cfj9dfbb.js → chunk-d2m879s4.js} +2 -2
  292. package/dist/{chunk-arns890k.js → chunk-d7vyc7k6.js} +2 -2
  293. package/dist/chunk-d7vyc7k6.js.map +10 -0
  294. package/dist/{chunk-q7gn29y3.js → chunk-dp0cdtj2.js} +2 -2
  295. package/dist/{chunk-6x0pqh32.js → chunk-e5wf5vz0.js} +3 -1
  296. package/dist/chunk-e5wf5vz0.js.map +10 -0
  297. package/dist/{chunk-cn0fwwhy.js → chunk-efmm01gj.js} +108 -1045
  298. package/dist/chunk-efmm01gj.js.map +18 -0
  299. package/dist/{chunk-918wwnaa.js → chunk-ezne9wc9.js} +1224 -430
  300. package/dist/chunk-ezne9wc9.js.map +71 -0
  301. package/dist/{chunk-tbc1ngpd.js → chunk-fe8zwt8b.js} +58 -12
  302. package/dist/{chunk-tbc1ngpd.js.map → chunk-fe8zwt8b.js.map} +5 -4
  303. package/dist/{chunk-br3k6qbf.js → chunk-fm62y49k.js} +1 -1
  304. package/dist/{chunk-nq6gpjt7.js → chunk-fntqb7qy.js} +30 -4
  305. package/dist/{chunk-nq6gpjt7.js.map → chunk-fntqb7qy.js.map} +5 -5
  306. package/dist/{chunk-1cc1xaf3.js → chunk-fp2kq35z.js} +26 -10
  307. package/dist/{chunk-1cc1xaf3.js.map → chunk-fp2kq35z.js.map} +5 -5
  308. package/dist/{chunk-vvxtn22d.js → chunk-g663fahq.js} +2 -2
  309. package/dist/{chunk-k43ct2ke.js → chunk-gvj5cd3b.js} +16 -9
  310. package/dist/chunk-gvj5cd3b.js.map +12 -0
  311. package/dist/{chunk-rmakanzx.js → chunk-h33shhq6.js} +5 -5
  312. package/dist/{chunk-nn5xnx3s.js → chunk-h3pbv7n8.js} +1738 -38
  313. package/dist/chunk-h3pbv7n8.js.map +48 -0
  314. package/dist/chunk-hn2r7z41.js.map +1 -1
  315. package/dist/{chunk-pbcbn83d.js → chunk-hqsp2sx4.js} +54 -8
  316. package/dist/chunk-hqsp2sx4.js.map +14 -0
  317. package/dist/{chunk-d09e3rax.js → chunk-hwarjrgf.js} +1 -1
  318. package/dist/{chunk-vf57cr4t.js → chunk-hyesv9dv.js} +1 -1
  319. package/dist/chunk-hz5d43gn.js +45 -0
  320. package/dist/chunk-hz5d43gn.js.map +10 -0
  321. package/dist/{chunk-91mg3nj9.js → chunk-j936th07.js} +86 -41
  322. package/dist/chunk-j936th07.js.map +12 -0
  323. package/dist/chunk-kcqpk9w1.js +75 -0
  324. package/dist/chunk-kcqpk9w1.js.map +10 -0
  325. package/dist/{chunk-5vems3nx.js → chunk-m2nevja0.js} +2 -2
  326. package/dist/{chunk-x9v4cx1d.js → chunk-m36fw8ft.js} +1 -1
  327. package/dist/{chunk-a40ad1ft.js → chunk-mbsbxarb.js} +1 -1
  328. package/dist/chunk-mzx71snp.js +129 -0
  329. package/dist/chunk-mzx71snp.js.map +10 -0
  330. package/dist/{chunk-6aawea28.js → chunk-n8q5j6y5.js} +1 -1
  331. package/dist/{chunk-d7dnxdep.js → chunk-n9zpx9c6.js} +4 -4
  332. package/dist/{chunk-xvsc5m8n.js → chunk-npcr0228.js} +1 -1
  333. package/dist/chunk-nydf3dbe.js +663 -0
  334. package/dist/chunk-nydf3dbe.js.map +13 -0
  335. package/dist/chunk-pdt5cw8z.js +233 -0
  336. package/dist/chunk-pdt5cw8z.js.map +11 -0
  337. package/dist/{chunk-rj69qcrd.js → chunk-pgrf64hp.js} +55 -7
  338. package/dist/chunk-pgrf64hp.js.map +12 -0
  339. package/dist/{chunk-y5tah2kf.js → chunk-q4pmvkg0.js} +1 -1
  340. package/dist/chunk-qhqgp4jf.js +1418 -0
  341. package/dist/chunk-qhqgp4jf.js.map +22 -0
  342. package/dist/{chunk-48qjhh6v.js → chunk-qx00vjrj.js} +19 -60
  343. package/dist/chunk-qx00vjrj.js.map +13 -0
  344. package/dist/{chunk-5948n82c.js → chunk-r6szek0x.js} +184 -7
  345. package/dist/chunk-r6szek0x.js.map +10 -0
  346. package/dist/{chunk-v4jbb3rs.js → chunk-rap5w0x0.js} +156 -2
  347. package/dist/chunk-rap5w0x0.js.map +10 -0
  348. package/dist/{chunk-pfp1txq2.js → chunk-sgx82nnt.js} +5 -31
  349. package/dist/{chunk-pfp1txq2.js.map → chunk-sgx82nnt.js.map} +3 -4
  350. package/dist/{chunk-bkpke1sg.js → chunk-t5608tkq.js} +3 -1
  351. package/dist/{chunk-bkpke1sg.js.map → chunk-t5608tkq.js.map} +3 -3
  352. package/dist/{chunk-29yx306f.js → chunk-tdxfsg1c.js} +507 -265
  353. package/dist/chunk-tdxfsg1c.js.map +23 -0
  354. package/dist/{chunk-d5rjr8c0.js → chunk-vabga7fk.js} +1 -1
  355. package/dist/{chunk-dhdha526.js → chunk-vhbw5sqm.js} +26 -2
  356. package/dist/chunk-vhbw5sqm.js.map +10 -0
  357. package/dist/{chunk-e6k4thh5.js → chunk-vpgwq5nf.js} +98 -12
  358. package/dist/chunk-vpgwq5nf.js.map +21 -0
  359. package/dist/{chunk-61y5xs4p.js → chunk-vyt322b6.js} +69 -50
  360. package/dist/{chunk-61y5xs4p.js.map → chunk-vyt322b6.js.map} +4 -4
  361. package/dist/chunk-waqk73p1.js +2380 -0
  362. package/dist/chunk-waqk73p1.js.map +23 -0
  363. package/dist/chunk-wsc1brye.js +27 -0
  364. package/dist/chunk-wsc1brye.js.map +10 -0
  365. package/dist/{chunk-96yw3pwd.js → chunk-y7dbmaqh.js} +28 -2
  366. package/dist/chunk-y7dbmaqh.js.map +10 -0
  367. package/dist/{chunk-6vb4st8k.js → chunk-yc9ners4.js} +120 -19
  368. package/dist/{chunk-6vb4st8k.js.map → chunk-yc9ners4.js.map} +8 -8
  369. package/dist/{chunk-dvd2fp9q.js → chunk-zbc929zg.js} +28 -4
  370. package/dist/chunk-zbc929zg.js.map +13 -0
  371. package/dist/chunk-zrvhsq7f.js +37 -0
  372. package/dist/chunk-zrvhsq7f.js.map +10 -0
  373. package/dist/datasets/write.js +5 -5
  374. package/dist/error-reporting/internal.js +3 -3
  375. package/dist/errors/catalog.d.ts +26 -0
  376. package/dist/errors/catalog.d.ts.map +1 -1
  377. package/dist/errors/internal.d.ts.map +1 -1
  378. package/dist/errors/internal.js +1 -1
  379. package/dist/events/definitions.d.ts +7 -0
  380. package/dist/events/definitions.d.ts.map +1 -1
  381. package/dist/events/execution.d.ts.map +1 -1
  382. package/dist/events/index.d.ts +2 -3
  383. package/dist/events/index.d.ts.map +1 -1
  384. package/dist/events/index.js +8 -10
  385. package/dist/events/index.js.map +1 -1
  386. package/dist/events/scope.d.ts.map +1 -1
  387. package/dist/events/scope.js +1 -1
  388. package/dist/events/selectors/builder.d.ts +12 -1
  389. package/dist/events/selectors/builder.d.ts.map +1 -1
  390. package/dist/events/selectors/index.d.ts +2 -2
  391. package/dist/events/selectors/index.d.ts.map +1 -1
  392. package/dist/events/selectors/index.js +2 -2
  393. package/dist/events/selectors/types.d.ts +19 -3
  394. package/dist/events/selectors/types.d.ts.map +1 -1
  395. package/dist/events/service.d.ts +17 -2
  396. package/dist/events/service.d.ts.map +1 -1
  397. package/dist/events/types/index.d.ts +3 -1
  398. package/dist/events/types/index.d.ts.map +1 -1
  399. package/dist/events/types/users.d.ts +63 -0
  400. package/dist/events/types/users.d.ts.map +1 -0
  401. package/dist/events/view-conditions.d.ts +34 -0
  402. package/dist/events/view-conditions.d.ts.map +1 -0
  403. package/dist/execution/agent.d.ts +15 -0
  404. package/dist/execution/agent.d.ts.map +1 -1
  405. package/dist/execution/agent.js +63 -57
  406. package/dist/execution/agent.js.map +1 -1
  407. package/dist/execution/authorization.d.ts.map +1 -1
  408. package/dist/execution/authorized-object-reader.d.ts +51 -2
  409. package/dist/execution/authorized-object-reader.d.ts.map +1 -1
  410. package/dist/execution/lineage.d.ts +7 -0
  411. package/dist/execution/lineage.d.ts.map +1 -0
  412. package/dist/execution/object-reader-ontology.d.ts +2 -2
  413. package/dist/execution/object-reader-ontology.d.ts.map +1 -1
  414. package/dist/execution/object-reader-security.d.ts +24 -3
  415. package/dist/execution/object-reader-security.d.ts.map +1 -1
  416. package/dist/execution/object-reader-users.d.ts +20 -0
  417. package/dist/execution/object-reader-users.d.ts.map +1 -0
  418. package/dist/execution/preparation.d.ts +23 -0
  419. package/dist/execution/preparation.d.ts.map +1 -0
  420. package/dist/execution/primitive.js +61 -57
  421. package/dist/execution/primitive.js.map +1 -1
  422. package/dist/execution/request.d.ts +2 -1
  423. package/dist/execution/request.d.ts.map +1 -1
  424. package/dist/execution/request.js +64 -56
  425. package/dist/execution/request.js.map +3 -3
  426. package/dist/execution/unique-lookup.d.ts +14 -0
  427. package/dist/execution/unique-lookup.d.ts.map +1 -0
  428. package/dist/execution/visible-objects.d.ts +12 -0
  429. package/dist/execution/visible-objects.d.ts.map +1 -0
  430. package/dist/http/api-routes.d.ts +17 -0
  431. package/dist/http/api-routes.d.ts.map +1 -1
  432. package/dist/http/index.js +1 -1
  433. package/dist/index.d.ts +32 -15
  434. package/dist/index.d.ts.map +1 -1
  435. package/dist/index.js +137 -126
  436. package/dist/index.js.map +1 -1
  437. package/dist/lake-storage/index.js +5 -5
  438. package/dist/materialization/errors.d.ts +25 -0
  439. package/dist/materialization/errors.d.ts.map +1 -1
  440. package/dist/materialization/event-envelopes.d.ts +5 -0
  441. package/dist/materialization/event-envelopes.d.ts.map +1 -1
  442. package/dist/materialization/index.d.ts +1 -1
  443. package/dist/materialization/index.d.ts.map +1 -1
  444. package/dist/materialization/index.js +14 -8
  445. package/dist/materialization/index.js.map +1 -1
  446. package/dist/materialization/model.d.ts +20 -2
  447. package/dist/materialization/model.d.ts.map +1 -1
  448. package/dist/materializer/edits/commit.d.ts.map +1 -1
  449. package/dist/materializer/edits/load-state.d.ts +5 -1
  450. package/dist/materializer/edits/load-state.d.ts.map +1 -1
  451. package/dist/materializer/edits/plan.d.ts.map +1 -1
  452. package/dist/materializer/edits/unique-values.d.ts +47 -0
  453. package/dist/materializer/edits/unique-values.d.ts.map +1 -0
  454. package/dist/materializer/edits/working-state.d.ts +6 -1
  455. package/dist/materializer/edits/working-state.d.ts.map +1 -1
  456. package/dist/materializer/execution/work-records.d.ts +7 -1
  457. package/dist/materializer/execution/work-records.d.ts.map +1 -1
  458. package/dist/materializer/index.js +45 -41
  459. package/dist/materializer/index.js.map +1 -1
  460. package/dist/materializer/projections/replacement-plan.d.ts.map +1 -1
  461. package/dist/materializer/projections/source-materialization.d.ts +1 -0
  462. package/dist/materializer/projections/source-materialization.d.ts.map +1 -1
  463. package/dist/materializer/shared/normalize.d.ts.map +1 -1
  464. package/dist/materializer/shared/projection-run.d.ts +0 -1
  465. package/dist/materializer/shared/projection-run.d.ts.map +1 -1
  466. package/dist/materializer/telemetry/plan.d.ts.map +1 -1
  467. package/dist/models/audio/catalog.d.ts +13 -1
  468. package/dist/models/audio/catalog.d.ts.map +1 -1
  469. package/dist/models/audio/errors.d.ts +6 -1
  470. package/dist/models/audio/errors.d.ts.map +1 -1
  471. package/dist/models/audio/runtime.d.ts.map +1 -1
  472. package/dist/models/audio/speech.d.ts +8 -0
  473. package/dist/models/audio/speech.d.ts.map +1 -0
  474. package/dist/models/audio/types.d.ts +93 -0
  475. package/dist/models/audio/types.d.ts.map +1 -1
  476. package/dist/models/calls.d.ts +27 -0
  477. package/dist/models/calls.d.ts.map +1 -0
  478. package/dist/models/catalog-index.d.ts +7 -4
  479. package/dist/models/catalog-index.d.ts.map +1 -1
  480. package/dist/models/catalog.d.ts +55 -3
  481. package/dist/models/catalog.d.ts.map +1 -1
  482. package/dist/models/decision/runtime.d.ts +6 -1
  483. package/dist/models/decision/runtime.d.ts.map +1 -1
  484. package/dist/models/decision/validation.d.ts +4 -1
  485. package/dist/models/decision/validation.d.ts.map +1 -1
  486. package/dist/models/definitions.d.ts +23 -1
  487. package/dist/models/definitions.d.ts.map +1 -1
  488. package/dist/models/events.d.ts +12 -1
  489. package/dist/models/events.d.ts.map +1 -1
  490. package/dist/models/execution/binding.d.ts +3 -1
  491. package/dist/models/execution/binding.d.ts.map +1 -1
  492. package/dist/models/execution/index.d.ts +1 -0
  493. package/dist/models/execution/index.d.ts.map +1 -1
  494. package/dist/models/execution/index.js +44 -34
  495. package/dist/models/execution/index.js.map +1 -1
  496. package/dist/models/execution/model-call-accounting.d.ts.map +1 -1
  497. package/dist/models/execution/model-call-recorder.d.ts +3 -0
  498. package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
  499. package/dist/models/execution/usage.d.ts.map +1 -1
  500. package/dist/models/execution.d.ts +4 -2
  501. package/dist/models/execution.d.ts.map +1 -1
  502. package/dist/models/generation-types.d.ts +8 -1
  503. package/dist/models/generation-types.d.ts.map +1 -1
  504. package/dist/models/image/catalog.d.ts +13 -0
  505. package/dist/models/image/catalog.d.ts.map +1 -0
  506. package/dist/models/image/errors.d.ts +8 -0
  507. package/dist/models/image/errors.d.ts.map +1 -0
  508. package/dist/models/image/runtime.d.ts +8 -0
  509. package/dist/models/image/runtime.d.ts.map +1 -0
  510. package/dist/models/image/types.d.ts +103 -0
  511. package/dist/models/image/types.d.ts.map +1 -0
  512. package/dist/models/index.d.ts +12 -8
  513. package/dist/models/index.d.ts.map +1 -1
  514. package/dist/models/index.js +17 -7
  515. package/dist/models/index.js.map +1 -1
  516. package/dist/models/input-file.d.ts +9 -0
  517. package/dist/models/input-file.d.ts.map +1 -0
  518. package/dist/models/language-model.d.ts +13 -0
  519. package/dist/models/language-model.d.ts.map +1 -1
  520. package/dist/models/pricing.d.ts +25 -10
  521. package/dist/models/pricing.d.ts.map +1 -1
  522. package/dist/models/rate-card.d.ts +44 -6
  523. package/dist/models/rate-card.d.ts.map +1 -1
  524. package/dist/objects/conditional-writes.d.ts +37 -0
  525. package/dist/objects/conditional-writes.d.ts.map +1 -0
  526. package/dist/objects/execution.d.ts +2 -0
  527. package/dist/objects/execution.d.ts.map +1 -1
  528. package/dist/objects/index.d.ts +1 -0
  529. package/dist/objects/index.d.ts.map +1 -1
  530. package/dist/objects/index.js +68 -58
  531. package/dist/objects/index.js.map +1 -1
  532. package/dist/objects/link/authorization.d.ts +3 -0
  533. package/dist/objects/link/authorization.d.ts.map +1 -1
  534. package/dist/objects/link/endpoints.d.ts +21 -2
  535. package/dist/objects/link/endpoints.d.ts.map +1 -1
  536. package/dist/objects/link/remove.d.ts.map +1 -1
  537. package/dist/objects/link/upsert-batch.d.ts.map +1 -1
  538. package/dist/objects/link/upsert.d.ts.map +1 -1
  539. package/dist/objects/materializer-adapter.d.ts +13 -4
  540. package/dist/objects/materializer-adapter.d.ts.map +1 -1
  541. package/dist/objects/object/delete.d.ts +3 -0
  542. package/dist/objects/object/delete.d.ts.map +1 -1
  543. package/dist/objects/object/upsert-batch.d.ts.map +1 -1
  544. package/dist/objects/object/upsert.d.ts.map +1 -1
  545. package/dist/objects/query/current-user.d.ts +17 -0
  546. package/dist/objects/query/current-user.d.ts.map +1 -0
  547. package/dist/objects/query/executor.d.ts +14 -0
  548. package/dist/objects/query/executor.d.ts.map +1 -1
  549. package/dist/objects/query/index.d.ts +2 -2
  550. package/dist/objects/query/index.d.ts.map +1 -1
  551. package/dist/objects/query/index.js +49 -44
  552. package/dist/objects/query/index.js.map +1 -1
  553. package/dist/objects/query/ir.d.ts +19 -1
  554. package/dist/objects/query/ir.d.ts.map +1 -1
  555. package/dist/objects/query/matches-predicate.d.ts +9 -0
  556. package/dist/objects/query/matches-predicate.d.ts.map +1 -0
  557. package/dist/objects/query/normalize.d.ts.map +1 -1
  558. package/dist/objects/query/user-expansions.d.ts +27 -0
  559. package/dist/objects/query/user-expansions.d.ts.map +1 -0
  560. package/dist/objects/query/validate.d.ts.map +1 -1
  561. package/dist/objects/runtime-batch.d.ts +3 -1
  562. package/dist/objects/runtime-batch.d.ts.map +1 -1
  563. package/dist/objects/sdk/object-set.d.ts.map +1 -1
  564. package/dist/objects/sdk/query-executor.d.ts +6 -0
  565. package/dist/objects/sdk/query-executor.d.ts.map +1 -1
  566. package/dist/objects/serialize.d.ts +39 -0
  567. package/dist/objects/serialize.d.ts.map +1 -0
  568. package/dist/objects/unique-violation.d.ts +22 -0
  569. package/dist/objects/unique-violation.d.ts.map +1 -0
  570. package/dist/ontology/builders.d.ts +3 -1
  571. package/dist/ontology/builders.d.ts.map +1 -1
  572. package/dist/ontology/index.d.ts +2 -2
  573. package/dist/ontology/index.d.ts.map +1 -1
  574. package/dist/ontology/index.js +11 -7
  575. package/dist/ontology/index.js.map +1 -1
  576. package/dist/ontology/internal.js +7 -5
  577. package/dist/ontology/internal.js.map +3 -3
  578. package/dist/ontology/json-schema.d.ts.map +1 -1
  579. package/dist/ontology/primitives.d.ts +3 -0
  580. package/dist/ontology/primitives.d.ts.map +1 -1
  581. package/dist/ontology/registry.d.ts +6 -0
  582. package/dist/ontology/registry.d.ts.map +1 -1
  583. package/dist/ontology/types.d.ts +9 -0
  584. package/dist/ontology/types.d.ts.map +1 -1
  585. package/dist/ontology/unique-values.d.ts +26 -0
  586. package/dist/ontology/unique-values.d.ts.map +1 -0
  587. package/dist/ontology/user-ref.d.ts +23 -0
  588. package/dist/ontology/user-ref.d.ts.map +1 -1
  589. package/dist/ontology/validation/properties.d.ts.map +1 -1
  590. package/dist/ontology/validation/schema.d.ts.map +1 -1
  591. package/dist/pipelines/index.js +43 -40
  592. package/dist/pipelines/index.js.map +1 -1
  593. package/dist/projections/internal.js +36 -33
  594. package/dist/projections/internal.js.map +1 -1
  595. package/dist/projections/registry.d.ts +4 -0
  596. package/dist/projections/registry.d.ts.map +1 -1
  597. package/dist/projections/revision.d.ts +15 -0
  598. package/dist/projections/revision.d.ts.map +1 -1
  599. package/dist/projections/run-dispatch.d.ts.map +1 -1
  600. package/dist/projections/types.d.ts +2 -0
  601. package/dist/projections/types.d.ts.map +1 -1
  602. package/dist/query.d.ts +4 -2
  603. package/dist/query.d.ts.map +1 -1
  604. package/dist/query.js +2 -2
  605. package/dist/rules/execution.d.ts.map +1 -1
  606. package/dist/runtime/ai-cost.d.ts +2 -0
  607. package/dist/runtime/ai-cost.d.ts.map +1 -1
  608. package/dist/runtime/ai-usage.d.ts +7 -0
  609. package/dist/runtime/ai-usage.d.ts.map +1 -1
  610. package/dist/runtime/host.d.ts.map +1 -1
  611. package/dist/runtime/index.d.ts +1 -1
  612. package/dist/runtime/index.d.ts.map +1 -1
  613. package/dist/runtime/internal.js +42 -38
  614. package/dist/runtime/internal.js.map +1 -1
  615. package/dist/runtime/resolve-definitions.d.ts.map +1 -1
  616. package/dist/runtime/sixb.d.ts +2 -0
  617. package/dist/runtime/sixb.d.ts.map +1 -1
  618. package/dist/runtime/types.d.ts +66 -8
  619. package/dist/runtime/types.d.ts.map +1 -1
  620. package/dist/sandboxes/index.js +7 -6
  621. package/dist/sandboxes/index.js.map +1 -1
  622. package/dist/schedules/builders.d.ts.map +1 -1
  623. package/dist/schedules/index.js +3 -3
  624. package/dist/schedules/runtime.d.ts.map +1 -1
  625. package/dist/schedules/validation.d.ts.map +1 -1
  626. package/dist/security/grants.d.ts +12 -4
  627. package/dist/security/grants.d.ts.map +1 -1
  628. package/dist/security/index.d.ts +1 -1
  629. package/dist/security/index.d.ts.map +1 -1
  630. package/dist/security/internal.js +1 -1
  631. package/dist/security/project.d.ts +4 -1
  632. package/dist/security/project.d.ts.map +1 -1
  633. package/dist/security/public.js +2 -2
  634. package/dist/security/registry.d.ts +6 -0
  635. package/dist/security/registry.d.ts.map +1 -1
  636. package/dist/security/types.d.ts +47 -9
  637. package/dist/security/types.d.ts.map +1 -1
  638. package/dist/security/validation.d.ts.map +1 -1
  639. package/dist/security/view-conditions.d.ts +37 -0
  640. package/dist/security/view-conditions.d.ts.map +1 -0
  641. package/dist/shares/execution.d.ts.map +1 -1
  642. package/dist/shares/internal.js +34 -31
  643. package/dist/shares/internal.js.map +2 -2
  644. package/dist/storage/action-runs/failure.js +2 -2
  645. package/dist/storage/action-runs/provider.js +1 -1
  646. package/dist/storage/action-runs/types.d.ts +1 -1
  647. package/dist/storage/action-runs/types.d.ts.map +1 -1
  648. package/dist/storage/agents/errors.d.ts +3 -1
  649. package/dist/storage/agents/errors.d.ts.map +1 -1
  650. package/dist/storage/agents/in-memory.d.ts +120 -3
  651. package/dist/storage/agents/in-memory.d.ts.map +1 -1
  652. package/dist/storage/agents/index.d.ts +2 -2
  653. package/dist/storage/agents/index.d.ts.map +1 -1
  654. package/dist/storage/agents/provider.d.ts +154 -4
  655. package/dist/storage/agents/provider.d.ts.map +1 -1
  656. package/dist/storage/agents/provider.js +60 -5
  657. package/dist/storage/agents/provider.js.map +1 -1
  658. package/dist/storage/agents/types.d.ts +565 -13
  659. package/dist/storage/agents/types.d.ts.map +1 -1
  660. package/dist/storage/ai-cost/analytics.d.ts +10 -1
  661. package/dist/storage/ai-cost/analytics.d.ts.map +1 -1
  662. package/dist/storage/ai-cost/groups.d.ts +9 -0
  663. package/dist/storage/ai-cost/groups.d.ts.map +1 -1
  664. package/dist/storage/ai-cost/index.d.ts +1 -1
  665. package/dist/storage/ai-cost/index.d.ts.map +1 -1
  666. package/dist/storage/ai-cost/provider.d.ts +2 -1
  667. package/dist/storage/ai-cost/provider.d.ts.map +1 -1
  668. package/dist/storage/ai-cost/provider.js +11 -5
  669. package/dist/storage/ai-cost/provider.js.map +1 -1
  670. package/dist/storage/ai-cost/types.d.ts +14 -2
  671. package/dist/storage/ai-cost/types.d.ts.map +1 -1
  672. package/dist/storage/ai-cost/validation.d.ts.map +1 -1
  673. package/dist/storage/ai-limits/enforcement.js +5 -4
  674. package/dist/storage/ai-limits/enforcement.js.map +1 -1
  675. package/dist/storage/ai-limits/provider.d.ts +1 -1
  676. package/dist/storage/ai-limits/provider.d.ts.map +1 -1
  677. package/dist/storage/ai-limits/provider.js +3 -2
  678. package/dist/storage/ai-limits/provider.js.map +1 -1
  679. package/dist/storage/ai-usage/in-memory.d.ts +5 -1
  680. package/dist/storage/ai-usage/in-memory.d.ts.map +1 -1
  681. package/dist/storage/ai-usage/index.d.ts +2 -2
  682. package/dist/storage/ai-usage/index.d.ts.map +1 -1
  683. package/dist/storage/ai-usage/record.d.ts +5 -1
  684. package/dist/storage/ai-usage/record.d.ts.map +1 -1
  685. package/dist/storage/ai-usage/types.d.ts +33 -0
  686. package/dist/storage/ai-usage/types.d.ts.map +1 -1
  687. package/dist/storage/ai-usage/usage.d.ts +2 -0
  688. package/dist/storage/ai-usage/usage.d.ts.map +1 -1
  689. package/dist/storage/artifacts/errors.d.ts +12 -2
  690. package/dist/storage/artifacts/errors.d.ts.map +1 -1
  691. package/dist/storage/artifacts/in-memory.d.ts +23 -2
  692. package/dist/storage/artifacts/in-memory.d.ts.map +1 -1
  693. package/dist/storage/artifacts/index.d.ts +2 -2
  694. package/dist/storage/artifacts/index.d.ts.map +1 -1
  695. package/dist/storage/artifacts/record.d.ts +19 -2
  696. package/dist/storage/artifacts/record.d.ts.map +1 -1
  697. package/dist/storage/artifacts/types.d.ts +87 -8
  698. package/dist/storage/artifacts/types.d.ts.map +1 -1
  699. package/dist/storage/auth/in-memory/auth-storage.d.ts +3 -2
  700. package/dist/storage/auth/in-memory/auth-storage.d.ts.map +1 -1
  701. package/dist/storage/auth/in-memory/users.d.ts +7 -3
  702. package/dist/storage/auth/in-memory/users.d.ts.map +1 -1
  703. package/dist/storage/auth/index.d.ts +1 -1
  704. package/dist/storage/auth/index.d.ts.map +1 -1
  705. package/dist/storage/auth/types.d.ts +40 -9
  706. package/dist/storage/auth/types.d.ts.map +1 -1
  707. package/dist/storage/connector-connections/provider.js +1 -1
  708. package/dist/storage/executions/in-memory.d.ts +2 -1
  709. package/dist/storage/executions/in-memory.d.ts.map +1 -1
  710. package/dist/storage/executions/index.d.ts +1 -1
  711. package/dist/storage/executions/index.d.ts.map +1 -1
  712. package/dist/storage/executions/types.d.ts +15 -0
  713. package/dist/storage/executions/types.d.ts.map +1 -1
  714. package/dist/storage/file-upload-sessions/provider.js +15 -12
  715. package/dist/storage/file-upload-sessions/provider.js.map +1 -1
  716. package/dist/storage/index.d.ts +13 -11
  717. package/dist/storage/index.d.ts.map +1 -1
  718. package/dist/storage/index.js +50 -39
  719. package/dist/storage/index.js.map +1 -1
  720. package/dist/storage/internal.d.ts +2 -2
  721. package/dist/storage/internal.d.ts.map +1 -1
  722. package/dist/storage/internal.js +19 -8
  723. package/dist/storage/internal.js.map +1 -1
  724. package/dist/storage/migrations/migrate-storage.d.ts +4 -1
  725. package/dist/storage/migrations/migrate-storage.d.ts.map +1 -1
  726. package/dist/storage/migrations/prepare-unique-properties.d.ts +18 -0
  727. package/dist/storage/migrations/prepare-unique-properties.d.ts.map +1 -0
  728. package/dist/storage/objects/guard.d.ts +1 -1
  729. package/dist/storage/objects/guard.d.ts.map +1 -1
  730. package/dist/storage/objects/in-memory/conditional-reader.d.ts +5 -0
  731. package/dist/storage/objects/in-memory/conditional-reader.d.ts.map +1 -0
  732. package/dist/storage/objects/in-memory/query.d.ts.map +1 -1
  733. package/dist/storage/objects/in-memory/read-scope.d.ts +3 -9
  734. package/dist/storage/objects/in-memory/read-scope.d.ts.map +1 -1
  735. package/dist/storage/objects/in-memory/read-source.d.ts +10 -1
  736. package/dist/storage/objects/in-memory/read-source.d.ts.map +1 -1
  737. package/dist/storage/objects/in-memory/scoped-reader.d.ts +14 -0
  738. package/dist/storage/objects/in-memory/scoped-reader.d.ts.map +1 -0
  739. package/dist/storage/objects/in-memory/selected-reader.d.ts.map +1 -1
  740. package/dist/storage/objects/in-memory/storage.d.ts +36 -1
  741. package/dist/storage/objects/in-memory/storage.d.ts.map +1 -1
  742. package/dist/storage/objects/index.d.ts +2 -2
  743. package/dist/storage/objects/index.d.ts.map +1 -1
  744. package/dist/storage/objects/read-scope.d.ts +9 -1
  745. package/dist/storage/objects/read-scope.d.ts.map +1 -1
  746. package/dist/storage/objects/types.d.ts +64 -1
  747. package/dist/storage/objects/types.d.ts.map +1 -1
  748. package/dist/storage/ontology/in-memory/index.d.ts +2 -0
  749. package/dist/storage/ontology/in-memory/index.d.ts.map +1 -1
  750. package/dist/storage/ontology/in-memory/materializations.d.ts +1 -0
  751. package/dist/storage/ontology/in-memory/materializations.d.ts.map +1 -1
  752. package/dist/storage/ontology/in-memory/replacement-plans.d.ts.map +1 -1
  753. package/dist/storage/ontology/in-memory/unique-values.d.ts +32 -0
  754. package/dist/storage/ontology/in-memory/unique-values.d.ts.map +1 -0
  755. package/dist/storage/ontology/index.d.ts +4 -1
  756. package/dist/storage/ontology/index.d.ts.map +1 -1
  757. package/dist/storage/ontology/materializations.d.ts +34 -1
  758. package/dist/storage/ontology/materializations.d.ts.map +1 -1
  759. package/dist/storage/ontology/provider-work.d.ts +15 -2
  760. package/dist/storage/ontology/provider-work.d.ts.map +1 -1
  761. package/dist/storage/ontology/provider.d.ts +1 -1
  762. package/dist/storage/ontology/provider.d.ts.map +1 -1
  763. package/dist/storage/ontology/provider.js +9 -4
  764. package/dist/storage/ontology/provider.js.map +1 -1
  765. package/dist/storage/ontology/unique-values.d.ts +54 -0
  766. package/dist/storage/ontology/unique-values.d.ts.map +1 -0
  767. package/dist/storage/operation-scope.d.ts +1 -1
  768. package/dist/storage/operation-scope.d.ts.map +1 -1
  769. package/dist/storage/operation-scope.js +1 -1
  770. package/dist/storage/projection-runs/in-memory.d.ts +0 -6
  771. package/dist/storage/projection-runs/in-memory.d.ts.map +1 -1
  772. package/dist/storage/projection-runs/provider.js +2 -2
  773. package/dist/storage/share-grants/provider.js +4 -3
  774. package/dist/storage/share-grants/provider.js.map +1 -1
  775. package/dist/storage/types.d.ts +2 -2
  776. package/dist/storage/types.d.ts.map +1 -1
  777. package/dist/storage/workflow-runs/provider.js +15 -12
  778. package/dist/storage/workflow-runs/provider.js.map +1 -1
  779. package/dist/syncs/index.js +42 -39
  780. package/dist/syncs/index.js.map +1 -1
  781. package/dist/testing/agent-approval-storage-contract.d.ts +17 -0
  782. package/dist/testing/agent-approval-storage-contract.d.ts.map +1 -0
  783. package/dist/testing/agent-memory-storage-contract.d.ts +12 -0
  784. package/dist/testing/agent-memory-storage-contract.d.ts.map +1 -0
  785. package/dist/testing/agent-storage-contract.d.ts.map +1 -1
  786. package/dist/testing/ai-cost-storage-contract.d.ts.map +1 -1
  787. package/dist/testing/ai-limit-storage-contract.d.ts +0 -1
  788. package/dist/testing/ai-limit-storage-contract.d.ts.map +1 -1
  789. package/dist/testing/ai-model-call-groups-contract.d.ts.map +1 -1
  790. package/dist/testing/ai-usage-storage-contract.d.ts.map +1 -1
  791. package/dist/testing/artifact-storage-contract.d.ts.map +1 -1
  792. package/dist/testing/auth-storage-contract.d.ts +13 -0
  793. package/dist/testing/auth-storage-contract.d.ts.map +1 -1
  794. package/dist/testing/broker-contract.d.ts +5 -0
  795. package/dist/testing/broker-contract.d.ts.map +1 -1
  796. package/dist/testing/effective-storage-contract.d.ts.map +1 -1
  797. package/dist/testing/execution-storage-contract.d.ts.map +1 -1
  798. package/dist/testing/file-upload-session-storage-contract.d.ts.map +1 -1
  799. package/dist/testing/index.d.ts +9 -5
  800. package/dist/testing/index.d.ts.map +1 -1
  801. package/dist/testing/index.js +7938 -3743
  802. package/dist/testing/index.js.map +29 -25
  803. package/dist/testing/lake-storage-contract.d.ts.map +1 -1
  804. package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
  805. package/dist/testing/object-conditional-read-scope-contract.d.ts +11 -0
  806. package/dist/testing/object-conditional-read-scope-contract.d.ts.map +1 -0
  807. package/dist/testing/object-query-contract.d.ts +0 -2
  808. package/dist/testing/object-query-contract.d.ts.map +1 -1
  809. package/dist/testing/ontology-storage-contract.d.ts.map +1 -1
  810. package/dist/testing/projection-run-storage-contract.d.ts.map +1 -1
  811. package/dist/testing/queues-contract.d.ts +5 -0
  812. package/dist/testing/queues-contract.d.ts.map +1 -1
  813. package/dist/testing/sandboxes-contract.d.ts.map +1 -1
  814. package/dist/testing/share-grant-storage-contract.d.ts.map +1 -1
  815. package/dist/testing/share-session-storage-contract.d.ts.map +1 -1
  816. package/dist/testing/unique-values-contract.d.ts +21 -0
  817. package/dist/testing/unique-values-contract.d.ts.map +1 -0
  818. package/dist/testing/webhook-execution.d.ts +0 -8
  819. package/dist/testing/webhook-execution.d.ts.map +1 -1
  820. package/dist/testing/webhook-run-storage-contract.d.ts.map +1 -1
  821. package/dist/users/execution.d.ts +40 -0
  822. package/dist/users/execution.d.ts.map +1 -0
  823. package/dist/users/index.d.ts +3 -0
  824. package/dist/users/index.d.ts.map +1 -0
  825. package/dist/webhooks/internal.js +34 -31
  826. package/dist/webhooks/internal.js.map +2 -2
  827. package/dist/workers/index.js +4 -6
  828. package/dist/workers/index.js.map +4 -4
  829. package/dist/workers/queue-worker.d.ts +0 -2
  830. package/dist/workers/queue-worker.d.ts.map +1 -1
  831. package/dist/workers/worker.d.ts +0 -2
  832. package/dist/workers/worker.d.ts.map +1 -1
  833. package/dist/workflows/builders.d.ts.map +1 -1
  834. package/dist/workflows/index.js +67 -63
  835. package/dist/workflows/index.js.map +1 -1
  836. package/dist/workflows/request.d.ts +12 -1
  837. package/dist/workflows/request.d.ts.map +1 -1
  838. package/dist/workflows/types.d.ts +6 -2
  839. package/dist/workflows/types.d.ts.map +1 -1
  840. package/dist/workflows/validation.d.ts.map +1 -1
  841. package/package.json +1 -1
  842. package/src/actions/commit-edits.ts +6 -1
  843. package/src/actions/execution.ts +42 -15
  844. package/src/actions/read-facade.ts +33 -0
  845. package/src/actions/request.ts +224 -71
  846. package/src/actions/run/context.ts +47 -1
  847. package/src/actions/run/execute.ts +13 -6
  848. package/src/actions/run/executor.ts +11 -2
  849. package/src/actions/run/normalize.ts +12 -2
  850. package/src/actions/run/phases.ts +2 -0
  851. package/src/actions/run/run-action.ts +12 -3
  852. package/src/actions/run/signals.ts +3 -9
  853. package/src/actions/run/types.ts +17 -1
  854. package/src/actions/run-authorization.ts +72 -0
  855. package/src/actions/types/context.ts +20 -3
  856. package/src/actions/validators.ts +19 -8
  857. package/src/activity/README.md +5 -2
  858. package/src/activity/timeline.ts +39 -78
  859. package/src/agents/accounting.ts +59 -0
  860. package/src/agents/adapters.ts +10 -0
  861. package/src/agents/agent-mail.ts +29 -0
  862. package/src/agents/api-gateway.ts +14 -3
  863. package/src/agents/approval-continuation.ts +48 -0
  864. package/src/agents/approval-executor.ts +318 -0
  865. package/src/agents/approval-outcome.ts +59 -0
  866. package/src/agents/approvals.ts +566 -0
  867. package/src/agents/authority.ts +24 -1
  868. package/src/agents/builders.ts +5 -3
  869. package/src/agents/cancel.ts +103 -0
  870. package/src/agents/child-question.ts +46 -0
  871. package/src/agents/children.ts +404 -0
  872. package/src/agents/context-compaction.ts +12 -0
  873. package/src/agents/errors.ts +31 -0
  874. package/src/agents/execution.ts +788 -90
  875. package/src/agents/fork.ts +158 -0
  876. package/src/agents/ids.ts +18 -6
  877. package/src/agents/index.ts +55 -0
  878. package/src/agents/memory-execution.ts +186 -0
  879. package/src/agents/memory.ts +178 -0
  880. package/src/agents/message.ts +57 -0
  881. package/src/agents/model-loop.ts +93 -6
  882. package/src/agents/model-routing.ts +193 -0
  883. package/src/agents/participants.ts +213 -0
  884. package/src/agents/reference.ts +2 -0
  885. package/src/agents/request.ts +398 -69
  886. package/src/agents/run-scope.ts +134 -0
  887. package/src/agents/streams/index.ts +5 -0
  888. package/src/agents/streams/internal.ts +1 -0
  889. package/src/agents/streams/protocol.ts +385 -7
  890. package/src/agents/subagent-runs.ts +41 -0
  891. package/src/agents/thread-access.ts +137 -0
  892. package/src/agents/tool-definition.ts +5 -3
  893. package/src/agents/types.ts +35 -10
  894. package/src/agents/validation.ts +2 -0
  895. package/src/artifacts/access.ts +125 -0
  896. package/src/artifacts/canvas.ts +369 -0
  897. package/src/artifacts/csv.ts +10 -0
  898. package/src/artifacts/errors.ts +12 -1
  899. package/src/artifacts/execution.ts +436 -36
  900. package/src/artifacts/formula/check.ts +171 -0
  901. package/src/artifacts/formula/evaluate.ts +288 -0
  902. package/src/artifacts/formula/index.ts +199 -0
  903. package/src/artifacts/formula/parser.ts +357 -0
  904. package/src/artifacts/frames/assets.ts +35 -19
  905. package/src/artifacts/frames/entries.ts +35 -0
  906. package/src/artifacts/frames/grants.ts +10 -9
  907. package/src/artifacts/frames/index.ts +8 -2
  908. package/src/artifacts/frames/kit.ts +191 -14
  909. package/src/artifacts/frames/probe.ts +66 -18
  910. package/src/artifacts/frames/protocol.ts +164 -10
  911. package/src/artifacts/frames/runtime.ts +273 -28
  912. package/src/artifacts/index.ts +66 -2
  913. package/src/artifacts/kinds.ts +1 -1
  914. package/src/artifacts/limits.ts +31 -0
  915. package/src/artifacts/live-sheet.ts +345 -0
  916. package/src/artifacts/outline.ts +34 -1
  917. package/src/artifacts/publish/index.ts +2 -0
  918. package/src/artifacts/publish/publish.ts +120 -34
  919. package/src/artifacts/publish/queries.ts +336 -0
  920. package/src/artifacts/publish/references.ts +18 -13
  921. package/src/artifacts/publish/validate/canvas.ts +118 -0
  922. package/src/artifacts/publish/validate/html.ts +78 -0
  923. package/src/artifacts/publish/validate/page.ts +65 -0
  924. package/src/artifacts/publish/validate/sheet.ts +115 -69
  925. package/src/artifacts/publish/validate/slides.ts +11 -63
  926. package/src/artifacts/queries.ts +512 -0
  927. package/src/artifacts/resolve.ts +20 -5
  928. package/src/artifacts/run-query.ts +212 -0
  929. package/src/artifacts/serialize-query.ts +25 -0
  930. package/src/artifacts/sheet-rules.ts +180 -0
  931. package/src/artifacts/tones.ts +20 -0
  932. package/src/artifacts/workbook.ts +374 -15
  933. package/src/auth/index.ts +4 -0
  934. package/src/auth/member-events.ts +114 -0
  935. package/src/auth/profile.ts +118 -0
  936. package/src/auth/runtime.ts +190 -9
  937. package/src/auth/strategy.ts +3 -0
  938. package/src/auth/types.ts +32 -0
  939. package/src/authorization/decision.ts +47 -0
  940. package/src/authorization/event-visibility.ts +17 -16
  941. package/src/authorization/grant-kinds.ts +32 -0
  942. package/src/authorization/index.ts +6 -1
  943. package/src/authorization/resolve.ts +58 -1
  944. package/src/authorization/run-visibility.ts +8 -1
  945. package/src/authorization/types.ts +14 -0
  946. package/src/errors/catalog.ts +26 -1
  947. package/src/errors/internal.ts +17 -8
  948. package/src/events/definitions.ts +26 -0
  949. package/src/events/execution.ts +43 -6
  950. package/src/events/index.ts +10 -1
  951. package/src/events/scope.ts +2 -0
  952. package/src/events/selectors/builder.ts +50 -0
  953. package/src/events/selectors/index.ts +4 -0
  954. package/src/events/selectors/types.ts +32 -1
  955. package/src/events/service.ts +55 -2
  956. package/src/events/types/index.ts +10 -0
  957. package/src/events/types/users.ts +73 -0
  958. package/src/events/view-conditions.ts +241 -0
  959. package/src/execution/agent.ts +25 -0
  960. package/src/execution/authorization.ts +70 -0
  961. package/src/execution/authorized-object-reader.ts +238 -32
  962. package/src/execution/lineage.ts +14 -0
  963. package/src/execution/object-reader-ontology.ts +11 -14
  964. package/src/execution/object-reader-security.ts +134 -10
  965. package/src/execution/object-reader-users.ts +122 -0
  966. package/src/execution/preparation.ts +78 -0
  967. package/src/execution/request.ts +2 -0
  968. package/src/execution/unique-lookup.ts +55 -0
  969. package/src/execution/visible-objects.ts +26 -0
  970. package/src/http/api-routes.ts +206 -7
  971. package/src/index.ts +99 -2
  972. package/src/materialization/errors.ts +37 -0
  973. package/src/materialization/event-envelopes.ts +11 -3
  974. package/src/materialization/index.ts +1 -0
  975. package/src/materialization/model.ts +24 -4
  976. package/src/materializer/README.md +7 -1
  977. package/src/materializer/edits/commit.ts +56 -12
  978. package/src/materializer/edits/load-state.ts +15 -7
  979. package/src/materializer/edits/operations.ts +12 -0
  980. package/src/materializer/edits/plan.ts +2 -0
  981. package/src/materializer/edits/unique-values.ts +255 -0
  982. package/src/materializer/edits/working-state.ts +8 -1
  983. package/src/materializer/execution/work-records.ts +47 -0
  984. package/src/materializer/projections/finish-run.ts +0 -1
  985. package/src/materializer/projections/replace.ts +1 -1
  986. package/src/materializer/projections/replacement-plan.ts +4 -1
  987. package/src/materializer/projections/source-materialization.ts +2 -1
  988. package/src/materializer/shared/normalize.ts +37 -6
  989. package/src/materializer/shared/projection-run.ts +1 -2
  990. package/src/materializer/telemetry/append.ts +14 -17
  991. package/src/materializer/telemetry/plan.ts +2 -0
  992. package/src/models/audio/catalog.ts +89 -10
  993. package/src/models/audio/errors.ts +18 -1
  994. package/src/models/audio/runtime.ts +10 -13
  995. package/src/models/audio/speech.ts +261 -0
  996. package/src/models/audio/types.ts +97 -0
  997. package/src/models/calls.ts +100 -0
  998. package/src/models/catalog-index.ts +21 -2
  999. package/src/models/catalog.ts +211 -35
  1000. package/src/models/decision/runtime.ts +21 -22
  1001. package/src/models/decision/validation.ts +4 -1
  1002. package/src/models/definitions.ts +57 -8
  1003. package/src/models/events.ts +72 -1
  1004. package/src/models/execution/README.md +34 -5
  1005. package/src/models/execution/binding.ts +3 -1
  1006. package/src/models/execution/embedding.ts +1 -0
  1007. package/src/models/execution/index.ts +5 -0
  1008. package/src/models/execution/model-call-accounting.ts +3 -1
  1009. package/src/models/execution/model-call-recorder.ts +29 -1
  1010. package/src/models/execution/usage.ts +8 -0
  1011. package/src/models/execution.ts +20 -22
  1012. package/src/models/generation-types.ts +8 -1
  1013. package/src/models/image/catalog.ts +89 -0
  1014. package/src/models/image/errors.ts +19 -0
  1015. package/src/models/image/runtime.ts +335 -0
  1016. package/src/models/image/types.ts +111 -0
  1017. package/src/models/index.ts +38 -4
  1018. package/src/models/{audio/file.ts → input-file.ts} +22 -13
  1019. package/src/models/language-model.ts +13 -0
  1020. package/src/models/pricing.ts +263 -42
  1021. package/src/models/rate-card.ts +161 -12
  1022. package/src/objects/authorized-ontology-view.ts +1 -0
  1023. package/src/objects/conditional-writes.ts +109 -0
  1024. package/src/objects/execution.ts +4 -0
  1025. package/src/objects/index.ts +8 -0
  1026. package/src/objects/link/authorization.ts +12 -3
  1027. package/src/objects/link/endpoints.ts +42 -11
  1028. package/src/objects/link/remove.ts +25 -10
  1029. package/src/objects/link/upsert-batch.ts +2 -0
  1030. package/src/objects/link/upsert.ts +18 -12
  1031. package/src/objects/materializer-adapter.ts +55 -18
  1032. package/src/objects/object/delete.ts +24 -7
  1033. package/src/objects/object/upsert-batch.ts +44 -14
  1034. package/src/objects/object/upsert.ts +23 -5
  1035. package/src/objects/query/current-user.ts +76 -0
  1036. package/src/objects/query/executor.ts +39 -103
  1037. package/src/objects/query/explain.ts +20 -7
  1038. package/src/objects/query/index.ts +2 -0
  1039. package/src/objects/query/ir.ts +20 -0
  1040. package/src/objects/query/links.ts +8 -0
  1041. package/src/objects/query/matches-predicate.ts +108 -0
  1042. package/src/objects/query/normalize.ts +50 -19
  1043. package/src/objects/query/scalar-values.ts +19 -3
  1044. package/src/objects/query/user-expansions.ts +65 -0
  1045. package/src/objects/query/validate.ts +248 -10
  1046. package/src/objects/runtime-batch.ts +8 -2
  1047. package/src/objects/sdk/object-set.ts +12 -1
  1048. package/src/objects/sdk/query-builder.ts +39 -8
  1049. package/src/objects/sdk/query-executor.ts +6 -0
  1050. package/src/objects/serialize.ts +79 -0
  1051. package/src/objects/unique-violation.ts +59 -0
  1052. package/src/objects/vectors/handle.ts +3 -3
  1053. package/src/ontology/builders.ts +3 -0
  1054. package/src/ontology/docs-markdown.ts +1 -0
  1055. package/src/ontology/index.ts +2 -2
  1056. package/src/ontology/json-schema.ts +4 -0
  1057. package/src/ontology/primitives.ts +21 -8
  1058. package/src/ontology/registry.ts +16 -0
  1059. package/src/ontology/types.ts +9 -0
  1060. package/src/ontology/unique-values.ts +84 -0
  1061. package/src/ontology/user-ref.ts +39 -0
  1062. package/src/ontology/validation/properties.ts +43 -0
  1063. package/src/ontology/validation/schema.ts +9 -1
  1064. package/src/projections/registry.ts +16 -10
  1065. package/src/projections/revision.ts +112 -45
  1066. package/src/projections/run-dispatch.ts +38 -25
  1067. package/src/projections/types.ts +2 -0
  1068. package/src/query.ts +5 -0
  1069. package/src/rules/execution.ts +43 -11
  1070. package/src/runtime/ai-cost.ts +30 -0
  1071. package/src/runtime/ai-usage.ts +32 -1
  1072. package/src/runtime/host.ts +18 -1
  1073. package/src/runtime/index.ts +2 -0
  1074. package/src/runtime/resolve-definitions.ts +3 -0
  1075. package/src/runtime/sixb.ts +35 -8
  1076. package/src/runtime/types.ts +99 -9
  1077. package/src/schedules/builders.ts +3 -1
  1078. package/src/schedules/runtime.ts +6 -0
  1079. package/src/schedules/validation.ts +23 -1
  1080. package/src/security/README.md +62 -0
  1081. package/src/security/grants.ts +155 -10
  1082. package/src/security/index.ts +3 -1
  1083. package/src/security/project.ts +6 -1
  1084. package/src/security/registry.ts +32 -7
  1085. package/src/security/types.ts +54 -9
  1086. package/src/security/validation.ts +27 -11
  1087. package/src/security/view-conditions.ts +215 -0
  1088. package/src/shares/execution.ts +43 -10
  1089. package/src/storage/action-runs/types.ts +2 -0
  1090. package/src/storage/agents/errors.ts +3 -0
  1091. package/src/storage/agents/in-memory.ts +779 -32
  1092. package/src/storage/agents/index.ts +42 -0
  1093. package/src/storage/agents/provider.ts +733 -8
  1094. package/src/storage/agents/types.ts +620 -12
  1095. package/src/storage/ai-cost/analytics.ts +60 -7
  1096. package/src/storage/ai-cost/codec.ts +6 -1
  1097. package/src/storage/ai-cost/groups.ts +44 -1
  1098. package/src/storage/ai-cost/index.ts +1 -0
  1099. package/src/storage/ai-cost/provider.ts +2 -0
  1100. package/src/storage/ai-cost/types.ts +18 -1
  1101. package/src/storage/ai-cost/validation.ts +39 -12
  1102. package/src/storage/ai-limits/provider.ts +4 -7
  1103. package/src/storage/ai-usage/in-memory.ts +28 -1
  1104. package/src/storage/ai-usage/index.ts +9 -1
  1105. package/src/storage/ai-usage/record.ts +44 -7
  1106. package/src/storage/ai-usage/types.ts +38 -0
  1107. package/src/storage/ai-usage/usage.ts +15 -1
  1108. package/src/storage/artifacts/errors.ts +13 -1
  1109. package/src/storage/artifacts/in-memory.ts +156 -8
  1110. package/src/storage/artifacts/index.ts +6 -1
  1111. package/src/storage/artifacts/record.ts +61 -1
  1112. package/src/storage/artifacts/types.ts +92 -8
  1113. package/src/storage/auth/in-memory/auth-storage.ts +27 -2
  1114. package/src/storage/auth/in-memory/users.ts +40 -6
  1115. package/src/storage/auth/index.ts +1 -0
  1116. package/src/storage/auth/types.ts +43 -7
  1117. package/src/storage/executions/in-memory.ts +32 -0
  1118. package/src/storage/executions/index.ts +2 -0
  1119. package/src/storage/executions/types.ts +17 -0
  1120. package/src/storage/index.ts +69 -1
  1121. package/src/storage/internal.ts +9 -1
  1122. package/src/storage/migrations/migrate-storage.ts +8 -1
  1123. package/src/storage/migrations/prepare-unique-properties.ts +161 -0
  1124. package/src/storage/objects/guard.ts +7 -3
  1125. package/src/storage/objects/in-memory/conditional-reader.ts +72 -0
  1126. package/src/storage/objects/in-memory/query.ts +4 -105
  1127. package/src/storage/objects/in-memory/read-scope.ts +15 -14
  1128. package/src/storage/objects/in-memory/read-source.ts +11 -1
  1129. package/src/storage/objects/in-memory/scoped-reader.ts +243 -0
  1130. package/src/storage/objects/in-memory/selected-reader.ts +6 -231
  1131. package/src/storage/objects/in-memory/storage.ts +183 -1
  1132. package/src/storage/objects/index.ts +9 -1
  1133. package/src/storage/objects/read-scope.ts +191 -0
  1134. package/src/storage/objects/types.ts +68 -1
  1135. package/src/storage/ontology/in-memory/index.ts +3 -0
  1136. package/src/storage/ontology/in-memory/materializations.ts +35 -0
  1137. package/src/storage/ontology/in-memory/replacement-plans.ts +4 -0
  1138. package/src/storage/ontology/in-memory/unique-values.ts +62 -0
  1139. package/src/storage/ontology/index.ts +10 -0
  1140. package/src/storage/ontology/materializations.ts +35 -1
  1141. package/src/storage/ontology/provider-work.ts +76 -0
  1142. package/src/storage/ontology/provider.ts +3 -0
  1143. package/src/storage/ontology/unique-values.ts +56 -0
  1144. package/src/storage/operation-scope.ts +9 -1
  1145. package/src/storage/projection-runs/in-memory.ts +3 -35
  1146. package/src/storage/types.ts +2 -0
  1147. package/src/testing/agent-approval-storage-contract.ts +1117 -0
  1148. package/src/testing/agent-memory-storage-contract.ts +400 -0
  1149. package/src/testing/agent-storage-contract.ts +1188 -33
  1150. package/src/testing/ai-cost-storage-contract.ts +31 -1
  1151. package/src/testing/ai-limit-storage-contract.ts +9 -7
  1152. package/src/testing/ai-model-call-groups-contract.ts +76 -0
  1153. package/src/testing/ai-usage-storage-contract.ts +120 -13
  1154. package/src/testing/artifact-storage-contract.ts +338 -4
  1155. package/src/testing/auth-storage-contract.ts +550 -73
  1156. package/src/testing/broker-contract.ts +28 -23
  1157. package/src/testing/effective-storage-contract.ts +3 -8
  1158. package/src/testing/execution-storage-contract.ts +53 -0
  1159. package/src/testing/file-upload-session-storage-contract.ts +12 -24
  1160. package/src/testing/index.ts +17 -4
  1161. package/src/testing/lake-storage-contract.ts +22 -28
  1162. package/src/testing/materializer-storage-contract.ts +36 -9
  1163. package/src/testing/object-conditional-read-scope-contract.ts +634 -0
  1164. package/src/testing/object-query-contract.ts +386 -186
  1165. package/src/testing/ontology-storage-contract.ts +230 -21
  1166. package/src/testing/projection-run-storage-contract.ts +8 -18
  1167. package/src/testing/queues-contract.ts +39 -70
  1168. package/src/testing/sandboxes-contract.ts +3 -14
  1169. package/src/testing/share-grant-storage-contract.ts +13 -16
  1170. package/src/testing/share-session-storage-contract.ts +4 -14
  1171. package/src/testing/unique-values-contract.ts +907 -0
  1172. package/src/testing/webhook-execution.ts +1 -1
  1173. package/src/testing/webhook-run-storage-contract.ts +6 -9
  1174. package/src/users/execution.ts +131 -0
  1175. package/src/users/index.ts +2 -0
  1176. package/src/workers/queue-worker.ts +1 -3
  1177. package/src/workers/worker.ts +1 -3
  1178. package/src/workflows/builders.ts +6 -0
  1179. package/src/workflows/request.ts +46 -8
  1180. package/src/workflows/types.ts +6 -2
  1181. package/src/workflows/validation.ts +23 -9
  1182. package/dist/chunk-29yx306f.js.map +0 -22
  1183. package/dist/chunk-3jms7je7.js +0 -14
  1184. package/dist/chunk-3jms7je7.js.map +0 -10
  1185. package/dist/chunk-3qct2mdc.js +0 -297
  1186. package/dist/chunk-3qct2mdc.js.map +0 -12
  1187. package/dist/chunk-48qjhh6v.js.map +0 -13
  1188. package/dist/chunk-4as3wt1c.js.map +0 -12
  1189. package/dist/chunk-5948n82c.js.map +0 -10
  1190. package/dist/chunk-5hx48dnn.js.map +0 -14
  1191. package/dist/chunk-6rqgmkde.js.map +0 -29
  1192. package/dist/chunk-6x0pqh32.js.map +0 -10
  1193. package/dist/chunk-7n30ybym.js +0 -3
  1194. package/dist/chunk-7n440zgt.js +0 -261
  1195. package/dist/chunk-7n440zgt.js.map +0 -12
  1196. package/dist/chunk-7q8t23v4.js +0 -467
  1197. package/dist/chunk-7q8t23v4.js.map +0 -14
  1198. package/dist/chunk-8frc8a4j.js.map +0 -20
  1199. package/dist/chunk-918wwnaa.js.map +0 -68
  1200. package/dist/chunk-91mg3nj9.js.map +0 -12
  1201. package/dist/chunk-96yw3pwd.js.map +0 -10
  1202. package/dist/chunk-9j4jw7as.js.map +0 -14
  1203. package/dist/chunk-9k93ah50.js.map +0 -11
  1204. package/dist/chunk-9kgkfg6v.js +0 -502
  1205. package/dist/chunk-9kgkfg6v.js.map +0 -14
  1206. package/dist/chunk-akzryx9h.js.map +0 -100
  1207. package/dist/chunk-arns890k.js.map +0 -10
  1208. package/dist/chunk-bk9svbcq.js.map +0 -49
  1209. package/dist/chunk-c06hmxyy.js +0 -31
  1210. package/dist/chunk-c06hmxyy.js.map +0 -10
  1211. package/dist/chunk-c1rxbz5y.js.map +0 -12
  1212. package/dist/chunk-cn0fwwhy.js.map +0 -19
  1213. package/dist/chunk-dhcv7yxc.js.map +0 -11
  1214. package/dist/chunk-dhdha526.js.map +0 -10
  1215. package/dist/chunk-dvd2fp9q.js.map +0 -13
  1216. package/dist/chunk-e6k4thh5.js.map +0 -19
  1217. package/dist/chunk-ere85b8y.js.map +0 -15
  1218. package/dist/chunk-g257jwnc.js.map +0 -12
  1219. package/dist/chunk-hwksyjks.js.map +0 -11
  1220. package/dist/chunk-k43ct2ke.js.map +0 -12
  1221. package/dist/chunk-nn5xnx3s.js.map +0 -40
  1222. package/dist/chunk-pbcbn83d.js.map +0 -14
  1223. package/dist/chunk-pqajwytd.js +0 -68
  1224. package/dist/chunk-pqajwytd.js.map +0 -11
  1225. package/dist/chunk-qczk96d9.js.map +0 -11
  1226. package/dist/chunk-rdghfsss.js +0 -39
  1227. package/dist/chunk-rdghfsss.js.map +0 -10
  1228. package/dist/chunk-rj69qcrd.js.map +0 -11
  1229. package/dist/chunk-v4jbb3rs.js.map +0 -10
  1230. package/dist/chunk-yxd3nnqt.js.map +0 -11
  1231. package/dist/events/toStoredEvent.d.ts +0 -9
  1232. package/dist/events/toStoredEvent.d.ts.map +0 -1
  1233. package/dist/models/audio/file.d.ts +0 -9
  1234. package/dist/models/audio/file.d.ts.map +0 -1
  1235. package/src/events/toStoredEvent.ts +0 -33
  1236. /package/dist/{chunk-mfs23znk.js.map → chunk-07kkp2e1.js.map} +0 -0
  1237. /package/dist/{chunk-z58tm0hm.js.map → chunk-0phpbbvm.js.map} +0 -0
  1238. /package/dist/{chunk-e17zdm62.js.map → chunk-1t6k1avb.js.map} +0 -0
  1239. /package/dist/{chunk-kge7k6ey.js.map → chunk-2fn60nvs.js.map} +0 -0
  1240. /package/dist/{chunk-y0c4e6ex.js.map → chunk-3gbefjg5.js.map} +0 -0
  1241. /package/dist/{chunk-cy4mbddw.js.map → chunk-48jezz3j.js.map} +0 -0
  1242. /package/dist/{chunk-twe4dx8p.js → chunk-5tfev0fv.js} +0 -0
  1243. /package/dist/{chunk-twe4dx8p.js.map → chunk-5tfev0fv.js.map} +0 -0
  1244. /package/dist/{chunk-447a5c0p.js.map → chunk-6n69k945.js.map} +0 -0
  1245. /package/dist/{chunk-0bphap9y.js.map → chunk-6p0pastb.js.map} +0 -0
  1246. /package/dist/{chunk-431pyp2c.js.map → chunk-6y0mkhex.js.map} +0 -0
  1247. /package/dist/{chunk-s7jg7pmn.js.map → chunk-bab05bhg.js.map} +0 -0
  1248. /package/dist/{chunk-q5e5tv4b.js.map → chunk-c844dkwd.js.map} +0 -0
  1249. /package/dist/{chunk-cfj9dfbb.js.map → chunk-d2m879s4.js.map} +0 -0
  1250. /package/dist/{chunk-q7gn29y3.js.map → chunk-dp0cdtj2.js.map} +0 -0
  1251. /package/dist/{chunk-br3k6qbf.js.map → chunk-fm62y49k.js.map} +0 -0
  1252. /package/dist/{chunk-vvxtn22d.js.map → chunk-g663fahq.js.map} +0 -0
  1253. /package/dist/{chunk-rmakanzx.js.map → chunk-h33shhq6.js.map} +0 -0
  1254. /package/dist/{chunk-d09e3rax.js.map → chunk-hwarjrgf.js.map} +0 -0
  1255. /package/dist/{chunk-vf57cr4t.js.map → chunk-hyesv9dv.js.map} +0 -0
  1256. /package/dist/{chunk-5vems3nx.js.map → chunk-m2nevja0.js.map} +0 -0
  1257. /package/dist/{chunk-x9v4cx1d.js.map → chunk-m36fw8ft.js.map} +0 -0
  1258. /package/dist/{chunk-a40ad1ft.js.map → chunk-mbsbxarb.js.map} +0 -0
  1259. /package/dist/{chunk-6aawea28.js.map → chunk-n8q5j6y5.js.map} +0 -0
  1260. /package/dist/{chunk-d7dnxdep.js.map → chunk-n9zpx9c6.js.map} +0 -0
  1261. /package/dist/{chunk-xvsc5m8n.js.map → chunk-npcr0228.js.map} +0 -0
  1262. /package/dist/{chunk-y5tah2kf.js.map → chunk-q4pmvkg0.js.map} +0 -0
  1263. /package/dist/{chunk-d5rjr8c0.js.map → chunk-vabga7fk.js.map} +0 -0
@@ -0,0 +1,2380 @@
1
+ // @bun
2
+ import {
3
+ isArtifactAddress2,
4
+ parseSheetPart2
5
+ } from "./chunk-3fqxbn31.js";
6
+ import {
7
+ ARTIFACT_LIMITS2
8
+ } from "./chunk-hz5d43gn.js";
9
+
10
+ // src/artifacts/theme.ts
11
+ var ARTIFACT_THEME_FILE2 = "theme.json";
12
+ var COLOR_TOKENS = [
13
+ "--background",
14
+ "--foreground",
15
+ "--card",
16
+ "--card-foreground",
17
+ "--muted",
18
+ "--muted-foreground",
19
+ "--primary",
20
+ "--primary-foreground",
21
+ "--accent",
22
+ "--accent-foreground",
23
+ "--border",
24
+ "--chart-1",
25
+ "--chart-2",
26
+ "--chart-3",
27
+ "--chart-4",
28
+ "--chart-5"
29
+ ];
30
+ var FONT_TOKENS = ["--font-sans", "--font-serif", "--font-mono"];
31
+ var ARTIFACT_THEME_TOKENS = [
32
+ ...COLOR_TOKENS,
33
+ ...FONT_TOKENS,
34
+ "--radius"
35
+ ];
36
+ var HEX_COLOR = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
37
+ var FUNCTION_COLOR = /^(?:rgba?|hsla?|oklch|oklab|lab|lch)\((?:[\d.%\s,/+-]|deg|turn|rad|none)*\)$/i;
38
+ var FONT_FAMILY = /^\s*(?:"[\w -]+"|'[\w -]+'|[\w-]+)(?:\s*,\s*(?:"[\w -]+"|'[\w -]+'|[\w-]+))*\s*$/;
39
+ var LENGTH = /^(?:0|\d{1,3}(?:\.\d+)?(?:px|rem|em))$/;
40
+ function parseArtifactTheme2(text) {
41
+ let value;
42
+ try {
43
+ value = JSON.parse(text);
44
+ } catch {
45
+ return { error: `${ARTIFACT_THEME_FILE2} is not valid JSON.` };
46
+ }
47
+ if (!isObject(value))
48
+ return { error: `${ARTIFACT_THEME_FILE2} must be a JSON object.` };
49
+ const unknownKey = Object.keys(value).find((key) => key !== "mode" && key !== "tokens");
50
+ if (unknownKey) {
51
+ return {
52
+ error: `${ARTIFACT_THEME_FILE2} has '${unknownKey}'; it takes only "mode" and "tokens".`
53
+ };
54
+ }
55
+ if (value.mode !== undefined && value.mode !== "light" && value.mode !== "dark") {
56
+ return { error: `${ARTIFACT_THEME_FILE2} "mode" must be "light" or "dark".` };
57
+ }
58
+ if (value.tokens !== undefined && !isObject(value.tokens)) {
59
+ return { error: `${ARTIFACT_THEME_FILE2} "tokens" must be an object of token names to values.` };
60
+ }
61
+ const tokens = {};
62
+ for (const [name, tokenValue] of Object.entries(value.tokens ?? {})) {
63
+ if (!ARTIFACT_THEME_TOKENS.includes(name)) {
64
+ return {
65
+ error: `${ARTIFACT_THEME_FILE2} sets '${name}'. A theme can set ${ARTIFACT_THEME_TOKENS.join(", ")}.`
66
+ };
67
+ }
68
+ if (typeof tokenValue !== "string" || !tokenValueFits(name, tokenValue)) {
69
+ return {
70
+ error: `${ARTIFACT_THEME_FILE2} gives '${name}' a value it cannot use: ${expected(name)}.`
71
+ };
72
+ }
73
+ tokens[name] = tokenValue.trim();
74
+ }
75
+ return {
76
+ theme: {
77
+ ...value.mode === undefined ? {} : { mode: value.mode },
78
+ ...Object.keys(tokens).length === 0 ? {} : { tokens }
79
+ }
80
+ };
81
+ }
82
+ function tokenValueFits(name, value) {
83
+ const trimmed = value.trim();
84
+ if (name === "--radius")
85
+ return LENGTH.test(trimmed);
86
+ if (FONT_TOKENS.includes(name)) {
87
+ return trimmed.length <= 200 && FONT_FAMILY.test(trimmed);
88
+ }
89
+ return HEX_COLOR.test(trimmed) || FUNCTION_COLOR.test(trimmed);
90
+ }
91
+ function expected(name) {
92
+ if (name === "--radius")
93
+ return "a length such as 8px or 0.5rem";
94
+ if (FONT_TOKENS.includes(name)) {
95
+ return 'a font list such as "Inter Tight", system-ui, sans-serif';
96
+ }
97
+ return "a color such as #2f7280 or oklch(0.62 0.1 210)";
98
+ }
99
+ function isObject(value) {
100
+ return typeof value === "object" && value !== null && !Array.isArray(value);
101
+ }
102
+
103
+ // src/artifacts/queries.ts
104
+ var ARTIFACT_QUERIES_DIRECTORY = "queries/";
105
+ var ARTIFACT_QUERY_KINDS = ["sheet", "page", "slides", "canvas"];
106
+ var QUERY_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
107
+ function isArtifactQueryName(name) {
108
+ return QUERY_NAME.test(name);
109
+ }
110
+ function artifactQueryPath(name) {
111
+ return `${ARTIFACT_QUERIES_DIRECTORY}${name}.json`;
112
+ }
113
+ function artifactQueryName2(path) {
114
+ if (!path.startsWith(ARTIFACT_QUERIES_DIRECTORY) || !path.endsWith(".json"))
115
+ return;
116
+ const name = path.slice(ARTIFACT_QUERIES_DIRECTORY.length, -".json".length);
117
+ return isArtifactQueryName(name) ? name : undefined;
118
+ }
119
+
120
+ class QueryShapeError extends Error {
121
+ path;
122
+ constructor(path, message) {
123
+ super(message);
124
+ this.path = path;
125
+ }
126
+ }
127
+ function parseArtifactQuery(path, text) {
128
+ let value;
129
+ try {
130
+ value = JSON.parse(text);
131
+ } catch {
132
+ return { error: `${path} is not valid JSON.` };
133
+ }
134
+ try {
135
+ return readFile(value);
136
+ } catch (error) {
137
+ if (error instanceof QueryShapeError)
138
+ return { error: `${path}: ${error.path}: ${error.message}` };
139
+ throw error;
140
+ }
141
+ }
142
+ function readFile(value) {
143
+ const file = record(value, "$");
144
+ if (Object.hasOwn(file, "kind")) {
145
+ return { query: { kind: "objects", query: readNode(file, "$") }, at: "$" };
146
+ }
147
+ if (!Object.hasOwn(file, "query")) {
148
+ throw new QueryShapeError("$", 'a query file holds a query node, with "kind", or a request, with "query".');
149
+ }
150
+ if (!Object.hasOwn(file, "facets")) {
151
+ only(file, "$", ["query", "includeTotal"], "a query request");
152
+ if (file.includeTotal !== undefined)
153
+ boolean(file, "includeTotal", "$");
154
+ return { query: { kind: "objects", query: readNode(file.query, "$.query") }, at: "$.query" };
155
+ }
156
+ only(file, "$", ["query", "facets"], "a facets request");
157
+ const query = readNode(file.query, "$.query");
158
+ const facets = list(file.facets, "$.facets").map((facet, index) => readFacet(facet, `$.facets[${index}]`));
159
+ if (facets.length === 0)
160
+ throw new QueryShapeError("$.facets", "list at least one facet.");
161
+ return { query: { kind: "facets", query, facets }, at: "$.query" };
162
+ }
163
+ function readFacet(value, path) {
164
+ const facet = record(value, path);
165
+ only(facet, path, ["propertyId", "limit"], "a facet");
166
+ const limit = facet.limit;
167
+ if (typeof limit !== "number" || !Number.isInteger(limit) || limit <= 0) {
168
+ throw new QueryShapeError(`${path}.limit`, "must be a positive whole number.");
169
+ }
170
+ return { propertyId: text(facet, "propertyId", path), limit };
171
+ }
172
+ var NODE_KEYS = {
173
+ start: ["objectTypeId", "includeSubtypes"],
174
+ refs: ["refs"],
175
+ filter: ["input", "predicate"],
176
+ text: ["input", "query", "fields"],
177
+ traverse: ["input", "linkId", "direction", "sourceObjectTypeId"],
178
+ set: ["op", "inputs"],
179
+ sort: ["input", "fields"],
180
+ limit: ["input", "limit"],
181
+ project: ["input", "properties"],
182
+ expand: ["input", "expansions", "users"]
183
+ };
184
+ var REFUSED_NODES = {
185
+ page: 'Sixb pages the result for each reader; bound the query with "limit" instead.',
186
+ vector: "each reader who opens the artifact would pay for an embedding call.",
187
+ rerank: "each reader who opens the artifact would pay for a reranking call."
188
+ };
189
+ function readNode(value, path) {
190
+ const node = record(value, path);
191
+ const kind = node.kind;
192
+ if (typeof kind === "string" && Object.hasOwn(REFUSED_NODES, kind)) {
193
+ throw new QueryShapeError(`${path}.kind`, `"${kind}" is not allowed in an artifact's query: ${REFUSED_NODES[kind]}`);
194
+ }
195
+ if (typeof kind !== "string" || !Object.hasOwn(NODE_KEYS, kind)) {
196
+ throw new QueryShapeError(`${path}.kind`, `${JSON.stringify(kind)} is not a query node; use ${Object.keys(NODE_KEYS).join(", ")}.`);
197
+ }
198
+ const known = kind;
199
+ only(node, path, ["kind", ...NODE_KEYS[known]], `a "${known}" node`);
200
+ const input = () => readNode(node.input, `${path}.input`);
201
+ switch (known) {
202
+ case "start":
203
+ return {
204
+ kind: known,
205
+ objectTypeId: text(node, "objectTypeId", path),
206
+ ...node.includeSubtypes === undefined ? {} : { includeSubtypes: boolean(node, "includeSubtypes", path) }
207
+ };
208
+ case "refs":
209
+ return {
210
+ kind: known,
211
+ refs: list(node.refs, `${path}.refs`).map((ref, index) => {
212
+ const at = `${path}.refs[${index}]`;
213
+ const entry = record(ref, at);
214
+ only(entry, at, ["objectTypeId", "primaryId"], "a ref");
215
+ return {
216
+ objectTypeId: text(entry, "objectTypeId", at),
217
+ primaryId: text(entry, "primaryId", at)
218
+ };
219
+ })
220
+ };
221
+ case "filter":
222
+ return {
223
+ kind: known,
224
+ input: input(),
225
+ predicate: readPredicate(node.predicate, `${path}.predicate`)
226
+ };
227
+ case "text":
228
+ return {
229
+ kind: known,
230
+ input: input(),
231
+ query: string(node, "query", path),
232
+ ...node.fields === undefined ? {} : { fields: texts(node.fields, `${path}.fields`) }
233
+ };
234
+ case "traverse":
235
+ return {
236
+ kind: known,
237
+ input: input(),
238
+ linkId: text(node, "linkId", path),
239
+ direction: direction(node, path),
240
+ ...node.sourceObjectTypeId === undefined ? {} : { sourceObjectTypeId: text(node, "sourceObjectTypeId", path) }
241
+ };
242
+ case "set":
243
+ return {
244
+ kind: known,
245
+ op: oneOf(node, "op", path, ["union", "intersect", "subtract"]),
246
+ inputs: list(node.inputs, `${path}.inputs`).map((each, index) => readNode(each, `${path}.inputs[${index}]`))
247
+ };
248
+ case "sort":
249
+ return { kind: known, input: input(), fields: sortFields(node.fields, `${path}.fields`) };
250
+ case "limit":
251
+ return { kind: known, input: input(), limit: count(node, "limit", path) };
252
+ case "project":
253
+ return {
254
+ kind: known,
255
+ input: input(),
256
+ ...node.properties === undefined ? {} : { properties: texts(node.properties, `${path}.properties`) }
257
+ };
258
+ case "expand":
259
+ return {
260
+ kind: known,
261
+ input: input(),
262
+ expansions: expansions(node.expansions, `${path}.expansions`),
263
+ ...node.users === undefined ? {} : { users: texts(node.users, `${path}.users`) }
264
+ };
265
+ }
266
+ }
267
+ function readPredicate(value, path) {
268
+ const predicate = record(value, path);
269
+ const op = predicate.op;
270
+ switch (op) {
271
+ case "and":
272
+ case "or":
273
+ only(predicate, path, ["op", "items"], `an "${op}" predicate`);
274
+ return {
275
+ op,
276
+ items: list(predicate.items, `${path}.items`).map((item, index) => readPredicate(item, `${path}.items[${index}]`))
277
+ };
278
+ case "not":
279
+ only(predicate, path, ["op", "item"], 'a "not" predicate');
280
+ return { op, item: readPredicate(predicate.item, `${path}.item`) };
281
+ case "eq":
282
+ case "neq":
283
+ case "lt":
284
+ case "lte":
285
+ case "gt":
286
+ case "gte":
287
+ case "contains":
288
+ only(predicate, path, ["op", "propertyId", "value"], `an "${op}" predicate`);
289
+ return {
290
+ op,
291
+ propertyId: text(predicate, "propertyId", path),
292
+ value: present(predicate, "value", path)
293
+ };
294
+ case "in":
295
+ only(predicate, path, ["op", "propertyId", "values"], 'an "in" predicate');
296
+ return {
297
+ op,
298
+ propertyId: text(predicate, "propertyId", path),
299
+ values: list(predicate.values, `${path}.values`)
300
+ };
301
+ case "exists":
302
+ only(predicate, path, ["op", "propertyId", "value"], 'an "exists" predicate');
303
+ return {
304
+ op,
305
+ propertyId: text(predicate, "propertyId", path),
306
+ value: boolean(predicate, "value", path)
307
+ };
308
+ default:
309
+ throw new QueryShapeError(`${path}.op`, `${JSON.stringify(op)} is not a predicate; use and, or, not, eq, neq, lt, lte, gt, gte, in, exists or contains.`);
310
+ }
311
+ }
312
+ function sortFields(value, path) {
313
+ return list(value, path).map((each, index) => {
314
+ const at = `${path}[${index}]`;
315
+ const field = record(each, at);
316
+ const kind = oneOf(field, "kind", at, ["property", "relevance"]);
317
+ if (kind === "relevance") {
318
+ only(field, at, ["kind", "direction"], "a relevance sort");
319
+ return { kind, ...sortDirection(field, at) };
320
+ }
321
+ only(field, at, ["kind", "propertyId", "direction"], "a property sort");
322
+ return { kind, propertyId: text(field, "propertyId", at), ...sortDirection(field, at) };
323
+ });
324
+ }
325
+ function sortDirection(field, path) {
326
+ return field.direction === undefined ? {} : { direction: oneOf(field, "direction", path, ["asc", "desc"]) };
327
+ }
328
+ function expansions(value, path) {
329
+ return list(value, path).map((each, index) => {
330
+ const at = `${path}[${index}]`;
331
+ const expansion = record(each, at);
332
+ only(expansion, at, ["linkId", "direction", "sourceObjectTypeId", "limit", "orderBy", "expand", "users"], "an expansion");
333
+ return {
334
+ linkId: text(expansion, "linkId", at),
335
+ direction: direction(expansion, at),
336
+ ...expansion.sourceObjectTypeId === undefined ? {} : { sourceObjectTypeId: text(expansion, "sourceObjectTypeId", at) },
337
+ ...expansion.limit === undefined ? {} : { limit: count(expansion, "limit", at) },
338
+ ...expansion.orderBy === undefined ? {} : { orderBy: sortFields(expansion.orderBy, `${at}.orderBy`) },
339
+ ...expansion.expand === undefined ? {} : { expand: expansions(expansion.expand, `${at}.expand`) },
340
+ ...expansion.users === undefined ? {} : { users: texts(expansion.users, `${at}.users`) }
341
+ };
342
+ });
343
+ }
344
+ function direction(value, path) {
345
+ return oneOf(value, "direction", path, ["outgoing", "incoming"]);
346
+ }
347
+ function record(value, path) {
348
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
349
+ throw new QueryShapeError(path, "must be an object.");
350
+ }
351
+ return value;
352
+ }
353
+ function list(value, path) {
354
+ if (!Array.isArray(value))
355
+ throw new QueryShapeError(path, "must be a list.");
356
+ return value;
357
+ }
358
+ function only(value, path, keys, shape) {
359
+ const extra = Object.keys(value).find((key) => !keys.includes(key));
360
+ if (extra !== undefined) {
361
+ throw new QueryShapeError(`${path}.${extra}`, `is not a key of ${shape}.`);
362
+ }
363
+ }
364
+ function present(value, key, path) {
365
+ if (!Object.hasOwn(value, key))
366
+ throw new QueryShapeError(`${path}.${key}`, "is missing.");
367
+ return value[key];
368
+ }
369
+ function string(value, key, path) {
370
+ const found = value[key];
371
+ if (typeof found !== "string")
372
+ throw new QueryShapeError(`${path}.${key}`, "must be text.");
373
+ return found;
374
+ }
375
+ function text(value, key, path) {
376
+ const found = string(value, key, path);
377
+ if (found.length === 0)
378
+ throw new QueryShapeError(`${path}.${key}`, "must not be empty.");
379
+ return found;
380
+ }
381
+ function texts(value, path) {
382
+ return list(value, path).map((each, index) => {
383
+ if (typeof each !== "string" || each.length === 0) {
384
+ throw new QueryShapeError(`${path}[${index}]`, "must be text that is not empty.");
385
+ }
386
+ return each;
387
+ });
388
+ }
389
+ function boolean(value, key, path) {
390
+ const found = value[key];
391
+ if (typeof found !== "boolean") {
392
+ throw new QueryShapeError(`${path}.${key}`, "must be true or false.");
393
+ }
394
+ return found;
395
+ }
396
+ function count(value, key, path) {
397
+ const found = value[key];
398
+ if (typeof found !== "number" || !Number.isInteger(found) || found < 0) {
399
+ throw new QueryShapeError(`${path}.${key}`, "must be a whole number, 0 or more.");
400
+ }
401
+ return found;
402
+ }
403
+ function oneOf(value, key, path, values) {
404
+ const found = value[key];
405
+ if (typeof found !== "string" || !values.includes(found)) {
406
+ throw new QueryShapeError(`${path}.${key}`, `${JSON.stringify(found)} is not one of ${values.join(", ")}.`);
407
+ }
408
+ return found;
409
+ }
410
+
411
+ // src/artifacts/resolve.ts
412
+ function resolveArtifactAddress2(address, target) {
413
+ if (address.path !== undefined) {
414
+ if (address.part !== undefined)
415
+ return { problem: "names both a file and a part of one" };
416
+ return target.files.some((file) => file.path === address.path) ? { part: { type: "file", path: address.path } } : { problem: `has no file '${address.path}'` };
417
+ }
418
+ if (address.part === undefined)
419
+ return { part: { type: "artifact" } };
420
+ const { outline } = target;
421
+ switch (outline.kind) {
422
+ case "sheet": {
423
+ const part = parseSheetPart2(address.part);
424
+ if (!part) {
425
+ return {
426
+ problem: `has no part '${address.part}': name a sheet, a range such as Summary!A1:D12, or chart=<name>`
427
+ };
428
+ }
429
+ if (part.type === "chart") {
430
+ return outline.charts.includes(part.chart) ? { part } : { problem: `has no chart '${part.chart}'${listed("its charts", outline.charts)}` };
431
+ }
432
+ const sheet = outline.sheets.find((candidate) => candidate.name === part.sheet);
433
+ if (!sheet) {
434
+ return {
435
+ problem: `has no sheet '${part.sheet}'${listed("its sheets", outline.sheets.map((candidate) => candidate.name))}`
436
+ };
437
+ }
438
+ const rows = sheet.query === undefined ? sheet.rows : Number.POSITIVE_INFINITY;
439
+ if (part.range && (part.range.bottom > rows || part.range.right >= sheet.columns.length)) {
440
+ return {
441
+ problem: `has no range ${address.part.slice(address.part.lastIndexOf("!") + 1)} in sheet '${sheet.name}', which has ${sheet.rows + 1} rows and ${sheet.columns.length} columns`
442
+ };
443
+ }
444
+ return { part };
445
+ }
446
+ case "document": {
447
+ const heading = outline.headings.find((candidate) => candidate.slug === address.part);
448
+ return heading ? { part: { type: "section", slug: heading.slug } } : {
449
+ problem: `has no section '${address.part}'${listed("its sections", outline.headings.map((candidate) => candidate.slug))}`
450
+ };
451
+ }
452
+ case "slides": {
453
+ const slide = /^[1-9]\d*$/.test(address.part) ? Number(address.part) : Number.NaN;
454
+ return slide <= outline.slides.length ? { part: { type: "slide", slide } } : { problem: `has no slide '${address.part}': it has ${outline.slides.length} slides` };
455
+ }
456
+ case "canvas": {
457
+ const item = outline.items.find((candidate) => candidate.id === address.part);
458
+ if (!item) {
459
+ return {
460
+ problem: `has no board or section '${address.part}'${listed("its boards and sections", outline.items.map((candidate) => candidate.id))}`
461
+ };
462
+ }
463
+ return { part: { type: item.type === "board" ? "board" : "region", id: item.id } };
464
+ }
465
+ case "page":
466
+ case "file":
467
+ return { problem: `is a ${target.kind}, which has no parts to name` };
468
+ }
469
+ }
470
+ function listed(label, names) {
471
+ if (names.length === 0)
472
+ return "";
473
+ const shown = names.slice(0, 8).map((name) => `'${name}'`);
474
+ return `; ${label} are ${shown.join(", ")}${names.length > shown.length ? ", \u2026" : ""}`;
475
+ }
476
+
477
+ // src/artifacts/tones.ts
478
+ var ARTIFACT_TONES2 = [
479
+ "neutral",
480
+ "positive",
481
+ "warning",
482
+ "negative",
483
+ "chart-1",
484
+ "chart-2",
485
+ "chart-3",
486
+ "chart-4",
487
+ "chart-5"
488
+ ];
489
+ function isArtifactTone(value) {
490
+ return ARTIFACT_TONES2.includes(value);
491
+ }
492
+
493
+ // src/artifacts/canvas.ts
494
+ var CANVAS_FILE2 = "canvas.json";
495
+ var CANVAS_ITEM_TYPES = [
496
+ "board",
497
+ "section",
498
+ "note",
499
+ "text",
500
+ "shape",
501
+ "arrow",
502
+ "embed"
503
+ ];
504
+ var CANVAS_SHAPES = ["rect", "ellipse", "diamond"];
505
+ var CANVAS_TEXT_SIZES = ["s", "m", "l", "xl"];
506
+
507
+ class CanvasError extends Error {
508
+ }
509
+ function parseCanvas2(text) {
510
+ let value;
511
+ try {
512
+ value = JSON.parse(text);
513
+ } catch {
514
+ return { error: `${CANVAS_FILE2} is not valid JSON.` };
515
+ }
516
+ try {
517
+ return { canvas: readCanvas(value) };
518
+ } catch (error) {
519
+ if (error instanceof CanvasError)
520
+ return { error: `${CANVAS_FILE2}: ${error.message}` };
521
+ throw error;
522
+ }
523
+ }
524
+ var ITEM_ID = /^[a-z0-9][a-z0-9-]{0,39}$/;
525
+ var TEXT_MAX = ARTIFACT_LIMITS2.maxCanvasTextLength;
526
+ var LABEL_MAX = ARTIFACT_LIMITS2.maxCanvasLabelLength;
527
+ function readCanvas(value) {
528
+ const input = record2(value, "the canvas", ["items"]);
529
+ if (!Array.isArray(input.items) || input.items.length === 0) {
530
+ throw new CanvasError('"items" must list at least one item.');
531
+ }
532
+ if (input.items.length > ARTIFACT_LIMITS2.maxCanvasItems) {
533
+ throw new CanvasError(`a canvas holds at most ${ARTIFACT_LIMITS2.maxCanvasItems} items; this one has ${input.items.length}.`);
534
+ }
535
+ const items = input.items.map((item, index) => readItem(item, index));
536
+ const ids = new Set;
537
+ for (const item of items) {
538
+ if (ids.has(item.id))
539
+ throw new CanvasError(`two items have the id '${item.id}'.`);
540
+ ids.add(item.id);
541
+ }
542
+ const boards = items.filter((item) => item.type === "board").length;
543
+ if (boards > ARTIFACT_LIMITS2.maxCanvasBoards) {
544
+ throw new CanvasError(`a canvas holds at most ${ARTIFACT_LIMITS2.maxCanvasBoards} boards; this one has ${boards}.`);
545
+ }
546
+ for (const item of items) {
547
+ if (item.type !== "arrow")
548
+ continue;
549
+ for (const [key, end] of [
550
+ ["from", item.from],
551
+ ["to", item.to]
552
+ ]) {
553
+ if (typeof end !== "string")
554
+ continue;
555
+ const target = items.find((candidate) => candidate.id === end);
556
+ if (!target) {
557
+ throw new CanvasError(`arrow '${item.id}' "${key}" names '${end}', which the canvas does not have.`);
558
+ }
559
+ if (target.type === "arrow") {
560
+ throw new CanvasError(`arrow '${item.id}' "${key}" names arrow '${end}'; an arrow joins items, not arrows.`);
561
+ }
562
+ }
563
+ if (item.from === item.to) {
564
+ throw new CanvasError(`arrow '${item.id}' starts and ends at '${String(item.from)}'.`);
565
+ }
566
+ }
567
+ return { items };
568
+ }
569
+ var KEYS = {
570
+ board: ["file", "x", "y", "w", "h", "title"],
571
+ section: ["x", "y", "w", "h", "title"],
572
+ note: ["x", "y", "w", "h", "text", "tone"],
573
+ text: ["x", "y", "w", "text", "size"],
574
+ shape: ["shape", "x", "y", "w", "h", "text", "tone"],
575
+ arrow: ["from", "to", "label", "dashed"],
576
+ embed: ["src", "x", "y", "w", "h", "title"]
577
+ };
578
+ function readItem(value, index) {
579
+ const loose = record2(value, `item ${index + 1}`, null);
580
+ if (typeof loose.id !== "string" || !ITEM_ID.test(loose.id)) {
581
+ throw new CanvasError(`item ${index + 1} needs an "id" of lowercase letters, digits, and hyphens, such as "pricing".`);
582
+ }
583
+ const id = loose.id;
584
+ if (!CANVAS_ITEM_TYPES.includes(loose.type)) {
585
+ throw new CanvasError(`item '${id}' has type ${JSON.stringify(loose.type)}; use one of ${CANVAS_ITEM_TYPES.join(", ")}.`);
586
+ }
587
+ const type = loose.type;
588
+ const at = `${type} '${id}'`;
589
+ const input = record2(value, at, ["id", "type", ...KEYS[type]]);
590
+ const place = () => ({ id, x: position(input.x, at, "x"), y: position(input.y, at, "y") });
591
+ const size = (key) => dimension(input[key], at, key);
592
+ const title = () => optionalText(input.title, at, "title", LABEL_MAX);
593
+ const tone = () => {
594
+ if (input.tone === undefined)
595
+ return {};
596
+ if (!isArtifactTone(input.tone)) {
597
+ throw new CanvasError(`${at} has the tone ${JSON.stringify(input.tone)}; use one of ${ARTIFACT_TONES2.join(", ")}.`);
598
+ }
599
+ return { tone: input.tone };
600
+ };
601
+ switch (type) {
602
+ case "board": {
603
+ if (typeof input.file !== "string" || !/\.html?$/i.test(input.file)) {
604
+ throw new CanvasError(`${at} needs a "file", the HTML it shows, such as "boards/${id}.html".`);
605
+ }
606
+ return { type, ...place(), w: size("w"), h: size("h"), file: input.file, ...title() };
607
+ }
608
+ case "section":
609
+ return { type, ...place(), w: size("w"), h: size("h"), ...title() };
610
+ case "note":
611
+ return {
612
+ type,
613
+ ...place(),
614
+ w: size("w"),
615
+ ...input.h === undefined ? {} : { h: size("h") },
616
+ text: requiredText(input.text, at, "text", TEXT_MAX),
617
+ ...tone()
618
+ };
619
+ case "text": {
620
+ if (input.size !== undefined && !CANVAS_TEXT_SIZES.includes(input.size)) {
621
+ throw new CanvasError(`${at} "size" is ${JSON.stringify(input.size)}; use one of ${CANVAS_TEXT_SIZES.join(", ")}.`);
622
+ }
623
+ return {
624
+ type,
625
+ ...place(),
626
+ text: requiredText(input.text, at, "text", TEXT_MAX),
627
+ size: input.size ?? "m",
628
+ ...input.w === undefined ? {} : { w: size("w") }
629
+ };
630
+ }
631
+ case "shape": {
632
+ if (!CANVAS_SHAPES.includes(input.shape)) {
633
+ throw new CanvasError(`${at} "shape" is ${JSON.stringify(input.shape)}; use one of ${CANVAS_SHAPES.join(", ")}.`);
634
+ }
635
+ return {
636
+ type,
637
+ ...place(),
638
+ w: size("w"),
639
+ h: size("h"),
640
+ shape: input.shape,
641
+ ...optionalText(input.text, at, "text", LABEL_MAX, "text"),
642
+ ...tone()
643
+ };
644
+ }
645
+ case "embed": {
646
+ if (typeof input.src !== "string" || !isArtifactAddress2(input.src)) {
647
+ throw new CanvasError(`${at} needs a "src", another artifact's address, such as "artifact:art_k3m9q2x7tp#chart=revenue".`);
648
+ }
649
+ return { type, ...place(), w: size("w"), h: size("h"), src: input.src.trim(), ...title() };
650
+ }
651
+ case "arrow": {
652
+ if (input.dashed !== undefined && typeof input.dashed !== "boolean") {
653
+ throw new CanvasError(`${at} "dashed" must be true or false.`);
654
+ }
655
+ return {
656
+ type,
657
+ id,
658
+ from: end(input.from, at, "from"),
659
+ to: end(input.to, at, "to"),
660
+ ...optionalText(input.label, at, "label", LABEL_MAX, "label"),
661
+ dashed: input.dashed === true
662
+ };
663
+ }
664
+ }
665
+ }
666
+ function end(value, at, key) {
667
+ if (typeof value === "string" && value)
668
+ return value;
669
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
670
+ const point = record2(value, `${at} "${key}"`, ["x", "y"]);
671
+ return { x: position(point.x, at, `${key}.x`), y: position(point.y, at, `${key}.y`) };
672
+ }
673
+ throw new CanvasError(`${at} needs "${key}": an item's id, or a point such as { "x": 0, "y": 0 }.`);
674
+ }
675
+ function position(value, at, key) {
676
+ const max = ARTIFACT_LIMITS2.maxCanvasPosition;
677
+ if (typeof value !== "number" || !Number.isFinite(value) || Math.abs(value) > max) {
678
+ throw new CanvasError(`${at} needs "${key}", a number of pixels within \xB1${max.toLocaleString("en-US")}.`);
679
+ }
680
+ return value;
681
+ }
682
+ function dimension(value, at, key) {
683
+ const { minCanvasItemSize: min, maxCanvasItemSize: max } = ARTIFACT_LIMITS2;
684
+ if (typeof value !== "number" || !Number.isFinite(value) || value < min || value > max) {
685
+ throw new CanvasError(`${at} needs "${key}", a size of ${min} to ${max} pixels.`);
686
+ }
687
+ return value;
688
+ }
689
+ function requiredText(value, at, key, max) {
690
+ if (typeof value !== "string" || !value.trim())
691
+ throw new CanvasError(`${at} needs "${key}", its text.`);
692
+ if (value.length > max)
693
+ throw new CanvasError(`${at} "${key}" is ${value.length} characters; at most ${max}.`);
694
+ return value.trim();
695
+ }
696
+ function optionalText(value, at, key, max, as = key) {
697
+ if (value === undefined)
698
+ return {};
699
+ if (typeof value !== "string" || value.length > max) {
700
+ throw new CanvasError(`${at} "${key}" must be text of at most ${max} characters.`);
701
+ }
702
+ return value.trim() ? { [as]: value.trim() } : {};
703
+ }
704
+ function record2(value, at, keys) {
705
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
706
+ throw new CanvasError(`${at} must be an object.`);
707
+ }
708
+ const input = value;
709
+ const unknownKey = keys && Object.keys(input).find((key) => !keys.includes(key));
710
+ if (unknownKey) {
711
+ throw new CanvasError(`${at} has '${unknownKey}'; it takes ${keys.map((key) => `"${key}"`).join(", ")}.`);
712
+ }
713
+ return input;
714
+ }
715
+
716
+ // src/artifacts/outline.ts
717
+ function createHeadingSlugger2() {
718
+ const used = new Set;
719
+ return (text) => {
720
+ const base = text.trim().toLowerCase().replace(/[^\p{L}\p{N}\s_-]/gu, "").replace(/\s+/g, "-") || "section";
721
+ let slug = base;
722
+ for (let repeat = 1;used.has(slug); repeat += 1)
723
+ slug = `${base}-${repeat}`;
724
+ used.add(slug);
725
+ return slug;
726
+ };
727
+ }
728
+
729
+ // src/artifacts/csv.ts
730
+ class CsvParseError2 extends Error {
731
+ line;
732
+ constructor(message, line) {
733
+ super(message);
734
+ this.line = line;
735
+ this.name = "CsvParseError";
736
+ }
737
+ }
738
+ function parseCsv2(text, options = {}) {
739
+ const delimiter = options.delimiter ?? ",";
740
+ const source = text.charCodeAt(0) === 65279 ? text.slice(1) : text;
741
+ const records = [];
742
+ let record = [];
743
+ let field = "";
744
+ let quoted = false;
745
+ let quotedSeen = false;
746
+ let line = 1;
747
+ let recordLine = 1;
748
+ let index = 0;
749
+ const endField = () => {
750
+ record.push(field);
751
+ field = "";
752
+ };
753
+ const endRecord = () => {
754
+ endField();
755
+ if (!(record.length === 1 && record[0] === "" && !quotedSeen))
756
+ records.push(record);
757
+ record = [];
758
+ quotedSeen = false;
759
+ };
760
+ while (index < source.length) {
761
+ const char = source[index];
762
+ if (quoted) {
763
+ if (char === '"') {
764
+ if (source[index + 1] === '"') {
765
+ field += '"';
766
+ index += 2;
767
+ continue;
768
+ }
769
+ quoted = false;
770
+ index += 1;
771
+ const next = source[index];
772
+ if (next !== undefined && next !== delimiter && next !== `
773
+ ` && next !== "\r") {
774
+ throw new CsvParseError2(`A quoted field on line ${line} goes on after its closing quote; quote the whole field and double the quotes inside it.`, recordLine);
775
+ }
776
+ continue;
777
+ }
778
+ if (char === `
779
+ ` || char === "\r" && source[index + 1] !== `
780
+ `)
781
+ line += 1;
782
+ field += char;
783
+ index += 1;
784
+ continue;
785
+ }
786
+ if (char === '"' && field === "") {
787
+ quoted = true;
788
+ quotedSeen = true;
789
+ index += 1;
790
+ continue;
791
+ }
792
+ if (char === delimiter) {
793
+ endField();
794
+ index += 1;
795
+ continue;
796
+ }
797
+ if (char === "\r" || char === `
798
+ `) {
799
+ endRecord();
800
+ index += char === "\r" && source[index + 1] === `
801
+ ` ? 2 : 1;
802
+ line += 1;
803
+ recordLine = line;
804
+ continue;
805
+ }
806
+ field += char;
807
+ index += 1;
808
+ }
809
+ if (quoted) {
810
+ throw new CsvParseError2(`A quoted field that starts on line ${recordLine} is never closed.`, recordLine);
811
+ }
812
+ if (field !== "" || record.length > 0 || quotedSeen)
813
+ endRecord();
814
+ const [header, ...rows] = records;
815
+ return { header: header ?? [], rows };
816
+ }
817
+ function formatCsv2(header, rows) {
818
+ const field = (value) => /[",\r\n]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value;
819
+ return [header, ...rows].map((row) => `${row.map(field).join(",")}\r
820
+ `).join("");
821
+ }
822
+
823
+ // src/artifacts/formula/parser.ts
824
+ class FormulaSyntaxError extends Error {
825
+ position;
826
+ constructor(message, position) {
827
+ super(message);
828
+ this.position = position;
829
+ this.name = "FormulaSyntaxError";
830
+ }
831
+ }
832
+ var OPERATORS = ["<>", "<=", ">=", "+", "-", "*", "/", "^", "&", "=", "<", ">", "(", ")", ","];
833
+ function tokens(source) {
834
+ const list = [];
835
+ let index = 0;
836
+ const fail = (message, at = index) => {
837
+ throw new FormulaSyntaxError(`${message} at character ${at + 1}.`, at + 1);
838
+ };
839
+ const name = () => {
840
+ let value = "";
841
+ while (index < source.length && source[index] !== "]") {
842
+ if (source[index] === "[")
843
+ fail("A column's name holds '[': escape it as '[");
844
+ if (source[index] === "'")
845
+ index += 1;
846
+ value += source[index] ?? "";
847
+ index += 1;
848
+ }
849
+ if (source[index] !== "]")
850
+ fail("A column reference is never closed with ']'");
851
+ index += 1;
852
+ return value.trim();
853
+ };
854
+ while (index < source.length) {
855
+ const char = source[index];
856
+ const at = index;
857
+ if (/\s/.test(char)) {
858
+ index += 1;
859
+ continue;
860
+ }
861
+ if (/[0-9.]/.test(char)) {
862
+ const match = /^(\d+\.?\d*|\.\d+)(e[-+]?\d+)?/i.exec(source.slice(index));
863
+ if (!match)
864
+ fail("A number is not written right");
865
+ index += match[0].length;
866
+ list.push({ kind: "number", value: Number(match[0]), at });
867
+ continue;
868
+ }
869
+ if (char === '"') {
870
+ let value = "";
871
+ index += 1;
872
+ for (;; ) {
873
+ if (index >= source.length)
874
+ fail("A text in quotes is never closed", at);
875
+ if (source[index] === '"') {
876
+ if (source[index + 1] === '"') {
877
+ value += '"';
878
+ index += 2;
879
+ continue;
880
+ }
881
+ index += 1;
882
+ break;
883
+ }
884
+ value += source[index];
885
+ index += 1;
886
+ }
887
+ list.push({ kind: "text", value, at });
888
+ continue;
889
+ }
890
+ if (char === "[") {
891
+ index += 1;
892
+ const row = source[index] === "@";
893
+ if (row)
894
+ index += 1;
895
+ let column;
896
+ if (source[index] === "[") {
897
+ index += 1;
898
+ column = name();
899
+ if (source[index] !== "]")
900
+ fail("A bracketed column name needs its outer ']'");
901
+ index += 1;
902
+ } else {
903
+ column = name();
904
+ }
905
+ if (!column)
906
+ fail("A column reference names no column", at);
907
+ list.push({ kind: "ref", column, row, at });
908
+ continue;
909
+ }
910
+ if (/[A-Za-z_]/.test(char)) {
911
+ const match = /^[A-Za-z_][A-Za-z0-9_.]*/.exec(source.slice(index));
912
+ index += match[0].length;
913
+ list.push({ kind: "name", value: match[0].toUpperCase(), at });
914
+ continue;
915
+ }
916
+ const operator = OPERATORS.find((candidate) => source.startsWith(candidate, index));
917
+ if (!operator)
918
+ fail(`'${char}' is not part of a formula`);
919
+ index += operator.length;
920
+ list.push({ kind: "op", value: operator, at });
921
+ }
922
+ list.push({ kind: "end", at: source.length });
923
+ return list;
924
+ }
925
+ var BINDING = {
926
+ "=": 10,
927
+ "<>": 10,
928
+ "<": 10,
929
+ "<=": 10,
930
+ ">": 10,
931
+ ">=": 10,
932
+ "&": 20,
933
+ "+": 30,
934
+ "-": 30,
935
+ "*": 40,
936
+ "/": 40,
937
+ "^": 50
938
+ };
939
+ var PREFIX = 60;
940
+ function parseFormula2(text) {
941
+ const source = text.trim().replace(/^=/, "");
942
+ const list = tokens(source);
943
+ let position = 0;
944
+ const peek = () => list[position];
945
+ const next = () => list[position++];
946
+ const fail = (message, token) => {
947
+ throw new FormulaSyntaxError(`${message} at character ${token.at + 1}.`, token.at + 1);
948
+ };
949
+ const expect = (value) => {
950
+ const token = next();
951
+ if (token.kind !== "op" || token.value !== value) {
952
+ fail(`Expected '${value}'`, token);
953
+ }
954
+ };
955
+ const expression = (binding) => {
956
+ let left = operand();
957
+ for (;; ) {
958
+ const token = peek();
959
+ if (token.kind !== "op")
960
+ break;
961
+ const power = BINDING[token.value];
962
+ if (power === undefined || power <= binding)
963
+ break;
964
+ next();
965
+ const right = expression(power);
966
+ left = { kind: "binary", op: token.value, left, right };
967
+ }
968
+ return left;
969
+ };
970
+ const operand = () => {
971
+ const token = next();
972
+ switch (token.kind) {
973
+ case "number":
974
+ return { kind: "number", value: token.value };
975
+ case "text":
976
+ return { kind: "text", value: token.value };
977
+ case "ref":
978
+ return token.row ? { kind: "ref", column: token.column } : { kind: "columnRef", column: token.column };
979
+ case "name": {
980
+ if (token.value === "TRUE" || token.value === "FALSE") {
981
+ return { kind: "boolean", value: token.value === "TRUE" };
982
+ }
983
+ if (peek().kind !== "op" || peek().value !== "(") {
984
+ return fail(`'${token.value}' is not a function call or a reference; a column is written [@Name]`, token);
985
+ }
986
+ next();
987
+ const args = [];
988
+ if (!(peek().kind === "op" && peek().value === ")")) {
989
+ for (;; ) {
990
+ args.push(expression(0));
991
+ const separator = peek();
992
+ if (separator.kind === "op" && separator.value === ",") {
993
+ next();
994
+ continue;
995
+ }
996
+ break;
997
+ }
998
+ }
999
+ expect(")");
1000
+ return { kind: "call", name: token.value, args };
1001
+ }
1002
+ case "op":
1003
+ if (token.value === "(") {
1004
+ const inner = expression(0);
1005
+ expect(")");
1006
+ return inner;
1007
+ }
1008
+ if (token.value === "-" || token.value === "+") {
1009
+ return { kind: "unary", op: token.value, operand: expression(PREFIX) };
1010
+ }
1011
+ return fail(`'${token.value}' can't start a value`, token);
1012
+ case "end":
1013
+ return fail("The formula ends where a value is expected", token);
1014
+ }
1015
+ };
1016
+ const tree = expression(0);
1017
+ const rest = peek();
1018
+ if (rest.kind !== "end")
1019
+ fail("The formula goes on after a complete value", rest);
1020
+ return tree;
1021
+ }
1022
+ function formulaDependencies2(node) {
1023
+ const columns = new Set;
1024
+ visitReferences(node, (reference) => columns.add(reference.column));
1025
+ return columns;
1026
+ }
1027
+ function formulaReferences2(node) {
1028
+ const row = new Set;
1029
+ const whole = new Set;
1030
+ visitReferences(node, (reference) => (reference.kind === "ref" ? row : whole).add(reference.column));
1031
+ return { row, whole };
1032
+ }
1033
+ function visitReferences(node, found) {
1034
+ const visit = (current) => {
1035
+ switch (current.kind) {
1036
+ case "ref":
1037
+ case "columnRef":
1038
+ found(current);
1039
+ return;
1040
+ case "unary":
1041
+ visit(current.operand);
1042
+ return;
1043
+ case "binary":
1044
+ visit(current.left);
1045
+ visit(current.right);
1046
+ return;
1047
+ case "call":
1048
+ for (const arg of current.args)
1049
+ visit(arg);
1050
+ return;
1051
+ default:
1052
+ return;
1053
+ }
1054
+ };
1055
+ visit(node);
1056
+ }
1057
+ function renameColumnReferences2(formula, from, to) {
1058
+ let result = "";
1059
+ let index = 0;
1060
+ while (index < formula.length) {
1061
+ const char = formula[index];
1062
+ if (char === '"') {
1063
+ let end = index + 1;
1064
+ while (end < formula.length) {
1065
+ if (formula[end] === '"' && formula[end + 1] === '"')
1066
+ end += 2;
1067
+ else if (formula[end] === '"')
1068
+ break;
1069
+ else
1070
+ end += 1;
1071
+ }
1072
+ result += formula.slice(index, end + 1);
1073
+ index = end + 1;
1074
+ continue;
1075
+ }
1076
+ if (char !== "[") {
1077
+ result += char;
1078
+ index += 1;
1079
+ continue;
1080
+ }
1081
+ const start = index;
1082
+ index += 1;
1083
+ const row = formula[index] === "@";
1084
+ if (row)
1085
+ index += 1;
1086
+ const bracketed = formula[index] === "[";
1087
+ if (bracketed)
1088
+ index += 1;
1089
+ let name = "";
1090
+ while (index < formula.length && formula[index] !== "]") {
1091
+ if (formula[index] === "'")
1092
+ index += 1;
1093
+ name += formula[index] ?? "";
1094
+ index += 1;
1095
+ }
1096
+ index += bracketed ? 2 : 1;
1097
+ result += name.trim() === from ? columnReference(to, row) : formula.slice(start, Math.min(index, formula.length));
1098
+ }
1099
+ return result;
1100
+ }
1101
+ function columnReference(name, row) {
1102
+ const escaped = name.replace(/['[\]#@]/g, "'$&");
1103
+ const plain = /^[A-Za-z0-9_ ]+$/.test(name) && name === name.trim();
1104
+ const inner = plain ? escaped : `[${escaped}]`;
1105
+ return row ? `[@${inner}]` : `[${inner}]`;
1106
+ }
1107
+
1108
+ // src/artifacts/workbook.ts
1109
+ var WORKBOOK_FILE2 = "workbook.json";
1110
+ var SHEET_COLUMN_TYPES2 = [
1111
+ "text",
1112
+ "number",
1113
+ "currency",
1114
+ "percent",
1115
+ "date",
1116
+ "link",
1117
+ "image",
1118
+ "boolean",
1119
+ "tag"
1120
+ ];
1121
+ var NUMERIC_COLUMN_TYPES2 = ["number", "currency", "percent"];
1122
+ var SHEET_HIGHLIGHTS2 = ["bars", "scale", "diverging"];
1123
+ var SHEET_TOTALS2 = ["sum", "average", "min", "max", "count"];
1124
+ var SHEET_CHART_TYPES = ["bar", "line", "area", "pie", "scatter"];
1125
+ var SHEET_CHART_AGGREGATES = ["sum", "average", "count"];
1126
+ function sheetFilePath2(sheetName) {
1127
+ return `sheets/${sheetName}.csv`;
1128
+ }
1129
+ function parseWorkbook2(text) {
1130
+ let value;
1131
+ try {
1132
+ value = JSON.parse(text);
1133
+ } catch {
1134
+ return { error: `${WORKBOOK_FILE2} is not valid JSON.` };
1135
+ }
1136
+ try {
1137
+ return { workbook: readWorkbook(value) };
1138
+ } catch (error) {
1139
+ if (error instanceof WorkbookError)
1140
+ return { error: `${WORKBOOK_FILE2}: ${error.message}` };
1141
+ throw error;
1142
+ }
1143
+ }
1144
+ function parseSheetNumber2(value) {
1145
+ const trimmed = value.trim();
1146
+ if (!/^[-+]?(\d+\.?\d*|\.\d+)(e[-+]?\d+)?$/i.test(trimmed))
1147
+ return;
1148
+ const number = Number(trimmed);
1149
+ return Number.isFinite(number) ? number : undefined;
1150
+ }
1151
+ function parseSheetDate2(value) {
1152
+ const trimmed = value.trim();
1153
+ if (!/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[-+]\d{2}:\d{2})?)?$/.test(trimmed)) {
1154
+ return;
1155
+ }
1156
+ const date = new Date(trimmed.length === 10 ? `${trimmed}T00:00:00Z` : trimmed);
1157
+ return Number.isNaN(date.getTime()) ? undefined : date;
1158
+ }
1159
+
1160
+ class WorkbookError extends Error {
1161
+ }
1162
+ var SHEET_NAME_MAX = 60;
1163
+ var DESCRIPTION_MAX = 300;
1164
+ var TONES_MAX = 20;
1165
+ var TAG_MAX = 60;
1166
+ var FORMULA_MAX = 500;
1167
+ var COMPUTED_MAX = 20;
1168
+ var CHART_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
1169
+ var CONTROL = /[\u0000-\u001f\u007f]/;
1170
+ function readWorkbook(value) {
1171
+ const input = record3(value, "the workbook", ["sheets", "charts"]);
1172
+ if (!Array.isArray(input.sheets) || input.sheets.length === 0) {
1173
+ throw new WorkbookError('"sheets" must list at least one sheet.');
1174
+ }
1175
+ if (input.sheets.length > ARTIFACT_LIMITS2.maxSheets) {
1176
+ throw new WorkbookError(`a workbook holds at most ${ARTIFACT_LIMITS2.maxSheets} sheets; this one has ${input.sheets.length}.`);
1177
+ }
1178
+ const sheets = input.sheets.map((sheet, index) => readSheet(sheet, index));
1179
+ const names = new Set;
1180
+ for (const sheet of sheets) {
1181
+ const key = sheet.name.toLowerCase();
1182
+ if (names.has(key))
1183
+ throw new WorkbookError(`two sheets are named '${sheet.name}'.`);
1184
+ names.add(key);
1185
+ }
1186
+ const chartsInput = input.charts ?? [];
1187
+ if (!Array.isArray(chartsInput))
1188
+ throw new WorkbookError('"charts" must be a list.');
1189
+ if (chartsInput.length > ARTIFACT_LIMITS2.maxCharts) {
1190
+ throw new WorkbookError(`a workbook holds at most ${ARTIFACT_LIMITS2.maxCharts} charts; this one has ${chartsInput.length}.`);
1191
+ }
1192
+ const charts = chartsInput.map((chart, index) => readChart(chart, index, sheets));
1193
+ const chartNames = new Set;
1194
+ for (const chart of charts) {
1195
+ if (chartNames.has(chart.name))
1196
+ throw new WorkbookError(`two charts are named '${chart.name}'.`);
1197
+ chartNames.add(chart.name);
1198
+ }
1199
+ return { sheets, charts };
1200
+ }
1201
+ function readSheet(value, index) {
1202
+ const at = `sheet ${index + 1}`;
1203
+ const input = record3(value, at, [
1204
+ "name",
1205
+ "frozenRows",
1206
+ "frozenColumns",
1207
+ "columns",
1208
+ "widths",
1209
+ "descriptions",
1210
+ "totals",
1211
+ "query"
1212
+ ]);
1213
+ const name = typeof input.name === "string" ? input.name.trim() : "";
1214
+ if (!name || name.length > SHEET_NAME_MAX || CONTROL.test(name) || /[/\\]/.test(name) || name === "." || name === "..") {
1215
+ throw new WorkbookError(`${at} needs a "name" of at most ${SHEET_NAME_MAX} characters without / or \\; its values go in sheets/<name>.csv.`);
1216
+ }
1217
+ const sheetAt = `sheet '${name}'`;
1218
+ const live = input.query === undefined ? undefined : readLiveSheet(input, sheetAt);
1219
+ const columns = {};
1220
+ for (const [column, format] of Object.entries(record3(input.columns ?? {}, `${sheetAt} "columns"`, null))) {
1221
+ const at = `${sheetAt} column '${column}'`;
1222
+ if (!live) {
1223
+ columns[column] = readColumnFormat(format, at);
1224
+ continue;
1225
+ }
1226
+ const { from: _from, ...written } = format;
1227
+ if (written.type !== undefined || written.formula !== undefined) {
1228
+ columns[column] = readColumnFormat(written, at);
1229
+ }
1230
+ }
1231
+ const computed = Object.values(columns).filter((format) => format.formula).length;
1232
+ if (computed > COMPUTED_MAX) {
1233
+ throw new WorkbookError(`${sheetAt} computes ${computed} columns; a sheet computes at most ${COMPUTED_MAX}.`);
1234
+ }
1235
+ const widths = {};
1236
+ for (const [column, width] of Object.entries(record3(input.widths ?? {}, `${sheetAt} "widths"`, null))) {
1237
+ if (typeof width !== "number" || !Number.isInteger(width) || width < 40 || width > 800) {
1238
+ throw new WorkbookError(`${sheetAt} gives column '${column}' a width of ${String(width)}; use 40 to 800 pixels.`);
1239
+ }
1240
+ widths[column] = width;
1241
+ }
1242
+ const descriptions = {};
1243
+ for (const [column, description] of Object.entries(record3(input.descriptions ?? {}, `${sheetAt} "descriptions"`, null))) {
1244
+ if (typeof description !== "string" || !description.trim() || description.length > DESCRIPTION_MAX) {
1245
+ throw new WorkbookError(`${sheetAt} describes column '${column}' with ${JSON.stringify(description)}; a description is text of at most ${DESCRIPTION_MAX} characters.`);
1246
+ }
1247
+ descriptions[column] = description.trim();
1248
+ }
1249
+ const totals = {};
1250
+ for (const [column, total] of Object.entries(record3(input.totals ?? {}, `${sheetAt} "totals"`, null))) {
1251
+ if (!SHEET_TOTALS2.includes(total)) {
1252
+ throw new WorkbookError(`${sheetAt} totals column '${column}' with ${JSON.stringify(total)}; use one of ${SHEET_TOTALS2.join(", ")}.`);
1253
+ }
1254
+ const deferred = live !== undefined && columns[column] === undefined;
1255
+ const problem = deferred ? null : sheetTotalProblem(sheetAt, column, total, columns[column]?.type ?? "text");
1256
+ if (problem)
1257
+ throw new WorkbookError(problem);
1258
+ totals[column] = total;
1259
+ }
1260
+ return {
1261
+ name,
1262
+ frozenRows: integer(input.frozenRows, 1, 0, 10, `${sheetAt} "frozenRows"`),
1263
+ frozenColumns: integer(input.frozenColumns, 0, 0, 5, `${sheetAt} "frozenColumns"`),
1264
+ columns,
1265
+ widths,
1266
+ descriptions,
1267
+ totals,
1268
+ ...live ? { live } : {}
1269
+ };
1270
+ }
1271
+ function sheetTotalProblem(sheetAt, column, total, type) {
1272
+ if (total === "count" || NUMERIC_COLUMN_TYPES2.includes(type))
1273
+ return null;
1274
+ return `${sheetAt} totals column '${column}' with "${total}", but it is ${type}; only a number, currency, or percent column has a ${total}. Use "count", or give it a numeric type in "columns".`;
1275
+ }
1276
+ var INDEX_NAME = /^(0|[1-9]\d{0,8})$/;
1277
+ function readLiveSheet(input, sheetAt) {
1278
+ if (typeof input.query !== "string" || !isArtifactQueryName(input.query)) {
1279
+ throw new WorkbookError(`${sheetAt} "query" must name one of the version's queries, as queries/<name>.json names it: lowercase letters, digits and hyphens.`);
1280
+ }
1281
+ const entries = Object.entries(record3(input.columns ?? {}, `${sheetAt} "columns"`, null));
1282
+ if (entries.length === 0) {
1283
+ throw new WorkbookError(`${sheetAt} reads query '${input.query}': list its columns in "columns", each with the property it shows in "from".`);
1284
+ }
1285
+ const columns = entries.map(([name, value]) => {
1286
+ const at = `${sheetAt} column '${name}'`;
1287
+ if (INDEX_NAME.test(name)) {
1288
+ throw new WorkbookError(`${at}: a live sheet's columns come in the order "columns" lists them, and JSON puts a name of digits first. Name it with a letter, such as "FY${name}".`);
1289
+ }
1290
+ if (typeof value === "string") {
1291
+ throw new WorkbookError(`${at} is ${JSON.stringify(value)}; a live sheet's column is an object, such as { "from": "amount", "type": "${value}" }.`);
1292
+ }
1293
+ const column = record3(value, at, [
1294
+ "from",
1295
+ "type",
1296
+ "currency",
1297
+ "decimals",
1298
+ "compact",
1299
+ "signed",
1300
+ "tones",
1301
+ "highlight",
1302
+ "formula"
1303
+ ]);
1304
+ if (column.from === undefined && column.formula === undefined) {
1305
+ throw new WorkbookError(`${at} shows nothing: give it "from", the property it shows, or a "formula".`);
1306
+ }
1307
+ if (column.from !== undefined && column.formula !== undefined) {
1308
+ throw new WorkbookError(`${at} has both "from" and "formula": a column shows a property or computes, not both.`);
1309
+ }
1310
+ if (column.from === undefined)
1311
+ return { name };
1312
+ const from = column.from;
1313
+ const segments = typeof from === "string" ? from.split(".") : [];
1314
+ if (segments.length === 0 || segments.some((segment) => !segment)) {
1315
+ throw new WorkbookError(`${at} "from" must name a property of the rows, such as "amount", or of a link the query expands, such as "customer.name".`);
1316
+ }
1317
+ if (segments.length > 2) {
1318
+ throw new WorkbookError(`${at} "from" is ${JSON.stringify(from)}; a column reads a property of the rows or of one link the query expands, such as "customer.name".`);
1319
+ }
1320
+ const { from: _from, ...untyped } = column;
1321
+ return { name, from, ...column.type === undefined ? { untyped } : {} };
1322
+ });
1323
+ return { query: input.query, columns };
1324
+ }
1325
+ function readSheetColumnFormat(value, at, type) {
1326
+ try {
1327
+ return { format: readColumnFormat({ type, ...value }, at) };
1328
+ } catch (error) {
1329
+ if (error instanceof WorkbookError)
1330
+ return { error: `${WORKBOOK_FILE2}: ${error.message}` };
1331
+ throw error;
1332
+ }
1333
+ }
1334
+ function readColumnFormat(value, at) {
1335
+ if (typeof value === "string")
1336
+ return { type: columnType(value, at) };
1337
+ const input = record3(value, at, [
1338
+ "type",
1339
+ "currency",
1340
+ "decimals",
1341
+ "compact",
1342
+ "signed",
1343
+ "tones",
1344
+ "highlight",
1345
+ "formula"
1346
+ ]);
1347
+ const type = columnType(input.type, at);
1348
+ if (input.currency !== undefined) {
1349
+ if (type !== "currency")
1350
+ throw new WorkbookError(`${at} sets "currency" but is not a currency column.`);
1351
+ if (typeof input.currency !== "string" || !/^[A-Z]{3}$/.test(input.currency)) {
1352
+ throw new WorkbookError(`${at} "currency" must be an ISO 4217 code such as "USD".`);
1353
+ }
1354
+ }
1355
+ if (input.decimals !== undefined && !["number", "currency", "percent"].includes(type)) {
1356
+ throw new WorkbookError(`${at} sets "decimals" but is not a number, currency, or percent column.`);
1357
+ }
1358
+ for (const [key, types, named] of [
1359
+ ["compact", ["number", "currency"], "number or currency"],
1360
+ ["signed", ["number", "currency", "percent"], "number, currency, or percent"]
1361
+ ]) {
1362
+ if (input[key] === undefined)
1363
+ continue;
1364
+ if (typeof input[key] !== "boolean") {
1365
+ throw new WorkbookError(`${at} "${key}" must be true or false.`);
1366
+ }
1367
+ if (!types.includes(type)) {
1368
+ throw new WorkbookError(`${at} sets "${key}" but is not a ${named} column.`);
1369
+ }
1370
+ }
1371
+ let tones;
1372
+ if (input.tones !== undefined) {
1373
+ if (type !== "tag")
1374
+ throw new WorkbookError(`${at} sets "tones" but is not a tag column.`);
1375
+ tones = {};
1376
+ const entries = Object.entries(record3(input.tones, `${at} "tones"`, null));
1377
+ if (entries.length > TONES_MAX) {
1378
+ throw new WorkbookError(`${at} "tones" names ${entries.length} values; it takes at most ${TONES_MAX}.`);
1379
+ }
1380
+ for (const [tag, tone] of entries) {
1381
+ if (!tag.trim() || tag.length > TAG_MAX) {
1382
+ throw new WorkbookError(`${at} "tones" names a value of ${tag.length} characters; a tag is 1 to ${TAG_MAX}.`);
1383
+ }
1384
+ if (!isArtifactTone(tone)) {
1385
+ throw new WorkbookError(`${at} gives '${tag}' the tone ${JSON.stringify(tone)}; use one of ${ARTIFACT_TONES2.join(", ")}.`);
1386
+ }
1387
+ tones[tag] = tone;
1388
+ }
1389
+ }
1390
+ if (input.highlight !== undefined) {
1391
+ if (!SHEET_HIGHLIGHTS2.includes(input.highlight)) {
1392
+ throw new WorkbookError(`${at} "highlight" is ${JSON.stringify(input.highlight)}; use one of ${SHEET_HIGHLIGHTS2.join(", ")}.`);
1393
+ }
1394
+ if (!NUMERIC_COLUMN_TYPES2.includes(type)) {
1395
+ throw new WorkbookError(`${at} sets "highlight" but is not a number, currency, or percent column.`);
1396
+ }
1397
+ }
1398
+ let formula;
1399
+ if (input.formula !== undefined) {
1400
+ if (typeof input.formula !== "string" || !input.formula.trim()) {
1401
+ throw new WorkbookError(`${at} "formula" must be text, such as "[@Revenue]-[@Cost]".`);
1402
+ }
1403
+ if (input.formula.length > FORMULA_MAX) {
1404
+ throw new WorkbookError(`${at} "formula" is ${input.formula.length} characters; a formula is at most ${FORMULA_MAX}.`);
1405
+ }
1406
+ if (type === "link" || type === "image") {
1407
+ throw new WorkbookError(`${at} is a ${type} column, which a formula can't compute.`);
1408
+ }
1409
+ formula = input.formula.trim().replace(/^=/, "");
1410
+ try {
1411
+ parseFormula2(formula);
1412
+ } catch (error) {
1413
+ if (error instanceof FormulaSyntaxError) {
1414
+ throw new WorkbookError(`${at} "formula" does not read: ${error.message}`);
1415
+ }
1416
+ throw error;
1417
+ }
1418
+ }
1419
+ return {
1420
+ type,
1421
+ ...typeof input.currency === "string" ? { currency: input.currency } : {},
1422
+ ...formula ? { formula } : {},
1423
+ ...input.compact === true ? { compact: true } : {},
1424
+ ...input.signed === true ? { signed: true } : {},
1425
+ ...tones ? { tones } : {},
1426
+ ...input.highlight === undefined ? {} : { highlight: input.highlight },
1427
+ ...input.decimals === undefined ? {} : { decimals: integer(input.decimals, 0, 0, 6, `${at} "decimals"`) }
1428
+ };
1429
+ }
1430
+ function columnType(value, at) {
1431
+ if (typeof value === "string" && SHEET_COLUMN_TYPES2.includes(value)) {
1432
+ return value;
1433
+ }
1434
+ throw new WorkbookError(`${at} has type ${JSON.stringify(value)}; use one of ${SHEET_COLUMN_TYPES2.join(", ")}.`);
1435
+ }
1436
+ function readChart(value, index, sheets) {
1437
+ const input = record3(value, `chart ${index + 1}`, [
1438
+ "name",
1439
+ "type",
1440
+ "sheet",
1441
+ "x",
1442
+ "y",
1443
+ "line",
1444
+ "aggregate",
1445
+ "title",
1446
+ "stacked"
1447
+ ]);
1448
+ if (typeof input.name !== "string" || !CHART_NAME.test(input.name)) {
1449
+ throw new WorkbookError(`chart ${index + 1} needs a "name" of lowercase letters, digits, and hyphens, such as "revenue".`);
1450
+ }
1451
+ const at = `chart '${input.name}'`;
1452
+ if (!SHEET_CHART_TYPES.includes(input.type)) {
1453
+ throw new WorkbookError(`${at} has type ${JSON.stringify(input.type)}; use one of ${SHEET_CHART_TYPES.join(", ")}.`);
1454
+ }
1455
+ const type = input.type;
1456
+ if (typeof input.sheet !== "string" || !sheets.some((sheet) => sheet.name === input.sheet)) {
1457
+ throw new WorkbookError(`${at} names sheet ${JSON.stringify(input.sheet)}, which the workbook does not have.`);
1458
+ }
1459
+ if (typeof input.x !== "string" || !input.x)
1460
+ throw new WorkbookError(`${at} needs an "x" column.`);
1461
+ if (input.aggregate !== undefined && !SHEET_CHART_AGGREGATES.includes(input.aggregate)) {
1462
+ throw new WorkbookError(`${at} "aggregate" is ${JSON.stringify(input.aggregate)}; use one of ${SHEET_CHART_AGGREGATES.join(", ")}.`);
1463
+ }
1464
+ const aggregate = input.aggregate;
1465
+ if (aggregate && type === "scatter") {
1466
+ throw new WorkbookError(`${at} is a scatter chart, which plots every row; leave out "aggregate".`);
1467
+ }
1468
+ const columns = (key) => {
1469
+ const value = input[key];
1470
+ const list = typeof value === "string" ? [value] : value ?? [];
1471
+ if (!Array.isArray(list) || !list.every((column) => typeof column === "string" && column)) {
1472
+ throw new WorkbookError(`${at} "${key}" must be a column, or a list of them.`);
1473
+ }
1474
+ return list;
1475
+ };
1476
+ const y = columns("y");
1477
+ const line = columns("line");
1478
+ if (aggregate === "count") {
1479
+ if (y.length > 0 || line.length > 0) {
1480
+ throw new WorkbookError(`${at} counts rows, which needs no "y"; leave it out.`);
1481
+ }
1482
+ } else if (y.length === 0) {
1483
+ throw new WorkbookError(`${at} needs a "y" column, or a list of them.`);
1484
+ }
1485
+ if (line.length > 0 && type !== "bar") {
1486
+ throw new WorkbookError(`${at} is a ${type} chart; only a bar chart draws "line" columns over its bars.`);
1487
+ }
1488
+ if (y.length + line.length > ARTIFACT_LIMITS2.maxChartSeries) {
1489
+ throw new WorkbookError(`${at} plots ${y.length + line.length} columns; a chart reads well with at most ${ARTIFACT_LIMITS2.maxChartSeries}. Split it, or chart the ones that matter.`);
1490
+ }
1491
+ if (type === "pie" && aggregate !== "count" && y.length !== 1)
1492
+ throw new WorkbookError(`${at} is a pie: give it one "y" column.`);
1493
+ if (input.stacked !== undefined && typeof input.stacked !== "boolean") {
1494
+ throw new WorkbookError(`${at} "stacked" must be true or false.`);
1495
+ }
1496
+ if (input.stacked === true && type !== "bar" && type !== "area") {
1497
+ throw new WorkbookError(`${at} is a ${type} chart; only bar and area charts stack.`);
1498
+ }
1499
+ if (input.title !== undefined && (typeof input.title !== "string" || input.title.length > 120)) {
1500
+ throw new WorkbookError(`${at} "title" must be text of at most 120 characters.`);
1501
+ }
1502
+ return {
1503
+ name: input.name,
1504
+ type,
1505
+ sheet: input.sheet,
1506
+ x: input.x,
1507
+ y,
1508
+ line,
1509
+ ...aggregate ? { aggregate } : {},
1510
+ ...typeof input.title === "string" && input.title.trim() ? { title: input.title.trim() } : {},
1511
+ stacked: input.stacked === true
1512
+ };
1513
+ }
1514
+ function record3(value, at, keys) {
1515
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
1516
+ throw new WorkbookError(`${at} must be an object.`);
1517
+ }
1518
+ const input = value;
1519
+ const unknownKey = keys && Object.keys(input).find((key) => !keys.includes(key));
1520
+ if (unknownKey) {
1521
+ throw new WorkbookError(`${at} has '${unknownKey}'; it takes ${keys.map((key) => `"${key}"`).join(", ")}.`);
1522
+ }
1523
+ return input;
1524
+ }
1525
+ function integer(value, fallback, min, max, at) {
1526
+ if (value === undefined)
1527
+ return fallback;
1528
+ if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) {
1529
+ throw new WorkbookError(`${at} must be a whole number from ${min} to ${max}.`);
1530
+ }
1531
+ return value;
1532
+ }
1533
+
1534
+ // src/artifacts/formula/check.ts
1535
+ var FORMULA_FUNCTIONS = {
1536
+ IF: { min: 2, max: 3 },
1537
+ IFERROR: { min: 2, max: 2 },
1538
+ AND: { min: 1, max: 30 },
1539
+ OR: { min: 1, max: 30 },
1540
+ NOT: { min: 1, max: 1 },
1541
+ ISBLANK: { min: 1, max: 1 },
1542
+ ROUND: { min: 2, max: 2 },
1543
+ ABS: { min: 1, max: 1 },
1544
+ MIN: { min: 1, max: 30 },
1545
+ MAX: { min: 1, max: 30 },
1546
+ SUM: { min: 1, max: 30 },
1547
+ AVERAGE: { min: 1, max: 30 },
1548
+ COUNT: { min: 1, max: 30 },
1549
+ LEN: { min: 1, max: 1 },
1550
+ LOWER: { min: 1, max: 1 },
1551
+ UPPER: { min: 1, max: 1 },
1552
+ CONCAT: { min: 1, max: 30 },
1553
+ YEAR: { min: 1, max: 1 },
1554
+ MONTH: { min: 1, max: 1 },
1555
+ DAYS: { min: 2, max: 2 }
1556
+ };
1557
+ var AGGREGATE_FUNCTIONS = new Set([
1558
+ "SUM",
1559
+ "AVERAGE",
1560
+ "MIN",
1561
+ "MAX",
1562
+ "COUNT"
1563
+ ]);
1564
+ function checkFormula2(node, columns) {
1565
+ try {
1566
+ return { type: typeOf(node, columns, false) };
1567
+ } catch (error) {
1568
+ if (error instanceof FormulaCheckError)
1569
+ return { error: error.message };
1570
+ throw error;
1571
+ }
1572
+ }
1573
+
1574
+ class FormulaCheckError extends Error {
1575
+ }
1576
+ var numeric = (type) => type !== "text";
1577
+ function typeOf(node, columns, inAggregate) {
1578
+ switch (node.kind) {
1579
+ case "number":
1580
+ return "number";
1581
+ case "text":
1582
+ return "text";
1583
+ case "boolean":
1584
+ return "boolean";
1585
+ case "ref":
1586
+ case "columnRef": {
1587
+ const type = columns.get(node.column);
1588
+ if (type === undefined) {
1589
+ throw new FormulaCheckError(`it reads column '${node.column}', which the sheet does not have`);
1590
+ }
1591
+ if (node.kind === "columnRef" && !inAggregate) {
1592
+ throw new FormulaCheckError(`[${node.column}] is the whole column, which only ${[...AGGREGATE_FUNCTIONS].join(", ")} take; this row's value is [@${node.column}]`);
1593
+ }
1594
+ return type;
1595
+ }
1596
+ case "unary": {
1597
+ const type = typeOf(node.operand, columns, false);
1598
+ if (!numeric(type))
1599
+ throw new FormulaCheckError(`'${node.op}' needs a number, not text`);
1600
+ return "number";
1601
+ }
1602
+ case "binary": {
1603
+ const left = typeOf(node.left, columns, false);
1604
+ const right = typeOf(node.right, columns, false);
1605
+ switch (node.op) {
1606
+ case "&":
1607
+ return "text";
1608
+ case "=":
1609
+ case "<>":
1610
+ case "<":
1611
+ case "<=":
1612
+ case ">":
1613
+ case ">=":
1614
+ return "boolean";
1615
+ default: {
1616
+ if (!numeric(left) || !numeric(right)) {
1617
+ throw new FormulaCheckError(`'${node.op}' needs numbers on both sides, not text`);
1618
+ }
1619
+ if (node.op === "+" && left === "date" !== (right === "date"))
1620
+ return "date";
1621
+ if (node.op === "-" && left === "date" && right !== "date")
1622
+ return "date";
1623
+ return "number";
1624
+ }
1625
+ }
1626
+ }
1627
+ case "call": {
1628
+ const shape = FORMULA_FUNCTIONS[node.name];
1629
+ if (!shape) {
1630
+ throw new FormulaCheckError(`${node.name} is not a function a sheet computes; use one of ${Object.keys(FORMULA_FUNCTIONS).join(", ")}`);
1631
+ }
1632
+ if (node.args.length < shape.min || node.args.length > shape.max) {
1633
+ const count = shape.min === shape.max ? `${shape.min}` : shape.max === 30 ? `at least ${shape.min}` : `${shape.min} or ${shape.max}`;
1634
+ throw new FormulaCheckError(`${node.name} takes ${count} ${shape.max === 1 ? "argument" : "arguments"}, not ${node.args.length}`);
1635
+ }
1636
+ const aggregate = AGGREGATE_FUNCTIONS.has(node.name);
1637
+ const args = node.args.map((arg) => typeOf(arg, columns, aggregate));
1638
+ switch (node.name) {
1639
+ case "IF": {
1640
+ const [, then = "boolean", otherwise = "boolean"] = args;
1641
+ return then === otherwise ? then : "any";
1642
+ }
1643
+ case "IFERROR": {
1644
+ const [value = "any", fallback = "any"] = args;
1645
+ return value === fallback ? value : "any";
1646
+ }
1647
+ case "AND":
1648
+ case "OR":
1649
+ case "NOT":
1650
+ case "ISBLANK":
1651
+ return "boolean";
1652
+ case "LOWER":
1653
+ case "UPPER":
1654
+ case "CONCAT":
1655
+ return "text";
1656
+ default:
1657
+ for (const [index, type] of args.entries()) {
1658
+ if (node.name !== "LEN" && !aggregate && !numeric(type)) {
1659
+ throw new FormulaCheckError(`${node.name}'s argument ${index + 1} needs a number, not text`);
1660
+ }
1661
+ }
1662
+ return "number";
1663
+ }
1664
+ }
1665
+ }
1666
+ }
1667
+
1668
+ // src/artifacts/formula/evaluate.ts
1669
+ var FORMULA_ERRORS2 = ["#DIV/0!", "#VALUE!"];
1670
+ var isError = (value) => typeof value === "object" && value !== null;
1671
+ var fault = (error) => ({ error });
1672
+ function evaluateFormula(node, scope, memo = new Map) {
1673
+ const value = (current) => {
1674
+ switch (current.kind) {
1675
+ case "number":
1676
+ case "text":
1677
+ case "boolean":
1678
+ return current.value;
1679
+ case "ref":
1680
+ return scope.cell(current.column);
1681
+ case "columnRef":
1682
+ return fault("#VALUE!");
1683
+ case "unary": {
1684
+ const operand = number(value(current.operand));
1685
+ if (isError(operand))
1686
+ return operand;
1687
+ return current.op === "-" ? -operand : operand;
1688
+ }
1689
+ case "binary":
1690
+ return binary(current.op, value(current.left), value(current.right));
1691
+ case "call": {
1692
+ const constant = AGGREGATE_FUNCTIONS.has(current.name) && current.args.every(isConstant);
1693
+ if (constant && memo.has(current))
1694
+ return memo.get(current);
1695
+ const result = call(current.name, current.args, value, scope);
1696
+ if (constant)
1697
+ memo.set(current, result);
1698
+ return result;
1699
+ }
1700
+ }
1701
+ };
1702
+ return value(node);
1703
+ }
1704
+ function isConstant(node) {
1705
+ return node.kind === "columnRef" || node.kind === "number" || node.kind === "text";
1706
+ }
1707
+ function number(value) {
1708
+ if (isError(value))
1709
+ return value;
1710
+ if (value === null)
1711
+ return 0;
1712
+ if (typeof value === "boolean")
1713
+ return value ? 1 : 0;
1714
+ if (typeof value === "number")
1715
+ return value;
1716
+ const trimmed = value.trim();
1717
+ const parsed = trimmed ? Number(trimmed) : Number.NaN;
1718
+ return /^[-+]?(\d+\.?\d*|\.\d+)(e[-+]?\d+)?$/i.test(trimmed) && Number.isFinite(parsed) ? parsed : fault("#VALUE!");
1719
+ }
1720
+ function formulaText(value) {
1721
+ if (value === null)
1722
+ return "";
1723
+ if (typeof value === "boolean")
1724
+ return value ? "TRUE" : "FALSE";
1725
+ if (typeof value === "number")
1726
+ return String(Number(value.toPrecision(15)));
1727
+ return value;
1728
+ }
1729
+ function truth(value) {
1730
+ if (isError(value))
1731
+ return value;
1732
+ if (value === null)
1733
+ return false;
1734
+ if (typeof value === "boolean")
1735
+ return value;
1736
+ if (typeof value === "number")
1737
+ return value !== 0;
1738
+ const word = value.trim().toUpperCase();
1739
+ return word === "TRUE" ? true : word === "FALSE" ? false : fault("#VALUE!");
1740
+ }
1741
+ var finite = (result) => Number.isFinite(result) ? result : fault("#VALUE!");
1742
+ function binary(op, left, right) {
1743
+ if (isError(left))
1744
+ return left;
1745
+ if (isError(right))
1746
+ return right;
1747
+ if (op === "&")
1748
+ return formulaText(left) + formulaText(right);
1749
+ if (op === "=" || op === "<>" || op === "<" || op === "<=" || op === ">" || op === ">=") {
1750
+ const order = compare(left, right);
1751
+ return {
1752
+ "=": order === 0,
1753
+ "<>": order !== 0,
1754
+ "<": order < 0,
1755
+ "<=": order <= 0,
1756
+ ">": order > 0,
1757
+ ">=": order >= 0
1758
+ }[op];
1759
+ }
1760
+ const a = number(left);
1761
+ const b = number(right);
1762
+ if (isError(a))
1763
+ return a;
1764
+ if (isError(b))
1765
+ return b;
1766
+ switch (op) {
1767
+ case "+":
1768
+ return finite(a + b);
1769
+ case "-":
1770
+ return finite(a - b);
1771
+ case "*":
1772
+ return finite(a * b);
1773
+ case "/":
1774
+ return b === 0 ? fault("#DIV/0!") : finite(a / b);
1775
+ case "^":
1776
+ return a === 0 && b < 0 ? fault("#DIV/0!") : finite(a ** b);
1777
+ }
1778
+ }
1779
+ function compare(left, right) {
1780
+ const blank = (other) => typeof other === "number" ? 0 : typeof other === "boolean" ? false : "";
1781
+ const a = left === null ? blank(right) : left;
1782
+ const b = right === null ? blank(left) : right;
1783
+ const rank = (value) => typeof value === "number" ? 0 : typeof value === "string" ? 1 : 2;
1784
+ if (rank(a) !== rank(b))
1785
+ return rank(a) - rank(b);
1786
+ if (typeof a === "string" && typeof b === "string") {
1787
+ const x = a.toLowerCase();
1788
+ const y = b.toLowerCase();
1789
+ return x < y ? -1 : x > y ? 1 : 0;
1790
+ }
1791
+ return Number(a) - Number(b);
1792
+ }
1793
+ var EPOCH_SERIAL = 25569;
1794
+ var DAY_MS = 86400000;
1795
+ function dateSerial(date) {
1796
+ return date.getTime() / DAY_MS + EPOCH_SERIAL;
1797
+ }
1798
+ function serialDate(serial) {
1799
+ const date = new Date(Math.round((serial - EPOCH_SERIAL) * DAY_MS));
1800
+ const iso = date.toISOString();
1801
+ return Number.isInteger(serial) ? iso.slice(0, 10) : `${iso.slice(0, 19)}Z`;
1802
+ }
1803
+ function call(name, args, value, scope) {
1804
+ const at = (index) => value(args[index]);
1805
+ switch (name) {
1806
+ case "IF": {
1807
+ const condition = truth(at(0));
1808
+ if (isError(condition))
1809
+ return condition;
1810
+ if (condition)
1811
+ return at(1);
1812
+ return args.length > 2 ? at(2) : false;
1813
+ }
1814
+ case "IFERROR": {
1815
+ const result = at(0);
1816
+ return isError(result) ? at(1) : result;
1817
+ }
1818
+ case "AND":
1819
+ case "OR": {
1820
+ const values = args.map((_, index) => at(index)).filter((entry) => entry !== null);
1821
+ if (values.length === 0)
1822
+ return fault("#VALUE!");
1823
+ let result = name === "AND";
1824
+ for (const entry of values) {
1825
+ const flag = truth(entry);
1826
+ if (isError(flag))
1827
+ return flag;
1828
+ result = name === "AND" ? result && flag : result || flag;
1829
+ }
1830
+ return result;
1831
+ }
1832
+ case "NOT": {
1833
+ const flag = truth(at(0));
1834
+ return isError(flag) ? flag : !flag;
1835
+ }
1836
+ case "ISBLANK":
1837
+ return at(0) === null;
1838
+ case "ROUND": {
1839
+ const x = number(at(0));
1840
+ const digits = number(at(1));
1841
+ if (isError(x))
1842
+ return x;
1843
+ if (isError(digits))
1844
+ return digits;
1845
+ const scale = 10 ** Math.trunc(digits);
1846
+ return Math.sign(x) * Math.round(Number((Math.abs(x) * scale).toPrecision(15))) / scale;
1847
+ }
1848
+ case "ABS": {
1849
+ const x = number(at(0));
1850
+ return isError(x) ? x : Math.abs(x);
1851
+ }
1852
+ case "LEN":
1853
+ case "LOWER":
1854
+ case "UPPER": {
1855
+ const text = at(0);
1856
+ if (isError(text))
1857
+ return text;
1858
+ const written = formulaText(text);
1859
+ return name === "LEN" ? written.length : name === "LOWER" ? written.toLowerCase() : written.toUpperCase();
1860
+ }
1861
+ case "CONCAT": {
1862
+ let text = "";
1863
+ for (const index of args.keys()) {
1864
+ const part = at(index);
1865
+ if (isError(part))
1866
+ return part;
1867
+ text += formulaText(part);
1868
+ }
1869
+ return text;
1870
+ }
1871
+ case "YEAR":
1872
+ case "MONTH": {
1873
+ const serial = number(at(0));
1874
+ if (isError(serial))
1875
+ return serial;
1876
+ if (serial < 0)
1877
+ return fault("#VALUE!");
1878
+ const date = new Date((Math.floor(serial) - EPOCH_SERIAL) * DAY_MS);
1879
+ return name === "YEAR" ? date.getUTCFullYear() : date.getUTCMonth() + 1;
1880
+ }
1881
+ case "DAYS": {
1882
+ const end = number(at(0));
1883
+ const start = number(at(1));
1884
+ if (isError(end))
1885
+ return end;
1886
+ if (isError(start))
1887
+ return start;
1888
+ return Math.floor(end) - Math.floor(start);
1889
+ }
1890
+ default: {
1891
+ const numbers = [];
1892
+ for (const [index, arg] of args.entries()) {
1893
+ const values = arg.kind === "columnRef" ? scope.column(arg.column) : [at(index)];
1894
+ for (const entry of values) {
1895
+ if (isError(entry))
1896
+ return entry;
1897
+ if (typeof entry === "number")
1898
+ numbers.push(entry);
1899
+ }
1900
+ }
1901
+ switch (name) {
1902
+ case "COUNT":
1903
+ return numbers.length;
1904
+ case "SUM":
1905
+ return numbers.reduce((sum, entry) => sum + entry, 0);
1906
+ case "AVERAGE":
1907
+ return numbers.length === 0 ? fault("#DIV/0!") : numbers.reduce((sum, entry) => sum + entry, 0) / numbers.length;
1908
+ case "MIN":
1909
+ return numbers.length === 0 ? 0 : numbers.reduce((min, entry) => Math.min(min, entry));
1910
+ case "MAX":
1911
+ return numbers.length === 0 ? 0 : numbers.reduce((max, entry) => Math.max(max, entry));
1912
+ default:
1913
+ return fault("#VALUE!");
1914
+ }
1915
+ }
1916
+ }
1917
+ }
1918
+
1919
+ // src/artifacts/formula/index.ts
1920
+ function columnFormulaType2(type) {
1921
+ if (NUMERIC_COLUMN_TYPES2.includes(type))
1922
+ return "number";
1923
+ if (type === "date" || type === "boolean")
1924
+ return type;
1925
+ return "text";
1926
+ }
1927
+ function formulaFitsColumn2(result, type) {
1928
+ if (result === "any" || type === "text" || type === "tag")
1929
+ return true;
1930
+ if (NUMERIC_COLUMN_TYPES2.includes(type))
1931
+ return result === "number";
1932
+ if (type === "date")
1933
+ return result === "date";
1934
+ if (type === "boolean")
1935
+ return result === "boolean";
1936
+ return false;
1937
+ }
1938
+
1939
+ class FormulaCycleError2 extends Error {
1940
+ columns;
1941
+ constructor(columns) {
1942
+ super(`columns ${columns.map((column) => `'${column}'`).join(" \u2192 ")} compute from each other`);
1943
+ this.columns = columns;
1944
+ this.name = "FormulaCycleError";
1945
+ }
1946
+ }
1947
+ function evaluateComputedColumns2(sheet, table) {
1948
+ const computed = table.header.filter((name) => sheet.columns[name]?.formula !== undefined);
1949
+ if (computed.length === 0)
1950
+ return { table, errors: new Map };
1951
+ const formulas = new Map(computed.map((name) => [name, parseFormula2(sheet.columns[name]?.formula ?? "")]));
1952
+ const indexOf = new Map(table.header.map((name, index) => [name, index]));
1953
+ const typeOf = (name) => sheet.columns[name]?.type ?? "text";
1954
+ const values = new Map;
1955
+ const columnValues = (name) => {
1956
+ let column = values.get(name);
1957
+ if (!column) {
1958
+ const index = indexOf.get(name) ?? -1;
1959
+ const type = typeOf(name);
1960
+ column = table.rows.map((row) => readCell(row[index] ?? "", type));
1961
+ values.set(name, column);
1962
+ }
1963
+ return column;
1964
+ };
1965
+ const rows = table.rows.map((row) => {
1966
+ const copy = [...row];
1967
+ while (copy.length < table.header.length)
1968
+ copy.push("");
1969
+ return copy;
1970
+ });
1971
+ const errors = new Map;
1972
+ for (const name of computeOrder(formulas)) {
1973
+ const formula = formulas.get(name);
1974
+ const index = indexOf.get(name);
1975
+ const type = typeOf(name);
1976
+ const results = [];
1977
+ const memo = new Map;
1978
+ for (const [rowIndex, row] of rows.entries()) {
1979
+ const result = evaluateFormula(formula, {
1980
+ cell: (column) => columnValues(column)[rowIndex] ?? null,
1981
+ column: (column) => columnValues(column)
1982
+ }, memo);
1983
+ const cell = writeCell(result, type);
1984
+ results.push(typeof cell === "object" ? cell : result);
1985
+ row[index] = typeof cell === "object" ? cell.error : cell;
1986
+ if (typeof cell === "object") {
1987
+ const known = errors.get(name);
1988
+ errors.set(name, {
1989
+ count: (known?.count ?? 0) + 1,
1990
+ firstRow: known?.firstRow ?? rowIndex,
1991
+ code: known?.code ?? cell.error
1992
+ });
1993
+ }
1994
+ }
1995
+ values.set(name, results);
1996
+ }
1997
+ return { table: { header: table.header, rows }, errors };
1998
+ }
1999
+ function computeOrder(formulas) {
2000
+ const order = [];
2001
+ const state = new Map;
2002
+ const visit = (name, path) => {
2003
+ if (state.get(name) === "done")
2004
+ return;
2005
+ if (state.get(name) === "visiting") {
2006
+ throw new FormulaCycleError2([...path.slice(path.indexOf(name)), name]);
2007
+ }
2008
+ state.set(name, "visiting");
2009
+ for (const dependency of formulaDependencies2(formulas.get(name))) {
2010
+ if (formulas.has(dependency))
2011
+ visit(dependency, [...path, name]);
2012
+ }
2013
+ state.set(name, "done");
2014
+ order.push(name);
2015
+ };
2016
+ for (const name of formulas.keys())
2017
+ visit(name, []);
2018
+ return order;
2019
+ }
2020
+ function readCell(raw, type) {
2021
+ if (!raw.trim())
2022
+ return null;
2023
+ if (NUMERIC_COLUMN_TYPES2.includes(type))
2024
+ return parseSheetNumber2(raw) ?? raw;
2025
+ if (type === "date") {
2026
+ const date = parseSheetDate2(raw);
2027
+ return date ? dateSerial(date) : raw;
2028
+ }
2029
+ if (type === "boolean") {
2030
+ const word = raw.trim().toLowerCase();
2031
+ return word === "true" ? true : word === "false" ? false : raw;
2032
+ }
2033
+ return raw;
2034
+ }
2035
+ function writeCell(value, type) {
2036
+ if (typeof value === "object" && value !== null)
2037
+ return value;
2038
+ if (value === null)
2039
+ return "";
2040
+ if (type === "text" || type === "tag")
2041
+ return formulaText(value);
2042
+ if (NUMERIC_COLUMN_TYPES2.includes(type)) {
2043
+ return typeof value === "number" ? formulaText(value) : { error: "#VALUE!" };
2044
+ }
2045
+ if (type === "date") {
2046
+ return typeof value === "number" ? serialDate(value) : { error: "#VALUE!" };
2047
+ }
2048
+ if (type === "boolean") {
2049
+ return typeof value === "boolean" ? String(value) : { error: "#VALUE!" };
2050
+ }
2051
+ return { error: "#VALUE!" };
2052
+ }
2053
+
2054
+ // src/artifacts/live-sheet.ts
2055
+ function sheetColumnType(property) {
2056
+ switch (property.type) {
2057
+ case "integer":
2058
+ case "double":
2059
+ case "decimal":
2060
+ return "number";
2061
+ case "boolean":
2062
+ return "boolean";
2063
+ case "date":
2064
+ case "timestamp":
2065
+ return "date";
2066
+ case "enum":
2067
+ return property.valueType === "integer" ? "number" : "tag";
2068
+ default:
2069
+ return "text";
2070
+ }
2071
+ }
2072
+ function liveSheetColumns2(sheet, schema) {
2073
+ const live = sheet.live;
2074
+ if (!live)
2075
+ throw new Error(`[Sixb] Sheet '${sheet.name}' is not a live sheet.`);
2076
+ let problem = null;
2077
+ const formats = {};
2078
+ const totals = { ...sheet.totals };
2079
+ const columns = live.columns.map((source) => {
2080
+ const columnAt = `sheet '${sheet.name}' column '${source.name}'`;
2081
+ const at = `${WORKBOOK_FILE2} ${columnAt}`;
2082
+ const written = sheet.columns[source.name];
2083
+ if (source.from === undefined) {
2084
+ if (written)
2085
+ formats[source.name] = written;
2086
+ return { name: source.name, missing: false };
2087
+ }
2088
+ const [first = "", second] = source.from.split(".");
2089
+ const from = second === undefined ? { propertyId: first } : { linkId: first, propertyId: second };
2090
+ const found = resolveProperty(schema, live.query, from);
2091
+ if ("problem" in found)
2092
+ problem ??= `${at} "from": ${found.problem}`;
2093
+ const inferred = "property" in found ? sheetColumnType(found.property) : undefined;
2094
+ const format = layColumn(columnAt, source.from, written, source.untyped, inferred);
2095
+ if (format.problem)
2096
+ problem ??= format.problem;
2097
+ formats[source.name] = format.format;
2098
+ const total = totals[source.name];
2099
+ const totalProblem = total && source.untyped ? sheetTotalProblem(`${WORKBOOK_FILE2} sheet '${sheet.name}'`, source.name, total, format.format.type) : null;
2100
+ if (totalProblem) {
2101
+ problem ??= totalProblem;
2102
+ delete totals[source.name];
2103
+ }
2104
+ return { name: source.name, from, missing: !("property" in found) };
2105
+ });
2106
+ return { sheet: { ...sheet, columns: formats, totals }, columns, problem };
2107
+ }
2108
+ function resolveProperty(schema, query, from) {
2109
+ const { linkId, propertyId } = from;
2110
+ if (linkId === undefined) {
2111
+ const property = schema.properties[propertyId];
2112
+ return property ? { property } : {
2113
+ problem: `query '${query}' returns no property '${propertyId}'${known(schema.properties)}.`
2114
+ };
2115
+ }
2116
+ const link = schema.links[linkId];
2117
+ if (!link) {
2118
+ return {
2119
+ problem: `query '${query}' does not expand link '${linkId}': add it to the query's "expand" node, or show a property of the rows.`
2120
+ };
2121
+ }
2122
+ const property = link.properties[propertyId];
2123
+ return property ? { property } : { problem: `link '${linkId}' reaches no property '${propertyId}'${known(link.properties)}.` };
2124
+ }
2125
+ function known(properties) {
2126
+ const ids = Object.keys(properties);
2127
+ return ids.length > 0 ? `; it has ${ids.join(", ")}` : "";
2128
+ }
2129
+ function layColumn(columnAt, from, written, untyped, inferred) {
2130
+ if (written) {
2131
+ if (inferred === undefined || fits(written.type, inferred))
2132
+ return { format: written };
2133
+ return {
2134
+ format: written,
2135
+ problem: `${WORKBOOK_FILE2} ${columnAt} is ${written.type}, but '${from}' holds ${HOLDS[inferred]}: leave out "type" to show it as its property is, or show another property.`
2136
+ };
2137
+ }
2138
+ const type = inferred ?? "text";
2139
+ const read = readSheetColumnFormat(untyped ?? {}, columnAt, type);
2140
+ return "format" in read ? read : { format: { type }, problem: read.error };
2141
+ }
2142
+ var HOLDS = {
2143
+ text: "text",
2144
+ tag: "text",
2145
+ number: "numbers",
2146
+ currency: "numbers",
2147
+ percent: "numbers",
2148
+ date: "dates",
2149
+ boolean: "true or false",
2150
+ link: "text",
2151
+ image: "text"
2152
+ };
2153
+ function fits(type, inferred) {
2154
+ if (NUMERIC_COLUMN_TYPES2.includes(type))
2155
+ return inferred === "number";
2156
+ if (type === "date" || type === "boolean")
2157
+ return inferred === type;
2158
+ return true;
2159
+ }
2160
+ function liveSheetTable2(layout, rows) {
2161
+ const { columns } = layout;
2162
+ const locked = new Map;
2163
+ const lock = (row, column) => {
2164
+ const cells = locked.get(row) ?? new Set;
2165
+ cells.add(column);
2166
+ locked.set(row, cells);
2167
+ };
2168
+ const tableRows = rows.map((row, rowIndex) => columns.map((column, columnIndex) => {
2169
+ if (!column.from)
2170
+ return "";
2171
+ if (column.missing) {
2172
+ lock(rowIndex, columnIndex);
2173
+ return "";
2174
+ }
2175
+ const cell = readCell2(row, column.from);
2176
+ if (cell.locked)
2177
+ lock(rowIndex, columnIndex);
2178
+ return cell.locked ? "" : cell.text;
2179
+ }));
2180
+ lockComputed(layout, rows.length, locked);
2181
+ return { table: { header: columns.map((column) => column.name), rows: tableRows }, locked };
2182
+ }
2183
+ function readCell2(row, from) {
2184
+ const { linkId, propertyId } = from;
2185
+ if (linkId === undefined)
2186
+ return propertyCell(row, propertyId);
2187
+ const linked = row.links?.[linkId];
2188
+ if (!linked)
2189
+ return { text: "", locked: false };
2190
+ if (!isRowList(linked))
2191
+ return propertyCell(linked, propertyId);
2192
+ const values = linked.map((each) => propertyCell(each, propertyId));
2193
+ return {
2194
+ text: values.map((value) => value.text).filter(Boolean).join(", "),
2195
+ locked: values.some((value) => value.locked)
2196
+ };
2197
+ }
2198
+ function isRowList(value) {
2199
+ return Array.isArray(value);
2200
+ }
2201
+ function propertyCell(row, propertyId) {
2202
+ if (row.redactions && Object.hasOwn(row.redactions, propertyId)) {
2203
+ return { text: "", locked: true };
2204
+ }
2205
+ return { text: cellText(row.properties[propertyId]), locked: false };
2206
+ }
2207
+ function cellText(value) {
2208
+ if (value === null || value === undefined)
2209
+ return "";
2210
+ if (typeof value === "string")
2211
+ return value;
2212
+ if (typeof value === "number" || typeof value === "bigint")
2213
+ return String(value);
2214
+ if (typeof value === "boolean")
2215
+ return value ? "true" : "false";
2216
+ if (value instanceof Date)
2217
+ return value.toISOString();
2218
+ if (Array.isArray(value))
2219
+ return value.map(cellText).filter(Boolean).join(", ");
2220
+ return JSON.stringify(value);
2221
+ }
2222
+ function lockComputed(layout, rowCount, locked) {
2223
+ const indexOf = new Map(layout.columns.map((column, index) => [column.name, index]));
2224
+ const indexes = (names) => [...names].map((name) => indexOf.get(name)).filter((read) => read !== undefined);
2225
+ const computed = layout.columns.flatMap((column, index) => {
2226
+ const formula = column.from ? undefined : layout.sheet.columns[column.name]?.formula;
2227
+ if (!formula)
2228
+ return [];
2229
+ const { row, whole } = formulaReferences2(parseFormula2(formula));
2230
+ return [{ index, row: indexes(row), whole: indexes(whole) }];
2231
+ });
2232
+ if (computed.length === 0)
2233
+ return;
2234
+ for (let changed = true;changed; ) {
2235
+ changed = false;
2236
+ const anywhere = new Set;
2237
+ for (const cells of locked.values())
2238
+ for (const column of cells)
2239
+ anywhere.add(column);
2240
+ for (const { index, whole } of computed) {
2241
+ if (!whole.some((read) => anywhere.has(read)))
2242
+ continue;
2243
+ for (let row = 0;row < rowCount; row += 1) {
2244
+ const cells = locked.get(row) ?? new Set;
2245
+ if (cells.has(index))
2246
+ continue;
2247
+ cells.add(index);
2248
+ locked.set(row, cells);
2249
+ changed = true;
2250
+ }
2251
+ }
2252
+ for (const cells of locked.values()) {
2253
+ for (const { index, row } of computed) {
2254
+ if (cells.has(index) || !row.some((read) => cells.has(read)))
2255
+ continue;
2256
+ cells.add(index);
2257
+ changed = true;
2258
+ }
2259
+ }
2260
+ }
2261
+ }
2262
+
2263
+ // src/artifacts/sheet-rules.ts
2264
+ function checkSheet2(workbook, tables) {
2265
+ for (const sheet of workbook.sheets) {
2266
+ const table = tables.get(sheet.name);
2267
+ if (!table)
2268
+ continue;
2269
+ const problem = sheetColumnsProblem(sheet, table) ?? sheetFormulasProblem(sheet, table);
2270
+ if (problem)
2271
+ return problem;
2272
+ }
2273
+ return sheetChartsProblem(workbook, tables);
2274
+ }
2275
+ function sheetColumnsProblem(sheet, table) {
2276
+ const path = sheetFilePath2(sheet.name);
2277
+ const source = sheet.live ? `${WORKBOOK_FILE2} sheet '${sheet.name}' "columns"` : `'${path}'`;
2278
+ const { header, rows } = table;
2279
+ if (header.length === 0)
2280
+ return `'${path}' is empty: its first line names the columns.`;
2281
+ if (header.length > ARTIFACT_LIMITS2.maxSheetColumns) {
2282
+ return `${source} has ${header.length} columns; a sheet holds at most ${ARTIFACT_LIMITS2.maxSheetColumns}.`;
2283
+ }
2284
+ const seen = new Set;
2285
+ for (const [index, name] of header.entries()) {
2286
+ if (!name.trim())
2287
+ return `${source} column ${index + 1} has no name${sheet.live ? "" : " in the header row"}.`;
2288
+ if (seen.has(name))
2289
+ return `${source} has two columns named '${name}'.`;
2290
+ seen.add(name);
2291
+ }
2292
+ if (rows.length > ARTIFACT_LIMITS2.maxSheetRows) {
2293
+ return `'${path}' has ${rows.length} rows; a sheet holds at most ${ARTIFACT_LIMITS2.maxSheetRows}.`;
2294
+ }
2295
+ for (const [index, row] of rows.entries()) {
2296
+ if (row.length > header.length) {
2297
+ return `'${path}' row ${index + 2} has ${row.length} fields; the header names ${header.length} columns.`;
2298
+ }
2299
+ }
2300
+ for (const column of [
2301
+ ...Object.keys(sheet.columns),
2302
+ ...Object.keys(sheet.widths),
2303
+ ...Object.keys(sheet.descriptions),
2304
+ ...Object.keys(sheet.totals)
2305
+ ]) {
2306
+ if (!seen.has(column)) {
2307
+ return `${WORKBOOK_FILE2} sheet '${sheet.name}' names column '${column}', which ${sheet.live ? 'its "columns" does not list' : `'${path}' does not have`}.`;
2308
+ }
2309
+ }
2310
+ return null;
2311
+ }
2312
+ function sheetFormulasProblem(sheet, table) {
2313
+ const at = (column) => `${WORKBOOK_FILE2} sheet '${sheet.name}' column '${column}'`;
2314
+ const types = new Map(table.header.map((name) => [name, columnFormulaType2(sheet.columns[name]?.type ?? "text")]));
2315
+ for (const [column, format] of Object.entries(sheet.columns)) {
2316
+ if (!format.formula)
2317
+ continue;
2318
+ let node;
2319
+ try {
2320
+ node = parseFormula2(format.formula);
2321
+ } catch (error) {
2322
+ if (error instanceof FormulaSyntaxError) {
2323
+ return `${at(column)} "formula" does not read: ${error.message}`;
2324
+ }
2325
+ throw error;
2326
+ }
2327
+ const checked = checkFormula2(node, types);
2328
+ if ("error" in checked)
2329
+ return `${at(column)} "formula": ${checked.error}.`;
2330
+ if (!formulaFitsColumn2(checked.type, format.type)) {
2331
+ return `${at(column)} "formula" computes ${checked.type === "date" ? "a date" : checked.type === "boolean" ? "true or false" : checked.type === "text" ? "text" : "a number"}, which a ${format.type} column can't show: change its type, or the formula.`;
2332
+ }
2333
+ }
2334
+ try {
2335
+ evaluateComputedColumns2(sheet, { header: table.header, rows: [] });
2336
+ } catch (error) {
2337
+ if (error instanceof FormulaCycleError2) {
2338
+ return `${WORKBOOK_FILE2} sheet '${sheet.name}': ${error.message}, so none can be computed first.`;
2339
+ }
2340
+ throw error;
2341
+ }
2342
+ return null;
2343
+ }
2344
+ function sheetChartsProblem(workbook, tables) {
2345
+ for (const chart of workbook.charts) {
2346
+ const sheet = workbook.sheets.find((candidate) => candidate.name === chart.sheet);
2347
+ const table = tables.get(chart.sheet);
2348
+ if (!sheet || !table)
2349
+ continue;
2350
+ const plotted = [...chart.y, ...chart.line];
2351
+ for (const column of [chart.x, ...plotted]) {
2352
+ if (!table.header.includes(column)) {
2353
+ return `${WORKBOOK_FILE2} chart '${chart.name}' plots column '${column}', which sheet '${chart.sheet}' does not have.`;
2354
+ }
2355
+ }
2356
+ for (const column of chart.type === "scatter" ? [chart.x, ...plotted] : plotted) {
2357
+ const type = sheet.columns[column]?.type ?? "text";
2358
+ if (!NUMERIC_COLUMN_TYPES2.includes(type)) {
2359
+ return `${WORKBOOK_FILE2} chart '${chart.name}' plots column '${column}', which is ${type}; give it a number, currency, or percent type in "columns".`;
2360
+ }
2361
+ }
2362
+ const barType = sheet.columns[chart.y[0] ?? ""]?.type;
2363
+ const rightTypes = new Set(chart.line.map((column) => sheet.columns[column]?.type).filter((type) => type !== barType));
2364
+ if (rightTypes.size > 1) {
2365
+ return `${WORKBOOK_FILE2} chart '${chart.name}' draws lines of ${[...rightTypes].join(" and ")} over ${barType ?? "its"} bars; the right axis reads one kind. Chart the others separately.`;
2366
+ }
2367
+ if (chart.type === "pie") {
2368
+ const index = table.header.indexOf(chart.x);
2369
+ const slices = chart.aggregate ? new Set(table.rows.map((row) => (row[index] ?? "").trim())).size : table.rows.length;
2370
+ if (slices > ARTIFACT_LIMITS2.maxPieSlices) {
2371
+ return `${WORKBOOK_FILE2} chart '${chart.name}' is a pie with ${slices} slices; a pie reads well with at most ${ARTIFACT_LIMITS2.maxPieSlices}. Use a bar chart instead.`;
2372
+ }
2373
+ }
2374
+ }
2375
+ return null;
2376
+ }
2377
+
2378
+ export { ARTIFACT_THEME_FILE2, ARTIFACT_THEME_TOKENS, parseArtifactTheme2, ARTIFACT_QUERIES_DIRECTORY, ARTIFACT_QUERY_KINDS, isArtifactQueryName, artifactQueryPath, artifactQueryName2, parseArtifactQuery, resolveArtifactAddress2, ARTIFACT_TONES2, CANVAS_FILE2, parseCanvas2, createHeadingSlugger2, CsvParseError2, parseCsv2, formatCsv2, parseFormula2, formulaDependencies2, formulaReferences2, renameColumnReferences2, WORKBOOK_FILE2, SHEET_COLUMN_TYPES2, NUMERIC_COLUMN_TYPES2, SHEET_HIGHLIGHTS2, SHEET_TOTALS2, sheetFilePath2, parseWorkbook2, parseSheetNumber2, parseSheetDate2, checkFormula2, FORMULA_ERRORS2, columnFormulaType2, formulaFitsColumn2, FormulaCycleError2, evaluateComputedColumns2, liveSheetColumns2, liveSheetTable2, checkSheet2, sheetColumnsProblem, sheetFormulasProblem, sheetChartsProblem };
2379
+
2380
+ //# debugId=B716461C2DF6F0DA64756E2164756E21