
























@@ -15,13 +15,17 @@ import type { loadOpenClawPlugins as loadOpenClawPluginsType } from "../../plugi
1515import type { PluginManifestRecord } from "../../plugins/manifest-registry.js";
1616import { loadPluginManifestRegistryForPluginRegistry } from "../../plugins/plugin-registry.js";
1717import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../../routing/session-key.js";
18-import { normalizeOptionalString } from "../../shared/string-coerce.js";
1918import { sanitizeForLog } from "../../terminal/ansi.js";
2019import { getBundledChannelSetupPlugin } from "./bundled.js";
20+import {
21+isSafeManifestChannelId,
22+normalizeChannelCommandDefaults,
23+readOwnRecordValue,
24+resolveReadOnlyChannelCommandDefaults,
25+} from "./read-only-command-defaults.js";
2126import { listChannelPlugins } from "./registry.js";
2227import type { ChannelPlugin } from "./types.plugin.js";
232824-const SAFE_MANIFEST_CHANNEL_ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/i;
2529const LOADER_MODULE_CANDIDATES = [
2630new URL("../../plugins/loader.js", import.meta.url),
2731new URL("../../plugins/loader.ts", import.meta.url),
@@ -73,10 +77,6 @@ type ReadOnlyChannelPluginResolution = {
7377missingConfiguredChannelIds: string[];
7478};
7579type ManifestChannelConfigRecord = NonNullable<PluginManifestRecord["channelConfigs"]>[string];
76-type ChannelCommandDefaults = Pick<
77-NonNullable<ChannelPlugin["commands"]>,
78-"nativeCommandsAutoEnabled" | "nativeSkillsAutoEnabled"
79->;
80808181function addChannelPlugins(
8282byId: Map<string, ChannelPlugin>,
@@ -115,41 +115,10 @@ function rebindChannelScopedString(
115115return value;
116116}
117117118-function isSafeManifestChannelId(channelId: string): boolean {
119-return SAFE_MANIFEST_CHANNEL_ID_PATTERN.test(channelId) && !isBlockedObjectKey(channelId);
120-}
121-122-function readOwnRecordValue(record: Record<string, unknown>, key: string): unknown {
123-if (isBlockedObjectKey(key) || !Object.prototype.hasOwnProperty.call(record, key)) {
124-return undefined;
125-}
126-return record[key];
127-}
128-129118function normalizeManifestText(value: string | undefined, fallback: string): string {
130119return sanitizeForLog(value?.trim() || fallback).trim();
131120}
132121133-function normalizeChannelCommandDefaults(
134-value: ChannelCommandDefaults | undefined,
135-): ChannelCommandDefaults | undefined {
136-if (!value) {
137-return undefined;
138-}
139-const nativeCommandsAutoEnabled =
140-typeof value.nativeCommandsAutoEnabled === "boolean"
141- ? value.nativeCommandsAutoEnabled
142- : undefined;
143-const nativeSkillsAutoEnabled =
144-typeof value.nativeSkillsAutoEnabled === "boolean" ? value.nativeSkillsAutoEnabled : undefined;
145-return nativeCommandsAutoEnabled !== undefined || nativeSkillsAutoEnabled !== undefined
146- ? {
147- ...(nativeCommandsAutoEnabled !== undefined ? { nativeCommandsAutoEnabled } : {}),
148- ...(nativeSkillsAutoEnabled !== undefined ? { nativeSkillsAutoEnabled } : {}),
149-}
150- : undefined;
151-}
152-153122function rebindChannelConfig(
154123cfg: OpenClawConfig,
155124sourceChannelId: string,
@@ -347,46 +316,7 @@ function canUseManifestChannelPlugin(record: PluginManifestRecord, channelId: st
347316return record.channelCatalogMeta?.id === channelId;
348317}
349318350-export function resolveReadOnlyChannelCommandDefaults(
351-channelId: string,
352-options: {
353-env?: NodeJS.ProcessEnv;
354-stateDir?: string;
355-workspaceDir?: string;
356-} = {},
357-): ChannelCommandDefaults | undefined {
358-const normalizedChannelId = normalizeOptionalString(channelId) ?? "";
359-if (!normalizedChannelId || !isSafeManifestChannelId(normalizedChannelId)) {
360-return undefined;
361-}
362-const registry = loadPluginManifestRegistryForPluginRegistry({
363-stateDir: options.stateDir,
364-workspaceDir: options.workspaceDir,
365-env: options.env ?? process.env,
366-includeDisabled: true,
367-});
368-for (const record of registry.plugins) {
369-if (!record.channels.includes(normalizedChannelId)) {
370-continue;
371-}
372-const channelConfigValue = record.channelConfigs
373- ? readOwnRecordValue(record.channelConfigs as Record<string, unknown>, normalizedChannelId)
374- : undefined;
375-const channelConfig =
376-channelConfigValue &&
377-typeof channelConfigValue === "object" &&
378-!Array.isArray(channelConfigValue)
379- ? (channelConfigValue as ManifestChannelConfigRecord)
380- : undefined;
381-const commands = normalizeChannelCommandDefaults(
382-channelConfig?.commands ?? record.channelCatalogMeta?.commands,
383-);
384-if (commands) {
385-return commands;
386-}
387-}
388-return undefined;
389-}
319+export { resolveReadOnlyChannelCommandDefaults };
390320391321function rebindChannelPluginConfig(
392322config: ChannelPlugin["config"],
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。