@serene-pub/core-catalog 0.6.0-pr-7 → 0.6.0-pr-9

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 (276) hide show
  1. package/README.md +1 -1
  2. package/components/genres/story/authors-note/AuthorsNote.svelte +2 -1
  3. package/components/genres/story/authors-note/AuthorsNoteWidget.svelte +177 -58
  4. package/components/shared/WidgetBoundary.svelte +37 -0
  5. package/components/shared/actions/Actions.svelte +2 -1
  6. package/components/shared/actions/ActionsWidget.svelte +31 -38
  7. package/components/shared/album/Album.svelte +2 -1
  8. package/components/shared/album/AlbumWidget.svelte +1 -7
  9. package/components/shared/annex/Annex.svelte +2 -1
  10. package/components/shared/annex/AnnexWidget.svelte +1 -1
  11. package/components/shared/attendance/Attendance.svelte +2 -1
  12. package/components/shared/attendance/AttendanceWidget.svelte +5 -8
  13. package/components/shared/backdrop/Backdrop.svelte +2 -1
  14. package/components/shared/backdrop/BackdropWidget.svelte +28 -22
  15. package/components/shared/chronicle/Chronicle.svelte +2 -1
  16. package/components/shared/chronicle/ChronicleWidget.svelte +211 -99
  17. package/components/shared/composer/Composer.svelte +25 -0
  18. package/components/shared/composer/ComposerWidget.svelte +146 -0
  19. package/components/shared/composer/composer.ts +10 -0
  20. package/components/shared/composer/settings.ts +59 -0
  21. package/components/shared/composer/target.ts +79 -0
  22. package/components/shared/dialogue-box/DialogueBoxMount.svelte +25 -0
  23. package/components/shared/dialogue-box/DialogueBoxWidget.svelte +207 -0
  24. package/components/shared/dialogue-box/dialogue-box.ts +10 -0
  25. package/components/shared/dialogue-box/settings.ts +25 -0
  26. package/components/shared/lore-entries/LoreEntries.svelte +2 -1
  27. package/components/shared/lore-entries/LoreEntriesWidget.svelte +44 -41
  28. package/components/shared/messages/MessageBlocksView.svelte +1 -1
  29. package/components/shared/messages/MessageControls.svelte +23 -5
  30. package/components/shared/messages/Messages.svelte +2 -1
  31. package/components/shared/messages/MessagesWidget.svelte +82 -191
  32. package/components/shared/messages/NextCharacterBlock.svelte +35 -20
  33. package/components/shared/messages/SceneDivider.svelte +40 -14
  34. package/components/shared/messages/SessionComposer.svelte +178 -123
  35. package/components/shared/messages/SessionContainer.svelte +89 -38
  36. package/components/shared/messages/SessionMessage.svelte +157 -54
  37. package/components/shared/messages/SpokenLine.svelte +57 -16
  38. package/components/shared/messages/StateProposalList.svelte +30 -20
  39. package/components/shared/messages/TurnLine.svelte +258 -66
  40. package/components/shared/messages/conversation.svelte.ts +83 -5
  41. package/components/shared/messages/readingPace.ts +101 -0
  42. package/components/shared/messages/rowFacts.ts +44 -0
  43. package/components/shared/messages/sceneMarks.ts +54 -0
  44. package/components/shared/messages/spokenLine.ts +63 -14
  45. package/components/shared/places/Places.svelte +2 -1
  46. package/components/shared/places/PlacesWidget.svelte +42 -33
  47. package/components/shared/routine-log/RoutineLog.svelte +2 -1
  48. package/components/shared/routine-log/RoutineLogWidget.svelte +0 -4
  49. package/components/shared/routine-log/routineLog.ts +5 -21
  50. package/components/shared/scene-portraits/ScenePortraits.svelte +2 -1
  51. package/components/shared/scene-portraits/ScenePortraitsWidget.svelte +54 -32
  52. package/components/shared/session-runs/SessionRuns.svelte +26 -0
  53. package/components/shared/session-runs/SessionRunsWidget.svelte +270 -0
  54. package/components/shared/session-runs/session-runs.ts +11 -0
  55. package/components/shared/state/PieceCard.svelte +36 -25
  56. package/components/shared/state/SlotControl.svelte +18 -5
  57. package/components/shared/stats/Stats.svelte +2 -1
  58. package/components/shared/stats/StatsWidget.svelte +104 -72
  59. package/components/shared/turn-line/TurnLineMount.svelte +25 -0
  60. package/components/shared/turn-line/TurnLineWidget.svelte +25 -0
  61. package/components/shared/turn-line/settings.ts +31 -0
  62. package/components/shared/turn-line/turn-line.ts +10 -0
  63. package/components/shared/turn-order/TurnOrder.svelte +2 -1
  64. package/components/shared/turn-order/TurnOrderWidget.svelte +1 -6
  65. package/dist/components/actions.js +71 -88
  66. package/dist/components/actions.source.json +1 -1
  67. package/dist/components/album.js +39 -44
  68. package/dist/components/album.source.json +1 -1
  69. package/dist/components/annex.js +17 -8
  70. package/dist/components/annex.source.json +1 -1
  71. package/dist/components/attendance.js +39 -48
  72. package/dist/components/attendance.source.json +1 -1
  73. package/dist/components/authors-note.js +329 -162
  74. package/dist/components/authors-note.source.json +1 -1
  75. package/dist/components/backdrop.js +52 -55
  76. package/dist/components/backdrop.source.json +1 -1
  77. package/dist/components/chronicle.js +798 -559
  78. package/dist/components/chronicle.source.json +1 -1
  79. package/dist/components/composer.js +1639 -0
  80. package/dist/components/composer.source.json +1 -0
  81. package/dist/components/core-ui.json +1 -1
  82. package/dist/components/dialogue-box.js +373 -0
  83. package/dist/components/dialogue-box.source.json +1 -0
  84. package/dist/components/lore-entries.js +134 -122
  85. package/dist/components/lore-entries.source.json +1 -1
  86. package/dist/components/messages.js +1517 -8930
  87. package/dist/components/messages.source.json +1 -1
  88. package/dist/components/places.js +267 -244
  89. package/dist/components/places.source.json +1 -1
  90. package/dist/components/routine-log.js +35 -51
  91. package/dist/components/routine-log.source.json +1 -1
  92. package/dist/components/scene-portraits.js +118 -59
  93. package/dist/components/scene-portraits.source.json +1 -1
  94. package/dist/components/session-runs.js +488 -0
  95. package/dist/components/session-runs.source.json +1 -0
  96. package/dist/components/{shared-7VDIXYAL.js → shared-47J4TNSF.js} +1 -1
  97. package/dist/components/{shared-W3XS5FEL.js → shared-5E4RQYRX.js} +3 -2
  98. package/dist/components/{shared-YDS7HYL6.js → shared-EFMMT76D.js} +57 -4
  99. package/dist/components/{shared-BIWKZFUU.js → shared-FOVKPMSK.js} +3 -3
  100. package/dist/components/{shared-JPG5DQO7.js → shared-HEAKNNZB.js} +92 -17
  101. package/dist/components/shared-JXP6SHKF.js +159 -0
  102. package/dist/components/{shared-XBDUENRA.js → shared-JXYPKSTQ.js} +1 -1
  103. package/dist/components/shared-KJIOSSE3.js +257 -0
  104. package/dist/components/{shared-WV3QTKZT.js → shared-KLURQFWI.js} +13 -9
  105. package/dist/components/shared-MHCNUDUT.js +1680 -0
  106. package/dist/components/{shared-QXF5CJVN.js → shared-NICRJ4Z2.js} +1 -1
  107. package/dist/components/{shared-BBF64YGL.js → shared-W2BBJCNE.js} +22 -16
  108. package/dist/components/shared-YYYXFDZU.js +4354 -0
  109. package/dist/components/stats.js +828 -678
  110. package/dist/components/stats.source.json +1 -1
  111. package/dist/components/turn-line.js +856 -0
  112. package/dist/components/turn-line.source.json +1 -0
  113. package/dist/components/turn-order.js +62 -67
  114. package/dist/components/turn-order.source.json +1 -1
  115. package/dist/factories/answerForm.d.ts +6 -0
  116. package/dist/factories/answerForm.js +104 -96
  117. package/dist/factories/turnOrder.d.ts +98 -105
  118. package/dist/factories/turnOrder.js +120 -136
  119. package/dist/functions/pieces.js +1 -0
  120. package/dist/functions/time.js +2 -0
  121. package/dist/genres/chat/create.js +2 -0
  122. package/dist/genres/chat/memory.js +64 -43
  123. package/dist/genres/chat/respond.d.ts +7 -6
  124. package/dist/genres/chat/respond.js +13 -4
  125. package/dist/genres/chat/turnOrder.d.ts +2 -2
  126. package/dist/genres/chat/turnOrder.js +28 -12
  127. package/dist/genres/defaults.d.ts +28 -6
  128. package/dist/genres/defaults.js +84 -26
  129. package/dist/genres/dungeon-crawler/calls.d.ts +3 -1
  130. package/dist/genres/dungeon-crawler/calls.js +5 -0
  131. package/dist/genres/dungeon-crawler/create.d.ts +9 -6
  132. package/dist/genres/dungeon-crawler/create.js +18 -8
  133. package/dist/genres/dungeon-crawler/death.d.ts +13 -6
  134. package/dist/genres/dungeon-crawler/death.js +26 -12
  135. package/dist/genres/dungeon-crawler/index.d.ts +1 -0
  136. package/dist/genres/dungeon-crawler/index.js +1 -0
  137. package/dist/genres/dungeon-crawler/journal.d.ts +1 -1
  138. package/dist/genres/dungeon-crawler/journal.js +1 -1
  139. package/dist/genres/dungeon-crawler/lore.d.ts +13 -12
  140. package/dist/genres/dungeon-crawler/lore.js +16 -25
  141. package/dist/genres/dungeon-crawler/names.d.ts +10 -3
  142. package/dist/genres/dungeon-crawler/names.js +10 -3
  143. package/dist/genres/dungeon-crawler/preamble.d.ts +5 -4
  144. package/dist/genres/dungeon-crawler/preamble.js +75 -33
  145. package/dist/genres/dungeon-crawler/respond.js +4 -2
  146. package/dist/genres/dungeon-crawler/rest.d.ts +8 -7
  147. package/dist/genres/dungeon-crawler/rest.js +39 -15
  148. package/dist/genres/dungeon-crawler/reveal.js +2 -2
  149. package/dist/genres/dungeon-crawler/roundScript.d.ts +2 -1
  150. package/dist/genres/dungeon-crawler/roundScript.js +23 -5
  151. package/dist/genres/dungeon-crawler/scripts.js +4 -5
  152. package/dist/genres/dungeon-crawler/shape.d.ts +16 -0
  153. package/dist/genres/dungeon-crawler/shape.js +5 -1
  154. package/dist/genres/dungeon-crawler/sheet.d.ts +20 -20
  155. package/dist/genres/dungeon-crawler/story.d.ts +27 -16
  156. package/dist/genres/dungeon-crawler/story.js +175 -46
  157. package/dist/genres/dungeon-crawler/storyScripts.d.ts +2 -2
  158. package/dist/genres/dungeon-crawler/storyScripts.js +109 -14
  159. package/dist/genres/dungeon-crawler/summarizeScene.d.ts +13 -0
  160. package/dist/genres/dungeon-crawler/summarizeScene.js +21 -0
  161. package/dist/genres/dungeon-crawler/turnOrder.d.ts +8 -9
  162. package/dist/genres/dungeon-crawler/turnOrder.js +33 -23
  163. package/dist/genres/guide/create.js +2 -0
  164. package/dist/genres/guide/turnOrder.d.ts +3 -3
  165. package/dist/genres/guide/turnOrder.js +29 -13
  166. package/dist/genres/lair/answerForm.js +4 -1
  167. package/dist/genres/lair/buildRoom.js +4 -3
  168. package/dist/genres/lair/castellanAction.js +160 -154
  169. package/dist/genres/lair/create.js +2 -0
  170. package/dist/genres/lair/fileCurrentRoom.js +13 -10
  171. package/dist/genres/lair/fileRoom.js +4 -3
  172. package/dist/genres/lair/keeper.js +6 -2
  173. package/dist/genres/lair/names.d.ts +2 -0
  174. package/dist/genres/lair/names.js +2 -0
  175. package/dist/genres/lair/reply.js +16 -6
  176. package/dist/genres/lair/roomAnswer.js +4 -3
  177. package/dist/genres/lair/scratchpad.js +9 -7
  178. package/dist/genres/lair/scripts.js +8 -6
  179. package/dist/genres/lair/turnOrder.d.ts +3 -2
  180. package/dist/genres/lair/turnOrder.js +45 -16
  181. package/dist/genres/story/ask.d.ts +4 -0
  182. package/dist/genres/story/ask.js +4 -0
  183. package/dist/genres/story/create.js +15 -0
  184. package/dist/genres/story/index.d.ts +1 -1
  185. package/dist/genres/story/index.js +1 -1
  186. package/dist/genres/story/narrate.js +8 -0
  187. package/dist/genres/story/narrateCharacter.js +8 -0
  188. package/dist/genres/story/reckon.d.ts +5 -19
  189. package/dist/genres/story/reckon.js +53 -40
  190. package/dist/genres/story/reckoning.js +3 -0
  191. package/dist/genres/story/respond.js +17 -28
  192. package/dist/genres/story/sweep.d.ts +1 -1
  193. package/dist/genres/story/sweep.js +1 -1
  194. package/dist/genres/story/turnOrder.d.ts +21 -3
  195. package/dist/genres/story/turnOrder.js +87 -21
  196. package/dist/index.d.ts +3 -0
  197. package/dist/index.js +23 -9
  198. package/dist/loadouts.d.ts +1 -0
  199. package/dist/loadouts.js +17 -1
  200. package/dist/primers/ninth-mile.d.ts +3 -4
  201. package/dist/registry/entries.d.ts +2 -0
  202. package/dist/registry/entries.js +18 -5
  203. package/dist/registry/genres.d.ts +146 -40
  204. package/dist/registry/genres.js +373 -101
  205. package/dist/registry/hostState.d.ts +1 -2
  206. package/dist/registry/hostState.js +2 -4
  207. package/dist/registry/layouts.d.ts +141 -111
  208. package/dist/registry/layouts.js +302 -141
  209. package/dist/registry/slots.d.ts +4 -3
  210. package/dist/registry/slots.js +4 -3
  211. package/dist/registry/widgets.d.ts +12 -2
  212. package/dist/registry/widgets.js +259 -106
  213. package/dist/rulesets/vis-itineris/ruleset.js +8 -5
  214. package/dist/rulesets/wherewithal/ruleset.js +2 -1
  215. package/dist/seed/presets.js +15 -9
  216. package/dist/seed/prompts.js +24 -5
  217. package/dist/seed/scripts.js +3 -0
  218. package/dist/shared/annexField.js +23 -3
  219. package/dist/shared/illustrateScene.d.ts +1 -0
  220. package/dist/shared/illustrateScene.js +29 -1
  221. package/dist/shared/lore.d.ts +13 -0
  222. package/dist/shared/lore.js +37 -1
  223. package/dist/shared/portrait.js +13 -4
  224. package/dist/shared/reckoning.d.ts +8 -2
  225. package/dist/shared/reckoning.js +47 -30
  226. package/dist/shared/roundTick.d.ts +20 -0
  227. package/dist/shared/roundTick.js +76 -0
  228. package/dist/shared/sceneBoundaries.d.ts +7 -0
  229. package/dist/shared/sceneBoundaries.js +62 -0
  230. package/dist/shared/sceneSummaries.d.ts +7 -0
  231. package/dist/shared/sceneSummaries.js +49 -0
  232. package/dist/shared/speakMessage.d.ts +9 -2
  233. package/dist/shared/speakMessage.js +32 -9
  234. package/dist/shared/speechFields.js +4 -0
  235. package/dist/shared/summarize/character.d.ts +1 -1
  236. package/dist/shared/summarize/history.d.ts +1 -1
  237. package/dist/shared/summarize/scene.d.ts +1 -1
  238. package/dist/shared/summarize/summarizeScene.js +1 -0
  239. package/dist/shared/summarize/summarizeSpec.d.ts +1 -1
  240. package/dist/shared/summarize/world.d.ts +1 -1
  241. package/dist/shared/ui/attendance/index.d.ts +3 -2
  242. package/dist/shared/ui/attendance/index.js +3 -7
  243. package/dist/shared/ui/chronicle/index.d.ts +24 -2
  244. package/dist/shared/ui/chronicle/index.js +58 -29
  245. package/dist/shared/ui/conversation/formAnswer.d.ts +16 -2
  246. package/dist/shared/ui/conversation/formAnswer.js +23 -9
  247. package/dist/shared/ui/conversation/index.d.ts +2 -0
  248. package/dist/shared/ui/conversation/index.js +4 -0
  249. package/dist/shared/ui/conversation/itemValues.d.ts +16 -3
  250. package/dist/shared/ui/conversation/itemValues.js +15 -5
  251. package/dist/shared/ui/conversation/messageVerbState.d.ts +17 -2
  252. package/dist/shared/ui/conversation/messageVerbState.js +5 -4
  253. package/dist/shared/ui/conversation/readingPlace.d.ts +40 -0
  254. package/dist/shared/ui/conversation/readingPlace.js +119 -0
  255. package/dist/shared/ui/conversation/rewindStrip.d.ts +13 -4
  256. package/dist/shared/ui/conversation/rewindStrip.js +29 -7
  257. package/dist/shared/ui/conversation/runsInProgress.d.ts +30 -0
  258. package/dist/shared/ui/conversation/runsInProgress.js +47 -0
  259. package/dist/shared/ui/conversation/storyDays.d.ts +7 -1
  260. package/dist/shared/ui/conversation/storyDays.js +8 -0
  261. package/dist/shared/ui/conversation/tableChannel.d.ts +8 -11
  262. package/dist/shared/ui/conversation/tableChannel.js +8 -9
  263. package/dist/shared/ui/places/index.d.ts +3 -2
  264. package/dist/shared/ui/places/index.js +4 -5
  265. package/dist/shared/ui/routine-log/index.d.ts +3 -0
  266. package/dist/shared/ui/routine-log/index.js +22 -0
  267. package/dist/shared/ui/scene-portraits/portraits.d.ts +50 -16
  268. package/dist/shared/ui/scene-portraits/portraits.js +84 -21
  269. package/dist/shared/ui/session-runs/index.d.ts +90 -0
  270. package/dist/shared/ui/session-runs/index.js +143 -0
  271. package/dist/shared/ui/session-state/stateView.d.ts +18 -5
  272. package/dist/shared/ui/session-state/stateView.js +29 -8
  273. package/dist/shared/ui/turn-order/index.d.ts +0 -9
  274. package/dist/shared/ui/turn-order/index.js +1 -2
  275. package/package.json +12 -8
  276. /package/dist/components/{shared-4ME6NFDK.js → shared-LUIF6DW7.js} +0 -0
@@ -0,0 +1,1680 @@
1
+ import {
2
+ defineVerdict,
3
+ setStatusTextResolver,
4
+ statusTextIn
5
+ } from "./shared-W2BBJCNE.js";
6
+ import {
7
+ UNCLAIMED_LINE_NAME,
8
+ actionsOf,
9
+ effectsOf,
10
+ worldActionCrossing
11
+ } from "./shared-NICRJ4Z2.js";
12
+ import {
13
+ formatStoryTime
14
+ } from "./shared-EFMMT76D.js";
15
+ import {
16
+ SvelteMap,
17
+ SvelteSet,
18
+ formatChannel,
19
+ get,
20
+ getContext,
21
+ parseChannel,
22
+ proxy,
23
+ set,
24
+ setContext,
25
+ state,
26
+ tick,
27
+ untrack,
28
+ useWidgetContext,
29
+ user_derived,
30
+ user_effect
31
+ } from "./shared-HEAKNNZB.js";
32
+
33
+ // ../sdk/dist/messageBlocks.js
34
+ var MESSAGE_BLOCK_LIMITS = {
35
+ maxBlocks: 64,
36
+ maxDepth: 3,
37
+ maxText: 64 * 1024,
38
+ maxRows: 64,
39
+ maxActions: 12
40
+ };
41
+ function formBlocksOf(blocks) {
42
+ const out = [];
43
+ const walk = (list) => {
44
+ for (const b of list) {
45
+ if (b.kind === "choices" || b.kind === "form" || b.kind === "roll")
46
+ out.push(b);
47
+ else if (b.kind === "group")
48
+ walk(b.blocks);
49
+ }
50
+ };
51
+ walk(blocks);
52
+ return out;
53
+ }
54
+ var isOwnerAddressed = (addressee) => addressee === "owner";
55
+ function worldBlockFunctions(blocks, spec) {
56
+ const world = new Set(actionsOf(spec).filter((a) => effectsOf(a) === "world").map((a) => a.key));
57
+ const fns = /* @__PURE__ */ new Set();
58
+ for (const b of formBlocksOf(blocks)) {
59
+ if (isOwnerAddressed(b.addressee))
60
+ continue;
61
+ if (b.kind === "choices") {
62
+ for (const a of b.actions)
63
+ if (world.has(a.fn))
64
+ fns.add(a.fn);
65
+ } else if (world.has(b.fn))
66
+ fns.add(b.fn);
67
+ }
68
+ return [...fns];
69
+ }
70
+ var worldBlockSentence = (named) => `the blocks name ${named}, whose action changes something outside the story (effects: 'world'). Such an action is the owner's, from the composer or the review gate \u2014 the one block that may carry it is one addressed to 'owner' (the effects line, R-15)`;
71
+ var effectsLineVerdict = defineVerdict({
72
+ id: "core:verdict/effects-line",
73
+ law: "F41",
74
+ doors: ["construction", "validate", "publish", "write", "fire"],
75
+ judge(input) {
76
+ switch (input.kind) {
77
+ case "venue":
78
+ case "actor":
79
+ return worldActionCrossing(input);
80
+ case "block": {
81
+ const world = worldBlockFunctions(input.blocks, input.spec);
82
+ if (!world.length)
83
+ return { ok: true };
84
+ return { ok: false, sentence: worldBlockSentence(world.map((f) => `'${f}'`).join(", ")) };
85
+ }
86
+ case "identity": {
87
+ const ownersOnly = input.addressees.length > 0 && input.addressees.every(isOwnerAddressed);
88
+ if (input.effects !== "world" || ownersOnly)
89
+ return { ok: true };
90
+ return { ok: false, sentence: worldBlockSentence(`'${input.identity}'`) };
91
+ }
92
+ case "press": {
93
+ if (input.effects !== "world")
94
+ return { ok: true };
95
+ if (!input.as && !(input.onBlock && !isOwnerAddressed(input.blockAddressee)))
96
+ return { ok: true };
97
+ return {
98
+ ok: false,
99
+ sentence: `'${input.name}' changes something outside the story, so it is the owner's to invoke from the composer, or from a question put to them \u2014 never a question put to anybody else.`
100
+ };
101
+ }
102
+ default:
103
+ return {
104
+ ok: false,
105
+ sentence: `'${String(input.kind)}' is not a shape this verdict judges \u2014 one of 'venue', 'actor', 'block', 'identity', 'press'.`
106
+ };
107
+ }
108
+ },
109
+ failing: (door) => door === "write" ? {
110
+ kind: "block",
111
+ blocks: [
112
+ {
113
+ kind: "choices",
114
+ question: "Give them the keys?",
115
+ actions: [{ fn: "grant", label: "Yes", choice: "yes" }]
116
+ }
117
+ ],
118
+ spec: {
119
+ id: "conformance:spec/world-in-composer",
120
+ contributes: {
121
+ actions: [
122
+ {
123
+ key: "grant",
124
+ genre: "core:genre/chat",
125
+ venue: { kind: "composer" },
126
+ label: { en: "Grant" },
127
+ description: { en: "Grant a permission outside the story." },
128
+ effects: "world"
129
+ }
130
+ ]
131
+ }
132
+ }
133
+ } : door === "fire" ? { kind: "press", name: "Grant", effects: "world", as: true, onBlock: false, blockAddressee: void 0 } : { kind: "venue", where: "contributes.actions[grant]", effects: "world", venue: "widget" }
134
+ });
135
+ var isChannelHead = (v) => typeof v === "number" && Number.isInteger(v) && v > 0;
136
+ function isFormStale(block, headNow) {
137
+ if (block.answered)
138
+ return false;
139
+ if (!isChannelHead(block.head))
140
+ return false;
141
+ if (headNow == null)
142
+ return false;
143
+ return headNow > block.head;
144
+ }
145
+ var stalenessVerdict = defineVerdict({
146
+ id: "core:verdict/staleness",
147
+ law: "U5f",
148
+ doors: ["fire", "list"],
149
+ judge({ block, headNow }) {
150
+ if (!isFormStale(block, headNow))
151
+ return { ok: true };
152
+ return {
153
+ ok: false,
154
+ sentence: "That question was overtaken \u2014 the conversation moved on before it was answered."
155
+ };
156
+ },
157
+ failing: () => ({ block: { head: 3 }, headNow: 4 })
158
+ });
159
+
160
+ // ../sdk/dist/composerStates.js
161
+ var COMPOSER_STATE_ANY = "*";
162
+ function composerStateChannel(channel) {
163
+ if (typeof channel === "string" && channel.trim() === COMPOSER_STATE_ANY)
164
+ return COMPOSER_STATE_ANY;
165
+ return formatChannel(parseChannel(channel));
166
+ }
167
+ function composerClosedOn(closed, lane) {
168
+ if (!closed)
169
+ return void 0;
170
+ return closed[composerStateChannel(lane)] ?? closed[COMPOSER_STATE_ANY];
171
+ }
172
+ var COMPOSER_CLOSED_NO_REASON = "You can't send here yet.";
173
+ function composerClosedPlaceholder(closure) {
174
+ const reason = closure?.reason?.trim();
175
+ if (reason && closure?.waits === false)
176
+ return reason;
177
+ return reason ? `Waiting: ${reason}` : COMPOSER_CLOSED_NO_REASON;
178
+ }
179
+
180
+ // dist/shared/ui/conversation/dossier.js
181
+ var NO_LINE = {
182
+ controllable: false,
183
+ speaker: { name: UNCLAIMED_LINE_NAME.en, ref: null, face: null, sprite: null },
184
+ swipes: { show: false, right: false },
185
+ embedding: "hidden"
186
+ };
187
+
188
+ // dist/shared/ui/conversation/formAnswer.js
189
+ var rowId = (text) => {
190
+ if (!/^\d{1,10}$/.test(text))
191
+ return null;
192
+ const n = Number(text);
193
+ return Number.isSafeInteger(n) && n > 0 ? n : null;
194
+ };
195
+ function canAnswerForm(addressee, viewer, session) {
196
+ if (!addressee)
197
+ return true;
198
+ if (viewer.userId == null)
199
+ return false;
200
+ const cut = addressee.indexOf(":");
201
+ const kind = cut === -1 ? addressee : addressee.slice(0, cut);
202
+ const rest = cut === -1 ? "" : addressee.slice(cut + 1);
203
+ switch (kind) {
204
+ case "character":
205
+ case "seated-member": {
206
+ const id = rowId(rest);
207
+ if (id === null)
208
+ return viewer.isOwner;
209
+ const named = (row) => row.ref === addressee || kind === "seated-member" && row.castMemberId === id;
210
+ const presence = (session?.sessionPersonas ?? []).find((p) => !!p && (p.ref != null ? named(p) : kind === "character" && p.personaId === id));
211
+ if (presence)
212
+ return presence.persona?.userId === viewer.userId;
213
+ const seated = (session?.sessionCharacters ?? []).some((c) => !!c && (c.ref != null ? named(c) : kind === "character" && c.characterId === id));
214
+ return seated ? false : viewer.isOwner;
215
+ }
216
+ case "player-seat": {
217
+ const id = rowId(rest);
218
+ const rows = session?.sessionPersonas ?? [];
219
+ const seat = id === null ? void 0 : rows.find((p) => p?.id === id);
220
+ const sits = seat?.userId ?? seat?.persona?.userId;
221
+ return sits != null && sits === viewer.userId;
222
+ }
223
+ case "envoy":
224
+ return false;
225
+ case "user":
226
+ return rowId(rest) === viewer.userId;
227
+ case "owner":
228
+ return viewer.isOwner;
229
+ case "admin":
230
+ return viewer.isAdmin === true;
231
+ case "participant":
232
+ case "run-owner":
233
+ return true;
234
+ default:
235
+ return false;
236
+ }
237
+ }
238
+ function answeredChoiceLabel(block, answered) {
239
+ if (block.kind !== "choices" || answered.choice === void 0)
240
+ return null;
241
+ const option = (block.actions ?? []).find((o) => o.choice === answered.choice);
242
+ return option?.label ?? answered.choice;
243
+ }
244
+ function channelHeadOf(messages, channel) {
245
+ let head = null;
246
+ for (const m of messages) {
247
+ if (!m || (m.channel ?? "main") !== channel)
248
+ continue;
249
+ if (head === null || m.id > head)
250
+ head = m.id;
251
+ }
252
+ return head;
253
+ }
254
+ function stalenessHeadOf(messages, channel, rowId2) {
255
+ return channelHeadOf(messages.filter((m) => m?.metadata?.answersForm?.messageId !== rowId2 && m?.metadata?.tableLine !== true), channel);
256
+ }
257
+ function staleOf(block, row, messages) {
258
+ const headNow = stalenessHeadOf(messages, row.channel ?? "main", row.id);
259
+ return !stalenessVerdict.judge({ block, headNow }).ok;
260
+ }
261
+ function answeredOf(block) {
262
+ const a = block?.answered;
263
+ if (!a || typeof a !== "object" || typeof a.by !== "string" || typeof a.at !== "string")
264
+ return null;
265
+ return {
266
+ by: a.by,
267
+ at: a.at,
268
+ ...typeof a.choice === "string" ? { choice: a.choice } : {},
269
+ ...typeof a.value === "string" && a.value ? { value: a.value } : {}
270
+ };
271
+ }
272
+
273
+ // dist/shared/ui/conversation/messageOrder.js
274
+ function orderedMessages(messages, order) {
275
+ return order === "newest-first" ? [...messages].reverse() : messages;
276
+ }
277
+ function conversationIndex(row, total, order) {
278
+ return order === "newest-first" ? total - 1 - row : row;
279
+ }
280
+
281
+ // dist/shared/ui/conversation/messageSpeaker.js
282
+ function messageEnvoySlug(msg) {
283
+ const ref = msg.metadata?.speaker;
284
+ return typeof ref === "string" && ref.startsWith("envoy:") ? ref.slice("envoy:".length) : null;
285
+ }
286
+
287
+ // dist/shared/ui/conversation/composerTray.js
288
+ var ATTACHMENT_KINDS_V1 = ["image", "text", "pdf", "audio", "video"];
289
+ var KIND_PLURAL = {
290
+ image: "images",
291
+ text: "text files",
292
+ pdf: "PDFs",
293
+ audio: "audio files",
294
+ video: "videos"
295
+ };
296
+ var KIND_NAME = {
297
+ image: "Images",
298
+ text: "Text files",
299
+ pdf: "PDFs",
300
+ audio: "Audio",
301
+ video: "Video"
302
+ };
303
+ var KIND_ONE = {
304
+ image: "An image",
305
+ text: "A text file",
306
+ pdf: "A PDF",
307
+ audio: "An audio file",
308
+ video: "A video"
309
+ };
310
+ var KIND_FORMATS = {
311
+ image: "PNG, JPEG, WebP, GIF",
312
+ text: ".txt, .md",
313
+ pdf: ".pdf",
314
+ audio: "MP3, WAV, OGG, FLAC, M4A",
315
+ video: "MP4, WebM, MOV"
316
+ };
317
+ function kindList(kinds) {
318
+ return ATTACHMENT_KINDS_V1.filter((k) => kinds.includes(k)).map((k) => KIND_PLURAL[k]).join(" \xB7 ");
319
+ }
320
+ function readableKinds(readers) {
321
+ if (!readers)
322
+ return [];
323
+ return ATTACHMENT_KINDS_V1.filter((k) => readers.kinds[k]?.allowed);
324
+ }
325
+ function readersSummary(readers) {
326
+ if (!readers)
327
+ return null;
328
+ const kinds = readableKinds(readers);
329
+ if (!kinds.length)
330
+ return "This reply reads no attachments.";
331
+ return `${readers.calls.length > 1 ? "Can read" : "This reply can read"}: ${kindList(kinds)}`;
332
+ }
333
+ function readerCallLines(readers) {
334
+ if (!readers)
335
+ return [];
336
+ return readers.calls.map((c) => {
337
+ const who = c.model ? `${c.label} (${c.model})` : c.label;
338
+ const reads = ATTACHMENT_KINDS_V1.filter((k) => c.reads.includes(k)).map((k) => KIND_PLURAL[k]);
339
+ const heard = c.transcribes ?? [];
340
+ const named = ATTACHMENT_KINDS_V1.filter((k) => c.placeholderFor.includes(k) && !heard.includes(k)).map((k) => KIND_PLURAL[k]);
341
+ const words = ATTACHMENT_KINDS_V1.filter((k) => heard.includes(k)).map((k) => KIND_PLURAL[k]);
342
+ return `${who}: ${reads.join(", ") || "nothing"}` + (named.length ? ` (${named.join(" and ")} appear to it as a name)` : "") + (words.length ? ` (${words.join(" and ")} reach it as what they say)` : "");
343
+ });
344
+ }
345
+ var MiB = 1024 * 1024;
346
+ var formatCap = (bytes) => `${Math.round(bytes / MiB)} MB`;
347
+ var SVG_REFUSAL = "An SVG can't be attached. Attach an image (PNG, JPEG, WebP, GIF), a text file (.txt, .md), a PDF or an audio file.";
348
+ var TYPE_REFUSAL = "That file type can't be attached. Attach an image (PNG, JPEG, WebP, GIF), a text file (.txt, .md), a PDF or an audio file (MP3, WAV, OGG, FLAC, M4A).";
349
+ var startsWith = (head, sig, at = 0) => sig.every((b, i) => head[at + i] === b);
350
+ function sniffAttachmentKind(head, filename, type = "") {
351
+ if (startsWith(head, [137, 80, 78, 71]))
352
+ return "image";
353
+ if (startsWith(head, [255, 216, 255]))
354
+ return "image";
355
+ if (startsWith(head, [71, 73, 70, 56]))
356
+ return "image";
357
+ if (startsWith(head, [82, 73, 70, 70]) && startsWith(head, [87, 69, 66, 80], 8))
358
+ return "image";
359
+ if (startsWith(head, [37, 80, 68, 70]))
360
+ return "pdf";
361
+ if (startsWith(head, [82, 73, 70, 70]) && startsWith(head, [87, 65, 86, 69], 8))
362
+ return "audio";
363
+ if (startsWith(head, [73, 68, 51]))
364
+ return "audio";
365
+ if (head[0] === 255 && ((head[1] ?? 0) & 224) === 224)
366
+ return "audio";
367
+ if (startsWith(head, [79, 103, 103, 83]))
368
+ return /\.ogv$/i.test(filename) || type === "video/ogg" ? "video" : "audio";
369
+ if (startsWith(head, [102, 76, 97, 67]))
370
+ return "audio";
371
+ if (startsWith(head, [102, 116, 121, 112], 4))
372
+ return startsWith(head, [77, 52, 65], 8) ? "audio" : "video";
373
+ if (startsWith(head, [26, 69, 223, 163]))
374
+ return /\.weba$/i.test(filename) || type.startsWith("audio/") ? "audio" : "video";
375
+ if (/\.svgz?$/i.test(filename) || type === "image/svg+xml")
376
+ return "svg";
377
+ const textual = /\.(txt|md|markdown)$/i.test(filename) || type === "text/plain" || type === "text/markdown";
378
+ if (!textual)
379
+ return null;
380
+ for (const b of head)
381
+ if (b === 0 || b < 9 || b > 13 && b < 32 && b !== 27)
382
+ return null;
383
+ const start = new TextDecoder("utf-8", { fatal: false }).decode(head.subarray(0, 512)).trimStart();
384
+ if (/^(<\?xml[^>]*>\s*)?(<!--[\s\S]*?-->\s*)*(<!DOCTYPE[^>]*>\s*)?<svg[\s>/]/i.test(start))
385
+ return "svg";
386
+ return "text";
387
+ }
388
+ function preCheckFiles(files, tray, readers) {
389
+ const accept = [];
390
+ const refusals = [];
391
+ const cap = readers?.filesPerMessage ?? 10;
392
+ let room = cap - tray.filter((t) => t.status !== "refused").length;
393
+ files.forEach((f, i) => {
394
+ const refuse = (reason) => refusals.push({ filename: f.name, reason });
395
+ if (f.kind === "svg")
396
+ return refuse(SVG_REFUSAL);
397
+ if (!f.kind)
398
+ return refuse(TYPE_REFUSAL);
399
+ const verdict = readers?.kinds[f.kind];
400
+ if (readers && !verdict?.allowed)
401
+ return refuse(verdict?.reason ?? `Nothing in this reply reads ${KIND_PLURAL[f.kind]}.`);
402
+ if (f.size <= 0)
403
+ return refuse("That file is empty.");
404
+ const limit = readers?.bytesPerKind[f.kind];
405
+ if (limit && f.size > limit)
406
+ return refuse(`${KIND_ONE[f.kind]} can be at most ${formatCap(limit)}.`);
407
+ if (room <= 0)
408
+ return refuse(`A message can carry at most ${cap} files.`);
409
+ room--;
410
+ accept.push(i);
411
+ });
412
+ return { accept, refusals };
413
+ }
414
+ function uploadingNote(tray) {
415
+ const live = tray.filter((t) => t.status !== "refused");
416
+ const uploading = live.filter((t) => t.status === "uploading").length;
417
+ return uploading ? `Uploading ${uploading} of ${live.length}\u2026` : null;
418
+ }
419
+ function sendableTrayIds(tray) {
420
+ return tray.filter((t) => t.status === "ready").map((t) => t.id);
421
+ }
422
+
423
+ // dist/shared/ui/conversation/storyDays.js
424
+ function storyDayText(day, calendar) {
425
+ const t = { year: Math.trunc(day.year) };
426
+ if (typeof day.month === "number" && day.month) {
427
+ t.month = day.month;
428
+ if (typeof day.day === "number" && day.day)
429
+ t.day = day.day;
430
+ }
431
+ return formatStoryTime(t, calendar ?? null);
432
+ }
433
+ function storyTimeText(time, calendar) {
434
+ return formatStoryTime(time, calendar ?? null);
435
+ }
436
+ var storyDayLabelIn = (calendar) => (day) => storyDayText(day, calendar);
437
+
438
+ // dist/shared/ui/conversation/channelLanes.js
439
+ var NO_LANE_CHANNEL = "\0no-lane";
440
+ function isNoLaneChannel(listed) {
441
+ return listed === NO_LANE_CHANNEL;
442
+ }
443
+ function rowOnListedChannels(listed, rowChannel) {
444
+ const row = parseChannel(typeof rowChannel === "string" && rowChannel ? rowChannel : "main");
445
+ for (const entry of listed) {
446
+ if (isNoLaneChannel(entry))
447
+ continue;
448
+ const ref = parseChannel(entry);
449
+ if (ref.slug !== row.slug)
450
+ continue;
451
+ if (!ref.explicit || ref.lane === row.lane)
452
+ return true;
453
+ }
454
+ return false;
455
+ }
456
+ function canonicalListedChannel(listed) {
457
+ return isNoLaneChannel(listed) ? listed : formatChannel(parseChannel(listed));
458
+ }
459
+
460
+ // dist/shared/ui/conversation/channelTabs.js
461
+ function channelTabsOf(listed) {
462
+ if (!listed)
463
+ return [];
464
+ const out = [];
465
+ for (const entry of listed) {
466
+ if (isNoLaneChannel(entry))
467
+ continue;
468
+ const slug = canonicalListedChannel(entry);
469
+ if (!out.includes(slug))
470
+ out.push(slug);
471
+ }
472
+ return out.length > 1 ? out : [];
473
+ }
474
+ function newestNewsOn(rows, tab, viewerId) {
475
+ const shown = parseChannel(tab);
476
+ let newest = 0;
477
+ for (const m of rows) {
478
+ if (m.isHidden || m.isGenerating)
479
+ continue;
480
+ const at = parseChannel(typeof m.channel === "string" && m.channel ? m.channel : "main");
481
+ if (at.slug !== shown.slug)
482
+ continue;
483
+ if (shown.explicit && at.lane !== shown.lane)
484
+ continue;
485
+ if (viewerId != null && m.userId === viewerId && (m.role ?? "user") === "user")
486
+ continue;
487
+ if (m.id > newest)
488
+ newest = m.id;
489
+ }
490
+ return newest;
491
+ }
492
+ function channelTabDots(tabs, active, rows, viewerId, seen) {
493
+ const out = /* @__PURE__ */ new Set();
494
+ for (const tab of tabs) {
495
+ if (tab === active)
496
+ continue;
497
+ const last = seen.get(tab);
498
+ if (last !== void 0 && newestNewsOn(rows, tab, viewerId) > last)
499
+ out.add(tab);
500
+ }
501
+ return out;
502
+ }
503
+
504
+ // dist/shared/ui/conversation/diceLine.js
505
+ var DICE_KINDS = /* @__PURE__ */ new Set(["roll", "dice"]);
506
+ function holdsDice(blocks, depth = 0) {
507
+ if (!Array.isArray(blocks) || depth > 3)
508
+ return false;
509
+ for (const b of blocks) {
510
+ if (!b || typeof b !== "object")
511
+ continue;
512
+ if (typeof b.kind === "string" && DICE_KINDS.has(b.kind))
513
+ return true;
514
+ if (b.kind === "group" && holdsDice(b.blocks, depth + 1))
515
+ return true;
516
+ }
517
+ return false;
518
+ }
519
+ var blockTreesOf = (row) => (row?.parts ?? []).map((p) => p?.data?.blocks).filter((b) => Array.isArray(b));
520
+ function blockById(blocks, id, depth = 0) {
521
+ if (!Array.isArray(blocks) || depth > 3)
522
+ return null;
523
+ for (const b of blocks) {
524
+ if (!b || typeof b !== "object")
525
+ continue;
526
+ if (b.id === id)
527
+ return b;
528
+ if (b.kind === "group") {
529
+ const inner = blockById(b.blocks, id, depth + 1);
530
+ if (inner)
531
+ return inner;
532
+ }
533
+ }
534
+ return null;
535
+ }
536
+ function isDiceLine(row, messages = []) {
537
+ if (!row)
538
+ return false;
539
+ if (blockTreesOf(row).some((tree) => holdsDice(tree)))
540
+ return true;
541
+ const answers = row.metadata?.answersForm;
542
+ const askedOn = Number(answers?.messageId);
543
+ const blockId = typeof answers?.blockId === "string" ? answers.blockId : null;
544
+ if (!Number.isSafeInteger(askedOn) || !blockId)
545
+ return false;
546
+ const asked = messages.find((m) => m?.id === askedOn);
547
+ return blockTreesOf(asked).some((tree) => blockById(tree, blockId)?.kind === "roll");
548
+ }
549
+
550
+ // dist/shared/ui/conversation/rewindStrip.js
551
+ var REWIND_STRIP_REASONS = Object.freeze({
552
+ notOwner: "Only the session's owner can go back or forward.",
553
+ generating: "Wait for the reply to finish."
554
+ });
555
+ var turnsAheadText = (n, step = "turn") => n > 0 ? `${n} ${step === "message" ? n === 1 ? "message" : "messages" : n === 1 ? "turn" : "turns"} ahead` : "";
556
+ var backTakesText = (t) => {
557
+ const whole2 = (v) => Math.max(0, Math.trunc(v ?? 0) || 0);
558
+ const m = t.newestMessage;
559
+ if (m) {
560
+ const filed = whole2(m.filed);
561
+ const head2 = m.yours ? "your line" : `the newest message${m.author ? ` (${m.author})` : ""}`;
562
+ return filed > 0 ? `${head2} and ${filed} ${filed === 1 ? "line" : "lines"} filed on it` : head2;
563
+ }
564
+ const lines = whole2(t.personLines);
565
+ const head = lines >= 2 ? `${lines} lines` : "your line";
566
+ const n = whole2(t.count);
567
+ if (n === 0)
568
+ return head;
569
+ const names = t.names.length ? ` (${t.names.join(", ")})` : "";
570
+ return `${head} and ${n} ${n === 1 ? "reply" : "replies"}${names}`;
571
+ };
572
+ function rewindStripState(input) {
573
+ const r = input.rewind;
574
+ const ahead = r && r.ahead > 0 ? Math.trunc(r.ahead) : 0;
575
+ const step = r?.step === "message" ? "message" : "turn";
576
+ const press = (serverReason, waitFor) => {
577
+ const reason = !input.isOwner ? REWIND_STRIP_REASONS.notOwner : input.generating ? REWIND_STRIP_REASONS.generating : waitFor || serverReason || void 0;
578
+ return reason ? { disabled: true, reason } : { disabled: false };
579
+ };
580
+ const back = press(r?.back, input.waitFor);
581
+ if (!back.disabled && r?.backTakes)
582
+ back.takes = backTakesText(r.backTakes);
583
+ return {
584
+ shown: !!r && input.story && input.isOwner,
585
+ back,
586
+ forward: press(r?.forward),
587
+ ahead,
588
+ aheadText: turnsAheadText(ahead, step),
589
+ replaceText: r && ahead > 0 && input.story ? `${turnsAheadText(ahead, step)} will be replaced if you write now.` : null,
590
+ step
591
+ };
592
+ }
593
+
594
+ // dist/shared/ui/conversation/runsInProgress.js
595
+ var RUN_WAITING_FOR_REVIEW = "waiting for review";
596
+ function runItemWords(run) {
597
+ const words = [];
598
+ const status = run.status?.trim();
599
+ if (status)
600
+ words.push(status);
601
+ if (run.parked)
602
+ words.push(RUN_WAITING_FOR_REVIEW);
603
+ const speaker = run.readsReplyOf?.trim();
604
+ if (speaker)
605
+ words.push(`reading ${speaker}'s reply`);
606
+ return words;
607
+ }
608
+ function runElapsedWords(since, now) {
609
+ if (since === void 0 || !Number.isFinite(since))
610
+ return "";
611
+ const s = Math.max(0, Math.floor((now - since) / 1e3));
612
+ if (s < 60)
613
+ return `${s} s`;
614
+ const min = Math.floor(s / 60);
615
+ if (min < 60)
616
+ return `${min} min`;
617
+ const h = Math.floor(min / 60);
618
+ const m = min % 60;
619
+ return m ? `${h} h ${m} min` : `${h} h`;
620
+ }
621
+ var RUNS_SHOWN_BEFORE_COUNT = 3;
622
+ var runTickMs = (reducedMotion) => reducedMotion ? 6e4 : 1e3;
623
+
624
+ // dist/shared/ui/conversation/readingPlace.js
625
+ function isReadLine(row) {
626
+ const md = row.metadata && typeof row.metadata === "object" ? row.metadata : {};
627
+ if (md.tableLine === true)
628
+ return false;
629
+ if (md.anchorMessageId != null)
630
+ return false;
631
+ if (row.role === "system")
632
+ return false;
633
+ if (row.isGenerating)
634
+ return true;
635
+ if (row.isNarratorResponse)
636
+ return true;
637
+ if (row.characterId != null)
638
+ return true;
639
+ if (row.personaId != null)
640
+ return true;
641
+ if (row.castMemberId != null)
642
+ return true;
643
+ if (typeof md.speaker === "string" && md.speaker.startsWith("envoy:"))
644
+ return true;
645
+ return row.role === "user";
646
+ }
647
+ function pass(rows, index, ownId) {
648
+ let i = index;
649
+ while (i < rows.length - 1 && (rows[i].id === ownId || !isReadLine(rows[i])))
650
+ i++;
651
+ return i;
652
+ }
653
+ function settlePlace(rows, place, ownId) {
654
+ if (rows.length === 0)
655
+ return null;
656
+ const newest = rows.length - 1;
657
+ let index;
658
+ if (place === null) {
659
+ index = newest;
660
+ } else {
661
+ index = rows.findIndex((r) => r.id === place);
662
+ if (index < 0) {
663
+ index = -1;
664
+ for (let i = 0; i < rows.length; i++)
665
+ if (rows[i].id <= place)
666
+ index = i;
667
+ if (index < 0)
668
+ index = newest;
669
+ }
670
+ if (ownId != null && ownId > rows[index].id) {
671
+ const own = rows.findIndex((r) => r.id === ownId);
672
+ if (own >= 0)
673
+ index = own;
674
+ }
675
+ }
676
+ return rows[pass(rows, index, ownId)].id;
677
+ }
678
+ function nextLinePlace(rows, place, ownId) {
679
+ const index = place === null ? -1 : rows.findIndex((r) => r.id === place);
680
+ if (index < 0)
681
+ return settlePlace(rows, place, ownId);
682
+ if (index >= rows.length - 1)
683
+ return place;
684
+ return rows[pass(rows, index + 1, ownId)].id;
685
+ }
686
+ function queuedSummary(rows, place, nameOf) {
687
+ const none = { lines: 0, repliedBy: [], writing: null };
688
+ if (place === null)
689
+ return none;
690
+ const after = rows.filter((r) => r.id > place && isReadLine(r));
691
+ const writingRow = after.find((r) => r.isGenerating);
692
+ const finished = after.filter((r) => !r.isGenerating);
693
+ const names = [];
694
+ let nameless = false;
695
+ for (const r of finished) {
696
+ const n = nameOf(r);
697
+ if (!n)
698
+ nameless = true;
699
+ else if (!names.includes(n))
700
+ names.push(n);
701
+ }
702
+ return {
703
+ lines: finished.length,
704
+ repliedBy: nameless ? [] : names,
705
+ writing: writingRow ? nameOf(writingRow) ?? "" : null
706
+ };
707
+ }
708
+ function queuedText(summary) {
709
+ const parts = [];
710
+ const { lines, repliedBy, writing } = summary;
711
+ if (lines > 0) {
712
+ if (repliedBy.length > 0 && lines <= 2 && repliedBy.length === lines) {
713
+ parts.push(repliedBy.length === 1 ? `${repliedBy[0]} has replied` : `${repliedBy[0]} and ${repliedBy[1]} have replied`);
714
+ } else {
715
+ parts.push(lines === 1 ? "1 more line" : `${lines} more lines`);
716
+ }
717
+ }
718
+ if (writing !== null)
719
+ parts.push(writing === "" ? "Writing\u2026" : `${writing} is writing\u2026`);
720
+ return parts.length ? parts.join(" \xB7 ") : null;
721
+ }
722
+
723
+ // components/shared/composer/target.ts
724
+ var str = (v) => typeof v === "string" && v !== "";
725
+ function composerTargetOf(dossier) {
726
+ const composer = dossier?.composer;
727
+ const t = composer?.target;
728
+ const w = composer?.writingTo;
729
+ const target = t && str(t.instance) && str(t.channel) ? {
730
+ instance: t.instance,
731
+ channel: t.channel,
732
+ label: typeof t.label === "string" ? t.label : t.channel,
733
+ ...t.lineWidth === "column" || t.lineWidth === "full" || t.lineWidth === "comfortable" ? { lineWidth: t.lineWidth } : {},
734
+ ...t.presentation === "rows" || t.presentation === "folio" ? { presentation: t.presentation } : {}
735
+ } : null;
736
+ const writingTo = w && str(w.channel) ? { channel: w.channel, label: typeof w.label === "string" && w.label ? w.label : w.channel } : null;
737
+ return { target, writingTo };
738
+ }
739
+ function composerSendShownOf(dossier) {
740
+ return dossier?.composer?.sendShown;
741
+ }
742
+ function composerSendShown(setting, tier) {
743
+ return tier === "compact" || setting !== false;
744
+ }
745
+
746
+ // components/shared/messages/sceneMarks.ts
747
+ var SCENE_SWATCH_COUNT = 8;
748
+ function laneOf(channel) {
749
+ const raw = typeof channel === "string" && channel.trim() ? channel.trim() : "main";
750
+ const at = raw.indexOf(":");
751
+ if (at < 0) return raw;
752
+ const lane = raw.slice(at + 1);
753
+ return lane === "1" ? raw.slice(0, at) : raw;
754
+ }
755
+ var isLiveScene = (s) => typeof s.openedAtMessageId === "number";
756
+ var isOpenScene = (s) => isLiveScene(s) && s.closedAtMessageId == null;
757
+ function sceneStartOf(s) {
758
+ if (isLiveScene(s)) return s.openedAtMessageId;
759
+ const ids = s.selectedMessageIds ?? [];
760
+ return ids.length ? Math.min(...ids) : Number.POSITIVE_INFINITY;
761
+ }
762
+ function sceneSwatches(scenes) {
763
+ const out = /* @__PURE__ */ new Map();
764
+ [...scenes].sort((a, b) => sceneStartOf(a) - sceneStartOf(b) || a.id - b.id).forEach((s, i) => out.set(s.id, i % SCENE_SWATCH_COUNT));
765
+ return out;
766
+ }
767
+ function liveSceneHolds(s, row) {
768
+ if (!isLiveScene(s)) return false;
769
+ if (laneOf(row.channel) !== laneOf(s.channel)) return false;
770
+ if (row.id < s.openedAtMessageId) return false;
771
+ return s.closedAtMessageId == null || row.id <= s.closedAtMessageId;
772
+ }
773
+ var whole = (v) => typeof v === "number" && Number.isInteger(v) ? v : null;
774
+ function storyDayOfRow(row) {
775
+ const year = whole(row.storyClockYear);
776
+ if (year === null) return null;
777
+ const month = whole(row.storyClockMonth);
778
+ return { year, month, day: month === null ? null : whole(row.storyClockDay) };
779
+ }
780
+ function storyTimeOfRow(row) {
781
+ const day = storyDayOfRow(row);
782
+ if (day === null) return null;
783
+ const hour = whole(row.storyClockHour);
784
+ const out = { year: day.year };
785
+ if (day.month != null) out.month = day.month;
786
+ if (day.day != null) out.day = day.day;
787
+ if (hour !== null) {
788
+ out.hour = hour;
789
+ out.minute = whole(row.storyClockMinute) ?? 0;
790
+ }
791
+ return out;
792
+ }
793
+ function messageStoryTime(row, spell, timeFormat) {
794
+ const t = storyTimeOfRow(row);
795
+ if (t === null) return null;
796
+ const full = spell.full(t);
797
+ const formatted = timeFormat && timeFormat.trim() ? spell.as(t, timeFormat) : null;
798
+ if (formatted) return { text: formatted, full };
799
+ if (t.hour != null) {
800
+ const pad = (n) => String(n).padStart(2, "0");
801
+ return { text: `${pad(t.hour)}:${pad(t.minute ?? 0)}`, full };
802
+ }
803
+ return { text: spell.day(t), full };
804
+ }
805
+ function sameStoryDay(a, b) {
806
+ return a.year === b.year && (a.month ?? null) === (b.month ?? null) && (a.day ?? null) === (b.day ?? null);
807
+ }
808
+ function storyDayLabel(t) {
809
+ let out = `Year ${Math.trunc(t.year)}`;
810
+ if (t.month) out += `, Mo. ${t.month}`;
811
+ if (t.month && t.day) out += `, Day ${t.day}`;
812
+ return out;
813
+ }
814
+ var sceneName = (s) => s.name?.trim() ? s.name : "Scene";
815
+ function sceneMarks(rows, scenes, opts = {}) {
816
+ const dayLabel = opts.dayLabel ?? storyDayLabel;
817
+ const sceneOf = /* @__PURE__ */ new Map();
818
+ const dividers = /* @__PURE__ */ new Map();
819
+ const dayMarks = /* @__PURE__ */ new Map();
820
+ const swatches = sceneSwatches(scenes);
821
+ const byId = new Map(rows.map((r) => [r.id, r]));
822
+ const holds = /* @__PURE__ */ new Map();
823
+ for (const s of scenes) {
824
+ if (isLiveScene(s)) continue;
825
+ for (const id of s.selectedMessageIds ?? []) {
826
+ if (!byId.has(id) || sceneOf.has(id)) continue;
827
+ sceneOf.set(id, { sceneId: s.id, swatch: swatches.get(s.id) ?? 0, name: sceneName(s) });
828
+ }
829
+ }
830
+ const live = scenes.filter(isLiveScene);
831
+ for (const row of rows) {
832
+ if (sceneOf.has(row.id)) continue;
833
+ const s = live.find((x) => liveSceneHolds(x, row));
834
+ if (s) sceneOf.set(row.id, { sceneId: s.id, swatch: swatches.get(s.id) ?? 0, name: sceneName(s) });
835
+ }
836
+ for (const row of rows) {
837
+ const at = sceneOf.get(row.id);
838
+ if (!at) continue;
839
+ const list = holds.get(at.sceneId) ?? [];
840
+ list.push(row.id);
841
+ holds.set(at.sceneId, list);
842
+ }
843
+ for (const s of scenes) {
844
+ const ids = holds.get(s.id);
845
+ if (!ids?.length) continue;
846
+ const liveScene = isLiveScene(s);
847
+ const open = isOpenScene(s);
848
+ const shown = ids.filter((id) => !byId.get(id)?.isHidden).length;
849
+ const recorded = s.selectedMessageIds?.length ?? 0;
850
+ const when = liveScene ? s.openedAt : null;
851
+ const nudge = liveScene ? startNudges(s, rows, sceneOf) : { startEarlier: null, startLater: null };
852
+ dividers.set(ids[0], {
853
+ scene: s,
854
+ swatch: swatches.get(s.id) ?? 0,
855
+ live: liveScene,
856
+ open,
857
+ lineCount: !open && recorded > 0 ? recorded : shown,
858
+ rowIds: ids,
859
+ dateLabel: when && typeof when.year === "number" ? dayLabel(when) : null,
860
+ ...nudge,
861
+ reopens: liveScene && !open && mayReopen(s, live)
862
+ });
863
+ }
864
+ let last = null;
865
+ for (const row of rows) {
866
+ if (opts.lane !== void 0 && (typeof row.channel === "string" && row.channel ? row.channel : "main") !== opts.lane)
867
+ continue;
868
+ const day = storyDayOfRow(row);
869
+ if (!day) continue;
870
+ if (!last || !sameStoryDay(last, day)) dayMarks.set(row.id, { label: dayLabel(day), day });
871
+ last = day;
872
+ }
873
+ return { sceneOf, dividers, dayMarks };
874
+ }
875
+ function startNudges(s, rows, sceneOf) {
876
+ const lane = laneOf(s.channel);
877
+ const onLane = rows.filter((r) => laneOf(r.channel) === lane);
878
+ const at = onLane.findIndex((r) => r.id === s.openedAtMessageId);
879
+ if (at < 0) return { startEarlier: null, startLater: null };
880
+ let earlier;
881
+ for (let i = at - 1; i >= 0; i--)
882
+ if (!onLane[i].isHidden) {
883
+ earlier = onLane[i];
884
+ break;
885
+ }
886
+ let later;
887
+ for (let i = at + 1; i < onLane.length; i++)
888
+ if (!onLane[i].isHidden) {
889
+ later = onLane[i];
890
+ break;
891
+ }
892
+ return {
893
+ startEarlier: earlier && !sceneOf.has(earlier.id) ? earlier.id : null,
894
+ startLater: later && sceneOf.get(later.id)?.sceneId === s.id && (s.closedAtMessageId == null || later.id <= s.closedAtMessageId) ? later.id : null
895
+ };
896
+ }
897
+ function mayReopen(s, live) {
898
+ const lane = laneOf(s.channel);
899
+ return !live.some(
900
+ (x) => x.id !== s.id && laneOf(x.channel) === lane && (isOpenScene(x) || x.openedAtMessageId > s.openedAtMessageId)
901
+ );
902
+ }
903
+ function boundaryOffer(row, scenes) {
904
+ const lane = laneOf(row.channel);
905
+ const onLane = scenes.filter((s) => isLiveScene(s) && laneOf(s.channel) === lane);
906
+ const open = onLane.find(isOpenScene) ?? null;
907
+ const captured = scenes.some(
908
+ (s) => !isLiveScene(s) && (s.selectedMessageIds ?? []).includes(row.id)
909
+ );
910
+ const inClosed = onLane.some((s) => !isOpenScene(s) && liveSceneHolds(s, row));
911
+ const start = !captured && !inClosed && (open ? row.id > open.openedAtMessageId : onLane.every((s) => s.closedAtMessageId != null && s.closedAtMessageId < row.id));
912
+ const end = open && row.id >= open.openedAtMessageId ? open.id : null;
913
+ return { start, end };
914
+ }
915
+ function runOffer(run, scenes, rows) {
916
+ const onLane = scenes.filter((s) => isLiveScene(s) && laneOf(s.channel) === run.lane);
917
+ for (const s of onLane) {
918
+ const opened = s.openedAtMessageId;
919
+ if (isOpenScene(s)) {
920
+ if (run.last < opened) continue;
921
+ if (run.first <= opened) return false;
922
+ continue;
923
+ }
924
+ if (run.first <= s.closedAtMessageId && opened <= run.last) return false;
925
+ }
926
+ const captured = new Set(scenes.filter((s) => !isLiveScene(s)).flatMap((s) => s.selectedMessageIds ?? []));
927
+ return !rows.some(
928
+ (r) => r.id >= run.first && r.id <= run.last && laneOf(r.channel) === run.lane && captured.has(r.id)
929
+ );
930
+ }
931
+ function markedRun(selected, rows) {
932
+ const picked = new Set(selected);
933
+ const chosen = rows.filter((r) => picked.has(r.id));
934
+ if (!chosen.length) return null;
935
+ const first = chosen.reduce((a, b) => b.id < a.id ? b : a);
936
+ const lane = laneOf(first.channel);
937
+ const last = chosen.filter((r) => laneOf(r.channel) === lane).reduce((a, b) => b.id > a.id ? b : a);
938
+ return { lane, first: first.id, last: last.id };
939
+ }
940
+
941
+ // components/shared/messages/rowFacts.ts
942
+ function anyGenerating(rows) {
943
+ return rows.some((m) => m.isGenerating);
944
+ }
945
+ function indexRowsById(rows) {
946
+ const out = /* @__PURE__ */ new Map();
947
+ for (const m of rows) {
948
+ const id = m?.id;
949
+ if (typeof id === "number" && Number.isNaN(id)) continue;
950
+ if (!out.has(id)) out.set(id, m);
951
+ }
952
+ return out;
953
+ }
954
+ function rowWithId(index, id) {
955
+ return index.get(id);
956
+ }
957
+ function scenedSetOf(scened) {
958
+ return new Set(scened ?? []);
959
+ }
960
+
961
+ // components/shared/messages/interleave.ts
962
+ function slugOf(channel) {
963
+ const c = typeof channel === "string" && channel ? channel : "main";
964
+ const at = c.indexOf(":");
965
+ return at < 0 ? c : c.slice(0, at);
966
+ }
967
+ function interleaveSlug(raw) {
968
+ return typeof raw === "string" ? raw.trim() : "";
969
+ }
970
+ function anchorOf(row) {
971
+ const v = row.metadata?.anchorMessageId;
972
+ return typeof v === "number" && Number.isInteger(v) ? v : null;
973
+ }
974
+ function isInterleavedRow(row, slug) {
975
+ return !!slug && slugOf(row.channel) === slug;
976
+ }
977
+ function interleaveByAnchor(rows, slug) {
978
+ if (!slug) return rows;
979
+ const present = /* @__PURE__ */ new Set();
980
+ for (const r of rows) if (!isInterleavedRow(r, slug)) present.add(r.id);
981
+ const under = /* @__PURE__ */ new Map();
982
+ const rest = [];
983
+ for (const r of rows) {
984
+ const anchor = isInterleavedRow(r, slug) ? anchorOf(r) : null;
985
+ if (anchor !== null && present.has(anchor)) {
986
+ const list = under.get(anchor);
987
+ if (list) list.push(r);
988
+ else under.set(anchor, [r]);
989
+ } else rest.push(r);
990
+ }
991
+ if (!under.size) return rows;
992
+ const out = [];
993
+ for (const r of rest) {
994
+ out.push(r);
995
+ const list = under.get(r.id);
996
+ if (list) out.push(...list.sort((a, b) => a.id - b.id));
997
+ }
998
+ return out;
999
+ }
1000
+ function interleaveMode(raw) {
1001
+ return raw === "open" ? "open" : "fold";
1002
+ }
1003
+ function foldHeadOf(row) {
1004
+ const meta = row.metadata;
1005
+ const summary = typeof meta?.summary === "string" ? meta.summary.trim() : "";
1006
+ const source = summary || (typeof row.content === "string" ? row.content : "");
1007
+ const first = source.split("\n").map((l) => l.trim()).find(Boolean) ?? "";
1008
+ const bare = first.replace(/^(#{1,6}\s+|[-*]\s+|>\s+)/, "").replace(/\*\*|__/g, "");
1009
+ return bare.length > 160 ? `${bare.slice(0, 159)}\u2026` : bare;
1010
+ }
1011
+ function foldRestOf(row) {
1012
+ const meta = row.metadata;
1013
+ const lines = (typeof row.content === "string" ? row.content : "").split("\n").map((l) => l.trim()).filter(Boolean);
1014
+ const summary = typeof meta?.summary === "string" ? meta.summary.trim() : "";
1015
+ return summary ? lines : lines.slice(1);
1016
+ }
1017
+ function rowKindsOf(raw) {
1018
+ const listed = Array.isArray(raw) ? raw.filter((k) => typeof k === "string") : typeof raw === "string" ? raw.split(",") : [];
1019
+ return listed.map((k) => k.trim().toLowerCase()).filter(Boolean);
1020
+ }
1021
+ function rowKindOf(row) {
1022
+ const k = row.metadata?.kind;
1023
+ return typeof k === "string" && k.trim() ? k.trim().toLowerCase() : null;
1024
+ }
1025
+ function roundOf(row) {
1026
+ const m = row.metadata;
1027
+ const a = m?.anchorMessageId;
1028
+ if (typeof a === "number" || typeof a === "string" && a) return `anchor:${String(a)}`;
1029
+ const r = m?.round;
1030
+ return typeof r === "number" || typeof r === "string" && r ? String(r) : null;
1031
+ }
1032
+ function rowsByKind(rows, kinds) {
1033
+ const kept = kinds.length ? rows.filter((r) => {
1034
+ const k = rowKindOf(r);
1035
+ return k === null || kinds.includes(k);
1036
+ }) : rows.slice();
1037
+ if (!kept.some((r) => rowKindOf(r) !== null && roundOf(r) !== null)) return kept;
1038
+ const byRound = /* @__PURE__ */ new Map();
1039
+ for (const r of kept) {
1040
+ const round = rowKindOf(r) !== null ? roundOf(r) : null;
1041
+ if (round === null) continue;
1042
+ const list = byRound.get(round);
1043
+ if (list) list.push(r);
1044
+ else byRound.set(round, [r]);
1045
+ }
1046
+ const placed = /* @__PURE__ */ new Set();
1047
+ const out = [];
1048
+ for (const r of kept) {
1049
+ const round = rowKindOf(r) !== null ? roundOf(r) : null;
1050
+ if (round === null) {
1051
+ out.push(r);
1052
+ continue;
1053
+ }
1054
+ const list = byRound.get(round);
1055
+ const head = list.find((x) => rowKindOf(x) === "did");
1056
+ if (placed.has(round) || head && r !== head) continue;
1057
+ placed.add(round);
1058
+ const rest = list.filter((x) => x !== head).sort((a, b) => a.id - b.id);
1059
+ if (head) out.push(head);
1060
+ out.push(...rest);
1061
+ }
1062
+ return out;
1063
+ }
1064
+
1065
+ // components/shared/messages/conversation.svelte.ts
1066
+ var KEY = /* @__PURE__ */ Symbol("sp-conversation");
1067
+ function isUnmountDecline(e) {
1068
+ const code = typeof e === "object" && e !== null ? e.code : void 0;
1069
+ if (code !== void 0) return code === "unmounted";
1070
+ const message = e instanceof Error ? e.message : String(e);
1071
+ return /\bunmounted\b/.test(message);
1072
+ }
1073
+ function createConversation(widget, options = {}) {
1074
+ const followTarget = !!options.followTarget;
1075
+ const noSelection = !!options.noSelection;
1076
+ const ctx = () => widget.current;
1077
+ const warn = (what) => (e) => {
1078
+ if (isUnmountDecline(e)) return;
1079
+ console.warn(`conversation: ${what} \u2014 ${e instanceof Error ? e.message : String(e)}`);
1080
+ };
1081
+ let editingId = state(null);
1082
+ let sceneRefusal = state(null);
1083
+ let sceneBusy = state(false);
1084
+ let menuFor = state(void 0);
1085
+ let speechNow = state(null);
1086
+ let speechTakes = state(proxy({}));
1087
+ let speechMenuAt = state(null);
1088
+ const bumpTake = (id, player) => {
1089
+ const k = `${id}:${player}`;
1090
+ set(speechTakes, { ...get(speechTakes), [k]: (get(speechTakes)[k] ?? 0) + 1 }, true);
1091
+ };
1092
+ let selecting = state(false);
1093
+ let lane = state("main");
1094
+ const selected = new SvelteSet();
1095
+ setStatusTextResolver(() => ctx().locale.v1, (source) => ctx().t(source));
1096
+ const dossier = user_derived(() => ctx().scope("session:full") ?? null);
1097
+ const interleave = user_derived(() => interleaveSlug(ctx().settings?.v1?.interleave));
1098
+ const interleaveAs = user_derived(() => interleaveMode(ctx().settings?.v1?.interleaveAs));
1099
+ const rowKinds = user_derived(() => rowKindsOf(ctx().settings?.v1?.rowKinds));
1100
+ const channels = user_derived(() => {
1101
+ const listed = get(dossier)?.composer?.channels;
1102
+ if (!listed || !listed.length) return null;
1103
+ const own = get(interleave) ? listed.filter((c) => c !== get(interleave)) : listed;
1104
+ return own.length ? own : listed;
1105
+ });
1106
+ const noLane = user_derived(() => !!get(channels) && get(channels).every(isNoLaneChannel));
1107
+ const rows = user_derived(() => {
1108
+ const all = ctx().messages.v1;
1109
+ const listed = get(channels);
1110
+ const mine = listed ? all.filter((m) => rowOnListedChannels(listed, m.channel) || isInterleavedRow(m, get(interleave))) : all;
1111
+ const anchored = get(interleave) ? interleaveByAnchor(mine, get(interleave)) : mine;
1112
+ return rowsByKind(anchored, get(rowKinds));
1113
+ });
1114
+ const generatingNow = user_derived(() => anyGenerating(ctx().messages.v1));
1115
+ const rowIndex = user_derived(() => indexRowsById(ctx().messages.v1));
1116
+ const scenedSet = user_derived(() => scenedSetOf(get(dossier)?.scened));
1117
+ const messageTotal = user_derived(() => ctx().messages.v1.length);
1118
+ let summaryEnded = null;
1119
+ user_effect(() => {
1120
+ const n = get(dossier)?.summaryEnded ?? 0;
1121
+ if (summaryEnded !== null && n !== summaryEnded) {
1122
+ set(selecting, false);
1123
+ selected.clear();
1124
+ }
1125
+ summaryEnded = n;
1126
+ });
1127
+ const runStartedAt = /* @__PURE__ */ new Map();
1128
+ const runTook = new SvelteMap();
1129
+ user_effect(() => untrack(() => {
1130
+ const offStart = ctx().on("generation:start", (e) => {
1131
+ if (e.kind === "generation:start" && e.messageId != null) runStartedAt.set(e.messageId, Date.now());
1132
+ });
1133
+ const offEnd = ctx().on("generation:end", (e) => {
1134
+ if (e.kind !== "generation:end" || e.messageId == null) return;
1135
+ const t0 = runStartedAt.get(e.messageId);
1136
+ runStartedAt.delete(e.messageId);
1137
+ if (t0 === void 0 || e.aborted) runTook.delete(e.messageId);
1138
+ else runTook.set(e.messageId, (Date.now() - t0) / 1e3);
1139
+ });
1140
+ return () => {
1141
+ offStart();
1142
+ offEnd();
1143
+ };
1144
+ }));
1145
+ function invoke(key, subject, payload, text) {
1146
+ try {
1147
+ ctx().invoke(key, {
1148
+ messageId: subject?.id,
1149
+ payload,
1150
+ ...text !== void 0 ? { text } : {}
1151
+ });
1152
+ } catch (e) {
1153
+ warn(key)(e);
1154
+ }
1155
+ }
1156
+ function request(kind, params) {
1157
+ return ctx().request(kind, params).catch(warn(kind));
1158
+ }
1159
+ async function sceneWrite(where, kind, params) {
1160
+ set(sceneRefusal, null);
1161
+ try {
1162
+ return await ctx().request(kind, params);
1163
+ } catch (e) {
1164
+ if (!isUnmountDecline(e)) set(sceneRefusal, { ...where, text: e instanceof Error ? e.message : String(e) }, true);
1165
+ return null;
1166
+ }
1167
+ }
1168
+ return {
1169
+ get ctx() {
1170
+ return ctx();
1171
+ },
1172
+ get dossier() {
1173
+ return get(dossier);
1174
+ },
1175
+ /** The page's word on one line; nothing when it has none. */
1176
+ line(id) {
1177
+ return get(dossier)?.lines[id] ?? NO_LINE;
1178
+ },
1179
+ t: (source) => ctx().t(source),
1180
+ /** How long the run that wrote this reply took, in seconds, as this view saw it; undefined when it did not see it. */
1181
+ runTook: (messageId) => runTook.get(messageId),
1182
+ /** A status sentence in the viewer's language. */
1183
+ statusText: (status) => statusTextIn(status, ctx().locale.v1, (source) => ctx().t(source)),
1184
+ /** May the viewer answer a form put to `addressee`? */
1185
+ canAnswer(addressee) {
1186
+ const f = get(dossier);
1187
+ return canAnswerForm(
1188
+ addressee,
1189
+ {
1190
+ userId: ctx().viewer.v1.userId,
1191
+ isOwner: !!f?.isOwner,
1192
+ isAdmin: ctx().viewer.v1.isAdmin
1193
+ },
1194
+ f?.cast
1195
+ );
1196
+ },
1197
+ /**
1198
+ * 🚧 The cast lookup: a cast member id → that seat's `ref`, off the
1199
+ * conversation cast row (either list) whose `castMemberId` matches; null on
1200
+ * a miss or a host that fills none (⏳ the card form is then read). The
1201
+ * optional `seatKind` prefers a seat of that kind (`'character-seat'` looks
1202
+ * in the character seats first; `'player-seat'` or none, the player seats
1203
+ * first) and falls back to the other, so it changes identity only.
1204
+ */
1205
+ refOfMember(castMemberId, seatKind) {
1206
+ const cast = get(dossier)?.cast;
1207
+ const players = cast?.sessionPersonas ?? [];
1208
+ const characters = cast?.sessionCharacters ?? [];
1209
+ for (const row of seatKind === "character-seat" ? [...characters, ...players] : [...players, ...characters]) if (row?.castMemberId === castMemberId && row.ref) return row.ref;
1210
+ return null;
1211
+ },
1212
+ // ── verbs ────────────────────────────────────────────────────────────
1213
+ invoke,
1214
+ /** A reply swiped: to the newer alternative (right) or the older (left). */
1215
+ swipe(subject, direction) {
1216
+ invoke("swipe", subject, { direction });
1217
+ },
1218
+ request,
1219
+ // ── 🚧 Back · Forward (RF fix 5): the session's forward stack ───────
1220
+ rewind: {
1221
+ /** The host's word (`SessionDossierV1.rewind`); null from a host that sends none. */
1222
+ get state() {
1223
+ return get(dossier)?.rewind ?? null;
1224
+ },
1225
+ /** Back: the newest turn out of the history. The host refuses in words. */
1226
+ back() {
1227
+ void request("rewind-turn", {});
1228
+ },
1229
+ /** Forward: the newest rewound turn back into it. */
1230
+ forward() {
1231
+ void request("forward-turn", {});
1232
+ }
1233
+ },
1234
+ /** 🚧 The session's settle line (`SessionDossierV1.settledThrough`): the newest settled message id; null when none or from a host that sends none. */
1235
+ get settledThrough() {
1236
+ return typeof get(dossier)?.settledThrough === "number" ? get(dossier).settledThrough : null;
1237
+ },
1238
+ // ── editing: the widget's own state; saving is the `edit` verb ───────
1239
+ edit: {
1240
+ get id() {
1241
+ return get(editingId);
1242
+ },
1243
+ start(subject) {
1244
+ set(editingId, subject.id, true);
1245
+ set(menuFor, void 0);
1246
+ },
1247
+ cancel() {
1248
+ set(editingId, null);
1249
+ },
1250
+ save(subject, content) {
1251
+ invoke("edit", subject, { content });
1252
+ set(editingId, null);
1253
+ }
1254
+ },
1255
+ /** The rows this copy's log holds — its channels' (S1), in the host's order. */
1256
+ get rows() {
1257
+ return get(rows);
1258
+ },
1259
+ /** Whether any line of the host's log is being written. */
1260
+ get anyGenerating() {
1261
+ return get(generatingNow);
1262
+ },
1263
+ /** A line of the host's log by id; the first on a duplicate id, as `find` answers. */
1264
+ rowById(id) {
1265
+ return rowWithId(get(rowIndex), id);
1266
+ },
1267
+ /** Whether a scene has already captured this line. */
1268
+ isScened(id) {
1269
+ return get(scenedSet).has(id);
1270
+ },
1271
+ /** How many lines the host's log holds. */
1272
+ get messageCount() {
1273
+ return get(messageTotal);
1274
+ },
1275
+ /** The channels this copy shows, or `null` for every channel. */
1276
+ get channels() {
1277
+ return get(channels);
1278
+ },
1279
+ /**
1280
+ * 🚧 Older lines remain for THIS copy (owner ruling ★7): one of its
1281
+ * channels — or the channel it interleaves — is among the dossier's
1282
+ * `olderIn`; a host that predates it answers with `hasOlder`.
1283
+ */
1284
+ get hasOlder() {
1285
+ const olderIn = get(dossier)?.olderIn;
1286
+ if (!Array.isArray(olderIn)) return !!get(dossier)?.hasOlder;
1287
+ if (!get(channels)) return olderIn.length > 0;
1288
+ const mine = get(interleave) ? [...get(channels), get(interleave)] : get(channels);
1289
+ return olderIn.some((c) => rowOnListedChannels(mine, c));
1290
+ },
1291
+ /** 🚧 Ask for the next older page of this copy's own channels (`load-older`, ★7). */
1292
+ loadOlder() {
1293
+ const mine = get(channels) ? get(interleave) ? [...get(channels), get(interleave)] : [...get(channels)] : null;
1294
+ void request("load-older", mine ? { channels: mine } : {});
1295
+ },
1296
+ /** 🚧 The channel this copy draws inline under its anchors, or `''`. */
1297
+ get interleave() {
1298
+ return get(interleave);
1299
+ },
1300
+ /** 🚧 Whether `row` is drawn inline from the interleaved channel. */
1301
+ isInterleaved(row) {
1302
+ return isInterleavedRow(row, get(interleave));
1303
+ },
1304
+ /** 🚧 How an interleaved row reads: `fold` (the default) or `open`. */
1305
+ get interleaveAs() {
1306
+ return get(interleaveAs);
1307
+ },
1308
+ /** 🚧 A row's kind (`metadata.kind`), or `null` — a journal's `did`, `found`, `met`… */
1309
+ rowKind(row) {
1310
+ return rowKindOf(row);
1311
+ },
1312
+ /** 🚧 The viewer is in no lane of this copy's claimed channel: nothing to show or write. */
1313
+ get noLane() {
1314
+ return get(noLane);
1315
+ },
1316
+ /**
1317
+ * What a channel is CALLED: its declared label in the viewer's language
1318
+ * (`ChannelDecl.label`, the Lair's _Sanctum_), else its slug, title-cased
1319
+ * (`manuscript` reads _Manuscript_).
1320
+ */
1321
+ channelName(slug) {
1322
+ const label = get(dossier)?.composer?.channelLabels?.[slug];
1323
+ if (label) return label;
1324
+ return slug.split(/[-_]/).filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
1325
+ },
1326
+ /**
1327
+ * What a channel IS (`ChannelDecl.role`, PLAN-core-widgets §3.7):
1328
+ * `folio` for a manuscript-style channel, else `conversation` — the
1329
+ * default every channel has, and the answer while the host says
1330
+ * nothing (`composer.channelRoles` absent).
1331
+ */
1332
+ channelRole(slug) {
1333
+ return get(dossier)?.composer?.channelRoles?.[slug] === "folio" ? "folio" : "conversation";
1334
+ },
1335
+ /**
1336
+ * The lane the composer writes to; the log shows that lane's rows. It is
1337
+ * always one of this copy's channels: a copy told one channel writes on
1338
+ * it whatever was chosen before (S1).
1339
+ */
1340
+ lane: {
1341
+ get current() {
1342
+ const followed = followTarget ? composerTargetOf(get(dossier)).target : null;
1343
+ if (followed) return canonicalListedChannel(followed.channel);
1344
+ if (!get(channels)) return get(lane);
1345
+ const writable = get(channels).filter((c) => !isNoLaneChannel(c));
1346
+ if (!writable.length) return get(channels)[0];
1347
+ const pick = writable.includes(get(lane)) ? get(lane) : writable[0];
1348
+ return canonicalListedChannel(pick);
1349
+ },
1350
+ set(next) {
1351
+ if (followTarget) return;
1352
+ set(lane, next || "main", true);
1353
+ }
1354
+ },
1355
+ /** Whose ⋮ menu is open — one at a time across the log. */
1356
+ menu: {
1357
+ get open() {
1358
+ return get(menuFor);
1359
+ },
1360
+ set(id) {
1361
+ set(menuFor, id, true);
1362
+ }
1363
+ },
1364
+ /**
1365
+ * 🚧 Heading audio control: which line's audio is playing (one at a
1366
+ * time) and through which player. `take(id, player)` is the rewind
1367
+ * counter a player is keyed by.
1368
+ */
1369
+ speech: {
1370
+ get playing() {
1371
+ return get(speechNow);
1372
+ },
1373
+ isPlaying(id, player) {
1374
+ return get(speechNow)?.id === id && get(speechNow).player === player;
1375
+ },
1376
+ /** The ⋮ player's playhead for this line while it is the current player; else null. */
1377
+ menuAt(id) {
1378
+ return get(speechMenuAt)?.id === id && get(speechNow)?.id === id && get(speechNow).player === "menu" ? get(speechMenuAt).at : null;
1379
+ },
1380
+ reportMenuAt(id, at) {
1381
+ if (at) set(speechMenuAt, { id, at }, true);
1382
+ },
1383
+ take(id, player = "line") {
1384
+ return get(speechTakes)[`${id}:${player}`] ?? 0;
1385
+ },
1386
+ /**
1387
+ * Make this line's player the playing one. Another line is stopped
1388
+ * first (its `playing` off, its player re-keyed = pause + rewind),
1389
+ * a tick ahead of the new one flipping on; the same line's other
1390
+ * player is only paused.
1391
+ */
1392
+ async play(id, player = "line") {
1393
+ const prev = get(speechNow);
1394
+ if (prev && !(prev.id === id && prev.player === player)) {
1395
+ if (prev.id !== id) bumpTake(prev.id, prev.player);
1396
+ set(speechNow, null);
1397
+ await tick();
1398
+ }
1399
+ set(speechNow, { id, player }, true);
1400
+ },
1401
+ /** Pause and rewind: nothing playing, that player starts over. */
1402
+ stop(id) {
1403
+ if (get(speechNow)?.id === id) {
1404
+ bumpTake(id, get(speechNow).player);
1405
+ set(speechNow, null);
1406
+ }
1407
+ },
1408
+ /**
1409
+ * A player's own play / pause / ended. A play makes it the current
1410
+ * one (stopping any other line); a pause or end of the current one
1411
+ * clears it. A pause from a player that is not current is old news.
1412
+ */
1413
+ heard(id, player, paused) {
1414
+ const cur = get(speechNow);
1415
+ const mine = cur?.id === id && cur.player === player;
1416
+ if (paused) {
1417
+ if (mine) set(speechNow, null);
1418
+ return;
1419
+ }
1420
+ if (mine) return;
1421
+ if (cur && cur.id !== id) bumpTake(cur.id, cur.player);
1422
+ set(speechNow, { id, player }, true);
1423
+ }
1424
+ },
1425
+ // ── 🚧 live scenes: the boundaries a person places (§7, §14 C) ─────
1426
+ scenes: {
1427
+ /** The viewer may place scene boundaries here (the dossier's verdict). */
1428
+ get boundaries() {
1429
+ return !!get(dossier)?.sceneBoundaries;
1430
+ },
1431
+ /** The last refusal, and where it is said. */
1432
+ get refusal() {
1433
+ return get(sceneRefusal);
1434
+ },
1435
+ dismiss() {
1436
+ set(sceneRefusal, null);
1437
+ },
1438
+ /** A boundary write is in flight. */
1439
+ get busy() {
1440
+ return get(sceneBusy);
1441
+ },
1442
+ /**
1443
+ * 🚧 A scene's summary may be asked for here — not when the
1444
+ * session's summaries are off (`sceneSummaryMode: 'never'`).
1445
+ */
1446
+ get summarizes() {
1447
+ return get(dossier)?.sceneSummaryMode !== "never";
1448
+ },
1449
+ /**
1450
+ * 🚧 The scene cues waiting at lines — Suggested mode's *New
1451
+ * scene?* chips (lane E) — only where the viewer may place a
1452
+ * boundary.
1453
+ */
1454
+ get cues() {
1455
+ return get(dossier)?.sceneBoundaries ? get(dossier).sceneCues ?? [] : [];
1456
+ },
1457
+ /** Which boundaries this line's menu offers (none without the verdict). */
1458
+ offer(row) {
1459
+ if (!get(dossier)?.sceneBoundaries) return { start: false, end: null };
1460
+ return boundaryOffer(row, get(dossier).scenes ?? []);
1461
+ },
1462
+ /** *Start scene here*: a scene opens at this line, on its lane. */
1463
+ async startAt(row) {
1464
+ if (get(sceneBusy)) return;
1465
+ set(sceneBusy, true);
1466
+ try {
1467
+ await sceneWrite({ at: "line", id: row.id }, "scene-open", { messageId: row.id, channel: laneOf(row.channel) });
1468
+ } finally {
1469
+ set(sceneBusy, false);
1470
+ }
1471
+ },
1472
+ /** *End scene here* (a line), or *End scene* (its divider: at the lane's newest line). */
1473
+ async endAt(sceneId, row) {
1474
+ if (get(sceneBusy)) return;
1475
+ set(sceneBusy, true);
1476
+ try {
1477
+ await sceneWrite(
1478
+ row ? { at: "line", id: row.id } : { at: "scene", id: sceneId },
1479
+ "scene-close",
1480
+ row ? { sceneId, messageId: row.id } : { sceneId }
1481
+ );
1482
+ } finally {
1483
+ set(sceneBusy, false);
1484
+ }
1485
+ },
1486
+ /**
1487
+ * 🚧 Move where a live scene starts — a divider dragged between
1488
+ * lines, or its menu's *Move start up/down one line* (lane E).
1489
+ */
1490
+ async moveStart(sceneId, openedAt) {
1491
+ if (get(sceneBusy)) return;
1492
+ set(sceneBusy, true);
1493
+ try {
1494
+ await sceneWrite({ at: "scene", id: sceneId }, "scene-move", { sceneId, openedAt });
1495
+ } finally {
1496
+ set(sceneBusy, false);
1497
+ }
1498
+ },
1499
+ /** 🚧 *Reopen scene*: a closed scene runs on to its lane's newest line again (lane E). */
1500
+ async reopen(sceneId) {
1501
+ if (get(sceneBusy)) return;
1502
+ set(sceneBusy, true);
1503
+ try {
1504
+ await sceneWrite({ at: "scene", id: sceneId }, "scene-move", { sceneId, closedAt: null });
1505
+ } finally {
1506
+ set(sceneBusy, false);
1507
+ }
1508
+ },
1509
+ /** 🚧 A scene cue's **Yes** (a scene opens at its line) or **Not here** (lane E). */
1510
+ async decideCue(cueId, accept) {
1511
+ if (get(sceneBusy)) return;
1512
+ set(sceneBusy, true);
1513
+ try {
1514
+ await sceneWrite({ at: "cue", id: cueId }, "decide-scene-cue", { cueId, accept });
1515
+ } finally {
1516
+ set(sceneBusy, false);
1517
+ }
1518
+ },
1519
+ /** A divider's name, renamed; whether the host took it. */
1520
+ async rename(sceneId, name) {
1521
+ const done = await sceneWrite({ at: "scene", id: sceneId }, "scene-rename", { sceneId, name });
1522
+ return done !== null;
1523
+ },
1524
+ /** *Remove boundary*: the host asks the person, then removes the scene. */
1525
+ async remove(sceneId) {
1526
+ if (get(sceneBusy)) return;
1527
+ set(sceneBusy, true);
1528
+ try {
1529
+ await sceneWrite({ at: "scene", id: sceneId }, "scene-remove", { sceneId });
1530
+ } finally {
1531
+ set(sceneBusy, false);
1532
+ }
1533
+ },
1534
+ /** *Summarize* a scene in the host's review. */
1535
+ summarize(sceneId) {
1536
+ void sceneWrite({ at: "scene", id: sceneId }, "summarize", { kind: "scene", sceneId });
1537
+ },
1538
+ /**
1539
+ * *Mark as scene* (the selection bar's boundary path): the picked run
1540
+ * becomes one closed live scene — opened at its first line and
1541
+ * closed at its last on that lane, in ONE write (`closeAt`, lane E),
1542
+ * so any run that overlaps no scene can be marked, an earlier one
1543
+ * included — and the selection ends. A refusal keeps it.
1544
+ */
1545
+ async markSelection() {
1546
+ const run = markedRun(selected, get(rows));
1547
+ if (!run || get(sceneBusy)) return;
1548
+ set(sceneBusy, true);
1549
+ try {
1550
+ const opened = await sceneWrite({ at: "selection", id: run.first }, "scene-open", { messageId: run.first, channel: run.lane, closeAt: run.last });
1551
+ if (!opened) return;
1552
+ set(selecting, false);
1553
+ selected.clear();
1554
+ } finally {
1555
+ set(sceneBusy, false);
1556
+ }
1557
+ }
1558
+ },
1559
+ // ── selecting lines for a summary ────────────────────────────────────
1560
+ select: {
1561
+ get active() {
1562
+ return get(selecting);
1563
+ },
1564
+ get ids() {
1565
+ return selected;
1566
+ },
1567
+ /** Whether this copy offers selecting lines for a summary; false only for a Dialogue box. */
1568
+ get offered() {
1569
+ return !noSelection;
1570
+ },
1571
+ start(subject) {
1572
+ if (noSelection) return;
1573
+ set(selecting, true);
1574
+ selected.clear();
1575
+ if (subject) selected.add(subject.id);
1576
+ set(menuFor, void 0);
1577
+ },
1578
+ stop() {
1579
+ set(selecting, false);
1580
+ selected.clear();
1581
+ },
1582
+ toggle(subject) {
1583
+ if (get(scenedSet).has(subject.id)) return;
1584
+ if (selected.has(subject.id)) selected.delete(subject.id);
1585
+ else selected.add(subject.id);
1586
+ },
1587
+ set(ids) {
1588
+ selected.clear();
1589
+ for (const id of ids) selected.add(id);
1590
+ },
1591
+ /**
1592
+ * From a line toward one end, up to the nearest line already
1593
+ * selected — never through a line a scene has already captured.
1594
+ */
1595
+ range(index, toward) {
1596
+ const list = get(rows);
1597
+ const taken = get(scenedSet);
1598
+ const step = toward === "above" ? -1 : 1;
1599
+ for (let i = index; i >= 0 && i < list.length; i += step) {
1600
+ const id = list[i].id;
1601
+ if (taken.has(id)) break;
1602
+ if (selected.has(id) && i !== index) break;
1603
+ selected.add(id);
1604
+ }
1605
+ },
1606
+ /**
1607
+ * Hand the selection to the host's summarizer. It stays until the host
1608
+ * says the summary finished (`summaryEnded`): a cancelled or failed
1609
+ * create keeps a hand-picked selection.
1610
+ */
1611
+ commit(kind) {
1612
+ ctx().request("summarize", { kind, messageIds: [...selected] }).catch(warn("summarize"));
1613
+ }
1614
+ }
1615
+ };
1616
+ }
1617
+ function setConversation(c) {
1618
+ return setContext(KEY, c);
1619
+ }
1620
+ function useConversation() {
1621
+ const c = getContext(KEY);
1622
+ if (!c) throw new Error("a conversation part rendered outside MessagesWidget");
1623
+ return c;
1624
+ }
1625
+ function useT() {
1626
+ const w = useWidgetContext();
1627
+ return (source) => w?.current.t?.(source) ?? source;
1628
+ }
1629
+
1630
+ export {
1631
+ composerClosedOn,
1632
+ composerClosedPlaceholder,
1633
+ answeredChoiceLabel,
1634
+ staleOf,
1635
+ answeredOf,
1636
+ orderedMessages,
1637
+ conversationIndex,
1638
+ messageEnvoySlug,
1639
+ ATTACHMENT_KINDS_V1,
1640
+ KIND_NAME,
1641
+ KIND_FORMATS,
1642
+ readersSummary,
1643
+ readerCallLines,
1644
+ sniffAttachmentKind,
1645
+ preCheckFiles,
1646
+ uploadingNote,
1647
+ sendableTrayIds,
1648
+ storyDayText,
1649
+ storyTimeText,
1650
+ storyDayLabelIn,
1651
+ channelTabsOf,
1652
+ newestNewsOn,
1653
+ channelTabDots,
1654
+ isDiceLine,
1655
+ rewindStripState,
1656
+ runItemWords,
1657
+ runElapsedWords,
1658
+ RUNS_SHOWN_BEFORE_COUNT,
1659
+ runTickMs,
1660
+ settlePlace,
1661
+ nextLinePlace,
1662
+ queuedSummary,
1663
+ queuedText,
1664
+ composerTargetOf,
1665
+ composerSendShownOf,
1666
+ composerSendShown,
1667
+ laneOf,
1668
+ isLiveScene,
1669
+ messageStoryTime,
1670
+ sceneMarks,
1671
+ runOffer,
1672
+ markedRun,
1673
+ anchorOf,
1674
+ foldHeadOf,
1675
+ foldRestOf,
1676
+ createConversation,
1677
+ setConversation,
1678
+ useConversation,
1679
+ useT
1680
+ };