@@ -24,14 +24,15 @@ import * as aisdk from '../llm-apis/vercel-ai-sdk/ai-sdk'
2424import * as liveUserInputs from '../live-user-inputs'
2525import { runAgentStep } from '../run-agent-step'
2626import { clearAgentGeneratorCache } from '../run-programmatic-step'
27- import { assembleLocalAgentTemplates } from '../templates/agent-registry'
2827import * as websocketAction from '../websockets/websocket-action'
2928
3029import type { AgentTemplate } from '../templates/types'
3130import type { ProjectFileContext } from '@codebuff/common/util/file'
3231import type { WebSocket } from 'ws'
3332
3433describe ( 'runAgentStep - set_output tool' , ( ) => {
34+ let testAgent : AgentTemplate
35+
3536 beforeAll ( ( ) => {
3637 // Mock logger
3738 mockModule ( '@codebuff/backend/util/logger' , ( ) => ( {
@@ -46,6 +47,22 @@ describe('runAgentStep - set_output tool', () => {
4647 } )
4748
4849 beforeEach ( async ( ) => {
50+ // Create a test agent that supports set_output
51+ testAgent = {
52+ id : 'test-set-output-agent' ,
53+ displayName : 'Test Set Output Agent' ,
54+ parentPrompt : 'Testing set_output functionality' ,
55+ model : 'claude-3-5-sonnet-20241022' ,
56+ inputSchema : { } ,
57+ outputMode : 'structured_output' as const ,
58+ includeMessageHistory : true ,
59+ toolNames : [ 'set_output' , 'end_turn' ] ,
60+ subagents : [ ] ,
61+ systemPrompt : 'Test system prompt' ,
62+ instructionsPrompt : 'Test instructions prompt' ,
63+ stepPrompt : 'Test agent step prompt' ,
64+ }
65+
4966 // Mock analytics and tracing
5067 spyOn ( analytics , 'initAnalytics' ) . mockImplementation ( ( ) => { } )
5168 analytics . initAnalytics ( )
@@ -152,8 +169,9 @@ describe('runAgentStep - set_output tool', () => {
152169
153170 const sessionState = getInitialSessionState ( mockFileContext )
154171 const agentState = sessionState . mainAgentState
155- const { agentTemplates : localAgentTemplates } =
156- assembleLocalAgentTemplates ( mockFileContext )
172+ const localAgentTemplates = {
173+ 'test-set-output-agent' : testAgent ,
174+ }
157175
158176 const result = await runAgentStep (
159177 new MockWebSocket ( ) as unknown as WebSocket ,
@@ -163,7 +181,7 @@ describe('runAgentStep - set_output tool', () => {
163181 clientSessionId : 'test-session' ,
164182 fingerprintId : 'test-fingerprint' ,
165183 onResponseChunk : ( ) => { } ,
166- agentType : 'base ' ,
184+ agentType : 'test-set-output-agent ' ,
167185 fileContext : mockFileContext ,
168186 localAgentTemplates,
169187 agentState,
@@ -192,8 +210,9 @@ describe('runAgentStep - set_output tool', () => {
192210
193211 const sessionState = getInitialSessionState ( mockFileContext )
194212 const agentState = sessionState . mainAgentState
195- const { agentTemplates : localAgentTemplates } =
196- assembleLocalAgentTemplates ( mockFileContext )
213+ const localAgentTemplates = {
214+ 'test-set-output-agent' : testAgent ,
215+ }
197216
198217 const result = await runAgentStep (
199218 new MockWebSocket ( ) as unknown as WebSocket ,
@@ -203,7 +222,7 @@ describe('runAgentStep - set_output tool', () => {
203222 clientSessionId : 'test-session' ,
204223 fingerprintId : 'test-fingerprint' ,
205224 onResponseChunk : ( ) => { } ,
206- agentType : 'base ' ,
225+ agentType : 'test-set-output-agent ' ,
207226 fileContext : mockFileContext ,
208227 localAgentTemplates,
209228 agentState,
@@ -238,8 +257,9 @@ describe('runAgentStep - set_output tool', () => {
238257 existingField : 'original value' ,
239258 anotherField : 'unchanged' ,
240259 }
241- const { agentTemplates : localAgentTemplates } =
242- assembleLocalAgentTemplates ( mockFileContext )
260+ const localAgentTemplates = {
261+ 'test-set-output-agent' : testAgent ,
262+ }
243263
244264 const result = await runAgentStep (
245265 new MockWebSocket ( ) as unknown as WebSocket ,
@@ -249,7 +269,7 @@ describe('runAgentStep - set_output tool', () => {
249269 clientSessionId : 'test-session' ,
250270 fingerprintId : 'test-fingerprint' ,
251271 onResponseChunk : ( ) => { } ,
252- agentType : 'base ' ,
272+ agentType : 'test-set-output-agent ' ,
253273 fileContext : mockFileContext ,
254274 localAgentTemplates,
255275 agentState,
@@ -275,8 +295,9 @@ describe('runAgentStep - set_output tool', () => {
275295 const sessionState = getInitialSessionState ( mockFileContext )
276296 const agentState = sessionState . mainAgentState
277297 agentState . output = { existingField : 'value' }
278- const { agentTemplates : localAgentTemplates } =
279- assembleLocalAgentTemplates ( mockFileContext )
298+ const localAgentTemplates = {
299+ 'test-set-output-agent' : testAgent ,
300+ }
280301
281302 const result = await runAgentStep (
282303 new MockWebSocket ( ) as unknown as WebSocket ,
@@ -286,7 +307,7 @@ describe('runAgentStep - set_output tool', () => {
286307 clientSessionId : 'test-session' ,
287308 fingerprintId : 'test-fingerprint' ,
288309 onResponseChunk : ( ) => { } ,
289- agentType : 'base ' ,
310+ agentType : 'test-set-output-agent ' ,
290311 fileContext : mockFileContext ,
291312 localAgentTemplates,
292313 agentState,
@@ -362,7 +383,7 @@ describe('runAgentStep - set_output tool', () => {
362383 clientSessionId : 'test-session' ,
363384 fingerprintId : 'test-fingerprint' ,
364385 onResponseChunk : ( ) => { } ,
365- agentType : 'test-handlesteps-agent' as any ,
386+ agentType : 'test-handlesteps-agent' ,
366387 fileContext : mockFileContext ,
367388 localAgentTemplates : mockAgentRegistry ,
368389 agentState,
@@ -510,7 +531,7 @@ describe('runAgentStep - set_output tool', () => {
510531 clientSessionId : 'test-session' ,
511532 fingerprintId : 'test-fingerprint' ,
512533 onResponseChunk : ( ) => { } ,
513- agentType : 'parent-agent' as any ,
534+ agentType : 'parent-agent' ,
514535 fileContext : mockFileContext ,
515536 localAgentTemplates : mockAgentRegistry ,
516537 agentState,
0 commit comments