Official
palette
Built-in command palette (⌘⇧P) and chat search (⌘P).
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/palette@0.2.3
Permissions in 0.2.3
Files
chats.ts1.8 KB
// The chat search's chats: read when the plugin starts and again when the
// workspaces change (an import adds chats that way, and a removed workspace
// takes its chats away), and kept current by
// the chat events in between, so the search opens at once and lists what
// the host has now.
import * as Effect from "effect/Effect";
import type { Chat } from "divergence";
import { Host } from "divergence/effect";
import { PaletteState } from "./state.ts";
export const chats = Effect.fn("Palette.chats")(function* () {
const state = yield* PaletteState;
const host = yield* Host;
const update = () => {
if (state.open) state.view?.update();
};
// A chat whose event came while the read was on its way keeps the
// event's copy unless the read's is newer.
const load = Effect.fn("Palette.loadChats")(function* () {
const [chats, workspaces] = yield* Effect.all(
[host.call("host/chats.list", {}), host.call("host/workspaces.list", {})],
{ concurrency: "unbounded" },
);
for (const chat of chats.chats) {
const known = state.chats.get(chat.id);
if (!known || known.updatedAt < chat.updatedAt) state.chats.set(chat.id, chat);
}
state.workspaces = Object.fromEntries(workspaces.workspaces.map((workspace) => [workspace.id, workspace]));
// Removing a workspace deletes its chats with it, and the host reports
// only the workspaces' change: they go here.
for (const [id, chat] of state.chats) if (!state.workspaces[chat.workspaceId]) state.chats.delete(id);
state.chatsLoaded = true;
update();
});
const changed = (chat: Chat) => {
state.chats.set(chat.id, chat);
update();
};
const removed = (chatId: string) => {
state.chats.delete(chatId);
update();
};
return { load, changed, removed };
});
No comments yet.