| 66 | |
| 67 | // Helper to simulate LLM responses (sequence of tool calls over multiple turns) |
| 68 | const createMockStream = ( |
| 69 | functionCallsList: Array<FunctionCall[] | 'stop'>, |
| 70 | ) => { |
| 71 | let index = 0; |
| 72 | return vi.fn().mockImplementation(() => { |
| 73 | const response = functionCallsList[index] || 'stop'; |
| 74 | index++; |
| 75 | return (async function* () { |
| 76 | if (response === 'stop') { |
| 77 | // When stopping, the model might return text, but the subagent logic primarily cares about the absence of functionCalls. |
| 78 | yield { text: 'Done.' }; |
| 79 | } else if (response.length > 0) { |
| 80 | yield { functionCalls: response }; |
| 81 | } else { |
| 82 | yield { text: 'Done.' }; // Handle empty array also as stop |
| 83 | } |
| 84 | })(); |
| 85 | }); |
| 86 | }; |
| 87 | |
| 88 | describe('subagent.ts', () => { |
| 89 | describe('ContextState', () => { |