@@ -73,56 +73,54 @@ export function validateAgents(
7373 }
7474 }
7575
76- try {
77- const agentKeys = Object . keys ( agentTemplates )
78-
79- // Pass 1: Collect all agent IDs from template files
80- const dynamicAgentIds = collectAgentIds ( agentTemplates )
81-
82- // Pass 2: Load and validate each agent template
83- for ( const agentKey of agentKeys ) {
84- try {
85- const content = agentTemplates [ agentKey ]
86- if ( ! content ) {
87- continue
88- }
76+ const agentKeys = Object . keys ( agentTemplates )
8977
90- const validationResult = validateSingleAgent (
91- dynamicAgentIds ,
92- content ,
93- agentKey ,
94- )
78+ // Pass 1: Collect all agent IDs from template files
79+ const dynamicAgentIds = collectAgentIds ( agentTemplates )
9580
96- if ( ! validationResult . success ) {
97- validationErrors . push ( {
98- filePath : agentKey ,
99- message : validationResult . error ! ,
100- } )
101- continue
102- }
81+ // Pass 2: Load and validate each agent template
82+ for ( const agentKey of agentKeys ) {
83+ try {
84+ const content = agentTemplates [ agentKey ]
85+ if ( ! content ) {
86+ continue
87+ }
10388
104- templates [ content . id ] = validationResult . agentTemplate !
105- } catch ( error ) {
106- const errorMessage =
107- error instanceof Error ? error . message : 'Unknown error'
89+ const validationResult = validateSingleAgent ( content , {
90+ filePath : agentKey ,
91+ dynamicAgentIds ,
92+ } )
10893
94+ if ( ! validationResult . success ) {
10995 validationErrors . push ( {
11096 filePath : agentKey ,
111- message : `Error in agent template ${ agentKey } : ${ errorMessage } ` ,
97+ message : validationResult . error ! ,
11298 } )
99+ continue
100+ }
113101
114- logger . warn (
115- { filePath : agentKey , error : errorMessage } ,
116- 'Failed to load dynamic agent template' ,
117- )
102+ if ( templates [ content . id ] ) {
103+ validationErrors . push ( {
104+ filePath : agentKey ,
105+ message : `Duplicate agent ID: ${ content . id } ` ,
106+ } )
107+ continue
118108 }
109+ templates [ content . id ] = validationResult . agentTemplate !
110+ } catch ( error ) {
111+ const errorMessage =
112+ error instanceof Error ? error . message : 'Unknown error'
113+
114+ validationErrors . push ( {
115+ filePath : agentKey ,
116+ message : `Error in agent template ${ agentKey } : ${ errorMessage } ` ,
117+ } )
118+
119+ logger . warn (
120+ { filePath : agentKey , error : errorMessage } ,
121+ 'Failed to load dynamic agent template' ,
122+ )
119123 }
120- } catch ( error ) {
121- logger . error ( { error } , 'Failed to process agent templates' )
122- validationErrors . push ( {
123- filePath : 'agentTemplates' ,
124- message : 'Failed to process agent templates' ,
125- } )
126124 }
127125
128126 return {
@@ -137,31 +135,44 @@ export function validateAgents(
137135 *
138136 * @param dynamicAgentIds - Array of all available dynamic agent IDs for validation
139137 * @param template - The dynamic agent template to validate
140- * @param filePath - Optional file path for error context
138+ * @param options - Optional configuration object
139+ * @param options.filePath - Optional file path for error context
140+ * @param options.skipSubagentValidation - Skip subagent validation when loading from database
141141 * @returns Validation result with either the converted AgentTemplate or an error
142142 */
143143export function validateSingleAgent (
144- dynamicAgentIds : string [ ] ,
145144 template : DynamicAgentTemplate ,
146- filePath ?: string ,
145+ options ?: {
146+ dynamicAgentIds ?: string [ ]
147+ filePath ?: string
148+ skipSubagentValidation ?: boolean
149+ } ,
147150) : {
148151 success : boolean
149152 agentTemplate ?: AgentTemplate
150153 error ?: string
151154} {
155+ const {
156+ filePath,
157+ skipSubagentValidation = false ,
158+ dynamicAgentIds = [ ] ,
159+ } = options || { }
160+
152161 try {
153- // Validate subagents
154- const subagentValidation = validateSubagents (
155- template . subagents ,
156- dynamicAgentIds ,
157- )
158- if ( ! subagentValidation . valid ) {
159- return {
160- success : false ,
161- error : formatSubagentError (
162- subagentValidation . invalidAgents ,
163- subagentValidation . availableAgents ,
164- ) ,
162+ // Validate subagents (skip if requested, e.g., for database agents)
163+ if ( ! skipSubagentValidation ) {
164+ const subagentValidation = validateSubagents (
165+ template . subagents ,
166+ dynamicAgentIds ,
167+ )
168+ if ( ! subagentValidation . valid ) {
169+ return {
170+ success : false ,
171+ error : formatSubagentError (
172+ subagentValidation . invalidAgents ,
173+ subagentValidation . availableAgents ,
174+ ) ,
175+ }
165176 }
166177 }
167178
@@ -254,11 +265,8 @@ export function validateSingleAgent(
254265 */
255266function isValidGeneratorFunction ( code : string ) : boolean {
256267 const trimmed = code . trim ( )
257- return (
258- trimmed . startsWith ( 'function*' ) ||
259- // Also allow arrow function generators
260- / ^ \s * \* \s * \( / . test ( trimmed )
261- )
268+ // Check if it's a generator function (must start with function*)
269+ return trimmed . startsWith ( 'function*' )
262270}
263271
264272/**
0 commit comments