@seriousgaming/sdk-tools 1.1.0 → 1.3.0

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 (40) hide show
  1. package/dist/cli.js +565 -309
  2. package/dist/client.js +608 -352
  3. package/dist/core/participant-registry.d.ts +6 -0
  4. package/dist/core/session-roster.d.ts +4 -1
  5. package/dist/dev/brands.d.ts +20 -3
  6. package/dist/dev/console/assets/{index-qxHcu9fJ.js → index-DEV8N0na.js} +47 -47
  7. package/dist/dev/console/index.html +1 -1
  8. package/dist/dev/view/batch.d.ts +17 -9
  9. package/dist/dev/view/view.d.ts +2 -1
  10. package/dist/docs/api/index.md +1 -1
  11. package/dist/docs/api/sdk-commands.md +4 -0
  12. package/dist/docs/api/sdk-e2e.md +4 -0
  13. package/dist/docs/api/sdk-tools-client.md +4 -0
  14. package/dist/docs/api/sdk-ui-testing.md +2 -1
  15. package/dist/docs/api/sdk-ui.md +54 -3
  16. package/dist/docs/api/sdk.md +3 -1
  17. package/dist/docs/changelog.md +41 -0
  18. package/dist/docs/guides/guide.md +35 -4
  19. package/dist/docs/guides/presentation.md +23 -9
  20. package/dist/docs/guides/production-constraints.md +1 -1
  21. package/dist/docs/guides/session.md +50 -9
  22. package/dist/docs/guides/testing.md +9 -0
  23. package/dist/docs/guides/theming-and-branding.md +18 -4
  24. package/dist/docs/guides/ui.md +33 -0
  25. package/dist/docs/guides/upgrading.md +19 -0
  26. package/dist/docs/guides/waiting-room.md +2 -0
  27. package/dist/docs/recipes/create-guide.md +2 -2
  28. package/dist/docs/recipes/make-a-guide-follow-the-scenario.md +9 -9
  29. package/dist/guide/settings.d.ts +7 -0
  30. package/dist/guide/video-registry.d.ts +33 -1
  31. package/dist/host/index.d.ts +4 -2
  32. package/dist/host/protocol.d.ts +27 -2
  33. package/dist/host.js +131 -0
  34. package/dist/runtime/manifest-version.d.ts +1 -1
  35. package/dist/runtime.js +4 -2
  36. package/dist/templates/package/CLAUDE.md.template +1 -1
  37. package/dist/templates/package/claude/rules/workflow-create-guide.md +8 -2
  38. package/dist/validation/facilitator-guide-validator.d.ts +5 -1
  39. package/dist/validation/schema-validation.d.ts +12 -4
  40. package/package.json +3 -3
package/dist/client.js CHANGED
@@ -259,6 +259,7 @@ var COMMAND_FIELDS = {
259
259
  removeTeam: { teamIndex: "number" },
260
260
  renameTeam: { teamId: "string", name: "string" },
261
261
  renameOwnTeam: { name: "string", "participantId?": "string", "teamId?": "string" },
262
+ renameSelf: { name: "string", "participantId?": "string", "teamId?": "string" },
262
263
  addParticipant: { teamId: "string", "name?": "string" },
263
264
  renameParticipant: { participantId: "string", name: "string" },
264
265
  moveParticipant: { participantId: "string", teamId: "string" },
@@ -2700,7 +2701,9 @@ function gameOverrideRefusal(overrides) {
2700
2701
  // cli/runtime/manifest-version.ts
2701
2702
  var SUPPORTED_FEATURES = [
2702
2703
  // A validator's `Scenario` gate (§15.8).
2703
- "scenario-validation"
2704
+ "scenario-validation",
2705
+ // The presentation as a host overlay a session surface may open (§6.4).
2706
+ "presentation-overlay"
2704
2707
  ];
2705
2708
  function unsupportedFeatures(manifest) {
2706
2709
  return (manifest.requires ?? []).filter((feature) => !SUPPORTED_FEATURES.includes(feature));
@@ -4195,7 +4198,7 @@ function validateSettingsOverrides(overrides, schemas, sourceLabel) {
4195
4198
  ${errors.join("\n")}` } : { valid: true };
4196
4199
  }
4197
4200
  function validatePartialOverride(override, settingsSchema) {
4198
- const validator = settingsAjv.compile(withoutRequired(settingsSchema));
4201
+ const validator = settingsAjv.compile(closed(withoutRequired(settingsSchema)));
4199
4202
  return validator(override) ? null : validator.errors ?? [];
4200
4203
  }
4201
4204
  var SCHEMA_MAP_KEYWORDS = ["properties", "patternProperties", "definitions", "$defs"];
@@ -4223,6 +4226,53 @@ function withoutRequired(schema2) {
4223
4226
  }
4224
4227
  return copy;
4225
4228
  }
4229
+ var COMBINATOR_KEYWORDS = ["allOf", "anyOf", "oneOf", "if", "not", "$ref"];
4230
+ function closed(schema2) {
4231
+ if (typeof schema2 !== "object" || schema2 === null) return schema2;
4232
+ const copy = { ...schema2 };
4233
+ for (const keyword of SCHEMA_MAP_KEYWORDS) {
4234
+ const map3 = schema2[keyword];
4235
+ if (map3 && typeof map3 === "object") {
4236
+ copy[keyword] = Object.fromEntries(
4237
+ Object.entries(map3).map(([key, value]) => [key, closed(value)])
4238
+ );
4239
+ }
4240
+ }
4241
+ if (typeof schema2.additionalProperties === "object") {
4242
+ copy.additionalProperties = closed(schema2.additionalProperties);
4243
+ }
4244
+ if (Array.isArray(schema2.items)) copy.items = schema2.items.map(closed);
4245
+ else if (schema2.items !== void 0) copy.items = closed(schema2.items);
4246
+ if (isPlainOpen(schema2)) copy.additionalProperties = false;
4247
+ return copy;
4248
+ }
4249
+ function isPlainOpen(schema2) {
4250
+ return schema2.properties !== void 0 && schema2.additionalProperties === void 0 && schema2.patternProperties === void 0 && !COMBINATOR_KEYWORDS.some((keyword) => keyword in schema2);
4251
+ }
4252
+ function openSettingsObjects(schema2, at = "") {
4253
+ if (typeof schema2 !== "object" || schema2 === null) return [];
4254
+ const found = isPlainOpen(schema2) ? [at] : [];
4255
+ for (const keyword of SCHEMA_MAP_KEYWORDS) {
4256
+ const map3 = schema2[keyword];
4257
+ if (!map3 || typeof map3 !== "object") continue;
4258
+ for (const [key, value] of Object.entries(map3)) {
4259
+ found.push(...openSettingsObjects(value, `${at}/${keyword}/${key}`));
4260
+ }
4261
+ }
4262
+ if (typeof schema2.additionalProperties === "object") {
4263
+ found.push(
4264
+ ...openSettingsObjects(schema2.additionalProperties, `${at}/additionalProperties`)
4265
+ );
4266
+ }
4267
+ if (Array.isArray(schema2.items)) {
4268
+ schema2.items.forEach(
4269
+ (item, index3) => found.push(...openSettingsObjects(item, `${at}/items/${index3}`))
4270
+ );
4271
+ } else if (schema2.items !== void 0) {
4272
+ found.push(...openSettingsObjects(schema2.items, `${at}/items`));
4273
+ }
4274
+ return found;
4275
+ }
4226
4276
 
4227
4277
  // cli/discovery/manifest-paths.ts
4228
4278
  import { posix } from "path";
@@ -22075,6 +22125,16 @@ function settingReferences(markdown) {
22075
22125
  walk3(parse2(markdown).children, false);
22076
22126
  return references;
22077
22127
  }
22128
+ function strayFences(markdown) {
22129
+ const lines = [];
22130
+ visit(parse2(markdown), "text", (node2) => {
22131
+ const start = node2.position?.start.line ?? 0;
22132
+ node2.value.split("\n").forEach((text5, offset) => {
22133
+ if (/^:{3,}\s*$/.test(text5)) lines.push(start + offset);
22134
+ });
22135
+ });
22136
+ return lines;
22137
+ }
22078
22138
 
22079
22139
  // cli/guide/effective-guide.ts
22080
22140
  function readEffectiveGuide(guide, root2, resolved) {
@@ -22337,6 +22397,7 @@ function swallow() {
22337
22397
 
22338
22398
  // cli/core/participant-registry.ts
22339
22399
  import { EventEmitter } from "events";
22400
+ var MAX_PARTICIPANT_NAME_LENGTH = 60;
22340
22401
  var ParticipantRegistry = class extends EventEmitter {
22341
22402
  teams = /* @__PURE__ */ new Map();
22342
22403
  /**
@@ -23606,6 +23667,16 @@ var SessionRoster = class {
23606
23667
  if (!teamId) throw new DeniedError("The caller is not on a team");
23607
23668
  return this.renameTeam(teamId, command.name);
23608
23669
  }
23670
+ renameSelf(command) {
23671
+ if (!command.participantId)
23672
+ throw new DeniedError("Only a participant can rename themselves");
23673
+ const trimmed = command.name.trim();
23674
+ if (!trimmed) throw new DeniedError("A name cannot be blank");
23675
+ if (trimmed.length > MAX_PARTICIPANT_NAME_LENGTH) {
23676
+ throw new DeniedError(`A name is at most ${MAX_PARTICIPANT_NAME_LENGTH} characters`);
23677
+ }
23678
+ return this.renameParticipant(command.participantId, trimmed);
23679
+ }
23609
23680
  async addParticipant(teamId, name) {
23610
23681
  if (!this.host.state.getTeamIndexes().some((i) => `team-${i + 1}` === teamId)) {
23611
23682
  throw new DeniedError(`Unknown team "${teamId}"`);
@@ -25033,6 +25104,7 @@ var PLAY_STAGE = /* @__PURE__ */ new Set([
25033
25104
  "renameParticipant",
25034
25105
  "moveParticipant",
25035
25106
  "renameOwnTeam",
25107
+ "renameSelf",
25036
25108
  "extendTick"
25037
25109
  ]);
25038
25110
  var STALE_BLOCKED = /* @__PURE__ */ new Set([
@@ -25687,6 +25759,8 @@ var Session = class {
25687
25759
  return this.roster.renameTeam(command.teamId, command.name);
25688
25760
  case "renameOwnTeam":
25689
25761
  return this.roster.renameOwnTeam(command);
25762
+ case "renameSelf":
25763
+ return this.roster.renameSelf(command);
25690
25764
  case "addParticipant":
25691
25765
  return this.roster.addParticipant(command.teamId, command.name);
25692
25766
  case "renameParticipant":
@@ -25859,6 +25933,12 @@ var Session = class {
25859
25933
  await deleteBlobs(this.options.packagePath, retentions);
25860
25934
  }
25861
25935
  setLocale(locale) {
25936
+ const supported = this.packageConfiguration()?.game?.definition.supportedLocales;
25937
+ if (supported?.length && !supported.includes(locale)) {
25938
+ throw new DeniedError(
25939
+ `"${locale}" is not one of this game's locales (${supported.join(", ")})`
25940
+ );
25941
+ }
25862
25942
  this.locale = locale;
25863
25943
  this.executor.setLocale(locale);
25864
25944
  return void 0;
@@ -26846,7 +26926,42 @@ var VIDEO_PROVIDERS = {
26846
26926
  embedHosts: ["www.youtube-nocookie.com"]
26847
26927
  }
26848
26928
  };
26849
- var ALLOWED_KEYS = /* @__PURE__ */ new Set(["provider", "id"]);
26929
+ var FILE_VIDEO_PROVIDER = "file";
26930
+ var FILE_VIDEO_EXTENSIONS = {
26931
+ src: ["mp4", "webm"],
26932
+ poster: ["png", "jpg", "jpeg", "gif", "webp", "avif"],
26933
+ captions: ["vtt"]
26934
+ };
26935
+ var ALLOWED_KEYS = {
26936
+ youtube: /* @__PURE__ */ new Set(["provider", "id"]),
26937
+ [FILE_VIDEO_PROVIDER]: /* @__PURE__ */ new Set(["provider", "src", "title", "poster", "captions"])
26938
+ };
26939
+ var SUPPORTED_PROVIDERS = [...Object.keys(VIDEO_PROVIDERS), FILE_VIDEO_PROVIDER];
26940
+ var CHAPTER_BASE = "https://guide.invalid/content/locale/chapter.md";
26941
+ function guideAssetPath(reference) {
26942
+ if (/^[a-z][a-z0-9+.-]*:/i.test(reference) || reference.startsWith("/")) return void 0;
26943
+ if (reference.includes("\\") || /[?#]/.test(reference)) return void 0;
26944
+ let resolved;
26945
+ try {
26946
+ resolved = new URL(reference, CHAPTER_BASE);
26947
+ } catch {
26948
+ return void 0;
26949
+ }
26950
+ if (resolved.origin !== "https://guide.invalid" || !resolved.pathname.startsWith("/assets/")) {
26951
+ return void 0;
26952
+ }
26953
+ try {
26954
+ const path3 = decodeURIComponent(resolved.pathname.slice("/assets/".length));
26955
+ const segments = path3.split("/");
26956
+ return segments.some((s) => s === "" || s === "." || s === ".." || s.includes("\\")) ? void 0 : path3;
26957
+ } catch {
26958
+ return void 0;
26959
+ }
26960
+ }
26961
+ function extensionOf(path3) {
26962
+ const dot = path3.lastIndexOf(".");
26963
+ return dot === -1 ? "" : path3.slice(dot + 1).toLowerCase();
26964
+ }
26850
26965
  function parseVideoBlock(body) {
26851
26966
  const entries = {};
26852
26967
  for (const rawLine of body.split("\n")) {
@@ -26858,9 +26973,6 @@ function parseVideoBlock(body) {
26858
26973
  }
26859
26974
  const key = match2[1];
26860
26975
  const value = match2[2].trim();
26861
- if (!ALLOWED_KEYS.has(key)) {
26862
- return { ok: false, error: `Unknown key "${key}" in video block` };
26863
- }
26864
26976
  if (key in entries) {
26865
26977
  return { ok: false, error: `Duplicate key "${key}" in video block` };
26866
26978
  }
@@ -26870,13 +26982,20 @@ function parseVideoBlock(body) {
26870
26982
  if (!provider) {
26871
26983
  return { ok: false, error: 'Video block is missing "provider"' };
26872
26984
  }
26873
- const registered = VIDEO_PROVIDERS[provider];
26874
- if (!registered) {
26985
+ const allowed = ALLOWED_KEYS[provider];
26986
+ if (!allowed) {
26875
26987
  return {
26876
26988
  ok: false,
26877
- error: `Unknown video provider "${provider}". Supported providers: ${Object.keys(VIDEO_PROVIDERS).join(", ")}`
26989
+ error: `Unknown video provider "${provider}". Supported providers: ${SUPPORTED_PROVIDERS.join(", ")}`
26878
26990
  };
26879
26991
  }
26992
+ for (const key of Object.keys(entries)) {
26993
+ if (!allowed.has(key)) {
26994
+ return { ok: false, error: `Unknown key "${key}" in video block` };
26995
+ }
26996
+ }
26997
+ if (provider === FILE_VIDEO_PROVIDER) return parseFileVideo(entries);
26998
+ const registered = VIDEO_PROVIDERS[provider];
26880
26999
  const id = entries.id;
26881
27000
  if (!id) {
26882
27001
  return { ok: false, error: 'Video block is missing "id"' };
@@ -26887,7 +27006,43 @@ function parseVideoBlock(body) {
26887
27006
  error: `Video id "${id}" is not a valid ${provider} id`
26888
27007
  };
26889
27008
  }
26890
- return { ok: true, provider, id, embedUrl: registered.embedUrl(id) };
27009
+ return { ok: true, kind: "embed", provider, id, embedUrl: registered.embedUrl(id) };
27010
+ }
27011
+ function parseFileVideo(entries) {
27012
+ if (!entries.src) {
27013
+ return { ok: false, error: 'Video block is missing "src"' };
27014
+ }
27015
+ const files = {};
27016
+ for (const key of Object.keys(
27017
+ FILE_VIDEO_EXTENSIONS
27018
+ )) {
27019
+ const reference = entries[key];
27020
+ if (reference === void 0) continue;
27021
+ const path3 = guideAssetPath(reference);
27022
+ if (!path3) {
27023
+ return {
27024
+ ok: false,
27025
+ error: `Video ${key} "${reference}" must be a file in the guide's assets/ directory`
27026
+ };
27027
+ }
27028
+ const extensions = FILE_VIDEO_EXTENSIONS[key];
27029
+ if (!extensions.includes(extensionOf(path3))) {
27030
+ return {
27031
+ ok: false,
27032
+ error: `Video ${key} "${reference}" must be a ${extensions.map((e) => `.${e}`).join(", ")} file`
27033
+ };
27034
+ }
27035
+ files[key] = path3;
27036
+ }
27037
+ return {
27038
+ ok: true,
27039
+ kind: "file",
27040
+ provider: FILE_VIDEO_PROVIDER,
27041
+ src: files.src,
27042
+ ...files.poster ? { poster: files.poster } : {},
27043
+ ...files.captions ? { captions: files.captions } : {},
27044
+ ...entries.title ? { title: entries.title } : {}
27045
+ };
26891
27046
  }
26892
27047
 
26893
27048
  // cli/validation/guide-settings-validator.ts
@@ -26959,6 +27114,11 @@ function validateGuideSettings(chapters, context) {
26959
27114
  const warnings = [];
26960
27115
  const used = /* @__PURE__ */ new Set();
26961
27116
  for (const chapter of chapters) {
27117
+ for (const line of strayFences(chapter.markdown)) {
27118
+ warnings.push(
27119
+ `${chapter.label}:${line}: this ::: closes nothing, so a block above it ended early; a :::when that holds another ::: block needs more colons than it, as in ::::when`
27120
+ );
27121
+ }
26962
27122
  for (const reference of settingReferences(chapter.markdown)) {
26963
27123
  const where3 = `${chapter.label}:${reference.line}`;
26964
27124
  const directive2 = reference.kind === "value" ? ":setting" : ":::when";
@@ -27023,6 +27183,7 @@ function validateGuideSettings(chapters, context) {
27023
27183
  }
27024
27184
 
27025
27185
  // cli/validation/facilitator-guide-validator.ts
27186
+ var LARGE_VIDEO_FILE_BYTES = 25 * 1024 * 1024;
27026
27187
  var VIDEO_BLOCK_PATTERN = /^[ \t]*```video[ \t]*\r?\n([\s\S]*?)^[ \t]*```[ \t]*$/gm;
27027
27188
  var IMAGE_PATTERN = /!\[[^\]]*\]\(([^()\s]+)(?:\s+"[^"]*")?\)/g;
27028
27189
  function listChapters(localeDir) {
@@ -27081,6 +27242,27 @@ function validateFacilitatorGuideContent(options) {
27081
27242
  const parsed = parseVideoBlock(match2[1]);
27082
27243
  if (!parsed.ok) {
27083
27244
  errors.push(`${label4}: ${parsed.error}`);
27245
+ continue;
27246
+ }
27247
+ if (parsed.kind !== "file") continue;
27248
+ const assetsDir = join11(rootDirectory, "assets");
27249
+ for (const [key, path3] of [
27250
+ ["src", parsed.src],
27251
+ ["poster", parsed.poster],
27252
+ ["captions", parsed.captions]
27253
+ ]) {
27254
+ if (path3 === void 0) continue;
27255
+ const file = join11(assetsDir, path3);
27256
+ if (!existsSync11(file) || !statSync2(file).isFile()) {
27257
+ errors.push(
27258
+ `${label4}: video ${key} "assets/${path3}" does not resolve to a file`
27259
+ );
27260
+ } else if (key === "src" && statSync2(file).size > LARGE_VIDEO_FILE_BYTES) {
27261
+ const megabytes = Math.round(statSync2(file).size / (1024 * 1024));
27262
+ warnings.push(
27263
+ `${label4}: video "assets/${path3}" is ${megabytes} MB; every upload of the package carries it, so consider compressing it or embedding it from YouTube`
27264
+ );
27265
+ }
27084
27266
  }
27085
27267
  }
27086
27268
  for (const match2 of content3.matchAll(IMAGE_PATTERN)) {
@@ -27134,6 +27316,7 @@ function validateGame(game, config) {
27134
27316
  }
27135
27317
  }
27136
27318
  warnings.push(...namesBeyondMax("game", declared));
27319
+ warnings.push(...openSettingsObjectWarnings(config));
27137
27320
  for (const scenario of config.scenarios ?? []) {
27138
27321
  const overrides = scenarioGame(scenario);
27139
27322
  if (!overrides?.teams) continue;
@@ -27496,6 +27679,13 @@ function collectMissingSettingsDefaults(config) {
27496
27679
  }
27497
27680
  return errors;
27498
27681
  }
27682
+ function openSettingsObjectWarnings(config) {
27683
+ return (config.settings ?? []).flatMap(
27684
+ (settings) => openSettingsObjects(settings.definition.settingsSchema).map(
27685
+ (pointer) => `Settings "${settings.definition.identifier}" leaves the object at ${pointer === "" ? "the top of its settingsSchema" : `settingsSchema${pointer}`} open. A key it does not declare is refused all the same; add "additionalProperties": false so the schema says so.`
27686
+ )
27687
+ );
27688
+ }
27499
27689
  function collectVestigialRequired(config) {
27500
27690
  const errors = [];
27501
27691
  for (const settings of config.settings ?? []) {
@@ -28719,7 +28909,16 @@ var BRAND_FILE_SCHEMA = {
28719
28909
  properties: { onLight: { type: "string" }, onDark: { type: "string" } },
28720
28910
  additionalProperties: false
28721
28911
  },
28722
- icon: { type: "string", minLength: 1 },
28912
+ icon: {
28913
+ oneOf: [
28914
+ { type: "string", minLength: 1 },
28915
+ {
28916
+ type: "object",
28917
+ properties: { onLight: { type: "string" }, onDark: { type: "string" } },
28918
+ additionalProperties: false
28919
+ }
28920
+ ]
28921
+ },
28723
28922
  fonts: {
28724
28923
  type: "object",
28725
28924
  properties: { heading: FONT_SCHEMA, body: FONT_SCHEMA },
@@ -28806,7 +29005,12 @@ function readBrandFile(path3, id, defaults) {
28806
29005
  if (data.logo?.onDark) checkPath(path3, root2, data.logo.onDark, "/logo/onDark");
28807
29006
  if (data.loader?.onLight) checkPath(path3, root2, data.loader.onLight, "/loader/onLight");
28808
29007
  if (data.loader?.onDark) checkPath(path3, root2, data.loader.onDark, "/loader/onDark");
28809
- if (data.icon) checkPath(path3, root2, data.icon, "/icon");
29008
+ const icon = typeof data.icon === "string" ? { onLight: data.icon, onDark: data.icon } : data.icon;
29009
+ if (typeof data.icon === "string") checkPath(path3, root2, data.icon, "/icon");
29010
+ else {
29011
+ if (icon?.onLight) checkPath(path3, root2, icon.onLight, "/icon/onLight");
29012
+ if (icon?.onDark) checkPath(path3, root2, icon.onDark, "/icon/onDark");
29013
+ }
28810
29014
  for (const slot2 of ["heading", "body"]) {
28811
29015
  data.fonts?.[slot2]?.sources.forEach(
28812
29016
  (source, index3) => checkPath(path3, root2, source.url, `/fonts/${slot2}/sources/${index3}/url`)
@@ -28822,7 +29026,7 @@ function readBrandFile(path3, id, defaults) {
28822
29026
  brand: {
28823
29027
  name: data.name,
28824
29028
  ...data.logo && (data.logo.onLight || data.logo.onDark) ? { logo: data.logo } : {},
28825
- ...data.icon ? { icon: data.icon } : {},
29029
+ ...icon && (icon.onLight || icon.onDark) ? { icon } : {},
28826
29030
  ...data.fonts && (data.fonts.heading || data.fonts.body) ? { fonts: data.fonts } : {}
28827
29031
  }
28828
29032
  };
@@ -28917,7 +29121,12 @@ function summarise(brand, assetOrigin) {
28917
29121
  ...source.logo.onDark ? { onDark: url(source.logo.onDark) } : {}
28918
29122
  }
28919
29123
  } : {},
28920
- ...source.icon ? { icon: url(source.icon) } : {},
29124
+ ...source.icon ? {
29125
+ icon: {
29126
+ ...source.icon.onLight ? { onLight: url(source.icon.onLight) } : {},
29127
+ ...source.icon.onDark ? { onDark: url(source.icon.onDark) } : {}
29128
+ }
29129
+ } : {},
28921
29130
  ...fonts ? { fonts } : {}
28922
29131
  }
28923
29132
  }
@@ -29480,52 +29689,365 @@ function mountableSurfaces(config) {
29480
29689
  ].filter((surface) => surface !== null);
29481
29690
  }
29482
29691
 
29483
- // cli/dev/routes.ts
29484
- function runOf(req) {
29485
- return req.query.run === "walkthrough" ? "walkthrough" : "session";
29692
+ // cli/dev/view/batch.ts
29693
+ function projectContext2(context, surface) {
29694
+ const declared = /* @__PURE__ */ new Set([...surface.reads, ...surface.writes]);
29695
+ const projected = {};
29696
+ for (const [capability, values] of Object.entries(context)) {
29697
+ if (declared.has(capability)) projected[capability] = values;
29698
+ }
29699
+ return projected;
29486
29700
  }
29487
- function registerRoutes(app, deps) {
29488
- const { session, packagePath, runFor } = deps;
29489
- app.get("/api/state", async (req, res) => {
29490
- res.json((await runFor(runOf(req))).project());
29491
- });
29492
- app.get("/api/surfaces", (req, res) => {
29493
- const origin = deps.assetOrigin(req.headers.host);
29494
- res.json(
29495
- mountableSurfaces(session.packageConfiguration()).map((mountable) => ({
29496
- ...mountable,
29497
- origin
29498
- }))
29499
- );
29500
- });
29501
- app.get("/api/session", async (req, res) => {
29502
- const run = await runFor(runOf(req));
29503
- res.json({
29504
- instanceId: deps.instanceId,
29505
- inSetup: run.inSetup,
29506
- diagnostics: run.diagnostics(),
29507
- sessionOverrides: run.sessionOverrides(),
29508
- pending: run.pendingChanges(),
29509
- warnings: deps.notices(run)
29701
+ function settingsFor(state2, surface, { withoutSession = false } = {}) {
29702
+ const settings = withoutSession ? state2.settingsWithoutSession : state2.settings;
29703
+ return Object.fromEntries(
29704
+ surface.settings.filter((identifier) => identifier in settings).map((identifier) => [identifier, settings[identifier]])
29705
+ );
29706
+ }
29707
+ function draftSettingsFor(state2, surface, viewer) {
29708
+ const scenarioId = viewer.scenario ?? null;
29709
+ const draft = state2.scenarioDrafts?.find((entry) => entry.scenarioId === scenarioId);
29710
+ const settings = draft?.settings ?? {};
29711
+ return Object.fromEntries(
29712
+ surface.settings.filter((identifier) => identifier in settings).map((identifier) => [identifier, settings[identifier]])
29713
+ );
29714
+ }
29715
+ function sessionKeyFor(state2, surface, { sessionless = false } = {}) {
29716
+ const outside = surface.kind === "scenario-editor" || surface.kind === "presentation" && sessionless;
29717
+ return outside ? `outside-session:${state2.game.identifier}` : state2.session.sessionKey;
29718
+ }
29719
+ function themeMessages(theme) {
29720
+ return [
29721
+ { type: "setTheme", payload: theme.palette },
29722
+ { type: "themePreferenceChanged", preference: theme.preference }
29723
+ ];
29724
+ }
29725
+ function assetUrls(assetOrigin) {
29726
+ return {
29727
+ blobPrefix: `${assetOrigin}/assets/blobs/`,
29728
+ scenarioAssetPrefix: `${assetOrigin}/assets/scenario/`,
29729
+ sharedAssetPrefix: `${assetOrigin}/assets/shared/`,
29730
+ assetAuthRedeemUrl: `${assetOrigin}/assets/auth/redeem`
29731
+ };
29732
+ }
29733
+ function teamOf(state2, teamIndex) {
29734
+ if (teamIndex === void 0) return state2.teams[0];
29735
+ return state2.teams.find((team) => team.index === teamIndex);
29736
+ }
29737
+ function teamList(state2) {
29738
+ return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({ teamId: team.teamId, index: team.index, name: team.name }));
29739
+ }
29740
+ var IDLE_TIMER2 = {
29741
+ enabled: false,
29742
+ paused: false,
29743
+ nextTickAt: null,
29744
+ intervalMs: null,
29745
+ pausedAt: null,
29746
+ pausedMs: 0,
29747
+ extendedMs: 0,
29748
+ scheduleStartedAt: null
29749
+ };
29750
+ function buildBatch(options) {
29751
+ const { surface, state: state2, theme, origin, assetOrigin } = options;
29752
+ const common = [
29753
+ { type: "setLocale", payload: { locale: state2.session.locale } },
29754
+ { type: "setAssetUrls", payload: assetUrls(assetOrigin ?? origin) },
29755
+ ...theme ? themeMessages(theme) : []
29756
+ ];
29757
+ switch (surface.kind) {
29758
+ case "game":
29759
+ case "waiting-room":
29760
+ return [...playerBatch(options), ...common];
29761
+ case "session":
29762
+ return [...sessionBatch(options), ...common];
29763
+ // The two settings editors are sent the same batch (§12.3): neither is
29764
+ // told which slot it fills, since each is its own bundle.
29765
+ case "setup":
29766
+ return [{ type: "setSettings", payload: settingsFor(state2, surface) }, ...common];
29767
+ case "scenario-editor":
29768
+ return [
29769
+ { type: "setSettings", payload: draftSettingsFor(state2, surface, options.viewer) },
29770
+ ...common
29771
+ ];
29772
+ case "presentation":
29773
+ return [...presentationBatch(options), ...common];
29774
+ }
29775
+ return common;
29776
+ }
29777
+ function crossTeamData(state2, surface, ownTeamIndex) {
29778
+ const across = new Set(surface.crossTeamReads);
29779
+ return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({
29780
+ teamId: team.teamId,
29781
+ index: team.index,
29782
+ name: team.name,
29783
+ context: team.index === ownTeamIndex ? projectContext2(team.context, surface) : Object.fromEntries(
29784
+ Object.entries(team.context).filter(
29785
+ ([capability]) => across.has(capability)
29786
+ )
29787
+ )
29788
+ }));
29789
+ }
29790
+ function joinUrl(origin, teamIndex) {
29791
+ return `${origin}/team/${teamIndex + 1}/join?bare`;
29792
+ }
29793
+ function playerBatch({
29794
+ surface,
29795
+ state: state2,
29796
+ viewer,
29797
+ origin,
29798
+ roundProcessing
29799
+ }) {
29800
+ const team = teamOf(state2, viewer.teamIndex);
29801
+ const participant = viewer.observer ? void 0 : team?.participants.find((p) => p.id === viewer.participantId) ?? team?.participants[0];
29802
+ const messages2 = [
29803
+ {
29804
+ type: "stateChanged",
29805
+ payload: projectContext2(team?.context ?? {}, surface),
29806
+ // §12.5: the head tick, so a review scrubber can be bounded and a
29807
+ // cache invalidated on undo.
29808
+ completedTicks: team?.completedTicks ?? state2.session.completedTicks
29809
+ },
29810
+ { type: "setSettings", payload: settingsFor(state2, surface) }
29811
+ ];
29812
+ if (participant) {
29813
+ messages2.push({
29814
+ type: "setParticipant",
29815
+ payload: {
29816
+ id: participant.id,
29817
+ name: participant.name,
29818
+ index: participant.index,
29819
+ teamId: team?.teamId ?? "team-1"
29820
+ },
29821
+ // There are no accounts here, so every name is the participant's
29822
+ // own to change (§12.5).
29823
+ canRenameSelf: true
29510
29824
  });
29511
- });
29512
- app.post("/api/command", express.json({ limit: "20mb" }), async (req, res) => {
29513
- const invalid2 = commandError(req.body);
29514
- if (invalid2) {
29515
- res.status(400).json({ error: invalid2 });
29516
- return;
29517
- }
29518
- const command = req.body;
29519
- try {
29520
- if (rebuildsWalkthrough(command, runOf(req))) {
29521
- res.json(await deps.settleWalkthroughReset(command));
29522
- return;
29523
- }
29524
- const run = await runFor(runOf(req));
29525
- const result = isQuery(command) ? await run.query(command) : await run.submit(command);
29526
- if (command.type === "callEndpoint" && command.external && "type" in result && result.type === "endpoint") {
29527
- const blobs = blobLinks(
29528
- result.response,
29825
+ }
29826
+ messages2.push(
29827
+ { type: "setViewerRole", role: viewer.observer ? "observer" : "participant" },
29828
+ { type: "setRunKind", runKind: state2.session.runKind },
29829
+ { type: "setScenarioName", scenarioName: state2.game.scenarioName },
29830
+ {
29831
+ type: "setOwnTeam",
29832
+ payload: team ? { teamId: team.teamId, index: team.index, name: team.name } : { teamId: "team-1", index: 0, name: "Team 1" }
29833
+ },
29834
+ {
29835
+ type: "setOwnTeamJoinLink",
29836
+ payload: team ? { joinUrl: joinUrl(origin, team.index) } : (
29837
+ // §12.3, as amended: a host with nothing to offer says so
29838
+ // rather than staying silent, so a surface rendering a join
29839
+ // panel shows nothing instead of waiting for a message that
29840
+ // never comes.
29841
+ null
29842
+ )
29843
+ },
29844
+ { type: "setParticipantList", participants: team?.participants ?? [] },
29845
+ { type: "setTeamList", payload: teamList(state2) },
29846
+ { type: "setTimer", payload: team?.timer ?? IDLE_TIMER2 }
29847
+ );
29848
+ if (surface.kind === "game") {
29849
+ messages2.push({ type: "setRoundProcessing", processing: roundProcessing === true });
29850
+ }
29851
+ if ((surface.kind === "game" || surface.kind === "waiting-room") && surface.crossTeamReads.length > 0 && state2.session.mode === "shared-state") {
29852
+ messages2.push({
29853
+ type: "setCrossTeamData",
29854
+ payload: crossTeamData(state2, surface, team?.index)
29855
+ });
29856
+ }
29857
+ return messages2;
29858
+ }
29859
+ function sessionBatch({
29860
+ surface,
29861
+ state: state2,
29862
+ gameName,
29863
+ origin,
29864
+ overlays
29865
+ }) {
29866
+ return [
29867
+ {
29868
+ type: "setSessionMeta",
29869
+ payload: {
29870
+ sessionId: "dev-session",
29871
+ name: gameName,
29872
+ readOnly: false,
29873
+ waitingRoomOpen: state2.session.waitingRoomOpen,
29874
+ joinPin: null,
29875
+ canSetLocale: true
29876
+ }
29877
+ },
29878
+ { type: "setSessionData", payload: sessionData(state2, surface) },
29879
+ { type: "setSettings", payload: settingsFor(state2, surface) },
29880
+ { type: "setTeamConfiguration", payload: teamConfiguration(state2) },
29881
+ { type: "setTeamList", payload: teamList(state2) },
29882
+ {
29883
+ type: "setParticipantList",
29884
+ participants: participantList(state2)
29885
+ },
29886
+ { type: "setTeamLinks", payload: teamLinks(state2, origin) },
29887
+ { type: "setWalkthroughLink", payload: walkthroughLink(origin) },
29888
+ { type: "setRunKind", runKind: state2.session.runKind },
29889
+ { type: "setScenarioName", scenarioName: state2.game.scenarioName },
29890
+ { type: "setAvailableOverlays", overlays: overlays ?? availableOverlays() }
29891
+ ];
29892
+ }
29893
+ function presentationBatch({
29894
+ surface,
29895
+ state: state2,
29896
+ gameName,
29897
+ origin,
29898
+ sessionless
29899
+ }) {
29900
+ return [
29901
+ {
29902
+ type: "setPresentation",
29903
+ payload: {
29904
+ game: {
29905
+ name: state2.game.name,
29906
+ // Without a session, as the scenario resolves it alone (§6.15.1).
29907
+ maxTicks: sessionless ? gameSettingsOf(state2.settingsWithoutSession).maxTicks : state2.session.maxTicks,
29908
+ mode: state2.session.mode,
29909
+ scenarioName: state2.game.scenarioName
29910
+ },
29911
+ session: sessionless ? null : {
29912
+ // The dev server runs one session; its id is the
29913
+ // one the session surface is told (above).
29914
+ id: "dev-session",
29915
+ name: gameName,
29916
+ completedTicks: Math.max(
29917
+ state2.session.completedTicks,
29918
+ ...state2.teams.map((team) => team.completedTicks)
29919
+ ),
29920
+ data: sessionData(state2, surface),
29921
+ teams: teamList(state2),
29922
+ participants: participantList(state2),
29923
+ // A deck puts these on the projector, so no observe
29924
+ // URL: watching a team is the facilitator's tool.
29925
+ joinLinks: teamLinks(state2, origin).map(({ teamId, joinUrl: joinUrl2 }) => ({
29926
+ teamId,
29927
+ joinUrl: joinUrl2
29928
+ })),
29929
+ joinPin: null
29930
+ }
29931
+ }
29932
+ },
29933
+ {
29934
+ type: "setSettings",
29935
+ payload: settingsFor(state2, surface, { withoutSession: sessionless })
29936
+ }
29937
+ ];
29938
+ }
29939
+ function walkthroughLink(origin) {
29940
+ return { url: `${origin}/walkthrough` };
29941
+ }
29942
+ function availableOverlays(offered = {}) {
29943
+ return [
29944
+ ...offered.guide ? ["facilitator-guide"] : [],
29945
+ "print-sheets",
29946
+ ...offered.presentation ? ["presentation"] : []
29947
+ ];
29948
+ }
29949
+ function offersPresentationOverlay(config) {
29950
+ return config?.presentation !== void 0 && (config.requires ?? []).includes(PRESENTATION_OVERLAY);
29951
+ }
29952
+ var PRESENTATION_OVERLAY = "presentation-overlay";
29953
+ function participantList(state2) {
29954
+ return state2.teams.flatMap(
29955
+ (team) => team.participants.map((participant) => ({
29956
+ id: participant.id,
29957
+ name: participant.name,
29958
+ index: participant.index,
29959
+ connected: participant.connected,
29960
+ teamId: team.teamId
29961
+ }))
29962
+ );
29963
+ }
29964
+ function teamLinks(state2, origin) {
29965
+ return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({
29966
+ teamId: team.teamId,
29967
+ joinUrl: joinUrl(origin, team.index),
29968
+ observeUrl: `${origin}/team/${team.index + 1}/observe`
29969
+ }));
29970
+ }
29971
+ function teamConfiguration(state2) {
29972
+ return {
29973
+ mode: state2.session.mode,
29974
+ ...state2.session.teamBounds.min === void 0 ? {} : { min: state2.session.teamBounds.min },
29975
+ max: state2.session.teamBounds.max
29976
+ };
29977
+ }
29978
+ function sessionData(state2, surface) {
29979
+ const teams = {};
29980
+ for (const team of state2.teams) {
29981
+ const own5 = {};
29982
+ for (const [capability, values] of Object.entries(team.context)) {
29983
+ if (!(capability in state2.shared)) own5[capability] = values;
29984
+ }
29985
+ teams[team.teamId] = {
29986
+ context: projectContext2(own5, surface),
29987
+ completedTicks: team.completedTicks,
29988
+ timer: team.timer ?? IDLE_TIMER2,
29989
+ // Monotonic per delivery. One session, one host, so the tick is a
29990
+ // sufficient clock; the wrapper only compares it with itself.
29991
+ revision: team.completedTicks
29992
+ };
29993
+ }
29994
+ return {
29995
+ // The dev server only ever sends snapshots, so the revision is a
29996
+ // baseline the wrapper never compares a delta against.
29997
+ shared: {
29998
+ context: projectContext2(state2.shared, surface),
29999
+ revision: state2.session.completedTicks
30000
+ },
30001
+ teams
30002
+ };
30003
+ }
30004
+
30005
+ // cli/dev/routes.ts
30006
+ function runOf(req) {
30007
+ return req.query.run === "walkthrough" ? "walkthrough" : "session";
30008
+ }
30009
+ function registerRoutes(app, deps) {
30010
+ const { session, packagePath, runFor } = deps;
30011
+ app.get("/api/state", async (req, res) => {
30012
+ res.json((await runFor(runOf(req))).project());
30013
+ });
30014
+ app.get("/api/surfaces", (req, res) => {
30015
+ const origin = deps.assetOrigin(req.headers.host);
30016
+ res.json(
30017
+ mountableSurfaces(session.packageConfiguration()).map((mountable) => ({
30018
+ ...mountable,
30019
+ origin
30020
+ }))
30021
+ );
30022
+ });
30023
+ app.get("/api/session", async (req, res) => {
30024
+ const run = await runFor(runOf(req));
30025
+ res.json({
30026
+ instanceId: deps.instanceId,
30027
+ inSetup: run.inSetup,
30028
+ diagnostics: run.diagnostics(),
30029
+ sessionOverrides: run.sessionOverrides(),
30030
+ pending: run.pendingChanges(),
30031
+ warnings: deps.notices(run)
30032
+ });
30033
+ });
30034
+ app.post("/api/command", express.json({ limit: "20mb" }), async (req, res) => {
30035
+ const invalid2 = commandError(req.body);
30036
+ if (invalid2) {
30037
+ res.status(400).json({ error: invalid2 });
30038
+ return;
30039
+ }
30040
+ const command = req.body;
30041
+ try {
30042
+ if (rebuildsWalkthrough(command, runOf(req))) {
30043
+ res.json(await deps.settleWalkthroughReset(command));
30044
+ return;
30045
+ }
30046
+ const run = await runFor(runOf(req));
30047
+ const result = isQuery(command) ? await run.query(command) : await run.submit(command);
30048
+ if (command.type === "callEndpoint" && command.external && "type" in result && result.type === "endpoint") {
30049
+ const blobs = blobLinks(
30050
+ result.response,
29529
30051
  (blobId) => `${req.protocol}://${req.get("host")}/api/blobs/${encodeURIComponent(blobId)}`
29530
30052
  );
29531
30053
  res.json(Object.keys(blobs).length > 0 ? { ...result, blobs } : result);
@@ -29643,6 +30165,14 @@ function registerRoutes(app, deps) {
29643
30165
  app.get("/api/guide", (_req, res) => {
29644
30166
  res.json({ guide: session.effectiveGuide() });
29645
30167
  });
30168
+ app.get("/api/overlays", (_req, res) => {
30169
+ res.json({
30170
+ overlays: availableOverlays({
30171
+ guide: session.effectiveGuide() !== null,
30172
+ presentation: offersPresentationOverlay(session.packageConfiguration())
30173
+ })
30174
+ });
30175
+ });
29646
30176
  app.get("/api/guide/content/:locale/:chapter", async (req, res) => {
29647
30177
  const guide = session.guide();
29648
30178
  if (!guide) {
@@ -29759,8 +30289,8 @@ function serveAsset(req, res, root2) {
29759
30289
 
29760
30290
  // cli/dev/view/commands.ts
29761
30291
  var FRAME_COMMANDS = {
29762
- game: /* @__PURE__ */ new Set(["updateData", "requestTick", "renameOwnTeam"]),
29763
- "waiting-room": /* @__PURE__ */ new Set(["updateData", "requestTick", "renameOwnTeam"]),
30292
+ game: /* @__PURE__ */ new Set(["updateData", "requestTick", "renameOwnTeam", "renameSelf"]),
30293
+ "waiting-room": /* @__PURE__ */ new Set(["updateData", "requestTick", "renameOwnTeam", "renameSelf"]),
29764
30294
  session: /* @__PURE__ */ new Set([
29765
30295
  "updateSessionData",
29766
30296
  "updateSharedData",
@@ -29769,6 +30299,7 @@ var FRAME_COMMANDS = {
29769
30299
  "resetGame",
29770
30300
  "resetWalkthrough",
29771
30301
  "setWaitingRoom",
30302
+ "setLocale",
29772
30303
  "createTeam",
29773
30304
  "renameTeam",
29774
30305
  "renameParticipant",
@@ -29788,7 +30319,9 @@ var FRAME_COMMANDS = {
29788
30319
  var NO_TEAM_ID = {
29789
30320
  setWaitingRoom: "The waiting room is session-wide, so setWaitingRoom takes no teamId",
29790
30321
  renameOwnTeam: "renameOwnTeam renames the caller's own team, which the host resolves; it takes no teamId",
29791
- resetWalkthrough: "A walkthrough holds one team, so resetWalkthrough takes no teamId"
30322
+ resetWalkthrough: "A walkthrough holds one team, so resetWalkthrough takes no teamId",
30323
+ setLocale: "The locale is the session's, so setLocale takes no teamId",
30324
+ renameSelf: "renameSelf renames the caller, whom the host resolves; it takes no teamId"
29792
30325
  };
29793
30326
  var FRAME_QUERIES = {
29794
30327
  game: /* @__PURE__ */ new Set(["callEndpoint", "getPastState", "getAllTeamsParticipants"]),
@@ -29828,6 +30361,11 @@ function commandFor(message, surface, viewer) {
29828
30361
  if (message.teamId !== void 0 && message.type in NO_TEAM_ID) {
29829
30362
  return { refused: NO_TEAM_ID[message.type] };
29830
30363
  }
30364
+ if (message.type === "renameSelf" && message.participantId !== void 0) {
30365
+ return {
30366
+ refused: "renameSelf renames the caller, whom the host resolves; it takes no participantId"
30367
+ };
30368
+ }
29831
30369
  const scope = teamScope(viewer);
29832
30370
  const actor = actorOf(viewer);
29833
30371
  const role = roleOf(viewer);
@@ -29886,6 +30424,8 @@ function commandFor(message, surface, viewer) {
29886
30424
  };
29887
30425
  case "setWaitingRoom":
29888
30426
  return { type: "setWaitingRoom", open: message.open === true };
30427
+ case "setLocale":
30428
+ return { type: "setLocale", locale: String(message.locale) };
29889
30429
  case "resetWalkthrough":
29890
30430
  return { type: "resetWalkthrough" };
29891
30431
  case "createTeam":
@@ -29901,6 +30441,8 @@ function commandFor(message, surface, viewer) {
29901
30441
  };
29902
30442
  case "renameOwnTeam":
29903
30443
  return { type: "renameOwnTeam", name: String(message.name), ...actor };
30444
+ case "renameSelf":
30445
+ return { type: "renameSelf", name: String(message.name), ...actor };
29904
30446
  case "renameParticipant":
29905
30447
  return {
29906
30448
  type: "renameParticipant",
@@ -30024,295 +30566,6 @@ function routeHref(route) {
30024
30566
  return search2 ? `${path3}?${search2}` : path3;
30025
30567
  }
30026
30568
 
30027
- // cli/dev/view/batch.ts
30028
- function projectContext2(context, surface) {
30029
- const declared = /* @__PURE__ */ new Set([...surface.reads, ...surface.writes]);
30030
- const projected = {};
30031
- for (const [capability, values] of Object.entries(context)) {
30032
- if (declared.has(capability)) projected[capability] = values;
30033
- }
30034
- return projected;
30035
- }
30036
- function settingsFor(state2, surface, { withoutSession = false } = {}) {
30037
- const settings = withoutSession ? state2.settingsWithoutSession : state2.settings;
30038
- return Object.fromEntries(
30039
- surface.settings.filter((identifier) => identifier in settings).map((identifier) => [identifier, settings[identifier]])
30040
- );
30041
- }
30042
- function draftSettingsFor(state2, surface, viewer) {
30043
- const scenarioId = viewer.scenario ?? null;
30044
- const draft = state2.scenarioDrafts?.find((entry) => entry.scenarioId === scenarioId);
30045
- const settings = draft?.settings ?? {};
30046
- return Object.fromEntries(
30047
- surface.settings.filter((identifier) => identifier in settings).map((identifier) => [identifier, settings[identifier]])
30048
- );
30049
- }
30050
- function sessionKeyFor(state2, surface, { sessionless = false } = {}) {
30051
- const outside = surface.kind === "scenario-editor" || surface.kind === "presentation" && sessionless;
30052
- return outside ? `outside-session:${state2.game.identifier}` : state2.session.sessionKey;
30053
- }
30054
- function themeMessages(theme) {
30055
- return [
30056
- { type: "setTheme", payload: theme.palette },
30057
- { type: "themePreferenceChanged", preference: theme.preference }
30058
- ];
30059
- }
30060
- function assetUrls(assetOrigin) {
30061
- return {
30062
- blobPrefix: `${assetOrigin}/assets/blobs/`,
30063
- scenarioAssetPrefix: `${assetOrigin}/assets/scenario/`,
30064
- sharedAssetPrefix: `${assetOrigin}/assets/shared/`,
30065
- assetAuthRedeemUrl: `${assetOrigin}/assets/auth/redeem`
30066
- };
30067
- }
30068
- function teamOf(state2, teamIndex) {
30069
- if (teamIndex === void 0) return state2.teams[0];
30070
- return state2.teams.find((team) => team.index === teamIndex);
30071
- }
30072
- function teamList(state2) {
30073
- return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({ teamId: team.teamId, index: team.index, name: team.name }));
30074
- }
30075
- var IDLE_TIMER2 = {
30076
- enabled: false,
30077
- paused: false,
30078
- nextTickAt: null,
30079
- intervalMs: null,
30080
- pausedAt: null,
30081
- pausedMs: 0,
30082
- extendedMs: 0,
30083
- scheduleStartedAt: null
30084
- };
30085
- function buildBatch(options) {
30086
- const { surface, state: state2, theme, origin, assetOrigin } = options;
30087
- const common = [
30088
- { type: "setLocale", payload: { locale: state2.session.locale } },
30089
- { type: "setAssetUrls", payload: assetUrls(assetOrigin ?? origin) },
30090
- ...theme ? themeMessages(theme) : []
30091
- ];
30092
- switch (surface.kind) {
30093
- case "game":
30094
- case "waiting-room":
30095
- return [...playerBatch(options), ...common];
30096
- case "session":
30097
- return [...sessionBatch(options), ...common];
30098
- // The two settings editors are sent the same batch (§12.3): neither is
30099
- // told which slot it fills, since each is its own bundle.
30100
- case "setup":
30101
- return [{ type: "setSettings", payload: settingsFor(state2, surface) }, ...common];
30102
- case "scenario-editor":
30103
- return [
30104
- { type: "setSettings", payload: draftSettingsFor(state2, surface, options.viewer) },
30105
- ...common
30106
- ];
30107
- case "presentation":
30108
- return [...presentationBatch(options), ...common];
30109
- }
30110
- return common;
30111
- }
30112
- function crossTeamData(state2, surface, ownTeamIndex) {
30113
- const across = new Set(surface.crossTeamReads);
30114
- return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({
30115
- teamId: team.teamId,
30116
- index: team.index,
30117
- name: team.name,
30118
- context: team.index === ownTeamIndex ? projectContext2(team.context, surface) : Object.fromEntries(
30119
- Object.entries(team.context).filter(
30120
- ([capability]) => across.has(capability)
30121
- )
30122
- )
30123
- }));
30124
- }
30125
- function joinUrl(origin, teamIndex) {
30126
- return `${origin}/team/${teamIndex + 1}/join?bare`;
30127
- }
30128
- function playerBatch({
30129
- surface,
30130
- state: state2,
30131
- viewer,
30132
- origin,
30133
- roundProcessing
30134
- }) {
30135
- const team = teamOf(state2, viewer.teamIndex);
30136
- const participant = viewer.observer ? void 0 : team?.participants.find((p) => p.id === viewer.participantId) ?? team?.participants[0];
30137
- const messages2 = [
30138
- {
30139
- type: "stateChanged",
30140
- payload: projectContext2(team?.context ?? {}, surface),
30141
- // §12.5: the head tick, so a review scrubber can be bounded and a
30142
- // cache invalidated on undo.
30143
- completedTicks: team?.completedTicks ?? state2.session.completedTicks
30144
- },
30145
- { type: "setSettings", payload: settingsFor(state2, surface) }
30146
- ];
30147
- if (participant) {
30148
- messages2.push({
30149
- type: "setParticipant",
30150
- payload: {
30151
- id: participant.id,
30152
- name: participant.name,
30153
- index: participant.index,
30154
- teamId: team?.teamId ?? "team-1"
30155
- }
30156
- });
30157
- }
30158
- messages2.push(
30159
- { type: "setViewerRole", role: viewer.observer ? "observer" : "participant" },
30160
- { type: "setRunKind", runKind: state2.session.runKind },
30161
- { type: "setScenarioName", scenarioName: state2.game.scenarioName },
30162
- {
30163
- type: "setOwnTeam",
30164
- payload: team ? { teamId: team.teamId, index: team.index, name: team.name } : { teamId: "team-1", index: 0, name: "Team 1" }
30165
- },
30166
- {
30167
- type: "setOwnTeamJoinLink",
30168
- payload: team ? { joinUrl: joinUrl(origin, team.index) } : (
30169
- // §12.3, as amended: a host with nothing to offer says so
30170
- // rather than staying silent, so a surface rendering a join
30171
- // panel shows nothing instead of waiting for a message that
30172
- // never comes.
30173
- null
30174
- )
30175
- },
30176
- { type: "setParticipantList", participants: team?.participants ?? [] },
30177
- { type: "setTeamList", payload: teamList(state2) },
30178
- { type: "setTimer", payload: team?.timer ?? IDLE_TIMER2 }
30179
- );
30180
- if (surface.kind === "game") {
30181
- messages2.push({ type: "setRoundProcessing", processing: roundProcessing === true });
30182
- }
30183
- if ((surface.kind === "game" || surface.kind === "waiting-room") && surface.crossTeamReads.length > 0 && state2.session.mode === "shared-state") {
30184
- messages2.push({
30185
- type: "setCrossTeamData",
30186
- payload: crossTeamData(state2, surface, team?.index)
30187
- });
30188
- }
30189
- return messages2;
30190
- }
30191
- function sessionBatch({
30192
- surface,
30193
- state: state2,
30194
- gameName,
30195
- origin,
30196
- hasGuide
30197
- }) {
30198
- return [
30199
- {
30200
- type: "setSessionMeta",
30201
- payload: {
30202
- sessionId: "dev-session",
30203
- name: gameName,
30204
- readOnly: false,
30205
- waitingRoomOpen: state2.session.waitingRoomOpen,
30206
- joinPin: null
30207
- }
30208
- },
30209
- { type: "setSessionData", payload: sessionData(state2, surface) },
30210
- { type: "setSettings", payload: settingsFor(state2, surface) },
30211
- { type: "setTeamConfiguration", payload: teamConfiguration(state2) },
30212
- { type: "setTeamList", payload: teamList(state2) },
30213
- {
30214
- type: "setParticipantList",
30215
- participants: state2.teams.flatMap(
30216
- (team) => team.participants.map((participant) => ({
30217
- id: participant.id,
30218
- name: participant.name,
30219
- index: participant.index,
30220
- connected: participant.connected,
30221
- teamId: team.teamId
30222
- }))
30223
- )
30224
- },
30225
- { type: "setTeamLinks", payload: teamLinks(state2, origin) },
30226
- { type: "setWalkthroughLink", payload: walkthroughLink(origin) },
30227
- { type: "setRunKind", runKind: state2.session.runKind },
30228
- { type: "setScenarioName", scenarioName: state2.game.scenarioName },
30229
- { type: "setAvailableOverlays", overlays: availableOverlays(hasGuide) }
30230
- ];
30231
- }
30232
- function presentationBatch({
30233
- surface,
30234
- state: state2,
30235
- gameName,
30236
- sessionless
30237
- }) {
30238
- return [
30239
- {
30240
- type: "setPresentation",
30241
- payload: {
30242
- game: {
30243
- name: state2.game.name,
30244
- // Without a session, as the scenario resolves it alone (§6.15.1).
30245
- maxTicks: sessionless ? gameSettingsOf(state2.settingsWithoutSession).maxTicks : state2.session.maxTicks,
30246
- mode: state2.session.mode,
30247
- scenarioName: state2.game.scenarioName
30248
- },
30249
- session: sessionless ? null : {
30250
- // The dev server runs one session; its id is the
30251
- // one the session surface is told (above).
30252
- id: "dev-session",
30253
- name: gameName,
30254
- completedTicks: Math.max(
30255
- state2.session.completedTicks,
30256
- ...state2.teams.map((team) => team.completedTicks)
30257
- ),
30258
- data: sessionData(state2, surface),
30259
- teams: teamList(state2)
30260
- }
30261
- }
30262
- },
30263
- {
30264
- type: "setSettings",
30265
- payload: settingsFor(state2, surface, { withoutSession: sessionless })
30266
- }
30267
- ];
30268
- }
30269
- function walkthroughLink(origin) {
30270
- return { url: `${origin}/walkthrough` };
30271
- }
30272
- function availableOverlays(hasGuide = false) {
30273
- return hasGuide ? ["facilitator-guide", "print-sheets"] : ["print-sheets"];
30274
- }
30275
- function teamLinks(state2, origin) {
30276
- return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({
30277
- teamId: team.teamId,
30278
- joinUrl: joinUrl(origin, team.index),
30279
- observeUrl: `${origin}/team/${team.index + 1}/observe`
30280
- }));
30281
- }
30282
- function teamConfiguration(state2) {
30283
- return {
30284
- mode: state2.session.mode,
30285
- ...state2.session.teamBounds.min === void 0 ? {} : { min: state2.session.teamBounds.min },
30286
- max: state2.session.teamBounds.max
30287
- };
30288
- }
30289
- function sessionData(state2, surface) {
30290
- const teams = {};
30291
- for (const team of state2.teams) {
30292
- const own5 = {};
30293
- for (const [capability, values] of Object.entries(team.context)) {
30294
- if (!(capability in state2.shared)) own5[capability] = values;
30295
- }
30296
- teams[team.teamId] = {
30297
- context: projectContext2(own5, surface),
30298
- completedTicks: team.completedTicks,
30299
- timer: team.timer ?? IDLE_TIMER2,
30300
- // Monotonic per delivery. One session, one host, so the tick is a
30301
- // sufficient clock; the wrapper only compares it with itself.
30302
- revision: team.completedTicks
30303
- };
30304
- }
30305
- return {
30306
- // The dev server only ever sends snapshots, so the revision is a
30307
- // baseline the wrapper never compares a delta against.
30308
- shared: {
30309
- context: projectContext2(state2.shared, surface),
30310
- revision: state2.session.completedTicks
30311
- },
30312
- teams
30313
- };
30314
- }
30315
-
30316
30569
  // cli/dev/view/viewer.ts
30317
30570
  function resolveViewer(state2, route) {
30318
30571
  const base = {
@@ -30427,7 +30680,7 @@ function viewMessages(page, state2, options) {
30427
30680
  origin: options.origin,
30428
30681
  assetOrigin: options.assetOrigin,
30429
30682
  gameName: options.gameName,
30430
- hasGuide: options.hasGuide,
30683
+ overlays: options.overlays,
30431
30684
  roundProcessing: options.roundProcessing
30432
30685
  });
30433
30686
  }
@@ -31071,7 +31324,10 @@ Install the package's dependencies to serve its surfaces.
31071
31324
  origin: this.consoleOrigin(view.host),
31072
31325
  assetOrigin: origin,
31073
31326
  gameName: state2.game.name,
31074
- hasGuide: session.effectiveGuide() !== null,
31327
+ overlays: availableOverlays({
31328
+ guide: session.effectiveGuide() !== null,
31329
+ presentation: offersPresentationOverlay(session.packageConfiguration())
31330
+ }),
31075
31331
  roundProcessing
31076
31332
  });
31077
31333
  return { page, messages: messages2 };