@ksaa-nlp/gamehub-sdk 4.5.0 → 5.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +103 -48
  2. package/SPEC.md +230 -57
  3. package/dist/gamehub-sdk.js +1 -1458
  4. package/dist/gamehub-sdk.js.map +4 -4
  5. package/dist/src/answers.d.ts +22 -0
  6. package/dist/src/answers.d.ts.map +1 -0
  7. package/dist/src/answers.js +139 -0
  8. package/dist/src/answers.js.map +1 -0
  9. package/dist/src/bot-driver.d.ts +2 -1
  10. package/dist/src/bot-driver.d.ts.map +1 -1
  11. package/dist/src/bot-driver.js +11 -1
  12. package/dist/src/bot-driver.js.map +1 -1
  13. package/dist/src/bridge.d.ts.map +1 -1
  14. package/dist/src/bridge.js +2 -35
  15. package/dist/src/bridge.js.map +1 -1
  16. package/dist/src/constants.d.ts +1 -1
  17. package/dist/src/constants.js +1 -1
  18. package/dist/src/init.js +7 -7
  19. package/dist/src/init.js.map +1 -1
  20. package/dist/src/loading.d.ts +5 -0
  21. package/dist/src/loading.d.ts.map +1 -0
  22. package/dist/src/loading.js +54 -0
  23. package/dist/src/loading.js.map +1 -0
  24. package/dist/src/main.d.ts +14 -3
  25. package/dist/src/main.d.ts.map +1 -1
  26. package/dist/src/main.js +12 -4
  27. package/dist/src/main.js.map +1 -1
  28. package/dist/src/multiplayer-client.d.ts +52 -0
  29. package/dist/src/multiplayer-client.d.ts.map +1 -0
  30. package/dist/src/multiplayer-client.js +286 -0
  31. package/dist/src/multiplayer-client.js.map +1 -0
  32. package/dist/src/multiplayer-entry.d.ts +9 -0
  33. package/dist/src/multiplayer-entry.d.ts.map +1 -0
  34. package/dist/src/multiplayer-entry.js +9 -0
  35. package/dist/src/multiplayer-entry.js.map +1 -0
  36. package/dist/src/multiplayer-session.d.ts.map +1 -1
  37. package/dist/src/multiplayer-session.js +3 -3
  38. package/dist/src/multiplayer-session.js.map +1 -1
  39. package/dist/src/multiplayer.d.ts.map +1 -1
  40. package/dist/src/multiplayer.js +2 -1
  41. package/dist/src/multiplayer.js.map +1 -1
  42. package/dist/src/session.d.ts.map +1 -1
  43. package/dist/src/session.js +28 -7
  44. package/dist/src/session.js.map +1 -1
  45. package/dist/src/state.d.ts +1 -2
  46. package/dist/src/state.d.ts.map +1 -1
  47. package/dist/src/state.js +0 -1
  48. package/dist/src/state.js.map +1 -1
  49. package/dist/types/bootstrap.d.ts +8 -45
  50. package/dist/types/bootstrap.d.ts.map +1 -1
  51. package/dist/types/loading.d.ts +6 -0
  52. package/dist/types/loading.d.ts.map +1 -0
  53. package/dist/types/loading.js +2 -0
  54. package/dist/types/loading.js.map +1 -0
  55. package/dist/types/multiplayer-session.d.ts +9 -8
  56. package/dist/types/multiplayer-session.d.ts.map +1 -1
  57. package/dist/types/question.d.ts +0 -1
  58. package/dist/types/question.d.ts.map +1 -1
  59. package/dist/types/question.js +0 -1
  60. package/dist/types/question.js.map +1 -1
  61. package/dist/types/session.d.ts +16 -0
  62. package/dist/types/session.d.ts.map +1 -1
  63. package/dist/vendor/colyseus-schemas/clock.d.ts +15 -0
  64. package/dist/vendor/colyseus-schemas/clock.js +67 -0
  65. package/dist/vendor/colyseus-schemas/common.d.ts +35 -0
  66. package/dist/vendor/colyseus-schemas/common.js +15 -0
  67. package/dist/vendor/colyseus-schemas/multiplayer.d.ts +8 -0
  68. package/dist/vendor/colyseus-schemas/multiplayer.js +26 -0
  69. package/dist/vendor/colyseus-schemas/ugc.d.ts +53 -0
  70. package/dist/vendor/colyseus-schemas/ugc.js +124 -0
  71. package/dist/vendor/gamehub-multiplayer-contracts/index.d.ts +200 -0
  72. package/dist/vendor/gamehub-multiplayer-contracts/index.js +289 -0
  73. package/package.json +34 -4
@@ -0,0 +1,26 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { type, MapSchema } from '@colyseus/schema';
8
+ import { UgcState } from './ugc.js';
9
+ /** Isolated v2 schema identity. Legacy/Unity room wire layouts do not change. */
10
+ export class MultiplayerState extends UgcState {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.roundId = '';
14
+ this.roundPhase = 'loading';
15
+ this.participantKinds = new MapSchema();
16
+ }
17
+ }
18
+ __decorate([
19
+ type('string')
20
+ ], MultiplayerState.prototype, "roundId", void 0);
21
+ __decorate([
22
+ type('string')
23
+ ], MultiplayerState.prototype, "roundPhase", void 0);
24
+ __decorate([
25
+ type({ map: 'string' })
26
+ ], MultiplayerState.prototype, "participantKinds", void 0);
@@ -0,0 +1,53 @@
1
+ /**
2
+ * `UgcState` schema for the `ugc` engine — user-uploaded games whose
3
+ * authoritative server logic runs inside an `isolated-vm` sandbox on the
4
+ * colyseus side. The platform-wide `allowUgcServerLogic` setting AND the
5
+ * per-game `serverLogicApproved` flag must both be true for a room to be
6
+ * created on this engine; otherwise the game falls back to relay.
7
+ *
8
+ * The lobby roster + lifecycle phase mirror the relay engine. Game-defined
9
+ * state is exposed as a `MapSchema` of opaque JSON-encoded values keyed by
10
+ * top-level property name. Game authors mutate `ctx.state.<key> = value`
11
+ * inside the sandbox; the host serializes each top-level value to JSON
12
+ * once per dispatch and writes the result into `state.game`.
13
+ *
14
+ * Storing JSON-encoded scalars/objects (instead of registering arbitrary
15
+ * schemas at runtime) is what lets games ship state of any shape without
16
+ * authoring `@colyseus/schema` classes. The trade-off: a top-level key
17
+ * whose value mutates anywhere in its subtree re-sends the entire JSON
18
+ * blob for that key. Game authors who care about granular updates should
19
+ * shard their state across multiple top-level keys.
20
+ */
21
+ import { Schema, ArraySchema, MapSchema } from '@colyseus/schema';
22
+ import type { Phase } from './common.js';
23
+ export declare class UgcPlayer extends Schema {
24
+ peerId: string;
25
+ userId: string;
26
+ displayName: string;
27
+ avatar: string;
28
+ online: boolean;
29
+ ready: boolean;
30
+ joinedAt: number;
31
+ }
32
+ /** One entry in `UgcState.game`. The value is `JSON.stringify(...)` of any
33
+ * JSON-serializable subtree the guest assigned to that top-level key. */
34
+ export declare class UgcStateValue extends Schema {
35
+ json: string;
36
+ }
37
+ export declare class UgcState extends Schema {
38
+ phase: Phase;
39
+ roomCode: string;
40
+ hostPeerId: string;
41
+ maxPlayers: number;
42
+ createdAt: number;
43
+ startedAtMs: number;
44
+ endedAtMs: number;
45
+ /** Slug of the loaded UGC game. Diagnostic field; matches metadata.gameSlug. */
46
+ gameSlug: string;
47
+ /** sha256 of the currently running server bundle. Lets clients verify the
48
+ * authoritative code matches the version a moderator approved. */
49
+ serverBundleHash: string;
50
+ players: ArraySchema<UgcPlayer>;
51
+ /** Game-defined top-level keys. Each value is a JSON-encoded scalar/object. */
52
+ game: MapSchema<UgcStateValue, string>;
53
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * `UgcState` schema for the `ugc` engine — user-uploaded games whose
3
+ * authoritative server logic runs inside an `isolated-vm` sandbox on the
4
+ * colyseus side. The platform-wide `allowUgcServerLogic` setting AND the
5
+ * per-game `serverLogicApproved` flag must both be true for a room to be
6
+ * created on this engine; otherwise the game falls back to relay.
7
+ *
8
+ * The lobby roster + lifecycle phase mirror the relay engine. Game-defined
9
+ * state is exposed as a `MapSchema` of opaque JSON-encoded values keyed by
10
+ * top-level property name. Game authors mutate `ctx.state.<key> = value`
11
+ * inside the sandbox; the host serializes each top-level value to JSON
12
+ * once per dispatch and writes the result into `state.game`.
13
+ *
14
+ * Storing JSON-encoded scalars/objects (instead of registering arbitrary
15
+ * schemas at runtime) is what lets games ship state of any shape without
16
+ * authoring `@colyseus/schema` classes. The trade-off: a top-level key
17
+ * whose value mutates anywhere in its subtree re-sends the entire JSON
18
+ * blob for that key. Game authors who care about granular updates should
19
+ * shard their state across multiple top-level keys.
20
+ */
21
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
22
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
23
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
24
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
25
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
26
+ };
27
+ import { Schema, type, ArraySchema, MapSchema } from '@colyseus/schema';
28
+ export class UgcPlayer extends Schema {
29
+ constructor() {
30
+ super(...arguments);
31
+ this.peerId = '';
32
+ this.userId = '';
33
+ this.displayName = '';
34
+ this.avatar = '';
35
+ this.online = true;
36
+ this.ready = false;
37
+ this.joinedAt = 0;
38
+ }
39
+ }
40
+ __decorate([
41
+ type('string')
42
+ ], UgcPlayer.prototype, "peerId", void 0);
43
+ __decorate([
44
+ type('string')
45
+ ], UgcPlayer.prototype, "userId", void 0);
46
+ __decorate([
47
+ type('string')
48
+ ], UgcPlayer.prototype, "displayName", void 0);
49
+ __decorate([
50
+ type('string')
51
+ ], UgcPlayer.prototype, "avatar", void 0);
52
+ __decorate([
53
+ type('boolean')
54
+ ], UgcPlayer.prototype, "online", void 0);
55
+ __decorate([
56
+ type('boolean')
57
+ ], UgcPlayer.prototype, "ready", void 0);
58
+ __decorate([
59
+ type('number')
60
+ ], UgcPlayer.prototype, "joinedAt", void 0);
61
+ /** One entry in `UgcState.game`. The value is `JSON.stringify(...)` of any
62
+ * JSON-serializable subtree the guest assigned to that top-level key. */
63
+ export class UgcStateValue extends Schema {
64
+ constructor() {
65
+ super(...arguments);
66
+ this.json = '';
67
+ }
68
+ }
69
+ __decorate([
70
+ type('string')
71
+ ], UgcStateValue.prototype, "json", void 0);
72
+ export class UgcState extends Schema {
73
+ constructor() {
74
+ super(...arguments);
75
+ this.phase = 'lobby';
76
+ this.roomCode = '';
77
+ this.hostPeerId = '';
78
+ this.maxPlayers = 2;
79
+ this.createdAt = 0;
80
+ this.startedAtMs = 0;
81
+ this.endedAtMs = 0;
82
+ /** Slug of the loaded UGC game. Diagnostic field; matches metadata.gameSlug. */
83
+ this.gameSlug = '';
84
+ /** sha256 of the currently running server bundle. Lets clients verify the
85
+ * authoritative code matches the version a moderator approved. */
86
+ this.serverBundleHash = '';
87
+ this.players = new ArraySchema();
88
+ /** Game-defined top-level keys. Each value is a JSON-encoded scalar/object. */
89
+ this.game = new MapSchema();
90
+ }
91
+ }
92
+ __decorate([
93
+ type('string')
94
+ ], UgcState.prototype, "phase", void 0);
95
+ __decorate([
96
+ type('string')
97
+ ], UgcState.prototype, "roomCode", void 0);
98
+ __decorate([
99
+ type('string')
100
+ ], UgcState.prototype, "hostPeerId", void 0);
101
+ __decorate([
102
+ type('number')
103
+ ], UgcState.prototype, "maxPlayers", void 0);
104
+ __decorate([
105
+ type('number')
106
+ ], UgcState.prototype, "createdAt", void 0);
107
+ __decorate([
108
+ type('number')
109
+ ], UgcState.prototype, "startedAtMs", void 0);
110
+ __decorate([
111
+ type('number')
112
+ ], UgcState.prototype, "endedAtMs", void 0);
113
+ __decorate([
114
+ type('string')
115
+ ], UgcState.prototype, "gameSlug", void 0);
116
+ __decorate([
117
+ type('string')
118
+ ], UgcState.prototype, "serverBundleHash", void 0);
119
+ __decorate([
120
+ type([UgcPlayer])
121
+ ], UgcState.prototype, "players", void 0);
122
+ __decorate([
123
+ type({ map: UgcStateValue })
124
+ ], UgcState.prototype, "game", void 0);
@@ -0,0 +1,200 @@
1
+ /** Plain-data v2 wire contract. This entry must remain dependency and side-effect free. */
2
+ export declare const LAUNCH_VERSION: 2;
3
+ export declare const MULTIPLAYER_CAPABILITY: "multiplayer.launch.v2";
4
+ export declare const MULTIPLAYER_LOBBY_CAPABILITY: "multiplayer.lobby.v2";
5
+ export type LobbyMode = 'platform' | 'game';
6
+ export declare const CONTROL_TIMEOUT_MS = 10000;
7
+ export declare const ARRIVAL_WINDOW_MS = 90000;
8
+ export declare const RECOVERY_GRACE_MS = 60000;
9
+ export declare const RESERVATION_LEASE_MS = 15000;
10
+ export type ParticipantKind = 'human' | 'bot';
11
+ export declare const BOT_LEVELS: readonly ["easy", "medium", "hard"];
12
+ export type BotLevel = (typeof BOT_LEVELS)[number];
13
+ /** Bots stored before levels existed play at `medium`. */
14
+ export declare const DEFAULT_BOT_LEVEL: BotLevel;
15
+ export declare const isBotLevel: (value: unknown) => value is BotLevel;
16
+ /** UGC bots are game-owned; quiz bots are played by the built-in engine. Relay has none. */
17
+ export declare const BOT_ENGINES: readonly Engine[];
18
+ export interface PlayerPolicy {
19
+ minPlayers: number;
20
+ maxPlayers: number;
21
+ minHumanPlayers: number;
22
+ maxBots: number;
23
+ maxSpectators: number;
24
+ }
25
+ /** Missing policy identifies an existing two-human v2 package/round. */
26
+ export declare function playerPolicy(binding: {
27
+ playerPolicy?: PlayerPolicy;
28
+ }): PlayerPolicy;
29
+ export declare function parsePlayerPolicy(manifest: Record<string, unknown>, ceiling?: number): PlayerPolicy;
30
+ export type SeatType = 'player' | 'spectator';
31
+ export type SessionPhase = 'waiting' | 'in_round' | 'completed' | 'closed';
32
+ export type RoundPhase = 'preparing' | 'loading' | 'playing' | 'finishing' | 'completed' | 'aborted' | 'interrupted';
33
+ export type Authority = 'server' | 'unverified';
34
+ export type Engine = 'ugc' | 'quiz-template' | 'relay';
35
+ export interface PackageBinding {
36
+ lobbyMode?: LobbyMode;
37
+ /** Manifest lobbyUi:"game" capability required when the admin selects a game-owned lobby. */
38
+ gameLobbySupported?: boolean;
39
+ playerPolicy?: PlayerPolicy;
40
+ gameId: string;
41
+ gameSlug: string;
42
+ ownerId: string;
43
+ versionId: string;
44
+ versionKey: string;
45
+ contentHash: string;
46
+ serverHash: string | null;
47
+ gameUrl: string;
48
+ engine: Engine;
49
+ protocol: 'gamehub.v2';
50
+ scorePolicy?: 'history-only' | 'account';
51
+ profileId?: string | null;
52
+ questions?: 'none' | 'required';
53
+ }
54
+ export interface Seat {
55
+ /** Omitted only on records created before participant support; means human. */
56
+ kind?: ParticipantKind;
57
+ /** Bot seats only; omitted on bots created before levels means `medium`. */
58
+ botLevel?: BotLevel;
59
+ seatId: string;
60
+ displayName: string;
61
+ type: SeatType;
62
+ ready: boolean;
63
+ online: boolean;
64
+ status: 'joined' | 'left' | 'removed';
65
+ }
66
+ export interface LaunchReference {
67
+ recoveryGraceMs?: number;
68
+ version: 2;
69
+ multiplayerSessionId: string;
70
+ roundId: string;
71
+ attemptId: string;
72
+ seatId: string;
73
+ hostInstanceId: string;
74
+ gameUrl: string;
75
+ scoreAuthority: Authority;
76
+ }
77
+ export interface Reservation {
78
+ name: string;
79
+ roomId: string;
80
+ sessionId: string;
81
+ processId?: string;
82
+ publicAddress?: string;
83
+ }
84
+ export declare const ERROR_CODES: readonly ["INVALID_REQUEST", "UNAUTHORIZED", "LOGIN_REQUIRED", "FORBIDDEN", "NOT_FOUND", "GAME_MISMATCH", "GAME_UNAVAILABLE", "NO_QUESTIONS", "PROTOCOL_UNSUPPORTED", "PASSCODE_REQUIRED", "INVALID_PASSCODE", "ROOM_FULL", "SEAT_REMOVED", "SEAT_LEFT", "ROSTER_FROZEN", "NOT_HOST", "STALE_REVISION", "NOT_READY", "STALE_ATTEMPT", "STALE_GENERATION", "ALREADY_CONNECTED", "LAUNCH_PENDING", "LAUNCH_EXPIRED", "ARRIVAL_TIMEOUT", "RECOVERY_EXPIRED", "INTERRUPTED", "ROUND_TERMINAL", "RESULT_CONFLICT", "INVALID_RESULT", "RATE_LIMITED", "UNAVAILABLE", "CANCELLED", "STORAGE_UNAVAILABLE"];
85
+ export type ErrorCode = (typeof ERROR_CODES)[number];
86
+ export interface MultiplayerError {
87
+ code: ErrorCode;
88
+ retryable: boolean;
89
+ message: string;
90
+ phase?: RoundPhase | SessionPhase;
91
+ retryAfterMs?: number;
92
+ }
93
+ export declare class MultiplayerFault extends Error {
94
+ readonly code: ErrorCode;
95
+ readonly retryable: boolean;
96
+ readonly status: number;
97
+ constructor(code: ErrorCode, retryable?: boolean, status?: number);
98
+ toJSON(): MultiplayerError;
99
+ }
100
+ export type LaunchOutcome = {
101
+ status: 'reserved';
102
+ launch: LaunchReference;
103
+ reservation: Reservation;
104
+ wsEndpoint: string;
105
+ generation: number;
106
+ expiresAt: number;
107
+ } | {
108
+ status: 'recoverable' | 'terminal';
109
+ error: MultiplayerError;
110
+ };
111
+ export interface SessionView {
112
+ /** Normal rooms use host Start without confirmations; party/league retain readiness. */
113
+ lobbyReadyRequired?: boolean;
114
+ /** Derived public website URLs. Absent/null outside waiting or for invalid site configuration. */
115
+ invitations?: {
116
+ playerUrl: string;
117
+ spectatorUrl: string | null;
118
+ } | null;
119
+ /** Trusted host telemetry identity, excluded from the game lobby projection. */
120
+ gameId?: string;
121
+ /** Frozen presentation choice; old sessions retain the platform lobby. */
122
+ lobbyMode?: LobbyMode;
123
+ lobbyGameUrl?: string;
124
+ playerPolicy?: PlayerPolicy;
125
+ version: 2;
126
+ multiplayerSessionId: string;
127
+ roomCode: string;
128
+ gameSlug: string;
129
+ phase: SessionPhase;
130
+ revision: number;
131
+ hostSeatId: string;
132
+ ownSeatId: string;
133
+ rematchAllowed?: boolean;
134
+ /** Trusted host metadata; never part of the game-owned launch reference. */
135
+ contentOrigin?: string | null;
136
+ contentReady?: boolean;
137
+ seats: Seat[];
138
+ round: null | {
139
+ roundId: string;
140
+ revision?: number;
141
+ phase: RoundPhase;
142
+ reason: string | null;
143
+ projection?: 'pending' | 'applied' | 'rejected';
144
+ projectionReason?: string | null;
145
+ result: CanonicalResult | null;
146
+ launch: LaunchReference;
147
+ };
148
+ }
149
+ export interface ResultProposal {
150
+ version: 2;
151
+ scores: Record<string, number>;
152
+ winnerSeatIds: string[];
153
+ reason: 'win' | 'draw' | 'forfeit' | 'abort';
154
+ metadata?: Record<string, string | number | boolean | null>;
155
+ }
156
+ export interface CanonicalResult extends ResultProposal {
157
+ participants?: Array<{
158
+ seatId: string;
159
+ displayName: string;
160
+ kind: ParticipantKind;
161
+ }>;
162
+ roundId: string;
163
+ multiplayerSessionId: string;
164
+ authority: Authority;
165
+ package: PackageBinding;
166
+ startedAt: number;
167
+ endedAt: number;
168
+ }
169
+ /** Public presentation of a party game's result; contains no admission credentials. */
170
+ export interface PartyGameResult {
171
+ multiplayerSessionId: string;
172
+ roundId: string;
173
+ gameSlug: string;
174
+ completed: boolean;
175
+ reason: ResultProposal['reason'] | null;
176
+ memberMetric?: 'correct-answers';
177
+ teams: Array<{
178
+ teamId: string;
179
+ name: string;
180
+ score: number | null;
181
+ winner: boolean;
182
+ members: Array<{
183
+ seatId: string;
184
+ displayName: string;
185
+ score: number | null;
186
+ correctAnswers?: number | null;
187
+ }>;
188
+ }>;
189
+ }
190
+ export declare const terminalRound: (phase: RoundPhase) => boolean;
191
+ export declare function canTransition(from: RoundPhase, to: RoundPhase): boolean;
192
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
193
+ export declare function isBoundedId(value: unknown): value is string;
194
+ export declare function isLaunchReference(value: unknown): value is LaunchReference;
195
+ export declare function isLaunchOutcome(value: unknown): value is LaunchOutcome;
196
+ export declare function parseResultProposal(value: unknown, participantSeatIds: readonly string[]): ResultProposal;
197
+ /** Stable, bounded canonical JSON; callers validate their domain payload first. */
198
+ export declare function canonicalJson(value: unknown): string;
199
+ export declare function normalizeError(error: unknown): MultiplayerError;
200
+ export declare function errorMessage(code: ErrorCode): string;