UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

105 lines (104 loc) 4.54 kB
import { type LanguageModel, type Schema } from "ai"; import { type AIProviderName } from "../constants/enums.js"; import { BaseProvider } from "../core/baseProvider.js"; import type { ZodUnknownSchema, EnhancedGenerateResult, TextGenerationOptions, StreamOptions, StreamResult } from "../types/index.js"; /** * Google AI Studio provider implementation using BaseProvider * Migrated from original GoogleAIStudio class to new factory pattern * * @important Structured Output Limitation * Google Gemini models cannot combine function calling (tools) with structured * output (JSON schema). When using schemas with output.format: "json", you MUST * set disableTools: true. * * Error without disableTools: * "Function calling with a response mime type: 'application/json' is unsupported" * * This is a Google API limitation documented at: * https://ai.google.dev/gemini-api/docs/function-calling * * @example * ```typescript * // ✅ Correct usage with schemas * const provider = new GoogleAIStudioProvider("gemini-2.5-flash"); * const result = await provider.generate({ * input: { text: "Analyze data" }, * schema: MySchema, * output: { format: "json" }, * disableTools: true // Required * }); * ``` * * @note Gemini 3 Pro Preview (November 2025) will support combining tools + schemas * @note "Too many states for serving" errors can occur with complex schemas + tools. * Solution: Simplify schema or use disableTools: true */ export declare class GoogleAIStudioProvider extends BaseProvider { private credentials?; constructor(modelName?: string, sdk?: unknown, credentials?: { apiKey?: string; }); getProviderName(): AIProviderName; getDefaultModel(): string; /** * AI SDK model instance — no longer used. * All models are routed through native @google/genai SDK directly. */ getAISDKModel(): LanguageModel; protected formatProviderError(error: unknown): Error; /** * Overrides the BaseProvider's image generation method to implement it for Google AI. * This method calls the Google AI API to generate an image from a prompt. * @param options The generation options containing the prompt. * @returns A promise that resolves to the generation result, including the image data. */ protected executeImageGeneration(options: TextGenerationOptions): Promise<EnhancedGenerateResult>; /** * Detect image MIME type from buffer */ private detectImageType; /** * Estimate token count from text using centralized estimation with provider multipliers */ private estimateTokenCount; protected executeStream(options: StreamOptions, analysisSchema?: ZodUnknownSchema | Schema<unknown>): Promise<StreamResult>; /** * Execute stream using native @google/genai SDK * Uses @google/genai directly for all Gemini models (2.0, 2.5, 3.x) */ private executeNativeGemini3Stream; /** * Execute generate using native @google/genai SDK for Gemini 3 models * This bypasses @ai-sdk/google to properly handle thought_signature */ private executeNativeGemini3Generate; /** * Override generate to route Gemini 3 models with tools to native SDK */ generate(optionsOrPrompt: TextGenerationOptions | string): Promise<EnhancedGenerateResult | null>; /** * Emit `generation:end` so the Pipeline B observability listener creates * a `model.generation` span for native Google AI Studio generate calls. * Without this hand-off the native path silently disappears from * Pipeline B exporters (Langfuse, custom OTEL collectors). */ private emitPipelineBGenerationEvent; private executeAudioStreamViaGeminiLive; protected getDefaultEmbeddingModel(): string; /** * Generate embeddings for text using Google AI Studio embedding models * @param text - The text to embed * @param modelName - The embedding model to use (default: gemini-embedding-001) * @returns Promise resolving to the embedding vector */ embed(text: string, modelName?: string): Promise<number[]>; /** * Generate embeddings for multiple texts in a single batch * @param texts - The texts to embed * @param modelName - The embedding model to use (default: gemini-embedding-001) * @returns Promise resolving to an array of embedding vectors */ embedMany(texts: string[], modelName?: string): Promise<number[][]>; private getApiKey; } export default GoogleAIStudioProvider;