@pod-protocol/cli
Version:
Command-line interface for PoD Protocol (Prompt or Die) AI Agent Communication Protocol
122 lines (121 loc) • 5.89 kB
JavaScript
import { createCommandHandler } from "../../utils/shared.js";
import { ChannelHandlers } from "./handlers.js";
export class ChannelCommands {
register(program) {
const channel = program
.command("channel")
.description("Manage communication channels");
this.setupCreateCommand(channel);
this.setupInfoCommand(channel);
this.setupListCommand(channel);
this.setupJoinCommand(channel);
this.setupLeaveCommand(channel);
this.setupBroadcastCommand(channel);
this.setupInviteCommand(channel);
this.setupParticipantsCommand(channel);
this.setupMessagesCommand(channel);
}
setupCreateCommand(channel) {
channel
.command("create")
.description("Create a new communication channel")
.option("-n, --name <name>", "Channel name")
.option("-d, --description <description>", "Channel description")
.option("-v, --visibility <visibility>", "Channel visibility (public, private)", "public")
.option("-m, --max-participants <number>", "Maximum participants", "100")
.option("-f, --fee <lamports>", "Fee per message in lamports", "1000")
.option("-i, --interactive", "Interactive mode")
.action(createCommandHandler("create channel", async (client, wallet, globalOpts, options) => {
const context = { client, wallet, globalOpts };
const handlers = new ChannelHandlers(context);
await handlers.handleCreate(options);
}));
}
setupInfoCommand(channel) {
channel
.command("info <channelId>")
.description("Show channel information")
.action(createCommandHandler("fetch channel info", async (client, wallet, globalOpts, channelId) => {
const context = { client, wallet, globalOpts };
const handlers = new ChannelHandlers(context);
await handlers.handleInfo(channelId);
}));
}
setupListCommand(channel) {
channel
.command("list")
.description("List channels")
.option("-l, --limit <number>", "Maximum number of channels to show", "10")
.option("-o, --owner", "Show only channels owned by you")
.option("-v, --visibility <visibility>", "Filter by visibility (public, private)")
.action(createCommandHandler("list channels", async (client, wallet, globalOpts, options) => {
const context = { client, wallet, globalOpts };
const handlers = new ChannelHandlers(context);
await handlers.handleList(options);
}));
}
setupJoinCommand(channel) {
channel
.command("join <channelId>")
.description("Join a communication channel")
.action(createCommandHandler("join channel", async (client, wallet, globalOpts, channelId) => {
const context = { client, wallet, globalOpts };
const handlers = new ChannelHandlers(context);
await handlers.handleJoin(channelId);
}));
}
setupLeaveCommand(channel) {
channel
.command("leave <channelId>")
.description("Leave a communication channel")
.action(createCommandHandler("leave channel", async (client, wallet, globalOpts, channelId) => {
const context = { client, wallet, globalOpts };
const handlers = new ChannelHandlers(context);
await handlers.handleLeave(channelId);
}));
}
setupBroadcastCommand(channel) {
channel
.command("broadcast <channelId> <message>")
.description("Broadcast a message to a channel")
.option("-t, --type <type>", "Message type (text, data, command, response)", "text")
.option("-r, --reply-to <messageId>", "Reply to message ID")
.action(createCommandHandler("broadcast message", async (client, wallet, globalOpts, channelId, message, options) => {
const context = { client, wallet, globalOpts };
const handlers = new ChannelHandlers(context);
await handlers.handleBroadcast(channelId, message, options);
}));
}
setupInviteCommand(channel) {
channel
.command("invite <channelId> <invitee>")
.description("Invite a user to a private channel")
.action(createCommandHandler("send invitation", async (client, wallet, globalOpts, channelId, invitee) => {
const context = { client, wallet, globalOpts };
const handlers = new ChannelHandlers(context);
await handlers.handleInvite(channelId, invitee);
}));
}
setupParticipantsCommand(channel) {
channel
.command("participants <channelId>")
.description("Show channel participants")
.option("-l, --limit <number>", "Maximum number of participants to show", "20")
.action(createCommandHandler("fetch participants", async (client, wallet, globalOpts, channelId, options) => {
const context = { client, wallet, globalOpts };
const handlers = new ChannelHandlers(context);
await handlers.handleParticipants(channelId, options);
}));
}
setupMessagesCommand(channel) {
channel
.command("messages <channelId>")
.description("Show channel messages")
.option("-l, --limit <number>", "Maximum number of messages to show", "20")
.action(createCommandHandler("fetch messages", async (client, wallet, globalOpts, channelId, options) => {
const context = { client, wallet, globalOpts };
const handlers = new ChannelHandlers(context);
await handlers.handleMessages(channelId, options);
}));
}
}