fix(upstream): 完善边界检查和 thinking block 处理
基于 Gemini + Codex 审查结果的修复:
1. thinking block dummy signature 填充
- Gemini 模型现在会填充 dummyThoughtSignature
- 与 tool_use 处理逻辑保持一致
2. 边界检查增强
- buildTools: 跳过空工具名称
- buildTools: 为 nil schema 提供默认值
- convertClaudeToolsToGeminiTools: 为 nil params 提供默认值
3. 防止下游 API 验证错误
- 确保所有工具都有有效的 parameters
- 默认 schema: {type: 'object', properties: {}}
审查报告:Gemini 评分 95%, Codex 评分 8.2/10
This commit is contained in:
@@ -210,6 +210,9 @@ func buildParts(content json.RawMessage, toolIDToName map[string]string, allowDu
|
||||
// Claude 模型需要有效 signature,跳过无 signature 的 thinking block
|
||||
log.Printf("Warning: skipping thinking block without signature for Claude model")
|
||||
continue
|
||||
} else {
|
||||
// Gemini 模型使用 dummy signature
|
||||
part.ThoughtSignature = dummyThoughtSignature
|
||||
}
|
||||
parts = append(parts, part)
|
||||
|
||||
@@ -384,6 +387,12 @@ func buildTools(tools []ClaudeTool) []GeminiToolDeclaration {
|
||||
// 普通工具
|
||||
var funcDecls []GeminiFunctionDecl
|
||||
for _, tool := range tools {
|
||||
// 跳过无效工具名称
|
||||
if tool.Name == "" {
|
||||
log.Printf("Warning: skipping tool with empty name")
|
||||
continue
|
||||
}
|
||||
|
||||
var description string
|
||||
var inputSchema map[string]any
|
||||
|
||||
@@ -401,6 +410,14 @@ func buildTools(tools []ClaudeTool) []GeminiToolDeclaration {
|
||||
// 清理 JSON Schema
|
||||
params := cleanJSONSchema(inputSchema)
|
||||
|
||||
// 为 nil schema 提供默认值
|
||||
if params == nil {
|
||||
params = map[string]any{
|
||||
"type": "OBJECT",
|
||||
"properties": map[string]any{},
|
||||
}
|
||||
}
|
||||
|
||||
funcDecls = append(funcDecls, GeminiFunctionDecl{
|
||||
Name: tool.Name,
|
||||
Description: description,
|
||||
|
||||
@@ -2271,6 +2271,14 @@ func convertClaudeToolsToGeminiTools(tools any) []any {
|
||||
continue
|
||||
}
|
||||
|
||||
// 为 nil params 提供默认值
|
||||
if params == nil {
|
||||
params = map[string]any{
|
||||
"type": "object",
|
||||
"properties": map[string]any{},
|
||||
}
|
||||
}
|
||||
|
||||
funcDecls = append(funcDecls, map[string]any{
|
||||
"name": name,
|
||||
"description": desc,
|
||||
|
||||
Reference in New Issue
Block a user