Skip to content

Commit 005c6e1

Browse files
fix: 修正 Gemini 流处理逻辑
Co-authored-by: aider (vertex_ai/gemini-2.5-pro) <aider@aider.chat>
1 parent 8932b8f commit 005c6e1

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

packages/mcp-server/src/gemini-client.ts

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

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';
128
import {
139
type Content,
1410
type Part,
@@ -191,27 +187,15 @@ export class GeminiApiClient {
191187
console.log('[GeminiApiClient] Got stream from Gemini.');
192188
// Transform the event stream to a simpler StreamChunk stream
193189
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+
}
215199
}
216200
}
217201
})();

0 commit comments

Comments
 (0)