( definitions: AgentDefinition[], options?: ValidateAgentsOptions, )
| 54 | * ``` |
| 55 | */ |
| 56 | export async function validateAgents( |
| 57 | definitions: AgentDefinition[], |
| 58 | options?: ValidateAgentsOptions, |
| 59 | ): Promise<ValidationResult> { |
| 60 | // Convert array of definitions to Record<string, AgentDefinition> format |
| 61 | // that the common validation functions expect |
| 62 | // Use index as key to preserve all entries (including duplicates) |
| 63 | const agentTemplates: Record<string, AgentDefinition> = {} |
| 64 | for (const [index, definition] of definitions.entries()) { |
| 65 | // Handle null/undefined gracefully |
| 66 | if (!definition) { |
| 67 | agentTemplates[`agent_${index}`] = definition |
| 68 | continue |
| 69 | } |
| 70 | // Use index to ensure duplicates aren't overwritten |
| 71 | const key = definition.id ? `${definition.id}_${index}` : `agent_${index}` |
| 72 | agentTemplates[key] = definition |
| 73 | } |
| 74 | |
| 75 | // Simple logger implementation for common validation functions |
| 76 | const logger = { |
| 77 | debug: () => {}, |
| 78 | info: () => {}, |
| 79 | warn: () => {}, |
| 80 | error: () => {}, |
| 81 | } |
| 82 | |
| 83 | let validationErrors: DynamicAgentValidationError[] = [] |
| 84 | |
| 85 | if (options?.remote) { |
| 86 | // Remote validation: call the web API |
| 87 | // Use provided websiteUrl or fall back to the default from environment |
| 88 | const websiteUrl = options.websiteUrl || WEBSITE_URL |
| 89 | |
| 90 | try { |
| 91 | const response = await fetch(`${websiteUrl}/api/agents/validate`, { |
| 92 | method: 'POST', |
| 93 | headers: { |
| 94 | 'Content-Type': 'application/json', |
| 95 | }, |
| 96 | body: JSON.stringify({ agentDefinitions: definitions }), |
| 97 | }) |
| 98 | |
| 99 | if (!response.ok) { |
| 100 | const errorData = await response.json().catch(() => ({})) |
| 101 | const errorMessage = |
| 102 | (errorData as any).error || |
| 103 | `HTTP ${response.status}: ${response.statusText}` |
| 104 | |
| 105 | return { |
| 106 | success: false, |
| 107 | validationErrors: [ |
| 108 | { |
| 109 | id: 'network_error', |
| 110 | message: `Failed to validate via API: ${errorMessage}`, |
| 111 | }, |
| 112 | ], |
| 113 | errorCount: 1, |
no test coverage detected