Files
paseo/plugins/muse-provider/server/provider.ts
T
Mohamed Boudra 3914893aa1 Troubleshoot providers from their settings page, and tidy provider settings (#10487)
* feat(providers): add docs links, sign-in facts and a tidier provider page

A user whose Antigravity models looked stale had no way to find out why
without asking in chat. agy 1.5.14 picks its sign-in from the
environment: with SSH_CONNECTION, SSH_CLIENT or SSH_TTY set it reads a
token file, otherwise the OS keyring
(google-antigravity/antigravity-cli#1336). The daemon is often started
outside SSH while the user tests agy over SSH, so the two can be signed
in to different accounts and list different models.

- The Antigravity status reports whether agy runs in an SSH session, and
  the diagnostic report for plugin providers now includes the resolved
  command, path and version like built-in providers do.
- Providers carry an optional docsUrl (protocol field, plugin SDK
  registration, built-in definitions). The provider page links it from
  Troubleshooting, and the Antigravity page documents the sign-in
  mismatch.
- Provider and project settings get a breadcrumb title. Refresh moves to
  the Models header, the model list scrolls inside a fixed height with a
  full-width search, and section headers keep one spacing whether or not
  they hold an action.
- A switch no longer makes its row taller than the track, and every
  settings row is at least as tall as one with a switch, so a switch row
  and a text row line up.

* fix(providers): report Antigravity's sign-in when ACP does not start

A sign-in problem can be what stops agy's ACP server from starting, so
the diagnostic report now shows the SSH session rows in that case too.

The plugin provider diagnostic test no longer compares the daemon PATH
and shell rows, which differ per host (Windows reports ComSpec).

* fix(server): show the same provider version in the report and Installation

The plugin diagnostic read the version by calling the provider's
inspect itself with a 10s deadline, while the Installation row reads it
through the installation service with a 20s deadline and a cache. A
version check between 10 and 20 seconds showed in Installation and as
an error in the report.

The snapshot manager now hands getDiagnostic an inspectInstallation
that reads through the installation service, so both show one answer
and agy --version runs once for both.

* feat(app): give rows that open something the same height as other rows

Detail rows and collapsible row headers reserved a button's height so a
list where only some rows held a switch kept one height. Now that every
settings row is at least as tall as a switch row, that reserve only made
rows like Diagnostic report and Docs taller than their neighbours.

* test(app): compare rows that open something with text and switch rows

* feat(app): size the provider icon to the page title

* fix(app): scale the provider title icon with the interface size
2026-11-22 15:13:31 +07:00

264 lines
8.8 KiB
TypeScript

import {
negotiateProviderCapabilities,
requireProviderCapabilities,
type ProviderConnection,
type ProviderEvent,
type ProviderInput,
type ProviderLaunch,
type ProviderRegistration,
type ProviderStatus,
} from "@getpaseo/plugin/server/provider";
import { serveArgs } from "./options.js";
import { Usage } from "./usage.js";
import { execCommand } from "@getpaseo/plugin/server";
import { Catalog, launchKey } from "./catalog.js";
import { MspConnection } from "./connection.js";
import { MuseError, actionableError } from "./errors.js";
import { Sessions } from "./sessions.js";
import { Session } from "./session.js";
import { accountSchema } from "./wire.js";
import {
checkMuseForUpdates,
readMuseChannelRelease,
type ReadMuseChannelRelease,
} from "./updates.js";
const capabilities = [
"prompt.message",
"prompt.command",
"prompt.image",
"prompt.steer",
"session.configure",
"session.persistence",
"permission",
"session.list",
] as const;
export interface MuseProviderOptions {
/** Reads a Muse update channel; defaults to the channel the `muse` launcher updates from. */
readChannelRelease?: ReadMuseChannelRelease;
}
export function createMuseProvider(
usage: Usage,
museOptions: MuseProviderOptions = {},
): ProviderRegistration {
return {
id: "muse",
label: "Muse Code",
icon: "icon.svg",
command: ["muse"],
docsUrl: "https://paseo.sh/docs/supported-providers/muse-code",
installation: {
installUrl: "https://paseo.sh/docs/muse-code",
async inspect({ launch, signal }) {
if (!launch?.resolved) return { status: "not_installed" };
const version = await readVersion(launch, signal);
// The build identifies a release; several builds share one x.y.z.
return version
? { status: "installed", version: version.build ?? version.text }
: { status: "installed" };
},
async checkForUpdates({ launch, installedVersion, signal }) {
return checkMuseForUpdates({
installedVersion,
env: launch?.env,
readChannelRelease: museOptions.readChannelRelease ?? readMuseChannelRelease,
signal,
});
},
},
async getCatalogCacheKey(options) {
return launchKey(requireLaunch(options.launch));
},
async status({ launch }) {
if (!launch)
return { available: false, diagnostic: "Install Muse Code and ensure `muse` is on PATH." };
usage.remember(launch);
return status(launch);
},
async connect(request) {
if (!request.versions.includes(1))
throw new MuseError("protocol", "Provider protocol version 1 is required");
usage.remember(requireLaunch(request.launch));
return connect(
requireLaunch(request.launch),
negotiateProviderCapabilities(request.capabilities, capabilities),
usage,
);
},
};
}
function requireLaunch(launch: ProviderLaunch | undefined): ProviderLaunch {
if (!launch) throw new MuseError("missingLaunch", "Muse requires a daemon-resolved executable");
return launch;
}
interface MuseVersion {
text: string;
major: number;
minor: number;
/** The build in parentheses, as in `Muse Code 1.4.18 (1.4.18-R8587.1)`. */
build: string | null;
}
/** The `x.y.z` that `muse --version` prints, or null when the output has none. */
async function readVersion(
launch: ProviderLaunch,
signal?: AbortSignal,
): Promise<MuseVersion | null> {
const { stdout } = await execCommand(launch.command, [...launch.args, "--version"], {
env: launch.env,
timeout: 3000,
maxBuffer: 8192,
signal,
});
const match = /\b(\d+)\.(\d+)\.(\d+)\b/.exec(stdout);
if (!match) return null;
const build = /\(([^)\s]+)\)/.exec(stdout)?.[1] ?? null;
return { text: match[0], major: Number(match[1]), minor: Number(match[2]), build };
}
async function status(launch: ProviderLaunch): Promise<ProviderStatus> {
let host: MspConnection | undefined;
try {
const version = await readVersion(launch);
if (!version) return { available: false, diagnostic: "Muse returned an unrecognized version." };
if (version.major < 1 || (version.major === 1 && version.minor < 3))
return {
available: false,
diagnostic: `Update Muse Code: found ${version.text}, need ≥1.3.0`,
};
// Leave room for the version probe, account read and cleanup within the status RPC deadline.
host = new MspConnection({ launch, timeoutMs: 3000, startupTimeoutMs: 20000 });
await host.initialize();
const account = await host.request("account/read", {}, accountSchema);
if (account.state === "loggedOut")
return { available: false, diagnostic: "Run `muse login` or set META_API_KEY" };
return { available: true };
} catch (error) {
return { available: false, diagnostic: actionableError(error, launch).message };
} finally {
await host?.close();
}
}
function connect(
launch: ProviderLaunch,
negotiated: readonly string[],
usage: Usage,
): ProviderConnection {
const listeners = new Set<(event: ProviderEvent) => void>();
const sessions = new Map<string, Session>();
const catalog = new Catalog();
const imports = new Sessions();
let closed = false;
function emit(event: ProviderEvent): void {
if (!closed) for (const listener of listeners) listener(event);
}
async function dispatch(input: ProviderInput): Promise<void> {
if (input.type === "sessions") {
emit({
type: "sessions",
requestId: input.requestId,
sessions: await imports.list(launch, input),
});
return;
}
if (input.type === "catalog") {
emit({ type: "catalog", requestId: input.requestId, catalog: await catalog.read(launch) });
return;
}
if (input.type === "session.open") {
if (sessions.has(input.sessionId))
throw new MuseError("duplicateSession", "Muse session is already open");
const session = new Session({
id: input.sessionId,
config: input.config,
launch,
emit,
capabilities: negotiated,
serveArgs: serveArgs(input.config.providerOptions),
});
sessions.set(input.sessionId, session);
try {
await session.open(input);
usage.attach(
input.sessionId,
{ ...launch, env: { ...launch.env, ...input.config.env } },
() => session.readUsage(),
);
} catch (error) {
sessions.delete(input.sessionId);
await session.close();
throw error;
}
return;
}
if (!("sessionId" in input))
throw new MuseError("unsupported", `Muse does not support ${input.type}`);
const session = sessions.get(input.sessionId);
if (!session) throw new MuseError("unknownSession", "Muse session is not open");
switch (input.type) {
case "session.prompt":
await session.prompt(input.prompt);
return;
case "session.configure":
await session.configure(input.changes);
break;
case "session.permission":
await session.answer(input.permissionId, input.response);
return;
case "session.interrupt":
await session.interrupt();
break;
case "session.close":
await session.close();
sessions.delete(input.sessionId);
usage.detach(input.sessionId);
emit({ type: "session.closed", sessionId: input.sessionId });
break;
default:
throw new MuseError("unsupported", `Muse does not support ${input.type}`);
}
if ("requestId" in input) emit({ type: "request.completed", requestId: input.requestId });
}
function failed(input: ProviderInput, failure: unknown): void {
const error = actionableError(failure, launch);
if (input.type === "session.prompt")
emit({
type: "session.prompt_result",
sessionId: input.sessionId,
clientMessageId: input.prompt.clientMessageId,
result: { type: "failed", error },
});
else if ("requestId" in input)
emit({ type: "request.failed", requestId: input.requestId, error });
else if ("sessionId" in input)
emit({ type: "session.runtime_failed", sessionId: input.sessionId, error });
}
return {
version: 1,
capabilities: negotiated,
async send(input) {
if (closed) throw new MuseError("closed", "Muse connection is closed");
requireProviderCapabilities(negotiated, input);
queueMicrotask(() => {
if (!closed) void dispatch(input).catch((error: unknown) => failed(input, error));
});
},
onEvent(listener) {
listeners.add(listener);
return () => listeners.delete(listener);
},
async close() {
if (closed) return;
closed = true;
await Promise.all([
catalog.close(),
imports.close(),
...[...sessions.values()].map((session) => session.close()),
]);
for (const id of sessions.keys()) usage.detach(id);
sessions.clear();
listeners.clear();
},
};
}