mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
refactor(plugins): share channel command normalization
This commit is contained in:
@@ -16,6 +16,7 @@ import type { BundledChannelConfigCollector } from "./manifest-registry.js";
|
||||
import {
|
||||
DEFAULT_PLUGIN_ENTRY_CANDIDATES,
|
||||
getPackageManifestMetadata,
|
||||
normalizeManifestChannelCommandDefaults,
|
||||
type OpenClawPackageManifest,
|
||||
type PackageManifest,
|
||||
type PluginPackageChannel,
|
||||
@@ -274,28 +275,6 @@ function resolveFallbackPluginSource(record: InstalledPluginIndexRecord): string
|
||||
return path.join(rootDir, DEFAULT_PLUGIN_ENTRY_CANDIDATES[0]);
|
||||
}
|
||||
|
||||
function normalizePackageChannelCommands(
|
||||
commands: unknown,
|
||||
): PluginPackageChannel["commands"] | undefined {
|
||||
if (!isRecord(commands)) {
|
||||
return undefined;
|
||||
}
|
||||
const nativeCommandsAutoEnabled =
|
||||
typeof commands.nativeCommandsAutoEnabled === "boolean"
|
||||
? commands.nativeCommandsAutoEnabled
|
||||
: undefined;
|
||||
const nativeSkillsAutoEnabled =
|
||||
typeof commands.nativeSkillsAutoEnabled === "boolean"
|
||||
? commands.nativeSkillsAutoEnabled
|
||||
: undefined;
|
||||
return nativeCommandsAutoEnabled !== undefined || nativeSkillsAutoEnabled !== undefined
|
||||
? {
|
||||
...(nativeCommandsAutoEnabled !== undefined ? { nativeCommandsAutoEnabled } : {}),
|
||||
...(nativeSkillsAutoEnabled !== undefined ? { nativeSkillsAutoEnabled } : {}),
|
||||
}
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function normalizePackageChannelExposure(
|
||||
exposure: unknown,
|
||||
): PluginPackageChannel["exposure"] | undefined {
|
||||
@@ -480,7 +459,7 @@ function normalizePersistedPackageChannel(value: unknown): PluginPackageChannel
|
||||
if (exposure) {
|
||||
channel.exposure = exposure;
|
||||
}
|
||||
const commands = normalizePackageChannelCommands(value.commands);
|
||||
const commands = normalizeManifestChannelCommandDefaults(value.commands);
|
||||
if (commands) {
|
||||
channel.commands = commands;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ import {
|
||||
type PluginManifestToolMetadata,
|
||||
type PluginPackageChannel,
|
||||
type PluginPackageInstall,
|
||||
normalizeManifestChannelCommandDefaults,
|
||||
} from "./manifest.js";
|
||||
import { checkMinHostVersion } from "./min-host-version.js";
|
||||
import {
|
||||
@@ -295,29 +296,6 @@ function normalizePreferredPluginIds(raw: unknown): string[] | undefined {
|
||||
return normalizeOptionalTrimmedStringList(raw);
|
||||
}
|
||||
|
||||
function normalizePackageChannelCommands(
|
||||
commands: unknown,
|
||||
): PluginManifestChannelCommandDefaults | undefined {
|
||||
if (!commands || typeof commands !== "object" || Array.isArray(commands)) {
|
||||
return undefined;
|
||||
}
|
||||
const record = commands as Record<string, unknown>;
|
||||
const nativeCommandsAutoEnabled =
|
||||
typeof record.nativeCommandsAutoEnabled === "boolean"
|
||||
? record.nativeCommandsAutoEnabled
|
||||
: undefined;
|
||||
const nativeSkillsAutoEnabled =
|
||||
typeof record.nativeSkillsAutoEnabled === "boolean"
|
||||
? record.nativeSkillsAutoEnabled
|
||||
: undefined;
|
||||
return nativeCommandsAutoEnabled !== undefined || nativeSkillsAutoEnabled !== undefined
|
||||
? {
|
||||
...(nativeCommandsAutoEnabled !== undefined ? { nativeCommandsAutoEnabled } : {}),
|
||||
...(nativeSkillsAutoEnabled !== undefined ? { nativeSkillsAutoEnabled } : {}),
|
||||
}
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function mergePackageChannelMetaIntoChannelConfigs(params: {
|
||||
channelConfigs?: Record<string, PluginManifestChannelConfig>;
|
||||
packageChannel?: OpenClawPackageManifest["channel"];
|
||||
@@ -342,7 +320,7 @@ function mergePackageChannelMetaIntoChannelConfigs(params: {
|
||||
const preferOver =
|
||||
existing.preferOver ?? normalizePreferredPluginIds(params.packageChannel?.preferOver);
|
||||
const commands =
|
||||
existing.commands ?? normalizePackageChannelCommands(params.packageChannel?.commands);
|
||||
existing.commands ?? normalizeManifestChannelCommandDefaults(params.packageChannel?.commands);
|
||||
|
||||
const merged: Record<string, PluginManifestChannelConfig> = Object.create(null);
|
||||
for (const [key, value] of Object.entries(params.channelConfigs)) {
|
||||
@@ -501,7 +479,7 @@ function buildRecord(params: {
|
||||
}),
|
||||
packageChannel: params.candidate.packageManifest?.channel,
|
||||
});
|
||||
const packageChannelCommands = normalizePackageChannelCommands(
|
||||
const packageChannelCommands = normalizeManifestChannelCommandDefaults(
|
||||
params.candidate.packageManifest?.channel?.commands,
|
||||
);
|
||||
return {
|
||||
|
||||
@@ -1615,7 +1615,7 @@ function normalizeChannelConfigs(
|
||||
return Object.keys(normalized).length > 0 ? normalized : undefined;
|
||||
}
|
||||
|
||||
function normalizeManifestChannelCommandDefaults(
|
||||
export function normalizeManifestChannelCommandDefaults(
|
||||
value: unknown,
|
||||
): PluginManifestChannelCommandDefaults | undefined {
|
||||
if (!isRecord(value)) {
|
||||
|
||||
Reference in New Issue
Block a user