perf: deduplicate _goose/providers/list RPC call at startup (#8873)
Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,22 @@ export interface AcpCreateSessionOptions extends AcpPrepareSessionOptions {
|
||||
/** Discover ACP providers installed on the system. */
|
||||
export async function discoverAcpProviders(): Promise<AcpProvider[]> {
|
||||
const providers = await directAcp.listProviders();
|
||||
return resolveProvidersCatalog(providers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive ACP providers from already-fetched inventory entries,
|
||||
* avoiding a duplicate `_goose/providers/list` RPC.
|
||||
*/
|
||||
export function discoverAcpProvidersFromEntries(
|
||||
entries: Array<{ providerId: string; providerName: string }>,
|
||||
): AcpProvider[] {
|
||||
return resolveProvidersCatalog(
|
||||
directAcp.buildProviderListFromEntries(entries),
|
||||
);
|
||||
}
|
||||
|
||||
function resolveProvidersCatalog(providers: AcpProvider[]): AcpProvider[] {
|
||||
const seen = new Set<string>();
|
||||
|
||||
return providers
|
||||
|
||||
@@ -27,26 +27,40 @@ export interface AcpSessionInfo {
|
||||
personaId: string | null;
|
||||
}
|
||||
|
||||
const DEPRECATED_PROVIDER_IDS = new Set(["claude-code", "codex", "gemini-cli"]);
|
||||
const DEFAULT_PROVIDER: AcpProvider = {
|
||||
export const DEPRECATED_PROVIDER_IDS = new Set([
|
||||
"claude-code",
|
||||
"codex",
|
||||
"gemini-cli",
|
||||
]);
|
||||
export const DEFAULT_PROVIDER: AcpProvider = {
|
||||
id: "goose",
|
||||
label: "Goose (Default)",
|
||||
};
|
||||
|
||||
/**
|
||||
* Build the ACP provider list from raw inventory entries.
|
||||
*
|
||||
* Shared by both `listProviders` (which fetches entries via RPC) and
|
||||
* `discoverAcpProvidersFromEntries` in acp.ts (which reuses
|
||||
* already-fetched entries at startup).
|
||||
*/
|
||||
export function buildProviderListFromEntries(
|
||||
entries: Array<{ providerId: string; providerName: string }>,
|
||||
): AcpProvider[] {
|
||||
return [
|
||||
DEFAULT_PROVIDER,
|
||||
...entries
|
||||
.filter((entry) => !DEPRECATED_PROVIDER_IDS.has(entry.providerId))
|
||||
.map((entry) => ({ id: entry.providerId, label: entry.providerName })),
|
||||
];
|
||||
}
|
||||
|
||||
export async function listProviders(): Promise<AcpProvider[]> {
|
||||
const client = await getClient();
|
||||
const result = await client.goose.GooseProvidersList({
|
||||
providerIds: [],
|
||||
});
|
||||
|
||||
const providers = result.entries
|
||||
.filter((entry) => !DEPRECATED_PROVIDER_IDS.has(entry.providerId))
|
||||
.map((entry) => ({
|
||||
id: entry.providerId,
|
||||
label: entry.providerName,
|
||||
}));
|
||||
|
||||
return [DEFAULT_PROVIDER, ...providers];
|
||||
return buildProviderListFromEntries(result.entries);
|
||||
}
|
||||
|
||||
export async function listSessions(): Promise<AcpSessionInfo[]> {
|
||||
|
||||
Reference in New Issue
Block a user