Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/messaging/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

export * from "./manifest";
5 changes: 5 additions & 0 deletions src/lib/messaging/manifest/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

export * from "./registry";
export type * from "./types";
70 changes: 70 additions & 0 deletions src/lib/messaging/manifest/registry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, it } from "vitest";

import { ChannelManifestRegistry, createChannelManifestRegistry } from "./index";
import type { ChannelManifest } from "./index";

function makeManifest(
id: string,
displayName: string,
supportedAgents: ChannelManifest["supportedAgents"],
): ChannelManifest {
return {
schemaVersion: 1,
id,
displayName,
supportedAgents,
auth: {
mode: "token-paste",
},
inputs: [],
credentials: [],
policyPresets: [id],
render: [],
state: {},
hooks: [],
};
}

const TELEGRAM_MANIFEST = makeManifest("telegram", "Telegram", ["openclaw", "hermes"]);
const WECHAT_MANIFEST = makeManifest("wechat", "WeChat", ["openclaw"]);

describe("ChannelManifestRegistry", () => {
it("registers, retrieves, and lists manifests in memory", () => {
const registry = createChannelManifestRegistry();

registry.register(TELEGRAM_MANIFEST);

expect(registry.get("telegram")).toBe(TELEGRAM_MANIFEST);
expect(registry.get(" TELEGRAM ")).toBe(TELEGRAM_MANIFEST);
expect(registry.list()).toEqual([TELEGRAM_MANIFEST]);
});

it("rejects duplicate channel ids", () => {
expect(
() => new ChannelManifestRegistry([TELEGRAM_MANIFEST, TELEGRAM_MANIFEST]),
).toThrow("Duplicate channel manifest id 'telegram'");
});

it("filters available manifests by agent and non-empty platform support lists", () => {
const registry = new ChannelManifestRegistry([TELEGRAM_MANIFEST, WECHAT_MANIFEST]);

expect(registry.listAvailable().map((manifest) => manifest.id)).toEqual([
"telegram",
"wechat",
]);
expect(registry.listAvailable({ agent: "hermes" }).map((manifest) => manifest.id)).toEqual([
"telegram",
]);
expect(
registry.listAvailable({ agent: "openclaw", supportedChannelIds: ["wechat"] }).map(
(manifest) => manifest.id,
),
).toEqual(["wechat"]);
expect(
registry.listAvailable({ supportedChannelIds: [] }).map((manifest) => manifest.id),
).toEqual(["telegram", "wechat"]);
});
});
64 changes: 64 additions & 0 deletions src/lib/messaging/manifest/registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import type { ChannelManifest, MessagingAgentId, MessagingChannelId } from "./types";

export interface ChannelManifestAvailabilityContext {
readonly agent?: MessagingAgentId | null;
readonly supportedChannelIds?: readonly MessagingChannelId[] | null;
}

export class ChannelManifestRegistry {
private readonly manifests = new Map<MessagingChannelId, ChannelManifest>();

constructor(manifests: readonly ChannelManifest[] = []) {
for (const manifest of manifests) {
this.register(manifest);
}
}

register(manifest: ChannelManifest): this {
const id = normalizeChannelId(manifest.id);
if (this.manifests.has(id)) {
throw new Error(`Duplicate channel manifest id '${id}'`);
}

this.manifests.set(id, manifest);
return this;
}

get(channelId: MessagingChannelId): ChannelManifest | undefined {
return this.manifests.get(normalizeChannelId(channelId));
}

list(): ChannelManifest[] {
return Array.from(this.manifests.values());
}

listAvailable(ctx: ChannelManifestAvailabilityContext = {}): ChannelManifest[] {
const supportedChannelIds =
ctx.supportedChannelIds && ctx.supportedChannelIds.length > 0
? new Set(ctx.supportedChannelIds.map(normalizeChannelId))
: null;

return this.list().filter((manifest) => {
if (ctx.agent && !manifest.supportedAgents.includes(ctx.agent)) {
return false;
}
if (supportedChannelIds && !supportedChannelIds.has(manifest.id)) {
Comment thread
sandl99 marked this conversation as resolved.
Resolved
return false;
}
return true;
});
}
}

export function createChannelManifestRegistry(
manifests: readonly ChannelManifest[] = [],
): ChannelManifestRegistry {
return new ChannelManifestRegistry(manifests);
}

function normalizeChannelId(channelId: MessagingChannelId): MessagingChannelId {
return channelId.trim().toLowerCase();
}
Loading
Loading