@sixb/core 0.2.3 → 0.2.5

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 (587) hide show
  1. package/dist/actions/index.js +28 -28
  2. package/dist/agents/cancel.d.ts +1 -1
  3. package/dist/agents/cancel.d.ts.map +1 -1
  4. package/dist/agents/child-question.d.ts +35 -2
  5. package/dist/agents/child-question.d.ts.map +1 -1
  6. package/dist/agents/execution.d.ts +35 -3
  7. package/dist/agents/execution.d.ts.map +1 -1
  8. package/dist/agents/ids.d.ts +4 -0
  9. package/dist/agents/ids.d.ts.map +1 -1
  10. package/dist/agents/index.d.ts +9 -7
  11. package/dist/agents/index.d.ts.map +1 -1
  12. package/dist/agents/index.js +59 -33
  13. package/dist/agents/index.js.map +1 -1
  14. package/dist/agents/model-loop.d.ts.map +1 -1
  15. package/dist/agents/queued-turn.d.ts +16 -0
  16. package/dist/agents/queued-turn.d.ts.map +1 -0
  17. package/dist/agents/request.d.ts +79 -1
  18. package/dist/agents/request.d.ts.map +1 -1
  19. package/dist/agents/run-after-finish.d.ts +10 -0
  20. package/dist/agents/run-after-finish.d.ts.map +1 -1
  21. package/dist/agents/run-artifacts.d.ts +0 -38
  22. package/dist/agents/run-artifacts.d.ts.map +1 -1
  23. package/dist/agents/run-events.d.ts +6 -1
  24. package/dist/agents/run-events.d.ts.map +1 -1
  25. package/dist/agents/run-session-children.d.ts +9 -0
  26. package/dist/agents/run-session-children.d.ts.map +1 -1
  27. package/dist/agents/run-session-http.d.ts.map +1 -1
  28. package/dist/agents/run-session-serve.d.ts.map +1 -1
  29. package/dist/agents/run-session.d.ts +14 -1
  30. package/dist/agents/run-session.d.ts.map +1 -1
  31. package/dist/agents/run-turn.d.ts.map +1 -1
  32. package/dist/agents/streams/index.d.ts +1 -1
  33. package/dist/agents/streams/index.d.ts.map +1 -1
  34. package/dist/agents/streams/index.js +1 -1
  35. package/dist/agents/streams/internal.js +1 -1
  36. package/dist/agents/streams/protocol.d.ts +16 -0
  37. package/dist/agents/streams/protocol.d.ts.map +1 -1
  38. package/dist/agents/tool-files.d.ts +1 -1
  39. package/dist/agents/tool-files.d.ts.map +1 -1
  40. package/dist/agents/tool-input-coercion.d.ts +20 -0
  41. package/dist/agents/tool-input-coercion.d.ts.map +1 -0
  42. package/dist/agents/turn-answered.d.ts +7 -0
  43. package/dist/agents/turn-answered.d.ts.map +1 -0
  44. package/dist/agents/validation.d.ts +1 -1
  45. package/dist/agents/validation.d.ts.map +1 -1
  46. package/dist/artifacts/canvas-display.d.ts +3 -5
  47. package/dist/artifacts/canvas-display.d.ts.map +1 -1
  48. package/dist/artifacts/comments.d.ts +14 -3
  49. package/dist/artifacts/comments.d.ts.map +1 -1
  50. package/dist/artifacts/document-fill.d.ts +18 -0
  51. package/dist/artifacts/document-fill.d.ts.map +1 -0
  52. package/dist/artifacts/errors.d.ts +1 -1
  53. package/dist/artifacts/errors.d.ts.map +1 -1
  54. package/dist/artifacts/events.d.ts +3 -2
  55. package/dist/artifacts/events.d.ts.map +1 -1
  56. package/dist/artifacts/execution.d.ts +40 -4
  57. package/dist/artifacts/execution.d.ts.map +1 -1
  58. package/dist/artifacts/frames/assets.d.ts +8 -1
  59. package/dist/artifacts/frames/assets.d.ts.map +1 -1
  60. package/dist/artifacts/frames/document-data.d.ts +98 -0
  61. package/dist/artifacts/frames/document-data.d.ts.map +1 -0
  62. package/dist/artifacts/frames/entries.d.ts +12 -7
  63. package/dist/artifacts/frames/entries.d.ts.map +1 -1
  64. package/dist/artifacts/frames/index.d.ts +2 -1
  65. package/dist/artifacts/frames/index.d.ts.map +1 -1
  66. package/dist/artifacts/frames/index.js +22 -13
  67. package/dist/artifacts/frames/index.js.map +4 -4
  68. package/dist/artifacts/frames/kit.d.ts +15 -0
  69. package/dist/artifacts/frames/kit.d.ts.map +1 -1
  70. package/dist/artifacts/frames/protocol.d.ts +65 -3
  71. package/dist/artifacts/frames/protocol.d.ts.map +1 -1
  72. package/dist/artifacts/frames/runtime.d.ts +32 -5
  73. package/dist/artifacts/frames/runtime.d.ts.map +1 -1
  74. package/dist/artifacts/index.d.ts +4 -2
  75. package/dist/artifacts/index.d.ts.map +1 -1
  76. package/dist/artifacts/index.js +35 -3
  77. package/dist/artifacts/index.js.map +3 -3
  78. package/dist/artifacts/live/blocks.d.ts +62 -0
  79. package/dist/artifacts/live/blocks.d.ts.map +1 -0
  80. package/dist/artifacts/live/board.d.ts +6 -0
  81. package/dist/artifacts/live/board.d.ts.map +1 -1
  82. package/dist/artifacts/live/document.d.ts +12 -0
  83. package/dist/artifacts/live/document.d.ts.map +1 -1
  84. package/dist/artifacts/live/index.d.ts +2 -0
  85. package/dist/artifacts/live/index.d.ts.map +1 -1
  86. package/dist/artifacts/live/index.js +148 -44
  87. package/dist/artifacts/live/index.js.map +3 -3
  88. package/dist/artifacts/live/page.d.ts +49 -0
  89. package/dist/artifacts/live/page.d.ts.map +1 -0
  90. package/dist/artifacts/live/protocol.d.ts +5 -0
  91. package/dist/artifacts/live/protocol.d.ts.map +1 -1
  92. package/dist/artifacts/live/server.d.ts +2 -2
  93. package/dist/artifacts/live/server.d.ts.map +1 -1
  94. package/dist/artifacts/live/server.js +23 -19
  95. package/dist/artifacts/live/server.js.map +1 -1
  96. package/dist/artifacts/live/state.d.ts +4 -1
  97. package/dist/artifacts/live/state.d.ts.map +1 -1
  98. package/dist/artifacts/outline.d.ts +16 -0
  99. package/dist/artifacts/outline.d.ts.map +1 -1
  100. package/dist/artifacts/paper.d.ts +22 -0
  101. package/dist/artifacts/paper.d.ts.map +1 -0
  102. package/dist/artifacts/pdf-job.d.ts +9 -0
  103. package/dist/artifacts/pdf-job.d.ts.map +1 -0
  104. package/dist/artifacts/publish/fields.d.ts +25 -0
  105. package/dist/artifacts/publish/fields.d.ts.map +1 -0
  106. package/dist/artifacts/publish/index.d.ts +2 -1
  107. package/dist/artifacts/publish/index.d.ts.map +1 -1
  108. package/dist/artifacts/publish/index.js +26 -18
  109. package/dist/artifacts/publish/index.js.map +1 -1
  110. package/dist/artifacts/publish/merge.d.ts +5 -5
  111. package/dist/artifacts/publish/merge.d.ts.map +1 -1
  112. package/dist/artifacts/publish/pdf.d.ts +28 -0
  113. package/dist/artifacts/publish/pdf.d.ts.map +1 -0
  114. package/dist/artifacts/publish/previews.d.ts +12 -20
  115. package/dist/artifacts/publish/previews.d.ts.map +1 -1
  116. package/dist/artifacts/publish/publish.d.ts.map +1 -1
  117. package/dist/artifacts/publish/queries.d.ts +6 -1
  118. package/dist/artifacts/publish/queries.d.ts.map +1 -1
  119. package/dist/artifacts/publish/query-answers.d.ts +5 -2
  120. package/dist/artifacts/publish/query-answers.d.ts.map +1 -1
  121. package/dist/artifacts/publish/validate/document-html.d.ts +24 -0
  122. package/dist/artifacts/publish/validate/document-html.d.ts.map +1 -0
  123. package/dist/artifacts/publish/validate/document.d.ts +5 -3
  124. package/dist/artifacts/publish/validate/document.d.ts.map +1 -1
  125. package/dist/artifacts/queries.d.ts +16 -2
  126. package/dist/artifacts/queries.d.ts.map +1 -1
  127. package/dist/auth/index.js +2 -2
  128. package/dist/authorization/event-visibility.d.ts.map +1 -1
  129. package/dist/authorization/index.js +1 -1
  130. package/dist/blob-storage/index.js +1 -1
  131. package/dist/bootstrap/index.js +38 -38
  132. package/dist/{chunk-tqa68kj7.js → chunk-0hkdtwqk.js} +5 -5
  133. package/dist/{chunk-s5n9617r.js → chunk-0mvjpgvm.js} +5 -5
  134. package/dist/{chunk-k66rp2hr.js → chunk-1yh6jgtz.js} +1 -1
  135. package/dist/{chunk-26qet7wh.js → chunk-5t9gm5tt.js} +4 -4
  136. package/dist/{chunk-a6fjkcne.js → chunk-60662fyv.js} +54 -28
  137. package/dist/{chunk-a6fjkcne.js.map → chunk-60662fyv.js.map} +7 -6
  138. package/dist/{chunk-e0hnbb1m.js → chunk-61zptves.js} +1 -1
  139. package/dist/{chunk-hkaa807g.js → chunk-68hm50qh.js} +3 -3
  140. package/dist/{chunk-9nsjjd44.js → chunk-8tv3qd65.js} +2 -1
  141. package/dist/chunk-8tv3qd65.js.map +12 -0
  142. package/dist/{chunk-fe6r7yhg.js → chunk-92wrka15.js} +1 -1
  143. package/dist/{chunk-m7b9q5dk.js → chunk-aw1z0gre.js} +4 -4
  144. package/dist/chunk-az95tsh3.js.map +2 -2
  145. package/dist/{chunk-4j0sagwv.js → chunk-b4escq4c.js} +62 -14
  146. package/dist/{chunk-4j0sagwv.js.map → chunk-b4escq4c.js.map} +7 -7
  147. package/dist/chunk-bqr703h4.js +1799 -0
  148. package/dist/chunk-bqr703h4.js.map +13 -0
  149. package/dist/{chunk-eptrvnby.js → chunk-c29729me.js} +42 -3
  150. package/dist/chunk-c29729me.js.map +12 -0
  151. package/dist/{chunk-t24yktqr.js → chunk-dvgc56n2.js} +20 -4
  152. package/dist/{chunk-t24yktqr.js.map → chunk-dvgc56n2.js.map} +5 -5
  153. package/dist/{chunk-3014rfjz.js → chunk-ewqn51gr.js} +25 -7
  154. package/dist/{chunk-3014rfjz.js.map → chunk-ewqn51gr.js.map} +3 -3
  155. package/dist/{chunk-7z5rkf0m.js → chunk-ey1p8w68.js} +175 -5
  156. package/dist/chunk-ey1p8w68.js.map +13 -0
  157. package/dist/{chunk-z0t4p2sk.js → chunk-fpf57gca.js} +350 -61
  158. package/dist/chunk-fpf57gca.js.map +47 -0
  159. package/dist/{chunk-kv0kvknv.js → chunk-fzae1jpq.js} +7 -7
  160. package/dist/{chunk-b9qfh2ya.js → chunk-fzbhybya.js} +29 -2
  161. package/dist/chunk-fzbhybya.js.map +11 -0
  162. package/dist/{chunk-2by73sm2.js → chunk-gjhrz66x.js} +225 -17
  163. package/dist/{chunk-2by73sm2.js.map → chunk-gjhrz66x.js.map} +5 -5
  164. package/dist/chunk-hn2r7z41.js.map +1 -1
  165. package/dist/{chunk-6gtxshcc.js → chunk-k29n4176.js} +6 -6
  166. package/dist/{chunk-48c1z8nj.js → chunk-k3jh8gsg.js} +10 -2
  167. package/dist/chunk-k3jh8gsg.js.map +10 -0
  168. package/dist/{chunk-w9s23r24.js → chunk-m3qx2pns.js} +751 -93
  169. package/dist/chunk-m3qx2pns.js.map +34 -0
  170. package/dist/{chunk-smnt672s.js → chunk-m9ketb51.js} +20 -4
  171. package/dist/chunk-m9ketb51.js.map +10 -0
  172. package/dist/chunk-mbwsgjn7.js +40 -0
  173. package/dist/chunk-mbwsgjn7.js.map +11 -0
  174. package/dist/{chunk-sysnvjce.js → chunk-naxjka9v.js} +2 -2
  175. package/dist/{chunk-n4zzaf6q.js → chunk-nxysqbt0.js} +4 -2
  176. package/dist/chunk-nxysqbt0.js.map +10 -0
  177. package/dist/{chunk-vzkxqf8h.js → chunk-paxabbqd.js} +49 -5
  178. package/dist/chunk-paxabbqd.js.map +23 -0
  179. package/dist/{chunk-8tqnsx3q.js → chunk-pc7kra3k.js} +5 -3
  180. package/dist/{chunk-8tqnsx3q.js.map → chunk-pc7kra3k.js.map} +3 -3
  181. package/dist/{chunk-qafng88v.js → chunk-pqvvqc65.js} +4 -4
  182. package/dist/chunk-pvpq483h.js.map +2 -2
  183. package/dist/{chunk-mzx71snp.js → chunk-q7g9cqwt.js} +7 -2
  184. package/dist/{chunk-mzx71snp.js.map → chunk-q7g9cqwt.js.map} +3 -3
  185. package/dist/{chunk-8t2ynwg0.js → chunk-q8d9p0tb.js} +24 -1
  186. package/dist/{chunk-8t2ynwg0.js.map → chunk-q8d9p0tb.js.map} +3 -3
  187. package/dist/{chunk-wa05txmk.js → chunk-qavwr628.js} +49 -5
  188. package/dist/chunk-qavwr628.js.map +12 -0
  189. package/dist/{chunk-bkmnd7zq.js → chunk-rg725hry.js} +174 -30
  190. package/dist/{chunk-bkmnd7zq.js.map → chunk-rg725hry.js.map} +9 -8
  191. package/dist/{chunk-8p7bze4c.js → chunk-s1mqyqmm.js} +3 -3
  192. package/dist/{chunk-p351afzm.js → chunk-s5pj68fa.js} +2 -2
  193. package/dist/{chunk-855w9nvw.js → chunk-vehcr9eb.js} +1 -1
  194. package/dist/{chunk-qds484t8.js → chunk-vs2s3p8n.js} +932 -21
  195. package/dist/chunk-vs2s3p8n.js.map +20 -0
  196. package/dist/chunk-vtjzwymr.js.map +2 -2
  197. package/dist/{chunk-n68vz95m.js → chunk-wqe9shx2.js} +1 -1
  198. package/dist/{chunk-0k3r5kb3.js → chunk-xcrnrpfh.js} +1 -1
  199. package/dist/{chunk-cwdzcv37.js → chunk-xrmbhap8.js} +2 -2
  200. package/dist/{chunk-cwdzcv37.js.map → chunk-xrmbhap8.js.map} +2 -2
  201. package/dist/{chunk-f6ahf5gf.js → chunk-xxfj0rr2.js} +20 -5
  202. package/dist/chunk-xxfj0rr2.js.map +13 -0
  203. package/dist/{chunk-3hzhcfsv.js → chunk-y8fwm3z2.js} +2 -2
  204. package/dist/{chunk-3hzhcfsv.js.map → chunk-y8fwm3z2.js.map} +3 -3
  205. package/dist/{chunk-e9w4mgdh.js → chunk-z1njfqqs.js} +589 -53
  206. package/dist/{chunk-e9w4mgdh.js.map → chunk-z1njfqqs.js.map} +14 -11
  207. package/dist/{chunk-yv8hv4wq.js → chunk-z4jqb44a.js} +3 -1
  208. package/dist/chunk-z4jqb44a.js.map +10 -0
  209. package/dist/{chunk-s7xqfxs9.js → chunk-zft9bzbc.js} +2 -1
  210. package/dist/{chunk-s7xqfxs9.js.map → chunk-zft9bzbc.js.map} +3 -3
  211. package/dist/{chunk-38yvdqzd.js → chunk-zxhym8tr.js} +1 -1
  212. package/dist/connectors/connection-handles.d.ts +9 -0
  213. package/dist/connectors/connection-handles.d.ts.map +1 -0
  214. package/dist/connectors/connections/authorizations.d.ts +9 -0
  215. package/dist/connectors/connections/authorizations.d.ts.map +1 -1
  216. package/dist/connectors/connections/events.d.ts +17 -0
  217. package/dist/connectors/connections/events.d.ts.map +1 -0
  218. package/dist/connectors/connections/runs.d.ts +3 -0
  219. package/dist/connectors/connections/runs.d.ts.map +1 -1
  220. package/dist/connectors/connections/service.d.ts +4 -0
  221. package/dist/connectors/connections/service.d.ts.map +1 -1
  222. package/dist/connectors/execution.d.ts +7 -1
  223. package/dist/connectors/execution.d.ts.map +1 -1
  224. package/dist/connectors/index.d.ts +1 -1
  225. package/dist/connectors/index.d.ts.map +1 -1
  226. package/dist/connectors/types.d.ts +22 -1
  227. package/dist/connectors/types.d.ts.map +1 -1
  228. package/dist/datasets/write.js +1 -1
  229. package/dist/deploy/index.d.ts +1 -1
  230. package/dist/deploy/index.d.ts.map +1 -1
  231. package/dist/deploy/internal.js +3 -2
  232. package/dist/deploy/internal.js.map +3 -3
  233. package/dist/deploy/services.d.ts.map +1 -1
  234. package/dist/deploy/types.d.ts +18 -1
  235. package/dist/deploy/types.d.ts.map +1 -1
  236. package/dist/events/definitions.d.ts +4 -0
  237. package/dist/events/definitions.d.ts.map +1 -1
  238. package/dist/events/execution.d.ts.map +1 -1
  239. package/dist/events/index.d.ts +2 -2
  240. package/dist/events/index.d.ts.map +1 -1
  241. package/dist/events/index.js +3 -3
  242. package/dist/events/outbox-dispatcher.d.ts +7 -0
  243. package/dist/events/outbox-dispatcher.d.ts.map +1 -1
  244. package/dist/events/scope.d.ts +1 -0
  245. package/dist/events/scope.d.ts.map +1 -1
  246. package/dist/events/scope.js +1 -1
  247. package/dist/events/selectors/builder.d.ts +9 -1
  248. package/dist/events/selectors/builder.d.ts.map +1 -1
  249. package/dist/events/selectors/index.d.ts +2 -2
  250. package/dist/events/selectors/index.d.ts.map +1 -1
  251. package/dist/events/selectors/index.js +2 -2
  252. package/dist/events/selectors/predicate.d.ts.map +1 -1
  253. package/dist/events/selectors/types.d.ts +18 -3
  254. package/dist/events/selectors/types.d.ts.map +1 -1
  255. package/dist/events/types/artifacts.d.ts +7 -1
  256. package/dist/events/types/artifacts.d.ts.map +1 -1
  257. package/dist/events/types/connectors.d.ts +32 -0
  258. package/dist/events/types/connectors.d.ts.map +1 -0
  259. package/dist/events/types/index.d.ts +3 -1
  260. package/dist/events/types/index.d.ts.map +1 -1
  261. package/dist/execution/agent.js +28 -28
  262. package/dist/execution/authorization.d.ts +5 -0
  263. package/dist/execution/authorization.d.ts.map +1 -1
  264. package/dist/execution/primitive.js +28 -28
  265. package/dist/execution/request.js +29 -29
  266. package/dist/execution/scopes.d.ts +8 -0
  267. package/dist/execution/scopes.d.ts.map +1 -1
  268. package/dist/execution/script.d.ts +7 -0
  269. package/dist/execution/script.d.ts.map +1 -0
  270. package/dist/execution/types.d.ts +16 -1
  271. package/dist/execution/types.d.ts.map +1 -1
  272. package/dist/http/api-routes.d.ts.map +1 -1
  273. package/dist/http/index.js +1 -1
  274. package/dist/index.d.ts +9 -8
  275. package/dist/index.d.ts.map +1 -1
  276. package/dist/index.js +46 -44
  277. package/dist/index.js.map +1 -1
  278. package/dist/lake-storage/index.js +1 -1
  279. package/dist/lineage/executors.d.ts +1 -1
  280. package/dist/lineage/executors.d.ts.map +1 -1
  281. package/dist/maintenance/index.js +1 -1
  282. package/dist/materialization/event-envelopes.d.ts +3 -3
  283. package/dist/materialization/event-envelopes.d.ts.map +1 -1
  284. package/dist/materialization/events.d.ts +6 -0
  285. package/dist/materialization/events.d.ts.map +1 -1
  286. package/dist/materialization/index.js +1 -1
  287. package/dist/materialization/model.d.ts +6 -0
  288. package/dist/materialization/model.d.ts.map +1 -1
  289. package/dist/materializer/index.js +13 -13
  290. package/dist/materializer/projections/replace.d.ts.map +1 -1
  291. package/dist/materializer/projections/replacement-plan.d.ts +2 -0
  292. package/dist/materializer/projections/replacement-plan.d.ts.map +1 -1
  293. package/dist/materializer/shared/normalize.d.ts +1 -0
  294. package/dist/materializer/shared/normalize.d.ts.map +1 -1
  295. package/dist/models/execution/index.js +12 -12
  296. package/dist/models/language-model.d.ts +6 -0
  297. package/dist/models/language-model.d.ts.map +1 -1
  298. package/dist/models/tools.d.ts +2 -0
  299. package/dist/models/tools.d.ts.map +1 -1
  300. package/dist/objects/index.js +28 -28
  301. package/dist/objects/query/index.js +12 -12
  302. package/dist/pipelines/index.js +18 -18
  303. package/dist/projections/builders.d.ts +7 -1
  304. package/dist/projections/builders.d.ts.map +1 -1
  305. package/dist/projections/index.d.ts +1 -1
  306. package/dist/projections/index.d.ts.map +1 -1
  307. package/dist/projections/internal.js +13 -13
  308. package/dist/projections/types.d.ts +10 -0
  309. package/dist/projections/types.d.ts.map +1 -1
  310. package/dist/projections/validation.d.ts.map +1 -1
  311. package/dist/queues/in-memory.d.ts +2 -1
  312. package/dist/queues/in-memory.d.ts.map +1 -1
  313. package/dist/queues/index.d.ts +1 -1
  314. package/dist/queues/index.d.ts.map +1 -1
  315. package/dist/queues/index.js +1 -1
  316. package/dist/queues/types.d.ts +40 -13
  317. package/dist/queues/types.d.ts.map +1 -1
  318. package/dist/runtime/host.d.ts +13 -0
  319. package/dist/runtime/host.d.ts.map +1 -1
  320. package/dist/runtime/internal.d.ts +1 -0
  321. package/dist/runtime/internal.d.ts.map +1 -1
  322. package/dist/runtime/internal.js +39 -18
  323. package/dist/runtime/internal.js.map +4 -3
  324. package/dist/runtime/resolve-definitions.d.ts +1 -1
  325. package/dist/runtime/resolve-definitions.d.ts.map +1 -1
  326. package/dist/runtime/script.d.ts +39 -0
  327. package/dist/runtime/script.d.ts.map +1 -0
  328. package/dist/runtime/sixb.d.ts +2 -2
  329. package/dist/runtime/sixb.d.ts.map +1 -1
  330. package/dist/schedules/builders.d.ts.map +1 -1
  331. package/dist/schedules/index.js +3 -3
  332. package/dist/schedules/runtime.d.ts.map +1 -1
  333. package/dist/schedules/validation.d.ts +2 -0
  334. package/dist/schedules/validation.d.ts.map +1 -1
  335. package/dist/shares/internal.js +12 -12
  336. package/dist/storage/agents/errors.d.ts +1 -1
  337. package/dist/storage/agents/errors.d.ts.map +1 -1
  338. package/dist/storage/agents/in-memory.d.ts +26 -1
  339. package/dist/storage/agents/in-memory.d.ts.map +1 -1
  340. package/dist/storage/agents/index.d.ts +2 -2
  341. package/dist/storage/agents/index.d.ts.map +1 -1
  342. package/dist/storage/agents/provider.d.ts +12 -3
  343. package/dist/storage/agents/provider.d.ts.map +1 -1
  344. package/dist/storage/agents/provider.js +25 -5
  345. package/dist/storage/agents/provider.js.map +1 -1
  346. package/dist/storage/agents/types.d.ts +156 -1
  347. package/dist/storage/agents/types.d.ts.map +1 -1
  348. package/dist/storage/artifacts/in-memory.d.ts +7 -1
  349. package/dist/storage/artifacts/in-memory.d.ts.map +1 -1
  350. package/dist/storage/artifacts/index.d.ts +1 -1
  351. package/dist/storage/artifacts/index.d.ts.map +1 -1
  352. package/dist/storage/artifacts/record.d.ts +2 -1
  353. package/dist/storage/artifacts/record.d.ts.map +1 -1
  354. package/dist/storage/artifacts/types.d.ts +34 -0
  355. package/dist/storage/artifacts/types.d.ts.map +1 -1
  356. package/dist/storage/executions/provider.d.ts +3 -3
  357. package/dist/storage/executions/provider.d.ts.map +1 -1
  358. package/dist/storage/executions/provider.js +1 -1
  359. package/dist/storage/executions/types.d.ts +6 -0
  360. package/dist/storage/executions/types.d.ts.map +1 -1
  361. package/dist/storage/executions/validation.d.ts.map +1 -1
  362. package/dist/storage/file-upload-sessions/provider.js +3 -3
  363. package/dist/storage/index.d.ts +3 -3
  364. package/dist/storage/index.d.ts.map +1 -1
  365. package/dist/storage/index.js +18 -14
  366. package/dist/storage/index.js.map +1 -1
  367. package/dist/storage/internal.d.ts +1 -1
  368. package/dist/storage/internal.d.ts.map +1 -1
  369. package/dist/storage/internal.js +8 -6
  370. package/dist/storage/internal.js.map +2 -2
  371. package/dist/storage/ontology/in-memory/replacement-plans.d.ts +2 -0
  372. package/dist/storage/ontology/in-memory/replacement-plans.d.ts.map +1 -1
  373. package/dist/storage/ontology/provider.js +1 -1
  374. package/dist/storage/ontology/replacement-plans.d.ts +8 -0
  375. package/dist/storage/ontology/replacement-plans.d.ts.map +1 -1
  376. package/dist/storage/operation-scope.d.ts.map +1 -1
  377. package/dist/storage/operation-scope.js +1 -1
  378. package/dist/storage/workflow-runs/provider.js +3 -3
  379. package/dist/syncs/index.js +19 -19
  380. package/dist/testing/agent-execution.d.ts +3 -0
  381. package/dist/testing/agent-execution.d.ts.map +1 -1
  382. package/dist/testing/agent-inbox-storage-contract.d.ts +15 -0
  383. package/dist/testing/agent-inbox-storage-contract.d.ts.map +1 -0
  384. package/dist/testing/agent-storage-contract.d.ts.map +1 -1
  385. package/dist/testing/artifact-storage-contract.d.ts.map +1 -1
  386. package/dist/testing/execution-storage-contract.d.ts.map +1 -1
  387. package/dist/testing/index.d.ts +1 -0
  388. package/dist/testing/index.d.ts.map +1 -1
  389. package/dist/testing/index.js +5524 -4555
  390. package/dist/testing/index.js.map +10 -9
  391. package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
  392. package/dist/testing/queues-contract.d.ts.map +1 -1
  393. package/dist/webhooks/connections.d.ts +3 -4
  394. package/dist/webhooks/connections.d.ts.map +1 -1
  395. package/dist/webhooks/index.d.ts +1 -1
  396. package/dist/webhooks/index.d.ts.map +1 -1
  397. package/dist/webhooks/internal.js +16 -49
  398. package/dist/webhooks/internal.js.map +3 -3
  399. package/dist/webhooks/types.d.ts +2 -11
  400. package/dist/webhooks/types.d.ts.map +1 -1
  401. package/dist/workers/queued-run-dispatch.d.ts.map +1 -1
  402. package/dist/workflows/index.js +35 -35
  403. package/package.json +6 -1
  404. package/src/agents/README.md +6 -2
  405. package/src/agents/approval-outcome.ts +2 -2
  406. package/src/agents/cancel.ts +2 -2
  407. package/src/agents/child-question.ts +76 -8
  408. package/src/agents/execution.ts +168 -30
  409. package/src/agents/ids.ts +9 -1
  410. package/src/agents/index.ts +27 -6
  411. package/src/agents/model-loop.ts +3 -1
  412. package/src/agents/queued-turn.ts +46 -0
  413. package/src/agents/request.ts +517 -2
  414. package/src/agents/run-after-finish.ts +259 -2
  415. package/src/agents/run-artifacts.ts +3 -93
  416. package/src/agents/run-events.ts +26 -1
  417. package/src/agents/run-session-children.ts +33 -0
  418. package/src/agents/run-session-http.ts +10 -2
  419. package/src/agents/run-session-serve.ts +3 -8
  420. package/src/agents/run-session.ts +142 -3
  421. package/src/agents/run-turn.ts +8 -0
  422. package/src/agents/streams/index.ts +1 -0
  423. package/src/agents/streams/protocol.ts +41 -1
  424. package/src/agents/tool-files.ts +1 -1
  425. package/src/agents/tool-input-coercion.ts +140 -0
  426. package/src/agents/turn-answered.ts +31 -0
  427. package/src/agents/validation.ts +13 -3
  428. package/src/artifacts/canvas-display.ts +4 -6
  429. package/src/artifacts/comments.ts +70 -17
  430. package/src/artifacts/document-fill.ts +103 -0
  431. package/src/artifacts/errors.ts +2 -0
  432. package/src/artifacts/events.ts +4 -1
  433. package/src/artifacts/execution.ts +265 -31
  434. package/src/artifacts/frames/assets.ts +42 -7
  435. package/src/artifacts/frames/document-data.ts +353 -0
  436. package/src/artifacts/frames/entries.ts +22 -16
  437. package/src/artifacts/frames/grants.ts +2 -2
  438. package/src/artifacts/frames/index.ts +3 -0
  439. package/src/artifacts/frames/kit.ts +102 -0
  440. package/src/artifacts/frames/protocol.ts +96 -3
  441. package/src/artifacts/frames/runtime.ts +709 -19
  442. package/src/artifacts/index.ts +6 -0
  443. package/src/artifacts/live/blocks.ts +889 -0
  444. package/src/artifacts/live/board.ts +195 -42
  445. package/src/artifacts/live/document.ts +170 -5
  446. package/src/artifacts/live/index.ts +7 -0
  447. package/src/artifacts/live/page.ts +807 -0
  448. package/src/artifacts/live/protocol.ts +5 -0
  449. package/src/artifacts/live/server.ts +2 -2
  450. package/src/artifacts/live/state.ts +9 -4
  451. package/src/artifacts/outline.ts +17 -0
  452. package/src/artifacts/paper.ts +173 -0
  453. package/src/artifacts/pdf-job.ts +11 -0
  454. package/src/artifacts/publish/fields.ts +177 -0
  455. package/src/artifacts/publish/index.ts +6 -1
  456. package/src/artifacts/publish/merge.ts +14 -12
  457. package/src/artifacts/publish/pdf.ts +82 -0
  458. package/src/artifacts/publish/previews.ts +24 -34
  459. package/src/artifacts/publish/publish.ts +26 -3
  460. package/src/artifacts/publish/queries.ts +20 -4
  461. package/src/artifacts/publish/query-answers.ts +14 -3
  462. package/src/artifacts/publish/validate/document-html.ts +245 -0
  463. package/src/artifacts/publish/validate/document.ts +34 -3
  464. package/src/artifacts/queries.ts +59 -13
  465. package/src/authorization/event-visibility.ts +13 -0
  466. package/src/connectors/connection-handles.ts +71 -0
  467. package/src/connectors/connections/authorizations.ts +50 -2
  468. package/src/connectors/connections/events.ts +57 -0
  469. package/src/connectors/connections/runs.ts +5 -0
  470. package/src/connectors/connections/service.ts +19 -1
  471. package/src/connectors/execution.ts +30 -2
  472. package/src/connectors/index.ts +3 -0
  473. package/src/connectors/types.ts +29 -1
  474. package/src/deploy/index.ts +1 -0
  475. package/src/deploy/services.ts +1 -0
  476. package/src/deploy/types.ts +26 -1
  477. package/src/events/definitions.ts +14 -0
  478. package/src/events/execution.ts +9 -2
  479. package/src/events/index.ts +8 -0
  480. package/src/events/outbox-dispatcher.ts +12 -2
  481. package/src/events/scope.ts +3 -0
  482. package/src/events/selectors/builder.ts +49 -0
  483. package/src/events/selectors/index.ts +5 -0
  484. package/src/events/selectors/predicate.ts +2 -0
  485. package/src/events/selectors/types.ts +30 -1
  486. package/src/events/types/artifacts.ts +7 -1
  487. package/src/events/types/connectors.ts +36 -0
  488. package/src/events/types/index.ts +7 -0
  489. package/src/execution/authorization.ts +45 -0
  490. package/src/execution/durable.ts +2 -0
  491. package/src/execution/scopes.ts +24 -0
  492. package/src/execution/script.ts +27 -0
  493. package/src/execution/types.ts +7 -1
  494. package/src/http/api-routes.ts +26 -1
  495. package/src/index.ts +21 -2
  496. package/src/lineage/executors.ts +3 -1
  497. package/src/materialization/event-envelopes.ts +10 -5
  498. package/src/materialization/events.ts +2 -0
  499. package/src/materialization/model.ts +6 -0
  500. package/src/materializer/README.md +10 -0
  501. package/src/materializer/projections/replace.ts +42 -1
  502. package/src/materializer/projections/replacement-plan.ts +44 -4
  503. package/src/materializer/shared/normalize.ts +4 -0
  504. package/src/models/language-model.ts +6 -0
  505. package/src/models/tools.ts +2 -0
  506. package/src/projections/builders.ts +20 -0
  507. package/src/projections/index.ts +1 -0
  508. package/src/projections/registry.ts +1 -0
  509. package/src/projections/revision.ts +2 -0
  510. package/src/projections/types.ts +11 -0
  511. package/src/projections/validation.ts +6 -0
  512. package/src/queues/in-memory.ts +5 -0
  513. package/src/queues/index.ts +3 -1
  514. package/src/queues/types.ts +45 -14
  515. package/src/runtime/host.ts +112 -4
  516. package/src/runtime/internal.ts +1 -0
  517. package/src/runtime/resolve-definitions.ts +4 -1
  518. package/src/runtime/script.ts +62 -0
  519. package/src/runtime/sixb.ts +3 -3
  520. package/src/schedules/builders.ts +4 -1
  521. package/src/schedules/runtime.ts +3 -0
  522. package/src/schedules/validation.ts +20 -2
  523. package/src/storage/agents/errors.ts +1 -0
  524. package/src/storage/agents/in-memory.ts +229 -1
  525. package/src/storage/agents/index.ts +16 -0
  526. package/src/storage/agents/provider.ts +284 -2
  527. package/src/storage/agents/types.ts +168 -1
  528. package/src/storage/artifacts/in-memory.ts +32 -1
  529. package/src/storage/artifacts/index.ts +2 -0
  530. package/src/storage/artifacts/record.ts +25 -2
  531. package/src/storage/artifacts/types.ts +37 -0
  532. package/src/storage/executions/provider.ts +22 -2
  533. package/src/storage/executions/types.ts +2 -0
  534. package/src/storage/executions/validation.ts +27 -0
  535. package/src/storage/index.ts +18 -0
  536. package/src/storage/internal.ts +1 -0
  537. package/src/storage/ontology/in-memory/replacement-plans.ts +22 -0
  538. package/src/storage/ontology/replacement-plans.ts +6 -0
  539. package/src/storage/operation-scope.ts +1 -0
  540. package/src/testing/agent-execution.ts +45 -2
  541. package/src/testing/agent-inbox-storage-contract.ts +815 -0
  542. package/src/testing/agent-storage-contract.ts +103 -0
  543. package/src/testing/artifact-storage-contract.ts +72 -4
  544. package/src/testing/execution-storage-contract.ts +31 -0
  545. package/src/testing/index.ts +5 -0
  546. package/src/testing/materializer-storage-contract.ts +139 -1
  547. package/src/testing/queues-contract.ts +22 -0
  548. package/src/webhooks/connections.ts +9 -50
  549. package/src/webhooks/index.ts +0 -2
  550. package/src/webhooks/types.ts +2 -13
  551. package/src/workers/queued-run-dispatch.ts +8 -1
  552. package/dist/chunk-48c1z8nj.js.map +0 -10
  553. package/dist/chunk-58geavnf.js +0 -29
  554. package/dist/chunk-58geavnf.js.map +0 -10
  555. package/dist/chunk-7z5rkf0m.js.map +0 -13
  556. package/dist/chunk-9nsjjd44.js.map +0 -12
  557. package/dist/chunk-b9qfh2ya.js.map +0 -11
  558. package/dist/chunk-eptrvnby.js.map +0 -12
  559. package/dist/chunk-f6ahf5gf.js.map +0 -13
  560. package/dist/chunk-m2jerfef.js +0 -474
  561. package/dist/chunk-m2jerfef.js.map +0 -11
  562. package/dist/chunk-n4zzaf6q.js.map +0 -10
  563. package/dist/chunk-qds484t8.js.map +0 -18
  564. package/dist/chunk-smnt672s.js.map +0 -10
  565. package/dist/chunk-vzkxqf8h.js.map +0 -23
  566. package/dist/chunk-w9s23r24.js.map +0 -30
  567. package/dist/chunk-wa05txmk.js.map +0 -11
  568. package/dist/chunk-yv8hv4wq.js.map +0 -10
  569. package/dist/chunk-z0t4p2sk.js.map +0 -47
  570. /package/dist/{chunk-tqa68kj7.js.map → chunk-0hkdtwqk.js.map} +0 -0
  571. /package/dist/{chunk-s5n9617r.js.map → chunk-0mvjpgvm.js.map} +0 -0
  572. /package/dist/{chunk-k66rp2hr.js.map → chunk-1yh6jgtz.js.map} +0 -0
  573. /package/dist/{chunk-26qet7wh.js.map → chunk-5t9gm5tt.js.map} +0 -0
  574. /package/dist/{chunk-e0hnbb1m.js.map → chunk-61zptves.js.map} +0 -0
  575. /package/dist/{chunk-hkaa807g.js.map → chunk-68hm50qh.js.map} +0 -0
  576. /package/dist/{chunk-fe6r7yhg.js.map → chunk-92wrka15.js.map} +0 -0
  577. /package/dist/{chunk-m7b9q5dk.js.map → chunk-aw1z0gre.js.map} +0 -0
  578. /package/dist/{chunk-kv0kvknv.js.map → chunk-fzae1jpq.js.map} +0 -0
  579. /package/dist/{chunk-6gtxshcc.js.map → chunk-k29n4176.js.map} +0 -0
  580. /package/dist/{chunk-sysnvjce.js.map → chunk-naxjka9v.js.map} +0 -0
  581. /package/dist/{chunk-qafng88v.js.map → chunk-pqvvqc65.js.map} +0 -0
  582. /package/dist/{chunk-8p7bze4c.js.map → chunk-s1mqyqmm.js.map} +0 -0
  583. /package/dist/{chunk-p351afzm.js.map → chunk-s5pj68fa.js.map} +0 -0
  584. /package/dist/{chunk-855w9nvw.js.map → chunk-vehcr9eb.js.map} +0 -0
  585. /package/dist/{chunk-n68vz95m.js.map → chunk-wqe9shx2.js.map} +0 -0
  586. /package/dist/{chunk-0k3r5kb3.js.map → chunk-xcrnrpfh.js.map} +0 -0
  587. /package/dist/{chunk-38yvdqzd.js.map → chunk-zxhym8tr.js.map} +0 -0
@@ -4,12 +4,12 @@ import {
4
4
  validateObjectQueryWithAdmission,
5
5
  SYSTEM_PRINCIPAL2,
6
6
  principalsEqual2
7
- } from "./chunk-0k3r5kb3.js";
7
+ } from "./chunk-xcrnrpfh.js";
8
8
  import {
9
9
  resolveRuntimeAuthorizationForProject,
10
10
  AuthorizationError2,
11
11
  isRuntimeAllowed2
12
- } from "./chunk-vzkxqf8h.js";
12
+ } from "./chunk-paxabbqd.js";
13
13
  import {
14
14
  createArtifactId,
15
15
  createArtifactCommentId
@@ -24,21 +24,42 @@ import {
24
24
  import {
25
25
  ArtifactStorageError,
26
26
  turnUndoable2
27
- } from "./chunk-3014rfjz.js";
27
+ } from "./chunk-ewqn51gr.js";
28
28
  import {
29
29
  ARTIFACT_LIMITS2,
30
30
  ARTIFACT_STATE_LIMITS2,
31
31
  ARTIFACT_HOLDERS_LIMIT2,
32
32
  ARTIFACT_COMMENT_LIMITS2
33
33
  } from "./chunk-9vsc919v.js";
34
+ import {
35
+ computeBlobDigest2
36
+ } from "./chunk-xrmbhap8.js";
34
37
  import {
35
38
  objectBatchKey2
36
- } from "./chunk-2by73sm2.js";
39
+ } from "./chunk-gjhrz66x.js";
37
40
  import {
38
41
  objectReadersIn,
39
42
  getAuthorizedOntologyView,
40
43
  readerClearance
41
- } from "./chunk-26qet7wh.js";
44
+ } from "./chunk-5t9gm5tt.js";
45
+ import {
46
+ ArtifactRequestError2,
47
+ documentData,
48
+ documentMarks,
49
+ fillDocumentHtml,
50
+ frozenDocumentHtml2,
51
+ checkArtifactFiles,
52
+ readArtifactText,
53
+ invalidArtifact,
54
+ decodeHtmlEntities,
55
+ HTML_ENTRY2,
56
+ refuseFrameAssetPaths,
57
+ readHtmlReferences,
58
+ FRAME_DEFAULT_THEMES2,
59
+ FRAME_CDN_ALLOWLIST2,
60
+ FRAME_ASSETS2,
61
+ serializeArtifactQueryResult2
62
+ } from "./chunk-vs2s3p8n.js";
42
63
  import {
43
64
  isArtifactAddress2,
44
65
  parseArtifactAddress2,
@@ -49,8 +70,9 @@ import {
49
70
  isLiveTextPath,
50
71
  createArtifactDocument,
51
72
  documentFiles2,
52
- mergeIntoDocument2
53
- } from "./chunk-m2jerfef.js";
73
+ mergeIntoDocument2,
74
+ holdPage
75
+ } from "./chunk-bqr703h4.js";
54
76
  import {
55
77
  BOARD_PREVIEW_JOB2,
56
78
  BOARD_PREVIEW_WAIT_MS2,
@@ -59,15 +81,16 @@ import {
59
81
  canvasEndBox,
60
82
  ARTIFACT_QUERIES_DIRECTORY,
61
83
  ARTIFACT_QUERY_KINDS,
84
+ DOCUMENT_HOLDER_QUERY2,
62
85
  isArtifactQueryName,
63
86
  artifactQueryPath,
64
87
  artifactQueryName2,
65
88
  parseArtifactQuery,
89
+ createHeadingSlugger2,
66
90
  ARTIFACT_THEME_FILE2,
67
91
  parseArtifactTheme2,
68
92
  artifactThemeModes2,
69
93
  resolveArtifactAddress2,
70
- createHeadingSlugger2,
71
94
  CsvParseError2,
72
95
  parseCsv2,
73
96
  WORKBOOK_FILE2,
@@ -80,20 +103,7 @@ import {
80
103
  sheetColumnsProblem,
81
104
  sheetFormulasProblem,
82
105
  sheetChartsProblem
83
- } from "./chunk-a6fjkcne.js";
84
- import {
85
- ArtifactRequestError2,
86
- checkArtifactFiles,
87
- readArtifactText,
88
- invalidArtifact,
89
- decodeHtmlEntities,
90
- HTML_ENTRY2,
91
- refuseFrameAssetPaths,
92
- readHtmlReferences,
93
- FRAME_DEFAULT_THEMES2,
94
- FRAME_ASSETS2,
95
- serializeArtifactQueryResult2
96
- } from "./chunk-qds484t8.js";
106
+ } from "./chunk-60662fyv.js";
97
107
  import {
98
108
  ObjectQueryValidationError2,
99
109
  ObjectQueryPlanningError2,
@@ -103,9 +113,6 @@ import {
103
113
  import {
104
114
  AgentRequestError2
105
115
  } from "./chunk-9wr3yajk.js";
106
- import {
107
- statFileRef2
108
- } from "./chunk-a3faa34j.js";
109
116
 
110
117
  // src/agents/thread-access.ts
111
118
  function createAgentThreadAccessRule(runtime, authority, agents) {
@@ -251,7 +258,7 @@ async function announceArtifactUpdates(events, latest) {
251
258
  }))
252
259
  }, { source: "Sixb" });
253
260
  }
254
- async function announceArtifactComment(events, comment, action) {
261
+ async function announceArtifactComment(events, comment, shareGrantId, action) {
255
262
  await events.emit({
256
263
  events: [
257
264
  {
@@ -260,6 +267,7 @@ async function announceArtifactComment(events, comment, action) {
260
267
  artifactId: comment.artifactId,
261
268
  commentId: comment.id,
262
269
  ...comment.parentId === undefined ? {} : { parentId: comment.parentId },
270
+ ...shareGrantId === undefined ? {} : { shareGrantId },
263
271
  action
264
272
  }
265
273
  }
@@ -271,7 +279,9 @@ async function announceArtifactComment(events, comment, action) {
271
279
  var ELEMENT_ADDRESS = /^body(>[a-z][a-z0-9-]*:\d+)*$/;
272
280
  var MAX_ELEMENT_ADDRESS_LENGTH = 1024;
273
281
  function createArtifactCommentsRuntime(input) {
274
- const { projectId, events } = input;
282
+ const { projectId, events, guest } = input;
283
+ const threadOf = (comment) => comment.parentId === undefined ? Promise.resolve(comment) : input.storage().getComment({ projectId, artifactId: comment.artifactId, id: comment.parentId });
284
+ const reads = (thread) => thread !== null && (!guest || guest.grantId !== undefined && threadLink(thread) === guest.grantId);
275
285
  const readable = async (artifactId) => {
276
286
  const reached = await input.reach(artifactId);
277
287
  if (!reached)
@@ -283,23 +293,28 @@ function createArtifactCommentsRuntime(input) {
283
293
  };
284
294
  const managed = async (artifactId, commentId) => {
285
295
  const { access } = await readable(artifactId);
286
- const manager = input.manager();
287
296
  const comment = await input.storage().getComment({ projectId, artifactId, id: commentId });
288
- if (!comment)
297
+ const thread = comment ? await threadOf(comment) : null;
298
+ if (!comment || !reads(thread))
289
299
  throw commentNotFound(artifactId, commentId);
300
+ const manager = input.manager();
290
301
  const changes = access === "owner" || access === "update";
291
302
  const authored = comment.author.type !== "guest" && principalsEqual2(comment.author, manager);
292
303
  if (!changes && !authored) {
293
304
  throw new ArtifactRequestError2("not_allowed", "[Sixb] Only a comment's author, or whoever may change the artifact, resolves or deletes it.");
294
305
  }
295
- return comment;
306
+ return { comment, thread };
296
307
  };
297
308
  return {
298
309
  async listComments(artifactId) {
299
310
  const reached = await input.reach(artifactId);
300
311
  if (!reached || reached.access === "none")
301
312
  return null;
302
- return input.storage().listComments({ projectId, id: artifactId });
313
+ const comments = await input.storage().listComments({ projectId, id: artifactId });
314
+ if (!guest)
315
+ return comments;
316
+ const threads = new Set(comments.filter((comment) => comment.parentId === undefined && reads(comment)).map((comment) => comment.id));
317
+ return comments.filter((comment) => threads.has(comment.parentId ?? comment.id));
303
318
  },
304
319
  async addComment(artifactId, comment) {
305
320
  const { artifact } = await readable(artifactId);
@@ -310,9 +325,10 @@ function createArtifactCommentsRuntime(input) {
310
325
  throw invalid(`A comment holds 1 to ${ARTIFACT_COMMENT_LIMITS2.maxBodyLength} characters of text.`);
311
326
  }
312
327
  let anchor;
328
+ let parent = null;
313
329
  if (comment.parentId !== undefined) {
314
- const parent = await storage.getComment({ projectId, artifactId, id: comment.parentId });
315
- if (!parent)
330
+ parent = await storage.getComment({ projectId, artifactId, id: comment.parentId });
331
+ if (!reads(parent))
316
332
  throw commentNotFound(artifactId, comment.parentId);
317
333
  anchor = parent.anchor;
318
334
  } else {
@@ -330,14 +346,14 @@ function createArtifactCommentsRuntime(input) {
330
346
  ...comment.origin ? { origin: comment.origin } : {},
331
347
  createdAt: new Date
332
348
  });
333
- await announceArtifactComment(events, created, "created");
349
+ await announceArtifactComment(events, created, threadLink(parent ?? created), "created");
334
350
  return created;
335
351
  } catch (error) {
336
352
  throw commentRequestError(error);
337
353
  }
338
354
  },
339
355
  async resolveComment(artifactId, commentId, resolved = true) {
340
- await managed(artifactId, commentId);
356
+ const { thread } = await managed(artifactId, commentId);
341
357
  const changed = await input.storage().resolveComment({
342
358
  projectId,
343
359
  artifactId,
@@ -346,18 +362,21 @@ function createArtifactCommentsRuntime(input) {
346
362
  });
347
363
  if (!changed)
348
364
  throw commentNotFound(artifactId, commentId);
349
- await announceArtifactComment(events, changed, resolved ? "resolved" : "reopened");
365
+ await announceArtifactComment(events, changed, threadLink(thread), resolved ? "resolved" : "reopened");
350
366
  return changed;
351
367
  },
352
368
  async deleteComment(artifactId, commentId) {
353
- const comment = await managed(artifactId, commentId);
369
+ const { comment, thread } = await managed(artifactId, commentId);
354
370
  const deleted = await input.storage().deleteComment({ projectId, artifactId, id: commentId });
355
371
  if (!deleted)
356
372
  throw commentNotFound(artifactId, commentId);
357
- await announceArtifactComment(events, comment, "deleted");
373
+ await announceArtifactComment(events, comment, threadLink(thread), "deleted");
358
374
  }
359
375
  };
360
376
  }
377
+ function threadLink(thread) {
378
+ return thread.author.type === "guest" ? thread.author.grantId : undefined;
379
+ }
361
380
  async function checkAnchor(storage, artifact, anchor) {
362
381
  const revision = anchor.revision ?? artifact.revision;
363
382
  if (!Number.isSafeInteger(revision) || revision < 1 || revision > artifact.revision) {
@@ -524,17 +543,18 @@ function sameArtifactFiles2(left, right) {
524
543
  }
525
544
 
526
545
  // src/artifacts/live/state.ts
527
- function keepsDocument(kind) {
528
- return kind === "canvas";
546
+ function keepsDocument2(kind) {
547
+ return kind === "canvas" || kind === "document";
529
548
  }
530
549
  async function loadArtifactDocument2(blobStorage, artifact, files) {
531
550
  const doc = new Y.Doc;
532
551
  const stored = artifact.document;
552
+ const clientID = madeClientId(artifact.id, stored, files);
533
553
  if (stored?.revision === artifact.revision) {
534
554
  Y.applyUpdate(doc, await readDocumentState2(blobStorage, stored.file));
555
+ holdPage(doc, clientID);
535
556
  return doc;
536
557
  }
537
- const clientID = madeClientId(artifact.id, stored, files);
538
558
  const live = await readLiveFiles2(blobStorage, files);
539
559
  let made;
540
560
  if (stored) {
@@ -547,6 +567,7 @@ async function loadArtifactDocument2(blobStorage, artifact, files) {
547
567
  }
548
568
  Y.applyUpdate(doc, Y.encodeStateAsUpdate(made));
549
569
  made.destroy();
570
+ holdPage(doc, clientID);
550
571
  return doc;
551
572
  }
552
573
  async function readDocumentState2(blobStorage, document) {
@@ -562,7 +583,7 @@ async function storeArtifactDocument(blobStorage, doc) {
562
583
  });
563
584
  }
564
585
  async function firstArtifactDocument(blobStorage, kind, files) {
565
- if (!keepsDocument(kind))
586
+ if (!keepsDocument2(kind))
566
587
  return;
567
588
  const doc = createArtifactDocument(kind, await readLiveFiles2(blobStorage, files));
568
589
  try {
@@ -591,7 +612,7 @@ async function mergeArtifactWrite(context, write) {
591
612
  ...write.baseRevision === undefined ? {} : { baseRevision: write.baseRevision },
592
613
  merged: false
593
614
  };
594
- if (!keepsDocument(write.kind))
615
+ if (!keepsDocument2(write.kind))
595
616
  return unmerged;
596
617
  const { projectId, storage, blobStorage } = context;
597
618
  const artifact = await storage.get({ projectId, id: write.artifactId });
@@ -637,15 +658,16 @@ async function withMergedWrite(context, write, store) {
637
658
  try {
638
659
  return await store(merged);
639
660
  } catch (error) {
640
- if (!isMoved(error) || !keepsDocument(write.kind) || attempt === MERGE_ATTEMPTS)
661
+ if (!isMoved(error) || !keepsDocument2(write.kind) || attempt === MERGE_ATTEMPTS) {
641
662
  throw error;
663
+ }
642
664
  }
643
665
  }
644
666
  }
645
667
  async function documentHolding(context, artifactId, files) {
646
668
  const { projectId, storage, blobStorage } = context;
647
669
  const artifact = await storage.get({ projectId, id: artifactId });
648
- if (!artifact || !keepsDocument(artifact.kind))
670
+ if (!artifact || !keepsDocument2(artifact.kind))
649
671
  return null;
650
672
  const latest = await storage.getVersion({
651
673
  projectId,
@@ -689,7 +711,7 @@ async function undoneTurnDocuments(context, turnRunId) {
689
711
  if (write.created)
690
712
  continue;
691
713
  const artifact = await storage.get({ projectId, id: write.artifactId });
692
- if (!artifact || !keepsDocument(artifact.kind))
714
+ if (!artifact || !keepsDocument2(artifact.kind))
693
715
  continue;
694
716
  const points = await storage.listRestorePoints({ projectId, id: artifact.id });
695
717
  const point = points.find((each) => each.turnRunId === turnRunId);
@@ -700,7 +722,7 @@ async function undoneTurnDocuments(context, turnRunId) {
700
722
  ...point ? { point } : {},
701
723
  ...target ? { target: { frozen: target.frozenAt !== undefined } } : {}
702
724
  });
703
- if (!point || !undoable)
725
+ if (!point || !undoable || !keepsDocument2(artifact.kind))
704
726
  continue;
705
727
  const held = await documentHolding(context, artifact.id, point.files);
706
728
  if (held?.baseRevision === artifact.revision)
@@ -719,6 +741,9 @@ async function filesAtRevision(storage, projectId, artifactId, revision) {
719
741
  return versions.find((version) => version.revision === revision)?.files ?? null;
720
742
  }
721
743
 
744
+ // src/artifacts/publish/pdf.ts
745
+ import { createHash as createHash3 } from "crypto";
746
+
722
747
  // src/artifacts/publish/previews.ts
723
748
  import { createHash as createHash2 } from "crypto";
724
749
 
@@ -742,6 +767,9 @@ async function answerArtifactQueries2(version, read) {
742
767
  const name = artifactQueryName2(file.path);
743
768
  return name === undefined ? [] : [name];
744
769
  });
770
+ if (version.outline.kind === "document" && version.outline.holder) {
771
+ names.push(DOCUMENT_HOLDER_QUERY2);
772
+ }
745
773
  const answers = await Promise.all(names.map(async (name) => [name, await answerArtifactQuery(() => read(name))]));
746
774
  return Object.fromEntries(answers);
747
775
  }
@@ -897,13 +925,13 @@ async function boardPreviewStatuses2(storage, version, input) {
897
925
  return [board.id, ready ? "ready" : waiting ? "pending" : "none"];
898
926
  }));
899
927
  }
900
- async function storeBoardPreviews2(context, version, previews) {
928
+ async function storeBoardPreviews2(storage, version, previews) {
901
929
  if (previews.length === 0)
902
930
  return [];
903
931
  const { boards, themes } = previewedBoards(version);
904
932
  const keys = new Map(boards.map((board) => [board.id, board.renderKey]));
905
933
  const createdAt = new Date;
906
- const checked = await Promise.all(previews.map(async (preview) => {
934
+ const checked = previews.map((preview) => {
907
935
  const { board, theme, size, file } = preview;
908
936
  const refuse = (reason) => ({ refused: { board, theme, size, reason } });
909
937
  const renderKey = keys.get(board);
@@ -917,13 +945,11 @@ async function storeBoardPreviews2(context, version, previews) {
917
945
  if (file.sizeBytes > MAX_BOARD_PREVIEW_BYTES2) {
918
946
  return refuse(`it is ${file.sizeBytes} bytes, past the ${MAX_BOARD_PREVIEW_BYTES2} kept`);
919
947
  }
920
- if (!await statFileRef2(context.blobStorage, file))
921
- return refuse("it is not stored");
922
948
  return { record: { renderKey, theme, size, file: { ...file }, createdAt } };
923
- }));
949
+ });
924
950
  const records = checked.flatMap((each) => ("record" in each) ? [each.record] : []);
925
951
  if (records.length > 0) {
926
- await context.storage.putBoardPreviews({ projectId: version.projectId, previews: records });
952
+ await storage.putBoardPreviews({ projectId: version.projectId, previews: records });
927
953
  }
928
954
  return checked.flatMap((each) => ("refused" in each) ? [each.refused] : []);
929
955
  }
@@ -937,21 +963,20 @@ async function requestBoardPreviews(input, version, options = {}) {
937
963
  if ((await missingBoardPreviews2(input.storage, version)).length === 0)
938
964
  return;
939
965
  const queries = boardsReadLiveData2(version) && !options.withoutAnswers ? await storeQueryAnswers(input, version) : undefined;
940
- const delayMs = options.delayMs ?? BOARD_PREVIEW_JOB2.settleMs;
941
966
  await input.queue.enqueue({
942
967
  projectId: version.projectId,
943
968
  jobs: [
944
969
  {
945
970
  id: boardPreviewsJobId(version.artifactId),
946
971
  replace: true,
947
- type: "agent.artifact-previews.requested",
972
+ type: "artifact.previews.requested",
948
973
  payload: {
949
974
  artifactId: version.artifactId,
950
975
  version: version.version,
951
976
  updatedAt: version.updatedAt.toISOString(),
952
977
  ...queries ? { queries } : {}
953
978
  },
954
- availableAt: new Date(Date.now() + delayMs).toISOString()
979
+ availableAt: new Date(Date.now() + BOARD_PREVIEW_JOB2.settleMs).toISOString()
955
980
  }
956
981
  ]
957
982
  });
@@ -975,6 +1000,484 @@ function frameKitDigest() {
975
1000
  return kitDigest;
976
1001
  }
977
1002
 
1003
+ // src/artifacts/publish/validate/document-html.ts
1004
+ import { posix as posix2 } from "path";
1005
+
1006
+ // src/artifacts/paper.ts
1007
+ var PX_PER_UNIT = {
1008
+ px: 1,
1009
+ in: 96,
1010
+ cm: 96 / 2.54,
1011
+ mm: 96 / 25.4,
1012
+ q: 96 / 101.6,
1013
+ pt: 96 / 72,
1014
+ pc: 16
1015
+ };
1016
+ var PAGE_SIZES = {
1017
+ a5: ["148mm", "210mm"],
1018
+ a4: ["210mm", "297mm"],
1019
+ a3: ["297mm", "420mm"],
1020
+ b5: ["176mm", "250mm"],
1021
+ b4: ["250mm", "353mm"],
1022
+ "jis-b5": ["182mm", "257mm"],
1023
+ "jis-b4": ["257mm", "364mm"],
1024
+ letter: ["8.5in", "11in"],
1025
+ legal: ["8.5in", "14in"],
1026
+ ledger: ["11in", "17in"]
1027
+ };
1028
+ function readDocumentPaper(stylesheets) {
1029
+ let size = null;
1030
+ const margin = [0, 0, 0, 0];
1031
+ for (const css of stylesheets) {
1032
+ for (const declarations of pageRules(css)) {
1033
+ for (const [property, value] of declarations) {
1034
+ if (property === "size") {
1035
+ size = readSize(value) ?? size;
1036
+ } else if (property === "margin") {
1037
+ const sides = readLengths(value);
1038
+ if (sides && sides.length <= 4) {
1039
+ const [top, right = top, bottom = top, left = right] = sides;
1040
+ margin.splice(0, 4, top, right, bottom, left);
1041
+ }
1042
+ } else {
1043
+ const side = ["margin-top", "margin-right", "margin-bottom", "margin-left"].indexOf(property);
1044
+ const length = side === -1 ? null : readLength(value);
1045
+ if (length !== null)
1046
+ margin[side] = length;
1047
+ }
1048
+ }
1049
+ }
1050
+ }
1051
+ if (!size)
1052
+ return null;
1053
+ const round = (value) => Math.round(value * 100) / 100;
1054
+ return {
1055
+ width: round(size[0]),
1056
+ height: round(size[1]),
1057
+ margin: {
1058
+ top: round(margin[0]),
1059
+ right: round(margin[1]),
1060
+ bottom: round(margin[2]),
1061
+ left: round(margin[3])
1062
+ }
1063
+ };
1064
+ }
1065
+ function pageRules(css) {
1066
+ const text = css.replace(/\/\*[\s\S]*?\*\//g, "");
1067
+ const rules = [];
1068
+ const opening = /@page\b([^{;]*)\{/gi;
1069
+ for (let match = opening.exec(text);match; match = opening.exec(text)) {
1070
+ const body = blockAt(text, opening.lastIndex);
1071
+ opening.lastIndex += body.length;
1072
+ if (match[1]?.trim())
1073
+ continue;
1074
+ let flat = "";
1075
+ let depth = 0;
1076
+ for (const char of body) {
1077
+ if (char === "{")
1078
+ depth += 1;
1079
+ else if (char === "}")
1080
+ depth -= 1;
1081
+ else if (depth === 0)
1082
+ flat += char;
1083
+ }
1084
+ rules.push(flat.split(";").flatMap((declaration) => {
1085
+ const colon = declaration.indexOf(":");
1086
+ if (colon === -1)
1087
+ return [];
1088
+ const property = declaration.slice(0, colon).trim().toLowerCase();
1089
+ const value = declaration.slice(colon + 1).replace(/!important\s*$/i, "").trim().toLowerCase();
1090
+ return property && value ? [[property, value]] : [];
1091
+ }));
1092
+ }
1093
+ return rules;
1094
+ }
1095
+ function blockAt(text, start) {
1096
+ let depth = 1;
1097
+ for (let index = start;index < text.length; index++) {
1098
+ if (text[index] === "{")
1099
+ depth += 1;
1100
+ else if (text[index] === "}")
1101
+ depth -= 1;
1102
+ if (depth === 0)
1103
+ return text.slice(start, index);
1104
+ }
1105
+ return text.slice(start);
1106
+ }
1107
+ function readSize(value) {
1108
+ const words = value.split(/\s+/);
1109
+ const orientation = words.find((word) => word === "portrait" || word === "landscape");
1110
+ const rest = words.filter((word) => word !== orientation);
1111
+ let size = null;
1112
+ if (rest.length === 1 && rest[0] && PAGE_SIZES[rest[0]]) {
1113
+ const [width, height] = PAGE_SIZES[rest[0]];
1114
+ size = [readLength(width), readLength(height)];
1115
+ } else if (rest.length === 0 && orientation) {
1116
+ size = [readLength("8.5in"), readLength("11in")];
1117
+ } else {
1118
+ const lengths = readLengths(rest.join(" "));
1119
+ if (lengths?.length === 1 && lengths[0])
1120
+ size = [lengths[0], lengths[0]];
1121
+ else if (lengths?.length === 2 && lengths[0] && lengths[1])
1122
+ size = [lengths[0], lengths[1]];
1123
+ }
1124
+ if (!size || size[0] <= 0 || size[1] <= 0)
1125
+ return null;
1126
+ const [short, long] = size[0] <= size[1] ? size : [size[1], size[0]];
1127
+ if (orientation === "landscape")
1128
+ return [long, short];
1129
+ if (orientation === "portrait")
1130
+ return [short, long];
1131
+ return size;
1132
+ }
1133
+ function readLengths(value) {
1134
+ const lengths = value.split(/\s+/).map(readLength);
1135
+ return lengths.length > 0 && lengths.every((length) => length !== null) ? lengths : null;
1136
+ }
1137
+ function readLength(value) {
1138
+ if (value === "0")
1139
+ return 0;
1140
+ const match = /^(-?\d*\.?\d+)([a-z]+)$/.exec(value);
1141
+ const perUnit = match?.[2] ? PX_PER_UNIT[match[2]] : undefined;
1142
+ if (!match || perUnit === undefined)
1143
+ return null;
1144
+ const length = Number(match[1]) * perUnit;
1145
+ return Number.isFinite(length) && length >= 0 ? length : null;
1146
+ }
1147
+
1148
+ // src/artifacts/publish/validate/document-html.ts
1149
+ var DOCUMENT_HTML_ENTRY = "document.html";
1150
+ var REFUSED_ELEMENTS = [
1151
+ "script",
1152
+ "iframe",
1153
+ "frame",
1154
+ "frameset",
1155
+ "object",
1156
+ "embed",
1157
+ "applet",
1158
+ "form",
1159
+ "base",
1160
+ "portal",
1161
+ "meta[http-equiv]"
1162
+ ];
1163
+ var RAW_TEXT_ELEMENTS = ["style", "title", "textarea", "xmp", "noembed", "noframes", "noscript"];
1164
+ var ADDRESS_ATTRIBUTES = ["href", "src", "xlink:href", "poster", "action", "formaction"];
1165
+ async function validateHtmlDocument(blobStorage, files) {
1166
+ const entry = files.find((file) => file.path === DOCUMENT_HTML_ENTRY);
1167
+ if (!entry)
1168
+ throw invalidArtifact(`A designed document needs '${DOCUMENT_HTML_ENTRY}'.`);
1169
+ refuseFrameAssetPaths(files, "the document");
1170
+ const html = await readArtifactText(blobStorage, entry, ARTIFACT_LIMITS2.maxDocumentBytes);
1171
+ const paths = new Set(files.map((file) => file.path));
1172
+ let refused;
1173
+ const refuse = (message) => {
1174
+ refused ??= message;
1175
+ };
1176
+ const headings = [];
1177
+ const slug = createHeadingSlugger2();
1178
+ const slugs = [];
1179
+ let heading = null;
1180
+ const styles = [];
1181
+ let style = null;
1182
+ let objectTypeId;
1183
+ const rewriter = new HTMLRewriter().on(REFUSED_ELEMENTS.join(", "), {
1184
+ element(element) {
1185
+ refuse(`${DOCUMENT_HTML_ENTRY} holds <${element.tagName}>. A designed document is laid out and printed, never run: it may not hold scripts, frames, forms, or <base>.`);
1186
+ }
1187
+ }).on("*", {
1188
+ element(element) {
1189
+ for (const [name, value] of element.attributes) {
1190
+ const attribute = name.toLowerCase();
1191
+ if (attribute.startsWith("on")) {
1192
+ refuse(`${DOCUMENT_HTML_ENTRY} gives <${element.tagName}> the handler '${name}'. A designed document runs no script.`);
1193
+ } else if (ADDRESS_ATTRIBUTES.includes(attribute) && /^\s*javascript:/i.test(decodeHtmlEntities(value).replace(/[\s\u0000-\u001f]/g, ""))) {
1194
+ refuse(`${DOCUMENT_HTML_ENTRY} links <${element.tagName}> to a javascript: address. A designed document runs no script.`);
1195
+ }
1196
+ }
1197
+ }
1198
+ }).on(RAW_TEXT_ELEMENTS.map((tag) => `${tag}[data-sixb-field], ${tag}[data-sixb-each]`).join(", "), {
1199
+ element(element) {
1200
+ refuse(`${DOCUMENT_HTML_ENTRY} shows live data in <${element.tagName}>, whose text is not markup. Put the field in an element that shows text, such as <span>.`);
1201
+ }
1202
+ }).on("h1, h2, h3, h4, h5, h6", {
1203
+ element(element) {
1204
+ const current = { depth: Number(element.tagName.slice(1)), text: "" };
1205
+ heading = current;
1206
+ headings.push(current);
1207
+ element.onEndTag(() => {
1208
+ slugs.push(slug(plainText(current.text)));
1209
+ heading = null;
1210
+ });
1211
+ },
1212
+ text(chunk) {
1213
+ if (heading)
1214
+ heading.text += chunk.text;
1215
+ }
1216
+ }).on("img[src]", {
1217
+ element(element) {
1218
+ const source = decodeHtmlEntities(element.getAttribute("src") ?? "").trim();
1219
+ if (isArtifactAddress2(source))
1220
+ return;
1221
+ const problem = localFileProblem(source, paths);
1222
+ if (problem) {
1223
+ refuse(`${DOCUMENT_HTML_ENTRY} shows the image '${source}', ${problem}. Images are files in the artifact, by their relative path, or another artifact's address, such as artifact:art_k3m9q2x7tp/logo.png.`);
1224
+ }
1225
+ }
1226
+ }).on("link[href]", {
1227
+ element(element) {
1228
+ const rel = (element.getAttribute("rel") ?? "").toLowerCase().split(/\s+/);
1229
+ if (!rel.includes("stylesheet"))
1230
+ return;
1231
+ const href = decodeHtmlEntities(element.getAttribute("href") ?? "").trim();
1232
+ if (FRAME_CDN_ALLOWLIST2.some((origin) => href.startsWith(`${origin}/`)))
1233
+ return;
1234
+ const problem = localFileProblem(href, paths);
1235
+ if (problem) {
1236
+ refuse(`${DOCUMENT_HTML_ENTRY} loads the stylesheet '${href}', ${problem}. A stylesheet is a file in the artifact, by its relative path, or on ${FRAME_CDN_ALLOWLIST2.join(", ")}.`);
1237
+ return;
1238
+ }
1239
+ styles.push({ path: posix2.normalize(safeDecodeUri(href.split(/[?#]/)[0] ?? "")) });
1240
+ }
1241
+ }).on('meta[name="sixb:object-type"]', {
1242
+ element(element) {
1243
+ const content = decodeHtmlEntities(element.getAttribute("content") ?? "").trim();
1244
+ if (content)
1245
+ objectTypeId ??= content;
1246
+ }
1247
+ }).on("style", {
1248
+ element(element) {
1249
+ const current = { css: "" };
1250
+ style = current;
1251
+ styles.push(current);
1252
+ element.onEndTag(() => {
1253
+ style = null;
1254
+ });
1255
+ },
1256
+ text(chunk) {
1257
+ if (style)
1258
+ style.css += chunk.text;
1259
+ }
1260
+ });
1261
+ const { references, refusal } = readHtmlReferences(rewriter, () => slugs.at(-1) ?? "", DOCUMENT_HTML_ENTRY);
1262
+ rewriter.transform(html);
1263
+ const problem = refused ?? refusal();
1264
+ if (problem)
1265
+ throw invalidArtifact(problem);
1266
+ const stylesheets = [];
1267
+ for (const each of styles) {
1268
+ if ("css" in each) {
1269
+ stylesheets.push(each.css);
1270
+ continue;
1271
+ }
1272
+ const file = files.find((candidate) => candidate.path === each.path);
1273
+ if (file) {
1274
+ stylesheets.push(await readArtifactText(blobStorage, file, ARTIFACT_LIMITS2.maxDocumentBytes));
1275
+ }
1276
+ }
1277
+ const paper = readDocumentPaper(stylesheets);
1278
+ const outlined = headings.map(({ depth, text }, index) => ({
1279
+ depth,
1280
+ text: plainText(text),
1281
+ slug: slugs[index] ?? ""
1282
+ }));
1283
+ return {
1284
+ entry: DOCUMENT_HTML_ENTRY,
1285
+ outline: {
1286
+ kind: "document",
1287
+ format: "html",
1288
+ headings: outlined,
1289
+ ...paper ? { paper } : {},
1290
+ ...objectTypeId ? { holder: { objectTypeId, links: [] } } : {}
1291
+ },
1292
+ references,
1293
+ marks: documentMarks(html)
1294
+ };
1295
+ }
1296
+ function plainText(text) {
1297
+ return decodeHtmlEntities(text).replace(/\s+/g, " ").trim();
1298
+ }
1299
+ function localFileProblem(source, paths) {
1300
+ if (source === "" || source.startsWith("//") || /^[a-z][a-z\d+.-]*:/i.test(source)) {
1301
+ return "which is not a file in the artifact";
1302
+ }
1303
+ const path = posix2.normalize(safeDecodeUri(source.split(/[?#]/)[0] ?? ""));
1304
+ return paths.has(path) ? null : "which is not one of the artifact's files";
1305
+ }
1306
+ function safeDecodeUri(value) {
1307
+ try {
1308
+ return decodeURI(value);
1309
+ } catch {
1310
+ return value;
1311
+ }
1312
+ }
1313
+
1314
+ // src/artifacts/publish/pdf.ts
1315
+ var MAX_DOCUMENT_PDF_BYTES2 = 64 * 1024 * 1024;
1316
+ var RENDER_KEY_FORMAT2 = "sixb-document-pdf/1";
1317
+ function documentPdfKey2(version, document) {
1318
+ if (version.outline.kind !== "document" || version.outline.format !== "html")
1319
+ return null;
1320
+ const files = version.files.map((entry) => [
1321
+ entry.path,
1322
+ document && entry.path === DOCUMENT_HTML_ENTRY ? document.digest : entry.file.digest
1323
+ ]).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
1324
+ return createHash3("sha256").update(JSON.stringify([RENDER_KEY_FORMAT2, frameKitDigest(), version.artifactId, files])).digest("hex");
1325
+ }
1326
+ async function requestDocumentPdf(context, version, options = {}) {
1327
+ const renderKey = documentPdfKey2(version, options.document);
1328
+ if (!renderKey)
1329
+ return;
1330
+ if (options.retry) {
1331
+ await context.storage.clearPdfFailure({ projectId: version.projectId, renderKey });
1332
+ }
1333
+ await context.queue.enqueue({
1334
+ projectId: version.projectId,
1335
+ jobs: [
1336
+ {
1337
+ id: `art_pdf_${renderKey}`,
1338
+ ...options.retry ? { replace: true } : {},
1339
+ type: "artifact.pdf.requested",
1340
+ payload: {
1341
+ artifactId: version.artifactId,
1342
+ version: version.version,
1343
+ renderKey,
1344
+ ...options.document ? { document: options.document } : {}
1345
+ }
1346
+ }
1347
+ ]
1348
+ });
1349
+ }
1350
+
1351
+ // src/artifacts/publish/fields.ts
1352
+ async function checkDocumentFields(input) {
1353
+ const data = documentData();
1354
+ const warnings = [];
1355
+ const unknown = (mark, why) => warnings.push({
1356
+ code: "field_unknown",
1357
+ message: `data-sixb-${mark.kind}="${mark.path}" ${why}. It keeps the text written in it.`
1358
+ });
1359
+ const baseOf = (path, within) => {
1360
+ if (path.query !== undefined) {
1361
+ const query = input.queries.get(path.query);
1362
+ return query ? { kind: "rows", query } : { kind: "unknown" };
1363
+ }
1364
+ const each = within.at(-1);
1365
+ if (each === undefined)
1366
+ return { kind: "holder" };
1367
+ const parsed = data.parse(each);
1368
+ if (!parsed)
1369
+ return { kind: "unknown" };
1370
+ if (parsed.query !== undefined && parsed.steps.length === 0)
1371
+ return baseOf(parsed, []);
1372
+ const [step, ...rest] = parsed.steps;
1373
+ const repeatsHolder = baseOf(parsed, within.slice(0, -1)).kind === "holder";
1374
+ return step && rest.length === 0 && step.id === undefined && repeatsHolder ? { kind: "item", key: step.key } : { kind: "unknown" };
1375
+ };
1376
+ const reads = input.marks.flatMap((mark) => {
1377
+ const path = data.parse(mark.path);
1378
+ if (!path) {
1379
+ unknown(mark, "is not a path: name properties with dots, and a list's item by its id in [ ]");
1380
+ return [];
1381
+ }
1382
+ return [{ mark, path, base: baseOf(path, mark.within) }];
1383
+ });
1384
+ let holder;
1385
+ let holderProperties = {};
1386
+ const linkProperties = new Map;
1387
+ const readsHolder = reads.some((read) => read.base.kind === "holder");
1388
+ if (readsHolder && !input.holder) {
1389
+ warnings.push({
1390
+ code: "field_unknown",
1391
+ message: `The document's fields read the object that holds it, but it names no type of object: add <meta name="sixb:object-type" content="..."> to its <head>. They keep the text written in them.`
1392
+ });
1393
+ }
1394
+ if (input.holder) {
1395
+ if (!input.checker) {
1396
+ throw invalidArtifact("The document shows live data of the object that holds it, and this publish has no way to check that its author reads it.");
1397
+ }
1398
+ const objectTypeId = input.holder;
1399
+ const start = { kind: "start", objectTypeId };
1400
+ try {
1401
+ holderProperties = (await input.checker({ kind: "objects", query: start })).schema.properties;
1402
+ } catch (error) {
1403
+ throw invalidArtifact(`The document names the object type '${objectTypeId}' in <meta name="sixb:object-type">, which you cannot read: ${error instanceof Error ? error.message.replace(/^\[Sixb\]\s*/, "") : String(error)}`);
1404
+ }
1405
+ const candidates = new Set;
1406
+ for (const { base, path } of reads) {
1407
+ const first = path.steps[0]?.key;
1408
+ if (base.kind === "holder" && first && !Object.hasOwn(holderProperties, first)) {
1409
+ candidates.add(first);
1410
+ }
1411
+ }
1412
+ for (const linkId of candidates) {
1413
+ try {
1414
+ const checked = await input.checker({
1415
+ kind: "objects",
1416
+ query: { kind: "expand", input: start, expansions: [{ linkId, direction: "outgoing" }] }
1417
+ });
1418
+ linkProperties.set(linkId, checked.schema.links[linkId]?.properties ?? {});
1419
+ } catch {}
1420
+ }
1421
+ holder = { objectTypeId, links: [...linkProperties.keys()] };
1422
+ }
1423
+ for (const { mark, path, base } of reads) {
1424
+ const [first, second] = path.steps;
1425
+ switch (base.kind) {
1426
+ case "unknown":
1427
+ if (path.query !== undefined)
1428
+ unknown(mark, `names no query: add queries/${path.query}.json`);
1429
+ break;
1430
+ case "rows": {
1431
+ const facets = base.query.kind === "facets";
1432
+ if (path.query !== undefined) {
1433
+ if (mark.kind === "field" && first?.key === "total" && path.steps.length === 1)
1434
+ break;
1435
+ if (first?.key === "facets" && path.steps.length === 2 && facets)
1436
+ break;
1437
+ if (mark.kind === "each" && path.steps.length === 0 && !facets)
1438
+ break;
1439
+ unknown(mark, facets ? `reads facets: repeat over query:${path.query}.facets.<property>, or show query:${path.query}.total` : `reads rows: repeat over query:${path.query}, or show query:${path.query}.total`);
1440
+ break;
1441
+ }
1442
+ if (!first)
1443
+ break;
1444
+ const links = base.query.schema.links;
1445
+ if (Object.hasOwn(base.query.schema.properties, first.key))
1446
+ break;
1447
+ if (Object.hasOwn(links, first.key)) {
1448
+ if (second && !Object.hasOwn(links[first.key]?.properties ?? {}, second.key)) {
1449
+ unknown(mark, `reads '${second.key}', which what '${first.key}' reaches does not hold`);
1450
+ }
1451
+ break;
1452
+ }
1453
+ unknown(mark, `reads '${first.key}', which the rows of its query do not hold`);
1454
+ break;
1455
+ }
1456
+ case "item": {
1457
+ const reached = linkProperties.get(base.key);
1458
+ if (reached && first && !Object.hasOwn(reached, first.key)) {
1459
+ unknown(mark, `reads '${first.key}', which what '${base.key}' reaches does not hold`);
1460
+ }
1461
+ break;
1462
+ }
1463
+ case "holder": {
1464
+ if (!input.holder || !first)
1465
+ break;
1466
+ if (Object.hasOwn(holderProperties, first.key))
1467
+ break;
1468
+ const reached = linkProperties.get(first.key);
1469
+ if (!reached) {
1470
+ unknown(mark, `reads '${first.key}', which a ${input.holder} does not hold`);
1471
+ } else if (second && !Object.hasOwn(reached, second.key)) {
1472
+ unknown(mark, `reads '${second.key}', which what '${first.key}' reaches does not hold`);
1473
+ }
1474
+ break;
1475
+ }
1476
+ }
1477
+ }
1478
+ return { ...holder ? { holder } : {}, warnings };
1479
+ }
1480
+
978
1481
  // src/artifacts/run-query.ts
979
1482
  var PAGE_SIZE = 1000;
980
1483
  async function runArtifactQuery(runtime, name, query) {
@@ -1207,7 +1710,7 @@ function outermostProject(query, at = "$") {
1207
1710
  return;
1208
1711
  }
1209
1712
  }
1210
- async function checkArtifactQueries(blobStorage, kind, files, checker) {
1713
+ async function checkArtifactQueries(blobStorage, kind, files, checker, options = {}) {
1211
1714
  const checked = new Map;
1212
1715
  if (kind === "file")
1213
1716
  return checked;
@@ -1215,8 +1718,9 @@ async function checkArtifactQueries(blobStorage, kind, files, checker) {
1215
1718
  const [first] = queries;
1216
1719
  if (!first)
1217
1720
  return checked;
1218
- if (!ARTIFACT_QUERY_KINDS.includes(kind)) {
1219
- throw invalidArtifact(`'${first.path}': a ${kind} runs no query. A document shows a live sheet instead.`);
1721
+ const markdown = kind === "document" && !files.some((file) => file.path === DOCUMENT_HTML_ENTRY);
1722
+ if (!ARTIFACT_QUERY_KINDS.includes(kind) || markdown) {
1723
+ throw invalidArtifact(`'${first.path}': a ${markdown ? "Markdown document" : kind} runs no query. A Markdown document shows a live sheet instead; a designed one, document.html, runs queries.`);
1220
1724
  }
1221
1725
  if (queries.length > ARTIFACT_LIMITS2.maxQueries) {
1222
1726
  throw invalidArtifact(`A version holds at most ${ARTIFACT_LIMITS2.maxQueries} queries; this one has ${queries.length}.`);
@@ -1229,8 +1733,11 @@ async function checkArtifactQueries(blobStorage, kind, files, checker) {
1229
1733
  if (!name) {
1230
1734
  throw invalidArtifact(`'${file.path}' is not a query: name it queries/<name>.json, with lowercase letters, digits and hyphens, at most 64 characters.`);
1231
1735
  }
1736
+ if (kind === "document" && name === DOCUMENT_HOLDER_QUERY2) {
1737
+ throw invalidArtifact(`'${file.path}': "${DOCUMENT_HOLDER_QUERY2}" is what a document's fields read of the object that holds it. Name the query otherwise.`);
1738
+ }
1232
1739
  const text = await readArtifactText(blobStorage, file, ARTIFACT_LIMITS2.maxQueryBytes);
1233
- const parsed = parseArtifactQuery(file.path, text);
1740
+ const parsed = parseArtifactQuery(file.path, text, options.holder ? { holder: { kind: "start", objectTypeId: options.holder } } : {});
1234
1741
  if ("error" in parsed)
1235
1742
  throw invalidArtifact(parsed.error);
1236
1743
  try {
@@ -1345,7 +1852,7 @@ function ownArtifacts(author) {
1345
1852
  }
1346
1853
 
1347
1854
  // src/artifacts/publish/validate/canvas.ts
1348
- import { posix as posix2 } from "path";
1855
+ import { posix as posix3 } from "path";
1349
1856
  async function validateCanvas(blobStorage, files) {
1350
1857
  const byPath = new Map(files.map((file) => [file.path, file]));
1351
1858
  const canvasFile = byPath.get(CANVAS_FILE2);
@@ -1363,7 +1870,7 @@ async function validateCanvas(blobStorage, files) {
1363
1870
  references.push({ address: item.src, as: "embed", at: item.id });
1364
1871
  if (item.type !== "board")
1365
1872
  continue;
1366
- const file = byPath.get(posix2.normalize(item.file));
1873
+ const file = byPath.get(posix3.normalize(item.file));
1367
1874
  if (!file) {
1368
1875
  throw invalidArtifact(`${CANVAS_FILE2} board '${item.id}' shows '${item.file}', which is not one of the canvas's files.`);
1369
1876
  }
@@ -1384,7 +1891,7 @@ async function validateCanvas(blobStorage, files) {
1384
1891
  const named = { id: item.id, ...title ? { title } : {} };
1385
1892
  if (item.type === "board") {
1386
1893
  return [
1387
- { ...named, type: "board", file: posix2.normalize(item.file), w: item.w, h: item.h }
1894
+ { ...named, type: "board", file: posix3.normalize(item.file), w: item.w, h: item.h }
1388
1895
  ];
1389
1896
  }
1390
1897
  return item.type === "section" ? [{ ...named, type: "section" }] : [];
@@ -1523,12 +2030,22 @@ function crosses(start, end, box) {
1523
2030
  }
1524
2031
 
1525
2032
  // src/artifacts/publish/validate/document.ts
1526
- import { posix as posix3 } from "path";
2033
+ import { posix as posix4 } from "path";
1527
2034
  var DOCUMENT_ENTRY = "document.md";
1528
2035
  async function validateDocument(blobStorage, files) {
1529
- const entry = files.find((file) => file.path === DOCUMENT_ENTRY);
1530
- if (!entry)
1531
- throw invalidArtifact(`A document needs its Markdown in '${DOCUMENT_ENTRY}'.`);
2036
+ const markdown = files.find((file) => file.path === DOCUMENT_ENTRY);
2037
+ const designed = files.some((file) => file.path === DOCUMENT_HTML_ENTRY);
2038
+ if (markdown && designed) {
2039
+ throw invalidArtifact(`A document renders from '${DOCUMENT_ENTRY}' or from '${DOCUMENT_HTML_ENTRY}', not both: keep one.`);
2040
+ }
2041
+ if (designed)
2042
+ return validateHtmlDocument(blobStorage, files);
2043
+ if (!markdown) {
2044
+ throw invalidArtifact(`A document needs its Markdown in '${DOCUMENT_ENTRY}', or its HTML in '${DOCUMENT_HTML_ENTRY}' when it has a design of its own.`);
2045
+ }
2046
+ return validateMarkdownDocument(blobStorage, markdown, files);
2047
+ }
2048
+ async function validateMarkdownDocument(blobStorage, entry, files) {
1532
2049
  const markdown = await readArtifactText(blobStorage, entry, ARTIFACT_LIMITS2.maxDocumentBytes);
1533
2050
  const html = Bun.markdown.html(markdown, {
1534
2051
  tables: true,
@@ -1591,12 +2108,12 @@ function checkImage(source, paths) {
1591
2108
  if (source === "" || source.startsWith("//") || /^[a-z][a-z\d+.-]*:/i.test(source)) {
1592
2109
  throw invalidArtifact(`${DOCUMENT_ENTRY} shows the image '${source}'. Images must be files in the artifact, by their relative path, or another artifact's address, such as artifact:art_k3m9q2x7tp#chart=revenue.`);
1593
2110
  }
1594
- const path = posix3.normalize(safeDecodeUri(source.split(/[?#]/)[0] ?? ""));
2111
+ const path = posix4.normalize(safeDecodeUri2(source.split(/[?#]/)[0] ?? ""));
1595
2112
  if (!paths.has(path)) {
1596
2113
  throw invalidArtifact(`${DOCUMENT_ENTRY} shows the image '${source}', which is not one of the artifact's files.`);
1597
2114
  }
1598
2115
  }
1599
- function safeDecodeUri(value) {
2116
+ function safeDecodeUri2(value) {
1600
2117
  try {
1601
2118
  return decodeURI(value);
1602
2119
  } catch {
@@ -1661,7 +2178,7 @@ async function validatePage(blobStorage, files) {
1661
2178
  }
1662
2179
 
1663
2180
  // src/artifacts/publish/validate/sheet.ts
1664
- import { posix as posix4 } from "path";
2181
+ import { posix as posix5 } from "path";
1665
2182
  async function validateSheet(blobStorage, files, queries) {
1666
2183
  const byPath = new Map(files.map((file) => [file.path, file]));
1667
2184
  const workbookFile = byPath.get(WORKBOOK_FILE2);
@@ -1821,7 +2338,7 @@ function cellProblem(value, format, byPath) {
1821
2338
  case "link":
1822
2339
  return /^https?:\/\/[^\s]+$/i.test(value.trim()) ? undefined : "is not a link: write a full https:// address, or another artifact's address.";
1823
2340
  case "image": {
1824
- const imagePath = posix4.normalize(value.trim());
2341
+ const imagePath = posix5.normalize(value.trim());
1825
2342
  return byPath.has(imagePath) ? undefined : "is not one of the artifact's files: add the image to the artifact and give its relative path, or give another artifact's address.";
1826
2343
  }
1827
2344
  case "boolean":
@@ -1914,8 +2431,22 @@ async function prepareArtifactVersion2(context, input) {
1914
2431
  const title = checkTitle(input.title);
1915
2432
  await checkArtifactFiles(context.blobStorage, input.files);
1916
2433
  const theme = input.kind === "file" ? undefined : await readTheme(context.blobStorage, input.files);
1917
- const queries = await checkArtifactQueries(context.blobStorage, input.kind, input.files, input.checkQuery);
1918
- const validated = await validateKind(context.blobStorage, input.kind, input.files, queries);
2434
+ const document = input.kind === "document" ? await validateDocument(context.blobStorage, input.files) : null;
2435
+ const queries = await checkArtifactQueries(context.blobStorage, input.kind, input.files, input.checkQuery, document?.outline.holder ? { holder: document.outline.holder.objectTypeId } : {});
2436
+ const fields = document?.marks ? await checkDocumentFields({
2437
+ marks: document.marks,
2438
+ ...document.outline.holder ? { holder: document.outline.holder.objectTypeId } : {},
2439
+ queries,
2440
+ ...input.checkQuery ? { checker: input.checkQuery } : {}
2441
+ }) : null;
2442
+ const validated = document ? {
2443
+ ...document,
2444
+ outline: {
2445
+ ...document.outline,
2446
+ ...fields?.holder ? { holder: fields.holder } : {}
2447
+ },
2448
+ warnings: fields?.warnings ?? []
2449
+ } : await validateKind(context.blobStorage, input.kind, input.files, queries);
1919
2450
  const readable = input.readable ?? ownArtifacts(input.author);
1920
2451
  const references = await resolveReferences(referenceContext(context, { readable, artifactId: input.artifactId }), validated.references ?? []);
1921
2452
  return {
@@ -2165,13 +2696,92 @@ function createArtifactsRuntime(runtime, blobStorage, options = {}) {
2165
2696
  };
2166
2697
  const rule = () => createRuntimeArtifactAccessRule(runtime);
2167
2698
  const checkQuery = createArtifactQueryChecker(runtime);
2699
+ const runQuery = async (read, name) => {
2700
+ const { artifact, version } = read;
2701
+ const holder = version.outline.kind === "document" ? version.outline.holder : undefined;
2702
+ if (holder && name === DOCUMENT_HOLDER_QUERY2) {
2703
+ const refs = { kind: "refs", refs: [await requireHolder(artifact.id, holder)] };
2704
+ const expansions = holder.links.map((linkId) => ({
2705
+ linkId,
2706
+ direction: "outgoing"
2707
+ }));
2708
+ return runArtifactQuery(runtime, name, {
2709
+ kind: "objects",
2710
+ query: expansions.length > 0 ? { kind: "expand", input: refs, expansions } : refs
2711
+ });
2712
+ }
2713
+ const file = ARTIFACT_QUERY_KINDS.includes(artifact.kind) && isArtifactQueryName(name) ? version.files.find((candidate) => candidate.path === artifactQueryPath(name)) : undefined;
2714
+ if (!file) {
2715
+ throw new ArtifactRequestError2("query_not_found", `[Sixb] Version ${version.version} of artifact '${artifact.id}' has no query '${name}'.`);
2716
+ }
2717
+ const text = await readArtifactText(blobStorage, file, ARTIFACT_LIMITS2.maxQueryBytes);
2718
+ const parse = (start) => parseArtifactQuery(file.path, text, start ? { holder: start } : {});
2719
+ let parsed = parse(holder ? { kind: "refs", refs: [] } : undefined);
2720
+ if (holder && "usesHolder" in parsed && parsed.usesHolder) {
2721
+ parsed = parse({ kind: "refs", refs: [await requireHolder(artifact.id, holder)] });
2722
+ }
2723
+ if ("error" in parsed) {
2724
+ throw new ArtifactRequestError2("query_invalid", `[Sixb] ${parsed.error}`);
2725
+ }
2726
+ return runArtifactQuery(runtime, name, parsed.query);
2727
+ };
2728
+ const writtenIn = async (read, options = {}) => {
2729
+ const { version } = read;
2730
+ const entry = version.files.find((file) => file.path === DOCUMENT_HTML_ENTRY);
2731
+ if (version.outline.kind !== "document" || !entry)
2732
+ return null;
2733
+ const html = await readArtifactText(blobStorage, entry, ARTIFACT_LIMITS2.maxDocumentBytes);
2734
+ const reads = documentData().reads(documentMarks(html));
2735
+ if (!reads.holder && reads.queries.length === 0)
2736
+ return null;
2737
+ if (version.frozenAt)
2738
+ return frozenDocumentHtml2(html);
2739
+ const answer = (name) => runQuery(read, name).then((result) => result, (error) => {
2740
+ if (error instanceof AuthorizationError2 || error instanceof ArtifactRequestError2) {
2741
+ return;
2742
+ }
2743
+ throw error;
2744
+ });
2745
+ const [holder, ...results] = await Promise.all([
2746
+ reads.holder ? answer(DOCUMENT_HOLDER_QUERY2) : undefined,
2747
+ ...reads.queries.map(answer)
2748
+ ]);
2749
+ const queries = {};
2750
+ reads.queries.forEach((name, index) => {
2751
+ const result = results[index];
2752
+ if (result)
2753
+ queries[name] = result;
2754
+ });
2755
+ const row = holder?.objects?.[0];
2756
+ return fillDocumentHtml(html, { ...row ? { holder: row } : {}, queries }, options.keep ? { keep: true } : { plain: true });
2757
+ };
2758
+ const requireHolder = async (artifactId, holder) => {
2759
+ const found = new Set;
2760
+ const holdings = readableHoldings({
2761
+ runtime,
2762
+ reader: runtime.objectReader,
2763
+ objects: runtime.storage.objects,
2764
+ artifactId
2765
+ });
2766
+ for await (const holding of holdings) {
2767
+ if (holding.objectTypeId === holder.objectTypeId)
2768
+ found.add(holding.primaryId);
2769
+ if (found.size > 1)
2770
+ break;
2771
+ }
2772
+ const [primaryId] = found;
2773
+ if (found.size !== 1 || primaryId === undefined) {
2774
+ throw new ArtifactRequestError2("holder_not_found", `[Sixb] No one ${holder.objectTypeId} you read holds artifact '${artifactId}', so its fields show what is written in them.`);
2775
+ }
2776
+ return { objectTypeId: holder.objectTypeId, primaryId };
2777
+ };
2168
2778
  const requestPreviews = async (version, requestOptions) => {
2169
2779
  const storage = runtime.storage.artifacts;
2170
- if (!options.rendersBoardPreviews || !storage)
2780
+ if (!options.rendersInSandboxes || !storage)
2171
2781
  return;
2172
2782
  await requestBoardPreviews({
2173
2783
  storage,
2174
- queue: runtime.queues.agents,
2784
+ queue: runtime.queues.renders,
2175
2785
  blobStorage,
2176
2786
  query: (name) => artifacts.query(version.artifactId, name, { version: version.version })
2177
2787
  }, version, requestOptions);
@@ -2278,8 +2888,8 @@ function createArtifactsRuntime(runtime, blobStorage, options = {}) {
2278
2888
  };
2279
2889
  const writeLive = async (artifactId, input) => {
2280
2890
  const artifact = await requireUpdatable(artifactId);
2281
- if (!keepsDocument(artifact.kind)) {
2282
- throw invalidArtifact(`Artifact '${artifactId}' is a ${artifact.kind}, which is not edited live: publish its files.`);
2891
+ if (!keepsDocument2(artifact.kind)) {
2892
+ throw invalidArtifact(`Artifact '${artifactId}' is a ${artifact.kind} that is not edited live: publish its files.`);
2283
2893
  }
2284
2894
  return write({ artifactId, kind: artifact.kind, ...input });
2285
2895
  };
@@ -2290,7 +2900,8 @@ function createArtifactsRuntime(runtime, blobStorage, options = {}) {
2290
2900
  events: runtime.events,
2291
2901
  author: commentAuthor,
2292
2902
  manager: requireCaller,
2293
- reach
2903
+ reach,
2904
+ ...authority.type === "delegated" ? { guest: { grantId: authority.delegation?.grantId } } : {}
2294
2905
  }),
2295
2906
  async create(input) {
2296
2907
  const author = requireCaller();
@@ -2321,11 +2932,30 @@ function createArtifactsRuntime(runtime, blobStorage, options = {}) {
2321
2932
  });
2322
2933
  },
2323
2934
  async freeze(artifactId, input = {}) {
2935
+ let baseRevision = input.baseRevision;
2936
+ const open = await readVersion(artifactId, "latest");
2937
+ const filled = open && !open.version.frozenAt ? await writtenIn(open, { keep: true }) : null;
2938
+ if (open && filled !== null) {
2939
+ await requireUpdatable(artifactId);
2940
+ const document = await blobStorage.put({
2941
+ body: new TextEncoder().encode(filled),
2942
+ fileName: DOCUMENT_HTML_ENTRY,
2943
+ mediaType: "text/html"
2944
+ });
2945
+ const written = await write({
2946
+ artifactId,
2947
+ kind: "document",
2948
+ files: open.version.files.map((file) => file.path === DOCUMENT_HTML_ENTRY ? { path: file.path, file: document } : file),
2949
+ baseRevision: baseRevision ?? open.version.revision,
2950
+ title: open.version.title
2951
+ });
2952
+ baseRevision = written.version.revision;
2953
+ }
2324
2954
  const frozenAt = new Date;
2325
2955
  const frozen = await change(artifactId, (storage, author) => storage.freeze({
2326
2956
  projectId: runtime.projectId,
2327
2957
  artifactId,
2328
- ...input.baseRevision === undefined ? {} : { baseRevision: input.baseRevision },
2958
+ ...baseRevision === undefined ? {} : { baseRevision },
2329
2959
  frozenAt,
2330
2960
  frozenBy: author
2331
2961
  }));
@@ -2405,21 +3035,49 @@ function createArtifactsRuntime(runtime, blobStorage, options = {}) {
2405
3035
  async getVersion(artifactId, version) {
2406
3036
  return (await readVersion(artifactId, version))?.version ?? null;
2407
3037
  },
2408
- async query(artifactId, name, options = {}) {
2409
- const read = await readVersion(artifactId, options.version ?? "latest");
3038
+ async pdf(artifactId, pdfOptions = {}) {
3039
+ const read = await readVersion(artifactId, pdfOptions.version ?? "latest");
2410
3040
  if (!read)
2411
3041
  return null;
2412
- const { artifact, version } = read;
2413
- const file = ARTIFACT_QUERY_KINDS.includes(artifact.kind) && isArtifactQueryName(name) ? version.files.find((candidate) => candidate.path === artifactQueryPath(name)) : undefined;
2414
- if (!file) {
2415
- throw new ArtifactRequestError2("query_not_found", `[Sixb] Version ${version.version} of artifact '${artifactId}' has no query '${name}'.`);
3042
+ const { version } = read;
3043
+ if (!documentPdfKey2(version)) {
3044
+ throw invalidArtifact(`Version ${version.version} of '${artifactId}' is not a designed document, which alone prints to PDF.`);
2416
3045
  }
2417
- const text = await readArtifactText(blobStorage, file, ARTIFACT_LIMITS2.maxQueryBytes);
2418
- const parsed = parseArtifactQuery(file.path, text);
2419
- if ("error" in parsed) {
2420
- throw new ArtifactRequestError2("query_invalid", `[Sixb] ${parsed.error}`);
3046
+ const { key } = pdfOptions;
3047
+ const filled = key !== undefined ? null : await writtenIn(read);
3048
+ const printed = filled === null ? null : new TextEncoder().encode(filled);
3049
+ const digest = key ?? (printed ? computeBlobDigest2(printed) : undefined);
3050
+ const keyed = digest ? { key: digest } : {};
3051
+ const renderKey = documentPdfKey2(version, digest ? { digest } : undefined);
3052
+ const storage = requireStorage();
3053
+ const kept = await storage.getPdf({ projectId: runtime.projectId, renderKey });
3054
+ if (kept && !("failure" in kept)) {
3055
+ return { status: "ready", file: kept.file, pages: kept.pages, ...keyed };
2421
3056
  }
2422
- return runArtifactQuery(runtime, name, parsed.query);
3057
+ if (kept && (!pdfOptions.retry || key !== undefined)) {
3058
+ return { status: "failed", reason: kept.failure, ...keyed };
3059
+ }
3060
+ if (pdfOptions.print === false || key !== undefined)
3061
+ return { status: "printing", ...keyed };
3062
+ if (!options.rendersInSandboxes) {
3063
+ throw new ArtifactRequestError2("pdf_unavailable", "[Sixb] A document prints to PDF in a sandbox, and this project has no sandbox provider.");
3064
+ }
3065
+ const document = printed ? await blobStorage.put({
3066
+ body: printed,
3067
+ fileName: DOCUMENT_HTML_ENTRY,
3068
+ mediaType: "text/html"
3069
+ }) : undefined;
3070
+ await requestDocumentPdf({ storage, queue: runtime.queues.renders }, version, {
3071
+ ...document ? { document } : {},
3072
+ retry: pdfOptions.retry === true
3073
+ });
3074
+ return { status: "printing", ...keyed };
3075
+ },
3076
+ async query(artifactId, name, options = {}) {
3077
+ const read = await readVersion(artifactId, options.version ?? "latest");
3078
+ if (!read)
3079
+ return null;
3080
+ return runQuery(read, name);
2423
3081
  },
2424
3082
  async listVersions(artifactId, input = {}) {
2425
3083
  if (!await getReadable(artifactId))
@@ -2524,12 +3182,12 @@ async function sharedLinkGuest(runtime, delegation) {
2524
3182
  if (!name) {
2525
3183
  throw new ArtifactRequestError2("name_required", "[Sixb] A shared link's guest gives their name before they comment.");
2526
3184
  }
2527
- return { type: "guest", id: delegation.sessionId, name };
3185
+ return { type: "guest", id: delegation.sessionId, name, grantId: delegation.grantId };
2528
3186
  }
2529
3187
  function notFound3(artifactId) {
2530
3188
  return new ArtifactRequestError2("artifact_not_found", `[Sixb] Artifact '${artifactId}' was not found.`);
2531
3189
  }
2532
3190
 
2533
- export { createAgentThreadAccessRule, assertConversationThread2, conversationThreadId2, agentThreadViews, announceArtifactUpdates, readLiveFiles2, storeLiveFiles2, sameArtifactFiles2, loadArtifactDocument2, readDocumentState2, firstArtifactDocument, withMergedWrite, undoneTurnDocuments, answerArtifactQueries2, parseArtifactQueryAnswers2, BOARD_PREVIEW_MEDIA_TYPES2, MAX_BOARD_PREVIEW_BYTES2, boardRenderKey, boardPreviewsOfCopy, boardsReadLiveData2, boardPreviews2, boardPreview2, missingBoardPreviews2, boardPreviewStatuses2, storeBoardPreviews2, publishArtifact2, prepareArtifactVersion2, storeArtifactVersion2, artifactVersionWarnings2, artifactAccessRule2, artifactTransactionRules, artifactQueryChecker2, artifactPreviewRequester, writeLiveArtifact2, createRuntimeArtifactAccessRule, transactionArtifactAccessRules, updatableArtifactIds, createArtifactsRuntime };
3191
+ export { createAgentThreadAccessRule, assertConversationThread2, conversationThreadId2, agentThreadViews, announceArtifactUpdates, readLiveFiles2, storeLiveFiles2, sameArtifactFiles2, keepsDocument2, loadArtifactDocument2, readDocumentState2, firstArtifactDocument, withMergedWrite, undoneTurnDocuments, answerArtifactQueries2, parseArtifactQueryAnswers2, BOARD_PREVIEW_MEDIA_TYPES2, MAX_BOARD_PREVIEW_BYTES2, boardRenderKey, boardPreviewsOfCopy, boardsReadLiveData2, boardPreviews2, boardPreview2, missingBoardPreviews2, boardPreviewStatuses2, storeBoardPreviews2, MAX_DOCUMENT_PDF_BYTES2, documentPdfKey2, publishArtifact2, prepareArtifactVersion2, storeArtifactVersion2, artifactVersionWarnings2, artifactAccessRule2, artifactTransactionRules, artifactQueryChecker2, artifactPreviewRequester, writeLiveArtifact2, createRuntimeArtifactAccessRule, transactionArtifactAccessRules, updatableArtifactIds, createArtifactsRuntime };
2534
3192
 
2535
- //# debugId=AA04267CD72FF03864756E2164756E21
3193
+ //# debugId=9B02BA7B361316AF64756E2164756E21