fix: restore channel auto-enable metadata

This commit is contained in:
Peter Steinberger
2026-04-11 14:04:21 +01:00
parent 40beb68fb0
commit 2ffc19720b
2 changed files with 39 additions and 20 deletions

View File

@@ -91,14 +91,23 @@ function resolveExternalCatalogPreferOver(channelId: string, env: NodeJS.Process
return [];
}
function resolveBuiltInChannelPreferOver(channelId: string): readonly string[] {
const builtInChannelId = normalizeChatChannelId(channelId);
if (!builtInChannelId) {
return [];
}
return getChatChannelMeta(builtInChannelId).preferOver ?? [];
}
function resolvePreferredOverIds(
pluginId: string,
candidate: PluginAutoEnableCandidate,
env: NodeJS.ProcessEnv,
registry: PluginManifestRegistry,
): string[] {
const normalized = normalizeChatChannelId(pluginId) ?? pluginId;
const installedPlugin = registry.plugins.find((record) => record.id === normalized);
const manifestChannelPreferOver = installedPlugin?.channelConfigs?.[pluginId]?.preferOver;
const channelId =
candidate.kind === "channel-configured" ? candidate.channelId : candidate.pluginId;
const installedPlugin = registry.plugins.find((record) => record.id === candidate.pluginId);
const manifestChannelPreferOver = installedPlugin?.channelConfigs?.[channelId]?.preferOver;
if (manifestChannelPreferOver?.length) {
return [...manifestChannelPreferOver];
}
@@ -106,11 +115,11 @@ function resolvePreferredOverIds(
if (installedChannelMeta?.preferOver?.length) {
return [...installedChannelMeta.preferOver];
}
const bundledChannelMeta = getChatChannelMeta(normalized);
if (bundledChannelMeta?.preferOver?.length) {
return [...bundledChannelMeta.preferOver];
const builtInChannelPreferOver = resolveBuiltInChannelPreferOver(channelId);
if (builtInChannelPreferOver.length) {
return [...builtInChannelPreferOver];
}
return resolveExternalCatalogPreferOver(pluginId, env);
return resolveExternalCatalogPreferOver(channelId, env);
}
export function shouldSkipPreferredPluginAutoEnable(params: {
@@ -133,9 +142,7 @@ export function shouldSkipPreferredPluginAutoEnable(params: {
continue;
}
if (
resolvePreferredOverIds(other.pluginId, params.env, params.registry).includes(
params.entry.pluginId,
)
resolvePreferredOverIds(other, params.env, params.registry).includes(params.entry.pluginId)
) {
return true;
}

View File

@@ -608,17 +608,29 @@ function materializeConfiguredPluginEntryAllowlist(params: {
return next;
}
function resolveAutoEnableChangeReason(entry: PluginAutoEnableCandidate): string {
if (entry.kind !== "channel-configured") {
return resolvePluginAutoEnableCandidateReason(entry);
function resolveChannelAutoEnableDisplayLabel(
entry: Extract<PluginAutoEnableCandidate, { kind: "channel-configured" }>,
manifestRegistry: PluginManifestRegistry,
): string | undefined {
const builtInChannelId = normalizeChatChannelId(entry.channelId);
if (builtInChannelId) {
return getChatChannelMeta(builtInChannelId).label;
}
const channelId = normalizeChatChannelId(entry.channelId);
const label = channelId ? getChatChannelMeta(channelId)?.label : undefined;
return `${label ?? entry.channelId} configured`;
const plugin = manifestRegistry.plugins.find((record) => record.id === entry.pluginId);
return plugin?.channelConfigs?.[entry.channelId]?.label ?? plugin?.channelCatalogMeta?.label;
}
function formatAutoEnableChange(entry: PluginAutoEnableCandidate): string {
return `${resolveAutoEnableChangeReason(entry).trim()}, enabled automatically.`;
function formatAutoEnableChange(
entry: PluginAutoEnableCandidate,
manifestRegistry: PluginManifestRegistry,
): string {
if (entry.kind === "channel-configured") {
const label = resolveChannelAutoEnableDisplayLabel(entry, manifestRegistry);
if (label) {
return `${label} configured, enabled automatically.`;
}
}
return `${resolvePluginAutoEnableCandidateReason(entry).trim()}, enabled automatically.`;
}
export function resolvePluginAutoEnableManifestRegistry(params: {
@@ -684,7 +696,7 @@ export function materializePluginAutoEnableCandidatesInternal(params: {
...(autoEnabledReasons.get(entry.pluginId) ?? []),
reason,
]);
changes.push(formatAutoEnableChange(entry));
changes.push(formatAutoEnableChange(entry, params.manifestRegistry));
}
next = materializeConfiguredPluginEntryAllowlist({