allyhub 0.19.0 → 0.20.0

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 (699) hide show
  1. package/dist/commands/align.js +1 -1
  2. package/dist/commands/check.js +1 -1
  3. package/dist/commands/cloud-tools.js +1 -1
  4. package/dist/commands/cloud.js +1 -1
  5. package/dist/commands/dev.js +5 -5
  6. package/dist/commands/export.js +3 -0
  7. package/dist/commands/frames/doc.js +1 -1
  8. package/dist/commands/frames/piece.js +1 -1
  9. package/dist/commands/frames/sheet.js +1 -1
  10. package/dist/commands/frames.js +9 -9
  11. package/dist/commands/index.js +1 -1
  12. package/dist/commands/inspect/combos.js +1 -1
  13. package/dist/commands/inspect/common.js +2 -2
  14. package/dist/commands/inspect/facts.js +2 -2
  15. package/dist/commands/migrate.js +3 -0
  16. package/dist/commands/skills.js +3 -3
  17. package/dist/commands/upgrade.js +5 -0
  18. package/dist/commands.json +1 -1
  19. package/dist/help.js +3 -3
  20. package/dist/main.js +8 -7
  21. package/dist/node_modules/@allyhub/3d-extension/package.json +2 -2
  22. package/dist/node_modules/@allyhub/audio/package.json +1 -1
  23. package/dist/node_modules/@allyhub/blocks/LICENSE +241 -0
  24. package/dist/node_modules/@allyhub/blocks/dist/alt.js +2 -0
  25. package/dist/node_modules/@allyhub/blocks/dist/elements.js +2 -0
  26. package/dist/node_modules/@allyhub/blocks/dist/flow-resolve.js +2 -0
  27. package/dist/node_modules/@allyhub/blocks/dist/flow-table.js +2 -0
  28. package/dist/node_modules/@allyhub/blocks/dist/format.js +2 -0
  29. package/dist/node_modules/@allyhub/blocks/dist/gantt.js +2 -0
  30. package/dist/node_modules/@allyhub/blocks/dist/grids.js +2 -0
  31. package/dist/node_modules/@allyhub/blocks/dist/html.js +75 -0
  32. package/dist/node_modules/@allyhub/blocks/dist/icons.generated.js +2 -0
  33. package/dist/node_modules/@allyhub/blocks/dist/icons.js +2 -0
  34. package/dist/node_modules/@allyhub/blocks/dist/index.js +2 -0
  35. package/dist/node_modules/@allyhub/blocks/dist/layout.js +2 -0
  36. package/dist/node_modules/@allyhub/blocks/dist/look.js +2 -0
  37. package/dist/node_modules/@allyhub/blocks/dist/measure.js +3 -0
  38. package/dist/node_modules/@allyhub/blocks/dist/model.js +2 -0
  39. package/dist/node_modules/@allyhub/blocks/dist/page.js +2 -0
  40. package/dist/node_modules/@allyhub/blocks/dist/palette.js +2 -0
  41. package/dist/node_modules/@allyhub/blocks/dist/path.js +2 -0
  42. package/dist/node_modules/@allyhub/blocks/dist/resolve.js +2 -0
  43. package/dist/node_modules/@allyhub/blocks/dist/samples.js +2 -0
  44. package/dist/node_modules/@allyhub/blocks/dist/sankey.js +2 -0
  45. package/dist/node_modules/@allyhub/blocks/dist/svg.js +2 -0
  46. package/dist/node_modules/@allyhub/blocks/dist/tidy.js +2 -0
  47. package/dist/node_modules/@allyhub/blocks/dist/trees.js +2 -0
  48. package/dist/node_modules/@allyhub/blocks/package.json +19 -0
  49. package/dist/node_modules/@allyhub/browser/dist/html.js +1 -1
  50. package/dist/node_modules/@allyhub/browser/package.json +1 -1
  51. package/dist/node_modules/@allyhub/build/dist/fonts.js +9 -3
  52. package/dist/node_modules/@allyhub/build/dist/index.js +1 -1
  53. package/dist/node_modules/@allyhub/build/dist/inspect-view.js +1 -1
  54. package/dist/node_modules/@allyhub/build/dist/migrate.js +2 -0
  55. package/dist/node_modules/@allyhub/build/dist/prepare.js +3 -3
  56. package/dist/node_modules/@allyhub/build/dist/work.js +3 -3
  57. package/dist/node_modules/@allyhub/build/package.json +5 -1
  58. package/dist/node_modules/@allyhub/canvas-extension/package.json +1 -1
  59. package/dist/node_modules/@allyhub/canvas-model/package.json +1 -1
  60. package/dist/node_modules/@allyhub/chart/dist/chart-file.js +2 -1
  61. package/dist/node_modules/@allyhub/chart/dist/chart-xml.js +4 -3
  62. package/dist/node_modules/@allyhub/chart/dist/chart.js +4 -2
  63. package/dist/node_modules/@allyhub/chart/dist/chartex-xml.js +4 -0
  64. package/dist/node_modules/@allyhub/chart/dist/classic.js +2 -0
  65. package/dist/node_modules/@allyhub/chart/dist/embedded.js +2 -2
  66. package/dist/node_modules/@allyhub/chart/dist/extended.js +2 -0
  67. package/dist/node_modules/@allyhub/chart/dist/index.js +1 -1
  68. package/dist/node_modules/@allyhub/chart/dist/svg.js +1 -1
  69. package/dist/node_modules/@allyhub/chart/dist/tree.js +2 -0
  70. package/dist/node_modules/@allyhub/chart/package.json +1 -1
  71. package/dist/node_modules/@allyhub/check/dist/check.js +1 -1
  72. package/dist/node_modules/@allyhub/check/package.json +1 -1
  73. package/dist/node_modules/@allyhub/cloud/dist/blobs.js +1 -1
  74. package/dist/node_modules/@allyhub/cloud/dist/call.js +4 -4
  75. package/dist/node_modules/@allyhub/cloud/dist/client.js +1 -1
  76. package/dist/node_modules/@allyhub/cloud/dist/storage.js +2 -0
  77. package/dist/node_modules/@allyhub/cloud/dist/uploads.js +2 -2
  78. package/dist/node_modules/@allyhub/cloud/package.json +1 -1
  79. package/dist/node_modules/@allyhub/components/package.json +1 -1
  80. package/dist/node_modules/@allyhub/dev-server/dist/background.js +1 -1
  81. package/dist/node_modules/@allyhub/dev-server/dist/item-process.js +2 -0
  82. package/dist/node_modules/@allyhub/dev-server/dist/item-worker.js +2 -0
  83. package/dist/node_modules/@allyhub/dev-server/dist/live.js +1 -1
  84. package/dist/node_modules/@allyhub/dev-server/dist/pages.js +20 -1
  85. package/dist/node_modules/@allyhub/dev-server/dist/project.js +1 -1
  86. package/dist/node_modules/@allyhub/dev-server/dist/record.js +1 -1
  87. package/dist/node_modules/@allyhub/dev-server/dist/server.js +2 -2
  88. package/dist/node_modules/@allyhub/dev-server/dist/tools.js +1 -1
  89. package/dist/node_modules/@allyhub/dev-server/dist/validate.js +2 -2
  90. package/dist/node_modules/@allyhub/dev-server/dist/writer.js +3 -3
  91. package/dist/node_modules/@allyhub/dev-server/package.json +1 -1
  92. package/dist/node_modules/@allyhub/diagnostics/dist/rules.js +1 -1
  93. package/dist/node_modules/@allyhub/diagnostics/package.json +1 -1
  94. package/dist/node_modules/@allyhub/doc/dist/blocks.js +2 -0
  95. package/dist/node_modules/@allyhub/doc/dist/chart.js +1 -1
  96. package/dist/node_modules/@allyhub/doc/dist/color.js +1 -1
  97. package/dist/node_modules/@allyhub/doc/dist/docx-read.js +12 -0
  98. package/dist/node_modules/@allyhub/doc/dist/docx.js +5 -4
  99. package/dist/node_modules/@allyhub/doc/dist/html.js +83 -48
  100. package/dist/node_modules/@allyhub/doc/dist/index.js +1 -1
  101. package/dist/node_modules/@allyhub/doc/dist/markdown.js +1 -1
  102. package/dist/node_modules/@allyhub/doc/dist/merges.js +2 -0
  103. package/dist/node_modules/@allyhub/doc/dist/model.js +1 -1
  104. package/dist/node_modules/@allyhub/doc/dist/numbering.js +2 -0
  105. package/dist/node_modules/@allyhub/doc/dist/omml.js +3 -0
  106. package/dist/node_modules/@allyhub/doc/dist/page.js +2 -1
  107. package/dist/node_modules/@allyhub/doc/dist/paper.js +1 -1
  108. package/dist/node_modules/@allyhub/doc/dist/parse.js +5 -4
  109. package/dist/node_modules/@allyhub/doc/dist/redline.js +2 -0
  110. package/dist/node_modules/@allyhub/doc/dist/revisions.js +2 -0
  111. package/dist/node_modules/@allyhub/doc/dist/shapes.js +4 -0
  112. package/dist/node_modules/@allyhub/doc/dist/styles.js +2 -0
  113. package/dist/node_modules/@allyhub/doc/dist/table.js +1 -1
  114. package/dist/node_modules/@allyhub/doc/dist/write.js +65 -39
  115. package/dist/node_modules/@allyhub/doc/package.json +5 -1
  116. package/dist/node_modules/@allyhub/doc-extension/dist/build.js +2 -2
  117. package/dist/node_modules/@allyhub/doc-extension/dist/cli/find.js +1 -1
  118. package/dist/node_modules/@allyhub/doc-extension/dist/cli/import.js +3 -0
  119. package/dist/node_modules/@allyhub/doc-extension/dist/cli/index.js +1 -1
  120. package/dist/node_modules/@allyhub/doc-extension/dist/cli/styles.js +4 -0
  121. package/dist/node_modules/@allyhub/doc-extension/dist/export.js +1 -1
  122. package/dist/node_modules/@allyhub/doc-extension/dist/inspect.js +1 -1
  123. package/dist/node_modules/@allyhub/doc-extension/dist/project-tools.js +1 -1
  124. package/dist/node_modules/@allyhub/doc-extension/dist/tools.js +1 -1
  125. package/dist/node_modules/@allyhub/doc-extension/package.json +22 -2
  126. package/dist/node_modules/@allyhub/doc-print/dist/drawn.js +4 -4
  127. package/dist/node_modules/@allyhub/doc-print/dist/index.js +1 -1
  128. package/dist/node_modules/@allyhub/doc-print/dist/layout.js +8 -7
  129. package/dist/node_modules/@allyhub/doc-print/dist/print.js +22 -16
  130. package/dist/node_modules/@allyhub/doc-print/package.json +1 -1
  131. package/dist/node_modules/@allyhub/export/dist/export.js +1 -1
  132. package/dist/node_modules/@allyhub/export/package.json +1 -1
  133. package/dist/node_modules/@allyhub/extension-api/package.json +1 -1
  134. package/dist/node_modules/@allyhub/extension-host/dist/points.js +1 -1
  135. package/dist/node_modules/@allyhub/extension-host/package.json +1 -1
  136. package/dist/node_modules/@allyhub/formats/dist/data/blocks-flow.js +2 -0
  137. package/dist/node_modules/@allyhub/formats/dist/data/blocks.d.ts +146 -0
  138. package/dist/node_modules/@allyhub/formats/dist/data/blocks.js +2 -0
  139. package/dist/node_modules/@allyhub/formats/dist/data/cell-styles.d.ts +9 -0
  140. package/dist/node_modules/@allyhub/formats/dist/data/cell-styles.js +2 -0
  141. package/dist/node_modules/@allyhub/formats/dist/data/deck-code.d.ts +47 -40
  142. package/dist/node_modules/@allyhub/formats/dist/data/deck-code.js +1 -1
  143. package/dist/node_modules/@allyhub/formats/dist/data/diagram-kinds.d.ts +6 -0
  144. package/dist/node_modules/@allyhub/formats/dist/data/diagram-kinds.js +2 -0
  145. package/dist/node_modules/@allyhub/formats/dist/data/diagrams.d.ts +29 -0
  146. package/dist/node_modules/@allyhub/formats/dist/data/diagrams.js +2 -0
  147. package/dist/node_modules/@allyhub/formats/dist/data/faces.d.ts +18 -0
  148. package/dist/node_modules/@allyhub/formats/dist/data/faces.js +1 -1
  149. package/dist/node_modules/@allyhub/formats/dist/data/page-data.d.ts +59 -0
  150. package/dist/node_modules/@allyhub/formats/dist/data/page-data.js +2 -0
  151. package/dist/node_modules/@allyhub/formats/dist/data/reference.d.ts +1 -1
  152. package/dist/node_modules/@allyhub/formats/dist/data/sheet.d.ts +698 -258
  153. package/dist/node_modules/@allyhub/formats/dist/data/sheet.js +1 -1
  154. package/dist/node_modules/@allyhub/formats/dist/data/slides.d.ts +14104 -2167
  155. package/dist/node_modules/@allyhub/formats/dist/data/slides.js +1 -1
  156. package/dist/node_modules/@allyhub/formats/dist/data/themes.d.ts +82 -0
  157. package/dist/node_modules/@allyhub/formats/dist/data/themes.js +2 -0
  158. package/dist/node_modules/@allyhub/formats/dist/data/tokens.d.ts +67 -0
  159. package/dist/node_modules/@allyhub/formats/dist/data/tokens.js +2 -0
  160. package/dist/node_modules/@allyhub/formats/dist/data/work.d.ts +42 -0
  161. package/dist/node_modules/@allyhub/formats/dist/data/work.js +1 -1
  162. package/dist/node_modules/@allyhub/formats/dist/index.d.ts +7 -0
  163. package/dist/node_modules/@allyhub/formats/dist/index.js +1 -1
  164. package/dist/node_modules/@allyhub/formats/dist/items.d.ts +12 -3
  165. package/dist/node_modules/@allyhub/formats/dist/schemas.d.ts +3260 -290
  166. package/dist/node_modules/@allyhub/formats/dist/schemas.js +1 -1
  167. package/dist/node_modules/@allyhub/formats/dist/tolerant.d.ts +45 -0
  168. package/dist/node_modules/@allyhub/formats/dist/tolerant.js +2 -0
  169. package/dist/node_modules/@allyhub/formats/package.json +1 -1
  170. package/dist/node_modules/@allyhub/html-extension/dist/project-tools.js +21 -9
  171. package/dist/node_modules/@allyhub/html-extension/dist/tools.js +1 -1
  172. package/dist/node_modules/@allyhub/html-extension/markup/allyhub.yaml +2 -0
  173. package/dist/node_modules/@allyhub/html-extension/markup/markup.json +14 -4
  174. package/dist/node_modules/@allyhub/html-extension/markup/pages/budget.html +22 -1
  175. package/dist/node_modules/@allyhub/html-extension/package.json +9 -1
  176. package/dist/node_modules/@allyhub/i18n/package.json +1 -1
  177. package/dist/node_modules/@allyhub/image-draw/dist/fonts.js +1 -1
  178. package/dist/node_modules/@allyhub/image-draw/dist/inspect.js +2 -2
  179. package/dist/node_modules/@allyhub/image-draw/package.json +1 -1
  180. package/dist/node_modules/@allyhub/image-extension/dist/build-plugins.js +1 -1
  181. package/dist/node_modules/@allyhub/image-extension/dist/cli.js +1 -1
  182. package/dist/node_modules/@allyhub/image-extension/package.json +2 -2
  183. package/dist/node_modules/@allyhub/image-extension/skills/allyhub/references/images.md +1 -1
  184. package/dist/node_modules/@allyhub/image-measure/dist/layout.js +2 -2
  185. package/dist/node_modules/@allyhub/image-measure/package.json +1 -1
  186. package/dist/node_modules/@allyhub/image-psd/package.json +1 -1
  187. package/dist/node_modules/@allyhub/image-render/package.json +1 -1
  188. package/dist/node_modules/@allyhub/image-runtime/package.json +1 -1
  189. package/dist/node_modules/@allyhub/image-sdk/dist/block.js +2 -0
  190. package/dist/node_modules/@allyhub/image-sdk/dist/blocks.js +2 -0
  191. package/dist/node_modules/@allyhub/image-sdk/dist/index.js +1 -1
  192. package/dist/node_modules/@allyhub/image-sdk/package.json +1 -1
  193. package/dist/node_modules/@allyhub/jobs/package.json +1 -1
  194. package/dist/node_modules/@allyhub/linkedin-extension/package.json +1 -3
  195. package/dist/node_modules/@allyhub/linkedin-extension/skills/allyhub/references/linkedin.md +3 -3
  196. package/dist/node_modules/@allyhub/linkedin-model/package.json +1 -1
  197. package/dist/node_modules/@allyhub/linkedin-view/package.json +1 -1
  198. package/dist/node_modules/@allyhub/measure/package.json +1 -1
  199. package/dist/node_modules/@allyhub/media/package.json +1 -1
  200. package/dist/node_modules/@allyhub/media-extension/dist/analyses/faces.js +1 -1
  201. package/dist/node_modules/@allyhub/media-extension/dist/asr/transcribe.js +1 -1
  202. package/dist/node_modules/@allyhub/media-extension/dist/ocr/text.js +1 -1
  203. package/dist/node_modules/@allyhub/media-extension/dist/vision/faces.js +1 -1
  204. package/dist/node_modules/@allyhub/media-extension/dist/vision/index-media.js +3 -2
  205. package/dist/node_modules/@allyhub/media-extension/package.json +1 -1
  206. package/dist/node_modules/@allyhub/model/package.json +1 -1
  207. package/dist/node_modules/@allyhub/office-extension/markup/csv/allyhub.yaml +2 -0
  208. package/dist/node_modules/@allyhub/office-extension/markup/csv/markup.json +1 -1
  209. package/dist/node_modules/@allyhub/office-extension/markup/document/allyhub.yaml +2 -0
  210. package/dist/node_modules/@allyhub/office-extension/markup/presentation/allyhub.yaml +2 -0
  211. package/dist/node_modules/@allyhub/office-extension/markup/workbook/allyhub.yaml +2 -0
  212. package/dist/node_modules/@allyhub/office-extension/markup/workbook/markup.json +1 -1
  213. package/dist/node_modules/@allyhub/office-extension/package.json +1 -1
  214. package/dist/node_modules/@allyhub/ooxml/dist/ext.js +1 -1
  215. package/dist/node_modules/@allyhub/ooxml/dist/mce.js +1 -1
  216. package/dist/node_modules/@allyhub/ooxml/dist/node.js +1 -1
  217. package/dist/node_modules/@allyhub/ooxml/dist/ns.js +1 -1
  218. package/dist/node_modules/@allyhub/ooxml/dist/opc.js +1 -1
  219. package/dist/node_modules/@allyhub/ooxml/package.json +1 -1
  220. package/dist/node_modules/@allyhub/piece/dist/export.d.ts +1 -1
  221. package/dist/node_modules/@allyhub/piece/dist/layout.d.ts +2 -0
  222. package/dist/node_modules/@allyhub/piece/dist/look.d.ts +10 -2
  223. package/dist/node_modules/@allyhub/piece/dist/look.js +1 -1
  224. package/dist/node_modules/@allyhub/piece/dist/media.d.ts +8 -2
  225. package/dist/node_modules/@allyhub/piece/dist/script.js +1 -1
  226. package/dist/node_modules/@allyhub/piece/dist/source.d.ts +3 -0
  227. package/dist/node_modules/@allyhub/piece/package.json +1 -1
  228. package/dist/node_modules/@allyhub/project/dist/media-index.js +1 -1
  229. package/dist/node_modules/@allyhub/project/package.json +1 -1
  230. package/dist/node_modules/@allyhub/protocol/dist/cli.js +1 -1
  231. package/dist/node_modules/@allyhub/protocol/dist/cloud.js +1 -1
  232. package/dist/node_modules/@allyhub/protocol/dist/events.js +1 -1
  233. package/dist/node_modules/@allyhub/protocol/dist/index.js +1 -1
  234. package/dist/node_modules/@allyhub/protocol/dist/kinds.js +1 -1
  235. package/dist/node_modules/@allyhub/protocol/dist/page-frame.js +2 -0
  236. package/dist/node_modules/@allyhub/protocol/package.json +1 -1
  237. package/dist/node_modules/@allyhub/registry/package.json +1 -1
  238. package/dist/node_modules/@allyhub/render/package.json +1 -1
  239. package/dist/node_modules/@allyhub/runtime/dist/footage.js +1 -1
  240. package/dist/node_modules/@allyhub/runtime/package.json +1 -1
  241. package/dist/node_modules/@allyhub/runtimes/dist/packages.js +2 -2
  242. package/dist/node_modules/@allyhub/runtimes/dist/runtimes.js +3 -3
  243. package/dist/node_modules/@allyhub/runtimes/package.json +1 -1
  244. package/dist/node_modules/@allyhub/scaffold/dist/index.js +12 -8
  245. package/dist/node_modules/@allyhub/scaffold/package.json +1 -1
  246. package/dist/node_modules/@allyhub/scenery/package.json +1 -1
  247. package/dist/node_modules/@allyhub/scenery-host/package.json +1 -1
  248. package/dist/node_modules/@allyhub/sheet/dist/api/capabilities.js +1 -1
  249. package/dist/node_modules/@allyhub/sheet/dist/api/charts.js +1 -1
  250. package/dist/node_modules/@allyhub/sheet/dist/api/index.js +1 -1
  251. package/dist/node_modules/@allyhub/sheet/dist/api/styles.js +1 -1
  252. package/dist/node_modules/@allyhub/sheet/dist/api/workbook.js +1 -1
  253. package/dist/node_modules/@allyhub/sheet/dist/calc/engine.js +1 -1
  254. package/dist/node_modules/@allyhub/sheet/dist/calc/server.js +1 -1
  255. package/dist/node_modules/@allyhub/sheet/dist/cell-styles.js +2 -0
  256. package/dist/node_modules/@allyhub/sheet/dist/chart.js +1 -1
  257. package/dist/node_modules/@allyhub/sheet/dist/check.js +1 -1
  258. package/dist/node_modules/@allyhub/sheet/dist/file.js +2 -2
  259. package/dist/node_modules/@allyhub/sheet/dist/heatmap.js +2 -0
  260. package/dist/node_modules/@allyhub/sheet/dist/html.js +10 -10
  261. package/dist/node_modules/@allyhub/sheet/dist/index.js +1 -1
  262. package/dist/node_modules/@allyhub/sheet/dist/inspect.js +1 -1
  263. package/dist/node_modules/@allyhub/sheet/dist/paginate.js +1 -1
  264. package/dist/node_modules/@allyhub/sheet/dist/printed.js +1 -1
  265. package/dist/node_modules/@allyhub/sheet/dist/sdk.js +1 -1
  266. package/dist/node_modules/@allyhub/sheet/dist/sparklines.js +2 -0
  267. package/dist/node_modules/@allyhub/sheet/dist/table-style.js +1 -1
  268. package/dist/node_modules/@allyhub/sheet/dist/table-styles.js +1 -1
  269. package/dist/node_modules/@allyhub/sheet/dist/theme.js +2 -0
  270. package/dist/node_modules/@allyhub/sheet/dist/tiles.js +2 -0
  271. package/dist/node_modules/@allyhub/sheet/dist/units.js +2 -0
  272. package/dist/node_modules/@allyhub/sheet/dist/workbook.js +1 -1
  273. package/dist/node_modules/@allyhub/sheet/dist/write.js +14 -14
  274. package/dist/node_modules/@allyhub/sheet/dist/xlsx/charts.js +1 -1
  275. package/dist/node_modules/@allyhub/sheet/dist/xlsx/import.js +1 -1
  276. package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.js +2 -2
  277. package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.js +1 -1
  278. package/dist/node_modules/@allyhub/sheet/dist/xlsx/theme.js +1 -1
  279. package/dist/node_modules/@allyhub/sheet/dist/xlsx/write.js +1 -1
  280. package/dist/node_modules/@allyhub/sheet/package.json +1 -1
  281. package/dist/node_modules/@allyhub/sheet-extension/dist/build.js +1 -1
  282. package/dist/node_modules/@allyhub/sheet-extension/dist/cli/sheet.js +7 -7
  283. package/dist/node_modules/@allyhub/sheet-extension/dist/code.js +1 -1
  284. package/dist/node_modules/@allyhub/sheet-extension/dist/evaluate.js +2 -2
  285. package/dist/node_modules/@allyhub/sheet-extension/dist/export.js +2 -2
  286. package/dist/node_modules/@allyhub/sheet-extension/dist/inspect.js +2 -2
  287. package/dist/node_modules/@allyhub/sheet-extension/dist/migrations.js +4 -0
  288. package/dist/node_modules/@allyhub/sheet-extension/dist/project-tools.js +1 -1
  289. package/dist/node_modules/@allyhub/sheet-extension/dist/tools.js +1 -1
  290. package/dist/node_modules/@allyhub/sheet-extension/package.json +7 -3
  291. package/dist/node_modules/@allyhub/slides-core/dist/api.js +2 -2
  292. package/dist/node_modules/@allyhub/slides-core/dist/blocks.js +2 -0
  293. package/dist/node_modules/@allyhub/slides-core/dist/capabilities.js +1 -1
  294. package/dist/node_modules/@allyhub/slides-core/dist/chart-api.js +1 -1
  295. package/dist/node_modules/@allyhub/slides-core/dist/code.js +1 -1
  296. package/dist/node_modules/@allyhub/slides-core/dist/enums.js +1 -1
  297. package/dist/node_modules/@allyhub/slides-core/dist/file.js +3 -3
  298. package/dist/node_modules/@allyhub/slides-core/dist/index.js +1 -1
  299. package/dist/node_modules/@allyhub/slides-core/dist/measure.js +1 -1
  300. package/dist/node_modules/@allyhub/slides-core/dist/model.js +1 -1
  301. package/dist/node_modules/@allyhub/slides-core/dist/office-layouts.js +2 -0
  302. package/dist/node_modules/@allyhub/slides-core/dist/office.js +1 -1
  303. package/dist/node_modules/@allyhub/slides-core/dist/resolve.js +1 -1
  304. package/dist/node_modules/@allyhub/slides-core/dist/script.js +2 -2
  305. package/dist/node_modules/@allyhub/slides-core/dist/styles/brief.js +2 -0
  306. package/dist/node_modules/@allyhub/slides-core/dist/styles/editorial.js +2 -0
  307. package/dist/node_modules/@allyhub/slides-core/dist/styles/index.js +2 -0
  308. package/dist/node_modules/@allyhub/slides-core/dist/styles/kit.js +2 -0
  309. package/dist/node_modules/@allyhub/slides-core/dist/styles/layouts.js +2 -0
  310. package/dist/node_modules/@allyhub/slides-core/dist/styles/pitch.js +2 -0
  311. package/dist/node_modules/@allyhub/slides-core/dist/styles/stage.js +2 -0
  312. package/dist/node_modules/@allyhub/slides-core/dist/styles/tiles.js +2 -0
  313. package/dist/node_modules/@allyhub/slides-core/dist/theme.js +1 -1
  314. package/dist/node_modules/@allyhub/slides-core/dist/units.js +1 -1
  315. package/dist/node_modules/@allyhub/slides-core/package.json +1 -1
  316. package/dist/node_modules/@allyhub/slides-extension/dist/check.js +1 -1
  317. package/dist/node_modules/@allyhub/slides-extension/dist/cli/slides.js +2 -2
  318. package/dist/node_modules/@allyhub/slides-extension/dist/deck-fonts.js +1 -1
  319. package/dist/node_modules/@allyhub/slides-extension/dist/project-tools.js +1 -1
  320. package/dist/node_modules/@allyhub/slides-extension/package.json +24 -1
  321. package/dist/node_modules/@allyhub/slides-pptx/dist/charts.js +1 -1
  322. package/dist/node_modules/@allyhub/slides-pptx/dist/fonts.js +1 -1
  323. package/dist/node_modules/@allyhub/slides-pptx/dist/image-size.js +2 -0
  324. package/dist/node_modules/@allyhub/slides-pptx/dist/import/code.js +3 -3
  325. package/dist/node_modules/@allyhub/slides-pptx/dist/import/index.js +7 -2
  326. package/dist/node_modules/@allyhub/slides-pptx/dist/import/names.js +1 -1
  327. package/dist/node_modules/@allyhub/slides-pptx/dist/import/script.js +1 -1
  328. package/dist/node_modules/@allyhub/slides-pptx/dist/index.js +1 -1
  329. package/dist/node_modules/@allyhub/slides-pptx/dist/mtx.js +2 -0
  330. package/dist/node_modules/@allyhub/slides-pptx/dist/read/chart.js +3 -2
  331. package/dist/node_modules/@allyhub/slides-pptx/dist/read/chartex.js +3 -0
  332. package/dist/node_modules/@allyhub/slides-pptx/dist/read/common.js +1 -1
  333. package/dist/node_modules/@allyhub/slides-pptx/dist/read/index.js +2 -2
  334. package/dist/node_modules/@allyhub/slides-pptx/dist/read/shapes.js +1 -1
  335. package/dist/node_modules/@allyhub/slides-pptx/dist/read/table.js +1 -1
  336. package/dist/node_modules/@allyhub/slides-pptx/dist/read/text.js +1 -1
  337. package/dist/node_modules/@allyhub/slides-pptx/dist/read/timing.js +1 -1
  338. package/dist/node_modules/@allyhub/slides-pptx/dist/shapes.js +1 -1
  339. package/dist/node_modules/@allyhub/slides-pptx/dist/text.js +1 -1
  340. package/dist/node_modules/@allyhub/slides-pptx/dist/write.js +2 -2
  341. package/dist/node_modules/@allyhub/slides-pptx/dist/xml.js +3 -2
  342. package/dist/node_modules/@allyhub/slides-pptx/package.json +1 -1
  343. package/dist/node_modules/@allyhub/slides-runtime/dist/draw.js +2 -2
  344. package/dist/node_modules/@allyhub/slides-runtime/dist/load.js +1 -1
  345. package/dist/node_modules/@allyhub/slides-runtime/package.json +1 -1
  346. package/dist/node_modules/@allyhub/stage/package.json +1 -1
  347. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/LICENSE +93 -0
  348. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/files/archivo-latin-400-italic.woff2 +0 -0
  349. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/files/archivo-latin-400-normal.woff2 +0 -0
  350. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/files/archivo-latin-700-italic.woff2 +0 -0
  351. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/files/archivo-latin-700-normal.woff2 +0 -0
  352. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/files/archivo-latin-ext-400-italic.woff2 +0 -0
  353. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/files/archivo-latin-ext-400-normal.woff2 +0 -0
  354. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/files/archivo-latin-ext-700-italic.woff2 +0 -0
  355. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/files/archivo-latin-ext-700-normal.woff2 +0 -0
  356. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/latin-400-italic.css +1 -0
  357. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/latin-400.css +1 -0
  358. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/latin-700-italic.css +1 -0
  359. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/latin-700.css +1 -0
  360. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/latin-ext-400-italic.css +1 -0
  361. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/latin-ext-400.css +1 -0
  362. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/latin-ext-700-italic.css +1 -0
  363. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo/latin-ext-700.css +1 -0
  364. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo-black/LICENSE +93 -0
  365. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo-black/files/archivo-black-latin-400-normal.woff2 +0 -0
  366. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo-black/files/archivo-black-latin-ext-400-normal.woff2 +0 -0
  367. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo-black/latin-400.css +1 -0
  368. package/dist/node_modules/@allyhub/stage-page/dist/fonts/archivo-black/latin-ext-400.css +1 -0
  369. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/LICENSE +93 -0
  370. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/files/ibm-plex-sans-latin-400-italic.woff2 +0 -0
  371. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/files/ibm-plex-sans-latin-400-normal.woff2 +0 -0
  372. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/files/ibm-plex-sans-latin-700-italic.woff2 +0 -0
  373. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/files/ibm-plex-sans-latin-700-normal.woff2 +0 -0
  374. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/files/ibm-plex-sans-latin-ext-400-italic.woff2 +0 -0
  375. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/files/ibm-plex-sans-latin-ext-400-normal.woff2 +0 -0
  376. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/files/ibm-plex-sans-latin-ext-700-italic.woff2 +0 -0
  377. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/files/ibm-plex-sans-latin-ext-700-normal.woff2 +0 -0
  378. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/latin-400-italic.css +1 -0
  379. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/latin-400.css +1 -0
  380. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/latin-700-italic.css +1 -0
  381. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/latin-700.css +1 -0
  382. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/latin-ext-400-italic.css +1 -0
  383. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/latin-ext-400.css +1 -0
  384. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/latin-ext-700-italic.css +1 -0
  385. package/dist/node_modules/@allyhub/stage-page/dist/fonts/ibm-plex-sans/latin-ext-700.css +1 -0
  386. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/LICENSE +93 -0
  387. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/files/inter-latin-400-italic.woff2 +0 -0
  388. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/files/inter-latin-400-normal.woff2 +0 -0
  389. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/files/inter-latin-700-italic.woff2 +0 -0
  390. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/files/inter-latin-700-normal.woff2 +0 -0
  391. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/files/inter-latin-ext-400-italic.woff2 +0 -0
  392. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/files/inter-latin-ext-400-normal.woff2 +0 -0
  393. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/files/inter-latin-ext-700-italic.woff2 +0 -0
  394. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/files/inter-latin-ext-700-normal.woff2 +0 -0
  395. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/latin-400-italic.css +1 -0
  396. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/latin-400.css +1 -0
  397. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/latin-700-italic.css +1 -0
  398. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/latin-700.css +1 -0
  399. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/latin-ext-400-italic.css +1 -0
  400. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/latin-ext-400.css +1 -0
  401. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/latin-ext-700-italic.css +1 -0
  402. package/dist/node_modules/@allyhub/stage-page/dist/fonts/inter-static/latin-ext-700.css +1 -0
  403. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/LICENSE +93 -0
  404. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/files/newsreader-latin-400-italic.woff2 +0 -0
  405. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/files/newsreader-latin-400-normal.woff2 +0 -0
  406. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/files/newsreader-latin-700-italic.woff2 +0 -0
  407. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/files/newsreader-latin-700-normal.woff2 +0 -0
  408. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/files/newsreader-latin-ext-400-italic.woff2 +0 -0
  409. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/files/newsreader-latin-ext-400-normal.woff2 +0 -0
  410. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/files/newsreader-latin-ext-700-italic.woff2 +0 -0
  411. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/files/newsreader-latin-ext-700-normal.woff2 +0 -0
  412. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/latin-400-italic.css +1 -0
  413. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/latin-400.css +1 -0
  414. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/latin-700-italic.css +1 -0
  415. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/latin-700.css +1 -0
  416. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/latin-ext-400-italic.css +1 -0
  417. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/latin-ext-400.css +1 -0
  418. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/latin-ext-700-italic.css +1 -0
  419. package/dist/node_modules/@allyhub/stage-page/dist/fonts/newsreader/latin-ext-700.css +1 -0
  420. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/LICENSE +93 -0
  421. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/files/plus-jakarta-sans-latin-400-italic.woff2 +0 -0
  422. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/files/plus-jakarta-sans-latin-400-normal.woff2 +0 -0
  423. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/files/plus-jakarta-sans-latin-700-italic.woff2 +0 -0
  424. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/files/plus-jakarta-sans-latin-700-normal.woff2 +0 -0
  425. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/files/plus-jakarta-sans-latin-ext-400-italic.woff2 +0 -0
  426. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/files/plus-jakarta-sans-latin-ext-400-normal.woff2 +0 -0
  427. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/files/plus-jakarta-sans-latin-ext-700-italic.woff2 +0 -0
  428. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/files/plus-jakarta-sans-latin-ext-700-normal.woff2 +0 -0
  429. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/latin-400-italic.css +1 -0
  430. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/latin-400.css +1 -0
  431. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/latin-700-italic.css +1 -0
  432. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/latin-700.css +1 -0
  433. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/latin-ext-400-italic.css +1 -0
  434. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/latin-ext-400.css +1 -0
  435. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/latin-ext-700-italic.css +1 -0
  436. package/dist/node_modules/@allyhub/stage-page/dist/fonts/plus-jakarta-sans/latin-ext-700.css +1 -0
  437. package/dist/node_modules/@allyhub/stage-page/dist/host.js +1 -1
  438. package/dist/node_modules/@allyhub/stage-page/dist/runtime/stage.html +42 -0
  439. package/dist/node_modules/@allyhub/stage-page/dist/style-faces.js +2 -0
  440. package/dist/node_modules/@allyhub/stage-page/package.json +1 -1
  441. package/dist/node_modules/@allyhub/stage-runtime/dist/runtime.js +96 -92
  442. package/dist/node_modules/@allyhub/stage-runtime/package.json +1 -1
  443. package/dist/node_modules/@allyhub/telemetry/dist/limit.js +2 -0
  444. package/dist/node_modules/@allyhub/telemetry/package.json +5 -1
  445. package/dist/node_modules/@allyhub/text-extension/markup/allyhub.yaml +2 -0
  446. package/dist/node_modules/@allyhub/text-extension/markup-file/allyhub.yaml +2 -0
  447. package/dist/node_modules/@allyhub/text-extension/package.json +1 -1
  448. package/dist/node_modules/@allyhub/video-core/dist/footage-motion.js +1 -1
  449. package/dist/node_modules/@allyhub/video-core/dist/measure.js +1 -1
  450. package/dist/node_modules/@allyhub/video-core/dist/seams.js +1 -1
  451. package/dist/node_modules/@allyhub/video-core/package.json +1 -1
  452. package/dist/node_modules/@allyhub/video-extension/dist/cli/reference-text.js +1 -1
  453. package/dist/node_modules/@allyhub/video-extension/dist/inspect/index.js +1 -1
  454. package/dist/node_modules/@allyhub/video-extension/dist/inspect/joins.js +1 -1
  455. package/dist/node_modules/@allyhub/video-extension/dist/inspect/loop.js +3 -0
  456. package/dist/node_modules/@allyhub/video-extension/package.json +2 -25
  457. package/dist/node_modules/@allyhub/video-measure/dist/check.js +2 -2
  458. package/dist/node_modules/@allyhub/video-measure/dist/index.js +1 -1
  459. package/dist/node_modules/@allyhub/video-measure/dist/seams.js +1 -1
  460. package/dist/node_modules/@allyhub/video-measure/dist/version.js +1 -1
  461. package/dist/node_modules/@allyhub/video-measure/package.json +1 -1
  462. package/dist/node_modules/@allyhub/video-sdk/dist/free.js +1 -1
  463. package/dist/node_modules/@allyhub/video-sdk/package.json +1 -1
  464. package/dist/node_modules/@allyhub/website/dist/index.js +1 -1
  465. package/dist/node_modules/@allyhub/website/dist/website.js +2 -2
  466. package/dist/node_modules/@allyhub/website/package.json +1 -1
  467. package/dist/node_modules/@allyhub/website-extension/package.json +3 -3
  468. package/dist/node_modules/@allyhub/x-extension/package.json +1 -3
  469. package/dist/node_modules/@allyhub/x-extension/skills/allyhub/references/x.md +3 -3
  470. package/dist/node_modules/@allyhub/x-model/package.json +1 -1
  471. package/dist/node_modules/@allyhub/x-view/package.json +1 -1
  472. package/dist/package.json +14 -14
  473. package/dist/self-upgrade.js +2 -0
  474. package/dist/text/batch-text.js +1 -1
  475. package/dist/text/facts-text.js +5 -5
  476. package/dist/text/format.js +2 -2
  477. package/dist/update-notice.js +3 -0
  478. package/dist/version.js +1 -1
  479. package/dist/works.js +1 -1
  480. package/editor-web/assets/{abnfDiagram-WEYOIA3C-DYaMS_BB.js → abnfDiagram-WEYOIA3C-BkVJMd53.js} +1 -1
  481. package/editor-web/assets/{architecture-WOLXFQ4H-g_Tjfl_y.js → architecture-WOLXFQ4H-C6rnaynZ.js} +1 -1
  482. package/editor-web/assets/{architectureDiagram-ZHVYKT53-CqdhofOL.js → architectureDiagram-ZHVYKT53-D3vrh8LK.js} +1 -1
  483. package/editor-web/assets/arrow-down-D-QZrqcz.js +1 -0
  484. package/editor-web/assets/arrow-up-B1zjKUHX.js +1 -0
  485. package/editor-web/assets/article-DHf6mOY_.js +7 -0
  486. package/editor-web/assets/article-Dns1-Xh-.js +3 -0
  487. package/editor-web/assets/{audio-lines-PZj77e7t.js → audio-lines-BFoW_IeO.js} +1 -1
  488. package/editor-web/assets/bar-button-CKPfx2AB.js +1 -0
  489. package/editor-web/assets/{blockDiagram-RJAE7QA3-Bc-28Bci.js → blockDiagram-RJAE7QA3-BKngt8H7.js} +1 -1
  490. package/editor-web/assets/{browser-C9NP0ZYz.js → browser-DEGNhKTV.js} +1 -1
  491. package/editor-web/assets/{c4Diagram-XDPPPE54-CTGJb8FB.js → c4Diagram-XDPPPE54-j7sUELqF.js} +1 -1
  492. package/editor-web/assets/calc-worker-Cr4a0xmt.js +168 -0
  493. package/editor-web/assets/channel-CVWSV3su.js +1 -0
  494. package/editor-web/assets/{chart-no-axes-column-Be0lFcGF.js → chart-no-axes-column-Dyy25XZ_.js} +1 -1
  495. package/editor-web/assets/chip-Bn_9JRRG.js +1 -0
  496. package/editor-web/assets/{chunk-2E7WHVMD-B2MPOVTU.js → chunk-2E7WHVMD-BXa-uRSi.js} +1 -1
  497. package/editor-web/assets/{chunk-4EMNKR2T-BUV1ZHP0.js → chunk-4EMNKR2T-B3ntcsZN.js} +1 -1
  498. package/editor-web/assets/{chunk-55XCU76K-BZlpspL5.js → chunk-55XCU76K-AMvnFwUg.js} +1 -1
  499. package/editor-web/assets/{chunk-7S6XSTFO-CpKeisWE.js → chunk-7S6XSTFO-BA6esfFu.js} +1 -1
  500. package/editor-web/assets/{chunk-AQDTSKZB-BJqwAPyo.js → chunk-AQDTSKZB-BT_vANXs.js} +1 -1
  501. package/editor-web/assets/{chunk-DSNLSHJZ-D6oPWl_W.js → chunk-DSNLSHJZ-DoUgmzGB.js} +1 -1
  502. package/editor-web/assets/{chunk-HAGFOTED-B5pk4MZF.js → chunk-HAGFOTED-DtnIrCZb.js} +1 -1
  503. package/editor-web/assets/{chunk-HNE4Q36P-DHbSPvxQ.js → chunk-HNE4Q36P-BlPwQx3_.js} +1 -1
  504. package/editor-web/assets/{chunk-NQOKRVIF-CcL_GcRA.js → chunk-NQOKRVIF-D2r7jp2r.js} +1 -1
  505. package/editor-web/assets/{chunk-UHW7PFBP-YgiOL6XE.js → chunk-UHW7PFBP-Cmc0_F5o.js} +1 -1
  506. package/editor-web/assets/{chunk-VQ5W62QI-p14b4UYc.js → chunk-VQ5W62QI-nJSMqAr0.js} +1 -1
  507. package/editor-web/assets/{chunk-WQQL4CDK-BWW0x-XH.js → chunk-WQQL4CDK-Btq2nbF6.js} +1 -1
  508. package/editor-web/assets/{chunk-YZO67HFG-oG3qd68C.js → chunk-YZO67HFG-DTbcCoGt.js} +1 -1
  509. package/editor-web/assets/{chunk-ZAUX2LTX-CpcheH0u.js → chunk-ZAUX2LTX-DVwkg-2N.js} +1 -1
  510. package/editor-web/assets/{chunk-ZCHMQSOR-cWQvLl1w.js → chunk-ZCHMQSOR-BV39jOOE.js} +1 -1
  511. package/editor-web/assets/{classDiagram-v2-4MYWR3UA-7PG7YcdU.js → classDiagram-v2-4MYWR3UA-Cj74-fhM.js} +1 -1
  512. package/editor-web/assets/code-Ch6AB5bZ.js +1 -0
  513. package/editor-web/assets/collaborator-XiHOxwGM.js +1 -0
  514. package/editor-web/assets/{copy-CuJSs0nI.js → copy-SoaMYqsN.js} +1 -1
  515. package/editor-web/assets/{createLucideIcon-lm_6n8YT.js → createLucideIcon-euu7Wcd9.js} +1 -1
  516. package/editor-web/assets/{cynefin-EF2NZ3EQ-CtcknEQ_.js → cynefin-EF2NZ3EQ-C0CkiipV.js} +1 -1
  517. package/editor-web/assets/{cynefinDiagram-WF24UDRP-Ca7VIsjN.js → cynefinDiagram-WF24UDRP-hdsnJ4cI.js} +1 -1
  518. package/editor-web/assets/{dagre-NK4GIZVX-BzcSLtsr.js → dagre-NK4GIZVX-CC7WSgaK.js} +1 -1
  519. package/editor-web/assets/deck-DQpNIS2p.js +1 -0
  520. package/editor-web/assets/{diagram-CBK3MWTC-DpRmTGlG.js → diagram-CBK3MWTC-DmaVm13J.js} +1 -1
  521. package/editor-web/assets/{diagram-I5XIIV2D-BTrs_AX8.js → diagram-I5XIIV2D-De8jqp7b.js} +1 -1
  522. package/editor-web/assets/{diagram-ODIL2UCW-CkIVjPqH.js → diagram-ODIL2UCW-B5pBTulX.js} +1 -1
  523. package/editor-web/assets/{diagram-PFBEJUXE-BlFMbAG1.js → diagram-PFBEJUXE-BYsXg5_w.js} +1 -1
  524. package/editor-web/assets/{diagram-RJA3I4VV-D3f8VJ-D.js → diagram-RJA3I4VV-DZ8f6bYe.js} +1 -1
  525. package/editor-web/assets/{diagram-TYUNFSNR-Bbpngj6F.js → diagram-TYUNFSNR-qXHUsauD.js} +1 -1
  526. package/editor-web/assets/dist--z0ZHp4T.js +16 -0
  527. package/editor-web/assets/dist-9kuRjUTN.js +41 -0
  528. package/editor-web/assets/dist-B3rd02Cg.js +6 -0
  529. package/editor-web/assets/dist-B5GOGGEe.js +1 -0
  530. package/editor-web/assets/dist-Bx6q9kCu.js +1 -0
  531. package/editor-web/assets/dist-C4hHtrJr.js +1 -0
  532. package/editor-web/assets/dist-CCXJewsi.js +19 -0
  533. package/editor-web/assets/dist-CfK2BLl8.js +4 -0
  534. package/editor-web/assets/dist-Cmux3oJ_.js +1 -0
  535. package/editor-web/assets/dist-Cspf85KV.js +6 -0
  536. package/editor-web/assets/dist-DA72-4WB.js +82 -0
  537. package/editor-web/assets/{dist-DruvDNQe.js → dist-DAhe-kFC.js} +5 -5
  538. package/editor-web/assets/dist-DIJnhQFK.js +9 -0
  539. package/editor-web/assets/dist-DOrGo1GD.js +19 -0
  540. package/editor-web/assets/{dist-Bd8IxQPP.js → dist-DQ6RpEJD.js} +2 -2
  541. package/editor-web/assets/dist-DjiCHlSu.js +35 -0
  542. package/editor-web/assets/dist-Do4a40Wn.js +19 -0
  543. package/editor-web/assets/dist-FKEWS3Co.js +547 -0
  544. package/editor-web/assets/dist-QKd2i6kG.js +5 -0
  545. package/editor-web/assets/dist-SGnOfLhx.js +24 -0
  546. package/editor-web/assets/dist-VmVB7tl4.js +3 -0
  547. package/editor-web/assets/{docx-draw-CoK1oqQD.js → docx-draw-L54blreB.js} +1 -1
  548. package/editor-web/assets/{ebnfDiagram-V4P3TTPT-BaKj-yL6.js → ebnfDiagram-V4P3TTPT-B7-IfVI-.js} +1 -1
  549. package/editor-web/assets/{elk-QONTBCTQ-Cn2qv1_U.js → elk-QONTBCTQ-Gj_WaeBn.js} +1 -1
  550. package/editor-web/assets/{erDiagram-KYQIGQAA-Bd7AEIDo.js → erDiagram-KYQIGQAA-BDF6Qoqx.js} +1 -1
  551. package/editor-web/assets/esm-PQD5Pn8a.js +21 -0
  552. package/editor-web/assets/{eventmodeling-K75KTNOO-Sfp7_461.js → eventmodeling-K75KTNOO-elxVXXEe.js} +1 -1
  553. package/editor-web/assets/{file-question-mark-DlIjUK37.js → file-question-mark-PeZgyqkK.js} +1 -1
  554. package/editor-web/assets/flowDiagram-IUGLLWBU-B-25n8zE.js +1 -0
  555. package/editor-web/assets/{ganttDiagram-R7GPNTJY-CBqcGdHI.js → ganttDiagram-R7GPNTJY-CEogW3jW.js} +1 -1
  556. package/editor-web/assets/{gitGraph-VSP46ZUC-WTokXKTW.js → gitGraph-VSP46ZUC-Bh9cRWFa.js} +1 -1
  557. package/editor-web/assets/{gitGraphDiagram-PDYL7XHY-BIWZHD9q.js → gitGraphDiagram-PDYL7XHY-BQAvdM_V.js} +1 -1
  558. package/editor-web/assets/{group-BdrTp7gi.js → group-DwM2yqU8.js} +1 -1
  559. package/editor-web/assets/hint-CbwoSBMw.js +1 -0
  560. package/editor-web/assets/index-CXisi0Cj.css +2 -0
  561. package/editor-web/assets/index-wMlfx8aT.js +28 -0
  562. package/editor-web/assets/{info-OHQRW6UA-COC6G-_J.js → info-OHQRW6UA-CdPrqere.js} +1 -1
  563. package/editor-web/assets/{infoDiagram-MVDRKAX5-DpaqdKBD.js → infoDiagram-MVDRKAX5-uwIMeP44.js} +1 -1
  564. package/editor-web/assets/{ishikawaDiagram-HPEHV2GE-Dyn2MAy1.js → ishikawaDiagram-HPEHV2GE-rtfvqK7E.js} +1 -1
  565. package/editor-web/assets/iso-UwGLGD3F.js +1 -0
  566. package/editor-web/assets/{italic-zw4_eUNF.js → italic-BV7iHxoP.js} +1 -1
  567. package/editor-web/assets/{journeyDiagram-BOSHW7O7-DeSVfmm7.js → journeyDiagram-BOSHW7O7-mmhfIyVG.js} +1 -1
  568. package/editor-web/assets/{kanban-definition-FNSA4HC5-Bfg0lj7B.js → kanban-definition-FNSA4HC5-Fe7jBsi-.js} +1 -1
  569. package/editor-web/assets/{link-DopSU3aa.js → link-CFOv3nz-.js} +1 -1
  570. package/editor-web/assets/{mermaid-parser.core-CyhovuYE.js → mermaid-parser.core-BxOSjBH9.js} +3 -3
  571. package/editor-web/assets/{mermaid.core-Dx1fBVUG.js → mermaid.core-BOln9YdH.js} +4 -4
  572. package/editor-web/assets/{mindmap-definition-6OY57UG3-QEU2HF_m.js → mindmap-definition-6OY57UG3-M3Q1LOtO.js} +1 -1
  573. package/editor-web/assets/minus-ngE8owxs.js +1 -0
  574. package/editor-web/assets/{packet-JDAUHWVQ-ReJTa_hw.js → packet-JDAUHWVQ-Dbb0TUG6.js} +1 -1
  575. package/editor-web/assets/{pegDiagram-ECIUJNBX-Bo1jFrvb.js → pegDiagram-ECIUJNBX-BZMRpSFC.js} +1 -1
  576. package/editor-web/assets/{pie-XZMESJXO-BrtYafNA.js → pie-XZMESJXO-Ctm9XdKp.js} +1 -1
  577. package/editor-web/assets/{pieDiagram-GNMPY74T-Cj0zQqs_.js → pieDiagram-GNMPY74T-cGbs5ZTl.js} +1 -1
  578. package/editor-web/assets/progress-DZQTiRLv.js +6 -0
  579. package/editor-web/assets/{quadrantDiagram-D57K4MC3-D5npDAVn.js → quadrantDiagram-D57K4MC3-BUe_zsxT.js} +1 -1
  580. package/editor-web/assets/{radar-ABXABTNO-C8RDrRqi.js → radar-ABXABTNO-CCmKtqLs.js} +1 -1
  581. package/editor-web/assets/{railroad-I3PHUGI6-ebDrmYTK.js → railroad-I3PHUGI6-k-yhjhjA.js} +1 -1
  582. package/editor-web/assets/{railroad-abnf-LNEFI6M7-BxKuqg6V.js → railroad-abnf-LNEFI6M7-B-PvntB3.js} +1 -1
  583. package/editor-web/assets/{railroad-ebnf-DWYD2UWJ-DOclnfpr.js → railroad-ebnf-DWYD2UWJ-Ds2rua1h.js} +1 -1
  584. package/editor-web/assets/{railroad-peg-JR7BVNR7-DN0A1fpq.js → railroad-peg-JR7BVNR7-jNZ2wEp2.js} +1 -1
  585. package/editor-web/assets/{railroadDiagram-Y72NRBL7-B3PjoVWw.js → railroadDiagram-Y72NRBL7-CTqSQ15w.js} +1 -1
  586. package/editor-web/assets/react-Byupo4pA.js +1 -0
  587. package/editor-web/assets/replace-CLLMtF4e.js +1 -0
  588. package/editor-web/assets/{requirementDiagram-EQYSW5RA-DLdzkQk5.js → requirementDiagram-EQYSW5RA-CUblhR5M.js} +1 -1
  589. package/editor-web/assets/ribbon-DajdQ_Ya.js +1 -0
  590. package/editor-web/assets/row-Bei9HNEe.js +1 -0
  591. package/editor-web/assets/{sankeyDiagram-SY24JHO5-Dip4Piv_.js → sankeyDiagram-SY24JHO5-nSz6zDX3.js} +1 -1
  592. package/editor-web/assets/schemas-C21MyseF.js +1 -0
  593. package/editor-web/assets/{iso-DoC-ZoBr.js → schemas-DlRAoVtq.js} +1 -1
  594. package/editor-web/assets/{scissors-B_xOiUhd.js → scissors-m6QcoEf2.js} +1 -1
  595. package/editor-web/assets/search-D75Bi2GU.js +1 -0
  596. package/editor-web/assets/{sequenceDiagram-BLEHNHQU-QnPcoybL.js → sequenceDiagram-BLEHNHQU-DxTpOYuo.js} +1 -1
  597. package/editor-web/assets/{session-DMlLCFWg.js → session-BhClkDyr.js} +1 -1
  598. package/editor-web/assets/{sigma-DSUsJhMn.js → sigma-B4AWtnVA.js} +1 -1
  599. package/editor-web/assets/snapshots-DwGHDN3t.js +1 -0
  600. package/editor-web/assets/sound-DkR3qxSt.js +1 -0
  601. package/editor-web/assets/split-DBAbwPZ5.js +3 -0
  602. package/editor-web/assets/{square-arrow-out-up-right-DF5dvsSp.js → square-arrow-out-up-right-1NqFsNDe.js} +1 -1
  603. package/editor-web/assets/{stateDiagram-v2-A6IESKWZ-D103CiMX.js → stateDiagram-v2-A6IESKWZ-C3e14iHY.js} +1 -1
  604. package/editor-web/assets/{sticky-note-BdkIu5_D.js → sticky-note-s4QfzaBB.js} +1 -1
  605. package/editor-web/assets/surface-CIF0Ae0z.js +1 -0
  606. package/editor-web/assets/swatch-BUzr_XmH.js +1 -0
  607. package/editor-web/assets/{swimlanes-B3ENRKFQ-y4gCqEoa.js → swimlanes-B3ENRKFQ-DPPdzNzu.js} +1 -1
  608. package/editor-web/assets/swimlanesDiagram-AYQRV4AK-B8n3zOw_.js +8 -0
  609. package/editor-web/assets/switch-DrZxoPQS.js +1 -0
  610. package/editor-web/assets/{syntax-CU_WPKxt.js → syntax-emXV4DnN.js} +1 -1
  611. package/editor-web/assets/table-BW43XXVd.js +1 -0
  612. package/editor-web/assets/tabs-BwU2E7bU.js +1 -0
  613. package/editor-web/assets/text-wrap-Baus6l-V.js +1 -0
  614. package/editor-web/assets/textarea-BX_ax3X8.js +1 -0
  615. package/editor-web/assets/{timeline-definition-JXYKGLGB-BMp76v4V.js → timeline-definition-JXYKGLGB-DRTJ1_Er.js} +1 -1
  616. package/editor-web/assets/tolerant-DM9s0Mt1.js +1 -0
  617. package/editor-web/assets/{treeView-D4JQ5SDB-Q_GYyk0b.js → treeView-D4JQ5SDB-BYJ_m-i5.js} +1 -1
  618. package/editor-web/assets/{treemap-SAJKECNS-B5lRWdQB.js → treemap-SAJKECNS-BcU6I6Rg.js} +1 -1
  619. package/editor-web/assets/type-CvZ0HZsV.js +41 -0
  620. package/editor-web/assets/{undo-2-C47jrRp5.js → undo-2-DCbMWoug.js} +1 -1
  621. package/editor-web/assets/{usecaseDiagram-WPOLBNNX--QRllA-U.js → usecaseDiagram-WPOLBNNX-YV92pS4o.js} +1 -1
  622. package/editor-web/assets/{vennDiagram-Q3Y3IDCW-CzkATPA3.js → vennDiagram-Q3Y3IDCW-oAvfHZtf.js} +1 -1
  623. package/editor-web/assets/video-SJvDRCJK.js +1 -0
  624. package/editor-web/assets/{wardley-7MLQ67FV-BXzwcdJa.js → wardley-7MLQ67FV-BLNiqxtt.js} +1 -1
  625. package/editor-web/assets/{wardleyDiagram-IVAIDKWA-BQvC8Agx.js → wardleyDiagram-IVAIDKWA-SppgC6xW.js} +1 -1
  626. package/editor-web/assets/{whole-word-D3ZAtnkw.js → whole-word-C9TkGBCY.js} +1 -1
  627. package/editor-web/assets/{words-CaUHhQHf.js → words-BUlNNuH2.js} +3 -3
  628. package/editor-web/assets/words-zMedmPWc.js +3 -0
  629. package/editor-web/assets/workbook-BZKYx4WB.js +41 -0
  630. package/editor-web/assets/{xychartDiagram-4URNHDU4-aY-lsD5o.js → xychartDiagram-4URNHDU4-BHMn_jwJ.js} +1 -1
  631. package/editor-web/assets/{zoom-in-PgsC94hP.js → zoom-in-yAGKspfC.js} +1 -1
  632. package/editor-web/index.html +9 -8
  633. package/package.json +3 -3
  634. package/CHANGELOG.md +0 -251
  635. package/dist/commands/render.js +0 -3
  636. package/dist/node_modules/@allyhub/video-extension/dist/inspect/motion.js +0 -4
  637. package/dist/node_modules/@allyhub/video-measure/dist/still.js +0 -2
  638. package/editor-web/assets/arrow-down-B8VUPCGi.js +0 -1
  639. package/editor-web/assets/arrow-up-Ds4juY8X.js +0 -1
  640. package/editor-web/assets/article-8evPh712.js +0 -3
  641. package/editor-web/assets/article-BhRtWYMd.js +0 -7
  642. package/editor-web/assets/bar-button-J9vbfzTx.js +0 -1
  643. package/editor-web/assets/calc-worker-oEIqrrTM.js +0 -45
  644. package/editor-web/assets/channel-wIj_OqDm.js +0 -1
  645. package/editor-web/assets/chart-amT4lgX3.js +0 -2
  646. package/editor-web/assets/chart-file-dGiRgFcH.js +0 -1
  647. package/editor-web/assets/code-CD-CbJG9.js +0 -1
  648. package/editor-web/assets/collaborator-BU4qU7O3.js +0 -1
  649. package/editor-web/assets/deck-C7fN0Qtn.js +0 -1
  650. package/editor-web/assets/dist-3iovns9K.js +0 -16
  651. package/editor-web/assets/dist-BkHnbOEj.js +0 -4
  652. package/editor-web/assets/dist-BvOrNcK-.js +0 -19
  653. package/editor-web/assets/dist-CEIszq39.js +0 -1
  654. package/editor-web/assets/dist-CU5RbLNH.js +0 -1
  655. package/editor-web/assets/dist-CWZj8IAm.js +0 -1
  656. package/editor-web/assets/dist-C_Mtrnif.js +0 -17
  657. package/editor-web/assets/dist-CdqpwdCV.js +0 -24
  658. package/editor-web/assets/dist-CjT76RAw.js +0 -43
  659. package/editor-web/assets/dist-CpzEn9T8.js +0 -6
  660. package/editor-web/assets/dist-CrFYWl5-.js +0 -3
  661. package/editor-web/assets/dist-D3C6FyrO.js +0 -82
  662. package/editor-web/assets/dist-D4eBFGVL.js +0 -1
  663. package/editor-web/assets/dist-DTcjb3cP.js +0 -18
  664. package/editor-web/assets/dist-D_WSM29I.js +0 -17
  665. package/editor-web/assets/dist-Dp_9ISjP.js +0 -531
  666. package/editor-web/assets/dist-J-tPYKGS.js +0 -5
  667. package/editor-web/assets/dist-YW8hS4IM.js +0 -9
  668. package/editor-web/assets/esm-Cjv8ogpP.js +0 -21
  669. package/editor-web/assets/file-exclamation-point-_L3ElCJ5.js +0 -1
  670. package/editor-web/assets/flowDiagram-IUGLLWBU-BlVUglzw.js +0 -1
  671. package/editor-web/assets/hint-rlht0uxG.js +0 -1
  672. package/editor-web/assets/index-BQWZnyAQ.js +0 -28
  673. package/editor-web/assets/index-Dvh1t1om.css +0 -2
  674. package/editor-web/assets/minus-CbPnUIOy.js +0 -1
  675. package/editor-web/assets/progress-CwKcXARv.js +0 -6
  676. package/editor-web/assets/props-form-BpSXbrSF.js +0 -1
  677. package/editor-web/assets/react-Edyoga_4.js +0 -1
  678. package/editor-web/assets/row-C_svyL8o.js +0 -1
  679. package/editor-web/assets/schemas-CQ_UU8-Z.js +0 -1
  680. package/editor-web/assets/search-Ba2BbT6T.js +0 -1
  681. package/editor-web/assets/slides-7xWhREpt.js +0 -1
  682. package/editor-web/assets/snapshots-BLX4NTQC.js +0 -1
  683. package/editor-web/assets/sound-bTlco_K3.js +0 -1
  684. package/editor-web/assets/split-tFGKk-x8.js +0 -3
  685. package/editor-web/assets/strikethrough-BwXWi4zg.js +0 -1
  686. package/editor-web/assets/surface-DtCjIlrq.js +0 -1
  687. package/editor-web/assets/svg-CWIBMIQ9.js +0 -1
  688. package/editor-web/assets/swatch-DhztHwPU.js +0 -1
  689. package/editor-web/assets/swimlanesDiagram-AYQRV4AK-DKzB_wSf.js +0 -8
  690. package/editor-web/assets/switch-8MU4Nfxe.js +0 -1
  691. package/editor-web/assets/table-DRbddzx0.js +0 -1
  692. package/editor-web/assets/tabs-CuEawka3.js +0 -1
  693. package/editor-web/assets/tag-CIfWT8B_.js +0 -1
  694. package/editor-web/assets/text-align-start-Cic2-TLh.js +0 -1
  695. package/editor-web/assets/textarea-D7TnPwv1.js +0 -1
  696. package/editor-web/assets/video-D0uTbHWx.js +0 -1
  697. package/editor-web/assets/words-XlXG79Ur.js +0 -3
  698. package/editor-web/assets/workbook-CiCXkjmN.js +0 -45
  699. package/editor-web/assets/x-DlhyIKuu.js +0 -41
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{mkdir as S,readFile as p,writeFile as k}from"node:fs/promises";import{dirname as E}from"node:path";import{BLOBS_MAX as y,BlobsResponseSchema as O}from"@allyhub/protocol/blobs";import{z as r}from"zod";import{CloudError as v}from"./errors.js";import{sha256Of as N}from"./hashes.js";export class BlobsUnavailable extends Error{sha256s;constructor(e){super(`${String(e.length)} blob(s) storage lacks cannot be put from here: their bytes are not here any more.`),this.name="BlobsUnavailable",this.sha256s=e}}const A=r.object({scope:r.string(),held:r.array(r.string())}),B=4,x=30*6e4,T=3*6e4;export class BlobStore{cloud;path;file;known;constructor(e,t){this.cloud=e,this.path=t.path,this.file=t.file}async scope(){const e=await this.cloud.requireKey();return JSON.stringify([e.account,e.organization??null])}async load(){const e=await this.scope();return this.known?.scope!==e&&(this.known={scope:e,held:await this.read(e)}),this.known.held}async read(e){if(this.file===void 0)return new Set;let t;try{t=JSON.parse(await p(this.file,"utf8"))}catch(o){if(o instanceof SyntaxError||o instanceof Error&&"code"in o&&o.code==="ENOENT")return new Set;throw o}const s=A.safeParse(t);return s.success&&s.data.scope===e?new Set(s.data.held):new Set}async save(){this.file===void 0||this.known===void 0||(await S(E(this.file),{recursive:!0}),await k(this.file,JSON.stringify({scope:this.known.scope,held:[...this.known.held]})))}async bytesOf(e){if(e.bytes!==void 0)return e.bytes;if(e.file===void 0)return;let t;try{t=await p(e.file)}catch(s){if(s instanceof Error&&"code"in s&&s.code==="ENOENT")return;throw s}return e.checkBytes===!0&&N(t)!==e.sha256?void 0:t}async forget(e){const t=await this.load();for(const s of e)t.delete(s);await this.save()}async put(e){let t=0;const s=await this.load(),o=new Map;for(const i of e)s.has(i.sha256)||o.set(i.sha256,i);const f=[...o.values()],a=[];for(let i=0;i<f.length;i+=y){const d=f.slice(i,i+y),{uploads:c}=O.parse(await this.cloud.json(this.path,{method:"POST",signal:AbortSignal.timeout(T),body:{blobs:d.map(n=>({sha256:n.sha256,size:n.size,contentType:n.type}))}}));let u=0;const b=async()=>{for(;u<c.length;){const n=c[u++],h=n&&o.get(n.sha256);if(!n||!h)continue;const w=await this.bytesOf(h);if(w===void 0){a.push(h.sha256);continue}const l=await this.cloud.config.fetch(n.url,{method:"PUT",headers:n.headers,body:new Uint8Array(w),signal:AbortSignal.timeout(x)});if(!l.ok)throw new v("blob-refused",`Storage refused a blob: ${String(l.status)} ${(await l.text()).slice(0,200)}`);t+=1}};await Promise.all(Array.from({length:Math.min(B,c.length)},b));const g=new Set(a);for(const n of d)g.has(n.sha256)||s.add(n.sha256);await this.save()}if(a.length>0)throw new BlobsUnavailable(a);return t}}
2
+ import{mkdir as S,readFile as w,writeFile as g}from"node:fs/promises";import{dirname as k}from"node:path";import{BLOBS_MAX as y,BlobsResponseSchema as M}from"@allyhub/protocol/blobs";import{z as r}from"zod";import{sha256Of as O}from"./hashes.js";import{putToStorage as E}from"./storage.js";export class BlobsUnavailable extends Error{sha256s;constructor(e){super(`${String(e.length)} blob(s) storage lacks cannot be put from here: their bytes are not here any more.`),this.name="BlobsUnavailable",this.sha256s=e}}const v=r.object({scope:r.string(),held:r.array(r.string())}),N=4,B=30*6e4,T=3*6e4;export class BlobStore{cloud;path;file;known;delaysMs;constructor(e,t){this.cloud=e,this.path=t.path,this.file=t.file,this.delaysMs=t.delaysMs}async scope(){const e=await this.cloud.requireKey();return JSON.stringify([e.account,e.organization??null])}async load(){const e=await this.scope();return this.known?.scope!==e&&(this.known={scope:e,held:await this.read(e)}),this.known.held}async read(e){if(this.file===void 0)return new Set;let t;try{t=JSON.parse(await w(this.file,"utf8"))}catch(a){if(a instanceof SyntaxError||a instanceof Error&&"code"in a&&a.code==="ENOENT")return new Set;throw a}const s=v.safeParse(t);return s.success&&s.data.scope===e?new Set(s.data.held):new Set}async save(){this.file===void 0||this.known===void 0||(await S(k(this.file),{recursive:!0}),await g(this.file,JSON.stringify({scope:this.known.scope,held:[...this.known.held]})))}async bytesOf(e){if(e.bytes!==void 0)return e.bytes;if(e.file===void 0)return;let t;try{t=await w(e.file)}catch(s){if(s instanceof Error&&"code"in s&&s.code==="ENOENT")return;throw s}return e.checkBytes===!0&&O(t)!==e.sha256?void 0:t}async forget(e){const t=await this.load();for(const s of e)t.delete(s);await this.save()}async put(e){let t=0;const s=await this.load(),a=new Map;for(const i of e)s.has(i.sha256)||a.set(i.sha256,i);const l=[...a.values()],o=[];for(let i=0;i<l.length;i+=y){const d=l.slice(i,i+y),{uploads:c}=M.parse(await this.cloud.json(this.path,{method:"POST",signal:AbortSignal.timeout(T),body:{blobs:d.map(n=>({sha256:n.sha256,size:n.size,contentType:n.type}))}}));let f=0;const m=async()=>{for(;f<c.length;){const n=c[f++],h=n&&a.get(n.sha256);if(!n||!h)continue;const u=await this.bytesOf(h);if(u===void 0){o.push(h.sha256);continue}await E(this.cloud.config.fetch,n.url,{headers:n.headers,body:u,timeoutMs:B,what:"a blob",code:"blob-refused",...this.delaysMs===void 0?{}:{delaysMs:this.delaysMs}}),t+=1}};await Promise.all(Array.from({length:Math.min(N,c.length)},m));const b=new Set(o);for(const n of d)b.has(n.sha256)||s.add(n.sha256);await this.save()}if(o.length>0)throw new BlobsUnavailable(o);return t}}
@@ -1,5 +1,5 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{randomUUID as X}from"node:crypto";import{mkdir as D,readdir as Y,readFile as E,rm as q,writeFile as A}from"node:fs/promises";import{basename as $,dirname as k,extname as S,join as j}from"node:path";import{EXIT as p}from"@allyhub/protocol/cli";import{FileContentResponseSchema as Q,ToolCallSchema as _,callPath as V,fileContentPath as tt,parseAllyFilePath as I,toolCallsPath as et}from"@allyhub/protocol/cloud";import{genFileFor as U}from"@allyhub/formats/data/gen";import{CloudError as d}from"./errors.js";import{genRecord as H,inputHash as nt,namedFile as it,readGen as at,toolWords as ot,writeGen as M,writeWords as rt}from"./records.js";import{withKnownUploads as st}from"./uploads.js";export const WAIT_SECONDS=900,POLL_SECONDS={least:1,most:60},RETRY_SECONDS={least:1,most:30},READ_SECONDS=120;const lt=new Set([408,429,500,502,503,504]),ut=t=>t instanceof d&&(t.code==="network"||t.status!==void 0&&lt.has(t.status));function ft(t){if(!/^https?:\/\//iu.test(t))return t;let e;try{e=new URL(t)}catch{return t}if(e.search==="")return t.replace(/^https?:\/\//iu,"");const i=/filename\*?=(?:UTF-8'')?"?([^";]+)/iu.exec(e.searchParams.get("response-content-disposition")??"")?.[1];return i===void 0?void 0:decodeURIComponent(i)}export function inputSlug(t){return Object.values(t).flatMap(e=>Array.isArray(e)?e:[e]).filter(e=>typeof e=="string").flatMap(e=>ft(e)??[]).join("-").replace(/[^\p{L}\p{N}._]+/gu,"-").replace(/^-+|-+$/gu,"").slice(0,40).replace(/-+$/u,"")}const L=t=>t.replace(/[^A-Za-z0-9_-]/gu,"_").slice(0,8),W=(t,e)=>{const i=S(t);return`${$(t,i)}-${L(e)}${i}`};async function ct(t,e,i,n,o){await D(t,{recursive:!0});const s=[e,inputSlug(i),L(n)].filter(Boolean).join("-"),r=j(t,`${s}.output.json`);return await A(r,`${JSON.stringify(o,null,2)}
3
- `),r}async function dt(t,e){const i=S(t)===""?`${t}.json`:t;return await D(k(i),{recursive:!0}),await A(i,`${JSON.stringify(e,null,2)}
4
- `),i}const T=t=>j(t.config.cacheDir,"jobs"),C=(t,e)=>j(T(t),`${e.replace(/[^A-Za-z0-9_-]/gu,"_")}.json`);async function wt(t,e,i){await D(k(C(t,e)),{recursive:!0}),await A(C(t,e),`${JSON.stringify(i,null,2)}
5
- `)}const P=(t,e)=>q(C(t,e),{force:!0});async function ht(t,e,i){const n=await Y(T(t)).catch(()=>[]);for(const o of n.filter(s=>s.endsWith(".json")).sort()){const s=await E(j(T(t),o),"utf8").then(r=>JSON.parse(r)).catch(()=>{});if(s?.jobId!==void 0&&s.file===e&&s.inputHash===i)return s.jobId}}async function pt(t,e){try{return JSON.parse(await E(C(t,e),"utf8"))}catch{throw new d("unknown-job",`No job ${e} was started on this computer.`,{exit:p.notFound,hint:"Call the tool again: that is a new call."})}}async function B(t,e,i,n,o){const{url:s}=Q.parse(await t.json(tt(e,"attachment"),{signal:v(o)}));let r;try{const f=await t.config.fetch(s,o?{signal:o}:{});if(!f.ok)throw new d("download-failed",`Downloading ${i} answered ${String(f.status)}.`,{exit:p.platform,status:f.status});r=Buffer.from(await f.arrayBuffer())}catch(f){throw f instanceof d||o?.aborted===!0?f:new d("network",`Downloading ${i} failed: ${f instanceof Error?f.message:String(f)}`,{exit:p.platform,cause:f})}const w="dir"in n?j(n.dir,$(n.name??i)):S(n.file)?n.file:`${n.file}${S(i)}`;return await D(k(w),{recursive:!0}),await A(w,r),w}const v=t=>t?AbortSignal.any([t,AbortSignal.timeout(READ_SECONDS*1e3)]):AbortSignal.timeout(READ_SECONDS*1e3),z=(t,e)=>new Promise((i,n)=>{const o=setTimeout(i,t*1e3);e?.addEventListener("abort",()=>{clearTimeout(o),n(e.reason instanceof Error?e.reason:new Error("Stopped."))},{once:!0})});export async function callTool(t,e,i,n){const o=n.file,s=await st(t,i,n.base),r=nt(e,s);let w=n.jobId,f=!1;if(o!==void 0&&w===void 0){w=await ht(t,o,r);const u=w===void 0?await it(o):void 0,l=u?await at(u):void 0;if(n.force===!0)f=l!==void 0;else{if(u&&!l)throw new d("file-exists",`${u} is there, without a record (${$(U(u))}) saying a tool call made it.`,{exit:p.conflict,hint:"Choose another --file, or pass --force to replace it."});if(u&&l){if(l.tool===e&&l.inputHash===r)return{tool:e,output:typeof l.output?.allyFilePath=="string"?l.output:JSON.parse(await E(u,"utf8")),file:u,gen:U(u),kept:{at:l.at}};throw new d("file-exists",`${u} was made by ${l.tool??"another tool"} from another input on ${l.at}.`,{exit:p.conflict,hint:"Choose another --file to keep it, or pass --force to make it again over it (charged again)."})}}}const m=Date.now()+(n.timeoutSeconds??WAIT_SECONDS)*1e3,g=n.signal;let a=w===void 0?_.parse(await t.json(et(e),{method:"POST",body:{input:i},idempotencyKey:X(),...g?{signal:g}:{}})):await G(t,w,m,n);a.status==="working"&&w===void 0&&await wt(t,a.id,{jobId:a.id,tool:e,input:{...i},inputHash:r,outDir:n.outDir,...o===void 0?{}:{file:o}});const K=()=>({tool:e,jobId:a.id,status:"running",elapsedSeconds:(Date.now()-Date.parse(a.createdAt))/1e3,...o===void 0?{}:{file:o}});for(;a.status==="working";){if(n.wait===!1||Date.now()>m)return K();n.onRunning?.(a),await z(Math.min(Math.max((a.pollAfterMs??0)/1e3,POLL_SECONDS.least),POLL_SECONDS.most),g),a=await G(t,a.id,m,n)}if(a.status==="failed")throw await P(t,a.id),new d(`tool-${(a.error?.kind??"failed").replaceAll("_","-")}`,a.error?.message??"The tool failed.",{exit:a.error?.kind==="input"?p.usage:p.platform,hint:a.error?.kind==="input"||a.error?.kind==="not_found"?"A failed call is not charged. Change the input and call again.":a.error?.kind==="unavailable"?"A failed call is not charged. Calling it again will not help until AllyHub sets it up or fixes it.":"A failed call is not charged. Call it again; a supplier's failure often passes."});if(a.status!=="completed")throw new d("tool-state",`The call ${a.id} is ${a.status}, a state this version of allyhub does not know.`,{exit:p.platform,hint:"Update allyhub in the project (npm install allyhub@latest) and call it again."});const h=typeof a.output=="object"&&a.output!==null?a.output:{value:a.output},R=h.allyFilePath,y=typeof R=="string"?I(R):void 0,b=!y&&o!==void 0?await dt(o,h):void 0,c={tool:e,output:h,outputFile:b??await ct(n.outputDir??n.outDir,e,i,a.id,h),...a.credits===void 0?{}:{credits:a.credits}};if(y){const u=a.id,l=await J(u,()=>B(t,y.id,y.name,o!==void 0?{file:o}:{dir:n.outDir,name:W(y.name,u)},g),m,n);c.file=l,c.gen=await M(l,await H(l,{tool:e,input:s,output:h,credits:a.credits}));const x=ot(h),N=h.durationSeconds;x&&(c.words=await rt(l,x,typeof N=="number"&&N>=0?N:void 0)),f&&(c.replaced=!0)}else b!==void 0&&(c.file=b,c.gen=await M(b,await H(b,{tool:e,input:s,output:h,credits:a.credits})),f&&(c.replaced=!0));const O={},Z=c.file===void 0?n.outDir:k(c.file),F=c.file;for(const u of mt(h)){const l=I(u);if(!l)continue;const x=F===void 0?W(l.name,a.id):`${$(F,S(F))}.${$(l.name)}`;O[u]=await J(a.id,()=>B(t,l.id,l.name,{dir:Z,name:x},g),m,n)}return Object.keys(O).length>0&&(c.more=O),await P(t,a.id),c}function mt(t){const e=[],i=(n,o)=>{if(Array.isArray(n))for(const s of n)i(s,!1);else if(typeof n=="object"&&n!==null)for(const[s,r]of Object.entries(n))s==="allyFilePath"&&!o&&typeof r=="string"?e.push(r):i(r,!1)};return i(t,!0),e}async function G(t,e,i,n){try{return await J(e,async()=>_.parse(await t.json(V(e),{signal:v(n.signal)})),i,n)}catch(o){throw o instanceof d&&o.status===404&&await P(t,e),o}}async function J(t,e,i,n){const o=n.retrySeconds??RETRY_SECONDS;for(let s=o.least;;)try{return await e()}catch(r){if(!ut(r)||n.signal?.aborted===!0)throw r;if(Date.now()+s*1e3>i)throw new d(r.code,r.message,{exit:r.exit,...r.status===void 0?{}:{status:r.status},hint:`Call ${t} goes on at AllyHub, charged once when it works: --resume ${t} waits for it again (so does the same call to the same --file).`,cause:r});n.onRetry?.(t,r,s),await z(s,n.signal),s=Math.min(s*2,o.most)}}export async function resumeJob(t,e,i){const n=await pt(t,e);if(i.tool!==void 0&&i.tool!==n.tool)throw new d("wrong-job",`Job ${e} is ${n.tool}'s, not ${i.tool}'s.`,{exit:p.usage,hint:`Resume it with ${n.tool}.`});return await callTool(t,n.tool,n.input,{...i,outDir:n.outDir,...n.file===void 0?{}:{file:n.file},jobId:e})}
2
+ import{randomUUID as X}from"node:crypto";import{mkdir as A,readdir as Y,readFile as T,rm as q,writeFile as D}from"node:fs/promises";import{basename as $,dirname as k,extname as S,join as j}from"node:path";import{EXIT as p}from"@allyhub/protocol/cli";import{FileContentResponseSchema as Q,ToolCallSchema as R,callPath as V,fileContentPath as tt,parseAllyFilePath as I,toolCallsPath as et}from"@allyhub/protocol/cloud";import{genFileFor as U}from"@allyhub/formats/data/gen";import{CloudError as d}from"./errors.js";import{genRecord as H,inputHash as nt,namedFile as it,readGen as at,toolWords as ot,writeGen as M,writeWords as rt}from"./records.js";import{TRANSIENT_STATUSES as st}from"./storage.js";import{withKnownUploads as lt}from"./uploads.js";export const WAIT_SECONDS=900,POLL_SECONDS={least:1,most:60},RETRY_SECONDS={least:1,most:30},READ_SECONDS=120;const ft=t=>t instanceof d&&(t.code==="network"||t.status!==void 0&&st.has(t.status));function ut(t){if(!/^https?:\/\//iu.test(t))return t;let e;try{e=new URL(t)}catch{return t}if(e.search==="")return t.replace(/^https?:\/\//iu,"");const i=/filename\*?=(?:UTF-8'')?"?([^";]+)/iu.exec(e.searchParams.get("response-content-disposition")??"")?.[1];return i===void 0?void 0:decodeURIComponent(i)}export function inputSlug(t){return Object.values(t).flatMap(e=>Array.isArray(e)?e:[e]).filter(e=>typeof e=="string").flatMap(e=>ut(e)??[]).join("-").replace(/[^\p{L}\p{N}._]+/gu,"-").replace(/^-+|-+$/gu,"").slice(0,40).replace(/-+$/u,"")}const L=t=>t.replace(/[^A-Za-z0-9_-]/gu,"_").slice(0,8),W=(t,e)=>{const i=S(t);return`${$(t,i)}-${L(e)}${i}`};async function ct(t,e,i,n,o){await A(t,{recursive:!0});const s=[e,inputSlug(i),L(n)].filter(Boolean).join("-"),r=j(t,`${s}.output.json`);return await D(r,`${JSON.stringify(o,null,2)}
3
+ `),r}async function dt(t,e){const i=S(t)===""?`${t}.json`:t;return await A(k(i),{recursive:!0}),await D(i,`${JSON.stringify(e,null,2)}
4
+ `),i}const E=t=>j(t.config.cacheDir,"jobs"),C=(t,e)=>j(E(t),`${e.replace(/[^A-Za-z0-9_-]/gu,"_")}.json`);async function wt(t,e,i){await A(k(C(t,e)),{recursive:!0}),await D(C(t,e),`${JSON.stringify(i,null,2)}
5
+ `)}const P=(t,e)=>q(C(t,e),{force:!0});async function ht(t,e,i){const n=await Y(E(t)).catch(()=>[]);for(const o of n.filter(s=>s.endsWith(".json")).sort()){const s=await T(j(E(t),o),"utf8").then(r=>JSON.parse(r)).catch(()=>{});if(s?.jobId!==void 0&&s.file===e&&s.inputHash===i)return s.jobId}}async function pt(t,e){try{return JSON.parse(await T(C(t,e),"utf8"))}catch{throw new d("unknown-job",`No job ${e} was started on this computer.`,{exit:p.notFound,hint:"Call the tool again: that is a new call."})}}async function B(t,e,i,n,o){const{url:s}=Q.parse(await t.json(tt(e,"attachment"),{signal:v(o)}));let r;try{const u=await t.config.fetch(s,o?{signal:o}:{});if(!u.ok)throw new d("download-failed",`Downloading ${i} answered ${String(u.status)}.`,{exit:p.platform,status:u.status});r=Buffer.from(await u.arrayBuffer())}catch(u){throw u instanceof d||o?.aborted===!0?u:new d("network",`Downloading ${i} failed: ${u instanceof Error?u.message:String(u)}`,{exit:p.platform,cause:u})}const w="dir"in n?j(n.dir,$(n.name??i)):S(n.file)?n.file:`${n.file}${S(i)}`;return await A(k(w),{recursive:!0}),await D(w,r),w}const v=t=>t?AbortSignal.any([t,AbortSignal.timeout(READ_SECONDS*1e3)]):AbortSignal.timeout(READ_SECONDS*1e3),z=(t,e)=>new Promise((i,n)=>{const o=setTimeout(i,t*1e3);e?.addEventListener("abort",()=>{clearTimeout(o),n(e.reason instanceof Error?e.reason:new Error("Stopped."))},{once:!0})});export async function callTool(t,e,i,n){const o=n.file,s=await lt(t,i,n.base),r=nt(e,s);let w=n.jobId,u=!1;if(o!==void 0&&w===void 0){w=await ht(t,o,r);const f=w===void 0?await it(o):void 0,l=f?await at(f):void 0;if(n.force===!0)u=l!==void 0;else{if(f&&!l)throw new d("file-exists",`${f} is there, without a record (${$(U(f))}) saying a tool call made it.`,{exit:p.conflict,hint:"Choose another --file, or pass --force to replace it."});if(f&&l){if(l.tool===e&&l.inputHash===r)return{tool:e,output:typeof l.output?.allyFilePath=="string"?l.output:JSON.parse(await T(f,"utf8")),file:f,gen:U(f),kept:{at:l.at}};throw new d("file-exists",`${f} was made by ${l.tool??"another tool"} from another input on ${l.at}.`,{exit:p.conflict,hint:"Choose another --file to keep it, or pass --force to make it again over it (charged again)."})}}}const m=Date.now()+(n.timeoutSeconds??WAIT_SECONDS)*1e3,g=n.signal;let a=w===void 0?R.parse(await t.json(et(e),{method:"POST",body:{input:i},idempotencyKey:X(),...g?{signal:g}:{}})):await G(t,w,m,n);a.status==="working"&&w===void 0&&await wt(t,a.id,{jobId:a.id,tool:e,input:{...i},inputHash:r,outDir:n.outDir,...o===void 0?{}:{file:o}});const K=()=>({tool:e,jobId:a.id,status:"running",elapsedSeconds:(Date.now()-Date.parse(a.createdAt))/1e3,...o===void 0?{}:{file:o}});for(;a.status==="working";){if(n.wait===!1||Date.now()>m)return K();n.onRunning?.(a),await z(Math.min(Math.max((a.pollAfterMs??0)/1e3,POLL_SECONDS.least),POLL_SECONDS.most),g),a=await G(t,a.id,m,n)}if(a.status==="failed")throw await P(t,a.id),new d(`tool-${(a.error?.kind??"failed").replaceAll("_","-")}`,a.error?.message??"The tool failed.",{exit:a.error?.kind==="input"?p.usage:p.platform,hint:a.error?.kind==="input"||a.error?.kind==="not_found"?"A failed call is not charged. Change the input and call again.":a.error?.kind==="unavailable"?"A failed call is not charged. Calling it again will not help until AllyHub sets it up or fixes it.":"A failed call is not charged. Call it again; a supplier's failure often passes."});if(a.status!=="completed")throw new d("tool-state",`The call ${a.id} is ${a.status}, a state this version of allyhub does not know.`,{exit:p.platform,hint:"Update allyhub in the project (npm install allyhub@latest) and call it again."});const h=typeof a.output=="object"&&a.output!==null?a.output:{value:a.output},J=h.allyFilePath,y=typeof J=="string"?I(J):void 0,b=!y&&o!==void 0?await dt(o,h):void 0,c={tool:e,output:h,outputFile:b??await ct(n.outputDir??n.outDir,e,i,a.id,h),...a.credits===void 0?{}:{credits:a.credits}};if(y){const f=a.id,l=await _(f,()=>B(t,y.id,y.name,o!==void 0?{file:o}:{dir:n.outDir,name:W(y.name,f)},g),m,n);c.file=l,c.gen=await M(l,await H(l,{tool:e,input:s,output:h,credits:a.credits}));const x=ot(h),N=h.durationSeconds;x&&(c.words=await rt(l,x,typeof N=="number"&&N>=0?N:void 0)),u&&(c.replaced=!0)}else b!==void 0&&(c.file=b,c.gen=await M(b,await H(b,{tool:e,input:s,output:h,credits:a.credits})),u&&(c.replaced=!0));const O={},Z=c.file===void 0?n.outDir:k(c.file),F=c.file;for(const f of mt(h)){const l=I(f);if(!l)continue;const x=F===void 0?W(l.name,a.id):`${$(F,S(F))}.${$(l.name)}`;O[f]=await _(a.id,()=>B(t,l.id,l.name,{dir:Z,name:x},g),m,n)}return Object.keys(O).length>0&&(c.more=O),await P(t,a.id),c}function mt(t){const e=[],i=(n,o)=>{if(Array.isArray(n))for(const s of n)i(s,!1);else if(typeof n=="object"&&n!==null)for(const[s,r]of Object.entries(n))s==="allyFilePath"&&!o&&typeof r=="string"?e.push(r):i(r,!1)};return i(t,!0),e}async function G(t,e,i,n){try{return await _(e,async()=>R.parse(await t.json(V(e),{signal:v(n.signal)})),i,n)}catch(o){throw o instanceof d&&o.status===404&&await P(t,e),o}}async function _(t,e,i,n){const o=n.retrySeconds??RETRY_SECONDS;for(let s=o.least;;)try{return await e()}catch(r){if(!ft(r)||n.signal?.aborted===!0)throw r;if(Date.now()+s*1e3>i)throw new d(r.code,r.message,{exit:r.exit,...r.status===void 0?{}:{status:r.status},hint:`Call ${t} goes on at AllyHub, charged once when it works: --resume ${t} waits for it again (so does the same call to the same --file).`,cause:r});n.onRetry?.(t,r,s),await z(s,n.signal),s=Math.min(s*2,o.most)}}export async function resumeJob(t,e,i){const n=await pt(t,e);if(i.tool!==void 0&&i.tool!==n.tool)throw new d("wrong-job",`Job ${e} is ${n.tool}'s, not ${i.tool}'s.`,{exit:p.usage,hint:`Resume it with ${n.tool}.`});return await callTool(t,n.tool,n.input,{...i,outDir:n.outDir,...n.file===void 0?{}:{file:n.file},jobId:e})}
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{AsyncLocalStorage as _}from"node:async_hooks";import{createHash as b}from"node:crypto";import{BACKGROUND_HEADER as A,DEVICE_HEADER as E,ORGANIZATION_HEADER as g}from"@allyhub/protocol/auth";import{COMMAND_LINE_PAYWALL_MET as O,paywallNumbersOfData as k,paywallReasonOfCode as S}from"@allyhub/protocol/paywall";import{EXIT as c}from"@allyhub/protocol/cli";import{IDEMPOTENCY_KEY_HEADER as $,planPageAddress as y}from"@allyhub/protocol/cloud";import{accessOf as N,SignedOut as x}from"./credentials.js";import{userAgent as z}from"./device.js";import{CloudError as h,notSignedIn as p,unreachable as m}from"./errors.js";export function scrub(u,n){let t=u.replace(/(authorization)\s*[:=]\s*[^\r\n]+/giu,"$1: <redacted>");return t=t.replace(/\bahk_[A-Za-z0-9_-]+/gu,"<api-key>"),t=t.replace(/\beyJ[\w-]+\.[\w-]+\.[\w-]+/gu,"<token>"),n&&(t=t.split(n).join("<key>")),t}const I="/api/tools",w=new _;export function callsMadeInBackground(u){return w.run(!0,u)}export class Cloud{config;constructor(n){this.config=n}async tellStudio(n,t,i){const r=this.config.studioHost;if(r===void 0)return;const s={reason:n,what:t.startsWith(I)?"tool":"command",numbers:k(i)},e=(d,o)=>fetch(`${r}/${d}`,{method:"POST",signal:AbortSignal.timeout(1e3),...o===void 0?{}:{headers:{"content-type":"application/json"},body:o}}).then(async f=>(await f.body?.cancel(),f.status),()=>{});await e(O,JSON.stringify(s))===404&&n==="insufficient_credits"&&await e("out-of-credits")}get url(){return this.config.url}async key(n={}){const t=this.config.apiKey;if(t)return{key:t,source:"env",account:b("sha256").update(t).digest("hex")};try{const i=await N(this.config,n);if(!i)return;const r=i.credentials.account.organization?.id,s=i.credentials.device;return{key:i.token,source:"oauth",account:i.credentials.account.id,expiresAt:i.expiresAt,...r===void 0?{}:{organization:r},...s===void 0?{}:{device:s}}}catch(i){if(i instanceof x)return;throw m(this.url,i)}}async requireKey(){const n=await this.key();if(!n)throw p();return n}keyedFetch=async(n,t)=>{const i=this.config.client===void 0?void 0:await z(this.config.client),r=d=>{const o=new Headers(t?.headers);return o.set("authorization",`Bearer ${d.key}`),i!==void 0&&!o.has("user-agent")&&o.set("user-agent",i),this.config.traceparent!==void 0&&!o.has("traceparent")&&o.set("traceparent",this.config.traceparent),d.organization!==void 0&&!o.has(g)&&o.set(g,d.organization),d.device!==void 0&&o.set(E,d.device),w.getStore()===!0&&o.set(A,"1"),this.config.fetch(n,{...t,headers:o})},s=await this.requireKey(),e=await r(s);if(e.status!==401||s.source!=="oauth"||t?.body instanceof ReadableStream||n instanceof Request)return e;const a=await this.key({refused:s.key});return a===void 0?e:(await e.body?.cancel(),r(a))};async json(n,t={}){const i=t.auth!==!1,r=i?await this.requireKey():void 0,s=r?.key,e=t.organization??r?.organization;let a;try{a=await(i?this.keyedFetch:this.config.fetch)(`${this.url}${n}`,{redirect:"error",signal:t.signal??AbortSignal.timeout(3e4),method:t.method??"GET",headers:{accept:"application/json",...t.body===void 0?{}:{"content-type":"application/json"},...t.organization===void 0?{}:{[g]:t.organization},...t.idempotencyKey===void 0?{}:{[$]:t.idempotencyKey}},...t.body===void 0?{}:{body:JSON.stringify(t.body)}})}catch(l){throw l instanceof h?l:m(this.url,l)}const d=await a.text(),o=a.ok?void 0:T(d,a.status,s,this.url,e),f=S(o?.code);if(f!==void 0&&await this.tellStudio(f,n,o?.data),o&&a.status!==401)throw o;if(a.status===403)throw new h("forbidden","This AllyHub account does not have access to this operation.",{exit:c.auth,status:403});if(a.status===401)throw p(i?"This computer's AllyHub sign-in is not valid any more.":void 0);if(!a.ok)throw new h("api-error",`${this.url}${n} answered ${String(a.status)}: ${scrub(d.slice(0,300),s)}`,{exit:a.status>=500?c.platform:c.usage,status:a.status});if(a.status!==204)try{return JSON.parse(d)}catch{throw new h("api-error",`${this.url}${n} did not answer JSON.`,{exit:c.platform,status:a.status})}}}const R={bad_input:c.usage,insufficient_credits:c.auth,plan_required:c.auth,tool_off:c.auth,storage_full:c.auth,limit_reached:c.auth,forbidden:c.auth,not_found:c.notFound,conflict:c.conflict};function T(u,n,t,i,r){let s;try{s=JSON.parse(u)}catch{return}const e=s?.error;if(typeof e?.code!="string"||typeof e.message!="string")return;const a=e.code==="insufficient_credits"?`Buy credits at ${y(i,{organization:r,open:"credits"})}, or ask an owner or admin of the team to.`:e.code==="plan_required"?`Subscribe at ${y(i,{organization:r,open:"plans"})}, or ask an owner or admin of the team to.`:e.code==="tool_off"?`Turn it on in Capabilities at ${i}/, or ask an owner or admin of the team to.`:typeof e.hint=="string"?e.hint:void 0;return new h(e.code.replaceAll("_","-"),scrub(e.message,t),{exit:R[e.code]??c.platform,status:n,...a===void 0?{}:{hint:a},...typeof e.data=="object"&&e.data!==null?{data:e.data}:{}})}
2
+ import{AsyncLocalStorage as _}from"node:async_hooks";import{createHash as b}from"node:crypto";import{BACKGROUND_HEADER as A,DEVICE_HEADER as E,ORGANIZATION_HEADER as g}from"@allyhub/protocol/auth";import{COMMAND_LINE_PAYWALL_MET as O,paywallNumbersOfData as k,paywallReasonOfCode as S}from"@allyhub/protocol/paywall";import{EXIT as r}from"@allyhub/protocol/cli";import{IDEMPOTENCY_KEY_HEADER as $,planPageAddress as p}from"@allyhub/protocol/cloud";import{accessOf as N,SignedOut as x}from"./credentials.js";import{userAgent as z}from"./device.js";import{CloudError as l,notSignedIn as y,unreachable as m}from"./errors.js";export function scrub(u,n){let t=u.replace(/(authorization)\s*[:=]\s*[^\r\n]+/giu,"$1: <redacted>");return t=t.replace(/\bahk_[A-Za-z0-9_-]+/gu,"<api-key>"),t=t.replace(/\beyJ[\w-]+\.[\w-]+\.[\w-]+/gu,"<token>"),n&&(t=t.split(n).join("<key>")),t}const I="/api/tools",w=new _;export function callsMadeInBackground(u){return w.run(!0,u)}export class Cloud{config;constructor(n){this.config=n}async tellStudio(n,t,i){const s=this.config.studioHost;if(s===void 0)return;const c={reason:n,what:t.startsWith(I)?"tool":"command",numbers:k(i)},e=(d,o)=>fetch(`${s}/${d}`,{method:"POST",signal:AbortSignal.timeout(1e3),...o===void 0?{}:{headers:{"content-type":"application/json"},body:o}}).then(async f=>(await f.body?.cancel(),f.status),()=>{});await e(O,JSON.stringify(c))===404&&n==="insufficient_credits"&&await e("out-of-credits")}get url(){return this.config.url}async key(n={}){const t=this.config.apiKey;if(t)return{key:t,source:"env",account:b("sha256").update(t).digest("hex")};try{const i=await N(this.config,n);if(!i)return;const s=i.credentials.account.organization?.id,c=i.credentials.device;return{key:i.token,source:"oauth",account:i.credentials.account.id,expiresAt:i.expiresAt,...s===void 0?{}:{organization:s},...c===void 0?{}:{device:c}}}catch(i){if(i instanceof x)return;throw m(this.url,i)}}async requireKey(){const n=await this.key();if(!n)throw y();return n}keyedFetch=async(n,t)=>{const i=this.config.client===void 0?void 0:await z(this.config.client),s=d=>{const o=new Headers(t?.headers);return o.set("authorization",`Bearer ${d.key}`),i!==void 0&&!o.has("user-agent")&&o.set("user-agent",i),this.config.traceparent!==void 0&&!o.has("traceparent")&&o.set("traceparent",this.config.traceparent),d.organization!==void 0&&!o.has(g)&&o.set(g,d.organization),d.device!==void 0&&o.set(E,d.device),w.getStore()===!0&&o.set(A,"1"),this.config.fetch(n,{...t,headers:o})},c=await this.requireKey(),e=await s(c);if(e.status!==401||c.source!=="oauth"||t?.body instanceof ReadableStream||n instanceof Request)return e;const a=await this.key({refused:c.key});return a===void 0?e:(await e.body?.cancel(),s(a))};async json(n,t={}){const i=t.auth!==!1,s=i?await this.requireKey():void 0,c=s?.key,e=t.organization??s?.organization;let a;try{a=await(i?this.keyedFetch:this.config.fetch)(`${this.url}${n}`,{redirect:"error",signal:t.signal??AbortSignal.timeout(3e4),method:t.method??"GET",headers:{accept:"application/json",...t.body===void 0?{}:{"content-type":"application/json"},...t.organization===void 0?{}:{[g]:t.organization},...t.idempotencyKey===void 0?{}:{[$]:t.idempotencyKey}},...t.body===void 0?{}:{body:JSON.stringify(t.body)}})}catch(h){throw h instanceof l?h:m(this.url,h)}const d=await a.text(),o=a.ok?void 0:T(d,a.status,c,this.url,e),f=S(o?.code);if(f!==void 0&&await this.tellStudio(f,n,o?.data),o&&a.status!==401)throw o;if(a.status===403)throw new l("forbidden","This AllyHub account does not have access to this operation.",{exit:r.auth,status:403});if(a.status===401)throw y(i?"This computer's AllyHub sign-in is not valid any more.":void 0);if(!a.ok)throw new l("api-error",`${this.url}${n} answered ${String(a.status)}: ${scrub(d.slice(0,300),c)}`,{exit:a.status>=500?r.platform:r.usage,status:a.status});if(a.status!==204)try{return JSON.parse(d)}catch{throw new l("api-error",`${this.url}${n} did not answer JSON.`,{exit:r.platform,status:a.status})}}}const R={bad_input:r.usage,insufficient_credits:r.auth,plan_required:r.auth,tool_off:r.auth,storage_full:r.auth,limit_reached:r.auth,forbidden:r.auth,not_found:r.notFound,conflict:r.conflict,cli_outdated:r.platform};function T(u,n,t,i,s){let c;try{c=JSON.parse(u)}catch{return}const e=c?.error;if(typeof e?.code!="string"||typeof e.message!="string")return;const a=e.code==="insufficient_credits"?`Buy credits at ${p(i,{organization:s,open:"credits"})}, or ask an owner or admin of the team to.`:e.code==="plan_required"?`Subscribe at ${p(i,{organization:s,open:"plans"})}, or ask an owner or admin of the team to.`:e.code==="tool_off"?`Turn it on in Capabilities at ${i}/, or ask an owner or admin of the team to.`:typeof e.hint=="string"?e.hint:void 0;return new l(e.code.replaceAll("_","-"),scrub(e.message,t),{exit:R[e.code]??r.platform,status:n,...a===void 0?{}:{hint:a},...typeof e.data=="object"&&e.data!==null?{data:e.data}:{}})}
@@ -0,0 +1,2 @@
1
+ /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
+ import{CloudError as m}from"./errors.js";export const TRANSIENT_STATUSES=new Set([408,429,500,502,503,504]),PUT_ATTEMPTS=3;const c={base:500,cap:4e3},h=()=>Array.from({length:PUT_ATTEMPTS-1},(t,n)=>Math.round(Math.random()*Math.min(c.cap,c.base*2**n))),l=t=>!(t instanceof Error&&(t.name==="AbortError"||t.name==="TimeoutError"));export async function putToStorage(t,n,e){const o=e.delaysMs??h(),s=Math.min(PUT_ATTEMPTS,o.length+1);for(let a=1;;a++){let r;try{r=await t(n,{method:"PUT",headers:e.headers,body:new Uint8Array(e.body),signal:AbortSignal.timeout(e.timeoutMs)})}catch(i){if(a>=s||!l(i))throw i;await d(o[a-1]??0);continue}if(r.ok){await r.body?.cancel();return}const u=(await r.text()).slice(0,200);if(a<s&&TRANSIENT_STATUSES.has(r.status)){await d(o[a-1]??0);continue}throw new m(e.code,`Storage refused ${e.what}: ${String(r.status)} ${u}${a>1?` (after ${String(a)} attempts)`:""}`,{status:r.status,...e.exit===void 0?{}:{exit:e.exit}})}}const d=t=>t<=0?Promise.resolve():new Promise(n=>setTimeout(n,t));
@@ -1,3 +1,3 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{createHash as b}from"node:crypto";import{chmod as U,mkdir as F,readFile as x,realpath as S,stat as P,writeFile as C}from"node:fs/promises";import{basename as D,dirname as N,extname as _,isAbsolute as L,join as R,relative as A,resolve as g}from"node:path";import{EXIT as $}from"@allyhub/protocol/cli";import{FILES_PATH as M,FILE_MAX_BYTES as O,FileContentResponseSchema as z,FileCreatedSchema as v,UploadedFileSchema as X,fileContentPath as q,fileDonePath as H}from"@allyhub/protocol/cloud";import{CloudError as p}from"./errors.js";export const UPLOAD_TYPES={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp",gif:"image/gif",mp3:"audio/mpeg",wav:"audio/wav",m4a:"audio/mp4",aac:"audio/aac",ogg:"audio/ogg",oga:"audio/ogg",flac:"audio/flac",mp4:"video/mp4",mov:"video/quicktime",webm:"video/webm"},REUSE_LEFT_MS=3600*1e3;const K=720*60*60*1e3;export const UPLOAD_CONCURRENCY=4;const Y=Object.keys(UPLOAD_TYPES).map(e=>`.${e}`).join(", ");async function j(e){const t=(await e.key())?.account??"",i=b("sha256").update(`${e.url}
3
- ${t}`).digest("hex").slice(0,12);return R(e.config.cacheDir,`uploads-${i}.json`)}async function E(e){try{const t=JSON.parse(await x(e,"utf8"));return{files:t.files??{},urls:t.urls??{}}}catch{return{files:{},urls:{}}}}async function J(e,t){const i=Date.now();for(const[c,o]of Object.entries(t.urls))i-Date.parse(o.expiresAt??o.at)>K&&Reflect.deleteProperty(t.urls,c);await F(N(e),{recursive:!0}),await C(e,JSON.stringify(t),{mode:384}),await U(e,384)}export function urlExpiry(e){let t;try{t=new URL(e).searchParams}catch{return}const i=/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/u.exec(t.get("X-Amz-Date")??""),c=Number(t.get("X-Amz-Expires"));if(!i||!Number.isFinite(c)||c<=0)return;const[o,r,l,a,n,u]=i.slice(1).map(Number);return new Date(Date.UTC(o,r-1,l,a,n,u)+c*1e3).toISOString()}const T=async e=>await S(g(e)).catch(()=>g(e)),y=(e,t)=>{const i=A(e,t);return i.startsWith("..")||L(i)},w=(e,t)=>new p("bad-input",e,{exit:$.usage,...t===void 0?{}:{hint:t}});async function W(e,t){const i=g(t.base,e),c=()=>w(`${e} is not inside ${String(t.inside)}.`,"Upload a file of the project.");if(t.inside!==void 0&&y(g(t.inside),i))throw c();const o=await P(i).catch(()=>{});if(!o?.isFile())throw w(`There is no file ${i}.`,"A relative path is read from the folder it is run in.");const r=await S(i);if(t.inside!==void 0&&y(await T(t.inside),r))throw c();const l=_(r).slice(1).toLowerCase(),a=UPLOAD_TYPES[l];if(a===void 0)throw w(`${e} is a${l?` .${l}`:"n unnamed"} file; an upload is one of ${Y}.`,"Convert it first, for example with ffmpeg.");if(o.size>O)throw w(`${e} is ${String(o.size)} bytes; AllyHub keeps files of at most ${String(O)}.`,"Make it smaller first, for example with ffmpeg.");const n=await x(r);return{given:e,path:r,type:a,sha256:b("sha256").update(n).digest("hex"),bytes:n}}async function B(e,t,i){const c=new Array(e.length);let o=0;const r=async()=>{for(;o<e.length;){const l=o++;c[l]=await i(e[l])}};return await Promise.all(Array.from({length:Math.min(t,e.length)},r)),c}async function k(e,t,i,c){const o=i.files[t.sha256];if(o&&!c)return{fileId:o.fileId,known:!0};const r={name:D(t.path),size:t.bytes.length,sha256:t.sha256,contentType:t.type},l=v.parse(await e.json(M,{method:"POST",body:r}));if(l.upload!==null){const n=await e.config.fetch(l.upload.url,{method:"PUT",headers:l.upload.headers,body:new Uint8Array(t.bytes),signal:AbortSignal.timeout(3e5)});if(!n.ok)throw new p("upload-failed",`Storage refused ${t.given}: ${String(n.status)} ${(await n.text()).slice(0,200)}`,{exit:$.platform})}const a=X.parse(await e.json(H(l.id),{method:"POST"}));return i.files[t.sha256]={fileId:a.id,path:t.path,bytes:t.bytes.length},{fileId:a.id,known:!1}}const I=async(e,t)=>z.parse(await e.json(q(t,"inline"))).url;export async function uploadFiles(e,t,i){if(t.length===0)throw w("Name at least one file to upload.");const c=[];for(const a of t)c.push(await W(a,{base:i.base,...i.inside===void 0?{}:{inside:i.inside}}));await e.requireKey();const o=await j(e),r=await E(o),l=await B(c,i.concurrency??UPLOAD_CONCURRENCY,async a=>{const n=(s,d,f,m,h)=>({ok:!0,file:a.given,path:a.path,fileId:s,url:d,...f===void 0?{}:{expiresAt:f},sha256:a.sha256,bytes:a.bytes.length,contentType:a.type,known:m,reused:h}),u=r.files[a.sha256];if(u){const s=Date.now(),d=Object.entries(r.urls).find(([,f])=>f.sha256===a.sha256&&f.expiresAt!==void 0&&Date.parse(f.expiresAt)-s>=REUSE_LEFT_MS);if(d)return u.path=a.path,n(u.fileId,d[0],d[1].expiresAt,!0,!0)}try{let s=await k(e,a,r,!1),d;try{d=await I(e,s.fileId)}catch(h){if(!s.known||!(h instanceof p)||h.status!==404)throw h;s=await k(e,a,r,!0),d=await I(e,s.fileId)}const f=urlExpiry(d);r.urls[d]={sha256:a.sha256,...f===void 0?{}:{expiresAt:f},at:new Date().toISOString()};const m=r.files[a.sha256];return m&&(m.path=a.path),n(s.fileId,d,f,s.known,!1)}catch(s){if(!(s instanceof p)||s.code==="not-signed-in")throw s;return{ok:!1,file:a.given,error:new p(s.code==="api-error"?"upload-failed":s.code,`Uploading ${a.given} failed. ${s.message}`,{exit:s.exit,...s.hint?{hint:s.hint}:{}})}}});return await J(o,r),l}export async function withKnownUploads(e,t,i){const c=await E(await j(e)),o=await T(i),r=n=>y(o,n)?n:A(o,n),l=new Map;for(const[n,u]of Object.entries(c.urls)){const s=c.files[u.sha256];s&&l.set(n,{uploaded:r(s.path),sha256:u.sha256,bytes:s.bytes})}const a=n=>typeof n=="string"?l.get(n)??n:Array.isArray(n)?n.map(a):typeof n=="object"&&n!==null?Object.fromEntries(Object.entries(n).map(([u,s])=>[u,a(s)])):n;return a(t)}
2
+ import{createHash as b}from"node:crypto";import{chmod as F,mkdir as C,readFile as x,realpath as S,stat as P,writeFile as U}from"node:fs/promises";import{basename as _,dirname as D,extname as M,isAbsolute as L,join as N,relative as O,resolve as m}from"node:path";import{EXIT as j}from"@allyhub/protocol/cli";import{FILES_PATH as R,FILE_MAX_BYTES as A,FileContentResponseSchema as v,FileCreatedSchema as z,UploadedFileSchema as H,fileContentPath as K,fileDonePath as Y,signedUntil as q}from"@allyhub/protocol/cloud";import{CloudError as g}from"./errors.js";import{putToStorage as J}from"./storage.js";export const UPLOAD_TYPES={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp",gif:"image/gif",mp3:"audio/mpeg",wav:"audio/wav",m4a:"audio/mp4",aac:"audio/aac",ogg:"audio/ogg",oga:"audio/ogg",flac:"audio/flac",mp4:"video/mp4",mov:"video/quicktime",webm:"video/webm"},REUSE_LEFT_MS=720*60*1e3;const W=720*60*60*1e3;export const UPLOAD_CONCURRENCY=4;const X=Object.keys(UPLOAD_TYPES).map(e=>`.${e}`).join(", ");async function $(e){const t=(await e.key())?.account??"",n=b("sha256").update(`${e.url}
3
+ ${t}`).digest("hex").slice(0,12);return N(e.config.cacheDir,`uploads-${n}.json`)}async function E(e){try{const t=JSON.parse(await x(e,"utf8"));return{files:t.files??{},urls:t.urls??{}}}catch{return{files:{},urls:{}}}}async function B(e,t){const n=Date.now();for(const[l,s]of Object.entries(t.urls))n-Date.parse(s.expiresAt??s.at)>W&&Reflect.deleteProperty(t.urls,l);await C(D(e),{recursive:!0}),await U(e,JSON.stringify(t),{mode:384}),await F(e,384)}export const urlExpiry=e=>q(e)?.toISOString();const I=async e=>await S(m(e)).catch(()=>m(e)),y=(e,t)=>{const n=O(e,t);return n.startsWith("..")||L(n)},p=(e,t)=>new g("bad-input",e,{exit:j.usage,...t===void 0?{}:{hint:t}});async function G(e,t){const n=m(t.base,e),l=()=>p(`${e} is not inside ${String(t.inside)}.`,"Upload a file of the project.");if(t.inside!==void 0&&y(m(t.inside),n))throw l();const s=await P(n).catch(()=>{});if(!s?.isFile())throw p(`There is no file ${n}.`,"A relative path is read from the folder it is run in.");const r=await S(n);if(t.inside!==void 0&&y(await I(t.inside),r))throw l();const c=M(r).slice(1).toLowerCase(),a=UPLOAD_TYPES[c];if(a===void 0)throw p(`${e} is a${c?` .${c}`:"n unnamed"} file; an upload is one of ${X}.`,"Convert it first, for example with ffmpeg.");if(s.size>A)throw p(`${e} is ${String(s.size)} bytes; AllyHub keeps files of at most ${String(A)}.`,"Make it smaller first, for example with ffmpeg.");const o=await x(r);return{given:e,path:r,type:a,sha256:b("sha256").update(o).digest("hex"),bytes:o}}async function Q(e,t,n){const l=new Array(e.length);let s=0;const r=async()=>{for(;s<e.length;){const c=s++;l[c]=await n(e[c])}};return await Promise.all(Array.from({length:Math.min(t,e.length)},r)),l}async function k(e,t,n,l){const s=n.files[t.sha256];if(s&&!l)return{fileId:s.fileId,known:!0};const r={name:_(t.path),size:t.bytes.length,sha256:t.sha256,contentType:t.type},c=z.parse(await e.json(R,{method:"POST",body:r}));c.upload!==null&&await J(e.config.fetch,c.upload.url,{headers:c.upload.headers,body:t.bytes,timeoutMs:3e5,what:t.given,code:"upload-failed",exit:j.platform});const a=H.parse(await e.json(Y(c.id),{method:"POST"}));return n.files[t.sha256]={fileId:a.id,path:t.path,bytes:t.bytes.length},{fileId:a.id,known:!1}}const T=async(e,t)=>v.parse(await e.json(K(t,"inline"))).url;export async function uploadFiles(e,t,n){if(t.length===0)throw p("Name at least one file to upload.");const l=[];for(const a of t)l.push(await G(a,{base:n.base,...n.inside===void 0?{}:{inside:n.inside}}));await e.requireKey();const s=await $(e),r=await E(s),c=await Q(l,n.concurrency??UPLOAD_CONCURRENCY,async a=>{const o=(i,d,f,w,h)=>({ok:!0,file:a.given,path:a.path,fileId:i,url:d,...f===void 0?{}:{expiresAt:f},sha256:a.sha256,bytes:a.bytes.length,contentType:a.type,known:w,reused:h}),u=r.files[a.sha256];if(u){const i=Date.now(),d=Object.entries(r.urls).find(([,f])=>f.sha256===a.sha256&&f.expiresAt!==void 0&&Date.parse(f.expiresAt)-i>=REUSE_LEFT_MS);if(d)return u.path=a.path,o(u.fileId,d[0],d[1].expiresAt,!0,!0)}try{let i=await k(e,a,r,!1),d;try{d=await T(e,i.fileId)}catch(h){if(!i.known||!(h instanceof g)||h.status!==404)throw h;i=await k(e,a,r,!0),d=await T(e,i.fileId)}const f=urlExpiry(d);r.urls[d]={sha256:a.sha256,...f===void 0?{}:{expiresAt:f},at:new Date().toISOString()};const w=r.files[a.sha256];return w&&(w.path=a.path),o(i.fileId,d,f,i.known,!1)}catch(i){if(!(i instanceof g)||i.code==="not-signed-in")throw i;return{ok:!1,file:a.given,error:new g(i.code==="api-error"?"upload-failed":i.code,`Uploading ${a.given} failed. ${i.message}`,{exit:i.exit,...i.hint?{hint:i.hint}:{}})}}});return await B(s,r),c}export async function withKnownUploads(e,t,n){const l=await E(await $(e)),s=await I(n),r=o=>y(s,o)?o:O(s,o),c=new Map;for(const[o,u]of Object.entries(l.urls)){const i=l.files[u.sha256];i&&c.set(o,{uploaded:r(i.path),sha256:u.sha256,bytes:i.bytes})}const a=o=>typeof o=="string"?c.get(o)??o:Array.isArray(o)?o.map(a):typeof o=="object"&&o!==null?Object.fromEntries(Object.entries(o).map(([u,i])=>[u,a(i)])):o;return a(t)}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allyhub/cloud",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allyhub/components",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{runCheck as l}from"@allyhub/check";import{analysesAsked as d,indexNeeds as c,makeIndex as f}from"@allyhub/project";import{loose as h}from"./paths.js";export const SETTLE_MS=1500;export class Checker{state;reads=new Map;timer;active;again=!1;closed=!1;live;emit;needs;settle;files;constructor(t){this.live=t.live,this.emit=t.emit,this.needs=t.needs,this.settle=t.settle??SETTLE_MS,this.files=t.files,this.state={status:"waiting",revision:0,problems:[],facts:[]}}schedule(t=!1){this.closed||(clearTimeout(this.timer),this.state.status!=="running"&&this.publish({...this.state,status:"waiting"}),this.timer=setTimeout(()=>{if(!this.closed){if(this.active){this.again=!0;return}this.active=this.run().finally(()=>{this.active=void 0})}},t?0:this.settle))}async run(){const t=this.live.revision;this.publish({...this.state,status:"running",revision:t});let i;try{const s=await this.live.withSession(a=>l({dir:this.live.root,session:a,...this.files===void 0?{}:{files:this.files}}));i={status:"done",revision:t,problems:s.problems.map(h),facts:s.facts.map(h),versions:{total:s.targets.length,loaded:s.stats.loaded.length,reused:s.stats.reused}},this.needs?.(c(s.results));const e=new Map;for(const a of s.results){const n=e.get(a.piece)??{media:new Set,data:new Set};e.set(a.piece,n);for(const r of a.reads?.media??[])n.media.add(r.path);for(const r of a.reads?.data??[])n.data.add(r.path)}this.reads=new Map([...e].map(([a,{media:n,data:r}])=>[a,{media:[...n],data:[...r]}]))}catch(s){i={status:"failed",revision:t,problems:[],facts:[],error:s instanceof Error?s.message:String(s)}}this.closed||(t===this.live.revision&&!this.again?this.publish(i):(this.again=!1,this.schedule(!0)))}publish(t){this.state=t,this.emit(t)}async close(){this.closed=!0,clearTimeout(this.timer),await this.active}}export class Indexer{jobs=[];root;analyses;env;emit;made;wanted=[];tried=new Set;running;abort=new AbortController;constructor(t){this.root=t.root,this.analyses=t.analyses,this.env=t.env,this.emit=t.emit,this.made=t.made}want(t){const i=e=>`${e.file}:${d(e).join(",")}`,s=t.filter(e=>!this.tried.has(i(e)));if(s.length!==0){for(const e of s)this.tried.add(i(e));this.wanted.push(...s),this.running??=this.loop().finally(()=>{this.running=void 0})}}async loop(){for(;this.wanted.length>0&&!this.abort.signal.aborted;){const t=this.wanted.splice(0),{done:i}=await f(this.root,t,this.analyses,{env:this.env,onProgress:s=>{this.jobs=[...this.jobs.filter(e=>e.file!==s.file),{file:s.file,status:s.status,message:s.message,...s.share===void 0?{}:{share:s.share}}],this.emit(this.jobs)},signal:this.abort.signal});i.length>0&&this.made()}}async close(){this.abort.abort(),await this.running}}
2
+ import{stageFiles as e}from"@allyhub/stage-page";export const SETTLE_MS=1500;export class Checker{state;reads=new Map;timer;active;again=!1;closed=!1;live;emit;settle;files;constructor(t){this.live=t.live,this.emit=t.emit,this.settle=t.settle??SETTLE_MS,this.files=t.files,this.state={status:"waiting",revision:0,problems:[],facts:[]}}schedule(t=!1){this.closed||(clearTimeout(this.timer),this.state.status!=="running"&&this.publish({...this.state,status:"waiting"}),this.timer=setTimeout(()=>{if(!this.closed){if(this.active){this.again=!0;return}this.active=this.run().finally(()=>{this.active=void 0})}},t?0:this.settle))}async run(){const t=this.live.revision;this.publish({...this.state,status:"running",revision:t});let i;try{const s=await this.live.checks.run({type:"check",dir:this.live.root,revision:t,kinds:this.live.kinds,prepared:await this.live.prepared(),runtime:e().runtime,...this.files===void 0?{}:{files:this.files}});i={status:"done",revision:t,problems:s.problems,facts:s.facts,versions:s.versions},this.reads=new Map(s.reads)}catch(s){i={status:"failed",revision:t,problems:[],facts:[],error:s instanceof Error?s.message:String(s)}}this.closed||(t===this.live.revision&&!this.again?this.publish(i):(this.again=!1,this.schedule(!0)))}publish(t){this.state=t,this.emit(t)}async close(){this.closed=!0,clearTimeout(this.timer),await this.active}}
@@ -0,0 +1,2 @@
1
+ /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
+ import{spawn as l}from"node:child_process";import{declaredRules as u}from"@allyhub/diagnostics";import{workerCommand as p}from"@allyhub/runtimes/node";const f=4e3,m=5*6e4;export class ItemProcess{heapMb;child;idle;next=0;output="";waiting=new Map;constructor(s={}){this.heapMb=s.heapMb}run(s){clearTimeout(this.idle);const d=this.child??this.start(),o=++this.next;return new Promise((e,n)=>{this.waiting.set(o,{resolve:t=>{e(t)},reject:n});const r={...s,id:o,rules:u()};d.send(r)})}close(){clearTimeout(this.idle);const s=this.child;this.child=void 0,s?.kill()}start(){const{command:s,args:d}=p(import.meta.url,"item-worker"),o=this.heapMb===void 0?[]:[`--max-old-space-size=${String(this.heapMb)}`],e=l(s,[...o,...d],{stdio:["ignore","pipe","pipe","ipc"],serialization:"json"});this.output="";let n=!1;const r=t=>{const i=t.toString("utf8");i.includes("heap out of memory")&&(n=!0),this.output=(this.output+i).slice(-f)};return e.stdout?.on("data",r),e.stderr?.on("data",r),e.on("message",t=>{const i=this.waiting.get(t.id);if(i)if(this.waiting.delete(t.id),this.waiting.size===0&&(clearTimeout(this.idle),this.idle=setTimeout(()=>{this.waiting.size===0&&this.close()},m),this.idle.unref()),t.ok)i.resolve(t.value);else{const c=new Error(t.error);t.stack&&(c.stack=t.stack),i.reject(c)}}),e.on("close",(t,i)=>{this.child===e&&(this.child=void 0);const c=n?"it ran out of memory":i!==null?`it ended (${i})`:`it ended (exit code ${String(t)})`;for(const[a,h]of this.waiting)this.waiting.delete(a),h.reject(new Error(`It stopped: ${c}.`))}),this.child=e,e}}
@@ -0,0 +1,2 @@
1
+ /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
+ import{startBrowser as p}from"@allyhub/browser";import{kindBuildOf as c,nodeLending as h}from"@allyhub/build";import{runCheck as k}from"@allyhub/check";import{declareAll as w}from"@allyhub/diagnostics";import{CheckSession as m}from"@allyhub/project";import{useStageRuntime as b}from"@allyhub/stage-page";import{loose as f}from"./paths.js";let a,d,u=!1,l=Promise.resolve();async function g(e){if(d?.revision===e.revision)return d.session;const n=d;a??=await p(),b(e.runtime);const s=m.open({root:e.dir,kinds:e.kinds,browser:a,prepared:e.prepared});return d={revision:e.revision,session:s},n&&n.session.then(t=>t.close()).catch(()=>{}),s}async function v(e){const n=await g(e),s=await k({dir:e.dir,session:n,...e.files===void 0?{}:{files:e.files}}),t=new Map;for(const r of s.results){const o=t.get(r.piece)??{media:new Set,data:new Set};t.set(r.piece,o);for(const i of r.reads?.media??[])o.media.add(i.path);for(const i of r.reads?.data??[])o.data.add(i.path)}return{problems:s.problems.map(f),facts:s.facts.map(f),versions:{total:s.targets.length,loaded:s.stats.loaded.length,reused:s.stats.reused},reads:[...t].map(([r,{media:o,data:i}])=>[r,{media:[...o],data:[...i]}])}}async function y(e){const n=await c(e.kinds.find(s=>s.id===e.kind))?.catch(()=>{});return n?.unreadable?[...n.unreadable(e.text)]:void 0}async function S(e){const n=await c(e.kinds.find(r=>r.id===e.item.kind))?.catch(()=>{}),s=n?.code?.bind(n);if(!s)return;const t=await h(e.kinds,e.root);return s(e.item,{root:e.root,lend:t})}function x(e){switch(e.type){case"check":{const n=l.then(()=>v(e));return l=n.catch(()=>{}),n}case"unreadable":return y(e);case"code":return S(e)}}process.on("message",e=>{u||(w(e.rules),u=!0),x(e).then(n=>{const s={id:e.id,ok:!0,value:n};process.send?.(s)},n=>{const s=n instanceof Error?n:new Error(String(n)),t={id:e.id,ok:!1,error:s.message,...s.stack?{stack:s.stack}:{}};process.send?.(t)})}),process.on("disconnect",()=>{a?.close().finally(()=>process.exit(0)),setTimeout(()=>process.exit(0),2e3).unref()});
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{rm as f}from"node:fs/promises";import{join as u}from"node:path";import{startBrowser as m}from"@allyhub/browser";import{kindBuildOf as w,mediaHref as b,nodeLending as v,projectItems as g,sourceOf as k,stageItem as S}from"@allyhub/build";import{CACHE_DIR as y}from"@allyhub/formats";import{CheckSession as D,ProjectError as R,pickTarget as E,parseCombo as O}from"@allyhub/project";import{RPC_ERROR as h,RpcError as c,SNAPSHOT_TREE as l}from"@allyhub/protocol";import{prepareStage as $,viewStage as C}from"@allyhub/stage";import{Routes as P}from"./routes.js";export function rpcErrorOf(o){return o instanceof R?new c(o.kind==="not-found"?h.notFound:h.invalid,o.hint?`${o.message} ${o.hint}`:o.message):o}export class Live{root;buildDir;revision=0;prep;last;lease;old=new Set;browserStarted;gpu;building=Promise.resolve();closed=!1;codes=new Map;kinds;routes;constructor(e,i){this.root=e,this.kinds=i.kinds,this.buildDir=u(e,y,"build",`dev-${String(process.pid)}`),this.gpu=i.gpu,this.routes=new P({root:e,kinds:i.kinds,buildDir:this.buildDir,revision:()=>this.revision,prepared:()=>this.prepared(),latest:()=>this.latest(),view:(t,s)=>C(e,t,s,i.kinds),recordInputs:(t,s,n)=>{i.recordInputs?.(t,s,n)}})}moved(e){this.revision=e,this.lease&&this.lease.revision!==e&&this.retire(this.lease)}prepared(){const e=this.revision;if(this.prep?.revision===e)return this.prep.promise;const i=this.building.then(()=>e===this.revision?this.build():void 0);this.building=i.catch(()=>{});const t=i.then(s=>s??this.prepared());return this.prep={revision:e,promise:t},t.catch(()=>{this.prep?.promise===t&&(this.prep=void 0)}),t}async build(){const e=await $(this.root,this.pieceDir,this.kinds);return this.last=e,e}async itemCode(e){const i=await this.item(e),t=i?await w(this.kinds.find(r=>r.id===i.kind))?.catch(()=>{}):void 0,s=t?.code?.bind(t);if(!i||!s)return{failed:!1};const n=this.codes.get(e),d=n?.revision===this.revision?n.promise:v(this.kinds,this.root).then(r=>s(i,{root:this.root,lend:r})).catch(()=>{});return this.codes.set(e,{revision:this.revision,promise:d}),await d??{failed:!0}}async item(e){const{items:i}=await g(this.root,this.kinds);return i.find(t=>t.id===e)}get pieceDir(){return u(this.buildDir,"stage")}latest(){return this.last}async target(e,i){const t=await this.prepared();try{const{piece:s,target:n}=E(t,e,i===void 0?void 0:[O(i)]);return{prepared:t,piece:s,combo:n.combo}}catch(s){throw rpcErrorOf(s)}}async componentHost(e,i){const t=await this.prepared(),s=t.docs.find(r=>r.place===e||r.file===e);if(s){if(s.components.length===0)throw new c(h.notFound,`${s.place} shows no component.`);const r=t.messages.locales[0];return{prepared:t,host:s,combo:r===void 0?{}:{lang:r}}}const{piece:n,combo:d}=await this.target(e,i);return{prepared:t,host:n,combo:d}}async source(e){const i=await this.prepared(),t=S(i,e);if(!t)throw new c(h.notFound,`No piece ${e}.`);const s=k(i,t),n={...s.media},d=(r,a)=>`${r}${b(a).slice(l.media.length)}`;return await Promise.all(Object.entries(n).map(async([r,a])=>{let p=a;a.kind==="video"&&a.matte===!0&&(p={...p,matteUrl:d(l.matte,r)}),n[r]=await this.routes.mediaOf(r,p)})),{...s,media:n}}browser(){return this.refuseStopped(),this.browserStarted??=m(this.gpu===void 0?{}:{gpu:this.gpu}),this.browserStarted}async withSession(e){this.refuseStopped();let i=this.lease;if(i?.revision!==this.revision){i&&this.retire(i);const t=await this.browser();if(this.refuseStopped(),i=this.lease,i?.revision!==this.revision){i&&this.retire(i);const s={revision:this.revision,session:this.prepared().then(n=>D.open({root:this.root,kinds:this.kinds,browser:t,prepared:n})),users:0,retired:!1};i=s,this.lease=s,s.session.catch(()=>{this.lease===s&&(this.lease=void 0)})}}i.users++;try{return await e(await i.session)}finally{i.users--,i.retired&&i.users===0&&this.end(i)}}refuseStopped(){if(this.closed)throw new c(h.unavailable,"allyhub dev is stopping.")}retire(e){e.retired=!0,this.lease===e&&(this.lease=void 0),this.old.add(e),e.users===0&&this.end(e)}end(e){return e.ended??=(async()=>{this.old.delete(e),await e.session.then(i=>i.close()).catch(()=>{})})(),e.ended}async close(){this.closed=!0;const e=[...this.old,...this.lease?[this.lease]:[]];this.lease&&this.retire(this.lease),await Promise.all(e.map(i=>this.end(i))),await this.browserStarted?.then(i=>i.close()).catch(()=>{}),await this.building,await f(this.buildDir,{recursive:!0,force:!0})}}
2
+ import{rm as m}from"node:fs/promises";import{join as u}from"node:path";import{startBrowser as w}from"@allyhub/browser";import{mediaHref as v,projectItems as b,sourceOf as g,stageItem as k}from"@allyhub/build";import{CACHE_DIR as S}from"@allyhub/formats";import{CheckSession as y,ProjectError as D,pickTarget as R,parseCombo as E}from"@allyhub/project";import{RPC_ERROR as d,RpcError as h,SNAPSHOT_TREE as l}from"@allyhub/protocol";import{prepareStage as P,viewStage as $}from"@allyhub/stage";import{ItemProcess as f}from"./item-process.js";import{Routes as C}from"./routes.js";export function rpcErrorOf(n){return n instanceof D?new h(n.kind==="not-found"?d.notFound:d.invalid,n.hint?`${n.message} ${n.hint}`:n.message):n}export class Live{root;buildDir;revision=0;prep;last;lease;old=new Set;browserStarted;gpu;building=Promise.resolve();closed=!1;codes=new Map;kinds;checks=new f;quick=new f;routes;constructor(e,i){this.root=e,this.kinds=i.kinds,this.buildDir=u(e,S,"build",`dev-${String(process.pid)}`),this.gpu=i.gpu,this.routes=new C({root:e,kinds:i.kinds,buildDir:this.buildDir,revision:()=>this.revision,prepared:()=>this.prepared(),latest:()=>this.latest(),view:(t,s)=>$(e,t,s,i.kinds),recordInputs:(t,s,r)=>{i.recordInputs?.(t,s,r)}})}moved(e){this.revision=e,this.lease&&this.lease.revision!==e&&this.retire(this.lease)}prepared(){const e=this.revision;if(this.prep?.revision===e)return this.prep.promise;const i=this.building.then(()=>e===this.revision?this.build():void 0);this.building=i.catch(()=>{});const t=i.then(s=>s??this.prepared());return this.prep={revision:e,promise:t},t.catch(()=>{this.prep?.promise===t&&(this.prep=void 0)}),t}async build(){const e=await P(this.root,this.pieceDir,this.kinds);return this.last=e,e}async itemCode(e){const i=await this.item(e);if(!i)return{failed:!1};const t=this.codes.get(e),s=t?.revision===this.revision?t.promise:this.quick.run({type:"code",root:this.root,kinds:this.kinds,item:i}).then(r=>r??{failed:!1}).catch(()=>{});return this.codes.set(e,{revision:this.revision,promise:s}),await s??{failed:!0}}async item(e){const{items:i}=await b(this.root,this.kinds);return i.find(t=>t.id===e)}get pieceDir(){return u(this.buildDir,"stage")}latest(){return this.last}async target(e,i){const t=await this.prepared();try{const{piece:s,target:r}=R(t,e,i===void 0?void 0:[E(i)]);return{prepared:t,piece:s,combo:r.combo}}catch(s){throw rpcErrorOf(s)}}async componentHost(e,i){const t=await this.prepared(),s=t.docs.find(o=>o.place===e||o.file===e);if(s){if(s.components.length===0)throw new h(d.notFound,`${s.place} shows no component.`);const o=t.messages.locales[0];return{prepared:t,host:s,combo:o===void 0?{}:{lang:o}}}const{piece:r,combo:c}=await this.target(e,i);return{prepared:t,host:r,combo:c}}async source(e){const i=await this.prepared(),t=k(i,e);if(!t)throw new h(d.notFound,`No piece ${e}.`);const s=g(i,t),r={...s.media},c=(o,a)=>`${o}${v(a).slice(l.media.length)}`;return await Promise.all(Object.entries(r).map(async([o,a])=>{let p=a;a.kind==="video"&&a.matte===!0&&(p={...p,matteUrl:c(l.matte,o)}),r[o]=await this.routes.mediaOf(o,p)})),{...s,media:r}}browser(){return this.refuseStopped(),this.browserStarted??=w(this.gpu===void 0?{}:{gpu:this.gpu}),this.browserStarted}async withSession(e){this.refuseStopped();let i=this.lease;if(i?.revision!==this.revision){i&&this.retire(i);const t=await this.browser();if(this.refuseStopped(),i=this.lease,i?.revision!==this.revision){i&&this.retire(i);const s={revision:this.revision,session:this.prepared().then(r=>y.open({root:this.root,kinds:this.kinds,browser:t,prepared:r})),users:0,retired:!1};i=s,this.lease=s,s.session.catch(()=>{this.lease===s&&(this.lease=void 0)})}}i.users++;try{return await e(await i.session)}finally{i.users--,i.retired&&i.users===0&&this.end(i)}}refuseStopped(){if(this.closed)throw new h(d.unavailable,"allyhub dev is stopping.")}retire(e){e.retired=!0,this.lease===e&&(this.lease=void 0),this.old.add(e),e.users===0&&this.end(e)}end(e){return e.ended??=(async()=>{this.old.delete(e),await e.session.then(i=>i.close()).catch(()=>{})})(),e.ended}async close(){this.closed=!0,this.checks.close(),this.quick.close();const e=[...this.old,...this.lease?[this.lease]:[]];this.lease&&this.retire(this.lease),await Promise.all(e.map(i=>this.end(i))),await this.browserStarted?.then(i=>i.close()).catch(()=>{}),await this.building,await m(this.buildDir,{recursive:!0,force:!0})}}
@@ -1,2 +1,21 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{once as S}from"node:events";import{createServer as v}from"node:http";import{posix as R}from"node:path";import{getRequestListener as P}from"@hono/node-server";import{pathProblem as x}from"./paths.js";import{forwarded as $}from"./ports.js";import{fileResponse as C}from"./respond.js";import{inside as L}from"./tree.js";export const PAGE_POLICY=["default-src 'self' data: blob:","script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:","style-src 'self' 'unsafe-inline'","img-src 'self' data: blob:","font-src 'self' data:","connect-src 'self' data: blob:","media-src 'self' data: blob:"].join("; "),NETWORK_PAGE_POLICY=["default-src 'self' data: blob: https:","script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: https:","style-src 'self' 'unsafe-inline' https:","img-src 'self' data: blob: https:","font-src 'self' data: https:","connect-src 'self' data: blob:","media-src 'self' data: blob: https:"].join("; "),PAGE_SOURCE="page";export class Pages{o;origins=new Map;constructor(n){this.o=n}async url(n,s,o,l={}){const a=await this.origin(s);a.pages.set(o,n),l.network===!0?a.network.add(o):a.network.delete(o);const d=a.port.url.endsWith("/")?a.port.url:`${a.port.url}/`,f=s===""?o:o.slice(s.length+1);return`${d}${f.split("/").map(encodeURIComponent).join("/")}`}origin(n){let s=this.origins.get(n);return s||(s=this.start(n),this.origins.set(n,s),s.catch(()=>{this.origins.get(n)===s&&this.origins.delete(n)})),s}async start(n){const{root:s,inputs:o}=this.o,l=new Map,a=new Set,d=new Map;let f=new Set;const g=r=>{let t;try{t=decodeURIComponent(r).replace(/^\/+/u,"")}catch{return}(t===""||t.endsWith("/"))&&(t=`${t}index.html`);const e=n===""?t:`${n}/${t}`;if(x(e)===void 0&&!e.split("/").some(c=>c.startsWith(".")))return R.normalize(e)},b=(r,t)=>{const e=l.get(r);if(e!==void 0){o.set(e,PAGE_SOURCE,[r]);for(const i of d.values())i.delete(e);return new Set([e])}let c;try{const i=t===void 0?void 0:new URL(t);i&&f.has(i.host)&&(c=g(i.pathname))}catch{c=void 0}if(c!==void 0){const i=l.get(c);if(i!==void 0)return new Set([i]);const u=d.get(c);if(u)return new Set(u)}return new Set(l.values())},y=P(async r=>{const t=new URL(r.url),e=g(t.pathname);if(e===void 0)return new Response("not found",{status:404});const c=b(e,r.headers.get("referer")??void 0),i=d.get(e)??new Set;for(const w of c)i.add(w),o.add(w,PAGE_SOURCE,e);d.set(e,i);const u=L(s,e);return u?C(u,r.headers.get("range")??void 0,{"content-security-policy":a.has(e)?NETWORK_PAGE_POLICY:PAGE_POLICY,"cache-control":"no-store","x-content-type-options":"nosniff"}):new Response("not found",{status:404})}),p=v((r,t)=>{if(!f.has(r.headers.host??"")){t.writeHead(403,{"content-type":"text/plain; charset=utf-8"}),t.end("forbidden host");return}y(r,t)});p.listen(0,"127.0.0.1"),await S(p,"listening");const h=p.address().port,m=$(this.o.ports,h);return f=new Set([`127.0.0.1:${String(h)}`,`localhost:${String(h)}`,...m.hosts,new URL(m.url).host]),{server:p,port:m,pages:l,network:a,loads:d}}async close(){const n=[...this.origins.values()];this.origins.clear();for(const s of n){const o=await s.catch(()=>{});o&&(o.port.dispose(),o.server.closeAllConnections(),await new Promise(l=>o.server.close(l)))}}}
2
+ import{once as x}from"node:events";import{createServer as P}from"node:http";import{readFile as v}from"node:fs/promises";import{posix as $}from"node:path";import{getRequestListener as L}from"@hono/node-server";import{ProjectError as O,projectTheme as C}from"@allyhub/build";import{pageWithTheme as k,projectThemeName as N,readPath as T,servedPage as j}from"@allyhub/formats";import{PAGE_SCROLLED as A,PAGE_SCROLL_TO as I}from"@allyhub/protocol";import{pathProblem as _}from"./paths.js";import{forwarded as U}from"./ports.js";import{fileResponse as D}from"./respond.js";import{hasErrorCode as G}from"./deletion.js";import{inside as M}from"./tree.js";export const PAGE_POLICY=["default-src 'self' data: blob:","script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:","style-src 'self' 'unsafe-inline'","img-src 'self' data: blob:","font-src 'self' data:","connect-src 'self' data: blob:","media-src 'self' data: blob:"].join("; "),NETWORK_PAGE_POLICY=["default-src 'self' data: blob: https:","script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: https:","style-src 'self' 'unsafe-inline' https:","img-src 'self' data: blob: https:","font-src 'self' data: https:","connect-src 'self' data: blob:","media-src 'self' data: blob: https:"].join("; "),FRAME_SCRIPT=`<script data-allyhub-frame>(() => {
3
+ if (window.parent === window) return;
4
+ let asked = false;
5
+ const say = () => {
6
+ asked = false;
7
+ parent.postMessage({ type: ${JSON.stringify(A)}, x: scrollX, y: scrollY }, "*");
8
+ };
9
+ addEventListener("scroll", () => {
10
+ if (asked) return;
11
+ asked = true;
12
+ requestAnimationFrame(say);
13
+ }, { passive: true });
14
+ addEventListener("message", (e) => {
15
+ const d = e.data;
16
+ if (e.source !== parent || !d || d.type !== ${JSON.stringify(I)}) return;
17
+ const go = () => scrollTo(Number(d.x) || 0, Number(d.y) || 0);
18
+ go();
19
+ if (document.readyState !== "complete") addEventListener("load", go, { once: true });
20
+ });
21
+ })();<\/script>`;export function framedPage(p){const e=/<head\b[^>]*>/iu.exec(p)??/<html\b[^>]*>/iu.exec(p),t=e?e.index+e[0].length:0;return`${p.slice(0,t)}${FRAME_SCRIPT}${p.slice(t)}`}export const PAGE_SOURCE="page";export class Pages{o;origins=new Map;constructor(e){this.o=e}async url(e,t,n,i={}){const o=await this.origin(t);o.pages.set(n,e),i.network===!0?o.network.add(n):o.network.delete(n);const d=o.port.url.endsWith("/")?o.port.url:`${o.port.url}/`,u=t===""?n:n.slice(t.length+1);return`${d}${u.split("/").map(encodeURIComponent).join("/")}`}origin(e){let t=this.origins.get(e);return t||(t=this.start(e),this.origins.set(e,t),t.catch(()=>{this.origins.get(e)===t&&this.origins.delete(e)})),t}async start(e){const{root:t,inputs:n}=this.o,i=new Map,o=new Set,d=new Map;let u=new Set;const w=a=>{let r;try{r=decodeURIComponent(a).replace(/^\/+/u,"")}catch{return}(r===""||r.endsWith("/"))&&(r=`${r}index.html`);const s=e===""?r:`${e}/${r}`;if(_(s)===void 0&&!s.split("/").some(f=>f.startsWith(".")))return $.normalize(s)},l=(a,r)=>{const s=i.get(a);if(s!==void 0){n.set(s,PAGE_SOURCE,[a]);for(const c of d.values())c.delete(s);return new Set([s])}let f;try{const c=r===void 0?void 0:new URL(r);c&&u.has(c.host)&&(f=w(c.pathname))}catch{f=void 0}if(f!==void 0){const c=i.get(f);if(c!==void 0)return new Set([c]);const g=d.get(f);if(g)return new Set(g)}return new Set(i.values())},y=L(async a=>{const r=new URL(a.url),s=w(r.pathname);if(s===void 0)return new Response("not found",{status:404});const f=l(s,a.headers.get("referer")??void 0),c=d.get(s)??new Set;for(const R of f)c.add(R),n.add(R,PAGE_SOURCE,s);d.set(s,c);const g=M(t,s);if(!g)return new Response("not found",{status:404});const S={"content-security-policy":o.has(s)?NETWORK_PAGE_POLICY:PAGE_POLICY,"cache-control":"no-store","x-content-type-options":"nosniff"},E=i.has(s)?await this.withData(s,f,await W(g,N(C(t))),g):void 0;return E!==void 0?new Response(E,{headers:{...S,"content-type":"text/html; charset=utf-8"}}):D(g,a.headers.get("range")??void 0,S)}),b=P((a,r)=>{if(!u.has(a.headers.host??"")){r.writeHead(403,{"content-type":"text/plain; charset=utf-8"}),r.end("forbidden host");return}y(a,r)});b.listen(0,"127.0.0.1"),await x(b,"listening");const h=b.address().port,m=U(this.o.ports,h);return u=new Set([`127.0.0.1:${String(h)}`,`localhost:${String(h)}`,...m.hosts,new URL(m.url).host]),{server:b,port:m,pages:i,network:o,loads:d}}async withData(e,t,n,i){const o=this.o.data;if(o===void 0||!/\.html?$/iu.test(e))return n;const d=n??await v(i,"utf8").catch(l=>{if(!G(l,"ENOENT","ENOTDIR","EISDIR"))throw l});if(!d?.includes("allyhub"))return n;let u;try{u=await o()}catch(l){if(l instanceof O)return n;throw l}const w=j(d,e,u.data);if(w.read.length===0)return n;for(const l of w.read){const y=T(e,l),b=u.items.find(h=>h.id===y||h.entry===y);for(const h of b?.files?.map(m=>m.path)??[y])for(const m of t)this.o.inputs.add(m,PAGE_SOURCE,h)}return w.html}async close(){const e=[...this.origins.values()];this.origins.clear();for(const t of e){const n=await t.catch(()=>{});n&&(n.port.dispose(),n.server.closeAllConnections(),await new Promise(i=>n.server.close(i)))}}}async function W(p,e){if(!/\.html?$/iu.test(p))return;const t=await v(p,"utf8").catch(()=>{});if(t===void 0)return;const n=e===void 0?void 0:k(t,e);return framedPage(n??t)}
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{isListedFile as v,itemNameOf as g,listedWork as T,listsFile as k,projectPath as S}from"@allyhub/formats";import{randomBytes as E}from"node:crypto";import{isAbsolute as y,relative as j,resolve as I,sep as P}from"node:path";import{AGENT_NAME as N,FILE_METHODS as R,HOST_METHODS as x,JSONRPC as h,PRESENCE_METHODS as D,PROJECT_TOOLS as l,RPC_ERROR as d,RequestSchema as M,RpcError as f,answer as p}from"@allyhub/protocol";import{listFiles as _,projectItems as C,readWork as F}from"@allyhub/build";import{Checker as A,Indexer as J}from"./background.js";import{TRASH_KEPT_DAYS as H,movesOfDeletion as L}from"./deletion.js";import{Exports as q}from"./exports.js";import{downloadsFolder as W,hasFileManager as B,revealFile as $}from"./reveal.js";import{Live as K}from"./live.js";import{Inputs as U}from"./inputs.js";import{Pages as Y}from"./pages.js";import{fileIn as O}from"./paths.js";import{kindContext as G}from"./kinds.js";import{Presence as V}from"./presence.js";import{Texts as X}from"./texts.js";import{contributedTool as z,contributedTools as Q,projectToolContext as Z,toolHandlers as ee}from"./tools.js";import{Watcher as te}from"./watcher.js";import{Writer as se}from"./writer.js";export const SERVER_METHODS={...R,"tools/call":x["tools/call"],...D};const ie=5e3,ne="sidebar";export class ProjectServer{root;writer;watcher;live;exports;presence;inputs=new U;pages;texts;placing=Promise.resolve();telling=Promise.resolve();listed;extensions;reveal;checker;serving;indexer;clients=new Map;contributed;services;held=new Map;unhearJobs;constructor(e){this.root=I(e.root),this.services={...e.jobs===void 0?{}:{jobs:e.jobs},...e.cloud===void 0?{}:{cloud:e.cloud},...e.env===void 0?{}:{env:e.env},...e.ports===void 0?{}:{ports:e.ports}},this.unhearJobs=e.jobs?.on(t=>{if(!y(t.about.id))return;const s=j(this.root,t.about.id);s===""||s.startsWith("..")||y(s)||this.notify("jobs/changed",{job:t,item:s.split(P).join("/")})})??(()=>{}),this.contributed=Q(e.kinds,e.extensions?.projectTools()??[]),this.extensions=e.extensions,this.live=new K(this.root,{kinds:e.kinds,...e.gpu===void 0?{}:{gpu:e.gpu},recordInputs:(t,s,r)=>{const n=[...r];this.listedItems().then(a=>{const c=a.find(u=>u.entry===t);c&&this.inputs.set(c.id,s,n)})}}),this.pages=new Y({root:this.root,ports:e.ports,inputs:this.inputs}),this.presence=new V(t=>{this.notify("presence/changed",{collaborators:t})}),this.texts=new X(this.root),this.watcher=new te(this.root,(t,s)=>{this.sendTo(this.watchOwner(t),"files/changed",{watch:t,changes:s})},(t,s)=>{this.live.moved(t),this.notify("project/changed",{revision:t}),this.checker?.schedule(),this.telling=this.telling.then(()=>this.tellItems(s))},{by:{kind:"agent",name:N},moved:t=>{this.placing=this.placing.then(()=>this.wroteOutside(t))}}),this.writer=new se(this.root,e.kinds,(t,s)=>{for(const r of t)this.texts.set(r.path,r.text);this.watcher.wrote(t.map(({path:r,version:n})=>({path:r,version:n})),s)},e.writable),this.reveal=e.reveal===!1?void 0:e.reveal??(B()?$:void 0),this.exports=new q(this.root,e.kinds,t=>{this.notify("export/changed",{job:t})},e.jobs===void 0?void 0:{jobs:e.jobs,nameOf:async t=>{const{items:s}=await this.tool("project/items",{}),r=s.find(n=>n.id===t);return g(r??{id:t})}},{...e.extensions?{processors:e.extensions.exportProcessors(),analyses:e.extensions.mediaAnalyses()}:{},...this.reveal===void 0||e.exportsTo===!1?{}:{saveTo:e.exportsTo??W}});const i=e.index??process.env.ALLYHUB_NO_INDEX!=="1";if(e.check!==!1){const t=i?new J({root:this.root,analyses:e.extensions?.mediaAnalyses()??[],env:e.env??process.env,emit:r=>{this.notify("index/changed",{jobs:r})},made:()=>{this.checker?.schedule(!0)}}):void 0;this.indexer=t;const s=e.extensions?.fileEditors();this.checker=new A({live:this.live,...s===void 0?{}:{files:s},emit:r=>{this.notify("check/changed",r)},...t?{needs:r=>{t.want(r)}}:{},...e.settle===void 0?{}:{settle:e.settle}})}}static open(e){const i=new ProjectServer(e);return i.watcher.start(),i.checker?.schedule(),i.texts.warm(),Promise.resolve(i)}async settled(){await this.watcher.settled(),await this.placing,await this.telling}async tellItems(e){if(e.length===0)return;const i=await this.listedItems();for(const[t,s]of this.inputs.affected(i,e))this.notify("items/changed",{item:t,paths:s})}async wroteOutside(e){let i;for(const s of e){const{changed:r,lines:n}=await this.texts.changed(s).catch(()=>({changed:!1,lines:void 0}));r&&(i={path:s,...n})}if(i===void 0)return;const t=await this.itemOf(i.path);this.presence.agent({doing:"editing",...t===void 0?{}:{item:t},source:i})}async itemOf(e){const i=await this.listedItems(),t=i.filter(s=>s.dir!==""&&e.startsWith(`${s.dir}/`)).sort((s,r)=>r.dir.length-s.dir.length);return(i.find(s=>s.entry===e)??i.find(s=>s.files!==void 0&&k(s.files,e))??t[0])?.id}async listedItems(){const e=Date.now();return this.listed!==void 0&&e-this.listed.at<ie||(this.listed={at:e,items:this.tool("project/items",{}).then(t=>t.items,()=>[])}),await this.listed?.items??[]}owners=new Map;watchOwner(e){return this.owners.get(e)}connect(e,i={}){const t=`c${E(6).toString("hex")}`;this.clients.set(t,e);const s=this.handlersFor(t,i.origin);return{id:t,receive:async r=>{const n=await this.answerOne(s,r);n&&e(n)},close:()=>{this.clients.delete(t),this.watcher.forget(t);for(const[r,n]of this.owners)n===t&&this.owners.delete(r)}}}channel(){const e=new Set,i=this.connect(t=>{const s=JSON.parse(JSON.stringify(t));queueMicrotask(()=>{for(const r of e)r(s)})});return{send:t=>{i.receive(JSON.parse(JSON.stringify(t)))},listen:t=>(e.add(t),()=>e.delete(t)),close:()=>{i.close()}}}notify(e,i){for(const t of this.clients.values())t({jsonrpc:h,method:e,params:i})}sendTo(e,i,t){e!==void 0&&this.clients.get(e)?.({jsonrpc:h,method:i,params:t})}async answerOne(e,i){const t=M.safeParse(i);if(!t.success){const r=i?.id;return typeof r!="string"&&typeof r!="number"?void 0:{jsonrpc:h,id:r,error:{code:d.invalidRequest,message:"Not a JSON-RPC request."}}}const s=t.data;return Object.hasOwn(x,s.method)&&s.method!=="tools/call"?{jsonrpc:h,id:s.id,error:{code:d.methodNotFound,message:`${s.method} is answered by the page that hosts the editor, not by allyhub dev's server.`}}:p(SERVER_METHODS,e,s)}handlersFor(e,i){const{writer:t,watcher:s}=this,r=this.toolSet(()=>this.serving?.tree(i));return{"files/read":({path:n})=>t.read(n),"files/write":async({path:n,text:a,over:c})=>({version:await t.write(n,a,c,e)}),"files/upload":async({dir:n,name:a,data:c})=>({path:await t.upload(n,a,Buffer.from(c,"base64"),e)}),"files/url":async({path:n})=>{if(await O(this.root,n),!this.serving)throw new f(d.unavailable,"This server serves no files over HTTP: only allyhub dev's does.");return{url:this.serving.file(i,n)}},"files/list":({dir:n})=>t.list(n),"files/move":async({from:n,to:a})=>({rewritten:await t.move(n,a,e)}),"files/remove":async({path:n})=>({trash:await t.remove(n,e)}),"files/trash":async()=>({entries:await t.trash()}),"files/restore":async({id:n})=>({path:await t.restore(n,e)}),"files/watch":async({paths:n})=>{for(const c of n)await O(this.root,c);const a=await s.watch(e,n);return this.owners.set(a,e),{watch:a}},"files/unwatch":({watch:n})=>(this.owners.get(n)===e&&(s.unwatch(n),this.owners.delete(n)),Promise.resolve({})),"tools/call":async({name:n,arguments:a})=>({result:await this.runTool(r,n,a)}),"presence/get":()=>Promise.resolve({collaborators:this.presence.list()})}}toolSet(e){const i=this.toolContext(e);return{core:ee(i),context:Z(i)}}async runTool(e,i,t){const s={jsonrpc:h,id:0,method:i,params:t},r=Object.hasOwn(l,i)?void 0:this.contributed.get(i);let n;if(r===void 0)n=await p(l,e.core,s);else{const a=await z(r).catch(c=>{throw new f(d.internal,c instanceof Error?c.message:String(c))});n=await p({[i]:a},{[i]:c=>a.run(c,e.context)},s)}if("error"in n)throw new f(n.error.code,n.error.message,n.error.data);return n.result}hasTool(e){return Object.hasOwn(l,e)||this.contributed.has(e)}toolContext(e){return{live:this.live,checker:this.checker,exports:this.exports,reveal:this.reveal,tree:e,extensions:this.extensions,services:this.services,held:this.held,kindContext:G(this.root,i=>this.hasTool(i),(i,t)=>this.tool(i,t)),inputs:this.inputs,pages:this.pages}}async tool(e,i,t={}){const s=await this.runTool(this.toolSet(()=>t.tree??this.serving?.tree(void 0)),e,i);return Object.hasOwn(l,e)?l[e].result.parse(s):s}async planDeletionOfItem(e){const i=await _(this.root),{listed:t}=await C(this.root,this.live.kinds,i,this.extensions?.fileEditors()??[]),s=t.find(o=>o.id===e);if(s===void 0)throw new f(d.notFound,`There is no item ${e}.`);const r=this.live.latest(),n=new Map((r?.items??[]).map(o=>[o.id,o.files])),a=o=>{const m=!v(o);return{id:o.id,entry:o.entry,ofKind:m,files:m?n.get(o.id):[{path:o.entry}],inputs:[...this.inputs.of(o.id)]}},{work:c}=await F(this.root),{moves:u,stays:b}=L({target:a(s),others:t.filter(o=>o.id!==e).map(a),listed:T(c).map(o=>S(o.file)).filter(o=>o!==s.entry),files:i}),w=r?.pieces.find(o=>o.place===e)?.title;return{item:e,name:g(s,typeof w=="string"?w:void 0),...v(s)?{}:{kind:s.kind},entry:s.entry,moves:u,stays:b}}deleteItemFromSidebar(e,i={}){return this.writer.moveToTrashAndUnlist({planNow:()=>this.planDeletionOfItem(e),keptDays:i.keptDays??H,...i.now===void 0?{}:{now:i.now}},ne)}async close(){this.unhearJobs(),this.presence.close(),this.watcher.close(),this.clients.clear();for(const e of[...this.held.values()].reverse())await Promise.resolve(e.dispose()).catch(()=>{});this.held.clear(),await this.pages.close(),await this.checker?.close(),await this.indexer?.close(),await this.exports.close(),await this.live.close()}}
2
+ import{isListedFile as m,itemNameOf as v,listedWork as T,listsFile as k,projectPath as S}from"@allyhub/formats";import{randomBytes as E}from"node:crypto";import{isAbsolute as g,relative as j,resolve as P,sep as I}from"node:path";import{AGENT_NAME as R,FILE_METHODS as N,HOST_METHODS as y,JSONRPC as c,PRESENCE_METHODS as M,PROJECT_TOOLS as h,RPC_ERROR as d,RequestSchema as C,RpcError as f,answer as u}from"@allyhub/protocol";import{listFiles as D,projectItems as F,readWork as _}from"@allyhub/build";import{Checker as J}from"./background.js";import{TRASH_KEPT_DAYS as A,movesOfDeletion as H}from"./deletion.js";import{Exports as q}from"./exports.js";import{downloadsFolder as W,hasFileManager as L,revealFile as $}from"./reveal.js";import{Live as B}from"./live.js";import{Inputs as K}from"./inputs.js";import{Pages as G}from"./pages.js";import{fileIn as x}from"./paths.js";import{kindContext as U}from"./kinds.js";import{Presence as V}from"./presence.js";import{Texts as Y}from"./texts.js";import{contributedTool as z,contributedTools as Q,projectToolContext as X,toolHandlers as Z}from"./tools.js";import{Watcher as ee}from"./watcher.js";import{Writer as te}from"./writer.js";export const SERVER_METHODS={...N,"tools/call":y["tools/call"],...M};const se=5e3,ie="sidebar";export class ProjectServer{root;writer;watcher;live;exports;presence;inputs=new K;pages;texts;placing=Promise.resolve();telling=Promise.resolve();listed;extensions;reveal;checker;serving;clients=new Map;contributed;services;held=new Map;unhearJobs;constructor(e){if(this.root=P(e.root),this.services={...e.jobs===void 0?{}:{jobs:e.jobs},...e.cloud===void 0?{}:{cloud:e.cloud},...e.env===void 0?{}:{env:e.env},...e.ports===void 0?{}:{ports:e.ports}},this.unhearJobs=e.jobs?.on(t=>{if(!g(t.about.id))return;const s=j(this.root,t.about.id);s===""||s.startsWith("..")||g(s)||this.notify("jobs/changed",{job:t,item:s.split(I).join("/")})})??(()=>{}),this.contributed=Q(e.kinds,e.extensions?.projectTools()??[]),this.extensions=e.extensions,this.live=new B(this.root,{kinds:e.kinds,...e.gpu===void 0?{}:{gpu:e.gpu},recordInputs:(t,s,i)=>{const n=[...i];this.listedItems().then(r=>{const o=r.find(l=>l.entry===t);o&&this.inputs.set(o.id,s,n)})}}),this.pages=new G({root:this.root,ports:e.ports,inputs:this.inputs,data:async()=>{const t=await this.live.prepared();return{data:t.data,items:t.items}}}),this.presence=new V(t=>{this.notify("presence/changed",{collaborators:t})}),this.texts=new Y(this.root),this.watcher=new ee(this.root,(t,s)=>{this.sendTo(this.watchOwner(t),"files/changed",{watch:t,changes:s})},(t,s)=>{this.live.moved(t),this.notify("project/changed",{revision:t}),this.checker?.schedule(),this.telling=this.telling.then(()=>this.tellItems(s))},{by:{kind:"agent",name:R},moved:t=>{this.placing=this.placing.then(()=>this.wroteOutside(t))}}),this.writer=new te(this.root,e.kinds,(t,s)=>{for(const i of t)this.texts.set(i.path,i.text);this.watcher.wrote(t.map(({path:i,version:n})=>({path:i,version:n})),s)},e.writable,(t,s)=>this.live.quick.run({type:"unreadable",kinds:e.kinds,kind:t,text:s})),this.reveal=e.reveal===!1?void 0:e.reveal??(L()?$:void 0),this.exports=new q(this.root,e.kinds,t=>{this.notify("export/changed",{job:t})},e.jobs===void 0?void 0:{jobs:e.jobs,nameOf:async t=>{const{items:s}=await this.tool("project/items",{}),i=s.find(n=>n.id===t);return v(i??{id:t})}},{...e.extensions?{processors:e.extensions.exportProcessors(),analyses:e.extensions.mediaAnalyses()}:{},...this.reveal===void 0||e.exportsTo===!1?{}:{saveTo:e.exportsTo??W}}),e.check!==!1){const t=e.extensions?.fileEditors();this.checker=new J({live:this.live,...t===void 0?{}:{files:t},emit:s=>{this.notify("check/changed",s)},...e.settle===void 0?{}:{settle:e.settle}})}}static open(e){const t=new ProjectServer(e);return t.watcher.start(),t.checker?.schedule(),t.texts.warm(),Promise.resolve(t)}async settled(){await this.watcher.settled(),await this.placing,await this.telling}async tellItems(e){if(e.length===0)return;const t=await this.listedItems();for(const[s,i]of this.inputs.affected(t,e))this.notify("items/changed",{item:s,paths:i})}async wroteOutside(e){let t;for(const i of e){const{changed:n,lines:r}=await this.texts.changed(i).catch(()=>({changed:!1,lines:void 0}));n&&(t={path:i,...r})}if(t===void 0)return;const s=await this.itemOf(t.path);this.presence.agent({doing:"editing",...s===void 0?{}:{item:s},source:t})}async itemOf(e){const t=await this.listedItems(),s=t.filter(i=>i.dir!==""&&e.startsWith(`${i.dir}/`)).sort((i,n)=>n.dir.length-i.dir.length);return(t.find(i=>i.entry===e)??t.find(i=>i.files!==void 0&&k(i.files,e))??s[0])?.id}async listedItems(){const e=Date.now();return this.listed!==void 0&&e-this.listed.at<se||(this.listed={at:e,items:this.tool("project/items",{}).then(s=>s.items,()=>[])}),await this.listed?.items??[]}owners=new Map;watchOwner(e){return this.owners.get(e)}connect(e,t={}){const s=`c${E(6).toString("hex")}`;this.clients.set(s,e);const i=this.handlersFor(s,t.origin);return{id:s,receive:async n=>{const r=await this.answerOne(i,n);r&&e(r)},close:()=>{this.clients.delete(s),this.watcher.forget(s);for(const[n,r]of this.owners)r===s&&this.owners.delete(n)}}}channel(){const e=new Set,t=this.connect(s=>{const i=JSON.parse(JSON.stringify(s));queueMicrotask(()=>{for(const n of e)n(i)})});return{send:s=>{t.receive(JSON.parse(JSON.stringify(s)))},listen:s=>(e.add(s),()=>e.delete(s)),close:()=>{t.close()}}}notify(e,t){for(const s of this.clients.values())s({jsonrpc:c,method:e,params:t})}sendTo(e,t,s){e!==void 0&&this.clients.get(e)?.({jsonrpc:c,method:t,params:s})}async answerOne(e,t){const s=C.safeParse(t);if(!s.success){const n=t?.id;return typeof n!="string"&&typeof n!="number"?void 0:{jsonrpc:c,id:n,error:{code:d.invalidRequest,message:"Not a JSON-RPC request."}}}const i=s.data;return Object.hasOwn(y,i.method)&&i.method!=="tools/call"?{jsonrpc:c,id:i.id,error:{code:d.methodNotFound,message:`${i.method} is answered by the page that hosts the editor, not by allyhub dev's server.`}}:u(SERVER_METHODS,e,i)}handlersFor(e,t){const{writer:s,watcher:i}=this,n=this.toolSet(()=>this.serving?.tree(t));return{"files/read":({path:r})=>s.read(r),"files/write":async({path:r,text:o,over:l})=>({version:await s.write(r,o,l,e)}),"files/upload":async({dir:r,name:o,data:l})=>({path:await s.upload(r,o,Buffer.from(l,"base64"),e)}),"files/url":async({path:r})=>{if(await x(this.root,r),!this.serving)throw new f(d.unavailable,"This server serves no files over HTTP: only allyhub dev's does.");return{url:this.serving.file(t,r)}},"files/list":({dir:r})=>s.list(r),"files/move":async({from:r,to:o})=>({rewritten:await s.move(r,o,e)}),"files/remove":async({path:r})=>({trash:await s.remove(r,e)}),"files/trash":async()=>({entries:await s.trash()}),"files/restore":async({id:r})=>({path:await s.restore(r,e)}),"files/watch":async({paths:r})=>{for(const l of r)await x(this.root,l);const o=await i.watch(e,r);return this.owners.set(o,e),{watch:o}},"files/unwatch":({watch:r})=>(this.owners.get(r)===e&&(i.unwatch(r),this.owners.delete(r)),Promise.resolve({})),"tools/call":async({name:r,arguments:o})=>({result:await this.runTool(n,r,o)}),"presence/get":()=>Promise.resolve({collaborators:this.presence.list()})}}toolSet(e){const t=this.toolContext(e);return{core:Z(t),context:X(t)}}async runTool(e,t,s){const i={jsonrpc:c,id:0,method:t,params:s},n=Object.hasOwn(h,t)?void 0:this.contributed.get(t);let r;if(n===void 0)r=await u(h,e.core,i);else{const o=await z(n).catch(l=>{throw new f(d.internal,l instanceof Error?l.message:String(l))});r=await u({[t]:o},{[t]:l=>o.run(l,e.context)},i)}if("error"in r)throw new f(r.error.code,r.error.message,r.error.data);return r.result}hasTool(e){return Object.hasOwn(h,e)||this.contributed.has(e)}toolContext(e){return{live:this.live,checker:this.checker,exports:this.exports,reveal:this.reveal,tree:e,extensions:this.extensions,services:this.services,held:this.held,kindContext:U(this.root,t=>this.hasTool(t),(t,s)=>this.tool(t,s)),inputs:this.inputs,pages:this.pages}}async tool(e,t,s={}){const i=await this.runTool(this.toolSet(()=>s.tree??this.serving?.tree(void 0)),e,t);return Object.hasOwn(h,e)?h[e].result.parse(i):i}async planDeletionOfItem(e){const t=await D(this.root),{listed:s}=await F(this.root,this.live.kinds,t,this.extensions?.fileEditors()??[]),i=s.find(a=>a.id===e);if(i===void 0)throw new f(d.notFound,`There is no item ${e}.`);const n=this.live.latest(),r=new Map((n?.items??[]).map(a=>[a.id,a.files])),o=a=>{const w=!m(a);return{id:a.id,entry:a.entry,ofKind:w,files:w?r.get(a.id):[{path:a.entry}],inputs:[...this.inputs.of(a.id)]}},{work:l}=await _(this.root),{moves:b,stays:O}=H({target:o(i),others:s.filter(a=>a.id!==e).map(o),listed:T(l).map(a=>S(a.file)).filter(a=>a!==i.entry),files:t}),p=n?.pieces.find(a=>a.place===e)?.title;return{item:e,name:v(i,typeof p=="string"?p:void 0),...m(i)?{}:{kind:i.kind},entry:i.entry,moves:b,stays:O}}deleteItemFromSidebar(e,t={}){return this.writer.moveToTrashAndUnlist({planNow:()=>this.planDeletionOfItem(e),keptDays:t.keptDays??A,...t.now===void 0?{}:{now:t.now}},ie)}async close(){this.unhearJobs(),this.presence.close(),this.watcher.close(),this.clients.clear();for(const e of[...this.held.values()].reverse())await Promise.resolve(e.dispose()).catch(()=>{});this.held.clear(),await this.pages.close(),await this.checker?.close(),await this.exports.close(),await this.live.close()}}
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{readFile as ne,readdir as ie,realpath as re,stat as ae}from"node:fs/promises";import{setTimeout as ce}from"node:timers/promises";import{join as P,relative as de,sep as fe}from"node:path";import{openPage as le}from"@allyhub/browser";import{KeyedStore as ue}from"@allyhub/project";import{NEVER_CANCELLED as pe}from"@allyhub/extension-api";import{COMPONENT_STILLS_MAX as V,KindSnapshotSchema as me,RpcError as X,SNAPSHOT_TREE as b,pieceSourcePath as he,snapshotAnswerPath as T,snapshotPreviewPath as we,stillPath as Q,stillsIndexKey as ge,stillsIndexPath as ye}from"@allyhub/protocol";import{runtimeFiles as be}from"@allyhub/stage-page";import{itemPreview as ke}from"./card.js";import{offlinePage as $e}from"./offline-page.js";import{kindContext as Se,kindItem as Ee}from"./kinds.js";import{USE_FORMS as Pe,mediaTypeOf as F}from"@allyhub/formats";import{Reach as ve,pieceBundle as Me,pieceNames as je,reachedCheck as Ie,reachedSource as Oe}from"./reach.js";import{matteFile as Te}from"./tree.js";const Ne="assets/";export const PAGE_RECORDING={width:1440,height:900,timeout:3e4,settle:1500};const N="https://tree.invalid/";function _(i){return typeof i=="string"?i.startsWith(N)?i.slice(N.length):i:Array.isArray(i)?i.map(_):i!==null&&typeof i=="object"?Object.fromEntries(Object.entries(i).map(([S,a])=>[S,_(a)])):i}const j=i=>new TextEncoder().encode(JSON.stringify(i));async function Y(i){return(await ie(i,{recursive:!0,withFileTypes:!0}).catch(()=>[])).filter(a=>a.isFile()).map(a=>de(i,P(a.parentPath,a.name)).split(fe).join("/"))}const xe=i=>ae(i).then(S=>S.isFile(),()=>!1);export async function recordTree(i,S={}){const{project:a}=i,{live:u,root:y}=a;await a.watcher.settled();const k=new Map,g=(e,t,o=F(e))=>{k.set(e,{path:e,type:o,file:t})},L=(e,t)=>{k.set(e,{path:e,type:F(e),file:t,immutable:!0})},v=(e,t,o=F(e))=>{k.set(e,{path:e,type:o,bytes:t})},W=async(e,t)=>{for(const o of await Y(t))g(`${e}${o}`,P(t,o))},Z=u.revision,d=await u.prepared(),x=new Map;if(i.ui!==void 0)for(const e of await Y(i.ui))(e.startsWith(Ne)?L:g)(`${b.editor}${e}`,P(i.ui,e));for(const[e,t]of await be())g(`${b.runtime}${e}`,t);const I=async(e,t)=>{let o;try{o={result:_(await a.tool(e,t,{tree:N}))}}catch(n){o={error:n instanceof X?{code:n.code,message:n.message}:{code:-32603,message:n instanceof Error?n.message:""}}}const r=T(e,t);v(r,j(o));const f=t.item;return typeof f=="string"&&x.set(f,[...x.get(f)??[],r]),o},ee=Se(y,e=>a.hasTool(e),async(e,t)=>{const o=await I(e,t);if(o.error)throw new X(o.error.code,o.error.message);return o.result}),te=async(e,t,o)=>{const r=new Map;for(const s of o)r.set(ge(s),s);if(r.size===0)return;const f=ue.of(y,"stills"),n={stills:{}},$=p.of(e),m=[...r];for(let s=0;s<m.length;s+=V){const l=m.slice(s,s+V);(await a.tool("components/stills",{item:e,...t===""?{}:{version:t},components:l.map(([,w])=>w)},{tree:N}).catch(()=>{}))?.stills.forEach((w,E)=>{const H=l[E]?.[0];!w||H===void 0||(n.stills[H]=w.key,g(Q(w.key),f.path(`${w.key}.webp`),"image/webp"),$?.tree.add(Q(w.key)))})}const c=ye(e,t);v(c,j(n),"application/json"),$?.tree.add(c)},B=(await I("project/items",{})).result,O=B?.items??[],R=O.filter(e=>e.kind!==void 0),C=O.filter(e=>e.kind===void 0&&e.kindInfo?.share===!0),oe=new Map(d.items.map(e=>[e.id,e.files])),p=new ve([...R.map(e=>({...e,files:oe.get(e.id)??e.files})),...C],d.files,(d.bundle?.beside??[]).map(e=>`${b.build}${e}`)),M=a.checker?.state,D=M===void 0||M.status==="waiting"||M.status==="running"?{status:"off",revision:u.revision,problems:M?.problems??[],facts:M?.facts??[]}:M;v(T("check/results",{}),j({result:D}));for(const e of p.items){const t=p.of(e),o=new Set(d.pieces.filter(n=>n.place===e).map(n=>n.id)),r=O.find(n=>n.id===e)?.entry,f=n=>n===r||p.itemsOf(n).includes(e);t?.own.push({path:T("project/items",{}),type:"application/json",bytes:j({result:{...B,items:O.filter(n=>n.id===e)}})},{path:T("check/results",{}),type:"application/json",bytes:j({result:Ie(D,o,f)})})}for(const e of d.bundle?.chunks.files??[])L(`${b.build}${e}`,P(u.pieceDir,e));for(const e of d.bundle?.beside??[])await W(`${b.build}${e}`,P(u.pieceDir,e));const q=new Set(Object.keys(d.media));for(const e of Object.keys(d.media)){const t=Te(y,d.media[e]);t!==void 0&&await xe(t)&&g(`${b.matte}${e}`,t,"video/mp4")}const A=new Map,G=new Map,se=a.extensions?.fileEditors()??[];for(const e of C)se.some(t=>t.id===e.kindInfo?.editor&&t.page)&&(A.set(e.id,{}),G.set(e.id,e.entry));const J=new Map,K=e=>({file:(t,o,r)=>{g(`${e}${t}`,o,r)},folder:(t,o)=>W(`${e}${t}`,o),bytes:(t,o,r)=>{v(`${e}${t}`,o,r)},media:t=>{q.add(t)}});for(const e of R){const t=await a.extensions?.kindProvider(e.kind);if(!t?.snapshot)continue;const o=await Promise.resolve(t.snapshot(Ee(e),ee,pe)).catch(()=>{}),r=me.safeParse(o??{});if(!r.success)continue;const{stills:f,shows:n,routes:$,page:m}=r.data;m&&A.set(e.id,{...m.folder===void 0?{}:{folder:m.folder},...m.file===void 0?{}:{file:m.file}}),n&&J.set(e.id,{media:new Set(n.media),data:new Set(n.data)});for(const c of f??[])await I("components/stage",{item:e.id,version:c.version}),c.version===""&&await I("components/stage",{item:e.id}),await te(e.id,c.version,c.components);for(const[c,s]of Object.entries($??{})){const l=await u.routes.route(c).catch(()=>{});if(l?.route.recordItem)for(const h of s)await l.route.recordItem(h,K(c),l.context).catch(()=>{})}}for(const e of q)g(`${b.media}${e}`,P(y,e));for(const[e,t]of A){const o=await a.tool("items/page",{item:e,...t}).catch(()=>{});if(!o)continue;const r=new URL(o.url).origin,f=G.get(e),n=await le(await u.browser(),{width:PAGE_RECORDING.width,height:PAGE_RECORDING.height,allow:s=>s===r||s.startsWith(`${r}/`)||f!==void 0&&s.startsWith("https://")}).catch(()=>{});if(!n)continue;const $=[],m=[];try{if(f!==void 0){const s=n.session,l=new Map;s.on("Network.responseReceived",h=>{h.response.url.startsWith("https://")&&h.response.status===200&&l.set(h.requestId,{url:h.response.url,mime:h.response.mimeType})}),s.on("Network.loadingFinished",h=>{const w=l.get(h.requestId);w&&m.push(s.send("Network.getResponseBody",{requestId:h.requestId}).then(E=>{$.push({...w,body:E.base64Encoded?Buffer.from(E.body,"base64"):new TextEncoder().encode(E.body)})},E=>{if(!(E instanceof Error))throw E}))}),await s.send("Network.enable",{})}await n.goto(o.url,{timeoutMs:PAGE_RECORDING.timeout}),await n.evaluate("document.fonts.ready.then(() => true)",{timeoutMs:PAGE_RECORDING.timeout}),await ce(PAGE_RECORDING.settle)}catch{}finally{await Promise.allSettled(m),await n.close()}if(f===void 0||$.length===0)continue;const c=await ne(P(y,f),"utf8").catch(()=>{});if(c!==void 0)for(const s of $e(f,c,$)){const l=`${b.pages}${s.path}`;v(l,s.bytes,s.type),p.of(e)?.tree.add(l)}}for(const e of p.items){const t=p.of(e);if(t)for(const o of a.inputs.of(e))if(o===""||o.endsWith("/"))for(const r of d.files)r.startsWith(o)&&t.files.add(r);else d.files.includes(o)&&t.files.add(o)}for(const e of u.routes.specs.keys()){const t=await u.routes.route(e).catch(()=>{});t?.route.record&&await t.route.record(K(e),t.context).catch(()=>{})}const U=[y,await re(y).catch(()=>y)];for(const e of d.pieces){const t=await u.source(e.id).catch(()=>{});if(!t)continue;const o=[e,...d.pieces.filter(s=>Re(d.items,e.place).has(s.place))],r=o.map(s=>({p:s,bundle:Me(d.bundle?.chunks,s.id)})),f={files:new Set(r.flatMap(s=>[...s.bundle.files])),modules:new Set(r.flatMap(s=>[...s.bundle.modules]))},n={media:new Set,data:new Set};for(const{p:s,bundle:l}of r){const h=je({prepared:d,piece:s,reach:p,modules:l.modules,roots:U,reads:a.checker?.reads.get(s.id),shows:J.get(s.place)});for(const w of h.media)n.media.add(w);for(const w of h.data)n.data.add(w)}const $=d.pieces.filter(s=>!o.includes(s)&&!U.some(l=>f.modules.has(P(l,s.file)))).map(s=>s.id),m=he(e.id);v(m,j(Oe(t,n,$)));const c=p.of(e.place);if(c){c.tree.add(m);for(const s of f.files)c.tree.add(`${b.build}${s}`);for(const s of n.media)c.tree.add(`${b.media}${s}`),c.tree.add(`${b.matte}${s}`),c.files.add(s)}}for(const[e,t]of x)for(const o of t)p.of(e)?.tree.add(o);for(const e of d.docs)for(const t of e.shows)p.of(e.place)?.files.add(t);for(const e of d.sheets)for(const t of e.files)p.of(e.place)?.files.add(t);const z=S.preview===!1?void 0:S.preview??(e=>ke(i,e));if(z)for(const e of R){const t=await z(e).catch(()=>{});if(t===void 0)continue;const o=we(e.id);v(o,Buffer.from(JSON.stringify(t)),"application/json"),p.of(e.id)?.tree.add(o)}return{revision:Z,files:[...k.values()],reach:p.done(new Set(k.keys())),routes:u.routes.loads()}}function Re(i,S){const a=new Map(i.map(k=>[k.id,k])),u=new Set,y=k=>{for(const g of a.get(k)?.uses??[])g.type===Pe.live&&!u.has(g.item)&&(u.add(g.item),y(g.item))};return y(S),u}
2
+ import{readFile as ie,readdir as re,realpath as ae,stat as ce}from"node:fs/promises";import{setTimeout as de}from"node:timers/promises";import{join as P,relative as fe,sep as le}from"node:path";import{openPage as ue}from"@allyhub/browser";import{KeyedStore as pe}from"@allyhub/project";import{NEVER_CANCELLED as me}from"@allyhub/extension-api";import{COMPONENT_STILLS_MAX as X,KindSnapshotSchema as he,RpcError as Q,SNAPSHOT_TREE as b,pieceSourcePath as we,snapshotAnswerPath as N,snapshotPreviewPath as ge,stillPath as Y,stillsIndexKey as ye,stillsIndexPath as be}from"@allyhub/protocol";import{runtimeFiles as ke}from"@allyhub/stage-page";import{itemPreview as $e}from"./card.js";import{offlinePage as Se}from"./offline-page.js";import{kindContext as Ee,kindItem as Pe}from"./kinds.js";import{USE_FORMS as ve,mediaTypeOf as W,servedPage as Me}from"@allyhub/formats";import{Reach as je,pieceBundle as Te,pieceNames as xe,reachedCheck as Ie,reachedSource as Oe}from"./reach.js";import{matteFile as Ne}from"./tree.js";const Re="assets/";export const PAGE_RECORDING={width:1440,height:900,timeout:3e4,settle:1500};const R="https://tree.invalid/";function B(i){return typeof i=="string"?i.startsWith(R)?i.slice(R.length):i:Array.isArray(i)?i.map(B):i!==null&&typeof i=="object"?Object.fromEntries(Object.entries(i).map(([S,c])=>[S,B(c)])):i}const T=i=>new TextEncoder().encode(JSON.stringify(i));async function Z(i){return(await re(i,{recursive:!0,withFileTypes:!0}).catch(()=>[])).filter(c=>c.isFile()).map(c=>fe(i,P(c.parentPath,c.name)).split(le).join("/"))}const Ae=i=>ce(i).then(S=>S.isFile(),()=>!1);export async function recordTree(i,S={}){const{project:c}=i,{live:p,root:y}=c;await c.watcher.settled();const k=new Map,g=(e,t,o=W(e))=>{k.set(e,{path:e,type:o,file:t})},C=(e,t)=>{k.set(e,{path:e,type:W(e),file:t,immutable:!0})},v=(e,t,o=W(e))=>{k.set(e,{path:e,type:o,bytes:t})},D=async(e,t)=>{for(const o of await Z(t))g(`${e}${o}`,P(t,o))},ee=p.revision,d=await p.prepared(),A=new Map;if(i.ui!==void 0)for(const e of await Z(i.ui))(e.startsWith(Re)?C:g)(`${b.editor}${e}`,P(i.ui,e));for(const[e,t]of await ke())g(`${b.runtime}${e}`,t);const I=async(e,t)=>{let o;try{o={result:B(await c.tool(e,t,{tree:R}))}}catch(n){o={error:n instanceof Q?{code:n.code,message:n.message}:{code:-32603,message:n instanceof Error?n.message:""}}}const r=N(e,t);v(r,T(o));const f=t.item;return typeof f=="string"&&A.set(f,[...A.get(f)??[],r]),o},te=Ee(y,e=>c.hasTool(e),async(e,t)=>{const o=await I(e,t);if(o.error)throw new Q(o.error.code,o.error.message);return o.result}),oe=async(e,t,o)=>{const r=new Map;for(const s of o)r.set(ye(s),s);if(r.size===0)return;const f=pe.of(y,"stills"),n={stills:{}},E=h.of(e),m=[...r];for(let s=0;s<m.length;s+=X){const w=m.slice(s,s+X);(await c.tool("components/stills",{item:e,...t===""?{}:{version:t},components:w.map(([,u])=>u)},{tree:R}).catch(()=>{}))?.stills.forEach((u,$)=>{const x=w[$]?.[0];!u||x===void 0||(n.stills[x]=u.key,g(Y(u.key),f.path(`${u.key}.webp`),"image/webp"),E?.tree.add(Y(u.key)))})}const a=be(e,t);v(a,T(n),"application/json"),E?.tree.add(a)},q=(await I("project/items",{})).result,O=q?.items??[],F=O.filter(e=>e.kind!==void 0),G=O.filter(e=>e.kind===void 0&&e.kindInfo?.share===!0),se=new Map(d.items.map(e=>[e.id,e.files])),h=new je([...F.map(e=>({...e,files:se.get(e.id)??e.files})),...G],d.files,(d.bundle?.beside??[]).map(e=>`${b.build}${e}`)),M=c.checker?.state,J=M===void 0||M.status==="waiting"||M.status==="running"?{status:"off",revision:p.revision,problems:M?.problems??[],facts:M?.facts??[]}:M;v(N("check/results",{}),T({result:J}));for(const e of h.items){const t=h.of(e),o=new Set(d.pieces.filter(n=>n.place===e).map(n=>n.id)),r=O.find(n=>n.id===e)?.entry,f=n=>n===r||h.itemsOf(n).includes(e);t?.own.push({path:N("project/items",{}),type:"application/json",bytes:T({result:{...q,items:O.filter(n=>n.id===e)}})},{path:N("check/results",{}),type:"application/json",bytes:T({result:Ie(J,o,f)})})}for(const e of d.bundle?.chunks.files??[])C(`${b.build}${e}`,P(p.pieceDir,e));for(const e of d.bundle?.beside??[])await D(`${b.build}${e}`,P(p.pieceDir,e));const K=new Set(Object.keys(d.media));for(const e of Object.keys(d.media)){const t=Ne(y,d.media[e]);t!==void 0&&await Ae(t)&&g(`${b.matte}${e}`,t,"video/mp4")}const _=new Map,L=new Map,ne=c.extensions?.fileEditors()??[];for(const e of G)ne.some(t=>t.id===e.kindInfo?.editor&&t.page)&&(_.set(e.id,{}),L.set(e.id,e.entry));const U=new Map,z=e=>({file:(t,o,r)=>{g(`${e}${t}`,o,r)},folder:(t,o)=>D(`${e}${t}`,o),bytes:(t,o,r)=>{v(`${e}${t}`,o,r)},media:t=>{K.add(t)}});for(const e of F){const t=await c.extensions?.kindProvider(e.kind);if(!t?.snapshot)continue;const o=await Promise.resolve(t.snapshot(Pe(e),te,me)).catch(()=>{}),r=he.safeParse(o??{});if(!r.success)continue;const{stills:f,shows:n,routes:E,page:m}=r.data;m&&(_.set(e.id,{...m.folder===void 0?{}:{folder:m.folder},...m.file===void 0?{}:{file:m.file}}),p.kinds.some(a=>a.id===e.kind&&a.network===!0)&&L.set(e.id,m.file??e.entry)),n&&U.set(e.id,{media:new Set(n.media),data:new Set(n.data)});for(const a of f??[])await I("components/stage",{item:e.id,version:a.version}),a.version===""&&await I("components/stage",{item:e.id}),await oe(e.id,a.version,a.components);for(const[a,s]of Object.entries(E??{})){const w=await p.routes.route(a).catch(()=>{});if(w?.route.recordItem)for(const l of s)await w.route.recordItem(l,z(a),w.context).catch(()=>{})}}for(const e of K)g(`${b.media}${e}`,P(y,e));for(const[e,t]of _){const o=await c.tool("items/page",{item:e,...t}).catch(()=>{});if(!o)continue;const r=new URL(o.url).origin,f=L.get(e),n=await ue(await p.browser(),{width:PAGE_RECORDING.width,height:PAGE_RECORDING.height,allow:l=>l===r||l.startsWith(`${r}/`)||f!==void 0&&l.startsWith("https://")}).catch(()=>{});if(!n)continue;const E=[],m=[];try{if(f!==void 0){const l=n.session,u=new Map;l.on("Network.responseReceived",$=>{$.response.url.startsWith("https://")&&$.response.status===200&&u.set($.requestId,{url:$.response.url,mime:$.response.mimeType})}),l.on("Network.loadingFinished",$=>{const x=u.get($.requestId);x&&m.push(l.send("Network.getResponseBody",{requestId:$.requestId}).then(j=>{E.push({...x,body:j.base64Encoded?Buffer.from(j.body,"base64"):new TextEncoder().encode(j.body)})},j=>{if(!(j instanceof Error))throw j}))}),await l.send("Network.enable",{})}await n.goto(o.url,{timeoutMs:PAGE_RECORDING.timeout}),await n.evaluate("document.fonts.ready.then(() => true)",{timeoutMs:PAGE_RECORDING.timeout}),await de(PAGE_RECORDING.settle)}catch{}finally{await Promise.allSettled(m),await n.close()}if(f===void 0)continue;const a=await ie(P(y,f),"utf8").catch(()=>{});if(a===void 0)continue;const s=Me(a,f,d.data).html;let w=Se(f,s,E);w.length===0&&s!==a&&(w=[{path:f,type:"text/html; charset=utf-8",bytes:new TextEncoder().encode(s)}]);for(const l of w){const u=`${b.pages}${l.path}`;v(u,l.bytes,l.type),h.of(e)?.tree.add(u)}}for(const e of h.items){const t=h.of(e);if(t)for(const o of c.inputs.of(e))if(o===""||o.endsWith("/"))for(const r of d.files)r.startsWith(o)&&t.files.add(r);else d.files.includes(o)&&t.files.add(o)}for(const e of p.routes.specs.keys()){const t=await p.routes.route(e).catch(()=>{});t?.route.record&&await t.route.record(z(e),t.context).catch(()=>{})}const H=[y,await ae(y).catch(()=>y)];for(const e of d.pieces){const t=await p.source(e.id).catch(()=>{});if(!t)continue;const o=[e,...d.pieces.filter(s=>Fe(d.items,e.place).has(s.place))],r=o.map(s=>({p:s,bundle:Te(d.bundle?.chunks,s.id)})),f={files:new Set(r.flatMap(s=>[...s.bundle.files])),modules:new Set(r.flatMap(s=>[...s.bundle.modules]))},n={media:new Set,data:new Set};for(const{p:s,bundle:w}of r){const l=xe({prepared:d,piece:s,reach:h,modules:w.modules,roots:H,reads:c.checker?.reads.get(s.id),shows:U.get(s.place)});for(const u of l.media)n.media.add(u);for(const u of l.data)n.data.add(u)}const E=d.pieces.filter(s=>!o.includes(s)&&!H.some(w=>f.modules.has(P(w,s.file)))).map(s=>s.id),m=we(e.id);v(m,T(Oe(t,n,E)));const a=h.of(e.place);if(a){a.tree.add(m);for(const s of f.files)a.tree.add(`${b.build}${s}`);for(const s of n.media)a.tree.add(`${b.media}${s}`),a.tree.add(`${b.matte}${s}`),a.files.add(s)}}for(const[e,t]of A)for(const o of t)h.of(e)?.tree.add(o);for(const e of d.docs)for(const t of e.shows)h.of(e.place)?.files.add(t);for(const e of d.sheets)for(const t of e.files)h.of(e.place)?.files.add(t);const V=S.preview===!1?void 0:S.preview??(e=>$e(i,e));if(V)for(const e of F){const t=await V(e).catch(()=>{});if(t===void 0)continue;const o=ge(e.id);v(o,Buffer.from(JSON.stringify(t)),"application/json"),h.of(e.id)?.tree.add(o)}return{revision:ee,files:[...k.values()],reach:h.done(new Set(k.keys())),routes:p.routes.loads()}}function Fe(i,S){const c=new Map(i.map(k=>[k.id,k])),p=new Set,y=k=>{for(const g of c.get(k)?.uses??[])g.type===ve.live&&!p.has(g.item)&&(p.add(g.item),y(g.item))};return y(S),p}
@@ -1,6 +1,6 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{randomBytes as F}from"node:crypto";import{readFile as D}from"node:fs/promises";import{createServer as J}from"node:http";import{join as M,resolve as C}from"node:path";import{getRequestListener as W}from"@hono/node-server";import{Hono as G}from"hono";import{WebSocketServer as K}from"ws";import{KeyedStore as Y}from"@allyhub/project";import{CollaboratorStateSchema as Q,PRESENCE_PATH as V,SNAPSHOT_TREE as $,TREE_PAGES as X,stageCsp as Z}from"@allyhub/protocol";import{runtimeFile as ee}from"@allyhub/stage-page";import{pathProblem as te}from"./paths.js";import{fileResponse as g}from"./respond.js";import{ProjectServer as ne}from"./project.js";import{STILL_NAME as re,inside as x,matteFile as oe,sourceName as se}from"./tree.js";export const RPC_PATH="/rpc",RAW_PATH="/files/raw/";const p={"access-control-allow-origin":"*"},L=/^[a-z][a-z0-9+.-]*:\/\/[a-z0-9.-]+(:\d{1,5})?$/u;export const PING_MS=3e4,ALLYHUB_FORWARDED="allyhub-forwarded";export function forwardedHost(n){const d=n[ALLYHUB_FORWARDED],y=(n.forwarded??(Array.isArray(d)?d[0]:d))?.split(",")[0]?.split(";").map(i=>i.trim().split("=")).find(([i])=>i?.toLowerCase()==="host")?.[1];if(y!==void 0)return y.replace(/^"(.*)"$/u,"$1");const u=n["x-forwarded-host"];return(Array.isArray(u)?u[0]:u)?.split(",")[0]?.trim()}export function frameSources(n){const d=["'self'","http://127.0.0.1:*","http://localhost:*"];if(n===void 0)return d;const a=new URL(n.replace("{port}","1")),y=new URL(n.replace("{port}","2"));if(a.port!==y.port)return[...d,`${a.protocol}//${a.hostname}:*`];const u=a.hostname.slice(a.hostname.indexOf(".")+1);return[...d,`${a.protocol}//*.${u}`]}export async function startDevServer(n){const d=C(n.root);if(n.embedder!==void 0&&!L.test(n.embedder))throw new Error(`Not an origin: ${n.embedder}`);if(n.publicOrigin!==void 0&&!L.test(n.publicOrigin.replace("{port}","1")))throw new Error(`Not an origin: ${n.publicOrigin}`);const a=n.token??F(18).toString("base64url"),u=`/s/${F(18).toString("base64url")}/`,i=await ne.open({...n,root:d,...n.publicOrigin===void 0?{}:{reveal:!1}});let f=0;const P=()=>f===0?void 0:n.publicOrigin?.replace("{port}",String(f)),v=()=>{const e=P();return e===void 0?void 0:new URL(e).host},E=()=>{const e=v();return new Set([`127.0.0.1:${String(f)}`,`localhost:${String(f)}`,...e===void 0?[]:[e]])},R=e=>e===v()?P()??"":`http://${e}`,N=e=>new URL(e.req.url).host,T=e=>R(N(e)),A=e=>{const t=v();t!==void 0&&forwardedHost(e.headers)===t&&(e.headers.host=t)},U=e=>e??`http://127.0.0.1:${String(f)}`;i.serving={file:(e,t)=>`${U(e)}${RAW_PATH}${t.split("/").map(encodeURIComponent).join("/")}?token=${encodeURIComponent(a)}`,tree:e=>`${U(e)}${u}`};const{routes:O}=i.live,b=new G,I=async e=>{if(!n.ui)return e.text("allyhub dev serves its editors here.",200);const t=await D(M(n.ui,"index.html"),"utf8").catch(()=>{});if(t===void 0)return e.text("The page's files are missing: build them first (pnpm --filter @allyhub/editor-web build).",500);const c=F(16).toString("base64");return e.html(t.replace(/<script/gu,`<script nonce="${c}"`).replace("</head>",`<meta name="allyhub-token" content="${a}"></head>`),200,{"content-security-policy":["default-src 'self'",`script-src 'self' 'nonce-${c}'`,"style-src 'self' 'unsafe-inline'","img-src 'self' data: blob:","media-src 'self' blob:","font-src 'self' data:",`connect-src 'self' ws://${N(e)}`,`frame-src ${frameSources(n.publicOrigin).join(" ")}`,`frame-ancestors ${n.embedder??"'none'"}`].join("; "),"cache-control":"no-store"})};b.get("/",I),b.post(V,async e=>{if(e.req.header("authorization")!==`Bearer ${a}`)return e.text("forbidden",403);const t=Q.safeParse(await e.req.json().catch(()=>{}));return t.success?(i.presence.agent(t.data),e.body(null,204)):e.text(t.error.message,400)}),b.get(`${RAW_PATH}*`,async e=>{if(e.req.query("token")!==a)return e.text("forbidden",403);const t=decodeURIComponent(e.req.path.slice(RAW_PATH.length));if(te(t)!==void 0)return e.text("forbidden",403);const c=x(d,t);return c?g(c,e.req.header("range"),{"x-content-type-options":"nosniff","content-security-policy":"sandbox; default-src 'none'; img-src 'self'; media-src 'self'; style-src 'unsafe-inline'"}):e.text("forbidden",403)}),b.get(`${u}*`,async e=>{let t;try{t=decodeURIComponent(e.req.path.slice(u.length))}catch{return e.notFound()}const c=e.req.header("range"),m=T(e),l=t.slice(0,t.indexOf("/")+1),s=t.slice(l.length);switch(l){case $.runtime:{const r=ee(s);if(!r)return e.notFound();const o=Object.values(X).includes(t);return g(r,void 0,{...p,...o?{"content-security-policy":Z(`${m}${u}`,[m,...n.embedder?[n.embedder]:[],...n.framers??[]],O.loads())}:{}})}case $.build:{const r=se(s);if(r===void 0){const o=x(i.live.pieceDir,s);return o?g(o,void 0,p):e.notFound()}try{return e.json(await i.live.source(r),200,{...p,"cache-control":"no-store"})}catch(o){return e.json({error:{message:o instanceof Error?o.message:String(o)}},404,p)}}case $.media:{const o=Object.hasOwn(i.live.latest()?.media??{},s)||O.allowed(s)?x(d,s):void 0;return o?g(o,c,p):e.notFound()}case $.matte:{const r=oe(d,i.live.latest()?.media[s]);return r?g(r,c,{...p,"content-type":"video/mp4"}):e.notFound()}case $.stills:return re.test(s)?g(Y.of(d,"stills").path(s),void 0,{...p,"cache-control":"public, max-age=31536000, immutable"}):e.notFound();default:try{const r=await O.route(l);if(!r)return await e.notFound();const o=new WeakSet,h=await r.route.serve({path:s,query:new URL(e.req.url).searchParams,file:async(B,q,z)=>{const j=x(B,q);if(!j)return;const k=await g(j,c,{...p,...z});return o.add(k),k}},r.context);return h?(!o.has(h)&&!h.headers.has("access-control-allow-origin")&&h.headers.set("access-control-allow-origin","*"),h):await e.notFound()}catch(r){return e.text(r instanceof Error?r.message:String(r),500,{...p})}}}),b.get("/*",async e=>{if(!n.ui)return e.notFound();const t=x(C(n.ui),decodeURIComponent(e.req.path.slice(1)));return t?g(t,void 0,{"cache-control":"public, max-age=3600"}):e.notFound()});const S=new K({noServer:!0,maxPayload:512*1024*1024});S.on("connection",(e,t)=>{const c=i.connect(r=>{e.readyState===e.OPEN&&e.send(JSON.stringify(r))},{origin:R(t.headers.host??"")});e.on("message",(r,o)=>{if(o||!Buffer.isBuffer(r))return;let h;try{h=JSON.parse(r.toString("utf8"))}catch{e.send(JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32700,message:"Not JSON."}}));return}c.receive(h)});const m=n.pingMs??PING_MS;let l=!0;e.on("pong",()=>{l=!0});const s=m>0?setInterval(()=>{if(!l){e.terminate();return}l=!1,e.ping()},m):void 0;s?.unref(),e.on("close",()=>{clearInterval(s),c.close()})});const H=W(b.fetch),_=(e,t)=>{e.writeHead(403,{"content-type":"text/plain; charset=utf-8"}),e.end(t)},w=J((e,t)=>{if(A(e),!E().has(e.headers.host??"")){_(t,"forbidden host");return}H(e,t)});w.on("upgrade",(e,t,c)=>{const m=new URL(e.url??"/","http://x"),l=(r,o)=>{t.end(`HTTP/1.1 ${String(r)} ${o}\r
2
+ import{randomBytes as F}from"node:crypto";import{readFile as D}from"node:fs/promises";import{createServer as J}from"node:http";import{join as M,resolve as C}from"node:path";import{getRequestListener as W}from"@hono/node-server";import{Hono as G}from"hono";import{WebSocketServer as K}from"ws";import{migrateProject as Y}from"@allyhub/build";import{KeyedStore as Q}from"@allyhub/project";import{CollaboratorStateSchema as V,PRESENCE_PATH as X,SNAPSHOT_TREE as $,TREE_PAGES as Z,stageCsp as ee}from"@allyhub/protocol";import{runtimeFile as te}from"@allyhub/stage-page";import{pathProblem as ne}from"./paths.js";import{fileResponse as g}from"./respond.js";import{ProjectServer as re}from"./project.js";import{STILL_NAME as oe,inside as x,matteFile as se,sourceName as ie}from"./tree.js";export const RPC_PATH="/rpc",RAW_PATH="/files/raw/";const p={"access-control-allow-origin":"*"},L=/^[a-z][a-z0-9+.-]*:\/\/[a-z0-9.-]+(:\d{1,5})?$/u;export const PING_MS=3e4,ALLYHUB_FORWARDED="allyhub-forwarded";export function forwardedHost(n){const a=n[ALLYHUB_FORWARDED],y=(n.forwarded??(Array.isArray(a)?a[0]:a))?.split(",")[0]?.split(";").map(i=>i.trim().split("=")).find(([i])=>i?.toLowerCase()==="host")?.[1];if(y!==void 0)return y.replace(/^"(.*)"$/u,"$1");const u=n["x-forwarded-host"];return(Array.isArray(u)?u[0]:u)?.split(",")[0]?.trim()}export function frameSources(n){const a=["'self'","http://127.0.0.1:*","http://localhost:*"];if(n===void 0)return a;const c=new URL(n.replace("{port}","1")),y=new URL(n.replace("{port}","2"));if(c.port!==y.port)return[...a,`${c.protocol}//${c.hostname}:*`];const u=c.hostname.slice(c.hostname.indexOf(".")+1);return[...a,`${c.protocol}//*.${u}`]}export async function startDevServer(n){const a=C(n.root);if(n.embedder!==void 0&&!L.test(n.embedder))throw new Error(`Not an origin: ${n.embedder}`);if(n.publicOrigin!==void 0&&!L.test(n.publicOrigin.replace("{port}","1")))throw new Error(`Not an origin: ${n.publicOrigin}`);const c=n.token??F(18).toString("base64url"),u=`/s/${F(18).toString("base64url")}/`;await Y(a,n.kinds);const i=await re.open({...n,root:a,...n.publicOrigin===void 0?{}:{reveal:!1}});let f=0;const P=()=>f===0?void 0:n.publicOrigin?.replace("{port}",String(f)),v=()=>{const e=P();return e===void 0?void 0:new URL(e).host},E=()=>{const e=v();return new Set([`127.0.0.1:${String(f)}`,`localhost:${String(f)}`,...e===void 0?[]:[e]])},R=e=>e===v()?P()??"":`http://${e}`,N=e=>new URL(e.req.url).host,T=e=>R(N(e)),A=e=>{const t=v();t!==void 0&&forwardedHost(e.headers)===t&&(e.headers.host=t)},j=e=>e??`http://127.0.0.1:${String(f)}`;i.serving={file:(e,t)=>`${j(e)}${RAW_PATH}${t.split("/").map(encodeURIComponent).join("/")}?token=${encodeURIComponent(c)}`,tree:e=>`${j(e)}${u}`};const{routes:O}=i.live,b=new G,I=async e=>{if(!n.ui)return e.text("allyhub dev serves its editors here.",200);const t=await D(M(n.ui,"index.html"),"utf8").catch(()=>{});if(t===void 0)return e.text("The page's files are missing: build them first (pnpm --filter @allyhub/editor-web build).",500);const d=F(16).toString("base64");return e.html(t.replace(/<script/gu,`<script nonce="${d}"`).replace("</head>",`<meta name="allyhub-token" content="${c}"></head>`),200,{"content-security-policy":["default-src 'self'",`script-src 'self' 'nonce-${d}'`,"style-src 'self' 'unsafe-inline'","img-src 'self' data: blob:","media-src 'self' blob:","font-src 'self' data:",`connect-src 'self' ws://${N(e)}`,`frame-src ${frameSources(n.publicOrigin).join(" ")}`,`frame-ancestors ${n.embedder??"'none'"}`].join("; "),"cache-control":"no-store"})};b.get("/",I),b.post(X,async e=>{if(e.req.header("authorization")!==`Bearer ${c}`)return e.text("forbidden",403);const t=V.safeParse(await e.req.json().catch(()=>{}));return t.success?(i.presence.agent(t.data),e.body(null,204)):e.text(t.error.message,400)}),b.get(`${RAW_PATH}*`,async e=>{if(e.req.query("token")!==c)return e.text("forbidden",403);const t=decodeURIComponent(e.req.path.slice(RAW_PATH.length));if(ne(t)!==void 0)return e.text("forbidden",403);const d=x(a,t);return d?g(d,e.req.header("range"),{"x-content-type-options":"nosniff","content-security-policy":"sandbox; default-src 'none'; img-src 'self'; media-src 'self'; style-src 'unsafe-inline'"}):e.text("forbidden",403)}),b.get(`${u}*`,async e=>{let t;try{t=decodeURIComponent(e.req.path.slice(u.length))}catch{return e.notFound()}const d=e.req.header("range"),m=T(e),l=t.slice(0,t.indexOf("/")+1),s=t.slice(l.length);switch(l){case $.runtime:{const r=te(s);if(!r)return e.notFound();const o=Object.values(Z).includes(t);return g(r,void 0,{...p,...o?{"content-security-policy":ee(`${m}${u}`,[m,...n.embedder?[n.embedder]:[],...n.framers??[]],O.loads())}:{}})}case $.build:{const r=ie(s);if(r===void 0){const o=x(i.live.pieceDir,s);return o?g(o,void 0,p):e.notFound()}try{return e.json(await i.live.source(r),200,{...p,"cache-control":"no-store"})}catch(o){return e.json({error:{message:o instanceof Error?o.message:String(o)}},404,p)}}case $.media:{const o=Object.hasOwn(i.live.latest()?.media??{},s)||O.allowed(s)?x(a,s):void 0;return o?g(o,d,p):e.notFound()}case $.matte:{const r=se(a,i.live.latest()?.media[s]);return r?g(r,d,{...p,"content-type":"video/mp4"}):e.notFound()}case $.stills:return oe.test(s)?g(Q.of(a,"stills").path(s),void 0,{...p,"cache-control":"public, max-age=31536000, immutable"}):e.notFound();default:try{const r=await O.route(l);if(!r)return await e.notFound();const o=new WeakSet,h=await r.route.serve({path:s,query:new URL(e.req.url).searchParams,file:async(B,q,z)=>{const k=x(B,q);if(!k)return;const U=await g(k,d,{...p,...z});return o.add(U),U}},r.context);return h?(!o.has(h)&&!h.headers.has("access-control-allow-origin")&&h.headers.set("access-control-allow-origin","*"),h):await e.notFound()}catch(r){return e.text(r instanceof Error?r.message:String(r),500,{...p})}}}),b.get("/*",async e=>{if(!n.ui)return e.notFound();const t=x(C(n.ui),decodeURIComponent(e.req.path.slice(1)));return t?g(t,void 0,{"cache-control":"public, max-age=3600"}):e.notFound()});const S=new K({noServer:!0,maxPayload:512*1024*1024});S.on("connection",(e,t)=>{const d=i.connect(r=>{e.readyState===e.OPEN&&e.send(JSON.stringify(r))},{origin:R(t.headers.host??"")});e.on("message",(r,o)=>{if(o||!Buffer.isBuffer(r))return;let h;try{h=JSON.parse(r.toString("utf8"))}catch{e.send(JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32700,message:"Not JSON."}}));return}d.receive(h)});const m=n.pingMs??PING_MS;let l=!0;e.on("pong",()=>{l=!0});const s=m>0?setInterval(()=>{if(!l){e.terminate();return}l=!1,e.ping()},m):void 0;s?.unref(),e.on("close",()=>{clearInterval(s),d.close()})});const H=W(b.fetch),_=(e,t)=>{e.writeHead(403,{"content-type":"text/plain; charset=utf-8"}),e.end(t)},w=J((e,t)=>{if(A(e),!E().has(e.headers.host??"")){_(t,"forbidden host");return}H(e,t)});w.on("upgrade",(e,t,d)=>{const m=new URL(e.url??"/","http://x"),l=(r,o)=>{t.end(`HTTP/1.1 ${String(r)} ${o}\r
3
3
  connection: close\r
4
4
  content-length: 0\r
5
5
  \r
6
- `)};A(e);const s=e.headers.host??"";if(!E().has(s)){l(403,"Forbidden");return}if(m.pathname!==RPC_PATH){l(404,"Not Found");return}if(e.headers.origin!==R(s)){l(403,"Forbidden");return}if(m.searchParams.get("token")!==a){l(403,"Forbidden");return}S.handleUpgrade(e,t,c,r=>{S.emit("connection",r,e)})});try{await new Promise((e,t)=>{w.once("error",t),w.listen(n.port??0,"127.0.0.1",()=>{e()})})}catch(e){throw await i.close(),e}return f=w.address().port,{url:`http://127.0.0.1:${String(f)}/`,port:f,token:a,tree:`http://127.0.0.1:${String(f)}${u}`,ui:n.ui,project:i,async close(){for(const e of S.clients)e.terminate();S.close(),await new Promise(e=>{w.closeAllConnections(),w.close(()=>{e()})}),await i.close()}}}
6
+ `)};A(e);const s=e.headers.host??"";if(!E().has(s)){l(403,"Forbidden");return}if(m.pathname!==RPC_PATH){l(404,"Not Found");return}if(e.headers.origin!==R(s)){l(403,"Forbidden");return}if(m.searchParams.get("token")!==c){l(403,"Forbidden");return}S.handleUpgrade(e,t,d,r=>{S.emit("connection",r,e)})});try{await new Promise((e,t)=>{w.once("error",t),w.listen(n.port??0,"127.0.0.1",()=>{e()})})}catch(e){throw await i.close(),e}return f=w.address().port,{url:`http://127.0.0.1:${String(f)}/`,port:f,token:c,tree:`http://127.0.0.1:${String(f)}${u}`,ui:n.ui,project:i,async close(){for(const e of S.clients)e.terminate();S.close(),await new Promise(e=>{w.closeAllConnections(),w.close(()=>{e()})}),await i.close()}}}
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{createHash as M}from"node:crypto";import{access as y,stat as F}from"node:fs/promises";import{basename as N,join as b,posix as E}from"node:path";import{pathToFileURL as _}from"node:url";import{inTime as T,listWork as D,projectItems as h,stageId as H}from"@allyhub/build";import{NEVER_CANCELLED as W}from"@allyhub/extension-api";import{OUT_DIR as U,fileEditorIn as j,isListedFile as R,listedFileIdOf as A,unscanned as S,WORK_FILE as K}from"@allyhub/formats";import{OpenedVersion as V,componentStills as q,itemDigests as G,keyedStills as z,parseCombo as B}from"@allyhub/project";import{runtimeFile as J,stageFiles as Q}from"@allyhub/stage-page";import{RPC_ERROR as f,RpcError as c,SNAPSHOT_TREE as I,TREE_PAGES as P,listedFileEditor as g,listedKind as $,stillPath as X}from"@allyhub/protocol";import{comboKey as Y,componentRefText as Z}from"@allyhub/piece";import{providedPreview as ee}from"./card.js";import{kindItem as te}from"./kinds.js";import{rpcErrorOf as x}from"./live.js";import{pathProblem as ne}from"./paths.js";import{forwarded as oe}from"./ports.js";import{inside as ie}from"./tree.js";const re=n=>M("sha256").update(n).digest("base64url").slice(0,16);async function O(n,t,o){const e=t.replace(/^\.\//u,""),i=(await h(n.live.root,n.live.kinds)).items.find(u=>u.id===e||u.entry===e),s=i?void 0:await se(n,e),r=i?.id??s;if(r===void 0)throw new c(f.notFound,`There is no item ${t} in the project's list, nor a file of the project an editor opens.`);const d=(o.folder??"").replace(/\/+$/u,""),a=o.file??i?.entry??r;if(d!==""&&!a.startsWith(`${d}/`))throw new c(f.invalid,`${a} is not in the folder ${d} the page is served from.`);return n.pages.url(r,d,a,{network:s!==void 0})}async function se(n,t){if(S(t)||ne(t)!==void 0||!j(n.extensions?.fileEditors()??[],t))return;const o=ie(n.live.root,t);return o&&await F(o).then(i=>i.isFile(),()=>!1)?A(t):void 0}const v=(n,t)=>{const o=n.tree();if(o===void 0)throw new c(f.unavailable,"This server serves no pages: only allyhub dev's does.");return new URL(t,o).href},C=(n,t,o)=>({url:v(n,`${t}?${o.toString()}`),probe:v(n,P.probe)});async function ae(n,t,o){if(t.title!==void 0)return t.title;const e=await n.extensions?.kindProvider(t.kind);if(!e?.title)return(await o()).get(t.id);try{const i=await e.title(te(t),n.kindContext,W);return typeof i=="string"?i:void 0}catch{return}}export function contributedTools(n,t=[]){const o=new Map;for(const e of n)for(const i of e.projectTools??[])o.has(i.name)||o.set(i.name,i);for(const e of t)o.has(e.name)||o.set(e.name,e);return o}const k=new Map;export async function contributedTool(n){let t=k.get(n.module);t||(t=import(_(n.module).href).then(e=>{if(typeof e.default!="object"||e.default===null)throw new Error(`${n.extension}'s project tools (${n.module}) have no default export.`);return e.default}),k.set(n.module,t),t.catch(()=>{k.get(n.module)===t&&k.delete(n.module)}));const o=(await t)[n.name];if(!o)throw new Error(`${n.extension} contributes the project tool "${n.name}" but its module (${n.module}) has none of that name.`);return o}export function projectToolContext(n){const{live:t}=n,o=new Map;return{root:t.root,kinds:t.kinds,prepared:()=>t.prepared(),target:(e,i)=>t.target(e,i),itemCode:e=>t.itemCode(e),items:async()=>(await h(t.root,t.kinds)).items,async version(e,i,s,r){try{return await t.withSession(async d=>{const a=await V.open({root:t.root,item:e,...i===void 0?{}:{combos:[B(i)]},purpose:s,session:d});try{return await r(a)}finally{await a.close()}})}catch(d){throw x(d)}},async componentStills(e,i,s){try{const r=await t.prepared(),{gpu:d}=await t.browser();return await z(i,{prepared:r,item:e,combo:s,gpu:d,withSession:a=>t.withSession(a)})}catch(r){throw x(r)}},served:e=>v(n,e),page:(e,i)=>C(n,e,i),buildDir:t.pieceDir,stageStyles:()=>Q().fontCss.flatMap(e=>{const i=J(e);return i===void 0?[]:[{file:i,url:v(n,`${I.runtime}${e}`)}]}),kept(e,i){return o.has(e)||o.set(e,i()),o.get(e)},held(e,i){return n.held.has(e)||n.held.set(e,i()),n.held.get(e)},jobs:n.services.jobs,cloud:n.services.cloud,env:n.services.env??process.env,forward:e=>oe(n.services.ports,e),pageOf:(e,i={})=>O(n,e,i),recordInputs:(e,i,s)=>{n.inputs.set(e,i,s)}}}export function toolHandlers(n){const{live:t}=n;return{"project/items":async()=>{const o=await h(t.root,t.kinds,void 0,n.extensions?.fileEditors()??[]);let e;const i=()=>e??=(async()=>{const a=await t.prepared().catch(()=>t.latest()),u=new Map;for(const l of a?.pieces??[]){const p=typeof l.title=="string"?l.title:void 0;p&&u.set(l.place,p)}return u})(),s=new Map((t.latest()?.items??[]).map(a=>[a.id,a.files])),r=n.extensions?.fileEditors()??[];return{items:await Promise.all(o.listed.map(async a=>{const u={id:a.id,dir:a.dir,entry:a.entry,...a.title===void 0?{}:{title:a.title},groups:a.groups};if(R(a)){const w=r.find(L=>L.id===a.editor);return{...u,...w?{kindInfo:g(w)}:{}}}const l=await ae(n,a,i),p=t.kinds.find(w=>w.id===a.kind),m=s.get(a.id);return{...u,kind:a.kind,...l?{title:l}:{},...m?{files:m}:{},...p?{kindInfo:$(p)}:{}}})),kinds:t.kinds.map(a=>({id:a.id,...$(a)})),name:N(t.root),scope:re(t.root),revision:t.revision}},"project/file":async({path:o})=>{const e=o.replace(/^\.\//u,""),i=n.extensions?.fileEditors()??[],r=(await h(t.root,t.kinds,void 0,i)).listed.find(l=>l.entry===e||l.id===e);if(r){const l={id:r.id,dir:r.dir,entry:r.entry,...r.title===void 0?{}:{title:r.title},groups:r.groups};if(R(r)){const m=i.find(w=>w.id===r.editor);return{item:{...l,...m?{kindInfo:g(m)}:{}}}}const p=t.kinds.find(m=>m.id===r.kind);return{item:{...l,kind:r.kind,...p?{kindInfo:$(p)}:{}}}}const d=!S(e)&&await F(b(t.root,e)).then(l=>l.isFile(),()=>!1),a=d?j(i,e):void 0;if(!a)throw new c(f.notFound,d?`No editor opens ${e} by its name.`:`The project has no file ${e}.`);const u=E.dirname(e);return{item:{id:e,dir:u==="."?"":u,entry:e,groups:[],kindInfo:g(a)}}},"items/preview":async({item:o})=>{const e=o.replace(/^\.\//u,""),i=(await h(t.root,t.kinds)).items.find(r=>r.id===e||r.entry===e);if(!i)throw new c(f.notFound,`There is no item ${o} in the project's list.`);const s=await ee(n.extensions,i,n.kindContext);return s===void 0?{}:{preview:s}},"items/page":async({item:o,folder:e,file:i})=>({url:await O(n,o,{folder:e,file:i})}),"work/add":async({kind:o,file:e,title:i})=>{if(!t.kinds.some(s=>s.id===o))throw new c(f.invalid,`No extension here contributes the kind ${o}.`);return await y(b(t.root,e)).catch(()=>{throw new c(f.notFound,`There is no file ${e} to list in ${K}.`)}),await D(t.root,{kind:o,file:e,...i===void 0?{}:{title:i}}),{}},"components/list":async({item:o})=>{const e=await t.prepared(),i=e.items.find(s=>s.id===o||s.entry===o)?.dir??o;return{components:e.components.map(s=>{const r=E.relative(i,s.file);return{of:Z({path:r.startsWith(".")?r:`./${r}`,name:s.export}),name:s.name,...s.label===void 0?{}:{label:s.label}}})}},"components/stage":async({item:o,version:e})=>{const{prepared:i,host:s,combo:r}=await t.componentHost(o,e);if(!("components"in s)&&T(s,i.kinds))throw new c(f.notFound,`${o} has no components to draw alone: a deck's or a doc's are.`);const{code:d}=await G(i,s),a=new URLSearchParams({piece:H(s),combo:Y(r),mode:"component",code:d.slice(0,16)});return C(n,P.stage,a)},"components/stills":async({item:o,version:e,components:i})=>{v(n,I.stills);try{const{prepared:s,host:r,combo:d}=await t.componentHost(o,e);if(!("components"in r)&&T(r,s.kinds))throw new c(f.notFound,`${o} has no components to draw alone: a deck's or a doc's are.`);const{gpu:a}=await t.browser();return{stills:(await q(i,{prepared:s,item:r,combo:d,gpu:a,withSession:l=>t.withSession(l)})).map(({key:l})=>({key:l,url:v(n,X(l))}))}}catch(s){throw x(s)}},"check/results":()=>Promise.resolve(n.checker?.state??{status:"off",revision:t.revision,problems:[],facts:[]}),"check/run":()=>{if(!n.checker)throw new c(f.unavailable,"This server runs no check.");return n.checker.schedule(!0),Promise.resolve({})},"export/start":async({item:o,versions:e,types:i,options:s})=>{const{items:r}=await h(t.root,t.kinds);if(!r.some(d=>d.id===o))throw new c(f.notFound,`There is no item ${o}.`);return{job:n.exports.start(o,e??[],i??[],s)}},"export/cancel":({job:o})=>{if(!n.exports.cancel(o))throw new c(f.notFound,`No export ${o} is under way.`);return Promise.resolve({})},"export/list":()=>Promise.resolve({jobs:n.exports.list(),reveal:n.reveal!==void 0}),"export/reveal":async({path:o})=>{if(!n.reveal)throw new c(f.unavailable,"This server is not on the person's computer: download the file.");if(!o.startsWith(`${U}/`))throw new c(f.notFound,`${o} is no exported file.`);const e=n.exports.savedOf(o),i=e!==void 0&&await y(e).then(()=>!0,()=>!1)?e:b(t.root,o);return await y(i).catch(()=>{throw new c(f.notFound,`There is no file ${o}.`)}),await n.reveal(i),{}}}}
2
+ import{createHash as M}from"node:crypto";import{access as y,stat as F}from"node:fs/promises";import{basename as N,join as b,posix as E}from"node:path";import{pathToFileURL as _}from"node:url";import{inTime as T,listWork as D,projectItems as h,stageId as H}from"@allyhub/build";import{NEVER_CANCELLED as W}from"@allyhub/extension-api";import{OUT_DIR as U,fileEditorIn as j,isListedFile as R,listedFileIdOf as A,unscanned as S,WORK_FILE as K}from"@allyhub/formats";import{OpenedVersion as V,componentStills as q,itemDigests as G,keyedStills as z,parseCombo as B}from"@allyhub/project";import{runtimeFile as J,stageFiles as Q}from"@allyhub/stage-page";import{RPC_ERROR as f,RpcError as c,SNAPSHOT_TREE as I,TREE_PAGES as P,listedFileEditor as g,listedKind as $,stillPath as X}from"@allyhub/protocol";import{comboKey as Y,componentRefText as Z}from"@allyhub/piece";import{providedPreview as ee}from"./card.js";import{kindItem as te}from"./kinds.js";import{rpcErrorOf as x}from"./live.js";import{pathProblem as ne}from"./paths.js";import{forwarded as oe}from"./ports.js";import{inside as ie}from"./tree.js";const re=n=>M("sha256").update(n).digest("base64url").slice(0,16);async function O(n,t,o){const e=t.replace(/^\.\//u,""),i=(await h(n.live.root,n.live.kinds)).items.find(d=>d.id===e||d.entry===e),s=i?void 0:await se(n,e),r=i?.id??s;if(r===void 0)throw new c(f.notFound,`There is no item ${t} in the project's list, nor a file of the project an editor opens.`);const l=(o.folder??"").replace(/\/+$/u,""),a=o.file??i?.entry??r;if(l!==""&&!a.startsWith(`${l}/`))throw new c(f.invalid,`${a} is not in the folder ${l} the page is served from.`);const u=s!==void 0||n.live.kinds.some(d=>d.id===i?.kind&&d.network===!0);return n.pages.url(r,l,a,{network:u})}async function se(n,t){if(S(t)||ne(t)!==void 0||!j(n.extensions?.fileEditors()??[],t))return;const o=ie(n.live.root,t);return o&&await F(o).then(i=>i.isFile(),()=>!1)?A(t):void 0}const v=(n,t)=>{const o=n.tree();if(o===void 0)throw new c(f.unavailable,"This server serves no pages: only allyhub dev's does.");return new URL(t,o).href},C=(n,t,o)=>({url:v(n,`${t}?${o.toString()}`),probe:v(n,P.probe)});async function ae(n,t,o){if(t.title!==void 0)return t.title;const e=await n.extensions?.kindProvider(t.kind);if(!e?.title)return(await o()).get(t.id);try{const i=await e.title(te(t),n.kindContext,W);return typeof i=="string"?i:void 0}catch{return}}export function contributedTools(n,t=[]){const o=new Map;for(const e of n)for(const i of e.projectTools??[])o.has(i.name)||o.set(i.name,i);for(const e of t)o.has(e.name)||o.set(e.name,e);return o}const k=new Map;export async function contributedTool(n){let t=k.get(n.module);t||(t=import(_(n.module).href).then(e=>{if(typeof e.default!="object"||e.default===null)throw new Error(`${n.extension}'s project tools (${n.module}) have no default export.`);return e.default}),k.set(n.module,t),t.catch(()=>{k.get(n.module)===t&&k.delete(n.module)}));const o=(await t)[n.name];if(!o)throw new Error(`${n.extension} contributes the project tool "${n.name}" but its module (${n.module}) has none of that name.`);return o}export function projectToolContext(n){const{live:t}=n,o=new Map;return{root:t.root,kinds:t.kinds,prepared:()=>t.prepared(),target:(e,i)=>t.target(e,i),itemCode:e=>t.itemCode(e),items:async()=>(await h(t.root,t.kinds)).items,async version(e,i,s,r){try{return await t.withSession(async l=>{const a=await V.open({root:t.root,item:e,...i===void 0?{}:{combos:[B(i)]},purpose:s,session:l});try{return await r(a)}finally{await a.close()}})}catch(l){throw x(l)}},async componentStills(e,i,s){try{const r=await t.prepared(),{gpu:l}=await t.browser();return await z(i,{prepared:r,item:e,combo:s,gpu:l,withSession:a=>t.withSession(a)})}catch(r){throw x(r)}},served:e=>v(n,e),page:(e,i)=>C(n,e,i),buildDir:t.pieceDir,stageStyles:()=>Q().fontCss.flatMap(e=>{const i=J(e);return i===void 0?[]:[{file:i,url:v(n,`${I.runtime}${e}`)}]}),kept(e,i){return o.has(e)||o.set(e,i()),o.get(e)},held(e,i){return n.held.has(e)||n.held.set(e,i()),n.held.get(e)},jobs:n.services.jobs,cloud:n.services.cloud,env:n.services.env??process.env,forward:e=>oe(n.services.ports,e),pageOf:(e,i={})=>O(n,e,i),recordInputs:(e,i,s)=>{n.inputs.set(e,i,s)}}}export function toolHandlers(n){const{live:t}=n;return{"project/items":async()=>{const o=await h(t.root,t.kinds,void 0,n.extensions?.fileEditors()??[]);let e;const i=()=>e??=(async()=>{const a=await t.prepared().catch(()=>t.latest()),u=new Map;for(const d of a?.pieces??[]){const p=typeof d.title=="string"?d.title:void 0;p&&u.set(d.place,p)}return u})(),s=new Map((t.latest()?.items??[]).map(a=>[a.id,a.files])),r=n.extensions?.fileEditors()??[];return{items:await Promise.all(o.listed.map(async a=>{const u={id:a.id,dir:a.dir,entry:a.entry,...a.title===void 0?{}:{title:a.title},groups:a.groups};if(R(a)){const w=r.find(L=>L.id===a.editor);return{...u,...w?{kindInfo:g(w)}:{}}}const d=await ae(n,a,i),p=t.kinds.find(w=>w.id===a.kind),m=s.get(a.id);return{...u,kind:a.kind,...d?{title:d}:{},...m?{files:m}:{},...p?{kindInfo:$(p)}:{}}})),kinds:t.kinds.map(a=>({id:a.id,...$(a)})),name:N(t.root),scope:re(t.root),revision:t.revision}},"project/file":async({path:o})=>{const e=o.replace(/^\.\//u,""),i=n.extensions?.fileEditors()??[],r=(await h(t.root,t.kinds,void 0,i)).listed.find(d=>d.entry===e||d.id===e);if(r){const d={id:r.id,dir:r.dir,entry:r.entry,...r.title===void 0?{}:{title:r.title},groups:r.groups};if(R(r)){const m=i.find(w=>w.id===r.editor);return{item:{...d,...m?{kindInfo:g(m)}:{}}}}const p=t.kinds.find(m=>m.id===r.kind);return{item:{...d,kind:r.kind,...p?{kindInfo:$(p)}:{}}}}const l=!S(e)&&await F(b(t.root,e)).then(d=>d.isFile(),()=>!1),a=l?j(i,e):void 0;if(!a)throw new c(f.notFound,l?`No editor opens ${e} by its name.`:`The project has no file ${e}.`);const u=E.dirname(e);return{item:{id:e,dir:u==="."?"":u,entry:e,groups:[],kindInfo:g(a)}}},"items/preview":async({item:o})=>{const e=o.replace(/^\.\//u,""),i=(await h(t.root,t.kinds)).items.find(r=>r.id===e||r.entry===e);if(!i)throw new c(f.notFound,`There is no item ${o} in the project's list.`);const s=await ee(n.extensions,i,n.kindContext);return s===void 0?{}:{preview:s}},"items/page":async({item:o,folder:e,file:i})=>({url:await O(n,o,{folder:e,file:i})}),"work/add":async({kind:o,file:e,title:i})=>{if(!t.kinds.some(s=>s.id===o))throw new c(f.invalid,`No extension here contributes the kind ${o}.`);return await y(b(t.root,e)).catch(()=>{throw new c(f.notFound,`There is no file ${e} to list in ${K}.`)}),await D(t.root,{kind:o,file:e,...i===void 0?{}:{title:i}},t.kinds),{}},"components/list":async({item:o})=>{const e=await t.prepared(),i=e.items.find(s=>s.id===o||s.entry===o)?.dir??o;return{components:e.components.map(s=>{const r=E.relative(i,s.file);return{of:Z({path:r.startsWith(".")?r:`./${r}`,name:s.export}),name:s.name,...s.label===void 0?{}:{label:s.label}}})}},"components/stage":async({item:o,version:e})=>{const{prepared:i,host:s,combo:r}=await t.componentHost(o,e);if(!("components"in s)&&T(s,i.kinds))throw new c(f.notFound,`${o} has no components to draw alone: a deck's or a doc's are.`);const{code:l}=await G(i,s),a=new URLSearchParams({piece:H(s),combo:Y(r),mode:"component",code:l.slice(0,16)});return C(n,P.stage,a)},"components/stills":async({item:o,version:e,components:i})=>{v(n,I.stills);try{const{prepared:s,host:r,combo:l}=await t.componentHost(o,e);if(!("components"in r)&&T(r,s.kinds))throw new c(f.notFound,`${o} has no components to draw alone: a deck's or a doc's are.`);const{gpu:a}=await t.browser();return{stills:(await q(i,{prepared:s,item:r,combo:l,gpu:a,withSession:d=>t.withSession(d)})).map(({key:d})=>({key:d,url:v(n,X(d))}))}}catch(s){throw x(s)}},"check/results":()=>Promise.resolve(n.checker?.state??{status:"off",revision:t.revision,problems:[],facts:[]}),"check/run":()=>{if(!n.checker)throw new c(f.unavailable,"This server runs no check.");return n.checker.schedule(!0),Promise.resolve({})},"export/start":async({item:o,versions:e,types:i,options:s})=>{const{items:r}=await h(t.root,t.kinds);if(!r.some(l=>l.id===o))throw new c(f.notFound,`There is no item ${o}.`);return{job:n.exports.start(o,e??[],i??[],s)}},"export/cancel":({job:o})=>{if(!n.exports.cancel(o))throw new c(f.notFound,`No export ${o} is under way.`);return Promise.resolve({})},"export/list":()=>Promise.resolve({jobs:n.exports.list(),reveal:n.reveal!==void 0}),"export/reveal":async({path:o})=>{if(!n.reveal)throw new c(f.unavailable,"This server is not on the person's computer: download the file.");if(!o.startsWith(`${U}/`))throw new c(f.notFound,`${o} is no exported file.`);const e=n.exports.savedOf(o),i=e!==void 0&&await y(e).then(()=>!0,()=>!1)?e:b(t.root,o);return await y(i).catch(()=>{throw new c(f.notFound,`There is no file ${o}.`)}),await n.reveal(i),{}}}}
@@ -1,3 +1,3 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{parse as f}from"yaml";import{kindBuildOf as m,readWork as p}from"@allyhub/build";import{DATA_FILES as c,baseOf as $,listedWork as b}from"@allyhub/formats";const g=e=>new RegExp(`^${e.split("**/").map(a=>a.replace(/[.+?^${}()|[\]\\]/gu,"\\$&").replaceAll("*","[^/]*")).join("(?:.*/)?")}$`,"u"),k=Object.entries(c).flatMap(([e,a])=>a.files.map(n=>({name:e,re:g(n)})));export function dataFileOf(e){return k.find(a=>a.re.test(e))?.name}export async function writeProblems(e,a,n,u){const t=$(e),d=b((await p(u)).work).find(r=>r.file.replace(/^\.\//u,"")===e)?.kind,s=await m(n.find(r=>r.id===d))?.catch(()=>{});if(s?.unreadable)return[...s.unreadable(a)];const i=dataFileOf(e);if(i===void 0)return[];let o;try{o=/\.ya?ml$/u.test(t)?f(a):JSON.parse(a)}catch(r){return[`not ${/\.ya?ml$/u.test(t)?"YAML":"JSON"}: ${r.message.split(`
3
- `)[0]??""}`]}const l=c[i].schema.safeParse(o);return l.success?[]:l.error.issues.map(r=>`${r.path.length?`${r.path.join(".")}: `:""}${r.message}`)}
2
+ import{parse as m}from"yaml";import{kindBuildOf as p,readWork as $}from"@allyhub/build";import{DATA_FILES as f,baseOf as b,listedWork as g}from"@allyhub/formats";const k=r=>new RegExp(`^${r.split("**/").map(a=>a.replace(/[.+?^${}()|[\]\\]/gu,"\\$&").replaceAll("*","[^/]*")).join("(?:.*/)?")}$`,"u"),w=Object.entries(f).flatMap(([r,a])=>a.files.map(n=>({name:r,re:k(n)})));export function dataFileOf(r){return w.find(a=>a.re.test(r))?.name}export async function writeProblems(r,a,n,u,s){const i=b(r),t=g((await $(u)).work).find(e=>e.file.replace(/^\.\//u,"")===r)?.kind;if(t!==void 0&&s){const e=await s(t,a);if(e)return[...e]}else{const e=await p(n.find(d=>d.id===t))?.catch(()=>{});if(e?.unreadable)return[...e.unreadable(a)]}const o=dataFileOf(r);if(o===void 0)return[];let l;try{l=/\.ya?ml$/u.test(i)?m(a):JSON.parse(a)}catch(e){return[`not ${/\.ya?ml$/u.test(i)?"YAML":"JSON"}: ${e.message.split(`
3
+ `)[0]??""}`]}const c=f[o].schema.safeParse(l);return c.success?[]:c.error.issues.map(e=>`${e.path.length?`${e.path.join(".")}: `:""}${e.message}`)}