@fps-games/editor 0.2.1-beta.3 → 0.2.1-beta.4

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 (514) hide show
  1. package/dist/build-info.json +44 -44
  2. package/dist/editor-commands/capabilities/assets.d.ts +8 -0
  3. package/dist/editor-commands/capabilities/assets.d.ts.map +1 -0
  4. package/dist/{agent-bridge → editor-commands}/capabilities/assets.js +41 -41
  5. package/dist/editor-commands/capabilities/assets.js.map +1 -0
  6. package/dist/editor-commands/capabilities/editor-state.d.ts +5 -0
  7. package/dist/editor-commands/capabilities/editor-state.d.ts.map +1 -0
  8. package/dist/{agent-bridge → editor-commands}/capabilities/editor-state.js +22 -22
  9. package/dist/editor-commands/capabilities/editor-state.js.map +1 -0
  10. package/dist/editor-commands/capabilities/hierarchy.d.ts +4 -0
  11. package/dist/editor-commands/capabilities/hierarchy.d.ts.map +1 -0
  12. package/dist/{agent-bridge → editor-commands}/capabilities/hierarchy.js +5 -5
  13. package/dist/editor-commands/capabilities/hierarchy.js.map +1 -0
  14. package/dist/editor-commands/capabilities/host-lifecycle.d.ts +11 -0
  15. package/dist/editor-commands/capabilities/host-lifecycle.d.ts.map +1 -0
  16. package/dist/editor-commands/capabilities/host-lifecycle.js +149 -0
  17. package/dist/editor-commands/capabilities/host-lifecycle.js.map +1 -0
  18. package/dist/editor-commands/capabilities/prefabs.d.ts +5 -0
  19. package/dist/editor-commands/capabilities/prefabs.d.ts.map +1 -0
  20. package/dist/{agent-bridge → editor-commands}/capabilities/prefabs.js +93 -93
  21. package/dist/editor-commands/capabilities/prefabs.js.map +1 -0
  22. package/dist/editor-commands/capabilities/scene-objects.d.ts +8 -0
  23. package/dist/editor-commands/capabilities/scene-objects.d.ts.map +1 -0
  24. package/dist/editor-commands/capabilities/scene-objects.js +480 -0
  25. package/dist/editor-commands/capabilities/scene-objects.js.map +1 -0
  26. package/dist/editor-commands/capabilities/selection.d.ts +5 -0
  27. package/dist/editor-commands/capabilities/selection.d.ts.map +1 -0
  28. package/dist/editor-commands/capabilities/selection.js +60 -0
  29. package/dist/editor-commands/capabilities/selection.js.map +1 -0
  30. package/dist/editor-commands/capabilities/shadows.d.ts +5 -0
  31. package/dist/editor-commands/capabilities/shadows.d.ts.map +1 -0
  32. package/dist/{agent-bridge → editor-commands}/capabilities/shadows.js +74 -74
  33. package/dist/editor-commands/capabilities/shadows.js.map +1 -0
  34. package/dist/editor-commands/capabilities/transform.d.ts +5 -0
  35. package/dist/editor-commands/capabilities/transform.d.ts.map +1 -0
  36. package/dist/editor-commands/capabilities/transform.js +164 -0
  37. package/dist/editor-commands/capabilities/transform.js.map +1 -0
  38. package/dist/editor-commands/capabilities/ui-regions.d.ts +4 -0
  39. package/dist/editor-commands/capabilities/ui-regions.d.ts.map +1 -0
  40. package/dist/{agent-bridge → editor-commands}/capabilities/ui-regions.js +55 -57
  41. package/dist/editor-commands/capabilities/ui-regions.js.map +1 -0
  42. package/dist/editor-commands/capabilities/viewport.d.ts +5 -0
  43. package/dist/editor-commands/capabilities/viewport.d.ts.map +1 -0
  44. package/dist/{agent-bridge → editor-commands}/capabilities/viewport.js +100 -100
  45. package/dist/editor-commands/capabilities/viewport.js.map +1 -0
  46. package/dist/editor-commands/command-sources.d.ts +7 -0
  47. package/dist/editor-commands/command-sources.d.ts.map +1 -0
  48. package/dist/editor-commands/command-sources.js +34 -0
  49. package/dist/editor-commands/command-sources.js.map +1 -0
  50. package/dist/editor-commands/diagnostics.d.ts +12 -0
  51. package/dist/editor-commands/diagnostics.d.ts.map +1 -0
  52. package/dist/{agent-bridge → editor-commands}/diagnostics.js +4 -4
  53. package/dist/editor-commands/diagnostics.js.map +1 -0
  54. package/dist/{agent-bridge → editor-commands}/index.d.ts +1 -1
  55. package/dist/editor-commands/index.d.ts.map +1 -0
  56. package/dist/{agent-bridge → editor-commands}/index.js +1 -1
  57. package/dist/editor-commands/index.js.map +1 -0
  58. package/dist/editor-commands/register.d.ts +4 -0
  59. package/dist/editor-commands/register.d.ts.map +1 -0
  60. package/dist/{agent-bridge → editor-commands}/register.js +323 -286
  61. package/dist/editor-commands/register.js.map +1 -0
  62. package/dist/{agent-bridge → editor-commands}/shared.d.ts +80 -80
  63. package/dist/editor-commands/shared.d.ts.map +1 -0
  64. package/dist/{agent-bridge → editor-commands}/shared.js +29 -29
  65. package/dist/editor-commands/shared.js.map +1 -0
  66. package/dist/editor-commands/source-types.d.ts +110 -0
  67. package/dist/editor-commands/source-types.d.ts.map +1 -0
  68. package/dist/editor-commands/source-types.js.map +1 -0
  69. package/dist/editor-plugin-commands.d.ts +4 -0
  70. package/dist/editor-plugin-commands.d.ts.map +1 -0
  71. package/dist/editor-plugin-commands.js +18 -0
  72. package/dist/editor-plugin-commands.js.map +1 -0
  73. package/dist/index.d.ts +2 -2
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +1 -1
  76. package/dist/index.js.map +1 -1
  77. package/dist/local-editor-commands.d.ts +2 -0
  78. package/dist/local-editor-commands.d.ts.map +1 -0
  79. package/dist/local-editor-commands.js +2 -0
  80. package/dist/local-editor-commands.js.map +1 -0
  81. package/dist/local-editor-harness.d.ts +35 -21
  82. package/dist/local-editor-harness.d.ts.map +1 -1
  83. package/dist/local-editor-harness.js +1721 -367
  84. package/dist/local-editor-harness.js.map +1 -1
  85. package/dist/local-editor-prefab-stage-transaction.d.ts +2 -1
  86. package/dist/local-editor-prefab-stage-transaction.d.ts.map +1 -1
  87. package/dist/local-editor-prefab-stage-transaction.js +6 -5
  88. package/dist/local-editor-prefab-stage-transaction.js.map +1 -1
  89. package/dist/local-editor-scene-view-interaction-runtime.d.ts.map +1 -1
  90. package/dist/local-editor-scene-view-interaction-runtime.js +2 -5
  91. package/dist/local-editor-scene-view-interaction-runtime.js.map +1 -1
  92. package/dist/playable-local-editor-entry.d.ts +10 -0
  93. package/dist/playable-local-editor-entry.d.ts.map +1 -1
  94. package/dist/playable-local-editor-entry.js +10 -2
  95. package/dist/playable-local-editor-entry.js.map +1 -1
  96. package/dist/playable-local-editor-host.d.ts +3 -32
  97. package/dist/playable-local-editor-host.d.ts.map +1 -1
  98. package/dist/playable-local-editor-host.js +6 -70
  99. package/dist/playable-local-editor-host.js.map +1 -1
  100. package/dist/playable-product-local-editor.d.ts +1 -2
  101. package/dist/playable-product-local-editor.d.ts.map +1 -1
  102. package/dist/playable-product-local-editor.js +0 -1
  103. package/dist/playable-product-local-editor.js.map +1 -1
  104. package/dist/playable-product-projection-preview.d.ts.map +1 -1
  105. package/dist/playable-product-projection-preview.js +1 -1
  106. package/dist/playable-product-projection-preview.js.map +1 -1
  107. package/dist/playable-product-scene-capabilities.d.ts +0 -2
  108. package/dist/playable-product-scene-capabilities.d.ts.map +1 -1
  109. package/dist/playable-product-scene-capabilities.js +33 -6
  110. package/dist/playable-product-scene-capabilities.js.map +1 -1
  111. package/dist/playable-runtime-babylon.d.ts +4 -0
  112. package/dist/playable-runtime-babylon.d.ts.map +1 -1
  113. package/dist/playable-runtime-babylon.js +4 -0
  114. package/dist/playable-runtime-babylon.js.map +1 -1
  115. package/dist/playable-sdk.d.ts +1 -1
  116. package/dist/playable-sdk.d.ts.map +1 -1
  117. package/dist/playable-sdk.js.map +1 -1
  118. package/dist/playable-standard-project.d.ts +0 -2
  119. package/dist/playable-standard-project.d.ts.map +1 -1
  120. package/dist/playable-standard-project.js +1 -2
  121. package/dist/playable-standard-project.js.map +1 -1
  122. package/dist/project-service-projection.d.ts +16 -0
  123. package/dist/project-service-projection.d.ts.map +1 -0
  124. package/dist/project-service-projection.js +67 -0
  125. package/dist/project-service-projection.js.map +1 -0
  126. package/node_modules/@fps-games/babylon-renderer/dist/post-process/babylon-default-pipeline.d.ts +18 -0
  127. package/node_modules/@fps-games/babylon-renderer/dist/post-process/babylon-default-pipeline.d.ts.map +1 -1
  128. package/node_modules/@fps-games/babylon-renderer/dist/post-process/babylon-default-pipeline.js +54 -18
  129. package/node_modules/@fps-games/babylon-renderer/dist/post-process/babylon-default-pipeline.js.map +1 -1
  130. package/node_modules/@fps-games/babylon-renderer/package.json +9 -9
  131. package/node_modules/@fps-games/editor-babylon/dist/projection.d.ts +1 -0
  132. package/node_modules/@fps-games/editor-babylon/dist/projection.d.ts.map +1 -1
  133. package/node_modules/@fps-games/editor-babylon/dist/projection.js +1 -1
  134. package/node_modules/@fps-games/editor-babylon/dist/projection.js.map +1 -1
  135. package/node_modules/@fps-games/editor-babylon/dist/selection-presentation-controller.d.ts.map +1 -1
  136. package/node_modules/@fps-games/editor-babylon/dist/selection-presentation-controller.js +127 -13
  137. package/node_modules/@fps-games/editor-babylon/dist/selection-presentation-controller.js.map +1 -1
  138. package/node_modules/@fps-games/editor-babylon/dist/transform-gizmo-controller.d.ts.map +1 -1
  139. package/node_modules/@fps-games/editor-babylon/dist/transform-gizmo-controller.js +66 -1
  140. package/node_modules/@fps-games/editor-babylon/dist/transform-gizmo-controller.js.map +1 -1
  141. package/node_modules/@fps-games/editor-babylon/package.json +6 -6
  142. package/node_modules/@fps-games/editor-browser/dist/editor-command-service-client.d.ts +32 -0
  143. package/node_modules/@fps-games/editor-browser/dist/editor-command-service-client.d.ts.map +1 -0
  144. package/node_modules/@fps-games/editor-browser/dist/editor-command-service-client.js +254 -0
  145. package/node_modules/@fps-games/editor-browser/dist/editor-command-service-client.js.map +1 -0
  146. package/node_modules/@fps-games/editor-browser/dist/index.d.ts +3 -1
  147. package/node_modules/@fps-games/editor-browser/dist/index.d.ts.map +1 -1
  148. package/node_modules/@fps-games/editor-browser/dist/index.js +2 -0
  149. package/node_modules/@fps-games/editor-browser/dist/index.js.map +1 -1
  150. package/node_modules/@fps-games/editor-browser/dist/local-editor-command-center.d.ts +68 -0
  151. package/node_modules/@fps-games/editor-browser/dist/local-editor-command-center.d.ts.map +1 -0
  152. package/node_modules/@fps-games/editor-browser/dist/local-editor-command-center.js +650 -0
  153. package/node_modules/@fps-games/editor-browser/dist/local-editor-command-center.js.map +1 -0
  154. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-formal-surface-visibility.d.ts +1 -0
  155. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-formal-surface-visibility.d.ts.map +1 -1
  156. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-formal-surface-visibility.js +22 -0
  157. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-formal-surface-visibility.js.map +1 -1
  158. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-hierarchy-controller.d.ts +8 -0
  159. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-hierarchy-controller.d.ts.map +1 -1
  160. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-hierarchy-controller.js +117 -6
  161. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-hierarchy-controller.js.map +1 -1
  162. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-hierarchy-view.d.ts +14 -1
  163. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-hierarchy-view.d.ts.map +1 -1
  164. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-hierarchy-view.js +100 -1
  165. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-hierarchy-view.js.map +1 -1
  166. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panels.d.ts +8 -1
  167. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panels.d.ts.map +1 -1
  168. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panels.js +75 -2
  169. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-panels.js.map +1 -1
  170. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-types.d.ts +37 -12
  171. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-types.d.ts.map +1 -1
  172. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui-types.js.map +1 -1
  173. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui.d.ts +25 -2
  174. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui.d.ts.map +1 -1
  175. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui.js +332 -107
  176. package/node_modules/@fps-games/editor-browser/dist/local-editor-ui.js.map +1 -1
  177. package/node_modules/@fps-games/editor-browser/package.json +7 -7
  178. package/node_modules/@fps-games/editor-core/dist/editor-authoring-host.d.ts +107 -0
  179. package/node_modules/@fps-games/editor-core/dist/editor-authoring-host.d.ts.map +1 -0
  180. package/node_modules/@fps-games/editor-core/dist/editor-authoring-host.js +1211 -0
  181. package/node_modules/@fps-games/editor-core/dist/editor-authoring-host.js.map +1 -0
  182. package/node_modules/@fps-games/editor-core/dist/editor-command-capability-adapter.d.ts +34 -0
  183. package/node_modules/@fps-games/editor-core/dist/editor-command-capability-adapter.d.ts.map +1 -0
  184. package/node_modules/@fps-games/editor-core/dist/editor-command-capability-adapter.js +260 -0
  185. package/node_modules/@fps-games/editor-core/dist/editor-command-capability-adapter.js.map +1 -0
  186. package/node_modules/@fps-games/editor-core/dist/editor-command-composed-authority.d.ts +9 -0
  187. package/node_modules/@fps-games/editor-core/dist/editor-command-composed-authority.d.ts.map +1 -0
  188. package/node_modules/@fps-games/editor-core/dist/editor-command-composed-authority.js +14 -0
  189. package/node_modules/@fps-games/editor-core/dist/editor-command-composed-authority.js.map +1 -0
  190. package/node_modules/@fps-games/editor-core/dist/editor-command-observability.d.ts +18 -0
  191. package/node_modules/@fps-games/editor-core/dist/editor-command-observability.d.ts.map +1 -0
  192. package/node_modules/@fps-games/editor-core/dist/editor-command-observability.js +113 -0
  193. package/node_modules/@fps-games/editor-core/dist/editor-command-observability.js.map +1 -0
  194. package/node_modules/@fps-games/editor-core/dist/editor-command-system.d.ts +82 -0
  195. package/node_modules/@fps-games/editor-core/dist/editor-command-system.d.ts.map +1 -0
  196. package/node_modules/@fps-games/editor-core/dist/editor-command-system.js +1098 -0
  197. package/node_modules/@fps-games/editor-core/dist/editor-command-system.js.map +1 -0
  198. package/node_modules/@fps-games/editor-core/dist/editor-plugin-host.d.ts +6 -7
  199. package/node_modules/@fps-games/editor-core/dist/editor-plugin-host.d.ts.map +1 -1
  200. package/node_modules/@fps-games/editor-core/dist/editor-plugin-host.js +62 -103
  201. package/node_modules/@fps-games/editor-core/dist/editor-plugin-host.js.map +1 -1
  202. package/node_modules/@fps-games/editor-core/dist/editor-service-gateway.d.ts +30 -0
  203. package/node_modules/@fps-games/editor-core/dist/editor-service-gateway.d.ts.map +1 -0
  204. package/node_modules/@fps-games/editor-core/dist/editor-service-gateway.js +540 -0
  205. package/node_modules/@fps-games/editor-core/dist/editor-service-gateway.js.map +1 -0
  206. package/node_modules/@fps-games/editor-core/dist/editor-session-authority.d.ts +9 -0
  207. package/node_modules/@fps-games/editor-core/dist/editor-session-authority.d.ts.map +1 -0
  208. package/node_modules/@fps-games/editor-core/dist/editor-session-authority.js +61 -0
  209. package/node_modules/@fps-games/editor-core/dist/editor-session-authority.js.map +1 -0
  210. package/node_modules/@fps-games/editor-core/dist/editor-session.d.ts +55 -0
  211. package/node_modules/@fps-games/editor-core/dist/editor-session.d.ts.map +1 -1
  212. package/node_modules/@fps-games/editor-core/dist/editor-session.js +247 -6
  213. package/node_modules/@fps-games/editor-core/dist/editor-session.js.map +1 -1
  214. package/node_modules/@fps-games/editor-core/dist/index.d.ts +6 -2
  215. package/node_modules/@fps-games/editor-core/dist/index.d.ts.map +1 -1
  216. package/node_modules/@fps-games/editor-core/dist/index.js +6 -2
  217. package/node_modules/@fps-games/editor-core/dist/index.js.map +1 -1
  218. package/node_modules/@fps-games/editor-core/package.json +6 -6
  219. package/node_modules/@fps-games/editor-forge-play/dist/index.d.ts +0 -1
  220. package/node_modules/@fps-games/editor-forge-play/dist/index.d.ts.map +1 -1
  221. package/node_modules/@fps-games/editor-forge-play/dist/index.js +0 -1
  222. package/node_modules/@fps-games/editor-forge-play/dist/index.js.map +1 -1
  223. package/node_modules/@fps-games/editor-forge-play/package.json +2 -2
  224. package/node_modules/@fps-games/editor-playable-sdk/dist/bridge-command/protocol.d.ts +2 -0
  225. package/node_modules/@fps-games/editor-playable-sdk/dist/bridge-command/protocol.d.ts.map +1 -1
  226. package/node_modules/@fps-games/editor-playable-sdk/dist/document/helpers.d.ts.map +1 -1
  227. package/node_modules/@fps-games/editor-playable-sdk/dist/document/helpers.js +41 -1
  228. package/node_modules/@fps-games/editor-playable-sdk/dist/document/helpers.js.map +1 -1
  229. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play-types.d.ts +27 -1
  230. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play-types.d.ts.map +1 -1
  231. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play-types.js.map +1 -1
  232. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play.d.ts +2 -0
  233. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play.d.ts.map +1 -1
  234. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play.js +214 -7
  235. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/forge-play.js.map +1 -1
  236. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/host-controller.d.ts +1 -0
  237. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/host-controller.d.ts.map +1 -1
  238. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/host-controller.js +11 -3
  239. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/host-controller.js.map +1 -1
  240. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/index.d.ts +2 -4
  241. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/index.d.ts.map +1 -1
  242. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/index.js +0 -1
  243. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/index.js.map +1 -1
  244. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/lifecycle.d.ts.map +1 -1
  245. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/lifecycle.js +77 -31
  246. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/lifecycle.js.map +1 -1
  247. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/types.d.ts +8 -1
  248. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/types.d.ts.map +1 -1
  249. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/types.js.map +1 -1
  250. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/asset-fields.d.ts +21 -1
  251. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/asset-fields.d.ts.map +1 -1
  252. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/asset-fields.js +90 -4
  253. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/asset-fields.js.map +1 -1
  254. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/binding.d.ts +27 -1
  255. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/binding.d.ts.map +1 -1
  256. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/binding.js +161 -1
  257. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/binding.js.map +1 -1
  258. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/inspector.d.ts +2 -2
  259. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/inspector.d.ts.map +1 -1
  260. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/inspector.js +5 -92
  261. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/inspector.js.map +1 -1
  262. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/scene-inspector.d.ts +7 -0
  263. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/scene-inspector.d.ts.map +1 -1
  264. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/scene-inspector.js +26 -9
  265. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/scene-inspector.js.map +1 -1
  266. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/slot-inspector.d.ts +9 -0
  267. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/slot-inspector.d.ts.map +1 -1
  268. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/slot-inspector.js +19 -8
  269. package/node_modules/@fps-games/editor-playable-sdk/dist/material-binding/slot-inspector.js.map +1 -1
  270. package/node_modules/@fps-games/editor-playable-sdk/dist/prefab-stage/material-override-inspector.d.ts +5 -0
  271. package/node_modules/@fps-games/editor-playable-sdk/dist/prefab-stage/material-override-inspector.d.ts.map +1 -1
  272. package/node_modules/@fps-games/editor-playable-sdk/dist/prefab-stage/material-override-inspector.js +16 -4
  273. package/node_modules/@fps-games/editor-playable-sdk/dist/prefab-stage/material-override-inspector.js.map +1 -1
  274. package/node_modules/@fps-games/editor-playable-sdk/dist/prefab-stage/stage-inspector.d.ts +9 -0
  275. package/node_modules/@fps-games/editor-playable-sdk/dist/prefab-stage/stage-inspector.d.ts.map +1 -1
  276. package/node_modules/@fps-games/editor-playable-sdk/dist/prefab-stage/stage-inspector.js +12 -2
  277. package/node_modules/@fps-games/editor-playable-sdk/dist/prefab-stage/stage-inspector.js.map +1 -1
  278. package/node_modules/@fps-games/editor-playable-sdk/dist/product/ground-decal.d.ts +2 -1
  279. package/node_modules/@fps-games/editor-playable-sdk/dist/product/ground-decal.d.ts.map +1 -1
  280. package/node_modules/@fps-games/editor-playable-sdk/dist/product/ground-decal.js +10 -5
  281. package/node_modules/@fps-games/editor-playable-sdk/dist/product/ground-decal.js.map +1 -1
  282. package/node_modules/@fps-games/editor-playable-sdk/dist/product/index.d.ts +1 -0
  283. package/node_modules/@fps-games/editor-playable-sdk/dist/product/index.d.ts.map +1 -1
  284. package/node_modules/@fps-games/editor-playable-sdk/dist/product/index.js +1 -0
  285. package/node_modules/@fps-games/editor-playable-sdk/dist/product/index.js.map +1 -1
  286. package/node_modules/@fps-games/editor-playable-sdk/dist/product/project-host-services.d.ts +17 -82
  287. package/node_modules/@fps-games/editor-playable-sdk/dist/product/project-host-services.d.ts.map +1 -1
  288. package/node_modules/@fps-games/editor-playable-sdk/dist/product/project-host-services.js +53 -57
  289. package/node_modules/@fps-games/editor-playable-sdk/dist/product/project-host-services.js.map +1 -1
  290. package/node_modules/@fps-games/editor-playable-sdk/dist/product/scene-session.d.ts.map +1 -1
  291. package/node_modules/@fps-games/editor-playable-sdk/dist/product/scene-session.js +3 -2
  292. package/node_modules/@fps-games/editor-playable-sdk/dist/product/scene-session.js.map +1 -1
  293. package/node_modules/@fps-games/editor-playable-sdk/dist/product/standard-authoring-commands.d.ts +10 -0
  294. package/node_modules/@fps-games/editor-playable-sdk/dist/product/standard-authoring-commands.d.ts.map +1 -0
  295. package/node_modules/@fps-games/editor-playable-sdk/dist/product/standard-authoring-commands.js +256 -0
  296. package/node_modules/@fps-games/editor-playable-sdk/dist/product/standard-authoring-commands.js.map +1 -0
  297. package/node_modules/@fps-games/editor-playable-sdk/dist/product/standard-scene-assembly.d.ts.map +1 -1
  298. package/node_modules/@fps-games/editor-playable-sdk/dist/product/standard-scene-assembly.js +7 -5
  299. package/node_modules/@fps-games/editor-playable-sdk/dist/product/standard-scene-assembly.js.map +1 -1
  300. package/node_modules/@fps-games/editor-playable-sdk/dist/scene-source/client.d.ts.map +1 -1
  301. package/node_modules/@fps-games/editor-playable-sdk/dist/scene-source/client.js +8 -0
  302. package/node_modules/@fps-games/editor-playable-sdk/dist/scene-source/client.js.map +1 -1
  303. package/node_modules/@fps-games/editor-playable-sdk/dist/scene-source/types.d.ts +1 -0
  304. package/node_modules/@fps-games/editor-playable-sdk/dist/scene-source/types.d.ts.map +1 -1
  305. package/node_modules/@fps-games/editor-playable-sdk/dist/scene-source/types.js.map +1 -1
  306. package/node_modules/@fps-games/editor-playable-sdk/dist/upgrade-doctor/inspectors.js +134 -12
  307. package/node_modules/@fps-games/editor-playable-sdk/dist/upgrade-doctor/inspectors.js.map +1 -1
  308. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/editor-scene-workflow.d.ts.map +1 -1
  309. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/editor-scene-workflow.js +47 -0
  310. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/editor-scene-workflow.js.map +1 -1
  311. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/editor-service-vite.d.ts +27 -0
  312. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/editor-service-vite.d.ts.map +1 -0
  313. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/editor-service-vite.js +592 -0
  314. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/editor-service-vite.js.map +1 -0
  315. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/index.d.ts +3 -1
  316. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/index.d.ts.map +1 -1
  317. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/index.js +2 -1
  318. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/index.js.map +1 -1
  319. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/plugin.d.ts.map +1 -1
  320. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/plugin.js +61 -6
  321. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/plugin.js.map +1 -1
  322. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/product-adapter.d.ts +0 -2
  323. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/product-adapter.d.ts.map +1 -1
  324. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/product-adapter.js +1 -10
  325. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/product-adapter.js.map +1 -1
  326. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/product-authoring-api.d.ts.map +1 -1
  327. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/product-authoring-api.js +21 -0
  328. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/product-authoring-api.js.map +1 -1
  329. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/project-authoring-backend.d.ts +13 -0
  330. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/project-authoring-backend.d.ts.map +1 -0
  331. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/project-authoring-backend.js +18 -0
  332. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/project-authoring-backend.js.map +1 -0
  333. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/project-editor-service.d.ts +28 -0
  334. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/project-editor-service.d.ts.map +1 -0
  335. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/project-editor-service.js +863 -0
  336. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/project-editor-service.js.map +1 -0
  337. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/types.d.ts +2 -0
  338. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/types.d.ts.map +1 -1
  339. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/types.js.map +1 -1
  340. package/node_modules/@fps-games/editor-playable-sdk/package.json +6 -6
  341. package/node_modules/@fps-games/editor-protocol/dist/editor-command-capabilities.d.ts +1626 -0
  342. package/node_modules/@fps-games/editor-protocol/dist/editor-command-capabilities.d.ts.map +1 -0
  343. package/node_modules/@fps-games/editor-protocol/dist/{agent-bridge.js → editor-command-capabilities.js} +766 -620
  344. package/node_modules/@fps-games/editor-protocol/dist/editor-command-capabilities.js.map +1 -0
  345. package/node_modules/@fps-games/editor-protocol/dist/editor-command-trace.d.ts +69 -0
  346. package/node_modules/@fps-games/editor-protocol/dist/editor-command-trace.d.ts.map +1 -0
  347. package/node_modules/@fps-games/editor-protocol/dist/editor-command-trace.js +22 -0
  348. package/node_modules/@fps-games/editor-protocol/dist/editor-command-trace.js.map +1 -0
  349. package/node_modules/@fps-games/editor-protocol/dist/editor-command.d.ts +136 -0
  350. package/node_modules/@fps-games/editor-protocol/dist/editor-command.d.ts.map +1 -0
  351. package/node_modules/@fps-games/editor-protocol/dist/editor-command.js +2 -0
  352. package/node_modules/@fps-games/editor-protocol/dist/editor-command.js.map +1 -0
  353. package/node_modules/@fps-games/editor-protocol/dist/editor-service.d.ts +225 -0
  354. package/node_modules/@fps-games/editor-protocol/dist/editor-service.d.ts.map +1 -0
  355. package/node_modules/@fps-games/editor-protocol/dist/editor-service.js +4 -0
  356. package/node_modules/@fps-games/editor-protocol/dist/editor-service.js.map +1 -0
  357. package/node_modules/@fps-games/editor-protocol/dist/index.d.ts +6 -3
  358. package/node_modules/@fps-games/editor-protocol/dist/index.d.ts.map +1 -1
  359. package/node_modules/@fps-games/editor-protocol/dist/index.js +6 -3
  360. package/node_modules/@fps-games/editor-protocol/dist/index.js.map +1 -1
  361. package/node_modules/@fps-games/editor-protocol/package.json +2 -2
  362. package/node_modules/@fps-games/editor-tooling/package.json +3 -3
  363. package/node_modules/@fps-games/editor-ui/package.json +1 -1
  364. package/node_modules/@fps-games/playable-assets/package.json +1 -1
  365. package/node_modules/@fps-games/playable-contracts/package.json +1 -1
  366. package/node_modules/@fps-games/playable-rendering/package.json +2 -2
  367. package/node_modules/@fps-games/playable-runtime/package.json +12 -12
  368. package/node_modules/@fps-games/playable-runtime-data/package.json +4 -4
  369. package/node_modules/@fps-games/playable-scene/package.json +2 -2
  370. package/node_modules/@fps-games/plugin-api/package.json +1 -1
  371. package/node_modules/@fps-games/plugin-assets/dist/version.d.ts +1 -1
  372. package/node_modules/@fps-games/plugin-assets/dist/version.js +1 -1
  373. package/node_modules/@fps-games/plugin-assets/dist/version.js.map +1 -1
  374. package/node_modules/@fps-games/plugin-assets/package.json +6 -6
  375. package/node_modules/@fps-games/plugin-hierarchy/dist/kernel.d.ts +1 -0
  376. package/node_modules/@fps-games/plugin-hierarchy/dist/kernel.d.ts.map +1 -1
  377. package/node_modules/@fps-games/plugin-hierarchy/dist/kernel.js +78 -4
  378. package/node_modules/@fps-games/plugin-hierarchy/dist/kernel.js.map +1 -1
  379. package/node_modules/@fps-games/plugin-hierarchy/dist/version.d.ts +1 -1
  380. package/node_modules/@fps-games/plugin-hierarchy/dist/version.js +1 -1
  381. package/node_modules/@fps-games/plugin-hierarchy/dist/version.js.map +1 -1
  382. package/node_modules/@fps-games/plugin-hierarchy/package.json +5 -5
  383. package/node_modules/@fps-games/plugin-host/package.json +2 -2
  384. package/node_modules/@fps-games/plugin-markers/dist/version.d.ts +1 -1
  385. package/node_modules/@fps-games/plugin-markers/dist/version.js +1 -1
  386. package/node_modules/@fps-games/plugin-markers/dist/version.js.map +1 -1
  387. package/node_modules/@fps-games/plugin-markers/package.json +5 -5
  388. package/node_modules/@fps-games/plugin-materials/dist/version.d.ts +1 -1
  389. package/node_modules/@fps-games/plugin-materials/dist/version.js +1 -1
  390. package/node_modules/@fps-games/plugin-materials/dist/version.js.map +1 -1
  391. package/node_modules/@fps-games/plugin-materials/package.json +5 -5
  392. package/node_modules/@fps-games/plugin-rendering/dist/version.d.ts +1 -1
  393. package/node_modules/@fps-games/plugin-rendering/dist/version.js +1 -1
  394. package/node_modules/@fps-games/plugin-rendering/dist/version.js.map +1 -1
  395. package/node_modules/@fps-games/plugin-rendering/package.json +5 -5
  396. package/node_modules/@fps-games/plugin-scene/dist/version.d.ts +1 -1
  397. package/node_modules/@fps-games/plugin-scene/dist/version.js +1 -1
  398. package/node_modules/@fps-games/plugin-scene/dist/version.js.map +1 -1
  399. package/node_modules/@fps-games/plugin-scene/package.json +5 -5
  400. package/node_modules/@fps-games/plugin-shadow-map-experiment/dist/version.d.ts +1 -1
  401. package/node_modules/@fps-games/plugin-shadow-map-experiment/dist/version.js +1 -1
  402. package/node_modules/@fps-games/plugin-shadow-map-experiment/dist/version.js.map +1 -1
  403. package/node_modules/@fps-games/plugin-shadow-map-experiment/package.json +5 -5
  404. package/node_modules/@fps-games/plugin-shadows/dist/version.d.ts +1 -1
  405. package/node_modules/@fps-games/plugin-shadows/dist/version.js +1 -1
  406. package/node_modules/@fps-games/plugin-shadows/dist/version.js.map +1 -1
  407. package/node_modules/@fps-games/plugin-shadows/package.json +7 -7
  408. package/package.json +23 -23
  409. package/dist/agent-bridge/capabilities/assets.d.ts +0 -8
  410. package/dist/agent-bridge/capabilities/assets.d.ts.map +0 -1
  411. package/dist/agent-bridge/capabilities/assets.js.map +0 -1
  412. package/dist/agent-bridge/capabilities/editor-state.d.ts +0 -5
  413. package/dist/agent-bridge/capabilities/editor-state.d.ts.map +0 -1
  414. package/dist/agent-bridge/capabilities/editor-state.js.map +0 -1
  415. package/dist/agent-bridge/capabilities/hierarchy.d.ts +0 -4
  416. package/dist/agent-bridge/capabilities/hierarchy.d.ts.map +0 -1
  417. package/dist/agent-bridge/capabilities/hierarchy.js.map +0 -1
  418. package/dist/agent-bridge/capabilities/host-lifecycle.d.ts +0 -11
  419. package/dist/agent-bridge/capabilities/host-lifecycle.d.ts.map +0 -1
  420. package/dist/agent-bridge/capabilities/host-lifecycle.js +0 -149
  421. package/dist/agent-bridge/capabilities/host-lifecycle.js.map +0 -1
  422. package/dist/agent-bridge/capabilities/prefabs.d.ts +0 -5
  423. package/dist/agent-bridge/capabilities/prefabs.d.ts.map +0 -1
  424. package/dist/agent-bridge/capabilities/prefabs.js.map +0 -1
  425. package/dist/agent-bridge/capabilities/scene-objects.d.ts +0 -8
  426. package/dist/agent-bridge/capabilities/scene-objects.d.ts.map +0 -1
  427. package/dist/agent-bridge/capabilities/scene-objects.js +0 -480
  428. package/dist/agent-bridge/capabilities/scene-objects.js.map +0 -1
  429. package/dist/agent-bridge/capabilities/selection.d.ts +0 -5
  430. package/dist/agent-bridge/capabilities/selection.d.ts.map +0 -1
  431. package/dist/agent-bridge/capabilities/selection.js +0 -60
  432. package/dist/agent-bridge/capabilities/selection.js.map +0 -1
  433. package/dist/agent-bridge/capabilities/shadows.d.ts +0 -5
  434. package/dist/agent-bridge/capabilities/shadows.d.ts.map +0 -1
  435. package/dist/agent-bridge/capabilities/shadows.js.map +0 -1
  436. package/dist/agent-bridge/capabilities/transform.d.ts +0 -5
  437. package/dist/agent-bridge/capabilities/transform.d.ts.map +0 -1
  438. package/dist/agent-bridge/capabilities/transform.js +0 -164
  439. package/dist/agent-bridge/capabilities/transform.js.map +0 -1
  440. package/dist/agent-bridge/capabilities/ui-regions.d.ts +0 -4
  441. package/dist/agent-bridge/capabilities/ui-regions.d.ts.map +0 -1
  442. package/dist/agent-bridge/capabilities/ui-regions.js.map +0 -1
  443. package/dist/agent-bridge/capabilities/viewport.d.ts +0 -5
  444. package/dist/agent-bridge/capabilities/viewport.d.ts.map +0 -1
  445. package/dist/agent-bridge/capabilities/viewport.js.map +0 -1
  446. package/dist/agent-bridge/capability-sources.d.ts +0 -7
  447. package/dist/agent-bridge/capability-sources.d.ts.map +0 -1
  448. package/dist/agent-bridge/capability-sources.js +0 -34
  449. package/dist/agent-bridge/capability-sources.js.map +0 -1
  450. package/dist/agent-bridge/diagnostics.d.ts +0 -12
  451. package/dist/agent-bridge/diagnostics.d.ts.map +0 -1
  452. package/dist/agent-bridge/diagnostics.js.map +0 -1
  453. package/dist/agent-bridge/index.d.ts.map +0 -1
  454. package/dist/agent-bridge/index.js.map +0 -1
  455. package/dist/agent-bridge/register.d.ts +0 -4
  456. package/dist/agent-bridge/register.d.ts.map +0 -1
  457. package/dist/agent-bridge/register.js.map +0 -1
  458. package/dist/agent-bridge/shared.d.ts.map +0 -1
  459. package/dist/agent-bridge/shared.js.map +0 -1
  460. package/dist/agent-bridge/source-types.d.ts +0 -110
  461. package/dist/agent-bridge/source-types.d.ts.map +0 -1
  462. package/dist/agent-bridge/source-types.js.map +0 -1
  463. package/dist/editor-plugin-agent-capabilities.d.ts +0 -4
  464. package/dist/editor-plugin-agent-capabilities.d.ts.map +0 -1
  465. package/dist/editor-plugin-agent-capabilities.js +0 -64
  466. package/dist/editor-plugin-agent-capabilities.js.map +0 -1
  467. package/dist/local-editor-agent-actions.d.ts +0 -43
  468. package/dist/local-editor-agent-actions.d.ts.map +0 -1
  469. package/dist/local-editor-agent-actions.js +0 -321
  470. package/dist/local-editor-agent-actions.js.map +0 -1
  471. package/dist/local-editor-agent-bridge-transport.d.ts +0 -129
  472. package/dist/local-editor-agent-bridge-transport.d.ts.map +0 -1
  473. package/dist/local-editor-agent-bridge-transport.js +0 -403
  474. package/dist/local-editor-agent-bridge-transport.js.map +0 -1
  475. package/dist/local-editor-agent-bridge.d.ts +0 -2
  476. package/dist/local-editor-agent-bridge.d.ts.map +0 -1
  477. package/dist/local-editor-agent-bridge.js +0 -2
  478. package/dist/local-editor-agent-bridge.js.map +0 -1
  479. package/dist/local-editor-agent-context.d.ts +0 -68
  480. package/dist/local-editor-agent-context.d.ts.map +0 -1
  481. package/dist/local-editor-agent-context.js +0 -716
  482. package/dist/local-editor-agent-context.js.map +0 -1
  483. package/node_modules/@fps-games/editor-core/dist/agent-bridge.d.ts +0 -22
  484. package/node_modules/@fps-games/editor-core/dist/agent-bridge.d.ts.map +0 -1
  485. package/node_modules/@fps-games/editor-core/dist/agent-bridge.js +0 -106
  486. package/node_modules/@fps-games/editor-core/dist/agent-bridge.js.map +0 -1
  487. package/node_modules/@fps-games/editor-core/dist/agent-interaction.d.ts +0 -17
  488. package/node_modules/@fps-games/editor-core/dist/agent-interaction.d.ts.map +0 -1
  489. package/node_modules/@fps-games/editor-core/dist/agent-interaction.js +0 -14
  490. package/node_modules/@fps-games/editor-core/dist/agent-interaction.js.map +0 -1
  491. package/node_modules/@fps-games/editor-forge-play/dist/agent-transport.d.ts +0 -23
  492. package/node_modules/@fps-games/editor-forge-play/dist/agent-transport.d.ts.map +0 -1
  493. package/node_modules/@fps-games/editor-forge-play/dist/agent-transport.js +0 -47
  494. package/node_modules/@fps-games/editor-forge-play/dist/agent-transport.js.map +0 -1
  495. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/agent-descriptions.d.ts +0 -112
  496. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/agent-descriptions.d.ts.map +0 -1
  497. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/agent-descriptions.js +0 -159
  498. package/node_modules/@fps-games/editor-playable-sdk/dist/local-harness/agent-descriptions.js.map +0 -1
  499. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/session-metadata.d.ts +0 -15
  500. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/session-metadata.d.ts.map +0 -1
  501. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/session-metadata.js +0 -76
  502. package/node_modules/@fps-games/editor-playable-sdk/dist/vite/session-metadata.js.map +0 -1
  503. package/node_modules/@fps-games/editor-protocol/dist/agent-bridge.d.ts +0 -1622
  504. package/node_modules/@fps-games/editor-protocol/dist/agent-bridge.d.ts.map +0 -1
  505. package/node_modules/@fps-games/editor-protocol/dist/agent-bridge.js.map +0 -1
  506. package/node_modules/@fps-games/editor-protocol/dist/agent-trace.d.ts +0 -68
  507. package/node_modules/@fps-games/editor-protocol/dist/agent-trace.d.ts.map +0 -1
  508. package/node_modules/@fps-games/editor-protocol/dist/agent-trace.js +0 -23
  509. package/node_modules/@fps-games/editor-protocol/dist/agent-trace.js.map +0 -1
  510. package/node_modules/@fps-games/editor-protocol/dist/agent.d.ts +0 -187
  511. package/node_modules/@fps-games/editor-protocol/dist/agent.d.ts.map +0 -1
  512. package/node_modules/@fps-games/editor-protocol/dist/agent.js +0 -5
  513. package/node_modules/@fps-games/editor-protocol/dist/agent.js.map +0 -1
  514. /package/dist/{agent-bridge → editor-commands}/source-types.js +0 -0
@@ -0,0 +1,1211 @@
1
+ import { EDITOR_COMMAND_SCHEMA_VERSION, } from '@fps-games/editor-protocol';
2
+ import { createEditorCommandSystem, } from './editor-command-system.js';
3
+ import { callWithEditorSessionWriteAuthority, claimEditorSessionWriteAuthority, releaseEditorSessionWriteAuthority, runWithEditorSessionWriteAuthority, } from './editor-session-authority.js';
4
+ import { authorizeCommandComposedRegistration } from './editor-command-composed-authority.js';
5
+ const CALL_WITH_SERIALIZED_SESSION_AUTHORITY = Symbol('fps.editor.call-with-serialized-session-authority');
6
+ /** @internal Adapter used by command handlers that already own the Host FIFO. */
7
+ export function callWithEditorAuthoringSerializedAccess(access, handler) {
8
+ if (!access || typeof access !== 'object'
9
+ || !(CALL_WITH_SERIALIZED_SESSION_AUTHORITY in access)) {
10
+ throw new Error('Editor Authoring Host serialized access is invalid or expired.');
11
+ }
12
+ return access[CALL_WITH_SERIALIZED_SESSION_AUTHORITY](handler);
13
+ }
14
+ /** @internal Operation-scoped Session façade for a handler that already owns serialized Host access. */
15
+ export function createEditorAuthoringSerializedSessionView(session, serializedAccess) {
16
+ return createOperationScopedSessionView(session, () => callWithEditorAuthoringSerializedAccess(serializedAccess, () => undefined), handler => callWithEditorAuthoringSerializedAccess(serializedAccess, handler));
17
+ }
18
+ const DEFAULT_EVENT_LIMIT = 200;
19
+ const DEFAULT_HISTORY_VIEW_LIMIT = 200;
20
+ const EXTERNAL_COMMAND_SESSION_VIEW_METHODS = new Set([
21
+ 'getState',
22
+ 'getWorkingDocument',
23
+ 'getSource',
24
+ 'getSelection',
25
+ 'isDirty',
26
+ 'canUndo',
27
+ 'canRedo',
28
+ 'dispatch',
29
+ 'undo',
30
+ 'redo',
31
+ 'rebaseExternalDocuments',
32
+ ]);
33
+ const SESSION_AUTHORITY_OWNERS = new WeakMap();
34
+ const HOST_EXTERNAL_COMMAND_REGISTRARS = new WeakMap();
35
+ /** @internal Registration path bound to the Host that owns authoring authority. */
36
+ export function registerEditorAuthoringHostExternalCommand(host, registration) {
37
+ const register = HOST_EXTERNAL_COMMAND_REGISTRARS.get(host);
38
+ if (!register)
39
+ throw new Error('Editor Authoring Host external command registration authority is unavailable.');
40
+ return register(registration);
41
+ }
42
+ export function createEditorAuthoringHost(options) {
43
+ const serviceInstanceId = normalizeRequiredId(options.serviceInstanceId, 'serviceInstanceId');
44
+ const commandSystem = options.commandSystem ?? createEditorCommandSystem(options.commandSystemOptions);
45
+ const ownsCommandSystem = options.commandSystem === undefined;
46
+ const sessionAuthorityOwner = Object.freeze({ serviceInstanceId });
47
+ const claimedSessions = new Set();
48
+ const reservedSessionCounts = new Map();
49
+ const trackedSessions = new Set();
50
+ let sessionClaimsReleased = false;
51
+ const assertSessionAuthorityAvailable = (session) => {
52
+ if (!session || typeof session !== 'object')
53
+ throw new Error('Editor Authoring Host session is required.');
54
+ const owner = SESSION_AUTHORITY_OWNERS.get(session);
55
+ if (owner && owner !== sessionAuthorityOwner) {
56
+ throw new Error('Editor Session already has a different write authority.');
57
+ }
58
+ };
59
+ const claimSessionAuthority = (session) => {
60
+ assertSessionAuthorityAvailable(session);
61
+ claimEditorSessionWriteAuthority(session, sessionAuthorityOwner);
62
+ try {
63
+ runWithEditorSessionWriteAuthority(session, sessionAuthorityOwner, () => {
64
+ session.detachDocumentReferencesForWriteAuthority();
65
+ });
66
+ }
67
+ catch (error) {
68
+ releaseEditorSessionWriteAuthority(session, sessionAuthorityOwner);
69
+ throw error;
70
+ }
71
+ SESSION_AUTHORITY_OWNERS.set(session, sessionAuthorityOwner);
72
+ claimedSessions.add(session);
73
+ trackedSessions.add(session);
74
+ };
75
+ const reserveSessionAuthority = (session) => {
76
+ assertSessionAuthorityAvailable(session);
77
+ if (claimedSessions.has(session)) {
78
+ return Object.freeze({ establish() { }, release() { } });
79
+ }
80
+ const existingOwner = SESSION_AUTHORITY_OWNERS.get(session);
81
+ claimEditorSessionWriteAuthority(session, sessionAuthorityOwner);
82
+ if (!existingOwner) {
83
+ try {
84
+ runWithEditorSessionWriteAuthority(session, sessionAuthorityOwner, () => {
85
+ session.detachDocumentReferencesForWriteAuthority();
86
+ });
87
+ }
88
+ catch (error) {
89
+ releaseEditorSessionWriteAuthority(session, sessionAuthorityOwner);
90
+ throw error;
91
+ }
92
+ }
93
+ SESSION_AUTHORITY_OWNERS.set(session, sessionAuthorityOwner);
94
+ trackedSessions.add(session);
95
+ reservedSessionCounts.set(session, (reservedSessionCounts.get(session) ?? 0) + 1);
96
+ let active = true;
97
+ const settle = (establish) => {
98
+ if (!active)
99
+ return;
100
+ active = false;
101
+ const remaining = (reservedSessionCounts.get(session) ?? 1) - 1;
102
+ if (remaining > 0)
103
+ reservedSessionCounts.set(session, remaining);
104
+ else
105
+ reservedSessionCounts.delete(session);
106
+ if (establish)
107
+ claimedSessions.add(session);
108
+ if (!claimedSessions.has(session) && !reservedSessionCounts.has(session)) {
109
+ if (SESSION_AUTHORITY_OWNERS.get(session) === sessionAuthorityOwner) {
110
+ SESSION_AUTHORITY_OWNERS.delete(session);
111
+ }
112
+ releaseEditorSessionWriteAuthority(session, sessionAuthorityOwner);
113
+ trackedSessions.delete(session);
114
+ }
115
+ };
116
+ return Object.freeze({
117
+ establish: () => settle(true),
118
+ release: () => settle(false),
119
+ });
120
+ };
121
+ const releaseSessionAuthorities = () => {
122
+ if (sessionClaimsReleased)
123
+ return;
124
+ sessionClaimsReleased = true;
125
+ for (const session of trackedSessions) {
126
+ if (SESSION_AUTHORITY_OWNERS.get(session) === sessionAuthorityOwner) {
127
+ SESSION_AUTHORITY_OWNERS.delete(session);
128
+ }
129
+ releaseEditorSessionWriteAuthority(session, sessionAuthorityOwner);
130
+ }
131
+ claimedSessions.clear();
132
+ reservedSessionCounts.clear();
133
+ trackedSessions.clear();
134
+ };
135
+ try {
136
+ claimSessionAuthority(options.session);
137
+ }
138
+ catch (error) {
139
+ if (ownsCommandSystem)
140
+ commandSystem.dispose();
141
+ throw error;
142
+ }
143
+ const eventLimit = normalizePositiveInteger(options.eventLimit, DEFAULT_EVENT_LIMIT);
144
+ const now = options.now ?? Date.now;
145
+ const events = [];
146
+ const unregisterBuiltins = [];
147
+ const ownedRegistrations = new Set();
148
+ const ownedCommandIds = new Set();
149
+ const handlerValidatedRevisionCommandIds = new Set();
150
+ let eventCursor = 0;
151
+ let disposed = false;
152
+ const authorityController = new AbortController();
153
+ let writeQueue = Promise.resolve();
154
+ let writeAdmissionCount = 0;
155
+ let externalOperationCount = 0;
156
+ const activeExternalOperationIds = new Set();
157
+ let authorityReleased = false;
158
+ let resolveDrained;
159
+ const drained = new Promise(resolve => { resolveDrained = resolve; });
160
+ const activeTransactions = new Map();
161
+ const externalCommandResults = new Map();
162
+ const activeSerializedAccess = new WeakSet();
163
+ let activeSession = options.session;
164
+ const prepareEvent = (reason, state, timestamp) => Object.freeze({
165
+ cursor: eventCursor + 1,
166
+ serviceInstanceId,
167
+ reason,
168
+ documentRevision: state.documentRevision,
169
+ dirty: state.dirty,
170
+ timestamp,
171
+ });
172
+ const commitEvent = (event) => {
173
+ eventCursor = event.cursor;
174
+ events.push(event);
175
+ while (events.length > eventLimit)
176
+ events.shift();
177
+ };
178
+ const registerCommand = (registration) => {
179
+ assertActive();
180
+ const expectedRevisionPolicy = registration.expectedRevisionPolicy ?? 'current-document';
181
+ if (expectedRevisionPolicy !== 'current-document'
182
+ && expectedRevisionPolicy !== 'handler-validated') {
183
+ throw new Error('Editor Authoring Host command expected revision policy is invalid.');
184
+ }
185
+ if (expectedRevisionPolicy === 'handler-validated'
186
+ && (registration.manifest.target !== 'authoring' || registration.manifest.access !== 'write')) {
187
+ throw new Error('Handler-validated revisions are reserved for authoring write commands.');
188
+ }
189
+ const isSerializedWrite = registration.manifest.target === 'authoring'
190
+ && registration.manifest.access === 'write';
191
+ const { expectedRevisionPolicy: _expectedRevisionPolicy, ...commandRegistration } = registration;
192
+ const unregisterCommand = commandSystem.registerCommand({
193
+ ...commandRegistration,
194
+ authorityTransaction: 'isolated',
195
+ handler: async (input, context) => {
196
+ const readTransaction = isSerializedWrite ? undefined : activeSession.beginTransaction();
197
+ const session = isSerializedWrite
198
+ ? activeTransactions.get(context.operationId)?.session
199
+ : readTransaction?.session;
200
+ if (!session) {
201
+ return {
202
+ ok: false,
203
+ diagnostics: [diagnostic('command.authorityUnavailable', `Authoring transaction is unavailable: ${context.commandId}`)],
204
+ };
205
+ }
206
+ try {
207
+ return await registration.handler(input, {
208
+ ...context,
209
+ session,
210
+ dispatch(command, dispatchOptions) {
211
+ session.dispatch(command, dispatchOptions);
212
+ return session.getState();
213
+ },
214
+ });
215
+ }
216
+ finally {
217
+ readTransaction?.discard();
218
+ }
219
+ },
220
+ });
221
+ ownedCommandIds.add(registration.manifest.id);
222
+ if (expectedRevisionPolicy === 'handler-validated') {
223
+ handlerValidatedRevisionCommandIds.add(registration.manifest.id);
224
+ }
225
+ let active = true;
226
+ const unregister = () => {
227
+ if (!active)
228
+ return;
229
+ active = false;
230
+ ownedRegistrations.delete(unregister);
231
+ ownedCommandIds.delete(registration.manifest.id);
232
+ handlerValidatedRevisionCommandIds.delete(registration.manifest.id);
233
+ unregisterCommand();
234
+ };
235
+ ownedRegistrations.add(unregister);
236
+ return unregister;
237
+ };
238
+ let releaseExecutionAuthority;
239
+ try {
240
+ releaseExecutionAuthority = commandSystem.installExecutionInterceptor(async (context, execute) => {
241
+ const isSerializedWrite = (context.authorityTransaction === 'composed'
242
+ && context.manifest.access === 'write')
243
+ || (context.manifest.target === 'authoring' && context.manifest.access === 'write');
244
+ if (!isSerializedWrite)
245
+ return execute();
246
+ const admittedSession = activeSession;
247
+ return enqueueWrite(async () => {
248
+ if (authorityController.signal.aborted)
249
+ return cancelledDiagnostic(context.commandId);
250
+ if (context.signal.aborted)
251
+ return cancelledDiagnostic(context.commandId);
252
+ if (activeSession !== admittedSession && context.authorityTransaction !== 'composed') {
253
+ return {
254
+ ok: false,
255
+ diagnostics: [diagnostic('command.documentScopeChanged', `Authoring document scope changed before execution: ${context.commandId}`)],
256
+ };
257
+ }
258
+ if (context.authorityTransaction !== 'composed' && !ownedCommandIds.has(context.commandId)) {
259
+ return {
260
+ ok: false,
261
+ diagnostics: [diagnostic('command.authorityRegistrationRequired', `Authoring write command is not registered by this Host: ${context.commandId}`)],
262
+ };
263
+ }
264
+ const gate = validateAuthoringWriteInvocation(context, activeSession, handlerValidatedRevisionCommandIds.has(context.commandId));
265
+ if (gate)
266
+ return { ok: false, diagnostics: [gate] };
267
+ const beforeRevision = activeSession.getState({ cloneDocuments: false }).documentRevision;
268
+ if (context.authorityTransaction === 'composed') {
269
+ // The timestamp source is injectable and may throw. Resolve it before
270
+ // a external command handler can mutate the authoritative Session.
271
+ const eventTimestamp = now();
272
+ externalOperationCount += 1;
273
+ activeExternalOperationIds.add(context.operationId);
274
+ const serializedAccess = Object.freeze({
275
+ serviceInstanceId,
276
+ [CALL_WITH_SERIALIZED_SESSION_AUTHORITY]: (handler) => {
277
+ if (!activeSerializedAccess.has(serializedAccess)) {
278
+ throw new Error('Editor Authoring Host serialized access is invalid or expired.');
279
+ }
280
+ return callWithEditorSessionWriteAuthority(activeSession, sessionAuthorityOwner, handler);
281
+ },
282
+ });
283
+ activeSerializedAccess.add(serializedAccess);
284
+ try {
285
+ try {
286
+ const execution = callWithEditorSessionWriteAuthority(activeSession, sessionAuthorityOwner, () => execute(serializedAccess));
287
+ return await execution;
288
+ }
289
+ catch (error) {
290
+ return {
291
+ ok: false,
292
+ diagnostics: [diagnostic('command.exception', error instanceof Error ? error.message : String(error))],
293
+ };
294
+ }
295
+ }
296
+ finally {
297
+ activeSerializedAccess.delete(serializedAccess);
298
+ const next = activeSession.getState({ cloneDocuments: false });
299
+ if (activeSession === admittedSession && next.documentRevision !== beforeRevision) {
300
+ commitEvent(prepareEvent('document', next, eventTimestamp));
301
+ }
302
+ externalOperationCount -= 1;
303
+ activeExternalOperationIds.delete(context.operationId);
304
+ finishDisposal();
305
+ }
306
+ }
307
+ const transaction = activeSession.beginTransaction();
308
+ activeTransactions.set(context.operationId, transaction);
309
+ let committed = false;
310
+ try {
311
+ const outcome = await executeWhileHostActive(execute, context.commandId);
312
+ if (!outcome.ok)
313
+ return outcome;
314
+ if (context.signal.aborted)
315
+ return cancelledDiagnostic(context.commandId);
316
+ const reason = context.commandId === 'history.undo' || context.commandId === 'history.redo'
317
+ ? 'history'
318
+ : 'document';
319
+ const draftState = transaction.session.getState({ cloneDocuments: false });
320
+ const event = draftState.documentRevision !== beforeRevision
321
+ ? prepareEvent(reason, draftState, now())
322
+ : null;
323
+ runWithEditorSessionWriteAuthority(activeSession, sessionAuthorityOwner, () => {
324
+ transaction.commit(reason);
325
+ });
326
+ committed = true;
327
+ if (event)
328
+ commitEvent(event);
329
+ return outcome;
330
+ }
331
+ finally {
332
+ activeTransactions.delete(context.operationId);
333
+ if (!committed)
334
+ transaction.discard();
335
+ }
336
+ });
337
+ }, { scopeId: serviceInstanceId });
338
+ }
339
+ catch (error) {
340
+ releaseSessionAuthorities();
341
+ if (ownsCommandSystem)
342
+ commandSystem.dispose();
343
+ throw error;
344
+ }
345
+ const host = {
346
+ serviceInstanceId,
347
+ commandSystem: createCommandClient(commandSystem),
348
+ registerCommand,
349
+ invoke(invocation) {
350
+ assertActive();
351
+ return commandSystem.invoke(invocation);
352
+ },
353
+ execute(invocation) {
354
+ assertActive();
355
+ return commandSystem.execute(invocation);
356
+ },
357
+ getSnapshot() {
358
+ assertActive();
359
+ return createSnapshot(activeSession.getState(), serviceInstanceId, eventCursor);
360
+ },
361
+ readEvents(afterCursor = eventCursor, expectedServiceInstanceId = serviceInstanceId) {
362
+ assertActive();
363
+ if (expectedServiceInstanceId !== serviceInstanceId) {
364
+ return {
365
+ kind: 'snapshot-required',
366
+ reason: 'service.restarted',
367
+ snapshot: host.getSnapshot(),
368
+ };
369
+ }
370
+ const normalizedCursor = Number.isSafeInteger(afterCursor) && afterCursor >= 0
371
+ ? afterCursor
372
+ : 0;
373
+ if (normalizedCursor > eventCursor) {
374
+ return {
375
+ kind: 'snapshot-required',
376
+ reason: 'cursor.invalid',
377
+ snapshot: host.getSnapshot(),
378
+ };
379
+ }
380
+ const oldestCursor = events[0]?.cursor ?? eventCursor + 1;
381
+ if (normalizedCursor < oldestCursor - 1) {
382
+ return {
383
+ kind: 'snapshot-required',
384
+ reason: 'cursor.expired',
385
+ snapshot: host.getSnapshot(),
386
+ };
387
+ }
388
+ return {
389
+ kind: 'events',
390
+ serviceInstanceId,
391
+ latestCursor: eventCursor,
392
+ events: events.filter(event => event.cursor > normalizedCursor).map(event => ({ ...event })),
393
+ };
394
+ },
395
+ async markSaved(document, markSavedOptions) {
396
+ assertActive();
397
+ if (!markSavedOptions || typeof markSavedOptions !== 'object'
398
+ || !Number.isSafeInteger(markSavedOptions.expectedDocumentRevision)
399
+ || markSavedOptions.expectedDocumentRevision < 0) {
400
+ throw new Error('Editor save checkpoint expectedDocumentRevision must be a non-negative safe integer.');
401
+ }
402
+ const expectedDocumentRevision = markSavedOptions.expectedDocumentRevision;
403
+ const serializedAccess = markSavedOptions.serializedAccess;
404
+ const admittedSession = activeSession;
405
+ const admission = admittedSession.beginTransaction();
406
+ let admittedDocument;
407
+ let admittedSource;
408
+ try {
409
+ admission.session.reset(document, markSavedOptions.source);
410
+ admittedDocument = admission.session.getWorkingDocument();
411
+ admittedSource = admission.session.getSource();
412
+ }
413
+ finally {
414
+ admission.discard();
415
+ }
416
+ const commitCheckpoint = async () => {
417
+ assertActive();
418
+ if (activeSession !== admittedSession) {
419
+ throw new Error('Editor save checkpoint document scope changed before commit.');
420
+ }
421
+ const actualRevision = activeSession.getState({ cloneDocuments: false }).documentRevision;
422
+ if (actualRevision !== expectedDocumentRevision) {
423
+ throw new Error(`Editor save checkpoint revision mismatch: expected ${expectedDocumentRevision}, received ${actualRevision}.`);
424
+ }
425
+ const transaction = activeSession.beginTransaction();
426
+ let committed = false;
427
+ try {
428
+ const eventTimestamp = now();
429
+ transaction.session.markSaved(admittedDocument, admittedSource);
430
+ const draftState = transaction.session.getState({ cloneDocuments: false });
431
+ const event = prepareEvent('saved', draftState, eventTimestamp);
432
+ const state = runWithEditorSessionWriteAuthority(activeSession, sessionAuthorityOwner, () => (transaction.commit('saved')));
433
+ committed = true;
434
+ commitEvent(event);
435
+ return createSnapshot(state, serviceInstanceId, eventCursor);
436
+ }
437
+ finally {
438
+ if (!committed)
439
+ transaction.discard();
440
+ }
441
+ };
442
+ if (serializedAccess) {
443
+ assertSerializedAccess(serializedAccess);
444
+ return commitCheckpoint();
445
+ }
446
+ return enqueueWrite(commitCheckpoint);
447
+ },
448
+ async markSavedWithRelatedSession(document, markSavedOptions) {
449
+ assertActive();
450
+ if (!markSavedOptions || typeof markSavedOptions !== 'object'
451
+ || !Number.isSafeInteger(markSavedOptions.expectedDocumentRevision)
452
+ || markSavedOptions.expectedDocumentRevision < 0) {
453
+ throw new Error('Editor related save checkpoint expectedDocumentRevision must be a non-negative safe integer.');
454
+ }
455
+ if (!markSavedOptions.relatedSession || typeof markSavedOptions.relatedSession !== 'object') {
456
+ throw new Error('Editor related save checkpoint Session is required.');
457
+ }
458
+ if (!Number.isSafeInteger(markSavedOptions.expectedRelatedDocumentRevision)
459
+ || markSavedOptions.expectedRelatedDocumentRevision < 0) {
460
+ throw new Error('Editor related save checkpoint expectedRelatedDocumentRevision must be a non-negative safe integer.');
461
+ }
462
+ if (typeof markSavedOptions.mutateRelatedSession !== 'function') {
463
+ throw new Error('Editor related save checkpoint mutation is required.');
464
+ }
465
+ const expectedDocumentRevision = markSavedOptions.expectedDocumentRevision;
466
+ const admittedSession = activeSession;
467
+ const relatedSession = markSavedOptions.relatedSession;
468
+ const expectedRelatedDocumentRevision = markSavedOptions.expectedRelatedDocumentRevision;
469
+ const resetHistory = markSavedOptions.resetHistory === true;
470
+ const mutateRelatedSession = markSavedOptions.mutateRelatedSession;
471
+ const serializedAccess = markSavedOptions.serializedAccess;
472
+ if (admittedSession === relatedSession) {
473
+ throw new Error('Editor related save checkpoint requires a distinct Session.');
474
+ }
475
+ const admission = admittedSession.beginTransaction();
476
+ let admittedDocument;
477
+ let admittedSource;
478
+ try {
479
+ admission.session.reset(document, markSavedOptions.source);
480
+ admittedDocument = admission.session.getWorkingDocument();
481
+ admittedSource = admission.session.getSource();
482
+ }
483
+ finally {
484
+ admission.discard();
485
+ }
486
+ const sessionReservation = reserveSessionAuthority(relatedSession);
487
+ const commitCheckpoint = async () => {
488
+ assertActive();
489
+ if (activeSession !== admittedSession) {
490
+ throw new Error('Editor related save checkpoint document scope changed before commit.');
491
+ }
492
+ const actualRevision = activeSession.getState({ cloneDocuments: false }).documentRevision;
493
+ if (actualRevision !== expectedDocumentRevision) {
494
+ throw new Error(`Editor related save checkpoint revision mismatch: expected ${expectedDocumentRevision}, received ${actualRevision}.`);
495
+ }
496
+ const actualRelatedRevision = relatedSession.getState({ cloneDocuments: false }).documentRevision;
497
+ if (actualRelatedRevision !== expectedRelatedDocumentRevision) {
498
+ throw new Error(`Editor related save checkpoint related revision mismatch: expected ${expectedRelatedDocumentRevision}, received ${actualRelatedRevision}.`);
499
+ }
500
+ const activeTransaction = activeSession.beginTransaction();
501
+ const relatedTransaction = relatedSession.beginTransaction();
502
+ let committed = false;
503
+ try {
504
+ const eventTimestamp = now();
505
+ activeTransaction.session.markSaved(admittedDocument, admittedSource, {
506
+ resetHistory,
507
+ });
508
+ const relatedMutationResult = mutateRelatedSession(relatedTransaction.session);
509
+ if (relatedMutationResult && typeof relatedMutationResult === 'object'
510
+ && 'then' in relatedMutationResult && typeof relatedMutationResult.then === 'function') {
511
+ throw new Error('Editor related save checkpoint mutation must be synchronous.');
512
+ }
513
+ const draftState = activeTransaction.session.getState({ cloneDocuments: false });
514
+ const event = prepareEvent('saved', draftState, eventTimestamp);
515
+ const preparedActive = activeTransaction.prepareCommit('saved');
516
+ const preparedRelated = relatedTransaction.prepareCommit('saved');
517
+ preparedActive.assertReady();
518
+ preparedRelated.assertReady();
519
+ const { activeCommit, relatedCommit } = runWithEditorSessionWriteAuthority(activeSession, sessionAuthorityOwner, () => runWithEditorSessionWriteAuthority(relatedSession, sessionAuthorityOwner, () => ({
520
+ activeCommit: preparedActive.commit({ deferChangeNotification: true }),
521
+ relatedCommit: preparedRelated.commit({ deferChangeNotification: true }),
522
+ })));
523
+ committed = true;
524
+ sessionReservation.establish();
525
+ activeCommit.notifyChange();
526
+ relatedCommit.notifyChange();
527
+ commitEvent(event);
528
+ return createSnapshot(activeCommit.state, serviceInstanceId, eventCursor);
529
+ }
530
+ finally {
531
+ if (!committed) {
532
+ activeTransaction.discard();
533
+ relatedTransaction.discard();
534
+ }
535
+ }
536
+ };
537
+ try {
538
+ const result = serializedAccess
539
+ ? (assertSerializedAccess(serializedAccess), await commitCheckpoint())
540
+ : await enqueueWrite(commitCheckpoint);
541
+ return result;
542
+ }
543
+ catch (error) {
544
+ sessionReservation.release();
545
+ throw error;
546
+ }
547
+ },
548
+ async reset(document, source, resetOptions) {
549
+ assertActive();
550
+ if (!resetOptions || !Number.isSafeInteger(resetOptions.expectedDocumentRevision)
551
+ || resetOptions.expectedDocumentRevision < 0) {
552
+ throw new Error('Editor reset expectedDocumentRevision must be a non-negative safe integer.');
553
+ }
554
+ const expectedDocumentRevision = resetOptions.expectedDocumentRevision;
555
+ const serializedAccess = resetOptions.serializedAccess;
556
+ const admittedSession = activeSession;
557
+ const admission = admittedSession.beginTransaction();
558
+ let admittedDocument;
559
+ let admittedSource;
560
+ try {
561
+ admission.session.reset(document, source);
562
+ admittedDocument = admission.session.getWorkingDocument();
563
+ admittedSource = admission.session.getSource();
564
+ }
565
+ finally {
566
+ admission.discard();
567
+ }
568
+ const commitReset = async () => {
569
+ assertActive();
570
+ if (activeSession !== admittedSession) {
571
+ throw new Error('Editor reset document scope changed before commit.');
572
+ }
573
+ const actualRevision = activeSession.getState({ cloneDocuments: false }).documentRevision;
574
+ if (actualRevision !== expectedDocumentRevision) {
575
+ throw new Error(`Editor reset revision mismatch: expected ${expectedDocumentRevision}, received ${actualRevision}.`);
576
+ }
577
+ const transaction = activeSession.beginTransaction();
578
+ let committed = false;
579
+ try {
580
+ const eventTimestamp = now();
581
+ transaction.session.reset(admittedDocument, admittedSource);
582
+ const draftState = transaction.session.getState({ cloneDocuments: false });
583
+ const event = prepareEvent('reset', draftState, eventTimestamp);
584
+ const state = runWithEditorSessionWriteAuthority(activeSession, sessionAuthorityOwner, () => (transaction.commit('reset')));
585
+ committed = true;
586
+ commitEvent(event);
587
+ return createSnapshot(state, serviceInstanceId, eventCursor);
588
+ }
589
+ finally {
590
+ if (!committed)
591
+ transaction.discard();
592
+ }
593
+ };
594
+ if (serializedAccess) {
595
+ assertSerializedAccess(serializedAccess);
596
+ return commitReset();
597
+ }
598
+ return enqueueWrite(commitReset);
599
+ },
600
+ async resetWithRelatedSession(document, source, resetOptions) {
601
+ assertActive();
602
+ if (!resetOptions || !Number.isSafeInteger(resetOptions.expectedDocumentRevision)
603
+ || resetOptions.expectedDocumentRevision < 0) {
604
+ throw new Error('Editor related reset expectedDocumentRevision must be a non-negative safe integer.');
605
+ }
606
+ if (!resetOptions.relatedSession || typeof resetOptions.relatedSession !== 'object') {
607
+ throw new Error('Editor related reset Session is required.');
608
+ }
609
+ if (!Number.isSafeInteger(resetOptions.expectedRelatedDocumentRevision)
610
+ || resetOptions.expectedRelatedDocumentRevision < 0) {
611
+ throw new Error('Editor related reset expectedRelatedDocumentRevision must be a non-negative safe integer.');
612
+ }
613
+ if (typeof resetOptions.mutateRelatedSession !== 'function') {
614
+ throw new Error('Editor related reset mutation is required.');
615
+ }
616
+ const admittedSession = activeSession;
617
+ const relatedSession = resetOptions.relatedSession;
618
+ const expectedDocumentRevision = resetOptions.expectedDocumentRevision;
619
+ const expectedRelatedDocumentRevision = resetOptions.expectedRelatedDocumentRevision;
620
+ const mutateRelatedSession = resetOptions.mutateRelatedSession;
621
+ const serializedAccess = resetOptions.serializedAccess;
622
+ if (admittedSession === relatedSession) {
623
+ throw new Error('Editor related reset requires a distinct Session.');
624
+ }
625
+ const admission = admittedSession.beginTransaction();
626
+ let admittedDocument;
627
+ let admittedSource;
628
+ try {
629
+ admission.session.reset(document, source);
630
+ admittedDocument = admission.session.getWorkingDocument();
631
+ admittedSource = admission.session.getSource();
632
+ }
633
+ finally {
634
+ admission.discard();
635
+ }
636
+ const sessionReservation = reserveSessionAuthority(relatedSession);
637
+ const commitReset = async () => {
638
+ assertActive();
639
+ if (activeSession !== admittedSession) {
640
+ throw new Error('Editor related reset document scope changed before commit.');
641
+ }
642
+ const actualRevision = activeSession.getState({ cloneDocuments: false }).documentRevision;
643
+ if (actualRevision !== expectedDocumentRevision) {
644
+ throw new Error(`Editor related reset revision mismatch: expected ${expectedDocumentRevision}, received ${actualRevision}.`);
645
+ }
646
+ const actualRelatedRevision = relatedSession.getState({ cloneDocuments: false }).documentRevision;
647
+ if (actualRelatedRevision !== expectedRelatedDocumentRevision) {
648
+ throw new Error(`Editor related reset related revision mismatch: expected ${expectedRelatedDocumentRevision}, received ${actualRelatedRevision}.`);
649
+ }
650
+ const activeTransaction = activeSession.beginTransaction();
651
+ const relatedTransaction = relatedSession.beginTransaction();
652
+ let committed = false;
653
+ try {
654
+ const eventTimestamp = now();
655
+ activeTransaction.session.reset(admittedDocument, admittedSource);
656
+ const relatedMutationResult = mutateRelatedSession(relatedTransaction.session);
657
+ if (relatedMutationResult && typeof relatedMutationResult === 'object'
658
+ && 'then' in relatedMutationResult && typeof relatedMutationResult.then === 'function') {
659
+ throw new Error('Editor related reset mutation must be synchronous.');
660
+ }
661
+ const draftState = activeTransaction.session.getState({ cloneDocuments: false });
662
+ const event = prepareEvent('reset', draftState, eventTimestamp);
663
+ const preparedActive = activeTransaction.prepareCommit('reset');
664
+ const preparedRelated = relatedTransaction.prepareCommit('reset');
665
+ preparedActive.assertReady();
666
+ preparedRelated.assertReady();
667
+ const { activeCommit, relatedCommit } = runWithEditorSessionWriteAuthority(activeSession, sessionAuthorityOwner, () => runWithEditorSessionWriteAuthority(relatedSession, sessionAuthorityOwner, () => ({
668
+ activeCommit: preparedActive.commit({ deferChangeNotification: true }),
669
+ relatedCommit: preparedRelated.commit({ deferChangeNotification: true }),
670
+ })));
671
+ committed = true;
672
+ sessionReservation.establish();
673
+ activeCommit.notifyChange();
674
+ relatedCommit.notifyChange();
675
+ commitEvent(event);
676
+ return createSnapshot(activeCommit.state, serviceInstanceId, eventCursor);
677
+ }
678
+ finally {
679
+ if (!committed) {
680
+ activeTransaction.discard();
681
+ relatedTransaction.discard();
682
+ }
683
+ }
684
+ };
685
+ try {
686
+ const result = serializedAccess
687
+ ? (assertSerializedAccess(serializedAccess), await commitReset())
688
+ : await enqueueWrite(commitReset);
689
+ return result;
690
+ }
691
+ catch (error) {
692
+ sessionReservation.release();
693
+ throw error;
694
+ }
695
+ },
696
+ async switchSession(session, switchOptions) {
697
+ assertActive();
698
+ if (!session || typeof session !== 'object')
699
+ throw new Error('Editor Authoring Host session is required.');
700
+ if (!switchOptions || !Number.isSafeInteger(switchOptions.expectedDocumentRevision)
701
+ || switchOptions.expectedDocumentRevision < 0) {
702
+ throw new Error('Editor scope switch expectedDocumentRevision must be a non-negative safe integer.');
703
+ }
704
+ const expectedDocumentRevision = switchOptions.expectedDocumentRevision;
705
+ const serializedAccess = switchOptions.serializedAccess;
706
+ const sessionReservation = reserveSessionAuthority(session);
707
+ const admittedSession = activeSession;
708
+ const switchActiveSession = async () => {
709
+ assertActive();
710
+ if (activeSession !== admittedSession) {
711
+ throw new Error('Editor scope changed before scope switch commit.');
712
+ }
713
+ const actualRevision = activeSession.getState({ cloneDocuments: false }).documentRevision;
714
+ if (actualRevision !== expectedDocumentRevision) {
715
+ throw new Error(`Editor scope switch revision mismatch: expected ${expectedDocumentRevision}, received ${actualRevision}.`);
716
+ }
717
+ if (activeSession === session)
718
+ return host.getSnapshot();
719
+ const sourceState = activeSession.getState({ cloneDocuments: false });
720
+ // Prepare every fallible target clone, timestamp, event and public
721
+ // snapshot before changing either the target revision or active owner.
722
+ const targetState = session.getState();
723
+ const eventTimestamp = now();
724
+ const scopeRevision = Math.max(sourceState.documentRevision, targetState.documentRevision) + 1;
725
+ const scopeStructureSequence = Math.max(sourceState.documentStructureRevision, targetState.documentStructureRevision) + 1;
726
+ const switchedState = {
727
+ ...targetState,
728
+ documentRevision: scopeRevision,
729
+ documentStructureRevision: scopeStructureSequence,
730
+ };
731
+ const event = prepareEvent('rebase', switchedState, eventTimestamp);
732
+ const snapshot = createSnapshot(switchedState, serviceInstanceId, event.cursor);
733
+ runWithEditorSessionWriteAuthority(session, sessionAuthorityOwner, () => {
734
+ session.advanceRevisionsForScopeSwitch(scopeRevision, scopeStructureSequence);
735
+ });
736
+ sessionReservation.establish();
737
+ activeSession = session;
738
+ commitEvent(event);
739
+ return snapshot;
740
+ };
741
+ try {
742
+ const result = serializedAccess
743
+ ? (assertSerializedAccess(serializedAccess), await switchActiveSession())
744
+ : await enqueueWrite(switchActiveSession);
745
+ return result;
746
+ }
747
+ catch (error) {
748
+ sessionReservation.release();
749
+ throw error;
750
+ }
751
+ },
752
+ runExternalCommandMutation(request, handler) {
753
+ assertActive();
754
+ const commandId = normalizeRequiredId(request?.commandId, 'commandId');
755
+ normalizeRequiredId(request?.requestId, 'requestId');
756
+ const idempotencyKey = normalizeRequiredId(request?.idempotencyKey, 'idempotencyKey');
757
+ const fingerprint = normalizeRequiredId(request?.fingerprint, 'fingerprint');
758
+ const idempotencyScope = JSON.stringify([commandId, idempotencyKey]);
759
+ if (!Number.isSafeInteger(request?.expectedDocumentRevision) || request.expectedDocumentRevision < 0) {
760
+ throw new Error('External command authoring mutation expectedDocumentRevision must be a non-negative safe integer.');
761
+ }
762
+ const expectedDocumentRevision = request.expectedDocumentRevision;
763
+ if (typeof handler !== 'function')
764
+ throw new Error('External command authoring mutation handler is required.');
765
+ const existing = externalCommandResults.get(idempotencyScope);
766
+ if (existing) {
767
+ if (existing.fingerprint !== fingerprint
768
+ || existing.expectedDocumentRevision !== expectedDocumentRevision) {
769
+ throw new Error(`External command authoring idempotency conflict: ${idempotencyKey}`);
770
+ }
771
+ return existing.result;
772
+ }
773
+ const admittedSession = activeSession;
774
+ externalOperationCount += 1;
775
+ const result = enqueueWrite(() => {
776
+ let beforeRevision = null;
777
+ let eventTimestamp = null;
778
+ let sessionViewActive = true;
779
+ const authorizedSession = createOperationScopedSessionView(admittedSession, () => {
780
+ if (!sessionViewActive)
781
+ throw new Error('Browser authoring Session access is expired.');
782
+ }, handler => runWithEditorSessionWriteAuthority(admittedSession, sessionAuthorityOwner, handler));
783
+ const finish = () => {
784
+ sessionViewActive = false;
785
+ if (beforeRevision !== null && eventTimestamp !== null && activeSession === admittedSession) {
786
+ const next = activeSession.getState({ cloneDocuments: false });
787
+ if (next.documentRevision !== beforeRevision) {
788
+ commitEvent(prepareEvent('document', next, eventTimestamp));
789
+ }
790
+ }
791
+ externalOperationCount -= 1;
792
+ finishDisposal();
793
+ };
794
+ try {
795
+ assertActive();
796
+ if (activeSession !== admittedSession) {
797
+ throw new Error(`Browser authoring document scope changed before execution: ${commandId}`);
798
+ }
799
+ beforeRevision = activeSession.getState({ cloneDocuments: false }).documentRevision;
800
+ if (beforeRevision !== expectedDocumentRevision) {
801
+ throw new Error(`Browser authoring revision mismatch for ${commandId}: expected ${expectedDocumentRevision}, received ${beforeRevision}.`);
802
+ }
803
+ eventTimestamp = now();
804
+ const value = callWithEditorSessionWriteAuthority(admittedSession, sessionAuthorityOwner, () => handler(authorizedSession));
805
+ if (value && typeof value === 'object' && 'then' in value
806
+ && typeof value.then === 'function') {
807
+ return Promise.resolve(value).finally(finish);
808
+ }
809
+ finish();
810
+ return value;
811
+ }
812
+ catch (error) {
813
+ finish();
814
+ throw error;
815
+ }
816
+ }, true);
817
+ externalCommandResults.set(idempotencyScope, {
818
+ fingerprint,
819
+ expectedDocumentRevision,
820
+ result,
821
+ });
822
+ return result;
823
+ },
824
+ tryRunExternalCommandMutationImmediately(request, handler) {
825
+ assertActive();
826
+ const commandId = normalizeRequiredId(request?.commandId, 'commandId');
827
+ normalizeRequiredId(request?.requestId, 'requestId');
828
+ const idempotencyKey = normalizeRequiredId(request?.idempotencyKey, 'idempotencyKey');
829
+ const fingerprint = normalizeRequiredId(request?.fingerprint, 'fingerprint');
830
+ const idempotencyScope = JSON.stringify([commandId, idempotencyKey]);
831
+ if (!Number.isSafeInteger(request?.expectedDocumentRevision) || request.expectedDocumentRevision < 0) {
832
+ throw new Error('External command authoring mutation expectedDocumentRevision must be a non-negative safe integer.');
833
+ }
834
+ const expectedDocumentRevision = request.expectedDocumentRevision;
835
+ if (typeof handler !== 'function')
836
+ throw new Error('External command authoring mutation handler is required.');
837
+ const existing = externalCommandResults.get(idempotencyScope);
838
+ if (existing) {
839
+ if (existing.fingerprint !== fingerprint
840
+ || existing.expectedDocumentRevision !== expectedDocumentRevision) {
841
+ throw new Error(`External command authoring idempotency conflict: ${idempotencyKey}`);
842
+ }
843
+ if (existing.hasImmediateValue) {
844
+ return { ok: true, value: existing.immediateValue, reused: true };
845
+ }
846
+ return { ok: false, reason: 'busy' };
847
+ }
848
+ if (writeAdmissionCount > 0)
849
+ return { ok: false, reason: 'busy' };
850
+ const beforeRevision = activeSession.getState({ cloneDocuments: false }).documentRevision;
851
+ if (beforeRevision !== expectedDocumentRevision) {
852
+ throw new Error(`Browser authoring revision mismatch for ${commandId}: expected ${expectedDocumentRevision}, received ${beforeRevision}.`);
853
+ }
854
+ const eventTimestamp = now();
855
+ externalOperationCount += 1;
856
+ const transaction = activeSession.beginTransaction();
857
+ let committed = false;
858
+ try {
859
+ const value = handler(transaction.session);
860
+ if (value && typeof value === 'object' && 'then' in value && typeof value.then === 'function') {
861
+ throw new Error('Immediate Browser authoring mutations must be synchronous.');
862
+ }
863
+ const next = transaction.session.getState({ cloneDocuments: false });
864
+ const event = next.documentRevision !== beforeRevision
865
+ ? prepareEvent('document', next, eventTimestamp)
866
+ : null;
867
+ runWithEditorSessionWriteAuthority(activeSession, sessionAuthorityOwner, () => {
868
+ transaction.commit('document');
869
+ });
870
+ committed = true;
871
+ if (event)
872
+ commitEvent(event);
873
+ externalCommandResults.set(idempotencyScope, {
874
+ fingerprint,
875
+ expectedDocumentRevision,
876
+ result: Promise.resolve(value),
877
+ immediateValue: value,
878
+ hasImmediateValue: true,
879
+ });
880
+ return { ok: true, value, reused: false };
881
+ }
882
+ finally {
883
+ if (!committed)
884
+ transaction.discard();
885
+ externalOperationCount -= 1;
886
+ finishDisposal();
887
+ }
888
+ },
889
+ runSerializedExternalMutation(serializedAccess, expectedDocumentRevision, handler) {
890
+ assertActive();
891
+ assertSerializedAccess(serializedAccess);
892
+ if (!Number.isSafeInteger(expectedDocumentRevision) || expectedDocumentRevision < 0) {
893
+ throw new Error('Serialized external command mutation expectedDocumentRevision must be a non-negative safe integer.');
894
+ }
895
+ const actualRevision = activeSession.getState({ cloneDocuments: false }).documentRevision;
896
+ if (actualRevision !== expectedDocumentRevision) {
897
+ throw new Error(`Serialized external command mutation revision mismatch: expected ${expectedDocumentRevision}, received ${actualRevision}.`);
898
+ }
899
+ const transaction = activeSession.beginTransaction();
900
+ let committed = false;
901
+ try {
902
+ const value = handler(transaction.session);
903
+ if (value && typeof value === 'object' && 'then' in value && typeof value.then === 'function') {
904
+ throw new Error('Serialized external command mutations must be synchronous.');
905
+ }
906
+ runWithEditorSessionWriteAuthority(activeSession, sessionAuthorityOwner, () => {
907
+ transaction.commit('document');
908
+ });
909
+ committed = true;
910
+ return value;
911
+ }
912
+ finally {
913
+ if (!committed)
914
+ transaction.discard();
915
+ }
916
+ },
917
+ dispose() {
918
+ if (disposed)
919
+ return;
920
+ disposed = true;
921
+ HOST_EXTERNAL_COMMAND_REGISTRARS.delete(host);
922
+ authorityController.abort();
923
+ for (const operationId of activeExternalOperationIds)
924
+ commandSystem.cancelOperation(operationId);
925
+ for (const unregister of unregisterBuiltins.splice(0).reverse())
926
+ unregister();
927
+ for (const unregister of [...ownedRegistrations].reverse())
928
+ unregister();
929
+ finishDisposal();
930
+ },
931
+ drain() {
932
+ if (!disposed)
933
+ return Promise.resolve();
934
+ return drained;
935
+ },
936
+ };
937
+ HOST_EXTERNAL_COMMAND_REGISTRARS.set(host, (registration) => {
938
+ assertActive();
939
+ const unregisterCommand = commandSystem.registerCommand(authorizeCommandComposedRegistration({
940
+ ...registration,
941
+ authorityTransaction: 'composed',
942
+ }));
943
+ let active = true;
944
+ const unregister = () => {
945
+ if (!active)
946
+ return;
947
+ active = false;
948
+ ownedRegistrations.delete(unregister);
949
+ unregisterCommand();
950
+ };
951
+ ownedRegistrations.add(unregister);
952
+ return unregister;
953
+ });
954
+ try {
955
+ unregisterBuiltins.push(registerCommand(createSnapshotCommand(host)));
956
+ unregisterBuiltins.push(registerCommand(createUndoCommand()));
957
+ unregisterBuiltins.push(registerCommand(createRedoCommand()));
958
+ }
959
+ catch (error) {
960
+ HOST_EXTERNAL_COMMAND_REGISTRARS.delete(host);
961
+ for (const unregister of unregisterBuiltins.splice(0).reverse())
962
+ unregister();
963
+ for (const unregister of [...ownedRegistrations].reverse())
964
+ unregister();
965
+ releaseExecutionAuthority();
966
+ releaseSessionAuthorities();
967
+ if (options.disposeCommandSystem !== false)
968
+ commandSystem.dispose();
969
+ throw error;
970
+ }
971
+ return host;
972
+ function assertActive() {
973
+ if (disposed)
974
+ throw new Error('Editor Authoring Host is disposed.');
975
+ }
976
+ function assertSerializedAccess(access) {
977
+ if (!access || typeof access !== 'object' || !activeSerializedAccess.has(access)) {
978
+ throw new Error('Editor Authoring Host serialized access is invalid or expired.');
979
+ }
980
+ }
981
+ function enqueueWrite(task, startIdleSynchronously = false) {
982
+ const startImmediately = startIdleSynchronously && writeAdmissionCount === 0;
983
+ writeAdmissionCount += 1;
984
+ const previous = writeQueue;
985
+ let releaseQueue;
986
+ writeQueue = new Promise(resolve => { releaseQueue = resolve; });
987
+ const release = () => {
988
+ writeAdmissionCount -= 1;
989
+ releaseQueue();
990
+ finishDisposal();
991
+ };
992
+ const execute = () => {
993
+ try {
994
+ const value = task();
995
+ if (value && typeof value === 'object' && 'then' in value
996
+ && typeof value.then === 'function') {
997
+ return Promise.resolve(value).finally(release);
998
+ }
999
+ release();
1000
+ return Promise.resolve(value);
1001
+ }
1002
+ catch (error) {
1003
+ release();
1004
+ return Promise.reject(error);
1005
+ }
1006
+ };
1007
+ // A synchronous composed UI interaction may start only when the FIFO is
1008
+ // idle; every other command retains the established queued turn.
1009
+ return startImmediately ? execute() : previous.then(execute);
1010
+ }
1011
+ async function executeWhileHostActive(execute, commandId) {
1012
+ if (authorityController.signal.aborted)
1013
+ return cancelledDiagnostic(commandId);
1014
+ return new Promise((resolve, reject) => {
1015
+ const onAbort = () => resolve(cancelledDiagnostic(commandId));
1016
+ authorityController.signal.addEventListener('abort', onAbort, { once: true });
1017
+ execute().then(outcome => {
1018
+ authorityController.signal.removeEventListener('abort', onAbort);
1019
+ resolve(outcome);
1020
+ }, error => {
1021
+ authorityController.signal.removeEventListener('abort', onAbort);
1022
+ reject(error);
1023
+ });
1024
+ });
1025
+ }
1026
+ function finishDisposal() {
1027
+ if (!disposed || authorityReleased || externalOperationCount > 0 || writeAdmissionCount > 0)
1028
+ return;
1029
+ authorityReleased = true;
1030
+ releaseExecutionAuthority();
1031
+ releaseSessionAuthorities();
1032
+ if (options.disposeCommandSystem !== false)
1033
+ commandSystem.dispose();
1034
+ resolveDrained();
1035
+ }
1036
+ }
1037
+ function createCommandClient(commandSystem) {
1038
+ return Object.freeze({
1039
+ get catalogRevision() { return commandSystem.catalogRevision; },
1040
+ get executionAuthorityInstalled() { return commandSystem.executionAuthorityInstalled; },
1041
+ listManifests: () => commandSystem.listManifests(),
1042
+ getCatalog: query => commandSystem.getCatalog(query),
1043
+ describeCommand: commandId => commandSystem.describeCommand(commandId),
1044
+ invoke: invocation => commandSystem.invoke(invocation),
1045
+ execute: invocation => commandSystem.execute(invocation),
1046
+ getOperation: operationId => commandSystem.getOperation(operationId),
1047
+ cancelOperation: operationId => commandSystem.cancelOperation(operationId),
1048
+ });
1049
+ }
1050
+ function createOperationScopedSessionView(session, assertActive, invoke) {
1051
+ return new Proxy(Object.create(null), {
1052
+ get(_target, property) {
1053
+ assertActive();
1054
+ if (!EXTERNAL_COMMAND_SESSION_VIEW_METHODS.has(property)) {
1055
+ throw new Error(`Browser authoring Session member is unavailable: ${String(property)}.`);
1056
+ }
1057
+ const value = Reflect.get(session, property, session);
1058
+ if (typeof value !== 'function') {
1059
+ throw new Error(`Browser authoring Session method is unavailable: ${String(property)}.`);
1060
+ }
1061
+ return (...args) => {
1062
+ assertActive();
1063
+ return invoke(() => Reflect.apply(value, session, args));
1064
+ };
1065
+ },
1066
+ set() {
1067
+ throw new Error('Browser authoring Session properties are immutable.');
1068
+ },
1069
+ defineProperty() {
1070
+ throw new Error('Browser authoring Session properties are immutable.');
1071
+ },
1072
+ deleteProperty() {
1073
+ throw new Error('Browser authoring Session properties are immutable.');
1074
+ },
1075
+ });
1076
+ }
1077
+ function validateAuthoringWriteInvocation(context, session, handlerValidatesExpectedRevision = false) {
1078
+ if (!context.idempotencyKey) {
1079
+ return diagnostic('command.idempotencyKeyRequired', 'Authoring write commands require an idempotency key.');
1080
+ }
1081
+ const expected = context.expectedRevision?.document;
1082
+ if (expected === undefined) {
1083
+ return diagnostic('command.expectedRevisionRequired', 'Authoring write commands require expectedRevision.document.');
1084
+ }
1085
+ if (handlerValidatesExpectedRevision)
1086
+ return null;
1087
+ const actual = session.getState({ cloneDocuments: false }).documentRevision;
1088
+ if (expected !== actual) {
1089
+ return diagnostic('command.documentRevisionMismatch', `Expected document revision ${expected}, received ${actual}.`, { expected, actual });
1090
+ }
1091
+ return null;
1092
+ }
1093
+ function createSnapshotCommand(host) {
1094
+ return {
1095
+ manifest: manifest({
1096
+ id: 'authoring.snapshot.get',
1097
+ title: 'Get Authoring Snapshot',
1098
+ target: 'authoring',
1099
+ access: 'read',
1100
+ persistence: 'none',
1101
+ idempotent: true,
1102
+ }),
1103
+ handler: () => ({ ok: true, output: host.getSnapshot() }),
1104
+ };
1105
+ }
1106
+ function createUndoCommand() {
1107
+ return {
1108
+ manifest: manifest({
1109
+ id: 'history.undo', title: 'Undo', target: 'authoring', access: 'write',
1110
+ persistence: 'authoring', idempotent: false,
1111
+ shortcut: 'Mod+Z', menu: { path: ['Edit', 'Undo'] },
1112
+ }),
1113
+ available: () => true,
1114
+ handler: (_input, context) => {
1115
+ const result = context.session.undo();
1116
+ if (!result)
1117
+ return { ok: false, diagnostics: [diagnostic('history.undoUnavailable', 'There is no command to undo.')] };
1118
+ return { ok: true, output: historyOutput(context.session) };
1119
+ },
1120
+ };
1121
+ }
1122
+ function createRedoCommand() {
1123
+ return {
1124
+ manifest: manifest({
1125
+ id: 'history.redo', title: 'Redo', target: 'authoring', access: 'write',
1126
+ persistence: 'authoring', idempotent: false,
1127
+ shortcut: 'Mod+Shift+Z / Ctrl+Y', menu: { path: ['Edit', 'Redo'] },
1128
+ }),
1129
+ handler: (_input, context) => {
1130
+ const result = context.session.redo();
1131
+ if (!result)
1132
+ return { ok: false, diagnostics: [diagnostic('history.redoUnavailable', 'There is no command to redo.')] };
1133
+ return { ok: true, output: historyOutput(context.session) };
1134
+ },
1135
+ };
1136
+ }
1137
+ function manifest(input) {
1138
+ return {
1139
+ schemaVersion: EDITOR_COMMAND_SCHEMA_VERSION,
1140
+ id: input.id,
1141
+ version: 1,
1142
+ title: input.title,
1143
+ target: input.target,
1144
+ access: input.access,
1145
+ stability: 'stable',
1146
+ inputSchema: { type: 'object', additionalProperties: false },
1147
+ outputSchema: { type: 'object' },
1148
+ effects: {
1149
+ persistence: input.persistence,
1150
+ undoable: input.id === 'history.undo' || input.id === 'history.redo',
1151
+ idempotent: input.idempotent,
1152
+ },
1153
+ presentation: {
1154
+ category: 'History',
1155
+ inputMode: 'none',
1156
+ ...(input.shortcut ? { shortcut: input.shortcut } : {}),
1157
+ ...(input.menu ? { menu: input.menu } : {}),
1158
+ },
1159
+ };
1160
+ }
1161
+ function historyOutput(session) {
1162
+ const state = session.getState({ cloneDocuments: false });
1163
+ return {
1164
+ documentRevision: state.documentRevision,
1165
+ dirty: state.dirty,
1166
+ canUndo: state.canUndo,
1167
+ canRedo: state.canRedo,
1168
+ };
1169
+ }
1170
+ function createSnapshot(state, serviceInstanceId, eventCursor) {
1171
+ return {
1172
+ serviceInstanceId,
1173
+ documentRevision: state.documentRevision,
1174
+ documentStructureRevision: state.documentStructureRevision,
1175
+ eventCursor,
1176
+ dirty: state.dirty,
1177
+ canUndo: state.canUndo,
1178
+ canRedo: state.canRedo,
1179
+ history: {
1180
+ entries: state.history.entries
1181
+ .slice(0, DEFAULT_HISTORY_VIEW_LIMIT)
1182
+ .map(entry => ({ ...entry })),
1183
+ },
1184
+ document: state.workingDocument,
1185
+ savedDocument: state.persistedDocument,
1186
+ };
1187
+ }
1188
+ function cancelledDiagnostic(commandId) {
1189
+ return {
1190
+ ok: false,
1191
+ diagnostics: [diagnostic('command.cancelled', `Editor command was cancelled: ${commandId}`)],
1192
+ };
1193
+ }
1194
+ function diagnostic(code, message, details) {
1195
+ return {
1196
+ severity: 'error',
1197
+ source: 'command-system',
1198
+ code,
1199
+ message,
1200
+ ...(details ? { details } : {}),
1201
+ };
1202
+ }
1203
+ function normalizeRequiredId(value, label) {
1204
+ if (typeof value !== 'string' || !value.trim())
1205
+ throw new Error(`Editor Authoring Host ${label} is required.`);
1206
+ return value.trim();
1207
+ }
1208
+ function normalizePositiveInteger(value, fallback) {
1209
+ return Number.isInteger(value) && value > 0 ? value : fallback;
1210
+ }
1211
+ //# sourceMappingURL=editor-authoring-host.js.map