castle-web-cli 0.4.238 → 0.4.240
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.
- package/dist/agent.js +5 -1
- package/dist/api.d.ts +20 -0
- package/dist/api.js +57 -0
- package/dist/bundle.d.ts +38 -1
- package/dist/bundle.js +309 -13
- package/dist/castle-host/host.js +218 -11
- package/dist/castleJson.d.ts +10 -0
- package/dist/castleJson.js +46 -2
- package/dist/check.js +5 -2
- package/dist/devSessionServer.js +4 -1
- package/dist/devSessionStorage.d.ts +1 -0
- package/dist/devSessionStorage.js +32 -7
- package/dist/importOrder.d.ts +2 -0
- package/dist/importOrder.js +29 -0
- package/dist/index.js +22 -3
- package/dist/init.js +24 -2
- package/dist/multiplayerDoc.d.ts +1 -1
- package/dist/multiplayerDoc.js +9 -0
- package/dist/platformDoc.js +4 -2
- package/dist/playPagePolicy.d.ts +1 -0
- package/dist/playPagePolicy.js +12 -3
- package/dist/resetLeaderboards.d.ts +8 -1
- package/dist/resetLeaderboards.js +43 -8
- package/dist/roomLogs.d.ts +39 -0
- package/dist/roomLogs.js +166 -0
- package/dist/save-deck.d.ts +32 -2
- package/dist/save-deck.js +240 -39
- package/kits/base/CLAUDE.md +2 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +240 -8
- package/kits/base/sdk/analytics.d.ts +8 -0
- package/kits/base/sdk/analytics.js +92 -0
- package/kits/base/sdk/castle.d.ts +8 -2
- package/kits/base/sdk/castle.js +3 -0
- package/kits/base/sdk/commands.d.ts +79 -0
- package/kits/base/sdk/commands.js +1 -0
- package/kits/base/sdk/debugConsole.d.ts +17 -0
- package/kits/base/sdk/debugConsole.js +154 -0
- package/kits/base/sdk/experiments.js +24 -1
- package/kits/base/sdk/hostRetry.d.ts +7 -0
- package/kits/base/sdk/hostRetry.js +57 -0
- package/kits/base/sdk/hub.d.ts +20 -2
- package/kits/base/sdk/hub.js +99 -13
- package/kits/base/sdk/multiplayer.d.ts +2 -0
- package/kits/base/sdk/multiplayer.js +198 -26
- package/kits/base/sdk/reconnectBudget.d.ts +6 -0
- package/kits/base/sdk/reconnectBudget.js +41 -1
- package/kits/base/sdk/rooms.d.ts +11 -0
- package/kits/base/sdk/rooms.js +22 -0
- package/kits/base/sdk/runtime.js +36 -19
- package/kits/base/sdk/server/hub.d.ts +19 -0
- package/kits/base/sdk/server/hub.js +12 -0
- package/kits/base/sdk/server/platformHandle.d.ts +1 -0
- package/kits/base/sdk/server/wrapper.d.ts +1 -1
- package/kits/base/sdk/server/wrapper.js +26 -1
- package/kits/base/sdk/store.d.ts +8 -2
- package/kits/base/sdk/store.js +5 -1
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +35 -0
- package/kits/hub-game/CLAUDE.md +66 -19
- package/kits/hub-game/castle.json +4 -4
- package/kits/hub-game/code/client/act.js +9 -6
- package/kits/hub-game/code/client/actCore.js +26 -6
- package/kits/hub-game/code/client/actGateLog.js +36 -0
- package/kits/hub-game/code/client/actionOverflow.js +29 -8
- package/kits/hub-game/code/client/actionRailSurface.js +186 -0
- package/kits/hub-game/code/client/actionRailTree.js +173 -0
- package/kits/hub-game/code/client/askSurface.js +85 -0
- package/kits/hub-game/code/client/askTree.js +51 -0
- package/kits/hub-game/code/client/attention.js +31 -6
- package/kits/hub-game/code/client/ballot.js +42 -5
- package/kits/hub-game/code/client/ballotSurface.js +115 -0
- package/kits/hub-game/code/client/ballotTree.js +180 -0
- package/kits/hub-game/code/client/catchingUp.js +19 -0
- package/kits/hub-game/code/client/celebrate.js +66 -0
- package/kits/hub-game/code/client/chrome.js +474 -53
- package/kits/hub-game/code/client/companion.js +93 -23
- package/kits/hub-game/code/client/companionDress.js +1 -1
- package/kits/hub-game/code/client/cornerSurface.js +106 -0
- package/kits/hub-game/code/client/cornerTree.js +83 -0
- package/kits/hub-game/code/client/decor.js +20 -11
- package/kits/hub-game/code/client/deviceStorage.js +121 -0
- package/kits/hub-game/code/client/disguise.js +23 -0
- package/kits/hub-game/code/client/disguiseDraw.js +87 -0
- package/kits/hub-game/code/client/dockSurface.js +206 -0
- package/kits/hub-game/code/client/dockTree.js +232 -0
- package/kits/hub-game/code/client/earned.js +29 -0
- package/kits/hub-game/code/client/emoteSurface.js +188 -0
- package/kits/hub-game/code/client/emoteTree.js +264 -0
- package/kits/hub-game/code/client/farAvatars.js +4 -3
- package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
- package/kits/hub-game/code/client/grab.js +121 -50
- package/kits/hub-game/code/client/holdShow.js +19 -0
- package/kits/hub-game/code/client/hookLayer.js +96 -12
- package/kits/hub-game/code/client/hubControls.js +7 -1
- package/kits/hub-game/code/client/hudSurface.js +11 -3
- package/kits/hub-game/code/client/hudTree.js +7 -4
- package/kits/hub-game/code/client/idle.js +21 -3
- package/kits/hub-game/code/client/invites.js +24 -3
- package/kits/hub-game/code/client/keys.js +15 -0
- package/kits/hub-game/code/client/labelsNear.js +8 -1
- package/kits/hub-game/code/client/layoutCache.js +57 -8
- package/kits/hub-game/code/client/loadingCover.js +53 -4
- package/kits/hub-game/code/client/menuIcons.js +15 -0
- package/kits/hub-game/code/client/menuRows.js +8 -2
- package/kits/hub-game/code/client/menuSurface.js +102 -0
- package/kits/hub-game/code/client/menuTree.js +135 -0
- package/kits/hub-game/code/client/modelLook.js +41 -0
- package/kits/hub-game/code/client/pickerSurface.js +152 -0
- package/kits/hub-game/code/client/pickerTree.js +163 -0
- package/kits/hub-game/code/client/pushVisit.js +4 -2
- package/kits/hub-game/code/client/quality.js +188 -29
- package/kits/hub-game/code/client/qualityEntry.js +10 -1
- package/kits/hub-game/code/client/quickChatSurface.js +222 -0
- package/kits/hub-game/code/client/quickChatTree.js +201 -0
- package/kits/hub-game/code/client/rehello.js +75 -0
- package/kits/hub-game/code/client/renderVisibility.js +17 -0
- package/kits/hub-game/code/client/replay.js +118 -0
- package/kits/hub-game/code/client/role.js +3 -0
- package/kits/hub-game/code/client/safeLayout.js +441 -56
- package/kits/hub-game/code/client/safeStyle.js +13 -10
- package/kits/hub-game/code/client/say.js +2 -0
- package/kits/hub-game/code/client/soundSurface.js +77 -0
- package/kits/hub-game/code/client/soundTree.js +74 -0
- package/kits/hub-game/code/client/soundscape.js +12 -9
- package/kits/hub-game/code/client/soundscapeCues.js +1 -1
- package/kits/hub-game/code/client/state.js +67 -1
- package/kits/hub-game/code/client/stuckSurface.js +76 -0
- package/kits/hub-game/code/client/stuckTree.js +67 -0
- package/kits/hub-game/code/client/talk.js +42 -12
- package/kits/hub-game/code/client/talkTree.js +4 -2
- package/kits/hub-game/code/client/textAskSurface.js +147 -0
- package/kits/hub-game/code/client/textAskTree.js +67 -0
- package/kits/hub-game/code/client/tiers.js +252 -27
- package/kits/hub-game/code/client/together.js +4 -1
- package/kits/hub-game/code/client/uiDom.js +86 -8
- package/kits/hub-game/code/client/uiTree.js +33 -4
- package/kits/hub-game/code/client/vehicle.js +75 -52
- package/kits/hub-game/code/client/weakestTier.js +75 -31
- package/kits/hub-game/code/client/wear.js +159 -5
- package/kits/hub-game/code/client/worldLabels.js +215 -26
- package/kits/hub-game/code/companionSpec.js +4 -2
- package/kits/hub-game/code/server/act.js +3 -0
- package/kits/hub-game/code/server/actGate.js +83 -0
- package/kits/hub-game/code/server/actions.js +71 -15
- package/kits/hub-game/code/server/actors.js +20 -5
- package/kits/hub-game/code/server/analytics.js +40 -15
- package/kits/hub-game/code/server/ask.js +39 -3
- package/kits/hub-game/code/server/ballot.js +167 -4
- package/kits/hub-game/code/server/celebrate.js +64 -0
- package/kits/hub-game/code/server/companion.js +17 -2
- package/kits/hub-game/code/server/decor.js +11 -2
- package/kits/hub-game/code/server/disguise.js +63 -0
- package/kits/hub-game/code/server/doorAnalytics.js +2 -5
- package/kits/hub-game/code/server/earned.js +6 -2
- package/kits/hub-game/code/server/friendBests.js +13 -4
- package/kits/hub-game/code/server/friendsAmong.js +67 -8
- package/kits/hub-game/code/server/grab.js +12 -2
- package/kits/hub-game/code/server/heldOffers.js +142 -0
- package/kits/hub-game/code/server/holdShow.js +98 -0
- package/kits/hub-game/code/server/hub.js +854 -45
- package/kits/hub-game/code/server/idle.js +110 -9
- package/kits/hub-game/code/server/index.js +9 -0
- package/kits/hub-game/code/server/labels.js +13 -3
- package/kits/hub-game/code/server/loadAbandon.js +2 -5
- package/kits/hub-game/code/server/manifest.js +94 -6
- package/kits/hub-game/code/server/menu.js +26 -3
- package/kits/hub-game/code/server/npcs.js +55 -9
- package/kits/hub-game/code/server/observe.js +67 -6
- package/kits/hub-game/code/server/players.js +8 -1
- package/kits/hub-game/code/server/replay.js +135 -0
- package/kits/hub-game/code/server/storageLimit.js +4 -1
- package/kits/hub-game/code/server/townDay.js +74 -0
- package/kits/hub-game/code/server/trackQueue.js +29 -0
- package/kits/hub-game/code/server/vehicle.js +3 -0
- package/kits/hub-game/code/server/vis.js +26 -4
- package/kits/hub-game/code/server/wallet.js +677 -0
- package/kits/hub-game/code/server/wear.js +13 -3
- package/kits/hub-game/code/server/writerLease.js +191 -0
- package/kits/hub-game/code/shared/act.js +1 -1
- package/kits/hub-game/code/shared/expression.js +6 -0
- package/kits/hub-game/code/shared/replay.js +37 -0
- package/kits/hub-game/code/systems/hub.js +437 -57
- package/kits/hub-game/docs/analytics.md +20 -3
- package/kits/hub-game/docs/contract.md +942 -99
- package/kits/hub-game/docs/home-pieces.md +5 -6
- package/kits/hub-game/docs/observed-progress.md +49 -1
- package/kits/hub-game/docs/vehicle-preset.md +23 -0
- package/kits/hub-game/index.html +1 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
- package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
- package/kits/hub-game/models/hats/cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/captain.pxmodel +3 -3
- package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
- package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
- package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
- package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
- package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
- package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
- package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
- package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
- package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
- package/kits/hub-game/models/hats/straw.pxmodel +3 -3
- package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
- package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
- package/kits/hub-game/models/hats/witch.pxmodel +3 -3
- package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
- package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
- package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
- package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
- package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
- package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
- package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
- package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
- package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
- package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
- package/kits/hub-game/package-lock.json +3 -3
- package/kits/hub-game/package.json +4 -3
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
- package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
- package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
- package/kits/hub-game/scripts/gen-hats.mjs +1 -1
- package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
- package/kits/hub-game/scripts/pack.mjs +89 -23
- package/kits/hub-game/scripts/test-act-client.mjs +5 -0
- package/kits/hub-game/scripts/test-act-core.mjs +32 -0
- package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
- package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
- package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
- package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
- package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
- package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
- package/kits/hub-game/scripts/test-actions.mjs +24 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -0
- package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
- package/kits/hub-game/scripts/test-analytics.mjs +80 -1
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
- package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
- package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
- package/kits/hub-game/scripts/test-attention.mjs +43 -1
- package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
- package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
- package/kits/hub-game/scripts/test-ballot.mjs +420 -3
- package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
- package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
- package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
- package/kits/hub-game/scripts/test-chat.mjs +73 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
- package/kits/hub-game/scripts/test-companion.mjs +110 -3
- package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
- package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
- package/kits/hub-game/scripts/test-decor.mjs +27 -0
- package/kits/hub-game/scripts/test-device-class.mjs +4 -1
- package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
- package/kits/hub-game/scripts/test-disguise.mjs +176 -0
- package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
- package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
- package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
- package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
- package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
- package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
- package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
- package/kits/hub-game/scripts/test-grab.mjs +10 -1
- package/kits/hub-game/scripts/test-hats.mjs +28 -0
- package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
- package/kits/hub-game/scripts/test-high-only.mjs +3 -3
- package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
- package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
- package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +147 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +260 -5
- package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
- package/kits/hub-game/scripts/test-idle.mjs +160 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
- package/kits/hub-game/scripts/test-labels.mjs +11 -0
- package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
- package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
- package/kits/hub-game/scripts/test-manifest.mjs +27 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +55 -6
- package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
- package/kits/hub-game/scripts/test-npcs.mjs +128 -0
- package/kits/hub-game/scripts/test-observed.mjs +171 -3
- package/kits/hub-game/scripts/test-pack.mjs +166 -0
- package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
- package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
- package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
- package/kits/hub-game/scripts/test-quality.mjs +312 -9
- package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
- package/kits/hub-game/scripts/test-rehello.mjs +237 -0
- package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
- package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
- package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
- package/kits/hub-game/scripts/test-replay.mjs +178 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
- package/kits/hub-game/scripts/test-resync.mjs +13 -0
- package/kits/hub-game/scripts/test-role-client.mjs +10 -3
- package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
- package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
- package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
- package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
- package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
- package/kits/hub-game/scripts/test-stuck.mjs +31 -0
- package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
- package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
- package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
- package/kits/hub-game/scripts/test-tiers.mjs +453 -3
- package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
- package/kits/hub-game/scripts/test-together.mjs +11 -0
- package/kits/hub-game/scripts/test-town-day.mjs +90 -0
- package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
- package/kits/hub-game/scripts/test-try-on.mjs +39 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
- package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +77 -1
- package/kits/hub-game/scripts/test-vis.mjs +145 -0
- package/kits/hub-game/scripts/test-wallet.mjs +650 -0
- package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
- package/kits/hub-game/scripts/test-world-labels.mjs +380 -0
- package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
- package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
- package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
- package/kits/hub-game/tools/hubScene/export.mjs +6 -5
- package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +48 -2
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +21 -3
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
- package/kits/multiplayer-3d/code/server/ownership.js +25 -6
- package/kits/multiplayer-3d/code/server/world.js +19 -4
- package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
- package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
- package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +10 -2
- package/kits/physics-3d/CLAUDE.md +14 -0
- package/kits/physics-3d/behaviors/Player.jsx +39 -3
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-model-cache.md +109 -0
- package/kits/physics-3d/docs/engine-player.md +76 -0
- package/kits/physics-3d/docs/engine-skip-work.md +16 -0
- package/kits/physics-3d/docs/pxmodel-format.md +5 -1
- package/kits/physics-3d/engine3d/gait.js +16 -8
- package/kits/physics-3d/engine3d/groundsize.js +23 -0
- package/kits/physics-3d/engine3d/kithooks.js +50 -0
- package/kits/physics-3d/engine3d/look.js +110 -17
- package/kits/physics-3d/engine3d/lookbake.js +19 -1
- package/kits/physics-3d/engine3d/materialpresets.js +3 -2
- package/kits/physics-3d/engine3d/modelcache.js +280 -0
- package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
- package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
- package/kits/physics-3d/engine3d/modelrefs.js +13 -0
- package/kits/physics-3d/engine3d/optimize.js +20 -9
- package/kits/physics-3d/engine3d/playerRun.js +26 -1
- package/kits/physics-3d/engine3d/pxmodel.js +7 -3
- package/kits/physics-3d/engine3d/templatecache.js +722 -0
- package/kits/physics-3d/engine3d/world3d.js +211 -17
- package/kits/physics-3d/package-lock.json +1 -1
- package/kits/physics-3d/package.json +2 -1
- package/kits/physics-3d/play/behaviors/Player.js +43 -3
- package/kits/physics-3d/scripts/render.mjs +56 -8
- package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
- package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
- package/kits/physics-3d/scripts/test-gait.mjs +53 -9
- package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
- package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
- package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
- package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
- package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
- package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
- package/kits/physics-3d/systems/physics3d.js +51 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +3 -0
- package/package.json +2 -2
- package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
|
@@ -19,9 +19,25 @@ export interface StoreAllowance {
|
|
|
19
19
|
byteCount: number;
|
|
20
20
|
byteLimit: number;
|
|
21
21
|
}
|
|
22
|
+
/** One storage rate window: what was spent in the current second, and its limits. */
|
|
23
|
+
export interface StoreRateBudget {
|
|
24
|
+
opsUsed: number;
|
|
25
|
+
opsLimit: number;
|
|
26
|
+
bytesUsed: number;
|
|
27
|
+
bytesLimit: number;
|
|
28
|
+
}
|
|
29
|
+
/** The storage rate windows a call is charged against. */
|
|
30
|
+
export interface StoreRateUsage {
|
|
31
|
+
/** Which caller bucket answered: "client", "server", "session" or "town-layer". */
|
|
32
|
+
callerClass: string;
|
|
33
|
+
caller: StoreRateBudget;
|
|
34
|
+
deck: StoreRateBudget;
|
|
35
|
+
}
|
|
22
36
|
export interface StoreAllowances {
|
|
23
37
|
player: StoreAllowance;
|
|
24
38
|
shared: StoreAllowance;
|
|
39
|
+
/** Absent from a host older than the rate field. */
|
|
40
|
+
rate?: StoreRateUsage;
|
|
25
41
|
}
|
|
26
42
|
export interface StoreBoardEntry {
|
|
27
43
|
subject: string;
|
|
@@ -96,6 +112,19 @@ export interface SocialPresence extends SocialFriend {
|
|
|
96
112
|
slot?: string;
|
|
97
113
|
updatedAt: string;
|
|
98
114
|
}
|
|
115
|
+
/** One public room of the current deck, as Castle last counted it. */
|
|
116
|
+
export interface RoomSummary {
|
|
117
|
+
sessionId: string;
|
|
118
|
+
routeId?: string;
|
|
119
|
+
slot?: string;
|
|
120
|
+
players: number;
|
|
121
|
+
maxPlayers: number;
|
|
122
|
+
}
|
|
123
|
+
export interface RoomsListResult {
|
|
124
|
+
/** Players across every room listed. */
|
|
125
|
+
total: number;
|
|
126
|
+
rooms: RoomSummary[];
|
|
127
|
+
}
|
|
99
128
|
export type PartyStatus = "invited" | "joined" | "rejected" | "left" | "party_closed" | "banned";
|
|
100
129
|
export interface PartySummary {
|
|
101
130
|
partyId: string;
|
|
@@ -209,6 +238,15 @@ export interface HubSignInResult {
|
|
|
209
238
|
status: "signedIn" | "dismissed" | "unavailable";
|
|
210
239
|
userId?: string;
|
|
211
240
|
}
|
|
241
|
+
export interface HubPushPermissionResult {
|
|
242
|
+
status: "granted" | "denied" | "unavailable";
|
|
243
|
+
}
|
|
244
|
+
export type HubPushDestinationResult = {
|
|
245
|
+
notificationId: string;
|
|
246
|
+
townDeckId: string;
|
|
247
|
+
} | {
|
|
248
|
+
status: "unavailable";
|
|
249
|
+
};
|
|
212
250
|
export type HubFriendsResult = {
|
|
213
251
|
status: "ok";
|
|
214
252
|
friends: HubFriend[];
|
|
@@ -237,6 +275,13 @@ export type HubCanInviteResult = {
|
|
|
237
275
|
status: "unavailable";
|
|
238
276
|
canInvite: false;
|
|
239
277
|
};
|
|
278
|
+
/** Viewer invite-gate availability, without exposing the gate map. */
|
|
279
|
+
export type HubInviteAvailableResult = {
|
|
280
|
+
status: "ok";
|
|
281
|
+
available: boolean;
|
|
282
|
+
} | {
|
|
283
|
+
status: "unavailable";
|
|
284
|
+
};
|
|
240
285
|
export interface HubInviteArrivalResult {
|
|
241
286
|
status: "ok" | "unavailable" | "route";
|
|
242
287
|
doorId?: string;
|
|
@@ -364,6 +409,17 @@ export interface HubEventEnvelope {
|
|
|
364
409
|
castleSdk: typeof CASTLE_SDK_PROTOCOL;
|
|
365
410
|
hub: HubEvent;
|
|
366
411
|
}
|
|
412
|
+
export type HubGoFailedWhy = "refused" | "content" | "join";
|
|
413
|
+
export type HubGoFailedEvent = {
|
|
414
|
+
type: "goFailed";
|
|
415
|
+
doorId: string;
|
|
416
|
+
owner?: string;
|
|
417
|
+
why: HubGoFailedWhy;
|
|
418
|
+
};
|
|
419
|
+
export interface HubGoFailedEnvelope {
|
|
420
|
+
castleSdk: typeof CASTLE_SDK_PROTOCOL;
|
|
421
|
+
hub: HubGoFailedEvent;
|
|
422
|
+
}
|
|
367
423
|
export declare function hubEventFrom(value: unknown): HubEvent | null;
|
|
368
424
|
export type HapticStyle = "light" | "medium" | "heavy" | "selection" | "success" | "warning" | "error";
|
|
369
425
|
export type HapticsStatus = "triggered" | "unavailable";
|
|
@@ -614,6 +670,14 @@ export interface CommandParams {
|
|
|
614
670
|
userId: string;
|
|
615
671
|
};
|
|
616
672
|
"experiments.get": Record<string, never>;
|
|
673
|
+
"experiments.exposed": {
|
|
674
|
+
name: string;
|
|
675
|
+
variant: string;
|
|
676
|
+
};
|
|
677
|
+
"analytics.event": {
|
|
678
|
+
name: string;
|
|
679
|
+
properties: Record<string, number>;
|
|
680
|
+
};
|
|
617
681
|
"time.getServerTime": Record<string, never>;
|
|
618
682
|
"pass.has": {
|
|
619
683
|
passId: string;
|
|
@@ -676,6 +740,7 @@ export interface CommandParams {
|
|
|
676
740
|
crew?: boolean;
|
|
677
741
|
};
|
|
678
742
|
"hub.canInvite": Record<string, never>;
|
|
743
|
+
"hub.inviteAvailable": Record<string, never>;
|
|
679
744
|
"hub.inviteArrival": Record<string, never>;
|
|
680
745
|
"hub.undoInvite": {
|
|
681
746
|
userId: string;
|
|
@@ -685,6 +750,8 @@ export interface CommandParams {
|
|
|
685
750
|
doorIds: string[];
|
|
686
751
|
};
|
|
687
752
|
"hub.signIn": HubSignInParams;
|
|
753
|
+
"hub.pushPermission": Record<string, never>;
|
|
754
|
+
"hub.pushDestination": Record<string, never>;
|
|
688
755
|
"hub.jump": HubJumpParams;
|
|
689
756
|
"hub.report": HubReportParams;
|
|
690
757
|
"hub.chat": HubChatParams;
|
|
@@ -799,6 +866,7 @@ export interface CommandParams {
|
|
|
799
866
|
subject?: string | null;
|
|
800
867
|
};
|
|
801
868
|
"cauldronStorage.usage": Record<string, never>;
|
|
869
|
+
"rooms.list": Record<string, never>;
|
|
802
870
|
"lifecycle.restoreState": Record<string, never>;
|
|
803
871
|
"localCache.get": {
|
|
804
872
|
key: string;
|
|
@@ -848,6 +916,12 @@ export interface CommandResult {
|
|
|
848
916
|
"experiments.get": {
|
|
849
917
|
variants: Record<string, string>;
|
|
850
918
|
};
|
|
919
|
+
"experiments.exposed": {
|
|
920
|
+
recorded: boolean;
|
|
921
|
+
};
|
|
922
|
+
"analytics.event": {
|
|
923
|
+
recorded: boolean;
|
|
924
|
+
};
|
|
851
925
|
"time.getServerTime": {
|
|
852
926
|
timestamp: number;
|
|
853
927
|
timezoneOffset: number;
|
|
@@ -885,11 +959,14 @@ export interface CommandResult {
|
|
|
885
959
|
"hub.friends": HubFriendsResult;
|
|
886
960
|
"hub.invite": HubInviteResult;
|
|
887
961
|
"hub.canInvite": HubCanInviteResult;
|
|
962
|
+
"hub.inviteAvailable": HubInviteAvailableResult;
|
|
888
963
|
"hub.inviteArrival": HubInviteArrivalResult;
|
|
889
964
|
"hub.undoInvite": HubReportResult;
|
|
890
965
|
"hub.hearts": HubHeartsResult;
|
|
891
966
|
"hub.setHearts": HubHeartsResult;
|
|
892
967
|
"hub.signIn": HubSignInResult;
|
|
968
|
+
"hub.pushPermission": HubPushPermissionResult;
|
|
969
|
+
"hub.pushDestination": HubPushDestinationResult;
|
|
893
970
|
"hub.jump": HubJumpResult;
|
|
894
971
|
"hub.report": HubReportResult;
|
|
895
972
|
"hub.chat": HubChatResult;
|
|
@@ -956,6 +1033,7 @@ export interface CommandResult {
|
|
|
956
1033
|
"cauldronStorage.usage": {
|
|
957
1034
|
usage: StoreAllowances;
|
|
958
1035
|
};
|
|
1036
|
+
"rooms.list": RoomsListResult | null;
|
|
959
1037
|
"lifecycle.restoreState": LifecycleRestoreStateResult;
|
|
960
1038
|
"localCache.get": {
|
|
961
1039
|
value: ArrayBuffer | string | null;
|
|
@@ -1000,6 +1078,7 @@ export interface CommandResponseEnvelope {
|
|
|
1000
1078
|
ok: boolean;
|
|
1001
1079
|
data?: unknown;
|
|
1002
1080
|
error?: SerializedCommandError;
|
|
1081
|
+
hubPushReceipt?: string;
|
|
1003
1082
|
}
|
|
1004
1083
|
export declare function isResponseEnvelope(value: unknown): value is CommandResponseEnvelope;
|
|
1005
1084
|
export interface CommandStreamEnvelope {
|
|
@@ -55,6 +55,7 @@ export const COMMAND_TIMEOUTS_MS = {
|
|
|
55
55
|
// Native auth may include a provider handoff, but it must not leave a deck
|
|
56
56
|
// waiting forever if the host loses the completion callback.
|
|
57
57
|
"hub.signIn": 120_000,
|
|
58
|
+
"hub.pushPermission": 120_000,
|
|
58
59
|
// A large entry is an IndexedDB read or write plus a copy into the other
|
|
59
60
|
// frame, and can wait behind other tabs' writes to the same store.
|
|
60
61
|
"localCache.get": 60_000,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type DebugConsoleLevel = "log" | "warn" | "error";
|
|
2
|
+
export interface DebugConsoleLine {
|
|
3
|
+
level: DebugConsoleLevel;
|
|
4
|
+
text: string;
|
|
5
|
+
/** `Date.now()` when the line was written. */
|
|
6
|
+
time: number;
|
|
7
|
+
}
|
|
8
|
+
export interface DebugConsoleApi {
|
|
9
|
+
show(): void;
|
|
10
|
+
hide(): void;
|
|
11
|
+
lines(): DebugConsoleLine[];
|
|
12
|
+
}
|
|
13
|
+
export declare function formatConsoleArgs(args: unknown[]): string;
|
|
14
|
+
export declare function recordConsoleLine(level: DebugConsoleLevel, text: string): void;
|
|
15
|
+
export declare function noteConsoleHooked(): void;
|
|
16
|
+
export declare function captureErrors(): void;
|
|
17
|
+
export declare const DebugConsole: DebugConsoleApi;
|
|
@@ -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
|
-
|
|
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
|
+
}
|
package/kits/base/sdk/hub.d.ts
CHANGED
|
@@ -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 {
|
package/kits/base/sdk/hub.js
CHANGED
|
@@ -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`
|
|
45
|
-
|
|
46
|
-
async function untilListed(ask) {
|
|
47
|
-
const
|
|
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 (
|
|
54
|
-
return {
|
|
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
|
-
|
|
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) {
|