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.7
Permissions in 0.2.7
Files
app-commands.ts5.5 KB
// Slash commands the app answers itself, for every agent: `/model`,
// `/effort`, `/mode` and `/speed` open the chat's settings menu at that
// setting, and `/rename` turns the title into a field. They work from
// anywhere in the prompt, and run in place of an agent's command of the
// same name, which would change the agent's session behind the menu's
// back. With a value (`/model sonnet`, `/rename Fix login`) they set it
// at once.
import * as Effect from "effect/Effect";
import type { ConfigOption } from "divergence";
import { Slash } from "divergence/effect";
import type { Controller } from "./controller.ts";
import type { Composer } from "./state.ts";
import { errorMessage } from "./data.ts";
type Setting = { name: string; category: string; description: string; icon: string; what: string };
/// The settings menu's rows a command opens, by the option's category.
const SETTINGS: readonly Setting[] = [
{ name: "model", category: "model", description: "Choose the model", icon: "cpu", what: "model" },
{ name: "effort", category: "reasoning", description: "Choose how hard the model thinks", icon: "brain", what: "effort" },
{ name: "mode", category: "mode", description: "Choose the agent's mode", icon: "layers", what: "mode" },
{ name: "speed", category: "speed", description: "Choose how fast the agent answers", icon: "zap", what: "speed" },
];
const RENAME = { name: "rename", description: "Rename this chat", icon: "pencil", inputHint: "[title]" };
export const APP_COMMANDS: ReadonlySet<string> = new Set([...SETTINGS.map((setting) => setting.name), RENAME.name]);
export type AppCommand = { name: string; description: string; icon: string };
/// The app's commands this chat can use now: a setting's only while the
/// agent offers that setting.
export function appCommands(c: Controller, composer: Composer): AppCommand[] {
const options = c.visibleOptions(composer);
return [...SETTINGS.filter((setting) => options.some((option) => option.category === setting.category)), RENAME];
}
/// The choice `input` names: its value, else the first name that starts
/// with it, else the first that holds it (case-insensitive).
function choiceNamed(option: ConfigOption, input: string) {
const wanted = input.toLowerCase();
const choices = option.choices ?? [];
return (
choices.find((choice) => choice.value.toLowerCase() === wanted || choice.name.toLowerCase() === wanted) ??
choices.find((choice) => choice.name.toLowerCase().startsWith(wanted)) ??
choices.find((choice) => choice.name.toLowerCase().includes(wanted) || choice.value.toLowerCase().includes(wanted))
);
}
/// Runs the app's command `name` in a chat: with no input it opens the
/// setting's menu or the title field, with one it sets it.
export const runAppCommand = Effect.fn("Chat.runAppCommand")(function* (
c: Controller,
chatId: string,
name: string,
input = "",
) {
const chat = c.state.chats[chatId];
if (!chat) return;
if (name === RENAME.name) return yield* input ? rename(c, chatId, input) : startRename(c, chatId);
const setting = SETTINGS.find((known) => known.name === name);
if (!setting) return;
const composer = c.composer(chatId);
const option = c.visibleOptions(composer).find((known) => known.category === setting.category);
if (!option) {
const agent = c.state.agents[chat.agentId]?.name ?? "This agent";
return yield* c.notify.warning(`${agent} has no ${setting.what} setting`);
}
if (input) {
const choice = choiceNamed(option, input);
if (choice) return yield* c.setOption(chatId, option.id, choice.value);
yield* c.notify.warning(`No ${setting.what} matches “${input}”`);
}
yield* c.views.focus(`models-${chatId}-${chat.agentId}`, option.id);
});
/// Turns the title in the title strip into a field holding the title.
export const startRename = Effect.fn("Chat.startRename")(function* (c: Controller, chatId: string) {
const chat = c.state.chats[chatId];
if (!chat) return;
c.state.renaming = { chatId, text: c.titleOf(chat) };
c.presentations?.updateTitle(chatId);
yield* c.views.focus(`title-rename-${chatId}`);
});
/// Saves a chat's title, "New Chat" when it is blank, and closes the field.
export const rename = Effect.fn("Chat.rename")(function* (c: Controller, chatId: string, title: string) {
if (c.state.renaming?.chatId === chatId) c.state.renaming = null;
c.presentations?.updateTitle(chatId);
yield* c.views.focus(`prompt-${chatId}`);
yield* c.host
.call("host/chats.update", { chatId, title: title.trim() || "New Chat" })
.pipe(Effect.catch((error) => c.notify.error(`Rename failed: ${errorMessage(error)}`)));
});
/// Closes the title field without saving.
export const cancelRename = Effect.fn("Chat.cancelRename")(function* (c: Controller) {
const chatId = c.state.renaming?.chatId;
c.state.renaming = null;
if (chatId) c.presentations?.updateTitle(chatId);
if (chatId) yield* c.views.focus(`prompt-${chatId}`);
});
/// Registers the commands with the host, so a sent `/model sonnet` runs
/// here instead of reaching the agent.
export const registerAppCommands = Effect.fn("Chat.registerAppCommands")(function* (c: Controller) {
const slash = yield* Slash;
for (const command of [...SETTINGS.map((setting) => ({ ...setting, inputHint: "[name]" })), RENAME])
yield* slash.register({
name: command.name,
description: command.description,
inputHint: command.inputHint,
run: Effect.fn("Chat.appCommand")(function* (input, context) {
if (context.chatId) yield* runAppCommand(c, context.chatId, command.name, input.trim());
return { action: "none" as const };
}),
});
});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.