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 divergence/chat@0.2.5
Permissions in 0.2.5
Files
views/pending.ts9 KB
// The list of held inputs over the prompt box and a semantic usage-limit
// notice. Native admission/unknown delivery remains visible without
// fictitious edit/withdraw.
import * as Effect from "effect/Effect";
import { html } from "divergence";
import type { Chat, ContentBlock, Element, PendingInput } from "divergence";
import type { ChatView } from "../controller.ts";
import { autoSend, editable, inputLabel, pending, policyOf } from "../scheduler-policy.ts";
import { editableComposition, steeringReason } from "../composition.ts";
import { clickable, column, fill, revealOnHover, row, RAISED } from "./styles.ts";
import { resetsIn } from "./usage.ts";
const descriptions = (blocks: readonly ContentBlock[]) => blocks.filter((block) => block.type !== "text").map((block) => {
switch (block.type) {
case "image": return `Image · ${block.mimeType}`;
case "audio": return `Audio · ${block.mimeType}`;
case "file_ref": case "resource": return block.path;
case "skill": return `$${block.name}${block.input ? ` ${block.input}` : ""}`;
}
});
export function renderPending(v: ChatView, chat: Chat): Element[] {
const scheduler = v.controller.scheduler, snapshot = scheduler.snapshots[chat.id], composer = v.controller.composer(chat.id);
const act = <A, E>(effect: Effect.Effect<A, E>) => v.ctx.run(effect.pipe(Effect.catch((error) => scheduler.report(chat.id, error))));
const reason = steeringReason(v.controller, chat);
// Input the transcript shows needs no card: a send joins it when it is
// handed over, a steer when the agent picks it up.
const shown = new Set(v.controller.state.transcripts[chat.id]?.items.map((item) => item.id));
const handed = (input: PendingInput) =>
(input.id === composer.outgoing?.id && composer.outgoing.preview && !input.error) ||
(shown.has(input.id) && !editable(input) && !input.error);
// One line per input: what it says, cut to the width, and what makes it
// more than a prompt waiting its turn. Its actions follow on the right,
// the one that sends it now always visible.
const line = (icon: string, text: string, status: string, actions: (Element | null)[] = []) => html`
<div ...${row} gap="small" minHeight=${28} paddingLeft="small" ...${clickable}>
<icon name=${icon} small tone="muted" />
<div ...${fill}><text style="body" size="xs" truncate text=${text} /></div>
${status ? html`<text style="body" size="xs" tone="muted" text=${status} />` : null}
${actions}
</div>`;
// A steer the agent was handed waits here until it picks it up; while
// the run goes on that wait is the normal case and needs no words.
const status = (input: PendingInput) =>
input.intent === "steer" && snapshot?.running && !input.error && ["dispatching", "native_admitted", "delivery_unknown"].includes(input.state)
? ""
: inputLabel(input);
const extras = (texts: string[]) =>
texts.length ? html`<div ...${row} gap="small" paddingLeft=${28} flexWrap="wrap">${texts.map((text) => html`<text style="body" size="xs" tone="muted" text=${text} />`)}</div>` : null;
const rows = snapshot ? pending(snapshot).filter((input) => !handed(input)).map((input): [boolean, Element] => [input.intent === "steer", (() => {
const canEdit = editable(input), edit = canEdit && composer.pendingEdit?.id === input.id ? composer.pendingEdit : undefined;
const save = Effect.fn("Chat.savePendingEdit")(function* () {
if (!edit) return;
yield* scheduler.edit(input, edit.revision, edit.text);
composer.pendingEdit = undefined;
v.ctx.update();
});
const icon = input.intent === "steer" ? "corner-down-left" : "list-plus";
const actions = canEdit ? [
html`
<div ...${row} ...${revealOnHover}>
<button id=${`edit-input-${input.id}`} icon="pencil" small variant="ghost" tooltip="Edit" onClick=${() => { composer.pendingEdit = { id: input.id, revision: snapshot.revision, text: editableComposition(input).text }; v.ctx.update(); }} />
<button id=${`remove-input-${input.id}`} icon="x" small variant="ghost" tooltip="Remove" onClick=${() => act(scheduler.change({ chatId: chat.id, inputId: input.id, revision: snapshot.revision, remove: true }))} />
</div>`,
input.intent === "steer" ? html`<button id=${`demote-${input.id}`} icon="list-plus" small variant="ghost" tooltip="Move back to the queue" onClick=${() => act(scheduler.change({ chatId: chat.id, inputId: input.id, revision: snapshot.revision, intent: "queue" }))} />` : null,
html`<button id=${`promote-${input.id}`} icon="arrow-right" small variant="ghost" disabled=${!!reason} tooltip=${reason ?? (v.controller.isRunning(chat) ? "Steer now; your draft stays" : "Send now; your draft stays")} onClick=${() => act(scheduler.promote(chat.id, input.id, snapshot.revision))} />`,
] : [];
if (edit) return html`
<div ...${column} gap="small" paddingY="small">
<input id=${`edit-pending-${input.id}`} multiline value=${edit.text} onChange=${(event: { value: string }) => { edit.text = event.value; }} />
<div ...${row} gap="small">
<button id=${`save-pending-${input.id}`} label="Save" small onClick=${() => act(save())} />
<button id=${`cancel-pending-${input.id}`} label="Cancel edit" small variant="ghost" onClick=${() => { composer.pendingEdit = undefined; v.ctx.update(); }} />
</div>
</div>`;
return html`<div ...${column}>${line(icon, v.controller.plainText(input.blocks), status(input), actions)}${extras(descriptions(input.blocks))}</div>`;
})()]) : [];
const outgoing = composer.outgoing;
// Local intent is visible before persistence, but only host evidence grants
// edit/remove authority. Clearing the submission identity acknowledges even
// a steer merged into another input; an exact-id event can take over sooner.
if (outgoing?.intent && composer.submission && !shown.has(outgoing.id) && !snapshot?.inputs.some((input) => input.id === outgoing.id) && !composer.queue.some((input) => input.id === outgoing.id)) {
rows.push([outgoing.intent === "steer", html`
<div ...${column}>
${line(outgoing.intent === "steer" ? "corner-down-left" : "list-plus", outgoing.text, "Saving")}
${extras([...descriptions(outgoing.blocks ?? []), ...outgoing.attachments.map((image) => `Image · ${image.mimeType}`)])}
</div>`]);
}
// Steers first, the agent reads them before anything queued.
const groups = (["Steer", "Queued"] as const)
.map((title) => [title, rows.filter(([steer]) => steer === (title === "Steer")).map(([, element]) => element)] as const)
.filter(([, elements]) => elements.length);
if (!groups.length) return [];
// The list sits on the prompt box's top edge, inset from its sides.
return [html`
<div ...${column} marginX="medium" padding="small" paddingX="medium" background="muted" borderTopLeftRadius="xl" borderTopRightRadius="xl" ...${RAISED}>
${groups.flatMap(([title, elements]) => [
html`<div ...${row} minHeight=${24} paddingLeft="small"><text style="body" size="xs" weight=${500} tone="muted" text=${title} /></div>`,
...elements,
])}
</div>`];
}
export function renderLimit(v: ChatView, chat: Chat): Element | null {
const scheduler = v.controller.scheduler, snapshot = scheduler.snapshots[chat.id];
const state = snapshot ? policyOf(snapshot) : undefined, wait = state?.wait;
const active = scheduler.activeLimits[chat.id];
const grace = !!active && (snapshot?.running || v.controller.isRunning(chat)) && (!active.runId || active.runId === snapshot?.runId);
if (!wait && !grace) return null;
const enabled = autoSend(scheduler.preferences, chat.agentId);
const reset = wait?.resetAt ?? (grace ? active?.evidence.resetsAt : undefined);
const countdown = resetsIn(reset);
const resetText = countdown && reset ? `Reset ${countdown === "now" ? "reported for now" : `in ${countdown}`} · ${new Date(reset).toLocaleString()}` : "Reset time unavailable";
const status = grace ? "Usage limit reported · still working / retrying" : scheduler.checking.has(chat.id) ? "Checking availability…" :
state?.pause || wait?.status === "paused" ? "Automatic send paused" : !enabled ? "Auto-send disabled for this agent" : wait?.status === "attempting" ? wait.reason : wait?.status === "failed" ? "Recovery check failed" : "Waiting for usage-limit recovery";
return html`
<div ...${column} gap="small" padding="medium" background="warning/10" borderRadius="md" border=${{ width: 1, color: "warning/30" }}>
<div ...${row} gap="small"><icon name="clock" small tone="warning" /><text style="body" size="xs" tone="warning">${status}</text></div>
<text style="body" size="xs" tone="muted">${resetText}</text>
<text style="body" size="xs" tone="muted">${state?.pause ?? wait?.reason ?? active?.evidence.reason}</text>
<checkbox id=${`auto-limit-${chat.id}`} label="Auto-send pending input after recovery · all chats for this agent" checked=${enabled}
onChange=${(event: { value: boolean }) => v.ctx.run(scheduler.setAutoSend(chat.agentId, event.value))} />
</div>`;
}Versions
| Version | Published | Plugin API | Size | Permissions | Status |
|---|---|---|---|---|---|
| 0.2.9latest | Nov 21, 2026 | >=5 <6 | 349 KB | 5 permissions | Listed |
| 0.2.8 | Nov 16, 2026 | >=5 <6 | 348.6 KB | 5 permissions | Listed |
| 0.2.7 | Nov 11, 2026 | >=5 <6 | 314.3 KB | 5 permissions | Listed |
| 0.2.6 | Nov 9, 2026 | >=5 <6 | 306.2 KB | 5 permissions | Listed |
| 0.2.5 | Oct 27, 2026 | >=2 <4 | 178.6 KB | 5 permissions | Listed |
No comments yet.