@dreamboard-games/sdk 0.5.0-alpha.34 → 0.5.0-alpha.36

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.
@@ -11,7 +11,7 @@ import {
11
11
  boardSpaceHostId,
12
12
  isCardReferenceNamespace,
13
13
  parseBoardSpaceHostId
14
- } from "./chunk-BSS4ORU3.js";
14
+ } from "./chunk-G4MY5YMA.js";
15
15
  import {
16
16
  AuthoredTileDisclosureSchema,
17
17
  BoardProjectionSchema,
@@ -23,6 +23,7 @@ import {
23
23
  SeatTileRefSchema,
24
24
  TileDisclosureSchema,
25
25
  TilePlacementSchema,
26
+ canonicalizeInputSelection,
26
27
  canonicalizePluginRuntimeJson,
27
28
  createBoardTopologyCache,
28
29
  createHexTopologyCache,
@@ -39,7 +40,7 @@ import {
39
40
  requireLookup,
40
41
  tileSpaceId,
41
42
  zonePositions
42
- } from "./chunk-CZRPUWCT.js";
43
+ } from "./chunk-7GX27XU6.js";
43
44
 
44
45
  // src/reducer/model/error-codes.ts
45
46
  var FrameworkErrorCodes = {
@@ -180,6 +181,216 @@ function normalizeCommandParams(schema, input) {
180
181
  return schema.parse(normalizeSchemaInput(schema, input));
181
182
  }
182
183
 
184
+ // src/reducer/inputs/combinations.ts
185
+ function* enumerateCombinations(values, count) {
186
+ if (!Number.isSafeInteger(count) || count < 0) {
187
+ throw new RangeError("Combination count must be a nonnegative integer.");
188
+ }
189
+ yield* combinationsFrom(values, count, 0, []);
190
+ }
191
+ function* combinationsFrom(values, remaining, start, current) {
192
+ if (remaining === 0) {
193
+ yield [...current];
194
+ return;
195
+ }
196
+ for (let index = start; index <= values.length - remaining; index += 1) {
197
+ yield* combinationsFrom(values, remaining - 1, index + 1, [
198
+ ...current,
199
+ values[index]
200
+ ]);
201
+ }
202
+ }
203
+
204
+ // src/reducer/bundle/define-bots.ts
205
+ var registeredStrategies = /* @__PURE__ */ Symbol(
206
+ "registeredStrategies"
207
+ );
208
+ var diagnosticMessages = {
209
+ unsupported_interaction: "Unsupported interaction for bot scoring.",
210
+ missing_handler: "Missing bot score handler.",
211
+ invalid_binding: "Card input name or resolver is incompatible with bot scoring.",
212
+ resolver_failed: "Bot card resolver failed. Every eligible card must resolve exactly once.",
213
+ scorer_failed: "Bot scorer failed.",
214
+ invalid_score: "Bot score must be finite.",
215
+ candidate_generator_failed: "Bot candidate generator failed.",
216
+ invalid_candidate: "Bot proposal must contain the required number of distinct eligible cards."
217
+ };
218
+ var BotStrategyError = class extends Error {
219
+ constructor(category, interactionKey) {
220
+ super(diagnosticMessages[category]);
221
+ this.category = category;
222
+ this.interactionKey = interactionKey;
223
+ }
224
+ category;
225
+ interactionKey;
226
+ name = "BotStrategyError";
227
+ };
228
+ function resolvedCards(resolve, view, ids, interactionKey) {
229
+ const byId = /* @__PURE__ */ new Map();
230
+ const wanted = new Set(ids);
231
+ try {
232
+ for (const card of resolve(view)) {
233
+ const { id: id2 } = card;
234
+ if (!wanted.has(id2)) continue;
235
+ if (byId.has(id2)) {
236
+ throw new BotStrategyError("resolver_failed", interactionKey);
237
+ }
238
+ byId.set(id2, card);
239
+ }
240
+ } catch {
241
+ throw new BotStrategyError("resolver_failed", interactionKey);
242
+ }
243
+ return Array.from(wanted, (id2) => {
244
+ const card = byId.get(id2);
245
+ if (!card) throw new BotStrategyError("resolver_failed", interactionKey);
246
+ return { id: id2, card };
247
+ });
248
+ }
249
+ function* generatedProposals(handler, context, interactionKey) {
250
+ try {
251
+ yield* handler.candidates(context);
252
+ } catch {
253
+ throw new BotStrategyError("candidate_generator_failed", interactionKey);
254
+ }
255
+ }
256
+ function* proposedSelections(handler, eligible, count, alias, view, interactionKey) {
257
+ const context = {
258
+ view,
259
+ eligible: { [alias]: eligible.map(({ card }) => card) },
260
+ selection: { [alias]: { count } }
261
+ };
262
+ for (const proposal of generatedProposals(handler, context, interactionKey)) {
263
+ let ordered;
264
+ try {
265
+ const cards = proposal?.[alias];
266
+ if (!Array.isArray(cards) || cards.length !== count) {
267
+ throw new BotStrategyError("invalid_candidate", interactionKey);
268
+ }
269
+ const proposedIds = new Set(cards.map(({ id: id2 }) => id2));
270
+ ordered = eligible.filter(({ id: id2 }) => proposedIds.has(id2));
271
+ } catch {
272
+ throw new BotStrategyError("invalid_candidate", interactionKey);
273
+ }
274
+ if (ordered.length !== count) {
275
+ throw new BotStrategyError("invalid_candidate", interactionKey);
276
+ }
277
+ yield ordered;
278
+ }
279
+ }
280
+ function* candidates(offer, view, resolve, handler) {
281
+ if (offer.step || offer.inputs.length > 1) {
282
+ throw new BotStrategyError("unsupported_interaction", offer.interactionKey);
283
+ }
284
+ const [input] = offer.inputs;
285
+ const generate = typeof handler !== "function";
286
+ if (generate && input?.domain.selection?.mode !== "many") {
287
+ throw new BotStrategyError("unsupported_interaction", offer.interactionKey);
288
+ }
289
+ if (!input) {
290
+ yield { args: {}, params: {} };
291
+ return;
292
+ }
293
+ if (input.kind !== "card" || input.domain.type !== "cardTarget" || !resolve) {
294
+ throw new BotStrategyError("invalid_binding", offer.interactionKey);
295
+ }
296
+ const { key, domain } = input;
297
+ const selection = domain.selection;
298
+ const multiple = selection?.mode === "many";
299
+ const suffix = multiple ? "Ids" : "Id";
300
+ const name = key.endsWith(suffix) ? key.slice(0, -suffix.length) : "";
301
+ const alias = multiple ? name + "s" : name;
302
+ if (!name || alias === "view") {
303
+ throw new BotStrategyError("invalid_binding", offer.interactionKey);
304
+ }
305
+ const eligible = resolvedCards(
306
+ resolve,
307
+ view,
308
+ domain.eligibleTargets,
309
+ offer.interactionKey
310
+ );
311
+ if (!multiple) {
312
+ for (const { card, id: id2 } of eligible) {
313
+ yield { args: { [alias]: card }, params: { [key]: id2 } };
314
+ }
315
+ return;
316
+ }
317
+ if (!selection.distinct || selection.min !== selection.max) {
318
+ throw new BotStrategyError("unsupported_interaction", offer.interactionKey);
319
+ }
320
+ const selections = generate ? proposedSelections(
321
+ handler,
322
+ eligible,
323
+ selection.min,
324
+ alias,
325
+ view,
326
+ offer.interactionKey
327
+ ) : enumerateCombinations(eligible, selection.min);
328
+ for (const cards of selections) {
329
+ yield {
330
+ args: { [alias]: cards.map(({ card }) => card) },
331
+ params: { [key]: cards.map(({ id: id2 }) => id2) }
332
+ };
333
+ }
334
+ }
335
+ function scoredStrategy(strategy, resolve) {
336
+ const score = new Map(
337
+ Object.entries(
338
+ strategy.score
339
+ )
340
+ );
341
+ return {
342
+ id: strategy.id,
343
+ name: strategy.name,
344
+ description: strategy.description,
345
+ decide(frame) {
346
+ const { view } = frame;
347
+ if (view == null) return null;
348
+ let bestScore = -Infinity;
349
+ let decision = null;
350
+ for (const offer of frame.availableInteractions) {
351
+ if (offer.availability.status !== "available") continue;
352
+ const handler = score.get(offer.interactionKey);
353
+ if (handler === "skip") continue;
354
+ if (!handler) {
355
+ throw new BotStrategyError("missing_handler", offer.interactionKey);
356
+ }
357
+ for (const { args, params } of candidates(
358
+ offer,
359
+ view,
360
+ resolve,
361
+ handler
362
+ )) {
363
+ let value;
364
+ try {
365
+ const context = { ...args, view };
366
+ value = typeof handler === "function" ? handler(context) : handler.score(context);
367
+ } catch {
368
+ throw new BotStrategyError("scorer_failed", offer.interactionKey);
369
+ }
370
+ if (!Number.isFinite(value)) {
371
+ throw new BotStrategyError("invalid_score", offer.interactionKey);
372
+ }
373
+ if (value > bestScore) {
374
+ bestScore = value;
375
+ decision = {
376
+ interactionId: offer.interactionId,
377
+ params
378
+ };
379
+ }
380
+ }
381
+ }
382
+ return decision;
383
+ }
384
+ };
385
+ }
386
+ function defineBots(_game, config) {
387
+ return {
388
+ [registeredStrategies]: config.strategies.map(
389
+ (strategy) => scoredStrategy(strategy, config.resolve.card)
390
+ )
391
+ };
392
+ }
393
+
183
394
  // src/shared/worker-contract.ts
184
395
  import * as z3 from "zod";
185
396
  var REDUCER_CONTRACT_VERSION = "0.11.0";
@@ -1535,8 +1746,14 @@ function createStateQueries(state, definitions) {
1535
1746
  }
1536
1747
 
1537
1748
  // src/reducer/bundle/bot-strategies.ts
1538
- function createBotCapability(strategies) {
1539
- if (!strategies?.length) return {};
1749
+ function createBotCapability(registration) {
1750
+ if (!registration) return {};
1751
+ const strategies = registration[registeredStrategies];
1752
+ if (!strategies)
1753
+ throw new TypeError(
1754
+ "Register bot strategies with defineBots(game, config)."
1755
+ );
1756
+ if (!strategies.length) return {};
1540
1757
  const botStrategies = BotStrategyCatalogSchema.parse(
1541
1758
  strategies.map(({ id: id2, name, description }) => ({ id: id2, name, description }))
1542
1759
  );
@@ -3239,6 +3456,7 @@ function createTrustedRuntimeScope(definition, options = {}) {
3239
3456
  }
3240
3457
  return {
3241
3458
  definition,
3459
+ errorMessages: new Map(Object.entries(definition.contract.errors ?? {})),
3242
3460
  manifest,
3243
3461
  diagnostics: createReducerDiagnosticsEmitter(options.diagnostics),
3244
3462
  registry,
@@ -3304,11 +3522,22 @@ function makeValidationError(errorCode, message) {
3304
3522
  }
3305
3523
 
3306
3524
  // src/reducer/bundle/trusted/collector-params.ts
3307
- function parseInteractionParams(interaction, rawParams, options = {}) {
3525
+ function parseInteractionParams(interaction, rawParams, options) {
3308
3526
  const collectors = interactionInputsOf(interaction);
3309
3527
  const record3 = rawParams ?? {};
3310
3528
  if (interaction.paramsSchema) {
3311
- const result = interaction.paramsSchema.safeParse(record3);
3529
+ const normalized = { ...record3 };
3530
+ let q;
3531
+ for (const [key, collector] of Object.entries(collectors)) {
3532
+ const selection = collector.selection;
3533
+ if (selection?.mode !== "many") continue;
3534
+ const value = normalized[key];
3535
+ if (!Array.isArray(value)) continue;
3536
+ q ??= createStateQueries(options.state, options.definitions);
3537
+ const domain = collector.domain?.(options.state, options.playerId, q);
3538
+ normalized[key] = canonicalizeInputSelection(value, selection, domain);
3539
+ }
3540
+ const result = interaction.paramsSchema.safeParse(normalized);
3312
3541
  if (!result.success) {
3313
3542
  return {
3314
3543
  ok: false,
@@ -3365,14 +3594,25 @@ function validateCollectorTargets(interaction, domainState, playerId, params, de
3365
3594
  let queriesLazy = null;
3366
3595
  const queries = () => queriesLazy ??= createStateQueries(domainState, definitions);
3367
3596
  for (const [key, collector] of Object.entries(collectors)) {
3597
+ const value = params[key];
3598
+ const q = queries();
3599
+ const domain = collector.domain?.(domainState, playerId, q);
3368
3600
  const issue = validateCollectorValue(
3369
3601
  collector,
3370
3602
  domainState,
3371
3603
  playerId,
3372
- queries(),
3373
- params[key]
3604
+ q,
3605
+ value,
3606
+ domain
3374
3607
  );
3375
3608
  if (issue) return makeValidationError(issue.errorCode, issue.message);
3609
+ if (collector.selection?.mode === "many") {
3610
+ params[key] = canonicalizeInputSelection(
3611
+ value,
3612
+ collector.selection,
3613
+ domain
3614
+ );
3615
+ }
3376
3616
  }
3377
3617
  return { valid: true };
3378
3618
  }
@@ -3610,9 +3850,15 @@ function evaluateStepPrefix(steps, state, playerId, values, definitions) {
3610
3850
  issue = `Value for step '${entry.key}' is no longer eligible.`;
3611
3851
  break;
3612
3852
  }
3613
- selected[entry.key] = parsed.data;
3853
+ selected[entry.key] = canonicalizeInputSelection(
3854
+ parsed.data,
3855
+ collector.selection,
3856
+ domain
3857
+ );
3614
3858
  collectors[entry.key] = collector;
3615
- validValues.push(value);
3859
+ validValues.push(
3860
+ canonicalizeInputSelection(value, collector.selection, domain)
3861
+ );
3616
3862
  current = void 0;
3617
3863
  }
3618
3864
  if (values.length > steps.entries.length)
@@ -3786,16 +4032,19 @@ function valueSourceForCollector(context, inputKey, collector) {
3786
4032
  );
3787
4033
  const base = baseValuesForDomain(domain, collector, context);
3788
4034
  const selection = collector.selection ?? domain.selection;
3789
- const selected = applySelection(base, selection);
4035
+ const selected = applySelection(base, selection, domain);
3790
4036
  const resolved = collector.schema.safeParse(void 0).success ? withAbsentCollectorValue(selected) : selected;
3791
4037
  if (!hasFixedValue) return resolved;
3792
4038
  if (selection?.mode === "many" && Array.isArray(fixedValue) && base.complete) {
3793
4039
  const keys = fixedValue.map(canonicalJson);
3794
4040
  const valid = collector.schema.safeParse(fixedValue).success && fixedValue.length >= selection.min && (selection.max === void 0 || fixedValue.length <= selection.max) && (!selection.distinct || new Set(keys).size === keys.length) && fixedValue.every((value) => sourceContainsValue(base, value));
3795
- return { complete: true, values: () => valid ? [fixedValue] : [] };
4041
+ return {
4042
+ complete: true,
4043
+ values: () => valid ? [canonicalizeInputSelection(fixedValue, selection, domain)] : []
4044
+ };
3796
4045
  }
3797
4046
  if (!resolved.complete) {
3798
- return fixedCollectorValueSource(context, collector, fixedValue);
4047
+ return fixedCollectorValueSource(context, collector, fixedValue, domain);
3799
4048
  }
3800
4049
  if (selection?.mode === "many" && !Array.isArray(fixedValue)) {
3801
4050
  const eligible = sourceContainsValue(base, fixedValue);
@@ -3822,7 +4071,7 @@ function sourceContainsValue(source, value) {
3822
4071
  }
3823
4072
  return false;
3824
4073
  }
3825
- function fixedCollectorValueSource(context, collector, fixedValue) {
4074
+ function fixedCollectorValueSource(context, collector, fixedValue, domain) {
3826
4075
  const schemaResult = collector.schema.safeParse(fixedValue);
3827
4076
  const targetValues = collector.selection?.mode === "many" && Array.isArray(fixedValue) ? fixedValue : [fixedValue];
3828
4077
  const targetValid = targetValues.every(
@@ -3836,7 +4085,13 @@ function fixedCollectorValueSource(context, collector, fixedValue) {
3836
4085
  return {
3837
4086
  complete: true,
3838
4087
  values: function* () {
3839
- if (schemaResult.success && targetValid) yield fixedValue;
4088
+ if (schemaResult.success && targetValid) {
4089
+ yield canonicalizeInputSelection(
4090
+ fixedValue,
4091
+ collector.selection,
4092
+ domain
4093
+ );
4094
+ }
3840
4095
  }
3841
4096
  };
3842
4097
  }
@@ -3981,12 +4236,12 @@ function choiceListValueSource(domain) {
3981
4236
  complete: true,
3982
4237
  values: function* () {
3983
4238
  for (let count = min; count <= cappedMax; count += 1) {
3984
- yield* enumerateCombinations(choices, count, 0, []);
4239
+ yield* enumerateCombinations(choices, count);
3985
4240
  }
3986
4241
  }
3987
4242
  };
3988
4243
  }
3989
- function applySelection(source, selection) {
4244
+ function applySelection(source, selection, domain) {
3990
4245
  if (selection?.mode !== "many") return source;
3991
4246
  if (!source.complete) return incompleteValueSource();
3992
4247
  const min = selection.min;
@@ -3995,44 +4250,29 @@ function applySelection(source, selection) {
3995
4250
  if (max !== void 0 && (!Number.isSafeInteger(max) || max < min)) {
3996
4251
  return incompleteValueSource();
3997
4252
  }
3998
- if (max === void 0 && !selection.distinct) {
3999
- return {
4000
- complete: false,
4001
- values: function* () {
4002
- yield* enumerateSequencesFromSource(source.values, min, []);
4003
- }
4004
- };
4005
- }
4253
+ const distinct = selection.distinct === true;
4006
4254
  return {
4007
- complete: true,
4255
+ complete: max !== void 0 || distinct,
4008
4256
  values: function* () {
4009
- if (selection.distinct && max === void 0) {
4010
- for (let count = min; ; count += 1) {
4011
- let yielded = false;
4012
- for (const combination of enumerateCombinationsFromSource(
4013
- source.values,
4014
- count,
4015
- 0,
4016
- []
4017
- )) {
4018
- yielded = true;
4019
- yield combination;
4020
- }
4021
- if (!yielded) return;
4022
- }
4023
- }
4024
- const finiteMax = max ?? min;
4025
- for (let count = min; count <= finiteMax; count += 1) {
4026
- if (selection.distinct) {
4027
- yield* enumerateCombinationsFromSource(source.values, count, 0, []);
4028
- } else {
4029
- yield* enumerateSequencesFromSource(source.values, count, []);
4257
+ const upper = max ?? (distinct ? Infinity : min);
4258
+ for (let count = min; count <= upper; count += 1) {
4259
+ let yielded = false;
4260
+ for (const combination of enumerateCombinationsFromSource(
4261
+ source.values,
4262
+ count,
4263
+ distinct,
4264
+ 0,
4265
+ []
4266
+ )) {
4267
+ yielded = true;
4268
+ yield canonicalizeInputSelection(combination, selection, domain);
4030
4269
  }
4270
+ if (!yielded) return;
4031
4271
  }
4032
4272
  }
4033
4273
  };
4034
4274
  }
4035
- function* enumerateCombinationsFromSource(values, count, start, current) {
4275
+ function* enumerateCombinationsFromSource(values, count, distinct, start, current) {
4036
4276
  if (current.length === count) {
4037
4277
  yield [...current];
4038
4278
  return;
@@ -4040,35 +4280,17 @@ function* enumerateCombinationsFromSource(values, count, start, current) {
4040
4280
  let index = 0;
4041
4281
  for (const value of values()) {
4042
4282
  if (index >= start) {
4043
- yield* enumerateCombinationsFromSource(values, count, index + 1, [
4044
- ...current,
4045
- value
4046
- ]);
4283
+ yield* enumerateCombinationsFromSource(
4284
+ values,
4285
+ count,
4286
+ distinct,
4287
+ distinct ? index + 1 : index,
4288
+ [...current, value]
4289
+ );
4047
4290
  }
4048
4291
  index += 1;
4049
4292
  }
4050
4293
  }
4051
- function* enumerateSequencesFromSource(values, count, current) {
4052
- if (current.length === count) {
4053
- yield [...current];
4054
- return;
4055
- }
4056
- for (const value of values()) {
4057
- yield* enumerateSequencesFromSource(values, count, [...current, value]);
4058
- }
4059
- }
4060
- function* enumerateCombinations(values, count, start, current) {
4061
- if (current.length === count) {
4062
- yield [...current];
4063
- return;
4064
- }
4065
- for (let index = start; index < values.length; index += 1) {
4066
- yield* enumerateCombinations(values, count, index + 1, [
4067
- ...current,
4068
- values[index]
4069
- ]);
4070
- }
4071
- }
4072
4294
  function canonicalJson(value) {
4073
4295
  return JSON.stringify(canonicalizeJson(value));
4074
4296
  }
@@ -4376,15 +4598,11 @@ function explanationAvailability(decision) {
4376
4598
  }
4377
4599
  }
4378
4600
  function createInteractionDecisionResolver(scope, authorization, options = {}) {
4379
- const contractErrors = scope.definition.contract.errors ?? {};
4380
- function defaultMessageForCode(code) {
4381
- return contractErrors[code];
4382
- }
4383
4601
  function issueFromRule(rule, message) {
4384
4602
  return {
4385
4603
  ruleId: rule.ruleId,
4386
4604
  errorCode: rule.errorCode,
4387
- message: message ?? rule.message ?? defaultMessageForCode(rule.errorCode)
4605
+ message: message ?? rule.message ?? scope.errorMessages.get(rule.errorCode)
4388
4606
  };
4389
4607
  }
4390
4608
  function issueFromRuleValidationResult(rule, result) {
@@ -4394,7 +4612,7 @@ function createInteractionDecisionResolver(scope, authorization, options = {}) {
4394
4612
  return {
4395
4613
  ruleId: rule.ruleId,
4396
4614
  errorCode: result.errorCode,
4397
- message: result.message ?? rule.message ?? defaultMessageForCode(result.errorCode)
4615
+ message: result.message ?? rule.message ?? scope.errorMessages.get(result.errorCode)
4398
4616
  };
4399
4617
  }
4400
4618
  return void 0;
@@ -4601,7 +4819,10 @@ function createInteractionDecisionResolver(scope, authorization, options = {}) {
4601
4819
  ok: true,
4602
4820
  params: finalStepSchema?.success ? finalStepSchema.data : submittedPrefix.selected
4603
4821
  } : parseForSubmit ? parseInteractionParams(interaction, params, {
4604
- skipRng: true
4822
+ skipRng: true,
4823
+ state: projection?.domainState ?? scope.toDomainState(state),
4824
+ playerId,
4825
+ definitions: scope.manifest
4605
4826
  }) : {
4606
4827
  ok: true,
4607
4828
  params: prepareInteractionProjectionParams(interaction, params)
@@ -4886,7 +5107,7 @@ function createInteractionDecisionResolver(scope, authorization, options = {}) {
4886
5107
  ruleId: rule.id,
4887
5108
  outcome: "notEvaluated",
4888
5109
  errorCode: rule.errorCode,
4889
- message: rule.message ?? defaultMessageForCode(rule.errorCode)
5110
+ message: rule.message ?? scope.errorMessages.get(rule.errorCode)
4890
5111
  });
4891
5112
  continue;
4892
5113
  }
@@ -5622,7 +5843,7 @@ function createSeatDisclosure(table, definitions, playerId, referenceBasis) {
5622
5843
  if (!boardAccess(boardId).inventory) continue;
5623
5844
  const instance = table.boards[boardId];
5624
5845
  const definition = definitions.boardDefinitions[instance.baseId];
5625
- const candidates = Object.keys(table.tiles).flatMap((tileId) => {
5846
+ const candidates2 = Object.keys(table.tiles).flatMap((tileId) => {
5626
5847
  const location = table.componentLocations[tileId];
5627
5848
  if (location?.type !== "OnBoard" || location.boardId !== boardId)
5628
5849
  return [];
@@ -5639,7 +5860,7 @@ function createSeatDisclosure(table, definitions, playerId, referenceBasis) {
5639
5860
  }
5640
5861
  ] : [];
5641
5862
  }).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
5642
- const placed = candidates.flatMap(({ tileId, location }, index) => {
5863
+ const placed = candidates2.flatMap(({ tileId, location }, index) => {
5643
5864
  const tile = issueTile(tileId, { boardId }, index);
5644
5865
  if (!tile) return [];
5645
5866
  const placement = location.layout === "hex" ? {
@@ -5655,7 +5876,7 @@ function createSeatDisclosure(table, definitions, playerId, referenceBasis) {
5655
5876
  };
5656
5877
  return [{ ...tile, placement }];
5657
5878
  });
5658
- const visibleIds = candidates.filter(({ tileId }) => disclosure(tileId) === "visible").map(({ tileId }) => tileId);
5879
+ const visibleIds = candidates2.filter(({ tileId }) => disclosure(tileId) === "visible").map(({ tileId }) => tileId);
5659
5880
  const visibleSpaces = new Set(
5660
5881
  definition.layout === "generic" ? Object.keys(definition.spaces) : visibleIds.flatMap(
5661
5882
  (tileId) => definitions.tileDefinitions[table.tiles[tileId].tileTypeId].cells.map((cell) => tileSpaceId(tileId, cell.id))
@@ -6572,18 +6793,26 @@ function createProjectionBuilder(scope, interactions) {
6572
6793
  function createDescriptorRegistry(timing) {
6573
6794
  const byRef = {};
6574
6795
  const byHash = /* @__PURE__ */ new Map();
6796
+ const byDescriptor = /* @__PURE__ */ new Map();
6575
6797
  return {
6576
6798
  add(descriptor, actorSeat) {
6577
6799
  return measureProjectionTiming(timing, "descriptorHashMs", () => {
6800
+ const key = `${actorSeat}:${encodeCanonicalPluginRuntimeJson(descriptor)}`;
6801
+ const cached = byDescriptor.get(key);
6802
+ if (cached) return cached;
6578
6803
  const enriched = descriptorWithBrowserReplayDigests(
6579
6804
  descriptor,
6580
6805
  actorSeat
6581
6806
  );
6582
6807
  const fingerprint = encodeCanonicalPluginRuntimeJson(enriched);
6583
6808
  const existing = byHash.get(fingerprint);
6584
- if (existing) return existing;
6809
+ if (existing) {
6810
+ byDescriptor.set(key, existing);
6811
+ return existing;
6812
+ }
6585
6813
  const base = typeof enriched.interactionId === "string" && enriched.interactionId.length > 0 ? enriched.interactionId : "interaction";
6586
6814
  const ref = `${base}:${fnv1a64(fingerprint)}`;
6815
+ byDescriptor.set(key, ref);
6587
6816
  byHash.set(fingerprint, ref);
6588
6817
  byRef[ref] = enriched;
6589
6818
  return ref;
@@ -7185,6 +7414,7 @@ function createReducerBundle(definition, options = {}) {
7185
7414
  });
7186
7415
  const result = executor.dispatch(combinedState, input, referenceBasis);
7187
7416
  if (result.type === "reject") {
7417
+ result.message ??= scope.errorMessages.get(result.errorCode);
7188
7418
  scope.diagnostics.event({
7189
7419
  type: "submitRejected",
7190
7420
  submissionId,
@@ -7249,6 +7479,7 @@ export {
7249
7479
  resolveZoneAccess,
7250
7480
  assertContainmentAcyclic,
7251
7481
  assertZoneConsistency,
7482
+ defineBots,
7252
7483
  REDUCER_CONTRACT_VERSION,
7253
7484
  assertReducerBundleContract,
7254
7485
  ZoneVisibilitySchema,
@@ -7270,4 +7501,4 @@ export {
7270
7501
  createProjectionBuilder,
7271
7502
  createReducerBundle
7272
7503
  };
7273
- //# sourceMappingURL=chunk-KYQQIFXN.js.map
7504
+ //# sourceMappingURL=chunk-75QTSYRZ.js.map