@@ -10,13 +10,12 @@ import type { CodebuffToolCall } from '@codebuff/common/tools/list'
1010import type { AgentTemplate } from '@codebuff/common/types/agent-template'
1111import type { CodebuffMessage } from '@codebuff/common/types/message'
1212import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
13- import type {
14- AgentState ,
15- AgentTemplateType ,
16- } from '@codebuff/common/types/session-state'
13+ import type { AgentState } from '@codebuff/common/types/session-state'
1714import type { ProjectFileContext } from '@codebuff/common/util/file'
1815import type { WebSocket } from 'ws'
1916
17+ import { getMatchingSpawn } from './spawn-agents'
18+
2019export const handleSpawnAgentInline = ( ( params : {
2120 previousToolCallFinished : Promise < void >
2221 toolCall : CodebuffToolCall < 'spawn_agent_inline' >
@@ -91,16 +90,21 @@ export const handleSpawnAgentInline = ((params: {
9190 }
9291
9392 const triggerSpawnAgentInline = async ( ) => {
94- const agentType = agentTypeStr as AgentTemplateType
95- const agentTemplate = await getAgentTemplate ( agentType , localAgentTemplates )
96-
93+ const agentTemplate = await getAgentTemplate (
94+ agentTypeStr ,
95+ localAgentTemplates ,
96+ )
9797 if ( ! agentTemplate ) {
9898 throw new Error ( `Agent type ${ agentTypeStr } not found.` )
9999 }
100100
101- if ( ! parentAgentTemplate . spawnableAgents . includes ( agentType ) ) {
101+ const agentType = getMatchingSpawn (
102+ parentAgentTemplate . spawnableAgents ,
103+ agentTypeStr ,
104+ )
105+ if ( ! agentType ) {
102106 throw new Error (
103- `Agent type ${ parentAgentTemplate . id } is not allowed to spawn child agent type ${ agentType } .` ,
107+ `Agent type ${ parentAgentTemplate . id } is not allowed to spawn child agent type ${ agentTypeStr } .` ,
104108 )
105109 }
106110
0 commit comments