Skip to content

Commit 1ac75ce

Browse files
committed
refactor(channels): split chat-meta accessors along the SDK contract
getChatChannelMeta keeps its shipped plugin-SDK signature (defined for bundled ids, fail-loud on impossible misses); new findChatChannelMeta carries the drift-tolerant optional contract for core auto-enable and formatting paths.
1 parent 1936309 commit 1ac75ce

7 files changed

Lines changed: 25 additions & 15 deletions

File tree

src/channels/chat-meta.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* Provides ordered channel metadata for setup, status, and selection surfaces.
55
*/
6+
import { expectDefined } from "@openclaw/normalization-core";
67
import { buildChatChannelMetaById, type ChatChannelMeta } from "./chat-meta-shared.js";
78
import { CHAT_CHANNEL_ORDER, type ChatChannelId } from "./ids.js";
89

@@ -26,7 +27,16 @@ export function listChatChannels(): ChatChannelMeta[] {
2627
/**
2728
* Returns metadata for one built-in chat channel id.
2829
*/
29-
export function getChatChannelMeta(id: ChatChannelId): ChatChannelMeta | undefined {
30-
// Undefined is a real state: callers tolerate bundled channel id metadata drift.
30+
/** Drift-tolerant lookup: undefined when the id is missing from the bundled catalog. */
31+
export function findChatChannelMeta(id: ChatChannelId): ChatChannelMeta | undefined {
3132
return getChatChannelMetaById()[id];
3233
}
34+
35+
/**
36+
* Returns metadata for one built-in chat channel id.
37+
* Shipped plugin-SDK contract: callers pass bundled ids, so absence is an invariant
38+
* violation; drift-tolerant core paths use findChatChannelMeta instead.
39+
*/
40+
export function getChatChannelMeta(id: ChatChannelId): ChatChannelMeta {
41+
return expectDefined(findChatChannelMeta(id), `chat channel meta for ${id}`);
42+
}

src/channels/registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
findRegisteredChannelPluginEntryById,
1212
listRegisteredChannelPluginEntries,
1313
} from "./registry-lookup.js";
14-
export { getChatChannelMeta } from "./chat-meta.js";
14+
export { findChatChannelMeta, getChatChannelMeta } from "./chat-meta.js";
1515
export { CHAT_CHANNEL_ORDER } from "./ids.js";
1616
export type { ChatChannelId } from "./ids.js";
1717
export { normalizeChatChannelId };

src/config/plugin-auto-enable.prefer-over.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from "node:fs";
33
import path from "node:path";
44
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
55
import { normalizeStringEntries } from "@openclaw/normalization-core/string-normalization";
6-
import { getChatChannelMeta, normalizeChatChannelId } from "../channels/registry.js";
6+
import { findChatChannelMeta, normalizeChatChannelId } from "../channels/registry.js";
77
import type { PluginManifestRegistry } from "../plugins/manifest-registry.js";
88
import { isRecord, resolveConfigDir, resolveUserPath } from "../utils.js";
99
import type { PluginAutoEnableCandidate } from "./plugin-auto-enable.types.js";
@@ -97,7 +97,7 @@ function resolveBuiltInChannelPreferOver(channelId: string): readonly string[] {
9797
if (!builtInChannelId) {
9898
return [];
9999
}
100-
return getChatChannelMeta(builtInChannelId)?.preferOver ?? [];
100+
return findChatChannelMeta(builtInChannelId)?.preferOver ?? [];
101101
}
102102

103103
function resolvePreferredOverIds(

src/config/plugin-auto-enable.shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
hasBundledChannelConfiguredState,
1313
listBundledChannelIdsWithConfiguredState,
1414
} from "../channels/plugins/configured-state.js";
15-
import { getChatChannelMeta, normalizeChatChannelId } from "../channels/registry.js";
15+
import { findChatChannelMeta, normalizeChatChannelId } from "../channels/registry.js";
1616
import { isBlockedObjectKey } from "../infra/prototype-keys.js";
1717
import { normalizePluginsConfig } from "../plugins/config-state.js";
1818
import { getCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-snapshot.js";
@@ -1014,7 +1014,7 @@ function resolveChannelAutoEnableDisplayLabel(
10141014
const builtInChannelId = normalizeChatChannelId(entry.channelId);
10151015
const plugin = manifestRegistry.plugins.find((record) => record.id === entry.pluginId);
10161016
return (
1017-
(builtInChannelId ? getChatChannelMeta(builtInChannelId)?.label : undefined) ??
1017+
(builtInChannelId ? findChatChannelMeta(builtInChannelId)?.label : undefined) ??
10181018
plugin?.channelConfigs?.[entry.channelId]?.label ??
10191019
plugin?.channelCatalogMeta?.label
10201020
);

src/infra/outbound/format.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Outbound delivery formatting produces human CLI summaries for direct and
22
// gateway send results.
3-
import { getChatChannelMeta } from "../../channels/chat-meta.js";
3+
import { findChatChannelMeta } from "../../channels/chat-meta.js";
44
import { getChannelPlugin } from "../../channels/plugins/index.js";
55
import type { ChannelId } from "../../channels/plugins/types.public.js";
66
import { normalizeChatChannelId } from "../../channels/registry.js";
@@ -32,7 +32,7 @@ const resolveChannelLabel = (channel: string) => {
3232
// Some legacy chat channels are not plugins; keep their human labels for CLI output.
3333
const normalized = normalizeChatChannelId(channel);
3434
if (normalized) {
35-
return getChatChannelMeta(normalized)?.label ?? channel;
35+
return findChatChannelMeta(normalized)?.label ?? channel;
3636
}
3737
return channel;
3838
};

src/plugins/channel-validation.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ describe("normalizeRegisteredChannelPlugin", () => {
5757
docsPath: normalized?.meta.docsPath,
5858
blurb: normalized?.meta.blurb,
5959
}).toEqual({
60-
label: telegram?.label,
61-
selectionLabel: telegram?.selectionLabel,
62-
docsPath: telegram?.docsPath,
63-
blurb: telegram?.blurb,
60+
label: telegram.label,
61+
selectionLabel: telegram.selectionLabel,
62+
docsPath: telegram.docsPath,
63+
blurb: telegram.blurb,
6464
});
6565
expect(diagnostics).toEqual([
6666
{

src/utils/message-channel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
normalizeGatewayClientName,
99
} from "../../packages/gateway-protocol/src/client-info.js";
1010
import { listBundledChannelCatalogEntries } from "../channels/bundled-channel-catalog-read.js";
11-
import { getChatChannelMeta } from "../channels/chat-meta.js";
11+
import { findChatChannelMeta } from "../channels/chat-meta.js";
1212
import { getRegisteredChannelPluginMeta, normalizeChatChannelId } from "../channels/registry.js";
1313
export {
1414
isDeliverableMessageChannel,
@@ -103,7 +103,7 @@ export function isMarkdownCapableMessageChannel(raw?: string | null): boolean {
103103
}
104104
const builtInChannel = normalizeChatChannelId(channel);
105105
if (builtInChannel) {
106-
const builtInMeta = getChatChannelMeta(builtInChannel);
106+
const builtInMeta = findChatChannelMeta(builtInChannel);
107107
if (builtInMeta) {
108108
return builtInMeta.markdownCapable === true;
109109
}

0 commit comments

Comments
 (0)