refactor(plugins): derive compat provider ids from manifests

This commit is contained in:
Peter Steinberger
2026-03-16 00:40:58 -07:00
parent 74d0c39b32
commit 8fe08df2eb
8 changed files with 88 additions and 57 deletions

View File

@@ -20,7 +20,13 @@ describe("resolvePluginProviders", () => {
});
loadPluginManifestRegistryMock.mockReset();
loadPluginManifestRegistryMock.mockReturnValue({
plugins: [],
plugins: [
{ id: "google", providers: ["google"], origin: "bundled" },
{ id: "kilocode", providers: ["kilocode"], origin: "bundled" },
{ id: "moonshot", providers: ["moonshot"], origin: "bundled" },
{ id: "google-gemini-cli-auth", providers: [], origin: "bundled" },
{ id: "workspace-provider", providers: ["workspace-provider"], origin: "workspace" },
],
diagnostics: [],
});
});
@@ -77,7 +83,7 @@ describe("resolvePluginProviders", () => {
config: expect.objectContaining({
plugins: expect.objectContaining({
enabled: true,
allow: expect.arrayContaining(["openai", "moonshot", "zai"]),
allow: expect.arrayContaining(["google", "moonshot"]),
}),
}),
cache: false,
@@ -103,6 +109,22 @@ describe("resolvePluginProviders", () => {
expect(allow).not.toContain("google-gemini-cli-auth");
});
it("does not inject non-bundled provider plugin ids into compat allowlists", () => {
resolvePluginProviders({
config: {
plugins: {
allow: ["openrouter"],
},
},
bundledProviderAllowlistCompat: true,
});
const call = loadOpenClawPluginsMock.mock.calls.at(-1)?.[0];
const allow = call?.config?.plugins?.allow;
expect(allow).not.toContain("workspace-provider");
});
it("maps provider ids to owning plugin ids via manifests", () => {
loadPluginManifestRegistryMock.mockReturnValue({
plugins: [

View File

@@ -7,39 +7,6 @@ import { loadPluginManifestRegistry } from "./manifest-registry.js";
import type { ProviderPlugin } from "./types.js";
const log = createSubsystemLogger("plugins");
const BUNDLED_PROVIDER_ALLOWLIST_COMPAT_PLUGIN_IDS = [
"anthropic",
"byteplus",
"cloudflare-ai-gateway",
"copilot-proxy",
"github-copilot",
"google",
"huggingface",
"kilocode",
"kimi-coding",
"minimax",
"mistral",
"modelstudio",
"moonshot",
"nvidia",
"ollama",
"openai",
"opencode",
"opencode-go",
"openrouter",
"qianfan",
"qwen-portal-auth",
"sglang",
"synthetic",
"together",
"venice",
"vercel-ai-gateway",
"volcengine",
"xai",
"vllm",
"xiaomi",
"zai",
] as const;
function hasExplicitPluginConfig(config: PluginLoadOptions["config"]): boolean {
const plugins = config?.plugins;
@@ -69,10 +36,11 @@ function hasExplicitPluginConfig(config: PluginLoadOptions["config"]): boolean {
function withBundledProviderVitestCompat(params: {
config: PluginLoadOptions["config"];
pluginIds: readonly string[];
env?: PluginLoadOptions["env"];
}): PluginLoadOptions["config"] {
const env = params.env ?? process.env;
if (!env.VITEST || hasExplicitPluginConfig(params.config)) {
if (!env.VITEST || hasExplicitPluginConfig(params.config) || params.pluginIds.length === 0) {
return params.config;
}
@@ -81,7 +49,7 @@ function withBundledProviderVitestCompat(params: {
plugins: {
...params.config?.plugins,
enabled: true,
allow: [...BUNDLED_PROVIDER_ALLOWLIST_COMPAT_PLUGIN_IDS],
allow: [...params.pluginIds],
slots: {
...params.config?.plugins?.slots,
memory: "none",
@@ -90,6 +58,22 @@ function withBundledProviderVitestCompat(params: {
};
}
function resolveBundledProviderCompatPluginIds(params: {
config?: PluginLoadOptions["config"];
workspaceDir?: string;
env?: PluginLoadOptions["env"];
}): string[] {
const registry = loadPluginManifestRegistry({
config: params.config,
workspaceDir: params.workspaceDir,
env: params.env,
});
return registry.plugins
.filter((plugin) => plugin.origin === "bundled" && plugin.providers.length > 0)
.map((plugin) => plugin.id)
.toSorted((left, right) => left.localeCompare(right));
}
export function resolveOwningPluginIdsForProvider(params: {
provider: string;
config?: PluginLoadOptions["config"];
@@ -126,15 +110,24 @@ export function resolvePluginProviders(params: {
activate?: boolean;
cache?: boolean;
}): ProviderPlugin[] {
const bundledProviderCompatPluginIds =
params.bundledProviderAllowlistCompat || params.bundledProviderVitestCompat
? resolveBundledProviderCompatPluginIds({
config: params.config,
workspaceDir: params.workspaceDir,
env: params.env,
})
: [];
const maybeAllowlistCompat = params.bundledProviderAllowlistCompat
? withBundledPluginAllowlistCompat({
config: params.config,
pluginIds: BUNDLED_PROVIDER_ALLOWLIST_COMPAT_PLUGIN_IDS,
pluginIds: bundledProviderCompatPluginIds,
})
: params.config;
const config = params.bundledProviderVitestCompat
? withBundledProviderVitestCompat({
config: maybeAllowlistCompat,
pluginIds: bundledProviderCompatPluginIds,
env: params.env,
})
: maybeAllowlistCompat;