refactor: expand plugin lookup owner maps

This commit is contained in:
Shakker
2026-04-27 07:24:16 +01:00
parent dc6ac472db
commit fbf0a29195
2 changed files with 46 additions and 0 deletions

View File

@@ -106,11 +106,27 @@ describe("loadPluginLookUpTable", () => {
id: "telegram",
origin: "bundled",
channels: ["telegram"],
channelConfigs: {
telegram: {
schema: { type: "object" },
},
},
commandAliases: [{ name: "telegram-send" }],
contracts: {
tools: ["telegram.send"],
},
}),
createManifestRecord({
id: "openai",
origin: "bundled",
providers: ["openai", "openai-codex"],
modelCatalog: {
providers: {
openai: {
models: [{ id: "gpt-test" }],
},
},
},
cliBackends: ["codex-cli"],
setup: {
providers: [{ id: "openai" }],
@@ -146,9 +162,13 @@ describe("loadPluginLookUpTable", () => {
expect(table.byPluginId.get("telegram")?.id).toBe("telegram");
expect(table.normalizePluginId("openai-codex")).toBe("openai");
expect(table.owners.channels.get("telegram")).toEqual(["telegram"]);
expect(table.owners.channelConfigs.get("telegram")).toEqual(["telegram"]);
expect(table.owners.providers.get("openai")).toEqual(["openai"]);
expect(table.owners.modelCatalogProviders.get("openai")).toEqual(["openai"]);
expect(table.owners.cliBackends.get("codex-cli")).toEqual(["openai"]);
expect(table.owners.setupProviders.get("openai")).toEqual(["openai"]);
expect(table.owners.commandAliases.get("telegram-send")).toEqual(["telegram"]);
expect(table.owners.contracts.get("tools")).toEqual(["telegram"]);
expect(table.startup.channelPluginIds).toEqual(["telegram"]);
expect(table.startup.configuredDeferredChannelPluginIds).toEqual([]);
expect(table.startup.pluginIds).toEqual(["telegram"]);

View File

@@ -17,9 +17,13 @@ import {
export type PluginLookUpTableOwnerMaps = {
channels: ReadonlyMap<string, readonly string[]>;
channelConfigs: ReadonlyMap<string, readonly string[]>;
providers: ReadonlyMap<string, readonly string[]>;
modelCatalogProviders: ReadonlyMap<string, readonly string[]>;
cliBackends: ReadonlyMap<string, readonly string[]>;
setupProviders: ReadonlyMap<string, readonly string[]>;
commandAliases: ReadonlyMap<string, readonly string[]>;
contracts: ReadonlyMap<string, readonly string[]>;
};
export type PluginLookUpTableStartupPlan = {
@@ -66,30 +70,52 @@ function freezeOwnerMap(owners: Map<string, string[]>): ReadonlyMap<string, read
function buildOwnerMaps(plugins: readonly PluginManifestRecord[]): PluginLookUpTableOwnerMaps {
const channels = new Map<string, string[]>();
const channelConfigs = new Map<string, string[]>();
const providers = new Map<string, string[]>();
const modelCatalogProviders = new Map<string, string[]>();
const cliBackends = new Map<string, string[]>();
const setupProviders = new Map<string, string[]>();
const commandAliases = new Map<string, string[]>();
const contracts = new Map<string, string[]>();
for (const plugin of plugins) {
for (const channelId of plugin.channels) {
appendOwner(channels, channelId, plugin.id);
}
for (const channelId of Object.keys(plugin.channelConfigs ?? {})) {
appendOwner(channelConfigs, channelId, plugin.id);
}
for (const providerId of plugin.providers) {
appendOwner(providers, providerId, plugin.id);
}
for (const providerId of Object.keys(plugin.modelCatalog?.providers ?? {})) {
appendOwner(modelCatalogProviders, providerId, plugin.id);
}
for (const cliBackendId of plugin.cliBackends) {
appendOwner(cliBackends, cliBackendId, plugin.id);
}
for (const setupProvider of plugin.setup?.providers ?? []) {
appendOwner(setupProviders, setupProvider.id, plugin.id);
}
for (const commandAlias of plugin.commandAliases ?? []) {
appendOwner(commandAliases, commandAlias.name, plugin.id);
}
for (const [contract, values] of Object.entries(plugin.contracts ?? {})) {
if (Array.isArray(values) && values.length > 0) {
appendOwner(contracts, contract, plugin.id);
}
}
}
return {
channels: freezeOwnerMap(channels),
channelConfigs: freezeOwnerMap(channelConfigs),
providers: freezeOwnerMap(providers),
modelCatalogProviders: freezeOwnerMap(modelCatalogProviders),
cliBackends: freezeOwnerMap(cliBackends),
setupProviders: freezeOwnerMap(setupProviders),
commandAliases: freezeOwnerMap(commandAliases),
contracts: freezeOwnerMap(contracts),
};
}