Official
sidebar
Built-in sidebar 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/sidebar@0.2.5
Permissions in 0.2.5
Files
main.ts3.9 KB
// Register the sidebar synchronously, its commands, and the event
// subscriptions that keep its state current; the initial refresh runs in
// the plugin scope.
import * as Effect from "effect/Effect";
import * as Scope from "effect/Scope";
import * as Stream from "effect/Stream";
import { App, Commands, Events, Views, runPlugin } from "divergence/effect";
import { Sidebar } from "./controller.ts";
import { renderSidebar } from "./views.tsx";
const program = Effect.gen(function* () {
const sidebar = yield* Sidebar;
const views = yield* Views;
// Views register synchronously at the start of the program so reload
// keeps the view's identity (same slot, same order).
sidebar.views.push(
yield* views.add("left", { slot: "left", render: (ctx) => renderSidebar(ctx, sidebar), on: ["workspaces_changed", "chat_changed", "chat_removed", "agents_changed", "app_state"] }),
);
const commands = yield* Commands;
const app = yield* App;
yield* commands.register("sidebar.newChat", sidebar.newChatCommand());
yield* commands.register("sidebar.toggleChatCompleted", sidebar.toggleCompletedCommand());
yield* commands.register("sidebar.closeChat", sidebar.closeChatCommand());
yield* commands.register("sidebar.addWorkspace", sidebar.addWorkspace());
// The workspace picker at the sidebar's top, which Settings replaces.
yield* commands.register(
"sidebar.chooseWorkspaces",
Effect.gen(function* () {
const { route } = yield* app.state;
if (route && route !== "chat") yield* sidebar.route("chat");
yield* views.focus("workspace-filter");
}),
);
yield* commands.register("sidebar.togglePin", sidebar.onScreenRow((chat) => sidebar.togglePin(chat)));
yield* commands.register("sidebar.archiveRow", sidebar.onScreenRow((chat, task) => (task ? sidebar.archiveTask(task.id) : sidebar.archive(chat))));
yield* commands.register("sidebar.openRowMenu", sidebar.onScreenRow((chat) => sidebar.openRowMenu(chat.id, false)));
for (let n = 1; n <= 9; n++) yield* commands.register(`sidebar.openChat${n}`, sidebar.selectListedCommand(n - 1));
sidebar.declareChatActions();
const events = yield* Events;
// Event followers are fire-and-forget like the original's async handlers:
// a failed refresh is logged and leaves the state for the next event, and
// the rest of the plugin keeps working.
const follow = <A, E>(
stream: Stream.Stream<A, E>,
handle: (event: A) => Effect.Effect<void, unknown>,
): Effect.Effect<void, never, Scope.Scope> =>
stream.pipe(
Stream.mapEffect(
(event) =>
handle(event).pipe(Effect.ignore({ log: "Warn", message: "The sidebar could not follow a host event" })),
{ concurrency: "unbounded" },
),
Stream.runDrain,
Effect.forkScoped,
);
yield* follow(events.stream("workspaces_changed"), () => sidebar.refresh());
yield* follow(events.stream("agents_changed"), () => sidebar.refresh());
// A row brought back from the archive takes its place once the host reports it whole.
yield* follow(events.stream("chat_changed"), (event) => sidebar.chatChanged(event).pipe(Effect.andThen(sidebar.land())));
yield* follow(events.stream("chat_removed"), (event) => sidebar.chatRemoved(event));
yield* follow(events.stream("task_changed"), (event) => sidebar.taskChanged(event).pipe(Effect.andThen(sidebar.land())));
yield* follow(events.stream("task_removed"), (event) => sidebar.taskRemoved(event));
yield* follow(events.stream("transcript_reset"), (event) => sidebar.transcriptReset(event));
yield* follow(events.stream("agent"), (event) => sidebar.agentEvent(event));
// The first load runs in the program fiber, like the original's refresh()
// at the end of activate: its list calls leave before activate returns.
// A failed load says so in place of the list, and the next event retries.
yield* sidebar.refresh().pipe(Effect.catch(sidebar.loadFailed));
});
export default runPlugin(Sidebar.layer, program);
No comments yet.