@dreamboard-games/sdk 0.4.0-alpha.4 → 0.4.0-alpha.6

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 (79) hide show
  1. package/REFERENCE.md +1089 -123
  2. package/dist/{HandView-x8MhbhFl.d.ts → HandView-Bi2lxzQP.d.ts} +3 -3
  3. package/dist/{ThemeProvider-DRalAWzY.d.ts → ThemeProvider-CElaL2ik.d.ts} +1 -1
  4. package/dist/authoring/index.js +2 -2
  5. package/dist/browser-interaction.js +1 -1
  6. package/dist/{chunk-E3X552YM.js → chunk-2TRZSZGD.js} +1061 -425
  7. package/dist/chunk-2TRZSZGD.js.map +1 -0
  8. package/dist/{chunk-CP35NPPY.js → chunk-52DH7VQF.js} +61 -7
  9. package/dist/chunk-52DH7VQF.js.map +1 -0
  10. package/dist/{chunk-N6ZDIMRB.js → chunk-B2YBS3SG.js} +1 -1
  11. package/dist/chunk-B2YBS3SG.js.map +1 -0
  12. package/dist/{chunk-LKJLAGND.js → chunk-DDST4U2P.js} +2 -2
  13. package/dist/{chunk-SUMZ5OEH.js → chunk-HK3WN4U7.js} +2 -2
  14. package/dist/{chunk-SUMZ5OEH.js.map → chunk-HK3WN4U7.js.map} +1 -1
  15. package/dist/{chunk-QOFFRHZR.js → chunk-OV6JC2BM.js} +64 -28
  16. package/dist/chunk-OV6JC2BM.js.map +1 -0
  17. package/dist/{chunk-K5ZRJTZZ.js → chunk-PAPIAMYX.js} +6 -3
  18. package/dist/chunk-PAPIAMYX.js.map +1 -0
  19. package/dist/{chunk-TTISZQNI.js → chunk-SOBNI363.js} +39 -28
  20. package/dist/chunk-SOBNI363.js.map +1 -0
  21. package/dist/{chunk-Y6Y2YABD.js → chunk-TGMXBRKY.js} +22 -6
  22. package/dist/chunk-TGMXBRKY.js.map +1 -0
  23. package/dist/{chunk-XZ667T4K.js → chunk-UC2UXAC6.js} +2 -2
  24. package/dist/{chunk-O6M6PN4E.js → chunk-UUQNOGZV.js} +94 -53
  25. package/dist/chunk-UUQNOGZV.js.map +1 -0
  26. package/dist/{chunk-WUIVY2KE.js → chunk-WHR5UW3F.js} +1 -1
  27. package/dist/chunk-WHR5UW3F.js.map +1 -0
  28. package/dist/codegen.d.ts +13 -0
  29. package/dist/codegen.js +1 -1
  30. package/dist/{components-B7hFaEn_.d.ts → components-BTwSIjXj.d.ts} +77 -206
  31. package/dist/{hex-board-view-BFlWDb9k.d.ts → hex-board-view-aKkblDp6.d.ts} +180 -1
  32. package/dist/{index-gjxQichK.d.ts → index-CFTjJIXd.d.ts} +5 -4
  33. package/dist/{index.d-BL3bT5lt.d.ts → index.d-DMASeF6M.d.ts} +294 -27
  34. package/dist/index.js +2 -2
  35. package/dist/package-set.d.ts +2 -2
  36. package/dist/package-set.js +2 -2
  37. package/dist/{runtime-api-BJharVaj.d.ts → plugin-state-BRH3UiUp.d.ts} +19 -3
  38. package/dist/{protocol-BP193lva.d.ts → protocol-835hEGne.d.ts} +42 -1
  39. package/dist/reducer/advanced.d.ts +4 -2
  40. package/dist/reducer/advanced.js +1 -1
  41. package/dist/reducer-contract.d.ts +1 -1
  42. package/dist/reducer-contract.js +2 -2
  43. package/dist/reducer.d.ts +10 -4
  44. package/dist/reducer.js +317 -15
  45. package/dist/reducer.js.map +1 -1
  46. package/dist/runtime/primitives.d.ts +32 -7
  47. package/dist/runtime/primitives.js +9 -5
  48. package/dist/runtime/runtime-api.d.ts +1 -1
  49. package/dist/runtime/workspace-contract.d.ts +7 -7
  50. package/dist/runtime/workspace-contract.js +6 -6
  51. package/dist/runtime-Dkfm1x2r.d.ts +1670 -0
  52. package/dist/runtime.d.ts +10 -9
  53. package/dist/runtime.js +240 -16
  54. package/dist/runtime.js.map +1 -1
  55. package/dist/testing.d.ts +78 -15
  56. package/dist/testing.js +69 -8
  57. package/dist/testing.js.map +1 -1
  58. package/dist/{types-CYeN0wLK.d.ts → types-aI4V9CWe.d.ts} +5 -5
  59. package/dist/types.d.ts +13 -0
  60. package/dist/ui/components.d.ts +6 -3
  61. package/dist/ui/components.js +15 -3
  62. package/dist/ui/plugin-styles.css +2 -2
  63. package/dist/{ui-contract-B4NjRlvC.d.ts → ui-contract-Ue6SywvO.d.ts} +24 -10
  64. package/dist/ui.d.ts +9 -6
  65. package/dist/ui.js +16 -4
  66. package/dist/views-32rSsfeU.d.ts +1559 -0
  67. package/package.json +21 -20
  68. package/dist/chunk-CP35NPPY.js.map +0 -1
  69. package/dist/chunk-E3X552YM.js.map +0 -1
  70. package/dist/chunk-K5ZRJTZZ.js.map +0 -1
  71. package/dist/chunk-N6ZDIMRB.js.map +0 -1
  72. package/dist/chunk-O6M6PN4E.js.map +0 -1
  73. package/dist/chunk-QOFFRHZR.js.map +0 -1
  74. package/dist/chunk-TTISZQNI.js.map +0 -1
  75. package/dist/chunk-WUIVY2KE.js.map +0 -1
  76. package/dist/chunk-Y6Y2YABD.js.map +0 -1
  77. package/dist/views-fn2RuXOx.d.ts +0 -3168
  78. /package/dist/{chunk-LKJLAGND.js.map → chunk-DDST4U2P.js.map} +0 -0
  79. /package/dist/{chunk-XZ667T4K.js.map → chunk-UC2UXAC6.js.map} +0 -0
@@ -0,0 +1,1559 @@
1
+ import { bQ as RuntimeTableRecord, aE as PlayerIdOfState, az as PhaseStateOfState, aM as PublicStateOfState, a8 as HiddenStateOfState, aK as PrivateStateOfState, ci as SharedZoneIdOfTable, cE as TableOfState, F as DeckCardsOfTable, aF as PlayerIdOfTable, H as DeckIdOfTable, aI as PlayerZoneIdOfTable, u as CompatibleCardIdForTwoPlayerZones, t as CompatibleCardIdForHandAndDeck, v as CompatibleHandIdForDeck, Y as HandIdOfTable, p as CardIdOfTable, e as BoardIdOfTable, ck as SpaceIdOfTable, x as ComponentIdOfTable, c as BoardContainerIdOfTable, cH as TiledBoardIdOfTable, cJ as TiledEdgeIdOfTable, cP as TiledVertexIdOfTable, b5 as ResourceAmountsOfTable, ba as ResourceIdOfTable, cG as TableQueriesOfState, aQ as ReducerGameState, cD as TableOfManifest, ac as ManifestContractOf, aL as PublicSchemaOfContract, aJ as PrivateSchemaOfContract, a7 as HiddenSchemaOfContract, ay as PhaseStateMapOfContract, at as PhaseNameOfContract, bY as SchemaLike, cx as StateDefinition, a9 as InitContext, ah as ManifestOf, O as ExactManifestContractOf, ca as SetupProfileDefinition, aR as ReducerManifestContract, aV as ReducerSessionState, bF as RuntimeSetupSelection, bz as RuntimePhaseState, a as AnySchema, ab as ManifestContract, E as ContinuationToken, av as PhaseNameOfState, aU as ReducerRuntimeStateForState, ce as SetupSelectionOfManifest, aO as ReducerAcceptOptions, aN as ReducerAccept, U as GameOutcome, aS as ReducerReject, aP as ReducerFx, aT as ReducerResult, cB as StringKeyOf, A as AnyContinuationToken, aG as PlayerZoneIdOfManifest, q as CardTypeOfState, o as CardIdOfState } from './runtime-Dkfm1x2r.js';
2
+ import { z } from 'zod';
3
+
4
+ /**
5
+ * State composition primitives.
6
+ *
7
+ * `pipe` threads a seed state through a sequence of `State -> State`
8
+ * transformations, left to right. It is the preferred way to compose curried
9
+ * writers (the `ops.*` namespace) in reducers:
10
+ *
11
+ * return accept(
12
+ * pipe(state,
13
+ * ops.spendPlayerResources({ playerId, resources: cost }),
14
+ * ops.placePieceOnVertex({ boardId, vertexId, pieceId, ownerId: playerId }),
15
+ * ),
16
+ * );
17
+ */
18
+ /**
19
+ * A state-preserving transformation.
20
+ *
21
+ * `Op<State>` is polymorphic in the exact input subtype — given a state `S`
22
+ * that extends `State`, it returns the same `S`. This lets curried writers
23
+ * from `ops.*` and author-written helpers thread through phase-scoped `pipe`
24
+ * calls without losing the narrowed phase state type.
25
+ */
26
+ type Op<State> = <S extends State>(state: S) => S;
27
+ declare function pipe<State>(state: State, ...ops: ReadonlyArray<Op<NoInfer<State>>>): State;
28
+
29
+ /**
30
+ * Curried state writers for use with `pipe`.
31
+ *
32
+ * Each entry in the returned `ops` namespace is a curried transformation
33
+ * `(args) => (state) => state` that can be composed with `pipe`:
34
+ *
35
+ * const ops = createReducerOps<GameState>();
36
+ *
37
+ * return accept(
38
+ * pipe(state,
39
+ * ops.setActivePlayers([playerId]),
40
+ * ops.moveCardFromPlayerZoneToSharedZone({
41
+ * playerId,
42
+ * fromZoneId: "things-hand",
43
+ * toZoneId: "ring-1",
44
+ * cardId: "a-dog",
45
+ * }),
46
+ * ),
47
+ * );
48
+ *
49
+ * The factory binds all ops to a specific `State` type so that ID arguments
50
+ * (deck ids, card ids, etc.) are checked against the manifest-derived table
51
+ * shape of the game.
52
+ */
53
+
54
+ /**
55
+ * Minimum shape required for any state targeted by reducer ops.
56
+ *
57
+ * All curried writers operate on a game state with a `table` field.
58
+ */
59
+ type ReducerStateBase = {
60
+ table: RuntimeTableRecord;
61
+ };
62
+ type PipeTable<State extends ReducerStateBase> = TableOfState<State>;
63
+ /**
64
+ * A shallow patch for a slice of state. Either a partial object to merge
65
+ * over the previous value, or a functional updater `(prev) => next`.
66
+ */
67
+ type StatePatch<T> = Partial<T> | ((prev: T) => T);
68
+ /**
69
+ * Curried writer namespace for a specific game state type.
70
+ *
71
+ * Created via {@link createReducerOps}.
72
+ */
73
+ interface ReducerOps<State extends ReducerStateBase> {
74
+ /** Set the list of players whose turn is currently active. */
75
+ setActivePlayers(activePlayers: ReadonlyArray<PlayerIdOfState<State>>): Op<State>;
76
+ /**
77
+ * Advance `flow.activePlayers` to the single next seat in `playerOrder`.
78
+ *
79
+ * Uses `state.flow.activePlayers[0]` as the current seat (or the first
80
+ * seat in `playerOrder` when `activePlayers` is empty) and sets
81
+ * `activePlayers` to `[q.player.nextInOrder(current)]`. No-op when the
82
+ * player order is empty.
83
+ */
84
+ advanceActivePlayer(): Op<State>;
85
+ /**
86
+ * Update the current phase's local state.
87
+ *
88
+ * Accepts either a `Partial<PhaseState>` which is shallow-merged into the
89
+ * previous value, or a functional updater `(prev) => next` which must
90
+ * return a complete `PhaseState`.
91
+ */
92
+ patchPhaseState(patch: StatePatch<PhaseStateOfState<State>>): Op<State>;
93
+ /**
94
+ * Update `state.publicState`.
95
+ *
96
+ * Accepts either a `Partial<PublicState>` which is shallow-merged into the
97
+ * previous value, or a functional updater `(prev) => next` which must
98
+ * return a complete `PublicState`.
99
+ */
100
+ patchPublicState(patch: StatePatch<PublicStateOfState<State>>): Op<State>;
101
+ /**
102
+ * Update `state.hiddenState`.
103
+ *
104
+ * Accepts either a `Partial<HiddenState>` or a functional updater.
105
+ */
106
+ patchHiddenState(patch: StatePatch<HiddenStateOfState<State>>): Op<State>;
107
+ /**
108
+ * Update a single player's entry in `state.privateState`.
109
+ *
110
+ * Accepts either a `Partial<PrivateState>` or a functional updater.
111
+ */
112
+ patchPlayerPrivateState(args: {
113
+ playerId: PlayerIdOfState<State>;
114
+ patch: StatePatch<PrivateStateOfState<State>>;
115
+ }): Op<State>;
116
+ /**
117
+ * Append a card to a shared zone (deck). Defaults to placing the card at the
118
+ * bottom; pass `position: "top"` for top-of-deck placement (e.g. Bureaucrat-style).
119
+ */
120
+ addCardToSharedZone<DeckId extends SharedZoneIdOfTable<PipeTable<State>>>(args: {
121
+ deckId: DeckId;
122
+ cardId: DeckCardsOfTable<PipeTable<State>, DeckId>[number];
123
+ playedBy?: PlayerIdOfTable<PipeTable<State>> | null;
124
+ position?: "top" | "bottom";
125
+ }): Op<State>;
126
+ /** Remove a card from a shared zone (deck). */
127
+ removeCardFromSharedZone<DeckId extends DeckIdOfTable<PipeTable<State>>>(args: {
128
+ deckId: DeckId;
129
+ cardId: DeckCardsOfTable<PipeTable<State>, DeckId>[number];
130
+ }): Op<State>;
131
+ /**
132
+ * Move a card between two shared zones (decks). Defaults to placing the card
133
+ * at the bottom of the destination; pass `position: "top"` for top placement.
134
+ */
135
+ moveCardBetweenSharedZones<FromZoneId extends SharedZoneIdOfTable<PipeTable<State>>, ToZoneId extends SharedZoneIdOfTable<PipeTable<State>>>(args: {
136
+ fromZoneId: FromZoneId;
137
+ toZoneId: ToZoneId;
138
+ cardId: DeckCardsOfTable<PipeTable<State>, FromZoneId>[number];
139
+ playedBy?: PlayerIdOfTable<PipeTable<State>> | null;
140
+ position?: "top" | "bottom";
141
+ }): Op<State>;
142
+ /**
143
+ * Draw the top `count` cards from one perPlayer zone into another for the
144
+ * same player (e.g. deck → hand at the start of a turn). Companion to
145
+ * {@link dealCardsToPlayerZone} for the perPlayer → perPlayer case. Stops
146
+ * silently if the source runs out before `count` is reached.
147
+ */
148
+ dealCardsBetweenPlayerZones<FromZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, ToZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>>(args: {
149
+ playerId: PlayerId;
150
+ fromZoneId: FromZoneId;
151
+ toZoneId: ToZoneId;
152
+ count: number;
153
+ }): Op<State>;
154
+ /**
155
+ * Move a card between two perPlayer zones owned by the same player (e.g.
156
+ * hand → in-play → discard). Owner is preserved; visibility is recomputed
157
+ * from the destination zone.
158
+ */
159
+ moveCardBetweenPlayerZones<FromZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, ToZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>>(args: {
160
+ playerId: PlayerId;
161
+ fromZoneId: FromZoneId;
162
+ toZoneId: ToZoneId;
163
+ cardId: CompatibleCardIdForTwoPlayerZones<PipeTable<State>, FromZoneId, ToZoneId>;
164
+ position?: "top" | "bottom";
165
+ }): Op<State>;
166
+ /**
167
+ * Move a card from a player zone (hand) to a shared zone (deck). Defaults to
168
+ * placing the card at the bottom; pass `position: "top"` to topdeck.
169
+ */
170
+ moveCardFromPlayerZoneToSharedZone<FromZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, ToZoneId extends SharedZoneIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>>(args: {
171
+ playerId: PlayerId;
172
+ fromZoneId: FromZoneId;
173
+ toZoneId: ToZoneId;
174
+ cardId: CompatibleCardIdForHandAndDeck<PipeTable<State>, FromZoneId, ToZoneId>;
175
+ playedBy?: PlayerIdOfTable<PipeTable<State>> | null;
176
+ position?: "top" | "bottom";
177
+ }): Op<State>;
178
+ /**
179
+ * Move a named card from a shared zone (supply pile, deck) to a perPlayer
180
+ * zone (e.g. discard). The "gain" verb in deck-builders. Distinct from
181
+ * {@link dealCardsToPlayerZone}, which draws unspecified top-N cards from a
182
+ * deck. Owner flips to the receiving player; visibility is recomputed.
183
+ */
184
+ moveCardFromSharedZoneToPlayerZone<FromZoneId extends SharedZoneIdOfTable<PipeTable<State>>, ToZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>>(args: {
185
+ playerId: PlayerId;
186
+ fromZoneId: FromZoneId;
187
+ toZoneId: ToZoneId;
188
+ cardId: CompatibleCardIdForHandAndDeck<PipeTable<State>, ToZoneId, FromZoneId>;
189
+ position?: "top" | "bottom";
190
+ }): Op<State>;
191
+ /**
192
+ * Deal the top `count` cards from a shared deck into a player's hand zone.
193
+ *
194
+ * This op does not consume RNG. If the deck needs to be random, shuffle it
195
+ * first with `fx.shuffleSharedZone(...)`, then deal from the shuffled deck
196
+ * inside the same reducer via this op.
197
+ */
198
+ dealCardsToPlayerZone<FromZoneId extends DeckIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>, ToZoneId extends CompatibleHandIdForDeck<PipeTable<State>, FromZoneId> & HandIdOfTable<PipeTable<State>>>(args: {
199
+ fromZoneId: FromZoneId;
200
+ playerId: PlayerId;
201
+ toZoneId: ToZoneId;
202
+ count: number;
203
+ }): Op<State>;
204
+ /**
205
+ * Atomically rotate cards in a per-player zone around the table.
206
+ *
207
+ * Defaults to rotating every card currently in `zoneId` for every player in
208
+ * turn order. Pass `players` to use a smaller explicit order, or
209
+ * `cardIdsByPlayer` to rotate only selected cards such as Hearts passes.
210
+ */
211
+ rotatePlayerZone<ZoneId extends PlayerZoneIdOfTable<PipeTable<State>>, PlayerId extends PlayerIdOfTable<PipeTable<State>>>(args: {
212
+ zoneId: ZoneId;
213
+ direction: "left" | "right";
214
+ players?: readonly PlayerId[];
215
+ cardIdsByPlayer?: Partial<Record<PlayerId, readonly CardIdOfTable<PipeTable<State>>[]>>;
216
+ position?: "top" | "bottom";
217
+ }): Op<State>;
218
+ /** Move a component onto a board space. */
219
+ moveComponentToSpace<BoardId extends BoardIdOfTable<PipeTable<State>>, SpaceId extends SpaceIdOfTable<PipeTable<State>, BoardId>, ComponentId extends ComponentIdOfTable<PipeTable<State>>>(args: {
220
+ componentId: ComponentId;
221
+ boardId: BoardId;
222
+ spaceId: SpaceId;
223
+ }): Op<State>;
224
+ /** Move a component into a board container. */
225
+ moveComponentToContainer<BoardId extends BoardIdOfTable<PipeTable<State>>, ContainerId extends BoardContainerIdOfTable<PipeTable<State>, BoardId>, ComponentId extends ComponentIdOfTable<PipeTable<State>>>(args: {
226
+ componentId: ComponentId;
227
+ boardId: BoardId;
228
+ containerId: ContainerId;
229
+ }): Op<State>;
230
+ /** Move a component onto a tiled board edge. */
231
+ moveComponentToEdge<BoardId extends TiledBoardIdOfTable<PipeTable<State>>, EdgeId extends TiledEdgeIdOfTable<PipeTable<State>, BoardId>, ComponentId extends ComponentIdOfTable<PipeTable<State>>>(args: {
232
+ componentId: ComponentId;
233
+ boardId: BoardId;
234
+ edgeId: EdgeId;
235
+ }): Op<State>;
236
+ /** Move a component onto a tiled board vertex. */
237
+ moveComponentToVertex<BoardId extends TiledBoardIdOfTable<PipeTable<State>>, VertexId extends TiledVertexIdOfTable<PipeTable<State>, BoardId>, ComponentId extends ComponentIdOfTable<PipeTable<State>>>(args: {
238
+ componentId: ComponentId;
239
+ boardId: BoardId;
240
+ vertexId: VertexId;
241
+ }): Op<State>;
242
+ /** Move a component back to the detached pool. */
243
+ moveComponentToDetached<ComponentId extends ComponentIdOfTable<PipeTable<State>>>(args: {
244
+ componentId: ComponentId;
245
+ }): Op<State>;
246
+ /**
247
+ * Credit the specified resources to a player.
248
+ *
249
+ * Amounts must be non-negative; use {@link spendResources} for deductions
250
+ * so that affordability is checked explicitly.
251
+ *
252
+ * pipe(
253
+ * state,
254
+ * ops.addResources({ playerId, amounts: { wood: 1, brick: 1 } }),
255
+ * )
256
+ */
257
+ addResources(args: {
258
+ playerId: PlayerIdOfTable<PipeTable<State>>;
259
+ amounts: ResourceAmountsOfTable<PipeTable<State>>;
260
+ }): Op<State>;
261
+ /**
262
+ * Debit the specified resources from a player.
263
+ *
264
+ * Throws when the player cannot afford the full cost — gate with
265
+ * `q.player.canAfford(...)` in your `validate` step before invoking.
266
+ *
267
+ * pipe(
268
+ * state,
269
+ * ops.spendResources({ playerId, amounts: COST_DEV_CARD }),
270
+ * ops.dealCardsToPlayerZone({ ... }),
271
+ * )
272
+ */
273
+ spendResources(args: {
274
+ playerId: PlayerIdOfTable<PipeTable<State>>;
275
+ amounts: ResourceAmountsOfTable<PipeTable<State>>;
276
+ }): Op<State>;
277
+ /**
278
+ * Transfer the specified resources from one player to another.
279
+ *
280
+ * Throws when the source cannot afford the full amount. On success the
281
+ * destination gains exactly what the source loses.
282
+ */
283
+ transferResources(args: {
284
+ fromPlayerId: PlayerIdOfTable<PipeTable<State>>;
285
+ toPlayerId: PlayerIdOfTable<PipeTable<State>>;
286
+ amounts: ResourceAmountsOfTable<PipeTable<State>>;
287
+ }): Op<State>;
288
+ /**
289
+ * Overwrite a single resource balance for a player. Prefer
290
+ * {@link addResources} / {@link spendResources} — use this only when the
291
+ * new balance is an absolute (e.g. scripted setup).
292
+ */
293
+ setResource(args: {
294
+ playerId: PlayerIdOfTable<PipeTable<State>>;
295
+ resourceId: ResourceIdOfTable<PipeTable<State>>;
296
+ amount: number;
297
+ }): Op<State>;
298
+ }
299
+ /**
300
+ * Create the `ops.*` namespace specialised to a game state.
301
+ *
302
+ * Call this once (typically in a shared reducer-support module) and reuse the
303
+ * resulting object across phases:
304
+ *
305
+ * export const ops = createReducerOps<GameState>();
306
+ */
307
+ declare function createReducerOps<State extends ReducerStateBase>(): ReducerOps<State>;
308
+
309
+ type RotatePlayerZoneArgs<State extends {
310
+ table: RuntimeTableRecord;
311
+ }, ZoneId extends PlayerZoneIdOfTable<TableOfState<State>> = PlayerZoneIdOfTable<TableOfState<State>>, PlayerId extends PlayerIdOfTable<TableOfState<State>> = PlayerIdOfTable<TableOfState<State>>> = {
312
+ zoneId: ZoneId;
313
+ direction: "left" | "right";
314
+ players?: readonly PlayerId[];
315
+ cardIdsByPlayer?: Partial<Record<PlayerId, readonly CardIdOfTable<TableOfState<State>>[]>>;
316
+ position?: "top" | "bottom";
317
+ };
318
+ type TransactionMethods<State extends {
319
+ table: RuntimeTableRecord;
320
+ }> = {
321
+ [Key in Exclude<keyof ReducerOps<State>, "moveComponentToSpace">]: ReducerOps<State>[Key] extends (...args: infer Args) => Op<State> ? (...args: Args) => State : never;
322
+ } & {
323
+ moveComponentToSpace<BoardId extends BoardIdOfTable<TableOfState<State>>, SpaceId extends SpaceIdOfTable<TableOfState<State>, BoardId>, ComponentId extends ComponentIdOfTable<TableOfState<State>>>(args: {
324
+ componentId: ComponentId;
325
+ boardId: BoardId;
326
+ spaceId: SpaceId;
327
+ }): State;
328
+ };
329
+ type ReducerTransaction<State extends {
330
+ table: RuntimeTableRecord;
331
+ }> = TransactionMethods<State> & {
332
+ readonly state: State;
333
+ readonly q: TableQueriesOfState<State>;
334
+ apply(op: Op<State>): State;
335
+ rotatePlayerZone<ZoneId extends PlayerZoneIdOfTable<TableOfState<State>>, PlayerId extends PlayerIdOfTable<TableOfState<State>>>(args: RotatePlayerZoneArgs<State, ZoneId, PlayerId>): State;
336
+ };
337
+ type ReducerEdit<State extends {
338
+ table: RuntimeTableRecord;
339
+ }> = <DraftState extends State>(state: DraftState) => ReducerTransaction<DraftState>;
340
+ declare function createReducerTransaction<State extends {
341
+ table: RuntimeTableRecord;
342
+ }>(initialState: State, ops?: ReducerOps<State>): ReducerTransaction<State>;
343
+ declare function createReducerEdit<State extends {
344
+ table: RuntimeTableRecord;
345
+ }>(ops?: ReducerOps<State>): ReducerEdit<State>;
346
+
347
+ type ReducerGameContract<Table extends RuntimeTableRecord, Manifest extends ReducerManifestContract<Table, string, string, string, string, string>, PublicSchema extends SchemaLike<object>, PrivateSchema extends SchemaLike<object>, HiddenSchema extends SchemaLike<object>, Phases extends Record<string, SchemaLike<object>>, Errors extends Record<string, string> | undefined = undefined> = {
348
+ manifest: Manifest;
349
+ state: StateDefinition<PublicSchema, PrivateSchema, HiddenSchema>;
350
+ phases: Phases;
351
+ errors?: Errors;
352
+ /** Derived from `phases`; retained as an internal runtime convenience. */
353
+ phaseNames: readonly string[];
354
+ };
355
+ type ReducerStateForConfig<Table extends RuntimeTableRecord, PublicSchema extends SchemaLike<object>, PrivateSchema extends SchemaLike<object>, HiddenSchema extends SchemaLike<object>, PhaseName extends string> = ReducerGameState<Table, z.infer<PublicSchema>, z.infer<PrivateSchema>, z.infer<HiddenSchema>, RuntimePhaseState, PhaseName, Record<PhaseName, RuntimePhaseState>>;
356
+ type ReducerSessionForConfig<Table extends RuntimeTableRecord, PublicSchema extends SchemaLike<object>, PrivateSchema extends SchemaLike<object>, HiddenSchema extends SchemaLike<object>, PhaseName extends string, Setup extends RuntimeSetupSelection = RuntimeSetupSelection> = ReducerSessionState<ReducerStateForConfig<Table, PublicSchema, PrivateSchema, HiddenSchema, PhaseName>, Setup>;
357
+ type BaseGameStateOfContract<Contract> = ReducerGameState<TableOfManifest<ManifestContractOf<Contract>>, z.infer<PublicSchemaOfContract<Contract>>, z.infer<PrivateSchemaOfContract<Contract>>, z.infer<HiddenSchemaOfContract<Contract>>, PhaseStateMapOfContract<Contract>[PhaseNameOfContract<Contract>], PhaseNameOfContract<Contract>, PhaseStateMapOfContract<Contract>>;
358
+ type BaseGameSessionOfContract<Contract> = ReducerSessionState<BaseGameStateOfContract<Contract>, RuntimeSetupSelection<ManifestContractOf<Contract>>>;
359
+ /**
360
+ * Heterogeneous phase map for a contract. Each phase carries its own local
361
+ * `PhaseStateSchema` plus authoring-time Actions/Flows/Interactions/
362
+ * Stages/Zones maps. The registries are bound to the contract's base state +
363
+ * manifest so the runtime can iterate them through a single index type
364
+ * without reaching for `any`.
365
+ */
366
+ type PhaseMapOf<Contract> = {
367
+ [Name in PhaseNameOfContract<Contract>]: PhaseDefinition<SchemaLike<object>, BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>, Record<string, InputCollector>, EffectMap<BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>>, InteractionMap<BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>>, StageMap<BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>>, PhaseZoneList<ManifestContractOf<Contract>>, CardActionMap<BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>>>;
368
+ };
369
+ type AnyPhaseDefinitionForContract<Contract> = PhaseMapOf<Contract>[PhaseNameOfContract<Contract>];
370
+ /**
371
+ * Helpers below accept heterogeneous phase maps (each phase binds its own
372
+ * `PhaseStateSchema` + per-phase registries). TypeScript requires the
373
+ * constraint to use a shape compatible with contract-bound state types in a
374
+ * contravariant `initialState` position, so we erase the registry-bound
375
+ * state/manifest generics with `any`. The only purpose of the constraint is
376
+ * to guarantee `Definitions[Name]` is a `PhaseDefinition` so the `extends`
377
+ * check below can infer `PhaseStateSchema`.
378
+ */
379
+ type PhaseStateMapOfDefinitions<Definitions extends Record<string, PhaseDefinition<SchemaLike<object>, any, any, Record<string, InputCollector>, EffectMap<any, any>, InteractionMap<any, any>, StageMap<any, any>, PhaseZoneList<any>, CardActionMap<any, any>>>> = Partial<{
380
+ [Name in keyof Definitions & string]: Definitions[Name] extends {
381
+ state: infer PhaseStateSchema extends SchemaLike<object>;
382
+ } ? z.infer<PhaseStateSchema> : never;
383
+ }>;
384
+ type PhaseStateOfDefinitions<Definitions extends Record<string, PhaseDefinition<SchemaLike<object>, any, any, Record<string, InputCollector>, EffectMap<any, any>, InteractionMap<any, any>, StageMap<any, any>, PhaseZoneList<any>, CardActionMap<any, any>>>> = {
385
+ [Name in keyof Definitions & string]: Definitions[Name] extends {
386
+ state: infer PhaseStateSchema extends SchemaLike<object>;
387
+ } ? z.infer<PhaseStateSchema> : never;
388
+ }[keyof Definitions & string];
389
+ type ResolvedGameStateOf<Contract, Definitions extends PhaseMapOf<Contract>> = {
390
+ [Name in keyof Definitions & string]: ReducerGameState<TableOfManifest<ManifestContractOf<Contract>>, z.infer<PublicSchemaOfContract<Contract>>, z.infer<PrivateSchemaOfContract<Contract>>, z.infer<HiddenSchemaOfContract<Contract>>, Definitions[Name] extends {
391
+ state: infer PhaseStateSchema extends SchemaLike<object>;
392
+ } ? z.infer<PhaseStateSchema> : never, PhaseNameOfContract<Contract>> & {
393
+ flow: ReducerGameState<TableOfManifest<ManifestContractOf<Contract>>, z.infer<PublicSchemaOfContract<Contract>>, z.infer<PrivateSchemaOfContract<Contract>>, z.infer<HiddenSchemaOfContract<Contract>>, PhaseStateOfDefinitions<Definitions>, PhaseNameOfContract<Contract>>["flow"] & {
394
+ currentPhase: Name;
395
+ };
396
+ };
397
+ }[keyof Definitions & string];
398
+ type ResolvedGameSessionOf<Contract, Definitions extends PhaseMapOf<Contract>> = ReducerSessionState<ResolvedGameStateOf<Contract, Definitions>, RuntimeSetupSelection<ManifestContractOf<Contract>>>;
399
+ type ViewMapOf<Contract> = Record<string, ViewDefinition<BaseGameStateOfContract<Contract>, ManifestContractOf<Contract>, unknown>>;
400
+ type PhasesOfDefinition<Definition> = Definition extends {
401
+ phases: infer Definitions extends Record<string, unknown>;
402
+ } ? Definitions : never;
403
+ type ViewsOfDefinition<Definition> = Definition extends {
404
+ views?: infer Views;
405
+ } ? NonNullable<Views> : never;
406
+ type NonNeverKeys<Registry> = {
407
+ [Key in keyof Registry]-?: [Registry[Key]] extends [never] ? never : Key;
408
+ }[keyof Registry];
409
+ type ViewNamesOfDefinition<Definition> = NonNeverKeys<ViewsOfDefinition<Definition>> & string;
410
+ type ViewDefinitionByName<Definition, ViewName extends ViewNamesOfDefinition<Definition>> = ViewsOfDefinition<Definition>[ViewName];
411
+ type ViewOfDefinition<Definition, ViewName extends ViewNamesOfDefinition<Definition>> = ViewDefinitionByName<Definition, ViewName> extends {
412
+ project: (...args: never[]) => infer Projection;
413
+ } ? Projection : never;
414
+ type PhaseNamesOfDefinition<Definition> = keyof PhasesOfDefinition<Definition> & string;
415
+ type PhaseDefinitionByName<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseName extends keyof PhasesOfDefinition<Definition> & string ? PhasesOfDefinition<Definition>[PhaseName] : never;
416
+ type EffectsOfDefinition<Definition> = PhasesOfDefinition<Definition>[keyof PhasesOfDefinition<Definition> & string] extends {
417
+ effects?: infer Effects;
418
+ } ? Effects extends Record<string, unknown> ? Effects[keyof Effects & string] : never : never;
419
+ type EffectIdsOfDefinition<Definition> = EffectsOfDefinition<Definition> extends infer Effect ? Effect extends {
420
+ id: infer Id;
421
+ } ? Extract<Id, string> : never : never;
422
+ type GameStateOf<Source> = Source extends {
423
+ contract: infer Contract extends ReducerGameContractLike;
424
+ phases: infer Definitions;
425
+ } ? Definitions extends PhaseMapOf<Contract> ? ResolvedGameStateOf<Contract, Definitions> : never : Source extends ReducerGameContract<any, any, any, any, any, any, any> ? BaseGameStateOfContract<Source> : never;
426
+ /**
427
+ * Public structural upper bound for a reducer game contract.
428
+ *
429
+ * The `manifest` slot is intentionally erased with `any` because concrete
430
+ * manifests bind per-contract branded literals (e.g. `PlayerId` unions with
431
+ * specific string literals). Using a ground `ManifestContract<...>` type
432
+ * here would prevent assignability from contract-bound manifests in a
433
+ * contravariant position.
434
+ */
435
+ type ReducerGameContractLike = {
436
+ manifest: any;
437
+ state: StateDefinition<SchemaLike<object>, SchemaLike<object>, SchemaLike<object>>;
438
+ };
439
+ type InitialStateContextOf<Contract extends ReducerGameContractLike> = InitContext<TableOfManifest<ManifestOf<Contract>>, ExactManifestContractOf<Contract>>;
440
+ type InitialStateCallbacks<Contract extends ReducerGameContractLike> = {
441
+ public?: (ctx: InitialStateContextOf<Contract>) => z.infer<PublicSchemaOfContract<Contract>>;
442
+ private?: (ctx: InitialStateContextOf<Contract> & {
443
+ playerId: PlayerIdOfTable<TableOfManifest<ManifestOf<Contract>>>;
444
+ }) => z.infer<PrivateSchemaOfContract<Contract>>;
445
+ hidden?: (ctx: InitialStateContextOf<Contract>) => z.infer<HiddenSchemaOfContract<Contract>>;
446
+ };
447
+ type ReducerGameDefinition<Contract extends ReducerGameContractLike, Definitions extends PhaseMapOf<Contract>, Views extends ViewMapOf<Contract> = Record<string, never>> = {
448
+ contract: Contract;
449
+ initial?: InitialStateCallbacks<NoInfer<Contract>>;
450
+ initialPhase?: keyof Definitions & string;
451
+ setupProfiles?: Record<string, SetupProfileDefinition<keyof Definitions & string, ExactManifestContractOf<Contract>>>;
452
+ phases: Definitions;
453
+ views?: Views;
454
+ /**
455
+ * Optional session-scoped static projection. Authored via
456
+ * {@link StaticViewDefinition}; computed once per reducer session from the
457
+ * manifest + setup profile and cached by the host. The client merges the
458
+ * cached payload into every seat view, so the per-tick `projectSeatsDynamic`
459
+ * call no longer needs to re-serialize static board topology.
460
+ */
461
+ staticView?: StaticViewDefinition<ExactManifestContractOf<NoInfer<Contract>>, unknown>;
462
+ };
463
+ type AnyReducerGameDefinition = ReducerGameDefinition<ReducerGameContractLike, PhaseMapOf<ReducerGameContractLike>, ViewMapOf<ReducerGameContractLike>>;
464
+ type InteractionRegistriesOfDefinition<Definition> = PhasesOfDefinition<Definition>[keyof PhasesOfDefinition<Definition> & string] extends {
465
+ interactions?: infer Interactions;
466
+ } ? NonNullable<Interactions> : never;
467
+ type SimultaneousSubmitRegistriesOfDefinition<Definition> = PhasesOfDefinition<Definition>[keyof PhasesOfDefinition<Definition> & string] extends {
468
+ submit?: infer Submit;
469
+ } ? {
470
+ submit: NonNullable<Submit>;
471
+ } : never;
472
+ type CardActionRegistriesOfDefinition<Definition> = PhasesOfDefinition<Definition>[keyof PhasesOfDefinition<Definition> & string] extends {
473
+ cardActions?: infer CardActions;
474
+ } ? NonNullable<CardActions> : never;
475
+ type InteractionIdOfDefinition<Definition> = InteractionRegistriesOfDefinition<Definition> extends infer Interactions ? SimultaneousSubmitRegistriesOfDefinition<Definition> extends infer Submit ? CardActionRegistriesOfDefinition<Definition> extends infer CardActions ? Interactions extends Record<string, unknown> ? CardActions extends Record<string, unknown> ? Submit extends Record<string, unknown> ? (NonNeverKeys<Interactions> & string) | (NonNeverKeys<CardActions> & string) | (NonNeverKeys<Submit> & string) : (NonNeverKeys<Interactions> & string) | (NonNeverKeys<CardActions> & string) : Submit extends Record<string, unknown> ? (NonNeverKeys<Interactions> & string) | (NonNeverKeys<Submit> & string) : NonNeverKeys<Interactions> & string : CardActions extends Record<string, unknown> ? Submit extends Record<string, unknown> ? (NonNeverKeys<CardActions> & string) | (NonNeverKeys<Submit> & string) : NonNeverKeys<CardActions> & string : Submit extends Record<string, unknown> ? NonNeverKeys<Submit> & string : never : never : never : never;
476
+ type InteractionRegistryOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseDefinitionByName<Definition, PhaseName> extends {
477
+ interactions?: infer Interactions;
478
+ } ? NonNullable<Interactions> : Record<string, never>;
479
+ type SimultaneousSubmitRegistryOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseDefinitionByName<Definition, PhaseName> extends {
480
+ submit?: infer Submit;
481
+ } ? {
482
+ submit: NonNullable<Submit>;
483
+ } : Record<string, never>;
484
+ type CardActionRegistryOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseDefinitionByName<Definition, PhaseName> extends {
485
+ cardActions?: infer CardActions;
486
+ } ? NonNullable<CardActions> : Record<string, never>;
487
+ type NonNeverRegistryValue<Registry, Key extends string> = Registry extends Record<string, unknown> ? Key extends keyof Registry ? [Registry[Key]] extends [never] ? never : Registry[Key] : never : never;
488
+ type InteractionIdOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = InteractionRegistryOfDefinitionPhase<Definition, PhaseName> extends infer Interactions ? SimultaneousSubmitRegistryOfDefinitionPhase<Definition, PhaseName> extends infer Submit ? CardActionRegistryOfDefinitionPhase<Definition, PhaseName> extends infer CardActions ? Interactions extends Record<string, unknown> ? CardActions extends Record<string, unknown> ? Submit extends Record<string, unknown> ? (NonNeverKeys<Interactions> & string) | (NonNeverKeys<CardActions> & string) | (NonNeverKeys<Submit> & string) : (NonNeverKeys<Interactions> & string) | (NonNeverKeys<CardActions> & string) : Submit extends Record<string, unknown> ? (NonNeverKeys<Interactions> & string) | (NonNeverKeys<Submit> & string) : NonNeverKeys<Interactions> & string : CardActions extends Record<string, unknown> ? Submit extends Record<string, unknown> ? (NonNeverKeys<CardActions> & string) | (NonNeverKeys<Submit> & string) : NonNeverKeys<CardActions> & string : Submit extends Record<string, unknown> ? NonNeverKeys<Submit> & string : never : never : never : never;
489
+ type InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>> = InteractionRegistryOfDefinitionPhase<Definition, PhaseName> extends infer Interactions ? Interactions extends Record<string, unknown> ? NonNeverRegistryValue<Interactions, InteractionId> extends infer InteractionSpec ? [InteractionSpec] extends [never] ? CardActionRegistryOfDefinitionPhase<Definition, PhaseName> extends infer CardActions ? NonNeverRegistryValue<CardActions, InteractionId> extends infer CardActionSpec ? [CardActionSpec] extends [never] ? SimultaneousSubmitRegistryOfDefinitionPhase<Definition, PhaseName> extends infer Submit ? NonNeverRegistryValue<Submit, InteractionId> : never : CardActionSpec : never : never : InteractionSpec : never : never : never;
490
+ type CollectorKindsOf<Collectors> = Collectors extends Record<string, InputCollector> ? Collectors[keyof Collectors] extends infer Collector ? Collector extends {
491
+ kind: infer Kind extends string;
492
+ } ? Kind : never : never : never;
493
+ type CollectorKeysWithKind<Collectors, Kind extends string> = Collectors extends Record<string, InputCollector> ? {
494
+ [K in keyof Collectors]: Collectors[K] extends {
495
+ kind: infer CollectorKind;
496
+ } ? Extract<CollectorKind, Kind> extends never ? never : K : never;
497
+ }[keyof Collectors] : never;
498
+ type CardCollectorZoneIds<Collector> = Collector extends {
499
+ kind: "card";
500
+ meta: infer Meta;
501
+ } ? Meta extends {
502
+ readonly zoneIds: infer ZoneIds extends readonly string[];
503
+ } ? ZoneIds[number] : Meta extends {
504
+ readonly zoneId: infer ZoneId extends string;
505
+ } ? ZoneId : never : never;
506
+ type CollectorCardZoneIds<Collectors, Input extends string> = Collectors extends Record<string, InputCollector> ? Input extends keyof Collectors ? CardCollectorZoneIds<Collectors[Input]> : never : never;
507
+ type CollectorsOfInteractionDefinition<Spec> = Spec extends {
508
+ readonly inputs?: infer Collectors;
509
+ } ? NonNullable<Collectors> extends Record<string, InputCollector> ? NonNullable<Collectors> : Record<string, never> : Record<string, never>;
510
+ type CollectorKindsOfInteractionDefinition<Spec> = (Spec extends {
511
+ readonly cardType: unknown;
512
+ readonly playFrom: unknown;
513
+ } ? "card" : never) | CollectorKindsOf<CollectorsOfInteractionDefinition<Spec>>;
514
+ type InputKeysWithCollectorKindOfInteractionDefinition<Spec, Kind extends string> = (Spec extends {
515
+ readonly cardType: unknown;
516
+ readonly playFrom: unknown;
517
+ } ? Extract<"card", Kind> extends never ? never : "cardId" : never) | (CollectorKeysWithKind<CollectorsOfInteractionDefinition<Spec>, Kind> & string);
518
+ type CardInputZoneIdsOfInteractionDefinition<Spec, Input extends string> = Input extends "cardId" ? Spec extends {
519
+ readonly playFrom: infer PlayFrom extends string;
520
+ } ? PlayFrom : CollectorCardZoneIds<CollectorsOfInteractionDefinition<Spec>, Input> : CollectorCardZoneIds<CollectorsOfInteractionDefinition<Spec>, Input>;
521
+ type ParamsOfCollectors<Collectors> = Collectors extends Record<string, InputCollector> ? {
522
+ [K in keyof Collectors]: Collectors[K] extends InputCollector<infer S> ? S extends SchemaLike<infer V> ? V : never : never;
523
+ } : never;
524
+ type ClientParamsOfCollectors<Collectors> = Collectors extends Record<string, InputCollector> ? {
525
+ [K in keyof Collectors as Collectors[K] extends {
526
+ readonly kind: "rng";
527
+ } ? never : K]: Collectors[K] extends InputCollector<infer S> ? S extends SchemaLike<infer V> ? V : never : never;
528
+ } : never;
529
+ type InteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, Kind extends string> = {
530
+ [InteractionId in InteractionIdOfDefinitionPhase<Definition, PhaseName>]: InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends infer Spec ? Extract<CollectorKindsOfInteractionDefinition<Spec>, Kind> extends never ? never : InteractionId : never;
531
+ }[InteractionIdOfDefinitionPhase<Definition, PhaseName>];
532
+ type QualifiedInteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, Kind extends string> = InteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName, Kind> extends infer InteractionId extends string ? `${PhaseName}.${InteractionId}` : never;
533
+ type PromptInteractionKeyOfDefinition<Definition> = {
534
+ [PhaseName in PhaseNamesOfDefinition<Definition>]: QualifiedInteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName, "prompt">;
535
+ }[PhaseNamesOfDefinition<Definition>];
536
+ type BoardInteractionKeyOfDefinition<Definition> = {
537
+ [PhaseName in PhaseNamesOfDefinition<Definition>]: QualifiedInteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName, "board-edge" | "board-space" | "board-tile" | "board-vertex">;
538
+ }[PhaseNamesOfDefinition<Definition>];
539
+ type CardInteractionKeyOfDefinition<Definition> = {
540
+ [PhaseName in PhaseNamesOfDefinition<Definition>]: QualifiedInteractionIdsWithCollectorKindOfDefinitionPhase<Definition, PhaseName, "card">;
541
+ }[PhaseNamesOfDefinition<Definition>];
542
+ type InputKeysWithCollectorKindOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>, Kind extends string> = InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends infer Spec ? InputKeysWithCollectorKindOfInteractionDefinition<Spec, Kind> : never;
543
+ type CardInputZoneIdsOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>, Input extends string> = InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends infer Spec ? CardInputZoneIdsOfInteractionDefinition<Spec, Input> : never;
544
+ type ParamsOfInteractionOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>> = InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends infer Spec ? Spec extends {
545
+ readonly cardType: unknown;
546
+ readonly playFrom: unknown;
547
+ } ? {
548
+ cardId: string;
549
+ } & ParamsOfCollectors<CollectorsOfInteractionDefinition<Spec>> : ParamsOfCollectors<CollectorsOfInteractionDefinition<Spec>> : never;
550
+ /**
551
+ * Client-facing params shape for an interaction. Omits engine-sampled
552
+ * collectors (`rngInput.*`) — clients never supply those fields; the
553
+ * trusted reducer bundle fills them during `submitInteraction`.
554
+ *
555
+ * This is the type that drives `submit(playerId, id, params)`,
556
+ * `handle.submit(params)`, and the generated `InteractionParams` surface
557
+ * in `shared/generated/ui-contract.ts`. The `reduce`-input counterpart is
558
+ * {@link ParamsOfInteractionOfDefinition}, which includes every field
559
+ * because the engine has already filled the sampled ones by then.
560
+ */
561
+ type ClientParamsOfInteractionOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>> = InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends infer Spec ? Spec extends {
562
+ readonly cardType: unknown;
563
+ readonly playFrom: unknown;
564
+ } ? {
565
+ cardId: string;
566
+ } & ClientParamsOfCollectors<CollectorsOfInteractionDefinition<Spec>> : ClientParamsOfCollectors<CollectorsOfInteractionDefinition<Spec>> : never;
567
+ type DefaultedClientCollectorKeys<Collectors extends Record<string, InputCollector>> = {
568
+ [K in keyof Collectors]: Collectors[K] extends {
569
+ readonly kind: "rng";
570
+ } ? never : Collectors[K] extends {
571
+ readonly defaultValue: unknown;
572
+ } ? K : never;
573
+ }[keyof Collectors];
574
+ type DefaultedClientParamKeysOfInteractionOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, InteractionId extends InteractionIdOfDefinitionPhase<Definition, PhaseName>> = InteractionSpecByNameOfDefinitionPhase<Definition, PhaseName, InteractionId> extends infer Spec ? DefaultedClientCollectorKeys<CollectorsOfInteractionDefinition<Spec>> & string : never;
575
+ type StageRegistryOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseDefinitionByName<Definition, PhaseName> extends {
576
+ stages?: infer Stages;
577
+ } ? NonNullable<Stages> : Record<string, never>;
578
+ type StageNamesOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = StageRegistryOfDefinitionPhase<Definition, PhaseName> extends infer Stages ? Stages extends Record<string, unknown> ? NonNeverKeys<Stages> & string : never : never;
579
+ type ZoneRegistriesOfDefinition<Definition> = PhasesOfDefinition<Definition>[keyof PhasesOfDefinition<Definition> & string] extends {
580
+ zones?: infer Zones;
581
+ } ? NonNullable<Zones> : never;
582
+ type ZoneIdsOfDefinition<Definition> = ZoneRegistriesOfDefinition<Definition> extends infer Zones ? Zones extends readonly (infer ZoneId)[] ? Extract<ZoneId, string> : never : never;
583
+ type ZoneListOfDefinitionPhase<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>> = PhaseDefinitionByName<Definition, PhaseName> extends {
584
+ zones?: infer Zones;
585
+ } ? NonNullable<Zones> : readonly [];
586
+ type PlayableInteractionsOfZoneOfDefinition<Definition, PhaseName extends PhaseNamesOfDefinition<Definition>, ZoneId extends string> = ZoneListOfDefinitionPhase<Definition, PhaseName> extends readonly (infer From)[] ? Extract<From, ZoneId> extends never ? never : CardActionRegistryOfDefinitionPhase<Definition, PhaseName> extends infer CardActions ? CardActions extends Record<string, unknown> ? {
587
+ [ActionId in keyof CardActions & string]: CardActions[ActionId] extends {
588
+ playFrom: infer PlayFrom extends string;
589
+ } ? Extract<PlayFrom, ZoneId> extends never ? never : ActionId : never;
590
+ }[keyof CardActions & string] : never : never : never;
591
+
592
+ /**
593
+ * A freestanding, memoized projection of immutable game state.
594
+ *
595
+ * Use `defineDerived` for values that are pure functions of component
596
+ * locations, zone contents, resources, or other state fields - and are
597
+ * consumed from multiple reducer or view call sites, or whose compute cost
598
+ * is non-trivial (graph walks, aggregate reductions).
599
+ *
600
+ * Do NOT cache derived values in `publicState`. State fields should be
601
+ * inputs to derivations, not mirrors of them.
602
+ */
603
+ type DerivedDefinition<Contract, Value> = {
604
+ /** Optional label for debugging. Does not affect caching. */
605
+ readonly name?: string;
606
+ readonly compute: (ctx: {
607
+ readonly state: BaseGameStateOfContract<Contract>;
608
+ readonly q: TableQueriesOfState<BaseGameStateOfContract<Contract>>;
609
+ readonly derived: DerivedResolver;
610
+ }) => Value;
611
+ };
612
+ /**
613
+ * Resolves a `DerivedDefinition` to its value. Callers do not need to know
614
+ * about memoization - the resolver handles caching internally.
615
+ */
616
+ type DerivedResolver = <Value>(def: DerivedDefinition<never, Value>) => Value;
617
+ /**
618
+ * Author-facing factory for creating a derived value tied to a game
619
+ * contract. Usage:
620
+ *
621
+ * ```ts
622
+ * export const longestRoad = defineDerived<GameContract>()({
623
+ * name: "longestRoad",
624
+ * compute: ({ q, derived }) => computeLongestRoad(q),
625
+ * });
626
+ * ```
627
+ */
628
+ declare function defineDerived<Contract>(): <Value>(def: {
629
+ name?: string;
630
+ compute: (ctx: {
631
+ state: BaseGameStateOfContract<Contract>;
632
+ q: TableQueriesOfState<BaseGameStateOfContract<Contract>>;
633
+ derived: DerivedResolver;
634
+ }) => Value;
635
+ }) => DerivedDefinition<Contract, Value>;
636
+ /**
637
+ * Creates a resolver scoped to a single state snapshot. Each engine tick
638
+ * and each view projection call creates its own resolver; cache lifetime
639
+ * ends with the call. Cache key is the `DerivedDefinition` identity (the
640
+ * object reference).
641
+ *
642
+ * Re-entry on an in-flight definition throws a readable error.
643
+ */
644
+ declare function createDerivedResolver<State extends {
645
+ table: RuntimeTableRecord;
646
+ }>(state: State, options?: {
647
+ q?: TableQueriesOfState<State>;
648
+ }): DerivedResolver;
649
+
650
+ type StaticBoardsOfManifest<Manifest> = Manifest extends {
651
+ staticBoards?: infer StaticBoards;
652
+ } ? NonNullable<StaticBoards> : {
653
+ byId: Record<string, never>;
654
+ hex: Record<string, never>;
655
+ square: Record<string, never>;
656
+ };
657
+ type StaticBoardMapOfManifest<Manifest> = StaticBoardsOfManifest<Manifest> extends {
658
+ byId: infer Boards;
659
+ } ? Boards : Record<string, never>;
660
+ type StaticHexBoardMapOfManifest<Manifest> = StaticBoardsOfManifest<Manifest> extends {
661
+ hex: infer Boards;
662
+ } ? Boards : Record<string, never>;
663
+ type StaticSquareBoardMapOfManifest<Manifest> = StaticBoardsOfManifest<Manifest> extends {
664
+ square: infer Boards;
665
+ } ? Boards : Record<string, never>;
666
+ type StaticViewQueries<Manifest extends ManifestContract<RuntimeTableRecord>> = {
667
+ board: {
668
+ get: <BoardId extends StringKeyOf<StaticBoardMapOfManifest<Manifest>>>(boardId: BoardId) => StaticBoardMapOfManifest<Manifest>[BoardId];
669
+ hex: <BoardId extends StringKeyOf<StaticHexBoardMapOfManifest<Manifest>>>(boardId: BoardId) => StaticHexBoardMapOfManifest<Manifest>[BoardId];
670
+ square: <BoardId extends StringKeyOf<StaticSquareBoardMapOfManifest<Manifest>>>(boardId: BoardId) => StaticSquareBoardMapOfManifest<Manifest>[BoardId];
671
+ };
672
+ };
673
+ type ContinuationSourceKind = "effect";
674
+ type ResumableEffectKind = "rollDie" | "shuffleSharedZone" | "shufflePlayerZone";
675
+ type ContinuationKind = ResumableEffectKind;
676
+ type RollDieContinuationResponse = {
677
+ dieId: string;
678
+ value: number;
679
+ };
680
+ type ShuffleSharedZoneContinuationResponse = {
681
+ zoneId: string;
682
+ orderedCardIds: readonly string[];
683
+ };
684
+ type ShufflePlayerZoneContinuationResponse = {
685
+ zoneId: string;
686
+ playerId: string;
687
+ orderedCardIds: readonly string[];
688
+ };
689
+ type EffectContinuationResponse<Kind extends ResumableEffectKind> = Kind extends "rollDie" ? RollDieContinuationResponse : Kind extends "shuffleSharedZone" ? ShuffleSharedZoneContinuationResponse : Kind extends "shufflePlayerZone" ? ShufflePlayerZoneContinuationResponse : never;
690
+ type EffectContinuationInput<DataSchema extends AnySchema, Kind extends ResumableEffectKind = ResumableEffectKind> = {
691
+ source: "effect";
692
+ effectKind: Kind;
693
+ data: z.infer<DataSchema>;
694
+ response: EffectContinuationResponse<Kind>;
695
+ };
696
+ type ContinuationInput<DataSchema extends AnySchema> = EffectContinuationInput<DataSchema, ResumableEffectKind>;
697
+ type ContinuationInputForSource<DataSchema extends AnySchema, EffectType extends ResumableEffectKind = ResumableEffectKind> = EffectContinuationInput<DataSchema, EffectType>;
698
+ type PhaseEnterContext = {
699
+ event: "initialize" | "transition";
700
+ };
701
+ type BivariantCallback<Args, Result> = {
702
+ bivarianceHack(args: Args): Result;
703
+ }["bivarianceHack"];
704
+ type ActionContext<State extends {
705
+ table: RuntimeTableRecord;
706
+ flow: {
707
+ currentPhase: string;
708
+ };
709
+ }, Manifest extends ManifestContract<TableOfState<State>>> = {
710
+ currentPhase: PhaseNameOfState<State>;
711
+ manifest: Manifest;
712
+ playerOrder: PlayerIdOfState<State>[];
713
+ activePlayers: PlayerIdOfState<State>[];
714
+ runtime: Omit<ReducerRuntimeStateForState<State>, "rng">;
715
+ setup: SetupSelectionOfManifest<Manifest> | null;
716
+ };
717
+ type ValidationIssue<ErrorCode extends string = string> = {
718
+ errorCode: ErrorCode;
719
+ message?: string;
720
+ };
721
+ type RuntimeHelpers<State extends {
722
+ table: RuntimeTableRecord;
723
+ flow: {
724
+ currentPhase: string;
725
+ };
726
+ }, ErrorCode extends string = string> = {
727
+ accept(state: State, options?: ReducerAcceptOptions<State>): ReducerAccept<State>;
728
+ endGame(state: State, outcome: GameOutcome<PlayerIdOfState<State>>, options?: ReducerAcceptOptions<State>): ReducerAccept<State>;
729
+ reject: (errorCode: ErrorCode, message?: string) => ReducerReject;
730
+ fx: ReducerFx<State>;
731
+ ops: ReducerOps<State>;
732
+ edit<DraftState extends State>(state: DraftState): ReducerTransaction<DraftState>;
733
+ q: TableQueriesOfState<State>;
734
+ derived: DerivedResolver;
735
+ };
736
+ type RandomHelpers = {
737
+ subset<const Values extends readonly unknown[]>(options: {
738
+ from: Values;
739
+ count: number;
740
+ }): readonly Values[number][];
741
+ };
742
+ type MutationRuntimeHelpers = {
743
+ random: RandomHelpers;
744
+ };
745
+ type PhaseEnterArgs<State extends {
746
+ table: RuntimeTableRecord;
747
+ flow: {
748
+ currentPhase: string;
749
+ };
750
+ }, Manifest extends ManifestContract<TableOfState<State>>> = ActionContext<State, Manifest> & RuntimeHelpers<State> & MutationRuntimeHelpers & PhaseEnterContext & {
751
+ state: State;
752
+ };
753
+ type ActorSelectorArgs<State extends {
754
+ table: RuntimeTableRecord;
755
+ flow: {
756
+ currentPhase: string;
757
+ };
758
+ }, Manifest extends ManifestContract<TableOfState<State>>> = ActionContext<State, Manifest> & RuntimeHelpers<State> & {
759
+ state: State;
760
+ };
761
+ type ActorSelection<State extends {
762
+ table: RuntimeTableRecord;
763
+ flow: {
764
+ currentPhase: string;
765
+ };
766
+ }> = PlayerIdOfState<State> | readonly PlayerIdOfState<State>[] | null | undefined;
767
+ type ActorSelector<State extends {
768
+ table: RuntimeTableRecord;
769
+ flow: {
770
+ currentPhase: string;
771
+ };
772
+ }, Manifest extends ManifestContract<TableOfState<State>>> = BivariantCallback<ActorSelectorArgs<State, Manifest>, ActorSelection<State>>;
773
+ type ContinuationReduceArgs<DataSchema extends AnySchema, State extends {
774
+ table: RuntimeTableRecord;
775
+ flow: {
776
+ currentPhase: string;
777
+ };
778
+ }, Manifest extends ManifestContract<TableOfState<State>>, EffectType extends ResumableEffectKind = ResumableEffectKind> = ActionContext<State, Manifest> & RuntimeHelpers<State> & MutationRuntimeHelpers & {
779
+ state: State;
780
+ input: ContinuationInputForSource<DataSchema, EffectType>;
781
+ };
782
+ type ScopedPhaseState<State extends {
783
+ table: RuntimeTableRecord;
784
+ flow: {
785
+ currentPhase: string;
786
+ };
787
+ phase: object;
788
+ }, PhaseState extends object> = State & {
789
+ phase: PhaseState;
790
+ };
791
+ type ContinuationCallable<DataSchema extends AnySchema, State extends {
792
+ table: RuntimeTableRecord;
793
+ flow: {
794
+ currentPhase: string;
795
+ };
796
+ }, Manifest extends ManifestContract<TableOfState<State>>, ContinuationId extends string = string, EffectType extends ResumableEffectKind = ResumableEffectKind> = ((data: z.infer<DataSchema>) => ContinuationToken<z.infer<DataSchema>, ContinuationId, EffectContinuationResponse<EffectType>>) & {
797
+ id: ContinuationId;
798
+ source: "effect";
799
+ dataSchema: DataSchema;
800
+ responseSchema: AnySchema;
801
+ effectKind?: EffectType;
802
+ reduce: BivariantCallback<ContinuationReduceArgs<DataSchema, State, Manifest, EffectType>, ReducerResult<State>>;
803
+ };
804
+ type AnyContinuationCallable<State extends {
805
+ table: RuntimeTableRecord;
806
+ flow: {
807
+ currentPhase: string;
808
+ };
809
+ }> = {
810
+ (data: never): AnyContinuationToken;
811
+ id: string;
812
+ source: "effect";
813
+ dataSchema: AnySchema;
814
+ responseSchema: AnySchema;
815
+ effectKind?: ResumableEffectKind;
816
+ reduce: (args: unknown) => ReducerResult<State>;
817
+ };
818
+ type EffectContinuationCallable<DataSchema extends AnySchema, State extends {
819
+ table: RuntimeTableRecord;
820
+ flow: {
821
+ currentPhase: string;
822
+ };
823
+ }, Manifest extends ManifestContract<TableOfState<State>>, ContinuationId extends string = string, Kind extends ResumableEffectKind = ResumableEffectKind> = ContinuationCallable<DataSchema, State, Manifest, ContinuationId, Kind>;
824
+
825
+ /**
826
+ * `rollDie` effect. Resolves a `rollDie` wire effect. `reduce` / `context`
827
+ * are both optional so authors can fire-and-forget a die roll without
828
+ * observing the result.
829
+ */
830
+ type EffectRollDieDefinition<Id extends string, ContextSchema extends AnySchema, State extends {
831
+ table: RuntimeTableRecord;
832
+ flow: {
833
+ currentPhase: string;
834
+ };
835
+ }, Manifest extends ManifestContract<TableOfState<State>>> = {
836
+ readonly type: "rollDie";
837
+ readonly id: Id;
838
+ readonly contextSchema?: ContextSchema;
839
+ readonly __continuation?: EffectContinuationCallable<ContextSchema, State, Manifest, Id, "rollDie">;
840
+ };
841
+ /**
842
+ * `shuffleSharedZone` effect. Resolves a `shuffleSharedZone` wire effect.
843
+ * `reduce` / `context` are both optional.
844
+ */
845
+ type EffectShuffleDefinition<Id extends string, ContextSchema extends AnySchema, State extends {
846
+ table: RuntimeTableRecord;
847
+ flow: {
848
+ currentPhase: string;
849
+ };
850
+ }, Manifest extends ManifestContract<TableOfState<State>>> = {
851
+ readonly type: "shuffleSharedZone";
852
+ readonly id: Id;
853
+ readonly contextSchema?: ContextSchema;
854
+ readonly __continuation?: EffectContinuationCallable<ContextSchema, State, Manifest, Id, "shuffleSharedZone">;
855
+ };
856
+ /**
857
+ * `shufflePlayerZone` effect. Resolves a `shufflePlayerZone` wire effect for
858
+ * a single player's perPlayer zone (e.g. deck-builder reshuffle of discard
859
+ * into deck). `reduce` / `context` are both optional.
860
+ */
861
+ type EffectShufflePlayerZoneDefinition<Id extends string, ContextSchema extends AnySchema, State extends {
862
+ table: RuntimeTableRecord;
863
+ flow: {
864
+ currentPhase: string;
865
+ };
866
+ }, Manifest extends ManifestContract<TableOfState<State>>> = {
867
+ readonly type: "shufflePlayerZone";
868
+ readonly id: Id;
869
+ readonly contextSchema?: ContextSchema;
870
+ readonly __continuation?: EffectContinuationCallable<ContextSchema, State, Manifest, Id, "shufflePlayerZone">;
871
+ };
872
+ /**
873
+ * Discriminated union of every `defineEffect` output.
874
+ */
875
+ type EffectDefinition<State extends {
876
+ table: RuntimeTableRecord;
877
+ flow: {
878
+ currentPhase: string;
879
+ };
880
+ }, Manifest extends ManifestContract<TableOfState<State>>> = EffectRollDieDefinition<string, AnySchema, State, Manifest> | EffectShuffleDefinition<string, AnySchema, State, Manifest> | EffectShufflePlayerZoneDefinition<string, AnySchema, State, Manifest>;
881
+ type EffectMap<State extends {
882
+ table: RuntimeTableRecord;
883
+ flow: {
884
+ currentPhase: string;
885
+ };
886
+ }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, EffectDefinition<State, Manifest>>;
887
+ type EffectRegistryOfPhase<Phase> = Phase extends {
888
+ effects?: infer Effects extends Record<string, unknown>;
889
+ } ? Effects : Record<string, never>;
890
+
891
+ type InputCollectorKind = "form" | "board-vertex" | "board-edge" | "board-tile" | "board-space" | "card" | "prompt" | "rng";
892
+ type TargetKind = "edge" | "vertex" | "space" | "tile" | "card";
893
+ type BoardInputCollectorKind = Exclude<InputCollectorKind, "form" | "card" | "prompt" | "rng">;
894
+ type CardInputCollectorMeta = {
895
+ readonly zoneId: string;
896
+ readonly zoneIds?: readonly string[];
897
+ readonly targetKind: "card";
898
+ };
899
+ type BoardInputCollectorMeta = {
900
+ readonly targetKind: TargetKind;
901
+ readonly boardId: string;
902
+ readonly valueKind?: "board-id" | "player-board-space";
903
+ };
904
+ type PromptInputCollectorMeta = {
905
+ readonly options: (state: unknown, playerId: unknown, q: unknown) => ReadonlyArray<{
906
+ id: unknown;
907
+ label?: string;
908
+ }>;
909
+ readonly eligibleOptions: (state: unknown, playerId: unknown, q: unknown) => ReadonlyArray<{
910
+ id: unknown;
911
+ label?: string;
912
+ }>;
913
+ };
914
+ type RngInputCollectorMeta = {
915
+ readonly rng: "d6";
916
+ readonly count: number;
917
+ } | {
918
+ readonly rng: "coin";
919
+ };
920
+ type InputCollectorMetaForKind<Kind extends InputCollectorKind> = Kind extends "card" ? CardInputCollectorMeta : Kind extends BoardInputCollectorKind ? BoardInputCollectorMeta : Kind extends "prompt" ? PromptInputCollectorMeta | undefined : Kind extends "rng" ? RngInputCollectorMeta : never;
921
+ type InputSelectionDescriptor = {
922
+ readonly mode: "single";
923
+ } | {
924
+ readonly mode: "many";
925
+ readonly min: number;
926
+ readonly max?: number;
927
+ readonly distinct?: boolean;
928
+ };
929
+ type InputDomainResolverDescriptor = {
930
+ readonly interactionKey?: string;
931
+ readonly inputKey: string;
932
+ };
933
+ type InputDomainDependencyCase<Domain extends InputDomainDescriptor = InputDomainDescriptor> = {
934
+ when: Record<string, string>;
935
+ domain: Domain;
936
+ };
937
+ type EagerInputDomainDependencies<Domain extends InputDomainDescriptor = InputDomainDescriptor> = {
938
+ readonly mode: "eager";
939
+ readonly dependentCases: readonly InputDomainDependencyCase<Domain>[];
940
+ };
941
+ type LazyInputDomainDependencies = {
942
+ readonly mode: "lazy";
943
+ readonly dependsOn: readonly string[];
944
+ readonly resolver: InputDomainResolverDescriptor;
945
+ };
946
+ type CardTargetDomainDescriptor = ResolvedCardTargetDomainDescriptor | LazyCardTargetDomainDescriptor;
947
+ type ResolvedCardTargetDomainDescriptor = {
948
+ readonly type: "cardTarget";
949
+ readonly projection: "resolved";
950
+ readonly targetKind: "card";
951
+ readonly zoneIds: readonly string[];
952
+ readonly eligibleTargets: readonly string[];
953
+ readonly selection?: InputSelectionDescriptor;
954
+ readonly dependencies?: EagerInputDomainDependencies<ResolvedCardTargetDomainDescriptor>;
955
+ };
956
+ type LazyCardTargetDomainDescriptor = {
957
+ readonly type: "cardTarget";
958
+ readonly projection: "lazy";
959
+ readonly targetKind: "card";
960
+ readonly zoneIds: readonly string[];
961
+ readonly eligibleTargets?: never;
962
+ readonly selection?: InputSelectionDescriptor;
963
+ readonly dependencies: LazyInputDomainDependencies;
964
+ };
965
+ type BoardTargetDomainDescriptor = ResolvedBoardTargetDomainDescriptor | LazyBoardTargetDomainDescriptor;
966
+ type ResolvedBoardTargetDomainDescriptor = {
967
+ readonly type: "boardTarget";
968
+ readonly projection: "resolved";
969
+ readonly targetKind: Exclude<TargetKind, "card">;
970
+ readonly boardId: string;
971
+ readonly valueKind?: "board-id" | "player-board-space";
972
+ readonly eligibleTargets: readonly string[];
973
+ readonly selection?: InputSelectionDescriptor;
974
+ readonly dependencies?: EagerInputDomainDependencies<ResolvedBoardTargetDomainDescriptor>;
975
+ };
976
+ type LazyBoardTargetDomainDescriptor = {
977
+ readonly type: "boardTarget";
978
+ readonly projection: "lazy";
979
+ readonly targetKind: Exclude<TargetKind, "card">;
980
+ readonly boardId: string;
981
+ readonly valueKind?: "board-id" | "player-board-space";
982
+ readonly eligibleTargets?: never;
983
+ readonly selection?: InputSelectionDescriptor;
984
+ readonly dependencies: LazyInputDomainDependencies;
985
+ };
986
+ type ResourceMapDomainDescriptor = {
987
+ type: "resourceMap";
988
+ resources: Array<{
989
+ resourceId: string;
990
+ label?: string;
991
+ icon?: string;
992
+ min: number;
993
+ max: number;
994
+ }>;
995
+ selection?: InputSelectionDescriptor;
996
+ };
997
+ type BoundedNumberDomainDescriptor = {
998
+ type: "boundedNumber";
999
+ min: number;
1000
+ max: number;
1001
+ step?: number;
1002
+ selection?: InputSelectionDescriptor;
1003
+ };
1004
+ type ChoiceDomainDescriptor = {
1005
+ type: "choice";
1006
+ choices: Array<{
1007
+ value: string | null;
1008
+ label: string;
1009
+ icon?: string;
1010
+ badge?: string;
1011
+ description?: string;
1012
+ disabled?: boolean;
1013
+ disabledReason?: string;
1014
+ }>;
1015
+ selection?: InputSelectionDescriptor;
1016
+ dependencies?: EagerInputDomainDependencies<ChoiceDomainDescriptor>;
1017
+ };
1018
+ type ChoiceListDomainDescriptor = {
1019
+ type: "choiceList";
1020
+ choices: Array<{
1021
+ value: string;
1022
+ label: string;
1023
+ icon?: string;
1024
+ badge?: string;
1025
+ description?: string;
1026
+ disabled?: boolean;
1027
+ disabledReason?: string;
1028
+ }>;
1029
+ min?: number;
1030
+ max?: number;
1031
+ selection?: InputSelectionDescriptor;
1032
+ dependencies?: EagerInputDomainDependencies<ChoiceListDomainDescriptor>;
1033
+ };
1034
+ type InputDomainDescriptor = CardTargetDomainDescriptor | BoardTargetDomainDescriptor | ResourceMapDomainDescriptor | BoundedNumberDomainDescriptor | ChoiceDomainDescriptor | ChoiceListDomainDescriptor;
1035
+ type DomainProjector<Domain extends InputDomainDescriptor> = (state: CollectorState, playerId: string, q: unknown, derived: DerivedResolver, values?: Readonly<Record<string, unknown>>) => Domain;
1036
+ type InputDomainForCollectorKind<Kind extends InputCollectorKind> = Kind extends "card" ? CardTargetDomainDescriptor : Kind extends BoardInputCollectorKind ? BoardTargetDomainDescriptor : Exclude<InputDomainDescriptor, CardTargetDomainDescriptor | BoardTargetDomainDescriptor>;
1037
+ /**
1038
+ * Base state shape every collector is generic over. Collectors that need
1039
+ * narrowed ids (card / player) use `PlayerIdOfState<State>` etc. to thread
1040
+ * the manifest's branded types.
1041
+ */
1042
+ type CollectorState = {
1043
+ table: RuntimeTableRecord;
1044
+ flow: {
1045
+ currentPhase: string;
1046
+ };
1047
+ };
1048
+ /**
1049
+ * An input collector declares:
1050
+ * - a Zod schema for the parameter value the interaction expects. The
1051
+ * schema's `z.infer` feeds `ParamsOf<Collectors>`, so downstream
1052
+ * `reduce({ input: { params } })` sees branded ids from `cardInput` /
1053
+ * `boardInput` without a second declaration.
1054
+ * - an optional `eligibleTargets(state, playerId, q)` hook that the runtime
1055
+ * calls to enumerate server-authoritative valid values. The hook receives
1056
+ * the same `q` table-queries helper that `validate` / `reduce` see, so
1057
+ * board/card/prompt collectors can reuse whatever board-graph or zone
1058
+ * lookups they already use for validation without rebuilding them from
1059
+ * raw state. Each collector helper narrows the return type to its own
1060
+ * branded id (`CardIdOfState<State>` for `cardInput`, the caller-supplied
1061
+ * `Id extends string` for `boardInput.*`, etc.). At the generic interface
1062
+ * level we keep inputs weak (`CollectorState`, `string`, `unknown`) and
1063
+ * the return `ReadonlyArray<unknown>` so the runtime can treat all
1064
+ * collectors uniformly; per-helper signatures provide the author-facing
1065
+ * strong typing.
1066
+ * - optional `meta` for collector-kind-specific routing (e.g. `cardInput`
1067
+ * stores the `zoneId` the card must come from).
1068
+ *
1069
+ * Collectors without meaningful eligibility (`form`, `rng`) leave
1070
+ * `eligibleTargets` undefined.
1071
+ */
1072
+ type InputCollectorMetaSlot<Kind extends InputCollectorKind> = [
1073
+ InputCollectorMetaForKind<Kind>
1074
+ ] extends [never] ? {
1075
+ readonly meta?: never;
1076
+ } : undefined extends InputCollectorMetaForKind<Kind> ? {
1077
+ readonly meta?: Exclude<InputCollectorMetaForKind<Kind>, undefined>;
1078
+ } : {
1079
+ readonly meta: InputCollectorMetaForKind<Kind>;
1080
+ };
1081
+ type InputCollectorBase<Schema extends SchemaLike<unknown> = SchemaLike<unknown>, State extends CollectorState = CollectorState, Kind extends InputCollectorKind = InputCollectorKind> = {
1082
+ readonly kind: Kind;
1083
+ readonly schema: Schema;
1084
+ readonly defaultValue?: z.infer<Schema>;
1085
+ readonly selection?: InputSelectionDescriptor;
1086
+ readonly eligibleTargets?: (state: CollectorState, playerId: string, q: unknown, values?: Readonly<Record<string, unknown>>) => ReadonlyArray<unknown>;
1087
+ readonly validateTarget?: (state: CollectorState, playerId: string, q: unknown, targetId: unknown, values?: Readonly<Record<string, unknown>>) => ValidationIssue | null | undefined;
1088
+ readonly dependsOn?: readonly string[];
1089
+ readonly resolveDefaultValue?: (state: CollectorState, playerId: string, q: unknown, derived: DerivedResolver, domain: InputDomainDescriptor) => z.infer<Schema> | undefined;
1090
+ } & (Kind extends "rng" ? {
1091
+ readonly domain?: never;
1092
+ } : Kind extends "card" | BoardInputCollectorKind ? {
1093
+ readonly domain: DomainProjector<InputDomainForCollectorKind<Kind>>;
1094
+ } : {
1095
+ readonly domain?: DomainProjector<InputDomainForCollectorKind<Kind>>;
1096
+ }) & InputCollectorMetaSlot<Kind>;
1097
+ type InputCollector<Schema extends SchemaLike<unknown> = SchemaLike<unknown>, State extends CollectorState = CollectorState, Kind extends InputCollectorKind = InputCollectorKind> = Kind extends InputCollectorKind ? InputCollectorBase<Schema, State, Kind> : never;
1098
+ type ParamsOf<Collectors extends Record<string, InputCollector>> = {
1099
+ [K in keyof Collectors]: Collectors[K] extends InputCollector<infer S> ? S extends SchemaLike<infer V> ? V : never : never;
1100
+ };
1101
+ type EngineSampledCollectorKeys<Collectors extends Record<string, InputCollector>> = {
1102
+ [K in keyof Collectors]: Collectors[K] extends InputCollector & {
1103
+ kind: "rng";
1104
+ } ? K : never;
1105
+ }[keyof Collectors];
1106
+ type ClientParamsOf<Collectors extends Record<string, InputCollector>> = {
1107
+ [K in keyof Collectors as K extends EngineSampledCollectorKeys<Collectors> ? never : K]: Collectors[K] extends InputCollector<infer S> ? S extends SchemaLike<infer V> ? V : never : never;
1108
+ };
1109
+
1110
+ type InteractionReduceInput<Collectors extends Record<string, InputCollector>, State extends {
1111
+ table: RuntimeTableRecord;
1112
+ flow: {
1113
+ currentPhase: string;
1114
+ };
1115
+ }> = {
1116
+ playerId: PlayerIdOfState<State>;
1117
+ params: ParamsOf<Collectors>;
1118
+ };
1119
+ type InteractionValidateArgs<Collectors extends Record<string, InputCollector>, State extends {
1120
+ table: RuntimeTableRecord;
1121
+ flow: {
1122
+ currentPhase: string;
1123
+ };
1124
+ }, Manifest extends ManifestContract<TableOfState<State>>, ErrorCode extends string = string> = ActionContext<State, Manifest> & RuntimeHelpers<State, ErrorCode> & {
1125
+ state: State;
1126
+ input: InteractionReduceInput<Collectors, State>;
1127
+ };
1128
+ type InteractionReduceArgs<Collectors extends Record<string, InputCollector>, State extends {
1129
+ table: RuntimeTableRecord;
1130
+ flow: {
1131
+ currentPhase: string;
1132
+ };
1133
+ }, Manifest extends ManifestContract<TableOfState<State>>, ErrorCode extends string = string> = InteractionValidateArgs<Collectors, State, Manifest, ErrorCode> & MutationRuntimeHelpers;
1134
+ type InteractionAvailabilityArgs<State extends {
1135
+ table: RuntimeTableRecord;
1136
+ flow: {
1137
+ currentPhase: string;
1138
+ };
1139
+ }, Manifest extends ManifestContract<TableOfState<State>>> = ActionContext<State, Manifest> & RuntimeHelpers<State> & {
1140
+ state: State;
1141
+ input: {
1142
+ playerId: PlayerIdOfState<State>;
1143
+ };
1144
+ };
1145
+ type InteractionRuleValidationResult<ErrorCode extends string = string> = boolean | string | ValidationIssue<ErrorCode> | null | undefined;
1146
+ type InteractionRule<Collectors extends Record<string, InputCollector> = Record<string, InputCollector>, State extends {
1147
+ table: RuntimeTableRecord;
1148
+ flow: {
1149
+ currentPhase: string;
1150
+ };
1151
+ } = {
1152
+ table: RuntimeTableRecord;
1153
+ flow: {
1154
+ currentPhase: string;
1155
+ };
1156
+ }, Manifest extends ManifestContract<TableOfState<State>> = ManifestContract<TableOfState<State>>, ErrorCode extends string = string> = {
1157
+ /**
1158
+ * Stable rule id for diagnostics and tests. Rule ids are author-owned and
1159
+ * should be unique within one interaction.
1160
+ */
1161
+ id: string;
1162
+ /**
1163
+ * Error code used when the rule fails. The same code is used for descriptor
1164
+ * availability and submit-time validation unless `validate` returns a
1165
+ * specific ValidationIssue.
1166
+ */
1167
+ errorCode: ErrorCode;
1168
+ message?: string;
1169
+ /**
1170
+ * Projection-time rule. Runs without submitted params, so UI descriptors can
1171
+ * reflect action availability before the user clicks.
1172
+ */
1173
+ available?: BivariantCallback<InteractionAvailabilityArgs<State, Manifest>, boolean>;
1174
+ /**
1175
+ * Submit-time rule. Runs with parsed params and may return false, a concrete
1176
+ * ValidationIssue, null, or undefined.
1177
+ */
1178
+ validate?: BivariantCallback<InteractionValidateArgs<Collectors, State, Manifest, ErrorCode>, InteractionRuleValidationResult<ErrorCode>>;
1179
+ };
1180
+ type InteractionCommitPolicy = {
1181
+ mode: "manual";
1182
+ } | {
1183
+ mode: "autoWhenReady";
1184
+ };
1185
+ type HasManyInputCollector<Collectors extends Record<string, InputCollector>> = Extract<Collectors[keyof Collectors], {
1186
+ readonly selection: {
1187
+ readonly mode: "many";
1188
+ };
1189
+ }> extends never ? false : true;
1190
+ type InteractionCommitPolicyFor<Collectors extends Record<string, InputCollector>> = HasManyInputCollector<Collectors> extends true ? {
1191
+ mode: "manual";
1192
+ } : InteractionCommitPolicy;
1193
+ /**
1194
+ * Projection-level interaction kind, derived by the trusted bundle from
1195
+ * collector shape:
1196
+ *
1197
+ * - `"action"`: any interaction whose inputs are ordinary collectors
1198
+ * (`formInput`, `cardInput`).
1199
+ * - `"prompt"`: any interaction whose inputs include a `promptInput`
1200
+ * collector. Prompt descriptors carry addressed-player context and options
1201
+ * so UI primitives can render response controls without reducer-owned
1202
+ * placement metadata.
1203
+ *
1204
+ * Authors never set this directly — the `promptInput(...)` collector is
1205
+ * the single source of truth for prompt semantics. See {@link promptInput}
1206
+ * and {@link InteractionDescriptor.kind}.
1207
+ */
1208
+ type InteractionKind = "action" | "prompt";
1209
+ type InteractionPresentation = {
1210
+ label: string;
1211
+ help?: string;
1212
+ };
1213
+ type InteractionToArgs<State extends {
1214
+ table: RuntimeTableRecord;
1215
+ flow: {
1216
+ currentPhase: string;
1217
+ };
1218
+ }, Manifest extends ManifestContract<TableOfState<State>>> = ActionContext<State, Manifest> & {
1219
+ state: State;
1220
+ };
1221
+ type InteractionSpec<Collectors extends Record<string, InputCollector> = Record<string, InputCollector>, State extends {
1222
+ table: RuntimeTableRecord;
1223
+ flow: {
1224
+ currentPhase: string;
1225
+ };
1226
+ } = {
1227
+ table: RuntimeTableRecord;
1228
+ flow: {
1229
+ currentPhase: string;
1230
+ };
1231
+ }, Manifest extends ManifestContract<TableOfState<State>> = ManifestContract<TableOfState<State>>, ErrorCode extends string = string> = {
1232
+ inputs: Collectors;
1233
+ paramsSchema?: SchemaLike<ClientParamsOf<Collectors>>;
1234
+ presentation?: InteractionPresentation;
1235
+ /** @internal Phase-local step gates are attached by `defineStepPhase`. */
1236
+ __steps?: readonly string[];
1237
+ /**
1238
+ * Draft commit policy. The input collectors still own value shape and
1239
+ * validation; this only controls whether a ready draft may be submitted
1240
+ * automatically by SDK controls.
1241
+ *
1242
+ * Multi-value collectors created with `many(...)` are always manual draft
1243
+ * interactions. They represent a selection set that should be committed by
1244
+ * explicit player intent, so `autoWhenReady` is intentionally not accepted.
1245
+ */
1246
+ commit?: InteractionCommitPolicyFor<Collectors>;
1247
+ /**
1248
+ * Addressed-player selector, used by prompt-kind interactions. When
1249
+ * present, the trusted bundle only emits this descriptor for players in
1250
+ * the returned set (or the single player, if a scalar is returned). Use
1251
+ * to thread e.g. `state.publicState.knowerPlayerId` through without
1252
+ * having to manage `activePlayers`. `undefined` / empty returns fall back
1253
+ * to the standard `activePlayers` gating used by action-kind interactions.
1254
+ */
1255
+ to?: BivariantCallback<InteractionToArgs<State, Manifest>, PlayerIdOfState<State> | ReadonlyArray<PlayerIdOfState<State>> | null | undefined>;
1256
+ /**
1257
+ * Explicit actor selector. Overrides the phase-level actor for this
1258
+ * interaction. Prefer this over `to` for new non-prompt interactions; `to`
1259
+ * remains the prompt/addressee shorthand.
1260
+ */
1261
+ actor?: ActorSelector<State, Manifest>;
1262
+ /**
1263
+ * Descriptor visibility policy. `all` keeps non-actors visible but disabled;
1264
+ * `actorsOnly` suppresses descriptors for seats that cannot act.
1265
+ */
1266
+ visibility?: "all" | "actorsOnly";
1267
+ errorCodes?: readonly ErrorCode[];
1268
+ cost?: BivariantCallback<InteractionValidateArgs<Collectors, State, Manifest, ErrorCode>, Readonly<Record<string, number>>>;
1269
+ rules?: readonly InteractionRule<NoInfer<Collectors>, State, Manifest, ErrorCode>[];
1270
+ reduce: BivariantCallback<InteractionReduceArgs<Collectors, State, Manifest, ErrorCode>, ReducerResult<State>>;
1271
+ };
1272
+ type CardActionSpec<Collectors extends Record<string, InputCollector> = Record<string, InputCollector>, State extends {
1273
+ table: RuntimeTableRecord;
1274
+ flow: {
1275
+ currentPhase: string;
1276
+ };
1277
+ } = {
1278
+ table: RuntimeTableRecord;
1279
+ flow: {
1280
+ currentPhase: string;
1281
+ };
1282
+ }, Manifest extends ManifestContract<TableOfState<State>> = ManifestContract<TableOfState<State>>, PlayFrom extends PlayerZoneIdOfManifest<Manifest> = PlayerZoneIdOfManifest<Manifest>, ErrorCode extends string = string> = {
1283
+ cardType: CardTypeOfState<State>;
1284
+ playFrom: PlayFrom;
1285
+ inputs?: Collectors;
1286
+ paramsSchema?: SchemaLike<Record<string, unknown>>;
1287
+ presentation?: InteractionPresentation;
1288
+ /** @internal Phase-local step gates are attached by `defineStepPhase`. */
1289
+ __steps?: readonly string[];
1290
+ /**
1291
+ * Draft commit policy. Card clicks still mutate the draft first;
1292
+ * `autoWhenReady` submits only once the full interaction draft validates.
1293
+ * Multi-value collectors created with `many(...)` are always manual draft
1294
+ * interactions and cannot opt into `autoWhenReady`.
1295
+ */
1296
+ commit?: InteractionCommitPolicyFor<Collectors>;
1297
+ actor?: ActorSelector<State, Manifest>;
1298
+ visibility?: "all" | "actorsOnly";
1299
+ errorCodes?: readonly ErrorCode[];
1300
+ cost?: BivariantCallback<InteractionValidateArgs<Collectors & {
1301
+ cardId: InputCollector<SchemaLike<CardIdOfState<State>>>;
1302
+ }, State, Manifest, ErrorCode>, Readonly<Record<string, number>>>;
1303
+ rules?: readonly InteractionRule<NoInfer<Collectors & {
1304
+ cardId: InputCollector<SchemaLike<CardIdOfState<State>>>;
1305
+ }>, State, Manifest, ErrorCode>[];
1306
+ reduce: BivariantCallback<InteractionReduceArgs<Collectors & {
1307
+ cardId: InputCollector<SchemaLike<CardIdOfState<State>>>;
1308
+ }, State, Manifest, ErrorCode>, ReducerResult<State>>;
1309
+ };
1310
+ type AnyInteractionRule = Omit<InteractionRule<any, any, any, any>, "available" | "validate"> & {
1311
+ available?: BivariantCallback<any, boolean>;
1312
+ validate?: BivariantCallback<any, InteractionRuleValidationResult<any>>;
1313
+ };
1314
+ type AnyCardActionSpec<State extends {
1315
+ table: RuntimeTableRecord;
1316
+ flow: {
1317
+ currentPhase: string;
1318
+ };
1319
+ }, Manifest extends ManifestContract<TableOfState<State>>> = Omit<CardActionSpec<any, State, Manifest, any, any>, "actor" | "cost" | "rules" | "reduce"> & {
1320
+ actor?: BivariantCallback<any, any>;
1321
+ cost?: BivariantCallback<any, Readonly<Record<string, number>>>;
1322
+ rules?: readonly AnyInteractionRule[];
1323
+ reduce: BivariantCallback<any, ReducerResult<any>>;
1324
+ };
1325
+ type CardActionMap<State extends {
1326
+ table: RuntimeTableRecord;
1327
+ flow: {
1328
+ currentPhase: string;
1329
+ };
1330
+ }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, AnyCardActionSpec<State, Manifest>>;
1331
+ /**
1332
+ * Type-safe erasure of {@link InteractionSpec} used by the runtime when it
1333
+ * stores heterogeneous interactions in a single map. The collectors generic is
1334
+ * intentionally erased with `any`: each authored interaction keeps a specific
1335
+ * params shape, but phase registries need to store all of them together.
1336
+ */
1337
+ type AnyInteractionSpec<State extends {
1338
+ table: RuntimeTableRecord;
1339
+ flow: {
1340
+ currentPhase: string;
1341
+ };
1342
+ }, Manifest extends ManifestContract<TableOfState<State>>> = Omit<InteractionSpec<any, State, Manifest, any>, "actor" | "cost" | "rules" | "reduce" | "to"> & {
1343
+ actor?: BivariantCallback<any, any>;
1344
+ cost?: BivariantCallback<any, Readonly<Record<string, number>>>;
1345
+ rules?: readonly AnyInteractionRule[];
1346
+ reduce: BivariantCallback<any, ReducerResult<any>>;
1347
+ to?: BivariantCallback<any, any>;
1348
+ };
1349
+ type InteractionMap<State extends {
1350
+ table: RuntimeTableRecord;
1351
+ flow: {
1352
+ currentPhase: string;
1353
+ };
1354
+ }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, AnyInteractionSpec<State, Manifest>>;
1355
+ type StageSpec<State extends {
1356
+ table: RuntimeTableRecord;
1357
+ flow: {
1358
+ currentPhase: string;
1359
+ };
1360
+ }, Manifest extends ManifestContract<TableOfState<State>>> = {
1361
+ when?: BivariantCallback<ActionContext<State, Manifest> & {
1362
+ state: State;
1363
+ }, boolean>;
1364
+ onEnter?: BivariantCallback<PhaseEnterArgs<State, Manifest>, ReducerResult<State> | void>;
1365
+ onExit?: BivariantCallback<PhaseEnterArgs<State, Manifest>, ReducerResult<State> | void>;
1366
+ allow: readonly string[];
1367
+ };
1368
+ type StageMap<State extends {
1369
+ table: RuntimeTableRecord;
1370
+ flow: {
1371
+ currentPhase: string;
1372
+ };
1373
+ }, Manifest extends ManifestContract<TableOfState<State>>> = Record<string, StageSpec<State, Manifest>>;
1374
+ type PhaseZoneList<Manifest extends ManifestContract<RuntimeTableRecord>> = readonly PlayerZoneIdOfManifest<Manifest>[];
1375
+
1376
+ type SimultaneousSubmission<Collectors extends Record<string, InputCollector>, State extends {
1377
+ table: RuntimeTableRecord;
1378
+ flow: {
1379
+ currentPhase: string;
1380
+ };
1381
+ }> = {
1382
+ playerId: PlayerIdOfState<State>;
1383
+ params: ParamsOf<Collectors>;
1384
+ };
1385
+ type SimultaneousResolveArgs<Collectors extends Record<string, InputCollector>, State extends {
1386
+ table: RuntimeTableRecord;
1387
+ flow: {
1388
+ currentPhase: string;
1389
+ };
1390
+ }, Manifest extends ManifestContract<TableOfState<State>>> = ActionContext<State, Manifest> & RuntimeHelpers<State> & MutationRuntimeHelpers & {
1391
+ state: State;
1392
+ submissions: Record<PlayerIdOfState<State>, SimultaneousSubmission<Collectors, State>>;
1393
+ submittedPlayerIds: PlayerIdOfState<State>[];
1394
+ waitingPlayerIds: PlayerIdOfState<State>[];
1395
+ };
1396
+ type SimultaneousSubmitSpec<Collectors extends Record<string, InputCollector> = Record<string, InputCollector>, State extends {
1397
+ table: RuntimeTableRecord;
1398
+ flow: {
1399
+ currentPhase: string;
1400
+ };
1401
+ } = {
1402
+ table: RuntimeTableRecord;
1403
+ flow: {
1404
+ currentPhase: string;
1405
+ };
1406
+ }, Manifest extends ManifestContract<TableOfState<State>> = ManifestContract<TableOfState<State>>> = Omit<InteractionSpec<Collectors, State, Manifest>, "reduce"> & {
1407
+ /**
1408
+ * Optional compatibility slot for callers that reuse `defineInteraction`.
1409
+ * The simultaneous phase barrier stores submissions and invokes the
1410
+ * phase-level `resolve`; this per-submission reducer is intentionally
1411
+ * ignored when present.
1412
+ */
1413
+ reduce?: InteractionSpec<Collectors, State, Manifest>["reduce"];
1414
+ };
1415
+
1416
+ type PhaseGuidance = {
1417
+ summary: string;
1418
+ objective?: string;
1419
+ };
1420
+ type PhaseDefinitionCommon<PhaseStateSchema extends SchemaLike<object>, State extends {
1421
+ table: RuntimeTableRecord;
1422
+ flow: {
1423
+ currentPhase: string;
1424
+ };
1425
+ phase: object;
1426
+ }, Manifest extends ManifestContract<TableOfState<State>>> = {
1427
+ name?: string;
1428
+ guidance?: PhaseGuidance;
1429
+ state: PhaseStateSchema;
1430
+ initialState?: (ctx: {
1431
+ manifest: Manifest;
1432
+ state: State;
1433
+ playerIds: PlayerIdOfState<State>[];
1434
+ setup: SetupSelectionOfManifest<Manifest> | null;
1435
+ }) => z.infer<PhaseStateSchema>;
1436
+ enter?: BivariantCallback<PhaseEnterArgs<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest>, ReducerResult<ScopedPhaseState<State, z.infer<PhaseStateSchema>>> | void>;
1437
+ };
1438
+ type AutoPhaseDefinition<PhaseStateSchema extends SchemaLike<object>, State extends {
1439
+ table: RuntimeTableRecord;
1440
+ flow: {
1441
+ currentPhase: string;
1442
+ };
1443
+ phase: object;
1444
+ }, Manifest extends ManifestContract<TableOfState<State>>> = PhaseDefinitionCommon<PhaseStateSchema, State, Manifest> & {
1445
+ kind: "auto";
1446
+ actor?: never;
1447
+ actors?: never;
1448
+ submit?: never;
1449
+ canResubmit?: never;
1450
+ resolve?: never;
1451
+ effects?: never;
1452
+ interactions?: never;
1453
+ stages?: never;
1454
+ zones?: never;
1455
+ cardActions?: never;
1456
+ };
1457
+ type PlayerPhaseDefinition<PhaseStateSchema extends SchemaLike<object>, State extends {
1458
+ table: RuntimeTableRecord;
1459
+ flow: {
1460
+ currentPhase: string;
1461
+ };
1462
+ phase: object;
1463
+ }, Manifest extends ManifestContract<TableOfState<State>>, Effects extends EffectMap<State, Manifest> = Record<string, never>, Interactions extends InteractionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Stages extends StageMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Zones extends PhaseZoneList<Manifest> = readonly [], CardActions extends CardActionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>> = PhaseDefinitionCommon<PhaseStateSchema, State, Manifest> & {
1464
+ kind: "player";
1465
+ /**
1466
+ * Default actor selector for interactions in this phase. When omitted the
1467
+ * runtime falls back to `flow.activePlayers`, preserving the existing turn
1468
+ * ownership model. Returning multiple players models simultaneous actors.
1469
+ */
1470
+ actor?: ActorSelector<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest>;
1471
+ actors?: never;
1472
+ submit?: never;
1473
+ canResubmit?: never;
1474
+ resolve?: never;
1475
+ effects?: Effects;
1476
+ interactions?: Interactions;
1477
+ stages?: Stages;
1478
+ zones?: Zones;
1479
+ cardActions?: CardActions;
1480
+ };
1481
+ type SimultaneousPlayerPhaseDefinition<PhaseStateSchema extends SchemaLike<object>, State extends {
1482
+ table: RuntimeTableRecord;
1483
+ flow: {
1484
+ currentPhase: string;
1485
+ };
1486
+ phase: object;
1487
+ }, Manifest extends ManifestContract<TableOfState<State>>, SubmitCollectors extends Record<string, InputCollector> = Record<string, InputCollector>, Effects extends EffectMap<State, Manifest> = Record<string, never>, Interactions extends InteractionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Stages extends StageMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Zones extends PhaseZoneList<Manifest> = readonly [], CardActions extends CardActionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>> = PhaseDefinitionCommon<PhaseStateSchema, State, Manifest> & {
1488
+ kind: "simultaneousPlayer";
1489
+ actor?: never;
1490
+ /**
1491
+ * Actor selector for `kind: "simultaneousPlayer"` phases. This is an alias
1492
+ * of `actor` with wording that matches simultaneous submission semantics.
1493
+ */
1494
+ actors: ActorSelector<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest>;
1495
+ /**
1496
+ * Canonical sealed submission interaction for simultaneous phases. It is
1497
+ * projected like a normal interaction, but the trusted runtime stores the
1498
+ * parsed params until every actor has submitted, then calls `resolve`.
1499
+ */
1500
+ submit: SimultaneousSubmitSpec<SubmitCollectors, ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest>;
1501
+ /**
1502
+ * When false or omitted, each actor can submit once per simultaneous
1503
+ * barrier. Set true to allow replacing the sealed submission before every
1504
+ * required actor has submitted.
1505
+ */
1506
+ canResubmit?: boolean;
1507
+ /**
1508
+ * Batch resolver invoked once all simultaneous actors have submitted. The
1509
+ * submitted params are passed together so game state mutates from one
1510
+ * deterministic base state instead of one player at a time.
1511
+ */
1512
+ resolve: BivariantCallback<SimultaneousResolveArgs<SubmitCollectors, ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest>, ReducerResult<ScopedPhaseState<State, z.infer<PhaseStateSchema>>>>;
1513
+ effects?: Effects;
1514
+ interactions?: Interactions;
1515
+ stages?: Stages;
1516
+ zones?: Zones;
1517
+ cardActions?: CardActions;
1518
+ };
1519
+ type PhaseDefinition<PhaseStateSchema extends SchemaLike<object>, State extends {
1520
+ table: RuntimeTableRecord;
1521
+ flow: {
1522
+ currentPhase: string;
1523
+ };
1524
+ phase: object;
1525
+ }, Manifest extends ManifestContract<TableOfState<State>>, SubmitCollectors extends Record<string, InputCollector> = Record<string, InputCollector>, Effects extends EffectMap<State, Manifest> = Record<string, never>, Interactions extends InteractionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Stages extends StageMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>, Zones extends PhaseZoneList<Manifest> = readonly [], CardActions extends CardActionMap<ScopedPhaseState<State, z.infer<PhaseStateSchema>>, Manifest> = Record<string, never>> = AutoPhaseDefinition<PhaseStateSchema, State, Manifest> | PlayerPhaseDefinition<PhaseStateSchema, State, Manifest, Effects, Interactions, Stages, Zones, CardActions> | SimultaneousPlayerPhaseDefinition<PhaseStateSchema, State, Manifest, SubmitCollectors, Effects, Interactions, Stages, Zones, CardActions>;
1526
+
1527
+ type ViewDefinition<State extends {
1528
+ table: RuntimeTableRecord;
1529
+ flow: {
1530
+ currentPhase: string;
1531
+ };
1532
+ }, Manifest extends ManifestContract<TableOfState<State>>, Projection = unknown> = {
1533
+ project: (args: ActionContext<State, Manifest> & RuntimeHelpers<State> & {
1534
+ state: State;
1535
+ playerId: PlayerIdOfState<State>;
1536
+ runtime: State extends {
1537
+ runtime: infer RuntimeStateValue;
1538
+ } ? RuntimeStateValue : never;
1539
+ }) => Projection;
1540
+ };
1541
+ /**
1542
+ * Session-scoped, once-per-init view. The `project` callback receives only
1543
+ * the authored manifest — the mutable-state helpers (`state`, `playerId`,
1544
+ * `runtime`, `fx`, `ops`, `accept`, `reject`, `q`) that `ViewDefinition.project`
1545
+ * exposes are structurally absent, so an author cannot accidentally project
1546
+ * per-tick state into the payload. The host calls this once per reducer
1547
+ * session, caches the result, and merges it back into every seat view on
1548
+ * the client. Moving static board topology here is what lets the adapter
1549
+ * skip the ~87% of `projectSeatsDynamic` wall time that used to re-serialize
1550
+ * manifest-sourced fields on every input.
1551
+ */
1552
+ type StaticViewDefinition<Manifest extends ManifestContract<RuntimeTableRecord>, Projection = unknown> = {
1553
+ project: (args: {
1554
+ manifest: Manifest;
1555
+ q: StaticViewQueries<Manifest>;
1556
+ }) => Projection;
1557
+ };
1558
+
1559
+ export { type InputDomainDependencyCase as $, type ActionContext as A, type BaseGameSessionOfContract as B, type CardActionMap as C, type ContinuationInput as D, type ContinuationInputForSource as E, type ContinuationKind as F, type ContinuationReduceArgs as G, type ContinuationSourceKind as H, type DefaultedClientParamKeysOfInteractionOfDefinition as I, type DerivedDefinition as J, type DerivedResolver as K, type EagerInputDomainDependencies as L, type EffectContinuationCallable as M, type EffectContinuationInput as N, type EffectContinuationResponse as O, type EffectDefinition as P, type EffectIdsOfDefinition as Q, type EffectMap as R, type EffectRegistryOfPhase as S, type EffectRollDieDefinition as T, type EffectShuffleDefinition as U, type EffectShufflePlayerZoneDefinition as V, type GameStateOf as W, type InitialStateCallbacks as X, type InputCollector as Y, type InputCollectorKind as Z, type InputCollectorMetaForKind as _, type ActorSelection as a, type SimultaneousSubmission as a$, type InputDomainDescriptor as a0, type InputDomainResolverDescriptor as a1, type InputKeysWithCollectorKindOfDefinition as a2, type InputSelectionDescriptor as a3, type InteractionAvailabilityArgs as a4, type InteractionCommitPolicy as a5, type InteractionIdOfDefinition as a6, type InteractionIdOfDefinitionPhase as a7, type InteractionKind as a8, type InteractionMap as a9, type PromptInputCollectorMeta as aA, type PromptInteractionKeyOfDefinition as aB, type RandomHelpers as aC, type ReducerEdit as aD, type ReducerGameContract as aE, type ReducerGameContractLike as aF, type ReducerGameDefinition as aG, type ReducerOps as aH, type ReducerSessionForConfig as aI, type ReducerStateBase as aJ, type ReducerStateForConfig as aK, type ReducerTransaction as aL, type ResolvedBoardTargetDomainDescriptor as aM, type ResolvedCardTargetDomainDescriptor as aN, type ResolvedGameSessionOf as aO, type ResolvedGameStateOf as aP, type ResourceMapDomainDescriptor as aQ, type ResumableEffectKind as aR, type RngInputCollectorMeta as aS, type RollDieContinuationResponse as aT, type RotatePlayerZoneArgs as aU, type RuntimeHelpers as aV, type ScopedPhaseState as aW, type ShufflePlayerZoneContinuationResponse as aX, type ShuffleSharedZoneContinuationResponse as aY, type SimultaneousPlayerPhaseDefinition as aZ, type SimultaneousResolveArgs as a_, type InteractionReduceArgs as aa, type InteractionReduceInput as ab, type InteractionRule as ac, type InteractionRuleValidationResult as ad, type InteractionSpec as ae, type InteractionSpecByNameOfDefinitionPhase as af, type InteractionToArgs as ag, type InteractionValidateArgs as ah, type LazyBoardTargetDomainDescriptor as ai, type LazyCardTargetDomainDescriptor as aj, type LazyInputDomainDependencies as ak, type MutationRuntimeHelpers as al, type Op as am, type ParamsOf as an, type ParamsOfInteractionOfDefinition as ao, type PhaseDefinition as ap, type PhaseDefinitionByName as aq, type PhaseEnterArgs as ar, type PhaseEnterContext as as, type PhaseMapOf as at, type PhaseNamesOfDefinition as au, type PhaseStateMapOfDefinitions as av, type PhaseStateOfDefinitions as aw, type PhaseZoneList as ax, type PlayableInteractionsOfZoneOfDefinition as ay, type PlayerPhaseDefinition as az, type ActorSelector as b, type SimultaneousSubmitSpec as b0, type StageMap as b1, type StageNamesOfDefinitionPhase as b2, type StageSpec as b3, type StaticViewDefinition as b4, type StaticViewQueries as b5, type TargetKind as b6, type ValidationIssue as b7, type ViewDefinition as b8, type ViewDefinitionByName as b9, type ViewMapOf as ba, type ViewNamesOfDefinition as bb, type ViewOfDefinition as bc, type ViewsOfDefinition as bd, type ZoneIdsOfDefinition as be, createDerivedResolver as bf, createReducerEdit as bg, createReducerOps as bh, createReducerTransaction as bi, defineDerived as bj, pipe as bk, type ActorSelectorArgs as c, type AnyCardActionSpec as d, type AnyContinuationCallable as e, type AnyInteractionSpec as f, type AnyPhaseDefinitionForContract as g, type AnyReducerGameDefinition as h, type AutoPhaseDefinition as i, type BaseGameStateOfContract as j, type BoardInputCollectorKind as k, type BoardInputCollectorMeta as l, type BoardInteractionKeyOfDefinition as m, type BoardTargetDomainDescriptor as n, type BoundedNumberDomainDescriptor as o, type CardActionSpec as p, type CardInputCollectorMeta as q, type CardInputZoneIdsOfDefinition as r, type CardInteractionKeyOfDefinition as s, type CardTargetDomainDescriptor as t, type ChoiceDomainDescriptor as u, type ChoiceListDomainDescriptor as v, type ClientParamsOf as w, type ClientParamsOfInteractionOfDefinition as x, type CollectorState as y, type ContinuationCallable as z };