style: interface{} → any (gofmt rewrite rule)
This commit is contained in:
@@ -40,7 +40,7 @@ type ClaudeMetadata struct {
|
|||||||
type ClaudeTool struct {
|
type ClaudeTool struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
InputSchema map[string]interface{} `json:"input_schema"`
|
InputSchema map[string]any `json:"input_schema"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SystemBlock system prompt 数组形式的元素
|
// SystemBlock system prompt 数组形式的元素
|
||||||
@@ -60,7 +60,7 @@ type ContentBlock struct {
|
|||||||
// tool_use
|
// tool_use
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Input interface{} `json:"input,omitempty"`
|
Input any `json:"input,omitempty"`
|
||||||
// tool_result
|
// tool_result
|
||||||
ToolUseID string `json:"tool_use_id,omitempty"`
|
ToolUseID string `json:"tool_use_id,omitempty"`
|
||||||
Content json.RawMessage `json:"content,omitempty"`
|
Content json.RawMessage `json:"content,omitempty"`
|
||||||
@@ -102,7 +102,7 @@ type ClaudeContentItem struct {
|
|||||||
// tool_use
|
// tool_use
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Input interface{} `json:"input,omitempty"`
|
Input any `json:"input,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClaudeUsage Claude 用量统计
|
// ClaudeUsage Claude 用量统计
|
||||||
|
|||||||
@@ -48,14 +48,14 @@ type GeminiInlineData struct {
|
|||||||
// GeminiFunctionCall Gemini 函数调用
|
// GeminiFunctionCall Gemini 函数调用
|
||||||
type GeminiFunctionCall struct {
|
type GeminiFunctionCall struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Args interface{} `json:"args,omitempty"`
|
Args any `json:"args,omitempty"`
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GeminiFunctionResponse Gemini 函数响应
|
// GeminiFunctionResponse Gemini 函数响应
|
||||||
type GeminiFunctionResponse struct {
|
type GeminiFunctionResponse struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Response map[string]interface{} `json:"response"`
|
Response map[string]any `json:"response"`
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ type GeminiToolDeclaration struct {
|
|||||||
type GeminiFunctionDecl struct {
|
type GeminiFunctionDecl struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Parameters map[string]interface{} `json:"parameters,omitempty"`
|
Parameters map[string]any `json:"parameters,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GeminiGoogleSearch Gemini Google 搜索工具
|
// GeminiGoogleSearch Gemini Google 搜索工具
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ func buildParts(content json.RawMessage, toolIDToName map[string]string, allowDu
|
|||||||
parts = append(parts, GeminiPart{
|
parts = append(parts, GeminiPart{
|
||||||
FunctionResponse: &GeminiFunctionResponse{
|
FunctionResponse: &GeminiFunctionResponse{
|
||||||
Name: funcName,
|
Name: funcName,
|
||||||
Response: map[string]interface{}{
|
Response: map[string]any{
|
||||||
"result": resultContent,
|
"result": resultContent,
|
||||||
},
|
},
|
||||||
ID: block.ToolUseID,
|
ID: block.ToolUseID,
|
||||||
@@ -290,7 +290,7 @@ func parseToolResultContent(content json.RawMessage, isError bool) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 尝试解析为数组
|
// 尝试解析为数组
|
||||||
var arr []map[string]interface{}
|
var arr []map[string]any
|
||||||
if err := json.Unmarshal(content, &arr); err == nil {
|
if err := json.Unmarshal(content, &arr); err == nil {
|
||||||
var texts []string
|
var texts []string
|
||||||
for _, item := range arr {
|
for _, item := range arr {
|
||||||
@@ -400,12 +400,12 @@ func buildTools(tools []ClaudeTool) []GeminiToolDeclaration {
|
|||||||
|
|
||||||
// cleanJSONSchema 清理 JSON Schema,移除 Antigravity/Gemini 不支持的字段
|
// cleanJSONSchema 清理 JSON Schema,移除 Antigravity/Gemini 不支持的字段
|
||||||
// 参考 proxycast 的实现,确保 schema 符合 JSON Schema draft 2020-12
|
// 参考 proxycast 的实现,确保 schema 符合 JSON Schema draft 2020-12
|
||||||
func cleanJSONSchema(schema map[string]interface{}) map[string]interface{} {
|
func cleanJSONSchema(schema map[string]any) map[string]any {
|
||||||
if schema == nil {
|
if schema == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cleaned := cleanSchemaValue(schema)
|
cleaned := cleanSchemaValue(schema)
|
||||||
result, ok := cleaned.(map[string]interface{})
|
result, ok := cleaned.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -417,13 +417,13 @@ func cleanJSONSchema(schema map[string]interface{}) map[string]interface{} {
|
|||||||
|
|
||||||
// 确保有 properties 字段(默认空对象)
|
// 确保有 properties 字段(默认空对象)
|
||||||
if _, hasProps := result["properties"]; !hasProps {
|
if _, hasProps := result["properties"]; !hasProps {
|
||||||
result["properties"] = make(map[string]interface{})
|
result["properties"] = make(map[string]any)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证 required 中的字段都存在于 properties 中
|
// 验证 required 中的字段都存在于 properties 中
|
||||||
if required, ok := result["required"].([]interface{}); ok {
|
if required, ok := result["required"].([]any); ok {
|
||||||
if props, ok := result["properties"].(map[string]interface{}); ok {
|
if props, ok := result["properties"].(map[string]any); ok {
|
||||||
validRequired := make([]interface{}, 0, len(required))
|
validRequired := make([]any, 0, len(required))
|
||||||
for _, r := range required {
|
for _, r := range required {
|
||||||
if reqName, ok := r.(string); ok {
|
if reqName, ok := r.(string); ok {
|
||||||
if _, exists := props[reqName]; exists {
|
if _, exists := props[reqName]; exists {
|
||||||
@@ -471,10 +471,10 @@ var excludedSchemaKeys = map[string]bool{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cleanSchemaValue 递归清理 schema 值
|
// cleanSchemaValue 递归清理 schema 值
|
||||||
func cleanSchemaValue(value interface{}) interface{} {
|
func cleanSchemaValue(value any) any {
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
result := make(map[string]interface{})
|
result := make(map[string]any)
|
||||||
for k, val := range v {
|
for k, val := range v {
|
||||||
// 跳过不支持的字段
|
// 跳过不支持的字段
|
||||||
if excludedSchemaKeys[k] {
|
if excludedSchemaKeys[k] {
|
||||||
@@ -492,9 +492,9 @@ func cleanSchemaValue(value interface{}) interface{} {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
case []interface{}:
|
case []any:
|
||||||
// 递归处理数组中的每个元素
|
// 递归处理数组中的每个元素
|
||||||
cleaned := make([]interface{}, 0, len(v))
|
cleaned := make([]any, 0, len(v))
|
||||||
for _, item := range v {
|
for _, item := range v {
|
||||||
cleaned = append(cleaned, cleanSchemaValue(item))
|
cleaned = append(cleaned, cleanSchemaValue(item))
|
||||||
}
|
}
|
||||||
@@ -506,11 +506,11 @@ func cleanSchemaValue(value interface{}) interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cleanTypeValue 处理 type 字段,转换为大写
|
// cleanTypeValue 处理 type 字段,转换为大写
|
||||||
func cleanTypeValue(value interface{}) interface{} {
|
func cleanTypeValue(value any) any {
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case string:
|
case string:
|
||||||
return strings.ToUpper(v)
|
return strings.ToUpper(v)
|
||||||
case []interface{}:
|
case []any:
|
||||||
// 联合类型 ["string", "null"] -> 取第一个非 null 类型
|
// 联合类型 ["string", "null"] -> 取第一个非 null 类型
|
||||||
for _, t := range v {
|
for _, t := range v {
|
||||||
if ts, ok := t.(string); ok && ts != "null" {
|
if ts, ok := t.(string); ok && ts != "null" {
|
||||||
|
|||||||
Reference in New Issue
Block a user