{"version":3,"sources":["../../src/vertexai/utils.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, z, type ActionContext } from 'genkit';\nimport { GoogleAuth } from 'google-auth-library';\nimport {\n  isMultiRegionalLocation,\n  type ClientOptions,\n  type ExpressClientOptions,\n  type GlobalClientOptions,\n  type MultiRegionalClientOptions,\n  type RegionalClientOptions,\n  type VertexPluginOptions,\n} from './types.mjs';\n\nexport {\n  checkModelName,\n  checkSupportedMimeType,\n  cleanSchema,\n  extractMedia,\n  extractMimeType,\n  extractText,\n  extractVersion,\n  modelName,\n} from '../common/utils.mjs';\n\nconst CLOUD_PLATFORM_OAUTH_SCOPE =\n  'https://www.googleapis.com/auth/cloud-platform';\n\nfunction parseFirebaseProjectId(): string | undefined {\n  if (!process.env.FIREBASE_CONFIG) return undefined;\n  try {\n    return JSON.parse(process.env.FIREBASE_CONFIG).projectId as string;\n  } catch {\n    return undefined;\n  }\n}\n\nexport function shouldUseLegacyEndpoint(model: string) {\n  // This only covers lyria models so far\n  return model === 'lyria-002';\n}\n\nlet __mockDerivedOptions: ClientOptions | undefined = undefined;\nfunction setMockDerivedOptions(options: ClientOptions | undefined): void {\n  __mockDerivedOptions = options;\n}\nexport const TEST_ONLY = { setMockDerivedOptions };\n\nexport async function getDerivedOptions(\n  options?: VertexPluginOptions,\n  AuthClass: typeof GoogleAuth = GoogleAuth // Injectable testing\n): Promise<ClientOptions> {\n  if (__mockDerivedOptions) {\n    return Promise.resolve(__mockDerivedOptions);\n  }\n\n  // Lazy instantiate the authClient\n  let authClientPromise: Promise<GoogleAuth> | undefined;\n  const getAuthClientInternal = (): Promise<GoogleAuth> => {\n    if (!authClientPromise) {\n      authClientPromise = getAuthClient(AuthClass, options);\n    }\n    return authClientPromise;\n  };\n\n  // Lazy instantiate the projectId\n  let projectIdPromise: Promise<string> | undefined;\n  const getProjectIdInternal = (): Promise<string> => {\n    if (!projectIdPromise) {\n      projectIdPromise = (async () => {\n        const authClient = await getAuthClientInternal();\n        return getProjectId(authClient, options);\n      })();\n    }\n    return projectIdPromise;\n  };\n\n  // Figure out the type of preferred options if possible\n  // The order of the if statements is important.\n  if (options?.location == 'global') {\n    return await getGlobalDerivedOptions(\n      await getAuthClientInternal(),\n      await getProjectIdInternal(),\n      options\n    );\n  } else if (isMultiRegionalLocation(options?.location)) {\n    return await getMultiRegionalDerivedOptions(\n      await getAuthClientInternal(),\n      await getProjectIdInternal(),\n      options\n    );\n  } else if (options?.location) {\n    return await getRegionalDerivedOptions(\n      await getAuthClientInternal(),\n      await getProjectIdInternal(),\n      options\n    );\n  } else if (options?.apiKey !== undefined) {\n    // apiKey = false still indicates apiKey expectation\n    return getExpressDerivedOptions(options);\n  }\n\n  // If we got here then we're relying on environment variables.\n  // Try multi-regional first, it's very narrowly defined location\n  try {\n    const multiRegionalOptions = await getMultiRegionalDerivedOptions(\n      await getAuthClientInternal(),\n      await getProjectIdInternal(),\n      options\n    );\n    return multiRegionalOptions;\n  } catch (e: unknown) {\n    /* no-op - try regional next */\n  }\n  // Try regional second, it's the most common usage.\n  try {\n    const regionalOptions = await getRegionalDerivedOptions(\n      await getAuthClientInternal(),\n      await getProjectIdInternal(),\n      options\n    );\n    return regionalOptions;\n  } catch (e: unknown) {\n    /* no-op - try global next */\n  }\n  try {\n    const globalOptions = await getGlobalDerivedOptions(\n      await getAuthClientInternal(),\n      await getProjectIdInternal(),\n      options\n    );\n    return globalOptions;\n  } catch (e: unknown) {\n    /* no-op - try express last */\n  }\n  try {\n    const expressOptions = getExpressDerivedOptions(options);\n    return expressOptions;\n  } catch (e: unknown) {\n    /* no-op */\n  }\n\n  // We did not have enough information in the options or in environment variables\n  // to properly determine client options.\n  throw new GenkitError({\n    status: 'INVALID_ARGUMENT',\n    message:\n      'Unable to determine client options. Please set either apiKey or projectId and location',\n  });\n}\n\nasync function getGlobalDerivedOptions(\n  authClient: GoogleAuth,\n  projectId: string,\n  options?: VertexPluginOptions\n): Promise<GlobalClientOptions> {\n  const clientOpt: GlobalClientOptions = {\n    kind: 'global',\n    location: 'global',\n    projectId,\n    authClient,\n    experimental_debugTraces: options?.experimental_debugTraces,\n  };\n  if (options?.apiKey) {\n    clientOpt.apiKey = options.apiKey;\n  }\n  if (options?.apiVersion) {\n    clientOpt.apiVersion = options.apiVersion;\n  }\n\n  return clientOpt;\n}\n\nfunction getExpressDerivedOptions(\n  options?: VertexPluginOptions\n): ExpressClientOptions {\n  const apiKey = checkApiKey(options?.apiKey);\n  const clientOpt: ExpressClientOptions = {\n    kind: 'express',\n    apiKey,\n    experimental_debugTraces: options?.experimental_debugTraces,\n  };\n  if (options?.apiVersion) {\n    clientOpt.apiVersion = options.apiVersion;\n  }\n  return clientOpt;\n}\n\nasync function getAuthClient(\n  AuthClass: typeof GoogleAuth,\n  options?: VertexPluginOptions\n): Promise<GoogleAuth> {\n  let authOptions = options?.googleAuth;\n  let authClient: GoogleAuth;\n  const providedProjectId =\n    options?.projectId ||\n    process.env.GCLOUD_PROJECT ||\n    parseFirebaseProjectId();\n  if (process.env.GCLOUD_SERVICE_ACCOUNT_CREDS) {\n    const serviceAccountCreds = JSON.parse(\n      process.env.GCLOUD_SERVICE_ACCOUNT_CREDS\n    );\n    authOptions = {\n      credentials: serviceAccountCreds,\n      scopes: [CLOUD_PLATFORM_OAUTH_SCOPE],\n      projectId: providedProjectId,\n    };\n    authClient = new AuthClass(authOptions);\n  } else {\n    authClient = new AuthClass(\n      authOptions ?? {\n        scopes: [CLOUD_PLATFORM_OAUTH_SCOPE],\n        projectId: providedProjectId,\n      }\n    );\n  }\n  return authClient;\n}\n\nasync function getProjectId(\n  authClient: GoogleAuth,\n  options?: VertexPluginOptions\n): Promise<string> {\n  const projectId =\n    options?.projectId ||\n    process.env.GCLOUD_PROJECT ||\n    (await authClient.getProjectId());\n  if (!projectId) {\n    throw new Error(\n      `VertexAI Plugin is missing the 'project' configuration. Please set the 'GCLOUD_PROJECT' environment variable or explicitly pass 'project' into genkit config.`\n    );\n  }\n  return projectId;\n}\n\nasync function getMultiRegionalDerivedOptions(\n  authClient: GoogleAuth,\n  projectId: string,\n  options?: VertexPluginOptions\n): Promise<MultiRegionalClientOptions> {\n  const location = options?.location || process.env.GCLOUD_LOCATION;\n\n  if (!location) {\n    throw new Error(\n      `VertexAI Plugin is missing the 'location' configuration. Please set the 'GCLOUD_LOCATION' environment variable or explicitly pass 'location' into genkit config.`\n    );\n  }\n  if (!isMultiRegionalLocation(location)) {\n    throw new Error(\n      `Tried to set multi regional location to an invalid region: ${location}`\n    );\n  }\n\n  const clientOpt: MultiRegionalClientOptions = {\n    kind: 'multi-regional',\n    location,\n    projectId,\n    authClient,\n    experimental_debugTraces: options?.experimental_debugTraces,\n  };\n  if (options?.apiKey) {\n    clientOpt.apiKey = options.apiKey;\n  }\n  if (options?.apiVersion) {\n    clientOpt.apiVersion = options.apiVersion;\n  }\n  return clientOpt;\n}\n\nasync function getRegionalDerivedOptions(\n  authClient: GoogleAuth,\n  projectId: string,\n  options?: VertexPluginOptions\n): Promise<RegionalClientOptions> {\n  // TODO(V2): Default to 'global' for every model. For now only models on\n  // the Interactions API (only on global and the us/eu multi-regions) use\n  // global when the location is defaulted (see `locationDefaulted`).\n  const chosenLocation = options?.location || process.env.GCLOUD_LOCATION;\n  const location = chosenLocation || 'us-central1';\n  if (!location) {\n    throw new Error(\n      `VertexAI Plugin is missing the 'location' configuration. Please set the 'GCLOUD_LOCATION' environment variable or explicitly pass 'location' into genkit config.`\n    );\n  }\n\n  const clientOpt: RegionalClientOptions = {\n    kind: 'regional',\n    location,\n    projectId,\n    authClient,\n    experimental_debugTraces: options?.experimental_debugTraces,\n  };\n  if (!chosenLocation) {\n    clientOpt.locationDefaulted = true;\n  }\n  if (options?.apiKey) {\n    clientOpt.apiKey = options.apiKey;\n  }\n  if (options?.apiVersion) {\n    clientOpt.apiVersion = options.apiVersion;\n  }\n  return clientOpt;\n}\n\n/**\n * Client options for an Interactions API request. The Interactions API is\n * only on the global location (and the us/eu multi-regions), so when the\n * location is the built-in default (`us-central1`, nothing chosen) the\n * request goes to `global`. A chosen location is used as is.\n */\nexport function toInteractionsClientOptions(\n  clientOptions: ClientOptions\n): ClientOptions {\n  if (clientOptions.kind === 'regional' && clientOptions.locationDefaulted) {\n    const {\n      locationDefaulted: _,\n      kind: _kind,\n      location: _location,\n      ...rest\n    } = clientOptions;\n    const globalOptions: GlobalClientOptions = {\n      ...rest,\n      kind: 'global',\n      location: 'global',\n    };\n    return globalOptions;\n  }\n  return clientOptions;\n}\n\nexport type RequestClientOptions = ClientOptions & {\n  signal: AbortSignal;\n};\n\n/**\n * If location or apiKey are present in reqConfig, they will\n * override the values in the clientOptions. The newOptions will\n * contain the clientOptions with those overrides.\n * @param clientOptions The client options\n * @param reqConfig The request config\n */\nexport function calculateRequestOptions<T extends z.ZodObject<any, any, any>>(\n  clientOptions: RequestClientOptions,\n  reqConfig?: z.infer<T>\n): RequestClientOptions;\nexport function calculateRequestOptions<T extends z.ZodObject<any, any, any>>(\n  clientOptions: ClientOptions,\n  reqConfig?: z.infer<T>\n): ClientOptions;\nexport function calculateRequestOptions<T extends z.ZodObject<any, any, any>>(\n  clientOptions: RequestClientOptions | ClientOptions,\n  reqConfig?: z.infer<T>\n): RequestClientOptions | ClientOptions {\n  let newOptions = { ...clientOptions };\n  if (reqConfig?.apiVersion) {\n    newOptions.apiVersion = reqConfig.apiVersion;\n  }\n  // A location set in the request is chosen, even if it equals the default.\n  if (\n    reqConfig?.location &&\n    typeof reqConfig.location == 'string' &&\n    newOptions.kind == 'regional'\n  ) {\n    delete newOptions.locationDefaulted;\n  }\n  if (\n    reqConfig?.location &&\n    typeof reqConfig.location == 'string' &&\n    newOptions.kind != 'express' &&\n    newOptions.location != reqConfig.location\n  ) {\n    // Override the location if it's specified in the request\n    if (reqConfig.location == 'global') {\n      newOptions.location = 'global';\n      newOptions.kind = 'global';\n    } else if (isMultiRegionalLocation(reqConfig.location)) {\n      newOptions.kind = 'multi-regional';\n      newOptions.location = reqConfig.location;\n    } else {\n      newOptions.kind = 'regional';\n      newOptions.location = reqConfig.location;\n    }\n  }\n  if (\n    clientOptions.kind == 'express' &&\n    reqConfig?.apiKey &&\n    typeof reqConfig.apiKey == 'string'\n  ) {\n    newOptions.apiKey = calculateApiKey(clientOptions.apiKey, reqConfig.apiKey);\n  } else if (reqConfig?.apiKey && typeof reqConfig.apiKey == 'string') {\n    // Regional or Global can still use APIKey for billing (not auth)\n    newOptions.apiKey = reqConfig.apiKey;\n  }\n  return newOptions;\n}\n\n/**\n * Applies connection-related overrides carried in the action run context\n * (e.g. `options.context` on `start`/`check`/`cancel` for background models)\n * on top of the given client options. This is the mechanism by which callers\n * can supply per-call overrides for calls (like\n * `checkOperation`/`cancelOperation`) that don't have access to the original\n * request's `config`.\n *\n * The API key is read from `context.secrets.apiKey` (scrubbed from traces).\n * All other overrides (e.g. `location`, `apiVersion`) are read from\n * `context.config`, which is where `checkOperation`/`cancelOperation` fold\n * their top-level `config` option. This lets callers write\n * `ai.checkOperation(op, { config: { location } })`.\n *\n * All context-derived values take precedence over whatever is already in\n * `clientOptions`.\n *\n * @param clientOptions The base client options to apply overrides on top of.\n * @param context The action run context (`options.context`), if any.\n */\nexport function applyContextOverrides(\n  clientOptions: ClientOptions,\n  context?: ActionContext\n): ClientOptions {\n  if (!context) {\n    return clientOptions;\n  }\n  let newOptions = { ...clientOptions };\n  const contextApiKey = context.secrets?.apiKey;\n  if (typeof contextApiKey === 'string') {\n    if (newOptions.kind == 'express') {\n      newOptions.apiKey = calculateApiKey(newOptions.apiKey, contextApiKey);\n    } else {\n      // Regional or Global can still use APIKey for billing (not auth)\n      newOptions.apiKey = contextApiKey;\n    }\n  }\n  // All non-secret overrides (e.g. location, apiVersion) are carried in\n  // `context.config` (from checkOperation/cancelOperation's top-level\n  // `config`).\n  return calculateRequestOptions(newOptions, context.config);\n}\n\n/**\n * Retrieves an API key from environment variables.\n *\n * @returns The API key as a string, or `undefined` if none of the specified\n *          environment variables are set.\n */\nexport function getApiKeyFromEnvVar(): string | undefined {\n  return (\n    process.env.VERTEX_API_KEY ||\n    process.env.GOOGLE_API_KEY ||\n    process.env.GOOGLE_GENAI_API_KEY\n  );\n}\n\nexport const MISSING_API_KEY_ERROR = new GenkitError({\n  status: 'FAILED_PRECONDITION',\n  message:\n    'Please pass in the API key or set the VERTEX_API_KEY or GOOGLE_API_KEY environment variable.\\n' +\n    'For more details see https://genkit.dev/docs/integrations/google-genai',\n});\n\nexport const API_KEY_FALSE_ERROR = new GenkitError({\n  status: 'INVALID_ARGUMENT',\n  message:\n    'VertexAI plugin was initialized with {apiKey: false} but no apiKey configuration was passed at call time.',\n});\n\nexport const NOT_SUPPORTED_IN_EXPRESS_ERROR = new GenkitError({\n  status: 'PERMISSION_DENIED',\n  message:\n    'This method or model is not supported in Vertex AI Express Mode.\\n' +\n    'For more details see https://cloud.google.com/vertex-ai/generative-ai/docs/start/express-mode/vertex-ai-express-mode-api-reference',\n});\n\n/**\n * Checks and retrieves an API key based on the provided argument and environment variables.\n *\n * - If `pluginApiKey` is a non-empty string, it's used as the API key.\n * - If `pluginApiKey` is `undefined` or an empty string, it attempts to fetch the API key from environment\n * - If `pluginApiKey` is `false`, key retrieval from the environment is skipped, and the function\n *   will return `undefined`. This mode indicates that the API key is expected to be provided\n *   at a later stage or in a different context.\n *\n * @param pluginApiKey - An optional API key string, `undefined` to check the environment, or `false` to bypass all checks in this function.\n * @returns The resolved API key as a string, or `undefined` if `pluginApiKey` is `false`.\n * @throws {Error} MISSING_API_KEY_ERROR - Thrown if `pluginApiKey` is not `false` and no API key\n *   can be found either in the `pluginApiKey` argument or from the environment.\n */\nexport function checkApiKey(\n  pluginApiKey: string | false | undefined\n): string | undefined {\n  let apiKey: string | undefined;\n\n  // Don't get the key from the environment if pluginApiKey is false\n  if (pluginApiKey !== false) {\n    apiKey = pluginApiKey || getApiKeyFromEnvVar();\n  }\n\n  // If pluginApiKey is false, then we don't throw because we are waiting for\n  // the apiKey passed into the individual call\n  if (pluginApiKey !== false && !apiKey) {\n    throw MISSING_API_KEY_ERROR;\n  }\n  return apiKey;\n}\n\n/**\n * Calculates and returns the effective API key based on multiple potential sources.\n * The order of precedence for determining the API key is:\n * 1. `requestApiKey` (if provided)\n * 2. `pluginApiKey` (if provided and not `false`)\n * 3. Environment variable (if `pluginApiKey` is not `false` and `pluginApiKey` is not provided)\n *\n * @param pluginApiKey - The apiKey value provided during plugin initialization.\n * @param requestApiKey - The apiKey provided to an individual generate call.\n * @returns The resolved API key as a string.\n * @throws {Error} API_KEY_FALSE_ERROR - Thrown if `pluginApiKey` is `false` and `requestApiKey` is not provided\n * @throws {Error} MISSING_API_KEY_ERROR - Thrown if no API key can be resolved from any source\n */\nexport function calculateApiKey(\n  pluginApiKey: string | false | undefined,\n  requestApiKey: string | undefined\n): string {\n  let apiKey: string | undefined;\n\n  // Don't get the key from the environment if pluginApiKey is false\n  if (pluginApiKey !== false) {\n    apiKey = pluginApiKey || getApiKeyFromEnvVar();\n  }\n\n  apiKey = requestApiKey || apiKey;\n\n  if (pluginApiKey === false && !requestApiKey) {\n    throw API_KEY_FALSE_ERROR;\n  }\n\n  if (!apiKey) {\n    throw MISSING_API_KEY_ERROR;\n  }\n  return apiKey;\n}\n\n/** Vertex Express Mode lets you try a *subset* of Vertex AI features */\nexport function checkSupportedResourceMethod(params: {\n  clientOptions: ClientOptions;\n  resourcePath?: string;\n  resourceMethod?: string;\n}) {\n  if (params.resourcePath == '') {\n    // This is how we get a base url for metadata\n    return;\n  }\n\n  const supportedExpressMethods = [\n    'countTokens',\n    'generateContent',\n    'streamGenerateContent',\n  ];\n\n  // The Interactions API has no resource method (`.../interactions`) and is\n  // available in Express mode.\n  const isInteractions =\n    !params.resourceMethod &&\n    !!params.resourcePath?.split('/').includes('interactions');\n\n  if (\n    params.clientOptions.kind === 'express' &&\n    ((!isInteractions &&\n      !supportedExpressMethods.includes(params.resourceMethod ?? '')) ||\n      params.resourcePath?.includes('endpoints/'))\n  ) {\n    throw NOT_SUPPORTED_IN_EXPRESS_ERROR;\n  }\n}\n"],"mappings":"AAgBA,SAAS,mBAA0C;AACnD,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,OAOK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,6BACJ;AAEF,SAAS,yBAA6C;AACpD,MAAI,CAAC,QAAQ,IAAI,gBAAiB,QAAO;AACzC,MAAI;AACF,WAAO,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE;AAAA,EACjD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,wBAAwB,OAAe;AAErD,SAAO,UAAU;AACnB;AAEA,IAAI,uBAAkD;AACtD,SAAS,sBAAsB,SAA0C;AACvE,yBAAuB;AACzB;AACO,MAAM,YAAY,EAAE,sBAAsB;AAEjD,eAAsB,kBACpB,SACA,YAA+B,YACP;AACxB,MAAI,sBAAsB;AACxB,WAAO,QAAQ,QAAQ,oBAAoB;AAAA,EAC7C;AAGA,MAAI;AACJ,QAAM,wBAAwB,MAA2B;AACvD,QAAI,CAAC,mBAAmB;AACtB,0BAAoB,cAAc,WAAW,OAAO;AAAA,IACtD;AACA,WAAO;AAAA,EACT;AAGA,MAAI;AACJ,QAAM,uBAAuB,MAAuB;AAClD,QAAI,CAAC,kBAAkB;AACrB,0BAAoB,YAAY;AAC9B,cAAM,aAAa,MAAM,sBAAsB;AAC/C,eAAO,aAAa,YAAY,OAAO;AAAA,MACzC,GA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