{"version":3,"sources":["../../../src/modelgarden/v2/index.ts"],"sourcesContent":["/**\n * Copyright 2025 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 { GenkitError, ModelReference, z } from 'genkit';\nimport { genkitPluginV2, type GenkitPluginV2 } from 'genkit/plugin';\nimport { ActionType } from 'genkit/registry';\nimport { getDerivedParams } from '../../common/index.js';\nimport * as anthropic from './anthropic.js';\nimport * as llama from './llama.js';\nimport * as mistral from './mistral.js';\nimport type { PluginOptions } from './types.js';\n\nexport type { PluginOptions };\n\nasync function initializer(pluginOptions?: PluginOptions) {\n  const clientOptions = await getDerivedParams(pluginOptions);\n  return [\n    ...anthropic.listKnownModels(clientOptions, pluginOptions),\n    ...mistral.listKnownModels(clientOptions, pluginOptions),\n    ...llama.listKnownModels(clientOptions, pluginOptions),\n  ];\n}\n\nasync function resolver(\n  actionType: ActionType,\n  actionName: string,\n  pluginOptions?: PluginOptions\n) {\n  const clientOptions = await getDerivedParams(pluginOptions);\n  switch (actionType) {\n    case 'model':\n      if (anthropic.isAnthropicModelName(actionName)) {\n        return anthropic.defineModel(actionName, clientOptions, pluginOptions);\n      } else if (mistral.isMistralModelName(actionName)) {\n        return mistral.defineModel(actionName, clientOptions, pluginOptions);\n      } else if (llama.isLlamaModelName(actionName)) {\n        return llama.defineModel(actionName, clientOptions, pluginOptions);\n      }\n      break;\n  }\n  return undefined;\n}\n\nasync function listActions(options?: PluginOptions) {\n  try {\n    const clientOptions = await getDerivedParams(options);\n    return [\n      ...anthropic.listActions(clientOptions),\n      ...mistral.listActions(clientOptions),\n      ...llama.listActions(clientOptions),\n    ];\n  } catch (e: unknown) {\n    return [];\n  }\n}\n\n/**\n * Add Google Cloud Vertex AI Model Garden to Genkit.\n */\nexport function vertexModelGardenPlugin(\n  options: PluginOptions\n): GenkitPluginV2 {\n  let listActionsCache;\n  return genkitPluginV2({\n    name: 'vertex-model-garden',\n    init: async () => await initializer(options),\n    resolve: async (actionType: ActionType, actionName: string) =>\n      await resolver(actionType, actionName, options),\n    list: async () => {\n      if (listActionsCache) return listActionsCache;\n      listActionsCache = await listActions(options);\n      return listActionsCache;\n    },\n  });\n}\n\nexport type VertexModelGardenPlugin = {\n  (pluginOptions?: PluginOptions): GenkitPluginV2;\n  model(\n    name: anthropic.KnownModels | (anthropic.AnthropicModelName & {}),\n    config?: anthropic.AnthropicConfig\n  ): ModelReference<anthropic.AnthropicConfigSchemaType>;\n  model(\n    name: mistral.KnownModels | (mistral.MistralModelName & {}),\n    config: mistral.MistralConfig\n  ): ModelReference<mistral.MistralConfigSchemaType>;\n  model(\n    name: llama.KnownModels | (llama.LlamaModelName & {}),\n    config: llama.LlamaConfig\n  ): ModelReference<llama.LlamaConfigSchemaType>;\n  model(name: string, config?: any): ModelReference<z.ZodTypeAny>;\n};\n\nexport const vertexModelGarden =\n  vertexModelGardenPlugin as VertexModelGardenPlugin;\n(vertexModelGarden as any).model = (\n  name: string,\n  config?: any\n): ModelReference<z.ZodTypeAny> => {\n  if (anthropic.isAnthropicModelName(name)) {\n    return anthropic.model(name, config);\n  }\n  if (mistral.isMistralModelName(name)) {\n    return mistral.model(name, config);\n  }\n  if (llama.isLlamaModelName(name)) {\n    return llama.model(name, config);\n  }\n  throw new GenkitError({\n    status: 'INVALID_ARGUMENT',\n    message: `model '${name}' is not a recognized model name`,\n  });\n};\n"],"mappings":"AAgBA,SAAS,mBAAsC;AAC/C,SAAS,sBAA2C;AAEpD,SAAS,wBAAwB;AACjC,YAAY,eAAe;AAC3B,YAAY,WAAW;AACvB,YAAY,aAAa;AAKzB,eAAe,YAAY,eAA+B;AACxD,QAAM,g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