(
result: AsyncGenerator<GenerateContentResponse, unknown, unknown>,
options: TextOptions<GeminiTextProviderOptions>,
logger: InternalLogger,
)
| 240 | } |
| 241 | |
| 242 | private async *processStreamChunks( |
| 243 | result: AsyncGenerator<GenerateContentResponse, unknown, unknown>, |
| 244 | options: TextOptions<GeminiTextProviderOptions>, |
| 245 | logger: InternalLogger, |
| 246 | ): AsyncIterable<StreamChunk> { |
| 247 | const model = options.model |
| 248 | let accumulatedContent = '' |
| 249 | let accumulatedThinking = '' |
| 250 | const toolCallMap = new Map< |
| 251 | string, |
| 252 | { |
| 253 | name: string |
| 254 | args: string |
| 255 | index: number |
| 256 | started: boolean |
| 257 | thoughtSignature?: string |
| 258 | } |
| 259 | >() |
| 260 | let nextToolIndex = 0 |
| 261 | |
| 262 | // AG-UI lifecycle tracking |
| 263 | const runId = options.runId ?? generateId(this.name) |
| 264 | const threadId = options.threadId ?? generateId(this.name) |
| 265 | const messageId = generateId(this.name) |
| 266 | let stepId: string | null = null |
| 267 | let reasoningMessageId: string | null = null |
| 268 | let hasClosedReasoning = false |
| 269 | let hasEmittedRunStarted = false |
| 270 | let hasEmittedTextMessageStart = false |
| 271 | let hasEmittedStepStarted = false |
| 272 | |
| 273 | for await (const chunk of result) { |
| 274 | logger.provider(`provider=gemini`, { chunk }) |
| 275 | // Emit RUN_STARTED on first chunk |
| 276 | if (!hasEmittedRunStarted) { |
| 277 | hasEmittedRunStarted = true |
| 278 | yield { |
| 279 | type: EventType.RUN_STARTED, |
| 280 | runId, |
| 281 | threadId, |
| 282 | model, |
| 283 | timestamp: Date.now(), |
| 284 | parentRunId: options.parentRunId, |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | if (chunk.candidates?.[0]?.content?.parts) { |
| 289 | const parts = chunk.candidates[0].content.parts |
| 290 | |
| 291 | for (const part of parts) { |
| 292 | if (part.text) { |
| 293 | if (part.thought) { |
| 294 | // Emit STEP_STARTED and REASONING events on first thinking content |
| 295 | if (!hasEmittedStepStarted) { |
| 296 | hasEmittedStepStarted = true |
| 297 | stepId = generateId(this.name) |
| 298 | reasoningMessageId = generateId(this.name) |
| 299 |
no test coverage detected