{"version":3,"file":"google-vertex.d.ts","sourceRoot":"","sources":["../../src/providers/google-vertex.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAyF7D,wBAAgB,oBAAoB,IAAI,QAAQ,CAAC,eAAe,CAAC,CAQhE","sourcesContent":["import { googleVertexApi } from \"../api/google-vertex.lazy.ts\";\nimport type { ApiKeyAuth } from \"../auth/types.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { GOOGLE_VERTEX_MODELS } from \"./google-vertex.models.ts\";\n\nconst VERTEX_ADC_PATH = \"~/.config/gcloud/application_default_credentials.json\";\n\n/**\n * Vertex accepts an explicit API key or Application Default Credentials\n * (`gcloud auth application-default login`). ADC additionally requires\n * project and location env vars, which the implementation reads itself.\n */\nconst vertexAuth: ApiKeyAuth = {\n\tname: \"Google Cloud credentials\",\n\tlogin: async (interaction) => {\n\t\tinteraction.signal.throwIfAborted();\n\t\tconst method = await interaction.prompt({\n\t\t\ttype: \"select\",\n\t\t\tmessage: \"Select Google Vertex AI authentication method:\",\n\t\t\toptions: [\n\t\t\t\t{ id: \"api-key\", label: \"Google Cloud API key\" },\n\t\t\t\t{ id: \"adc\", label: \"Application Default Credentials\" },\n\t\t\t\t{ id: \"service-account\", label: \"Service account credentials file\" },\n\t\t\t],\n\t\t});\n\t\tinteraction.signal.throwIfAborted();\n\t\tif (method === \"api-key\") {\n\t\t\treturn {\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: await interaction.prompt({ type: \"secret\", message: \"Enter Google Cloud API key\" }),\n\t\t\t};\n\t\t}\n\t\tif (method !== \"adc\" && method !== \"service-account\") {\n\t\t\tthrow new Error(`Unknown Google Vertex AI auth method: ${method}`);\n\t\t}\n\t\tinteraction.notify({\n\t\t\ttype: \"info\",\n\t\t\tmessage:\n\t\t\t\tmethod === \"adc\"\n\t\t\t\t\t? \"Run `gcloud auth application-default login`, then provide the project and location.\"\n\t\t\t\t\t: \"Provide a service account credentials file, project, and location.\",\n\t\t\tlinks: [\n\t\t\t\t{\n\t\t\t\t\tlabel: \"Application Default Credentials\",\n\t\t\t\t\turl: \"https://cloud.google.com/docs/authentication/provide-credentials-adc\",\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t\tconst project = await interaction.prompt({ type: \"text\", message: \"Enter Google Cloud project ID\" });\n\t\tconst location = await interaction.prompt({ type: \"text\", message: \"Enter Google Cloud location\" });\n\t\tconst credentialsPath =\n\t\t\tmethod === \"service-account\"\n\t\t\t\t? await interaction.prompt({ type: \"text\", message: \"Enter service account credentials file path\" })\n\t\t\t\t: undefined;\n\t\treturn {\n\t\t\ttype: \"api_key\",\n\t\t\tenv: {\n\t\t\t\tGOOGLE_CLOUD_PROJECT: project,\n\t\t\t\tGOOGLE_CLOUD_LOCATION: location,\n\t\t\t\t...(credentialsPath ? { GOOGLE_APPLICATION_CREDENTIALS: credentialsPath } : {}),\n\t\t\t},\n\t\t};\n\t},\n\tresolve: async ({ ctx, credential, signal }) => {\n\t\tconst env = async (name: string) => {\n\t\t\tsignal.throwIfAborted();\n\t\t\tconst value = await ctx.env(name);\n\t\t\tsignal.throwIfAborted();\n\t\t\treturn value;\n\t\t};\n\t\tconst key = credential?.key ?? (await env(\"GOOGLE_CLOUD_API_KEY\"));\n\t\tif (key) return { auth: { apiKey: key }, source: credential?.key ? \"stored credential\" : \"GOOGLE_CLOUD_API_KEY\" };\n\n\t\tconst adcPath = credential?.env?.GOOGLE_APPLICATION_CREDENTIALS ?? (await env(\"GOOGLE_APPLICATION_CREDENTIALS\"));\n\t\tsignal.throwIfAborted();\n\t\tconst hasCredentials = await ctx.fileExists(adcPath ?? VERTEX_ADC_PATH);\n\t\tsignal.throwIfAborted();\n\t\tconst project =\n\t\t\tcredential?.env?.GOOGLE_CLOUD_PROJECT ?? (await env(\"GOOGLE_CLOUD_PROJECT\")) ?? (await env(\"GCLOUD_PROJECT\"));\n\t\tconst location = credential?.env?.GOOGLE_CLOUD_LOCATION ?? (await env(\"GOOGLE_CLOUD_LOCATION\"));\n\t\tif (hasCredentials && project && location) {\n\t\t\treturn {\n\t\t\t\tauth: {},\n\t\t\t\tenv: credential?.env,\n\t\t\t\tsource: credential ? \"stored credential\" : \"gcloud application default credentials\",\n\t\t\t};\n\t\t}\n\t\treturn undefined;\n\t},\n};\n\nexport function googleVertexProvider(): Provider<\"google-vertex\"> {\n\treturn createProvider({\n\t\tid: \"google-vertex\",\n\t\tname: \"Google Vertex AI\",\n\t\tauth: { apiKey: vertexAuth },\n\t\tmodels: Object.values(GOOGLE_VERTEX_MODELS),\n\t\tapi: googleVertexApi(),\n\t});\n}\n"]}