()
| 320 | * their custom agents without needing to modify the base agent definition. |
| 321 | */ |
| 322 | export const loadAgentDefinitions = (): AgentDefinition[] => { |
| 323 | // Start with bundled agents - these are the default Codebuff agents |
| 324 | const bundledAgents = getBundledAgents() |
| 325 | const definitions: AgentDefinition[] = Object.values(bundledAgents).map( |
| 326 | (def) => ({ ...def }), |
| 327 | ) |
| 328 | const bundledIds = new Set(Object.keys(bundledAgents)) |
| 329 | |
| 330 | // Get user agents from the SDK-loaded cache |
| 331 | const userAgentDefs = getUserAgentDefinitions() |
| 332 | const userAgentIds = userAgentDefs.map((def) => def.id) |
| 333 | |
| 334 | for (const agentDef of userAgentDefs) { |
| 335 | // User agents override bundled agents with the same ID |
| 336 | if (bundledIds.has(agentDef.id)) { |
| 337 | const idx = definitions.findIndex((d) => d.id === agentDef.id) |
| 338 | if (idx !== -1) { |
| 339 | definitions[idx] = { ...agentDef } |
| 340 | } |
| 341 | } else { |
| 342 | definitions.push({ ...agentDef }) |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | // Auto-add user agent IDs to spawnableAgents of base agents |
| 347 | // This allows users to spawn their custom agents without needing to |
| 348 | // explicitly add them to the base agent's spawnableAgents list |
| 349 | if (userAgentIds.length > 0) { |
| 350 | for (const def of definitions) { |
| 351 | // Consider any agent with an ID starting with 'base' as a base agent |
| 352 | if (def.id.startsWith('base') && def.spawnableAgents) { |
| 353 | const existingSpawnable = new Set(def.spawnableAgents) |
| 354 | for (const userAgentId of userAgentIds) { |
| 355 | if (!existingSpawnable.has(userAgentId)) { |
| 356 | def.spawnableAgents = [...def.spawnableAgents, userAgentId] |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | // Merge MCP servers from mcp.json into base agents |
| 364 | // This allows users to configure MCP tools that are available to the main agent |
| 365 | if (Object.keys(mcpServersCache).length > 0) { |
| 366 | for (const def of definitions) { |
| 367 | // Consider any agent with an ID starting with 'base' as a base agent |
| 368 | if (def.id.startsWith('base')) { |
| 369 | // Initialize mcpServers if not present |
| 370 | if (!def.mcpServers) { |
| 371 | def.mcpServers = {} |
| 372 | } |
| 373 | // Merge MCP servers (user config can override existing servers) |
| 374 | def.mcpServers = { |
| 375 | ...def.mcpServers, |
| 376 | ...mcpServersCache, |
| 377 | } |
| 378 | } |
| 379 | } |
no test coverage detected