openplanr 2.2640.8 → 2.2641.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 (192) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/dashboard/.vite/manifest.json +1 -1
  3. package/dist/dashboard/assets/{index-COZ36pFn.js → index-D7R6tnlX.js} +2 -2
  4. package/dist/dashboard/assets/{index-COZ36pFn.js.map → index-D7R6tnlX.js.map} +1 -1
  5. package/dist/dashboard/dashboard-manifest.json +8 -8
  6. package/dist/dashboard/index.html +1 -1
  7. package/lib/host-packages/adapter-registry.json +5 -5
  8. package/lib/host-packages/capability-map.json +1 -1
  9. package/lib/host-packages/claude/.claude-plugin/marketplace.json +2 -2
  10. package/lib/host-packages/claude/openplanr/.claude-plugin/plugin.json +1 -1
  11. package/lib/host-packages/claude/openplanr/.openplanr-content.json +167 -35
  12. package/lib/host-packages/claude/openplanr/README.md +22 -1
  13. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-artifact-shell.mjs +3 -11
  14. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-chunked-workspace-client.mjs +555 -0
  15. package/lib/host-packages/claude/openplanr/runtime/design/scripts/{design-pako-esm.mjs → design-compression.mjs} +2 -1521
  16. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-document.mjs +133 -12
  17. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-encrypted-workspace-client.mjs +647 -0
  18. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-entities.mjs +17 -67
  19. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-handoff.mjs +14 -16
  20. package/lib/host-packages/claude/openplanr/runtime/design/scripts/{design-planr-home.mjs → design-loopback-server.mjs} +15 -36
  21. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-owner-custody.mjs +121 -0
  22. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-resource-pack.mjs +698 -0
  23. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-review.mjs +798 -796
  24. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-runtime-home.mjs +39 -0
  25. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-runtime-support-5cb7531bede8.mjs +24 -0
  26. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-share.mjs +138 -765
  27. package/lib/host-packages/claude/openplanr/runtime/design/scripts/{design-escape.mjs → design-shared-artifact-support-dependencies-design-support-protocol-contracts-3d9b1a86.mjs} +158 -156
  28. package/lib/host-packages/{openai/openplanr/runtime/design/scripts/design-artifact-sources.mjs → claude/openplanr/runtime/design/scripts/design-shared-artifact-support-protocol-contracts-ea2cd15e.mjs} +1 -1
  29. package/lib/host-packages/{openai/openplanr/runtime/design/scripts/design-bounded-json-data.mjs → claude/openplanr/runtime/design/scripts/design-shared-protocol-contracts-31a760fc.mjs} +241 -454
  30. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-shared-protocol-contracts-75a938cc.mjs +222 -0
  31. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-upload-spool.mjs +198 -0
  32. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design.mjs +12 -5
  33. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/lib/artifact/ui/studio-shell.css +1 -1
  34. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/01-module-runtime.js +18 -0
  35. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/02-artifact-review-ui.js +809 -0
  36. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/03-protocol-contracts.js +5193 -0
  37. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/04-compression.js +4175 -0
  38. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/05-artifact-sharing.js +65 -0
  39. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/06-artifact-review-ui.js +1755 -0
  40. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/07-artifact-sharing.js +62 -0
  41. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/08-artifact-review-ui.js +2600 -0
  42. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources.json +123 -0
  43. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/package.json +3 -3
  44. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.css +3 -3
  45. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/01-module-runtime.js +34 -0
  46. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/02-react.js +992 -0
  47. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/03-react-dom-client-fiber-foundations.js +2513 -0
  48. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/04-react-dom-client-reconciliation-hooks.js +1919 -0
  49. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/05-react-dom-client-render-phases.js +1759 -0
  50. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/06-react-dom-client-commit-effects.js +1551 -0
  51. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/07-react-dom-client-work-loop-scheduling.js +1121 -0
  52. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/08-react-dom-client-dom-events-properties-hydration.js +2183 -0
  53. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/09-react-dom-client-public-roots.js +705 -0
  54. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/10-react.js +27 -0
  55. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/11-artifact-review-ui.js +13 -0
  56. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/12-design-review-experience.js +3561 -0
  57. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/13-studio-shell.js +184 -0
  58. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/14-interface-primitives.js +5045 -0
  59. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/15-interface-primitives.js +1698 -0
  60. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/16-studio-shell.js +455 -0
  61. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/17-design-studio.js +1844 -0
  62. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources.json +257 -0
  63. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/protocol/package.json +1 -1
  64. package/lib/host-packages/claude/openplanr/runtime/plan/scripts/design-protocol-contracts.mjs +4966 -0
  65. package/lib/host-packages/claude/openplanr/runtime/plan/scripts/design.mjs +240 -5192
  66. package/lib/host-packages/claude/openplanr/runtime/plan/scripts/runtime/packages/protocol/package.json +1 -1
  67. package/lib/host-packages/claude/openplanr/skills/delegate/scripts/backend-diagnostics.mjs +6 -2
  68. package/lib/host-packages/cursor/openplanr/.openplanr-content.json +166 -34
  69. package/lib/host-packages/cursor/openplanr/manifest.json +1 -1
  70. package/lib/host-packages/cursor/openplanr/rules/planr-delegate/scripts/backend-diagnostics.mjs +6 -2
  71. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-artifact-shell.mjs +3 -11
  72. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-chunked-workspace-client.mjs +555 -0
  73. package/lib/host-packages/{openai/openplanr/runtime/design/scripts/design-pako-esm.mjs → cursor/openplanr/runtime/design/scripts/design-compression.mjs} +2 -1521
  74. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-document.mjs +133 -12
  75. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-encrypted-workspace-client.mjs +647 -0
  76. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-entities.mjs +17 -67
  77. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-handoff.mjs +14 -16
  78. package/lib/host-packages/{openai/openplanr/runtime/design/scripts/design-planr-home.mjs → cursor/openplanr/runtime/design/scripts/design-loopback-server.mjs} +15 -36
  79. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-owner-custody.mjs +121 -0
  80. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-resource-pack.mjs +698 -0
  81. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-review.mjs +798 -796
  82. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-runtime-home.mjs +39 -0
  83. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-runtime-support-5cb7531bede8.mjs +24 -0
  84. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-share.mjs +138 -765
  85. package/lib/host-packages/{openai/openplanr/runtime/design/scripts/design-escape.mjs → cursor/openplanr/runtime/design/scripts/design-shared-artifact-support-dependencies-design-support-protocol-contracts-3d9b1a86.mjs} +158 -156
  86. package/lib/host-packages/{claude/openplanr/runtime/design/scripts/design-artifact-sources.mjs → cursor/openplanr/runtime/design/scripts/design-shared-artifact-support-protocol-contracts-ea2cd15e.mjs} +1 -1
  87. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/{design-bounded-json-data.mjs → design-shared-protocol-contracts-31a760fc.mjs} +241 -454
  88. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-shared-protocol-contracts-75a938cc.mjs +222 -0
  89. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-upload-spool.mjs +198 -0
  90. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design.mjs +12 -5
  91. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/lib/artifact/ui/studio-shell.css +1 -1
  92. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/01-module-runtime.js +18 -0
  93. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/02-artifact-review-ui.js +809 -0
  94. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/03-protocol-contracts.js +5193 -0
  95. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/04-compression.js +4175 -0
  96. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/05-artifact-sharing.js +65 -0
  97. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/06-artifact-review-ui.js +1755 -0
  98. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/07-artifact-sharing.js +62 -0
  99. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/08-artifact-review-ui.js +2600 -0
  100. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources.json +123 -0
  101. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/package.json +3 -3
  102. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.css +3 -3
  103. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/01-module-runtime.js +34 -0
  104. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/02-react.js +992 -0
  105. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/03-react-dom-client-fiber-foundations.js +2513 -0
  106. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/04-react-dom-client-reconciliation-hooks.js +1919 -0
  107. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/05-react-dom-client-render-phases.js +1759 -0
  108. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/06-react-dom-client-commit-effects.js +1551 -0
  109. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/07-react-dom-client-work-loop-scheduling.js +1121 -0
  110. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/08-react-dom-client-dom-events-properties-hydration.js +2183 -0
  111. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/09-react-dom-client-public-roots.js +705 -0
  112. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/10-react.js +27 -0
  113. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/11-artifact-review-ui.js +13 -0
  114. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/12-design-review-experience.js +3561 -0
  115. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/13-studio-shell.js +184 -0
  116. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/14-interface-primitives.js +5045 -0
  117. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/15-interface-primitives.js +1698 -0
  118. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/16-studio-shell.js +455 -0
  119. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/17-design-studio.js +1844 -0
  120. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources.json +257 -0
  121. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/protocol/package.json +1 -1
  122. package/lib/host-packages/cursor/openplanr/runtime/plan/scripts/design-protocol-contracts.mjs +4966 -0
  123. package/lib/host-packages/cursor/openplanr/runtime/plan/scripts/design.mjs +240 -5192
  124. package/lib/host-packages/cursor/openplanr/runtime/plan/scripts/runtime/packages/protocol/package.json +1 -1
  125. package/lib/host-packages/openai/.claude-plugin/marketplace.json +2 -2
  126. package/lib/host-packages/openai/openplanr/.codex-plugin/plugin.json +1 -1
  127. package/lib/host-packages/openai/openplanr/.openplanr-content.json +166 -34
  128. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-artifact-shell.mjs +3 -11
  129. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-chunked-workspace-client.mjs +555 -0
  130. package/lib/host-packages/{cursor/openplanr/runtime/design/scripts/design-pako-esm.mjs → openai/openplanr/runtime/design/scripts/design-compression.mjs} +2 -1521
  131. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-document.mjs +133 -12
  132. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-encrypted-workspace-client.mjs +647 -0
  133. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-entities.mjs +17 -67
  134. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-handoff.mjs +14 -16
  135. package/lib/host-packages/{cursor/openplanr/runtime/design/scripts/design-planr-home.mjs → openai/openplanr/runtime/design/scripts/design-loopback-server.mjs} +15 -36
  136. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-owner-custody.mjs +121 -0
  137. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-resource-pack.mjs +698 -0
  138. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-review.mjs +798 -796
  139. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-runtime-home.mjs +39 -0
  140. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-runtime-support-5cb7531bede8.mjs +24 -0
  141. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-share.mjs +138 -765
  142. package/lib/host-packages/{cursor/openplanr/runtime/design/scripts/design-escape.mjs → openai/openplanr/runtime/design/scripts/design-shared-artifact-support-dependencies-design-support-protocol-contracts-3d9b1a86.mjs} +158 -156
  143. package/lib/host-packages/{cursor/openplanr/runtime/design/scripts/design-artifact-sources.mjs → openai/openplanr/runtime/design/scripts/design-shared-artifact-support-protocol-contracts-ea2cd15e.mjs} +1 -1
  144. package/lib/host-packages/{claude/openplanr/runtime/design/scripts/design-bounded-json-data.mjs → openai/openplanr/runtime/design/scripts/design-shared-protocol-contracts-31a760fc.mjs} +241 -454
  145. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-shared-protocol-contracts-75a938cc.mjs +222 -0
  146. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-upload-spool.mjs +198 -0
  147. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design.mjs +12 -5
  148. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/lib/artifact/ui/studio-shell.css +1 -1
  149. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/01-module-runtime.js +18 -0
  150. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/02-artifact-review-ui.js +809 -0
  151. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/03-protocol-contracts.js +5193 -0
  152. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/04-compression.js +4175 -0
  153. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/05-artifact-sharing.js +65 -0
  154. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/06-artifact-review-ui.js +1755 -0
  155. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/07-artifact-sharing.js +62 -0
  156. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources/08-artifact-review-ui.js +2600 -0
  157. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js.sources.json +123 -0
  158. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/package.json +3 -3
  159. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.css +3 -3
  160. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/01-module-runtime.js +34 -0
  161. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/02-react.js +992 -0
  162. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/03-react-dom-client-fiber-foundations.js +2513 -0
  163. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/04-react-dom-client-reconciliation-hooks.js +1919 -0
  164. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/05-react-dom-client-render-phases.js +1759 -0
  165. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/06-react-dom-client-commit-effects.js +1551 -0
  166. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/07-react-dom-client-work-loop-scheduling.js +1121 -0
  167. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/08-react-dom-client-dom-events-properties-hydration.js +2183 -0
  168. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/09-react-dom-client-public-roots.js +705 -0
  169. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/10-react.js +27 -0
  170. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/11-artifact-review-ui.js +13 -0
  171. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/12-design-review-experience.js +3561 -0
  172. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/13-studio-shell.js +184 -0
  173. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/14-interface-primitives.js +5045 -0
  174. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/15-interface-primitives.js +1698 -0
  175. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/16-studio-shell.js +455 -0
  176. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources/17-design-studio.js +1844 -0
  177. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js.sources.json +257 -0
  178. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/protocol/package.json +1 -1
  179. package/lib/host-packages/openai/openplanr/runtime/plan/scripts/design-protocol-contracts.mjs +4966 -0
  180. package/lib/host-packages/openai/openplanr/runtime/plan/scripts/design.mjs +240 -5192
  181. package/lib/host-packages/openai/openplanr/runtime/plan/scripts/runtime/packages/protocol/package.json +1 -1
  182. package/lib/host-packages/openai/openplanr/skills/delegate/scripts/backend-diagnostics.mjs +6 -2
  183. package/package.json +2 -2
  184. package/lib/host-packages/claude/openplanr/runtime/design/scripts/design-generated-b0798298053515fd.mjs +0 -18
  185. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js +0 -5
  186. package/lib/host-packages/claude/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js +0 -25597
  187. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/design-generated-b0798298053515fd.mjs +0 -18
  188. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js +0 -5
  189. package/lib/host-packages/cursor/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js +0 -25597
  190. package/lib/host-packages/openai/openplanr/runtime/design/scripts/design-generated-b0798298053515fd.mjs +0 -18
  191. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/artifact/templates/artifact-review-stage.js +0 -5
  192. package/lib/host-packages/openai/openplanr/runtime/design/scripts/runtime/packages/design/templates/studio/studio.js +0 -25597
@@ -0,0 +1,698 @@
1
+ import {
2
+ Inflate_1,
3
+ deflateRaw_1
4
+ } from "./design-compression.mjs";
5
+ import {
6
+ LARGE_OBJECT_CHUNK_CONTEXT,
7
+ LARGE_OBJECT_LIMITS,
8
+ RESOURCE_HTML_SEGMENT_ENCODING,
9
+ assertLargeObjectContract
10
+ } from "./design-shared-protocol-contracts-31a760fc.mjs";
11
+ import {
12
+ canonicalizeJson
13
+ } from "./design-shared-protocol-contracts-75a938cc.mjs";
14
+
15
+ // packages/artifact/lib/artifact/resource-pack.mjs
16
+ var encoder = new TextEncoder();
17
+ var decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
18
+ var htmlSegmentMagic = encoder.encode(`\0${RESOURCE_HTML_SEGMENT_ENCODING}\0`);
19
+ var blockPattern = /(<(script|style)\b[^>]*>)([\s\S]*?)<\/\2\s*>/gi;
20
+ function encodeResourceBytes(bytes) {
21
+ let binary = "";
22
+ for (let offset = 0; offset < bytes.length; offset += 8192)
23
+ binary += String.fromCharCode(...bytes.subarray(offset, offset + 8192));
24
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
25
+ }
26
+ function decodeResourceBytes(value, maxBytes = 65536) {
27
+ if (typeof value !== "string" || !/^[A-Za-z0-9_-]+$/u.test(value) || value.length > Math.ceil(maxBytes * 4 / 3))
28
+ throw new TypeError("Invalid encoded resource value.");
29
+ const bytes = Uint8Array.from(
30
+ atob(value.replaceAll("-", "+").replaceAll("_", "/")),
31
+ (char) => char.charCodeAt(0)
32
+ );
33
+ if (bytes.byteLength > maxBytes || encodeResourceBytes(bytes) !== value)
34
+ throw new TypeError("Noncanonical resource encoding.");
35
+ return bytes;
36
+ }
37
+ async function resourceSha256(bytes) {
38
+ return [...new Uint8Array(await crypto.subtle.digest("SHA-256", bytes))].map((part) => part.toString(16).padStart(2, "0")).join("");
39
+ }
40
+ function encodeResource(bytes) {
41
+ const compressed = deflateRaw_1(bytes);
42
+ return compressed.byteLength < bytes.byteLength ? { bytes: compressed, codec: "deflate-raw" } : { bytes, codec: "identity" };
43
+ }
44
+ function decodeResource(bytes, descriptor, maxBytes = LARGE_OBJECT_LIMITS.decodedBytes) {
45
+ if (descriptor.encodedBytes !== bytes.byteLength || descriptor.decodedBytes > maxBytes || descriptor.decodedBytes < 1)
46
+ throw new RangeError("Resource size is invalid.");
47
+ if (descriptor.codec === "identity") {
48
+ if (bytes.byteLength !== descriptor.decodedBytes)
49
+ throw new TypeError("Identity resource length differs.");
50
+ return bytes;
51
+ }
52
+ if (descriptor.codec !== "deflate-raw") throw new TypeError("Unsupported resource codec.");
53
+ const inflater = new Inflate_1({ raw: true, chunkSize: 65536 });
54
+ const chunks = [];
55
+ let size = 0;
56
+ inflater.onData = (part) => {
57
+ size += part.byteLength;
58
+ if (size > descriptor.decodedBytes || size > maxBytes)
59
+ throw new RangeError("Resource expands beyond its declared limit.");
60
+ chunks.push(part);
61
+ };
62
+ inflater.push(bytes, true);
63
+ if (!inflater.ended && !inflater.err && inflater.strm?.avail_in === 0)
64
+ inflater.push(new Uint8Array(0), true);
65
+ if (!inflater.ended || inflater.err || size !== descriptor.decodedBytes || inflater.strm?.avail_in)
66
+ throw new TypeError("Compressed resource is corrupt or has trailing data.");
67
+ const output = new Uint8Array(size);
68
+ let offset = 0;
69
+ for (const part of chunks) {
70
+ output.set(part, offset);
71
+ offset += part.byteLength;
72
+ }
73
+ return output;
74
+ }
75
+ function jsonStringByteLength(value, maxBytes) {
76
+ let bytes = 2;
77
+ for (let index = 0; index < value.length; index++) {
78
+ const code = value.charCodeAt(index);
79
+ if (code === 34 || code === 92) bytes += 2;
80
+ else if (code < 32) bytes += [8, 9, 10, 12, 13].includes(code) ? 2 : 6;
81
+ else if (code < 128) bytes++;
82
+ else if (code < 2048) bytes += 2;
83
+ else if (code >= 55296 && code <= 56319) {
84
+ const next = value.charCodeAt(index + 1);
85
+ if (next >= 56320 && next <= 57343) {
86
+ bytes += 4;
87
+ index++;
88
+ } else bytes += 6;
89
+ } else bytes += code >= 56320 && code <= 57343 ? 6 : 3;
90
+ if (bytes > maxBytes) throw new RangeError("Resource pack exceeds its decoded byte limit.");
91
+ }
92
+ return bytes;
93
+ }
94
+ function utf8SegmentInfo(text, maximum) {
95
+ let bytes = 0, wellFormed = true;
96
+ for (let index = 0; index < text.length; index++) {
97
+ const code = text.charCodeAt(index);
98
+ if (code < 128) bytes++;
99
+ else if (code < 2048) bytes += 2;
100
+ else if (code >= 55296 && code <= 56319) {
101
+ const next = text.charCodeAt(index + 1);
102
+ if (next >= 56320 && next <= 57343) {
103
+ bytes += 4;
104
+ index++;
105
+ } else {
106
+ bytes += 3;
107
+ wellFormed = false;
108
+ }
109
+ } else {
110
+ bytes += 3;
111
+ if (code >= 56320 && code <= 57343) wellFormed = false;
112
+ }
113
+ if (bytes > maximum) throw new RangeError("Resource pack exceeds its decoded byte limit.");
114
+ }
115
+ return { bytes, wellFormed };
116
+ }
117
+ function segmentText(segment) {
118
+ if (typeof segment === "string") return { type: 0, text: segment };
119
+ if (!segment || typeof segment !== "object" || Array.isArray(segment))
120
+ throw new TypeError("Source segment is invalid.");
121
+ const descriptors = Object.getOwnPropertyDescriptors(segment);
122
+ if (Reflect.ownKeys(descriptors).length !== 1 || !Object.hasOwn(descriptors, "resourceId") || !Object.hasOwn(descriptors.resourceId, "value") || typeof descriptors.resourceId.value !== "string" || !/^r[0-9]{1,4}$/u.test(descriptors.resourceId.value))
123
+ throw new TypeError("Source segment is invalid.");
124
+ return { type: 1, text: descriptors.resourceId.value };
125
+ }
126
+ function encodeHtmlSegments(segments, maxBytes = LARGE_OBJECT_LIMITS.decodedBytes) {
127
+ if (!Array.isArray(segments) || !segments.length || segments.length > LARGE_OBJECT_LIMITS.resources * 2 + 1 || !Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > LARGE_OBJECT_LIMITS.decodedBytes)
128
+ throw new RangeError("Source segment count or byte limit is invalid.");
129
+ let byteLength = htmlSegmentMagic.byteLength + 4, wellFormed = true;
130
+ const parts = [];
131
+ for (const segment of segments) {
132
+ const part = segmentText(segment);
133
+ byteLength += 5;
134
+ if (byteLength > maxBytes)
135
+ throw new RangeError("Resource pack exceeds its decoded byte limit.");
136
+ const info = utf8SegmentInfo(part.text, maxBytes - byteLength);
137
+ byteLength += info.bytes;
138
+ wellFormed &&= info.wellFormed;
139
+ parts.push({ ...part, byteLength: info.bytes });
140
+ }
141
+ if (!wellFormed) throw new TypeError("Source segment text is not valid Unicode.");
142
+ const bytes = new Uint8Array(byteLength), view = new DataView(bytes.buffer);
143
+ bytes.set(htmlSegmentMagic);
144
+ view.setUint32(htmlSegmentMagic.byteLength, parts.length);
145
+ let cursor = htmlSegmentMagic.byteLength + 4;
146
+ for (const part of parts) {
147
+ bytes[cursor++] = part.type;
148
+ view.setUint32(cursor, part.byteLength);
149
+ cursor += 4;
150
+ const encoded = encoder.encodeInto(part.text, bytes.subarray(cursor, cursor + part.byteLength));
151
+ if (encoded.read !== part.text.length || encoded.written !== part.byteLength)
152
+ throw new TypeError("Source segment byte accounting differs.");
153
+ cursor += part.byteLength;
154
+ }
155
+ return bytes;
156
+ }
157
+ function decodeHtmlSegments(bytes, maxBytes = LARGE_OBJECT_LIMITS.decodedBytes) {
158
+ if (!(bytes instanceof Uint8Array) || !bytes.byteLength || bytes.byteLength > maxBytes || !Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > LARGE_OBJECT_LIMITS.decodedBytes)
159
+ throw new RangeError("Source segment bytes exceed their limit.");
160
+ if (bytes[0] !== 0) {
161
+ const segments2 = JSON.parse(decoder.decode(bytes));
162
+ if (!Array.isArray(segments2) || !segments2.length || segments2.length > LARGE_OBJECT_LIMITS.resources * 2 + 1)
163
+ throw new TypeError("Source segment count is invalid.");
164
+ for (const segment of segments2) segmentText(segment);
165
+ return segments2;
166
+ }
167
+ if (bytes.byteLength < htmlSegmentMagic.byteLength + 4 || htmlSegmentMagic.some((byte, index) => byte !== bytes[index]))
168
+ throw new TypeError("Source segment encoding is unsupported or corrupt.");
169
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
170
+ const count = view.getUint32(htmlSegmentMagic.byteLength);
171
+ if (!count || count > LARGE_OBJECT_LIMITS.resources * 2 + 1)
172
+ throw new TypeError("Source segment count is invalid.");
173
+ const segments = [];
174
+ let cursor = htmlSegmentMagic.byteLength + 4;
175
+ for (let index = 0; index < count; index++) {
176
+ if (bytes.byteLength - cursor < 5) throw new TypeError("Source segment span is truncated.");
177
+ const type = bytes[cursor++], length = view.getUint32(cursor);
178
+ cursor += 4;
179
+ if (![0, 1].includes(type) || length > bytes.byteLength - cursor || type === 1 && length > 128)
180
+ throw new TypeError("Source segment span is invalid.");
181
+ const text = decoder.decode(bytes.subarray(cursor, cursor + length));
182
+ cursor += length;
183
+ const segment = type === 0 ? text : { resourceId: text };
184
+ segmentText(segment);
185
+ segments.push(segment);
186
+ }
187
+ if (cursor !== bytes.byteLength) throw new TypeError("Source segment bytes have trailing data.");
188
+ return segments;
189
+ }
190
+ async function packResourceBundle(bundle, { reviewOf } = {}) {
191
+ if (reviewOf !== void 0 && !/^[a-f0-9]{64}$/u.test(reviewOf))
192
+ throw new TypeError("Invalid full review identity.");
193
+ const diagram = bundle?.kind === "openplanr-diagram-review-bundle";
194
+ const envelope = diagram ? { schemaVersion: "1.0.0", artifacts: [{ id: "diagram", html: bundle.scene?.svg }] } : bundle?.envelope;
195
+ const views = envelope?.artifacts;
196
+ if (!Array.isArray(views) || !views.length || views.length > LARGE_OBJECT_LIMITS.views || new Set(views.map((view) => view.id)).size !== views.length)
197
+ throw new RangeError("Resource pack view count or identity is invalid.");
198
+ const pooled = envelope.schemaVersion === "1.1.0";
199
+ let sources;
200
+ const viewSources = /* @__PURE__ */ Object.create(null);
201
+ if (pooled) {
202
+ sources = envelope.sources;
203
+ if (!Array.isArray(sources) || !sources.length || sources.length > LARGE_OBJECT_LIMITS.sources || new Set(sources.map((source) => source.id)).size !== sources.length)
204
+ throw new RangeError("Resource pack source count or identity is invalid.");
205
+ const sourceIds = new Set(sources.map((source) => source.id));
206
+ for (const view of views) {
207
+ if (!sourceIds.has(view.sourceId)) throw new TypeError("View references an unknown source.");
208
+ viewSources[view.id] = view.sourceId;
209
+ }
210
+ } else {
211
+ sources = [];
212
+ const pages = /* @__PURE__ */ new Map();
213
+ for (const view of views) {
214
+ if (typeof view.html !== "string") throw new TypeError("View has no HTML source.");
215
+ if (!pages.has(view.html)) {
216
+ const id = `source-${sources.length}`;
217
+ pages.set(view.html, id);
218
+ sources.push({ id, html: view.html });
219
+ }
220
+ viewSources[view.id] = pages.get(view.html);
221
+ }
222
+ }
223
+ if (sources.length > LARGE_OBJECT_LIMITS.sources)
224
+ throw new RangeError("Resource pack exceeds its source limit.");
225
+ const blocks = /* @__PURE__ */ new Map();
226
+ const resources = [];
227
+ const encodedResources = [];
228
+ let encodedBytes = 0, decodedBytes = 0, uniqueHtmlBytes = 0;
229
+ async function addResource(type, bytes) {
230
+ if (!bytes.byteLength || resources.length >= LARGE_OBJECT_LIMITS.resources)
231
+ throw new RangeError("Resource count exceeds its limit.");
232
+ if (bytes.byteLength > LARGE_OBJECT_LIMITS.decodedBytes - decodedBytes)
233
+ throw new RangeError("Resource pack exceeds its decoded byte limit.");
234
+ const encoded = encodeResource(bytes);
235
+ const descriptor = {
236
+ id: `r${resources.length}`,
237
+ type,
238
+ offset: encodedBytes,
239
+ encodedBytes: encoded.bytes.byteLength,
240
+ decodedBytes: bytes.byteLength,
241
+ codec: encoded.codec,
242
+ sha256: await resourceSha256(bytes)
243
+ };
244
+ encodedBytes += descriptor.encodedBytes;
245
+ decodedBytes += descriptor.decodedBytes;
246
+ if (decodedBytes > LARGE_OBJECT_LIMITS.decodedBytes || encodedBytes > LARGE_OBJECT_LIMITS.decodedBytes)
247
+ throw new RangeError("Resource pack exceeds its decoded byte limit.");
248
+ resources.push(descriptor);
249
+ encodedResources.push(encoded.bytes);
250
+ return descriptor.id;
251
+ }
252
+ const sourceRecords = [];
253
+ for (const source of sources) {
254
+ if (typeof source.html !== "string" || !source.html.length)
255
+ throw new TypeError("Source HTML is invalid.");
256
+ let info;
257
+ try {
258
+ info = utf8SegmentInfo(source.html, LARGE_OBJECT_LIMITS.uniqueHtmlBytes - uniqueHtmlBytes);
259
+ } catch {
260
+ throw new RangeError("Resource pack exceeds its unique HTML limit.");
261
+ }
262
+ if (!info.wellFormed) throw new TypeError("Source HTML is not valid Unicode.");
263
+ uniqueHtmlBytes += info.bytes;
264
+ const htmlBytes = encoder.encode(source.html);
265
+ const sha256 = await resourceSha256(htmlBytes);
266
+ if (source.sha256 && source.sha256 !== sha256)
267
+ throw new TypeError("Source digest does not match its HTML.");
268
+ const segments = [];
269
+ let offset = 0;
270
+ for (const match of source.html.matchAll(blockPattern)) {
271
+ const body = match[3];
272
+ if (segments.length >= LARGE_OBJECT_LIMITS.resources * 2 || body.length < 2048 || !blocks.has(body) && blocks.size >= 512)
273
+ continue;
274
+ const start = match.index + match[1].length;
275
+ segments.push(source.html.slice(offset, start));
276
+ if (!blocks.has(body))
277
+ blocks.set(body, await addResource("shared-block", encoder.encode(body)));
278
+ segments.push({ resourceId: blocks.get(body) });
279
+ offset = start + body.length;
280
+ }
281
+ segments.push(source.html.slice(offset));
282
+ const resourceId = await addResource(
283
+ "html-segments",
284
+ encodeHtmlSegments(segments, LARGE_OBJECT_LIMITS.decodedBytes - decodedBytes)
285
+ );
286
+ sourceRecords.push({ id: source.id, resourceId, htmlBytes: htmlBytes.byteLength, sha256 });
287
+ }
288
+ const withoutHtml = ({ html: _html, ...value }) => value;
289
+ const metadata = diagram ? { ...bundle, scene: { ...bundle.scene, svg: "" } } : {
290
+ ...bundle,
291
+ envelope: {
292
+ ...envelope,
293
+ artifacts: views.map(withoutHtml),
294
+ ...pooled ? { sources: sources.map(withoutHtml) } : {}
295
+ }
296
+ };
297
+ const catalog = {
298
+ schemaVersion: "1.0.0",
299
+ kind: "openplanr-resource-catalog",
300
+ ...reviewOf === void 0 ? {} : { reviewOf },
301
+ bundle: metadata,
302
+ uniqueHtmlBytes,
303
+ totalDecodedBytes: decodedBytes,
304
+ resources,
305
+ sources: sourceRecords,
306
+ viewSources
307
+ };
308
+ let catalogBytes;
309
+ for (let attempt = 0; attempt < 4; attempt++) {
310
+ catalogBytes = encoder.encode(canonicalizeJson(catalog));
311
+ const total = decodedBytes + catalogBytes.byteLength;
312
+ if (catalog.totalDecodedBytes === total) break;
313
+ catalog.totalDecodedBytes = total;
314
+ }
315
+ catalogBytes = encoder.encode(canonicalizeJson(catalog));
316
+ if (decodedBytes + catalogBytes.byteLength !== catalog.totalDecodedBytes || catalog.totalDecodedBytes > LARGE_OBJECT_LIMITS.decodedBytes)
317
+ throw new RangeError("Resource pack total exceeds its decoded limit.");
318
+ assertLargeObjectContract(catalog, "resource-catalog");
319
+ const encodedCatalog = encodeResource(catalogBytes);
320
+ const catalogSpan = {
321
+ offset: encodedBytes,
322
+ encodedBytes: encodedCatalog.bytes.byteLength,
323
+ decodedBytes: catalogBytes.byteLength,
324
+ codec: encodedCatalog.codec
325
+ };
326
+ return {
327
+ catalog,
328
+ catalogSpan,
329
+ encodedResources: [...encodedResources, encodedCatalog.bytes],
330
+ plaintextBytes: encodedBytes + encodedCatalog.bytes.byteLength
331
+ };
332
+ }
333
+ function resourceChunkAAD(manifest, index) {
334
+ return encoder.encode(
335
+ canonicalizeJson({
336
+ context: LARGE_OBJECT_CHUNK_CONTEXT,
337
+ workspaceId: manifest.workspaceId,
338
+ revisionId: manifest.revisionId,
339
+ epoch: manifest.epoch,
340
+ index
341
+ })
342
+ );
343
+ }
344
+ async function encryptResourcePack(pack, { workspaceId, revisionId, epoch, rawKey, sign, createdAt = (/* @__PURE__ */ new Date()).toISOString() }) {
345
+ const header = {
346
+ schemaVersion: "2.0.0",
347
+ kind: "openplanr-encrypted-resource-manifest",
348
+ workspaceId,
349
+ revisionId,
350
+ epoch,
351
+ createdAt,
352
+ plaintextBytes: pack.plaintextBytes,
353
+ catalog: pack.catalogSpan
354
+ };
355
+ const key = await crypto.subtle.importKey("raw", rawKey, "AES-GCM", false, ["encrypt"]);
356
+ const chunks = [];
357
+ const descriptors = [];
358
+ const ivs = /* @__PURE__ */ new Set();
359
+ let part = new Uint8Array(LARGE_OBJECT_LIMITS.chunkPlaintextBytes), filled = 0;
360
+ async function flush() {
361
+ if (!filled) return;
362
+ let iv, encodedIv;
363
+ do {
364
+ iv = crypto.getRandomValues(new Uint8Array(12));
365
+ encodedIv = encodeResourceBytes(iv);
366
+ } while (ivs.has(encodedIv));
367
+ ivs.add(encodedIv);
368
+ const index = chunks.length;
369
+ const cipher = new Uint8Array(
370
+ await crypto.subtle.encrypt(
371
+ { name: "AES-GCM", iv, additionalData: resourceChunkAAD(header, index), tagLength: 128 },
372
+ key,
373
+ part.subarray(0, filled)
374
+ )
375
+ );
376
+ if (chunks.length >= LARGE_OBJECT_LIMITS.chunks)
377
+ throw new RangeError("Encrypted pack exceeds its chunk limit.");
378
+ chunks.push(cipher);
379
+ descriptors.push({
380
+ index,
381
+ iv: encodedIv,
382
+ byteLength: cipher.byteLength,
383
+ sha256: await resourceSha256(cipher)
384
+ });
385
+ filled = 0;
386
+ }
387
+ for (const bytes of pack.encodedResources) {
388
+ for (let offset = 0; offset < bytes.byteLength; ) {
389
+ const take = Math.min(part.byteLength - filled, bytes.byteLength - offset);
390
+ part.set(bytes.subarray(offset, offset + take), filled);
391
+ filled += take;
392
+ offset += take;
393
+ if (filled === part.byteLength) await flush();
394
+ }
395
+ }
396
+ await flush();
397
+ part.fill(0);
398
+ const manifest = await sign({
399
+ ...header,
400
+ ciphertextBytes: chunks.reduce((sum, value) => sum + value.byteLength, 0),
401
+ chunks: descriptors
402
+ });
403
+ assertLargeObjectContract(manifest, "encrypted-resource-manifest");
404
+ return { manifest, chunks };
405
+ }
406
+ async function openResourcePack(manifest, { rawKey, verify, fetchChunk, maxCachedBytes = 8 * 1024 * 1024 }) {
407
+ assertLargeObjectContract(manifest, "encrypted-resource-manifest");
408
+ if (!await verify(manifest)) throw new TypeError("Resource manifest signature is invalid.");
409
+ const key = await crypto.subtle.importKey("raw", rawKey, "AES-GCM", false, ["decrypt"]);
410
+ const cache = /* @__PURE__ */ new Map();
411
+ let cacheBytes = 0, disposed = false;
412
+ if (!Number.isSafeInteger(maxCachedBytes) || maxCachedBytes < LARGE_OBJECT_LIMITS.chunkBytes || maxCachedBytes > LARGE_OBJECT_LIMITS.decodedBytes)
413
+ throw new RangeError("Resource cache bound is invalid.");
414
+ async function chunkAt(index) {
415
+ if (disposed) throw new Error("Resource pack has been disposed.");
416
+ if (cache.has(index)) {
417
+ const bytes2 = cache.get(index);
418
+ cache.delete(index);
419
+ cache.set(index, bytes2);
420
+ return bytes2;
421
+ }
422
+ const descriptor = manifest.chunks[index];
423
+ const bytes = await fetchChunk(index, descriptor);
424
+ if (!(bytes instanceof Uint8Array) || bytes.byteLength !== descriptor.byteLength || await resourceSha256(bytes) !== descriptor.sha256)
425
+ throw new TypeError("Ciphertext chunk integrity check failed.");
426
+ const plaintext = new Uint8Array(
427
+ await crypto.subtle.decrypt(
428
+ {
429
+ name: "AES-GCM",
430
+ iv: decodeResourceBytes(descriptor.iv, 12),
431
+ additionalData: resourceChunkAAD(manifest, index),
432
+ tagLength: 128
433
+ },
434
+ key,
435
+ bytes
436
+ )
437
+ );
438
+ if (disposed) {
439
+ plaintext.fill(0);
440
+ throw new Error("Resource pack has been disposed.");
441
+ }
442
+ cache.set(index, plaintext);
443
+ cacheBytes += plaintext.byteLength;
444
+ while (cacheBytes > maxCachedBytes && cache.size > 1) {
445
+ const first = cache.keys().next().value;
446
+ cacheBytes -= cache.get(first).byteLength;
447
+ cache.delete(first);
448
+ }
449
+ return plaintext;
450
+ }
451
+ return openPackedResources({
452
+ catalogSpan: manifest.catalog,
453
+ plaintextBytes: manifest.plaintextBytes,
454
+ chunkPlaintextBytes: LARGE_OBJECT_LIMITS.chunkPlaintextBytes,
455
+ chunkAt,
456
+ dispose() {
457
+ disposed = true;
458
+ for (const bytes of cache.values()) bytes.fill(0);
459
+ cache.clear();
460
+ cacheBytes = 0;
461
+ }
462
+ });
463
+ }
464
+ async function openPackedResources({
465
+ catalogSpan,
466
+ plaintextBytes,
467
+ chunkPlaintextBytes,
468
+ chunkAt,
469
+ dispose = () => {
470
+ }
471
+ }) {
472
+ async function spanBytes(span) {
473
+ if (!Number.isSafeInteger(span.offset) || !Number.isSafeInteger(span.encodedBytes) || span.offset < 0 || span.encodedBytes < 1 || span.offset + span.encodedBytes > plaintextBytes)
474
+ throw new TypeError("Resource span is invalid.");
475
+ const bytes = new Uint8Array(span.encodedBytes);
476
+ for (let copied = 0; copied < bytes.byteLength; ) {
477
+ const absolute = span.offset + copied, index = Math.floor(absolute / chunkPlaintextBytes), within = absolute % chunkPlaintextBytes;
478
+ const chunk = await chunkAt(index);
479
+ const take = Math.min(chunk.byteLength - within, bytes.byteLength - copied);
480
+ if (take < 1) throw new TypeError("Resource span exceeds its chunks.");
481
+ bytes.set(chunk.subarray(within, within + take), copied);
482
+ copied += take;
483
+ }
484
+ return bytes;
485
+ }
486
+ const catalogBytes = decodeResource(
487
+ await spanBytes(catalogSpan),
488
+ catalogSpan,
489
+ LARGE_OBJECT_LIMITS.catalogBytes
490
+ );
491
+ const catalog = assertLargeObjectContract(
492
+ JSON.parse(decoder.decode(catalogBytes)),
493
+ "resource-catalog"
494
+ );
495
+ const resourceBytes = catalog.resources.reduce((sum, part) => sum + part.decodedBytes, 0);
496
+ const encodedBytes = catalog.resources.reduce((sum, part) => sum + part.encodedBytes, 0);
497
+ if (resourceBytes + catalogBytes.byteLength !== catalog.totalDecodedBytes || encodedBytes !== catalogSpan.offset)
498
+ throw new TypeError("Catalog and manifest byte accounting differ.");
499
+ const resources = new Map(catalog.resources.map((resource) => [resource.id, resource]));
500
+ const sourceRecords = new Map(catalog.sources.map((source) => [source.id, source]));
501
+ async function resourceAt(id, expectedType, maxBytes = LARGE_OBJECT_LIMITS.decodedBytes) {
502
+ const descriptor = resources.get(id);
503
+ if (!descriptor || descriptor.type !== expectedType || descriptor.offset + descriptor.encodedBytes > catalogSpan.offset)
504
+ throw new TypeError("Resource reference is invalid.");
505
+ if (descriptor.decodedBytes > maxBytes || descriptor.encodedBytes > maxBytes)
506
+ throw new RangeError("Selected source resource exceeds its read limit.");
507
+ const decoded = decodeResource(await spanBytes(descriptor), descriptor, maxBytes);
508
+ if (await resourceSha256(decoded) !== descriptor.sha256)
509
+ throw new TypeError("Decoded resource integrity check failed.");
510
+ return decoded;
511
+ }
512
+ async function loadSource(id, { maxSourceBytes } = {}) {
513
+ const source = sourceRecords.get(id);
514
+ if (!source) throw new TypeError("Unknown source.");
515
+ if (maxSourceBytes !== void 0 && (!Number.isSafeInteger(maxSourceBytes) || maxSourceBytes < 1 || maxSourceBytes > LARGE_OBJECT_LIMITS.uniqueHtmlBytes))
516
+ throw new RangeError("Selected source read limit is invalid.");
517
+ if (maxSourceBytes !== void 0 && source.htmlBytes > maxSourceBytes)
518
+ throw new RangeError("Selected source exceeds its read limit.");
519
+ const segmentLimit = maxSourceBytes === void 0 ? LARGE_OBJECT_LIMITS.decodedBytes : Math.min(
520
+ LARGE_OBJECT_LIMITS.decodedBytes,
521
+ maxSourceBytes * 6 + (LARGE_OBJECT_LIMITS.resources * 2 + 1) * 160 + htmlSegmentMagic.byteLength + 4
522
+ );
523
+ const segments = decodeHtmlSegments(
524
+ await resourceAt(source.resourceId, "html-segments", segmentLimit),
525
+ segmentLimit
526
+ );
527
+ if (!Array.isArray(segments) || segments.length > LARGE_OBJECT_LIMITS.resources * 2 + 1)
528
+ throw new TypeError("Source segment count is invalid.");
529
+ const parts = [];
530
+ let htmlBytes = 0;
531
+ for (const segment of segments) {
532
+ let text;
533
+ if (typeof segment === "string") text = segment;
534
+ else if (segment && Object.keys(segment).length === 1 && typeof segment.resourceId === "string")
535
+ text = decoder.decode(
536
+ await resourceAt(
537
+ segment.resourceId,
538
+ "shared-block",
539
+ maxSourceBytes ?? LARGE_OBJECT_LIMITS.decodedBytes
540
+ )
541
+ );
542
+ else throw new TypeError("Source segment is invalid.");
543
+ htmlBytes += encoder.encode(text).byteLength;
544
+ if (htmlBytes > source.htmlBytes)
545
+ throw new RangeError("Source expands beyond its declared limit.");
546
+ parts.push(text);
547
+ }
548
+ const html = parts.join("");
549
+ if (htmlBytes !== source.htmlBytes || await resourceSha256(encoder.encode(html)) !== source.sha256)
550
+ throw new TypeError("Reconstructed HTML integrity check failed.");
551
+ return html;
552
+ }
553
+ async function loadView(viewId, options) {
554
+ if (catalog.bundle.kind === "openplanr-diagram-review-bundle") {
555
+ if (viewId !== "diagram") throw new TypeError("Unknown diagram view.");
556
+ return { id: "diagram", html: await loadSource(catalog.viewSources.diagram, options) };
557
+ }
558
+ const view = catalog.bundle.envelope.artifacts.find((item) => item.id === viewId);
559
+ if (!view || !Object.hasOwn(catalog.viewSources, viewId)) throw new TypeError("Unknown view.");
560
+ return { ...view, html: await loadSource(catalog.viewSources[viewId], options) };
561
+ }
562
+ async function loadBundle({ sourcePool = false } = {}) {
563
+ const metadataBytes = encoder.encode(canonicalizeJson(catalog.bundle)).byteLength;
564
+ const poolInline = sourcePool && catalog.bundle.kind === "openplanr-design-review-bundle" && catalog.bundle.envelope.schemaVersion !== "1.1.0";
565
+ const references = catalog.bundle.kind === "openplanr-diagram-review-bundle" ? [{ id: catalog.viewSources.diagram, field: null }] : catalog.bundle.envelope.schemaVersion === "1.1.0" ? catalog.bundle.envelope.sources.map((source) => ({ id: source.id, field: "html" })) : poolInline ? catalog.sources.map((source) => ({ id: source.id, field: "html" })) : catalog.bundle.envelope.artifacts.map((view) => ({
566
+ id: catalog.viewSources[view.id],
567
+ field: "html"
568
+ }));
569
+ const counts = /* @__PURE__ */ new Map();
570
+ let serializedBytes = metadataBytes;
571
+ for (const { id, field } of references) {
572
+ const source = sourceRecords.get(id);
573
+ if (!source) throw new TypeError("Unknown source.");
574
+ serializedBytes += source.htmlBytes + (field === null ? 0 : field.length + 6);
575
+ if (serializedBytes > LARGE_OBJECT_LIMITS.decodedBytes)
576
+ throw new RangeError(
577
+ "Complete bundle reconstruction exceeds its serialized byte limit. Use lazy views."
578
+ );
579
+ counts.set(id, (counts.get(id) ?? 0) + 1);
580
+ }
581
+ const uniqueRepresentation = [...counts.values()].every((count) => count === 1);
582
+ const htmlBySource = /* @__PURE__ */ new Map();
583
+ for (const [id, count] of counts) {
584
+ const html = await loadSource(id);
585
+ const source = sourceRecords.get(id);
586
+ if (!uniqueRepresentation) {
587
+ const escapedBytes = jsonStringByteLength(html, LARGE_OBJECT_LIMITS.decodedBytes);
588
+ serializedBytes += count * (escapedBytes - source.htmlBytes - 2);
589
+ }
590
+ if (serializedBytes > LARGE_OBJECT_LIMITS.decodedBytes)
591
+ throw new RangeError(
592
+ "Complete bundle reconstruction exceeds its serialized byte limit. Use lazy views."
593
+ );
594
+ htmlBySource.set(id, html);
595
+ }
596
+ const bundle = structuredClone(catalog.bundle);
597
+ if (poolInline) {
598
+ if (bundle.schemaVersion === "1.1.0") bundle.schemaVersion = "1.2.0";
599
+ bundle.envelope.schemaVersion = "1.1.0";
600
+ bundle.envelope.sources = catalog.sources.map((source) => ({
601
+ id: source.id,
602
+ kind: "html",
603
+ sha256: source.sha256,
604
+ html: htmlBySource.get(source.id)
605
+ }));
606
+ bundle.envelope.artifacts = bundle.envelope.artifacts.map((view) => ({
607
+ ...view,
608
+ sourceId: catalog.viewSources[view.id]
609
+ }));
610
+ const actualMetadata = {
611
+ ...bundle,
612
+ envelope: {
613
+ ...bundle.envelope,
614
+ sources: bundle.envelope.sources.map(({ html: _html, ...source }) => source)
615
+ }
616
+ };
617
+ const extraMetadata = encoder.encode(canonicalizeJson(actualMetadata)).byteLength - metadataBytes;
618
+ if (serializedBytes + extraMetadata > LARGE_OBJECT_LIMITS.decodedBytes)
619
+ throw new RangeError("Complete pooled reconstruction exceeds its serialized byte limit.");
620
+ return bundle;
621
+ }
622
+ if (bundle.kind === "openplanr-diagram-review-bundle")
623
+ bundle.scene.svg = htmlBySource.get(catalog.viewSources.diagram);
624
+ else if (bundle.envelope.schemaVersion === "1.1.0") {
625
+ for (const source of bundle.envelope.sources) source.html = htmlBySource.get(source.id);
626
+ } else
627
+ for (const view of bundle.envelope.artifacts)
628
+ view.html = htmlBySource.get(catalog.viewSources[view.id]);
629
+ return bundle;
630
+ }
631
+ return {
632
+ catalog: structuredClone(catalog),
633
+ bundle: structuredClone(catalog.bundle),
634
+ reviewOf: catalog.reviewOf,
635
+ loadSource,
636
+ loadView,
637
+ loadBundle,
638
+ assertMatchesBundle: (value) => assertResourceBundleMatchesCatalog(value, catalog),
639
+ dispose
640
+ };
641
+ }
642
+ async function assertResourceBundleMatchesCatalog(bundle, catalog) {
643
+ assertLargeObjectContract(catalog, "resource-catalog");
644
+ const diagram = bundle?.kind === "openplanr-diagram-review-bundle";
645
+ const envelope = diagram ? { schemaVersion: "1.0.0", artifacts: [{ id: "diagram", html: bundle.scene?.svg }] } : bundle?.envelope;
646
+ if (!Array.isArray(envelope?.artifacts))
647
+ throw new TypeError("Saved content differs from resource catalog.");
648
+ const sources = [], viewSources = /* @__PURE__ */ Object.create(null), pages = /* @__PURE__ */ new Map();
649
+ if (envelope.schemaVersion === "1.1.0") {
650
+ if (!Array.isArray(envelope.sources))
651
+ throw new TypeError("Saved content differs from resource catalog.");
652
+ sources.push(...envelope.sources);
653
+ for (const view of envelope.artifacts) viewSources[view.id] = view.sourceId;
654
+ } else
655
+ for (const view of envelope.artifacts) {
656
+ if (typeof view.html !== "string")
657
+ throw new TypeError("Saved content differs from resource catalog.");
658
+ if (!pages.has(view.html)) {
659
+ const id = `source-${sources.length}`;
660
+ pages.set(view.html, id);
661
+ sources.push({ id, html: view.html });
662
+ }
663
+ viewSources[view.id] = pages.get(view.html);
664
+ }
665
+ const withoutHtml = ({ html: _html, ...value }) => value;
666
+ const metadata = diagram ? { ...bundle, scene: { ...bundle.scene, svg: "" } } : {
667
+ ...bundle,
668
+ envelope: {
669
+ ...envelope,
670
+ artifacts: envelope.artifacts.map(withoutHtml),
671
+ ...envelope.schemaVersion === "1.1.0" ? { sources: sources.map(withoutHtml) } : {}
672
+ }
673
+ };
674
+ if (canonicalizeJson(metadata) !== canonicalizeJson(catalog.bundle) || canonicalizeJson(viewSources) !== canonicalizeJson(catalog.viewSources) || sources.length !== catalog.sources.length)
675
+ throw new TypeError("Saved content differs from resource catalog.");
676
+ const saved = new Map(catalog.sources.map((source) => [source.id, source]));
677
+ for (const source of sources) {
678
+ const record = saved.get(source.id);
679
+ if (!record || typeof source.html !== "string")
680
+ throw new TypeError("Saved source differs from resource catalog.");
681
+ const info = utf8SegmentInfo(source.html, record.htmlBytes);
682
+ if (!info.wellFormed || info.bytes !== record.htmlBytes)
683
+ throw new TypeError("Saved source differs from resource catalog.");
684
+ const bytes = encoder.encode(source.html);
685
+ if (await resourceSha256(bytes) !== record.sha256)
686
+ throw new TypeError("Saved source differs from resource catalog.");
687
+ }
688
+ return bundle;
689
+ }
690
+
691
+ export {
692
+ encodeResourceBytes,
693
+ decodeResourceBytes,
694
+ resourceSha256,
695
+ packResourceBundle,
696
+ encryptResourcePack,
697
+ openResourcePack
698
+ };