UNPKG

@kya-os/cli

Version:

CLI for KYA-OS MCP-I setup and management

341 lines 10.2 kB
/** * Agent Table Component * Displays agent identity information using cli-table3 for better presentation */ import Table from "cli-table3"; import chalk from "chalk"; import { showAgentAvatar, getAvatarEmoji } from "./agent-avatar.js"; /** * Create an agent identity table */ export function createAgentTable(data) { // Create table with custom styling const table = new Table({ head: [], style: { head: [], border: ["white"], "padding-left": 2, "padding-right": 2, }, chars: { top: "═", "top-mid": "╤", "top-left": "╔", "top-right": "╗", bottom: "═", "bottom-mid": "╧", "bottom-left": "╚", "bottom-right": "╝", left: "║", "left-mid": "╟", mid: "─", "mid-mid": "┼", right: "║", "right-mid": "╢", middle: "│", }, colWidths: [20, 60], wordWrap: true, }); // Add title row table.push([ { colSpan: 2, content: chalk.bold.white("AGENT IDENTITY CREATED"), hAlign: "center", }, ]); // Add agent details table.push([chalk.bold("Agent Name"), chalk.white(data.name)], [chalk.bold("Description"), chalk.gray(data.description || "N/A")]); // Add separator table.push([{ colSpan: 2, content: "" }]); // Add DID with proper wrapping table.push([chalk.bold("DID"), chalk.white(data.did)]); // Add profile URL if available if (data.profileUrl || data.agentSlug) { const profileUrl = data.profileUrl || `https://knowthat.ai/agents/${data.agentSlug}`; table.push([chalk.bold("Profile"), chalk.white(profileUrl)]); } // If private key is provided, add it with warning if (data.privateKey) { table.push([{ colSpan: 2, content: "" }]); table.push([ { colSpan: 2, content: chalk.bold.white("PRIVATE KEY (KEEP SAFE!)"), hAlign: "center", }, ]); table.push([ { colSpan: 2, content: chalk.gray(data.privateKey), hAlign: "left", }, ]); table.push([ { colSpan: 2, content: chalk.gray("This key controls your agent - never share it"), hAlign: "center", }, ]); } // Add success message table.push([{ colSpan: 2, content: "" }]); table.push([ { colSpan: 2, content: chalk.bold.white("Agent successfully registered on the KYA-OS network"), hAlign: "center", }, ]); table.push([ { colSpan: 2, content: chalk.gray("Your AI agent now has a verifiable decentralized identity"), hAlign: "center", }, ]); return table.toString(); } /** * Create a compact agent info table (for check command) */ export function createCompactAgentTable(data) { const table = new Table({ style: { head: [], border: ["green"], }, chars: { top: "─", "top-mid": "┬", "top-left": "╭", "top-right": "╮", bottom: "─", "bottom-mid": "┴", "bottom-left": "╰", "bottom-right": "╯", left: "│", "left-mid": "├", mid: "─", "mid-mid": "┼", right: "│", "right-mid": "┤", middle: "│", }, colWidths: [15, 50], wordWrap: true, }); table.push([chalk.bold("Agent"), chalk.yellow(data.name)], [chalk.bold("DID"), chalk.green(data.did)]); if (data.profileUrl || data.agentSlug) { const profileUrl = data.profileUrl || `https://knowthat.ai/agents/${data.agentSlug}`; table.push([chalk.bold("Profile"), chalk.white(profileUrl)]); } return table.toString(); } /** * Create claim URL table with interactive prompt */ export function createClaimTable(data) { const table = new Table({ style: { head: [], border: ["white"], }, chars: { top: "═", "top-mid": "╤", "top-left": "╔", "top-right": "╗", bottom: "═", "bottom-mid": "╧", "bottom-left": "╚", "bottom-right": "╝", left: "║", "left-mid": "╟", mid: "─", "mid-mid": "┼", right: "║", "right-mid": "╢", middle: "│", }, colWidths: [70], wordWrap: true, }); table.push([ { content: chalk.bold.white("CLAIM YOUR AGENT NOW"), hAlign: "center", }, ]); table.push([{ content: "" }]); table.push([ { content: chalk.bold.white("Click to claim your agent:"), hAlign: "center", }, ]); table.push([ { content: chalk.white.underline(data.claimUrl), hAlign: "center", }, ]); table.push([{ content: "" }]); table.push([ { content: chalk.gray("This link lets you manage your agent and add capabilities."), hAlign: "center", }, ]); table.push([{ content: "" }]); table.push([ { content: chalk.bold.white("Press Enter to open in your browser"), hAlign: "center", }, ]); return table.toString(); } /** * Create an agent identity table with optional avatar */ export async function createAgentTableWithAvatar(data, options) { const { showAvatar = true, claimed = false, verified = false, hasGithub = false, hasDescription = !!data.description, handshakeComplete = false, } = options || {}; if (!showAvatar) { return createAgentTable(data); } // Create table with custom styling const table = new Table({ style: { head: [], border: ["white"], "padding-left": 2, "padding-right": 2, }, chars: { top: "═", "top-mid": "╤", "top-left": "╔", "top-right": "╗", bottom: "═", "bottom-mid": "╧", "bottom-left": "╚", "bottom-right": "╝", left: "║", "left-mid": "╟", mid: "─", "mid-mid": "┼", right: "║", "right-mid": "╢", middle: "│", }, colWidths: [30, 50], wordWrap: true, }); // Add header with title table.push([ { colSpan: 2, content: chalk.bold.white("AGENT IDENTITY CREATED"), hAlign: "center", }, ]); // Try to add avatar row try { const avatarDisplay = await showAgentAvatar({ did: data.did, claimed, width: "20%", height: "20%", level: { claimed, verified, hasGithub, hasDescription, handshakeComplete, }, }); table.push([ { content: avatarDisplay, hAlign: "center", vAlign: "center", }, { content: `${chalk.bold("Agent Name")}: ${chalk.yellow(data.name)}\n${chalk.bold("Status")}: ${claimed ? chalk.green("✓ CLAIMED") : chalk.yellow("UNCLAIMED")}\n${chalk.bold("Description")}: ${chalk.gray(data.description || "N/A")}`, vAlign: "center", }, ]); } catch (error) { // Fallback to emoji if avatar fails const emoji = getAvatarEmoji(claimed); table.push([ { content: ` ${emoji}\n${claimed ? chalk.green("✓ CLAIMED") : chalk.yellow("UNCLAIMED")}`, hAlign: "center", vAlign: "center", }, { content: `${chalk.bold("Agent Name")}: ${chalk.yellow(data.name)}\n${chalk.bold("Description")}: ${chalk.gray(data.description || "N/A")}`, vAlign: "center", }, ]); } // Add separator table.push([{ colSpan: 2, content: "" }]); // Add DID with proper wrapping table.push([chalk.bold("DID"), chalk.white(data.did)]); // Add profile URL if available if (data.profileUrl || data.agentSlug) { const profileUrl = data.profileUrl || `https://knowthat.ai/agents/${data.agentSlug}`; table.push([chalk.bold("Profile"), chalk.white(profileUrl)]); } // If private key is provided, add it with warning if (data.privateKey) { table.push([{ colSpan: 2, content: "" }]); table.push([ { colSpan: 2, content: chalk.bold.red("🔐 PRIVATE KEY (KEEP SAFE!)"), hAlign: "center", }, ]); table.push([ { colSpan: 2, content: chalk.gray(data.privateKey), hAlign: "left", }, ]); table.push([ { colSpan: 2, content: chalk.gray("This key controls your agent - never share it"), hAlign: "center", }, ]); } // Add success message table.push([{ colSpan: 2, content: "" }]); table.push([ { colSpan: 2, content: chalk.bold.green("Agent successfully registered on the KYA-OS network"), hAlign: "center", }, ]); table.push([ { colSpan: 2, content: chalk.gray("Your AI agent now has a verifiable decentralized identity"), hAlign: "center", }, ]); return table.toString(); } //# sourceMappingURL=agent-table.js.map