UNPKG

@kya-os/cli

Version:

CLI for KYA-OS MCP-I setup and management

109 lines 3.13 kB
/** * Validation Schemas * Using Zod for runtime validation of CLI inputs */ import { z } from "zod"; /** * Agent name validation * - Must be 3-64 characters * - Only lowercase letters, numbers, and hyphens * - Must start with a letter * - Cannot end with a hyphen */ export const agentNameSchema = z .string() .min(3, "Agent name must be at least 3 characters") .max(64, "Agent name must be less than 64 characters") .regex(/^[a-z][a-z0-9-]*[a-z0-9]$/, "Agent name must start with a letter, contain only lowercase letters, numbers, and hyphens, and not end with a hyphen"); /** * Agent description validation */ export const agentDescriptionSchema = z .string() .min(1, "Description cannot be empty") .max(500, "Description must be less than 500 characters") .optional(); /** * Repository URL validation */ export const repositoryUrlSchema = z .string() .url("Invalid URL format") .regex(/^https?:\/\/(github\.com|gitlab\.com|bitbucket\.org)\/.+/, "Repository URL must be from GitHub, GitLab, or Bitbucket") .optional(); /** * DID validation */ export const didSchema = z .string() .regex(/^did:[a-z]+:[a-zA-Z0-9._\-]+/, "Invalid DID format"); /** * Environment variable validation */ export const envVariableSchema = z.object({ MCP_IDENTITY_AGENT_DID: didSchema, MCP_IDENTITY_AGENT_PUBLIC_KEY: z.string().min(1), MCP_IDENTITY_AGENT_PRIVATE_KEY: z.string().min(1), MCP_IDENTITY_AGENT_ID: z.string().min(1), MCP_IDENTITY_AGENT_SLUG: z.string().min(1), }); /** * Init command options validation */ export const initOptionsSchema = z.object({ name: agentNameSchema.optional(), description: agentDescriptionSchema.optional(), repository: repositoryUrlSchema.optional(), platform: z.string().optional(), skipRegistration: z.boolean().optional(), force: z.boolean().optional(), verbose: z.boolean().optional(), local: z.boolean().optional(), endpoint: z.string().url("Invalid endpoint URL").optional(), skipClaimCheck: z.boolean().optional(), }); /** * Platform validation */ export const platformSchema = z.enum([ "vercel", "nextjs", "netlify", "cloudflare", "aws-lambda", "heroku", "docker", "nodejs", "other", ]); /** * Directory configuration validation */ export const directoryConfigSchema = z.union([ z.literal("verified"), z.literal("none"), z.array(z.string().url()), ]); /** * Validate input with helpful error messages */ export function validateInput(schema, data, fieldName) { try { return schema.parse(data); } catch (error) { if (error instanceof z.ZodError) { const messages = error.errors.map((e) => ` • ${e.message}`).join("\n"); throw new Error(`Invalid ${fieldName}:\n${messages}`); } throw error; } } /** * Safe parse with default value */ export function safeParseWithDefault(schema, data, defaultValue) { const result = schema.safeParse(data); return result.success ? result.data : defaultValue; } //# sourceMappingURL=validation.js.map