Skip to content

Commit 22b9ebf

Browse files
fix: 修复类型不匹配和枚举值比较错误
Co-authored-by: aider (vertex_ai/gemini-2.5-pro) <aider@aider.chat>
1 parent e18dafd commit 22b9ebf

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

packages/mcp-server/src/bridge/stream-transformer.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GenerateContentResponse } from '@google/genai';
1+
import { GenerateContentResponse, FinishReason } from '@google/genai';
22
import { randomUUID } from 'node:crypto';
33

44
// --- 更新的 OpenAI 响应结构接口 ---
@@ -87,7 +87,7 @@ export function createOpenAIStreamTransformer(
8787
enqueueChunk(controller, createChunk(delta));
8888
}
8989

90-
if (part.functionCall) {
90+
if (part.functionCall?.name) {
9191
const fc = part.functionCall;
9292
const callId = `call_${randomUUID()}`;
9393

@@ -130,15 +130,11 @@ export function createOpenAIStreamTransformer(
130130
}
131131
}
132132

133-
if (
134-
finishReason &&
135-
finishReason !== 'FINISH_REASON_UNSPECIFIED' &&
136-
finishReason !== 'NOT_SET'
137-
) {
133+
if (finishReason && finishReason !== 'FINISH_REASON_UNSPECIFIED') {
138134
const reason =
139-
finishReason === 'STOP'
135+
finishReason === FinishReason.STOP
140136
? 'stop'
141-
: finishReason === 'TOOL_CALL'
137+
: finishReason === FinishReason.TOOL_CALL
142138
? 'tool_calls'
143139
: finishReason.toLowerCase();
144140
enqueueChunk(controller, createChunk({}, reason));

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
type Tool,
1212
type FunctionDeclaration,
1313
type GenerateContentConfig,
14+
FunctionCallingConfigMode,
1415
} from '@google/genai';
1516
import {
1617
type OpenAIMessage,
@@ -134,7 +135,10 @@ export class GeminiApiClient {
134135
if (tool_choice && tool_choice !== 'auto') {
135136
generationConfig.toolConfig = {
136137
functionCallingConfig: {
137-
mode: tool_choice.type === 'function' ? 'ANY' : 'AUTO',
138+
mode:
139+
tool_choice.type === 'function'
140+
? FunctionCallingConfigMode.ANY
141+
: FunctionCallingConfigMode.AUTO,
138142
allowedFunctionNames: tool_choice.function
139143
? [tool_choice.function.name]
140144
: undefined,

0 commit comments

Comments
 (0)