@serene-pub/core-catalog 0.6.0-pr-2 → 0.6.0-pr-4

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 (243) hide show
  1. package/README.md +21 -1
  2. package/components/{sessions → genres/chat}/authors-note/AuthorsNote.svelte +1 -1
  3. package/components/{sessions → genres/chat}/authors-note/AuthorsNoteWidget.svelte +1 -1
  4. package/components/{sessions → shared}/lore-entries/LoreEntries.svelte +1 -1
  5. package/components/{sessions → shared}/lore-entries/LoreEntriesWidget.svelte +1 -1
  6. package/components/{sessions → shared}/messages/MessageComposer.svelte +1 -1
  7. package/components/{sessions → shared}/messages/Messages.svelte +1 -1
  8. package/components/{sessions → shared}/messages/MessagesWidget.svelte +1 -1
  9. package/components/{sessions → shared}/messages/SessionComposer.svelte +1 -1
  10. package/components/{sessions → shared}/messages/SessionMessage.svelte +1 -1
  11. package/components/{sessions → shared}/messages/conversation.svelte.ts +1 -1
  12. package/components/{sessions → shared}/scene-portraits/ScenePortraits.svelte +1 -1
  13. package/components/{sessions → shared}/scene-portraits/ScenePortraitsWidget.svelte +1 -1
  14. package/components/{sessions → shared}/stats/Stats.svelte +1 -1
  15. package/components/{sessions → shared}/stats/StatsWidget.svelte +1 -1
  16. package/components/{sessions → shared}/world-state/WorldState.svelte +1 -1
  17. package/components/{sessions → shared}/world-state/WorldStateWidget.svelte +1 -1
  18. package/dist/components/authors-note.js +5 -5
  19. package/dist/components/authors-note.source.json +1 -1
  20. package/dist/components/core-ui.json +1 -1
  21. package/dist/components/lore-entries.js +5 -5
  22. package/dist/components/lore-entries.source.json +1 -1
  23. package/dist/components/messages.js +26 -26
  24. package/dist/components/messages.source.json +1 -1
  25. package/dist/components/scene-portraits.js +7 -7
  26. package/dist/components/scene-portraits.source.json +1 -1
  27. package/dist/components/{shared-TCQZXBE3.js → shared-3FGURYVS.js} +2 -2
  28. package/dist/components/{shared-AINANAIA.js → shared-FXYLABGF.js} +6 -6
  29. package/dist/components/{shared-UAQVMZZK.js → shared-U3UU5V7L.js} +3 -3
  30. package/dist/components/stats.js +6 -6
  31. package/dist/components/stats.source.json +1 -1
  32. package/dist/components/world-state.js +6 -6
  33. package/dist/components/world-state.source.json +1 -1
  34. package/dist/{answerForm.d.ts → factories/answerForm.d.ts} +4 -30
  35. package/dist/{answerForm.js → factories/answerForm.js} +4 -37
  36. package/dist/factories/once.d.ts +7 -0
  37. package/dist/factories/once.js +9 -0
  38. package/dist/{turnOrder.d.ts → factories/turnOrder.d.ts} +0 -22
  39. package/dist/{turnOrder.js → factories/turnOrder.js} +4 -104
  40. package/dist/genres/adventure/advanceTime.d.ts +11 -0
  41. package/dist/genres/adventure/advanceTime.js +17 -0
  42. package/dist/genres/adventure/answer.d.ts +23 -0
  43. package/dist/genres/adventure/answer.js +59 -0
  44. package/dist/genres/adventure/answerForm.d.ts +9 -0
  45. package/dist/genres/adventure/answerForm.js +11 -0
  46. package/dist/genres/adventure/ask.d.ts +73 -0
  47. package/dist/genres/adventure/ask.js +157 -0
  48. package/dist/genres/adventure/create.d.ts +36 -0
  49. package/dist/genres/adventure/create.js +62 -0
  50. package/dist/genres/adventure/index.d.ts +43 -0
  51. package/dist/genres/adventure/index.js +43 -0
  52. package/dist/genres/adventure/keeperAction.d.ts +24 -0
  53. package/dist/genres/adventure/keeperAction.js +150 -0
  54. package/dist/genres/adventure/look.d.ts +45 -0
  55. package/dist/genres/adventure/look.js +209 -0
  56. package/dist/{adventure.d.ts → genres/adventure/respond.d.ts} +10 -34
  57. package/dist/{adventure.js → genres/adventure/respond.js} +34 -60
  58. package/dist/genres/adventure/rest.d.ts +10 -0
  59. package/dist/genres/adventure/rest.js +16 -0
  60. package/dist/genres/adventure/turnOrder.d.ts +10 -0
  61. package/dist/genres/adventure/turnOrder.js +27 -0
  62. package/dist/genres/chat/answerForm.d.ts +9 -0
  63. package/dist/genres/chat/answerForm.js +11 -0
  64. package/dist/genres/chat/create.d.ts +7 -0
  65. package/dist/{createChat.js → genres/chat/create.js} +6 -6
  66. package/dist/genres/chat/generateImage.d.ts +7 -0
  67. package/dist/{generateImage.js → genres/chat/generateImage.js} +5 -5
  68. package/dist/genres/chat/index.d.ts +15 -0
  69. package/dist/genres/chat/index.js +15 -0
  70. package/dist/{narrate.d.ts → genres/chat/narrate.d.ts} +3 -3
  71. package/dist/{narrate.js → genres/chat/narrate.js} +34 -12
  72. package/dist/{narrateCharacter.d.ts → genres/chat/narrateCharacter.d.ts} +2 -2
  73. package/dist/{narrateCharacter.js → genres/chat/narrateCharacter.js} +35 -16
  74. package/dist/genres/chat/respond.d.ts +25 -0
  75. package/dist/{respond.js → genres/chat/respond.js} +48 -22
  76. package/dist/genres/chat/turnOrder.d.ts +9 -0
  77. package/dist/genres/chat/turnOrder.js +28 -0
  78. package/dist/{ui/sessions → genres/chat/ui}/authors-note/index.d.ts +1 -1
  79. package/dist/genres/guide/answerForm.d.ts +9 -0
  80. package/dist/genres/guide/answerForm.js +11 -0
  81. package/dist/genres/guide/create.d.ts +24 -0
  82. package/dist/genres/guide/create.js +58 -0
  83. package/dist/genres/guide/index.d.ts +9 -0
  84. package/dist/genres/guide/index.js +9 -0
  85. package/dist/{guide.d.ts → genres/guide/respond.d.ts} +1 -20
  86. package/dist/{guide.js → genres/guide/respond.js} +29 -60
  87. package/dist/genres/guide/turnOrder.d.ts +10 -0
  88. package/dist/genres/guide/turnOrder.js +27 -0
  89. package/dist/genres/index.d.ts +14 -0
  90. package/dist/genres/index.js +41 -0
  91. package/dist/genres/lair/answerForm.d.ts +17 -0
  92. package/dist/genres/lair/answerForm.js +19 -0
  93. package/dist/genres/lair/buildRoom.d.ts +64 -0
  94. package/dist/genres/lair/buildRoom.js +244 -0
  95. package/dist/genres/lair/castellanAction.d.ts +27 -0
  96. package/dist/genres/lair/castellanAction.js +177 -0
  97. package/dist/genres/lair/create.d.ts +28 -0
  98. package/dist/genres/lair/create.js +69 -0
  99. package/dist/genres/lair/fileRoom.d.ts +53 -0
  100. package/dist/genres/lair/fileRoom.js +288 -0
  101. package/dist/genres/lair/index.d.ts +60 -0
  102. package/dist/genres/lair/index.js +60 -0
  103. package/dist/genres/lair/nudge.d.ts +25 -0
  104. package/dist/genres/lair/nudge.js +78 -0
  105. package/dist/{lair.d.ts → genres/lair/respond.d.ts} +15 -28
  106. package/dist/{lair.js → genres/lair/respond.js} +45 -76
  107. package/dist/genres/lair/reveal.d.ts +10 -0
  108. package/dist/genres/lair/reveal.js +18 -0
  109. package/dist/genres/lair/roomAnswer.d.ts +86 -0
  110. package/dist/genres/lair/roomAnswer.js +378 -0
  111. package/dist/genres/lair/trap.d.ts +11 -0
  112. package/dist/genres/lair/trap.js +24 -0
  113. package/dist/genres/lair/turnOrder.d.ts +9 -0
  114. package/dist/genres/lair/turnOrder.js +36 -0
  115. package/dist/genres/lair/whisper.d.ts +35 -0
  116. package/dist/genres/lair/whisper.js +90 -0
  117. package/dist/index.d.ts +47 -29
  118. package/dist/index.js +117 -88
  119. package/dist/{genres.js → registry/genres.js} +4 -4
  120. package/dist/{ui/sessions → registry}/widgets.js +6 -6
  121. package/dist/{presets.js → seed/presets.js} +28 -13
  122. package/dist/{prompts.js → seed/prompts.js} +27 -56
  123. package/dist/{annexField.d.ts → shared/annexField.d.ts} +3 -2
  124. package/dist/{annexField.js → shared/annexField.js} +6 -8
  125. package/dist/shared/builtins/branch.d.ts +8 -0
  126. package/dist/shared/builtins/branch.js +13 -0
  127. package/dist/{builtins.d.ts → shared/builtins/builtIn.d.ts} +16 -21
  128. package/dist/{builtins.js → shared/builtins/builtIn.js} +3 -37
  129. package/dist/shared/builtins/delete.d.ts +8 -0
  130. package/dist/shared/builtins/delete.js +13 -0
  131. package/dist/shared/builtins/edit.d.ts +8 -0
  132. package/dist/shared/builtins/edit.js +13 -0
  133. package/dist/shared/builtins/hide.d.ts +8 -0
  134. package/dist/shared/builtins/hide.js +13 -0
  135. package/dist/shared/builtins/index.d.ts +11 -0
  136. package/dist/shared/builtins/index.js +11 -0
  137. package/dist/shared/builtins/swipe.d.ts +8 -0
  138. package/dist/shared/builtins/swipe.js +17 -0
  139. package/dist/shared/sprites.d.ts +34 -0
  140. package/dist/shared/sprites.js +98 -0
  141. package/dist/shared/summarize/character.d.ts +9 -0
  142. package/dist/shared/summarize/character.js +10 -0
  143. package/dist/shared/summarize/history.d.ts +9 -0
  144. package/dist/shared/summarize/history.js +10 -0
  145. package/dist/shared/summarize/index.d.ts +10 -0
  146. package/dist/shared/summarize/index.js +10 -0
  147. package/dist/shared/summarize/scene.d.ts +38 -0
  148. package/dist/shared/summarize/scene.js +42 -0
  149. package/dist/shared/summarize/summarizeSpec.d.ts +54 -0
  150. package/dist/{summarize.js → shared/summarize/summarizeSpec.js} +8 -53
  151. package/dist/shared/summarize/world.d.ts +8 -0
  152. package/dist/shared/summarize/world.js +9 -0
  153. package/dist/{toolLoop.d.ts → shared/toolLoop.d.ts} +25 -3
  154. package/dist/{toolLoop.js → shared/toolLoop.js} +67 -14
  155. package/dist/{ui/sessions → shared/ui}/conversation/index.d.ts +1 -1
  156. package/dist/{ui/sessions → shared/ui}/conversation/index.js +1 -1
  157. package/dist/{ui/sessions → shared/ui}/coreWidgetsEntry.d.ts +1 -1
  158. package/dist/{ui/sessions → shared/ui}/coreWidgetsEntry.js +1 -1
  159. package/dist/{ui/sessions → shared/ui}/lore-entries/index.d.ts +1 -1
  160. package/dist/{ui/sessions → shared/ui}/scene-portraits/index.d.ts +1 -1
  161. package/dist/{ui/sessions → shared/ui}/scene-portraits/index.js +1 -1
  162. package/dist/{ui/sessions → shared/ui}/session-state/index.d.ts +1 -1
  163. package/dist/{ui/sessions → shared/ui}/session-state/index.js +1 -1
  164. package/package.json +28 -28
  165. package/dist/adventureActions.d.ts +0 -169
  166. package/dist/adventureActions.js +0 -599
  167. package/dist/createChat.d.ts +0 -7
  168. package/dist/generateImage.d.ts +0 -7
  169. package/dist/lairActions.d.ts +0 -296
  170. package/dist/lairActions.js +0 -1287
  171. package/dist/respond.d.ts +0 -24
  172. package/dist/sprites.d.ts +0 -24
  173. package/dist/sprites.js +0 -102
  174. package/dist/summarize.d.ts +0 -76
  175. /package/components/{sessions → genres/chat}/authors-note/authors-note.ts +0 -0
  176. /package/components/{sessions/shared → shared}/context.ts +0 -0
  177. /package/components/{sessions → shared}/lore-entries/lore-entries.ts +0 -0
  178. /package/components/{sessions → shared}/messages/MessageBlocksView.svelte +0 -0
  179. /package/components/{sessions → shared}/messages/MessageControls.svelte +0 -0
  180. /package/components/{sessions → shared}/messages/MessageMediaStrip.svelte +0 -0
  181. /package/components/{sessions → shared}/messages/MessagePartsView.svelte +0 -0
  182. /package/components/{sessions → shared}/messages/MessageStateLedger.svelte +0 -0
  183. /package/components/{sessions → shared}/messages/NextCharacterBlock.svelte +0 -0
  184. /package/components/{sessions → shared}/messages/SessionContainer.svelte +0 -0
  185. /package/components/{sessions → shared}/messages/StateProposalList.svelte +0 -0
  186. /package/components/{sessions → shared}/messages/mediaStrip.ts +0 -0
  187. /package/components/{sessions → shared}/messages/messages.ts +0 -0
  188. /package/components/{sessions → shared}/scene-portraits/StatBars.svelte +0 -0
  189. /package/components/{sessions → shared}/scene-portraits/scene-portraits.ts +0 -0
  190. /package/components/{sessions → shared}/state/SlotControl.svelte +0 -0
  191. /package/components/{sessions → shared}/state/entryFinder.ts +0 -0
  192. /package/components/{sessions → shared}/state/slotWriter.svelte.ts +0 -0
  193. /package/components/{sessions → shared}/stats/stats.ts +0 -0
  194. /package/components/{sessions/shared → shared}/widgetRef.svelte.ts +0 -0
  195. /package/components/{sessions → shared}/world-state/world-state.ts +0 -0
  196. /package/dist/{ui/sessions → genres/chat/ui}/authors-note/index.js +0 -0
  197. /package/dist/{entries.d.ts → registry/entries.d.ts} +0 -0
  198. /package/dist/{entries.js → registry/entries.js} +0 -0
  199. /package/dist/{genres.d.ts → registry/genres.d.ts} +0 -0
  200. /package/dist/{ui/sessions → registry}/layouts.d.ts +0 -0
  201. /package/dist/{ui/sessions → registry}/layouts.js +0 -0
  202. /package/dist/{slots.d.ts → registry/slots.d.ts} +0 -0
  203. /package/dist/{slots.js → registry/slots.js} +0 -0
  204. /package/dist/{statShapes.d.ts → registry/statShapes.d.ts} +0 -0
  205. /package/dist/{statShapes.js → registry/statShapes.js} +0 -0
  206. /package/dist/{ui/sessions → registry}/widgets.d.ts +0 -0
  207. /package/dist/{guideMascotImage.d.ts → seed/guideMascotImage.d.ts} +0 -0
  208. /package/dist/{guideMascotImage.js → seed/guideMascotImage.js} +0 -0
  209. /package/dist/{presets.d.ts → seed/presets.d.ts} +0 -0
  210. /package/dist/{prompts.d.ts → seed/prompts.d.ts} +0 -0
  211. /package/dist/{graphBuild.d.ts → shared/graphBuild.d.ts} +0 -0
  212. /package/dist/{graphBuild.js → shared/graphBuild.js} +0 -0
  213. /package/dist/{ui/sessions → shared/ui}/conversation/actionsDisclosure.d.ts +0 -0
  214. /package/dist/{ui/sessions → shared/ui}/conversation/actionsDisclosure.js +0 -0
  215. /package/dist/{ui/sessions → shared/ui}/conversation/composerTray.d.ts +0 -0
  216. /package/dist/{ui/sessions → shared/ui}/conversation/composerTray.js +0 -0
  217. /package/dist/{ui/sessions → shared/ui}/conversation/dossier.d.ts +0 -0
  218. /package/dist/{ui/sessions → shared/ui}/conversation/dossier.js +0 -0
  219. /package/dist/{ui/sessions → shared/ui}/conversation/formAnswer.d.ts +0 -0
  220. /package/dist/{ui/sessions → shared/ui}/conversation/formAnswer.js +0 -0
  221. /package/dist/{ui/sessions → shared/ui}/conversation/itemValues.d.ts +0 -0
  222. /package/dist/{ui/sessions → shared/ui}/conversation/itemValues.js +0 -0
  223. /package/dist/{ui/sessions → shared/ui}/conversation/messageOrder.d.ts +0 -0
  224. /package/dist/{ui/sessions → shared/ui}/conversation/messageOrder.js +0 -0
  225. /package/dist/{ui/sessions → shared/ui}/conversation/messageSpeaker.d.ts +0 -0
  226. /package/dist/{ui/sessions → shared/ui}/conversation/messageSpeaker.js +0 -0
  227. /package/dist/{ui/sessions → shared/ui}/conversation/messageVerbState.d.ts +0 -0
  228. /package/dist/{ui/sessions → shared/ui}/conversation/messageVerbState.js +0 -0
  229. /package/dist/{ui/sessions → shared/ui}/conversation/slashPalette.d.ts +0 -0
  230. /package/dist/{ui/sessions → shared/ui}/conversation/slashPalette.js +0 -0
  231. /package/dist/{ui/sessions → shared/ui}/conversation/text.d.ts +0 -0
  232. /package/dist/{ui/sessions → shared/ui}/conversation/text.js +0 -0
  233. /package/dist/{ui/sessions → shared/ui}/lore-entries/index.js +0 -0
  234. /package/dist/{ui/sessions → shared/ui}/scene-portraits/portraits.d.ts +0 -0
  235. /package/dist/{ui/sessions → shared/ui}/scene-portraits/portraits.js +0 -0
  236. /package/dist/{ui/sessions → shared/ui}/session-state/barMath.d.ts +0 -0
  237. /package/dist/{ui/sessions → shared/ui}/session-state/barMath.js +0 -0
  238. /package/dist/{ui/sessions → shared/ui}/session-state/shapes.d.ts +0 -0
  239. /package/dist/{ui/sessions → shared/ui}/session-state/shapes.js +0 -0
  240. /package/dist/{ui/sessions → shared/ui}/session-state/stateView.d.ts +0 -0
  241. /package/dist/{ui/sessions → shared/ui}/session-state/stateView.js +0 -0
  242. /package/dist/{ui/sessions → shared/ui}/widgetContext.d.ts +0 -0
  243. /package/dist/{ui/sessions → shared/ui}/widgetContext.js +0 -0
@@ -1 +1 @@
1
- {"slug":"world-state","framework":"svelte","entry":"sessions/world-state/world-state.ts","files":{"sessions/shared/context.ts":"/**\n * Core's widgets read their widget context with their own `getContext`, so\n * the lookup resolves in whichever Svelte runtime renders them — the\n * component's, in the page's UI worker. The key and the context's shape are\n * the host's contract (`@serene-pub/core-catalog/widgets`). Shared by every\n * core widget (R21); the conversation was the first.\n */\nimport { getContext } from 'svelte'\nimport { WIDGET_CONTEXT_KEY, type WidgetContextRef } from '@serene-pub/core-catalog/widgets'\n\n/** The widget context, if a host provides one; undefined outside a host (tests, a bare mount). */\nexport function useWidgetContext(): WidgetContextRef | undefined {\n\treturn getContext<WidgetContextRef | undefined>(WIDGET_CONTEXT_KEY)\n}\n","sessions/shared/widgetRef.svelte.ts":"/**\n * A remote's widget context (C0b): the component context a UI worker hands\n * a component, as the native `WidgetContext` core's widgets read\n * (`useWidgetContext`). So a core widget — written against the native\n * context — runs in a worker with no change to its source: the same\n * sections, the same verbs, reaching the host over the component's port.\n * Shared by every core widget (R21); the conversation was the first.\n */\nimport {\n\tEMPTY_TURN_ORDER,\n\tWIDGET_PROTOCOL,\n\ttype ComponentContext,\n\ttype LayoutV1,\n\ttype ViewerV1,\n\ttype WidgetEvent,\n\ttype WidgetEventKind\n} from \"@serene-pub/sdk/component\"\nimport {\n\tWIDGET_SCOPED_SECTIONS,\n\ttype WidgetContext,\n\ttype WidgetContextRef,\n\ttype WidgetScopedData\n} from \"@serene-pub/core-catalog/widgets\"\n\n/** Every scoped section's posted name — the SDK's one table, read once. */\nconst SCOPED_NAMES = Object.values(WIDGET_SCOPED_SECTIONS)\n\nconst NOBODY: ViewerV1 = { userId: null, isAdmin: false, isGuest: false }\n\n/**\n * A remote's context carries its saved view state besides: what it saved\n * last mount (`state`) and the host's save-state channel (`saveState`) —\n * read by core's widgets off the context where a remote has them.\n */\ntype RemoteWidgetContext = WidgetContext & {\n\tstate: unknown\n\tsaveState: (state: unknown) => void\n}\n\n/** The granted scoped sections as the envelope carries them: `{ <name>: { v1 } }`, absent when not granted. */\nfunction scopedData(scoped: ComponentContext[\"scoped\"]): WidgetScopedData {\n\tconst out: Record<string, { v1: unknown }> = {}\n\tfor (const name of SCOPED_NAMES) if (scoped[name] !== undefined) out[name] = { v1: scoped[name] }\n\treturn out as WidgetScopedData\n}\n\nexport function widgetRefFromComponent(\n\tctx: ComponentContext,\n\twidget: WidgetContext[\"widget\"]\n): WidgetContextRef {\n\t// Any section the host pushes re-projects the context, as a native\n\t// host's re-projection does.\n\tlet version = $state(0)\n\tctx.subscribe(() => version++)\n\n\tconst current = $derived.by((): RemoteWidgetContext => {\n\t\tvoid version\n\t\tconst scoped = ctx.scoped ?? {}\n\t\treturn {\n\t\t\tprotocol: WIDGET_PROTOCOL,\n\t\t\twidget,\n\t\t\tlayout: { v1: (ctx.layout ?? {}) as LayoutV1 },\n\t\t\tsession: { v1: (ctx.session ?? { id: 0, name: null }) as WidgetContext[\"session\"][\"v1\"] },\n\t\t\tchannels: { v1: Object.keys(ctx.channels ?? {}) },\n\t\t\tmessages: { v1: (ctx.messages ?? []) as WidgetContext[\"messages\"][\"v1\"] },\n\t\t\tprops: { v1: ctx.props ?? {} },\n\t\t\tactions: { v1: (ctx.actions ?? {}) as WidgetContext[\"actions\"][\"v1\"] },\n\t\t\tsettings: { v1: ctx.settings ?? {} },\n\t\t\tannex: { v1: (ctx.annex ?? {}) as WidgetContext[\"annex\"][\"v1\"] },\n\t\t\tlocale: { v1: ctx.locale ?? \"en\" },\n\t\t\tviewer: { v1: ctx.viewer ?? NOBODY },\n\t\t\tturnOrder: { v1: ctx.turnOrder ?? EMPTY_TURN_ORDER },\n\t\t\t// What the host said this widget holds — absent until it has — so a\n\t\t\t// widget can tell a scope never granted apart from a section not yet posted.\n\t\t\tgrants: ctx.grants,\n\t\t\t// The scoped sections the host granted, each as its `{ v1 }` bag — by\n\t\t\t// the table, so a section the SDK adds arrives with no change here.\n\t\t\t...scopedData(scoped),\n\t\t\taction: (fn, messageId, payload, action, blockId) => ctx.action(fn, messageId, payload, action, blockId),\n\t\t\tinvoke: (key, args) => ctx.invoke(key, args),\n\t\t\trequest: ((kind, params) => ctx.request(kind, params)) as WidgetContext[\"request\"],\n\t\t\t// No host menu across the port yet: dismissed, as a native host without one answers.\n\t\t\tmenu: async () => null,\n\t\t\ton: (kind: WidgetEventKind | \"*\", cb: (e: WidgetEvent) => void) =>\n\t\t\t\tctx.onEvent((e) => {\n\t\t\t\t\tconst ev = e as WidgetEvent\n\t\t\t\t\tif (kind === \"*\" || ev.kind === kind) cb(ev)\n\t\t\t\t}),\n\t\t\tt: (source) => ctx.t(source),\n\t\t\tstate: ctx.state,\n\t\t\tsaveState: (state) => ctx.saveState(state)\n\t\t}\n\t})\n\n\treturn {\n\t\tget current() {\n\t\t\treturn current\n\t\t}\n\t}\n}\n","sessions/state/SlotControl.svelte":"<script lang=\"ts\">\n\t/**\n\t * One attribute slot, drawn as what it is and edited in place — shared by\n\t * core's World State and Stats widgets (R21).\n\t *\n\t * The slot's STAT SHAPE decides the control (`slotKind`: its field, or its\n\t * type when the host predates shapes), and the configuration in force\n\t * decides its bounds: a bounded number is a bar, a choice is a chip over a\n\t * closed set (an `sp-menu` on the chip), a list opens to its items — add,\n\t * remove, move up and down — a story time is read through the calendar\n\t * and opens to its year, month, day and time, text is a line, a boolean is\n\t * a toggle. A derived slot is computed on every read and a retired one\n\t * takes nothing new, so both are shown greyed and never offered.\n\t *\n\t * Every edit here is the USER's, which is the one writer with authority: it\n\t * applies at once (`set-attribute-value`) rather than waiting at the review\n\t * gate. Nothing is applied optimistically — the new value arrives as a\n\t * `session_state` push, so what is drawn a beat later is the resolver's\n\t * answer and not this component's guess. A list is written whole, its\n\t * items in order.\n\t *\n\t * A number or text field commits on Enter, and Escape puts the stored\n\t * value back (R80: the field's `keys`). Leaving the field commits what was\n\t * typed, and only closes it when nothing was — never a write of the value\n\t * already stored. A text field also commits on `change`; a number field\n\t * does not, because the browser raises `change` on every spinner step and\n\t * a person may step several times before they are done. A list's new item\n\t * is added on Enter; a story time is saved on Enter or its Save button —\n\t * it has four fields, so leaving one of them is not being done.\n\t *\n\t * A list that takes lore references (one not closed over words) also\n\t * picks from the session's lorebook (phase 3c): item entries first, then\n\t * the rest of the book, with how many to add — Enter in the count field\n\t * adds, Escape closes the picker. A held reference reads \"Name ×N\" and\n\t * steps up and down; one fewer than one takes it out.\n\t *\n\t * The markup carries no look. A shared control owns its parts under its own\n\t * name, so every element here is `stat-slot.<part>` in `data-widget-part`\n\t * (with a generic part where the element truly is one): a style draws a\n\t * slot once for every widget, and scopes it to one through the widget's\n\t * root (STYLE-GUIDE §6.16). A slot's state is its own `data-*` or ARIA,\n\t * never a part: `data-density`, `data-retired`, `data-slot-shape`,\n\t * `data-empty` (nothing to show), `aria-pressed` (a switch on, a row\n\t * chosen), `role=\"alert\"` (refused).\n\t */\n\timport type { SessionStateSlotV1 } from \"@serene-pub/core-catalog/widgets\"\n\timport {\n\t\tbarView,\n\t\tenumValues,\n\t\tlistItemKeyOf,\n\t\tlistItemRef,\n\t\tlistItemText,\n\t\tlistItemsOf,\n\t\tlistMoved,\n\t\tcountDraftFor,\n\t\tlistWithAdded,\n\t\tlistWithRefAdded,\n\t\tlistWithRefStep,\n\t\tlistWithout,\n\t\tnumberDraftFor,\n\t\tpickableEntries,\n\t\tslotTakesLoreRefs,\n\t\ttype PickableEntry,\n\t\tshownValueText,\n\t\tslotIsWhole,\n\t\tslotKind,\n\t\tslotWritable,\n\t\tstoryTimeDraftOf,\n\t\tstoryTimeDraftValue,\n\t\ttextDraftValue,\n\t\ttype SlotWriteValue,\n\t\ttype StoryTimeDraft\n\t} from \"@serene-pub/core-catalog/session-state\"\n\timport type { HostKeyEventDetail } from \"@serene-pub/sdk/component\"\n\timport type { EntryFinder, EntryFinds } from \"./entryFinder\"\n\n\tinterface Props {\n\t\tslot: SessionStateSlotV1\n\t\t/** The configuration in force for this owner: bounds, options, a list's limits. */\n\t\tconfig: Record<string, unknown>\n\t\tvalue: unknown\n\t\t/** Compact drops the label into the control's own line. */\n\t\tdensity?: \"compact\" | \"full\"\n\t\t/** The widget's language. */\n\t\tt: (source: string) => string\n\t\t/** `null` clears this layer, so the read inherits again. */\n\t\tonset: (value: SlotWriteValue) => void\n\t\t/** Searches the session's lorebook for a list's picker; absent, a list adds words only. */\n\t\tfindEntries?: EntryFinder\n\t}\n\n\tlet { slot, config, value, density = \"full\", t, onset, findEntries }: Props = $props()\n\n\t/** A menu item's value for \"not set\" — never an option's, which are `opt:`-prefixed. */\n\tconst CLEAR = \"clear\"\n\n\tlet editing = $state(false)\n\tlet numberDraft = $state<number | null>(null)\n\tlet textDraft = $state(\"\")\n\tlet itemDraft = $state(\"\")\n\tlet timeDraft = $state<StoryTimeDraft>({ year: \"\", month: \"\", day: \"\", time: \"\" })\n\t/** Why the editor's last attempt wrote nothing — a list over its limit, a time that is not one. */\n\tlet invalid = $state<string | null>(null)\n\t/** The drafts as the field opened, so leaving it untouched writes nothing. */\n\tlet numberOpened: number | null = null\n\tlet textOpened = \"\"\n\n\t// The lorebook picker, inside a list's editor.\n\tlet picking = $state(false)\n\tlet pickWords = $state(\"\")\n\tlet pickCount = $state<number | null>(1)\n\tlet pickFound = $state<EntryFinds | null>(null)\n\tlet pickChosen = $state<number | null>(null)\n\tlet pickBusy = $state(false)\n\t/** The newest search owns the list: an older answer that lands late is dropped. */\n\tlet searches = 0\n\n\tlet kind = $derived(slotKind(slot))\n\tlet bar = $derived(kind === \"number\" ? barView(value, config as { min?: number; max?: number }) : null)\n\tlet options = $derived(enumValues(config))\n\tlet items = $derived(listItemsOf(value))\n\tlet canPick = $derived(!!findEntries && slotTakesLoreRefs(config))\n\tlet offered = $derived<PickableEntry[]>(pickFound ? pickableEntries(value, pickFound.pages) : [])\n\tlet offeredItems = $derived(offered.filter((e) => e.item))\n\tlet offeredOthers = $derived(offered.filter((e) => !e.item))\n\tlet chosen = $derived(offered.find((e) => e.entryId === pickChosen) ?? null)\n\tlet writable = $derived(slotWritable(slot))\n\tlet shown = $derived(shownValueText(slot, value, t))\n\tlet notSet = $derived(t(\"not set\"))\n\tlet fieldLabel = $derived(t(\"{label} value\").replace(\"{label}\", slot.label))\n\tlet editLabel = $derived(t(\"{label}, edit\").replace(\"{label}\", slot.label))\n\tlet barEditLabel = $derived(\n\t\tbar ? t(\"{label} {value}, edit\").replace(\"{label}\", slot.label).replace(\"{value}\", bar.label) : editLabel\n\t)\n\n\tfunction open() {\n\t\tif (!writable) return\n\t\tnumberDraft = numberOpened = typeof value === \"number\" ? value : null\n\t\ttextDraft = textOpened = value === undefined || value === null ? \"\" : String(value)\n\t\titemDraft = \"\"\n\t\ttimeDraft = storyTimeDraftOf(value)\n\t\tinvalid = null\n\t\tpicking = false\n\t\tediting = true\n\t}\n\n\t/** One commit per edit: Enter and `change` may both arrive for one. */\n\tfunction commitNumber() {\n\t\tif (!editing) return\n\t\tediting = false\n\t\tconst next = numberDraftFor(numberDraft, config as { min?: number; max?: number }, slotIsWhole(slot))\n\t\tif (next !== undefined) onset(next)\n\t}\n\n\tfunction commitText() {\n\t\tif (!editing) return\n\t\tediting = false\n\t\tonset(textDraftValue(textDraft, config as { maxLength?: unknown }))\n\t}\n\n\t/** Enter commits; Escape leaves the stored value as it was. */\n\tfunction onkey(e: CustomEvent<HostKeyEventDetail>, commit: () => void) {\n\t\tif (e.detail.key === \"Enter\") commit()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n\n\t/** Leaving the field: commit what was typed, or just close it. */\n\tfunction onblur(unchanged: boolean, commit: () => void) {\n\t\tif (!editing) return\n\t\tif (unchanged) editing = false\n\t\telse commit()\n\t}\n\n\tfunction pick(e: CustomEvent<{ value: string }>) {\n\t\tconst v = e.detail.value\n\t\tif (v === CLEAR) onset(null)\n\t\telse if (v.startsWith(\"opt:\")) onset(v.slice(4))\n\t}\n\n\t// ── A list: every change writes the whole list, and the editor stays open ──\n\n\tfunction addItem() {\n\t\tconst edit = listWithAdded(value, itemDraft, config)\n\t\tif (!edit) return\n\t\tif (edit.refusal) {\n\t\t\tinvalid = edit.refusal\n\t\t\treturn\n\t\t}\n\t\tinvalid = null\n\t\titemDraft = \"\"\n\t\tonset(edit.value)\n\t}\n\n\tfunction onItemKey(e: CustomEvent<HostKeyEventDetail>) {\n\t\tif (e.detail.key === \"Enter\") addItem()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n\n\t// ── A list's lorebook picker: choose an entry, say how many, add ──\n\n\tasync function search() {\n\t\tif (!findEntries) return\n\t\tconst mine = ++searches\n\t\tpickBusy = true\n\t\ttry {\n\t\t\tconst found = await findEntries(pickWords)\n\t\t\tif (mine !== searches) return\n\t\t\tpickFound = found\n\t\t\tif (pickChosen !== null && !found.pages.some((p) => p.some((r) => r.id === pickChosen))) pickChosen = null\n\t\t} catch (e) {\n\t\t\tif (mine !== searches) return\n\t\t\tpickFound = { pages: [], notice: e instanceof Error ? e.message : String(e) }\n\t\t} finally {\n\t\t\tif (mine === searches) pickBusy = false\n\t\t}\n\t}\n\n\tfunction openPicker() {\n\t\tpicking = true\n\t\tpickWords = \"\"\n\t\tpickCount = 1\n\t\tpickChosen = null\n\t\tpickFound = null\n\t\tinvalid = null\n\t\tvoid search()\n\t}\n\n\tfunction closePicker() {\n\t\tpicking = false\n\t\tpickChosen = null\n\t}\n\n\tfunction addPicked() {\n\t\tif (!chosen) {\n\t\t\tinvalid = t(\"Choose an entry to add first.\")\n\t\t\treturn\n\t\t}\n\t\tconst count = countDraftFor(pickCount)\n\t\tif (count === undefined) {\n\t\t\tinvalid = t(\"How many is a whole number, 1 or more.\")\n\t\t\treturn\n\t\t}\n\t\tconst edit = listWithRefAdded(value, chosen.entryId, count, config)\n\t\tif (edit.refusal) {\n\t\t\tinvalid = edit.refusal\n\t\t\treturn\n\t\t}\n\t\tinvalid = null\n\t\tpickCount = 1\n\t\tonset(edit.value)\n\t}\n\n\tfunction onPickKey(e: CustomEvent<HostKeyEventDetail>, enter: () => void) {\n\t\tif (e.detail.key === \"Enter\") enter()\n\t\telse if (e.detail.key === \"Escape\") closePicker()\n\t}\n\n\t// ── A story time: four fields, saved together ──\n\n\tfunction commitTime() {\n\t\tif (!editing) return\n\t\tconst next = storyTimeDraftValue(timeDraft)\n\t\tif (next === undefined) {\n\t\t\tinvalid = t(\"That is not a story time: a year, then a month, a day and a time as hh:mm — each optional, a day only with a month.\")\n\t\t\treturn\n\t\t}\n\t\tediting = false\n\t\tinvalid = null\n\t\tonset(next)\n\t}\n\n\tfunction onTimeKey(e: CustomEvent<HostKeyEventDetail>) {\n\t\tif (e.detail.key === \"Enter\") commitTime()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n</script>\n\n<div\n\tdata-widget-part=\"stat-slot.root row\"\n\tdata-density={density}\n\tdata-slot-id={slot.slotId}\n\tdata-slot-type={slot.type}\n\tdata-slot-shape={kind}\n\tdata-retired={slot.retired ? \"\" : undefined}\n>\n\t<span data-widget-part=\"stat-slot.label label\" title={slot.description ?? slot.label}>\n\t\t{slot.label}\n\t\t{#if slot.required}\n\t\t\t<span data-widget-part=\"stat-slot.required\" role=\"img\" aria-label={t(\"required\")} title={t(\"required\")}>*</span>\n\t\t{/if}\n\t\t{#if slot.retired}\n\t\t\t<sp-icon name=\"archive\" size=\"10\" label={t(\"retired\")}></sp-icon>\n\t\t{:else if kind === \"derived\"}\n\t\t\t<sp-icon name=\"sigma\" size=\"10\"></sp-icon>\n\t\t{/if}\n\t</span>\n\n\t<div data-widget-part=\"stat-slot.control\">\n\t\t{#if kind === \"boolean\" && writable}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\taria-pressed={value === true}\n\t\t\t\tonclick={() => onset(value === true ? false : true)}\n\t\t\t>\n\t\t\t\t{value === undefined ? notSet : shown}\n\t\t\t</button>\n\t\t{:else if editing && kind === \"number\"}\n\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t<input\n\t\t\t\tdata-widget-part=\"stat-slot.field\"\n\t\t\t\ttype=\"number\"\n\t\t\t\taria-label={fieldLabel}\n\t\t\t\tmin={(config as { min?: number }).min}\n\t\t\t\tmax={(config as { max?: number }).max}\n\t\t\t\tstep={slotIsWhole(slot) ? \"1\" : \"any\"}\n\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\tautofocus\n\t\t\t\tbind:value={numberDraft}\n\t\t\t\tonblur={() => onblur(numberDraft === numberOpened, commitNumber)}\n\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onkey(e, commitNumber)}\n\t\t\t/>\n\t\t{:else if editing && kind === \"list\"}\n\t\t\t<div data-widget-part=\"stat-slot.editor\" role=\"group\" aria-label={fieldLabel}>\n\t\t\t\t{#if items.length}\n\t\t\t\t\t<ol data-widget-part=\"stat-slot.items list\">\n\t\t\t\t\t\t{#each items as item, i (listItemKeyOf(item, i))}\n\t\t\t\t\t\t\t{@const itemText = listItemText(item, t)}\n\t\t\t\t\t\t\t{@const ref = listItemRef(item)}\n\t\t\t\t\t\t\t<li data-widget-part=\"stat-slot.item row\" data-item-index={i}>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.item-text label\">{itemText}</span>\n\t\t\t\t\t\t\t\t{#if ref}\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-less\"\n\t\t\t\t\t\t\t\t\t\taria-label={t(\"One fewer {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithRefStep(value, ref.entryId, -1))}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"minus\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-more\"\n\t\t\t\t\t\t\t\t\t\taria-label={t(\"One more {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithRefStep(value, ref.entryId, 1))}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"plus\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-up\"\n\t\t\t\t\t\t\t\t\tdisabled={i === 0}\n\t\t\t\t\t\t\t\t\taria-label={t(\"Move {item} up\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listMoved(value, i, -1))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"arrow-up\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-down\"\n\t\t\t\t\t\t\t\t\tdisabled={i === items.length - 1}\n\t\t\t\t\t\t\t\t\taria-label={t(\"Move {item} down\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listMoved(value, i, 1))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"arrow-down\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-remove\"\n\t\t\t\t\t\t\t\t\taria-label={t(\"Remove {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithout(value, i))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"x\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</ol>\n\t\t\t\t{:else}\n\t\t\t\t\t<p data-widget-part=\"stat-slot.items-empty empty\">{t(\"Nothing in the list yet.\")}</p>\n\t\t\t\t{/if}\n\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.add stat-slot.field\"\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\taria-label={t(\"Add to {label}\").replace(\"{label}\", slot.label)}\n\t\t\t\t\tplaceholder={t(\"Add an item, then Enter\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tautofocus\n\t\t\t\t\tbind:value={itemDraft}\n\t\t\t\t\tonkey={onItemKey}\n\t\t\t\t/>\n\t\t\t\t{#if canPick && !picking}\n\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-open\" onclick={openPicker}>\n\t\t\t\t\t\t<sp-icon name=\"book-open\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t<span>{t(\"Add from the lorebook\")}</span>\n\t\t\t\t\t</button>\n\t\t\t\t{:else if canPick}\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"stat-slot.picker\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={t(\"Add to {label} from the lorebook\").replace(\"{label}\", slot.label)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-search stat-slot.field\"\n\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\taria-label={t(\"Search the lorebook\")}\n\t\t\t\t\t\t\tplaceholder={t(\"Search by name or key, then Enter\")}\n\t\t\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\t\t\tautofocus\n\t\t\t\t\t\t\tbind:value={pickWords}\n\t\t\t\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onPickKey(e, () => void search())}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{#if !pickFound}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Searching the lorebook…\")}</p>\n\t\t\t\t\t\t{:else if pickFound.notice}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{pickFound.notice}</p>\n\t\t\t\t\t\t{:else if !offered.length}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Nothing in the lorebook matches.\")}</p>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t{#each [{ heading: t(\"Items\"), rows: offeredItems, group: \"items\" }, { heading: t(\"Other entries\"), rows: offeredOthers, group: \"others\" }] as part (part.group)}\n\t\t\t\t\t\t\t\t{#if part.rows.length}\n\t\t\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-heading\">{part.heading}</p>\n\t\t\t\t\t\t\t\t\t<ul data-widget-part=\"stat-slot.pick-list list\" aria-label={part.heading} data-pick-group={part.group}>\n\t\t\t\t\t\t\t\t\t\t{#each part.rows as entry (entry.entryId)}\n\t\t\t\t\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-entry row\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata-entry-id={entry.entryId}\n\t\t\t\t\t\t\t\t\t\t\t\t\taria-pressed={pickChosen === entry.entryId}\n\t\t\t\t\t\t\t\t\t\t\t\t\tonclick={() => (pickChosen = pickChosen === entry.entryId ? null : entry.entryId)}\n\t\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.pick-title label\">{entry.title}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{#if entry.held}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.pick-held\">{t(\"held ×{n}\").replace(\"{n}\", String(entry.held))}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if pickBusy && pickFound}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Searching the lorebook…\")}</p>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<div data-widget-part=\"stat-slot.pick-add toolbar\">\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-count stat-slot.field\"\n\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\tmin=\"1\"\n\t\t\t\t\t\t\t\tstep=\"1\"\n\t\t\t\t\t\t\t\taria-label={chosen ? t(\"How many {item} to add\").replace(\"{item}\", chosen.title) : t(\"How many to add\")}\n\t\t\t\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\t\t\t\tbind:value={pickCount}\n\t\t\t\t\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onPickKey(e, addPicked)}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-confirm\" disabled={!chosen} onclick={addPicked}>\n\t\t\t\t\t\t\t\t{chosen ? t(\"Add {item}\").replace(\"{item}\", chosen.title) : t(\"Add\")}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-close\" onclick={closePicker}>{t(\"Close\")}</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t\t{#if invalid}<p data-widget-part=\"stat-slot.invalid\" role=\"alert\">{invalid}</p>{/if}\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.done\" onclick={() => (editing = false)}>{t(\"Done\")}</button>\n\t\t\t</div>\n\t\t{:else if editing && kind === \"story-time\"}\n\t\t\t<div data-widget-part=\"stat-slot.editor\" role=\"group\" aria-label={fieldLabel}>\n\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.year stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Year\")}\n\t\t\t\t\tplaceholder={t(\"Year\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tautofocus\n\t\t\t\t\tbind:value={timeDraft.year}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.month stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tmin=\"1\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Month\")}\n\t\t\t\t\tplaceholder={t(\"Month\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.month}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.day stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tmin=\"1\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Day\")}\n\t\t\t\t\tplaceholder={t(\"Day\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.day}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.clock stat-slot.field\"\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\taria-label={t(\"Time of day\")}\n\t\t\t\t\tplaceholder=\"hh:mm\"\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.time}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t{#if invalid}<p data-widget-part=\"stat-slot.invalid\" role=\"alert\">{invalid}</p>{/if}\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.save\" onclick={commitTime}>{t(\"Save\")}</button>\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.cancel\" onclick={() => (editing = false)}>{t(\"Cancel\")}</button>\n\t\t\t</div>\n\t\t{:else if editing}\n\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t<input\n\t\t\t\tdata-widget-part=\"stat-slot.field\"\n\t\t\t\ttype=\"text\"\n\t\t\t\taria-label={fieldLabel}\n\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\tautofocus\n\t\t\t\tbind:value={textDraft}\n\t\t\t\tonchange={commitText}\n\t\t\t\tonblur={() => onblur(textDraft === textOpened, commitText)}\n\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onkey(e, commitText)}\n\t\t\t/>\n\t\t{:else if bar}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.bar\"\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={barEditLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t<span data-widget-part=\"stat-slot.track meter\">\n\t\t\t\t\t<span data-widget-part=\"stat-slot.fill\" style:--sp-fill=\"{bar.percent}%\"></span>\n\t\t\t\t</span>\n\t\t\t\t<span data-widget-part=\"stat-slot.bar-value value\">{bar.label}</span>\n\t\t\t</button>\n\t\t{:else if kind === \"choice\" && writable}\n\t\t\t<!-- The chip opens the closed set; picking one writes it. -->\n\t\t\t<sp-menu label={fieldLabel} onselect={pick}>\n\t\t\t\t<button\n\t\t\t\t\tslot=\"trigger\"\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\t\tdata-empty={value == null ? \"\" : undefined}\n\t\t\t\t\taria-label={editLabel}\n\t\t\t\t>\n\t\t\t\t\t{shown || notSet}\n\t\t\t\t</button>\n\t\t\t\t<sp-menu-item value={CLEAR} data-widget-part=\"stat-slot.option\" data-empty=\"\">{notSet}</sp-menu-item>\n\t\t\t\t{#each options as option (option)}\n\t\t\t\t\t<sp-menu-item value=\"opt:{option}\" data-widget-part=\"stat-slot.option\">\n\t\t\t\t\t\t{#if value === option}<sp-icon name=\"check\" size=\"12\" label={t(\"current\")}></sp-icon>{/if}\n\t\t\t\t\t\t<span>{option}</span>\n\t\t\t\t\t</sp-menu-item>\n\t\t\t\t{/each}\n\t\t\t</sp-menu>\n\t\t{:else if kind === \"choice\"}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\tdata-empty={value == null ? \"\" : undefined}\n\t\t\t\tdisabled\n\t\t\t\taria-label={editLabel}\n\t\t\t>\n\t\t\t\t{shown || notSet}\n\t\t\t</button>\n\t\t{:else if kind === \"list\"}\n\t\t\t<!-- A list reads as its items; opening it edits them. -->\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.line value\"\n\t\t\t\tdata-empty={items.length ? undefined : \"\"}\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={editLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t{items.length ? shown : value === undefined ? notSet : t(\"none\")}\n\t\t\t</button>\n\t\t{:else}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.line value\"\n\t\t\t\tdata-empty={value === undefined ? \"\" : undefined}\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={editLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t{shown || notSet}\n\t\t\t</button>\n\t\t{/if}\n\t</div>\n</div>\n","sessions/state/entryFinder.ts":"/**\n * 🚧 A state widget's lorebook search for a list's picker (attributes phase\n * 3c): the session's book through `session-entries`, item entries asked for\n * first (`typeIds`), then the rest of the book — two pages the picker merges\n * (`pickableEntries`), so the items lead even in a book too big for one page.\n *\n * A session that reads no lorebook, and a viewer who does not own the book,\n * are told so in words (`notice`) rather than shown an empty list that reads\n * as \"nothing to pick\". A declined request rejects, and the picker says why.\n */\nimport type { WidgetContextRef } from \"@serene-pub/core-catalog/widgets\"\nimport { ITEM_ENTRY_TYPE_ID } from \"@serene-pub/core-catalog/session-state\"\n\n/** One row the picker can offer, as `session-entries` answered it. */\nexport interface FoundEntry {\n\tid: number\n\ttypeId: string\n\ttitle: string\n}\n\n/** What one search found: the item page, then the book's page; or why there is nothing. */\nexport interface EntryFinds {\n\tpages: FoundEntry[][]\n\tnotice: string | null\n}\n\n/** Search the session's lorebook by title or key; blank is the whole book. */\nexport type EntryFinder = (titleOrKey: string) => Promise<EntryFinds>\n\n/** How many of each the picker shows before the search has to narrow it. */\nconst PAGE = 25\n\nexport function createEntryFinder(\n\twidget: WidgetContextRef | undefined,\n\tt: (source: string) => string\n): EntryFinder | undefined {\n\tif (!widget) return undefined\n\treturn async (titleOrKey) => {\n\t\tconst words = titleOrKey.trim()\n\t\tconst ask = (typeIds?: string[]) =>\n\t\t\twidget.current.request(\"session-entries\", {\n\t\t\t\t...(words ? { titleOrKey: words } : {}),\n\t\t\t\tsort: \"name\",\n\t\t\t\t...(typeIds ? { typeIds } : {}),\n\t\t\t\tlimit: PAGE\n\t\t\t})\n\t\tconst items = await ask([ITEM_ENTRY_TYPE_ID])\n\t\tif (items.lorebookId == null) return { pages: [], notice: t(\"This session reads no lorebook, so there is nothing to pick from.\") }\n\t\tif (items.ownerOnly)\n\t\t\treturn { pages: [], notice: t(\"Only the lorebook's owner can pick from it. Type the item's name instead.\") }\n\t\tconst rest = await ask()\n\t\tconst rows = (page: { rows: FoundEntry[] }) => page.rows.map(({ id, typeId, title }) => ({ id, typeId, title }))\n\t\treturn { pages: [rows(items), rows(rest)], notice: null }\n\t}\n}\n","sessions/state/slotWriter.svelte.ts":"/**\n * A state widget's writes (R21): `set-attribute-value` through the widget's\n * own context, and the widget's OWN error line (R77) — a write that fails is\n * said in the widget that asked, never in every state widget on the page.\n *\n * The newest write owns the line: asking again clears it, and a refusal of\n * an older write that lands after a newer one was asked says nothing.\n */\nimport type { SessionStateOwnerV1, WidgetContextRef } from \"@serene-pub/core-catalog/widgets\"\nimport type { SlotWriteValue } from \"@serene-pub/core-catalog/session-state\"\n\nexport interface SlotWriter {\n\t/** Why the newest write failed, in words; null when it did not (or has not answered). */\n\treadonly error: string | null\n\tset(owner: SessionStateOwnerV1, slotId: string, value: SlotWriteValue): Promise<void>\n}\n\nexport function createSlotWriter(widget: WidgetContextRef | undefined): SlotWriter {\n\tlet error = $state<string | null>(null)\n\tlet asked = 0\n\treturn {\n\t\tget error() {\n\t\t\treturn error\n\t\t},\n\t\tasync set(owner, slotId, value) {\n\t\t\tconst mine = ++asked\n\t\t\terror = null\n\t\t\tif (!widget) return\n\t\t\ttry {\n\t\t\t\tawait widget.current.request(\"set-attribute-value\", {\n\t\t\t\t\towner: { kind: owner.kind, id: owner.id },\n\t\t\t\t\tslotId,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t} catch (e) {\n\t\t\t\tif (mine === asked) error = e instanceof Error ? e.message : String(e)\n\t\t\t}\n\t\t}\n\t}\n}\n","sessions/world-state/WorldState.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's World State widget as a remote component (R21): the component\n\t * context, as the widget context, around the widget.\n\t */\n\timport { setContext, untrack } from \"svelte\"\n\timport type { ComponentContext } from \"@serene-pub/sdk/component\"\n\timport { WIDGET_CONTEXT_KEY } from \"@serene-pub/core-catalog/widgets\"\n\timport WorldStateWidget from \"./WorldStateWidget.svelte\"\n\timport { widgetRefFromComponent } from \"../shared/widgetRef.svelte\"\n\n\tlet { ctx }: { ctx: ComponentContext } = $props()\n\n\t// The context is the mount's, handed once: its sections move, it does not.\n\tsetContext(\n\t\tWIDGET_CONTEXT_KEY,\n\t\twidgetRefFromComponent(\n\t\t\tuntrack(() => ctx),\n\t\t\t{ id: \"world-state\", instanceId: \"world-state\", title: \"World State\" }\n\t\t)\n\t)\n</script>\n\n<WorldStateWidget />\n","sessions/world-state/WorldStateWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * The World State widget: the session's world slots, editable (R21).\n\t *\n\t * The same values a template reads as `state.world.*` and the conditions\n\t * vocabulary reads for layout rules — so what is edited here is what the\n\t * model is told and what a rule fires on, which is why it is worth one\n\t * strip above the messages rather than a page somewhere else.\n\t *\n\t * A world slot belongs to the session's own owner, so an edit is a\n\t * session-layer deviation: the world's own answer is untouched, and clearing\n\t * one goes back to inheriting it. Reads the `session_state` section and its\n\t * settings (`layout`, `slots`, `pickSlots`); writes `set-attribute-value`,\n\t * whose refusal is this widget's own line (R77).\n\t *\n\t * 🚧 A location holding state (attributes phase 4) is drawn as a place\n\t * under the world's slots — only one with a value in play.\n\t *\n\t * The markup carries no look: each element names what it is in\n\t * `data-widget-part` (`world-state.place`, …), the layout rides on\n\t * `data-layout`, and the default widget stylesheet draws them\n\t * (STYLE-GUIDE §6.16).\n\t */\n\timport { worldStateView } from \"@serene-pub/core-catalog/session-state\"\n\timport { useWidgetContext } from \"../shared/context\"\n\timport SlotControl from \"../state/SlotControl.svelte\"\n\timport { createSlotWriter } from \"../state/slotWriter.svelte\"\n\timport { createEntryFinder } from \"../state/entryFinder\"\n\n\tconst widget = useWidgetContext()\n\tconst writer = createSlotWriter(widget)\n\tconst t = (source: string) => widget?.current.t(source) ?? source\n\t// A list's lorebook picker (phase 3c) searches through `session-entries`.\n\tconst findEntries = createEntryFinder(widget, t)\n\n\tlet section = $derived(widget?.current.session_state?.v1)\n\tlet settings = $derived((widget?.current.settings.v1 ?? {}) as Record<string, unknown>)\n\t// Not granted `session:state`: the section will never come — said, not waited for.\n\tlet view = $derived(worldStateView(section, settings, widget?.current.grants?.includes(\"session:state\")))\n</script>\n\n<div\n\tdata-widget-part=\"world-state.root\"\n\tdata-layout={view.layout === \"strip\" ? \"strip\" : \"list\"}\n\tdata-state-widget=\"world-state\"\n\tdata-owner-key=\"world\"\n>\n\t{#if section?.error}\n\t\t<p data-widget-part=\"world-state.alert\" role=\"alert\">{section.error}</p>\n\t{/if}\n\t{#if writer.error}\n\t\t<p data-widget-part=\"world-state.alert\" role=\"alert\">{writer.error}</p>\n\t{/if}\n\n\t{#if view.status === \"not-granted\"}\n\t\t<div data-widget-part=\"world-state.empty empty\" role=\"status\" data-scope-not-granted=\"session:state\">\n\t\t\t<sp-icon name=\"lock\" size=\"16\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{t(\"This widget has not been granted the session's stats. An administrator can grant it in the extension's permissions.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else if view.status === \"loading\"}\n\t\t<div data-widget-part=\"world-state.empty empty\" role=\"status\">\n\t\t\t<sp-icon name=\"cloud-sun\" size=\"16\"></sp-icon>\n\t\t\t<span>{t(\"Loading the world's stats…\")}</span>\n\t\t</div>\n\t{:else if view.status === \"failed\"}\n\t\t<!-- The first read was refused: the alert above is the whole story. -->\n\t{:else if view.status === \"empty\"}\n\t\t<div data-widget-part=\"world-state.empty empty\">\n\t\t\t<sp-icon name=\"cloud-sun\" size=\"16\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{view.reason === \"none-shown\"\n\t\t\t\t\t? t(\"This session's world declares no stats to show here.\")\n\t\t\t\t\t: t(\"Nothing in this session declares world stats. A genre or an extension adds them.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else}\n\t\t{@const owner = view.owner}\n\t\t{#each view.slots as shown (shown.slot.slotId)}\n\t\t\t<SlotControl\n\t\t\t\tslot={shown.slot}\n\t\t\t\tdensity={view.layout === \"strip\" ? \"compact\" : \"full\"}\n\t\t\t\tconfig={shown.config}\n\t\t\t\tvalue={shown.value}\n\t\t\t\t{t}\n\t\t\t\t{findEntries}\n\t\t\t\tonset={(next) => void writer.set(owner, shown.slot.slotId, next)}\n\t\t\t/>\n\t\t{/each}\n\t\t<!-- Phase 4: each location in play, under the world's own slots. -->\n\t\t{#each view.places as place (place.owner.key)}\n\t\t\t<section data-widget-part=\"world-state.place\" data-owner-key={place.owner.key} aria-label={place.owner.label}>\n\t\t\t\t<header data-widget-part=\"world-state.place-head\">\n\t\t\t\t\t<sp-icon name=\"map-pin\" size=\"13\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"world-state.place-name\">{place.owner.label}</span>\n\t\t\t\t</header>\n\t\t\t\t{#each place.slots as shown (shown.slot.slotId)}\n\t\t\t\t\t<SlotControl\n\t\t\t\t\t\tslot={shown.slot}\n\t\t\t\t\t\tdensity={view.layout === \"strip\" ? \"compact\" : \"full\"}\n\t\t\t\t\t\tconfig={shown.config}\n\t\t\t\t\t\tvalue={shown.value}\n\t\t\t\t\t\t{t}\n\t\t\t\t\t\t{findEntries}\n\t\t\t\t\t\tonset={(next) => void writer.set(place.owner, shown.slot.slotId, next)}\n\t\t\t\t\t/>\n\t\t\t\t{/each}\n\t\t\t</section>\n\t\t{/each}\n\t{/if}\n</div>\n","sessions/world-state/world-state.ts":"/**\n * Core's `world-state` component (R21): the session's world stats, as the\n * page's UI worker runs it. `npm run build` compiles it with the CLI's\n * component bundler to `dist/components/world-state.js`, the module the app\n * serves at `/core-ui/world-state`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport WorldState from './WorldState.svelte'\n\nexport default svelteComponent(WorldState)\n"},"sourceHash":"5b44affdf8ef7178ec2eb1043913b475e2aba22cf863f2ae4104d28334b69cd5","catalogVersion":"0.6.0-pr-2"}
1
+ {"slug":"world-state","framework":"svelte","entry":"shared/world-state/world-state.ts","files":{"shared/context.ts":"/**\n * Core's widgets read their widget context with their own `getContext`, so\n * the lookup resolves in whichever Svelte runtime renders them — the\n * component's, in the page's UI worker. The key and the context's shape are\n * the host's contract (`@serene-pub/core-catalog/widgets`). Shared by every\n * core widget (R21); the conversation was the first.\n */\nimport { getContext } from 'svelte'\nimport { WIDGET_CONTEXT_KEY, type WidgetContextRef } from '@serene-pub/core-catalog/widgets'\n\n/** The widget context, if a host provides one; undefined outside a host (tests, a bare mount). */\nexport function useWidgetContext(): WidgetContextRef | undefined {\n\treturn getContext<WidgetContextRef | undefined>(WIDGET_CONTEXT_KEY)\n}\n","shared/state/SlotControl.svelte":"<script lang=\"ts\">\n\t/**\n\t * One attribute slot, drawn as what it is and edited in place — shared by\n\t * core's World State and Stats widgets (R21).\n\t *\n\t * The slot's STAT SHAPE decides the control (`slotKind`: its field, or its\n\t * type when the host predates shapes), and the configuration in force\n\t * decides its bounds: a bounded number is a bar, a choice is a chip over a\n\t * closed set (an `sp-menu` on the chip), a list opens to its items — add,\n\t * remove, move up and down — a story time is read through the calendar\n\t * and opens to its year, month, day and time, text is a line, a boolean is\n\t * a toggle. A derived slot is computed on every read and a retired one\n\t * takes nothing new, so both are shown greyed and never offered.\n\t *\n\t * Every edit here is the USER's, which is the one writer with authority: it\n\t * applies at once (`set-attribute-value`) rather than waiting at the review\n\t * gate. Nothing is applied optimistically — the new value arrives as a\n\t * `session_state` push, so what is drawn a beat later is the resolver's\n\t * answer and not this component's guess. A list is written whole, its\n\t * items in order.\n\t *\n\t * A number or text field commits on Enter, and Escape puts the stored\n\t * value back (R80: the field's `keys`). Leaving the field commits what was\n\t * typed, and only closes it when nothing was — never a write of the value\n\t * already stored. A text field also commits on `change`; a number field\n\t * does not, because the browser raises `change` on every spinner step and\n\t * a person may step several times before they are done. A list's new item\n\t * is added on Enter; a story time is saved on Enter or its Save button —\n\t * it has four fields, so leaving one of them is not being done.\n\t *\n\t * A list that takes lore references (one not closed over words) also\n\t * picks from the session's lorebook (phase 3c): item entries first, then\n\t * the rest of the book, with how many to add — Enter in the count field\n\t * adds, Escape closes the picker. A held reference reads \"Name ×N\" and\n\t * steps up and down; one fewer than one takes it out.\n\t *\n\t * The markup carries no look. A shared control owns its parts under its own\n\t * name, so every element here is `stat-slot.<part>` in `data-widget-part`\n\t * (with a generic part where the element truly is one): a style draws a\n\t * slot once for every widget, and scopes it to one through the widget's\n\t * root (STYLE-GUIDE §6.16). A slot's state is its own `data-*` or ARIA,\n\t * never a part: `data-density`, `data-retired`, `data-slot-shape`,\n\t * `data-empty` (nothing to show), `aria-pressed` (a switch on, a row\n\t * chosen), `role=\"alert\"` (refused).\n\t */\n\timport type { SessionStateSlotV1 } from \"@serene-pub/core-catalog/widgets\"\n\timport {\n\t\tbarView,\n\t\tenumValues,\n\t\tlistItemKeyOf,\n\t\tlistItemRef,\n\t\tlistItemText,\n\t\tlistItemsOf,\n\t\tlistMoved,\n\t\tcountDraftFor,\n\t\tlistWithAdded,\n\t\tlistWithRefAdded,\n\t\tlistWithRefStep,\n\t\tlistWithout,\n\t\tnumberDraftFor,\n\t\tpickableEntries,\n\t\tslotTakesLoreRefs,\n\t\ttype PickableEntry,\n\t\tshownValueText,\n\t\tslotIsWhole,\n\t\tslotKind,\n\t\tslotWritable,\n\t\tstoryTimeDraftOf,\n\t\tstoryTimeDraftValue,\n\t\ttextDraftValue,\n\t\ttype SlotWriteValue,\n\t\ttype StoryTimeDraft\n\t} from \"@serene-pub/core-catalog/session-state\"\n\timport type { HostKeyEventDetail } from \"@serene-pub/sdk/component\"\n\timport type { EntryFinder, EntryFinds } from \"./entryFinder\"\n\n\tinterface Props {\n\t\tslot: SessionStateSlotV1\n\t\t/** The configuration in force for this owner: bounds, options, a list's limits. */\n\t\tconfig: Record<string, unknown>\n\t\tvalue: unknown\n\t\t/** Compact drops the label into the control's own line. */\n\t\tdensity?: \"compact\" | \"full\"\n\t\t/** The widget's language. */\n\t\tt: (source: string) => string\n\t\t/** `null` clears this layer, so the read inherits again. */\n\t\tonset: (value: SlotWriteValue) => void\n\t\t/** Searches the session's lorebook for a list's picker; absent, a list adds words only. */\n\t\tfindEntries?: EntryFinder\n\t}\n\n\tlet { slot, config, value, density = \"full\", t, onset, findEntries }: Props = $props()\n\n\t/** A menu item's value for \"not set\" — never an option's, which are `opt:`-prefixed. */\n\tconst CLEAR = \"clear\"\n\n\tlet editing = $state(false)\n\tlet numberDraft = $state<number | null>(null)\n\tlet textDraft = $state(\"\")\n\tlet itemDraft = $state(\"\")\n\tlet timeDraft = $state<StoryTimeDraft>({ year: \"\", month: \"\", day: \"\", time: \"\" })\n\t/** Why the editor's last attempt wrote nothing — a list over its limit, a time that is not one. */\n\tlet invalid = $state<string | null>(null)\n\t/** The drafts as the field opened, so leaving it untouched writes nothing. */\n\tlet numberOpened: number | null = null\n\tlet textOpened = \"\"\n\n\t// The lorebook picker, inside a list's editor.\n\tlet picking = $state(false)\n\tlet pickWords = $state(\"\")\n\tlet pickCount = $state<number | null>(1)\n\tlet pickFound = $state<EntryFinds | null>(null)\n\tlet pickChosen = $state<number | null>(null)\n\tlet pickBusy = $state(false)\n\t/** The newest search owns the list: an older answer that lands late is dropped. */\n\tlet searches = 0\n\n\tlet kind = $derived(slotKind(slot))\n\tlet bar = $derived(kind === \"number\" ? barView(value, config as { min?: number; max?: number }) : null)\n\tlet options = $derived(enumValues(config))\n\tlet items = $derived(listItemsOf(value))\n\tlet canPick = $derived(!!findEntries && slotTakesLoreRefs(config))\n\tlet offered = $derived<PickableEntry[]>(pickFound ? pickableEntries(value, pickFound.pages) : [])\n\tlet offeredItems = $derived(offered.filter((e) => e.item))\n\tlet offeredOthers = $derived(offered.filter((e) => !e.item))\n\tlet chosen = $derived(offered.find((e) => e.entryId === pickChosen) ?? null)\n\tlet writable = $derived(slotWritable(slot))\n\tlet shown = $derived(shownValueText(slot, value, t))\n\tlet notSet = $derived(t(\"not set\"))\n\tlet fieldLabel = $derived(t(\"{label} value\").replace(\"{label}\", slot.label))\n\tlet editLabel = $derived(t(\"{label}, edit\").replace(\"{label}\", slot.label))\n\tlet barEditLabel = $derived(\n\t\tbar ? t(\"{label} {value}, edit\").replace(\"{label}\", slot.label).replace(\"{value}\", bar.label) : editLabel\n\t)\n\n\tfunction open() {\n\t\tif (!writable) return\n\t\tnumberDraft = numberOpened = typeof value === \"number\" ? value : null\n\t\ttextDraft = textOpened = value === undefined || value === null ? \"\" : String(value)\n\t\titemDraft = \"\"\n\t\ttimeDraft = storyTimeDraftOf(value)\n\t\tinvalid = null\n\t\tpicking = false\n\t\tediting = true\n\t}\n\n\t/** One commit per edit: Enter and `change` may both arrive for one. */\n\tfunction commitNumber() {\n\t\tif (!editing) return\n\t\tediting = false\n\t\tconst next = numberDraftFor(numberDraft, config as { min?: number; max?: number }, slotIsWhole(slot))\n\t\tif (next !== undefined) onset(next)\n\t}\n\n\tfunction commitText() {\n\t\tif (!editing) return\n\t\tediting = false\n\t\tonset(textDraftValue(textDraft, config as { maxLength?: unknown }))\n\t}\n\n\t/** Enter commits; Escape leaves the stored value as it was. */\n\tfunction onkey(e: CustomEvent<HostKeyEventDetail>, commit: () => void) {\n\t\tif (e.detail.key === \"Enter\") commit()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n\n\t/** Leaving the field: commit what was typed, or just close it. */\n\tfunction onblur(unchanged: boolean, commit: () => void) {\n\t\tif (!editing) return\n\t\tif (unchanged) editing = false\n\t\telse commit()\n\t}\n\n\tfunction pick(e: CustomEvent<{ value: string }>) {\n\t\tconst v = e.detail.value\n\t\tif (v === CLEAR) onset(null)\n\t\telse if (v.startsWith(\"opt:\")) onset(v.slice(4))\n\t}\n\n\t// ── A list: every change writes the whole list, and the editor stays open ──\n\n\tfunction addItem() {\n\t\tconst edit = listWithAdded(value, itemDraft, config)\n\t\tif (!edit) return\n\t\tif (edit.refusal) {\n\t\t\tinvalid = edit.refusal\n\t\t\treturn\n\t\t}\n\t\tinvalid = null\n\t\titemDraft = \"\"\n\t\tonset(edit.value)\n\t}\n\n\tfunction onItemKey(e: CustomEvent<HostKeyEventDetail>) {\n\t\tif (e.detail.key === \"Enter\") addItem()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n\n\t// ── A list's lorebook picker: choose an entry, say how many, add ──\n\n\tasync function search() {\n\t\tif (!findEntries) return\n\t\tconst mine = ++searches\n\t\tpickBusy = true\n\t\ttry {\n\t\t\tconst found = await findEntries(pickWords)\n\t\t\tif (mine !== searches) return\n\t\t\tpickFound = found\n\t\t\tif (pickChosen !== null && !found.pages.some((p) => p.some((r) => r.id === pickChosen))) pickChosen = null\n\t\t} catch (e) {\n\t\t\tif (mine !== searches) return\n\t\t\tpickFound = { pages: [], notice: e instanceof Error ? e.message : String(e) }\n\t\t} finally {\n\t\t\tif (mine === searches) pickBusy = false\n\t\t}\n\t}\n\n\tfunction openPicker() {\n\t\tpicking = true\n\t\tpickWords = \"\"\n\t\tpickCount = 1\n\t\tpickChosen = null\n\t\tpickFound = null\n\t\tinvalid = null\n\t\tvoid search()\n\t}\n\n\tfunction closePicker() {\n\t\tpicking = false\n\t\tpickChosen = null\n\t}\n\n\tfunction addPicked() {\n\t\tif (!chosen) {\n\t\t\tinvalid = t(\"Choose an entry to add first.\")\n\t\t\treturn\n\t\t}\n\t\tconst count = countDraftFor(pickCount)\n\t\tif (count === undefined) {\n\t\t\tinvalid = t(\"How many is a whole number, 1 or more.\")\n\t\t\treturn\n\t\t}\n\t\tconst edit = listWithRefAdded(value, chosen.entryId, count, config)\n\t\tif (edit.refusal) {\n\t\t\tinvalid = edit.refusal\n\t\t\treturn\n\t\t}\n\t\tinvalid = null\n\t\tpickCount = 1\n\t\tonset(edit.value)\n\t}\n\n\tfunction onPickKey(e: CustomEvent<HostKeyEventDetail>, enter: () => void) {\n\t\tif (e.detail.key === \"Enter\") enter()\n\t\telse if (e.detail.key === \"Escape\") closePicker()\n\t}\n\n\t// ── A story time: four fields, saved together ──\n\n\tfunction commitTime() {\n\t\tif (!editing) return\n\t\tconst next = storyTimeDraftValue(timeDraft)\n\t\tif (next === undefined) {\n\t\t\tinvalid = t(\"That is not a story time: a year, then a month, a day and a time as hh:mm — each optional, a day only with a month.\")\n\t\t\treturn\n\t\t}\n\t\tediting = false\n\t\tinvalid = null\n\t\tonset(next)\n\t}\n\n\tfunction onTimeKey(e: CustomEvent<HostKeyEventDetail>) {\n\t\tif (e.detail.key === \"Enter\") commitTime()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n</script>\n\n<div\n\tdata-widget-part=\"stat-slot.root row\"\n\tdata-density={density}\n\tdata-slot-id={slot.slotId}\n\tdata-slot-type={slot.type}\n\tdata-slot-shape={kind}\n\tdata-retired={slot.retired ? \"\" : undefined}\n>\n\t<span data-widget-part=\"stat-slot.label label\" title={slot.description ?? slot.label}>\n\t\t{slot.label}\n\t\t{#if slot.required}\n\t\t\t<span data-widget-part=\"stat-slot.required\" role=\"img\" aria-label={t(\"required\")} title={t(\"required\")}>*</span>\n\t\t{/if}\n\t\t{#if slot.retired}\n\t\t\t<sp-icon name=\"archive\" size=\"10\" label={t(\"retired\")}></sp-icon>\n\t\t{:else if kind === \"derived\"}\n\t\t\t<sp-icon name=\"sigma\" size=\"10\"></sp-icon>\n\t\t{/if}\n\t</span>\n\n\t<div data-widget-part=\"stat-slot.control\">\n\t\t{#if kind === \"boolean\" && writable}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\taria-pressed={value === true}\n\t\t\t\tonclick={() => onset(value === true ? false : true)}\n\t\t\t>\n\t\t\t\t{value === undefined ? notSet : shown}\n\t\t\t</button>\n\t\t{:else if editing && kind === \"number\"}\n\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t<input\n\t\t\t\tdata-widget-part=\"stat-slot.field\"\n\t\t\t\ttype=\"number\"\n\t\t\t\taria-label={fieldLabel}\n\t\t\t\tmin={(config as { min?: number }).min}\n\t\t\t\tmax={(config as { max?: number }).max}\n\t\t\t\tstep={slotIsWhole(slot) ? \"1\" : \"any\"}\n\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\tautofocus\n\t\t\t\tbind:value={numberDraft}\n\t\t\t\tonblur={() => onblur(numberDraft === numberOpened, commitNumber)}\n\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onkey(e, commitNumber)}\n\t\t\t/>\n\t\t{:else if editing && kind === \"list\"}\n\t\t\t<div data-widget-part=\"stat-slot.editor\" role=\"group\" aria-label={fieldLabel}>\n\t\t\t\t{#if items.length}\n\t\t\t\t\t<ol data-widget-part=\"stat-slot.items list\">\n\t\t\t\t\t\t{#each items as item, i (listItemKeyOf(item, i))}\n\t\t\t\t\t\t\t{@const itemText = listItemText(item, t)}\n\t\t\t\t\t\t\t{@const ref = listItemRef(item)}\n\t\t\t\t\t\t\t<li data-widget-part=\"stat-slot.item row\" data-item-index={i}>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.item-text label\">{itemText}</span>\n\t\t\t\t\t\t\t\t{#if ref}\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-less\"\n\t\t\t\t\t\t\t\t\t\taria-label={t(\"One fewer {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithRefStep(value, ref.entryId, -1))}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"minus\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-more\"\n\t\t\t\t\t\t\t\t\t\taria-label={t(\"One more {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithRefStep(value, ref.entryId, 1))}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"plus\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-up\"\n\t\t\t\t\t\t\t\t\tdisabled={i === 0}\n\t\t\t\t\t\t\t\t\taria-label={t(\"Move {item} up\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listMoved(value, i, -1))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"arrow-up\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-down\"\n\t\t\t\t\t\t\t\t\tdisabled={i === items.length - 1}\n\t\t\t\t\t\t\t\t\taria-label={t(\"Move {item} down\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listMoved(value, i, 1))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"arrow-down\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-remove\"\n\t\t\t\t\t\t\t\t\taria-label={t(\"Remove {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithout(value, i))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"x\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</ol>\n\t\t\t\t{:else}\n\t\t\t\t\t<p data-widget-part=\"stat-slot.items-empty empty\">{t(\"Nothing in the list yet.\")}</p>\n\t\t\t\t{/if}\n\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.add stat-slot.field\"\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\taria-label={t(\"Add to {label}\").replace(\"{label}\", slot.label)}\n\t\t\t\t\tplaceholder={t(\"Add an item, then Enter\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tautofocus\n\t\t\t\t\tbind:value={itemDraft}\n\t\t\t\t\tonkey={onItemKey}\n\t\t\t\t/>\n\t\t\t\t{#if canPick && !picking}\n\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-open\" onclick={openPicker}>\n\t\t\t\t\t\t<sp-icon name=\"book-open\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t<span>{t(\"Add from the lorebook\")}</span>\n\t\t\t\t\t</button>\n\t\t\t\t{:else if canPick}\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"stat-slot.picker\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={t(\"Add to {label} from the lorebook\").replace(\"{label}\", slot.label)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-search stat-slot.field\"\n\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\taria-label={t(\"Search the lorebook\")}\n\t\t\t\t\t\t\tplaceholder={t(\"Search by name or key, then Enter\")}\n\t\t\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\t\t\tautofocus\n\t\t\t\t\t\t\tbind:value={pickWords}\n\t\t\t\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onPickKey(e, () => void search())}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{#if !pickFound}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Searching the lorebook…\")}</p>\n\t\t\t\t\t\t{:else if pickFound.notice}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{pickFound.notice}</p>\n\t\t\t\t\t\t{:else if !offered.length}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Nothing in the lorebook matches.\")}</p>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t{#each [{ heading: t(\"Items\"), rows: offeredItems, group: \"items\" }, { heading: t(\"Other entries\"), rows: offeredOthers, group: \"others\" }] as part (part.group)}\n\t\t\t\t\t\t\t\t{#if part.rows.length}\n\t\t\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-heading\">{part.heading}</p>\n\t\t\t\t\t\t\t\t\t<ul data-widget-part=\"stat-slot.pick-list list\" aria-label={part.heading} data-pick-group={part.group}>\n\t\t\t\t\t\t\t\t\t\t{#each part.rows as entry (entry.entryId)}\n\t\t\t\t\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-entry row\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata-entry-id={entry.entryId}\n\t\t\t\t\t\t\t\t\t\t\t\t\taria-pressed={pickChosen === entry.entryId}\n\t\t\t\t\t\t\t\t\t\t\t\t\tonclick={() => (pickChosen = pickChosen === entry.entryId ? null : entry.entryId)}\n\t\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.pick-title label\">{entry.title}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{#if entry.held}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.pick-held\">{t(\"held ×{n}\").replace(\"{n}\", String(entry.held))}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if pickBusy && pickFound}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Searching the lorebook…\")}</p>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<div data-widget-part=\"stat-slot.pick-add toolbar\">\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-count stat-slot.field\"\n\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\tmin=\"1\"\n\t\t\t\t\t\t\t\tstep=\"1\"\n\t\t\t\t\t\t\t\taria-label={chosen ? t(\"How many {item} to add\").replace(\"{item}\", chosen.title) : t(\"How many to add\")}\n\t\t\t\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\t\t\t\tbind:value={pickCount}\n\t\t\t\t\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onPickKey(e, addPicked)}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-confirm\" disabled={!chosen} onclick={addPicked}>\n\t\t\t\t\t\t\t\t{chosen ? t(\"Add {item}\").replace(\"{item}\", chosen.title) : t(\"Add\")}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-close\" onclick={closePicker}>{t(\"Close\")}</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t\t{#if invalid}<p data-widget-part=\"stat-slot.invalid\" role=\"alert\">{invalid}</p>{/if}\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.done\" onclick={() => (editing = false)}>{t(\"Done\")}</button>\n\t\t\t</div>\n\t\t{:else if editing && kind === \"story-time\"}\n\t\t\t<div data-widget-part=\"stat-slot.editor\" role=\"group\" aria-label={fieldLabel}>\n\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.year stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Year\")}\n\t\t\t\t\tplaceholder={t(\"Year\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tautofocus\n\t\t\t\t\tbind:value={timeDraft.year}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.month stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tmin=\"1\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Month\")}\n\t\t\t\t\tplaceholder={t(\"Month\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.month}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.day stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tmin=\"1\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Day\")}\n\t\t\t\t\tplaceholder={t(\"Day\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.day}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.clock stat-slot.field\"\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\taria-label={t(\"Time of day\")}\n\t\t\t\t\tplaceholder=\"hh:mm\"\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.time}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t{#if invalid}<p data-widget-part=\"stat-slot.invalid\" role=\"alert\">{invalid}</p>{/if}\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.save\" onclick={commitTime}>{t(\"Save\")}</button>\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.cancel\" onclick={() => (editing = false)}>{t(\"Cancel\")}</button>\n\t\t\t</div>\n\t\t{:else if editing}\n\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t<input\n\t\t\t\tdata-widget-part=\"stat-slot.field\"\n\t\t\t\ttype=\"text\"\n\t\t\t\taria-label={fieldLabel}\n\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\tautofocus\n\t\t\t\tbind:value={textDraft}\n\t\t\t\tonchange={commitText}\n\t\t\t\tonblur={() => onblur(textDraft === textOpened, commitText)}\n\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onkey(e, commitText)}\n\t\t\t/>\n\t\t{:else if bar}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.bar\"\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={barEditLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t<span data-widget-part=\"stat-slot.track meter\">\n\t\t\t\t\t<span data-widget-part=\"stat-slot.fill\" style:--sp-fill=\"{bar.percent}%\"></span>\n\t\t\t\t</span>\n\t\t\t\t<span data-widget-part=\"stat-slot.bar-value value\">{bar.label}</span>\n\t\t\t</button>\n\t\t{:else if kind === \"choice\" && writable}\n\t\t\t<!-- The chip opens the closed set; picking one writes it. -->\n\t\t\t<sp-menu label={fieldLabel} onselect={pick}>\n\t\t\t\t<button\n\t\t\t\t\tslot=\"trigger\"\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\t\tdata-empty={value == null ? \"\" : undefined}\n\t\t\t\t\taria-label={editLabel}\n\t\t\t\t>\n\t\t\t\t\t{shown || notSet}\n\t\t\t\t</button>\n\t\t\t\t<sp-menu-item value={CLEAR} data-widget-part=\"stat-slot.option\" data-empty=\"\">{notSet}</sp-menu-item>\n\t\t\t\t{#each options as option (option)}\n\t\t\t\t\t<sp-menu-item value=\"opt:{option}\" data-widget-part=\"stat-slot.option\">\n\t\t\t\t\t\t{#if value === option}<sp-icon name=\"check\" size=\"12\" label={t(\"current\")}></sp-icon>{/if}\n\t\t\t\t\t\t<span>{option}</span>\n\t\t\t\t\t</sp-menu-item>\n\t\t\t\t{/each}\n\t\t\t</sp-menu>\n\t\t{:else if kind === \"choice\"}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\tdata-empty={value == null ? \"\" : undefined}\n\t\t\t\tdisabled\n\t\t\t\taria-label={editLabel}\n\t\t\t>\n\t\t\t\t{shown || notSet}\n\t\t\t</button>\n\t\t{:else if kind === \"list\"}\n\t\t\t<!-- A list reads as its items; opening it edits them. -->\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.line value\"\n\t\t\t\tdata-empty={items.length ? undefined : \"\"}\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={editLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t{items.length ? shown : value === undefined ? notSet : t(\"none\")}\n\t\t\t</button>\n\t\t{:else}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.line value\"\n\t\t\t\tdata-empty={value === undefined ? \"\" : undefined}\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={editLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t{shown || notSet}\n\t\t\t</button>\n\t\t{/if}\n\t</div>\n</div>\n","shared/state/entryFinder.ts":"/**\n * 🚧 A state widget's lorebook search for a list's picker (attributes phase\n * 3c): the session's book through `session-entries`, item entries asked for\n * first (`typeIds`), then the rest of the book — two pages the picker merges\n * (`pickableEntries`), so the items lead even in a book too big for one page.\n *\n * A session that reads no lorebook, and a viewer who does not own the book,\n * are told so in words (`notice`) rather than shown an empty list that reads\n * as \"nothing to pick\". A declined request rejects, and the picker says why.\n */\nimport type { WidgetContextRef } from \"@serene-pub/core-catalog/widgets\"\nimport { ITEM_ENTRY_TYPE_ID } from \"@serene-pub/core-catalog/session-state\"\n\n/** One row the picker can offer, as `session-entries` answered it. */\nexport interface FoundEntry {\n\tid: number\n\ttypeId: string\n\ttitle: string\n}\n\n/** What one search found: the item page, then the book's page; or why there is nothing. */\nexport interface EntryFinds {\n\tpages: FoundEntry[][]\n\tnotice: string | null\n}\n\n/** Search the session's lorebook by title or key; blank is the whole book. */\nexport type EntryFinder = (titleOrKey: string) => Promise<EntryFinds>\n\n/** How many of each the picker shows before the search has to narrow it. */\nconst PAGE = 25\n\nexport function createEntryFinder(\n\twidget: WidgetContextRef | undefined,\n\tt: (source: string) => string\n): EntryFinder | undefined {\n\tif (!widget) return undefined\n\treturn async (titleOrKey) => {\n\t\tconst words = titleOrKey.trim()\n\t\tconst ask = (typeIds?: string[]) =>\n\t\t\twidget.current.request(\"session-entries\", {\n\t\t\t\t...(words ? { titleOrKey: words } : {}),\n\t\t\t\tsort: \"name\",\n\t\t\t\t...(typeIds ? { typeIds } : {}),\n\t\t\t\tlimit: PAGE\n\t\t\t})\n\t\tconst items = await ask([ITEM_ENTRY_TYPE_ID])\n\t\tif (items.lorebookId == null) return { pages: [], notice: t(\"This session reads no lorebook, so there is nothing to pick from.\") }\n\t\tif (items.ownerOnly)\n\t\t\treturn { pages: [], notice: t(\"Only the lorebook's owner can pick from it. Type the item's name instead.\") }\n\t\tconst rest = await ask()\n\t\tconst rows = (page: { rows: FoundEntry[] }) => page.rows.map(({ id, typeId, title }) => ({ id, typeId, title }))\n\t\treturn { pages: [rows(items), rows(rest)], notice: null }\n\t}\n}\n","shared/state/slotWriter.svelte.ts":"/**\n * A state widget's writes (R21): `set-attribute-value` through the widget's\n * own context, and the widget's OWN error line (R77) — a write that fails is\n * said in the widget that asked, never in every state widget on the page.\n *\n * The newest write owns the line: asking again clears it, and a refusal of\n * an older write that lands after a newer one was asked says nothing.\n */\nimport type { SessionStateOwnerV1, WidgetContextRef } from \"@serene-pub/core-catalog/widgets\"\nimport type { SlotWriteValue } from \"@serene-pub/core-catalog/session-state\"\n\nexport interface SlotWriter {\n\t/** Why the newest write failed, in words; null when it did not (or has not answered). */\n\treadonly error: string | null\n\tset(owner: SessionStateOwnerV1, slotId: string, value: SlotWriteValue): Promise<void>\n}\n\nexport function createSlotWriter(widget: WidgetContextRef | undefined): SlotWriter {\n\tlet error = $state<string | null>(null)\n\tlet asked = 0\n\treturn {\n\t\tget error() {\n\t\t\treturn error\n\t\t},\n\t\tasync set(owner, slotId, value) {\n\t\t\tconst mine = ++asked\n\t\t\terror = null\n\t\t\tif (!widget) return\n\t\t\ttry {\n\t\t\t\tawait widget.current.request(\"set-attribute-value\", {\n\t\t\t\t\towner: { kind: owner.kind, id: owner.id },\n\t\t\t\t\tslotId,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t} catch (e) {\n\t\t\t\tif (mine === asked) error = e instanceof Error ? e.message : String(e)\n\t\t\t}\n\t\t}\n\t}\n}\n","shared/widgetRef.svelte.ts":"/**\n * A remote's widget context (C0b): the component context a UI worker hands\n * a component, as the native `WidgetContext` core's widgets read\n * (`useWidgetContext`). So a core widget — written against the native\n * context — runs in a worker with no change to its source: the same\n * sections, the same verbs, reaching the host over the component's port.\n * Shared by every core widget (R21); the conversation was the first.\n */\nimport {\n\tEMPTY_TURN_ORDER,\n\tWIDGET_PROTOCOL,\n\ttype ComponentContext,\n\ttype LayoutV1,\n\ttype ViewerV1,\n\ttype WidgetEvent,\n\ttype WidgetEventKind\n} from \"@serene-pub/sdk/component\"\nimport {\n\tWIDGET_SCOPED_SECTIONS,\n\ttype WidgetContext,\n\ttype WidgetContextRef,\n\ttype WidgetScopedData\n} from \"@serene-pub/core-catalog/widgets\"\n\n/** Every scoped section's posted name — the SDK's one table, read once. */\nconst SCOPED_NAMES = Object.values(WIDGET_SCOPED_SECTIONS)\n\nconst NOBODY: ViewerV1 = { userId: null, isAdmin: false, isGuest: false }\n\n/**\n * A remote's context carries its saved view state besides: what it saved\n * last mount (`state`) and the host's save-state channel (`saveState`) —\n * read by core's widgets off the context where a remote has them.\n */\ntype RemoteWidgetContext = WidgetContext & {\n\tstate: unknown\n\tsaveState: (state: unknown) => void\n}\n\n/** The granted scoped sections as the envelope carries them: `{ <name>: { v1 } }`, absent when not granted. */\nfunction scopedData(scoped: ComponentContext[\"scoped\"]): WidgetScopedData {\n\tconst out: Record<string, { v1: unknown }> = {}\n\tfor (const name of SCOPED_NAMES) if (scoped[name] !== undefined) out[name] = { v1: scoped[name] }\n\treturn out as WidgetScopedData\n}\n\nexport function widgetRefFromComponent(\n\tctx: ComponentContext,\n\twidget: WidgetContext[\"widget\"]\n): WidgetContextRef {\n\t// Any section the host pushes re-projects the context, as a native\n\t// host's re-projection does.\n\tlet version = $state(0)\n\tctx.subscribe(() => version++)\n\n\tconst current = $derived.by((): RemoteWidgetContext => {\n\t\tvoid version\n\t\tconst scoped = ctx.scoped ?? {}\n\t\treturn {\n\t\t\tprotocol: WIDGET_PROTOCOL,\n\t\t\twidget,\n\t\t\tlayout: { v1: (ctx.layout ?? {}) as LayoutV1 },\n\t\t\tsession: { v1: (ctx.session ?? { id: 0, name: null }) as WidgetContext[\"session\"][\"v1\"] },\n\t\t\tchannels: { v1: Object.keys(ctx.channels ?? {}) },\n\t\t\tmessages: { v1: (ctx.messages ?? []) as WidgetContext[\"messages\"][\"v1\"] },\n\t\t\tprops: { v1: ctx.props ?? {} },\n\t\t\tactions: { v1: (ctx.actions ?? {}) as WidgetContext[\"actions\"][\"v1\"] },\n\t\t\tsettings: { v1: ctx.settings ?? {} },\n\t\t\tannex: { v1: (ctx.annex ?? {}) as WidgetContext[\"annex\"][\"v1\"] },\n\t\t\tlocale: { v1: ctx.locale ?? \"en\" },\n\t\t\tviewer: { v1: ctx.viewer ?? NOBODY },\n\t\t\tturnOrder: { v1: ctx.turnOrder ?? EMPTY_TURN_ORDER },\n\t\t\t// What the host said this widget holds — absent until it has — so a\n\t\t\t// widget can tell a scope never granted apart from a section not yet posted.\n\t\t\tgrants: ctx.grants,\n\t\t\t// The scoped sections the host granted, each as its `{ v1 }` bag — by\n\t\t\t// the table, so a section the SDK adds arrives with no change here.\n\t\t\t...scopedData(scoped),\n\t\t\taction: (fn, messageId, payload, action, blockId) => ctx.action(fn, messageId, payload, action, blockId),\n\t\t\tinvoke: (key, args) => ctx.invoke(key, args),\n\t\t\trequest: ((kind, params) => ctx.request(kind, params)) as WidgetContext[\"request\"],\n\t\t\t// No host menu across the port yet: dismissed, as a native host without one answers.\n\t\t\tmenu: async () => null,\n\t\t\ton: (kind: WidgetEventKind | \"*\", cb: (e: WidgetEvent) => void) =>\n\t\t\t\tctx.onEvent((e) => {\n\t\t\t\t\tconst ev = e as WidgetEvent\n\t\t\t\t\tif (kind === \"*\" || ev.kind === kind) cb(ev)\n\t\t\t\t}),\n\t\t\tt: (source) => ctx.t(source),\n\t\t\tstate: ctx.state,\n\t\t\tsaveState: (state) => ctx.saveState(state)\n\t\t}\n\t})\n\n\treturn {\n\t\tget current() {\n\t\t\treturn current\n\t\t}\n\t}\n}\n","shared/world-state/WorldState.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's World State widget as a remote component (R21): the component\n\t * context, as the widget context, around the widget.\n\t */\n\timport { setContext, untrack } from \"svelte\"\n\timport type { ComponentContext } from \"@serene-pub/sdk/component\"\n\timport { WIDGET_CONTEXT_KEY } from \"@serene-pub/core-catalog/widgets\"\n\timport WorldStateWidget from \"./WorldStateWidget.svelte\"\n\timport { widgetRefFromComponent } from \"../widgetRef.svelte\"\n\n\tlet { ctx }: { ctx: ComponentContext } = $props()\n\n\t// The context is the mount's, handed once: its sections move, it does not.\n\tsetContext(\n\t\tWIDGET_CONTEXT_KEY,\n\t\twidgetRefFromComponent(\n\t\t\tuntrack(() => ctx),\n\t\t\t{ id: \"world-state\", instanceId: \"world-state\", title: \"World State\" }\n\t\t)\n\t)\n</script>\n\n<WorldStateWidget />\n","shared/world-state/WorldStateWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * The World State widget: the session's world slots, editable (R21).\n\t *\n\t * The same values a template reads as `state.world.*` and the conditions\n\t * vocabulary reads for layout rules — so what is edited here is what the\n\t * model is told and what a rule fires on, which is why it is worth one\n\t * strip above the messages rather than a page somewhere else.\n\t *\n\t * A world slot belongs to the session's own owner, so an edit is a\n\t * session-layer deviation: the world's own answer is untouched, and clearing\n\t * one goes back to inheriting it. Reads the `session_state` section and its\n\t * settings (`layout`, `slots`, `pickSlots`); writes `set-attribute-value`,\n\t * whose refusal is this widget's own line (R77).\n\t *\n\t * 🚧 A location holding state (attributes phase 4) is drawn as a place\n\t * under the world's slots — only one with a value in play.\n\t *\n\t * The markup carries no look: each element names what it is in\n\t * `data-widget-part` (`world-state.place`, …), the layout rides on\n\t * `data-layout`, and the default widget stylesheet draws them\n\t * (STYLE-GUIDE §6.16).\n\t */\n\timport { worldStateView } from \"@serene-pub/core-catalog/session-state\"\n\timport { useWidgetContext } from \"../context\"\n\timport SlotControl from \"../state/SlotControl.svelte\"\n\timport { createSlotWriter } from \"../state/slotWriter.svelte\"\n\timport { createEntryFinder } from \"../state/entryFinder\"\n\n\tconst widget = useWidgetContext()\n\tconst writer = createSlotWriter(widget)\n\tconst t = (source: string) => widget?.current.t(source) ?? source\n\t// A list's lorebook picker (phase 3c) searches through `session-entries`.\n\tconst findEntries = createEntryFinder(widget, t)\n\n\tlet section = $derived(widget?.current.session_state?.v1)\n\tlet settings = $derived((widget?.current.settings.v1 ?? {}) as Record<string, unknown>)\n\t// Not granted `session:state`: the section will never come — said, not waited for.\n\tlet view = $derived(worldStateView(section, settings, widget?.current.grants?.includes(\"session:state\")))\n</script>\n\n<div\n\tdata-widget-part=\"world-state.root\"\n\tdata-layout={view.layout === \"strip\" ? \"strip\" : \"list\"}\n\tdata-state-widget=\"world-state\"\n\tdata-owner-key=\"world\"\n>\n\t{#if section?.error}\n\t\t<p data-widget-part=\"world-state.alert\" role=\"alert\">{section.error}</p>\n\t{/if}\n\t{#if writer.error}\n\t\t<p data-widget-part=\"world-state.alert\" role=\"alert\">{writer.error}</p>\n\t{/if}\n\n\t{#if view.status === \"not-granted\"}\n\t\t<div data-widget-part=\"world-state.empty empty\" role=\"status\" data-scope-not-granted=\"session:state\">\n\t\t\t<sp-icon name=\"lock\" size=\"16\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{t(\"This widget has not been granted the session's stats. An administrator can grant it in the extension's permissions.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else if view.status === \"loading\"}\n\t\t<div data-widget-part=\"world-state.empty empty\" role=\"status\">\n\t\t\t<sp-icon name=\"cloud-sun\" size=\"16\"></sp-icon>\n\t\t\t<span>{t(\"Loading the world's stats…\")}</span>\n\t\t</div>\n\t{:else if view.status === \"failed\"}\n\t\t<!-- The first read was refused: the alert above is the whole story. -->\n\t{:else if view.status === \"empty\"}\n\t\t<div data-widget-part=\"world-state.empty empty\">\n\t\t\t<sp-icon name=\"cloud-sun\" size=\"16\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{view.reason === \"none-shown\"\n\t\t\t\t\t? t(\"This session's world declares no stats to show here.\")\n\t\t\t\t\t: t(\"Nothing in this session declares world stats. A genre or an extension adds them.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else}\n\t\t{@const owner = view.owner}\n\t\t{#each view.slots as shown (shown.slot.slotId)}\n\t\t\t<SlotControl\n\t\t\t\tslot={shown.slot}\n\t\t\t\tdensity={view.layout === \"strip\" ? \"compact\" : \"full\"}\n\t\t\t\tconfig={shown.config}\n\t\t\t\tvalue={shown.value}\n\t\t\t\t{t}\n\t\t\t\t{findEntries}\n\t\t\t\tonset={(next) => void writer.set(owner, shown.slot.slotId, next)}\n\t\t\t/>\n\t\t{/each}\n\t\t<!-- Phase 4: each location in play, under the world's own slots. -->\n\t\t{#each view.places as place (place.owner.key)}\n\t\t\t<section data-widget-part=\"world-state.place\" data-owner-key={place.owner.key} aria-label={place.owner.label}>\n\t\t\t\t<header data-widget-part=\"world-state.place-head\">\n\t\t\t\t\t<sp-icon name=\"map-pin\" size=\"13\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"world-state.place-name\">{place.owner.label}</span>\n\t\t\t\t</header>\n\t\t\t\t{#each place.slots as shown (shown.slot.slotId)}\n\t\t\t\t\t<SlotControl\n\t\t\t\t\t\tslot={shown.slot}\n\t\t\t\t\t\tdensity={view.layout === \"strip\" ? \"compact\" : \"full\"}\n\t\t\t\t\t\tconfig={shown.config}\n\t\t\t\t\t\tvalue={shown.value}\n\t\t\t\t\t\t{t}\n\t\t\t\t\t\t{findEntries}\n\t\t\t\t\t\tonset={(next) => void writer.set(place.owner, shown.slot.slotId, next)}\n\t\t\t\t\t/>\n\t\t\t\t{/each}\n\t\t\t</section>\n\t\t{/each}\n\t{/if}\n</div>\n","shared/world-state/world-state.ts":"/**\n * Core's `world-state` component (R21): the session's world stats, as the\n * page's UI worker runs it. `npm run build` compiles it with the CLI's\n * component bundler to `dist/components/world-state.js`, the module the app\n * serves at `/core-ui/world-state`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport WorldState from './WorldState.svelte'\n\nexport default svelteComponent(WorldState)\n"},"sourceHash":"b826757c3487d5ad81a66288e034cdf1069d62e9668b4f6a0ceb044aad93ac06","catalogVersion":"0.6.0-pr-4"}
@@ -23,8 +23,10 @@
23
23
  * A spec has one inlet lock and a preset binds a spec whose lock names the
24
24
  * preset's genre (24 §4), so the pipeline is declared once here and
25
25
  * published once per shipped genre — one each for chat, adventure, guide
26
- * and lair. Chat and Guide reuse the same authored prompt row; a plugin
27
- * genre publishes its own through the same builder, naming its own row.
26
+ * and lair, each named genre first like every genre pipeline
27
+ * (`core:spec/<genre>-answer-form`, in `genres/<genre>/answerForm.ts`).
28
+ * Chat and Guide reuse the same authored prompt row; a plugin genre
29
+ * publishes its own through the same builder, naming its own row.
28
30
  *
29
31
  * ⚠ **Every shipped genre binds one, whatever its own forms look like**
30
32
  * (ruled 2026-09-17). A genre cannot promise that no pipeline — its own, one
@@ -55,18 +57,6 @@
55
57
  import { type GenreDecl } from '@serene-pub/sdk';
56
58
  /** @internal */
57
59
  export declare const ANSWER_FORM_VERSION = "1.0.0";
58
- /** The one spec id prefix every answer pipeline core ships shares. @internal */
59
- export declare const ANSWER_FORM_SPEC_PREFIX = "core:spec/answer-form-";
60
- /** @internal */
61
- export declare const ANSWER_FORM_CHAT_SPEC_ID = "core:spec/answer-form-chat";
62
- /** @internal */
63
- export declare const ANSWER_FORM_ADVENTURE_SPEC_ID = "core:spec/answer-form-adventure";
64
- /** @internal */
65
- export declare const ANSWER_FORM_GUIDE_SPEC_ID = "core:spec/answer-form-guide";
66
- /** @internal */
67
- export declare const ANSWER_FORM_LAIR_SPEC_ID = "core:spec/answer-form-lair";
68
- /** Every answer pipeline core ships, by the genre it serves. @internal */
69
- export declare const ANSWER_FORM_SPEC_IDS: Readonly<Record<string, string>>;
70
60
  /**
71
61
  * The assembly template. Triple-stashed like every shipped context template:
72
62
  * prose going to a model, not markup going to a browser. Each line renders its
@@ -96,20 +86,4 @@ export interface AnswerFormOptions {
96
86
  * @experimental
97
87
  */
98
88
  export declare const answerFormSpec: (id: string, genre: GenreDecl, options?: AnswerFormOptions) => import("@serene-pub/sdk").SpecDocument;
99
- /** @internal */
100
- export declare const answerFormChatSpec: () => import("@serene-pub/sdk").SpecDocument;
101
- /** @internal */
102
- export declare const answerFormAdventureSpec: () => import("@serene-pub/sdk").SpecDocument;
103
- /** @internal */
104
- export declare const answerFormGuideSpec: () => import("@serene-pub/sdk").SpecDocument;
105
- /**
106
- * Lair's, on the same terms as the other three (one graph, published once per
107
- * shipped genre because a preset binds a spec whose inlet lock names its
108
- * genre). Its forms are addressed to the **owner**, which is a person, so this
109
- * pipeline is what waits for the day a Lair session seats an AI in a seat a
110
- * form is put to — core records `form-addressed` only when the resolver says
111
- * the AI portrays the addressee, and `owner` never resolves that way.
112
- * @internal
113
- */
114
- export declare const answerFormLairSpec: () => import("@serene-pub/sdk").SpecDocument;
115
89
  //# sourceMappingURL=answerForm.d.ts.map
@@ -23,8 +23,10 @@
23
23
  * A spec has one inlet lock and a preset binds a spec whose lock names the
24
24
  * preset's genre (24 §4), so the pipeline is declared once here and
25
25
  * published once per shipped genre — one each for chat, adventure, guide
26
- * and lair. Chat and Guide reuse the same authored prompt row; a plugin
27
- * genre publishes its own through the same builder, naming its own row.
26
+ * and lair, each named genre first like every genre pipeline
27
+ * (`core:spec/<genre>-answer-form`, in `genres/<genre>/answerForm.ts`).
28
+ * Chat and Guide reuse the same authored prompt row; a plugin genre
29
+ * publishes its own through the same builder, naming its own row.
28
30
  *
29
31
  * ⚠ **Every shipped genre binds one, whatever its own forms look like**
30
32
  * (ruled 2026-09-17). A genre cannot promise that no pipeline — its own, one
@@ -54,27 +56,8 @@
54
56
  */
55
57
  import { compile, handlebars, slot, spec, sessionEvents } from '@serene-pub/sdk';
56
58
  import * as C from '@serene-pub/contracts';
57
- import { adventureGenre, chatGenre, guideGenre } from './genres.js';
58
- import { lairGenre } from './genres.js';
59
59
  /** @internal */
60
60
  export const ANSWER_FORM_VERSION = '1.0.0';
61
- /** The one spec id prefix every answer pipeline core ships shares. @internal */
62
- export const ANSWER_FORM_SPEC_PREFIX = 'core:spec/answer-form-';
63
- /** @internal */
64
- export const ANSWER_FORM_CHAT_SPEC_ID = `${ANSWER_FORM_SPEC_PREFIX}chat`;
65
- /** @internal */
66
- export const ANSWER_FORM_ADVENTURE_SPEC_ID = `${ANSWER_FORM_SPEC_PREFIX}adventure`;
67
- /** @internal */
68
- export const ANSWER_FORM_GUIDE_SPEC_ID = `${ANSWER_FORM_SPEC_PREFIX}guide`;
69
- /** @internal */
70
- export const ANSWER_FORM_LAIR_SPEC_ID = `${ANSWER_FORM_SPEC_PREFIX}lair`;
71
- /** Every answer pipeline core ships, by the genre it serves. @internal */
72
- export const ANSWER_FORM_SPEC_IDS = Object.freeze({
73
- [chatGenre.id]: ANSWER_FORM_CHAT_SPEC_ID,
74
- [adventureGenre.id]: ANSWER_FORM_ADVENTURE_SPEC_ID,
75
- [guideGenre.id]: ANSWER_FORM_GUIDE_SPEC_ID,
76
- [lairGenre.id]: ANSWER_FORM_LAIR_SPEC_ID,
77
- });
78
61
  /**
79
62
  * The assembly template. Triple-stashed like every shipped context template:
80
63
  * prose going to a model, not markup going to a browser. Each line renders its
@@ -222,20 +205,4 @@ export const answerFormSpec = (id, genre, options = {}) => compile(spec(id, {
222
205
  return options.prompt ? templated.prompts('context', options.prompt) : templated;
223
206
  })
224
207
  .build());
225
- /** @internal */
226
- export const answerFormChatSpec = () => answerFormSpec(ANSWER_FORM_CHAT_SPEC_ID, chatGenre);
227
- /** @internal */
228
- export const answerFormAdventureSpec = () => answerFormSpec(ANSWER_FORM_ADVENTURE_SPEC_ID, adventureGenre);
229
- /** @internal */
230
- export const answerFormGuideSpec = () => answerFormSpec(ANSWER_FORM_GUIDE_SPEC_ID, guideGenre);
231
- /**
232
- * Lair's, on the same terms as the other three (one graph, published once per
233
- * shipped genre because a preset binds a spec whose inlet lock names its
234
- * genre). Its forms are addressed to the **owner**, which is a person, so this
235
- * pipeline is what waits for the day a Lair session seats an AI in a seat a
236
- * form is put to — core records `form-addressed` only when the resolver says
237
- * the AI portrays the addressee, and `owner` never resolves that way.
238
- * @internal
239
- */
240
- export const answerFormLairSpec = () => answerFormSpec(ANSWER_FORM_LAIR_SPEC_ID, lairGenre);
241
208
  //# sourceMappingURL=answerForm.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A spec document built once, on first use. Internal: never re-exported.
3
+ */
4
+ import type { SpecDocument } from '@serene-pub/sdk';
5
+ /** Built once, on first use — a preset reads it at import, `CORE_SPECS` whenever it publishes. */
6
+ export declare const once: (build: () => SpecDocument) => (() => SpecDocument);
7
+ //# sourceMappingURL=once.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A spec document built once, on first use. Internal: never re-exported.
3
+ */
4
+ /** Built once, on first use — a preset reads it at import, `CORE_SPECS` whenever it publishes. */
5
+ export const once = (build) => {
6
+ let doc;
7
+ return () => (doc ??= build());
8
+ };
9
+ //# sourceMappingURL=once.js.map
@@ -49,14 +49,6 @@
49
49
  import { S } from '@serene-pub/sdk';
50
50
  import type { Descriptor, GenreDecl, SpecDocument } from '@serene-pub/sdk';
51
51
  /** @experimental */
52
- export declare const CHAT_TURN_ORDER_SPEC_ID = "core:spec/chat-turn-order";
53
- /** @experimental */
54
- export declare const GUIDE_TURN_ORDER_SPEC_ID = "core:spec/guide-turn-order";
55
- /** @experimental */
56
- export declare const ADVENTURE_TURN_ORDER_SPEC_ID = "core:spec/adventure-turn-order";
57
- /** @experimental */
58
- export declare const LAIR_TURN_ORDER_SPEC_ID = "core:spec/lair-turn-order";
59
- /** @experimental */
60
52
  export declare const TURN_ORDER_VERSION = "1.0.0";
61
53
  /**
62
54
  * The nine events a cast genre recomputes on (§4.5).
@@ -207,19 +199,5 @@ export interface TurnOrderHandle {
207
199
  /** The node key the genre's Turn order control swaps — read this, never assume `strategy` (R26, M4). */
208
200
  strategyNode: string;
209
201
  }
210
- /** Chat's turn order, by value — hand `build()` and `strategyNode` to `swaps` (R26). @experimental */
211
- export declare const chatTurnOrder: TurnOrderHandle;
212
- /** Guide's turn order, by value — hand `build()` and `strategyNode` to `swaps` (R26). @experimental */
213
- export declare const guideTurnOrder: TurnOrderHandle;
214
- /** Adventure's turn order, by value — hand `build()` and `strategyNode` to `swaps` (R26). @experimental */
215
- export declare const adventureTurnOrder: TurnOrderHandle;
216
- /** The Lair's turn order, by value — hand `build()` and `strategyNode` to `swaps` (R26). @experimental */
217
- export declare const lairTurnOrder: TurnOrderHandle;
218
- /**
219
- * Core's four (§4.14's table): which genre gets which spec, on which events —
220
- * what the presets bind and what `CORE_SPECS` publishes.
221
- * @experimental
222
- */
223
- export declare const TURN_ORDER_BY_GENRE: ReadonlyArray<TurnOrderHandle>;
224
202
  export {};
225
203
  //# sourceMappingURL=turnOrder.d.ts.map
@@ -48,16 +48,6 @@
48
48
  */
49
49
  import { compile, slot, spec, sessionEvents } from '@serene-pub/sdk';
50
50
  import * as C from '@serene-pub/contracts';
51
- import { chatGenre, guideGenre } from './genres.js';
52
- import { adventureGenre, lairGenre } from './genres.js';
53
- /** @experimental */
54
- export const CHAT_TURN_ORDER_SPEC_ID = 'core:spec/chat-turn-order';
55
- /** @experimental */
56
- export const GUIDE_TURN_ORDER_SPEC_ID = 'core:spec/guide-turn-order';
57
- /** @experimental */
58
- export const ADVENTURE_TURN_ORDER_SPEC_ID = 'core:spec/adventure-turn-order';
59
- /** @experimental */
60
- export const LAIR_TURN_ORDER_SPEC_ID = 'core:spec/lair-turn-order';
61
51
  /** @experimental */
62
52
  export const TURN_ORDER_VERSION = '1.0.0';
63
53
  /**
@@ -148,9 +138,11 @@ export function turnOrderSpec(opts) {
148
138
  * who has already spoken; the cast rides on the inlet in the settings
149
139
  * document (§4.12), resolved after the write that caused this event.
150
140
  * `pool` decides who may be seated at all; `mentioned` (R8) moves whoever
151
- * was named to the front without changing who is in.
141
+ * was named to the front without changing who is in. `maintenance`
142
+ * because it is a background lane (ruled 2026-10-05): it runs after the
143
+ * turn, off its critical path, and carries no turn of its own.
152
144
  */
153
- const upToMentioned = spec(id, { version, taxonomy: { role: 'primary' } })
145
+ const upToMentioned = spec(id, { version, taxonomy: { role: 'maintenance' } })
154
146
  .inlet('event', C.sessionEvent.v1(), { genre, events: [...events] })
155
147
  .query('history', ($) => C.sessionHistory.v1({ scope: $.event.sessionScope, params: slot.params() }))
156
148
  .task('pool', ($) => C.turnPool.v1({ cast: $.event.cast, messages: $.history.main, params: slot.params() }), controls)
@@ -201,96 +193,4 @@ export function turnOrderSpec(opts) {
201
193
  }
202
194
  /** The key of the node a turn-order spec's Turn order control swaps (M4): `strategy`, or `decide.rules.strategy` with a model path. @experimental */
203
195
  export const turnStrategyNode = (opts) => opts.advise ? 'decide.rules.strategy' : 'strategy';
204
- /** Built once, on first use — a preset reads it at import, `CORE_SPECS` whenever it publishes. */
205
- const once = (build) => {
206
- let doc;
207
- return () => (doc ??= build());
208
- };
209
- /** Every core turn strategy but round robin, in the order chat's control lists them. */
210
- const CHAT_SWAPS = [C.turnUserSplit, C.turnRandom, C.turnScripted, C.turnManual, C.turnNarrator];
211
- /** Guide: its one in-turn envoy is the whole order. */
212
- const ENVOY_ONLY = { characters: 'none', envoys: 'in-turn' };
213
- /** The planner genres: nobody is seated — the one entry is the pipeline's own voice. */
214
- const NOBODY = { characters: 'none', envoys: 'none' };
215
- /**
216
- * 🚧 The Lair: its active delvers are seated (owner ruling 2026-09-30, "they
217
- * are character turns"). The narrator strategy still seats nobody by rule;
218
- * what the pool admits is who a standing turn plan may prepare a character
219
- * turn for, since an entry naming somebody the pool did not admit is dropped
220
- * at the write. Envoys stay out: the Castellan's turns are the null entry's.
221
- */
222
- const PARTY = { characters: 'active', envoys: 'none' };
223
- /** Chat's turn order, by value — hand `build()` and `strategyNode` to `swaps` (R26). @experimental */
224
- export const chatTurnOrder = {
225
- genre: chatGenre,
226
- spec: CHAT_TURN_ORDER_SPEC_ID,
227
- events: TURN_ORDER_EVENTS,
228
- build: once(() => turnOrderSpec({
229
- id: CHAT_TURN_ORDER_SPEC_ID,
230
- genre: chatGenre,
231
- events: TURN_ORDER_EVENTS,
232
- strategy: C.turnRoundRobin,
233
- swaps: CHAT_SWAPS,
234
- // The optional model path (R41, M4): chat declares `turnMode`.
235
- advise: C.turnAdvise,
236
- })),
237
- strategyNode: turnStrategyNode({ advise: C.turnAdvise }),
238
- };
239
- /** Guide's turn order, by value — hand `build()` and `strategyNode` to `swaps` (R26). @experimental */
240
- export const guideTurnOrder = {
241
- genre: guideGenre,
242
- spec: GUIDE_TURN_ORDER_SPEC_ID,
243
- events: TURN_ORDER_EVENTS,
244
- build: once(() => turnOrderSpec({
245
- id: GUIDE_TURN_ORDER_SPEC_ID,
246
- genre: guideGenre,
247
- events: TURN_ORDER_EVENTS,
248
- strategy: C.turnRoundRobin,
249
- pool: ENVOY_ONLY,
250
- })),
251
- strategyNode: turnStrategyNode({}),
252
- };
253
- /** Adventure's turn order, by value — hand `build()` and `strategyNode` to `swaps` (R26). @experimental */
254
- export const adventureTurnOrder = {
255
- genre: adventureGenre,
256
- spec: ADVENTURE_TURN_ORDER_SPEC_ID,
257
- events: TURN_ORDER_NARRATOR_EVENTS,
258
- build: once(() => turnOrderSpec({
259
- id: ADVENTURE_TURN_ORDER_SPEC_ID,
260
- genre: adventureGenre,
261
- events: TURN_ORDER_NARRATOR_EVENTS,
262
- strategy: C.turnNarrator,
263
- pool: NOBODY,
264
- })),
265
- strategyNode: turnStrategyNode({}),
266
- };
267
- /** The Lair's turn order, by value — hand `build()` and `strategyNode` to `swaps` (R26). @experimental */
268
- export const lairTurnOrder = {
269
- genre: lairGenre,
270
- spec: LAIR_TURN_ORDER_SPEC_ID,
271
- events: TURN_ORDER_NARRATOR_EVENTS,
272
- build: once(() => turnOrderSpec({
273
- id: LAIR_TURN_ORDER_SPEC_ID,
274
- genre: lairGenre,
275
- events: TURN_ORDER_NARRATOR_EVENTS,
276
- strategy: C.turnNarrator,
277
- // The delvers its plans name take character turns.
278
- pool: PARTY,
279
- // Every channel (R6): a line on the Sanctum prepares the
280
- // Castellan's reply there, as a line on `main` prepares its turn.
281
- historyChannel: '*',
282
- })),
283
- strategyNode: turnStrategyNode({}),
284
- };
285
- /**
286
- * Core's four (§4.14's table): which genre gets which spec, on which events —
287
- * what the presets bind and what `CORE_SPECS` publishes.
288
- * @experimental
289
- */
290
- export const TURN_ORDER_BY_GENRE = [
291
- chatTurnOrder,
292
- guideTurnOrder,
293
- adventureTurnOrder,
294
- lairTurnOrder,
295
- ];
296
196
  //# sourceMappingURL=turnOrder.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Adventure's **Time passes** action. The genre's actions are introduced in
3
+ * `index.ts`.
4
+ */
5
+ /** @internal */
6
+ export declare const ADVENTURE_ADVANCE_TIME_SPEC_ID = "core:spec/adventure-advance-time";
7
+ /** @internal */
8
+ export declare const ADVENTURE_ADVANCE_TIME_VERSION = "1.0.0";
9
+ /** Let time pass: the world clock steps on, and the weather may turn with it. @internal */
10
+ export declare const adventureAdvanceTimeSpec: () => import("@serene-pub/sdk").SpecDocument;
11
+ //# sourceMappingURL=advanceTime.d.ts.map
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Adventure's **Time passes** action. The genre's actions are introduced in
3
+ * `index.ts`.
4
+ */
5
+ import { keeperAction } from './keeperAction.js';
6
+ /** @internal */
7
+ export const ADVENTURE_ADVANCE_TIME_SPEC_ID = 'core:spec/adventure-advance-time';
8
+ /** @internal */
9
+ export const ADVENTURE_ADVANCE_TIME_VERSION = '1.0.0';
10
+ /** Let time pass: the world clock steps on, and the weather may turn with it. @internal */
11
+ export const adventureAdvanceTimeSpec = () => keeperAction(ADVENTURE_ADVANCE_TIME_SPEC_ID, ADVENTURE_ADVANCE_TIME_VERSION, {
12
+ key: 'advance-time',
13
+ icon: 'clock',
14
+ label: 'Time passes',
15
+ description: 'Let time pass in the world; the weather may change with it.',
16
+ });
17
+ //# sourceMappingURL=advanceTime.js.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Adventure's **Answer**: what an option of `ask.ts`'s question fires. The genre's
3
+ * actions are introduced in `index.ts`.
4
+ */
5
+ /** @internal */
6
+ export declare const ADVENTURE_ANSWER_SPEC_ID = "core:spec/adventure-answer";
7
+ /** @internal */
8
+ export declare const ADVENTURE_ANSWER_VERSION = "1.0.0";
9
+ /**
10
+ * **Answer**: what a form's option fires — the addressee's line, as the
11
+ * addressee. `read-answer` takes the press apart (the chosen option's label,
12
+ * who answered and their character row) and `create-message` posts the
13
+ * label as that participant's message. A person portraying the addressee
14
+ * clicks and the row is theirs; the answer pipeline commits an oracle's
15
+ * choice and the row is the AI's — same spec, same row, either way, which
16
+ * is the whole of "exactly as a click would".
17
+ *
18
+ * Declared on its own spec rather than folded into `ask`: a spec has one
19
+ * inlet and one graph, and asking and answering are two graphs.
20
+ * @internal
21
+ */
22
+ export declare const adventureAnswerSpec: () => import("@serene-pub/sdk").SpecDocument;
23
+ //# sourceMappingURL=answer.d.ts.map
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Adventure's **Answer**: what an option of `ask.ts`'s question fires. The genre's
3
+ * actions are introduced in `index.ts`.
4
+ */
5
+ import { compile, spec, sessionEvents } from '@serene-pub/sdk';
6
+ import * as C from '@serene-pub/contracts';
7
+ import { adventureGenre } from '../../registry/genres.js';
8
+ /** @internal */
9
+ export const ADVENTURE_ANSWER_SPEC_ID = 'core:spec/adventure-answer';
10
+ /** @internal */
11
+ export const ADVENTURE_ANSWER_VERSION = '1.0.0';
12
+ /**
13
+ * **Answer**: what a form's option fires — the addressee's line, as the
14
+ * addressee. `read-answer` takes the press apart (the chosen option's label,
15
+ * who answered and their character row) and `create-message` posts the
16
+ * label as that participant's message. A person portraying the addressee
17
+ * clicks and the row is theirs; the answer pipeline commits an oracle's
18
+ * choice and the row is the AI's — same spec, same row, either way, which
19
+ * is the whole of "exactly as a click would".
20
+ *
21
+ * Declared on its own spec rather than folded into `ask`: a spec has one
22
+ * inlet and one graph, and asking and answering are two graphs.
23
+ * @internal
24
+ */
25
+ export const adventureAnswerSpec = () => compile(spec(ADVENTURE_ANSWER_SPEC_ID, {
26
+ version: ADVENTURE_ANSWER_VERSION,
27
+ taxonomy: { role: 'action' },
28
+ contributes: {
29
+ actions: [
30
+ {
31
+ key: 'answer',
32
+ /**
33
+ * Carried by a block in a message and pressed from that
34
+ * block alone: the `form` venue (U5d review, S1) is the
35
+ * one no listing offers, so *Answer* is in no message's
36
+ * overflow and no composer menu — a question is answered
37
+ * where it was asked. The block's fire still resolves it.
38
+ */
39
+ venue: { kind: 'form' },
40
+ audience: { see: ['participant'], act: ['participant'] },
41
+ icon: 'message-circle-reply',
42
+ label: { en: 'Answer' },
43
+ description: { en: 'Answer a question the narrator put to you.' },
44
+ },
45
+ ],
46
+ },
47
+ })
48
+ .inlet('input', C.userMessage.v1(), {
49
+ genre: adventureGenre,
50
+ event: sessionEvents.sessionAction,
51
+ })
52
+ .task('answer', ($) => C.readAnswer.v1({ payload: $.input.payload, form: $.input.form }))
53
+ .outlet('save', ($) => C.createMessage.v1({
54
+ text: $.answer.label,
55
+ characterId: $.answer.characterId,
56
+ speaker: $.answer.addressee,
57
+ }))
58
+ .build());
59
+ //# sourceMappingURL=answer.js.map