* feat(plugins): contribute settings screens and shared controls * fix(plugins): localize settings and verify shared UI consumers * test(composer): unmount draft test roots after each case * test(app): keep launch terminals alive until cleanup The fixed ten-second profile lifetime could expire before a busy CI browser attached or finished revisiting the composer. Keep the real process waiting for input until project teardown terminates it. * test(server): await the initial snapshot before a buffered ref event Watcher setup can read checkout facts before the initial refresh publishes a snapshot. Wait for publication before injecting the event so the test consistently exercises a second refresh.
195 lines
5.5 KiB
TypeScript
195 lines
5.5 KiB
TypeScript
import type {
|
|
ProviderConnectRequest,
|
|
ProviderEvent,
|
|
ProviderInput,
|
|
} from "@getpaseo/plugin/provider";
|
|
import { ProviderEventSchema, ProviderInputSchema } from "@getpaseo/plugin/provider";
|
|
import { z } from "zod";
|
|
|
|
export interface PluginProviderMetadata {
|
|
id: string;
|
|
label: string;
|
|
description?: string;
|
|
iconPath?: string;
|
|
}
|
|
|
|
export type PluginProcessRequest =
|
|
| {
|
|
type: "initialize";
|
|
pluginId: string;
|
|
bundle: string;
|
|
appVersion: string;
|
|
settingsDirectory?: string;
|
|
}
|
|
| { type: "invoke"; requestId: string; method: string; input: unknown }
|
|
| {
|
|
type: "provider.connect";
|
|
providerId: string;
|
|
connectionId: string;
|
|
request: ProviderConnectRequest;
|
|
}
|
|
| {
|
|
type: "provider.send";
|
|
connectionId: string;
|
|
acceptanceId: string;
|
|
input: ProviderInput;
|
|
}
|
|
| { type: "provider.close"; connectionId: string }
|
|
| { type: "shutdown" }
|
|
| { type: "paseo_frame"; data: string | Uint8Array; isBinary: boolean }
|
|
| { type: "paseo_close" };
|
|
|
|
export type PluginProcessMessage =
|
|
| { type: "settings.changed"; settingsId: string }
|
|
| { type: "ready"; methods: string[]; providers: PluginProviderMetadata[] }
|
|
| { type: "result"; requestId: string; output: unknown }
|
|
| { type: "error"; requestId: string; error: string }
|
|
| { type: "fatal"; error: string }
|
|
| {
|
|
type: "provider.connected";
|
|
connectionId: string;
|
|
version: number;
|
|
capabilities: readonly string[];
|
|
}
|
|
| { type: "provider.connect_failed"; connectionId: string; error: string }
|
|
| { type: "provider.accepted"; connectionId: string; acceptanceId: string }
|
|
| {
|
|
type: "provider.rejected";
|
|
connectionId: string;
|
|
acceptanceId: string;
|
|
error: string;
|
|
}
|
|
| { type: "provider.event"; connectionId: string; event: ProviderEvent }
|
|
| { type: "provider.closed"; connectionId: string; error?: string }
|
|
| { type: "paseo_frame"; data: string | Uint8Array; isBinary: boolean }
|
|
| { type: "paseo_close" };
|
|
|
|
const providerMetadataSchema = z
|
|
.object({
|
|
id: z.string().min(1),
|
|
label: z.string().min(1),
|
|
description: z.string().optional(),
|
|
iconPath: z.string().optional(),
|
|
})
|
|
.strict();
|
|
const providerConnectRequestSchema = z
|
|
.object({
|
|
versions: z.array(z.number().int().positive()),
|
|
capabilities: z.array(z.string()),
|
|
})
|
|
.strict();
|
|
const frameFields = {
|
|
data: z.union([z.string(), z.instanceof(Uint8Array)]),
|
|
isBinary: z.boolean(),
|
|
};
|
|
|
|
export const PluginProcessRequestSchema: z.ZodType<PluginProcessRequest> = z.discriminatedUnion(
|
|
"type",
|
|
[
|
|
z
|
|
.object({
|
|
type: z.literal("initialize"),
|
|
pluginId: z.string().min(1),
|
|
bundle: z.string(),
|
|
appVersion: z.string(),
|
|
settingsDirectory: z.string().optional(),
|
|
})
|
|
.strict(),
|
|
z
|
|
.object({
|
|
type: z.literal("invoke"),
|
|
requestId: z.string().min(1),
|
|
method: z.string().min(1),
|
|
input: z.unknown(),
|
|
})
|
|
.strict(),
|
|
z
|
|
.object({
|
|
type: z.literal("provider.connect"),
|
|
providerId: z.string().min(1),
|
|
connectionId: z.string().min(1),
|
|
request: providerConnectRequestSchema,
|
|
})
|
|
.strict(),
|
|
z
|
|
.object({
|
|
type: z.literal("provider.send"),
|
|
connectionId: z.string().min(1),
|
|
acceptanceId: z.string().min(1),
|
|
input: ProviderInputSchema,
|
|
})
|
|
.strict(),
|
|
z.object({ type: z.literal("provider.close"), connectionId: z.string().min(1) }).strict(),
|
|
z.object({ type: z.literal("shutdown") }).strict(),
|
|
z.object({ type: z.literal("paseo_frame"), ...frameFields }).strict(),
|
|
z.object({ type: z.literal("paseo_close") }).strict(),
|
|
],
|
|
);
|
|
|
|
export const PluginProcessMessageSchema: z.ZodType<PluginProcessMessage> = z.discriminatedUnion(
|
|
"type",
|
|
[
|
|
z.object({ type: z.literal("settings.changed"), settingsId: z.string() }).strict(),
|
|
z
|
|
.object({
|
|
type: z.literal("ready"),
|
|
methods: z.array(z.string()),
|
|
providers: z.array(providerMetadataSchema),
|
|
})
|
|
.strict(),
|
|
z
|
|
.object({ type: z.literal("result"), requestId: z.string().min(1), output: z.unknown() })
|
|
.strict(),
|
|
z
|
|
.object({ type: z.literal("error"), requestId: z.string().min(1), error: z.string() })
|
|
.strict(),
|
|
z.object({ type: z.literal("fatal"), error: z.string() }).strict(),
|
|
z
|
|
.object({
|
|
type: z.literal("provider.connected"),
|
|
connectionId: z.string().min(1),
|
|
version: z.number().int().positive(),
|
|
capabilities: z.array(z.string()),
|
|
})
|
|
.strict(),
|
|
z
|
|
.object({
|
|
type: z.literal("provider.connect_failed"),
|
|
connectionId: z.string().min(1),
|
|
error: z.string(),
|
|
})
|
|
.strict(),
|
|
z
|
|
.object({
|
|
type: z.literal("provider.accepted"),
|
|
connectionId: z.string().min(1),
|
|
acceptanceId: z.string().min(1),
|
|
})
|
|
.strict(),
|
|
z
|
|
.object({
|
|
type: z.literal("provider.rejected"),
|
|
connectionId: z.string().min(1),
|
|
acceptanceId: z.string().min(1),
|
|
error: z.string(),
|
|
})
|
|
.strict(),
|
|
z
|
|
.object({
|
|
type: z.literal("provider.event"),
|
|
connectionId: z.string().min(1),
|
|
event: ProviderEventSchema,
|
|
})
|
|
.strict(),
|
|
z
|
|
.object({
|
|
type: z.literal("provider.closed"),
|
|
connectionId: z.string().min(1),
|
|
error: z.string().optional(),
|
|
})
|
|
.strict(),
|
|
z.object({ type: z.literal("paseo_frame"), ...frameFields }).strict(),
|
|
z.object({ type: z.literal("paseo_close") }).strict(),
|
|
],
|
|
);
|