diff --git a/src/plugin-sdk/core.ts b/src/plugin-sdk/core.ts index a81a11ddf46..2dbc5a7feec 100644 --- a/src/plugin-sdk/core.ts +++ b/src/plugin-sdk/core.ts @@ -1,6 +1,6 @@ -import { CHAT_CHANNEL_ORDER, type ChatChannelId } from "../channels/ids.js"; +import { buildChatChannelMetaById } from "../channels/chat-meta-shared.js"; +import type { ChatChannelId } from "../channels/ids.js"; import { emptyChannelConfigSchema } from "../channels/plugins/config-schema.js"; -import { resolveChannelExposure } from "../channels/plugins/exposure.js"; import { buildAccountScopedDmSecurityPolicy } from "../channels/plugins/helpers.js"; import { createScopedAccountReplyToModeResolver, @@ -23,8 +23,6 @@ import type { OpenClawConfig } from "../config/config.js"; import type { ReplyToMode } from "../config/types.base.js"; import { buildOutboundBaseSessionKey } from "../infra/outbound/base-session-key.js"; import type { OutboundDeliveryResult } from "../infra/outbound/deliver.js"; -import { listBundledPluginMetadata } from "../plugins/bundled-plugin-metadata.js"; -import type { PluginPackageChannel } from "../plugins/manifest.js"; import type { PluginRuntime } from "../plugins/runtime/types.js"; import type { OpenClawPluginApi } from "../plugins/types.js"; @@ -217,93 +215,6 @@ export type ChannelOutboundSessionRouteParams = Parameters< >[0]; var cachedSdkChatChannelMeta: ReturnType | undefined; -var cachedSdkChatChannelIdSet: Set | undefined; - -function getSdkChatChannelIdSet(): Set { - cachedSdkChatChannelIdSet ??= new Set(CHAT_CHANNEL_ORDER); - return cachedSdkChatChannelIdSet; -} - -function toSdkChatChannelMeta(params: { - id: ChatChannelId; - channel: PluginPackageChannel; -}): ChannelMeta { - const label = params.channel.label?.trim(); - if (!label) { - throw new Error(`Missing label for bundled chat channel "${params.id}"`); - } - const exposure = resolveChannelExposure(params.channel); - return { - id: params.id, - label, - selectionLabel: params.channel.selectionLabel?.trim() || label, - docsPath: params.channel.docsPath?.trim() || `/channels/${params.id}`, - docsLabel: params.channel.docsLabel?.trim() || undefined, - blurb: params.channel.blurb?.trim() || "", - ...(params.channel.aliases?.length ? { aliases: params.channel.aliases } : {}), - ...(params.channel.order !== undefined ? { order: params.channel.order } : {}), - ...(params.channel.selectionDocsPrefix !== undefined - ? { selectionDocsPrefix: params.channel.selectionDocsPrefix } - : {}), - ...(params.channel.selectionDocsOmitLabel !== undefined - ? { selectionDocsOmitLabel: params.channel.selectionDocsOmitLabel } - : {}), - ...(params.channel.selectionExtras?.length - ? { selectionExtras: params.channel.selectionExtras } - : {}), - ...(params.channel.detailLabel?.trim() - ? { detailLabel: params.channel.detailLabel.trim() } - : {}), - ...(params.channel.systemImage?.trim() - ? { systemImage: params.channel.systemImage.trim() } - : {}), - ...(params.channel.markdownCapable !== undefined - ? { markdownCapable: params.channel.markdownCapable } - : {}), - exposure, - ...(params.channel.quickstartAllowFrom !== undefined - ? { quickstartAllowFrom: params.channel.quickstartAllowFrom } - : {}), - ...(params.channel.forceAccountBinding !== undefined - ? { forceAccountBinding: params.channel.forceAccountBinding } - : {}), - ...(params.channel.preferSessionLookupForAnnounceTarget !== undefined - ? { - preferSessionLookupForAnnounceTarget: params.channel.preferSessionLookupForAnnounceTarget, - } - : {}), - ...(params.channel.preferOver?.length ? { preferOver: params.channel.preferOver } : {}), - }; -} - -function buildChatChannelMetaById(): Record { - const entries = new Map(); - for (const entry of listBundledPluginMetadata({ - includeChannelConfigs: true, - includeSyntheticChannelConfigs: false, - })) { - const channel = - entry.packageManifest && "channel" in entry.packageManifest - ? entry.packageManifest.channel - : undefined; - if (!channel) { - continue; - } - const rawId = channel.id?.trim(); - if (!rawId || !getSdkChatChannelIdSet().has(rawId)) { - continue; - } - const id = rawId; - entries.set( - id, - toSdkChatChannelMeta({ - id, - channel, - }), - ); - } - return Object.freeze(Object.fromEntries(entries)) as Record; -} function resolveSdkChatChannelMeta(id: string) { cachedSdkChatChannelMeta ??= buildChatChannelMetaById();