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.8

Permissions in 0.2.8

  • 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, and its Close Chat and Reopen Closed Chat for Cmd+W and Cmd+Shift+T on a chat's only tab
  • 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

models.tsx7.6 KB
// Request failures recover at the same notification/logging boundaries as the JavaScript baseline.
// Model picker state and scoped storage effects retain provider-qualified favorites.
import * as Semaphore from "effect/Semaphore";
import * as Effect from "effect/Effect";
import * as z from "zod";
import type { Chat, ConfigOption, Element } from "divergence";
import type { ConfigChoice } from "divergence/protocol";
import type { ChatView, Controller } from "./controller.ts";
import { parse } from "divergence/effect";
import { errorMessage } from "./data.ts";
export type Section = { name: string; favorite?: boolean; choices: ConfigChoice[] };
export type ModelPicker = ReturnType<typeof createModelPicker>;

// Each setting's mark in the menu, by the kind of setting the agent says it is,
// when the agent gives the setting no mark of its own.
const SETTING_ICONS: Record<string, string> = { model: "bot", reasoning: "brain", speed: "zap", mode: "route", approval: "shield" };
// The approval levels every agent publishes (plugins/sdk/agent.ts), each
// with its own mark on the approval row.
const APPROVAL_ICONS: Record<string, string> = {
  supervised: "shield-check",
  auto_edits: "file-pen",
  auto: "shield-half",
  full: "shield-off",
};

// Favorites use the agent's complete model id, including its provider.
export function sections(choices: readonly ConfigChoice[], favorites: readonly string[], query: string): Section[] {
  const terms = query.trim().toLowerCase().split(/\s+/);
  const matches = choices.filter((choice) => {
    const text = `${choice.name} ${choice.value} ${choice.group ?? ""}`.toLowerCase();
    return terms.every((term) => text.includes(term));
  });
  const groups = new Map<string, ConfigChoice[]>();
  const starred = matches.filter((choice) => favorites.includes(choice.value));
  for (const choice of matches) {
    if (favorites.includes(choice.value)) continue;
    const group = choice.group ?? "";
    if (!groups.has(group)) groups.set(group, []);
    groups.get(group)?.push(choice);
  }
  return [
    ...(starred.length ? [{ name: "Favorites", favorite: true, choices: starred }] : []),
    ...[...groups].map(([name, choices]) => ({ name, choices })),
  ];
}

export function createModelPicker(controller: Controller) {
  let favorites: Record<string, string[]> = {};
  let loaded = false;
  const writes = Semaphore.makeUnsafe(1);
  const load = Effect.fn("Chat.loadModelFavorites")(function* () {
    yield* Effect.gen(function* () {
      const stored = (yield* controller.host.call("host/storage.get", { key: "modelFavorites" })).value;
      favorites = yield* parse("model favorites", z.record(z.string(), z.array(z.string())), stored ?? {});
      loaded = true;
      controller.view.update();
    }).pipe(Effect.catch((error) => controller.notify.error(`Could not load model favorites: ${errorMessage(error)}`)));
  });
  // Writes are serialized so an older snapshot never overwrites a newer star action.
  const star = Effect.fn("Chat.starModel")(function* (agentId: string, value: string) {
    const current = favorites[agentId] ?? [];
    favorites = {
      ...favorites,
      [agentId]: current.includes(value) ? current.filter((id) => id !== value) : [...current, value],
    };
    const snapshot = favorites;
    controller.view.update();
    yield* writes.withPermit(
      controller.host
        .call("host/storage.set", { key: "modelFavorites", value: snapshot })
        .pipe(
          Effect.catch((error) => controller.notify.error(`Could not save model favorites: ${errorMessage(error)}`)),
        ),
    );
  });
  // One menu, as the Electron app had it: a row per setting (model, mode,
  // effort, approval, …) with what it is set to, each opening its choices
  // beside it, and a switch row per toggle. The model's choices are
  // searchable, grouped by provider, with the starred ones first. The
  // trigger names the model and, fainter, its reasoning, after the marks
  // of the toggles that are on. The kernel's combobox draws all of it;
  // this only says what is in it.
  // `fit`: in a narrow footer the trigger is the Model row's robot alone (the model's name in the tooltip),
  // and in a very narrow one it also leaves out its chevron.
  const render = (v: ChatView, chat: Chat, model: ConfigOption | undefined, extras: ConfigOption[] = [], fit: "label" | "icon" | "bare" = "label"): Element => {
    const chosen = (o: ConfigOption) => o.choices?.find((choice) => choice.value === o.value)?.name;
    const starred = favorites[chat.agentId] ?? [];
    const modelChoices = (o: ConfigOption) =>
      sections(o.choices ?? [], starred, "").flatMap((section) =>
        section.choices.map((choice) => ({
          value: choice.value,
          label: choice.name,
          svg: choice.icon,
          group: section.name || undefined,
          starred: loaded ? starred.includes(choice.value) : undefined,
        })),
      );
    // The agent's own mark for the setting, else its chosen value's, else
    // one for its kind.
    const mark = (o: ConfigOption) => {
      const svg = o.icon ?? o.choices?.find((choice) => choice.value === o.value)?.icon;
      if (svg) return { svg };
      const icon = o.category === "approval" ? APPROVAL_ICONS[String(o.value)] : undefined;
      return { icon: icon ?? SETTING_ICONS[o === model ? "model" : o.category] ?? "sliders-horizontal" };
    };
    const row = (o: ConfigOption) => {
      const isModel = o === model;
      const count = o.choices?.length ?? 0;
      if (o.kind === "toggle") return { value: o.id, ...mark(o), label: o.name, switch: o.value === true };
      return {
        value: o.id,
        ...mark(o),
        label: isModel ? "Model" : o.name,
        detail: chosen(o) ?? "Default",
        submenu: {
          value: String(o.value ?? ""),
          width: isModel ? 288 : 256,
          search: isModel && count > 8 ? "Search models…" : undefined,
          empty: isModel ? "No models found" : undefined,
          options: isModel
            ? modelChoices(o)
            : // Names only, as for models: a level's description took room.
              (o.choices ?? []).map((choice) => ({ value: choice.value, label: choice.name, svg: choice.icon })),
        },
      };
    };
    const rows = [...(model ? [model] : []), ...extras];
    const lead = model ?? extras[0];
    // The trigger names the model and how hard it thinks: the option the
    // agent puts in the reasoning category. Speed and the rest stay in the
    // menu.
    const thinking = extras.find((o) => o !== lead && o.category === "reasoning" && o.kind !== "toggle");
    const summary = thinking ? chosen(thinking) : undefined;
    const name = lead ? (chosen(lead) ?? lead.name) : "Settings";
    const iconOnly = fit !== "label";
    const on = extras.flatMap((o) => (o.kind === "toggle" && o.value === true && o.icon ? [{ svg: o.icon }] : []));
    return (
      <combobox id={`models-${chat.id}-${chat.agentId}`} look="toolbar" tooltip={iconOnly ? [name, summary].filter(Boolean).join(" · ") : "Model and reply settings"} label={iconOnly ? "" : name} detail={iconOnly ? undefined : summary || undefined} marks={iconOnly ? [{ icon: SETTING_ICONS.model }] : on.length ? on : undefined} chevron={fit === "bare" ? false : undefined} options={rows.map(row)} onChange={(e: { value?: string | boolean; option?: string }) => {
            if (!e.option || e.value === undefined) return;
            v.ctx.run(controller.setOption(chat.id, e.option, e.value));
            v.ctx.run(controller.views.focus(`prompt-${chat.id}`));
          }} onStar={(e: { value: string }) => v.ctx.run(star(chat.agentId, e.value))} />
    );
  };
  return { load: load(), render };
}

Versions

VersionPublishedPlugin APISizePermissionsStatus
0.2.9latestNov 21, 2026>=5 <6349 KB5 permissionsListed
0.2.8Nov 16, 2026>=5 <6348.6 KB5 permissionsListed
0.2.7Nov 11, 2026>=5 <6314.3 KB5 permissionsListed
0.2.6Nov 9, 2026>=5 <6306.2 KB5 permissionsListed
0.2.5Oct 27, 2026>=2 <4178.6 KB5 permissionsListed

Reviews and comments

0 threads · 0 reviews

No comments yet.