UNPKG

agentlang

Version:

The easiest way to build the most reliable AI agents - enterprise-grade teams of AI agents that collaborate with each other and humans

73 lines 2.73 kB
import { isStandaloneStatement, } from './generated/ast.js'; /** * Register custom validation checks. */ export function registerValidationChecks(services) { const registry = services.validation.ValidationRegistry; const validator = services.validation.AgentlangValidator; const checks = { ModuleDefinition: validator.checkUniqueDefs, SchemaDefinition: validator.checkUniqueAttributes, }; registry.register(checks, validator); } /** * Implementation of custom validations. */ export class AgentlangValidator { // our new validation function for defs checkUniqueDefs(module, accept) { // create a set of visited functions // and report an error when we see one we've already seen const reported = new Set(); module.defs.forEach(d => { let n; if (!isStandaloneStatement(d)) { if (d.$type === 'PublicWorkflowDefinition' || d.$type === 'PublicAgentDefinition' || d.$type === 'PublicEventDefinition') { n = d.def.name; } else { n = d.name; } if (d.$type != 'WorkflowDefinition' && d.$type != 'FlowDefinition' && d.$type != 'PublicWorkflowDefinition' && d.$type != 'ScenarioDefinition' && d.$type != 'DirectiveDefinition' && d.$type != 'GlossaryEntryDefinition' && reported.has(n)) { accept('error', `Definition has non-unique name '${n}'.`, { node: d, property: 'name', }); } if (d.$type != 'FlowDefinition' && d.$type != 'ScenarioDefinition' && d.$type != 'DirectiveDefinition' && d.$type != 'GlossaryEntryDefinition') { reported.add(n); } } }); } checkUniqueAttributes(def, accept) { // create a set of visited functions // and report an error when we see one we've already seen const reported = new Set(); if (def.$type === 'PublicEventDefinition') { def = def.def; } def.schema.attributes.forEach((a) => { if (reported.has(a.name)) { accept('error', `'${def.name} " - attribute has non-unique name '${a.name}'.`, { node: a, property: 'name', }); } reported.add(a.name); }); } } //# sourceMappingURL=agentlang-validator.js.map