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
requests.ts6 KB
// Request failures recover at the same notification/logging boundaries as the JavaScript baseline.
// Native approvals remain kernel-owned; chat questions and checkpoint actions use host services.
// Cached attachment ids prevent image bytes from travelling through streaming renders.
import * as Effect from "effect/Effect";
import type { Controller } from "./controller.ts";
import type { Question } from "./state.ts";
import { errorMessage, textChanged } from "./data.ts";
import { allTasks } from "./subagents.ts";
import { changed } from "./transcript.ts";
export const respondQuestion = Effect.fn("Chat.respondQuestion")(function* (
c: Controller,
chatId: string,
req: Question,
cancelled: boolean,
) {
const transcript = c.transcript(chatId),
answers = (transcript.answers[req.id] ??= {});
if (req.submitting) return;
req.submitting = true;
c.view.update();
const values = cancelled
? {}
: Object.fromEntries(Object.entries(answers).filter(([, value]) => value !== "" && value != null));
yield* c.host.call("host/chats.respond_question", { chatId, questionId: req.id, answer: { values, cancelled } }).pipe(
Effect.tap(() => {
transcript.questions = transcript.questions.filter((question) => question.id !== req.id);
return c.answers.prune(chatId);
}),
Effect.catch((error) => c.notify.error(`Answer failed: ${errorMessage(error)}`)),
Effect.ensuring(
Effect.sync(() => {
req.submitting = false;
c.view.update();
}),
),
);
});
export const openQuestionLink = Effect.fn("Chat.openQuestionLink")(function* (
c: Controller,
chatId: string,
req: Question,
) {
if (req.url) yield* Effect.forkIn(c.kernel.call("open_url", { url: req.url }), c.scope, { startImmediately: true });
yield* respondQuestion(c, chatId, req, false);
});
export const submitEdit = Effect.fn("Chat.submitEdit")(function* (c: Controller, chatId: string, itemId: string) {
const transcript = c.transcript(chatId),
text = transcript.editText.trim();
if (!text) return;
transcript.editing = null;
// The edited text shows at once, and the chat is busy until the host
// rewound the agent and sent it; a failed edit puts the old text back.
const item = transcript.items.find((item) => item.id === itemId);
const before = item?.role === "user" ? item.blocks : null;
if (item?.role === "user") {
item.blocks = [{ type: "text", text }, ...item.blocks.filter((block) => block.type !== "text")];
changed(item);
}
transcript.resending = itemId;
transcript.version++;
c.view.update();
yield* c.host.call("host/chats.edit_message", { chatId, itemId, text }).pipe(
Effect.catch((error) =>
Effect.gen(function* () {
if (item?.role === "user" && before) {
item.blocks = before;
changed(item);
}
yield* c.notify.error(`Edit failed: ${errorMessage(error)}`);
}),
),
Effect.ensuring(
Effect.sync(() => {
delete transcript.resending;
transcript.version++;
c.view.update();
}),
),
);
});
export const revert = Effect.fn("Chat.revert")(function* (c: Controller, chatId: string, itemId: string) {
const item = c.transcript(chatId).items.find((item) => item.id === itemId);
const text = item?.role === "user" ? c.plainText(item.blocks) : "";
yield* Effect.gen(function* () {
const coverage = yield* c.host.call("host/chats.checkpoint_coverage", { chatId, itemId });
yield* c.host.call("host/chats.restore_checkpoint", { chatId, itemId });
// Said once the files are back, so a failed restore never reads as done.
if (coverage.unknownPaths.length) {
const names = coverage.unknownPaths.slice(0, 5).join(", "),
more = coverage.unknownPaths.length > 5 ? ` and ${coverage.unknownPaths.length - 5} more` : "";
yield* c.notify.warning(`Files restored, except these, which are left as they are: ${names}${more}`);
} else yield* c.notify.info("Files restored to before this message");
const composer = c.composer(chatId);
if (!composer.text.trim()) composer.text = text;
yield* textChanged(c, chatId);
c.view.update();
}).pipe(Effect.catch((error) => c.notify.error(`Restore failed: ${errorMessage(error)}`)));
});
export const stopTask = Effect.fn("Chat.stopTask")(function* (c: Controller, chat: { id: string }, taskId: string) {
yield* c.host
.call("host/chats.cancel_task", { chatId: chat.id, taskId })
.pipe(Effect.catch((error) => c.notify.error(`Could not stop the subagent: ${errorMessage(error)}`)));
});
export const loadImages = Effect.fn("Chat.loadImages")(function* (c: Controller, chatId: string) {
const transcript = c.transcript(chatId);
const lists = [transcript.items, ...allTasks(transcript.items).map((row) => row.item.items ?? [])];
for (const items of lists)
for (const item of items) {
if (item.role !== "user" || c.state.itemImages[item.id]) continue;
// A stored image (a `path`) is drawn from its file; only an inline one
// (from an older host) is handed to the kernel.
const blocks = item.blocks.flatMap((block) =>
block.type === "image" && block.data && !(block.path && block.width && block.height)
? [{ ...block, data: block.data }] : [],
);
if (!blocks.length) continue;
c.state.itemImages[item.id] = "pending";
yield* Effect.forkIn(
Effect.all(
blocks.map((block) =>
c.kernel.call("attach_image", {
data: block.data,
name: `Image.${(block.mimeType ?? "image/png").split("/")[1]}`,
}),
),
{ concurrency: "unbounded" },
).pipe(
Effect.tap((images) =>
Effect.sync(() => {
c.state.itemImages[item.id] = images.map((image) => image.id);
c.view.update();
}),
),
Effect.catch((error) => {
c.state.itemImages[item.id] = [];
return c.notify.warning(`Could not show an attached image: ${errorMessage(error)}`);
}),
),
c.scope,
{ startImmediately: true },
);
}
});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.