/**
 * Shared utilities for Gemini 3 native SDK support.
 *
 * Both GoogleAIStudioProvider and GoogleVertexProvider route Gemini 3 models
 * with tools to the native @google/genai SDK (bypassing the Vercel AI SDK)
 * in order to properly handle thought_signature in multi-turn tool calling.
 *
 * This module extracts the functions that are duplicated between the two
 * providers so they can share a single implementation.
 */
import { type Tool } from "ai";
import type { ThinkingConfig } from "../types/configTypes.js";
import type { CollectedChunkResult, NativeFunctionCall, NativeFunctionDeclaration, NativeFunctionResponse, NativeToolDeclarationsResult, NativeToolsConfig, TextChannel } from "../types/index.js";
export type { CollectedChunkResult, NativeFunctionCall, NativeFunctionDeclaration, NativeFunctionResponse, NativeToolDeclarationsResult, NativeToolsConfig, TextChannel, };
/**
 * Sanitize a JSON Schema for Gemini's proto-based API.
 *
 * Gemini cannot handle `anyOf`/`oneOf` union types in function declarations
 * because its proto format expects a single `type` field, not a list of types.
 * This function recursively converts unions to `string` type (the most
 * permissive primitive that can represent any value as text).
 *
 * Also removes `$schema`, `additionalProperties`, and `default` keys that
 * Gemini's proto format doesn't support.
 */
export declare function sanitizeSchemaForGemini(schema: Record<string, unknown>): Record<string, unknown>;
/**
 * Sanitize Vercel AI SDK tools for Gemini compatibility.
 *
 * For the Vercel AI SDK path (non-native), tool parameters are Zod schemas that
 * get converted to JSON Schema internally by @ai-sdk/google. This conversion
 * doesn't sanitize union types (anyOf/oneOf), causing Gemini proto errors.
 *
 * This function pre-converts each tool's Zod parameters to sanitized JSON Schema
 * and re-wraps with the Vercel AI SDK's jsonSchema() helper.
 */
export declare function sanitizeToolsForGemini(tools: Record<string, Tool>): {
    tools: Record<string, Tool>;
    dropped: string[];
};
export declare function normalizeToolsForJsonSchemaProvider(tools: Record<string, Tool>): {
    tools: Record<string, Tool>;
    normalized: string[];
};
/**
 * Convert Vercel AI SDK tools to @google/genai FunctionDeclarations and an execute map.
 *
 * This handles both Zod schemas and plain JSON Schema objects for tool parameters.
 */
export declare function buildNativeToolDeclarations(tools: Record<string, Tool>): NativeToolDeclarationsResult;
/**
 * Build the native @google/genai config object shared by stream and generate.
 */
export declare function buildNativeConfig(options: {
    temperature?: number;
    maxTokens?: number;
    systemPrompt?: string;
    thinkingConfig?: ThinkingConfig;
}, toolsConfig?: NativeToolsConfig): Record<string, unknown>;
/**
 * Compute a safe, clamped maxSteps value.
 */
export declare function computeMaxSteps(rawMaxSteps?: number): number;
/**
 * Process stream chunks to extract raw response parts, function calls, and usage metadata.
 *
 * Consumes the full async iterable and returns all collected data.
 */
export declare function collectStreamChunks(stream: AsyncIterable<{
    functionCalls?: NativeFunctionCall[];
    [key: string]: unknown;
}>): Promise<CollectedChunkResult>;
/**
 * Create a push-based text channel that bridges a background producer
 * (the agentic tool-calling loop) with an async-iterable consumer.
 *
 * This enables truly incremental streaming: text parts are yielded to the
 * caller as they arrive from the network, rather than being buffered until
 * the model finishes generating.
 */
export declare function createTextChannel(): TextChannel;
/**
 * Iterate a single stream step incrementally, pushing text parts to `channel`
 * as they arrive from the network while simultaneously accumulating the full
 * `CollectedChunkResult` needed for history and token accounting.
 *
 * Used for all steps (both intermediate tool-calling steps and the final
 * text-only step).  Text parts are pushed to the channel as they arrive,
 * enabling truly incremental streaming.  The complete `rawResponseParts`
 * (including thoughtSignature) are still returned at the end for use by
 * `pushModelResponseToHistory`.
 */
export declare function collectStreamChunksIncremental(stream: AsyncIterable<{
    functionCalls?: NativeFunctionCall[];
    [key: string]: unknown;
}>, channel: TextChannel): Promise<CollectedChunkResult>;
/**
 * Extract text from raw response parts, filtering out non-text parts
 * (thoughtSignature, functionCall) to avoid SDK warnings.
 */
export declare function extractTextFromParts(rawResponseParts: unknown[]): string;
/**
 * Execute a batch of native function calls with retry tracking and permanent failure detection.
 *
 * @param logLabel - Label for log messages (e.g. "[GoogleAIStudio]" or "[GoogleVertex]")
 * @param stepFunctionCalls - The function calls from the model
 * @param executeMap - Map of tool name to execute function
 * @param failedTools - Mutable map tracking per-tool failure counts
 * @param allToolCalls - Mutable array accumulating all tool call records
 * @param options - Optional settings for execution tracking and cancellation
 * @returns Array of function responses for conversation history
 */
export declare function executeNativeToolCalls(logLabel: string, stepFunctionCalls: NativeFunctionCall[], executeMap: Map<string, Tool["execute"]>, failedTools: Map<string, {
    count: number;
    lastError: string;
}>, allToolCalls: Array<{
    toolName: string;
    args: Record<string, unknown>;
}>, options?: {
    toolExecutions?: Array<{
        name: string;
        input: Record<string, unknown>;
        output: unknown;
    }>;
    abortSignal?: AbortSignal;
}): Promise<NativeFunctionResponse[]>;
/**
 * Handle maxSteps termination by producing a final text when the model
 * was still calling tools when the step limit was reached.
 *
 * @param logLabel - Label for log messages (e.g. "[GoogleAIStudio]" or "[GoogleVertex]")
 */
export declare function handleMaxStepsTermination(logLabel: string, step: number, maxSteps: number, finalText: string, lastStepText: string): string;
/**
 * Push model response parts to conversation history, preserving thoughtSignature
 * for Gemini 3 multi-turn tool calling.
 */
export declare function pushModelResponseToHistory(currentContents: Array<{
    role: string;
    parts: unknown[];
}>, rawResponseParts: unknown[], stepFunctionCalls: NativeFunctionCall[]): void;
