@seriousgaming/sdk-tools 1.5.0 → 1.6.1

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 (169) hide show
  1. package/dist/agent/guidance.md +350 -0
  2. package/dist/bundling/ui-bundler.d.ts +12 -0
  3. package/dist/cli-25RWY5BQ.js +41 -0
  4. package/dist/cli-2BH7FX27.js +52 -0
  5. package/dist/cli-2GZYGRVL.js +36 -0
  6. package/dist/cli-2NU2LPEE.js +97 -0
  7. package/dist/cli-3BRC32CP.js +132 -0
  8. package/dist/cli-3D3ZXWOV.js +111 -0
  9. package/dist/cli-3ZKWV3PN.js +96 -0
  10. package/dist/cli-45OCBG53.js +60 -0
  11. package/dist/cli-4LKXZQ2B.js +48 -0
  12. package/dist/cli-4PXNOJQX.js +81 -0
  13. package/dist/cli-4SIWLHQO.js +717 -0
  14. package/dist/cli-4UWFQNGF.js +54 -0
  15. package/dist/cli-4VFZHLDG.js +202 -0
  16. package/dist/cli-4YB3ROVR.js +78 -0
  17. package/dist/cli-5ACDPCXI.js +21 -0
  18. package/dist/cli-5IAW3LIF.js +38 -0
  19. package/dist/cli-5SM367K7.js +30 -0
  20. package/dist/cli-64AB62PM.js +25 -0
  21. package/dist/cli-6K3VQQUS.js +307 -0
  22. package/dist/cli-6QB2VFPY.js +80 -0
  23. package/dist/cli-6SGCYEEC.js +649 -0
  24. package/dist/cli-6UTPHWRQ.js +207 -0
  25. package/dist/cli-6VNKQ3OX.js +391 -0
  26. package/dist/cli-72XDEFU3.js +61 -0
  27. package/dist/cli-7A6MKCUJ.js +463 -0
  28. package/dist/cli-7XLHO2FE.js +226 -0
  29. package/dist/cli-AV2FYC5G.js +225 -0
  30. package/dist/cli-B6YHEKIJ.js +248 -0
  31. package/dist/cli-BJMS3VX3.js +1837 -0
  32. package/dist/cli-BUQI5UU4.js +43 -0
  33. package/dist/cli-BWX5E7TQ.js +23 -0
  34. package/dist/cli-BYCHKSSH.js +1331 -0
  35. package/dist/cli-C3CMJSNL.js +89 -0
  36. package/dist/cli-C47GJATR.js +42 -0
  37. package/dist/cli-C5QOJJWX.js +46 -0
  38. package/dist/cli-C6ZLPK2U.js +124 -0
  39. package/dist/cli-CD5CIJZI.js +72 -0
  40. package/dist/cli-DDJYUKQG.js +36 -0
  41. package/dist/cli-DFBTZEBX.js +167 -0
  42. package/dist/cli-DOXRQ3S5.js +60 -0
  43. package/dist/cli-EVI36HEM.js +79 -0
  44. package/dist/cli-F2D4GGUA.js +549 -0
  45. package/dist/cli-FQRVFGN6.js +0 -0
  46. package/dist/cli-FWFRKQNE.js +11 -0
  47. package/dist/cli-G6CANSPL.js +88 -0
  48. package/dist/cli-GFNDW2DL.js +124 -0
  49. package/dist/cli-HCRTYQQS.js +16 -0
  50. package/dist/cli-HFX3YPUL.js +76 -0
  51. package/dist/cli-HKORECAG.js +53 -0
  52. package/dist/cli-HOE3WLFH.js +73 -0
  53. package/dist/cli-HSIHDN6K.js +187 -0
  54. package/dist/cli-HW53ICZC.js +89 -0
  55. package/dist/cli-IDVUHGKG.js +218 -0
  56. package/dist/cli-IEMKI7J7.js +1387 -0
  57. package/dist/cli-ILFDANBR.js +101 -0
  58. package/dist/cli-ILKCQNM6.js +8 -0
  59. package/dist/cli-IP4RXGHM.js +2847 -0
  60. package/dist/cli-IUS2YCD3.js +31 -0
  61. package/dist/cli-J4DKUUTK.js +138 -0
  62. package/dist/cli-J4UBELKF.js +37 -0
  63. package/dist/cli-JJSWBW4H.js +89 -0
  64. package/dist/cli-JVI24FI6.js +68 -0
  65. package/dist/cli-JZCLIT3O.js +135 -0
  66. package/dist/cli-JZOZOEZM.js +131 -0
  67. package/dist/cli-KGM6RRQW.js +185 -0
  68. package/dist/cli-KGT5L7VZ.js +13641 -0
  69. package/dist/cli-KOGRWFN7.js +89 -0
  70. package/dist/cli-KSGB2ZLK.js +101 -0
  71. package/dist/cli-L7VYSXQK.js +243 -0
  72. package/dist/cli-LK3V4RI5.js +36 -0
  73. package/dist/cli-LQOHATY2.js +126 -0
  74. package/dist/cli-MJUYJIEP.js +13 -0
  75. package/dist/cli-MJV47HKI.js +143 -0
  76. package/dist/cli-MMN4BPO4.js +145 -0
  77. package/dist/cli-MOPSZ3CS.js +88 -0
  78. package/dist/cli-MU5LB43S.js +136 -0
  79. package/dist/cli-MYJGMA6U.js +40 -0
  80. package/dist/cli-N24OHSAN.js +36 -0
  81. package/dist/cli-N45DREM4.js +99 -0
  82. package/dist/cli-N6H6T2E2.js +616 -0
  83. package/dist/cli-NROTDF5Y.js +182 -0
  84. package/dist/cli-O5ABH2WK.js +226 -0
  85. package/dist/cli-OMWC75CC.js +256 -0
  86. package/dist/cli-OXAUOWCN.js +50 -0
  87. package/dist/cli-PGCIHPU7.js +143 -0
  88. package/dist/cli-Q6ZBZYK2.js +35 -0
  89. package/dist/cli-QUNIRH7A.js +57 -0
  90. package/dist/cli-QUSCIUOM.js +142 -0
  91. package/dist/cli-QVASWX2A.js +187 -0
  92. package/dist/cli-QWQMPCL6.js +253 -0
  93. package/dist/cli-QY5NZAR7.js +97 -0
  94. package/dist/cli-R2MUZQE2.js +62 -0
  95. package/dist/cli-RCIWBCXD.js +36 -0
  96. package/dist/cli-RLEGRWFM.js +81 -0
  97. package/dist/cli-RSW6EBBD.js +89 -0
  98. package/dist/cli-RZITKPJX.js +367 -0
  99. package/dist/cli-S5IVGDDD.js +32 -0
  100. package/dist/cli-SRHBXZCN.js +159 -0
  101. package/dist/cli-TDSQSCX4.js +131 -0
  102. package/dist/cli-TIDQ4WUE.js +257 -0
  103. package/dist/cli-TT36JCU5.js +370 -0
  104. package/dist/cli-TTKICM5P.js +100 -0
  105. package/dist/cli-TTMBBEJC.js +131 -0
  106. package/dist/cli-UMEBPAZQ.js +16 -0
  107. package/dist/cli-UNAJ2OTE.js +15 -0
  108. package/dist/cli-UZZFNXRX.js +226 -0
  109. package/dist/cli-VDBW23SS.js +81 -0
  110. package/dist/cli-VL2P354N.js +46 -0
  111. package/dist/cli-VPRRICZA.js +304 -0
  112. package/dist/cli-VQ6HVQW4.js +4010 -0
  113. package/dist/cli-WR3NOY74.js +36 -0
  114. package/dist/cli-WU43JT4T.js +52 -0
  115. package/dist/cli-XAT25PRU.js +117 -0
  116. package/dist/cli-XOTNXEJA.js +124 -0
  117. package/dist/cli-XSLNH5PR.js +6417 -0
  118. package/dist/cli-XSVGKI3R.js +39 -0
  119. package/dist/cli-XZCJIKIV.js +124 -0
  120. package/dist/cli-Y3DDNMPX.js +97 -0
  121. package/dist/cli-Y3O5F4JN.js +90 -0
  122. package/dist/cli-YOTGR3NB.js +82 -0
  123. package/dist/cli-Z56ZIVA6.js +97 -0
  124. package/dist/cli-ZBN5KAIB.js +59 -0
  125. package/dist/cli-ZDOTXEKL.js +31 -0
  126. package/dist/cli-ZDUADFBY.js +88 -0
  127. package/dist/cli-ZJFQ7EEA.js +131 -0
  128. package/dist/cli-ZTWOE3ZT.js +65 -0
  129. package/dist/cli.js +148 -43093
  130. package/dist/client/build-surfaces.d.ts +33 -0
  131. package/dist/client/dev-server.d.ts +6 -0
  132. package/dist/client/index.d.ts +1 -0
  133. package/dist/client/playwright.d.ts +62 -0
  134. package/dist/client.js +228 -48
  135. package/dist/core/session.d.ts +15 -1
  136. package/dist/dev/console/assets/{index-BVF8exas.js → index-CuMOOH9m.js} +1 -1
  137. package/dist/dev/console/index.html +1 -1
  138. package/dist/dev/shell.d.ts +19 -0
  139. package/dist/dev/surfaces.d.ts +7 -0
  140. package/dist/docs/ai-agents.md +1 -1
  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.md +34 -0
  145. package/dist/docs/cli-and-dev-server.md +21 -0
  146. package/dist/docs/cli-reference.md +45 -31
  147. package/dist/docs/environment-variables.md +6 -0
  148. package/dist/docs/getting-started.md +1 -1
  149. package/dist/docs/guides/designing-a-game.md +29 -4
  150. package/dist/docs/guides/starter-game.md +3 -3
  151. package/dist/docs/guides/testing.md +33 -18
  152. package/dist/docs/guides/upgrading.md +19 -2
  153. package/dist/docs/page-index.md +10 -9
  154. package/dist/docs/recipes/e2e-testing.md +19 -20
  155. package/dist/playwright.js +32232 -0
  156. package/dist/templates/package/CLAUDE.md.template +7 -346
  157. package/dist/templates/package/claude/rules/workflow-create-engine.md +2 -2
  158. package/dist/templates/package/claude/rules/workflow-create-guide.md +2 -2
  159. package/dist/templates/package/claude/rules/workflow-create-user-interface.md +1 -1
  160. package/dist/templates/package/claude/rules/workflow-test-engine-or-ui.md +1 -1
  161. package/dist/templates/package/claude/rules/workflow-update-sdk-version.md +3 -3
  162. package/dist/templates/package/global-setup.ts.template +7 -18
  163. package/dist/templates/package/playwright.config.ts.liquid +8 -11
  164. package/dist/templates/starter-game/playwright.config.ts +8 -11
  165. package/dist/templates/starter-game/testing/e2e/game.spec.ts +1 -1
  166. package/dist/templates/starter-game/testing/e2e/global-setup.ts +7 -18
  167. package/dist/utils/prompt.d.ts +5 -5
  168. package/dist/utils/resource-scan.d.ts +39 -0
  169. package/package.json +7 -3
@@ -93,7 +93,10 @@ export interface ReloadOutcome {
93
93
  kind: 'live' | 'pending' | 'reinitialised' | 'failed';
94
94
  /** What is waiting now, or what a re-initialisation just applied. */
95
95
  pending: PendingChanges;
96
- /** Capabilities adopted live, seeded with their schema defaults. */
96
+ /**
97
+ * Capabilities new to the package. Seeded with their schema defaults,
98
+ * except on `reinitialised`, where `Init` ran for them.
99
+ */
97
100
  added: string[];
98
101
  }
99
102
  export declare class Session {
@@ -136,6 +139,12 @@ export declare class Session {
136
139
  private holdingAtSetup;
137
140
  /** Edits on disk that apply only at the next initialisation (#640). */
138
141
  private pending;
142
+ /**
143
+ * Set when applying {@link pending} threw. The executor has already
144
+ * adopted the package on disk by then, so the next reload finds nothing
145
+ * changed and would otherwise drop the edit `Init` never ran on.
146
+ */
147
+ private pendingInitFailed;
139
148
  /** The scenario editor's drafts, which belong to no session (§6.5). */
140
149
  private readonly drafts;
141
150
  /** What the parts below are handed of the session. */
@@ -254,6 +263,11 @@ export declare class Session {
254
263
  * last good configuration stays in force.
255
264
  */
256
265
  reloadBundles(): Promise<ReloadOutcome>;
266
+ /**
267
+ * Give every board the capabilities a reload added, now rather than at
268
+ * its next write, so a read sees them straight away.
269
+ */
270
+ private seedAdded;
257
271
  /**
258
272
  * Whether anything has been played: a tick committed and not since
259
273
  * rewound. A session at its configuration step has played nothing.
@@ -201,4 +201,4 @@ Error generating stack: `+e.message+`
201
201
  `});++r<e.length;)r&&n.push({type:`text`,value:`
202
202
  `}),n.push(e[r]);return t&&e.length>0&&n.push({type:`text`,value:`
203
203
  `}),n}function zM(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function BM(e,t){let n=PM(e,t),r=n.one(e,void 0),i=jM(n),a=Array.isArray(r)?{type:`root`,children:r}:r||{type:`root`,children:[]};return i&&(`children`in a,a.children.push({type:`text`,value:`
204
- `},i)),a}function VM(e,t){return e&&`run`in e?async function(n,r){let i=BM(n,{file:r,...t});await e.run(i,r)}:function(n,r){return BM(n,{file:r,...e||t})}}var HM=[],UM={allowDangerousHtml:!0},WM=/^(https?|ircs?|mailto|xmpp)$/i,GM=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`className`,id:`remove-classname`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function KM(e){let t=qM(e),n=JM(e);return YM(t.runSync(t.parse(n),n),e)}function qM(e){let t=e.rehypePlugins||HM,n=e.remarkPlugins||HM,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...UM}:UM;return _k().use(HO).use(n).use(VM,r).use(t)}function JM(e){let t=e.children||``,n=new lk;return typeof t==`string`?n.value=t:``+t,n}function YM(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||XM;for(let e of GM)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return hw(e,l),mj(e,{Fragment:V.Fragment,components:i,ignoreInvalidStyle:!0,jsx:V.jsx,jsxs:V.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in Ij)if(Object.hasOwn(Ij,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=Ij[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function XM(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||WM.test(e.slice(0,t))?e:``}var ZM={note:{label:`Note`,palette:`info`,icon:(0,V.jsx)(iA,{fontSize:`small`})},warning:{label:`Warning`,palette:`warning`,icon:(0,V.jsx)(lA,{fontSize:`small`})},tip:{label:`Tip`,palette:`success`,icon:(0,V.jsx)(aA,{fontSize:`small`})},say:{label:`Say`,palette:`primary`,icon:(0,V.jsx)(oA,{fontSize:`small`})},do:{label:`Do`,palette:`secondary`,icon:(0,V.jsx)(sA,{fontSize:`small`})},timing:{label:`Timing`,palette:`info`,icon:(0,V.jsx)(cA,{fontSize:`small`})}};function QM({type:e,children:t}){let n=ZM[e];return(0,V.jsxs)(am,{sx:e=>({my:2,px:2,py:1.5,borderLeft:3,borderColor:`${n.palette}.main`,borderRadius:1,bgcolor:gi(e.palette[n.palette].main,.08),"& p:first-of-type":{mt:0},"& p:last-of-type":{mb:0}}),"data-testid":`guide-admonition-${e}`,children:[(0,V.jsxs)(Z,{variant:`overline`,component:`p`,sx:{display:`flex`,alignItems:`center`,gap:.75,fontWeight:600,lineHeight:1.5,mb:.5,color:`${n.palette}.main`},children:[n.icon,n.label]}),t]})}function $M(e){return`/api/guide/assets/${e.split(`/`).map(encodeURIComponent).join(`/`)}`}function eN({body:e,locale:t}){let n=nA(e);return n.ok?n.kind===`file`?(0,V.jsxs)(am,{component:`figure`,sx:{my:2,mx:0,maxWidth:720},"data-testid":`guide-video-file`,children:[(0,V.jsxs)(am,{component:`video`,controls:!0,preload:`metadata`,playsInline:!0,src:$M(n.src),poster:n.poster?$M(n.poster):void 0,"aria-label":n.title,sx:{display:`block`,width:`100%`,"@media print":{display:`none`}},children:[n.captions&&(0,V.jsx)(`track`,{kind:`captions`,src:$M(n.captions),srcLang:t,label:t,default:!0}),n.title]}),(0,V.jsxs)(am,{sx:{display:`none`,"@media print":{display:`block`}},children:[n.poster&&(0,V.jsx)(am,{component:`img`,src:$M(n.poster),alt:``,sx:{display:`block`,maxWidth:`100%`}}),n.title&&(0,V.jsx)(Z,{component:`figcaption`,variant:`body2`,children:n.title})]})]}):(0,V.jsx)(am,{sx:{my:2,position:`relative`,aspectRatio:`16 / 9`,maxWidth:720},"data-testid":`guide-video-embed`,children:(0,V.jsx)(am,{component:`iframe`,src:n.embedUrl,title:`${n.provider} video`,sandbox:`allow-scripts allow-same-origin allow-presentation`,allow:`encrypted-media; fullscreen; picture-in-picture`,referrerPolicy:`strict-origin-when-cross-origin`,sx:{position:`absolute`,inset:0,width:`100%`,height:`100%`,border:0}})}):(0,V.jsxs)(xd,{severity:`error`,sx:{my:2},"data-testid":`guide-video-error`,children:[`Video block error: `,n.error]})}function tN(e){return e.children.map(e=>e.type===`text`?e.value:e.type===`element`?tN(e):``).join(``)}function nN({markdown:e,chapterFile:t,locale:n,settings:r}){return(0,V.jsx)(KM,{remarkPlugins:[$D,nC,[Bk,{settings:r,locale:n}],kk,Ak,[Kk,{chapterFile:t}]],urlTransform:e=>{let r=XM(e);if(!r)return;if(/^[a-z][a-z0-9+.-]*:/i.test(r)||r.startsWith(`//`)||r.startsWith(`#`)||r.startsWith(`/`))return r;let i=new URL(`/api/guide/content/${n}/${t}`,window.location.origin),a=new URL(r,i);if(a.origin===window.location.origin&&a.pathname.startsWith(`/api/guide/`))return a.pathname+a.search},components:{pre({node:e,children:t,...r}){let i=e?.children[0];return i&&i.type===`element`&&i.tagName===`code`&&Array.isArray(i.properties?.className)&&i.properties.className.includes(`language-video`)?(0,V.jsx)(eN,{body:tN(i),locale:n}):(0,V.jsx)(`pre`,{...r,children:t})},span(e){let{node:t,children:n,...r}=e;return typeof r[`data-guide-error`]==`string`?(0,V.jsx)(am,{component:`span`,"data-testid":`guide-setting-error`,sx:{color:`error.main`,fontStyle:`italic`},children:n}):(0,V.jsx)(`span`,{...r,children:n})},div(e){let{node:t,children:n,...r}=e,i=r;if(typeof i[`data-guide-error`]==`string`)return(0,V.jsx)(xd,{severity:`error`,sx:{my:2},"data-testid":`guide-setting-error`,children:n});let a=i[`data-admonition`];if(typeof a==`string`&&Ok(a))return(0,V.jsx)(QM,{type:a,children:n});let o=i[`data-admonition-unknown`];return typeof o==`string`?(0,V.jsxs)(xd,{severity:`error`,sx:{my:2},"data-testid":`guide-admonition-unknown`,children:[`Unknown admonition type ":::`,o,`"`]}):(0,V.jsx)(`div`,{...e})},a({node:e,children:t,href:n,...r}){let i=typeof n==`string`&&/^https?:\/\//.test(n);return(0,V.jsx)(`a`,{href:n,...r,...i?{target:`_blank`,rel:`noreferrer noopener`}:{},children:t})}},children:e})}function rN(e){let t=e.replace(/\.md$/,``).replace(/^\d+[-_. ]*/,``).replace(/[-_]+/g,` `).trim();return t.charAt(0).toUpperCase()+t.slice(1)}function iN({locale:e,reloads:t}){let n=new URLSearchParams(window.location.search),[r,i]=(0,E.useState)(void 0),[a,o]=(0,E.useState)(n.get(`locale`)??e),[s,c]=(0,E.useState)(n.get(`chapter`)),[l,u]=(0,E.useState)(``);(0,E.useEffect)(()=>{fetch(`/api/guide`).then(e=>e.json()).then(e=>i(e.guide))},[t]);let d=(0,E.useMemo)(()=>Object.keys(r?.locales??{}),[r]),f=(0,E.useMemo)(()=>r?nx(r.locales,r.chapters,a):[],[r,a]),p=(0,E.useMemo)(()=>f.map(e=>e.file),[f]),m=f.find(e=>e.file===s)?.locale??a;(0,E.useEffect)(()=>{if(r){if(p.length===0)return c(null);s&&p.includes(s)||c(p[0])}},[r,p,s]),(0,E.useEffect)(()=>{if(!r||!s)return u(``);let e=!0;return fetch(`/api/guide/content/${encodeURIComponent(m)}/${encodeURIComponent(s)}`).then(e=>e.ok?e.text():`This chapter could not be read.`).then(t=>{e&&u(t)}),()=>{e=!1}},[r,m,s,t]);let h=(0,E.useMemo)(()=>s&&l&&r?qk(s,l,{settings:r.settings,locale:m}):[],[s,l,r,m]);return r===void 0?(0,V.jsx)(uy,{sx:{alignItems:`center`,justifyContent:`center`,height:`100%`},children:(0,V.jsx)(rd,{size:28})}):r===null?(0,V.jsx)(uy,{sx:{alignItems:`center`,justifyContent:`center`,height:`100%`,p:4},children:(0,V.jsx)(Z,{color:`text.secondary`,children:`This package declares no facilitator guide, or none of its chapters applies to this session.`})}):(0,V.jsxs)(uy,{direction:`row`,sx:{height:`100%`},children:[(0,V.jsxs)(am,{sx:{width:280,borderRight:1,borderColor:`divider`,overflow:`auto`,"@media print":{display:`none`}},children:[d.length>1&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(am,{sx:{p:2},children:(0,V.jsx)(Bv,{size:`small`,fullWidth:!0,value:d.includes(a)?a:d[0]??``,onChange:e=>o(e.target.value),children:d.map(e=>(0,V.jsx)($_,{value:e,children:r.locales[e]?.name??e},e))})}),(0,V.jsx)(Nh,{})]}),(0,V.jsxs)(Rg,{dense:!0,children:[p.map(e=>(0,V.jsx)(Hg,{selected:e===s,onClick:()=>c(e),children:(0,V.jsx)(Jg,{primary:rN(e)})},e)),p.length===0&&(0,V.jsx)(am,{sx:{px:2,py:1},children:(0,V.jsx)(Z,{variant:`body2`,color:`text.secondary`,children:`This guide has no chapters yet.`})})]}),h.some(e=>e.depth>1)&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Nh,{}),(0,V.jsx)(Z,{variant:`overline`,color:`text.secondary`,sx:{display:`block`,px:2,pt:1.5},children:`On this page`}),(0,V.jsx)(Rg,{dense:!0,disablePadding:!0,sx:{pb:2},children:h.filter(e=>e.depth>1).map(e=>(0,V.jsx)(Hg,{dense:!0,sx:{pl:2+(e.depth-2)*1.5,py:.25},onClick:()=>document.getElementById(e.id)?.scrollIntoView({block:`start`}),children:(0,V.jsx)(Jg,{primary:e.text,slotProps:{primary:{variant:`body2`,color:`text.secondary`}}})},e.id))})]})]}),(0,V.jsx)(am,{sx:{flex:1,minWidth:0,overflow:`auto`},children:(0,V.jsxs)(am,{"data-testid":`guide-content`,sx:{maxWidth:780,mx:`auto`,px:4,py:3,"& img":{maxWidth:`100%`},"& pre":{p:2,borderRadius:1,overflow:`auto`,bgcolor:`action.hover`},"& table":{borderCollapse:`collapse`,width:`100%`},"& th, & td":{border:1,borderColor:`divider`,px:1,py:.5},"& h1, & h2, & h3":{scrollMarginTop:16},"@media print":{maxWidth:`none`,px:0,py:0}},children:[s&&m!==a&&(0,V.jsxs)(xd,{severity:`info`,"data-testid":`guide-untranslated`,sx:{mb:2,"@media print":{display:`none`}},children:[`This chapter is not yet translated into`,` `,r.locales[a]?.name??a,`, so it is shown in`,` `,r.locales[m]?.name??m,`.`]}),s&&(0,V.jsx)(nN,{markdown:l,chapterFile:s,locale:m,settings:r.settings})]})})]})}function aN({team:e,bare:t}){return e?e.participants.length===0?(0,V.jsxs)(oN,{children:[(0,V.jsxs)(uy,{spacing:1,sx:{alignItems:`center`,maxWidth:420},children:[(0,V.jsx)(Z,{variant:`overline`,color:`text.secondary`,children:e.name}),(0,V.jsx)(Z,{variant:`h5`,children:`Nobody is on this team yet`}),(0,V.jsxs)(Z,{color:`text.secondary`,sx:{textAlign:`center`},children:[`Add a participant from the dev drawer, or with`,` `,(0,V.jsxs)(`code`,{children:[`sdk participant add --team `,e.index+1]}),`, and they will be listed here.`]})]}),(0,V.jsx)(_m,{size:`small`,href:Wc({kind:`observer`,teamIndex:e.index,bare:t}),children:`Watch without joining`})]}):(0,V.jsxs)(oN,{children:[(0,V.jsxs)(uy,{spacing:1,sx:{alignItems:`center`},children:[(0,V.jsx)(Z,{variant:`overline`,color:`text.secondary`,children:e.name}),(0,V.jsx)(Z,{variant:`h5`,children:`Who are you?`})]}),(0,V.jsx)(uy,{spacing:1.5,sx:{width:`100%`,maxWidth:420},children:e.participants.map((n,r)=>(0,V.jsx)(xm,{variant:`outlined`,"data-testid":`join-participant`,children:(0,V.jsxs)(Dm,{href:Wc({kind:`player`,teamIndex:e.index,participant:r+1,bare:t}),sx:{p:2},children:[(0,V.jsx)(Z,{variant:`subtitle1`,children:n.name}),(0,V.jsxs)(Z,{variant:`body2`,color:`text.secondary`,children:[`Participant `,r+1]})]})},n.id))}),(0,V.jsx)(_m,{size:`small`,href:Wc({kind:`observer`,teamIndex:e.index,bare:t}),children:`Watch without joining`})]}):(0,V.jsxs)(oN,{children:[(0,V.jsx)(Z,{color:`text.secondary`,children:`This session has no such team. It may have been removed.`}),(0,V.jsx)(_m,{href:`/`,children:`Back to the session`})]})}function oN({children:e}){return(0,V.jsx)(uy,{spacing:3,sx:{alignItems:`center`,justifyContent:`center`,height:`100%`,p:4,bgcolor:`background.default`},children:(0,V.jsx)(am,{sx:{display:`contents`},children:e})})}function sN({state:e}){let t=new URLSearchParams(window.location.search).get(`team`),n=t?e.teams.filter(e=>e.teamId===t):e.teams;return(0,E.useEffect)(()=>{let t=document.title;return document.title=`${e.game.name} — team sheets`,()=>{document.title=t}},[e.game.name]),(0,V.jsxs)(am,{"data-testid":`print-sheets`,sx:{height:`100%`,overflow:`auto`,bgcolor:`background.default`,"@media print":{height:`auto`,overflow:`visible`}},children:[(0,V.jsxs)(uy,{direction:`row`,spacing:2,sx:{alignItems:`center`,p:2,"@media print":{display:`none`}},children:[(0,V.jsx)(Z,{variant:`h6`,sx:{flex:1},children:`Team sheets`}),(0,V.jsx)(_m,{variant:`contained`,onClick:()=>window.print(),children:`Print`})]}),n.map(t=>(0,V.jsxs)(am,{sx:{m:2,p:4,bgcolor:`background.paper`,border:1,borderColor:`divider`,borderRadius:1,"@media print":{breakAfter:`page`,breakInside:`avoid`,border:0,m:0}},children:[(0,V.jsx)(Z,{variant:`overline`,color:`text.secondary`,children:e.game.name}),(0,V.jsx)(Z,{variant:`h3`,gutterBottom:!0,children:t.name}),(0,V.jsx)(Nh,{sx:{my:2}}),(0,V.jsx)(Z,{variant:`subtitle2`,gutterBottom:!0,children:`Open your screen at`}),(0,V.jsx)(Z,{sx:{fontFamily:`monospace`,fontSize:18,mb:3,wordBreak:`break-all`},children:`${window.location.origin}${Wc({kind:`player`,teamIndex:t.index,participant:1})}`}),(0,V.jsx)(Z,{variant:`subtitle2`,gutterBottom:!0,children:`On this team`}),(0,V.jsxs)(uy,{spacing:.5,children:[t.participants.map((e,n)=>(0,V.jsxs)(Z,{children:[n+1,`. `,e.name,(0,V.jsx)(Z,{component:`span`,variant:`caption`,color:`text.secondary`,sx:{ml:1,fontFamily:`monospace`},children:Wc({kind:`player`,teamIndex:t.index,participant:n+1})})]},e.id)),t.participants.length===0&&(0,V.jsx)(Z,{color:`text.secondary`,children:`Nobody yet.`})]})]},t.teamId))]})}var cN={game:new Set([`updateData`,`requestTick`,`renameOwnTeam`,`renameSelf`]),"waiting-room":new Set([`updateData`,`requestTick`,`renameOwnTeam`,`renameSelf`]),session:new Set([`updateSessionData`,`updateSharedData`,`requestTick`,`undoTick`,`resetGame`,`resetWalkthrough`,`setWaitingRoom`,`setLocale`,`createTeam`,`renameTeam`,`renameParticipant`,`moveParticipant`,`deleteTeam`,`pauseTimer`,`resumeTimer`,`extendTick`]),setup:new Set([`updateSettings`,`requestPlay`]),"scenario-editor":new Set([`updateSettings`]),presentation:new Set},lN={setWaitingRoom:`The waiting room is session-wide, so setWaitingRoom takes no teamId`,renameOwnTeam:`renameOwnTeam renames the caller's own team, which the host resolves; it takes no teamId`,resetWalkthrough:`A walkthrough holds one team, so resetWalkthrough takes no teamId`,setLocale:`The locale is the session's, so setLocale takes no teamId`,renameSelf:`renameSelf renames the caller, whom the host resolves; it takes no teamId`},uN={game:new Set([`callEndpoint`,`getPastState`,`getAllTeamsParticipants`]),"waiting-room":new Set([`callEndpoint`,`getPastState`,`getAllTeamsParticipants`]),session:new Set([`callEndpoint`,`getPastState`]),setup:new Set([`callEndpoint`]),"scenario-editor":new Set([`callEndpoint`]),presentation:new Set([`getPastState`])};function dN(e){return e.teamIndex===void 0?{}:{teamIndex:e.teamIndex}}function fN(e){return e.participantId===void 0?{}:{participantId:e.participantId,teamId:`team-${(e.teamIndex??0)+1}`}}function pN(e){return e.role===void 0?{}:{viewerRole:e.role}}function mN(e){return{...dN(e),...fN(e),...pN(e)}}function hN(e){let t=typeof e==`string`?/^team-([1-9]\d*)$/.exec(e):null;return t?Number(t[1])-1:-1}function gN(e,t){return e.teamId===void 0?t:{teamIndex:hN(e.teamId)}}function _N(e){return typeof e==`object`&&!!e&&`refused`in e}function vN(e,t,n){if(!cN[t.kind].has(e.type))return null;if(e.teamId!==void 0&&e.type in lN)return{refused:lN[e.type]};if(e.type===`renameSelf`&&e.participantId!==void 0)return{refused:`renameSelf renames the caller, whom the host resolves; it takes no participantId`};let r=dN(n),i=fN(n),a=pN(n);switch(e.type){case`updateData`:return{type:`updateContext`,uiIdentifier:t.identifier,payload:e.payload,...e.deletes?{deletes:e.deletes}:{},...r,...i,...a};case`updateSessionData`:return{type:`updateContext`,payload:e.payload,teamIndex:hN(e.teamId),sessionUiIdentifier:t.identifier,...e.deletes?{deletes:e.deletes}:{}};case`updateSharedData`:return{type:`updateSharedContext`,uiIdentifier:t.identifier,payload:e.payload,...e.deletes?{deletes:e.deletes}:{}};case`updateSettings`:return t.kind===`scenario-editor`?{type:`updateScenarioDraft`,scenarioId:n.scenario??null,payload:e.payload,uiIdentifier:t.identifier}:{type:`updateSettings`,payload:e.payload,uiIdentifier:t.identifier};case`requestTick`:return{type:`tick`,...gN(e,r),...t.kind===`session`?{}:{...i,...a}};case`undoTick`:return{type:`undo`,...gN(e,r)};case`resetGame`:return{type:`reset`,...gN(e,{})};case`setWaitingRoom`:return{type:`setWaitingRoom`,open:e.open===!0};case`setLocale`:return{type:`setLocale`,locale:String(e.locale)};case`resetWalkthrough`:return{type:`resetWalkthrough`};case`createTeam`:return{type:`addTeam`,...typeof e.name==`string`?{name:e.name}:{}};case`renameTeam`:return{type:`renameTeam`,teamId:String(e.teamId),name:String(e.name)};case`renameOwnTeam`:return{type:`renameOwnTeam`,name:String(e.name),...i};case`renameSelf`:return{type:`renameSelf`,name:String(e.name),...i};case`renameParticipant`:return{type:`renameParticipant`,participantId:String(e.participantId),name:String(e.name)};case`moveParticipant`:return{type:`moveParticipant`,participantId:String(e.participantId),teamId:String(e.teamId)};case`deleteTeam`:return{type:`removeTeam`,teamIndex:hN(e.teamId)};case`requestPlay`:return{type:`play`};case`pauseTimer`:return{type:`pauseTimer`,...gN(e,r)};case`resumeTimer`:return{type:`resumeTimer`,...gN(e,r)};case`extendTick`:return{type:`extendTick`,byMs:Number(e.byMs??0),...gN(e,r)};default:return null}}function yN(e,t,n){if(!uN[t.kind].has(e.type))return null;switch(e.type){case`callEndpoint`:return{type:`callEndpoint`,endpointIdentifier:String(e.endpointIdentifier),request:e.request,uiIdentifier:t.identifier,...mN(n),...t.kind===`scenario-editor`?{scenarioId:n.scenario??null}:{}};case`getPastState`:return{type:`getPastState`,query:e.query,uiIdentifier:t.identifier,...n.teamIndex===void 0?{}:{teamId:`team-${n.teamIndex+1}`}};case`getAllTeamsParticipants`:return{type:`getAllTeamsParticipants`,uiIdentifier:t.identifier};default:return null}}var bN={game:{required:[`stateChanged`,`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`,`setParticipant`],alsoSent:[`setTimer`,`setViewerRole`,`setOwnTeam`,`setOwnTeamJoinLink`,`setParticipantList`,`setTeamList`,`setRunKind`,`setScenarioName`,`setRoundProcessing`,`setCrossTeamData`,`themePreferenceChanged`],isPlayerSurface:!0},"waiting-room":{required:[`stateChanged`,`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`,`setParticipant`],alsoSent:[`setTimer`,`setViewerRole`,`setOwnTeam`,`setOwnTeamJoinLink`,`setParticipantList`,`setTeamList`,`setRunKind`,`setScenarioName`,`setCrossTeamData`,`themePreferenceChanged`],isPlayerSurface:!0},session:{required:[`setSessionMeta`,`setSessionData`,`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`,`setTeamConfiguration`],alsoSent:[`setTeamList`,`setParticipantList`,`setTeamLinks`,`setAvailableOverlays`,`setRunKind`,`setScenarioName`,`setWalkthroughLink`,`themePreferenceChanged`],isPlayerSurface:!1},presentation:{required:[`setPresentation`,`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`],alsoSent:[`themePreferenceChanged`],isPlayerSurface:!1},setup:{required:[`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`],alsoSent:[`themePreferenceChanged`],isPlayerSurface:!1},"scenario-editor":{required:[`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`],alsoSent:[`themePreferenceChanged`],isPlayerSurface:!1}};function xN(e,t={}){let{required:n,isPlayerSurface:r}=bN[e];return!t.observer||!r?n:n.filter(e=>e!==`setParticipant`)}var SN=new Set([`callEndpoint`,`uploadBlob`,`getPastState`,`getAllTeamsParticipants`]),CN=class{options;host;logger;port=null;readyListener=null;loadListener=null;handshakeTimer=null;disposed=!1;lastSent=new Map;sticky=new Map;outbound=[];pending=new Map;requestCounter=0;constructor(e){this.options=e,this.host=e.window??globalThis.window,this.logger=e.logger??console,this.listenForReady()}get connected(){return this.port!==null}send(e){this.disposed||(this.lastSent.set(e.type,wN(e)),this.port?this.port.postMessage(e):this.outbound.push(e))}sendState(e){this.disposed||(this.sticky.set(e.type,e),this.lastSent.set(e.type,wN(e)),this.port?.postMessage(e))}sendIfChanged(e){return this.disposed||this.lastSent.get(e.type)===wN(e)?!1:(this.sendState(e),!0)}sendInitialBatch(e){let t=xN(this.options.surface,{observer:this.options.observer}),n=new Set(e.map(e=>e.type)),r=t.filter(e=>!n.has(e));if(r.length>0)throw Error(`Initial batch for a "${this.options.surface}" surface is missing ${r.join(`, `)}. The guest blocks its first paint on ${t.join(`, `)}.`);for(let t of e)this.sendState(t)}request(e,t=3e4){let n=`host-${++this.requestCounter}`;return new Promise((r,i)=>{let a=setTimeout(()=>{this.pending.delete(n),i(Error(`Guest did not answer "${e.type}" in ${t}ms`))},t);this.pending.set(n,{resolve:()=>{clearTimeout(a),r()},reject:e=>{clearTimeout(a),i(e)}}),this.send({...e,requestId:n})})}dispose(){this.disposed||(this.disposed=!0,this.clearHandshakeTimer(),this.readyListener&&=(this.host.removeEventListener(`message`,this.readyListener),null),this.loadListener&&=(this.options.iframe.removeEventListener?.(`load`,this.loadListener),null),this.closePort(),this.rejectPending(`Channel disposed`),this.options.onTeardown?.(`disposed`))}listenForReady(){let e=e=>{if(this.disposed)return;let t=e.data;if(!t||t.type!==`ready`||e.source!==this.options.iframe.contentWindow)return;if(e.origin!==this.options.iframeOrigin){this.logger.warn(`[${this.options.uiIdentifier}] ignoring a handshake from ${e.origin}; this frame is pinned to ${this.options.iframeOrigin}`);return}let n=t.protocolVersion;typeof n==`number`&&n!==4&&this.logger.warn(`[${this.options.uiIdentifier}] host↔iframe protocol version mismatch: iframe ${n}, host 4`),this.connect(t.signalsRendered===!0)};this.readyListener=e,this.host.addEventListener(`message`,e),this.armHandshakeTimer(),this.listenForLoads()}listenForLoads(){let{iframe:e}=this.options;if(!e.addEventListener)return;let t=()=>{this.disposed||(this.armHandshakeTimer(),this.port?.postMessage({type:`ping`}))};this.loadListener=t,e.addEventListener(`load`,t)}armHandshakeTimer(){this.clearHandshakeTimer();let e=this.options.handshakeTimeoutMs??1e4;this.handshakeTimer=setTimeout(()=>{this.handshakeTimer=null,!this.disposed&&(this.closePort(),this.options.onTeardown?.(`handshake-timeout`))},e)}connect(e){this.closePort(),this.rejectPending(`Connection reset`),this.lastSent.clear();let t=[...this.sticky.values()],n=new MessageChannel;this.port=n.port1,this.port.onmessage=e=>this.receive(e.data),this.port.start(),this.clearHandshakeTimer(),this.options.iframe.contentWindow?.postMessage({type:`init`,protocolVersion:4,sessionKey:this.options.sessionKey},this.options.iframeOrigin,[n.port2]);for(let e of t)this.sendState(e);let r=this.outbound;this.outbound=[];for(let e of r)this.port.postMessage(e);this.options.onConnect?.({signalsRendered:e})}closePort(){this.port&&=(this.port.onmessage=null,this.port.close(),null)}clearHandshakeTimer(){this.handshakeTimer!==null&&(clearTimeout(this.handshakeTimer),this.handshakeTimer=null)}rejectPending(e){for(let{reject:t}of this.pending.values())t(Error(e));this.pending.clear()}receive(e){if(e&&typeof e.type==`string`){switch(e.type){case`pong`:this.clearHandshakeTimer();return;case`rendered`:this.options.onRendered?.();return;case`refreshAssetAuth:response`:{let{requestId:t,ok:n,error:r}=e;if(typeof t!=`string`)return;let i=this.pending.get(t);this.pending.delete(t),n?i?.resolve():i?.reject(Error(r??`Asset auth refresh failed`));return}}SN.has(e.type)?this.answer(e):this.options.onMessage?.(e)}}async answer(e){let t=e.requestId;if(typeof t!=`string`){this.logger.warn(`[${this.options.uiIdentifier}] dropped a "${e.type}" with no requestId`);return}let n=`${e.type}:response`;try{let r=await this.dispatch(e);this.send({type:n,requestId:t,ok:!0,...r})}catch(r){this.send(e.type===`callEndpoint`?{type:n,requestId:t,ok:!1,...TN(r)}:{type:n,requestId:t,ok:!1,error:r instanceof Error?r.message:String(r)})}}async dispatch(e){let t=this.options.adapter,n={uiIdentifier:this.options.uiIdentifier,...this.options.origin};switch(e.type){case`callEndpoint`:if(!t?.callEndpoint)throw Error(`This host serves no endpoints`);return{response:await t.callEndpoint({endpointIdentifier:String(e.endpointIdentifier),request:e.request},n)};case`uploadBlob`:if(!t?.uploadBlob)throw Error(`This host stores no blobs`);return{reference:await t.uploadBlob({data:e.data,name:String(e.name),mimeType:String(e.mimeType)},n)};case`getPastState`:if(!t?.getPastState)throw Error(`This host serves no past state`);return{entries:await t.getPastState(e.query,n)};case`getAllTeamsParticipants`:return{participants:await t?.getAllTeamsParticipants?.(n)??[]};default:throw Error(`Unroutable request "${e.type}"`)}}};function wN(e){return typeof e!=`object`||!e?JSON.stringify(e)??`undefined`:Array.isArray(e)?`[${e.map(wN).join(`,`)}]`:`{${Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e<t?-1:+(e>t)).map(([e,t])=>`${JSON.stringify(e)}:${wN(t)}`).join(`,`)}}`}function TN(e){let t=typeof e==`object`&&e?e.failure:void 0;return typeof t==`object`&&t&&typeof t.outcome?.kind==`string`&&Array.isArray(t.applied)?t:{outcome:{kind:`error`,message:e instanceof Error?e.message:String(e)},applied:[]}}var EN=[`primary`,`secondary`,`success`,`error`,`warning`,`info`];function DN(e){let t=e.trim().toLowerCase(),n=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.exec(t);if(n){let e=n[1];e.length<=4&&(e=[...e].map(e=>e+e).join(``));let t=t=>parseInt(e.slice(t,t+2),16);return{r:t(0),g:t(2),b:t(4),a:e.length===8?t(6)/255:1}}let r=/^rgba?\(([^)]*)\)$/.exec(t);if(r){let e=r[1].split(/[\s,/]+/).filter(Boolean);if(e.length!==3&&e.length!==4)return null;let[t,n,i]=e.slice(0,3).map(e=>e.endsWith(`%`)?parseFloat(e)/100*255:parseFloat(e)),a=e[3],o=a===void 0?1:a.endsWith(`%`)?parseFloat(a)/100:parseFloat(a);return[t,n,i,o].some(e=>!Number.isFinite(e))?null:{r:ON(t,255),g:ON(n,255),b:ON(i,255),a:ON(o,1)}}return null}function ON(e,t){return Math.min(t,Math.max(0,e))}function kN(e,t){let n=(t,n)=>t*e.a+n*(1-e.a);return{r:n(e.r,t.r),g:n(e.g,t.g),b:n(e.b,t.b),a:1}}function AN({r:e,g:t,b:n}){let r=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return .2126*r(e)+.7152*r(t)+.0722*r(n)}function jN(e,t){let[n,r]=[AN(e),AN(t)].sort((e,t)=>t-e);return(n+.05)/(r+.05)}function MN({r:e,g:t,b:n}){let r=e=>Math.round(e).toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}var NN={r:0,g:0,b:0,a:1},PN={r:255,g:255,b:255,a:1};function FN(e,t){let n=DN(e);if(!n)return MN(NN);let r=n.a<1?kN(n,PN):n,i=t===void 0?null:DN(t);if(i){let e=kN(i,r);if(jN(e,r)>=4.5)return MN(e)}return jN(NN,r)>=jN(PN,r)?MN(NN):MN(PN)}var IN={light:{background:`#ffffff`,surface:`#ffffff`,text:`#000000`},dark:{background:`#121212`,surface:`#1e1e1e`,text:`#ffffff`}};function LN(e){let{background:t,surface:n,text:r}=e;if(!t||!n)return;let i=DN(t),a=DN(n);if(!i||!a)return;let o=e=>e.a<1?kN(e,PN):e,s=[o(i),o(a)],c=e=>Math.min(...s.map(t=>jN(kN(e,t),t))),l=r===void 0?null:DN(r);if(l&&l.a===1&&c(l)>=4.5)return{background:t,surface:n,text:MN(l)};let u=c(NN)>=c(PN)?NN:PN;if(!(c(u)<4.5))return{background:t,surface:n,text:MN(u)}}function RN(e,t){let n=Object.fromEntries(EN.map(t=>[t,FN(e[t],e.contrastText?.[t])]));return{...Object.fromEntries(EN.map(t=>[t,e[t]])),contrastText:n,...LN(e)??IN[t]}}function zN(e){return{mode:e.mode,light:RN(e.light,`light`),dark:RN(e.dark,`dark`),brand:e.brand}}var BN={primary:{main:`#6B00FF`,contrastText:`#ffffff`},secondary:{main:`#17D1C7`,contrastText:`rgba(0,0,0,0.87)`},error:{main:`#DB324D`,contrastText:`#ffffff`},success:{main:`#00c894`,contrastText:`rgba(0,0,0,0.87)`},warning:{main:`#ffb65c`,contrastText:`rgba(0,0,0,0.87)`},info:{main:`#336BEB`,contrastText:`#ffffff`}},VN={primary:{main:`#BC8CFF`,contrastText:`rgba(0,0,0,0.87)`},secondary:{main:`#17D1C7`,contrastText:`rgba(0,0,0,0.87)`},error:{main:`#ef7a8e`,contrastText:`rgba(0,0,0,0.87)`},success:{main:`#00c894`,contrastText:`rgba(0,0,0,0.87)`},warning:{main:`#ffb65c`,contrastText:`rgba(0,0,0,0.87)`},info:{main:`#7d9bf2`,contrastText:`rgba(0,0,0,0.87)`}},HN=`#414042`,UN=`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif`,WN=`"Work Sans", ${UN}`,GN=`Sora, ${UN}`;function KN(e){return{primary:e.primary.main,secondary:e.secondary.main,success:e.success.main,error:e.error.main,warning:e.warning.main,info:e.info.main,contrastText:{primary:e.primary.contrastText,secondary:e.secondary.contrastText,success:e.success.contrastText,error:e.error.contrastText,warning:e.warning.contrastText,info:e.info.contrastText}}}function qN(e,t){return zN(t?{mode:e,...t.theme}:{mode:e,light:KN(BN),dark:KN(VN),brand:{name:`Serious Gaming`}})}var JN=[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`];function YN(e){return Xo({palette:e===`dark`?{mode:`dark`,...VN}:{mode:`light`,...BN,text:{primary:HN}},typography:{fontFamily:WN,...Object.fromEntries(JN.map(e=>[e,{fontFamily:GN}]))},components:{MuiButton:{styleOverrides:{root:{textTransform:`none`}}}}})}function XN(e){return e===`system`?window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:e}function ZN(e,t){return{"Content-Type":e.mimeType,"X-Blob-Name":encodeURIComponent(e.name),"X-Blob-Mime":e.mimeType,"X-Blob-Retention":t===`setup`?`settings`:t===`scenario-editor`?`scenario`:`game`}}var QN=5e3,$N=[`allow-scripts`,`allow-same-origin`,`allow-forms`,`allow-downloads`,`allow-modals`,`allow-presentation`,`allow-popups`,`allow-popups-to-escape-sandbox`].join(` `),eP=[`clipboard-write`,`autoplay`,`screen-wake-lock`,`fullscreen`,`microphone`,`camera`,`geolocation`,`picture-in-picture`,`web-share`,`gamepad`,`window-management`,`speaker-selection`].join(`; `);function tP(e){return Object.assign(Error(e.outcome.message??e.outcome.kind),{failure:e})}function nP(e,t,n){return async r=>{let i=yN(r,e,t)??vN(r,e,t);return _N(i)?{ok:!1,outcome:{kind:`denied`,message:i.refused}}:i?n(i):null}}function rP(e,t,n){return JSON.stringify([e.kind,e.identifier,t.observer??null,t.teamIndex??null,t.participantId??null,t.role??null,n])}function iP({surface:e,viewer:t,feed:n,mode:r,resolved:i,onModeChange:a,rejection:o,hookFailure:s,onTeardown:c}){let l=n.kind===`view`?n.dispatch:nP(e,t,n.send),u=e.origin??window.location.origin,d=(0,E.useRef)(null),f=(0,E.useRef)(null),p=cP(n),m=(0,E.useRef)({dispatch:l,onModeChange:a,overlays:p});m.current={dispatch:l,onModeChange:a,overlays:p};let[h,g]=(0,E.useState)(!1),[_,v]=(0,E.useState)(!1),[y,b]=(0,E.useState)(!1),[x,S]=(0,E.useState)(!1),{selected:C}=vb(),{hold:w}=Tb(),T=n.kind===`view`?n.sessionKey:Xc(n.state,e,{sessionless:n.sessionless===!0});return(0,E.useEffect)(()=>{let n=d.current;if(!n)return;let r;return r=new CN({iframe:n,surface:e.kind,uiIdentifier:e.identifier,iframeOrigin:u,sessionKey:T,adapter:{callEndpoint:async({endpointIdentifier:e,request:t})=>{let n=await m.current.dispatch({type:`callEndpoint`,endpointIdentifier:e,request:t});if(n&&`type`in n){if(n.type===`endpoint`)return n.response;if(n.type===`endpointFailure`)throw tP(n.failure)}throw tP({outcome:n&&`ok`in n&&!n.ok?n.outcome:{kind:`error`,message:`The endpoint did not answer`},applied:[]})},uploadBlob:async t=>{let n=await(await fetch(`/api/blobs`,{method:`POST`,headers:ZN(t,e.kind),body:t.data})).json();if(!n.reference)throw Error(`The blob was not stored`);return n.reference},getPastState:async e=>{let t=await m.current.dispatch({type:`getPastState`,query:e});return t&&`type`in t&&t.type===`pastState`?t.entries:[]},getAllTeamsParticipants:async()=>{let e=await m.current.dispatch({type:`getAllTeamsParticipants`});return e&&`type`in e&&e.type===`participants`?e.participants:[]}},observer:t.observer===!0,onConnect:({signalsRendered:e})=>{g(!0),v(!e),b(!e),S(!1)},onRendered:()=>{v(!0),b(!0)},onTeardown:e=>{e===`handshake-timeout`&&(g(!1),S(!0),c?.())},onMessage:e=>{e.type===`setThemePreference`?m.current.onModeChange?.(e.preference):oP(r,e,m.current.dispatch,m.current.overlays)}}),f.current=r,()=>{r.dispose(),f.current=null,g(!1),v(!1),b(!1)}},[e.identifier,e.kind,t.observer,t.teamIndex,t.participantId,t.role,T,w]),(0,E.useEffect)(()=>{let a=f.current;if(!a)return;let o={mode:i,preference:r,palette:qN(i,C)},s=n.kind===`view`?[...n.messages,...Zc(o)]:nl({surface:e,state:n.state,viewer:t,theme:o,origin:window.location.origin,assetOrigin:u,gameName:n.state.game.name,...n.overlays===void 0?{}:{overlays:n.overlays},...n.roundProcessing===void 0?{}:{roundProcessing:n.roundProcessing},...n.sessionless===void 0?{}:{sessionless:n.sessionless}});if(w===`surface`)for(let e of xb(s,w))a.sendIfChanged(e);else if(a.connected)for(let e of s)a.sendIfChanged(e);else a.sendInitialBatch(s)},[e,n,t,r,i,u,C,w]),(0,E.useEffect)(()=>{if(!h||_||w===`host`)return;let e=setTimeout(()=>v(!0),QN);return()=>clearTimeout(e)},[h,_,w]),(0,E.useEffect)(()=>{let e=f.current;e&&o&&(o.teamIndex===void 0||o.teamIndex===t.teamIndex)&&e.send({type:`validationRejected`,rejections:o.rejections})},[o?.nonce,o,t.teamIndex]),(0,E.useEffect)(()=>{let t=f.current;t&&s&&e.kind===`session`&&t.send({type:`hookFailed`,payload:s.payload})},[s?.nonce,s,e.kind]),(0,V.jsxs)(am,{"data-surface-state":x?`lost`:h?y?`rendered`:_?`unconfirmed`:`loading`:`loading`,sx:{position:`relative`,width:`100%`,height:`100%`},children:[(0,V.jsx)(am,{component:`iframe`,ref:d,title:e.identifier,src:`${u}${e.src}?expectedParentOrigin=${encodeURIComponent(window.location.origin)}`,sandbox:$N,allow:eP,sx:{width:`100%`,height:`100%`,border:0,display:`block`}},`${rP(e,t,T)}:${w}`),(!h||w===`host`||!_&&w!==`surface`)&&(0,V.jsx)(uy,{spacing:2,"data-testid":`surface-loading`,sx:{alignItems:`center`,justifyContent:`center`,position:`absolute`,inset:0,bgcolor:`background.default`},children:x?(0,V.jsx)(Z,{color:`text.secondary`,children:`This surface did not connect. Check its console for an error.`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(dP,{brand:C,resolved:i}),(0,V.jsxs)(Z,{color:`text.secondary`,variant:`body2`,children:[`Loading `,e.identifier]})]})})]})}function aP(e,t,n){return e!==`facilitator-guide`&&e!==`print-sheets`&&e!==`presentation`?`"${String(e)}" is not a host overlay`:n.available.includes(e)?e===`print-sheets`&&t!==void 0&&n.teamIds!==void 0&&!n.teamIds.includes(String(t))?`There is no team "${String(t)}" to print`:null:`This host does not offer the "${e}" overlay for this game`}async function oP(e,t,n,r={available:[`facilitator-guide`,`print-sheets`,`presentation`]}){if(t.type===`setThemePreference`)return;if(t.type===`openHostOverlay`){let n=aP(t.overlay,t.target,r);n||sP(t.overlay,t.target),lP(e,t,n?{ok:!1,outcome:{kind:`denied`,message:n}}:{ok:!0});return}let i;try{i=await n(t)}catch(e){i={ok:!1,outcome:{kind:`error`,message:e instanceof Error?e.message:`The command failed`}}}if(!i){lP(e,t,{ok:!1,outcome:{kind:`denied`,message:`This host does not handle "${String(t.type)}"`}});return}let a=typeof t.requestId==`string`?t.requestId:null;a&&(`ok`in i?e.send(i.ok?{type:`mutation:response`,requestId:a,ok:!0,...i.committedAtTick===void 0?{}:{committedAtTick:i.committedAtTick}}:{type:`mutation:response`,requestId:a,ok:!1,outcome:i.outcome}):e.send({type:`mutation:response`,requestId:a,ok:!0}))}function sP(e,t){if(e===`facilitator-guide`)return window.open(`/guide`,`_blank`,`noreferrer`),!0;if(e===`print-sheets`){let e=typeof t==`string`?`?team=${encodeURIComponent(t)}`:``;return window.open(`/print${e}`,`_blank`,`noreferrer`),!0}return e===`presentation`&&(window.open(`/presentation`,`_blank`,`noreferrer`),!0)}function cP(e){if(e.kind===`operator`)return{available:e.overlays??ll(),teamIds:e.state.teams.map(e=>e.teamId)};let t=e.messages.find(e=>e.type===`setAvailableOverlays`),n=e.messages.find(e=>e.type===`setTeamList`);return{available:Array.isArray(t?.overlays)?t.overlays:[],...Array.isArray(n?.payload)?{teamIds:n.payload.map(e=>e.teamId)}:{}}}function lP(e,t,n){typeof t.requestId==`string`&&e.send({type:`mutation:response`,requestId:t.requestId,...n})}function uP(e,t){return t===`dark`?e?.onDark??e?.onLight:e?.onLight??e?.onDark}function dP({brand:e,resolved:t}){let n=uP(e?.loader,t);if(n)return(0,V.jsx)(am,{component:`img`,src:n,alt:``,sx:{width:72,height:72}});let r=uP(e?.theme.brand?.logo,t),i=e?.theme[t].primary;return(0,V.jsxs)(V.Fragment,{children:[r&&(0,V.jsx)(am,{component:`img`,src:r,alt:e?.name??``,sx:{maxHeight:48,maxWidth:`min(320px, 80%)`,objectFit:`contain`}}),(0,V.jsx)(rd,{size:28,sx:i?{color:i}:void 0})]})}function fP({scenario:e,surface:t,state:n,mode:r,resolved:i,send:a,onModeChange:o,rejection:s}){let[c,l]=(0,E.useState)(!1),[u,d]=(0,E.useState)(!1),[f,p]=(0,E.useState)(null),m=e===``?null:e,h=n.scenarioDrafts?.some(e=>e.scenarioId===m)===!0,[g,_]=(0,E.useState)(null);(0,E.useEffect)(()=>{h||a({type:`editScenario`,scenarioId:m}).then(e=>{`ok`in e&&!e.ok&&_(e.outcome.message??`The scenario could not be opened`)})},[h,m,a]);let v=async()=>{l(!0),p(null);try{let t=await fetch(`/api/scenarios`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({identifier:e,overwrite:!0,draft:!0})});if(!t.ok){let e=await t.json();p(e.error??`The scenario could not be saved`);return}d(!0)}finally{l(!1)}};return(0,V.jsxs)(am,{sx:{display:`flex`,flexDirection:`column`,height:`100vh`},children:[(0,V.jsx)(jd,{position:`static`,color:`default`,elevation:1,children:(0,V.jsxs)(yy,{variant:`dense`,sx:{gap:2},children:[(0,V.jsxs)(uy,{sx:{flex:1},children:[(0,V.jsx)(Z,{variant:`subtitle2`,children:`Editing scenario`}),(0,V.jsx)(Z,{variant:`caption`,color:`text.secondary`,children:e})]}),u&&!f&&(0,V.jsx)(Z,{variant:`body2`,color:`success.main`,children:`Saved`}),(0,V.jsx)(_m,{variant:`contained`,"data-testid":`save-scenario`,disabled:c,onClick:()=>void v(),children:`Save`}),(0,V.jsx)(_m,{href:`/`,children:`Done`})]})}),(f??g)&&(0,V.jsx)(xd,{severity:`error`,sx:{borderRadius:0},children:f??g}),(0,V.jsx)(am,{sx:{flex:1,minHeight:0,position:`relative`},children:h?t?(0,V.jsx)(iP,{surface:t,viewer:m===null?{}:{scenario:m},feed:{kind:`operator`,state:n,send:e=>(e.type===`updateScenarioDraft`&&d(!1),a(e))},mode:r,resolved:i,onModeChange:o,rejection:s}):(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100%`,p:4},children:[(0,V.jsxs)(xd,{severity:`info`,sx:{maxWidth:560},children:[(0,V.jsxs)(Z,{gutterBottom:!0,children:[`This game has no `,(0,V.jsx)(`strong`,{children:`scenario_editor`}),` slot.`]}),(0,V.jsxs)(Z,{variant:`body2`,color:`text.secondary`,children:[`A scenario editor is optional (§6.5). Without one there is nothing to author a scenario in here; the values can still be set with`,` `,(0,V.jsx)(`code`,{children:`sdk configure`}),` and captured from the Scenario tab, and an agent can edit a game's settings directly from their schemas.`]})]}),(0,V.jsx)(_m,{href:`/`,children:`Back to the session`})]}):(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100%`},children:[(0,V.jsx)(rd,{size:28}),(0,V.jsxs)(Z,{color:`text.secondary`,variant:`body2`,children:[`Opening `,e||`the package settings`]})]})})]})}var pP={processing:new Set,errors:[],rejection:null,hookFailure:null,reloads:0,restarted:null},mP=new Set([`bundles-reloaded`,`reinitialised-on-change`,`logic-reloaded`]);function hP(e=`session`){let[t,n]=(0,E.useState)(null),[r,i]=(0,E.useState)(!1),[a,o]=(0,E.useState)(0),[s,c]=(0,E.useState)(pP),l=(0,E.useRef)(null),u=(0,E.useRef)(null),d=(0,E.useRef)(new Map),f=(0,E.useRef)(0);(0,E.useEffect)(()=>{let t=!1,r,a=()=>{let s=e===`walkthrough`?`?run=walkthrough`:``,f=new WebSocket(`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws${s}`);l.current=f,f.onopen=()=>{i(!0),o(0),u.current!==null&&f.send(JSON.stringify({presence:u.current}))},f.onclose=()=>{i(!1),o(e=>e+1),t||(r=setTimeout(a,1e3))},f.onmessage=e=>{let t=JSON.parse(e.data);t.type===`result`?(d.current.get(t.requestId)?.(t.result),d.current.delete(t.requestId)):gP(t,n,c)}};return a(),()=>{t=!0,clearTimeout(r),l.current?.close()}},[e]);let p=(0,E.useCallback)(e=>{let t=l.current;if(!t||t.readyState!==WebSocket.OPEN)return Promise.resolve({ok:!1,outcome:{kind:`error`,message:`Not connected to the session`}});let n=`console-${++f.current}`;return new Promise(r=>{d.current.set(n,r),t.send(JSON.stringify({requestId:n,command:e}))})},[]),m=(0,E.useCallback)(e=>{if(u.current===e)return;u.current=e;let t=l.current;t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify({presence:e}))},[]);return(0,E.useMemo)(()=>({state:t,connected:r,attempts:a,transients:s,send:p,announce:m}),[t,r,a,s,p,m])}function gP(e,t,n){switch(e.type){case`state`:t(e.state),mP.has(e.cause)&&n(t=>({...t,reloads:t.reloads+1,restarted:e.cause===`reinitialised-on-change`?{nonce:(t.restarted?.nonce??0)+1}:t.restarted}));return;case`round-processing`:n(t=>{let n=new Set(t.processing),r=e.teamIndex??-1;return e.processing?n.add(r):n.delete(r),{...t,processing:n}});return;case`error`:n(t=>({...t,errors:[...t.errors,`${e.source}: ${e.message}`],hookFailure:e.source.startsWith(`hook:`)?{payload:{signal:e.source.slice(5),teamId:e.teamId??``,message:e.message},nonce:(t.hookFailure?.nonce??0)+1}:t.hookFailure}));return;case`validation-rejected`:n(t=>({...t,rejection:{...e.teamIndex===void 0?{}:{teamIndex:e.teamIndex},rejections:e.rejections,nonce:(t.rejection?.nonce??0)+1}}));return}}function _P(){let[e,t]=(0,E.useState)(null),[n,r]=(0,E.useState)(!1),[i,a]=(0,E.useState)(0),[o,s]=(0,E.useState)(null),[c,l]=(0,E.useState)(null),u=(0,E.useRef)(null),d=(0,E.useRef)(new Map),f=(0,E.useRef)(0);(0,E.useEffect)(()=>{let e=!1,n,i=()=>{let o=encodeURIComponent(location.pathname+location.search),c=new WebSocket(`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws/view?page=${o}`);u.current=c,c.onopen=()=>{r(!0),a(0)},c.onclose=()=>{r(!1),a(e=>e+1),e||(n=setTimeout(i,1e3))},c.onmessage=e=>{let n=JSON.parse(e.data);switch(n.type){case`view`:(0,Ap.flushSync)(()=>t({page:n.page,messages:n.messages}));return;case`result`:d.current.get(n.requestId)?.(n.result),d.current.delete(n.requestId);return;case`validation-rejected`:s(e=>({rejections:n.rejections,nonce:(e?.nonce??0)+1}));return;case`hookFailed`:l(e=>({payload:n.payload,nonce:(e?.nonce??0)+1}));return}}};return i(),()=>{e=!0,clearTimeout(n),u.current?.close()}},[]);let p=(0,E.useCallback)(e=>{let t=u.current;if(!t||t.readyState!==WebSocket.OPEN)return Promise.resolve({ok:!1,outcome:{kind:`error`,message:`Not connected to the session`}});let n=`view-${++f.current}`;return new Promise(r=>{d.current.set(n,r),t.send(JSON.stringify({requestId:n,message:e}))})},[]);return(0,E.useMemo)(()=>({view:e,connected:n,attempts:i,rejection:o,hookFailure:c,dispatch:p}),[e,n,i,o,c,p])}function vP(e){let t=(0,E.useMemo)(()=>Uc(location.pathname,location.search),[]);return _l(t)?(0,V.jsx)(yP,{...e}):(0,V.jsx)(xP,{...e,route:t})}function yP({mode:e,resolved:t,onModeChange:n}){let{view:r,connected:i,attempts:a,rejection:o,hookFailure:s,dispatch:c}=_P();if(!r)return(0,V.jsx)(DP,{connected:i,attempts:a});let{page:l,messages:u}=r;switch(l.status){case`redirect`:return location.replace(l.href),(0,V.jsx)(DP,{connected:i,attempts:a});case`configuring`:return(0,V.jsx)(bP,{children:`The facilitator is setting the session up. This page opens when it starts.`});case`closed`:return(0,V.jsx)(bP,{children:`This session has already started, so its configuration is closed.`});case`join`:return(0,V.jsx)(aN,{team:l.team??void 0,bare:!0});case`no-such-team`:return(0,V.jsx)(OP,{resolution:{kind:`no-such-team`,teamIndex:l.teamIndex},bare:!0});case`no-such-participant`:return(0,V.jsx)(OP,{resolution:{kind:`no-such-participant`,teamIndex:l.teamIndex,slot:l.slot,held:l.held},bare:!0});case`missing-surface`:return(0,V.jsx)(kP,{kind:l.kind});case`surface`:return(0,V.jsxs)(am,{sx:{display:`flex`,flexDirection:`column`,height:`100vh`},children:[!i&&(0,V.jsx)(TP,{attempts:a}),l.inSetup&&l.surface.kind===`setup`&&(0,V.jsx)(jd,{position:`static`,color:`default`,elevation:1,children:(0,V.jsxs)(yy,{variant:`dense`,sx:{gap:2},children:[(0,V.jsx)(Z,{variant:`subtitle2`,sx:{flex:1},children:`Configure the session, then start it`}),(0,V.jsx)(_m,{variant:`contained`,"data-testid":`play`,onClick:()=>void c({type:`requestPlay`}),children:`Play`})]})}),(0,V.jsx)(am,{sx:{flex:1,minHeight:0,position:`relative`},children:(0,V.jsx)(iP,{surface:l.surface,viewer:l.viewer,feed:{kind:`view`,messages:u,dispatch:c,sessionKey:l.sessionKey},mode:e,resolved:t,onModeChange:n,rejection:o,hookFailure:s})})]})}}function bP({children:e}){return(0,V.jsx)(uy,{sx:{alignItems:`center`,justifyContent:`center`,height:`100vh`,p:4},children:(0,V.jsx)(xd,{severity:`info`,sx:{maxWidth:560},"data-testid":`view-notice`,children:(0,V.jsx)(Z,{children:e})})})}function xP({mode:e,resolved:t,onModeChange:n,route:r}){let{state:i,connected:a,attempts:o,transients:s,send:c,announce:l}=hP(r.run),[u,d]=(0,E.useState)(null),[f,p]=(0,E.useState)([`print-sheets`]);(0,E.useEffect)(()=>{fetch(`/api/surfaces`).then(e=>e.json()).then(d)},[s.reloads]);let[m,h]=(0,E.useState)([]);(0,E.useEffect)(()=>{fetch(`/api/session`).then(e=>e.json()).then(e=>h((e.warnings??[]).filter(e=>e.build)))},[s.reloads]);let[g,_]=(0,E.useState)(!1);(0,E.useEffect)(()=>{s.restarted&&_(!0)},[s.restarted]),(0,E.useEffect)(()=>{fetch(`/api/overlays`).then(e=>e.json()).then(e=>p(e.overlays))},[s.reloads]);let v=i&&r.kind===`player`?(()=>{let e=ml(i,r);return e.kind===`viewer`?e.viewer.participantId??null:null})():null;if((0,E.useEffect)(()=>l(v),[l,v]),!i||!u)return(0,V.jsx)(DP,{connected:a,attempts:o});let y=u.some(e=>e.kind===`setup`),b=i.session.inSetup,x=r.kind===`guide`||r.kind===`print`||r.kind===`scenario-editor`||r.kind===`presentation`,S=b&&!x?{...r,kind:`setup`}:r;if(!b&&S.kind===`setup`)return(0,V.jsx)(wP,{configurable:y,onReconfigure:()=>void c({type:`reconfigure`})});if(S.kind===`scenario-editor`)return S.scenario===void 0?(0,V.jsx)(EP,{}):(0,V.jsx)(fP,{scenario:S.scenario,surface:u.find(e=>e.kind===`scenario-editor`),state:i,mode:e,resolved:t,send:c,onModeChange:n,rejection:s.rejection});if(S.kind===`join`){let e=i.teams.find(e=>e.index===S.teamIndex);return e?.participants.length===1?(location.replace(Wc({kind:`player`,teamIndex:e.index,participant:1,bare:S.bare})),(0,V.jsx)(DP,{connected:a,attempts:o})):(0,V.jsx)(aN,{team:e,bare:S.bare})}let C=ml(i,S);if(C.kind!==`viewer`)return(0,V.jsx)(OP,{resolution:C,bare:S.bare,onAddParticipant:()=>void c({type:`addParticipant`,teamId:`team-${C.teamIndex+1}`})});let w=i.session.waitingRoomOpen&&(S.kind===`player`||S.kind===`waiting-room`)?`waiting-room`:hl[S.kind],T=w?u.find(e=>e.kind===w):void 0;return(0,V.jsxs)(am,{sx:{display:`flex`,flexDirection:`column`,height:`100vh`},children:[!a&&(0,V.jsx)(TP,{attempts:o}),Lc(i.session.pending)&&!S.bare&&(0,V.jsx)(SP,{pending:i.session.pending,onReinitialise:()=>void c({type:`reset`})}),m.length>0&&!S.bare&&(0,V.jsx)(CP,{errors:m}),b&&(0,V.jsx)(jd,{position:`static`,color:`default`,elevation:1,children:(0,V.jsxs)(yy,{variant:`dense`,sx:{gap:2},children:[(0,V.jsx)(Z,{variant:`subtitle2`,sx:{flex:1},children:`Configure the session, then start it`}),(0,V.jsx)(_m,{variant:`contained`,"data-testid":`play`,onClick:()=>void c({type:`play`}),children:`Play`})]})}),(0,V.jsx)(am,{sx:{flex:1,minHeight:0,position:`relative`},children:S.kind===`guide`?(0,V.jsx)(iN,{locale:i.session.locale,reloads:s.reloads}):S.kind===`print`?(0,V.jsx)(sN,{state:i}):T?(0,V.jsx)(iP,{surface:T,viewer:C.viewer,feed:{kind:`operator`,state:i,overlays:f,...S.kind===`presentation`?{sessionless:S.preview===!0}:{},roundProcessing:s.processing.has(-1)||C.viewer.teamIndex!==void 0&&s.processing.has(C.viewer.teamIndex),send:c},mode:e,resolved:t,onModeChange:n,rejection:s.rejection,hookFailure:s.hookFailure}):(0,V.jsx)(kP,{kind:w??`session`})}),!S.bare&&(0,V.jsx)(Db,{state:i,route:S,inSetup:b,configurable:y,connected:a,transients:s,mode:e,onModeChange:n,send:c}),(0,V.jsx)(Zv,{open:g,autoHideDuration:4e3,onClose:()=>_(!1),anchorOrigin:{vertical:`top`,horizontal:`center`},children:(0,V.jsx)(xd,{severity:`info`,"data-testid":`restarted-notice`,children:`Settings changed, game restarted`})})]})}function SP({pending:e,onReinitialise:t}){return(0,V.jsxs)(xd,{severity:`warning`,square:!0,"data-testid":`pending-changes`,sx:{borderRadius:0,py:.25},action:(0,V.jsx)(_m,{size:`small`,color:`inherit`,"data-testid":`reinitialise`,onClick:t,children:`Re-initialise`}),children:[(0,V.jsx)(`strong`,{children:Rc(e)}),`. `,zc(e),`. Re-initialising returns play to tick 0.`]})}function CP({errors:e}){return(0,V.jsxs)(xd,{severity:`error`,square:!0,"data-testid":`build-errors`,sx:{borderRadius:0,py:.25},children:[(0,V.jsxs)(`strong`,{children:["`sdk build` would refuse this package (",e.length===1?`one error`:`${e.length} errors`,`)`]}),`. It runs here anyway, so it can be fixed while you watch.`,e.map((e,t)=>(0,V.jsx)(Z,{variant:`body2`,sx:{fontFamily:`monospace`},children:e.message},t))]})}function wP({configurable:e,onReconfigure:t}){return(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100vh`,p:4},children:[(0,V.jsxs)(xd,{severity:`info`,sx:{maxWidth:560},children:[(0,V.jsx)(Z,{gutterBottom:!0,children:`This session has already started.`}),(0,V.jsx)(Z,{variant:`body2`,color:`text.secondary`,children:e?`Settings are resolved when a session initialises, so changing them now would change nothing until the session starts again. Reconfiguring puts the session back to its setup step and returns every team to tick 0.`:`This game has no setup step.`})]}),(0,V.jsxs)(uy,{direction:`row`,spacing:1,children:[e&&(0,V.jsx)(_m,{variant:`contained`,"data-testid":`reconfigure`,onClick:t,children:`Reconfigure`}),(0,V.jsx)(_m,{href:`/`,children:`Back to the session`})]})]})}function TP({attempts:e}){return(0,V.jsxs)(xd,{severity:`warning`,square:!0,"data-testid":`disconnected`,sx:{borderRadius:0,py:.25},action:(0,V.jsx)(_m,{size:`small`,color:`inherit`,onClick:()=>location.reload(),children:`Reload`}),children:[`Disconnected from the session — nothing on this page is live.`,e>1?` Retrying (${e}).`:` Retrying…`]})}function EP(){return(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100vh`,p:4},children:[(0,V.jsxs)(xd,{severity:`info`,sx:{maxWidth:560},children:[(0,V.jsx)(Z,{gutterBottom:!0,children:`The scenario editor opens on a scenario.`}),(0,V.jsxs)(Z,{variant:`body2`,color:`text.secondary`,children:[`Open the dev drawer (press `,(0,V.jsx)(`kbd`,{children:"`"}),`) and use the Scenario tab:`,` `,(0,V.jsx)(`strong`,{children:`Add scenario`}),` to start a new one, or `,(0,V.jsx)(`strong`,{children:`Edit`}),` on an existing one. An editor with no scenario behind it has nowhere to save what you do in it.`]})]}),(0,V.jsx)(_m,{href:`/`,children:`Back to the session`})]})}function DP({connected:e,attempts:t}){let n=!e&&t>=2,r=$o().palette.mode===`dark`;return(0,V.jsxs)(uy,{spacing:2,"data-testid":`console-loading`,sx:{alignItems:`center`,justifyContent:`center`,height:`100vh`,p:4},children:[(0,V.jsx)(am,{component:`img`,src:r?Jy:Yy,alt:`Serious Gaming`,sx:{width:72,height:72}}),!n&&(0,V.jsx)(Z,{color:`text.secondary`,children:e?`Loading the session…`:`Connecting to the session…`}),n&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(xd,{severity:`warning`,sx:{maxWidth:620},children:[(0,V.jsxs)(Z,{gutterBottom:!0,children:[`Nothing is answering at`,` `,(0,V.jsxs)(`code`,{children:[location.host,`/ws`]}),`.`]}),(0,V.jsxs)(Z,{variant:`body2`,color:`text.secondary`,component:`div`,children:[`This page loaded, so something is serving it — most likely an older dev server still holding this port. Check two things:`,(0,V.jsxs)(`ul`,{style:{marginBottom:0},children:[(0,V.jsxs)(`li`,{children:[`The address your server actually printed.`,location.port&&(0,V.jsxs)(V.Fragment,{children:[` `,`A port already in use makes it move to the next one, so it may be on `,(0,V.jsx)(`code`,{children:Number(location.port)+1})]})]}),(0,V.jsxs)(`li`,{children:[`Whether an old one is still running:`,` `,(0,V.jsx)(`code`,{children:`pnpm run sdk dev status`}),`, and`,` `,(0,V.jsx)(`code`,{children:`pnpm run sdk dev stop`}),` to end it`]})]})]})]}),(0,V.jsx)(_m,{variant:`outlined`,onClick:()=>location.reload(),children:`Try again`})]})]})}function OP({resolution:e,bare:t,onAddParticipant:n}){let r=e.teamIndex+1;return(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100vh`,p:4},"data-testid":`no-such-participant`,children:[(0,V.jsx)(xd,{severity:`warning`,sx:{maxWidth:560},children:e.kind===`no-such-team`?(0,V.jsxs)(Z,{gutterBottom:!0,children:[`This session has no team `,r,`. It may have been removed.`]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(Z,{gutterBottom:!0,children:[`Team `,r,` has`,` `,e.held===0?`no participants`:e.held===1?`one participant`:`${e.held} participants`,`, and this URL asks for participant `,e.slot,`.`]}),(0,V.jsx)(Z,{variant:`body2`,color:`text.secondary`,children:`A second tab is not a second participant. Add one, then open their surface: a participant is who a write is attributed to, and a surface with nobody behind it cannot submit one.`})]})}),e.kind===`no-such-participant`&&n&&(0,V.jsx)(_m,{variant:`contained`,onClick:n,"data-testid":`add-participant`,children:`Add participant`}),(0,V.jsxs)(_m,{size:`small`,href:Wc({kind:`observer`,teamIndex:e.teamIndex,bare:t}),children:[`Watch team `,r,` without joining`]})]})}function kP({kind:e}){return(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100%`,p:4},children:[(0,V.jsxs)(xd,{severity:`info`,sx:{maxWidth:560},children:[(0,V.jsxs)(Z,{gutterBottom:!0,children:[`This package wires no `,(0,V.jsx)(`strong`,{children:e}),` surface.`]}),(0,V.jsx)(Z,{variant:`body2`,color:`text.secondary`,children:`A game supplies its own facilitator and player surfaces; the dev server renders them rather than substituting a console of its own, so there is nothing to show until the package fills that slot.`})]}),(0,V.jsx)(_m,{href:`/`,size:`small`,children:`Back to the session`})]})}function AP(){let[e,t]=(0,E.useState)(()=>ob(location.search,rb(`sessionStorage`),rb(`localStorage`)));(0,E.useEffect)(()=>{if(window.parent===window)return;let e=e=>{if(e.source!==window.parent)return;let n=lb(e.data);n&&(sb(rb(`sessionStorage`),n),t(n))};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[]);let n=XN(e),r=(0,E.useMemo)(()=>YN(n),[n]);return(0,V.jsxs)(Ac,{theme:r,children:[(0,V.jsx)(ds,{}),(0,V.jsx)(_b,{children:(0,V.jsx)(wb,{children:(0,V.jsx)(vP,{mode:e,resolved:n,onModeChange:e=>{cb(rb(`sessionStorage`),rb(`localStorage`),e),t(e)}})})})]})}(0,Ic.createRoot)(document.getElementById(`root`)).render((0,V.jsx)(E.StrictMode,{children:(0,V.jsx)(AP,{})}));
204
+ `},i)),a}function VM(e,t){return e&&`run`in e?async function(n,r){let i=BM(n,{file:r,...t});await e.run(i,r)}:function(n,r){return BM(n,{file:r,...e||t})}}var HM=[],UM={allowDangerousHtml:!0},WM=/^(https?|ircs?|mailto|xmpp)$/i,GM=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`className`,id:`remove-classname`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function KM(e){let t=qM(e),n=JM(e);return YM(t.runSync(t.parse(n),n),e)}function qM(e){let t=e.rehypePlugins||HM,n=e.remarkPlugins||HM,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...UM}:UM;return _k().use(HO).use(n).use(VM,r).use(t)}function JM(e){let t=e.children||``,n=new lk;return typeof t==`string`?n.value=t:``+t,n}function YM(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||XM;for(let e of GM)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return hw(e,l),mj(e,{Fragment:V.Fragment,components:i,ignoreInvalidStyle:!0,jsx:V.jsx,jsxs:V.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in Ij)if(Object.hasOwn(Ij,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=Ij[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function XM(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||WM.test(e.slice(0,t))?e:``}var ZM={note:{label:`Note`,palette:`info`,icon:(0,V.jsx)(iA,{fontSize:`small`})},warning:{label:`Warning`,palette:`warning`,icon:(0,V.jsx)(lA,{fontSize:`small`})},tip:{label:`Tip`,palette:`success`,icon:(0,V.jsx)(aA,{fontSize:`small`})},say:{label:`Say`,palette:`primary`,icon:(0,V.jsx)(oA,{fontSize:`small`})},do:{label:`Do`,palette:`secondary`,icon:(0,V.jsx)(sA,{fontSize:`small`})},timing:{label:`Timing`,palette:`info`,icon:(0,V.jsx)(cA,{fontSize:`small`})}};function QM({type:e,children:t}){let n=ZM[e];return(0,V.jsxs)(am,{sx:e=>({my:2,px:2,py:1.5,borderLeft:3,borderColor:`${n.palette}.main`,borderRadius:1,bgcolor:gi(e.palette[n.palette].main,.08),"& p:first-of-type":{mt:0},"& p:last-of-type":{mb:0}}),"data-testid":`guide-admonition-${e}`,children:[(0,V.jsxs)(Z,{variant:`overline`,component:`p`,sx:{display:`flex`,alignItems:`center`,gap:.75,fontWeight:600,lineHeight:1.5,mb:.5,color:`${n.palette}.main`},children:[n.icon,n.label]}),t]})}function $M(e){return`/api/guide/assets/${e.split(`/`).map(encodeURIComponent).join(`/`)}`}function eN({body:e,locale:t}){let n=nA(e);return n.ok?n.kind===`file`?(0,V.jsxs)(am,{component:`figure`,sx:{my:2,mx:0,maxWidth:720},"data-testid":`guide-video-file`,children:[(0,V.jsxs)(am,{component:`video`,controls:!0,preload:`metadata`,playsInline:!0,src:$M(n.src),poster:n.poster?$M(n.poster):void 0,"aria-label":n.title,sx:{display:`block`,width:`100%`,"@media print":{display:`none`}},children:[n.captions&&(0,V.jsx)(`track`,{kind:`captions`,src:$M(n.captions),srcLang:t,label:t,default:!0}),n.title]}),(0,V.jsxs)(am,{sx:{display:`none`,"@media print":{display:`block`}},children:[n.poster&&(0,V.jsx)(am,{component:`img`,src:$M(n.poster),alt:``,sx:{display:`block`,maxWidth:`100%`}}),n.title&&(0,V.jsx)(Z,{component:`figcaption`,variant:`body2`,children:n.title})]})]}):(0,V.jsx)(am,{sx:{my:2,position:`relative`,aspectRatio:`16 / 9`,maxWidth:720},"data-testid":`guide-video-embed`,children:(0,V.jsx)(am,{component:`iframe`,src:n.embedUrl,title:`${n.provider} video`,sandbox:`allow-scripts allow-same-origin allow-presentation`,allow:`encrypted-media; fullscreen; picture-in-picture`,referrerPolicy:`strict-origin-when-cross-origin`,sx:{position:`absolute`,inset:0,width:`100%`,height:`100%`,border:0}})}):(0,V.jsxs)(xd,{severity:`error`,sx:{my:2},"data-testid":`guide-video-error`,children:[`Video block error: `,n.error]})}function tN(e){return e.children.map(e=>e.type===`text`?e.value:e.type===`element`?tN(e):``).join(``)}function nN({markdown:e,chapterFile:t,locale:n,settings:r}){return(0,V.jsx)(KM,{remarkPlugins:[$D,nC,[Bk,{settings:r,locale:n}],kk,Ak,[Kk,{chapterFile:t}]],urlTransform:e=>{let r=XM(e);if(!r)return;if(/^[a-z][a-z0-9+.-]*:/i.test(r)||r.startsWith(`//`)||r.startsWith(`#`)||r.startsWith(`/`))return r;let i=new URL(`/api/guide/content/${n}/${t}`,window.location.origin),a=new URL(r,i);if(a.origin===window.location.origin&&a.pathname.startsWith(`/api/guide/`))return a.pathname+a.search},components:{pre({node:e,children:t,...r}){let i=e?.children[0];return i&&i.type===`element`&&i.tagName===`code`&&Array.isArray(i.properties?.className)&&i.properties.className.includes(`language-video`)?(0,V.jsx)(eN,{body:tN(i),locale:n}):(0,V.jsx)(`pre`,{...r,children:t})},span(e){let{node:t,children:n,...r}=e;return typeof r[`data-guide-error`]==`string`?(0,V.jsx)(am,{component:`span`,"data-testid":`guide-setting-error`,sx:{color:`error.main`,fontStyle:`italic`},children:n}):(0,V.jsx)(`span`,{...r,children:n})},div(e){let{node:t,children:n,...r}=e,i=r;if(typeof i[`data-guide-error`]==`string`)return(0,V.jsx)(xd,{severity:`error`,sx:{my:2},"data-testid":`guide-setting-error`,children:n});let a=i[`data-admonition`];if(typeof a==`string`&&Ok(a))return(0,V.jsx)(QM,{type:a,children:n});let o=i[`data-admonition-unknown`];return typeof o==`string`?(0,V.jsxs)(xd,{severity:`error`,sx:{my:2},"data-testid":`guide-admonition-unknown`,children:[`Unknown admonition type ":::`,o,`"`]}):(0,V.jsx)(`div`,{...e})},a({node:e,children:t,href:n,...r}){let i=typeof n==`string`&&/^https?:\/\//.test(n);return(0,V.jsx)(`a`,{href:n,...r,...i?{target:`_blank`,rel:`noreferrer noopener`}:{},children:t})}},children:e})}function rN(e){let t=e.replace(/\.md$/,``).replace(/^\d+[-_. ]*/,``).replace(/[-_]+/g,` `).trim();return t.charAt(0).toUpperCase()+t.slice(1)}function iN({locale:e,reloads:t}){let n=new URLSearchParams(window.location.search),[r,i]=(0,E.useState)(void 0),[a,o]=(0,E.useState)(n.get(`locale`)??e),[s,c]=(0,E.useState)(n.get(`chapter`)),[l,u]=(0,E.useState)(``);(0,E.useEffect)(()=>{fetch(`/api/guide`).then(e=>e.json()).then(e=>i(e.guide))},[t]);let d=(0,E.useMemo)(()=>Object.keys(r?.locales??{}),[r]),f=(0,E.useMemo)(()=>r?nx(r.locales,r.chapters,a):[],[r,a]),p=(0,E.useMemo)(()=>f.map(e=>e.file),[f]),m=f.find(e=>e.file===s)?.locale??a;(0,E.useEffect)(()=>{if(r){if(p.length===0)return c(null);s&&p.includes(s)||c(p[0])}},[r,p,s]),(0,E.useEffect)(()=>{if(!r||!s)return u(``);let e=!0;return fetch(`/api/guide/content/${encodeURIComponent(m)}/${encodeURIComponent(s)}`).then(e=>e.ok?e.text():`This chapter could not be read.`).then(t=>{e&&u(t)}),()=>{e=!1}},[r,m,s,t]);let h=(0,E.useMemo)(()=>s&&l&&r?qk(s,l,{settings:r.settings,locale:m}):[],[s,l,r,m]);return r===void 0?(0,V.jsx)(uy,{sx:{alignItems:`center`,justifyContent:`center`,height:`100%`},children:(0,V.jsx)(rd,{size:28})}):r===null?(0,V.jsx)(uy,{sx:{alignItems:`center`,justifyContent:`center`,height:`100%`,p:4},children:(0,V.jsx)(Z,{color:`text.secondary`,children:`This package declares no facilitator guide, or none of its chapters applies to this session.`})}):(0,V.jsxs)(uy,{direction:`row`,sx:{height:`100%`},children:[(0,V.jsxs)(am,{sx:{width:280,borderRight:1,borderColor:`divider`,overflow:`auto`,"@media print":{display:`none`}},children:[d.length>1&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(am,{sx:{p:2},children:(0,V.jsx)(Bv,{size:`small`,fullWidth:!0,value:d.includes(a)?a:d[0]??``,onChange:e=>o(e.target.value),children:d.map(e=>(0,V.jsx)($_,{value:e,children:r.locales[e]?.name??e},e))})}),(0,V.jsx)(Nh,{})]}),(0,V.jsxs)(Rg,{dense:!0,children:[p.map(e=>(0,V.jsx)(Hg,{selected:e===s,onClick:()=>c(e),children:(0,V.jsx)(Jg,{primary:rN(e)})},e)),p.length===0&&(0,V.jsx)(am,{sx:{px:2,py:1},children:(0,V.jsx)(Z,{variant:`body2`,color:`text.secondary`,children:`This guide has no chapters yet.`})})]}),h.some(e=>e.depth>1)&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Nh,{}),(0,V.jsx)(Z,{variant:`overline`,color:`text.secondary`,sx:{display:`block`,px:2,pt:1.5},children:`On this page`}),(0,V.jsx)(Rg,{dense:!0,disablePadding:!0,sx:{pb:2},children:h.filter(e=>e.depth>1).map(e=>(0,V.jsx)(Hg,{dense:!0,sx:{pl:2+(e.depth-2)*1.5,py:.25},onClick:()=>document.getElementById(e.id)?.scrollIntoView({block:`start`}),children:(0,V.jsx)(Jg,{primary:e.text,slotProps:{primary:{variant:`body2`,color:`text.secondary`}}})},e.id))})]})]}),(0,V.jsx)(am,{sx:{flex:1,minWidth:0,overflow:`auto`},children:(0,V.jsxs)(am,{"data-testid":`guide-content`,sx:{maxWidth:780,mx:`auto`,px:4,py:3,"& img":{maxWidth:`100%`},"& pre":{p:2,borderRadius:1,overflow:`auto`,bgcolor:`action.hover`},"& table":{borderCollapse:`collapse`,width:`100%`},"& th, & td":{border:1,borderColor:`divider`,px:1,py:.5},"& h1, & h2, & h3":{scrollMarginTop:16},"@media print":{maxWidth:`none`,px:0,py:0}},children:[s&&m!==a&&(0,V.jsxs)(xd,{severity:`info`,"data-testid":`guide-untranslated`,sx:{mb:2,"@media print":{display:`none`}},children:[`This chapter is not yet translated into`,` `,r.locales[a]?.name??a,`, so it is shown in`,` `,r.locales[m]?.name??m,`.`]}),s&&(0,V.jsx)(nN,{markdown:l,chapterFile:s,locale:m,settings:r.settings})]})})]})}function aN({team:e,bare:t}){return e?e.participants.length===0?(0,V.jsxs)(oN,{children:[(0,V.jsxs)(uy,{spacing:1,sx:{alignItems:`center`,maxWidth:420},children:[(0,V.jsx)(Z,{variant:`overline`,color:`text.secondary`,children:e.name}),(0,V.jsx)(Z,{variant:`h5`,children:`Nobody is on this team yet`}),(0,V.jsxs)(Z,{color:`text.secondary`,sx:{textAlign:`center`},children:[`Add a participant from the dev drawer, or with`,` `,(0,V.jsxs)(`code`,{children:[`sdk participant add --team `,e.index+1]}),`, and they will be listed here.`]})]}),(0,V.jsx)(_m,{size:`small`,href:Wc({kind:`observer`,teamIndex:e.index,bare:t}),children:`Watch without joining`})]}):(0,V.jsxs)(oN,{children:[(0,V.jsxs)(uy,{spacing:1,sx:{alignItems:`center`},children:[(0,V.jsx)(Z,{variant:`overline`,color:`text.secondary`,children:e.name}),(0,V.jsx)(Z,{variant:`h5`,children:`Who are you?`})]}),(0,V.jsx)(uy,{spacing:1.5,sx:{width:`100%`,maxWidth:420},children:e.participants.map((n,r)=>(0,V.jsx)(xm,{variant:`outlined`,"data-testid":`join-participant`,children:(0,V.jsxs)(Dm,{href:Wc({kind:`player`,teamIndex:e.index,participant:r+1,bare:t}),sx:{p:2},children:[(0,V.jsx)(Z,{variant:`subtitle1`,children:n.name}),(0,V.jsxs)(Z,{variant:`body2`,color:`text.secondary`,children:[`Participant `,r+1]})]})},n.id))}),(0,V.jsx)(_m,{size:`small`,href:Wc({kind:`observer`,teamIndex:e.index,bare:t}),children:`Watch without joining`})]}):(0,V.jsxs)(oN,{children:[(0,V.jsx)(Z,{color:`text.secondary`,children:`This session has no such team. It may have been removed.`}),(0,V.jsx)(_m,{href:`/`,children:`Back to the session`})]})}function oN({children:e}){return(0,V.jsx)(uy,{spacing:3,sx:{alignItems:`center`,justifyContent:`center`,height:`100%`,p:4,bgcolor:`background.default`},children:(0,V.jsx)(am,{sx:{display:`contents`},children:e})})}function sN({state:e}){let t=new URLSearchParams(window.location.search).get(`team`),n=t?e.teams.filter(e=>e.teamId===t):e.teams;return(0,E.useEffect)(()=>{let t=document.title;return document.title=`${e.game.name} — team sheets`,()=>{document.title=t}},[e.game.name]),(0,V.jsxs)(am,{"data-testid":`print-sheets`,sx:{height:`100%`,overflow:`auto`,bgcolor:`background.default`,"@media print":{height:`auto`,overflow:`visible`}},children:[(0,V.jsxs)(uy,{direction:`row`,spacing:2,sx:{alignItems:`center`,p:2,"@media print":{display:`none`}},children:[(0,V.jsx)(Z,{variant:`h6`,sx:{flex:1},children:`Team sheets`}),(0,V.jsx)(_m,{variant:`contained`,onClick:()=>window.print(),children:`Print`})]}),n.map(t=>(0,V.jsxs)(am,{sx:{m:2,p:4,bgcolor:`background.paper`,border:1,borderColor:`divider`,borderRadius:1,"@media print":{breakAfter:`page`,breakInside:`avoid`,border:0,m:0}},children:[(0,V.jsx)(Z,{variant:`overline`,color:`text.secondary`,children:e.game.name}),(0,V.jsx)(Z,{variant:`h3`,gutterBottom:!0,children:t.name}),(0,V.jsx)(Nh,{sx:{my:2}}),(0,V.jsx)(Z,{variant:`subtitle2`,gutterBottom:!0,children:`Open your screen at`}),(0,V.jsx)(Z,{sx:{fontFamily:`monospace`,fontSize:18,mb:3,wordBreak:`break-all`},children:`${window.location.origin}${Wc({kind:`player`,teamIndex:t.index,participant:1})}`}),(0,V.jsx)(Z,{variant:`subtitle2`,gutterBottom:!0,children:`On this team`}),(0,V.jsxs)(uy,{spacing:.5,children:[t.participants.map((e,n)=>(0,V.jsxs)(Z,{children:[n+1,`. `,e.name,(0,V.jsx)(Z,{component:`span`,variant:`caption`,color:`text.secondary`,sx:{ml:1,fontFamily:`monospace`},children:Wc({kind:`player`,teamIndex:t.index,participant:n+1})})]},e.id)),t.participants.length===0&&(0,V.jsx)(Z,{color:`text.secondary`,children:`Nobody yet.`})]})]},t.teamId))]})}var cN={game:new Set([`updateData`,`requestTick`,`renameOwnTeam`,`renameSelf`]),"waiting-room":new Set([`updateData`,`requestTick`,`renameOwnTeam`,`renameSelf`]),session:new Set([`updateSessionData`,`updateSharedData`,`requestTick`,`undoTick`,`resetGame`,`resetWalkthrough`,`setWaitingRoom`,`setLocale`,`createTeam`,`renameTeam`,`renameParticipant`,`moveParticipant`,`deleteTeam`,`pauseTimer`,`resumeTimer`,`extendTick`]),setup:new Set([`updateSettings`,`requestPlay`]),"scenario-editor":new Set([`updateSettings`]),presentation:new Set},lN={setWaitingRoom:`The waiting room is session-wide, so setWaitingRoom takes no teamId`,renameOwnTeam:`renameOwnTeam renames the caller's own team, which the host resolves; it takes no teamId`,resetWalkthrough:`A walkthrough holds one team, so resetWalkthrough takes no teamId`,setLocale:`The locale is the session's, so setLocale takes no teamId`,renameSelf:`renameSelf renames the caller, whom the host resolves; it takes no teamId`},uN={game:new Set([`callEndpoint`,`getPastState`,`getAllTeamsParticipants`]),"waiting-room":new Set([`callEndpoint`,`getPastState`,`getAllTeamsParticipants`]),session:new Set([`callEndpoint`,`getPastState`]),setup:new Set([`callEndpoint`]),"scenario-editor":new Set([`callEndpoint`]),presentation:new Set([`getPastState`])};function dN(e){return e.teamIndex===void 0?{}:{teamIndex:e.teamIndex}}function fN(e){return e.participantId===void 0?{}:{participantId:e.participantId,teamId:`team-${(e.teamIndex??0)+1}`}}function pN(e){return e.role===void 0?{}:{viewerRole:e.role}}function mN(e){return{...dN(e),...fN(e),...pN(e)}}function hN(e){let t=typeof e==`string`?/^team-([1-9]\d*)$/.exec(e):null;return t?Number(t[1])-1:-1}function gN(e,t){return e.teamId===void 0?t:{teamIndex:hN(e.teamId)}}function _N(e){return typeof e==`object`&&!!e&&`refused`in e}function vN(e,t,n){if(!cN[t.kind].has(e.type))return null;if(e.teamId!==void 0&&e.type in lN)return{refused:lN[e.type]};if(e.type===`renameSelf`&&e.participantId!==void 0)return{refused:`renameSelf renames the caller, whom the host resolves; it takes no participantId`};let r=dN(n),i=fN(n),a=pN(n);switch(e.type){case`updateData`:return{type:`updateContext`,uiIdentifier:t.identifier,payload:e.payload,...e.deletes?{deletes:e.deletes}:{},...r,...i,...a};case`updateSessionData`:return{type:`updateContext`,payload:e.payload,teamIndex:hN(e.teamId),sessionUiIdentifier:t.identifier,...e.deletes?{deletes:e.deletes}:{}};case`updateSharedData`:return{type:`updateSharedContext`,uiIdentifier:t.identifier,payload:e.payload,...e.deletes?{deletes:e.deletes}:{}};case`updateSettings`:return t.kind===`scenario-editor`?{type:`updateScenarioDraft`,scenarioId:n.scenario??null,payload:e.payload,uiIdentifier:t.identifier}:{type:`updateSettings`,payload:e.payload,uiIdentifier:t.identifier};case`requestTick`:return{type:`tick`,...gN(e,r),...t.kind===`session`?{}:{...i,...a}};case`undoTick`:return{type:`undo`,...gN(e,r)};case`resetGame`:return{type:`reset`,...gN(e,{})};case`setWaitingRoom`:return{type:`setWaitingRoom`,open:e.open===!0};case`setLocale`:return{type:`setLocale`,locale:String(e.locale)};case`resetWalkthrough`:return{type:`resetWalkthrough`};case`createTeam`:return{type:`addTeam`,...typeof e.name==`string`?{name:e.name}:{}};case`renameTeam`:return{type:`renameTeam`,teamId:String(e.teamId),name:String(e.name)};case`renameOwnTeam`:return{type:`renameOwnTeam`,name:String(e.name),...i};case`renameSelf`:return{type:`renameSelf`,name:String(e.name),...i};case`renameParticipant`:return{type:`renameParticipant`,participantId:String(e.participantId),name:String(e.name)};case`moveParticipant`:return{type:`moveParticipant`,participantId:String(e.participantId),teamId:String(e.teamId)};case`deleteTeam`:return{type:`removeTeam`,teamIndex:hN(e.teamId)};case`requestPlay`:return{type:`play`};case`pauseTimer`:return{type:`pauseTimer`,...gN(e,r)};case`resumeTimer`:return{type:`resumeTimer`,...gN(e,r)};case`extendTick`:return{type:`extendTick`,byMs:Number(e.byMs??0),...gN(e,r)};default:return null}}function yN(e,t,n){if(!uN[t.kind].has(e.type))return null;switch(e.type){case`callEndpoint`:return{type:`callEndpoint`,endpointIdentifier:String(e.endpointIdentifier),request:e.request,uiIdentifier:t.identifier,...mN(n),...t.kind===`scenario-editor`?{scenarioId:n.scenario??null}:{}};case`getPastState`:return{type:`getPastState`,query:e.query,uiIdentifier:t.identifier,...n.teamIndex===void 0?{}:{teamId:`team-${n.teamIndex+1}`}};case`getAllTeamsParticipants`:return{type:`getAllTeamsParticipants`,uiIdentifier:t.identifier};default:return null}}var bN={game:{required:[`stateChanged`,`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`,`setParticipant`],alsoSent:[`setTimer`,`setViewerRole`,`setOwnTeam`,`setOwnTeamJoinLink`,`setParticipantList`,`setTeamList`,`setRunKind`,`setScenarioName`,`setRoundProcessing`,`setCrossTeamData`,`themePreferenceChanged`],isPlayerSurface:!0},"waiting-room":{required:[`stateChanged`,`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`,`setParticipant`],alsoSent:[`setTimer`,`setViewerRole`,`setOwnTeam`,`setOwnTeamJoinLink`,`setParticipantList`,`setTeamList`,`setRunKind`,`setScenarioName`,`setCrossTeamData`,`themePreferenceChanged`],isPlayerSurface:!0},session:{required:[`setSessionMeta`,`setSessionData`,`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`,`setTeamConfiguration`],alsoSent:[`setTeamList`,`setParticipantList`,`setTeamLinks`,`setAvailableOverlays`,`setRunKind`,`setScenarioName`,`setWalkthroughLink`,`themePreferenceChanged`],isPlayerSurface:!1},presentation:{required:[`setPresentation`,`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`],alsoSent:[`themePreferenceChanged`],isPlayerSurface:!1},setup:{required:[`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`],alsoSent:[`themePreferenceChanged`],isPlayerSurface:!1},"scenario-editor":{required:[`setSettings`,`setTheme`,`setLocale`,`setAssetUrls`],alsoSent:[`themePreferenceChanged`],isPlayerSurface:!1}};function xN(e,t={}){let{required:n,isPlayerSurface:r}=bN[e];return!t.observer||!r?n:n.filter(e=>e!==`setParticipant`)}var SN=new Set([`callEndpoint`,`uploadBlob`,`getPastState`,`getAllTeamsParticipants`]),CN=class{options;host;logger;port=null;readyListener=null;loadListener=null;handshakeTimer=null;disposed=!1;lastSent=new Map;sticky=new Map;outbound=[];pending=new Map;requestCounter=0;constructor(e){this.options=e,this.host=e.window??globalThis.window,this.logger=e.logger??console,this.listenForReady()}get connected(){return this.port!==null}send(e){this.disposed||(this.lastSent.set(e.type,wN(e)),this.port?this.port.postMessage(e):this.outbound.push(e))}sendState(e){this.disposed||(this.sticky.set(e.type,e),this.lastSent.set(e.type,wN(e)),this.port?.postMessage(e))}sendIfChanged(e){return this.disposed||this.lastSent.get(e.type)===wN(e)?!1:(this.sendState(e),!0)}sendInitialBatch(e){let t=xN(this.options.surface,{observer:this.options.observer}),n=new Set(e.map(e=>e.type)),r=t.filter(e=>!n.has(e));if(r.length>0)throw Error(`Initial batch for a "${this.options.surface}" surface is missing ${r.join(`, `)}. The guest blocks its first paint on ${t.join(`, `)}.`);for(let t of e)this.sendState(t)}request(e,t=3e4){let n=`host-${++this.requestCounter}`;return new Promise((r,i)=>{let a=setTimeout(()=>{this.pending.delete(n),i(Error(`Guest did not answer "${e.type}" in ${t}ms`))},t);this.pending.set(n,{resolve:()=>{clearTimeout(a),r()},reject:e=>{clearTimeout(a),i(e)}}),this.send({...e,requestId:n})})}dispose(){this.disposed||(this.disposed=!0,this.clearHandshakeTimer(),this.readyListener&&=(this.host.removeEventListener(`message`,this.readyListener),null),this.loadListener&&=(this.options.iframe.removeEventListener?.(`load`,this.loadListener),null),this.closePort(),this.rejectPending(`Channel disposed`),this.options.onTeardown?.(`disposed`))}listenForReady(){let e=e=>{if(this.disposed)return;let t=e.data;if(!t||t.type!==`ready`||e.source!==this.options.iframe.contentWindow)return;if(e.origin!==this.options.iframeOrigin){this.logger.warn(`[${this.options.uiIdentifier}] ignoring a handshake from ${e.origin}; this frame is pinned to ${this.options.iframeOrigin}`);return}let n=t.protocolVersion;typeof n==`number`&&n!==4&&this.logger.warn(`[${this.options.uiIdentifier}] host↔iframe protocol version mismatch: iframe ${n}, host 4`),this.connect(t.signalsRendered===!0)};this.readyListener=e,this.host.addEventListener(`message`,e),this.armHandshakeTimer(),this.listenForLoads()}listenForLoads(){let{iframe:e}=this.options;if(!e.addEventListener)return;let t=()=>{this.disposed||(this.armHandshakeTimer(),this.port?.postMessage({type:`ping`}))};this.loadListener=t,e.addEventListener(`load`,t)}armHandshakeTimer(){this.clearHandshakeTimer();let e=this.options.handshakeTimeoutMs??1e4;this.handshakeTimer=setTimeout(()=>{this.handshakeTimer=null,!this.disposed&&(this.closePort(),this.options.onTeardown?.(`handshake-timeout`))},e)}connect(e){this.closePort(),this.rejectPending(`Connection reset`),this.lastSent.clear();let t=[...this.sticky.values()],n=new MessageChannel;this.port=n.port1,this.port.onmessage=e=>this.receive(e.data),this.port.start(),this.clearHandshakeTimer(),this.options.iframe.contentWindow?.postMessage({type:`init`,protocolVersion:4,sessionKey:this.options.sessionKey},this.options.iframeOrigin,[n.port2]);for(let e of t)this.sendState(e);let r=this.outbound;this.outbound=[];for(let e of r)this.port.postMessage(e);this.options.onConnect?.({signalsRendered:e})}closePort(){this.port&&=(this.port.onmessage=null,this.port.close(),null)}clearHandshakeTimer(){this.handshakeTimer!==null&&(clearTimeout(this.handshakeTimer),this.handshakeTimer=null)}rejectPending(e){for(let{reject:t}of this.pending.values())t(Error(e));this.pending.clear()}receive(e){if(e&&typeof e.type==`string`){switch(e.type){case`pong`:this.clearHandshakeTimer();return;case`rendered`:this.options.onRendered?.();return;case`refreshAssetAuth:response`:{let{requestId:t,ok:n,error:r}=e;if(typeof t!=`string`)return;let i=this.pending.get(t);this.pending.delete(t),n?i?.resolve():i?.reject(Error(r??`Asset auth refresh failed`));return}}SN.has(e.type)?this.answer(e):this.options.onMessage?.(e)}}async answer(e){let t=e.requestId;if(typeof t!=`string`){this.logger.warn(`[${this.options.uiIdentifier}] dropped a "${e.type}" with no requestId`);return}let n=`${e.type}:response`;try{let r=await this.dispatch(e);this.send({type:n,requestId:t,ok:!0,...r})}catch(r){this.send(e.type===`callEndpoint`?{type:n,requestId:t,ok:!1,...TN(r)}:{type:n,requestId:t,ok:!1,error:r instanceof Error?r.message:String(r)})}}async dispatch(e){let t=this.options.adapter,n={uiIdentifier:this.options.uiIdentifier,...this.options.origin};switch(e.type){case`callEndpoint`:if(!t?.callEndpoint)throw Error(`This host serves no endpoints`);return{response:await t.callEndpoint({endpointIdentifier:String(e.endpointIdentifier),request:e.request},n)};case`uploadBlob`:if(!t?.uploadBlob)throw Error(`This host stores no blobs`);return{reference:await t.uploadBlob({data:e.data,name:String(e.name),mimeType:String(e.mimeType)},n)};case`getPastState`:if(!t?.getPastState)throw Error(`This host serves no past state`);return{entries:await t.getPastState(e.query,n)};case`getAllTeamsParticipants`:return{participants:await t?.getAllTeamsParticipants?.(n)??[]};default:throw Error(`Unroutable request "${e.type}"`)}}};function wN(e){return typeof e!=`object`||!e?JSON.stringify(e)??`undefined`:Array.isArray(e)?`[${e.map(wN).join(`,`)}]`:`{${Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e<t?-1:+(e>t)).map(([e,t])=>`${JSON.stringify(e)}:${wN(t)}`).join(`,`)}}`}function TN(e){let t=typeof e==`object`&&e?e.failure:void 0;return typeof t==`object`&&t&&typeof t.outcome?.kind==`string`&&Array.isArray(t.applied)?t:{outcome:{kind:`error`,message:e instanceof Error?e.message:String(e)},applied:[]}}var EN=[`primary`,`secondary`,`success`,`error`,`warning`,`info`];function DN(e){let t=e.trim().toLowerCase(),n=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.exec(t);if(n){let e=n[1];e.length<=4&&(e=[...e].map(e=>e+e).join(``));let t=t=>parseInt(e.slice(t,t+2),16);return{r:t(0),g:t(2),b:t(4),a:e.length===8?t(6)/255:1}}let r=/^rgba?\(([^)]*)\)$/.exec(t);if(r){let e=r[1].split(/[\s,/]+/).filter(Boolean);if(e.length!==3&&e.length!==4)return null;let[t,n,i]=e.slice(0,3).map(e=>e.endsWith(`%`)?parseFloat(e)/100*255:parseFloat(e)),a=e[3],o=a===void 0?1:a.endsWith(`%`)?parseFloat(a)/100:parseFloat(a);return[t,n,i,o].some(e=>!Number.isFinite(e))?null:{r:ON(t,255),g:ON(n,255),b:ON(i,255),a:ON(o,1)}}return null}function ON(e,t){return Math.min(t,Math.max(0,e))}function kN(e,t){let n=(t,n)=>t*e.a+n*(1-e.a);return{r:n(e.r,t.r),g:n(e.g,t.g),b:n(e.b,t.b),a:1}}function AN({r:e,g:t,b:n}){let r=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return .2126*r(e)+.7152*r(t)+.0722*r(n)}function jN(e,t){let[n,r]=[AN(e),AN(t)].sort((e,t)=>t-e);return(n+.05)/(r+.05)}function MN({r:e,g:t,b:n}){let r=e=>Math.round(e).toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}var NN={r:0,g:0,b:0,a:1},PN={r:255,g:255,b:255,a:1};function FN(e,t){let n=DN(e);if(!n)return MN(NN);let r=n.a<1?kN(n,PN):n,i=t===void 0?null:DN(t);if(i){let e=kN(i,r);if(jN(e,r)>=4.5)return MN(e)}return jN(NN,r)>=jN(PN,r)?MN(NN):MN(PN)}var IN={light:{background:`#ffffff`,surface:`#ffffff`,text:`#000000`},dark:{background:`#121212`,surface:`#1e1e1e`,text:`#ffffff`}};function LN(e){let{background:t,surface:n,text:r}=e;if(!t||!n)return;let i=DN(t),a=DN(n);if(!i||!a)return;let o=e=>e.a<1?kN(e,PN):e,s=[o(i),o(a)],c=e=>Math.min(...s.map(t=>jN(kN(e,t),t))),l=r===void 0?null:DN(r);if(l&&l.a===1&&c(l)>=4.5)return{background:t,surface:n,text:MN(l)};let u=c(NN)>=c(PN)?NN:PN;if(!(c(u)<4.5))return{background:t,surface:n,text:MN(u)}}function RN(e,t){let n=Object.fromEntries(EN.map(t=>[t,FN(e[t],e.contrastText?.[t])]));return{...Object.fromEntries(EN.map(t=>[t,e[t]])),contrastText:n,...LN(e)??IN[t]}}function zN(e){return{mode:e.mode,light:RN(e.light,`light`),dark:RN(e.dark,`dark`),brand:e.brand}}var BN={primary:{main:`#6B00FF`,contrastText:`#ffffff`},secondary:{main:`#17D1C7`,contrastText:`rgba(0,0,0,0.87)`},error:{main:`#DB324D`,contrastText:`#ffffff`},success:{main:`#00c894`,contrastText:`rgba(0,0,0,0.87)`},warning:{main:`#ffb65c`,contrastText:`rgba(0,0,0,0.87)`},info:{main:`#336BEB`,contrastText:`#ffffff`}},VN={primary:{main:`#BC8CFF`,contrastText:`rgba(0,0,0,0.87)`},secondary:{main:`#17D1C7`,contrastText:`rgba(0,0,0,0.87)`},error:{main:`#ef7a8e`,contrastText:`rgba(0,0,0,0.87)`},success:{main:`#00c894`,contrastText:`rgba(0,0,0,0.87)`},warning:{main:`#ffb65c`,contrastText:`rgba(0,0,0,0.87)`},info:{main:`#7d9bf2`,contrastText:`rgba(0,0,0,0.87)`}},HN=`#414042`,UN=`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif`,WN=`"Work Sans", ${UN}`,GN=`Sora, ${UN}`;function KN(e){return{primary:e.primary.main,secondary:e.secondary.main,success:e.success.main,error:e.error.main,warning:e.warning.main,info:e.info.main,contrastText:{primary:e.primary.contrastText,secondary:e.secondary.contrastText,success:e.success.contrastText,error:e.error.contrastText,warning:e.warning.contrastText,info:e.info.contrastText}}}function qN(e,t){return zN(t?{mode:e,...t.theme}:{mode:e,light:KN(BN),dark:KN(VN),brand:{name:`Serious Gaming`}})}var JN=[`h1`,`h2`,`h3`,`h4`,`h5`,`h6`];function YN(e){return Xo({palette:e===`dark`?{mode:`dark`,...VN}:{mode:`light`,...BN,text:{primary:HN}},typography:{fontFamily:WN,...Object.fromEntries(JN.map(e=>[e,{fontFamily:GN}]))},components:{MuiButton:{styleOverrides:{root:{textTransform:`none`}}}}})}function XN(e){return e===`system`?window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:e}function ZN(e,t){return{"Content-Type":e.mimeType,"X-Blob-Name":encodeURIComponent(e.name),"X-Blob-Mime":e.mimeType,"X-Blob-Retention":t===`setup`?`settings`:t===`scenario-editor`?`scenario`:`game`}}var QN=5e3,$N=[`allow-scripts`,`allow-same-origin`,`allow-forms`,`allow-downloads`,`allow-modals`,`allow-presentation`,`allow-popups`,`allow-popups-to-escape-sandbox`].join(` `),eP=[`clipboard-write`,`autoplay`,`screen-wake-lock`,`fullscreen`,`microphone`,`camera`,`geolocation`,`picture-in-picture`,`web-share`,`gamepad`,`window-management`,`speaker-selection`].join(`; `);function tP(e){return Object.assign(Error(e.outcome.message??e.outcome.kind),{failure:e})}function nP(e,t,n){return async r=>{let i=yN(r,e,t)??vN(r,e,t);return _N(i)?{ok:!1,outcome:{kind:`denied`,message:i.refused}}:i?n(i):null}}function rP(e,t,n){return JSON.stringify([e.kind,e.identifier,t.observer??null,t.teamIndex??null,t.participantId??null,t.role??null,n])}function iP({surface:e,viewer:t,feed:n,mode:r,resolved:i,onModeChange:a,rejection:o,hookFailure:s,onTeardown:c}){let l=n.kind===`view`?n.dispatch:nP(e,t,n.send),u=e.origin??window.location.origin,d=(0,E.useRef)(null),f=(0,E.useRef)(null),p=cP(n),m=(0,E.useRef)({dispatch:l,onModeChange:a,overlays:p});m.current={dispatch:l,onModeChange:a,overlays:p};let[h,g]=(0,E.useState)(!1),[_,v]=(0,E.useState)(!1),[y,b]=(0,E.useState)(!1),[x,S]=(0,E.useState)(!1),{selected:C}=vb(),{hold:w}=Tb(),T=n.kind===`view`?n.sessionKey:Xc(n.state,e,{sessionless:n.sessionless===!0});return(0,E.useEffect)(()=>{let n=d.current;if(!n)return;let r;return r=new CN({iframe:n,surface:e.kind,uiIdentifier:e.identifier,iframeOrigin:u,sessionKey:T,adapter:{callEndpoint:async({endpointIdentifier:e,request:t})=>{let n=await m.current.dispatch({type:`callEndpoint`,endpointIdentifier:e,request:t});if(n&&`type`in n){if(n.type===`endpoint`)return n.response;if(n.type===`endpointFailure`)throw tP(n.failure)}throw tP({outcome:n&&`ok`in n&&!n.ok?n.outcome:{kind:`error`,message:`The endpoint did not answer`},applied:[]})},uploadBlob:async t=>{let n=await(await fetch(`/api/blobs`,{method:`POST`,headers:ZN(t,e.kind),body:t.data})).json();if(!n.reference)throw Error(`The blob was not stored`);return n.reference},getPastState:async e=>{let t=await m.current.dispatch({type:`getPastState`,query:e});return t&&`type`in t&&t.type===`pastState`?t.entries:[]},getAllTeamsParticipants:async()=>{let e=await m.current.dispatch({type:`getAllTeamsParticipants`});return e&&`type`in e&&e.type===`participants`?e.participants:[]}},observer:t.observer===!0,onConnect:({signalsRendered:e})=>{g(!0),v(!e),b(!e),S(!1)},onRendered:()=>{v(!0),b(!0)},onTeardown:e=>{e===`handshake-timeout`&&(g(!1),S(!0),c?.())},onMessage:e=>{e.type===`setThemePreference`?m.current.onModeChange?.(e.preference):oP(r,e,m.current.dispatch,m.current.overlays)}}),f.current=r,()=>{r.dispose(),f.current=null,g(!1),v(!1),b(!1)}},[e.identifier,e.kind,t.observer,t.teamIndex,t.participantId,t.role,T,w]),(0,E.useEffect)(()=>{let a=f.current;if(!a)return;let o={mode:i,preference:r,palette:qN(i,C)},s=n.kind===`view`?[...n.messages,...Zc(o)]:nl({surface:e,state:n.state,viewer:t,theme:o,origin:window.location.origin,assetOrigin:u,gameName:n.state.game.name,...n.overlays===void 0?{}:{overlays:n.overlays},...n.roundProcessing===void 0?{}:{roundProcessing:n.roundProcessing},...n.sessionless===void 0?{}:{sessionless:n.sessionless}});if(w===`surface`)for(let e of xb(s,w))a.sendIfChanged(e);else if(a.connected)for(let e of s)a.sendIfChanged(e);else a.sendInitialBatch(s)},[e,n,t,r,i,u,C,w]),(0,E.useEffect)(()=>{if(!h||_||w===`host`)return;let e=setTimeout(()=>v(!0),QN);return()=>clearTimeout(e)},[h,_,w]),(0,E.useEffect)(()=>{let e=f.current;e&&o&&(o.teamIndex===void 0||o.teamIndex===t.teamIndex)&&e.send({type:`validationRejected`,rejections:o.rejections})},[o?.nonce,o,t.teamIndex]),(0,E.useEffect)(()=>{let t=f.current;t&&s&&e.kind===`session`&&t.send({type:`hookFailed`,payload:s.payload})},[s?.nonce,s,e.kind]),(0,V.jsxs)(am,{"data-surface-state":x?`lost`:h?y?`rendered`:_?`unconfirmed`:`loading`:`loading`,sx:{position:`relative`,width:`100%`,height:`100%`},children:[(0,V.jsx)(am,{component:`iframe`,ref:d,title:e.identifier,src:`${u}${e.src}?expectedParentOrigin=${encodeURIComponent(window.location.origin)}`,sandbox:$N,allow:eP,sx:{width:`100%`,height:`100%`,border:0,display:`block`}},`${rP(e,t,T)}:${w}`),(!h||w===`host`||!_&&w!==`surface`)&&(0,V.jsx)(uy,{spacing:2,"data-testid":`surface-loading`,sx:{alignItems:`center`,justifyContent:`center`,position:`absolute`,inset:0,bgcolor:`background.default`},children:x?(0,V.jsx)(Z,{color:`text.secondary`,children:`This surface did not connect. Check its console for an error.`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(dP,{brand:C,resolved:i}),(0,V.jsxs)(Z,{color:`text.secondary`,variant:`body2`,children:[`Loading `,e.identifier]})]})})]})}function aP(e,t,n){return e!==`facilitator-guide`&&e!==`print-sheets`&&e!==`presentation`?`"${String(e)}" is not a host overlay`:n.available.includes(e)?e===`print-sheets`&&t!==void 0&&n.teamIds!==void 0&&!n.teamIds.includes(String(t))?`There is no team "${String(t)}" to print`:null:`This host does not offer the "${e}" overlay for this game`}async function oP(e,t,n,r={available:[`facilitator-guide`,`print-sheets`,`presentation`]}){if(t.type===`setThemePreference`)return;if(t.type===`openHostOverlay`){let n=aP(t.overlay,t.target,r);n||sP(t.overlay,t.target),lP(e,t,n?{ok:!1,outcome:{kind:`denied`,message:n}}:{ok:!0});return}let i;try{i=await n(t)}catch(e){i={ok:!1,outcome:{kind:`error`,message:e instanceof Error?e.message:`The command failed`}}}if(!i){lP(e,t,{ok:!1,outcome:{kind:`denied`,message:`This host does not handle "${String(t.type)}"`}});return}let a=typeof t.requestId==`string`?t.requestId:null;a&&(`ok`in i?e.send(i.ok?{type:`mutation:response`,requestId:a,ok:!0,...i.committedAtTick===void 0?{}:{committedAtTick:i.committedAtTick}}:{type:`mutation:response`,requestId:a,ok:!1,outcome:i.outcome}):e.send({type:`mutation:response`,requestId:a,ok:!0}))}function sP(e,t){if(e===`facilitator-guide`)return window.open(`/guide`,`_blank`,`noreferrer`),!0;if(e===`print-sheets`){let e=typeof t==`string`?`?team=${encodeURIComponent(t)}`:``;return window.open(`/print${e}`,`_blank`,`noreferrer`),!0}return e===`presentation`&&(window.open(`/presentation`,`_blank`,`noreferrer`),!0)}function cP(e){if(e.kind===`operator`)return{available:e.overlays??ll(),teamIds:e.state.teams.map(e=>e.teamId)};let t=e.messages.find(e=>e.type===`setAvailableOverlays`),n=e.messages.find(e=>e.type===`setTeamList`);return{available:Array.isArray(t?.overlays)?t.overlays:[],...Array.isArray(n?.payload)?{teamIds:n.payload.map(e=>e.teamId)}:{}}}function lP(e,t,n){typeof t.requestId==`string`&&e.send({type:`mutation:response`,requestId:t.requestId,...n})}function uP(e,t){return t===`dark`?e?.onDark??e?.onLight:e?.onLight??e?.onDark}function dP({brand:e,resolved:t}){let n=uP(e?.loader,t);if(n)return(0,V.jsx)(am,{component:`img`,src:n,alt:``,sx:{width:72,height:72}});let r=uP(e?.theme.brand?.logo,t),i=e?.theme[t].primary;return(0,V.jsxs)(V.Fragment,{children:[r&&(0,V.jsx)(am,{component:`img`,src:r,alt:e?.name??``,sx:{maxHeight:48,maxWidth:`min(320px, 80%)`,objectFit:`contain`}}),(0,V.jsx)(rd,{size:28,sx:i?{color:i}:void 0})]})}function fP({scenario:e,surface:t,state:n,mode:r,resolved:i,send:a,onModeChange:o,rejection:s}){let[c,l]=(0,E.useState)(!1),[u,d]=(0,E.useState)(!1),[f,p]=(0,E.useState)(null),m=e===``?null:e,h=n.scenarioDrafts?.some(e=>e.scenarioId===m)===!0,[g,_]=(0,E.useState)(null);(0,E.useEffect)(()=>{h||a({type:`editScenario`,scenarioId:m}).then(e=>{`ok`in e&&!e.ok&&_(e.outcome.message??`The scenario could not be opened`)})},[h,m,a]);let v=async()=>{l(!0),p(null);try{let t=await fetch(`/api/scenarios`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({identifier:e,overwrite:!0,draft:!0})});if(!t.ok){let e=await t.json();p(e.error??`The scenario could not be saved`);return}d(!0)}finally{l(!1)}};return(0,V.jsxs)(am,{sx:{display:`flex`,flexDirection:`column`,height:`100vh`},children:[(0,V.jsx)(jd,{position:`static`,color:`default`,elevation:1,children:(0,V.jsxs)(yy,{variant:`dense`,sx:{gap:2},children:[(0,V.jsxs)(uy,{sx:{flex:1},children:[(0,V.jsx)(Z,{variant:`subtitle2`,children:`Editing scenario`}),(0,V.jsx)(Z,{variant:`caption`,color:`text.secondary`,children:e})]}),u&&!f&&(0,V.jsx)(Z,{variant:`body2`,color:`success.main`,children:`Saved`}),(0,V.jsx)(_m,{variant:`contained`,"data-testid":`save-scenario`,disabled:c,onClick:()=>void v(),children:`Save`}),(0,V.jsx)(_m,{href:`/`,children:`Done`})]})}),(f??g)&&(0,V.jsx)(xd,{severity:`error`,sx:{borderRadius:0},children:f??g}),(0,V.jsx)(am,{sx:{flex:1,minHeight:0,position:`relative`},children:h?t?(0,V.jsx)(iP,{surface:t,viewer:m===null?{}:{scenario:m},feed:{kind:`operator`,state:n,send:e=>(e.type===`updateScenarioDraft`&&d(!1),a(e))},mode:r,resolved:i,onModeChange:o,rejection:s}):(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100%`,p:4},children:[(0,V.jsxs)(xd,{severity:`info`,sx:{maxWidth:560},children:[(0,V.jsxs)(Z,{gutterBottom:!0,children:[`This game has no `,(0,V.jsx)(`strong`,{children:`scenario_editor`}),` slot.`]}),(0,V.jsxs)(Z,{variant:`body2`,color:`text.secondary`,children:[`A scenario editor is optional (§6.5). Without one there is nothing to author a scenario in here; the values can still be set with`,` `,(0,V.jsx)(`code`,{children:`sdk configure`}),` and captured from the Scenario tab, and an agent can edit a game's settings directly from their schemas.`]})]}),(0,V.jsx)(_m,{href:`/`,children:`Back to the session`})]}):(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100%`},children:[(0,V.jsx)(rd,{size:28}),(0,V.jsxs)(Z,{color:`text.secondary`,variant:`body2`,children:[`Opening `,e||`the package settings`]})]})})]})}var pP={processing:new Set,errors:[],rejection:null,hookFailure:null,reloads:0,restarted:null,restarts:0},mP=new Set([`bundles-reloaded`,`reinitialised-on-change`,`logic-reloaded`]),hP=new Set([`reinitialise`,`reconfigure`,`reset`,`selectScenario`]);function gP(e=`session`){let[t,n]=(0,E.useState)(null),[r,i]=(0,E.useState)(!1),[a,o]=(0,E.useState)(0),[s,c]=(0,E.useState)(pP),l=(0,E.useRef)(null),u=(0,E.useRef)(null),d=(0,E.useRef)(new Map),f=(0,E.useRef)(0);(0,E.useEffect)(()=>{let t=!1,r,a=()=>{let s=e===`walkthrough`?`?run=walkthrough`:``,f=new WebSocket(`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws${s}`);l.current=f,f.onopen=()=>{i(!0),o(0),u.current!==null&&f.send(JSON.stringify({presence:u.current}))},f.onclose=()=>{i(!1),o(e=>e+1),t||(r=setTimeout(a,1e3))},f.onmessage=e=>{let t=JSON.parse(e.data);t.type===`result`?(d.current.get(t.requestId)?.(t.result),d.current.delete(t.requestId)):_P(t,n,c)}};return a(),()=>{t=!0,clearTimeout(r),l.current?.close()}},[e]);let p=(0,E.useCallback)(e=>{let t=l.current;if(!t||t.readyState!==WebSocket.OPEN)return Promise.resolve({ok:!1,outcome:{kind:`error`,message:`Not connected to the session`}});let n=`console-${++f.current}`;return new Promise(r=>{d.current.set(n,r),t.send(JSON.stringify({requestId:n,command:e}))})},[]),m=(0,E.useCallback)(e=>{if(u.current===e)return;u.current=e;let t=l.current;t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify({presence:e}))},[]);return(0,E.useMemo)(()=>({state:t,connected:r,attempts:a,transients:s,send:p,announce:m}),[t,r,a,s,p,m])}function _P(e,t,n){switch(e.type){case`state`:t(e.state),mP.has(e.cause)&&n(t=>({...t,reloads:t.reloads+1,restarted:e.cause===`reinitialised-on-change`?{nonce:(t.restarted?.nonce??0)+1}:t.restarted})),hP.has(e.cause)&&n(e=>({...e,restarts:e.restarts+1}));return;case`round-processing`:n(t=>{let n=new Set(t.processing),r=e.teamIndex??-1;return e.processing?n.add(r):n.delete(r),{...t,processing:n}});return;case`error`:n(t=>({...t,errors:[...t.errors,`${e.source}: ${e.message}`],hookFailure:e.source.startsWith(`hook:`)?{payload:{signal:e.source.slice(5),teamId:e.teamId??``,message:e.message},nonce:(t.hookFailure?.nonce??0)+1}:t.hookFailure}));return;case`validation-rejected`:n(t=>({...t,rejection:{...e.teamIndex===void 0?{}:{teamIndex:e.teamIndex},rejections:e.rejections,nonce:(t.rejection?.nonce??0)+1}}));return}}function vP(){let[e,t]=(0,E.useState)(null),[n,r]=(0,E.useState)(!1),[i,a]=(0,E.useState)(0),[o,s]=(0,E.useState)(null),[c,l]=(0,E.useState)(null),u=(0,E.useRef)(null),d=(0,E.useRef)(new Map),f=(0,E.useRef)(0);(0,E.useEffect)(()=>{let e=!1,n,i=()=>{let o=encodeURIComponent(location.pathname+location.search),c=new WebSocket(`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws/view?page=${o}`);u.current=c,c.onopen=()=>{r(!0),a(0)},c.onclose=()=>{r(!1),a(e=>e+1),e||(n=setTimeout(i,1e3))},c.onmessage=e=>{let n=JSON.parse(e.data);switch(n.type){case`view`:(0,Ap.flushSync)(()=>t({page:n.page,messages:n.messages}));return;case`result`:d.current.get(n.requestId)?.(n.result),d.current.delete(n.requestId);return;case`validation-rejected`:s(e=>({rejections:n.rejections,nonce:(e?.nonce??0)+1}));return;case`hookFailed`:l(e=>({payload:n.payload,nonce:(e?.nonce??0)+1}));return}}};return i(),()=>{e=!0,clearTimeout(n),u.current?.close()}},[]);let p=(0,E.useCallback)(e=>{let t=u.current;if(!t||t.readyState!==WebSocket.OPEN)return Promise.resolve({ok:!1,outcome:{kind:`error`,message:`Not connected to the session`}});let n=`view-${++f.current}`;return new Promise(r=>{d.current.set(n,r),t.send(JSON.stringify({requestId:n,message:e}))})},[]);return(0,E.useMemo)(()=>({view:e,connected:n,attempts:i,rejection:o,hookFailure:c,dispatch:p}),[e,n,i,o,c,p])}function yP(e){let t=(0,E.useMemo)(()=>Uc(location.pathname,location.search),[]);return _l(t)?(0,V.jsx)(bP,{...e}):(0,V.jsx)(SP,{...e,route:t})}function bP({mode:e,resolved:t,onModeChange:n}){let{view:r,connected:i,attempts:a,rejection:o,hookFailure:s,dispatch:c}=vP();if(!r)return(0,V.jsx)(AP,{connected:i,attempts:a});let{page:l,messages:u}=r;switch(l.status){case`redirect`:return location.replace(l.href),(0,V.jsx)(AP,{connected:i,attempts:a});case`configuring`:return(0,V.jsx)(xP,{children:`The facilitator is setting the session up. This page opens when it starts.`});case`closed`:return(0,V.jsx)(xP,{children:`This session has already started, so its configuration is closed.`});case`join`:return(0,V.jsx)(aN,{team:l.team??void 0,bare:!0});case`no-such-team`:return(0,V.jsx)(jP,{resolution:{kind:`no-such-team`,teamIndex:l.teamIndex},bare:!0});case`no-such-participant`:return(0,V.jsx)(jP,{resolution:{kind:`no-such-participant`,teamIndex:l.teamIndex,slot:l.slot,held:l.held},bare:!0});case`missing-surface`:return(0,V.jsx)(MP,{kind:l.kind});case`surface`:return(0,V.jsxs)(am,{sx:{display:`flex`,flexDirection:`column`,height:`100vh`},children:[!i&&(0,V.jsx)(OP,{attempts:a}),l.inSetup&&l.surface.kind===`setup`&&(0,V.jsx)(jd,{position:`static`,color:`default`,elevation:1,children:(0,V.jsxs)(yy,{variant:`dense`,sx:{gap:2},children:[(0,V.jsx)(Z,{variant:`subtitle2`,sx:{flex:1},children:`Configure the session, then start it`}),(0,V.jsx)(_m,{variant:`contained`,"data-testid":`play`,onClick:()=>void c({type:`requestPlay`}),children:`Play`})]})}),(0,V.jsx)(am,{sx:{flex:1,minHeight:0,position:`relative`},children:(0,V.jsx)(iP,{surface:l.surface,viewer:l.viewer,feed:{kind:`view`,messages:u,dispatch:c,sessionKey:l.sessionKey},mode:e,resolved:t,onModeChange:n,rejection:o,hookFailure:s})})]})}}function xP({children:e}){return(0,V.jsx)(uy,{sx:{alignItems:`center`,justifyContent:`center`,height:`100vh`,p:4},children:(0,V.jsx)(xd,{severity:`info`,sx:{maxWidth:560},"data-testid":`view-notice`,children:(0,V.jsx)(Z,{children:e})})})}function SP({mode:e,resolved:t,onModeChange:n,route:r}){let{state:i,connected:a,attempts:o,transients:s,send:c,announce:l}=gP(r.run),[u,d]=(0,E.useState)(null),[f,p]=(0,E.useState)([`print-sheets`]);(0,E.useEffect)(()=>{fetch(`/api/surfaces`).then(e=>e.json()).then(d)},[s.reloads]);let[m,h]=(0,E.useState)([]);(0,E.useEffect)(()=>{fetch(`/api/session`).then(e=>e.json()).then(e=>h(e.warnings??[]))},[s.reloads,s.restarts]);let g=m.filter(e=>e.build),_=m.filter(e=>wP.has(e.code??``)),[v,y]=(0,E.useState)(!1);(0,E.useEffect)(()=>{s.restarted&&y(!0)},[s.restarted]),(0,E.useEffect)(()=>{fetch(`/api/overlays`).then(e=>e.json()).then(e=>p(e.overlays))},[s.reloads]);let b=i&&r.kind===`player`?(()=>{let e=ml(i,r);return e.kind===`viewer`?e.viewer.participantId??null:null})():null;if((0,E.useEffect)(()=>l(b),[l,b]),!i||!u)return(0,V.jsx)(AP,{connected:a,attempts:o});let x=u.some(e=>e.kind===`setup`),S=i.session.inSetup,C=r.kind===`guide`||r.kind===`print`||r.kind===`scenario-editor`||r.kind===`presentation`,w=S&&!C?{...r,kind:`setup`}:r;if(!S&&w.kind===`setup`)return(0,V.jsx)(DP,{configurable:x,onReconfigure:()=>void c({type:`reconfigure`})});if(w.kind===`scenario-editor`)return w.scenario===void 0?(0,V.jsx)(kP,{}):(0,V.jsx)(fP,{scenario:w.scenario,surface:u.find(e=>e.kind===`scenario-editor`),state:i,mode:e,resolved:t,send:c,onModeChange:n,rejection:s.rejection});if(w.kind===`join`){let e=i.teams.find(e=>e.index===w.teamIndex);return e?.participants.length===1?(location.replace(Wc({kind:`player`,teamIndex:e.index,participant:1,bare:w.bare})),(0,V.jsx)(AP,{connected:a,attempts:o})):(0,V.jsx)(aN,{team:e,bare:w.bare})}let T=ml(i,w);if(T.kind!==`viewer`)return(0,V.jsx)(jP,{resolution:T,bare:w.bare,onAddParticipant:()=>void c({type:`addParticipant`,teamId:`team-${T.teamIndex+1}`})});let D=i.session.waitingRoomOpen&&(w.kind===`player`||w.kind===`waiting-room`)?`waiting-room`:hl[w.kind],O=D?u.find(e=>e.kind===D):void 0;return(0,V.jsxs)(am,{sx:{display:`flex`,flexDirection:`column`,height:`100vh`},children:[!a&&(0,V.jsx)(OP,{attempts:o}),Lc(i.session.pending)&&!w.bare&&(0,V.jsx)(CP,{pending:i.session.pending,onReinitialise:()=>void c({type:`reset`})}),g.length>0&&!w.bare&&(0,V.jsx)(TP,{errors:g}),_.length>0&&!w.bare&&(0,V.jsx)(EP,{notices:_}),S&&(0,V.jsx)(jd,{position:`static`,color:`default`,elevation:1,children:(0,V.jsxs)(yy,{variant:`dense`,sx:{gap:2},children:[(0,V.jsx)(Z,{variant:`subtitle2`,sx:{flex:1},children:`Configure the session, then start it`}),(0,V.jsx)(_m,{variant:`contained`,"data-testid":`play`,onClick:()=>void c({type:`play`}),children:`Play`})]})}),(0,V.jsx)(am,{sx:{flex:1,minHeight:0,position:`relative`},children:w.kind===`guide`?(0,V.jsx)(iN,{locale:i.session.locale,reloads:s.reloads}):w.kind===`print`?(0,V.jsx)(sN,{state:i}):O?(0,V.jsx)(iP,{surface:O,viewer:T.viewer,feed:{kind:`operator`,state:i,overlays:f,...w.kind===`presentation`?{sessionless:w.preview===!0}:{},roundProcessing:s.processing.has(-1)||T.viewer.teamIndex!==void 0&&s.processing.has(T.viewer.teamIndex),send:c},mode:e,resolved:t,onModeChange:n,rejection:s.rejection,hookFailure:s.hookFailure}):(0,V.jsx)(MP,{kind:D??`session`})}),!w.bare&&(0,V.jsx)(Db,{state:i,route:w,inSetup:S,configurable:x,connected:a,transients:s,mode:e,onModeChange:n,send:c}),(0,V.jsx)(Zv,{open:v,autoHideDuration:4e3,onClose:()=>y(!1),anchorOrigin:{vertical:`top`,horizontal:`center`},children:(0,V.jsx)(xd,{severity:`info`,"data-testid":`restarted-notice`,children:`Settings changed, game restarted`})})]})}function CP({pending:e,onReinitialise:t}){return(0,V.jsxs)(xd,{severity:`warning`,square:!0,"data-testid":`pending-changes`,sx:{borderRadius:0,py:.25},action:(0,V.jsx)(_m,{size:`small`,color:`inherit`,"data-testid":`reinitialise`,onClick:t,children:`Re-initialise`}),children:[(0,V.jsx)(`strong`,{children:Rc(e)}),`. `,zc(e),`. Re-initialising returns play to tick 0.`]})}var wP=new Set([`RELOAD_FAILED`,`CAPABILITY_SEEDED`]);function TP({errors:e}){return(0,V.jsxs)(xd,{severity:`error`,square:!0,"data-testid":`build-errors`,sx:{borderRadius:0,py:.25},children:[(0,V.jsxs)(`strong`,{children:["`sdk build` would refuse this package (",e.length===1?`one error`:`${e.length} errors`,`)`]}),`. It runs here anyway, so it can be fixed while you watch.`,e.map((e,t)=>(0,V.jsx)(Z,{variant:`body2`,sx:{fontFamily:`monospace`},children:e.message},t))]})}function EP({notices:e}){return(0,V.jsx)(xd,{severity:`warning`,square:!0,"data-testid":`package-notices`,sx:{borderRadius:0,py:.25},children:e.map((e,t)=>(0,V.jsx)(Z,{variant:`body2`,children:e.message},t))})}function DP({configurable:e,onReconfigure:t}){return(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100vh`,p:4},children:[(0,V.jsxs)(xd,{severity:`info`,sx:{maxWidth:560},children:[(0,V.jsx)(Z,{gutterBottom:!0,children:`This session has already started.`}),(0,V.jsx)(Z,{variant:`body2`,color:`text.secondary`,children:e?`Settings are resolved when a session initialises, so changing them now would change nothing until the session starts again. Reconfiguring puts the session back to its setup step and returns every team to tick 0.`:`This game has no setup step.`})]}),(0,V.jsxs)(uy,{direction:`row`,spacing:1,children:[e&&(0,V.jsx)(_m,{variant:`contained`,"data-testid":`reconfigure`,onClick:t,children:`Reconfigure`}),(0,V.jsx)(_m,{href:`/`,children:`Back to the session`})]})]})}function OP({attempts:e}){return(0,V.jsxs)(xd,{severity:`warning`,square:!0,"data-testid":`disconnected`,sx:{borderRadius:0,py:.25},action:(0,V.jsx)(_m,{size:`small`,color:`inherit`,onClick:()=>location.reload(),children:`Reload`}),children:[`Disconnected from the session — nothing on this page is live.`,e>1?` Retrying (${e}).`:` Retrying…`]})}function kP(){return(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100vh`,p:4},children:[(0,V.jsxs)(xd,{severity:`info`,sx:{maxWidth:560},children:[(0,V.jsx)(Z,{gutterBottom:!0,children:`The scenario editor opens on a scenario.`}),(0,V.jsxs)(Z,{variant:`body2`,color:`text.secondary`,children:[`Open the dev drawer (press `,(0,V.jsx)(`kbd`,{children:"`"}),`) and use the Scenario tab:`,` `,(0,V.jsx)(`strong`,{children:`Add scenario`}),` to start a new one, or `,(0,V.jsx)(`strong`,{children:`Edit`}),` on an existing one. An editor with no scenario behind it has nowhere to save what you do in it.`]})]}),(0,V.jsx)(_m,{href:`/`,children:`Back to the session`})]})}function AP({connected:e,attempts:t}){let n=!e&&t>=2,r=$o().palette.mode===`dark`;return(0,V.jsxs)(uy,{spacing:2,"data-testid":`console-loading`,sx:{alignItems:`center`,justifyContent:`center`,height:`100vh`,p:4},children:[(0,V.jsx)(am,{component:`img`,src:r?Jy:Yy,alt:`Serious Gaming`,sx:{width:72,height:72}}),!n&&(0,V.jsx)(Z,{color:`text.secondary`,children:e?`Loading the session…`:`Connecting to the session…`}),n&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(xd,{severity:`warning`,sx:{maxWidth:620},children:[(0,V.jsxs)(Z,{gutterBottom:!0,children:[`Nothing is answering at`,` `,(0,V.jsxs)(`code`,{children:[location.host,`/ws`]}),`.`]}),(0,V.jsxs)(Z,{variant:`body2`,color:`text.secondary`,component:`div`,children:[`This page loaded, so something is serving it — most likely an older dev server still holding this port. Check two things:`,(0,V.jsxs)(`ul`,{style:{marginBottom:0},children:[(0,V.jsxs)(`li`,{children:[`The address your server actually printed.`,location.port&&(0,V.jsxs)(V.Fragment,{children:[` `,`A port already in use makes it move to the next one, so it may be on `,(0,V.jsx)(`code`,{children:Number(location.port)+1})]})]}),(0,V.jsxs)(`li`,{children:[`Whether an old one is still running:`,` `,(0,V.jsx)(`code`,{children:`pnpm run sdk dev status`}),`, and`,` `,(0,V.jsx)(`code`,{children:`pnpm run sdk dev stop`}),` to end it`]})]})]})]}),(0,V.jsx)(_m,{variant:`outlined`,onClick:()=>location.reload(),children:`Try again`})]})]})}function jP({resolution:e,bare:t,onAddParticipant:n}){let r=e.teamIndex+1;return(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100vh`,p:4},"data-testid":`no-such-participant`,children:[(0,V.jsx)(xd,{severity:`warning`,sx:{maxWidth:560},children:e.kind===`no-such-team`?(0,V.jsxs)(Z,{gutterBottom:!0,children:[`This session has no team `,r,`. It may have been removed.`]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(Z,{gutterBottom:!0,children:[`Team `,r,` has`,` `,e.held===0?`no participants`:e.held===1?`one participant`:`${e.held} participants`,`, and this URL asks for participant `,e.slot,`.`]}),(0,V.jsx)(Z,{variant:`body2`,color:`text.secondary`,children:`A second tab is not a second participant. Add one, then open their surface: a participant is who a write is attributed to, and a surface with nobody behind it cannot submit one.`})]})}),e.kind===`no-such-participant`&&n&&(0,V.jsx)(_m,{variant:`contained`,onClick:n,"data-testid":`add-participant`,children:`Add participant`}),(0,V.jsxs)(_m,{size:`small`,href:Wc({kind:`observer`,teamIndex:e.teamIndex,bare:t}),children:[`Watch team `,r,` without joining`]})]})}function MP({kind:e}){return(0,V.jsxs)(uy,{spacing:2,sx:{alignItems:`center`,justifyContent:`center`,height:`100%`,p:4},children:[(0,V.jsxs)(xd,{severity:`info`,sx:{maxWidth:560},children:[(0,V.jsxs)(Z,{gutterBottom:!0,children:[`This package wires no `,(0,V.jsx)(`strong`,{children:e}),` surface.`]}),(0,V.jsx)(Z,{variant:`body2`,color:`text.secondary`,children:`A game supplies its own facilitator and player surfaces; the dev server renders them rather than substituting a console of its own, so there is nothing to show until the package fills that slot.`})]}),(0,V.jsx)(_m,{href:`/`,size:`small`,children:`Back to the session`})]})}function NP(){let[e,t]=(0,E.useState)(()=>ob(location.search,rb(`sessionStorage`),rb(`localStorage`)));(0,E.useEffect)(()=>{if(window.parent===window)return;let e=e=>{if(e.source!==window.parent)return;let n=lb(e.data);n&&(sb(rb(`sessionStorage`),n),t(n))};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[]);let n=XN(e),r=(0,E.useMemo)(()=>YN(n),[n]);return(0,V.jsxs)(Ac,{theme:r,children:[(0,V.jsx)(ds,{}),(0,V.jsx)(_b,{children:(0,V.jsx)(wb,{children:(0,V.jsx)(yP,{mode:e,resolved:n,onModeChange:e=>{cb(rb(`sessionStorage`),rb(`localStorage`),e),t(e)}})})})]})}(0,Ic.createRoot)(document.getElementById(`root`)).render((0,V.jsx)(E.StrictMode,{children:(0,V.jsx)(NP,{})}));
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <link rel="icon" type="image/svg+xml" href="/assets/icon-CRaj5uhr.svg" />
7
7
  <title>Serious Gaming</title>
8
- <script type="module" crossorigin src="/assets/index-BVF8exas.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-CuMOOH9m.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-q6-lvlN3.css">
10
10
  </head>
11
11
  <body>
@@ -60,6 +60,19 @@ export interface ShellOptions extends SessionOptions, PublicOrigins {
60
60
  * starts, so a broken one fails the start rather than the page.
61
61
  */
62
62
  brandFiles?: string[];
63
+ /**
64
+ * Whether surfaces show Vite's full-screen error overlay. Unset leaves it
65
+ * to the package's own Vite config, which shows it by default (#807).
66
+ */
67
+ errorOverlay?: boolean;
68
+ /**
69
+ * A directory of surfaces already built, laid out as `sdk build` lays out
70
+ * `dist/` (`ui/`, `session/`, ...). Surfaces are served from it as static
71
+ * files and Vite is never started, so a page loads at once and an edit to
72
+ * a surface's source is not seen. For browser test runs, where every
73
+ * worker's server would otherwise compile the same surfaces again.
74
+ */
75
+ builtSurfaces?: string;
63
76
  }
64
77
  /**
65
78
  * Something the server could not apply live, kept until it no longer holds so
@@ -230,6 +243,12 @@ export declare class DevShell {
230
243
  * reads, all under the bundle policy and nothing under `/api`.
231
244
  */
232
245
  private configureAssets;
246
+ /**
247
+ * Each surface from its built directory, which `sdk build` gives relative
248
+ * asset paths, so the document and everything it loads resolve under the
249
+ * route the console already mounts it at.
250
+ */
251
+ private serveBuiltSurfaces;
233
252
  /**
234
253
  * Vite, started the first time something asks for a surface (#320).
235
254
  *
@@ -37,5 +37,12 @@ export interface MountableSurface {
37
37
  */
38
38
  settings: string[];
39
39
  }
40
+ /** URL prefix each surface kind is served under. */
41
+ export declare const SURFACE_PREFIX: Record<SurfaceKind, string>;
42
+ /**
43
+ * The slot each surface kind fills, which is both its identifier and where
44
+ * `sdk build` writes it inside `dist/`.
45
+ */
46
+ export declare const SURFACE_SLOT: Record<SurfaceKind, string>;
40
47
  /** Every surface this package can mount: one per slot it fills. */
41
48
  export declare function mountableSurfaces(config: ResolvedPackageManifest | null): MountableSurface[];
@@ -34,7 +34,7 @@ mkdir my-game && cd my-game
34
34
  pnpm dlx @seriousgaming/sdk-tools new package '{"identifier":"com.example.mygame","name":"My Game","version":"0.1.0"}'
35
35
  ```
36
36
 
37
- You get the starter game, a complete lemonade stand, with tests at every level, a `CLAUDE.md`, and `.claude/rules/`. Read `CLAUDE.md` before changing anything: it holds the rules that are expensive to get wrong. Pass `--empty` for the package files and the agent guidance alone.
37
+ You get the starter game, a complete lemonade stand, with tests at every level, a `CLAUDE.md`, and `.claude/rules/`. Read `CLAUDE.md` before changing anything. Its first line imports the SDK's guidance, the rules that are expensive to get wrong, from `node_modules/@seriousgaming/sdk-tools/dist/agent/guidance.md`, so it describes the installed version; the rest of the file is the package's own, for what this game is. Pass `--empty` for the package files and the agent guidance alone.
38
38
 
39
39
  Without a terminal, the CLI never prompts: a command that would ask fails with `PROMPT_REQUIRED` and exit code 2. Every `new` and `update` takes its definition as an argument, with `--file`, or on stdin, and `delete` takes `--yes`.
40
40
 
@@ -4,17 +4,18 @@
4
4
 
5
5
  Every type, function, hook and component your game imports, one page per entry point. Each page is generated from the published declarations and their documentation, so it always matches the release it ships in.
6
6
 
7
- | Entry point | Exports |
8
- | ---------------------------------------------------------- | -------------------------------------------------------------- |
9
- | [`@seriousgaming/sdk`](./sdk.md) | 12 functions, 3 classes, 1 constant, 100 interfaces, 48 types |
10
- | [`@seriousgaming/sdk/ui`](./sdk-ui.md) | 49 functions, 3 classes, 39 constants, 26 interfaces, 37 types |
11
- | [`@seriousgaming/sdk/ui/testing`](./sdk-ui-testing.md) | 14 functions, 6 types |
12
- | [`@seriousgaming/sdk/testing`](./sdk-testing.md) | 8 functions, 4 constants, 8 types |
13
- | [`@seriousgaming/sdk/projection`](./sdk-projection.md) | 1 constant, 8 interfaces, 3 types |
14
- | [`@seriousgaming/sdk/commands`](./sdk-commands.md) | 3 interfaces, 5 types |
15
- | [`@seriousgaming/sdk/e2e`](./sdk-e2e.md) | 6 functions, 1 constant, 4 interfaces, 5 types |
16
- | [`@seriousgaming/deck`](./deck.md) | 16 functions, 5 constants, 15 interfaces, 4 types |
17
- | [`@seriousgaming/sdk-tools/client`](./sdk-tools-client.md) | 4 functions, 1 class, 10 interfaces, 11 types |
7
+ | Entry point | Exports |
8
+ | ------------------------------------------------------------------ | -------------------------------------------------------------- |
9
+ | [`@seriousgaming/sdk`](./sdk.md) | 12 functions, 3 classes, 1 constant, 100 interfaces, 48 types |
10
+ | [`@seriousgaming/sdk/ui`](./sdk-ui.md) | 49 functions, 3 classes, 39 constants, 26 interfaces, 37 types |
11
+ | [`@seriousgaming/sdk/ui/testing`](./sdk-ui-testing.md) | 14 functions, 6 types |
12
+ | [`@seriousgaming/sdk/testing`](./sdk-testing.md) | 8 functions, 4 constants, 8 types |
13
+ | [`@seriousgaming/sdk/projection`](./sdk-projection.md) | 1 constant, 8 interfaces, 3 types |
14
+ | [`@seriousgaming/sdk/commands`](./sdk-commands.md) | 3 interfaces, 5 types |
15
+ | [`@seriousgaming/sdk/e2e`](./sdk-e2e.md) | 6 functions, 1 constant, 4 interfaces, 5 types |
16
+ | [`@seriousgaming/deck`](./deck.md) | 16 functions, 5 constants, 15 interfaces, 4 types |
17
+ | [`@seriousgaming/sdk-tools/client`](./sdk-tools-client.md) | 5 functions, 1 class, 12 interfaces, 11 types |
18
+ | [`@seriousgaming/sdk-tools/playwright`](./sdk-tools-playwright.md) | 1 function, 3 constants, 2 interfaces, 1 type |
18
19
 
19
20
  ## Which entry point to import from
20
21
 
@@ -24,7 +25,8 @@ Every type, function, hook and component your game imports, one page per entry p
24
25
  - **`@seriousgaming/sdk/ui/testing`**: the harness for component-testing a surface
25
26
  - **`@seriousgaming/sdk/e2e`**: the browser-test driver for a running dev server
26
27
  - **`@seriousgaming/sdk/commands`** and **`@seriousgaming/sdk/projection`**: the commands a client may send a session, and the shape of the state it reads back (`sdk view --json` and the dev server's `/api/state`)
27
- - **`@seriousgaming/sdk-tools/client`**: `createTestSession`, which plays a whole game in-process, and `startDevServer`, which starts an isolated dev server for browser tests
28
+ - **`@seriousgaming/sdk-tools/client`**: `createTestSession`, which plays a whole game in-process, `startDevServer`, which starts an isolated dev server for browser tests, and `buildSurfaces`, which builds a game's surfaces for those servers to serve
29
+ - **`@seriousgaming/sdk-tools/playwright`**: the Playwright `test` that starts a dev server for each worker, and the `globalSetup` that builds the surfaces they serve
28
30
  - **`@seriousgaming/deck`**: the slide components and layout primitives a presentation is built from
29
31
 
30
32
  `@seriousgaming/sdk-tools` also exports `/host` and `/runtime`. They are for people building a runtime that hosts games, not for game authors, their shapes may change in a minor release, and they are not documented here.
@@ -26,6 +26,14 @@ Every export of `@seriousgaming/sdk-tools/client`, with the declaration it is pu
26
26
 
27
27
  ## Functions
28
28
 
29
+ ### buildSurfaces
30
+
31
+ Build every surface the package has, as `sdk build` builds them, and nothing else: no logic, no guide, no archive.
32
+
33
+ ```ts
34
+ function buildSurfaces(options: BuildSurfacesOptions): Promise<BuiltSurfaces>;
35
+ ```
36
+
29
37
  ### createStubServices
30
38
 
31
39
  The stubbed service callbacks: `generateText`, `generateSpeech` and `extractText`. Blob storage stays real, because it is local.
@@ -86,6 +94,26 @@ class FakeClock implements Clock {
86
94
 
87
95
  ## Interfaces
88
96
 
97
+ ### BuildSurfacesOptions
98
+
99
+ A package's surfaces built once, for every dev server of a test run (#808).
100
+
101
+ ```ts
102
+ interface BuildSurfacesOptions {
103
+ packagePath: string;
104
+ outDir?: string;
105
+ }
106
+ ```
107
+
108
+ ### BuiltSurfaces
109
+
110
+ ```ts
111
+ interface BuiltSurfaces {
112
+ directory: string;
113
+ remove(): Promise<void>;
114
+ }
115
+ ```
116
+
89
117
  ### Clock
90
118
 
91
119
  ```ts
@@ -118,6 +146,7 @@ interface DevServerOptions {
118
146
  clock?: Clock;
119
147
  callbacks?: Partial<SignatureCallbacks>;
120
148
  reinitOnChange?: boolean;
149
+ builtSurfaces?: string;
121
150
  }
122
151
  ```
123
152
 
@@ -0,0 +1,104 @@
1
+ <!-- Generated by `pnpm docs:generate` from the exports of `@seriousgaming/sdk-tools/playwright`. Edit those, not this file. -->
2
+
3
+ # `@seriousgaming/sdk-tools/playwright`
4
+
5
+ Playwright for a game's browser tests: a dev server for each worker.
6
+
7
+ A dev server holds one session, so a run against one server has to take its
8
+ tests one at a time. Each worker here starts its own isolated server, so the
9
+ tests of different workers never share a session and the run can be
10
+ parallel. Tests in one worker still share its server, one after another, so
11
+ each still states its own starting point (`reinitialiseSession()`).
12
+
13
+ @example
14
+
15
+ ```ts
16
+ // playwright.config.ts
17
+ export default defineConfig({
18
+ testDir: './testing/e2e',
19
+ globalSetup: './testing/e2e/global-setup.ts',
20
+ fullyParallel: true,
21
+ });
22
+
23
+ // testing/e2e/global-setup.ts
24
+ export { globalSetup as default } from '@seriousgaming/sdk-tools/playwright';
25
+
26
+ // testing/e2e/game.spec.ts
27
+ import { expect, test } from '@seriousgaming/sdk-tools/playwright';
28
+ ```
29
+
30
+ Every export of `@seriousgaming/sdk-tools/playwright`, with the declaration it is published with. Anything tagged `@internal` is left out: it ships in the declarations, but is not part of the supported API and may change without a major release. For how the pieces fit together, see the [API reference](./index.md) and the guides it links to.
31
+
32
+ ## Functions
33
+
34
+ ### globalSetup
35
+
36
+ A Playwright `globalSetup` that builds the package's surfaces once for the whole run, so every worker's server serves them as files rather than each compiling them through Vite. Removes the build when the run ends.
37
+
38
+ ```ts
39
+ function globalSetup(config: FullConfig): Promise<() => Promise<void>>;
40
+ ```
41
+
42
+ ## Constants
43
+
44
+ ### BUILT_SURFACES_ENV_VAR
45
+
46
+ Where `globalSetup` tells the workers it built the surfaces.
47
+
48
+ ```ts
49
+ const BUILT_SURFACES_ENV_VAR = 'SERIOUSGAMING_BUILT_SURFACES';
50
+ ```
51
+
52
+ ### expect
53
+
54
+ ```ts
55
+ const expect: Expect<{}>;
56
+ ```
57
+
58
+ ### test
59
+
60
+ Playwright's `test`, with an isolated dev server started for each worker.
61
+
62
+ ```ts
63
+ const test: import('@playwright/test').TestType<
64
+ import('@playwright/test').PlaywrightTestArgs &
65
+ import('@playwright/test').PlaywrightTestOptions &
66
+ object,
67
+ import('@playwright/test').PlaywrightWorkerArgs &
68
+ import('@playwright/test').PlaywrightWorkerOptions &
69
+ DevServerWorkerFixtures
70
+ >;
71
+ ```
72
+
73
+ ## Interfaces
74
+
75
+ ### DevServer
76
+
77
+ ```ts
78
+ interface DevServer {
79
+ url: string;
80
+ assetUrl: string;
81
+ stop(): Promise<void>;
82
+ }
83
+ ```
84
+
85
+ ### DevServerWorkerFixtures
86
+
87
+ ```ts
88
+ interface DevServerWorkerFixtures {
89
+ devServerOptions: DevServerFixtureOptions;
90
+ devServer: DevServer;
91
+ }
92
+ ```
93
+
94
+ ## Types
95
+
96
+ ### DevServerFixtureOptions
97
+
98
+ How each worker's server starts. The package is the config file's directory unless named.
99
+
100
+ ```ts
101
+ type DevServerFixtureOptions = Omit<DevServerOptions, 'packagePath' | 'builtSurfaces'> & {
102
+ packagePath?: string;
103
+ };
104
+ ```
@@ -31,6 +31,40 @@ are in the [0.x changelog](changelog-0.x.md).
31
31
 
32
32
  ## [Unreleased]
33
33
 
34
+ ## [1.6.1] — 2026-11-02
35
+
36
+ ### Changed
37
+
38
+ - **A new package's agent guidance no longer describes the starter game as the package.** The SDK's guidance (`guidance.md`, below; until now `CLAUDE.md.template`) replaces its 'This package' section with four patterns worth keeping in any game (keyed state, a validator on shared state, awaited writes, and a deliberate team mode), citing the starter as one worked example, and its command examples use placeholders such as `/<capability>/<variable>` in place of the starter's paths. The `workflow-create-engine.md`, `workflow-create-user-interface.md` and `workflow-create-guide.md` rules read the same way for a package that has since been reskinned. Merge the rules into an existing package's `.claude/rules/`, and import the guidance as below, so an agent stops being told a reskinned game is a lemonade stand
39
+ - **A package's `CLAUDE.md` imports the SDK's agent guidance instead of copying it.** The guidance ships in `@seriousgaming/sdk-tools` at `dist/agent/guidance.md`, so it always matches the installed version and updates when you upgrade. A new package's `CLAUDE.md` (`CLAUDE.md.template`) starts with `@node_modules/@seriousgaming/sdk-tools/dist/agent/guidance.md`, then a sentence naming that path for a tool that does not follow imports, then a section of its own for describing the game. `workflow-update-sdk-version.md` says the same. An existing package can replace its copied SDK text with the import, keeping what it wrote about the game; see [Import the SDK's agent guidance](guides/upgrading.md#optional-import-the-sdks-agent-guidance-in-claudemd)
40
+
41
+ ### Fixed
42
+
43
+ - **`new <type>` keeps every field you write.** It used to drop some fields from the written bundle without an error: an endpoint's `actions` and `roster`, a capability's `lifetime`, `endpoints` and `crossTeamParticipants` on the participant interface, `endpoints` on the session interface, `crossTeamParticipants` on the waiting room, and `settings` on the guide. A generated field the build derives from the code, a validator's `gates` or an endpoint's `responds`, is now refused rather than dropped. Interactive `update engine` also keeps the engine's `uses`. On an earlier version, add a dropped field after creating the resource with `pnpm run sdk update <type> <id> --patch '[...]'`
44
+
45
+ ### Security
46
+
47
+ - **The `body-parser` advisory is cleared.** The SDK's lockfile now takes `body-parser` 2.4.0 through `express` in the dev server, as 1.5.0 said the next release would. A game's own install already resolves it
48
+
49
+ ## [1.6.0] — 2026-11-02
50
+
51
+ ### Added
52
+
53
+ - **Browser tests run in parallel.** Import `test` from the new `@seriousgaming/sdk-tools/playwright` and each Playwright worker starts its own isolated dev server, so a suite no longer needs `workers: 1`. Its `globalSetup` builds the game's surfaces once for the run, and every worker's server serves that build instead of compiling the surfaces through Vite. New packages are set up this way, and an existing suite keeps working as it is. See [A dev server for browser tests](guides/testing.md#a-dev-server-for-browser-tests)
54
+ - **`sdk dev --built-surfaces <DIR>`** serves surfaces from a build, such as `dist/` after `sdk build`, instead of compiling them through Vite. `startDevServer` takes the same as `builtSurfaces`, and `buildSurfaces` from `@seriousgaming/sdk-tools/client` builds them into a temporary directory. See [Serve built surfaces](cli-reference.md#serve-built-surfaces)
55
+ - **`sdk dev --no-error-overlay`** hides Vite's full-screen error overlay over a surface that fails to build, for a preview watched by people who are not developers. `SERIOUSGAMING_DEV_ERROR_OVERLAY=false` does the same for a server a command starts. The error still reaches the server's log and the browser console. See [Hide the error overlay](cli-and-dev-server.md#hide-the-error-overlay)
56
+
57
+ ### Changed
58
+
59
+ - **A capability added to a running game gets its `Init` when nothing has been played yet.** At tick 0, or under `sdk dev --reinit-on-change`, the dev server now re-initialises the session so `Init` runs for the new capability, instead of seeding it with its schema defaults. Once play is under way it is still seeded, and the console now says so as well as the terminal. See [What reloads](cli-reference.md#what-reloads)
60
+ - **Designing a serious game covers more of the design.** The guide now suggests finding the one tension a game is built around, scoring the behaviour the aim teaches, keeping stuck and trailing teams in play, and recording what the debrief needs. It also suggests getting a game playing before balancing it, then balancing against outcomes written while designing
61
+ - **The CLI starts faster.** Each command now loads only what it uses, so a call such as `pnpm run sdk version` or `view` no longer loads Vite, Express and the template engine first, which cut its start-up time by about two thirds
62
+
63
+ ### Fixed
64
+
65
+ - **The dev server no longer exits when `Init` throws while an edit re-initialises the session.** It reports the error in its log and on the console and keeps serving, and the edit stays pending until the next edit or `sdk init` applies it. It used to stop, losing the session and leaving the preview unreachable
66
+ - **A dev server a command started in the background stops when its package is removed.** It used to run on with nothing to serve, holding its ports, after a scratch game or a test's temporary copy was deleted. A server you start yourself with `sdk dev` is unchanged
67
+
34
68
  ## [1.5.0] — 2026-10-29
35
69
 
36
70
  ### Added