Official

chat

Built-in chat UI (JavaScript UI plugin).

The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install convergence/chat@0.2.3

Permissions in 0.2.3

  • Control chats chats.controlHighCreates chats, sends prompts and cancels runs.Send prompts, answer agent questions, and create, change, fork, revert, stop and group chats
  • Run other plugins' commands commands.runHighRuns commands of other plugins.Run the sidebar's New chat command from the title bar
  • Read chats chats.readMediumReads your transcripts and chat lists.Show workspaces, tasks, chats and transcripts, and follow them as agents work
  • Read files fs.readMediumReads files in the listed places.Suggest workspace files for @ mentionsPlaces: the open workspace
  • Show panels ui.slotsAlways grantedShows views in the listed parts of the window.Draw the chat grid, the title bar, and the Session panel with its rail buttonSlots: centertitlerailright

Files

views/rows.ts25.6 KB
// Rows rendering preserves the chat's retained tree and interaction keys.
import * as z from "zod";
import { html } from "convergence";
import { editStats, groupTitle, foldItems } from "../grouping.ts";
import { groupTasks, withoutSpawnRows } from "../subagents.ts";
import { sessionChanges } from "../transcript.ts";
import type { SessionChange } from "../transcript.ts";
import type { Element, Chat, Plan, SecurityRequest, ToolStatus, TranscriptItem, ValueEvent } from "convergence";
import type { ProgramCall } from "convergence/protocol";
import type { Transcript, UserItem, TextItem, ToolItem, ActivityProps } from "../state.ts";
import type { ChatView } from "../controller.ts";
import type { ToolGroup } from "../grouping.ts";
import { renderApproval, renderPublishRow, placeRequests, renderQuestion } from "./questions.ts";
import { renderTask, renderTaskGroup, renderWorkflow } from "./tasks.ts";
import {
  READING_WIDTH,
  FIELD_INSET_X,
  column,
  row,
  fill,
  full,
  HOVER,
  clickable,
  revealOnHover,
  centred,
  ROW_TEXT,
  TOOL_ICONS,
  TOOL_LABELS,
  RAISED,
  corner,
} from "./styles.ts";
export function activityRow(_v: ChatView, props: ActivityProps): Element | null {
  const { icon, label, detail, extra, status, open, onClick, tone, compact } = props;
  const gap = "medium";
  // The text sits in a filled row so the detail still truncates; the
  // opacity is on the row because text takes none. No padding of its
  // own, so the label starts on the reply text's line.
  return html`
      <div ...${row} ...${onClick ? clickable : null} gap=${gap} padding="small" paddingX=${compact ? 6 : 5} paddingY=${compact ? 5 : "small"}
        borderRadius="md" hover=${onClick ? HOVER : undefined} onClick=${onClick}>
        ${
          icon
            ? html`
            <div ...${row} gap="small" padding="small" width=${14} flexShrink=${0} height=${14} lineHeight=${14} justifyContent="center">
              ${typeof icon === "string" ? html`<icon name=${icon} small tone=${tone ?? "faint"} />` : icon}
            </div>`
            : null
        }
        <div ...${row} ...${fill} gap=${gap} padding=${0} opacity=${tone ? undefined : 0.8}>
          ${label ? html`<text style="body" ...${ROW_TEXT} tone=${tone ?? "foreground"}>${label}</text>` : null}
          ${detail ? html`<text style="body" ...${ROW_TEXT} tone=${tone ?? "foreground"} truncate>${detail}</text>` : null}
          ${extra ?? null}
        </div>
        ${status ?? null}
        ${
          onClick
            ? html`<div ...${column} ...${revealOnHover} gap="small" padding=${0}><icon name=${open ? "chevron-down" : "chevron-right"} small tone="muted" /></div>`
            : null
        }
      </div>`;
}

// No vertical padding: a row with the counts is as tall as one without.
export function statsRow(_v: ChatView, stats: { added: number; removed: number } | null): Element | null {
  if (!stats) return null;
  return html`
      <div ...${row} gap=${6} padding=${0} paddingX=${3}>
        <text style="body" size="xs" weight=${620} lineHeight=${14.6} tone="success">${`+${stats.added}`}</text>
        <text style="body" size="xs" weight=${620} lineHeight=${14.6} tone="danger">${`-${stats.removed}`}</text>
      </div>`;
}

export function renderUser(
  v: ChatView,
  chatId: string,
  t: Transcript,
  item: UserItem,
  pending = false,
): Element | null {
  // Editing replaces the message: the files go back to the checkpoint
  // taken before it and the turns after it are dropped, so it is offered
  // only while nothing is running.
  if (t.editing === item.id) {
    return html`
        <div ...${column} gap="small" padding="small" paddingY="medium" alignItems="end">
          <div ...${column} ...${full} gap="small" padding="small" maxWidth=${600}>
            <div ...${column} gap="small" padding="small" paddingX=${FIELD_INSET_X} paddingY="small" background="card" borderRadius="md" ...${RAISED}>
              <input id=${`edit-${item.id}`} value=${t.editText} multiline ghost submitOnEnter
                onChange=${(e: ValueEvent<string>) => {
                  t.editText = e.value;
                }}
                onSubmit=${() => v.ctx.run(v.controller.submitEdit(chatId, item.id))} />
            </div>
            <div ...${row} gap="small" padding="small">
              <spacer />
              <button id=${`edit-cancel-${item.id}`} label="Cancel" variant="ghost" small onClick=${() => {
                t.editing = null;
                v.controller.view.update();
              }} />
              <button id=${`edit-send-${item.id}`} label="Send again" variant="primary" small onClick=${() => v.ctx.run(v.controller.submitEdit(chatId, item.id))} />
            </div>
          </div>
        </div>`;
  }
  const chat = v.controller.state.chats[chatId];
  const running = pending || t.running || !!t.resending || t.loading || v.controller.isRunning(chat);
  // The host refuses an edit the agent cannot rewind its own conversation for.
  const editable = !!(chat && v.controller.state.agents[chat.agentId]?.capabilities?.rollback);
  const images = pending
    ? (v.controller.composer(chatId).outgoing?.attachments.map((image) => image.id) ?? [])
    : v.controller.imagesOf(item);
  // Stored images (docs/adr/0003): the kernel draws a box of the stored
  // size at once and reads the file only while the row is on screen.
  const stored = pending
    ? []
    : item.blocks.flatMap((block) =>
        block.type === "image" && block.path && block.width && block.height
          ? [{ path: block.path, width: block.width, height: block.height }]
          : [],
      );
  const text = v.controller.plainText(item.blocks);
  // A screenshot takes the message's corner: its frame is `xl` and clips
  // it there, and the picture has the same corner where the frame cannot
  // clip (no rounded clip on the platform).
  const MESSAGE_IMAGE_RADIUS = corner("xl", 15.5);
  return html`
      <div ...${column} padding="small" paddingY="small" alignItems="end">
        ${
          images.length || stored.length
            ? html`
            <div ...${row} width="100%" gap="small" padding="small" paddingY="small" maxWidth=${600} justifyContent="end" flexWrap="wrap">
              ${[
                ...images.map((id) => html`<image id=${id} maxHeight=${360} radius=${MESSAGE_IMAGE_RADIUS} />`),
                ...stored.map(
                  (image) =>
                    html`<image path=${image.path} pixelWidth=${image.width} pixelHeight=${image.height} maxHeight=${360} radius=${MESSAGE_IMAGE_RADIUS} />`,
                ),
              ].map(
                (picture) =>
                  // The shadow on a frame around the clip: a clipped box
                  // clips its own shadow too.
                  html`<div maxWidth="100%" minWidth=${0} borderRadius="xl" ...${RAISED}><div maxWidth="100%" borderRadius=${MESSAGE_IMAGE_RADIUS} overflow="hidden">${picture}</div></div>`,
              )}
            </div>`
            : null
        }
        ${
          text
            ? html`
            <div ...${column} gap="small" padding="small" paddingX=${11} paddingY="medium" maxWidth=${600} background="bubble"
              fontSize=${13.125} lineHeight=${21.3} borderRadius="xl" ...${RAISED}>
              <markdown id=${`md-${item.id}`} text=${text} />
            </div>`
            : null
        }
        <div ...${row} ...${full} gap="small" padding="small" justifyContent="end">
          ${
            running || !editable
              ? null
              : html`<button id=${`edit-${item.id}`} icon="pencil" variant="ghost" small tooltip="Edit this message and run again from here"
                onClick=${() => {
                  t.editing = item.id;
                  t.editText = v.controller.plainText(item.blocks);
                  v.controller.view.update();
                }} />`
          }
          <div visibility=${!pending && !t.loading && t.checkpoints.has(item.id) ? "visible" : "hidden"}>
            <button id=${`restore-${item.id}`} icon="rotate-ccw" variant="ghost" small tooltip="Revert the workspace files to before this prompt"
              onClick=${() => v.ctx.run(v.controller.revert(chatId, item.id))} />
          </div>
        </div>
      </div>`;
}

export function renderAssistant(_v: ChatView, _chat: Chat, item: TextItem): Element | null {
  // A model sometimes ends a step with a blank line and nothing else;
  // a heading over empty space would look like a lost reply.
  if (!item.text.trim()) return null;
  return html`
      <div ...${column} gap="small" padding="small" paddingX=${5} paddingY=${8} fontSize=${13.125} lineHeight=${18.75}>
        <markdown id=${`md-${item.id}`} text=${item.text} />
      </div>`;
}

export function renderArtifact(
  v: ChatView,
  t: Transcript,
  item: Extract<TranscriptItem, { role: "artifact" }>,
): Element {
  const open = t.expanded.has(item.id);
  const fallback = html`
    <div ...${column} gap="small" padding="small">
      <text weight=${600}>${item.artifact.title}</text>
      <text>${item.artifact.summary}</text>
      <text tone="muted" size="xs">${`The ${item.artifact.owner} renderer is unavailable. The saved data remains readable.`}</text>
      <button id=${`source-${item.id}`} label=${open ? "Hide source" : "Show source"} variant="ghost" small
        onClick=${() => v.controller.toggle(t.expanded, item.id)} />
      ${open ? html`<code text=${JSON.stringify(item.artifact, null, 2)} language="json" />` : null}
    </div>`;
  if (typeof v.controller.api.artifactRenderers !== "function") return fallback;
  return html`<artifact_view id=${item.id} artifact=${item.artifact}>${fallback}</artifact_view>`;
}

export function bodyInset(_v: ChatView, folded?: boolean): { paddingX: number; paddingY: string } {
  return { paddingX: folded ? 6 : 5, paddingY: "small" };
}

export function renderReasoning(v: ChatView, t: Transcript, item: TextItem, folded?: boolean): Element | null {
  const streaming = t.running && t.items[t.items.length - 1]?.id === item.id;
  const open = t.expanded.has(item.id) || streaming;
  const first =
    item.text
      .split("\n")
      .find((l) => l.trim())
      ?.replace(/^#+\s*|\*\*/g, "") ?? "";
  const title = streaming ? "Thinking" : open || !first ? "Thought" : first;
  return html`
      <div ...${column} padding=${0}>
        ${activityRow(v, { compact: folded, detail: title, open, onClick: () => v.controller.toggle(t.expanded, item.id) })}
        ${
          open
            ? html`
            <div ...${column} gap="small" padding="small" ...${bodyInset(v, folded)} opacity=${0.85} fontSize=${11.25} lineHeight=${14.6}>
              <markdown id=${`md-${item.id}`} text=${item.text} />
            </div>`
            : null
        }
      </div>`;
}

export function renderToolBody(v: ChatView, call: import("convergence").ToolCall, chat: Chat): Element | null {
  const parts = [];
  const diffPaths = new Set<string>();
  const code = (text: string, language?: string) => html`<code text=${text} language=${language} />`;
  // Code mode: the program the agent ran, then what it gave back.
  const parsed = z.object({ code: z.string() }).strict().safeParse(call.input);
  const program = parsed.success ? parsed.data.code : null;
  if (program) parts.push(code(program, "javascript"));
  for (const c of call.content ?? []) {
    if (c.type === "terminal") {
      // The command column shrinks so a long command wraps inside the
      // card instead of running past its edge.
      parts.push(
        html`
          <div ...${column} gap="small" padding="small">
            <div ...${row} gap="small" padding="small" alignItems="start">
              <text style="mono" tone="muted">$</text>
              <div ...${column} ...${fill} gap="small" padding="small"><text style="mono" text=${String(c.command ?? "")} /></div>
            </div>
            ${c.output ? code(clip(v, c.output)) : null}
            ${c.exitCode ? html`<text style="body" size="xs" tone="muted">${`exit ${c.exitCode}`}</text>` : null}
          </div>`,
      );
    } else if (c.type === "diff") {
      diffPaths.add(c.path);
      parts.push(
        html`<diff path=${inWorkspace(v, c.path, chat)} diff=${c.diff} oldText=${c.oldText} newText=${c.newText} maxLines=${200} />`,
      );
    } else if (c.type === "text") {
      parts.push(code(clip(v, c.text)));
    } else if (c.type === "image") {
      parts.push(html`<text style="body" size="xs" tone="muted">${c.path ? `Image: ${c.path}` : "Image"}</text>`);
    }
  }
  // Some agents report the whole result as structured output and send no
  // content at all, which used to render an empty card.
  // A text result (a command's output) reads as text, not as one quoted line.
  if (!call.content?.length && call.output != null)
    parts.push(
      typeof call.output === "string"
        ? code(clip(v, call.output))
        : code(clip(v, JSON.stringify(call.output, null, 2)), "json"),
    );
  if (!parts.length && call.input != null) parts.push(code(JSON.stringify(call.input, null, 2), "json"));
  const locations = (call.locations ?? [])
    .filter((l) => !diffPaths.has(l.path))
    .map((l) => inWorkspace(v, l.line ? `${l.path}:${l.line}` : l.path, chat));
  if (locations.length) parts.push(html`<text style="body" size="xs" tone="muted">${locations.join("  ")}</text>`);
  return html`
      <div ...${column} gap="small" padding="medium" background="card" fontSize=${11.25} lineHeight=${14.6} borderRadius="sm">${parts}</div>`;
}

export function clip(_v: ChatView, text: string): string {
  const MAX = 20000;
  return text.length > MAX ? `…\n${text.slice(-MAX)}` : text;
}

export function inWorkspace(v: ChatView, text: string, chat: Chat): string {
  const root = v.controller.state.workspaces[chat?.workspaceId]?.path;
  return root ? text.split(`${root}/`).join("") : text;
}

function toolStatus(status: ToolStatus | undefined): Element | null {
  return status === "failed"
    ? html`<icon name="circle-alert" small tone="muted" />`
    : status === "cancelled"
      ? html`<text style="body" size="xs" tone="muted">cancelled</text>`
      : status === "completed"
        ? null
        : html`<spinner activity />`;
}

/// One call a code mode program made: a compact activity row, its tool's
/// path and the short form of its input the host sent.
function renderProgramCall(v: ChatView, call: ProgramCall): Element | null {
  const input = call.input;
  const shown = (value: unknown) => (typeof value === "string" ? value : JSON.stringify(value));
  const detail =
    input && typeof input === "object" && !Array.isArray(input)
      ? Object.entries(input)
          .map(([key, value]) => `${key}: ${shown(value)}`)
          .join("  ")
      : input === undefined
        ? ""
        : shown(input);
  return activityRow(v, {
    compact: true,
    icon: TOOL_ICONS.other,
    label: call.tool,
    detail: detail.split("\n")[0] ?? "",
    status: toolStatus(call.status),
  });
}

export function renderTool(v: ChatView, t: Transcript, item: ToolItem, chat: Chat, folded?: boolean): Element | null {
  const call = item.call;
  // A plugin that registered a renderer for this tool draws it, in its
  // own runtime; the kernel places its view here.
  const owned = v.controller.api
    .toolRenderers()
    .some((r) => (r.name && r.name === call.name) || (r.kind && r.kind === call.kind));
  if (owned) return html`<tool_view call=${call} id=${String(call.id ?? "")} />`;
  const calls = call.calls ?? [];
  const hasBody = (call.content?.length ?? 0) > 0 || call.output != null || call.input != null || calls.length > 0;
  const open = hasBody && t.expanded.has(call.id);
  const label = TOOL_LABELS[call.kind ?? "other"] ?? "";
  const stats = call.kind === "edit" && call.status === "completed" ? statsRow(v, editStats([item])) : null;
  const count = calls.length
    ? html`<text style="body" ...${ROW_TEXT} tone="muted">${calls.length === 1 ? "1 call" : `${calls.length} calls`}</text>`
    : null;
  // A multi-line command (a heredoc, say) shows its first line in the row;
  // the whole command is in the body.
  const detail =
    inWorkspace(v, call.title, chat)
      .split("\n")
      .find((l) => l.trim()) ?? "";
  // A code mode program opens like a fold of tool calls: one raised card
  // with a row per call it made, then the program and its result.
  const body = calls.length
    ? html`
        <div ...${column} id=${`program-scroll-${call.id}`} followEnd gap=${2} padding=${5} maxHeight=${400} background="card" borderRadius="md" ...${RAISED} overflowY="scroll">
          ${calls.map((programCall) => renderProgramCall(v, programCall))}
          <div ...${column} gap="small" padding="small" ...${bodyInset(v, true)}>${renderToolBody(v, call, chat)}</div>
        </div>`
    : html`<div ...${column} gap="small" padding="small" ...${bodyInset(v, folded)}>${renderToolBody(v, call, chat)}</div>`;
  return html`
      <div ...${column} gap=${calls.length && open ? 2 : undefined} padding=${0}>
        ${activityRow(v, { compact: folded, icon: TOOL_ICONS[call.kind ?? "other"] ?? "cpu", label, detail, extra: count ?? stats, status: toolStatus(call.status), open, onClick: hasBody ? () => v.controller.toggle(t.expanded, call.id) : undefined })}
        ${open ? body : null}
      </div>`;
}

export function renderPlan(_v: ChatView, plan: Plan): Element | null {
  const icon = { pending: "circle", in_progress: "loader", completed: "circle-check" };
  const tone = { pending: "faint", in_progress: "info", completed: "success" };
  return html`
      <div ...${column} gap="small" padding="medium" background="card" borderRadius="md">
        ${(plan.entries ?? []).map(
          (e) =>
            html`
          <div ...${row} gap="small" padding="small">
            <icon name=${icon[e.status ?? "pending"] ?? "circle"} small tone=${tone[e.status ?? "pending"] ?? "muted"} />
            <text style="body" size="sm" text=${String(e.content ?? "")} />
          </div>`,
        )}
      </div>`;
}

export function renderCompaction(v: ChatView, item: Extract<TranscriptItem, { role: "compaction" }>): Element | null {
  return activityRow(v, {
    icon: "fold-vertical",
    label: item.summary || "Earlier messages were summarized to free context.",
  });
}

export function renderItem(
  v: ChatView,
  chat: Chat,
  t: Transcript,
  item: TranscriptItem,
  folded?: boolean,
  pending = false,
): Element | null {
  switch (item.role) {
    case "user":
      return html`
          <div ...${column} padding="small">
            <div ...${row} gap="small" padding="small" height=${12} />
            ${renderUser(v, chat.id, t, item, pending)}
          </div>`;
    case "assistant":
      return renderAssistant(v, chat, item);
    case "reasoning":
      return renderReasoning(v, t, item, folded);
    case "tool":
      return renderTool(v, t, item, chat, folded);
    case "artifact":
      return renderArtifact(v, t, item);
    case "plan":
      return renderPlan(v, item.plan);
    case "notice":
      return html`<text style="body" size="xs" tone="muted" text=${String(item.text ?? "")} />`;
    case "task":
      return item.task.workflow ? renderWorkflow(v, chat, t, item) : renderTask(v, chat, t, item);
    case "compaction":
      return renderCompaction(v, item);
    default:
      return null;
  }
}

// A line across the reading column with the agents in its middle, above the
// first message sent after a handoff or in a new native session.
export function renderSessionChange(v: ChatView, change: SessionChange): Element {
  const agents = v.controller.state.agents;
  const mark = (agentId: string) => html`<icon name="bot" small tone="muted" svg=${agents[agentId]?.icon} />`;
  const line = html`<div ...${fill} height=${1} background="border/60" />`;
  const caption = (text: string) =>
    html`<text style="body" size="xs" weight=${560} lineHeight=${14.6} tone="muted">${text}</text>`;
  const handoff = change.kind === "handoff";
  return html`
      <div ...${column} group="hover" gap=${2} padding=${0} paddingTop=${14} alignItems="center">
        <div ...${row} width="100%" gap="medium" padding=${0}>
          ${line}
          <div ...${row} gap=${6} padding=${0} flexShrink=${0}>
            ${
              handoff
                ? html`${mark(change.from)}<icon name="arrow-right" small tone="faint" />${mark(change.to)}${caption("Handed off")}`
                : html`${mark(change.to)}${caption("New session")}`
            }
          </div>
          ${line}
        </div>
        ${
          handoff
            ? null
            : html`<div ...${revealOnHover} padding=${0}><text style="body" size="xs" lineHeight=${14.6} tone="faint">The previous session was unavailable. The conversation so far went to a new one.</text></div>`
        }
      </div>`;
}

function withSessionChange(v: ChatView, change: SessionChange | undefined, rendered: Element | null): Element | null {
  if (!change) return rendered;
  return html`<div ...${column} padding=${0}>${renderSessionChange(v, change)}${rendered}</div>`;
}

export function renderFold(v: ChatView, chat: Chat, t: Transcript, entry: ToolGroup, last?: boolean): Element | null {
  const calls = entry.items.filter((item) => item.role === "tool").map((item) => item.call);
  const failed = calls.some((call) => call.status === "failed");
  const running = calls.some((call) => call.status === "pending" || call.status === "running");
  const open = t.folds.get(entry.id) ?? last;
  const stats = editStats(entry.items);
  const status = failed ? html`<icon name="circle-alert" small tone="muted" />` : running ? html`<spinner activity />` : null;
  // The title starts on the same line as the reply text (both inset 5).
  return html`
      <div ...${column} gap=${2} padding="small" paddingX=${0} paddingY=${4}>
        ${activityRow(v, {
          label: groupTitle(entry.items),
          extra: statsRow(v, stats),
          status,
          open,
          onClick: () => {
            t.folds.set(entry.id, !open);
            v.controller.view.update();
          },
        })}
        ${
          open
            ? html`
            <div ...${column} id=${`fold-scroll-${entry.id}`} followEnd gap=${2} padding=${5} maxHeight=${400} background="card" borderRadius="md" ...${RAISED} overflowY="scroll">
              ${entry.items.map((item) => renderItem(v, chat, t, item, true))}
            </div>`
            : null
        }
      </div>`;
}

export function renderItems(
  v: ChatView,
  chat: Chat,
  t: Transcript,
  items: TranscriptItem[],
  requests: readonly SecurityRequest[] = [],
): (Element | null)[] {
  // "Group tool calls" is the plugin's own setting (plugin.json).
  const shown = withoutSpawnRows(items);
  const entries = groupTasks(
    v.controller.api.settings.get("groupTools") === false
      ? shown.map((item) => ({ kind: "item", item }))
      : foldItems(shown),
  );
  const changes = sessionChanges(shown, t.sessions);
  const rows = entries.map((entry, i) => {
    if (entry.kind === "item")
      return withSessionChange(v, changes.get(entry.item.id), renderItem(v, chat, t, entry.item));
    if (entry.kind === "tasks") return renderTaskGroup(v, chat, t, entry);
    return renderFold(v, chat, t, entry, i === entries.length - 1);
  });
  return requests.length ? placeRequests(v, entries, rows, requests) : rows;
}

// `footer` floats over the bottom of the transcript, which scrolls under it.
export function renderTranscript(v: ChatView, chat: Chat, footer?: Element | null): Element | null {
  const chatId = chat.id;
  const t = v.controller.transcript(chatId);
  // The publish row, or in a chat that fixes a bug report the attach
  // row, ends the transcript (§10.6, §14.2).
  const endRow = (r: SecurityRequest) => r.kind === "publish" || r.kind === "attach_fix";
  const publish = t.requests.filter(endRow);
  const rows = renderItems(
    v,
    chat,
    t,
    t.items,
    t.requests.filter((r) => !endRow(r)),
  );
  const outgoing = v.controller.composer(chatId).outgoing;
  if (outgoing?.preview && !t.items.some((item) => item.id === outgoing.id)) {
    const preview: UserItem = {
      id: outgoing.id,
      role: "user",
      blocks: outgoing.blocks ?? [{ type: "text", text: outgoing.text }],
    };
    // The message goes to the chat's current session: a handoff shows its
    // divider before the host has the message.
    const last = [...t.items].reverse().find((item) => item.role === "user");
    const sessions = { [preview.id]: { agentId: chat.agentId, sessionId: chat.sessionId ?? null } };
    if (last && t.sessions[last.id]) sessions[last.id] = t.sessions[last.id]!;
    const change = sessionChanges(last ? [last, preview] : [preview], sessions).get(preview.id);
    rows.push(withSessionChange(v, change, renderItem(v, chat, t, preview, undefined, true)));
  }
  if (t.plan?.entries?.length) rows.push(renderPlan(v, t.plan));
  if (!t.running) for (const req of publish) rows.push(renderPublishRow(v, chatId, req));
  for (const a of t.approvals) rows.push(renderApproval(v, chatId, a));
  for (const q of t.questions) rows.push(renderQuestion(v, chatId, t, q));
  if (t.running && !t.approvals.length && !t.questions.some((q) => q.responseMode !== "message"))
    rows.push(activityRow(v, { icon: html`<spinner activity />`, label: "Working…" }));
  else if (t.resending) rows.push(activityRow(v, { icon: html`<spinner />`, label: "Sending again…" }));
  else if (outgoing?.preview) rows.push(activityRow(v, { icon: html`<spinner />`, label: "Submitting…" }));
  // Near the first row the scroller asks for the page before it.
  const older = t.start > 0 ? () => v.ctx.run(v.controller.loadOlder(chatId)) : undefined;
  return html`<scroller id=${`transcript-${chatId}`} onReachStart=${older}>${rows.map((row) => reading(v, [row]))}${footer ? html`<slot name="footer">${footer}</slot>` : null}</scroller>`;
}

export function reading(_v: ChatView, children: readonly (Element | null)[]): Element | null {
  return html`<div ...${column} ...${centred} gap="small" padding="small" paddingX=${22.5} paddingY=${0} maxWidth=${READING_WIDTH}>${children}</div>`;
}

Versions

VersionPublishedPlugin APISizePermissionsStatus
0.2.5latestNov 21, 2026>=2 <4174.6 KB5 permissionsListed
0.2.4Oct 25, 2026>=2 <4174.2 KB5 permissionsListed
0.2.3Oct 24, 2026>=2 <4165.4 KB5 permissionsListed
0.2.2Oct 23, 2026>=2 <4165 KB5 permissionsListed
0.2.1Oct 6, 2026>=2 <3111.8 KB5 permissionsListed
0.2.0Oct 5, 2026>=2 <3105.1 KB5 permissionsListed

Reviews and comments

0 threads · 0 reviews

No comments yet.