Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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")).toBeUndefined();
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"]);
});
});
59 changes: 59 additions & 0 deletions src/lib/messaging/manifest/registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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 {
if (this.manifests.has(manifest.id)) {
throw new Error(`Duplicate channel manifest id '${manifest.id}'`);
}

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

get(channelId: MessagingChannelId): ChannelManifest | undefined {
return this.manifests.get(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)
: 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.
return false;
}
return true;
});
}
}

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