castle-web-cli 0.4.239 → 0.4.241

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 (396) hide show
  1. package/dist/agent.js +5 -1
  2. package/dist/api.d.ts +20 -0
  3. package/dist/api.js +57 -0
  4. package/dist/bundle.d.ts +38 -1
  5. package/dist/bundle.js +309 -13
  6. package/dist/castle-host/host.js +163 -11
  7. package/dist/castleJson.d.ts +10 -0
  8. package/dist/castleJson.js +46 -2
  9. package/dist/check.js +5 -2
  10. package/dist/devSessionServer.js +4 -1
  11. package/dist/devSessionStorage.d.ts +1 -0
  12. package/dist/devSessionStorage.js +32 -7
  13. package/dist/importOrder.d.ts +2 -0
  14. package/dist/importOrder.js +29 -0
  15. package/dist/index.js +6 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +2 -0
  19. package/dist/platformDoc.js +3 -2
  20. package/dist/playPagePolicy.js +5 -1
  21. package/dist/resetLeaderboards.d.ts +8 -1
  22. package/dist/resetLeaderboards.js +43 -8
  23. package/dist/roomLogs.d.ts +1 -0
  24. package/dist/roomLogs.js +30 -6
  25. package/dist/save-deck.d.ts +32 -2
  26. package/dist/save-deck.js +240 -39
  27. package/kits/base/CLAUDE.md +1 -1
  28. package/kits/base/castle.json +1 -1
  29. package/kits/base/sdk/README.md +174 -6
  30. package/kits/base/sdk/analytics.d.ts +8 -0
  31. package/kits/base/sdk/analytics.js +92 -0
  32. package/kits/base/sdk/castle.d.ts +5 -1
  33. package/kits/base/sdk/castle.js +2 -0
  34. package/kits/base/sdk/commands.d.ts +48 -0
  35. package/kits/base/sdk/commands.js +1 -0
  36. package/kits/base/sdk/debugConsole.d.ts +17 -0
  37. package/kits/base/sdk/debugConsole.js +154 -0
  38. package/kits/base/sdk/experiments.js +24 -1
  39. package/kits/base/sdk/hostRetry.d.ts +7 -0
  40. package/kits/base/sdk/hostRetry.js +57 -0
  41. package/kits/base/sdk/hub.d.ts +20 -2
  42. package/kits/base/sdk/hub.js +99 -13
  43. package/kits/base/sdk/multiplayer.d.ts +2 -0
  44. package/kits/base/sdk/multiplayer.js +168 -26
  45. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  46. package/kits/base/sdk/reconnectBudget.js +41 -1
  47. package/kits/base/sdk/runtime.js +36 -19
  48. package/kits/base/sdk/server/hub.d.ts +19 -0
  49. package/kits/base/sdk/server/hub.js +12 -0
  50. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  51. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  52. package/kits/base/sdk/server/wrapper.js +26 -1
  53. package/kits/base/sdk/transport.d.ts +2 -1
  54. package/kits/base/sdk/transport.js +35 -0
  55. package/kits/hub-game/CLAUDE.md +66 -19
  56. package/kits/hub-game/code/client/act.js +9 -6
  57. package/kits/hub-game/code/client/actCore.js +26 -6
  58. package/kits/hub-game/code/client/actGateLog.js +36 -0
  59. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  60. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  61. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  62. package/kits/hub-game/code/client/askSurface.js +85 -0
  63. package/kits/hub-game/code/client/askTree.js +51 -0
  64. package/kits/hub-game/code/client/attention.js +31 -6
  65. package/kits/hub-game/code/client/ballot.js +42 -5
  66. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  67. package/kits/hub-game/code/client/ballotTree.js +180 -0
  68. package/kits/hub-game/code/client/catchingUp.js +19 -0
  69. package/kits/hub-game/code/client/celebrate.js +66 -0
  70. package/kits/hub-game/code/client/chrome.js +481 -57
  71. package/kits/hub-game/code/client/companion.js +93 -23
  72. package/kits/hub-game/code/client/companionDress.js +1 -1
  73. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  74. package/kits/hub-game/code/client/cornerTree.js +83 -0
  75. package/kits/hub-game/code/client/decor.js +20 -11
  76. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  77. package/kits/hub-game/code/client/disguise.js +23 -0
  78. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  79. package/kits/hub-game/code/client/dockSurface.js +206 -0
  80. package/kits/hub-game/code/client/dockTree.js +232 -0
  81. package/kits/hub-game/code/client/earned.js +29 -0
  82. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  83. package/kits/hub-game/code/client/emoteTree.js +264 -0
  84. package/kits/hub-game/code/client/farAvatars.js +4 -3
  85. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  86. package/kits/hub-game/code/client/grab.js +121 -50
  87. package/kits/hub-game/code/client/holdShow.js +19 -0
  88. package/kits/hub-game/code/client/hookLayer.js +96 -12
  89. package/kits/hub-game/code/client/hubControls.js +7 -1
  90. package/kits/hub-game/code/client/hudSurface.js +11 -3
  91. package/kits/hub-game/code/client/hudTree.js +7 -4
  92. package/kits/hub-game/code/client/idle.js +21 -3
  93. package/kits/hub-game/code/client/invites.js +24 -3
  94. package/kits/hub-game/code/client/keys.js +15 -0
  95. package/kits/hub-game/code/client/labelsNear.js +8 -1
  96. package/kits/hub-game/code/client/layoutCache.js +57 -8
  97. package/kits/hub-game/code/client/loadingCover.js +53 -4
  98. package/kits/hub-game/code/client/menuIcons.js +15 -0
  99. package/kits/hub-game/code/client/menuSurface.js +102 -0
  100. package/kits/hub-game/code/client/menuTree.js +135 -0
  101. package/kits/hub-game/code/client/modelLook.js +41 -0
  102. package/kits/hub-game/code/client/padCues.js +11 -7
  103. package/kits/hub-game/code/client/padReadability.js +3 -3
  104. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  105. package/kits/hub-game/code/client/pickerTree.js +163 -0
  106. package/kits/hub-game/code/client/pushVisit.js +4 -2
  107. package/kits/hub-game/code/client/quality.js +188 -29
  108. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  109. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  110. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  111. package/kits/hub-game/code/client/rehello.js +75 -0
  112. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  113. package/kits/hub-game/code/client/replay.js +118 -0
  114. package/kits/hub-game/code/client/role.js +3 -0
  115. package/kits/hub-game/code/client/safeLayout.js +441 -56
  116. package/kits/hub-game/code/client/safeStyle.js +13 -10
  117. package/kits/hub-game/code/client/say.js +2 -0
  118. package/kits/hub-game/code/client/soundSurface.js +77 -0
  119. package/kits/hub-game/code/client/soundTree.js +74 -0
  120. package/kits/hub-game/code/client/soundscape.js +12 -9
  121. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  122. package/kits/hub-game/code/client/state.js +67 -1
  123. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  124. package/kits/hub-game/code/client/stuckTree.js +67 -0
  125. package/kits/hub-game/code/client/talk.js +42 -12
  126. package/kits/hub-game/code/client/talkTree.js +4 -2
  127. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  128. package/kits/hub-game/code/client/textAskTree.js +67 -0
  129. package/kits/hub-game/code/client/tiers.js +252 -27
  130. package/kits/hub-game/code/client/together.js +4 -1
  131. package/kits/hub-game/code/client/uiDom.js +86 -8
  132. package/kits/hub-game/code/client/uiTree.js +33 -4
  133. package/kits/hub-game/code/client/vehicle.js +72 -51
  134. package/kits/hub-game/code/client/weakestTier.js +75 -31
  135. package/kits/hub-game/code/client/wear.js +159 -5
  136. package/kits/hub-game/code/client/worldLabels.js +205 -25
  137. package/kits/hub-game/code/companionSpec.js +4 -2
  138. package/kits/hub-game/code/server/act.js +3 -0
  139. package/kits/hub-game/code/server/actGate.js +83 -0
  140. package/kits/hub-game/code/server/actions.js +71 -15
  141. package/kits/hub-game/code/server/actors.js +20 -5
  142. package/kits/hub-game/code/server/analytics.js +35 -3
  143. package/kits/hub-game/code/server/ask.js +39 -3
  144. package/kits/hub-game/code/server/ballot.js +167 -4
  145. package/kits/hub-game/code/server/celebrate.js +64 -0
  146. package/kits/hub-game/code/server/companion.js +17 -2
  147. package/kits/hub-game/code/server/decor.js +11 -2
  148. package/kits/hub-game/code/server/disguise.js +63 -0
  149. package/kits/hub-game/code/server/earned.js +6 -2
  150. package/kits/hub-game/code/server/friendBests.js +13 -4
  151. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  152. package/kits/hub-game/code/server/grab.js +12 -2
  153. package/kits/hub-game/code/server/heldOffers.js +142 -0
  154. package/kits/hub-game/code/server/holdShow.js +98 -0
  155. package/kits/hub-game/code/server/hub.js +991 -72
  156. package/kits/hub-game/code/server/idle.js +110 -9
  157. package/kits/hub-game/code/server/index.js +9 -0
  158. package/kits/hub-game/code/server/labels.js +13 -3
  159. package/kits/hub-game/code/server/manifest.js +94 -6
  160. package/kits/hub-game/code/server/menu.js +26 -3
  161. package/kits/hub-game/code/server/npcs.js +55 -9
  162. package/kits/hub-game/code/server/observe.js +67 -6
  163. package/kits/hub-game/code/server/players.js +14 -2
  164. package/kits/hub-game/code/server/replay.js +135 -0
  165. package/kits/hub-game/code/server/standing.js +7 -3
  166. package/kits/hub-game/code/server/storageLimit.js +4 -1
  167. package/kits/hub-game/code/server/townDay.js +74 -0
  168. package/kits/hub-game/code/server/vehicle.js +3 -0
  169. package/kits/hub-game/code/server/vis.js +26 -4
  170. package/kits/hub-game/code/server/wallet.js +677 -0
  171. package/kits/hub-game/code/server/wear.js +13 -3
  172. package/kits/hub-game/code/server/writerLease.js +191 -0
  173. package/kits/hub-game/code/shared/act.js +1 -1
  174. package/kits/hub-game/code/shared/expression.js +6 -0
  175. package/kits/hub-game/code/shared/replay.js +37 -0
  176. package/kits/hub-game/code/systems/hub.js +429 -55
  177. package/kits/hub-game/docs/analytics.md +16 -2
  178. package/kits/hub-game/docs/contract.md +956 -101
  179. package/kits/hub-game/docs/home-pieces.md +5 -6
  180. package/kits/hub-game/docs/observed-progress.md +49 -1
  181. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  182. package/kits/hub-game/index.html +1 -0
  183. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  184. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  185. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  186. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  187. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  188. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  189. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  190. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  207. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  208. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  209. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  210. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  211. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  212. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  213. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  214. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  215. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  216. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  217. package/kits/hub-game/package-lock.json +3 -3
  218. package/kits/hub-game/package.json +4 -3
  219. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  220. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  221. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  222. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  223. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  224. package/kits/hub-game/scripts/pack.mjs +89 -23
  225. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  226. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  227. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  228. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  229. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  230. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  231. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  232. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  233. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  234. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  235. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  236. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  237. package/kits/hub-game/scripts/test-analytics.mjs +79 -0
  238. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  239. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  240. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  241. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  242. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  243. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  244. package/kits/hub-game/scripts/test-ballot.mjs +421 -4
  245. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  246. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  247. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  248. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  249. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  250. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  251. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  252. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  253. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  254. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  255. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  256. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  257. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  258. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  259. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  260. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  261. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  262. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  263. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  264. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  265. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  266. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  267. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  268. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  269. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  270. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  271. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  272. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  273. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  274. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  275. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  276. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  277. package/kits/hub-game/scripts/test-hub-ops.mjs +119 -0
  278. package/kits/hub-game/scripts/test-hub-trip.mjs +240 -4
  279. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  280. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  281. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  282. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  283. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  284. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  285. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  286. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  287. package/kits/hub-game/scripts/test-menu-client.mjs +54 -5
  288. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  289. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  290. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  291. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  292. package/kits/hub-game/scripts/test-pad-cues.mjs +39 -0
  293. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  294. package/kits/hub-game/scripts/test-placeat-server.mjs +648 -0
  295. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  296. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  297. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  298. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  299. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  300. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  301. package/kits/hub-game/scripts/test-rehello.mjs +242 -3
  302. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  303. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  304. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  305. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  306. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  307. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  308. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  309. package/kits/hub-game/scripts/test-role-client.mjs +2 -1
  310. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  311. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  312. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  313. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  314. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  315. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  316. package/kits/hub-game/scripts/test-standing.mjs +135 -2
  317. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  318. package/kits/hub-game/scripts/test-stuck.mjs +36 -1
  319. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  320. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  321. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  322. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  323. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  324. package/kits/hub-game/scripts/test-together.mjs +11 -0
  325. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  326. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  327. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  328. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  329. package/kits/hub-game/scripts/test-vehicle-client.mjs +68 -1
  330. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  331. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  332. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  333. package/kits/hub-game/scripts/test-world-labels.mjs +340 -0
  334. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  335. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  336. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  337. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  338. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  339. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +36 -2
  340. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +10 -2
  341. package/kits/multiplayer-3d/castle.json +5 -5
  342. package/kits/multiplayer-3d/code/client/resumeGate.js +66 -2
  343. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  344. package/kits/multiplayer-3d/code/server/world.js +19 -4
  345. package/kits/multiplayer-3d/code/systems/multiplayer.js +108 -18
  346. package/kits/multiplayer-3d/package-lock.json +1 -1
  347. package/kits/multiplayer-3d/package.json +2 -1
  348. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  349. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  350. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  351. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +417 -5
  352. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  353. package/kits/physics-2d/castle.json +2 -2
  354. package/kits/physics-2d/engine/scene.js +10 -2
  355. package/kits/physics-3d/CLAUDE.md +14 -0
  356. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  357. package/kits/physics-3d/castle.json +3 -3
  358. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  359. package/kits/physics-3d/docs/engine-player.md +76 -0
  360. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  361. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  362. package/kits/physics-3d/engine3d/gait.js +16 -8
  363. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  364. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  365. package/kits/physics-3d/engine3d/look.js +110 -17
  366. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  367. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  368. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  369. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  370. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  371. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  372. package/kits/physics-3d/engine3d/optimize.js +20 -9
  373. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  374. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  375. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  376. package/kits/physics-3d/engine3d/world3d.js +211 -17
  377. package/kits/physics-3d/package-lock.json +1 -1
  378. package/kits/physics-3d/package.json +2 -1
  379. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  380. package/kits/physics-3d/scripts/render.mjs +56 -8
  381. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  382. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  383. package/kits/physics-3d/scripts/test-coaxial-escape.mjs +176 -0
  384. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  385. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  386. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  387. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  388. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  389. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  390. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  391. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  392. package/kits/physics-3d/systems/physics3d.js +59 -2
  393. package/kits/real-time/castle.json +2 -2
  394. package/kits/real-time/code/client/connection.js +3 -0
  395. package/package.json +2 -2
  396. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -0,0 +1,154 @@
1
+ // A console drawn inside the deck's own frame, for debugging on a phone. A
2
+ // published deck runs in an opaque-origin frame (and in the app, a WebView), so
3
+ // the host page's devtools never see its console; this puts the lines where the
4
+ // person holding the device can read them. Off until the deck asks for it.
5
+ //
6
+ // `setup()` records every console line and uncaught error from the start, so
7
+ // `show()` reveals what happened before it was called. A deck that never calls
8
+ // `setup()` gets recording from its first `show()` on.
9
+ const MAX_LINES = 300;
10
+ const MAX_LINE_CHARS = 2000;
11
+ const COLORS = {
12
+ log: "#e8e8e8",
13
+ warn: "#ffd66b",
14
+ error: "#ff8a80",
15
+ };
16
+ const recorded = [];
17
+ let consoleHooked = false;
18
+ let errorsHooked = false;
19
+ let panel = null;
20
+ let list = null;
21
+ export function formatConsoleArgs(args) {
22
+ return args
23
+ .map((arg) => {
24
+ if (typeof arg === "string")
25
+ return arg;
26
+ if (arg instanceof Error)
27
+ return arg.stack || arg.message;
28
+ try {
29
+ const json = JSON.stringify(arg);
30
+ return json ?? String(arg);
31
+ }
32
+ catch {
33
+ return String(arg);
34
+ }
35
+ })
36
+ .join(" ");
37
+ }
38
+ // runtime.ts's own console hook calls this, so the line is formatted once for
39
+ // both the dev serve and this buffer.
40
+ export function recordConsoleLine(level, text) {
41
+ const line = {
42
+ level,
43
+ text: text.length > MAX_LINE_CHARS ? `${text.slice(0, MAX_LINE_CHARS)}…` : text,
44
+ time: Date.now(),
45
+ };
46
+ recorded.push(line);
47
+ if (recorded.length > MAX_LINES) {
48
+ recorded.splice(0, recorded.length - MAX_LINES);
49
+ }
50
+ if (list) {
51
+ appendRow(line);
52
+ }
53
+ }
54
+ export function noteConsoleHooked() {
55
+ consoleHooked = true;
56
+ }
57
+ // Uncaught errors and rejections never pass through console.error, and they
58
+ // are what a deck that "just shows a black card" on a phone is hiding.
59
+ export function captureErrors() {
60
+ if (errorsHooked || typeof window === "undefined")
61
+ return;
62
+ errorsHooked = true;
63
+ window.addEventListener("error", (event) => {
64
+ const error = event.error;
65
+ const text = error instanceof Error ? error.stack || error.message : event.message;
66
+ recordConsoleLine("error", `Uncaught ${text || "error"}`);
67
+ });
68
+ window.addEventListener("unhandledrejection", (event) => {
69
+ recordConsoleLine("error", `Unhandled rejection ${formatConsoleArgs([event.reason])}`);
70
+ });
71
+ }
72
+ function hookConsole() {
73
+ if (consoleHooked)
74
+ return;
75
+ consoleHooked = true;
76
+ for (const level of ["log", "warn", "error"]) {
77
+ const original = console[level];
78
+ console[level] = (...args) => {
79
+ original(...args);
80
+ recordConsoleLine(level, formatConsoleArgs(args));
81
+ };
82
+ }
83
+ }
84
+ function button(label, onClick) {
85
+ const el = document.createElement("button");
86
+ el.type = "button";
87
+ el.textContent = label;
88
+ el.style.cssText =
89
+ "font: inherit; color: #fff; background: #333; border: 1px solid #555; border-radius: 4px; padding: 2px 8px; margin-left: 6px;";
90
+ el.addEventListener("click", onClick);
91
+ return el;
92
+ }
93
+ // Text only, never markup: a line is whatever the deck logged.
94
+ function appendRow(line) {
95
+ if (!list)
96
+ return;
97
+ const row = document.createElement("div");
98
+ row.textContent = line.text;
99
+ row.style.cssText = `color: ${COLORS[line.level]}; white-space: pre-wrap; word-break: break-word; border-bottom: 1px solid #222; padding: 1px 0;`;
100
+ const atBottom = list.scrollHeight - list.scrollTop - list.clientHeight < 8;
101
+ list.appendChild(row);
102
+ while (list.childElementCount > MAX_LINES) {
103
+ list.firstElementChild?.remove();
104
+ }
105
+ if (atBottom) {
106
+ list.scrollTop = list.scrollHeight;
107
+ }
108
+ }
109
+ function buildPanel() {
110
+ const root = document.createElement("div");
111
+ root.setAttribute("data-castle-debug-console", "");
112
+ root.style.cssText =
113
+ "position: fixed; left: 0; right: 0; bottom: 0; max-height: 40%; z-index: 2147483647; display: flex; flex-direction: column; background: rgba(0, 0, 0, 0.85); color: #e8e8e8; font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace; pointer-events: auto; touch-action: pan-y;";
114
+ const header = document.createElement("div");
115
+ header.style.cssText =
116
+ "display: flex; align-items: center; padding: 4px 8px; border-bottom: 1px solid #444; flex: none;";
117
+ const title = document.createElement("span");
118
+ title.textContent = "Console";
119
+ title.style.cssText = "flex: 1; font-weight: bold;";
120
+ header.append(title, button("Clear", () => {
121
+ recorded.length = 0;
122
+ list?.replaceChildren();
123
+ }), button("Hide", hide));
124
+ list = document.createElement("div");
125
+ list.style.cssText = "overflow-y: auto; padding: 4px 8px; flex: 1; min-height: 0;";
126
+ root.append(header, list);
127
+ return root;
128
+ }
129
+ function show() {
130
+ if (typeof document === "undefined")
131
+ return;
132
+ hookConsole();
133
+ captureErrors();
134
+ if (panel)
135
+ return;
136
+ panel = buildPanel();
137
+ (document.body ?? document.documentElement).appendChild(panel);
138
+ for (const line of recorded) {
139
+ appendRow(line);
140
+ }
141
+ if (list) {
142
+ list.scrollTop = list.scrollHeight;
143
+ }
144
+ }
145
+ function hide() {
146
+ panel?.remove();
147
+ panel = null;
148
+ list = null;
149
+ }
150
+ export const DebugConsole = {
151
+ show,
152
+ hide,
153
+ lines: () => recorded.slice(),
154
+ };
@@ -10,12 +10,18 @@
10
10
  //
11
11
  // `null` is a normal answer: no such experiment, one that has ended, a player
12
12
  // who is not in it, or a host that predates experiments. Always handle it.
13
+ //
14
+ // The first `experiment(name)` that answers a variant also tells the host, once
15
+ // per name per page load, which records the exposure (the player was shown this
16
+ // arm) for the deck's analytics. `experiments()` reports nothing: a deck reading
17
+ // the whole map has not shown the player any one arm.
13
18
  import { getCastleEmbed } from "./context";
14
19
  import { hostRequest } from "./transport";
15
20
  const NONE = Object.freeze({});
16
21
  let variants = null;
17
22
  let loading = null;
18
23
  let warnedEarlyRead = false;
24
+ const exposed = new Set();
19
25
  /**
20
26
  * The variant this player has in `name`, or `null` when they are in no such
21
27
  * experiment. Synchronous; see `experimentsReady` for the one case where a read
@@ -23,7 +29,24 @@ let warnedEarlyRead = false;
23
29
  */
24
30
  export function experiment(name) {
25
31
  const known = current();
26
- return Object.hasOwn(known, name) ? known[name] : null;
32
+ if (!Object.hasOwn(known, name))
33
+ return null;
34
+ const variant = known[name];
35
+ reportExposure(name, variant);
36
+ return variant;
37
+ }
38
+ // Fire and forget: a host from before exposures does not know the command, and
39
+ // a failed report must never change what the deck reads.
40
+ function reportExposure(name, variant) {
41
+ if (exposed.has(name))
42
+ return;
43
+ exposed.add(name);
44
+ try {
45
+ void hostRequest("experiments.exposed", { name, variant }).catch(() => { });
46
+ }
47
+ catch {
48
+ // No host to tell.
49
+ }
27
50
  }
28
51
  /** Every experiment this player is in on this deck, `{ name: variant }`. */
29
52
  export function experiments() {
@@ -0,0 +1,7 @@
1
+ export declare const HOST_TRANSPORT_RETRY_MS: readonly [1000, 2000, 4000, 8000];
2
+ export interface HostRetryOptions {
3
+ signal?: AbortSignal;
4
+ stopped?: () => boolean;
5
+ }
6
+ export declare function isHostTransportFailure(error: unknown): boolean;
7
+ export declare function retryHostTransport<T>(command: string, ask: () => Promise<T>, options?: HostRetryOptions): Promise<T>;
@@ -0,0 +1,57 @@
1
+ // Re-asking a join-path host command whose request failed in transit.
2
+ //
3
+ // The host runs these commands against Castle's API with its own fetch. When
4
+ // the load balancer in front of the API answers a 502 (an HTML page, in bursts
5
+ // while app servers are replaced), the host cannot read the reply and the deck
6
+ // gets CASTLE_HOST_ERROR: the request never reached ghost, or reached it and
7
+ // its answer was lost. Ghost lets a newer acquisition supersede an earlier
8
+ // pending one, so asking again is safe for the acquisitions that use this
9
+ // (Hub.go/back/jump, multiplayer.getSession, multiplayer.joinDestination).
10
+ //
11
+ // Only CASTLE_HOST_ERROR is asked again. Every error ghost itself answered
12
+ // carries its own code (FORBIDDEN, LOGIN_REQUIRED, ...) and is final, and
13
+ // CASTLE_HOST_UNAVAILABLE is mostly the deck's own timeout, where the request
14
+ // may still be running and another wait would outlast the caller's deadline.
15
+ import { CastleError } from "./errors";
16
+ // The wait before each ask after the first: five asks over about 15 s, inside
17
+ // the 30 s the deck gives one hub.go/back/jump and the hub kit's door limit.
18
+ export const HOST_TRANSPORT_RETRY_MS = [1_000, 2_000, 4_000, 8_000];
19
+ export function isHostTransportFailure(error) {
20
+ return error instanceof CastleError && error.code === "CASTLE_HOST_ERROR";
21
+ }
22
+ export async function retryHostTransport(command, ask, options = {}) {
23
+ for (let attempt = 0;; attempt++) {
24
+ try {
25
+ return await ask();
26
+ }
27
+ catch (error) {
28
+ const delay = HOST_TRANSPORT_RETRY_MS[attempt];
29
+ if (!isHostTransportFailure(error) || delay === undefined || isStopped(options)) {
30
+ throw error;
31
+ }
32
+ console.warn(`Castle ${command} failed in transit; asking again in ${delay} ms ` +
33
+ `(attempt ${attempt + 2} of ${HOST_TRANSPORT_RETRY_MS.length + 1}).`);
34
+ await wait(delay, options.signal);
35
+ if (isStopped(options))
36
+ throw error;
37
+ }
38
+ }
39
+ }
40
+ function isStopped(options) {
41
+ return options.signal?.aborted === true || options.stopped?.() === true;
42
+ }
43
+ function wait(milliseconds, signal) {
44
+ return new Promise((resolve) => {
45
+ if (signal?.aborted) {
46
+ resolve();
47
+ return;
48
+ }
49
+ const done = () => {
50
+ clearTimeout(timer);
51
+ signal?.removeEventListener("abort", done);
52
+ resolve();
53
+ };
54
+ const timer = setTimeout(done, milliseconds);
55
+ signal?.addEventListener("abort", done, { once: true });
56
+ });
57
+ }
@@ -1,5 +1,5 @@
1
- import type { HubBackResult, HubCancelResult, HubChatResult, HubDoorsResult, HubFriendsResult, HubInviteResult, HubCanInviteResult, HubInviteArrivalResult, HubHeartsResult, HubGoResult, HubJumpResult, HubReportResult, HubSayResult, HubSignInResult } from "./commands";
2
- export type { HubBackResult, HubCancelResult, HubCancelStatus, HubChatMessage, HubChatResult, HubDoor, HubDoorsResult, HubFriend, HubFriendsResult, HubInviteResult, HubCanInviteResult, HubInviteArrivalResult, HubHeartsResult, HubGoParams, HubGoResult, HubHandoffResult, HubHandoffStatus, HubJumpResult, HubPlacementKind, HubReportResult, HubSayResult, HubSignInParams, HubSignInResult, } from "./commands";
1
+ import type { HubBackResult, HubCancelResult, HubChatResult, HubDoorsResult, HubFriendsResult, HubInviteResult, HubCanInviteResult, HubInviteAvailableResult, HubInviteArrivalResult, HubHeartsResult, HubGoResult, HubJumpResult, HubReportResult, HubSayResult, HubSignInResult, HubPushPermissionResult, HubPushDestinationResult, HubGoFailedWhy } from "./commands";
2
+ export type { HubBackResult, HubCancelResult, HubCancelStatus, HubChatMessage, HubChatResult, HubDoor, HubDoorsResult, HubFriend, HubFriendsResult, HubInviteResult, HubCanInviteResult, HubInviteAvailableResult, HubInviteArrivalResult, HubHeartsResult, HubGoFailedWhy, HubGoParams, HubGoResult, HubHandoffResult, HubHandoffStatus, HubJumpResult, HubPlacementKind, HubReportResult, HubSayResult, HubSignInParams, HubSignInResult, HubPushPermissionResult, HubPushDestinationResult, } from "./commands";
3
3
  /**
4
4
  * Doors between hub places. Every hub-kit deck is a place; ghost's door table
5
5
  * is the allowlist, and the host supplies real authentication and the current
@@ -14,6 +14,10 @@ export type { HubBackResult, HubCancelResult, HubCancelStatus, HubChatMessage, H
14
14
  * ticket is written. A failure before then leaves the player where they were.
15
15
  */
16
16
  export interface CastleHubApi {
17
+ /** Deliberate user action after a committed personal promise; native hosts may ask OS permission. */
18
+ pushPermission(): Promise<HubPushPermissionResult>;
19
+ /** One-time native push hint after authenticated town join. */
20
+ pushDestination(): Promise<HubPushDestinationResult>;
17
21
  /**
18
22
  * Acquire the destination behind a door of the current place. A door used
19
23
  * within seconds of arriving may take up to 15 s while ghost catches up with
@@ -50,6 +54,8 @@ export interface CastleHubApi {
50
54
  * command rejects it, so treat anything but `canInvite: true` as no.
51
55
  */
52
56
  canInvite(): Promise<HubCanInviteResult>;
57
+ /** Read the authenticated viewer's invite gate; old hosts answer unavailable. */
58
+ inviteAvailable(): Promise<HubInviteAvailableResult>;
53
59
  /** Hub-kit arrival hook: the trusted host retains the invite token. */
54
60
  inviteArrival(): Promise<HubInviteArrivalResult>;
55
61
  /** Undo both follow directions for one pair from this host's invite arrival. */
@@ -122,6 +128,18 @@ export interface CastleHubApi {
122
128
  * that never send it are the norm. Returns an unsubscribe function.
123
129
  */
124
130
  onGo(listener: (go: HubGoRequest) => void): () => void;
131
+ /**
132
+ * Tell the host that a Go it sent (`onGo`) ended without the player going
133
+ * through the door: `why` is `"refused"` (`go` gave no handoff),
134
+ * `"content"` (the destination's content would not load) or `"join"` (the
135
+ * join was never committed). A host that acquired the door from its own
136
+ * session may acquire it again there and send a fresh Go. One-way: nothing
137
+ * answers it, and hosts that predate it ignore it.
138
+ */
139
+ goFailed(go: {
140
+ doorId: string;
141
+ owner?: string | null;
142
+ }, why: HubGoFailedWhy): void;
125
143
  }
126
144
  /** A host's request to go through a door (see `Hub.onGo`). */
127
145
  export interface HubGoRequest {
@@ -1,13 +1,37 @@
1
+ import { HUB_GO_DOOR_ID_MAX } from "./commands";
1
2
  import { CastleError } from "./errors";
2
- import { hostRequest, setHubEventHandler } from "./transport";
3
+ import { hostNotifyHub, hostRequest, setHubEventHandler } from "./transport";
3
4
  import { HUB_FORBIDDEN_RETRY_MS, rejoinedRecently } from "./hubRejoin";
5
+ import { isHostTransportFailure, retryHostTransport } from "./hostRetry";
6
+ // Hub contract v1.177: a host that predates these commands answers
7
+ // UNKNOWN_COMMAND, and no host at all (no bridge, an unreachable dev server, a
8
+ // timeout) surfaces CASTLE_HOST_UNAVAILABLE. Both read as unavailable to a
9
+ // deck; every other failure still rejects.
10
+ const HUB_PUSH_UNAVAILABLE_CODES = new Set([
11
+ "UNKNOWN_COMMAND",
12
+ "CASTLE_HOST_UNAVAILABLE",
13
+ ]);
14
+ async function hubPushRequest(command) {
15
+ try {
16
+ return await hostRequest(command, {});
17
+ }
18
+ catch (error) {
19
+ if (error instanceof CastleError && HUB_PUSH_UNAVAILABLE_CODES.has(error.code)) {
20
+ return { status: "unavailable" };
21
+ }
22
+ throw error;
23
+ }
24
+ }
4
25
  export const Hub = {
26
+ pushPermission: () => hubPushRequest("hub.pushPermission"),
27
+ pushDestination: () => hubPushRequest("hub.pushDestination"),
5
28
  go,
6
29
  back,
7
30
  doors,
8
31
  friends,
9
32
  invite,
10
33
  canInvite,
34
+ inviteAvailable,
11
35
  inviteArrival,
12
36
  undoInvite,
13
37
  hearts,
@@ -21,6 +45,7 @@ export const Hub = {
21
45
  cancel,
22
46
  onBack,
23
47
  onGo,
48
+ goFailed,
24
49
  };
25
50
  async function go(doorId, options = {}) {
26
51
  if (typeof doorId !== "string" || doorId.length === 0) {
@@ -38,25 +63,59 @@ async function go(doorId, options = {}) {
38
63
  operation: "Hub.go",
39
64
  });
40
65
  }
41
- return untilListed(() => hostRequest("hub.go", ownerUserId === undefined ? { doorId } : { doorId, ownerUserId }));
66
+ return untilListed("hub.go", () => hostRequest("hub.go", ownerUserId === undefined ? { doorId } : { doorId, ownerUserId }));
67
+ }
68
+ // Aborted, and dropped, by every `Hub.cancel`: it ends any wait below. Made
69
+ // on first use, so loading the SDK needs no AbortController.
70
+ let cancelWaits = null;
71
+ function cancelSignal() {
72
+ return (cancelWaits ??= new AbortController()).signal;
73
+ }
74
+ const CANCELLED_HANDOFF = {
75
+ status: "cancelled", url: null, nonce: null, sessionId: null, bundleHash: null, contentUrl: null,
76
+ };
77
+ // Every go/back/jump takes the next generation. Ghost lets the newest pending
78
+ // acquisition supersede the others, so an older one asked again after a newer
79
+ // one began would replace it: only the newest is asked again.
80
+ let hubAcquisitions = 0;
81
+ function startAcquisition() {
82
+ return { signal: cancelSignal(), generation: ++hubAcquisitions };
83
+ }
84
+ function isSuperseded(acquisition) {
85
+ return acquisition.generation !== hubAcquisitions;
86
+ }
87
+ // An acquisition whose request failed in transit is asked again
88
+ // (`retryHostTransport`) until `Hub.cancel` or a newer acquisition, either of
89
+ // which answers `cancelled`.
90
+ async function handoff(command, ask, acquisition) {
91
+ const superseded = () => isSuperseded(acquisition);
92
+ try {
93
+ return await retryHostTransport(command, ask, { signal: acquisition.signal, stopped: superseded });
94
+ }
95
+ catch (error) {
96
+ if ((acquisition.signal.aborted || superseded()) && isHostTransportFailure(error)) {
97
+ return { ...CANCELLED_HANDOFF };
98
+ }
99
+ throw error;
100
+ }
42
101
  }
43
102
  // Right after the socket rejoined its session ghost may not list the player
44
- // yet, and answers `forbidden` until it does. `Hub.cancel` ends the wait.
45
- let cancels = 0;
46
- async function untilListed(ask) {
47
- const asked = cancels;
103
+ // yet, and answers `forbidden` until it does. `Hub.cancel` or a newer
104
+ // acquisition ends the wait, and nothing more is asked.
105
+ async function untilListed(command, ask) {
106
+ const acquisition = startAcquisition();
107
+ const signal = acquisition.signal;
48
108
  for (;;) {
49
- const result = await ask();
109
+ const result = await handoff(command, ask, acquisition);
50
110
  if (result.status !== "forbidden" || !rejoinedRecently())
51
111
  return result;
52
112
  await new Promise((resolve) => setTimeout(resolve, HUB_FORBIDDEN_RETRY_MS));
53
- if (cancels !== asked) {
54
- return { status: "cancelled", url: null, nonce: null, sessionId: null, bundleHash: null, contentUrl: null };
55
- }
113
+ if (signal.aborted || isSuperseded(acquisition))
114
+ return { ...CANCELLED_HANDOFF };
56
115
  }
57
116
  }
58
117
  async function back() {
59
- return hostRequest("hub.back", {});
118
+ return handoff("hub.back", () => hostRequest("hub.back", {}), startAcquisition());
60
119
  }
61
120
  async function doors() {
62
121
  return hostRequest("hub.doors", {});
@@ -72,6 +131,17 @@ async function invite(options = {}) {
72
131
  async function canInvite() {
73
132
  return hostRequest("hub.canInvite", {});
74
133
  }
134
+ async function inviteAvailable() {
135
+ try {
136
+ const answer = await hostRequest("hub.inviteAvailable", {});
137
+ return answer?.status === "ok" && typeof answer.available === "boolean"
138
+ ? { status: "ok", available: answer.available }
139
+ : { status: "unavailable" };
140
+ }
141
+ catch {
142
+ return { status: "unavailable" };
143
+ }
144
+ }
75
145
  async function inviteArrival() {
76
146
  return hostRequest("hub.inviteArrival", {});
77
147
  }
@@ -116,7 +186,7 @@ async function jump(userId) {
116
186
  operation: "Hub.jump",
117
187
  });
118
188
  }
119
- return untilListed(() => hostRequest("hub.jump", { userId }));
189
+ return untilListed("hub.jump", () => hostRequest("hub.jump", { userId }));
120
190
  }
121
191
  async function report(userId, reason) {
122
192
  if (typeof userId !== "string" || userId.length === 0) {
@@ -152,9 +222,25 @@ async function reportChat(messageId, options) {
152
222
  return hostRequest("hub.reportChat", { messageId, ...(options?.block === true ? { block: true } : {}) });
153
223
  }
154
224
  async function cancel() {
155
- cancels += 1;
225
+ cancelWaits?.abort();
226
+ cancelWaits = null;
156
227
  return hostRequest("hub.cancel", {});
157
228
  }
229
+ const GO_FAILED_WHYS = ["refused", "content", "join"];
230
+ function goFailed(go, why) {
231
+ const doorId = go?.doorId;
232
+ const owner = go?.owner ?? undefined;
233
+ if (typeof doorId !== "string" || doorId.length === 0 || doorId.length > HUB_GO_DOOR_ID_MAX ||
234
+ (owner !== undefined && (typeof owner !== "string" || !/^[1-9]\d{0,9}$/.test(owner))) ||
235
+ !GO_FAILED_WHYS.includes(why)) {
236
+ throw new CastleError({
237
+ code: "INVALID_ARGUMENT",
238
+ message: "Hub.goFailed requires a Go's doorId, its owner if any, and why it failed.",
239
+ operation: "Hub.goFailed",
240
+ });
241
+ }
242
+ hostNotifyHub({ type: "goFailed", doorId, ...(owner !== undefined ? { owner } : {}), why });
243
+ }
158
244
  const backListeners = new Set();
159
245
  const goListeners = new Set();
160
246
  function onBack(listener) {
@@ -205,6 +205,8 @@ export interface MultiplayerConnection {
205
205
  readonly sharedCharacters: boolean;
206
206
  /** Sends byte payloads as binary frames and all other payloads as JSON. */
207
207
  send(data: unknown): void;
208
+ /** Starts recovery for a connected socket; false when there is none. */
209
+ reconnect(): boolean;
208
210
  /** Requests one billed character turn through this authenticated world socket. */
209
211
  requestCharacterTurn(request: MultiplayerCharacterTurnRequest): Promise<MultiplayerCharacterTurnAdmission>;
210
212
  /** Recovers the durable status of a prior operation after reconnecting. */