ccdd9ea129
the inventory (GM-designed in conversation, 2026-11-19): six human roles -- the developer (maintains the repo, and is the system packages author by consequence: system packages ship in the repo), the deployment operator (maintains a deployment: identities, providers, the registry; filesystem access as recovery; never a reader of runs' private surfaces -- owner-gating holds even against the superuser), the deployment user (any claimed identity; the only reach is the API -- no filesystem, no keys, ever), the package author (an off-platform seat: authorship travels with the files, the machinery sees only the publisher), a run's GM (maintains a run they own -- the same person the machinery records as the run's owner, one role two names, never split; the fork creates a second GM seat over a branching canon), and the reader (defined by the act, membership-free: on-platform any signed-in user, off-platform anyone the story text reaches). The inferencer roles: the assistant, the player, the housekeeper, the curator, the clerk (code, never a model), and the bookkeeper (parked). The example that pinned the mappings: Alice the op forking Bob's Faye into her Kate (hats stack, seats don't), Charlie authoring package files Bob publishes (the author-publisher split), Dave reading the exported story with no invite at all (the reader needs nothing).
the naming convention, stated in AGENTS's header and DICTIONARY both: "GM" always means a run's GM, everywhere; ruling attributions name the developer; the assistant is the assistant; the op stays the op. The role line that is never crossed (developer, 2026-11-19): the assistant is NOT the player -- player-facing instructions are for the assistant to understand how the player would interpret them, never to follow. The root prompts and every model-facing string were already correct (GM there was always the run's GM) and are untouched; the packages' fiction is exempt from the term lint (rule 4 scopes to the substrate: README and the root prompts); the records keep their day's words -- DECISIONS gained one dated header note mapping the old usage instead of a rewrite ("GM" in a ruling attribution is the developer, "the agent" is the assistant).
the sweep: 125+ ruling attributions rewritten across living prose and code comments in every spelling the repo used (paren-wrapped, date-first, mid-sentence, line-wrapped); AGENTS.md fully re-voiced (the header rewritten, "the agent" gone, the developer-meaning prose fixed line by line); README's "invited players" became "invited users"; the gm.md carve-out made precise everywhere (the file is the run's GM's private file, the flagging target is the developer, the non-editor is the assistant).
the word retirements, both lint-banned in rule 4 exactly like "window": "agent" (the word did too many jobs at once; every seat is named; the filename AGENTS.md consumed as-is, "Windows" the OS the precedent) and "LLM" (the class word is "inferencer(s)"; "model" kept as the machinery's noun -- a registry entry, never a seat: a model is what the registry lists, an inferencer is who a seat is). The fixes the bans forced: the exposure rule's "internal agents" -> "internal inferencers", the hypothetical "status-keeper agent" -> invocation, the bookkeeper shed its "agent" tag, "player-model" fell to "the player" everywhere including housekeeper.md's one prompt hit, README's "inference key" and its Roles section re-voiced, the #22 attribution comments at the three call sites, and the runtime log markers renamed (llm -> inferencer, a meaning-preserving log rename under the no-legacy rule). DICTIONARY's renames section carries both retirement entries.
the duties audit (along the what-hats-do lines: the developer maintains the repo, the op maintains a deployment, a user's only reach is the API, a run's GM maintains their run). Found and fixed: README's Housekeeping section was pre-split era text -- "every housekeeping pass should end in a commit" and "confess in the commit message" (runs/ is gitignored; the developer's commit duty was assigned to the run flow), the dead packages/<story>/dumps and packages/<story>/db paths (the dump is per-session under runs/<id>/sessions/<n>/), "canon/ stays committed", and "single-human" (multiuser since 2026-11-14) -- rewritten to the current paths with the audit's hat named: the dump cross-check is the operator side's, a run's GM reviews a pass through the server (the housekeeping log, the rendered rings, the story). The CLI-attributed-to-the-GM lines now say what they are: deployment-side filesystem reach, --gm-authorized writes, whoever's hand runs it (the protocol passage, quickstart step 7 -- which also dropped its "commit" -- and the booting intro now names its hat switches: the author's files, the deployment-side create with its API twin named, the GM's start). "The host" -> "the op" in the pitch. One mechanical fiction PARKED on the ROADMAP deferred list instead of fixed: the memory tiers table promises records access "none -- until the GM unlocks it in the story", but no channel exists (records is a creation-time settings bool, settings.json is read-only in the file API) -- build the channel or fix the promise, later. Verified consistent by the audit: the notepad (ONE notepad -- the run's gm.md, owner-writable through its route, seeded from the package copy), the op's non-reader boundary, every provider act, the spec attributions, the reader, the prompts.
verified: typecheck green both programs, check-repo ALL CLEAN with both new bans active, the ban regexes proven by direct test (agent/agents/multi-agent and LLM/LLMs caught; AGENTS.md and the assistant pass), and final greps confirming every remaining "GM" is a protocol term and every remaining "agent"/"LLM" is a quoting entry or a record's day-words. The developer's own edits ride along: the operator queue strike (the inventory line done, the loopback typo, "external sec review"), and the handoff prepared -- the queue renumbered, the fresh-run item's garbled line repaired, the commit count brought current (seven await the push), template and box marked committed, a stray paragraph break fixed. detention stays untracked WIP, untouched.
436 lines
18 KiB
JavaScript
436 lines
18 KiB
JavaScript
// web/transcript.mjs -- the transcript: register rendering and the
|
|
// entry walk.
|
|
//
|
|
// The transcript renders three registers by the ruled markers: plain
|
|
// text is speech, *italics* is narration, a line opening with `(` is
|
|
// OOC (closing paren optional; a lone paren is an empty OOC line and
|
|
// is skipped). The machinery never shows here: the status and agenda
|
|
// blocks (and the retired delta tags) strip from the prose -- the
|
|
// dedicated panes carry the derived state -- and the reminder rides
|
|
// only on the raw tab. The mind chip is the one exception: the mind
|
|
// is write-only, the chip is its display.
|
|
|
|
/** @typedef {import('../server/shapes.mjs').LogEvent} LogEvent */
|
|
/** @typedef {import('../server/shapes.mjs').BundleEvent} BundleEvent */
|
|
/** @typedef {import('../server/shapes.mjs').MsgEvent} MsgEvent */
|
|
/** @typedef {import('../server/shapes.mjs').NoteEvent} NoteEvent */
|
|
|
|
import { $, el } from './dom.mjs';
|
|
|
|
// splits text into spans: *italics* = narration, **bold** = emphasis.
|
|
// Colour-only (developer, 2026-11-16): the workbench renders no faces --
|
|
// same glyphs, same widths, only paint differs, and the input's
|
|
// caret can never drift from what it overlays. The asterisks stay
|
|
// on screen: the authored text is the rendered text
|
|
/** @param {HTMLElement} target @param {string} text */
|
|
function renderSpans(target, text) {
|
|
const parts = String(text).split(/(\*\*[^*]+\*\*|\*[^*\n]+\*)/g);
|
|
for (const p of parts) {
|
|
if (!p) continue;
|
|
if (p.startsWith('**') && p.endsWith('**')) {
|
|
target.appendChild(el('span', 'emph', p));
|
|
} else if (p.startsWith('*') && p.endsWith('*') && p.length > 2) {
|
|
target.appendChild(el('span', 'narration', p));
|
|
} else {
|
|
target.appendChild(document.createTextNode(p));
|
|
}
|
|
}
|
|
}
|
|
|
|
// one content block (a GM or player turn) -> DOM lines. extract pulls
|
|
// the riding blocks (status/conflict/agenda) out of GM prose; the
|
|
// delta tags on player turns always render as chips. The workbench's
|
|
// register renderer -- colour-only, source verbatim; the story view
|
|
// carries its own (view-story.mjs), the book's typography is not the
|
|
// tool's (developer, 2026-11-16).
|
|
/** @param {HTMLElement} target @param {?string} text @param {{ extract?: boolean }} opts @returns {{ status: ?string, conflict: ?string, agenda: ?string }} */
|
|
function renderContent(target, text, { extract }) {
|
|
let body = String(text ?? '');
|
|
let status = null;
|
|
let conflict = null;
|
|
let agenda = null;
|
|
if (extract) {
|
|
const sm = body.match(/<status>([\s\S]*?)<\/status>/);
|
|
if (sm) { status = sm[1]; body = body.replace(sm[0], ''); }
|
|
const cm = body.match(/<conflict>([\s\S]*?)<\/conflict>/);
|
|
if (cm) { conflict = cm[1]; body = body.replace(cm[0], ''); }
|
|
const am = body.match(/<agenda>([\s\S]*?)<\/agenda>/);
|
|
if (am) { agenda = am[1]; body = body.replace(am[0], ''); }
|
|
}
|
|
const tags = [];
|
|
for (const m of body.matchAll(/<(lost|gained|add|drop|mind|status|agenda|sheet)>([\s\S]*?)<\/\1>/g)) {
|
|
// the mind block is JSON -- it rides whole (no comma-splitting);
|
|
// the note line carries the human-readable form. Status and
|
|
// agenda blocks are the full-block protocol: their items chip
|
|
// like the deltas did (list markers stripped for display). The
|
|
// sheet is JSON too -- it chips whole like the mind
|
|
const items = m[1] === 'mind' || m[1] === 'sheet'
|
|
? [m[2].trim()]
|
|
: m[2].split('\n').flatMap((l) => l.replace(/^\s*[-*]\s+\d*[.:)]?\s*/, '').split(',')).map((x) => x.trim()).filter(Boolean);
|
|
tags.push({ kind: m[1], items });
|
|
}
|
|
for (const t of tags) body = body.replace(new RegExp(`<${t.kind}>[\\s\\S]*?</${t.kind}>`), '');
|
|
|
|
let narr = false; // an open multi-line narration block
|
|
for (const line of body.split('\n')) {
|
|
const t = line.trim();
|
|
if (!t) { target.appendChild(document.createElement('br')); continue; }
|
|
if (t.startsWith('(')) {
|
|
if (t === '(') continue; // empty OOC -- skip
|
|
const d = document.createElement('div');
|
|
d.className = 'line ooc';
|
|
d.textContent = t;
|
|
target.appendChild(d);
|
|
continue;
|
|
}
|
|
if (t.startsWith('<')) {
|
|
// substrate lines: an opening <tag> is always OOC (invariants.md).
|
|
// Known blocks were extracted above; whatever remains is an
|
|
// unknown or unbalanced tag -- keep it visible, styled as OOC
|
|
const d = document.createElement('div');
|
|
d.className = 'line ooc';
|
|
d.textContent = t;
|
|
target.appendChild(d);
|
|
continue;
|
|
}
|
|
const stars = (line.match(/\*/g) ?? []).length;
|
|
if (!narr && stars % 2 === 0) {
|
|
// balanced: spans carry the registers -- mixed lines
|
|
// (`*foo* bar *baz*`), whole-line narration (`*she sleeps.*`),
|
|
// bold -- all render correctly
|
|
const d = document.createElement('div');
|
|
d.className = 'line speech';
|
|
renderSpans(d, line);
|
|
target.appendChild(d);
|
|
continue;
|
|
}
|
|
if (!narr && !(t.startsWith('*') && !t.startsWith('**'))) {
|
|
// a stray unpaired * mid-line is not a block opener -- render
|
|
// as-is; the stray stays literal
|
|
const d = document.createElement('div');
|
|
d.className = 'line speech';
|
|
renderSpans(d, line);
|
|
target.appendChild(d);
|
|
continue;
|
|
}
|
|
// block narration: an unpaired leading * opens a multi-line
|
|
// block, a trailing * closes it
|
|
let content = line.replace(/^\s*\*/, '');
|
|
narr = true;
|
|
if (t.endsWith('*') && !t.endsWith('**')) {
|
|
narr = false;
|
|
content = content.trimEnd().slice(0, -1);
|
|
}
|
|
const d = document.createElement('div');
|
|
d.className = 'line narration';
|
|
renderSpans(d, content);
|
|
target.appendChild(d);
|
|
}
|
|
if (tags.some((t) => t.kind === 'mind')) {
|
|
// only the mind chips: it is write-only, the chip is its one
|
|
// table-side display. The state machinery (status, agenda, the
|
|
// retired delta tags) renders nowhere in the prose pane -- the
|
|
// dedicated panes carry the derived state, the transcript
|
|
// carries the prose (developer, 2026-11-16)
|
|
const wrap = document.createElement('div');
|
|
wrap.className = 'tags';
|
|
for (const t of tags) {
|
|
if (t.kind !== 'mind') continue;
|
|
for (const item of t.items) {
|
|
const c = document.createElement('span');
|
|
c.className = `chip ${t.kind}`;
|
|
c.textContent = item;
|
|
wrap.appendChild(c);
|
|
}
|
|
}
|
|
target.appendChild(wrap);
|
|
}
|
|
return { status, conflict, agenda };
|
|
}
|
|
|
|
// the request record's line: the resolved spec (provider and model)
|
|
// and the effective params as sent. Shared by the raw walk and the
|
|
// per-turn raw control. fail is present when the call failed -- no
|
|
// message resulted.
|
|
/** @param {{ model: string, provider?: string, params?: Record<string, number|string> }} via @param {?string} [fail] @returns {string} */
|
|
export function viaLine(via, fail = null) {
|
|
const ks = Object.entries(via.params ?? {});
|
|
const p = ks.length ? ` -- ${ks.map(([k, v]) => `${k}: ${v}`).join(', ')}` : ' (no knobs set)';
|
|
const who = via.provider ? `${via.provider}/${via.model}` : via.model;
|
|
return fail ? `[request failed] ${who}${p} -- ${fail}` : `[request] ${who}${p}`;
|
|
}
|
|
|
|
// the GM's block edit, as the machinery line both walks show: the
|
|
// override rides its turn as the record; the composition overwrites
|
|
// her newest blocks with it. The sheet record rides the same way --
|
|
// the GM's ledger, a whole set
|
|
/** @param {{ status?: string[], agenda?: string[] }} o @returns {string} */
|
|
function overrideText(o) {
|
|
const parts = [];
|
|
if (o.status) parts.push(`status ${JSON.stringify(o.status)}`);
|
|
if (o.agenda) parts.push(`agenda ${JSON.stringify(o.agenda)}`);
|
|
return `[block edit] ${parts.join(' | ')} -- composes over her newest blocks`;
|
|
}
|
|
/** @param {Record<string, unknown>} sheet @returns {string} */
|
|
function sheetText(sheet) {
|
|
return `[sheet] ${JSON.stringify(sheet)} -- the GM's ledger`;
|
|
}
|
|
|
|
// the note line, shared by both walks
|
|
/** @param {NoteEvent} e @returns {?string} */
|
|
function noteText(e) {
|
|
if (e.kind === 'session') return `session ${e.n} opened`;
|
|
if (e.kind === 'ask') return `ask_gm: ${e.question}`;
|
|
if (e.kind === 'status') {
|
|
return e.set
|
|
? `status set: ${JSON.stringify(e.set)}`
|
|
: `status: lost ${JSON.stringify(e.applied?.lost ?? [])}, gained ${JSON.stringify(e.applied?.gained ?? [])}`;
|
|
}
|
|
if (e.kind === 'agenda') {
|
|
return e.set
|
|
? `agenda set: ${JSON.stringify(e.set)}${e.evicted?.length ? ` -- evicted ${JSON.stringify(e.evicted)}` : ''}`
|
|
: `agenda: added ${JSON.stringify(e.applied?.added ?? [])}, dropped ${JSON.stringify(e.applied?.dropped ?? [])}`;
|
|
}
|
|
if (e.kind === 'pick') return `variant literature: ${e.count} offered, #${e.chosen + 1} picked`;
|
|
if (e.kind === 'mind') return `mind: ${Object.entries(e.params ?? {}).map(([k, v]) => `${k} ${v}`).join(', ')} -- rides her next turn`;
|
|
if (e.kind === 'state') {
|
|
const parts = [];
|
|
if (e.status) parts.push(`status ${JSON.stringify(e.status)}`);
|
|
if (e.agenda) parts.push(`agenda ${JSON.stringify(e.agenda)}`);
|
|
if (e.sheet) parts.push(`sheet ${JSON.stringify(e.sheet)}`);
|
|
return `boundary state carried across the stop: ${parts.join(' | ')}`;
|
|
}
|
|
if (e.kind === 'start') return 'the frozen opening ends here -- rewind reaches your turns below this line';
|
|
return null;
|
|
}
|
|
|
|
// the transcript's stick-to-bottom: the div itself just grows -- main
|
|
// is the scroller. Firefox can also reclaim a same-tick programmatic
|
|
// scroll around a content wipe (scroll anchoring re-anchoring after
|
|
// the rebuild), so the position re-asserts on the next frame
|
|
/** @param {HTMLElement} t */
|
|
export function stickBottom(t) {
|
|
const sc = t.closest('main');
|
|
if (!sc) return;
|
|
sc.scrollTop = sc.scrollHeight;
|
|
requestAnimationFrame(() => { sc.scrollTop = sc.scrollHeight; });
|
|
}
|
|
|
|
// the raw walk: the audit surface over the same log -- everything as
|
|
// it rode the wire. Thinking, whole variant blocks, every reminder
|
|
// copy, full tool results, the rides inline in the GM prose; plain
|
|
// labeled blocks, no register rendering -- the table is the reading
|
|
// surface, this is the wire.
|
|
/** @param {LogEvent[]} entries */
|
|
export function renderRaw(entries) {
|
|
const t = $('transcript');
|
|
t.textContent = '';
|
|
/** @param {string} who @returns {HTMLElement} */
|
|
const block = (who) => {
|
|
const d = el('div', 'raw-block');
|
|
d.appendChild(el('div', 'who', who));
|
|
t.appendChild(d);
|
|
return d;
|
|
};
|
|
for (const e of entries) {
|
|
if (e.t === 'bundle') {
|
|
// the bundle rides collapsed here too -- it is the same content
|
|
// the table shows, and it is huge
|
|
const d = el('details', 'bundle');
|
|
d.appendChild(el('summary', null, `bundle -- ${e.part}`));
|
|
d.appendChild(el('pre', null, e.m.content));
|
|
t.appendChild(d);
|
|
continue;
|
|
}
|
|
if (e.t === 'opening') {
|
|
t.appendChild(el('div', 'machinery', `her opening status: ${JSON.stringify(e.status)}`));
|
|
continue;
|
|
}
|
|
if (e.t === 'req') {
|
|
// a failed provider request: the record of what was attempted
|
|
t.appendChild(el('div', 'machinery', viaLine(e, e.fail)));
|
|
continue;
|
|
}
|
|
if (e.t === 'note') {
|
|
const text = noteText(e);
|
|
if (text) t.appendChild(el('div', 'machinery', text));
|
|
continue;
|
|
}
|
|
if (e.t === 'tool') {
|
|
const d = block(e.ask ? 'ruling' : 'tool result');
|
|
d.appendChild(el('pre', null, String(e.m.content)));
|
|
continue;
|
|
}
|
|
if (e.t === 'msg' && e.reminder) {
|
|
// every copy shows: the raw log keeps each as-sent chunk, and
|
|
// the audit surface keeps them all (the table elides superseded
|
|
// ones)
|
|
const d = el('details', 'bundle');
|
|
d.appendChild(el('summary', null, 'turn reminder -- as sent'));
|
|
d.appendChild(el('pre', null, String(e.m.content ?? '')));
|
|
t.appendChild(d);
|
|
continue;
|
|
}
|
|
if (e.t === 'msg' && e.m.role === 'user') {
|
|
const d = block(e.conflictOnly ? 'gm -- conflict only' : 'gm');
|
|
d.appendChild(el('pre', null, String(e.m.content ?? '')));
|
|
if (e.override) d.appendChild(el('div', 'machinery', overrideText(e.override)));
|
|
if (e.sheet) d.appendChild(el('div', 'machinery', sheetText(e.sheet)));
|
|
continue;
|
|
}
|
|
if (e.t === 'msg' && e.m.role === 'assistant') {
|
|
const d = block('player');
|
|
if (e.m.reasoning_content) d.appendChild(el('pre', 'raw-thinking', e.m.reasoning_content));
|
|
if (e.via) d.appendChild(el('div', 'machinery', viaLine(e.via)));
|
|
d.appendChild(el('pre', null, String(e.m.content ?? '')));
|
|
for (const c of e.m.tool_calls ?? []) {
|
|
d.appendChild(el('div', 'machinery', `[tool call] ${c.function.name}`));
|
|
if (c.function.arguments) d.appendChild(el('pre', null, String(c.function.arguments)));
|
|
}
|
|
continue;
|
|
}
|
|
}
|
|
stickBottom(t);
|
|
}
|
|
|
|
// the entry walk. onConflict receives a conflict block found on a GM
|
|
// turn -- the play view owns where it lands (the status pane).
|
|
// onRaw, when given, puts a small control on every GM/player turn
|
|
// that shows that one entry's wire form inline -- the play view owns
|
|
// the fetch (the raw session is the audit surface; the walks are
|
|
// index-aligned, so table entry i is session entry i). onRewind, when
|
|
// given, puts the rewind control on every GM turn (the play view
|
|
// passes it only while it may fire: live, no pending ask) -- the
|
|
// callback receives the entry's index, its text, and the button, and
|
|
// owns the two-click arm and everything the gesture stages. The
|
|
// opening event (her opening status) renders as machinery, mirroring
|
|
// the wire policy: it is set once, never re-sent.
|
|
/** @param {LogEvent[]} entries @param {{ onConflict?: (text: string) => void, onRaw?: (idx: number, slot: HTMLElement) => Promise<void>, onRewind?: (idx: number, text: string, btn: HTMLButtonElement) => void }} [opts] */
|
|
export function renderTranscript(entries, { onConflict, onRaw, onRewind } = {}) {
|
|
const t = $('transcript');
|
|
t.textContent = '';
|
|
/** @type {BundleEvent[]} */ const bundleParts = [];
|
|
const flushBundle = () => {
|
|
if (!bundleParts.length) return;
|
|
const d = el('details', 'bundle');
|
|
d.appendChild(el('summary', null, `session bundle -- ${bundleParts.map((p) => p.part).join(', ')}`));
|
|
for (const p of bundleParts) {
|
|
const sec = el('details');
|
|
sec.appendChild(el('summary', null, p.part));
|
|
sec.appendChild(el('pre', null, p.m.content));
|
|
d.appendChild(sec);
|
|
}
|
|
t.appendChild(d);
|
|
bundleParts.length = 0;
|
|
};
|
|
|
|
for (let idx = 0; idx < entries.length; idx++) {
|
|
const e = entries[idx];
|
|
if (e.t === 'bundle') {
|
|
// every part is inspectable, read-only: system (guards +
|
|
// substrate + craft), backdrop, character, the rings
|
|
bundleParts.push(e);
|
|
continue;
|
|
}
|
|
flushBundle();
|
|
if (e.t === 'msg' && e.reminder) {
|
|
// the reminder never renders in the prose pane (developer, 2026-11-16):
|
|
// it is the same every turn -- the raw tab keeps every copy,
|
|
// the audit surface is its home
|
|
continue;
|
|
}
|
|
if (e.t === 'opening') {
|
|
t.appendChild(el('div', 'machinery', `her opening status: ${JSON.stringify(e.status)}`));
|
|
continue;
|
|
}
|
|
if (e.t === 'req') continue; // a failed request's record -- the raw surfaces carry it
|
|
if (e.t === 'msg') {
|
|
if (e.m.role === 'user' && e.conflictOnly) {
|
|
// the self-heal message: error traffic on its own, never GM prose
|
|
t.appendChild(el('div', 'machinery', `[conflict] ${String(e.m.content).replace(/<\/?conflict>/g, '').trim()}`));
|
|
continue;
|
|
}
|
|
if (e.m.role === 'user') gmTurn(e, idx, 'GM');
|
|
else if (e.m.role === 'assistant') playerTurn(e, idx);
|
|
continue;
|
|
}
|
|
if (e.t === 'tool') {
|
|
t.appendChild(el('div', 'machinery', `${e.ask ? '[ruling] ' : '[tool result] '}${String(e.m.content).split('\n')[0]}`));
|
|
continue;
|
|
}
|
|
if (e.t === 'note') {
|
|
// the state receipts never render in the prose pane (developer,
|
|
// 2026-11-16): the status/agenda notes -- the old delta applies
|
|
// and the whole-list sets alike -- duplicate the panes; the raw
|
|
// tab keeps every receipt
|
|
if (e.kind === 'status' || e.kind === 'agenda') continue;
|
|
renderNote(e);
|
|
}
|
|
}
|
|
flushBundle();
|
|
stickBottom(t);
|
|
|
|
/** @param {MsgEvent} e @param {number} idx @param {string} who */
|
|
function gmTurn(e, idx, who) {
|
|
const d = el('div', 'turn gm');
|
|
const head = el('div', 'who', who);
|
|
d.appendChild(head);
|
|
const body = el('div');
|
|
d.appendChild(body);
|
|
const { conflict } = renderContent(body, e.m.content, { extract: true });
|
|
if (conflict) onConflict?.(conflict);
|
|
if (e.override) d.appendChild(el('div', 'machinery', overrideText(e.override)));
|
|
if (e.sheet) d.appendChild(el('div', 'machinery', sheetText(e.sheet)));
|
|
if (onRaw) addRawControl(head, d, idx);
|
|
if (onRewind) {
|
|
const btn = /** @type {HTMLButtonElement} */ (el('button', 'rewind-toggle', 'rewind'));
|
|
head.appendChild(btn);
|
|
onRewind(idx, String(e.m.content ?? ''), btn);
|
|
}
|
|
t.appendChild(d);
|
|
}
|
|
/** @param {MsgEvent} e @param {number} idx */
|
|
function playerTurn(e, idx) {
|
|
const d = el('div', 'turn player');
|
|
const head = el('div', 'who', 'player');
|
|
d.appendChild(head);
|
|
const body = el('div');
|
|
d.appendChild(body);
|
|
renderContent(body, e.m.content, { extract: false });
|
|
for (const c of e.m.tool_calls ?? []) {
|
|
d.appendChild(el('div', 'machinery', `[tool call] ${c.function.name}`));
|
|
}
|
|
if (onRaw) addRawControl(head, d, idx);
|
|
t.appendChild(d);
|
|
}
|
|
/** @param {NoteEvent} e */
|
|
function renderNote(e) {
|
|
const text = noteText(e);
|
|
if (text) t.appendChild(el('div', 'machinery', text));
|
|
}
|
|
|
|
// the per-turn raw control: the who row carries the button, the
|
|
// card gains a slot under the body -- onRaw fills it on first open
|
|
// (the caller owns the fetch and its errors), later clicks toggle
|
|
/** @param {HTMLElement} head @param {HTMLElement} card @param {number} idx */
|
|
function addRawControl(head, card, idx) {
|
|
const btn = /** @type {HTMLButtonElement} */ (el('button', 'raw-toggle', 'raw'));
|
|
head.appendChild(btn);
|
|
btn.addEventListener('click', async () => {
|
|
const slot = /** @type {?HTMLElement} */ (card.querySelector('.raw-slot'));
|
|
if (slot && slot.childElementCount) {
|
|
slot.hidden = !slot.hidden; // filled already -- just toggle
|
|
return;
|
|
}
|
|
const fresh = slot ?? el('div', 'raw-slot');
|
|
if (!slot) card.appendChild(fresh);
|
|
btn.disabled = true;
|
|
try {
|
|
await onRaw?.(idx, fresh);
|
|
} finally {
|
|
btn.disabled = false;
|
|
}
|
|
});
|
|
}
|
|
}
|