@reaatech/structured-function-calling-ai-adapter-google
Normalize tool calls to and from Google Gemini’s function-calling format.
Installation
pnpm add @reaatech/structured-function-calling-ai-adapter-googleAPI
toToolCall
function toToolCall(fc: GoogleFunctionCall): ToolCall;Converts a Google FunctionCall into a provider-agnostic ToolCall. Treats null/undefined args as an empty object {}. Note: Gemini does not provide a call ID in the request, so id is always an empty string.
GoogleFunctionCall is { name: string; args?: Record<string, unknown> | null }.
fromToolCallResult
function fromToolCallResult(tc: ToolCall, result: unknown): GoogleFunctionResponse;Converts a ToolCall and execution result into Google’s FunctionResponse shape. Note that the result is wrapped in a result key: { name: string, response: { result: unknown } }.
GoogleFunctionResponse is { name: string; response: Record<string, unknown> }.
toGoogleTools
function toGoogleTools(defs: readonly ToolDefinition[], opts?: GoogleAdapterOptions): GoogleTool;
type GoogleAdapterOptions = {
suppressAdditionalProperties?: boolean;
};Converts ToolDefinitions to Google’s FunctionDeclaration format. When opts.suppressAdditionalProperties is true, rejectedAdditionalProperties is explicitly set to false to suppress the additionalProperties keyword in the output schema. This is required for Gemini compatibility — Gemini does not accept additionalProperties in function declarations.
GoogleTool is { functionDeclarations: Array<{ name: string; description: string; parametersJsonSchema: Record<string, unknown> }> }.
Types
type ToolCall = { id: string; name: string; arguments: Record<string, unknown> };
type GoogleFunctionCall = { name: string; args?: Record<string, unknown> | null };
type GoogleFunctionResponse = { name: string; response: Record<string, unknown> };
type GoogleTool = { functionDeclarations: Array<{ name: string; description: string; parametersJsonSchema: Record<string, unknown> }> };Usage example
import { toToolCall, fromToolCallResult, toGoogleTools } from '@reaatech/structured-function-calling-ai-adapter-google';
// Convert from Gemini format
const toolCall = toToolCall({ name: 'get_weather', args: { city: 'NYC', units: 'metric' } });
// → { id: '', name: 'get_weather', arguments: { city: 'NYC', units: 'metric' } }
// Convert to Gemini tools (suppressing additionalProperties for Gemini compat)
const geminiTool = toGoogleTools(registry.list(), { suppressAdditionalProperties: true });
// → { functionDeclarations: [{ name: 'get_weather', description: '...', parametersJsonSchema: { $ref: '#/definitions/...' } }] }
// Note: additionalProperties keyword is absent from the schema
// Convert result back to Gemini format
const response = fromToolCallResult(toolCall, { temp: 22, conditions: 'sunny' });
// → { name: 'get_weather', response: { result: { temp: 22, conditions: 'sunny' } } }Dependencies
@reaatech/structured-function-calling-ai-core(workspace:*)
