Files
Nexus_Mat/.next/static/chunks/7b3a7bf8-bf0e044ebc1c1648.js

113 lines
208 KiB
JavaScript

"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[279],{1426:function(e,t,n){var i,l,o,r,s,a,u,p,d,c,h,f,m,g,y,E,v,_,I,T,A,C,S,O,b,N,R,P,D,M,U,w,q,k,G,L,x,H,F,V,j,B,J,Y,K,W,$,z,X,Q,Z,ee,et,en,ei,el,eo,er,es,ea,eu,ep,ed,ec,eh,ef,em,eg,ey,eE,ev,e_,eI,eT,eA,eC,eS,eO,eb,eN,eR,eP,eD,eM,eU,ew,eq,ek,eG,eL,ex,eH,eF,eV,ej,eB,eJ,eY,eK,eW,e$,ez,eX,eQ,eZ,e0,e1,e2,e6,e4,e3,e8;let e9,e5;n.d(t,{fA:function(){return is}});/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class e7{}function te(e,t){return e.replace(/\{([^}]+)\}/g,(e,n)=>{if(Object.prototype.hasOwnProperty.call(t,n)){let e=t[n];return null!=e?String(e):""}throw Error(`Key '${n}' not found in valueMap.`)})}function tt(e,t,n){for(let i=0;i<t.length-1;i++){let l=t[i];if(l.endsWith("[]")){let o=l.slice(0,-2);if(!(o in e)){if(Array.isArray(n))e[o]=Array.from({length:n.length},()=>({}));else throw Error(`Value must be a list given an array path ${l}`)}if(Array.isArray(e[o])){let l=e[o];if(Array.isArray(n))for(let e=0;e<l.length;e++)tt(l[e],t.slice(i+1),n[e]);else for(let e of l)tt(e,t.slice(i+1),n)}return}if(l.endsWith("[0]")){let o=l.slice(0,-3);o in e||(e[o]=[{}]),tt(e[o][0],t.slice(i+1),n);return}e[l]&&"object"==typeof e[l]||(e[l]={}),e=e[l]}let i=t[t.length-1],l=e[i];if(void 0!==l){if(!n||"object"==typeof n&&0===Object.keys(n).length||n===l)return;if("object"==typeof l&&"object"==typeof n&&null!==l&&null!==n)Object.assign(l,n);else throw Error(`Cannot set value for an existing key. Key: ${i}`)}else"_self"!==i||"object"!=typeof n||null===n||Array.isArray(n)?e[i]=n:Object.assign(e,n)}function tn(e,t,n){try{if(1===t.length&&"_self"===t[0])return e;for(let i=0;i<t.length;i++){if("object"!=typeof e||null===e)return n;let l=t[i];if(l.endsWith("[]")){let o=l.slice(0,-2);if(!(o in e))return n;{let l=e[o];if(!Array.isArray(l))return n;return l.map(e=>tn(e,t.slice(i+1),n))}}e=e[l]}return e}catch(e){if(e instanceof TypeError)return n;throw e}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function ti(e){if("string"!=typeof e)throw Error("fromImageBytes must be a string");return e}function tl(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["name"],n);let i=tn(e,["metadata"]);null!=i&&tt(t,["metadata"],i);let l=tn(e,["done"]);null!=l&&tt(t,["done"],l);let o=tn(e,["error"]);null!=o&&tt(t,["error"],o);let r=tn(e,["response"]);return null!=r&&tt(t,["response"],function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["parent"]);null!=i&&tt(t,["parent"],i);let l=tn(e,["documentName"]);return null!=l&&tt(t,["documentName"],l),t}(r)),t}(eo=i||(i={})).OUTCOME_UNSPECIFIED="OUTCOME_UNSPECIFIED",eo.OUTCOME_OK="OUTCOME_OK",eo.OUTCOME_FAILED="OUTCOME_FAILED",eo.OUTCOME_DEADLINE_EXCEEDED="OUTCOME_DEADLINE_EXCEEDED",(er=l||(l={})).LANGUAGE_UNSPECIFIED="LANGUAGE_UNSPECIFIED",er.PYTHON="PYTHON",(es=o||(o={})).SCHEDULING_UNSPECIFIED="SCHEDULING_UNSPECIFIED",es.SILENT="SILENT",es.WHEN_IDLE="WHEN_IDLE",es.INTERRUPT="INTERRUPT",(ea=r||(r={})).TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",ea.STRING="STRING",ea.NUMBER="NUMBER",ea.INTEGER="INTEGER",ea.BOOLEAN="BOOLEAN",ea.ARRAY="ARRAY",ea.OBJECT="OBJECT",ea.NULL="NULL",(eu=s||(s={})).MODE_UNSPECIFIED="MODE_UNSPECIFIED",eu.MODE_DYNAMIC="MODE_DYNAMIC",(ep=a||(a={})).API_SPEC_UNSPECIFIED="API_SPEC_UNSPECIFIED",ep.SIMPLE_SEARCH="SIMPLE_SEARCH",ep.ELASTIC_SEARCH="ELASTIC_SEARCH",(ed=u||(u={})).AUTH_TYPE_UNSPECIFIED="AUTH_TYPE_UNSPECIFIED",ed.NO_AUTH="NO_AUTH",ed.API_KEY_AUTH="API_KEY_AUTH",ed.HTTP_BASIC_AUTH="HTTP_BASIC_AUTH",ed.GOOGLE_SERVICE_ACCOUNT_AUTH="GOOGLE_SERVICE_ACCOUNT_AUTH",ed.OAUTH="OAUTH",ed.OIDC_AUTH="OIDC_AUTH",(ec=p||(p={})).HTTP_IN_UNSPECIFIED="HTTP_IN_UNSPECIFIED",ec.HTTP_IN_QUERY="HTTP_IN_QUERY",ec.HTTP_IN_HEADER="HTTP_IN_HEADER",ec.HTTP_IN_PATH="HTTP_IN_PATH",ec.HTTP_IN_BODY="HTTP_IN_BODY",ec.HTTP_IN_COOKIE="HTTP_IN_COOKIE",(eh=d||(d={})).PHISH_BLOCK_THRESHOLD_UNSPECIFIED="PHISH_BLOCK_THRESHOLD_UNSPECIFIED",eh.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",eh.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",eh.BLOCK_HIGH_AND_ABOVE="BLOCK_HIGH_AND_ABOVE",eh.BLOCK_HIGHER_AND_ABOVE="BLOCK_HIGHER_AND_ABOVE",eh.BLOCK_VERY_HIGH_AND_ABOVE="BLOCK_VERY_HIGH_AND_ABOVE",eh.BLOCK_ONLY_EXTREMELY_HIGH="BLOCK_ONLY_EXTREMELY_HIGH",(ef=c||(c={})).THINKING_LEVEL_UNSPECIFIED="THINKING_LEVEL_UNSPECIFIED",ef.LOW="LOW",ef.HIGH="HIGH",(em=h||(h={})).HARM_CATEGORY_UNSPECIFIED="HARM_CATEGORY_UNSPECIFIED",em.HARM_CATEGORY_HARASSMENT="HARM_CATEGORY_HARASSMENT",em.HARM_CATEGORY_HATE_SPEECH="HARM_CATEGORY_HATE_SPEECH",em.HARM_CATEGORY_SEXUALLY_EXPLICIT="HARM_CATEGORY_SEXUALLY_EXPLICIT",em.HARM_CATEGORY_DANGEROUS_CONTENT="HARM_CATEGORY_DANGEROUS_CONTENT",em.HARM_CATEGORY_CIVIC_INTEGRITY="HARM_CATEGORY_CIVIC_INTEGRITY",em.HARM_CATEGORY_IMAGE_HATE="HARM_CATEGORY_IMAGE_HATE",em.HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT="HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT",em.HARM_CATEGORY_IMAGE_HARASSMENT="HARM_CATEGORY_IMAGE_HARASSMENT",em.HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT="HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT",em.HARM_CATEGORY_JAILBREAK="HARM_CATEGORY_JAILBREAK",(eg=f||(f={})).HARM_BLOCK_METHOD_UNSPECIFIED="HARM_BLOCK_METHOD_UNSPECIFIED",eg.SEVERITY="SEVERITY",eg.PROBABILITY="PROBABILITY",(ey=m||(m={})).HARM_BLOCK_THRESHOLD_UNSPECIFIED="HARM_BLOCK_THRESHOLD_UNSPECIFIED",ey.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",ey.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",ey.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",ey.BLOCK_NONE="BLOCK_NONE",ey.OFF="OFF",(eE=g||(g={})).FINISH_REASON_UNSPECIFIED="FINISH_REASON_UNSPECIFIED",eE.STOP="STOP",eE.MAX_TOKENS="MAX_TOKENS",eE.SAFETY="SAFETY",eE.RECITATION="RECITATION",eE.LANGUAGE="LANGUAGE",eE.OTHER="OTHER",eE.BLOCKLIST="BLOCKLIST",eE.PROHIBITED_CONTENT="PROHIBITED_CONTENT",eE.SPII="SPII",eE.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",eE.IMAGE_SAFETY="IMAGE_SAFETY",eE.UNEXPECTED_TOOL_CALL="UNEXPECTED_TOOL_CALL",eE.IMAGE_PROHIBITED_CONTENT="IMAGE_PROHIBITED_CONTENT",eE.NO_IMAGE="NO_IMAGE",(ev=y||(y={})).HARM_PROBABILITY_UNSPECIFIED="HARM_PROBABILITY_UNSPECIFIED",ev.NEGLIGIBLE="NEGLIGIBLE",ev.LOW="LOW",ev.MEDIUM="MEDIUM",ev.HIGH="HIGH",(e_=E||(E={})).HARM_SEVERITY_UNSPECIFIED="HARM_SEVERITY_UNSPECIFIED",e_.HARM_SEVERITY_NEGLIGIBLE="HARM_SEVERITY_NEGLIGIBLE",e_.HARM_SEVERITY_LOW="HARM_SEVERITY_LOW",e_.HARM_SEVERITY_MEDIUM="HARM_SEVERITY_MEDIUM",e_.HARM_SEVERITY_HIGH="HARM_SEVERITY_HIGH",(eI=v||(v={})).URL_RETRIEVAL_STATUS_UNSPECIFIED="URL_RETRIEVAL_STATUS_UNSPECIFIED",eI.URL_RETRIEVAL_STATUS_SUCCESS="URL_RETRIEVAL_STATUS_SUCCESS",eI.URL_RETRIEVAL_STATUS_ERROR="URL_RETRIEVAL_STATUS_ERROR",eI.URL_RETRIEVAL_STATUS_PAYWALL="URL_RETRIEVAL_STATUS_PAYWALL",eI.URL_RETRIEVAL_STATUS_UNSAFE="URL_RETRIEVAL_STATUS_UNSAFE",(eT=_||(_={})).BLOCKED_REASON_UNSPECIFIED="BLOCKED_REASON_UNSPECIFIED",eT.SAFETY="SAFETY",eT.OTHER="OTHER",eT.BLOCKLIST="BLOCKLIST",eT.PROHIBITED_CONTENT="PROHIBITED_CONTENT",eT.IMAGE_SAFETY="IMAGE_SAFETY",eT.MODEL_ARMOR="MODEL_ARMOR",eT.JAILBREAK="JAILBREAK",(eA=I||(I={})).TRAFFIC_TYPE_UNSPECIFIED="TRAFFIC_TYPE_UNSPECIFIED",eA.ON_DEMAND="ON_DEMAND",eA.PROVISIONED_THROUGHPUT="PROVISIONED_THROUGHPUT",(eC=T||(T={})).MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",eC.TEXT="TEXT",eC.IMAGE="IMAGE",eC.AUDIO="AUDIO",(eS=A||(A={})).MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",eS.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",eS.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",eS.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH",(eO=C||(C={})).TUNING_MODE_UNSPECIFIED="TUNING_MODE_UNSPECIFIED",eO.TUNING_MODE_FULL="TUNING_MODE_FULL",eO.TUNING_MODE_PEFT_ADAPTER="TUNING_MODE_PEFT_ADAPTER",(eb=S||(S={})).ADAPTER_SIZE_UNSPECIFIED="ADAPTER_SIZE_UNSPECIFIED",eb.ADAPTER_SIZE_ONE="ADAPTER_SIZE_ONE",eb.ADAPTER_SIZE_TWO="ADAPTER_SIZE_TWO",eb.ADAPTER_SIZE_FOUR="ADAPTER_SIZE_FOUR",eb.ADAPTER_SIZE_EIGHT="ADAPTER_SIZE_EIGHT",eb.ADAPTER_SIZE_SIXTEEN="ADAPTER_SIZE_SIXTEEN",eb.ADAPTER_SIZE_THIRTY_TWO="ADAPTER_SIZE_THIRTY_TWO",(eN=O||(O={})).JOB_STATE_UNSPECIFIED="JOB_STATE_UNSPECIFIED",eN.JOB_STATE_QUEUED="JOB_STATE_QUEUED",eN.JOB_STATE_PENDING="JOB_STATE_PENDING",eN.JOB_STATE_RUNNING="JOB_STATE_RUNNING",eN.JOB_STATE_SUCCEEDED="JOB_STATE_SUCCEEDED",eN.JOB_STATE_FAILED="JOB_STATE_FAILED",eN.JOB_STATE_CANCELLING="JOB_STATE_CANCELLING",eN.JOB_STATE_CANCELLED="JOB_STATE_CANCELLED",eN.JOB_STATE_PAUSED="JOB_STATE_PAUSED",eN.JOB_STATE_EXPIRED="JOB_STATE_EXPIRED",eN.JOB_STATE_UPDATING="JOB_STATE_UPDATING",eN.JOB_STATE_PARTIALLY_SUCCEEDED="JOB_STATE_PARTIALLY_SUCCEEDED",(eR=b||(b={})).TUNING_TASK_UNSPECIFIED="TUNING_TASK_UNSPECIFIED",eR.TUNING_TASK_I2V="TUNING_TASK_I2V",eR.TUNING_TASK_T2V="TUNING_TASK_T2V",eR.TUNING_TASK_R2V="TUNING_TASK_R2V",(eP=N||(N={})).MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",eP.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",eP.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",eP.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH",(eD=R||(R={})).FEATURE_SELECTION_PREFERENCE_UNSPECIFIED="FEATURE_SELECTION_PREFERENCE_UNSPECIFIED",eD.PRIORITIZE_QUALITY="PRIORITIZE_QUALITY",eD.BALANCED="BALANCED",eD.PRIORITIZE_COST="PRIORITIZE_COST",(eM=P||(P={})).UNSPECIFIED="UNSPECIFIED",eM.BLOCKING="BLOCKING",eM.NON_BLOCKING="NON_BLOCKING",(eU=D||(D={})).MODE_UNSPECIFIED="MODE_UNSPECIFIED",eU.MODE_DYNAMIC="MODE_DYNAMIC",(ew=M||(M={})).ENVIRONMENT_UNSPECIFIED="ENVIRONMENT_UNSPECIFIED",ew.ENVIRONMENT_BROWSER="ENVIRONMENT_BROWSER",(eq=U||(U={})).MODE_UNSPECIFIED="MODE_UNSPECIFIED",eq.AUTO="AUTO",eq.ANY="ANY",eq.NONE="NONE",eq.VALIDATED="VALIDATED",(ek=w||(w={})).BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",ek.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",ek.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",ek.BLOCK_NONE="BLOCK_NONE",(eG=q||(q={})).DONT_ALLOW="DONT_ALLOW",eG.ALLOW_ADULT="ALLOW_ADULT",eG.ALLOW_ALL="ALLOW_ALL",(eL=k||(k={})).auto="auto",eL.en="en",eL.ja="ja",eL.ko="ko",eL.hi="hi",eL.zh="zh",eL.pt="pt",eL.es="es",(ex=G||(G={})).MASK_MODE_DEFAULT="MASK_MODE_DEFAULT",ex.MASK_MODE_USER_PROVIDED="MASK_MODE_USER_PROVIDED",ex.MASK_MODE_BACKGROUND="MASK_MODE_BACKGROUND",ex.MASK_MODE_FOREGROUND="MASK_MODE_FOREGROUND",ex.MASK_MODE_SEMANTIC="MASK_MODE_SEMANTIC",(eH=L||(L={})).CONTROL_TYPE_DEFAULT="CONTROL_TYPE_DEFAULT",eH.CONTROL_TYPE_CANNY="CONTROL_TYPE_CANNY",eH.CONTROL_TYPE_SCRIBBLE="CONTROL_TYPE_SCRIBBLE",eH.CONTROL_TYPE_FACE_MESH="CONTROL_TYPE_FACE_MESH",(eF=x||(x={})).SUBJECT_TYPE_DEFAULT="SUBJECT_TYPE_DEFAULT",eF.SUBJECT_TYPE_PERSON="SUBJECT_TYPE_PERSON",eF.SUBJECT_TYPE_ANIMAL="SUBJECT_TYPE_ANIMAL",eF.SUBJECT_TYPE_PRODUCT="SUBJECT_TYPE_PRODUCT",(eV=H||(H={})).EDIT_MODE_DEFAULT="EDIT_MODE_DEFAULT",eV.EDIT_MODE_INPAINT_REMOVAL="EDIT_MODE_INPAINT_REMOVAL",eV.EDIT_MODE_INPAINT_INSERTION="EDIT_MODE_INPAINT_INSERTION",eV.EDIT_MODE_OUTPAINT="EDIT_MODE_OUTPAINT",eV.EDIT_MODE_CONTROLLED_EDITING="EDIT_MODE_CONTROLLED_EDITING",eV.EDIT_MODE_STYLE="EDIT_MODE_STYLE",eV.EDIT_MODE_BGSWAP="EDIT_MODE_BGSWAP",eV.EDIT_MODE_PRODUCT_IMAGE="EDIT_MODE_PRODUCT_IMAGE",(ej=F||(F={})).FOREGROUND="FOREGROUND",ej.BACKGROUND="BACKGROUND",ej.PROMPT="PROMPT",ej.SEMANTIC="SEMANTIC",ej.INTERACTIVE="INTERACTIVE",(eB=V||(V={})).ASSET="ASSET",eB.STYLE="STYLE",(eJ=j||(j={})).INSERT="INSERT",eJ.REMOVE="REMOVE",eJ.REMOVE_STATIC="REMOVE_STATIC",eJ.OUTPAINT="OUTPAINT",(eY=B||(B={})).OPTIMIZED="OPTIMIZED",eY.LOSSLESS="LOSSLESS",(eK=J||(J={})).SUPERVISED_FINE_TUNING="SUPERVISED_FINE_TUNING",eK.PREFERENCE_TUNING="PREFERENCE_TUNING",(eW=Y||(Y={})).STATE_UNSPECIFIED="STATE_UNSPECIFIED",eW.STATE_PENDING="STATE_PENDING",eW.STATE_ACTIVE="STATE_ACTIVE",eW.STATE_FAILED="STATE_FAILED",(e$=K||(K={})).STATE_UNSPECIFIED="STATE_UNSPECIFIED",e$.PROCESSING="PROCESSING",e$.ACTIVE="ACTIVE",e$.FAILED="FAILED",(ez=W||(W={})).SOURCE_UNSPECIFIED="SOURCE_UNSPECIFIED",ez.UPLOADED="UPLOADED",ez.GENERATED="GENERATED",(eX=$||($={})).TURN_COMPLETE_REASON_UNSPECIFIED="TURN_COMPLETE_REASON_UNSPECIFIED",eX.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",eX.RESPONSE_REJECTED="RESPONSE_REJECTED",eX.NEED_MORE_INPUT="NEED_MORE_INPUT",(eQ=z||(z={})).MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",eQ.TEXT="TEXT",eQ.IMAGE="IMAGE",eQ.VIDEO="VIDEO",eQ.AUDIO="AUDIO",eQ.DOCUMENT="DOCUMENT",(eZ=X||(X={})).START_SENSITIVITY_UNSPECIFIED="START_SENSITIVITY_UNSPECIFIED",eZ.START_SENSITIVITY_HIGH="START_SENSITIVITY_HIGH",eZ.START_SENSITIVITY_LOW="START_SENSITIVITY_LOW",(e0=Q||(Q={})).END_SENSITIVITY_UNSPECIFIED="END_SENSITIVITY_UNSPECIFIED",e0.END_SENSITIVITY_HIGH="END_SENSITIVITY_HIGH",e0.END_SENSITIVITY_LOW="END_SENSITIVITY_LOW",(e1=Z||(Z={})).ACTIVITY_HANDLING_UNSPECIFIED="ACTIVITY_HANDLING_UNSPECIFIED",e1.START_OF_ACTIVITY_INTERRUPTS="START_OF_ACTIVITY_INTERRUPTS",e1.NO_INTERRUPTION="NO_INTERRUPTION",(e2=ee||(ee={})).TURN_COVERAGE_UNSPECIFIED="TURN_COVERAGE_UNSPECIFIED",e2.TURN_INCLUDES_ONLY_ACTIVITY="TURN_INCLUDES_ONLY_ACTIVITY",e2.TURN_INCLUDES_ALL_INPUT="TURN_INCLUDES_ALL_INPUT",(e6=et||(et={})).SCALE_UNSPECIFIED="SCALE_UNSPECIFIED",e6.C_MAJOR_A_MINOR="C_MAJOR_A_MINOR",e6.D_FLAT_MAJOR_B_FLAT_MINOR="D_FLAT_MAJOR_B_FLAT_MINOR",e6.D_MAJOR_B_MINOR="D_MAJOR_B_MINOR",e6.E_FLAT_MAJOR_C_MINOR="E_FLAT_MAJOR_C_MINOR",e6.E_MAJOR_D_FLAT_MINOR="E_MAJOR_D_FLAT_MINOR",e6.F_MAJOR_D_MINOR="F_MAJOR_D_MINOR",e6.G_FLAT_MAJOR_E_FLAT_MINOR="G_FLAT_MAJOR_E_FLAT_MINOR",e6.G_MAJOR_E_MINOR="G_MAJOR_E_MINOR",e6.A_FLAT_MAJOR_F_MINOR="A_FLAT_MAJOR_F_MINOR",e6.A_MAJOR_G_FLAT_MINOR="A_MAJOR_G_FLAT_MINOR",e6.B_FLAT_MAJOR_G_MINOR="B_FLAT_MAJOR_G_MINOR",e6.B_MAJOR_A_FLAT_MINOR="B_MAJOR_A_FLAT_MINOR",(e4=en||(en={})).MUSIC_GENERATION_MODE_UNSPECIFIED="MUSIC_GENERATION_MODE_UNSPECIFIED",e4.QUALITY="QUALITY",e4.DIVERSITY="DIVERSITY",e4.VOCALIZATION="VOCALIZATION",(e3=ei||(ei={})).PLAYBACK_CONTROL_UNSPECIFIED="PLAYBACK_CONTROL_UNSPECIFIED",e3.PLAY="PLAY",e3.PAUSE="PAUSE",e3.STOP="STOP",e3.RESET_CONTEXT="RESET_CONTEXT";class to{constructor(e){let t={};for(let n of e.headers.entries())t[n[0]]=n[1];this.headers=t,this.responseInternal=e}json(){return this.responseInternal.json()}}class tr{get text(){var e,t,n,i,l,o,r,s;if((null===(i=null===(n=null===(t=null===(e=this.candidates)||void 0===e?void 0:e[0])||void 0===t?void 0:t.content)||void 0===n?void 0:n.parts)||void 0===i?void 0:i.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning text from the first one.");let a="",u=!1,p=[];for(let e of null!==(s=null===(r=null===(o=null===(l=this.candidates)||void 0===l?void 0:l[0])||void 0===o?void 0:o.content)||void 0===r?void 0:r.parts)&&void 0!==s?s:[]){for(let[t,n]of Object.entries(e))"text"!==t&&"thought"!==t&&"thoughtSignature"!==t&&(null!==n||void 0!==n)&&p.push(t);if("string"==typeof e.text){if("boolean"==typeof e.thought&&e.thought)continue;u=!0,a+=e.text}}return p.length>0&&console.warn(`there are non-text parts ${p} in the response, returning concatenation of all text parts. Please refer to the non text parts for a full response from model.`),u?a:void 0}get data(){var e,t,n,i,l,o,r,s;if((null===(i=null===(n=null===(t=null===(e=this.candidates)||void 0===e?void 0:e[0])||void 0===t?void 0:t.content)||void 0===n?void 0:n.parts)||void 0===i?void 0:i.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning data from the first one.");let a="",u=[];for(let e of null!==(s=null===(r=null===(o=null===(l=this.candidates)||void 0===l?void 0:l[0])||void 0===o?void 0:o.content)||void 0===r?void 0:r.parts)&&void 0!==s?s:[]){for(let[t,n]of Object.entries(e))"inlineData"!==t&&(null!==n||void 0!==n)&&u.push(t);e.inlineData&&"string"==typeof e.inlineData.data&&(a+=atob(e.inlineData.data))}return u.length>0&&console.warn(`there are non-data parts ${u} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`),a.length>0?btoa(a):void 0}get functionCalls(){var e,t,n,i,l,o,r,s;if((null===(i=null===(n=null===(t=null===(e=this.candidates)||void 0===e?void 0:e[0])||void 0===t?void 0:t.content)||void 0===n?void 0:n.parts)||void 0===i?void 0:i.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning function calls from the first one.");let a=null===(s=null===(r=null===(o=null===(l=this.candidates)||void 0===l?void 0:l[0])||void 0===o?void 0:o.content)||void 0===r?void 0:r.parts)||void 0===s?void 0:s.filter(e=>e.functionCall).map(e=>e.functionCall).filter(e=>void 0!==e);if((null==a?void 0:a.length)!==0)return a}get executableCode(){var e,t,n,i,l,o,r,s,a;if((null===(i=null===(n=null===(t=null===(e=this.candidates)||void 0===e?void 0:e[0])||void 0===t?void 0:t.content)||void 0===n?void 0:n.parts)||void 0===i?void 0:i.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning executable code from the first one.");let u=null===(s=null===(r=null===(o=null===(l=this.candidates)||void 0===l?void 0:l[0])||void 0===o?void 0:o.content)||void 0===r?void 0:r.parts)||void 0===s?void 0:s.filter(e=>e.executableCode).map(e=>e.executableCode).filter(e=>void 0!==e);if((null==u?void 0:u.length)!==0)return null===(a=null==u?void 0:u[0])||void 0===a?void 0:a.code}get codeExecutionResult(){var e,t,n,i,l,o,r,s,a;if((null===(i=null===(n=null===(t=null===(e=this.candidates)||void 0===e?void 0:e[0])||void 0===t?void 0:t.content)||void 0===n?void 0:n.parts)||void 0===i?void 0:i.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning code execution result from the first one.");let u=null===(s=null===(r=null===(o=null===(l=this.candidates)||void 0===l?void 0:l[0])||void 0===o?void 0:o.content)||void 0===r?void 0:r.parts)||void 0===s?void 0:s.filter(e=>e.codeExecutionResult).map(e=>e.codeExecutionResult).filter(e=>void 0!==e);if((null==u?void 0:u.length)!==0)return null===(a=null==u?void 0:u[0])||void 0===a?void 0:a.output}}class ts{}class ta{}class tu{}class tp{}class td{}class tc{}class th{}class tf{}class tm{}class tg{}class ty{_fromAPIResponse({apiResponse:e,_isVertexAI:t}){let n=new ty;return Object.assign(n,t?function(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["name"],n);let i=tn(e,["metadata"]);null!=i&&tt(t,["metadata"],i);let l=tn(e,["done"]);null!=l&&tt(t,["done"],l);let o=tn(e,["error"]);null!=o&&tt(t,["error"],o);let r=tn(e,["response"]);return null!=r&&tt(t,["response"],function(e){let t={},n=tn(e,["videos"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["_self"]);return null!=n&&tt(t,["video"],function(e){let t={},n=tn(e,["gcsUri"]);null!=n&&tt(t,["uri"],n);let i=tn(e,["bytesBase64Encoded"]);null!=i&&tt(t,["videoBytes"],ti(i));let l=tn(e,["mimeType"]);return null!=l&&tt(t,["mimeType"],l),t}(n)),t})(e))),tt(t,["generatedVideos"],e)}let i=tn(e,["raiMediaFilteredCount"]);null!=i&&tt(t,["raiMediaFilteredCount"],i);let l=tn(e,["raiMediaFilteredReasons"]);return null!=l&&tt(t,["raiMediaFilteredReasons"],l),t}(r)),t}(e):function(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["name"],n);let i=tn(e,["metadata"]);null!=i&&tt(t,["metadata"],i);let l=tn(e,["done"]);null!=l&&tt(t,["done"],l);let o=tn(e,["error"]);null!=o&&tt(t,["error"],o);let r=tn(e,["response","generateVideoResponse"]);return null!=r&&tt(t,["response"],function(e){let t={},n=tn(e,["generatedSamples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["video"]);return null!=n&&tt(t,["video"],function(e){let t={},n=tn(e,["uri"]);null!=n&&tt(t,["uri"],n);let i=tn(e,["encodedVideo"]);null!=i&&tt(t,["videoBytes"],ti(i));let l=tn(e,["encoding"]);return null!=l&&tt(t,["mimeType"],l),t}(n)),t})(e))),tt(t,["generatedVideos"],e)}let i=tn(e,["raiMediaFilteredCount"]);null!=i&&tt(t,["raiMediaFilteredCount"],i);let l=tn(e,["raiMediaFilteredReasons"]);return null!=l&&tt(t,["raiMediaFilteredReasons"],l),t}(r)),t}(e)),n}}class tE{}class tv{}class t_{}class tI{}class tT{}class tA{}class tC{_fromAPIResponse({apiResponse:e,_isVertexAI:t}){let n=new tC;return Object.assign(n,function(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["name"],n);let i=tn(e,["metadata"]);null!=i&&tt(t,["metadata"],i);let l=tn(e,["done"]);null!=l&&tt(t,["done"],l);let o=tn(e,["error"]);null!=o&&tt(t,["error"],o);let r=tn(e,["response"]);return null!=r&&tt(t,["response"],function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["parent"]);null!=i&&tt(t,["parent"],i);let l=tn(e,["documentName"]);return null!=l&&tt(t,["documentName"],l),t}(r)),t}(e)),n}}class tS{}class tO{}class tb{}class tN{}class tR{get text(){var e,t,n;let i="",l=!1,o=[];for(let r of null!==(n=null===(t=null===(e=this.serverContent)||void 0===e?void 0:e.modelTurn)||void 0===t?void 0:t.parts)&&void 0!==n?n:[]){for(let[e,t]of Object.entries(r))"text"!==e&&"thought"!==e&&null!==t&&o.push(e);if("string"==typeof r.text){if("boolean"==typeof r.thought&&r.thought)continue;l=!0,i+=r.text}}return o.length>0&&console.warn(`there are non-text parts ${o} in the response, returning concatenation of all text parts. Please refer to the non text parts for a full response from model.`),l?i:void 0}get data(){var e,t,n;let i="",l=[];for(let o of null!==(n=null===(t=null===(e=this.serverContent)||void 0===e?void 0:e.modelTurn)||void 0===t?void 0:t.parts)&&void 0!==n?n:[]){for(let[e,t]of Object.entries(o))"inlineData"!==e&&null!==t&&l.push(e);o.inlineData&&"string"==typeof o.inlineData.data&&(i+=atob(o.inlineData.data))}return l.length>0&&console.warn(`there are non-data parts ${l} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`),i.length>0?btoa(i):void 0}}class tP{get audioChunk(){if(this.serverContent&&this.serverContent.audioChunks&&this.serverContent.audioChunks.length>0)return this.serverContent.audioChunks[0]}}class tD{_fromAPIResponse({apiResponse:e,_isVertexAI:t}){let n=new tD;return Object.assign(n,tl(e)),n}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function tM(e,t){if(!t||"string"!=typeof t)throw Error("model is required and must be a string");if(t.includes("..")||t.includes("?")||t.includes("&"))throw Error("invalid model parameter");if(e.isVertexAI()){if(t.startsWith("publishers/")||t.startsWith("projects/")||t.startsWith("models/"))return t;if(!(t.indexOf("/")>=0))return`publishers/google/models/${t}`;{let e=t.split("/",2);return`publishers/${e[0]}/models/${e[1]}`}}return t.startsWith("models/")||t.startsWith("tunedModels/")?t:`models/${t}`}function tU(e,t){let n=tM(e,t);return n?n.startsWith("publishers/")&&e.isVertexAI()?`projects/${e.getProject()}/locations/${e.getLocation()}/${n}`:n.startsWith("models/")&&e.isVertexAI()?`projects/${e.getProject()}/locations/${e.getLocation()}/publishers/google/${n}`:n:""}function tw(e){return Array.isArray(e)?e.map(e=>tq(e)):[tq(e)]}function tq(e){if("object"==typeof e&&null!==e)return e;throw Error(`Could not parse input as Blob. Unsupported blob type: ${typeof e}`)}function tk(e){let t=tq(e);if(t.mimeType&&t.mimeType.startsWith("image/"))return t;throw Error(`Unsupported mime type: ${t.mimeType}`)}function tG(e){let t=tq(e);if(t.mimeType&&t.mimeType.startsWith("audio/"))return t;throw Error(`Unsupported mime type: ${t.mimeType}`)}function tL(e){if(null==e)throw Error("PartUnion is required");if("object"==typeof e)return e;if("string"==typeof e)return{text:e};throw Error(`Unsupported part type: ${typeof e}`)}function tx(e){if(null==e||Array.isArray(e)&&0===e.length)throw Error("PartListUnion is required");return Array.isArray(e)?e.map(e=>tL(e)):[tL(e)]}function tH(e){return null!=e&&"object"==typeof e&&"parts"in e&&Array.isArray(e.parts)}function tF(e){return null!=e&&"object"==typeof e&&"functionCall"in e}function tV(e){return null!=e&&"object"==typeof e&&"functionResponse"in e}function tj(e){if(null==e)throw Error("ContentUnion is required");return tH(e)?e:{role:"user",parts:tx(e)}}function tB(e,t){if(!t)return[];if(e.isVertexAI()&&Array.isArray(t))return t.flatMap(e=>{let t=tj(e);return t.parts&&t.parts.length>0&&void 0!==t.parts[0].text?[t.parts[0].text]:[]});if(e.isVertexAI()){let e=tj(t);return e.parts&&e.parts.length>0&&void 0!==e.parts[0].text?[e.parts[0].text]:[]}return Array.isArray(t)?t.map(e=>tj(e)):[tj(t)]}function tJ(e){if(null==e||Array.isArray(e)&&0===e.length)throw Error("contents are required");if(!Array.isArray(e)){if(tF(e)||tV(e))throw Error("To specify functionCall or functionResponse parts, please wrap them in a Content object, specifying the role for them");return[tj(e)]}let t=[],n=[],i=tH(e[0]);for(let l of e){let e=tH(l);if(e!=i)throw Error("Mixing Content and Parts is not supported, please group the parts into a the appropriate Content objects and specify the roles for them");if(e)t.push(l);else if(tF(l)||tV(l))throw Error("To specify functionCall or functionResponse parts, please wrap them, and any other parts, in Content objects as appropriate, specifying the role for them");else n.push(l)}return i||t.push({role:"user",parts:tx(n)}),t}function tY(e){let t={},n=["items"],i=["anyOf"],l=["properties"];if(e.type&&e.anyOf)throw Error("type and anyOf cannot be both populated.");let o=e.anyOf;for(let[s,a]of(null!=o&&2==o.length&&("null"===o[0].type?(t.nullable=!0,e=o[1]):"null"===o[1].type&&(t.nullable=!0,e=o[0])),e.type instanceof Array&&function(e,t){e.includes("null")&&(t.nullable=!0);let n=e.filter(e=>"null"!==e);if(1===n.length)t.type=Object.values(r).includes(n[0].toUpperCase())?n[0].toUpperCase():r.TYPE_UNSPECIFIED;else for(let e of(t.anyOf=[],n))t.anyOf.push({type:Object.values(r).includes(e.toUpperCase())?e.toUpperCase():r.TYPE_UNSPECIFIED})}(e.type,t),Object.entries(e)))if(null!=a){if("type"==s){if("null"===a)throw Error("type: null can not be the only possible type for the field.");if(a instanceof Array)continue;t.type=Object.values(r).includes(a.toUpperCase())?a.toUpperCase():r.TYPE_UNSPECIFIED}else if(n.includes(s))t[s]=tY(a);else if(i.includes(s)){let e=[];for(let n of a){if("null"==n.type){t.nullable=!0;continue}e.push(tY(n))}t[s]=e}else if(l.includes(s)){let e={};for(let[t,n]of Object.entries(a))e[t]=tY(n);t[s]=e}else{if("additionalProperties"===s)continue;t[s]=a}}return t}function tK(e){if("object"==typeof e)return e;if("string"==typeof e)return{voiceConfig:{prebuiltVoiceConfig:{voiceName:e}}};throw Error(`Unsupported speechConfig type: ${typeof e}`)}function tW(e){if("multiSpeakerVoiceConfig"in e)throw Error("multiSpeakerVoiceConfig is not supported in the live API.");return e}function t$(e){if(e.functionDeclarations)for(let t of e.functionDeclarations)t.parameters&&(Object.keys(t.parameters).includes("$schema")?t.parametersJsonSchema||(t.parametersJsonSchema=t.parameters,delete t.parameters):t.parameters=tY(t.parameters)),t.response&&(Object.keys(t.response).includes("$schema")?t.responseJsonSchema||(t.responseJsonSchema=t.response,delete t.response):t.response=tY(t.response));return e}function tz(e){if(null==e)throw Error("tools is required");if(!Array.isArray(e))throw Error("tools is required and must be an array of Tools");let t=[];for(let n of e)t.push(n);return t}function tX(e,t){if("string"!=typeof t)throw Error("name must be a string");return function(e,t,n,i=1){let l=!t.startsWith(`${n}/`)&&t.split("/").length===i;if(e.isVertexAI())return t.startsWith("projects/")?t:t.startsWith("locations/")?`projects/${e.getProject()}/${t}`:t.startsWith(`${n}/`)?`projects/${e.getProject()}/locations/${e.getLocation()}/${t}`:l?`projects/${e.getProject()}/locations/${e.getLocation()}/${n}/${t}`:t;return l?`${n}/${t}`:t}(e,t,"cachedContents")}function tQ(e){switch(e){case"STATE_UNSPECIFIED":return"JOB_STATE_UNSPECIFIED";case"CREATING":return"JOB_STATE_RUNNING";case"ACTIVE":return"JOB_STATE_SUCCEEDED";case"FAILED":return"JOB_STATE_FAILED";default:return e}}function tZ(e){var t;let n;if(null!=e&&"object"==typeof e&&"name"in e&&(n=e.name),(null==e||"object"!=typeof e||!("uri"in e)||void 0!==(n=e.uri))&&(null==e||"object"!=typeof e||!("video"in e)||void 0!==(n=null===(t=e.video)||void 0===t?void 0:t.uri))){if("string"==typeof e&&(n=e),void 0===n)throw Error("Could not extract file name from the provided input.");if(n.startsWith("https://")){let e=n.split("files/")[1].match(/[a-z0-9]+/);if(null===e)throw Error(`Could not extract file name from URI ${n}`);n=e[0]}else n.startsWith("files/")&&(n=n.split("files/")[1]);return n}}function t0(e,t){return e.isVertexAI()?t?"publishers/google/models":"models":t?"models":"tunedModels"}function t1(e){for(let t of["models","tunedModels","publisherModels"]){if(null!==e&&"object"==typeof e&&t in e)return e[t]}return[]}function t2(e,t){let n;if("string"==typeof t){if(e.isVertexAI()){if(t.startsWith("gs://"))n={format:"jsonl",gcsUri:[t]};else if(t.startsWith("bq://"))n={format:"bigquery",bigqueryUri:t};else throw Error(`Unsupported string source for Vertex AI: ${t}`)}else if(t.startsWith("files/"))n={fileName:t};else throw Error(`Unsupported string source for Gemini API: ${t}`)}else if(Array.isArray(t)){if(e.isVertexAI())throw Error("InlinedRequest[] is not supported in Vertex AI.");n={inlinedRequests:t}}else n=t;let i=[n.gcsUri,n.bigqueryUri].filter(Boolean).length,l=[n.inlinedRequests,n.fileName].filter(Boolean).length;if(e.isVertexAI()){if(l>0||1!==i)throw Error("Exactly one of `gcsUri` or `bigqueryUri` must be set for Vertex AI.")}else if(i>0||1!==l)throw Error("Exactly one of `inlinedRequests`, `fileName`, must be set for Gemini API.");return n}function t6(e){if("object"!=typeof e||null===e)return{};let t=e.inlinedResponses;if("object"!=typeof t||null===t)return e;let n=t.inlinedResponses;if(!Array.isArray(n)||0===n.length)return e;let i=!1;for(let e of n){if("object"!=typeof e||null===e)continue;let t=e.response;if("object"==typeof t&&null!==t&&void 0!==t.embedding){i=!0;break}}return i&&(e.inlinedEmbedContentResponses=e.inlinedResponses,delete e.inlinedResponses),e}function t4(e,t){if(!e.isVertexAI()){if(/batches\/[^/]+$/.test(t))return t.split("/").pop();throw Error(`Invalid batch job name: ${t}.`)}if(/^projects\/[^/]+\/locations\/[^/]+\/batchPredictionJobs\/[^/]+$/.test(t))return t.split("/").pop();if(/^\d+$/.test(t))return t;throw Error(`Invalid batch job name: ${t}.`)}function t3(e){if("BATCH_STATE_UNSPECIFIED"===e)return"JOB_STATE_UNSPECIFIED";if("BATCH_STATE_PENDING"===e)return"JOB_STATE_PENDING";if("BATCH_STATE_RUNNING"===e)return"JOB_STATE_RUNNING";if("BATCH_STATE_SUCCEEDED"===e)return"JOB_STATE_SUCCEEDED";if("BATCH_STATE_FAILED"===e)return"JOB_STATE_FAILED";if("BATCH_STATE_CANCELLED"===e)return"JOB_STATE_CANCELLED";if("BATCH_STATE_EXPIRED"===e)return"JOB_STATE_EXPIRED";else return e}function t8(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["name"],n);let i=tn(e,["metadata","displayName"]);null!=i&&tt(t,["displayName"],i);let l=tn(e,["metadata","state"]);null!=l&&tt(t,["state"],t3(l));let o=tn(e,["metadata","createTime"]);null!=o&&tt(t,["createTime"],o);let r=tn(e,["metadata","endTime"]);null!=r&&tt(t,["endTime"],r);let s=tn(e,["metadata","updateTime"]);null!=s&&tt(t,["updateTime"],s);let a=tn(e,["metadata","model"]);null!=a&&tt(t,["model"],a);let u=tn(e,["metadata","output"]);return null!=u&&tt(t,["dest"],/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function(e){let t={},n=tn(e,["responsesFile"]);null!=n&&tt(t,["fileName"],n);let i=tn(e,["inlinedResponses","inlinedResponses"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["response"]);null!=n&&tt(t,["response"],function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["candidates"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["content"]);null!=n&&tt(t,["content"],n);let i=tn(e,["citationMetadata"]);null!=i&&tt(t,["citationMetadata"],function(e){let t={},n=tn(e,["citationSources"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["citations"],e)}return t}(i));let l=tn(e,["tokenCount"]);null!=l&&tt(t,["tokenCount"],l);let o=tn(e,["finishReason"]);null!=o&&tt(t,["finishReason"],o);let r=tn(e,["avgLogprobs"]);null!=r&&tt(t,["avgLogprobs"],r);let s=tn(e,["groundingMetadata"]);null!=s&&tt(t,["groundingMetadata"],s);let a=tn(e,["index"]);null!=a&&tt(t,["index"],a);let u=tn(e,["logprobsResult"]);null!=u&&tt(t,["logprobsResult"],u);let p=tn(e,["safetyRatings"]);if(null!=p){let e=p;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["safetyRatings"],e)}let d=tn(e,["urlContextMetadata"]);return null!=d&&tt(t,["urlContextMetadata"],d),t})(e))),tt(t,["candidates"],e)}let l=tn(e,["modelVersion"]);null!=l&&tt(t,["modelVersion"],l);let o=tn(e,["promptFeedback"]);null!=o&&tt(t,["promptFeedback"],o);let r=tn(e,["responseId"]);null!=r&&tt(t,["responseId"],r);let s=tn(e,["usageMetadata"]);return null!=s&&tt(t,["usageMetadata"],s),t}(n));let i=tn(e,["error"]);return null!=i&&tt(t,["error"],i),t})(e))),tt(t,["inlinedResponses"],e)}let l=tn(e,["inlinedEmbedContentResponses","inlinedResponses"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["inlinedEmbedContentResponses"],e)}return t}(t6(u))),t}function t9(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["name"],n);let i=tn(e,["displayName"]);null!=i&&tt(t,["displayName"],i);let l=tn(e,["state"]);null!=l&&tt(t,["state"],t3(l));let o=tn(e,["error"]);null!=o&&tt(t,["error"],o);let r=tn(e,["createTime"]);null!=r&&tt(t,["createTime"],r);let s=tn(e,["startTime"]);null!=s&&tt(t,["startTime"],s);let a=tn(e,["endTime"]);null!=a&&tt(t,["endTime"],a);let u=tn(e,["updateTime"]);null!=u&&tt(t,["updateTime"],u);let p=tn(e,["model"]);null!=p&&tt(t,["model"],p);let d=tn(e,["inputConfig"]);null!=d&&tt(t,["src"],function(e){let t={},n=tn(e,["instancesFormat"]);null!=n&&tt(t,["format"],n);let i=tn(e,["gcsSource","uris"]);null!=i&&tt(t,["gcsUri"],i);let l=tn(e,["bigquerySource","inputUri"]);return null!=l&&tt(t,["bigqueryUri"],l),t}(d));let c=tn(e,["outputConfig"]);null!=c&&tt(t,["dest"],function(e){let t={},n=tn(e,["predictionsFormat"]);null!=n&&tt(t,["format"],n);let i=tn(e,["gcsDestination","outputUriPrefix"]);null!=i&&tt(t,["gcsUri"],i);let l=tn(e,["bigqueryDestination","outputUri"]);return null!=l&&tt(t,["bigqueryUri"],l),t}(t6(c)));let h=tn(e,["completionStats"]);return null!=h&&tt(t,["completionStats"],h),t}function t5(e){let t={},n=tn(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["mediaResolution"]);null!=n&&tt(t,["mediaResolution"],n);let i=tn(e,["codeExecutionResult"]);null!=i&&tt(t,["codeExecutionResult"],i);let l=tn(e,["executableCode"]);null!=l&&tt(t,["executableCode"],l);let o=tn(e,["fileData"]);null!=o&&tt(t,["fileData"],function(e){let t={};if(void 0!==tn(e,["displayName"]))throw Error("displayName parameter is not supported in Gemini API.");let n=tn(e,["fileUri"]);null!=n&&tt(t,["fileUri"],n);let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}(o));let r=tn(e,["functionCall"]);null!=r&&tt(t,["functionCall"],function(e){let t={},n=tn(e,["id"]);null!=n&&tt(t,["id"],n);let i=tn(e,["args"]);null!=i&&tt(t,["args"],i);let l=tn(e,["name"]);if(null!=l&&tt(t,["name"],l),void 0!==tn(e,["partialArgs"]))throw Error("partialArgs parameter is not supported in Gemini API.");if(void 0!==tn(e,["willContinue"]))throw Error("willContinue parameter is not supported in Gemini API.");return t}(r));let s=tn(e,["functionResponse"]);null!=s&&tt(t,["functionResponse"],s);let a=tn(e,["inlineData"]);null!=a&&tt(t,["inlineData"],function(e){let t={},n=tn(e,["data"]);if(null!=n&&tt(t,["data"],n),void 0!==tn(e,["displayName"]))throw Error("displayName parameter is not supported in Gemini API.");let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}(a));let u=tn(e,["text"]);null!=u&&tt(t,["text"],u);let p=tn(e,["thought"]);null!=p&&tt(t,["thought"],p);let d=tn(e,["thoughtSignature"]);null!=d&&tt(t,["thoughtSignature"],d);let c=tn(e,["videoMetadata"]);return null!=c&&tt(t,["videoMetadata"],c),t})(e))),tt(t,["parts"],e)}let i=tn(e,["role"]);return null!=i&&tt(t,["role"],i),t}function t7(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["src"]);null!=l&&tt(n,["batch","inputConfig"],function(e,t){let n={};if(void 0!==tn(t,["format"]))throw Error("format parameter is not supported in Gemini API.");if(void 0!==tn(t,["gcsUri"]))throw Error("gcsUri parameter is not supported in Gemini API.");if(void 0!==tn(t,["bigqueryUri"]))throw Error("bigqueryUri parameter is not supported in Gemini API.");let i=tn(t,["fileName"]);null!=i&&tt(n,["fileName"],i);let l=tn(t,["inlinedRequests"]);if(null!=l){let t=l;Array.isArray(t)&&(t=t.map(t=>(function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["request","model"],tM(e,i));let l=tn(t,["contents"]);if(null!=l){let e=tJ(l);Array.isArray(e)&&(e=e.map(e=>t5(e))),tt(n,["request","contents"],e)}let o=tn(t,["metadata"]);null!=o&&tt(n,["metadata"],o);let r=tn(t,["config"]);return null!=r&&tt(n,["request","generationConfig"],function(e,t,n){let i={},l=tn(t,["systemInstruction"]);void 0!==n&&null!=l&&tt(n,["systemInstruction"],t5(tj(l)));let o=tn(t,["temperature"]);null!=o&&tt(i,["temperature"],o);let r=tn(t,["topP"]);null!=r&&tt(i,["topP"],r);let s=tn(t,["topK"]);null!=s&&tt(i,["topK"],s);let a=tn(t,["candidateCount"]);null!=a&&tt(i,["candidateCount"],a);let u=tn(t,["maxOutputTokens"]);null!=u&&tt(i,["maxOutputTokens"],u);let p=tn(t,["stopSequences"]);null!=p&&tt(i,["stopSequences"],p);let d=tn(t,["responseLogprobs"]);null!=d&&tt(i,["responseLogprobs"],d);let c=tn(t,["logprobs"]);null!=c&&tt(i,["logprobs"],c);let h=tn(t,["presencePenalty"]);null!=h&&tt(i,["presencePenalty"],h);let f=tn(t,["frequencyPenalty"]);null!=f&&tt(i,["frequencyPenalty"],f);let m=tn(t,["seed"]);null!=m&&tt(i,["seed"],m);let g=tn(t,["responseMimeType"]);null!=g&&tt(i,["responseMimeType"],g);let y=tn(t,["responseSchema"]);null!=y&&tt(i,["responseSchema"],tY(y));let E=tn(t,["responseJsonSchema"]);if(null!=E&&tt(i,["responseJsonSchema"],E),void 0!==tn(t,["routingConfig"]))throw Error("routingConfig parameter is not supported in Gemini API.");if(void 0!==tn(t,["modelSelectionConfig"]))throw Error("modelSelectionConfig parameter is not supported in Gemini API.");let v=tn(t,["safetySettings"]);if(void 0!==n&&null!=v){let e=v;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["category"]);if(null!=n&&tt(t,["category"],n),void 0!==tn(e,["method"]))throw Error("method parameter is not supported in Gemini API.");let i=tn(e,["threshold"]);return null!=i&&tt(t,["threshold"],i),t})(e))),tt(n,["safetySettings"],e)}let _=tn(t,["tools"]);if(void 0!==n&&null!=_){let e=tz(_);Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["functionDeclarations"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["functionDeclarations"],e)}if(void 0!==tn(e,["retrieval"]))throw Error("retrieval parameter is not supported in Gemini API.");let i=tn(e,["googleSearchRetrieval"]);null!=i&&tt(t,["googleSearchRetrieval"],i);let l=tn(e,["computerUse"]);null!=l&&tt(t,["computerUse"],l);let o=tn(e,["fileSearch"]);null!=o&&tt(t,["fileSearch"],o);let r=tn(e,["codeExecution"]);if(null!=r&&tt(t,["codeExecution"],r),void 0!==tn(e,["enterpriseWebSearch"]))throw Error("enterpriseWebSearch parameter is not supported in Gemini API.");let s=tn(e,["googleMaps"]);null!=s&&tt(t,["googleMaps"],function(e){let t={};if(void 0!==tn(e,["authConfig"]))throw Error("authConfig parameter is not supported in Gemini API.");let n=tn(e,["enableWidget"]);return null!=n&&tt(t,["enableWidget"],n),t}(s));let a=tn(e,["googleSearch"]);null!=a&&tt(t,["googleSearch"],function(e){let t={};if(void 0!==tn(e,["excludeDomains"]))throw Error("excludeDomains parameter is not supported in Gemini API.");if(void 0!==tn(e,["blockingConfidence"]))throw Error("blockingConfidence parameter is not supported in Gemini API.");let n=tn(e,["timeRangeFilter"]);return null!=n&&tt(t,["timeRangeFilter"],n),t}(a));let u=tn(e,["urlContext"]);return null!=u&&tt(t,["urlContext"],u),t})(t$(e)))),tt(n,["tools"],e)}let I=tn(t,["toolConfig"]);if(void 0!==n&&null!=I&&tt(n,["toolConfig"],function(e){let t={},n=tn(e,["functionCallingConfig"]);null!=n&&tt(t,["functionCallingConfig"],function(e){let t={},n=tn(e,["mode"]);null!=n&&tt(t,["mode"],n);let i=tn(e,["allowedFunctionNames"]);if(null!=i&&tt(t,["allowedFunctionNames"],i),void 0!==tn(e,["streamFunctionCallArguments"]))throw Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return t}(n));let i=tn(e,["retrievalConfig"]);return null!=i&&tt(t,["retrievalConfig"],i),t}(I)),void 0!==tn(t,["labels"]))throw Error("labels parameter is not supported in Gemini API.");let T=tn(t,["cachedContent"]);void 0!==n&&null!=T&&tt(n,["cachedContent"],tX(e,T));let A=tn(t,["responseModalities"]);null!=A&&tt(i,["responseModalities"],A);let C=tn(t,["mediaResolution"]);null!=C&&tt(i,["mediaResolution"],C);let S=tn(t,["speechConfig"]);if(null!=S&&tt(i,["speechConfig"],tK(S)),void 0!==tn(t,["audioTimestamp"]))throw Error("audioTimestamp parameter is not supported in Gemini API.");let O=tn(t,["thinkingConfig"]);null!=O&&tt(i,["thinkingConfig"],O);let b=tn(t,["imageConfig"]);return null!=b&&tt(i,["imageConfig"],function(e){let t={},n=tn(e,["aspectRatio"]);null!=n&&tt(t,["aspectRatio"],n);let i=tn(e,["imageSize"]);if(null!=i&&tt(t,["imageSize"],i),void 0!==tn(e,["outputMimeType"]))throw Error("outputMimeType parameter is not supported in Gemini API.");if(void 0!==tn(e,["outputCompressionQuality"]))throw Error("outputCompressionQuality parameter is not supported in Gemini API.");return t}(b)),i}(e,r,tn(n,["request"],{}))),n})(e,t))),tt(n,["requests","requests"],t)}return n}(e,t2(e,l)));let o=tn(t,["config"]);return null!=o&&function(e,t){let n=tn(e,["displayName"]);if(void 0!==t&&null!=n&&tt(t,["batch","displayName"],n),void 0!==tn(e,["dest"]))throw Error("dest parameter is not supported in Gemini API.")}(o,n),n}(e8=el||(el={})).PAGED_ITEM_BATCH_JOBS="batchJobs",e8.PAGED_ITEM_MODELS="models",e8.PAGED_ITEM_TUNING_JOBS="tuningJobs",e8.PAGED_ITEM_FILES="files",e8.PAGED_ITEM_CACHED_CONTENTS="cachedContents",e8.PAGED_ITEM_FILE_SEARCH_STORES="fileSearchStores",e8.PAGED_ITEM_DOCUMENTS="documents";class ne{constructor(e,t,n,i){this.pageInternal=[],this.paramsInternal={},this.requestInternal=t,this.init(e,n,i)}init(e,t,n){var i,l;this.nameInternal=e,this.pageInternal=t[this.nameInternal]||[],this.sdkHttpResponseInternal=null==t?void 0:t.sdkHttpResponse,this.idxInternal=0;let o={config:{}};(o=n&&0!==Object.keys(n).length?"object"==typeof n?Object.assign({},n):n:{config:{}}).config&&(o.config.pageToken=t.nextPageToken),this.paramsInternal=o,this.pageInternalSize=null!==(l=null===(i=o.config)||void 0===i?void 0:i.pageSize)&&void 0!==l?l:this.pageInternal.length}initNextPage(e){this.init(this.nameInternal,e,this.paramsInternal)}get page(){return this.pageInternal}get name(){return this.nameInternal}get pageSize(){return this.pageInternalSize}get sdkHttpResponse(){return this.sdkHttpResponseInternal}get params(){return this.paramsInternal}get pageLength(){return this.pageInternal.length}getItem(e){return this.pageInternal[e]}[Symbol.asyncIterator](){return{next:async()=>{if(this.idxInternal>=this.pageLength){if(!this.hasNextPage())return{value:void 0,done:!0};await this.nextPage()}let e=this.getItem(this.idxInternal);return this.idxInternal+=1,{value:e,done:!1}},return:async()=>({value:void 0,done:!0})}}async nextPage(){if(!this.hasNextPage())throw Error("No more pages to fetch.");let e=await this.requestInternal(this.params);return this.initNextPage(e),this.page}hasNextPage(){var e;return(null===(e=this.params.config)||void 0===e?void 0:e.pageToken)!==void 0}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class nt extends e7{constructor(e){super(),this.apiClient=e,this.create=async e=>(this.apiClient.isVertexAI()&&(e.config=this.formatDestination(e.src,e.config)),this.createInternal(e)),this.createEmbeddings=async e=>{if(console.warn("batches.createEmbeddings() is experimental and may change without notice."),this.apiClient.isVertexAI())throw Error("Vertex AI does not support batches.createEmbeddings.");return this.createEmbeddingsInternal(e)},this.list=async(e={})=>new ne(el.PAGED_ITEM_BATCH_JOBS,e=>this.listInternal(e),await this.listInternal(e),e)}createInlinedGenerateContentRequest(e){let t=t7(this.apiClient,e),n=te("{model}:batchGenerateContent",t._url),i=t.batch.inputConfig.requests,l=i.requests,o=[];for(let e of l){let t=Object.assign({},e);if(t.systemInstruction){let e=t.systemInstruction;delete t.systemInstruction;let n=t.request;n.systemInstruction=e,t.request=n}o.push(t)}return i.requests=o,delete t.config,delete t._url,delete t._query,{path:n,body:t}}getGcsUri(e){return"string"==typeof e?e.startsWith("gs://")?e:void 0:!Array.isArray(e)&&e.gcsUri&&e.gcsUri.length>0?e.gcsUri[0]:void 0}getBigqueryUri(e){return"string"==typeof e?e.startsWith("bq://")?e:void 0:Array.isArray(e)?void 0:e.bigqueryUri}formatDestination(e,t){let n=t?Object.assign({},t):{},i=Date.now().toString();if(n.displayName||(n.displayName=`genaiBatchJob_${i}`),void 0===n.dest){let t=this.getGcsUri(e),l=this.getBigqueryUri(e);if(t)t.endsWith(".jsonl")?n.dest=`${t.slice(0,-6)}/dest`:n.dest=`${t}_dest_${i}`;else if(l)n.dest=`${l}_dest_${i}`;else throw Error("Unsupported source for Vertex AI: No GCS or BigQuery URI found.")}return n}async createInternal(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["model"],tM(e,i));let l=tn(t,["src"]);null!=l&&tt(n,["inputConfig"],function(e){let t={},n=tn(e,["format"]);null!=n&&tt(t,["instancesFormat"],n);let i=tn(e,["gcsUri"]);null!=i&&tt(t,["gcsSource","uris"],i);let l=tn(e,["bigqueryUri"]);if(null!=l&&tt(t,["bigquerySource","inputUri"],l),void 0!==tn(e,["fileName"]))throw Error("fileName parameter is not supported in Vertex AI.");if(void 0!==tn(e,["inlinedRequests"]))throw Error("inlinedRequests parameter is not supported in Vertex AI.");return t}(t2(e,l)));let o=tn(t,["config"]);return null!=o&&function(e,t){let n=tn(e,["displayName"]);void 0!==t&&null!=n&&tt(t,["displayName"],n);let i=tn(e,["dest"]);void 0!==t&&null!=i&&tt(t,["outputConfig"],function(e){let t={},n=tn(e,["format"]);null!=n&&tt(t,["predictionsFormat"],n);let i=tn(e,["gcsUri"]);null!=i&&tt(t,["gcsDestination","outputUriPrefix"],i);let l=tn(e,["bigqueryUri"]);if(null!=l&&tt(t,["bigqueryDestination","outputUri"],l),void 0!==tn(e,["fileName"]))throw Error("fileName parameter is not supported in Vertex AI.");if(void 0!==tn(e,["inlinedResponses"]))throw Error("inlinedResponses parameter is not supported in Vertex AI.");if(void 0!==tn(e,["inlinedEmbedContentResponses"]))throw Error("inlinedEmbedContentResponses parameter is not supported in Vertex AI.");return t}(function(e){if("string"!=typeof e)return e;if(e.startsWith("gs://"))return{format:"jsonl",gcsUri:e};if(e.startsWith("bq://"))return{format:"bigquery",bigqueryUri:e};throw Error(`Unsupported destination: ${e}`)}(i)))}(o,n),n}(this.apiClient,e);return o=te("batchPredictionJobs",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>t9(e))}{let t=t7(this.apiClient,e);return o=te("{model}:batchGenerateContent",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json()).then(e=>t8(e))}}async createEmbeddingsInternal(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["src"]);null!=l&&tt(n,["batch","inputConfig"],function(e,t){let n={},i=tn(t,["fileName"]);null!=i&&tt(n,["file_name"],i);let l=tn(t,["inlinedRequests"]);return null!=l&&tt(n,["requests"],function(e,t){let n={},i=tn(t,["contents"]);if(null!=i){let t=tB(e,i);Array.isArray(t)&&(t=t.map(e=>e)),tt(n,["requests[]","request","content"],t)}let l=tn(t,["config"]);return null!=l&&(tt(n,["_self"],function(e,t){let n=tn(e,["taskType"]);void 0!==t&&null!=n&&tt(t,["requests[]","taskType"],n);let i=tn(e,["title"]);void 0!==t&&null!=i&&tt(t,["requests[]","title"],i);let l=tn(e,["outputDimensionality"]);if(void 0!==t&&null!=l&&tt(t,["requests[]","outputDimensionality"],l),void 0!==tn(e,["mimeType"]))throw Error("mimeType parameter is not supported in Gemini API.");if(void 0!==tn(e,["autoTruncate"]))throw Error("autoTruncate parameter is not supported in Gemini API.");return{}}(l,n)),function(e,t){for(let[n,i]of Object.entries(t)){let t=n.split("."),l=i.split("."),o=new Set,r=-1;for(let e=0;e<t.length;e++)if("*"===t[e]){r=e;break}if(-1!==r&&l.length>r)for(let e=r;e<l.length;e++){let t=l[e];"*"===t||t.endsWith("[]")||t.endsWith("[0]")||o.add(t)}(function e(t,n,i,l,o){if(l>=n.length||"object"!=typeof t||null===t)return;let r=n[l];if(r.endsWith("[]")){let s=r.slice(0,-2);if(s in t&&Array.isArray(t[s]))for(let r of t[s])e(r,n,i,l+1,o)}else if("*"===r){if("object"==typeof t&&null!==t&&!Array.isArray(t)){let e=Object.keys(t).filter(e=>!e.startsWith("_")&&!o.has(e)),n={};for(let i of e)n[i]=t[i];for(let[e,o]of Object.entries(n)){let n=[];for(let t of i.slice(l))"*"===t?n.push(e):n.push(t);tt(t,n,o)}for(let n of e)delete t[n]}}else r in t&&e(t[r],n,i,l+1,o)})(e,t,l,0,o)}}(n,{"requests[].*":"requests[].request.*"})),n}(e,l)),n}(e,l));let o=tn(t,["config"]);return null!=o&&function(e,t){let n=tn(e,["displayName"]);void 0!==t&&null!=n&&tt(t,["batch","displayName"],n)}(o,n),n}(this.apiClient,e);return i=te("{model}:asyncBatchEmbedContent",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>t8(e))}}async get(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["name"]);return null!=i&&tt(n,["_url","name"],t4(e,i)),n}(this.apiClient,e);return o=te("batchPredictionJobs/{name}",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>t9(e))}{let t=function(e,t){let n={},i=tn(t,["name"]);return null!=i&&tt(n,["_url","name"],t4(e,i)),n}(this.apiClient,e);return o=te("batches/{name}",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json()).then(e=>t8(e))}}async cancel(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["name"]);return null!=i&&tt(n,["_url","name"],t4(e,i)),n}(this.apiClient,e);o=te("batchPredictionJobs/{name}:cancel",i._url),r=i._query,delete i._url,delete i._query,await this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal})}else{let t=function(e,t){let n={},i=tn(t,["name"]);return null!=i&&tt(n,["_url","name"],t4(e,i)),n}(this.apiClient,e);o=te("batches/{name}:cancel",t._url),r=t._query,delete t._url,delete t._query,await this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal})}}async listInternal(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e){let t={},n=tn(e,["config"]);return null!=n&&function(e,t){let n=tn(e,["pageSize"]);void 0!==t&&null!=n&&tt(t,["_query","pageSize"],n);let i=tn(e,["pageToken"]);void 0!==t&&null!=i&&tt(t,["_query","pageToken"],i);let l=tn(e,["filter"]);void 0!==t&&null!=l&&tt(t,["_query","filter"],l)}(n,t),t}(e);return o=te("batchPredictionJobs",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["nextPageToken"]);null!=i&&tt(t,["nextPageToken"],i);let l=tn(e,["batchPredictionJobs"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>t9(e))),tt(t,["batchJobs"],e)}return t}(e),n=new tN;return Object.assign(n,t),n})}{let t=function(e){let t={},n=tn(e,["config"]);return null!=n&&function(e,t){let n=tn(e,["pageSize"]);void 0!==t&&null!=n&&tt(t,["_query","pageSize"],n);let i=tn(e,["pageToken"]);if(void 0!==t&&null!=i&&tt(t,["_query","pageToken"],i),void 0!==tn(e,["filter"]))throw Error("filter parameter is not supported in Gemini API.")}(n,t),t}(e);return o=te("batches",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["nextPageToken"]);null!=i&&tt(t,["nextPageToken"],i);let l=tn(e,["operations"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>t8(e))),tt(t,["batchJobs"],e)}return t}(e),n=new tN;return Object.assign(n,t),n})}}async delete(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["name"]);return null!=i&&tt(n,["_url","name"],t4(e,i)),n}(this.apiClient,e);return o=te("batchPredictionJobs/{name}",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"DELETE",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>(function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["name"]);null!=i&&tt(t,["name"],i);let l=tn(e,["done"]);null!=l&&tt(t,["done"],l);let o=tn(e,["error"]);return null!=o&&tt(t,["error"],o),t})(e))}{let t=function(e,t){let n={},i=tn(t,["name"]);return null!=i&&tt(n,["_url","name"],t4(e,i)),n}(this.apiClient,e);return o=te("batches/{name}",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"DELETE",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>(function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["name"]);null!=i&&tt(t,["name"],i);let l=tn(e,["done"]);null!=l&&tt(t,["done"],l);let o=tn(e,["error"]);return null!=o&&tt(t,["error"],o),t})(e))}}}function nn(e){let t={},n=tn(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["mediaResolution"]);null!=n&&tt(t,["mediaResolution"],n);let i=tn(e,["codeExecutionResult"]);null!=i&&tt(t,["codeExecutionResult"],i);let l=tn(e,["executableCode"]);null!=l&&tt(t,["executableCode"],l);let o=tn(e,["fileData"]);null!=o&&tt(t,["fileData"],function(e){let t={};if(void 0!==tn(e,["displayName"]))throw Error("displayName parameter is not supported in Gemini API.");let n=tn(e,["fileUri"]);null!=n&&tt(t,["fileUri"],n);let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}(o));let r=tn(e,["functionCall"]);null!=r&&tt(t,["functionCall"],function(e){let t={},n=tn(e,["id"]);null!=n&&tt(t,["id"],n);let i=tn(e,["args"]);null!=i&&tt(t,["args"],i);let l=tn(e,["name"]);if(null!=l&&tt(t,["name"],l),void 0!==tn(e,["partialArgs"]))throw Error("partialArgs parameter is not supported in Gemini API.");if(void 0!==tn(e,["willContinue"]))throw Error("willContinue parameter is not supported in Gemini API.");return t}(r));let s=tn(e,["functionResponse"]);null!=s&&tt(t,["functionResponse"],s);let a=tn(e,["inlineData"]);null!=a&&tt(t,["inlineData"],/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function(e){let t={},n=tn(e,["data"]);if(null!=n&&tt(t,["data"],n),void 0!==tn(e,["displayName"]))throw Error("displayName parameter is not supported in Gemini API.");let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}(a));let u=tn(e,["text"]);null!=u&&tt(t,["text"],u);let p=tn(e,["thought"]);null!=p&&tt(t,["thought"],p);let d=tn(e,["thoughtSignature"]);null!=d&&tt(t,["thoughtSignature"],d);let c=tn(e,["videoMetadata"]);return null!=c&&tt(t,["videoMetadata"],c),t})(e))),tt(t,["parts"],e)}let i=tn(e,["role"]);return null!=i&&tt(t,["role"],i),t}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class ni extends e7{constructor(e){super(),this.apiClient=e,this.list=async(e={})=>new ne(el.PAGED_ITEM_CACHED_CONTENTS,e=>this.listInternal(e),await this.listInternal(e),e)}async create(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["model"],tU(e,i));let l=tn(t,["config"]);return null!=l&&function(e,t){let n=tn(e,["ttl"]);void 0!==t&&null!=n&&tt(t,["ttl"],n);let i=tn(e,["expireTime"]);void 0!==t&&null!=i&&tt(t,["expireTime"],i);let l=tn(e,["displayName"]);void 0!==t&&null!=l&&tt(t,["displayName"],l);let o=tn(e,["contents"]);if(void 0!==t&&null!=o){let e=tJ(o);Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["contents"],e)}let r=tn(e,["systemInstruction"]);void 0!==t&&null!=r&&tt(t,["systemInstruction"],tj(r));let s=tn(e,["tools"]);if(void 0!==t&&null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["functionDeclarations"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={};if(void 0!==tn(e,["behavior"]))throw Error("behavior parameter is not supported in Vertex AI.");let n=tn(e,["description"]);null!=n&&tt(t,["description"],n);let i=tn(e,["name"]);null!=i&&tt(t,["name"],i);let l=tn(e,["parameters"]);null!=l&&tt(t,["parameters"],l);let o=tn(e,["parametersJsonSchema"]);null!=o&&tt(t,["parametersJsonSchema"],o);let r=tn(e,["response"]);null!=r&&tt(t,["response"],r);let s=tn(e,["responseJsonSchema"]);return null!=s&&tt(t,["responseJsonSchema"],s),t})(e))),tt(t,["functionDeclarations"],e)}let i=tn(e,["retrieval"]);null!=i&&tt(t,["retrieval"],i);let l=tn(e,["googleSearchRetrieval"]);null!=l&&tt(t,["googleSearchRetrieval"],l);let o=tn(e,["computerUse"]);if(null!=o&&tt(t,["computerUse"],o),void 0!==tn(e,["fileSearch"]))throw Error("fileSearch parameter is not supported in Vertex AI.");let r=tn(e,["codeExecution"]);null!=r&&tt(t,["codeExecution"],r);let s=tn(e,["enterpriseWebSearch"]);null!=s&&tt(t,["enterpriseWebSearch"],s);let a=tn(e,["googleMaps"]);null!=a&&tt(t,["googleMaps"],a);let u=tn(e,["googleSearch"]);null!=u&&tt(t,["googleSearch"],u);let p=tn(e,["urlContext"]);return null!=p&&tt(t,["urlContext"],p),t})(e))),tt(t,["tools"],e)}let a=tn(e,["toolConfig"]);void 0!==t&&null!=a&&tt(t,["toolConfig"],a);let u=tn(e,["kmsKeyName"]);void 0!==t&&null!=u&&tt(t,["encryption_spec","kmsKeyName"],u)}(l,n),n}(this.apiClient,e);return o=te("cachedContents",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>e)}{let t=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["model"],tU(e,i));let l=tn(t,["config"]);return null!=l&&function(e,t){let n=tn(e,["ttl"]);void 0!==t&&null!=n&&tt(t,["ttl"],n);let i=tn(e,["expireTime"]);void 0!==t&&null!=i&&tt(t,["expireTime"],i);let l=tn(e,["displayName"]);void 0!==t&&null!=l&&tt(t,["displayName"],l);let o=tn(e,["contents"]);if(void 0!==t&&null!=o){let e=tJ(o);Array.isArray(e)&&(e=e.map(e=>nn(e))),tt(t,["contents"],e)}let r=tn(e,["systemInstruction"]);void 0!==t&&null!=r&&tt(t,["systemInstruction"],nn(tj(r)));let s=tn(e,["tools"]);if(void 0!==t&&null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["functionDeclarations"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["functionDeclarations"],e)}if(void 0!==tn(e,["retrieval"]))throw Error("retrieval parameter is not supported in Gemini API.");let i=tn(e,["googleSearchRetrieval"]);null!=i&&tt(t,["googleSearchRetrieval"],i);let l=tn(e,["computerUse"]);null!=l&&tt(t,["computerUse"],l);let o=tn(e,["fileSearch"]);null!=o&&tt(t,["fileSearch"],o);let r=tn(e,["codeExecution"]);if(null!=r&&tt(t,["codeExecution"],r),void 0!==tn(e,["enterpriseWebSearch"]))throw Error("enterpriseWebSearch parameter is not supported in Gemini API.");let s=tn(e,["googleMaps"]);null!=s&&tt(t,["googleMaps"],function(e){let t={};if(void 0!==tn(e,["authConfig"]))throw Error("authConfig parameter is not supported in Gemini API.");let n=tn(e,["enableWidget"]);return null!=n&&tt(t,["enableWidget"],n),t}(s));let a=tn(e,["googleSearch"]);null!=a&&tt(t,["googleSearch"],function(e){let t={};if(void 0!==tn(e,["excludeDomains"]))throw Error("excludeDomains parameter is not supported in Gemini API.");if(void 0!==tn(e,["blockingConfidence"]))throw Error("blockingConfidence parameter is not supported in Gemini API.");let n=tn(e,["timeRangeFilter"]);return null!=n&&tt(t,["timeRangeFilter"],n),t}(a));let u=tn(e,["urlContext"]);return null!=u&&tt(t,["urlContext"],u),t})(e))),tt(t,["tools"],e)}let a=tn(e,["toolConfig"]);if(void 0!==t&&null!=a&&tt(t,["toolConfig"],function(e){let t={},n=tn(e,["functionCallingConfig"]);null!=n&&tt(t,["functionCallingConfig"],function(e){let t={},n=tn(e,["mode"]);null!=n&&tt(t,["mode"],n);let i=tn(e,["allowedFunctionNames"]);if(null!=i&&tt(t,["allowedFunctionNames"],i),void 0!==tn(e,["streamFunctionCallArguments"]))throw Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return t}(n));let i=tn(e,["retrievalConfig"]);return null!=i&&tt(t,["retrievalConfig"],i),t}(a)),void 0!==tn(e,["kmsKeyName"]))throw Error("kmsKeyName parameter is not supported in Gemini API.")}(l,n),n}(this.apiClient,e);return o=te("cachedContents",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json()).then(e=>e)}}async get(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["name"]);return null!=i&&tt(n,["_url","name"],tX(e,i)),n}(this.apiClient,e);return o=te("{name}",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>e)}{let t=function(e,t){let n={},i=tn(t,["name"]);return null!=i&&tt(n,["_url","name"],tX(e,i)),n}(this.apiClient,e);return o=te("{name}",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json()).then(e=>e)}}async delete(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["name"]);return null!=i&&tt(n,["_url","name"],tX(e,i)),n}(this.apiClient,e);return o=te("{name}",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"DELETE",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);return null!=n&&tt(t,["sdkHttpResponse"],n),t}(e),n=new tv;return Object.assign(n,t),n})}{let t=function(e,t){let n={},i=tn(t,["name"]);return null!=i&&tt(n,["_url","name"],tX(e,i)),n}(this.apiClient,e);return o=te("{name}",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"DELETE",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);return null!=n&&tt(t,["sdkHttpResponse"],n),t}(e),n=new tv;return Object.assign(n,t),n})}}async update(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["name"]);null!=i&&tt(n,["_url","name"],tX(e,i));let l=tn(t,["config"]);return null!=l&&function(e,t){let n=tn(e,["ttl"]);void 0!==t&&null!=n&&tt(t,["ttl"],n);let i=tn(e,["expireTime"]);void 0!==t&&null!=i&&tt(t,["expireTime"],i)}(l,n),n}(this.apiClient,e);return o=te("{name}",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"PATCH",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>e)}{let t=function(e,t){let n={},i=tn(t,["name"]);null!=i&&tt(n,["_url","name"],tX(e,i));let l=tn(t,["config"]);return null!=l&&function(e,t){let n=tn(e,["ttl"]);void 0!==t&&null!=n&&tt(t,["ttl"],n);let i=tn(e,["expireTime"]);void 0!==t&&null!=i&&tt(t,["expireTime"],i)}(l,n),n}(this.apiClient,e);return o=te("{name}",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"PATCH",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json()).then(e=>e)}}async listInternal(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e){let t={},n=tn(e,["config"]);return null!=n&&function(e,t){let n=tn(e,["pageSize"]);void 0!==t&&null!=n&&tt(t,["_query","pageSize"],n);let i=tn(e,["pageToken"]);void 0!==t&&null!=i&&tt(t,["_query","pageToken"],i)}(n,t),t}(e);return o=te("cachedContents",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["nextPageToken"]);null!=i&&tt(t,["nextPageToken"],i);let l=tn(e,["cachedContents"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["cachedContents"],e)}return t}(e),n=new t_;return Object.assign(n,t),n})}{let t=function(e){let t={},n=tn(e,["config"]);return null!=n&&function(e,t){let n=tn(e,["pageSize"]);void 0!==t&&null!=n&&tt(t,["_query","pageSize"],n);let i=tn(e,["pageToken"]);void 0!==t&&null!=i&&tt(t,["_query","pageToken"],i)}(n,t),t}(e);return o=te("cachedContents",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["nextPageToken"]);null!=i&&tt(t,["nextPageToken"],i);let l=tn(e,["cachedContents"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["cachedContents"],e)}return t}(e),n=new t_;return Object.assign(n,t),n})}}}function nl(e){return this instanceof nl?(this.v=e,this):new nl(e)}function no(e,t,n){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var i,l=n.apply(e,t||[]),o=[];return i=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),r("next"),r("throw"),r("return",function(e){return function(t){return Promise.resolve(t).then(e,u)}}),i[Symbol.asyncIterator]=function(){return this},i;function r(e,t){l[e]&&(i[e]=function(t){return new Promise(function(n,i){o.push([e,t,n,i])>1||s(e,t)})},t&&(i[e]=t(i[e])))}function s(e,t){try{var n;(n=l[e](t)).value instanceof nl?Promise.resolve(n.value.v).then(a,u):p(o[0][2],n)}catch(e){p(o[0][3],e)}}function a(e){s("next",e)}function u(e){s("throw",e)}function p(e,t){e(t),o.shift(),o.length&&s(o[0][0],o[0][1])}}function nr(e){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],i=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(e),t={},i("next"),i("throw"),i("return"),t[Symbol.asyncIterator]=function(){return this},t);function i(n){t[n]=e[n]&&function(t){return new Promise(function(i,l){!function(e,t,n,i){Promise.resolve(i).then(function(t){e({value:t,done:n})},t)}(i,l,(t=e[n](t)).done,t.value)})}}}function ns(e){if(void 0===e.parts||0===e.parts.length)return!1;for(let t of e.parts)if(void 0===t||0===Object.keys(t).length)return!1;return!0}function na(e){if(void 0===e||0===e.length)return[];let t=[],n=e.length,i=0;for(;i<n;)if("user"===e[i].role)t.push(e[i]),i++;else{let l=[],o=!0;for(;i<n&&"model"===e[i].role;)l.push(e[i]),o&&!ns(e[i])&&(o=!1),i++;o?t.push(...l):t.pop()}return t}"function"==typeof SuppressedError&&SuppressedError;class nu{constructor(e,t){this.modelsModule=e,this.apiClient=t}create(e){return new np(this.apiClient,this.modelsModule,e.model,e.config,structuredClone(e.history))}}class np{constructor(e,t,n,i={},l=[]){this.apiClient=e,this.modelsModule=t,this.model=n,this.config=i,this.history=l,this.sendPromise=Promise.resolve(),function(e){if(0!==e.length){for(let t of e)if("user"!==t.role&&"model"!==t.role)throw Error(`Role must be user or model, but got ${t.role}.`)}}(l)}async sendMessage(e){var t;await this.sendPromise;let n=tj(e.message),i=this.modelsModule.generateContent({model:this.model,contents:this.getHistory(!0).concat(n),config:null!==(t=e.config)&&void 0!==t?t:this.config});return this.sendPromise=(async()=>{var e,t,l;let o=await i,r=null===(t=null===(e=o.candidates)||void 0===e?void 0:e[0])||void 0===t?void 0:t.content,s=o.automaticFunctionCallingHistory,a=this.getHistory(!0).length,u=[];null!=s&&(u=null!==(l=s.slice(a))&&void 0!==l?l:[]),this.recordHistory(n,r?[r]:[],u)})(),await this.sendPromise.catch(()=>{this.sendPromise=Promise.resolve()}),i}async sendMessageStream(e){var t;await this.sendPromise;let n=tj(e.message),i=this.modelsModule.generateContentStream({model:this.model,contents:this.getHistory(!0).concat(n),config:null!==(t=e.config)&&void 0!==t?t:this.config});this.sendPromise=i.then(()=>void 0).catch(()=>void 0);let l=await i;return this.processStreamResponse(l,n)}getHistory(e=!1){let t=e?na(this.history):this.history;return structuredClone(t)}processStreamResponse(e,t){var n,i;return no(this,arguments,function*(){var l,o,r,s;let a=[];try{for(var u,p=!0,d=nr(e);!(l=(u=yield nl(d.next())).done);p=!0){if(s=u.value,p=!1,/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function(e){var t;if(void 0==e.candidates||0===e.candidates.length)return!1;let n=null===(t=e.candidates[0])||void 0===t?void 0:t.content;return void 0!==n&&ns(n)}(s)){let e=null===(i=null===(n=s.candidates)||void 0===n?void 0:n[0])||void 0===i?void 0:i.content;void 0!==e&&a.push(e)}yield yield nl(s)}}catch(e){o={error:e}}finally{try{!p&&!l&&(r=d.return)&&(yield nl(r.call(d)))}finally{if(o)throw o.error}}this.recordHistory(t,a)})}recordHistory(e,t,n){let i=[];t.length>0&&t.every(e=>void 0!==e.role)?i=t:i.push({role:"model",parts:[]}),n&&n.length>0?this.history.push(...na(n)):this.history.push(e),this.history.push(...i)}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class nd extends Error{constructor(e){super(e.message),this.name="ApiError",this.status=e.status,Object.setPrototypeOf(this,nd.prototype)}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class nc extends e7{constructor(e){super(),this.apiClient=e,this.list=async(e={})=>new ne(el.PAGED_ITEM_FILES,e=>this.listInternal(e),await this.listInternal(e),e)}async upload(e){if(this.apiClient.isVertexAI())throw Error("Vertex AI does not support uploading files. You can share files through a GCS bucket.");return this.apiClient.uploadFile(e.file,e.config).then(e=>e)}async download(e){await this.apiClient.downloadFile(e)}async listInternal(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["config"]);return null!=n&&function(e,t){let n=tn(e,["pageSize"]);void 0!==t&&null!=n&&tt(t,["_query","pageSize"],n);let i=tn(e,["pageToken"]);void 0!==t&&null!=i&&tt(t,["_query","pageToken"],i)}(n,t),t}(e);return i=te("files",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["nextPageToken"]);null!=i&&tt(t,["nextPageToken"],i);let l=tn(e,["files"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["files"],e)}return t}(e),n=new tS;return Object.assign(n,t),n})}}async createInternal(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function(e){let t={},n=tn(e,["file"]);return null!=n&&tt(t,["file"],n),t}(e);return i=te("upload/v1beta/files",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);return null!=n&&tt(t,["sdkHttpResponse"],n),t}(e),n=new tO;return Object.assign(n,t),n})}}async get(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["name"]);return null!=n&&tt(t,["_url","file"],tZ(n)),t}(e);return i=te("files/{file}",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>e)}}async delete(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["name"]);return null!=n&&tt(t,["_url","file"],tZ(n)),t}(e);return i=te("files/{file}",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"DELETE",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);return null!=n&&tt(t,["sdkHttpResponse"],n),t}(e),n=new tb;return Object.assign(n,t),n})}}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function nh(e){let t={},n=tn(e,["data"]);if(null!=n&&tt(t,["data"],n),void 0!==tn(e,["displayName"]))throw Error("displayName parameter is not supported in Gemini API.");let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}function nf(e){let t={},n=tn(e,["languageCode"]);null!=n&&tt(t,["languageCode"],n);let i=tn(e,["voiceConfig"]);if(null!=i&&tt(t,["voiceConfig"],i),void 0!==tn(e,["multiSpeakerVoiceConfig"]))throw Error("multiSpeakerVoiceConfig parameter is not supported in Vertex AI.");return t}function nm(e){let t={},n=tn(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["mediaResolution"]);null!=n&&tt(t,["mediaResolution"],n);let i=tn(e,["codeExecutionResult"]);null!=i&&tt(t,["codeExecutionResult"],i);let l=tn(e,["executableCode"]);null!=l&&tt(t,["executableCode"],l);let o=tn(e,["fileData"]);null!=o&&tt(t,["fileData"],function(e){let t={};if(void 0!==tn(e,["displayName"]))throw Error("displayName parameter is not supported in Gemini API.");let n=tn(e,["fileUri"]);null!=n&&tt(t,["fileUri"],n);let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}(o));let r=tn(e,["functionCall"]);null!=r&&tt(t,["functionCall"],function(e){let t={},n=tn(e,["id"]);null!=n&&tt(t,["id"],n);let i=tn(e,["args"]);null!=i&&tt(t,["args"],i);let l=tn(e,["name"]);if(null!=l&&tt(t,["name"],l),void 0!==tn(e,["partialArgs"]))throw Error("partialArgs parameter is not supported in Gemini API.");if(void 0!==tn(e,["willContinue"]))throw Error("willContinue parameter is not supported in Gemini API.");return t}(r));let s=tn(e,["functionResponse"]);null!=s&&tt(t,["functionResponse"],s);let a=tn(e,["inlineData"]);null!=a&&tt(t,["inlineData"],/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function(e){let t={},n=tn(e,["data"]);if(null!=n&&tt(t,["data"],n),void 0!==tn(e,["displayName"]))throw Error("displayName parameter is not supported in Gemini API.");let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}(a));let u=tn(e,["text"]);null!=u&&tt(t,["text"],u);let p=tn(e,["thought"]);null!=p&&tt(t,["thought"],p);let d=tn(e,["thoughtSignature"]);null!=d&&tt(t,["thoughtSignature"],d);let c=tn(e,["videoMetadata"]);return null!=c&&tt(t,["videoMetadata"],c),t})(e))),tt(t,["parts"],e)}let i=tn(e,["role"]);return null!=i&&tt(t,["role"],i),t}function ng(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["contents"]);if(null!=l){let e=tJ(l);Array.isArray(e)&&(e=e.map(e=>nm(e))),tt(n,["contents"],e)}let o=tn(t,["config"]);return null!=o&&tt(n,["generationConfig"],function(e,t,n){let i={},l=tn(t,["systemInstruction"]);void 0!==n&&null!=l&&tt(n,["systemInstruction"],nm(tj(l)));let o=tn(t,["temperature"]);null!=o&&tt(i,["temperature"],o);let r=tn(t,["topP"]);null!=r&&tt(i,["topP"],r);let s=tn(t,["topK"]);null!=s&&tt(i,["topK"],s);let a=tn(t,["candidateCount"]);null!=a&&tt(i,["candidateCount"],a);let u=tn(t,["maxOutputTokens"]);null!=u&&tt(i,["maxOutputTokens"],u);let p=tn(t,["stopSequences"]);null!=p&&tt(i,["stopSequences"],p);let d=tn(t,["responseLogprobs"]);null!=d&&tt(i,["responseLogprobs"],d);let c=tn(t,["logprobs"]);null!=c&&tt(i,["logprobs"],c);let h=tn(t,["presencePenalty"]);null!=h&&tt(i,["presencePenalty"],h);let f=tn(t,["frequencyPenalty"]);null!=f&&tt(i,["frequencyPenalty"],f);let m=tn(t,["seed"]);null!=m&&tt(i,["seed"],m);let g=tn(t,["responseMimeType"]);null!=g&&tt(i,["responseMimeType"],g);let y=tn(t,["responseSchema"]);null!=y&&tt(i,["responseSchema"],tY(y));let E=tn(t,["responseJsonSchema"]);if(null!=E&&tt(i,["responseJsonSchema"],E),void 0!==tn(t,["routingConfig"]))throw Error("routingConfig parameter is not supported in Gemini API.");if(void 0!==tn(t,["modelSelectionConfig"]))throw Error("modelSelectionConfig parameter is not supported in Gemini API.");let v=tn(t,["safetySettings"]);if(void 0!==n&&null!=v){let e=v;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["category"]);if(null!=n&&tt(t,["category"],n),void 0!==tn(e,["method"]))throw Error("method parameter is not supported in Gemini API.");let i=tn(e,["threshold"]);return null!=i&&tt(t,["threshold"],i),t})(e))),tt(n,["safetySettings"],e)}let _=tn(t,["tools"]);if(void 0!==n&&null!=_){let e=tz(_);Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["functionDeclarations"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["functionDeclarations"],e)}if(void 0!==tn(e,["retrieval"]))throw Error("retrieval parameter is not supported in Gemini API.");let i=tn(e,["googleSearchRetrieval"]);null!=i&&tt(t,["googleSearchRetrieval"],i);let l=tn(e,["computerUse"]);null!=l&&tt(t,["computerUse"],l);let o=tn(e,["fileSearch"]);null!=o&&tt(t,["fileSearch"],o);let r=tn(e,["codeExecution"]);if(null!=r&&tt(t,["codeExecution"],r),void 0!==tn(e,["enterpriseWebSearch"]))throw Error("enterpriseWebSearch parameter is not supported in Gemini API.");let s=tn(e,["googleMaps"]);null!=s&&tt(t,["googleMaps"],function(e){let t={};if(void 0!==tn(e,["authConfig"]))throw Error("authConfig parameter is not supported in Gemini API.");let n=tn(e,["enableWidget"]);return null!=n&&tt(t,["enableWidget"],n),t}(s));let a=tn(e,["googleSearch"]);null!=a&&tt(t,["googleSearch"],function(e){let t={};if(void 0!==tn(e,["excludeDomains"]))throw Error("excludeDomains parameter is not supported in Gemini API.");if(void 0!==tn(e,["blockingConfidence"]))throw Error("blockingConfidence parameter is not supported in Gemini API.");let n=tn(e,["timeRangeFilter"]);return null!=n&&tt(t,["timeRangeFilter"],n),t}(a));let u=tn(e,["urlContext"]);return null!=u&&tt(t,["urlContext"],u),t})(t$(e)))),tt(n,["tools"],e)}let I=tn(t,["toolConfig"]);if(void 0!==n&&null!=I&&tt(n,["toolConfig"],function(e){let t={},n=tn(e,["functionCallingConfig"]);null!=n&&tt(t,["functionCallingConfig"],function(e){let t={},n=tn(e,["mode"]);null!=n&&tt(t,["mode"],n);let i=tn(e,["allowedFunctionNames"]);if(null!=i&&tt(t,["allowedFunctionNames"],i),void 0!==tn(e,["streamFunctionCallArguments"]))throw Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return t}(n));let i=tn(e,["retrievalConfig"]);return null!=i&&tt(t,["retrievalConfig"],i),t}(I)),void 0!==tn(t,["labels"]))throw Error("labels parameter is not supported in Gemini API.");let T=tn(t,["cachedContent"]);void 0!==n&&null!=T&&tt(n,["cachedContent"],tX(e,T));let A=tn(t,["responseModalities"]);null!=A&&tt(i,["responseModalities"],A);let C=tn(t,["mediaResolution"]);null!=C&&tt(i,["mediaResolution"],C);let S=tn(t,["speechConfig"]);if(null!=S&&tt(i,["speechConfig"],tK(S)),void 0!==tn(t,["audioTimestamp"]))throw Error("audioTimestamp parameter is not supported in Gemini API.");let O=tn(t,["thinkingConfig"]);null!=O&&tt(i,["thinkingConfig"],O);let b=tn(t,["imageConfig"]);return null!=b&&tt(i,["imageConfig"],function(e){let t={},n=tn(e,["aspectRatio"]);null!=n&&tt(t,["aspectRatio"],n);let i=tn(e,["imageSize"]);if(null!=i&&tt(t,["imageSize"],i),void 0!==tn(e,["outputMimeType"]))throw Error("outputMimeType parameter is not supported in Gemini API.");if(void 0!==tn(e,["outputCompressionQuality"]))throw Error("outputCompressionQuality parameter is not supported in Gemini API.");return t}(b)),i}(e,o,n)),n}function ny(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["contents"]);if(null!=l){let e=tJ(l);Array.isArray(e)&&(e=e.map(e=>e)),tt(n,["contents"],e)}let o=tn(t,["config"]);return null!=o&&tt(n,["generationConfig"],function(e,t,n){let i={},l=tn(t,["systemInstruction"]);void 0!==n&&null!=l&&tt(n,["systemInstruction"],tj(l));let o=tn(t,["temperature"]);null!=o&&tt(i,["temperature"],o);let r=tn(t,["topP"]);null!=r&&tt(i,["topP"],r);let s=tn(t,["topK"]);null!=s&&tt(i,["topK"],s);let a=tn(t,["candidateCount"]);null!=a&&tt(i,["candidateCount"],a);let u=tn(t,["maxOutputTokens"]);null!=u&&tt(i,["maxOutputTokens"],u);let p=tn(t,["stopSequences"]);null!=p&&tt(i,["stopSequences"],p);let d=tn(t,["responseLogprobs"]);null!=d&&tt(i,["responseLogprobs"],d);let c=tn(t,["logprobs"]);null!=c&&tt(i,["logprobs"],c);let h=tn(t,["presencePenalty"]);null!=h&&tt(i,["presencePenalty"],h);let f=tn(t,["frequencyPenalty"]);null!=f&&tt(i,["frequencyPenalty"],f);let m=tn(t,["seed"]);null!=m&&tt(i,["seed"],m);let g=tn(t,["responseMimeType"]);null!=g&&tt(i,["responseMimeType"],g);let y=tn(t,["responseSchema"]);null!=y&&tt(i,["responseSchema"],tY(y));let E=tn(t,["responseJsonSchema"]);null!=E&&tt(i,["responseJsonSchema"],E);let v=tn(t,["routingConfig"]);null!=v&&tt(i,["routingConfig"],v);let _=tn(t,["modelSelectionConfig"]);null!=_&&tt(i,["modelConfig"],_);let I=tn(t,["safetySettings"]);if(void 0!==n&&null!=I){let e=I;Array.isArray(e)&&(e=e.map(e=>e)),tt(n,["safetySettings"],e)}let T=tn(t,["tools"]);if(void 0!==n&&null!=T){let e=tz(T);Array.isArray(e)&&(e=e.map(e=>nR(t$(e)))),tt(n,["tools"],e)}let A=tn(t,["toolConfig"]);void 0!==n&&null!=A&&tt(n,["toolConfig"],A);let C=tn(t,["labels"]);void 0!==n&&null!=C&&tt(n,["labels"],C);let S=tn(t,["cachedContent"]);void 0!==n&&null!=S&&tt(n,["cachedContent"],tX(e,S));let O=tn(t,["responseModalities"]);null!=O&&tt(i,["responseModalities"],O);let b=tn(t,["mediaResolution"]);null!=b&&tt(i,["mediaResolution"],b);let N=tn(t,["speechConfig"]);null!=N&&tt(i,["speechConfig"],nN(tK(N)));let R=tn(t,["audioTimestamp"]);null!=R&&tt(i,["audioTimestamp"],R);let P=tn(t,["thinkingConfig"]);null!=P&&tt(i,["thinkingConfig"],P);let D=tn(t,["imageConfig"]);return null!=D&&tt(i,["imageConfig"],function(e){let t={},n=tn(e,["aspectRatio"]);null!=n&&tt(t,["aspectRatio"],n);let i=tn(e,["imageSize"]);null!=i&&tt(t,["imageSize"],i);let l=tn(e,["outputMimeType"]);null!=l&&tt(t,["imageOutputOptions","mimeType"],l);let o=tn(e,["outputCompressionQuality"]);return null!=o&&tt(t,["imageOutputOptions","compressionQuality"],o),t}(D)),i}(e,o,n)),n}function nE(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["candidates"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["content"]);null!=n&&tt(t,["content"],n);let i=tn(e,["citationMetadata"]);null!=i&&tt(t,["citationMetadata"],function(e){let t={},n=tn(e,["citationSources"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["citations"],e)}return t}(i));let l=tn(e,["tokenCount"]);null!=l&&tt(t,["tokenCount"],l);let o=tn(e,["finishReason"]);null!=o&&tt(t,["finishReason"],o);let r=tn(e,["avgLogprobs"]);null!=r&&tt(t,["avgLogprobs"],r);let s=tn(e,["groundingMetadata"]);null!=s&&tt(t,["groundingMetadata"],s);let a=tn(e,["index"]);null!=a&&tt(t,["index"],a);let u=tn(e,["logprobsResult"]);null!=u&&tt(t,["logprobsResult"],u);let p=tn(e,["safetyRatings"]);if(null!=p){let e=p;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["safetyRatings"],e)}let d=tn(e,["urlContextMetadata"]);return null!=d&&tt(t,["urlContextMetadata"],d),t})(e))),tt(t,["candidates"],e)}let l=tn(e,["modelVersion"]);null!=l&&tt(t,["modelVersion"],l);let o=tn(e,["promptFeedback"]);null!=o&&tt(t,["promptFeedback"],o);let r=tn(e,["responseId"]);null!=r&&tt(t,["responseId"],r);let s=tn(e,["usageMetadata"]);return null!=s&&tt(t,["usageMetadata"],s),t}function nv(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["candidates"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["candidates"],e)}let l=tn(e,["createTime"]);null!=l&&tt(t,["createTime"],l);let o=tn(e,["modelVersion"]);null!=o&&tt(t,["modelVersion"],o);let r=tn(e,["promptFeedback"]);null!=r&&tt(t,["promptFeedback"],r);let s=tn(e,["responseId"]);null!=s&&tt(t,["responseId"],s);let a=tn(e,["usageMetadata"]);return null!=a&&tt(t,["usageMetadata"],a),t}function n_(e){let t={},n=tn(e,["_self"]);null!=n&&tt(t,["image"],nI(n));let i=tn(e,["raiFilteredReason"]);null!=i&&tt(t,["raiFilteredReason"],i);let l=tn(e,["_self"]);null!=l&&tt(t,["safetyAttributes"],nb(l));let o=tn(e,["prompt"]);return null!=o&&tt(t,["enhancedPrompt"],o),t}function nI(e){let t={},n=tn(e,["gcsUri"]);null!=n&&tt(t,["gcsUri"],n);let i=tn(e,["bytesBase64Encoded"]);null!=i&&tt(t,["imageBytes"],ti(i));let l=tn(e,["mimeType"]);return null!=l&&tt(t,["mimeType"],l),t}function nT(e){let t={};if(void 0!==tn(e,["gcsUri"]))throw Error("gcsUri parameter is not supported in Gemini API.");let n=tn(e,["imageBytes"]);null!=n&&tt(t,["bytesBase64Encoded"],ti(n));let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}function nA(e){let t={},n=tn(e,["gcsUri"]);null!=n&&tt(t,["gcsUri"],n);let i=tn(e,["imageBytes"]);null!=i&&tt(t,["bytesBase64Encoded"],ti(i));let l=tn(e,["mimeType"]);return null!=l&&tt(t,["mimeType"],l),t}function nC(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["name"],n);let i=tn(e,["displayName"]);null!=i&&tt(t,["displayName"],i);let l=tn(e,["description"]);null!=l&&tt(t,["description"],l);let o=tn(e,["version"]);null!=o&&tt(t,["version"],o);let r=tn(e,["_self"]);null!=r&&tt(t,["tunedModelInfo"],function(e){let t={},n=tn(e,["baseModel"]);null!=n&&tt(t,["baseModel"],n);let i=tn(e,["createTime"]);null!=i&&tt(t,["createTime"],i);let l=tn(e,["updateTime"]);return null!=l&&tt(t,["updateTime"],l),t}(r));let s=tn(e,["inputTokenLimit"]);null!=s&&tt(t,["inputTokenLimit"],s);let a=tn(e,["outputTokenLimit"]);null!=a&&tt(t,["outputTokenLimit"],a);let u=tn(e,["supportedGenerationMethods"]);null!=u&&tt(t,["supportedActions"],u);let p=tn(e,["temperature"]);null!=p&&tt(t,["temperature"],p);let d=tn(e,["maxTemperature"]);null!=d&&tt(t,["maxTemperature"],d);let c=tn(e,["topP"]);null!=c&&tt(t,["topP"],c);let h=tn(e,["topK"]);null!=h&&tt(t,["topK"],h);let f=tn(e,["thinking"]);return null!=f&&tt(t,["thinking"],f),t}function nS(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["name"],n);let i=tn(e,["displayName"]);null!=i&&tt(t,["displayName"],i);let l=tn(e,["description"]);null!=l&&tt(t,["description"],l);let o=tn(e,["versionId"]);null!=o&&tt(t,["version"],o);let r=tn(e,["deployedModels"]);if(null!=r){let e=r;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["endpoint"]);null!=n&&tt(t,["name"],n);let i=tn(e,["deployedModelId"]);return null!=i&&tt(t,["deployedModelId"],i),t})(e))),tt(t,["endpoints"],e)}let s=tn(e,["labels"]);null!=s&&tt(t,["labels"],s);let a=tn(e,["_self"]);null!=a&&tt(t,["tunedModelInfo"],function(e){let t={},n=tn(e,["labels","google-vertex-llm-tuning-base-model-id"]);null!=n&&tt(t,["baseModel"],n);let i=tn(e,["createTime"]);null!=i&&tt(t,["createTime"],i);let l=tn(e,["updateTime"]);return null!=l&&tt(t,["updateTime"],l),t}(a));let u=tn(e,["defaultCheckpointId"]);null!=u&&tt(t,["defaultCheckpointId"],u);let p=tn(e,["checkpoints"]);if(null!=p){let e=p;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["checkpoints"],e)}return t}function nO(e){let t={},n=tn(e,["safetyAttributes","categories"]);null!=n&&tt(t,["categories"],n);let i=tn(e,["safetyAttributes","scores"]);null!=i&&tt(t,["scores"],i);let l=tn(e,["contentType"]);return null!=l&&tt(t,["contentType"],l),t}function nb(e){let t={},n=tn(e,["safetyAttributes","categories"]);null!=n&&tt(t,["categories"],n);let i=tn(e,["safetyAttributes","scores"]);null!=i&&tt(t,["scores"],i);let l=tn(e,["contentType"]);return null!=l&&tt(t,["contentType"],l),t}function nN(e){let t={},n=tn(e,["languageCode"]);null!=n&&tt(t,["languageCode"],n);let i=tn(e,["voiceConfig"]);if(null!=i&&tt(t,["voiceConfig"],i),void 0!==tn(e,["multiSpeakerVoiceConfig"]))throw Error("multiSpeakerVoiceConfig parameter is not supported in Vertex AI.");return t}function nR(e){let t={},n=tn(e,["functionDeclarations"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={};if(void 0!==tn(e,["behavior"]))throw Error("behavior parameter is not supported in Vertex AI.");let n=tn(e,["description"]);null!=n&&tt(t,["description"],n);let i=tn(e,["name"]);null!=i&&tt(t,["name"],i);let l=tn(e,["parameters"]);null!=l&&tt(t,["parameters"],l);let o=tn(e,["parametersJsonSchema"]);null!=o&&tt(t,["parametersJsonSchema"],o);let r=tn(e,["response"]);null!=r&&tt(t,["response"],r);let s=tn(e,["responseJsonSchema"]);return null!=s&&tt(t,["responseJsonSchema"],s),t})(e))),tt(t,["functionDeclarations"],e)}let i=tn(e,["retrieval"]);null!=i&&tt(t,["retrieval"],i);let l=tn(e,["googleSearchRetrieval"]);null!=l&&tt(t,["googleSearchRetrieval"],l);let o=tn(e,["computerUse"]);if(null!=o&&tt(t,["computerUse"],o),void 0!==tn(e,["fileSearch"]))throw Error("fileSearch parameter is not supported in Vertex AI.");let r=tn(e,["codeExecution"]);null!=r&&tt(t,["codeExecution"],r);let s=tn(e,["enterpriseWebSearch"]);null!=s&&tt(t,["enterpriseWebSearch"],s);let a=tn(e,["googleMaps"]);null!=a&&tt(t,["googleMaps"],a);let u=tn(e,["googleSearch"]);null!=u&&tt(t,["googleSearch"],u);let p=tn(e,["urlContext"]);return null!=p&&tt(t,["urlContext"],p),t}function nP(e){let t={},n=tn(e,["uri"]);null!=n&&tt(t,["uri"],n);let i=tn(e,["videoBytes"]);null!=i&&tt(t,["encodedVideo"],ti(i));let l=tn(e,["mimeType"]);return null!=l&&tt(t,["encoding"],l),t}function nD(e){let t={},n=tn(e,["uri"]);null!=n&&tt(t,["gcsUri"],n);let i=tn(e,["videoBytes"]);null!=i&&tt(t,["bytesBase64Encoded"],ti(i));let l=tn(e,["mimeType"]);return null!=l&&tt(t,["mimeType"],l),t}let nM="x-goog-api-client",nU=/^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;class nw{constructor(e){var t,n;this.clientOptions=Object.assign(Object.assign({},e),{project:e.project,location:e.location,apiKey:e.apiKey,vertexai:e.vertexai});let i={};this.clientOptions.vertexai?(i.apiVersion=null!==(t=this.clientOptions.apiVersion)&&void 0!==t?t:"v1beta1",i.baseUrl=this.baseUrlFromProjectLocation(),this.normalizeAuthParameters()):(i.apiVersion=null!==(n=this.clientOptions.apiVersion)&&void 0!==n?n:"v1beta",i.baseUrl="https://generativelanguage.googleapis.com/"),i.headers=this.getDefaultHeaders(),this.clientOptions.httpOptions=i,e.httpOptions&&(this.clientOptions.httpOptions=this.patchHttpOptions(i,e.httpOptions))}baseUrlFromProjectLocation(){return this.clientOptions.project&&this.clientOptions.location&&"global"!==this.clientOptions.location?`https://${this.clientOptions.location}-aiplatform.googleapis.com/`:"https://aiplatform.googleapis.com/"}normalizeAuthParameters(){if(this.clientOptions.project&&this.clientOptions.location){this.clientOptions.apiKey=void 0;return}this.clientOptions.project=void 0,this.clientOptions.location=void 0}isVertexAI(){var e;return null!==(e=this.clientOptions.vertexai)&&void 0!==e&&e}getProject(){return this.clientOptions.project}getLocation(){return this.clientOptions.location}getApiVersion(){if(this.clientOptions.httpOptions&&void 0!==this.clientOptions.httpOptions.apiVersion)return this.clientOptions.httpOptions.apiVersion;throw Error("API version is not set.")}getBaseUrl(){if(this.clientOptions.httpOptions&&void 0!==this.clientOptions.httpOptions.baseUrl)return this.clientOptions.httpOptions.baseUrl;throw Error("Base URL is not set.")}getRequestUrl(){return this.getRequestUrlInternal(this.clientOptions.httpOptions)}getHeaders(){if(this.clientOptions.httpOptions&&void 0!==this.clientOptions.httpOptions.headers)return this.clientOptions.httpOptions.headers;throw Error("Headers are not set.")}getRequestUrlInternal(e){if(!e||void 0===e.baseUrl||void 0===e.apiVersion)throw Error("HTTP options are not correctly set.");let t=[e.baseUrl.endsWith("/")?e.baseUrl.slice(0,-1):e.baseUrl];return e.apiVersion&&""!==e.apiVersion&&t.push(e.apiVersion),t.join("/")}getBaseResourcePath(){return`projects/${this.clientOptions.project}/locations/${this.clientOptions.location}`}getApiKey(){return this.clientOptions.apiKey}getWebsocketBaseUrl(){let e=this.getBaseUrl(),t=new URL(e);return t.protocol="http:"==t.protocol?"ws":"wss",t.toString()}setBaseUrl(e){if(this.clientOptions.httpOptions)this.clientOptions.httpOptions.baseUrl=e;else throw Error("HTTP options are not correctly set.")}constructUrl(e,t,n){let i=[this.getRequestUrlInternal(t)];return n&&i.push(this.getBaseResourcePath()),""!==e&&i.push(e),new URL(`${i.join("/")}`)}shouldPrependVertexProjectPath(e){return!(this.clientOptions.apiKey||!this.clientOptions.vertexai||e.path.startsWith("projects/")||"GET"===e.httpMethod&&e.path.startsWith("publishers/google/models"))}async request(e){let t=this.clientOptions.httpOptions;e.httpOptions&&(t=this.patchHttpOptions(this.clientOptions.httpOptions,e.httpOptions));let n=this.shouldPrependVertexProjectPath(e),i=this.constructUrl(e.path,t,n);if(e.queryParams)for(let[t,n]of Object.entries(e.queryParams))i.searchParams.append(t,String(n));let l={};if("GET"===e.httpMethod){if(e.body&&"{}"!==e.body)throw Error("Request body should be empty for GET request, but got non empty request body")}else l.body=e.body;return l=await this.includeExtraHttpOptionsToRequestInit(l,t,i.toString(),e.abortSignal),this.unaryApiCall(i,l,e.httpMethod)}patchHttpOptions(e,t){let n=JSON.parse(JSON.stringify(e));for(let[e,i]of Object.entries(t))"object"==typeof i?n[e]=Object.assign(Object.assign({},n[e]),i):void 0!==i&&(n[e]=i);return n}async requestStream(e){let t=this.clientOptions.httpOptions;e.httpOptions&&(t=this.patchHttpOptions(this.clientOptions.httpOptions,e.httpOptions));let n=this.shouldPrependVertexProjectPath(e),i=this.constructUrl(e.path,t,n);i.searchParams.has("alt")&&"sse"===i.searchParams.get("alt")||i.searchParams.set("alt","sse");let l={};return l.body=e.body,l=await this.includeExtraHttpOptionsToRequestInit(l,t,i.toString(),e.abortSignal),this.streamApiCall(i,l,e.httpMethod)}async includeExtraHttpOptionsToRequestInit(e,t,n,i){if(t&&t.timeout||i){let n=new AbortController,l=n.signal;if(t.timeout&&(null==t?void 0:t.timeout)>0){let e=setTimeout(()=>n.abort(),t.timeout);e&&"function"==typeof e.unref&&e.unref()}i&&i.addEventListener("abort",()=>{n.abort()}),e.signal=l}return t&&null!==t.extraBody&&function(e,t){if(!t||0===Object.keys(t).length)return;if(e.body instanceof Blob){console.warn("includeExtraBodyToRequestInit: extraBody provided but current request body is a Blob. extraBody will be ignored as merging is not supported for Blob bodies.");return}let n={};if("string"==typeof e.body&&e.body.length>0)try{let t=JSON.parse(e.body);if("object"!=typeof t||null===t||Array.isArray(t)){console.warn("includeExtraBodyToRequestInit: Original request body is valid JSON but not a non-array object. Skip applying extraBody to the request body.");return}n=t}catch(e){console.warn("includeExtraBodyToRequestInit: Original request body is not valid JSON. Skip applying extraBody to the request body.");return}let i=function e(t,n){let i=Object.assign({},t);for(let t in n)if(Object.prototype.hasOwnProperty.call(n,t)){let l=n[t],o=i[t];l&&"object"==typeof l&&!Array.isArray(l)&&o&&"object"==typeof o&&!Array.isArray(o)?i[t]=e(o,l):(o&&l&&typeof o!=typeof l&&console.warn(`includeExtraBodyToRequestInit:deepMerge: Type mismatch for key "${t}". Original type: ${typeof o}, New type: ${typeof l}. Overwriting.`),i[t]=l)}return i}(n,t);e.body=JSON.stringify(i)}(e,t.extraBody),e.headers=await this.getHeadersInternal(t,n),e}async unaryApiCall(e,t,n){return this.apiCall(e.toString(),Object.assign(Object.assign({},t),{method:n})).then(async e=>(await nq(e),new to(e))).catch(e=>{if(e instanceof Error)throw e;throw Error(JSON.stringify(e))})}async streamApiCall(e,t,n){return this.apiCall(e.toString(),Object.assign(Object.assign({},t),{method:n})).then(async e=>(await nq(e),this.processStreamResponse(e))).catch(e=>{if(e instanceof Error)throw e;throw Error(JSON.stringify(e))})}processStreamResponse(e){var t;return no(this,arguments,function*(){let n=null===(t=null==e?void 0:e.body)||void 0===t?void 0:t.getReader(),i=new TextDecoder("utf-8");if(!n)throw Error("Response body is empty");try{let t="";for(;;){let{done:l,value:o}=yield nl(n.read());if(l){if(t.trim().length>0)throw Error("Incomplete JSON segment at the end");break}let r=i.decode(o,{stream:!0});try{let e=JSON.parse(r);if("error"in e){let t=JSON.parse(JSON.stringify(e.error)),n=t.status,i=t.code,l=`got status: ${n}. ${JSON.stringify(e)}`;if(i>=400&&i<600)throw new nd({message:l,status:i})}}catch(e){if("ApiError"===e.name)throw e}let s=(t+=r).match(nU);for(;s;){let n=s[1];try{let i=new Response(n,{headers:null==e?void 0:e.headers,status:null==e?void 0:e.status,statusText:null==e?void 0:e.statusText});yield yield nl(new to(i)),s=(t=t.slice(s[0].length)).match(nU)}catch(e){throw Error(`exception parsing stream chunk ${n}. ${e}`)}}}}finally{n.releaseLock()}})}async apiCall(e,t){return fetch(e,t).catch(e=>{throw Error(`exception ${e} sending request`)})}getDefaultHeaders(){let e={},t="google-genai-sdk/1.30.0 "+this.clientOptions.userAgentExtra;return e["User-Agent"]=t,e[nM]=t,e["Content-Type"]="application/json",e}async getHeadersInternal(e,t){let n=new Headers;if(e&&e.headers){for(let[t,i]of Object.entries(e.headers))n.append(t,i);e.timeout&&e.timeout>0&&n.append("X-Server-Timeout",String(Math.ceil(e.timeout/1e3)))}return await this.clientOptions.auth.addAuthHeaders(n,t),n}getFileName(e){var t;let n="";return"string"==typeof e&&(n=null!==(t=(n=e.replace(/[/\\]+$/,"")).split(/[/\\]/).pop())&&void 0!==t?t:""),n}async uploadFile(e,t){var n;let i={};null!=t&&(i.mimeType=t.mimeType,i.name=t.name,i.displayName=t.displayName),i.name&&!i.name.startsWith("files/")&&(i.name=`files/${i.name}`);let l=this.clientOptions.uploader,o=await l.stat(e);i.sizeBytes=String(o.size);let r=null!==(n=null==t?void 0:t.mimeType)&&void 0!==n?n:o.type;if(void 0===r||""===r)throw Error("Can not determine mimeType. Please provide mimeType in the config.");i.mimeType=r;let s={file:i},a=this.getFileName(e),u=te("upload/v1beta/files",s._url),p=await this.fetchUploadUrl(u,i.sizeBytes,i.mimeType,a,s,null==t?void 0:t.httpOptions);return l.upload(e,p,this)}async uploadFileToFileSearchStore(e,t,n){var i;let l=this.clientOptions.uploader,o=await l.stat(t),r=String(o.size),s=null!==(i=null==n?void 0:n.mimeType)&&void 0!==i?i:o.type;if(void 0===s||""===s)throw Error("Can not determine mimeType. Please provide mimeType in the config.");let a=`upload/v1beta/${e}:uploadToFileSearchStore`,u=this.getFileName(t),p={};(null==n?void 0:n.customMetadata)&&(p.customMetadata=n.customMetadata),(null==n?void 0:n.chunkingConfig)&&(p.chunkingConfig=n.chunkingConfig);let d=await this.fetchUploadUrl(a,r,s,u,p,null==n?void 0:n.httpOptions);return l.uploadToFileSearchStore(t,d,this)}async downloadFile(e){let t=this.clientOptions.downloader;await t.download(e,this)}async fetchUploadUrl(e,t,n,i,l,o){var r;let s={};s=o||{apiVersion:"",headers:Object.assign({"Content-Type":"application/json","X-Goog-Upload-Protocol":"resumable","X-Goog-Upload-Command":"start","X-Goog-Upload-Header-Content-Length":`${t}`,"X-Goog-Upload-Header-Content-Type":`${n}`},i?{"X-Goog-Upload-File-Name":i}:{})};let a=await this.request({path:e,body:JSON.stringify(l),httpMethod:"POST",httpOptions:s});if(!a||!(null==a?void 0:a.headers))throw Error("Server did not return an HttpResponse or the returned HttpResponse did not have headers.");let u=null===(r=null==a?void 0:a.headers)||void 0===r?void 0:r["x-goog-upload-url"];if(void 0===u)throw Error("Failed to get upload url. Server did not return the x-google-upload-url in the headers");return u}}async function nq(e){var t;if(void 0===e)throw Error("response is undefined");if(!e.ok){let n=e.status,i=JSON.stringify((null===(t=e.headers.get("content-type"))||void 0===t?void 0:t.includes("application/json"))?await e.json():{error:{message:await e.text(),code:e.status,status:e.statusText}});if(n>=400&&n<600)throw new nd({message:i,status:n});throw Error(i)}}function nk(e){for(let t of e){if(null!==t&&"object"==typeof t&&t instanceof nL||"object"==typeof t&&"inputSchema"in t)return!0}return!1}function nG(e){var t;let n=null!==(t=e[nM])&&void 0!==t?t:"";e[nM]=(n+" mcp_used/unknown").trimStart()}class nL{constructor(e=[],t){this.mcpTools=[],this.functionNameToMcpClient={},this.mcpClients=e,this.config=t}static create(e,t){return new nL(e,t)}async initialize(){var e,t,n,i;if(this.mcpTools.length>0)return;let l={},o=[];for(let u of this.mcpClients)try{for(var r,s=!0,a=(t=void 0,nr(function(e,t=100){return no(this,arguments,function*(){let n;let i=0;for(;i<t;){let t=yield nl(e.listTools({cursor:n}));for(let e of t.tools)yield yield nl(e),i++;if(!t.nextCursor)break;n=t.nextCursor}})}(u)));!(e=(r=await a.next()).done);s=!0){i=r.value,s=!1,o.push(i);let e=i.name;if(l[e])throw Error(`Duplicate function name ${e} found in MCP tools. Please ensure function names are unique.`);l[e]=u}}catch(e){t={error:e}}finally{try{!s&&!e&&(n=a.return)&&await n.call(a)}finally{if(t)throw t.error}}this.mcpTools=o,this.functionNameToMcpClient=l}async tool(){return await this.initialize(),function(e,t={}){let n=[],i=new Set;for(let l of e){let e=l.name;if(i.has(e))throw Error(`Duplicate function name ${e} found in MCP tools. Please ensure function names are unique.`);i.add(e);let o=function(e,t={}){let n={name:e.name,description:e.description,parametersJsonSchema:e.inputSchema};return e.outputSchema&&(n.responseJsonSchema=e.outputSchema),t.behavior&&(n.behavior=t.behavior),{functionDeclarations:[n]}}(l,t);o.functionDeclarations&&n.push(...o.functionDeclarations)}return{functionDeclarations:n}}(this.mcpTools,this.config)}async callTool(e){await this.initialize();let t=[];for(let n of e)if(n.name in this.functionNameToMcpClient){let e;let i=this.functionNameToMcpClient[n.name];this.config.timeout&&(e={timeout:this.config.timeout});let l=await i.callTool({name:n.name,arguments:n.args},void 0,e);t.push({functionResponse:{name:n.name,response:l.isError?{error:l}:l}})}return t}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/async function nx(e,t,n){let i=new tP;Object.assign(i,n.data instanceof Blob?JSON.parse(await n.data.text()):JSON.parse(n.data)),t(i)}class nH{constructor(e,t,n){this.apiClient=e,this.auth=t,this.webSocketFactory=n}async connect(e){var t,n;if(this.apiClient.isVertexAI())throw Error("Live music is not supported for Vertex AI.");console.warn("Live music generation is experimental and may change in future versions.");let i=this.apiClient.getWebsocketBaseUrl(),l=this.apiClient.getApiVersion(),o=function(e){let t=new Headers;for(let[n,i]of Object.entries(e))t.append(n,i);return t}(this.apiClient.getDefaultHeaders()),r=this.apiClient.getApiKey(),s=`${i}/ws/google.ai.generativelanguage.${l}.GenerativeService.BidiGenerateMusic?key=${r}`,a=()=>{},u=new Promise(e=>{a=e}),p=e.callbacks,d=this.apiClient,c={onopen:function(){a({})},onmessage:e=>{nx(d,p.onmessage,e)},onerror:null!==(t=null==p?void 0:p.onerror)&&void 0!==t?t:function(e){},onclose:null!==(n=null==p?void 0:p.onclose)&&void 0!==n?n:function(e){}},h=this.webSocketFactory.create(s,function(e){let t={};return e.forEach((e,n)=>{t[n]=e}),t}(o),c);h.connect(),await u;let f=tM(this.apiClient,e.model);return h.send(JSON.stringify({setup:{model:f}})),new nF(h,this.apiClient)}}class nF{constructor(e,t){this.conn=e,this.apiClient=t}async setWeightedPrompts(e){if(!e.weightedPrompts||0===Object.keys(e.weightedPrompts).length)throw Error("Weighted prompts must be set and contain at least one entry.");let t=function(e){let t={},n=tn(e,["weightedPrompts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["weightedPrompts"],e)}return t}(e);this.conn.send(JSON.stringify({clientContent:t}))}async setMusicGenerationConfig(e){e.musicGenerationConfig||(e.musicGenerationConfig={});let t=function(e){let t={},n=tn(e,["musicGenerationConfig"]);return null!=n&&tt(t,["musicGenerationConfig"],n),t}(e);this.conn.send(JSON.stringify(t))}sendPlaybackControl(e){this.conn.send(JSON.stringify({playbackControl:e}))}play(){this.sendPlaybackControl(ei.PLAY)}pause(){this.sendPlaybackControl(ei.PAUSE)}stop(){this.sendPlaybackControl(ei.STOP)}resetContext(){this.sendPlaybackControl(ei.RESET_CONTEXT)}close(){this.conn.close()}}async function nV(e,t,n){let i=new tR,l=JSON.parse(n.data instanceof Blob?await n.data.text():n.data instanceof ArrayBuffer?new TextDecoder().decode(n.data):n.data);e.isVertexAI()?Object.assign(i,function(e){let t={},n=tn(e,["setupComplete"]);null!=n&&tt(t,["setupComplete"],n);let i=tn(e,["serverContent"]);null!=i&&tt(t,["serverContent"],i);let l=tn(e,["toolCall"]);null!=l&&tt(t,["toolCall"],l);let o=tn(e,["toolCallCancellation"]);null!=o&&tt(t,["toolCallCancellation"],o);let r=tn(e,["usageMetadata"]);null!=r&&tt(t,["usageMetadata"],function(e){let t={},n=tn(e,["promptTokenCount"]);null!=n&&tt(t,["promptTokenCount"],n);let i=tn(e,["cachedContentTokenCount"]);null!=i&&tt(t,["cachedContentTokenCount"],i);let l=tn(e,["candidatesTokenCount"]);null!=l&&tt(t,["responseTokenCount"],l);let o=tn(e,["toolUsePromptTokenCount"]);null!=o&&tt(t,["toolUsePromptTokenCount"],o);let r=tn(e,["thoughtsTokenCount"]);null!=r&&tt(t,["thoughtsTokenCount"],r);let s=tn(e,["totalTokenCount"]);null!=s&&tt(t,["totalTokenCount"],s);let a=tn(e,["promptTokensDetails"]);if(null!=a){let e=a;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["promptTokensDetails"],e)}let u=tn(e,["cacheTokensDetails"]);if(null!=u){let e=u;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["cacheTokensDetails"],e)}let p=tn(e,["candidatesTokensDetails"]);if(null!=p){let e=p;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["responseTokensDetails"],e)}let d=tn(e,["toolUsePromptTokensDetails"]);if(null!=d){let e=d;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["toolUsePromptTokensDetails"],e)}let c=tn(e,["trafficType"]);return null!=c&&tt(t,["trafficType"],c),t}(r));let s=tn(e,["goAway"]);null!=s&&tt(t,["goAway"],s);let a=tn(e,["sessionResumptionUpdate"]);return null!=a&&tt(t,["sessionResumptionUpdate"],a),t}(l)):Object.assign(i,l),t(i)}class nj{constructor(e,t,n){this.apiClient=e,this.auth=t,this.webSocketFactory=n,this.music=new nH(this.apiClient,this.auth,this.webSocketFactory)}async connect(e){var t,n,i,l,o,r;let s;if(e.config&&e.config.httpOptions)throw Error("The Live module does not support httpOptions at request-level in LiveConnectConfig yet. Please use the client-level httpOptions configuration instead.");let a=this.apiClient.getWebsocketBaseUrl(),u=this.apiClient.getApiVersion(),p=this.apiClient.getHeaders();e.config&&e.config.tools&&nk(e.config.tools)&&nG(p);let d=function(e){let t=new Headers;for(let[n,i]of Object.entries(e))t.append(n,i);return t}(p);if(this.apiClient.isVertexAI())s=`${a}/ws/google.cloud.aiplatform.${u}.LlmBidiService/BidiGenerateContent`,await this.auth.addAuthHeaders(d,s);else{let e=this.apiClient.getApiKey(),t="BidiGenerateContent",n="key";(null==e?void 0:e.startsWith("auth_tokens/"))&&(console.warn("Warning: Ephemeral token support is experimental and may change in future versions."),"v1alpha"!==u&&console.warn("Warning: The SDK's ephemeral token support is in v1alpha only. Please use const ai = new GoogleGenAI({apiKey: token.name, httpOptions: { apiVersion: 'v1alpha' }}); before session connection."),t="BidiGenerateContentConstrained",n="access_token"),s=`${a}/ws/google.ai.generativelanguage.${u}.GenerativeService.${t}?${n}=${e}`}let c=()=>{},h=new Promise(e=>{c=e}),f=e.callbacks,m=this.apiClient,g={onopen:function(){var e;null===(e=null==f?void 0:f.onopen)||void 0===e||e.call(f),c({})},onmessage:e=>{nV(m,f.onmessage,e)},onerror:null!==(t=null==f?void 0:f.onerror)&&void 0!==t?t:function(e){},onclose:null!==(n=null==f?void 0:f.onclose)&&void 0!==n?n:function(e){}},y=this.webSocketFactory.create(s,function(e){let t={};return e.forEach((e,n)=>{t[n]=e}),t}(d),g);y.connect(),await h;let E=tM(this.apiClient,e.model);if(this.apiClient.isVertexAI()&&E.startsWith("publishers/")){let e=this.apiClient.getProject(),t=this.apiClient.getLocation();E=`projects/${e}/locations/${t}/`+E}let v={};this.apiClient.isVertexAI()&&(null===(i=e.config)||void 0===i?void 0:i.responseModalities)===void 0&&(void 0===e.config?e.config={responseModalities:[T.AUDIO]}:e.config.responseModalities=[T.AUDIO]),(null===(l=e.config)||void 0===l?void 0:l.generationConfig)&&console.warn("Setting `LiveConnectConfig.generation_config` is deprecated, please set the fields on `LiveConnectConfig` directly. This will become an error in a future version (not before Q3 2025).");let _=null!==(r=null===(o=e.config)||void 0===o?void 0:o.tools)&&void 0!==r?r:[],I=[];for(let e of _)this.isCallableTool(e)?I.push(await e.tool()):I.push(e);I.length>0&&(e.config.tools=I);let A={model:E,config:e.config,callbacks:e.callbacks};return v=this.apiClient.isVertexAI()?function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["setup","model"],tM(e,i));let l=tn(t,["config"]);return null!=l&&tt(n,["config"],function(e,t){let n=tn(e,["generationConfig"]);void 0!==t&&null!=n&&tt(t,["setup","generationConfig"],function(e){let t={},n=tn(e,["modelSelectionConfig"]);null!=n&&tt(t,["modelConfig"],n);let i=tn(e,["responseJsonSchema"]);null!=i&&tt(t,["responseJsonSchema"],i);let l=tn(e,["audioTimestamp"]);null!=l&&tt(t,["audioTimestamp"],l);let o=tn(e,["candidateCount"]);null!=o&&tt(t,["candidateCount"],o);let r=tn(e,["enableAffectiveDialog"]);null!=r&&tt(t,["enableAffectiveDialog"],r);let s=tn(e,["frequencyPenalty"]);null!=s&&tt(t,["frequencyPenalty"],s);let a=tn(e,["logprobs"]);null!=a&&tt(t,["logprobs"],a);let u=tn(e,["maxOutputTokens"]);null!=u&&tt(t,["maxOutputTokens"],u);let p=tn(e,["mediaResolution"]);null!=p&&tt(t,["mediaResolution"],p);let d=tn(e,["presencePenalty"]);null!=d&&tt(t,["presencePenalty"],d);let c=tn(e,["responseLogprobs"]);null!=c&&tt(t,["responseLogprobs"],c);let h=tn(e,["responseMimeType"]);null!=h&&tt(t,["responseMimeType"],h);let f=tn(e,["responseModalities"]);null!=f&&tt(t,["responseModalities"],f);let m=tn(e,["responseSchema"]);null!=m&&tt(t,["responseSchema"],m);let g=tn(e,["routingConfig"]);null!=g&&tt(t,["routingConfig"],g);let y=tn(e,["seed"]);null!=y&&tt(t,["seed"],y);let E=tn(e,["speechConfig"]);null!=E&&tt(t,["speechConfig"],nf(E));let v=tn(e,["stopSequences"]);null!=v&&tt(t,["stopSequences"],v);let _=tn(e,["temperature"]);null!=_&&tt(t,["temperature"],_);let I=tn(e,["thinkingConfig"]);null!=I&&tt(t,["thinkingConfig"],I);let T=tn(e,["topK"]);null!=T&&tt(t,["topK"],T);let A=tn(e,["topP"]);if(null!=A&&tt(t,["topP"],A),void 0!==tn(e,["enableEnhancedCivicAnswers"]))throw Error("enableEnhancedCivicAnswers parameter is not supported in Vertex AI.");return t}(n));let i=tn(e,["responseModalities"]);void 0!==t&&null!=i&&tt(t,["setup","generationConfig","responseModalities"],i);let l=tn(e,["temperature"]);void 0!==t&&null!=l&&tt(t,["setup","generationConfig","temperature"],l);let o=tn(e,["topP"]);void 0!==t&&null!=o&&tt(t,["setup","generationConfig","topP"],o);let r=tn(e,["topK"]);void 0!==t&&null!=r&&tt(t,["setup","generationConfig","topK"],r);let s=tn(e,["maxOutputTokens"]);void 0!==t&&null!=s&&tt(t,["setup","generationConfig","maxOutputTokens"],s);let a=tn(e,["mediaResolution"]);void 0!==t&&null!=a&&tt(t,["setup","generationConfig","mediaResolution"],a);let u=tn(e,["seed"]);void 0!==t&&null!=u&&tt(t,["setup","generationConfig","seed"],u);let p=tn(e,["speechConfig"]);void 0!==t&&null!=p&&tt(t,["setup","generationConfig","speechConfig"],nf(tW(p)));let d=tn(e,["thinkingConfig"]);void 0!==t&&null!=d&&tt(t,["setup","generationConfig","thinkingConfig"],d);let c=tn(e,["enableAffectiveDialog"]);void 0!==t&&null!=c&&tt(t,["setup","generationConfig","enableAffectiveDialog"],c);let h=tn(e,["systemInstruction"]);void 0!==t&&null!=h&&tt(t,["setup","systemInstruction"],tj(h));let f=tn(e,["tools"]);if(void 0!==t&&null!=f){let e=tz(f);Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["functionDeclarations"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={};if(void 0!==tn(e,["behavior"]))throw Error("behavior parameter is not supported in Vertex AI.");let n=tn(e,["description"]);null!=n&&tt(t,["description"],n);let i=tn(e,["name"]);null!=i&&tt(t,["name"],i);let l=tn(e,["parameters"]);null!=l&&tt(t,["parameters"],l);let o=tn(e,["parametersJsonSchema"]);null!=o&&tt(t,["parametersJsonSchema"],o);let r=tn(e,["response"]);null!=r&&tt(t,["response"],r);let s=tn(e,["responseJsonSchema"]);return null!=s&&tt(t,["responseJsonSchema"],s),t})(e))),tt(t,["functionDeclarations"],e)}let i=tn(e,["retrieval"]);null!=i&&tt(t,["retrieval"],i);let l=tn(e,["googleSearchRetrieval"]);null!=l&&tt(t,["googleSearchRetrieval"],l);let o=tn(e,["computerUse"]);if(null!=o&&tt(t,["computerUse"],o),void 0!==tn(e,["fileSearch"]))throw Error("fileSearch parameter is not supported in Vertex AI.");let r=tn(e,["codeExecution"]);null!=r&&tt(t,["codeExecution"],r);let s=tn(e,["enterpriseWebSearch"]);null!=s&&tt(t,["enterpriseWebSearch"],s);let a=tn(e,["googleMaps"]);null!=a&&tt(t,["googleMaps"],a);let u=tn(e,["googleSearch"]);null!=u&&tt(t,["googleSearch"],u);let p=tn(e,["urlContext"]);return null!=p&&tt(t,["urlContext"],p),t})(t$(e)))),tt(t,["setup","tools"],e)}let m=tn(e,["sessionResumption"]);void 0!==t&&null!=m&&tt(t,["setup","sessionResumption"],m);let g=tn(e,["inputAudioTranscription"]);void 0!==t&&null!=g&&tt(t,["setup","inputAudioTranscription"],g);let y=tn(e,["outputAudioTranscription"]);void 0!==t&&null!=y&&tt(t,["setup","outputAudioTranscription"],y);let E=tn(e,["realtimeInputConfig"]);void 0!==t&&null!=E&&tt(t,["setup","realtimeInputConfig"],E);let v=tn(e,["contextWindowCompression"]);void 0!==t&&null!=v&&tt(t,["setup","contextWindowCompression"],v);let _=tn(e,["proactivity"]);return void 0!==t&&null!=_&&tt(t,["setup","proactivity"],_),{}}(l,n)),n}(this.apiClient,A):function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["setup","model"],tM(e,i));let l=tn(t,["config"]);return null!=l&&tt(n,["config"],function(e,t){let n=tn(e,["generationConfig"]);void 0!==t&&null!=n&&tt(t,["setup","generationConfig"],n);let i=tn(e,["responseModalities"]);void 0!==t&&null!=i&&tt(t,["setup","generationConfig","responseModalities"],i);let l=tn(e,["temperature"]);void 0!==t&&null!=l&&tt(t,["setup","generationConfig","temperature"],l);let o=tn(e,["topP"]);void 0!==t&&null!=o&&tt(t,["setup","generationConfig","topP"],o);let r=tn(e,["topK"]);void 0!==t&&null!=r&&tt(t,["setup","generationConfig","topK"],r);let s=tn(e,["maxOutputTokens"]);void 0!==t&&null!=s&&tt(t,["setup","generationConfig","maxOutputTokens"],s);let a=tn(e,["mediaResolution"]);void 0!==t&&null!=a&&tt(t,["setup","generationConfig","mediaResolution"],a);let u=tn(e,["seed"]);void 0!==t&&null!=u&&tt(t,["setup","generationConfig","seed"],u);let p=tn(e,["speechConfig"]);void 0!==t&&null!=p&&tt(t,["setup","generationConfig","speechConfig"],tW(p));let d=tn(e,["thinkingConfig"]);void 0!==t&&null!=d&&tt(t,["setup","generationConfig","thinkingConfig"],d);let c=tn(e,["enableAffectiveDialog"]);void 0!==t&&null!=c&&tt(t,["setup","generationConfig","enableAffectiveDialog"],c);let h=tn(e,["systemInstruction"]);void 0!==t&&null!=h&&tt(t,["setup","systemInstruction"],function(e){let t={},n=tn(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["mediaResolution"]);null!=n&&tt(t,["mediaResolution"],n);let i=tn(e,["codeExecutionResult"]);null!=i&&tt(t,["codeExecutionResult"],i);let l=tn(e,["executableCode"]);null!=l&&tt(t,["executableCode"],l);let o=tn(e,["fileData"]);null!=o&&tt(t,["fileData"],function(e){let t={};if(void 0!==tn(e,["displayName"]))throw Error("displayName parameter is not supported in Gemini API.");let n=tn(e,["fileUri"]);null!=n&&tt(t,["fileUri"],n);let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}(o));let r=tn(e,["functionCall"]);null!=r&&tt(t,["functionCall"],function(e){let t={},n=tn(e,["id"]);null!=n&&tt(t,["id"],n);let i=tn(e,["args"]);null!=i&&tt(t,["args"],i);let l=tn(e,["name"]);if(null!=l&&tt(t,["name"],l),void 0!==tn(e,["partialArgs"]))throw Error("partialArgs parameter is not supported in Gemini API.");if(void 0!==tn(e,["willContinue"]))throw Error("willContinue parameter is not supported in Gemini API.");return t}(r));let s=tn(e,["functionResponse"]);null!=s&&tt(t,["functionResponse"],s);let a=tn(e,["inlineData"]);null!=a&&tt(t,["inlineData"],nh(a));let u=tn(e,["text"]);null!=u&&tt(t,["text"],u);let p=tn(e,["thought"]);null!=p&&tt(t,["thought"],p);let d=tn(e,["thoughtSignature"]);null!=d&&tt(t,["thoughtSignature"],d);let c=tn(e,["videoMetadata"]);return null!=c&&tt(t,["videoMetadata"],c),t})(e))),tt(t,["parts"],e)}let i=tn(e,["role"]);return null!=i&&tt(t,["role"],i),t}(tj(h)));let f=tn(e,["tools"]);if(void 0!==t&&null!=f){let e=tz(f);Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["functionDeclarations"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["functionDeclarations"],e)}if(void 0!==tn(e,["retrieval"]))throw Error("retrieval parameter is not supported in Gemini API.");let i=tn(e,["googleSearchRetrieval"]);null!=i&&tt(t,["googleSearchRetrieval"],i);let l=tn(e,["computerUse"]);null!=l&&tt(t,["computerUse"],l);let o=tn(e,["fileSearch"]);null!=o&&tt(t,["fileSearch"],o);let r=tn(e,["codeExecution"]);if(null!=r&&tt(t,["codeExecution"],r),void 0!==tn(e,["enterpriseWebSearch"]))throw Error("enterpriseWebSearch parameter is not supported in Gemini API.");let s=tn(e,["googleMaps"]);null!=s&&tt(t,["googleMaps"],function(e){let t={};if(void 0!==tn(e,["authConfig"]))throw Error("authConfig parameter is not supported in Gemini API.");let n=tn(e,["enableWidget"]);return null!=n&&tt(t,["enableWidget"],n),t}(s));let a=tn(e,["googleSearch"]);null!=a&&tt(t,["googleSearch"],function(e){let t={};if(void 0!==tn(e,["excludeDomains"]))throw Error("excludeDomains parameter is not supported in Gemini API.");if(void 0!==tn(e,["blockingConfidence"]))throw Error("blockingConfidence parameter is not supported in Gemini API.");let n=tn(e,["timeRangeFilter"]);return null!=n&&tt(t,["timeRangeFilter"],n),t}(a));let u=tn(e,["urlContext"]);return null!=u&&tt(t,["urlContext"],u),t})(t$(e)))),tt(t,["setup","tools"],e)}let m=tn(e,["sessionResumption"]);void 0!==t&&null!=m&&tt(t,["setup","sessionResumption"],function(e){let t={},n=tn(e,["handle"]);if(null!=n&&tt(t,["handle"],n),void 0!==tn(e,["transparent"]))throw Error("transparent parameter is not supported in Gemini API.");return t}(m));let g=tn(e,["inputAudioTranscription"]);void 0!==t&&null!=g&&tt(t,["setup","inputAudioTranscription"],g);let y=tn(e,["outputAudioTranscription"]);void 0!==t&&null!=y&&tt(t,["setup","outputAudioTranscription"],y);let E=tn(e,["realtimeInputConfig"]);void 0!==t&&null!=E&&tt(t,["setup","realtimeInputConfig"],E);let v=tn(e,["contextWindowCompression"]);void 0!==t&&null!=v&&tt(t,["setup","contextWindowCompression"],v);let _=tn(e,["proactivity"]);return void 0!==t&&null!=_&&tt(t,["setup","proactivity"],_),{}}(l,n)),n}(this.apiClient,A),delete v.config,y.send(JSON.stringify(v)),new nJ(y,this.apiClient)}isCallableTool(e){return"callTool"in e&&"function"==typeof e.callTool}}let nB={turnComplete:!0};class nJ{constructor(e,t){this.conn=e,this.apiClient=t}tLiveClientContent(e,t){if(null!==t.turns&&void 0!==t.turns){let n=[];try{n=tJ(t.turns),e.isVertexAI()||(n=n.map(e=>nm(e)))}catch(e){throw Error(`Failed to parse client content "turns", type: '${typeof t.turns}'`)}return{clientContent:{turns:n,turnComplete:t.turnComplete}}}return{clientContent:{turnComplete:t.turnComplete}}}tLiveClienttToolResponse(e,t){let n=[];if(null==t.functionResponses||0===(n=Array.isArray(t.functionResponses)?t.functionResponses:[t.functionResponses]).length)throw Error("functionResponses is required.");for(let t of n){if("object"!=typeof t||null===t||!("name"in t)||!("response"in t))throw Error(`Could not parse function response, type '${typeof t}'.`);if(!e.isVertexAI()&&!("id"in t))throw Error("FunctionResponse request must have an `id` field from the response of a ToolCall.FunctionalCalls in Google AI.")}return{toolResponse:{functionResponses:n}}}sendClientContent(e){e=Object.assign(Object.assign({},nB),e);let t=this.tLiveClientContent(this.apiClient,e);this.conn.send(JSON.stringify(t))}sendRealtimeInput(e){let t={};t=this.apiClient.isVertexAI()?{realtimeInput:function(e){let t={},n=tn(e,["media"]);if(null!=n){let e=tw(n);Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["mediaChunks"],e)}let i=tn(e,["audio"]);null!=i&&tt(t,["audio"],tG(i));let l=tn(e,["audioStreamEnd"]);null!=l&&tt(t,["audioStreamEnd"],l);let o=tn(e,["video"]);null!=o&&tt(t,["video"],tk(o));let r=tn(e,["text"]);null!=r&&tt(t,["text"],r);let s=tn(e,["activityStart"]);null!=s&&tt(t,["activityStart"],s);let a=tn(e,["activityEnd"]);return null!=a&&tt(t,["activityEnd"],a),t}(e)}:{realtimeInput:function(e){let t={},n=tn(e,["media"]);if(null!=n){let e=tw(n);Array.isArray(e)&&(e=e.map(e=>nh(e))),tt(t,["mediaChunks"],e)}let i=tn(e,["audio"]);null!=i&&tt(t,["audio"],nh(tG(i)));let l=tn(e,["audioStreamEnd"]);null!=l&&tt(t,["audioStreamEnd"],l);let o=tn(e,["video"]);null!=o&&tt(t,["video"],nh(tk(o)));let r=tn(e,["text"]);null!=r&&tt(t,["text"],r);let s=tn(e,["activityStart"]);null!=s&&tt(t,["activityStart"],s);let a=tn(e,["activityEnd"]);return null!=a&&tt(t,["activityEnd"],a),t}(e)},this.conn.send(JSON.stringify(t))}sendToolResponse(e){if(null==e.functionResponses)throw Error("Tool response parameters are required.");let t=this.tLiveClienttToolResponse(this.apiClient,e);this.conn.send(JSON.stringify(t))}close(){this.conn.close()}}function nY(e){var t,n,i;if(null===(t=null==e?void 0:e.automaticFunctionCalling)||void 0===t?void 0:t.disable)return!0;let l=!1;for(let t of null!==(n=null==e?void 0:e.tools)&&void 0!==n?n:[])if(nK(t)){l=!0;break}if(!l)return!0;let o=null===(i=null==e?void 0:e.automaticFunctionCalling)||void 0===i?void 0:i.maximumRemoteCalls;return(!!o&&(o<0||!Number.isInteger(o))||0==o)&&(console.warn("Invalid maximumRemoteCalls value provided for automatic function calling. Disabled automatic function calling. Please provide a valid integer value greater than 0. maximumRemoteCalls provided:",o),!0)}function nK(e){return"callTool"in e&&"function"==typeof e.callTool}function nW(e){var t;let n=[];return(null===(t=null==e?void 0:e.config)||void 0===t?void 0:t.tools)&&e.config.tools.forEach((e,t)=>{!nK(e)&&e.functionDeclarations&&e.functionDeclarations.length>0&&n.push(t)}),n}function n$(e){var t;return!(null===(t=null==e?void 0:e.automaticFunctionCalling)||void 0===t?void 0:t.ignoreCallHistory)}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class nz extends e7{constructor(e){super(),this.apiClient=e,this.generateContent=async e=>{var t,n,i,l,o,r,s,a;let u,p;let d=await this.processParamsMaybeAddMcpUsage(e);if(this.maybeMoveToResponseJsonSchem(e),!(null!==(a=null===(s=null===(r=e.config)||void 0===r?void 0:r.tools)||void 0===s?void 0:s.some(e=>nK(e)))&&void 0!==a&&a)||nY(e.config))return await this.generateContentInternal(d);let c=nW(e);if(c.length>0){let e=c.map(e=>`tools[${e}]`).join(", ");throw Error(`Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations is not yet supported. Incompatible tools found at ${e}.`)}let h=tJ(d.contents),f=null!==(i=null===(n=null===(t=d.config)||void 0===t?void 0:t.automaticFunctionCalling)||void 0===n?void 0:n.maximumRemoteCalls)&&void 0!==i?i:10,m=0;for(;m<f&&(u=await this.generateContentInternal(d)).functionCalls&&0!==u.functionCalls.length;){let t=u.candidates[0].content,n=[];for(let t of null!==(o=null===(l=e.config)||void 0===l?void 0:l.tools)&&void 0!==o?o:[])if(nK(t)){let e=await t.callTool(u.functionCalls);n.push(...e)}m++,p={role:"user",parts:n},d.contents=tJ(d.contents),d.contents.push(t),d.contents.push(p),n$(d.config)&&(h.push(t),h.push(p))}return n$(d.config)&&(u.automaticFunctionCallingHistory=h),u},this.generateContentStream=async e=>{var t,n,i,l,o;if(this.maybeMoveToResponseJsonSchem(e),nY(e.config)){let t=await this.processParamsMaybeAddMcpUsage(e);return await this.generateContentStreamInternal(t)}let r=nW(e);if(r.length>0){let e=r.map(e=>`tools[${e}]`).join(", ");throw Error(`Incompatible tools found at ${e}. Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations" is not yet supported.`)}let s=null===(i=null===(n=null===(t=null==e?void 0:e.config)||void 0===t?void 0:t.toolConfig)||void 0===n?void 0:n.functionCallingConfig)||void 0===i?void 0:i.streamFunctionCallArguments,a=null===(o=null===(l=null==e?void 0:e.config)||void 0===l?void 0:l.automaticFunctionCalling)||void 0===o?void 0:o.disable;if(s&&!a)throw Error("Running in streaming mode with 'streamFunctionCallArguments' enabled, this feature is not compatible with automatic function calling (AFC). Please set 'config.automaticFunctionCalling.disable' to true to disable AFC or leave 'config.toolConfig.functionCallingConfig.streamFunctionCallArguments' to be undefined or set to false to disable streaming function call arguments feature.");return await this.processAfcStream(e)},this.generateImages=async e=>await this.generateImagesInternal(e).then(e=>{var t;let n;let i=[];if(null==e?void 0:e.generatedImages)for(let l of e.generatedImages)l&&(null==l?void 0:l.safetyAttributes)&&(null===(t=null==l?void 0:l.safetyAttributes)||void 0===t?void 0:t.contentType)==="Positive Prompt"?n=null==l?void 0:l.safetyAttributes:i.push(l);return n?{generatedImages:i,positivePromptSafetyAttributes:n,sdkHttpResponse:e.sdkHttpResponse}:{generatedImages:i,sdkHttpResponse:e.sdkHttpResponse}}),this.list=async e=>{var t;let n={config:Object.assign(Object.assign({},{queryBase:!0}),null==e?void 0:e.config)};if(this.apiClient.isVertexAI()&&!n.config.queryBase){if(null===(t=n.config)||void 0===t?void 0:t.filter)throw Error("Filtering tuned models list for Vertex AI is not currently supported");n.config.filter="labels.tune-type:*"}return new ne(el.PAGED_ITEM_MODELS,e=>this.listInternal(e),await this.listInternal(n),n)},this.editImage=async e=>{let t={model:e.model,prompt:e.prompt,referenceImages:[],config:e.config};return e.referenceImages&&e.referenceImages&&(t.referenceImages=e.referenceImages.map(e=>e.toReferenceImageAPI())),await this.editImageInternal(t)},this.upscaleImage=async e=>{let t={numberOfImages:1,mode:"upscale"};e.config&&(t=Object.assign(Object.assign({},t),e.config));let n={model:e.model,image:e.image,upscaleFactor:e.upscaleFactor,config:t};return await this.upscaleImageInternal(n)},this.generateVideos=async e=>{var t,n,i,l,o,r;if((e.prompt||e.image||e.video)&&e.source)throw Error("Source and prompt/image/video are mutually exclusive. Please only use source.");return!this.apiClient.isVertexAI()&&((null===(t=e.video)||void 0===t?void 0:t.uri)&&(null===(n=e.video)||void 0===n?void 0:n.videoBytes)?e.video={uri:e.video.uri,mimeType:e.video.mimeType}:(null===(l=null===(i=e.source)||void 0===i?void 0:i.video)||void 0===l?void 0:l.uri)&&(null===(r=null===(o=e.source)||void 0===o?void 0:o.video)||void 0===r?void 0:r.videoBytes)&&(e.source.video={uri:e.source.video.uri,mimeType:e.source.video.mimeType})),await this.generateVideosInternal(e)}}maybeMoveToResponseJsonSchem(e){e.config&&e.config.responseSchema&&!e.config.responseJsonSchema&&Object.keys(e.config.responseSchema).includes("$schema")&&(e.config.responseJsonSchema=e.config.responseSchema,delete e.config.responseSchema)}async processParamsMaybeAddMcpUsage(e){var t,n,i;let l=null===(t=e.config)||void 0===t?void 0:t.tools;if(!l)return e;let o=await Promise.all(l.map(async e=>nK(e)?await e.tool():e)),r={model:e.model,contents:e.contents,config:Object.assign(Object.assign({},e.config),{tools:o})};if(r.config.tools=o,e.config&&e.config.tools&&nk(e.config.tools)){let t=Object.assign({},null!==(i=null===(n=e.config.httpOptions)||void 0===n?void 0:n.headers)&&void 0!==i?i:{});0===Object.keys(t).length&&(t=this.apiClient.getDefaultHeaders()),nG(t),r.config.httpOptions=Object.assign(Object.assign({},e.config.httpOptions),{headers:t})}return r}async initAfcToolsMap(e){var t,n,i;let l=new Map;for(let o of null!==(n=null===(t=e.config)||void 0===t?void 0:t.tools)&&void 0!==n?n:[])if(nK(o))for(let e of null!==(i=(await o.tool()).functionDeclarations)&&void 0!==i?i:[]){if(!e.name)throw Error("Function declaration name is required.");if(l.has(e.name))throw Error(`Duplicate tool declaration name: ${e.name}`);l.set(e.name,o)}return l}async processAfcStream(e){var t,n,i;let l=null!==(i=null===(n=null===(t=e.config)||void 0===t?void 0:t.automaticFunctionCalling)||void 0===n?void 0:n.maximumRemoteCalls)&&void 0!==i?i:10,o=!1,r=0;return function(e,t,n){var i,s;return no(this,arguments,function*(){for(var a,u,p,d;r<l;){o&&(r++,o=!1);let m=yield nl(e.processParamsMaybeAddMcpUsage(n)),g=yield nl(e.generateContentStreamInternal(m)),y=[],E=[];try{for(var c,h=!0,f=(u=void 0,nr(g));!(a=(c=yield nl(f.next())).done);h=!0)if(d=c.value,h=!1,yield yield nl(d),d.candidates&&(null===(i=d.candidates[0])||void 0===i?void 0:i.content)){for(let e of(E.push(d.candidates[0].content),null!==(s=d.candidates[0].content.parts)&&void 0!==s?s:[]))if(r<l&&e.functionCall){if(!e.functionCall.name)throw Error("Function call name was not returned by the model.");if(t.has(e.functionCall.name)){let n=yield nl(t.get(e.functionCall.name).callTool([e.functionCall]));y.push(...n)}else throw Error(`Automatic function calling was requested, but not all the tools the model used implement the CallableTool interface. Available tools: ${t.keys()}, mising tool: ${e.functionCall.name}`)}}}catch(e){u={error:e}}finally{try{!h&&!a&&(p=f.return)&&(yield nl(p.call(f)))}finally{if(u)throw u.error}}if(y.length>0){o=!0;let e=new tr;e.candidates=[{content:{role:"user",parts:y}}],yield yield nl(e);let t=[];t.push(...E),t.push({role:"user",parts:y});let i=tJ(n.contents).concat(t);n.contents=i}else break}})}(this,await this.initAfcToolsMap(e),e)}async generateContentInternal(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=ny(this.apiClient,e);return o=te("{model}:generateContent",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=nv(e),n=new tr;return Object.assign(n,t),n})}{let t=ng(this.apiClient,e);return o=te("{model}:generateContent",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=nE(e),n=new tr;return Object.assign(n,t),n})}}async generateContentStreamInternal(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=ny(this.apiClient,e);return o=te("{model}:streamGenerateContent?alt=sse",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.requestStream({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(function(e){return no(this,arguments,function*(){var t,n,i,l;try{for(var o,r=!0,s=nr(e);!(t=(o=yield nl(s.next())).done);r=!0){l=o.value,r=!1;let e=nv((yield nl(l.json())));e.sdkHttpResponse={headers:l.headers};let t=new tr;Object.assign(t,e),yield yield nl(t)}}catch(e){n={error:e}}finally{try{!r&&!t&&(i=s.return)&&(yield nl(i.call(s)))}finally{if(n)throw n.error}}})})}{let t=ng(this.apiClient,e);return o=te("{model}:streamGenerateContent?alt=sse",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.requestStream({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(function(e){return no(this,arguments,function*(){var t,n,i,l;try{for(var o,r=!0,s=nr(e);!(t=(o=yield nl(s.next())).done);r=!0){l=o.value,r=!1;let e=nE((yield nl(l.json())));e.sdkHttpResponse={headers:l.headers};let t=new tr;Object.assign(t,e),yield yield nl(t)}}catch(e){n={error:e}}finally{try{!r&&!t&&(i=s.return)&&(yield nl(i.call(s)))}finally{if(n)throw n.error}}})})}}async embedContent(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["contents"]);if(null!=l){let t=tB(e,l);Array.isArray(t)&&(t=t.map(e=>e)),tt(n,["instances[]","content"],t)}let o=tn(t,["config"]);return null!=o&&function(e,t){let n=tn(e,["taskType"]);void 0!==t&&null!=n&&tt(t,["instances[]","task_type"],n);let i=tn(e,["title"]);void 0!==t&&null!=i&&tt(t,["instances[]","title"],i);let l=tn(e,["outputDimensionality"]);void 0!==t&&null!=l&&tt(t,["parameters","outputDimensionality"],l);let o=tn(e,["mimeType"]);void 0!==t&&null!=o&&tt(t,["instances[]","mimeType"],o);let r=tn(e,["autoTruncate"]);void 0!==t&&null!=r&&tt(t,["parameters","autoTruncate"],r)}(o,n),n}(this.apiClient,e);return o=te("{model}:predict",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["predictions[]","embeddings"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["values"]);null!=n&&tt(t,["values"],n);let i=tn(e,["statistics"]);return null!=i&&tt(t,["statistics"],function(e){let t={},n=tn(e,["truncated"]);null!=n&&tt(t,["truncated"],n);let i=tn(e,["token_count"]);return null!=i&&tt(t,["tokenCount"],i),t}(i)),t})(e))),tt(t,["embeddings"],e)}let l=tn(e,["metadata"]);return null!=l&&tt(t,["metadata"],l),t}(e),n=new ts;return Object.assign(n,t),n})}{let t=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["contents"]);if(null!=l){let t=tB(e,l);Array.isArray(t)&&(t=t.map(e=>e)),tt(n,["requests[]","content"],t)}let o=tn(t,["config"]);null!=o&&function(e,t){let n=tn(e,["taskType"]);void 0!==t&&null!=n&&tt(t,["requests[]","taskType"],n);let i=tn(e,["title"]);void 0!==t&&null!=i&&tt(t,["requests[]","title"],i);let l=tn(e,["outputDimensionality"]);if(void 0!==t&&null!=l&&tt(t,["requests[]","outputDimensionality"],l),void 0!==tn(e,["mimeType"]))throw Error("mimeType parameter is not supported in Gemini API.");if(void 0!==tn(e,["autoTruncate"]))throw Error("autoTruncate parameter is not supported in Gemini API.")}(o,n);let r=tn(t,["model"]);return void 0!==r&&tt(n,["requests[]","model"],tM(e,r)),n}(this.apiClient,e);return o=te("{model}:batchEmbedContents",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["embeddings"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["embeddings"],e)}let l=tn(e,["metadata"]);return null!=l&&tt(t,["metadata"],l),t}(e),n=new ts;return Object.assign(n,t),n})}}async generateImagesInternal(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["prompt"]);null!=l&&tt(n,["instances[0]","prompt"],l);let o=tn(t,["config"]);return null!=o&&function(e,t){let n=tn(e,["outputGcsUri"]);void 0!==t&&null!=n&&tt(t,["parameters","storageUri"],n);let i=tn(e,["negativePrompt"]);void 0!==t&&null!=i&&tt(t,["parameters","negativePrompt"],i);let l=tn(e,["numberOfImages"]);void 0!==t&&null!=l&&tt(t,["parameters","sampleCount"],l);let o=tn(e,["aspectRatio"]);void 0!==t&&null!=o&&tt(t,["parameters","aspectRatio"],o);let r=tn(e,["guidanceScale"]);void 0!==t&&null!=r&&tt(t,["parameters","guidanceScale"],r);let s=tn(e,["seed"]);void 0!==t&&null!=s&&tt(t,["parameters","seed"],s);let a=tn(e,["safetyFilterLevel"]);void 0!==t&&null!=a&&tt(t,["parameters","safetySetting"],a);let u=tn(e,["personGeneration"]);void 0!==t&&null!=u&&tt(t,["parameters","personGeneration"],u);let p=tn(e,["includeSafetyAttributes"]);void 0!==t&&null!=p&&tt(t,["parameters","includeSafetyAttributes"],p);let d=tn(e,["includeRaiReason"]);void 0!==t&&null!=d&&tt(t,["parameters","includeRaiReason"],d);let c=tn(e,["language"]);void 0!==t&&null!=c&&tt(t,["parameters","language"],c);let h=tn(e,["outputMimeType"]);void 0!==t&&null!=h&&tt(t,["parameters","outputOptions","mimeType"],h);let f=tn(e,["outputCompressionQuality"]);void 0!==t&&null!=f&&tt(t,["parameters","outputOptions","compressionQuality"],f);let m=tn(e,["addWatermark"]);void 0!==t&&null!=m&&tt(t,["parameters","addWatermark"],m);let g=tn(e,["labels"]);void 0!==t&&null!=g&&tt(t,["labels"],g);let y=tn(e,["imageSize"]);void 0!==t&&null!=y&&tt(t,["parameters","sampleImageSize"],y);let E=tn(e,["enhancePrompt"]);void 0!==t&&null!=E&&tt(t,["parameters","enhancePrompt"],E)}(o,n),n}(this.apiClient,e);return o=te("{model}:predict",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["predictions"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>n_(e))),tt(t,["generatedImages"],e)}let l=tn(e,["positivePromptSafetyAttributes"]);return null!=l&&tt(t,["positivePromptSafetyAttributes"],nb(l)),t}(e),n=new ta;return Object.assign(n,t),n})}{let t=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["prompt"]);null!=l&&tt(n,["instances[0]","prompt"],l);let o=tn(t,["config"]);return null!=o&&function(e,t){if(void 0!==tn(e,["outputGcsUri"]))throw Error("outputGcsUri parameter is not supported in Gemini API.");if(void 0!==tn(e,["negativePrompt"]))throw Error("negativePrompt parameter is not supported in Gemini API.");let n=tn(e,["numberOfImages"]);void 0!==t&&null!=n&&tt(t,["parameters","sampleCount"],n);let i=tn(e,["aspectRatio"]);void 0!==t&&null!=i&&tt(t,["parameters","aspectRatio"],i);let l=tn(e,["guidanceScale"]);if(void 0!==t&&null!=l&&tt(t,["parameters","guidanceScale"],l),void 0!==tn(e,["seed"]))throw Error("seed parameter is not supported in Gemini API.");let o=tn(e,["safetyFilterLevel"]);void 0!==t&&null!=o&&tt(t,["parameters","safetySetting"],o);let r=tn(e,["personGeneration"]);void 0!==t&&null!=r&&tt(t,["parameters","personGeneration"],r);let s=tn(e,["includeSafetyAttributes"]);void 0!==t&&null!=s&&tt(t,["parameters","includeSafetyAttributes"],s);let a=tn(e,["includeRaiReason"]);void 0!==t&&null!=a&&tt(t,["parameters","includeRaiReason"],a);let u=tn(e,["language"]);void 0!==t&&null!=u&&tt(t,["parameters","language"],u);let p=tn(e,["outputMimeType"]);void 0!==t&&null!=p&&tt(t,["parameters","outputOptions","mimeType"],p);let d=tn(e,["outputCompressionQuality"]);if(void 0!==t&&null!=d&&tt(t,["parameters","outputOptions","compressionQuality"],d),void 0!==tn(e,["addWatermark"]))throw Error("addWatermark parameter is not supported in Gemini API.");if(void 0!==tn(e,["labels"]))throw Error("labels parameter is not supported in Gemini API.");let c=tn(e,["imageSize"]);if(void 0!==t&&null!=c&&tt(t,["parameters","sampleImageSize"],c),void 0!==tn(e,["enhancePrompt"]))throw Error("enhancePrompt parameter is not supported in Gemini API.")}(o,n),n}(this.apiClient,e);return o=te("{model}:predict",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["predictions"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["_self"]);null!=n&&tt(t,["image"],function(e){let t={},n=tn(e,["bytesBase64Encoded"]);null!=n&&tt(t,["imageBytes"],ti(n));let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}(n));let i=tn(e,["raiFilteredReason"]);null!=i&&tt(t,["raiFilteredReason"],i);let l=tn(e,["_self"]);return null!=l&&tt(t,["safetyAttributes"],nO(l)),t})(e))),tt(t,["generatedImages"],e)}let l=tn(e,["positivePromptSafetyAttributes"]);return null!=l&&tt(t,["positivePromptSafetyAttributes"],nO(l)),t}(e),n=new ta;return Object.assign(n,t),n})}}async editImageInternal(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI()){let o=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["prompt"]);null!=l&&tt(n,["instances[0]","prompt"],l);let o=tn(t,["referenceImages"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["referenceImage"]);null!=n&&tt(t,["referenceImage"],nA(n));let i=tn(e,["referenceId"]);null!=i&&tt(t,["referenceId"],i);let l=tn(e,["referenceType"]);null!=l&&tt(t,["referenceType"],l);let o=tn(e,["maskImageConfig"]);null!=o&&tt(t,["maskImageConfig"],function(e){let t={},n=tn(e,["maskMode"]);null!=n&&tt(t,["maskMode"],n);let i=tn(e,["segmentationClasses"]);null!=i&&tt(t,["maskClasses"],i);let l=tn(e,["maskDilation"]);return null!=l&&tt(t,["dilation"],l),t}(o));let r=tn(e,["controlImageConfig"]);null!=r&&tt(t,["controlImageConfig"],function(e){let t={},n=tn(e,["controlType"]);null!=n&&tt(t,["controlType"],n);let i=tn(e,["enableControlImageComputation"]);return null!=i&&tt(t,["computeControl"],i),t}(r));let s=tn(e,["styleImageConfig"]);null!=s&&tt(t,["styleImageConfig"],s);let a=tn(e,["subjectImageConfig"]);return null!=a&&tt(t,["subjectImageConfig"],a),t})(e))),tt(n,["instances[0]","referenceImages"],e)}let r=tn(t,["config"]);return null!=r&&function(e,t){let n=tn(e,["outputGcsUri"]);void 0!==t&&null!=n&&tt(t,["parameters","storageUri"],n);let i=tn(e,["negativePrompt"]);void 0!==t&&null!=i&&tt(t,["parameters","negativePrompt"],i);let l=tn(e,["numberOfImages"]);void 0!==t&&null!=l&&tt(t,["parameters","sampleCount"],l);let o=tn(e,["aspectRatio"]);void 0!==t&&null!=o&&tt(t,["parameters","aspectRatio"],o);let r=tn(e,["guidanceScale"]);void 0!==t&&null!=r&&tt(t,["parameters","guidanceScale"],r);let s=tn(e,["seed"]);void 0!==t&&null!=s&&tt(t,["parameters","seed"],s);let a=tn(e,["safetyFilterLevel"]);void 0!==t&&null!=a&&tt(t,["parameters","safetySetting"],a);let u=tn(e,["personGeneration"]);void 0!==t&&null!=u&&tt(t,["parameters","personGeneration"],u);let p=tn(e,["includeSafetyAttributes"]);void 0!==t&&null!=p&&tt(t,["parameters","includeSafetyAttributes"],p);let d=tn(e,["includeRaiReason"]);void 0!==t&&null!=d&&tt(t,["parameters","includeRaiReason"],d);let c=tn(e,["language"]);void 0!==t&&null!=c&&tt(t,["parameters","language"],c);let h=tn(e,["outputMimeType"]);void 0!==t&&null!=h&&tt(t,["parameters","outputOptions","mimeType"],h);let f=tn(e,["outputCompressionQuality"]);void 0!==t&&null!=f&&tt(t,["parameters","outputOptions","compressionQuality"],f);let m=tn(e,["addWatermark"]);void 0!==t&&null!=m&&tt(t,["parameters","addWatermark"],m);let g=tn(e,["labels"]);void 0!==t&&null!=g&&tt(t,["labels"],g);let y=tn(e,["editMode"]);void 0!==t&&null!=y&&tt(t,["parameters","editMode"],y);let E=tn(e,["baseSteps"]);void 0!==t&&null!=E&&tt(t,["parameters","editConfig","baseSteps"],E)}(r,n),n}(this.apiClient,e);return i=te("{model}:predict",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["predictions"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>n_(e))),tt(t,["generatedImages"],e)}return t}(e),n=new tu;return Object.assign(n,t),n})}throw Error("This method is only supported by the Vertex AI.")}async upscaleImageInternal(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI()){let o=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["image"]);null!=l&&tt(n,["instances[0]","image"],nA(l));let o=tn(t,["upscaleFactor"]);null!=o&&tt(n,["parameters","upscaleConfig","upscaleFactor"],o);let r=tn(t,["config"]);return null!=r&&function(e,t){let n=tn(e,["outputGcsUri"]);void 0!==t&&null!=n&&tt(t,["parameters","storageUri"],n);let i=tn(e,["safetyFilterLevel"]);void 0!==t&&null!=i&&tt(t,["parameters","safetySetting"],i);let l=tn(e,["personGeneration"]);void 0!==t&&null!=l&&tt(t,["parameters","personGeneration"],l);let o=tn(e,["includeRaiReason"]);void 0!==t&&null!=o&&tt(t,["parameters","includeRaiReason"],o);let r=tn(e,["outputMimeType"]);void 0!==t&&null!=r&&tt(t,["parameters","outputOptions","mimeType"],r);let s=tn(e,["outputCompressionQuality"]);void 0!==t&&null!=s&&tt(t,["parameters","outputOptions","compressionQuality"],s);let a=tn(e,["enhanceInputImage"]);void 0!==t&&null!=a&&tt(t,["parameters","upscaleConfig","enhanceInputImage"],a);let u=tn(e,["imagePreservationFactor"]);void 0!==t&&null!=u&&tt(t,["parameters","upscaleConfig","imagePreservationFactor"],u);let p=tn(e,["labels"]);void 0!==t&&null!=p&&tt(t,["labels"],p);let d=tn(e,["numberOfImages"]);void 0!==t&&null!=d&&tt(t,["parameters","sampleCount"],d);let c=tn(e,["mode"]);void 0!==t&&null!=c&&tt(t,["parameters","mode"],c)}(r,n),n}(this.apiClient,e);return i=te("{model}:predict",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["predictions"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>n_(e))),tt(t,["generatedImages"],e)}return t}(e),n=new tp;return Object.assign(n,t),n})}throw Error("This method is only supported by the Vertex AI.")}async recontextImage(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI()){let o=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["source"]);null!=l&&function(e,t){let n=tn(e,["prompt"]);void 0!==t&&null!=n&&tt(t,["instances[0]","prompt"],n);let i=tn(e,["personImage"]);void 0!==t&&null!=i&&tt(t,["instances[0]","personImage","image"],nA(i));let l=tn(e,["productImages"]);if(void 0!==t&&null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["productImage"]);return null!=n&&tt(t,["image"],nA(n)),t})(e))),tt(t,["instances[0]","productImages"],e)}}(l,n);let o=tn(t,["config"]);return null!=o&&function(e,t){let n=tn(e,["numberOfImages"]);void 0!==t&&null!=n&&tt(t,["parameters","sampleCount"],n);let i=tn(e,["baseSteps"]);void 0!==t&&null!=i&&tt(t,["parameters","baseSteps"],i);let l=tn(e,["outputGcsUri"]);void 0!==t&&null!=l&&tt(t,["parameters","storageUri"],l);let o=tn(e,["seed"]);void 0!==t&&null!=o&&tt(t,["parameters","seed"],o);let r=tn(e,["safetyFilterLevel"]);void 0!==t&&null!=r&&tt(t,["parameters","safetySetting"],r);let s=tn(e,["personGeneration"]);void 0!==t&&null!=s&&tt(t,["parameters","personGeneration"],s);let a=tn(e,["addWatermark"]);void 0!==t&&null!=a&&tt(t,["parameters","addWatermark"],a);let u=tn(e,["outputMimeType"]);void 0!==t&&null!=u&&tt(t,["parameters","outputOptions","mimeType"],u);let p=tn(e,["outputCompressionQuality"]);void 0!==t&&null!=p&&tt(t,["parameters","outputOptions","compressionQuality"],p);let d=tn(e,["enhancePrompt"]);void 0!==t&&null!=d&&tt(t,["parameters","enhancePrompt"],d);let c=tn(e,["labels"]);void 0!==t&&null!=c&&tt(t,["labels"],c)}(o,n),n}(this.apiClient,e);return i=te("{model}:predict",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>{let t=function(e){let t={},n=tn(e,["predictions"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>n_(e))),tt(t,["generatedImages"],e)}return t}(e),n=new td;return Object.assign(n,t),n})}throw Error("This method is only supported by the Vertex AI.")}async segmentImage(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI()){let o=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["source"]);null!=l&&function(e,t){let n=tn(e,["prompt"]);void 0!==t&&null!=n&&tt(t,["instances[0]","prompt"],n);let i=tn(e,["image"]);void 0!==t&&null!=i&&tt(t,["instances[0]","image"],nA(i));let l=tn(e,["scribbleImage"]);void 0!==t&&null!=l&&tt(t,["instances[0]","scribble"],function(e){let t={},n=tn(e,["image"]);return null!=n&&tt(t,["image"],nA(n)),t}(l))}(l,n);let o=tn(t,["config"]);return null!=o&&function(e,t){let n=tn(e,["mode"]);void 0!==t&&null!=n&&tt(t,["parameters","mode"],n);let i=tn(e,["maxPredictions"]);void 0!==t&&null!=i&&tt(t,["parameters","maxPredictions"],i);let l=tn(e,["confidenceThreshold"]);void 0!==t&&null!=l&&tt(t,["parameters","confidenceThreshold"],l);let o=tn(e,["maskDilation"]);void 0!==t&&null!=o&&tt(t,["parameters","maskDilation"],o);let r=tn(e,["binaryColorThreshold"]);void 0!==t&&null!=r&&tt(t,["parameters","binaryColorThreshold"],r);let s=tn(e,["labels"]);void 0!==t&&null!=s&&tt(t,["labels"],s)}(o,n),n}(this.apiClient,e);return i=te("{model}:predict",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>{let t=function(e){let t={},n=tn(e,["predictions"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["_self"]);null!=n&&tt(t,["mask"],nI(n));let i=tn(e,["labels"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["labels"],e)}return t})(e))),tt(t,["generatedMasks"],e)}return t}(e),n=new tc;return Object.assign(n,t),n})}throw Error("This method is only supported by the Vertex AI.")}async get(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["model"]);return null!=i&&tt(n,["_url","name"],tM(e,i)),n}(this.apiClient,e);return o=te("{name}",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>nS(e))}{let t=function(e,t){let n={},i=tn(t,["model"]);return null!=i&&tt(n,["_url","name"],tM(e,i)),n}(this.apiClient,e);return o=te("{name}",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json()).then(e=>nC(e))}}async listInternal(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["config"]);return null!=i&&function(e,t,n){let i=tn(t,["pageSize"]);void 0!==n&&null!=i&&tt(n,["_query","pageSize"],i);let l=tn(t,["pageToken"]);void 0!==n&&null!=l&&tt(n,["_query","pageToken"],l);let o=tn(t,["filter"]);void 0!==n&&null!=o&&tt(n,["_query","filter"],o);let r=tn(t,["queryBase"]);void 0!==n&&null!=r&&tt(n,["_url","models_url"],t0(e,r))}(e,i,n),n}(this.apiClient,e);return o=te("{models_url}",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["nextPageToken"]);null!=i&&tt(t,["nextPageToken"],i);let l=tn(e,["_self"]);if(null!=l){let e=t1(l);Array.isArray(e)&&(e=e.map(e=>nS(e))),tt(t,["models"],e)}return t}(e),n=new th;return Object.assign(n,t),n})}{let t=function(e,t){let n={},i=tn(t,["config"]);return null!=i&&function(e,t,n){let i=tn(t,["pageSize"]);void 0!==n&&null!=i&&tt(n,["_query","pageSize"],i);let l=tn(t,["pageToken"]);void 0!==n&&null!=l&&tt(n,["_query","pageToken"],l);let o=tn(t,["filter"]);void 0!==n&&null!=o&&tt(n,["_query","filter"],o);let r=tn(t,["queryBase"]);void 0!==n&&null!=r&&tt(n,["_url","models_url"],t0(e,r))}(e,i,n),n}(this.apiClient,e);return o=te("{models_url}",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["nextPageToken"]);null!=i&&tt(t,["nextPageToken"],i);let l=tn(e,["_self"]);if(null!=l){let e=t1(l);Array.isArray(e)&&(e=e.map(e=>nC(e))),tt(t,["models"],e)}return t}(e),n=new th;return Object.assign(n,t),n})}}async update(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["config"]);return null!=l&&function(e,t){let n=tn(e,["displayName"]);void 0!==t&&null!=n&&tt(t,["displayName"],n);let i=tn(e,["description"]);void 0!==t&&null!=i&&tt(t,["description"],i);let l=tn(e,["defaultCheckpointId"]);void 0!==t&&null!=l&&tt(t,["defaultCheckpointId"],l)}(l,n),n}(this.apiClient,e);return o=te("{model}",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"PATCH",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>nS(e))}{let t=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","name"],tM(e,i));let l=tn(t,["config"]);return null!=l&&function(e,t){let n=tn(e,["displayName"]);void 0!==t&&null!=n&&tt(t,["displayName"],n);let i=tn(e,["description"]);void 0!==t&&null!=i&&tt(t,["description"],i);let l=tn(e,["defaultCheckpointId"]);void 0!==t&&null!=l&&tt(t,["defaultCheckpointId"],l)}(l,n),n}(this.apiClient,e);return o=te("{name}",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"PATCH",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json()).then(e=>nC(e))}}async delete(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["model"]);return null!=i&&tt(n,["_url","name"],tM(e,i)),n}(this.apiClient,e);return o=te("{name}",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"DELETE",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);return null!=n&&tt(t,["sdkHttpResponse"],n),t}(e),n=new tf;return Object.assign(n,t),n})}{let t=function(e,t){let n={},i=tn(t,["model"]);return null!=i&&tt(n,["_url","name"],tM(e,i)),n}(this.apiClient,e);return o=te("{name}",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"DELETE",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);return null!=n&&tt(t,["sdkHttpResponse"],n),t}(e),n=new tf;return Object.assign(n,t),n})}}async countTokens(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["contents"]);if(null!=l){let e=tJ(l);Array.isArray(e)&&(e=e.map(e=>e)),tt(n,["contents"],e)}let o=tn(t,["config"]);return null!=o&&function(e,t){let n=tn(e,["systemInstruction"]);void 0!==t&&null!=n&&tt(t,["systemInstruction"],tj(n));let i=tn(e,["tools"]);if(void 0!==t&&null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>nR(e))),tt(t,["tools"],e)}let l=tn(e,["generationConfig"]);void 0!==t&&null!=l&&tt(t,["generationConfig"],function(e){let t={},n=tn(e,["modelSelectionConfig"]);null!=n&&tt(t,["modelConfig"],n);let i=tn(e,["responseJsonSchema"]);null!=i&&tt(t,["responseJsonSchema"],i);let l=tn(e,["audioTimestamp"]);null!=l&&tt(t,["audioTimestamp"],l);let o=tn(e,["candidateCount"]);null!=o&&tt(t,["candidateCount"],o);let r=tn(e,["enableAffectiveDialog"]);null!=r&&tt(t,["enableAffectiveDialog"],r);let s=tn(e,["frequencyPenalty"]);null!=s&&tt(t,["frequencyPenalty"],s);let a=tn(e,["logprobs"]);null!=a&&tt(t,["logprobs"],a);let u=tn(e,["maxOutputTokens"]);null!=u&&tt(t,["maxOutputTokens"],u);let p=tn(e,["mediaResolution"]);null!=p&&tt(t,["mediaResolution"],p);let d=tn(e,["presencePenalty"]);null!=d&&tt(t,["presencePenalty"],d);let c=tn(e,["responseLogprobs"]);null!=c&&tt(t,["responseLogprobs"],c);let h=tn(e,["responseMimeType"]);null!=h&&tt(t,["responseMimeType"],h);let f=tn(e,["responseModalities"]);null!=f&&tt(t,["responseModalities"],f);let m=tn(e,["responseSchema"]);null!=m&&tt(t,["responseSchema"],m);let g=tn(e,["routingConfig"]);null!=g&&tt(t,["routingConfig"],g);let y=tn(e,["seed"]);null!=y&&tt(t,["seed"],y);let E=tn(e,["speechConfig"]);null!=E&&tt(t,["speechConfig"],nN(E));let v=tn(e,["stopSequences"]);null!=v&&tt(t,["stopSequences"],v);let _=tn(e,["temperature"]);null!=_&&tt(t,["temperature"],_);let I=tn(e,["thinkingConfig"]);null!=I&&tt(t,["thinkingConfig"],I);let T=tn(e,["topK"]);null!=T&&tt(t,["topK"],T);let A=tn(e,["topP"]);if(null!=A&&tt(t,["topP"],A),void 0!==tn(e,["enableEnhancedCivicAnswers"]))throw Error("enableEnhancedCivicAnswers parameter is not supported in Vertex AI.");return t}(l))}(o,n),n}(this.apiClient,e);return o=te("{model}:countTokens",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["totalTokens"]);return null!=i&&tt(t,["totalTokens"],i),t}(e),n=new tm;return Object.assign(n,t),n})}{let t=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["contents"]);if(null!=l){let e=tJ(l);Array.isArray(e)&&(e=e.map(e=>nm(e))),tt(n,["contents"],e)}let o=tn(t,["config"]);return null!=o&&function(e){if(void 0!==tn(e,["systemInstruction"]))throw Error("systemInstruction parameter is not supported in Gemini API.");if(void 0!==tn(e,["tools"]))throw Error("tools parameter is not supported in Gemini API.");if(void 0!==tn(e,["generationConfig"]))throw Error("generationConfig parameter is not supported in Gemini API.")}(o),n}(this.apiClient,e);return o=te("{model}:countTokens",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["totalTokens"]);null!=i&&tt(t,["totalTokens"],i);let l=tn(e,["cachedContentTokenCount"]);return null!=l&&tt(t,["cachedContentTokenCount"],l),t}(e),n=new tm;return Object.assign(n,t),n})}}async computeTokens(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI()){let o=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["contents"]);if(null!=l){let e=tJ(l);Array.isArray(e)&&(e=e.map(e=>e)),tt(n,["contents"],e)}return n}(this.apiClient,e);return i=te("{model}:computeTokens",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["tokensInfo"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["tokensInfo"],e)}return t}(e),n=new tg;return Object.assign(n,t),n})}throw Error("This method is only supported by the Vertex AI.")}async generateVideosInternal(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["prompt"]);null!=l&&tt(n,["instances[0]","prompt"],l);let o=tn(t,["image"]);null!=o&&tt(n,["instances[0]","image"],nA(o));let r=tn(t,["video"]);null!=r&&tt(n,["instances[0]","video"],nD(r));let s=tn(t,["source"]);null!=s&&function(e,t){let n=tn(e,["prompt"]);void 0!==t&&null!=n&&tt(t,["instances[0]","prompt"],n);let i=tn(e,["image"]);void 0!==t&&null!=i&&tt(t,["instances[0]","image"],nA(i));let l=tn(e,["video"]);void 0!==t&&null!=l&&tt(t,["instances[0]","video"],nD(l))}(s,n);let a=tn(t,["config"]);return null!=a&&function(e,t){let n=tn(e,["numberOfVideos"]);void 0!==t&&null!=n&&tt(t,["parameters","sampleCount"],n);let i=tn(e,["outputGcsUri"]);void 0!==t&&null!=i&&tt(t,["parameters","storageUri"],i);let l=tn(e,["fps"]);void 0!==t&&null!=l&&tt(t,["parameters","fps"],l);let o=tn(e,["durationSeconds"]);void 0!==t&&null!=o&&tt(t,["parameters","durationSeconds"],o);let r=tn(e,["seed"]);void 0!==t&&null!=r&&tt(t,["parameters","seed"],r);let s=tn(e,["aspectRatio"]);void 0!==t&&null!=s&&tt(t,["parameters","aspectRatio"],s);let a=tn(e,["resolution"]);void 0!==t&&null!=a&&tt(t,["parameters","resolution"],a);let u=tn(e,["personGeneration"]);void 0!==t&&null!=u&&tt(t,["parameters","personGeneration"],u);let p=tn(e,["pubsubTopic"]);void 0!==t&&null!=p&&tt(t,["parameters","pubsubTopic"],p);let d=tn(e,["negativePrompt"]);void 0!==t&&null!=d&&tt(t,["parameters","negativePrompt"],d);let c=tn(e,["enhancePrompt"]);void 0!==t&&null!=c&&tt(t,["parameters","enhancePrompt"],c);let h=tn(e,["generateAudio"]);void 0!==t&&null!=h&&tt(t,["parameters","generateAudio"],h);let f=tn(e,["lastFrame"]);void 0!==t&&null!=f&&tt(t,["instances[0]","lastFrame"],nA(f));let m=tn(e,["referenceImages"]);if(void 0!==t&&null!=m){let e=m;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["image"]);null!=n&&tt(t,["image"],nA(n));let i=tn(e,["referenceType"]);return null!=i&&tt(t,["referenceType"],i),t})(e))),tt(t,["instances[0]","referenceImages"],e)}let g=tn(e,["mask"]);void 0!==t&&null!=g&&tt(t,["instances[0]","mask"],function(e){let t={},n=tn(e,["image"]);null!=n&&tt(t,["_self"],nA(n));let i=tn(e,["maskMode"]);return null!=i&&tt(t,["maskMode"],i),t}(g));let y=tn(e,["compressionQuality"]);void 0!==t&&null!=y&&tt(t,["parameters","compressionQuality"],y)}(a,n),n}(this.apiClient,e);return o=te("{model}:predictLongRunning",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>{let t=function(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["name"],n);let i=tn(e,["metadata"]);null!=i&&tt(t,["metadata"],i);let l=tn(e,["done"]);null!=l&&tt(t,["done"],l);let o=tn(e,["error"]);null!=o&&tt(t,["error"],o);let r=tn(e,["response"]);return null!=r&&tt(t,["response"],function(e){let t={},n=tn(e,["videos"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["_self"]);return null!=n&&tt(t,["video"],function(e){let t={},n=tn(e,["gcsUri"]);null!=n&&tt(t,["uri"],n);let i=tn(e,["bytesBase64Encoded"]);null!=i&&tt(t,["videoBytes"],ti(i));let l=tn(e,["mimeType"]);return null!=l&&tt(t,["mimeType"],l),t}(n)),t})(e))),tt(t,["generatedVideos"],e)}let i=tn(e,["raiMediaFilteredCount"]);null!=i&&tt(t,["raiMediaFilteredCount"],i);let l=tn(e,["raiMediaFilteredReasons"]);return null!=l&&tt(t,["raiMediaFilteredReasons"],l),t}(r)),t}(e),n=new ty;return Object.assign(n,t),n})}{let t=function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["_url","model"],tM(e,i));let l=tn(t,["prompt"]);null!=l&&tt(n,["instances[0]","prompt"],l);let o=tn(t,["image"]);null!=o&&tt(n,["instances[0]","image"],nT(o));let r=tn(t,["video"]);null!=r&&tt(n,["instances[0]","video"],nP(r));let s=tn(t,["source"]);null!=s&&function(e,t){let n=tn(e,["prompt"]);void 0!==t&&null!=n&&tt(t,["instances[0]","prompt"],n);let i=tn(e,["image"]);void 0!==t&&null!=i&&tt(t,["instances[0]","image"],nT(i));let l=tn(e,["video"]);void 0!==t&&null!=l&&tt(t,["instances[0]","video"],nP(l))}(s,n);let a=tn(t,["config"]);return null!=a&&function(e,t){let n=tn(e,["numberOfVideos"]);if(void 0!==t&&null!=n&&tt(t,["parameters","sampleCount"],n),void 0!==tn(e,["outputGcsUri"]))throw Error("outputGcsUri parameter is not supported in Gemini API.");if(void 0!==tn(e,["fps"]))throw Error("fps parameter is not supported in Gemini API.");let i=tn(e,["durationSeconds"]);if(void 0!==t&&null!=i&&tt(t,["parameters","durationSeconds"],i),void 0!==tn(e,["seed"]))throw Error("seed parameter is not supported in Gemini API.");let l=tn(e,["aspectRatio"]);void 0!==t&&null!=l&&tt(t,["parameters","aspectRatio"],l);let o=tn(e,["resolution"]);void 0!==t&&null!=o&&tt(t,["parameters","resolution"],o);let r=tn(e,["personGeneration"]);if(void 0!==t&&null!=r&&tt(t,["parameters","personGeneration"],r),void 0!==tn(e,["pubsubTopic"]))throw Error("pubsubTopic parameter is not supported in Gemini API.");let s=tn(e,["negativePrompt"]);void 0!==t&&null!=s&&tt(t,["parameters","negativePrompt"],s);let a=tn(e,["enhancePrompt"]);if(void 0!==t&&null!=a&&tt(t,["parameters","enhancePrompt"],a),void 0!==tn(e,["generateAudio"]))throw Error("generateAudio parameter is not supported in Gemini API.");let u=tn(e,["lastFrame"]);void 0!==t&&null!=u&&tt(t,["instances[0]","lastFrame"],nT(u));let p=tn(e,["referenceImages"]);if(void 0!==t&&null!=p){let e=p;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["image"]);null!=n&&tt(t,["image"],nT(n));let i=tn(e,["referenceType"]);return null!=i&&tt(t,["referenceType"],i),t})(e))),tt(t,["instances[0]","referenceImages"],e)}if(void 0!==tn(e,["mask"]))throw Error("mask parameter is not supported in Gemini API.");if(void 0!==tn(e,["compressionQuality"]))throw Error("compressionQuality parameter is not supported in Gemini API.")}(a,n),n}(this.apiClient,e);return o=te("{model}:predictLongRunning",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json()).then(e=>{let t=function(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["name"],n);let i=tn(e,["metadata"]);null!=i&&tt(t,["metadata"],i);let l=tn(e,["done"]);null!=l&&tt(t,["done"],l);let o=tn(e,["error"]);null!=o&&tt(t,["error"],o);let r=tn(e,["response","generateVideoResponse"]);return null!=r&&tt(t,["response"],function(e){let t={},n=tn(e,["generatedSamples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["video"]);return null!=n&&tt(t,["video"],function(e){let t={},n=tn(e,["uri"]);null!=n&&tt(t,["uri"],n);let i=tn(e,["encodedVideo"]);null!=i&&tt(t,["videoBytes"],ti(i));let l=tn(e,["encoding"]);return null!=l&&tt(t,["mimeType"],l),t}(n)),t})(e))),tt(t,["generatedVideos"],e)}let i=tn(e,["raiMediaFilteredCount"]);null!=i&&tt(t,["raiMediaFilteredCount"],i);let l=tn(e,["raiMediaFilteredReasons"]);return null!=l&&tt(t,["raiMediaFilteredReasons"],l),t}(r)),t}(e),n=new ty;return Object.assign(n,t),n})}}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class nX extends e7{constructor(e){super(),this.apiClient=e}async getVideosOperation(e){let t=e.operation,n=e.config;if(void 0===t.name||""===t.name)throw Error("Operation name is required.");if(this.apiClient.isVertexAI()){let e;let i=t.name.split("/operations/")[0];n&&"httpOptions"in n&&(e=n.httpOptions);let l=await this.fetchPredictVideosOperationInternal({operationName:t.name,resourceName:i,config:{httpOptions:e}});return t._fromAPIResponse({apiResponse:l,_isVertexAI:!0})}{let e=await this.getVideosOperationInternal({operationName:t.name,config:n});return t._fromAPIResponse({apiResponse:e,_isVertexAI:!1})}}async get(e){let t=e.operation,n=e.config;if(void 0===t.name||""===t.name)throw Error("Operation name is required.");if(this.apiClient.isVertexAI()){let e;let i=t.name.split("/operations/")[0];n&&"httpOptions"in n&&(e=n.httpOptions);let l=await this.fetchPredictVideosOperationInternal({operationName:t.name,resourceName:i,config:{httpOptions:e}});return t._fromAPIResponse({apiResponse:l,_isVertexAI:!0})}{let e=await this.getVideosOperationInternal({operationName:t.name,config:n});return t._fromAPIResponse({apiResponse:e,_isVertexAI:!1})}}async getVideosOperationInternal(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e){let t={},n=tn(e,["operationName"]);return null!=n&&tt(t,["_url","operationName"],n),t}(e);return o=te("{operationName}",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json())}{let t=function(e){let t={},n=tn(e,["operationName"]);return null!=n&&tt(t,["_url","operationName"],n),t}(e);return o=te("{operationName}",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json())}}async fetchPredictVideosOperationInternal(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI()){let o=/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function(e){let t={},n=tn(e,["operationName"]);null!=n&&tt(t,["operationName"],n);let i=tn(e,["resourceName"]);return null!=i&&tt(t,["_url","resourceName"],i),t}(e);return i=te("{resourceName}:fetchPredictOperation",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json())}throw Error("This method is only supported by the Vertex AI.")}}class nQ extends e7{constructor(e){super(),this.apiClient=e}async create(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("The client.tokens.create method is only supported by the Gemini Developer API.");{let o=function(e,t){let n={},i=tn(t,["config"]);return null!=i&&tt(n,["config"],function(e,t,n){let i=tn(t,["expireTime"]);void 0!==n&&null!=i&&tt(n,["expireTime"],i);let l=tn(t,["newSessionExpireTime"]);void 0!==n&&null!=l&&tt(n,["newSessionExpireTime"],l);let o=tn(t,["uses"]);void 0!==n&&null!=o&&tt(n,["uses"],o);let r=tn(t,["liveConnectConstraints"]);void 0!==n&&null!=r&&tt(n,["bidiGenerateContentSetup"],function(e,t){let n={},i=tn(t,["model"]);null!=i&&tt(n,["setup","model"],tM(e,i));let l=tn(t,["config"]);return null!=l&&tt(n,["config"],function(e,t){let n=tn(e,["generationConfig"]);void 0!==t&&null!=n&&tt(t,["setup","generationConfig"],n);let i=tn(e,["responseModalities"]);void 0!==t&&null!=i&&tt(t,["setup","generationConfig","responseModalities"],i);let l=tn(e,["temperature"]);void 0!==t&&null!=l&&tt(t,["setup","generationConfig","temperature"],l);let o=tn(e,["topP"]);void 0!==t&&null!=o&&tt(t,["setup","generationConfig","topP"],o);let r=tn(e,["topK"]);void 0!==t&&null!=r&&tt(t,["setup","generationConfig","topK"],r);let s=tn(e,["maxOutputTokens"]);void 0!==t&&null!=s&&tt(t,["setup","generationConfig","maxOutputTokens"],s);let a=tn(e,["mediaResolution"]);void 0!==t&&null!=a&&tt(t,["setup","generationConfig","mediaResolution"],a);let u=tn(e,["seed"]);void 0!==t&&null!=u&&tt(t,["setup","generationConfig","seed"],u);let p=tn(e,["speechConfig"]);void 0!==t&&null!=p&&tt(t,["setup","generationConfig","speechConfig"],tW(p));let d=tn(e,["thinkingConfig"]);void 0!==t&&null!=d&&tt(t,["setup","generationConfig","thinkingConfig"],d);let c=tn(e,["enableAffectiveDialog"]);void 0!==t&&null!=c&&tt(t,["setup","generationConfig","enableAffectiveDialog"],c);let h=tn(e,["systemInstruction"]);void 0!==t&&null!=h&&tt(t,["setup","systemInstruction"],function(e){let t={},n=tn(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["mediaResolution"]);null!=n&&tt(t,["mediaResolution"],n);let i=tn(e,["codeExecutionResult"]);null!=i&&tt(t,["codeExecutionResult"],i);let l=tn(e,["executableCode"]);null!=l&&tt(t,["executableCode"],l);let o=tn(e,["fileData"]);null!=o&&tt(t,["fileData"],function(e){let t={};if(void 0!==tn(e,["displayName"]))throw Error("displayName parameter is not supported in Gemini API.");let n=tn(e,["fileUri"]);null!=n&&tt(t,["fileUri"],n);let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}(o));let r=tn(e,["functionCall"]);null!=r&&tt(t,["functionCall"],function(e){let t={},n=tn(e,["id"]);null!=n&&tt(t,["id"],n);let i=tn(e,["args"]);null!=i&&tt(t,["args"],i);let l=tn(e,["name"]);if(null!=l&&tt(t,["name"],l),void 0!==tn(e,["partialArgs"]))throw Error("partialArgs parameter is not supported in Gemini API.");if(void 0!==tn(e,["willContinue"]))throw Error("willContinue parameter is not supported in Gemini API.");return t}(r));let s=tn(e,["functionResponse"]);null!=s&&tt(t,["functionResponse"],s);let a=tn(e,["inlineData"]);null!=a&&tt(t,["inlineData"],/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function(e){let t={},n=tn(e,["data"]);if(null!=n&&tt(t,["data"],n),void 0!==tn(e,["displayName"]))throw Error("displayName parameter is not supported in Gemini API.");let i=tn(e,["mimeType"]);return null!=i&&tt(t,["mimeType"],i),t}(a));let u=tn(e,["text"]);null!=u&&tt(t,["text"],u);let p=tn(e,["thought"]);null!=p&&tt(t,["thought"],p);let d=tn(e,["thoughtSignature"]);null!=d&&tt(t,["thoughtSignature"],d);let c=tn(e,["videoMetadata"]);return null!=c&&tt(t,["videoMetadata"],c),t})(e))),tt(t,["parts"],e)}let i=tn(e,["role"]);return null!=i&&tt(t,["role"],i),t}(tj(h)));let f=tn(e,["tools"]);if(void 0!==t&&null!=f){let e=tz(f);Array.isArray(e)&&(e=e.map(e=>(function(e){let t={},n=tn(e,["functionDeclarations"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["functionDeclarations"],e)}if(void 0!==tn(e,["retrieval"]))throw Error("retrieval parameter is not supported in Gemini API.");let i=tn(e,["googleSearchRetrieval"]);null!=i&&tt(t,["googleSearchRetrieval"],i);let l=tn(e,["computerUse"]);null!=l&&tt(t,["computerUse"],l);let o=tn(e,["fileSearch"]);null!=o&&tt(t,["fileSearch"],o);let r=tn(e,["codeExecution"]);if(null!=r&&tt(t,["codeExecution"],r),void 0!==tn(e,["enterpriseWebSearch"]))throw Error("enterpriseWebSearch parameter is not supported in Gemini API.");let s=tn(e,["googleMaps"]);null!=s&&tt(t,["googleMaps"],function(e){let t={};if(void 0!==tn(e,["authConfig"]))throw Error("authConfig parameter is not supported in Gemini API.");let n=tn(e,["enableWidget"]);return null!=n&&tt(t,["enableWidget"],n),t}(s));let a=tn(e,["googleSearch"]);null!=a&&tt(t,["googleSearch"],function(e){let t={};if(void 0!==tn(e,["excludeDomains"]))throw Error("excludeDomains parameter is not supported in Gemini API.");if(void 0!==tn(e,["blockingConfidence"]))throw Error("blockingConfidence parameter is not supported in Gemini API.");let n=tn(e,["timeRangeFilter"]);return null!=n&&tt(t,["timeRangeFilter"],n),t}(a));let u=tn(e,["urlContext"]);return null!=u&&tt(t,["urlContext"],u),t})(t$(e)))),tt(t,["setup","tools"],e)}let m=tn(e,["sessionResumption"]);void 0!==t&&null!=m&&tt(t,["setup","sessionResumption"],function(e){let t={},n=tn(e,["handle"]);if(null!=n&&tt(t,["handle"],n),void 0!==tn(e,["transparent"]))throw Error("transparent parameter is not supported in Gemini API.");return t}(m));let g=tn(e,["inputAudioTranscription"]);void 0!==t&&null!=g&&tt(t,["setup","inputAudioTranscription"],g);let y=tn(e,["outputAudioTranscription"]);void 0!==t&&null!=y&&tt(t,["setup","outputAudioTranscription"],y);let E=tn(e,["realtimeInputConfig"]);void 0!==t&&null!=E&&tt(t,["setup","realtimeInputConfig"],E);let v=tn(e,["contextWindowCompression"]);void 0!==t&&null!=v&&tt(t,["setup","contextWindowCompression"],v);let _=tn(e,["proactivity"]);return void 0!==t&&null!=_&&tt(t,["setup","proactivity"],_),{}}(l,n)),n}(e,r));let s=tn(t,["lockAdditionalFields"]);return void 0!==n&&null!=s&&tt(n,["fieldMask"],s),{}}(e,i,n)),n}(this.apiClient,e);i=te("auth_tokens",o._url),l=o._query,delete o.config,delete o._url,delete o._query;let r=function(e,t){let n=null,i=e.bidiGenerateContentSetup;if("object"==typeof i&&null!==i&&"setup"in i){let t=i.setup;"object"==typeof t&&null!==t?(e.bidiGenerateContentSetup=t,n=t):delete e.bidiGenerateContentSetup}else void 0!==i&&delete e.bidiGenerateContentSetup;let l=e.fieldMask;if(n){let i=/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function(e){let t=[];for(let n in e)if(Object.prototype.hasOwnProperty.call(e,n)){let i=e[n];if("object"==typeof i&&null!=i&&Object.keys(i).length>0){let e=Object.keys(i).map(e=>`${n}.${e}`);t.push(...e)}else t.push(n)}return t.join(",")}(n);if(Array.isArray(null==t?void 0:t.lockAdditionalFields)&&(null==t?void 0:t.lockAdditionalFields.length)===0)i?e.fieldMask=i:delete e.fieldMask;else if((null==t?void 0:t.lockAdditionalFields)&&t.lockAdditionalFields.length>0&&null!==l&&Array.isArray(l)&&l.length>0){let t=["temperature","topK","topP","maxOutputTokens","responseModalities","seed","speechConfig"],n=[];l.length>0&&(n=l.map(e=>t.includes(e)?`generationConfig.${e}`:e));let o=[];i&&o.push(i),n.length>0&&o.push(...n),o.length>0?e.fieldMask=o.join(","):delete e.fieldMask}else delete e.fieldMask}else null!==l&&Array.isArray(l)&&l.length>0?e.fieldMask=l.join(","):delete e.fieldMask;return e}(o,e.config);return this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(r),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>e)}}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class nZ extends e7{constructor(e){super(),this.apiClient=e,this.list=async e=>new ne(el.PAGED_ITEM_DOCUMENTS,t=>this.listInternal({parent:e.parent,config:t.config}),await this.listInternal(e),e)}async get(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["name"]);return null!=n&&tt(t,["_url","name"],n),t}(e);return i=te("{name}",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>e)}}async delete(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["_url","name"],n);let i=tn(e,["config"]);return null!=i&&/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function(e,t){let n=tn(e,["force"]);void 0!==t&&null!=n&&tt(t,["_query","force"],n)}(i,t),t}(e);i=te("{name}",o._url),l=o._query,delete o._url,delete o._query,await this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"DELETE",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal})}}async listInternal(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["parent"]);null!=n&&tt(t,["_url","parent"],n);let i=tn(e,["config"]);return null!=i&&function(e,t){let n=tn(e,["pageSize"]);void 0!==t&&null!=n&&tt(t,["_query","pageSize"],n);let i=tn(e,["pageToken"]);void 0!==t&&null!=i&&tt(t,["_query","pageToken"],i)}(i,t),t}(e);return i=te("{parent}/documents",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["nextPageToken"]);null!=i&&tt(t,["nextPageToken"],i);let l=tn(e,["documents"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["documents"],e)}return t}(e),n=new tI;return Object.assign(n,t),n})}}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class n0 extends e7{constructor(e,t=new nZ(e)){super(),this.apiClient=e,this.documents=t,this.list=async(e={})=>new ne(el.PAGED_ITEM_FILE_SEARCH_STORES,e=>this.listInternal(e),await this.listInternal(e),e)}async uploadToFileSearchStore(e){if(this.apiClient.isVertexAI())throw Error("Vertex AI does not support uploading files to a file search store.");return this.apiClient.uploadFileToFileSearchStore(e.fileSearchStoreName,e.file,e.config)}async create(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["config"]);return null!=n&&/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function(e,t){let n=tn(e,["displayName"]);void 0!==t&&null!=n&&tt(t,["displayName"],n)}(n,t),t}(e);return i=te("fileSearchStores",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>e)}}async get(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["name"]);return null!=n&&tt(t,["_url","name"],n),t}(e);return i=te("{name}",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>e)}}async delete(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["_url","name"],n);let i=tn(e,["config"]);return null!=i&&function(e,t){let n=tn(e,["force"]);void 0!==t&&null!=n&&tt(t,["_query","force"],n)}(i,t),t}(e);i=te("{name}",o._url),l=o._query,delete o._url,delete o._query,await this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"DELETE",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal})}}async listInternal(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["config"]);return null!=n&&function(e,t){let n=tn(e,["pageSize"]);void 0!==t&&null!=n&&tt(t,["_query","pageSize"],n);let i=tn(e,["pageToken"]);void 0!==t&&null!=i&&tt(t,["_query","pageToken"],i)}(n,t),t}(e);return i=te("fileSearchStores",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["nextPageToken"]);null!=i&&tt(t,["nextPageToken"],i);let l=tn(e,["fileSearchStores"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["fileSearchStores"],e)}return t}(e),n=new tT;return Object.assign(n,t),n})}}async uploadToFileSearchStoreInternal(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["fileSearchStoreName"]);null!=n&&tt(t,["_url","file_search_store_name"],n);let i=tn(e,["config"]);return null!=i&&function(e,t){let n=tn(e,["mimeType"]);void 0!==t&&null!=n&&tt(t,["mimeType"],n);let i=tn(e,["displayName"]);void 0!==t&&null!=i&&tt(t,["displayName"],i);let l=tn(e,["customMetadata"]);if(void 0!==t&&null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["customMetadata"],e)}let o=tn(e,["chunkingConfig"]);void 0!==t&&null!=o&&tt(t,["chunkingConfig"],o)}(i,t),t}(e);return i=te("upload/v1beta/{file_search_store_name}:uploadToFileSearchStore",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>{let t=function(e){let t={},n=tn(e,["sdkHttpResponse"]);return null!=n&&tt(t,["sdkHttpResponse"],n),t}(e),n=new tA;return Object.assign(n,t),n})}}async importFile(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e){let t={},n=tn(e,["fileSearchStoreName"]);null!=n&&tt(t,["_url","file_search_store_name"],n);let i=tn(e,["fileName"]);null!=i&&tt(t,["fileName"],i);let l=tn(e,["config"]);return null!=l&&function(e,t){let n=tn(e,["customMetadata"]);if(void 0!==t&&null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),tt(t,["customMetadata"],e)}let i=tn(e,["chunkingConfig"]);void 0!==t&&null!=i&&tt(t,["chunkingConfig"],i)}(l,t),t}(e);return i=te("{file_search_store_name}:importFile",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json()).then(e=>{let t=function(e){let t={},n=tn(e,["name"]);null!=n&&tt(t,["name"],n);let i=tn(e,["metadata"]);null!=i&&tt(t,["metadata"],i);let l=tn(e,["done"]);null!=l&&tt(t,["done"],l);let o=tn(e,["error"]);null!=o&&tt(t,["error"],o);let r=tn(e,["response"]);return null!=r&&tt(t,["response"],function(e){let t={},n=tn(e,["sdkHttpResponse"]);null!=n&&tt(t,["sdkHttpResponse"],n);let i=tn(e,["parent"]);null!=i&&tt(t,["parent"],i);let l=tn(e,["documentName"]);return null!=l&&tt(t,["documentName"],l),t}(r)),t}(e),n=new tC;return Object.assign(n,t),n})}}}function n1(e,t){let n={},i=tn(e,["sdkHttpResponse"]);null!=i&&tt(n,["sdkHttpResponse"],i);let l=tn(e,["name"]);null!=l&&tt(n,["name"],l);let o=tn(e,["state"]);null!=o&&tt(n,["state"],tQ(o));let r=tn(e,["createTime"]);null!=r&&tt(n,["createTime"],r);let s=tn(e,["tuningTask","startTime"]);null!=s&&tt(n,["startTime"],s);let a=tn(e,["tuningTask","completeTime"]);null!=a&&tt(n,["endTime"],a);let u=tn(e,["updateTime"]);null!=u&&tt(n,["updateTime"],u);let p=tn(e,["description"]);null!=p&&tt(n,["description"],p);let d=tn(e,["baseModel"]);null!=d&&tt(n,["baseModel"],d);let c=tn(e,["_self"]);return null!=c&&tt(n,["tunedModel"],function(e,t){let n={},i=tn(e,["name"]);null!=i&&tt(n,["model"],i);let l=tn(e,["name"]);return null!=l&&tt(n,["endpoint"],l),n}(c)),n}function n2(e,t){let n={},i=tn(e,["sdkHttpResponse"]);null!=i&&tt(n,["sdkHttpResponse"],i);let l=tn(e,["name"]);null!=l&&tt(n,["name"],l);let o=tn(e,["state"]);null!=o&&tt(n,["state"],tQ(o));let r=tn(e,["createTime"]);null!=r&&tt(n,["createTime"],r);let s=tn(e,["startTime"]);null!=s&&tt(n,["startTime"],s);let a=tn(e,["endTime"]);null!=a&&tt(n,["endTime"],a);let u=tn(e,["updateTime"]);null!=u&&tt(n,["updateTime"],u);let p=tn(e,["error"]);null!=p&&tt(n,["error"],p);let d=tn(e,["description"]);null!=d&&tt(n,["description"],d);let c=tn(e,["baseModel"]);null!=c&&tt(n,["baseModel"],c);let h=tn(e,["tunedModel"]);null!=h&&tt(n,["tunedModel"],h);let f=tn(e,["preTunedModel"]);null!=f&&tt(n,["preTunedModel"],f);let m=tn(e,["supervisedTuningSpec"]);null!=m&&tt(n,["supervisedTuningSpec"],m);let g=tn(e,["preferenceOptimizationSpec"]);null!=g&&tt(n,["preferenceOptimizationSpec"],g);let y=tn(e,["tuningDataStats"]);null!=y&&tt(n,["tuningDataStats"],y);let E=tn(e,["encryptionSpec"]);null!=E&&tt(n,["encryptionSpec"],E);let v=tn(e,["partnerModelTuningSpec"]);null!=v&&tt(n,["partnerModelTuningSpec"],v);let _=tn(e,["customBaseModel"]);null!=_&&tt(n,["customBaseModel"],_);let I=tn(e,["experiment"]);null!=I&&tt(n,["experiment"],I);let T=tn(e,["labels"]);null!=T&&tt(n,["labels"],T);let A=tn(e,["outputUri"]);null!=A&&tt(n,["outputUri"],A);let C=tn(e,["pipelineJob"]);null!=C&&tt(n,["pipelineJob"],C);let S=tn(e,["serviceAccount"]);null!=S&&tt(n,["serviceAccount"],S);let O=tn(e,["tunedModelDisplayName"]);null!=O&&tt(n,["tunedModelDisplayName"],O);let b=tn(e,["veoTuningSpec"]);return null!=b&&tt(n,["veoTuningSpec"],b),n}function n6(e,t){let n={},i=tn(e,["gcsUri"]);null!=i&&tt(n,["validationDatasetUri"],i);let l=tn(e,["vertexDatasetResource"]);return null!=l&&tt(n,["validationDatasetUri"],l),n}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class n4 extends e7{constructor(e){super(),this.apiClient=e,this.get=async e=>await this.getInternal(e),this.list=async(e={})=>new ne(el.PAGED_ITEM_TUNING_JOBS,e=>this.listInternal(e),await this.listInternal(e),e),this.tune=async e=>{var t;if(this.apiClient.isVertexAI()){if(e.baseModel.startsWith("projects/")){let n={tunedModelName:e.baseModel};(null===(t=e.config)||void 0===t?void 0:t.preTunedModelCheckpointId)&&(n.checkpointId=e.config.preTunedModelCheckpointId);let i=Object.assign(Object.assign({},e),{preTunedModel:n});return i.baseModel=void 0,await this.tuneInternal(i)}{let t=Object.assign({},e);return await this.tuneInternal(t)}}{let t=Object.assign({},e),n=await this.tuneMldevInternal(t),i="";return void 0!==n.metadata&&void 0!==n.metadata.tunedModel?i=n.metadata.tunedModel:void 0!==n.name&&n.name.includes("/operations/")&&(i=n.name.split("/operations/")[0]),{name:i,state:O.JOB_STATE_QUEUED}}}}async getInternal(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(e,["name"]);return null!=i&&tt(n,["_url","name"],i),n}(e);return o=te("{name}",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>n2(e))}{let t=function(e,t){let n={},i=tn(e,["name"]);return null!=i&&tt(n,["_url","name"],i),n}(e);return o=te("{name}",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>n1(e))}}async listInternal(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(e,["config"]);return null!=i&&function(e,t,n){let i=tn(e,["pageSize"]);void 0!==t&&null!=i&&tt(t,["_query","pageSize"],i);let l=tn(e,["pageToken"]);void 0!==t&&null!=l&&tt(t,["_query","pageToken"],l);let o=tn(e,["filter"]);void 0!==t&&null!=o&&tt(t,["_query","filter"],o)}(i,n),n}(e);return o=te("tuningJobs",i._url),r=i._query,delete i._url,delete i._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"GET",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e,t){let n={},i=tn(e,["sdkHttpResponse"]);null!=i&&tt(n,["sdkHttpResponse"],i);let l=tn(e,["nextPageToken"]);null!=l&&tt(n,["nextPageToken"],l);let o=tn(e,["tuningJobs"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>n2(e))),tt(n,["tuningJobs"],e)}return n}(e),n=new tE;return Object.assign(n,t),n})}{let t=function(e,t){let n={},i=tn(e,["config"]);return null!=i&&function(e,t,n){let i=tn(e,["pageSize"]);void 0!==t&&null!=i&&tt(t,["_query","pageSize"],i);let l=tn(e,["pageToken"]);void 0!==t&&null!=l&&tt(t,["_query","pageToken"],l);let o=tn(e,["filter"]);void 0!==t&&null!=o&&tt(t,["_query","filter"],o)}(i,n),n}(e);return o=te("tunedModels",t._url),r=t._query,delete t._url,delete t._query,this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>{let t=function(e,t){let n={},i=tn(e,["sdkHttpResponse"]);null!=i&&tt(n,["sdkHttpResponse"],i);let l=tn(e,["nextPageToken"]);null!=l&&tt(n,["nextPageToken"],l);let o=tn(e,["tunedModels"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>n1(e))),tt(n,["tuningJobs"],e)}return n}(e),n=new tE;return Object.assign(n,t),n})}}async cancel(e){var t,n,i,l;let o="",r={};if(this.apiClient.isVertexAI()){let i=function(e,t){let n={},i=tn(e,["name"]);return null!=i&&tt(n,["_url","name"],i),n}(e);o=te("{name}:cancel",i._url),r=i._query,delete i._url,delete i._query,await this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(i),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal})}else{let t=/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/function(e,t){let n={},i=tn(e,["name"]);return null!=i&&tt(n,["_url","name"],i),n}(e);o=te("{name}:cancel",t._url),r=t._query,delete t._url,delete t._query,await this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(i=e.config)||void 0===i?void 0:i.httpOptions,abortSignal:null===(l=e.config)||void 0===l?void 0:l.abortSignal})}}async tuneInternal(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI()){let o=function(e,t){let n={},i=tn(e,["baseModel"]);null!=i&&tt(n,["baseModel"],i);let l=tn(e,["preTunedModel"]);null!=l&&tt(n,["preTunedModel"],l);let o=tn(e,["trainingDataset"]);null!=o&&function(e,t,n){let i=tn(n,["config","method"]);if(void 0===i&&(i="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===i){let n=tn(e,["gcsUri"]);void 0!==t&&null!=n&&tt(t,["supervisedTuningSpec","trainingDatasetUri"],n)}else if("PREFERENCE_TUNING"===i){let n=tn(e,["gcsUri"]);void 0!==t&&null!=n&&tt(t,["preferenceOptimizationSpec","trainingDatasetUri"],n)}let l=tn(n,["config","method"]);if(void 0===l&&(l="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===l){let n=tn(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&tt(t,["supervisedTuningSpec","trainingDatasetUri"],n)}else if("PREFERENCE_TUNING"===l){let n=tn(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&tt(t,["preferenceOptimizationSpec","trainingDatasetUri"],n)}if(void 0!==tn(e,["examples"]))throw Error("examples parameter is not supported in Vertex AI.")}(o,n,t);let r=tn(e,["config"]);return null!=r&&function(e,t,n){let i=tn(n,["config","method"]);if(void 0===i&&(i="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===i){let n=tn(e,["validationDataset"]);void 0!==t&&null!=n&&tt(t,["supervisedTuningSpec"],n6(n))}else if("PREFERENCE_TUNING"===i){let n=tn(e,["validationDataset"]);void 0!==t&&null!=n&&tt(t,["preferenceOptimizationSpec"],n6(n))}let l=tn(e,["tunedModelDisplayName"]);void 0!==t&&null!=l&&tt(t,["tunedModelDisplayName"],l);let o=tn(e,["description"]);void 0!==t&&null!=o&&tt(t,["description"],o);let r=tn(n,["config","method"]);if(void 0===r&&(r="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===r){let n=tn(e,["epochCount"]);void 0!==t&&null!=n&&tt(t,["supervisedTuningSpec","hyperParameters","epochCount"],n)}else if("PREFERENCE_TUNING"===r){let n=tn(e,["epochCount"]);void 0!==t&&null!=n&&tt(t,["preferenceOptimizationSpec","hyperParameters","epochCount"],n)}let s=tn(n,["config","method"]);if(void 0===s&&(s="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===s){let n=tn(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&tt(t,["supervisedTuningSpec","hyperParameters","learningRateMultiplier"],n)}else if("PREFERENCE_TUNING"===s){let n=tn(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&tt(t,["preferenceOptimizationSpec","hyperParameters","learningRateMultiplier"],n)}let a=tn(n,["config","method"]);if(void 0===a&&(a="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===a){let n=tn(e,["exportLastCheckpointOnly"]);void 0!==t&&null!=n&&tt(t,["supervisedTuningSpec","exportLastCheckpointOnly"],n)}else if("PREFERENCE_TUNING"===a){let n=tn(e,["exportLastCheckpointOnly"]);void 0!==t&&null!=n&&tt(t,["preferenceOptimizationSpec","exportLastCheckpointOnly"],n)}let u=tn(n,["config","method"]);if(void 0===u&&(u="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===u){let n=tn(e,["adapterSize"]);void 0!==t&&null!=n&&tt(t,["supervisedTuningSpec","hyperParameters","adapterSize"],n)}else if("PREFERENCE_TUNING"===u){let n=tn(e,["adapterSize"]);void 0!==t&&null!=n&&tt(t,["preferenceOptimizationSpec","hyperParameters","adapterSize"],n)}if(void 0!==tn(e,["batchSize"]))throw Error("batchSize parameter is not supported in Vertex AI.");if(void 0!==tn(e,["learningRate"]))throw Error("learningRate parameter is not supported in Vertex AI.");let p=tn(e,["labels"]);void 0!==t&&null!=p&&tt(t,["labels"],p);let d=tn(e,["beta"]);void 0!==t&&null!=d&&tt(t,["preferenceOptimizationSpec","hyperParameters","beta"],d)}(r,n,t),n}(e,e);return i=te("tuningJobs",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>n2(e))}throw Error("This method is only supported by the Vertex AI.")}async tuneMldevInternal(e){var t,n;let i="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");{let o=function(e,t){let n={},i=tn(e,["baseModel"]);null!=i&&tt(n,["baseModel"],i);let l=tn(e,["preTunedModel"]);null!=l&&tt(n,["preTunedModel"],l);let o=tn(e,["trainingDataset"]);null!=o&&function(e,t){if(void 0!==tn(e,["gcsUri"]))throw Error("gcsUri parameter is not supported in Gemini API.");if(void 0!==tn(e,["vertexDatasetResource"]))throw Error("vertexDatasetResource parameter is not supported in Gemini API.");let n=tn(e,["examples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),tt({},["examples","examples"],e)}}(o);let r=tn(e,["config"]);return null!=r&&function(e,t,n){if(void 0!==tn(e,["validationDataset"]))throw Error("validationDataset parameter is not supported in Gemini API.");let i=tn(e,["tunedModelDisplayName"]);if(void 0!==t&&null!=i&&tt(t,["displayName"],i),void 0!==tn(e,["description"]))throw Error("description parameter is not supported in Gemini API.");let l=tn(e,["epochCount"]);void 0!==t&&null!=l&&tt(t,["tuningTask","hyperparameters","epochCount"],l);let o=tn(e,["learningRateMultiplier"]);if(null!=o&&tt({},["tuningTask","hyperparameters","learningRateMultiplier"],o),void 0!==tn(e,["exportLastCheckpointOnly"]))throw Error("exportLastCheckpointOnly parameter is not supported in Gemini API.");if(void 0!==tn(e,["preTunedModelCheckpointId"]))throw Error("preTunedModelCheckpointId parameter is not supported in Gemini API.");if(void 0!==tn(e,["adapterSize"]))throw Error("adapterSize parameter is not supported in Gemini API.");let r=tn(e,["batchSize"]);void 0!==t&&null!=r&&tt(t,["tuningTask","hyperparameters","batchSize"],r);let s=tn(e,["learningRate"]);if(void 0!==t&&null!=s&&tt(t,["tuningTask","hyperparameters","learningRate"],s),void 0!==tn(e,["labels"]))throw Error("labels parameter is not supported in Gemini API.");if(void 0!==tn(e,["beta"]))throw Error("beta parameter is not supported in Gemini API.")}(r,n),n}(e);return i=te("tunedModels",o._url),l=o._query,delete o._url,delete o._query,this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(o),httpMethod:"POST",httpOptions:null===(t=e.config)||void 0===t?void 0:t.httpOptions,abortSignal:null===(n=e.config)||void 0===n?void 0:n.abortSignal}).then(e=>e.json().then(t=>(t.sdkHttpResponse={headers:e.headers},t))).then(e=>(function(e,t){let n={},i=tn(e,["sdkHttpResponse"]);null!=i&&tt(n,["sdkHttpResponse"],i);let l=tn(e,["name"]);null!=l&&tt(n,["name"],l);let o=tn(e,["metadata"]);null!=o&&tt(n,["metadata"],o);let r=tn(e,["done"]);null!=r&&tt(n,["done"],r);let s=tn(e,["error"]);return null!=s&&tt(n,["error"],s),n})(e))}}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class n3{async download(e,t){throw Error("Download to file is not supported in the browser, please use a browser compliant download like an <a> tag.")}}let n8="x-goog-upload-status";async function n9(e,t,n){var i;let l=await n7(e,t,n),o=await (null==l?void 0:l.json());if((null===(i=null==l?void 0:l.headers)||void 0===i?void 0:i[n8])!=="final")throw Error("Failed to upload file: Upload status is not finalized.");return o.file}async function n5(e,t,n){var i;let l=await n7(e,t,n),o=await (null==l?void 0:l.json());if((null===(i=null==l?void 0:l.headers)||void 0===i?void 0:i[n8])!=="final")throw Error("Failed to upload file: Upload status is not finalized.");let r=tl(o),s=new tD;return Object.assign(s,r),s}async function n7(e,t,n){var i,l;let o=0,r=0,s=new to(new Response),a="upload";for(o=e.size;r<o;){let u=Math.min(8388608,o-r),p=e.slice(r,r+u);r+u>=o&&(a+=", finalize");let d=0,c=1e3;for(;d<3&&(null===(i=null==(s=await n.request({path:"",body:p,httpMethod:"POST",httpOptions:{apiVersion:"",baseUrl:t,headers:{"X-Goog-Upload-Command":a,"X-Goog-Upload-Offset":String(r),"Content-Length":String(u)}}}))?void 0:s.headers)||void 0===i||!i[n8]);)d++,await function(e){return new Promise(t=>setTimeout(t,e))}(c),c*=2;if(r+=u,(null===(l=null==s?void 0:s.headers)||void 0===l?void 0:l[n8])!=="active")break;if(o<=r)throw Error("All content has been uploaded, but the upload status is not finalized.")}return s}async function ie(e){return{size:e.size,type:e.type}}class it{async upload(e,t,n){if("string"==typeof e)throw Error("File path is not supported in browser uploader.");return await n9(e,t,n)}async uploadToFileSearchStore(e,t,n){if("string"==typeof e)throw Error("File path is not supported in browser uploader.");return await n5(e,t,n)}async stat(e){if("string"!=typeof e)return await ie(e);throw Error("File path is not supported in browser uploader.")}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/class ii{create(e,t,n){return new il(e,t,n)}}class il{constructor(e,t,n){this.url=e,this.headers=t,this.callbacks=n}connect(){this.ws=new WebSocket(this.url),this.ws.onopen=this.callbacks.onopen,this.ws.onerror=this.callbacks.onerror,this.ws.onclose=this.callbacks.onclose,this.ws.onmessage=this.callbacks.onmessage}send(e){if(void 0===this.ws)throw Error("WebSocket is not connected");this.ws.send(e)}close(){if(void 0===this.ws)throw Error("WebSocket is not connected");this.ws.close()}}/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/let io="x-goog-api-key";class ir{constructor(e){this.apiKey=e}async addAuthHeaders(e,t){if(null===e.get(io)){if(this.apiKey.startsWith("auth_tokens/"))throw Error("Ephemeral tokens are only supported by the live API.");if(!this.apiKey)throw Error("API key is missing. Please provide a valid API key.");e.append(io,this.apiKey)}}}class is{constructor(e){var t;if(null==e.apiKey)throw Error("An API Key must be set when running in a browser");if(e.project||e.location)throw Error("Vertex AI project based authentication is not supported on browser runtimes. Please do not provide a project or location.");this.vertexai=null!==(t=e.vertexai)&&void 0!==t&&t,this.apiKey=e.apiKey;let n=function(e,t,n,i){var l,o;if(!(null==e?void 0:e.baseUrl)){let e={geminiUrl:e9,vertexUrl:e5};return t?null!==(l=e.vertexUrl)&&void 0!==l?l:n:null!==(o=e.geminiUrl)&&void 0!==o?o:i}return e.baseUrl}(e.httpOptions,e.vertexai,void 0,void 0);n&&(e.httpOptions?e.httpOptions.baseUrl=n:e.httpOptions={baseUrl:n}),this.apiVersion=e.apiVersion;let i=new ir(this.apiKey);this.apiClient=new nw({auth:i,apiVersion:this.apiVersion,apiKey:this.apiKey,vertexai:this.vertexai,httpOptions:e.httpOptions,userAgentExtra:"gl-node/web",uploader:new it,downloader:new n3}),this.models=new nz(this.apiClient),this.live=new nj(this.apiClient,i,new ii),this.batches=new nt(this.apiClient),this.chats=new nu(this.models,this.apiClient),this.caches=new ni(this.apiClient),this.files=new nc(this.apiClient),this.operations=new nX(this.apiClient),this.authTokens=new nQ(this.apiClient),this.tunings=new n4(this.apiClient),this.fileSearchStores=new n0(this.apiClient)}}}}]);