mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 12:41:12 +00:00
Channels: finish message-channel host lookup
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import type { ChannelPlugin } from "../channels/plugins/types.js";
|
||||
import { addExtensionHostChannelRegistration } from "../extension-host/runtime-registry.js";
|
||||
import { setActivePluginRegistry } from "../plugins/runtime.js";
|
||||
import { createMSTeamsTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js";
|
||||
import { resolveGatewayMessageChannel } from "./message-channel.js";
|
||||
@@ -31,4 +32,22 @@ describe("message-channel", () => {
|
||||
);
|
||||
expect(resolveGatewayMessageChannel("teams")).toBe("msteams");
|
||||
});
|
||||
|
||||
it("falls back to host-owned channel state when the legacy channel array is replaced", () => {
|
||||
const registry = createTestRegistry([
|
||||
{ pluginId: "msteams", plugin: msteamsPlugin, source: "test" },
|
||||
]);
|
||||
setActivePluginRegistry(registry, "message-channel-registry");
|
||||
expect(resolveGatewayMessageChannel("teams")).toBe("msteams");
|
||||
|
||||
registry.channels = [] as typeof registry.channels;
|
||||
addExtensionHostChannelRegistration(registry, {
|
||||
pluginId: "msteams",
|
||||
plugin: msteamsPlugin,
|
||||
source: "test",
|
||||
});
|
||||
setActivePluginRegistry(registry, "message-channel-registry");
|
||||
|
||||
expect(resolveGatewayMessageChannel("teams")).toBe("msteams");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
normalizeChatChannelId,
|
||||
} from "../channels/registry.js";
|
||||
import { getActiveExtensionHostRegistry } from "../extension-host/active-registry.js";
|
||||
import { listExtensionHostChannelRegistrations } from "../extension-host/runtime-registry.js";
|
||||
import {
|
||||
GATEWAY_CLIENT_MODES,
|
||||
GATEWAY_CLIENT_NAMES,
|
||||
@@ -65,14 +66,16 @@ export function normalizeMessageChannel(raw?: string | null): string | undefined
|
||||
return builtIn;
|
||||
}
|
||||
const registry = getActiveExtensionHostRegistry();
|
||||
const pluginMatch = registry?.channels.find((entry) => {
|
||||
if (entry.plugin.id.toLowerCase() === normalized) {
|
||||
return true;
|
||||
}
|
||||
return (entry.plugin.meta.aliases ?? []).some(
|
||||
(alias) => alias.trim().toLowerCase() === normalized,
|
||||
);
|
||||
});
|
||||
const pluginMatch = registry
|
||||
? listExtensionHostChannelRegistrations(registry).find((entry) => {
|
||||
if (entry.plugin.id.toLowerCase() === normalized) {
|
||||
return true;
|
||||
}
|
||||
return (entry.plugin.meta.aliases ?? []).some(
|
||||
(alias) => alias.trim().toLowerCase() === normalized,
|
||||
);
|
||||
})
|
||||
: undefined;
|
||||
return pluginMatch?.plugin.id ?? normalized;
|
||||
}
|
||||
|
||||
@@ -81,7 +84,7 @@ const listPluginChannelIds = (): string[] => {
|
||||
if (!registry) {
|
||||
return [];
|
||||
}
|
||||
return registry.channels.map((entry) => entry.plugin.id);
|
||||
return listExtensionHostChannelRegistrations(registry).map((entry) => entry.plugin.id);
|
||||
};
|
||||
|
||||
const listPluginChannelAliases = (): string[] => {
|
||||
@@ -89,7 +92,9 @@ const listPluginChannelAliases = (): string[] => {
|
||||
if (!registry) {
|
||||
return [];
|
||||
}
|
||||
return registry.channels.flatMap((entry) => entry.plugin.meta.aliases ?? []);
|
||||
return listExtensionHostChannelRegistrations(registry).flatMap(
|
||||
(entry) => entry.plugin.meta.aliases ?? [],
|
||||
);
|
||||
};
|
||||
|
||||
export const listDeliverableMessageChannels = (): ChannelId[] =>
|
||||
|
||||
Reference in New Issue
Block a user