|
|
|
|
|
import { sanitizeToolName, cleanParameters } from './utils.js'; |
|
|
import { setToolNameMapping } from './toolNameCache.js'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function convertSingleTool(name, description, parameters, sessionId, actualModelName) { |
|
|
const originalName = name; |
|
|
const safeName = sanitizeToolName(originalName); |
|
|
|
|
|
if (sessionId && actualModelName && safeName !== originalName) { |
|
|
setToolNameMapping(sessionId, actualModelName, safeName, originalName); |
|
|
} |
|
|
|
|
|
const rawParams = parameters || {}; |
|
|
const cleanedParams = cleanParameters(rawParams) || {}; |
|
|
if (cleanedParams.type === undefined) cleanedParams.type = 'object'; |
|
|
if (cleanedParams.type === 'object' && cleanedParams.properties === undefined) cleanedParams.properties = {}; |
|
|
|
|
|
return { |
|
|
name: safeName, |
|
|
description: description || '', |
|
|
parameters: cleanedParams |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function convertOpenAIToolsToAntigravity(openaiTools, sessionId, actualModelName) { |
|
|
if (!openaiTools || openaiTools.length === 0) return []; |
|
|
|
|
|
return openaiTools.map((tool) => { |
|
|
const func = tool.function || {}; |
|
|
const declaration = convertSingleTool( |
|
|
func.name, |
|
|
func.description, |
|
|
func.parameters, |
|
|
sessionId, |
|
|
actualModelName |
|
|
); |
|
|
|
|
|
return { |
|
|
functionDeclarations: [declaration] |
|
|
}; |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function convertClaudeToolsToAntigravity(claudeTools, sessionId, actualModelName) { |
|
|
if (!claudeTools || claudeTools.length === 0) return []; |
|
|
|
|
|
return claudeTools.map((tool) => { |
|
|
const declaration = convertSingleTool( |
|
|
tool.name, |
|
|
tool.description, |
|
|
tool.input_schema, |
|
|
sessionId, |
|
|
actualModelName |
|
|
); |
|
|
|
|
|
return { |
|
|
functionDeclarations: [declaration] |
|
|
}; |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function convertGeminiToolsToAntigravity(geminiTools, sessionId, actualModelName) { |
|
|
if (!geminiTools || geminiTools.length === 0) return []; |
|
|
|
|
|
return geminiTools.map((tool) => { |
|
|
|
|
|
if (tool.functionDeclarations) { |
|
|
return { |
|
|
functionDeclarations: tool.functionDeclarations.map(fd => |
|
|
convertSingleTool(fd.name, fd.description, fd.parameters, sessionId, actualModelName) |
|
|
) |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
if (tool.name) { |
|
|
const declaration = convertSingleTool( |
|
|
tool.name, |
|
|
tool.description, |
|
|
tool.parameters || tool.input_schema, |
|
|
sessionId, |
|
|
actualModelName |
|
|
); |
|
|
|
|
|
return { |
|
|
functionDeclarations: [declaration] |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
return tool; |
|
|
}); |
|
|
} |