mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-07 17:04:42 +00:00
A plugin registers a component with addComposerItem and reads and changes the composer through useComposer(): provider, model, mode, thinking, options, prompt, attachments and agent metadata. The agent, draft and New workspace composers provide the same ComposerInput and ComposerAgent halves, so a command reaches the right model without the plugin knowing which composer it sits in. Toggle, Select and Action are drawn by one ComposerControl renderer that the thinking select and provider option controls now use too. Controls sit in the toolbar when there is room and become rows in the existing overflow sheet otherwise, so on a phone they appear in the overflow. Plugin items count in the density presence so the composer condenses to make room. Model and mode stay specialized but share the trigger, density and overflow. Draft metadata is kept locally, sent at creation and reset when the prompt is sent. PluginAgentSnapshot.metadata, deferred from the metadata phase, lands here. The unused provider badge is removed. vitest resolves @floating-ui/react-native to its ESM build: the CJS entry requires the real react-native, whose Flow sources do not parse.
80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
import { PluginTranslationRuntime } from "@getpaseo/plugin/client/host";
|
|
import { usePaseo, useRpc } from "@getpaseo/plugin/client";
|
|
import { defineRpc } from "@getpaseo/plugin";
|
|
import type { PaseoApi } from "@getpaseo/client";
|
|
import { QueryClient } from "@tanstack/react-query";
|
|
import React from "react";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { expect, it } from "vitest";
|
|
import { z } from "zod";
|
|
import { PluginInstallationProvider } from "./installation-provider";
|
|
import type { InstalledPlugin } from "./types";
|
|
|
|
const status = defineRpc({
|
|
name: "deploys.status",
|
|
input: z.object({}),
|
|
output: z.object({ state: z.string() }),
|
|
});
|
|
|
|
function installation(invoked: string[]): InstalledPlugin {
|
|
return {
|
|
id: "deploys",
|
|
serverId: "host",
|
|
clientBundle: "",
|
|
lifetime: new AbortController(),
|
|
locale: "en",
|
|
i18n: new PluginTranslationRuntime({ getLocale: () => "en", subscribe: () => () => {} }),
|
|
paseo: { dispose: async () => undefined } as PaseoApi,
|
|
invoke: async (method) => {
|
|
invoked.push(method);
|
|
return { state: "green" };
|
|
},
|
|
subscribe: () => {
|
|
throw new Error("Subscriptions are not used here");
|
|
},
|
|
queryClient: new QueryClient(),
|
|
cleanup: () => undefined,
|
|
settingsScreens: [],
|
|
surfaces: [],
|
|
sidebarItems: { header: [], footer: [] },
|
|
legacySidebarItems: [],
|
|
filePanels: [],
|
|
composerItems: [],
|
|
workspacePanels: [],
|
|
commandCenterItems: [],
|
|
clientSlashCommands: [],
|
|
attachmentSources: [],
|
|
themes: [],
|
|
timelineTransformers: [],
|
|
timelineRenderers: [],
|
|
};
|
|
}
|
|
|
|
it("gives every surface the installation's client and RPCs on its first frame", async () => {
|
|
const invoked: string[] = [];
|
|
const plugin = installation(invoked);
|
|
const received: PaseoApi[] = [];
|
|
let rpc: ((input: Record<string, never>) => Promise<unknown>) | null = null;
|
|
function Surface({ name }: { name: string }) {
|
|
received.push(usePaseo());
|
|
rpc = useRpc(status);
|
|
return <span>{name}</span>;
|
|
}
|
|
|
|
const markup = ["Screen", "Sidebar item", "Popover"]
|
|
.map((name) =>
|
|
renderToStaticMarkup(
|
|
<PluginInstallationProvider plugin={plugin}>
|
|
<Surface name={name} />
|
|
</PluginInstallationProvider>,
|
|
),
|
|
)
|
|
.join("");
|
|
|
|
expect(markup).toBe("<span>Screen</span><span>Sidebar item</span><span>Popover</span>");
|
|
expect(received).toEqual([plugin.paseo, plugin.paseo, plugin.paseo]);
|
|
expect(received.every((paseo) => paseo === plugin.paseo)).toBe(true);
|
|
await expect(rpc!({})).resolves.toEqual({ state: "green" });
|
|
expect(invoked).toEqual(["deploys.status"]);
|
|
});
|