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

  • 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
  • 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

panes.ts8.1 KB
// Each chat has one pane view, kept while it is one of the last few
// shown so switching back is instant. Detail views (a subagent, a
// workflow) open in tabs through the convergence/tabs service.
import * as Scope from "effect/Scope";
import * as Effect from "effect/Effect";
import type { Chat, Element, ViewHandle } from "convergence";
import type { Controller, ChatError, ChatView } from "./controller.ts";
import { renderComposerView, renderPane } from "./views/panes.ts";
import { renderSubagentPane, renderWorkflowPane } from "./views/tasks.ts";
import { findTask, nameOf } from "./subagents.ts";
import { unknownMethod } from "./scheduler.ts";
import { errorMessage, loadOptions, loadTranscript, loadRequests, noteRecent, refreshHistory } from "./data.ts";

/** Chats whose panes stay mounted (the one shown and the last before it). */
const RETAINED = 3;

export const ensureComposer = Effect.fn("Chat.ensureComposer")(function* (c: Controller, chatId: string) {
  if (!c.state.composers[chatId]) {
    c.composer(chatId);
    if (c.state.restored) delete c.state.restored[chatId];
    yield* Effect.forkIn(
      c.drafts.load(chatId).pipe(Effect.catch((error) => c.notify.error(`Draft unavailable: ${error.message}`))),
      c.scope,
      { startImmediately: true },
    );
    yield* Effect.forkIn(loadOptions(c, chatId), c.scope, { startImmediately: true });
  }
});
export const ensureChat = Effect.fn("Chat.ensureChat")(function* (c: Controller, chatId: string) {
  const kept = c.state.transcripts[chatId];
  if (!kept || kept.carried) {
    if (kept) kept.carried = false;
    else c.transcript(chatId);
    yield* Effect.forkIn(loadRequests(c, chatId), c.scope, { startImmediately: true });
  }
  const transcript = c.transcript(chatId);
  if (!transcript.loaded && !transcript.loading)
    yield* Effect.forkIn(loadTranscript(c, chatId), c.scope, { startImmediately: true });
});
// The chat's pane view, made the first time it shows; the oldest beyond
// the retained few goes.
export const ensurePane = Effect.fn("Chat.ensurePane")(function* (c: Controller, chatId: string) {
  const pane = c.state.panes[chatId];
  if (!pane) {
    const view = yield* c.views
      .slot(
        "pane",
        (ctx) => {
          const tree = renderPane({ controller: c, ctx }, chatId);
          // Until now the center showed a skeleton: a view with no tree yet
          // draws nothing, and the center waited a render for it.
          const drawn = c.state.panes[chatId];
          if (drawn && !drawn.drawn) {
            drawn.drawn = true;
            c.center?.update();
          }
          return tree;
        },
        // Not `chat_changed`: it re-rendered every kept pane for any chat's
        // change, before the listener updated the chat. `onChatChanged`
        // renders the pane on screen, after.
        { key: `chat:${chatId}`, on: ["agents_changed"] },
      )
      .pipe(Effect.provideService(Scope.Scope, c.scope));
    const composer = yield* c.views
      .slot("composer", (ctx) => renderComposerView({ controller: c, ctx }, chatId), {
        key: `composer:${chatId}`,
        on: ["agents_changed"],
      })
      .pipe(Effect.provideService(Scope.Scope, c.scope));
    c.state.panes[chatId] = { chatId, view, composer };
  } else if (pane.stale) {
    pane.stale = false;
    pane.view.update();
    pane.composer?.update();
  }
  c.state.recentPanes = [chatId, ...c.state.recentPanes.filter((id) => id !== chatId)];
  for (const old of c.state.recentPanes.splice(RETAINED)) removePane(c, old);
});
// A chat whose pane goes keeps no transcript here; the host keeps less of
// it too. It is read again, newest page first, when it shows.
export function removePane(c: Controller, chatId: string) {
  c.state.panes[chatId]?.view.remove();
  c.state.panes[chatId]?.composer?.remove();
  delete c.state.panes[chatId];
  c.state.recentPanes = c.state.recentPanes.filter((id) => id !== chatId);
  if (c.api.app.state().chatId === chatId) return;
  const transcript = c.state.transcripts[chatId];
  if (transcript && !transcript.loading) {
    for (const item of transcript.items) delete c.state.itemImages[item.id];
    delete c.state.transcripts[chatId];
  }
  // An older host has no `chats.close`: it keeps everything, as before.
  Effect.runFork(c.host.call("host/chats.close", { chatId }).pipe(Effect.catch(() => Effect.void)));
}
// A host without the method is an older one: nothing to prepare. A failed
// preparation arrives as `prepareError` and is toasted; any other failure is toasted here.
const prepareChat = (c: Controller, chatId: string) =>
  c.host
    .call("host/chats.prepare", { chatId })
    .pipe(
      Effect.catch((error) =>
        unknownMethod(error) ? Effect.void : c.notify.error(`Preparing the conversation failed: ${errorMessage(error)}`),
      ),
    );
export const followApp = Effect.fn("Chat.followApp")(function* (c: Controller): Effect.fn.Return<void, ChatError> {
  const app = c.api.app.state();
  if (app.route !== "chat" || !app.chatId) return;
  const chat = c.state.chats[app.chatId];
  if (!chat) return;
  yield* ensurePane(c, chat.id);
  yield* Effect.forkIn(noteRecent(c, chat.id), c.scope, { startImmediately: true });
  // Once per show: the host resumes the chat's session now, so its first Send finds it ready.
  if (chat.id !== c.state.preparedChat) {
    c.state.preparedChat = chat.id;
    yield* Effect.forkIn(prepareChat(c, chat.id), c.scope, { startImmediately: true });
  }
  if (chat.id !== c.state.promptedChat && !c.state.switcher) {
    c.state.promptedChat = chat.id;
    yield* c.views.focus(`prompt-${chat.id}`);
  }
  if (chat.id !== c.state.historyChat) {
    c.state.historyChat = chat.id;
    yield* Effect.forkIn(refreshHistory(c, chat.id), c.scope, { startImmediately: true });
  }
});
const paneView = Effect.fn("Chat.paneView")(function* (
  c: Controller,
  key: string,
  chatId: string,
  render: (v: ChatView) => Element | null,
) {
  let entry = c.state.paneViews[key];
  if (!entry) {
    const view = yield* c.views
      .slot("subagent", (ctx) => render({ controller: c, ctx }), { key, on: ["chat_changed", "agents_changed"] })
      .pipe(Effect.provideService(Scope.Scope, c.scope));
    entry = c.state.paneViews[key] = { chatId, view };
  }
  return entry.view;
});
const showInPane = Effect.fn("Chat.showInPane")(function* (
  c: Controller,
  chat: Chat,
  key: string,
  title: string,
  icon: string,
  pane: ViewHandle,
) {
  const client = c.tabs;
  // Without the tabs plugin there is no detail pane; the shared request the
  // baseline wrote would have had no reader either.
  if (!client) return;
  yield* client.open({ kind: "view", workspaceId: chat.workspaceId, path: key, title, icon, view: pane.id }).pipe(
    // A call that loses its provider on the way behaves like no reader.
    Effect.ignore,
  );
});
export const openWorkflow = Effect.fn("Chat.openWorkflow")(function* (c: Controller, chat: Chat, taskId: string) {
  const key = `workflow/${chat.id}/${taskId}`,
    pane = yield* paneView(c, key, chat.id, (v) => renderWorkflowPane(v, chat.id, taskId));
  const item = findTask(c.transcript(chat.id).items, taskId);
  yield* showInPane(
    c,
    chat,
    key,
    item ? item.task.name || item.task.title || "Workflow" : "Workflow",
    "workflow",
    pane,
  );
});
export const openSubagent = Effect.fn("Chat.openSubagent")(function* (
  c: Controller,
  chat: Chat,
  taskId: string,
): Effect.fn.Return<void, ChatError> {
  if (findTask(c.transcript(chat.id).items, taskId)?.task.workflow) return yield* openWorkflow(c, chat, taskId);
  const key = `subagent/${chat.id}/${taskId}`,
    pane = yield* paneView(c, key, chat.id, (v) => renderSubagentPane(v, chat.id, taskId));
  const item = findTask(c.transcript(chat.id).items, taskId);
  // A reconcile leaves a settled subagent's transcript unread; the tab reads it.
  if (item && !item.items?.length)
    yield* Effect.forkIn(
      c.host
        .call("host/chats.load_task", { chatId: chat.id, taskId })
        .pipe(Effect.catch((error) => Effect.logWarning(`subagent history unavailable: ${errorMessage(error)}`))),
      c.scope,
      { startImmediately: true },
    );
  yield* showInPane(c, chat, key, item ? item.task.title || nameOf(item.task) : "Subagent", "bot", pane);
});

Versions

VersionPublishedPlugin APISizePermissionsStatus
0.2.5latestNov 21, 2026>=2 <4174.6 KB5 permissionsListed
0.2.4Oct 25, 2026>=2 <4174.2 KB5 permissionsListed
0.2.3Oct 24, 2026>=2 <4165.4 KB5 permissionsListed
0.2.2Oct 23, 2026>=2 <4165 KB5 permissionsListed
0.2.1Oct 6, 2026>=2 <3111.8 KB5 permissionsListed
0.2.0Oct 5, 2026>=2 <3105.1 KB5 permissionsListed

Reviews and comments

0 threads · 0 reviews

No comments yet.