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.2
Permissions in 0.2.2
Files
views/panes.ts8.2 KB
// Panes rendering preserves the chat's retained tree and interaction keys.
import { html } from "convergence";
import { VISIBLE, reconcile as reconcileCycle, visible } from "../switcher.ts";
import type { Chat, Element } from "convergence";
import type { ChatView } from "../controller.ts";
import { selectedChat } from "../input-schema.ts";
import { renderTranscript, reading } from "./rows.ts";
import { renderComposer, renderLanding } from "./composer.ts";
import { column, row, fill, full } from "./styles.ts";
export function switcherRow(v: ChatView, id: string, chosen: boolean): Element | null {
const chat = v.controller.state.chats[id];
if (!chat) return null;
const workspace = v.controller.state.workspaces[chat.workspaceId]?.name ?? "";
return html`
<item id=${`switch-${id}`} label=${v.controller.titleOf(chat)} sublabel=${workspace || undefined} selected=${chosen}
busy=${v.controller.isRunning(chat)} icon="bot" iconSvg=${v.controller.state.agents[chat.agentId]?.icon}
onClick=${() => {
v.controller.state.switcher = { list: [id], selected: id };
v.ctx.run(v.controller.commitSwitcher());
}} />`;
}
export function renderSwitcher(v: ChatView): Element | null {
// The list is checked against the chats the app still has: one closed
// while the cycle is open must not leave a row behind.
const open = reconcileCycle(v.controller.state.switcher, v.controller.state.chats);
v.controller.state.switcher = open;
const { rows } = open ? visible(open.list, open.selected, VISIBLE) : { rows: [] };
const keys = {
up: () => v.controller.switchBy(-1),
left: () => v.controller.switchBy(-1),
down: () => v.controller.switchBy(1),
right: () => v.controller.switchBy(1),
enter: () => v.ctx.run(v.controller.commitSwitcher()),
escape: v.controller.closeSwitcher,
};
// The overlay draws the card around the column; only the rows are ours.
return html`
<overlay id="chat-switcher" open=${!!open} width=${544} hold="ctrl" onRelease=${() => v.ctx.run(v.controller.commitSwitcher())} onDismiss=${v.controller.closeSwitcher} keys=${keys}>
<div ...${column} gap=${2} padding="small">
<div ...${row} gap="small" padding="small" paddingX=${8} paddingY=${2}>
<text style="section" size=${9.84} weight=${700} tone="muted">Recent chats</text>
</div>
${rows.map((id) => switcherRow(v, id, id === open?.selected))}
</div>
</overlay>`;
}
// How far above the prompt box the blur starts, and the backdrop under the
// composer: no blur at its top, 8px at the pane's edge; the fade reaches the
// pane's colour where the controls under the prompt box start.
const FOOTER_LEAD = 16;
const FOOTER_BACKDROP = { blur: [0, 8], fade: [0, 1.35] };
// One chat: the landing page while it is fresh, else its transcript with
// the composer floating over its bottom.
export function renderPane(v: ChatView, chatId: string): Element | null {
const chat = v.controller.state.chats[chatId];
if (!chat) return null;
v.ctx.run(v.controller.ensureChat(chat.id));
v.ctx.run(v.controller.ensureComposer(chat.id));
const t = v.controller.transcript(chat.id);
const submitting = v.controller.state.composers[chat.id]?.submitting;
const landing = !t.items.length && !t.running && !submitting && (t.loaded || !chat.sessionId);
// The landing page draws its own composer.
const composer = () =>
html`<div ...${column} gap="small" padding="small" paddingY="medium">${reading(v, [composerOf(v, chat)])}</div>`;
// The transcript scrolls under the composer. Over its bottom, from a
// little above the prompt box down to the pane's edge, the blur grows
// row by row and the chat fades into the pane, gone before the controls
// under the prompt box.
const footer = () => html`<div ...${column} paddingTop=${FOOTER_LEAD} backdrop=${FOOTER_BACKDROP}>${composer()}</div>`;
const body = landing
? renderLanding(v, chat, composerOf(v, chat))
: html`
<div ...${column} ...${fill} ...${full} padding="small">
${
!t.loaded && !t.items.length && !submitting
? [renderSkeleton(v), composer()]
: renderTranscript(v, chat, footer())
}
</div>`;
// The landing page's stage runs to the pane's edges; the transcript keeps
// the pane's inset.
return html`
<div ...${column} ...${fill} ...${full} id=${`pane-${chat.id}`} padding=${landing ? undefined : "small"} position="relative">
${body}
</div>`;
}
// The chat's composer view, which renders on its own as the user types; a
// pane drawn without one (as the tests draw it) draws the composer itself.
function composerOf(v: ChatView, chat: Chat): Element | null {
const view = v.controller.state.panes[chat.id]?.composer;
return view ? html`<view view=${view.id} fit />` : renderComposer(v, chat);
}
// The composer view of one chat.
export function renderComposerView(v: ChatView, chatId: string): Element | null {
const chat = v.controller.state.chats[chatId];
return chat ? renderComposer(v, chat) : null;
}
// A chat whose rows are on their way: the shapes of a conversation where
// they will be, in the same frame as the click, so the pane is never empty
// and nothing jumps when the rows come.
export function renderSkeleton(v: ChatView): Element {
const line = (width: string) => html`<div width=${width} height=${9} borderRadius="sm" background="muted" />`;
const activity = (width: string) => html`<div width=${width} height=${22} borderRadius="sm" background="muted" />`;
return html`
<div ...${column} ...${fill} ...${full} id="chat-skeleton" paddingY="large">
${reading(v, [
html`<div ...${row} justifyContent="end"><div width="46%" height=${40} borderRadius="xl" background="muted" /></div>`,
html`<div ...${column} gap=${9} paddingY="medium">${["94%", "88%", "63%"].map(line)}</div>`,
html`<div ...${column} gap="small">${["34%", "41%"].map(activity)}</div>`,
html`<div ...${column} gap=${9} paddingY="medium">${["91%", "76%"].map(line)}</div>`,
])}
</div>`;
}
// The skeleton where the pane will be, with the pane's own insets.
const centerSkeleton = (v: ChatView) =>
html`<div ...${column} ...${fill} ...${full} padding="small"><div ...${column} ...${fill} ...${full} padding="small">${renderSkeleton(v)}</div></div>`;
// The shown chat's pane view, made the first time it shows.
export function renderCenter(v: ChatView): Element | null {
const app = v.ctx.app;
v.controller.keepTranscripts(v.ctx.state);
// Kept panes render only when their chat changes, so the panes that
// gain and lose the main prompt box render now.
const mainPrompt = app.route === "chat" ? (app.chatId ?? null) : null;
const was = v.controller.state.mainPrompt;
if (was !== mainPrompt) {
v.controller.state.mainPrompt = mainPrompt;
for (const chatId of [was, mainPrompt]) {
const pane = chatId ? v.controller.state.panes[chatId] : undefined;
(pane?.composer ?? pane?.view)?.update();
}
}
if (app.route !== "chat") {
v.controller.state.preparedChat = null;
return null;
}
if (!app.chatId) return html`<empty>Select a chat or press ⌘N to start one.</empty>`;
if (!v.controller.state.chats[app.chatId]) {
const selected = selectedChat.safeParse(app.shared?.selectedChat);
if (selected.success && selected.data.id === app.chatId) v.controller.state.chats[app.chatId] = selected.data;
}
const chat = v.controller.state.chats[app.chatId];
if (!chat) {
v.ctx.run(v.controller.loadChat(app.chatId));
return centerSkeleton(v);
}
v.ctx.run(v.controller.followApp());
// A pane made by this render has no tree yet, and the kernel would draw
// it empty. The center keeps the pane it showed until the new one's
// first render, which asks for this one again: the switch is one step,
// with nothing between. With no pane before, the skeleton waits.
const { panes } = v.controller.state;
const pane = panes[chat.id];
const shown = pane?.drawn ? pane : v.controller.state.onScreen ? panes[v.controller.state.onScreen] : undefined;
if (!shown) return centerSkeleton(v);
v.controller.state.onScreen = shown.chatId;
return html`<view view=${shown.view.id} />`;
}Versions
| Version | Published | Plugin API | Size | Permissions | Status |
|---|---|---|---|---|---|
| 0.2.5latest | Nov 21, 2026 | >=2 <4 | 174.6 KB | 5 permissions | Listed |
| 0.2.4 | Oct 25, 2026 | >=2 <4 | 174.2 KB | 5 permissions | Listed |
| 0.2.3 | Oct 24, 2026 | >=2 <4 | 165.4 KB | 5 permissions | Listed |
| 0.2.2 | Oct 23, 2026 | >=2 <4 | 165 KB | 5 permissions | Listed |
| 0.2.1 | Oct 6, 2026 | >=2 <3 | 111.8 KB | 5 permissions | Listed |
| 0.2.0 | Oct 5, 2026 | >=2 <3 | 105.1 KB | 5 permissions | Listed |
No comments yet.