{"version":3,"sources":["../src/llm.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type * as types from '@google/genai';\nimport { FunctionCallingConfigMode, type GenerateContentConfig, GoogleGenAI } from '@google/genai';\nimport type { APIConnectOptions } from '@livekit/agents';\nimport {\n  APIConnectionError,\n  APIStatusError,\n  DEFAULT_API_CONNECT_OPTIONS,\n  llm,\n  shortuuid,\n} from '@livekit/agents';\nimport type { ChatModels } from './models.js';\nimport type { LLMTools } from './tools.js';\nimport { toFunctionDeclarations } from './utils.js';\n\ninterface GoogleFormatData {\n  systemMessages: string[] | null;\n}\n\nexport interface LLMOptions {\n  model: string | ChatModels;\n  apiKey?: string;\n  temperature?: number;\n  toolChoice?: llm.ToolChoice;\n  vertexai?: boolean;\n  project?: string;\n  location?: string;\n  maxOutputTokens?: number;\n  topP?: number;\n  topK?: number;\n  presencePenalty?: number;\n  frequencyPenalty?: number;\n  thinkingConfig?: types.ThinkingConfig;\n  automaticFunctionCallingConfig?: types.AutomaticFunctionCallingConfig;\n  geminiTools?: LLMTools;\n  httpOptions?: types.HttpOptions;\n  seed?: number;\n  serviceTier?: types.ServiceTier;\n  mediaResolution?: types.MediaResolution;\n}\n\nexport class LLM extends llm.LLM {\n  #opts: LLMOptions;\n  #client: GoogleGenAI;\n\n  label(): string {\n    return 'google.LLM';\n  }\n\n  get model(): string {\n    return this.#opts.model;\n  }\n\n  get provider(): string {\n    if (this.#opts.vertexai) {\n      return 'Vertex AI';\n    }\n    return 'Gemini';\n  }\n\n  /**\n   * Create a new instance of Google GenAI LLM.\n   *\n   * Environment Requirements:\n   * - For VertexAI: Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of the service account key file or use any of the other Google Cloud auth methods.\n   * The Google Cloud project and location can be set via `project` and `location` arguments or the environment variables\n   * `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION`. By default, the project is inferred from the service account key file,\n   * and the location defaults to \"us-central1\".\n   * - For Google Gemini API: Set the `apiKey` argument or the `GOOGLE_API_KEY` environment variable.\n   *\n   * @param model - The model name to use. Defaults to \"gemini-2.0-flash-001\".\n   * @param apiKey - The API key for Google Gemini. If not provided, it attempts to read from the `GOOGLE_API_KEY` environment variable.\n   * @param vertexai - Whether to use VertexAI. If not provided, it attempts to read from the `GOOGLE_GENAI_USE_VERTEXAI` environment variable. Defaults to false.\n   * @param project - The Google Cloud project to use (only for VertexAI). Defaults to undefined.\n   * @param location - The location to use for VertexAI API requests. Default value is \"us-central1\".\n   * @param temperature - Sampling temperature for response generation. Defaults to undefined.\n   * @param maxOutputTokens - Maximum number of tokens to generate in the output. Defaults to undefined.\n   * @param topP - The nucleus sampling probability for response generation. Defaults to undefined.\n   * @param topK - The top-k sampling value for response generation. Defaults to undefined.\n   * @param presencePenalty - Penalizes the model for generating previously mentioned concepts. Defaults to undefined.\n   * @param frequencyPenalty - Penalizes the model for repeating words. Defaults to undefined.\n   * @param toolChoice - Specifies whether to use tools during response generation. Defaults to \"auto\".\n   * @param thinkingConfig - The thinking configuration for response generation. Gemini 3.1 models use `thinkingLevel`; Gemini 2.5 models use `thinkingBudget`. Defaults to undefined.\n   * @param automaticFunctionCallingConfig - The automatic function calling configuration for response generation. Defaults to undefined.\n   * @param geminiTools - The Gemini-specific tools to use for the session.\n   * @param httpOptions - The HTTP options to use for the session.\n   * @param seed - Random seed for reproducible results. Defaults to undefined.\n   * @param serviceTier - The service tier for the request (e.g. ServiceTier.PRIORITY). Defaults to undefined.\n   * @param mediaResolution - The media resolution for the request. Defaults to undefined.\n   */\n  constructor(\n    {\n      model,\n      apiKey,\n      vertexai,\n      project,\n      location,\n      temperature,\n      maxOutputTokens,\n      topP,\n      topK,\n      presencePenalty,\n      frequencyPenalty,\n      toolChoice,\n      thinkingConfig,\n      automaticFunctionCallingConfig,\n      geminiTools,\n      httpOptions,\n      seed,\n      serviceTier,\n      mediaResolution,\n    }: LLMOptions = {\n      model: 'gemini-2.0-flash-001',\n    },\n  ) {\n    super();\n\n    const useVertexAI =\n      vertexai ??\n      (process.env.GOOGLE_GENAI_USE_VERTEXAI === 'true' ||\n        process.env.GOOGLE_GENAI_USE_VERTEXAI === '1');\n\n    let gcpProject: string | undefined = project ?? process.env.GOOGLE_CLOUD_PROJECT;\n    let gcpLocation: string | undefined = location ?? process.env.GOOGLE_CLOUD_LOCATION;\n    let geminiApiKey: string | undefined = apiKey ?? process.env.GOOGLE_API_KEY;\n\n    if (useVertexAI) {\n      if (!gcpProject) {\n        // TODO(brian): use default_async to get the project ID\n        throw new Error(\n          'Project ID is required for Vertex AI. Set via project option or GOOGLE_CLOUD_PROJECT environment variable',\n        );\n      }\n      geminiApiKey = undefined;\n    } else {\n      gcpProject = undefined;\n      gcpLocation = undefined;\n      if (!geminiApiKey) {\n        throw new Error(\n          'API key is required for Google API either via apiKey or GOOGLE_API_KEY environment variable',\n        );\n      }\n    }\n\n    // Validate thinkingConfig\n    if (thinkingConfig?.thinkingBudget !== undefined) {\n      const budget = thinkingConfig.thinkingBudget;\n      if (budget < 0 || budget > 24576) {\n        throw new Error('thinkingBudget inside thinkingConfig must be between 0 and 24576');\n      }\n    }\n\n    const clientOptions: types.GoogleGenAIOptions = useVertexAI\n      ? {\n          vertexai: true,\n          project: gcpProject,\n          location: gcpLocation,\n        }\n      : {\n          apiKey: geminiApiKey,\n        };\n\n    this.#client = new GoogleGenAI(clientOptions);\n\n    this.#opts = {\n      model,\n      vertexai: useVertexAI,\n      project: gcpProject,\n      location: gcpLocation,\n      temperature,\n      maxOutputTokens,\n      topP,\n      topK,\n      presencePenalty,\n      frequencyPenalty,\n      toolChoice,\n      thinkingConfig,\n      automaticFunctionCallingConfig,\n      geminiTools,\n      httpOptions,\n      seed,\n      serviceTier,\n      mediaResolution,\n      apiKey,\n    };\n  }\n\n  chat({\n    chatCtx,\n    toolCtx,\n    connOptions = DEFAULT_API_CONNECT_OPTIONS,\n    toolChoice,\n    extraKwargs,\n    geminiTools,\n  }: {\n    chatCtx: llm.ChatContext;\n    toolCtx?: llm.ToolContext;\n    connOptions?: APIConnectOptions;\n    parallelToolCalls?: boolean;\n    toolChoice?: llm.ToolChoice;\n    extraKwargs?: Record<string, unknown>;\n    geminiTools?: LLMTools;\n  }): LLMStream {\n    const extras: GenerateContentConfig = { ...extraKwargs } as GenerateContentConfig;\n\n    if (this.#opts.httpOptions !== undefined && extras.httpOptions === undefined) {\n      extras.httpOptions = this.#opts.httpOptions;\n    }\n\n    toolChoice = toolChoice !== undefined ? toolChoice : this.#opts.toolChoice;\n\n    if (toolChoice) {\n      let geminiToolConfig: types.ToolConfig;\n\n      if (typeof toolChoice === 'object' && toolChoice.type === 'function') {\n        geminiToolConfig = {\n          functionCallingConfig: {\n            mode: FunctionCallingConfigMode.ANY,\n            allowedFunctionNames: [toolChoice.function.name],\n          },\n        };\n      } else if (toolChoice === 'required') {\n        const toolNames = llm.sortedToolNames(toolCtx);\n        geminiToolConfig = {\n          functionCallingConfig: {\n            mode: FunctionCallingConfigMode.ANY,\n            allowedFunctionNames: toolNames.length > 0 ? toolNames : undefined,\n          },\n        };\n      } else if (toolChoice === 'auto') {\n        geminiToolConfig = {\n          functionCallingConfig: {\n            mode: FunctionCallingConfigMode.AUTO,\n          },\n        };\n      } else if (toolChoice === 'none') {\n        geminiToolConfig = {\n          functionCallingConfig: {\n            mode: FunctionCallingConfigMode.NONE,\n          },\n        };\n      } else {\n        throw new Error(`Invalid tool choice: ${toolChoice}`);\n      }\n\n      extras.toolConfig = geminiToolConfig;\n    }\n\n    if (this.#opts.temperature !== undefined) {\n      extras.temperature = this.#opts.temperature;\n    }\n    if (this.#opts.maxOutputTokens !== undefined) {\n      extras.maxOutputTokens = this.#opts.maxOutputTokens;\n    }\n    if (this.#opts.topP !== undefined) {\n      extras.topP = this.#opts.topP;\n    }\n    if (this.#opts.topK !== undefined) {\n      extras.topK = this.#opts.topK;\n    }\n    if (this.#opts.presencePenalty !== undefined) {\n      extras.presencePenalty = this.#opts.presencePenalty;\n    }\n    if (this.#opts.frequencyPenalty !== undefined) {\n      extras.frequencyPenalty = this.#opts.frequencyPenalty;\n    }\n    if (this.#opts.seed !== undefined) {\n      extras.seed = this.#opts.seed;\n    }\n\n    if (this.#opts.thinkingConfig !== undefined) {\n      extras.thinkingConfig = this.#opts.thinkingConfig;\n    }\n\n    if (this.#opts.automaticFunctionCallingConfig !== undefined) {\n      extras.automaticFunctionCalling = this.#opts.automaticFunctionCallingConfig;\n    }\n\n    if (this.#opts.serviceTier !== undefined) {\n      extras.serviceTier = this.#opts.serviceTier;\n    }\n\n    if (this.#opts.mediaResolution !== undefined) {\n      extras.mediaResolution = this.#opts.mediaResolution;\n    }\n\n    geminiTools = geminiTools !== undefined ? geminiTools : this.#opts.geminiTools;\n\n    return new LLMStream(this, {\n      client: this.#client,\n      model: this.#opts.model,\n      chatCtx,\n      toolCtx,\n      connOptions,\n      geminiTools,\n      extraKwargs: extras,\n    });\n  }\n}\n\nconst BLOCKED_REASONS = [\n  'SAFETY',\n  'SPII',\n  'PROHIBITED_CONTENT',\n  'BLOCKLIST',\n  'LANGUAGE',\n  'RECITATION',\n];\n\nexport class LLMStream extends llm.LLMStream {\n  #client: GoogleGenAI;\n  #model: string;\n  #geminiTools?: LLMTools;\n  #extraKwargs: GenerateContentConfig;\n\n  constructor(\n    llm: LLM,\n    {\n      client,\n      model,\n      chatCtx,\n      toolCtx,\n      connOptions,\n      geminiTools,\n      extraKwargs,\n    }: {\n      client: GoogleGenAI;\n      model: string;\n      chatCtx: llm.ChatContext;\n      toolCtx?: llm.ToolContext;\n      connOptions: APIConnectOptions;\n      geminiTools?: LLMTools;\n      extraKwargs: GenerateContentConfig;\n    },\n  ) {\n    // Call base constructor with dev 1.0 object parameter pattern\n    super(llm, { chatCtx, toolCtx, connOptions });\n    this.#client = client;\n    this.#model = model;\n    this.#geminiTools = geminiTools;\n    this.#extraKwargs = extraKwargs;\n  }\n\n  protected async run(): Promise<void> {\n    let retryable = true;\n    const requestId = `google_${Date.now()}`;\n\n    try {\n      const [turns, extraData] = (await this.chatCtx.toProviderFormat('google')) as [\n        Record<string, unknown>[],\n        GoogleFormatData,\n      ];\n\n      const contents: types.Content[] = turns.map((turn: Record<string, unknown>) => ({\n        role: turn.role as types.Content['role'],\n        parts: turn.parts as types.Part[],\n      }));\n\n      const functionDeclarations = this.toolCtx ? toFunctionDeclarations(this.toolCtx) : undefined;\n      const tools =\n        functionDeclarations && functionDeclarations.length > 0\n          ? [{ functionDeclarations }]\n          : undefined;\n\n      let systemInstruction: types.Content | undefined = undefined;\n      if (extraData.systemMessages && extraData.systemMessages.length > 0) {\n        systemInstruction = {\n          parts: extraData.systemMessages.map((content: string) => ({ text: content })),\n        };\n      }\n\n      const httpOptions = {\n        ...this.#extraKwargs.httpOptions,\n        timeout: this.#extraKwargs.httpOptions?.timeout ?? Math.floor(this.connOptions.timeoutMs),\n      };\n\n      const response = await this.#client.models.generateContentStream({\n        model: this.#model,\n        contents,\n        config: {\n          ...this.#extraKwargs,\n          systemInstruction,\n          httpOptions,\n          tools,\n        },\n      });\n\n      for await (const chunk of response) {\n        if (chunk.promptFeedback) {\n          throw new APIStatusError({\n            message: `Prompt feedback error: ${JSON.stringify(chunk.promptFeedback)}`,\n            options: {\n              retryable: false,\n              requestId,\n            },\n          });\n        }\n\n        // Check for blocked reasons first — safety-blocked responses often lack content.parts,\n        // so this must run before the no-content guard to avoid wasting retries.\n        if (\n          chunk.candidates?.[0]?.finishReason &&\n          BLOCKED_REASONS.includes(chunk.candidates[0].finishReason)\n        ) {\n          throw new APIStatusError({\n            message: `Google LLM: generation blocked - ${chunk.candidates[0].finishReason}`,\n            options: {\n              retryable: false,\n              requestId,\n            },\n          });\n        }\n\n        if (!chunk.candidates || !chunk.candidates[0]?.content?.parts) {\n          this.logger.warn(`No content in the response: ${JSON.stringify(chunk)}`);\n          if (retryable) {\n            throw new APIStatusError({\n              message: 'Google LLM: no content in the response',\n              options: {\n                retryable: true,\n                requestId,\n              },\n            });\n          }\n          continue;\n        }\n\n        if (chunk.candidates.length > 1) {\n          this.logger.warn(\n            'Google LLM: there are multiple candidates in the response, returning response from the first one.',\n          );\n        }\n\n        const candidate = chunk.candidates[0];\n        const finishReason = candidate.finishReason;\n\n        let chunksYielded = false;\n        for (const part of candidate.content!.parts!) {\n          const chatChunk = this.#parsePart(requestId, part);\n          if (chatChunk) {\n            chunksYielded = true;\n            retryable = false;\n            this.queue.put(chatChunk);\n          }\n        }\n\n        if (finishReason === 'STOP' && !chunksYielded && retryable) {\n          throw new APIStatusError({\n            message: 'Google LLM: no response generated',\n            options: {\n              retryable,\n              requestId,\n            },\n          });\n        }\n\n        if (chunk.usageMetadata) {\n          const usage = chunk.usageMetadata;\n          this.queue.put({\n            id: requestId,\n            usage: {\n              completionTokens: usage.candidatesTokenCount || 0,\n              promptTokens: usage.promptTokenCount || 0,\n              promptCachedTokens: usage.cachedContentTokenCount || 0,\n              totalTokens: usage.totalTokenCount || 0,\n            },\n          });\n        }\n      }\n    } catch (error: unknown) {\n      if (error instanceof APIStatusError || error instanceof APIConnectionError) {\n        throw error;\n      }\n\n      const err = error as {\n        code?: number;\n        message?: string;\n        status?: string;\n        type?: string;\n      };\n\n      if (err.code && err.code >= 400 && err.code < 500) {\n        if (err.code === 429) {\n          throw new APIStatusError({\n            message: `Google LLM: Rate limit error - ${err.message || 'Unknown error'}`,\n            options: {\n              statusCode: 429,\n              retryable: true,\n            },\n          });\n        } else {\n          throw new APIStatusError({\n            message: `Google LLM: Client error (${err.code}) - ${err.message || 'Unknown error'}`,\n            options: {\n              statusCode: err.code,\n              retryable: false,\n            },\n          });\n        }\n      }\n\n      if (err.code && err.code >= 500) {\n        throw new APIStatusError({\n          message: `Google LLM: Server error (${err.code}) - ${err.message || 'Unknown error'}`,\n          options: {\n            statusCode: err.code,\n            retryable,\n          },\n        });\n      }\n\n      throw new APIConnectionError({\n        message: `Google LLM: API error - ${err.message || 'Unknown error'}`,\n        options: {\n          retryable,\n        },\n      });\n    }\n  }\n\n  #parsePart(id: string, part: types.Part): llm.ChatChunk | null {\n    if (part.functionCall) {\n      return {\n        id,\n        delta: {\n          role: 'assistant',\n          toolCalls: [\n            llm.FunctionCall.create({\n              callId: part.functionCall.id || shortuuid('function_call_'),\n              name: part.functionCall.name!,\n              args: JSON.stringify(part.functionCall.args!),\n              // Preserve thought signature for Gemini 3+ thinking mode\n              thoughtSignature: part.thoughtSignature,\n            }),\n          ],\n        },\n      };\n    }\n\n    if (!part.text) {\n      return null;\n    }\n\n    return {\n      id,\n      delta: {\n        content: part.text,\n        role: 'assistant',\n      },\n    };\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAAmF;AAEnF,oBAMO;AAGP,mBAAuC;AA4BhC,MAAM,YAAY,kBAAI,IAAI;AAAA,EAC/B;AAAA,EACA;AAAA,EAEA,QAAgB;AACd,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAEA,IAAI,WAAmB;AACrB,QAAI,KAAK,MAAM,UAAU;AACvB,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgCA,YACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAgB;AAAA,IACd,OAAO;AAAA,EACT,GACA;AACA,UAAM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