UNPKG

@kya-os/cli

Version:

CLI for KYA-OS MCP-I setup and management

167 lines 6.62 kB
/** * Agent Card Component * Displays agent identity information in a beautiful card format */ import chalk from "chalk"; import { createBox } from "./box.js"; /** * Create an agent identity card */ export function createAgentCard(data) { const lines = []; const width = 72; // Header lines.push(chalk.cyan("╔" + "═".repeat(width - 2) + "╗")); lines.push(chalk.cyan("║") + chalk.bold.white(centerText(" AGENT IDENTITY CREATED", width - 2)) + chalk.cyan("║")); lines.push(chalk.cyan("╠" + "═".repeat(width - 2) + "╣")); lines.push(chalk.cyan("║" + " ".repeat(width - 2) + "║")); // Agent Name lines.push(chalk.cyan("║") + " " + chalk.bold("Agent Name: ") + chalk.yellow(data.name.padEnd(width - 16)) + chalk.cyan("║")); // Description if (data.description) { const descLines = wrapText(data.description, width - 18); lines.push(chalk.cyan("║") + " " + chalk.bold("Description: ") + chalk.gray(descLines[0].padEnd(width - 17)) + chalk.cyan("║")); for (let i = 1; i < descLines.length; i++) { lines.push(chalk.cyan("║") + " " + chalk.gray(descLines[i].padEnd(width - 18)) + chalk.cyan("║")); } } lines.push(chalk.cyan("║" + " ".repeat(width - 2) + "║")); // DID const didLines = wrapText(data.did, width - 10); lines.push(chalk.cyan("║") + " " + chalk.bold("DID: ") + chalk.green(didLines[0].padEnd(width - 9)) + chalk.cyan("║")); for (let i = 1; i < didLines.length; i++) { lines.push(chalk.cyan("║") + " " + chalk.green(didLines[i].padEnd(width - 10)) + chalk.cyan("║")); } lines.push(chalk.cyan("║" + " ".repeat(width - 2) + "║")); // Profile URL if (data.profileUrl || data.agentSlug) { const profileUrl = data.profileUrl || `https://knowthat.ai/agents/${data.agentSlug}`; lines.push(chalk.cyan("║") + " " + chalk.bold("Profile: ") + chalk.blue(profileUrl.padEnd(width - 13)) + chalk.cyan("║")); lines.push(chalk.cyan("║" + " ".repeat(width - 2) + "║")); } // Private Key Section (if provided) if (data.privateKey) { lines.push(chalk.cyan("║") + chalk.bold.red("PRIVATE KEY (KEEP SAFE!): ".padEnd(width - 2)) + chalk.cyan("║")); const keyLines = wrapText(data.privateKey, width - 10); for (const keyLine of keyLines) { lines.push(chalk.cyan("║") + chalk.red(keyLine.padEnd(width - 7)) + chalk.cyan("║")); } lines.push(chalk.cyan("║") + chalk.yellow("⚠️ This key controls your agent - never share it!".padEnd(width - 2)) + chalk.cyan("║")); lines.push(chalk.cyan("║" + " ".repeat(width - 2) + "║")); } // Claim URL Section (if provided) if (data.claimUrl) { lines.push(chalk.cyan("╠" + "═".repeat(width - 2) + "╣")); lines.push(chalk.cyan("║" + " ".repeat(width - 2) + "║")); lines.push(chalk.cyan("║") + chalk.bold.white("CLAIM YOUR AGENT NOW:".padEnd(width - 2)) + chalk.cyan("║")); lines.push(chalk.cyan("║" + " ".repeat(width - 2) + "║")); lines.push(chalk.cyan("╚" + "═".repeat(width - 2) + "╝")); lines.push(""); lines.push(chalk.cyan("Click to claim your agent:")); lines.push(chalk.cyan.underline(data.claimUrl)); lines.push(""); lines.push(chalk.cyan("╔" + "═".repeat(width - 2) + "╗")); lines.push(chalk.cyan("║" + " ".repeat(width - 2) + "║")); lines.push(chalk.cyan("║") + chalk.gray(" This link lets you manage your agent and add capabilities.".padEnd(width - 2)) + chalk.cyan("║")); lines.push(chalk.cyan("║" + " ".repeat(width - 2) + "║")); } // Footer lines.push(chalk.cyan("╠" + "═".repeat(width - 2) + "╣")); lines.push(chalk.cyan("║" + " ".repeat(width - 2) + "║")); lines.push(chalk.cyan("║") + chalk.bold.green("Agent successfully registered on the KYA-OS network".padEnd(width - 2)) + chalk.cyan("║")); lines.push(chalk.cyan("║") + chalk.gray(" Your AI agent now has a verifiable decentralized identity".padEnd(width - 2)) + chalk.cyan("║")); lines.push(chalk.cyan("║" + " ".repeat(width - 2) + "║")); lines.push(chalk.cyan("╚" + "═".repeat(width - 2) + "╝")); return lines.join("\n"); } /** * Create a compact agent card (without private key) */ export function createCompactAgentCard(data) { const content = []; content.push(chalk.bold("Agent Name: ") + chalk.yellow(data.name)); if (data.description) { content.push(chalk.bold("Description: ") + chalk.gray(data.description)); } content.push(""); content.push(chalk.bold("DID: ") + chalk.green(data.did)); if (data.profileUrl || data.agentSlug) { const profileUrl = data.profileUrl || `https://knowthat.ai/agents/${data.agentSlug}`; content.push(chalk.bold("Profile: ") + chalk.blue(profileUrl)); } return createBox(content, { title: "Agent Identity", style: "round", padding: 2, borderColor: "00ff00", }); } // Helper functions function stripAnsi(text) { // Simple ANSI code removal - matches most common ANSI escape sequences return text.replace(/\x1b\[[0-9;]*m/g, ""); } function centerText(text, width) { const textLength = stripAnsi(text).length; if (textLength >= width) return text; const totalPadding = width - textLength; const leftPadding = Math.floor(totalPadding / 2); const rightPadding = totalPadding - leftPadding; return " ".repeat(leftPadding) + text + " ".repeat(rightPadding); } function wrapText(text, width) { const words = text.split(" "); const lines = []; let currentLine = ""; for (const word of words) { if (currentLine.length + word.length + 1 <= width) { currentLine += (currentLine ? " " : "") + word; } else { if (currentLine) lines.push(currentLine); currentLine = word; } } if (currentLine) lines.push(currentLine); return lines.length > 0 ? lines : [""]; } //# sourceMappingURL=agent-card.js.map