Files
Mohamed Boudra 0b3d82a469 feat(plugin): add shared header buttons and composer controls (#4577)
* feat(plugin): add shared header buttons and composer controls

* fix(plugin): isolate button registration imports and settle captures

* test(plugin): express button journeys through domain helpers
2026-09-09 15:39:12 +02:00

62 lines
1.9 KiB
TypeScript

import type { PluginAgentCommandContext, PluginClientContext } from "@getpaseo/plugin/client";
import { createButtonExamples, type ButtonMode } from "./client/examples";
export default function contribute(client: PluginClientContext) {
// Keep one example active at a time, including when switching agents or workspaces.
let current:
| {
workspaceId: string;
agentId: string;
buttons: ReturnType<typeof createButtonExamples>;
}
| undefined;
function buttonsFor({ workspace, agent }: PluginAgentCommandContext) {
if (current?.workspaceId !== workspace.id || current.agentId !== agent.id) {
current?.buttons.remove();
current = {
workspaceId: workspace.id,
agentId: agent.id,
buttons: createButtonExamples(client, workspace.id, agent.id),
};
}
return current.buttons;
}
for (const mode of ["action", "menu", "popover"] satisfies ButtonMode[]) {
client.addCommandCenterItem({
id: `show-${mode}`,
title: `Button examples: ${mode}`,
icon: "MousePointerClick",
context: "agent",
onSelect(context) {
buttonsFor(context).setMode(mode);
},
});
}
for (const visible of [false, true]) {
client.addCommandCenterItem({
id: visible ? "show" : "hide",
title: `Button examples: ${visible ? "show" : "hide"}`,
icon: visible ? "Eye" : "EyeOff",
context: "agent",
onSelect(context) {
buttonsFor(context).setVisible(visible);
},
});
}
for (const disabled of [true, false]) {
client.addCommandCenterItem({
id: disabled ? "disable" : "enable",
title: `Button examples: ${disabled ? "disable" : "enable"}`,
icon: "MousePointerClick",
context: "agent",
onSelect(context) {
buttonsFor(context).setDisabled(disabled);
},
});
}
return () => current?.buttons.remove();
}