refactor(channels): remove stale discovery helpers

This commit is contained in:
Vincent Koc
2026-06-19 04:19:17 +08:00
parent dfd8a2220b
commit 033162f209
6 changed files with 6 additions and 122 deletions
@@ -247,24 +247,6 @@ export function resolveMessageActionDiscoveryForPlugin(params: {
};
}
/**
* Lists message actions available across registered channel plugins.
*/
export function listChannelMessageActions(cfg: OpenClawConfig): ChannelMessageActionName[] {
const actions = new Set<ChannelMessageActionName>(["send", "broadcast"]);
for (const plugin of listChannelPlugins()) {
for (const action of resolveMessageActionDiscoveryForPlugin({
pluginId: plugin.id,
actions: plugin.actions,
context: { cfg },
includeActions: true,
}).actions) {
actions.add(action);
}
}
return Array.from(actions);
}
/**
* Lists actions whose schemas do not block cross-channel tool usage.
*/
@@ -13,7 +13,6 @@ import {
channelSupportsMessageCapability,
channelSupportsMessageCapabilityForChannel,
listCrossChannelSchemaSupportedMessageActions,
listChannelMessageActions,
listChannelMessageCapabilities,
listChannelMessageCapabilitiesForChannel,
resolveChannelMessageToolMediaSourceParamKeys,
@@ -184,7 +183,6 @@ describe("message action capability checks", () => {
createTestRegistry([{ pluginId: "demo-unified", source: "test", plugin: unifiedPlugin }]),
);
expect(listChannelMessageActions({} as OpenClawConfig)).toEqual(["send", "broadcast", "react"]);
expect(listChannelMessageCapabilities({} as OpenClawConfig)).toEqual(["presentation"]);
expect(
resolveChannelMessageToolSchemaProperties({
@@ -443,11 +441,9 @@ describe("message action capability checks", () => {
createTestRegistry([{ pluginId: "demo-crashing", source: "test", plugin: crashingPlugin }]),
);
expect(listChannelMessageActions({} as OpenClawConfig)).toEqual(["send", "broadcast"]);
expect(listChannelMessageCapabilities({} as OpenClawConfig)).toStrictEqual([]);
expect(errorSpy).toHaveBeenCalledTimes(1);
expect(listChannelMessageActions({} as OpenClawConfig)).toEqual(["send", "broadcast"]);
expect(listChannelMessageCapabilities({} as OpenClawConfig)).toStrictEqual([]);
expect(errorSpy).toHaveBeenCalledTimes(1);
});
@@ -14,10 +14,7 @@ vi.mock("./registry.js", () => ({
getLoadedChannelPlugin: getLoadedChannelPluginMock,
}));
import {
resolveSingleAccountKeysToMove,
shouldMoveSingleAccountChannelKey,
} from "./setup-promotion-helpers.js";
import { resolveSingleAccountKeysToMove } from "./setup-promotion-helpers.js";
describe("setup promotion helpers", () => {
beforeEach(() => {
@@ -76,11 +73,13 @@ describe("setup promotion helpers", () => {
});
expect(
shouldMoveSingleAccountChannelKey({
resolveSingleAccountKeysToMove({
channelKey: "demo",
key: "customAuth",
channel: {
customAuth: "secret",
},
}),
).toBe(true);
).toEqual(["customAuth"]);
expect(getBundledChannelPluginMock).toHaveBeenCalledWith("demo");
});
@@ -44,33 +44,6 @@ function getBundledChannelSetupPromotionSurface(
return asPromotionSurface(getBundledChannelPlugin(channelKey)?.setup);
}
/**
* Returns whether one root-level channel key should move into account config.
*/
export function shouldMoveSingleAccountChannelKey(params: {
channelKey: string;
key: string;
}): boolean {
// Common keys move for every channel; channel-owned setup surfaces can add
// plugin-specific keys without teaching core about that channel's schema.
if (isCommonSingleAccountPromotionKey(params.key)) {
return true;
}
const loadedContractKeys = getLoadedChannelSetupPromotionSurface(
params.channelKey,
)?.singleAccountKeysToMove;
if (loadedContractKeys?.includes(params.key)) {
return true;
}
const bundledContractKeys = getBundledChannelSetupPromotionSurface(
params.channelKey,
)?.singleAccountKeysToMove;
if (bundledContractKeys?.includes(params.key)) {
return true;
}
return false;
}
/**
* Resolves all root-level keys eligible for single-account promotion.
*/
-28
View File
@@ -3,13 +3,10 @@ import { beforeEach, describe, expect, it } from "vitest";
import { setActivePluginRegistry } from "../plugins/runtime.js";
import { createChannelTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js";
import {
deliveryContextFromRoute,
formatConversationTarget,
normalizeRoutableChannelRoute,
resolveConversationDeliveryTarget,
routeFromBindingRecord,
routeFromConversationRef,
routeFromDeliveryContext,
routeToDeliveryFields,
} from "./route-projection.js";
@@ -80,28 +77,6 @@ describe("channel route projection", () => {
);
});
it("round-trips delivery context through channel route metadata", () => {
const route = routeFromDeliveryContext({
channel: " Slack ",
to: " channel:C123 ",
accountId: " work ",
threadId: " 177000.123 ",
});
expect(route).toEqual({
channel: "slack",
accountId: "work",
target: { to: "channel:C123" },
thread: { id: "177000.123" },
});
expect(deliveryContextFromRoute(route)).toEqual({
channel: "slack",
to: "channel:C123",
accountId: "work",
threadId: "177000.123",
});
});
it("formats plugin-defined conversation targets via channel messaging hooks", () => {
expect(
formatConversationTarget({ channel: "room-chat", conversationId: "!room:example" }),
@@ -190,7 +165,4 @@ describe("channel route projection", () => {
});
});
it("narrows only routable routes", () => {
expect(normalizeRoutableChannelRoute({ channel: "slack" })).toBeUndefined();
});
});
-38
View File
@@ -5,7 +5,6 @@ import type {
} from "../infra/outbound/session-binding-service.js";
import {
normalizeChannelRouteRef,
type ChannelRouteChatType,
type ChannelRouteRef,
} from "../plugin-sdk/channel-route.js";
import {
@@ -13,9 +12,7 @@ import {
type ConversationTargetParams,
} from "../utils/conversation-target.js";
import {
channelRouteFromDeliveryContext,
deliveryContextFromChannelRoute,
normalizeDeliveryContext,
type DeliveryContext,
} from "../utils/delivery-context.shared.js";
import { getChannelPlugin, normalizeChannelId } from "./plugins/registry.js";
@@ -66,41 +63,6 @@ export function resolveConversationDeliveryTarget(params: ConversationTargetPara
return { to };
}
/** Channel route normalized enough to address an outbound delivery target. */
export type RoutableChannelRouteRef = ChannelRouteRef & {
channel: string;
target: {
to: string;
rawTo?: string;
chatType?: ChannelRouteChatType;
};
};
/** Normalizes a route and rejects routes that cannot address a channel target. */
export function normalizeRoutableChannelRoute(
route?: ChannelRouteRef | null,
): RoutableChannelRouteRef | undefined {
const normalized = normalizeChannelRouteRef({
channel: route?.channel,
accountId: route?.accountId,
to: route?.target?.to,
rawTo: route?.target?.rawTo,
chatType: route?.target?.chatType,
threadId: route?.thread?.id,
threadKind: route?.thread?.kind,
threadSource: route?.thread?.source,
});
if (!normalized?.channel || !normalized.target?.to) {
return undefined;
}
return normalized as RoutableChannelRouteRef;
}
/** Converts legacy delivery context metadata into a channel route. */
export function routeFromDeliveryContext(context?: DeliveryContext): ChannelRouteRef | undefined {
return channelRouteFromDeliveryContext(normalizeDeliveryContext(context));
}
/** Converts a channel route back to legacy delivery context metadata. */
export function deliveryContextFromRoute(route?: ChannelRouteRef): DeliveryContext | undefined {
return deliveryContextFromChannelRoute(route);