|
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
7 | | -import { |
8 | | - type Config, |
9 | | - GeminiChat, |
10 | | - GeminiEventType, |
11 | | -} from '@google/gemini-cli-core'; |
| 7 | +import { type Config, GeminiChat } from '@google/gemini-cli-core'; |
12 | 8 | import { |
13 | 9 | type Content, |
14 | 10 | type Part, |
@@ -191,27 +187,15 @@ export class GeminiApiClient { |
191 | 187 | console.log('[GeminiApiClient] Got stream from Gemini.'); |
192 | 188 | // Transform the event stream to a simpler StreamChunk stream |
193 | 189 | return (async function* (): AsyncGenerator<StreamChunk> { |
194 | | - for await (const event of geminiStream) { |
195 | | - switch (event.type) { |
196 | | - case GeminiEventType.Content: |
197 | | - if (event.value) { |
198 | | - yield { type: 'text', data: event.value }; |
199 | | - } |
200 | | - break; |
201 | | - case GeminiEventType.Thought: |
202 | | - const reasoningData: ReasoningData = { |
203 | | - reasoning: `${event.value.subject}: ${event.value.description}`, |
204 | | - }; |
205 | | - yield { type: 'reasoning', data: reasoningData }; |
206 | | - break; |
207 | | - case GeminiEventType.ToolCallRequest: |
208 | | - yield { type: 'tool_code', data: event.value }; |
209 | | - break; |
210 | | - // Ignore other event types for now |
211 | | - case GeminiEventType.ChatCompressed: |
212 | | - case GeminiEventType.Error: |
213 | | - case GeminiEventType.UserCancelled: |
214 | | - break; |
| 190 | + for await (const response of geminiStream) { |
| 191 | + const parts = response.candidates?.[0]?.content?.parts || []; |
| 192 | + for (const part of parts) { |
| 193 | + if (part.text) { |
| 194 | + yield { type: 'text', data: part.text }; |
| 195 | + } |
| 196 | + if (part.functionCall) { |
| 197 | + yield { type: 'tool_code', data: part.functionCall }; |
| 198 | + } |
215 | 199 | } |
216 | 200 | } |
217 | 201 | })(); |
|
0 commit comments