@serene-pub/core-catalog 0.6.0-pr-1 → 0.6.0-pr-2
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.
- package/dist/components/authors-note.source.json +1 -1
- package/dist/components/lore-entries.source.json +1 -1
- package/dist/components/messages.source.json +1 -1
- package/dist/components/scene-portraits.source.json +1 -1
- package/dist/components/stats.source.json +1 -1
- package/dist/components/world-state.source.json +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"slug":"messages","framework":"svelte","entry":"sessions/messages/messages.ts","files":{"sessions/messages/MessageBlocksView.svelte":"<script lang=\"ts\">\n\t/**\n\t * The block renderer (20 §6): plugin message content as data, drawn by\n\t * core's own components — themed, accessible, and with nothing to\n\t * sanitize, because no markup ever crosses the boundary.\n\t *\n\t * Interactivity is declared: a `choices` button or a `form` submit names a\n\t * function key, and `onAction` carries it (with the entered values as the\n\t * payload) up to the page, which fires `sessions:fireAction` with the\n\t * message as subject — the same audited path as every contributed button.\n\t * The block's `action` — the identity of the declaration it fires,\n\t * stamped by the outlet that wrote it (U5c review, W-E) — rides along\n\t * verbatim, so the server holds the press to THAT declaration's audience;\n\t * a block carrying none is fired as the legacy shape and gets the owner\n\t * floor. This view never invents one.\n\t *\n\t * A **form** (R-15 *Forms*; U5d) is a `choices` or `form` block with an\n\t * `addressee`: its `id` rides the press as `blockId`, so the server reads\n\t * the block off the row and holds the press to the addressee — the person\n\t * portraying them may answer, nobody else; when the AI portrays them the\n\t * answer pipeline already answered. A choice's `choice` key is the\n\t * payload. The question is shown above the options unless the message\n\t * body already says it (`bodyText`), which is how the narrator's Ask\n\t * reads: the question once, then the buttons.\n\t *\n\t * **Answered once** (U5d review, W7): a form the host has stamped\n\t * `answered` shows the answer in place of its buttons, greyed; a form\n\t * put to somebody the viewer does not portray shows no buttons at all —\n\t * `canAnswer` is the viewer's verdict, handed down from the page, which\n\t * mirrors the server's resolver (`utils/formAnswer.ts`). An affordance\n\t * only: the server refuses regardless.\n\t *\n\t * **Superseded** (plans/29 R-15 *Staleness and order*; U5f): a form the\n\t * channel has moved past — unanswered, and a newer message on its row's\n\t * channel than the `head` it was issued at — collapses to one quiet line,\n\t * no question and no buttons (the row's body already showed the question).\n\t * `isStale` is the verdict, handed down from the message\n\t * (`utils/formAnswer.ts` `staleOf`, the server's rule over the list the\n\t * client holds). Answered beats stale.\n\t *\n\t * Every drawing of a `choices` or `form` block carries its stamped id as\n\t * `data-block-id`: a notification's link lands on the form it names\n\t * (`?message=<id>&block=<blockId>`, the page's `messageLanding.ts`).\n\t */\n\timport MessageBlocksView from \"./MessageBlocksView.svelte\"\n\timport { useT } from \"./conversation.svelte\"\n\timport { answeredChoiceLabel, answeredOf } from \"@serene-pub/core-catalog/conversation\"\n\n\tconst t = useT()\n\n\tinterface Props {\n\t\tblocks: any[]\n\t\tonAction?: (\n\t\t\tfn: string,\n\t\t\tpayload?: Record<string, unknown>,\n\t\t\taction?: string,\n\t\t\tblockId?: string\n\t\t) => void\n\t\tdepth?: number\n\t\t/** The message body, so a form's question is not shown twice. */\n\t\tbodyText?: string\n\t\t/**\n\t\t * May the viewer answer a form put to this addressee? Absent, every\n\t\t * addressed form shows its buttons and the server judges the press.\n\t\t */\n\t\tcanAnswer?: (addressee: string | undefined) => boolean\n\t\t/**\n\t\t * Has the channel moved past this form (U5f)? Absent, no form is\n\t\t * drawn superseded and the server refuses a stale press.\n\t\t */\n\t\tisStale?: (block: { head?: unknown; answered?: unknown }) => boolean\n\t}\n\n\tlet { blocks, onAction, depth = 1, bodyText, canAnswer, isStale }: Props = $props()\n\n\t/** Whether the form is superseded — never when answered. */\n\tconst superseded = (b: { head?: unknown; answered?: unknown }): boolean =>\n\t\t!answeredOf(b) && !!isStale && isStale(b)\n\n\t/** The addressee, when the block has one. */\n\tconst addresseeOf = (b: { addressee?: unknown }): string | undefined =>\n\t\ttypeof b?.addressee === \"string\" && b.addressee ? b.addressee : undefined\n\n\t/** Whether this viewer's buttons show on the form. */\n\tconst mayAnswer = (b: { addressee?: unknown }): boolean =>\n\t\t!canAnswer || canAnswer(addresseeOf(b))\n\n\t/** A form's question, when the body does not already carry it. */\n\tconst caption = (b: { question?: unknown }): string | null => {\n\t\tif (typeof b?.question !== \"string\" || !b.question.trim()) return null\n\t\tconst q = b.question.trim()\n\t\treturn bodyText && bodyText.trim().includes(q) ? null : q\n\t}\n\n\t/** The block's id, when the host stamped one. */\n\tconst blockIdOf = (b: { id?: unknown }): string | undefined =>\n\t\ttypeof b?.id === \"string\" && b.id ? b.id : undefined\n\n\t/** Form drafts, keyed by block index within this view. */\n\tlet formDrafts = $state<Record<number, Record<string, unknown>>>({})\n\n\tfunction editField(i: number, key: string, value: unknown) {\n\t\tformDrafts[i] = { ...(formDrafts[i] ?? {}), [key]: value }\n\t}\n\n\tfunction submitForm(i: number, block: any) {\n\t\tif (!onAction) return\n\t\t// Declared defaults fill what the person didn't touch.\n\t\tconst values: Record<string, unknown> = {}\n\t\tfor (const [key, decl] of Object.entries(block.fields ?? {}) as any)\n\t\t\tif (decl?.default !== undefined) values[key] = decl.default\n\t\tObject.assign(values, formDrafts[i] ?? {})\n\t\tonAction(block.fn, values, identityOf(block), blockIdOf(block))\n\t}\n\n\t/** The block's stamped identity, when it carries a well-formed one. */\n\tconst identityOf = (b: { action?: unknown }): string | undefined =>\n\t\ttypeof b?.action === \"string\" && b.action ? b.action : undefined\n\n\tconst fieldLabel = (key: string, decl: any): string =>\n\t\ttypeof decl?.label === \"string\" ? decl.label : (decl?.label?.en ?? key)\n</script>\n\n<!-- The block tree's parts (`messages.block*`, STYLE-GUIDE §6.16): no look\n here; the default widget stylesheet draws them. `data-depth` is how deep\n in a group the view is (1: the part's own tree). -->\n<div data-widget-part=\"messages.blocks\" data-depth={depth}>\n\t{#each blocks as block, i}\n\t\t{#if block?.kind === \"md\"}\n\t\t\t<div data-widget-part=\"messages.block-markdown messages.prose\">\n\t\t\t\t<sp-message-body text={String(block.text ?? \"\")}></sp-message-body>\n\t\t\t</div>\n\t\t{:else if block?.kind === \"kv\"}\n\t\t\t<dl data-widget-part=\"messages.block-kv\">\n\t\t\t\t{#each block.rows ?? [] as row}\n\t\t\t\t\t<dt data-widget-part=\"messages.block-kv-label\">{row.label}</dt>\n\t\t\t\t\t<dd>{row.value}</dd>\n\t\t\t\t{/each}\n\t\t\t</dl>\n\t\t{:else if block?.kind === \"table\"}\n\t\t\t<div data-widget-part=\"messages.block-table-scroll\">\n\t\t\t\t<table data-widget-part=\"messages.block-table\">\n\t\t\t\t\t<thead>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t{#each block.columns ?? [] as col}\n\t\t\t\t\t\t\t\t<th>{col}</th>\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t{#each block.rows ?? [] as row}\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t{#each row as cell}\n\t\t\t\t\t\t\t\t\t<td>{cell}</td>\n\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t</div>\n\t\t{:else if block?.kind === \"stat\"}\n\t\t\t<div data-widget-part=\"messages.block-stat\">\n\t\t\t\t<div data-widget-part=\"messages.block-stat-head\">\n\t\t\t\t\t<span data-widget-part=\"messages.block-stat-label\">{block.label}</span>\n\t\t\t\t\t<span data-widget-part=\"messages.block-stat-value\">\n\t\t\t\t\t\t{block.value}{block.max != null ? ` / ${block.max}` : \"\"}\n\t\t\t\t\t</span>\n\t\t\t\t</div>\n\t\t\t\t{#if block.max}\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.block-stat-track meter\"\n\t\t\t\t\t\trole=\"meter\"\n\t\t\t\t\t\taria-label={block.label}\n\t\t\t\t\t\taria-valuenow={block.value}\n\t\t\t\t\t\taria-valuemin={0}\n\t\t\t\t\t\taria-valuemax={block.max}\n\t\t\t\t\t>\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tdata-widget-part=\"messages.block-stat-fill\"\n\t\t\t\t\t\t\tstyle=\"--sp-fill: {Math.max(\n\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\tMath.min(100, (block.value / block.max) * 100)\n\t\t\t\t\t\t\t)}%\"\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</div>\n\t\t{:else if block?.kind === \"image\" && block.assetId != null}\n\t\t\t<img\n\t\t\t\tdata-widget-part=\"messages.block-image\"\n\t\t\t\tsrc=\"/session-assets/{block.assetId}\"\n\t\t\t\talt={block.alt ?? \"attachment\"}\n\t\t\t/>\n\t\t{:else if block?.kind === \"choices\" && superseded(block)}\n\t\t\t<!-- Superseded (U5f): the conversation moved on; one quiet line, no buttons. -->\n\t\t\t<p\n\t\t\t\tdata-widget-part=\"messages.block-superseded\"\n\t\t\t\tdata-superseded=\"true\"\n\t\t\t\tdata-block-id={blockIdOf(block)}\n\t\t\t>\n\t\t\t\t<sp-icon name=\"history\" size=\"14\"></sp-icon>\n\t\t\t\t<span>{t(\"Superseded — the conversation moved on\")}</span>\n\t\t\t</p>\n\t\t{:else if block?.kind === \"choices\"}\n\t\t\t{@const answered = answeredOf(block)}\n\t\t\t<div\n\t\t\t\tdata-widget-part=\"messages.block-choices\"\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label={typeof block.question === \"string\" && block.question\n\t\t\t\t\t? block.question\n\t\t\t\t\t: t(\"Choices\")}\n\t\t\t\tdata-answered={answered ? \"true\" : undefined}\n\t\t\t\tdata-block-id={blockIdOf(block)}\n\t\t\t>\n\t\t\t\t{#if caption(block)}\n\t\t\t\t\t<p data-widget-part=\"messages.block-caption\">{caption(block)}</p>\n\t\t\t\t{/if}\n\t\t\t\t{#if answered}\n\t\t\t\t\t<!-- Answered once: the answer stands in for the buttons. -->\n\t\t\t\t\t<p data-widget-part=\"messages.block-answered\">\n\t\t\t\t\t\t<sp-icon name=\"check\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t<span data-widget-part=\"messages.block-answered-label\">{t(\"Answered\")}</span>\n\t\t\t\t\t\t{#if answeredChoiceLabel(block, answered)}\n\t\t\t\t\t\t\t<span>· {answeredChoiceLabel(block, answered)}</span>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</p>\n\t\t\t\t{:else if !mayAnswer(block)}\n\t\t\t\t\t<!-- Somebody else's to answer: no buttons for this viewer. -->\n\t\t\t\t\t<p data-widget-part=\"messages.block-awaiting\">{t(\"Awaiting an answer\")}</p>\n\t\t\t\t{:else}\n\t\t\t\t\t<div data-widget-part=\"messages.block-choice-list\">\n\t\t\t\t\t\t{#each block.actions ?? [] as action}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.block-choice\"\n\t\t\t\t\t\t\t\tdisabled={!onAction}\n\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\tonAction?.(\n\t\t\t\t\t\t\t\t\t\taction.fn,\n\t\t\t\t\t\t\t\t\t\ttypeof action.choice === \"string\"\n\t\t\t\t\t\t\t\t\t\t\t? { choice: action.choice }\n\t\t\t\t\t\t\t\t\t\t\t: {},\n\t\t\t\t\t\t\t\t\t\tidentityOf(action),\n\t\t\t\t\t\t\t\t\t\tblockIdOf(block)\n\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"play\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\t{action.label}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t</div>\n\t\t{:else if block?.kind === \"form\" && superseded(block)}\n\t\t\t<!-- Superseded (U5f): the conversation moved on; one quiet line, no buttons. -->\n\t\t\t<p\n\t\t\t\tdata-widget-part=\"messages.block-superseded\"\n\t\t\t\tdata-superseded=\"true\"\n\t\t\t\tdata-block-id={blockIdOf(block)}\n\t\t\t>\n\t\t\t\t<sp-icon name=\"history\" size=\"14\"></sp-icon>\n\t\t\t\t<span>{t(\"Superseded — the conversation moved on\")}</span>\n\t\t\t</p>\n\t\t{:else if block?.kind === \"form\" && answeredOf(block)}\n\t\t\t<div\n\t\t\t\tdata-widget-part=\"messages.block-form\"\n\t\t\t\tdata-answered=\"true\"\n\t\t\t\tdata-block-id={blockIdOf(block)}\n\t\t\t>\n\t\t\t\t{#if caption(block)}\n\t\t\t\t\t<p data-widget-part=\"messages.block-caption\">{caption(block)}</p>\n\t\t\t\t{/if}\n\t\t\t\t<p data-widget-part=\"messages.block-answered\">\n\t\t\t\t\t<sp-icon name=\"check\" size=\"14\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"messages.block-answered-label\">{t(\"Answered\")}</span>\n\t\t\t\t</p>\n\t\t\t</div>\n\t\t{:else if block?.kind === \"form\" && !mayAnswer(block)}\n\t\t\t<div data-widget-part=\"messages.block-form\" data-block-id={blockIdOf(block)}>\n\t\t\t\t{#if caption(block)}\n\t\t\t\t\t<p data-widget-part=\"messages.block-caption\">{caption(block)}</p>\n\t\t\t\t{/if}\n\t\t\t\t<p data-widget-part=\"messages.block-awaiting\">{t(\"Awaiting an answer\")}</p>\n\t\t\t</div>\n\t\t{:else if block?.kind === \"form\"}\n\t\t\t<div data-widget-part=\"messages.block-form\" data-block-id={blockIdOf(block)}>\n\t\t\t\t{#if caption(block)}\n\t\t\t\t\t<p data-widget-part=\"messages.block-caption\">{caption(block)}</p>\n\t\t\t\t{/if}\n\t\t\t\t{#each Object.entries(block.fields ?? {}) as [key, decl]}\n\t\t\t\t\t{@const d = decl as any}\n\t\t\t\t\t<label data-widget-part=\"messages.block-field\">\n\t\t\t\t\t\t<span data-widget-part=\"messages.block-field-label\">{fieldLabel(key, d)}</span>\n\t\t\t\t\t\t{#if d.type === \"boolean\"}\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\ttype=\"checkbox\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.block-checkbox\"\n\t\t\t\t\t\t\t\tchecked={!!(formDrafts[i]?.[key] ?? d.default)}\n\t\t\t\t\t\t\t\tonchange={(e) =>\n\t\t\t\t\t\t\t\t\teditField(i, key, e.currentTarget.checked)}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t{:else if d.type === \"enum\"}\n\t\t\t\t\t\t\t<sp-combobox\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.block-select\"\n\t\t\t\t\t\t\t\tlabel={key}\n\t\t\t\t\t\t\t\tvalue={String(formDrafts[i]?.[key] ?? d.default ?? \"\")}\n\t\t\t\t\t\t\t\tonchange={(e: CustomEvent<{ value: string }>) =>\n\t\t\t\t\t\t\t\t\teditField(i, key, e.detail.value)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{#each d.of ?? [] as opt}\n\t\t\t\t\t\t\t\t\t<sp-option value={opt}>{opt}</sp-option>\n\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t</sp-combobox>\n\t\t\t\t\t\t{:else if d.type === \"number\" || d.type === \"integer\"}\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.block-input\"\n\t\t\t\t\t\t\t\tstep={d.type === \"integer\" ? \"1\" : \"any\"}\n\t\t\t\t\t\t\t\tvalue={formDrafts[i]?.[key] ?? d.default ?? \"\"}\n\t\t\t\t\t\t\t\toninput={(e) => {\n\t\t\t\t\t\t\t\t\tconst n = Number(e.currentTarget.value)\n\t\t\t\t\t\t\t\t\teditField(\n\t\t\t\t\t\t\t\t\t\ti,\n\t\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\t\tNumber.isFinite(n) ? n : undefined\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.block-input\"\n\t\t\t\t\t\t\t\tvalue={String(\n\t\t\t\t\t\t\t\t\tformDrafts[i]?.[key] ?? d.default ?? \"\"\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\toninput={(e) =>\n\t\t\t\t\t\t\t\t\teditField(i, key, e.currentTarget.value)}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</label>\n\t\t\t\t{/each}\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"messages.block-submit\"\n\t\t\t\t\tdisabled={!onAction}\n\t\t\t\t\tonclick={() => submitForm(i, block)}\n\t\t\t\t>\n\t\t\t\t\t{block.label ?? \"Submit\"}\n\t\t\t\t</button>\n\t\t\t</div>\n\t\t{:else if block?.kind === \"group\" && Array.isArray(block.blocks) && depth < 3}\n\t\t\t<div\n\t\t\t\tdata-widget-part=\"messages.block-group\"\n\t\t\t\tdata-layout={block.layout === \"row\" ? \"row\" : \"column\"}\n\t\t\t>\n\t\t\t\t<MessageBlocksView\n\t\t\t\t\tblocks={block.blocks}\n\t\t\t\t\t{onAction}\n\t\t\t\t\t{bodyText}\n\t\t\t\t\t{canAnswer}\n\t\t\t\t\t{isStale}\n\t\t\t\t\tdepth={depth + 1}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t{/if}\n\t{/each}\n</div>\n","sessions/messages/MessageComposer.svelte":"<script lang=\"ts\">\n\timport type { Snippet } from \"svelte\"\n\timport { useWidgetContext } from \"../shared/context\"\n\n\tinterface Props {\n\t\tmarkdown: string\n\t\tleftControls?: Snippet\n\t\trightControls?: Snippet\n\t\textraTabs?: {\n\t\t\tvalue: string\n\t\t\ttitle: string\n\t\t\tcontrol: Snippet\n\t\t\tcontent: Snippet\n\t\t\t/** Stays as its own permanently visible tab on all screen sizes\n\t\t\t * instead of collapsing into the mobile \"More\" popover. */\n\t\t\talwaysVisible?: boolean\n\t\t}[]\n\t\tonSend: () => void\n\t\t/** Escape handler. Only kept from the field when provided, so a\n\t\t * composer where Escape means nothing leaves it to the page. */\n\t\tonCancel?: () => void\n\t\tplaceholder?: string\n\t\t/** `\"send\"` (default) is the session bar's behaviour: Enter submits on\n\t\t * desktop. `\"newline\"` is for editing existing prose, where a stray\n\t\t * Enter mid-paragraph committing the edit is a trap — there Enter\n\t\t * always inserts a newline and Ctrl/Cmd+Enter submits. */\n\t\tenterBehavior?: \"send\" | \"newline\"\n\t\t/** Focus the field and put the caret at the end on mount. */\n\t\tautofocus?: boolean\n\t\t/** A `composer: 'none'` mode (19 §2): no Compose/Preview tabs, no\n\t\t * input, no send — the extra tabs (triggers, lore, stats) are the\n\t\t * whole surface. */\n\t\thideCompose?: boolean\n\t}\n\tlet {\n\t\tmarkdown = $bindable(),\n\t\tleftControls,\n\t\trightControls,\n\t\textraTabs = $bindable(),\n\t\tonSend,\n\t\tonCancel,\n\t\tplaceholder = \"Type a message...\",\n\t\tenterBehavior = \"send\",\n\t\tautofocus = false,\n\t\thideCompose = false\n\t}: Props = $props()\n\n\tlet tabGroup: string = $state(\"compose\")\n\t// Without a compose tab the initial (and any stale) selection must land\n\t// on a tab that exists — the first extra tab is the surface's front page.\n\t$effect(() => {\n\t\tif (hideCompose && (tabGroup === \"compose\" || tabGroup === \"preview\")) {\n\t\t\ttabGroup = extraTabs?.[0]?.value ?? \"compose\"\n\t\t}\n\t})\n\t// On mobile, extraTabs collapse into a single \"More\" popover instead of\n\t// competing inline with Compose/Preview for a 375px-wide row — mirrors\n\t// the same overflow-into-a-menu pattern already used for per-message\n\t// controls (see SessionMessage.svelte's mobile controls popover).\n\tlet showMoreMenu = $state(false)\n\tlet collapsibleExtraTabs = $derived(\n\t\textraTabs?.filter((t) => !t.alwaysVisible) ?? []\n\t)\n\tlet activeExtraTab = $derived(\n\t\tcollapsibleExtraTabs.find((t) => t.value === tabGroup)\n\t)\n\t// Enter submits on desktop only; on touch it inserts a newline like any\n\t// other textarea. There is deliberately no on-screen hint for this — it was\n\t// permanent noise under every session, and gating it on \"only while typing\"\n\t// just traded that for a layout jump on the first keystroke.\n\t// The widget's box, not the window: a remote has no window to ask.\n\tconst widget = useWidgetContext()\n\tconst submitOnEnter = $derived(widget?.current.layout?.v1?.tier !== \"compact\")\n\n\t// The field is the page's (`sp-composer-field`): a remote hears no\n\t// keydown, so the keys this composer answers are named to the field,\n\t// which keeps them from itself and raises them as `key`. Escape cancels;\n\t// under `\"newline\"` Ctrl/Cmd+Enter submits — regardless of viewport:\n\t// unlike plain Enter, it isn't something a touch keyboard can emit by\n\t// accident — and Enter and Shift+Enter stay the field's newline. Under\n\t// `\"send\"` the field's own send key (Enter without Shift) submits.\n\tconst fieldKeys = $derived(\n\t\t[onCancel ? \"Escape\" : \"\", enterBehavior === \"newline\" ? \"Control+Enter Meta+Enter\" : \"\"]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\" \")\n\t)\n\n\tfunction handleFieldKey(e: CustomEvent<{ key: string; shift: boolean; ctrl?: boolean; meta?: boolean }>) {\n\t\tconst { key, ctrl, meta } = e.detail\n\t\tif (key === \"Escape\") onCancel?.()\n\t\telse if (key === \"Enter\" && (ctrl || meta)) onSend()\n\t}\n\n\t/**\n\t * The field holds `markdown` as the caller sets it (an edit's text,\n\t * copied in as editing starts). Only a value from OUTSIDE is written: a\n\t * write resets the page's field, so the text the person typed, heard\n\t * back through `markdown`, is never echoed onto what they type next.\n\t * The caret goes to the end as the field lands (`autofocus`, which the\n\t * page honours) rather than selecting all: this is an edit of existing\n\t * text, so a select-all means the first keystroke destroys the message.\n\t */\n\tconst heard = new WeakMap<EventTarget, string>()\n\tconst writeField = (el: HTMLElement) => {\n\t\tconst v = markdown ?? \"\"\n\t\tif (heard.get(el) === v) return\n\t\theard.set(el, v)\n\t\tel.removeAttribute(\"value\")\n\t\tel.setAttribute(\"value\", v)\n\t}\n\t/** What the person typed (or sent), from the field that raised it. */\n\tconst hear = (e: CustomEvent<{ value: string }>) => {\n\t\tif (e.target) heard.set(e.target, e.detail.value)\n\t\tmarkdown = e.detail.value\n\t}\n\n\t$effect(() => {\n\t\tconst fixed = new Set([\"compose\", \"preview\"])\n\t\tconst extra = new Set(extraTabs?.map((t) => t.value) ?? [])\n\t\tif (!fixed.has(tabGroup) && !extra.has(tabGroup)) {\n\t\t\ttabGroup = \"compose\"\n\t\t}\n\t})\n</script>\n\n<!-- `sp-tabs` (§3.5): the list is drawn from the `sp-tab`s; the panels may sit\n anywhere below, each finding its tabs. Its parts are `messages.edit-*`\n (STYLE-GUIDE §6.16): no look here; the default widget stylesheet draws\n them, the list and the triggers through the tabs' own part. A panel's\n field raises `change` too, so only the element's own counts as a tab\n change. -->\n<sp-tabs\n\tvalue={tabGroup}\n\tlabel=\"Message composer\"\n\tdata-widget-part=\"messages.edit-tabs\"\n\tonchange={(e: CustomEvent<{ value: string }>) => {\n\t\tif (e.target === e.currentTarget) tabGroup = e.detail.value\n\t}}\n>\n\t<!-- Every trigger carries its own `title` and `aria-label`. A tab strip that\n\t shows icons only while inactive has no text to name it, and a name put\n\t on a generic element inside the button is not exposed at all — it has to\n\t be on the button. -->\n\t\t<!-- One block per tab: an sp element seats each tab's content in its\n\t\t own trigger, and Svelte removes a block by walking its nodes as\n\t\t siblings — two tabs in one block would leave one behind. -->\n\t\t{#if !hideCompose}\n\t\t\t<sp-tab\n\t\t\t\tvalue=\"compose\"\n\t\t\t\tlabel=\"Compose\"\n\t\t\t\tdata-widget-part=\"messages.edit-tab\"\n\t\t\t>\n\t\t\t\t<span data-widget-part=\"messages.edit-tab-body\">\n\t\t\t\t\t<sp-icon name=\"pen\" size=\"0.75em\"></sp-icon>\n\t\t\t\t\t{#if tabGroup === \"compose\"}<span data-widget-part=\"messages.edit-tab-label\">\n\t\t\t\t\t\t\tCompose\n\t\t\t\t\t\t</span>{/if}\n\t\t\t\t</span>\n\t\t\t</sp-tab>\n\t\t{/if}\n\t\t{#if !hideCompose}\n\t\t\t<sp-tab\n\t\t\t\tvalue=\"preview\"\n\t\t\t\tlabel=\"Preview\"\n\t\t\t\tdata-widget-part=\"messages.edit-tab\"\n\t\t\t>\n\t\t\t\t<span data-widget-part=\"messages.edit-tab-body\">\n\t\t\t\t\t<sp-icon name=\"eye\" size=\"0.75em\"></sp-icon>\n\t\t\t\t\t{#if tabGroup === \"preview\"}<span data-widget-part=\"messages.edit-tab-label\">\n\t\t\t\t\t\t\tPreview\n\t\t\t\t\t\t</span>{/if}\n\t\t\t\t</span>\n\t\t\t</sp-tab>\n\t\t{/if}\n\t\t{#if extraTabs}\n\t\t\t{#each extraTabs as tab}\n\t\t\t\t<!-- A tab not `alwaysVisible` folds into the More menu in a narrow\n\t\t\t\t box (`data-collapsible`). -->\n\t\t\t\t<sp-tab\n\t\t\t\t\tvalue={tab.value}\n\t\t\t\t\tlabel={tab.title}\n\t\t\t\t\tdata-widget-part=\"messages.edit-tab\"\n\t\t\t\t\tdata-collapsible={tab.alwaysVisible ? undefined : \"\"}\n\t\t\t\t>\n\t\t\t\t\t<span data-widget-part=\"messages.edit-tab-body\">\n\t\t\t\t\t\t{@render tab.control?.()}\n\t\t\t\t\t\t{#if tabGroup === tab.value}<span data-widget-part=\"messages.edit-tab-label\">\n\t\t\t\t\t\t\t\t{tab.title}\n\t\t\t\t\t\t\t</span>{/if}\n\t\t\t\t\t</span>\n\t\t\t\t</sp-tab>\n\t\t\t{/each}\n\t\t\t{#if collapsibleExtraTabs.length > 0}\n\t\t\t\t<!-- `self-stretch` rather than any stated height: it makes this\n\t\t\t\t match whatever the real tab triggers work out to, at any\n\t\t\t\t font scale, with no number to keep in sync. Skeleton sizes\n\t\t\t\t those triggers itself (17.07px font, so their `2em` is\n\t\t\t\t 34.14px) and that isn't inherited here, so every attempt to\n\t\t\t\t restate the height in em/rem lands a couple of pixels off.\n\t\t\t\t What was here before: the button carried `min-h-[2em]` while\n\t\t\t\t `btn-sm` shrank its font to 14.9px, so the same `2em` came\n\t\t\t\t out 29.9px against the tabs' 34.1px — and `pt-[0.7em]` was a\n\t\t\t\t hand-tuned patch for the difference that still left the icon\n\t\t\t\t 2px below centre. -->\n\t\t\t\t<div slot=\"list-end\" data-widget-part=\"messages.edit-more-tabs\">\n\t\t\t\t\t<!-- `sp-popover` (§3.5): our button is the trigger, the card the panel. -->\n\t\t\t\t\t<sp-popover\n\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t\topen={showMoreMenu}\n\t\t\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => (showMoreMenu = e.detail.open)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<button slot=\"trigger\" type=\"button\" data-widget-part=\"messages.edit-more-tabs-button\"\n\t\t\t\t\t\t\tdata-active={activeExtraTab ? \"\" : undefined}\n\t\t\t\t\t\t\taria-label=\"More composer tabs\">\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.edit-more-tabs-body\">\n\t\t\t\t\t\t\t\t{#if activeExtraTab}\n\t\t\t\t\t\t\t\t\t{@render activeExtraTab.control?.()}\n\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.edit-more-tabs-label\">\n\t\t\t\t\t\t\t\t\t\t{activeExtraTab.title}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"0.9em\" data-widget-part=\"messages.edit-more-tabs-icon\"></sp-icon>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<div data-widget-part=\"messages.edit-more-tabs-panel\">\n\t\t\t\t\t\t\t\t\t<header data-widget-part=\"messages.edit-more-tabs-title\">\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"18\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t<p>More</p>\n\t\t\t\t\t\t\t\t\t</header>\n\t\t\t\t\t\t\t\t\t<article data-widget-part=\"messages.edit-more-tabs-list\">\n\t\t\t\t\t\t\t\t\t\t{#each collapsibleExtraTabs as tab}\n\t\t\t\t\t\t\t\t\t\t\t<button\n\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\tdata-widget-part=\"messages.edit-more-tabs-option\"\n\t\t\t\t\t\t\t\t\t\t\t\tdata-current={tabGroup === tab.value ? \"\" : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttabGroup = tab.value\n\t\t\t\t\t\t\t\t\t\t\t\t\tshowMoreMenu = false\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>\n\t\t\t\t\t\t\t\t\t\t\t\t{@render tab.control?.()}\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{tab.title}</span>\n\t\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t\t\t</article>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</sp-popover>\n\t\t\t\t</div>\n\t\t\t{/if}\n\t\t{/if}\n\t<!-- Spacing lives on the side groups as padding rather than as a `gap` on\n\t this row, and each group only renders when it actually has something in\n\t it. With a gap, the wrapper was always a flex item even when its\n\t contents were hidden — the avatar is `max-lg:hidden`, so on mobile a\n\t zero-width group still bought a full 16px of dead space at the left\n\t edge, and the edit composer (which passes neither snippet) paid it\n\t twice. This way an absent group costs nothing. -->\n\t<div data-widget-part=\"messages.edit-row\">\n\t\t<!-- A column only exists when it has something to show. Reserving the\n\t\t slots on tabs that render neither avatar nor send button left an\n\t\t empty 48px band down the side of every extra tab; the panes below\n\t\t are full-width content and should use the whole row. -->\n\t\t{#if leftControls && (tabGroup === \"compose\" || tabGroup === \"preview\")}\n\t\t\t<div role=\"group\" aria-label=\"Message controls\" data-widget-part=\"messages.edit-left\">\n\t\t\t\t{@render leftControls()}\n\t\t\t</div>\n\t\t{/if}\n\t\t<div data-widget-part=\"messages.edit-panels\">\n\t\t\t{#if !hideCompose}\n\t\t\t\t<sp-tab-panel value=\"compose\">\n\t\t\t\t\t<!-- The field inside takes focus and carries the name and ARIA: this is\n\t\t\t\t\t its host element; the field itself is its child `textarea`. -->\n\t\t\t\t\t<sp-composer-field\n\t\t\t\t\t\tdata-widget-part=\"messages.edit-field\"\n\t\t\t\t\t\trows=\"1\"\n\t\t\t\t\t\tlabel=\"Type your message here\"\n\t\t\t\t\t\t{placeholder}\n\t\t\t\t\t\tsubmit-on={enterBehavior === \"send\" && submitOnEnter ? \"enter\" : \"none\"}\n\t\t\t\t\t\tkeys={fieldKeys}\n\t\t\t\t\t\tspellcheck=\"true\"\n\t\t\t\t\t\tautofocus={autofocus || undefined}\n\t\t\t\t\t\toninput={hear}\n\t\t\t\t\t\tonsubmit={(e: CustomEvent<{ value: string }>) => {\n\t\t\t\t\t\t\thear(e)\n\t\t\t\t\t\t\tonSend()\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonkey={handleFieldKey}\n\t\t\t\t\t\t{@attach writeField}\n\t\t\t\t\t></sp-composer-field>\n\t\t\t\t</sp-tab-panel>\n\t\t\t{/if}\n\t\t\t{#if !hideCompose}\n\t\t\t\t<sp-tab-panel value=\"preview\">\n\t\t\t\t\t<!-- Sized to land on the same row height as the compose tab so\n\t\t\t\t switching between them doesn't resize the bar. On mobile the\n\t\t\t\t compose row is set by the 48px send button (taller than the\n\t\t\t\t now single-line textarea), so the preview matches at 3rem; on\n\t\t\t\t lg it's set by the 4em avatar, so the preview matches that.\n\t\t\t\t `mb-[1em]` used to hang off the bottom here, which is what\n\t\t\t\t made preview 4px taller than compose. -->\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.edit-preview\"\n\t\t\t\t\t\trole=\"region\"\n\t\t\t\t\t\taria-label=\"Message preview\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<div data-widget-part=\"messages.edit-preview-body\">\n\t\t\t\t\t\t\t<sp-message-body text={markdown}></sp-message-body>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</sp-tab-panel>\n\t\t\t{/if}\n\t\t\t{#if extraTabs}\n\t\t\t\t{#each extraTabs as tab}\n\t\t\t\t\t<sp-tab-panel value={tab.value}>\n\t\t\t\t\t\t<div role=\"region\" aria-label=\"{tab.title} content\">\n\t\t\t\t\t\t\t{@render tab.content?.()}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</sp-tab-panel>\n\t\t\t\t{/each}\n\t\t\t{/if}\n\t\t</div>\n\t\t{#if rightControls && tabGroup === \"compose\"}\n\t\t\t<div\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label=\"Send controls\"\n\t\t\t\tdata-widget-part=\"messages.edit-right\"\n\t\t\t>\n\t\t\t\t{@render rightControls()}\n\t\t\t</div>\n\t\t{/if}\n\t</div>\n</sp-tabs>\n","sessions/messages/MessageControls.svelte":"<script lang=\"ts\">\n\timport {\n\t\tcoreVerbState,\n\t\tverbKeyOf,\n\t\tverdictOf,\n\t\ttype VerbContext\n\t} from \"@serene-pub/core-catalog/conversation\"\n\timport { actionIdentity } from \"@serene-pub/sdk/component\"\n\timport { useConversation } from \"./conversation.svelte\"\n\timport type { MessageV1, WidgetAction } from \"@serene-pub/sdk/component\"\n\n\t/**\n\t * A message's ⋮ menu: every verb the session offers on it, named in words.\n\t * Everything else — whose menu is open, what the viewer controls, the\n\t * session's list, why Extend is refused — is the conversation's\n\t * (`useConversation`), and every press is one of its verbs (C0b).\n\t */\n\tinterface Props {\n\t\tmsg: MessageV1\n\t\tisLastMessage?: boolean\n\t}\n\n\tlet { msg, isLastMessage = false }: Props = $props()\n\n\tconst conv = useConversation()\n\tconst open = $derived(conv.menu.open === msg.id)\n\tconst onOpenChange = (next: boolean) => conv.menu.set(next ? msg.id : undefined)\n\tconst canControl = $derived(conv.line(msg.id).controllable)\n\tconst extendRefusal = $derived(conv.dossier?.extendRefusal)\n\tconst hasGeneratingMessage = $derived(\n\t\t(conv.ctx.messages.v1 as Array<{ isGenerating?: boolean }>).some((m) => m.isGenerating)\n\t)\n\tconst messageActions = $derived(\n\t\tconv.ctx.actions?.v1?.message as\n\t\t\t| { primary: WidgetAction[]; overflow: WidgetAction[] }\n\t\t\t| undefined\n\t)\n\tconst isAdmin = $derived(conv.ctx.viewer.v1.isAdmin)\n\n\tfunction closeMenu() {\n\t\tonOpenChange(false)\n\t}\n\n\t/**\n\t * **Change sprite** (DESIGN-sprites §6): a character's settled line, and a\n\t * person who may act on it. The picker is the host's (`change-sprite`\n\t * request, C0b): it loads the sprites and sends the pick itself.\n\t */\n\tlet canChangeSprite = $derived(\n\t\tcanControl &&\n\t\t\t!!msg.characterId &&\n\t\t\t!msg.isNarratorResponse &&\n\t\t\t!msg.isGenerating\n\t)\n\n\t/**\n\t * The floors, for a mount with no list: stop, edit and branch are present\n\t * in every genre, and a server too old to send the list still offers them.\n\t */\n\tconst FLOORS: WidgetAction[] = [\n\t\t{ key: \"stop\", name: \"Stop generating\", icon: \"square\", quick: true },\n\t\t{ key: \"edit\", name: \"Edit\", icon: \"pencil\", quick: true },\n\t\t{ key: \"branch\", name: \"Branch from here\", icon: \"git-branch\", quick: false }\n\t].map((a) => ({\n\t\t...a,\n\t\tspecSlug: \"core\",\n\t\tslash: a.key,\n\t\taudience: { see: [\"participant\"], act: [\"item\"] },\n\t\tvenue: \"message\",\n\t\torigin: \"core\" as const,\n\t\tfloor: true,\n\t\tcanAct: true,\n\t\titemGated: a.key !== \"branch\",\n\t\tisNew: false,\n\t\tenabled: true\n\t}))\n\n\t/** The whole list, primary first — the menu is the complete list. */\n\tconst listed = $derived(\n\t\tmessageActions\n\t\t\t? [...messageActions.primary, ...messageActions.overflow]\n\t\t\t: FLOORS\n\t)\n\n\t/** This message's state, for the verb table. */\n\tconst verbCtx = $derived<\n\t\tOmit<VerbContext, \"canAct\" | \"itemGated\" | \"action\" | \"enabled\" | \"reason\" | \"itemPredicates\">\n\t>({\n\t\tmsg,\n\t\tisLastMessage,\n\t\tediting: conv.edit.id !== null,\n\t\thasGeneratingMessage,\n\t\tcanControl,\n\t\textendRefusal\n\t})\n\t// `itemGated` rides with `canAct` (W6): a contributed action whose\n\t// audience is `item` was answered `true` ahead of any message, and this\n\t// message's ownership rule is what decides. The enabled-when verdict\n\t// rides beside them (U5e): the list's `enabled`/`reason`, and the\n\t// `item.*` predicates this row is judged against.\n\tconst stateOf = (a: WidgetAction) =>\n\t\tcoreVerbState(verbKeyOf(a), { ...verbCtx, ...verdictOf(a) })\n\n\t/** The rows the menu draws: shown by the table, core's before contributed. */\n\tconst rows = $derived(\n\t\tlisted\n\t\t\t.map((a) => ({ action: a, state: stateOf(a) }))\n\t\t\t.filter((r) => r.state.shown)\n\t)\n\tconst coreRows = $derived(rows.filter((r) => r.action.specSlug === \"core\"))\n\tconst contributedRows = $derived(\n\t\trows.filter((r) => r.action.specSlug !== \"core\")\n\t)\n\tconst hasNew = $derived(contributedRows.some((r) => r.action.isNew))\n\n\t/** Fire a core verb by its key: the conversation's verb, or its own edit. */\n\tfunction fireCore(_e: Event, key: string) {\n\t\tcloseMenu()\n\t\tif (key === \"edit\") return conv.edit.start(msg)\n\t\tif (key === \"swipe\") return conv.swipe(msg, \"right\")\n\t\tconv.invoke(key, msg)\n\t}\n\n\t/** The row's name: the verb, with hide's read off the message's state. */\n\tfunction nameOf(a: WidgetAction) {\n\t\treturn a.key === \"hide\" && a.specSlug === \"core\"\n\t\t\t? msg.isHidden\n\t\t\t\t? \"Unhide\"\n\t\t\t\t: \"Hide\"\n\t\t\t: a.name\n\t}\n\t/**\n\t * The tooltip for one row, the chips' shape: the name, then the reason\n\t * when it is grey (UI nit 2). The reason also reaches assistive tech\n\t * through `aria-describedby` → an sr-only note, so the accessible NAME\n\t * stays the verb — a name that also carries the reason is read twice.\n\t */\n\tconst titleOf = (a: WidgetAction, reason?: string) =>\n\t\treason\n\t\t\t? `${nameOf(a)} — ${reason}`\n\t\t\t: a.description\n\t\t\t\t? `${nameOf(a)} — ${a.description}`\n\t\t\t\t: nameOf(a)\n\t/** One note id per row; the identity's punctuation is not an id's. */\n\tconst noteIdOf = (a: WidgetAction) =>\n\t\t`msg-${msg.id}-note-${actionIdentity(a).replace(/[^a-z0-9-]/g, \"-\")}`\n\n\t/**\n\t * \"Inspect run\" (R55: administrators only): the host finds the run that\n\t * wrote this reply and opens the inspector (`inspect-run`), or says there\n\t * is none.\n\t */\n\tconst isReply = $derived(!!msg.characterId || !!msg.isNarratorResponse)\n\n\t/**\n\t * The mark clears the moment the menu that lists the newcomers opens:\n\t * the person has now met them.\n\t */\n\t$effect(() => {\n\t\tif (!open || !hasNew) return\n\t\tvoid conv.request(\"actions-seen\", {\n\t\t\tkeys: contributedRows.filter((r) => r.action.isNew).map((r) => actionIdentity(r.action))\n\t\t})\n\t})\n</script>\n\n<!-- The ⋮ menu: every action this message offers, named in words. The row's\n quick icons call the same handlers; this is the complete list. Its parts\n are `messages.message-options*` (STYLE-GUIDE §6.16): no look here. -->\n<div data-widget-part=\"messages.message-options\">\n\t<!-- `sp-popover` (§3.5): the host's positioned panel. The trigger slot is\n\t our own button; the body is the panel. -->\n\t<sp-popover\n\t\tplacement=\"bottom-end\"\n\t\tlabel=\"Message options\"\n\t\t{open}\n\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => onOpenChange(e.detail.open)}\n\t>\n\t\t<button slot=\"trigger\" type=\"button\" data-widget-part=\"messages.message-options-button messages.message-icon-button\" aria-label=\"Message options\">\n\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"16\"></sp-icon>\n\t\t</button>\n\t\t\t\t<div data-widget-part=\"messages.message-options-panel\">\n\t\t\t\t\t<header data-widget-part=\"messages.message-options-title\">\n\t\t\t\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"18\"></sp-icon>\n\t\t\t\t\t\t<p>Message options</p>\n\t\t\t\t\t</header>\n\t\t\t\t\t<article data-widget-part=\"messages.message-options-list\">\n\t\t\t\t\t\t<!-- Core's verbs, from the list (R-15, U5c): every one\n\t\t\t\t\t\t the session offers on this message, primary set\n\t\t\t\t\t\t first, then the overflow — nothing is reachable\n\t\t\t\t\t\t only by hovering. Disabled and explained rather\n\t\t\t\t\t\t than hidden where the message's own state says no. -->\n\t\t\t\t\t\t<!-- Greyed, not disabled, like the chips (S6): `aria-disabled`\n\t\t\t\t\t\t keeps the row reachable and the reason reaches a screen\n\t\t\t\t\t\t reader through `aria-describedby`; a native `disabled`\n\t\t\t\t\t\t is skipped and says nothing. The click is guarded. -->\n\t\t\t\t\t\t{#each coreRows as { action, state } (action.key)}\n\t\t\t\t\t\t\t{@const iconName = action.icon || \"play\"}\n\t\t\t\t\t\t\t<!-- Which core verb (`data-verb`: the sheet sets Delete and\n\t\t\t\t\t\t\t Stop in the error's tone); Hide while the line is hidden\n\t\t\t\t\t\t\t is its `aria-pressed`, a row the line refuses its\n\t\t\t\t\t\t\t `aria-disabled`. -->\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\tdata-verb={action.key}\n\t\t\t\t\t\t\t\ttitle={titleOf(action, state.reason)}\n\t\t\t\t\t\t\t\taria-pressed={action.key === \"hide\"\n\t\t\t\t\t\t\t\t\t? !!msg.isHidden\n\t\t\t\t\t\t\t\t\t: undefined}\n\t\t\t\t\t\t\t\taria-disabled={state.disabled}\n\t\t\t\t\t\t\t\taria-describedby={state.reason\n\t\t\t\t\t\t\t\t\t? noteIdOf(action)\n\t\t\t\t\t\t\t\t\t: undefined}\n\t\t\t\t\t\t\t\tonclick={(e) =>\n\t\t\t\t\t\t\t\t\tstate.disabled\n\t\t\t\t\t\t\t\t\t\t? e.preventDefault()\n\t\t\t\t\t\t\t\t\t\t: fireCore(e, action.key)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name={iconName} size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>{nameOf(action)}</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t{#if state.reason}\n\t\t\t\t\t\t\t\t<span id={noteIdOf(action)} data-widget-part=\"messages.message-option-note\">\n\t\t\t\t\t\t\t\t\t{state.reason}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t{#if conv.dossier?.writes.lore && !msg.isGenerating}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\ttitle=\"Select for summary\"\n\t\t\t\t\t\t\t\taria-label=\"Select this message for summarization\"\n\t\t\t\t\t\t\t\tdisabled={conv.edit.id !== null || hasGeneratingMessage}\n\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\tcloseMenu()\n\t\t\t\t\t\t\t\t\tconv.select.start(msg)\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"book-marked\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Select for summary</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if canChangeSprite}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\ttitle=\"Choose the face this line shows\"\n\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\tcloseMenu()\n\t\t\t\t\t\t\t\t\tvoid conv.request(\"change-sprite\", { messageId: msg.id })\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"drama\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Change sprite</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if isAdmin && isReply && !msg.isGenerating}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\ttitle=\"See what the pipeline did for this reply\"\n\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\tcloseMenu()\n\t\t\t\t\t\t\t\t\tvoid conv.request(\"inspect-run\", { messageId: msg.id })\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"receipt\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Inspect run</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if conv.dossier?.debugPrompts && conv.line(msg.id).promptDetails && !msg.isGenerating}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\ttitle=\"Prompt details\"\n\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\tcloseMenu()\n\t\t\t\t\t\t\t\t\tvoid conv.request(\"prompt-details\", { messageId: msg.id })\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"info\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Prompt details</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if contributedRows.length}\n\t\t\t\t\t\t\t<!-- The contributed entries (19 §4): after core's\n\t\t\t\t\t\t\t verbs, separated so a plugin's never reads as\n\t\t\t\t\t\t\t one of core's. A newcomer wears its mark until\n\t\t\t\t\t\t\t this menu has been opened once. -->\n\t\t\t\t\t\t\t<hr data-widget-part=\"messages.message-options-divider\" />\n\t\t\t\t\t\t\t{#each contributedRows as { action, state } (actionIdentity(action))}\n\t\t\t\t\t\t\t\t{@const iconName = action.icon || \"play\"}\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\t\ttitle={titleOf(action, state.reason)}\n\t\t\t\t\t\t\t\t\taria-disabled={state.disabled}\n\t\t\t\t\t\t\t\t\taria-describedby={state.reason\n\t\t\t\t\t\t\t\t\t\t? noteIdOf(action)\n\t\t\t\t\t\t\t\t\t\t: undefined}\n\t\t\t\t\t\t\t\t\tonclick={(e) => {\n\t\t\t\t\t\t\t\t\t\tif (state.disabled) {\n\t\t\t\t\t\t\t\t\t\t\te.preventDefault()\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tcloseMenu()\n\t\t\t\t\t\t\t\t\t\tconv.invoke(actionIdentity(action), msg)\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name={iconName} size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t\t<span>{action.name}</span>\n\t\t\t\t\t\t\t\t\t{#if action.isNew}\n\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.message-option-new\" aria-label=\"New\">\n\t\t\t\t\t\t\t\t\t\t\tNew\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\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{#if state.reason}\n\t\t\t\t\t\t\t\t\t<span id={noteIdOf(action)} data-widget-part=\"messages.message-option-note\">\n\t\t\t\t\t\t\t\t\t\t{state.reason}\n\t\t\t\t\t\t\t\t\t</span>\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</article>\n\t\t\t\t</div>\n\t</sp-popover>\n</div>\n\n","sessions/messages/MessageMediaStrip.svelte":"<script lang=\"ts\">\n\t/**\n\t * The media strip (composer attachments plan §3.4; next-pass note 40,\n\t * 2026-10-03): a message's images and files as a row of square tiles\n\t * BELOW the message's card — never inside it — in every state of the row:\n\t * settled, legacy text, editing and generating alike. `SessionMessage`\n\t * mounts it as its own cell of the message grid, under the content.\n\t *\n\t * - every image, one or many, is a square **tile**: the `thumb` variant\n\t * cropped to fill the square, the same size each; past\n\t * `MEDIA_STRIP_MAX_TILES` the rest fold into a count tile that opens\n\t * the lightbox where the tiles stop;\n\t * - a file is a square **file tile**: its kind's icon, its name, its size\n\t * when known, and a download link.\n\t *\n\t * Every tile is a button (keyboard-reachable, named \"Open image cat.png,\n\t * 1 of 3\") that asks the page for its lightbox through `onOpen`. An image\n\t * whose file is gone (deleted from the Media panel) raises `error` and is\n\t * drawn as \"File no longer available\" — never a broken image — and leaves\n\t * the lightbox's gallery.\n\t *\n\t * No look here: every element is a widget part (`messages.media-*`,\n\t * STYLE-GUIDE §6.16, §6.18), drawn by the default widget stylesheet.\n\t */\n\timport { SvelteSet } from 'svelte/reactivity'\n\timport {\n\t\tfileIcon,\n\t\tformatBytes,\n\t\tmediaDownloadHref,\n\t\tmediaSrc,\n\t\tMEDIA_STRIP_MAX_TILES,\n\t\ttype MediaStripItem,\n\t} from './mediaStrip'\n\n\tinterface Props {\n\t\titems: MediaStripItem[]\n\t\t/** Open image `index` of `images` (the strip's available images) in the lightbox. */\n\t\tonOpen?: (images: MediaStripItem[], index: number) => void\n\t\t/** The row is being edited: a tile may be taken off (D9, remove only). */\n\t\tediting?: boolean\n\t\t/**\n\t\t * Take one attachment off the message. Absent, no ✕ is drawn — the\n\t\t * host has no removal to offer yet — and absent too for a viewer who\n\t\t * does not control the row.\n\t\t */\n\t\tonRemove?: (item: MediaStripItem) => void\n\t}\n\n\tlet { items, onOpen, editing = false, onRemove }: Props = $props()\n\n\t/** Images whose file failed to load, by part id. */\n\tconst missing = new SvelteSet<number>()\n\n\tconst images = $derived(items.filter((i) => i.kind === 'image'))\n\tconst files = $derived(items.filter((i) => i.kind === 'file'))\n\t/** What the lightbox can page through: every image still there. */\n\tconst openable = $derived(images.filter((i) => !missing.has(i.partId)))\n\tconst folds = $derived(images.length > MEDIA_STRIP_MAX_TILES)\n\t/** With a count tile, the tiles leave its place: one fewer than the cap. */\n\tconst shown = $derived(folds ? images.slice(0, MEDIA_STRIP_MAX_TILES - 1) : images)\n\tconst hidden = $derived(images.length - shown.length)\n\tconst removable = $derived(editing && !!onRemove)\n\n\tfunction open(item: MediaStripItem) {\n\t\tconst index = openable.findIndex((i) => i.partId === item.partId)\n\t\tif (index >= 0) onOpen?.(openable, index)\n\t}\n\n\tfunction openFolded() {\n\t\t// The first image the tiles left out that is still there.\n\t\tconst first = images.slice(shown.length).find((i) => !missing.has(i.partId))\n\t\tif (first) open(first)\n\t}\n\n\t/** \"Open image cat.png, 2 of 3\" — the position among what the lightbox shows. */\n\tfunction openLabel(item: MediaStripItem): string {\n\t\tconst at = openable.findIndex((i) => i.partId === item.partId)\n\t\treturn openable.length > 1\n\t\t\t? `Open image ${item.label}, ${at + 1} of ${openable.length}`\n\t\t\t: `Open image ${item.label}`\n\t}\n</script>\n\n{#snippet removeButton(item: MediaStripItem)}\n\t{#if removable}\n\t\t<button\n\t\t\ttype=\"button\"\n\t\t\tdata-widget-part=\"messages.media-remove\"\n\t\t\taria-label=\"Remove {item.label}\"\n\t\t\ttitle=\"Remove {item.label}\"\n\t\t\tonclick={() => onRemove?.(item)}\n\t\t>\n\t\t\t<sp-icon name=\"x\" size=\"14\"></sp-icon>\n\t\t</button>\n\t{/if}\n{/snippet}\n\n{#snippet gone(item: MediaStripItem)}\n\t<div data-widget-part=\"messages.media-missing\" role=\"img\" aria-label=\"{item.label}: file no longer available\">\n\t\t<sp-icon name=\"image-off\" size=\"20\"></sp-icon>\n\t\t<span data-widget-part=\"messages.media-missing-text\">File no longer available</span>\n\t</div>\n{/snippet}\n\n{#if items.length}\n\t<div\n\t\tdata-widget-part=\"messages.media-strip\"\n\t\tdata-editing={removable ? '' : undefined}\n\t\trole=\"group\"\n\t\taria-label={items.length === 1 ? 'Attachment' : `${items.length} attachments`}\n\t>\n\t\t{#if images.length}\n\t\t\t<div data-widget-part=\"messages.media-images\">\n\t\t\t\t{#each shown as item (item.partId)}\n\t\t\t\t\t<div data-widget-part=\"messages.media-item\">\n\t\t\t\t\t\t{#if missing.has(item.partId)}\n\t\t\t\t\t\t\t{@render gone(item)}\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.media-tile\"\n\t\t\t\t\t\t\t\taria-label={openLabel(item)}\n\t\t\t\t\t\t\t\tonclick={() => open(item)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.media-tile-img\"\n\t\t\t\t\t\t\t\t\tsrc={mediaSrc(item.assetId, 'thumb')}\n\t\t\t\t\t\t\t\t\talt={item.label}\n\t\t\t\t\t\t\t\t\tloading=\"lazy\"\n\t\t\t\t\t\t\t\t\tdecoding=\"async\"\n\t\t\t\t\t\t\t\t\tonerror={() => missing.add(item.partId)}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{@render removeButton(item)}\n\t\t\t\t\t</div>\n\t\t\t\t{/each}\n\t\t\t\t{#if folds}\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tdata-widget-part=\"messages.media-more\"\n\t\t\t\t\t\taria-label=\"Show {hidden} more {hidden === 1 ? 'image' : 'images'}\"\n\t\t\t\t\t\tonclick={openFolded}\n\t\t\t\t\t>\n\t\t\t\t\t\t+{hidden}\n\t\t\t\t\t</button>\n\t\t\t\t{/if}\n\t\t\t</div>\n\t\t{/if}\n\t\t{#if files.length}\n\t\t\t<ul data-widget-part=\"messages.media-files\">\n\t\t\t\t{#each files as item (item.partId)}\n\t\t\t\t\t<li data-widget-part=\"messages.media-item\">\n\t\t\t\t\t\t<a\n\t\t\t\t\t\t\tdata-widget-part=\"messages.media-file\"\n\t\t\t\t\t\t\thref={mediaDownloadHref(item.assetId)}\n\t\t\t\t\t\t\tdownload={item.name ?? undefined}\n\t\t\t\t\t\t\ttitle={item.label}\n\t\t\t\t\t\t\taria-label=\"Download {item.label}{item.bytes ? `, ${formatBytes(item.bytes)}` : ''}\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name={fileIcon(item.mime)} size=\"20\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.media-file-name\">{item.label}</span>\n\t\t\t\t\t\t\t{#if item.bytes}\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.media-file-size\">{formatBytes(item.bytes)}</span>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t<sp-icon name=\"download\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t\t{@render removeButton(item)}\n\t\t\t\t\t</li>\n\t\t\t\t{/each}\n\t\t\t</ul>\n\t\t{/if}\n\t</div>\n{/if}\n","sessions/messages/MessagePartsView.svelte":"<script lang=\"ts\">\n\t/**\n\t * The parts-native message body (20 §2, phase 2 of §13).\n\t *\n\t * Renders a message's typed parts: steps ascending (they accumulate — a\n\t * stepped activity's phases stand side by side), each step showing only\n\t * its active revision (`activeRevisions`, the swipe cursor), parts in\n\t * their own ordinal order.\n\t *\n\t * Types: markdown is the body; reasoning and sections are collapsibles —\n\t * the generalization that retires the two hardcoded blocks in\n\t * SessionMessage. A reply's **folded sections** (B4; D5, 2026-09-27) are\n\t * `core:section` parts: collapsed by default, laid out by the host above\n\t * the reasoning and the body, and a section with `items` draws them as a\n\t * list — never as JSON. An unknown namespaced type (its plugin is gone, or not\n\t * yet installed) renders as a collapsed labeled section rather than\n\t * breaking: uninstalling strands nothing. `core:image` / `core:file` parts\n\t * are not drawn here: the media strip under the body shows them\n\t * (composer attachments plan §3.4).\n\t */\n\timport MessageBlocksView from \"./MessageBlocksView.svelte\"\n\timport type { MessagePartV1 } from \"@serene-pub/sdk/component\"\n\n\tinterface Props {\n\t\tmessageId: number\n\t\tparts: MessagePartV1[]\n\t\tactiveRevisions: Record<string, number>\n\t\t/** An image in the message was clicked — its address. */\n\t\tonOpenImage?: (src: string) => void\n\t\t/** Declared block actions (20 §6) — fn + payload up to the page; a form's `blockId` rides along (U5d). */\n\t\tonAction?: (\n\t\t\tfn: string,\n\t\t\tpayload?: Record<string, unknown>,\n\t\t\taction?: string,\n\t\t\tblockId?: string\n\t\t) => void\n\t\t/** The message body, so a form's question is not shown twice. */\n\t\tbodyText?: string\n\t\t/** The viewer's verdict on a form's addressee (U5d review, W7) — see `MessageBlocksView`. */\n\t\tcanAnswer?: (addressee: string | undefined) => boolean\n\t\t/** Whether the channel has moved past a form (U5f) — see `MessageBlocksView`. */\n\t\tisStale?: (block: { head?: unknown; answered?: unknown }) => boolean\n\t}\n\n\tlet {\n\t\tmessageId,\n\t\tparts,\n\t\tactiveRevisions,\n\t\tonOpenImage,\n\t\tonAction,\n\t\tbodyText,\n\t\tcanAnswer,\n\t\tisStale\n\t}: Props = $props()\n\n\t/** Expanded state per collapsible, keyed by part id. Default collapsed. */\n\tlet expanded = $state<Record<number, boolean>>({})\n\n\tconst steps = $derived(\n\t\t[...new Set(parts.map((p) => p.step))].sort((a, b) => a - b)\n\t)\n\n\tfunction visibleParts(step: number): MessagePartV1[] {\n\t\tconst active = activeRevisions[String(step)] ?? 0\n\t\treturn parts\n\t\t\t.filter((p) => p.step === step && p.revision === active)\n\t\t\t.sort((a, b) => a.ordinal - b.ordinal)\n\t}\n\n\tfunction sectionTitle(part: MessagePartV1): string {\n\t\tconst t = (part.data as any)?.title\n\t\tif (typeof t === \"string\" && t) return t\n\t\treturn \"Section\"\n\t}\n\n\t/** A folded section's list, when it is one — strings only. */\n\tfunction sectionItems(part: MessagePartV1): string[] | undefined {\n\t\tconst items = (part.data as any)?.items\n\t\treturn Array.isArray(items) &&\n\t\t\titems.every((i: unknown) => typeof i === \"string\")\n\t\t\t? items\n\t\t\t: undefined\n\t}\n\n\t/** A section of reasoning wears the reasoning fold's glyph; every other kind the notebook. */\n\tfunction sectionIcon(part: MessagePartV1): \"brain\" | \"notebook\" {\n\t\treturn (part.data as any)?.kind === \"reasoning\" ? \"brain\" : \"notebook\"\n\t}\n\n\t/** The graceful floor: what an unknown type shows when unfolded. */\n\tfunction unknownBody(part: MessagePartV1): string {\n\t\tif (part.content) return part.content\n\t\ttry {\n\t\t\treturn \"```json\\n\" + JSON.stringify(part.data ?? {}, null, 2) + \"\\n```\"\n\t\t} catch {\n\t\t\treturn \"\"\n\t\t}\n\t}\n</script>\n\n{#snippet collapsible(\n\tpart: MessagePartV1,\n\ttitle: string,\n\ticon: \"brain\" | \"notebook\" | \"puzzle\" | \"wrench\",\n\tbody: string,\n\titems?: string[]\n)}\n\t<div data-widget-part=\"messages.part-disclosure\">\n\t\t<button\n\t\t\ttype=\"button\"\n\t\t\tdata-widget-part=\"messages.part-disclosure-toggle\"\n\t\t\tonclick={() => (expanded[part.id] = !expanded[part.id])}\n\t\t\ttitle={expanded[part.id] ? `Collapse ${title}` : `Expand ${title}`}\n\t\t\taria-expanded={!!expanded[part.id]}\n\t\t\taria-controls=\"part-{messageId}-{part.id}\"\n\t\t>\n\t\t\t{#if icon === \"brain\"}\n\t\t\t\t<sp-icon name=\"brain-circuit\" size=\"16\"></sp-icon>\n\t\t\t{:else if icon === \"notebook\"}\n\t\t\t\t<sp-icon name=\"notebook-pen\" size=\"16\"></sp-icon>\n\t\t\t{:else if icon === \"wrench\"}\n\t\t\t\t<sp-icon name=\"wrench\" size=\"16\"></sp-icon>\n\t\t\t{:else}\n\t\t\t\t<sp-icon name=\"puzzle\" size=\"16\"></sp-icon>\n\t\t\t{/if}\n\t\t\t<span>{title}</span>\n\t\t\t<!-- Unfolded, the chevron turns: the toggle's `aria-expanded`. -->\n\t\t\t<sp-icon name=\"chevron-down\" size=\"16\" data-widget-part=\"messages.part-disclosure-chevron\"></sp-icon>\n\t\t</button>\n\t\t<!-- grid 0fr -> 1fr transitions to/from auto height in pure CSS; the\n\t\t overflow-hidden wrapper keeps collapsed content from spilling, and\n\t\t the skin's `visibility` keeps the 0fr track's focusables out of the\n\t\t tab order (`messages.part-disclosure-track`, widgets.css). -->\n\t\t<div\n\t\t\tid=\"part-{messageId}-{part.id}\"\n\t\t\tdata-widget-part=\"messages.part-disclosure-track\"\n\t\t\tdata-expanded={expanded[part.id] ? \"\" : undefined}\n\t\t>\n\t\t\t<div data-widget-part=\"messages.part-disclosure-clip\">\n\t\t\t\t<div data-widget-part=\"messages.part-disclosure-panel messages.prose\">\n\t\t\t\t\t{#if items}\n\t\t\t\t\t\t<ul data-widget-part=\"messages.fold-list\">\n\t\t\t\t\t\t\t{#each items as item, i (i)}\n\t\t\t\t\t\t\t\t<li>{item}</li>\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t{:else}\n\t\t\t\t\t\t<sp-message-body text={body}></sp-message-body>\n\t\t\t\t\t{/if}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n{/snippet}\n\n{#each steps as step, i (step)}\n\t{#if i > 0}\n\t\t<!-- Steps accumulate (20 §1): a stepped activity's phases render\n\t\t stacked, separated so the progression reads as chapters. -->\n\t\t<hr data-widget-part=\"messages.part-step-divider\" />\n\t{/if}\n\t{#each visibleParts(step) as part (part.id)}\n\t\t{#if part.type === \"core:markdown\"}\n\t\t\t<div data-widget-part=\"messages.part-markdown messages.prose\">\n\t\t\t\t<sp-message-body\n\t\t\t\t\ttext={part.content ?? \"\"}\n\t\t\t\t\tonopen-image={(e: CustomEvent<{ src: string }>) => onOpenImage?.(e.detail.src)}\n\t\t\t\t></sp-message-body>\n\t\t\t</div>\n\t\t{:else if part.type === \"core:reasoning\"}\n\t\t\t{@render collapsible(part, \"Reasoning\", \"brain\", part.content ?? \"\")}\n\t\t{:else if part.type === \"core:tool-call\"}\n\t\t\t{@render collapsible(\n\t\t\t\tpart,\n\t\t\t\t(part.data as any)?.tool\n\t\t\t\t\t? `Tool: ${(part.data as any).tool}`\n\t\t\t\t\t: \"Tool call\",\n\t\t\t\t\"wrench\",\n\t\t\t\tpart.content ?? unknownBody(part)\n\t\t\t)}\n\t\t{:else if part.type === \"core:tool-result\"}\n\t\t\t{@render collapsible(\n\t\t\t\tpart,\n\t\t\t\t\"Tool result\",\n\t\t\t\t\"wrench\",\n\t\t\t\tpart.content ?? unknownBody(part)\n\t\t\t)}\n\t\t{:else if part.type === \"core:section\"}\n\t\t\t{@render collapsible(\n\t\t\t\tpart,\n\t\t\t\tsectionTitle(part),\n\t\t\t\tsectionIcon(part),\n\t\t\t\tpart.content ?? \"\",\n\t\t\t\tsectionItems(part)\n\t\t\t)}\n\t\t{:else if part.type === \"core:image\" || part.type === \"core:file\"}\n\t\t\t<!-- Attachments and generated images are the media strip's\n\t\t\t (MessageMediaStrip, under the body in every state of the row),\n\t\t\t never drawn inline here — and never the unknown-type fold. -->\n\t\t{:else if Array.isArray((part.data as any)?.blocks)}\n\t\t\t<!-- A block tree (20 §6): plugin content as data, core's renderer,\n\t\t\t whatever the part's namespace — the convention, not a registry. -->\n\t\t\t<MessageBlocksView\n\t\t\t\tblocks={(part.data as any).blocks}\n\t\t\t\t{onAction}\n\t\t\t\t{bodyText}\n\t\t\t\t{canAnswer}\n\t\t\t\t{isStale}\n\t\t\t/>\n\t\t{:else}\n\t\t\t{@render collapsible(part, part.type, \"puzzle\", unknownBody(part))}\n\t\t{/if}\n\t{/each}\n{/each}\n","sessions/messages/MessageStateLedger.svelte":"<script lang=\"ts\">\n\t/**\n\t * The transcript ledger: what one message changed, under that message.\n\t *\n\t * Every line is a real row anchored to this message, which is what makes it\n\t * revertible WITH the message: delete or regenerate the reply and the rows it\n\t * wrote go too, so the ledger cannot drift from the fiction it describes.\n\t * It renders nothing at all for a message that changed nothing, which is\n\t * almost every message in almost every session.\n\t *\n\t * Pending lines are the model's proposals waiting at the gate. They sit here\n\t * rather than in a queue somewhere else because the sentence that justifies a\n\t * change is the one above them; **Review** opens the same rows for the whole\n\t * session, for when they have scrolled away.\n\t */\n\timport StateProposalList from \"./StateProposalList.svelte\"\n\timport { useConversation } from \"./conversation.svelte\"\n\n\tinterface Props {\n\t\tmessageId: number\n\t}\n\tlet { messageId }: Props = $props()\n\n\t// What this line changed and what waits on it: the page's projection of\n\t// the session state (C0b), read off the conversation.\n\tconst conv = useConversation()\n\tlet groups = $derived(conv.dossier?.state.ledgers[messageId] ?? [])\n\tlet pending = $derived(conv.dossier?.state.pending[messageId] ?? [])\n\tlet waiting = $derived(conv.dossier?.state.waiting ?? [])\n\tlet reviewOpen = $state(false)\n</script>\n\n<!-- The ledger's parts (`messages.ledger*`, `messages.proposal*`; STYLE-GUIDE\n §6.16): no look here; the default widget stylesheet draws them. -->\n{#if groups.length || pending.length}\n\t<div data-widget-part=\"messages.ledger\" data-ledger-message={messageId}>\n\t\t{#each groups as group (group.ownerKey)}\n\t\t\t<p data-widget-part=\"messages.ledger-line\" data-owner-key={group.ownerKey}>\n\t\t\t\t<span data-widget-part=\"messages.ledger-owner\">{group.ownerLabel}</span>\n\t\t\t\t{#each group.lines as line, i (line.key)}\n\t\t\t\t\t{#if i > 0}<span data-widget-part=\"messages.ledger-separator\">·</span>{/if}\n\t\t\t\t\t<span data-widget-part=\"messages.ledger-change\" title=\"changed by {line.updatedBy}\">\n\t\t\t\t\t\t{line.text}\n\t\t\t\t\t</span>\n\t\t\t\t{/each}\n\t\t\t</p>\n\t\t{/each}\n\n\t\t{#if pending.length}\n\t\t\t<StateProposalList proposals={pending} />\n\t\t{/if}\n\n\t\t{#if waiting.length}\n\t\t\t<!-- `sp-popover` (§3.5): our button is the trigger, the card the panel. -->\n\t\t\t<sp-popover\n\t\t\t\tplacement=\"bottom-start\"\n\t\t\t\tlabel=\"Waiting for you\"\n\t\t\t\topen={reviewOpen}\n\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => (reviewOpen = e.detail.open)}\n\t\t\t>\n\t\t\t\t<button slot=\"trigger\" type=\"button\" data-widget-part=\"messages.ledger-review\">\n\t\t\t\t\t<sp-icon name=\"clipboard-check\" size=\"11\"></sp-icon>\n\t\t\t\t\t<span>\n\t\t\t\t\t\tReview\n\t\t\t\t\t\t{waiting.length === 1\n\t\t\t\t\t\t\t? \"1 change\"\n\t\t\t\t\t\t\t: `${waiting.length} changes`}\n\t\t\t\t\t</span>\n\t\t\t\t</button>\n\t\t\t\t\t\t<div data-widget-part=\"messages.ledger-review-panel\">\n\t\t\t\t\t\t\t<header\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.ledger-review-title\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"clipboard-check\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Waiting for you</span>\n\t\t\t\t\t\t\t</header>\n\t\t\t\t\t\t\t<p data-widget-part=\"messages.ledger-review-note\">\n\t\t\t\t\t\t\t\tThe AI asked for these. Nothing changes until\n\t\t\t\t\t\t\t\tyou accept one.\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t<StateProposalList proposals={waiting} showAnchor />\n\t\t\t\t\t\t</div>\n\t\t\t</sp-popover>\n\t\t{/if}\n\t</div>\n{/if}\n","sessions/messages/Messages.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's messages widget as a remote component (C0b): the component\n\t * context, as the native widget context, around the very same\n\t * `MessagesWidget` the page mounts natively.\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/conversation\"\n\timport MessagesWidget from \"./MessagesWidget.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: \"messages\", instanceId: \"messages\", title: \"Messages\" }\n\t\t)\n\t)\n</script>\n\n<MessagesWidget />\n","sessions/messages/MessagesWidget.svelte":"<script lang=\"ts\" module>\n\timport type { MessageOrder } from \"@serene-pub/core-catalog/conversation\"\n\n\t/** How the composer's field is drawn. */\n\texport type ComposerSkin = \"classic\" | \"minimal\" | \"writer\" | \"quill\"\n\n\t/** Which end of the widget the composer sits at. */\n\texport type ComposerPosition = \"bottom\" | \"top\"\n\n\t/**\n\t * Who is due next (PLAN-turn-order §4.9): the order's head with Continue,\n\t * the head and who follows it, or nothing.\n\t */\n\texport type NextUp = \"head\" | \"list\" | \"hidden\"\n\n\t/**\n\t * How wide the log's rows and the composer run: the whole width the layout\n\t * gives the widget (`full`, the default), or a reading measure centred in\n\t * it (`comfortable`, about 640px of prose). Never a hidden cap: the widget\n\t * fills its box unless its settings say otherwise.\n\t */\n\texport type LineWidth = \"full\" | \"comfortable\"\n\n\t/**\n\t * The `messages` widget's settings, complete: every value the widget reads,\n\t * with the declared default wherever the instance has no deviation. The\n\t * page receives this object too (as the snippet parameter and through\n\t * `onSettings`), so the log, the composer and the page's scroll handling\n\t * all answer to one reading of the settings.\n\t */\n\texport interface ConversationSettings {\n\t\torder: MessageOrder\n\t\tcomposerSkin: ComposerSkin\n\t\tcomposerPosition: ComposerPosition\n\t\tlineWidth: LineWidth\n\t\tshowMessages: boolean\n\t\tshowComposer: boolean\n\t\tshowAvatars: boolean\n\t\tshowTimestamps: boolean\n\t\tshowSceneMarkers: boolean\n\t\tnextUp: NextUp\n\t\tshowActions: boolean\n\t\t/**\n\t\t * The one channel this copy shows (lair re-plan S1), or `null` for the\n\t\t * primary log. The host narrows the rows and the composer's channels\n\t\t * by it; the widget draws its head from it.\n\t\t */\n\t\tchannel: string | null\n\t}\n\n\t/**\n\t * The declared defaults (`CORE_WIDGETS`, the `messages` entry), restated as\n\t * the fallback for a mount with no `WidgetHost` above it — a standalone\n\t * render, a test — where there is no `settings.v1` to read.\n\t */\n\texport const CONVERSATION_DEFAULTS: ConversationSettings = {\n\t\torder: \"oldest-first\",\n\t\tcomposerSkin: \"classic\",\n\t\tcomposerPosition: \"bottom\",\n\t\tlineWidth: \"full\",\n\t\tshowMessages: true,\n\t\tshowComposer: true,\n\t\tshowAvatars: true,\n\t\tshowTimestamps: true,\n\t\tshowSceneMarkers: true,\n\t\tnextUp: \"head\",\n\t\tshowActions: true,\n\t\tchannel: null\n\t}\n\n\tfunction pickEnum<T extends string>(\n\t\traw: unknown,\n\t\tof: readonly T[],\n\t\tfallback: T\n\t): T {\n\t\treturn typeof raw === \"string\" &&\n\t\t\t(of as readonly string[]).includes(raw)\n\t\t\t? (raw as T)\n\t\t\t: fallback\n\t}\n\n\tfunction pickBool(raw: unknown, fallback: boolean): boolean {\n\t\treturn typeof raw === \"boolean\" ? raw : fallback\n\t}\n\n\t/** Read one settings payload into the complete object above. */\n\texport function readConversationSettings(\n\t\traw: Record<string, unknown> | undefined\n\t): ConversationSettings {\n\t\tconst v = raw ?? {}\n\t\tconst d = CONVERSATION_DEFAULTS\n\t\treturn {\n\t\t\torder: pickEnum(v.order, [\"oldest-first\", \"newest-first\"], d.order),\n\t\t\tcomposerSkin: pickEnum(\n\t\t\t\tv.composer,\n\t\t\t\t[\"classic\", \"minimal\", \"writer\", \"quill\"],\n\t\t\t\td.composerSkin\n\t\t\t),\n\t\t\tcomposerPosition: pickEnum(\n\t\t\t\tv.composerPosition,\n\t\t\t\t[\"bottom\", \"top\"],\n\t\t\t\td.composerPosition\n\t\t\t),\n\t\t\tlineWidth: pickEnum(v.lineWidth, [\"full\", \"comfortable\"], d.lineWidth),\n\t\t\tshowMessages: pickBool(v.showMessages, d.showMessages),\n\t\t\tshowComposer: pickBool(v.showComposer, d.showComposer),\n\t\t\tshowAvatars: pickBool(v.showAvatars, d.showAvatars),\n\t\t\tshowTimestamps: pickBool(v.showTimestamps, d.showTimestamps),\n\t\t\tshowSceneMarkers: pickBool(v.showSceneMarkers, d.showSceneMarkers),\n\t\t\t// ⏳ `showNudge: false` was this setting before `nextUp` (A8).\n\t\t\tnextUp: pickEnum(\n\t\t\t\tv.nextUp,\n\t\t\t\t[\"head\", \"list\", \"hidden\"],\n\t\t\t\tv.showNudge === false ? \"hidden\" : d.nextUp\n\t\t\t),\n\t\t\tshowActions: pickBool(v.showActions, d.showActions),\n\t\t\tchannel:\n\t\t\t\ttypeof v.channel === \"string\" && v.channel.trim()\n\t\t\t\t\t? v.channel.trim()\n\t\t\t\t\t: d.channel\n\t\t}\n\t}\n</script>\n\n<script lang=\"ts\">\n\t/**\n\t * The `messages` widget's component: the log you read and the\n\t * field you write into, as ONE widget.\n\t *\n\t * It owns the conversation (C0b): the model its parts read\n\t * (`conversation.svelte.ts`) and the log. The page still passes the\n\t * composer, the ready-to-continue line and the banners as snippets; this\n\t * component reads the widget's settings off `useWidgetContext()`, hands\n\t * them back to those snippets, writes them onto the root as data\n\t * attributes, and decides which end the composer sits at.\n\t */\n\timport { useWidgetContext } from \"../shared/context\"\n\timport SessionContainer from \"./SessionContainer.svelte\"\n\timport SessionComposer from \"./SessionComposer.svelte\"\n\timport NextCharacterBlock from \"./NextCharacterBlock.svelte\"\n\timport { createConversation, setConversation } from \"./conversation.svelte\"\n\n\tinterface Props {\n\t\t/**\n\t\t * Called with the effective settings whenever they change, for the\n\t\t * page's imperative half — the scroll handling, which runs outside the\n\t\t * render and cannot read a snippet parameter.\n\t\t */\n\t\tonSettings?: (settings: ConversationSettings) => void\n\t}\n\n\tlet { onSettings }: Props = $props()\n\n\tconst ctx = useWidgetContext()\n\t// The conversation's own model (C0b): the log and its lines read it, and\n\t// act through its verbs. Absent a host there is nothing to converse with.\n\tconst conversation = ctx ? setConversation(createConversation(ctx)) : null\n\n\t// A host view asked for a selection (the workflow tab): start one.\n\tlet askedToSelect: number | null = null\n\t$effect(() => {\n\t\tconst n = conversation?.dossier?.selectForSummary ?? 0\n\t\tif (askedToSelect !== null && n !== askedToSelect) conversation?.select.start()\n\t\taskedToSelect = n\n\t})\n\tconst selecting = $derived(!!conversation?.select.active)\n\tconst selectedCount = $derived(conversation?.select.ids.size ?? 0)\n\t/** Every line a scene has not already captured. */\n\tconst selectable = $derived.by(() => {\n\t\tconst taken = new Set(conversation?.dossier?.scened ?? [])\n\t\treturn ((conversation?.rows ?? []) as Array<{ id: number }>)\n\t\t\t.map((m) => m.id)\n\t\t\t.filter((id) => !taken.has(id))\n\t})\n\tlet settings = $derived(\n\t\treadConversationSettings(\n\t\t\tctx?.current.settings.v1 as Record<string, unknown> | undefined\n\t\t)\n\t)\n\n\t// Compared by value, the way `WidgetHost` compares its layout: the widget\n\t// context re-projects on every message that lands, and the settings on it\n\t// are the same object nearly every time.\n\tlet lastSettingsKey: string | null = null\n\t$effect(() => {\n\t\tconst next = settings\n\t\tconst key = JSON.stringify(next)\n\t\tif (key === lastSettingsKey) return\n\t\tlastSettingsKey = key\n\t\tonSettings?.(next)\n\t})\n</script>\n\n<!-- The widget's parts (`messages.*`, STYLE-GUIDE §6.16): no look here; the\n default widget stylesheet draws them, and a pack or a person's style\n restyles them. -->\n<div\n\tdata-widget-part=\"messages.root\"\n\tdata-order={settings.order}\n\tdata-composer-position={settings.composerPosition}\n\tdata-composer-skin={settings.composerSkin}\n\tdata-line-width={settings.lineWidth}\n\tdata-show-messages={settings.showMessages}\n\tdata-show-avatars={settings.showAvatars}\n\tdata-show-timestamps={settings.showTimestamps}\n\tdata-show-scene-markers={settings.showSceneMarkers}\n\tdata-channel={settings.channel ?? undefined}\n>\n\t{#if settings.channel && conversation}\n\t\t<!-- A copy pinned to one channel names it (S1): the channel's declared\n\t\t label, the Lair's _Sanctum_. The primary log has no head — the\n\t\t session's own header names it. -->\n\t\t<header data-widget-part=\"messages.channel-head\">\n\t\t\t<sp-icon name=\"messages-square\" size=\"16\" data-widget-part=\"messages.channel-icon\"></sp-icon>\n\t\t\t<h2 data-widget-part=\"messages.channel-title\">{conversation.channelName(settings.channel)}</h2>\n\t\t</header>\n\t{/if}\n\t<!-- The whole panel scrolls: the log spans the widget's width, so its\n\t scrollbar sits at the panel's edge and the wheel works anywhere in it;\n\t the rows (the stage, `messages.stage`) and the composer take the\n\t widget's full width, or a centred reading measure when the Line width\n\t setting says Comfortable. DOM order is log then composer whichever end the\n\t composer is drawn at: the reading order a screen reader and the tab\n\t sequence follow is the conversation's, and `order` moves the box on\n\t screen. -->\n\t{#if settings.showMessages}\n\t\t<div data-widget-part=\"messages.log\">\n\t\t\t{#if conversation}\n\t\t\t\t<SessionContainer order={settings.order} showSceneMarkers={settings.showSceneMarkers} />\n\t\t\t{/if}\n\t\t</div>\n\t{/if}\n\t{#if selecting && conversation}\n\t\t<!-- Selecting lines for a summary: the composer steps aside for the\n\t\t selection's own bar, and committing hands it to the host. -->\n\t\t<!-- The compose block (`messages.compose`, on the reading column) and the\n\t\t composer's area (`messages.compose-area`), where the selection bar\n\t\t stands in the composer's place. -->\n\t\t<div data-widget-part=\"messages.compose\">\n\t\t\t<div data-widget-part=\"messages.compose-area\">\n\t\t\t\t<!-- The selection bar's parts are `messages.selection-*` (STYLE-GUIDE\n\t\t\t\t §6.16): no look here; the default widget stylesheet draws them. -->\n\t\t\t\t<div data-widget-part=\"messages.selection-bar toolbar\">\n\t\t\t\t\t<span data-widget-part=\"messages.selection-count\">\n\t\t\t\t\t\t{selectedCount}\n\t\t\t\t\t\t{selectedCount === 1 ? \"message\" : \"messages\"} selected\n\t\t\t\t\t</span>\n\t\t\t\t\t<div data-widget-part=\"messages.selection-bulk\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.select-all messages.selection-button\"\n\t\t\t\t\t\t\ttitle=\"Select all\"\n\t\t\t\t\t\t\tonclick={() => conversation.select.set(selectable)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"check-square\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">Select all</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.select-none messages.selection-button\"\n\t\t\t\t\t\t\ttitle=\"Select none\"\n\t\t\t\t\t\t\tonclick={() => conversation.select.set([])}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"square\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">Select none</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div data-widget-part=\"messages.selection-finish\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.selection-cancel messages.selection-button\"\n\t\t\t\t\t\t\ttitle=\"Cancel\"\n\t\t\t\t\t\t\tonclick={() => conversation.select.stop()}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"x\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">Cancel</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<!-- A scene summary opens a scene, which is its own declared\n\t\t\t\t\t\t write (R-B): a genre that opens none does not offer it. -->\n\t\t\t\t\t\t{#if conversation.dossier?.writes.scenes}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.summarize-scene messages.selection-button\"\n\t\t\t\t\t\t\t\ttitle=\"Scene\"\n\t\t\t\t\t\t\t\tdisabled={selectedCount === 0}\n\t\t\t\t\t\t\t\tonclick={() => conversation.select.commit(\"scene\")}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"film\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">Scene</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.summarize-world messages.selection-button\"\n\t\t\t\t\t\t\ttitle=\"World lore\"\n\t\t\t\t\t\t\tdisabled={selectedCount === 0}\n\t\t\t\t\t\t\tonclick={() => conversation.select.commit(\"world\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"globe\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">World lore</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.summarize-character messages.selection-button\"\n\t\t\t\t\t\t\ttitle=\"Character lore\"\n\t\t\t\t\t\t\tdisabled={selectedCount === 0}\n\t\t\t\t\t\t\tonclick={() => conversation.select.commit(\"character\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"user\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">Character lore</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t{:else if settings.showComposer && conversation}\n\t\t{@const dossier = conversation.dossier}\n\t\t<div data-widget-part=\"messages.compose\">\n\t\t\t<!-- The page's status strips (who is typing, a stale preset). -->\n\t\t\t<sp-host-view name=\"session-banners\"></sp-host-view>\n\t\t\t{#if settings.nextUp !== \"hidden\" && dossier && !dossier.readOnly}\n\t\t\t\t<div data-widget-part=\"messages.next-up\">\n\t\t\t\t\t<NextCharacterBlock\n\t\t\t\t\t\torder={dossier.turn.order}\n\t\t\t\t\t\tcandidates={dossier.turn.candidates}\n\t\t\t\t\t\tmode={settings.nextUp}\n\t\t\t\t\t\tshouldShow={dossier.turn.show && conversation.edit.id === null}\n\t\t\t\t\t\tavatarFor={(ref) => (ref.startsWith(\"character:\") ? ref : undefined)}\n\t\t\t\t\t\tcanChooseSomeoneElse={dossier.turn.canChoose}\n\t\t\t\t\t\tviewerUserId={conversation.ctx.viewer.v1.userId}\n\t\t\t\t\t\tonContinue={(channel) => void conversation.request(\"fire-turn\", { channel })}\n\t\t\t\t\t\tonSomeoneElse={() => void conversation.request(\"pick-turn\", {})}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t{/if}\n\t\t\t<div data-widget-part=\"messages.compose-area\">\n\t\t\t\t{#if dossier?.readOnly}\n\t\t\t\t\t<!-- Read-only (19 §6, ruled): the mode disappeared, the history\n\t\t\t\t\t stays, nothing starts a new turn — and the server refuses\n\t\t\t\t\t independently at every generation choke, so this banner is\n\t\t\t\t\t honesty, not the lock. -->\n\t\t\t\t\t<div data-widget-part=\"messages.read-only\" role=\"status\">\n\t\t\t\t\t\t<sp-icon name=\"lock\" size=\"20\" data-widget-part=\"messages.read-only-icon\"></sp-icon>\n\t\t\t\t\t\t<div data-widget-part=\"messages.read-only-text\">\n\t\t\t\t\t\t\t<p data-widget-part=\"messages.read-only-title\">This session is read-only.</p>\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\tIts mode ({dossier.readOnly.genreId}) is not installed. Messages are safe to\n\t\t\t\t\t\t\t\tread; new turns resume when the mode returns.\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{:else}\n\t\t\t\t\t<SessionComposer composerSkin={settings.composerSkin} showActions={settings.showActions} />\n\t\t\t\t{/if}\n\t\t\t</div>\n\t\t</div>\n\t{/if}\n</div>\n","sessions/messages/NextCharacterBlock.svelte":"<script lang=\"ts\">\n\t/**\n\t * Who is due next (PLAN-turn-order §4.9), rendered from the session's\n\t * stored turn order — never derived on the client. It reads the entries\n\t * on **its own log's channel** (the composer's, `conversation.lane`;\n\t * lair re-plan R5): an entry with no `channel` is `main`'s. That\n\t * channel's first entry is its head, named from the order's candidates:\n\t *\n\t * - a character or envoy: \"<name> is ready to continue\", with Continue;\n\t * - `ref: null`, the pipeline's own voice: \"<own voice> is ready to\n\t * continue\", with Continue — the name the page resolved\n\t * (`turn.ownVoiceName`: the Lair's \"Castellan\", else the narrator's);\n\t * - a person (a persona): \"<name>'s turn\", or \"Your turn\" when the\n\t * persona is the viewer's own, and no Continue — a person's turn is\n\t * taken by writing.\n\t *\n\t * An empty order with people to choose from — a round that is over, or\n\t * a manual strategy waiting to be told — waits on a message and offers\n\t * the pick. An order whose entries are all on other channels shows\n\t * nothing here.\n\t *\n\t * Continue hands its channel to `onContinue`, so the page fires this\n\t * channel's entry. \"Someone else\" asks the page to open the turn picker.\n\t * With `mode: 'list'` the entries after the head follow as one quiet line.\n\t *\n\t * Its parts are `messages.next-up-*` (STYLE-GUIDE §6.16): the markup\n\t * carries no look; the default widget stylesheet draws it.\n\t */\n\timport type { NextUp } from \"./MessagesWidget.svelte\"\n\timport { useConversation } from \"./conversation.svelte\"\n\n\ttype Entry = { ref: string | null; channel?: unknown; [k: string]: unknown }\n\ttype Candidate = {\n\t\tref: string\n\t\tkind: string\n\t\tname: string\n\t\tnickname?: string\n\t\townerUserId?: number\n\t}\n\n\tinterface Props {\n\t\torder: Entry[]\n\t\tcandidates: Candidate[]\n\t\tmode: NextUp\n\t\tshouldShow: boolean\n\t\t/** A face for a ref, when the session has one loaded. */\n\t\tavatarFor?: (ref: string) => unknown\n\t\t/** Continue, with the channel of the log it was pressed under (R5). */\n\t\tonContinue: (channel: string) => void\n\t\tonSomeoneElse: () => void\n\t\t/** Whether anyone else could take the turn. */\n\t\tcanChooseSomeoneElse?: boolean\n\t\t/** The person looking: their own persona's turn reads \"Your turn\". */\n\t\tviewerUserId?: number | null\n\t}\n\n\tlet {\n\t\torder,\n\t\tcandidates,\n\t\tmode,\n\t\tshouldShow,\n\t\tavatarFor,\n\t\tonContinue,\n\t\tonSomeoneElse,\n\t\tcanChooseSomeoneElse = true,\n\t\tviewerUserId = null\n\t}: Props = $props()\n\n\tconst conversation = useConversation()\n\t/** This log's channel — the composer's — `main` by default. */\n\tconst channel = $derived(conversation.lane.current || \"main\")\n\tconst channelOf = (e: Entry) =>\n\t\ttypeof e.channel === \"string\" && e.channel ? e.channel : \"main\"\n\t/** The entries prepared on this channel, in the order's order. */\n\tconst here = $derived(order.filter((e) => channelOf(e) === channel))\n\tconst byRef = $derived(new Map(candidates.map((c) => [c.ref, c])))\n\tconst head = $derived(here[0])\n\tconst nameOf = (ref: string | null): string => {\n\t\tif (ref === null)\n\t\t\treturn conversation.dossier?.turn.ownVoiceName || \"The narrator\"\n\t\tconst c = byRef.get(ref)\n\t\treturn c?.nickname || c?.name || \"Someone\"\n\t}\n\tconst isPerson = (ref: string | null) =>\n\t\tref !== null && byRef.get(ref)?.kind === \"persona\"\n\tconst headName = $derived(head ? nameOf(head.ref) : \"\")\n\tconst headIsPerson = $derived(!!head && isPerson(head.ref))\n\tconst headIsMine = $derived(\n\t\theadIsPerson &&\n\t\t\tviewerUserId != null &&\n\t\t\tbyRef.get(head!.ref as string)?.ownerUserId === viewerUserId\n\t)\n\tconst line = $derived(\n\t\theadIsMine\n\t\t\t? \"Your turn\"\n\t\t\t: headIsPerson\n\t\t\t\t? `${headName}'s turn`\n\t\t\t\t: `${headName} is ready to continue`\n\t)\n\tconst face = $derived(head?.ref ? avatarFor?.(head.ref) : undefined)\n\tconst after = $derived(mode === \"list\" ? here.slice(1) : [])\n</script>\n\n{#if shouldShow && !order.length && candidates.length}\n\t<div data-widget-part=\"messages.next-up-waiting\">\n\t\t<span data-widget-part=\"messages.next-up-text\">\n\t\t\tWaiting for a message — or pick who speaks next\n\t\t</span>\n\t\t<button type=\"button\" data-widget-part=\"messages.next-up-pick\" onclick={onSomeoneElse}>\n\t\t\t<sp-icon name=\"users\" size=\"14\"></sp-icon>\n\t\t\t<span>Pick</span>\n\t\t</button>\n\t</div>\n{:else if shouldShow && head}\n\t<!-- One line: who is up, and what you can do about it. -->\n\t<div data-widget-part=\"messages.next-up-head\">\n\t\t<div data-widget-part=\"messages.next-up-line\">\n\t\t\t{#if face}\n\t\t\t\t<sp-avatar ref={head.ref} size=\"sm\"></sp-avatar>\n\t\t\t{:else if head.ref === null}\n\t\t\t\t<sp-icon name=\"book-open-text\" size=\"18\" data-widget-part=\"messages.next-up-narrator\"></sp-icon>\n\t\t\t{/if}\n\t\t\t<span data-widget-part=\"messages.next-up-text\">\n\t\t\t\t{line}\n\t\t\t</span>\n\t\t\t<div data-widget-part=\"messages.next-up-controls\">\n\t\t\t\t{#if canChooseSomeoneElse}\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tdata-widget-part=\"messages.next-up-pick\"\n\t\t\t\t\t\tonclick={onSomeoneElse}\n\t\t\t\t\t\ttitle=\"Someone else\"\n\t\t\t\t\t\taria-label=\"Pick someone else to continue\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-icon name=\"users\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t<span data-widget-part=\"messages.next-up-pick-label\">Someone else</span>\n\t\t\t\t\t</button>\n\t\t\t\t{/if}\n\t\t\t\t{#if !headIsPerson}\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tdata-widget-part=\"messages.next-up-continue\"\n\t\t\t\t\t\tonclick={() => onContinue(channel)}\n\t\t\t\t\t\ttitle=\"Continue\"\n\t\t\t\t\t\taria-label=\"Continue with {headName}\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-icon name=\"play\"></sp-icon>\n\t\t\t\t\t\t<span>Continue</span>\n\t\t\t\t\t</button>\n\t\t\t\t{/if}\n\t\t\t</div>\n\t\t</div>\n\t\t{#if after.length}\n\t\t\t<p data-widget-part=\"messages.next-up-after\">\n\t\t\t\tThen {after.map((e) => nameOf(e.ref)).join(\", \")}\n\t\t\t</p>\n\t\t{/if}\n\t</div>\n{/if}\n","sessions/messages/SessionComposer.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's composer (C0b): the field you write into, the persona you write\n\t * as, the lane, the session's action chips and its More panel. It reads\n\t * the conversation (`useConversation`) and the dossier's composer part;\n\t * sending, the draft and a persona switch are requests core's own widget\n\t * may make, a press of an action is `invoke`, and the page's own parts —\n\t * the chips, the turn controls, the panels, the run card, the retrieval\n\t * notice — are host views it places (`sp-host-view`).\n\t */\n\timport {\n\t\texactPaletteMatch,\n\t\texactSlashCommand,\n\t\tfilterPaletteActions,\n\t\tpaletteRowState,\n\t\tslashArgumentHint,\n\t\tslashArgumentRefusal,\n\t\tslashQueryOf,\n\t\tstepHighlight,\n\t\ttype PaletteAction\n\t} from \"@serene-pub/core-catalog/conversation\"\n\timport { actionIdentity } from \"@serene-pub/sdk/component\"\n\timport type { ItemValues } from \"@serene-pub/core-catalog/conversation\"\n\timport {\n\t\tATTACHMENT_KINDS_V1,\n\t\tKIND_FORMATS,\n\t\tKIND_NAME,\n\t\tpreCheckFiles,\n\t\treaderCallLines,\n\t\treadersSummary,\n\t\tsendableTrayIds,\n\t\tsniffAttachmentKind,\n\t\tuploadingNote,\n\t\ttype TrayItemV1,\n\t\ttype TrayRefusalV1\n\t} from \"@serene-pub/core-catalog/conversation\"\n\timport { i18nText } from \"@serene-pub/sdk/component\"\n\timport { untrack } from \"svelte\"\n\timport { useConversation } from \"./conversation.svelte\"\n\timport type { WidgetAction } from \"@serene-pub/sdk/component\"\n\n\t/** The More panel's tab that is not a pane: the turn controls, in the actions row. */\n\tconst TURN_CONTROLS_VIEW = \"session-controls\"\n\n\tinterface Props {\n\t\t/** How the composer is drawn (a widget setting). */\n\t\tcomposerSkin?: \"classic\" | \"minimal\" | \"writer\" | \"quill\"\n\t\t/** Hides the Actions label and its row outright. */\n\t\tshowActions?: boolean\n\t}\n\n\tlet { composerSkin = \"classic\", showActions = true }: Props = $props()\n\n\tconst conv = useConversation()\n\tconst c = $derived(conv.dossier?.composer)\n\tconst hideCompose = $derived(!!c?.hidden)\n\tconst channels = $derived(c?.channels ?? [])\n\tconst overflowActions = $derived((c?.overflow ?? []) as WidgetAction[])\n\tconst paletteActions = $derived((c?.palette ?? []) as PaletteAction[])\n\tconst newestItem = $derived((c?.newest ?? null) as ItemValues | null)\n\tconst sendTonal = $derived(!!c?.sendTonal)\n\tconst actionsListed = $derived(!!c?.actions)\n\n\t/**\n\t * The draft: the composer's own between the host's writes. A write — the\n\t * kept draft when the session opens, an empty one when an action spent\n\t * it — replaces the field, whatever it holds; the same write, re-posted\n\t * with the rest of the dossier, never does.\n\t */\n\tlet draft = $state(\"\")\n\tlet written: number | null = null\n\tlet writtenFor: number | null = null\n\t$effect(() => {\n\t\tconst write = c?.draft ?? null\n\t\tconst session = conv.dossier?.sessionId ?? null\n\t\t// Another session: its own draft, never the last one's.\n\t\tif (session === writtenFor && (write?.write ?? null) === written) return\n\t\twrittenFor = session\n\t\twritten = write?.write ?? null\n\t\tsetField(write?.content ?? \"\")\n\t})\n\t// The host keeps the draft (and counts its tokens): told as it changes.\n\t$effect(() => {\n\t\tconst content = draft\n\t\tconst t = setTimeout(() => void conv.request(\"draft\", { content }), 150)\n\t\treturn () => clearTimeout(t)\n\t})\n\n\t/**\n\t * What the field is told to show. The field is the host's between writes\n\t * (the caret stays on the page), so a write is a reset — and every reset\n\t * must arrive, the same text included: the attachment removes the\n\t * attribute first, since both Svelte and the renderer skip a write of the\n\t * value they last wrote.\n\t */\n\tlet fieldValue = $state(\"\")\n\tlet fieldWrites = $state(0)\n\tfunction setField(text: string) {\n\t\tdraft = text\n\t\tfieldValue = text\n\t\tfieldWrites++\n\t}\n\tconst writeField = (el: HTMLElement) => {\n\t\tvoid fieldWrites\n\t\tconst v = fieldValue\n\t\tel.removeAttribute(\"value\")\n\t\tel.setAttribute(\"value\", v)\n\t}\n\n\tfunction send() {\n\t\tconst content = draft\n\t\tconst trayItemIds = sendableTrayIds(tray)\n\t\t// Attachments alone are a line (composer attachments §3.1).\n\t\tif (!content.trim() && !trayItemIds.length && !uploading) return\n\t\t// A whole slash name — with or without its argument — is a command,\n\t\t// never a line: Send runs it as Enter does (S2), which is how a phone,\n\t\t// whose Enter writes a new line, runs `/nudge go north`.\n\t\tconst command = content.trim() ? exactSlashCommand(paletteActions, content) : undefined\n\t\tif (command) {\n\t\t\tinvokePalette(command.action, command.argument)\n\t\t\treturn\n\t\t}\n\t\t// Send waits only for the files still uploading (\"Uploading 1 of\n\t\t// 2…\"), then goes on its own.\n\t\tif (uploading) {\n\t\t\tsendWaiting = true\n\t\t\treturn\n\t\t}\n\t\tsendWaiting = false\n\t\t// Cleared once the host took it: a refused line (no persona, an\n\t\t// attachment the reply stopped reading) stays put, tiles and all.\n\t\t// The tiles leave when the host's tray says they were sent.\n\t\tconv.ctx\n\t\t\t.request(\"send\", {\n\t\t\t\tcontent,\n\t\t\t\tpersonaId: c?.personaId ?? null,\n\t\t\t\tchannel: conv.lane.current,\n\t\t\t\t...(trayItemIds.length ? { trayItemIds } : {})\n\t\t\t})\n\t\t\t.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (draft === content) setField(\"\")\n\t\t\t\t},\n\t\t\t\t(e: Error) => console.warn(`Send: ${e.message}`)\n\t\t\t)\n\t\tpaletteDismissed = null\n\t\tpaletteHighlight = -1\n\t}\n\n\t/* ── attachments (composer attachments §3.3) ──────────────────────────\n\t * The tray is the host's (`composer.tray`): this composer asks it to\n\t * take files (`attach-files`) and to drop one (`remove-tray-item`), and\n\t * draws what it says. A file the readers would refuse — or an SVG, an\n\t * oversized file, one past the count — is refused here first, before a\n\t * byte goes up, as a tile that says why and clears itself; the server\n\t * checks every file again. What the reply can read is not drawn in the\n\t * composer's body: the More (⋮) panel's **What can be attached** opens\n\t * it in a dialog (next-pass note 41, 2026-10-03). */\n\tconst tray = $derived((c?.tray ?? []) as TrayItemV1[])\n\tconst readers = $derived(c?.attachments ?? null)\n\tconst offersAttachments = $derived(c?.tray !== undefined && !hideCompose)\n\tconst readersLine = $derived(readersSummary(readers))\n\tconst readerLines = $derived(readerCallLines(readers))\n\t/** The More panel offers **What can be attached**: there is something to say. */\n\tconst readersOffered = $derived(offersAttachments && !!readersLine)\n\tconst uploading = $derived(uploadingNote(tray))\n\tconst hasAttachments = $derived(tray.some((t) => t.status !== \"refused\"))\n\t/** The **What can be attached** dialog is open. */\n\tlet readersOpen = $state(false)\n\t/** Pressed Send while files were uploading: it goes when they finish. */\n\tlet sendWaiting = $state(false)\n\t$effect(() => {\n\t\tif (sendWaiting && !uploading) untrack(() => send())\n\t})\n\t/** Files refused before upload, drawn as tiles until they clear (§2b). */\n\tlet refusedHere = $state<Array<TrayRefusalV1 & { key: number }>>([])\n\tlet refusalSeq = 0\n\t/** What the live region last said (\"cat.png attached\", a refusal). */\n\tlet announcement = $state(\"\")\n\n\tasync function attachFiles(files: File[]) {\n\t\tif (!files.length) return\n\t\tconst sniffed = await Promise.all(\n\t\t\tfiles.map(async (f) => ({\n\t\t\t\tname: f.name,\n\t\t\t\tsize: f.size,\n\t\t\t\tkind: sniffAttachmentKind(\n\t\t\t\t\tnew Uint8Array(await f.slice(0, 512).arrayBuffer()),\n\t\t\t\t\tf.name,\n\t\t\t\t\tf.type\n\t\t\t\t)\n\t\t\t}))\n\t\t)\n\t\tconst { accept, refusals } = preCheckFiles(sniffed, tray, readers)\n\t\tfor (const r of refusals) {\n\t\t\tconst key = ++refusalSeq\n\t\t\trefusedHere = [...refusedHere, { ...r, key }]\n\t\t\tsetTimeout(() => (refusedHere = refusedHere.filter((x) => x.key !== key)), 6000)\n\t\t}\n\t\tif (refusals.length)\n\t\t\tannouncement = refusals.map((r) => `Can't attach ${r.filename}: ${r.reason}`).join(\" \")\n\t\tif (accept.length)\n\t\t\tconv.ctx\n\t\t\t\t.request(\"attach-files\", { files: accept.map((i) => files[i]!) })\n\t\t\t\t.catch((e: Error) => (announcement = e.message))\n\t}\n\n\tfunction removeTrayItem(item: TrayItemV1) {\n\t\tvoid conv.ctx.request(\"remove-tray-item\", { trayItemId: item.id }).catch(() => {})\n\t\tannouncement = `${item.filename} removed`\n\t}\n\n\t// \"cat.png attached\" — once, as a tile turns ready; a server refusal too.\n\tconst heard = new Map<string, string>()\n\t$effect(() => {\n\t\tfor (const t of tray) {\n\t\t\tconst was = heard.get(t.id)\n\t\t\tif (was === t.status) continue\n\t\t\theard.set(t.id, t.status)\n\t\t\tif (was === undefined && t.status === \"uploading\") continue\n\t\t\tif (t.status === \"ready\") untrack(() => (announcement = `${t.filename} attached`))\n\t\t\tif (t.status === \"refused\")\n\t\t\t\tuntrack(() => (announcement = `Can't attach ${t.filename}: ${t.refusal ?? \"\"}`))\n\t\t}\n\t})\n\n\t/** \"Open the picker\" filter — the kinds this reply reads, by mime and extension. */\n\tconst pickerAccept = $derived(readers?.accept ?? \"\")\n\tconst progressOf = (t: TrayItemV1) => Math.round(Math.min(Math.max(t.progress, 0), 1) * 100)\n\n\t/**\n\t * What a channel is CALLED: its declared label (`ChannelDecl.label`, the\n\t * Lair's _Sanctum_), else its slug title-cased — the conversation's one\n\t * reading (S1), so the strip and a pinned copy's head never disagree.\n\t */\n\tconst channelLabel = (slug: string) => conv.channelName(slug)\n\n\t// Unique per instance: a session page can hold more than one composer on\n\t// screen at a time, and a shared id sends every `for`/`aria-describedby` to\n\t// whichever element happens to come first in the DOM.\n\tconst uid = $props.id()\n\tconst inputId = `composer-input-${uid}`\n\tconst warningId = `composer-warning-${uid}`\n\tconst actionsId = `composer-actions-${uid}`\n\tconst paletteId = `composer-palette-${uid}`\n\tconst paletteOptionId = (i: number) => `${paletteId}-option-${i}`\n\n\tlet personaSwitcherOpen = $state(false)\n\tlet moreMenuOpen = $state(false)\n\tlet actionsOpen = $state(false)\n\tlet previewOpen = $state(false)\n\t/** The More panel currently filling the field area, or null for the field. */\n\tlet activePaneValue: string | null = $state(null)\n\n\t// Enter submits at desktop widths only; on a touch keyboard it inserts a\n\t// newline like any other textarea.\n\t// Enter sends where there is a keyboard to press it on; a narrow box (a\n\t// phone's) keeps Enter for a new line, as a touch keyboard does.\n\tconst submitOnEnter = $derived(conv.ctx.layout?.v1?.tier !== \"compact\")\n\t/** The Enter/Shift+Enter hint: shown once, remembered in the widget's saved state. */\n\tlet hintSeen = $state(true)\n\t// ⏳ A native widget has no saved state yet: the hint is remembered per\n\t// mount until it does (a remote's `state` carries it).\n\tconst saved = $derived(\n\t\t(conv.ctx as unknown as { state?: { hintSeen?: boolean } }).state\n\t)\n\t$effect(() => {\n\t\thintSeen = !!saved?.hintSeen\n\t})\n\tlet hintVisible = $state(false)\n\n\tconst activePersona = $derived(\n\t\tc?.personas.find((p) => p.personaId === c?.personaId) ?? null\n\t)\n\tconst personaCount = $derived(c?.personas.length ?? 0)\n\n\tconst tabs = $derived(c?.tabs ?? [])\n\tlet turnControls = $derived(tabs.find((t) => t.view === TURN_CONTROLS_VIEW))\n\tlet morePanes = $derived(tabs.filter((t) => t.view !== TURN_CONTROLS_VIEW))\n\tlet activePane = $derived(morePanes.find((t) => t.view === activePaneValue))\n\tlet hasActionsRow = $derived(actionsListed || !!turnControls || overflowActions.length > 0)\n\tlet overflowNew = $derived(overflowActions.filter((a) => a.isNew))\n\tlet overflowOpen = $state(false)\n\t/**\n\t * The verdict the overflow reads off a listed action (U5e): the same\n\t * `paletteRowState` the chips and the palette read, so the three cannot\n\t * disagree. The reason arrives as a locale map and is resolved here.\n\t */\n\tconst overflowRow = (a: WidgetAction) => ({\n\t\tname: a.name,\n\t\taudience: a.audience,\n\t\tcanAct: a.canAct,\n\t\tenabled: a.enabled,\n\t\tvenue: a.venue,\n\t\t...(a.reason ? { reason: i18nText(a.reason.i18n, conv.ctx.locale.v1) ?? a.reason.i18n.en } : {}),\n\t\t...(a.itemPredicates?.length ? { itemPredicates: a.itemPredicates } : {})\n\t})\n\n\t/* ── the `/` palette (R-15 slash names, F38; U5c) ──────────────────────\n\t * Typing `/` at the start of an empty draft lists the composer's actions;\n\t * the rest of the draft filters them. Escape closes it until the draft\n\t * changes; Enter invokes the highlighted row, or the exact match when\n\t * the palette is closed. The textarea stays the input — the list is a\n\t * listbox it controls (`aria-controls`, `aria-activedescendant`). */\n\t/** The query Escape was pressed on; the palette stays closed while the draft still says it. */\n\tlet paletteDismissed = $state<string | null>(null)\n\tlet paletteHighlight = $state(-1)\n\tconst paletteQuery = $derived(slashQueryOf(draft))\n\tconst paletteRows = $derived(\n\t\tpaletteQuery === null || !paletteActions.length\n\t\t\t? []\n\t\t\t: filterPaletteActions(paletteActions, paletteQuery)\n\t)\n\tconst paletteOpen = $derived(\n\t\tpaletteDismissed !== paletteQuery &&\n\t\t\tpaletteRows.length > 0 &&\n\t\t\t!hideCompose\n\t)\n\t// The highlight never points past the rows it has.\n\t$effect(() => {\n\t\tif (paletteHighlight >= paletteRows.length)\n\t\t\tpaletteHighlight = paletteRows.length ? 0 : -1\n\t})\n\t/**\n\t * What Enter runs while the palette is open: the highlighted row, else\n\t * the name typed in full, else — once the draft has narrowed the list —\n\t * its first row. A bare `/` and Enter highlights rather than fires:\n\t * nothing was named. ONE derivation, read by the key handler and by the\n\t * footer hint, so the hint cannot promise a row Enter would not run.\n\t */\n\tconst paletteEnterPick = $derived(\n\t\t!paletteOpen\n\t\t\t? undefined\n\t\t\t: paletteHighlight >= 0\n\t\t\t\t? paletteRows[paletteHighlight]\n\t\t\t\t: (exactPaletteMatch(paletteActions, draft) ??\n\t\t\t\t\t(paletteQuery ? paletteRows[0] : undefined))\n\t)\n\t// Opening the palette is meeting its newcomers.\n\t$effect(() => {\n\t\tif (!paletteOpen) return\n\t\tconst fresh = paletteRows.filter((a) => a.isNew)\n\t\tif (fresh.length) void conv.request(\"actions-seen\", { keys: fresh.map(actionIdentity) })\n\t})\n\n\t/**\n\t * Run one action. With a **slash argument** (S2) the press supplies its\n\t * text, and the draft stays until the host's run spends it (D1) — kept\n\t * on an error, or on the host's refusal of text to an action that\n\t * collects none (`/advance x`), so nothing typed is lost. Without one the\n\t * draft was only the name, and goes now.\n\t */\n\tfunction invokePalette(action: PaletteAction, argument: string | null = null) {\n\t\t// The same gate the chips and the More menu apply (S5): the\n\t\t// audience, and nothing while a reply streams.\n\t\tif (paletteRowState(action, { generating: isGenerating, newest: newestItem }).disabled)\n\t\t\treturn\n\t\tif (argument === null) setField(\"\")\n\t\tpaletteDismissed = null\n\t\tpaletteHighlight = -1\n\t\tconv.invoke(actionIdentity(action), undefined, undefined, argument ?? undefined)\n\t}\n\t/**\n\t * The draft as a whole slash name and its argument (S2), when it has one:\n\t * what Enter runs (the palette is closed once a space is typed) and what\n\t * the footer says it will do.\n\t */\n\tconst slashCommand = $derived.by(() => {\n\t\tconst command = exactSlashCommand(paletteActions, draft)\n\t\treturn command?.argument ? command : undefined\n\t})\n\tconst slashRefusal = $derived(\n\t\tslashCommand ? slashArgumentRefusal(slashCommand.action, slashCommand.argument) : null\n\t)\n\n\t/**\n\t * The keys the palette handles, which the field keeps from itself and\n\t * raises as `key`: all four while it is open, Enter alone while the draft\n\t * names an action exactly.\n\t */\n\tconst capturedKeys = $derived(\n\t\tpaletteOpen\n\t\t\t? \"ArrowUp ArrowDown Escape Enter Tab\"\n\t\t\t: exactPaletteMatch(paletteActions, draft) || (slashCommand && submitOnEnter)\n\t\t\t\t? \"Enter\"\n\t\t\t\t: \"\"\n\t)\n\n\t/** True when the key was the palette's to handle. */\n\tfunction handlePaletteKey(e: { key: string; shiftKey: boolean; preventDefault: () => void }): boolean {\n\t\tif (paletteOpen) {\n\t\t\tif (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n\t\t\t\te.preventDefault()\n\t\t\t\tpaletteHighlight = stepHighlight(\n\t\t\t\t\tpaletteHighlight,\n\t\t\t\t\tpaletteRows.length,\n\t\t\t\t\te.key === \"ArrowDown\" ? 1 : -1\n\t\t\t\t)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (e.key === \"Escape\") {\n\t\t\t\te.preventDefault()\n\t\t\t\tpaletteDismissed = paletteQuery\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (e.key === \"Enter\" && !e.shiftKey) {\n\t\t\t\te.preventDefault()\n\t\t\t\tconst pick = paletteEnterPick\n\t\t\t\tif (pick) invokePalette(pick)\n\t\t\t\telse paletteHighlight = 0\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (e.key === \"Tab\" && paletteRows.length) {\n\t\t\t\t// Complete to the highlighted (or first) name, like a shell.\n\t\t\t\te.preventDefault()\n\t\t\t\tconst pick =\n\t\t\t\t\tpaletteRows[paletteHighlight >= 0 ? paletteHighlight : 0]!\n\t\t\t\t// One that takes an argument (S2) completes with its space, ready for it.\n\t\t\t\tsetField(`/${pick.slash}${slashArgumentHint(pick) ? \" \" : \"\"}`)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t\t// Closed: `/name` + Enter still invokes an exact match, so a name\n\t\t// typed in full never needs the list.\n\t\tif (e.key === \"Enter\" && !e.shiftKey) {\n\t\t\tconst exact = exactPaletteMatch(paletteActions, draft)\n\t\t\tif (exact) {\n\t\t\t\te.preventDefault()\n\t\t\t\tinvokePalette(exact)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\t// `/nudge go north` + Enter runs Nudge with its argument (S2) —\n\t\t\t// where Enter sends; a phone's Enter keeps writing the argument's\n\t\t\t// next line, and its Send runs the command.\n\t\t\tif (slashCommand && submitOnEnter) {\n\t\t\t\te.preventDefault()\n\t\t\t\tinvokePalette(slashCommand.action, slashCommand.argument)\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tfunction handleOverflowOpen(open: boolean) {\n\t\toverflowOpen = open\n\t\tif (open && overflowNew.length)\n\t\t\tvoid conv.request(\"actions-seen\", { keys: overflowNew.map(actionIdentity) })\n\t}\n\tlet actionsLabelShown = $derived(showActions && hasActionsRow)\n\n\tlet tokenCounts = $derived(c?.usage ?? null)\n\tlet usageRatio = $derived(\n\t\ttokenCounts && tokenCounts.limit > 0\n\t\t\t? Math.min(tokenCounts.total / tokenCounts.limit, 1)\n\t\t\t: null\n\t)\n\tlet contextExceeded = $derived(\n\t\ttokenCounts ? tokenCounts.total > tokenCounts.limit : false\n\t)\n\n\tconst messages = $derived(conv.ctx.messages.v1 as Array<{ isGenerating?: boolean }>)\n\tlet isGenerating = $derived(!!messages[messages.length - 1]?.isGenerating)\n\tlet ragVisible = $derived(!!c?.notice && composerSkin !== \"minimal\")\n\t// Writing as no persona in a genre that names the person's lines (R4's\n\t// `playerLabel`, S2): \"Write as the Dungeon Master…\".\n\tlet placeholder = $derived(\n\t\tactivePersona\n\t\t\t? `Write as ${activePersona.name}…`\n\t\t\t: c?.playerLabel\n\t\t\t\t? `Write as the ${c.playerLabel}…`\n\t\t\t\t: \"Write a message…\"\n\t)\n\n\t// A pane that has gone (a lorebook unbound, context debugging switched off)\n\t// hands the field area back. A mode with no field opens on its first panel,\n\t// because there is nothing else for the area to show.\n\t$effect(() => {\n\t\tconst values = morePanes.map((p) => p.view)\n\t\tif (activePaneValue && !values.includes(activePaneValue)) {\n\t\t\tactivePaneValue = null\n\t\t}\n\t\tif (hideCompose && !activePaneValue && values.length) {\n\t\t\tactivePaneValue = values[0]\n\t\t}\n\t})\n\n\t/** The field raised a key the palette keeps (`keys`). */\n\tfunction handleFieldKey(e: CustomEvent<{ key: string; shift: boolean }>) {\n\t\tconst ev = { key: e.detail.key, shiftKey: e.detail.shift, preventDefault() {} }\n\t\tif (handlePaletteKey(ev)) return\n\t\t// Enter reached here only as a captured key: the send key, then.\n\t\tif (ev.key === \"Enter\" && !ev.shiftKey && submitOnEnter) send()\n\t}\n\n\tfunction handleFieldFocus() {\n\t\tif (hintSeen || !submitOnEnter) return\n\t\thintVisible = true\n\t\thintSeen = true\n\t\t;(conv.ctx as unknown as { saveState?: (s: object) => void }).saveState?.({ ...(saved ?? {}), hintSeen: true })\n\t}\n\n\tfunction openPane(value: string) {\n\t\tactivePaneValue = value\n\t\tpreviewOpen = false\n\t\tmoreMenuOpen = false\n\t}\n\n\t/** More › What can be attached: the panel closes, the dialog opens. */\n\tfunction openReaders() {\n\t\tmoreMenuOpen = false\n\t\treadersOpen = true\n\t}\n\n\tfunction backToCompose() {\n\t\tactivePaneValue = null\n\t}\n\n\tfunction togglePreview() {\n\t\tpreviewOpen = !previewOpen\n\t\tif (previewOpen) activePaneValue = null\n\t}\n\n\t// The row is a disclosure, not a menu: it closes on its toggle and on\n\t// Escape, never because focus left it — `src/ui/sessions/conversation/actionsDisclosure.ts` has the\n\t// table and the reason. There is deliberately no `onfocusout` here.\n\t/** Escape closes the actions row (natively; a remote hears no keys). */\n\tfunction handleKeyDown(e: KeyboardEvent) {\n\t\tif (e.key === \"Escape\" && actionsOpen && !overflowOpen) actionsOpen = false\n\t}\n</script>\n\n\n<!-- The composer's parts are `messages.composer-*` (STYLE-GUIDE §6.16): no look\n here; the default widget stylesheet draws them, and the skin\n (`data-composer-skin`) is a state a style reads. -->\n<!-- Escape closes the actions row: a keyboard shortcut over the whole group,\n not an interaction of its own (natively; a remote hears no keys). -->\n<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->\n<div\n\tdata-widget-part=\"messages.composer\"\n\tdata-composer-skin={composerSkin}\n\thidden={conv.edit.id !== null}\n\tonkeydown={handleKeyDown}\n\trole=\"group\"\n\taria-label=\"Compose\"\n>\n\t{#if c?.addPersona}\n\t\t<!-- Guests without a persona get the one thing they can do here. -->\n\t\t<div data-widget-part=\"messages.join\">\n\t\t\t<div data-widget-part=\"messages.join-text\">\n\t\t\t\t<sp-icon name=\"user-plus\" size=\"48\" data-widget-part=\"messages.join-icon\"></sp-icon>\n\t\t\t\t<h3 data-widget-part=\"messages.join-title\">Join the conversation</h3>\n\t\t\t\t<p data-widget-part=\"messages.join-note\">\n\t\t\t\t\tAdd a persona to this session to send messages.\n\t\t\t\t</p>\n\t\t\t</div>\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.join-button\"\n\t\t\t\tonclick={() => void conv.request(\"add-persona\", {})}\n\t\t\t>\n\t\t\t\t<sp-icon name=\"user-plus\" size=\"20\"></sp-icon>\n\t\t\t\tAdd your persona\n\t\t\t</button>\n\t\t</div>\n\t{:else}\n\t\t<!-- Above the composer, because a run in flight is about the message you\n\t\t are about to get rather than the ones already there — and because it\n\t\t has to stay visible while the transcript scrolls. -->\n\t\t<sp-host-view name=\"run-progress\"></sp-host-view>\n\n\t\t<div data-widget-part=\"messages.composer-disclosure\">\n\t\t\t<div data-widget-part=\"messages.composer-disclosure-bar\">\n\t\t\t\t{#if actionsLabelShown}\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tdata-widget-part=\"messages.composer-actions-toggle\"\n\t\t\t\t\t\taria-expanded={actionsOpen}\n\t\t\t\t\t\taria-controls={actionsId}\n\t\t\t\t\t\tonclick={() => (actionsOpen = !actionsOpen)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<span>Actions</span>\n\t\t\t\t\t\t<sp-icon name=\"chevron-down\" size=\"12\" data-widget-part=\"messages.composer-actions-chevron\"></sp-icon>\n\t\t\t\t\t</button>\n\t\t\t\t{/if}\n\t\t\t\t{#if ragVisible}\n\t\t\t\t\t<div data-widget-part=\"messages.composer-notice\">\n\t\t\t\t\t\t<sp-host-view name=\"retrieval-notice\"></sp-host-view>\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t</div>\n\n\t\t\t{#if actionsLabelShown && actionsOpen}\n\t\t\t\t<div\n\t\t\t\t\tid={actionsId}\n\t\t\t\t\tdata-widget-part=\"messages.composer-actions-row\"\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label=\"Session actions\"\n\t\t\t\t>\n\t\t\t\t\t<!-- ONE group, ONE chip (next-pass note 30, 2026-10-02): the turn\n\t\t\t\t\t controls first — Continue, Pick who speaks, Regenerate — then\n\t\t\t\t\t the genre's actions, then More. The page's two host views\n\t\t\t\t\t draw their chips straight into this row (the row lays out\n\t\t\t\t\t `sp-host-view`'s children as its own), so they wrap, space\n\t\t\t\t\t and look as one set. -->\n\t\t\t\t\t<div data-widget-part=\"messages.composer-actions messages.composer-chips\">\n\t\t\t\t\t\t{#if turnControls}\n\t\t\t\t\t\t\t<!-- This composer's channel's turn controls (S1): a copy pinned to the\n\t\t\t\t\t\t\t Sanctum draws the Sanctum's listing. -->\n\t\t\t\t\t\t\t<sp-host-view name=\"session-controls\" channel={conv.lane.current}></sp-host-view>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if actionsListed}\n\t\t\t\t\t\t\t<sp-host-view name=\"session-actions\" channel={conv.lane.current}></sp-host-view>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if overflowActions.length}\n\t\t\t\t\t\t\t<!-- The overflow (R-15, F38): every enabled action\n\t\t\t\t\t\t\t the primary row leaves out, never hidden by\n\t\t\t\t\t\t\t prominence. A Menu — these are actions, not a\n\t\t\t\t\t\t\t field. A newcomer marks the trigger until the\n\t\t\t\t\t\t\t menu has been opened once. -->\n\t\t\t\t\t\t\t<!-- `sp-menu` (§3.5): each `sp-menu-item`'s own content is its row. -->\n\t\t\t\t\t\t\t<sp-menu\n\t\t\t\t\t\t\t\tplacement=\"top-start\"\n\t\t\t\t\t\t\t\tlabel=\"More actions\"\n\t\t\t\t\t\t\t\topen={overflowOpen}\n\t\t\t\t\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) =>\n\t\t\t\t\t\t\t\t\thandleOverflowOpen(e.detail.open)}\n\t\t\t\t\t\t\t\tonselect={(e: CustomEvent<{ value: string }>) => {\n\t\t\t\t\t\t\t\t\tconst a = overflowActions.find(\n\t\t\t\t\t\t\t\t\t\t(x) => actionIdentity(x) === e.detail.value\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t// The wire's reason is a locale map; the palette's\n\t\t\t\t\t\t\t\t\t// shape carries a sentence, and the fire needs neither.\n\t\t\t\t\t\t\t\t\tif (a) conv.invoke(actionIdentity(a))\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\tslot=\"trigger\"\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-more-actions\"\n\t\t\t\t\t\t\t\t\ttitle=\"More actions\"\n\t\t\t\t\t\t\t\t\taria-label={overflowNew.length\n\t\t\t\t\t\t\t\t\t\t? `More actions (${overflowNew.length} new)`\n\t\t\t\t\t\t\t\t\t\t: \"More actions\"}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"ellipsis\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\t\tMore\n\t\t\t\t\t\t\t\t\t{#if overflowNew.length}\n\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-new-dot\" aria-hidden=\"true\"></span>\n\t\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{#each overflowActions as a (actionIdentity(a))}\n\t\t\t\t\t\t\t\t\t{@const iconName = a.icon || \"play\"}\n\t\t\t\t\t\t\t\t\t{@const row = paletteRowState(overflowRow(a), {\n\t\t\t\t\t\t\t\t\t\tgenerating: isGenerating,\n\t\t\t\t\t\t\t\t\t\tnewest: newestItem\n\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t<!-- Grey, listed, with its reason (R-15, U5e): the\n\t\t\t\t\t\t\t\t\t audience's word, the declared enabled-when's, or\n\t\t\t\t\t\t\t\t\t the busy rule — as a second line and to a screen\n\t\t\t\t\t\t\t\t\t reader, never dropped from the list. -->\n\t\t\t\t\t\t\t\t\t<sp-menu-item\n\t\t\t\t\t\t\t\t\t\tvalue={actionIdentity(a)}\n\t\t\t\t\t\t\t\t\t\tdisabled={row.disabled}\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-overflow-item\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name={iconName} size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t<span title={a.description}>\n\t\t\t\t\t\t\t\t\t\t\t{a.name}\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-overflow-slash\">/{a.slash}</span>\n\t\t\t\t\t\t\t\t\t\t\t{#if row.reason}\n\t\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-overflow-note\">{row.reason}</span>\n\t\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t{#if a.isNew}\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-new\">New</span>\n\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t</sp-menu-item>\n\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t</sp-menu>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t{/if}\n\t\t</div>\n\n\t\t<!-- Files dropped onto the composer, or pasted into it (a screenshot),\n\t\t join the tray; a drag shows \"Drop to attach\" (STYLE-GUIDE §6.7).\n\t\t Off where the host offers no attachments, so a paste of text is\n\t\t the field's as ever. -->\n\t\t<sp-drop-zone\n\t\t\tdata-widget-part=\"messages.composer-drop\"\n\t\t\tlabel=\"Drop to attach\"\n\t\t\tdisabled={!offersAttachments}\n\t\t\tonfiles={(e: CustomEvent<{ files: File[] }>) => {\n\t\t\t\t// Its OWN files only. An sp element's event bubbles, and the\n\t\t\t\t// Attach picker sits inside this zone — without this, one pick\n\t\t\t\t// staged every file twice (found in the 2026-10-02 live check).\n\t\t\t\tif (e.target !== e.currentTarget) return\n\t\t\t\tvoid attachFiles(e.detail.files)\n\t\t\t}}\n\t\t>\n\t\t<div data-widget-part=\"messages.composer-card\">\n\t\t\t{#if usageRatio !== null}\n\t\t\t\t<!-- The draft's share of the context window, read along the card's\n\t\t\t\t top edge rather than as a number, so it costs no row. -->\n\t\t\t\t<div\n\t\t\t\t\tdata-widget-part=\"messages.composer-meter\"\n\t\t\t\t\trole=\"progressbar\"\n\t\t\t\t\taria-label=\"Context window used\"\n\t\t\t\t\taria-valuemin={0}\n\t\t\t\t\taria-valuemax={100}\n\t\t\t\t\taria-valuenow={Math.round(usageRatio * 100)}\n\t\t\t\t>\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.composer-meter-fill\"\n\t\t\t\t\t\tdata-high={usageRatio > 0.9 ? \"\" : undefined}\n\t\t\t\t\t\tstyle=\"--sp-fill: {(usageRatio * 100).toFixed(1)}%\"\n\t\t\t\t\t></div>\n\t\t\t\t</div>\n\t\t\t{/if}\n\n\t\t\t<div data-widget-part=\"messages.composer-body\">\n\t\t\t\t{#if activePane}\n\t\t\t\t\t<div data-widget-part=\"messages.composer-pane-head\">\n\t\t\t\t\t\t<span data-widget-part=\"messages.composer-pane-title\">\n\t\t\t\t\t\t\t{activePane.title}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t{#if !hideCompose}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-back\"\n\t\t\t\t\t\t\t\tonclick={backToCompose}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"arrow-left\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\tBack to compose\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</div>\n\t\t\t\t\t<div role=\"region\" aria-label=\"{activePane.title} panel\">\n\t\t\t\t\t\t<sp-host-view name={activePane.view}></sp-host-view>\n\t\t\t\t\t</div>\n\t\t\t\t{:else if previewOpen}\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.composer-preview\"\n\t\t\t\t\t\trole=\"region\"\n\t\t\t\t\t\taria-label=\"Message preview\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-message-body text={draft}></sp-message-body>\n\t\t\t\t\t</div>\n\t\t\t\t{:else if !hideCompose}\n\t\t\t\t\t{#if paletteOpen}\n\t\t\t\t\t\t<!-- The `/` palette: the composer's actions by slash\n\t\t\t\t\t\t name, filtered by the draft. A listbox the field\n\t\t\t\t\t\t controls; Enter invokes, Escape closes, Tab\n\t\t\t\t\t\t completes the name. -->\n\t\t\t\t\t\t<ul\n\t\t\t\t\t\t\tid={paletteId}\n\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-palette\"\n\t\t\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\t\t\taria-label=\"Slash commands\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{#each paletteRows as a, i (a.slash)}\n\t\t\t\t\t\t\t\t{@const iconName = a.icon || \"play\"}\n\t\t\t\t\t\t\t\t{@const rowState = paletteRowState(a, {\n\t\t\t\t\t\t\t\t\tgenerating: isGenerating,\n\t\t\t\t\t\t\t\t\tnewest: newestItem\n\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t{@const argHint = slashArgumentHint(a)}\n\t\t\t\t\t\t\t\t<!-- The highlighted row is its `aria-selected`, a row the\n\t\t\t\t\t\t\t\t audience or a reply in flight refuses its `aria-disabled`. -->\n\t\t\t\t\t\t\t\t<li\n\t\t\t\t\t\t\t\t\tid={paletteOptionId(i)}\n\t\t\t\t\t\t\t\t\trole=\"option\"\n\t\t\t\t\t\t\t\t\taria-selected={i === paletteHighlight}\n\t\t\t\t\t\t\t\t\taria-disabled={rowState.disabled}\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-palette-row\"\n\t\t\t\t\t\t\t\t>\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=\"messages.composer-palette-button\"\n\t\t\t\t\t\t\t\t\t\ttabindex=\"-1\"\n\t\t\t\t\t\t\t\t\t\tdisabled={rowState.disabled}\n\t\t\t\t\t\t\t\t\t\tonmousedown={(e) => e.preventDefault()}\n\t\t\t\t\t\t\t\t\t\tonmouseenter={() => (paletteHighlight = i)}\n\t\t\t\t\t\t\t\t\t\tonclick={() => invokePalette(a)}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name={iconName} size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-palette-slash\">/{a.slash}</span>\n\t\t\t\t\t\t\t\t\t\t{#if argHint}\n\t\t\t\t\t\t\t\t\t\t\t<!-- The argument it takes (S2): `/nudge <direction…>`. -->\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-palette-argument\">{argHint}</span>\n\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-palette-label\">{a.name}</span>\n\t\t\t\t\t\t\t\t\t\t{#if a.isNew}\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-new\">New</span>\n\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t{#if rowState.reason}\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-palette-note\">{rowState.reason}</span>\n\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t{/if}\n\t\t\t\t\t<!-- The field inside takes focus and carries the ARIA: this is its\n\t\t\t\t\t host element; the field itself is its child `textarea`. -->\n\t\t\t\t\t<!-- svelte-ignore a11y_aria_activedescendant_has_tabindex -->\n\t\t\t\t\t<sp-composer-field\n\t\t\t\t\t\tdata-widget-part=\"messages.composer-field\"\n\t\t\t\t\t\trows=\"1\"\n\t\t\t\t\t\tlabel=\"Write a message\"\n\t\t\t\t\t\t{placeholder}\n\t\t\t\t\t\tsubmit-on={submitOnEnter ? \"enter\" : \"none\"}\n\t\t\t\t\t\tkeys={capturedKeys}\n\t\t\t\t\t\tspellcheck=\"true\"\n\t\t\t\t\t\taria-describedby={contextExceeded ? warningId : undefined}\n\t\t\t\t\t\taria-invalid={contextExceeded ? \"true\" : undefined}\n\t\t\t\t\t\taria-autocomplete={paletteActions.length ? \"list\" : undefined}\n\t\t\t\t\t\taria-controls={paletteOpen ? paletteId : undefined}\n\t\t\t\t\t\taria-activedescendant={paletteOpen && paletteHighlight >= 0\n\t\t\t\t\t\t\t? paletteOptionId(paletteHighlight)\n\t\t\t\t\t\t\t: undefined}\n\t\t\t\t\t\toninput={(e: CustomEvent<{ value: string }>) => (draft = e.detail.value)}\n\t\t\t\t\t\tonsubmit={(e: CustomEvent<{ value: string }>) => {\n\t\t\t\t\t\t\tdraft = e.detail.value\n\t\t\t\t\t\t\tsend()\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonkey={handleFieldKey}\n\t\t\t\t\t\tonfocus={handleFieldFocus}\n\t\t\t\t\t\t{@attach writeField}\n\t\t\t\t\t></sp-composer-field>\n\t\t\t\t{/if}\n\t\t\t</div>\n\n\t\t\t{#if offersAttachments && (tray.length || refusedHere.length)}\n\t\t\t\t<!-- The tray: this line's attachments, uploading, ready or\n\t\t\t\t refused. A row of tiles that scrolls sideways on a phone. -->\n\t\t\t\t<ul data-widget-part=\"messages.composer-tray\" aria-label=\"Attachments\">\n\t\t\t\t\t{#each tray as t (t.id)}\n\t\t\t\t\t\t<li\n\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-tray-item\"\n\t\t\t\t\t\t\tdata-status={t.status}\n\t\t\t\t\t\t\tdata-kind={t.kind ?? undefined}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{#if t.thumbSrc}\n\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-tray-thumb\"\n\t\t\t\t\t\t\t\t\tsrc={t.thumbSrc}\n\t\t\t\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\t\t\t\tloading=\"lazy\"\n\t\t\t\t\t\t\t\t\tdecoding=\"async\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t<sp-icon\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-tray-icon\"\n\t\t\t\t\t\t\t\t\tname={t.kind === \"image\" ? \"image\" : \"file-text\"}\n\t\t\t\t\t\t\t\t\tsize=\"20\"\n\t\t\t\t\t\t\t\t></sp-icon>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-tray-name\" title={t.filename}>{t.filename}</span>\n\t\t\t\t\t\t\t{#if t.status === \"uploading\"}\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-tray-progress\"\n\t\t\t\t\t\t\t\t\trole=\"progressbar\"\n\t\t\t\t\t\t\t\t\taria-label=\"Uploading {t.filename}\"\n\t\t\t\t\t\t\t\t\taria-valuemin={0}\n\t\t\t\t\t\t\t\t\taria-valuemax={100}\n\t\t\t\t\t\t\t\t\taria-valuenow={progressOf(t)}\n\t\t\t\t\t\t\t\t\tstyle=\"--sp-fill: {progressOf(t)}%\"\n\t\t\t\t\t\t\t\t></span>\n\t\t\t\t\t\t\t{:else if t.status === \"refused\"}\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-tray-refusal\">{t.refusal ?? \"Not attached.\"}</span>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-tray-remove\"\n\t\t\t\t\t\t\t\taria-label=\"Remove {t.filename}\"\n\t\t\t\t\t\t\t\ttitle=\"Remove\"\n\t\t\t\t\t\t\t\tonclick={() => removeTrayItem(t)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"x\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</li>\n\t\t\t\t\t{/each}\n\t\t\t\t\t{#each refusedHere as r (r.key)}\n\t\t\t\t\t\t<li data-widget-part=\"messages.composer-tray-item\" data-status=\"refused\">\n\t\t\t\t\t\t\t<sp-icon data-widget-part=\"messages.composer-tray-icon\" name=\"ban\" size=\"20\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-tray-name\" title={r.filename}>{r.filename}</span>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-tray-refusal\">{r.reason}</span>\n\t\t\t\t\t\t</li>\n\t\t\t\t\t{/each}\n\t\t\t\t</ul>\n\t\t\t{/if}\n\t\t\t<div data-widget-part=\"messages.composer-footer\">\n\t\t\t\t<!-- Which channel this line lands on. Drawn only when there is\n\t\t\t\t a choice: one channel is every session that exists today,\n\t\t\t\t and a picker with one option is a control that teaches\n\t\t\t\t nothing. The chosen one is its `aria-pressed`. -->\n\t\t\t\t{#if channels.length > 1}\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.composer-channels\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label=\"Which channel you are writing on\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{#each channels as slug (slug)}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-channel\"\n\t\t\t\t\t\t\t\taria-pressed={slug === conv.lane.current}\n\t\t\t\t\t\t\t\ttitle=\"Write on {channelLabel(slug)}\"\n\t\t\t\t\t\t\t\tonclick={() => conv.lane.set(slug)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{channelLabel(slug)}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t\t{#if activePersona}\n\t\t\t\t\t{#if personaCount > 1}\n\t\t\t\t\t\t<!-- `sp-popover` (§3.5): our button is the trigger, the card the panel. -->\n\t\t\t\t\t\t<sp-popover\n\t\t\t\t\t\t\tplacement=\"top-start\"\n\t\t\t\t\t\t\topen={personaSwitcherOpen}\n\t\t\t\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => (personaSwitcherOpen = e.detail.open)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<button slot=\"trigger\" type=\"button\" data-widget-part=\"messages.composer-persona\"\n\t\t\t\t\t\t\t\ttitle=\"Switch persona\"\n\t\t\t\t\t\t\t\taria-label=\"Switch persona (currently {activePersona.name})\">\n\t\t\t\t\t\t\t\t<sp-avatar ref={`character:${activePersona.personaId}`} size=\"sm\"></sp-avatar>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-persona-name\">\n\t\t\t\t\t\t\t\t\t{activePersona.name}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t<sp-icon name=\"chevron-down\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.composer-persona-menu\">\n\t\t\t\t\t\t\t\t<p data-widget-part=\"messages.composer-persona-menu-title\">\n\t\t\t\t\t\t\t\t\tWrite as\n\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t{#each c?.personas ?? [] as p (p.personaId)}\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=\"messages.composer-persona-option\"\n\t\t\t\t\t\t\t\t\t\taria-current={p.personaId === c?.personaId ? \"true\" : undefined}\n\t\t\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\t\t\tvoid conv.request(\"switch-persona\", { personaId: p.personaId })\n\t\t\t\t\t\t\t\t\t\t\tpersonaSwitcherOpen = false\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-avatar ref={`character:${p.personaId}`} size=\"sm\"></sp-avatar>\n\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-persona-option-name\">{p.name}</span>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</sp-popover>\n\t\t\t\t\t{:else}\n\t\t\t\t\t\t<span data-widget-part=\"messages.composer-persona\">\n\t\t\t\t\t\t\t<sp-avatar ref={`character:${activePersona.personaId}`} size=\"sm\"></sp-avatar>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-persona-name\">\n\t\t\t\t\t\t\t\t{activePersona.name}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t{/if}\n\t\t\t\t{/if}\n\n\t\t\t\t<div data-widget-part=\"messages.composer-footer-end\">\n\t\t\t\t\t{#if offersAttachments}\n\t\t\t\t\t\t<!-- Attach: the device's picker, filtered to what this reply\n\t\t\t\t\t\t reads. Its body is our own button; the picker is the\n\t\t\t\t\t\t page's (`sp-file-picker`). -->\n\t\t\t\t\t\t<sp-file-picker\n\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-attach\"\n\t\t\t\t\t\t\taccept={pickerAccept || undefined}\n\t\t\t\t\t\t\tmultiple={true}\n\t\t\t\t\t\t\tonfiles={(e: CustomEvent<{ files: File[] }>) => void attachFiles(e.detail.files)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-attach-button messages.composer-icon-button\"\n\t\t\t\t\t\t\t\ttitle={readersLine ? `Attach files. ${readersLine}` : \"Attach files\"}\n\t\t\t\t\t\t\t\taria-label=\"Attach files\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"paperclip\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</sp-file-picker>\n\t\t\t\t\t{/if}\n\t\t\t\t\t{#if !hideCompose}\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-preview-toggle messages.composer-icon-button\"\n\t\t\t\t\t\t\taria-pressed={previewOpen}\n\t\t\t\t\t\t\ttitle=\"Preview\"\n\t\t\t\t\t\t\taria-label=\"Preview the formatted draft\"\n\t\t\t\t\t\t\tonclick={togglePreview}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"eye\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t{/if}\n\n\t\t\t\t\t{#if morePanes.length > 0 || readersOffered}\n\t\t\t\t\t\t<!-- `sp-popover` (§3.5): our button is the trigger, the card the panel.\n\t\t\t\t\t\t A panel filling the field area marks it `data-active`. Under\n\t\t\t\t\t\t the panes, **What can be attached** opens the readers dialog\n\t\t\t\t\t\t (note 41) — so it is here in every skin, panes or none. -->\n\t\t\t\t\t\t<sp-popover\n\t\t\t\t\t\t\tplacement=\"top-end\"\n\t\t\t\t\t\t\topen={moreMenuOpen}\n\t\t\t\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => (moreMenuOpen = e.detail.open)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<button slot=\"trigger\" type=\"button\" data-widget-part=\"messages.composer-more messages.composer-icon-button\"\n\t\t\t\t\t\t\t\tdata-active={activePane ? \"\" : undefined}\n\t\t\t\t\t\t\t\ttitle=\"More\"\n\t\t\t\t\t\t\t\taria-label=\"More\">\n\t\t\t\t\t\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.composer-panes\">\n\t\t\t\t\t\t\t\t\t\t<header data-widget-part=\"messages.composer-panes-title\">\n\t\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t\t<p>More</p>\n\t\t\t\t\t\t\t\t\t\t</header>\n\t\t\t\t\t\t\t\t\t\t<div data-widget-part=\"messages.composer-panes-list\">\n\t\t\t\t\t\t\t\t\t\t\t{#each morePanes as pane (pane.view)}\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=\"messages.composer-pane-option\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata-current={activePaneValue === pane.view ? \"\" : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\topenPane(pane.view)}\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<sp-icon name={pane.icon} size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span>{pane.title}</span>\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{/each}\n\t\t\t\t\t\t\t\t\t\t\t{#if readersOffered}\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=\"messages.composer-pane-option messages.composer-readers-button\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tonclick={openReaders}\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<sp-icon name=\"paperclip\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span>What can be attached</span>\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{/if}\n\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</sp-popover>\n\t\t\t\t\t{/if}\n\n\t\t\t\t\t{#if !hideCompose}\n\t\t\t\t\t\t{#if isGenerating}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-stop\"\n\t\t\t\t\t\t\t\ttitle=\"Stop\"\n\t\t\t\t\t\t\t\taria-label=\"Stop generating\"\n\t\t\t\t\t\t\t\tonclick={() => conv.invoke(\"stop\")}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"square\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Stop</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t<!-- Someone due next (`data-someone-due`): Send steps back. -->\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-send\"\n\t\t\t\t\t\t\t\tdata-someone-due={sendTonal ? \"\" : undefined}\n\t\t\t\t\t\t\t\tdisabled={!draft.trim() && !hasAttachments}\n\t\t\t\t\t\t\t\ttitle=\"Send\"\n\t\t\t\t\t\t\t\taria-label=\"Send message\"\n\t\t\t\t\t\t\t\tonclick={send}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"send\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Send</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t{/if}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t\t</sp-drop-zone>\n\n\t\t{#if offersAttachments}\n\t\t\t<!-- Attachments said aloud: \"cat.png attached\", a refusal, a removal. -->\n\t\t\t<p data-widget-part=\"messages.composer-announce\" aria-live=\"polite\">{announcement}</p>\n\t\t{/if}\n\t\t{#if readersOffered}\n\t\t\t<!-- What this reply can read (§3.2; note 41): out of the composer's\n\t\t\t body, opened from More. The summary, every kind with the reason\n\t\t\t a refused one can't be attached, and each model call's reading.\n\t\t\t A refusal at the moment of a pick or a drop still says why on\n\t\t\t its own tile, and aloud. -->\n\t\t\t<sp-dialog\n\t\t\t\tlabel=\"What can be attached\"\n\t\t\t\topen={readersOpen}\n\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => (readersOpen = e.detail.open)}\n\t\t\t>\n\t\t\t\t<span slot=\"title\">What can be attached</span>\n\t\t\t\t<div data-widget-part=\"messages.composer-readers\">\n\t\t\t\t\t<p data-widget-part=\"messages.composer-readers-line\">{readersLine}</p>\n\t\t\t\t\t<ul data-widget-part=\"messages.composer-readers-kinds\" aria-label=\"Kinds of file\">\n\t\t\t\t\t\t{#each ATTACHMENT_KINDS_V1 as k (k)}\n\t\t\t\t\t\t\t{@const v = readers?.kinds[k]}\n\t\t\t\t\t\t\t<li data-widget-part=\"messages.composer-readers-kind\" data-allowed={v?.allowed ? \"\" : undefined}>\n\t\t\t\t\t\t\t\t<strong>{KIND_NAME[k]}</strong>\n\t\t\t\t\t\t\t\t<span>({KIND_FORMATS[k]})</span>\n\t\t\t\t\t\t\t\t{#if v?.allowed}\n\t\t\t\t\t\t\t\t\t<span> — can be attached</span>\n\t\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-readers-reason\"> — can't be attached. {v?.reason ?? \"\"}</span>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</ul>\n\t\t\t\t\t{#if readerLines.length}\n\t\t\t\t\t\t<ul data-widget-part=\"messages.composer-readers-calls\" aria-label=\"Each model call\">\n\t\t\t\t\t\t\t{#each readerLines as line (line)}\n\t\t\t\t\t\t\t\t<li>{line}</li>\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t{/if}\n\t\t\t\t</div>\n\t\t\t</sp-dialog>\n\t\t{/if}\n\t\t{#if sendWaiting && uploading}\n\t\t\t<p data-widget-part=\"messages.composer-hint\" aria-live=\"polite\">{uploading} Sends when done.</p>\n\t\t{/if}\n\n\t\t{#if contextExceeded}\n\t\t\t<p\n\t\t\t\tid={warningId}\n\t\t\t\tdata-widget-part=\"messages.composer-warning\"\n\t\t\t\trole=\"alert\"\n\t\t\t>\n\t\t\t\tThis draft pushes the prompt past the context limit. Older turns\n\t\t\t\twill be trimmed.\n\t\t\t</p>\n\t\t{/if}\n\n\t\t{#if paletteOpen}\n\t\t\t<!-- While the palette is open Enter does not send: it runs the\n\t\t\t row it would pick (the same derivation the key handler reads),\n\t\t\t or — a bare `/` with nothing highlighted — only highlights. -->\n\t\t\t<p data-widget-part=\"messages.composer-hint\" aria-live=\"polite\">\n\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">Enter</kbd>\n\t\t\t\t{#if paletteEnterPick}\n\t\t\t\t\truns /{paletteEnterPick.slash}\n\t\t\t\t{:else}\n\t\t\t\t\thighlights the first ·\n\t\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">↑</kbd>\n\t\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">↓</kbd>\n\t\t\t\t\tto choose\n\t\t\t\t{/if}\n\t\t\t\t·\n\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">Esc</kbd>\n\t\t\t\tcloses.\n\t\t\t</p>\n\t\t{:else if slashCommand}\n\t\t\t<!-- A whole slash name and its argument (S2): what Enter (or Send)\n\t\t\t will do with it — or why it will not. -->\n\t\t\t<p\n\t\t\t\tdata-widget-part=\"messages.composer-hint\"\n\t\t\t\tdata-refused={slashRefusal ? \"\" : undefined}\n\t\t\t\taria-live=\"polite\"\n\t\t\t>\n\t\t\t\t{#if slashRefusal}\n\t\t\t\t\t{slashRefusal}.\n\t\t\t\t{:else}\n\t\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">{submitOnEnter ? \"Enter\" : \"Send\"}</kbd>\n\t\t\t\t\truns /{slashCommand.action.slash} with your text.\n\t\t\t\t{/if}\n\t\t\t</p>\n\t\t{:else if hintVisible && submitOnEnter}\n\t\t\t<p data-widget-part=\"messages.composer-hint\">\n\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">Enter</kbd>\n\t\t\t\tsends.\n\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">Shift</kbd>\n\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">Enter</kbd>\n\t\t\t\tfor a new line.\n\t\t\t</p>\n\t\t{/if}\n\t{/if}\n</div>\n","sessions/messages/SessionContainer.svelte":"<script lang=\"ts\">\n\timport { untrack } from \"svelte\"\n\timport {\n\t\tconversationIndex,\n\t\torderedMessages,\n\t\ttype ConversationSceneV1,\n\t\ttype MessageOrder\n\t} from \"@serene-pub/core-catalog/conversation\"\n\timport SessionMessage from \"./SessionMessage.svelte\"\n\timport { scopeNotGranted } from \"@serene-pub/core-catalog/widgets\"\n\timport { useConversation } from \"./conversation.svelte\"\n\timport type { MessageV1 } from \"@serene-pub/sdk/component\"\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\n\t// Visually distinct, readable scene colors (work in both light and dark)\n\tconst SCENE_COLORS = [\n\t\t{\n\t\t\tbar: \"hsl(220,65%,62%)\",\n\t\t\ttext: \"hsl(220,65%,65%)\",\n\t\t\tbg: \"hsl(220,65%,62%,0.10)\"\n\t\t}, // blue\n\t\t{\n\t\t\tbar: \"hsl(150,52%,48%)\",\n\t\t\ttext: \"hsl(150,52%,52%)\",\n\t\t\tbg: \"hsl(150,52%,48%,0.10)\"\n\t\t}, // green\n\t\t{\n\t\t\tbar: \"hsl(35, 75%,55%)\",\n\t\t\ttext: \"hsl(35, 75%,58%)\",\n\t\t\tbg: \"hsl(35, 75%,55%,0.10)\"\n\t\t}, // amber\n\t\t{\n\t\t\tbar: \"hsl(280,55%,62%)\",\n\t\t\ttext: \"hsl(280,55%,66%)\",\n\t\t\tbg: \"hsl(280,55%,62%,0.10)\"\n\t\t}, // purple\n\t\t{\n\t\t\tbar: \"hsl(340,60%,58%)\",\n\t\t\ttext: \"hsl(340,60%,62%)\",\n\t\t\tbg: \"hsl(340,60%,58%,0.10)\"\n\t\t}, // rose\n\t\t{\n\t\t\tbar: \"hsl(190,60%,48%)\",\n\t\t\ttext: \"hsl(190,60%,52%)\",\n\t\t\tbg: \"hsl(190,60%,48%,0.10)\"\n\t\t}, // teal\n\t\t{\n\t\t\tbar: \"hsl(55, 70%,50%)\",\n\t\t\ttext: \"hsl(55, 70%,54%)\",\n\t\t\tbg: \"hsl(55, 70%,50%,0.10)\"\n\t\t}, // yellow\n\t\t{\n\t\t\tbar: \"hsl(15, 70%,55%)\",\n\t\t\ttext: \"hsl(15, 70%,59%)\",\n\t\t\tbg: \"hsl(15, 70%,55%,0.10)\"\n\t\t} // orange\n\t]\n\n\t// Props for customizing the components used\n\t/**\n\t * The conversation's log (C0b): the widget's own part. It draws what the\n\t * conversation holds — the rows off the widget context, the scenes off the\n\t * page's dossier — in a host-measured scroll region (`sp-scroll`), and asks\n\t * for older rows when the reader reaches the far end.\n\t */\n\tinterface Props {\n\t\torder?: MessageOrder\n\t\tshowSceneMarkers?: boolean\n\t}\n\n\tlet { order = \"oldest-first\", showSceneMarkers = true }: Props = $props()\n\n\tconst conv = useConversation()\n\t// This copy's rows (S1): its channels', so a channel another copy claims\n\t// is never drawn here, not even hidden.\n\tconst messages = $derived(conv.rows)\n\tconst sceneList = $derived(conv.dossier?.scenes ?? [])\n\tconst loadingOlderMessages = $derived(!!conv.dossier?.loadingOlder)\n\tconst loaded = $derived(!!conv.dossier)\n\t/**\n\t * The host said this widget does not hold `session:full` (a plugin's copy\n\t * not granted it): the dossier will never come, so \"Loading session…\"\n\t * would spin forever — it is said instead.\n\t */\n\tconst dossierNotGranted = $derived(scopeNotGranted(conv.ctx, \"session:full\"))\n\n\t/** Older rows, asked for once per reach of the far end. */\n\tfunction loadOlder() {\n\t\tif (!conv.dossier?.hasOlder || conv.dossier.loadingOlder) return\n\t\tvoid conv.request(\"messages\", {})\n\t}\n\t/** The lore panel, at a history entry, a scene, or a new entry. */\n\tconst openLore = (params: {\n\t\tlorebookId: number\n\t\tscope: \"history\" | \"scenes\"\n\t\tentryId?: number\n\t\tsceneId?: number\n\t\tcreate?: boolean\n\t}) => void conv.request(\"open-lore\", params)\n\n\ttype MsgSceneInfo = {\n\t\tscene: ConversationSceneV1\n\t\tisFirstInScene: boolean\n\t\tisLastInScene: boolean\n\t\thistoryEntry: ConversationSceneV1[\"historyEntry\"]\n\t\tisFirstOfEntry: boolean\n\t\tisLastOfEntry: boolean\n\t\tcolorIndex: number\n\t}\n\n\t// Lightweight signal capturing only the message *set and order* (ids), not\n\t// their content. The parent replaces the whole `messages` array\n\t// reference on every streamed chunk even when only one message's content\n\t// changed, which would otherwise force the expensive O(scenes × messages)\n\t// derivation below to fully recompute on every token.\n\tlet msgOrderKey = $derived(messages.map((m) => m.id).join(\",\"))\n\n\tlet msgSceneMap = $derived.by((): Map<number, MsgSceneInfo> => {\n\t\t// Track sceneList and msgOrderKey as the real dependencies here. The\n\t\t// heavy work below (which reads messages directly) is wrapped\n\t\t// in untrack() so a messages reference change alone doesn't\n\t\t// dirty this derived — only a change in msgOrderKey's *value* (i.e. the\n\t\t// message ids/order actually changing) or sceneList does.\n\t\tvoid sceneList.length\n\t\tvoid msgOrderKey\n\n\t\t// An empty map is what \"no scene markers\" means everywhere below: no\n\t\t// divider, no chip, no coloured bar, and none of the work to find them.\n\t\tif (!showSceneMarkers) return new Map()\n\t\treturn untrack(buildMsgSceneMap)\n\t})\n\n\t/** The messages in the sequence this log draws them, `order` applied. */\n\tlet drawnMessages = $derived(\n\t\torderedMessages(messages, order)\n\t)\n\n\tfunction buildMsgSceneMap(): Map<number, MsgSceneInfo> {\n\t\tconst map = new Map<number, MsgSceneInfo>()\n\t\tif (!sceneList.length || !messages.length) return map\n\n\t\t// Build messageId → scene lookup\n\t\tconst messageToScene = new Map<number, ConversationSceneV1>()\n\t\tfor (const scene of sceneList) {\n\t\t\tfor (const msgId of scene.selectedMessageIds ?? []) {\n\t\t\t\tmessageToScene.set(msgId, scene)\n\t\t\t}\n\t\t}\n\n\t\t// For each scene, find its first/last message IDs in session display order\n\t\tconst sceneBounds = new Map<number, { first: number; last: number }>()\n\t\tfor (const scene of sceneList) {\n\t\t\tconst ids = new Set(scene.selectedMessageIds ?? [])\n\t\t\tif (!ids.size) continue\n\t\t\tconst ordered = messages\n\t\t\t\t.filter((m) => ids.has(m.id))\n\t\t\t\t.map((m) => m.id)\n\t\t\tif (ordered.length)\n\t\t\t\tsceneBounds.set(scene.id, {\n\t\t\t\t\tfirst: ordered[0],\n\t\t\t\t\tlast: ordered[ordered.length - 1]\n\t\t\t\t})\n\t\t}\n\n\t\t// For each history entry, find the last message across all its scenes\n\t\tconst entryLastMsgIndex = new Map<number, number>()\n\t\tfor (const scene of sceneList) {\n\t\t\tif (!scene.historyEntryId) continue\n\t\t\tconst bounds = sceneBounds.get(scene.id)\n\t\t\tif (!bounds) continue\n\t\t\tconst idx = messages.findIndex(\n\t\t\t\t(m) => m.id === bounds.last\n\t\t\t)\n\t\t\tconst current = entryLastMsgIndex.get(scene.historyEntryId) ?? -1\n\t\t\tif (idx > current) entryLastMsgIndex.set(scene.historyEntryId, idx)\n\t\t}\n\t\tconst entryLastMsgId = new Map<number, number>()\n\t\tfor (const [entryId, idx] of entryLastMsgIndex) {\n\t\t\tentryLastMsgId.set(entryId, messages[idx].id)\n\t\t}\n\n\t\t// Assign colors in the order scenes first appear in the session\n\t\tconst sceneColorIndex = new Map<number, number>()\n\t\tlet colorCounter = 0\n\t\tfor (const msg of messages) {\n\t\t\tconst scene = messageToScene.get(msg.id)\n\t\t\tif (scene && !sceneColorIndex.has(scene.id)) {\n\t\t\t\tsceneColorIndex.set(\n\t\t\t\t\tscene.id,\n\t\t\t\t\tcolorCounter % SCENE_COLORS.length\n\t\t\t\t)\n\t\t\t\tcolorCounter++\n\t\t\t}\n\t\t}\n\n\t\t// Walk messages in display order to build the full map\n\t\tconst seenEntryIds = new Set<number>()\n\t\tfor (const msg of messages) {\n\t\t\tconst scene = messageToScene.get(msg.id)\n\t\t\tif (!scene) continue\n\t\t\tconst bounds = sceneBounds.get(scene.id)\n\t\t\tif (!bounds) continue\n\n\t\t\tconst isFirstInScene = bounds.first === msg.id\n\t\t\tconst isLastInScene = bounds.last === msg.id\n\t\t\tconst entryId = scene.historyEntryId\n\t\t\tconst isFirstOfEntry =\n\t\t\t\tisFirstInScene && !!entryId && !seenEntryIds.has(entryId)\n\t\t\tif (isFirstOfEntry) seenEntryIds.add(entryId)\n\t\t\tconst isLastOfEntry =\n\t\t\t\t!!entryId && entryLastMsgId.get(entryId) === msg.id\n\n\t\t\tmap.set(msg.id, {\n\t\t\t\tscene,\n\t\t\t\tisFirstInScene,\n\t\t\t\tisLastInScene,\n\t\t\t\thistoryEntry: scene.historyEntry,\n\t\t\t\tisFirstOfEntry,\n\t\t\t\tisLastOfEntry,\n\t\t\t\tcolorIndex: sceneColorIndex.get(scene.id) ?? 0\n\t\t\t})\n\t\t}\n\n\t\treturn map\n\t}\n\n\tfunction formatEntryDate(he: {\n\t\tyear: number\n\t\tmonth: number | null\n\t\tday: number | null\n\t}): string {\n\t\tlet s = `Year ${he.year}`\n\t\tif (he.month) s += `, Mo. ${he.month}`\n\t\tif (he.day) s += `, Day ${he.day}`\n\t\treturn s\n\t}\n</script>\n\n<!-- The log's parts (`messages.*`, STYLE-GUIDE §6.16): no look here; the\n default widget stylesheet draws them. -->\n<div data-widget-part=\"messages.log-body\">\n\t<!-- The host measures and scrolls (`sp-scroll`): pinned to the newest end\n\t as rows arrive, held still when the reader has scrolled away, and\n\t `reach-start` at the far end asks for older rows. -->\n\t<sp-scroll\n\t\tdata-widget-part=\"messages.log-scroll\"\n\t\tstick={order === \"newest-first\" ? \"top\" : \"bottom\"}\n\t\tlabel=\"Session messages\"\n\t\tonreach-start={loadOlder}\n\t>\n\t<!-- The region spans the panel; the rows (the stage, `messages.stage`)\n\t take its full width, or a centred measure under Line width:\n\t Comfortable. -->\n\t<div\n\t\tid=\"session-history\"\n\t\tdata-widget-part=\"messages.stage\"\n\t\trole=\"log\"\n\t\taria-live=\"polite\"\n\t\taria-atomic=\"false\"\n\t>\n\t\t<div data-widget-part=\"messages.stage-body\">\n\t\t\t{#if !loaded && dossierNotGranted}\n\t\t\t\t<div data-widget-part=\"messages.log-note messages.log-floor\" role=\"status\" data-scope-not-granted=\"session:full\">\n\t\t\t\t\t<sp-icon name=\"lock\" size=\"28\" data-widget-part=\"messages.log-floor-icon\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"messages.log-floor-text\">\n\t\t\t\t\t\t{conv.t(\"This widget has not been granted the whole conversation. An administrator can grant it in the extension's permissions.\")}\n\t\t\t\t\t</span>\n\t\t\t\t</div>\n\t\t\t{:else if !loaded}\n\t\t\t\t<!-- Still loading the session itself — distinct from a genuinely\n\t\t\t\t empty session below, otherwise \"No messages yet.\" flashes on\n\t\t\t\t every session open even when it has hundreds of messages. -->\n\t\t\t\t<div data-widget-part=\"messages.log-loading messages.log-floor\">\n\t\t\t\t\t<sp-icon name=\"loader-2\" size=\"28\" data-widget-part=\"messages.log-floor-icon messages.log-loading-icon\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"messages.log-floor-text\">Loading session…</span>\n\t\t\t\t</div>\n\t\t\t{:else if messages.length === 0}\n\t\t\t\t<div data-widget-part=\"messages.log-empty messages.log-floor empty\">\n\t\t\t\t\t<sp-icon name=\"message-square-text\" size=\"28\" data-widget-part=\"messages.log-floor-icon\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"messages.log-floor-text\">Send a message to start</span>\n\t\t\t\t</div>\n\t\t\t{:else}\n\t\t\t\t<!-- The older messages arrive at whichever end they are drawn\n\t\t\t\t at, so the indicator for them sits at that end too. -->\n\t\t\t\t{#snippet olderMessagesLoading()}\n\t\t\t\t\t{#if loadingOlderMessages}\n\t\t\t\t\t\t<div data-widget-part=\"messages.older-loading\">\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.older-loading-body\">\n\t\t\t\t\t\t\t\t<sp-icon name=\"loader-2\" size=\"16\" data-widget-part=\"messages.older-loading-icon\"></sp-icon>\n\t\t\t\t\t\t\t\tLoading older messages...\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t{/if}\n\t\t\t\t{/snippet}\n\t\t\t\t{#if order === \"oldest-first\"}\n\t\t\t\t\t{@render olderMessagesLoading()}\n\t\t\t\t{/if}\n\n\t\t\t\t<ul\n\t\t\t\t\tdata-widget-part=\"messages.message-list list\"\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label=\"Session conversation with {messages.length} messages\"\n\t\t\t\t>\n\t\t\t\t\t{#each drawnMessages as msg, row (msg.id)}\n\t\t\t\t\t\t{@const index = conversationIndex(\n\t\t\t\t\t\t\trow,\n\t\t\t\t\t\t\tmessages.length,\n\t\t\t\t\t\t\torder\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{@const isLastMessage =\n\t\t\t\t\t\t\tindex === messages.length - 1}\n\t\t\t\t\t\t{@const onThisChannel =\n\t\t\t\t\t\t\t(msg.channel || \"main\") === conv.lane.current}\n\t\t\t\t\t\t{@const si = msgSceneMap.get(msg.id)}\n\t\t\t\t\t\t{@const color = si ? SCENE_COLORS[si.colorIndex] : null}\n\n\t\t\t\t\t\t<!-- History-entry marker: the date this stretch of the\n\t\t\t\t\t\t story is set on, once before the entry's first scene\n\t\t\t\t\t\t message. -->\n\t\t\t\t\t\t{#if si?.isFirstOfEntry && si.historyEntry}\n\t\t\t\t\t\t\t<li data-widget-part=\"messages.log-item\" role=\"presentation\">\n\t\t\t\t\t\t\t\t{#if si.scene.historyEntryId}\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.history-marker\"\n\t\t\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\t\t\topenLore({\n\t\t\t\t\t\t\t\t\t\t\t\tscope: \"history\",\n\t\t\t\t\t\t\t\t\t\t\t\tentryId: si.scene.historyEntryId!,\n\t\t\t\t\t\t\t\t\t\t\t\tlorebookId: si.scene.lorebookId\n\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\ttitle=\"Open history entry in lorebook\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"calendar\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t{formatEntryDate(si.historyEntry)}\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.history-marker\">\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"calendar\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t{formatEntryDate(si.historyEntry)}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t{/if}\n\n\t\t\t\t\t\t<!-- Scene title: the scene's name at the top of its\n\t\t\t\t\t\t group, in the scene's own colour. -->\n\t\t\t\t\t\t{#if si?.isFirstInScene && color}\n\t\t\t\t\t\t\t<li\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.log-item\"\n\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\tstyle=\"--sp-scene: {color.text}\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.scene-title\"\n\t\t\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\t\t\topenLore({\n\t\t\t\t\t\t\t\t\t\t\t\tscope: \"scenes\",\n\t\t\t\t\t\t\t\t\t\t\t\tsceneId: si.scene.id,\n\t\t\t\t\t\t\t\t\t\t\t\tentryId: si.scene.historyEntryId ?? undefined,\n\t\t\t\t\t\t\t\t\t\t\t\tlorebookId: si.scene.lorebookId\n\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\ttitle=\"Open scene in lorebook\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"film\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t{si.scene.name ?? \"Scene\"}\n\t\t\t\t\t\t\t\t\t\t{#if si.historyEntry && !si.historyEntry.isCompleted}\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.scene-title-state\">\n\t\t\t\t\t\t\t\t\t\t\t\topen\n\t\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t{/if}\n\n\t\t\t\t\t\t<!-- The message row. It carries the scene's colour as\n\t\t\t\t\t\t `--sp-scene`, which the style pack draws the scene's\n\t\t\t\t\t\t edge with and the message's own scene badge inherits.\n\n\t\t\t\t\t\t Opacity-only fade, no height/transform — autoscroll\n\t\t\t\t\t\t reads scrollHeight synchronously on insert, so an\n\t\t\t\t\t\t entering message has to contribute its full height\n\t\t\t\t\t\t to layout immediately.\n\t\t\t\t\t\t Enter is suppressed for bulk inserts: while older\n\t\t\t\t\t\t messages are being prepended, and for anything that\n\t\t\t\t\t\t isn't the last message (so switching sessions doesn't\n\t\t\t\t\t\t fade the whole backlog in). First render needs no\n\t\t\t\t\t\t guard — Svelte transitions are local by default, so\n\t\t\t\t\t\t they don't play when an ancestor block is created.\n\t\t\t\t\t\t Exit is fade-only: the <ul> has a gap, and a\n\t\t\t\t\t\t collapsing <li> would leave that gap behind to snap\n\t\t\t\t\t\t shut at the end — a worse artifact than the fix. -->\n\t\t\t\t\t\t<li\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-row\"\n\t\t\t\t\t\t\thidden={!onThisChannel}\n\t\t\t\t\t\t\tstyle={color\n\t\t\t\t\t\t\t\t? `--sp-scene: ${color.text}`\n\t\t\t\t\t\t\t\t: undefined}\n\t\t\t\t\t\t\tdata-scene={si ? si.scene.id : undefined}\n\t\t\t\t\t\t\tdata-arrive={untrack(() =>\n\t\t\t\t\t\t\t\tloadingOlderMessages || !isLastMessage\n\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t: \"\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<SessionMessage\n\t\t\t\t\t\t\t\t{msg}\n\t\t\t\t\t\t\t\t{index}\n\t\t\t\t\t\t\t\t{isLastMessage}\n\t\t\t\t\t\t\t\tsceneName={si ? (si.scene.name ?? \"Scene\") : null}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</li>\n\n\t\t\t\t\t\t<!-- Completed-entry marker: where this entry's story\n\t\t\t\t\t\t stops, and the way on to the next one. -->\n\t\t\t\t\t\t{#if si?.isLastOfEntry && si.historyEntry?.isCompleted}\n\t\t\t\t\t\t\t<li data-widget-part=\"messages.log-item\" role=\"presentation\">\n\t\t\t\t\t\t\t\t{#if si.historyEntry.nextEntry}\n\t\t\t\t\t\t\t\t\t{@const next = si.historyEntry.nextEntry}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.history-marker\"\n\t\t\t\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\t\t\t\topenLore({\n\t\t\t\t\t\t\t\t\t\t\t\t\tscope: \"history\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tentryId: next.id,\n\t\t\t\t\t\t\t\t\t\t\t\t\tlorebookId: si.scene.lorebookId\n\t\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\t\ttitle=\"Open next history entry in lorebook\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"calendar\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t\tNext: {formatEntryDate(next)}\n\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.history-marker messages.history-start\"\n\t\t\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\t\t\topenLore({\n\t\t\t\t\t\t\t\t\t\t\t\tscope: \"history\",\n\t\t\t\t\t\t\t\t\t\t\t\tcreate: true,\n\t\t\t\t\t\t\t\t\t\t\t\tlorebookId: si.scene.lorebookId\n\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\ttitle=\"Start a new history entry\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"calendar-plus\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\tStart a new entry\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</li>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t{/each}\n\t\t\t\t</ul>\n\t\t\t\t{#if order === \"newest-first\"}\n\t\t\t\t\t{@render olderMessagesLoading()}\n\t\t\t\t{/if}\n\t\t\t{/if}\n\t\t</div>\n\t</div>\n\t</sp-scroll>\n</div>\n","sessions/messages/SessionMessage.svelte":"<script lang=\"ts\">\n\timport { messageEnvoySlug } from \"@serene-pub/core-catalog/conversation\"\n\timport MessageComposer from \"./MessageComposer.svelte\"\n\timport MessageControls from \"./MessageControls.svelte\"\n\timport {\n\t\tenabledWhenState,\n\t\tquickRowActions,\n\t\tverdictOf\n\t} from \"@serene-pub/core-catalog/conversation\"\n\timport { actionIdentity, foldedSectionsOf } from \"@serene-pub/sdk/component\"\n\timport MessagePartsView from \"./MessagePartsView.svelte\"\n\timport MessageMediaStrip from \"./MessageMediaStrip.svelte\"\n\timport { mediaStripItems, viewImageParams } from \"./mediaStrip\"\n\timport MessageStateLedger from \"./MessageStateLedger.svelte\"\n\timport { useWidgetContext } from \"../shared/context\"\n\timport { staleOf } from \"@serene-pub/core-catalog/conversation\"\n\timport { untrack } from \"svelte\"\n\timport { useConversation } from \"./conversation.svelte\"\n\timport type { MessageV1, WidgetAction } from \"@serene-pub/sdk/component\"\n\n\t/**\n\t * One line of the conversation (C0b). It is handed its row and where it\n\t * sits; everything else is the conversation's (`useConversation`) — who\n\t * spoke, what the viewer controls, what is being edited or selected — and\n\t * every press is one of its verbs.\n\t */\n\tinterface Props {\n\t\tmsg: MessageV1\n\t\tindex: number\n\t\tisLastMessage: boolean\n\t\t/**\n\t\t * The scene this message belongs to, when it belongs to one — the log\n\t\t * reads it off its scene map. The row also carries the scene's colour\n\t\t * as `--sp-scene`, which the badge below inherits.\n\t\t */\n\t\tsceneName?: string | null\n\t}\n\n\tlet { msg, index, isLastMessage, sceneName = null }: Props = $props()\n\n\tconst conv = useConversation()\n\tconst line = $derived(conv.line(msg.id))\n\tconst allMessages = $derived(conv.ctx.messages.v1)\n\tconst hasGeneratingMessage = $derived(allMessages.some((m) => m.isGenerating))\n\tconst extendRefusal = $derived(conv.dossier?.extendRefusal)\n\tconst isSummarizationMode = $derived(conv.select.active)\n\tconst isSelected = $derived(conv.select.ids.has(msg.id))\n\tconst scened = $derived(conv.dossier?.scened.includes(msg.id) ?? false)\n\n\t/**\n\t * The unified widget envelope (PLAN 25, ruled 2026-08-30). Present at the\n\t * one real site — SessionLayout renders the `messages` widget's snippet\n\t * inside a `WidgetHost`, and Svelte resolves context where a snippet RENDERS\n\t * rather than where it was declared, so the host's ctx reaches down here.\n\t * Undefined anywhere else (a standalone mount, a test), which is why every\n\t * read below keeps its prop as the fallback.\n\t */\n\tconst widget = useWidgetContext()\n\tconst ctx = $derived(widget?.current)\n\n\t/**\n\t * The first two of this component's ~16 `onXxx` callbacks to move onto the\n\t * envelope, because they are the two that were already action-shaped — a\n\t * verb plus this message as its subject, which is exactly `ctx.action`'s\n\t * signature.\n\t *\n\t * The two routes are the SAME call, not two spellings of a similar one:\n\t * the envelope's `invoke` resolves the identity against `ctx.actions.v1`\n\t * and hands the press to the host's `actionDispatch`, whose `fire` IS\n\t * +page's `fireOfferedAction` — the one the prop reaches through\n\t * `fireMenuAction`. One function, one emit, one permission check, so the\n\t * run is named and the narrator's modal opens whichever way it was\n\t * pressed. `ctx.action` (⏳) remains the block lane's fallback and lands\n\t * on the same function by way of `handleFrameAction`.\n\t */\n\t/**\n\t * A contributed action fired from the options menu or the quick row\n\t * (19 §4), its identity riding along (W1) so the server checks THAT\n\t * declaration and runs THAT spec.\n\t */\n\tfunction fireOfferedAction(action: WidgetAction, m: MessageV1) {\n\t\tconv.invoke(actionIdentity(action), m)\n\t}\n\n\t/**\n\t * A declared block action inside a parts-native body (20 §6). `action`\n\t * is the identity the block was stamped with by the outlet that wrote it\n\t * (W-E) — carried, never chosen here — so the server checks THAT\n\t * declaration; a block with none fires legacy (the owner floor).\n\t */\n\tfunction fireBlockAction(\n\t\tfn: string,\n\t\tm: MessageV1,\n\t\tpayload?: Record<string, unknown>,\n\t\taction?: string,\n\t\tblockId?: string\n\t) {\n\t\t// ⏳ `action`, not `invoke`: a block's `action` is the identity the\n\t\t// OUTLET stamped it with (W-E), which need not be listed in any venue of\n\t\t// this session, and `invoke` refuses a reference no venue lists. The\n\t\t// host forwards all five arguments, so the identity and the block\n\t\t// survive the hop and the server holds the press to the block's\n\t\t// addressee.\n\t\tconv.ctx.action(fn, m.id, payload, action, blockId)\n\t}\n\n\tconst messageCount = $derived(allMessages.length)\n\n\t/**\n\t * The face beside this line (DESIGN-sprites §7). With the messages widget's\n\t * `avatarFace` setting at `sprite`, a line shows the sprite it was SHOWN —\n\t * set and label recorded on the line itself, so scrolling back past an\n\t * outfit change keeps the old outfit on the old lines. The default is the\n\t * avatar, because a face per line is busy in the bubble skins. The message\n\t * id picks among a label's variants, so one line always shows one image.\n\t */\n\tlet showLineSprite = $derived(\n\t\t(ctx?.settings?.v1 as { avatarFace?: string } | undefined)?.avatarFace ===\n\t\t\t\"sprite\"\n\t)\n\tlet faceSrc = $derived(\n\t\tshowLineSprite ? (line.speaker.sprite ?? line.speaker.face) : line.speaker.face\n\t)\n\tconst narratorDisplayName = $derived(\n\t\tmsg.metadata?.narratorName || \"Narrator\"\n\t)\n\t/** Who this message is from, as the header prints it. */\n\tconst displayName = $derived(\n\t\tmsg.isNarratorResponse ? narratorDisplayName : line.speaker.name\n\t)\n\t/**\n\t * The member a role-named line belongs to (R4): \"Dungeon Master · jody\"\n\t * on a shared session's persona-less line, drawn muted after the name.\n\t * The page sends it only when the session has more than one member.\n\t */\n\tconst speakerMember = $derived(\n\t\tmsg.isNarratorResponse ? undefined : line.speaker.member?.trim() || undefined\n\t)\n\t/** The disc a speaker with no picture gets: their initial. */\n\tconst avatarInitial = $derived(\n\t\tdisplayName.trim().charAt(0).toUpperCase() || \"?\"\n\t)\n\tconst isGreeting = $derived(!!msg.metadata?.isGreeting)\n\t// Two independent classifications the style packs (sessionLayout skins) key\n\t// off. The one SessionMessage renders every layout; these attributes are\n\t// what a bubbles/compact/moonlit skin uses for alignment, colour and\n\t// avatar placement.\n\t// data-msg-role = user | assistant | narration (who's speaking, by turn)\n\t// data-msg-author = persona | character | narrator (which entity kind)\n\t// They usually agree (a persona speaks as 'user', a character as 'assistant')\n\t// but are kept separate so a skin can leverage either — e.g. impersonation,\n\t// or group chats where the split matters.\n\tconst msgRole = $derived(\n\t\tmsg.isNarratorResponse\n\t\t\t? \"narration\"\n\t\t\t: msg.role === \"user\"\n\t\t\t\t? \"user\"\n\t\t\t\t: \"assistant\"\n\t)\n\t/** An envoy's line (U5g): named by reference, no character row behind it. */\n\tconst isEnvoy = $derived(messageEnvoySlug(msg) !== null)\n\tconst msgAuthor = $derived(\n\t\tmsg.isNarratorResponse\n\t\t\t? \"narrator\"\n\t\t\t: msg.personaId != null\n\t\t\t\t? \"persona\"\n\t\t\t\t: msg.characterId != null\n\t\t\t\t\t? \"character\"\n\t\t\t\t\t: isEnvoy\n\t\t\t\t\t\t? \"envoy\"\n\t\t\t\t\t\t: \"unknown\"\n\t)\n\tconst canControl = $derived(line.controllable)\n\tconst showSwipes = $derived(line.swipes.show)\n\t/**\n\t * The swipe arrow's gate is the swipe verb's own enabled-when (U5e,\n\t * review W3): the list's verdict, then the `item.*` predicates — the\n\t * newest row, a swipe to take — judged against this row exactly as the\n\t * ⋮ menu's Swipe entry and the server's door judge them, so the arrow\n\t * and the entry can never disagree. `canSwipeRight` (the page's older\n\t * compound) is ⏳ unread here since U5e and kept on the prop chain one\n\t * release. With no listed swipe verb (an older server) the arrow is\n\t * open to the item rule alone.\n\t */\n\tconst swipeWhen = $derived.by(() => {\n\t\tconst listed = [\n\t\t\t...(venueActions?.primary ?? []),\n\t\t\t...(venueActions?.overflow ?? [])\n\t\t].find((a) => a.specSlug === \"core\" && a.key === \"swipe\")\n\t\tif (!listed) return [false, undefined] as const\n\t\treturn enabledWhenState({\n\t\t\tmsg,\n\t\t\tisLastMessage,\n\t\t\tcanControl,\n\t\t\t...verdictOf(listed)\n\t\t})\n\t})\n\t// The model's reasoning, for the active swipe — native (Ollama's\n\t// `message.thinking`, a `reasoning_content` field) or lifted out of the\n\t// text by the host. It streams in as it arrives: the host's live row\n\t// writes it beside the body on every frame, so the fold fills while the\n\t// reply is still reasoning.\n\tconst reasoningContent = $derived(msg.metadata?.reasoning || \"\")\n\tconst hasReasoning = $derived(reasoningContent.trim().length > 0)\n\n\t// Optional per-trigger focus note for a Narrator response (e.g. \"Focus on\n\t// the weather turning stormy\") — set once at trigger time, see sessions.ts's\n\t// narratorMessage.metadata.narratorInstructions.\n\tconst narratorInstructionsContent = $derived(\n\t\tmsg.metadata?.narratorInstructions || \"\"\n\t)\n\tconst hasNarratorInstructions = $derived(\n\t\tnarratorInstructionsContent.trim().length > 0\n\t)\n\n\tlet isReasoningExpanded = $state(false)\n\tlet isNarratorInstructionsExpanded = $state(false)\n\n\t// The shown alternative's folded sections (B4) — for a row that arrives\n\t// without its parts (a streamed frame's announce, a swipe), which the\n\t// parts view would otherwise draw. Expanded state by position.\n\tconst foldedSections = $derived(foldedSectionsOf(msg.metadata))\n\tlet expandedSections = $state<Record<number, boolean>>({})\n\n\t// The edit buffer: the widget owns edit mode (`conv.edit`); the row's text\n\t// is copied in when editing starts, and saving is the `edit` verb.\n\tconst isEditing = $derived(conv.edit.id === msg.id)\n\tlet editContent = $state(\"\")\n\t$effect(() => {\n\t\tif (isEditing) editContent = untrack(() => msg.content)\n\t})\n\t// Parts-native rendering (20 §13 phase 2): when the server attached the\n\t// message's typed parts and the message is settled, the body — reasoning\n\t// and section collapsibles included — renders from them. Streaming,\n\t// errors, and unenriched broadcasts fall back to the legacy fields, which\n\t// are parity-identical by construction.\n\tconst partsNative = $derived(\n\t\t!!msg.parts?.length && !msg.isGenerating && !msg.error && !isEditing\n\t)\n\n\tconst isEditDirty = $derived(isEditing && editContent !== msg.content)\n\t// Empty is blocked as well as unchanged: clearing a message to nothing\n\t// leaves an unreadable stub in the thread, and Delete is the control that\n\t// actually expresses that intent.\n\tconst canSaveEdit = $derived(isEditDirty && editContent.trim().length > 0)\n\n\t/** A `date` column carries the day only; a time of day needs a timestamp. */\n\tconst DAY_ONLY = /^\\d{4}-\\d{2}-\\d{2}$/\n\n\t/**\n\t * The clock beside the name, in the reader's own locale. `createdAt` is a\n\t * day-precision `date` column on this row (20 §5), so a value with no time\n\t * of day in it reads `updatedAt`, which is a timestamp.\n\t */\n\tconst messageTime = $derived.by(() => {\n\t\tconst created: unknown = msg.createdAt\n\t\tconst stamp =\n\t\t\ttypeof created === \"string\" && DAY_ONLY.test(created)\n\t\t\t\t? (msg.updatedAt ?? created)\n\t\t\t\t: (created ?? msg.updatedAt)\n\t\tif (!stamp) return \"\"\n\t\tconst at =\n\t\t\tstamp instanceof Date ? stamp : new Date(stamp as string | number)\n\t\tif (Number.isNaN(at.getTime())) return \"\"\n\t\treturn at.toLocaleTimeString([], {\n\t\t\thour: \"numeric\",\n\t\t\tminute: \"2-digit\"\n\t\t})\n\t})\n\n\t/**\n\t * What the ember dot beside the name says while a reply is being made:\n\t * the run's own status (R-19) — *Jasmine is thinking*, *Jasmine is\n\t * reasoning* while the model's trace streams, *Jasmine is typing*,\n\t * *loading the model* — resolved in the reader's language. A\n\t * row with none says *working* until its run's first status lands.\n\t */\n\tconst generatingStatus = $derived(\n\t\tconv.statusText(msg.generationStatus) || conv.t(\"working\")\n\t)\n\n\t// ── the quick actions ────────────────────────────────────────────────\n\t// The message venue's PRIMARY set (R-15 `quick`, U5c), one click away on\n\t// the row itself — core's verbs and a plugin's `quick` message action\n\t// alike (S8) — each shown on exactly the messages the ⋮ menu offers it\n\t// on and only while the menu would have it enabled, through the one verb\n\t// table both read (`quickRowActions`). The menu keeps the full list,\n\t// including the entries that are disabled and explained. Stop is the\n\t// primary set's too, but it has its own pill below rather than an icon.\n\t//\n\t// The list arrives on the widget envelope when a host provides one, the\n\t// prop otherwise; with neither, the floors alone.\n\tconst venueActions = $derived(\n\t\tctx?.actions?.v1?.message as\n\t\t\t| { primary: WidgetAction[]; overflow: WidgetAction[] }\n\t\t\t| undefined\n\t)\n\tconst quickActions = $derived(\n\t\tquickRowActions(venueActions?.primary ?? [], {\n\t\t\tmsg,\n\t\t\tisLastMessage,\n\t\t\tediting: conv.edit.id !== null,\n\t\t\thasGeneratingMessage,\n\t\t\tcanControl,\n\t\t\textendRefusal\n\t\t})\n\t)\n\tconst showQuickActions = $derived(\n\t\t!isSummarizationMode && !isEditing && quickActions.length > 0\n\t)\n\n\t/**\n\t * A quick icon fires the same handler the menu's row does: core's verbs\n\t * to the page's handlers, a contributed action through `fireOfferedAction`\n\t * with this message as the subject.\n\t */\n\tfunction fireQuick(_e: Event, action: WidgetAction) {\n\t\tif (action.specSlug !== \"core\") return fireOfferedAction(action, msg)\n\t\tif (action.key === \"edit\") return conv.edit.start(msg)\n\t\tif (action.key === \"swipe\") return conv.swipe(msg, \"right\")\n\t\tconv.invoke(action.key, msg)\n\t}\n\n\t/** The swipe counter is drawn only where there is a history to count. */\n\tconst swipes = $derived(msg.metadata?.swipes)\n\tconst hasSwipeHistory = $derived(\n\t\tswipes?.currentIdx !== null &&\n\t\t\tswipes?.currentIdx !== undefined &&\n\t\t\t!!swipes?.history &&\n\t\t\tswipes.history.length > 1\n\t)\n\n\tfunction handleMessageUpdate() {\n\t\tif (!canSaveEdit) return\n\t\tconv.edit.save(msg, editContent)\n\t}\n\n\tfunction toggleReasoning() {\n\t\tisReasoningExpanded = !isReasoningExpanded\n\t}\n\n\tfunction toggleNarratorInstructions() {\n\t\tisNarratorInstructionsExpanded = !isNarratorInstructionsExpanded\n\t}\n\n\t/**\n\t * The media strip's files (composer attachments plan §3.4): read off the\n\t * row's parts in EVERY state — settled, legacy text, editing, generating —\n\t * so an attachment never disappears while its line is edited or a reply\n\t * streams beside it. The parts view no longer draws them inline.\n\t */\n\tconst mediaItems = $derived(\n\t\tmediaStripItems(msg.parts, msg.activeRevisions ?? { \"0\": 0 })\n\t)\n\n\t// An image inside the rendered text is the host's markup; `sp-message-body`\n\t// raises `open-image` with its address.\n\tconst openImage = (e: CustomEvent<{ src: string }>) =>\n\t\tvoid conv.request(\"view-image\", { src: e.detail.src })\n</script>\n\n<!-- A <div>, not an <li>: SessionContainer already wraps each message in its own\n <li> (the row that carries `--sp-scene`), so an <li> here nests a list item\n inside a list item — invalid HTML that confuses assistive-tech list\n semantics. The role=\"article\" below is what carries the semantics.\n\n The four cells are the style packs' contract: avatar, identity, controls,\n content — plus the media strip, a fifth cell under content when the\n message has files — and the `data-msg-*` attributes a pack keys its look off. Every\n element is a widget part (`messages.message-*`, STYLE-GUIDE §6.16): no look\n here; the default widget stylesheet draws them, and a pack restyles them. -->\n<div\n\tid=\"message-{msg.id}\"\n\tdata-widget-part=\"messages.message\"\n\tdata-msg-role={msgRole}\n\tdata-msg-author={msgAuthor}\n\tdata-msg-state={isEditing\n\t\t? \"editing\"\n\t\t: isSummarizationMode\n\t\t\t? isSelected\n\t\t\t\t? \"selected\"\n\t\t\t\t: \"dim\"\n\t\t\t: \"normal\"}\n\tdata-msg-generating={msg.isGenerating ? \"\" : undefined}\n\tdata-msg-hidden={msg.isHidden ? \"\" : undefined}\n\tdata-msg-greeting={isGreeting ? \"\" : undefined}\n\tdata-msg-newest={isLastMessage ? \"\" : undefined}\n\ttabindex=\"-1\"\n\trole=\"article\"\n\taria-label=\"Message {index +\n\t\t1} of {messageCount} from {displayName}{speakerMember ? ` · ${speakerMember}` : ''}: {msg.content.slice(0, 100)}{msg\n\t\t.content.length > 100\n\t\t? '...'\n\t\t: ''}\"\n>\n\t<span data-widget-part=\"messages.message-avatar\">\n\t\t{#if msg.isNarratorResponse}\n\t\t\t<span\n\t\t\t\tdata-widget-part=\"messages.message-avatar-glyph\"\n\t\t\t\ttitle={narratorDisplayName}\n\t\t\t\taria-hidden=\"true\"\n\t\t\t>\n\t\t\t\t<sp-icon name=\"cloud-sun\" size=\"1.25em\"></sp-icon>\n\t\t\t</span>\n\t\t{:else}\n\t\t\t<!-- Avatar rendered directly (not the reusable Avatar component):\n\t\t\t Skeleton hard-sizes its avatar root, which fought the layout\n\t\t\t CSS. A plain img/glyph lets each style pack own size and shape. -->\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.message-avatar-button\"\n\t\t\t\tonclick={() => line.speaker.ref && void conv.request(\"view-avatar\", { ref: line.speaker.ref })}\n\t\t\t\taria-label=\"View {displayName}'s avatar\"\n\t\t\t>\n\t\t\t\t{#if faceSrc}\n\t\t\t\t\t<img\n\t\t\t\t\t\tdata-widget-part=\"messages.message-avatar-img\"\n\t\t\t\t\t\tsrc={faceSrc}\n\t\t\t\t\t\talt={displayName}\n\t\t\t\t\t/>\n\t\t\t\t{:else}\n\t\t\t\t\t<span data-widget-part=\"messages.message-avatar-glyph\" aria-hidden=\"true\">\n\t\t\t\t\t\t{avatarInitial}\n\t\t\t\t\t</span>\n\t\t\t\t{/if}\n\t\t\t</button>\n\t\t{/if}\n\t</span>\n\n\t<div data-widget-part=\"messages.message-identity\">\n\t\t{#if msg.isNarratorResponse}\n\t\t\t<span data-widget-part=\"messages.message-name\" title={narratorDisplayName}>\n\t\t\t\t{narratorDisplayName}\n\t\t\t</span>\n\t\t{:else if isEnvoy}\n\t\t\t<!-- Nothing to open: an envoy has no character page. -->\n\t\t\t<span data-widget-part=\"messages.message-name\" title={displayName}>\n\t\t\t\t{displayName}\n\t\t\t</span>\n\t\t{:else}\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.message-name\"\n\t\t\t\tonclick={() => {\n\t\t\t\t\tconst id = msg.characterId ?? msg.personaId\n\t\t\t\t\tif (id) void conv.request(\"open-character\", { characterId: id })\n\t\t\t\t}}\n\t\t\t\ttitle={displayName}\n\t\t\t>\n\t\t\t\t{displayName}\n\t\t\t</button>\n\t\t{/if}\n\t\t{#if speakerMember}\n\t\t\t<span data-widget-part=\"messages.message-member\">· {speakerMember}</span>\n\t\t{/if}\n\n\t\t<span data-widget-part=\"messages.message-badges\">\n\t\t\t{#if isGreeting}\n\t\t\t\t<span\n\t\t\t\t\tdata-widget-part=\"messages.message-badge\"\n\t\t\t\t\trole=\"img\"\n\t\t\t\t\taria-label=\"Greeting message\"\n\t\t\t\t>\n\t\t\t\t\t<sp-icon name=\"handshake\" size=\"14\"></sp-icon>\n\t\t\t\t</span>\n\t\t\t{/if}\n\t\t\t{#if msg.isHidden}\n\t\t\t\t<span\n\t\t\t\t\tdata-widget-part=\"messages.message-badge\"\n\t\t\t\t\trole=\"img\"\n\t\t\t\t\taria-label=\"Hidden from the model\"\n\t\t\t\t>\n\t\t\t\t\t<sp-icon name=\"ghost\" size=\"14\"></sp-icon>\n\t\t\t\t</span>\n\t\t\t{/if}\n\t\t\t{#if sceneName}\n\t\t\t\t<!-- Colour comes from `--sp-scene` on the row this message\n\t\t\t\t sits in, so the badge and the pack's scene bar are the\n\t\t\t\t same colour by construction. -->\n\t\t\t\t<span data-widget-part=\"messages.message-badge messages.message-badge-scene\">\n\t\t\t\t\t<sp-icon name=\"film\" size=\"14\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"messages.message-badge-label\">In scene:</span>\n\t\t\t\t\t<span data-widget-part=\"messages.message-badge-text\">{sceneName}</span>\n\t\t\t\t</span>\n\t\t\t{/if}\n\t\t\t<!-- The line's vectors against the active embedding model: nothing\n\t\t\t at all while that is hidden (the common case); which it is\n\t\t\t rides `data-vectors`. -->\n\t\t\t{#if line.embedding === \"current\"}\n\t\t\t\t<span data-widget-part=\"messages.message-vectors\" data-vectors=\"current\" title=\"Vectors up to date\" aria-label=\"Vectors up to date\">\n\t\t\t\t\t<sp-icon name=\"zap\" size=\"12\"></sp-icon>\n\t\t\t\t</span>\n\t\t\t{:else if line.embedding === \"stale\"}\n\t\t\t\t<span data-widget-part=\"messages.message-vectors\" data-vectors=\"stale\" title=\"Vectors stale — model changed\" aria-label=\"Vectors stale — model changed\">\n\t\t\t\t\t<sp-icon name=\"refresh-cw\" size=\"12\"></sp-icon>\n\t\t\t\t</span>\n\t\t\t{/if}\n\t\t</span>\n\n\t\t{#if msg.isGenerating}\n\t\t\t<span data-widget-part=\"messages.message-status\">\n\t\t\t\t<span data-widget-part=\"messages.message-ember\" aria-hidden=\"true\"></span>\n\t\t\t\t{generatingStatus}\n\t\t\t</span>\n\t\t{:else if isEditing}\n\t\t\t<span data-widget-part=\"messages.message-status\">Editing</span>\n\t\t{:else if msg.generationOutcome === \"stopped\"}\n\t\t\t<!-- The explicit outcome (R-15): a reply somebody stopped, holding\n\t\t\t the partial text. Cleared by the next regenerate or extend on\n\t\t\t the row, and by a swipe onto another alternative — the stop\n\t\t\t belongs to the alternative that was streaming, so selecting a\n\t\t\t different one leaves the mark behind. -->\n\t\t\t<span data-widget-part=\"messages.message-status\" title=\"This reply was stopped before it finished\">\n\t\t\t\tStopped\n\t\t\t</span>\n\t\t{/if}\n\t</div>\n\n\t<div data-widget-part=\"messages.message-controls\">\n\t\t{#if isEditing}\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.message-cancel\"\n\t\t\t\ttitle=\"Cancel edit (Esc)\"\n\t\t\t\tonclick={() => conv.edit.cancel()}\n\t\t\t>\n\t\t\t\tCancel\n\t\t\t</button>\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.message-save\"\n\t\t\t\ttitle={canSaveEdit\n\t\t\t\t\t? \"Save changes (Ctrl+Enter)\"\n\t\t\t\t\t: isEditDirty\n\t\t\t\t\t\t? \"A message can't be saved empty\"\n\t\t\t\t\t\t: \"No changes to save\"}\n\t\t\t\tdisabled={!canSaveEdit}\n\t\t\t\tonclick={handleMessageUpdate}\n\t\t\t>\n\t\t\t\tSave\n\t\t\t</button>\n\t\t{:else}\n\t\t\t{#if messageTime}\n\t\t\t\t<span data-widget-part=\"messages.message-time\">{messageTime}</span>\n\t\t\t{/if}\n\n\t\t\t{#if showSwipes}\n\t\t\t\t<div data-widget-part=\"messages.message-swipes\">\n\t\t\t\t\t{#if hasSwipeHistory}\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-swipe-previous messages.message-icon-button\"\n\t\t\t\t\t\t\taria-label=\"Previous swipe\"\n\t\t\t\t\t\t\tonclick={() => conv.swipe(msg, \"left\")}\n\t\t\t\t\t\t\tdisabled={conv.edit.id !== null ||\n\t\t\t\t\t\t\t\t!swipes!.currentIdx ||\n\t\t\t\t\t\t\t\tswipes!.history.length <= 1 ||\n\t\t\t\t\t\t\t\tmsg.isGenerating ||\n\t\t\t\t\t\t\t\t!canControl}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"chevron-left\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<!-- tabular-nums + a min width so stepping 9/12 -> 10/12\n\t\t\t\t\t\t doesn't shove the arrows sideways. -->\n\t\t\t\t\t\t<span data-widget-part=\"messages.message-swipe-count\" aria-live=\"polite\">\n\t\t\t\t\t\t\t{(swipes!.currentIdx || 0) + 1} / {swipes!.history\n\t\t\t\t\t\t\t\t.length}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t{/if}\n\t\t\t\t\t<button\n\t\t\t\t\t\tdata-widget-part=\"messages.message-swipe-next messages.message-icon-button\"\n\t\t\t\t\t\taria-label=\"Next swipe\"\n\t\t\t\t\t\ttitle={swipeWhen[1] ? `Next swipe — ${swipeWhen[1]}` : undefined}\n\t\t\t\t\t\tonclick={() => conv.swipe(msg, \"right\")}\n\t\t\t\t\t\tdisabled={conv.edit.id !== null || swipeWhen[0] || !canControl}\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-icon name=\"chevron-right\" size=\"14\"></sp-icon>\n\t\t\t\t\t</button>\n\t\t\t\t</div>\n\t\t\t{/if}\n\n\t\t\t{#if showQuickActions}\n\t\t\t\t<!-- The icons fade in on hover and focus on a fine pointer and\n\t\t\t\t stand permanently on a coarse one — see messageLayouts.css,\n\t\t\t\t STYLE-GUIDE §9. -->\n\t\t\t\t<div\n\t\t\t\t\tdata-widget-part=\"messages.message-actions\"\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label=\"Message actions\"\n\t\t\t\t>\n\t\t\t\t\t{#each quickActions as { action } (actionIdentity(action))}\n\t\t\t\t\t\t{@const iconName = action.icon || \"play\"}\n\t\t\t\t\t\t<!-- Icon-only: the accessible name is the declaration's\n\t\t\t\t\t\t `iconAlt`, else its name; the tooltip adds what it\n\t\t\t\t\t\t does (the legend, 2026-09-28). -->\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-action messages.message-icon-button\"\n\t\t\t\t\t\t\taria-label={action.iconAlt || action.name}\n\t\t\t\t\t\t\ttitle={action.description\n\t\t\t\t\t\t\t\t? `${action.name} — ${action.description}`\n\t\t\t\t\t\t\t\t: action.name}\n\t\t\t\t\t\t\tonclick={(e) => fireQuick(e, action)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name={iconName} size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t{/each}\n\t\t\t\t</div>\n\t\t\t{/if}\n\n\t\t\t<div data-widget-part=\"messages.message-menu\">\n\t\t\t\t{#if isSummarizationMode}\n\t\t\t\t\t<!-- Selecting lines for a summary: this line's own choice, and\n\t\t\t\t\t the two range selections. A line a scene already captured\n\t\t\t\t\t cannot join another. -->\n\t\t\t\t\t<div data-widget-part=\"messages.message-selection\" role=\"group\" aria-label=\"Selection controls\">\n\t\t\t\t\t\t{#if scened}\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-in-scene messages.message-selection-button\"\n\t\t\t\t\t\t\t\ttitle=\"Already captured in a scene\"\n\t\t\t\t\t\t\t\taria-label=\"Already captured in a scene\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"film\"></sp-icon>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.message-selection-label\">In Scene</span>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-select messages.message-selection-button\"\n\t\t\t\t\t\t\t\ttitle={isSelected ? \"Deselect message\" : \"Select message\"}\n\t\t\t\t\t\t\t\taria-label={isSelected ? \"Deselect message\" : \"Select message\"}\n\t\t\t\t\t\t\t\taria-pressed={isSelected}\n\t\t\t\t\t\t\t\tonclick={() => conv.select.toggle(msg)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name={isSelected ? \"check-square\" : \"square\"}></sp-icon>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.message-selection-label\">{isSelected ? \"Deselect\" : \"Select\"}</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-select-above messages.message-selection-button\"\n\t\t\t\t\t\t\t\ttitle=\"Select all above up to nearest selected\"\n\t\t\t\t\t\t\t\taria-label=\"Select all above up to nearest selected\"\n\t\t\t\t\t\t\t\tonclick={() => conv.select.range(index, \"above\")}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"chevrons-up\"></sp-icon>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.message-selection-label\">Select all above</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-select-below messages.message-selection-button\"\n\t\t\t\t\t\t\t\ttitle=\"Select all below up to nearest selected\"\n\t\t\t\t\t\t\t\taria-label=\"Select all below up to nearest selected\"\n\t\t\t\t\t\t\t\tonclick={() => conv.select.range(index, \"below\")}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"chevrons-down\"></sp-icon>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.message-selection-label\">Select all below</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</div>\n\t\t\t\t{:else}\n\t\t\t\t\t<MessageControls {msg} {isLastMessage} />\n\t\t\t\t{/if}\n\t\t\t</div>\n\n\t\t\t{#if msg.isGenerating}\n\t\t\t\t<button\n\t\t\t\t\tdata-widget-part=\"messages.message-stop\"\n\t\t\t\t\tonclick={() => conv.invoke(\"stop\", msg)}\n\t\t\t\t>\n\t\t\t\t\t<sp-icon name=\"square\" size=\"14\"></sp-icon>\n\t\t\t\t\tStop\n\t\t\t\t</button>\n\t\t\t{/if}\n\t\t{/if}\n\t</div>\n\n\t<div data-widget-part=\"messages.message-content\">\n\t\t<!-- The collapsibles a reply can carry: the Narrator's per-trigger\n\t\t focus note, its folded sections (a Plan, B4) and the model's own\n\t\t reasoning. All are suppressed when parts render — the section and\n\t\t reasoning parts carry them there, in the same order. -->\n\t\t{#if (hasNarratorInstructions || hasReasoning || foldedSections.length) && !partsNative}\n\t\t\t<div data-widget-part=\"messages.message-disclosures\">\n\t\t\t\t{#if hasNarratorInstructions}\n\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-toggle\"\n\t\t\t\t\t\t\tonclick={toggleNarratorInstructions}\n\t\t\t\t\t\t\taria-expanded={isNarratorInstructionsExpanded}\n\t\t\t\t\t\t\taria-controls=\"extra-instructions-{msg.id}\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"target\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t<span>Extra instructions</span>\n\t\t\t\t\t\t\t<sp-icon name=\"chevron-down\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<!-- grid 0fr -> 1fr is the only way to transition to/from an\n\t\t\t\t\t\t auto height in pure CSS. The inner overflow-hidden\n\t\t\t\t\t\t wrapper is required: the track collapses to 0 but the\n\t\t\t\t\t\t content keeps its intrinsic height, so without it the\n\t\t\t\t\t\t text spills out. Content stays mounted while collapsed\n\t\t\t\t\t\t because a transition needs both endpoints to exist —\n\t\t\t\t\t\t and the skin hides a collapsed track's content, since\n\t\t\t\t\t\t a 0fr track still contains focusable content\n\t\t\t\t\t\t (`messages.message-disclosure-track`, widgets.css). -->\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tid=\"extra-instructions-{msg.id}\"\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-track\"\n\t\t\t\t\t\t\tdata-expanded={isNarratorInstructionsExpanded ? \"\" : undefined}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure-clip\">\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-panel messages.prose\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-message-body text={narratorInstructionsContent}></sp-message-body>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\n\t\t\t\t{#each foldedSections as section, i (i)}\n\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-toggle\"\n\t\t\t\t\t\t\tonclick={() => (expandedSections[i] = !expandedSections[i])}\n\t\t\t\t\t\t\taria-expanded={!!expandedSections[i]}\n\t\t\t\t\t\t\taria-controls=\"folded-section-{msg.id}-{i}\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon\n\t\t\t\t\t\t\t\tname={section.kind === \"reasoning\" ? \"brain-circuit\" : \"notebook-pen\"}\n\t\t\t\t\t\t\t\tsize=\"14\"\n\t\t\t\t\t\t\t></sp-icon>\n\t\t\t\t\t\t\t<span>{section.label}</span>\n\t\t\t\t\t\t\t<sp-icon name=\"chevron-down\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<!-- See the first block for why this is a grid track. -->\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tid=\"folded-section-{msg.id}-{i}\"\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-track\"\n\t\t\t\t\t\t\tdata-expanded={expandedSections[i] ? \"\" : undefined}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure-clip\">\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-panel messages.prose\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{#if section.items}\n\t\t\t\t\t\t\t\t\t\t<ul data-widget-part=\"messages.fold-list\">\n\t\t\t\t\t\t\t\t\t\t\t{#each section.items as item, j (j)}\n\t\t\t\t\t\t\t\t\t\t\t\t<li>{item}</li>\n\t\t\t\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t\t\t<sp-message-body text={section.content ?? \"\"}></sp-message-body>\n\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{/each}\n\n\t\t\t\t{#if hasReasoning}\n\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-toggle\"\n\t\t\t\t\t\t\tonclick={toggleReasoning}\n\t\t\t\t\t\t\taria-expanded={isReasoningExpanded}\n\t\t\t\t\t\t\taria-controls=\"reasoning-{msg.id}\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"brain-circuit\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t<span>Reasoning</span>\n\t\t\t\t\t\t\t<sp-icon name=\"chevron-down\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<!-- See the block above for why this is a grid track. -->\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tid=\"reasoning-{msg.id}\"\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-track\"\n\t\t\t\t\t\t\tdata-expanded={isReasoningExpanded ? \"\" : undefined}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure-clip\">\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-panel messages.prose\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-message-body text={reasoningContent}></sp-message-body>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\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</div>\n\t\t{/if}\n\n\t\t<!-- Padding-free wrapper that carries the height change of a discrete\n\t\t swap (swiping between alternatives, entering or leaving edit, an\n\t\t error replacing content) — in CSS, the conversation skin's\n\t\t `messages.message-sizer`, where the engine can interpolate to `auto`. Not while\n\t\t generating: the height changes on every token, and a transition\n\t\t would trail the text instead of settling. -->\n\t\t<div data-widget-part=\"messages.message-sizer\" data-settled={msg.isGenerating ? undefined : \"\"}>\n\t\t\t<div data-widget-part=\"messages.message-body\">\n\t\t\t\t{#if msg.error}\n\t\t\t\t\t<div data-widget-part=\"messages.message-failure\">\n\t\t\t\t\t\t{#if msg.content}\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.message-partial messages.prose\">\n\t\t\t\t\t\t\t\t<sp-message-body text={msg.content}></sp-message-body>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<div data-widget-part=\"messages.message-error\">\n\t\t\t\t\t\t\t<p data-widget-part=\"messages.message-error-line\">\n\t\t\t\t\t\t\t\t<sp-icon name=\"alert-triangle\" size=\"14\" data-widget-part=\"messages.message-error-icon\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t{msg.error.message}{#if msg.error.code}\n\t\t\t\t\t\t\t\t\t\t({msg.error.code}){/if}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t<!--\n\t\t\t\t\t\tPresence IS permission. `error.connection` is connection\n\t\t\t\t\t\tidentity, and the server removes that key from every\n\t\t\t\t\t\tpayload a non-admin receives (connections/visibility.ts),\n\t\t\t\t\t\tso a client that renders it whenever it arrives shows it\n\t\t\t\t\t\tonly to administrators — no role check here to drift out\n\t\t\t\t\t\tof step with the one on the server.\n\n\t\t\t\t\t\tThe sentence above names no connection by construction,\n\t\t\t\t\t\twhich is what lets it be stored and shown to anybody; this\n\t\t\t\t\t\tis where an administrator gets back the half it left out —\n\t\t\t\t\t\twhich connection, and what the service actually said.\n\t\t\t\t\t-->\n\t\t\t\t\t\t\t{#if msg.error.connection?.name || msg.error.connection?.detail}\n\t\t\t\t\t\t\t\t<p data-widget-part=\"messages.message-error-detail\">\n\t\t\t\t\t\t\t\t\t{[\n\t\t\t\t\t\t\t\t\t\tmsg.error.connection.name,\n\t\t\t\t\t\t\t\t\t\tmsg.error.connection.model\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t\t\t\t.join(\" · \")}{msg.error.connection\n\t\t\t\t\t\t\t\t\t\t.detail\n\t\t\t\t\t\t\t\t\t\t? `${msg.error.connection.name ? \"\\n\" : \"\"}${msg.error.connection.detail}`\n\t\t\t\t\t\t\t\t\t\t: \"\"}\n\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-retry\"\n\t\t\t\t\t\t\t\tonclick={() => conv.invoke(\"retry\", msg)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tRetry\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{:else if isEditing}\n\t\t\t\t\t<!-- One surface: the panel IS the field. The textarea below\n\t\t\t\t\t drops its own border, radius and fill (see `edit-field`)\n\t\t\t\t\t and simply lays text on this one. -->\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.edit-surface\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<MessageComposer\n\t\t\t\t\t\t\tbind:markdown={editContent}\n\t\t\t\t\t\t\tonSend={handleMessageUpdate}\n\t\t\t\t\t\t\tonCancel={() => conv.edit.cancel()}\n\t\t\t\t\t\t\tenterBehavior=\"newline\"\n\t\t\t\t\t\t\tplaceholder=\"Edit this message…\"\n\t\t\t\t\t\t\tautofocus\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<!-- Transient: it exists only while an edit is open, so\n\t\t\t\t\t\t it can't become permanent noise. -->\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tdata-widget-part=\"messages.edit-hint\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<kbd data-widget-part=\"messages.edit-key\">Ctrl</kbd>\n\t\t\t\t\t\t\t\t+\n\t\t\t\t\t\t\t\t<kbd data-widget-part=\"messages.edit-key\">Enter</kbd>\n\t\t\t\t\t\t\t\tto save\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span aria-hidden=\"true\" data-widget-part=\"messages.edit-hint-separator\">·</span>\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<kbd data-widget-part=\"messages.edit-key\">Esc</kbd>\n\t\t\t\t\t\t\t\tto cancel\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t{#if isEditDirty}\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.edit-unsaved\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\tUnsaved changes\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{:else if partsNative}\n\t\t\t\t\t<!-- The parts-native body (20 §2): markdown, reasoning,\n\t\t\t\t sections, steps — everything typed renders from parts. -->\n\t\t\t\t\t<div data-widget-part=\"messages.message-parts\">\n\t\t\t\t\t\t<MessagePartsView\n\t\t\t\t\t\t\tmessageId={msg.id}\n\t\t\t\t\t\t\tparts={msg.parts!}\n\t\t\t\t\t\t\tactiveRevisions={msg.activeRevisions ?? { \"0\": 0 }}\n\t\t\t\t\t\t\tonOpenImage={(src) => void conv.request(\"view-image\", { src })}\n\t\t\t\t\t\t\tbodyText={msg.content ?? \"\"}\n\t\t\t\t\t\t\tonAction={(fn, payload, action, blockId) =>\n\t\t\t\t\t\t\t\tfireBlockAction(fn, msg, payload, action, blockId)}\n\t\t\t\t\t\t\tcanAnswer={(addressee) => conv.canAnswer(addressee)}\n\t\t\t\t\t\t\tisStale={(block) =>\n\t\t\t\t\t\t\t\tstaleOf(block, msg, allMessages)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t{:else}\n\t\t\t\t\t<!-- `data-streaming`: text is arriving (the row is generating and\n\t\t\t\t\t has some), which the sheet pulses. -->\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.message-text messages.prose\"\n\t\t\t\t\t\tdata-streaming={msg.isGenerating && msg.content ? \"\" : undefined}\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-message-body\n\t\t\t\t\t\t\ttext={msg.content}\n\t\t\t\t\t\t\tstreaming={msg.isGenerating ? \"\" : undefined}\n\t\t\t\t\t\t\tonopen-image={openImage}\n\t\t\t\t\t\t></sp-message-body>\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t</div>\n\t\t</div>\n\n\t\t<!-- What this turn changed, and what it is still asking for (the stats\n\t\t and states ledger). Renders nothing at all for a message that\n\t\t changed nothing, which is almost every message — and it is outside\n\t\t the height-animated wrapper above, because a decision landing here\n\t\t must not look like the body re-rendering. -->\n\t\t<MessageStateLedger messageId={msg.id} />\n\t</div>\n\n\t<!-- The media strip: attachments and generated images as square tiles,\n\t in every state of the row — a cell of its own under the content, so\n\t it sits BELOW a pack's card, never inside it (next-pass note 40,\n\t 2026-10-03; the base sheet places it on the row after `content`). -->\n\t<MessageMediaStrip\n\t\titems={mediaItems}\n\t\tediting={isEditing && canControl}\n\t\tonOpen={(images, index) =>\n\t\t\tvoid conv.request(\"view-image\", viewImageParams(images, index))}\n\t\tonRemove={canControl\n\t\t\t? (item) =>\n\t\t\t\t\tvoid conv.request(\"remove-attachment\", { messageId: msg.id, partId: item.partId })\n\t\t\t: undefined}\n\t/>\n</div>\n","sessions/messages/StateProposalList.svelte":"<script lang=\"ts\">\n\t/**\n\t * Held changes, with the two buttons that decide them.\n\t *\n\t * The model is the one writer with no authority: what it produces is a\n\t * pending line, not a change. So nothing here applies anything — Accept runs\n\t * the same write a script's would have run, Reject leaves the world as it\n\t * was, and until one of them is pressed the stat says what it said.\n\t *\n\t * The same list under a message and in the Review panel, because \"everything\n\t * waiting\" and \"what this turn asked for\" are the same rows read at two\n\t * scopes, and two components would be two ways to describe one payload.\n\t *\n\t * A **superseded** row (plans/29 R-15 *Staleness and order*; U5f) is an\n\t * accept that applied nothing: the slot moved since the proposal was\n\t * made. It stays under its message, collapsed, naming what moved, with\n\t * no buttons — the ledger's word on why the model's ask never landed.\n\t */\n\timport type { ConversationProposalV1 } from \"@serene-pub/core-catalog/conversation\"\n\timport { useConversation, useT } from \"./conversation.svelte\"\n\n\tinterface Props {\n\t\tproposals: ConversationProposalV1[]\n\t\t/** Shown in the Review panel, where a row is not under its message. */\n\t\tshowAnchor?: boolean\n\t}\n\tlet { proposals, showAnchor = false }: Props = $props()\n\n\tconst conv = useConversation()\n\tconst t = useT()\n\tconst describe = (row: ConversationProposalV1) => row.text\n\tconst movedName = (row: ConversationProposalV1) => row.moved ?? t(\"a value\")\n\tconst decide = (id: number, accept: boolean) =>\n\t\tvoid conv.request(\"decide-proposal\", { proposalId: id, accept })\n</script>\n\n{#each proposals as row (row.id)}\n\t{#if row.status === \"superseded\"}\n\t\t<div\n\t\t\tdata-widget-part=\"messages.proposal\"\n\t\t\tdata-proposal-id={row.id}\n\t\t\tdata-superseded=\"true\"\n\t\t>\n\t\t\t<sp-icon name=\"history\" size=\"11\"></sp-icon>\n\t\t\t<span data-widget-part=\"messages.proposal-text\">\n\t\t\t\t{describe(row)}\n\t\t\t\t<span data-widget-part=\"messages.proposal-note\">\n\t\t\t\t\t· {t(\"Superseded — {slot} changed since this was proposed\").replace(\n\t\t\t\t\t\t\"{slot}\",\n\t\t\t\t\t\tmovedName(row)\n\t\t\t\t\t)}\n\t\t\t\t</span>\n\t\t\t</span>\n\t\t</div>\n\t{:else}\n\t\t<div data-widget-part=\"messages.proposal\" data-proposal-id={row.id}>\n\t\t\t<sp-icon name=\"sparkles\" size=\"11\"></sp-icon>\n\t\t\t<span data-widget-part=\"messages.proposal-text\">\n\t\t\t\t{describe(row)}\n\t\t\t\t{#if showAnchor && row.messageId != null}\n\t\t\t\t\t<span data-widget-part=\"messages.proposal-anchor\">on message {row.messageId}</span>\n\t\t\t\t{/if}\n\t\t\t</span>\n\t\t\t<span data-widget-part=\"messages.proposal-note\" title=\"Proposed by {row.proposedBy || 'a run'}\">\n\t\t\t\tproposed\n\t\t\t</span>\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.proposal-decide messages.proposal-accept\"\n\t\t\t\tonclick={() => decide(row.id, true)}\n\t\t\t>\n\t\t\t\tAccept\n\t\t\t</button>\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.proposal-decide messages.proposal-reject\"\n\t\t\t\tonclick={() => decide(row.id, false)}\n\t\t\t>\n\t\t\t\tReject\n\t\t\t</button>\n\t\t</div>\n\t{/if}\n{/each}\n","sessions/messages/conversation.svelte.ts":"/**\n * The conversation widget's own model (C0b): what its parts read, derived\n * from the widget context alone, and what they do, through its verbs alone.\n *\n * `MessagesWidget` creates one and provides it; the log, each message, its\n * controls and the composer read it (`useConversation`) instead of taking the\n * page's callbacks as props. So the widget's state — which line is being\n * edited, whose menu is open, what is selected for a summary — is the\n * widget's, and every effect is an `invoke` (core's verbs, a contributed\n * action) or a `request` (something the host opens). Nothing here imports a\n * store, the socket or the page: the same source runs in a UI worker.\n */\nimport { getContext, setContext } from \"svelte\"\nimport { SvelteSet } from \"svelte/reactivity\"\nimport { useWidgetContext } from \"../shared/context\"\nimport type { WidgetContextRef } from \"@serene-pub/core-catalog/conversation\"\nimport {\n\tNO_LINE,\n\ttype ConversationDossierV1,\n\ttype ConversationLineV1\n} from \"@serene-pub/core-catalog/conversation\"\nimport type { WidgetRequestKind, WidgetRequests } from \"@serene-pub/sdk/component\"\nimport { canAnswerForm } from \"@serene-pub/core-catalog/conversation\"\nimport { setStatusTextResolver, statusTextIn } from \"@serene-pub/core-catalog/conversation\"\nimport type { RequestDeclineCode, StatusText } from \"@serene-pub/sdk/component\"\n\nconst KEY = Symbol(\"sp-conversation\")\n\nexport type Conversation = ReturnType<typeof createConversation>\n\n/** What a verb's subject is: a message, by id. */\ntype Subject = { id: number }\n\n/**\n * A request declined because the view went away — the page's decline of what\n * it never answered, or the wire's own at `close()`. Expected at every\n * unmount with a request in flight (the composer's `draft` is nearly always\n * one), so it is not a failure worth a line on stderr. Read by its\n * `code` (`unmounted`, a {@link RequestDeclineCode}); an older host declines\n * with its sentence alone (\"the page was unmounted before it answered\"), so\n * the text is the fallback.\n */\nexport function isUnmountDecline(e: unknown): boolean {\n\tconst code: unknown = typeof e === \"object\" && e !== null ? (e as { code?: unknown }).code : undefined\n\tif (code !== undefined) return code === (\"unmounted\" satisfies RequestDeclineCode)\n\tconst message = e instanceof Error ? e.message : String(e)\n\treturn /\\bunmounted\\b/.test(message)\n}\n\nexport function createConversation(widget: WidgetContextRef) {\n\tconst ctx = () => widget.current\n\tconst warn = (what: string) => (e: unknown) => {\n\t\tif (isUnmountDecline(e)) return\n\t\tconsole.warn(`conversation: ${what} — ${e instanceof Error ? e.message : String(e)}`)\n\t}\n\n\tlet editingId = $state<number | null>(null)\n\tlet menuFor = $state<number | undefined>(undefined)\n\tlet selecting = $state(false)\n\t/** The lane the composer writes to, and the log shows (`main` by default). */\n\tlet lane = $state(\"main\")\n\tconst selected = new SvelteSet<number>()\n\n\t// Status sentences in this widget's language (`text.ts`).\n\tsetStatusTextResolver(\n\t\t() => ctx().locale.v1,\n\t\t(source) => ctx().t(source)\n\t)\n\n\t// Through the context's own type — its scoped keys come from the SDK's\n\t// one table — so a renamed section fails to compile here.\n\tconst dossier = $derived((ctx().session_full?.v1 ?? null) as ConversationDossierV1 | null)\n\n\t/**\n\t * The channels this copy shows (lair re-plan S1): its composer's, which\n\t * the host narrows per mount — a copy pinned to the Sanctum is told\n\t * `['sanctum']`, the primary log the channels no pinned copy claims.\n\t * `null` (no dossier yet, or an empty list) is every channel.\n\t */\n\tconst channels = $derived.by((): string[] | null => {\n\t\tconst listed = dossier?.composer?.channels\n\t\treturn listed && listed.length ? listed : null\n\t})\n\t/** A row's channel slug: `main` when unset, a lane's slug for `slug:n`. */\n\tconst slugOf = (channel: unknown) =>\n\t\t(typeof channel === \"string\" && channel ? channel : \"main\").split(\":\")[0]\n\t/**\n\t * The rows this log holds: the host's log narrowed to this copy's\n\t * channels. A row on a channel another copy claims is not drawn here at\n\t * all (never merely hidden), so two copies never hold the same line.\n\t */\n\tconst rows = $derived.by(() => {\n\t\tconst all = ctx().messages.v1\n\t\tif (!channels) return all\n\t\tconst shown = new Set(channels)\n\t\treturn all.filter((m) => shown.has(slugOf((m as { channel?: unknown }).channel)))\n\t})\n\n\t// The host's summary finished: the selection it was handed ends.\n\tlet summaryEnded: number | null = null\n\t$effect(() => {\n\t\tconst n = dossier?.summaryEnded ?? 0\n\t\tif (summaryEnded !== null && n !== summaryEnded) {\n\t\t\tselecting = false\n\t\t\tselected.clear()\n\t\t}\n\t\tsummaryEnded = n\n\t})\n\n\t/** `text`: what the press supplies — the composer's slash argument (S2). */\n\tfunction invoke(key: string, subject?: Subject, payload?: Record<string, unknown>, text?: string) {\n\t\ttry {\n\t\t\tctx().invoke(key, { messageId: subject?.id, payload, ...(text !== undefined ? { text } : {}) })\n\t\t} catch (e) {\n\t\t\twarn(key)(e)\n\t\t}\n\t}\n\n\tfunction request<K extends WidgetRequestKind>(kind: K, params: WidgetRequests[K][\"params\"]) {\n\t\treturn ctx().request(kind, params).catch(warn(kind))\n\t}\n\n\treturn {\n\t\tget ctx() {\n\t\t\treturn ctx()\n\t\t},\n\t\tget dossier() {\n\t\t\treturn dossier\n\t\t},\n\t\t/** The page's word on one line; nothing when it has none. */\n\t\tline(id: number): ConversationLineV1 {\n\t\t\treturn dossier?.lines[id] ?? NO_LINE\n\t\t},\n\t\tt: (source: string) => ctx().t(source),\n\t\t/** A status sentence in the viewer's language. */\n\t\tstatusText: (status: StatusText | null | undefined) =>\n\t\t\tstatusTextIn(status, ctx().locale.v1, (source) => ctx().t(source)),\n\n\t\t/** May the viewer answer a form put to `addressee`? */\n\t\tcanAnswer(addressee: string | undefined) {\n\t\t\tconst f = dossier\n\t\t\treturn canAnswerForm(\n\t\t\t\taddressee,\n\t\t\t\t{ userId: ctx().viewer.v1.userId, isOwner: !!f?.isOwner, isAdmin: ctx().viewer.v1.isAdmin },\n\t\t\t\tf?.cast\n\t\t\t)\n\t\t},\n\n\t\t// ── verbs ────────────────────────────────────────────────────────────\n\t\tinvoke,\n\t\t/** A reply swiped: to the newer alternative (right) or the older (left). */\n\t\tswipe(subject: Subject, direction: \"left\" | \"right\") {\n\t\t\tinvoke(\"swipe\", subject, { direction })\n\t\t},\n\t\trequest,\n\n\t\t// ── editing: the widget's own state; saving is the `edit` verb ───────\n\t\tedit: {\n\t\t\tget id() {\n\t\t\t\treturn editingId\n\t\t\t},\n\t\t\tstart(subject: Subject) {\n\t\t\t\teditingId = subject.id\n\t\t\t\tmenuFor = undefined\n\t\t\t},\n\t\t\tcancel() {\n\t\t\t\teditingId = null\n\t\t\t},\n\t\t\tsave(subject: Subject, content: string) {\n\t\t\t\tinvoke(\"edit\", subject, { content })\n\t\t\t\teditingId = null\n\t\t\t}\n\t\t},\n\n\t\t/** The rows this copy's log holds — its channels' (S1), in the host's order. */\n\t\tget rows() {\n\t\t\treturn rows\n\t\t},\n\t\t/** The channels this copy shows, or `null` for every channel. */\n\t\tget channels() {\n\t\t\treturn channels\n\t\t},\n\t\t/**\n\t\t * What a channel is CALLED: its declared label in the viewer's language\n\t\t * (`ChannelDecl.label`, the Lair's _Sanctum_), else its slug, title-cased\n\t\t * (`manuscript` reads _Manuscript_).\n\t\t */\n\t\tchannelName(slug: string): string {\n\t\t\tconst label = dossier?.composer?.channelLabels?.[slug]\n\t\t\tif (label) return label\n\t\t\treturn slug\n\t\t\t\t.split(/[-_]/)\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.map((w) => w.charAt(0).toUpperCase() + w.slice(1))\n\t\t\t\t.join(\" \")\n\t\t},\n\n\t\t/**\n\t\t * The lane the composer writes to; the log shows that lane's rows. It is\n\t\t * always one of this copy's channels: a copy told one channel writes on\n\t\t * it whatever was chosen before (S1).\n\t\t */\n\t\tlane: {\n\t\t\tget current() {\n\t\t\t\treturn channels && !channels.includes(lane) ? channels[0] : lane\n\t\t\t},\n\t\t\tset(next: string) {\n\t\t\t\tlane = next || \"main\"\n\t\t\t}\n\t\t},\n\n\t\t/** Whose ⋮ menu is open — one at a time across the log. */\n\t\tmenu: {\n\t\t\tget open() {\n\t\t\t\treturn menuFor\n\t\t\t},\n\t\t\tset(id: number | undefined) {\n\t\t\t\tmenuFor = id\n\t\t\t}\n\t\t},\n\n\t\t// ── selecting lines for a summary ────────────────────────────────────\n\t\tselect: {\n\t\t\tget active() {\n\t\t\t\treturn selecting\n\t\t\t},\n\t\t\tget ids() {\n\t\t\t\treturn selected\n\t\t\t},\n\t\t\tstart(subject?: Subject) {\n\t\t\t\tselecting = true\n\t\t\t\tselected.clear()\n\t\t\t\tif (subject) selected.add(subject.id)\n\t\t\t\tmenuFor = undefined\n\t\t\t},\n\t\t\tstop() {\n\t\t\t\tselecting = false\n\t\t\t\tselected.clear()\n\t\t\t},\n\t\t\ttoggle(subject: Subject) {\n\t\t\t\t// A line a scene already captured cannot join another.\n\t\t\t\tif (dossier?.scened.includes(subject.id)) return\n\t\t\t\tif (selected.has(subject.id)) selected.delete(subject.id)\n\t\t\t\telse selected.add(subject.id)\n\t\t\t},\n\t\t\tset(ids: number[]) {\n\t\t\t\tselected.clear()\n\t\t\t\tfor (const id of ids) selected.add(id)\n\t\t\t},\n\t\t\t/**\n\t\t\t * From a line toward one end, up to the nearest line already\n\t\t\t * selected — never through a line a scene has already captured.\n\t\t\t */\n\t\t\trange(index: number, toward: \"above\" | \"below\") {\n\t\t\t\t// The log's own rows: `index` counts the lines this copy draws.\n\t\t\t\tconst list = rows\n\t\t\t\tconst taken = new Set(dossier?.scened ?? [])\n\t\t\t\tconst step = toward === \"above\" ? -1 : 1\n\t\t\t\tfor (let i = index; i >= 0 && i < list.length; i += step) {\n\t\t\t\t\tconst id = list[i].id\n\t\t\t\t\tif (taken.has(id)) break\n\t\t\t\t\tif (selected.has(id) && i !== index) break\n\t\t\t\t\tselected.add(id)\n\t\t\t\t}\n\t\t\t},\n\t\t\t/**\n\t\t\t * Hand the selection to the host's summarizer. It stays until the host\n\t\t\t * says the summary finished (`summaryEnded`): a cancelled or failed\n\t\t\t * create keeps a hand-picked selection.\n\t\t\t */\n\t\t\tcommit(kind: \"scene\" | \"world\" | \"character\") {\n\t\t\t\tctx().request(\"summarize\", { kind, messageIds: [...selected] }).catch(warn(\"summarize\"))\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function setConversation(c: Conversation): Conversation {\n\treturn setContext(KEY, c)\n}\n\nexport function useConversation(): Conversation {\n\tconst c = getContext<Conversation | undefined>(KEY)\n\tif (!c) throw new Error(\"a conversation part rendered outside MessagesWidget\")\n\treturn c\n}\n\n/**\n * The widget's `t` for a part that may also render outside a widget (a\n * block view in a test): the English source there.\n */\nexport function useT(): (source: string) => string {\n\tconst w = useWidgetContext()\n\treturn (source) => w?.current.t?.(source) ?? source\n}\n","sessions/messages/mediaStrip.ts":"/**\n * The media strip's reading of a message (composer attachments plan §3.4):\n * which of its parts are files, in what order, and how each is addressed.\n * Pure, so the strip and its tests read one answer.\n *\n * A **media strip** is the square image tiles and file tiles below a\n * message's card (next-pass note 40, 2026-10-03) — `core:image` /\n * `core:file` parts, whoever wrote them (a person's attachment, a\n * pipeline's generated image). Not the character gallery, not\n * an image a block tree places (`messages.block-image` stays where its plugin\n * put it).\n */\nimport type { MessagePartV1 } from '@serene-pub/sdk/component'\n\n/** One image or file the strip shows. */\nexport interface MediaStripItem {\n\t/** The part's id — the key, and what a removal names. */\n\tpartId: number\n\tkind: 'image' | 'file'\n\t/** `files.id` — the part's `data.assetId`. */\n\tassetId: number\n\t/** What a reader is told: the part's alt, then its file's name. */\n\tlabel: string\n\t/** The file's name, when the part kept one. */\n\tname: string | null\n\twidth: number | null\n\theight: number | null\n\tmime: string | null\n\tbytes: number | null\n}\n\n/** How many image tiles show before the rest fold into a count tile. */\nexport const MEDIA_STRIP_MAX_TILES = 6\n\nconst text = (v: unknown): string | null => (typeof v === 'string' && v.trim() ? v.trim() : null)\nconst count = (v: unknown): number | null => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : null)\n\n/**\n * The message's files, steps ascending and each step's active revision only\n * (the swipe cursor, as `MessagePartsView` reads it), parts in ordinal order.\n * A part with no usable `assetId` is not a file anyone can fetch, so it is\n * left out rather than drawn broken.\n */\nexport function mediaStripItems(\n\tparts: readonly MessagePartV1[] | null | undefined,\n\tactiveRevisions: Record<string, number> | null | undefined,\n): MediaStripItem[] {\n\tif (!parts?.length) return []\n\tconst active = activeRevisions ?? {}\n\treturn parts\n\t\t.filter(\n\t\t\t(p) =>\n\t\t\t\t(p.type === 'core:image' || p.type === 'core:file') &&\n\t\t\t\tp.revision === (active[String(p.step)] ?? 0) &&\n\t\t\t\tcount((p.data as Record<string, unknown> | null)?.assetId) !== null,\n\t\t)\n\t\t.sort((a, b) => a.step - b.step || a.ordinal - b.ordinal)\n\t\t.map((p) => {\n\t\t\tconst d = (p.data ?? {}) as Record<string, unknown>\n\t\t\tconst kind = p.type === 'core:image' ? 'image' : 'file'\n\t\t\tconst name = text(d.filename) ?? text(d.name)\n\t\t\treturn {\n\t\t\t\tpartId: p.id,\n\t\t\t\tkind,\n\t\t\t\tassetId: d.assetId as number,\n\t\t\t\tlabel: text(d.alt) ?? name ?? (kind === 'image' ? 'Image' : 'File'),\n\t\t\t\tname,\n\t\t\t\twidth: count(d.width),\n\t\t\t\theight: count(d.height),\n\t\t\t\tmime: text(d.mime),\n\t\t\t\tbytes: count(d.bytes),\n\t\t\t}\n\t\t})\n}\n\n/** The address of one representation (`/media/{id}`, plus `?v=` for a derived one). */\nexport function mediaSrc(assetId: number, variant?: 'thumb' | 'fitted'): string {\n\treturn variant ? `/media/${assetId}?v=${variant}` : `/media/${assetId}`\n}\n\n/** A file's download address — the app's own, saved under its name. */\nexport function mediaDownloadHref(assetId: number): string {\n\treturn `/media/${assetId}?download=1`\n}\n\n/** A byte count for a file tile: `812 B`, `14 KB`, `3.2 MB`. */\nexport function formatBytes(bytes: number): string {\n\tif (bytes < 1024) return `${bytes} B`\n\tif (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`\n\treturn `${(bytes / (1024 * 1024)).toFixed(1)} MB`\n}\n\n/** The icon a file tile wears, by its type. */\nexport function fileIcon(mime: string | null): string {\n\tif (!mime) return 'file'\n\tif (mime.startsWith('text/') || mime === 'application/pdf') return 'file-text'\n\treturn 'file'\n}\n\n/**\n * The `view-image` request for opening image `index` of `images`: the image\n * itself, full size, and the message's other images as the lightbox's\n * gallery so it can page through them. Images the strip found missing are\n * not offered.\n */\nexport function viewImageParams(images: readonly MediaStripItem[], index: number) {\n\tconst srcs = images.map((i) => mediaSrc(i.assetId))\n\treturn {\n\t\tsrc: srcs[index],\n\t\tgallery: { srcs, index, captions: images.map((i) => i.label) },\n\t}\n}\n","sessions/messages/messages.ts":"/**\n * Core's `messages` component (C7): the conversation — the log, the field\n * you write into, and the strips beside it — as the page's UI worker runs\n * it. `npm run build` compiles it with the CLI's component bundler to\n * `dist/components/messages.js`, the module the app serves at\n * `/core-ui/messages`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport Messages from './Messages.svelte'\n\nexport default svelteComponent(Messages)\n","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"},"sourceHash":"690981d8959a0506e3ccf7ea45d01968b2a853b9a2e85dda88abcef3634a76cd","catalogVersion":"0.6.0-pr-1"}
|
|
1
|
+
{"slug":"messages","framework":"svelte","entry":"sessions/messages/messages.ts","files":{"sessions/messages/MessageBlocksView.svelte":"<script lang=\"ts\">\n\t/**\n\t * The block renderer (20 §6): plugin message content as data, drawn by\n\t * core's own components — themed, accessible, and with nothing to\n\t * sanitize, because no markup ever crosses the boundary.\n\t *\n\t * Interactivity is declared: a `choices` button or a `form` submit names a\n\t * function key, and `onAction` carries it (with the entered values as the\n\t * payload) up to the page, which fires `sessions:fireAction` with the\n\t * message as subject — the same audited path as every contributed button.\n\t * The block's `action` — the identity of the declaration it fires,\n\t * stamped by the outlet that wrote it (U5c review, W-E) — rides along\n\t * verbatim, so the server holds the press to THAT declaration's audience;\n\t * a block carrying none is fired as the legacy shape and gets the owner\n\t * floor. This view never invents one.\n\t *\n\t * A **form** (R-15 *Forms*; U5d) is a `choices` or `form` block with an\n\t * `addressee`: its `id` rides the press as `blockId`, so the server reads\n\t * the block off the row and holds the press to the addressee — the person\n\t * portraying them may answer, nobody else; when the AI portrays them the\n\t * answer pipeline already answered. A choice's `choice` key is the\n\t * payload. The question is shown above the options unless the message\n\t * body already says it (`bodyText`), which is how the narrator's Ask\n\t * reads: the question once, then the buttons.\n\t *\n\t * **Answered once** (U5d review, W7): a form the host has stamped\n\t * `answered` shows the answer in place of its buttons, greyed; a form\n\t * put to somebody the viewer does not portray shows no buttons at all —\n\t * `canAnswer` is the viewer's verdict, handed down from the page, which\n\t * mirrors the server's resolver (`utils/formAnswer.ts`). An affordance\n\t * only: the server refuses regardless.\n\t *\n\t * **Superseded** (plans/29 R-15 *Staleness and order*; U5f): a form the\n\t * channel has moved past — unanswered, and a newer message on its row's\n\t * channel than the `head` it was issued at — collapses to one quiet line,\n\t * no question and no buttons (the row's body already showed the question).\n\t * `isStale` is the verdict, handed down from the message\n\t * (`utils/formAnswer.ts` `staleOf`, the server's rule over the list the\n\t * client holds). Answered beats stale.\n\t *\n\t * Every drawing of a `choices` or `form` block carries its stamped id as\n\t * `data-block-id`: a notification's link lands on the form it names\n\t * (`?message=<id>&block=<blockId>`, the page's `messageLanding.ts`).\n\t */\n\timport MessageBlocksView from \"./MessageBlocksView.svelte\"\n\timport { useT } from \"./conversation.svelte\"\n\timport { answeredChoiceLabel, answeredOf } from \"@serene-pub/core-catalog/conversation\"\n\n\tconst t = useT()\n\n\tinterface Props {\n\t\tblocks: any[]\n\t\tonAction?: (\n\t\t\tfn: string,\n\t\t\tpayload?: Record<string, unknown>,\n\t\t\taction?: string,\n\t\t\tblockId?: string\n\t\t) => void\n\t\tdepth?: number\n\t\t/** The message body, so a form's question is not shown twice. */\n\t\tbodyText?: string\n\t\t/**\n\t\t * May the viewer answer a form put to this addressee? Absent, every\n\t\t * addressed form shows its buttons and the server judges the press.\n\t\t */\n\t\tcanAnswer?: (addressee: string | undefined) => boolean\n\t\t/**\n\t\t * Has the channel moved past this form (U5f)? Absent, no form is\n\t\t * drawn superseded and the server refuses a stale press.\n\t\t */\n\t\tisStale?: (block: { head?: unknown; answered?: unknown }) => boolean\n\t}\n\n\tlet { blocks, onAction, depth = 1, bodyText, canAnswer, isStale }: Props = $props()\n\n\t/** Whether the form is superseded — never when answered. */\n\tconst superseded = (b: { head?: unknown; answered?: unknown }): boolean =>\n\t\t!answeredOf(b) && !!isStale && isStale(b)\n\n\t/** The addressee, when the block has one. */\n\tconst addresseeOf = (b: { addressee?: unknown }): string | undefined =>\n\t\ttypeof b?.addressee === \"string\" && b.addressee ? b.addressee : undefined\n\n\t/** Whether this viewer's buttons show on the form. */\n\tconst mayAnswer = (b: { addressee?: unknown }): boolean =>\n\t\t!canAnswer || canAnswer(addresseeOf(b))\n\n\t/** A form's question, when the body does not already carry it. */\n\tconst caption = (b: { question?: unknown }): string | null => {\n\t\tif (typeof b?.question !== \"string\" || !b.question.trim()) return null\n\t\tconst q = b.question.trim()\n\t\treturn bodyText && bodyText.trim().includes(q) ? null : q\n\t}\n\n\t/** The block's id, when the host stamped one. */\n\tconst blockIdOf = (b: { id?: unknown }): string | undefined =>\n\t\ttypeof b?.id === \"string\" && b.id ? b.id : undefined\n\n\t/** Form drafts, keyed by block index within this view. */\n\tlet formDrafts = $state<Record<number, Record<string, unknown>>>({})\n\n\tfunction editField(i: number, key: string, value: unknown) {\n\t\tformDrafts[i] = { ...(formDrafts[i] ?? {}), [key]: value }\n\t}\n\n\tfunction submitForm(i: number, block: any) {\n\t\tif (!onAction) return\n\t\t// Declared defaults fill what the person didn't touch.\n\t\tconst values: Record<string, unknown> = {}\n\t\tfor (const [key, decl] of Object.entries(block.fields ?? {}) as any)\n\t\t\tif (decl?.default !== undefined) values[key] = decl.default\n\t\tObject.assign(values, formDrafts[i] ?? {})\n\t\tonAction(block.fn, values, identityOf(block), blockIdOf(block))\n\t}\n\n\t/** The block's stamped identity, when it carries a well-formed one. */\n\tconst identityOf = (b: { action?: unknown }): string | undefined =>\n\t\ttypeof b?.action === \"string\" && b.action ? b.action : undefined\n\n\tconst fieldLabel = (key: string, decl: any): string =>\n\t\ttypeof decl?.label === \"string\" ? decl.label : (decl?.label?.en ?? key)\n</script>\n\n<!-- The block tree's parts (`messages.block*`, STYLE-GUIDE §6.16): no look\n here; the default widget stylesheet draws them. `data-depth` is how deep\n in a group the view is (1: the part's own tree). -->\n<div data-widget-part=\"messages.blocks\" data-depth={depth}>\n\t{#each blocks as block, i}\n\t\t{#if block?.kind === \"md\"}\n\t\t\t<div data-widget-part=\"messages.block-markdown messages.prose\">\n\t\t\t\t<sp-message-body text={String(block.text ?? \"\")}></sp-message-body>\n\t\t\t</div>\n\t\t{:else if block?.kind === \"kv\"}\n\t\t\t<dl data-widget-part=\"messages.block-kv\">\n\t\t\t\t{#each block.rows ?? [] as row}\n\t\t\t\t\t<dt data-widget-part=\"messages.block-kv-label\">{row.label}</dt>\n\t\t\t\t\t<dd>{row.value}</dd>\n\t\t\t\t{/each}\n\t\t\t</dl>\n\t\t{:else if block?.kind === \"table\"}\n\t\t\t<div data-widget-part=\"messages.block-table-scroll\">\n\t\t\t\t<table data-widget-part=\"messages.block-table\">\n\t\t\t\t\t<thead>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t{#each block.columns ?? [] as col}\n\t\t\t\t\t\t\t\t<th>{col}</th>\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t{#each block.rows ?? [] as row}\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t{#each row as cell}\n\t\t\t\t\t\t\t\t\t<td>{cell}</td>\n\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t</div>\n\t\t{:else if block?.kind === \"stat\"}\n\t\t\t<div data-widget-part=\"messages.block-stat\">\n\t\t\t\t<div data-widget-part=\"messages.block-stat-head\">\n\t\t\t\t\t<span data-widget-part=\"messages.block-stat-label\">{block.label}</span>\n\t\t\t\t\t<span data-widget-part=\"messages.block-stat-value\">\n\t\t\t\t\t\t{block.value}{block.max != null ? ` / ${block.max}` : \"\"}\n\t\t\t\t\t</span>\n\t\t\t\t</div>\n\t\t\t\t{#if block.max}\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.block-stat-track meter\"\n\t\t\t\t\t\trole=\"meter\"\n\t\t\t\t\t\taria-label={block.label}\n\t\t\t\t\t\taria-valuenow={block.value}\n\t\t\t\t\t\taria-valuemin={0}\n\t\t\t\t\t\taria-valuemax={block.max}\n\t\t\t\t\t>\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tdata-widget-part=\"messages.block-stat-fill\"\n\t\t\t\t\t\t\tstyle=\"--sp-fill: {Math.max(\n\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\tMath.min(100, (block.value / block.max) * 100)\n\t\t\t\t\t\t\t)}%\"\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</div>\n\t\t{:else if block?.kind === \"image\" && block.assetId != null}\n\t\t\t<img\n\t\t\t\tdata-widget-part=\"messages.block-image\"\n\t\t\t\tsrc=\"/session-assets/{block.assetId}\"\n\t\t\t\talt={block.alt ?? \"attachment\"}\n\t\t\t/>\n\t\t{:else if block?.kind === \"choices\" && superseded(block)}\n\t\t\t<!-- Superseded (U5f): the conversation moved on; one quiet line, no buttons. -->\n\t\t\t<p\n\t\t\t\tdata-widget-part=\"messages.block-superseded\"\n\t\t\t\tdata-superseded=\"true\"\n\t\t\t\tdata-block-id={blockIdOf(block)}\n\t\t\t>\n\t\t\t\t<sp-icon name=\"history\" size=\"14\"></sp-icon>\n\t\t\t\t<span>{t(\"Superseded — the conversation moved on\")}</span>\n\t\t\t</p>\n\t\t{:else if block?.kind === \"choices\"}\n\t\t\t{@const answered = answeredOf(block)}\n\t\t\t<div\n\t\t\t\tdata-widget-part=\"messages.block-choices\"\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label={typeof block.question === \"string\" && block.question\n\t\t\t\t\t? block.question\n\t\t\t\t\t: t(\"Choices\")}\n\t\t\t\tdata-answered={answered ? \"true\" : undefined}\n\t\t\t\tdata-block-id={blockIdOf(block)}\n\t\t\t>\n\t\t\t\t{#if caption(block)}\n\t\t\t\t\t<p data-widget-part=\"messages.block-caption\">{caption(block)}</p>\n\t\t\t\t{/if}\n\t\t\t\t{#if answered}\n\t\t\t\t\t<!-- Answered once: the answer stands in for the buttons. -->\n\t\t\t\t\t<p data-widget-part=\"messages.block-answered\">\n\t\t\t\t\t\t<sp-icon name=\"check\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t<span data-widget-part=\"messages.block-answered-label\">{t(\"Answered\")}</span>\n\t\t\t\t\t\t{#if answeredChoiceLabel(block, answered)}\n\t\t\t\t\t\t\t<span>· {answeredChoiceLabel(block, answered)}</span>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</p>\n\t\t\t\t{:else if !mayAnswer(block)}\n\t\t\t\t\t<!-- Somebody else's to answer: no buttons for this viewer. -->\n\t\t\t\t\t<p data-widget-part=\"messages.block-awaiting\">{t(\"Awaiting an answer\")}</p>\n\t\t\t\t{:else}\n\t\t\t\t\t<div data-widget-part=\"messages.block-choice-list\">\n\t\t\t\t\t\t{#each block.actions ?? [] as action}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.block-choice\"\n\t\t\t\t\t\t\t\tdisabled={!onAction}\n\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\tonAction?.(\n\t\t\t\t\t\t\t\t\t\taction.fn,\n\t\t\t\t\t\t\t\t\t\ttypeof action.choice === \"string\"\n\t\t\t\t\t\t\t\t\t\t\t? { choice: action.choice }\n\t\t\t\t\t\t\t\t\t\t\t: {},\n\t\t\t\t\t\t\t\t\t\tidentityOf(action),\n\t\t\t\t\t\t\t\t\t\tblockIdOf(block)\n\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"play\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\t{action.label}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t</div>\n\t\t{:else if block?.kind === \"form\" && superseded(block)}\n\t\t\t<!-- Superseded (U5f): the conversation moved on; one quiet line, no buttons. -->\n\t\t\t<p\n\t\t\t\tdata-widget-part=\"messages.block-superseded\"\n\t\t\t\tdata-superseded=\"true\"\n\t\t\t\tdata-block-id={blockIdOf(block)}\n\t\t\t>\n\t\t\t\t<sp-icon name=\"history\" size=\"14\"></sp-icon>\n\t\t\t\t<span>{t(\"Superseded — the conversation moved on\")}</span>\n\t\t\t</p>\n\t\t{:else if block?.kind === \"form\" && answeredOf(block)}\n\t\t\t<div\n\t\t\t\tdata-widget-part=\"messages.block-form\"\n\t\t\t\tdata-answered=\"true\"\n\t\t\t\tdata-block-id={blockIdOf(block)}\n\t\t\t>\n\t\t\t\t{#if caption(block)}\n\t\t\t\t\t<p data-widget-part=\"messages.block-caption\">{caption(block)}</p>\n\t\t\t\t{/if}\n\t\t\t\t<p data-widget-part=\"messages.block-answered\">\n\t\t\t\t\t<sp-icon name=\"check\" size=\"14\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"messages.block-answered-label\">{t(\"Answered\")}</span>\n\t\t\t\t</p>\n\t\t\t</div>\n\t\t{:else if block?.kind === \"form\" && !mayAnswer(block)}\n\t\t\t<div data-widget-part=\"messages.block-form\" data-block-id={blockIdOf(block)}>\n\t\t\t\t{#if caption(block)}\n\t\t\t\t\t<p data-widget-part=\"messages.block-caption\">{caption(block)}</p>\n\t\t\t\t{/if}\n\t\t\t\t<p data-widget-part=\"messages.block-awaiting\">{t(\"Awaiting an answer\")}</p>\n\t\t\t</div>\n\t\t{:else if block?.kind === \"form\"}\n\t\t\t<div data-widget-part=\"messages.block-form\" data-block-id={blockIdOf(block)}>\n\t\t\t\t{#if caption(block)}\n\t\t\t\t\t<p data-widget-part=\"messages.block-caption\">{caption(block)}</p>\n\t\t\t\t{/if}\n\t\t\t\t{#each Object.entries(block.fields ?? {}) as [key, decl]}\n\t\t\t\t\t{@const d = decl as any}\n\t\t\t\t\t<label data-widget-part=\"messages.block-field\">\n\t\t\t\t\t\t<span data-widget-part=\"messages.block-field-label\">{fieldLabel(key, d)}</span>\n\t\t\t\t\t\t{#if d.type === \"boolean\"}\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\ttype=\"checkbox\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.block-checkbox\"\n\t\t\t\t\t\t\t\tchecked={!!(formDrafts[i]?.[key] ?? d.default)}\n\t\t\t\t\t\t\t\tonchange={(e) =>\n\t\t\t\t\t\t\t\t\teditField(i, key, e.currentTarget.checked)}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t{:else if d.type === \"enum\"}\n\t\t\t\t\t\t\t<sp-combobox\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.block-select\"\n\t\t\t\t\t\t\t\tlabel={key}\n\t\t\t\t\t\t\t\tvalue={String(formDrafts[i]?.[key] ?? d.default ?? \"\")}\n\t\t\t\t\t\t\t\tonchange={(e: CustomEvent<{ value: string }>) =>\n\t\t\t\t\t\t\t\t\teditField(i, key, e.detail.value)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{#each d.of ?? [] as opt}\n\t\t\t\t\t\t\t\t\t<sp-option value={opt}>{opt}</sp-option>\n\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t</sp-combobox>\n\t\t\t\t\t\t{:else if d.type === \"number\" || d.type === \"integer\"}\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.block-input\"\n\t\t\t\t\t\t\t\tstep={d.type === \"integer\" ? \"1\" : \"any\"}\n\t\t\t\t\t\t\t\tvalue={formDrafts[i]?.[key] ?? d.default ?? \"\"}\n\t\t\t\t\t\t\t\toninput={(e) => {\n\t\t\t\t\t\t\t\t\tconst n = Number(e.currentTarget.value)\n\t\t\t\t\t\t\t\t\teditField(\n\t\t\t\t\t\t\t\t\t\ti,\n\t\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\t\tNumber.isFinite(n) ? n : undefined\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.block-input\"\n\t\t\t\t\t\t\t\tvalue={String(\n\t\t\t\t\t\t\t\t\tformDrafts[i]?.[key] ?? d.default ?? \"\"\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\toninput={(e) =>\n\t\t\t\t\t\t\t\t\teditField(i, key, e.currentTarget.value)}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</label>\n\t\t\t\t{/each}\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"messages.block-submit\"\n\t\t\t\t\tdisabled={!onAction}\n\t\t\t\t\tonclick={() => submitForm(i, block)}\n\t\t\t\t>\n\t\t\t\t\t{block.label ?? \"Submit\"}\n\t\t\t\t</button>\n\t\t\t</div>\n\t\t{:else if block?.kind === \"group\" && Array.isArray(block.blocks) && depth < 3}\n\t\t\t<div\n\t\t\t\tdata-widget-part=\"messages.block-group\"\n\t\t\t\tdata-layout={block.layout === \"row\" ? \"row\" : \"column\"}\n\t\t\t>\n\t\t\t\t<MessageBlocksView\n\t\t\t\t\tblocks={block.blocks}\n\t\t\t\t\t{onAction}\n\t\t\t\t\t{bodyText}\n\t\t\t\t\t{canAnswer}\n\t\t\t\t\t{isStale}\n\t\t\t\t\tdepth={depth + 1}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t{/if}\n\t{/each}\n</div>\n","sessions/messages/MessageComposer.svelte":"<script lang=\"ts\">\n\timport type { Snippet } from \"svelte\"\n\timport { useWidgetContext } from \"../shared/context\"\n\n\tinterface Props {\n\t\tmarkdown: string\n\t\tleftControls?: Snippet\n\t\trightControls?: Snippet\n\t\textraTabs?: {\n\t\t\tvalue: string\n\t\t\ttitle: string\n\t\t\tcontrol: Snippet\n\t\t\tcontent: Snippet\n\t\t\t/** Stays as its own permanently visible tab on all screen sizes\n\t\t\t * instead of collapsing into the mobile \"More\" popover. */\n\t\t\talwaysVisible?: boolean\n\t\t}[]\n\t\tonSend: () => void\n\t\t/** Escape handler. Only kept from the field when provided, so a\n\t\t * composer where Escape means nothing leaves it to the page. */\n\t\tonCancel?: () => void\n\t\tplaceholder?: string\n\t\t/** `\"send\"` (default) is the session bar's behaviour: Enter submits on\n\t\t * desktop. `\"newline\"` is for editing existing prose, where a stray\n\t\t * Enter mid-paragraph committing the edit is a trap — there Enter\n\t\t * always inserts a newline and Ctrl/Cmd+Enter submits. */\n\t\tenterBehavior?: \"send\" | \"newline\"\n\t\t/** Focus the field and put the caret at the end on mount. */\n\t\tautofocus?: boolean\n\t\t/** A `composer: 'none'` mode (19 §2): no Compose/Preview tabs, no\n\t\t * input, no send — the extra tabs (triggers, lore, stats) are the\n\t\t * whole surface. */\n\t\thideCompose?: boolean\n\t}\n\tlet {\n\t\tmarkdown = $bindable(),\n\t\tleftControls,\n\t\trightControls,\n\t\textraTabs = $bindable(),\n\t\tonSend,\n\t\tonCancel,\n\t\tplaceholder = \"Type a message...\",\n\t\tenterBehavior = \"send\",\n\t\tautofocus = false,\n\t\thideCompose = false\n\t}: Props = $props()\n\n\tlet tabGroup: string = $state(\"compose\")\n\t// Without a compose tab the initial (and any stale) selection must land\n\t// on a tab that exists — the first extra tab is the surface's front page.\n\t$effect(() => {\n\t\tif (hideCompose && (tabGroup === \"compose\" || tabGroup === \"preview\")) {\n\t\t\ttabGroup = extraTabs?.[0]?.value ?? \"compose\"\n\t\t}\n\t})\n\t// On mobile, extraTabs collapse into a single \"More\" popover instead of\n\t// competing inline with Compose/Preview for a 375px-wide row — mirrors\n\t// the same overflow-into-a-menu pattern already used for per-message\n\t// controls (see SessionMessage.svelte's mobile controls popover).\n\tlet showMoreMenu = $state(false)\n\tlet collapsibleExtraTabs = $derived(\n\t\textraTabs?.filter((t) => !t.alwaysVisible) ?? []\n\t)\n\tlet activeExtraTab = $derived(\n\t\tcollapsibleExtraTabs.find((t) => t.value === tabGroup)\n\t)\n\t// Enter submits on desktop only; on touch it inserts a newline like any\n\t// other textarea. There is deliberately no on-screen hint for this — it was\n\t// permanent noise under every session, and gating it on \"only while typing\"\n\t// just traded that for a layout jump on the first keystroke.\n\t// The widget's box, not the window: a remote has no window to ask.\n\tconst widget = useWidgetContext()\n\tconst submitOnEnter = $derived(widget?.current.layout?.v1?.tier !== \"compact\")\n\n\t// The field is the page's (`sp-composer-field`): a remote hears no\n\t// keydown, so the keys this composer answers are named to the field,\n\t// which keeps them from itself and raises them as `key`. Escape cancels;\n\t// under `\"newline\"` Ctrl/Cmd+Enter submits — regardless of viewport:\n\t// unlike plain Enter, it isn't something a touch keyboard can emit by\n\t// accident — and Enter and Shift+Enter stay the field's newline. Under\n\t// `\"send\"` the field's own send key (Enter without Shift) submits.\n\tconst fieldKeys = $derived(\n\t\t[onCancel ? \"Escape\" : \"\", enterBehavior === \"newline\" ? \"Control+Enter Meta+Enter\" : \"\"]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\" \")\n\t)\n\n\tfunction handleFieldKey(e: CustomEvent<{ key: string; shift: boolean; ctrl?: boolean; meta?: boolean }>) {\n\t\tconst { key, ctrl, meta } = e.detail\n\t\tif (key === \"Escape\") onCancel?.()\n\t\telse if (key === \"Enter\" && (ctrl || meta)) onSend()\n\t}\n\n\t/**\n\t * The field holds `markdown` as the caller sets it (an edit's text,\n\t * copied in as editing starts). Only a value from OUTSIDE is written: a\n\t * write resets the page's field, so the text the person typed, heard\n\t * back through `markdown`, is never echoed onto what they type next.\n\t * The caret goes to the end as the field lands (`autofocus`, which the\n\t * page honours) rather than selecting all: this is an edit of existing\n\t * text, so a select-all means the first keystroke destroys the message.\n\t */\n\tconst heard = new WeakMap<EventTarget, string>()\n\tconst writeField = (el: HTMLElement) => {\n\t\tconst v = markdown ?? \"\"\n\t\tif (heard.get(el) === v) return\n\t\theard.set(el, v)\n\t\tel.removeAttribute(\"value\")\n\t\tel.setAttribute(\"value\", v)\n\t}\n\t/** What the person typed (or sent), from the field that raised it. */\n\tconst hear = (e: CustomEvent<{ value: string }>) => {\n\t\tif (e.target) heard.set(e.target, e.detail.value)\n\t\tmarkdown = e.detail.value\n\t}\n\n\t$effect(() => {\n\t\tconst fixed = new Set([\"compose\", \"preview\"])\n\t\tconst extra = new Set(extraTabs?.map((t) => t.value) ?? [])\n\t\tif (!fixed.has(tabGroup) && !extra.has(tabGroup)) {\n\t\t\ttabGroup = \"compose\"\n\t\t}\n\t})\n</script>\n\n<!-- `sp-tabs` (§3.5): the list is drawn from the `sp-tab`s; the panels may sit\n anywhere below, each finding its tabs. Its parts are `messages.edit-*`\n (STYLE-GUIDE §6.16): no look here; the default widget stylesheet draws\n them, the list and the triggers through the tabs' own part. A panel's\n field raises `change` too, so only the element's own counts as a tab\n change. -->\n<sp-tabs\n\tvalue={tabGroup}\n\tlabel=\"Message composer\"\n\tdata-widget-part=\"messages.edit-tabs\"\n\tonchange={(e: CustomEvent<{ value: string }>) => {\n\t\tif (e.target === e.currentTarget) tabGroup = e.detail.value\n\t}}\n>\n\t<!-- Every trigger carries its own `title` and `aria-label`. A tab strip that\n\t shows icons only while inactive has no text to name it, and a name put\n\t on a generic element inside the button is not exposed at all — it has to\n\t be on the button. -->\n\t\t<!-- One block per tab: an sp element seats each tab's content in its\n\t\t own trigger, and Svelte removes a block by walking its nodes as\n\t\t siblings — two tabs in one block would leave one behind. -->\n\t\t{#if !hideCompose}\n\t\t\t<sp-tab\n\t\t\t\tvalue=\"compose\"\n\t\t\t\tlabel=\"Compose\"\n\t\t\t\tdata-widget-part=\"messages.edit-tab\"\n\t\t\t>\n\t\t\t\t<span data-widget-part=\"messages.edit-tab-body\">\n\t\t\t\t\t<sp-icon name=\"pen\" size=\"0.75em\"></sp-icon>\n\t\t\t\t\t{#if tabGroup === \"compose\"}<span data-widget-part=\"messages.edit-tab-label\">\n\t\t\t\t\t\t\tCompose\n\t\t\t\t\t\t</span>{/if}\n\t\t\t\t</span>\n\t\t\t</sp-tab>\n\t\t{/if}\n\t\t{#if !hideCompose}\n\t\t\t<sp-tab\n\t\t\t\tvalue=\"preview\"\n\t\t\t\tlabel=\"Preview\"\n\t\t\t\tdata-widget-part=\"messages.edit-tab\"\n\t\t\t>\n\t\t\t\t<span data-widget-part=\"messages.edit-tab-body\">\n\t\t\t\t\t<sp-icon name=\"eye\" size=\"0.75em\"></sp-icon>\n\t\t\t\t\t{#if tabGroup === \"preview\"}<span data-widget-part=\"messages.edit-tab-label\">\n\t\t\t\t\t\t\tPreview\n\t\t\t\t\t\t</span>{/if}\n\t\t\t\t</span>\n\t\t\t</sp-tab>\n\t\t{/if}\n\t\t{#if extraTabs}\n\t\t\t{#each extraTabs as tab}\n\t\t\t\t<!-- A tab not `alwaysVisible` folds into the More menu in a narrow\n\t\t\t\t box (`data-collapsible`). -->\n\t\t\t\t<sp-tab\n\t\t\t\t\tvalue={tab.value}\n\t\t\t\t\tlabel={tab.title}\n\t\t\t\t\tdata-widget-part=\"messages.edit-tab\"\n\t\t\t\t\tdata-collapsible={tab.alwaysVisible ? undefined : \"\"}\n\t\t\t\t>\n\t\t\t\t\t<span data-widget-part=\"messages.edit-tab-body\">\n\t\t\t\t\t\t{@render tab.control?.()}\n\t\t\t\t\t\t{#if tabGroup === tab.value}<span data-widget-part=\"messages.edit-tab-label\">\n\t\t\t\t\t\t\t\t{tab.title}\n\t\t\t\t\t\t\t</span>{/if}\n\t\t\t\t\t</span>\n\t\t\t\t</sp-tab>\n\t\t\t{/each}\n\t\t\t{#if collapsibleExtraTabs.length > 0}\n\t\t\t\t<!-- `self-stretch` rather than any stated height: it makes this\n\t\t\t\t match whatever the real tab triggers work out to, at any\n\t\t\t\t font scale, with no number to keep in sync. Skeleton sizes\n\t\t\t\t those triggers itself (17.07px font, so their `2em` is\n\t\t\t\t 34.14px) and that isn't inherited here, so every attempt to\n\t\t\t\t restate the height in em/rem lands a couple of pixels off.\n\t\t\t\t What was here before: the button carried `min-h-[2em]` while\n\t\t\t\t `btn-sm` shrank its font to 14.9px, so the same `2em` came\n\t\t\t\t out 29.9px against the tabs' 34.1px — and `pt-[0.7em]` was a\n\t\t\t\t hand-tuned patch for the difference that still left the icon\n\t\t\t\t 2px below centre. -->\n\t\t\t\t<div slot=\"list-end\" data-widget-part=\"messages.edit-more-tabs\">\n\t\t\t\t\t<!-- `sp-popover` (§3.5): our button is the trigger, the card the panel. -->\n\t\t\t\t\t<sp-popover\n\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t\topen={showMoreMenu}\n\t\t\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => (showMoreMenu = e.detail.open)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<button slot=\"trigger\" type=\"button\" data-widget-part=\"messages.edit-more-tabs-button\"\n\t\t\t\t\t\t\tdata-active={activeExtraTab ? \"\" : undefined}\n\t\t\t\t\t\t\taria-label=\"More composer tabs\">\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.edit-more-tabs-body\">\n\t\t\t\t\t\t\t\t{#if activeExtraTab}\n\t\t\t\t\t\t\t\t\t{@render activeExtraTab.control?.()}\n\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.edit-more-tabs-label\">\n\t\t\t\t\t\t\t\t\t\t{activeExtraTab.title}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"0.9em\" data-widget-part=\"messages.edit-more-tabs-icon\"></sp-icon>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<div data-widget-part=\"messages.edit-more-tabs-panel\">\n\t\t\t\t\t\t\t\t\t<header data-widget-part=\"messages.edit-more-tabs-title\">\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"18\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t<p>More</p>\n\t\t\t\t\t\t\t\t\t</header>\n\t\t\t\t\t\t\t\t\t<article data-widget-part=\"messages.edit-more-tabs-list\">\n\t\t\t\t\t\t\t\t\t\t{#each collapsibleExtraTabs as tab}\n\t\t\t\t\t\t\t\t\t\t\t<button\n\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\tdata-widget-part=\"messages.edit-more-tabs-option\"\n\t\t\t\t\t\t\t\t\t\t\t\tdata-current={tabGroup === tab.value ? \"\" : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttabGroup = tab.value\n\t\t\t\t\t\t\t\t\t\t\t\t\tshowMoreMenu = false\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>\n\t\t\t\t\t\t\t\t\t\t\t\t{@render tab.control?.()}\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{tab.title}</span>\n\t\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t\t\t</article>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</sp-popover>\n\t\t\t\t</div>\n\t\t\t{/if}\n\t\t{/if}\n\t<!-- Spacing lives on the side groups as padding rather than as a `gap` on\n\t this row, and each group only renders when it actually has something in\n\t it. With a gap, the wrapper was always a flex item even when its\n\t contents were hidden — the avatar is `max-lg:hidden`, so on mobile a\n\t zero-width group still bought a full 16px of dead space at the left\n\t edge, and the edit composer (which passes neither snippet) paid it\n\t twice. This way an absent group costs nothing. -->\n\t<div data-widget-part=\"messages.edit-row\">\n\t\t<!-- A column only exists when it has something to show. Reserving the\n\t\t slots on tabs that render neither avatar nor send button left an\n\t\t empty 48px band down the side of every extra tab; the panes below\n\t\t are full-width content and should use the whole row. -->\n\t\t{#if leftControls && (tabGroup === \"compose\" || tabGroup === \"preview\")}\n\t\t\t<div role=\"group\" aria-label=\"Message controls\" data-widget-part=\"messages.edit-left\">\n\t\t\t\t{@render leftControls()}\n\t\t\t</div>\n\t\t{/if}\n\t\t<div data-widget-part=\"messages.edit-panels\">\n\t\t\t{#if !hideCompose}\n\t\t\t\t<sp-tab-panel value=\"compose\">\n\t\t\t\t\t<!-- The field inside takes focus and carries the name and ARIA: this is\n\t\t\t\t\t its host element; the field itself is its child `textarea`. -->\n\t\t\t\t\t<sp-composer-field\n\t\t\t\t\t\tdata-widget-part=\"messages.edit-field\"\n\t\t\t\t\t\trows=\"1\"\n\t\t\t\t\t\tlabel=\"Type your message here\"\n\t\t\t\t\t\t{placeholder}\n\t\t\t\t\t\tsubmit-on={enterBehavior === \"send\" && submitOnEnter ? \"enter\" : \"none\"}\n\t\t\t\t\t\tkeys={fieldKeys}\n\t\t\t\t\t\tspellcheck=\"true\"\n\t\t\t\t\t\tautofocus={autofocus || undefined}\n\t\t\t\t\t\toninput={hear}\n\t\t\t\t\t\tonsubmit={(e: CustomEvent<{ value: string }>) => {\n\t\t\t\t\t\t\thear(e)\n\t\t\t\t\t\t\tonSend()\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonkey={handleFieldKey}\n\t\t\t\t\t\t{@attach writeField}\n\t\t\t\t\t></sp-composer-field>\n\t\t\t\t</sp-tab-panel>\n\t\t\t{/if}\n\t\t\t{#if !hideCompose}\n\t\t\t\t<sp-tab-panel value=\"preview\">\n\t\t\t\t\t<!-- Sized to land on the same row height as the compose tab so\n\t\t\t\t switching between them doesn't resize the bar. On mobile the\n\t\t\t\t compose row is set by the 48px send button (taller than the\n\t\t\t\t now single-line textarea), so the preview matches at 3rem; on\n\t\t\t\t lg it's set by the 4em avatar, so the preview matches that.\n\t\t\t\t `mb-[1em]` used to hang off the bottom here, which is what\n\t\t\t\t made preview 4px taller than compose. -->\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.edit-preview\"\n\t\t\t\t\t\trole=\"region\"\n\t\t\t\t\t\taria-label=\"Message preview\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<div data-widget-part=\"messages.edit-preview-body\">\n\t\t\t\t\t\t\t<sp-message-body text={markdown}></sp-message-body>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</sp-tab-panel>\n\t\t\t{/if}\n\t\t\t{#if extraTabs}\n\t\t\t\t{#each extraTabs as tab}\n\t\t\t\t\t<sp-tab-panel value={tab.value}>\n\t\t\t\t\t\t<div role=\"region\" aria-label=\"{tab.title} content\">\n\t\t\t\t\t\t\t{@render tab.content?.()}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</sp-tab-panel>\n\t\t\t\t{/each}\n\t\t\t{/if}\n\t\t</div>\n\t\t{#if rightControls && tabGroup === \"compose\"}\n\t\t\t<div\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label=\"Send controls\"\n\t\t\t\tdata-widget-part=\"messages.edit-right\"\n\t\t\t>\n\t\t\t\t{@render rightControls()}\n\t\t\t</div>\n\t\t{/if}\n\t</div>\n</sp-tabs>\n","sessions/messages/MessageControls.svelte":"<script lang=\"ts\">\n\timport {\n\t\tcoreVerbState,\n\t\tverbKeyOf,\n\t\tverdictOf,\n\t\ttype VerbContext\n\t} from \"@serene-pub/core-catalog/conversation\"\n\timport { actionIdentity } from \"@serene-pub/sdk/component\"\n\timport { useConversation } from \"./conversation.svelte\"\n\timport type { MessageV1, WidgetAction } from \"@serene-pub/sdk/component\"\n\n\t/**\n\t * A message's ⋮ menu: every verb the session offers on it, named in words.\n\t * Everything else — whose menu is open, what the viewer controls, the\n\t * session's list, why Extend is refused — is the conversation's\n\t * (`useConversation`), and every press is one of its verbs (C0b).\n\t */\n\tinterface Props {\n\t\tmsg: MessageV1\n\t\tisLastMessage?: boolean\n\t}\n\n\tlet { msg, isLastMessage = false }: Props = $props()\n\n\tconst conv = useConversation()\n\tconst open = $derived(conv.menu.open === msg.id)\n\tconst onOpenChange = (next: boolean) => conv.menu.set(next ? msg.id : undefined)\n\tconst canControl = $derived(conv.line(msg.id).controllable)\n\tconst extendRefusal = $derived(conv.dossier?.extendRefusal)\n\tconst hasGeneratingMessage = $derived(\n\t\t(conv.ctx.messages.v1 as Array<{ isGenerating?: boolean }>).some((m) => m.isGenerating)\n\t)\n\tconst messageActions = $derived(\n\t\tconv.ctx.actions?.v1?.message as\n\t\t\t| { primary: WidgetAction[]; overflow: WidgetAction[] }\n\t\t\t| undefined\n\t)\n\tconst isAdmin = $derived(conv.ctx.viewer.v1.isAdmin)\n\n\tfunction closeMenu() {\n\t\tonOpenChange(false)\n\t}\n\n\t/**\n\t * **Change sprite** (DESIGN-sprites §6): a character's settled line, and a\n\t * person who may act on it. The picker is the host's (`change-sprite`\n\t * request, C0b): it loads the sprites and sends the pick itself.\n\t */\n\tlet canChangeSprite = $derived(\n\t\tcanControl &&\n\t\t\t!!msg.characterId &&\n\t\t\t!msg.isNarratorResponse &&\n\t\t\t!msg.isGenerating\n\t)\n\n\t/**\n\t * The floors, for a mount with no list: stop, edit and branch are present\n\t * in every genre, and a server too old to send the list still offers them.\n\t */\n\tconst FLOORS: WidgetAction[] = [\n\t\t{ key: \"stop\", name: \"Stop generating\", icon: \"square\", quick: true },\n\t\t{ key: \"edit\", name: \"Edit\", icon: \"pencil\", quick: true },\n\t\t{ key: \"branch\", name: \"Branch from here\", icon: \"git-branch\", quick: false }\n\t].map((a) => ({\n\t\t...a,\n\t\tspecSlug: \"core\",\n\t\tslash: a.key,\n\t\taudience: { see: [\"participant\"], act: [\"item\"] },\n\t\tvenue: \"message\",\n\t\torigin: \"core\" as const,\n\t\tfloor: true,\n\t\tcanAct: true,\n\t\titemGated: a.key !== \"branch\",\n\t\tisNew: false,\n\t\tenabled: true\n\t}))\n\n\t/** The whole list, primary first — the menu is the complete list. */\n\tconst listed = $derived(\n\t\tmessageActions\n\t\t\t? [...messageActions.primary, ...messageActions.overflow]\n\t\t\t: FLOORS\n\t)\n\n\t/** This message's state, for the verb table. */\n\tconst verbCtx = $derived<\n\t\tOmit<VerbContext, \"canAct\" | \"itemGated\" | \"action\" | \"enabled\" | \"reason\" | \"itemPredicates\">\n\t>({\n\t\tmsg,\n\t\tisLastMessage,\n\t\tediting: conv.edit.id !== null,\n\t\thasGeneratingMessage,\n\t\tcanControl,\n\t\textendRefusal\n\t})\n\t// `itemGated` rides with `canAct` (W6): a contributed action whose\n\t// audience is `item` was answered `true` ahead of any message, and this\n\t// message's ownership rule is what decides. The enabled-when verdict\n\t// rides beside them (U5e): the list's `enabled`/`reason`, and the\n\t// `item.*` predicates this row is judged against.\n\tconst stateOf = (a: WidgetAction) =>\n\t\tcoreVerbState(verbKeyOf(a), { ...verbCtx, ...verdictOf(a) })\n\n\t/** The rows the menu draws: shown by the table, core's before contributed. */\n\tconst rows = $derived(\n\t\tlisted\n\t\t\t.map((a) => ({ action: a, state: stateOf(a) }))\n\t\t\t.filter((r) => r.state.shown)\n\t)\n\tconst coreRows = $derived(rows.filter((r) => r.action.specSlug === \"core\"))\n\tconst contributedRows = $derived(\n\t\trows.filter((r) => r.action.specSlug !== \"core\")\n\t)\n\tconst hasNew = $derived(contributedRows.some((r) => r.action.isNew))\n\n\t/** Fire a core verb by its key: the conversation's verb, or its own edit. */\n\tfunction fireCore(_e: Event, key: string) {\n\t\tcloseMenu()\n\t\tif (key === \"edit\") return conv.edit.start(msg)\n\t\tif (key === \"swipe\") return conv.swipe(msg, \"right\")\n\t\tconv.invoke(key, msg)\n\t}\n\n\t/** The row's name: the verb, with hide's read off the message's state. */\n\tfunction nameOf(a: WidgetAction) {\n\t\treturn a.key === \"hide\" && a.specSlug === \"core\"\n\t\t\t? msg.isHidden\n\t\t\t\t? \"Unhide\"\n\t\t\t\t: \"Hide\"\n\t\t\t: a.name\n\t}\n\t/**\n\t * The tooltip for one row, the chips' shape: the name, then the reason\n\t * when it is grey (UI nit 2). The reason also reaches assistive tech\n\t * through `aria-describedby` → an sr-only note, so the accessible NAME\n\t * stays the verb — a name that also carries the reason is read twice.\n\t */\n\tconst titleOf = (a: WidgetAction, reason?: string) =>\n\t\treason\n\t\t\t? `${nameOf(a)} — ${reason}`\n\t\t\t: a.description\n\t\t\t\t? `${nameOf(a)} — ${a.description}`\n\t\t\t\t: nameOf(a)\n\t/** One note id per row; the identity's punctuation is not an id's. */\n\tconst noteIdOf = (a: WidgetAction) =>\n\t\t`msg-${msg.id}-note-${actionIdentity(a).replace(/[^a-z0-9-]/g, \"-\")}`\n\n\t/**\n\t * \"Inspect run\" (R55: administrators only): the host finds the run that\n\t * wrote this reply and opens the inspector (`inspect-run`), or says there\n\t * is none.\n\t */\n\tconst isReply = $derived(!!msg.characterId || !!msg.isNarratorResponse)\n\n\t/**\n\t * The mark clears the moment the menu that lists the newcomers opens:\n\t * the person has now met them.\n\t */\n\t$effect(() => {\n\t\tif (!open || !hasNew) return\n\t\tvoid conv.request(\"actions-seen\", {\n\t\t\tkeys: contributedRows.filter((r) => r.action.isNew).map((r) => actionIdentity(r.action))\n\t\t})\n\t})\n</script>\n\n<!-- The ⋮ menu: every action this message offers, named in words. The row's\n quick icons call the same handlers; this is the complete list. Its parts\n are `messages.message-options*` (STYLE-GUIDE §6.16): no look here. -->\n<div data-widget-part=\"messages.message-options\">\n\t<!-- `sp-popover` (§3.5): the host's positioned panel. The trigger slot is\n\t our own button; the body is the panel. -->\n\t<sp-popover\n\t\tplacement=\"bottom-end\"\n\t\tlabel=\"Message options\"\n\t\t{open}\n\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => onOpenChange(e.detail.open)}\n\t>\n\t\t<button slot=\"trigger\" type=\"button\" data-widget-part=\"messages.message-options-button messages.message-icon-button\" aria-label=\"Message options\">\n\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"16\"></sp-icon>\n\t\t</button>\n\t\t\t\t<div data-widget-part=\"messages.message-options-panel\">\n\t\t\t\t\t<header data-widget-part=\"messages.message-options-title\">\n\t\t\t\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"18\"></sp-icon>\n\t\t\t\t\t\t<p>Message options</p>\n\t\t\t\t\t</header>\n\t\t\t\t\t<article data-widget-part=\"messages.message-options-list\">\n\t\t\t\t\t\t<!-- Core's verbs, from the list (R-15, U5c): every one\n\t\t\t\t\t\t the session offers on this message, primary set\n\t\t\t\t\t\t first, then the overflow — nothing is reachable\n\t\t\t\t\t\t only by hovering. Disabled and explained rather\n\t\t\t\t\t\t than hidden where the message's own state says no. -->\n\t\t\t\t\t\t<!-- Greyed, not disabled, like the chips (S6): `aria-disabled`\n\t\t\t\t\t\t keeps the row reachable and the reason reaches a screen\n\t\t\t\t\t\t reader through `aria-describedby`; a native `disabled`\n\t\t\t\t\t\t is skipped and says nothing. The click is guarded. -->\n\t\t\t\t\t\t{#each coreRows as { action, state } (action.key)}\n\t\t\t\t\t\t\t{@const iconName = action.icon || \"play\"}\n\t\t\t\t\t\t\t<!-- Which core verb (`data-verb`: the sheet sets Delete and\n\t\t\t\t\t\t\t Stop in the error's tone); Hide while the line is hidden\n\t\t\t\t\t\t\t is its `aria-pressed`, a row the line refuses its\n\t\t\t\t\t\t\t `aria-disabled`. -->\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\tdata-verb={action.key}\n\t\t\t\t\t\t\t\ttitle={titleOf(action, state.reason)}\n\t\t\t\t\t\t\t\taria-pressed={action.key === \"hide\"\n\t\t\t\t\t\t\t\t\t? !!msg.isHidden\n\t\t\t\t\t\t\t\t\t: undefined}\n\t\t\t\t\t\t\t\taria-disabled={state.disabled}\n\t\t\t\t\t\t\t\taria-describedby={state.reason\n\t\t\t\t\t\t\t\t\t? noteIdOf(action)\n\t\t\t\t\t\t\t\t\t: undefined}\n\t\t\t\t\t\t\t\tonclick={(e) =>\n\t\t\t\t\t\t\t\t\tstate.disabled\n\t\t\t\t\t\t\t\t\t\t? e.preventDefault()\n\t\t\t\t\t\t\t\t\t\t: fireCore(e, action.key)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name={iconName} size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>{nameOf(action)}</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t{#if state.reason}\n\t\t\t\t\t\t\t\t<span id={noteIdOf(action)} data-widget-part=\"messages.message-option-note\">\n\t\t\t\t\t\t\t\t\t{state.reason}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t{#if conv.dossier?.writes.lore && !msg.isGenerating}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\ttitle=\"Select for summary\"\n\t\t\t\t\t\t\t\taria-label=\"Select this message for summarization\"\n\t\t\t\t\t\t\t\tdisabled={conv.edit.id !== null || hasGeneratingMessage}\n\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\tcloseMenu()\n\t\t\t\t\t\t\t\t\tconv.select.start(msg)\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"book-marked\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Select for summary</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if canChangeSprite}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\ttitle=\"Choose the face this line shows\"\n\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\tcloseMenu()\n\t\t\t\t\t\t\t\t\tvoid conv.request(\"change-sprite\", { messageId: msg.id })\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"drama\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Change sprite</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if isAdmin && isReply && !msg.isGenerating}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\ttitle=\"See what the pipeline did for this reply\"\n\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\tcloseMenu()\n\t\t\t\t\t\t\t\t\tvoid conv.request(\"inspect-run\", { messageId: msg.id })\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"receipt\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Inspect run</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if conv.dossier?.debugPrompts && conv.line(msg.id).promptDetails && !msg.isGenerating}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\ttitle=\"Prompt details\"\n\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\tcloseMenu()\n\t\t\t\t\t\t\t\t\tvoid conv.request(\"prompt-details\", { messageId: msg.id })\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"info\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Prompt details</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if contributedRows.length}\n\t\t\t\t\t\t\t<!-- The contributed entries (19 §4): after core's\n\t\t\t\t\t\t\t verbs, separated so a plugin's never reads as\n\t\t\t\t\t\t\t one of core's. A newcomer wears its mark until\n\t\t\t\t\t\t\t this menu has been opened once. -->\n\t\t\t\t\t\t\t<hr data-widget-part=\"messages.message-options-divider\" />\n\t\t\t\t\t\t\t{#each contributedRows as { action, state } (actionIdentity(action))}\n\t\t\t\t\t\t\t\t{@const iconName = action.icon || \"play\"}\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-option\"\n\t\t\t\t\t\t\t\t\ttitle={titleOf(action, state.reason)}\n\t\t\t\t\t\t\t\t\taria-disabled={state.disabled}\n\t\t\t\t\t\t\t\t\taria-describedby={state.reason\n\t\t\t\t\t\t\t\t\t\t? noteIdOf(action)\n\t\t\t\t\t\t\t\t\t\t: undefined}\n\t\t\t\t\t\t\t\t\tonclick={(e) => {\n\t\t\t\t\t\t\t\t\t\tif (state.disabled) {\n\t\t\t\t\t\t\t\t\t\t\te.preventDefault()\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tcloseMenu()\n\t\t\t\t\t\t\t\t\t\tconv.invoke(actionIdentity(action), msg)\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name={iconName} size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t\t<span>{action.name}</span>\n\t\t\t\t\t\t\t\t\t{#if action.isNew}\n\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.message-option-new\" aria-label=\"New\">\n\t\t\t\t\t\t\t\t\t\t\tNew\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\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{#if state.reason}\n\t\t\t\t\t\t\t\t\t<span id={noteIdOf(action)} data-widget-part=\"messages.message-option-note\">\n\t\t\t\t\t\t\t\t\t\t{state.reason}\n\t\t\t\t\t\t\t\t\t</span>\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</article>\n\t\t\t\t</div>\n\t</sp-popover>\n</div>\n\n","sessions/messages/MessageMediaStrip.svelte":"<script lang=\"ts\">\n\t/**\n\t * The media strip (composer attachments plan §3.4; next-pass note 40,\n\t * 2026-10-03): a message's images and files as a row of square tiles\n\t * BELOW the message's card — never inside it — in every state of the row:\n\t * settled, legacy text, editing and generating alike. `SessionMessage`\n\t * mounts it as its own cell of the message grid, under the content.\n\t *\n\t * - every image, one or many, is a square **tile**: the `thumb` variant\n\t * cropped to fill the square, the same size each; past\n\t * `MEDIA_STRIP_MAX_TILES` the rest fold into a count tile that opens\n\t * the lightbox where the tiles stop;\n\t * - a file is a square **file tile**: its kind's icon, its name, its size\n\t * when known, and a download link.\n\t *\n\t * Every tile is a button (keyboard-reachable, named \"Open image cat.png,\n\t * 1 of 3\") that asks the page for its lightbox through `onOpen`. An image\n\t * whose file is gone (deleted from the Media panel) raises `error` and is\n\t * drawn as \"File no longer available\" — never a broken image — and leaves\n\t * the lightbox's gallery.\n\t *\n\t * No look here: every element is a widget part (`messages.media-*`,\n\t * STYLE-GUIDE §6.16, §6.18), drawn by the default widget stylesheet.\n\t */\n\timport { SvelteSet } from 'svelte/reactivity'\n\timport {\n\t\tfileIcon,\n\t\tformatBytes,\n\t\tmediaDownloadHref,\n\t\tmediaSrc,\n\t\tMEDIA_STRIP_MAX_TILES,\n\t\ttype MediaStripItem,\n\t} from './mediaStrip'\n\n\tinterface Props {\n\t\titems: MediaStripItem[]\n\t\t/** Open image `index` of `images` (the strip's available images) in the lightbox. */\n\t\tonOpen?: (images: MediaStripItem[], index: number) => void\n\t\t/** The row is being edited: a tile may be taken off (D9, remove only). */\n\t\tediting?: boolean\n\t\t/**\n\t\t * Take one attachment off the message. Absent, no ✕ is drawn — the\n\t\t * host has no removal to offer yet — and absent too for a viewer who\n\t\t * does not control the row.\n\t\t */\n\t\tonRemove?: (item: MediaStripItem) => void\n\t}\n\n\tlet { items, onOpen, editing = false, onRemove }: Props = $props()\n\n\t/** Images whose file failed to load, by part id. */\n\tconst missing = new SvelteSet<number>()\n\n\tconst images = $derived(items.filter((i) => i.kind === 'image'))\n\tconst files = $derived(items.filter((i) => i.kind === 'file'))\n\t/** What the lightbox can page through: every image still there. */\n\tconst openable = $derived(images.filter((i) => !missing.has(i.partId)))\n\tconst folds = $derived(images.length > MEDIA_STRIP_MAX_TILES)\n\t/** With a count tile, the tiles leave its place: one fewer than the cap. */\n\tconst shown = $derived(folds ? images.slice(0, MEDIA_STRIP_MAX_TILES - 1) : images)\n\tconst hidden = $derived(images.length - shown.length)\n\tconst removable = $derived(editing && !!onRemove)\n\n\tfunction open(item: MediaStripItem) {\n\t\tconst index = openable.findIndex((i) => i.partId === item.partId)\n\t\tif (index >= 0) onOpen?.(openable, index)\n\t}\n\n\tfunction openFolded() {\n\t\t// The first image the tiles left out that is still there.\n\t\tconst first = images.slice(shown.length).find((i) => !missing.has(i.partId))\n\t\tif (first) open(first)\n\t}\n\n\t/** \"Open image cat.png, 2 of 3\" — the position among what the lightbox shows. */\n\tfunction openLabel(item: MediaStripItem): string {\n\t\tconst at = openable.findIndex((i) => i.partId === item.partId)\n\t\treturn openable.length > 1\n\t\t\t? `Open image ${item.label}, ${at + 1} of ${openable.length}`\n\t\t\t: `Open image ${item.label}`\n\t}\n</script>\n\n{#snippet removeButton(item: MediaStripItem)}\n\t{#if removable}\n\t\t<button\n\t\t\ttype=\"button\"\n\t\t\tdata-widget-part=\"messages.media-remove\"\n\t\t\taria-label=\"Remove {item.label}\"\n\t\t\ttitle=\"Remove {item.label}\"\n\t\t\tonclick={() => onRemove?.(item)}\n\t\t>\n\t\t\t<sp-icon name=\"x\" size=\"14\"></sp-icon>\n\t\t</button>\n\t{/if}\n{/snippet}\n\n{#snippet gone(item: MediaStripItem)}\n\t<div data-widget-part=\"messages.media-missing\" role=\"img\" aria-label=\"{item.label}: file no longer available\">\n\t\t<sp-icon name=\"image-off\" size=\"20\"></sp-icon>\n\t\t<span data-widget-part=\"messages.media-missing-text\">File no longer available</span>\n\t</div>\n{/snippet}\n\n{#if items.length}\n\t<div\n\t\tdata-widget-part=\"messages.media-strip\"\n\t\tdata-editing={removable ? '' : undefined}\n\t\trole=\"group\"\n\t\taria-label={items.length === 1 ? 'Attachment' : `${items.length} attachments`}\n\t>\n\t\t{#if images.length}\n\t\t\t<div data-widget-part=\"messages.media-images\">\n\t\t\t\t{#each shown as item (item.partId)}\n\t\t\t\t\t<div data-widget-part=\"messages.media-item\">\n\t\t\t\t\t\t{#if missing.has(item.partId)}\n\t\t\t\t\t\t\t{@render gone(item)}\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.media-tile\"\n\t\t\t\t\t\t\t\taria-label={openLabel(item)}\n\t\t\t\t\t\t\t\tonclick={() => open(item)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.media-tile-img\"\n\t\t\t\t\t\t\t\t\tsrc={mediaSrc(item.assetId, 'thumb')}\n\t\t\t\t\t\t\t\t\talt={item.label}\n\t\t\t\t\t\t\t\t\tloading=\"lazy\"\n\t\t\t\t\t\t\t\t\tdecoding=\"async\"\n\t\t\t\t\t\t\t\t\tonerror={() => missing.add(item.partId)}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{@render removeButton(item)}\n\t\t\t\t\t</div>\n\t\t\t\t{/each}\n\t\t\t\t{#if folds}\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tdata-widget-part=\"messages.media-more\"\n\t\t\t\t\t\taria-label=\"Show {hidden} more {hidden === 1 ? 'image' : 'images'}\"\n\t\t\t\t\t\tonclick={openFolded}\n\t\t\t\t\t>\n\t\t\t\t\t\t+{hidden}\n\t\t\t\t\t</button>\n\t\t\t\t{/if}\n\t\t\t</div>\n\t\t{/if}\n\t\t{#if files.length}\n\t\t\t<ul data-widget-part=\"messages.media-files\">\n\t\t\t\t{#each files as item (item.partId)}\n\t\t\t\t\t<li data-widget-part=\"messages.media-item\">\n\t\t\t\t\t\t<a\n\t\t\t\t\t\t\tdata-widget-part=\"messages.media-file\"\n\t\t\t\t\t\t\thref={mediaDownloadHref(item.assetId)}\n\t\t\t\t\t\t\tdownload={item.name ?? undefined}\n\t\t\t\t\t\t\ttitle={item.label}\n\t\t\t\t\t\t\taria-label=\"Download {item.label}{item.bytes ? `, ${formatBytes(item.bytes)}` : ''}\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name={fileIcon(item.mime)} size=\"20\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.media-file-name\">{item.label}</span>\n\t\t\t\t\t\t\t{#if item.bytes}\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.media-file-size\">{formatBytes(item.bytes)}</span>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t<sp-icon name=\"download\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t\t{@render removeButton(item)}\n\t\t\t\t\t</li>\n\t\t\t\t{/each}\n\t\t\t</ul>\n\t\t{/if}\n\t</div>\n{/if}\n","sessions/messages/MessagePartsView.svelte":"<script lang=\"ts\">\n\t/**\n\t * The parts-native message body (20 §2, phase 2 of §13).\n\t *\n\t * Renders a message's typed parts: steps ascending (they accumulate — a\n\t * stepped activity's phases stand side by side), each step showing only\n\t * its active revision (`activeRevisions`, the swipe cursor), parts in\n\t * their own ordinal order.\n\t *\n\t * Types: markdown is the body; reasoning and sections are collapsibles —\n\t * the generalization that retires the two hardcoded blocks in\n\t * SessionMessage. A reply's **folded sections** (B4; D5, 2026-09-27) are\n\t * `core:section` parts: collapsed by default, laid out by the host above\n\t * the reasoning and the body, and a section with `items` draws them as a\n\t * list — never as JSON. An unknown namespaced type (its plugin is gone, or not\n\t * yet installed) renders as a collapsed labeled section rather than\n\t * breaking: uninstalling strands nothing. `core:image` / `core:file` parts\n\t * are not drawn here: the media strip under the body shows them\n\t * (composer attachments plan §3.4).\n\t */\n\timport MessageBlocksView from \"./MessageBlocksView.svelte\"\n\timport type { MessagePartV1 } from \"@serene-pub/sdk/component\"\n\n\tinterface Props {\n\t\tmessageId: number\n\t\tparts: MessagePartV1[]\n\t\tactiveRevisions: Record<string, number>\n\t\t/** An image in the message was clicked — its address. */\n\t\tonOpenImage?: (src: string) => void\n\t\t/** Declared block actions (20 §6) — fn + payload up to the page; a form's `blockId` rides along (U5d). */\n\t\tonAction?: (\n\t\t\tfn: string,\n\t\t\tpayload?: Record<string, unknown>,\n\t\t\taction?: string,\n\t\t\tblockId?: string\n\t\t) => void\n\t\t/** The message body, so a form's question is not shown twice. */\n\t\tbodyText?: string\n\t\t/** The viewer's verdict on a form's addressee (U5d review, W7) — see `MessageBlocksView`. */\n\t\tcanAnswer?: (addressee: string | undefined) => boolean\n\t\t/** Whether the channel has moved past a form (U5f) — see `MessageBlocksView`. */\n\t\tisStale?: (block: { head?: unknown; answered?: unknown }) => boolean\n\t}\n\n\tlet {\n\t\tmessageId,\n\t\tparts,\n\t\tactiveRevisions,\n\t\tonOpenImage,\n\t\tonAction,\n\t\tbodyText,\n\t\tcanAnswer,\n\t\tisStale\n\t}: Props = $props()\n\n\t/** Expanded state per collapsible, keyed by part id. Default collapsed. */\n\tlet expanded = $state<Record<number, boolean>>({})\n\n\tconst steps = $derived(\n\t\t[...new Set(parts.map((p) => p.step))].sort((a, b) => a - b)\n\t)\n\n\tfunction visibleParts(step: number): MessagePartV1[] {\n\t\tconst active = activeRevisions[String(step)] ?? 0\n\t\treturn parts\n\t\t\t.filter((p) => p.step === step && p.revision === active)\n\t\t\t.sort((a, b) => a.ordinal - b.ordinal)\n\t}\n\n\tfunction sectionTitle(part: MessagePartV1): string {\n\t\tconst t = (part.data as any)?.title\n\t\tif (typeof t === \"string\" && t) return t\n\t\treturn \"Section\"\n\t}\n\n\t/** A folded section's list, when it is one — strings only. */\n\tfunction sectionItems(part: MessagePartV1): string[] | undefined {\n\t\tconst items = (part.data as any)?.items\n\t\treturn Array.isArray(items) &&\n\t\t\titems.every((i: unknown) => typeof i === \"string\")\n\t\t\t? items\n\t\t\t: undefined\n\t}\n\n\t/** A section of reasoning wears the reasoning fold's glyph; every other kind the notebook. */\n\tfunction sectionIcon(part: MessagePartV1): \"brain\" | \"notebook\" {\n\t\treturn (part.data as any)?.kind === \"reasoning\" ? \"brain\" : \"notebook\"\n\t}\n\n\t/** The graceful floor: what an unknown type shows when unfolded. */\n\tfunction unknownBody(part: MessagePartV1): string {\n\t\tif (part.content) return part.content\n\t\ttry {\n\t\t\treturn \"```json\\n\" + JSON.stringify(part.data ?? {}, null, 2) + \"\\n```\"\n\t\t} catch {\n\t\t\treturn \"\"\n\t\t}\n\t}\n</script>\n\n{#snippet collapsible(\n\tpart: MessagePartV1,\n\ttitle: string,\n\ticon: \"brain\" | \"notebook\" | \"puzzle\" | \"wrench\",\n\tbody: string,\n\titems?: string[]\n)}\n\t<div data-widget-part=\"messages.part-disclosure\">\n\t\t<button\n\t\t\ttype=\"button\"\n\t\t\tdata-widget-part=\"messages.part-disclosure-toggle\"\n\t\t\tonclick={() => (expanded[part.id] = !expanded[part.id])}\n\t\t\ttitle={expanded[part.id] ? `Collapse ${title}` : `Expand ${title}`}\n\t\t\taria-expanded={!!expanded[part.id]}\n\t\t\taria-controls=\"part-{messageId}-{part.id}\"\n\t\t>\n\t\t\t{#if icon === \"brain\"}\n\t\t\t\t<sp-icon name=\"brain-circuit\" size=\"16\"></sp-icon>\n\t\t\t{:else if icon === \"notebook\"}\n\t\t\t\t<sp-icon name=\"notebook-pen\" size=\"16\"></sp-icon>\n\t\t\t{:else if icon === \"wrench\"}\n\t\t\t\t<sp-icon name=\"wrench\" size=\"16\"></sp-icon>\n\t\t\t{:else}\n\t\t\t\t<sp-icon name=\"puzzle\" size=\"16\"></sp-icon>\n\t\t\t{/if}\n\t\t\t<span>{title}</span>\n\t\t\t<!-- Unfolded, the chevron turns: the toggle's `aria-expanded`. -->\n\t\t\t<sp-icon name=\"chevron-down\" size=\"16\" data-widget-part=\"messages.part-disclosure-chevron\"></sp-icon>\n\t\t</button>\n\t\t<!-- grid 0fr -> 1fr transitions to/from auto height in pure CSS; the\n\t\t overflow-hidden wrapper keeps collapsed content from spilling, and\n\t\t the skin's `visibility` keeps the 0fr track's focusables out of the\n\t\t tab order (`messages.part-disclosure-track`, widgets.css). -->\n\t\t<div\n\t\t\tid=\"part-{messageId}-{part.id}\"\n\t\t\tdata-widget-part=\"messages.part-disclosure-track\"\n\t\t\tdata-expanded={expanded[part.id] ? \"\" : undefined}\n\t\t>\n\t\t\t<div data-widget-part=\"messages.part-disclosure-clip\">\n\t\t\t\t<div data-widget-part=\"messages.part-disclosure-panel messages.prose\">\n\t\t\t\t\t{#if items}\n\t\t\t\t\t\t<ul data-widget-part=\"messages.fold-list\">\n\t\t\t\t\t\t\t{#each items as item, i (i)}\n\t\t\t\t\t\t\t\t<li>{item}</li>\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t{:else}\n\t\t\t\t\t\t<sp-message-body text={body}></sp-message-body>\n\t\t\t\t\t{/if}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n{/snippet}\n\n{#each steps as step, i (step)}\n\t{#if i > 0}\n\t\t<!-- Steps accumulate (20 §1): a stepped activity's phases render\n\t\t stacked, separated so the progression reads as chapters. -->\n\t\t<hr data-widget-part=\"messages.part-step-divider\" />\n\t{/if}\n\t{#each visibleParts(step) as part (part.id)}\n\t\t{#if part.type === \"core:markdown\"}\n\t\t\t<div data-widget-part=\"messages.part-markdown messages.prose\">\n\t\t\t\t<sp-message-body\n\t\t\t\t\ttext={part.content ?? \"\"}\n\t\t\t\t\tonopen-image={(e: CustomEvent<{ src: string }>) => onOpenImage?.(e.detail.src)}\n\t\t\t\t></sp-message-body>\n\t\t\t</div>\n\t\t{:else if part.type === \"core:reasoning\"}\n\t\t\t{@render collapsible(part, \"Reasoning\", \"brain\", part.content ?? \"\")}\n\t\t{:else if part.type === \"core:tool-call\"}\n\t\t\t{@render collapsible(\n\t\t\t\tpart,\n\t\t\t\t(part.data as any)?.tool\n\t\t\t\t\t? `Tool: ${(part.data as any).tool}`\n\t\t\t\t\t: \"Tool call\",\n\t\t\t\t\"wrench\",\n\t\t\t\tpart.content ?? unknownBody(part)\n\t\t\t)}\n\t\t{:else if part.type === \"core:tool-result\"}\n\t\t\t{@render collapsible(\n\t\t\t\tpart,\n\t\t\t\t\"Tool result\",\n\t\t\t\t\"wrench\",\n\t\t\t\tpart.content ?? unknownBody(part)\n\t\t\t)}\n\t\t{:else if part.type === \"core:section\"}\n\t\t\t{@render collapsible(\n\t\t\t\tpart,\n\t\t\t\tsectionTitle(part),\n\t\t\t\tsectionIcon(part),\n\t\t\t\tpart.content ?? \"\",\n\t\t\t\tsectionItems(part)\n\t\t\t)}\n\t\t{:else if part.type === \"core:image\" || part.type === \"core:file\"}\n\t\t\t<!-- Attachments and generated images are the media strip's\n\t\t\t (MessageMediaStrip, under the body in every state of the row),\n\t\t\t never drawn inline here — and never the unknown-type fold. -->\n\t\t{:else if Array.isArray((part.data as any)?.blocks)}\n\t\t\t<!-- A block tree (20 §6): plugin content as data, core's renderer,\n\t\t\t whatever the part's namespace — the convention, not a registry. -->\n\t\t\t<MessageBlocksView\n\t\t\t\tblocks={(part.data as any).blocks}\n\t\t\t\t{onAction}\n\t\t\t\t{bodyText}\n\t\t\t\t{canAnswer}\n\t\t\t\t{isStale}\n\t\t\t/>\n\t\t{:else}\n\t\t\t{@render collapsible(part, part.type, \"puzzle\", unknownBody(part))}\n\t\t{/if}\n\t{/each}\n{/each}\n","sessions/messages/MessageStateLedger.svelte":"<script lang=\"ts\">\n\t/**\n\t * The transcript ledger: what one message changed, under that message.\n\t *\n\t * Every line is a real row anchored to this message, which is what makes it\n\t * revertible WITH the message: delete or regenerate the reply and the rows it\n\t * wrote go too, so the ledger cannot drift from the fiction it describes.\n\t * It renders nothing at all for a message that changed nothing, which is\n\t * almost every message in almost every session.\n\t *\n\t * Pending lines are the model's proposals waiting at the gate. They sit here\n\t * rather than in a queue somewhere else because the sentence that justifies a\n\t * change is the one above them; **Review** opens the same rows for the whole\n\t * session, for when they have scrolled away.\n\t */\n\timport StateProposalList from \"./StateProposalList.svelte\"\n\timport { useConversation } from \"./conversation.svelte\"\n\n\tinterface Props {\n\t\tmessageId: number\n\t}\n\tlet { messageId }: Props = $props()\n\n\t// What this line changed and what waits on it: the page's projection of\n\t// the session state (C0b), read off the conversation.\n\tconst conv = useConversation()\n\tlet groups = $derived(conv.dossier?.state.ledgers[messageId] ?? [])\n\tlet pending = $derived(conv.dossier?.state.pending[messageId] ?? [])\n\tlet waiting = $derived(conv.dossier?.state.waiting ?? [])\n\tlet reviewOpen = $state(false)\n</script>\n\n<!-- The ledger's parts (`messages.ledger*`, `messages.proposal*`; STYLE-GUIDE\n §6.16): no look here; the default widget stylesheet draws them. -->\n{#if groups.length || pending.length}\n\t<div data-widget-part=\"messages.ledger\" data-ledger-message={messageId}>\n\t\t{#each groups as group (group.ownerKey)}\n\t\t\t<p data-widget-part=\"messages.ledger-line\" data-owner-key={group.ownerKey}>\n\t\t\t\t<span data-widget-part=\"messages.ledger-owner\">{group.ownerLabel}</span>\n\t\t\t\t{#each group.lines as line, i (line.key)}\n\t\t\t\t\t{#if i > 0}<span data-widget-part=\"messages.ledger-separator\">·</span>{/if}\n\t\t\t\t\t<span data-widget-part=\"messages.ledger-change\" title=\"changed by {line.updatedBy}\">\n\t\t\t\t\t\t{line.text}\n\t\t\t\t\t</span>\n\t\t\t\t{/each}\n\t\t\t</p>\n\t\t{/each}\n\n\t\t{#if pending.length}\n\t\t\t<StateProposalList proposals={pending} />\n\t\t{/if}\n\n\t\t{#if waiting.length}\n\t\t\t<!-- `sp-popover` (§3.5): our button is the trigger, the card the panel. -->\n\t\t\t<sp-popover\n\t\t\t\tplacement=\"bottom-start\"\n\t\t\t\tlabel=\"Waiting for you\"\n\t\t\t\topen={reviewOpen}\n\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => (reviewOpen = e.detail.open)}\n\t\t\t>\n\t\t\t\t<button slot=\"trigger\" type=\"button\" data-widget-part=\"messages.ledger-review\">\n\t\t\t\t\t<sp-icon name=\"clipboard-check\" size=\"11\"></sp-icon>\n\t\t\t\t\t<span>\n\t\t\t\t\t\tReview\n\t\t\t\t\t\t{waiting.length === 1\n\t\t\t\t\t\t\t? \"1 change\"\n\t\t\t\t\t\t\t: `${waiting.length} changes`}\n\t\t\t\t\t</span>\n\t\t\t\t</button>\n\t\t\t\t\t\t<div data-widget-part=\"messages.ledger-review-panel\">\n\t\t\t\t\t\t\t<header\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.ledger-review-title\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"clipboard-check\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Waiting for you</span>\n\t\t\t\t\t\t\t</header>\n\t\t\t\t\t\t\t<p data-widget-part=\"messages.ledger-review-note\">\n\t\t\t\t\t\t\t\tThe AI asked for these. Nothing changes until\n\t\t\t\t\t\t\t\tyou accept one.\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t<StateProposalList proposals={waiting} showAnchor />\n\t\t\t\t\t\t</div>\n\t\t\t</sp-popover>\n\t\t{/if}\n\t</div>\n{/if}\n","sessions/messages/Messages.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's messages widget as a remote component (C0b): the component\n\t * context, as the native widget context, around the very same\n\t * `MessagesWidget` the page mounts natively.\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/conversation\"\n\timport MessagesWidget from \"./MessagesWidget.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: \"messages\", instanceId: \"messages\", title: \"Messages\" }\n\t\t)\n\t)\n</script>\n\n<MessagesWidget />\n","sessions/messages/MessagesWidget.svelte":"<script lang=\"ts\" module>\n\timport type { MessageOrder } from \"@serene-pub/core-catalog/conversation\"\n\n\t/** How the composer's field is drawn. */\n\texport type ComposerSkin = \"classic\" | \"minimal\" | \"writer\" | \"quill\"\n\n\t/** Which end of the widget the composer sits at. */\n\texport type ComposerPosition = \"bottom\" | \"top\"\n\n\t/**\n\t * Who is due next (PLAN-turn-order §4.9): the order's head with Continue,\n\t * the head and who follows it, or nothing.\n\t */\n\texport type NextUp = \"head\" | \"list\" | \"hidden\"\n\n\t/**\n\t * How wide the log's rows and the composer run: the whole width the layout\n\t * gives the widget (`full`, the default), or a reading measure centred in\n\t * it (`comfortable`, about 640px of prose). Never a hidden cap: the widget\n\t * fills its box unless its settings say otherwise.\n\t */\n\texport type LineWidth = \"full\" | \"comfortable\"\n\n\t/**\n\t * The `messages` widget's settings, complete: every value the widget reads,\n\t * with the declared default wherever the instance has no deviation. The\n\t * page receives this object too (as the snippet parameter and through\n\t * `onSettings`), so the log, the composer and the page's scroll handling\n\t * all answer to one reading of the settings.\n\t */\n\texport interface ConversationSettings {\n\t\torder: MessageOrder\n\t\tcomposerSkin: ComposerSkin\n\t\tcomposerPosition: ComposerPosition\n\t\tlineWidth: LineWidth\n\t\tshowMessages: boolean\n\t\tshowComposer: boolean\n\t\tshowAvatars: boolean\n\t\tshowTimestamps: boolean\n\t\tshowSceneMarkers: boolean\n\t\tnextUp: NextUp\n\t\tshowActions: boolean\n\t\t/**\n\t\t * The one channel this copy shows (lair re-plan S1), or `null` for the\n\t\t * primary log. The host narrows the rows and the composer's channels\n\t\t * by it; the widget draws its head from it.\n\t\t */\n\t\tchannel: string | null\n\t}\n\n\t/**\n\t * The declared defaults (`CORE_WIDGETS`, the `messages` entry), restated as\n\t * the fallback for a mount with no `WidgetHost` above it — a standalone\n\t * render, a test — where there is no `settings.v1` to read.\n\t */\n\texport const CONVERSATION_DEFAULTS: ConversationSettings = {\n\t\torder: \"oldest-first\",\n\t\tcomposerSkin: \"classic\",\n\t\tcomposerPosition: \"bottom\",\n\t\tlineWidth: \"full\",\n\t\tshowMessages: true,\n\t\tshowComposer: true,\n\t\tshowAvatars: true,\n\t\tshowTimestamps: true,\n\t\tshowSceneMarkers: true,\n\t\tnextUp: \"head\",\n\t\tshowActions: true,\n\t\tchannel: null\n\t}\n\n\tfunction pickEnum<T extends string>(\n\t\traw: unknown,\n\t\tof: readonly T[],\n\t\tfallback: T\n\t): T {\n\t\treturn typeof raw === \"string\" &&\n\t\t\t(of as readonly string[]).includes(raw)\n\t\t\t? (raw as T)\n\t\t\t: fallback\n\t}\n\n\tfunction pickBool(raw: unknown, fallback: boolean): boolean {\n\t\treturn typeof raw === \"boolean\" ? raw : fallback\n\t}\n\n\t/** Read one settings payload into the complete object above. */\n\texport function readConversationSettings(\n\t\traw: Record<string, unknown> | undefined\n\t): ConversationSettings {\n\t\tconst v = raw ?? {}\n\t\tconst d = CONVERSATION_DEFAULTS\n\t\treturn {\n\t\t\torder: pickEnum(v.order, [\"oldest-first\", \"newest-first\"], d.order),\n\t\t\tcomposerSkin: pickEnum(\n\t\t\t\tv.composer,\n\t\t\t\t[\"classic\", \"minimal\", \"writer\", \"quill\"],\n\t\t\t\td.composerSkin\n\t\t\t),\n\t\t\tcomposerPosition: pickEnum(\n\t\t\t\tv.composerPosition,\n\t\t\t\t[\"bottom\", \"top\"],\n\t\t\t\td.composerPosition\n\t\t\t),\n\t\t\tlineWidth: pickEnum(v.lineWidth, [\"full\", \"comfortable\"], d.lineWidth),\n\t\t\tshowMessages: pickBool(v.showMessages, d.showMessages),\n\t\t\tshowComposer: pickBool(v.showComposer, d.showComposer),\n\t\t\tshowAvatars: pickBool(v.showAvatars, d.showAvatars),\n\t\t\tshowTimestamps: pickBool(v.showTimestamps, d.showTimestamps),\n\t\t\tshowSceneMarkers: pickBool(v.showSceneMarkers, d.showSceneMarkers),\n\t\t\t// ⏳ `showNudge: false` was this setting before `nextUp` (A8).\n\t\t\tnextUp: pickEnum(\n\t\t\t\tv.nextUp,\n\t\t\t\t[\"head\", \"list\", \"hidden\"],\n\t\t\t\tv.showNudge === false ? \"hidden\" : d.nextUp\n\t\t\t),\n\t\t\tshowActions: pickBool(v.showActions, d.showActions),\n\t\t\tchannel:\n\t\t\t\ttypeof v.channel === \"string\" && v.channel.trim()\n\t\t\t\t\t? v.channel.trim()\n\t\t\t\t\t: d.channel\n\t\t}\n\t}\n</script>\n\n<script lang=\"ts\">\n\t/**\n\t * The `messages` widget's component: the log you read and the\n\t * field you write into, as ONE widget.\n\t *\n\t * It owns the conversation (C0b): the model its parts read\n\t * (`conversation.svelte.ts`) and the log. The page still passes the\n\t * composer, the ready-to-continue line and the banners as snippets; this\n\t * component reads the widget's settings off `useWidgetContext()`, hands\n\t * them back to those snippets, writes them onto the root as data\n\t * attributes, and decides which end the composer sits at.\n\t */\n\timport { useWidgetContext } from \"../shared/context\"\n\timport SessionContainer from \"./SessionContainer.svelte\"\n\timport SessionComposer from \"./SessionComposer.svelte\"\n\timport NextCharacterBlock from \"./NextCharacterBlock.svelte\"\n\timport { createConversation, setConversation } from \"./conversation.svelte\"\n\n\tinterface Props {\n\t\t/**\n\t\t * Called with the effective settings whenever they change, for the\n\t\t * page's imperative half — the scroll handling, which runs outside the\n\t\t * render and cannot read a snippet parameter.\n\t\t */\n\t\tonSettings?: (settings: ConversationSettings) => void\n\t}\n\n\tlet { onSettings }: Props = $props()\n\n\tconst ctx = useWidgetContext()\n\t// The conversation's own model (C0b): the log and its lines read it, and\n\t// act through its verbs. Absent a host there is nothing to converse with.\n\tconst conversation = ctx ? setConversation(createConversation(ctx)) : null\n\n\t// A host view asked for a selection (the workflow tab): start one.\n\tlet askedToSelect: number | null = null\n\t$effect(() => {\n\t\tconst n = conversation?.dossier?.selectForSummary ?? 0\n\t\tif (askedToSelect !== null && n !== askedToSelect) conversation?.select.start()\n\t\taskedToSelect = n\n\t})\n\tconst selecting = $derived(!!conversation?.select.active)\n\tconst selectedCount = $derived(conversation?.select.ids.size ?? 0)\n\t/** Every line a scene has not already captured. */\n\tconst selectable = $derived.by(() => {\n\t\tconst taken = new Set(conversation?.dossier?.scened ?? [])\n\t\treturn ((conversation?.rows ?? []) as Array<{ id: number }>)\n\t\t\t.map((m) => m.id)\n\t\t\t.filter((id) => !taken.has(id))\n\t})\n\tlet settings = $derived(\n\t\treadConversationSettings(\n\t\t\tctx?.current.settings.v1 as Record<string, unknown> | undefined\n\t\t)\n\t)\n\n\t// Compared by value, the way `WidgetHost` compares its layout: the widget\n\t// context re-projects on every message that lands, and the settings on it\n\t// are the same object nearly every time.\n\tlet lastSettingsKey: string | null = null\n\t$effect(() => {\n\t\tconst next = settings\n\t\tconst key = JSON.stringify(next)\n\t\tif (key === lastSettingsKey) return\n\t\tlastSettingsKey = key\n\t\tonSettings?.(next)\n\t})\n</script>\n\n<!-- The widget's parts (`messages.*`, STYLE-GUIDE §6.16): no look here; the\n default widget stylesheet draws them, and a pack or a person's style\n restyles them. -->\n<div\n\tdata-widget-part=\"messages.root\"\n\tdata-order={settings.order}\n\tdata-composer-position={settings.composerPosition}\n\tdata-composer-skin={settings.composerSkin}\n\tdata-line-width={settings.lineWidth}\n\tdata-show-messages={settings.showMessages}\n\tdata-show-avatars={settings.showAvatars}\n\tdata-show-timestamps={settings.showTimestamps}\n\tdata-show-scene-markers={settings.showSceneMarkers}\n\tdata-channel={settings.channel ?? undefined}\n>\n\t{#if settings.channel && conversation}\n\t\t<!-- A copy pinned to one channel names it (S1): the channel's declared\n\t\t label, the Lair's _Sanctum_. The primary log has no head — the\n\t\t session's own header names it. -->\n\t\t<header data-widget-part=\"messages.channel-head\">\n\t\t\t<sp-icon name=\"messages-square\" size=\"16\" data-widget-part=\"messages.channel-icon\"></sp-icon>\n\t\t\t<h2 data-widget-part=\"messages.channel-title\">{conversation.channelName(settings.channel)}</h2>\n\t\t</header>\n\t{/if}\n\t<!-- The whole panel scrolls: the log spans the widget's width, so its\n\t scrollbar sits at the panel's edge and the wheel works anywhere in it;\n\t the rows (the stage, `messages.stage`) and the composer take the\n\t widget's full width, or a centred reading measure when the Line width\n\t setting says Comfortable. DOM order is log then composer whichever end the\n\t composer is drawn at: the reading order a screen reader and the tab\n\t sequence follow is the conversation's, and `order` moves the box on\n\t screen. -->\n\t{#if settings.showMessages}\n\t\t<div data-widget-part=\"messages.log\">\n\t\t\t{#if conversation}\n\t\t\t\t<SessionContainer order={settings.order} showSceneMarkers={settings.showSceneMarkers} />\n\t\t\t{/if}\n\t\t</div>\n\t{/if}\n\t{#if selecting && conversation}\n\t\t<!-- Selecting lines for a summary: the composer steps aside for the\n\t\t selection's own bar, and committing hands it to the host. -->\n\t\t<!-- The compose block (`messages.compose`, on the reading column) and the\n\t\t composer's area (`messages.compose-area`), where the selection bar\n\t\t stands in the composer's place. -->\n\t\t<div data-widget-part=\"messages.compose\">\n\t\t\t<div data-widget-part=\"messages.compose-area\">\n\t\t\t\t<!-- The selection bar's parts are `messages.selection-*` (STYLE-GUIDE\n\t\t\t\t §6.16): no look here; the default widget stylesheet draws them. -->\n\t\t\t\t<div data-widget-part=\"messages.selection-bar toolbar\">\n\t\t\t\t\t<span data-widget-part=\"messages.selection-count\">\n\t\t\t\t\t\t{selectedCount}\n\t\t\t\t\t\t{selectedCount === 1 ? \"message\" : \"messages\"} selected\n\t\t\t\t\t</span>\n\t\t\t\t\t<div data-widget-part=\"messages.selection-bulk\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.select-all messages.selection-button\"\n\t\t\t\t\t\t\ttitle=\"Select all\"\n\t\t\t\t\t\t\tonclick={() => conversation.select.set(selectable)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"check-square\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">Select all</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.select-none messages.selection-button\"\n\t\t\t\t\t\t\ttitle=\"Select none\"\n\t\t\t\t\t\t\tonclick={() => conversation.select.set([])}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"square\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">Select none</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div data-widget-part=\"messages.selection-finish\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.selection-cancel messages.selection-button\"\n\t\t\t\t\t\t\ttitle=\"Cancel\"\n\t\t\t\t\t\t\tonclick={() => conversation.select.stop()}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"x\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">Cancel</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<!-- A scene summary opens a scene, which is its own declared\n\t\t\t\t\t\t write (R-B): a genre that opens none does not offer it. -->\n\t\t\t\t\t\t{#if conversation.dossier?.writes.scenes}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.summarize-scene messages.selection-button\"\n\t\t\t\t\t\t\t\ttitle=\"Scene\"\n\t\t\t\t\t\t\t\tdisabled={selectedCount === 0}\n\t\t\t\t\t\t\t\tonclick={() => conversation.select.commit(\"scene\")}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"film\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">Scene</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.summarize-world messages.selection-button\"\n\t\t\t\t\t\t\ttitle=\"World lore\"\n\t\t\t\t\t\t\tdisabled={selectedCount === 0}\n\t\t\t\t\t\t\tonclick={() => conversation.select.commit(\"world\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"globe\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">World lore</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.summarize-character messages.selection-button\"\n\t\t\t\t\t\t\ttitle=\"Character lore\"\n\t\t\t\t\t\t\tdisabled={selectedCount === 0}\n\t\t\t\t\t\t\tonclick={() => conversation.select.commit(\"character\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"user\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.selection-button-label\">Character lore</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t{:else if settings.showComposer && conversation}\n\t\t{@const dossier = conversation.dossier}\n\t\t<div data-widget-part=\"messages.compose\">\n\t\t\t<!-- The page's status strips (who is typing, a stale preset). -->\n\t\t\t<sp-host-view name=\"session-banners\"></sp-host-view>\n\t\t\t{#if settings.nextUp !== \"hidden\" && dossier && !dossier.readOnly}\n\t\t\t\t<div data-widget-part=\"messages.next-up\">\n\t\t\t\t\t<NextCharacterBlock\n\t\t\t\t\t\torder={dossier.turn.order}\n\t\t\t\t\t\tcandidates={dossier.turn.candidates}\n\t\t\t\t\t\tmode={settings.nextUp}\n\t\t\t\t\t\tshouldShow={dossier.turn.show && conversation.edit.id === null}\n\t\t\t\t\t\tavatarFor={(ref) => (ref.startsWith(\"character:\") ? ref : undefined)}\n\t\t\t\t\t\tcanChooseSomeoneElse={dossier.turn.canChoose}\n\t\t\t\t\t\tviewerUserId={conversation.ctx.viewer.v1.userId}\n\t\t\t\t\t\tonContinue={(channel) => void conversation.request(\"fire-turn\", { channel })}\n\t\t\t\t\t\tonSomeoneElse={() => void conversation.request(\"pick-turn\", {})}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t{/if}\n\t\t\t<div data-widget-part=\"messages.compose-area\">\n\t\t\t\t{#if dossier?.readOnly}\n\t\t\t\t\t<!-- Read-only (19 §6, ruled): the mode disappeared, the history\n\t\t\t\t\t stays, nothing starts a new turn — and the server refuses\n\t\t\t\t\t independently at every generation choke, so this banner is\n\t\t\t\t\t honesty, not the lock. -->\n\t\t\t\t\t<div data-widget-part=\"messages.read-only\" role=\"status\">\n\t\t\t\t\t\t<sp-icon name=\"lock\" size=\"20\" data-widget-part=\"messages.read-only-icon\"></sp-icon>\n\t\t\t\t\t\t<div data-widget-part=\"messages.read-only-text\">\n\t\t\t\t\t\t\t<p data-widget-part=\"messages.read-only-title\">This session is read-only.</p>\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\tIts mode ({dossier.readOnly.genreId}) is not installed. Messages are safe to\n\t\t\t\t\t\t\t\tread; new turns resume when the mode returns.\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{:else}\n\t\t\t\t\t<SessionComposer composerSkin={settings.composerSkin} showActions={settings.showActions} />\n\t\t\t\t{/if}\n\t\t\t</div>\n\t\t</div>\n\t{/if}\n</div>\n","sessions/messages/NextCharacterBlock.svelte":"<script lang=\"ts\">\n\t/**\n\t * Who is due next (PLAN-turn-order §4.9), rendered from the session's\n\t * stored turn order — never derived on the client. It reads the entries\n\t * on **its own log's channel** (the composer's, `conversation.lane`;\n\t * lair re-plan R5): an entry with no `channel` is `main`'s. That\n\t * channel's first entry is its head, named from the order's candidates:\n\t *\n\t * - a character or envoy: \"<name> is ready to continue\", with Continue;\n\t * - `ref: null`, the pipeline's own voice: \"<own voice> is ready to\n\t * continue\", with Continue — the name the page resolved\n\t * (`turn.ownVoiceName`: the Lair's \"Castellan\", else the narrator's);\n\t * - a person (a persona): \"<name>'s turn\", or \"Your turn\" when the\n\t * persona is the viewer's own, and no Continue — a person's turn is\n\t * taken by writing.\n\t *\n\t * An empty order with people to choose from — a round that is over, or\n\t * a manual strategy waiting to be told — waits on a message and offers\n\t * the pick. An order whose entries are all on other channels shows\n\t * nothing here.\n\t *\n\t * Continue hands its channel to `onContinue`, so the page fires this\n\t * channel's entry. \"Someone else\" asks the page to open the turn picker.\n\t * With `mode: 'list'` the entries after the head follow as one quiet line.\n\t *\n\t * Its parts are `messages.next-up-*` (STYLE-GUIDE §6.16): the markup\n\t * carries no look; the default widget stylesheet draws it.\n\t */\n\timport type { NextUp } from \"./MessagesWidget.svelte\"\n\timport { useConversation } from \"./conversation.svelte\"\n\n\ttype Entry = { ref: string | null; channel?: unknown; [k: string]: unknown }\n\ttype Candidate = {\n\t\tref: string\n\t\tkind: string\n\t\tname: string\n\t\tnickname?: string\n\t\townerUserId?: number\n\t}\n\n\tinterface Props {\n\t\torder: Entry[]\n\t\tcandidates: Candidate[]\n\t\tmode: NextUp\n\t\tshouldShow: boolean\n\t\t/** A face for a ref, when the session has one loaded. */\n\t\tavatarFor?: (ref: string) => unknown\n\t\t/** Continue, with the channel of the log it was pressed under (R5). */\n\t\tonContinue: (channel: string) => void\n\t\tonSomeoneElse: () => void\n\t\t/** Whether anyone else could take the turn. */\n\t\tcanChooseSomeoneElse?: boolean\n\t\t/** The person looking: their own persona's turn reads \"Your turn\". */\n\t\tviewerUserId?: number | null\n\t}\n\n\tlet {\n\t\torder,\n\t\tcandidates,\n\t\tmode,\n\t\tshouldShow,\n\t\tavatarFor,\n\t\tonContinue,\n\t\tonSomeoneElse,\n\t\tcanChooseSomeoneElse = true,\n\t\tviewerUserId = null\n\t}: Props = $props()\n\n\tconst conversation = useConversation()\n\t/** This log's channel — the composer's — `main` by default. */\n\tconst channel = $derived(conversation.lane.current || \"main\")\n\tconst channelOf = (e: Entry) =>\n\t\ttypeof e.channel === \"string\" && e.channel ? e.channel : \"main\"\n\t/** The entries prepared on this channel, in the order's order. */\n\tconst here = $derived(order.filter((e) => channelOf(e) === channel))\n\tconst byRef = $derived(new Map(candidates.map((c) => [c.ref, c])))\n\tconst head = $derived(here[0])\n\tconst nameOf = (ref: string | null): string => {\n\t\tif (ref === null)\n\t\t\treturn conversation.dossier?.turn.ownVoiceName || \"The narrator\"\n\t\tconst c = byRef.get(ref)\n\t\treturn c?.nickname || c?.name || \"Someone\"\n\t}\n\tconst isPerson = (ref: string | null) =>\n\t\tref !== null && byRef.get(ref)?.kind === \"persona\"\n\tconst headName = $derived(head ? nameOf(head.ref) : \"\")\n\tconst headIsPerson = $derived(!!head && isPerson(head.ref))\n\tconst headIsMine = $derived(\n\t\theadIsPerson &&\n\t\t\tviewerUserId != null &&\n\t\t\tbyRef.get(head!.ref as string)?.ownerUserId === viewerUserId\n\t)\n\tconst line = $derived(\n\t\theadIsMine\n\t\t\t? \"Your turn\"\n\t\t\t: headIsPerson\n\t\t\t\t? `${headName}'s turn`\n\t\t\t\t: `${headName} is ready to continue`\n\t)\n\tconst face = $derived(head?.ref ? avatarFor?.(head.ref) : undefined)\n\tconst after = $derived(mode === \"list\" ? here.slice(1) : [])\n</script>\n\n{#if shouldShow && !order.length && candidates.length}\n\t<div data-widget-part=\"messages.next-up-waiting\">\n\t\t<span data-widget-part=\"messages.next-up-text\">\n\t\t\tWaiting for a message — or pick who speaks next\n\t\t</span>\n\t\t<button type=\"button\" data-widget-part=\"messages.next-up-pick\" onclick={onSomeoneElse}>\n\t\t\t<sp-icon name=\"users\" size=\"14\"></sp-icon>\n\t\t\t<span>Pick</span>\n\t\t</button>\n\t</div>\n{:else if shouldShow && head}\n\t<!-- One line: who is up, and what you can do about it. -->\n\t<div data-widget-part=\"messages.next-up-head\">\n\t\t<div data-widget-part=\"messages.next-up-line\">\n\t\t\t{#if face}\n\t\t\t\t<sp-avatar ref={head.ref} size=\"sm\"></sp-avatar>\n\t\t\t{:else if head.ref === null}\n\t\t\t\t<sp-icon name=\"book-open-text\" size=\"18\" data-widget-part=\"messages.next-up-narrator\"></sp-icon>\n\t\t\t{/if}\n\t\t\t<span data-widget-part=\"messages.next-up-text\">\n\t\t\t\t{line}\n\t\t\t</span>\n\t\t\t<div data-widget-part=\"messages.next-up-controls\">\n\t\t\t\t{#if canChooseSomeoneElse}\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tdata-widget-part=\"messages.next-up-pick\"\n\t\t\t\t\t\tonclick={onSomeoneElse}\n\t\t\t\t\t\ttitle=\"Someone else\"\n\t\t\t\t\t\taria-label=\"Pick someone else to continue\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-icon name=\"users\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t<span data-widget-part=\"messages.next-up-pick-label\">Someone else</span>\n\t\t\t\t\t</button>\n\t\t\t\t{/if}\n\t\t\t\t{#if !headIsPerson}\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tdata-widget-part=\"messages.next-up-continue\"\n\t\t\t\t\t\tonclick={() => onContinue(channel)}\n\t\t\t\t\t\ttitle=\"Continue\"\n\t\t\t\t\t\taria-label=\"Continue with {headName}\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-icon name=\"play\"></sp-icon>\n\t\t\t\t\t\t<span>Continue</span>\n\t\t\t\t\t</button>\n\t\t\t\t{/if}\n\t\t\t</div>\n\t\t</div>\n\t\t{#if after.length}\n\t\t\t<p data-widget-part=\"messages.next-up-after\">\n\t\t\t\tThen {after.map((e) => nameOf(e.ref)).join(\", \")}\n\t\t\t</p>\n\t\t{/if}\n\t</div>\n{/if}\n","sessions/messages/SessionComposer.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's composer (C0b): the field you write into, the persona you write\n\t * as, the lane, the session's action chips and its More panel. It reads\n\t * the conversation (`useConversation`) and the dossier's composer part;\n\t * sending, the draft and a persona switch are requests core's own widget\n\t * may make, a press of an action is `invoke`, and the page's own parts —\n\t * the chips, the turn controls, the panels, the run card, the retrieval\n\t * notice — are host views it places (`sp-host-view`).\n\t */\n\timport {\n\t\texactPaletteMatch,\n\t\texactSlashCommand,\n\t\tfilterPaletteActions,\n\t\tpaletteRowState,\n\t\tslashArgumentHint,\n\t\tslashArgumentRefusal,\n\t\tslashQueryOf,\n\t\tstepHighlight,\n\t\ttype PaletteAction\n\t} from \"@serene-pub/core-catalog/conversation\"\n\timport { actionIdentity } from \"@serene-pub/sdk/component\"\n\timport type { ItemValues } from \"@serene-pub/core-catalog/conversation\"\n\timport {\n\t\tATTACHMENT_KINDS_V1,\n\t\tKIND_FORMATS,\n\t\tKIND_NAME,\n\t\tpreCheckFiles,\n\t\treaderCallLines,\n\t\treadersSummary,\n\t\tsendableTrayIds,\n\t\tsniffAttachmentKind,\n\t\tuploadingNote,\n\t\ttype TrayItemV1,\n\t\ttype TrayRefusalV1\n\t} from \"@serene-pub/core-catalog/conversation\"\n\timport { i18nText } from \"@serene-pub/sdk/component\"\n\timport { untrack } from \"svelte\"\n\timport { useConversation } from \"./conversation.svelte\"\n\timport type { WidgetAction } from \"@serene-pub/sdk/component\"\n\n\t/** The More panel's tab that is not a pane: the turn controls, in the actions row. */\n\tconst TURN_CONTROLS_VIEW = \"session-controls\"\n\n\tinterface Props {\n\t\t/** How the composer is drawn (a widget setting). */\n\t\tcomposerSkin?: \"classic\" | \"minimal\" | \"writer\" | \"quill\"\n\t\t/** Hides the Actions label and its row outright. */\n\t\tshowActions?: boolean\n\t}\n\n\tlet { composerSkin = \"classic\", showActions = true }: Props = $props()\n\n\tconst conv = useConversation()\n\tconst c = $derived(conv.dossier?.composer)\n\tconst hideCompose = $derived(!!c?.hidden)\n\tconst channels = $derived(c?.channels ?? [])\n\tconst overflowActions = $derived((c?.overflow ?? []) as WidgetAction[])\n\tconst paletteActions = $derived((c?.palette ?? []) as PaletteAction[])\n\tconst newestItem = $derived((c?.newest ?? null) as ItemValues | null)\n\tconst sendTonal = $derived(!!c?.sendTonal)\n\tconst actionsListed = $derived(!!c?.actions)\n\n\t/**\n\t * The draft: the composer's own between the host's writes. A write — the\n\t * kept draft when the session opens, an empty one when an action spent\n\t * it — replaces the field, whatever it holds; the same write, re-posted\n\t * with the rest of the dossier, never does.\n\t */\n\tlet draft = $state(\"\")\n\tlet written: number | null = null\n\tlet writtenFor: number | null = null\n\t$effect(() => {\n\t\tconst write = c?.draft ?? null\n\t\tconst session = conv.dossier?.sessionId ?? null\n\t\t// Another session: its own draft, never the last one's.\n\t\tif (session === writtenFor && (write?.write ?? null) === written) return\n\t\twrittenFor = session\n\t\twritten = write?.write ?? null\n\t\tsetField(write?.content ?? \"\")\n\t})\n\t// The host keeps the draft (and counts its tokens): told as it changes.\n\t$effect(() => {\n\t\tconst content = draft\n\t\tconst t = setTimeout(() => void conv.request(\"draft\", { content }), 150)\n\t\treturn () => clearTimeout(t)\n\t})\n\n\t/**\n\t * What the field is told to show. The field is the host's between writes\n\t * (the caret stays on the page), so a write is a reset — and every reset\n\t * must arrive, the same text included: the attachment removes the\n\t * attribute first, since both Svelte and the renderer skip a write of the\n\t * value they last wrote.\n\t */\n\tlet fieldValue = $state(\"\")\n\tlet fieldWrites = $state(0)\n\tfunction setField(text: string) {\n\t\tdraft = text\n\t\tfieldValue = text\n\t\tfieldWrites++\n\t}\n\tconst writeField = (el: HTMLElement) => {\n\t\tvoid fieldWrites\n\t\tconst v = fieldValue\n\t\tel.removeAttribute(\"value\")\n\t\tel.setAttribute(\"value\", v)\n\t}\n\n\tfunction send() {\n\t\tconst content = draft\n\t\tconst trayItemIds = sendableTrayIds(tray)\n\t\t// Attachments alone are a line (composer attachments §3.1).\n\t\tif (!content.trim() && !trayItemIds.length && !uploading) return\n\t\t// A whole slash name — with or without its argument — is a command,\n\t\t// never a line: Send runs it as Enter does (S2), which is how a phone,\n\t\t// whose Enter writes a new line, runs `/nudge go north`.\n\t\tconst command = content.trim() ? exactSlashCommand(paletteActions, content) : undefined\n\t\tif (command) {\n\t\t\tinvokePalette(command.action, command.argument)\n\t\t\treturn\n\t\t}\n\t\t// Send waits only for the files still uploading (\"Uploading 1 of\n\t\t// 2…\"), then goes on its own.\n\t\tif (uploading) {\n\t\t\tsendWaiting = true\n\t\t\treturn\n\t\t}\n\t\tsendWaiting = false\n\t\t// Cleared once the host took it: a refused line (no persona, an\n\t\t// attachment the reply stopped reading) stays put, tiles and all.\n\t\t// The tiles leave when the host's tray says they were sent.\n\t\tconv.ctx\n\t\t\t.request(\"send\", {\n\t\t\t\tcontent,\n\t\t\t\tpersonaId: c?.personaId ?? null,\n\t\t\t\tchannel: conv.lane.current,\n\t\t\t\t...(trayItemIds.length ? { trayItemIds } : {})\n\t\t\t})\n\t\t\t.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (draft === content) setField(\"\")\n\t\t\t\t},\n\t\t\t\t(e: Error) => console.warn(`Send: ${e.message}`)\n\t\t\t)\n\t\tpaletteDismissed = null\n\t\tpaletteHighlight = -1\n\t}\n\n\t/* ── attachments (composer attachments §3.3) ──────────────────────────\n\t * The tray is the host's (`composer.tray`): this composer asks it to\n\t * take files (`attach-files`) and to drop one (`remove-tray-item`), and\n\t * draws what it says. A file the readers would refuse — or an SVG, an\n\t * oversized file, one past the count — is refused here first, before a\n\t * byte goes up, as a tile that says why and clears itself; the server\n\t * checks every file again. What the reply can read is not drawn in the\n\t * composer's body: the More (⋮) panel's **What can be attached** opens\n\t * it in a dialog (next-pass note 41, 2026-10-03). */\n\tconst tray = $derived((c?.tray ?? []) as TrayItemV1[])\n\tconst readers = $derived(c?.attachments ?? null)\n\tconst offersAttachments = $derived(c?.tray !== undefined && !hideCompose)\n\tconst readersLine = $derived(readersSummary(readers))\n\tconst readerLines = $derived(readerCallLines(readers))\n\t/** The More panel offers **What can be attached**: there is something to say. */\n\tconst readersOffered = $derived(offersAttachments && !!readersLine)\n\tconst uploading = $derived(uploadingNote(tray))\n\tconst hasAttachments = $derived(tray.some((t) => t.status !== \"refused\"))\n\t/** The **What can be attached** dialog is open. */\n\tlet readersOpen = $state(false)\n\t/** Pressed Send while files were uploading: it goes when they finish. */\n\tlet sendWaiting = $state(false)\n\t$effect(() => {\n\t\tif (sendWaiting && !uploading) untrack(() => send())\n\t})\n\t/** Files refused before upload, drawn as tiles until they clear (§2b). */\n\tlet refusedHere = $state<Array<TrayRefusalV1 & { key: number }>>([])\n\tlet refusalSeq = 0\n\t/** What the live region last said (\"cat.png attached\", a refusal). */\n\tlet announcement = $state(\"\")\n\n\tasync function attachFiles(files: File[]) {\n\t\tif (!files.length) return\n\t\tconst sniffed = await Promise.all(\n\t\t\tfiles.map(async (f) => ({\n\t\t\t\tname: f.name,\n\t\t\t\tsize: f.size,\n\t\t\t\tkind: sniffAttachmentKind(\n\t\t\t\t\tnew Uint8Array(await f.slice(0, 512).arrayBuffer()),\n\t\t\t\t\tf.name,\n\t\t\t\t\tf.type\n\t\t\t\t)\n\t\t\t}))\n\t\t)\n\t\tconst { accept, refusals } = preCheckFiles(sniffed, tray, readers)\n\t\tfor (const r of refusals) {\n\t\t\tconst key = ++refusalSeq\n\t\t\trefusedHere = [...refusedHere, { ...r, key }]\n\t\t\tsetTimeout(() => (refusedHere = refusedHere.filter((x) => x.key !== key)), 6000)\n\t\t}\n\t\tif (refusals.length)\n\t\t\tannouncement = refusals.map((r) => `Can't attach ${r.filename}: ${r.reason}`).join(\" \")\n\t\tif (accept.length)\n\t\t\tconv.ctx\n\t\t\t\t.request(\"attach-files\", { files: accept.map((i) => files[i]!) })\n\t\t\t\t.catch((e: Error) => (announcement = e.message))\n\t}\n\n\tfunction removeTrayItem(item: TrayItemV1) {\n\t\tvoid conv.ctx.request(\"remove-tray-item\", { trayItemId: item.id }).catch(() => {})\n\t\tannouncement = `${item.filename} removed`\n\t}\n\n\t// \"cat.png attached\" — once, as a tile turns ready; a server refusal too.\n\tconst heard = new Map<string, string>()\n\t$effect(() => {\n\t\tfor (const t of tray) {\n\t\t\tconst was = heard.get(t.id)\n\t\t\tif (was === t.status) continue\n\t\t\theard.set(t.id, t.status)\n\t\t\tif (was === undefined && t.status === \"uploading\") continue\n\t\t\tif (t.status === \"ready\") untrack(() => (announcement = `${t.filename} attached`))\n\t\t\tif (t.status === \"refused\")\n\t\t\t\tuntrack(() => (announcement = `Can't attach ${t.filename}: ${t.refusal ?? \"\"}`))\n\t\t}\n\t})\n\n\t/** \"Open the picker\" filter — the kinds this reply reads, by mime and extension. */\n\tconst pickerAccept = $derived(readers?.accept ?? \"\")\n\tconst progressOf = (t: TrayItemV1) => Math.round(Math.min(Math.max(t.progress, 0), 1) * 100)\n\n\t/**\n\t * What a channel is CALLED: its declared label (`ChannelDecl.label`, the\n\t * Lair's _Sanctum_), else its slug title-cased — the conversation's one\n\t * reading (S1), so the strip and a pinned copy's head never disagree.\n\t */\n\tconst channelLabel = (slug: string) => conv.channelName(slug)\n\n\t// Unique per instance: a session page can hold more than one composer on\n\t// screen at a time, and a shared id sends every `for`/`aria-describedby` to\n\t// whichever element happens to come first in the DOM.\n\tconst uid = $props.id()\n\tconst inputId = `composer-input-${uid}`\n\tconst warningId = `composer-warning-${uid}`\n\tconst actionsId = `composer-actions-${uid}`\n\tconst paletteId = `composer-palette-${uid}`\n\tconst paletteOptionId = (i: number) => `${paletteId}-option-${i}`\n\n\tlet personaSwitcherOpen = $state(false)\n\tlet moreMenuOpen = $state(false)\n\tlet actionsOpen = $state(false)\n\tlet previewOpen = $state(false)\n\t/** The More panel currently filling the field area, or null for the field. */\n\tlet activePaneValue: string | null = $state(null)\n\n\t// Enter submits at desktop widths only; on a touch keyboard it inserts a\n\t// newline like any other textarea.\n\t// Enter sends where there is a keyboard to press it on; a narrow box (a\n\t// phone's) keeps Enter for a new line, as a touch keyboard does.\n\tconst submitOnEnter = $derived(conv.ctx.layout?.v1?.tier !== \"compact\")\n\t/** The Enter/Shift+Enter hint: shown once, remembered in the widget's saved state. */\n\tlet hintSeen = $state(true)\n\t// ⏳ A native widget has no saved state yet: the hint is remembered per\n\t// mount until it does (a remote's `state` carries it).\n\tconst saved = $derived(\n\t\t(conv.ctx as unknown as { state?: { hintSeen?: boolean } }).state\n\t)\n\t$effect(() => {\n\t\thintSeen = !!saved?.hintSeen\n\t})\n\tlet hintVisible = $state(false)\n\n\tconst activePersona = $derived(\n\t\tc?.personas.find((p) => p.personaId === c?.personaId) ?? null\n\t)\n\tconst personaCount = $derived(c?.personas.length ?? 0)\n\n\tconst tabs = $derived(c?.tabs ?? [])\n\tlet turnControls = $derived(tabs.find((t) => t.view === TURN_CONTROLS_VIEW))\n\tlet morePanes = $derived(tabs.filter((t) => t.view !== TURN_CONTROLS_VIEW))\n\tlet activePane = $derived(morePanes.find((t) => t.view === activePaneValue))\n\tlet hasActionsRow = $derived(actionsListed || !!turnControls || overflowActions.length > 0)\n\tlet overflowNew = $derived(overflowActions.filter((a) => a.isNew))\n\tlet overflowOpen = $state(false)\n\t/**\n\t * The verdict the overflow reads off a listed action (U5e): the same\n\t * `paletteRowState` the chips and the palette read, so the three cannot\n\t * disagree. The reason arrives as a locale map and is resolved here.\n\t */\n\tconst overflowRow = (a: WidgetAction) => ({\n\t\tname: a.name,\n\t\taudience: a.audience,\n\t\tcanAct: a.canAct,\n\t\tenabled: a.enabled,\n\t\tvenue: a.venue,\n\t\t...(a.reason ? { reason: i18nText(a.reason.i18n, conv.ctx.locale.v1) ?? a.reason.i18n.en } : {}),\n\t\t...(a.itemPredicates?.length ? { itemPredicates: a.itemPredicates } : {})\n\t})\n\n\t/* ── the `/` palette (R-15 slash names, F38; U5c) ──────────────────────\n\t * Typing `/` at the start of an empty draft lists the composer's actions;\n\t * the rest of the draft filters them. Escape closes it until the draft\n\t * changes; Enter invokes the highlighted row, or the exact match when\n\t * the palette is closed. The textarea stays the input — the list is a\n\t * listbox it controls (`aria-controls`, `aria-activedescendant`). */\n\t/** The query Escape was pressed on; the palette stays closed while the draft still says it. */\n\tlet paletteDismissed = $state<string | null>(null)\n\tlet paletteHighlight = $state(-1)\n\tconst paletteQuery = $derived(slashQueryOf(draft))\n\tconst paletteRows = $derived(\n\t\tpaletteQuery === null || !paletteActions.length\n\t\t\t? []\n\t\t\t: filterPaletteActions(paletteActions, paletteQuery)\n\t)\n\tconst paletteOpen = $derived(\n\t\tpaletteDismissed !== paletteQuery &&\n\t\t\tpaletteRows.length > 0 &&\n\t\t\t!hideCompose\n\t)\n\t// The highlight never points past the rows it has.\n\t$effect(() => {\n\t\tif (paletteHighlight >= paletteRows.length)\n\t\t\tpaletteHighlight = paletteRows.length ? 0 : -1\n\t})\n\t/**\n\t * What Enter runs while the palette is open: the highlighted row, else\n\t * the name typed in full, else — once the draft has narrowed the list —\n\t * its first row. A bare `/` and Enter highlights rather than fires:\n\t * nothing was named. ONE derivation, read by the key handler and by the\n\t * footer hint, so the hint cannot promise a row Enter would not run.\n\t */\n\tconst paletteEnterPick = $derived(\n\t\t!paletteOpen\n\t\t\t? undefined\n\t\t\t: paletteHighlight >= 0\n\t\t\t\t? paletteRows[paletteHighlight]\n\t\t\t\t: (exactPaletteMatch(paletteActions, draft) ??\n\t\t\t\t\t(paletteQuery ? paletteRows[0] : undefined))\n\t)\n\t// Opening the palette is meeting its newcomers.\n\t$effect(() => {\n\t\tif (!paletteOpen) return\n\t\tconst fresh = paletteRows.filter((a) => a.isNew)\n\t\tif (fresh.length) void conv.request(\"actions-seen\", { keys: fresh.map(actionIdentity) })\n\t})\n\n\t/**\n\t * Run one action. With a **slash argument** (S2) the press supplies its\n\t * text, and the draft stays until the host's run spends it (D1) — kept\n\t * on an error, or on the host's refusal of text to an action that\n\t * collects none (`/advance x`), so nothing typed is lost. Without one the\n\t * draft was only the name, and goes now.\n\t */\n\tfunction invokePalette(action: PaletteAction, argument: string | null = null) {\n\t\t// The same gate the chips and the More menu apply (S5): the\n\t\t// audience, and nothing while a reply streams.\n\t\tif (paletteRowState(action, { generating: isGenerating, newest: newestItem }).disabled)\n\t\t\treturn\n\t\tif (argument === null) setField(\"\")\n\t\tpaletteDismissed = null\n\t\tpaletteHighlight = -1\n\t\tconv.invoke(actionIdentity(action), undefined, undefined, argument ?? undefined)\n\t}\n\t/**\n\t * The draft as a whole slash name and its argument (S2), when it has one:\n\t * what Enter runs (the palette is closed once a space is typed) and what\n\t * the footer says it will do.\n\t */\n\tconst slashCommand = $derived.by(() => {\n\t\tconst command = exactSlashCommand(paletteActions, draft)\n\t\treturn command?.argument ? command : undefined\n\t})\n\tconst slashRefusal = $derived(\n\t\tslashCommand ? slashArgumentRefusal(slashCommand.action, slashCommand.argument) : null\n\t)\n\n\t/**\n\t * The keys the palette handles, which the field keeps from itself and\n\t * raises as `key`: all four while it is open, Enter alone while the draft\n\t * names an action exactly.\n\t */\n\tconst capturedKeys = $derived(\n\t\tpaletteOpen\n\t\t\t? \"ArrowUp ArrowDown Escape Enter Tab\"\n\t\t\t: exactPaletteMatch(paletteActions, draft) || (slashCommand && submitOnEnter)\n\t\t\t\t? \"Enter\"\n\t\t\t\t: \"\"\n\t)\n\n\t/** True when the key was the palette's to handle. */\n\tfunction handlePaletteKey(e: { key: string; shiftKey: boolean; preventDefault: () => void }): boolean {\n\t\tif (paletteOpen) {\n\t\t\tif (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n\t\t\t\te.preventDefault()\n\t\t\t\tpaletteHighlight = stepHighlight(\n\t\t\t\t\tpaletteHighlight,\n\t\t\t\t\tpaletteRows.length,\n\t\t\t\t\te.key === \"ArrowDown\" ? 1 : -1\n\t\t\t\t)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (e.key === \"Escape\") {\n\t\t\t\te.preventDefault()\n\t\t\t\tpaletteDismissed = paletteQuery\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (e.key === \"Enter\" && !e.shiftKey) {\n\t\t\t\te.preventDefault()\n\t\t\t\tconst pick = paletteEnterPick\n\t\t\t\tif (pick) invokePalette(pick)\n\t\t\t\telse paletteHighlight = 0\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (e.key === \"Tab\" && paletteRows.length) {\n\t\t\t\t// Complete to the highlighted (or first) name, like a shell.\n\t\t\t\te.preventDefault()\n\t\t\t\tconst pick =\n\t\t\t\t\tpaletteRows[paletteHighlight >= 0 ? paletteHighlight : 0]!\n\t\t\t\t// One that takes an argument (S2) completes with its space, ready for it.\n\t\t\t\tsetField(`/${pick.slash}${slashArgumentHint(pick) ? \" \" : \"\"}`)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t\t// Closed: `/name` + Enter still invokes an exact match, so a name\n\t\t// typed in full never needs the list.\n\t\tif (e.key === \"Enter\" && !e.shiftKey) {\n\t\t\tconst exact = exactPaletteMatch(paletteActions, draft)\n\t\t\tif (exact) {\n\t\t\t\te.preventDefault()\n\t\t\t\tinvokePalette(exact)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\t// `/nudge go north` + Enter runs Nudge with its argument (S2) —\n\t\t\t// where Enter sends; a phone's Enter keeps writing the argument's\n\t\t\t// next line, and its Send runs the command.\n\t\t\tif (slashCommand && submitOnEnter) {\n\t\t\t\te.preventDefault()\n\t\t\t\tinvokePalette(slashCommand.action, slashCommand.argument)\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tfunction handleOverflowOpen(open: boolean) {\n\t\toverflowOpen = open\n\t\tif (open && overflowNew.length)\n\t\t\tvoid conv.request(\"actions-seen\", { keys: overflowNew.map(actionIdentity) })\n\t}\n\tlet actionsLabelShown = $derived(showActions && hasActionsRow)\n\n\tlet tokenCounts = $derived(c?.usage ?? null)\n\tlet usageRatio = $derived(\n\t\ttokenCounts && tokenCounts.limit > 0\n\t\t\t? Math.min(tokenCounts.total / tokenCounts.limit, 1)\n\t\t\t: null\n\t)\n\tlet contextExceeded = $derived(\n\t\ttokenCounts ? tokenCounts.total > tokenCounts.limit : false\n\t)\n\n\tconst messages = $derived(conv.ctx.messages.v1 as Array<{ isGenerating?: boolean }>)\n\tlet isGenerating = $derived(!!messages[messages.length - 1]?.isGenerating)\n\tlet ragVisible = $derived(!!c?.notice && composerSkin !== \"minimal\")\n\t// Writing as no persona in a genre that names the person's lines (R4's\n\t// `playerLabel`, S2): \"Write as the Dungeon Master…\".\n\tlet placeholder = $derived(\n\t\tactivePersona\n\t\t\t? `Write as ${activePersona.name}…`\n\t\t\t: c?.playerLabel\n\t\t\t\t? `Write as the ${c.playerLabel}…`\n\t\t\t\t: \"Write a message…\"\n\t)\n\n\t// A pane that has gone (a lorebook unbound, context debugging switched off)\n\t// hands the field area back. A mode with no field opens on its first panel,\n\t// because there is nothing else for the area to show.\n\t$effect(() => {\n\t\tconst values = morePanes.map((p) => p.view)\n\t\tif (activePaneValue && !values.includes(activePaneValue)) {\n\t\t\tactivePaneValue = null\n\t\t}\n\t\tif (hideCompose && !activePaneValue && values.length) {\n\t\t\tactivePaneValue = values[0]\n\t\t}\n\t})\n\n\t/** The field raised a key the palette keeps (`keys`). */\n\tfunction handleFieldKey(e: CustomEvent<{ key: string; shift: boolean }>) {\n\t\tconst ev = { key: e.detail.key, shiftKey: e.detail.shift, preventDefault() {} }\n\t\tif (handlePaletteKey(ev)) return\n\t\t// Enter reached here only as a captured key: the send key, then.\n\t\tif (ev.key === \"Enter\" && !ev.shiftKey && submitOnEnter) send()\n\t}\n\n\tfunction handleFieldFocus() {\n\t\tif (hintSeen || !submitOnEnter) return\n\t\thintVisible = true\n\t\thintSeen = true\n\t\t;(conv.ctx as unknown as { saveState?: (s: object) => void }).saveState?.({ ...(saved ?? {}), hintSeen: true })\n\t}\n\n\tfunction openPane(value: string) {\n\t\tactivePaneValue = value\n\t\tpreviewOpen = false\n\t\tmoreMenuOpen = false\n\t}\n\n\t/** More › What can be attached: the panel closes, the dialog opens. */\n\tfunction openReaders() {\n\t\tmoreMenuOpen = false\n\t\treadersOpen = true\n\t}\n\n\tfunction backToCompose() {\n\t\tactivePaneValue = null\n\t}\n\n\tfunction togglePreview() {\n\t\tpreviewOpen = !previewOpen\n\t\tif (previewOpen) activePaneValue = null\n\t}\n\n\t// The row is a disclosure, not a menu: it closes on its toggle and on\n\t// Escape, never because focus left it — `src/ui/sessions/conversation/actionsDisclosure.ts` has the\n\t// table and the reason. There is deliberately no `onfocusout` here.\n\t/** Escape closes the actions row (natively; a remote hears no keys). */\n\tfunction handleKeyDown(e: KeyboardEvent) {\n\t\tif (e.key === \"Escape\" && actionsOpen && !overflowOpen) actionsOpen = false\n\t}\n</script>\n\n\n<!-- The composer's parts are `messages.composer-*` (STYLE-GUIDE §6.16): no look\n here; the default widget stylesheet draws them, and the skin\n (`data-composer-skin`) is a state a style reads. -->\n<!-- Escape closes the actions row: a keyboard shortcut over the whole group,\n not an interaction of its own (natively; a remote hears no keys). -->\n<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->\n<div\n\tdata-widget-part=\"messages.composer\"\n\tdata-composer-skin={composerSkin}\n\thidden={conv.edit.id !== null}\n\tonkeydown={handleKeyDown}\n\trole=\"group\"\n\taria-label=\"Compose\"\n>\n\t{#if c?.addPersona}\n\t\t<!-- Guests without a persona get the one thing they can do here. -->\n\t\t<div data-widget-part=\"messages.join\">\n\t\t\t<div data-widget-part=\"messages.join-text\">\n\t\t\t\t<sp-icon name=\"user-plus\" size=\"48\" data-widget-part=\"messages.join-icon\"></sp-icon>\n\t\t\t\t<h3 data-widget-part=\"messages.join-title\">Join the conversation</h3>\n\t\t\t\t<p data-widget-part=\"messages.join-note\">\n\t\t\t\t\tAdd a persona to this session to send messages.\n\t\t\t\t</p>\n\t\t\t</div>\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.join-button\"\n\t\t\t\tonclick={() => void conv.request(\"add-persona\", {})}\n\t\t\t>\n\t\t\t\t<sp-icon name=\"user-plus\" size=\"20\"></sp-icon>\n\t\t\t\tAdd your persona\n\t\t\t</button>\n\t\t</div>\n\t{:else}\n\t\t<!-- Above the composer, because a run in flight is about the message you\n\t\t are about to get rather than the ones already there — and because it\n\t\t has to stay visible while the transcript scrolls. -->\n\t\t<sp-host-view name=\"run-progress\"></sp-host-view>\n\n\t\t<div data-widget-part=\"messages.composer-disclosure\">\n\t\t\t<div data-widget-part=\"messages.composer-disclosure-bar\">\n\t\t\t\t{#if actionsLabelShown}\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tdata-widget-part=\"messages.composer-actions-toggle\"\n\t\t\t\t\t\taria-expanded={actionsOpen}\n\t\t\t\t\t\taria-controls={actionsId}\n\t\t\t\t\t\tonclick={() => (actionsOpen = !actionsOpen)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<span>Actions</span>\n\t\t\t\t\t\t<sp-icon name=\"chevron-down\" size=\"12\" data-widget-part=\"messages.composer-actions-chevron\"></sp-icon>\n\t\t\t\t\t</button>\n\t\t\t\t{/if}\n\t\t\t\t{#if ragVisible}\n\t\t\t\t\t<div data-widget-part=\"messages.composer-notice\">\n\t\t\t\t\t\t<sp-host-view name=\"retrieval-notice\"></sp-host-view>\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t</div>\n\n\t\t\t{#if actionsLabelShown && actionsOpen}\n\t\t\t\t<div\n\t\t\t\t\tid={actionsId}\n\t\t\t\t\tdata-widget-part=\"messages.composer-actions-row\"\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label=\"Session actions\"\n\t\t\t\t>\n\t\t\t\t\t<!-- ONE group, ONE chip (next-pass note 30, 2026-10-02): the turn\n\t\t\t\t\t controls first — Continue, Pick who speaks, Regenerate — then\n\t\t\t\t\t the genre's actions, then More. The page's two host views\n\t\t\t\t\t draw their chips straight into this row (the row lays out\n\t\t\t\t\t `sp-host-view`'s children as its own), so they wrap, space\n\t\t\t\t\t and look as one set. -->\n\t\t\t\t\t<div data-widget-part=\"messages.composer-actions messages.composer-chips\">\n\t\t\t\t\t\t{#if turnControls}\n\t\t\t\t\t\t\t<!-- This composer's channel's turn controls (S1): a copy pinned to the\n\t\t\t\t\t\t\t Sanctum draws the Sanctum's listing. -->\n\t\t\t\t\t\t\t<sp-host-view name=\"session-controls\" channel={conv.lane.current}></sp-host-view>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if actionsListed}\n\t\t\t\t\t\t\t<sp-host-view name=\"session-actions\" channel={conv.lane.current}></sp-host-view>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if overflowActions.length}\n\t\t\t\t\t\t\t<!-- The overflow (R-15, F38): every enabled action\n\t\t\t\t\t\t\t the primary row leaves out, never hidden by\n\t\t\t\t\t\t\t prominence. A Menu — these are actions, not a\n\t\t\t\t\t\t\t field. A newcomer marks the trigger until the\n\t\t\t\t\t\t\t menu has been opened once. -->\n\t\t\t\t\t\t\t<!-- `sp-menu` (§3.5): each `sp-menu-item`'s own content is its row. -->\n\t\t\t\t\t\t\t<sp-menu\n\t\t\t\t\t\t\t\tplacement=\"top-start\"\n\t\t\t\t\t\t\t\tlabel=\"More actions\"\n\t\t\t\t\t\t\t\topen={overflowOpen}\n\t\t\t\t\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) =>\n\t\t\t\t\t\t\t\t\thandleOverflowOpen(e.detail.open)}\n\t\t\t\t\t\t\t\tonselect={(e: CustomEvent<{ value: string }>) => {\n\t\t\t\t\t\t\t\t\tconst a = overflowActions.find(\n\t\t\t\t\t\t\t\t\t\t(x) => actionIdentity(x) === e.detail.value\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t// The wire's reason is a locale map; the palette's\n\t\t\t\t\t\t\t\t\t// shape carries a sentence, and the fire needs neither.\n\t\t\t\t\t\t\t\t\tif (a) conv.invoke(actionIdentity(a))\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\tslot=\"trigger\"\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-more-actions\"\n\t\t\t\t\t\t\t\t\ttitle=\"More actions\"\n\t\t\t\t\t\t\t\t\taria-label={overflowNew.length\n\t\t\t\t\t\t\t\t\t\t? `More actions (${overflowNew.length} new)`\n\t\t\t\t\t\t\t\t\t\t: \"More actions\"}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"ellipsis\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\t\tMore\n\t\t\t\t\t\t\t\t\t{#if overflowNew.length}\n\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-new-dot\" aria-hidden=\"true\"></span>\n\t\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{#each overflowActions as a (actionIdentity(a))}\n\t\t\t\t\t\t\t\t\t{@const iconName = a.icon || \"play\"}\n\t\t\t\t\t\t\t\t\t{@const row = paletteRowState(overflowRow(a), {\n\t\t\t\t\t\t\t\t\t\tgenerating: isGenerating,\n\t\t\t\t\t\t\t\t\t\tnewest: newestItem\n\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t<!-- Grey, listed, with its reason (R-15, U5e): the\n\t\t\t\t\t\t\t\t\t audience's word, the declared enabled-when's, or\n\t\t\t\t\t\t\t\t\t the busy rule — as a second line and to a screen\n\t\t\t\t\t\t\t\t\t reader, never dropped from the list. -->\n\t\t\t\t\t\t\t\t\t<sp-menu-item\n\t\t\t\t\t\t\t\t\t\tvalue={actionIdentity(a)}\n\t\t\t\t\t\t\t\t\t\tdisabled={row.disabled}\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-overflow-item\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name={iconName} size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t<span title={a.description}>\n\t\t\t\t\t\t\t\t\t\t\t{a.name}\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-overflow-slash\">/{a.slash}</span>\n\t\t\t\t\t\t\t\t\t\t\t{#if row.reason}\n\t\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-overflow-note\">{row.reason}</span>\n\t\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t{#if a.isNew}\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-new\">New</span>\n\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t</sp-menu-item>\n\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t</sp-menu>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t{/if}\n\t\t</div>\n\n\t\t<!-- Files dropped onto the composer, or pasted into it (a screenshot),\n\t\t join the tray; a drag shows \"Drop to attach\" (STYLE-GUIDE §6.7).\n\t\t Off where the host offers no attachments, so a paste of text is\n\t\t the field's as ever. -->\n\t\t<sp-drop-zone\n\t\t\tdata-widget-part=\"messages.composer-drop\"\n\t\t\tlabel=\"Drop to attach\"\n\t\t\tdisabled={!offersAttachments}\n\t\t\tonfiles={(e: CustomEvent<{ files: File[] }>) => {\n\t\t\t\t// Its OWN files only. An sp element's event bubbles, and the\n\t\t\t\t// Attach picker sits inside this zone — without this, one pick\n\t\t\t\t// staged every file twice (found in the 2026-10-02 live check).\n\t\t\t\tif (e.target !== e.currentTarget) return\n\t\t\t\tvoid attachFiles(e.detail.files)\n\t\t\t}}\n\t\t>\n\t\t<div data-widget-part=\"messages.composer-card\">\n\t\t\t{#if usageRatio !== null}\n\t\t\t\t<!-- The draft's share of the context window, read along the card's\n\t\t\t\t top edge rather than as a number, so it costs no row. -->\n\t\t\t\t<div\n\t\t\t\t\tdata-widget-part=\"messages.composer-meter\"\n\t\t\t\t\trole=\"progressbar\"\n\t\t\t\t\taria-label=\"Context window used\"\n\t\t\t\t\taria-valuemin={0}\n\t\t\t\t\taria-valuemax={100}\n\t\t\t\t\taria-valuenow={Math.round(usageRatio * 100)}\n\t\t\t\t>\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.composer-meter-fill\"\n\t\t\t\t\t\tdata-high={usageRatio > 0.9 ? \"\" : undefined}\n\t\t\t\t\t\tstyle=\"--sp-fill: {(usageRatio * 100).toFixed(1)}%\"\n\t\t\t\t\t></div>\n\t\t\t\t</div>\n\t\t\t{/if}\n\n\t\t\t<div data-widget-part=\"messages.composer-body\">\n\t\t\t\t{#if activePane}\n\t\t\t\t\t<div data-widget-part=\"messages.composer-pane-head\">\n\t\t\t\t\t\t<span data-widget-part=\"messages.composer-pane-title\">\n\t\t\t\t\t\t\t{activePane.title}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t{#if !hideCompose}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-back\"\n\t\t\t\t\t\t\t\tonclick={backToCompose}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"arrow-left\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\tBack to compose\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</div>\n\t\t\t\t\t<div role=\"region\" aria-label=\"{activePane.title} panel\">\n\t\t\t\t\t\t<sp-host-view name={activePane.view}></sp-host-view>\n\t\t\t\t\t</div>\n\t\t\t\t{:else if previewOpen}\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.composer-preview\"\n\t\t\t\t\t\trole=\"region\"\n\t\t\t\t\t\taria-label=\"Message preview\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-message-body text={draft}></sp-message-body>\n\t\t\t\t\t</div>\n\t\t\t\t{:else if !hideCompose}\n\t\t\t\t\t{#if paletteOpen}\n\t\t\t\t\t\t<!-- The `/` palette: the composer's actions by slash\n\t\t\t\t\t\t name, filtered by the draft. A listbox the field\n\t\t\t\t\t\t controls; Enter invokes, Escape closes, Tab\n\t\t\t\t\t\t completes the name. -->\n\t\t\t\t\t\t<ul\n\t\t\t\t\t\t\tid={paletteId}\n\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-palette\"\n\t\t\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\t\t\taria-label=\"Slash commands\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{#each paletteRows as a, i (a.slash)}\n\t\t\t\t\t\t\t\t{@const iconName = a.icon || \"play\"}\n\t\t\t\t\t\t\t\t{@const rowState = paletteRowState(a, {\n\t\t\t\t\t\t\t\t\tgenerating: isGenerating,\n\t\t\t\t\t\t\t\t\tnewest: newestItem\n\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t{@const argHint = slashArgumentHint(a)}\n\t\t\t\t\t\t\t\t<!-- The highlighted row is its `aria-selected`, a row the\n\t\t\t\t\t\t\t\t audience or a reply in flight refuses its `aria-disabled`. -->\n\t\t\t\t\t\t\t\t<li\n\t\t\t\t\t\t\t\t\tid={paletteOptionId(i)}\n\t\t\t\t\t\t\t\t\trole=\"option\"\n\t\t\t\t\t\t\t\t\taria-selected={i === paletteHighlight}\n\t\t\t\t\t\t\t\t\taria-disabled={rowState.disabled}\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-palette-row\"\n\t\t\t\t\t\t\t\t>\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=\"messages.composer-palette-button\"\n\t\t\t\t\t\t\t\t\t\ttabindex=\"-1\"\n\t\t\t\t\t\t\t\t\t\tdisabled={rowState.disabled}\n\t\t\t\t\t\t\t\t\t\tonmousedown={(e) => e.preventDefault()}\n\t\t\t\t\t\t\t\t\t\tonmouseenter={() => (paletteHighlight = i)}\n\t\t\t\t\t\t\t\t\t\tonclick={() => invokePalette(a)}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name={iconName} size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-palette-slash\">/{a.slash}</span>\n\t\t\t\t\t\t\t\t\t\t{#if argHint}\n\t\t\t\t\t\t\t\t\t\t\t<!-- The argument it takes (S2): `/nudge <direction…>`. -->\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-palette-argument\">{argHint}</span>\n\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-palette-label\">{a.name}</span>\n\t\t\t\t\t\t\t\t\t\t{#if a.isNew}\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-new\">New</span>\n\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t{#if rowState.reason}\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-palette-note\">{rowState.reason}</span>\n\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t{/if}\n\t\t\t\t\t<!-- The field inside takes focus and carries the ARIA: this is its\n\t\t\t\t\t host element; the field itself is its child `textarea`. -->\n\t\t\t\t\t<!-- svelte-ignore a11y_aria_activedescendant_has_tabindex -->\n\t\t\t\t\t<sp-composer-field\n\t\t\t\t\t\tdata-widget-part=\"messages.composer-field\"\n\t\t\t\t\t\trows=\"1\"\n\t\t\t\t\t\tlabel=\"Write a message\"\n\t\t\t\t\t\t{placeholder}\n\t\t\t\t\t\tsubmit-on={submitOnEnter ? \"enter\" : \"none\"}\n\t\t\t\t\t\tkeys={capturedKeys}\n\t\t\t\t\t\tspellcheck=\"true\"\n\t\t\t\t\t\taria-describedby={contextExceeded ? warningId : undefined}\n\t\t\t\t\t\taria-invalid={contextExceeded ? \"true\" : undefined}\n\t\t\t\t\t\taria-autocomplete={paletteActions.length ? \"list\" : undefined}\n\t\t\t\t\t\taria-controls={paletteOpen ? paletteId : undefined}\n\t\t\t\t\t\taria-activedescendant={paletteOpen && paletteHighlight >= 0\n\t\t\t\t\t\t\t? paletteOptionId(paletteHighlight)\n\t\t\t\t\t\t\t: undefined}\n\t\t\t\t\t\toninput={(e: CustomEvent<{ value: string }>) => (draft = e.detail.value)}\n\t\t\t\t\t\tonsubmit={(e: CustomEvent<{ value: string }>) => {\n\t\t\t\t\t\t\tdraft = e.detail.value\n\t\t\t\t\t\t\tsend()\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonkey={handleFieldKey}\n\t\t\t\t\t\tonfocus={handleFieldFocus}\n\t\t\t\t\t\t{@attach writeField}\n\t\t\t\t\t></sp-composer-field>\n\t\t\t\t{/if}\n\t\t\t</div>\n\n\t\t\t{#if offersAttachments && (tray.length || refusedHere.length)}\n\t\t\t\t<!-- The tray: this line's attachments, uploading, ready or\n\t\t\t\t refused. A row of tiles that scrolls sideways on a phone. -->\n\t\t\t\t<ul data-widget-part=\"messages.composer-tray\" aria-label=\"Attachments\">\n\t\t\t\t\t{#each tray as t (t.id)}\n\t\t\t\t\t\t<li\n\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-tray-item\"\n\t\t\t\t\t\t\tdata-status={t.status}\n\t\t\t\t\t\t\tdata-kind={t.kind ?? undefined}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{#if t.thumbSrc}\n\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-tray-thumb\"\n\t\t\t\t\t\t\t\t\tsrc={t.thumbSrc}\n\t\t\t\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\t\t\t\tloading=\"lazy\"\n\t\t\t\t\t\t\t\t\tdecoding=\"async\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t<sp-icon\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-tray-icon\"\n\t\t\t\t\t\t\t\t\tname={t.kind === \"image\" ? \"image\" : \"file-text\"}\n\t\t\t\t\t\t\t\t\tsize=\"20\"\n\t\t\t\t\t\t\t\t></sp-icon>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-tray-name\" title={t.filename}>{t.filename}</span>\n\t\t\t\t\t\t\t{#if t.status === \"uploading\"}\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-tray-progress\"\n\t\t\t\t\t\t\t\t\trole=\"progressbar\"\n\t\t\t\t\t\t\t\t\taria-label=\"Uploading {t.filename}\"\n\t\t\t\t\t\t\t\t\taria-valuemin={0}\n\t\t\t\t\t\t\t\t\taria-valuemax={100}\n\t\t\t\t\t\t\t\t\taria-valuenow={progressOf(t)}\n\t\t\t\t\t\t\t\t\tstyle=\"--sp-fill: {progressOf(t)}%\"\n\t\t\t\t\t\t\t\t></span>\n\t\t\t\t\t\t\t{:else if t.status === \"refused\"}\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-tray-refusal\">{t.refusal ?? \"Not attached.\"}</span>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-tray-remove\"\n\t\t\t\t\t\t\t\taria-label=\"Remove {t.filename}\"\n\t\t\t\t\t\t\t\ttitle=\"Remove\"\n\t\t\t\t\t\t\t\tonclick={() => removeTrayItem(t)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"x\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</li>\n\t\t\t\t\t{/each}\n\t\t\t\t\t{#each refusedHere as r (r.key)}\n\t\t\t\t\t\t<li data-widget-part=\"messages.composer-tray-item\" data-status=\"refused\">\n\t\t\t\t\t\t\t<sp-icon data-widget-part=\"messages.composer-tray-icon\" name=\"ban\" size=\"20\"></sp-icon>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-tray-name\" title={r.filename}>{r.filename}</span>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-tray-refusal\">{r.reason}</span>\n\t\t\t\t\t\t</li>\n\t\t\t\t\t{/each}\n\t\t\t\t</ul>\n\t\t\t{/if}\n\t\t\t<div data-widget-part=\"messages.composer-footer\">\n\t\t\t\t<!-- Which channel this line lands on. Drawn only when there is\n\t\t\t\t a choice: one channel is every session that exists today,\n\t\t\t\t and a picker with one option is a control that teaches\n\t\t\t\t nothing. The chosen one is its `aria-pressed`. -->\n\t\t\t\t{#if channels.length > 1}\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.composer-channels\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label=\"Which channel you are writing on\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{#each channels as slug (slug)}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-channel\"\n\t\t\t\t\t\t\t\taria-pressed={slug === conv.lane.current}\n\t\t\t\t\t\t\t\ttitle=\"Write on {channelLabel(slug)}\"\n\t\t\t\t\t\t\t\tonclick={() => conv.lane.set(slug)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{channelLabel(slug)}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t\t{#if activePersona}\n\t\t\t\t\t{#if personaCount > 1}\n\t\t\t\t\t\t<!-- `sp-popover` (§3.5): our button is the trigger, the card the panel. -->\n\t\t\t\t\t\t<sp-popover\n\t\t\t\t\t\t\tplacement=\"top-start\"\n\t\t\t\t\t\t\topen={personaSwitcherOpen}\n\t\t\t\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => (personaSwitcherOpen = e.detail.open)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<button slot=\"trigger\" type=\"button\" data-widget-part=\"messages.composer-persona\"\n\t\t\t\t\t\t\t\ttitle=\"Switch persona\"\n\t\t\t\t\t\t\t\taria-label=\"Switch persona (currently {activePersona.name})\">\n\t\t\t\t\t\t\t\t<sp-avatar ref={`character:${activePersona.personaId}`} size=\"sm\"></sp-avatar>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-persona-name\">\n\t\t\t\t\t\t\t\t\t{activePersona.name}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t<sp-icon name=\"chevron-down\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.composer-persona-menu\">\n\t\t\t\t\t\t\t\t<p data-widget-part=\"messages.composer-persona-menu-title\">\n\t\t\t\t\t\t\t\t\tWrite as\n\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t{#each c?.personas ?? [] as p (p.personaId)}\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=\"messages.composer-persona-option\"\n\t\t\t\t\t\t\t\t\t\taria-current={p.personaId === c?.personaId ? \"true\" : undefined}\n\t\t\t\t\t\t\t\t\t\tonclick={() => {\n\t\t\t\t\t\t\t\t\t\t\tvoid conv.request(\"switch-persona\", { personaId: p.personaId })\n\t\t\t\t\t\t\t\t\t\t\tpersonaSwitcherOpen = false\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-avatar ref={`character:${p.personaId}`} size=\"sm\"></sp-avatar>\n\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-persona-option-name\">{p.name}</span>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</sp-popover>\n\t\t\t\t\t{:else}\n\t\t\t\t\t\t<span data-widget-part=\"messages.composer-persona\">\n\t\t\t\t\t\t\t<sp-avatar ref={`character:${activePersona.personaId}`} size=\"sm\"></sp-avatar>\n\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-persona-name\">\n\t\t\t\t\t\t\t\t{activePersona.name}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t{/if}\n\t\t\t\t{/if}\n\n\t\t\t\t<div data-widget-part=\"messages.composer-footer-end\">\n\t\t\t\t\t{#if offersAttachments}\n\t\t\t\t\t\t<!-- Attach: the device's picker, filtered to what this reply\n\t\t\t\t\t\t reads. Its body is our own button; the picker is the\n\t\t\t\t\t\t page's (`sp-file-picker`). -->\n\t\t\t\t\t\t<sp-file-picker\n\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-attach\"\n\t\t\t\t\t\t\taccept={pickerAccept || undefined}\n\t\t\t\t\t\t\tmultiple={true}\n\t\t\t\t\t\t\tonfiles={(e: CustomEvent<{ files: File[] }>) => void attachFiles(e.detail.files)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-attach-button messages.composer-icon-button\"\n\t\t\t\t\t\t\t\ttitle={readersLine ? `Attach files. ${readersLine}` : \"Attach files\"}\n\t\t\t\t\t\t\t\taria-label=\"Attach files\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"paperclip\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</sp-file-picker>\n\t\t\t\t\t{/if}\n\t\t\t\t\t{#if !hideCompose}\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-preview-toggle messages.composer-icon-button\"\n\t\t\t\t\t\t\taria-pressed={previewOpen}\n\t\t\t\t\t\t\ttitle=\"Preview\"\n\t\t\t\t\t\t\taria-label=\"Preview the formatted draft\"\n\t\t\t\t\t\t\tonclick={togglePreview}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"eye\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t{/if}\n\n\t\t\t\t\t{#if morePanes.length > 0 || readersOffered}\n\t\t\t\t\t\t<!-- `sp-popover` (§3.5): our button is the trigger, the card the panel.\n\t\t\t\t\t\t A panel filling the field area marks it `data-active`. Under\n\t\t\t\t\t\t the panes, **What can be attached** opens the readers dialog\n\t\t\t\t\t\t (note 41) — so it is here in every skin, panes or none. -->\n\t\t\t\t\t\t<sp-popover\n\t\t\t\t\t\t\tplacement=\"top-end\"\n\t\t\t\t\t\t\topen={moreMenuOpen}\n\t\t\t\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => (moreMenuOpen = e.detail.open)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<button slot=\"trigger\" type=\"button\" data-widget-part=\"messages.composer-more messages.composer-icon-button\"\n\t\t\t\t\t\t\t\tdata-active={activePane ? \"\" : undefined}\n\t\t\t\t\t\t\t\ttitle=\"More\"\n\t\t\t\t\t\t\t\taria-label=\"More\">\n\t\t\t\t\t\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.composer-panes\">\n\t\t\t\t\t\t\t\t\t\t<header data-widget-part=\"messages.composer-panes-title\">\n\t\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"ellipsis-vertical\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t\t<p>More</p>\n\t\t\t\t\t\t\t\t\t\t</header>\n\t\t\t\t\t\t\t\t\t\t<div data-widget-part=\"messages.composer-panes-list\">\n\t\t\t\t\t\t\t\t\t\t\t{#each morePanes as pane (pane.view)}\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=\"messages.composer-pane-option\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata-current={activePaneValue === pane.view ? \"\" : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\topenPane(pane.view)}\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<sp-icon name={pane.icon} size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span>{pane.title}</span>\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{/each}\n\t\t\t\t\t\t\t\t\t\t\t{#if readersOffered}\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=\"messages.composer-pane-option messages.composer-readers-button\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tonclick={openReaders}\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<sp-icon name=\"paperclip\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span>What can be attached</span>\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{/if}\n\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</sp-popover>\n\t\t\t\t\t{/if}\n\n\t\t\t\t\t{#if !hideCompose}\n\t\t\t\t\t\t{#if isGenerating}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-stop\"\n\t\t\t\t\t\t\t\ttitle=\"Stop\"\n\t\t\t\t\t\t\t\taria-label=\"Stop generating\"\n\t\t\t\t\t\t\t\tonclick={() => conv.invoke(\"stop\")}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"square\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Stop</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t<!-- Someone due next (`data-someone-due`): Send steps back. -->\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.composer-send\"\n\t\t\t\t\t\t\t\tdata-someone-due={sendTonal ? \"\" : undefined}\n\t\t\t\t\t\t\t\tdisabled={!draft.trim() && !hasAttachments}\n\t\t\t\t\t\t\t\ttitle=\"Send\"\n\t\t\t\t\t\t\t\taria-label=\"Send message\"\n\t\t\t\t\t\t\t\tonclick={send}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"send\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>Send</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t{/if}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t\t</sp-drop-zone>\n\n\t\t{#if offersAttachments}\n\t\t\t<!-- Attachments said aloud: \"cat.png attached\", a refusal, a removal. -->\n\t\t\t<p data-widget-part=\"messages.composer-announce\" aria-live=\"polite\">{announcement}</p>\n\t\t{/if}\n\t\t{#if readersOffered}\n\t\t\t<!-- What this reply can read (§3.2; note 41): out of the composer's\n\t\t\t body, opened from More. The summary, every kind with the reason\n\t\t\t a refused one can't be attached, and each model call's reading.\n\t\t\t A refusal at the moment of a pick or a drop still says why on\n\t\t\t its own tile, and aloud. -->\n\t\t\t<sp-dialog\n\t\t\t\tlabel=\"What can be attached\"\n\t\t\t\topen={readersOpen}\n\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => (readersOpen = e.detail.open)}\n\t\t\t>\n\t\t\t\t<span slot=\"title\">What can be attached</span>\n\t\t\t\t<div data-widget-part=\"messages.composer-readers\">\n\t\t\t\t\t<p data-widget-part=\"messages.composer-readers-line\">{readersLine}</p>\n\t\t\t\t\t<ul data-widget-part=\"messages.composer-readers-kinds\" aria-label=\"Kinds of file\">\n\t\t\t\t\t\t{#each ATTACHMENT_KINDS_V1 as k (k)}\n\t\t\t\t\t\t\t{@const v = readers?.kinds[k]}\n\t\t\t\t\t\t\t<li data-widget-part=\"messages.composer-readers-kind\" data-allowed={v?.allowed ? \"\" : undefined}>\n\t\t\t\t\t\t\t\t<strong>{KIND_NAME[k]}</strong>\n\t\t\t\t\t\t\t\t<span>({KIND_FORMATS[k]})</span>\n\t\t\t\t\t\t\t\t{#if v?.allowed}\n\t\t\t\t\t\t\t\t\t<span> — can be attached</span>\n\t\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.composer-readers-reason\"> — can't be attached. {v?.reason ?? \"\"}</span>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</ul>\n\t\t\t\t\t{#if readerLines.length}\n\t\t\t\t\t\t<ul data-widget-part=\"messages.composer-readers-calls\" aria-label=\"Each model call\">\n\t\t\t\t\t\t\t{#each readerLines as line (line)}\n\t\t\t\t\t\t\t\t<li>{line}</li>\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t{/if}\n\t\t\t\t</div>\n\t\t\t</sp-dialog>\n\t\t{/if}\n\t\t{#if sendWaiting && uploading}\n\t\t\t<p data-widget-part=\"messages.composer-hint\" aria-live=\"polite\">{uploading} Sends when done.</p>\n\t\t{/if}\n\n\t\t{#if contextExceeded}\n\t\t\t<p\n\t\t\t\tid={warningId}\n\t\t\t\tdata-widget-part=\"messages.composer-warning\"\n\t\t\t\trole=\"alert\"\n\t\t\t>\n\t\t\t\tThis draft pushes the prompt past the context limit. Older turns\n\t\t\t\twill be trimmed.\n\t\t\t</p>\n\t\t{/if}\n\n\t\t{#if paletteOpen}\n\t\t\t<!-- While the palette is open Enter does not send: it runs the\n\t\t\t row it would pick (the same derivation the key handler reads),\n\t\t\t or — a bare `/` with nothing highlighted — only highlights. -->\n\t\t\t<p data-widget-part=\"messages.composer-hint\" aria-live=\"polite\">\n\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">Enter</kbd>\n\t\t\t\t{#if paletteEnterPick}\n\t\t\t\t\truns /{paletteEnterPick.slash}\n\t\t\t\t{:else}\n\t\t\t\t\thighlights the first ·\n\t\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">↑</kbd>\n\t\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">↓</kbd>\n\t\t\t\t\tto choose\n\t\t\t\t{/if}\n\t\t\t\t·\n\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">Esc</kbd>\n\t\t\t\tcloses.\n\t\t\t</p>\n\t\t{:else if slashCommand}\n\t\t\t<!-- A whole slash name and its argument (S2): what Enter (or Send)\n\t\t\t will do with it — or why it will not. -->\n\t\t\t<p\n\t\t\t\tdata-widget-part=\"messages.composer-hint\"\n\t\t\t\tdata-refused={slashRefusal ? \"\" : undefined}\n\t\t\t\taria-live=\"polite\"\n\t\t\t>\n\t\t\t\t{#if slashRefusal}\n\t\t\t\t\t{slashRefusal}.\n\t\t\t\t{:else}\n\t\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">{submitOnEnter ? \"Enter\" : \"Send\"}</kbd>\n\t\t\t\t\truns /{slashCommand.action.slash} with your text.\n\t\t\t\t{/if}\n\t\t\t</p>\n\t\t{:else if hintVisible && submitOnEnter}\n\t\t\t<p data-widget-part=\"messages.composer-hint\">\n\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">Enter</kbd>\n\t\t\t\tsends.\n\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">Shift</kbd>\n\t\t\t\t<kbd data-widget-part=\"messages.composer-key\">Enter</kbd>\n\t\t\t\tfor a new line.\n\t\t\t</p>\n\t\t{/if}\n\t{/if}\n</div>\n","sessions/messages/SessionContainer.svelte":"<script lang=\"ts\">\n\timport { untrack } from \"svelte\"\n\timport {\n\t\tconversationIndex,\n\t\torderedMessages,\n\t\ttype ConversationSceneV1,\n\t\ttype MessageOrder\n\t} from \"@serene-pub/core-catalog/conversation\"\n\timport SessionMessage from \"./SessionMessage.svelte\"\n\timport { scopeNotGranted } from \"@serene-pub/core-catalog/widgets\"\n\timport { useConversation } from \"./conversation.svelte\"\n\timport type { MessageV1 } from \"@serene-pub/sdk/component\"\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\n\t// Visually distinct, readable scene colors (work in both light and dark)\n\tconst SCENE_COLORS = [\n\t\t{\n\t\t\tbar: \"hsl(220,65%,62%)\",\n\t\t\ttext: \"hsl(220,65%,65%)\",\n\t\t\tbg: \"hsl(220,65%,62%,0.10)\"\n\t\t}, // blue\n\t\t{\n\t\t\tbar: \"hsl(150,52%,48%)\",\n\t\t\ttext: \"hsl(150,52%,52%)\",\n\t\t\tbg: \"hsl(150,52%,48%,0.10)\"\n\t\t}, // green\n\t\t{\n\t\t\tbar: \"hsl(35, 75%,55%)\",\n\t\t\ttext: \"hsl(35, 75%,58%)\",\n\t\t\tbg: \"hsl(35, 75%,55%,0.10)\"\n\t\t}, // amber\n\t\t{\n\t\t\tbar: \"hsl(280,55%,62%)\",\n\t\t\ttext: \"hsl(280,55%,66%)\",\n\t\t\tbg: \"hsl(280,55%,62%,0.10)\"\n\t\t}, // purple\n\t\t{\n\t\t\tbar: \"hsl(340,60%,58%)\",\n\t\t\ttext: \"hsl(340,60%,62%)\",\n\t\t\tbg: \"hsl(340,60%,58%,0.10)\"\n\t\t}, // rose\n\t\t{\n\t\t\tbar: \"hsl(190,60%,48%)\",\n\t\t\ttext: \"hsl(190,60%,52%)\",\n\t\t\tbg: \"hsl(190,60%,48%,0.10)\"\n\t\t}, // teal\n\t\t{\n\t\t\tbar: \"hsl(55, 70%,50%)\",\n\t\t\ttext: \"hsl(55, 70%,54%)\",\n\t\t\tbg: \"hsl(55, 70%,50%,0.10)\"\n\t\t}, // yellow\n\t\t{\n\t\t\tbar: \"hsl(15, 70%,55%)\",\n\t\t\ttext: \"hsl(15, 70%,59%)\",\n\t\t\tbg: \"hsl(15, 70%,55%,0.10)\"\n\t\t} // orange\n\t]\n\n\t// Props for customizing the components used\n\t/**\n\t * The conversation's log (C0b): the widget's own part. It draws what the\n\t * conversation holds — the rows off the widget context, the scenes off the\n\t * page's dossier — in a host-measured scroll region (`sp-scroll`), and asks\n\t * for older rows when the reader reaches the far end.\n\t */\n\tinterface Props {\n\t\torder?: MessageOrder\n\t\tshowSceneMarkers?: boolean\n\t}\n\n\tlet { order = \"oldest-first\", showSceneMarkers = true }: Props = $props()\n\n\tconst conv = useConversation()\n\t// This copy's rows (S1): its channels', so a channel another copy claims\n\t// is never drawn here, not even hidden.\n\tconst messages = $derived(conv.rows)\n\tconst sceneList = $derived(conv.dossier?.scenes ?? [])\n\tconst loadingOlderMessages = $derived(!!conv.dossier?.loadingOlder)\n\tconst loaded = $derived(!!conv.dossier)\n\t/**\n\t * The host said this widget does not hold `session:full` (a plugin's copy\n\t * not granted it): the dossier will never come, so \"Loading session…\"\n\t * would spin forever — it is said instead.\n\t */\n\tconst dossierNotGranted = $derived(scopeNotGranted(conv.ctx, \"session:full\"))\n\n\t/** Older rows, asked for once per reach of the far end. */\n\tfunction loadOlder() {\n\t\tif (!conv.dossier?.hasOlder || conv.dossier.loadingOlder) return\n\t\tvoid conv.request(\"messages\", {})\n\t}\n\t/** The lore panel, at a history entry, a scene, or a new entry. */\n\tconst openLore = (params: {\n\t\tlorebookId: number\n\t\tscope: \"history\" | \"scenes\"\n\t\tentryId?: number\n\t\tsceneId?: number\n\t\tcreate?: boolean\n\t}) => void conv.request(\"open-lore\", params)\n\n\ttype MsgSceneInfo = {\n\t\tscene: ConversationSceneV1\n\t\tisFirstInScene: boolean\n\t\tisLastInScene: boolean\n\t\thistoryEntry: ConversationSceneV1[\"historyEntry\"]\n\t\tisFirstOfEntry: boolean\n\t\tisLastOfEntry: boolean\n\t\tcolorIndex: number\n\t}\n\n\t// Lightweight signal capturing only the message *set and order* (ids), not\n\t// their content. The parent replaces the whole `messages` array\n\t// reference on every streamed chunk even when only one message's content\n\t// changed, which would otherwise force the expensive O(scenes × messages)\n\t// derivation below to fully recompute on every token.\n\tlet msgOrderKey = $derived(messages.map((m) => m.id).join(\",\"))\n\n\tlet msgSceneMap = $derived.by((): Map<number, MsgSceneInfo> => {\n\t\t// Track sceneList and msgOrderKey as the real dependencies here. The\n\t\t// heavy work below (which reads messages directly) is wrapped\n\t\t// in untrack() so a messages reference change alone doesn't\n\t\t// dirty this derived — only a change in msgOrderKey's *value* (i.e. the\n\t\t// message ids/order actually changing) or sceneList does.\n\t\tvoid sceneList.length\n\t\tvoid msgOrderKey\n\n\t\t// An empty map is what \"no scene markers\" means everywhere below: no\n\t\t// divider, no chip, no coloured bar, and none of the work to find them.\n\t\tif (!showSceneMarkers) return new Map()\n\t\treturn untrack(buildMsgSceneMap)\n\t})\n\n\t/** The messages in the sequence this log draws them, `order` applied. */\n\tlet drawnMessages = $derived(\n\t\torderedMessages(messages, order)\n\t)\n\n\tfunction buildMsgSceneMap(): Map<number, MsgSceneInfo> {\n\t\tconst map = new Map<number, MsgSceneInfo>()\n\t\tif (!sceneList.length || !messages.length) return map\n\n\t\t// Build messageId → scene lookup\n\t\tconst messageToScene = new Map<number, ConversationSceneV1>()\n\t\tfor (const scene of sceneList) {\n\t\t\tfor (const msgId of scene.selectedMessageIds ?? []) {\n\t\t\t\tmessageToScene.set(msgId, scene)\n\t\t\t}\n\t\t}\n\n\t\t// For each scene, find its first/last message IDs in session display order\n\t\tconst sceneBounds = new Map<number, { first: number; last: number }>()\n\t\tfor (const scene of sceneList) {\n\t\t\tconst ids = new Set(scene.selectedMessageIds ?? [])\n\t\t\tif (!ids.size) continue\n\t\t\tconst ordered = messages\n\t\t\t\t.filter((m) => ids.has(m.id))\n\t\t\t\t.map((m) => m.id)\n\t\t\tif (ordered.length)\n\t\t\t\tsceneBounds.set(scene.id, {\n\t\t\t\t\tfirst: ordered[0],\n\t\t\t\t\tlast: ordered[ordered.length - 1]\n\t\t\t\t})\n\t\t}\n\n\t\t// For each history entry, find the last message across all its scenes\n\t\tconst entryLastMsgIndex = new Map<number, number>()\n\t\tfor (const scene of sceneList) {\n\t\t\tif (!scene.historyEntryId) continue\n\t\t\tconst bounds = sceneBounds.get(scene.id)\n\t\t\tif (!bounds) continue\n\t\t\tconst idx = messages.findIndex(\n\t\t\t\t(m) => m.id === bounds.last\n\t\t\t)\n\t\t\tconst current = entryLastMsgIndex.get(scene.historyEntryId) ?? -1\n\t\t\tif (idx > current) entryLastMsgIndex.set(scene.historyEntryId, idx)\n\t\t}\n\t\tconst entryLastMsgId = new Map<number, number>()\n\t\tfor (const [entryId, idx] of entryLastMsgIndex) {\n\t\t\tentryLastMsgId.set(entryId, messages[idx].id)\n\t\t}\n\n\t\t// Assign colors in the order scenes first appear in the session\n\t\tconst sceneColorIndex = new Map<number, number>()\n\t\tlet colorCounter = 0\n\t\tfor (const msg of messages) {\n\t\t\tconst scene = messageToScene.get(msg.id)\n\t\t\tif (scene && !sceneColorIndex.has(scene.id)) {\n\t\t\t\tsceneColorIndex.set(\n\t\t\t\t\tscene.id,\n\t\t\t\t\tcolorCounter % SCENE_COLORS.length\n\t\t\t\t)\n\t\t\t\tcolorCounter++\n\t\t\t}\n\t\t}\n\n\t\t// Walk messages in display order to build the full map\n\t\tconst seenEntryIds = new Set<number>()\n\t\tfor (const msg of messages) {\n\t\t\tconst scene = messageToScene.get(msg.id)\n\t\t\tif (!scene) continue\n\t\t\tconst bounds = sceneBounds.get(scene.id)\n\t\t\tif (!bounds) continue\n\n\t\t\tconst isFirstInScene = bounds.first === msg.id\n\t\t\tconst isLastInScene = bounds.last === msg.id\n\t\t\tconst entryId = scene.historyEntryId\n\t\t\tconst isFirstOfEntry =\n\t\t\t\tisFirstInScene && !!entryId && !seenEntryIds.has(entryId)\n\t\t\tif (isFirstOfEntry) seenEntryIds.add(entryId)\n\t\t\tconst isLastOfEntry =\n\t\t\t\t!!entryId && entryLastMsgId.get(entryId) === msg.id\n\n\t\t\tmap.set(msg.id, {\n\t\t\t\tscene,\n\t\t\t\tisFirstInScene,\n\t\t\t\tisLastInScene,\n\t\t\t\thistoryEntry: scene.historyEntry,\n\t\t\t\tisFirstOfEntry,\n\t\t\t\tisLastOfEntry,\n\t\t\t\tcolorIndex: sceneColorIndex.get(scene.id) ?? 0\n\t\t\t})\n\t\t}\n\n\t\treturn map\n\t}\n\n\tfunction formatEntryDate(he: {\n\t\tyear: number\n\t\tmonth: number | null\n\t\tday: number | null\n\t}): string {\n\t\tlet s = `Year ${he.year}`\n\t\tif (he.month) s += `, Mo. ${he.month}`\n\t\tif (he.day) s += `, Day ${he.day}`\n\t\treturn s\n\t}\n</script>\n\n<!-- The log's parts (`messages.*`, STYLE-GUIDE §6.16): no look here; the\n default widget stylesheet draws them. -->\n<div data-widget-part=\"messages.log-body\">\n\t<!-- The host measures and scrolls (`sp-scroll`): pinned to the newest end\n\t as rows arrive, held still when the reader has scrolled away, and\n\t `reach-start` at the far end asks for older rows. -->\n\t<sp-scroll\n\t\tdata-widget-part=\"messages.log-scroll\"\n\t\tstick={order === \"newest-first\" ? \"top\" : \"bottom\"}\n\t\tlabel=\"Session messages\"\n\t\tonreach-start={loadOlder}\n\t>\n\t<!-- The region spans the panel; the rows (the stage, `messages.stage`)\n\t take its full width, or a centred measure under Line width:\n\t Comfortable. -->\n\t<div\n\t\tid=\"session-history\"\n\t\tdata-widget-part=\"messages.stage\"\n\t\trole=\"log\"\n\t\taria-live=\"polite\"\n\t\taria-atomic=\"false\"\n\t>\n\t\t<div data-widget-part=\"messages.stage-body\">\n\t\t\t{#if !loaded && dossierNotGranted}\n\t\t\t\t<div data-widget-part=\"messages.log-note messages.log-floor\" role=\"status\" data-scope-not-granted=\"session:full\">\n\t\t\t\t\t<sp-icon name=\"lock\" size=\"28\" data-widget-part=\"messages.log-floor-icon\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"messages.log-floor-text\">\n\t\t\t\t\t\t{conv.t(\"This widget has not been granted the whole conversation. An administrator can grant it in the extension's permissions.\")}\n\t\t\t\t\t</span>\n\t\t\t\t</div>\n\t\t\t{:else if !loaded}\n\t\t\t\t<!-- Still loading the session itself — distinct from a genuinely\n\t\t\t\t empty session below, otherwise \"No messages yet.\" flashes on\n\t\t\t\t every session open even when it has hundreds of messages. -->\n\t\t\t\t<div data-widget-part=\"messages.log-loading messages.log-floor\">\n\t\t\t\t\t<sp-icon name=\"loader-2\" size=\"28\" data-widget-part=\"messages.log-floor-icon messages.log-loading-icon\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"messages.log-floor-text\">Loading session…</span>\n\t\t\t\t</div>\n\t\t\t{:else if messages.length === 0}\n\t\t\t\t<div data-widget-part=\"messages.log-empty messages.log-floor empty\">\n\t\t\t\t\t<sp-icon name=\"message-square-text\" size=\"28\" data-widget-part=\"messages.log-floor-icon\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"messages.log-floor-text\">Send a message to start</span>\n\t\t\t\t</div>\n\t\t\t{:else}\n\t\t\t\t<!-- The older messages arrive at whichever end they are drawn\n\t\t\t\t at, so the indicator for them sits at that end too. -->\n\t\t\t\t{#snippet olderMessagesLoading()}\n\t\t\t\t\t{#if loadingOlderMessages}\n\t\t\t\t\t\t<div data-widget-part=\"messages.older-loading\">\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.older-loading-body\">\n\t\t\t\t\t\t\t\t<sp-icon name=\"loader-2\" size=\"16\" data-widget-part=\"messages.older-loading-icon\"></sp-icon>\n\t\t\t\t\t\t\t\tLoading older messages...\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t{/if}\n\t\t\t\t{/snippet}\n\t\t\t\t{#if order === \"oldest-first\"}\n\t\t\t\t\t{@render olderMessagesLoading()}\n\t\t\t\t{/if}\n\n\t\t\t\t<ul\n\t\t\t\t\tdata-widget-part=\"messages.message-list list\"\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label=\"Session conversation with {messages.length} messages\"\n\t\t\t\t>\n\t\t\t\t\t{#each drawnMessages as msg, row (msg.id)}\n\t\t\t\t\t\t{@const index = conversationIndex(\n\t\t\t\t\t\t\trow,\n\t\t\t\t\t\t\tmessages.length,\n\t\t\t\t\t\t\torder\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{@const isLastMessage =\n\t\t\t\t\t\t\tindex === messages.length - 1}\n\t\t\t\t\t\t{@const onThisChannel =\n\t\t\t\t\t\t\t(msg.channel || \"main\") === conv.lane.current}\n\t\t\t\t\t\t{@const si = msgSceneMap.get(msg.id)}\n\t\t\t\t\t\t{@const color = si ? SCENE_COLORS[si.colorIndex] : null}\n\n\t\t\t\t\t\t<!-- History-entry marker: the date this stretch of the\n\t\t\t\t\t\t story is set on, once before the entry's first scene\n\t\t\t\t\t\t message. -->\n\t\t\t\t\t\t{#if si?.isFirstOfEntry && si.historyEntry}\n\t\t\t\t\t\t\t<li data-widget-part=\"messages.log-item\" role=\"presentation\">\n\t\t\t\t\t\t\t\t{#if si.scene.historyEntryId}\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.history-marker\"\n\t\t\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\t\t\topenLore({\n\t\t\t\t\t\t\t\t\t\t\t\tscope: \"history\",\n\t\t\t\t\t\t\t\t\t\t\t\tentryId: si.scene.historyEntryId!,\n\t\t\t\t\t\t\t\t\t\t\t\tlorebookId: si.scene.lorebookId\n\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\ttitle=\"Open history entry in lorebook\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"calendar\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t{formatEntryDate(si.historyEntry)}\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.history-marker\">\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"calendar\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t{formatEntryDate(si.historyEntry)}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t{/if}\n\n\t\t\t\t\t\t<!-- Scene title: the scene's name at the top of its\n\t\t\t\t\t\t group, in the scene's own colour. -->\n\t\t\t\t\t\t{#if si?.isFirstInScene && color}\n\t\t\t\t\t\t\t<li\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.log-item\"\n\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\tstyle=\"--sp-scene: {color.text}\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.scene-title\"\n\t\t\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\t\t\topenLore({\n\t\t\t\t\t\t\t\t\t\t\t\tscope: \"scenes\",\n\t\t\t\t\t\t\t\t\t\t\t\tsceneId: si.scene.id,\n\t\t\t\t\t\t\t\t\t\t\t\tentryId: si.scene.historyEntryId ?? undefined,\n\t\t\t\t\t\t\t\t\t\t\t\tlorebookId: si.scene.lorebookId\n\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\ttitle=\"Open scene in lorebook\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"film\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t{si.scene.name ?? \"Scene\"}\n\t\t\t\t\t\t\t\t\t\t{#if si.historyEntry && !si.historyEntry.isCompleted}\n\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.scene-title-state\">\n\t\t\t\t\t\t\t\t\t\t\t\topen\n\t\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t{/if}\n\n\t\t\t\t\t\t<!-- The message row. It carries the scene's colour as\n\t\t\t\t\t\t `--sp-scene`, which the style pack draws the scene's\n\t\t\t\t\t\t edge with and the message's own scene badge inherits.\n\n\t\t\t\t\t\t Opacity-only fade, no height/transform — autoscroll\n\t\t\t\t\t\t reads scrollHeight synchronously on insert, so an\n\t\t\t\t\t\t entering message has to contribute its full height\n\t\t\t\t\t\t to layout immediately.\n\t\t\t\t\t\t Enter is suppressed for bulk inserts: while older\n\t\t\t\t\t\t messages are being prepended, and for anything that\n\t\t\t\t\t\t isn't the last message (so switching sessions doesn't\n\t\t\t\t\t\t fade the whole backlog in). First render needs no\n\t\t\t\t\t\t guard — Svelte transitions are local by default, so\n\t\t\t\t\t\t they don't play when an ancestor block is created.\n\t\t\t\t\t\t Exit is fade-only: the <ul> has a gap, and a\n\t\t\t\t\t\t collapsing <li> would leave that gap behind to snap\n\t\t\t\t\t\t shut at the end — a worse artifact than the fix. -->\n\t\t\t\t\t\t<li\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-row\"\n\t\t\t\t\t\t\thidden={!onThisChannel}\n\t\t\t\t\t\t\tstyle={color\n\t\t\t\t\t\t\t\t? `--sp-scene: ${color.text}`\n\t\t\t\t\t\t\t\t: undefined}\n\t\t\t\t\t\t\tdata-scene={si ? si.scene.id : undefined}\n\t\t\t\t\t\t\tdata-arrive={untrack(() =>\n\t\t\t\t\t\t\t\tloadingOlderMessages || !isLastMessage\n\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t: \"\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<SessionMessage\n\t\t\t\t\t\t\t\t{msg}\n\t\t\t\t\t\t\t\t{index}\n\t\t\t\t\t\t\t\t{isLastMessage}\n\t\t\t\t\t\t\t\tsceneName={si ? (si.scene.name ?? \"Scene\") : null}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</li>\n\n\t\t\t\t\t\t<!-- Completed-entry marker: where this entry's story\n\t\t\t\t\t\t stops, and the way on to the next one. -->\n\t\t\t\t\t\t{#if si?.isLastOfEntry && si.historyEntry?.isCompleted}\n\t\t\t\t\t\t\t<li data-widget-part=\"messages.log-item\" role=\"presentation\">\n\t\t\t\t\t\t\t\t{#if si.historyEntry.nextEntry}\n\t\t\t\t\t\t\t\t\t{@const next = si.historyEntry.nextEntry}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.history-marker\"\n\t\t\t\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\t\t\t\topenLore({\n\t\t\t\t\t\t\t\t\t\t\t\t\tscope: \"history\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tentryId: next.id,\n\t\t\t\t\t\t\t\t\t\t\t\t\tlorebookId: si.scene.lorebookId\n\t\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\t\ttitle=\"Open next history entry in lorebook\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"calendar\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t\tNext: {formatEntryDate(next)}\n\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.history-marker messages.history-start\"\n\t\t\t\t\t\t\t\t\t\tonclick={() =>\n\t\t\t\t\t\t\t\t\t\t\topenLore({\n\t\t\t\t\t\t\t\t\t\t\t\tscope: \"history\",\n\t\t\t\t\t\t\t\t\t\t\t\tcreate: true,\n\t\t\t\t\t\t\t\t\t\t\t\tlorebookId: si.scene.lorebookId\n\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\ttitle=\"Start a new history entry\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"calendar-plus\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\tStart a new entry\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</li>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t{/each}\n\t\t\t\t</ul>\n\t\t\t\t{#if order === \"newest-first\"}\n\t\t\t\t\t{@render olderMessagesLoading()}\n\t\t\t\t{/if}\n\t\t\t{/if}\n\t\t</div>\n\t</div>\n\t</sp-scroll>\n</div>\n","sessions/messages/SessionMessage.svelte":"<script lang=\"ts\">\n\timport { messageEnvoySlug } from \"@serene-pub/core-catalog/conversation\"\n\timport MessageComposer from \"./MessageComposer.svelte\"\n\timport MessageControls from \"./MessageControls.svelte\"\n\timport {\n\t\tenabledWhenState,\n\t\tquickRowActions,\n\t\tverdictOf\n\t} from \"@serene-pub/core-catalog/conversation\"\n\timport { actionIdentity, foldedSectionsOf } from \"@serene-pub/sdk/component\"\n\timport MessagePartsView from \"./MessagePartsView.svelte\"\n\timport MessageMediaStrip from \"./MessageMediaStrip.svelte\"\n\timport { mediaStripItems, viewImageParams } from \"./mediaStrip\"\n\timport MessageStateLedger from \"./MessageStateLedger.svelte\"\n\timport { useWidgetContext } from \"../shared/context\"\n\timport { staleOf } from \"@serene-pub/core-catalog/conversation\"\n\timport { untrack } from \"svelte\"\n\timport { useConversation } from \"./conversation.svelte\"\n\timport type { MessageV1, WidgetAction } from \"@serene-pub/sdk/component\"\n\n\t/**\n\t * One line of the conversation (C0b). It is handed its row and where it\n\t * sits; everything else is the conversation's (`useConversation`) — who\n\t * spoke, what the viewer controls, what is being edited or selected — and\n\t * every press is one of its verbs.\n\t */\n\tinterface Props {\n\t\tmsg: MessageV1\n\t\tindex: number\n\t\tisLastMessage: boolean\n\t\t/**\n\t\t * The scene this message belongs to, when it belongs to one — the log\n\t\t * reads it off its scene map. The row also carries the scene's colour\n\t\t * as `--sp-scene`, which the badge below inherits.\n\t\t */\n\t\tsceneName?: string | null\n\t}\n\n\tlet { msg, index, isLastMessage, sceneName = null }: Props = $props()\n\n\tconst conv = useConversation()\n\tconst line = $derived(conv.line(msg.id))\n\tconst allMessages = $derived(conv.ctx.messages.v1)\n\tconst hasGeneratingMessage = $derived(allMessages.some((m) => m.isGenerating))\n\tconst extendRefusal = $derived(conv.dossier?.extendRefusal)\n\tconst isSummarizationMode = $derived(conv.select.active)\n\tconst isSelected = $derived(conv.select.ids.has(msg.id))\n\tconst scened = $derived(conv.dossier?.scened.includes(msg.id) ?? false)\n\n\t/**\n\t * The unified widget envelope (PLAN 25, ruled 2026-08-30). Present at the\n\t * one real site — SessionLayout renders the `messages` widget's snippet\n\t * inside a `WidgetHost`, and Svelte resolves context where a snippet RENDERS\n\t * rather than where it was declared, so the host's ctx reaches down here.\n\t * Undefined anywhere else (a standalone mount, a test), which is why every\n\t * read below keeps its prop as the fallback.\n\t */\n\tconst widget = useWidgetContext()\n\tconst ctx = $derived(widget?.current)\n\n\t/**\n\t * The first two of this component's ~16 `onXxx` callbacks to move onto the\n\t * envelope, because they are the two that were already action-shaped — a\n\t * verb plus this message as its subject, which is exactly `ctx.action`'s\n\t * signature.\n\t *\n\t * The two routes are the SAME call, not two spellings of a similar one:\n\t * the envelope's `invoke` resolves the identity against `ctx.actions.v1`\n\t * and hands the press to the host's `actionDispatch`, whose `fire` IS\n\t * +page's `fireOfferedAction` — the one the prop reaches through\n\t * `fireMenuAction`. One function, one emit, one permission check, so the\n\t * run is named and the narrator's modal opens whichever way it was\n\t * pressed. `ctx.action` (⏳) remains the block lane's fallback and lands\n\t * on the same function by way of `handleFrameAction`.\n\t */\n\t/**\n\t * A contributed action fired from the options menu or the quick row\n\t * (19 §4), its identity riding along (W1) so the server checks THAT\n\t * declaration and runs THAT spec.\n\t */\n\tfunction fireOfferedAction(action: WidgetAction, m: MessageV1) {\n\t\tconv.invoke(actionIdentity(action), m)\n\t}\n\n\t/**\n\t * A declared block action inside a parts-native body (20 §6). `action`\n\t * is the identity the block was stamped with by the outlet that wrote it\n\t * (W-E) — carried, never chosen here — so the server checks THAT\n\t * declaration; a block with none fires legacy (the owner floor).\n\t */\n\tfunction fireBlockAction(\n\t\tfn: string,\n\t\tm: MessageV1,\n\t\tpayload?: Record<string, unknown>,\n\t\taction?: string,\n\t\tblockId?: string\n\t) {\n\t\t// ⏳ `action`, not `invoke`: a block's `action` is the identity the\n\t\t// OUTLET stamped it with (W-E), which need not be listed in any venue of\n\t\t// this session, and `invoke` refuses a reference no venue lists. The\n\t\t// host forwards all five arguments, so the identity and the block\n\t\t// survive the hop and the server holds the press to the block's\n\t\t// addressee.\n\t\tconv.ctx.action(fn, m.id, payload, action, blockId)\n\t}\n\n\tconst messageCount = $derived(allMessages.length)\n\n\t/**\n\t * The face beside this line (DESIGN-sprites §7). With the messages widget's\n\t * `avatarFace` setting at `sprite`, a line shows the sprite it was SHOWN —\n\t * set and label recorded on the line itself, so scrolling back past an\n\t * outfit change keeps the old outfit on the old lines. The default is the\n\t * avatar, because a face per line is busy in the bubble skins. The message\n\t * id picks among a label's variants, so one line always shows one image.\n\t */\n\tlet showLineSprite = $derived(\n\t\t(ctx?.settings?.v1 as { avatarFace?: string } | undefined)?.avatarFace ===\n\t\t\t\"sprite\"\n\t)\n\tlet faceSrc = $derived(\n\t\tshowLineSprite ? (line.speaker.sprite ?? line.speaker.face) : line.speaker.face\n\t)\n\tconst narratorDisplayName = $derived(\n\t\tmsg.metadata?.narratorName || \"Narrator\"\n\t)\n\t/** Who this message is from, as the header prints it. */\n\tconst displayName = $derived(\n\t\tmsg.isNarratorResponse ? narratorDisplayName : line.speaker.name\n\t)\n\t/**\n\t * The member a role-named line belongs to (R4): \"Dungeon Master · jody\"\n\t * on a shared session's persona-less line, drawn muted after the name.\n\t * The page sends it only when the session has more than one member.\n\t */\n\tconst speakerMember = $derived(\n\t\tmsg.isNarratorResponse ? undefined : line.speaker.member?.trim() || undefined\n\t)\n\t/** The disc a speaker with no picture gets: their initial. */\n\tconst avatarInitial = $derived(\n\t\tdisplayName.trim().charAt(0).toUpperCase() || \"?\"\n\t)\n\tconst isGreeting = $derived(!!msg.metadata?.isGreeting)\n\t// Two independent classifications the style packs (sessionLayout skins) key\n\t// off. The one SessionMessage renders every layout; these attributes are\n\t// what a bubbles/compact/moonlit skin uses for alignment, colour and\n\t// avatar placement.\n\t// data-msg-role = user | assistant | narration (who's speaking, by turn)\n\t// data-msg-author = persona | character | narrator (which entity kind)\n\t// They usually agree (a persona speaks as 'user', a character as 'assistant')\n\t// but are kept separate so a skin can leverage either — e.g. impersonation,\n\t// or group chats where the split matters.\n\tconst msgRole = $derived(\n\t\tmsg.isNarratorResponse\n\t\t\t? \"narration\"\n\t\t\t: msg.role === \"user\"\n\t\t\t\t? \"user\"\n\t\t\t\t: \"assistant\"\n\t)\n\t/** An envoy's line (U5g): named by reference, no character row behind it. */\n\tconst isEnvoy = $derived(messageEnvoySlug(msg) !== null)\n\tconst msgAuthor = $derived(\n\t\tmsg.isNarratorResponse\n\t\t\t? \"narrator\"\n\t\t\t: msg.personaId != null\n\t\t\t\t? \"persona\"\n\t\t\t\t: msg.characterId != null\n\t\t\t\t\t? \"character\"\n\t\t\t\t\t: isEnvoy\n\t\t\t\t\t\t? \"envoy\"\n\t\t\t\t\t\t: \"unknown\"\n\t)\n\tconst canControl = $derived(line.controllable)\n\tconst showSwipes = $derived(line.swipes.show)\n\t/**\n\t * The swipe arrow's gate is the swipe verb's own enabled-when (U5e,\n\t * review W3): the list's verdict, then the `item.*` predicates — the\n\t * newest row, a swipe to take — judged against this row exactly as the\n\t * ⋮ menu's Swipe entry and the server's door judge them, so the arrow\n\t * and the entry can never disagree. `canSwipeRight` (the page's older\n\t * compound) is ⏳ unread here since U5e and kept on the prop chain one\n\t * release. With no listed swipe verb (an older server) the arrow is\n\t * open to the item rule alone.\n\t */\n\tconst swipeWhen = $derived.by(() => {\n\t\tconst listed = [\n\t\t\t...(venueActions?.primary ?? []),\n\t\t\t...(venueActions?.overflow ?? [])\n\t\t].find((a) => a.specSlug === \"core\" && a.key === \"swipe\")\n\t\tif (!listed) return [false, undefined] as const\n\t\treturn enabledWhenState({\n\t\t\tmsg,\n\t\t\tisLastMessage,\n\t\t\tcanControl,\n\t\t\t...verdictOf(listed)\n\t\t})\n\t})\n\t// The model's reasoning, for the active swipe — native (Ollama's\n\t// `message.thinking`, a `reasoning_content` field) or lifted out of the\n\t// text by the host. It streams in as it arrives: the host's live row\n\t// writes it beside the body on every frame, so the fold fills while the\n\t// reply is still reasoning.\n\tconst reasoningContent = $derived(msg.metadata?.reasoning || \"\")\n\tconst hasReasoning = $derived(reasoningContent.trim().length > 0)\n\n\t// Optional per-trigger focus note for a Narrator response (e.g. \"Focus on\n\t// the weather turning stormy\") — set once at trigger time, see sessions.ts's\n\t// narratorMessage.metadata.narratorInstructions.\n\tconst narratorInstructionsContent = $derived(\n\t\tmsg.metadata?.narratorInstructions || \"\"\n\t)\n\tconst hasNarratorInstructions = $derived(\n\t\tnarratorInstructionsContent.trim().length > 0\n\t)\n\n\tlet isReasoningExpanded = $state(false)\n\tlet isNarratorInstructionsExpanded = $state(false)\n\n\t// The shown alternative's folded sections (B4) — for a row that arrives\n\t// without its parts (a streamed frame's announce, a swipe), which the\n\t// parts view would otherwise draw. Expanded state by position.\n\tconst foldedSections = $derived(foldedSectionsOf(msg.metadata))\n\tlet expandedSections = $state<Record<number, boolean>>({})\n\n\t// The edit buffer: the widget owns edit mode (`conv.edit`); the row's text\n\t// is copied in when editing starts, and saving is the `edit` verb.\n\tconst isEditing = $derived(conv.edit.id === msg.id)\n\tlet editContent = $state(\"\")\n\t$effect(() => {\n\t\tif (isEditing) editContent = untrack(() => msg.content)\n\t})\n\t// Parts-native rendering (20 §13 phase 2): when the server attached the\n\t// message's typed parts and the message is settled, the body — reasoning\n\t// and section collapsibles included — renders from them. Streaming,\n\t// errors, and unenriched broadcasts fall back to the legacy fields, which\n\t// are parity-identical by construction.\n\tconst partsNative = $derived(\n\t\t!!msg.parts?.length && !msg.isGenerating && !msg.error && !isEditing\n\t)\n\n\tconst isEditDirty = $derived(isEditing && editContent !== msg.content)\n\t// Empty is blocked as well as unchanged: clearing a message to nothing\n\t// leaves an unreadable stub in the thread, and Delete is the control that\n\t// actually expresses that intent.\n\tconst canSaveEdit = $derived(isEditDirty && editContent.trim().length > 0)\n\n\t/** A `date` column carries the day only; a time of day needs a timestamp. */\n\tconst DAY_ONLY = /^\\d{4}-\\d{2}-\\d{2}$/\n\n\t/**\n\t * The clock beside the name, in the reader's own locale. `createdAt` is a\n\t * day-precision `date` column on this row (20 §5), so a value with no time\n\t * of day in it reads `updatedAt`, which is a timestamp.\n\t */\n\tconst messageTime = $derived.by(() => {\n\t\tconst created: unknown = msg.createdAt\n\t\tconst stamp =\n\t\t\ttypeof created === \"string\" && DAY_ONLY.test(created)\n\t\t\t\t? (msg.updatedAt ?? created)\n\t\t\t\t: (created ?? msg.updatedAt)\n\t\tif (!stamp) return \"\"\n\t\tconst at =\n\t\t\tstamp instanceof Date ? stamp : new Date(stamp as string | number)\n\t\tif (Number.isNaN(at.getTime())) return \"\"\n\t\treturn at.toLocaleTimeString([], {\n\t\t\thour: \"numeric\",\n\t\t\tminute: \"2-digit\"\n\t\t})\n\t})\n\n\t/**\n\t * What the ember dot beside the name says while a reply is being made:\n\t * the run's own status (R-19) — *Jasmine is thinking*, *Jasmine is\n\t * reasoning* while the model's trace streams, *Jasmine is typing*,\n\t * *loading the model* — resolved in the reader's language. A\n\t * row with none says *working* until its run's first status lands.\n\t */\n\tconst generatingStatus = $derived(\n\t\tconv.statusText(msg.generationStatus) || conv.t(\"working\")\n\t)\n\n\t// ── the quick actions ────────────────────────────────────────────────\n\t// The message venue's PRIMARY set (R-15 `quick`, U5c), one click away on\n\t// the row itself — core's verbs and a plugin's `quick` message action\n\t// alike (S8) — each shown on exactly the messages the ⋮ menu offers it\n\t// on and only while the menu would have it enabled, through the one verb\n\t// table both read (`quickRowActions`). The menu keeps the full list,\n\t// including the entries that are disabled and explained. Stop is the\n\t// primary set's too, but it has its own pill below rather than an icon.\n\t//\n\t// The list arrives on the widget envelope when a host provides one, the\n\t// prop otherwise; with neither, the floors alone.\n\tconst venueActions = $derived(\n\t\tctx?.actions?.v1?.message as\n\t\t\t| { primary: WidgetAction[]; overflow: WidgetAction[] }\n\t\t\t| undefined\n\t)\n\tconst quickActions = $derived(\n\t\tquickRowActions(venueActions?.primary ?? [], {\n\t\t\tmsg,\n\t\t\tisLastMessage,\n\t\t\tediting: conv.edit.id !== null,\n\t\t\thasGeneratingMessage,\n\t\t\tcanControl,\n\t\t\textendRefusal\n\t\t})\n\t)\n\tconst showQuickActions = $derived(\n\t\t!isSummarizationMode && !isEditing && quickActions.length > 0\n\t)\n\n\t/**\n\t * A quick icon fires the same handler the menu's row does: core's verbs\n\t * to the page's handlers, a contributed action through `fireOfferedAction`\n\t * with this message as the subject.\n\t */\n\tfunction fireQuick(_e: Event, action: WidgetAction) {\n\t\tif (action.specSlug !== \"core\") return fireOfferedAction(action, msg)\n\t\tif (action.key === \"edit\") return conv.edit.start(msg)\n\t\tif (action.key === \"swipe\") return conv.swipe(msg, \"right\")\n\t\tconv.invoke(action.key, msg)\n\t}\n\n\t/** The swipe counter is drawn only where there is a history to count. */\n\tconst swipes = $derived(msg.metadata?.swipes)\n\tconst hasSwipeHistory = $derived(\n\t\tswipes?.currentIdx !== null &&\n\t\t\tswipes?.currentIdx !== undefined &&\n\t\t\t!!swipes?.history &&\n\t\t\tswipes.history.length > 1\n\t)\n\n\tfunction handleMessageUpdate() {\n\t\tif (!canSaveEdit) return\n\t\tconv.edit.save(msg, editContent)\n\t}\n\n\tfunction toggleReasoning() {\n\t\tisReasoningExpanded = !isReasoningExpanded\n\t}\n\n\tfunction toggleNarratorInstructions() {\n\t\tisNarratorInstructionsExpanded = !isNarratorInstructionsExpanded\n\t}\n\n\t/**\n\t * The media strip's files (composer attachments plan §3.4): read off the\n\t * row's parts in EVERY state — settled, legacy text, editing, generating —\n\t * so an attachment never disappears while its line is edited or a reply\n\t * streams beside it. The parts view no longer draws them inline.\n\t */\n\tconst mediaItems = $derived(\n\t\tmediaStripItems(msg.parts, msg.activeRevisions ?? { \"0\": 0 })\n\t)\n\n\t// An image inside the rendered text is the host's markup; `sp-message-body`\n\t// raises `open-image` with its address.\n\tconst openImage = (e: CustomEvent<{ src: string }>) =>\n\t\tvoid conv.request(\"view-image\", { src: e.detail.src })\n</script>\n\n<!-- A <div>, not an <li>: SessionContainer already wraps each message in its own\n <li> (the row that carries `--sp-scene`), so an <li> here nests a list item\n inside a list item — invalid HTML that confuses assistive-tech list\n semantics. The role=\"article\" below is what carries the semantics.\n\n The four cells are the style packs' contract: avatar, identity, controls,\n content — plus the media strip, a fifth cell under content when the\n message has files — and the `data-msg-*` attributes a pack keys its look off. Every\n element is a widget part (`messages.message-*`, STYLE-GUIDE §6.16): no look\n here; the default widget stylesheet draws them, and a pack restyles them. -->\n<div\n\tid=\"message-{msg.id}\"\n\tdata-widget-part=\"messages.message\"\n\tdata-msg-role={msgRole}\n\tdata-msg-author={msgAuthor}\n\tdata-msg-state={isEditing\n\t\t? \"editing\"\n\t\t: isSummarizationMode\n\t\t\t? isSelected\n\t\t\t\t? \"selected\"\n\t\t\t\t: \"dim\"\n\t\t\t: \"normal\"}\n\tdata-msg-generating={msg.isGenerating ? \"\" : undefined}\n\tdata-msg-hidden={msg.isHidden ? \"\" : undefined}\n\tdata-msg-greeting={isGreeting ? \"\" : undefined}\n\tdata-msg-newest={isLastMessage ? \"\" : undefined}\n\ttabindex=\"-1\"\n\trole=\"article\"\n\taria-label=\"Message {index +\n\t\t1} of {messageCount} from {displayName}{speakerMember ? ` · ${speakerMember}` : ''}: {msg.content.slice(0, 100)}{msg\n\t\t.content.length > 100\n\t\t? '...'\n\t\t: ''}\"\n>\n\t<span data-widget-part=\"messages.message-avatar\">\n\t\t{#if msg.isNarratorResponse}\n\t\t\t<span\n\t\t\t\tdata-widget-part=\"messages.message-avatar-glyph\"\n\t\t\t\ttitle={narratorDisplayName}\n\t\t\t\taria-hidden=\"true\"\n\t\t\t>\n\t\t\t\t<sp-icon name=\"cloud-sun\" size=\"1.25em\"></sp-icon>\n\t\t\t</span>\n\t\t{:else}\n\t\t\t<!-- Avatar rendered directly (not the reusable Avatar component):\n\t\t\t Skeleton hard-sizes its avatar root, which fought the layout\n\t\t\t CSS. A plain img/glyph lets each style pack own size and shape. -->\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.message-avatar-button\"\n\t\t\t\tonclick={() => line.speaker.ref && void conv.request(\"view-avatar\", { ref: line.speaker.ref })}\n\t\t\t\taria-label=\"View {displayName}'s avatar\"\n\t\t\t>\n\t\t\t\t{#if faceSrc}\n\t\t\t\t\t<img\n\t\t\t\t\t\tdata-widget-part=\"messages.message-avatar-img\"\n\t\t\t\t\t\tsrc={faceSrc}\n\t\t\t\t\t\talt={displayName}\n\t\t\t\t\t/>\n\t\t\t\t{:else}\n\t\t\t\t\t<span data-widget-part=\"messages.message-avatar-glyph\" aria-hidden=\"true\">\n\t\t\t\t\t\t{avatarInitial}\n\t\t\t\t\t</span>\n\t\t\t\t{/if}\n\t\t\t</button>\n\t\t{/if}\n\t</span>\n\n\t<div data-widget-part=\"messages.message-identity\">\n\t\t{#if msg.isNarratorResponse}\n\t\t\t<span data-widget-part=\"messages.message-name\" title={narratorDisplayName}>\n\t\t\t\t{narratorDisplayName}\n\t\t\t</span>\n\t\t{:else if isEnvoy}\n\t\t\t<!-- Nothing to open: an envoy has no character page. -->\n\t\t\t<span data-widget-part=\"messages.message-name\" title={displayName}>\n\t\t\t\t{displayName}\n\t\t\t</span>\n\t\t{:else}\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.message-name\"\n\t\t\t\tonclick={() => {\n\t\t\t\t\tconst id = msg.characterId ?? msg.personaId\n\t\t\t\t\tif (id) void conv.request(\"open-character\", { characterId: id })\n\t\t\t\t}}\n\t\t\t\ttitle={displayName}\n\t\t\t>\n\t\t\t\t{displayName}\n\t\t\t</button>\n\t\t{/if}\n\t\t{#if speakerMember}\n\t\t\t<span data-widget-part=\"messages.message-member\">· {speakerMember}</span>\n\t\t{/if}\n\n\t\t<span data-widget-part=\"messages.message-badges\">\n\t\t\t{#if isGreeting}\n\t\t\t\t<span\n\t\t\t\t\tdata-widget-part=\"messages.message-badge\"\n\t\t\t\t\trole=\"img\"\n\t\t\t\t\taria-label=\"Greeting message\"\n\t\t\t\t>\n\t\t\t\t\t<sp-icon name=\"handshake\" size=\"14\"></sp-icon>\n\t\t\t\t</span>\n\t\t\t{/if}\n\t\t\t{#if msg.isHidden}\n\t\t\t\t<span\n\t\t\t\t\tdata-widget-part=\"messages.message-badge\"\n\t\t\t\t\trole=\"img\"\n\t\t\t\t\taria-label=\"Hidden from the model\"\n\t\t\t\t>\n\t\t\t\t\t<sp-icon name=\"ghost\" size=\"14\"></sp-icon>\n\t\t\t\t</span>\n\t\t\t{/if}\n\t\t\t{#if sceneName}\n\t\t\t\t<!-- Colour comes from `--sp-scene` on the row this message\n\t\t\t\t sits in, so the badge and the pack's scene bar are the\n\t\t\t\t same colour by construction. -->\n\t\t\t\t<span data-widget-part=\"messages.message-badge messages.message-badge-scene\">\n\t\t\t\t\t<sp-icon name=\"film\" size=\"14\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"messages.message-badge-label\">In scene:</span>\n\t\t\t\t\t<span data-widget-part=\"messages.message-badge-text\">{sceneName}</span>\n\t\t\t\t</span>\n\t\t\t{/if}\n\t\t\t<!-- The line's vectors against the active embedding model: nothing\n\t\t\t at all while that is hidden (the common case); which it is\n\t\t\t rides `data-vectors`. -->\n\t\t\t{#if line.embedding === \"current\"}\n\t\t\t\t<span data-widget-part=\"messages.message-vectors\" data-vectors=\"current\" title=\"Vectors up to date\" aria-label=\"Vectors up to date\">\n\t\t\t\t\t<sp-icon name=\"zap\" size=\"12\"></sp-icon>\n\t\t\t\t</span>\n\t\t\t{:else if line.embedding === \"stale\"}\n\t\t\t\t<span data-widget-part=\"messages.message-vectors\" data-vectors=\"stale\" title=\"Vectors stale — model changed\" aria-label=\"Vectors stale — model changed\">\n\t\t\t\t\t<sp-icon name=\"refresh-cw\" size=\"12\"></sp-icon>\n\t\t\t\t</span>\n\t\t\t{/if}\n\t\t</span>\n\n\t\t{#if msg.isGenerating}\n\t\t\t<span data-widget-part=\"messages.message-status\">\n\t\t\t\t<span data-widget-part=\"messages.message-ember\" aria-hidden=\"true\"></span>\n\t\t\t\t{generatingStatus}\n\t\t\t</span>\n\t\t{:else if isEditing}\n\t\t\t<span data-widget-part=\"messages.message-status\">Editing</span>\n\t\t{:else if msg.generationOutcome === \"stopped\"}\n\t\t\t<!-- The explicit outcome (R-15): a reply somebody stopped, holding\n\t\t\t the partial text. Cleared by the next regenerate or extend on\n\t\t\t the row, and by a swipe onto another alternative — the stop\n\t\t\t belongs to the alternative that was streaming, so selecting a\n\t\t\t different one leaves the mark behind. -->\n\t\t\t<span data-widget-part=\"messages.message-status\" title=\"This reply was stopped before it finished\">\n\t\t\t\tStopped\n\t\t\t</span>\n\t\t{/if}\n\t</div>\n\n\t<div data-widget-part=\"messages.message-controls\">\n\t\t{#if isEditing}\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.message-cancel\"\n\t\t\t\ttitle=\"Cancel edit (Esc)\"\n\t\t\t\tonclick={() => conv.edit.cancel()}\n\t\t\t>\n\t\t\t\tCancel\n\t\t\t</button>\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.message-save\"\n\t\t\t\ttitle={canSaveEdit\n\t\t\t\t\t? \"Save changes (Ctrl+Enter)\"\n\t\t\t\t\t: isEditDirty\n\t\t\t\t\t\t? \"A message can't be saved empty\"\n\t\t\t\t\t\t: \"No changes to save\"}\n\t\t\t\tdisabled={!canSaveEdit}\n\t\t\t\tonclick={handleMessageUpdate}\n\t\t\t>\n\t\t\t\tSave\n\t\t\t</button>\n\t\t{:else}\n\t\t\t{#if messageTime}\n\t\t\t\t<span data-widget-part=\"messages.message-time\">{messageTime}</span>\n\t\t\t{/if}\n\n\t\t\t{#if showSwipes}\n\t\t\t\t<div data-widget-part=\"messages.message-swipes\">\n\t\t\t\t\t{#if hasSwipeHistory}\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-swipe-previous messages.message-icon-button\"\n\t\t\t\t\t\t\taria-label=\"Previous swipe\"\n\t\t\t\t\t\t\tonclick={() => conv.swipe(msg, \"left\")}\n\t\t\t\t\t\t\tdisabled={conv.edit.id !== null ||\n\t\t\t\t\t\t\t\t!swipes!.currentIdx ||\n\t\t\t\t\t\t\t\tswipes!.history.length <= 1 ||\n\t\t\t\t\t\t\t\tmsg.isGenerating ||\n\t\t\t\t\t\t\t\t!canControl}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"chevron-left\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<!-- tabular-nums + a min width so stepping 9/12 -> 10/12\n\t\t\t\t\t\t doesn't shove the arrows sideways. -->\n\t\t\t\t\t\t<span data-widget-part=\"messages.message-swipe-count\" aria-live=\"polite\">\n\t\t\t\t\t\t\t{(swipes!.currentIdx || 0) + 1} / {swipes!.history\n\t\t\t\t\t\t\t\t.length}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t{/if}\n\t\t\t\t\t<button\n\t\t\t\t\t\tdata-widget-part=\"messages.message-swipe-next messages.message-icon-button\"\n\t\t\t\t\t\taria-label=\"Next swipe\"\n\t\t\t\t\t\ttitle={swipeWhen[1] ? `Next swipe — ${swipeWhen[1]}` : undefined}\n\t\t\t\t\t\tonclick={() => conv.swipe(msg, \"right\")}\n\t\t\t\t\t\tdisabled={conv.edit.id !== null || swipeWhen[0] || !canControl}\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-icon name=\"chevron-right\" size=\"14\"></sp-icon>\n\t\t\t\t\t</button>\n\t\t\t\t</div>\n\t\t\t{/if}\n\n\t\t\t{#if showQuickActions}\n\t\t\t\t<!-- The icons fade in on hover and focus on a fine pointer and\n\t\t\t\t stand permanently on a coarse one — see messageLayouts.css,\n\t\t\t\t STYLE-GUIDE §9. -->\n\t\t\t\t<div\n\t\t\t\t\tdata-widget-part=\"messages.message-actions\"\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label=\"Message actions\"\n\t\t\t\t>\n\t\t\t\t\t{#each quickActions as { action } (actionIdentity(action))}\n\t\t\t\t\t\t{@const iconName = action.icon || \"play\"}\n\t\t\t\t\t\t<!-- Icon-only: the accessible name is the declaration's\n\t\t\t\t\t\t `iconAlt`, else its name; the tooltip adds what it\n\t\t\t\t\t\t does (the legend, 2026-09-28). -->\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-action messages.message-icon-button\"\n\t\t\t\t\t\t\taria-label={action.iconAlt || action.name}\n\t\t\t\t\t\t\ttitle={action.description\n\t\t\t\t\t\t\t\t? `${action.name} — ${action.description}`\n\t\t\t\t\t\t\t\t: action.name}\n\t\t\t\t\t\t\tonclick={(e) => fireQuick(e, action)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name={iconName} size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t{/each}\n\t\t\t\t</div>\n\t\t\t{/if}\n\n\t\t\t<div data-widget-part=\"messages.message-menu\">\n\t\t\t\t{#if isSummarizationMode}\n\t\t\t\t\t<!-- Selecting lines for a summary: this line's own choice, and\n\t\t\t\t\t the two range selections. A line a scene already captured\n\t\t\t\t\t cannot join another. -->\n\t\t\t\t\t<div data-widget-part=\"messages.message-selection\" role=\"group\" aria-label=\"Selection controls\">\n\t\t\t\t\t\t{#if scened}\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-in-scene messages.message-selection-button\"\n\t\t\t\t\t\t\t\ttitle=\"Already captured in a scene\"\n\t\t\t\t\t\t\t\taria-label=\"Already captured in a scene\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"film\"></sp-icon>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.message-selection-label\">In Scene</span>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-select messages.message-selection-button\"\n\t\t\t\t\t\t\t\ttitle={isSelected ? \"Deselect message\" : \"Select message\"}\n\t\t\t\t\t\t\t\taria-label={isSelected ? \"Deselect message\" : \"Select message\"}\n\t\t\t\t\t\t\t\taria-pressed={isSelected}\n\t\t\t\t\t\t\t\tonclick={() => conv.select.toggle(msg)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name={isSelected ? \"check-square\" : \"square\"}></sp-icon>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.message-selection-label\">{isSelected ? \"Deselect\" : \"Select\"}</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-select-above messages.message-selection-button\"\n\t\t\t\t\t\t\t\ttitle=\"Select all above up to nearest selected\"\n\t\t\t\t\t\t\t\taria-label=\"Select all above up to nearest selected\"\n\t\t\t\t\t\t\t\tonclick={() => conv.select.range(index, \"above\")}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"chevrons-up\"></sp-icon>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.message-selection-label\">Select all above</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-select-below messages.message-selection-button\"\n\t\t\t\t\t\t\t\ttitle=\"Select all below up to nearest selected\"\n\t\t\t\t\t\t\t\taria-label=\"Select all below up to nearest selected\"\n\t\t\t\t\t\t\t\tonclick={() => conv.select.range(index, \"below\")}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<sp-icon name=\"chevrons-down\"></sp-icon>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"messages.message-selection-label\">Select all below</span>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</div>\n\t\t\t\t{:else}\n\t\t\t\t\t<MessageControls {msg} {isLastMessage} />\n\t\t\t\t{/if}\n\t\t\t</div>\n\n\t\t\t{#if msg.isGenerating}\n\t\t\t\t<button\n\t\t\t\t\tdata-widget-part=\"messages.message-stop\"\n\t\t\t\t\tonclick={() => conv.invoke(\"stop\", msg)}\n\t\t\t\t>\n\t\t\t\t\t<sp-icon name=\"square\" size=\"14\"></sp-icon>\n\t\t\t\t\tStop\n\t\t\t\t</button>\n\t\t\t{/if}\n\t\t{/if}\n\t</div>\n\n\t<div data-widget-part=\"messages.message-content\">\n\t\t<!-- The collapsibles a reply can carry: the Narrator's per-trigger\n\t\t focus note, its folded sections (a Plan, B4) and the model's own\n\t\t reasoning. All are suppressed when parts render — the section and\n\t\t reasoning parts carry them there, in the same order. -->\n\t\t{#if (hasNarratorInstructions || hasReasoning || foldedSections.length) && !partsNative}\n\t\t\t<div data-widget-part=\"messages.message-disclosures\">\n\t\t\t\t{#if hasNarratorInstructions}\n\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-toggle\"\n\t\t\t\t\t\t\tonclick={toggleNarratorInstructions}\n\t\t\t\t\t\t\taria-expanded={isNarratorInstructionsExpanded}\n\t\t\t\t\t\t\taria-controls=\"extra-instructions-{msg.id}\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"target\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t<span>Extra instructions</span>\n\t\t\t\t\t\t\t<sp-icon name=\"chevron-down\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<!-- grid 0fr -> 1fr is the only way to transition to/from an\n\t\t\t\t\t\t auto height in pure CSS. The inner overflow-hidden\n\t\t\t\t\t\t wrapper is required: the track collapses to 0 but the\n\t\t\t\t\t\t content keeps its intrinsic height, so without it the\n\t\t\t\t\t\t text spills out. Content stays mounted while collapsed\n\t\t\t\t\t\t because a transition needs both endpoints to exist —\n\t\t\t\t\t\t and the skin hides a collapsed track's content, since\n\t\t\t\t\t\t a 0fr track still contains focusable content\n\t\t\t\t\t\t (`messages.message-disclosure-track`, widgets.css). -->\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tid=\"extra-instructions-{msg.id}\"\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-track\"\n\t\t\t\t\t\t\tdata-expanded={isNarratorInstructionsExpanded ? \"\" : undefined}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure-clip\">\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-panel messages.prose\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-message-body text={narratorInstructionsContent}></sp-message-body>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\n\t\t\t\t{#each foldedSections as section, i (i)}\n\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-toggle\"\n\t\t\t\t\t\t\tonclick={() => (expandedSections[i] = !expandedSections[i])}\n\t\t\t\t\t\t\taria-expanded={!!expandedSections[i]}\n\t\t\t\t\t\t\taria-controls=\"folded-section-{msg.id}-{i}\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon\n\t\t\t\t\t\t\t\tname={section.kind === \"reasoning\" ? \"brain-circuit\" : \"notebook-pen\"}\n\t\t\t\t\t\t\t\tsize=\"14\"\n\t\t\t\t\t\t\t></sp-icon>\n\t\t\t\t\t\t\t<span>{section.label}</span>\n\t\t\t\t\t\t\t<sp-icon name=\"chevron-down\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<!-- See the first block for why this is a grid track. -->\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tid=\"folded-section-{msg.id}-{i}\"\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-track\"\n\t\t\t\t\t\t\tdata-expanded={expandedSections[i] ? \"\" : undefined}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure-clip\">\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-panel messages.prose\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{#if section.items}\n\t\t\t\t\t\t\t\t\t\t<ul data-widget-part=\"messages.fold-list\">\n\t\t\t\t\t\t\t\t\t\t\t{#each section.items as item, j (j)}\n\t\t\t\t\t\t\t\t\t\t\t\t<li>{item}</li>\n\t\t\t\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t\t\t\t<sp-message-body text={section.content ?? \"\"}></sp-message-body>\n\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{/each}\n\n\t\t\t\t{#if hasReasoning}\n\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure\">\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-toggle\"\n\t\t\t\t\t\t\tonclick={toggleReasoning}\n\t\t\t\t\t\t\taria-expanded={isReasoningExpanded}\n\t\t\t\t\t\t\taria-controls=\"reasoning-{msg.id}\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"brain-circuit\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t\t<span>Reasoning</span>\n\t\t\t\t\t\t\t<sp-icon name=\"chevron-down\" size=\"14\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t\t<!-- See the block above for why this is a grid track. -->\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tid=\"reasoning-{msg.id}\"\n\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-track\"\n\t\t\t\t\t\t\tdata-expanded={isReasoningExpanded ? \"\" : undefined}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.message-disclosure-clip\">\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-disclosure-panel messages.prose\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-message-body text={reasoningContent}></sp-message-body>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\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</div>\n\t\t{/if}\n\n\t\t<!-- Padding-free wrapper that carries the height change of a discrete\n\t\t swap (swiping between alternatives, entering or leaving edit, an\n\t\t error replacing content) — in CSS, the conversation skin's\n\t\t `messages.message-sizer`, where the engine can interpolate to `auto`. Not while\n\t\t generating: the height changes on every token, and a transition\n\t\t would trail the text instead of settling. -->\n\t\t<div data-widget-part=\"messages.message-sizer\" data-settled={msg.isGenerating ? undefined : \"\"}>\n\t\t\t<div data-widget-part=\"messages.message-body\">\n\t\t\t\t{#if msg.error}\n\t\t\t\t\t<div data-widget-part=\"messages.message-failure\">\n\t\t\t\t\t\t{#if msg.content}\n\t\t\t\t\t\t\t<div data-widget-part=\"messages.message-partial messages.prose\">\n\t\t\t\t\t\t\t\t<sp-message-body text={msg.content}></sp-message-body>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<div data-widget-part=\"messages.message-error\">\n\t\t\t\t\t\t\t<p data-widget-part=\"messages.message-error-line\">\n\t\t\t\t\t\t\t\t<sp-icon name=\"alert-triangle\" size=\"14\" data-widget-part=\"messages.message-error-icon\"></sp-icon>\n\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t{msg.error.message}{#if msg.error.code}\n\t\t\t\t\t\t\t\t\t\t({msg.error.code}){/if}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t<!--\n\t\t\t\t\t\tPresence IS permission. `error.connection` is connection\n\t\t\t\t\t\tidentity, and the server removes that key from every\n\t\t\t\t\t\tpayload a non-admin receives (connections/visibility.ts),\n\t\t\t\t\t\tso a client that renders it whenever it arrives shows it\n\t\t\t\t\t\tonly to administrators — no role check here to drift out\n\t\t\t\t\t\tof step with the one on the server.\n\n\t\t\t\t\t\tThe sentence above names no connection by construction,\n\t\t\t\t\t\twhich is what lets it be stored and shown to anybody; this\n\t\t\t\t\t\tis where an administrator gets back the half it left out —\n\t\t\t\t\t\twhich connection, and what the service actually said.\n\t\t\t\t\t-->\n\t\t\t\t\t\t\t{#if msg.error.connection?.name || msg.error.connection?.detail}\n\t\t\t\t\t\t\t\t<p data-widget-part=\"messages.message-error-detail\">\n\t\t\t\t\t\t\t\t\t{[\n\t\t\t\t\t\t\t\t\t\tmsg.error.connection.name,\n\t\t\t\t\t\t\t\t\t\tmsg.error.connection.model\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t\t\t\t.join(\" · \")}{msg.error.connection\n\t\t\t\t\t\t\t\t\t\t.detail\n\t\t\t\t\t\t\t\t\t\t? `${msg.error.connection.name ? \"\\n\" : \"\"}${msg.error.connection.detail}`\n\t\t\t\t\t\t\t\t\t\t: \"\"}\n\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tdata-widget-part=\"messages.message-retry\"\n\t\t\t\t\t\t\t\tonclick={() => conv.invoke(\"retry\", msg)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\tRetry\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{:else if isEditing}\n\t\t\t\t\t<!-- One surface: the panel IS the field. The textarea below\n\t\t\t\t\t drops its own border, radius and fill (see `edit-field`)\n\t\t\t\t\t and simply lays text on this one. -->\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.edit-surface\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<MessageComposer\n\t\t\t\t\t\t\tbind:markdown={editContent}\n\t\t\t\t\t\t\tonSend={handleMessageUpdate}\n\t\t\t\t\t\t\tonCancel={() => conv.edit.cancel()}\n\t\t\t\t\t\t\tenterBehavior=\"newline\"\n\t\t\t\t\t\t\tplaceholder=\"Edit this message…\"\n\t\t\t\t\t\t\tautofocus\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<!-- Transient: it exists only while an edit is open, so\n\t\t\t\t\t\t it can't become permanent noise. -->\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tdata-widget-part=\"messages.edit-hint\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<kbd data-widget-part=\"messages.edit-key\">Ctrl</kbd>\n\t\t\t\t\t\t\t\t+\n\t\t\t\t\t\t\t\t<kbd data-widget-part=\"messages.edit-key\">Enter</kbd>\n\t\t\t\t\t\t\t\tto save\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span aria-hidden=\"true\" data-widget-part=\"messages.edit-hint-separator\">·</span>\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<kbd data-widget-part=\"messages.edit-key\">Esc</kbd>\n\t\t\t\t\t\t\t\tto cancel\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t{#if isEditDirty}\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"messages.edit-unsaved\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\tUnsaved changes\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{:else if partsNative}\n\t\t\t\t\t<!-- The parts-native body (20 §2): markdown, reasoning,\n\t\t\t\t sections, steps — everything typed renders from parts. -->\n\t\t\t\t\t<div data-widget-part=\"messages.message-parts\">\n\t\t\t\t\t\t<MessagePartsView\n\t\t\t\t\t\t\tmessageId={msg.id}\n\t\t\t\t\t\t\tparts={msg.parts!}\n\t\t\t\t\t\t\tactiveRevisions={msg.activeRevisions ?? { \"0\": 0 }}\n\t\t\t\t\t\t\tonOpenImage={(src) => void conv.request(\"view-image\", { src })}\n\t\t\t\t\t\t\tbodyText={msg.content ?? \"\"}\n\t\t\t\t\t\t\tonAction={(fn, payload, action, blockId) =>\n\t\t\t\t\t\t\t\tfireBlockAction(fn, msg, payload, action, blockId)}\n\t\t\t\t\t\t\tcanAnswer={(addressee) => conv.canAnswer(addressee)}\n\t\t\t\t\t\t\tisStale={(block) =>\n\t\t\t\t\t\t\t\tstaleOf(block, msg, allMessages)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t{:else}\n\t\t\t\t\t<!-- `data-streaming`: text is arriving (the row is generating and\n\t\t\t\t\t has some), which the sheet pulses. -->\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"messages.message-text messages.prose\"\n\t\t\t\t\t\tdata-streaming={msg.isGenerating && msg.content ? \"\" : undefined}\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-message-body\n\t\t\t\t\t\t\ttext={msg.content}\n\t\t\t\t\t\t\tstreaming={msg.isGenerating ? \"\" : undefined}\n\t\t\t\t\t\t\tonopen-image={openImage}\n\t\t\t\t\t\t></sp-message-body>\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t</div>\n\t\t</div>\n\n\t\t<!-- What this turn changed, and what it is still asking for (the stats\n\t\t and states ledger). Renders nothing at all for a message that\n\t\t changed nothing, which is almost every message — and it is outside\n\t\t the height-animated wrapper above, because a decision landing here\n\t\t must not look like the body re-rendering. -->\n\t\t<MessageStateLedger messageId={msg.id} />\n\t</div>\n\n\t<!-- The media strip: attachments and generated images as square tiles,\n\t in every state of the row — a cell of its own under the content, so\n\t it sits BELOW a pack's card, never inside it (next-pass note 40,\n\t 2026-10-03; the base sheet places it on the row after `content`). -->\n\t<MessageMediaStrip\n\t\titems={mediaItems}\n\t\tediting={isEditing && canControl}\n\t\tonOpen={(images, index) =>\n\t\t\tvoid conv.request(\"view-image\", viewImageParams(images, index))}\n\t\tonRemove={canControl\n\t\t\t? (item) =>\n\t\t\t\t\tvoid conv.request(\"remove-attachment\", { messageId: msg.id, partId: item.partId })\n\t\t\t: undefined}\n\t/>\n</div>\n","sessions/messages/StateProposalList.svelte":"<script lang=\"ts\">\n\t/**\n\t * Held changes, with the two buttons that decide them.\n\t *\n\t * The model is the one writer with no authority: what it produces is a\n\t * pending line, not a change. So nothing here applies anything — Accept runs\n\t * the same write a script's would have run, Reject leaves the world as it\n\t * was, and until one of them is pressed the stat says what it said.\n\t *\n\t * The same list under a message and in the Review panel, because \"everything\n\t * waiting\" and \"what this turn asked for\" are the same rows read at two\n\t * scopes, and two components would be two ways to describe one payload.\n\t *\n\t * A **superseded** row (plans/29 R-15 *Staleness and order*; U5f) is an\n\t * accept that applied nothing: the slot moved since the proposal was\n\t * made. It stays under its message, collapsed, naming what moved, with\n\t * no buttons — the ledger's word on why the model's ask never landed.\n\t */\n\timport type { ConversationProposalV1 } from \"@serene-pub/core-catalog/conversation\"\n\timport { useConversation, useT } from \"./conversation.svelte\"\n\n\tinterface Props {\n\t\tproposals: ConversationProposalV1[]\n\t\t/** Shown in the Review panel, where a row is not under its message. */\n\t\tshowAnchor?: boolean\n\t}\n\tlet { proposals, showAnchor = false }: Props = $props()\n\n\tconst conv = useConversation()\n\tconst t = useT()\n\tconst describe = (row: ConversationProposalV1) => row.text\n\tconst movedName = (row: ConversationProposalV1) => row.moved ?? t(\"a value\")\n\tconst decide = (id: number, accept: boolean) =>\n\t\tvoid conv.request(\"decide-proposal\", { proposalId: id, accept })\n</script>\n\n{#each proposals as row (row.id)}\n\t{#if row.status === \"superseded\"}\n\t\t<div\n\t\t\tdata-widget-part=\"messages.proposal\"\n\t\t\tdata-proposal-id={row.id}\n\t\t\tdata-superseded=\"true\"\n\t\t>\n\t\t\t<sp-icon name=\"history\" size=\"11\"></sp-icon>\n\t\t\t<span data-widget-part=\"messages.proposal-text\">\n\t\t\t\t{describe(row)}\n\t\t\t\t<span data-widget-part=\"messages.proposal-note\">\n\t\t\t\t\t· {t(\"Superseded — {slot} changed since this was proposed\").replace(\n\t\t\t\t\t\t\"{slot}\",\n\t\t\t\t\t\tmovedName(row)\n\t\t\t\t\t)}\n\t\t\t\t</span>\n\t\t\t</span>\n\t\t</div>\n\t{:else}\n\t\t<div data-widget-part=\"messages.proposal\" data-proposal-id={row.id}>\n\t\t\t<sp-icon name=\"sparkles\" size=\"11\"></sp-icon>\n\t\t\t<span data-widget-part=\"messages.proposal-text\">\n\t\t\t\t{describe(row)}\n\t\t\t\t{#if showAnchor && row.messageId != null}\n\t\t\t\t\t<span data-widget-part=\"messages.proposal-anchor\">on message {row.messageId}</span>\n\t\t\t\t{/if}\n\t\t\t</span>\n\t\t\t<span data-widget-part=\"messages.proposal-note\" title=\"Proposed by {row.proposedBy || 'a run'}\">\n\t\t\t\tproposed\n\t\t\t</span>\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.proposal-decide messages.proposal-accept\"\n\t\t\t\tonclick={() => decide(row.id, true)}\n\t\t\t>\n\t\t\t\tAccept\n\t\t\t</button>\n\t\t\t<button\n\t\t\t\tdata-widget-part=\"messages.proposal-decide messages.proposal-reject\"\n\t\t\t\tonclick={() => decide(row.id, false)}\n\t\t\t>\n\t\t\t\tReject\n\t\t\t</button>\n\t\t</div>\n\t{/if}\n{/each}\n","sessions/messages/conversation.svelte.ts":"/**\n * The conversation widget's own model (C0b): what its parts read, derived\n * from the widget context alone, and what they do, through its verbs alone.\n *\n * `MessagesWidget` creates one and provides it; the log, each message, its\n * controls and the composer read it (`useConversation`) instead of taking the\n * page's callbacks as props. So the widget's state — which line is being\n * edited, whose menu is open, what is selected for a summary — is the\n * widget's, and every effect is an `invoke` (core's verbs, a contributed\n * action) or a `request` (something the host opens). Nothing here imports a\n * store, the socket or the page: the same source runs in a UI worker.\n */\nimport { getContext, setContext } from \"svelte\"\nimport { SvelteSet } from \"svelte/reactivity\"\nimport { useWidgetContext } from \"../shared/context\"\nimport type { WidgetContextRef } from \"@serene-pub/core-catalog/conversation\"\nimport {\n\tNO_LINE,\n\ttype ConversationDossierV1,\n\ttype ConversationLineV1\n} from \"@serene-pub/core-catalog/conversation\"\nimport type { WidgetRequestKind, WidgetRequests } from \"@serene-pub/sdk/component\"\nimport { canAnswerForm } from \"@serene-pub/core-catalog/conversation\"\nimport { setStatusTextResolver, statusTextIn } from \"@serene-pub/core-catalog/conversation\"\nimport type { RequestDeclineCode, StatusText } from \"@serene-pub/sdk/component\"\n\nconst KEY = Symbol(\"sp-conversation\")\n\nexport type Conversation = ReturnType<typeof createConversation>\n\n/** What a verb's subject is: a message, by id. */\ntype Subject = { id: number }\n\n/**\n * A request declined because the view went away — the page's decline of what\n * it never answered, or the wire's own at `close()`. Expected at every\n * unmount with a request in flight (the composer's `draft` is nearly always\n * one), so it is not a failure worth a line on stderr. Read by its\n * `code` (`unmounted`, a {@link RequestDeclineCode}); an older host declines\n * with its sentence alone (\"the page was unmounted before it answered\"), so\n * the text is the fallback.\n */\nexport function isUnmountDecline(e: unknown): boolean {\n\tconst code: unknown = typeof e === \"object\" && e !== null ? (e as { code?: unknown }).code : undefined\n\tif (code !== undefined) return code === (\"unmounted\" satisfies RequestDeclineCode)\n\tconst message = e instanceof Error ? e.message : String(e)\n\treturn /\\bunmounted\\b/.test(message)\n}\n\nexport function createConversation(widget: WidgetContextRef) {\n\tconst ctx = () => widget.current\n\tconst warn = (what: string) => (e: unknown) => {\n\t\tif (isUnmountDecline(e)) return\n\t\tconsole.warn(`conversation: ${what} — ${e instanceof Error ? e.message : String(e)}`)\n\t}\n\n\tlet editingId = $state<number | null>(null)\n\tlet menuFor = $state<number | undefined>(undefined)\n\tlet selecting = $state(false)\n\t/** The lane the composer writes to, and the log shows (`main` by default). */\n\tlet lane = $state(\"main\")\n\tconst selected = new SvelteSet<number>()\n\n\t// Status sentences in this widget's language (`text.ts`).\n\tsetStatusTextResolver(\n\t\t() => ctx().locale.v1,\n\t\t(source) => ctx().t(source)\n\t)\n\n\t// Through the context's own type — its scoped keys come from the SDK's\n\t// one table — so a renamed section fails to compile here.\n\tconst dossier = $derived((ctx().session_full?.v1 ?? null) as ConversationDossierV1 | null)\n\n\t/**\n\t * The channels this copy shows (lair re-plan S1): its composer's, which\n\t * the host narrows per mount — a copy pinned to the Sanctum is told\n\t * `['sanctum']`, the primary log the channels no pinned copy claims.\n\t * `null` (no dossier yet, or an empty list) is every channel.\n\t */\n\tconst channels = $derived.by((): string[] | null => {\n\t\tconst listed = dossier?.composer?.channels\n\t\treturn listed && listed.length ? listed : null\n\t})\n\t/** A row's channel slug: `main` when unset, a lane's slug for `slug:n`. */\n\tconst slugOf = (channel: unknown) =>\n\t\t(typeof channel === \"string\" && channel ? channel : \"main\").split(\":\")[0]\n\t/**\n\t * The rows this log holds: the host's log narrowed to this copy's\n\t * channels. A row on a channel another copy claims is not drawn here at\n\t * all (never merely hidden), so two copies never hold the same line.\n\t */\n\tconst rows = $derived.by(() => {\n\t\tconst all = ctx().messages.v1\n\t\tif (!channels) return all\n\t\tconst shown = new Set(channels)\n\t\treturn all.filter((m) => shown.has(slugOf((m as { channel?: unknown }).channel)))\n\t})\n\n\t// The host's summary finished: the selection it was handed ends.\n\tlet summaryEnded: number | null = null\n\t$effect(() => {\n\t\tconst n = dossier?.summaryEnded ?? 0\n\t\tif (summaryEnded !== null && n !== summaryEnded) {\n\t\t\tselecting = false\n\t\t\tselected.clear()\n\t\t}\n\t\tsummaryEnded = n\n\t})\n\n\t/** `text`: what the press supplies — the composer's slash argument (S2). */\n\tfunction invoke(key: string, subject?: Subject, payload?: Record<string, unknown>, text?: string) {\n\t\ttry {\n\t\t\tctx().invoke(key, { messageId: subject?.id, payload, ...(text !== undefined ? { text } : {}) })\n\t\t} catch (e) {\n\t\t\twarn(key)(e)\n\t\t}\n\t}\n\n\tfunction request<K extends WidgetRequestKind>(kind: K, params: WidgetRequests[K][\"params\"]) {\n\t\treturn ctx().request(kind, params).catch(warn(kind))\n\t}\n\n\treturn {\n\t\tget ctx() {\n\t\t\treturn ctx()\n\t\t},\n\t\tget dossier() {\n\t\t\treturn dossier\n\t\t},\n\t\t/** The page's word on one line; nothing when it has none. */\n\t\tline(id: number): ConversationLineV1 {\n\t\t\treturn dossier?.lines[id] ?? NO_LINE\n\t\t},\n\t\tt: (source: string) => ctx().t(source),\n\t\t/** A status sentence in the viewer's language. */\n\t\tstatusText: (status: StatusText | null | undefined) =>\n\t\t\tstatusTextIn(status, ctx().locale.v1, (source) => ctx().t(source)),\n\n\t\t/** May the viewer answer a form put to `addressee`? */\n\t\tcanAnswer(addressee: string | undefined) {\n\t\t\tconst f = dossier\n\t\t\treturn canAnswerForm(\n\t\t\t\taddressee,\n\t\t\t\t{ userId: ctx().viewer.v1.userId, isOwner: !!f?.isOwner, isAdmin: ctx().viewer.v1.isAdmin },\n\t\t\t\tf?.cast\n\t\t\t)\n\t\t},\n\n\t\t// ── verbs ────────────────────────────────────────────────────────────\n\t\tinvoke,\n\t\t/** A reply swiped: to the newer alternative (right) or the older (left). */\n\t\tswipe(subject: Subject, direction: \"left\" | \"right\") {\n\t\t\tinvoke(\"swipe\", subject, { direction })\n\t\t},\n\t\trequest,\n\n\t\t// ── editing: the widget's own state; saving is the `edit` verb ───────\n\t\tedit: {\n\t\t\tget id() {\n\t\t\t\treturn editingId\n\t\t\t},\n\t\t\tstart(subject: Subject) {\n\t\t\t\teditingId = subject.id\n\t\t\t\tmenuFor = undefined\n\t\t\t},\n\t\t\tcancel() {\n\t\t\t\teditingId = null\n\t\t\t},\n\t\t\tsave(subject: Subject, content: string) {\n\t\t\t\tinvoke(\"edit\", subject, { content })\n\t\t\t\teditingId = null\n\t\t\t}\n\t\t},\n\n\t\t/** The rows this copy's log holds — its channels' (S1), in the host's order. */\n\t\tget rows() {\n\t\t\treturn rows\n\t\t},\n\t\t/** The channels this copy shows, or `null` for every channel. */\n\t\tget channels() {\n\t\t\treturn channels\n\t\t},\n\t\t/**\n\t\t * What a channel is CALLED: its declared label in the viewer's language\n\t\t * (`ChannelDecl.label`, the Lair's _Sanctum_), else its slug, title-cased\n\t\t * (`manuscript` reads _Manuscript_).\n\t\t */\n\t\tchannelName(slug: string): string {\n\t\t\tconst label = dossier?.composer?.channelLabels?.[slug]\n\t\t\tif (label) return label\n\t\t\treturn slug\n\t\t\t\t.split(/[-_]/)\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.map((w) => w.charAt(0).toUpperCase() + w.slice(1))\n\t\t\t\t.join(\" \")\n\t\t},\n\n\t\t/**\n\t\t * The lane the composer writes to; the log shows that lane's rows. It is\n\t\t * always one of this copy's channels: a copy told one channel writes on\n\t\t * it whatever was chosen before (S1).\n\t\t */\n\t\tlane: {\n\t\t\tget current() {\n\t\t\t\treturn channels && !channels.includes(lane) ? channels[0] : lane\n\t\t\t},\n\t\t\tset(next: string) {\n\t\t\t\tlane = next || \"main\"\n\t\t\t}\n\t\t},\n\n\t\t/** Whose ⋮ menu is open — one at a time across the log. */\n\t\tmenu: {\n\t\t\tget open() {\n\t\t\t\treturn menuFor\n\t\t\t},\n\t\t\tset(id: number | undefined) {\n\t\t\t\tmenuFor = id\n\t\t\t}\n\t\t},\n\n\t\t// ── selecting lines for a summary ────────────────────────────────────\n\t\tselect: {\n\t\t\tget active() {\n\t\t\t\treturn selecting\n\t\t\t},\n\t\t\tget ids() {\n\t\t\t\treturn selected\n\t\t\t},\n\t\t\tstart(subject?: Subject) {\n\t\t\t\tselecting = true\n\t\t\t\tselected.clear()\n\t\t\t\tif (subject) selected.add(subject.id)\n\t\t\t\tmenuFor = undefined\n\t\t\t},\n\t\t\tstop() {\n\t\t\t\tselecting = false\n\t\t\t\tselected.clear()\n\t\t\t},\n\t\t\ttoggle(subject: Subject) {\n\t\t\t\t// A line a scene already captured cannot join another.\n\t\t\t\tif (dossier?.scened.includes(subject.id)) return\n\t\t\t\tif (selected.has(subject.id)) selected.delete(subject.id)\n\t\t\t\telse selected.add(subject.id)\n\t\t\t},\n\t\t\tset(ids: number[]) {\n\t\t\t\tselected.clear()\n\t\t\t\tfor (const id of ids) selected.add(id)\n\t\t\t},\n\t\t\t/**\n\t\t\t * From a line toward one end, up to the nearest line already\n\t\t\t * selected — never through a line a scene has already captured.\n\t\t\t */\n\t\t\trange(index: number, toward: \"above\" | \"below\") {\n\t\t\t\t// The log's own rows: `index` counts the lines this copy draws.\n\t\t\t\tconst list = rows\n\t\t\t\tconst taken = new Set(dossier?.scened ?? [])\n\t\t\t\tconst step = toward === \"above\" ? -1 : 1\n\t\t\t\tfor (let i = index; i >= 0 && i < list.length; i += step) {\n\t\t\t\t\tconst id = list[i].id\n\t\t\t\t\tif (taken.has(id)) break\n\t\t\t\t\tif (selected.has(id) && i !== index) break\n\t\t\t\t\tselected.add(id)\n\t\t\t\t}\n\t\t\t},\n\t\t\t/**\n\t\t\t * Hand the selection to the host's summarizer. It stays until the host\n\t\t\t * says the summary finished (`summaryEnded`): a cancelled or failed\n\t\t\t * create keeps a hand-picked selection.\n\t\t\t */\n\t\t\tcommit(kind: \"scene\" | \"world\" | \"character\") {\n\t\t\t\tctx().request(\"summarize\", { kind, messageIds: [...selected] }).catch(warn(\"summarize\"))\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function setConversation(c: Conversation): Conversation {\n\treturn setContext(KEY, c)\n}\n\nexport function useConversation(): Conversation {\n\tconst c = getContext<Conversation | undefined>(KEY)\n\tif (!c) throw new Error(\"a conversation part rendered outside MessagesWidget\")\n\treturn c\n}\n\n/**\n * The widget's `t` for a part that may also render outside a widget (a\n * block view in a test): the English source there.\n */\nexport function useT(): (source: string) => string {\n\tconst w = useWidgetContext()\n\treturn (source) => w?.current.t?.(source) ?? source\n}\n","sessions/messages/mediaStrip.ts":"/**\n * The media strip's reading of a message (composer attachments plan §3.4):\n * which of its parts are files, in what order, and how each is addressed.\n * Pure, so the strip and its tests read one answer.\n *\n * A **media strip** is the square image tiles and file tiles below a\n * message's card (next-pass note 40, 2026-10-03) — `core:image` /\n * `core:file` parts, whoever wrote them (a person's attachment, a\n * pipeline's generated image). Not the character gallery, not\n * an image a block tree places (`messages.block-image` stays where its plugin\n * put it).\n */\nimport type { MessagePartV1 } from '@serene-pub/sdk/component'\n\n/** One image or file the strip shows. */\nexport interface MediaStripItem {\n\t/** The part's id — the key, and what a removal names. */\n\tpartId: number\n\tkind: 'image' | 'file'\n\t/** `files.id` — the part's `data.assetId`. */\n\tassetId: number\n\t/** What a reader is told: the part's alt, then its file's name. */\n\tlabel: string\n\t/** The file's name, when the part kept one. */\n\tname: string | null\n\twidth: number | null\n\theight: number | null\n\tmime: string | null\n\tbytes: number | null\n}\n\n/** How many image tiles show before the rest fold into a count tile. */\nexport const MEDIA_STRIP_MAX_TILES = 6\n\nconst text = (v: unknown): string | null => (typeof v === 'string' && v.trim() ? v.trim() : null)\nconst count = (v: unknown): number | null => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : null)\n\n/**\n * The message's files, steps ascending and each step's active revision only\n * (the swipe cursor, as `MessagePartsView` reads it), parts in ordinal order.\n * A part with no usable `assetId` is not a file anyone can fetch, so it is\n * left out rather than drawn broken.\n */\nexport function mediaStripItems(\n\tparts: readonly MessagePartV1[] | null | undefined,\n\tactiveRevisions: Record<string, number> | null | undefined,\n): MediaStripItem[] {\n\tif (!parts?.length) return []\n\tconst active = activeRevisions ?? {}\n\treturn parts\n\t\t.filter(\n\t\t\t(p) =>\n\t\t\t\t(p.type === 'core:image' || p.type === 'core:file') &&\n\t\t\t\tp.revision === (active[String(p.step)] ?? 0) &&\n\t\t\t\tcount((p.data as Record<string, unknown> | null)?.assetId) !== null,\n\t\t)\n\t\t.sort((a, b) => a.step - b.step || a.ordinal - b.ordinal)\n\t\t.map((p) => {\n\t\t\tconst d = (p.data ?? {}) as Record<string, unknown>\n\t\t\tconst kind = p.type === 'core:image' ? 'image' : 'file'\n\t\t\tconst name = text(d.filename) ?? text(d.name)\n\t\t\treturn {\n\t\t\t\tpartId: p.id,\n\t\t\t\tkind,\n\t\t\t\tassetId: d.assetId as number,\n\t\t\t\tlabel: text(d.alt) ?? name ?? (kind === 'image' ? 'Image' : 'File'),\n\t\t\t\tname,\n\t\t\t\twidth: count(d.width),\n\t\t\t\theight: count(d.height),\n\t\t\t\tmime: text(d.mime),\n\t\t\t\tbytes: count(d.bytes),\n\t\t\t}\n\t\t})\n}\n\n/** The address of one representation (`/media/{id}`, plus `?v=` for a derived one). */\nexport function mediaSrc(assetId: number, variant?: 'thumb' | 'fitted'): string {\n\treturn variant ? `/media/${assetId}?v=${variant}` : `/media/${assetId}`\n}\n\n/** A file's download address — the app's own, saved under its name. */\nexport function mediaDownloadHref(assetId: number): string {\n\treturn `/media/${assetId}?download=1`\n}\n\n/** A byte count for a file tile: `812 B`, `14 KB`, `3.2 MB`. */\nexport function formatBytes(bytes: number): string {\n\tif (bytes < 1024) return `${bytes} B`\n\tif (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`\n\treturn `${(bytes / (1024 * 1024)).toFixed(1)} MB`\n}\n\n/** The icon a file tile wears, by its type. */\nexport function fileIcon(mime: string | null): string {\n\tif (!mime) return 'file'\n\tif (mime.startsWith('text/') || mime === 'application/pdf') return 'file-text'\n\treturn 'file'\n}\n\n/**\n * The `view-image` request for opening image `index` of `images`: the image\n * itself, full size, and the message's other images as the lightbox's\n * gallery so it can page through them. Images the strip found missing are\n * not offered.\n */\nexport function viewImageParams(images: readonly MediaStripItem[], index: number) {\n\tconst srcs = images.map((i) => mediaSrc(i.assetId))\n\treturn {\n\t\tsrc: srcs[index],\n\t\tgallery: { srcs, index, captions: images.map((i) => i.label) },\n\t}\n}\n","sessions/messages/messages.ts":"/**\n * Core's `messages` component (C7): the conversation — the log, the field\n * you write into, and the strips beside it — as the page's UI worker runs\n * it. `npm run build` compiles it with the CLI's component bundler to\n * `dist/components/messages.js`, the module the app serves at\n * `/core-ui/messages`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport Messages from './Messages.svelte'\n\nexport default svelteComponent(Messages)\n","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"},"sourceHash":"690981d8959a0506e3ccf7ea45d01968b2a853b9a2e85dda88abcef3634a76cd","catalogVersion":"0.6.0-pr-2"}
|