@seriousgaming/sdk-tools 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/dist/bundling/ui-bundler.d.ts +12 -0
  2. package/dist/cli-25RWY5BQ.js +41 -0
  3. package/dist/cli-272KBNJH.js +97 -0
  4. package/dist/cli-2BH7FX27.js +52 -0
  5. package/dist/cli-2GOFEW26.js +81 -0
  6. package/dist/cli-3E3MD5U4.js +21 -0
  7. package/dist/cli-3HE4AVZG.js +115 -0
  8. package/dist/cli-4AKVLEC4.js +1387 -0
  9. package/dist/cli-4BV45LBH.js +126 -0
  10. package/dist/cli-4LKXZQ2B.js +48 -0
  11. package/dist/cli-4UWFQNGF.js +54 -0
  12. package/dist/cli-4YB3ROVR.js +78 -0
  13. package/dist/cli-57RXC3HQ.js +36 -0
  14. package/dist/cli-5JEGTVTG.js +96 -0
  15. package/dist/cli-6AMT3BUO.js +97 -0
  16. package/dist/cli-6RRVEGFB.js +80 -0
  17. package/dist/cli-6WXLXJVX.js +36 -0
  18. package/dist/cli-7OGYADZ3.js +97 -0
  19. package/dist/cli-AK7OIPWY.js +229 -0
  20. package/dist/cli-B4TN6PJP.js +124 -0
  21. package/dist/cli-B6YHEKIJ.js +248 -0
  22. package/dist/cli-BPYMTOUL.js +89 -0
  23. package/dist/cli-BWX5E7TQ.js +23 -0
  24. package/dist/cli-BYJWFFCF.js +37 -0
  25. package/dist/cli-C3NVCKO6.js +43 -0
  26. package/dist/cli-C47GJATR.js +42 -0
  27. package/dist/cli-C5QOJJWX.js +46 -0
  28. package/dist/cli-C6TH5S7K.js +6417 -0
  29. package/dist/cli-DL2CVMRF.js +89 -0
  30. package/dist/cli-DMW2OQIJ.js +76 -0
  31. package/dist/cli-DZW3XD5F.js +143 -0
  32. package/dist/cli-E2NLWIFE.js +1331 -0
  33. package/dist/cli-E33CJRRQ.js +36 -0
  34. package/dist/cli-E6DJIMYD.js +142 -0
  35. package/dist/cli-EEFJKIGL.js +151 -0
  36. package/dist/cli-EVFS55WN.js +185 -0
  37. package/dist/cli-F2D4GGUA.js +549 -0
  38. package/dist/cli-FBTRTIZJ.js +226 -0
  39. package/dist/cli-FWFRKQNE.js +11 -0
  40. package/dist/cli-FYINNRML.js +760 -0
  41. package/dist/cli-G522CPRL.js +88 -0
  42. package/dist/cli-G6KELFSX.js +2847 -0
  43. package/dist/cli-G6UE5NL4.js +90 -0
  44. package/dist/cli-GBFM76BF.js +16 -0
  45. package/dist/cli-GDQ6ILJY.js +101 -0
  46. package/dist/cli-GFBGYFYD.js +50 -0
  47. package/dist/cli-GGPDQNM3.js +35 -0
  48. package/dist/cli-GTSGLN3Z.js +307 -0
  49. package/dist/cli-GUXKQMJ7.js +13641 -0
  50. package/dist/cli-GXD36NF2.js +60 -0
  51. package/dist/cli-HCRTYQQS.js +16 -0
  52. package/dist/cli-HYY64SUD.js +185 -0
  53. package/dist/cli-I355WTAF.js +463 -0
  54. package/dist/cli-IDKYF5XB.js +59 -0
  55. package/dist/cli-ILKCQNM6.js +8 -0
  56. package/dist/cli-IRZ5KB7D.js +36 -0
  57. package/dist/cli-IUS2YCD3.js +31 -0
  58. package/dist/cli-J4DKUUTK.js +138 -0
  59. package/dist/cli-JFU22EJ2.js +187 -0
  60. package/dist/cli-JMZLT65J.js +226 -0
  61. package/dist/cli-JZM7XTNV.js +89 -0
  62. package/dist/cli-K2B6WHKA.js +81 -0
  63. package/dist/cli-KL3756X6.js +126 -0
  64. package/dist/cli-KNOOKGYW.js +88 -0
  65. package/dist/cli-LFGRFIEO.js +226 -0
  66. package/dist/cli-LFM7GJHI.js +0 -0
  67. package/dist/cli-LMDJCHHD.js +304 -0
  68. package/dist/cli-LXYPE3L5.js +99 -0
  69. package/dist/cli-M6BCQRID.js +153 -0
  70. package/dist/cli-MBNMPVDC.js +367 -0
  71. package/dist/cli-MJUYJIEP.js +13 -0
  72. package/dist/cli-MMN4BPO4.js +145 -0
  73. package/dist/cli-MYJGMA6U.js +40 -0
  74. package/dist/cli-N6H6T2E2.js +616 -0
  75. package/dist/cli-O5KP4OVN.js +61 -0
  76. package/dist/cli-O6PWMJTZ.js +25 -0
  77. package/dist/cli-ORIG557O.js +141 -0
  78. package/dist/cli-PFFCNGHI.js +243 -0
  79. package/dist/cli-PNLYX6R6.js +131 -0
  80. package/dist/cli-PQBXVLEU.js +649 -0
  81. package/dist/cli-PTT5RGKO.js +62 -0
  82. package/dist/cli-Q2XJF5AS.js +127 -0
  83. package/dist/cli-QEVDDBNO.js +60 -0
  84. package/dist/cli-QEVE5HUM.js +167 -0
  85. package/dist/cli-QUIJCBYB.js +391 -0
  86. package/dist/cli-QUNIRH7A.js +57 -0
  87. package/dist/cli-QVASWX2A.js +187 -0
  88. package/dist/cli-QWQMPCL6.js +253 -0
  89. package/dist/cli-R4PCG5YX.js +131 -0
  90. package/dist/cli-RA673NGF.js +53 -0
  91. package/dist/cli-RN6IWTL2.js +36 -0
  92. package/dist/cli-ROT3DRKU.js +145 -0
  93. package/dist/cli-RZITKPJX.js +367 -0
  94. package/dist/cli-S5IVGDDD.js +32 -0
  95. package/dist/cli-S5QDONIQ.js +218 -0
  96. package/dist/cli-SIPDUBFL.js +36 -0
  97. package/dist/cli-SMFSZF2G.js +4009 -0
  98. package/dist/cli-SRHBXZCN.js +159 -0
  99. package/dist/cli-TCY5LJ7E.js +88 -0
  100. package/dist/cli-TDSQSCX4.js +131 -0
  101. package/dist/cli-TIDQ4WUE.js +257 -0
  102. package/dist/cli-TLLA6KAP.js +79 -0
  103. package/dist/cli-TPU4TUR6.js +132 -0
  104. package/dist/cli-U2UE7I7J.js +30 -0
  105. package/dist/cli-UELGBQG7.js +101 -0
  106. package/dist/cli-UHSZBKYO.js +97 -0
  107. package/dist/cli-UJ4UCL2Z.js +38 -0
  108. package/dist/cli-UKQYZYFK.js +31 -0
  109. package/dist/cli-UMFFURZ7.js +81 -0
  110. package/dist/cli-UNAJ2OTE.js +15 -0
  111. package/dist/cli-UNJ5X6BU.js +89 -0
  112. package/dist/cli-UTJU4IYG.js +117 -0
  113. package/dist/cli-V4GHRWOV.js +1837 -0
  114. package/dist/cli-VCI3CG36.js +73 -0
  115. package/dist/cli-VCKOC2EV.js +256 -0
  116. package/dist/cli-VL2P354N.js +46 -0
  117. package/dist/cli-WAE26SVW.js +72 -0
  118. package/dist/cli-WOGIAU2E.js +100 -0
  119. package/dist/cli-WU43JT4T.js +52 -0
  120. package/dist/cli-XCO2VQOH.js +122 -0
  121. package/dist/cli-XSVGKI3R.js +39 -0
  122. package/dist/cli-YOTGR3NB.js +82 -0
  123. package/dist/cli-YVVXUD2G.js +197 -0
  124. package/dist/cli-ZISJ36MM.js +89 -0
  125. package/dist/cli-ZTWOE3ZT.js +65 -0
  126. package/dist/cli-ZVSFYDPQ.js +205 -0
  127. package/dist/cli-ZWPYIXNI.js +68 -0
  128. package/dist/cli.js +171 -42385
  129. package/dist/client/build-surfaces.d.ts +33 -0
  130. package/dist/client/dev-server.d.ts +6 -0
  131. package/dist/client/index.d.ts +1 -0
  132. package/dist/client/playwright.d.ts +62 -0
  133. package/dist/client.js +339 -56
  134. package/dist/core/session.d.ts +15 -1
  135. package/dist/dev/console/assets/{index-BvB-LFQZ.js → index-CuMOOH9m.js} +21 -21
  136. package/dist/dev/console/index.html +1 -1
  137. package/dist/dev/public-origins.d.ts +61 -0
  138. package/dist/dev/shell.d.ts +51 -4
  139. package/dist/dev/surfaces.d.ts +7 -0
  140. package/dist/docs/ai-agents.md +5 -0
  141. package/dist/docs/api/index.md +14 -12
  142. package/dist/docs/api/sdk-tools-client.md +29 -0
  143. package/dist/docs/api/sdk-tools-playwright.md +104 -0
  144. package/dist/docs/changelog-0.x.md +2 -2
  145. package/dist/docs/changelog.md +56 -4
  146. package/dist/docs/cli-and-dev-server.md +79 -0
  147. package/dist/docs/cli-error-codes.md +39 -36
  148. package/dist/docs/cli-reference.md +93 -32
  149. package/dist/docs/environment-variables.md +16 -5
  150. package/dist/docs/guides/ai-facilitation.md +2 -0
  151. package/dist/docs/guides/capabilities.md +2 -0
  152. package/dist/docs/guides/designing-a-game.md +31 -4
  153. package/dist/docs/guides/designing-screens.md +133 -0
  154. package/dist/docs/guides/endpoints.md +2 -0
  155. package/dist/docs/guides/engine-testing.md +5 -1
  156. package/dist/docs/guides/engine.md +2 -0
  157. package/dist/docs/guides/file-handling.md +3 -1
  158. package/dist/docs/guides/games.md +3 -1
  159. package/dist/docs/guides/global-settings.md +2 -0
  160. package/dist/docs/guides/guide.md +2 -0
  161. package/dist/docs/guides/hooks.md +2 -0
  162. package/dist/docs/guides/index.md +9 -0
  163. package/dist/docs/guides/internationalization.md +2 -0
  164. package/dist/docs/guides/llm-integration.md +4 -2
  165. package/dist/docs/guides/multi-team-games.md +3 -1
  166. package/dist/docs/guides/patterns.md +2 -0
  167. package/dist/docs/guides/presentation.md +1 -1
  168. package/dist/docs/guides/production-constraints.md +2 -0
  169. package/dist/docs/guides/scenario-editor.md +2 -0
  170. package/dist/docs/guides/scenarios.md +6 -2
  171. package/dist/docs/guides/session-game-flow.md +365 -0
  172. package/dist/docs/guides/session-hooks.md +205 -0
  173. package/dist/docs/guides/session.md +27 -565
  174. package/dist/docs/guides/settings.md +2 -0
  175. package/dist/docs/guides/setup.md +3 -1
  176. package/dist/docs/guides/speech-generation.md +2 -0
  177. package/dist/docs/guides/starter-game.md +63 -23
  178. package/dist/docs/guides/testing.md +35 -18
  179. package/dist/docs/guides/tick-controller.md +3 -1
  180. package/dist/docs/guides/type-safety.md +2 -0
  181. package/dist/docs/guides/ui-files-and-llms.md +328 -0
  182. package/dist/docs/guides/ui-participants.md +281 -0
  183. package/dist/docs/guides/ui-styling.md +263 -0
  184. package/dist/docs/guides/ui-ticks.md +247 -0
  185. package/dist/docs/guides/ui.md +11 -1092
  186. package/dist/docs/guides/upgrading.md +2 -0
  187. package/dist/docs/guides/validators.md +2 -0
  188. package/dist/docs/guides/waiting-room.md +1 -1
  189. package/dist/docs/index.md +2 -1
  190. package/dist/docs/page-index.md +146 -0
  191. package/dist/docs/recipes/adapt-a-game-for-walkthroughs.md +1 -1
  192. package/dist/docs/recipes/adapt-ui-for-observers.md +1 -1
  193. package/dist/docs/recipes/create-presentation.md +11 -0
  194. package/dist/docs/recipes/create-scenario-editor.md +1 -0
  195. package/dist/docs/recipes/create-session-ui.md +2 -1
  196. package/dist/docs/recipes/create-setup.md +1 -0
  197. package/dist/docs/recipes/create-user-interface.md +1 -0
  198. package/dist/docs/recipes/create-waiting-room-ui.md +1 -0
  199. package/dist/docs/recipes/design-state-for-concurrent-writes.md +1 -1
  200. package/dist/docs/recipes/e2e-testing.md +19 -20
  201. package/dist/docs/recipes/fix-duplicate-packages.md +2 -2
  202. package/dist/docs/recipes/index.md +3 -0
  203. package/dist/docs/recipes/screenshot-a-surface.md +80 -0
  204. package/dist/docs/recipes/test-a-multi-role-game.md +1 -1
  205. package/dist/docs/recipes/use-request-tick.md +2 -2
  206. package/dist/execution/config-resolver.d.ts +4 -1
  207. package/dist/playwright.js +32232 -0
  208. package/dist/runtime/manifest-version.d.ts +1 -1
  209. package/dist/runtime.js +1 -1
  210. package/dist/templates/package/CLAUDE.md.template +14 -5
  211. package/dist/templates/package/DESIGN.md.liquid +39 -7
  212. package/dist/templates/package/README.md.liquid +1 -1
  213. package/dist/templates/package/claude/rules/workflow-create-user-interface.md +1 -1
  214. package/dist/templates/package/claude/rules/workflow-test-engine-or-ui.md +1 -1
  215. package/dist/templates/package/global-setup.ts.template +7 -18
  216. package/dist/templates/package/playwright.config.ts.liquid +8 -11
  217. package/dist/templates/package/pnpm-workspace.yaml.template +13 -0
  218. package/dist/templates/starter-game/capabilities/pacing/capability.sdk.json +18 -0
  219. package/dist/templates/starter-game/package.json +2 -0
  220. package/dist/templates/starter-game/playwright.config.ts +8 -11
  221. package/dist/templates/starter-game/presentation/defaults.ts +52 -0
  222. package/dist/templates/starter-game/presentation/index.html +20 -0
  223. package/dist/templates/starter-game/presentation/presentation.sdk.json +10 -0
  224. package/dist/templates/starter-game/presentation/src/App.tsx +55 -0
  225. package/dist/templates/starter-game/presentation/src/Band.tsx +40 -0
  226. package/dist/templates/starter-game/presentation/src/Slides.tsx +415 -0
  227. package/dist/templates/starter-game/presentation/src/WeatherIcon.tsx +21 -0
  228. package/dist/templates/starter-game/presentation/src/i18n.ts +88 -0
  229. package/dist/templates/starter-game/presentation/src/main.tsx +15 -0
  230. package/dist/templates/starter-game/presentation/src/stalls.test.ts +196 -0
  231. package/dist/templates/starter-game/presentation/src/stalls.ts +199 -0
  232. package/dist/templates/starter-game/presentation/types.ts +94 -0
  233. package/dist/templates/starter-game/seriousgaming.sdk.json +2 -1
  234. package/dist/templates/starter-game/session/defaults.ts +6 -0
  235. package/dist/templates/starter-game/session/index.html +1 -1
  236. package/dist/templates/starter-game/session/session.sdk.json +2 -2
  237. package/dist/templates/starter-game/session/src/App.test.tsx +436 -115
  238. package/dist/templates/starter-game/session/src/App.tsx +372 -222
  239. package/dist/templates/starter-game/session/src/JoinCodes.tsx +184 -0
  240. package/dist/templates/starter-game/session/src/ManagePanel.tsx +188 -0
  241. package/dist/templates/starter-game/session/src/Results.tsx +340 -0
  242. package/dist/templates/starter-game/session/src/SessionBar.tsx +179 -0
  243. package/dist/templates/starter-game/session/src/SessionPanels.tsx +105 -0
  244. package/dist/templates/starter-game/session/src/SidePanel.tsx +89 -0
  245. package/dist/templates/starter-game/session/src/StallCard.tsx +253 -0
  246. package/dist/templates/starter-game/session/src/TopBar.tsx +36 -0
  247. package/dist/templates/starter-game/session/src/i18n.ts +91 -24
  248. package/dist/templates/starter-game/session/src/status.ts +28 -0
  249. package/dist/templates/starter-game/session/types.ts +8 -2
  250. package/dist/templates/starter-game/shared/Awning.tsx +31 -0
  251. package/dist/templates/starter-game/shared/HostLogo.test.tsx +38 -0
  252. package/dist/templates/starter-game/shared/HostLogo.tsx +48 -0
  253. package/dist/templates/starter-game/shared/StallIcons.tsx +83 -0
  254. package/dist/templates/starter-game/shared/days.ts +11 -0
  255. package/dist/templates/starter-game/shared/format.test.ts +13 -0
  256. package/dist/templates/starter-game/{ui/src → shared}/format.ts +1 -1
  257. package/dist/templates/starter-game/testing/e2e/game.spec.ts +43 -9
  258. package/dist/templates/starter-game/testing/e2e/global-setup.ts +7 -18
  259. package/dist/templates/starter-game/ui/defaults.ts +3 -0
  260. package/dist/templates/starter-game/ui/src/App.test.tsx +197 -29
  261. package/dist/templates/starter-game/ui/src/App.tsx +176 -99
  262. package/dist/templates/starter-game/ui/src/DayBar.test.tsx +50 -7
  263. package/dist/templates/starter-game/ui/src/DayBar.tsx +96 -38
  264. package/dist/templates/starter-game/ui/src/DaysTable.tsx +69 -0
  265. package/dist/templates/starter-game/ui/src/FirstDay.tsx +37 -0
  266. package/dist/templates/starter-game/ui/src/Header.tsx +257 -0
  267. package/dist/templates/starter-game/ui/src/Lesson.tsx +63 -0
  268. package/dist/templates/starter-game/ui/src/MakeRow.tsx +98 -71
  269. package/dist/templates/starter-game/ui/src/Notices.tsx +59 -0
  270. package/dist/templates/starter-game/ui/src/PastDay.tsx +88 -0
  271. package/dist/templates/starter-game/ui/src/Section.tsx +26 -26
  272. package/dist/templates/starter-game/ui/src/ThemeToggle.tsx +25 -11
  273. package/dist/templates/starter-game/ui/src/TodayPanel.test.tsx +37 -33
  274. package/dist/templates/starter-game/ui/src/TodayPanel.tsx +66 -52
  275. package/dist/templates/starter-game/ui/src/WeatherCard.tsx +47 -0
  276. package/dist/templates/starter-game/ui/src/WeekOver.tsx +145 -0
  277. package/dist/templates/starter-game/ui/src/YesterdayPanel.tsx +65 -114
  278. package/dist/templates/starter-game/ui/src/days.ts +58 -0
  279. package/dist/templates/starter-game/ui/src/i18n.ts +86 -32
  280. package/dist/templates/starter-game/ui/src/test-helpers.ts +1 -0
  281. package/dist/templates/starter-game/ui/src/theme.ts +8 -8
  282. package/dist/templates/starter-game/ui/types.ts +6 -0
  283. package/dist/templates/starter-game/ui/ui.sdk.json +1 -1
  284. package/dist/templates/starter-game/validators/daylimit/defaults.ts +13 -0
  285. package/dist/templates/starter-game/validators/daylimit/logic/logic.test.ts +20 -0
  286. package/dist/templates/starter-game/validators/daylimit/logic/logic.ts +23 -0
  287. package/dist/templates/starter-game/validators/daylimit/types.ts +23 -0
  288. package/dist/templates/starter-game/validators/daylimit/validator.sdk.json +10 -0
  289. package/dist/templates/starter-game/waiting_room/src/App.test.tsx +83 -5
  290. package/dist/templates/starter-game/waiting_room/src/App.tsx +262 -119
  291. package/dist/templates/starter-game/waiting_room/src/i18n.ts +8 -4
  292. package/dist/utils/error-codes.d.ts +12 -0
  293. package/dist/utils/prompt.d.ts +5 -5
  294. package/dist/utils/resource-scan.d.ts +39 -0
  295. package/package.json +15 -4
  296. package/dist/templates/starter-game/session/src/Section.tsx +0 -37
  297. package/dist/templates/starter-game/session/src/TeamDoor.tsx +0 -96
  298. package/dist/templates/starter-game/session/src/format.ts +0 -8
  299. package/dist/templates/starter-game/ui/src/HistoryPanel.test.tsx +0 -74
  300. package/dist/templates/starter-game/ui/src/HistoryPanel.tsx +0 -120
  301. package/dist/templates/starter-game/ui/src/HostLogo.test.tsx +0 -25
  302. package/dist/templates/starter-game/ui/src/HostLogo.tsx +0 -38
package/dist/client.js CHANGED
@@ -487,6 +487,10 @@ var ERROR_CODES = {
487
487
  category: "usage",
488
488
  description: "A file named on the command line does not exist or cannot be read."
489
489
  },
490
+ DOCS_SECTION_NOT_FOUND: {
491
+ category: "usage",
492
+ description: "The page `docs view --section` reads has no heading by that name; the details list the ones it has."
493
+ },
490
494
  RESOURCE_TYPE_UNKNOWN: {
491
495
  category: "usage",
492
496
  description: "The resource type does not exist, or does not support this operation."
@@ -677,6 +681,10 @@ var ERROR_CODES = {
677
681
  category: "refused",
678
682
  description: "Game logic (an engine, hook, endpoint, validator or tick controller) threw. A diagnostic, not an error code: it sits in `diagnostics` under the command's TICK_FAILED, SESSION_ERROR or HANDLER_ERROR, with the file, line and column it threw at."
679
683
  },
684
+ SURFACE_NOT_RENDERED: {
685
+ category: "refused",
686
+ description: "`sdk screenshot` gave up on the page: its surface did not connect, or did not report its first paint before the timeout. error.details carries the page's console errors, failed requests and uncaught exceptions."
687
+ },
680
688
  SETTINGS_STALE: {
681
689
  category: "refused",
682
690
  description: "The package changed on disk since the session started in a way that applies only at initialisation (a setting, a manifest field such as `teams`, or a capability removed or moved to another scope), so a command that advances or changes play was refused. Run `sdk init`."
@@ -718,6 +726,10 @@ var ERROR_CODES = {
718
726
  category: "environment",
719
727
  description: "The dev server could not be stopped."
720
728
  },
729
+ BROWSER_MISSING: {
730
+ category: "environment",
731
+ description: "`sdk screenshot` found no Playwright in the package's dependencies, or no Chromium installed for it. Add `@playwright/test` and run `pnpm exec playwright install chromium`."
732
+ },
721
733
  LLM_NOT_CONFIGURED: {
722
734
  category: "environment",
723
735
  description: "Logic called generateText, and the dev server or in-process session running it has no platform API key configured."
@@ -838,8 +850,8 @@ var BUILTIN_FILTER = new RegExp(
838
850
  function refuseNodeBuiltins() {
839
851
  return {
840
852
  name: "refuse-node-builtins",
841
- setup(build) {
842
- build.onResolve({ filter: BUILTIN_FILTER }, (args) => {
853
+ setup(build2) {
854
+ build2.onResolve({ filter: BUILTIN_FILTER }, (args) => {
843
855
  if (args.kind === "entry-point" || !isNodeBuiltin(args.path)) return void 0;
844
856
  return {
845
857
  errors: [
@@ -3026,6 +3038,9 @@ function recordWarning(message, code3) {
3026
3038
 
3027
3039
  // cli/utils/logger.ts
3028
3040
  var isVerbose = false;
3041
+ function getVerboseMode() {
3042
+ return isVerbose;
3043
+ }
3029
3044
  function progress(message, ...args) {
3030
3045
  if (isJsonOutput()) console.error(message, ...args);
3031
3046
  else console.log(message, ...args);
@@ -5898,12 +5913,23 @@ var ConfigResolver = class {
5898
5913
  /**
5899
5914
  * Resolve the active scenario from a provided ID or the game's default.
5900
5915
  * Returns null if the game declares no scenarios, or when null is passed
5901
- * to explicitly opt out of the default scenario (the settings defaults).
5916
+ * for a game with no default scenario (the settings defaults).
5917
+ *
5918
+ * A game that declares a default never runs on none (§6.7), so null is
5919
+ * refused for it, naming the default.
5902
5920
  */
5903
5921
  resolveScenario(scenarioId) {
5904
- if (scenarioId === null) return null;
5905
5922
  const game = this.ctx.getGame();
5906
5923
  const config = this.ctx.getConfig();
5924
+ if (scenarioId === null) {
5925
+ const fallback = config?.scenarios?.find((s) => s.definition.default);
5926
+ if (fallback) {
5927
+ throw new DeniedError(
5928
+ `This game runs on a scenario: its default is "${fallback.definition.identifier}", so it cannot run on none`
5929
+ );
5930
+ }
5931
+ return null;
5932
+ }
5907
5933
  if (!game || !config) return null;
5908
5934
  const allScenarios = config.scenarios || [];
5909
5935
  if (allScenarios.length === 0) return null;
@@ -15370,10 +15396,10 @@ function resolveAll(constructs2, events, context) {
15370
15396
  const called = [];
15371
15397
  let index3 = -1;
15372
15398
  while (++index3 < constructs2.length) {
15373
- const resolve12 = constructs2[index3].resolveAll;
15374
- if (resolve12 && !called.includes(resolve12)) {
15375
- events = resolve12(events, context);
15376
- called.push(resolve12);
15399
+ const resolve13 = constructs2[index3].resolveAll;
15400
+ if (resolve13 && !called.includes(resolve13)) {
15401
+ events = resolve13(events, context);
15402
+ called.push(resolve13);
15377
15403
  }
15378
15404
  }
15379
15405
  return events;
@@ -21981,7 +22007,7 @@ var Processor = class _Processor extends CallableInstance {
21981
22007
  assertParser("process", this.parser || this.Parser);
21982
22008
  assertCompiler("process", this.compiler || this.Compiler);
21983
22009
  return done ? executor(void 0, done) : new Promise(executor);
21984
- function executor(resolve12, reject) {
22010
+ function executor(resolve13, reject) {
21985
22011
  const realFile = vfile(file);
21986
22012
  const parseTree = (
21987
22013
  /** @type {HeadTree extends undefined ? Node : HeadTree} */
@@ -22012,8 +22038,8 @@ var Processor = class _Processor extends CallableInstance {
22012
22038
  function realDone(error, file2) {
22013
22039
  if (error || !file2) {
22014
22040
  reject(error);
22015
- } else if (resolve12) {
22016
- resolve12(file2);
22041
+ } else if (resolve13) {
22042
+ resolve13(file2);
22017
22043
  } else {
22018
22044
  ok(done, "`done` is defined if `resolve` is not");
22019
22045
  done(void 0, file2);
@@ -22115,7 +22141,7 @@ var Processor = class _Processor extends CallableInstance {
22115
22141
  file = void 0;
22116
22142
  }
22117
22143
  return done ? executor(void 0, done) : new Promise(executor);
22118
- function executor(resolve12, reject) {
22144
+ function executor(resolve13, reject) {
22119
22145
  ok(
22120
22146
  typeof file !== "function",
22121
22147
  "`file` can\u2019t be a `done` anymore, we checked"
@@ -22129,8 +22155,8 @@ var Processor = class _Processor extends CallableInstance {
22129
22155
  );
22130
22156
  if (error) {
22131
22157
  reject(error);
22132
- } else if (resolve12) {
22133
- resolve12(resultingTree);
22158
+ } else if (resolve13) {
22159
+ resolve13(resultingTree);
22134
22160
  } else {
22135
22161
  ok(done, "`done` is defined if `resolve` is not");
22136
22162
  done(void 0, resultingTree, file2);
@@ -24863,7 +24889,7 @@ function fileSettingDeclarationErrors(identifier, settingsSchema) {
24863
24889
  }
24864
24890
  return errors;
24865
24891
  }
24866
- async function packageFileSettingErrors(owner, settings, schemas, resolve12, skip = () => false) {
24892
+ async function packageFileSettingErrors(owner, settings, schemas, resolve13, skip = () => false) {
24867
24893
  const errors = [];
24868
24894
  for (const [identifier, value] of Object.entries(settings)) {
24869
24895
  for (const file of fileSettingValues(schemas[identifier], value)) {
@@ -24875,7 +24901,7 @@ async function packageFileSettingErrors(owner, settings, schemas, resolve12, ski
24875
24901
  );
24876
24902
  continue;
24877
24903
  }
24878
- const found = await resolve12(file.value);
24904
+ const found = await resolve13(file.value);
24879
24905
  if (!found) {
24880
24906
  errors.push(`${setting}, but the package ships no such file`);
24881
24907
  continue;
@@ -25577,6 +25603,12 @@ var Session = class {
25577
25603
  holdingAtSetup = false;
25578
25604
  /** Edits on disk that apply only at the next initialisation (#640). */
25579
25605
  pending = NO_PENDING_CHANGES;
25606
+ /**
25607
+ * Set when applying {@link pending} threw. The executor has already
25608
+ * adopted the package on disk by then, so the next reload finds nothing
25609
+ * changed and would otherwise drop the edit `Init` never ran on.
25610
+ */
25611
+ pendingInitFailed = false;
25580
25612
  /** The scenario editor's drafts, which belong to no session (§6.5). */
25581
25613
  drafts = new ScenarioDrafts();
25582
25614
  /** What the parts below are handed of the session. */
@@ -26022,26 +26054,42 @@ var Session = class {
26022
26054
  );
26023
26055
  return { kind: "failed", pending: this.pendingChanges(), added: [] };
26024
26056
  }
26025
- if (hasPendingChanges(reload.pending)) {
26026
- if (this.options.reinitOnChange || !this.hasPlayed()) {
26027
- this.pending = reload.pending;
26057
+ const pending = this.pendingInitFailed && !hasPendingChanges(reload.pending) ? this.pending : reload.pending;
26058
+ const reinitialise = hasPendingChanges(pending) || reload.added.length > 0 || this.pendingInitFailed;
26059
+ if (reinitialise && (this.options.reinitOnChange || !this.hasPlayed())) {
26060
+ this.pending = pending;
26061
+ try {
26028
26062
  await this.applyPendingChanges();
26029
26063
  this.emitState(REINITIALISED_ON_CHANGE);
26030
- return { kind: "reinitialised", pending: reload.pending, added: [] };
26064
+ return { kind: "reinitialised", pending, added: reload.added };
26065
+ } catch (error) {
26066
+ this.pendingInitFailed = true;
26067
+ this.report(
26068
+ `The session could not re-initialise to apply an edit, because Init failed: ${errorMessage(error)}`,
26069
+ "reload"
26070
+ );
26071
+ this.seedAdded(reload.added);
26072
+ this.emitState("bundles-reloaded");
26073
+ return { kind: "failed", pending, added: reload.added };
26031
26074
  }
26032
26075
  }
26033
- this.pending = reload.pending;
26034
- if (reload.added.length > 0) {
26035
- this.state.setTeamContexts(this.state.getTeamContexts());
26036
- }
26076
+ this.pending = pending;
26077
+ this.seedAdded(reload.added);
26037
26078
  this.emitState("bundles-reloaded");
26038
26079
  return {
26039
- kind: hasPendingChanges(reload.pending) ? "pending" : "live",
26080
+ kind: hasPendingChanges(pending) ? "pending" : "live",
26040
26081
  pending: this.pendingChanges(),
26041
26082
  added: reload.added
26042
26083
  };
26043
26084
  });
26044
26085
  }
26086
+ /**
26087
+ * Give every board the capabilities a reload added, now rather than at
26088
+ * its next write, so a read sees them straight away.
26089
+ */
26090
+ seedAdded(added) {
26091
+ if (added.length > 0) this.state.setTeamContexts(this.state.getTeamContexts());
26092
+ }
26045
26093
  /**
26046
26094
  * Whether anything has been played: a tick committed and not since
26047
26095
  * rewound. A session at its configuration step has played nothing.
@@ -26289,6 +26337,7 @@ var Session = class {
26289
26337
  this.executor.setWaitingRoomOpen(this.waitingRoomOpen);
26290
26338
  }
26291
26339
  this.pending = NO_PENDING_CHANGES;
26340
+ this.pendingInitFailed = false;
26292
26341
  return 0;
26293
26342
  }
26294
26343
  setWaitingRoom(open) {
@@ -26905,6 +26954,7 @@ async function createTestSession(options) {
26905
26954
  }
26906
26955
 
26907
26956
  // cli/dev/shell.ts
26957
+ import { statSync as statSync3 } from "fs";
26908
26958
  import { mkdtemp as mkdtemp2, rm as rm5 } from "fs/promises";
26909
26959
  import { createServer } from "http";
26910
26960
  import { tmpdir as tmpdir2 } from "os";
@@ -26934,7 +26984,7 @@ async function listenWithPortFallback(server, startPort, options = {}) {
26934
26984
  );
26935
26985
  }
26936
26986
  function tryListen(server, port, host) {
26937
- return new Promise((resolve12, reject) => {
26987
+ return new Promise((resolve13, reject) => {
26938
26988
  const cleanup = () => {
26939
26989
  server.removeListener("error", onError);
26940
26990
  server.removeListener("listening", onListening);
@@ -26942,14 +26992,14 @@ function tryListen(server, port, host) {
26942
26992
  const onError = (err) => {
26943
26993
  cleanup();
26944
26994
  if (err.code === "EADDRINUSE") {
26945
- resolve12(false);
26995
+ resolve13(false);
26946
26996
  } else {
26947
26997
  reject(err);
26948
26998
  }
26949
26999
  };
26950
27000
  const onListening = () => {
26951
27001
  cleanup();
26952
- resolve12(true);
27002
+ resolve13(true);
26953
27003
  };
26954
27004
  server.once("error", onError);
26955
27005
  server.once("listening", onListening);
@@ -26979,13 +27029,13 @@ async function isFree(port) {
26979
27029
  return true;
26980
27030
  }
26981
27031
  function isFreeOn(port, host) {
26982
- return new Promise((resolve12) => {
27032
+ return new Promise((resolve13) => {
26983
27033
  const probe = createSocket();
26984
27034
  probe.once(
26985
27035
  "error",
26986
- (error) => resolve12(error.code === "EADDRNOTAVAIL" || error.code === "EAFNOSUPPORT")
27036
+ (error) => resolve13(error.code === "EADDRNOTAVAIL" || error.code === "EAFNOSUPPORT")
26987
27037
  );
26988
- probe.once("listening", () => probe.close(() => resolve12(true)));
27038
+ probe.once("listening", () => probe.close(() => resolve13(true)));
26989
27039
  probe.listen(port, host);
26990
27040
  });
26991
27041
  }
@@ -29690,7 +29740,7 @@ function newInstanceId() {
29690
29740
  }
29691
29741
 
29692
29742
  // cli/dev/package-watcher.ts
29693
- import { watch as watchDirectory } from "fs";
29743
+ import { rmSync as rmSync2, watch as watchDirectory } from "fs";
29694
29744
  import { mkdtemp, rm as rm3, writeFile as writeFile4 } from "fs/promises";
29695
29745
  import { tmpdir } from "os";
29696
29746
  import { basename as basename4, join as join16, relative as relative7, sep as sep11 } from "path";
@@ -29725,7 +29775,12 @@ function classifyDirectory(packagePath, path3) {
29725
29775
  }
29726
29776
  async function untilWatchesDeliver(timeoutMs = 2e3) {
29727
29777
  const directory = await mkdtemp(join16(tmpdir(), "sg-watch-"));
29728
- const remove = () => rm3(directory, { recursive: true, force: true });
29778
+ const removeOnExit = () => rmSync2(directory, { recursive: true, force: true });
29779
+ process.once("exit", removeOnExit);
29780
+ const remove = () => {
29781
+ process.off("exit", removeOnExit);
29782
+ return rm3(directory, { recursive: true, force: true });
29783
+ };
29729
29784
  let delivered = false;
29730
29785
  let probe;
29731
29786
  try {
@@ -29742,7 +29797,7 @@ async function untilWatchesDeliver(timeoutMs = 2e3) {
29742
29797
  const deadline = Date.now() + timeoutMs;
29743
29798
  for (let attempt = 0; !delivered && Date.now() < deadline; attempt++) {
29744
29799
  await writeFile4(join16(directory, "probe"), String(attempt));
29745
- await new Promise((resolve12) => setTimeout(resolve12, 25));
29800
+ await new Promise((resolve13) => setTimeout(resolve13, 25));
29746
29801
  }
29747
29802
  return async () => {
29748
29803
  probe.close();
@@ -29774,7 +29829,7 @@ async function watchPackage(packagePath, onChange, debounceMs = 150) {
29774
29829
  const change = classifyChange(packagePath, path3);
29775
29830
  if (change) schedule(change);
29776
29831
  });
29777
- await new Promise((resolve12) => watcher.once("ready", () => resolve12()));
29832
+ await new Promise((resolve13) => watcher.once("ready", () => resolve13()));
29778
29833
  const closeProbe = await untilWatchesDeliver();
29779
29834
  return {
29780
29835
  async close() {
@@ -29786,6 +29841,32 @@ async function watchPackage(packagePath, onChange, debounceMs = 150) {
29786
29841
  };
29787
29842
  }
29788
29843
 
29844
+ // cli/dev/public-origins.ts
29845
+ function publicAssetOrigin(origins, assetPort) {
29846
+ if (origins.publicAssetUrl) return origins.publicAssetUrl;
29847
+ if (!origins.publicUrl) return null;
29848
+ const url = new URL(origins.publicUrl);
29849
+ return `${url.protocol}//${url.hostname}:${assetPort}`;
29850
+ }
29851
+ function publicHmrOrigin(origins, assetPort, vitePort) {
29852
+ if (origins.publicHmrUrl) return origins.publicHmrUrl;
29853
+ const asset = publicAssetOrigin(origins, assetPort);
29854
+ if (!asset) return null;
29855
+ const url = new URL(asset);
29856
+ return `${url.protocol === "https:" ? "wss" : "ws"}://${url.hostname}:${vitePort}`;
29857
+ }
29858
+ function hmrClientTarget(origin) {
29859
+ const url = new URL(origin);
29860
+ const protocol = url.protocol === "wss:" ? "wss" : "ws";
29861
+ const clientPort = url.port ? Number(url.port) : protocol === "wss" ? 443 : 80;
29862
+ return { protocol, host: url.hostname, clientPort };
29863
+ }
29864
+ function publicHostnames(origins) {
29865
+ return [
29866
+ ...new Set(origins.filter((o) => Boolean(o)).map((o) => new URL(o).hostname))
29867
+ ];
29868
+ }
29869
+
29789
29870
  // cli/dev/routes.ts
29790
29871
  import { existsSync as existsSync19 } from "fs";
29791
29872
  import { readFile as readFile10 } from "fs/promises";
@@ -30129,7 +30210,7 @@ function blobLinks(response, urlFor) {
30129
30210
  }
30130
30211
 
30131
30212
  // cli/dev/surfaces.ts
30132
- var PREFIX = {
30213
+ var SURFACE_PREFIX = {
30133
30214
  game: "/user-interfaces",
30134
30215
  session: "/session-user-interfaces",
30135
30216
  setup: "/setup-user-interfaces",
@@ -30153,7 +30234,7 @@ function toSurface(kind2, bundle, hidden) {
30153
30234
  return {
30154
30235
  kind: kind2,
30155
30236
  identifier,
30156
- src: `${PREFIX[kind2]}/${encodeURIComponent(identifier)}/${bundle.ui?.entrypoint ?? "index.html"}`,
30237
+ src: `${SURFACE_PREFIX[kind2]}/${encodeURIComponent(identifier)}/${bundle.ui?.entrypoint ?? "index.html"}`,
30157
30238
  reads: visible(reads),
30158
30239
  writes: visible(writes),
30159
30240
  endpoints: endpoints ?? [],
@@ -30162,6 +30243,14 @@ function toSurface(kind2, bundle, hidden) {
30162
30243
  settings: (kind2 === "setup" || kind2 === "scenario-editor" ? configures : settings) ?? []
30163
30244
  };
30164
30245
  }
30246
+ var SURFACE_SLOT = {
30247
+ game: "ui",
30248
+ session: "session",
30249
+ setup: "setup",
30250
+ "scenario-editor": "scenario_editor",
30251
+ "waiting-room": "waiting_room",
30252
+ presentation: "presentation"
30253
+ };
30165
30254
  function mountableSurfaces(config) {
30166
30255
  if (!config) return [];
30167
30256
  const hidden = new Set(
@@ -31073,11 +31162,11 @@ function parseRoute(pathname, search2) {
31073
31162
  const preview = query.has("preview");
31074
31163
  const scenario = query.get("scenario");
31075
31164
  const run = /^\/walkthrough(\/|$)/.test(pathname) ? "walkthrough" : "session";
31076
- for (const [pattern, build] of PATTERNS) {
31165
+ for (const [pattern, build2] of PATTERNS) {
31077
31166
  const match2 = pathname.match(pattern);
31078
31167
  if (match2) {
31079
31168
  return {
31080
- ...build(match2),
31169
+ ...build2(match2),
31081
31170
  bare,
31082
31171
  run,
31083
31172
  ...scenario === null ? {} : { scenario },
@@ -31283,6 +31372,8 @@ var DevShell = class {
31283
31372
  viteFailure = null;
31284
31373
  /** Serialises the first requests for a surface so they share one Vite. */
31285
31374
  viteStarting = null;
31375
+ /** The hot-reload socket's own listener, when a public origin moves its client. */
31376
+ hmrServer = null;
31286
31377
  port;
31287
31378
  vitePort;
31288
31379
  assetPort;
@@ -31321,6 +31412,10 @@ var DevShell = class {
31321
31412
  return this.brands;
31322
31413
  }
31323
31414
  async start() {
31415
+ const built = this.options.builtSurfaces;
31416
+ if (built !== void 0 && !statSync3(built, { throwIfNoEntry: false })?.isDirectory()) {
31417
+ throw new Error(`No built surfaces at ${built}: build them first`);
31418
+ }
31324
31419
  if (this.options.isolated) {
31325
31420
  const dir = await mkdtemp2(join19(tmpdir2(), "seriousgaming-dev-blobs-"));
31326
31421
  this.isolatedBlobs = { dir, restore: redirectBlobs(this.options.packagePath, dir) };
@@ -31381,10 +31476,10 @@ var DevShell = class {
31381
31476
  await this.viteStarting;
31382
31477
  await this.vite?.close();
31383
31478
  await Promise.all(
31384
- [this.server, this.assetServer].map(
31385
- (server) => new Promise((resolve12) => {
31386
- if (!server) return resolve12();
31387
- server.close(() => resolve12());
31479
+ [this.server, this.assetServer, this.hmrServer].map(
31480
+ (server) => new Promise((resolve13) => {
31481
+ if (!server) return resolve13();
31482
+ server.close(() => resolve13());
31388
31483
  })
31389
31484
  )
31390
31485
  );
@@ -31457,7 +31552,7 @@ var DevShell = class {
31457
31552
  record(outcome) {
31458
31553
  if (outcome.kind !== "failed") this.reloadFailure = null;
31459
31554
  if (outcome.kind === "reinitialised") this.seeded.clear();
31460
- for (const capability of outcome.added) this.seeded.add(capability);
31555
+ else for (const capability of outcome.added) this.seeded.add(capability);
31461
31556
  }
31462
31557
  /**
31463
31558
  * Everything this server could not apply live to `run`, as it stands now:
@@ -31502,18 +31597,37 @@ var DevShell = class {
31502
31597
  get assetUrl() {
31503
31598
  return `http://localhost:${this.assetPort}`;
31504
31599
  }
31600
+ /** Where people reach the console, when a proxy stands in front of it. */
31601
+ get publicUrl() {
31602
+ return this.options.publicUrl ?? null;
31603
+ }
31604
+ /** Where people's browsers load bundles from, when a proxy stands in front. */
31605
+ get publicAssetUrl() {
31606
+ return publicAssetOrigin(this.options, this.assetPort);
31607
+ }
31505
31608
  /**
31506
- * The asset origin as a client that reached `host` must name it: the same
31507
- * host, the asset port. A browser on another machine reached us by an
31508
- * address `localhost` would not resolve to on its side.
31609
+ * The asset origin as a client that reached `host` must name it: the
31610
+ * public one where given, else the same host on the asset port. A browser
31611
+ * on another machine reached us by an address `localhost` would not
31612
+ * resolve to on its side.
31509
31613
  */
31510
31614
  assetOrigin(host) {
31615
+ const configured = this.publicAssetUrl;
31616
+ if (configured) return configured;
31511
31617
  const name = (host ?? "localhost").replace(/:\d+$/, "") || "localhost";
31512
31618
  return `http://${name}:${this.assetPort}`;
31513
31619
  }
31514
31620
  /** The console's own origin, as a client that reached `host` names it. */
31515
31621
  consoleOrigin(host) {
31516
- return host ? `http://${host}` : this.url;
31622
+ return this.options.publicUrl ?? (host ? `http://${host}` : this.url);
31623
+ }
31624
+ /** Where a frame's hot-reload client connects, when a public origin decides it. */
31625
+ get publicHmrUrl() {
31626
+ return publicHmrOrigin(this.options, this.assetPort, this.vitePort);
31627
+ }
31628
+ /** What the bundle policy's `connect-src` admits for hot reload. */
31629
+ hmrSources(host) {
31630
+ return this.publicHmrUrl ?? hmrConnectSources(host, this.vitePort);
31517
31631
  }
31518
31632
  /** The session this shell wraps, for tests and for the CLI in-process path. */
31519
31633
  get runtime() {
@@ -31644,7 +31758,7 @@ ${MISSING_CONSOLE_MESSAGE}
31644
31758
  */
31645
31759
  configureAssets() {
31646
31760
  this.assetApp.use((req, res, next) => {
31647
- applyBundlePolicy(res, req.headers.host, this.vitePort);
31761
+ applyBundlePolicy(res, this.hmrSources(req.headers.host));
31648
31762
  next();
31649
31763
  });
31650
31764
  registerAssetRoutes(
@@ -31653,6 +31767,10 @@ ${MISSING_CONSOLE_MESSAGE}
31653
31767
  "/assets"
31654
31768
  );
31655
31769
  registerBrandRoutes(this.assetApp, () => this.brands);
31770
+ if (this.options.builtSurfaces !== void 0) {
31771
+ this.serveBuiltSurfaces(this.options.builtSurfaces);
31772
+ return;
31773
+ }
31656
31774
  this.assetApp.use(async (req, res, next) => {
31657
31775
  const vite = await this.ensureVite();
31658
31776
  if (vite) {
@@ -31672,6 +31790,24 @@ Install the package's dependencies and restart.`
31672
31790
  res.status(404).type("text/plain").send(`Not found: ${req.path}`);
31673
31791
  });
31674
31792
  }
31793
+ /**
31794
+ * Each surface from its built directory, which `sdk build` gives relative
31795
+ * asset paths, so the document and everything it loads resolve under the
31796
+ * route the console already mounts it at.
31797
+ */
31798
+ serveBuiltSurfaces(directory) {
31799
+ for (const kind2 of Object.keys(SURFACE_PREFIX)) {
31800
+ const slot2 = SURFACE_SLOT[kind2];
31801
+ this.assetApp.use(
31802
+ `${SURFACE_PREFIX[kind2]}/${slot2}`,
31803
+ express2.static(join19(directory, slot2), { index: false })
31804
+ );
31805
+ }
31806
+ this.assetApp.use((req, res) => {
31807
+ const missing = BUNDLE_ROUTE.test(req.path) ? `${req.path} is not in the built surfaces at ${directory}. Build them again after adding a surface.` : `Not found: ${req.path}`;
31808
+ res.status(404).type("text/plain").send(missing);
31809
+ });
31810
+ }
31675
31811
  /**
31676
31812
  * Vite, started the first time something asks for a surface (#320).
31677
31813
  *
@@ -31703,6 +31839,7 @@ Install the package's dependencies to serve its surfaces.
31703
31839
  return this.viteStarting;
31704
31840
  }
31705
31841
  async createVite() {
31842
+ const server = await this.viteServerOptions();
31706
31843
  return createViteServer({
31707
31844
  root: this.options.packagePath,
31708
31845
  appType: "custom",
@@ -31725,10 +31862,48 @@ Install the package's dependencies to serve its surfaces.
31725
31862
  workingDir: this.options.packagePath
31726
31863
  })
31727
31864
  ],
31728
- server: { middlewareMode: true, hmr: { port: this.vitePort, ...this.bindHost } },
31865
+ server,
31729
31866
  logLevel: "error"
31730
31867
  });
31731
31868
  }
31869
+ /**
31870
+ * Vite's server options: its own hot-reload socket on the Vite port, as
31871
+ * before, unless a public origin says where the client connects.
31872
+ *
31873
+ * Vite takes one `host` for both where its socket listens and where its
31874
+ * client connects, and a public hostname is no address to listen on. So
31875
+ * behind a proxy the socket's listener is opened here, on the Vite port
31876
+ * as usual, and Vite only attaches to it.
31877
+ */
31878
+ async viteServerOptions() {
31879
+ const hmr = this.publicHmrUrl;
31880
+ const overlay = this.options.errorOverlay === false ? { overlay: false } : {};
31881
+ if (!hmr) {
31882
+ return {
31883
+ middlewareMode: true,
31884
+ hmr: { port: this.vitePort, ...this.bindHost, ...overlay }
31885
+ };
31886
+ }
31887
+ const listener = createServer((_req, res) => {
31888
+ res.writeHead(426, { "Content-Type": "text/plain" }).end("Upgrade Required");
31889
+ });
31890
+ await new Promise((resolve13, reject) => {
31891
+ listener.once("error", reject);
31892
+ listener.listen(this.vitePort, this.bindHost.host, () => {
31893
+ listener.off("error", reject);
31894
+ resolve13();
31895
+ });
31896
+ });
31897
+ this.hmrServer = listener;
31898
+ return {
31899
+ middlewareMode: true,
31900
+ ...this.options.errorOverlay === false ? { hmr: overlay } : {},
31901
+ ws: { server: listener, ...hmrClientTarget(hmr) },
31902
+ // Vite refuses a request whose `Host` it does not recognise, and a
31903
+ // proxy that passes its own on would otherwise be refused it.
31904
+ allowedHosts: publicHostnames([this.options.publicUrl, this.publicAssetUrl, hmr])
31905
+ };
31906
+ }
31732
31907
  // -----------------------------------------------------------------------
31733
31908
  // WebSocket
31734
31909
  // -----------------------------------------------------------------------
@@ -31757,7 +31932,10 @@ Install the package's dependencies to serve its surfaces.
31757
31932
  this.reloadFailure = event.message;
31758
31933
  }
31759
31934
  if (event.type === "state") {
31760
- if (REINITIALISING_CAUSES.has(event.cause)) this.seeded.clear();
31935
+ if (REINITIALISING_CAUSES.has(event.cause)) {
31936
+ this.seeded.clear();
31937
+ this.reloadFailure = null;
31938
+ }
31761
31939
  this.syncPresence("session");
31762
31940
  }
31763
31941
  });
@@ -32017,9 +32195,19 @@ function reportReload(outcome) {
32017
32195
  case "failed":
32018
32196
  return;
32019
32197
  case "reinitialised":
32020
- logger.success(
32021
- `${describePendingChanges(outcome.pending)}. Re-initialised the session at tick 0 to apply it.`
32022
- );
32198
+ if (hasPendingChanges(outcome.pending)) {
32199
+ logger.success(
32200
+ `${describePendingChanges(outcome.pending)}. Re-initialised the session at tick 0 to apply it.`
32201
+ );
32202
+ }
32203
+ for (const capability of outcome.added) {
32204
+ logger.success(
32205
+ `Capability "${capability}" added. Re-initialised the session at tick 0 so Init runs for it.`
32206
+ );
32207
+ }
32208
+ if (!hasPendingChanges(outcome.pending) && outcome.added.length === 0) {
32209
+ logger.success("Package changed; re-initialised the session at tick 0.");
32210
+ }
32023
32211
  return;
32024
32212
  case "pending":
32025
32213
  logger.warn(
@@ -32048,8 +32236,7 @@ function send(socket, message) {
32048
32236
  if (socket.readyState !== 1) return;
32049
32237
  socket.send(JSON.stringify(message));
32050
32238
  }
32051
- function applyBundlePolicy(res, host, vitePort) {
32052
- const hmr = hmrConnectSources(host, vitePort);
32239
+ function applyBundlePolicy(res, hmr) {
32053
32240
  res.setHeader(
32054
32241
  "Content-Security-Policy",
32055
32242
  [
@@ -32087,6 +32274,7 @@ async function startDevServer(options) {
32087
32274
  ...options.clock === void 0 ? {} : { clock: options.clock },
32088
32275
  ...options.callbacks === void 0 ? {} : { callbacks: options.callbacks },
32089
32276
  ...options.reinitOnChange ? { reinitOnChange: true } : {},
32277
+ ...options.builtSurfaces === void 0 ? {} : { builtSurfaces: options.builtSurfaces },
32090
32278
  ...environment.seriousGamingApiKey === void 0 ? {} : { seriousGamingApiKey: environment.seriousGamingApiKey },
32091
32279
  ...environment.seriousGamingApiHost === void 0 ? {} : { seriousGamingApiHost: environment.seriousGamingApiHost },
32092
32280
  ...environment.elevenLabsApiKey === void 0 ? {} : { elevenLabsApiKey: environment.elevenLabsApiKey }
@@ -32108,8 +32296,103 @@ async function startDevServer(options) {
32108
32296
  }
32109
32297
  };
32110
32298
  }
32299
+
32300
+ // cli/client/build-surfaces.ts
32301
+ import { mkdtemp as mkdtemp3, rm as rm6 } from "fs/promises";
32302
+ import { tmpdir as tmpdir3 } from "os";
32303
+ import { join as join21 } from "path";
32304
+
32305
+ // cli/bundling/ui-bundler.ts
32306
+ import { realpathSync as realpathSync3 } from "fs";
32307
+ import { join as join20, resolve as resolve12 } from "path";
32308
+ import react2 from "@vitejs/plugin-react";
32309
+ import { build, loadConfigFromFile, mergeConfig } from "vite";
32310
+
32311
+ // cli/utils/resource-scan.ts
32312
+ function distPath(meta, identifier) {
32313
+ if (meta.slot) return meta.slot;
32314
+ return `${meta.pluralDir}/${identifier}`;
32315
+ }
32316
+
32317
+ // cli/bundling/ui-bundler.ts
32318
+ async function bundleUserInterface(ui, workingDir, buildDir, type) {
32319
+ const uiOutputDir = join20(buildDir, distPath(getResourceMeta(type), ui.definition.identifier));
32320
+ const uiRootDir = join20(workingDir, ui.rootDirectory);
32321
+ const uiDir = realpathSync3(uiRootDir);
32322
+ logger.debug(`Building ${ui.definition.identifier}...`);
32323
+ const isVerbose2 = getVerboseMode();
32324
+ const configEnv = { command: "build", mode: "production" };
32325
+ const rootConfigResult = await loadConfigFromFile(configEnv, void 0, workingDir);
32326
+ const uiConfigResult = await loadConfigFromFile(configEnv, void 0, uiDir);
32327
+ if (rootConfigResult?.path && uiConfigResult?.path) {
32328
+ logger.warn(
32329
+ `Both ${rootConfigResult.path} and ${uiConfigResult.path} exist. They will be merged (per-UI overrides package-root), but this is almost certainly a mistake \u2014 choose one location and delete the other.`
32330
+ );
32331
+ }
32332
+ const inlineConfig = {
32333
+ base: "./",
32334
+ // Relative paths, must use this for iframes to work
32335
+ root: uiDir,
32336
+ // We've already loaded both user configs explicitly above. Disable
32337
+ // Vite's own config-file auto-discovery so it doesn't load
32338
+ // `uiDir/vite.config.ts` a second time.
32339
+ configFile: false,
32340
+ plugins: [react2()],
32341
+ resolve: {
32342
+ dedupe: ["react", "react-dom", "@emotion/react", "@emotion/styled"]
32343
+ },
32344
+ build: {
32345
+ outDir: uiOutputDir,
32346
+ emptyOutDir: true,
32347
+ rollupOptions: {
32348
+ input: resolve12(uiDir, ui.ui.entrypoint)
32349
+ }
32350
+ },
32351
+ logLevel: isVerbose2 ? "info" : "silent"
32352
+ };
32353
+ const mergedUserConfig = mergeConfig(
32354
+ rootConfigResult?.config ?? {},
32355
+ uiConfigResult?.config ?? {}
32356
+ );
32357
+ const finalConfig = mergeConfig(mergedUserConfig, inlineConfig);
32358
+ try {
32359
+ await build(finalConfig);
32360
+ logger.debug(` Built ${ui.definition.identifier} -> ${uiOutputDir}`);
32361
+ } catch (error) {
32362
+ logger.error(
32363
+ `Failed to build ${ui.definition.identifier}: ${error instanceof Error ? error.message : String(error)}`
32364
+ );
32365
+ throw error;
32366
+ }
32367
+ }
32368
+
32369
+ // cli/client/build-surfaces.ts
32370
+ var SURFACE_SLOTS = [
32371
+ "ui",
32372
+ "session",
32373
+ "setup",
32374
+ "scenario_editor",
32375
+ "waiting_room",
32376
+ "presentation"
32377
+ ];
32378
+ async function buildSurfaces(options) {
32379
+ const config = await loadConfig(join21(options.packagePath, "seriousgaming.sdk.json"));
32380
+ const directory = options.outDir ?? await mkdtemp3(join21(tmpdir3(), "seriousgaming-surfaces-"));
32381
+ const remove = () => rm6(directory, { recursive: true, force: true });
32382
+ try {
32383
+ for (const slot2 of SURFACE_SLOTS) {
32384
+ const surface = config[slot2];
32385
+ if (surface) await bundleUserInterface(surface, options.packagePath, directory, slot2);
32386
+ }
32387
+ } catch (error) {
32388
+ await remove();
32389
+ throw error;
32390
+ }
32391
+ return { directory, remove };
32392
+ }
32111
32393
  export {
32112
32394
  FakeClock,
32395
+ buildSurfaces,
32113
32396
  createStubServices,
32114
32397
  createTestSession,
32115
32398
  startDevServer,