@serene-pub/core-catalog 0.6.0-pr-8 → 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 (147) hide show
  1. package/README.md +1 -1
  2. package/components/shared/chronicle/ChronicleWidget.svelte +127 -57
  3. package/components/shared/composer/ComposerWidget.svelte +17 -5
  4. package/components/shared/composer/settings.ts +6 -2
  5. package/components/shared/composer/target.ts +19 -0
  6. package/components/shared/dialogue-box/DialogueBoxWidget.svelte +2 -2
  7. package/components/shared/lore-entries/LoreEntriesWidget.svelte +39 -35
  8. package/components/shared/messages/MessageBlocksView.svelte +1 -1
  9. package/components/shared/messages/MessageControls.svelte +21 -4
  10. package/components/shared/messages/MessagesWidget.svelte +24 -8
  11. package/components/shared/messages/NextCharacterBlock.svelte +18 -3
  12. package/components/shared/messages/SceneDivider.svelte +22 -12
  13. package/components/shared/messages/SessionComposer.svelte +67 -22
  14. package/components/shared/messages/SessionContainer.svelte +87 -32
  15. package/components/shared/messages/SessionMessage.svelte +68 -29
  16. package/components/shared/messages/SpokenLine.svelte +45 -13
  17. package/components/shared/messages/TurnLine.svelte +233 -45
  18. package/components/shared/messages/conversation.svelte.ts +30 -2
  19. package/components/shared/messages/rowFacts.ts +44 -0
  20. package/components/shared/messages/spokenLine.ts +63 -14
  21. package/components/shared/places/PlacesWidget.svelte +32 -20
  22. package/components/shared/routine-log/routineLog.ts +5 -21
  23. package/components/shared/session-runs/SessionRunsWidget.svelte +16 -12
  24. package/dist/components/actions.js +5 -5
  25. package/dist/components/actions.source.json +1 -1
  26. package/dist/components/album.js +1 -1
  27. package/dist/components/album.source.json +1 -1
  28. package/dist/components/annex.js +1 -1
  29. package/dist/components/annex.source.json +1 -1
  30. package/dist/components/attendance.js +1 -1
  31. package/dist/components/attendance.source.json +1 -1
  32. package/dist/components/authors-note.js +1 -1
  33. package/dist/components/authors-note.source.json +1 -1
  34. package/dist/components/backdrop.js +3 -3
  35. package/dist/components/backdrop.source.json +1 -1
  36. package/dist/components/chronicle.js +641 -484
  37. package/dist/components/chronicle.source.json +1 -1
  38. package/dist/components/composer.js +188 -153
  39. package/dist/components/composer.source.json +1 -1
  40. package/dist/components/core-ui.json +1 -1
  41. package/dist/components/dialogue-box.js +11 -11
  42. package/dist/components/dialogue-box.source.json +1 -1
  43. package/dist/components/lore-entries.js +101 -92
  44. package/dist/components/lore-entries.source.json +1 -1
  45. package/dist/components/messages.js +351 -275
  46. package/dist/components/messages.source.json +1 -1
  47. package/dist/components/places.js +237 -202
  48. package/dist/components/places.source.json +1 -1
  49. package/dist/components/routine-log.js +6 -17
  50. package/dist/components/routine-log.source.json +1 -1
  51. package/dist/components/scene-portraits.js +4 -4
  52. package/dist/components/scene-portraits.source.json +1 -1
  53. package/dist/components/session-runs.js +118 -211
  54. package/dist/components/session-runs.source.json +1 -1
  55. package/dist/components/{shared-OVDOAXYZ.js → shared-47J4TNSF.js} +1 -1
  56. package/dist/components/{shared-ASZVJYPD.js → shared-EFMMT76D.js} +56 -3
  57. package/dist/components/{shared-N7FFW5TX.js → shared-FOVKPMSK.js} +3 -3
  58. package/dist/components/{shared-7SWDK5MC.js → shared-HEAKNNZB.js} +4 -0
  59. package/dist/components/shared-JXP6SHKF.js +159 -0
  60. package/dist/components/{shared-TNJZHTMT.js → shared-JXYPKSTQ.js} +1 -1
  61. package/dist/components/{shared-2FMI3LEE.js → shared-KJIOSSE3.js} +2 -2
  62. package/dist/components/{shared-RQYMTMHF.js → shared-KLURQFWI.js} +2 -2
  63. package/dist/components/{shared-BR2KXM25.js → shared-MHCNUDUT.js} +96 -12
  64. package/dist/components/{shared-6S23SGJB.js → shared-NICRJ4Z2.js} +1 -1
  65. package/dist/components/{shared-M7AYID43.js → shared-W2BBJCNE.js} +7 -7
  66. package/dist/components/{shared-XJD6Y2OU.js → shared-YYYXFDZU.js} +387 -248
  67. package/dist/components/stats.js +5 -5
  68. package/dist/components/stats.source.json +1 -1
  69. package/dist/components/turn-line.js +384 -112
  70. package/dist/components/turn-line.source.json +1 -1
  71. package/dist/components/turn-order.js +4 -4
  72. package/dist/components/turn-order.source.json +1 -1
  73. package/dist/factories/answerForm.d.ts +6 -0
  74. package/dist/factories/answerForm.js +104 -96
  75. package/dist/factories/turnOrder.d.ts +84 -107
  76. package/dist/factories/turnOrder.js +89 -131
  77. package/dist/genres/chat/create.js +2 -0
  78. package/dist/genres/chat/memory.js +64 -43
  79. package/dist/genres/chat/respond.d.ts +7 -6
  80. package/dist/genres/chat/respond.js +13 -4
  81. package/dist/genres/chat/turnOrder.d.ts +2 -2
  82. package/dist/genres/chat/turnOrder.js +28 -12
  83. package/dist/genres/defaults.d.ts +8 -2
  84. package/dist/genres/defaults.js +51 -27
  85. package/dist/genres/dungeon-crawler/journal.d.ts +1 -1
  86. package/dist/genres/dungeon-crawler/journal.js +1 -1
  87. package/dist/genres/dungeon-crawler/rest.js +5 -3
  88. package/dist/genres/dungeon-crawler/story.d.ts +2 -1
  89. package/dist/genres/dungeon-crawler/story.js +7 -4
  90. package/dist/genres/dungeon-crawler/storyScripts.js +85 -9
  91. package/dist/genres/dungeon-crawler/turnOrder.d.ts +8 -9
  92. package/dist/genres/dungeon-crawler/turnOrder.js +33 -23
  93. package/dist/genres/guide/create.js +2 -0
  94. package/dist/genres/guide/turnOrder.d.ts +3 -3
  95. package/dist/genres/guide/turnOrder.js +29 -13
  96. package/dist/genres/lair/answerForm.js +4 -1
  97. package/dist/genres/lair/buildRoom.js +4 -3
  98. package/dist/genres/lair/castellanAction.js +160 -154
  99. package/dist/genres/lair/fileCurrentRoom.js +13 -10
  100. package/dist/genres/lair/fileRoom.js +4 -3
  101. package/dist/genres/lair/keeper.js +2 -0
  102. package/dist/genres/lair/names.d.ts +2 -0
  103. package/dist/genres/lair/names.js +2 -0
  104. package/dist/genres/lair/reply.js +16 -6
  105. package/dist/genres/lair/roomAnswer.js +4 -3
  106. package/dist/genres/lair/scratchpad.js +9 -7
  107. package/dist/genres/lair/turnOrder.d.ts +3 -2
  108. package/dist/genres/lair/turnOrder.js +45 -16
  109. package/dist/genres/story/create.d.ts +1 -0
  110. package/dist/genres/story/create.js +1 -0
  111. package/dist/genres/story/reckon.js +43 -10
  112. package/dist/genres/story/turnOrder.d.ts +13 -3
  113. package/dist/genres/story/turnOrder.js +79 -22
  114. package/dist/index.js +8 -8
  115. package/dist/primers/ninth-mile.d.ts +3 -4
  116. package/dist/registry/entries.js +16 -5
  117. package/dist/registry/genres.d.ts +61 -54
  118. package/dist/registry/genres.js +123 -106
  119. package/dist/registry/widgets.js +12 -1
  120. package/dist/seed/presets.js +11 -7
  121. package/dist/seed/scripts.js +3 -0
  122. package/dist/shared/lore.d.ts +13 -0
  123. package/dist/shared/lore.js +37 -1
  124. package/dist/shared/reckoning.d.ts +7 -1
  125. package/dist/shared/reckoning.js +24 -17
  126. package/dist/shared/sceneBoundaries.js +7 -6
  127. package/dist/shared/speakMessage.d.ts +9 -2
  128. package/dist/shared/speakMessage.js +32 -9
  129. package/dist/shared/ui/chronicle/index.d.ts +7 -2
  130. package/dist/shared/ui/chronicle/index.js +21 -12
  131. package/dist/shared/ui/conversation/index.d.ts +1 -0
  132. package/dist/shared/ui/conversation/index.js +2 -0
  133. package/dist/shared/ui/conversation/messageVerbState.d.ts +5 -0
  134. package/dist/shared/ui/conversation/messageVerbState.js +3 -3
  135. package/dist/shared/ui/conversation/rewindStrip.d.ts +11 -4
  136. package/dist/shared/ui/conversation/rewindStrip.js +9 -7
  137. package/dist/shared/ui/conversation/runsInProgress.d.ts +30 -0
  138. package/dist/shared/ui/conversation/runsInProgress.js +47 -0
  139. package/dist/shared/ui/conversation/tableChannel.d.ts +8 -11
  140. package/dist/shared/ui/conversation/tableChannel.js +8 -9
  141. package/dist/shared/ui/routine-log/index.d.ts +3 -0
  142. package/dist/shared/ui/routine-log/index.js +22 -0
  143. package/dist/shared/ui/session-runs/index.d.ts +9 -1
  144. package/dist/shared/ui/session-runs/index.js +20 -14
  145. package/dist/shared/ui/turn-order/index.d.ts +0 -9
  146. package/dist/shared/ui/turn-order/index.js +1 -2
  147. package/package.json +8 -8
@@ -5,15 +5,27 @@
5
5
  * combined"): ONE row between the log and the composer, in two halves.
6
6
  *
7
7
  * - **Left, what the last run is doing** (`messages.turn-line-run`): a
8
- * status pill read off the newest reply in this log — *Wren is
9
- * thinking* while it streams (the row's own run status), *Last run
10
- * failed · <the row's error>* — then *Review N changes* when proposals
11
- * wait for the viewer. At rest it says nothing (polish parity L1,
8
+ * status pill read off the newest reply in this log — *Last run
9
+ * failed*, the row's error as the pill's title — then *Review N changes* when proposals
10
+ * wait for the viewer. While a reply streams it says nothing: the row
11
+ * says it beside the name, and the run's card above the composer names the
12
+ * run and leaves the status to the row (owner, 2026-11-13). At rest it says nothing (polish parity L1,
12
13
  * 2026-10-24: one control row under the log): *Wren replied · 6.2 s*,
13
14
  * *Last run stopped* and *Inspect run* are the newest reply's ⋮ menu's
14
15
  * (`MessageControls`), and the pill is *Review N changes* alone when
15
- * something waits.
16
- * - **Right, who is next** (`messages.turn-line-next`): who is typing (the
16
+ * something waits. When none of those holds the left half, background
17
+ * work in this session says so in one short line (*Summarizing <scene>*,
18
+ * *<routine> is running*, or a count with the list in its tooltip); a
19
+ * failed run and Review always win it, and it stays quiet while a reply
20
+ * streams. It informs: no Stop.
21
+ * - **Background runs** (`turn-line.runs`): the session's actions,
22
+ * routines and summaries in progress (`dossier.runsInProgress`), one
23
+ * item each — name, status words, elapsed, **Stop** where the viewer may
24
+ * stop it (`stop-run`); *waiting for review* with no Stop when parked;
25
+ * past three, a count button expands the rest in place. A run that ends
26
+ * stays a moment as *‹name› finished*. One polite live region announces
27
+ * arrivals. Never a reply's run, never a line-bound run.
28
+ * - **Right, who is next** (`messages.turn-line-next`): who is typing (the
17
29
  * page's `session-banners` view), then `NextCharacterBlock` exactly as
18
30
  * it always drew — or **Stop** while the reply streams, or **Try again**
19
31
  * (the reply's `retry` verb, the error row's own Retry) after it failed.
@@ -22,10 +34,20 @@
22
34
  *
23
35
  * In a narrow box the pill is all of the left half: its links live in the
24
36
  * pill's own panel (`sp-popover`), which the pill opens at every width.
37
+ * The notice place (`turn-line.notice`) shows *Time limits off* while the
38
+ * dossier's `stepTimeLimitsOff` is set, unless a `notice` snippet fills it.
39
+ *
25
40
  * Reads only the conversation (its rows, its dossier, its events); acts
26
41
  * only through its verbs and requests.
27
42
  */
28
- import type { StatusText } from "@serene-pub/sdk/component"
43
+ import { untrack, type Snippet } from "svelte"
44
+ import {
45
+ RUNS_SHOWN_BEFORE_COUNT,
46
+ runElapsedWords,
47
+ runItemWords,
48
+ runTickMs
49
+ } from "@serene-pub/core-catalog/conversation"
50
+ import { composerSendShown, composerSendShownOf } from "../composer/target"
29
51
  import type { NextUp } from "../turn-line/settings"
30
52
  import NextCharacterBlock from "./NextCharacterBlock.svelte"
31
53
  import StateProposalList from "./StateProposalList.svelte"
@@ -34,9 +56,11 @@
34
56
  interface Props {
35
57
  /** The `nextUp` setting: what the right half shows; `hidden`, none of it. */
36
58
  nextUp: NextUp
59
+ /** 🚧 Fills the notice place; when absent it shows *Time limits off* while the dossier's `stepTimeLimitsOff` is set. */
60
+ notice?: Snippet
37
61
  }
38
62
 
39
- let { nextUp }: Props = $props()
63
+ let { nextUp, notice }: Props = $props()
40
64
 
41
65
  const conv = useConversation()
42
66
  const dossier = $derived(conv.dossier)
@@ -54,11 +78,17 @@
54
78
  }
55
79
  const rows = $derived(conv.rows as Row[])
56
80
  /**
57
- * 🚧 The composer under this line already offers Stop (its newest row is
58
- * generating — the composer's own rule): this line does not offer a
59
- * second (2026-10-18, the 100-turn walk #28: four Stops during a Rest).
81
+ * 🚧 The Composer beside this line draws Send: the host's answer for the
82
+ * setting (`dossier.composer.sendShown`, absent reads as shown), and at the
83
+ * compact width always, as the Composer reads it (`composerSendShown`).
84
+ */
85
+ const sendShown = $derived(composerSendShown(composerSendShownOf(dossier), conv.ctx.layout?.v1?.tier))
86
+ /**
87
+ * 🚧 The composer under this line already offers Stop (it shows Send and its
88
+ * newest row is generating): this line does not offer a second. With Send
89
+ * hidden, or no Composer beside, this line always offers the reply's Stop.
60
90
  */
61
- const composerStops = $derived(!!rows[rows.length - 1]?.isGenerating)
91
+ const composerStops = $derived(sendShown && !!rows[rows.length - 1]?.isGenerating)
62
92
  /** A reply some run wrote: a greeting opens the session, no run wrote it. */
63
93
  const isReply = (m: Row) =>
64
94
  (!!m.characterId || !!m.isNarratorResponse || !!m.isGenerating) && !m.metadata?.isGreeting
@@ -80,32 +110,25 @@
80
110
  return "done"
81
111
  })
82
112
 
83
- /** Who wrote the reply, as the page named the line. */
84
- const speaker = $derived.by((): string | null => {
85
- if (!reply) return null
86
- const named = dossier?.lines[reply.id]?.speaker.name
87
- if (named) return named
88
- if (reply.speakerLabel) return reply.speakerLabel
89
- if (reply.isNarratorResponse) return dossier?.turn.ownVoiceName || "The narrator"
90
- return null
91
- })
92
-
93
113
  /**
94
- * The pill while something is happening: a reply being written, or the
95
- * last one failed. A finished or stopped run says nothing here — its
96
- * reply's ⋮ menu says it.
114
+ * The pill while something needs saying here: the last run failed. A reply
115
+ * being written says nothing on this line: its own row says *Wren is
116
+ * typing* beside the name, and the run's card above the composer names the
117
+ * run and leaves the status to the row; a second copy here was noise
118
+ * (owner, 2026-11-13). A
119
+ * finished or stopped run says nothing either: its reply's ⋮ menu says it.
97
120
  */
98
121
  const status = $derived.by((): string => {
99
122
  if (!reply || !turnState) return ""
100
- if (turnState === "live")
101
- return (
102
- conv.statusText(reply.generationStatus as StatusText | null | undefined) ||
103
- `${speaker ?? "The reply"} is thinking`
104
- )
105
- if (turnState === "failed") return `Last run failed · ${reply.error!.message}`
123
+ if (turnState === "failed") return "Last run failed"
106
124
  return ""
107
125
  })
108
126
 
127
+ /** The failed run's reason, the pill's title; empty when the run did not fail. */
128
+ const statusReason = $derived(
129
+ reply && turnState === "failed" ? (reply.error?.message ?? "") : ""
130
+ )
131
+
109
132
  const waiting = $derived(dossier?.state.waiting ?? [])
110
133
  /**
111
134
  * 🚧 What waits ON the viewer, and the viewer's own offers waiting on
@@ -136,14 +159,91 @@
136
159
  /** The link beside the pill: Review, only when the pill is not already it. */
137
160
  const hasSideLinks = $derived(waiting.length > 0 && !!status)
138
161
  let panelOpen = $state(false)
162
+ /** The background list's own open state: Review's popover and this one are two popovers, and one opening must not open the other when the line changes hands. */
163
+ let backgroundOpen = $state(false)
164
+
165
+ /**
166
+ * Background work for this session: scene summaries under way (the
167
+ * owner's scene list is the one kept current) then the routines the host
168
+ * names as running.
169
+ */
170
+ const backgroundItems = $derived.by((): string[] => {
171
+ const items: string[] = []
172
+ if (dossier?.isOwner)
173
+ for (const scene of dossier.scenes)
174
+ if (scene.summaryStatus === "running") items.push(scene.name?.trim() ? `Summarizing ${scene.name.trim()}` : "Summarizing a scene")
175
+ for (const name of dossier?.runningRoutineNames ?? []) items.push(`${name} is running`)
176
+ return items
177
+ })
178
+ /**
179
+ * 🚧 Background runs in progress. Present: this list is the background
180
+ * line (the host sent it). Absent (an older host): the scenes' summary
181
+ * state and `runningRoutineNames` above are read instead.
182
+ */
183
+ const runs = $derived(dossier?.runsInProgress)
184
+ /** The left half's text for background work: nothing while a reply, a failure or Review holds it. */
185
+ const backgroundLine = $derived(
186
+ runs || !backgroundItems.length || status || hasLinks || turnState === "live"
187
+ ? ""
188
+ : backgroundItems.length === 1
189
+ ? backgroundItems[0]
190
+ : `${backgroundItems.length} things are running in the background`
191
+ )
192
+
193
+ /** 🚧 With Send hidden Continue stays reachable here, even under `hidden`. */
194
+ const nextShown = $derived(nextUp !== "hidden" || !sendShown)
195
+ const nextMode = $derived<NextUp>(nextUp === "hidden" ? "head" : nextUp)
196
+ const showNext = $derived(nextShown && !!dossier && !dossier.readOnly)
197
+
198
+ let runsOpen = $state(false)
199
+ const runsShown = $derived(runs ? (runsOpen ? runs : runs.slice(0, RUNS_SHOWN_BEFORE_COUNT)) : [])
200
+ const runsMore = $derived(runs ? Math.max(0, runs.length - RUNS_SHOWN_BEFORE_COUNT) : 0)
139
201
 
140
- const showNext = $derived(nextUp !== "hidden" && !!dossier && !dossier.readOnly)
202
+ /** Elapsed words tick once a second; once a minute under reduced motion. */
203
+ let now = $state(Date.now())
204
+ $effect(() => {
205
+ if (!runs?.length) return
206
+ now = Date.now()
207
+ const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches
208
+ const timer = setInterval(() => (now = Date.now()), runTickMs(reduced))
209
+ return () => clearInterval(timer)
210
+ })
211
+
212
+ /** How long a finished run stays on the line. */
213
+ const FINISHED_MOMENT_MS = 4000
214
+ let finished = $state<{ id: string; name: string }[]>([])
215
+ let seen = new Map<string, string>()
216
+ const finishTimers = new Set<ReturnType<typeof setTimeout>>()
217
+ $effect(() => {
218
+ const current = runs
219
+ untrack(() => {
220
+ if (!current) {
221
+ seen = new Map()
222
+ return
223
+ }
224
+ const ids = new Set(current.map((r) => r.id))
225
+ for (const [id, name] of seen) {
226
+ if (ids.has(id)) continue
227
+ finished = [...finished.filter((f) => f.id !== id), { id, name }]
228
+ const timer = setTimeout(() => {
229
+ finishTimers.delete(timer)
230
+ finished = finished.filter((f) => f.id !== id)
231
+ }, FINISHED_MOMENT_MS)
232
+ finishTimers.add(timer)
233
+ }
234
+ finished = finished.filter((f) => !ids.has(f.id))
235
+ seen = new Map(current.map((r) => [r.id, r.name]))
236
+ })
237
+ })
238
+ $effect(() => () => {
239
+ for (const t of finishTimers) clearTimeout(t)
240
+ })
141
241
  </script>
142
242
 
143
243
  <!-- The turn line's parts (`messages.turn-line*`, STYLE-GUIDE §6.16): no
144
244
  look here; the default widget stylesheet draws them. -->
145
245
  <div data-widget-part="messages.turn-line turn-line.turn-line" data-turn-state={turnState ?? undefined}>
146
- {#if status || hasLinks}
246
+ {#if status || hasLinks || backgroundLine}
147
247
  <div data-widget-part="messages.turn-line-run turn-line.run">
148
248
  {#if hasLinks}
149
249
  <!-- `sp-popover` (§3.5): the pill is the trigger; its panel holds
@@ -159,7 +259,7 @@
159
259
  type="button"
160
260
  data-widget-part="messages.turn-line-status turn-line.status"
161
261
  data-turn-state={turnState ?? undefined}
162
- title={status || reviewLabel}
262
+ title={statusReason || reviewLabel}
163
263
  >
164
264
  <span data-widget-part="messages.turn-line-status-text turn-line.status-text">{status || reviewLabel}</span>
165
265
  <sp-icon name="chevron-up" size="12" data-widget-part="messages.turn-line-status-more turn-line.status-more"></sp-icon>
@@ -185,8 +285,36 @@
185
285
  {/if}
186
286
  </div>
187
287
  </sp-popover>
288
+ {:else if backgroundLine && backgroundItems.length > 1}
289
+ <sp-popover
290
+ placement="top-start"
291
+ label="Running in the background"
292
+ open={backgroundOpen}
293
+ onopen-change={(e: CustomEvent<{ open: boolean }>) => (backgroundOpen = e.detail.open)}
294
+ >
295
+ <button
296
+ slot="trigger"
297
+ type="button"
298
+ data-widget-part="messages.turn-line-status turn-line.status"
299
+ title={backgroundItems.join("\n")}
300
+ >
301
+ <span data-widget-part="messages.turn-line-status-text turn-line.status-text">{backgroundLine}</span>
302
+ <sp-icon name="chevron-up" size="12" data-widget-part="messages.turn-line-status-more turn-line.status-more"></sp-icon>
303
+ </button>
304
+ <div data-widget-part="messages.turn-line-panel turn-line.panel">
305
+ <ul data-widget-part="turn-line.background-list">
306
+ {#each backgroundItems as item, i (i)}
307
+ <li>{item}</li>
308
+ {/each}
309
+ </ul>
310
+ </div>
311
+ </sp-popover>
312
+ {:else if backgroundLine}
313
+ <span data-widget-part="messages.turn-line-status turn-line.status" title={backgroundLine}>
314
+ <span data-widget-part="messages.turn-line-status-text turn-line.status-text">{backgroundLine}</span>
315
+ </span>
188
316
  {:else}
189
- <span data-widget-part="messages.turn-line-status turn-line.status" data-turn-state={turnState ?? undefined} title={status}>
317
+ <span data-widget-part="messages.turn-line-status turn-line.status" data-turn-state={turnState ?? undefined} title={statusReason || undefined}>
190
318
  <span data-widget-part="messages.turn-line-status-text turn-line.status-text">{status}</span>
191
319
  </span>
192
320
  {/if}
@@ -207,6 +335,62 @@
207
335
  {/if}
208
336
  </div>
209
337
  {/if}
338
+ {#if runs}
339
+ <!-- One polite live region for the list: arrivals are announced here,
340
+ never per item. Drawn whenever the dossier carries the list, empty when no run is in progress. -->
341
+ <div data-widget-part="turn-line.runs" aria-live="polite" aria-relevant="additions text">
342
+ {#each runsShown as run (run.id)}
343
+ {@const words = runItemWords(run)}
344
+ <span data-widget-part="turn-line.run-item" data-run-kind={run.kind} data-parked={run.parked ? "" : undefined}>
345
+ <span data-widget-part="turn-line.run-name">{run.name}</span>
346
+ {#if words.length}
347
+ <span data-widget-part="turn-line.run-status">{words.join(" · ")}</span>
348
+ {/if}
349
+ {#if run.since !== undefined}
350
+ <span data-widget-part="turn-line.run-since" aria-hidden="true">{runElapsedWords(run.since, now)}</span>
351
+ {/if}
352
+ {#if run.mayStop && !run.parked}
353
+ <button
354
+ type="button"
355
+ data-widget-part="turn-line.run-stop"
356
+ aria-label={`Stop ${run.name}`}
357
+ onclick={() => void conv.request("stop-run", { id: run.id })}
358
+ >
359
+ <sp-icon name="square" size="12"></sp-icon>
360
+ <span>Stop</span>
361
+ </button>
362
+ {/if}
363
+ </span>
364
+ {/each}
365
+ {#if runsMore > 0}
366
+ <button
367
+ type="button"
368
+ data-widget-part="turn-line.runs-more"
369
+ aria-expanded={runsOpen}
370
+ onclick={() => (runsOpen = !runsOpen)}
371
+ >
372
+ {runsOpen ? "Show fewer" : `${runsMore} more`}
373
+ </button>
374
+ {/if}
375
+ {#each finished as done (done.id)}
376
+ <span data-widget-part="turn-line.run-item" data-finished="">
377
+ <span data-widget-part="turn-line.run-name">{done.name}</span>
378
+ <span data-widget-part="turn-line.run-status">finished</span>
379
+ </span>
380
+ {/each}
381
+ </div>
382
+ {/if}
383
+ {#if notice}
384
+ <div data-widget-part="turn-line.notice">{@render notice()}</div>
385
+ {:else if dossier?.stepTimeLimitsOff === true}
386
+ <div data-widget-part="turn-line.notice">
387
+ <span
388
+ data-widget-part="turn-line.limits-off"
389
+ title="Step time limits are off in Admin › Diagnostics. A stuck step waits until someone stops it."
390
+ >Time limits off</span
391
+ >
392
+ </div>
393
+ {/if}
210
394
  {#if showNext && dossier}
211
395
  <div data-widget-part="messages.turn-line-next turn-line.next messages.next-up turn-line.next-up">
212
396
  <!-- Who else is writing (the page's view): a pill, when someone is. -->
@@ -226,20 +410,23 @@
226
410
  </button>
227
411
  {/if}
228
412
  {:else if turnState === "failed" && replyIsLast && reply}
229
- <button
230
- type="button"
231
- data-widget-part="messages.turn-line-retry turn-line.retry"
232
- title="Write this reply again"
233
- onclick={() => conv.invoke("retry", reply)}
234
- >
235
- <sp-icon name="refresh-cw" size="14"></sp-icon>
236
- <span>Try again</span>
237
- </button>
413
+ <!-- Absent unless the viewer may rerun this line (`rerunnable`); a line with no verdict keeps it. -->
414
+ {#if conv.line(reply.id).rerunnable !== false}
415
+ <button
416
+ type="button"
417
+ data-widget-part="messages.turn-line-retry turn-line.retry"
418
+ title="Write this reply again"
419
+ onclick={() => conv.invoke("retry", reply)}
420
+ >
421
+ <sp-icon name="refresh-cw" size="14"></sp-icon>
422
+ <span>Try again</span>
423
+ </button>
424
+ {/if}
238
425
  {:else}
239
426
  <NextCharacterBlock
240
427
  order={dossier.turn.order}
241
428
  candidates={dossier.turn.candidates}
242
- mode={nextUp}
429
+ mode={nextMode}
243
430
  shouldShow={dossier.turn.show && conv.edit.id === null}
244
431
  avatarFor={(ref) =>
245
432
  // 🚧 `seated-member:` resolves to a face as `character:` does. Not `player-seat:`: the page's
@@ -250,6 +437,7 @@
250
437
  viewerUserId={conv.ctx.viewer.v1.userId}
251
438
  waitingFor={dossier.turn.waitingFor ?? []}
252
439
  viewerIsOwner={!!dossier.isOwner}
440
+ standstill={dossier.turn.standstill}
253
441
  onContinue={(channel) => void conv.request("fire-turn", { channel })}
254
442
  onSomeoneElse={() => void conv.request("pick-turn", {})}
255
443
  />
@@ -31,6 +31,7 @@ import { setStatusTextResolver, statusTextIn } from "@serene-pub/core-catalog/co
31
31
  import type { RequestDeclineCode, StatusText } from "@serene-pub/sdk/component"
32
32
  import { composerTargetOf } from "../composer/target"
33
33
  import { boundaryOffer, laneOf, markedRun, type BoundaryOffer, type SceneMarkRow } from "./sceneMarks"
34
+ import { anyGenerating, indexRowsById, rowWithId, scenedSetOf } from "./rowFacts"
34
35
  import { interleaveByAnchor, interleaveMode, interleaveSlug, isInterleavedRow, rowKindOf, rowKindsOf, rowsByKind } from "./interleave"
35
36
 
36
37
  /** A seat's participant reference, as the conversation cast carries it. */
@@ -189,6 +190,17 @@ export function createConversation(widget: WidgetContextRef, options: Conversati
189
190
  return rowsByKind(anchored as Array<(typeof anchored)[number] & { metadata?: unknown }>, rowKinds)
190
191
  })
191
192
 
193
+ /**
194
+ * Facts the rows read off the whole list, once per list change: whether
195
+ * any row is being written, each row by id (the first on a duplicate), the
196
+ * lines a scene has captured, and the count. A row reads these O(1) instead
197
+ * of scanning the list on every streamed token.
198
+ */
199
+ const generatingNow = $derived(anyGenerating(ctx().messages.v1))
200
+ const rowIndex = $derived(indexRowsById(ctx().messages.v1))
201
+ const scenedSet = $derived(scenedSetOf(dossier?.scened))
202
+ const messageTotal = $derived(ctx().messages.v1.length)
203
+
192
204
  // The host's summary finished: the selection it was handed ends.
193
205
  let summaryEnded: number | null = null
194
206
  $effect(() => {
@@ -357,6 +369,22 @@ export function createConversation(widget: WidgetContextRef, options: Conversati
357
369
  get rows() {
358
370
  return rows
359
371
  },
372
+ /** Whether any line of the host's log is being written. */
373
+ get anyGenerating() {
374
+ return generatingNow
375
+ },
376
+ /** A line of the host's log by id; the first on a duplicate id, as `find` answers. */
377
+ rowById(id: unknown) {
378
+ return rowWithId(rowIndex, id)
379
+ },
380
+ /** Whether a scene has already captured this line. */
381
+ isScened(id: number): boolean {
382
+ return scenedSet.has(id)
383
+ },
384
+ /** How many lines the host's log holds. */
385
+ get messageCount() {
386
+ return messageTotal
387
+ },
360
388
  /** The channels this copy shows, or `null` for every channel. */
361
389
  get channels() {
362
390
  return channels
@@ -689,7 +717,7 @@ export function createConversation(widget: WidgetContextRef, options: Conversati
689
717
  },
690
718
  toggle(subject: Subject) {
691
719
  // A line a scene already captured cannot join another.
692
- if (dossier?.scened.includes(subject.id)) return
720
+ if (scenedSet.has(subject.id)) return
693
721
  if (selected.has(subject.id)) selected.delete(subject.id)
694
722
  else selected.add(subject.id)
695
723
  },
@@ -704,7 +732,7 @@ export function createConversation(widget: WidgetContextRef, options: Conversati
704
732
  range(index: number, toward: "above" | "below") {
705
733
  // The log's own rows: `index` counts the lines this copy draws.
706
734
  const list = rows
707
- const taken = new Set(dossier?.scened ?? [])
735
+ const taken = scenedSet
708
736
  const step = toward === "above" ? -1 : 1
709
737
  for (let i = index; i >= 0 && i < list.length; i += step) {
710
738
  const id = list[i].id
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Facts every conversation row reads off the whole message list, worked out
3
+ * once per list change (by the conversation) instead of once per row per
4
+ * streamed token. Pure, so a test reads each equivalence without a mount.
5
+ */
6
+
7
+ /** A row as far as these facts read it. */
8
+ export interface FactRow {
9
+ id?: unknown
10
+ isGenerating?: unknown
11
+ }
12
+
13
+ /** Whether any row is being written: what `rows.some((m) => m.isGenerating)` answers. */
14
+ export function anyGenerating(rows: ReadonlyArray<FactRow>): boolean {
15
+ return rows.some((m) => m.isGenerating)
16
+ }
17
+
18
+ /**
19
+ * Each row by its id, for a read that answers what
20
+ * `rows.find((m) => m?.id === id)` answers: on a duplicate id the first row
21
+ * stays. Hold it, then read with {@link rowWithId}.
22
+ */
23
+ export function indexRowsById<T extends FactRow | null | undefined>(
24
+ rows: ReadonlyArray<T>,
25
+ ): Map<unknown, T> {
26
+ const out = new Map<unknown, T>()
27
+ for (const m of rows) {
28
+ const id = m?.id
29
+ // `===` never matches NaN; a Map would.
30
+ if (typeof id === 'number' && Number.isNaN(id)) continue
31
+ if (!out.has(id)) out.set(id, m)
32
+ }
33
+ return out
34
+ }
35
+
36
+ /** The row `find((m) => m?.id === id)` would return, from an {@link indexRowsById} index. */
37
+ export function rowWithId<T>(index: ReadonlyMap<unknown, T>, id: unknown): T | undefined {
38
+ return index.get(id)
39
+ }
40
+
41
+ /** The ids a scene has already captured, as a Set; `has` answers what `includes` does. */
42
+ export function scenedSetOf(scened: ReadonlyArray<number> | null | undefined): Set<number> {
43
+ return new Set(scened ?? [])
44
+ }
@@ -6,7 +6,7 @@
6
6
  * imports no runtime from it.
7
7
  */
8
8
  import type { CueMap, Inflection, SpokenAs, SpokenMeta, SpokenVoiceFrom } from '@serene-pub/sdk/component'
9
- import type { MediaStripItem } from './mediaStrip'
9
+ import { mediaSrc, type MediaStripItem } from './mediaStrip'
10
10
 
11
11
  export type ReadAloudMode = 'off' | 'make' | 'play'
12
12
 
@@ -32,12 +32,16 @@ export function spokenOf(metadata: unknown): SpokenMeta | null {
32
32
  if (!as || typeof as !== 'object' || typeof as.voice !== 'string') return null
33
33
  const cueMap: CueMap =
34
34
  s.cueMap && Array.isArray(s.cueMap.spans) ? s.cueMap : { source: 'none', spans: [] }
35
+ const ids = s.assetIds
36
+ const assetIds =
37
+ Array.isArray(ids) && ids.length && ids.every((n) => Number.isInteger(n) && n > 0) ? (ids as number[]) : null
35
38
  return {
36
39
  spokenAs: as,
37
40
  cueMap,
38
41
  inflection: (s.inflection as Inflection | null | undefined) ?? null,
39
42
  template: typeof s.template === 'string' ? s.template : null,
40
43
  at: typeof s.at === 'string' ? s.at : '',
44
+ ...(assetIds ? { assetIds } : {}),
41
45
  }
42
46
  }
43
47
 
@@ -112,6 +116,10 @@ export interface Playback {
112
116
  currentTime: number
113
117
  duration: number
114
118
  paused: boolean
119
+ /** The file playing, 0-based, on a playlist element. */
120
+ playlistIndex?: number
121
+ /** How many files the playlist holds. */
122
+ playlistLength?: number
115
123
  }
116
124
 
117
125
  /** The `{ currentTime, duration, paused }` an `audio` event carries; a misshapen detail reads as none. */
@@ -120,7 +128,16 @@ export function playbackOf(detail: unknown): Playback | null {
120
128
  const p = d as Partial<Playback> | null | undefined
121
129
  if (!p || typeof p !== 'object') return null
122
130
  const num = (v: unknown) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : 0)
123
- return { currentTime: num(p.currentTime), duration: num(p.duration), paused: p.paused !== false }
131
+ const count = (v: unknown) => (typeof v === 'number' && Number.isInteger(v) && v >= 0 ? v : undefined)
132
+ const playlistIndex = count(p.playlistIndex)
133
+ const playlistLength = count(p.playlistLength)
134
+ return {
135
+ currentTime: num(p.currentTime),
136
+ duration: num(p.duration),
137
+ paused: p.paused !== false,
138
+ ...(playlistIndex !== undefined ? { playlistIndex } : {}),
139
+ ...(playlistLength !== undefined ? { playlistLength } : {}),
140
+ }
124
141
  }
125
142
 
126
143
  /** `m:ss` for a count of seconds (a negative, NaN or infinite count reads `0:00`). */
@@ -130,27 +147,59 @@ export function formatClock(seconds: number): string {
130
147
  }
131
148
 
132
149
  /**
133
- * The words of the cue(s) speaking at `seconds` into the audio: the spans whose
134
- * `[startMs, endMs)` hold the moment (the last span holds its end), their text
135
- * joined once each. Null when nothing is known there (no map, a gap, older
136
- * records without cue text).
150
+ * The words of the cue(s) speaking at `seconds` into file `fileIndex` of the
151
+ * line: the spans of that file (`assetIndex ?? 0`) whose `[startMs, endMs)` hold
152
+ * the moment (the file's last span holds its end), their text joined once each.
153
+ * Null when nothing is known there (no map, a gap, older records without cue text).
137
154
  */
138
- export function cueCaptionAt(cueMap: CueMap, seconds: number): string | null {
139
- if (!cueMap.spans.length || !Number.isFinite(seconds) || seconds < 0) return null
155
+ export function cueCaptionAt(cueMap: CueMap, seconds: number, fileIndex = 0): string | null {
156
+ const spans = cueMap.spans.filter((s) => (s.assetIndex ?? 0) === fileIndex)
157
+ if (!spans.length || !Number.isFinite(seconds) || seconds < 0) return null
140
158
  const ms = seconds * 1000
141
- const lastEnd = Math.max(...cueMap.spans.map((s) => s.endMs))
159
+ const lastEnd = Math.max(...spans.map((s) => s.endMs))
142
160
  const seen: string[] = []
143
- for (const span of cueMap.spans) {
161
+ for (const span of spans) {
144
162
  const inside = ms >= span.startMs && (ms < span.endMs || (ms === span.endMs && span.endMs === lastEnd))
145
163
  if (inside && span.text && !seen.includes(span.text)) seen.push(span.text)
146
164
  }
147
165
  return seen.length ? seen.join(' ') : null
148
166
  }
149
167
 
150
- /** The row's spoken audio: the newest audio file the strip found, else null. */
151
- export function spokenAudioItem(items: readonly MediaStripItem[]): MediaStripItem | null {
152
- for (let i = items.length - 1; i >= 0; i--) if (items[i].kind === 'audio') return items[i]
153
- return null
168
+ /**
169
+ * The row's spoken files in play order: the strip's audio items named by
170
+ * `spoken.assetIds`; without that list, the newest audio item alone; none when
171
+ * the row has no audio.
172
+ */
173
+ export function spokenAudioItems(items: readonly MediaStripItem[], spoken: SpokenMeta | null): MediaStripItem[] {
174
+ if (spoken?.assetIds?.length) {
175
+ const out: MediaStripItem[] = []
176
+ const used = new Set<number>()
177
+ for (const id of spoken.assetIds) {
178
+ const audio = items.filter((i) => i.kind === 'audio' && i.assetId === id)
179
+ const item = audio.find((i) => !used.has(i.partId)) ?? audio[0]
180
+ if (!item) continue
181
+ used.add(item.partId)
182
+ out.push(item)
183
+ }
184
+ return out
185
+ }
186
+ for (let i = items.length - 1; i >= 0; i--) if (items[i].kind === 'audio') return [items[i]]
187
+ return []
188
+ }
189
+
190
+ /** The `playlist` attribute of a line's files (space-joined app URLs) when there are two or more, else null. */
191
+ export function playlistOf(items: readonly MediaStripItem[]): string | null {
192
+ return items.length > 1 ? items.map((i) => mediaSrc(i.assetId)).join(' ') : null
193
+ }
194
+
195
+ /** `2 of 3` (1-based) when the line has more than one file, else null. */
196
+ export function fileCountLabel(index: number, length: number): string | null {
197
+ return length > 1 ? `${index + 1} of ${length}` : null
198
+ }
199
+
200
+ /** The screen-reader reading of {@link fileCountLabel}: `Part 2 of 3`. */
201
+ export function fileCountSr(index: number, length: number): string {
202
+ return `Part ${index + 1} of ${length}`
154
203
  }
155
204
 
156
205
  /** A spoken line made within this window counts as arriving now, not as history. */