mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:00:42 +00:00
refactor: resolve contribution owners from lookup maps
This commit is contained in:
@@ -221,6 +221,47 @@ function listContributionManifestPlugins(
|
||||
}).plugins;
|
||||
}
|
||||
|
||||
function resolveContributionOwnerMap(
|
||||
table: PluginLookUpTable,
|
||||
contribution: PluginRegistryContributionKey,
|
||||
): ReadonlyMap<string, readonly string[]> | undefined {
|
||||
switch (contribution) {
|
||||
case "channels":
|
||||
return table.owners.channels;
|
||||
case "channelConfigs":
|
||||
return table.owners.channelConfigs;
|
||||
case "providers":
|
||||
return table.owners.providers;
|
||||
case "modelCatalogProviders":
|
||||
return table.owners.modelCatalogProviders;
|
||||
case "cliBackends":
|
||||
return table.owners.cliBackends;
|
||||
case "setupProviders":
|
||||
return table.owners.setupProviders;
|
||||
case "commandAliases":
|
||||
return table.owners.commandAliases;
|
||||
case "contracts":
|
||||
return table.owners.contracts;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function filterContributionOwnerIds(params: {
|
||||
owners: readonly string[];
|
||||
index: PluginRegistrySnapshot;
|
||||
includeDisabled?: boolean;
|
||||
config?: OpenClawConfig;
|
||||
}): readonly string[] {
|
||||
const enabledPluginIds = new Set(
|
||||
resolveContributionPluginIds({
|
||||
index: params.index,
|
||||
includeDisabled: params.includeDisabled,
|
||||
config: params.config,
|
||||
}),
|
||||
);
|
||||
return sortUnique(params.owners.filter((owner) => enabledPluginIds.has(owner)));
|
||||
}
|
||||
|
||||
export function loadPluginManifestRegistryForPluginRegistry(
|
||||
params: LoadPluginRegistryManifestParams = {},
|
||||
): PluginManifestRegistry {
|
||||
@@ -310,11 +351,24 @@ export function listPluginContributionIds(
|
||||
export function resolvePluginContributionOwners(
|
||||
params: ResolvePluginContributionOwnersParams,
|
||||
): readonly string[] {
|
||||
const index = params.lookUpTable?.index ?? loadPluginRegistrySnapshot(params);
|
||||
if (params.lookUpTable && typeof params.matches === "string") {
|
||||
const ownerMap = resolveContributionOwnerMap(params.lookUpTable, params.contribution);
|
||||
const owners = ownerMap?.get(params.matches);
|
||||
if (owners) {
|
||||
return filterContributionOwnerIds({
|
||||
owners,
|
||||
index,
|
||||
includeDisabled: params.includeDisabled,
|
||||
config: params.config,
|
||||
});
|
||||
}
|
||||
return [];
|
||||
}
|
||||
const matcher =
|
||||
typeof params.matches === "string"
|
||||
? (contributionId: string) => contributionId === params.matches
|
||||
: params.matches;
|
||||
const index = params.lookUpTable?.index ?? loadPluginRegistrySnapshot(params);
|
||||
const plugins = listContributionManifestPlugins({ ...params, index });
|
||||
return sortUnique(
|
||||
plugins.flatMap((plugin) =>
|
||||
@@ -328,6 +382,19 @@ export function resolveProviderOwners(params: ResolveProviderOwnersParams): read
|
||||
if (!providerId) {
|
||||
return [];
|
||||
}
|
||||
if (params.lookUpTable) {
|
||||
const index = params.lookUpTable.index;
|
||||
const owners = [...params.lookUpTable.owners.providers.entries()].flatMap(
|
||||
([contributionId, ownerIds]) =>
|
||||
normalizeProviderId(contributionId) === providerId ? [...ownerIds] : [],
|
||||
);
|
||||
return filterContributionOwnerIds({
|
||||
owners,
|
||||
index,
|
||||
includeDisabled: params.includeDisabled,
|
||||
config: params.config,
|
||||
});
|
||||
}
|
||||
return resolvePluginContributionOwners({
|
||||
...params,
|
||||
contribution: "providers",
|
||||
|
||||
@@ -241,12 +241,26 @@ describe("plugin registry facade", () => {
|
||||
fs.unlinkSync(path.join(rootDir, "openclaw.plugin.json"));
|
||||
|
||||
expect(listPluginContributionIds({ lookUpTable, contribution: "providers" })).toEqual(["demo"]);
|
||||
expect(resolveProviderOwners({ lookUpTable, providerId: "demo" })).toEqual(["demo"]);
|
||||
expect(resolveProviderOwners({ lookUpTable, providerId: "DEMO" })).toEqual(["demo"]);
|
||||
expect(resolveChannelOwners({ lookUpTable, channelId: "demo-chat" })).toEqual(["demo"]);
|
||||
expect(resolveCliBackendOwners({ lookUpTable, cliBackendId: "demo-cli" })).toEqual(["demo"]);
|
||||
expect(resolveSetupProviderOwners({ lookUpTable, setupProviderId: "demo-setup" })).toEqual([
|
||||
"demo",
|
||||
]);
|
||||
expect(
|
||||
resolvePluginContributionOwners({
|
||||
lookUpTable,
|
||||
contribution: "commandAliases",
|
||||
matches: "demo-command",
|
||||
}),
|
||||
).toEqual(["demo"]);
|
||||
expect(
|
||||
resolvePluginContributionOwners({
|
||||
lookUpTable,
|
||||
contribution: "contracts",
|
||||
matches: "tools",
|
||||
}),
|
||||
).toEqual(["demo"]);
|
||||
});
|
||||
|
||||
it("normalizes plugin config ids through registry contribution aliases", () => {
|
||||
|
||||
Reference in New Issue
Block a user