mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-02 23:23:45 +00:00
fix: transform MCP tool schemas for Google/Gemini compatibility (#4538)
Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: Github Action <action@github.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
This commit is contained in:
@@ -254,7 +254,7 @@ export namespace ProviderTransform {
|
||||
return standardLimit
|
||||
}
|
||||
|
||||
export function schema(_providerID: string, _modelID: string, schema: JSONSchema.BaseSchema) {
|
||||
export function schema(providerID: string, modelID: string, schema: JSONSchema.BaseSchema) {
|
||||
/*
|
||||
if (["openai", "azure"].includes(providerID)) {
|
||||
if (schema.type === "object" && schema.properties) {
|
||||
@@ -271,11 +271,40 @@ export namespace ProviderTransform {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (providerID === "google") {
|
||||
}
|
||||
*/
|
||||
|
||||
// Convert integer enums to string enums for Google/Gemini
|
||||
if (providerID === "google" || modelID.includes("gemini")) {
|
||||
const convertIntEnumsToStrings = (obj: any): any => {
|
||||
if (obj === null || typeof obj !== "object") {
|
||||
return obj
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(convertIntEnumsToStrings)
|
||||
}
|
||||
|
||||
const result: any = {}
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (key === "enum" && Array.isArray(value)) {
|
||||
// Convert all enum values to strings
|
||||
result[key] = value.map((v) => String(v))
|
||||
// If we have integer type with enum, change type to string
|
||||
if (result.type === "integer" || result.type === "number") {
|
||||
result.type = "string"
|
||||
}
|
||||
} else if (typeof value === "object" && value !== null) {
|
||||
result[key] = convertIntEnumsToStrings(value)
|
||||
} else {
|
||||
result[key] = value
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
schema = convertIntEnumsToStrings(schema)
|
||||
}
|
||||
|
||||
return schema
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user