import type { Command } from "./command"; export type CommandRegistry = { get(id: string): Command | undefined; list(): Command[]; }; export function createCommandRegistry(commands: Command[]): CommandRegistry { const byId = new Map>(); for (const command of commands) { if (byId.has(command.id)) { throw new Error(`Duplicate command id: ${command.id}`); } byId.set(command.id, command); } return { get: (id) => byId.get(id), list: () => [...byId.values()], }; }