{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Genkit, ModelReference } from 'genkit';\nimport { GenkitPlugin, genkitPlugin } from 'genkit/plugin';\nimport {\n  SUPPORTED_MODELS as EMBEDDER_MODELS,\n  defineGoogleAIEmbedder,\n  textEmbedding004,\n  textEmbeddingGecko001,\n} from './embedder.js';\nimport {\n  GeminiConfigSchema,\n  SUPPORTED_V15_MODELS,\n  SUPPORTED_V1_MODELS,\n  defineGoogleAIModel,\n  gemini,\n  gemini10Pro,\n  gemini15Flash,\n  gemini15Flash8b,\n  gemini15Pro,\n  gemini20Flash,\n  gemini20FlashExp,\n  gemini20FlashLite,\n  gemini20ProExp0205,\n  gemini25ProExp0325,\n  type GeminiConfig,\n  type GeminiVersionString,\n} from './gemini.js';\nexport {\n  gemini,\n  gemini10Pro,\n  gemini15Flash,\n  gemini15Flash8b,\n  gemini15Pro,\n  gemini20Flash,\n  gemini20FlashExp,\n  gemini20FlashLite,\n  gemini20ProExp0205,\n  gemini25ProExp0325,\n  textEmbedding004,\n  textEmbeddingGecko001,\n  type GeminiConfig,\n  type GeminiVersionString,\n};\n\nexport interface PluginOptions {\n  /**\n   * Provide the API key to use to authenticate with the Gemini API. By\n   * default, an API key must be provided explicitly here or through the\n   * `GEMINI_API_KEY` or `GOOGLE_API_KEY` environment variables.\n   *\n   * If `false` is explicitly passed, the plugin will be configured to\n   * expect an `apiKey` option to be provided to the model config at\n   * call time.\n   **/\n  apiKey?: string | false;\n  apiVersion?: string | string[];\n  baseUrl?: string;\n  models?: (\n    | ModelReference</** @ignore */ typeof GeminiConfigSchema>\n    | string\n  )[];\n  experimental_debugTraces?: boolean;\n}\n\n/**\n * Google Gemini Developer API plugin.\n */\nexport function googleAI(options?: PluginOptions): GenkitPlugin {\n  return genkitPlugin('googleai', async (ai: Genkit) => {\n    let apiVersions = ['v1'];\n\n    if (options?.apiVersion) {\n      if (Array.isArray(options?.apiVersion)) {\n        apiVersions = options?.apiVersion;\n      } else {\n        apiVersions = [options?.apiVersion];\n      }\n    }\n\n    if (apiVersions.includes('v1beta')) {\n      Object.keys(SUPPORTED_V15_MODELS).forEach((name) =>\n        defineGoogleAIModel({\n          ai,\n          name,\n          apiKey: options?.apiKey,\n          apiVersion: 'v1beta',\n          baseUrl: options?.baseUrl,\n          debugTraces: options?.experimental_debugTraces,\n        })\n      );\n    }\n    if (apiVersions.includes('v1')) {\n      Object.keys(SUPPORTED_V1_MODELS).forEach((name) =>\n        defineGoogleAIModel({\n          ai,\n          name,\n          apiKey: options?.apiKey,\n          apiVersion: undefined,\n          baseUrl: options?.baseUrl,\n          debugTraces: options?.experimental_debugTraces,\n        })\n      );\n      Object.keys(SUPPORTED_V15_MODELS).forEach((name) =>\n        defineGoogleAIModel({\n          ai,\n          name,\n          apiKey: options?.apiKey,\n          apiVersion: undefined,\n          baseUrl: options?.baseUrl,\n          debugTraces: options?.experimental_debugTraces,\n        })\n      );\n      Object.keys(EMBEDDER_MODELS).forEach((name) =>\n        defineGoogleAIEmbedder(ai, name, { apiKey: options?.apiKey })\n      );\n    }\n\n    if (options?.models) {\n      for (const modelOrRef of options?.models) {\n        const modelName =\n          typeof modelOrRef === 'string'\n            ? modelOrRef\n            : // strip out the `googleai/` prefix\n              modelOrRef.name.split('/')[1];\n        const modelRef =\n          typeof modelOrRef === 'string' ? gemini(modelOrRef) : modelOrRef;\n        defineGoogleAIModel({\n          ai,\n          name: modelName,\n          apiKey: options?.apiKey,\n          baseUrl: options?.baseUrl,\n          info: {\n            ...modelRef.info,\n            label: `Google AI - ${modelName}`,\n          },\n          debugTraces: options?.experimental_debugTraces,\n        });\n      }\n    }\n  });\n}\n\nexport default googleAI;\n"],"mappings":"AAiBA,SAAuB,oBAAoB;AAC3C;AAAA,EACE,oBAAoB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAyCA,SAAS,SAAS,SAAuC;AAC9D,SAAO,aAAa,YAAY,OAAO,OAAe;AACpD,QAAI,cAAc,CAAC,IAAI;AAEvB,QAAI,SAAS,YAAY;AACvB,UAAI,MAAM,QAAQ,SAAS,UAAU,GAAG;AACtC,sBAAc,SAAS;AAAA,MACzB,OAAO;AACL,sBAAc,CAAC,SAAS,UAAU;AAAA,MACpC;AAAA,IACF;AAEA,QAAI,YAAY,SAAS,QAAQ,GAAG;AAClC,aAAO,KAAK,oBAAoB,EAAE;AAAA,QAAQ,CAAC,SACzC,oBAAoB;AAAA,UAClB;AAAA,UACA;AAAA,UACA,QAAQ,SAAS;AAAA,UACjB,YAAY;AAAA,UACZ,SAAS,SAAS;AAAA,UAClB,aAAa,SAAS;AAAA,QACxB,CAAC;AAAA,MACH;AAAA,IACF;AACA,QAAI,YAAY,SAAS,IAAI,GAAG;AAC9B,aAAO,KAAK,mBAAmB,EAAE;AAAA,QAAQ,CAAC,SACxC,oBAAoB;AAAA,UAClB;AAAA,UACA;AAAA,UACA,QAAQ,SAAS;AAAA,UACjB,YAAY;AAAA,UACZ,SAAS,SAAS;AAAA,UAClB,aAAa,SAAS;AAAA,QACxB,CAAC;AAAA,MACH;AACA,aAAO,KAAK,oBAAoB,EAAE;AAAA,QAAQ,CAAC,SACzC,oBAAoB;AAAA,UAClB;AAAA,UACA;AAAA,UACA,QAAQ,SAAS;AAAA,UACjB,YAAY;AA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