@hintergrund/ui 0.3.19 → 0.3.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- void 0===globalThis.process&&(globalThis.process={env:{},platform:"browser",version:"",versions:{},browser:!0,nextTick:function(e){return Promise.resolve().then(e)}});import{a as e,t}from"./rolldown-runtime-9urLBz53.js";import{C as n,T as o,_ as i,b as r,f as s,h as l,m as a,p as u,x as c}from"./AssistantPane-DUkfeYBX.js";import{r as p,t as d}from"./provider-retry-DNH2SSUZ.js";import{f as m,h as f,i as h,m as g,n as v}from"./transform-messages-BgUpJrOy.js";import{n as _,t as E}from"./error-body-B13t5xBI.js";var y,A,I,T,C,S,O,b,P,w,R,N,D,G,k,M,x,U,L,q,H,F,j,B,V,X,J,Y,$,K,W,z,Z,Q,ee,te,ne,oe,ie,re,se,le,ae,ue,ce,pe,de,me,fe,he,ge,ve,_e,Ee,ye,Ae,Ie,Te,Ce,Se,Oe,be,Pe,we,Re,Ne,De,Ge,ke,Me,xe,Ue,Le,qe,He,Fe,je,Be,Ve=/* @__PURE__ */t((e,t)=>{function n(e,t){"boolean"==typeof t&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}t.exports=n,n.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},n.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},n.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=/* @__PURE__ */(new Date).getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(e),this._errors.unshift(/* @__PURE__ */new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var n=this._timeouts.shift();if(void 0===n){if(!this._cachedTimeouts)return!1;this._errors.splice(0,this._errors.length-1),n=this._cachedTimeouts.slice(-1)}var o=this;return this._timer=setTimeout(function(){o._attempts++,o._operationTimeoutCb&&(o._timeout=setTimeout(function(){o._operationTimeoutCb(o._attempts)},o._operationTimeout),o._options.unref&&o._timeout.unref()),o._fn(o._attempts)},n),this._options.unref&&this._timer.unref(),!0},n.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){n._operationTimeoutCb()},n._operationTimeout)),this._operationStart=/* @__PURE__ */(new Date).getTime(),this._fn(this._attempts)},n.prototype.try=function(e){this.attempt(e)},n.prototype.start=function(e){this.attempt(e)},n.prototype.start=n.prototype.try,n.prototype.errors=function(){return this._errors},n.prototype.attempts=function(){return this._attempts},n.prototype.mainError=function(){if(0===this._errors.length)return null;for(var e={},t=null,n=0,o=0;o<this._errors.length;o++){var i=this._errors[o],r=i.message,s=(e[r]||0)+1;e[r]=s,s>=n&&(t=i,n=s)}return t}}),Xe=/* @__PURE__ */t(e=>{var t=Ve();e.operation=function(n){return new t(e.timeouts(n),{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},e.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var o=[],i=0;i<t.retries;i++)o.push(this.createTimeout(i,t));return e&&e.forever&&!o.length&&o.push(this.createTimeout(i,t)),o.sort(function(e,t){return e-t}),o},e.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,o=Math.round(n*Math.max(t.minTimeout,1)*Math.pow(t.factor,e));return Math.min(o,t.maxTimeout)},e.wrap=function(t,n,o){if(n instanceof Array&&(o=n,n=null),!o)for(var i in o=[],t)"function"==typeof t[i]&&o.push(i);for(var r=0;r<o.length;r++){var s=o[r],l=t[s];t[s]=function(o){var i=e.operation(n),r=Array.prototype.slice.call(arguments,1),s=r.pop();r.push(function(e){i.retry(e)||(e&&(arguments[0]=i.mainError()),s.apply(this,arguments))}),i.attempt(function(){o.apply(t,r)})}.bind(t,l),t[s].options=n}}}),Je=/* @__PURE__ */t((e,t)=>{t.exports=Xe()}),Ye=/* @__PURE__ */t((e,t)=>{var n=Je(),o=["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"],i=class extends Error{constructor(e){super(),e instanceof Error?(this.originalError=e,({message:e}=e)):(this.originalError=new Error(e),this.originalError.stack=this.stack),this.name="AbortError",this.message=e}},r=(e,t)=>new Promise((r,s)=>{t={onFailedAttempt:()=>{},retries:10,...t};const l=n.operation(t);l.attempt(async n=>{try{r(await e(n))}catch(u){if(!(u instanceof Error))return void s(/* @__PURE__ */new TypeError(`Non-error was thrown: "${u}". You should only throw errors.`));if(u instanceof i)l.stop(),s(u.originalError);else if(u instanceof TypeError&&(a=u.message,!o.includes(a)))l.stop(),s(u);else{((e,t,n)=>{const o=n.retries-(t-1);e.attemptNumber=t,e.retriesLeft=o})(u,n,t);try{await t.onFailedAttempt(u)}catch(u){return void s(u)}l.retry(u)||s(l.mainError())}}var a})});t.exports=r,t.exports.default=r,t.exports.AbortError=i}),$e=/* @__PURE__ */e(Ye(),1),Ke=class{};function We(e,t){return e.replace(/\{([^}]+)\}/g,(e,n)=>{if(Object.prototype.hasOwnProperty.call(t,n)){const e=t[n];return null!=e?String(e):""}throw new Error(`Key '${n}' not found in valueMap.`)})}function ze(e,t,n){for(let r=0;r<t.length-1;r++){const o=t[r];if(o.endsWith("[]")){const i=o.slice(0,-2);if(!(i in e)){if(!Array.isArray(n))throw new Error(`Value must be a list given an array path ${o}`);e[i]=Array.from({length:n.length},()=>({}))}if(Array.isArray(e[i])){const o=e[i];if(Array.isArray(n))for(let e=0;e<o.length;e++)ze(o[e],t.slice(r+1),n[e]);else for(const e of o)ze(e,t.slice(r+1),n)}return}if(o.endsWith("[0]")){const i=o.slice(0,-3);return i in e||(e[i]=[{}]),void ze(e[i][0],t.slice(r+1),n)}e[o]&&"object"==typeof e[o]||(e[o]={}),e=e[o]}const o=t[t.length-1],i=e[o];if(void 0!==i){if(!n||"object"==typeof n&&0===Object.keys(n).length)return;if(n===i)return;if("object"!=typeof i||"object"!=typeof n||null===i||null===n)throw new Error(`Cannot set value for an existing key. Key: ${o}`);Object.assign(i,n)}else"_self"!==o||"object"!=typeof n||null===n||Array.isArray(n)?e[o]=n:Object.assign(e,n)}function Ze(e,t,n=void 0){try{if(1===t.length&&"_self"===t[0])return e;for(let o=0;o<t.length;o++){if("object"!=typeof e||null===e)return n;const i=t[o];if(i.endsWith("[]")){const r=i.slice(0,-2);if(r in e){const i=e[r];return Array.isArray(i)?i.map(e=>Ze(e,t.slice(o+1),n)):n}return n}e=e[i]}return e}catch(o){if(o instanceof TypeError)return n;throw o}}function Qe(e,t,n,o,i){if(o>=t.length)return;if("object"!=typeof e||null===e)return;const r=t[o];if(r.endsWith("[]")){const s=r.slice(0,-2),l=e;if(s in l&&Array.isArray(l[s]))for(const e of l[s])Qe(e,t,n,o+1,i)}else if("*"===r){if("object"==typeof e&&null!==e&&!Array.isArray(e)){const t=e,r=Object.keys(t).filter(e=>!e.startsWith("_")&&!i.has(e)),s={};for(const e of r)s[e]=t[e];for(const[e,i]of Object.entries(s)){const r=[];for(const t of n.slice(o))"*"===t?r.push(e):r.push(t);ze(t,r,i)}for(const e of r)delete t[e]}}else r in e&&Qe(e[r],t,n,o+1,i)}function et(e){if("string"!=typeof e)throw new Error("fromImageBytes must be a string");return e}function tt(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["parent"]);null!=o&&ze(t,["parent"],o);const i=Ze(e,["documentName"]);return null!=i&&ze(t,["documentName"],i),t}(s)),t}!function(e){e.OUTCOME_UNSPECIFIED="OUTCOME_UNSPECIFIED",e.OUTCOME_OK="OUTCOME_OK",e.OUTCOME_FAILED="OUTCOME_FAILED",e.OUTCOME_DEADLINE_EXCEEDED="OUTCOME_DEADLINE_EXCEEDED"}(y||(y={})),function(e){e.LANGUAGE_UNSPECIFIED="LANGUAGE_UNSPECIFIED",e.PYTHON="PYTHON"}(A||(A={})),function(e){e.SCHEDULING_UNSPECIFIED="SCHEDULING_UNSPECIFIED",e.SILENT="SILENT",e.WHEN_IDLE="WHEN_IDLE",e.INTERRUPT="INTERRUPT"}(I||(I={})),function(e){e.TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",e.STRING="STRING",e.NUMBER="NUMBER",e.INTEGER="INTEGER",e.BOOLEAN="BOOLEAN",e.ARRAY="ARRAY",e.OBJECT="OBJECT",e.NULL="NULL"}(T||(T={})),function(e){e.AUTH_TYPE_UNSPECIFIED="AUTH_TYPE_UNSPECIFIED",e.NO_AUTH="NO_AUTH",e.API_KEY_AUTH="API_KEY_AUTH",e.HTTP_BASIC_AUTH="HTTP_BASIC_AUTH",e.GOOGLE_SERVICE_ACCOUNT_AUTH="GOOGLE_SERVICE_ACCOUNT_AUTH",e.OAUTH="OAUTH",e.OIDC_AUTH="OIDC_AUTH"}(C||(C={})),function(e){e.HTTP_IN_UNSPECIFIED="HTTP_IN_UNSPECIFIED",e.HTTP_IN_QUERY="HTTP_IN_QUERY",e.HTTP_IN_HEADER="HTTP_IN_HEADER",e.HTTP_IN_PATH="HTTP_IN_PATH",e.HTTP_IN_BODY="HTTP_IN_BODY",e.HTTP_IN_COOKIE="HTTP_IN_COOKIE"}(S||(S={})),function(e){e.API_SPEC_UNSPECIFIED="API_SPEC_UNSPECIFIED",e.SIMPLE_SEARCH="SIMPLE_SEARCH",e.ELASTIC_SEARCH="ELASTIC_SEARCH"}(O||(O={})),function(e){e.ENVIRONMENT_UNSPECIFIED="ENVIRONMENT_UNSPECIFIED",e.ENVIRONMENT_BROWSER="ENVIRONMENT_BROWSER",e.ENVIRONMENT_MOBILE="ENVIRONMENT_MOBILE",e.ENVIRONMENT_DESKTOP="ENVIRONMENT_DESKTOP"}(b||(b={})),function(e){e.SAFETY_POLICY_UNSPECIFIED="SAFETY_POLICY_UNSPECIFIED",e.FINANCIAL_TRANSACTIONS="FINANCIAL_TRANSACTIONS",e.SENSITIVE_DATA_MODIFICATION="SENSITIVE_DATA_MODIFICATION",e.COMMUNICATION_TOOL="COMMUNICATION_TOOL",e.ACCOUNT_CREATION="ACCOUNT_CREATION",e.DATA_MODIFICATION="DATA_MODIFICATION",e.USER_CONSENT_MANAGEMENT="USER_CONSENT_MANAGEMENT",e.LEGAL_TERMS_AND_AGREEMENTS="LEGAL_TERMS_AND_AGREEMENTS"}(P||(P={})),function(e){e.PHISH_BLOCK_THRESHOLD_UNSPECIFIED="PHISH_BLOCK_THRESHOLD_UNSPECIFIED",e.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",e.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",e.BLOCK_HIGH_AND_ABOVE="BLOCK_HIGH_AND_ABOVE",e.BLOCK_HIGHER_AND_ABOVE="BLOCK_HIGHER_AND_ABOVE",e.BLOCK_VERY_HIGH_AND_ABOVE="BLOCK_VERY_HIGH_AND_ABOVE",e.BLOCK_ONLY_EXTREMELY_HIGH="BLOCK_ONLY_EXTREMELY_HIGH"}(w||(w={})),function(e){e.UNSPECIFIED="UNSPECIFIED",e.BLOCKING="BLOCKING",e.NON_BLOCKING="NON_BLOCKING"}(R||(R={})),function(e){e.MODE_UNSPECIFIED="MODE_UNSPECIFIED",e.MODE_DYNAMIC="MODE_DYNAMIC"}(N||(N={})),function(e){e.THINKING_LEVEL_UNSPECIFIED="THINKING_LEVEL_UNSPECIFIED",e.MINIMAL="MINIMAL",e.LOW="LOW",e.MEDIUM="MEDIUM",e.HIGH="HIGH"}(D||(D={})),function(e){e.DONT_ALLOW="DONT_ALLOW",e.ALLOW_ADULT="ALLOW_ADULT",e.ALLOW_ALL="ALLOW_ALL"}(G||(G={})),function(e){e.PROMINENT_PEOPLE_UNSPECIFIED="PROMINENT_PEOPLE_UNSPECIFIED",e.ALLOW_PROMINENT_PEOPLE="ALLOW_PROMINENT_PEOPLE",e.BLOCK_PROMINENT_PEOPLE="BLOCK_PROMINENT_PEOPLE"}(k||(k={})),function(e){e.HARM_CATEGORY_UNSPECIFIED="HARM_CATEGORY_UNSPECIFIED",e.HARM_CATEGORY_HARASSMENT="HARM_CATEGORY_HARASSMENT",e.HARM_CATEGORY_HATE_SPEECH="HARM_CATEGORY_HATE_SPEECH",e.HARM_CATEGORY_SEXUALLY_EXPLICIT="HARM_CATEGORY_SEXUALLY_EXPLICIT",e.HARM_CATEGORY_DANGEROUS_CONTENT="HARM_CATEGORY_DANGEROUS_CONTENT",e.HARM_CATEGORY_CIVIC_INTEGRITY="HARM_CATEGORY_CIVIC_INTEGRITY",e.HARM_CATEGORY_JAILBREAK="HARM_CATEGORY_JAILBREAK",e.HARM_CATEGORY_IMAGE_HATE="HARM_CATEGORY_IMAGE_HATE",e.HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT="HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT",e.HARM_CATEGORY_IMAGE_HARASSMENT="HARM_CATEGORY_IMAGE_HARASSMENT",e.HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT="HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT"}(M||(M={})),function(e){e.HARM_BLOCK_METHOD_UNSPECIFIED="HARM_BLOCK_METHOD_UNSPECIFIED",e.SEVERITY="SEVERITY",e.PROBABILITY="PROBABILITY"}(x||(x={})),function(e){e.HARM_BLOCK_THRESHOLD_UNSPECIFIED="HARM_BLOCK_THRESHOLD_UNSPECIFIED",e.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",e.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",e.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",e.BLOCK_NONE="BLOCK_NONE",e.OFF="OFF"}(U||(U={})),function(e){e.MODE_UNSPECIFIED="MODE_UNSPECIFIED",e.AUTO="AUTO",e.ANY="ANY",e.NONE="NONE",e.VALIDATED="VALIDATED"}(L||(L={})),function(e){e.FINISH_REASON_UNSPECIFIED="FINISH_REASON_UNSPECIFIED",e.STOP="STOP",e.MAX_TOKENS="MAX_TOKENS",e.SAFETY="SAFETY",e.RECITATION="RECITATION",e.LANGUAGE="LANGUAGE",e.OTHER="OTHER",e.BLOCKLIST="BLOCKLIST",e.PROHIBITED_CONTENT="PROHIBITED_CONTENT",e.SPII="SPII",e.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",e.IMAGE_SAFETY="IMAGE_SAFETY",e.UNEXPECTED_TOOL_CALL="UNEXPECTED_TOOL_CALL",e.TOO_MANY_TOOL_CALLS="TOO_MANY_TOOL_CALLS",e.IMAGE_PROHIBITED_CONTENT="IMAGE_PROHIBITED_CONTENT",e.NO_IMAGE="NO_IMAGE",e.IMAGE_RECITATION="IMAGE_RECITATION",e.IMAGE_OTHER="IMAGE_OTHER"}(q||(q={})),function(e){e.HARM_PROBABILITY_UNSPECIFIED="HARM_PROBABILITY_UNSPECIFIED",e.NEGLIGIBLE="NEGLIGIBLE",e.LOW="LOW",e.MEDIUM="MEDIUM",e.HIGH="HIGH"}(H||(H={})),function(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"}(F||(F={})),function(e){e.URL_RETRIEVAL_STATUS_UNSPECIFIED="URL_RETRIEVAL_STATUS_UNSPECIFIED",e.URL_RETRIEVAL_STATUS_SUCCESS="URL_RETRIEVAL_STATUS_SUCCESS",e.URL_RETRIEVAL_STATUS_ERROR="URL_RETRIEVAL_STATUS_ERROR",e.URL_RETRIEVAL_STATUS_PAYWALL="URL_RETRIEVAL_STATUS_PAYWALL",e.URL_RETRIEVAL_STATUS_UNSAFE="URL_RETRIEVAL_STATUS_UNSAFE"}(j||(j={})),function(e){e.BLOCKED_REASON_UNSPECIFIED="BLOCKED_REASON_UNSPECIFIED",e.SAFETY="SAFETY",e.OTHER="OTHER",e.BLOCKLIST="BLOCKLIST",e.PROHIBITED_CONTENT="PROHIBITED_CONTENT",e.IMAGE_SAFETY="IMAGE_SAFETY",e.MODEL_ARMOR="MODEL_ARMOR",e.JAILBREAK="JAILBREAK"}(B||(B={})),function(e){e.TRAFFIC_TYPE_UNSPECIFIED="TRAFFIC_TYPE_UNSPECIFIED",e.ON_DEMAND="ON_DEMAND",e.ON_DEMAND_PRIORITY="ON_DEMAND_PRIORITY",e.ON_DEMAND_FLEX="ON_DEMAND_FLEX",e.PROVISIONED_THROUGHPUT="PROVISIONED_THROUGHPUT"}(V||(V={})),function(e){e.MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",e.TEXT="TEXT",e.IMAGE="IMAGE",e.VIDEO="VIDEO",e.AUDIO="AUDIO",e.DOCUMENT="DOCUMENT"}(X||(X={})),function(e){e.MODEL_STAGE_UNSPECIFIED="MODEL_STAGE_UNSPECIFIED",e.UNSTABLE_EXPERIMENTAL="UNSTABLE_EXPERIMENTAL",e.EXPERIMENTAL="EXPERIMENTAL",e.PREVIEW="PREVIEW",e.STABLE="STABLE",e.LEGACY="LEGACY",e.DEPRECATED="DEPRECATED",e.RETIRED="RETIRED"}(J||(J={})),function(e){e.MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",e.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",e.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",e.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH"}(Y||(Y={})),function(e){e.MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",e.TEXT="TEXT",e.IMAGE="IMAGE",e.AUDIO="AUDIO",e.VIDEO="VIDEO"}($||($={})),function(e){e.DELIVERY_UNSPECIFIED="DELIVERY_UNSPECIFIED",e.INLINE="INLINE",e.URI="URI"}(K||(K={})),function(e){e.ASPECT_RATIO_UNSPECIFIED="ASPECT_RATIO_UNSPECIFIED",e.ASPECT_RATIO_ONE_BY_ONE="ASPECT_RATIO_ONE_BY_ONE",e.ASPECT_RATIO_TWO_BY_THREE="ASPECT_RATIO_TWO_BY_THREE",e.ASPECT_RATIO_THREE_BY_TWO="ASPECT_RATIO_THREE_BY_TWO",e.ASPECT_RATIO_THREE_BY_FOUR="ASPECT_RATIO_THREE_BY_FOUR",e.ASPECT_RATIO_FOUR_BY_THREE="ASPECT_RATIO_FOUR_BY_THREE",e.ASPECT_RATIO_FOUR_BY_FIVE="ASPECT_RATIO_FOUR_BY_FIVE",e.ASPECT_RATIO_FIVE_BY_FOUR="ASPECT_RATIO_FIVE_BY_FOUR",e.ASPECT_RATIO_NINE_BY_SIXTEEN="ASPECT_RATIO_NINE_BY_SIXTEEN",e.ASPECT_RATIO_SIXTEEN_BY_NINE="ASPECT_RATIO_SIXTEEN_BY_NINE",e.ASPECT_RATIO_TWENTY_ONE_BY_NINE="ASPECT_RATIO_TWENTY_ONE_BY_NINE",e.ASPECT_RATIO_ONE_BY_EIGHT="ASPECT_RATIO_ONE_BY_EIGHT",e.ASPECT_RATIO_EIGHT_BY_ONE="ASPECT_RATIO_EIGHT_BY_ONE",e.ASPECT_RATIO_ONE_BY_FOUR="ASPECT_RATIO_ONE_BY_FOUR",e.ASPECT_RATIO_FOUR_BY_ONE="ASPECT_RATIO_FOUR_BY_ONE"}(W||(W={})),function(e){e.IMAGE_SIZE_UNSPECIFIED="IMAGE_SIZE_UNSPECIFIED",e.IMAGE_SIZE_FIVE_TWELVE="IMAGE_SIZE_FIVE_TWELVE",e.IMAGE_SIZE_ONE_K="IMAGE_SIZE_ONE_K",e.IMAGE_SIZE_TWO_K="IMAGE_SIZE_TWO_K",e.IMAGE_SIZE_FOUR_K="IMAGE_SIZE_FOUR_K"}(z||(z={})),function(e){e.TUNING_MODE_UNSPECIFIED="TUNING_MODE_UNSPECIFIED",e.TUNING_MODE_FULL="TUNING_MODE_FULL",e.TUNING_MODE_PEFT_ADAPTER="TUNING_MODE_PEFT_ADAPTER"}(Z||(Z={})),function(e){e.ADAPTER_SIZE_UNSPECIFIED="ADAPTER_SIZE_UNSPECIFIED",e.ADAPTER_SIZE_ONE="ADAPTER_SIZE_ONE",e.ADAPTER_SIZE_TWO="ADAPTER_SIZE_TWO",e.ADAPTER_SIZE_FOUR="ADAPTER_SIZE_FOUR",e.ADAPTER_SIZE_EIGHT="ADAPTER_SIZE_EIGHT",e.ADAPTER_SIZE_SIXTEEN="ADAPTER_SIZE_SIXTEEN",e.ADAPTER_SIZE_THIRTY_TWO="ADAPTER_SIZE_THIRTY_TWO"}(Q||(Q={})),function(e){e.RESPONSE_PARSE_TYPE_UNSPECIFIED="RESPONSE_PARSE_TYPE_UNSPECIFIED",e.IDENTITY="IDENTITY",e.REGEX_EXTRACT="REGEX_EXTRACT"}(ee||(ee={})),function(e){e.MATCH_OPERATION_UNSPECIFIED="MATCH_OPERATION_UNSPECIFIED",e.REGEX_CONTAINS="REGEX_CONTAINS",e.PARTIAL_MATCH="PARTIAL_MATCH",e.EXACT_MATCH="EXACT_MATCH"}(te||(te={})),function(e){e.REINFORCEMENT_TUNING_THINKING_LEVEL_UNSPECIFIED="REINFORCEMENT_TUNING_THINKING_LEVEL_UNSPECIFIED",e.MINIMAL="MINIMAL",e.HIGH="HIGH"}(ne||(ne={})),function(e){e.JOB_STATE_UNSPECIFIED="JOB_STATE_UNSPECIFIED",e.JOB_STATE_QUEUED="JOB_STATE_QUEUED",e.JOB_STATE_PENDING="JOB_STATE_PENDING",e.JOB_STATE_RUNNING="JOB_STATE_RUNNING",e.JOB_STATE_SUCCEEDED="JOB_STATE_SUCCEEDED",e.JOB_STATE_FAILED="JOB_STATE_FAILED",e.JOB_STATE_CANCELLING="JOB_STATE_CANCELLING",e.JOB_STATE_CANCELLED="JOB_STATE_CANCELLED",e.JOB_STATE_PAUSED="JOB_STATE_PAUSED",e.JOB_STATE_EXPIRED="JOB_STATE_EXPIRED",e.JOB_STATE_UPDATING="JOB_STATE_UPDATING",e.JOB_STATE_PARTIALLY_SUCCEEDED="JOB_STATE_PARTIALLY_SUCCEEDED"}(oe||(oe={})),function(e){e.TUNING_JOB_STATE_UNSPECIFIED="TUNING_JOB_STATE_UNSPECIFIED",e.TUNING_JOB_STATE_WAITING_FOR_QUOTA="TUNING_JOB_STATE_WAITING_FOR_QUOTA",e.TUNING_JOB_STATE_PROCESSING_DATASET="TUNING_JOB_STATE_PROCESSING_DATASET",e.TUNING_JOB_STATE_WAITING_FOR_CAPACITY="TUNING_JOB_STATE_WAITING_FOR_CAPACITY",e.TUNING_JOB_STATE_TUNING="TUNING_JOB_STATE_TUNING",e.TUNING_JOB_STATE_POST_PROCESSING="TUNING_JOB_STATE_POST_PROCESSING"}(ie||(ie={})),function(e){e.AGGREGATION_METRIC_UNSPECIFIED="AGGREGATION_METRIC_UNSPECIFIED",e.AVERAGE="AVERAGE",e.MODE="MODE",e.STANDARD_DEVIATION="STANDARD_DEVIATION",e.VARIANCE="VARIANCE",e.MINIMUM="MINIMUM",e.MAXIMUM="MAXIMUM",e.MEDIAN="MEDIAN",e.PERCENTILE_P90="PERCENTILE_P90",e.PERCENTILE_P95="PERCENTILE_P95",e.PERCENTILE_P99="PERCENTILE_P99"}(re||(re={})),function(e){e.PAIRWISE_CHOICE_UNSPECIFIED="PAIRWISE_CHOICE_UNSPECIFIED",e.BASELINE="BASELINE",e.CANDIDATE="CANDIDATE",e.TIE="TIE"}(se||(se={})),function(e){e.VIDEO_ORIENTATION_UNSPECIFIED="VIDEO_ORIENTATION_UNSPECIFIED",e.LANDSCAPE="LANDSCAPE",e.PORTRAIT="PORTRAIT"}(le||(le={})),function(e){e.TUNING_SPEED_UNSPECIFIED="TUNING_SPEED_UNSPECIFIED",e.REGULAR="REGULAR",e.FAST="FAST"}(ae||(ae={})),function(e){e.TUNING_TASK_UNSPECIFIED="TUNING_TASK_UNSPECIFIED",e.TUNING_TASK_I2V="TUNING_TASK_I2V",e.TUNING_TASK_T2V="TUNING_TASK_T2V",e.TUNING_TASK_R2V="TUNING_TASK_R2V"}(ue||(ue={})),function(e){e.STATE_UNSPECIFIED="STATE_UNSPECIFIED",e.STATE_PENDING="STATE_PENDING",e.STATE_ACTIVE="STATE_ACTIVE",e.STATE_FAILED="STATE_FAILED"}(ce||(ce={})),function(e){e.UNSPECIFIED="unspecified",e.FLEX="flex",e.STANDARD="standard",e.PRIORITY="priority"}(pe||(pe={})),function(e){e.MEDIA_PROCESSING_UNSPECIFIED="MEDIA_PROCESSING_UNSPECIFIED",e.STATIC="STATIC",e.AGENTIC="AGENTIC"}(de||(de={})),function(e){e.MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",e.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",e.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",e.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH",e.MEDIA_RESOLUTION_ULTRA_HIGH="MEDIA_RESOLUTION_ULTRA_HIGH"}(me||(me={})),function(e){e.TOOL_TYPE_UNSPECIFIED="TOOL_TYPE_UNSPECIFIED",e.GOOGLE_SEARCH_WEB="GOOGLE_SEARCH_WEB",e.GOOGLE_SEARCH_IMAGE="GOOGLE_SEARCH_IMAGE",e.URL_CONTEXT="URL_CONTEXT",e.GOOGLE_MAPS="GOOGLE_MAPS",e.FILE_SEARCH="FILE_SEARCH",e.MEDIA_PROCESSING="MEDIA_PROCESSING"}(fe||(fe={})),function(e){e.COLLECTION="COLLECTION"}(he||(he={})),function(e){e.FEATURE_SELECTION_PREFERENCE_UNSPECIFIED="FEATURE_SELECTION_PREFERENCE_UNSPECIFIED",e.PRIORITIZE_QUALITY="PRIORITIZE_QUALITY",e.BALANCED="BALANCED",e.PRIORITIZE_COST="PRIORITIZE_COST"}(ge||(ge={})),function(e){e.PREDICT="PREDICT",e.EMBED_CONTENT="EMBED_CONTENT"}(ve||(ve={})),function(e){e.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",e.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",e.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",e.BLOCK_NONE="BLOCK_NONE"}(_e||(_e={})),function(e){e.auto="auto",e.en="en",e.ja="ja",e.ko="ko",e.hi="hi",e.zh="zh",e.pt="pt",e.es="es"}(Ee||(Ee={})),function(e){e.MASK_MODE_DEFAULT="MASK_MODE_DEFAULT",e.MASK_MODE_USER_PROVIDED="MASK_MODE_USER_PROVIDED",e.MASK_MODE_BACKGROUND="MASK_MODE_BACKGROUND",e.MASK_MODE_FOREGROUND="MASK_MODE_FOREGROUND",e.MASK_MODE_SEMANTIC="MASK_MODE_SEMANTIC"}(ye||(ye={})),function(e){e.CONTROL_TYPE_DEFAULT="CONTROL_TYPE_DEFAULT",e.CONTROL_TYPE_CANNY="CONTROL_TYPE_CANNY",e.CONTROL_TYPE_SCRIBBLE="CONTROL_TYPE_SCRIBBLE",e.CONTROL_TYPE_FACE_MESH="CONTROL_TYPE_FACE_MESH"}(Ae||(Ae={})),function(e){e.SUBJECT_TYPE_DEFAULT="SUBJECT_TYPE_DEFAULT",e.SUBJECT_TYPE_PERSON="SUBJECT_TYPE_PERSON",e.SUBJECT_TYPE_ANIMAL="SUBJECT_TYPE_ANIMAL",e.SUBJECT_TYPE_PRODUCT="SUBJECT_TYPE_PRODUCT"}(Ie||(Ie={})),function(e){e.EDIT_MODE_DEFAULT="EDIT_MODE_DEFAULT",e.EDIT_MODE_INPAINT_REMOVAL="EDIT_MODE_INPAINT_REMOVAL",e.EDIT_MODE_INPAINT_INSERTION="EDIT_MODE_INPAINT_INSERTION",e.EDIT_MODE_OUTPAINT="EDIT_MODE_OUTPAINT",e.EDIT_MODE_CONTROLLED_EDITING="EDIT_MODE_CONTROLLED_EDITING",e.EDIT_MODE_STYLE="EDIT_MODE_STYLE",e.EDIT_MODE_BGSWAP="EDIT_MODE_BGSWAP",e.EDIT_MODE_PRODUCT_IMAGE="EDIT_MODE_PRODUCT_IMAGE"}(Te||(Te={})),function(e){e.FOREGROUND="FOREGROUND",e.BACKGROUND="BACKGROUND",e.PROMPT="PROMPT",e.SEMANTIC="SEMANTIC",e.INTERACTIVE="INTERACTIVE"}(Ce||(Ce={})),function(e){e.ASSET="ASSET",e.STYLE="STYLE"}(Se||(Se={})),function(e){e.INSERT="INSERT",e.REMOVE="REMOVE",e.REMOVE_STATIC="REMOVE_STATIC",e.OUTPAINT="OUTPAINT"}(Oe||(Oe={})),function(e){e.OPTIMIZED="OPTIMIZED",e.LOSSLESS="LOSSLESS"}(be||(be={})),function(e){e.CROP="CROP",e.PAD="PAD"}(Pe||(Pe={})),function(e){e.SUPERVISED_FINE_TUNING="SUPERVISED_FINE_TUNING",e.PREFERENCE_TUNING="PREFERENCE_TUNING",e.DISTILLATION="DISTILLATION",e.REINFORCEMENT_TUNING="REINFORCEMENT_TUNING"}(we||(we={})),function(e){e.STATE_UNSPECIFIED="STATE_UNSPECIFIED",e.PROCESSING="PROCESSING",e.ACTIVE="ACTIVE",e.FAILED="FAILED"}(Re||(Re={})),function(e){e.SOURCE_UNSPECIFIED="SOURCE_UNSPECIFIED",e.UPLOADED="UPLOADED",e.GENERATED="GENERATED",e.REGISTERED="REGISTERED"}(Ne||(Ne={})),function(e){e.TURN_COMPLETE_REASON_UNSPECIFIED="TURN_COMPLETE_REASON_UNSPECIFIED",e.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",e.RESPONSE_REJECTED="RESPONSE_REJECTED",e.NEED_MORE_INPUT="NEED_MORE_INPUT",e.PROHIBITED_INPUT_CONTENT="PROHIBITED_INPUT_CONTENT",e.IMAGE_PROHIBITED_INPUT_CONTENT="IMAGE_PROHIBITED_INPUT_CONTENT",e.INPUT_TEXT_CONTAIN_PROMINENT_PERSON_PROHIBITED="INPUT_TEXT_CONTAIN_PROMINENT_PERSON_PROHIBITED",e.INPUT_IMAGE_CELEBRITY="INPUT_IMAGE_CELEBRITY",e.INPUT_IMAGE_PHOTO_REALISTIC_CHILD_PROHIBITED="INPUT_IMAGE_PHOTO_REALISTIC_CHILD_PROHIBITED",e.INPUT_TEXT_NCII_PROHIBITED="INPUT_TEXT_NCII_PROHIBITED",e.INPUT_OTHER="INPUT_OTHER",e.INPUT_IP_PROHIBITED="INPUT_IP_PROHIBITED",e.BLOCKLIST="BLOCKLIST",e.UNSAFE_PROMPT_FOR_IMAGE_GENERATION="UNSAFE_PROMPT_FOR_IMAGE_GENERATION",e.GENERATED_IMAGE_SAFETY="GENERATED_IMAGE_SAFETY",e.GENERATED_CONTENT_SAFETY="GENERATED_CONTENT_SAFETY",e.GENERATED_AUDIO_SAFETY="GENERATED_AUDIO_SAFETY",e.GENERATED_VIDEO_SAFETY="GENERATED_VIDEO_SAFETY",e.GENERATED_CONTENT_PROHIBITED="GENERATED_CONTENT_PROHIBITED",e.GENERATED_CONTENT_BLOCKLIST="GENERATED_CONTENT_BLOCKLIST",e.GENERATED_IMAGE_PROHIBITED="GENERATED_IMAGE_PROHIBITED",e.GENERATED_IMAGE_CELEBRITY="GENERATED_IMAGE_CELEBRITY",e.GENERATED_IMAGE_PROMINENT_PEOPLE_DETECTED_BY_REWRITER="GENERATED_IMAGE_PROMINENT_PEOPLE_DETECTED_BY_REWRITER",e.GENERATED_IMAGE_IDENTIFIABLE_PEOPLE="GENERATED_IMAGE_IDENTIFIABLE_PEOPLE",e.GENERATED_IMAGE_MINORS="GENERATED_IMAGE_MINORS",e.OUTPUT_IMAGE_IP_PROHIBITED="OUTPUT_IMAGE_IP_PROHIBITED",e.GENERATED_OTHER="GENERATED_OTHER",e.MAX_REGENERATION_REACHED="MAX_REGENERATION_REACHED"}(De||(De={})),function(e){e.INTERACTION_STATUS_UNSPECIFIED="INTERACTION_STATUS_UNSPECIFIED",e.IN_PROGRESS="IN_PROGRESS",e.REQUIRES_ACTION="REQUIRES_ACTION",e.IDLE="IDLE"}(Ge||(Ge={})),function(e){e.VAD_SIGNAL_TYPE_UNSPECIFIED="VAD_SIGNAL_TYPE_UNSPECIFIED",e.VAD_SIGNAL_TYPE_SOS="VAD_SIGNAL_TYPE_SOS",e.VAD_SIGNAL_TYPE_EOS="VAD_SIGNAL_TYPE_EOS"}(ke||(ke={})),function(e){e.TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",e.ACTIVITY_START="ACTIVITY_START",e.ACTIVITY_END="ACTIVITY_END"}(Me||(Me={})),function(e){e.START_SENSITIVITY_UNSPECIFIED="START_SENSITIVITY_UNSPECIFIED",e.START_SENSITIVITY_HIGH="START_SENSITIVITY_HIGH",e.START_SENSITIVITY_LOW="START_SENSITIVITY_LOW"}(xe||(xe={})),function(e){e.END_SENSITIVITY_UNSPECIFIED="END_SENSITIVITY_UNSPECIFIED",e.END_SENSITIVITY_HIGH="END_SENSITIVITY_HIGH",e.END_SENSITIVITY_LOW="END_SENSITIVITY_LOW"}(Ue||(Ue={})),function(e){e.ACTIVITY_HANDLING_UNSPECIFIED="ACTIVITY_HANDLING_UNSPECIFIED",e.START_OF_ACTIVITY_INTERRUPTS="START_OF_ACTIVITY_INTERRUPTS",e.NO_INTERRUPTION="NO_INTERRUPTION"}(Le||(Le={})),function(e){e.TURN_COVERAGE_UNSPECIFIED="TURN_COVERAGE_UNSPECIFIED",e.TURN_INCLUDES_ONLY_ACTIVITY="TURN_INCLUDES_ONLY_ACTIVITY",e.TURN_INCLUDES_ALL_INPUT="TURN_INCLUDES_ALL_INPUT",e.TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO="TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO"}(qe||(qe={})),function(e){e.MODE_UNSPECIFIED="MODE_UNSPECIFIED",e.VERBATIM="VERBATIM",e.SMART="SMART"}(He||(He={})),function(e){e.SCALE_UNSPECIFIED="SCALE_UNSPECIFIED",e.C_MAJOR_A_MINOR="C_MAJOR_A_MINOR",e.D_FLAT_MAJOR_B_FLAT_MINOR="D_FLAT_MAJOR_B_FLAT_MINOR",e.D_MAJOR_B_MINOR="D_MAJOR_B_MINOR",e.E_FLAT_MAJOR_C_MINOR="E_FLAT_MAJOR_C_MINOR",e.E_MAJOR_D_FLAT_MINOR="E_MAJOR_D_FLAT_MINOR",e.F_MAJOR_D_MINOR="F_MAJOR_D_MINOR",e.G_FLAT_MAJOR_E_FLAT_MINOR="G_FLAT_MAJOR_E_FLAT_MINOR",e.G_MAJOR_E_MINOR="G_MAJOR_E_MINOR",e.A_FLAT_MAJOR_F_MINOR="A_FLAT_MAJOR_F_MINOR",e.A_MAJOR_G_FLAT_MINOR="A_MAJOR_G_FLAT_MINOR",e.B_FLAT_MAJOR_G_MINOR="B_FLAT_MAJOR_G_MINOR",e.B_MAJOR_A_FLAT_MINOR="B_MAJOR_A_FLAT_MINOR"}(Fe||(Fe={})),function(e){e.MUSIC_GENERATION_MODE_UNSPECIFIED="MUSIC_GENERATION_MODE_UNSPECIFIED",e.QUALITY="QUALITY",e.DIVERSITY="DIVERSITY",e.VOCALIZATION="VOCALIZATION"}(je||(je={})),function(e){e.PLAYBACK_CONTROL_UNSPECIFIED="PLAYBACK_CONTROL_UNSPECIFIED",e.PLAY="PLAY",e.PAUSE="PAUSE",e.STOP="STOP",e.RESET_CONTEXT="RESET_CONTEXT"}(Be||(Be={}));var nt,ot=class{constructor(e){const t={};for(const n of e.headers.entries())t[n[0]]=n[1];this.headers=t,this.responseInternal=e}json(){return this.responseInternal.json()}},it=class{get text(){var e,t,n,o,i,r,s,l;if(0===(null===(o=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===o?void 0:o.length))return;this.candidates&&this.candidates.length;let a="",u=!1;const c=[];for(const p of null!==(l=null===(s=null===(r=null===(i=this.candidates)||void 0===i?void 0:i[0])||void 0===r?void 0:r.content)||void 0===s?void 0:s.parts)&&void 0!==l?l:[]){for(const[e,t]of Object.entries(p))"text"===e||"thought"===e||"thoughtSignature"===e||null===t&&void 0===t||c.push(e);if("string"==typeof p.text){if("boolean"==typeof p.thought&&p.thought)continue;u=!0,a+=p.text}}return c.length,u?a:void 0}get data(){var e,t,n,o,i,r,s,l;if(0===(null===(o=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===o?void 0:o.length))return;this.candidates&&this.candidates.length;let a="";const u=[];for(const c of null!==(l=null===(s=null===(r=null===(i=this.candidates)||void 0===i?void 0:i[0])||void 0===r?void 0:r.content)||void 0===s?void 0:s.parts)&&void 0!==l?l:[]){for(const[e,t]of Object.entries(c))"inlineData"===e||null===t&&void 0===t||u.push(e);c.inlineData&&"string"==typeof c.inlineData.data&&(a+=atob(c.inlineData.data))}return u.length,a.length>0?btoa(a):void 0}get functionCalls(){var e,t,n,o,i,r,s,l;if(0===(null===(o=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===o?void 0:o.length))return;this.candidates&&this.candidates.length;const a=null===(l=null===(s=null===(r=null===(i=this.candidates)||void 0===i?void 0:i[0])||void 0===r?void 0:r.content)||void 0===s?void 0:s.parts)||void 0===l?void 0:l.filter(e=>e.functionCall).map(e=>e.functionCall).filter(e=>void 0!==e);return 0!==(null==a?void 0:a.length)?a:void 0}get executableCode(){var e,t,n,o,i,r,s,l,a;if(0===(null===(o=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===o?void 0:o.length))return;this.candidates&&this.candidates.length;const u=null===(l=null===(s=null===(r=null===(i=this.candidates)||void 0===i?void 0:i[0])||void 0===r?void 0:r.content)||void 0===s?void 0:s.parts)||void 0===l?void 0:l.filter(e=>e.executableCode).map(e=>e.executableCode).filter(e=>void 0!==e);return 0!==(null==u?void 0:u.length)?null===(a=null==u?void 0:u[0])||void 0===a?void 0:a.code:void 0}get codeExecutionResult(){var e,t,n,o,i,r,s,l,a;if(0===(null===(o=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===o?void 0:o.length))return;this.candidates&&this.candidates.length;const u=null===(l=null===(s=null===(r=null===(i=this.candidates)||void 0===i?void 0:i[0])||void 0===r?void 0:r.content)||void 0===s?void 0:s.parts)||void 0===l?void 0:l.filter(e=>e.codeExecutionResult).map(e=>e.codeExecutionResult).filter(e=>void 0!==e);return 0!==(null==u?void 0:u.length)?null===(a=null==u?void 0:u[0])||void 0===a?void 0:a.output:void 0}},rt=class{},st=class{},lt=class{},at=class{},ut=class{},ct=class{},pt=class{},dt=class{},mt=class{},ft=class{},ht=class e{_fromAPIResponse({apiResponse:t,_isVertexAI:n}){const o=new e;let i;const r=t;return i=n?function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["videos"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["_self"]);return null!=n&&ze(t,["video"],function(e){const t={},n=Ze(e,["gcsUri"]);null!=n&&ze(t,["uri"],n);const o=Ze(e,["bytesBase64Encoded"]);null!=o&&ze(t,["videoBytes"],et(o));const i=Ze(e,["mimeType"]);return null!=i&&ze(t,["mimeType"],i),t}(n)),t}(e))),ze(t,["generatedVideos"],e)}const o=Ze(e,["raiMediaFilteredCount"]);null!=o&&ze(t,["raiMediaFilteredCount"],o);const i=Ze(e,["raiMediaFilteredReasons"]);return null!=i&&ze(t,["raiMediaFilteredReasons"],i),t}(s)),t}(r):function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response","generateVideoResponse"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["generatedSamples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["video"]);return null!=n&&ze(t,["video"],function(e){const t={},n=Ze(e,["uri"]);null!=n&&ze(t,["uri"],n);const o=Ze(e,["encodedVideo"]);null!=o&&ze(t,["videoBytes"],et(o));const i=Ze(e,["encoding"]);return null!=i&&ze(t,["mimeType"],i),t}(n)),t}(e))),ze(t,["generatedVideos"],e)}const o=Ze(e,["raiMediaFilteredCount"]);null!=o&&ze(t,["raiMediaFilteredCount"],o);const i=Ze(e,["raiMediaFilteredReasons"]);return null!=i&&ze(t,["raiMediaFilteredReasons"],i),t}(s)),t}(r),Object.assign(o,i),o}},gt=class{},vt=class{},_t=class{},Et=class{},yt=class{},At=class{},It=class{},Tt=class{},Ct=class e{_fromAPIResponse({apiResponse:t,_isVertexAI:n}){const o=new e,i=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["parent"]);null!=o&&ze(t,["parent"],o);const i=Ze(e,["documentName"]);return null!=i&&ze(t,["documentName"],i),t}(s)),t}(t);return Object.assign(o,i),o}},St=class{},Ot=class{},bt=class{},Pt=class{},wt=class{},Rt=class{get text(){var e,t,n;let o="",i=!1;const r=[];for(const s 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(const[e,t]of Object.entries(s))"text"!==e&&"thought"!==e&&null!==t&&r.push(e);if("string"==typeof s.text){if("boolean"==typeof s.thought&&s.thought)continue;i=!0,o+=s.text}}return r.length,i?o:void 0}get data(){var e,t,n;let o="";const i=[];for(const 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(const[e,t]of Object.entries(r))"inlineData"!==e&&null!==t&&i.push(e);r.inlineData&&"string"==typeof r.inlineData.data&&(o+=atob(r.inlineData.data))}return i.length,o.length>0?btoa(o):void 0}},Nt=class{get audioChunk(){if(this.serverContent&&this.serverContent.audioChunks&&this.serverContent.audioChunks.length>0)return this.serverContent.audioChunks[0]}},Dt=class e{_fromAPIResponse({apiResponse:t,_isVertexAI:n}){const o=new e,i=tt(t);return Object.assign(o,i),o}};function Gt(e,t){if(!t||"string"!=typeof t)throw new Error("model is required and must be a string");if(t.includes("..")||t.includes("?")||t.includes("&"))throw new Error("invalid model parameter");if(e.isVertexAI()){if(t.startsWith("publishers/")||t.startsWith("projects/")||t.startsWith("models/"))return t;if(t.indexOf("/")>=0){const e=t.split("/",2);return`publishers/${e[0]}/models/${e[1]}`}return`publishers/google/models/${t}`}return t.startsWith("models/")||t.startsWith("tunedModels/")?t:`models/${t}`}function kt(e,t){const n=Gt(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 Mt(e){return Array.isArray(e)?e.map(e=>xt(e)):[xt(e)]}function xt(e){if("object"==typeof e&&null!==e)return e;throw new Error("Could not parse input as Blob. Unsupported blob type: "+typeof e)}function Ut(e){const t=xt(e);if(t.mimeType&&t.mimeType.startsWith("image/"))return t;throw new Error(`Unsupported mime type: ${t.mimeType}`)}function Lt(e){const t=xt(e);if(t.mimeType&&t.mimeType.startsWith("audio/"))return t;throw new Error(`Unsupported mime type: ${t.mimeType}`)}function qt(e){if(null==e)throw new Error("PartUnion is required");if("object"==typeof e)return e;if("string"==typeof e)return{text:e};throw new Error("Unsupported part type: "+typeof e)}function Ht(e){if(null==e||Array.isArray(e)&&0===e.length)throw new Error("PartListUnion is required");return Array.isArray(e)?e.map(e=>qt(e)):[qt(e)]}function Ft(e){return null!=e&&"object"==typeof e&&"parts"in e&&Array.isArray(e.parts)}function jt(e){return null!=e&&"object"==typeof e&&"functionCall"in e}function Bt(e){return null!=e&&"object"==typeof e&&"functionResponse"in e}function Vt(e){if(null==e)throw new Error("ContentUnion is required");return Ft(e)?e:{role:"user",parts:Ht(e)}}function Xt(e,t){if(!t)return[];if(e.isVertexAI()&&Array.isArray(t))return t.flatMap(e=>{const t=Vt(e);return t.parts&&t.parts.length>0&&void 0!==t.parts[0].text?[t.parts[0].text]:[]});if(e.isVertexAI()){const e=Vt(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=>Vt(e)):[Vt(t)]}function Jt(e){if(null==e||Array.isArray(e)&&0===e.length)throw new Error("contents are required");if(!Array.isArray(e)){if(jt(e)||Bt(e))throw new Error("To specify functionCall or functionResponse parts, please wrap them in a Content object, specifying the role for them");return[Vt(e)]}const t=[],n=[],o=Ft(e[0]);for(const i of e){const e=Ft(i);if(e!=o)throw new 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(i);else{if(jt(i)||Bt(i))throw new Error("To specify functionCall or functionResponse parts, please wrap them, and any other parts, in Content objects as appropriate, specifying the role for them");n.push(i)}}return o||t.push({role:"user",parts:Ht(n)}),t}function Yt(e){const t={},n=["items"],o=["anyOf"],i=["properties"];if(e.type&&e.anyOf)throw new Error("type and anyOf cannot be both populated.");const r=e.anyOf;null!=r&&2==r.length&&("null"===r[0].type?(t.nullable=!0,e=r[1]):"null"===r[1].type&&(t.nullable=!0,e=r[0])),e.type instanceof Array&&function(e,t){e.includes("null")&&(t.nullable=!0);const n=e.filter(e=>"null"!==e);if(1===n.length)t.type=Object.values(T).includes(n[0].toUpperCase())?n[0].toUpperCase():T.TYPE_UNSPECIFIED;else{t.anyOf=[];for(const e of n)t.anyOf.push({type:Object.values(T).includes(e.toUpperCase())?e.toUpperCase():T.TYPE_UNSPECIFIED})}}(e.type,t);for(const[s,l]of Object.entries(e))if(null!=l)if("type"==s){if("null"===l)throw new Error("type: null can not be the only possible type for the field.");if(l instanceof Array)continue;t.type=Object.values(T).includes(l.toUpperCase())?l.toUpperCase():T.TYPE_UNSPECIFIED}else if(n.includes(s))t[s]=Yt(l);else if(o.includes(s)){const e=[];for(const n of l)"null"!=n.type?e.push(Yt(n)):t.nullable=!0;t[s]=e}else if(i.includes(s)){const e={};for(const[t,n]of Object.entries(l))e[t]=Yt(n);t[s]=e}else{if("additionalProperties"===s)continue;t[s]=l}return t}function $t(e){return Yt(e)}function Kt(e){if("object"==typeof e)return e;if("string"==typeof e)return{voiceConfig:{prebuiltVoiceConfig:{voiceName:e}}};throw new Error("Unsupported speechConfig type: "+typeof e)}function Wt(e){if("multiSpeakerVoiceConfig"in e)throw new Error("multiSpeakerVoiceConfig is not supported in the live API.");return e}function zt(e){if(e.functionDeclarations)for(const t of e.functionDeclarations)t.parameters&&(Object.keys(t.parameters).includes("$schema")?t.parametersJsonSchema||(t.parametersJsonSchema=t.parameters,delete t.parameters):t.parameters=Yt(t.parameters)),t.response&&(Object.keys(t.response).includes("$schema")?t.responseJsonSchema||(t.responseJsonSchema=t.response,delete t.response):t.response=Yt(t.response));return e}function Zt(e){if(null==e)throw new Error("tools is required");if(!Array.isArray(e))throw new Error("tools is required and must be an array of Tools");const t=[];for(const n of e)t.push(n);return t}function Qt(e,t){if("string"!=typeof t)throw new Error("name must be a string");return function(e,t,n,o=1){const i=!t.startsWith(`${n}/`)&&t.split("/").length===o;return e.isVertexAI()?t.startsWith("projects/")?t:t.startsWith("locations/")?`projects/${e.getProject()}/${t}`:t.startsWith(`${n}/`)?`projects/${e.getProject()}/locations/${e.getLocation()}/${t}`:i?`projects/${e.getProject()}/locations/${e.getLocation()}/${n}/${t}`:t:i?`${n}/${t}`:t}(e,t,"cachedContents")}function en(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 tn(e){return et(e)}function nn(e){var t;let n;var o;if(null!=(o=e)&&"object"==typeof o&&"name"in o&&(n=e.name),!(function(e){return null!=e&&"object"==typeof e&&"uri"in e}(e)&&(n=e.uri,void 0===n)||function(e){return null!=e&&"object"==typeof e&&"video"in e}(e)&&(n=null===(t=e.video)||void 0===t?void 0:t.uri,void 0===n))){if("string"==typeof e&&(n=e),void 0===n)throw new Error("Could not extract file name from the provided input.");if(n.startsWith("https://")){const e=n.split("files/")[1].match(/[a-z0-9]+/);if(null===e)throw new Error(`Could not extract file name from URI ${n}`);n=e[0]}else n.startsWith("files/")&&(n=n.split("files/")[1]);return n}}function on(e,t){let n;return n=e.isVertexAI()?t?"publishers/google/models":"models":t?"models":"tunedModels",n}function rn(e){for(const t of["models","tunedModels","publisherModels"])if(sn(e,t))return e[t];return[]}function sn(e,t){return null!==e&&"object"==typeof e&&t in e}function ln(e,t={}){const n=e,o={name:n.name,description:n.description,parametersJsonSchema:n.inputSchema};return n.outputSchema&&(o.responseJsonSchema=n.outputSchema),t.behavior&&(o.behavior=t.behavior),{functionDeclarations:[o]}}function an(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{if(!/^projects\/[^/]+\/locations\/[^/]+\/datasets\/[^/]+$/.test(t))throw new Error(`Unsupported string source for Vertex AI: ${t}`);n={format:"vertex-dataset",vertexDatasetName:t}}else{if(!t.startsWith("files/"))throw new Error(`Unsupported string source for Gemini API: ${t}`);n={fileName:t}}else if(Array.isArray(t)){if(e.isVertexAI())throw new Error("InlinedRequest[] is not supported in Vertex AI.");n={inlinedRequests:t}}else n=t;const o=[n.gcsUri,n.bigqueryUri,n.vertexDatasetName].filter(Boolean).length,i=[n.inlinedRequests,n.fileName].filter(Boolean).length;if(e.isVertexAI()){if(i>0||1!==o)throw new Error("Exactly one of `gcsUri`, `bigqueryUri`, or `vertexDatasetName` must be set for Vertex AI.")}else if(o>0||1!==i)throw new Error("Exactly one of `inlinedRequests`, `fileName`, must be set for Gemini API.");return n}function un(e){if("object"!=typeof e||null===e)return{};const t=e,n=t.inlinedResponses;if("object"!=typeof n||null===n)return e;const o=n.inlinedResponses;if(!Array.isArray(o)||0===o.length)return e;let i=!1;for(const r of o){if("object"!=typeof r||null===r)continue;const e=r.response;if("object"==typeof e&&null!==e&&void 0!==e.embedding){i=!0;break}}return i&&(t.inlinedEmbedContentResponses=t.inlinedResponses,delete t.inlinedResponses),e}function cn(e,t){const n=t;if(!e.isVertexAI()){if(/batches\/[^/]+$/.test(n))return n.split("/").pop();throw new Error(`Invalid batch job name: ${n}.`)}if(/^projects\/[^/]+\/locations\/[^/]+\/batchPredictionJobs\/[^/]+$/.test(n))return n.split("/").pop();if(/^\d+$/.test(n))return n;throw new Error(`Invalid batch job name: ${n}.`)}function pn(e){return"BATCH_STATE_UNSPECIFIED"===e?"JOB_STATE_UNSPECIFIED":"BATCH_STATE_PENDING"===e?"JOB_STATE_PENDING":"BATCH_STATE_RUNNING"===e?"JOB_STATE_RUNNING":"BATCH_STATE_SUCCEEDED"===e?"JOB_STATE_SUCCEEDED":"BATCH_STATE_FAILED"===e?"JOB_STATE_FAILED":"BATCH_STATE_CANCELLED"===e?"JOB_STATE_CANCELLED":"BATCH_STATE_EXPIRED"===e?"JOB_STATE_EXPIRED":e}function dn(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata","displayName"]);null!=o&&ze(t,["displayName"],o);const i=Ze(e,["metadata","state"]);null!=i&&ze(t,["state"],pn(i));const r=Ze(e,["metadata","createTime"]);null!=r&&ze(t,["createTime"],r);const s=Ze(e,["metadata","endTime"]);null!=s&&ze(t,["endTime"],s);const l=Ze(e,["metadata","updateTime"]);null!=l&&ze(t,["updateTime"],l);const a=Ze(e,["metadata","model"]);null!=a&&ze(t,["model"],a);const u=Ze(e,["metadata","output"]);return null!=u&&ze(t,["dest"],function(e){const t={},n=Ze(e,["responsesFile"]);null!=n&&ze(t,["fileName"],n);const o=Ze(e,["inlinedResponses","inlinedResponses"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["response"]);null!=n&&ze(t,["response"],function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["candidates"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["content"]);null!=n&&ze(t,["content"],n);const o=Ze(e,["citationMetadata"]);null!=o&&ze(t,["citationMetadata"],function(e){const t={},n=Ze(e,["citationSources"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["citations"],e)}return t}(o));const i=Ze(e,["tokenCount"]);null!=i&&ze(t,["tokenCount"],i);const r=Ze(e,["finishReason"]);null!=r&&ze(t,["finishReason"],r);const s=Ze(e,["groundingMetadata"]);null!=s&&ze(t,["groundingMetadata"],s);const l=Ze(e,["avgLogprobs"]);null!=l&&ze(t,["avgLogprobs"],l);const a=Ze(e,["index"]);null!=a&&ze(t,["index"],a);const u=Ze(e,["logprobsResult"]);null!=u&&ze(t,["logprobsResult"],u);const c=Ze(e,["safetyRatings"]);if(null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["safetyRatings"],e)}const p=Ze(e,["urlContextMetadata"]);return null!=p&&ze(t,["urlContextMetadata"],p),t}(e))),ze(t,["candidates"],e)}const i=Ze(e,["modelVersion"]);null!=i&&ze(t,["modelVersion"],i);const r=Ze(e,["promptFeedback"]);null!=r&&ze(t,["promptFeedback"],r);const s=Ze(e,["responseId"]);null!=s&&ze(t,["responseId"],s);const l=Ze(e,["usageMetadata"]);null!=l&&ze(t,["usageMetadata"],l);const a=Ze(e,["modelStatus"]);return null!=a&&ze(t,["modelStatus"],a),t}(n));const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["error"]);return null!=i&&ze(t,["error"],i),t}(e))),ze(t,["inlinedResponses"],e)}const i=Ze(e,["inlinedEmbedContentResponses","inlinedResponses"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["inlinedEmbedContentResponses"],e)}return t}(un(u))),t}function mn(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["displayName"]);null!=o&&ze(t,["displayName"],o);const i=Ze(e,["state"]);null!=i&&ze(t,["state"],pn(i));const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["createTime"]);null!=s&&ze(t,["createTime"],s);const l=Ze(e,["startTime"]);null!=l&&ze(t,["startTime"],l);const a=Ze(e,["endTime"]);null!=a&&ze(t,["endTime"],a);const u=Ze(e,["updateTime"]);null!=u&&ze(t,["updateTime"],u);const c=Ze(e,["model"]);null!=c&&ze(t,["model"],c);const p=Ze(e,["inputConfig"]);null!=p&&ze(t,["src"],function(e){const t={},n=Ze(e,["instancesFormat"]);null!=n&&ze(t,["format"],n);const o=Ze(e,["gcsSource","uris"]);null!=o&&ze(t,["gcsUri"],o);const i=Ze(e,["bigquerySource","inputUri"]);null!=i&&ze(t,["bigqueryUri"],i);const r=Ze(e,["vertexMultimodalDatasetSource","datasetName"]);return null!=r&&ze(t,["vertexDatasetName"],r),t}(p));const d=Ze(e,["outputConfig"]);null!=d&&ze(t,["dest"],function(e){const t={},n=Ze(e,["predictionsFormat"]);null!=n&&ze(t,["format"],n);const o=Ze(e,["gcsDestination","outputUriPrefix"]);null!=o&&ze(t,["gcsUri"],o);const i=Ze(e,["bigqueryDestination","outputUri"]);null!=i&&ze(t,["bigqueryUri"],i);const r=Ze(e,["vertexMultimodalDatasetDestination"]);return null!=r&&ze(t,["vertexDataset"],function(e){const t={},n=Ze(e,["bigqueryDestination","outputUri"]);null!=n&&ze(t,["bigqueryDestination"],n);const o=Ze(e,["displayName"]);return null!=o&&ze(t,["displayName"],o),t}(r)),t}(un(d)));const m=Ze(e,["outputInfo"]);null!=m&&ze(t,["outputInfo"],m);const f=Ze(e,["completionStats"]);return null!=f&&ze(t,["completionStats"],f),t}function fn(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);null!=n&&ze(t,["mediaResolution"],n);const o=Ze(e,["toolCall"]);null!=o&&ze(t,["toolCall"],o);const i=Ze(e,["toolResponse"]);null!=i&&ze(t,["toolResponse"],i);const r=Ze(e,["audioTranscription"]);null!=r&&ze(t,["audioTranscription"],r);const s=Ze(e,["codeExecutionResult"]);null!=s&&ze(t,["codeExecutionResult"],s);const l=Ze(e,["executableCode"]);null!=l&&ze(t,["executableCode"],l);const a=Ze(e,["fileData"]);null!=a&&ze(t,["fileData"],function(e){const t={};if(void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["fileUri"]);null!=n&&ze(t,["fileUri"],n);const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(a));const u=Ze(e,["functionCall"]);null!=u&&ze(t,["functionCall"],function(e){const t={},n=Ze(e,["args"]);null!=n&&ze(t,["args"],n);const o=Ze(e,["id"]);null!=o&&ze(t,["id"],o);const i=Ze(e,["name"]);if(null!=i&&ze(t,["name"],i),void 0!==Ze(e,["partialArgs"]))throw new Error("partialArgs parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["willContinue"]))throw new Error("willContinue parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(u));const c=Ze(e,["functionResponse"]);null!=c&&ze(t,["functionResponse"],c);const p=Ze(e,["inlineData"]);null!=p&&ze(t,["inlineData"],function(e){const t={},n=Ze(e,["data"]);if(null!=n&&ze(t,["data"],n),void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(p));const d=Ze(e,["text"]);null!=d&&ze(t,["text"],d);const m=Ze(e,["thought"]);null!=m&&ze(t,["thought"],m);const f=Ze(e,["thoughtSignature"]);null!=f&&ze(t,["thoughtSignature"],f);const h=Ze(e,["videoMetadata"]);null!=h&&ze(t,["videoMetadata"],h);const g=Ze(e,["partMetadata"]);null!=g&&ze(t,["partMetadata"],g);const v=Ze(e,["mediaProcessing"]);return null!=v&&ze(t,["mediaProcessing"],v),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}function hn(e,t){const n=Ze(e,["displayName"]);void 0!==t&&null!=n&&ze(t,["displayName"],n);const o=Ze(e,["dest"]);if(void 0!==t&&null!=o&&ze(t,["outputConfig"],function(e){const t={},n=Ze(e,["format"]);null!=n&&ze(t,["predictionsFormat"],n);const o=Ze(e,["gcsUri"]);null!=o&&ze(t,["gcsDestination","outputUriPrefix"],o);const i=Ze(e,["bigqueryUri"]);null!=i&&ze(t,["bigqueryDestination","outputUri"],i);const r=Ze(e,["vertexDataset"]);if(null!=r&&ze(t,["vertexMultimodalDatasetDestination"],function(e){const t={},n=Ze(e,["bigqueryDestination"]);null!=n&&ze(t,["bigqueryDestination","outputUri"],n);const o=Ze(e,["displayName"]);return null!=o&&ze(t,["displayName"],o),t}(r)),void 0!==Ze(e,["fileName"]))throw new Error("fileName parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["inlinedResponses"]))throw new Error("inlinedResponses parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["inlinedEmbedContentResponses"]))throw new Error("inlinedEmbedContentResponses parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(function(e){if("string"!=typeof e)return e;const t=e;if(t.startsWith("gs://"))return{format:"jsonl",gcsUri:t};if(t.startsWith("bq://"))return{format:"bigquery",bigqueryUri:t};throw new Error(`Unsupported destination: ${t}`)}(o))),void 0!==Ze(e,["webhookConfig"]))throw new Error("webhookConfig parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return{}}function gn(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["src"]);null!=i&&ze(n,["batch","inputConfig"],function(e,t){const n={};if(void 0!==Ze(t,["format"]))throw new Error("format parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(t,["gcsUri"]))throw new Error("gcsUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(t,["bigqueryUri"]))throw new Error("bigqueryUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(t,["vertexDatasetName"]))throw new Error("vertexDatasetName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(t,["fileName"]);null!=o&&ze(n,["fileName"],o);const i=Ze(t,["inlinedRequests"]);if(null!=i){let t=i;Array.isArray(t)&&(t=t.map(t=>function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["request","model"],Gt(e,o));const i=Ze(t,["contents"]);if(null!=i){let e=Jt(i);Array.isArray(e)&&(e=e.map(e=>fn(e))),ze(n,["request","contents"],e)}const r=Ze(t,["metadata"]);null!=r&&ze(n,["metadata"],r);const s=Ze(t,["config"]);return null!=s&&ze(n,["request","generationConfig"],function(e,t,n){const o={},i=Ze(t,["serviceTier"]);void 0!==n&&null!=i&&ze(n,["serviceTier"],i);const r=Ze(t,["systemInstruction"]);void 0!==n&&null!=r&&ze(n,["systemInstruction"],fn(Vt(r)));const s=Ze(t,["temperature"]);null!=s&&ze(o,["temperature"],s);const l=Ze(t,["topP"]);null!=l&&ze(o,["topP"],l);const a=Ze(t,["topK"]);null!=a&&ze(o,["topK"],a);const u=Ze(t,["candidateCount"]);null!=u&&ze(o,["candidateCount"],u);const c=Ze(t,["maxOutputTokens"]);null!=c&&ze(o,["maxOutputTokens"],c);const p=Ze(t,["stopSequences"]);null!=p&&ze(o,["stopSequences"],p);const d=Ze(t,["responseLogprobs"]);null!=d&&ze(o,["responseLogprobs"],d);const m=Ze(t,["logprobs"]);null!=m&&ze(o,["logprobs"],m);const f=Ze(t,["presencePenalty"]);null!=f&&ze(o,["presencePenalty"],f);const h=Ze(t,["frequencyPenalty"]);null!=h&&ze(o,["frequencyPenalty"],h);const g=Ze(t,["seed"]);null!=g&&ze(o,["seed"],g);const v=Ze(t,["responseMimeType"]);null!=v&&ze(o,["responseMimeType"],v);const _=Ze(t,["responseSchema"]);null!=_&&ze(o,["responseSchema"],$t(_));const E=Ze(t,["responseJsonSchema"]);if(null!=E&&ze(o,["responseJsonSchema"],E),void 0!==Ze(t,["routingConfig"]))throw new Error("routingConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(t,["modelSelectionConfig"]))throw new Error("modelSelectionConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const y=Ze(t,["safetySettings"]);if(void 0!==n&&null!=y){let e=y;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["category"]);if(null!=n&&ze(t,["category"],n),void 0!==Ze(e,["method"]))throw new Error("method parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["threshold"]);return null!=o&&ze(t,["threshold"],o),t}(e))),ze(n,["safetySettings"],e)}const A=Ze(t,["tools"]);if(void 0!==n&&null!=A){let e=Zt(A);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==Ze(e,["retrieval"]))throw new Error("retrieval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["googleMaps"]);null!=n&&ze(t,["googleMaps"],function(e){const t={},n=Ze(e,["authConfig"]);null!=n&&ze(t,["authConfig"],function(e){const t={},n=Ze(e,["apiKey"]);if(null!=n&&ze(t,["apiKey"],n),void 0!==Ze(e,["apiKeyConfig"]))throw new Error("apiKeyConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["authType"]))throw new Error("authType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["googleServiceAccountConfig"]))throw new Error("googleServiceAccountConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["httpBasicAuthConfig"]))throw new Error("httpBasicAuthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oauthConfig"]))throw new Error("oauthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oidcConfig"]))throw new Error("oidcConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["enableWidget"]);if(null!=o&&ze(t,["enableWidget"],o),void 0!==Ze(e,["groundingTypes"]))throw new Error("groundingTypes parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["mcpServers"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mcpServers"],e)}const i=Ze(e,["codeExecution"]);null!=i&&ze(t,["codeExecution"],i);const r=Ze(e,["computerUse"]);if(null!=r&&ze(t,["computerUse"],r),void 0!==Ze(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["exaAiSearch"]))throw new Error("exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const s=Ze(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const l=Ze(e,["googleSearch"]);null!=l&&ze(t,["googleSearch"],function(e){const t={};if(void 0!==Ze(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["excludeDomains"]))throw new Error("excludeDomains parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["searchTypes"]);null!=n&&ze(t,["searchTypes"],n);const o=Ze(e,["timeRangeFilter"]);return null!=o&&ze(t,["timeRangeFilter"],o),t}(l));const a=Ze(e,["googleSearchRetrieval"]);if(null!=a&&ze(t,["googleSearchRetrieval"],a),void 0!==Ze(e,["parallelAiSearch"]))throw new Error("parallelAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["urlContext"]);null!=u&&ze(t,["urlContext"],u);const c=Ze(e,["fileSearch"]);return null!=c&&ze(t,["fileSearch"],c),t}(zt(e)))),ze(n,["tools"],e)}const I=Ze(t,["toolConfig"]);if(void 0!==n&&null!=I&&ze(n,["toolConfig"],function(e){const t={},n=Ze(e,["functionCallingConfig"]);null!=n&&ze(t,["functionCallingConfig"],function(e){const t={},n=Ze(e,["allowedFunctionNames"]);null!=n&&ze(t,["allowedFunctionNames"],n);const o=Ze(e,["mode"]);if(null!=o&&ze(t,["mode"],o),void 0!==Ze(e,["streamFunctionCallArguments"]))throw new Error("streamFunctionCallArguments parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["retrievalConfig"]);null!=o&&ze(t,["retrievalConfig"],o);const i=Ze(e,["includeServerSideToolInvocations"]);return null!=i&&ze(t,["includeServerSideToolInvocations"],i),t}(I)),void 0!==Ze(t,["labels"]))throw new Error("labels parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const T=Ze(t,["cachedContent"]);void 0!==n&&null!=T&&ze(n,["cachedContent"],Qt(e,T));const C=Ze(t,["responseModalities"]);null!=C&&ze(o,["responseModalities"],C);const S=Ze(t,["mediaResolution"]);null!=S&&ze(o,["mediaResolution"],S);const O=Ze(t,["speechConfig"]);if(null!=O&&ze(o,["speechConfig"],Kt(O)),void 0!==Ze(t,["audioTimestamp"]))throw new Error("audioTimestamp parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const b=Ze(t,["thinkingConfig"]);null!=b&&ze(o,["thinkingConfig"],b);const P=Ze(t,["audioTranscriptionConfig"]);null!=P&&ze(o,["audioTranscriptionConfig"],P);const w=Ze(t,["imageConfig"]);null!=w&&ze(o,["imageConfig"],function(e){const t={},n=Ze(e,["aspectRatio"]);null!=n&&ze(t,["aspectRatio"],n);const o=Ze(e,["imageSize"]);if(null!=o&&ze(t,["imageSize"],o),void 0!==Ze(e,["personGeneration"]))throw new Error("personGeneration parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["outputMimeType"]))throw new Error("outputMimeType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["outputCompressionQuality"]))throw new Error("outputCompressionQuality parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["imageOutputOptions"]))throw new Error("imageOutputOptions parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["prominentPeople"]))throw new Error("prominentPeople parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(w));const R=Ze(t,["enableEnhancedCivicAnswers"]);if(null!=R&&ze(o,["enableEnhancedCivicAnswers"],R),void 0!==Ze(t,["modelArmorConfig"]))throw new Error("modelArmorConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return o}(e,s,Ze(n,["request"],{}))),n}(e,t))),ze(n,["requests","requests"],t)}return n}(e,an(e,i)));const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["displayName"]);if(void 0!==t&&null!=n&&ze(t,["batch","displayName"],n),void 0!==Ze(e,["dest"]))throw new Error("dest parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["webhookConfig"]);void 0!==t&&null!=o&&ze(t,["batch","webhookConfig"],o)}(r,n),n}!function(e){e.PAGED_ITEM_BATCH_JOBS="batchJobs",e.PAGED_ITEM_MODELS="models",e.PAGED_ITEM_TUNING_JOBS="tuningJobs",e.PAGED_ITEM_FILES="files",e.PAGED_ITEM_CACHED_CONTENTS="cachedContents",e.PAGED_ITEM_FILE_SEARCH_STORES="fileSearchStores",e.PAGED_ITEM_DOCUMENTS="documents",e.PAGED_ITEM_SKILLS="skills"}(nt||(nt={}));var vn=class{constructor(e,t,n,o){this.pageInternal=[],this.paramsInternal={},this.requestInternal=t,this.init(e,n,o)}init(e,t,n){var o,i;this.nameInternal=e,this.pageInternal=t[this.nameInternal]||[],this.sdkHttpResponseInternal=null==t?void 0:t.sdkHttpResponse,this.idxInternal=0;let r={config:{}};r=n&&0!==Object.keys(n).length?"object"==typeof n?Object.assign({},n):n:{config:{}},r.config&&(r.config.pageToken=t.nextPageToken),this.paramsInternal=r,this.pageInternalSize=null!==(i=null===(o=r.config)||void 0===o?void 0:o.pageSize)&&void 0!==i?i: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()}const 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 new Error("No more pages to fetch.");const e=await this.requestInternal(this.params);return this.initNextPage(e),this.page}hasNextPage(){var e;return void 0!==(null===(e=this.params.config)||void 0===e?void 0:e.pageToken)}},_n=class extends Ke{constructor(e){super(),this.apiClient=e,this.list=async(e={})=>new vn(nt.PAGED_ITEM_BATCH_JOBS,e=>this.listInternal(e),await this.listInternal(e),e),this.create=async e=>(this.apiClient.isVertexAI()&&(e.config=this.formatDestination(e.src,e.config)),this.createInternal(e)),this.createEmbeddings=async e=>{if(this.apiClient.isVertexAI())throw new Error("Gemini Enterprise Agent Platform (previously known as Vertex AI) does not support batches.createEmbeddings.");return this.createEmbeddingsInternal(e)}}createInlinedGenerateContentRequest(e){const t=gn(this.apiClient,e),n=We("{model}:batchGenerateContent",t._url),o=t.batch.inputConfig.requests,i=o.requests,r=[];for(const s of i){const e=Object.assign({},s);if(e.systemInstruction){const t=e.systemInstruction;delete e.systemInstruction;const n=e.request;n.systemInstruction=t,e.request=n}r.push(e)}return o.requests=r,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){const n=t?Object.assign({},t):{},o=Date.now().toString();if(n.displayName||(n.displayName=`genaiBatchJob_${o}`),void 0===n.dest){const t=this.getGcsUri(e),i=this.getBigqueryUri(e);if(t)t.endsWith(".jsonl")?n.dest=`${t.slice(0,-6)}/dest`:n.dest=`${t}_dest_${o}`;else{if(!i)throw new Error("Unsupported source for Gemini Enterprise Agent Platform (previously known as Vertex AI): No GCS or BigQuery URI found.");n.dest=`${i}_dest_${o}`}}return n}async createInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["model"],Gt(e,o));const i=Ze(t,["src"]);null!=i&&ze(n,["inputConfig"],function(e){const t={},n=Ze(e,["format"]);null!=n&&ze(t,["instancesFormat"],n);const o=Ze(e,["gcsUri"]);null!=o&&ze(t,["gcsSource","uris"],o);const i=Ze(e,["bigqueryUri"]);null!=i&&ze(t,["bigquerySource","inputUri"],i);const r=Ze(e,["vertexDatasetName"]);if(null!=r&&ze(t,["vertexMultimodalDatasetSource","datasetName"],r),void 0!==Ze(e,["fileName"]))throw new Error("fileName parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["inlinedRequests"]))throw new Error("inlinedRequests parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(an(e,i)));const r=Ze(t,["config"]);return null!=r&&hn(r,n),n}(this.apiClient,e);return s=We("batchPredictionJobs",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>mn(e))}{const t=gn(this.apiClient,e);return s=We("{model}:batchGenerateContent",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>dn(e))}}async createEmbeddingsInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["src"]);null!=i&&ze(n,["batch","inputConfig"],function(e,t){const n={},o=Ze(t,["fileName"]);null!=o&&ze(n,["file_name"],o);const i=Ze(t,["inlinedRequests"]);return null!=i&&ze(n,["requests"],function(e,t){const n={},o=Ze(t,["contents"]);if(null!=o){let t=Xt(e,o);Array.isArray(t)&&(t=t.map(e=>e)),ze(n,["requests[]","request","content"],t)}const i=Ze(t,["config"]);return null!=i&&(ze(n,["_self"],function(e,t){const n=Ze(e,["taskType"]);void 0!==t&&null!=n&&ze(t,["requests[]","taskType"],n);const o=Ze(e,["title"]);void 0!==t&&null!=o&&ze(t,["requests[]","title"],o);const i=Ze(e,["outputDimensionality"]);if(void 0!==t&&null!=i&&ze(t,["requests[]","outputDimensionality"],i),void 0!==Ze(e,["mimeType"]))throw new Error("mimeType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["autoTruncate"]))throw new Error("autoTruncate parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["documentOcr"]))throw new Error("documentOcr parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["audioTrackExtraction"]))throw new Error("audioTrackExtraction parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return{}}(i,n)),function(e){for(const[t,n]of Object.entries({"requests[].*":"requests[].request.*"})){const o=t.split("."),i=n.split("."),r=/* @__PURE__ */new Set;let s=-1;for(let e=0;e<o.length;e++)if("*"===o[e]){s=e;break}if(-1!==s&&i.length>s)for(let e=s;e<i.length;e++){const t=i[e];"*"===t||t.endsWith("[]")||t.endsWith("[0]")||r.add(t)}Qe(e,o,i,0,r)}}(n)),n}(e,i)),n}(e,i));const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["displayName"]);void 0!==t&&null!=n&&ze(t,["batch","displayName"],n)}(r,n),n}(this.apiClient,e);return i=We("{model}:asyncBatchEmbedContent",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>dn(e))}}async get(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);return s=We("batchPredictionJobs/{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>mn(e))}{const t=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);return s=We("batches/{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>dn(e))}}async cancel(e){var t,n,o,i;let r="",s={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);r=We("batchPredictionJobs/{name}:cancel",o._url),s=o._query,delete o._url,delete o._query,await this.apiClient.request({path:r,queryParams:s,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})}else{const t=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);r=We("batches/{name}:cancel",t._url),s=t._query,delete t._url,delete t._query,await this.apiClient.request({path:r,queryParams:s,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal})}}async listInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o);const i=Ze(e,["filter"]);void 0!==t&&null!=i&&ze(t,["_query","filter"],i)}(n,t),t}(e);return s=We("batchPredictionJobs",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["batchPredictionJobs"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>mn(e))),ze(t,["batchJobs"],e)}return t}(e),n=new wt;return Object.assign(n,t),n})}{const t=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);if(void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o),void 0!==Ze(e,["filter"]))throw new Error("filter parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(n,t),t}(e);return s=We("batches",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["operations"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>dn(e))),ze(t,["batchJobs"],e)}return t}(e),n=new wt;return Object.assign(n,t),n})}}async delete(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);return s=We("batchPredictionJobs/{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["name"]);null!=o&&ze(t,["name"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);return null!=r&&ze(t,["error"],r),t}(e))}{const t=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);return s=We("batches/{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"DELETE",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["name"]);null!=o&&ze(t,["name"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);return null!=r&&ze(t,["error"],r),t}(e))}}};function En(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);null!=n&&ze(t,["mediaResolution"],n);const o=Ze(e,["toolCall"]);null!=o&&ze(t,["toolCall"],o);const i=Ze(e,["toolResponse"]);null!=i&&ze(t,["toolResponse"],i);const r=Ze(e,["audioTranscription"]);null!=r&&ze(t,["audioTranscription"],r);const s=Ze(e,["codeExecutionResult"]);null!=s&&ze(t,["codeExecutionResult"],s);const l=Ze(e,["executableCode"]);null!=l&&ze(t,["executableCode"],l);const a=Ze(e,["fileData"]);null!=a&&ze(t,["fileData"],function(e){const t={};if(void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["fileUri"]);null!=n&&ze(t,["fileUri"],n);const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(a));const u=Ze(e,["functionCall"]);null!=u&&ze(t,["functionCall"],function(e){const t={},n=Ze(e,["args"]);null!=n&&ze(t,["args"],n);const o=Ze(e,["id"]);null!=o&&ze(t,["id"],o);const i=Ze(e,["name"]);if(null!=i&&ze(t,["name"],i),void 0!==Ze(e,["partialArgs"]))throw new Error("partialArgs parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["willContinue"]))throw new Error("willContinue parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(u));const c=Ze(e,["functionResponse"]);null!=c&&ze(t,["functionResponse"],c);const p=Ze(e,["inlineData"]);null!=p&&ze(t,["inlineData"],function(e){const t={},n=Ze(e,["data"]);if(null!=n&&ze(t,["data"],n),void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(p));const d=Ze(e,["text"]);null!=d&&ze(t,["text"],d);const m=Ze(e,["thought"]);null!=m&&ze(t,["thought"],m);const f=Ze(e,["thoughtSignature"]);null!=f&&ze(t,["thoughtSignature"],f);const h=Ze(e,["videoMetadata"]);null!=h&&ze(t,["videoMetadata"],h);const g=Ze(e,["partMetadata"]);null!=g&&ze(t,["partMetadata"],g);const v=Ze(e,["mediaProcessing"]);return null!=v&&ze(t,["mediaProcessing"],v),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}function yn(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);if(null!=n&&ze(t,["mediaResolution"],n),void 0!==Ze(e,["toolCall"]))throw new Error("toolCall parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["toolResponse"]))throw new Error("toolResponse parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const o=Ze(e,["audioTranscription"]);null!=o&&ze(t,["audioTranscription"],o);const i=Ze(e,["codeExecutionResult"]);null!=i&&ze(t,["codeExecutionResult"],i);const r=Ze(e,["executableCode"]);null!=r&&ze(t,["executableCode"],r);const s=Ze(e,["fileData"]);null!=s&&ze(t,["fileData"],s);const l=Ze(e,["functionCall"]);null!=l&&ze(t,["functionCall"],l);const a=Ze(e,["functionResponse"]);null!=a&&ze(t,["functionResponse"],a);const u=Ze(e,["inlineData"]);null!=u&&ze(t,["inlineData"],u);const c=Ze(e,["text"]);null!=c&&ze(t,["text"],c);const p=Ze(e,["thought"]);null!=p&&ze(t,["thought"],p);const d=Ze(e,["thoughtSignature"]);null!=d&&ze(t,["thoughtSignature"],d);const m=Ze(e,["videoMetadata"]);if(null!=m&&ze(t,["videoMetadata"],m),void 0!==Ze(e,["partMetadata"]))throw new Error("partMetadata parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const f=Ze(e,["mediaProcessing"]);return null!=f&&ze(t,["mediaProcessing"],f),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}var An=class extends Ke{constructor(e){super(),this.apiClient=e,this.list=async(e={})=>new vn(nt.PAGED_ITEM_CACHED_CONTENTS,e=>this.listInternal(e),await this.listInternal(e),e)}async create(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["model"],kt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["ttl"]);void 0!==t&&null!=n&&ze(t,["ttl"],n);const o=Ze(e,["expireTime"]);void 0!==t&&null!=o&&ze(t,["expireTime"],o);const i=Ze(e,["displayName"]);void 0!==t&&null!=i&&ze(t,["displayName"],i);const r=Ze(e,["contents"]);if(void 0!==t&&null!=r){let e=Jt(r);Array.isArray(e)&&(e=e.map(e=>yn(e))),ze(t,["contents"],e)}const s=Ze(e,["systemInstruction"]);void 0!==t&&null!=s&&ze(t,["systemInstruction"],yn(Vt(s)));const l=Ze(e,["tools"]);if(void 0!==t&&null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["retrieval"]);null!=n&&ze(t,["retrieval"],n);const o=Ze(e,["googleMaps"]);null!=o&&ze(t,["googleMaps"],o);const i=Ze(e,["mcpServers"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>function(e){if(void 0!==Ze(e,["name"]))throw new Error("name parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["streamableHttpTransport"]))throw new Error("streamableHttpTransport parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return{}}(e))),ze(t,["mcpServers"],e)}const r=Ze(e,["codeExecution"]);null!=r&&ze(t,["codeExecution"],r);const s=Ze(e,["computerUse"]);null!=s&&ze(t,["computerUse"],function(e){const t={},n=Ze(e,["enablePromptInjectionDetection"]);null!=n&&ze(t,["enablePromptInjectionDetection"],n);const o=Ze(e,["environment"]);null!=o&&ze(t,["environment"],o);const i=Ze(e,["excludedPredefinedFunctions"]);if(null!=i&&ze(t,["excludedPredefinedFunctions"],i),void 0!==Ze(e,["disabledSafetyPolicies"]))throw new Error("disabledSafetyPolicies parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(s));const l=Ze(e,["enterpriseWebSearch"]);null!=l&&ze(t,["enterpriseWebSearch"],l);const a=Ze(e,["exaAiSearch"]);null!=a&&ze(t,["exaAiSearch"],a);const u=Ze(e,["functionDeclarations"]);if(null!=u){let e=u;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const c=Ze(e,["googleSearch"]);null!=c&&ze(t,["googleSearch"],c);const p=Ze(e,["googleSearchRetrieval"]);null!=p&&ze(t,["googleSearchRetrieval"],p);const d=Ze(e,["parallelAiSearch"]);null!=d&&ze(t,["parallelAiSearch"],d);const m=Ze(e,["urlContext"]);if(null!=m&&ze(t,["urlContext"],m),void 0!==Ze(e,["fileSearch"]))throw new Error("fileSearch parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(e))),ze(t,["tools"],e)}const a=Ze(e,["toolConfig"]);void 0!==t&&null!=a&&ze(t,["toolConfig"],function(e){const t={},n=Ze(e,["functionCallingConfig"]);null!=n&&ze(t,["functionCallingConfig"],n);const o=Ze(e,["retrievalConfig"]);if(null!=o&&ze(t,["retrievalConfig"],o),void 0!==Ze(e,["includeServerSideToolInvocations"]))throw new Error("includeServerSideToolInvocations parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(a));const u=Ze(e,["kmsKeyName"]);void 0!==t&&null!=u&&ze(t,["encryption_spec","kmsKeyName"],u)}(i,n),n}(this.apiClient,e);return s=We("cachedContents",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>e)}{const t=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["model"],kt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["ttl"]);void 0!==t&&null!=n&&ze(t,["ttl"],n);const o=Ze(e,["expireTime"]);void 0!==t&&null!=o&&ze(t,["expireTime"],o);const i=Ze(e,["displayName"]);void 0!==t&&null!=i&&ze(t,["displayName"],i);const r=Ze(e,["contents"]);if(void 0!==t&&null!=r){let e=Jt(r);Array.isArray(e)&&(e=e.map(e=>En(e))),ze(t,["contents"],e)}const s=Ze(e,["systemInstruction"]);void 0!==t&&null!=s&&ze(t,["systemInstruction"],En(Vt(s)));const l=Ze(e,["tools"]);if(void 0!==t&&null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==Ze(e,["retrieval"]))throw new Error("retrieval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["googleMaps"]);null!=n&&ze(t,["googleMaps"],function(e){const t={},n=Ze(e,["authConfig"]);null!=n&&ze(t,["authConfig"],function(e){const t={},n=Ze(e,["apiKey"]);if(null!=n&&ze(t,["apiKey"],n),void 0!==Ze(e,["apiKeyConfig"]))throw new Error("apiKeyConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["authType"]))throw new Error("authType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["googleServiceAccountConfig"]))throw new Error("googleServiceAccountConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["httpBasicAuthConfig"]))throw new Error("httpBasicAuthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oauthConfig"]))throw new Error("oauthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oidcConfig"]))throw new Error("oidcConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["enableWidget"]);if(null!=o&&ze(t,["enableWidget"],o),void 0!==Ze(e,["groundingTypes"]))throw new Error("groundingTypes parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["mcpServers"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mcpServers"],e)}const i=Ze(e,["codeExecution"]);null!=i&&ze(t,["codeExecution"],i);const r=Ze(e,["computerUse"]);if(null!=r&&ze(t,["computerUse"],r),void 0!==Ze(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["exaAiSearch"]))throw new Error("exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const s=Ze(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const l=Ze(e,["googleSearch"]);null!=l&&ze(t,["googleSearch"],function(e){const t={};if(void 0!==Ze(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["excludeDomains"]))throw new Error("excludeDomains parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["searchTypes"]);null!=n&&ze(t,["searchTypes"],n);const o=Ze(e,["timeRangeFilter"]);return null!=o&&ze(t,["timeRangeFilter"],o),t}(l));const a=Ze(e,["googleSearchRetrieval"]);if(null!=a&&ze(t,["googleSearchRetrieval"],a),void 0!==Ze(e,["parallelAiSearch"]))throw new Error("parallelAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["urlContext"]);null!=u&&ze(t,["urlContext"],u);const c=Ze(e,["fileSearch"]);return null!=c&&ze(t,["fileSearch"],c),t}(e))),ze(t,["tools"],e)}const a=Ze(e,["toolConfig"]);if(void 0!==t&&null!=a&&ze(t,["toolConfig"],function(e){const t={},n=Ze(e,["functionCallingConfig"]);null!=n&&ze(t,["functionCallingConfig"],function(e){const t={},n=Ze(e,["allowedFunctionNames"]);null!=n&&ze(t,["allowedFunctionNames"],n);const o=Ze(e,["mode"]);if(null!=o&&ze(t,["mode"],o),void 0!==Ze(e,["streamFunctionCallArguments"]))throw new Error("streamFunctionCallArguments parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["retrievalConfig"]);null!=o&&ze(t,["retrievalConfig"],o);const i=Ze(e,["includeServerSideToolInvocations"]);return null!=i&&ze(t,["includeServerSideToolInvocations"],i),t}(a)),void 0!==Ze(e,["kmsKeyName"]))throw new Error("kmsKeyName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(i,n),n}(this.apiClient,e);return s=We("cachedContents",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>e)}}async get(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],Qt(e,o)),n}(this.apiClient,e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>e)}{const t=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],Qt(e,o)),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>e)}}async delete(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],Qt(e,o)),n}(this.apiClient,e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new Et;return Object.assign(n,t),n})}{const t=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],Qt(e,o)),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"DELETE",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new Et;return Object.assign(n,t),n})}}async update(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);null!=o&&ze(n,["_url","name"],Qt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["ttl"]);void 0!==t&&null!=n&&ze(t,["ttl"],n);const o=Ze(e,["expireTime"]);void 0!==t&&null!=o&&ze(t,["expireTime"],o)}(i,n),n}(this.apiClient,e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(o),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()),r.then(e=>e)}{const t=function(e,t){const n={},o=Ze(t,["name"]);null!=o&&ze(n,["_url","name"],Qt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["ttl"]);void 0!==t&&null!=n&&ze(t,["ttl"],n);const o=Ze(e,["expireTime"]);void 0!==t&&null!=o&&ze(t,["expireTime"],o)}(i,n),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"PATCH",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>e)}}async listInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o)}(n,t),t}(e);return s=We("cachedContents",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["cachedContents"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["cachedContents"],e)}return t}(e),n=new yt;return Object.assign(n,t),n})}{const t=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o)}(n,t),t}(e);return s=We("cachedContents",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["cachedContents"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["cachedContents"],e)}return t}(e),n=new yt;return Object.assign(n,t),n})}}};function In(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n}function Tn(e){return this instanceof Tn?(this.v=e,this):new Tn(e)}function Cn(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,i=n.apply(e,t||[]),r=[];return o=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",function(e){return function(t){return Promise.resolve(t).then(e,u)}}),o[Symbol.asyncIterator]=function(){return this},o;function s(e,t){i[e]&&(o[e]=function(t){return new Promise(function(n,o){r.push([e,t,n,o])>1||l(e,t)})},t&&(o[e]=t(o[e])))}function l(e,t){try{(n=i[e](t)).value instanceof Tn?Promise.resolve(n.value.v).then(a,u):c(r[0][2],n)}catch(o){c(r[0][3],o)}var n}function a(e){l("next",e)}function u(e){l("throw",e)}function c(e,t){e(t),r.shift(),r.length&&l(r[0][0],r[0][1])}}function Sn(e){if(!Symbol.asyncIterator)throw new 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],o=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(e),t={},o("next"),o("throw"),o("return"),t[Symbol.asyncIterator]=function(){return this},t);function o(n){t[n]=e[n]&&function(t){return new Promise(function(o,i){!function(e,t,n,o){Promise.resolve(o).then(function(t){e({value:t,done:n})},t)}(o,i,(t=e[n](t)).done,t.value)})}}}function On(e){var t;if(null==e.candidates||0===e.candidates.length)return!1;const n=null===(t=e.candidates[0])||void 0===t?void 0:t.content;return void 0!==n&&bn(n)}function bn(e){if(void 0===e.parts||0===e.parts.length)return!1;for(const t of e.parts)if(void 0===t||0===Object.keys(t).length)return!1;return!0}function Pn(e){if(void 0===e||0===e.length)return[];const t=[],n=e.length;let o=0;for(;o<n;)if("user"===e[o].role)t.push(e[o]),o++;else{const i=[];let r=!0;for(;o<n&&"model"===e[o].role;)i.push(e[o]),r&&!bn(e[o])&&(r=!1),o++;r?t.push(...i):t.pop()}return t}var wn=class{constructor(e,t){this.modelsModule=e,this.apiClient=t}create(e){return new Rn(this.apiClient,this.modelsModule,e.model,e.config,structuredClone(e.history))}},Rn=class{constructor(e,t,n,o={},i=[]){this.apiClient=e,this.modelsModule=t,this.model=n,this.config=o,this.history=i,this.sendPromise=Promise.resolve(),function(e){if(0!==e.length)for(const t of e)if("user"!==t.role&&"model"!==t.role)throw new Error(`Role must be user or model, but got ${t.role}.`)}(i)}async sendMessage(e){var t;await this.sendPromise;const n=Vt(e.message),o=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,i;const r=await o,s=null===(t=null===(e=r.candidates)||void 0===e?void 0:e[0])||void 0===t?void 0:t.content,l=r.automaticFunctionCallingHistory,a=this.getHistory(!0).length;let u=[];null!=l&&(u=null!==(i=l.slice(a))&&void 0!==i?i:[]);const c=s?[s]:[];this.recordHistory(n,c,u)})(),await this.sendPromise.catch(()=>{this.sendPromise=Promise.resolve()}),o}async sendMessageStream(e){var t;await this.sendPromise;const n=Vt(e.message),o=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=o.then(()=>{}).catch(()=>{});const i=await o;return this.processStreamResponse(i,n)}getHistory(e=!1){const t=e?Pn(this.history):this.history;return structuredClone(t)}processStreamResponse(e,t){return Cn(this,arguments,function*(){var n,o,i,r,s,l;const a=[];try{for(var u,c=!0,p=Sn(e);!(n=(u=yield Tn(p.next())).done);c=!0){r=u.value,c=!1;const e=r;if(On(e)){const t=null===(l=null===(s=e.candidates)||void 0===s?void 0:s[0])||void 0===l?void 0:l.content;void 0!==t&&a.push(t)}yield yield Tn(e)}}catch(d){o={error:d}}finally{try{c||n||!(i=p.return)||(yield Tn(i.call(p)))}finally{if(o)throw o.error}}this.recordHistory(t,a)})}recordHistory(e,t,n){let o=[];t.length>0&&t.every(e=>void 0!==e.role)?o=t:o.push({role:"model",parts:[]}),n&&n.length>0?this.history.push(...Pn(n)):this.history.push(e),this.history.push(...o)}},Nn=class e extends Error{constructor(t){super(t.message),this.name="ApiError",this.status=t.status,Object.setPrototypeOf(this,e.prototype)}};var Dn=class extends Ke{constructor(e){super(),this.apiClient=e,this.list=async(e={})=>new vn(nt.PAGED_ITEM_FILES,e=>this.listInternal(e),await this.listInternal(e),e)}async upload(e){if(this.apiClient.isVertexAI())throw new Error("Gemini Enterprise Agent Platform (previously known as 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 registerFiles(e){throw new Error("registerFiles is only supported in Node.js environments.")}async _registerFiles(e){return this.registerFilesInternal(e)}async listInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o)}(n,t),t}(e);return i=We("files",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["files"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["files"],e)}return t}(e),n=new St;return Object.assign(n,t),n})}}async createInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["file"]);return null!=n&&ze(t,["file"],n),t}(e);return i=We("upload/v1beta/files",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new Ot;return Object.assign(n,t),n})}}async get(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","file"],nn(n)),t}(e);return i=We("files/{file}",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>e)}}async delete(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","file"],nn(n)),t}(e);return i=We("files/{file}",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new bt;return Object.assign(n,t),n})}}async registerFilesInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["uris"]);return null!=n&&ze(t,["uris"],n),t}(e);return i=We("files:register",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["files"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["files"],e)}return t}(e),n=new Pt;return Object.assign(n,t),n})}}};function Gn(e){const t={},n=Ze(e,["data"]);if(null!=n&&ze(t,["data"],n),void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}function kn(e,t){const n=Ze(e,["generationConfig"]);void 0!==t&&null!=n&&ze(t,["setup","generationConfig"],n);const o=Ze(e,["responseModalities"]);void 0!==t&&null!=o&&ze(t,["setup","generationConfig","responseModalities"],o);const i=Ze(e,["temperature"]);void 0!==t&&null!=i&&ze(t,["setup","generationConfig","temperature"],i);const r=Ze(e,["topP"]);void 0!==t&&null!=r&&ze(t,["setup","generationConfig","topP"],r);const s=Ze(e,["topK"]);void 0!==t&&null!=s&&ze(t,["setup","generationConfig","topK"],s);const l=Ze(e,["maxOutputTokens"]);void 0!==t&&null!=l&&ze(t,["setup","generationConfig","maxOutputTokens"],l);const a=Ze(e,["mediaResolution"]);void 0!==t&&null!=a&&ze(t,["setup","generationConfig","mediaResolution"],a);const u=Ze(e,["seed"]);void 0!==t&&null!=u&&ze(t,["setup","generationConfig","seed"],u);const c=Ze(e,["speechConfig"]);void 0!==t&&null!=c&&ze(t,["setup","generationConfig","speechConfig"],Wt(c));const p=Ze(e,["thinkingConfig"]);void 0!==t&&null!=p&&ze(t,["setup","generationConfig","thinkingConfig"],p);const d=Ze(e,["enableAffectiveDialog"]);void 0!==t&&null!=d&&ze(t,["setup","generationConfig","enableAffectiveDialog"],d);const m=Ze(e,["systemInstruction"]);void 0!==t&&null!=m&&ze(t,["setup","systemInstruction"],function(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);null!=n&&ze(t,["mediaResolution"],n);const o=Ze(e,["toolCall"]);null!=o&&ze(t,["toolCall"],o);const i=Ze(e,["toolResponse"]);null!=i&&ze(t,["toolResponse"],i);const r=Ze(e,["audioTranscription"]);null!=r&&ze(t,["audioTranscription"],r);const s=Ze(e,["codeExecutionResult"]);null!=s&&ze(t,["codeExecutionResult"],s);const l=Ze(e,["executableCode"]);null!=l&&ze(t,["executableCode"],l);const a=Ze(e,["fileData"]);null!=a&&ze(t,["fileData"],function(e){const t={};if(void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["fileUri"]);null!=n&&ze(t,["fileUri"],n);const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(a));const u=Ze(e,["functionCall"]);null!=u&&ze(t,["functionCall"],function(e){const t={},n=Ze(e,["args"]);null!=n&&ze(t,["args"],n);const o=Ze(e,["id"]);null!=o&&ze(t,["id"],o);const i=Ze(e,["name"]);if(null!=i&&ze(t,["name"],i),void 0!==Ze(e,["partialArgs"]))throw new Error("partialArgs parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["willContinue"]))throw new Error("willContinue parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(u));const c=Ze(e,["functionResponse"]);null!=c&&ze(t,["functionResponse"],c);const p=Ze(e,["inlineData"]);null!=p&&ze(t,["inlineData"],Gn(p));const d=Ze(e,["text"]);null!=d&&ze(t,["text"],d);const m=Ze(e,["thought"]);null!=m&&ze(t,["thought"],m);const f=Ze(e,["thoughtSignature"]);null!=f&&ze(t,["thoughtSignature"],f);const h=Ze(e,["videoMetadata"]);null!=h&&ze(t,["videoMetadata"],h);const g=Ze(e,["partMetadata"]);null!=g&&ze(t,["partMetadata"],g);const v=Ze(e,["mediaProcessing"]);return null!=v&&ze(t,["mediaProcessing"],v),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}(Vt(m)));const f=Ze(e,["tools"]);if(void 0!==t&&null!=f){let e=Zt(f);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==Ze(e,["retrieval"]))throw new Error("retrieval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["googleMaps"]);null!=n&&ze(t,["googleMaps"],function(e){const t={},n=Ze(e,["authConfig"]);null!=n&&ze(t,["authConfig"],function(e){const t={},n=Ze(e,["apiKey"]);if(null!=n&&ze(t,["apiKey"],n),void 0!==Ze(e,["apiKeyConfig"]))throw new Error("apiKeyConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["authType"]))throw new Error("authType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["googleServiceAccountConfig"]))throw new Error("googleServiceAccountConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["httpBasicAuthConfig"]))throw new Error("httpBasicAuthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oauthConfig"]))throw new Error("oauthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oidcConfig"]))throw new Error("oidcConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["enableWidget"]);if(null!=o&&ze(t,["enableWidget"],o),void 0!==Ze(e,["groundingTypes"]))throw new Error("groundingTypes parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["mcpServers"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mcpServers"],e)}const i=Ze(e,["codeExecution"]);null!=i&&ze(t,["codeExecution"],i);const r=Ze(e,["computerUse"]);if(null!=r&&ze(t,["computerUse"],r),void 0!==Ze(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["exaAiSearch"]))throw new Error("exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const s=Ze(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const l=Ze(e,["googleSearch"]);null!=l&&ze(t,["googleSearch"],function(e){const t={};if(void 0!==Ze(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["excludeDomains"]))throw new Error("excludeDomains parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["searchTypes"]);null!=n&&ze(t,["searchTypes"],n);const o=Ze(e,["timeRangeFilter"]);return null!=o&&ze(t,["timeRangeFilter"],o),t}(l));const a=Ze(e,["googleSearchRetrieval"]);if(null!=a&&ze(t,["googleSearchRetrieval"],a),void 0!==Ze(e,["parallelAiSearch"]))throw new Error("parallelAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["urlContext"]);null!=u&&ze(t,["urlContext"],u);const c=Ze(e,["fileSearch"]);return null!=c&&ze(t,["fileSearch"],c),t}(zt(e)))),ze(t,["setup","tools"],e)}const h=Ze(e,["sessionResumption"]);void 0!==t&&null!=h&&ze(t,["setup","sessionResumption"],function(e){const t={},n=Ze(e,["handle"]);if(null!=n&&ze(t,["handle"],n),void 0!==Ze(e,["transparent"]))throw new Error("transparent parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(h));const g=Ze(e,["inputAudioTranscription"]);void 0!==t&&null!=g&&ze(t,["setup","inputAudioTranscription"],g);const v=Ze(e,["outputAudioTranscription"]);void 0!==t&&null!=v&&ze(t,["setup","outputAudioTranscription"],v);const _=Ze(e,["realtimeInputConfig"]);void 0!==t&&null!=_&&ze(t,["setup","realtimeInputConfig"],_);const E=Ze(e,["contextWindowCompression"]);void 0!==t&&null!=E&&ze(t,["setup","contextWindowCompression"],E);const y=Ze(e,["proactivity"]);if(void 0!==t&&null!=y&&ze(t,["setup","proactivity"],y),void 0!==Ze(e,["explicitVadSignal"]))throw new Error("explicitVadSignal parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const A=Ze(e,["avatarConfig"]);void 0!==t&&null!=A&&ze(t,["setup","avatarConfig"],A);const I=Ze(e,["safetySettings"]);if(void 0!==t&&null!=I){let e=I;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["category"]);if(null!=n&&ze(t,["category"],n),void 0!==Ze(e,["method"]))throw new Error("method parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["threshold"]);return null!=o&&ze(t,["threshold"],o),t}(e))),ze(t,["setup","safetySettings"],e)}const T=Ze(e,["translationConfig"]);return void 0!==t&&null!=T&&ze(t,["setup","generationConfig","translationConfig"],T),{}}function Mn(e,t){const n=Ze(e,["generationConfig"]);void 0!==t&&null!=n&&ze(t,["setup","generationConfig"],function(e){const t={},n=Ze(e,["modelSelectionConfig"]);null!=n&&ze(t,["modelConfig"],n);const o=Ze(e,["responseJsonSchema"]);null!=o&&ze(t,["responseJsonSchema"],o);const i=Ze(e,["audioTranscriptionConfig"]);null!=i&&ze(t,["audioTranscriptionConfig"],i);const r=Ze(e,["audioTimestamp"]);null!=r&&ze(t,["audioTimestamp"],r);const s=Ze(e,["candidateCount"]);null!=s&&ze(t,["candidateCount"],s);const l=Ze(e,["enableAffectiveDialog"]);null!=l&&ze(t,["enableAffectiveDialog"],l);const a=Ze(e,["frequencyPenalty"]);null!=a&&ze(t,["frequencyPenalty"],a);const u=Ze(e,["logprobs"]);null!=u&&ze(t,["logprobs"],u);const c=Ze(e,["maxOutputTokens"]);null!=c&&ze(t,["maxOutputTokens"],c);const p=Ze(e,["mediaResolution"]);null!=p&&ze(t,["mediaResolution"],p);const d=Ze(e,["presencePenalty"]);null!=d&&ze(t,["presencePenalty"],d);const m=Ze(e,["responseFormat"]);if(null!=m){let e=m;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["responseFormat"],e)}const f=Ze(e,["responseLogprobs"]);null!=f&&ze(t,["responseLogprobs"],f);const h=Ze(e,["responseMimeType"]);null!=h&&ze(t,["responseMimeType"],h);const g=Ze(e,["responseModalities"]);null!=g&&ze(t,["responseModalities"],g);const v=Ze(e,["responseSchema"]);null!=v&&ze(t,["responseSchema"],v);const _=Ze(e,["routingConfig"]);null!=_&&ze(t,["routingConfig"],_);const E=Ze(e,["seed"]);null!=E&&ze(t,["seed"],E);const y=Ze(e,["speechConfig"]);null!=y&&ze(t,["speechConfig"],Ln(y));const A=Ze(e,["stopSequences"]);null!=A&&ze(t,["stopSequences"],A);const I=Ze(e,["temperature"]);null!=I&&ze(t,["temperature"],I);const T=Ze(e,["thinkingConfig"]);null!=T&&ze(t,["thinkingConfig"],T);const C=Ze(e,["topK"]);null!=C&&ze(t,["topK"],C);const S=Ze(e,["topP"]);if(null!=S&&ze(t,["topP"],S),void 0!==Ze(e,["enableEnhancedCivicAnswers"]))throw new Error("enableEnhancedCivicAnswers parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["translationConfig"]))throw new Error("translationConfig parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(n));const o=Ze(e,["responseModalities"]);void 0!==t&&null!=o&&ze(t,["setup","generationConfig","responseModalities"],o);const i=Ze(e,["temperature"]);void 0!==t&&null!=i&&ze(t,["setup","generationConfig","temperature"],i);const r=Ze(e,["topP"]);void 0!==t&&null!=r&&ze(t,["setup","generationConfig","topP"],r);const s=Ze(e,["topK"]);void 0!==t&&null!=s&&ze(t,["setup","generationConfig","topK"],s);const l=Ze(e,["maxOutputTokens"]);void 0!==t&&null!=l&&ze(t,["setup","generationConfig","maxOutputTokens"],l);const a=Ze(e,["mediaResolution"]);void 0!==t&&null!=a&&ze(t,["setup","generationConfig","mediaResolution"],a);const u=Ze(e,["seed"]);void 0!==t&&null!=u&&ze(t,["setup","generationConfig","seed"],u);const c=Ze(e,["speechConfig"]);void 0!==t&&null!=c&&ze(t,["setup","generationConfig","speechConfig"],Ln(Wt(c)));const p=Ze(e,["thinkingConfig"]);void 0!==t&&null!=p&&ze(t,["setup","generationConfig","thinkingConfig"],p);const d=Ze(e,["enableAffectiveDialog"]);void 0!==t&&null!=d&&ze(t,["setup","generationConfig","enableAffectiveDialog"],d);const m=Ze(e,["systemInstruction"]);void 0!==t&&null!=m&&ze(t,["setup","systemInstruction"],function(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);if(null!=n&&ze(t,["mediaResolution"],n),void 0!==Ze(e,["toolCall"]))throw new Error("toolCall parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["toolResponse"]))throw new Error("toolResponse parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const o=Ze(e,["audioTranscription"]);null!=o&&ze(t,["audioTranscription"],o);const i=Ze(e,["codeExecutionResult"]);null!=i&&ze(t,["codeExecutionResult"],i);const r=Ze(e,["executableCode"]);null!=r&&ze(t,["executableCode"],r);const s=Ze(e,["fileData"]);null!=s&&ze(t,["fileData"],s);const l=Ze(e,["functionCall"]);null!=l&&ze(t,["functionCall"],l);const a=Ze(e,["functionResponse"]);null!=a&&ze(t,["functionResponse"],a);const u=Ze(e,["inlineData"]);null!=u&&ze(t,["inlineData"],u);const c=Ze(e,["text"]);null!=c&&ze(t,["text"],c);const p=Ze(e,["thought"]);null!=p&&ze(t,["thought"],p);const d=Ze(e,["thoughtSignature"]);null!=d&&ze(t,["thoughtSignature"],d);const m=Ze(e,["videoMetadata"]);if(null!=m&&ze(t,["videoMetadata"],m),void 0!==Ze(e,["partMetadata"]))throw new Error("partMetadata parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const f=Ze(e,["mediaProcessing"]);return null!=f&&ze(t,["mediaProcessing"],f),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}(Vt(m)));const f=Ze(e,["tools"]);if(void 0!==t&&null!=f){let e=Zt(f);Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["retrieval"]);null!=n&&ze(t,["retrieval"],n);const o=Ze(e,["googleMaps"]);null!=o&&ze(t,["googleMaps"],o);const i=Ze(e,["mcpServers"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>function(e){if(void 0!==Ze(e,["name"]))throw new Error("name parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["streamableHttpTransport"]))throw new Error("streamableHttpTransport parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return{}}(e))),ze(t,["mcpServers"],e)}const r=Ze(e,["codeExecution"]);null!=r&&ze(t,["codeExecution"],r);const s=Ze(e,["computerUse"]);null!=s&&ze(t,["computerUse"],function(e){const t={},n=Ze(e,["enablePromptInjectionDetection"]);null!=n&&ze(t,["enablePromptInjectionDetection"],n);const o=Ze(e,["environment"]);null!=o&&ze(t,["environment"],o);const i=Ze(e,["excludedPredefinedFunctions"]);if(null!=i&&ze(t,["excludedPredefinedFunctions"],i),void 0!==Ze(e,["disabledSafetyPolicies"]))throw new Error("disabledSafetyPolicies parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(s));const l=Ze(e,["enterpriseWebSearch"]);null!=l&&ze(t,["enterpriseWebSearch"],l);const a=Ze(e,["exaAiSearch"]);null!=a&&ze(t,["exaAiSearch"],a);const u=Ze(e,["functionDeclarations"]);if(null!=u){let e=u;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const c=Ze(e,["googleSearch"]);null!=c&&ze(t,["googleSearch"],c);const p=Ze(e,["googleSearchRetrieval"]);null!=p&&ze(t,["googleSearchRetrieval"],p);const d=Ze(e,["parallelAiSearch"]);null!=d&&ze(t,["parallelAiSearch"],d);const m=Ze(e,["urlContext"]);if(null!=m&&ze(t,["urlContext"],m),void 0!==Ze(e,["fileSearch"]))throw new Error("fileSearch parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(zt(e)))),ze(t,["setup","tools"],e)}const h=Ze(e,["sessionResumption"]);void 0!==t&&null!=h&&ze(t,["setup","sessionResumption"],h);const g=Ze(e,["inputAudioTranscription"]);void 0!==t&&null!=g&&ze(t,["setup","inputAudioTranscription"],g);const v=Ze(e,["outputAudioTranscription"]);void 0!==t&&null!=v&&ze(t,["setup","outputAudioTranscription"],v);const _=Ze(e,["realtimeInputConfig"]);void 0!==t&&null!=_&&ze(t,["setup","realtimeInputConfig"],_);const E=Ze(e,["contextWindowCompression"]);void 0!==t&&null!=E&&ze(t,["setup","contextWindowCompression"],E);const y=Ze(e,["proactivity"]);void 0!==t&&null!=y&&ze(t,["setup","proactivity"],y);const A=Ze(e,["explicitVadSignal"]);void 0!==t&&null!=A&&ze(t,["setup","explicitVadSignal"],A);const I=Ze(e,["avatarConfig"]);void 0!==t&&null!=I&&ze(t,["setup","avatarConfig"],I);const T=Ze(e,["safetySettings"]);if(void 0!==t&&null!=T){let e=T;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["setup","safetySettings"],e)}const C=Ze(e,["translationConfig"]);return void 0!==t&&null!=C&&ze(t,["setup","generationConfig","translationConfig"],C),{}}function xn(e){const t={},n=Ze(e,["media"]);if(null!=n){let e=Mt(n);Array.isArray(e)&&(e=e.map(e=>Gn(e))),ze(t,["mediaChunks"],e)}const o=Ze(e,["audio"]);null!=o&&ze(t,["audio"],Gn(Lt(o)));const i=Ze(e,["audioStreamEnd"]);null!=i&&ze(t,["audioStreamEnd"],i);const r=Ze(e,["video"]);null!=r&&ze(t,["video"],Gn(Ut(r)));const s=Ze(e,["text"]);null!=s&&ze(t,["text"],s);const l=Ze(e,["activityStart"]);null!=l&&ze(t,["activityStart"],l);const a=Ze(e,["activityEnd"]);return null!=a&&ze(t,["activityEnd"],a),t}function Un(e){const t={},n=Ze(e,["media"]);if(null!=n){let e=Mt(n);Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mediaChunks"],e)}const o=Ze(e,["audio"]);null!=o&&ze(t,["audio"],Lt(o));const i=Ze(e,["audioStreamEnd"]);null!=i&&ze(t,["audioStreamEnd"],i);const r=Ze(e,["video"]);null!=r&&ze(t,["video"],Ut(r));const s=Ze(e,["text"]);null!=s&&ze(t,["text"],s);const l=Ze(e,["activityStart"]);null!=l&&ze(t,["activityStart"],l);const a=Ze(e,["activityEnd"]);return null!=a&&ze(t,["activityEnd"],a),t}function Ln(e){const t={},n=Ze(e,["voiceConfig"]);null!=n&&ze(t,["voiceConfig"],qn(n));const o=Ze(e,["languageCode"]);null!=o&&ze(t,["languageCode"],o);const i=Ze(e,["multiSpeakerVoiceConfig"]);return null!=i&&ze(t,["multiSpeakerVoiceConfig"],function(e){const t={},n=Ze(e,["speakerVoiceConfigs"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["speaker"]);null!=n&&ze(t,["speaker"],n);const o=Ze(e,["voiceConfig"]);return null!=o&&ze(t,["voiceConfig"],qn(o)),t}(e))),ze(t,["speakerVoiceConfigs"],e)}return t}(i)),t}function qn(e){const t={},n=Ze(e,["replicatedVoiceConfig"]);null!=n&&ze(t,["replicatedVoiceConfig"],function(e){const t={},n=Ze(e,["mimeType"]);null!=n&&ze(t,["mimeType"],n);const o=Ze(e,["voiceSampleAudio"]);if(null!=o&&ze(t,["voiceSampleAudio"],o),void 0!==Ze(e,["consentAudio"]))throw new Error("consentAudio parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["voiceConsentSignature"]))throw new Error("voiceConsentSignature parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(n));const o=Ze(e,["prebuiltVoiceConfig"]);return null!=o&&ze(t,["prebuiltVoiceConfig"],o),t}function Hn(e,t){const n={},o=Ze(e,["parts"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);null!=n&&ze(t,["mediaResolution"],n);const o=Ze(e,["toolCall"]);null!=o&&ze(t,["toolCall"],o);const i=Ze(e,["toolResponse"]);null!=i&&ze(t,["toolResponse"],i);const r=Ze(e,["audioTranscription"]);null!=r&&ze(t,["audioTranscription"],r);const s=Ze(e,["codeExecutionResult"]);null!=s&&ze(t,["codeExecutionResult"],s);const l=Ze(e,["executableCode"]);null!=l&&ze(t,["executableCode"],l);const a=Ze(e,["fileData"]);null!=a&&ze(t,["fileData"],function(e){const t={};if(void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["fileUri"]);null!=n&&ze(t,["fileUri"],n);const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(a));const u=Ze(e,["functionCall"]);null!=u&&ze(t,["functionCall"],function(e){const t={},n=Ze(e,["args"]);null!=n&&ze(t,["args"],n);const o=Ze(e,["id"]);null!=o&&ze(t,["id"],o);const i=Ze(e,["name"]);if(null!=i&&ze(t,["name"],i),void 0!==Ze(e,["partialArgs"]))throw new Error("partialArgs parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["willContinue"]))throw new Error("willContinue parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(u));const c=Ze(e,["functionResponse"]);null!=c&&ze(t,["functionResponse"],c);const p=Ze(e,["inlineData"]);null!=p&&ze(t,["inlineData"],function(e){const t={},n=Ze(e,["data"]);if(null!=n&&ze(t,["data"],n),void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(p));const d=Ze(e,["text"]);null!=d&&ze(t,["text"],d);const m=Ze(e,["thought"]);null!=m&&ze(t,["thought"],m);const f=Ze(e,["thoughtSignature"]);null!=f&&ze(t,["thoughtSignature"],f);const h=Ze(e,["videoMetadata"]);null!=h&&ze(t,["videoMetadata"],h);const g=Ze(e,["partMetadata"]);null!=g&&ze(t,["partMetadata"],g);const v=Ze(e,["mediaProcessing"]);return null!=v&&ze(t,["mediaProcessing"],v),t}(e))),ze(n,["parts"],e)}const i=Ze(e,["role"]);return null!=i&&ze(n,["role"],i),n}function Fn(e,t){const n={},o=Ze(e,["parts"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);if(null!=n&&ze(t,["mediaResolution"],n),void 0!==Ze(e,["toolCall"]))throw new Error("toolCall parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["toolResponse"]))throw new Error("toolResponse parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const o=Ze(e,["audioTranscription"]);null!=o&&ze(t,["audioTranscription"],o);const i=Ze(e,["codeExecutionResult"]);null!=i&&ze(t,["codeExecutionResult"],i);const r=Ze(e,["executableCode"]);null!=r&&ze(t,["executableCode"],r);const s=Ze(e,["fileData"]);null!=s&&ze(t,["fileData"],s);const l=Ze(e,["functionCall"]);null!=l&&ze(t,["functionCall"],l);const a=Ze(e,["functionResponse"]);null!=a&&ze(t,["functionResponse"],a);const u=Ze(e,["inlineData"]);null!=u&&ze(t,["inlineData"],u);const c=Ze(e,["text"]);null!=c&&ze(t,["text"],c);const p=Ze(e,["thought"]);null!=p&&ze(t,["thought"],p);const d=Ze(e,["thoughtSignature"]);null!=d&&ze(t,["thoughtSignature"],d);const m=Ze(e,["videoMetadata"]);if(null!=m&&ze(t,["videoMetadata"],m),void 0!==Ze(e,["partMetadata"]))throw new Error("partMetadata parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const f=Ze(e,["mediaProcessing"]);return null!=f&&ze(t,["mediaProcessing"],f),t}(e))),ze(n,["parts"],e)}const i=Ze(e,["role"]);return null!=i&&ze(n,["role"],i),n}function jn(e,t,n){const o={},i=Ze(t,["model"]);null!=i&&ze(o,["_url","model"],Gt(e,i));const r=Ze(t,["contents"]);if(null!=r){let e=Jt(r);Array.isArray(e)&&(e=e.map(e=>Hn(e))),ze(o,["contents"],e)}const s=Ze(t,["config"]);return null!=s&&ze(o,["generationConfig"],function(e,t,n){const o={},i=Ze(t,["serviceTier"]);void 0!==n&&null!=i&&ze(n,["serviceTier"],i);const r=Ze(t,["systemInstruction"]);void 0!==n&&null!=r&&ze(n,["systemInstruction"],Hn(Vt(r)));const s=Ze(t,["temperature"]);null!=s&&ze(o,["temperature"],s);const l=Ze(t,["topP"]);null!=l&&ze(o,["topP"],l);const a=Ze(t,["topK"]);null!=a&&ze(o,["topK"],a);const u=Ze(t,["candidateCount"]);null!=u&&ze(o,["candidateCount"],u);const c=Ze(t,["maxOutputTokens"]);null!=c&&ze(o,["maxOutputTokens"],c);const p=Ze(t,["stopSequences"]);null!=p&&ze(o,["stopSequences"],p);const d=Ze(t,["responseLogprobs"]);null!=d&&ze(o,["responseLogprobs"],d);const m=Ze(t,["logprobs"]);null!=m&&ze(o,["logprobs"],m);const f=Ze(t,["presencePenalty"]);null!=f&&ze(o,["presencePenalty"],f);const h=Ze(t,["frequencyPenalty"]);null!=h&&ze(o,["frequencyPenalty"],h);const g=Ze(t,["seed"]);null!=g&&ze(o,["seed"],g);const v=Ze(t,["responseMimeType"]);null!=v&&ze(o,["responseMimeType"],v);const _=Ze(t,["responseSchema"]);null!=_&&ze(o,["responseSchema"],$t(_));const E=Ze(t,["responseJsonSchema"]);if(null!=E&&ze(o,["responseJsonSchema"],E),void 0!==Ze(t,["routingConfig"]))throw new Error("routingConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(t,["modelSelectionConfig"]))throw new Error("modelSelectionConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const y=Ze(t,["safetySettings"]);if(void 0!==n&&null!=y){let e=y;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["category"]);if(null!=n&&ze(t,["category"],n),void 0!==Ze(e,["method"]))throw new Error("method parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["threshold"]);return null!=o&&ze(t,["threshold"],o),t}(e))),ze(n,["safetySettings"],e)}const A=Ze(t,["tools"]);if(void 0!==n&&null!=A){let e=Zt(A);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==Ze(e,["retrieval"]))throw new Error("retrieval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["googleMaps"]);null!=n&&ze(t,["googleMaps"],function(e){const t={},n=Ze(e,["authConfig"]);null!=n&&ze(t,["authConfig"],function(e){const t={},n=Ze(e,["apiKey"]);if(null!=n&&ze(t,["apiKey"],n),void 0!==Ze(e,["apiKeyConfig"]))throw new Error("apiKeyConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["authType"]))throw new Error("authType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["googleServiceAccountConfig"]))throw new Error("googleServiceAccountConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["httpBasicAuthConfig"]))throw new Error("httpBasicAuthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oauthConfig"]))throw new Error("oauthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oidcConfig"]))throw new Error("oidcConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["enableWidget"]);if(null!=o&&ze(t,["enableWidget"],o),void 0!==Ze(e,["groundingTypes"]))throw new Error("groundingTypes parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["mcpServers"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mcpServers"],e)}const i=Ze(e,["codeExecution"]);null!=i&&ze(t,["codeExecution"],i);const r=Ze(e,["computerUse"]);if(null!=r&&ze(t,["computerUse"],r),void 0!==Ze(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["exaAiSearch"]))throw new Error("exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const s=Ze(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const l=Ze(e,["googleSearch"]);null!=l&&ze(t,["googleSearch"],function(e){const t={};if(void 0!==Ze(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["excludeDomains"]))throw new Error("excludeDomains parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["searchTypes"]);null!=n&&ze(t,["searchTypes"],n);const o=Ze(e,["timeRangeFilter"]);return null!=o&&ze(t,["timeRangeFilter"],o),t}(l));const a=Ze(e,["googleSearchRetrieval"]);if(null!=a&&ze(t,["googleSearchRetrieval"],a),void 0!==Ze(e,["parallelAiSearch"]))throw new Error("parallelAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["urlContext"]);null!=u&&ze(t,["urlContext"],u);const c=Ze(e,["fileSearch"]);return null!=c&&ze(t,["fileSearch"],c),t}(zt(e)))),ze(n,["tools"],e)}const I=Ze(t,["toolConfig"]);if(void 0!==n&&null!=I&&ze(n,["toolConfig"],function(e){const t={},n=Ze(e,["functionCallingConfig"]);null!=n&&ze(t,["functionCallingConfig"],function(e){const t={},n=Ze(e,["allowedFunctionNames"]);null!=n&&ze(t,["allowedFunctionNames"],n);const o=Ze(e,["mode"]);if(null!=o&&ze(t,["mode"],o),void 0!==Ze(e,["streamFunctionCallArguments"]))throw new Error("streamFunctionCallArguments parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["retrievalConfig"]);null!=o&&ze(t,["retrievalConfig"],o);const i=Ze(e,["includeServerSideToolInvocations"]);return null!=i&&ze(t,["includeServerSideToolInvocations"],i),t}(I)),void 0!==Ze(t,["labels"]))throw new Error("labels parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const T=Ze(t,["cachedContent"]);void 0!==n&&null!=T&&ze(n,["cachedContent"],Qt(e,T));const C=Ze(t,["responseModalities"]);null!=C&&ze(o,["responseModalities"],C);const S=Ze(t,["mediaResolution"]);null!=S&&ze(o,["mediaResolution"],S);const O=Ze(t,["speechConfig"]);if(null!=O&&ze(o,["speechConfig"],Kt(O)),void 0!==Ze(t,["audioTimestamp"]))throw new Error("audioTimestamp parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const b=Ze(t,["thinkingConfig"]);null!=b&&ze(o,["thinkingConfig"],b);const P=Ze(t,["audioTranscriptionConfig"]);null!=P&&ze(o,["audioTranscriptionConfig"],P);const w=Ze(t,["imageConfig"]);null!=w&&ze(o,["imageConfig"],function(e){const t={},n=Ze(e,["aspectRatio"]);null!=n&&ze(t,["aspectRatio"],n);const o=Ze(e,["imageSize"]);if(null!=o&&ze(t,["imageSize"],o),void 0!==Ze(e,["personGeneration"]))throw new Error("personGeneration parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["outputMimeType"]))throw new Error("outputMimeType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["outputCompressionQuality"]))throw new Error("outputCompressionQuality parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["imageOutputOptions"]))throw new Error("imageOutputOptions parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["prominentPeople"]))throw new Error("prominentPeople parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(w));const R=Ze(t,["enableEnhancedCivicAnswers"]);if(null!=R&&ze(o,["enableEnhancedCivicAnswers"],R),void 0!==Ze(t,["modelArmorConfig"]))throw new Error("modelArmorConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return o}(e,s,o)),o}function Bn(e,t,n){const o={},i=Ze(t,["model"]);null!=i&&ze(o,["_url","model"],Gt(e,i));const r=Ze(t,["contents"]);if(null!=r){let e=Jt(r);Array.isArray(e)&&(e=e.map(e=>Fn(e))),ze(o,["contents"],e)}const s=Ze(t,["config"]);return null!=s&&ze(o,["generationConfig"],function(e,t,n){const o={},i=Ze(t,["serviceTier"]);void 0!==n&&null!=i&&ze(n,["serviceTier"],i);const r=Ze(t,["systemInstruction"]);void 0!==n&&null!=r&&ze(n,["systemInstruction"],Fn(Vt(r)));const s=Ze(t,["temperature"]);null!=s&&ze(o,["temperature"],s);const l=Ze(t,["topP"]);null!=l&&ze(o,["topP"],l);const a=Ze(t,["topK"]);null!=a&&ze(o,["topK"],a);const u=Ze(t,["candidateCount"]);null!=u&&ze(o,["candidateCount"],u);const c=Ze(t,["maxOutputTokens"]);null!=c&&ze(o,["maxOutputTokens"],c);const p=Ze(t,["stopSequences"]);null!=p&&ze(o,["stopSequences"],p);const d=Ze(t,["responseLogprobs"]);null!=d&&ze(o,["responseLogprobs"],d);const m=Ze(t,["logprobs"]);null!=m&&ze(o,["logprobs"],m);const f=Ze(t,["presencePenalty"]);null!=f&&ze(o,["presencePenalty"],f);const h=Ze(t,["frequencyPenalty"]);null!=h&&ze(o,["frequencyPenalty"],h);const g=Ze(t,["seed"]);null!=g&&ze(o,["seed"],g);const v=Ze(t,["responseMimeType"]);null!=v&&ze(o,["responseMimeType"],v);const _=Ze(t,["responseSchema"]);null!=_&&ze(o,["responseSchema"],$t(_));const E=Ze(t,["responseJsonSchema"]);null!=E&&ze(o,["responseJsonSchema"],E);const y=Ze(t,["routingConfig"]);null!=y&&ze(o,["routingConfig"],y);const A=Ze(t,["modelSelectionConfig"]);null!=A&&ze(o,["modelConfig"],A);const I=Ze(t,["safetySettings"]);if(void 0!==n&&null!=I){let e=I;Array.isArray(e)&&(e=e.map(e=>e)),ze(n,["safetySettings"],e)}const T=Ze(t,["tools"]);if(void 0!==n&&null!=T){let e=Zt(T);Array.isArray(e)&&(e=e.map(e=>no(zt(e)))),ze(n,["tools"],e)}const C=Ze(t,["toolConfig"]);void 0!==n&&null!=C&&ze(n,["toolConfig"],function(e){const t={},n=Ze(e,["functionCallingConfig"]);null!=n&&ze(t,["functionCallingConfig"],n);const o=Ze(e,["retrievalConfig"]);if(null!=o&&ze(t,["retrievalConfig"],o),void 0!==Ze(e,["includeServerSideToolInvocations"]))throw new Error("includeServerSideToolInvocations parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(C));const S=Ze(t,["labels"]);void 0!==n&&null!=S&&ze(n,["labels"],S);const O=Ze(t,["cachedContent"]);void 0!==n&&null!=O&&ze(n,["cachedContent"],Qt(e,O));const b=Ze(t,["responseModalities"]);null!=b&&ze(o,["responseModalities"],b);const P=Ze(t,["mediaResolution"]);null!=P&&ze(o,["mediaResolution"],P);const w=Ze(t,["speechConfig"]);null!=w&&ze(o,["speechConfig"],to(Kt(w)));const R=Ze(t,["audioTimestamp"]);null!=R&&ze(o,["audioTimestamp"],R);const N=Ze(t,["thinkingConfig"]);null!=N&&ze(o,["thinkingConfig"],N);const D=Ze(t,["audioTranscriptionConfig"]);null!=D&&ze(o,["audioTranscriptionConfig"],D);const G=Ze(t,["imageConfig"]);if(null!=G&&ze(o,["imageConfig"],function(e){const t={},n=Ze(e,["aspectRatio"]);null!=n&&ze(t,["aspectRatio"],n);const o=Ze(e,["imageSize"]);null!=o&&ze(t,["imageSize"],o);const i=Ze(e,["personGeneration"]);null!=i&&ze(t,["personGeneration"],i);const r=Ze(e,["outputMimeType"]);null!=r&&ze(t,["imageOutputOptions","mimeType"],r);const s=Ze(e,["outputCompressionQuality"]);null!=s&&ze(t,["imageOutputOptions","compressionQuality"],s);const l=Ze(e,["imageOutputOptions"]);null!=l&&ze(t,["imageOutputOptions"],l);const a=Ze(e,["prominentPeople"]);return null!=a&&ze(t,["prominentPeople"],a),t}(G)),void 0!==Ze(t,["enableEnhancedCivicAnswers"]))throw new Error("enableEnhancedCivicAnswers parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const k=Ze(t,["modelArmorConfig"]);return void 0!==n&&null!=k&&ze(n,["modelArmorConfig"],k),o}(e,s,o)),o}function Vn(e,t){const n={},o=Ze(e,["sdkHttpResponse"]);null!=o&&ze(n,["sdkHttpResponse"],o);const i=Ze(e,["candidates"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["content"]);null!=n&&ze(t,["content"],n);const o=Ze(e,["citationMetadata"]);null!=o&&ze(t,["citationMetadata"],function(e){const t={},n=Ze(e,["citationSources"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["citations"],e)}return t}(o));const i=Ze(e,["tokenCount"]);null!=i&&ze(t,["tokenCount"],i);const r=Ze(e,["finishReason"]);null!=r&&ze(t,["finishReason"],r);const s=Ze(e,["groundingMetadata"]);null!=s&&ze(t,["groundingMetadata"],s);const l=Ze(e,["avgLogprobs"]);null!=l&&ze(t,["avgLogprobs"],l);const a=Ze(e,["index"]);null!=a&&ze(t,["index"],a);const u=Ze(e,["logprobsResult"]);null!=u&&ze(t,["logprobsResult"],u);const c=Ze(e,["safetyRatings"]);if(null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["safetyRatings"],e)}const p=Ze(e,["urlContextMetadata"]);return null!=p&&ze(t,["urlContextMetadata"],p),t}(e))),ze(n,["candidates"],e)}const r=Ze(e,["modelVersion"]);null!=r&&ze(n,["modelVersion"],r);const s=Ze(e,["promptFeedback"]);null!=s&&ze(n,["promptFeedback"],s);const l=Ze(e,["responseId"]);null!=l&&ze(n,["responseId"],l);const a=Ze(e,["usageMetadata"]);null!=a&&ze(n,["usageMetadata"],a);const u=Ze(e,["modelStatus"]);return null!=u&&ze(n,["modelStatus"],u),n}function Xn(e,t){const n={},o=Ze(e,["sdkHttpResponse"]);null!=o&&ze(n,["sdkHttpResponse"],o);const i=Ze(e,["candidates"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(n,["candidates"],e)}const r=Ze(e,["createTime"]);null!=r&&ze(n,["createTime"],r);const s=Ze(e,["modelVersion"]);null!=s&&ze(n,["modelVersion"],s);const l=Ze(e,["promptFeedback"]);null!=l&&ze(n,["promptFeedback"],l);const a=Ze(e,["responseId"]);null!=a&&ze(n,["responseId"],a);const u=Ze(e,["usageMetadata"]);return null!=u&&ze(n,["usageMetadata"],u),n}function Jn(e,t,n){const o={},i=Ze(t,["model"]);null!=i&&ze(o,["_url","model"],Gt(e,i));const r=Ze(t,["prompt"]);null!=r&&ze(o,["instances[0]","prompt"],r);const s=Ze(t,["image"]);null!=s&&ze(o,["instances[0]","image"],Wn(s));const l=Ze(t,["video"]);null!=l&&ze(o,["instances[0]","video"],oo(l));const a=Ze(t,["source"]);null!=a&&function(e,t){const n=Ze(e,["prompt"]);void 0!==t&&null!=n&&ze(t,["instances[0]","prompt"],n);const o=Ze(e,["image"]);void 0!==t&&null!=o&&ze(t,["instances[0]","image"],Wn(o));const i=Ze(e,["video"]);void 0!==t&&null!=i&&ze(t,["instances[0]","video"],oo(i))}(a,o);const u=Ze(t,["config"]);return null!=u&&function(e,t){const n=Ze(e,["numberOfVideos"]);if(void 0!==t&&null!=n&&ze(t,["parameters","sampleCount"],n),void 0!==Ze(e,["outputGcsUri"]))throw new Error("outputGcsUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["fps"]))throw new Error("fps parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["durationSeconds"]);if(void 0!==t&&null!=o&&ze(t,["parameters","durationSeconds"],o),void 0!==Ze(e,["seed"]))throw new Error("seed parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const i=Ze(e,["aspectRatio"]);void 0!==t&&null!=i&&ze(t,["parameters","aspectRatio"],i);const r=Ze(e,["resolution"]);void 0!==t&&null!=r&&ze(t,["parameters","resolution"],r);const s=Ze(e,["personGeneration"]);if(void 0!==t&&null!=s&&ze(t,["parameters","personGeneration"],s),void 0!==Ze(e,["pubsubTopic"]))throw new Error("pubsubTopic parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const l=Ze(e,["negativePrompt"]);void 0!==t&&null!=l&&ze(t,["parameters","negativePrompt"],l);const a=Ze(e,["enhancePrompt"]);if(void 0!==t&&null!=a&&ze(t,["parameters","enhancePrompt"],a),void 0!==Ze(e,["generateAudio"]))throw new Error("generateAudio parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["lastFrame"]);void 0!==t&&null!=u&&ze(t,["instances[0]","lastFrame"],Wn(u));const c=Ze(e,["referenceImages"]);if(void 0!==t&&null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["image"]);null!=n&&ze(t,["image"],Wn(n));const o=Ze(e,["referenceType"]);return null!=o&&ze(t,["referenceType"],o),t}(e))),ze(t,["instances[0]","referenceImages"],e)}if(void 0!==Ze(e,["mask"]))throw new Error("mask parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["compressionQuality"]))throw new Error("compressionQuality parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["labels"]))throw new Error("labels parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const p=Ze(e,["webhookConfig"]);if(void 0!==t&&null!=p&&ze(t,["webhookConfig"],p),void 0!==Ze(e,["resizeMode"]))throw new Error("resizeMode parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(u,o),o}function Yn(e,t,n){const o={},i=Ze(t,["model"]);null!=i&&ze(o,["_url","model"],Gt(e,i));const r=Ze(t,["prompt"]);null!=r&&ze(o,["instances[0]","prompt"],r);const s=Ze(t,["image"]);null!=s&&ze(o,["instances[0]","image"],zn(s));const l=Ze(t,["video"]);null!=l&&ze(o,["instances[0]","video"],io(l));const a=Ze(t,["source"]);null!=a&&function(e,t){const n=Ze(e,["prompt"]);void 0!==t&&null!=n&&ze(t,["instances[0]","prompt"],n);const o=Ze(e,["image"]);void 0!==t&&null!=o&&ze(t,["instances[0]","image"],zn(o));const i=Ze(e,["video"]);void 0!==t&&null!=i&&ze(t,["instances[0]","video"],io(i))}(a,o);const u=Ze(t,["config"]);return null!=u&&function(e,t){const n=Ze(e,["numberOfVideos"]);void 0!==t&&null!=n&&ze(t,["parameters","sampleCount"],n);const o=Ze(e,["outputGcsUri"]);void 0!==t&&null!=o&&ze(t,["parameters","storageUri"],o);const i=Ze(e,["fps"]);void 0!==t&&null!=i&&ze(t,["parameters","fps"],i);const r=Ze(e,["durationSeconds"]);void 0!==t&&null!=r&&ze(t,["parameters","durationSeconds"],r);const s=Ze(e,["seed"]);void 0!==t&&null!=s&&ze(t,["parameters","seed"],s);const l=Ze(e,["aspectRatio"]);void 0!==t&&null!=l&&ze(t,["parameters","aspectRatio"],l);const a=Ze(e,["resolution"]);void 0!==t&&null!=a&&ze(t,["parameters","resolution"],a);const u=Ze(e,["personGeneration"]);void 0!==t&&null!=u&&ze(t,["parameters","personGeneration"],u);const c=Ze(e,["pubsubTopic"]);void 0!==t&&null!=c&&ze(t,["parameters","pubsubTopic"],c);const p=Ze(e,["negativePrompt"]);void 0!==t&&null!=p&&ze(t,["parameters","negativePrompt"],p);const d=Ze(e,["enhancePrompt"]);void 0!==t&&null!=d&&ze(t,["parameters","enhancePrompt"],d);const m=Ze(e,["generateAudio"]);void 0!==t&&null!=m&&ze(t,["parameters","generateAudio"],m);const f=Ze(e,["lastFrame"]);void 0!==t&&null!=f&&ze(t,["instances[0]","lastFrame"],zn(f));const h=Ze(e,["referenceImages"]);if(void 0!==t&&null!=h){let e=h;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["image"]);null!=n&&ze(t,["image"],zn(n));const o=Ze(e,["referenceType"]);return null!=o&&ze(t,["referenceType"],o),t}(e))),ze(t,["instances[0]","referenceImages"],e)}const g=Ze(e,["mask"]);void 0!==t&&null!=g&&ze(t,["instances[0]","mask"],function(e){const t={},n=Ze(e,["image"]);null!=n&&ze(t,["_self"],zn(n));const o=Ze(e,["maskMode"]);return null!=o&&ze(t,["maskMode"],o),t}(g));const v=Ze(e,["compressionQuality"]);void 0!==t&&null!=v&&ze(t,["parameters","compressionQuality"],v);const _=Ze(e,["labels"]);if(void 0!==t&&null!=_&&ze(t,["labels"],_),void 0!==Ze(e,["webhookConfig"]))throw new Error("webhookConfig parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const E=Ze(e,["resizeMode"]);void 0!==t&&null!=E&&ze(t,["parameters","resizeMode"],E)}(u,o),o}function $n(e,t){const n={},o=Ze(e,["_self"]);null!=o&&ze(n,["image"],Kn(o));const i=Ze(e,["raiFilteredReason"]);null!=i&&ze(n,["raiFilteredReason"],i);const r=Ze(e,["_self"]);null!=r&&ze(n,["safetyAttributes"],eo(r));const s=Ze(e,["prompt"]);return null!=s&&ze(n,["enhancedPrompt"],s),n}function Kn(e,t){const n={},o=Ze(e,["gcsUri"]);null!=o&&ze(n,["gcsUri"],o);const i=Ze(e,["bytesBase64Encoded"]);null!=i&&ze(n,["imageBytes"],tn(i));const r=Ze(e,["mimeType"]);return null!=r&&ze(n,["mimeType"],r),n}function Wn(e,t){const n={};if(void 0!==Ze(e,["gcsUri"]))throw new Error("gcsUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["imageBytes"]);null!=o&&ze(n,["bytesBase64Encoded"],tn(o));const i=Ze(e,["mimeType"]);return null!=i&&ze(n,["mimeType"],i),n}function zn(e,t){const n={},o=Ze(e,["gcsUri"]);null!=o&&ze(n,["gcsUri"],o);const i=Ze(e,["imageBytes"]);null!=i&&ze(n,["bytesBase64Encoded"],tn(i));const r=Ze(e,["mimeType"]);return null!=r&&ze(n,["mimeType"],r),n}function Zn(e,t){const n={},o=Ze(e,["name"]);null!=o&&ze(n,["name"],o);const i=Ze(e,["displayName"]);null!=i&&ze(n,["displayName"],i);const r=Ze(e,["description"]);null!=r&&ze(n,["description"],r);const s=Ze(e,["version"]);null!=s&&ze(n,["version"],s);const l=Ze(e,["_self"]);null!=l&&ze(n,["tunedModelInfo"],function(e){const t={},n=Ze(e,["baseModel"]);null!=n&&ze(t,["baseModel"],n);const o=Ze(e,["createTime"]);null!=o&&ze(t,["createTime"],o);const i=Ze(e,["updateTime"]);return null!=i&&ze(t,["updateTime"],i),t}(l));const a=Ze(e,["inputTokenLimit"]);null!=a&&ze(n,["inputTokenLimit"],a);const u=Ze(e,["outputTokenLimit"]);null!=u&&ze(n,["outputTokenLimit"],u);const c=Ze(e,["supportedGenerationMethods"]);null!=c&&ze(n,["supportedActions"],c);const p=Ze(e,["temperature"]);null!=p&&ze(n,["temperature"],p);const d=Ze(e,["maxTemperature"]);null!=d&&ze(n,["maxTemperature"],d);const m=Ze(e,["topP"]);null!=m&&ze(n,["topP"],m);const f=Ze(e,["topK"]);null!=f&&ze(n,["topK"],f);const h=Ze(e,["thinking"]);return null!=h&&ze(n,["thinking"],h),n}function Qn(e,t){const n={},o=Ze(e,["name"]);null!=o&&ze(n,["name"],o);const i=Ze(e,["displayName"]);null!=i&&ze(n,["displayName"],i);const r=Ze(e,["description"]);null!=r&&ze(n,["description"],r);const s=Ze(e,["versionId"]);null!=s&&ze(n,["version"],s);const l=Ze(e,["deployedModels"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["endpoint"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["deployedModelId"]);return null!=o&&ze(t,["deployedModelId"],o),t}(e))),ze(n,["endpoints"],e)}const a=Ze(e,["labels"]);null!=a&&ze(n,["labels"],a);const u=Ze(e,["_self"]);null!=u&&ze(n,["tunedModelInfo"],function(e){const t={},n=Ze(e,["labels","google-vertex-llm-tuning-base-model-id"]);null!=n&&ze(t,["baseModel"],n);const o=Ze(e,["createTime"]);null!=o&&ze(t,["createTime"],o);const i=Ze(e,["updateTime"]);return null!=i&&ze(t,["updateTime"],i),t}(u));const c=Ze(e,["defaultCheckpointId"]);null!=c&&ze(n,["defaultCheckpointId"],c);const p=Ze(e,["checkpoints"]);if(null!=p){let e=p;Array.isArray(e)&&(e=e.map(e=>e)),ze(n,["checkpoints"],e)}return n}function eo(e,t){const n={},o=Ze(e,["safetyAttributes","categories"]);null!=o&&ze(n,["categories"],o);const i=Ze(e,["safetyAttributes","scores"]);null!=i&&ze(n,["scores"],i);const r=Ze(e,["contentType"]);return null!=r&&ze(n,["contentType"],r),n}function to(e,t){const n={},o=Ze(e,["voiceConfig"]);null!=o&&ze(n,["voiceConfig"],ro(o));const i=Ze(e,["languageCode"]);null!=i&&ze(n,["languageCode"],i);const r=Ze(e,["multiSpeakerVoiceConfig"]);return null!=r&&ze(n,["multiSpeakerVoiceConfig"],function(e){const t={},n=Ze(e,["speakerVoiceConfigs"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["speaker"]);null!=n&&ze(t,["speaker"],n);const o=Ze(e,["voiceConfig"]);return null!=o&&ze(t,["voiceConfig"],ro(o)),t}(e))),ze(t,["speakerVoiceConfigs"],e)}return t}(r)),n}function no(e,t){const n={},o=Ze(e,["retrieval"]);null!=o&&ze(n,["retrieval"],o);const i=Ze(e,["googleMaps"]);null!=i&&ze(n,["googleMaps"],i);const r=Ze(e,["mcpServers"]);if(null!=r){let e=r;Array.isArray(e)&&(e=e.map(e=>function(e){if(void 0!==Ze(e,["name"]))throw new Error("name parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["streamableHttpTransport"]))throw new Error("streamableHttpTransport parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return{}}(e))),ze(n,["mcpServers"],e)}const s=Ze(e,["codeExecution"]);null!=s&&ze(n,["codeExecution"],s);const l=Ze(e,["computerUse"]);null!=l&&ze(n,["computerUse"],function(e){const t={},n=Ze(e,["enablePromptInjectionDetection"]);null!=n&&ze(t,["enablePromptInjectionDetection"],n);const o=Ze(e,["environment"]);null!=o&&ze(t,["environment"],o);const i=Ze(e,["excludedPredefinedFunctions"]);if(null!=i&&ze(t,["excludedPredefinedFunctions"],i),void 0!==Ze(e,["disabledSafetyPolicies"]))throw new Error("disabledSafetyPolicies parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(l));const a=Ze(e,["enterpriseWebSearch"]);null!=a&&ze(n,["enterpriseWebSearch"],a);const u=Ze(e,["exaAiSearch"]);null!=u&&ze(n,["exaAiSearch"],u);const c=Ze(e,["functionDeclarations"]);if(null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>e)),ze(n,["functionDeclarations"],e)}const p=Ze(e,["googleSearch"]);null!=p&&ze(n,["googleSearch"],p);const d=Ze(e,["googleSearchRetrieval"]);null!=d&&ze(n,["googleSearchRetrieval"],d);const m=Ze(e,["parallelAiSearch"]);null!=m&&ze(n,["parallelAiSearch"],m);const f=Ze(e,["urlContext"]);if(null!=f&&ze(n,["urlContext"],f),void 0!==Ze(e,["fileSearch"]))throw new Error("fileSearch parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return n}function oo(e,t){const n={},o=Ze(e,["uri"]);null!=o&&ze(n,["uri"],o);const i=Ze(e,["videoBytes"]);null!=i&&ze(n,["encodedVideo"],tn(i));const r=Ze(e,["mimeType"]);return null!=r&&ze(n,["encoding"],r),n}function io(e,t){const n={},o=Ze(e,["uri"]);null!=o&&ze(n,["gcsUri"],o);const i=Ze(e,["videoBytes"]);null!=i&&ze(n,["bytesBase64Encoded"],tn(i));const r=Ze(e,["mimeType"]);return null!=r&&ze(n,["mimeType"],r),n}function ro(e,t){const n={},o=Ze(e,["replicatedVoiceConfig"]);null!=o&&ze(n,["replicatedVoiceConfig"],function(e){const t={},n=Ze(e,["mimeType"]);null!=n&&ze(t,["mimeType"],n);const o=Ze(e,["voiceSampleAudio"]);if(null!=o&&ze(t,["voiceSampleAudio"],o),void 0!==Ze(e,["consentAudio"]))throw new Error("consentAudio parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["voiceConsentSignature"]))throw new Error("voiceConsentSignature parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(o));const i=Ze(e,["prebuiltVoiceConfig"]);return null!=i&&ze(n,["prebuiltVoiceConfig"],i),n}function so(e,t){const n=Ze(e,["mimeType"]);void 0!==t&&null!=n&&ze(t,["mimeType"],n);const o=Ze(e,["displayName"]);void 0!==t&&null!=o&&ze(t,["displayName"],o);const i=Ze(e,["customMetadata"]);if(void 0!==t&&null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["customMetadata"],e)}const r=Ze(e,["chunkingConfig"]);return void 0!==t&&null!=r&&ze(t,["chunkingConfig"],r),{}}var lo="x-goog-api-client",ao=/* @__PURE__ */new Set(["us","eu"]),uo=[408,429,500,502,503,504],co=class{constructor(e){var t,n,o;this.clientOptions=Object.assign({},e),this.customBaseUrl=null===(t=e.httpOptions)||void 0===t?void 0:t.baseUrl;const i={};if(this.clientOptions.vertexai){if(this.clientOptions.location||this.clientOptions.apiKey||this.customBaseUrl||(this.clientOptions.location="global"),!(this.clientOptions.project&&this.clientOptions.location||this.clientOptions.apiKey||this.customBaseUrl))throw new Error("Authentication is not set up. Please provide either a project and location, or an API key, or a custom base URL.");const t=e.project&&e.location||!!e.apiKey;this.customBaseUrl&&!t?(i.baseUrl=this.customBaseUrl,this.clientOptions.project=void 0,this.clientOptions.location=void 0):this.clientOptions.apiKey&&!this.clientOptions.project||"global"===this.clientOptions.location?i.baseUrl="https://aiplatform.googleapis.com/":this.clientOptions.project&&this.clientOptions.location&&ao.has(this.clientOptions.location)?i.baseUrl=`https://aiplatform.${this.clientOptions.location}.rep.googleapis.com/`:this.clientOptions.project&&this.clientOptions.location&&(i.baseUrl=`https://${this.clientOptions.location}-aiplatform.googleapis.com/`),i.apiVersion=null!==(n=this.clientOptions.apiVersion)&&void 0!==n?n:"v1beta1"}else this.clientOptions.apiKey,i.apiVersion=null!==(o=this.clientOptions.apiVersion)&&void 0!==o?o:"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))}isVertexAI(){var e;return null!==(e=this.clientOptions.vertexai)&&void 0!==e&&e}getProject(){return this.clientOptions.project}getLocation(){return this.clientOptions.location}getCustomBaseUrl(){return this.customBaseUrl}async getAuthHeaders(){const e=new Headers;return await this.clientOptions.auth.addAuthHeaders(e),e}getApiVersion(){if(this.clientOptions.httpOptions&&void 0!==this.clientOptions.httpOptions.apiVersion)return this.clientOptions.httpOptions.apiVersion;throw new Error("API version is not set.")}getBaseUrl(){if(this.clientOptions.httpOptions&&void 0!==this.clientOptions.httpOptions.baseUrl)return this.clientOptions.httpOptions.baseUrl;throw new 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 new Error("Headers are not set.")}getRequestUrlInternal(e){if(!e||void 0===e.baseUrl||void 0===e.apiVersion)throw new Error("HTTP options are not correctly set.");const 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(){const e=this.getBaseUrl(),t=new URL(e);return t.protocol="http:"==t.protocol?"ws":"wss",t.toString()}setBaseUrl(e){if(!this.clientOptions.httpOptions)throw new Error("HTTP options are not correctly set.");this.clientOptions.httpOptions.baseUrl=e}constructUrl(e,t,n){const o=[this.getRequestUrlInternal(t)];return n&&o.push(this.getBaseResourcePath()),""!==e&&o.push(e),new URL(`${o.join("/")}`)}shouldPrependVertexProjectPath(e,t){return!(t.baseUrl&&t.baseUrlResourceScope===he.COLLECTION||!this.clientOptions.vertexai||!this.clientOptions.project||!this.clientOptions.location||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));const n=this.shouldPrependVertexProjectPath(e,t),o=this.constructUrl(e.path,t,n);if(e.queryParams)for(const[r,s]of Object.entries(e.queryParams))o.searchParams.append(r,String(s));let i={};if("GET"===e.httpMethod){if(e.body&&"{}"!==e.body)throw new Error("Request body should be empty for GET request, but got non empty request body")}else i.body=e.body;return i=await this.includeExtraHttpOptionsToRequestInit(i,t,o.toString()),this.unaryApiCall(o,i,e.httpMethod,t.retryOptions,t.timeout,e.abortSignal)}patchHttpOptions(e,t){const n=JSON.parse(JSON.stringify(e));for(const[o,i]of Object.entries(t))"object"==typeof i?n[o]=Object.assign(Object.assign({},n[o]),i):void 0!==i&&(n[o]=i);return n}async requestStream(e){let t=this.clientOptions.httpOptions;e.httpOptions&&(t=this.patchHttpOptions(this.clientOptions.httpOptions,e.httpOptions));const n=this.shouldPrependVertexProjectPath(e,t),o=this.constructUrl(e.path,t,n);o.searchParams.has("alt")&&"sse"===o.searchParams.get("alt")||o.searchParams.set("alt","sse");let i={};return i.body=e.body,i=await this.includeExtraHttpOptionsToRequestInit(i,t,o.toString()),this.streamApiCall(o,i,e.httpMethod,t.retryOptions,t.timeout,e.abortSignal)}async includeExtraHttpOptionsToRequestInit(e,t,n){return(null==t?void 0:t.timeout)&&t.timeout>0&&function(e){const t=globalThis[Symbol.for("undici.globalDispatcher.1")];if(t)for(const n of Object.getOwnPropertySymbols(t)){const o=n.description;if((null==o?void 0:o.includes("headers timeout"))||(null==o?void 0:o.includes("body timeout"))){const o=t[n];"number"==typeof o&&(t[n]=Math.max(o,e))}}}(t.timeout),t&&null!==t.extraBody&&function(e,t){if(!t||0===Object.keys(t).length)return;if(e.body instanceof Blob)return;let n={};if("string"==typeof e.body&&e.body.length>0)try{const t=JSON.parse(e.body);if("object"!=typeof t||null===t||Array.isArray(t))return;n=t}catch(i){return}const o=function e(t,n){const o=Object.assign({},t);for(const i in n)if(Object.prototype.hasOwnProperty.call(n,i)){const t=n[i],r=o[i];t&&"object"==typeof t&&!Array.isArray(t)&&r&&"object"==typeof r&&!Array.isArray(r)?o[i]=e(r,t):o[i]=t}return o}(n,t);e.body=JSON.stringify(o)}(e,t.extraBody),e.headers=await this.getHeadersInternal(t,n),e}async unaryApiCall(e,t,n,o,i,r){return this.apiCall(e.toString(),Object.assign(Object.assign({},t),{method:n}),o,i,r).then(async e=>(await po(e),new ot(e))).catch(e=>{throw e instanceof Error?e:new Error(`exception ${e} sending request`,{cause:e})})}async streamApiCall(e,t,n,o,i,r){return this.apiCall(e.toString(),Object.assign(Object.assign({},t),{method:n}),o,i,r).then(async e=>(await po(e),this.processStreamResponse(e))).catch(e=>{throw e instanceof Error?e:new Error(`exception ${e} sending request`,{cause:e})})}processStreamResponse(e){return Cn(this,arguments,function*(){var t;const n=null===(t=null==e?void 0:e.body)||void 0===t?void 0:t.getReader(),o=new TextDecoder("utf-8");if(!n)throw new Error("Response body is empty");try{let t="";const r="data:",s=["\n\n","\r\r","\r\n\r\n"];for(;;){const{done:l,value:a}=yield Tn(n.read());if(l){if(t.trim().length>0)throw new Error("Incomplete JSON segment at the end");break}const u=o.decode(a,{stream:!0});try{const e=JSON.parse(u);if("error"in e){const t=JSON.parse(JSON.stringify(e.error)),n=t.status,o=t.code,i=`got status: ${n}. ${JSON.stringify(e)}`;if(o>=400&&o<600)throw new Nn({message:i,status:o})}}catch(i){if("ApiError"===i.name)throw i}t+=u;let c=-1,p=0;for(;;){c=-1,p=0;for(const e of s){const n=t.indexOf(e);-1!==n&&(-1===c||n<c)&&(c=n,p=e.length)}if(-1===c)break;const n=t.substring(0,c);t=t.substring(c+p);const o=n.trim();if(o.startsWith(r)){const t=o.substring(5).trim();try{const n=new Response(t,{headers:null==e?void 0:e.headers,status:null==e?void 0:e.status,statusText:null==e?void 0:e.statusText});yield yield Tn(new ot(n))}catch(i){throw new Error(`exception parsing stream chunk ${t}. ${i}`)}}}}}finally{n.releaseLock()}})}async apiCall(e,t,n,o,i){var r,s,l,a,u,c;const p=null!==(r=null==n?void 0:n.httpStatusCodes)&&void 0!==r?r:uo,d=async()=>{const r=function(e,t){if(!(e&&e>0||t))return{signal:void 0,dispose:()=>{}};const n=new AbortController;let o;e&&e>0&&(o=setTimeout(()=>n.abort(),e),o&&"function"==typeof o.unref&&o.unref());const i=()=>n.abort();return t&&(t.aborted?n.abort():t.addEventListener("abort",i)),{signal:n.signal,dispose:()=>{void 0!==o&&clearTimeout(o),null==t||t.removeEventListener("abort",i)}}}(o,i);let s;try{s=await fetch(e,Object.assign(Object.assign({},t),{signal:r.signal}))}catch(l){throw r.dispose(),l}if(!n||s.ok||!p.includes(s.status))return s;try{await po(s)}finally{r.dispose()}return s};if(!n)return d();const m=Math.max(1,null!==(s=n.attempts)&&void 0!==s?s:5),f=Math.round(1e3*(null!==(l=n.initialDelay)&&void 0!==l?l:1)),h=Math.max(f,Math.round(1e3*(null!==(a=n.maxDelay)&&void 0!==a?a:60)));return(0,$e.default)(d,{retries:m-1,factor:null!==(u=n.expBase)&&void 0!==u?u:2,minTimeout:f,maxTimeout:h,randomize:(null!==(c=n.jitter)&&void 0!==c?c:1)>0,onFailedAttempt:e=>{var t;if(null==i?void 0:i.aborted)throw null!==(t=e.error)&&void 0!==t?t:e}})}getDefaultHeaders(){const e={},t="google-genai-sdk/2.21.0 "+this.clientOptions.userAgentExtra;return e["User-Agent"]=t,e[lo]=t,e["Content-Type"]="application/json",e}async getHeadersInternal(e,t){const n=new Headers;if(e&&e.headers)for(const[o,i]of Object.entries(e.headers))n.append(o,i);return(null==e?void 0:e.timeout)&&e.timeout>0&&n.append("X-Server-Timeout",String(Math.ceil(e.timeout/1e3))),await this.clientOptions.auth.addAuthHeaders(n,t),n}getFileName(e){var t;let n="";return"string"==typeof e&&(n=e.replace(/[/\\]+$/,""),n=null!==(t=n.split(/[/\\]/).pop())&&void 0!==t?t:""),n}async uploadFile(e,t){var n;const o={};null!=t&&(o.mimeType=t.mimeType,o.name=t.name,o.displayName=t.displayName),o.name&&!o.name.startsWith("files/")&&(o.name=`files/${o.name}`);const i=this.clientOptions.uploader,r=await i.stat(e);o.sizeBytes=String(r.size);const s=null!==(n=null==t?void 0:t.mimeType)&&void 0!==n?n:r.type;if(void 0===s||""===s)throw new Error("Can not determine mimeType. Please provide mimeType in the config.");o.mimeType=s;const l={file:o},a=this.getFileName(e),u=We("upload/v1beta/files",l._url),c=await this.fetchUploadUrl(u,o.sizeBytes,o.mimeType,a,l,null==t?void 0:t.httpOptions);return i.upload(e,c,this)}async uploadFileToFileSearchStore(e,t,n){var o;const i=this.clientOptions.uploader,r=await i.stat(t),s=String(r.size),l=null!==(o=null==n?void 0:n.mimeType)&&void 0!==o?o:r.type;if(void 0===l||""===l)throw new Error("Can not determine mimeType. Please provide mimeType in the config.");const a=`upload/v1beta/${e}:uploadToFileSearchStore`,u=this.getFileName(t),c={};null!=n&&so(n,c);const p=await this.fetchUploadUrl(a,s,l,u,c,null==n?void 0:n.httpOptions);return i.uploadToFileSearchStore(t,p,this)}async downloadFile(e){await this.clientOptions.downloader.download(e,this)}async fetchUploadUrl(e,t,n,o,i,r){var s;let l={};l=r||{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}`},o?{"X-Goog-Upload-File-Name":o}:{})};const a=await this.request({path:e,body:JSON.stringify(i),httpMethod:"POST",httpOptions:l});if(!a||!(null==a?void 0:a.headers))throw new Error("Server did not return an HttpResponse or the returned HttpResponse did not have headers.");const u=null===(s=null==a?void 0:a.headers)||void 0===s?void 0:s["x-goog-upload-url"];if(void 0===u)throw new Error("Failed to get upload url. Server did not return the x-google-upload-url in the headers");return u}};async function po(e){var t;if(void 0===e)throw new Error("response is undefined");if(!e.ok){const n=e.status;let o;o=(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}};const i=JSON.stringify(o);if(n>=400&&n<600)throw new Nn({message:i,status:n});throw new Error(i)}}function mo(e){for(const t of e){if(ho(t))return!0;if("object"==typeof t&&"inputSchema"in t)return!0}return!1}function fo(e){var t;const n=null!==(t=e[lo])&&void 0!==t?t:"";e[lo]=(n+" mcp_used/unknown").trimStart()}function ho(e){return null!==e&&"object"==typeof e&&e instanceof vo}function go(e){return Cn(this,arguments,function*(e,t=100){let n,o=0;for(;o<t;){const t=yield Tn(e.listTools({cursor:n}));for(const e of t.tools)yield yield Tn(e),o++;if(!t.nextCursor)break;n=t.nextCursor}})}var vo=class e{constructor(e=[],t){this.mcpTools=[],this.functionNameToMcpClient={},this.mcpClients=e,this.config=t}static create(t,n){return new e(t,n)}async initialize(){var e,t,n,o;if(this.mcpTools.length>0)return;const i={},r=[];for(const c of this.mcpClients)try{for(var s,l=!0,a=(t=void 0,Sn(go(c)));!(e=(s=await a.next()).done);l=!0){o=s.value,l=!1;const e=o;r.push(e);const t=e.name;if(i[t])throw new Error(`Duplicate function name ${t} found in MCP tools. Please ensure function names are unique.`);i[t]=c}}catch(u){t={error:u}}finally{try{l||e||!(n=a.return)||await n.call(a)}finally{if(t)throw t.error}}this.mcpTools=r,this.functionNameToMcpClient=i}async tool(){return await this.initialize(),function(e,t={}){const n=[],o=/* @__PURE__ */new Set;for(const i of e){const e=i.name;if(o.has(e))throw new Error(`Duplicate function name ${e} found in MCP tools. Please ensure function names are unique.`);o.add(e);const r=ln(i,t);r.functionDeclarations&&n.push(...r.functionDeclarations)}return{functionDeclarations:n}}(this.mcpTools,this.config)}async callTool(e){await this.initialize();const t=[];for(const n of e)if(n.name in this.functionNameToMcpClient){const e=this.functionNameToMcpClient[n.name];let o;this.config.timeout&&(o={timeout:this.config.timeout});const i=await e.callTool({name:n.name,arguments:n.args},void 0,o);t.push({functionResponse:{name:n.name,response:i.isError?{error:i}:i}})}return t}},_o=class{constructor(e,t,n){this.apiClient=e,this.auth=t,this.webSocketFactory=n}async connect(e){var t,n;if(this.apiClient.isVertexAI())throw new Error("Live music is not supported for Vertex AI.");const o=this.apiClient.getWebsocketBaseUrl(),i=this.apiClient.getApiVersion(),r=function(e){const t=new Headers;for(const[n,o]of Object.entries(e))t.append(n,o);return t}(this.apiClient.getDefaultHeaders()),s=`${o}/ws/google.ai.generativelanguage.${i}.GenerativeService.BidiGenerateMusic?key=${this.apiClient.getApiKey()}`;let l=()=>{};const a=new Promise(e=>{l=e}),u=e.callbacks,c=(this.apiClient,{onopen:function(){l({})},onmessage:e=>{!async function(e,t,n){const o=new Nt;let i;i=n.data instanceof Blob?JSON.parse(await n.data.text()):JSON.parse(n.data),Object.assign(o,i),t(o)}(0,u.onmessage,e)},onerror:null!==(t=null==u?void 0:u.onerror)&&void 0!==t?t:function(e){},onclose:null!==(n=null==u?void 0:u.onclose)&&void 0!==n?n:function(e){}}),p=this.webSocketFactory.create(s,function(e){const t={};return e.forEach((e,n)=>{t[n]=e}),t}(r),c);p.connect(),await a;const d={setup:{model:Gt(this.apiClient,e.model)}};return p.send(JSON.stringify(d)),new Eo(p,this.apiClient)}},Eo=class{constructor(e,t){this.conn=e,this.apiClient=t}async setWeightedPrompts(e){if(!e.weightedPrompts||0===Object.keys(e.weightedPrompts).length)throw new Error("Weighted prompts must be set and contain at least one entry.");const t=function(e){const t={},n=Ze(e,["weightedPrompts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["weightedPrompts"],e)}return t}(e);this.conn.send(JSON.stringify({clientContent:t}))}async setMusicGenerationConfig(e){e.musicGenerationConfig||(e.musicGenerationConfig={});const t=function(e){const t={},n=Ze(e,["musicGenerationConfig"]);return null!=n&&ze(t,["musicGenerationConfig"],n),t}(e);this.conn.send(JSON.stringify(t))}sendPlaybackControl(e){const t={playbackControl:e};this.conn.send(JSON.stringify(t))}play(){this.sendPlaybackControl(Be.PLAY)}pause(){this.sendPlaybackControl(Be.PAUSE)}stop(){this.sendPlaybackControl(Be.STOP)}resetContext(){this.sendPlaybackControl(Be.RESET_CONTEXT)}close(){this.conn.close()}},yo=class{constructor(e,t,n){this.apiClient=e,this.auth=t,this.webSocketFactory=n,this.music=new _o(this.apiClient,this.auth,this.webSocketFactory)}async connect(e){var t,n,o,i,r,s;if(e.config&&e.config.httpOptions)throw new Error("The Live module does not support httpOptions at request-level in LiveConnectConfig yet. Please use the client-level httpOptions configuration instead.");const l=this.apiClient.getWebsocketBaseUrl(),a=this.apiClient.getApiVersion();let u;const c=this.apiClient.getHeaders();e.config&&e.config.tools&&mo(e.config.tools)&&fo(c);const p=function(e){const t=new Headers;for(const[n,o]of Object.entries(e))t.append(n,o);return t}(c);if(this.apiClient.isVertexAI()){const e=this.apiClient.getProject(),t=this.apiClient.getLocation(),n=this.apiClient.getApiKey(),o=!!e&&!!t||!!n;this.apiClient.getCustomBaseUrl()&&!o?u=l:(u=`${l}/ws/google.cloud.aiplatform.${a}.LlmBidiService/BidiGenerateContent`,await this.auth.addAuthHeaders(p,u))}else{const e=this.apiClient.getApiKey();let t="BidiGenerateContent",n="key";(null==e?void 0:e.startsWith("auth_tokens/"))&&(t="BidiGenerateContentConstrained",n="access_token"),u=`${l}/ws/google.ai.generativelanguage.${a}.GenerativeService.${t}?${n}=${e}`}let d=()=>{};const m=new Promise(e=>{d=e}),f=e.callbacks,h=this.apiClient;let g=!1;const v=[];let _=()=>{};const E=new Promise(e=>{_=e}),y={onopen:function(){var e;null===(e=null==f?void 0:f.onopen)||void 0===e||e.call(f),d({})},onmessage:e=>{!async function(e,t,n){const o=new Rt;let i;i=n.data instanceof Blob?await n.data.text():n.data instanceof ArrayBuffer?(new TextDecoder).decode(n.data):n.data;const r=JSON.parse(i);if(e.isVertexAI()){const e=function(e){const t={},n=Ze(e,["setupComplete"]);null!=n&&ze(t,["setupComplete"],n);const o=Ze(e,["serverContent"]);null!=o&&ze(t,["serverContent"],o);const i=Ze(e,["toolCall"]);null!=i&&ze(t,["toolCall"],i);const r=Ze(e,["toolCallCancellation"]);null!=r&&ze(t,["toolCallCancellation"],r);const s=Ze(e,["usageMetadata"]);null!=s&&ze(t,["usageMetadata"],function(e){const t={},n=Ze(e,["candidatesTokenCount"]);null!=n&&ze(t,["responseTokenCount"],n);const o=Ze(e,["candidatesTokensDetails"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["responseTokensDetails"],e)}const i=Ze(e,["cacheTokensDetails"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["cacheTokensDetails"],e)}const r=Ze(e,["cachedContentTokenCount"]);null!=r&&ze(t,["cachedContentTokenCount"],r);const s=Ze(e,["promptTokenCount"]);null!=s&&ze(t,["promptTokenCount"],s);const l=Ze(e,["promptTokensDetails"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["promptTokensDetails"],e)}const a=Ze(e,["thoughtsTokenCount"]);null!=a&&ze(t,["thoughtsTokenCount"],a);const u=Ze(e,["toolUsePromptTokenCount"]);null!=u&&ze(t,["toolUsePromptTokenCount"],u);const c=Ze(e,["toolUsePromptTokensDetails"]);if(null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["toolUsePromptTokensDetails"],e)}const p=Ze(e,["totalTokenCount"]);null!=p&&ze(t,["totalTokenCount"],p);const d=Ze(e,["trafficType"]);return null!=d&&ze(t,["trafficType"],d),t}(s));const l=Ze(e,["goAway"]);null!=l&&ze(t,["goAway"],l);const a=Ze(e,["sessionResumptionUpdate"]);null!=a&&ze(t,["sessionResumptionUpdate"],a);const u=Ze(e,["voiceActivityDetectionSignal"]);null!=u&&ze(t,["voiceActivityDetectionSignal"],u);const c=Ze(e,["voiceActivity"]);return null!=c&&ze(t,["voiceActivity"],function(e){const t={},n=Ze(e,["type"]);null!=n&&ze(t,["voiceActivityType"],n);const o=Ze(e,["audioOffset"]);return null!=o&&ze(t,["audioOffset"],o),t}(c)),t}(r);Object.assign(o,e)}else Object.assign(o,r);var s;(s=o).setupComplete&&!b.setupComplete&&(b.setupComplete=s.setupComplete,_({})),g?f.onmessage(s):v.push(s)}(h,0,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){}},A=this.webSocketFactory.create(u,function(e){const t={};return e.forEach((e,n)=>{t[n]=e}),t}(p),y);A.connect(),await m;let I=Gt(this.apiClient,e.model);if(this.apiClient.isVertexAI()&&I.startsWith("publishers/")){const e=this.apiClient.getProject(),t=this.apiClient.getLocation();e&&t&&(I=`projects/${e}/locations/${t}/`+I)}let T={};this.apiClient.isVertexAI()&&void 0===(null===(o=e.config)||void 0===o?void 0:o.responseModalities)&&(void 0===e.config?e.config={responseModalities:[$.AUDIO]}:e.config.responseModalities=[$.AUDIO]),null===(i=e.config)||void 0===i||i.generationConfig;const C=null!==(s=null===(r=e.config)||void 0===r?void 0:r.tools)&&void 0!==s?s:[],S=[];for(const P of C)if(this.isCallableTool(P)){const e=P;S.push(await e.tool())}else S.push(P);S.length>0&&(e.config.tools=S);const O={model:I,config:e.config,callbacks:e.callbacks};T=this.apiClient.isVertexAI()?function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["setup","model"],Gt(e,o));const i=Ze(t,["config"]);return null!=i&&ze(n,["config"],Mn(i,n)),n}(this.apiClient,O):function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["setup","model"],Gt(e,o));const i=Ze(t,["config"]);return null!=i&&ze(n,["config"],kn(i,n)),n}(this.apiClient,O),delete T.config;const b=new Io(A,this.apiClient);A.send(JSON.stringify(T)),await E,g=!0;for(const P of v)f.onmessage(P);return b}isCallableTool(e){return"callTool"in e&&"function"==typeof e.callTool}},Ao={turnComplete:!0},Io=class{constructor(e,t){this.conn=e,this.apiClient=t}tLiveClientContent(e,t){if(null!==t.turns&&void 0!==t.turns){let n=[];try{n=Jt(t.turns),e.isVertexAI()||(n=n.map(e=>Hn(e)))}catch(vr){throw new 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)throw new Error("functionResponses is required.");if(n=Array.isArray(t.functionResponses)?t.functionResponses:[t.functionResponses],0===n.length)throw new Error("functionResponses is required.");for(const o of n){if("object"!=typeof o||null===o||!("name"in o)||!("response"in o))throw new Error(`Could not parse function response, type '${typeof o}'.`);if(!e.isVertexAI()&&!("id"in o))throw new 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({},Ao),e);const t=this.tLiveClientContent(this.apiClient,e);this.conn.send(JSON.stringify(t))}sendRealtimeInput(e){let t={};t=this.apiClient.isVertexAI()?{realtimeInput:Un(e)}:{realtimeInput:xn(e)},this.conn.send(JSON.stringify(t))}sendToolResponse(e){if(null==e.functionResponses)throw new Error("Tool response parameters are required.");const t=this.tLiveClienttToolResponse(this.apiClient,e);this.conn.send(JSON.stringify(t))}close(){this.conn.close()}};function To(e){var t,n,o;if(null===(t=null==e?void 0:e.automaticFunctionCalling)||void 0===t?void 0:t.disable)return!0;let i=!1;for(const s of null!==(n=null==e?void 0:e.tools)&&void 0!==n?n:[])if(Co(s)){i=!0;break}if(!i)return!0;const r=null===(o=null==e?void 0:e.automaticFunctionCalling)||void 0===o?void 0:o.maximumRemoteCalls;return!!(r&&(r<0||!Number.isInteger(r))||0==r)}function Co(e){return"callTool"in e&&"function"==typeof e.callTool}function So(e){var t;const n=[];return(null===(t=null==e?void 0:e.config)||void 0===t?void 0:t.tools)?(e.config.tools.forEach((e,t)=>{if(Co(e))return;const o=e;o.functionDeclarations&&o.functionDeclarations.length>0&&n.push(t)}),n):n}function Oo(e){var t;return!(null===(t=null==e?void 0:e.automaticFunctionCalling)||void 0===t?void 0:t.ignoreCallHistory)}var bo=class e extends Ke{constructor(t){super(),this.apiClient=t,this.embedContent=async e=>{if(!this.apiClient.isVertexAI())return e.model.includes("gemini-embedding-2")&&(e.contents=Jt(e.contents)),await this.embedContentInternal(e);if(e.model.includes("gemini")&&"gemini-embedding-001"!==e.model||e.model.includes("maas")){const t=Jt(e.contents);if(t.length>1)throw new Error("The embedContent API for this model only supports one content at a time.");const n=Object.assign(Object.assign({},e),{content:t[0],embeddingApiType:ve.EMBED_CONTENT});return await this.embedContentInternal(n)}{const t=Object.assign(Object.assign({},e),{embeddingApiType:ve.PREDICT});return await this.embedContentInternal(t)}},this.generateContent=async e=>{var t,n,o,i,r;const s=await this.processParamsMaybeAddMcpUsage(e);if(this.maybeMoveToResponseJsonSchema(e),!function(e){var t,n,o;return null!==(o=null===(n=null===(t=e.config)||void 0===t?void 0:t.tools)||void 0===n?void 0:n.some(e=>Co(e)))&&void 0!==o&&o}(e)||To(e.config))return await this.generateContentInternal(s);const l=So(e);if(l.length>0){const e=l.map(e=>`tools[${e}]`).join(", ");throw new Error(`Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations is not yet supported. Incompatible tools found at ${e}.`)}let a,u;const c=Jt(s.contents),p=null!==(o=null===(n=null===(t=s.config)||void 0===t?void 0:t.automaticFunctionCalling)||void 0===n?void 0:n.maximumRemoteCalls)&&void 0!==o?o:10;let d=0;for(;d<p&&(a=await this.generateContentInternal(s),a.functionCalls&&0!==a.functionCalls.length);){const t=a.candidates[0].content,n=[];for(const o of null!==(r=null===(i=e.config)||void 0===i?void 0:i.tools)&&void 0!==r?r:[])if(Co(o)){const e=await o.callTool(a.functionCalls);n.push(...e)}d++,u={role:"user",parts:n},s.contents=Jt(s.contents),s.contents.push(t),s.contents.push(u),Oo(s.config)&&(c.push(t),c.push(u))}return Oo(s.config)&&(a.automaticFunctionCallingHistory=c),a},this.generateContentStream=async e=>{var t,n,o,i,r;if(this.maybeMoveToResponseJsonSchema(e),To(e.config)){const t=await this.processParamsMaybeAddMcpUsage(e);return await this.generateContentStreamInternal(t)}const s=So(e);if(s.length>0){const e=s.map(e=>`tools[${e}]`).join(", ");throw new Error(`Incompatible tools found at ${e}. Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations" is not yet supported.`)}const l=null===(o=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===o?void 0:o.streamFunctionCallArguments,a=null===(r=null===(i=null==e?void 0:e.config)||void 0===i?void 0:i.automaticFunctionCalling)||void 0===r?void 0:r.disable;if(l&&!a)throw new 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 t=>(e.loggedGenerateImagesWarning||(e.loggedGenerateImagesWarning=!0),await this.generateImagesInternal(t).then(e=>{var t;let n;const o=[];if(null==e?void 0:e.generatedImages)for(const r of e.generatedImages)r&&(null==r?void 0:r.safetyAttributes)&&"Positive Prompt"===(null===(t=null==r?void 0:r.safetyAttributes)||void 0===t?void 0:t.contentType)?n=null==r?void 0:r.safetyAttributes:o.push(r);let i;return i=n?{generatedImages:o,positivePromptSafetyAttributes:n,sdkHttpResponse:e.sdkHttpResponse}:{generatedImages:o,sdkHttpResponse:e.sdkHttpResponse},i})),this.list=async e=>{var t;const 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 new Error("Filtering tuned models list is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");n.config.filter="labels.tune-type:*"}return new vn(nt.PAGED_ITEM_MODELS,e=>this.listInternal(e),await this.listInternal(n),n)},this.editImage=async t=>{e.loggedEditImageWarning||(e.loggedEditImageWarning=!0);const n={model:t.model,prompt:t.prompt,referenceImages:[],config:t.config};return t.referenceImages&&t.referenceImages&&(n.referenceImages=t.referenceImages.map(e=>e.toReferenceImageAPI())),await this.editImageInternal(n)},this.upscaleImage=async e=>{let t={numberOfImages:1,mode:"upscale"};e.config&&(t=Object.assign(Object.assign({},t),e.config));const n={model:e.model,image:e.image,upscaleFactor:e.upscaleFactor,config:t};return await this.upscaleImageInternal(n)},this.generateVideos=async t=>{var n,o,i,r,s,l;if((t.prompt||t.image||t.video)&&t.source)throw new Error("Source and prompt/image/video are mutually exclusive. Please only use source.");return(t.prompt||t.image||t.video)&&(e.loggedGenerateVideosWarning||(e.loggedGenerateVideosWarning=!0)),this.apiClient.isVertexAI()||((null===(n=t.video)||void 0===n?void 0:n.uri)&&(null===(o=t.video)||void 0===o?void 0:o.videoBytes)?t.video={uri:t.video.uri,mimeType:t.video.mimeType}:(null===(r=null===(i=t.source)||void 0===i?void 0:i.video)||void 0===r?void 0:r.uri)&&(null===(l=null===(s=t.source)||void 0===s?void 0:s.video)||void 0===l?void 0:l.videoBytes)&&(t.source.video={uri:t.source.video.uri,mimeType:t.source.video.mimeType})),await this.generateVideosInternal(t)}}maybeMoveToResponseJsonSchema(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,o;const i=null===(t=e.config)||void 0===t?void 0:t.tools;if(!i)return e;const r=await Promise.all(i.map(async e=>Co(e)?await e.tool():e)),s={model:e.model,contents:e.contents,config:Object.assign(Object.assign({},e.config),{tools:r})};if(s.config.tools=r,e.config&&e.config.tools&&mo(e.config.tools)){const t=null!==(o=null===(n=e.config.httpOptions)||void 0===n?void 0:n.headers)&&void 0!==o?o:{};let i=Object.assign({},t);0===Object.keys(i).length&&(i=this.apiClient.getDefaultHeaders()),fo(i),s.config.httpOptions=Object.assign(Object.assign({},e.config.httpOptions),{headers:i})}return s}async initAfcToolsMap(e){var t,n,o;const i=/* @__PURE__ */new Map;for(const r of null!==(n=null===(t=e.config)||void 0===t?void 0:t.tools)&&void 0!==n?n:[])if(Co(r)){const e=r,t=await e.tool();for(const n of null!==(o=t.functionDeclarations)&&void 0!==o?o:[]){if(!n.name)throw new Error("Function declaration name is required.");if(i.has(n.name))throw new Error(`Duplicate tool declaration name: ${n.name}`);i.set(n.name,e)}}return i}async processAfcStream(e){var t,n,o;const i=null!==(o=null===(n=null===(t=e.config)||void 0===t?void 0:t.automaticFunctionCalling)||void 0===n?void 0:n.maximumRemoteCalls)&&void 0!==o?o:10;let r=!1,s=0;return function(e,t,n){return Cn(this,arguments,function*(){for(var o,l,a,u,c,p;s<i;){r&&(s++,r=!1);const g=yield Tn(e.processParamsMaybeAddMcpUsage(n)),v=yield Tn(e.generateContentStreamInternal(g)),_=[],E=[];try{for(var d,m=!0,f=(l=void 0,Sn(v));!(o=(d=yield Tn(f.next())).done);m=!0){u=d.value,m=!1;const e=u;if(yield yield Tn(e),e.candidates&&(null===(c=e.candidates[0])||void 0===c?void 0:c.content)){E.push(e.candidates[0].content);for(const n of null!==(p=e.candidates[0].content.parts)&&void 0!==p?p:[])if(s<i&&n.functionCall){if(!n.functionCall.name)throw new Error("Function call name was not returned by the model.");if(!t.has(n.functionCall.name))throw new Error(`Automatic function calling was requested, but not all the tools the model used implement the CallableTool interface. Available tools: ${t.keys()}, missing tool: ${n.functionCall.name}`);{const e=yield Tn(t.get(n.functionCall.name).callTool([n.functionCall]));_.push(...e)}}}}}catch(h){l={error:h}}finally{try{m||o||!(a=f.return)||(yield Tn(a.call(f)))}finally{if(l)throw l.error}}if(!(_.length>0))break;{r=!0;const e=new it;e.candidates=[{content:{role:"user",parts:_}}],yield yield Tn(e);const t=[];t.push(...E),t.push({role:"user",parts:_}),n.contents=Jt(n.contents).concat(t)}}})}(this,await this.initAfcToolsMap(e),e)}async generateContentInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=Bn(this.apiClient,e);return s=We("{model}:generateContent",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=Xn(e),n=new it;return Object.assign(n,t),n})}{const t=jn(this.apiClient,e);return s=We("{model}:generateContent",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=Vn(e),n=new it;return Object.assign(n,t),n})}}async generateContentStreamInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=Bn(this.apiClient,e);return s=We("{model}:streamGenerateContent?alt=sse",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.requestStream({path:s,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}),r.then(function(e){return Cn(this,arguments,function*(){var t,n,o,i;try{for(var r,s=!0,l=Sn(e);!(t=(r=yield Tn(l.next())).done);s=!0){i=r.value,s=!1;const e=i,t=Xn(yield Tn(e.json()));t.sdkHttpResponse={headers:e.headers};const n=new it;Object.assign(n,t),yield yield Tn(n)}}catch(a){n={error:a}}finally{try{s||t||!(o=l.return)||(yield Tn(o.call(l)))}finally{if(n)throw n.error}}})})}{const t=jn(this.apiClient,e);return s=We("{model}:streamGenerateContent?alt=sse",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.requestStream({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}),r.then(function(e){return Cn(this,arguments,function*(){var t,n,o,i;try{for(var r,s=!0,l=Sn(e);!(t=(r=yield Tn(l.next())).done);s=!0){i=r.value,s=!1;const e=i,t=Vn(yield Tn(e.json()));t.sdkHttpResponse={headers:e.headers};const n=new it;Object.assign(n,t),yield yield Tn(n)}}catch(a){n={error:a}}finally{try{s||t||!(o=l.return)||(yield Tn(o.call(l)))}finally{if(n)throw n.error}}})})}}async embedContentInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t,n){const o={},i=Ze(t,["model"]);null!=i&&ze(o,["_url","model"],Gt(e,i));let r=Ze(n,["embeddingApiType"]);if(void 0===r&&(r="PREDICT"),"PREDICT"===r){const n=Ze(t,["contents"]);if(null!=n){let t=Xt(e,n);Array.isArray(t)&&(t=t.map(e=>e)),ze(o,["instances[]","content"],t)}}let s=Ze(n,["embeddingApiType"]);if(void 0===s&&(s="PREDICT"),"EMBED_CONTENT"===s){const e=Ze(t,["content"]);null!=e&&ze(o,["content"],Fn(Vt(e)))}const l=Ze(t,["config"]);return null!=l&&function(e,t,n){let o=Ze(n,["embeddingApiType"]);if(void 0===o&&(o="PREDICT"),"PREDICT"===o){const n=Ze(e,["taskType"]);void 0!==t&&null!=n&&ze(t,["instances[]","task_type"],n)}else if("EMBED_CONTENT"===o){const n=Ze(e,["taskType"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","taskType"],n)}let i=Ze(n,["embeddingApiType"]);if(void 0===i&&(i="PREDICT"),"PREDICT"===i){const n=Ze(e,["title"]);void 0!==t&&null!=n&&ze(t,["instances[]","title"],n)}else if("EMBED_CONTENT"===i){const n=Ze(e,["title"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","title"],n)}let r=Ze(n,["embeddingApiType"]);if(void 0===r&&(r="PREDICT"),"PREDICT"===r){const n=Ze(e,["outputDimensionality"]);void 0!==t&&null!=n&&ze(t,["parameters","outputDimensionality"],n)}else if("EMBED_CONTENT"===r){const n=Ze(e,["outputDimensionality"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","outputDimensionality"],n)}let s=Ze(n,["embeddingApiType"]);if(void 0===s&&(s="PREDICT"),"PREDICT"===s){const n=Ze(e,["mimeType"]);void 0!==t&&null!=n&&ze(t,["instances[]","mimeType"],n)}let l=Ze(n,["embeddingApiType"]);if(void 0===l&&(l="PREDICT"),"PREDICT"===l){const n=Ze(e,["autoTruncate"]);void 0!==t&&null!=n&&ze(t,["parameters","autoTruncate"],n)}else if("EMBED_CONTENT"===l){const n=Ze(e,["autoTruncate"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","autoTruncate"],n)}let a=Ze(n,["embeddingApiType"]);if(void 0===a&&(a="PREDICT"),"EMBED_CONTENT"===a){const n=Ze(e,["documentOcr"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","documentOcr"],n)}let u=Ze(n,["embeddingApiType"]);if(void 0===u&&(u="PREDICT"),"EMBED_CONTENT"===u){const n=Ze(e,["audioTrackExtraction"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","audioTrackExtraction"],n)}}(l,o,n),o}(this.apiClient,e,e);return s=We((a=e.model).includes("gemini")&&"gemini-embedding-001"!==a||a.includes("maas")?"{model}:embedContent":"{model}:predict",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(t=>{const n=function(e,t){const n={},o=Ze(e,["sdkHttpResponse"]);null!=o&&ze(n,["sdkHttpResponse"],o);const i=Ze(e,["predictions[]","embeddings"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["values"]);null!=n&&ze(t,["values"],n);const o=Ze(e,["statistics"]);return null!=o&&ze(t,["statistics"],function(e){const t={},n=Ze(e,["truncated"]);null!=n&&ze(t,["truncated"],n);const o=Ze(e,["token_count"]);null!=o&&ze(t,["tokenCount"],o);const i=Ze(e,["tokensDetails"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["tokensDetails"],e)}return t}(o)),t}(e))),ze(n,["embeddings"],e)}const r=Ze(e,["metadata"]);if(null!=r&&ze(n,["metadata"],r),t&&"EMBED_CONTENT"===Ze(t,["embeddingApiType"])){const t=Ze(e,["embedding"]),o=Ze(e,["usageMetadata"]),i=Ze(e,["truncated"]);if(t){const e={};o&&o.promptTokenCount&&(e.tokenCount=o.promptTokenCount),o&&o.promptTokensDetails&&(e.tokensDetails=o.promptTokensDetails),i&&(e.truncated=i),t.statistics=e,ze(n,["embeddings"],[t])}}return n}(t,e),o=new rt;return Object.assign(o,n),o})}{const t=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["contents"]);if(null!=i){let t=Xt(e,i);Array.isArray(t)&&(t=t.map(e=>e)),ze(n,["requests[]","content"],t)}const r=Ze(t,["content"]);null!=r&&Hn(Vt(r));const s=Ze(t,["config"]);null!=s&&function(e,t){const n=Ze(e,["taskType"]);void 0!==t&&null!=n&&ze(t,["requests[]","taskType"],n);const o=Ze(e,["title"]);void 0!==t&&null!=o&&ze(t,["requests[]","title"],o);const i=Ze(e,["outputDimensionality"]);if(void 0!==t&&null!=i&&ze(t,["requests[]","outputDimensionality"],i),void 0!==Ze(e,["mimeType"]))throw new Error("mimeType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["autoTruncate"]))throw new Error("autoTruncate parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["documentOcr"]))throw new Error("documentOcr parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["audioTrackExtraction"]))throw new Error("audioTrackExtraction parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(s,n);const l=Ze(t,["model"]);return void 0!==l&&ze(n,["requests[]","model"],Gt(e,l)),n}(this.apiClient,e);return s=We("{model}:batchEmbedContents",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["embeddings"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["embeddings"],e)}const i=Ze(e,["metadata"]);return null!=i&&ze(t,["metadata"],i),t}(e),n=new rt;return Object.assign(n,t),n})}var a}async generateImagesInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["prompt"]);null!=i&&ze(n,["instances[0]","prompt"],i);const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["outputGcsUri"]);void 0!==t&&null!=n&&ze(t,["parameters","storageUri"],n);const o=Ze(e,["negativePrompt"]);void 0!==t&&null!=o&&ze(t,["parameters","negativePrompt"],o);const i=Ze(e,["numberOfImages"]);void 0!==t&&null!=i&&ze(t,["parameters","sampleCount"],i);const r=Ze(e,["aspectRatio"]);void 0!==t&&null!=r&&ze(t,["parameters","aspectRatio"],r);const s=Ze(e,["guidanceScale"]);void 0!==t&&null!=s&&ze(t,["parameters","guidanceScale"],s);const l=Ze(e,["seed"]);void 0!==t&&null!=l&&ze(t,["parameters","seed"],l);const a=Ze(e,["safetyFilterLevel"]);void 0!==t&&null!=a&&ze(t,["parameters","safetySetting"],a);const u=Ze(e,["personGeneration"]);void 0!==t&&null!=u&&ze(t,["parameters","personGeneration"],u);const c=Ze(e,["includeSafetyAttributes"]);void 0!==t&&null!=c&&ze(t,["parameters","includeSafetyAttributes"],c);const p=Ze(e,["includeRaiReason"]);void 0!==t&&null!=p&&ze(t,["parameters","includeRaiReason"],p);const d=Ze(e,["language"]);void 0!==t&&null!=d&&ze(t,["parameters","language"],d);const m=Ze(e,["outputMimeType"]);void 0!==t&&null!=m&&ze(t,["parameters","outputOptions","mimeType"],m);const f=Ze(e,["outputCompressionQuality"]);void 0!==t&&null!=f&&ze(t,["parameters","outputOptions","compressionQuality"],f);const h=Ze(e,["addWatermark"]);void 0!==t&&null!=h&&ze(t,["parameters","addWatermark"],h);const g=Ze(e,["labels"]);void 0!==t&&null!=g&&ze(t,["labels"],g);const v=Ze(e,["imageSize"]);void 0!==t&&null!=v&&ze(t,["parameters","sampleImageSize"],v);const _=Ze(e,["enhancePrompt"]);void 0!==t&&null!=_&&ze(t,["parameters","enhancePrompt"],_)}(r,n),n}(this.apiClient,e);return i=We("{model}:predict",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["predictions"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>$n(e))),ze(t,["generatedImages"],e)}const i=Ze(e,["positivePromptSafetyAttributes"]);return null!=i&&ze(t,["positivePromptSafetyAttributes"],eo(i)),t}(e),n=new st;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async editImageInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["prompt"]);null!=i&&ze(n,["instances[0]","prompt"],i);const r=Ze(t,["referenceImages"]);if(null!=r){let e=r;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["referenceImage"]);null!=n&&ze(t,["referenceImage"],zn(n));const o=Ze(e,["referenceId"]);null!=o&&ze(t,["referenceId"],o);const i=Ze(e,["referenceType"]);null!=i&&ze(t,["referenceType"],i);const r=Ze(e,["maskImageConfig"]);null!=r&&ze(t,["maskImageConfig"],function(e){const t={},n=Ze(e,["maskMode"]);null!=n&&ze(t,["maskMode"],n);const o=Ze(e,["segmentationClasses"]);null!=o&&ze(t,["maskClasses"],o);const i=Ze(e,["maskDilation"]);return null!=i&&ze(t,["dilation"],i),t}(r));const s=Ze(e,["controlImageConfig"]);null!=s&&ze(t,["controlImageConfig"],function(e){const t={},n=Ze(e,["controlType"]);null!=n&&ze(t,["controlType"],n);const o=Ze(e,["enableControlImageComputation"]);return null!=o&&ze(t,["computeControl"],o),t}(s));const l=Ze(e,["styleImageConfig"]);null!=l&&ze(t,["styleImageConfig"],l);const a=Ze(e,["subjectImageConfig"]);return null!=a&&ze(t,["subjectImageConfig"],a),t}(e))),ze(n,["instances[0]","referenceImages"],e)}const s=Ze(t,["config"]);return null!=s&&function(e,t){const n=Ze(e,["outputGcsUri"]);void 0!==t&&null!=n&&ze(t,["parameters","storageUri"],n);const o=Ze(e,["negativePrompt"]);void 0!==t&&null!=o&&ze(t,["parameters","negativePrompt"],o);const i=Ze(e,["numberOfImages"]);void 0!==t&&null!=i&&ze(t,["parameters","sampleCount"],i);const r=Ze(e,["aspectRatio"]);void 0!==t&&null!=r&&ze(t,["parameters","aspectRatio"],r);const s=Ze(e,["guidanceScale"]);void 0!==t&&null!=s&&ze(t,["parameters","guidanceScale"],s);const l=Ze(e,["seed"]);void 0!==t&&null!=l&&ze(t,["parameters","seed"],l);const a=Ze(e,["safetyFilterLevel"]);void 0!==t&&null!=a&&ze(t,["parameters","safetySetting"],a);const u=Ze(e,["personGeneration"]);void 0!==t&&null!=u&&ze(t,["parameters","personGeneration"],u);const c=Ze(e,["includeSafetyAttributes"]);void 0!==t&&null!=c&&ze(t,["parameters","includeSafetyAttributes"],c);const p=Ze(e,["includeRaiReason"]);void 0!==t&&null!=p&&ze(t,["parameters","includeRaiReason"],p);const d=Ze(e,["language"]);void 0!==t&&null!=d&&ze(t,["parameters","language"],d);const m=Ze(e,["outputMimeType"]);void 0!==t&&null!=m&&ze(t,["parameters","outputOptions","mimeType"],m);const f=Ze(e,["outputCompressionQuality"]);void 0!==t&&null!=f&&ze(t,["parameters","outputOptions","compressionQuality"],f);const h=Ze(e,["addWatermark"]);void 0!==t&&null!=h&&ze(t,["parameters","addWatermark"],h);const g=Ze(e,["labels"]);void 0!==t&&null!=g&&ze(t,["labels"],g);const v=Ze(e,["editMode"]);void 0!==t&&null!=v&&ze(t,["parameters","editMode"],v);const _=Ze(e,["baseSteps"]);void 0!==t&&null!=_&&ze(t,["parameters","editConfig","baseSteps"],_)}(s,n),n}(this.apiClient,e);return i=We("{model}:predict",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["predictions"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>$n(e))),ze(t,["generatedImages"],e)}return t}(e),n=new lt;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async upscaleImageInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["image"]);null!=i&&ze(n,["instances[0]","image"],zn(i));const r=Ze(t,["upscaleFactor"]);null!=r&&ze(n,["parameters","upscaleConfig","upscaleFactor"],r);const s=Ze(t,["config"]);return null!=s&&function(e,t){const n=Ze(e,["outputGcsUri"]);void 0!==t&&null!=n&&ze(t,["parameters","storageUri"],n);const o=Ze(e,["safetyFilterLevel"]);void 0!==t&&null!=o&&ze(t,["parameters","safetySetting"],o);const i=Ze(e,["personGeneration"]);void 0!==t&&null!=i&&ze(t,["parameters","personGeneration"],i);const r=Ze(e,["includeRaiReason"]);void 0!==t&&null!=r&&ze(t,["parameters","includeRaiReason"],r);const s=Ze(e,["outputMimeType"]);void 0!==t&&null!=s&&ze(t,["parameters","outputOptions","mimeType"],s);const l=Ze(e,["outputCompressionQuality"]);void 0!==t&&null!=l&&ze(t,["parameters","outputOptions","compressionQuality"],l);const a=Ze(e,["enhanceInputImage"]);void 0!==t&&null!=a&&ze(t,["parameters","upscaleConfig","enhanceInputImage"],a);const u=Ze(e,["imagePreservationFactor"]);void 0!==t&&null!=u&&ze(t,["parameters","upscaleConfig","imagePreservationFactor"],u);const c=Ze(e,["labels"]);void 0!==t&&null!=c&&ze(t,["labels"],c);const p=Ze(e,["numberOfImages"]);void 0!==t&&null!=p&&ze(t,["parameters","sampleCount"],p);const d=Ze(e,["mode"]);void 0!==t&&null!=d&&ze(t,["parameters","mode"],d)}(s,n),n}(this.apiClient,e);return i=We("{model}:predict",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["predictions"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>$n(e))),ze(t,["generatedImages"],e)}return t}(e),n=new at;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async recontextImage(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["source"]);null!=i&&function(e,t){const n=Ze(e,["prompt"]);void 0!==t&&null!=n&&ze(t,["instances[0]","prompt"],n);const o=Ze(e,["personImage"]);void 0!==t&&null!=o&&ze(t,["instances[0]","personImage","image"],zn(o));const i=Ze(e,["productImages"]);if(void 0!==t&&null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["productImage"]);return null!=n&&ze(t,["image"],zn(n)),t}(e))),ze(t,["instances[0]","productImages"],e)}}(i,n);const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["numberOfImages"]);void 0!==t&&null!=n&&ze(t,["parameters","sampleCount"],n);const o=Ze(e,["baseSteps"]);void 0!==t&&null!=o&&ze(t,["parameters","baseSteps"],o);const i=Ze(e,["outputGcsUri"]);void 0!==t&&null!=i&&ze(t,["parameters","storageUri"],i);const r=Ze(e,["seed"]);void 0!==t&&null!=r&&ze(t,["parameters","seed"],r);const s=Ze(e,["safetyFilterLevel"]);void 0!==t&&null!=s&&ze(t,["parameters","safetySetting"],s);const l=Ze(e,["personGeneration"]);void 0!==t&&null!=l&&ze(t,["parameters","personGeneration"],l);const a=Ze(e,["addWatermark"]);void 0!==t&&null!=a&&ze(t,["parameters","addWatermark"],a);const u=Ze(e,["outputMimeType"]);void 0!==t&&null!=u&&ze(t,["parameters","outputOptions","mimeType"],u);const c=Ze(e,["outputCompressionQuality"]);void 0!==t&&null!=c&&ze(t,["parameters","outputOptions","compressionQuality"],c);const p=Ze(e,["enhancePrompt"]);void 0!==t&&null!=p&&ze(t,["parameters","enhancePrompt"],p);const d=Ze(e,["labels"]);void 0!==t&&null!=d&&ze(t,["labels"],d)}(r,n),n}(this.apiClient,e);return i=We("{model}:predict",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["predictions"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>$n(e))),ze(t,["generatedImages"],e)}return t}(e),n=new ut;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async segmentImage(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["source"]);null!=i&&function(e,t){const n=Ze(e,["prompt"]);void 0!==t&&null!=n&&ze(t,["instances[0]","prompt"],n);const o=Ze(e,["image"]);void 0!==t&&null!=o&&ze(t,["instances[0]","image"],zn(o));const i=Ze(e,["scribbleImage"]);void 0!==t&&null!=i&&ze(t,["instances[0]","scribble"],function(e){const t={},n=Ze(e,["image"]);return null!=n&&ze(t,["image"],zn(n)),t}(i))}(i,n);const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["mode"]);void 0!==t&&null!=n&&ze(t,["parameters","mode"],n);const o=Ze(e,["maxPredictions"]);void 0!==t&&null!=o&&ze(t,["parameters","maxPredictions"],o);const i=Ze(e,["confidenceThreshold"]);void 0!==t&&null!=i&&ze(t,["parameters","confidenceThreshold"],i);const r=Ze(e,["maskDilation"]);void 0!==t&&null!=r&&ze(t,["parameters","maskDilation"],r);const s=Ze(e,["binaryColorThreshold"]);void 0!==t&&null!=s&&ze(t,["parameters","binaryColorThreshold"],s);const l=Ze(e,["labels"]);void 0!==t&&null!=l&&ze(t,["labels"],l)}(r,n),n}(this.apiClient,e);return i=We("{model}:predict",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["predictions"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["_self"]);null!=n&&ze(t,["mask"],Kn(n));const o=Ze(e,["labels"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["labels"],e)}return t}(e))),ze(t,["generatedMasks"],e)}return t}(e),n=new ct;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async get(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);return null!=o&&ze(n,["_url","name"],Gt(e,o)),n}(this.apiClient,e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>Qn(e))}{const t=function(e,t){const n={},o=Ze(t,["model"]);return null!=o&&ze(n,["_url","name"],Gt(e,o)),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>Zn(e))}}async listInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["config"]);return null!=o&&function(e,t,n){const o=Ze(t,["pageSize"]);void 0!==n&&null!=o&&ze(n,["_query","pageSize"],o);const i=Ze(t,["pageToken"]);void 0!==n&&null!=i&&ze(n,["_query","pageToken"],i);const r=Ze(t,["filter"]);void 0!==n&&null!=r&&ze(n,["_query","filter"],r);const s=Ze(t,["queryBase"]);void 0!==n&&null!=s&&ze(n,["_url","models_url"],on(e,s))}(e,o,n),n}(this.apiClient,e);return s=We("{models_url}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["_self"]);if(null!=i){let e=rn(i);Array.isArray(e)&&(e=e.map(e=>Qn(e))),ze(t,["models"],e)}return t}(e),n=new pt;return Object.assign(n,t),n})}{const t=function(e,t){const n={},o=Ze(t,["config"]);return null!=o&&function(e,t,n){const o=Ze(t,["pageSize"]);void 0!==n&&null!=o&&ze(n,["_query","pageSize"],o);const i=Ze(t,["pageToken"]);void 0!==n&&null!=i&&ze(n,["_query","pageToken"],i);const r=Ze(t,["filter"]);void 0!==n&&null!=r&&ze(n,["_query","filter"],r);const s=Ze(t,["queryBase"]);void 0!==n&&null!=s&&ze(n,["_url","models_url"],on(e,s))}(e,o,n),n}(this.apiClient,e);return s=We("{models_url}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["_self"]);if(null!=i){let e=rn(i);Array.isArray(e)&&(e=e.map(e=>Zn(e))),ze(t,["models"],e)}return t}(e),n=new pt;return Object.assign(n,t),n})}}async update(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["displayName"]);void 0!==t&&null!=n&&ze(t,["displayName"],n);const o=Ze(e,["description"]);void 0!==t&&null!=o&&ze(t,["description"],o);const i=Ze(e,["defaultCheckpointId"]);void 0!==t&&null!=i&&ze(t,["defaultCheckpointId"],i)}(i,n),n}(this.apiClient,e);return s=We("{model}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(o),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()),r.then(e=>Qn(e))}{const t=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","name"],Gt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["displayName"]);void 0!==t&&null!=n&&ze(t,["displayName"],n);const o=Ze(e,["description"]);void 0!==t&&null!=o&&ze(t,["description"],o);const i=Ze(e,["defaultCheckpointId"]);void 0!==t&&null!=i&&ze(t,["defaultCheckpointId"],i)}(i,n),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"PATCH",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>Zn(e))}}async delete(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);return null!=o&&ze(n,["_url","name"],Gt(e,o)),n}(this.apiClient,e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new dt;return Object.assign(n,t),n})}{const t=function(e,t){const n={},o=Ze(t,["model"]);return null!=o&&ze(n,["_url","name"],Gt(e,o)),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"DELETE",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new dt;return Object.assign(n,t),n})}}async countTokens(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["contents"]);if(null!=i){let e=Jt(i);Array.isArray(e)&&(e=e.map(e=>Fn(e))),ze(n,["contents"],e)}const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["systemInstruction"]);void 0!==t&&null!=n&&ze(t,["systemInstruction"],Fn(Vt(n)));const o=Ze(e,["tools"]);if(void 0!==t&&null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>no(e))),ze(t,["tools"],e)}const i=Ze(e,["generationConfig"]);void 0!==t&&null!=i&&ze(t,["generationConfig"],function(e){const t={},n=Ze(e,["modelSelectionConfig"]);null!=n&&ze(t,["modelConfig"],n);const o=Ze(e,["responseJsonSchema"]);null!=o&&ze(t,["responseJsonSchema"],o);const i=Ze(e,["audioTranscriptionConfig"]);null!=i&&ze(t,["audioTranscriptionConfig"],i);const r=Ze(e,["audioTimestamp"]);null!=r&&ze(t,["audioTimestamp"],r);const s=Ze(e,["candidateCount"]);null!=s&&ze(t,["candidateCount"],s);const l=Ze(e,["enableAffectiveDialog"]);null!=l&&ze(t,["enableAffectiveDialog"],l);const a=Ze(e,["frequencyPenalty"]);null!=a&&ze(t,["frequencyPenalty"],a);const u=Ze(e,["logprobs"]);null!=u&&ze(t,["logprobs"],u);const c=Ze(e,["maxOutputTokens"]);null!=c&&ze(t,["maxOutputTokens"],c);const p=Ze(e,["mediaResolution"]);null!=p&&ze(t,["mediaResolution"],p);const d=Ze(e,["presencePenalty"]);null!=d&&ze(t,["presencePenalty"],d);const m=Ze(e,["responseFormat"]);if(null!=m){let e=m;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["responseFormat"],e)}const f=Ze(e,["responseLogprobs"]);null!=f&&ze(t,["responseLogprobs"],f);const h=Ze(e,["responseMimeType"]);null!=h&&ze(t,["responseMimeType"],h);const g=Ze(e,["responseModalities"]);null!=g&&ze(t,["responseModalities"],g);const v=Ze(e,["responseSchema"]);null!=v&&ze(t,["responseSchema"],v);const _=Ze(e,["routingConfig"]);null!=_&&ze(t,["routingConfig"],_);const E=Ze(e,["seed"]);null!=E&&ze(t,["seed"],E);const y=Ze(e,["speechConfig"]);null!=y&&ze(t,["speechConfig"],to(y));const A=Ze(e,["stopSequences"]);null!=A&&ze(t,["stopSequences"],A);const I=Ze(e,["temperature"]);null!=I&&ze(t,["temperature"],I);const T=Ze(e,["thinkingConfig"]);null!=T&&ze(t,["thinkingConfig"],T);const C=Ze(e,["topK"]);null!=C&&ze(t,["topK"],C);const S=Ze(e,["topP"]);if(null!=S&&ze(t,["topP"],S),void 0!==Ze(e,["enableEnhancedCivicAnswers"]))throw new Error("enableEnhancedCivicAnswers parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["translationConfig"]))throw new Error("translationConfig parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(i))}(r,n),n}(this.apiClient,e);return s=We("{model}:countTokens",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["totalTokens"]);return null!=o&&ze(t,["totalTokens"],o),t}(e),n=new mt;return Object.assign(n,t),n})}{const t=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["contents"]);if(null!=i){let e=Jt(i);Array.isArray(e)&&(e=e.map(e=>Hn(e))),ze(n,["contents"],e)}const r=Ze(t,["config"]);return null!=r&&function(e){if(void 0!==Ze(e,["systemInstruction"]))throw new Error("systemInstruction parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["tools"]))throw new Error("tools parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["generationConfig"]))throw new Error("generationConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(r),n}(this.apiClient,e);return s=We("{model}:countTokens",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["totalTokens"]);null!=o&&ze(t,["totalTokens"],o);const i=Ze(e,["cachedContentTokenCount"]);return null!=i&&ze(t,["cachedContentTokenCount"],i),t}(e),n=new mt;return Object.assign(n,t),n})}}async computeTokens(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["contents"]);if(null!=i){let e=Jt(i);Array.isArray(e)&&(e=e.map(e=>Fn(e))),ze(n,["contents"],e)}return n}(this.apiClient,e);return i=We("{model}:computeTokens",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["tokensInfo"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["tokensInfo"],e)}return t}(e),n=new ft;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async generateVideosInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=Yn(this.apiClient,e);return s=We("{model}:predictLongRunning",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>{const t=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["videos"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["_self"]);return null!=n&&ze(t,["video"],function(e){const t={},n=Ze(e,["gcsUri"]);null!=n&&ze(t,["uri"],n);const o=Ze(e,["bytesBase64Encoded"]);null!=o&&ze(t,["videoBytes"],tn(o));const i=Ze(e,["mimeType"]);return null!=i&&ze(t,["mimeType"],i),t}(n)),t}(e))),ze(t,["generatedVideos"],e)}const o=Ze(e,["raiMediaFilteredCount"]);null!=o&&ze(t,["raiMediaFilteredCount"],o);const i=Ze(e,["raiMediaFilteredReasons"]);return null!=i&&ze(t,["raiMediaFilteredReasons"],i),t}(s)),t}(e),n=new ht;return Object.assign(n,t),n})}{const t=Jn(this.apiClient,e);return s=We("{model}:predictLongRunning",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>{const t=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response","generateVideoResponse"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["generatedSamples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["video"]);return null!=n&&ze(t,["video"],function(e){const t={},n=Ze(e,["uri"]);null!=n&&ze(t,["uri"],n);const o=Ze(e,["encodedVideo"]);null!=o&&ze(t,["videoBytes"],tn(o));const i=Ze(e,["encoding"]);return null!=i&&ze(t,["mimeType"],i),t}(n)),t}(e))),ze(t,["generatedVideos"],e)}const o=Ze(e,["raiMediaFilteredCount"]);null!=o&&ze(t,["raiMediaFilteredCount"],o);const i=Ze(e,["raiMediaFilteredReasons"]);return null!=i&&ze(t,["raiMediaFilteredReasons"],i),t}(s)),t}(e),n=new ht;return Object.assign(n,t),n})}}};bo.loggedGenerateImagesWarning=!1,bo.loggedEditImageWarning=!1,bo.loggedGenerateVideosWarning=!1;var Po=class extends Ke{constructor(e){super(),this.apiClient=e}async getVideosOperation(e){const t=e.operation,n=e.config;if(void 0===t.name||""===t.name)throw new Error("Operation name is required.");if(this.apiClient.isVertexAI()){const e=t.name.split("/operations/")[0];let o;n&&"httpOptions"in n&&(o=n.httpOptions);const i=await this.fetchPredictVideosOperationInternal({operationName:t.name,resourceName:e,config:{httpOptions:o}});return t._fromAPIResponse({apiResponse:i,_isVertexAI:!0})}{const e=await this.getVideosOperationInternal({operationName:t.name,config:n});return t._fromAPIResponse({apiResponse:e,_isVertexAI:!1})}}async get(e){const t=e.operation,n=e.config;if(void 0===t.name||""===t.name)throw new Error("Operation name is required.");if(this.apiClient.isVertexAI()){const e=t.name.split("/operations/")[0];let o;n&&"httpOptions"in n&&(o=n.httpOptions);const i=await this.fetchPredictVideosOperationInternal({operationName:t.name,resourceName:e,config:{httpOptions:o}});return t._fromAPIResponse({apiResponse:i,_isVertexAI:!0})}{const e=await this.getVideosOperationInternal({operationName:t.name,config:n});return t._fromAPIResponse({apiResponse:e,_isVertexAI:!1})}}async getVideosOperationInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e){const t={},n=Ze(e,["operationName"]);return null!=n&&ze(t,["_url","operationName"],n),t}(e);return s=We("{operationName}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r}{const t=function(e){const t={},n=Ze(e,["operationName"]);return null!=n&&ze(t,["_url","operationName"],n),t}(e);return s=We("{operationName}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r}}async fetchPredictVideosOperationInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e){const t={},n=Ze(e,["operationName"]);null!=n&&ze(t,["operationName"],n);const o=Ze(e,["resourceName"]);return null!=o&&ze(t,["_url","resourceName"],o),t}(e);return i=We("{resourceName}:fetchPredictOperation",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}};function wo(e,t,n){const o=Ze(t,["expireTime"]);void 0!==n&&null!=o&&ze(n,["expireTime"],o);const i=Ze(t,["newSessionExpireTime"]);void 0!==n&&null!=i&&ze(n,["newSessionExpireTime"],i);const r=Ze(t,["uses"]);void 0!==n&&null!=r&&ze(n,["uses"],r);const s=Ze(t,["liveConnectConstraints"]);void 0!==n&&null!=s&&ze(n,["bidiGenerateContentSetup"],function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["setup","model"],Gt(e,o));const i=Ze(t,["config"]);return null!=i&&ze(n,["config"],function(e,t){const n=Ze(e,["generationConfig"]);void 0!==t&&null!=n&&ze(t,["setup","generationConfig"],n);const o=Ze(e,["responseModalities"]);void 0!==t&&null!=o&&ze(t,["setup","generationConfig","responseModalities"],o);const i=Ze(e,["temperature"]);void 0!==t&&null!=i&&ze(t,["setup","generationConfig","temperature"],i);const r=Ze(e,["topP"]);void 0!==t&&null!=r&&ze(t,["setup","generationConfig","topP"],r);const s=Ze(e,["topK"]);void 0!==t&&null!=s&&ze(t,["setup","generationConfig","topK"],s);const l=Ze(e,["maxOutputTokens"]);void 0!==t&&null!=l&&ze(t,["setup","generationConfig","maxOutputTokens"],l);const a=Ze(e,["mediaResolution"]);void 0!==t&&null!=a&&ze(t,["setup","generationConfig","mediaResolution"],a);const u=Ze(e,["seed"]);void 0!==t&&null!=u&&ze(t,["setup","generationConfig","seed"],u);const c=Ze(e,["speechConfig"]);void 0!==t&&null!=c&&ze(t,["setup","generationConfig","speechConfig"],Wt(c));const p=Ze(e,["thinkingConfig"]);void 0!==t&&null!=p&&ze(t,["setup","generationConfig","thinkingConfig"],p);const d=Ze(e,["enableAffectiveDialog"]);void 0!==t&&null!=d&&ze(t,["setup","generationConfig","enableAffectiveDialog"],d);const m=Ze(e,["systemInstruction"]);void 0!==t&&null!=m&&ze(t,["setup","systemInstruction"],function(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);null!=n&&ze(t,["mediaResolution"],n);const o=Ze(e,["toolCall"]);null!=o&&ze(t,["toolCall"],o);const i=Ze(e,["toolResponse"]);null!=i&&ze(t,["toolResponse"],i);const r=Ze(e,["audioTranscription"]);null!=r&&ze(t,["audioTranscription"],r);const s=Ze(e,["codeExecutionResult"]);null!=s&&ze(t,["codeExecutionResult"],s);const l=Ze(e,["executableCode"]);null!=l&&ze(t,["executableCode"],l);const a=Ze(e,["fileData"]);null!=a&&ze(t,["fileData"],function(e){const t={};if(void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["fileUri"]);null!=n&&ze(t,["fileUri"],n);const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(a));const u=Ze(e,["functionCall"]);null!=u&&ze(t,["functionCall"],function(e){const t={},n=Ze(e,["args"]);null!=n&&ze(t,["args"],n);const o=Ze(e,["id"]);null!=o&&ze(t,["id"],o);const i=Ze(e,["name"]);if(null!=i&&ze(t,["name"],i),void 0!==Ze(e,["partialArgs"]))throw new Error("partialArgs parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["willContinue"]))throw new Error("willContinue parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(u));const c=Ze(e,["functionResponse"]);null!=c&&ze(t,["functionResponse"],c);const p=Ze(e,["inlineData"]);null!=p&&ze(t,["inlineData"],function(e){const t={},n=Ze(e,["data"]);if(null!=n&&ze(t,["data"],n),void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(p));const d=Ze(e,["text"]);null!=d&&ze(t,["text"],d);const m=Ze(e,["thought"]);null!=m&&ze(t,["thought"],m);const f=Ze(e,["thoughtSignature"]);null!=f&&ze(t,["thoughtSignature"],f);const h=Ze(e,["videoMetadata"]);null!=h&&ze(t,["videoMetadata"],h);const g=Ze(e,["partMetadata"]);null!=g&&ze(t,["partMetadata"],g);const v=Ze(e,["mediaProcessing"]);return null!=v&&ze(t,["mediaProcessing"],v),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}(Vt(m)));const f=Ze(e,["tools"]);if(void 0!==t&&null!=f){let e=Zt(f);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==Ze(e,["retrieval"]))throw new Error("retrieval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["googleMaps"]);null!=n&&ze(t,["googleMaps"],function(e){const t={},n=Ze(e,["authConfig"]);null!=n&&ze(t,["authConfig"],function(e){const t={},n=Ze(e,["apiKey"]);if(null!=n&&ze(t,["apiKey"],n),void 0!==Ze(e,["apiKeyConfig"]))throw new Error("apiKeyConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["authType"]))throw new Error("authType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["googleServiceAccountConfig"]))throw new Error("googleServiceAccountConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["httpBasicAuthConfig"]))throw new Error("httpBasicAuthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oauthConfig"]))throw new Error("oauthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oidcConfig"]))throw new Error("oidcConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["enableWidget"]);if(null!=o&&ze(t,["enableWidget"],o),void 0!==Ze(e,["groundingTypes"]))throw new Error("groundingTypes parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["mcpServers"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mcpServers"],e)}const i=Ze(e,["codeExecution"]);null!=i&&ze(t,["codeExecution"],i);const r=Ze(e,["computerUse"]);if(null!=r&&ze(t,["computerUse"],r),void 0!==Ze(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["exaAiSearch"]))throw new Error("exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const s=Ze(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const l=Ze(e,["googleSearch"]);null!=l&&ze(t,["googleSearch"],function(e){const t={};if(void 0!==Ze(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["excludeDomains"]))throw new Error("excludeDomains parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["searchTypes"]);null!=n&&ze(t,["searchTypes"],n);const o=Ze(e,["timeRangeFilter"]);return null!=o&&ze(t,["timeRangeFilter"],o),t}(l));const a=Ze(e,["googleSearchRetrieval"]);if(null!=a&&ze(t,["googleSearchRetrieval"],a),void 0!==Ze(e,["parallelAiSearch"]))throw new Error("parallelAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["urlContext"]);null!=u&&ze(t,["urlContext"],u);const c=Ze(e,["fileSearch"]);return null!=c&&ze(t,["fileSearch"],c),t}(zt(e)))),ze(t,["setup","tools"],e)}const h=Ze(e,["sessionResumption"]);void 0!==t&&null!=h&&ze(t,["setup","sessionResumption"],function(e){const t={},n=Ze(e,["handle"]);if(null!=n&&ze(t,["handle"],n),void 0!==Ze(e,["transparent"]))throw new Error("transparent parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(h));const g=Ze(e,["inputAudioTranscription"]);void 0!==t&&null!=g&&ze(t,["setup","inputAudioTranscription"],g);const v=Ze(e,["outputAudioTranscription"]);void 0!==t&&null!=v&&ze(t,["setup","outputAudioTranscription"],v);const _=Ze(e,["realtimeInputConfig"]);void 0!==t&&null!=_&&ze(t,["setup","realtimeInputConfig"],_);const E=Ze(e,["contextWindowCompression"]);void 0!==t&&null!=E&&ze(t,["setup","contextWindowCompression"],E);const y=Ze(e,["proactivity"]);if(void 0!==t&&null!=y&&ze(t,["setup","proactivity"],y),void 0!==Ze(e,["explicitVadSignal"]))throw new Error("explicitVadSignal parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const A=Ze(e,["avatarConfig"]);void 0!==t&&null!=A&&ze(t,["setup","avatarConfig"],A);const I=Ze(e,["safetySettings"]);if(void 0!==t&&null!=I){let e=I;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["category"]);if(null!=n&&ze(t,["category"],n),void 0!==Ze(e,["method"]))throw new Error("method parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["threshold"]);return null!=o&&ze(t,["threshold"],o),t}(e))),ze(t,["setup","safetySettings"],e)}const T=Ze(e,["translationConfig"]);return void 0!==t&&null!=T&&ze(t,["setup","generationConfig","translationConfig"],T),{}}(i,n)),n}(e,s));const l=Ze(t,["lockAdditionalFields"]);return void 0!==n&&null!=l&&ze(n,["fieldMask"],l),{}}var Ro=class extends Ke{constructor(e){super(),this.apiClient=e}async create(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("The client.tokens.create method is only supported by the Gemini Developer API.");{const s=function(e,t){const n={},o=Ze(t,["config"]);return null!=o&&ze(n,["config"],wo(e,o,n)),n}(this.apiClient,e);i=We("auth_tokens",s._url),r=s._query,delete s.config,delete s._url,delete s._query;const l=function(e,t){let n=null;const o=e.bidiGenerateContentSetup;if("object"==typeof o&&null!==o&&"setup"in o){const t=o.setup;"object"==typeof t&&null!==t?(e.bidiGenerateContentSetup=t,n=t):delete e.bidiGenerateContentSetup}else void 0!==o&&delete e.bidiGenerateContentSetup;const i=e.fieldMask;if(n){const o=function(e){const t=[];for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const o=e[n];if("object"==typeof o&&null!=o&&Object.keys(o).length>0){const e=Object.keys(o).map(e=>`${n}.${e}`);t.push(...e)}else t.push(n)}return t.join(",")}(n);if(Array.isArray(null==t?void 0:t.lockAdditionalFields)&&0===(null==t?void 0:t.lockAdditionalFields.length))o?e.fieldMask=o:delete e.fieldMask;else if((null==t?void 0:t.lockAdditionalFields)&&t.lockAdditionalFields.length>0&&null!==i&&Array.isArray(i)&&i.length>0){const t=["temperature","topK","topP","maxOutputTokens","responseModalities","seed","speechConfig"];let n=[];i.length>0&&(n=i.map(e=>t.includes(e)?`generationConfig.${e}`:e));const r=[];o&&r.push(o),n.length>0&&r.push(...n),r.length>0?e.fieldMask=r.join(","):delete e.fieldMask}else delete e.fieldMask}else null!==i&&Array.isArray(i)&&i.length>0?e.fieldMask=i.join(","):delete e.fieldMask;return e}(s,e.config);return o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(l),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()),o.then(e=>e)}}};var No=class extends Ke{constructor(e){super(),this.apiClient=e,this.list=async e=>new vn(nt.PAGED_ITEM_DOCUMENTS,t=>this.listInternal({parent:e.parent,config:t.config}),await this.listInternal(e),e)}async get(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return i=We("{name}",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>e)}}async delete(e){var t,n;let o="",i={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const r=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["_url","name"],n);const o=Ze(e,["config"]);return null!=o&&function(e,t){const n=Ze(e,["force"]);void 0!==t&&null!=n&&ze(t,["_query","force"],n)}(o,t),t}(e);o=We("{name}",r._url),i=r._query,delete r._url,delete r._query,await this.apiClient.request({path:o,queryParams:i,body:JSON.stringify(r),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 o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["parent"]);null!=n&&ze(t,["_url","parent"],n);const o=Ze(e,["config"]);return null!=o&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o)}(o,t),t}(e);return i=We("{parent}/documents",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["documents"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["documents"],e)}return t}(e),n=new At;return Object.assign(n,t),n})}}},Do=class extends Ke{constructor(e,t=new No(e)){super(),this.apiClient=e,this.documents=t,this.list=async(e={})=>new vn(nt.PAGED_ITEM_FILE_SEARCH_STORES,e=>this.listInternal(e),await this.listInternal(e),e)}async uploadToFileSearchStore(e){if(this.apiClient.isVertexAI())throw new Error("Gemini Enterprise Agent Platform (previously known as Vertex AI) does not support uploading files to a file search store.");return this.apiClient.uploadFileToFileSearchStore(e.fileSearchStoreName,e.file,e.config)}async downloadMedia(e,t){if(this.apiClient.isVertexAI())throw new Error("This method is only supported in the Gemini Developer client.");const n=new URL(e,"http://dummy.com");let o=n.pathname;if(o.startsWith("/")&&(o=o.slice(1)),!o.includes("/media/"))throw new Error(`Invalid uri format: ${e}. Expected to contain /media/`);const i={};n.searchParams.forEach((e,t)=>{i[t]=e}),i.alt="media";const r=Object.assign({},null==t?void 0:t.httpOptions),s=await this.apiClient.request({path:o,httpMethod:"GET",queryParams:i,httpOptions:r});if(s instanceof ot){const e=await s.responseInternal.arrayBuffer();return new Uint8Array(e)}throw new Error("Unexpected response type from downloadMedia")}async create(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e,t){const n={},o=Ze(t,["config"]);return null!=o&&function(e,t,n){const o=Ze(t,["displayName"]);void 0!==n&&null!=o&&ze(n,["displayName"],o);const i=Ze(t,["embeddingModel"]);void 0!==n&&null!=i&&ze(n,["embeddingModel"],Gt(e,i))}(e,o,n),n}(this.apiClient,e);return i=We("fileSearchStores",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>e)}}async get(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return i=We("{name}",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>e)}}async delete(e){var t,n;let o="",i={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const r=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["_url","name"],n);const o=Ze(e,["config"]);return null!=o&&function(e,t){const n=Ze(e,["force"]);void 0!==t&&null!=n&&ze(t,["_query","force"],n)}(o,t),t}(e);o=We("{name}",r._url),i=r._query,delete r._url,delete r._query,await this.apiClient.request({path:o,queryParams:i,body:JSON.stringify(r),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 o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o)}(n,t),t}(e);return i=We("fileSearchStores",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["fileSearchStores"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["fileSearchStores"],e)}return t}(e),n=new It;return Object.assign(n,t),n})}}async uploadToFileSearchStoreInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["fileSearchStoreName"]);null!=n&&ze(t,["_url","file_search_store_name"],n);const o=Ze(e,["config"]);return null!=o&&so(o,t),t}(e);return i=We("upload/v1beta/{file_search_store_name}:uploadToFileSearchStore",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new Tt;return Object.assign(n,t),n})}}async importFile(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["fileSearchStoreName"]);null!=n&&ze(t,["_url","file_search_store_name"],n);const o=Ze(e,["fileName"]);null!=o&&ze(t,["fileName"],o);const i=Ze(e,["config"]);return null!=i&&function(e,t){const n=Ze(e,["customMetadata"]);if(void 0!==t&&null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["customMetadata"],e)}const o=Ze(e,["chunkingConfig"]);void 0!==t&&null!=o&&ze(t,["chunkingConfig"],o)}(i,t),t}(e);return i=We("{file_search_store_name}:importFile",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["parent"]);null!=o&&ze(t,["parent"],o);const i=Ze(e,["documentName"]);return null!=i&&ze(t,["documentName"],i),t}(s)),t}(e),n=new Ct;return Object.assign(n,t),n})}}},Go=void 0;function ko(){var e,t,n,o,i,r;if(Go)return Go;const s=globalThis;let l={};return l="Deno"in globalThis?null!==(o=null===(n=null===(t=null===(e=s.Deno)||void 0===e?void 0:e.env)||void 0===t?void 0:t.toObject)||void 0===n?void 0:n.call(t))&&void 0!==o?o:{}:null!==(r=null===(i=s.process)||void 0===i?void 0:i.env)&&void 0!==r?r:{},Go=l}var Mo=class{constructor(e){this.options=e}getDefaultHeaders(){return this.options.defaultHeaders}async resolveGoogleGenAISecurity(e){return function(e){var t,n;const o={};for(const[r,s]of e){const e=r.toLowerCase();"authorization"!==e&&"x-goog-api-key"!==e&&(o[r]=s)}const i={access_token:null!==(t=e.get("authorization"))&&void 0!==t?t:void 0,api_key:null!==(n=e.get("x-goog-api-key"))&&void 0!==n?n:void 0,default_headers:Object.keys(o).length?o:void 0};return jo(i)?i:void 0}(await this.options.getAuthHeaders(e))}},xo=class{beforeCreateRequest(e,t){return Object.assign(Object.assign({},t),{url:Uo(t.url)})}async beforeRequest(e,t){if(qo(t.headers,function(e){var t,n;return Fo(e)?null!==(n=null===(t=e.getDefaultHeaders)||void 0===t?void 0:t.call(e))&&void 0!==n?n:e.defaultHeaders:Ho(e)?e.default_headers:void 0}(e.security_source)),function(e,t){void 0!==e.options.user_project&&null===t.get("x-goog-user-project")&&t.set("x-goog-user-project",e.options.user_project)}(e,t.headers),null!==(n=t.headers).get("authorization")||null!==n.get("x-goog-api-key"))return t;var n;const o=await async function(e,t){if(Fo(e))return e.resolveGoogleGenAISecurity(t);const n="function"==typeof e?await e():e;return Ho(n)?Lo(n):Lo(void 0)}(e.security_source,t.url);return qo(t.headers,null==o?void 0:o.default_headers),function(e,t){var n;t&&(t.api_key?e.set("x-goog-api-key",t.api_key):t.access_token&&e.set("Authorization","bearer "===(n=t.access_token).slice(0,7).toLowerCase()?n:`Bearer ${n}`))}(t.headers,o),t}};function Uo(e){const[,t,...n]=e.pathname.split("/");if(!t)return e;const o=decodeURIComponent(t);if(!o.includes("/"))return e;const i=new URL(e);return i.pathname=`/${o}/${n.join("/")}`,i}function Lo(e){var t,n;const o=ko(),i=Object.assign(Object.assign({},e),{api_key:null!==(t=null==e?void 0:e.api_key)&&void 0!==t?t:o.GOOGLE_GENAI_API_KEY,access_token:null!==(n=null==e?void 0:e.access_token)&&void 0!==n?n:o.GOOGLE_GENAI_ACCESS_TOKEN});return jo(i)?i:void 0}function qo(e,t){if(t)for(const[n,o]of new Headers(t))null===e.get(n)&&e.set(n,o)}function Ho(e){return"object"==typeof e&&null!==e}function Fo(e){return"object"==typeof e&&null!==e&&"resolveGoogleGenAISecurity"in e&&"function"==typeof e.resolveGoogleGenAISecurity}function jo(e){return void 0!==e.api_key||void 0!==e.access_token||void 0!==e.default_headers}var Bo=class extends Error{constructor(e,t){let n=e;(null==t?void 0:t.cause)&&(n+=`: ${t.cause}`),super(n,t),this.name="HTTPClientError",void 0===this.cause&&(this.cause=null==t?void 0:t.cause)}},Vo=class extends Bo{constructor(){super(...arguments),this.name="UnexpectedClientError"}},Xo=class extends Bo{constructor(){super(...arguments),this.name="InvalidRequestError"}},Jo=class extends Bo{constructor(){super(...arguments),this.name="RequestAbortedError"}},Yo=class extends Bo{constructor(){super(...arguments),this.name="RequestTimeoutError"}},$o=class extends Bo{constructor(){super(...arguments),this.name="ConnectionError"}},Ko=class extends Error{constructor(e,t){var n,o,i,r;super(e),this.statusCode=null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status,this.body=null!==(o=null==t?void 0:t.body)&&void 0!==o?o:"",this.headers=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.headers,this.contentType=(null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.headers.get("content-type"))||"",this.rawResponse=null==t?void 0:t.response,this.name="GoogleGenAiError"}},Wo=class extends Error{},zo=class e extends Wo{constructor(t,n,o,i){super(e.makeMessage(t,n,o)),this.status=t,this.headers=i,this.error=n,this.statusCode=t,this.body=pi(n),this.contentType=(null==i?void 0:i.get("content-type"))||"",this.rawResponse=void 0,this.cause=void 0,this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}static makeMessage(e,t,n){var o;const i=t&&null!==(r=t)&&"object"==typeof r&&!Array.isArray(r)&&"string"==typeof t.message?t.message:void 0;var r;const s=pi(t);return`${e?`${e} `:""}${null!==(o=null!=i?i:n)&&void 0!==o?o:s||"An error occurred"}`}static generate(t,n,o,i){return t&&i?400===t?new ti(t,n,o,i):401===t?new ni(t,n,o,i):403===t?new oi(t,n,o,i):404===t?new ii(t,n,o,i):409===t?new ri(t,n,o,i):422===t?new si(t,n,o,i):429===t?new li(t,n,o,i):t>=500?new ai(t,n,o,i):new e(t,n,o,i):new Qo({message:o,cause:n instanceof Error?n:void 0})}},Zo=class extends zo{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}},Qo=class extends zo{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),this.cause=t}},ei=class extends Qo{constructor({message:e}={}){super({message:e||"Request timed out. This is a client-side timeout. You can increase the timeout by setting the `timeout` argument in your request or client http options."})}},ti=class extends zo{},ni=class extends zo{},oi=class extends zo{},ii=class extends zo{},ri=class extends zo{},si=class extends zo{},li=class extends zo{},ai=class extends zo{};function ui(e){return"object"==typeof(t=e)&&null!==t&&zo.prototype.isPrototypeOf(t)?e:e instanceof Ko?function(e){const t=function(e){const t=ci(e,"data$");if(t&&"object"==typeof t)return t;try{const t=JSON.parse(e.body);if(t&&"object"==typeof t)return t}catch(vr){}const n=ci(e,"error");return n&&"object"==typeof n?n:void 0}(e),n=zo.generate(e.statusCode,t,e.message,e.headers);return di(n,"body",e.body),di(n,"contentType",e.contentType),di(n,"rawResponse",e.rawResponse),di(n,"statusCode",e.statusCode),di(n,"cause",e),n}(e):e instanceof Bo?function(e){return e instanceof Yo?new ei({message:e.message}):e instanceof Jo?new Zo({message:e.message}):new Qo({message:e.message,cause:e})}(e):e;var t}function ci(e,t){return e&&"object"==typeof e?e[t]:void 0}function pi(e){if(!e)return"";try{return JSON.stringify(e)}catch(vr){return String(e)}}function di(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,value:n,writable:!1})}var mi=class{constructor(){this.sdkInitHooks=[],this.beforeCreateRequestHooks=[],this.beforeRequestHooks=[],this.afterSuccessHooks=[],this.afterErrorHooks=[];for(const e of[])"sdkInit"in e&&this.registerSDKInitHook(e),"beforeCreateRequest"in e&&this.registerBeforeCreateRequestHook(e),"beforeRequest"in e&&this.registerBeforeRequestHook(e),"afterSuccess"in e&&this.registerAfterSuccessHook(e),"afterError"in e&&this.registerAfterErrorHook(e);!function(e){const t=new xo;e.registerBeforeCreateRequestHook(t),e.registerBeforeRequestHook(t)}(this)}registerSDKInitHook(e){this.sdkInitHooks.push(e)}registerBeforeCreateRequestHook(e){this.beforeCreateRequestHooks.push(e)}registerBeforeRequestHook(e){this.beforeRequestHooks.push(e)}registerAfterSuccessHook(e){this.afterSuccessHooks.push(e)}registerAfterErrorHook(e){this.afterErrorHooks.push(e)}sdkInit(e){return this.sdkInitHooks.reduce((e,t)=>t.sdkInit(e),e)}beforeCreateRequest(e,t){let n=t;for(const o of this.beforeCreateRequestHooks)n=o.beforeCreateRequest(e,n);return n}async beforeRequest(e,t){let n=t;for(const o of this.beforeRequestHooks)n=await o.beforeRequest(e,n);return n}async afterSuccess(e,t){let n=t;for(const o of this.afterSuccessHooks)n=await o.afterSuccess(e,n);return n}async afterError(e,t,n){let o=t,i=n;for(const r of this.afterErrorHooks){const t=await r.afterError(e,o,i);o=t.response,i=t.error}return{response:o,error:i}}};function fi(e){return{ok:!0,value:e}}function hi(e){return{ok:!1,error:e}}function gi(e){return btoa(String.fromCodePoint(...e))}var vi=Object.prototype.hasOwnProperty;function _i(e,t){const n=/\{([a-zA-Z0-9_][a-zA-Z0-9_-]*?)\}/g;return function(t={}){return e.replace(n,function(e,n){if(!vi.call(t,n))throw new Error(`Parameter '${n}' is required`);const o=t[n];if("string"!=typeof o&&"number"!=typeof o)throw new Error(`Parameter '${n}' must be a string or number`);return`${o}`}).replace(/^\/+/,"")}}var Ei=["https://generativelanguage.googleapis.com"];function yi(...e){const t=[];for(const n of e)n&&t.push(n);switch(t.length){case 0:case 1:return t[0]||null;default:return"any"in AbortSignal&&"function"==typeof AbortSignal.any?AbortSignal.any(t):function(e){const t=new AbortController,n=t.signal;if(!e.length)return t.signal;if(1===e.length)return e[0]||t.signal;for(const r of e)if(r.aborted)return r;function o(){t.abort(this.reason),function(){for(const e of i){const t=e.deref();t&&t.removeEventListener("abort",o)}}()}const i=[];for(const r of e)i.push(new WeakRef(r)),r.addEventListener("abort",o);return n}(t)}}function Ai(e){const t={};for(const[n,o]of Object.entries(e))void 0!==o&&(t[n]=o);return t}function Ii(e){if(null===e||"object"!=typeof e)return!1;if("[object Object]"!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);if(null===t||t===Object.prototype)return!0;try{return null===Object.getPrototypeOf(t)}catch(vr){return!1}}var Ti=(e,t,n)=>{let o="";const i=(null==n?void 0:n.explode)?Oi(e,t):[[e,t]];if(i.every(([e,t])=>null==t))return;const r=e=>"percent"===(null==n?void 0:n.charEncoding)?encodeURIComponent(e):e,s=e=>r(bi(e)),l=r(",");return i.forEach(([e,t])=>{var n,i;let a="",u=null;null!=t&&(u=Array.isArray(t)?null===(n=wi(t,e=>`${s(e)}`))||void 0===n?void 0:n.join(l):Ii(t)?null===(i=Ri(Object.entries(t),([e,t])=>`${r(e)}${l}${s(t)}`))||void 0===i?void 0:i.join(l):`${s(t)}`,null!=u&&(a=`${r(e)}=${u}`,a&&"="!==a&&(o+=`&${a}`)))}),o.slice(1)};function Ci(e,t,n){if(void 0===t)return;const o=e=>"percent"===(null==n?void 0:n.charEncoding)?encodeURIComponent(e):e,i=o(JSON.stringify(t,Pi));return(null==n?void 0:n.explode)?i:`${o(e)}=${i}`}var Si=(e,t,n)=>{let o="";const i=(null==n?void 0:n.explode)?Oi(e,t):[[e,t]];if(i.every(([e,t])=>null==t))return;const r=e=>"percent"===(null==n?void 0:n.charEncoding)?encodeURIComponent(e):e,s=e=>r(bi(e));return i.forEach(([e,i])=>{var l;let a="";if(null!=i){if(Array.isArray(i))a=null===(l=wi(i,e=>`${s(e)}`))||void 0===l?void 0:l.join(",");else if(Ii(i)){const e=Ri(Object.entries(i),([e,t])=>`,${r(e)},${s(t)}`);a=null==e?void 0:e.join("").slice(1)}else a=`${(null==n?void 0:n.explode)&&Ii(t)?`${e}=`:""}${s(i)}`;o+=a?`,${a}`:""}}),o.slice(1)};function Oi(e,t){return Array.isArray(t)?t.map(t=>[e,t]):Ii(t)?Object.entries(null!=t?t:{}).map(([e,t])=>[e,t]):[[e,t]]}function bi(e){return null==e?"":e instanceof Date?e.toISOString():e instanceof Uint8Array?gi(e):"object"==typeof e?JSON.stringify(e,Pi):`${e}`}function Pi(e,t){return t instanceof Uint8Array?gi(t):t}function wi(e,t){const n=e.reduce((e,n)=>{if(null==n)return e;const o=t(n);return null==o||e.push(o),e},[]);return n.length?n:null}function Ri(e,t){const n=[];for(const[o,i]of e){if(null==i)continue;const e=t([o,i]);null!=e&&n.push(e)}return n.length?n:null}var Ni,Di=(Ni=Ti,function(e,t){var n,o,i;const r=Object.assign(Object.assign({},t),{explode:null===(n=null==t?void 0:t.explode)||void 0===n||n,charEncoding:null!==(o=null==t?void 0:t.charEncoding)&&void 0!==o?o:"percent"}),s=new Set(null!==(i=null==t?void 0:t.allowEmptyValue)&&void 0!==i?i:[]);return function(...e){return e.filter(Boolean).join("&")}(...Object.entries(e).map(([e,t])=>s.has(e)&&(null==t||""===t||Array.isArray(t)&&0===t.length)?`${encodeURIComponent(e)}=`:Ni(e,t,r)))}),Gi=(e,t)=>null==t?fetch(e):fetch(e,t),ki=class e{constructor(e={}){this.requestHooks=[],this.requestErrorHooks=[],this.responseHooks=[],this.options=e,this.fetcher=e.fetcher||Gi}async request(e){let t=e;for(const o of this.requestHooks){const e=await o(t);e&&(t=e)}try{const e=await this.fetcher(t);for(const n of this.responseHooks)await n(e,t);return e}catch(n){for(const e of this.requestErrorHooks)await e(n,t);throw n}}addHook(...e){if("beforeRequest"===e[0])this.requestHooks.push(e[1]);else if("requestError"===e[0])this.requestErrorHooks.push(e[1]);else{if("response"!==e[0])throw new Error(`Invalid hook type: ${e[0]}`);this.responseHooks.push(e[1])}return this}removeHook(...e){let t;if("beforeRequest"===e[0])t=this.requestHooks;else if("requestError"===e[0])t=this.requestErrorHooks;else{if("response"!==e[0])throw new Error(`Invalid hook type: ${e[0]}`);t=this.responseHooks}const n=t.findIndex(t=>t===e[1]);return n>=0&&t.splice(n,1),this}clone(){const t=new e(this.options);return t.requestHooks=this.requestHooks.slice(),t.requestErrorHooks=this.requestErrorHooks.slice(),t.responseHooks=this.responseHooks.slice(),t}},Mi=/\s*;\s*/g;function xi(e,t){var n;if("*"===t)return!0;let o=(null===(n=e.headers.get("content-type"))||void 0===n?void 0:n.trim())||"application/octet-stream";o=o.toLowerCase();const[i="",...r]=t.toLowerCase().trim().split(Mi);if(2!==i.split("/").length)return!1;const[s="",...l]=o.split(Mi),[a="",u=""]=s.split("/");if(!a||!u)return!1;if("*/*"!==i&&s!==i&&`${a}/*`!==i&&`*/${u}`!==i)return!1;if(l.length<r.length)return!1;const c=new Set(l);for(const p of r)if(!c.has(p))return!1;return!0}var Ui=/* @__PURE__ */new RegExp("^[0-9]xx$","i");function Li(e,t){const n=`${e.status}`,o=Array.isArray(t)?t:[t];return!!o.length&&o.some(e=>{const t=`${e}`;if("default"===t)return!0;if(!Ui.test(`${t}`))return t===n;const o=t.charAt(0);if(!o)throw new Error("Invalid status code range");const i=n.charAt(0);if(!i)throw new Error(`Invalid response status code: ${n}`);return i===o})}function qi(e,t,n){return Li(e,t)&&xi(e,n)}function Hi(e){if("object"!=typeof e||null==e)return!1;const t=e instanceof TypeError&&e.message.toLowerCase().startsWith("failed to fetch"),n=e instanceof TypeError&&e.message.toLowerCase().startsWith("fetch failed"),o="name"in e&&"ConnectionError"===e.name,i="code"in e&&"string"==typeof e.code&&"econnreset"===e.code.toLowerCase();return t||n||i||o}function Fi(e){if("object"!=typeof e||null==e)return!1;const t="name"in e&&"TimeoutError"===e.name,n="code"in e&&23===e.code,o="code"in e&&"string"==typeof e.code&&"econnaborted"===e.code.toLowerCase();return t||n||o}var ji={initialInterval:500,maxInterval:6e4,exponent:1.5,maxElapsedTime:36e5},Bi=class e extends Error{constructor(t,n){let o=t;(null==n?void 0:n.cause)&&(o+=`: ${n.cause}`),super(o,n),this.name="PermanentError",void 0===this.cause&&(this.cause=null==n?void 0:n.cause),Object.setPrototypeOf(this,e.prototype)}},Vi=class e extends Error{constructor(t,n){super(t),this.response=n,this.name="TemporaryError",Object.setPrototypeOf(this,e.prototype)}};function Xi(e,t){return async n=>{try{const o=await e(n);if(function(e,t){const n=`${e.status}`;return t.some(e=>{if(!Ji.test(e))return e===n;const t=e.charAt(0);if(!t)throw new Error("Invalid status code range");const o=n.charAt(0);if(!o)throw new Error(`Invalid response status code: ${n}`);return o===t})}(o,t.statusCodes))throw new Vi("Response failed with retryable status code",o);return o}catch(o){if(o instanceof Vi)throw o;if(t.retryConnectionErrors&&(Fi(o)||Hi(o)))throw o;throw new Bi("Permanent error",{cause:o})}}}var Ji=/* @__PURE__ */new RegExp("^[0-9]xx$","i");function Yi(e){const t=e.headers.get("retry-after-ms");if(t){const e=Number(t);if(Number.isFinite(e)&&e>=0)return e}const n=e.headers.get("retry-after")||"";if(!n)return 0;const o=Number(n);if(Number.isInteger(o))return 1e3*o;const i=Date.parse(n);if(Number.isInteger(i)){const e=i-Date.now();return e>0?Math.ceil(e):0}return 0}async function $i(e){return new Promise(t=>setTimeout(t,e))}var Ki="undefined"==typeof globalThis?null:globalThis,Wi="object"==typeof Ki&&null!=Ki&&"importScripts"in Ki&&"function"==typeof Ki.importScripts||"undefined"!=typeof navigator&&"serviceWorker"in navigator||"object"==typeof window&&void 0!==window.document,zi=class{constructor(e={}){const t=e;"object"==typeof t&&null!=t&&"hooks"in t&&t.hooks instanceof mi?this._hooks=t.hooks:this._hooks=new mi;const n=new ki;e.http_client=e.http_client||n;const o=function(e){var t;let n=e.server_url;if(!n){const o=null!==(t=e.server_idx)&&void 0!==t?t:0;if(o<0||o>=Ei.length)throw new Error(`Invalid server index ${o}`);n=Ei[o]||""}const o=_i(n)({});return new URL(o)}(e=this._hooks.sdkInit(e));o&&(o.pathname=o.pathname.replace(/\/+$/,"")+"/"),this._baseURL=o,this._httpClient=e.http_client||n,this._options=Object.assign(Object.assign({},function(e){var t,n;const o=Object.assign({},e),i=ko();return void 0!==i.GOOGLE_GENAI_API_VERSION&&(null!==(t=o.api_version)&&void 0!==t||(o.api_version=i.GOOGLE_GENAI_API_VERSION)),void 0!==i.GOOGLE_GENAI_USER_PROJECT&&(null!==(n=o.user_project)&&void 0!==n||(o.user_project=i.GOOGLE_GENAI_USER_PROJECT)),o}(e)),{hooks:this._hooks}),this._logger=this._options.debug_logger,!this._logger&&ko().GOOGLE_GENAI_DEBUG&&(this._logger=console)}_createRequest(e,t,n){var o,i,r,s,l;const{method:a,path:u,query:c,headers:p,security:d}=t,m=null!==(o=t.baseURL)&&void 0!==o?o:this._baseURL;if(!m)return hi(new Xo("No base URL provided for operation"));const f=new URL(m);let h;u?(f.pathname=f.pathname.replace(/\/+$/,"")+"/",h=new URL(u,f),!h.search&&f.search&&(h.search=f.search)):h=f,h.hash="";const g=e=>Object.entries(e).map(([e,t])=>{if(null==t)return;const n=Ii(t)?JSON.stringify(t):t;return Ti(e,n,{explode:Array.isArray(n),charEncoding:"percent"})}).filter(e=>void 0!==e).join("&"),v=[c||"",g((null==n?void 0:n.extra_query)||{}),g((null==d?void 0:d.queryParams)||{})].reduce((e,t)=>{if(!t)return e;const n=new Set(t.split("&").filter(e=>""!==e).map(e=>{var t;return null!==(t=e.split("=")[0])&&void 0!==t?t:""}));return[...e.split("&").filter(e=>{var t;return""!==e&&!n.has(null!==(t=e.split("=")[0])&&void 0!==t?t:"")}),t].join("&")},h.search.slice(1));v&&(h.search=`?${v}`);const _=new Headers(p),E=null==d?void 0:d.basic.username,y=null==d?void 0:d.basic.password;if(null!=E||null!=y){const e=gi(function(e){return(new TextEncoder).encode(e)}([E||"",y||""].join(":")));_.set("Authorization",`Basic ${e}`)}const A=new Headers((null==d?void 0:d.headers)||{});for(const[w,R]of A)_.set(w,R);let I=_.get("cookie")||"";for(const[w,R]of Object.entries((null==d?void 0:d.cookies)||{}))I+=`; ${w}=${R}`;I=I.startsWith("; ")?I.slice(2):I,_.set("cookie",I);const T=new Headers(null!==(i=null==n?void 0:n.headers)&&void 0!==i?i:null===(r=null==n?void 0:n.fetch_options)||void 0===r?void 0:r.headers);for(const[w,R]of T)_.set(w,R);Wi||_.set(null!==(s=t.uaHeader)&&void 0!==s?s:"user-agent",null!==(l=t.userAgent)&&void 0!==l?l:"speakeasy-sdk/typescript 2.4.1-preview.4 internal v1beta @google/genai");let C=t.body;const S=Object.fromEntries(Object.entries((null==n?void 0:n.extra_body)||{}).filter(([,e])=>void 0!==e));if(Object.keys(S).length>0){const e=new Headers(p).get("content-type")||"";if(!/^(application|text)\/([^+]+\+)*json/.test(e)||"string"!=typeof C&&null!=C)return hi(new Xo("extra_body can only be merged into JSON object request bodies"));let t;try{t=C?JSON.parse(C):{}}catch(P){return hi(new Xo("extra_body can only be merged into JSON object request bodies",{cause:P}))}if(!Ii(t))return hi(new Xo("extra_body can only be merged into JSON object request bodies"));C=JSON.stringify(Object.assign(Object.assign({},t),S)),_.delete("content-length")}const O=Object.assign(Object.assign({},null==n?void 0:n.fetch_options),n);let b;!(null==O?void 0:O.signal)&&null!=t.timeout_ms&&t.timeout_ms>0&&(e.timeout_ms=t.timeout_ms),t.body instanceof ReadableStream&&Object.assign(O,{duplex:"half"});try{b=this._hooks.beforeCreateRequest(e,{url:h,options:Object.assign(Object.assign({},O),{body:null!=C?C:null,headers:_,method:a})})}catch(P){return hi(new Vo("Create request hook failed to execute",{cause:P}))}return fi(new Request(b.url,b.options))}async _do(e,t){const{context:n,isErrorStatusCode:o}=t,i=n.timeout_ms;return async function(e,t){var n;switch(t.config.strategy){case"backoff":return async function(e,t){const{maxElapsedTime:n,initialInterval:o,exponent:i,maxInterval:r}=t,s=Date.now();let l=0;for(;;)try{return await e(l)}catch(a){if(a instanceof Bi)throw a.cause;if(Date.now()-s>n){if(a instanceof Vi)return a.response;throw a}let e=0;a instanceof Vi&&(e=Yi(a.response)),e<=0&&(e=o*Math.pow(l,i)+1e3*Math.random()),await $i(Math.min(e,r)),l++}}(Xi(e,{statusCodes:t.statusCodes,retryConnectionErrors:!!t.config.retryConnectionErrors}),null!==(n=t.config.backoff)&&void 0!==n?n:ji);case"attempt-count-backoff":return async function(e,t,n){let o=0;for(;;)try{return await e(o)}catch(i){if(i instanceof Bi)throw i.cause;if(o>=n.maxRetries){if(i instanceof Vi)return i.response;throw i}let e=0;i instanceof Vi&&(e=Yi(i.response)),e<=0&&(e=t.initialInterval*Math.pow(t.exponent,o)*(1-.25*Math.random())),await $i(Math.min(e,t.maxInterval)),o++}}(Xi(e,{statusCodes:t.statusCodes,retryConnectionErrors:!!t.config.retryConnectionErrors}),Object.assign(Object.assign({},ji),t.config.backoff),t.config);default:return await e(0)}}(async()=>{var t;const r=e.clone();let s=r;if(null!=i&&i>0){const e=AbortSignal.timeout(i),n=null!==(t=yi(r.signal,e))&&void 0!==t?t:e;s=new Request(r,{signal:n})}const l=await this._hooks.beforeRequest(n,s);await async function(e,t){if(!e)return;const n=t.headers.get("content-type"),o=(null==n?void 0:n.split(";")[0])||"";e.group(`> Request: ${t.method} ${t.url}`),e.group("Headers:");for(const[i,r]of t.headers.entries())e.log(`${i}: ${r}`);switch(e.groupEnd(),e.group("Body:"),!0){case Zi.test(o):e.log(await t.clone().json());break;case o.startsWith("text/"):e.log(await t.clone().text());break;case"multipart/form-data"===o:{const n=await t.clone().formData();for(const[t,o]of n){const n=o instanceof Blob?"<Blob>":o;e.log(`${t}: ${n}`)}break}default:e.log(`<${n}>`)}e.groupEnd(),e.groupEnd()}(this._logger,l).catch(e=>{var t;return null===(t=this._logger)||void 0===t?void 0:t.log("Failed to log request:",e)});let a=await this._httpClient.request(l);try{if(o(a.status)){const e=await this._hooks.afterError(n,a,null);if(e.error)throw e.error;a=e.response||a}else a=await this._hooks.afterSuccess(n,a)}finally{await async function(e,t,n){if(!e)return;const o=t.headers.get("content-type"),i=(null==o?void 0:o.split(";")[0])||"";e.group(`< Response: ${n.method} ${n.url}`),e.log("Status Code:",t.status,t.statusText),e.group("Headers:");for(const[r,s]of t.headers.entries())e.log(`${r}: ${s}`);switch(e.groupEnd(),e.group("Body:"),!0){case xi(t,"application/json")||Zi.test(i)&&!Qi.test(i):e.log(await t.clone().json());break;case xi(t,"application/jsonl")||Qi.test(i):case xi(t,"text/event-stream"):e.log(`<${o}>`);break;case xi(t,"text/*"):e.log(await t.clone().text());break;case xi(t,"multipart/form-data"):{const n=await t.clone().formData();for(const[t,o]of n){const n=o instanceof Blob?"<Blob>":o;e.log(`${t}: ${n}`)}break}default:e.log(`<${o}>`)}e.groupEnd(),e.groupEnd()}(this._logger,a,l).catch(e=>{var t;return null===(t=this._logger)||void 0===t?void 0:t.log("Failed to log response:",e)})}return a},{config:t.retryConfig,statusCodes:t.retryCodes}).then(e=>fi(e),e=>{switch(!0){case function(e){if("object"!=typeof e||null==e)return!1;const t="name"in e&&"AbortError"===e.name,n="code"in e&&20===e.code,o="code"in e&&"string"==typeof e.code&&"econnaborted"===e.code.toLowerCase();return t||n||o}(e):return hi(new Jo("Request aborted by client",{cause:e}));case Fi(e):return hi(new Yo("Request timed out",{cause:e}));case Hi(e):return hi(new $o("Unable to make request",{cause:e}));default:return hi(new Vo("Unexpected HTTP client error",{cause:e}))}})}},Zi=/^(application|text)\/([^+]+\+)*json.*/,Qi=/^(application|text)\/([^+]+\+)*(jsonl|x-ndjson)\b.*/,er=class extends Ko{constructor(e,t){e&&(e+=": "),e+=`Status ${t.response.status}`;const n=t.response.headers.get("content-type")||'""';"application/json"!==n&&(e+=` Content-Type ${n.includes(" ")?`"${n}"`:n}`);const o=t.body||'""';e+=o.length>100?"\n":". ";let i=o;o.length>1e4&&(i=`${o.substring(0,1e4)}...and ${o.length-1e4} more chars`),super(e=(e+=`Body: ${i}`).trim(),t),this.name="GoogleGenAiDefaultError"}};function tr(e){try{return JSON.parse(e)}catch(vr){return e}}var nr=class extends ReadableStream{constructor(e,t,n){var o;const i=e.getReader();let r=/* @__PURE__ */new Uint8Array(4096),s=0,l=0;const a={eventId:void 0},u=null===(o=null==n?void 0:n.dataRequired)||void 0===o||o;super({async pull(e){try{for(;;){const n=lr(r,s,l);if(!n){l=Math.max(0,s-sr+1);const t=await i.read();if(t.done)return e.close();if(s+t.value.length>r.length){const e=new Uint8Array(Math.max(2*r.length,s+t.value.length));e.set(r.subarray(0,s)),r=e}r.set(t.value,s),s+=t.value.length;continue}const o=r.slice(0,n.index);if(r.copyWithin(0,n.index+n.length,s),s-=n.index+n.length,r.length>4096&&s<=r.length>>2){const e=new Uint8Array(Math.max(4096,2*s));e.set(r.subarray(0,s)),r=e}l=0;const c=ar(o,t,a,u);if(c&&!c.done)return e.enqueue(c.value);if(null==c?void 0:c.done)return await i.cancel("done"),e.close()}}catch(n){e.error(n),await i.cancel(n)}},cancel:e=>i.cancel(e)})}[Symbol.asyncIterator](e){const t=ReadableStream.prototype[Symbol.asyncIterator];if("function"==typeof t)return t.call(this,e);const n=this.getReader(),o={next:async()=>{const e=await n.read();return e.done?(n.releaseLock(),{done:!0,value:void 0}):{done:!1,value:e.value}},throw:async e=>(await n.cancel(e),n.releaseLock(),{done:!0,value:void 0}),return:async()=>(await n.cancel("done"),n.releaseLock(),{done:!0,value:void 0}),[Symbol.asyncIterator](){return this}},i=Symbol.asyncDispose;return i&&(o[i]=async()=>{var e;await(null===(e=o.return)||void 0===e?void 0:e.call(o))}),o}values(e){return this[Symbol.asyncIterator](e)}},or=13,ir=10,rr=[[or,ir,or,ir],[or,ir,or],[or,ir,ir],[or,or,ir],[ir,or,ir],[or,or],[ir,or],[ir,ir]],sr=rr.reduce((e,t)=>Math.max(e,t.length),0);function lr(e,t,n){for(let o=n;o<t;o++)if(e[o]===or||e[o]===ir)for(const n of rr){if(o+n.length>t)continue;let i=!0;for(let t=0;t<n.length;t++)if(e[o+t]!==n[t]){i=!1;break}if(i)return{index:o,length:n.length}}return null}function ar(e,t,n,o){const i=(new TextDecoder).decode(e).split(/\r\n|\r|\n/),r=[],s={};let l=!0;for(const a of i){if(!a||a.startsWith(":"))continue;l=!1;const e=a.indexOf(":");let t=a,o="";e>0&&(t=a.slice(0,e),o=" "===a[e+1]?a.slice(e+2):a.slice(e+1)),"data"===t?r.push(o):"event"===t?s.event=o:"id"!==t||o.includes("\0")?"retry"===t&&/^\d+$/.test(o)&&(s.retry=Number(o)):n.eventId=o}if(!l){if(s.id=n.eventId,r.length)s.data=r.join("\n");else if(o)return;return t(s)}}var ur={jsonl:"application/jsonl",json:"application/json",text:"text/plain",bytes:"application/octet-stream",stream:"application/octet-stream",sse:"text/event-stream",nil:"*",fail:"*"};function cr(e,t,n){return Object.assign(Object.assign({},n),{err:!0,enc:"json",codes:e,errorClass:t})}function pr(e,t){return Object.assign(Object.assign({},t),{enc:"json",codes:e})}function dr(e,t,n){return Object.assign(Object.assign(Object.assign({},n),{enc:"sse",codes:e}),t?{sse:t}:{})}function mr(e){return{enc:"fail",codes:e}}function fr(...e){return async function(t,n,o){let i,r;for(const d of e){const{codes:e}=d,n="ctype"in d?d.ctype:ur[d.enc];if(n&&qi(t,e,n)){r=d;break}if(!n&&Li(t,e)){r=d;break}}if(!r)return[{ok:!1,error:new er("Unexpected Status or Content-Type",{response:t,request:n,body:await t.text().catch(()=>"")})},i];const s=r.enc;let l="";switch(s){case"json":l=await t.text();try{i=JSON.parse(l)}catch(p){if(!("err"in r))throw p;i=l}break;case"jsonl":case"stream":i=t.body;break;case"bytes":i=new Uint8Array(await t.arrayBuffer());break;case"text":case"fail":l=await t.text(),i=l;break;case"sse":if(t.body){const e="sse"in r&&r.sse||{};i=function(e,t={}){var n,o;const i=!0===t.flattened,r=null!==(n=t.sentinel)&&void 0!==n?n:"";return new nr(e,e=>""!==r&&e.data===r?{done:!0,value:void 0}:i?{done:!1,value:null==e.data?void 0:tr(e.data)}:{done:!1,value:Object.assign(Object.assign({},e),{data:null==e.data?e.data:tr(e.data)})},{dataRequired:null===(o=t.dataRequired)||void 0===o||o})}(t.body,e)}else i=null;break;case"nil":l=await t.text(),i=void 0;break;default:throw new Error(`Unsupported response type: ${s}`)}if("fail"===r.enc)return[{ok:!1,error:new er("API error occurred",{request:n,response:t,body:l})},i];const a=r.key||(null==o?void 0:o.resultKey);let u;const c=r.hdrs?{headers:gr(t.headers)}:null;return u="err"in r?Object.assign(Object.assign(Object.assign({},null==o?void 0:o.extraFields),c),Ii(i)?i:null):a?Object.assign(Object.assign(Object.assign({},null==o?void 0:o.extraFields),c),{[a]:i}):r.hdrs?Object.assign(Object.assign(Object.assign({},null==o?void 0:o.extraFields),c),Ii(i)?i:null):i,"err"in r?[{ok:!1,error:r.errorClass?new r.errorClass(u,{request:n,response:t,body:l}):u},i]:[{ok:!0,value:u},i]}}var hr=/, */;function gr(e){const t={};for(const[n,o]of e.entries())t[n]=o.split(hr);return t}var vr,_r=class e extends Error{constructor(e,t){super(t),this.code=e,this.name="SecurityError"}static incomplete(){return new e("incomplete","Security requirements not met in order to perform the operation")}static unrecognizedType(t){return new e("unrecognized_security_type",`Unrecognised security type: ${t}`)}};function Er(e,t){var n,o;return function(...e){const t={basic:{},headers:{},queryParams:{},cookies:{},oauth2:{type:"none"}},n=e.find(e=>e.every(e=>{if(null==e.value)return!1;if("http:basic"===e.type)return null!=e.value.username||null!=e.value.password;if("http:custom"===e.type)return null;if("oauth2:password"===e.type)return"string"==typeof e.value&&!!e.value;if("oauth2:client_credentials"===e.type)return"string"==typeof e.value?!!e.value:null!=e.value.client_id||null!=e.value.client_secret;if("string"==typeof e.value)return!!e.value;throw new Error(`Unrecognized security type: ${e.type} (value type: ${typeof e.value})`)}));return null==n?null:(n.forEach(e=>{if(null==e.value)return;const{type:n}=e;switch(n){case"apiKey:header":t.headers[e.fieldName]=e.value;break;case"apiKey:query":t.queryParams[e.fieldName]=e.value;break;case"apiKey:cookie":t.cookies[e.fieldName]=e.value;break;case"http:basic":!function(e,t){null!=t.value&&(e.basic=t.value)}(t,e);break;case"http:custom":case"oauth2:client_credentials":break;case"http:bearer":case"oauth2":case"oauth2:password":case"openIdConnect":!function(e,t){if("string"!=typeof t.value||!t.value)return;let n=t.value;"bearer "!==n.slice(0,7).toLowerCase()&&(n=`Bearer ${n}`),void 0!==t.fieldName&&(e.headers[t.fieldName]=n)}(t,e);break;default:throw _r.unrecognizedType(n)}}),t)}([{fieldName:"accessToken",type:"http:custom",value:null!==(n=null==e?void 0:e.access_token)&&void 0!==n?n:ko().GOOGLE_GENAI_ACCESS_TOKEN},{fieldName:"apiKey",type:"http:custom",value:null!==(o=null==e?void 0:e.api_key)&&void 0!==o?o:ko().GOOGLE_GENAI_API_KEY},{fieldName:"defaultHeaders",type:"http:custom",value:null==e?void 0:e.default_headers}])}async function yr(e){if(null!=e)return"function"==typeof e?e():e}var Ar=class e{constructor(e,t){this[vr]="APIPromise",this._promise=e instanceof Promise?e:Promise.resolve(e),this._unwrapped=e instanceof Promise?null:Promise.resolve(e[0]),this._callSource=null!=t?t:null}_getUnwrapped(){var e;return null!==(e=this._unwrapped)&&void 0!==e?e:this._unwrapped=this._promise.then(([e])=>e)}then(e,t){return this._promise.then(e?([t])=>e(t):void 0,t)}catch(e){return this._getUnwrapped().catch(e)}finally(e){return this._getUnwrapped().finally(e)}$inspect(){return this._promise}asResponse(){var e;return(null!==(e=this._callSource)&&void 0!==e?e:this._callSource=this._promise.then(([,e])=>e)).then(e=>{if(!e.response)throw new Error("APIPromise.asResponse: response unavailable");return e.response})}async withResponse(){const[[e],t]=await Promise.all([this._promise,this.asResponse()]);return{data:e,response:t}}_thenUnwrap(t){var n;const o=this._promise.then(([e,n])=>[t(e),n]);return o.catch(()=>{}),new e(o,null!==(n=this._callSource)&&void 0!==n?n:void 0)}};function Ir(e){const t=e.$inspect(),n=t.then(([e,t])=>{if(!e.ok)throw e.error;return[e.value,t]}),o=t.then(([e,t])=>{var n;if(!e.ok&&!(null===(n=t.response)||void 0===n?void 0:n.ok))throw e.error;return t});return n.catch(()=>{}),o.catch(()=>{}),new Ar(n,o)}function Tr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={body:t,api_version:n},a=Ci("body",l.body,{explode:!0}),u={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/agents")(u),p=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),d=Er(await yr(e._options.security)),m={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"CreateAgent",o_auth2_scopes:null,resolved_security:d,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},f=e._createRequest(m,{security:d,method:"POST",baseURL:null==o?void 0:o.server_url,path:c,headers:p,body:a,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!f.ok)return[f,{status:"invalid"}];const h=f.value,g=await e._do(h,{context:m,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:m.retry_config,retryCodes:m.retry_codes});if(!g.ok)return[g,{status:"request-error",request:h}];const v=g.value,[_]=await fr(mr("4XX"),mr("5XX"),pr("default"))(v,h);return _.ok,[_,{status:"complete",request:h,response:v}]}(e,t,n,o))}function Cr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/agents/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"DeleteAgent",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"DELETE",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Sr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/agents/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"GetAgent",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"GET",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Or(e,t,n,o,i,r){return new Ar(async function(e,t,n,o,i,r){var s,l,a;const u={api_version:t,page_size:n,page_token:o,parent:i},c={api_version:Si("api_version",null!==(s=null==u?void 0:u.api_version)&&void 0!==s?s:e._options.api_version,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/agents")(c),d=Di({page_size:null==u?void 0:u.page_size,page_token:null==u?void 0:u.page_token,parent:null==u?void 0:u.parent}),m=new Headers(Ai({Accept:"application/json"})),f=Er(await yr(e._options.security)),h={options:e._options,base_url:null!==(a=null!==(l=null==r?void 0:r.server_url)&&void 0!==l?l:e._baseURL)&&void 0!==a?a:"",operation_id:"ListAgents",o_auth2_scopes:null,resolved_security:f,security_source:e._options.security,retry_config:(null==r?void 0:r.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==r?void 0:r.retry_codes)||["408","409","429","5XX"]},g=e._createRequest(h,{security:f,method:"GET",baseURL:null==r?void 0:r.server_url,path:p,headers:m,query:d,body:null,userAgent:e._options.user_agent,timeout_ms:(null==r?void 0:r.timeout_ms)||e._options.timeout_ms||-1},r);if(!g.ok)return[g,{status:"invalid"}];const v=g.value,_=await e._do(v,{context:h,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:h.retry_config,retryCodes:h.retry_codes});if(!_.ok)return[_,{status:"request-error",request:v}];const E=_.value,[y]=await fr(mr("4XX"),mr("5XX"),pr("default"))(E,v);return y.ok,[y,{status:"complete",request:v,response:E}]}(e,t,n,o,i,r))}vr=Symbol.toStringTag;var br=class extends zi{list(e,t){return Ir(Or(this,null==e?void 0:e.api_version,null==e?void 0:e.page_size,null==e?void 0:e.page_token,null==e?void 0:e.parent,t))}create(e,t){const{api_version:n}=e;return Ir(Tr(this,In(e,["api_version"]),n,t))}delete(e,t,n){return Ir(Cr(this,e,null==t?void 0:t.api_version,n))}get(e,t,n){return Ir(Sr(this,e,null==t?void 0:t.api_version,n))}};function Pr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={body:t,api_version:n},a=Ci("body",l.body,{explode:!0}),u={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/environments")(u),p=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),d=Er(await yr(e._options.security)),m={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"CreateEnvironment",o_auth2_scopes:null,resolved_security:d,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},f=e._createRequest(m,{security:d,method:"POST",baseURL:null==o?void 0:o.server_url,path:c,headers:p,body:a,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!f.ok)return[f,{status:"invalid"}];const h=f.value,g=await e._do(h,{context:m,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:m.retry_config,retryCodes:m.retry_codes});if(!g.ok)return[g,{status:"request-error",request:h}];const v=g.value,[_]=await fr(mr("4XX"),mr("5XX"),pr("default"))(v,h);return _.ok,[_,{status:"complete",request:h,response:v}]}(e,t,n,o))}function wr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/environments/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"DeleteEnvironment",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"DELETE",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Rr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/environments/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"GetEnvironment",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"GET",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Nr(e,t,n,o,i){return new Ar(async function(e,t,n,o,i){var r,s,l;const a={api_version:t,page_size:n,page_token:o},u={api_version:Si("api_version",null!==(r=null==a?void 0:a.api_version)&&void 0!==r?r:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/environments")(u),p=Di({page_size:null==a?void 0:a.page_size,page_token:null==a?void 0:a.page_token}),d=new Headers(Ai({Accept:"application/json"})),m=Er(await yr(e._options.security)),f={options:e._options,base_url:null!==(l=null!==(s=null==i?void 0:i.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"ListEnvironments",o_auth2_scopes:null,resolved_security:m,security_source:e._options.security,retry_config:(null==i?void 0:i.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==i?void 0:i.retry_codes)||["408","409","429","5XX"]},h=e._createRequest(f,{security:m,method:"GET",baseURL:null==i?void 0:i.server_url,path:c,headers:d,query:p,body:null,userAgent:e._options.user_agent,timeout_ms:(null==i?void 0:i.timeout_ms)||e._options.timeout_ms||-1},i);if(!h.ok)return[h,{status:"invalid"}];const g=h.value,v=await e._do(g,{context:f,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:f.retry_config,retryCodes:f.retry_codes});if(!v.ok)return[v,{status:"request-error",request:g}];const _=v.value,[E]=await fr(mr("4XX"),mr("5XX"),pr("default"))(_,g);return E.ok,[E,{status:"complete",request:g,response:_}]}(e,t,n,o,i))}function Dr(e,t,n,o,i,r,s,l){return new Ar(async function(e,t,n,o,i,r,s,l){var a,u,c;const p={environment:t,path:n,api_version:o,page_size:i,page_token:r,recursive:s},d={api_version:Si("api_version",null!==(a=p.api_version)&&void 0!==a?a:e._options.api_version,{explode:!1,charEncoding:"percent"}),environment:Si("environment",p.environment,{explode:!1,charEncoding:"percent"}),path:Si("path",p.path,{explode:!1,charEncoding:"percent"})},m=_i("/{api_version}/environments/{environment}/files/{path}")(d),f=Di({page_size:p.page_size,page_token:p.page_token,recursive:p.recursive}),h=new Headers(Ai({Accept:"application/json"})),g=Er(await yr(e._options.security)),v={options:e._options,base_url:null!==(c=null!==(u=null==l?void 0:l.server_url)&&void 0!==u?u:e._baseURL)&&void 0!==c?c:"",operation_id:"GetEnvironmentFiles",o_auth2_scopes:null,resolved_security:g,security_source:e._options.security,retry_config:(null==l?void 0:l.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==l?void 0:l.retry_codes)||["408","409","429","5XX"]},_=e._createRequest(v,{security:g,method:"GET",baseURL:null==l?void 0:l.server_url,path:m,headers:h,query:f,body:null,userAgent:e._options.user_agent,timeout_ms:(null==l?void 0:l.timeout_ms)||e._options.timeout_ms||-1},l);if(!_.ok)return[_,{status:"invalid"}];const E=_.value,y=await e._do(E,{context:v,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:v.retry_config,retryCodes:v.retry_codes});if(!y.ok)return[y,{status:"request-error",request:E}];const A=y.value,[I]=await fr(pr(200),mr("4XX"),mr("5XX"))(A,E);return I.ok,[I,{status:"complete",request:E,response:A}]}(e,t,n,o,i,r,s,l))}var Gr=class extends zi{list(e,t,n,o){return Ir(Dr(this,e,t,null==n?void 0:n.api_version,null==n?void 0:n.page_size,null==n?void 0:n.page_token,null==n?void 0:n.recursive,o))}},kr=class extends zi{get files(){var e;return null!==(e=this._files)&&void 0!==e?e:this._files=new Gr(this._options)}listEnvironments(e,t){return Ir(Nr(this,null==e?void 0:e.api_version,null==e?void 0:e.page_size,null==e?void 0:e.page_token,t))}createEnvironment(e,t,n){return Ir(Pr(this,e,t,n))}deleteEnvironment(e,t,n){return Ir(wr(this,e,null==t?void 0:t.api_version,n))}getEnvironment(e,t,n){return Ir(Rr(this,e,null==t?void 0:t.api_version,n))}},Mr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="CancelInteractionByIdServerError"}},xr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="CancelInteractionByIdClientError"}},Ur=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="CreateInteractionServerError"}},Lr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="CreateInteractionClientError"}},qr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="DeleteInteractionServerError"}},Hr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="DeleteInteractionClientError"}},Fr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="GetInteractionByIdServerError"}},jr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="GetInteractionByIdClientError"}};function Br(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/interactions/{id}/cancel")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"cancelInteractionById",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"POST",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,v={httpMeta:{response:g,request:f}},[_]=await fr(pr(200),cr("4XX",xr),cr("5XX",Mr))(g,f,{extraFields:v});return _.ok,[_,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Vr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s,l;const a={body:t,api_version:n},u=a,c=Ci("body",u.body,{explode:!0}),p={api_version:Si("api_version",null!==(i=u.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"})},d=_i("/{api_version}/interactions")(p),m=new Headers(Ai({"Content-Type":"application/json",Accept:(null===(r=null==a?void 0:a.body)||void 0===r?void 0:r.stream)?"text/event-stream":"application/json"})),f=Er(await yr(e._options.security)),h={options:e._options,base_url:null!==(l=null!==(s=null==o?void 0:o.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"CreateInteraction",o_auth2_scopes:null,resolved_security:f,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},g=e._createRequest(h,{security:f,method:"POST",baseURL:null==o?void 0:o.server_url,path:d,headers:m,body:c,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!g.ok)return[g,{status:"invalid"}];const v=g.value,_=await e._do(v,{context:h,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:h.retry_config,retryCodes:h.retry_codes});if(!_.ok)return[_,{status:"request-error",request:v}];const E=_.value,y={httpMeta:{response:E,request:v}},[A]=await fr(pr(200),dr(200,{sentinel:"[DONE]",flattened:!0}),cr("4XX",Lr),cr("5XX",Ur))(E,v,{extraFields:y});return A.ok,[A,{status:"complete",request:v,response:E}]}(e,t,n,o))}function Xr(e,t,n,o,i,r,s){return new Ar(async function(e,t,n,o,i,r,s){var l,a,u;const c={id:t,api_version:n,include_input:o,last_event_id:i,stream:r},p=c,d={api_version:Si("api_version",null!==(l=p.api_version)&&void 0!==l?l:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",p.id,{explode:!1,charEncoding:"percent"})},m=_i("/{api_version}/interactions/{id}")(d),f=Di({include_input:p.include_input,last_event_id:p.last_event_id,stream:p.stream}),h=new Headers(Ai({Accept:(null==c?void 0:c.stream)?"text/event-stream":"application/json"})),g=Er(await yr(e._options.security)),v={options:e._options,base_url:null!==(u=null!==(a=null==s?void 0:s.server_url)&&void 0!==a?a:e._baseURL)&&void 0!==u?u:"",operation_id:"getInteractionById",o_auth2_scopes:null,resolved_security:g,security_source:e._options.security,retry_config:(null==s?void 0:s.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==s?void 0:s.retry_codes)||["408","409","429","5XX"]},_=e._createRequest(v,{security:g,method:"GET",baseURL:null==s?void 0:s.server_url,path:m,headers:h,query:f,body:null,userAgent:e._options.user_agent,timeout_ms:(null==s?void 0:s.timeout_ms)||e._options.timeout_ms||-1},s);if(!_.ok)return[_,{status:"invalid"}];const E=_.value,y=await e._do(E,{context:v,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:v.retry_config,retryCodes:v.retry_codes});if(!y.ok)return[y,{status:"request-error",request:E}];const A=y.value,I={httpMeta:{response:A,request:E}},[T]=await fr(pr(200),dr(200,{sentinel:"[DONE]",flattened:!0}),cr("4XX",jr),cr("5XX",Fr))(A,E,{extraFields:I});return T.ok,[T,{status:"complete",request:E,response:A}]}(e,t,n,o,i,r,s))}var Jr=class extends zi{create(e,t){const{api_version:n}=e;return Ir(Vr(this,In(e,["api_version"]),n,t))}delete(e,t,n){return Ir(function(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/interactions/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"deleteInteraction",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"DELETE",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,v={httpMeta:{response:g,request:f}},[_]=await fr(Object.assign(Object.assign({},void 0),{enc:"nil",codes:200}),cr("4XX",Hr),cr("5XX",qr))(g,f,{extraFields:v});return _.ok,[_,{status:"complete",request:f,response:g}]}(e,t,n,o))}(this,e,null==t?void 0:t.api_version,n))}get(e,t,n){return Ir(Xr(this,e,null==t?void 0:t.api_version,null==t?void 0:t.include_input,null==t?void 0:t.last_event_id,null==t?void 0:t.stream,n))}cancel(e,t,n){return Ir(Br(this,e,null==t?void 0:t.api_version,n))}};function Yr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={body:t,api_version:n},a=Ci("body",l.body,{explode:!0}),u={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/triggers")(u),p=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),d=Er(await yr(e._options.security)),m={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"CreateTrigger",o_auth2_scopes:null,resolved_security:d,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},f=e._createRequest(m,{security:d,method:"POST",baseURL:null==o?void 0:o.server_url,path:c,headers:p,body:a,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!f.ok)return[f,{status:"invalid"}];const h=f.value,g=await e._do(h,{context:m,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:m.retry_config,retryCodes:m.retry_codes});if(!g.ok)return[g,{status:"request-error",request:h}];const v=g.value,[_]=await fr(pr(200),mr("4XX"),mr("5XX"))(v,h);return _.ok,[_,{status:"complete",request:h,response:v}]}(e,t,n,o))}function $r(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/triggers/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"DeleteTrigger",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"DELETE",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(pr(200),mr("4XX"),mr("5XX"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Kr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/triggers/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"GetTrigger",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"GET",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(pr(200),mr("4XX"),mr("5XX"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Wr(e,t,n,o,i,r){return new Ar(async function(e,t,n,o,i,r){var s,l,a;const u={trigger_id:t,api_version:n,page_size:o,page_token:i},c={api_version:Si("api_version",null!==(s=u.api_version)&&void 0!==s?s:e._options.api_version,{explode:!1,charEncoding:"percent"}),trigger_id:Si("trigger_id",u.trigger_id,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/triggers/{trigger_id}/executions")(c),d=Di({page_size:u.page_size,page_token:u.page_token}),m=new Headers(Ai({Accept:"application/json"})),f=Er(await yr(e._options.security)),h={options:e._options,base_url:null!==(a=null!==(l=null==r?void 0:r.server_url)&&void 0!==l?l:e._baseURL)&&void 0!==a?a:"",operation_id:"ListTriggerExecutions",o_auth2_scopes:null,resolved_security:f,security_source:e._options.security,retry_config:(null==r?void 0:r.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==r?void 0:r.retry_codes)||["408","409","429","5XX"]},g=e._createRequest(h,{security:f,method:"GET",baseURL:null==r?void 0:r.server_url,path:p,headers:m,query:d,body:null,userAgent:e._options.user_agent,timeout_ms:(null==r?void 0:r.timeout_ms)||e._options.timeout_ms||-1},r);if(!g.ok)return[g,{status:"invalid"}];const v=g.value,_=await e._do(v,{context:h,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:h.retry_config,retryCodes:h.retry_codes});if(!_.ok)return[_,{status:"request-error",request:v}];const E=_.value,[y]=await fr(pr(200),mr("4XX"),mr("5XX"))(E,v);return y.ok,[y,{status:"complete",request:v,response:E}]}(e,t,n,o,i,r))}function zr(e,t,n,o,i,r){return new Ar(async function(e,t,n,o,i,r){var s,l,a;const u={api_version:t,filter:n,page_size:o,page_token:i},c={api_version:Si("api_version",null!==(s=null==u?void 0:u.api_version)&&void 0!==s?s:e._options.api_version,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/triggers")(c),d=Di({filter:null==u?void 0:u.filter,page_size:null==u?void 0:u.page_size,page_token:null==u?void 0:u.page_token}),m=new Headers(Ai({Accept:"application/json"})),f=Er(await yr(e._options.security)),h={options:e._options,base_url:null!==(a=null!==(l=null==r?void 0:r.server_url)&&void 0!==l?l:e._baseURL)&&void 0!==a?a:"",operation_id:"ListTriggers",o_auth2_scopes:null,resolved_security:f,security_source:e._options.security,retry_config:(null==r?void 0:r.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==r?void 0:r.retry_codes)||["408","409","429","5XX"]},g=e._createRequest(h,{security:f,method:"GET",baseURL:null==r?void 0:r.server_url,path:p,headers:m,query:d,body:null,userAgent:e._options.user_agent,timeout_ms:(null==r?void 0:r.timeout_ms)||e._options.timeout_ms||-1},r);if(!g.ok)return[g,{status:"invalid"}];const v=g.value,_=await e._do(v,{context:h,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:h.retry_config,retryCodes:h.retry_codes});if(!_.ok)return[_,{status:"request-error",request:v}];const E=_.value,[y]=await fr(pr(200),mr("4XX"),mr("5XX"))(E,v);return y.ok,[y,{status:"complete",request:v,response:E}]}(e,t,n,o,i,r))}function Zr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={trigger_id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),trigger_id:Si("trigger_id",l.trigger_id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/triggers/{trigger_id}/executions")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"RunTrigger",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"POST",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(pr(200),mr("4XX"),mr("5XX"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Qr(e,t,n,o,i){return new Ar(async function(e,t,n,o,i){var r,s,l;const a={id:t,body:n,api_version:o},u=Ci("body",a.body,{explode:!0}),c={api_version:Si("api_version",null!==(r=a.api_version)&&void 0!==r?r:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",a.id,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/triggers/{id}")(c),d=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),m=Er(await yr(e._options.security)),f={options:e._options,base_url:null!==(l=null!==(s=null==i?void 0:i.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"UpdateTrigger",o_auth2_scopes:null,resolved_security:m,security_source:e._options.security,retry_config:(null==i?void 0:i.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==i?void 0:i.retry_codes)||["408","409","429","5XX"]},h=e._createRequest(f,{security:m,method:"PATCH",baseURL:null==i?void 0:i.server_url,path:p,headers:d,body:u,userAgent:e._options.user_agent,timeout_ms:(null==i?void 0:i.timeout_ms)||e._options.timeout_ms||-1},i);if(!h.ok)return[h,{status:"invalid"}];const g=h.value,v=await e._do(g,{context:f,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:f.retry_config,retryCodes:f.retry_codes});if(!v.ok)return[v,{status:"request-error",request:g}];const _=v.value,[E]=await fr(pr(200),mr("4XX"),mr("5XX"))(_,g);return E.ok,[E,{status:"complete",request:g,response:_}]}(e,t,n,o,i))}var es=class extends zi{list(e,t){return Ir(zr(this,null==e?void 0:e.api_version,null==e?void 0:e.filter,null==e?void 0:e.page_size,null==e?void 0:e.page_token,t))}create(e,t){const{api_version:n}=e;return Ir(Yr(this,In(e,["api_version"]),n,t))}delete(e,t,n){return Ir($r(this,e,null==t?void 0:t.api_version,n))}get(e,t,n){return Ir(Kr(this,e,null==t?void 0:t.api_version,n))}update(e,t,n){const{api_version:o}=t;return Ir(Qr(this,e,In(t,["api_version"]),o,n))}listExecutions(e,t,n){return Ir(Wr(this,e,null==t?void 0:t.api_version,null==t?void 0:t.page_size,null==t?void 0:t.page_token,n))}run(e,t,n){return Ir(Zr(this,e,null==t?void 0:t.api_version,n))}};function ts(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={body:t,api_version:n},a=Ci("body",l.body,{explode:!0}),u={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/webhooks")(u),p=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),d=Er(await yr(e._options.security)),m={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"CreateWebhook",o_auth2_scopes:null,resolved_security:d,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},f=e._createRequest(m,{security:d,method:"POST",baseURL:null==o?void 0:o.server_url,path:c,headers:p,body:a,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!f.ok)return[f,{status:"invalid"}];const h=f.value,g=await e._do(h,{context:m,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:m.retry_config,retryCodes:m.retry_codes});if(!g.ok)return[g,{status:"request-error",request:h}];const v=g.value,[_]=await fr(mr("4XX"),mr("5XX"),pr("default"))(v,h);return _.ok,[_,{status:"complete",request:h,response:v}]}(e,t,n,o))}function ns(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/webhooks/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"DeleteWebhook",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"DELETE",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function os(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/webhooks/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"GetWebhook",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"GET",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function is(e,t,n,o,i){return new Ar(async function(e,t,n,o,i){var r,s,l;const a={api_version:t,page_size:n,page_token:o},u={api_version:Si("api_version",null!==(r=null==a?void 0:a.api_version)&&void 0!==r?r:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/webhooks")(u),p=Di({page_size:null==a?void 0:a.page_size,page_token:null==a?void 0:a.page_token}),d=new Headers(Ai({Accept:"application/json"})),m=Er(await yr(e._options.security)),f={options:e._options,base_url:null!==(l=null!==(s=null==i?void 0:i.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"ListWebhooks",o_auth2_scopes:null,resolved_security:m,security_source:e._options.security,retry_config:(null==i?void 0:i.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==i?void 0:i.retry_codes)||["408","409","429","5XX"]},h=e._createRequest(f,{security:m,method:"GET",baseURL:null==i?void 0:i.server_url,path:c,headers:d,query:p,body:null,userAgent:e._options.user_agent,timeout_ms:(null==i?void 0:i.timeout_ms)||e._options.timeout_ms||-1},i);if(!h.ok)return[h,{status:"invalid"}];const g=h.value,v=await e._do(g,{context:f,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:f.retry_config,retryCodes:f.retry_codes});if(!v.ok)return[v,{status:"request-error",request:g}];const _=v.value,[E]=await fr(mr("4XX"),mr("5XX"),pr("default"))(_,g);return E.ok,[E,{status:"complete",request:g,response:_}]}(e,t,n,o,i))}function rs(e,t,n,o,i){return new Ar(async function(e,t,n,o,i){var r,s,l;const a={id:t,api_version:n,body:o},u=Ci("body",a.body,{explode:!0}),c={api_version:Si("api_version",null!==(r=a.api_version)&&void 0!==r?r:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",a.id,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/webhooks/{id}:ping")(c),d=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),m=Er(await yr(e._options.security)),f={options:e._options,base_url:null!==(l=null!==(s=null==i?void 0:i.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"PingWebhook",o_auth2_scopes:null,resolved_security:m,security_source:e._options.security,retry_config:(null==i?void 0:i.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==i?void 0:i.retry_codes)||["408","409","429","5XX"]},h=e._createRequest(f,{security:m,method:"POST",baseURL:null==i?void 0:i.server_url,path:p,headers:d,body:u,userAgent:e._options.user_agent,timeout_ms:(null==i?void 0:i.timeout_ms)||e._options.timeout_ms||-1},i);if(!h.ok)return[h,{status:"invalid"}];const g=h.value,v=await e._do(g,{context:f,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:f.retry_config,retryCodes:f.retry_codes});if(!v.ok)return[v,{status:"request-error",request:g}];const _=v.value,[E]=await fr(mr("4XX"),mr("5XX"),pr("default"))(_,g);return E.ok,[E,{status:"complete",request:g,response:_}]}(e,t,n,o,i))}function ss(e,t,n,o,i){return new Ar(async function(e,t,n,o,i){var r,s,l;const a={id:t,api_version:n,body:o},u=Ci("body",a.body,{explode:!0}),c={api_version:Si("api_version",null!==(r=a.api_version)&&void 0!==r?r:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",a.id,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/webhooks/{id}:rotateSigningSecret")(c),d=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),m=Er(await yr(e._options.security)),f={options:e._options,base_url:null!==(l=null!==(s=null==i?void 0:i.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"RotateSigningSecret",o_auth2_scopes:null,resolved_security:m,security_source:e._options.security,retry_config:(null==i?void 0:i.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==i?void 0:i.retry_codes)||["408","409","429","5XX"]},h=e._createRequest(f,{security:m,method:"POST",baseURL:null==i?void 0:i.server_url,path:p,headers:d,body:u,userAgent:e._options.user_agent,timeout_ms:(null==i?void 0:i.timeout_ms)||e._options.timeout_ms||-1},i);if(!h.ok)return[h,{status:"invalid"}];const g=h.value,v=await e._do(g,{context:f,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:f.retry_config,retryCodes:f.retry_codes});if(!v.ok)return[v,{status:"request-error",request:g}];const _=v.value,[E]=await fr(mr("4XX"),mr("5XX"),pr("default"))(_,g);return E.ok,[E,{status:"complete",request:g,response:_}]}(e,t,n,o,i))}function ls(e,t,n,o,i,r){return new Ar(async function(e,t,n,o,i,r){var s,l,a;const u={id:t,api_version:n,update_mask:o,body:i},c=Ci("body",u.body,{explode:!0}),p={api_version:Si("api_version",null!==(s=u.api_version)&&void 0!==s?s:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",u.id,{explode:!1,charEncoding:"percent"})},d=_i("/{api_version}/webhooks/{id}")(p),m=Di({update_mask:u.update_mask}),f=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),h=Er(await yr(e._options.security)),g={options:e._options,base_url:null!==(a=null!==(l=null==r?void 0:r.server_url)&&void 0!==l?l:e._baseURL)&&void 0!==a?a:"",operation_id:"UpdateWebhook",o_auth2_scopes:null,resolved_security:h,security_source:e._options.security,retry_config:(null==r?void 0:r.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==r?void 0:r.retry_codes)||["408","409","429","5XX"]},v=e._createRequest(g,{security:h,method:"PATCH",baseURL:null==r?void 0:r.server_url,path:d,headers:f,query:m,body:c,userAgent:e._options.user_agent,timeout_ms:(null==r?void 0:r.timeout_ms)||e._options.timeout_ms||-1},r);if(!v.ok)return[v,{status:"invalid"}];const _=v.value,E=await e._do(_,{context:g,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:g.retry_config,retryCodes:g.retry_codes});if(!E.ok)return[E,{status:"request-error",request:_}];const y=E.value,[A]=await fr(mr("4XX"),mr("5XX"),pr("default"))(y,_);return A.ok,[A,{status:"complete",request:_,response:y}]}(e,t,n,o,i,r))}var as=class extends zi{list(e,t){return Ir(is(this,null==e?void 0:e.api_version,null==e?void 0:e.page_size,null==e?void 0:e.page_token,t))}create(e,t){const{api_version:n}=e;return Ir(ts(this,In(e,["api_version"]),n,t))}delete(e,t,n){return Ir(ns(this,e,null==t?void 0:t.api_version,n))}get(e,t,n){return Ir(os(this,e,null==t?void 0:t.api_version,n))}update(e,t,n){const o=null!=t?t:{},{api_version:i,update_mask:r}=o,s=In(o,["api_version","update_mask"]);return Ir(ls(this,e,i,r,void 0===t||0===Object.keys(s).length?void 0:s,n))}ping(e,t,n,o){return Ir(rs(this,e,t,n,o))}rotateSigningSecret(e,t,n,o){return Ir(ss(this,e,t,n,o))}},us=class extends zi{get agents(){var e;return null!==(e=this._agents)&&void 0!==e?e:this._agents=new br(this._options)}get environments(){var e;return null!==(e=this._environments)&&void 0!==e?e:this._environments=new kr(this._options)}get interactions(){var e;return null!==(e=this._interactions)&&void 0!==e?e:this._interactions=new Jr(this._options)}get triggers(){var e;return null!==(e=this._triggers)&&void 0!==e?e:this._triggers=new es(this._options)}get webhooks(){var e;return null!==(e=this._webhooks)&&void 0!==e?e:this._webhooks=new as(this._options)}},cs=/* @__PURE__ */new Set(["lyria-3-pro-preview","lyria-3-clip-preview"]);function ps(e){const t=e.getBaseUrl();if(!t)throw new Error("Base URL must be set.");return t.replace(/\/+$/,"")}function ds(e){const t=e.getApiVersion().replace(/^\/+|\/+$/g,""),n=e.getProject(),o=e.getLocation();return e.isVertexAI()&&t&&n&&o?`${t}/projects/${encodeURIComponent(n)}/locations/${encodeURIComponent(o)}`:t}function ms(e,t={}){var n,o,i,r,s;return new us(Object.assign(Object.assign({},t),{api_version:null!==(n=t.api_version)&&void 0!==n?n:ds(e),security:null!==(o=t.security)&&void 0!==o?o:new Mo({defaultHeaders:Object.assign(Object.assign({},null===(i=e.getDefaultHeaders)||void 0===i?void 0:i.call(e)),null===(r=e.getHeaders)||void 0===r?void 0:r.call(e)),getAuthHeaders:t=>e.getAuthHeaders(t)}),server_url:null!==(s=t.server_url)&&void 0!==s?s:ps(e)}))}var fs=class{constructor(e){this.parentClient=e}async create(e,t){const{api_version:n}=e,o=In(e,["api_version"]);return!0===o.stream?As(await ys(()=>this.getClient(n).interactions.create(Object.assign(Object.assign({},o),{stream:!0,api_version:n}),_s(t,!0)))):Ts(await Es(Vr(this.getClient(n),o,n,_s(t))))}async get(e,t={},n){const{api_version:o,stream:i=!1,last_event_id:r,include_input:s}=null!=t?t:{};return!0===i?As(await ys(()=>this.getClient(o).interactions.get(e,{stream:i,last_event_id:r,include_input:s,api_version:o},_s(n,!0)))):Ts(await Es(Xr(this.getClient(o),e,o,s,r,i,_s(n))))}async delete(e,t={},n){return ys(()=>this.getClient(null==t?void 0:t.api_version).interactions.delete(e,{api_version:null==t?void 0:t.api_version},_s(n)))}async cancel(e,t={},n){return Ts(await Es(Br(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n))))}getClient(e){var t;return e?ms(this.parentClient,{api_version:e}):(null!==(t=this.sdk)&&void 0!==t||(this.sdk=ms(this.parentClient)),this.sdk)}},hs=class{constructor(e){this.parentClient=e}async create(e={},t){const n=null!=e?e:{},{api_version:o}=n,i=In(n,["api_version"]);return Es(Tr(this.getClient(o),i,o,_s(t)))}async list(e={},t){const{api_version:n,pageSize:o,pageToken:i,parent:r}=null!=e?e:{};return Es(Or(this.getClient(n),n,o,i,r,_s(t)))}async get(e,t={},n){return Es(Sr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}async delete(e,t={},n){return Es(Cr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}getClient(e){var t;return e?ms(this.parentClient,{api_version:e}):(null!==(t=this.sdk)&&void 0!==t||(this.sdk=ms(this.parentClient)),this.sdk)}},gs=class{constructor(e){this.parentClient=e}async create(e,t){const{api_version:n}=e,o=In(e,["api_version"]);return Es(ts(this.getClient(),o,n,_s(t)))}async list(e={},t){const{api_version:n,page_size:o,page_token:i}=null!=e?e:{};return Es(is(this.getClient(),n,o,i,_s(t)))}async get(e,t={},n){return Es(os(this.getClient(),e,null==t?void 0:t.api_version,_s(n)))}async update(e,t={},n){const o=null!=t?t:{},{api_version:i,update_mask:r}=o,s=In(o,["api_version","update_mask"]);return Es(ls(this.getClient(),e,i,r,s,_s(n)))}async delete(e,t={},n){return Es(ns(this.getClient(),e,null==t?void 0:t.api_version,_s(n)))}async rotateSigningSecret(e,t={},n){const o=null!=t?t:{},{api_version:i}=o,r=In(o,["api_version"]);return Es(ss(this.getClient(),e,i,r,_s(n)))}async ping(e,t=void 0,n){const{api_version:o,body:i}=null!=t?t:{};return Es(rs(this.getClient(),e,o,i,_s(n)))}getClient(){var e;return null!==(e=this.sdk)&&void 0!==e||(this.sdk=ms(this.parentClient)),this.sdk}},vs=class{constructor(e){this.parentClient=e}async create(e,t){const{api_version:n}=e,o=In(e,["api_version"]);return Es(Yr(this.getClient(n),o,n,_s(t)))}async list(e={},t){const{api_version:n,filter:o,pageSize:i,pageToken:r}=null!=e?e:{};return Es(zr(this.getClient(n),n,o,i,r,_s(t)))}async get(e,t={},n){return Es(Kr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}async update(e,t,n){const{api_version:o}=t,i=In(t,["api_version"]);return Es(Qr(this.getClient(o),e,i,o,_s(n)))}async delete(e,t={},n){return Es($r(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}async run(e,t={},n){return Es(Zr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}async listExecutions(e,t={},n){const{api_version:o,pageSize:i,pageToken:r}=null!=t?t:{};return Es(Wr(this.getClient(o),e,o,i,r,_s(n)))}getClient(e){var t;return e?ms(this.parentClient,{api_version:e}):(null!==(t=this.sdk)&&void 0!==t||(this.sdk=ms(this.parentClient)),this.sdk)}};function _s(e,t=!1){var n,o,i,r;if(!e&&!t)return;const s=null!=e?e:{},{timeout:l,maxRetries:a,defaultBaseURL:u,query:c,body:p,fetchOptions:d}=s,m=In(s,["timeout","maxRetries","defaultBaseURL","query","body","fetchOptions"]),f=Object.assign({},m);Cs(c)&&(f.extra_query=c),Cs(p)&&(f.extra_body=p);const h=null!==(n=m.fetch_options)&&void 0!==n?n:d;h&&(f.fetch_options=h);const g=null!==(o=m.server_url)&&void 0!==o?o:u;g&&(f.server_url=g);const v=null!==(i=m.timeout_ms)&&void 0!==i?i:l;if(void 0!==v&&(f.timeout_ms=v),void 0!==a&&(f.retries={strategy:"attempt-count-backoff",retryConnectionErrors:!0,maxRetries:a}),t){const e=new Headers(null!==(r=f.headers)&&void 0!==r?r:null==h?void 0:h.headers);e.set("Accept","text/event-stream"),f.headers=e}return f}async function Es(e){const[t,n]=await e.$inspect();if(!t.ok)throw ui(t.error);return function(e,t){return Cs(e)&&"complete"===t.status?Object.assign(Object.assign({},e),{sdkHttpResponse:Is(t.response,e)}):e}(t.value,n)}async function ys(e){try{return await e()}catch(t){throw ui(t)}}function As(e){const t=e;return new Proxy(e,{get(e,n){if(n!==Symbol.asyncIterator){const t=Reflect.get(e,n,e);return"function"==typeof t?t.bind(e):t}return function(){const e=t[Symbol.asyncIterator]();return{async next(...t){try{return await e.next(...t)}catch(n){throw ui(n)}},async return(t){if(!e.return)return{done:!0,value:t};try{return await e.return(t)}catch(n){throw ui(n)}},async throw(t){if(!e.throw)throw ui(t);try{return await e.throw(t)}catch(n){throw ui(n)}},[Symbol.asyncIterator](){return this}}}}})}function Is(e,t){const n={};for(const[o,i]of e.headers.entries())n[o]=i;return{headers:n,responseInternal:e,json:async()=>t}}function Ts(e){const t=function(e){if(Cs(e)){if(Array.isArray(e.steps))return e;if(function(e){const t=e.model;return"string"==typeof t&&cs.has(t)}(e)){const t=e.outputs;if(Array.isArray(t)){const{outputs:n}=e,o=In(e,["outputs"]);return Object.assign(Object.assign({},o),{steps:[{type:"model_output",content:t}]})}}return Object.assign(Object.assign({},e),{steps:[]})}}(e);return t?function(e){var t,n;const o=function(e){return Object.assign(Object.assign({},e),{created:Ss(e.created),updated:Ss(e.updated)})}(e),i=null!==(t=o.steps)&&void 0!==t?t:[],r=[];let s,l,a,u=!1;e:for(let p=i.length-1;p>=0;p--){const e=i[p];if("user_input"===e.type)break;if("model_output"!==e.type||!e.content){if(u)break;continue}const t=e.content;for(let o=t.length-1;o>=0;o--){const e=t[o];if("text"===e.type)u=!0,r.push(null!==(n=e.text)&&void 0!==n?n:"");else if(u)break e}}for(let p=i.length-1;p>=0;p--){const e=i[p];if("user_input"===e.type)break;if("model_output"===e.type&&e.content)for(let t=e.content.length-1;t>=0;t--){const n=e.content[t];"image"!==n.type||s||(s=n),"audio"!==n.type||l||(l=n),"video"!==n.type||a||(a=n)}}const c=r.reverse().join("");return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},o),c&&{output_text:c}),s?{output_image:s}:{}),l?{output_audio:l}:{}),a?{output_video:a}:{})}(t):e}function Cs(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Ss(e){return e instanceof Date?e.toISOString():e}var Os=class{constructor(e){this.resolveClient=e}async list(e,t){const{environment:n,path:o,page_size:i,page_token:r,recursive:s,api_version:l}=e;return Es(Dr(this.resolveClient(l),n,o,l,i,r,s,_s(t)))}},bs=class{constructor(e){this.parentClient=e,this.files=new Os(e=>this.getClient(e))}async create(e,t){const{api_version:n}=e,o=In(e,["api_version"]);return Es(Pr(this.getClient(n),o,n,_s(t)))}async list(e={},t){const{api_version:n,page_size:o,page_token:i}=null!=e?e:{};return Es(Nr(this.getClient(n),n,o,i,_s(t)))}async get(e,t={},n){return Es(Rr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}async delete(e,t={},n){return Es(wr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}getClient(e){var t;return e?ms(this.parentClient,{api_version:e}):(null!==(t=this.sdk)&&void 0!==t||(this.sdk=ms(this.parentClient)),this.sdk)}};function Ps(e,t){const n={},o=Ze(e,["parts"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);if(null!=n&&ze(t,["mediaResolution"],n),void 0!==Ze(e,["toolCall"]))throw new Error("toolCall parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["toolResponse"]))throw new Error("toolResponse parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const o=Ze(e,["audioTranscription"]);null!=o&&ze(t,["audioTranscription"],o);const i=Ze(e,["codeExecutionResult"]);null!=i&&ze(t,["codeExecutionResult"],i);const r=Ze(e,["executableCode"]);null!=r&&ze(t,["executableCode"],r);const s=Ze(e,["fileData"]);null!=s&&ze(t,["fileData"],s);const l=Ze(e,["functionCall"]);null!=l&&ze(t,["functionCall"],l);const a=Ze(e,["functionResponse"]);null!=a&&ze(t,["functionResponse"],a);const u=Ze(e,["inlineData"]);null!=u&&ze(t,["inlineData"],u);const c=Ze(e,["text"]);null!=c&&ze(t,["text"],c);const p=Ze(e,["thought"]);null!=p&&ze(t,["thought"],p);const d=Ze(e,["thoughtSignature"]);null!=d&&ze(t,["thoughtSignature"],d);const m=Ze(e,["videoMetadata"]);if(null!=m&&ze(t,["videoMetadata"],m),void 0!==Ze(e,["partMetadata"]))throw new Error("partMetadata parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const f=Ze(e,["mediaProcessing"]);return null!=f&&ze(t,["mediaProcessing"],f),t}(e))),ze(n,["parts"],e)}const i=Ze(e,["role"]);return null!=i&&ze(n,["role"],i),n}function ws(e,t){const n={},o=Ze(e,["epochCount"]);null!=o&&ze(n,["epochCount"],o);const i=Ze(e,["learningRateMultiplier"]);null!=i&&ze(n,["learningRateMultiplier"],i);const r=Ze(e,["adapterSize"]);null!=r&&ze(n,["adapterSize"],r);const s=Ze(e,["batchSize"]);null!=s&&ze(n,["batchSize"],s);const l=Ze(e,["learningRate"]);null!=l&&ze(n,["learningRate"],l);const a=Ze(e,["generationConfig"]);return null!=a&&ze(n,["generationConfig"],function(e){const t={},n=Ze(e,["modelConfig"]);null!=n&&ze(t,["modelSelectionConfig"],n);const o=Ze(e,["responseJsonSchema"]);null!=o&&ze(t,["responseJsonSchema"],o);const i=Ze(e,["audioTranscriptionConfig"]);null!=i&&ze(t,["audioTranscriptionConfig"],i);const r=Ze(e,["audioTimestamp"]);null!=r&&ze(t,["audioTimestamp"],r);const s=Ze(e,["candidateCount"]);null!=s&&ze(t,["candidateCount"],s);const l=Ze(e,["enableAffectiveDialog"]);null!=l&&ze(t,["enableAffectiveDialog"],l);const a=Ze(e,["frequencyPenalty"]);null!=a&&ze(t,["frequencyPenalty"],a);const u=Ze(e,["logprobs"]);null!=u&&ze(t,["logprobs"],u);const c=Ze(e,["maxOutputTokens"]);null!=c&&ze(t,["maxOutputTokens"],c);const p=Ze(e,["mediaResolution"]);null!=p&&ze(t,["mediaResolution"],p);const d=Ze(e,["presencePenalty"]);null!=d&&ze(t,["presencePenalty"],d);const m=Ze(e,["responseFormat"]);if(null!=m){let e=m;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["responseFormat"],e)}const f=Ze(e,["responseLogprobs"]);null!=f&&ze(t,["responseLogprobs"],f);const h=Ze(e,["responseMimeType"]);null!=h&&ze(t,["responseMimeType"],h);const g=Ze(e,["responseModalities"]);null!=g&&ze(t,["responseModalities"],g);const v=Ze(e,["responseSchema"]);null!=v&&ze(t,["responseSchema"],v);const _=Ze(e,["routingConfig"]);null!=_&&ze(t,["routingConfig"],_);const E=Ze(e,["seed"]);null!=E&&ze(t,["seed"],E);const y=Ze(e,["speechConfig"]);null!=y&&ze(t,["speechConfig"],y);const A=Ze(e,["stopSequences"]);null!=A&&ze(t,["stopSequences"],A);const I=Ze(e,["temperature"]);null!=I&&ze(t,["temperature"],I);const T=Ze(e,["thinkingConfig"]);null!=T&&ze(t,["thinkingConfig"],T);const C=Ze(e,["topK"]);null!=C&&ze(t,["topK"],C);const S=Ze(e,["topP"]);return null!=S&&ze(t,["topP"],S),t}(a)),n}function Rs(e,t){const n={},o=Ze(e,["sdkHttpResponse"]);null!=o&&ze(n,["sdkHttpResponse"],o);const i=Ze(e,["name"]);null!=i&&ze(n,["name"],i);const r=Ze(e,["state"]);null!=r&&ze(n,["state"],en(r));const s=Ze(e,["createTime"]);null!=s&&ze(n,["createTime"],s);const l=Ze(e,["startTime"]);null!=l&&ze(n,["startTime"],l);const a=Ze(e,["endTime"]);null!=a&&ze(n,["endTime"],a);const u=Ze(e,["updateTime"]);null!=u&&ze(n,["updateTime"],u);const c=Ze(e,["error"]);null!=c&&ze(n,["error"],c);const p=Ze(e,["description"]);null!=p&&ze(n,["description"],p);const d=Ze(e,["baseModel"]);null!=d&&ze(n,["baseModel"],d);const m=Ze(e,["tunedModel"]);null!=m&&ze(n,["tunedModel"],m);const f=Ze(e,["preTunedModel"]);null!=f&&ze(n,["preTunedModel"],f);const h=Ze(e,["supervisedTuningSpec"]);null!=h&&ze(n,["supervisedTuningSpec"],h);const g=Ze(e,["preferenceOptimizationSpec"]);null!=g&&ze(n,["preferenceOptimizationSpec"],g);const v=Ze(e,["distillationSamplingSpec"]);null!=v&&ze(n,["distillationSamplingSpec"],function(e){const t={},n=Ze(e,["promptDatasetUri"]);null!=n&&ze(t,["promptDatasetUri"],n);const o=Ze(e,["validationDatasetUri"]);null!=o&&ze(t,["validationDatasetUri"],o);const i=Ze(e,["baseTeacherModel"]);null!=i&&ze(t,["baseTeacherModel"],i);const r=Ze(e,["tunedTeacherModelSource"]);null!=r&&ze(t,["tunedTeacherModelSource"],r);const s=Ze(e,["hyperparameters"]);return null!=s&&ze(t,["hyperparameters"],ws(s)),t}(v));const _=Ze(e,["distillationSpec"]);null!=_&&ze(n,["distillationSpec"],function(e){const t={},n=Ze(e,["baseTeacherModel"]);null!=n&&ze(t,["baseTeacherModel"],n);const o=Ze(e,["hyperParameters"]);null!=o&&ze(t,["hyperParameters"],ws(o));const i=Ze(e,["pipelineRootDirectory"]);null!=i&&ze(t,["pipelineRootDirectory"],i);const r=Ze(e,["promptDatasetUri"]);null!=r&&ze(t,["promptDatasetUri"],r);const s=Ze(e,["studentModel"]);null!=s&&ze(t,["studentModel"],s);const l=Ze(e,["trainingDatasetUri"]);null!=l&&ze(t,["trainingDatasetUri"],l);const a=Ze(e,["tunedTeacherModelSource"]);null!=a&&ze(t,["tunedTeacherModelSource"],a);const u=Ze(e,["tuningMode"]);null!=u&&ze(t,["tuningMode"],u);const c=Ze(e,["validationDatasetUri"]);return null!=c&&ze(t,["validationDatasetUri"],c),t}(_));const E=Ze(e,["reinforcementTuningSpec"]);null!=E&&ze(n,["reinforcementTuningSpec"],E);const y=Ze(e,["tuningDataStats"]);null!=y&&ze(n,["tuningDataStats"],y);const A=Ze(e,["encryptionSpec"]);null!=A&&ze(n,["encryptionSpec"],A);const I=Ze(e,["partnerModelTuningSpec"]);null!=I&&ze(n,["partnerModelTuningSpec"],I);const T=Ze(e,["customBaseModel"]);null!=T&&ze(n,["customBaseModel"],T);const C=Ze(e,["evaluateDatasetRuns"]);if(null!=C){let e=C;Array.isArray(e)&&(e=e.map(e=>e)),ze(n,["evaluateDatasetRuns"],e)}const S=Ze(e,["experiment"]);null!=S&&ze(n,["experiment"],S);const O=Ze(e,["fullFineTuningSpec"]);null!=O&&ze(n,["fullFineTuningSpec"],O);const b=Ze(e,["labels"]);null!=b&&ze(n,["labels"],b);const P=Ze(e,["outputUri"]);null!=P&&ze(n,["outputUri"],P);const w=Ze(e,["pipelineJob"]);null!=w&&ze(n,["pipelineJob"],w);const R=Ze(e,["serviceAccount"]);null!=R&&ze(n,["serviceAccount"],R);const N=Ze(e,["tunedModelDisplayName"]);null!=N&&ze(n,["tunedModelDisplayName"],N);const D=Ze(e,["tuningJobMetadata"]);null!=D&&ze(n,["tuningJobMetadata"],D);const G=Ze(e,["tuningJobState"]);null!=G&&ze(n,["tuningJobState"],G);const k=Ze(e,["veoLoraTuningSpec"]);null!=k&&ze(n,["veoLoraTuningSpec"],k);const M=Ze(e,["veoTuningSpec"]);return null!=M&&ze(n,["veoTuningSpec"],M),n}function Ns(e,t){const n={},o=Ze(e,["gcsUri"]);null!=o&&ze(n,["validationDatasetUri"],o);const i=Ze(e,["vertexDatasetResource"]);return null!=i&&ze(n,["validationDatasetUri"],i),n}var Ds=class extends Ke{constructor(e){super(),this.apiClient=e,this.list=async(e={})=>new vn(nt.PAGED_ITEM_TUNING_JOBS,e=>this.listInternal(e),await this.listInternal(e),e),this.get=async e=>await this.getInternal(e),this.tune=async e=>{var t;if(this.apiClient.isVertexAI()){if(e.baseModel.startsWith("projects/")){const n={tunedModelName:e.baseModel};(null===(t=e.config)||void 0===t?void 0:t.preTunedModelCheckpointId)&&(n.checkpointId=e.config.preTunedModelCheckpointId);const o=Object.assign(Object.assign({},e),{preTunedModel:n});return o.baseModel=void 0,await this.tuneInternal(o)}{const t=Object.assign({},e);return await this.tuneInternal(t)}}{const t=Object.assign({},e),n=await this.tuneMldevInternal(t);let o="";return void 0!==n.metadata&&void 0!==n.metadata.tunedModel?o=n.metadata.tunedModel:void 0!==n.name&&n.name.includes("/operations/")&&(o=n.name.split("/operations/")[0]),{name:o,state:oe.JOB_STATE_QUEUED}}}}async getInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>Rs(e))}{const t=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["name"]);null!=o&&ze(t,["name"],o);const i=Ze(e,["state"]);null!=i&&ze(t,["state"],en(i));const r=Ze(e,["createTime"]);null!=r&&ze(t,["createTime"],r);const s=Ze(e,["tuningTask","startTime"]);null!=s&&ze(t,["startTime"],s);const l=Ze(e,["tuningTask","completeTime"]);null!=l&&ze(t,["endTime"],l);const a=Ze(e,["updateTime"]);null!=a&&ze(t,["updateTime"],a);const u=Ze(e,["description"]);null!=u&&ze(t,["description"],u);const c=Ze(e,["baseModel"]);null!=c&&ze(t,["baseModel"],c);const p=Ze(e,["_self"]);return null!=p&&ze(t,["tunedModel"],function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["model"],n);const o=Ze(e,["name"]);return null!=o&&ze(t,["endpoint"],o),t}(p)),t}(e))}}async listInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o);const i=Ze(e,["filter"]);void 0!==t&&null!=i&&ze(t,["_query","filter"],i)}(n,t),t}(e);return i=We("tuningJobs",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["tuningJobs"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>Rs(e))),ze(t,["tuningJobs"],e)}return t}(e),n=new gt;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async cancel(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return s=We("{name}:cancel",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new vt;return Object.assign(n,t),n})}{const t=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return s=We("{name}:cancel",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new vt;return Object.assign(n,t),n})}}async tuneInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(e,["baseModel"]);null!=o&&ze(n,["baseModel"],o);const i=Ze(e,["preTunedModel"]);null!=i&&ze(n,["preTunedModel"],i);const r=Ze(e,["trainingDataset"]);null!=r&&function(e,t,n){let o=Ze(n,["config","method"]);if(void 0===o&&(o="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===o){const n=Ze(e,["gcsUri"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","trainingDatasetUri"],n)}else if("PREFERENCE_TUNING"===o){const n=Ze(e,["gcsUri"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","trainingDatasetUri"],n)}else if("DISTILLATION"===o){const n=Ze(e,["gcsUri"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","promptDatasetUri"],n)}else if("REINFORCEMENT_TUNING"===o){const n=Ze(e,["gcsUri"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","trainingDatasetUri"],n)}let i=Ze(n,["config","method"]);if(void 0===i&&(i="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===i){const n=Ze(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","trainingDatasetUri"],n)}else if("PREFERENCE_TUNING"===i){const n=Ze(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","trainingDatasetUri"],n)}else if("DISTILLATION"===i){const n=Ze(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","promptDatasetUri"],n)}else if("REINFORCEMENT_TUNING"===i){const n=Ze(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","trainingDatasetUri"],n)}if(void 0!==Ze(e,["examples"]))throw new Error("examples parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.")}(r,n,t);const s=Ze(e,["config"]);return null!=s&&function(e,t,n){let o=Ze(n,["config","method"]);if(void 0===o&&(o="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===o){const n=Ze(e,["validationDataset"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec"],Ns(n))}else if("PREFERENCE_TUNING"===o){const n=Ze(e,["validationDataset"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec"],Ns(n))}else if("DISTILLATION"===o){const n=Ze(e,["validationDataset"]);void 0!==t&&null!=n&&ze(t,["distillationSpec"],Ns(n))}else if("REINFORCEMENT_TUNING"===o){const n=Ze(e,["validationDataset"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec"],Ns(n))}const i=Ze(e,["tunedModelDisplayName"]);void 0!==t&&null!=i&&ze(t,["tunedModelDisplayName"],i);const r=Ze(e,["description"]);void 0!==t&&null!=r&&ze(t,["description"],r);let s=Ze(n,["config","method"]);if(void 0===s&&(s="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===s){const n=Ze(e,["epochCount"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","hyperParameters","epochCount"],n)}else if("PREFERENCE_TUNING"===s){const n=Ze(e,["epochCount"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","hyperParameters","epochCount"],n)}else if("DISTILLATION"===s){const n=Ze(e,["epochCount"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","hyperParameters","epochCount"],n)}else if("REINFORCEMENT_TUNING"===s){const n=Ze(e,["epochCount"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","hyperParameters","epochCount"],n)}let l=Ze(n,["config","method"]);if(void 0===l&&(l="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===l){const n=Ze(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","hyperParameters","learningRateMultiplier"],n)}else if("PREFERENCE_TUNING"===l){const n=Ze(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","hyperParameters","learningRateMultiplier"],n)}else if("DISTILLATION"===l){const n=Ze(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","hyperParameters","learningRateMultiplier"],n)}else if("REINFORCEMENT_TUNING"===l){const n=Ze(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","hyperParameters","learningRateMultiplier"],n)}let a=Ze(n,["config","method"]);if(void 0===a&&(a="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===a){const n=Ze(e,["exportLastCheckpointOnly"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","exportLastCheckpointOnly"],n)}else if("PREFERENCE_TUNING"===a){const n=Ze(e,["exportLastCheckpointOnly"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","exportLastCheckpointOnly"],n)}else if("DISTILLATION"===a){const n=Ze(e,["exportLastCheckpointOnly"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","exportLastCheckpointOnly"],n)}let u=Ze(n,["config","method"]);if(void 0===u&&(u="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===u){const n=Ze(e,["adapterSize"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","hyperParameters","adapterSize"],n)}else if("PREFERENCE_TUNING"===u){const n=Ze(e,["adapterSize"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","hyperParameters","adapterSize"],n)}else if("DISTILLATION"===u){const n=Ze(e,["adapterSize"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","hyperParameters","adapterSize"],n)}else if("REINFORCEMENT_TUNING"===u){const n=Ze(e,["adapterSize"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","hyperParameters","adapterSize"],n)}let c=Ze(n,["config","method"]);if(void 0===c&&(c="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===c){const n=Ze(e,["tuningMode"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","tuningMode"],n)}else if("DISTILLATION"===c){const n=Ze(e,["tuningMode"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","tuningMode"],n)}const p=Ze(e,["customBaseModel"]);void 0!==t&&null!=p&&ze(t,["customBaseModel"],p);let d=Ze(n,["config","method"]);if(void 0===d&&(d="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===d){const n=Ze(e,["batchSize"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","hyperParameters","batchSize"],n)}else if("DISTILLATION"===d){const n=Ze(e,["batchSize"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","hyperParameters","batchSize"],n)}else if("REINFORCEMENT_TUNING"===d){const n=Ze(e,["batchSize"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","hyperParameters","batchSize"],n)}let m=Ze(n,["config","method"]);if(void 0===m&&(m="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===m){const n=Ze(e,["learningRate"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","hyperParameters","learningRate"],n)}else if("DISTILLATION"===m){const n=Ze(e,["learningRate"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","hyperParameters","learningRate"],n)}const f=Ze(e,["labels"]);void 0!==t&&null!=f&&ze(t,["labels"],f);const h=Ze(e,["beta"]);void 0!==t&&null!=h&&ze(t,["preferenceOptimizationSpec","hyperParameters","beta"],h);const g=Ze(e,["baseTeacherModel"]);void 0!==t&&null!=g&&ze(t,["distillationSpec","baseTeacherModel"],g);const v=Ze(e,["tunedTeacherModelSource"]);void 0!==t&&null!=v&&ze(t,["distillationSpec","tunedTeacherModelSource"],v);const _=Ze(e,["sftLossWeightMultiplier"]);void 0!==t&&null!=_&&ze(t,["distillationSpec","hyperParameters","sftLossWeightMultiplier"],_);const E=Ze(e,["outputUri"]);void 0!==t&&null!=E&&ze(t,["outputUri"],E);const y=Ze(e,["rewardConfig"]);void 0!==t&&null!=y&&ze(t,["reinforcementTuningSpec","singleRewardConfig"],y);const A=Ze(e,["compositeRewardConfig"]);void 0!==t&&null!=A&&ze(t,["reinforcementTuningSpec","compositeRewardConfig"],A);const I=Ze(e,["samplesPerPrompt"]);void 0!==t&&null!=I&&ze(t,["reinforcementTuningSpec","hyperParameters","samplesPerPrompt"],I);const T=Ze(e,["evaluateInterval"]);void 0!==t&&null!=T&&ze(t,["reinforcementTuningSpec","hyperParameters","evaluateInterval"],T);const C=Ze(e,["checkpointInterval"]);void 0!==t&&null!=C&&ze(t,["reinforcementTuningSpec","hyperParameters","checkpointInterval"],C);const S=Ze(e,["maxOutputTokens"]);void 0!==t&&null!=S&&ze(t,["reinforcementTuningSpec","hyperParameters","maxOutputTokens"],S);const O=Ze(e,["thinkingLevel"]);void 0!==t&&null!=O&&ze(t,["reinforcementTuningSpec","hyperParameters","thinkingLevel"],O);const b=Ze(e,["validationDatasetUri"]);void 0!==t&&null!=b&&ze(t,["reinforcementTuningSpec","validationDatasetUri"],b);const P=Ze(e,["encryptionSpec"]);void 0!==t&&null!=P&&ze(t,["encryptionSpec"],P)}(s,n,t),n}(e,e);return i=We("tuningJobs",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>Rs(e))}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async tuneMldevInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["baseModel"]);null!=n&&ze(t,["baseModel"],n);const o=Ze(e,["preTunedModel"]);null!=o&&ze(t,["preTunedModel"],o);const i=Ze(e,["trainingDataset"]);null!=i&&function(e){const t={};if(void 0!==Ze(e,["gcsUri"]))throw new Error("gcsUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["vertexDatasetResource"]))throw new Error("vertexDatasetResource parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["examples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["examples","examples"],e)}}(i);const r=Ze(e,["config"]);return null!=r&&function(e,t){if(void 0!==Ze(e,["validationDataset"]))throw new Error("validationDataset parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["tunedModelDisplayName"]);if(void 0!==t&&null!=n&&ze(t,["displayName"],n),void 0!==Ze(e,["description"]))throw new Error("description parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["epochCount"]);void 0!==t&&null!=o&&ze(t,["tuningTask","hyperparameters","epochCount"],o);const i=Ze(e,["learningRateMultiplier"]);if(null!=i&&ze({},["tuningTask","hyperparameters","learningRateMultiplier"],i),void 0!==Ze(e,["exportLastCheckpointOnly"]))throw new Error("exportLastCheckpointOnly parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["preTunedModelCheckpointId"]))throw new Error("preTunedModelCheckpointId parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["adapterSize"]))throw new Error("adapterSize parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["tuningMode"]))throw new Error("tuningMode parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["customBaseModel"]))throw new Error("customBaseModel parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const r=Ze(e,["batchSize"]);void 0!==t&&null!=r&&ze(t,["tuningTask","hyperparameters","batchSize"],r);const s=Ze(e,["learningRate"]);if(void 0!==t&&null!=s&&ze(t,["tuningTask","hyperparameters","learningRate"],s),void 0!==Ze(e,["labels"]))throw new Error("labels parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["beta"]))throw new Error("beta parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["baseTeacherModel"]))throw new Error("baseTeacherModel parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["tunedTeacherModelSource"]))throw new Error("tunedTeacherModelSource parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["sftLossWeightMultiplier"]))throw new Error("sftLossWeightMultiplier parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["outputUri"]))throw new Error("outputUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["rewardConfig"]))throw new Error("rewardConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["compositeRewardConfig"]))throw new Error("compositeRewardConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["samplesPerPrompt"]))throw new Error("samplesPerPrompt parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["evaluateInterval"]))throw new Error("evaluateInterval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["checkpointInterval"]))throw new Error("checkpointInterval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["maxOutputTokens"]))throw new Error("maxOutputTokens parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["thinkingLevel"]))throw new Error("thinkingLevel parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["validationDatasetUri"]))throw new Error("validationDatasetUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["encryptionSpec"]))throw new Error("encryptionSpec parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(r,t),t}(e);return i=We("tunedModels",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["name"]);null!=o&&ze(t,["name"],o);const i=Ze(e,["metadata"]);null!=i&&ze(t,["metadata"],i);const r=Ze(e,["done"]);null!=r&&ze(t,["done"],r);const s=Ze(e,["error"]);return null!=s&&ze(t,["error"],s),t}(e))}}async validateReward(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e){const t={},n=Ze(e,["parent"]);null!=n&&ze(t,["_url","parent"],n);const o=Ze(e,["sampleResponse"]);null!=o&&ze(t,["sampleResponse"],Ps(o));const i=Ze(e,["example"]);null!=i&&ze(t,["example"],function(e){const t={},n=Ze(e,["references"]);null!=n&&ze(t,["references"],n);const o=Ze(e,["contents"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>Ps(e))),ze(t,["contents"],e)}const i=Ze(e,["systemInstruction"]);return null!=i&&ze(t,["systemInstruction"],Ps(i)),t}(i));const r=Ze(e,["singleRewardConfig"]);null!=r&&ze(t,["singleRewardConfig"],r);const s=Ze(e,["compositeRewardConfig"]);return null!=s&&ze(t,["compositeRewardConfig"],s),t}(e);return i=We("{parent}/tuningJobs:validateReinforcementTuningReward",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["overallReward"]);null!=o&&ze(t,["overallReward"],o);const i=Ze(e,["error"]);null!=i&&ze(t,["error"],i);const r=Ze(e,["rewardInfoDetails"]);return null!=r&&ze(t,["rewardInfoDetails"],r),t}(e),n=new _t;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}},Gs=class{async download(e,t){throw new Error("Download to file is not supported in the browser, please use a browser compliant download like an <a> tag.")}},ks="x-goog-upload-status";async function Ms(e,t,n,o){var i,r,s;let l=t;const a=(null==o?void 0:o.baseUrl)||(null===(i=n.clientOptions.httpOptions)||void 0===i?void 0:i.baseUrl);if(a){const e=new URL(a),n=new URL(t);n.protocol=e.protocol,n.host=e.host,n.port=e.port,l=n.toString()}let u=0,c=0,p=new ot(new Response),d="upload";for(u=e.size;c<u;){const t=Math.min(8388608,u-c),i=e.slice(c,c+t);c+t>=u&&(d+=", finalize");let a=0,m=1e3;for(;a<3;){const e=Object.assign(Object.assign({},(null==o?void 0:o.headers)||{}),{"X-Goog-Upload-Command":d,"X-Goog-Upload-Offset":String(c)});if(p=await n.request({path:"",body:i,httpMethod:"POST",httpOptions:Object.assign(Object.assign({},o),{apiVersion:"",baseUrl:l,headers:e})}),null===(r=null==p?void 0:p.headers)||void 0===r?void 0:r[ks])break;a++,await xs(m),m*=2}if(c+=t,"active"!==(null===(s=null==p?void 0:p.headers)||void 0===s?void 0:s[ks]))break;if(u<=c)throw new Error("All content has been uploaded, but the upload status is not finalized.")}return p}function xs(e){return new Promise(t=>setTimeout(t,e))}var Us=class{async upload(e,t,n,o){if("string"==typeof e)throw new Error("File path is not supported in browser uploader.");return await async function(e,t,n,o){var i;const r=await Ms(e,t,n,o),s=await(null==r?void 0:r.json());if("final"!==(null===(i=null==r?void 0:r.headers)||void 0===i?void 0:i[ks]))throw new Error("Failed to upload file: Upload status is not finalized.");return s.file}(e,t,n,o)}async uploadToFileSearchStore(e,t,n,o){if("string"==typeof e)throw new Error("File path is not supported in browser uploader.");return await async function(e,t,n,o){var i;const r=await Ms(e,t,n,o),s=await(null==r?void 0:r.json());if("final"!==(null===(i=null==r?void 0:r.headers)||void 0===i?void 0:i[ks]))throw new Error("Failed to upload file: Upload status is not finalized.");const l=tt(s),a=new Dt;return Object.assign(a,l),a}(e,t,n,o)}async stat(e){if("string"==typeof e)throw new Error("File path is not supported in browser uploader.");return await async function(e){return{size:e.size,type:e.type}}(e)}},Ls=class{create(e,t,n){return new qs(e,t,n)}},qs=class{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 new Error("WebSocket is not connected");this.ws.send(e)}close(){if(void 0===this.ws)throw new Error("WebSocket is not connected");this.ws.close()}},Hs="x-goog-api-key",Fs=class{constructor(e){this.apiKey=e}async addAuthHeaders(e,t){if(null===e.get(Hs)){if(this.apiKey.startsWith("auth_tokens/"))throw new Error("Ephemeral tokens are only supported by the live API.");if(!this.apiKey)throw new Error("API key is missing. Please provide a valid API key.");e.append(Hs,this.apiKey)}}},js=class{getNextGenClient(){const e=this.httpOptions;return void 0===this._nextGenClient&&(this._nextGenClient=ms(this.apiClient,{timeout_ms:null==e?void 0:e.timeout})),null==e||e.extraBody,this._nextGenClient}get interactions(){return void 0!==this._interactions||(this._interactions=new fs(this.apiClient)),this._interactions}get webhooks(){return void 0!==this._webhooks||(this._webhooks=new gs(this.apiClient)),this._webhooks}get agents(){return void 0!==this._agents||(this._agents=new hs(this.apiClient)),this._agents}get triggers(){return void 0!==this._triggers||(this._triggers=new vs(this.apiClient)),this._triggers}get environments(){return void 0!==this._environments||(this._environments=new bs(this.apiClient)),this._environments}constructor(e={}){var t;if(null==e.apiKey)throw new Error("An API Key must be set when running in a browser");if(e.project||e.location)throw new 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;const n=function(e,t){var n,o;if(!(null==e?void 0:e.baseUrl)){const e={geminiUrl:void 0,vertexUrl:void 0};return t?null!==(n=e.vertexUrl)&&void 0!==n?n:void 0:null!==(o=e.geminiUrl)&&void 0!==o?o:void 0}return e.baseUrl}(e.httpOptions,e.vertexai);n&&(e.httpOptions?e.httpOptions.baseUrl=n:e.httpOptions={baseUrl:n}),this.apiVersion=e.apiVersion,this.httpOptions=e.httpOptions;const o=new Fs(this.apiKey);this.apiClient=new co({auth:o,apiVersion:this.apiVersion,apiKey:this.apiKey,vertexai:this.vertexai,httpOptions:this.httpOptions,userAgentExtra:"gl-node/web",uploader:new Us,downloader:new Gs}),this.models=new bo(this.apiClient),this.live=new yo(this.apiClient,o,new Ls),this.batches=new _n(this.apiClient),this.chats=new wn(this.models,this.apiClient),this.caches=new An(this.apiClient),this.files=new Dn(this.apiClient),this.operations=new Po(this.apiClient),this.authTokens=new Ro(this.apiClient),this.tunings=new Ds(this.apiClient),this.fileSearchStores=new Do(this.apiClient)}},Bs={THINKING_LEVEL_UNSPECIFIED:D.THINKING_LEVEL_UNSPECIFIED,MINIMAL:D.MINIMAL,LOW:D.LOW,MEDIUM:D.MEDIUM,HIGH:D.HIGH};function Vs(e,t){const n=e.thinkingLevelMap?.[t],o="string"==typeof n?n.toLowerCase():t;switch(o){case"minimal":case"low":case"medium":case"high":return o;default:throw new Error(`Unsupported Google thinking level mapping for ${e.provider}/${e.id}: ${t} -> ${String(n)}`)}}function Xs(e){const t=e.id.toLowerCase();return/gemini-3(?:\.\d+)?-(?:pro|flash)/.test(t)||/gemini-(?:[4-9]|[1-9]\d)/.test(t)||"gemini-flash-latest"===t||"gemini-flash-lite-latest"===t||/gemma-?4/.test(t)}function Js(e){switch(e){case"minimal":return"MINIMAL";case"low":return"LOW";case"medium":return"MEDIUM";case"high":return"HIGH"}}function Ys(e){return Bs[e]}function $s(e){return!0===e.thought}function Ks(e,t){return"string"==typeof t&&t.length>0?t:e}var Ws=/^[A-Za-z0-9+/]+={0,2}$/;function zs(e,t){return e&&function(e){return!!e&&e.length%4==0&&Ws.test(e)}(t)?t:void 0}function Zs(e){const t=Qs(e);return e.startsWith("claude-")||e.startsWith("gpt-oss-")||void 0!==t&&t>=3}function Qs(e){const t=e.toLowerCase().match(/^gemini(?:-live)?-(\d+)/);if(t)return Number.parseInt(t[1],10)}function el(e){const t=Qs(e);return void 0===t||t>=3}var tl=/* @__PURE__ */new Set(["$schema","$id","$anchor","$dynamicAnchor","$vocabulary","$comment","$defs","definitions"]);function nl(e){if("object"!=typeof e||null===e||Array.isArray(e))return e;const t={};for(const[n,o]of Object.entries(e))tl.has(n)||(t[n]=nl(o));return t}function ol(e,t=!1,n=!0){if(0!==e.length)return[{functionDeclarations:e.map(e=>{const o=g(e,n),i=m(e,o);return{name:e.name,description:e.description,...t?{parameters:nl(i)}:{parametersJsonSchema:i}}})}]}function il(e){switch(e){case"auto":default:return L.AUTO;case"none":return L.NONE;case"any":return L.ANY}}function rl(e){switch(e){case q.STOP:return"stop";case q.MAX_TOKENS:return"length";case q.BLOCKLIST:case q.PROHIBITED_CONTENT:case q.SPII:case q.SAFETY:case q.IMAGE_SAFETY:case q.IMAGE_PROHIBITED_CONTENT:case q.IMAGE_RECITATION:case q.IMAGE_OTHER:case q.RECITATION:case q.FINISH_REASON_UNSPECIFIED:case q.OTHER:case q.LANGUAGE:case q.MALFORMED_FUNCTION_CALL:case q.UNEXPECTED_TOOL_CALL:case q.TOO_MANY_TOOL_CALLS:case q.NO_IMAGE:return"error";default:throw new Error(`Unhandled stop reason: ${e}`)}}var sl=0,ll=(e,t,m)=>{const h=new o,y=a(t);return(async()=>{const t={role:"assistant",content:[],api:"google-generative-ai",provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()};try{if(m?.fetch&&m.fetch!==globalThis.fetch)throw new Error("Custom fetch is not supported by the Google Generative AI adapter");const o=m?.apiKey;if(!o)throw new Error(`No API key for provider: ${e.provider}`);const _=function(e,t,o,i){const r={};e.baseUrl&&(r.baseUrl=e.baseUrl,r.apiVersion="");const s=p(n(e,i),e.headers,o);return s&&(r.headers=s),new js({apiKey:t,httpOptions:Object.keys(r).length>0?r:void 0})}(e,o,m?.headers,m?.identity);let E=function(e,t,n={}){const o=function(e,t){const n=r(a(t).messages),o=[],i=v(n,e,t=>Zs(e.id)?t.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,64):t);for(const r of i)if("user"===r.role)if("string"==typeof r.content)o.push({role:"user",parts:[{text:f(r.content)}]});else{const e=r.content.map(e=>"text"===e.type?{text:f(e.text)}:{inlineData:{mimeType:e.mimeType,data:e.data}});if(0===e.length)continue;o.push({role:"user",parts:e})}else if("assistant"===r.role){const t=[],n=r.provider===e.provider&&r.model===e.id;for(const o of r.content)if("text"===o.type){const e=zs(n,o.textSignature);if(!(o.text&&""!==o.text.trim()||e))continue;t.push({text:f(o.text),...e&&{thoughtSignature:e}})}else if("thinking"===o.type)if(n){const e=zs(n,o.thinkingSignature);if(!(o.thinking&&""!==o.thinking.trim()||e))continue;t.push({thought:!0,text:f(o.thinking),...e&&{thoughtSignature:e}})}else{if(!o.thinking||""===o.thinking.trim())continue;t.push({text:f(o.thinking)})}else if("toolCall"===o.type){const i=zs(n,o.thoughtSignature),r={functionCall:{name:o.name,args:o.arguments??{},...Zs(e.id)?{id:o.id}:{}},...i&&{thoughtSignature:i}};t.push(r)}if(0===t.length)continue;o.push({role:"model",parts:t})}else if("toolResult"===r.role){const t=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),n=e.input.includes("image")?r.content.filter(e=>"image"===e.type):[],i=t.trim().length>0,s=n.length>0,l=el(e.id),a=i?f(t):s?"(see attached image)":"",u=n.map(e=>({inlineData:{mimeType:e.mimeType,data:e.data}})),c=Zs(e.id),p={functionResponse:{name:r.toolName,response:r.isError?{error:a}:{output:a},...s&&l&&{parts:u},...c?{id:r.toolCallId}:{}}},d=o[o.length-1];"user"===d?.role&&d.parts?.some(e=>e.functionResponse)?d.parts.push(p):o.push({role:"user",parts:[p]}),s&&!l&&o.push({role:"user",parts:[{text:"Tool result image:"},...u]})}return o}(e,t),s=i(t.messages),p=l(t.messages),d={};void 0!==n.temperature&&(d.temperature=n.temperature),void 0!==n.maxTokens&&(d.maxOutputTokens=n.maxTokens);const m=function(e){const t=Qs(e);return void 0!==t&&t>=3}(e.id),h=p.length>0?function(e,t,n){const o=e.some(e=>!0===g(e,n));return"none"===t||"any"===t?il(t):o?L.VALIDATED:t?il(t):void 0}(p,n.toolChoice,m):void 0,_=s?c(s):"",E={...Object.keys(d).length>0&&d,..._&&{systemInstruction:f(_)},...p.length>0&&{tools:ol(p,!1,m)},...void 0!==h&&{toolConfig:{functionCallingConfig:{mode:h}}}};if(n.thinking?.enabled&&e.reasoning){const e={includeThoughts:!0};void 0!==n.thinking.level?e.thinkingLevel=Ys(n.thinking.level):void 0!==n.thinking.budgetTokens&&(e.thinkingBudget=n.thinking.budgetTokens),E.thinkingConfig=e}else e.reasoning&&n.thinking&&!n.thinking.enabled&&(E.thinkingConfig=function(e){if(!Xs(e))return{thinkingBudget:0};const t=u(e,"off");return"off"===t?{thinkingBudget:0}:{thinkingLevel:Ys(Js(Vs(e,t)))}}(e));if(n.signal){if(n.signal.aborted)throw new Error("Request aborted");E.abortSignal=n.signal}return{model:e.id,contents:o,config:E}}(e,y,m);const A=await(m?.onPayload?.(E,e));void 0!==A&&(E=A);const I=await function(e,t){return d(async()=>{try{return await _.models.generateContentStream(E)}catch(e){throw e instanceof Error&&"status"in e&&!("headers"in e)&&(e.headers=void 0),e}},{maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,signal:t?.signal})}(0,m);h.push({type:"start",partial:t});let T=null;const C=t.content,S=()=>C.length-1;for await(const n of I){await(m?.onProviderStreamEvent?.(n,e)),t.responseId||=n.responseId;const o=n.candidates?.[0];if(o?.content?.parts)for(const e of o.content.parts){if(void 0!==e.text){const n=$s(e);(!T||n&&"thinking"!==T.type||!n&&"text"!==T.type)&&(T&&("text"===T.type?h.push({type:"text_end",contentIndex:C.length-1,content:T.text,partial:t}):h.push({type:"thinking_end",contentIndex:S(),content:T.thinking,partial:t})),n?(T={type:"thinking",thinking:"",thinkingSignature:void 0},t.content.push(T),h.push({type:"thinking_start",contentIndex:S(),partial:t})):(T={type:"text",text:""},t.content.push(T),h.push({type:"text_start",contentIndex:S(),partial:t}))),"thinking"===T.type?(T.thinking+=e.text,T.thinkingSignature=Ks(T.thinkingSignature,e.thoughtSignature),h.push({type:"thinking_delta",contentIndex:S(),delta:e.text,partial:t})):(T.text+=e.text,T.textSignature=Ks(T.textSignature,e.thoughtSignature),h.push({type:"text_delta",contentIndex:S(),delta:e.text,partial:t}))}if(e.functionCall){T&&("text"===T.type?h.push({type:"text_end",contentIndex:S(),content:T.text,partial:t}):h.push({type:"thinking_end",contentIndex:S(),content:T.thinking,partial:t}),T=null);const n=e.functionCall.id,o={type:"toolCall",id:!n||t.content.some(e=>"toolCall"===e.type&&e.id===n)?`${e.functionCall.name}_${Date.now()}_${++sl}`:n,name:e.functionCall.name||"",arguments:e.functionCall.args??{},...e.thoughtSignature&&{thoughtSignature:e.thoughtSignature}};t.content.push(o),h.push({type:"toolcall_start",contentIndex:S(),partial:t}),h.push({type:"toolcall_delta",contentIndex:S(),delta:JSON.stringify(o.arguments),partial:t}),h.push({type:"toolcall_end",contentIndex:S(),toolCall:o,partial:t})}}o?.finishReason&&(t.rawStopReason=o.finishReason,t.stopReason=rl(o.finishReason),t.content.some(e=>"toolCall"===e.type)&&"stop"===t.stopReason&&(t.stopReason="toolUse")),n.usageMetadata&&(t.usage={input:(n.usageMetadata.promptTokenCount||0)-(n.usageMetadata.cachedContentTokenCount||0),output:(n.usageMetadata.candidatesTokenCount||0)+(n.usageMetadata.thoughtsTokenCount||0),cacheRead:n.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,reasoning:n.usageMetadata.thoughtsTokenCount||0,totalTokens:n.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},s(e,t.usage))}if(T&&("text"===T.type?h.push({type:"text_end",contentIndex:S(),content:T.text,partial:t}):h.push({type:"thinking_end",contentIndex:S(),content:T.thinking,partial:t})),m?.signal?.aborted)throw new Error("Request was aborted");if("pending"===t.stopReason)throw new Error("Google stream ended without a finish reason");if("aborted"===t.stopReason||"error"===t.stopReason){const e=t.rawStopReason?`Provider stopped with: ${t.rawStopReason}`:"An unknown error occurred";throw new Error(e)}h.push({type:"done",reason:t.stopReason,message:t}),h.end()}catch(o){for(const e of t.content)"index"in e&&delete e.index;t.stopReason=m?.signal?.aborted?"aborted":"error",t.errorMessage=E(_(o)),h.push({type:"error",reason:t.stopReason,error:t}),h.end()}})(),h},al=(e,t,n)=>{const o=n?.apiKey;if(!o)throw new Error(`No API key for provider: ${e.provider}`);const i={...h(e,t,n,o),toolChoice:n?.toolChoice};if(!n?.reasoning)return ll(e,t,{...i,thinking:{enabled:!1}});const r=u(e,n.reasoning);if("off"===r)return ll(e,t,{...i,thinking:{enabled:!1}});const s=Vs(e,r);return Xs(e)?ll(e,t,{...i,thinking:{enabled:!0,level:Js(s)}}):ll(e,t,{...i,thinking:{enabled:!0,budgetTokens:ul(e,s,n.thinkingBudgets)}})};function ul(e,t,n){return void 0!==n?.[t]?n[t]:e.id.includes("2.5-pro")?{minimal:128,low:2048,medium:8192,high:32768}[t]:e.id.includes("2.5-flash-lite")?{minimal:512,low:2048,medium:8192,high:24576}[t]:e.id.includes("2.5-flash")?{minimal:128,low:2048,medium:8192,high:24576}[t]:-1}export{ll as stream,al as streamSimple};
1
+ void 0===globalThis.process&&(globalThis.process={env:{},platform:"browser",version:"",versions:{},browser:!0,nextTick:function(e){return Promise.resolve().then(e)}});import{a as e,t}from"./rolldown-runtime-9urLBz53.js";import{C as n,T as o,_ as i,b as r,f as s,h as l,m as a,p as u,x as c}from"./AssistantPane-CsTLAgrN.js";import{r as p,t as d}from"./provider-retry-DNH2SSUZ.js";import{f as m,h as f,i as h,m as g,n as v}from"./transform-messages-D8-i_dD2.js";import{n as _,t as E}from"./error-body-B13t5xBI.js";var y,A,I,T,C,S,O,b,P,w,R,N,D,G,k,M,x,U,L,q,H,F,j,B,V,X,J,Y,$,K,W,z,Z,Q,ee,te,ne,oe,ie,re,se,le,ae,ue,ce,pe,de,me,fe,he,ge,ve,_e,Ee,ye,Ae,Ie,Te,Ce,Se,Oe,be,Pe,we,Re,Ne,De,Ge,ke,Me,xe,Ue,Le,qe,He,Fe,je,Be,Ve=/* @__PURE__ */t((e,t)=>{function n(e,t){"boolean"==typeof t&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}t.exports=n,n.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},n.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},n.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=/* @__PURE__ */(new Date).getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(e),this._errors.unshift(/* @__PURE__ */new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var n=this._timeouts.shift();if(void 0===n){if(!this._cachedTimeouts)return!1;this._errors.splice(0,this._errors.length-1),n=this._cachedTimeouts.slice(-1)}var o=this;return this._timer=setTimeout(function(){o._attempts++,o._operationTimeoutCb&&(o._timeout=setTimeout(function(){o._operationTimeoutCb(o._attempts)},o._operationTimeout),o._options.unref&&o._timeout.unref()),o._fn(o._attempts)},n),this._options.unref&&this._timer.unref(),!0},n.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){n._operationTimeoutCb()},n._operationTimeout)),this._operationStart=/* @__PURE__ */(new Date).getTime(),this._fn(this._attempts)},n.prototype.try=function(e){this.attempt(e)},n.prototype.start=function(e){this.attempt(e)},n.prototype.start=n.prototype.try,n.prototype.errors=function(){return this._errors},n.prototype.attempts=function(){return this._attempts},n.prototype.mainError=function(){if(0===this._errors.length)return null;for(var e={},t=null,n=0,o=0;o<this._errors.length;o++){var i=this._errors[o],r=i.message,s=(e[r]||0)+1;e[r]=s,s>=n&&(t=i,n=s)}return t}}),Xe=/* @__PURE__ */t(e=>{var t=Ve();e.operation=function(n){return new t(e.timeouts(n),{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},e.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var o=[],i=0;i<t.retries;i++)o.push(this.createTimeout(i,t));return e&&e.forever&&!o.length&&o.push(this.createTimeout(i,t)),o.sort(function(e,t){return e-t}),o},e.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,o=Math.round(n*Math.max(t.minTimeout,1)*Math.pow(t.factor,e));return Math.min(o,t.maxTimeout)},e.wrap=function(t,n,o){if(n instanceof Array&&(o=n,n=null),!o)for(var i in o=[],t)"function"==typeof t[i]&&o.push(i);for(var r=0;r<o.length;r++){var s=o[r],l=t[s];t[s]=function(o){var i=e.operation(n),r=Array.prototype.slice.call(arguments,1),s=r.pop();r.push(function(e){i.retry(e)||(e&&(arguments[0]=i.mainError()),s.apply(this,arguments))}),i.attempt(function(){o.apply(t,r)})}.bind(t,l),t[s].options=n}}}),Je=/* @__PURE__ */t((e,t)=>{t.exports=Xe()}),Ye=/* @__PURE__ */t((e,t)=>{var n=Je(),o=["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"],i=class extends Error{constructor(e){super(),e instanceof Error?(this.originalError=e,({message:e}=e)):(this.originalError=new Error(e),this.originalError.stack=this.stack),this.name="AbortError",this.message=e}},r=(e,t)=>new Promise((r,s)=>{t={onFailedAttempt:()=>{},retries:10,...t};const l=n.operation(t);l.attempt(async n=>{try{r(await e(n))}catch(u){if(!(u instanceof Error))return void s(/* @__PURE__ */new TypeError(`Non-error was thrown: "${u}". You should only throw errors.`));if(u instanceof i)l.stop(),s(u.originalError);else if(u instanceof TypeError&&(a=u.message,!o.includes(a)))l.stop(),s(u);else{((e,t,n)=>{const o=n.retries-(t-1);e.attemptNumber=t,e.retriesLeft=o})(u,n,t);try{await t.onFailedAttempt(u)}catch(u){return void s(u)}l.retry(u)||s(l.mainError())}}var a})});t.exports=r,t.exports.default=r,t.exports.AbortError=i}),$e=/* @__PURE__ */e(Ye(),1),Ke=class{};function We(e,t){return e.replace(/\{([^}]+)\}/g,(e,n)=>{if(Object.prototype.hasOwnProperty.call(t,n)){const e=t[n];return null!=e?String(e):""}throw new Error(`Key '${n}' not found in valueMap.`)})}function ze(e,t,n){for(let r=0;r<t.length-1;r++){const o=t[r];if(o.endsWith("[]")){const i=o.slice(0,-2);if(!(i in e)){if(!Array.isArray(n))throw new Error(`Value must be a list given an array path ${o}`);e[i]=Array.from({length:n.length},()=>({}))}if(Array.isArray(e[i])){const o=e[i];if(Array.isArray(n))for(let e=0;e<o.length;e++)ze(o[e],t.slice(r+1),n[e]);else for(const e of o)ze(e,t.slice(r+1),n)}return}if(o.endsWith("[0]")){const i=o.slice(0,-3);return i in e||(e[i]=[{}]),void ze(e[i][0],t.slice(r+1),n)}e[o]&&"object"==typeof e[o]||(e[o]={}),e=e[o]}const o=t[t.length-1],i=e[o];if(void 0!==i){if(!n||"object"==typeof n&&0===Object.keys(n).length)return;if(n===i)return;if("object"!=typeof i||"object"!=typeof n||null===i||null===n)throw new Error(`Cannot set value for an existing key. Key: ${o}`);Object.assign(i,n)}else"_self"!==o||"object"!=typeof n||null===n||Array.isArray(n)?e[o]=n:Object.assign(e,n)}function Ze(e,t,n=void 0){try{if(1===t.length&&"_self"===t[0])return e;for(let o=0;o<t.length;o++){if("object"!=typeof e||null===e)return n;const i=t[o];if(i.endsWith("[]")){const r=i.slice(0,-2);if(r in e){const i=e[r];return Array.isArray(i)?i.map(e=>Ze(e,t.slice(o+1),n)):n}return n}e=e[i]}return e}catch(o){if(o instanceof TypeError)return n;throw o}}function Qe(e,t,n,o,i){if(o>=t.length)return;if("object"!=typeof e||null===e)return;const r=t[o];if(r.endsWith("[]")){const s=r.slice(0,-2),l=e;if(s in l&&Array.isArray(l[s]))for(const e of l[s])Qe(e,t,n,o+1,i)}else if("*"===r){if("object"==typeof e&&null!==e&&!Array.isArray(e)){const t=e,r=Object.keys(t).filter(e=>!e.startsWith("_")&&!i.has(e)),s={};for(const e of r)s[e]=t[e];for(const[e,i]of Object.entries(s)){const r=[];for(const t of n.slice(o))"*"===t?r.push(e):r.push(t);ze(t,r,i)}for(const e of r)delete t[e]}}else r in e&&Qe(e[r],t,n,o+1,i)}function et(e){if("string"!=typeof e)throw new Error("fromImageBytes must be a string");return e}function tt(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["parent"]);null!=o&&ze(t,["parent"],o);const i=Ze(e,["documentName"]);return null!=i&&ze(t,["documentName"],i),t}(s)),t}!function(e){e.OUTCOME_UNSPECIFIED="OUTCOME_UNSPECIFIED",e.OUTCOME_OK="OUTCOME_OK",e.OUTCOME_FAILED="OUTCOME_FAILED",e.OUTCOME_DEADLINE_EXCEEDED="OUTCOME_DEADLINE_EXCEEDED"}(y||(y={})),function(e){e.LANGUAGE_UNSPECIFIED="LANGUAGE_UNSPECIFIED",e.PYTHON="PYTHON"}(A||(A={})),function(e){e.SCHEDULING_UNSPECIFIED="SCHEDULING_UNSPECIFIED",e.SILENT="SILENT",e.WHEN_IDLE="WHEN_IDLE",e.INTERRUPT="INTERRUPT"}(I||(I={})),function(e){e.TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",e.STRING="STRING",e.NUMBER="NUMBER",e.INTEGER="INTEGER",e.BOOLEAN="BOOLEAN",e.ARRAY="ARRAY",e.OBJECT="OBJECT",e.NULL="NULL"}(T||(T={})),function(e){e.AUTH_TYPE_UNSPECIFIED="AUTH_TYPE_UNSPECIFIED",e.NO_AUTH="NO_AUTH",e.API_KEY_AUTH="API_KEY_AUTH",e.HTTP_BASIC_AUTH="HTTP_BASIC_AUTH",e.GOOGLE_SERVICE_ACCOUNT_AUTH="GOOGLE_SERVICE_ACCOUNT_AUTH",e.OAUTH="OAUTH",e.OIDC_AUTH="OIDC_AUTH"}(C||(C={})),function(e){e.HTTP_IN_UNSPECIFIED="HTTP_IN_UNSPECIFIED",e.HTTP_IN_QUERY="HTTP_IN_QUERY",e.HTTP_IN_HEADER="HTTP_IN_HEADER",e.HTTP_IN_PATH="HTTP_IN_PATH",e.HTTP_IN_BODY="HTTP_IN_BODY",e.HTTP_IN_COOKIE="HTTP_IN_COOKIE"}(S||(S={})),function(e){e.API_SPEC_UNSPECIFIED="API_SPEC_UNSPECIFIED",e.SIMPLE_SEARCH="SIMPLE_SEARCH",e.ELASTIC_SEARCH="ELASTIC_SEARCH"}(O||(O={})),function(e){e.ENVIRONMENT_UNSPECIFIED="ENVIRONMENT_UNSPECIFIED",e.ENVIRONMENT_BROWSER="ENVIRONMENT_BROWSER",e.ENVIRONMENT_MOBILE="ENVIRONMENT_MOBILE",e.ENVIRONMENT_DESKTOP="ENVIRONMENT_DESKTOP"}(b||(b={})),function(e){e.SAFETY_POLICY_UNSPECIFIED="SAFETY_POLICY_UNSPECIFIED",e.FINANCIAL_TRANSACTIONS="FINANCIAL_TRANSACTIONS",e.SENSITIVE_DATA_MODIFICATION="SENSITIVE_DATA_MODIFICATION",e.COMMUNICATION_TOOL="COMMUNICATION_TOOL",e.ACCOUNT_CREATION="ACCOUNT_CREATION",e.DATA_MODIFICATION="DATA_MODIFICATION",e.USER_CONSENT_MANAGEMENT="USER_CONSENT_MANAGEMENT",e.LEGAL_TERMS_AND_AGREEMENTS="LEGAL_TERMS_AND_AGREEMENTS"}(P||(P={})),function(e){e.PHISH_BLOCK_THRESHOLD_UNSPECIFIED="PHISH_BLOCK_THRESHOLD_UNSPECIFIED",e.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",e.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",e.BLOCK_HIGH_AND_ABOVE="BLOCK_HIGH_AND_ABOVE",e.BLOCK_HIGHER_AND_ABOVE="BLOCK_HIGHER_AND_ABOVE",e.BLOCK_VERY_HIGH_AND_ABOVE="BLOCK_VERY_HIGH_AND_ABOVE",e.BLOCK_ONLY_EXTREMELY_HIGH="BLOCK_ONLY_EXTREMELY_HIGH"}(w||(w={})),function(e){e.UNSPECIFIED="UNSPECIFIED",e.BLOCKING="BLOCKING",e.NON_BLOCKING="NON_BLOCKING"}(R||(R={})),function(e){e.MODE_UNSPECIFIED="MODE_UNSPECIFIED",e.MODE_DYNAMIC="MODE_DYNAMIC"}(N||(N={})),function(e){e.THINKING_LEVEL_UNSPECIFIED="THINKING_LEVEL_UNSPECIFIED",e.MINIMAL="MINIMAL",e.LOW="LOW",e.MEDIUM="MEDIUM",e.HIGH="HIGH"}(D||(D={})),function(e){e.DONT_ALLOW="DONT_ALLOW",e.ALLOW_ADULT="ALLOW_ADULT",e.ALLOW_ALL="ALLOW_ALL"}(G||(G={})),function(e){e.PROMINENT_PEOPLE_UNSPECIFIED="PROMINENT_PEOPLE_UNSPECIFIED",e.ALLOW_PROMINENT_PEOPLE="ALLOW_PROMINENT_PEOPLE",e.BLOCK_PROMINENT_PEOPLE="BLOCK_PROMINENT_PEOPLE"}(k||(k={})),function(e){e.HARM_CATEGORY_UNSPECIFIED="HARM_CATEGORY_UNSPECIFIED",e.HARM_CATEGORY_HARASSMENT="HARM_CATEGORY_HARASSMENT",e.HARM_CATEGORY_HATE_SPEECH="HARM_CATEGORY_HATE_SPEECH",e.HARM_CATEGORY_SEXUALLY_EXPLICIT="HARM_CATEGORY_SEXUALLY_EXPLICIT",e.HARM_CATEGORY_DANGEROUS_CONTENT="HARM_CATEGORY_DANGEROUS_CONTENT",e.HARM_CATEGORY_CIVIC_INTEGRITY="HARM_CATEGORY_CIVIC_INTEGRITY",e.HARM_CATEGORY_JAILBREAK="HARM_CATEGORY_JAILBREAK",e.HARM_CATEGORY_IMAGE_HATE="HARM_CATEGORY_IMAGE_HATE",e.HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT="HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT",e.HARM_CATEGORY_IMAGE_HARASSMENT="HARM_CATEGORY_IMAGE_HARASSMENT",e.HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT="HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT"}(M||(M={})),function(e){e.HARM_BLOCK_METHOD_UNSPECIFIED="HARM_BLOCK_METHOD_UNSPECIFIED",e.SEVERITY="SEVERITY",e.PROBABILITY="PROBABILITY"}(x||(x={})),function(e){e.HARM_BLOCK_THRESHOLD_UNSPECIFIED="HARM_BLOCK_THRESHOLD_UNSPECIFIED",e.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",e.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",e.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",e.BLOCK_NONE="BLOCK_NONE",e.OFF="OFF"}(U||(U={})),function(e){e.MODE_UNSPECIFIED="MODE_UNSPECIFIED",e.AUTO="AUTO",e.ANY="ANY",e.NONE="NONE",e.VALIDATED="VALIDATED"}(L||(L={})),function(e){e.FINISH_REASON_UNSPECIFIED="FINISH_REASON_UNSPECIFIED",e.STOP="STOP",e.MAX_TOKENS="MAX_TOKENS",e.SAFETY="SAFETY",e.RECITATION="RECITATION",e.LANGUAGE="LANGUAGE",e.OTHER="OTHER",e.BLOCKLIST="BLOCKLIST",e.PROHIBITED_CONTENT="PROHIBITED_CONTENT",e.SPII="SPII",e.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",e.IMAGE_SAFETY="IMAGE_SAFETY",e.UNEXPECTED_TOOL_CALL="UNEXPECTED_TOOL_CALL",e.TOO_MANY_TOOL_CALLS="TOO_MANY_TOOL_CALLS",e.IMAGE_PROHIBITED_CONTENT="IMAGE_PROHIBITED_CONTENT",e.NO_IMAGE="NO_IMAGE",e.IMAGE_RECITATION="IMAGE_RECITATION",e.IMAGE_OTHER="IMAGE_OTHER"}(q||(q={})),function(e){e.HARM_PROBABILITY_UNSPECIFIED="HARM_PROBABILITY_UNSPECIFIED",e.NEGLIGIBLE="NEGLIGIBLE",e.LOW="LOW",e.MEDIUM="MEDIUM",e.HIGH="HIGH"}(H||(H={})),function(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"}(F||(F={})),function(e){e.URL_RETRIEVAL_STATUS_UNSPECIFIED="URL_RETRIEVAL_STATUS_UNSPECIFIED",e.URL_RETRIEVAL_STATUS_SUCCESS="URL_RETRIEVAL_STATUS_SUCCESS",e.URL_RETRIEVAL_STATUS_ERROR="URL_RETRIEVAL_STATUS_ERROR",e.URL_RETRIEVAL_STATUS_PAYWALL="URL_RETRIEVAL_STATUS_PAYWALL",e.URL_RETRIEVAL_STATUS_UNSAFE="URL_RETRIEVAL_STATUS_UNSAFE"}(j||(j={})),function(e){e.BLOCKED_REASON_UNSPECIFIED="BLOCKED_REASON_UNSPECIFIED",e.SAFETY="SAFETY",e.OTHER="OTHER",e.BLOCKLIST="BLOCKLIST",e.PROHIBITED_CONTENT="PROHIBITED_CONTENT",e.IMAGE_SAFETY="IMAGE_SAFETY",e.MODEL_ARMOR="MODEL_ARMOR",e.JAILBREAK="JAILBREAK"}(B||(B={})),function(e){e.TRAFFIC_TYPE_UNSPECIFIED="TRAFFIC_TYPE_UNSPECIFIED",e.ON_DEMAND="ON_DEMAND",e.ON_DEMAND_PRIORITY="ON_DEMAND_PRIORITY",e.ON_DEMAND_FLEX="ON_DEMAND_FLEX",e.PROVISIONED_THROUGHPUT="PROVISIONED_THROUGHPUT"}(V||(V={})),function(e){e.MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",e.TEXT="TEXT",e.IMAGE="IMAGE",e.VIDEO="VIDEO",e.AUDIO="AUDIO",e.DOCUMENT="DOCUMENT"}(X||(X={})),function(e){e.MODEL_STAGE_UNSPECIFIED="MODEL_STAGE_UNSPECIFIED",e.UNSTABLE_EXPERIMENTAL="UNSTABLE_EXPERIMENTAL",e.EXPERIMENTAL="EXPERIMENTAL",e.PREVIEW="PREVIEW",e.STABLE="STABLE",e.LEGACY="LEGACY",e.DEPRECATED="DEPRECATED",e.RETIRED="RETIRED"}(J||(J={})),function(e){e.MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",e.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",e.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",e.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH"}(Y||(Y={})),function(e){e.MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",e.TEXT="TEXT",e.IMAGE="IMAGE",e.AUDIO="AUDIO",e.VIDEO="VIDEO"}($||($={})),function(e){e.DELIVERY_UNSPECIFIED="DELIVERY_UNSPECIFIED",e.INLINE="INLINE",e.URI="URI"}(K||(K={})),function(e){e.ASPECT_RATIO_UNSPECIFIED="ASPECT_RATIO_UNSPECIFIED",e.ASPECT_RATIO_ONE_BY_ONE="ASPECT_RATIO_ONE_BY_ONE",e.ASPECT_RATIO_TWO_BY_THREE="ASPECT_RATIO_TWO_BY_THREE",e.ASPECT_RATIO_THREE_BY_TWO="ASPECT_RATIO_THREE_BY_TWO",e.ASPECT_RATIO_THREE_BY_FOUR="ASPECT_RATIO_THREE_BY_FOUR",e.ASPECT_RATIO_FOUR_BY_THREE="ASPECT_RATIO_FOUR_BY_THREE",e.ASPECT_RATIO_FOUR_BY_FIVE="ASPECT_RATIO_FOUR_BY_FIVE",e.ASPECT_RATIO_FIVE_BY_FOUR="ASPECT_RATIO_FIVE_BY_FOUR",e.ASPECT_RATIO_NINE_BY_SIXTEEN="ASPECT_RATIO_NINE_BY_SIXTEEN",e.ASPECT_RATIO_SIXTEEN_BY_NINE="ASPECT_RATIO_SIXTEEN_BY_NINE",e.ASPECT_RATIO_TWENTY_ONE_BY_NINE="ASPECT_RATIO_TWENTY_ONE_BY_NINE",e.ASPECT_RATIO_ONE_BY_EIGHT="ASPECT_RATIO_ONE_BY_EIGHT",e.ASPECT_RATIO_EIGHT_BY_ONE="ASPECT_RATIO_EIGHT_BY_ONE",e.ASPECT_RATIO_ONE_BY_FOUR="ASPECT_RATIO_ONE_BY_FOUR",e.ASPECT_RATIO_FOUR_BY_ONE="ASPECT_RATIO_FOUR_BY_ONE"}(W||(W={})),function(e){e.IMAGE_SIZE_UNSPECIFIED="IMAGE_SIZE_UNSPECIFIED",e.IMAGE_SIZE_FIVE_TWELVE="IMAGE_SIZE_FIVE_TWELVE",e.IMAGE_SIZE_ONE_K="IMAGE_SIZE_ONE_K",e.IMAGE_SIZE_TWO_K="IMAGE_SIZE_TWO_K",e.IMAGE_SIZE_FOUR_K="IMAGE_SIZE_FOUR_K"}(z||(z={})),function(e){e.TUNING_MODE_UNSPECIFIED="TUNING_MODE_UNSPECIFIED",e.TUNING_MODE_FULL="TUNING_MODE_FULL",e.TUNING_MODE_PEFT_ADAPTER="TUNING_MODE_PEFT_ADAPTER"}(Z||(Z={})),function(e){e.ADAPTER_SIZE_UNSPECIFIED="ADAPTER_SIZE_UNSPECIFIED",e.ADAPTER_SIZE_ONE="ADAPTER_SIZE_ONE",e.ADAPTER_SIZE_TWO="ADAPTER_SIZE_TWO",e.ADAPTER_SIZE_FOUR="ADAPTER_SIZE_FOUR",e.ADAPTER_SIZE_EIGHT="ADAPTER_SIZE_EIGHT",e.ADAPTER_SIZE_SIXTEEN="ADAPTER_SIZE_SIXTEEN",e.ADAPTER_SIZE_THIRTY_TWO="ADAPTER_SIZE_THIRTY_TWO"}(Q||(Q={})),function(e){e.RESPONSE_PARSE_TYPE_UNSPECIFIED="RESPONSE_PARSE_TYPE_UNSPECIFIED",e.IDENTITY="IDENTITY",e.REGEX_EXTRACT="REGEX_EXTRACT"}(ee||(ee={})),function(e){e.MATCH_OPERATION_UNSPECIFIED="MATCH_OPERATION_UNSPECIFIED",e.REGEX_CONTAINS="REGEX_CONTAINS",e.PARTIAL_MATCH="PARTIAL_MATCH",e.EXACT_MATCH="EXACT_MATCH"}(te||(te={})),function(e){e.REINFORCEMENT_TUNING_THINKING_LEVEL_UNSPECIFIED="REINFORCEMENT_TUNING_THINKING_LEVEL_UNSPECIFIED",e.MINIMAL="MINIMAL",e.HIGH="HIGH"}(ne||(ne={})),function(e){e.JOB_STATE_UNSPECIFIED="JOB_STATE_UNSPECIFIED",e.JOB_STATE_QUEUED="JOB_STATE_QUEUED",e.JOB_STATE_PENDING="JOB_STATE_PENDING",e.JOB_STATE_RUNNING="JOB_STATE_RUNNING",e.JOB_STATE_SUCCEEDED="JOB_STATE_SUCCEEDED",e.JOB_STATE_FAILED="JOB_STATE_FAILED",e.JOB_STATE_CANCELLING="JOB_STATE_CANCELLING",e.JOB_STATE_CANCELLED="JOB_STATE_CANCELLED",e.JOB_STATE_PAUSED="JOB_STATE_PAUSED",e.JOB_STATE_EXPIRED="JOB_STATE_EXPIRED",e.JOB_STATE_UPDATING="JOB_STATE_UPDATING",e.JOB_STATE_PARTIALLY_SUCCEEDED="JOB_STATE_PARTIALLY_SUCCEEDED"}(oe||(oe={})),function(e){e.TUNING_JOB_STATE_UNSPECIFIED="TUNING_JOB_STATE_UNSPECIFIED",e.TUNING_JOB_STATE_WAITING_FOR_QUOTA="TUNING_JOB_STATE_WAITING_FOR_QUOTA",e.TUNING_JOB_STATE_PROCESSING_DATASET="TUNING_JOB_STATE_PROCESSING_DATASET",e.TUNING_JOB_STATE_WAITING_FOR_CAPACITY="TUNING_JOB_STATE_WAITING_FOR_CAPACITY",e.TUNING_JOB_STATE_TUNING="TUNING_JOB_STATE_TUNING",e.TUNING_JOB_STATE_POST_PROCESSING="TUNING_JOB_STATE_POST_PROCESSING"}(ie||(ie={})),function(e){e.AGGREGATION_METRIC_UNSPECIFIED="AGGREGATION_METRIC_UNSPECIFIED",e.AVERAGE="AVERAGE",e.MODE="MODE",e.STANDARD_DEVIATION="STANDARD_DEVIATION",e.VARIANCE="VARIANCE",e.MINIMUM="MINIMUM",e.MAXIMUM="MAXIMUM",e.MEDIAN="MEDIAN",e.PERCENTILE_P90="PERCENTILE_P90",e.PERCENTILE_P95="PERCENTILE_P95",e.PERCENTILE_P99="PERCENTILE_P99"}(re||(re={})),function(e){e.PAIRWISE_CHOICE_UNSPECIFIED="PAIRWISE_CHOICE_UNSPECIFIED",e.BASELINE="BASELINE",e.CANDIDATE="CANDIDATE",e.TIE="TIE"}(se||(se={})),function(e){e.VIDEO_ORIENTATION_UNSPECIFIED="VIDEO_ORIENTATION_UNSPECIFIED",e.LANDSCAPE="LANDSCAPE",e.PORTRAIT="PORTRAIT"}(le||(le={})),function(e){e.TUNING_SPEED_UNSPECIFIED="TUNING_SPEED_UNSPECIFIED",e.REGULAR="REGULAR",e.FAST="FAST"}(ae||(ae={})),function(e){e.TUNING_TASK_UNSPECIFIED="TUNING_TASK_UNSPECIFIED",e.TUNING_TASK_I2V="TUNING_TASK_I2V",e.TUNING_TASK_T2V="TUNING_TASK_T2V",e.TUNING_TASK_R2V="TUNING_TASK_R2V"}(ue||(ue={})),function(e){e.STATE_UNSPECIFIED="STATE_UNSPECIFIED",e.STATE_PENDING="STATE_PENDING",e.STATE_ACTIVE="STATE_ACTIVE",e.STATE_FAILED="STATE_FAILED"}(ce||(ce={})),function(e){e.UNSPECIFIED="unspecified",e.FLEX="flex",e.STANDARD="standard",e.PRIORITY="priority"}(pe||(pe={})),function(e){e.MEDIA_PROCESSING_UNSPECIFIED="MEDIA_PROCESSING_UNSPECIFIED",e.STATIC="STATIC",e.AGENTIC="AGENTIC"}(de||(de={})),function(e){e.MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",e.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",e.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",e.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH",e.MEDIA_RESOLUTION_ULTRA_HIGH="MEDIA_RESOLUTION_ULTRA_HIGH"}(me||(me={})),function(e){e.TOOL_TYPE_UNSPECIFIED="TOOL_TYPE_UNSPECIFIED",e.GOOGLE_SEARCH_WEB="GOOGLE_SEARCH_WEB",e.GOOGLE_SEARCH_IMAGE="GOOGLE_SEARCH_IMAGE",e.URL_CONTEXT="URL_CONTEXT",e.GOOGLE_MAPS="GOOGLE_MAPS",e.FILE_SEARCH="FILE_SEARCH",e.MEDIA_PROCESSING="MEDIA_PROCESSING"}(fe||(fe={})),function(e){e.COLLECTION="COLLECTION"}(he||(he={})),function(e){e.FEATURE_SELECTION_PREFERENCE_UNSPECIFIED="FEATURE_SELECTION_PREFERENCE_UNSPECIFIED",e.PRIORITIZE_QUALITY="PRIORITIZE_QUALITY",e.BALANCED="BALANCED",e.PRIORITIZE_COST="PRIORITIZE_COST"}(ge||(ge={})),function(e){e.PREDICT="PREDICT",e.EMBED_CONTENT="EMBED_CONTENT"}(ve||(ve={})),function(e){e.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",e.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",e.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",e.BLOCK_NONE="BLOCK_NONE"}(_e||(_e={})),function(e){e.auto="auto",e.en="en",e.ja="ja",e.ko="ko",e.hi="hi",e.zh="zh",e.pt="pt",e.es="es"}(Ee||(Ee={})),function(e){e.MASK_MODE_DEFAULT="MASK_MODE_DEFAULT",e.MASK_MODE_USER_PROVIDED="MASK_MODE_USER_PROVIDED",e.MASK_MODE_BACKGROUND="MASK_MODE_BACKGROUND",e.MASK_MODE_FOREGROUND="MASK_MODE_FOREGROUND",e.MASK_MODE_SEMANTIC="MASK_MODE_SEMANTIC"}(ye||(ye={})),function(e){e.CONTROL_TYPE_DEFAULT="CONTROL_TYPE_DEFAULT",e.CONTROL_TYPE_CANNY="CONTROL_TYPE_CANNY",e.CONTROL_TYPE_SCRIBBLE="CONTROL_TYPE_SCRIBBLE",e.CONTROL_TYPE_FACE_MESH="CONTROL_TYPE_FACE_MESH"}(Ae||(Ae={})),function(e){e.SUBJECT_TYPE_DEFAULT="SUBJECT_TYPE_DEFAULT",e.SUBJECT_TYPE_PERSON="SUBJECT_TYPE_PERSON",e.SUBJECT_TYPE_ANIMAL="SUBJECT_TYPE_ANIMAL",e.SUBJECT_TYPE_PRODUCT="SUBJECT_TYPE_PRODUCT"}(Ie||(Ie={})),function(e){e.EDIT_MODE_DEFAULT="EDIT_MODE_DEFAULT",e.EDIT_MODE_INPAINT_REMOVAL="EDIT_MODE_INPAINT_REMOVAL",e.EDIT_MODE_INPAINT_INSERTION="EDIT_MODE_INPAINT_INSERTION",e.EDIT_MODE_OUTPAINT="EDIT_MODE_OUTPAINT",e.EDIT_MODE_CONTROLLED_EDITING="EDIT_MODE_CONTROLLED_EDITING",e.EDIT_MODE_STYLE="EDIT_MODE_STYLE",e.EDIT_MODE_BGSWAP="EDIT_MODE_BGSWAP",e.EDIT_MODE_PRODUCT_IMAGE="EDIT_MODE_PRODUCT_IMAGE"}(Te||(Te={})),function(e){e.FOREGROUND="FOREGROUND",e.BACKGROUND="BACKGROUND",e.PROMPT="PROMPT",e.SEMANTIC="SEMANTIC",e.INTERACTIVE="INTERACTIVE"}(Ce||(Ce={})),function(e){e.ASSET="ASSET",e.STYLE="STYLE"}(Se||(Se={})),function(e){e.INSERT="INSERT",e.REMOVE="REMOVE",e.REMOVE_STATIC="REMOVE_STATIC",e.OUTPAINT="OUTPAINT"}(Oe||(Oe={})),function(e){e.OPTIMIZED="OPTIMIZED",e.LOSSLESS="LOSSLESS"}(be||(be={})),function(e){e.CROP="CROP",e.PAD="PAD"}(Pe||(Pe={})),function(e){e.SUPERVISED_FINE_TUNING="SUPERVISED_FINE_TUNING",e.PREFERENCE_TUNING="PREFERENCE_TUNING",e.DISTILLATION="DISTILLATION",e.REINFORCEMENT_TUNING="REINFORCEMENT_TUNING"}(we||(we={})),function(e){e.STATE_UNSPECIFIED="STATE_UNSPECIFIED",e.PROCESSING="PROCESSING",e.ACTIVE="ACTIVE",e.FAILED="FAILED"}(Re||(Re={})),function(e){e.SOURCE_UNSPECIFIED="SOURCE_UNSPECIFIED",e.UPLOADED="UPLOADED",e.GENERATED="GENERATED",e.REGISTERED="REGISTERED"}(Ne||(Ne={})),function(e){e.TURN_COMPLETE_REASON_UNSPECIFIED="TURN_COMPLETE_REASON_UNSPECIFIED",e.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",e.RESPONSE_REJECTED="RESPONSE_REJECTED",e.NEED_MORE_INPUT="NEED_MORE_INPUT",e.PROHIBITED_INPUT_CONTENT="PROHIBITED_INPUT_CONTENT",e.IMAGE_PROHIBITED_INPUT_CONTENT="IMAGE_PROHIBITED_INPUT_CONTENT",e.INPUT_TEXT_CONTAIN_PROMINENT_PERSON_PROHIBITED="INPUT_TEXT_CONTAIN_PROMINENT_PERSON_PROHIBITED",e.INPUT_IMAGE_CELEBRITY="INPUT_IMAGE_CELEBRITY",e.INPUT_IMAGE_PHOTO_REALISTIC_CHILD_PROHIBITED="INPUT_IMAGE_PHOTO_REALISTIC_CHILD_PROHIBITED",e.INPUT_TEXT_NCII_PROHIBITED="INPUT_TEXT_NCII_PROHIBITED",e.INPUT_OTHER="INPUT_OTHER",e.INPUT_IP_PROHIBITED="INPUT_IP_PROHIBITED",e.BLOCKLIST="BLOCKLIST",e.UNSAFE_PROMPT_FOR_IMAGE_GENERATION="UNSAFE_PROMPT_FOR_IMAGE_GENERATION",e.GENERATED_IMAGE_SAFETY="GENERATED_IMAGE_SAFETY",e.GENERATED_CONTENT_SAFETY="GENERATED_CONTENT_SAFETY",e.GENERATED_AUDIO_SAFETY="GENERATED_AUDIO_SAFETY",e.GENERATED_VIDEO_SAFETY="GENERATED_VIDEO_SAFETY",e.GENERATED_CONTENT_PROHIBITED="GENERATED_CONTENT_PROHIBITED",e.GENERATED_CONTENT_BLOCKLIST="GENERATED_CONTENT_BLOCKLIST",e.GENERATED_IMAGE_PROHIBITED="GENERATED_IMAGE_PROHIBITED",e.GENERATED_IMAGE_CELEBRITY="GENERATED_IMAGE_CELEBRITY",e.GENERATED_IMAGE_PROMINENT_PEOPLE_DETECTED_BY_REWRITER="GENERATED_IMAGE_PROMINENT_PEOPLE_DETECTED_BY_REWRITER",e.GENERATED_IMAGE_IDENTIFIABLE_PEOPLE="GENERATED_IMAGE_IDENTIFIABLE_PEOPLE",e.GENERATED_IMAGE_MINORS="GENERATED_IMAGE_MINORS",e.OUTPUT_IMAGE_IP_PROHIBITED="OUTPUT_IMAGE_IP_PROHIBITED",e.GENERATED_OTHER="GENERATED_OTHER",e.MAX_REGENERATION_REACHED="MAX_REGENERATION_REACHED"}(De||(De={})),function(e){e.INTERACTION_STATUS_UNSPECIFIED="INTERACTION_STATUS_UNSPECIFIED",e.IN_PROGRESS="IN_PROGRESS",e.REQUIRES_ACTION="REQUIRES_ACTION",e.IDLE="IDLE"}(Ge||(Ge={})),function(e){e.VAD_SIGNAL_TYPE_UNSPECIFIED="VAD_SIGNAL_TYPE_UNSPECIFIED",e.VAD_SIGNAL_TYPE_SOS="VAD_SIGNAL_TYPE_SOS",e.VAD_SIGNAL_TYPE_EOS="VAD_SIGNAL_TYPE_EOS"}(ke||(ke={})),function(e){e.TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",e.ACTIVITY_START="ACTIVITY_START",e.ACTIVITY_END="ACTIVITY_END"}(Me||(Me={})),function(e){e.START_SENSITIVITY_UNSPECIFIED="START_SENSITIVITY_UNSPECIFIED",e.START_SENSITIVITY_HIGH="START_SENSITIVITY_HIGH",e.START_SENSITIVITY_LOW="START_SENSITIVITY_LOW"}(xe||(xe={})),function(e){e.END_SENSITIVITY_UNSPECIFIED="END_SENSITIVITY_UNSPECIFIED",e.END_SENSITIVITY_HIGH="END_SENSITIVITY_HIGH",e.END_SENSITIVITY_LOW="END_SENSITIVITY_LOW"}(Ue||(Ue={})),function(e){e.ACTIVITY_HANDLING_UNSPECIFIED="ACTIVITY_HANDLING_UNSPECIFIED",e.START_OF_ACTIVITY_INTERRUPTS="START_OF_ACTIVITY_INTERRUPTS",e.NO_INTERRUPTION="NO_INTERRUPTION"}(Le||(Le={})),function(e){e.TURN_COVERAGE_UNSPECIFIED="TURN_COVERAGE_UNSPECIFIED",e.TURN_INCLUDES_ONLY_ACTIVITY="TURN_INCLUDES_ONLY_ACTIVITY",e.TURN_INCLUDES_ALL_INPUT="TURN_INCLUDES_ALL_INPUT",e.TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO="TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO"}(qe||(qe={})),function(e){e.MODE_UNSPECIFIED="MODE_UNSPECIFIED",e.VERBATIM="VERBATIM",e.SMART="SMART"}(He||(He={})),function(e){e.SCALE_UNSPECIFIED="SCALE_UNSPECIFIED",e.C_MAJOR_A_MINOR="C_MAJOR_A_MINOR",e.D_FLAT_MAJOR_B_FLAT_MINOR="D_FLAT_MAJOR_B_FLAT_MINOR",e.D_MAJOR_B_MINOR="D_MAJOR_B_MINOR",e.E_FLAT_MAJOR_C_MINOR="E_FLAT_MAJOR_C_MINOR",e.E_MAJOR_D_FLAT_MINOR="E_MAJOR_D_FLAT_MINOR",e.F_MAJOR_D_MINOR="F_MAJOR_D_MINOR",e.G_FLAT_MAJOR_E_FLAT_MINOR="G_FLAT_MAJOR_E_FLAT_MINOR",e.G_MAJOR_E_MINOR="G_MAJOR_E_MINOR",e.A_FLAT_MAJOR_F_MINOR="A_FLAT_MAJOR_F_MINOR",e.A_MAJOR_G_FLAT_MINOR="A_MAJOR_G_FLAT_MINOR",e.B_FLAT_MAJOR_G_MINOR="B_FLAT_MAJOR_G_MINOR",e.B_MAJOR_A_FLAT_MINOR="B_MAJOR_A_FLAT_MINOR"}(Fe||(Fe={})),function(e){e.MUSIC_GENERATION_MODE_UNSPECIFIED="MUSIC_GENERATION_MODE_UNSPECIFIED",e.QUALITY="QUALITY",e.DIVERSITY="DIVERSITY",e.VOCALIZATION="VOCALIZATION"}(je||(je={})),function(e){e.PLAYBACK_CONTROL_UNSPECIFIED="PLAYBACK_CONTROL_UNSPECIFIED",e.PLAY="PLAY",e.PAUSE="PAUSE",e.STOP="STOP",e.RESET_CONTEXT="RESET_CONTEXT"}(Be||(Be={}));var nt,ot=class{constructor(e){const t={};for(const n of e.headers.entries())t[n[0]]=n[1];this.headers=t,this.responseInternal=e}json(){return this.responseInternal.json()}},it=class{get text(){var e,t,n,o,i,r,s,l;if(0===(null===(o=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===o?void 0:o.length))return;this.candidates&&this.candidates.length;let a="",u=!1;const c=[];for(const p of null!==(l=null===(s=null===(r=null===(i=this.candidates)||void 0===i?void 0:i[0])||void 0===r?void 0:r.content)||void 0===s?void 0:s.parts)&&void 0!==l?l:[]){for(const[e,t]of Object.entries(p))"text"===e||"thought"===e||"thoughtSignature"===e||null===t&&void 0===t||c.push(e);if("string"==typeof p.text){if("boolean"==typeof p.thought&&p.thought)continue;u=!0,a+=p.text}}return c.length,u?a:void 0}get data(){var e,t,n,o,i,r,s,l;if(0===(null===(o=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===o?void 0:o.length))return;this.candidates&&this.candidates.length;let a="";const u=[];for(const c of null!==(l=null===(s=null===(r=null===(i=this.candidates)||void 0===i?void 0:i[0])||void 0===r?void 0:r.content)||void 0===s?void 0:s.parts)&&void 0!==l?l:[]){for(const[e,t]of Object.entries(c))"inlineData"===e||null===t&&void 0===t||u.push(e);c.inlineData&&"string"==typeof c.inlineData.data&&(a+=atob(c.inlineData.data))}return u.length,a.length>0?btoa(a):void 0}get functionCalls(){var e,t,n,o,i,r,s,l;if(0===(null===(o=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===o?void 0:o.length))return;this.candidates&&this.candidates.length;const a=null===(l=null===(s=null===(r=null===(i=this.candidates)||void 0===i?void 0:i[0])||void 0===r?void 0:r.content)||void 0===s?void 0:s.parts)||void 0===l?void 0:l.filter(e=>e.functionCall).map(e=>e.functionCall).filter(e=>void 0!==e);return 0!==(null==a?void 0:a.length)?a:void 0}get executableCode(){var e,t,n,o,i,r,s,l,a;if(0===(null===(o=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===o?void 0:o.length))return;this.candidates&&this.candidates.length;const u=null===(l=null===(s=null===(r=null===(i=this.candidates)||void 0===i?void 0:i[0])||void 0===r?void 0:r.content)||void 0===s?void 0:s.parts)||void 0===l?void 0:l.filter(e=>e.executableCode).map(e=>e.executableCode).filter(e=>void 0!==e);return 0!==(null==u?void 0:u.length)?null===(a=null==u?void 0:u[0])||void 0===a?void 0:a.code:void 0}get codeExecutionResult(){var e,t,n,o,i,r,s,l,a;if(0===(null===(o=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===o?void 0:o.length))return;this.candidates&&this.candidates.length;const u=null===(l=null===(s=null===(r=null===(i=this.candidates)||void 0===i?void 0:i[0])||void 0===r?void 0:r.content)||void 0===s?void 0:s.parts)||void 0===l?void 0:l.filter(e=>e.codeExecutionResult).map(e=>e.codeExecutionResult).filter(e=>void 0!==e);return 0!==(null==u?void 0:u.length)?null===(a=null==u?void 0:u[0])||void 0===a?void 0:a.output:void 0}},rt=class{},st=class{},lt=class{},at=class{},ut=class{},ct=class{},pt=class{},dt=class{},mt=class{},ft=class{},ht=class e{_fromAPIResponse({apiResponse:t,_isVertexAI:n}){const o=new e;let i;const r=t;return i=n?function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["videos"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["_self"]);return null!=n&&ze(t,["video"],function(e){const t={},n=Ze(e,["gcsUri"]);null!=n&&ze(t,["uri"],n);const o=Ze(e,["bytesBase64Encoded"]);null!=o&&ze(t,["videoBytes"],et(o));const i=Ze(e,["mimeType"]);return null!=i&&ze(t,["mimeType"],i),t}(n)),t}(e))),ze(t,["generatedVideos"],e)}const o=Ze(e,["raiMediaFilteredCount"]);null!=o&&ze(t,["raiMediaFilteredCount"],o);const i=Ze(e,["raiMediaFilteredReasons"]);return null!=i&&ze(t,["raiMediaFilteredReasons"],i),t}(s)),t}(r):function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response","generateVideoResponse"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["generatedSamples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["video"]);return null!=n&&ze(t,["video"],function(e){const t={},n=Ze(e,["uri"]);null!=n&&ze(t,["uri"],n);const o=Ze(e,["encodedVideo"]);null!=o&&ze(t,["videoBytes"],et(o));const i=Ze(e,["encoding"]);return null!=i&&ze(t,["mimeType"],i),t}(n)),t}(e))),ze(t,["generatedVideos"],e)}const o=Ze(e,["raiMediaFilteredCount"]);null!=o&&ze(t,["raiMediaFilteredCount"],o);const i=Ze(e,["raiMediaFilteredReasons"]);return null!=i&&ze(t,["raiMediaFilteredReasons"],i),t}(s)),t}(r),Object.assign(o,i),o}},gt=class{},vt=class{},_t=class{},Et=class{},yt=class{},At=class{},It=class{},Tt=class{},Ct=class e{_fromAPIResponse({apiResponse:t,_isVertexAI:n}){const o=new e,i=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["parent"]);null!=o&&ze(t,["parent"],o);const i=Ze(e,["documentName"]);return null!=i&&ze(t,["documentName"],i),t}(s)),t}(t);return Object.assign(o,i),o}},St=class{},Ot=class{},bt=class{},Pt=class{},wt=class{},Rt=class{get text(){var e,t,n;let o="",i=!1;const r=[];for(const s 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(const[e,t]of Object.entries(s))"text"!==e&&"thought"!==e&&null!==t&&r.push(e);if("string"==typeof s.text){if("boolean"==typeof s.thought&&s.thought)continue;i=!0,o+=s.text}}return r.length,i?o:void 0}get data(){var e,t,n;let o="";const i=[];for(const 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(const[e,t]of Object.entries(r))"inlineData"!==e&&null!==t&&i.push(e);r.inlineData&&"string"==typeof r.inlineData.data&&(o+=atob(r.inlineData.data))}return i.length,o.length>0?btoa(o):void 0}},Nt=class{get audioChunk(){if(this.serverContent&&this.serverContent.audioChunks&&this.serverContent.audioChunks.length>0)return this.serverContent.audioChunks[0]}},Dt=class e{_fromAPIResponse({apiResponse:t,_isVertexAI:n}){const o=new e,i=tt(t);return Object.assign(o,i),o}};function Gt(e,t){if(!t||"string"!=typeof t)throw new Error("model is required and must be a string");if(t.includes("..")||t.includes("?")||t.includes("&"))throw new Error("invalid model parameter");if(e.isVertexAI()){if(t.startsWith("publishers/")||t.startsWith("projects/")||t.startsWith("models/"))return t;if(t.indexOf("/")>=0){const e=t.split("/",2);return`publishers/${e[0]}/models/${e[1]}`}return`publishers/google/models/${t}`}return t.startsWith("models/")||t.startsWith("tunedModels/")?t:`models/${t}`}function kt(e,t){const n=Gt(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 Mt(e){return Array.isArray(e)?e.map(e=>xt(e)):[xt(e)]}function xt(e){if("object"==typeof e&&null!==e)return e;throw new Error("Could not parse input as Blob. Unsupported blob type: "+typeof e)}function Ut(e){const t=xt(e);if(t.mimeType&&t.mimeType.startsWith("image/"))return t;throw new Error(`Unsupported mime type: ${t.mimeType}`)}function Lt(e){const t=xt(e);if(t.mimeType&&t.mimeType.startsWith("audio/"))return t;throw new Error(`Unsupported mime type: ${t.mimeType}`)}function qt(e){if(null==e)throw new Error("PartUnion is required");if("object"==typeof e)return e;if("string"==typeof e)return{text:e};throw new Error("Unsupported part type: "+typeof e)}function Ht(e){if(null==e||Array.isArray(e)&&0===e.length)throw new Error("PartListUnion is required");return Array.isArray(e)?e.map(e=>qt(e)):[qt(e)]}function Ft(e){return null!=e&&"object"==typeof e&&"parts"in e&&Array.isArray(e.parts)}function jt(e){return null!=e&&"object"==typeof e&&"functionCall"in e}function Bt(e){return null!=e&&"object"==typeof e&&"functionResponse"in e}function Vt(e){if(null==e)throw new Error("ContentUnion is required");return Ft(e)?e:{role:"user",parts:Ht(e)}}function Xt(e,t){if(!t)return[];if(e.isVertexAI()&&Array.isArray(t))return t.flatMap(e=>{const t=Vt(e);return t.parts&&t.parts.length>0&&void 0!==t.parts[0].text?[t.parts[0].text]:[]});if(e.isVertexAI()){const e=Vt(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=>Vt(e)):[Vt(t)]}function Jt(e){if(null==e||Array.isArray(e)&&0===e.length)throw new Error("contents are required");if(!Array.isArray(e)){if(jt(e)||Bt(e))throw new Error("To specify functionCall or functionResponse parts, please wrap them in a Content object, specifying the role for them");return[Vt(e)]}const t=[],n=[],o=Ft(e[0]);for(const i of e){const e=Ft(i);if(e!=o)throw new 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(i);else{if(jt(i)||Bt(i))throw new Error("To specify functionCall or functionResponse parts, please wrap them, and any other parts, in Content objects as appropriate, specifying the role for them");n.push(i)}}return o||t.push({role:"user",parts:Ht(n)}),t}function Yt(e){const t={},n=["items"],o=["anyOf"],i=["properties"];if(e.type&&e.anyOf)throw new Error("type and anyOf cannot be both populated.");const r=e.anyOf;null!=r&&2==r.length&&("null"===r[0].type?(t.nullable=!0,e=r[1]):"null"===r[1].type&&(t.nullable=!0,e=r[0])),e.type instanceof Array&&function(e,t){e.includes("null")&&(t.nullable=!0);const n=e.filter(e=>"null"!==e);if(1===n.length)t.type=Object.values(T).includes(n[0].toUpperCase())?n[0].toUpperCase():T.TYPE_UNSPECIFIED;else{t.anyOf=[];for(const e of n)t.anyOf.push({type:Object.values(T).includes(e.toUpperCase())?e.toUpperCase():T.TYPE_UNSPECIFIED})}}(e.type,t);for(const[s,l]of Object.entries(e))if(null!=l)if("type"==s){if("null"===l)throw new Error("type: null can not be the only possible type for the field.");if(l instanceof Array)continue;t.type=Object.values(T).includes(l.toUpperCase())?l.toUpperCase():T.TYPE_UNSPECIFIED}else if(n.includes(s))t[s]=Yt(l);else if(o.includes(s)){const e=[];for(const n of l)"null"!=n.type?e.push(Yt(n)):t.nullable=!0;t[s]=e}else if(i.includes(s)){const e={};for(const[t,n]of Object.entries(l))e[t]=Yt(n);t[s]=e}else{if("additionalProperties"===s)continue;t[s]=l}return t}function $t(e){return Yt(e)}function Kt(e){if("object"==typeof e)return e;if("string"==typeof e)return{voiceConfig:{prebuiltVoiceConfig:{voiceName:e}}};throw new Error("Unsupported speechConfig type: "+typeof e)}function Wt(e){if("multiSpeakerVoiceConfig"in e)throw new Error("multiSpeakerVoiceConfig is not supported in the live API.");return e}function zt(e){if(e.functionDeclarations)for(const t of e.functionDeclarations)t.parameters&&(Object.keys(t.parameters).includes("$schema")?t.parametersJsonSchema||(t.parametersJsonSchema=t.parameters,delete t.parameters):t.parameters=Yt(t.parameters)),t.response&&(Object.keys(t.response).includes("$schema")?t.responseJsonSchema||(t.responseJsonSchema=t.response,delete t.response):t.response=Yt(t.response));return e}function Zt(e){if(null==e)throw new Error("tools is required");if(!Array.isArray(e))throw new Error("tools is required and must be an array of Tools");const t=[];for(const n of e)t.push(n);return t}function Qt(e,t){if("string"!=typeof t)throw new Error("name must be a string");return function(e,t,n,o=1){const i=!t.startsWith(`${n}/`)&&t.split("/").length===o;return e.isVertexAI()?t.startsWith("projects/")?t:t.startsWith("locations/")?`projects/${e.getProject()}/${t}`:t.startsWith(`${n}/`)?`projects/${e.getProject()}/locations/${e.getLocation()}/${t}`:i?`projects/${e.getProject()}/locations/${e.getLocation()}/${n}/${t}`:t:i?`${n}/${t}`:t}(e,t,"cachedContents")}function en(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 tn(e){return et(e)}function nn(e){var t;let n;var o;if(null!=(o=e)&&"object"==typeof o&&"name"in o&&(n=e.name),!(function(e){return null!=e&&"object"==typeof e&&"uri"in e}(e)&&(n=e.uri,void 0===n)||function(e){return null!=e&&"object"==typeof e&&"video"in e}(e)&&(n=null===(t=e.video)||void 0===t?void 0:t.uri,void 0===n))){if("string"==typeof e&&(n=e),void 0===n)throw new Error("Could not extract file name from the provided input.");if(n.startsWith("https://")){const e=n.split("files/")[1].match(/[a-z0-9]+/);if(null===e)throw new Error(`Could not extract file name from URI ${n}`);n=e[0]}else n.startsWith("files/")&&(n=n.split("files/")[1]);return n}}function on(e,t){let n;return n=e.isVertexAI()?t?"publishers/google/models":"models":t?"models":"tunedModels",n}function rn(e){for(const t of["models","tunedModels","publisherModels"])if(sn(e,t))return e[t];return[]}function sn(e,t){return null!==e&&"object"==typeof e&&t in e}function ln(e,t={}){const n=e,o={name:n.name,description:n.description,parametersJsonSchema:n.inputSchema};return n.outputSchema&&(o.responseJsonSchema=n.outputSchema),t.behavior&&(o.behavior=t.behavior),{functionDeclarations:[o]}}function an(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{if(!/^projects\/[^/]+\/locations\/[^/]+\/datasets\/[^/]+$/.test(t))throw new Error(`Unsupported string source for Vertex AI: ${t}`);n={format:"vertex-dataset",vertexDatasetName:t}}else{if(!t.startsWith("files/"))throw new Error(`Unsupported string source for Gemini API: ${t}`);n={fileName:t}}else if(Array.isArray(t)){if(e.isVertexAI())throw new Error("InlinedRequest[] is not supported in Vertex AI.");n={inlinedRequests:t}}else n=t;const o=[n.gcsUri,n.bigqueryUri,n.vertexDatasetName].filter(Boolean).length,i=[n.inlinedRequests,n.fileName].filter(Boolean).length;if(e.isVertexAI()){if(i>0||1!==o)throw new Error("Exactly one of `gcsUri`, `bigqueryUri`, or `vertexDatasetName` must be set for Vertex AI.")}else if(o>0||1!==i)throw new Error("Exactly one of `inlinedRequests`, `fileName`, must be set for Gemini API.");return n}function un(e){if("object"!=typeof e||null===e)return{};const t=e,n=t.inlinedResponses;if("object"!=typeof n||null===n)return e;const o=n.inlinedResponses;if(!Array.isArray(o)||0===o.length)return e;let i=!1;for(const r of o){if("object"!=typeof r||null===r)continue;const e=r.response;if("object"==typeof e&&null!==e&&void 0!==e.embedding){i=!0;break}}return i&&(t.inlinedEmbedContentResponses=t.inlinedResponses,delete t.inlinedResponses),e}function cn(e,t){const n=t;if(!e.isVertexAI()){if(/batches\/[^/]+$/.test(n))return n.split("/").pop();throw new Error(`Invalid batch job name: ${n}.`)}if(/^projects\/[^/]+\/locations\/[^/]+\/batchPredictionJobs\/[^/]+$/.test(n))return n.split("/").pop();if(/^\d+$/.test(n))return n;throw new Error(`Invalid batch job name: ${n}.`)}function pn(e){return"BATCH_STATE_UNSPECIFIED"===e?"JOB_STATE_UNSPECIFIED":"BATCH_STATE_PENDING"===e?"JOB_STATE_PENDING":"BATCH_STATE_RUNNING"===e?"JOB_STATE_RUNNING":"BATCH_STATE_SUCCEEDED"===e?"JOB_STATE_SUCCEEDED":"BATCH_STATE_FAILED"===e?"JOB_STATE_FAILED":"BATCH_STATE_CANCELLED"===e?"JOB_STATE_CANCELLED":"BATCH_STATE_EXPIRED"===e?"JOB_STATE_EXPIRED":e}function dn(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata","displayName"]);null!=o&&ze(t,["displayName"],o);const i=Ze(e,["metadata","state"]);null!=i&&ze(t,["state"],pn(i));const r=Ze(e,["metadata","createTime"]);null!=r&&ze(t,["createTime"],r);const s=Ze(e,["metadata","endTime"]);null!=s&&ze(t,["endTime"],s);const l=Ze(e,["metadata","updateTime"]);null!=l&&ze(t,["updateTime"],l);const a=Ze(e,["metadata","model"]);null!=a&&ze(t,["model"],a);const u=Ze(e,["metadata","output"]);return null!=u&&ze(t,["dest"],function(e){const t={},n=Ze(e,["responsesFile"]);null!=n&&ze(t,["fileName"],n);const o=Ze(e,["inlinedResponses","inlinedResponses"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["response"]);null!=n&&ze(t,["response"],function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["candidates"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["content"]);null!=n&&ze(t,["content"],n);const o=Ze(e,["citationMetadata"]);null!=o&&ze(t,["citationMetadata"],function(e){const t={},n=Ze(e,["citationSources"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["citations"],e)}return t}(o));const i=Ze(e,["tokenCount"]);null!=i&&ze(t,["tokenCount"],i);const r=Ze(e,["finishReason"]);null!=r&&ze(t,["finishReason"],r);const s=Ze(e,["groundingMetadata"]);null!=s&&ze(t,["groundingMetadata"],s);const l=Ze(e,["avgLogprobs"]);null!=l&&ze(t,["avgLogprobs"],l);const a=Ze(e,["index"]);null!=a&&ze(t,["index"],a);const u=Ze(e,["logprobsResult"]);null!=u&&ze(t,["logprobsResult"],u);const c=Ze(e,["safetyRatings"]);if(null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["safetyRatings"],e)}const p=Ze(e,["urlContextMetadata"]);return null!=p&&ze(t,["urlContextMetadata"],p),t}(e))),ze(t,["candidates"],e)}const i=Ze(e,["modelVersion"]);null!=i&&ze(t,["modelVersion"],i);const r=Ze(e,["promptFeedback"]);null!=r&&ze(t,["promptFeedback"],r);const s=Ze(e,["responseId"]);null!=s&&ze(t,["responseId"],s);const l=Ze(e,["usageMetadata"]);null!=l&&ze(t,["usageMetadata"],l);const a=Ze(e,["modelStatus"]);return null!=a&&ze(t,["modelStatus"],a),t}(n));const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["error"]);return null!=i&&ze(t,["error"],i),t}(e))),ze(t,["inlinedResponses"],e)}const i=Ze(e,["inlinedEmbedContentResponses","inlinedResponses"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["inlinedEmbedContentResponses"],e)}return t}(un(u))),t}function mn(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["displayName"]);null!=o&&ze(t,["displayName"],o);const i=Ze(e,["state"]);null!=i&&ze(t,["state"],pn(i));const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["createTime"]);null!=s&&ze(t,["createTime"],s);const l=Ze(e,["startTime"]);null!=l&&ze(t,["startTime"],l);const a=Ze(e,["endTime"]);null!=a&&ze(t,["endTime"],a);const u=Ze(e,["updateTime"]);null!=u&&ze(t,["updateTime"],u);const c=Ze(e,["model"]);null!=c&&ze(t,["model"],c);const p=Ze(e,["inputConfig"]);null!=p&&ze(t,["src"],function(e){const t={},n=Ze(e,["instancesFormat"]);null!=n&&ze(t,["format"],n);const o=Ze(e,["gcsSource","uris"]);null!=o&&ze(t,["gcsUri"],o);const i=Ze(e,["bigquerySource","inputUri"]);null!=i&&ze(t,["bigqueryUri"],i);const r=Ze(e,["vertexMultimodalDatasetSource","datasetName"]);return null!=r&&ze(t,["vertexDatasetName"],r),t}(p));const d=Ze(e,["outputConfig"]);null!=d&&ze(t,["dest"],function(e){const t={},n=Ze(e,["predictionsFormat"]);null!=n&&ze(t,["format"],n);const o=Ze(e,["gcsDestination","outputUriPrefix"]);null!=o&&ze(t,["gcsUri"],o);const i=Ze(e,["bigqueryDestination","outputUri"]);null!=i&&ze(t,["bigqueryUri"],i);const r=Ze(e,["vertexMultimodalDatasetDestination"]);return null!=r&&ze(t,["vertexDataset"],function(e){const t={},n=Ze(e,["bigqueryDestination","outputUri"]);null!=n&&ze(t,["bigqueryDestination"],n);const o=Ze(e,["displayName"]);return null!=o&&ze(t,["displayName"],o),t}(r)),t}(un(d)));const m=Ze(e,["outputInfo"]);null!=m&&ze(t,["outputInfo"],m);const f=Ze(e,["completionStats"]);return null!=f&&ze(t,["completionStats"],f),t}function fn(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);null!=n&&ze(t,["mediaResolution"],n);const o=Ze(e,["toolCall"]);null!=o&&ze(t,["toolCall"],o);const i=Ze(e,["toolResponse"]);null!=i&&ze(t,["toolResponse"],i);const r=Ze(e,["audioTranscription"]);null!=r&&ze(t,["audioTranscription"],r);const s=Ze(e,["codeExecutionResult"]);null!=s&&ze(t,["codeExecutionResult"],s);const l=Ze(e,["executableCode"]);null!=l&&ze(t,["executableCode"],l);const a=Ze(e,["fileData"]);null!=a&&ze(t,["fileData"],function(e){const t={};if(void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["fileUri"]);null!=n&&ze(t,["fileUri"],n);const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(a));const u=Ze(e,["functionCall"]);null!=u&&ze(t,["functionCall"],function(e){const t={},n=Ze(e,["args"]);null!=n&&ze(t,["args"],n);const o=Ze(e,["id"]);null!=o&&ze(t,["id"],o);const i=Ze(e,["name"]);if(null!=i&&ze(t,["name"],i),void 0!==Ze(e,["partialArgs"]))throw new Error("partialArgs parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["willContinue"]))throw new Error("willContinue parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(u));const c=Ze(e,["functionResponse"]);null!=c&&ze(t,["functionResponse"],c);const p=Ze(e,["inlineData"]);null!=p&&ze(t,["inlineData"],function(e){const t={},n=Ze(e,["data"]);if(null!=n&&ze(t,["data"],n),void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(p));const d=Ze(e,["text"]);null!=d&&ze(t,["text"],d);const m=Ze(e,["thought"]);null!=m&&ze(t,["thought"],m);const f=Ze(e,["thoughtSignature"]);null!=f&&ze(t,["thoughtSignature"],f);const h=Ze(e,["videoMetadata"]);null!=h&&ze(t,["videoMetadata"],h);const g=Ze(e,["partMetadata"]);null!=g&&ze(t,["partMetadata"],g);const v=Ze(e,["mediaProcessing"]);return null!=v&&ze(t,["mediaProcessing"],v),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}function hn(e,t){const n=Ze(e,["displayName"]);void 0!==t&&null!=n&&ze(t,["displayName"],n);const o=Ze(e,["dest"]);if(void 0!==t&&null!=o&&ze(t,["outputConfig"],function(e){const t={},n=Ze(e,["format"]);null!=n&&ze(t,["predictionsFormat"],n);const o=Ze(e,["gcsUri"]);null!=o&&ze(t,["gcsDestination","outputUriPrefix"],o);const i=Ze(e,["bigqueryUri"]);null!=i&&ze(t,["bigqueryDestination","outputUri"],i);const r=Ze(e,["vertexDataset"]);if(null!=r&&ze(t,["vertexMultimodalDatasetDestination"],function(e){const t={},n=Ze(e,["bigqueryDestination"]);null!=n&&ze(t,["bigqueryDestination","outputUri"],n);const o=Ze(e,["displayName"]);return null!=o&&ze(t,["displayName"],o),t}(r)),void 0!==Ze(e,["fileName"]))throw new Error("fileName parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["inlinedResponses"]))throw new Error("inlinedResponses parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["inlinedEmbedContentResponses"]))throw new Error("inlinedEmbedContentResponses parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(function(e){if("string"!=typeof e)return e;const t=e;if(t.startsWith("gs://"))return{format:"jsonl",gcsUri:t};if(t.startsWith("bq://"))return{format:"bigquery",bigqueryUri:t};throw new Error(`Unsupported destination: ${t}`)}(o))),void 0!==Ze(e,["webhookConfig"]))throw new Error("webhookConfig parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return{}}function gn(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["src"]);null!=i&&ze(n,["batch","inputConfig"],function(e,t){const n={};if(void 0!==Ze(t,["format"]))throw new Error("format parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(t,["gcsUri"]))throw new Error("gcsUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(t,["bigqueryUri"]))throw new Error("bigqueryUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(t,["vertexDatasetName"]))throw new Error("vertexDatasetName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(t,["fileName"]);null!=o&&ze(n,["fileName"],o);const i=Ze(t,["inlinedRequests"]);if(null!=i){let t=i;Array.isArray(t)&&(t=t.map(t=>function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["request","model"],Gt(e,o));const i=Ze(t,["contents"]);if(null!=i){let e=Jt(i);Array.isArray(e)&&(e=e.map(e=>fn(e))),ze(n,["request","contents"],e)}const r=Ze(t,["metadata"]);null!=r&&ze(n,["metadata"],r);const s=Ze(t,["config"]);return null!=s&&ze(n,["request","generationConfig"],function(e,t,n){const o={},i=Ze(t,["serviceTier"]);void 0!==n&&null!=i&&ze(n,["serviceTier"],i);const r=Ze(t,["systemInstruction"]);void 0!==n&&null!=r&&ze(n,["systemInstruction"],fn(Vt(r)));const s=Ze(t,["temperature"]);null!=s&&ze(o,["temperature"],s);const l=Ze(t,["topP"]);null!=l&&ze(o,["topP"],l);const a=Ze(t,["topK"]);null!=a&&ze(o,["topK"],a);const u=Ze(t,["candidateCount"]);null!=u&&ze(o,["candidateCount"],u);const c=Ze(t,["maxOutputTokens"]);null!=c&&ze(o,["maxOutputTokens"],c);const p=Ze(t,["stopSequences"]);null!=p&&ze(o,["stopSequences"],p);const d=Ze(t,["responseLogprobs"]);null!=d&&ze(o,["responseLogprobs"],d);const m=Ze(t,["logprobs"]);null!=m&&ze(o,["logprobs"],m);const f=Ze(t,["presencePenalty"]);null!=f&&ze(o,["presencePenalty"],f);const h=Ze(t,["frequencyPenalty"]);null!=h&&ze(o,["frequencyPenalty"],h);const g=Ze(t,["seed"]);null!=g&&ze(o,["seed"],g);const v=Ze(t,["responseMimeType"]);null!=v&&ze(o,["responseMimeType"],v);const _=Ze(t,["responseSchema"]);null!=_&&ze(o,["responseSchema"],$t(_));const E=Ze(t,["responseJsonSchema"]);if(null!=E&&ze(o,["responseJsonSchema"],E),void 0!==Ze(t,["routingConfig"]))throw new Error("routingConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(t,["modelSelectionConfig"]))throw new Error("modelSelectionConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const y=Ze(t,["safetySettings"]);if(void 0!==n&&null!=y){let e=y;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["category"]);if(null!=n&&ze(t,["category"],n),void 0!==Ze(e,["method"]))throw new Error("method parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["threshold"]);return null!=o&&ze(t,["threshold"],o),t}(e))),ze(n,["safetySettings"],e)}const A=Ze(t,["tools"]);if(void 0!==n&&null!=A){let e=Zt(A);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==Ze(e,["retrieval"]))throw new Error("retrieval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["googleMaps"]);null!=n&&ze(t,["googleMaps"],function(e){const t={},n=Ze(e,["authConfig"]);null!=n&&ze(t,["authConfig"],function(e){const t={},n=Ze(e,["apiKey"]);if(null!=n&&ze(t,["apiKey"],n),void 0!==Ze(e,["apiKeyConfig"]))throw new Error("apiKeyConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["authType"]))throw new Error("authType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["googleServiceAccountConfig"]))throw new Error("googleServiceAccountConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["httpBasicAuthConfig"]))throw new Error("httpBasicAuthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oauthConfig"]))throw new Error("oauthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oidcConfig"]))throw new Error("oidcConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["enableWidget"]);if(null!=o&&ze(t,["enableWidget"],o),void 0!==Ze(e,["groundingTypes"]))throw new Error("groundingTypes parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["mcpServers"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mcpServers"],e)}const i=Ze(e,["codeExecution"]);null!=i&&ze(t,["codeExecution"],i);const r=Ze(e,["computerUse"]);if(null!=r&&ze(t,["computerUse"],r),void 0!==Ze(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["exaAiSearch"]))throw new Error("exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const s=Ze(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const l=Ze(e,["googleSearch"]);null!=l&&ze(t,["googleSearch"],function(e){const t={};if(void 0!==Ze(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["excludeDomains"]))throw new Error("excludeDomains parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["searchTypes"]);null!=n&&ze(t,["searchTypes"],n);const o=Ze(e,["timeRangeFilter"]);return null!=o&&ze(t,["timeRangeFilter"],o),t}(l));const a=Ze(e,["googleSearchRetrieval"]);if(null!=a&&ze(t,["googleSearchRetrieval"],a),void 0!==Ze(e,["parallelAiSearch"]))throw new Error("parallelAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["urlContext"]);null!=u&&ze(t,["urlContext"],u);const c=Ze(e,["fileSearch"]);return null!=c&&ze(t,["fileSearch"],c),t}(zt(e)))),ze(n,["tools"],e)}const I=Ze(t,["toolConfig"]);if(void 0!==n&&null!=I&&ze(n,["toolConfig"],function(e){const t={},n=Ze(e,["functionCallingConfig"]);null!=n&&ze(t,["functionCallingConfig"],function(e){const t={},n=Ze(e,["allowedFunctionNames"]);null!=n&&ze(t,["allowedFunctionNames"],n);const o=Ze(e,["mode"]);if(null!=o&&ze(t,["mode"],o),void 0!==Ze(e,["streamFunctionCallArguments"]))throw new Error("streamFunctionCallArguments parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["retrievalConfig"]);null!=o&&ze(t,["retrievalConfig"],o);const i=Ze(e,["includeServerSideToolInvocations"]);return null!=i&&ze(t,["includeServerSideToolInvocations"],i),t}(I)),void 0!==Ze(t,["labels"]))throw new Error("labels parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const T=Ze(t,["cachedContent"]);void 0!==n&&null!=T&&ze(n,["cachedContent"],Qt(e,T));const C=Ze(t,["responseModalities"]);null!=C&&ze(o,["responseModalities"],C);const S=Ze(t,["mediaResolution"]);null!=S&&ze(o,["mediaResolution"],S);const O=Ze(t,["speechConfig"]);if(null!=O&&ze(o,["speechConfig"],Kt(O)),void 0!==Ze(t,["audioTimestamp"]))throw new Error("audioTimestamp parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const b=Ze(t,["thinkingConfig"]);null!=b&&ze(o,["thinkingConfig"],b);const P=Ze(t,["audioTranscriptionConfig"]);null!=P&&ze(o,["audioTranscriptionConfig"],P);const w=Ze(t,["imageConfig"]);null!=w&&ze(o,["imageConfig"],function(e){const t={},n=Ze(e,["aspectRatio"]);null!=n&&ze(t,["aspectRatio"],n);const o=Ze(e,["imageSize"]);if(null!=o&&ze(t,["imageSize"],o),void 0!==Ze(e,["personGeneration"]))throw new Error("personGeneration parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["outputMimeType"]))throw new Error("outputMimeType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["outputCompressionQuality"]))throw new Error("outputCompressionQuality parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["imageOutputOptions"]))throw new Error("imageOutputOptions parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["prominentPeople"]))throw new Error("prominentPeople parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(w));const R=Ze(t,["enableEnhancedCivicAnswers"]);if(null!=R&&ze(o,["enableEnhancedCivicAnswers"],R),void 0!==Ze(t,["modelArmorConfig"]))throw new Error("modelArmorConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return o}(e,s,Ze(n,["request"],{}))),n}(e,t))),ze(n,["requests","requests"],t)}return n}(e,an(e,i)));const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["displayName"]);if(void 0!==t&&null!=n&&ze(t,["batch","displayName"],n),void 0!==Ze(e,["dest"]))throw new Error("dest parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["webhookConfig"]);void 0!==t&&null!=o&&ze(t,["batch","webhookConfig"],o)}(r,n),n}!function(e){e.PAGED_ITEM_BATCH_JOBS="batchJobs",e.PAGED_ITEM_MODELS="models",e.PAGED_ITEM_TUNING_JOBS="tuningJobs",e.PAGED_ITEM_FILES="files",e.PAGED_ITEM_CACHED_CONTENTS="cachedContents",e.PAGED_ITEM_FILE_SEARCH_STORES="fileSearchStores",e.PAGED_ITEM_DOCUMENTS="documents",e.PAGED_ITEM_SKILLS="skills"}(nt||(nt={}));var vn=class{constructor(e,t,n,o){this.pageInternal=[],this.paramsInternal={},this.requestInternal=t,this.init(e,n,o)}init(e,t,n){var o,i;this.nameInternal=e,this.pageInternal=t[this.nameInternal]||[],this.sdkHttpResponseInternal=null==t?void 0:t.sdkHttpResponse,this.idxInternal=0;let r={config:{}};r=n&&0!==Object.keys(n).length?"object"==typeof n?Object.assign({},n):n:{config:{}},r.config&&(r.config.pageToken=t.nextPageToken),this.paramsInternal=r,this.pageInternalSize=null!==(i=null===(o=r.config)||void 0===o?void 0:o.pageSize)&&void 0!==i?i: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()}const 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 new Error("No more pages to fetch.");const e=await this.requestInternal(this.params);return this.initNextPage(e),this.page}hasNextPage(){var e;return void 0!==(null===(e=this.params.config)||void 0===e?void 0:e.pageToken)}},_n=class extends Ke{constructor(e){super(),this.apiClient=e,this.list=async(e={})=>new vn(nt.PAGED_ITEM_BATCH_JOBS,e=>this.listInternal(e),await this.listInternal(e),e),this.create=async e=>(this.apiClient.isVertexAI()&&(e.config=this.formatDestination(e.src,e.config)),this.createInternal(e)),this.createEmbeddings=async e=>{if(this.apiClient.isVertexAI())throw new Error("Gemini Enterprise Agent Platform (previously known as Vertex AI) does not support batches.createEmbeddings.");return this.createEmbeddingsInternal(e)}}createInlinedGenerateContentRequest(e){const t=gn(this.apiClient,e),n=We("{model}:batchGenerateContent",t._url),o=t.batch.inputConfig.requests,i=o.requests,r=[];for(const s of i){const e=Object.assign({},s);if(e.systemInstruction){const t=e.systemInstruction;delete e.systemInstruction;const n=e.request;n.systemInstruction=t,e.request=n}r.push(e)}return o.requests=r,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){const n=t?Object.assign({},t):{},o=Date.now().toString();if(n.displayName||(n.displayName=`genaiBatchJob_${o}`),void 0===n.dest){const t=this.getGcsUri(e),i=this.getBigqueryUri(e);if(t)t.endsWith(".jsonl")?n.dest=`${t.slice(0,-6)}/dest`:n.dest=`${t}_dest_${o}`;else{if(!i)throw new Error("Unsupported source for Gemini Enterprise Agent Platform (previously known as Vertex AI): No GCS or BigQuery URI found.");n.dest=`${i}_dest_${o}`}}return n}async createInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["model"],Gt(e,o));const i=Ze(t,["src"]);null!=i&&ze(n,["inputConfig"],function(e){const t={},n=Ze(e,["format"]);null!=n&&ze(t,["instancesFormat"],n);const o=Ze(e,["gcsUri"]);null!=o&&ze(t,["gcsSource","uris"],o);const i=Ze(e,["bigqueryUri"]);null!=i&&ze(t,["bigquerySource","inputUri"],i);const r=Ze(e,["vertexDatasetName"]);if(null!=r&&ze(t,["vertexMultimodalDatasetSource","datasetName"],r),void 0!==Ze(e,["fileName"]))throw new Error("fileName parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["inlinedRequests"]))throw new Error("inlinedRequests parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(an(e,i)));const r=Ze(t,["config"]);return null!=r&&hn(r,n),n}(this.apiClient,e);return s=We("batchPredictionJobs",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>mn(e))}{const t=gn(this.apiClient,e);return s=We("{model}:batchGenerateContent",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>dn(e))}}async createEmbeddingsInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["src"]);null!=i&&ze(n,["batch","inputConfig"],function(e,t){const n={},o=Ze(t,["fileName"]);null!=o&&ze(n,["file_name"],o);const i=Ze(t,["inlinedRequests"]);return null!=i&&ze(n,["requests"],function(e,t){const n={},o=Ze(t,["contents"]);if(null!=o){let t=Xt(e,o);Array.isArray(t)&&(t=t.map(e=>e)),ze(n,["requests[]","request","content"],t)}const i=Ze(t,["config"]);return null!=i&&(ze(n,["_self"],function(e,t){const n=Ze(e,["taskType"]);void 0!==t&&null!=n&&ze(t,["requests[]","taskType"],n);const o=Ze(e,["title"]);void 0!==t&&null!=o&&ze(t,["requests[]","title"],o);const i=Ze(e,["outputDimensionality"]);if(void 0!==t&&null!=i&&ze(t,["requests[]","outputDimensionality"],i),void 0!==Ze(e,["mimeType"]))throw new Error("mimeType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["autoTruncate"]))throw new Error("autoTruncate parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["documentOcr"]))throw new Error("documentOcr parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["audioTrackExtraction"]))throw new Error("audioTrackExtraction parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return{}}(i,n)),function(e){for(const[t,n]of Object.entries({"requests[].*":"requests[].request.*"})){const o=t.split("."),i=n.split("."),r=/* @__PURE__ */new Set;let s=-1;for(let e=0;e<o.length;e++)if("*"===o[e]){s=e;break}if(-1!==s&&i.length>s)for(let e=s;e<i.length;e++){const t=i[e];"*"===t||t.endsWith("[]")||t.endsWith("[0]")||r.add(t)}Qe(e,o,i,0,r)}}(n)),n}(e,i)),n}(e,i));const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["displayName"]);void 0!==t&&null!=n&&ze(t,["batch","displayName"],n)}(r,n),n}(this.apiClient,e);return i=We("{model}:asyncBatchEmbedContent",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>dn(e))}}async get(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);return s=We("batchPredictionJobs/{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>mn(e))}{const t=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);return s=We("batches/{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>dn(e))}}async cancel(e){var t,n,o,i;let r="",s={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);r=We("batchPredictionJobs/{name}:cancel",o._url),s=o._query,delete o._url,delete o._query,await this.apiClient.request({path:r,queryParams:s,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})}else{const t=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);r=We("batches/{name}:cancel",t._url),s=t._query,delete t._url,delete t._query,await this.apiClient.request({path:r,queryParams:s,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal})}}async listInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o);const i=Ze(e,["filter"]);void 0!==t&&null!=i&&ze(t,["_query","filter"],i)}(n,t),t}(e);return s=We("batchPredictionJobs",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["batchPredictionJobs"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>mn(e))),ze(t,["batchJobs"],e)}return t}(e),n=new wt;return Object.assign(n,t),n})}{const t=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);if(void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o),void 0!==Ze(e,["filter"]))throw new Error("filter parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(n,t),t}(e);return s=We("batches",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["operations"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>dn(e))),ze(t,["batchJobs"],e)}return t}(e),n=new wt;return Object.assign(n,t),n})}}async delete(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);return s=We("batchPredictionJobs/{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["name"]);null!=o&&ze(t,["name"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);return null!=r&&ze(t,["error"],r),t}(e))}{const t=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],cn(e,o)),n}(this.apiClient,e);return s=We("batches/{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"DELETE",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["name"]);null!=o&&ze(t,["name"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);return null!=r&&ze(t,["error"],r),t}(e))}}};function En(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);null!=n&&ze(t,["mediaResolution"],n);const o=Ze(e,["toolCall"]);null!=o&&ze(t,["toolCall"],o);const i=Ze(e,["toolResponse"]);null!=i&&ze(t,["toolResponse"],i);const r=Ze(e,["audioTranscription"]);null!=r&&ze(t,["audioTranscription"],r);const s=Ze(e,["codeExecutionResult"]);null!=s&&ze(t,["codeExecutionResult"],s);const l=Ze(e,["executableCode"]);null!=l&&ze(t,["executableCode"],l);const a=Ze(e,["fileData"]);null!=a&&ze(t,["fileData"],function(e){const t={};if(void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["fileUri"]);null!=n&&ze(t,["fileUri"],n);const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(a));const u=Ze(e,["functionCall"]);null!=u&&ze(t,["functionCall"],function(e){const t={},n=Ze(e,["args"]);null!=n&&ze(t,["args"],n);const o=Ze(e,["id"]);null!=o&&ze(t,["id"],o);const i=Ze(e,["name"]);if(null!=i&&ze(t,["name"],i),void 0!==Ze(e,["partialArgs"]))throw new Error("partialArgs parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["willContinue"]))throw new Error("willContinue parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(u));const c=Ze(e,["functionResponse"]);null!=c&&ze(t,["functionResponse"],c);const p=Ze(e,["inlineData"]);null!=p&&ze(t,["inlineData"],function(e){const t={},n=Ze(e,["data"]);if(null!=n&&ze(t,["data"],n),void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(p));const d=Ze(e,["text"]);null!=d&&ze(t,["text"],d);const m=Ze(e,["thought"]);null!=m&&ze(t,["thought"],m);const f=Ze(e,["thoughtSignature"]);null!=f&&ze(t,["thoughtSignature"],f);const h=Ze(e,["videoMetadata"]);null!=h&&ze(t,["videoMetadata"],h);const g=Ze(e,["partMetadata"]);null!=g&&ze(t,["partMetadata"],g);const v=Ze(e,["mediaProcessing"]);return null!=v&&ze(t,["mediaProcessing"],v),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}function yn(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);if(null!=n&&ze(t,["mediaResolution"],n),void 0!==Ze(e,["toolCall"]))throw new Error("toolCall parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["toolResponse"]))throw new Error("toolResponse parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const o=Ze(e,["audioTranscription"]);null!=o&&ze(t,["audioTranscription"],o);const i=Ze(e,["codeExecutionResult"]);null!=i&&ze(t,["codeExecutionResult"],i);const r=Ze(e,["executableCode"]);null!=r&&ze(t,["executableCode"],r);const s=Ze(e,["fileData"]);null!=s&&ze(t,["fileData"],s);const l=Ze(e,["functionCall"]);null!=l&&ze(t,["functionCall"],l);const a=Ze(e,["functionResponse"]);null!=a&&ze(t,["functionResponse"],a);const u=Ze(e,["inlineData"]);null!=u&&ze(t,["inlineData"],u);const c=Ze(e,["text"]);null!=c&&ze(t,["text"],c);const p=Ze(e,["thought"]);null!=p&&ze(t,["thought"],p);const d=Ze(e,["thoughtSignature"]);null!=d&&ze(t,["thoughtSignature"],d);const m=Ze(e,["videoMetadata"]);if(null!=m&&ze(t,["videoMetadata"],m),void 0!==Ze(e,["partMetadata"]))throw new Error("partMetadata parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const f=Ze(e,["mediaProcessing"]);return null!=f&&ze(t,["mediaProcessing"],f),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}var An=class extends Ke{constructor(e){super(),this.apiClient=e,this.list=async(e={})=>new vn(nt.PAGED_ITEM_CACHED_CONTENTS,e=>this.listInternal(e),await this.listInternal(e),e)}async create(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["model"],kt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["ttl"]);void 0!==t&&null!=n&&ze(t,["ttl"],n);const o=Ze(e,["expireTime"]);void 0!==t&&null!=o&&ze(t,["expireTime"],o);const i=Ze(e,["displayName"]);void 0!==t&&null!=i&&ze(t,["displayName"],i);const r=Ze(e,["contents"]);if(void 0!==t&&null!=r){let e=Jt(r);Array.isArray(e)&&(e=e.map(e=>yn(e))),ze(t,["contents"],e)}const s=Ze(e,["systemInstruction"]);void 0!==t&&null!=s&&ze(t,["systemInstruction"],yn(Vt(s)));const l=Ze(e,["tools"]);if(void 0!==t&&null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["retrieval"]);null!=n&&ze(t,["retrieval"],n);const o=Ze(e,["googleMaps"]);null!=o&&ze(t,["googleMaps"],o);const i=Ze(e,["mcpServers"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>function(e){if(void 0!==Ze(e,["name"]))throw new Error("name parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["streamableHttpTransport"]))throw new Error("streamableHttpTransport parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return{}}(e))),ze(t,["mcpServers"],e)}const r=Ze(e,["codeExecution"]);null!=r&&ze(t,["codeExecution"],r);const s=Ze(e,["computerUse"]);null!=s&&ze(t,["computerUse"],function(e){const t={},n=Ze(e,["enablePromptInjectionDetection"]);null!=n&&ze(t,["enablePromptInjectionDetection"],n);const o=Ze(e,["environment"]);null!=o&&ze(t,["environment"],o);const i=Ze(e,["excludedPredefinedFunctions"]);if(null!=i&&ze(t,["excludedPredefinedFunctions"],i),void 0!==Ze(e,["disabledSafetyPolicies"]))throw new Error("disabledSafetyPolicies parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(s));const l=Ze(e,["enterpriseWebSearch"]);null!=l&&ze(t,["enterpriseWebSearch"],l);const a=Ze(e,["exaAiSearch"]);null!=a&&ze(t,["exaAiSearch"],a);const u=Ze(e,["functionDeclarations"]);if(null!=u){let e=u;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const c=Ze(e,["googleSearch"]);null!=c&&ze(t,["googleSearch"],c);const p=Ze(e,["googleSearchRetrieval"]);null!=p&&ze(t,["googleSearchRetrieval"],p);const d=Ze(e,["parallelAiSearch"]);null!=d&&ze(t,["parallelAiSearch"],d);const m=Ze(e,["urlContext"]);if(null!=m&&ze(t,["urlContext"],m),void 0!==Ze(e,["fileSearch"]))throw new Error("fileSearch parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(e))),ze(t,["tools"],e)}const a=Ze(e,["toolConfig"]);void 0!==t&&null!=a&&ze(t,["toolConfig"],function(e){const t={},n=Ze(e,["functionCallingConfig"]);null!=n&&ze(t,["functionCallingConfig"],n);const o=Ze(e,["retrievalConfig"]);if(null!=o&&ze(t,["retrievalConfig"],o),void 0!==Ze(e,["includeServerSideToolInvocations"]))throw new Error("includeServerSideToolInvocations parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(a));const u=Ze(e,["kmsKeyName"]);void 0!==t&&null!=u&&ze(t,["encryption_spec","kmsKeyName"],u)}(i,n),n}(this.apiClient,e);return s=We("cachedContents",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>e)}{const t=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["model"],kt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["ttl"]);void 0!==t&&null!=n&&ze(t,["ttl"],n);const o=Ze(e,["expireTime"]);void 0!==t&&null!=o&&ze(t,["expireTime"],o);const i=Ze(e,["displayName"]);void 0!==t&&null!=i&&ze(t,["displayName"],i);const r=Ze(e,["contents"]);if(void 0!==t&&null!=r){let e=Jt(r);Array.isArray(e)&&(e=e.map(e=>En(e))),ze(t,["contents"],e)}const s=Ze(e,["systemInstruction"]);void 0!==t&&null!=s&&ze(t,["systemInstruction"],En(Vt(s)));const l=Ze(e,["tools"]);if(void 0!==t&&null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==Ze(e,["retrieval"]))throw new Error("retrieval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["googleMaps"]);null!=n&&ze(t,["googleMaps"],function(e){const t={},n=Ze(e,["authConfig"]);null!=n&&ze(t,["authConfig"],function(e){const t={},n=Ze(e,["apiKey"]);if(null!=n&&ze(t,["apiKey"],n),void 0!==Ze(e,["apiKeyConfig"]))throw new Error("apiKeyConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["authType"]))throw new Error("authType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["googleServiceAccountConfig"]))throw new Error("googleServiceAccountConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["httpBasicAuthConfig"]))throw new Error("httpBasicAuthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oauthConfig"]))throw new Error("oauthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oidcConfig"]))throw new Error("oidcConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["enableWidget"]);if(null!=o&&ze(t,["enableWidget"],o),void 0!==Ze(e,["groundingTypes"]))throw new Error("groundingTypes parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["mcpServers"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mcpServers"],e)}const i=Ze(e,["codeExecution"]);null!=i&&ze(t,["codeExecution"],i);const r=Ze(e,["computerUse"]);if(null!=r&&ze(t,["computerUse"],r),void 0!==Ze(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["exaAiSearch"]))throw new Error("exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const s=Ze(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const l=Ze(e,["googleSearch"]);null!=l&&ze(t,["googleSearch"],function(e){const t={};if(void 0!==Ze(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["excludeDomains"]))throw new Error("excludeDomains parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["searchTypes"]);null!=n&&ze(t,["searchTypes"],n);const o=Ze(e,["timeRangeFilter"]);return null!=o&&ze(t,["timeRangeFilter"],o),t}(l));const a=Ze(e,["googleSearchRetrieval"]);if(null!=a&&ze(t,["googleSearchRetrieval"],a),void 0!==Ze(e,["parallelAiSearch"]))throw new Error("parallelAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["urlContext"]);null!=u&&ze(t,["urlContext"],u);const c=Ze(e,["fileSearch"]);return null!=c&&ze(t,["fileSearch"],c),t}(e))),ze(t,["tools"],e)}const a=Ze(e,["toolConfig"]);if(void 0!==t&&null!=a&&ze(t,["toolConfig"],function(e){const t={},n=Ze(e,["functionCallingConfig"]);null!=n&&ze(t,["functionCallingConfig"],function(e){const t={},n=Ze(e,["allowedFunctionNames"]);null!=n&&ze(t,["allowedFunctionNames"],n);const o=Ze(e,["mode"]);if(null!=o&&ze(t,["mode"],o),void 0!==Ze(e,["streamFunctionCallArguments"]))throw new Error("streamFunctionCallArguments parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["retrievalConfig"]);null!=o&&ze(t,["retrievalConfig"],o);const i=Ze(e,["includeServerSideToolInvocations"]);return null!=i&&ze(t,["includeServerSideToolInvocations"],i),t}(a)),void 0!==Ze(e,["kmsKeyName"]))throw new Error("kmsKeyName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(i,n),n}(this.apiClient,e);return s=We("cachedContents",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>e)}}async get(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],Qt(e,o)),n}(this.apiClient,e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>e)}{const t=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],Qt(e,o)),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>e)}}async delete(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],Qt(e,o)),n}(this.apiClient,e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new Et;return Object.assign(n,t),n})}{const t=function(e,t){const n={},o=Ze(t,["name"]);return null!=o&&ze(n,["_url","name"],Qt(e,o)),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"DELETE",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new Et;return Object.assign(n,t),n})}}async update(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["name"]);null!=o&&ze(n,["_url","name"],Qt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["ttl"]);void 0!==t&&null!=n&&ze(t,["ttl"],n);const o=Ze(e,["expireTime"]);void 0!==t&&null!=o&&ze(t,["expireTime"],o)}(i,n),n}(this.apiClient,e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(o),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()),r.then(e=>e)}{const t=function(e,t){const n={},o=Ze(t,["name"]);null!=o&&ze(n,["_url","name"],Qt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["ttl"]);void 0!==t&&null!=n&&ze(t,["ttl"],n);const o=Ze(e,["expireTime"]);void 0!==t&&null!=o&&ze(t,["expireTime"],o)}(i,n),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"PATCH",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>e)}}async listInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o)}(n,t),t}(e);return s=We("cachedContents",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["cachedContents"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["cachedContents"],e)}return t}(e),n=new yt;return Object.assign(n,t),n})}{const t=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o)}(n,t),t}(e);return s=We("cachedContents",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["cachedContents"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["cachedContents"],e)}return t}(e),n=new yt;return Object.assign(n,t),n})}}};function In(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n}function Tn(e){return this instanceof Tn?(this.v=e,this):new Tn(e)}function Cn(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,i=n.apply(e,t||[]),r=[];return o=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",function(e){return function(t){return Promise.resolve(t).then(e,u)}}),o[Symbol.asyncIterator]=function(){return this},o;function s(e,t){i[e]&&(o[e]=function(t){return new Promise(function(n,o){r.push([e,t,n,o])>1||l(e,t)})},t&&(o[e]=t(o[e])))}function l(e,t){try{(n=i[e](t)).value instanceof Tn?Promise.resolve(n.value.v).then(a,u):c(r[0][2],n)}catch(o){c(r[0][3],o)}var n}function a(e){l("next",e)}function u(e){l("throw",e)}function c(e,t){e(t),r.shift(),r.length&&l(r[0][0],r[0][1])}}function Sn(e){if(!Symbol.asyncIterator)throw new 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],o=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(e),t={},o("next"),o("throw"),o("return"),t[Symbol.asyncIterator]=function(){return this},t);function o(n){t[n]=e[n]&&function(t){return new Promise(function(o,i){!function(e,t,n,o){Promise.resolve(o).then(function(t){e({value:t,done:n})},t)}(o,i,(t=e[n](t)).done,t.value)})}}}function On(e){var t;if(null==e.candidates||0===e.candidates.length)return!1;const n=null===(t=e.candidates[0])||void 0===t?void 0:t.content;return void 0!==n&&bn(n)}function bn(e){if(void 0===e.parts||0===e.parts.length)return!1;for(const t of e.parts)if(void 0===t||0===Object.keys(t).length)return!1;return!0}function Pn(e){if(void 0===e||0===e.length)return[];const t=[],n=e.length;let o=0;for(;o<n;)if("user"===e[o].role)t.push(e[o]),o++;else{const i=[];let r=!0;for(;o<n&&"model"===e[o].role;)i.push(e[o]),r&&!bn(e[o])&&(r=!1),o++;r?t.push(...i):t.pop()}return t}var wn=class{constructor(e,t){this.modelsModule=e,this.apiClient=t}create(e){return new Rn(this.apiClient,this.modelsModule,e.model,e.config,structuredClone(e.history))}},Rn=class{constructor(e,t,n,o={},i=[]){this.apiClient=e,this.modelsModule=t,this.model=n,this.config=o,this.history=i,this.sendPromise=Promise.resolve(),function(e){if(0!==e.length)for(const t of e)if("user"!==t.role&&"model"!==t.role)throw new Error(`Role must be user or model, but got ${t.role}.`)}(i)}async sendMessage(e){var t;await this.sendPromise;const n=Vt(e.message),o=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,i;const r=await o,s=null===(t=null===(e=r.candidates)||void 0===e?void 0:e[0])||void 0===t?void 0:t.content,l=r.automaticFunctionCallingHistory,a=this.getHistory(!0).length;let u=[];null!=l&&(u=null!==(i=l.slice(a))&&void 0!==i?i:[]);const c=s?[s]:[];this.recordHistory(n,c,u)})(),await this.sendPromise.catch(()=>{this.sendPromise=Promise.resolve()}),o}async sendMessageStream(e){var t;await this.sendPromise;const n=Vt(e.message),o=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=o.then(()=>{}).catch(()=>{});const i=await o;return this.processStreamResponse(i,n)}getHistory(e=!1){const t=e?Pn(this.history):this.history;return structuredClone(t)}processStreamResponse(e,t){return Cn(this,arguments,function*(){var n,o,i,r,s,l;const a=[];try{for(var u,c=!0,p=Sn(e);!(n=(u=yield Tn(p.next())).done);c=!0){r=u.value,c=!1;const e=r;if(On(e)){const t=null===(l=null===(s=e.candidates)||void 0===s?void 0:s[0])||void 0===l?void 0:l.content;void 0!==t&&a.push(t)}yield yield Tn(e)}}catch(d){o={error:d}}finally{try{c||n||!(i=p.return)||(yield Tn(i.call(p)))}finally{if(o)throw o.error}}this.recordHistory(t,a)})}recordHistory(e,t,n){let o=[];t.length>0&&t.every(e=>void 0!==e.role)?o=t:o.push({role:"model",parts:[]}),n&&n.length>0?this.history.push(...Pn(n)):this.history.push(e),this.history.push(...o)}},Nn=class e extends Error{constructor(t){super(t.message),this.name="ApiError",this.status=t.status,Object.setPrototypeOf(this,e.prototype)}};var Dn=class extends Ke{constructor(e){super(),this.apiClient=e,this.list=async(e={})=>new vn(nt.PAGED_ITEM_FILES,e=>this.listInternal(e),await this.listInternal(e),e)}async upload(e){if(this.apiClient.isVertexAI())throw new Error("Gemini Enterprise Agent Platform (previously known as 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 registerFiles(e){throw new Error("registerFiles is only supported in Node.js environments.")}async _registerFiles(e){return this.registerFilesInternal(e)}async listInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o)}(n,t),t}(e);return i=We("files",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["files"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["files"],e)}return t}(e),n=new St;return Object.assign(n,t),n})}}async createInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["file"]);return null!=n&&ze(t,["file"],n),t}(e);return i=We("upload/v1beta/files",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new Ot;return Object.assign(n,t),n})}}async get(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","file"],nn(n)),t}(e);return i=We("files/{file}",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>e)}}async delete(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","file"],nn(n)),t}(e);return i=We("files/{file}",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new bt;return Object.assign(n,t),n})}}async registerFilesInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["uris"]);return null!=n&&ze(t,["uris"],n),t}(e);return i=We("files:register",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["files"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["files"],e)}return t}(e),n=new Pt;return Object.assign(n,t),n})}}};function Gn(e){const t={},n=Ze(e,["data"]);if(null!=n&&ze(t,["data"],n),void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}function kn(e,t){const n=Ze(e,["generationConfig"]);void 0!==t&&null!=n&&ze(t,["setup","generationConfig"],n);const o=Ze(e,["responseModalities"]);void 0!==t&&null!=o&&ze(t,["setup","generationConfig","responseModalities"],o);const i=Ze(e,["temperature"]);void 0!==t&&null!=i&&ze(t,["setup","generationConfig","temperature"],i);const r=Ze(e,["topP"]);void 0!==t&&null!=r&&ze(t,["setup","generationConfig","topP"],r);const s=Ze(e,["topK"]);void 0!==t&&null!=s&&ze(t,["setup","generationConfig","topK"],s);const l=Ze(e,["maxOutputTokens"]);void 0!==t&&null!=l&&ze(t,["setup","generationConfig","maxOutputTokens"],l);const a=Ze(e,["mediaResolution"]);void 0!==t&&null!=a&&ze(t,["setup","generationConfig","mediaResolution"],a);const u=Ze(e,["seed"]);void 0!==t&&null!=u&&ze(t,["setup","generationConfig","seed"],u);const c=Ze(e,["speechConfig"]);void 0!==t&&null!=c&&ze(t,["setup","generationConfig","speechConfig"],Wt(c));const p=Ze(e,["thinkingConfig"]);void 0!==t&&null!=p&&ze(t,["setup","generationConfig","thinkingConfig"],p);const d=Ze(e,["enableAffectiveDialog"]);void 0!==t&&null!=d&&ze(t,["setup","generationConfig","enableAffectiveDialog"],d);const m=Ze(e,["systemInstruction"]);void 0!==t&&null!=m&&ze(t,["setup","systemInstruction"],function(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);null!=n&&ze(t,["mediaResolution"],n);const o=Ze(e,["toolCall"]);null!=o&&ze(t,["toolCall"],o);const i=Ze(e,["toolResponse"]);null!=i&&ze(t,["toolResponse"],i);const r=Ze(e,["audioTranscription"]);null!=r&&ze(t,["audioTranscription"],r);const s=Ze(e,["codeExecutionResult"]);null!=s&&ze(t,["codeExecutionResult"],s);const l=Ze(e,["executableCode"]);null!=l&&ze(t,["executableCode"],l);const a=Ze(e,["fileData"]);null!=a&&ze(t,["fileData"],function(e){const t={};if(void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["fileUri"]);null!=n&&ze(t,["fileUri"],n);const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(a));const u=Ze(e,["functionCall"]);null!=u&&ze(t,["functionCall"],function(e){const t={},n=Ze(e,["args"]);null!=n&&ze(t,["args"],n);const o=Ze(e,["id"]);null!=o&&ze(t,["id"],o);const i=Ze(e,["name"]);if(null!=i&&ze(t,["name"],i),void 0!==Ze(e,["partialArgs"]))throw new Error("partialArgs parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["willContinue"]))throw new Error("willContinue parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(u));const c=Ze(e,["functionResponse"]);null!=c&&ze(t,["functionResponse"],c);const p=Ze(e,["inlineData"]);null!=p&&ze(t,["inlineData"],Gn(p));const d=Ze(e,["text"]);null!=d&&ze(t,["text"],d);const m=Ze(e,["thought"]);null!=m&&ze(t,["thought"],m);const f=Ze(e,["thoughtSignature"]);null!=f&&ze(t,["thoughtSignature"],f);const h=Ze(e,["videoMetadata"]);null!=h&&ze(t,["videoMetadata"],h);const g=Ze(e,["partMetadata"]);null!=g&&ze(t,["partMetadata"],g);const v=Ze(e,["mediaProcessing"]);return null!=v&&ze(t,["mediaProcessing"],v),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}(Vt(m)));const f=Ze(e,["tools"]);if(void 0!==t&&null!=f){let e=Zt(f);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==Ze(e,["retrieval"]))throw new Error("retrieval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["googleMaps"]);null!=n&&ze(t,["googleMaps"],function(e){const t={},n=Ze(e,["authConfig"]);null!=n&&ze(t,["authConfig"],function(e){const t={},n=Ze(e,["apiKey"]);if(null!=n&&ze(t,["apiKey"],n),void 0!==Ze(e,["apiKeyConfig"]))throw new Error("apiKeyConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["authType"]))throw new Error("authType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["googleServiceAccountConfig"]))throw new Error("googleServiceAccountConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["httpBasicAuthConfig"]))throw new Error("httpBasicAuthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oauthConfig"]))throw new Error("oauthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oidcConfig"]))throw new Error("oidcConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["enableWidget"]);if(null!=o&&ze(t,["enableWidget"],o),void 0!==Ze(e,["groundingTypes"]))throw new Error("groundingTypes parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["mcpServers"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mcpServers"],e)}const i=Ze(e,["codeExecution"]);null!=i&&ze(t,["codeExecution"],i);const r=Ze(e,["computerUse"]);if(null!=r&&ze(t,["computerUse"],r),void 0!==Ze(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["exaAiSearch"]))throw new Error("exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const s=Ze(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const l=Ze(e,["googleSearch"]);null!=l&&ze(t,["googleSearch"],function(e){const t={};if(void 0!==Ze(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["excludeDomains"]))throw new Error("excludeDomains parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["searchTypes"]);null!=n&&ze(t,["searchTypes"],n);const o=Ze(e,["timeRangeFilter"]);return null!=o&&ze(t,["timeRangeFilter"],o),t}(l));const a=Ze(e,["googleSearchRetrieval"]);if(null!=a&&ze(t,["googleSearchRetrieval"],a),void 0!==Ze(e,["parallelAiSearch"]))throw new Error("parallelAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["urlContext"]);null!=u&&ze(t,["urlContext"],u);const c=Ze(e,["fileSearch"]);return null!=c&&ze(t,["fileSearch"],c),t}(zt(e)))),ze(t,["setup","tools"],e)}const h=Ze(e,["sessionResumption"]);void 0!==t&&null!=h&&ze(t,["setup","sessionResumption"],function(e){const t={},n=Ze(e,["handle"]);if(null!=n&&ze(t,["handle"],n),void 0!==Ze(e,["transparent"]))throw new Error("transparent parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(h));const g=Ze(e,["inputAudioTranscription"]);void 0!==t&&null!=g&&ze(t,["setup","inputAudioTranscription"],g);const v=Ze(e,["outputAudioTranscription"]);void 0!==t&&null!=v&&ze(t,["setup","outputAudioTranscription"],v);const _=Ze(e,["realtimeInputConfig"]);void 0!==t&&null!=_&&ze(t,["setup","realtimeInputConfig"],_);const E=Ze(e,["contextWindowCompression"]);void 0!==t&&null!=E&&ze(t,["setup","contextWindowCompression"],E);const y=Ze(e,["proactivity"]);if(void 0!==t&&null!=y&&ze(t,["setup","proactivity"],y),void 0!==Ze(e,["explicitVadSignal"]))throw new Error("explicitVadSignal parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const A=Ze(e,["avatarConfig"]);void 0!==t&&null!=A&&ze(t,["setup","avatarConfig"],A);const I=Ze(e,["safetySettings"]);if(void 0!==t&&null!=I){let e=I;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["category"]);if(null!=n&&ze(t,["category"],n),void 0!==Ze(e,["method"]))throw new Error("method parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["threshold"]);return null!=o&&ze(t,["threshold"],o),t}(e))),ze(t,["setup","safetySettings"],e)}const T=Ze(e,["translationConfig"]);return void 0!==t&&null!=T&&ze(t,["setup","generationConfig","translationConfig"],T),{}}function Mn(e,t){const n=Ze(e,["generationConfig"]);void 0!==t&&null!=n&&ze(t,["setup","generationConfig"],function(e){const t={},n=Ze(e,["modelSelectionConfig"]);null!=n&&ze(t,["modelConfig"],n);const o=Ze(e,["responseJsonSchema"]);null!=o&&ze(t,["responseJsonSchema"],o);const i=Ze(e,["audioTranscriptionConfig"]);null!=i&&ze(t,["audioTranscriptionConfig"],i);const r=Ze(e,["audioTimestamp"]);null!=r&&ze(t,["audioTimestamp"],r);const s=Ze(e,["candidateCount"]);null!=s&&ze(t,["candidateCount"],s);const l=Ze(e,["enableAffectiveDialog"]);null!=l&&ze(t,["enableAffectiveDialog"],l);const a=Ze(e,["frequencyPenalty"]);null!=a&&ze(t,["frequencyPenalty"],a);const u=Ze(e,["logprobs"]);null!=u&&ze(t,["logprobs"],u);const c=Ze(e,["maxOutputTokens"]);null!=c&&ze(t,["maxOutputTokens"],c);const p=Ze(e,["mediaResolution"]);null!=p&&ze(t,["mediaResolution"],p);const d=Ze(e,["presencePenalty"]);null!=d&&ze(t,["presencePenalty"],d);const m=Ze(e,["responseFormat"]);if(null!=m){let e=m;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["responseFormat"],e)}const f=Ze(e,["responseLogprobs"]);null!=f&&ze(t,["responseLogprobs"],f);const h=Ze(e,["responseMimeType"]);null!=h&&ze(t,["responseMimeType"],h);const g=Ze(e,["responseModalities"]);null!=g&&ze(t,["responseModalities"],g);const v=Ze(e,["responseSchema"]);null!=v&&ze(t,["responseSchema"],v);const _=Ze(e,["routingConfig"]);null!=_&&ze(t,["routingConfig"],_);const E=Ze(e,["seed"]);null!=E&&ze(t,["seed"],E);const y=Ze(e,["speechConfig"]);null!=y&&ze(t,["speechConfig"],Ln(y));const A=Ze(e,["stopSequences"]);null!=A&&ze(t,["stopSequences"],A);const I=Ze(e,["temperature"]);null!=I&&ze(t,["temperature"],I);const T=Ze(e,["thinkingConfig"]);null!=T&&ze(t,["thinkingConfig"],T);const C=Ze(e,["topK"]);null!=C&&ze(t,["topK"],C);const S=Ze(e,["topP"]);if(null!=S&&ze(t,["topP"],S),void 0!==Ze(e,["enableEnhancedCivicAnswers"]))throw new Error("enableEnhancedCivicAnswers parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["translationConfig"]))throw new Error("translationConfig parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(n));const o=Ze(e,["responseModalities"]);void 0!==t&&null!=o&&ze(t,["setup","generationConfig","responseModalities"],o);const i=Ze(e,["temperature"]);void 0!==t&&null!=i&&ze(t,["setup","generationConfig","temperature"],i);const r=Ze(e,["topP"]);void 0!==t&&null!=r&&ze(t,["setup","generationConfig","topP"],r);const s=Ze(e,["topK"]);void 0!==t&&null!=s&&ze(t,["setup","generationConfig","topK"],s);const l=Ze(e,["maxOutputTokens"]);void 0!==t&&null!=l&&ze(t,["setup","generationConfig","maxOutputTokens"],l);const a=Ze(e,["mediaResolution"]);void 0!==t&&null!=a&&ze(t,["setup","generationConfig","mediaResolution"],a);const u=Ze(e,["seed"]);void 0!==t&&null!=u&&ze(t,["setup","generationConfig","seed"],u);const c=Ze(e,["speechConfig"]);void 0!==t&&null!=c&&ze(t,["setup","generationConfig","speechConfig"],Ln(Wt(c)));const p=Ze(e,["thinkingConfig"]);void 0!==t&&null!=p&&ze(t,["setup","generationConfig","thinkingConfig"],p);const d=Ze(e,["enableAffectiveDialog"]);void 0!==t&&null!=d&&ze(t,["setup","generationConfig","enableAffectiveDialog"],d);const m=Ze(e,["systemInstruction"]);void 0!==t&&null!=m&&ze(t,["setup","systemInstruction"],function(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);if(null!=n&&ze(t,["mediaResolution"],n),void 0!==Ze(e,["toolCall"]))throw new Error("toolCall parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["toolResponse"]))throw new Error("toolResponse parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const o=Ze(e,["audioTranscription"]);null!=o&&ze(t,["audioTranscription"],o);const i=Ze(e,["codeExecutionResult"]);null!=i&&ze(t,["codeExecutionResult"],i);const r=Ze(e,["executableCode"]);null!=r&&ze(t,["executableCode"],r);const s=Ze(e,["fileData"]);null!=s&&ze(t,["fileData"],s);const l=Ze(e,["functionCall"]);null!=l&&ze(t,["functionCall"],l);const a=Ze(e,["functionResponse"]);null!=a&&ze(t,["functionResponse"],a);const u=Ze(e,["inlineData"]);null!=u&&ze(t,["inlineData"],u);const c=Ze(e,["text"]);null!=c&&ze(t,["text"],c);const p=Ze(e,["thought"]);null!=p&&ze(t,["thought"],p);const d=Ze(e,["thoughtSignature"]);null!=d&&ze(t,["thoughtSignature"],d);const m=Ze(e,["videoMetadata"]);if(null!=m&&ze(t,["videoMetadata"],m),void 0!==Ze(e,["partMetadata"]))throw new Error("partMetadata parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const f=Ze(e,["mediaProcessing"]);return null!=f&&ze(t,["mediaProcessing"],f),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}(Vt(m)));const f=Ze(e,["tools"]);if(void 0!==t&&null!=f){let e=Zt(f);Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["retrieval"]);null!=n&&ze(t,["retrieval"],n);const o=Ze(e,["googleMaps"]);null!=o&&ze(t,["googleMaps"],o);const i=Ze(e,["mcpServers"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>function(e){if(void 0!==Ze(e,["name"]))throw new Error("name parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["streamableHttpTransport"]))throw new Error("streamableHttpTransport parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return{}}(e))),ze(t,["mcpServers"],e)}const r=Ze(e,["codeExecution"]);null!=r&&ze(t,["codeExecution"],r);const s=Ze(e,["computerUse"]);null!=s&&ze(t,["computerUse"],function(e){const t={},n=Ze(e,["enablePromptInjectionDetection"]);null!=n&&ze(t,["enablePromptInjectionDetection"],n);const o=Ze(e,["environment"]);null!=o&&ze(t,["environment"],o);const i=Ze(e,["excludedPredefinedFunctions"]);if(null!=i&&ze(t,["excludedPredefinedFunctions"],i),void 0!==Ze(e,["disabledSafetyPolicies"]))throw new Error("disabledSafetyPolicies parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(s));const l=Ze(e,["enterpriseWebSearch"]);null!=l&&ze(t,["enterpriseWebSearch"],l);const a=Ze(e,["exaAiSearch"]);null!=a&&ze(t,["exaAiSearch"],a);const u=Ze(e,["functionDeclarations"]);if(null!=u){let e=u;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const c=Ze(e,["googleSearch"]);null!=c&&ze(t,["googleSearch"],c);const p=Ze(e,["googleSearchRetrieval"]);null!=p&&ze(t,["googleSearchRetrieval"],p);const d=Ze(e,["parallelAiSearch"]);null!=d&&ze(t,["parallelAiSearch"],d);const m=Ze(e,["urlContext"]);if(null!=m&&ze(t,["urlContext"],m),void 0!==Ze(e,["fileSearch"]))throw new Error("fileSearch parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(zt(e)))),ze(t,["setup","tools"],e)}const h=Ze(e,["sessionResumption"]);void 0!==t&&null!=h&&ze(t,["setup","sessionResumption"],h);const g=Ze(e,["inputAudioTranscription"]);void 0!==t&&null!=g&&ze(t,["setup","inputAudioTranscription"],g);const v=Ze(e,["outputAudioTranscription"]);void 0!==t&&null!=v&&ze(t,["setup","outputAudioTranscription"],v);const _=Ze(e,["realtimeInputConfig"]);void 0!==t&&null!=_&&ze(t,["setup","realtimeInputConfig"],_);const E=Ze(e,["contextWindowCompression"]);void 0!==t&&null!=E&&ze(t,["setup","contextWindowCompression"],E);const y=Ze(e,["proactivity"]);void 0!==t&&null!=y&&ze(t,["setup","proactivity"],y);const A=Ze(e,["explicitVadSignal"]);void 0!==t&&null!=A&&ze(t,["setup","explicitVadSignal"],A);const I=Ze(e,["avatarConfig"]);void 0!==t&&null!=I&&ze(t,["setup","avatarConfig"],I);const T=Ze(e,["safetySettings"]);if(void 0!==t&&null!=T){let e=T;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["setup","safetySettings"],e)}const C=Ze(e,["translationConfig"]);return void 0!==t&&null!=C&&ze(t,["setup","generationConfig","translationConfig"],C),{}}function xn(e){const t={},n=Ze(e,["media"]);if(null!=n){let e=Mt(n);Array.isArray(e)&&(e=e.map(e=>Gn(e))),ze(t,["mediaChunks"],e)}const o=Ze(e,["audio"]);null!=o&&ze(t,["audio"],Gn(Lt(o)));const i=Ze(e,["audioStreamEnd"]);null!=i&&ze(t,["audioStreamEnd"],i);const r=Ze(e,["video"]);null!=r&&ze(t,["video"],Gn(Ut(r)));const s=Ze(e,["text"]);null!=s&&ze(t,["text"],s);const l=Ze(e,["activityStart"]);null!=l&&ze(t,["activityStart"],l);const a=Ze(e,["activityEnd"]);return null!=a&&ze(t,["activityEnd"],a),t}function Un(e){const t={},n=Ze(e,["media"]);if(null!=n){let e=Mt(n);Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mediaChunks"],e)}const o=Ze(e,["audio"]);null!=o&&ze(t,["audio"],Lt(o));const i=Ze(e,["audioStreamEnd"]);null!=i&&ze(t,["audioStreamEnd"],i);const r=Ze(e,["video"]);null!=r&&ze(t,["video"],Ut(r));const s=Ze(e,["text"]);null!=s&&ze(t,["text"],s);const l=Ze(e,["activityStart"]);null!=l&&ze(t,["activityStart"],l);const a=Ze(e,["activityEnd"]);return null!=a&&ze(t,["activityEnd"],a),t}function Ln(e){const t={},n=Ze(e,["voiceConfig"]);null!=n&&ze(t,["voiceConfig"],qn(n));const o=Ze(e,["languageCode"]);null!=o&&ze(t,["languageCode"],o);const i=Ze(e,["multiSpeakerVoiceConfig"]);return null!=i&&ze(t,["multiSpeakerVoiceConfig"],function(e){const t={},n=Ze(e,["speakerVoiceConfigs"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["speaker"]);null!=n&&ze(t,["speaker"],n);const o=Ze(e,["voiceConfig"]);return null!=o&&ze(t,["voiceConfig"],qn(o)),t}(e))),ze(t,["speakerVoiceConfigs"],e)}return t}(i)),t}function qn(e){const t={},n=Ze(e,["replicatedVoiceConfig"]);null!=n&&ze(t,["replicatedVoiceConfig"],function(e){const t={},n=Ze(e,["mimeType"]);null!=n&&ze(t,["mimeType"],n);const o=Ze(e,["voiceSampleAudio"]);if(null!=o&&ze(t,["voiceSampleAudio"],o),void 0!==Ze(e,["consentAudio"]))throw new Error("consentAudio parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["voiceConsentSignature"]))throw new Error("voiceConsentSignature parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(n));const o=Ze(e,["prebuiltVoiceConfig"]);return null!=o&&ze(t,["prebuiltVoiceConfig"],o),t}function Hn(e,t){const n={},o=Ze(e,["parts"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);null!=n&&ze(t,["mediaResolution"],n);const o=Ze(e,["toolCall"]);null!=o&&ze(t,["toolCall"],o);const i=Ze(e,["toolResponse"]);null!=i&&ze(t,["toolResponse"],i);const r=Ze(e,["audioTranscription"]);null!=r&&ze(t,["audioTranscription"],r);const s=Ze(e,["codeExecutionResult"]);null!=s&&ze(t,["codeExecutionResult"],s);const l=Ze(e,["executableCode"]);null!=l&&ze(t,["executableCode"],l);const a=Ze(e,["fileData"]);null!=a&&ze(t,["fileData"],function(e){const t={};if(void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["fileUri"]);null!=n&&ze(t,["fileUri"],n);const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(a));const u=Ze(e,["functionCall"]);null!=u&&ze(t,["functionCall"],function(e){const t={},n=Ze(e,["args"]);null!=n&&ze(t,["args"],n);const o=Ze(e,["id"]);null!=o&&ze(t,["id"],o);const i=Ze(e,["name"]);if(null!=i&&ze(t,["name"],i),void 0!==Ze(e,["partialArgs"]))throw new Error("partialArgs parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["willContinue"]))throw new Error("willContinue parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(u));const c=Ze(e,["functionResponse"]);null!=c&&ze(t,["functionResponse"],c);const p=Ze(e,["inlineData"]);null!=p&&ze(t,["inlineData"],function(e){const t={},n=Ze(e,["data"]);if(null!=n&&ze(t,["data"],n),void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(p));const d=Ze(e,["text"]);null!=d&&ze(t,["text"],d);const m=Ze(e,["thought"]);null!=m&&ze(t,["thought"],m);const f=Ze(e,["thoughtSignature"]);null!=f&&ze(t,["thoughtSignature"],f);const h=Ze(e,["videoMetadata"]);null!=h&&ze(t,["videoMetadata"],h);const g=Ze(e,["partMetadata"]);null!=g&&ze(t,["partMetadata"],g);const v=Ze(e,["mediaProcessing"]);return null!=v&&ze(t,["mediaProcessing"],v),t}(e))),ze(n,["parts"],e)}const i=Ze(e,["role"]);return null!=i&&ze(n,["role"],i),n}function Fn(e,t){const n={},o=Ze(e,["parts"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);if(null!=n&&ze(t,["mediaResolution"],n),void 0!==Ze(e,["toolCall"]))throw new Error("toolCall parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["toolResponse"]))throw new Error("toolResponse parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const o=Ze(e,["audioTranscription"]);null!=o&&ze(t,["audioTranscription"],o);const i=Ze(e,["codeExecutionResult"]);null!=i&&ze(t,["codeExecutionResult"],i);const r=Ze(e,["executableCode"]);null!=r&&ze(t,["executableCode"],r);const s=Ze(e,["fileData"]);null!=s&&ze(t,["fileData"],s);const l=Ze(e,["functionCall"]);null!=l&&ze(t,["functionCall"],l);const a=Ze(e,["functionResponse"]);null!=a&&ze(t,["functionResponse"],a);const u=Ze(e,["inlineData"]);null!=u&&ze(t,["inlineData"],u);const c=Ze(e,["text"]);null!=c&&ze(t,["text"],c);const p=Ze(e,["thought"]);null!=p&&ze(t,["thought"],p);const d=Ze(e,["thoughtSignature"]);null!=d&&ze(t,["thoughtSignature"],d);const m=Ze(e,["videoMetadata"]);if(null!=m&&ze(t,["videoMetadata"],m),void 0!==Ze(e,["partMetadata"]))throw new Error("partMetadata parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const f=Ze(e,["mediaProcessing"]);return null!=f&&ze(t,["mediaProcessing"],f),t}(e))),ze(n,["parts"],e)}const i=Ze(e,["role"]);return null!=i&&ze(n,["role"],i),n}function jn(e,t,n){const o={},i=Ze(t,["model"]);null!=i&&ze(o,["_url","model"],Gt(e,i));const r=Ze(t,["contents"]);if(null!=r){let e=Jt(r);Array.isArray(e)&&(e=e.map(e=>Hn(e))),ze(o,["contents"],e)}const s=Ze(t,["config"]);return null!=s&&ze(o,["generationConfig"],function(e,t,n){const o={},i=Ze(t,["serviceTier"]);void 0!==n&&null!=i&&ze(n,["serviceTier"],i);const r=Ze(t,["systemInstruction"]);void 0!==n&&null!=r&&ze(n,["systemInstruction"],Hn(Vt(r)));const s=Ze(t,["temperature"]);null!=s&&ze(o,["temperature"],s);const l=Ze(t,["topP"]);null!=l&&ze(o,["topP"],l);const a=Ze(t,["topK"]);null!=a&&ze(o,["topK"],a);const u=Ze(t,["candidateCount"]);null!=u&&ze(o,["candidateCount"],u);const c=Ze(t,["maxOutputTokens"]);null!=c&&ze(o,["maxOutputTokens"],c);const p=Ze(t,["stopSequences"]);null!=p&&ze(o,["stopSequences"],p);const d=Ze(t,["responseLogprobs"]);null!=d&&ze(o,["responseLogprobs"],d);const m=Ze(t,["logprobs"]);null!=m&&ze(o,["logprobs"],m);const f=Ze(t,["presencePenalty"]);null!=f&&ze(o,["presencePenalty"],f);const h=Ze(t,["frequencyPenalty"]);null!=h&&ze(o,["frequencyPenalty"],h);const g=Ze(t,["seed"]);null!=g&&ze(o,["seed"],g);const v=Ze(t,["responseMimeType"]);null!=v&&ze(o,["responseMimeType"],v);const _=Ze(t,["responseSchema"]);null!=_&&ze(o,["responseSchema"],$t(_));const E=Ze(t,["responseJsonSchema"]);if(null!=E&&ze(o,["responseJsonSchema"],E),void 0!==Ze(t,["routingConfig"]))throw new Error("routingConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(t,["modelSelectionConfig"]))throw new Error("modelSelectionConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const y=Ze(t,["safetySettings"]);if(void 0!==n&&null!=y){let e=y;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["category"]);if(null!=n&&ze(t,["category"],n),void 0!==Ze(e,["method"]))throw new Error("method parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["threshold"]);return null!=o&&ze(t,["threshold"],o),t}(e))),ze(n,["safetySettings"],e)}const A=Ze(t,["tools"]);if(void 0!==n&&null!=A){let e=Zt(A);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==Ze(e,["retrieval"]))throw new Error("retrieval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["googleMaps"]);null!=n&&ze(t,["googleMaps"],function(e){const t={},n=Ze(e,["authConfig"]);null!=n&&ze(t,["authConfig"],function(e){const t={},n=Ze(e,["apiKey"]);if(null!=n&&ze(t,["apiKey"],n),void 0!==Ze(e,["apiKeyConfig"]))throw new Error("apiKeyConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["authType"]))throw new Error("authType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["googleServiceAccountConfig"]))throw new Error("googleServiceAccountConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["httpBasicAuthConfig"]))throw new Error("httpBasicAuthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oauthConfig"]))throw new Error("oauthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oidcConfig"]))throw new Error("oidcConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["enableWidget"]);if(null!=o&&ze(t,["enableWidget"],o),void 0!==Ze(e,["groundingTypes"]))throw new Error("groundingTypes parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["mcpServers"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mcpServers"],e)}const i=Ze(e,["codeExecution"]);null!=i&&ze(t,["codeExecution"],i);const r=Ze(e,["computerUse"]);if(null!=r&&ze(t,["computerUse"],r),void 0!==Ze(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["exaAiSearch"]))throw new Error("exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const s=Ze(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const l=Ze(e,["googleSearch"]);null!=l&&ze(t,["googleSearch"],function(e){const t={};if(void 0!==Ze(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["excludeDomains"]))throw new Error("excludeDomains parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["searchTypes"]);null!=n&&ze(t,["searchTypes"],n);const o=Ze(e,["timeRangeFilter"]);return null!=o&&ze(t,["timeRangeFilter"],o),t}(l));const a=Ze(e,["googleSearchRetrieval"]);if(null!=a&&ze(t,["googleSearchRetrieval"],a),void 0!==Ze(e,["parallelAiSearch"]))throw new Error("parallelAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["urlContext"]);null!=u&&ze(t,["urlContext"],u);const c=Ze(e,["fileSearch"]);return null!=c&&ze(t,["fileSearch"],c),t}(zt(e)))),ze(n,["tools"],e)}const I=Ze(t,["toolConfig"]);if(void 0!==n&&null!=I&&ze(n,["toolConfig"],function(e){const t={},n=Ze(e,["functionCallingConfig"]);null!=n&&ze(t,["functionCallingConfig"],function(e){const t={},n=Ze(e,["allowedFunctionNames"]);null!=n&&ze(t,["allowedFunctionNames"],n);const o=Ze(e,["mode"]);if(null!=o&&ze(t,["mode"],o),void 0!==Ze(e,["streamFunctionCallArguments"]))throw new Error("streamFunctionCallArguments parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["retrievalConfig"]);null!=o&&ze(t,["retrievalConfig"],o);const i=Ze(e,["includeServerSideToolInvocations"]);return null!=i&&ze(t,["includeServerSideToolInvocations"],i),t}(I)),void 0!==Ze(t,["labels"]))throw new Error("labels parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const T=Ze(t,["cachedContent"]);void 0!==n&&null!=T&&ze(n,["cachedContent"],Qt(e,T));const C=Ze(t,["responseModalities"]);null!=C&&ze(o,["responseModalities"],C);const S=Ze(t,["mediaResolution"]);null!=S&&ze(o,["mediaResolution"],S);const O=Ze(t,["speechConfig"]);if(null!=O&&ze(o,["speechConfig"],Kt(O)),void 0!==Ze(t,["audioTimestamp"]))throw new Error("audioTimestamp parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const b=Ze(t,["thinkingConfig"]);null!=b&&ze(o,["thinkingConfig"],b);const P=Ze(t,["audioTranscriptionConfig"]);null!=P&&ze(o,["audioTranscriptionConfig"],P);const w=Ze(t,["imageConfig"]);null!=w&&ze(o,["imageConfig"],function(e){const t={},n=Ze(e,["aspectRatio"]);null!=n&&ze(t,["aspectRatio"],n);const o=Ze(e,["imageSize"]);if(null!=o&&ze(t,["imageSize"],o),void 0!==Ze(e,["personGeneration"]))throw new Error("personGeneration parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["outputMimeType"]))throw new Error("outputMimeType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["outputCompressionQuality"]))throw new Error("outputCompressionQuality parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["imageOutputOptions"]))throw new Error("imageOutputOptions parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["prominentPeople"]))throw new Error("prominentPeople parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(w));const R=Ze(t,["enableEnhancedCivicAnswers"]);if(null!=R&&ze(o,["enableEnhancedCivicAnswers"],R),void 0!==Ze(t,["modelArmorConfig"]))throw new Error("modelArmorConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return o}(e,s,o)),o}function Bn(e,t,n){const o={},i=Ze(t,["model"]);null!=i&&ze(o,["_url","model"],Gt(e,i));const r=Ze(t,["contents"]);if(null!=r){let e=Jt(r);Array.isArray(e)&&(e=e.map(e=>Fn(e))),ze(o,["contents"],e)}const s=Ze(t,["config"]);return null!=s&&ze(o,["generationConfig"],function(e,t,n){const o={},i=Ze(t,["serviceTier"]);void 0!==n&&null!=i&&ze(n,["serviceTier"],i);const r=Ze(t,["systemInstruction"]);void 0!==n&&null!=r&&ze(n,["systemInstruction"],Fn(Vt(r)));const s=Ze(t,["temperature"]);null!=s&&ze(o,["temperature"],s);const l=Ze(t,["topP"]);null!=l&&ze(o,["topP"],l);const a=Ze(t,["topK"]);null!=a&&ze(o,["topK"],a);const u=Ze(t,["candidateCount"]);null!=u&&ze(o,["candidateCount"],u);const c=Ze(t,["maxOutputTokens"]);null!=c&&ze(o,["maxOutputTokens"],c);const p=Ze(t,["stopSequences"]);null!=p&&ze(o,["stopSequences"],p);const d=Ze(t,["responseLogprobs"]);null!=d&&ze(o,["responseLogprobs"],d);const m=Ze(t,["logprobs"]);null!=m&&ze(o,["logprobs"],m);const f=Ze(t,["presencePenalty"]);null!=f&&ze(o,["presencePenalty"],f);const h=Ze(t,["frequencyPenalty"]);null!=h&&ze(o,["frequencyPenalty"],h);const g=Ze(t,["seed"]);null!=g&&ze(o,["seed"],g);const v=Ze(t,["responseMimeType"]);null!=v&&ze(o,["responseMimeType"],v);const _=Ze(t,["responseSchema"]);null!=_&&ze(o,["responseSchema"],$t(_));const E=Ze(t,["responseJsonSchema"]);null!=E&&ze(o,["responseJsonSchema"],E);const y=Ze(t,["routingConfig"]);null!=y&&ze(o,["routingConfig"],y);const A=Ze(t,["modelSelectionConfig"]);null!=A&&ze(o,["modelConfig"],A);const I=Ze(t,["safetySettings"]);if(void 0!==n&&null!=I){let e=I;Array.isArray(e)&&(e=e.map(e=>e)),ze(n,["safetySettings"],e)}const T=Ze(t,["tools"]);if(void 0!==n&&null!=T){let e=Zt(T);Array.isArray(e)&&(e=e.map(e=>no(zt(e)))),ze(n,["tools"],e)}const C=Ze(t,["toolConfig"]);void 0!==n&&null!=C&&ze(n,["toolConfig"],function(e){const t={},n=Ze(e,["functionCallingConfig"]);null!=n&&ze(t,["functionCallingConfig"],n);const o=Ze(e,["retrievalConfig"]);if(null!=o&&ze(t,["retrievalConfig"],o),void 0!==Ze(e,["includeServerSideToolInvocations"]))throw new Error("includeServerSideToolInvocations parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(C));const S=Ze(t,["labels"]);void 0!==n&&null!=S&&ze(n,["labels"],S);const O=Ze(t,["cachedContent"]);void 0!==n&&null!=O&&ze(n,["cachedContent"],Qt(e,O));const b=Ze(t,["responseModalities"]);null!=b&&ze(o,["responseModalities"],b);const P=Ze(t,["mediaResolution"]);null!=P&&ze(o,["mediaResolution"],P);const w=Ze(t,["speechConfig"]);null!=w&&ze(o,["speechConfig"],to(Kt(w)));const R=Ze(t,["audioTimestamp"]);null!=R&&ze(o,["audioTimestamp"],R);const N=Ze(t,["thinkingConfig"]);null!=N&&ze(o,["thinkingConfig"],N);const D=Ze(t,["audioTranscriptionConfig"]);null!=D&&ze(o,["audioTranscriptionConfig"],D);const G=Ze(t,["imageConfig"]);if(null!=G&&ze(o,["imageConfig"],function(e){const t={},n=Ze(e,["aspectRatio"]);null!=n&&ze(t,["aspectRatio"],n);const o=Ze(e,["imageSize"]);null!=o&&ze(t,["imageSize"],o);const i=Ze(e,["personGeneration"]);null!=i&&ze(t,["personGeneration"],i);const r=Ze(e,["outputMimeType"]);null!=r&&ze(t,["imageOutputOptions","mimeType"],r);const s=Ze(e,["outputCompressionQuality"]);null!=s&&ze(t,["imageOutputOptions","compressionQuality"],s);const l=Ze(e,["imageOutputOptions"]);null!=l&&ze(t,["imageOutputOptions"],l);const a=Ze(e,["prominentPeople"]);return null!=a&&ze(t,["prominentPeople"],a),t}(G)),void 0!==Ze(t,["enableEnhancedCivicAnswers"]))throw new Error("enableEnhancedCivicAnswers parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const k=Ze(t,["modelArmorConfig"]);return void 0!==n&&null!=k&&ze(n,["modelArmorConfig"],k),o}(e,s,o)),o}function Vn(e,t){const n={},o=Ze(e,["sdkHttpResponse"]);null!=o&&ze(n,["sdkHttpResponse"],o);const i=Ze(e,["candidates"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["content"]);null!=n&&ze(t,["content"],n);const o=Ze(e,["citationMetadata"]);null!=o&&ze(t,["citationMetadata"],function(e){const t={},n=Ze(e,["citationSources"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["citations"],e)}return t}(o));const i=Ze(e,["tokenCount"]);null!=i&&ze(t,["tokenCount"],i);const r=Ze(e,["finishReason"]);null!=r&&ze(t,["finishReason"],r);const s=Ze(e,["groundingMetadata"]);null!=s&&ze(t,["groundingMetadata"],s);const l=Ze(e,["avgLogprobs"]);null!=l&&ze(t,["avgLogprobs"],l);const a=Ze(e,["index"]);null!=a&&ze(t,["index"],a);const u=Ze(e,["logprobsResult"]);null!=u&&ze(t,["logprobsResult"],u);const c=Ze(e,["safetyRatings"]);if(null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["safetyRatings"],e)}const p=Ze(e,["urlContextMetadata"]);return null!=p&&ze(t,["urlContextMetadata"],p),t}(e))),ze(n,["candidates"],e)}const r=Ze(e,["modelVersion"]);null!=r&&ze(n,["modelVersion"],r);const s=Ze(e,["promptFeedback"]);null!=s&&ze(n,["promptFeedback"],s);const l=Ze(e,["responseId"]);null!=l&&ze(n,["responseId"],l);const a=Ze(e,["usageMetadata"]);null!=a&&ze(n,["usageMetadata"],a);const u=Ze(e,["modelStatus"]);return null!=u&&ze(n,["modelStatus"],u),n}function Xn(e,t){const n={},o=Ze(e,["sdkHttpResponse"]);null!=o&&ze(n,["sdkHttpResponse"],o);const i=Ze(e,["candidates"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(n,["candidates"],e)}const r=Ze(e,["createTime"]);null!=r&&ze(n,["createTime"],r);const s=Ze(e,["modelVersion"]);null!=s&&ze(n,["modelVersion"],s);const l=Ze(e,["promptFeedback"]);null!=l&&ze(n,["promptFeedback"],l);const a=Ze(e,["responseId"]);null!=a&&ze(n,["responseId"],a);const u=Ze(e,["usageMetadata"]);return null!=u&&ze(n,["usageMetadata"],u),n}function Jn(e,t,n){const o={},i=Ze(t,["model"]);null!=i&&ze(o,["_url","model"],Gt(e,i));const r=Ze(t,["prompt"]);null!=r&&ze(o,["instances[0]","prompt"],r);const s=Ze(t,["image"]);null!=s&&ze(o,["instances[0]","image"],Wn(s));const l=Ze(t,["video"]);null!=l&&ze(o,["instances[0]","video"],oo(l));const a=Ze(t,["source"]);null!=a&&function(e,t){const n=Ze(e,["prompt"]);void 0!==t&&null!=n&&ze(t,["instances[0]","prompt"],n);const o=Ze(e,["image"]);void 0!==t&&null!=o&&ze(t,["instances[0]","image"],Wn(o));const i=Ze(e,["video"]);void 0!==t&&null!=i&&ze(t,["instances[0]","video"],oo(i))}(a,o);const u=Ze(t,["config"]);return null!=u&&function(e,t){const n=Ze(e,["numberOfVideos"]);if(void 0!==t&&null!=n&&ze(t,["parameters","sampleCount"],n),void 0!==Ze(e,["outputGcsUri"]))throw new Error("outputGcsUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["fps"]))throw new Error("fps parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["durationSeconds"]);if(void 0!==t&&null!=o&&ze(t,["parameters","durationSeconds"],o),void 0!==Ze(e,["seed"]))throw new Error("seed parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const i=Ze(e,["aspectRatio"]);void 0!==t&&null!=i&&ze(t,["parameters","aspectRatio"],i);const r=Ze(e,["resolution"]);void 0!==t&&null!=r&&ze(t,["parameters","resolution"],r);const s=Ze(e,["personGeneration"]);if(void 0!==t&&null!=s&&ze(t,["parameters","personGeneration"],s),void 0!==Ze(e,["pubsubTopic"]))throw new Error("pubsubTopic parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const l=Ze(e,["negativePrompt"]);void 0!==t&&null!=l&&ze(t,["parameters","negativePrompt"],l);const a=Ze(e,["enhancePrompt"]);if(void 0!==t&&null!=a&&ze(t,["parameters","enhancePrompt"],a),void 0!==Ze(e,["generateAudio"]))throw new Error("generateAudio parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["lastFrame"]);void 0!==t&&null!=u&&ze(t,["instances[0]","lastFrame"],Wn(u));const c=Ze(e,["referenceImages"]);if(void 0!==t&&null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["image"]);null!=n&&ze(t,["image"],Wn(n));const o=Ze(e,["referenceType"]);return null!=o&&ze(t,["referenceType"],o),t}(e))),ze(t,["instances[0]","referenceImages"],e)}if(void 0!==Ze(e,["mask"]))throw new Error("mask parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["compressionQuality"]))throw new Error("compressionQuality parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["labels"]))throw new Error("labels parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const p=Ze(e,["webhookConfig"]);if(void 0!==t&&null!=p&&ze(t,["webhookConfig"],p),void 0!==Ze(e,["resizeMode"]))throw new Error("resizeMode parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(u,o),o}function Yn(e,t,n){const o={},i=Ze(t,["model"]);null!=i&&ze(o,["_url","model"],Gt(e,i));const r=Ze(t,["prompt"]);null!=r&&ze(o,["instances[0]","prompt"],r);const s=Ze(t,["image"]);null!=s&&ze(o,["instances[0]","image"],zn(s));const l=Ze(t,["video"]);null!=l&&ze(o,["instances[0]","video"],io(l));const a=Ze(t,["source"]);null!=a&&function(e,t){const n=Ze(e,["prompt"]);void 0!==t&&null!=n&&ze(t,["instances[0]","prompt"],n);const o=Ze(e,["image"]);void 0!==t&&null!=o&&ze(t,["instances[0]","image"],zn(o));const i=Ze(e,["video"]);void 0!==t&&null!=i&&ze(t,["instances[0]","video"],io(i))}(a,o);const u=Ze(t,["config"]);return null!=u&&function(e,t){const n=Ze(e,["numberOfVideos"]);void 0!==t&&null!=n&&ze(t,["parameters","sampleCount"],n);const o=Ze(e,["outputGcsUri"]);void 0!==t&&null!=o&&ze(t,["parameters","storageUri"],o);const i=Ze(e,["fps"]);void 0!==t&&null!=i&&ze(t,["parameters","fps"],i);const r=Ze(e,["durationSeconds"]);void 0!==t&&null!=r&&ze(t,["parameters","durationSeconds"],r);const s=Ze(e,["seed"]);void 0!==t&&null!=s&&ze(t,["parameters","seed"],s);const l=Ze(e,["aspectRatio"]);void 0!==t&&null!=l&&ze(t,["parameters","aspectRatio"],l);const a=Ze(e,["resolution"]);void 0!==t&&null!=a&&ze(t,["parameters","resolution"],a);const u=Ze(e,["personGeneration"]);void 0!==t&&null!=u&&ze(t,["parameters","personGeneration"],u);const c=Ze(e,["pubsubTopic"]);void 0!==t&&null!=c&&ze(t,["parameters","pubsubTopic"],c);const p=Ze(e,["negativePrompt"]);void 0!==t&&null!=p&&ze(t,["parameters","negativePrompt"],p);const d=Ze(e,["enhancePrompt"]);void 0!==t&&null!=d&&ze(t,["parameters","enhancePrompt"],d);const m=Ze(e,["generateAudio"]);void 0!==t&&null!=m&&ze(t,["parameters","generateAudio"],m);const f=Ze(e,["lastFrame"]);void 0!==t&&null!=f&&ze(t,["instances[0]","lastFrame"],zn(f));const h=Ze(e,["referenceImages"]);if(void 0!==t&&null!=h){let e=h;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["image"]);null!=n&&ze(t,["image"],zn(n));const o=Ze(e,["referenceType"]);return null!=o&&ze(t,["referenceType"],o),t}(e))),ze(t,["instances[0]","referenceImages"],e)}const g=Ze(e,["mask"]);void 0!==t&&null!=g&&ze(t,["instances[0]","mask"],function(e){const t={},n=Ze(e,["image"]);null!=n&&ze(t,["_self"],zn(n));const o=Ze(e,["maskMode"]);return null!=o&&ze(t,["maskMode"],o),t}(g));const v=Ze(e,["compressionQuality"]);void 0!==t&&null!=v&&ze(t,["parameters","compressionQuality"],v);const _=Ze(e,["labels"]);if(void 0!==t&&null!=_&&ze(t,["labels"],_),void 0!==Ze(e,["webhookConfig"]))throw new Error("webhookConfig parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const E=Ze(e,["resizeMode"]);void 0!==t&&null!=E&&ze(t,["parameters","resizeMode"],E)}(u,o),o}function $n(e,t){const n={},o=Ze(e,["_self"]);null!=o&&ze(n,["image"],Kn(o));const i=Ze(e,["raiFilteredReason"]);null!=i&&ze(n,["raiFilteredReason"],i);const r=Ze(e,["_self"]);null!=r&&ze(n,["safetyAttributes"],eo(r));const s=Ze(e,["prompt"]);return null!=s&&ze(n,["enhancedPrompt"],s),n}function Kn(e,t){const n={},o=Ze(e,["gcsUri"]);null!=o&&ze(n,["gcsUri"],o);const i=Ze(e,["bytesBase64Encoded"]);null!=i&&ze(n,["imageBytes"],tn(i));const r=Ze(e,["mimeType"]);return null!=r&&ze(n,["mimeType"],r),n}function Wn(e,t){const n={};if(void 0!==Ze(e,["gcsUri"]))throw new Error("gcsUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["imageBytes"]);null!=o&&ze(n,["bytesBase64Encoded"],tn(o));const i=Ze(e,["mimeType"]);return null!=i&&ze(n,["mimeType"],i),n}function zn(e,t){const n={},o=Ze(e,["gcsUri"]);null!=o&&ze(n,["gcsUri"],o);const i=Ze(e,["imageBytes"]);null!=i&&ze(n,["bytesBase64Encoded"],tn(i));const r=Ze(e,["mimeType"]);return null!=r&&ze(n,["mimeType"],r),n}function Zn(e,t){const n={},o=Ze(e,["name"]);null!=o&&ze(n,["name"],o);const i=Ze(e,["displayName"]);null!=i&&ze(n,["displayName"],i);const r=Ze(e,["description"]);null!=r&&ze(n,["description"],r);const s=Ze(e,["version"]);null!=s&&ze(n,["version"],s);const l=Ze(e,["_self"]);null!=l&&ze(n,["tunedModelInfo"],function(e){const t={},n=Ze(e,["baseModel"]);null!=n&&ze(t,["baseModel"],n);const o=Ze(e,["createTime"]);null!=o&&ze(t,["createTime"],o);const i=Ze(e,["updateTime"]);return null!=i&&ze(t,["updateTime"],i),t}(l));const a=Ze(e,["inputTokenLimit"]);null!=a&&ze(n,["inputTokenLimit"],a);const u=Ze(e,["outputTokenLimit"]);null!=u&&ze(n,["outputTokenLimit"],u);const c=Ze(e,["supportedGenerationMethods"]);null!=c&&ze(n,["supportedActions"],c);const p=Ze(e,["temperature"]);null!=p&&ze(n,["temperature"],p);const d=Ze(e,["maxTemperature"]);null!=d&&ze(n,["maxTemperature"],d);const m=Ze(e,["topP"]);null!=m&&ze(n,["topP"],m);const f=Ze(e,["topK"]);null!=f&&ze(n,["topK"],f);const h=Ze(e,["thinking"]);return null!=h&&ze(n,["thinking"],h),n}function Qn(e,t){const n={},o=Ze(e,["name"]);null!=o&&ze(n,["name"],o);const i=Ze(e,["displayName"]);null!=i&&ze(n,["displayName"],i);const r=Ze(e,["description"]);null!=r&&ze(n,["description"],r);const s=Ze(e,["versionId"]);null!=s&&ze(n,["version"],s);const l=Ze(e,["deployedModels"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["endpoint"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["deployedModelId"]);return null!=o&&ze(t,["deployedModelId"],o),t}(e))),ze(n,["endpoints"],e)}const a=Ze(e,["labels"]);null!=a&&ze(n,["labels"],a);const u=Ze(e,["_self"]);null!=u&&ze(n,["tunedModelInfo"],function(e){const t={},n=Ze(e,["labels","google-vertex-llm-tuning-base-model-id"]);null!=n&&ze(t,["baseModel"],n);const o=Ze(e,["createTime"]);null!=o&&ze(t,["createTime"],o);const i=Ze(e,["updateTime"]);return null!=i&&ze(t,["updateTime"],i),t}(u));const c=Ze(e,["defaultCheckpointId"]);null!=c&&ze(n,["defaultCheckpointId"],c);const p=Ze(e,["checkpoints"]);if(null!=p){let e=p;Array.isArray(e)&&(e=e.map(e=>e)),ze(n,["checkpoints"],e)}return n}function eo(e,t){const n={},o=Ze(e,["safetyAttributes","categories"]);null!=o&&ze(n,["categories"],o);const i=Ze(e,["safetyAttributes","scores"]);null!=i&&ze(n,["scores"],i);const r=Ze(e,["contentType"]);return null!=r&&ze(n,["contentType"],r),n}function to(e,t){const n={},o=Ze(e,["voiceConfig"]);null!=o&&ze(n,["voiceConfig"],ro(o));const i=Ze(e,["languageCode"]);null!=i&&ze(n,["languageCode"],i);const r=Ze(e,["multiSpeakerVoiceConfig"]);return null!=r&&ze(n,["multiSpeakerVoiceConfig"],function(e){const t={},n=Ze(e,["speakerVoiceConfigs"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["speaker"]);null!=n&&ze(t,["speaker"],n);const o=Ze(e,["voiceConfig"]);return null!=o&&ze(t,["voiceConfig"],ro(o)),t}(e))),ze(t,["speakerVoiceConfigs"],e)}return t}(r)),n}function no(e,t){const n={},o=Ze(e,["retrieval"]);null!=o&&ze(n,["retrieval"],o);const i=Ze(e,["googleMaps"]);null!=i&&ze(n,["googleMaps"],i);const r=Ze(e,["mcpServers"]);if(null!=r){let e=r;Array.isArray(e)&&(e=e.map(e=>function(e){if(void 0!==Ze(e,["name"]))throw new Error("name parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["streamableHttpTransport"]))throw new Error("streamableHttpTransport parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return{}}(e))),ze(n,["mcpServers"],e)}const s=Ze(e,["codeExecution"]);null!=s&&ze(n,["codeExecution"],s);const l=Ze(e,["computerUse"]);null!=l&&ze(n,["computerUse"],function(e){const t={},n=Ze(e,["enablePromptInjectionDetection"]);null!=n&&ze(t,["enablePromptInjectionDetection"],n);const o=Ze(e,["environment"]);null!=o&&ze(t,["environment"],o);const i=Ze(e,["excludedPredefinedFunctions"]);if(null!=i&&ze(t,["excludedPredefinedFunctions"],i),void 0!==Ze(e,["disabledSafetyPolicies"]))throw new Error("disabledSafetyPolicies parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(l));const a=Ze(e,["enterpriseWebSearch"]);null!=a&&ze(n,["enterpriseWebSearch"],a);const u=Ze(e,["exaAiSearch"]);null!=u&&ze(n,["exaAiSearch"],u);const c=Ze(e,["functionDeclarations"]);if(null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>e)),ze(n,["functionDeclarations"],e)}const p=Ze(e,["googleSearch"]);null!=p&&ze(n,["googleSearch"],p);const d=Ze(e,["googleSearchRetrieval"]);null!=d&&ze(n,["googleSearchRetrieval"],d);const m=Ze(e,["parallelAiSearch"]);null!=m&&ze(n,["parallelAiSearch"],m);const f=Ze(e,["urlContext"]);if(null!=f&&ze(n,["urlContext"],f),void 0!==Ze(e,["fileSearch"]))throw new Error("fileSearch parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return n}function oo(e,t){const n={},o=Ze(e,["uri"]);null!=o&&ze(n,["uri"],o);const i=Ze(e,["videoBytes"]);null!=i&&ze(n,["encodedVideo"],tn(i));const r=Ze(e,["mimeType"]);return null!=r&&ze(n,["encoding"],r),n}function io(e,t){const n={},o=Ze(e,["uri"]);null!=o&&ze(n,["gcsUri"],o);const i=Ze(e,["videoBytes"]);null!=i&&ze(n,["bytesBase64Encoded"],tn(i));const r=Ze(e,["mimeType"]);return null!=r&&ze(n,["mimeType"],r),n}function ro(e,t){const n={},o=Ze(e,["replicatedVoiceConfig"]);null!=o&&ze(n,["replicatedVoiceConfig"],function(e){const t={},n=Ze(e,["mimeType"]);null!=n&&ze(t,["mimeType"],n);const o=Ze(e,["voiceSampleAudio"]);if(null!=o&&ze(t,["voiceSampleAudio"],o),void 0!==Ze(e,["consentAudio"]))throw new Error("consentAudio parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["voiceConsentSignature"]))throw new Error("voiceConsentSignature parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(o));const i=Ze(e,["prebuiltVoiceConfig"]);return null!=i&&ze(n,["prebuiltVoiceConfig"],i),n}function so(e,t){const n=Ze(e,["mimeType"]);void 0!==t&&null!=n&&ze(t,["mimeType"],n);const o=Ze(e,["displayName"]);void 0!==t&&null!=o&&ze(t,["displayName"],o);const i=Ze(e,["customMetadata"]);if(void 0!==t&&null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["customMetadata"],e)}const r=Ze(e,["chunkingConfig"]);return void 0!==t&&null!=r&&ze(t,["chunkingConfig"],r),{}}var lo="x-goog-api-client",ao=/* @__PURE__ */new Set(["us","eu"]),uo=[408,429,500,502,503,504],co=class{constructor(e){var t,n,o;this.clientOptions=Object.assign({},e),this.customBaseUrl=null===(t=e.httpOptions)||void 0===t?void 0:t.baseUrl;const i={};if(this.clientOptions.vertexai){if(this.clientOptions.location||this.clientOptions.apiKey||this.customBaseUrl||(this.clientOptions.location="global"),!(this.clientOptions.project&&this.clientOptions.location||this.clientOptions.apiKey||this.customBaseUrl))throw new Error("Authentication is not set up. Please provide either a project and location, or an API key, or a custom base URL.");const t=e.project&&e.location||!!e.apiKey;this.customBaseUrl&&!t?(i.baseUrl=this.customBaseUrl,this.clientOptions.project=void 0,this.clientOptions.location=void 0):this.clientOptions.apiKey&&!this.clientOptions.project||"global"===this.clientOptions.location?i.baseUrl="https://aiplatform.googleapis.com/":this.clientOptions.project&&this.clientOptions.location&&ao.has(this.clientOptions.location)?i.baseUrl=`https://aiplatform.${this.clientOptions.location}.rep.googleapis.com/`:this.clientOptions.project&&this.clientOptions.location&&(i.baseUrl=`https://${this.clientOptions.location}-aiplatform.googleapis.com/`),i.apiVersion=null!==(n=this.clientOptions.apiVersion)&&void 0!==n?n:"v1beta1"}else this.clientOptions.apiKey,i.apiVersion=null!==(o=this.clientOptions.apiVersion)&&void 0!==o?o:"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))}isVertexAI(){var e;return null!==(e=this.clientOptions.vertexai)&&void 0!==e&&e}getProject(){return this.clientOptions.project}getLocation(){return this.clientOptions.location}getCustomBaseUrl(){return this.customBaseUrl}async getAuthHeaders(){const e=new Headers;return await this.clientOptions.auth.addAuthHeaders(e),e}getApiVersion(){if(this.clientOptions.httpOptions&&void 0!==this.clientOptions.httpOptions.apiVersion)return this.clientOptions.httpOptions.apiVersion;throw new Error("API version is not set.")}getBaseUrl(){if(this.clientOptions.httpOptions&&void 0!==this.clientOptions.httpOptions.baseUrl)return this.clientOptions.httpOptions.baseUrl;throw new 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 new Error("Headers are not set.")}getRequestUrlInternal(e){if(!e||void 0===e.baseUrl||void 0===e.apiVersion)throw new Error("HTTP options are not correctly set.");const 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(){const e=this.getBaseUrl(),t=new URL(e);return t.protocol="http:"==t.protocol?"ws":"wss",t.toString()}setBaseUrl(e){if(!this.clientOptions.httpOptions)throw new Error("HTTP options are not correctly set.");this.clientOptions.httpOptions.baseUrl=e}constructUrl(e,t,n){const o=[this.getRequestUrlInternal(t)];return n&&o.push(this.getBaseResourcePath()),""!==e&&o.push(e),new URL(`${o.join("/")}`)}shouldPrependVertexProjectPath(e,t){return!(t.baseUrl&&t.baseUrlResourceScope===he.COLLECTION||!this.clientOptions.vertexai||!this.clientOptions.project||!this.clientOptions.location||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));const n=this.shouldPrependVertexProjectPath(e,t),o=this.constructUrl(e.path,t,n);if(e.queryParams)for(const[r,s]of Object.entries(e.queryParams))o.searchParams.append(r,String(s));let i={};if("GET"===e.httpMethod){if(e.body&&"{}"!==e.body)throw new Error("Request body should be empty for GET request, but got non empty request body")}else i.body=e.body;return i=await this.includeExtraHttpOptionsToRequestInit(i,t,o.toString()),this.unaryApiCall(o,i,e.httpMethod,t.retryOptions,t.timeout,e.abortSignal)}patchHttpOptions(e,t){const n=JSON.parse(JSON.stringify(e));for(const[o,i]of Object.entries(t))"object"==typeof i?n[o]=Object.assign(Object.assign({},n[o]),i):void 0!==i&&(n[o]=i);return n}async requestStream(e){let t=this.clientOptions.httpOptions;e.httpOptions&&(t=this.patchHttpOptions(this.clientOptions.httpOptions,e.httpOptions));const n=this.shouldPrependVertexProjectPath(e,t),o=this.constructUrl(e.path,t,n);o.searchParams.has("alt")&&"sse"===o.searchParams.get("alt")||o.searchParams.set("alt","sse");let i={};return i.body=e.body,i=await this.includeExtraHttpOptionsToRequestInit(i,t,o.toString()),this.streamApiCall(o,i,e.httpMethod,t.retryOptions,t.timeout,e.abortSignal)}async includeExtraHttpOptionsToRequestInit(e,t,n){return(null==t?void 0:t.timeout)&&t.timeout>0&&function(e){const t=globalThis[Symbol.for("undici.globalDispatcher.1")];if(t)for(const n of Object.getOwnPropertySymbols(t)){const o=n.description;if((null==o?void 0:o.includes("headers timeout"))||(null==o?void 0:o.includes("body timeout"))){const o=t[n];"number"==typeof o&&(t[n]=Math.max(o,e))}}}(t.timeout),t&&null!==t.extraBody&&function(e,t){if(!t||0===Object.keys(t).length)return;if(e.body instanceof Blob)return;let n={};if("string"==typeof e.body&&e.body.length>0)try{const t=JSON.parse(e.body);if("object"!=typeof t||null===t||Array.isArray(t))return;n=t}catch(i){return}const o=function e(t,n){const o=Object.assign({},t);for(const i in n)if(Object.prototype.hasOwnProperty.call(n,i)){const t=n[i],r=o[i];t&&"object"==typeof t&&!Array.isArray(t)&&r&&"object"==typeof r&&!Array.isArray(r)?o[i]=e(r,t):o[i]=t}return o}(n,t);e.body=JSON.stringify(o)}(e,t.extraBody),e.headers=await this.getHeadersInternal(t,n),e}async unaryApiCall(e,t,n,o,i,r){return this.apiCall(e.toString(),Object.assign(Object.assign({},t),{method:n}),o,i,r).then(async e=>(await po(e),new ot(e))).catch(e=>{throw e instanceof Error?e:new Error(`exception ${e} sending request`,{cause:e})})}async streamApiCall(e,t,n,o,i,r){return this.apiCall(e.toString(),Object.assign(Object.assign({},t),{method:n}),o,i,r).then(async e=>(await po(e),this.processStreamResponse(e))).catch(e=>{throw e instanceof Error?e:new Error(`exception ${e} sending request`,{cause:e})})}processStreamResponse(e){return Cn(this,arguments,function*(){var t;const n=null===(t=null==e?void 0:e.body)||void 0===t?void 0:t.getReader(),o=new TextDecoder("utf-8");if(!n)throw new Error("Response body is empty");try{let t="";const r="data:",s=["\n\n","\r\r","\r\n\r\n"];for(;;){const{done:l,value:a}=yield Tn(n.read());if(l){if(t.trim().length>0)throw new Error("Incomplete JSON segment at the end");break}const u=o.decode(a,{stream:!0});try{const e=JSON.parse(u);if("error"in e){const t=JSON.parse(JSON.stringify(e.error)),n=t.status,o=t.code,i=`got status: ${n}. ${JSON.stringify(e)}`;if(o>=400&&o<600)throw new Nn({message:i,status:o})}}catch(i){if("ApiError"===i.name)throw i}t+=u;let c=-1,p=0;for(;;){c=-1,p=0;for(const e of s){const n=t.indexOf(e);-1!==n&&(-1===c||n<c)&&(c=n,p=e.length)}if(-1===c)break;const n=t.substring(0,c);t=t.substring(c+p);const o=n.trim();if(o.startsWith(r)){const t=o.substring(5).trim();try{const n=new Response(t,{headers:null==e?void 0:e.headers,status:null==e?void 0:e.status,statusText:null==e?void 0:e.statusText});yield yield Tn(new ot(n))}catch(i){throw new Error(`exception parsing stream chunk ${t}. ${i}`)}}}}}finally{n.releaseLock()}})}async apiCall(e,t,n,o,i){var r,s,l,a,u,c;const p=null!==(r=null==n?void 0:n.httpStatusCodes)&&void 0!==r?r:uo,d=async()=>{const r=function(e,t){if(!(e&&e>0||t))return{signal:void 0,dispose:()=>{}};const n=new AbortController;let o;e&&e>0&&(o=setTimeout(()=>n.abort(),e),o&&"function"==typeof o.unref&&o.unref());const i=()=>n.abort();return t&&(t.aborted?n.abort():t.addEventListener("abort",i)),{signal:n.signal,dispose:()=>{void 0!==o&&clearTimeout(o),null==t||t.removeEventListener("abort",i)}}}(o,i);let s;try{s=await fetch(e,Object.assign(Object.assign({},t),{signal:r.signal}))}catch(l){throw r.dispose(),l}if(!n||s.ok||!p.includes(s.status))return s;try{await po(s)}finally{r.dispose()}return s};if(!n)return d();const m=Math.max(1,null!==(s=n.attempts)&&void 0!==s?s:5),f=Math.round(1e3*(null!==(l=n.initialDelay)&&void 0!==l?l:1)),h=Math.max(f,Math.round(1e3*(null!==(a=n.maxDelay)&&void 0!==a?a:60)));return(0,$e.default)(d,{retries:m-1,factor:null!==(u=n.expBase)&&void 0!==u?u:2,minTimeout:f,maxTimeout:h,randomize:(null!==(c=n.jitter)&&void 0!==c?c:1)>0,onFailedAttempt:e=>{var t;if(null==i?void 0:i.aborted)throw null!==(t=e.error)&&void 0!==t?t:e}})}getDefaultHeaders(){const e={},t="google-genai-sdk/2.21.0 "+this.clientOptions.userAgentExtra;return e["User-Agent"]=t,e[lo]=t,e["Content-Type"]="application/json",e}async getHeadersInternal(e,t){const n=new Headers;if(e&&e.headers)for(const[o,i]of Object.entries(e.headers))n.append(o,i);return(null==e?void 0:e.timeout)&&e.timeout>0&&n.append("X-Server-Timeout",String(Math.ceil(e.timeout/1e3))),await this.clientOptions.auth.addAuthHeaders(n,t),n}getFileName(e){var t;let n="";return"string"==typeof e&&(n=e.replace(/[/\\]+$/,""),n=null!==(t=n.split(/[/\\]/).pop())&&void 0!==t?t:""),n}async uploadFile(e,t){var n;const o={};null!=t&&(o.mimeType=t.mimeType,o.name=t.name,o.displayName=t.displayName),o.name&&!o.name.startsWith("files/")&&(o.name=`files/${o.name}`);const i=this.clientOptions.uploader,r=await i.stat(e);o.sizeBytes=String(r.size);const s=null!==(n=null==t?void 0:t.mimeType)&&void 0!==n?n:r.type;if(void 0===s||""===s)throw new Error("Can not determine mimeType. Please provide mimeType in the config.");o.mimeType=s;const l={file:o},a=this.getFileName(e),u=We("upload/v1beta/files",l._url),c=await this.fetchUploadUrl(u,o.sizeBytes,o.mimeType,a,l,null==t?void 0:t.httpOptions);return i.upload(e,c,this)}async uploadFileToFileSearchStore(e,t,n){var o;const i=this.clientOptions.uploader,r=await i.stat(t),s=String(r.size),l=null!==(o=null==n?void 0:n.mimeType)&&void 0!==o?o:r.type;if(void 0===l||""===l)throw new Error("Can not determine mimeType. Please provide mimeType in the config.");const a=`upload/v1beta/${e}:uploadToFileSearchStore`,u=this.getFileName(t),c={};null!=n&&so(n,c);const p=await this.fetchUploadUrl(a,s,l,u,c,null==n?void 0:n.httpOptions);return i.uploadToFileSearchStore(t,p,this)}async downloadFile(e){await this.clientOptions.downloader.download(e,this)}async fetchUploadUrl(e,t,n,o,i,r){var s;let l={};l=r||{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}`},o?{"X-Goog-Upload-File-Name":o}:{})};const a=await this.request({path:e,body:JSON.stringify(i),httpMethod:"POST",httpOptions:l});if(!a||!(null==a?void 0:a.headers))throw new Error("Server did not return an HttpResponse or the returned HttpResponse did not have headers.");const u=null===(s=null==a?void 0:a.headers)||void 0===s?void 0:s["x-goog-upload-url"];if(void 0===u)throw new Error("Failed to get upload url. Server did not return the x-google-upload-url in the headers");return u}};async function po(e){var t;if(void 0===e)throw new Error("response is undefined");if(!e.ok){const n=e.status;let o;o=(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}};const i=JSON.stringify(o);if(n>=400&&n<600)throw new Nn({message:i,status:n});throw new Error(i)}}function mo(e){for(const t of e){if(ho(t))return!0;if("object"==typeof t&&"inputSchema"in t)return!0}return!1}function fo(e){var t;const n=null!==(t=e[lo])&&void 0!==t?t:"";e[lo]=(n+" mcp_used/unknown").trimStart()}function ho(e){return null!==e&&"object"==typeof e&&e instanceof vo}function go(e){return Cn(this,arguments,function*(e,t=100){let n,o=0;for(;o<t;){const t=yield Tn(e.listTools({cursor:n}));for(const e of t.tools)yield yield Tn(e),o++;if(!t.nextCursor)break;n=t.nextCursor}})}var vo=class e{constructor(e=[],t){this.mcpTools=[],this.functionNameToMcpClient={},this.mcpClients=e,this.config=t}static create(t,n){return new e(t,n)}async initialize(){var e,t,n,o;if(this.mcpTools.length>0)return;const i={},r=[];for(const c of this.mcpClients)try{for(var s,l=!0,a=(t=void 0,Sn(go(c)));!(e=(s=await a.next()).done);l=!0){o=s.value,l=!1;const e=o;r.push(e);const t=e.name;if(i[t])throw new Error(`Duplicate function name ${t} found in MCP tools. Please ensure function names are unique.`);i[t]=c}}catch(u){t={error:u}}finally{try{l||e||!(n=a.return)||await n.call(a)}finally{if(t)throw t.error}}this.mcpTools=r,this.functionNameToMcpClient=i}async tool(){return await this.initialize(),function(e,t={}){const n=[],o=/* @__PURE__ */new Set;for(const i of e){const e=i.name;if(o.has(e))throw new Error(`Duplicate function name ${e} found in MCP tools. Please ensure function names are unique.`);o.add(e);const r=ln(i,t);r.functionDeclarations&&n.push(...r.functionDeclarations)}return{functionDeclarations:n}}(this.mcpTools,this.config)}async callTool(e){await this.initialize();const t=[];for(const n of e)if(n.name in this.functionNameToMcpClient){const e=this.functionNameToMcpClient[n.name];let o;this.config.timeout&&(o={timeout:this.config.timeout});const i=await e.callTool({name:n.name,arguments:n.args},void 0,o);t.push({functionResponse:{name:n.name,response:i.isError?{error:i}:i}})}return t}},_o=class{constructor(e,t,n){this.apiClient=e,this.auth=t,this.webSocketFactory=n}async connect(e){var t,n;if(this.apiClient.isVertexAI())throw new Error("Live music is not supported for Vertex AI.");const o=this.apiClient.getWebsocketBaseUrl(),i=this.apiClient.getApiVersion(),r=function(e){const t=new Headers;for(const[n,o]of Object.entries(e))t.append(n,o);return t}(this.apiClient.getDefaultHeaders()),s=`${o}/ws/google.ai.generativelanguage.${i}.GenerativeService.BidiGenerateMusic?key=${this.apiClient.getApiKey()}`;let l=()=>{};const a=new Promise(e=>{l=e}),u=e.callbacks,c=(this.apiClient,{onopen:function(){l({})},onmessage:e=>{!async function(e,t,n){const o=new Nt;let i;i=n.data instanceof Blob?JSON.parse(await n.data.text()):JSON.parse(n.data),Object.assign(o,i),t(o)}(0,u.onmessage,e)},onerror:null!==(t=null==u?void 0:u.onerror)&&void 0!==t?t:function(e){},onclose:null!==(n=null==u?void 0:u.onclose)&&void 0!==n?n:function(e){}}),p=this.webSocketFactory.create(s,function(e){const t={};return e.forEach((e,n)=>{t[n]=e}),t}(r),c);p.connect(),await a;const d={setup:{model:Gt(this.apiClient,e.model)}};return p.send(JSON.stringify(d)),new Eo(p,this.apiClient)}},Eo=class{constructor(e,t){this.conn=e,this.apiClient=t}async setWeightedPrompts(e){if(!e.weightedPrompts||0===Object.keys(e.weightedPrompts).length)throw new Error("Weighted prompts must be set and contain at least one entry.");const t=function(e){const t={},n=Ze(e,["weightedPrompts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["weightedPrompts"],e)}return t}(e);this.conn.send(JSON.stringify({clientContent:t}))}async setMusicGenerationConfig(e){e.musicGenerationConfig||(e.musicGenerationConfig={});const t=function(e){const t={},n=Ze(e,["musicGenerationConfig"]);return null!=n&&ze(t,["musicGenerationConfig"],n),t}(e);this.conn.send(JSON.stringify(t))}sendPlaybackControl(e){const t={playbackControl:e};this.conn.send(JSON.stringify(t))}play(){this.sendPlaybackControl(Be.PLAY)}pause(){this.sendPlaybackControl(Be.PAUSE)}stop(){this.sendPlaybackControl(Be.STOP)}resetContext(){this.sendPlaybackControl(Be.RESET_CONTEXT)}close(){this.conn.close()}},yo=class{constructor(e,t,n){this.apiClient=e,this.auth=t,this.webSocketFactory=n,this.music=new _o(this.apiClient,this.auth,this.webSocketFactory)}async connect(e){var t,n,o,i,r,s;if(e.config&&e.config.httpOptions)throw new Error("The Live module does not support httpOptions at request-level in LiveConnectConfig yet. Please use the client-level httpOptions configuration instead.");const l=this.apiClient.getWebsocketBaseUrl(),a=this.apiClient.getApiVersion();let u;const c=this.apiClient.getHeaders();e.config&&e.config.tools&&mo(e.config.tools)&&fo(c);const p=function(e){const t=new Headers;for(const[n,o]of Object.entries(e))t.append(n,o);return t}(c);if(this.apiClient.isVertexAI()){const e=this.apiClient.getProject(),t=this.apiClient.getLocation(),n=this.apiClient.getApiKey(),o=!!e&&!!t||!!n;this.apiClient.getCustomBaseUrl()&&!o?u=l:(u=`${l}/ws/google.cloud.aiplatform.${a}.LlmBidiService/BidiGenerateContent`,await this.auth.addAuthHeaders(p,u))}else{const e=this.apiClient.getApiKey();let t="BidiGenerateContent",n="key";(null==e?void 0:e.startsWith("auth_tokens/"))&&(t="BidiGenerateContentConstrained",n="access_token"),u=`${l}/ws/google.ai.generativelanguage.${a}.GenerativeService.${t}?${n}=${e}`}let d=()=>{};const m=new Promise(e=>{d=e}),f=e.callbacks,h=this.apiClient;let g=!1;const v=[];let _=()=>{};const E=new Promise(e=>{_=e}),y={onopen:function(){var e;null===(e=null==f?void 0:f.onopen)||void 0===e||e.call(f),d({})},onmessage:e=>{!async function(e,t,n){const o=new Rt;let i;i=n.data instanceof Blob?await n.data.text():n.data instanceof ArrayBuffer?(new TextDecoder).decode(n.data):n.data;const r=JSON.parse(i);if(e.isVertexAI()){const e=function(e){const t={},n=Ze(e,["setupComplete"]);null!=n&&ze(t,["setupComplete"],n);const o=Ze(e,["serverContent"]);null!=o&&ze(t,["serverContent"],o);const i=Ze(e,["toolCall"]);null!=i&&ze(t,["toolCall"],i);const r=Ze(e,["toolCallCancellation"]);null!=r&&ze(t,["toolCallCancellation"],r);const s=Ze(e,["usageMetadata"]);null!=s&&ze(t,["usageMetadata"],function(e){const t={},n=Ze(e,["candidatesTokenCount"]);null!=n&&ze(t,["responseTokenCount"],n);const o=Ze(e,["candidatesTokensDetails"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["responseTokensDetails"],e)}const i=Ze(e,["cacheTokensDetails"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["cacheTokensDetails"],e)}const r=Ze(e,["cachedContentTokenCount"]);null!=r&&ze(t,["cachedContentTokenCount"],r);const s=Ze(e,["promptTokenCount"]);null!=s&&ze(t,["promptTokenCount"],s);const l=Ze(e,["promptTokensDetails"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["promptTokensDetails"],e)}const a=Ze(e,["thoughtsTokenCount"]);null!=a&&ze(t,["thoughtsTokenCount"],a);const u=Ze(e,["toolUsePromptTokenCount"]);null!=u&&ze(t,["toolUsePromptTokenCount"],u);const c=Ze(e,["toolUsePromptTokensDetails"]);if(null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["toolUsePromptTokensDetails"],e)}const p=Ze(e,["totalTokenCount"]);null!=p&&ze(t,["totalTokenCount"],p);const d=Ze(e,["trafficType"]);return null!=d&&ze(t,["trafficType"],d),t}(s));const l=Ze(e,["goAway"]);null!=l&&ze(t,["goAway"],l);const a=Ze(e,["sessionResumptionUpdate"]);null!=a&&ze(t,["sessionResumptionUpdate"],a);const u=Ze(e,["voiceActivityDetectionSignal"]);null!=u&&ze(t,["voiceActivityDetectionSignal"],u);const c=Ze(e,["voiceActivity"]);return null!=c&&ze(t,["voiceActivity"],function(e){const t={},n=Ze(e,["type"]);null!=n&&ze(t,["voiceActivityType"],n);const o=Ze(e,["audioOffset"]);return null!=o&&ze(t,["audioOffset"],o),t}(c)),t}(r);Object.assign(o,e)}else Object.assign(o,r);var s;(s=o).setupComplete&&!b.setupComplete&&(b.setupComplete=s.setupComplete,_({})),g?f.onmessage(s):v.push(s)}(h,0,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){}},A=this.webSocketFactory.create(u,function(e){const t={};return e.forEach((e,n)=>{t[n]=e}),t}(p),y);A.connect(),await m;let I=Gt(this.apiClient,e.model);if(this.apiClient.isVertexAI()&&I.startsWith("publishers/")){const e=this.apiClient.getProject(),t=this.apiClient.getLocation();e&&t&&(I=`projects/${e}/locations/${t}/`+I)}let T={};this.apiClient.isVertexAI()&&void 0===(null===(o=e.config)||void 0===o?void 0:o.responseModalities)&&(void 0===e.config?e.config={responseModalities:[$.AUDIO]}:e.config.responseModalities=[$.AUDIO]),null===(i=e.config)||void 0===i||i.generationConfig;const C=null!==(s=null===(r=e.config)||void 0===r?void 0:r.tools)&&void 0!==s?s:[],S=[];for(const P of C)if(this.isCallableTool(P)){const e=P;S.push(await e.tool())}else S.push(P);S.length>0&&(e.config.tools=S);const O={model:I,config:e.config,callbacks:e.callbacks};T=this.apiClient.isVertexAI()?function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["setup","model"],Gt(e,o));const i=Ze(t,["config"]);return null!=i&&ze(n,["config"],Mn(i,n)),n}(this.apiClient,O):function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["setup","model"],Gt(e,o));const i=Ze(t,["config"]);return null!=i&&ze(n,["config"],kn(i,n)),n}(this.apiClient,O),delete T.config;const b=new Io(A,this.apiClient);A.send(JSON.stringify(T)),await E,g=!0;for(const P of v)f.onmessage(P);return b}isCallableTool(e){return"callTool"in e&&"function"==typeof e.callTool}},Ao={turnComplete:!0},Io=class{constructor(e,t){this.conn=e,this.apiClient=t}tLiveClientContent(e,t){if(null!==t.turns&&void 0!==t.turns){let n=[];try{n=Jt(t.turns),e.isVertexAI()||(n=n.map(e=>Hn(e)))}catch(vr){throw new 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)throw new Error("functionResponses is required.");if(n=Array.isArray(t.functionResponses)?t.functionResponses:[t.functionResponses],0===n.length)throw new Error("functionResponses is required.");for(const o of n){if("object"!=typeof o||null===o||!("name"in o)||!("response"in o))throw new Error(`Could not parse function response, type '${typeof o}'.`);if(!e.isVertexAI()&&!("id"in o))throw new 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({},Ao),e);const t=this.tLiveClientContent(this.apiClient,e);this.conn.send(JSON.stringify(t))}sendRealtimeInput(e){let t={};t=this.apiClient.isVertexAI()?{realtimeInput:Un(e)}:{realtimeInput:xn(e)},this.conn.send(JSON.stringify(t))}sendToolResponse(e){if(null==e.functionResponses)throw new Error("Tool response parameters are required.");const t=this.tLiveClienttToolResponse(this.apiClient,e);this.conn.send(JSON.stringify(t))}close(){this.conn.close()}};function To(e){var t,n,o;if(null===(t=null==e?void 0:e.automaticFunctionCalling)||void 0===t?void 0:t.disable)return!0;let i=!1;for(const s of null!==(n=null==e?void 0:e.tools)&&void 0!==n?n:[])if(Co(s)){i=!0;break}if(!i)return!0;const r=null===(o=null==e?void 0:e.automaticFunctionCalling)||void 0===o?void 0:o.maximumRemoteCalls;return!!(r&&(r<0||!Number.isInteger(r))||0==r)}function Co(e){return"callTool"in e&&"function"==typeof e.callTool}function So(e){var t;const n=[];return(null===(t=null==e?void 0:e.config)||void 0===t?void 0:t.tools)?(e.config.tools.forEach((e,t)=>{if(Co(e))return;const o=e;o.functionDeclarations&&o.functionDeclarations.length>0&&n.push(t)}),n):n}function Oo(e){var t;return!(null===(t=null==e?void 0:e.automaticFunctionCalling)||void 0===t?void 0:t.ignoreCallHistory)}var bo=class e extends Ke{constructor(t){super(),this.apiClient=t,this.embedContent=async e=>{if(!this.apiClient.isVertexAI())return e.model.includes("gemini-embedding-2")&&(e.contents=Jt(e.contents)),await this.embedContentInternal(e);if(e.model.includes("gemini")&&"gemini-embedding-001"!==e.model||e.model.includes("maas")){const t=Jt(e.contents);if(t.length>1)throw new Error("The embedContent API for this model only supports one content at a time.");const n=Object.assign(Object.assign({},e),{content:t[0],embeddingApiType:ve.EMBED_CONTENT});return await this.embedContentInternal(n)}{const t=Object.assign(Object.assign({},e),{embeddingApiType:ve.PREDICT});return await this.embedContentInternal(t)}},this.generateContent=async e=>{var t,n,o,i,r;const s=await this.processParamsMaybeAddMcpUsage(e);if(this.maybeMoveToResponseJsonSchema(e),!function(e){var t,n,o;return null!==(o=null===(n=null===(t=e.config)||void 0===t?void 0:t.tools)||void 0===n?void 0:n.some(e=>Co(e)))&&void 0!==o&&o}(e)||To(e.config))return await this.generateContentInternal(s);const l=So(e);if(l.length>0){const e=l.map(e=>`tools[${e}]`).join(", ");throw new Error(`Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations is not yet supported. Incompatible tools found at ${e}.`)}let a,u;const c=Jt(s.contents),p=null!==(o=null===(n=null===(t=s.config)||void 0===t?void 0:t.automaticFunctionCalling)||void 0===n?void 0:n.maximumRemoteCalls)&&void 0!==o?o:10;let d=0;for(;d<p&&(a=await this.generateContentInternal(s),a.functionCalls&&0!==a.functionCalls.length);){const t=a.candidates[0].content,n=[];for(const o of null!==(r=null===(i=e.config)||void 0===i?void 0:i.tools)&&void 0!==r?r:[])if(Co(o)){const e=await o.callTool(a.functionCalls);n.push(...e)}d++,u={role:"user",parts:n},s.contents=Jt(s.contents),s.contents.push(t),s.contents.push(u),Oo(s.config)&&(c.push(t),c.push(u))}return Oo(s.config)&&(a.automaticFunctionCallingHistory=c),a},this.generateContentStream=async e=>{var t,n,o,i,r;if(this.maybeMoveToResponseJsonSchema(e),To(e.config)){const t=await this.processParamsMaybeAddMcpUsage(e);return await this.generateContentStreamInternal(t)}const s=So(e);if(s.length>0){const e=s.map(e=>`tools[${e}]`).join(", ");throw new Error(`Incompatible tools found at ${e}. Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations" is not yet supported.`)}const l=null===(o=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===o?void 0:o.streamFunctionCallArguments,a=null===(r=null===(i=null==e?void 0:e.config)||void 0===i?void 0:i.automaticFunctionCalling)||void 0===r?void 0:r.disable;if(l&&!a)throw new 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 t=>(e.loggedGenerateImagesWarning||(e.loggedGenerateImagesWarning=!0),await this.generateImagesInternal(t).then(e=>{var t;let n;const o=[];if(null==e?void 0:e.generatedImages)for(const r of e.generatedImages)r&&(null==r?void 0:r.safetyAttributes)&&"Positive Prompt"===(null===(t=null==r?void 0:r.safetyAttributes)||void 0===t?void 0:t.contentType)?n=null==r?void 0:r.safetyAttributes:o.push(r);let i;return i=n?{generatedImages:o,positivePromptSafetyAttributes:n,sdkHttpResponse:e.sdkHttpResponse}:{generatedImages:o,sdkHttpResponse:e.sdkHttpResponse},i})),this.list=async e=>{var t;const 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 new Error("Filtering tuned models list is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");n.config.filter="labels.tune-type:*"}return new vn(nt.PAGED_ITEM_MODELS,e=>this.listInternal(e),await this.listInternal(n),n)},this.editImage=async t=>{e.loggedEditImageWarning||(e.loggedEditImageWarning=!0);const n={model:t.model,prompt:t.prompt,referenceImages:[],config:t.config};return t.referenceImages&&t.referenceImages&&(n.referenceImages=t.referenceImages.map(e=>e.toReferenceImageAPI())),await this.editImageInternal(n)},this.upscaleImage=async e=>{let t={numberOfImages:1,mode:"upscale"};e.config&&(t=Object.assign(Object.assign({},t),e.config));const n={model:e.model,image:e.image,upscaleFactor:e.upscaleFactor,config:t};return await this.upscaleImageInternal(n)},this.generateVideos=async t=>{var n,o,i,r,s,l;if((t.prompt||t.image||t.video)&&t.source)throw new Error("Source and prompt/image/video are mutually exclusive. Please only use source.");return(t.prompt||t.image||t.video)&&(e.loggedGenerateVideosWarning||(e.loggedGenerateVideosWarning=!0)),this.apiClient.isVertexAI()||((null===(n=t.video)||void 0===n?void 0:n.uri)&&(null===(o=t.video)||void 0===o?void 0:o.videoBytes)?t.video={uri:t.video.uri,mimeType:t.video.mimeType}:(null===(r=null===(i=t.source)||void 0===i?void 0:i.video)||void 0===r?void 0:r.uri)&&(null===(l=null===(s=t.source)||void 0===s?void 0:s.video)||void 0===l?void 0:l.videoBytes)&&(t.source.video={uri:t.source.video.uri,mimeType:t.source.video.mimeType})),await this.generateVideosInternal(t)}}maybeMoveToResponseJsonSchema(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,o;const i=null===(t=e.config)||void 0===t?void 0:t.tools;if(!i)return e;const r=await Promise.all(i.map(async e=>Co(e)?await e.tool():e)),s={model:e.model,contents:e.contents,config:Object.assign(Object.assign({},e.config),{tools:r})};if(s.config.tools=r,e.config&&e.config.tools&&mo(e.config.tools)){const t=null!==(o=null===(n=e.config.httpOptions)||void 0===n?void 0:n.headers)&&void 0!==o?o:{};let i=Object.assign({},t);0===Object.keys(i).length&&(i=this.apiClient.getDefaultHeaders()),fo(i),s.config.httpOptions=Object.assign(Object.assign({},e.config.httpOptions),{headers:i})}return s}async initAfcToolsMap(e){var t,n,o;const i=/* @__PURE__ */new Map;for(const r of null!==(n=null===(t=e.config)||void 0===t?void 0:t.tools)&&void 0!==n?n:[])if(Co(r)){const e=r,t=await e.tool();for(const n of null!==(o=t.functionDeclarations)&&void 0!==o?o:[]){if(!n.name)throw new Error("Function declaration name is required.");if(i.has(n.name))throw new Error(`Duplicate tool declaration name: ${n.name}`);i.set(n.name,e)}}return i}async processAfcStream(e){var t,n,o;const i=null!==(o=null===(n=null===(t=e.config)||void 0===t?void 0:t.automaticFunctionCalling)||void 0===n?void 0:n.maximumRemoteCalls)&&void 0!==o?o:10;let r=!1,s=0;return function(e,t,n){return Cn(this,arguments,function*(){for(var o,l,a,u,c,p;s<i;){r&&(s++,r=!1);const g=yield Tn(e.processParamsMaybeAddMcpUsage(n)),v=yield Tn(e.generateContentStreamInternal(g)),_=[],E=[];try{for(var d,m=!0,f=(l=void 0,Sn(v));!(o=(d=yield Tn(f.next())).done);m=!0){u=d.value,m=!1;const e=u;if(yield yield Tn(e),e.candidates&&(null===(c=e.candidates[0])||void 0===c?void 0:c.content)){E.push(e.candidates[0].content);for(const n of null!==(p=e.candidates[0].content.parts)&&void 0!==p?p:[])if(s<i&&n.functionCall){if(!n.functionCall.name)throw new Error("Function call name was not returned by the model.");if(!t.has(n.functionCall.name))throw new Error(`Automatic function calling was requested, but not all the tools the model used implement the CallableTool interface. Available tools: ${t.keys()}, missing tool: ${n.functionCall.name}`);{const e=yield Tn(t.get(n.functionCall.name).callTool([n.functionCall]));_.push(...e)}}}}}catch(h){l={error:h}}finally{try{m||o||!(a=f.return)||(yield Tn(a.call(f)))}finally{if(l)throw l.error}}if(!(_.length>0))break;{r=!0;const e=new it;e.candidates=[{content:{role:"user",parts:_}}],yield yield Tn(e);const t=[];t.push(...E),t.push({role:"user",parts:_}),n.contents=Jt(n.contents).concat(t)}}})}(this,await this.initAfcToolsMap(e),e)}async generateContentInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=Bn(this.apiClient,e);return s=We("{model}:generateContent",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=Xn(e),n=new it;return Object.assign(n,t),n})}{const t=jn(this.apiClient,e);return s=We("{model}:generateContent",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=Vn(e),n=new it;return Object.assign(n,t),n})}}async generateContentStreamInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=Bn(this.apiClient,e);return s=We("{model}:streamGenerateContent?alt=sse",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.requestStream({path:s,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}),r.then(function(e){return Cn(this,arguments,function*(){var t,n,o,i;try{for(var r,s=!0,l=Sn(e);!(t=(r=yield Tn(l.next())).done);s=!0){i=r.value,s=!1;const e=i,t=Xn(yield Tn(e.json()));t.sdkHttpResponse={headers:e.headers};const n=new it;Object.assign(n,t),yield yield Tn(n)}}catch(a){n={error:a}}finally{try{s||t||!(o=l.return)||(yield Tn(o.call(l)))}finally{if(n)throw n.error}}})})}{const t=jn(this.apiClient,e);return s=We("{model}:streamGenerateContent?alt=sse",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.requestStream({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}),r.then(function(e){return Cn(this,arguments,function*(){var t,n,o,i;try{for(var r,s=!0,l=Sn(e);!(t=(r=yield Tn(l.next())).done);s=!0){i=r.value,s=!1;const e=i,t=Vn(yield Tn(e.json()));t.sdkHttpResponse={headers:e.headers};const n=new it;Object.assign(n,t),yield yield Tn(n)}}catch(a){n={error:a}}finally{try{s||t||!(o=l.return)||(yield Tn(o.call(l)))}finally{if(n)throw n.error}}})})}}async embedContentInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t,n){const o={},i=Ze(t,["model"]);null!=i&&ze(o,["_url","model"],Gt(e,i));let r=Ze(n,["embeddingApiType"]);if(void 0===r&&(r="PREDICT"),"PREDICT"===r){const n=Ze(t,["contents"]);if(null!=n){let t=Xt(e,n);Array.isArray(t)&&(t=t.map(e=>e)),ze(o,["instances[]","content"],t)}}let s=Ze(n,["embeddingApiType"]);if(void 0===s&&(s="PREDICT"),"EMBED_CONTENT"===s){const e=Ze(t,["content"]);null!=e&&ze(o,["content"],Fn(Vt(e)))}const l=Ze(t,["config"]);return null!=l&&function(e,t,n){let o=Ze(n,["embeddingApiType"]);if(void 0===o&&(o="PREDICT"),"PREDICT"===o){const n=Ze(e,["taskType"]);void 0!==t&&null!=n&&ze(t,["instances[]","task_type"],n)}else if("EMBED_CONTENT"===o){const n=Ze(e,["taskType"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","taskType"],n)}let i=Ze(n,["embeddingApiType"]);if(void 0===i&&(i="PREDICT"),"PREDICT"===i){const n=Ze(e,["title"]);void 0!==t&&null!=n&&ze(t,["instances[]","title"],n)}else if("EMBED_CONTENT"===i){const n=Ze(e,["title"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","title"],n)}let r=Ze(n,["embeddingApiType"]);if(void 0===r&&(r="PREDICT"),"PREDICT"===r){const n=Ze(e,["outputDimensionality"]);void 0!==t&&null!=n&&ze(t,["parameters","outputDimensionality"],n)}else if("EMBED_CONTENT"===r){const n=Ze(e,["outputDimensionality"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","outputDimensionality"],n)}let s=Ze(n,["embeddingApiType"]);if(void 0===s&&(s="PREDICT"),"PREDICT"===s){const n=Ze(e,["mimeType"]);void 0!==t&&null!=n&&ze(t,["instances[]","mimeType"],n)}let l=Ze(n,["embeddingApiType"]);if(void 0===l&&(l="PREDICT"),"PREDICT"===l){const n=Ze(e,["autoTruncate"]);void 0!==t&&null!=n&&ze(t,["parameters","autoTruncate"],n)}else if("EMBED_CONTENT"===l){const n=Ze(e,["autoTruncate"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","autoTruncate"],n)}let a=Ze(n,["embeddingApiType"]);if(void 0===a&&(a="PREDICT"),"EMBED_CONTENT"===a){const n=Ze(e,["documentOcr"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","documentOcr"],n)}let u=Ze(n,["embeddingApiType"]);if(void 0===u&&(u="PREDICT"),"EMBED_CONTENT"===u){const n=Ze(e,["audioTrackExtraction"]);void 0!==t&&null!=n&&ze(t,["embedContentConfig","audioTrackExtraction"],n)}}(l,o,n),o}(this.apiClient,e,e);return s=We((a=e.model).includes("gemini")&&"gemini-embedding-001"!==a||a.includes("maas")?"{model}:embedContent":"{model}:predict",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(t=>{const n=function(e,t){const n={},o=Ze(e,["sdkHttpResponse"]);null!=o&&ze(n,["sdkHttpResponse"],o);const i=Ze(e,["predictions[]","embeddings"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["values"]);null!=n&&ze(t,["values"],n);const o=Ze(e,["statistics"]);return null!=o&&ze(t,["statistics"],function(e){const t={},n=Ze(e,["truncated"]);null!=n&&ze(t,["truncated"],n);const o=Ze(e,["token_count"]);null!=o&&ze(t,["tokenCount"],o);const i=Ze(e,["tokensDetails"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["tokensDetails"],e)}return t}(o)),t}(e))),ze(n,["embeddings"],e)}const r=Ze(e,["metadata"]);if(null!=r&&ze(n,["metadata"],r),t&&"EMBED_CONTENT"===Ze(t,["embeddingApiType"])){const t=Ze(e,["embedding"]),o=Ze(e,["usageMetadata"]),i=Ze(e,["truncated"]);if(t){const e={};o&&o.promptTokenCount&&(e.tokenCount=o.promptTokenCount),o&&o.promptTokensDetails&&(e.tokensDetails=o.promptTokensDetails),i&&(e.truncated=i),t.statistics=e,ze(n,["embeddings"],[t])}}return n}(t,e),o=new rt;return Object.assign(o,n),o})}{const t=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["contents"]);if(null!=i){let t=Xt(e,i);Array.isArray(t)&&(t=t.map(e=>e)),ze(n,["requests[]","content"],t)}const r=Ze(t,["content"]);null!=r&&Hn(Vt(r));const s=Ze(t,["config"]);null!=s&&function(e,t){const n=Ze(e,["taskType"]);void 0!==t&&null!=n&&ze(t,["requests[]","taskType"],n);const o=Ze(e,["title"]);void 0!==t&&null!=o&&ze(t,["requests[]","title"],o);const i=Ze(e,["outputDimensionality"]);if(void 0!==t&&null!=i&&ze(t,["requests[]","outputDimensionality"],i),void 0!==Ze(e,["mimeType"]))throw new Error("mimeType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["autoTruncate"]))throw new Error("autoTruncate parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["documentOcr"]))throw new Error("documentOcr parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["audioTrackExtraction"]))throw new Error("audioTrackExtraction parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(s,n);const l=Ze(t,["model"]);return void 0!==l&&ze(n,["requests[]","model"],Gt(e,l)),n}(this.apiClient,e);return s=We("{model}:batchEmbedContents",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["embeddings"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["embeddings"],e)}const i=Ze(e,["metadata"]);return null!=i&&ze(t,["metadata"],i),t}(e),n=new rt;return Object.assign(n,t),n})}var a}async generateImagesInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["prompt"]);null!=i&&ze(n,["instances[0]","prompt"],i);const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["outputGcsUri"]);void 0!==t&&null!=n&&ze(t,["parameters","storageUri"],n);const o=Ze(e,["negativePrompt"]);void 0!==t&&null!=o&&ze(t,["parameters","negativePrompt"],o);const i=Ze(e,["numberOfImages"]);void 0!==t&&null!=i&&ze(t,["parameters","sampleCount"],i);const r=Ze(e,["aspectRatio"]);void 0!==t&&null!=r&&ze(t,["parameters","aspectRatio"],r);const s=Ze(e,["guidanceScale"]);void 0!==t&&null!=s&&ze(t,["parameters","guidanceScale"],s);const l=Ze(e,["seed"]);void 0!==t&&null!=l&&ze(t,["parameters","seed"],l);const a=Ze(e,["safetyFilterLevel"]);void 0!==t&&null!=a&&ze(t,["parameters","safetySetting"],a);const u=Ze(e,["personGeneration"]);void 0!==t&&null!=u&&ze(t,["parameters","personGeneration"],u);const c=Ze(e,["includeSafetyAttributes"]);void 0!==t&&null!=c&&ze(t,["parameters","includeSafetyAttributes"],c);const p=Ze(e,["includeRaiReason"]);void 0!==t&&null!=p&&ze(t,["parameters","includeRaiReason"],p);const d=Ze(e,["language"]);void 0!==t&&null!=d&&ze(t,["parameters","language"],d);const m=Ze(e,["outputMimeType"]);void 0!==t&&null!=m&&ze(t,["parameters","outputOptions","mimeType"],m);const f=Ze(e,["outputCompressionQuality"]);void 0!==t&&null!=f&&ze(t,["parameters","outputOptions","compressionQuality"],f);const h=Ze(e,["addWatermark"]);void 0!==t&&null!=h&&ze(t,["parameters","addWatermark"],h);const g=Ze(e,["labels"]);void 0!==t&&null!=g&&ze(t,["labels"],g);const v=Ze(e,["imageSize"]);void 0!==t&&null!=v&&ze(t,["parameters","sampleImageSize"],v);const _=Ze(e,["enhancePrompt"]);void 0!==t&&null!=_&&ze(t,["parameters","enhancePrompt"],_)}(r,n),n}(this.apiClient,e);return i=We("{model}:predict",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["predictions"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>$n(e))),ze(t,["generatedImages"],e)}const i=Ze(e,["positivePromptSafetyAttributes"]);return null!=i&&ze(t,["positivePromptSafetyAttributes"],eo(i)),t}(e),n=new st;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async editImageInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["prompt"]);null!=i&&ze(n,["instances[0]","prompt"],i);const r=Ze(t,["referenceImages"]);if(null!=r){let e=r;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["referenceImage"]);null!=n&&ze(t,["referenceImage"],zn(n));const o=Ze(e,["referenceId"]);null!=o&&ze(t,["referenceId"],o);const i=Ze(e,["referenceType"]);null!=i&&ze(t,["referenceType"],i);const r=Ze(e,["maskImageConfig"]);null!=r&&ze(t,["maskImageConfig"],function(e){const t={},n=Ze(e,["maskMode"]);null!=n&&ze(t,["maskMode"],n);const o=Ze(e,["segmentationClasses"]);null!=o&&ze(t,["maskClasses"],o);const i=Ze(e,["maskDilation"]);return null!=i&&ze(t,["dilation"],i),t}(r));const s=Ze(e,["controlImageConfig"]);null!=s&&ze(t,["controlImageConfig"],function(e){const t={},n=Ze(e,["controlType"]);null!=n&&ze(t,["controlType"],n);const o=Ze(e,["enableControlImageComputation"]);return null!=o&&ze(t,["computeControl"],o),t}(s));const l=Ze(e,["styleImageConfig"]);null!=l&&ze(t,["styleImageConfig"],l);const a=Ze(e,["subjectImageConfig"]);return null!=a&&ze(t,["subjectImageConfig"],a),t}(e))),ze(n,["instances[0]","referenceImages"],e)}const s=Ze(t,["config"]);return null!=s&&function(e,t){const n=Ze(e,["outputGcsUri"]);void 0!==t&&null!=n&&ze(t,["parameters","storageUri"],n);const o=Ze(e,["negativePrompt"]);void 0!==t&&null!=o&&ze(t,["parameters","negativePrompt"],o);const i=Ze(e,["numberOfImages"]);void 0!==t&&null!=i&&ze(t,["parameters","sampleCount"],i);const r=Ze(e,["aspectRatio"]);void 0!==t&&null!=r&&ze(t,["parameters","aspectRatio"],r);const s=Ze(e,["guidanceScale"]);void 0!==t&&null!=s&&ze(t,["parameters","guidanceScale"],s);const l=Ze(e,["seed"]);void 0!==t&&null!=l&&ze(t,["parameters","seed"],l);const a=Ze(e,["safetyFilterLevel"]);void 0!==t&&null!=a&&ze(t,["parameters","safetySetting"],a);const u=Ze(e,["personGeneration"]);void 0!==t&&null!=u&&ze(t,["parameters","personGeneration"],u);const c=Ze(e,["includeSafetyAttributes"]);void 0!==t&&null!=c&&ze(t,["parameters","includeSafetyAttributes"],c);const p=Ze(e,["includeRaiReason"]);void 0!==t&&null!=p&&ze(t,["parameters","includeRaiReason"],p);const d=Ze(e,["language"]);void 0!==t&&null!=d&&ze(t,["parameters","language"],d);const m=Ze(e,["outputMimeType"]);void 0!==t&&null!=m&&ze(t,["parameters","outputOptions","mimeType"],m);const f=Ze(e,["outputCompressionQuality"]);void 0!==t&&null!=f&&ze(t,["parameters","outputOptions","compressionQuality"],f);const h=Ze(e,["addWatermark"]);void 0!==t&&null!=h&&ze(t,["parameters","addWatermark"],h);const g=Ze(e,["labels"]);void 0!==t&&null!=g&&ze(t,["labels"],g);const v=Ze(e,["editMode"]);void 0!==t&&null!=v&&ze(t,["parameters","editMode"],v);const _=Ze(e,["baseSteps"]);void 0!==t&&null!=_&&ze(t,["parameters","editConfig","baseSteps"],_)}(s,n),n}(this.apiClient,e);return i=We("{model}:predict",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["predictions"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>$n(e))),ze(t,["generatedImages"],e)}return t}(e),n=new lt;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async upscaleImageInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["image"]);null!=i&&ze(n,["instances[0]","image"],zn(i));const r=Ze(t,["upscaleFactor"]);null!=r&&ze(n,["parameters","upscaleConfig","upscaleFactor"],r);const s=Ze(t,["config"]);return null!=s&&function(e,t){const n=Ze(e,["outputGcsUri"]);void 0!==t&&null!=n&&ze(t,["parameters","storageUri"],n);const o=Ze(e,["safetyFilterLevel"]);void 0!==t&&null!=o&&ze(t,["parameters","safetySetting"],o);const i=Ze(e,["personGeneration"]);void 0!==t&&null!=i&&ze(t,["parameters","personGeneration"],i);const r=Ze(e,["includeRaiReason"]);void 0!==t&&null!=r&&ze(t,["parameters","includeRaiReason"],r);const s=Ze(e,["outputMimeType"]);void 0!==t&&null!=s&&ze(t,["parameters","outputOptions","mimeType"],s);const l=Ze(e,["outputCompressionQuality"]);void 0!==t&&null!=l&&ze(t,["parameters","outputOptions","compressionQuality"],l);const a=Ze(e,["enhanceInputImage"]);void 0!==t&&null!=a&&ze(t,["parameters","upscaleConfig","enhanceInputImage"],a);const u=Ze(e,["imagePreservationFactor"]);void 0!==t&&null!=u&&ze(t,["parameters","upscaleConfig","imagePreservationFactor"],u);const c=Ze(e,["labels"]);void 0!==t&&null!=c&&ze(t,["labels"],c);const p=Ze(e,["numberOfImages"]);void 0!==t&&null!=p&&ze(t,["parameters","sampleCount"],p);const d=Ze(e,["mode"]);void 0!==t&&null!=d&&ze(t,["parameters","mode"],d)}(s,n),n}(this.apiClient,e);return i=We("{model}:predict",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["predictions"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>$n(e))),ze(t,["generatedImages"],e)}return t}(e),n=new at;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async recontextImage(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["source"]);null!=i&&function(e,t){const n=Ze(e,["prompt"]);void 0!==t&&null!=n&&ze(t,["instances[0]","prompt"],n);const o=Ze(e,["personImage"]);void 0!==t&&null!=o&&ze(t,["instances[0]","personImage","image"],zn(o));const i=Ze(e,["productImages"]);if(void 0!==t&&null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["productImage"]);return null!=n&&ze(t,["image"],zn(n)),t}(e))),ze(t,["instances[0]","productImages"],e)}}(i,n);const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["numberOfImages"]);void 0!==t&&null!=n&&ze(t,["parameters","sampleCount"],n);const o=Ze(e,["baseSteps"]);void 0!==t&&null!=o&&ze(t,["parameters","baseSteps"],o);const i=Ze(e,["outputGcsUri"]);void 0!==t&&null!=i&&ze(t,["parameters","storageUri"],i);const r=Ze(e,["seed"]);void 0!==t&&null!=r&&ze(t,["parameters","seed"],r);const s=Ze(e,["safetyFilterLevel"]);void 0!==t&&null!=s&&ze(t,["parameters","safetySetting"],s);const l=Ze(e,["personGeneration"]);void 0!==t&&null!=l&&ze(t,["parameters","personGeneration"],l);const a=Ze(e,["addWatermark"]);void 0!==t&&null!=a&&ze(t,["parameters","addWatermark"],a);const u=Ze(e,["outputMimeType"]);void 0!==t&&null!=u&&ze(t,["parameters","outputOptions","mimeType"],u);const c=Ze(e,["outputCompressionQuality"]);void 0!==t&&null!=c&&ze(t,["parameters","outputOptions","compressionQuality"],c);const p=Ze(e,["enhancePrompt"]);void 0!==t&&null!=p&&ze(t,["parameters","enhancePrompt"],p);const d=Ze(e,["labels"]);void 0!==t&&null!=d&&ze(t,["labels"],d)}(r,n),n}(this.apiClient,e);return i=We("{model}:predict",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["predictions"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>$n(e))),ze(t,["generatedImages"],e)}return t}(e),n=new ut;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async segmentImage(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["source"]);null!=i&&function(e,t){const n=Ze(e,["prompt"]);void 0!==t&&null!=n&&ze(t,["instances[0]","prompt"],n);const o=Ze(e,["image"]);void 0!==t&&null!=o&&ze(t,["instances[0]","image"],zn(o));const i=Ze(e,["scribbleImage"]);void 0!==t&&null!=i&&ze(t,["instances[0]","scribble"],function(e){const t={},n=Ze(e,["image"]);return null!=n&&ze(t,["image"],zn(n)),t}(i))}(i,n);const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["mode"]);void 0!==t&&null!=n&&ze(t,["parameters","mode"],n);const o=Ze(e,["maxPredictions"]);void 0!==t&&null!=o&&ze(t,["parameters","maxPredictions"],o);const i=Ze(e,["confidenceThreshold"]);void 0!==t&&null!=i&&ze(t,["parameters","confidenceThreshold"],i);const r=Ze(e,["maskDilation"]);void 0!==t&&null!=r&&ze(t,["parameters","maskDilation"],r);const s=Ze(e,["binaryColorThreshold"]);void 0!==t&&null!=s&&ze(t,["parameters","binaryColorThreshold"],s);const l=Ze(e,["labels"]);void 0!==t&&null!=l&&ze(t,["labels"],l)}(r,n),n}(this.apiClient,e);return i=We("{model}:predict",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["predictions"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["_self"]);null!=n&&ze(t,["mask"],Kn(n));const o=Ze(e,["labels"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["labels"],e)}return t}(e))),ze(t,["generatedMasks"],e)}return t}(e),n=new ct;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async get(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);return null!=o&&ze(n,["_url","name"],Gt(e,o)),n}(this.apiClient,e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>Qn(e))}{const t=function(e,t){const n={},o=Ze(t,["model"]);return null!=o&&ze(n,["_url","name"],Gt(e,o)),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>Zn(e))}}async listInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["config"]);return null!=o&&function(e,t,n){const o=Ze(t,["pageSize"]);void 0!==n&&null!=o&&ze(n,["_query","pageSize"],o);const i=Ze(t,["pageToken"]);void 0!==n&&null!=i&&ze(n,["_query","pageToken"],i);const r=Ze(t,["filter"]);void 0!==n&&null!=r&&ze(n,["_query","filter"],r);const s=Ze(t,["queryBase"]);void 0!==n&&null!=s&&ze(n,["_url","models_url"],on(e,s))}(e,o,n),n}(this.apiClient,e);return s=We("{models_url}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["_self"]);if(null!=i){let e=rn(i);Array.isArray(e)&&(e=e.map(e=>Qn(e))),ze(t,["models"],e)}return t}(e),n=new pt;return Object.assign(n,t),n})}{const t=function(e,t){const n={},o=Ze(t,["config"]);return null!=o&&function(e,t,n){const o=Ze(t,["pageSize"]);void 0!==n&&null!=o&&ze(n,["_query","pageSize"],o);const i=Ze(t,["pageToken"]);void 0!==n&&null!=i&&ze(n,["_query","pageToken"],i);const r=Ze(t,["filter"]);void 0!==n&&null!=r&&ze(n,["_query","filter"],r);const s=Ze(t,["queryBase"]);void 0!==n&&null!=s&&ze(n,["_url","models_url"],on(e,s))}(e,o,n),n}(this.apiClient,e);return s=We("{models_url}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["_self"]);if(null!=i){let e=rn(i);Array.isArray(e)&&(e=e.map(e=>Zn(e))),ze(t,["models"],e)}return t}(e),n=new pt;return Object.assign(n,t),n})}}async update(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["displayName"]);void 0!==t&&null!=n&&ze(t,["displayName"],n);const o=Ze(e,["description"]);void 0!==t&&null!=o&&ze(t,["description"],o);const i=Ze(e,["defaultCheckpointId"]);void 0!==t&&null!=i&&ze(t,["defaultCheckpointId"],i)}(i,n),n}(this.apiClient,e);return s=We("{model}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(o),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()),r.then(e=>Qn(e))}{const t=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","name"],Gt(e,o));const i=Ze(t,["config"]);return null!=i&&function(e,t){const n=Ze(e,["displayName"]);void 0!==t&&null!=n&&ze(t,["displayName"],n);const o=Ze(e,["description"]);void 0!==t&&null!=o&&ze(t,["description"],o);const i=Ze(e,["defaultCheckpointId"]);void 0!==t&&null!=i&&ze(t,["defaultCheckpointId"],i)}(i,n),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"PATCH",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>Zn(e))}}async delete(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);return null!=o&&ze(n,["_url","name"],Gt(e,o)),n}(this.apiClient,e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new dt;return Object.assign(n,t),n})}{const t=function(e,t){const n={},o=Ze(t,["model"]);return null!=o&&ze(n,["_url","name"],Gt(e,o)),n}(this.apiClient,e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"DELETE",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new dt;return Object.assign(n,t),n})}}async countTokens(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["contents"]);if(null!=i){let e=Jt(i);Array.isArray(e)&&(e=e.map(e=>Fn(e))),ze(n,["contents"],e)}const r=Ze(t,["config"]);return null!=r&&function(e,t){const n=Ze(e,["systemInstruction"]);void 0!==t&&null!=n&&ze(t,["systemInstruction"],Fn(Vt(n)));const o=Ze(e,["tools"]);if(void 0!==t&&null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>no(e))),ze(t,["tools"],e)}const i=Ze(e,["generationConfig"]);void 0!==t&&null!=i&&ze(t,["generationConfig"],function(e){const t={},n=Ze(e,["modelSelectionConfig"]);null!=n&&ze(t,["modelConfig"],n);const o=Ze(e,["responseJsonSchema"]);null!=o&&ze(t,["responseJsonSchema"],o);const i=Ze(e,["audioTranscriptionConfig"]);null!=i&&ze(t,["audioTranscriptionConfig"],i);const r=Ze(e,["audioTimestamp"]);null!=r&&ze(t,["audioTimestamp"],r);const s=Ze(e,["candidateCount"]);null!=s&&ze(t,["candidateCount"],s);const l=Ze(e,["enableAffectiveDialog"]);null!=l&&ze(t,["enableAffectiveDialog"],l);const a=Ze(e,["frequencyPenalty"]);null!=a&&ze(t,["frequencyPenalty"],a);const u=Ze(e,["logprobs"]);null!=u&&ze(t,["logprobs"],u);const c=Ze(e,["maxOutputTokens"]);null!=c&&ze(t,["maxOutputTokens"],c);const p=Ze(e,["mediaResolution"]);null!=p&&ze(t,["mediaResolution"],p);const d=Ze(e,["presencePenalty"]);null!=d&&ze(t,["presencePenalty"],d);const m=Ze(e,["responseFormat"]);if(null!=m){let e=m;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["responseFormat"],e)}const f=Ze(e,["responseLogprobs"]);null!=f&&ze(t,["responseLogprobs"],f);const h=Ze(e,["responseMimeType"]);null!=h&&ze(t,["responseMimeType"],h);const g=Ze(e,["responseModalities"]);null!=g&&ze(t,["responseModalities"],g);const v=Ze(e,["responseSchema"]);null!=v&&ze(t,["responseSchema"],v);const _=Ze(e,["routingConfig"]);null!=_&&ze(t,["routingConfig"],_);const E=Ze(e,["seed"]);null!=E&&ze(t,["seed"],E);const y=Ze(e,["speechConfig"]);null!=y&&ze(t,["speechConfig"],to(y));const A=Ze(e,["stopSequences"]);null!=A&&ze(t,["stopSequences"],A);const I=Ze(e,["temperature"]);null!=I&&ze(t,["temperature"],I);const T=Ze(e,["thinkingConfig"]);null!=T&&ze(t,["thinkingConfig"],T);const C=Ze(e,["topK"]);null!=C&&ze(t,["topK"],C);const S=Ze(e,["topP"]);if(null!=S&&ze(t,["topP"],S),void 0!==Ze(e,["enableEnhancedCivicAnswers"]))throw new Error("enableEnhancedCivicAnswers parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["translationConfig"]))throw new Error("translationConfig parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");return t}(i))}(r,n),n}(this.apiClient,e);return s=We("{model}:countTokens",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["totalTokens"]);return null!=o&&ze(t,["totalTokens"],o),t}(e),n=new mt;return Object.assign(n,t),n})}{const t=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["contents"]);if(null!=i){let e=Jt(i);Array.isArray(e)&&(e=e.map(e=>Hn(e))),ze(n,["contents"],e)}const r=Ze(t,["config"]);return null!=r&&function(e){if(void 0!==Ze(e,["systemInstruction"]))throw new Error("systemInstruction parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["tools"]))throw new Error("tools parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["generationConfig"]))throw new Error("generationConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(r),n}(this.apiClient,e);return s=We("{model}:countTokens",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["totalTokens"]);null!=o&&ze(t,["totalTokens"],o);const i=Ze(e,["cachedContentTokenCount"]);return null!=i&&ze(t,["cachedContentTokenCount"],i),t}(e),n=new mt;return Object.assign(n,t),n})}}async computeTokens(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["_url","model"],Gt(e,o));const i=Ze(t,["contents"]);if(null!=i){let e=Jt(i);Array.isArray(e)&&(e=e.map(e=>Fn(e))),ze(n,["contents"],e)}return n}(this.apiClient,e);return i=We("{model}:computeTokens",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["tokensInfo"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["tokensInfo"],e)}return t}(e),n=new ft;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async generateVideosInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=Yn(this.apiClient,e);return s=We("{model}:predictLongRunning",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r.then(e=>{const t=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["videos"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["_self"]);return null!=n&&ze(t,["video"],function(e){const t={},n=Ze(e,["gcsUri"]);null!=n&&ze(t,["uri"],n);const o=Ze(e,["bytesBase64Encoded"]);null!=o&&ze(t,["videoBytes"],tn(o));const i=Ze(e,["mimeType"]);return null!=i&&ze(t,["mimeType"],i),t}(n)),t}(e))),ze(t,["generatedVideos"],e)}const o=Ze(e,["raiMediaFilteredCount"]);null!=o&&ze(t,["raiMediaFilteredCount"],o);const i=Ze(e,["raiMediaFilteredReasons"]);return null!=i&&ze(t,["raiMediaFilteredReasons"],i),t}(s)),t}(e),n=new ht;return Object.assign(n,t),n})}{const t=Jn(this.apiClient,e);return s=We("{model}:predictLongRunning",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r.then(e=>{const t=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response","generateVideoResponse"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["generatedSamples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["video"]);return null!=n&&ze(t,["video"],function(e){const t={},n=Ze(e,["uri"]);null!=n&&ze(t,["uri"],n);const o=Ze(e,["encodedVideo"]);null!=o&&ze(t,["videoBytes"],tn(o));const i=Ze(e,["encoding"]);return null!=i&&ze(t,["mimeType"],i),t}(n)),t}(e))),ze(t,["generatedVideos"],e)}const o=Ze(e,["raiMediaFilteredCount"]);null!=o&&ze(t,["raiMediaFilteredCount"],o);const i=Ze(e,["raiMediaFilteredReasons"]);return null!=i&&ze(t,["raiMediaFilteredReasons"],i),t}(s)),t}(e),n=new ht;return Object.assign(n,t),n})}}};bo.loggedGenerateImagesWarning=!1,bo.loggedEditImageWarning=!1,bo.loggedGenerateVideosWarning=!1;var Po=class extends Ke{constructor(e){super(),this.apiClient=e}async getVideosOperation(e){const t=e.operation,n=e.config;if(void 0===t.name||""===t.name)throw new Error("Operation name is required.");if(this.apiClient.isVertexAI()){const e=t.name.split("/operations/")[0];let o;n&&"httpOptions"in n&&(o=n.httpOptions);const i=await this.fetchPredictVideosOperationInternal({operationName:t.name,resourceName:e,config:{httpOptions:o}});return t._fromAPIResponse({apiResponse:i,_isVertexAI:!0})}{const e=await this.getVideosOperationInternal({operationName:t.name,config:n});return t._fromAPIResponse({apiResponse:e,_isVertexAI:!1})}}async get(e){const t=e.operation,n=e.config;if(void 0===t.name||""===t.name)throw new Error("Operation name is required.");if(this.apiClient.isVertexAI()){const e=t.name.split("/operations/")[0];let o;n&&"httpOptions"in n&&(o=n.httpOptions);const i=await this.fetchPredictVideosOperationInternal({operationName:t.name,resourceName:e,config:{httpOptions:o}});return t._fromAPIResponse({apiResponse:i,_isVertexAI:!0})}{const e=await this.getVideosOperationInternal({operationName:t.name,config:n});return t._fromAPIResponse({apiResponse:e,_isVertexAI:!1})}}async getVideosOperationInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e){const t={},n=Ze(e,["operationName"]);return null!=n&&ze(t,["_url","operationName"],n),t}(e);return s=We("{operationName}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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()),r}{const t=function(e){const t={},n=Ze(e,["operationName"]);return null!=n&&ze(t,["_url","operationName"],n),t}(e);return s=We("{operationName}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json()),r}}async fetchPredictVideosOperationInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e){const t={},n=Ze(e,["operationName"]);null!=n&&ze(t,["operationName"],n);const o=Ze(e,["resourceName"]);return null!=o&&ze(t,["_url","resourceName"],o),t}(e);return i=We("{resourceName}:fetchPredictOperation",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}};function wo(e,t,n){const o=Ze(t,["expireTime"]);void 0!==n&&null!=o&&ze(n,["expireTime"],o);const i=Ze(t,["newSessionExpireTime"]);void 0!==n&&null!=i&&ze(n,["newSessionExpireTime"],i);const r=Ze(t,["uses"]);void 0!==n&&null!=r&&ze(n,["uses"],r);const s=Ze(t,["liveConnectConstraints"]);void 0!==n&&null!=s&&ze(n,["bidiGenerateContentSetup"],function(e,t){const n={},o=Ze(t,["model"]);null!=o&&ze(n,["setup","model"],Gt(e,o));const i=Ze(t,["config"]);return null!=i&&ze(n,["config"],function(e,t){const n=Ze(e,["generationConfig"]);void 0!==t&&null!=n&&ze(t,["setup","generationConfig"],n);const o=Ze(e,["responseModalities"]);void 0!==t&&null!=o&&ze(t,["setup","generationConfig","responseModalities"],o);const i=Ze(e,["temperature"]);void 0!==t&&null!=i&&ze(t,["setup","generationConfig","temperature"],i);const r=Ze(e,["topP"]);void 0!==t&&null!=r&&ze(t,["setup","generationConfig","topP"],r);const s=Ze(e,["topK"]);void 0!==t&&null!=s&&ze(t,["setup","generationConfig","topK"],s);const l=Ze(e,["maxOutputTokens"]);void 0!==t&&null!=l&&ze(t,["setup","generationConfig","maxOutputTokens"],l);const a=Ze(e,["mediaResolution"]);void 0!==t&&null!=a&&ze(t,["setup","generationConfig","mediaResolution"],a);const u=Ze(e,["seed"]);void 0!==t&&null!=u&&ze(t,["setup","generationConfig","seed"],u);const c=Ze(e,["speechConfig"]);void 0!==t&&null!=c&&ze(t,["setup","generationConfig","speechConfig"],Wt(c));const p=Ze(e,["thinkingConfig"]);void 0!==t&&null!=p&&ze(t,["setup","generationConfig","thinkingConfig"],p);const d=Ze(e,["enableAffectiveDialog"]);void 0!==t&&null!=d&&ze(t,["setup","generationConfig","enableAffectiveDialog"],d);const m=Ze(e,["systemInstruction"]);void 0!==t&&null!=m&&ze(t,["setup","systemInstruction"],function(e){const t={},n=Ze(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);null!=n&&ze(t,["mediaResolution"],n);const o=Ze(e,["toolCall"]);null!=o&&ze(t,["toolCall"],o);const i=Ze(e,["toolResponse"]);null!=i&&ze(t,["toolResponse"],i);const r=Ze(e,["audioTranscription"]);null!=r&&ze(t,["audioTranscription"],r);const s=Ze(e,["codeExecutionResult"]);null!=s&&ze(t,["codeExecutionResult"],s);const l=Ze(e,["executableCode"]);null!=l&&ze(t,["executableCode"],l);const a=Ze(e,["fileData"]);null!=a&&ze(t,["fileData"],function(e){const t={};if(void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["fileUri"]);null!=n&&ze(t,["fileUri"],n);const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(a));const u=Ze(e,["functionCall"]);null!=u&&ze(t,["functionCall"],function(e){const t={},n=Ze(e,["args"]);null!=n&&ze(t,["args"],n);const o=Ze(e,["id"]);null!=o&&ze(t,["id"],o);const i=Ze(e,["name"]);if(null!=i&&ze(t,["name"],i),void 0!==Ze(e,["partialArgs"]))throw new Error("partialArgs parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["willContinue"]))throw new Error("willContinue parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(u));const c=Ze(e,["functionResponse"]);null!=c&&ze(t,["functionResponse"],c);const p=Ze(e,["inlineData"]);null!=p&&ze(t,["inlineData"],function(e){const t={},n=Ze(e,["data"]);if(null!=n&&ze(t,["data"],n),void 0!==Ze(e,["displayName"]))throw new Error("displayName parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["mimeType"]);return null!=o&&ze(t,["mimeType"],o),t}(p));const d=Ze(e,["text"]);null!=d&&ze(t,["text"],d);const m=Ze(e,["thought"]);null!=m&&ze(t,["thought"],m);const f=Ze(e,["thoughtSignature"]);null!=f&&ze(t,["thoughtSignature"],f);const h=Ze(e,["videoMetadata"]);null!=h&&ze(t,["videoMetadata"],h);const g=Ze(e,["partMetadata"]);null!=g&&ze(t,["partMetadata"],g);const v=Ze(e,["mediaProcessing"]);return null!=v&&ze(t,["mediaProcessing"],v),t}(e))),ze(t,["parts"],e)}const o=Ze(e,["role"]);return null!=o&&ze(t,["role"],o),t}(Vt(m)));const f=Ze(e,["tools"]);if(void 0!==t&&null!=f){let e=Zt(f);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==Ze(e,["retrieval"]))throw new Error("retrieval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["googleMaps"]);null!=n&&ze(t,["googleMaps"],function(e){const t={},n=Ze(e,["authConfig"]);null!=n&&ze(t,["authConfig"],function(e){const t={},n=Ze(e,["apiKey"]);if(null!=n&&ze(t,["apiKey"],n),void 0!==Ze(e,["apiKeyConfig"]))throw new Error("apiKeyConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["authType"]))throw new Error("authType parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["googleServiceAccountConfig"]))throw new Error("googleServiceAccountConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["httpBasicAuthConfig"]))throw new Error("httpBasicAuthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oauthConfig"]))throw new Error("oauthConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["oidcConfig"]))throw new Error("oidcConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["enableWidget"]);if(null!=o&&ze(t,["enableWidget"],o),void 0!==Ze(e,["groundingTypes"]))throw new Error("groundingTypes parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(n));const o=Ze(e,["mcpServers"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["mcpServers"],e)}const i=Ze(e,["codeExecution"]);null!=i&&ze(t,["codeExecution"],i);const r=Ze(e,["computerUse"]);if(null!=r&&ze(t,["computerUse"],r),void 0!==Ze(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["exaAiSearch"]))throw new Error("exaAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const s=Ze(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["functionDeclarations"],e)}const l=Ze(e,["googleSearch"]);null!=l&&ze(t,["googleSearch"],function(e){const t={};if(void 0!==Ze(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["excludeDomains"]))throw new Error("excludeDomains parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["searchTypes"]);null!=n&&ze(t,["searchTypes"],n);const o=Ze(e,["timeRangeFilter"]);return null!=o&&ze(t,["timeRangeFilter"],o),t}(l));const a=Ze(e,["googleSearchRetrieval"]);if(null!=a&&ze(t,["googleSearchRetrieval"],a),void 0!==Ze(e,["parallelAiSearch"]))throw new Error("parallelAiSearch parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const u=Ze(e,["urlContext"]);null!=u&&ze(t,["urlContext"],u);const c=Ze(e,["fileSearch"]);return null!=c&&ze(t,["fileSearch"],c),t}(zt(e)))),ze(t,["setup","tools"],e)}const h=Ze(e,["sessionResumption"]);void 0!==t&&null!=h&&ze(t,["setup","sessionResumption"],function(e){const t={},n=Ze(e,["handle"]);if(null!=n&&ze(t,["handle"],n),void 0!==Ze(e,["transparent"]))throw new Error("transparent parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");return t}(h));const g=Ze(e,["inputAudioTranscription"]);void 0!==t&&null!=g&&ze(t,["setup","inputAudioTranscription"],g);const v=Ze(e,["outputAudioTranscription"]);void 0!==t&&null!=v&&ze(t,["setup","outputAudioTranscription"],v);const _=Ze(e,["realtimeInputConfig"]);void 0!==t&&null!=_&&ze(t,["setup","realtimeInputConfig"],_);const E=Ze(e,["contextWindowCompression"]);void 0!==t&&null!=E&&ze(t,["setup","contextWindowCompression"],E);const y=Ze(e,["proactivity"]);if(void 0!==t&&null!=y&&ze(t,["setup","proactivity"],y),void 0!==Ze(e,["explicitVadSignal"]))throw new Error("explicitVadSignal parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const A=Ze(e,["avatarConfig"]);void 0!==t&&null!=A&&ze(t,["setup","avatarConfig"],A);const I=Ze(e,["safetySettings"]);if(void 0!==t&&null!=I){let e=I;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["category"]);if(null!=n&&ze(t,["category"],n),void 0!==Ze(e,["method"]))throw new Error("method parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["threshold"]);return null!=o&&ze(t,["threshold"],o),t}(e))),ze(t,["setup","safetySettings"],e)}const T=Ze(e,["translationConfig"]);return void 0!==t&&null!=T&&ze(t,["setup","generationConfig","translationConfig"],T),{}}(i,n)),n}(e,s));const l=Ze(t,["lockAdditionalFields"]);return void 0!==n&&null!=l&&ze(n,["fieldMask"],l),{}}var Ro=class extends Ke{constructor(e){super(),this.apiClient=e}async create(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("The client.tokens.create method is only supported by the Gemini Developer API.");{const s=function(e,t){const n={},o=Ze(t,["config"]);return null!=o&&ze(n,["config"],wo(e,o,n)),n}(this.apiClient,e);i=We("auth_tokens",s._url),r=s._query,delete s.config,delete s._url,delete s._query;const l=function(e,t){let n=null;const o=e.bidiGenerateContentSetup;if("object"==typeof o&&null!==o&&"setup"in o){const t=o.setup;"object"==typeof t&&null!==t?(e.bidiGenerateContentSetup=t,n=t):delete e.bidiGenerateContentSetup}else void 0!==o&&delete e.bidiGenerateContentSetup;const i=e.fieldMask;if(n){const o=function(e){const t=[];for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const o=e[n];if("object"==typeof o&&null!=o&&Object.keys(o).length>0){const e=Object.keys(o).map(e=>`${n}.${e}`);t.push(...e)}else t.push(n)}return t.join(",")}(n);if(Array.isArray(null==t?void 0:t.lockAdditionalFields)&&0===(null==t?void 0:t.lockAdditionalFields.length))o?e.fieldMask=o:delete e.fieldMask;else if((null==t?void 0:t.lockAdditionalFields)&&t.lockAdditionalFields.length>0&&null!==i&&Array.isArray(i)&&i.length>0){const t=["temperature","topK","topP","maxOutputTokens","responseModalities","seed","speechConfig"];let n=[];i.length>0&&(n=i.map(e=>t.includes(e)?`generationConfig.${e}`:e));const r=[];o&&r.push(o),n.length>0&&r.push(...n),r.length>0?e.fieldMask=r.join(","):delete e.fieldMask}else delete e.fieldMask}else null!==i&&Array.isArray(i)&&i.length>0?e.fieldMask=i.join(","):delete e.fieldMask;return e}(s,e.config);return o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(l),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()),o.then(e=>e)}}};var No=class extends Ke{constructor(e){super(),this.apiClient=e,this.list=async e=>new vn(nt.PAGED_ITEM_DOCUMENTS,t=>this.listInternal({parent:e.parent,config:t.config}),await this.listInternal(e),e)}async get(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return i=We("{name}",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>e)}}async delete(e){var t,n;let o="",i={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const r=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["_url","name"],n);const o=Ze(e,["config"]);return null!=o&&function(e,t){const n=Ze(e,["force"]);void 0!==t&&null!=n&&ze(t,["_query","force"],n)}(o,t),t}(e);o=We("{name}",r._url),i=r._query,delete r._url,delete r._query,await this.apiClient.request({path:o,queryParams:i,body:JSON.stringify(r),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 o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["parent"]);null!=n&&ze(t,["_url","parent"],n);const o=Ze(e,["config"]);return null!=o&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o)}(o,t),t}(e);return i=We("{parent}/documents",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["documents"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["documents"],e)}return t}(e),n=new At;return Object.assign(n,t),n})}}},Do=class extends Ke{constructor(e,t=new No(e)){super(),this.apiClient=e,this.documents=t,this.list=async(e={})=>new vn(nt.PAGED_ITEM_FILE_SEARCH_STORES,e=>this.listInternal(e),await this.listInternal(e),e)}async uploadToFileSearchStore(e){if(this.apiClient.isVertexAI())throw new Error("Gemini Enterprise Agent Platform (previously known as Vertex AI) does not support uploading files to a file search store.");return this.apiClient.uploadFileToFileSearchStore(e.fileSearchStoreName,e.file,e.config)}async downloadMedia(e,t){if(this.apiClient.isVertexAI())throw new Error("This method is only supported in the Gemini Developer client.");const n=new URL(e,"http://dummy.com");let o=n.pathname;if(o.startsWith("/")&&(o=o.slice(1)),!o.includes("/media/"))throw new Error(`Invalid uri format: ${e}. Expected to contain /media/`);const i={};n.searchParams.forEach((e,t)=>{i[t]=e}),i.alt="media";const r=Object.assign({},null==t?void 0:t.httpOptions),s=await this.apiClient.request({path:o,httpMethod:"GET",queryParams:i,httpOptions:r});if(s instanceof ot){const e=await s.responseInternal.arrayBuffer();return new Uint8Array(e)}throw new Error("Unexpected response type from downloadMedia")}async create(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e,t){const n={},o=Ze(t,["config"]);return null!=o&&function(e,t,n){const o=Ze(t,["displayName"]);void 0!==n&&null!=o&&ze(n,["displayName"],o);const i=Ze(t,["embeddingModel"]);void 0!==n&&null!=i&&ze(n,["embeddingModel"],Gt(e,i))}(e,o,n),n}(this.apiClient,e);return i=We("fileSearchStores",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>e)}}async get(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return i=We("{name}",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>e)}}async delete(e){var t,n;let o="",i={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const r=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["_url","name"],n);const o=Ze(e,["config"]);return null!=o&&function(e,t){const n=Ze(e,["force"]);void 0!==t&&null!=n&&ze(t,["_query","force"],n)}(o,t),t}(e);o=We("{name}",r._url),i=r._query,delete r._url,delete r._query,await this.apiClient.request({path:o,queryParams:i,body:JSON.stringify(r),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 o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o)}(n,t),t}(e);return i=We("fileSearchStores",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["fileSearchStores"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["fileSearchStores"],e)}return t}(e),n=new It;return Object.assign(n,t),n})}}async uploadToFileSearchStoreInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["fileSearchStoreName"]);null!=n&&ze(t,["_url","file_search_store_name"],n);const o=Ze(e,["config"]);return null!=o&&so(o,t),t}(e);return i=We("upload/v1beta/{file_search_store_name}:uploadToFileSearchStore",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new Tt;return Object.assign(n,t),n})}}async importFile(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["fileSearchStoreName"]);null!=n&&ze(t,["_url","file_search_store_name"],n);const o=Ze(e,["fileName"]);null!=o&&ze(t,["fileName"],o);const i=Ze(e,["config"]);return null!=i&&function(e,t){const n=Ze(e,["customMetadata"]);if(void 0!==t&&null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["customMetadata"],e)}const o=Ze(e,["chunkingConfig"]);void 0!==t&&null!=o&&ze(t,["chunkingConfig"],o)}(i,t),t}(e);return i=We("{file_search_store_name}:importFile",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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()),o.then(e=>{const t=function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["name"],n);const o=Ze(e,["metadata"]);null!=o&&ze(t,["metadata"],o);const i=Ze(e,["done"]);null!=i&&ze(t,["done"],i);const r=Ze(e,["error"]);null!=r&&ze(t,["error"],r);const s=Ze(e,["response"]);return null!=s&&ze(t,["response"],function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["parent"]);null!=o&&ze(t,["parent"],o);const i=Ze(e,["documentName"]);return null!=i&&ze(t,["documentName"],i),t}(s)),t}(e),n=new Ct;return Object.assign(n,t),n})}}},Go=void 0;function ko(){var e,t,n,o,i,r;if(Go)return Go;const s=globalThis;let l={};return l="Deno"in globalThis?null!==(o=null===(n=null===(t=null===(e=s.Deno)||void 0===e?void 0:e.env)||void 0===t?void 0:t.toObject)||void 0===n?void 0:n.call(t))&&void 0!==o?o:{}:null!==(r=null===(i=s.process)||void 0===i?void 0:i.env)&&void 0!==r?r:{},Go=l}var Mo=class{constructor(e){this.options=e}getDefaultHeaders(){return this.options.defaultHeaders}async resolveGoogleGenAISecurity(e){return function(e){var t,n;const o={};for(const[r,s]of e){const e=r.toLowerCase();"authorization"!==e&&"x-goog-api-key"!==e&&(o[r]=s)}const i={access_token:null!==(t=e.get("authorization"))&&void 0!==t?t:void 0,api_key:null!==(n=e.get("x-goog-api-key"))&&void 0!==n?n:void 0,default_headers:Object.keys(o).length?o:void 0};return jo(i)?i:void 0}(await this.options.getAuthHeaders(e))}},xo=class{beforeCreateRequest(e,t){return Object.assign(Object.assign({},t),{url:Uo(t.url)})}async beforeRequest(e,t){if(qo(t.headers,function(e){var t,n;return Fo(e)?null!==(n=null===(t=e.getDefaultHeaders)||void 0===t?void 0:t.call(e))&&void 0!==n?n:e.defaultHeaders:Ho(e)?e.default_headers:void 0}(e.security_source)),function(e,t){void 0!==e.options.user_project&&null===t.get("x-goog-user-project")&&t.set("x-goog-user-project",e.options.user_project)}(e,t.headers),null!==(n=t.headers).get("authorization")||null!==n.get("x-goog-api-key"))return t;var n;const o=await async function(e,t){if(Fo(e))return e.resolveGoogleGenAISecurity(t);const n="function"==typeof e?await e():e;return Ho(n)?Lo(n):Lo(void 0)}(e.security_source,t.url);return qo(t.headers,null==o?void 0:o.default_headers),function(e,t){var n;t&&(t.api_key?e.set("x-goog-api-key",t.api_key):t.access_token&&e.set("Authorization","bearer "===(n=t.access_token).slice(0,7).toLowerCase()?n:`Bearer ${n}`))}(t.headers,o),t}};function Uo(e){const[,t,...n]=e.pathname.split("/");if(!t)return e;const o=decodeURIComponent(t);if(!o.includes("/"))return e;const i=new URL(e);return i.pathname=`/${o}/${n.join("/")}`,i}function Lo(e){var t,n;const o=ko(),i=Object.assign(Object.assign({},e),{api_key:null!==(t=null==e?void 0:e.api_key)&&void 0!==t?t:o.GOOGLE_GENAI_API_KEY,access_token:null!==(n=null==e?void 0:e.access_token)&&void 0!==n?n:o.GOOGLE_GENAI_ACCESS_TOKEN});return jo(i)?i:void 0}function qo(e,t){if(t)for(const[n,o]of new Headers(t))null===e.get(n)&&e.set(n,o)}function Ho(e){return"object"==typeof e&&null!==e}function Fo(e){return"object"==typeof e&&null!==e&&"resolveGoogleGenAISecurity"in e&&"function"==typeof e.resolveGoogleGenAISecurity}function jo(e){return void 0!==e.api_key||void 0!==e.access_token||void 0!==e.default_headers}var Bo=class extends Error{constructor(e,t){let n=e;(null==t?void 0:t.cause)&&(n+=`: ${t.cause}`),super(n,t),this.name="HTTPClientError",void 0===this.cause&&(this.cause=null==t?void 0:t.cause)}},Vo=class extends Bo{constructor(){super(...arguments),this.name="UnexpectedClientError"}},Xo=class extends Bo{constructor(){super(...arguments),this.name="InvalidRequestError"}},Jo=class extends Bo{constructor(){super(...arguments),this.name="RequestAbortedError"}},Yo=class extends Bo{constructor(){super(...arguments),this.name="RequestTimeoutError"}},$o=class extends Bo{constructor(){super(...arguments),this.name="ConnectionError"}},Ko=class extends Error{constructor(e,t){var n,o,i,r;super(e),this.statusCode=null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status,this.body=null!==(o=null==t?void 0:t.body)&&void 0!==o?o:"",this.headers=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.headers,this.contentType=(null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.headers.get("content-type"))||"",this.rawResponse=null==t?void 0:t.response,this.name="GoogleGenAiError"}},Wo=class extends Error{},zo=class e extends Wo{constructor(t,n,o,i){super(e.makeMessage(t,n,o)),this.status=t,this.headers=i,this.error=n,this.statusCode=t,this.body=pi(n),this.contentType=(null==i?void 0:i.get("content-type"))||"",this.rawResponse=void 0,this.cause=void 0,this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}static makeMessage(e,t,n){var o;const i=t&&null!==(r=t)&&"object"==typeof r&&!Array.isArray(r)&&"string"==typeof t.message?t.message:void 0;var r;const s=pi(t);return`${e?`${e} `:""}${null!==(o=null!=i?i:n)&&void 0!==o?o:s||"An error occurred"}`}static generate(t,n,o,i){return t&&i?400===t?new ti(t,n,o,i):401===t?new ni(t,n,o,i):403===t?new oi(t,n,o,i):404===t?new ii(t,n,o,i):409===t?new ri(t,n,o,i):422===t?new si(t,n,o,i):429===t?new li(t,n,o,i):t>=500?new ai(t,n,o,i):new e(t,n,o,i):new Qo({message:o,cause:n instanceof Error?n:void 0})}},Zo=class extends zo{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}},Qo=class extends zo{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),this.cause=t}},ei=class extends Qo{constructor({message:e}={}){super({message:e||"Request timed out. This is a client-side timeout. You can increase the timeout by setting the `timeout` argument in your request or client http options."})}},ti=class extends zo{},ni=class extends zo{},oi=class extends zo{},ii=class extends zo{},ri=class extends zo{},si=class extends zo{},li=class extends zo{},ai=class extends zo{};function ui(e){return"object"==typeof(t=e)&&null!==t&&zo.prototype.isPrototypeOf(t)?e:e instanceof Ko?function(e){const t=function(e){const t=ci(e,"data$");if(t&&"object"==typeof t)return t;try{const t=JSON.parse(e.body);if(t&&"object"==typeof t)return t}catch(vr){}const n=ci(e,"error");return n&&"object"==typeof n?n:void 0}(e),n=zo.generate(e.statusCode,t,e.message,e.headers);return di(n,"body",e.body),di(n,"contentType",e.contentType),di(n,"rawResponse",e.rawResponse),di(n,"statusCode",e.statusCode),di(n,"cause",e),n}(e):e instanceof Bo?function(e){return e instanceof Yo?new ei({message:e.message}):e instanceof Jo?new Zo({message:e.message}):new Qo({message:e.message,cause:e})}(e):e;var t}function ci(e,t){return e&&"object"==typeof e?e[t]:void 0}function pi(e){if(!e)return"";try{return JSON.stringify(e)}catch(vr){return String(e)}}function di(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,value:n,writable:!1})}var mi=class{constructor(){this.sdkInitHooks=[],this.beforeCreateRequestHooks=[],this.beforeRequestHooks=[],this.afterSuccessHooks=[],this.afterErrorHooks=[];for(const e of[])"sdkInit"in e&&this.registerSDKInitHook(e),"beforeCreateRequest"in e&&this.registerBeforeCreateRequestHook(e),"beforeRequest"in e&&this.registerBeforeRequestHook(e),"afterSuccess"in e&&this.registerAfterSuccessHook(e),"afterError"in e&&this.registerAfterErrorHook(e);!function(e){const t=new xo;e.registerBeforeCreateRequestHook(t),e.registerBeforeRequestHook(t)}(this)}registerSDKInitHook(e){this.sdkInitHooks.push(e)}registerBeforeCreateRequestHook(e){this.beforeCreateRequestHooks.push(e)}registerBeforeRequestHook(e){this.beforeRequestHooks.push(e)}registerAfterSuccessHook(e){this.afterSuccessHooks.push(e)}registerAfterErrorHook(e){this.afterErrorHooks.push(e)}sdkInit(e){return this.sdkInitHooks.reduce((e,t)=>t.sdkInit(e),e)}beforeCreateRequest(e,t){let n=t;for(const o of this.beforeCreateRequestHooks)n=o.beforeCreateRequest(e,n);return n}async beforeRequest(e,t){let n=t;for(const o of this.beforeRequestHooks)n=await o.beforeRequest(e,n);return n}async afterSuccess(e,t){let n=t;for(const o of this.afterSuccessHooks)n=await o.afterSuccess(e,n);return n}async afterError(e,t,n){let o=t,i=n;for(const r of this.afterErrorHooks){const t=await r.afterError(e,o,i);o=t.response,i=t.error}return{response:o,error:i}}};function fi(e){return{ok:!0,value:e}}function hi(e){return{ok:!1,error:e}}function gi(e){return btoa(String.fromCodePoint(...e))}var vi=Object.prototype.hasOwnProperty;function _i(e,t){const n=/\{([a-zA-Z0-9_][a-zA-Z0-9_-]*?)\}/g;return function(t={}){return e.replace(n,function(e,n){if(!vi.call(t,n))throw new Error(`Parameter '${n}' is required`);const o=t[n];if("string"!=typeof o&&"number"!=typeof o)throw new Error(`Parameter '${n}' must be a string or number`);return`${o}`}).replace(/^\/+/,"")}}var Ei=["https://generativelanguage.googleapis.com"];function yi(...e){const t=[];for(const n of e)n&&t.push(n);switch(t.length){case 0:case 1:return t[0]||null;default:return"any"in AbortSignal&&"function"==typeof AbortSignal.any?AbortSignal.any(t):function(e){const t=new AbortController,n=t.signal;if(!e.length)return t.signal;if(1===e.length)return e[0]||t.signal;for(const r of e)if(r.aborted)return r;function o(){t.abort(this.reason),function(){for(const e of i){const t=e.deref();t&&t.removeEventListener("abort",o)}}()}const i=[];for(const r of e)i.push(new WeakRef(r)),r.addEventListener("abort",o);return n}(t)}}function Ai(e){const t={};for(const[n,o]of Object.entries(e))void 0!==o&&(t[n]=o);return t}function Ii(e){if(null===e||"object"!=typeof e)return!1;if("[object Object]"!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);if(null===t||t===Object.prototype)return!0;try{return null===Object.getPrototypeOf(t)}catch(vr){return!1}}var Ti=(e,t,n)=>{let o="";const i=(null==n?void 0:n.explode)?Oi(e,t):[[e,t]];if(i.every(([e,t])=>null==t))return;const r=e=>"percent"===(null==n?void 0:n.charEncoding)?encodeURIComponent(e):e,s=e=>r(bi(e)),l=r(",");return i.forEach(([e,t])=>{var n,i;let a="",u=null;null!=t&&(u=Array.isArray(t)?null===(n=wi(t,e=>`${s(e)}`))||void 0===n?void 0:n.join(l):Ii(t)?null===(i=Ri(Object.entries(t),([e,t])=>`${r(e)}${l}${s(t)}`))||void 0===i?void 0:i.join(l):`${s(t)}`,null!=u&&(a=`${r(e)}=${u}`,a&&"="!==a&&(o+=`&${a}`)))}),o.slice(1)};function Ci(e,t,n){if(void 0===t)return;const o=e=>"percent"===(null==n?void 0:n.charEncoding)?encodeURIComponent(e):e,i=o(JSON.stringify(t,Pi));return(null==n?void 0:n.explode)?i:`${o(e)}=${i}`}var Si=(e,t,n)=>{let o="";const i=(null==n?void 0:n.explode)?Oi(e,t):[[e,t]];if(i.every(([e,t])=>null==t))return;const r=e=>"percent"===(null==n?void 0:n.charEncoding)?encodeURIComponent(e):e,s=e=>r(bi(e));return i.forEach(([e,i])=>{var l;let a="";if(null!=i){if(Array.isArray(i))a=null===(l=wi(i,e=>`${s(e)}`))||void 0===l?void 0:l.join(",");else if(Ii(i)){const e=Ri(Object.entries(i),([e,t])=>`,${r(e)},${s(t)}`);a=null==e?void 0:e.join("").slice(1)}else a=`${(null==n?void 0:n.explode)&&Ii(t)?`${e}=`:""}${s(i)}`;o+=a?`,${a}`:""}}),o.slice(1)};function Oi(e,t){return Array.isArray(t)?t.map(t=>[e,t]):Ii(t)?Object.entries(null!=t?t:{}).map(([e,t])=>[e,t]):[[e,t]]}function bi(e){return null==e?"":e instanceof Date?e.toISOString():e instanceof Uint8Array?gi(e):"object"==typeof e?JSON.stringify(e,Pi):`${e}`}function Pi(e,t){return t instanceof Uint8Array?gi(t):t}function wi(e,t){const n=e.reduce((e,n)=>{if(null==n)return e;const o=t(n);return null==o||e.push(o),e},[]);return n.length?n:null}function Ri(e,t){const n=[];for(const[o,i]of e){if(null==i)continue;const e=t([o,i]);null!=e&&n.push(e)}return n.length?n:null}var Ni,Di=(Ni=Ti,function(e,t){var n,o,i;const r=Object.assign(Object.assign({},t),{explode:null===(n=null==t?void 0:t.explode)||void 0===n||n,charEncoding:null!==(o=null==t?void 0:t.charEncoding)&&void 0!==o?o:"percent"}),s=new Set(null!==(i=null==t?void 0:t.allowEmptyValue)&&void 0!==i?i:[]);return function(...e){return e.filter(Boolean).join("&")}(...Object.entries(e).map(([e,t])=>s.has(e)&&(null==t||""===t||Array.isArray(t)&&0===t.length)?`${encodeURIComponent(e)}=`:Ni(e,t,r)))}),Gi=(e,t)=>null==t?fetch(e):fetch(e,t),ki=class e{constructor(e={}){this.requestHooks=[],this.requestErrorHooks=[],this.responseHooks=[],this.options=e,this.fetcher=e.fetcher||Gi}async request(e){let t=e;for(const o of this.requestHooks){const e=await o(t);e&&(t=e)}try{const e=await this.fetcher(t);for(const n of this.responseHooks)await n(e,t);return e}catch(n){for(const e of this.requestErrorHooks)await e(n,t);throw n}}addHook(...e){if("beforeRequest"===e[0])this.requestHooks.push(e[1]);else if("requestError"===e[0])this.requestErrorHooks.push(e[1]);else{if("response"!==e[0])throw new Error(`Invalid hook type: ${e[0]}`);this.responseHooks.push(e[1])}return this}removeHook(...e){let t;if("beforeRequest"===e[0])t=this.requestHooks;else if("requestError"===e[0])t=this.requestErrorHooks;else{if("response"!==e[0])throw new Error(`Invalid hook type: ${e[0]}`);t=this.responseHooks}const n=t.findIndex(t=>t===e[1]);return n>=0&&t.splice(n,1),this}clone(){const t=new e(this.options);return t.requestHooks=this.requestHooks.slice(),t.requestErrorHooks=this.requestErrorHooks.slice(),t.responseHooks=this.responseHooks.slice(),t}},Mi=/\s*;\s*/g;function xi(e,t){var n;if("*"===t)return!0;let o=(null===(n=e.headers.get("content-type"))||void 0===n?void 0:n.trim())||"application/octet-stream";o=o.toLowerCase();const[i="",...r]=t.toLowerCase().trim().split(Mi);if(2!==i.split("/").length)return!1;const[s="",...l]=o.split(Mi),[a="",u=""]=s.split("/");if(!a||!u)return!1;if("*/*"!==i&&s!==i&&`${a}/*`!==i&&`*/${u}`!==i)return!1;if(l.length<r.length)return!1;const c=new Set(l);for(const p of r)if(!c.has(p))return!1;return!0}var Ui=/* @__PURE__ */new RegExp("^[0-9]xx$","i");function Li(e,t){const n=`${e.status}`,o=Array.isArray(t)?t:[t];return!!o.length&&o.some(e=>{const t=`${e}`;if("default"===t)return!0;if(!Ui.test(`${t}`))return t===n;const o=t.charAt(0);if(!o)throw new Error("Invalid status code range");const i=n.charAt(0);if(!i)throw new Error(`Invalid response status code: ${n}`);return i===o})}function qi(e,t,n){return Li(e,t)&&xi(e,n)}function Hi(e){if("object"!=typeof e||null==e)return!1;const t=e instanceof TypeError&&e.message.toLowerCase().startsWith("failed to fetch"),n=e instanceof TypeError&&e.message.toLowerCase().startsWith("fetch failed"),o="name"in e&&"ConnectionError"===e.name,i="code"in e&&"string"==typeof e.code&&"econnreset"===e.code.toLowerCase();return t||n||i||o}function Fi(e){if("object"!=typeof e||null==e)return!1;const t="name"in e&&"TimeoutError"===e.name,n="code"in e&&23===e.code,o="code"in e&&"string"==typeof e.code&&"econnaborted"===e.code.toLowerCase();return t||n||o}var ji={initialInterval:500,maxInterval:6e4,exponent:1.5,maxElapsedTime:36e5},Bi=class e extends Error{constructor(t,n){let o=t;(null==n?void 0:n.cause)&&(o+=`: ${n.cause}`),super(o,n),this.name="PermanentError",void 0===this.cause&&(this.cause=null==n?void 0:n.cause),Object.setPrototypeOf(this,e.prototype)}},Vi=class e extends Error{constructor(t,n){super(t),this.response=n,this.name="TemporaryError",Object.setPrototypeOf(this,e.prototype)}};function Xi(e,t){return async n=>{try{const o=await e(n);if(function(e,t){const n=`${e.status}`;return t.some(e=>{if(!Ji.test(e))return e===n;const t=e.charAt(0);if(!t)throw new Error("Invalid status code range");const o=n.charAt(0);if(!o)throw new Error(`Invalid response status code: ${n}`);return o===t})}(o,t.statusCodes))throw new Vi("Response failed with retryable status code",o);return o}catch(o){if(o instanceof Vi)throw o;if(t.retryConnectionErrors&&(Fi(o)||Hi(o)))throw o;throw new Bi("Permanent error",{cause:o})}}}var Ji=/* @__PURE__ */new RegExp("^[0-9]xx$","i");function Yi(e){const t=e.headers.get("retry-after-ms");if(t){const e=Number(t);if(Number.isFinite(e)&&e>=0)return e}const n=e.headers.get("retry-after")||"";if(!n)return 0;const o=Number(n);if(Number.isInteger(o))return 1e3*o;const i=Date.parse(n);if(Number.isInteger(i)){const e=i-Date.now();return e>0?Math.ceil(e):0}return 0}async function $i(e){return new Promise(t=>setTimeout(t,e))}var Ki="undefined"==typeof globalThis?null:globalThis,Wi="object"==typeof Ki&&null!=Ki&&"importScripts"in Ki&&"function"==typeof Ki.importScripts||"undefined"!=typeof navigator&&"serviceWorker"in navigator||"object"==typeof window&&void 0!==window.document,zi=class{constructor(e={}){const t=e;"object"==typeof t&&null!=t&&"hooks"in t&&t.hooks instanceof mi?this._hooks=t.hooks:this._hooks=new mi;const n=new ki;e.http_client=e.http_client||n;const o=function(e){var t;let n=e.server_url;if(!n){const o=null!==(t=e.server_idx)&&void 0!==t?t:0;if(o<0||o>=Ei.length)throw new Error(`Invalid server index ${o}`);n=Ei[o]||""}const o=_i(n)({});return new URL(o)}(e=this._hooks.sdkInit(e));o&&(o.pathname=o.pathname.replace(/\/+$/,"")+"/"),this._baseURL=o,this._httpClient=e.http_client||n,this._options=Object.assign(Object.assign({},function(e){var t,n;const o=Object.assign({},e),i=ko();return void 0!==i.GOOGLE_GENAI_API_VERSION&&(null!==(t=o.api_version)&&void 0!==t||(o.api_version=i.GOOGLE_GENAI_API_VERSION)),void 0!==i.GOOGLE_GENAI_USER_PROJECT&&(null!==(n=o.user_project)&&void 0!==n||(o.user_project=i.GOOGLE_GENAI_USER_PROJECT)),o}(e)),{hooks:this._hooks}),this._logger=this._options.debug_logger,!this._logger&&ko().GOOGLE_GENAI_DEBUG&&(this._logger=console)}_createRequest(e,t,n){var o,i,r,s,l;const{method:a,path:u,query:c,headers:p,security:d}=t,m=null!==(o=t.baseURL)&&void 0!==o?o:this._baseURL;if(!m)return hi(new Xo("No base URL provided for operation"));const f=new URL(m);let h;u?(f.pathname=f.pathname.replace(/\/+$/,"")+"/",h=new URL(u,f),!h.search&&f.search&&(h.search=f.search)):h=f,h.hash="";const g=e=>Object.entries(e).map(([e,t])=>{if(null==t)return;const n=Ii(t)?JSON.stringify(t):t;return Ti(e,n,{explode:Array.isArray(n),charEncoding:"percent"})}).filter(e=>void 0!==e).join("&"),v=[c||"",g((null==n?void 0:n.extra_query)||{}),g((null==d?void 0:d.queryParams)||{})].reduce((e,t)=>{if(!t)return e;const n=new Set(t.split("&").filter(e=>""!==e).map(e=>{var t;return null!==(t=e.split("=")[0])&&void 0!==t?t:""}));return[...e.split("&").filter(e=>{var t;return""!==e&&!n.has(null!==(t=e.split("=")[0])&&void 0!==t?t:"")}),t].join("&")},h.search.slice(1));v&&(h.search=`?${v}`);const _=new Headers(p),E=null==d?void 0:d.basic.username,y=null==d?void 0:d.basic.password;if(null!=E||null!=y){const e=gi(function(e){return(new TextEncoder).encode(e)}([E||"",y||""].join(":")));_.set("Authorization",`Basic ${e}`)}const A=new Headers((null==d?void 0:d.headers)||{});for(const[w,R]of A)_.set(w,R);let I=_.get("cookie")||"";for(const[w,R]of Object.entries((null==d?void 0:d.cookies)||{}))I+=`; ${w}=${R}`;I=I.startsWith("; ")?I.slice(2):I,_.set("cookie",I);const T=new Headers(null!==(i=null==n?void 0:n.headers)&&void 0!==i?i:null===(r=null==n?void 0:n.fetch_options)||void 0===r?void 0:r.headers);for(const[w,R]of T)_.set(w,R);Wi||_.set(null!==(s=t.uaHeader)&&void 0!==s?s:"user-agent",null!==(l=t.userAgent)&&void 0!==l?l:"speakeasy-sdk/typescript 2.4.1-preview.4 internal v1beta @google/genai");let C=t.body;const S=Object.fromEntries(Object.entries((null==n?void 0:n.extra_body)||{}).filter(([,e])=>void 0!==e));if(Object.keys(S).length>0){const e=new Headers(p).get("content-type")||"";if(!/^(application|text)\/([^+]+\+)*json/.test(e)||"string"!=typeof C&&null!=C)return hi(new Xo("extra_body can only be merged into JSON object request bodies"));let t;try{t=C?JSON.parse(C):{}}catch(P){return hi(new Xo("extra_body can only be merged into JSON object request bodies",{cause:P}))}if(!Ii(t))return hi(new Xo("extra_body can only be merged into JSON object request bodies"));C=JSON.stringify(Object.assign(Object.assign({},t),S)),_.delete("content-length")}const O=Object.assign(Object.assign({},null==n?void 0:n.fetch_options),n);let b;!(null==O?void 0:O.signal)&&null!=t.timeout_ms&&t.timeout_ms>0&&(e.timeout_ms=t.timeout_ms),t.body instanceof ReadableStream&&Object.assign(O,{duplex:"half"});try{b=this._hooks.beforeCreateRequest(e,{url:h,options:Object.assign(Object.assign({},O),{body:null!=C?C:null,headers:_,method:a})})}catch(P){return hi(new Vo("Create request hook failed to execute",{cause:P}))}return fi(new Request(b.url,b.options))}async _do(e,t){const{context:n,isErrorStatusCode:o}=t,i=n.timeout_ms;return async function(e,t){var n;switch(t.config.strategy){case"backoff":return async function(e,t){const{maxElapsedTime:n,initialInterval:o,exponent:i,maxInterval:r}=t,s=Date.now();let l=0;for(;;)try{return await e(l)}catch(a){if(a instanceof Bi)throw a.cause;if(Date.now()-s>n){if(a instanceof Vi)return a.response;throw a}let e=0;a instanceof Vi&&(e=Yi(a.response)),e<=0&&(e=o*Math.pow(l,i)+1e3*Math.random()),await $i(Math.min(e,r)),l++}}(Xi(e,{statusCodes:t.statusCodes,retryConnectionErrors:!!t.config.retryConnectionErrors}),null!==(n=t.config.backoff)&&void 0!==n?n:ji);case"attempt-count-backoff":return async function(e,t,n){let o=0;for(;;)try{return await e(o)}catch(i){if(i instanceof Bi)throw i.cause;if(o>=n.maxRetries){if(i instanceof Vi)return i.response;throw i}let e=0;i instanceof Vi&&(e=Yi(i.response)),e<=0&&(e=t.initialInterval*Math.pow(t.exponent,o)*(1-.25*Math.random())),await $i(Math.min(e,t.maxInterval)),o++}}(Xi(e,{statusCodes:t.statusCodes,retryConnectionErrors:!!t.config.retryConnectionErrors}),Object.assign(Object.assign({},ji),t.config.backoff),t.config);default:return await e(0)}}(async()=>{var t;const r=e.clone();let s=r;if(null!=i&&i>0){const e=AbortSignal.timeout(i),n=null!==(t=yi(r.signal,e))&&void 0!==t?t:e;s=new Request(r,{signal:n})}const l=await this._hooks.beforeRequest(n,s);await async function(e,t){if(!e)return;const n=t.headers.get("content-type"),o=(null==n?void 0:n.split(";")[0])||"";e.group(`> Request: ${t.method} ${t.url}`),e.group("Headers:");for(const[i,r]of t.headers.entries())e.log(`${i}: ${r}`);switch(e.groupEnd(),e.group("Body:"),!0){case Zi.test(o):e.log(await t.clone().json());break;case o.startsWith("text/"):e.log(await t.clone().text());break;case"multipart/form-data"===o:{const n=await t.clone().formData();for(const[t,o]of n){const n=o instanceof Blob?"<Blob>":o;e.log(`${t}: ${n}`)}break}default:e.log(`<${n}>`)}e.groupEnd(),e.groupEnd()}(this._logger,l).catch(e=>{var t;return null===(t=this._logger)||void 0===t?void 0:t.log("Failed to log request:",e)});let a=await this._httpClient.request(l);try{if(o(a.status)){const e=await this._hooks.afterError(n,a,null);if(e.error)throw e.error;a=e.response||a}else a=await this._hooks.afterSuccess(n,a)}finally{await async function(e,t,n){if(!e)return;const o=t.headers.get("content-type"),i=(null==o?void 0:o.split(";")[0])||"";e.group(`< Response: ${n.method} ${n.url}`),e.log("Status Code:",t.status,t.statusText),e.group("Headers:");for(const[r,s]of t.headers.entries())e.log(`${r}: ${s}`);switch(e.groupEnd(),e.group("Body:"),!0){case xi(t,"application/json")||Zi.test(i)&&!Qi.test(i):e.log(await t.clone().json());break;case xi(t,"application/jsonl")||Qi.test(i):case xi(t,"text/event-stream"):e.log(`<${o}>`);break;case xi(t,"text/*"):e.log(await t.clone().text());break;case xi(t,"multipart/form-data"):{const n=await t.clone().formData();for(const[t,o]of n){const n=o instanceof Blob?"<Blob>":o;e.log(`${t}: ${n}`)}break}default:e.log(`<${o}>`)}e.groupEnd(),e.groupEnd()}(this._logger,a,l).catch(e=>{var t;return null===(t=this._logger)||void 0===t?void 0:t.log("Failed to log response:",e)})}return a},{config:t.retryConfig,statusCodes:t.retryCodes}).then(e=>fi(e),e=>{switch(!0){case function(e){if("object"!=typeof e||null==e)return!1;const t="name"in e&&"AbortError"===e.name,n="code"in e&&20===e.code,o="code"in e&&"string"==typeof e.code&&"econnaborted"===e.code.toLowerCase();return t||n||o}(e):return hi(new Jo("Request aborted by client",{cause:e}));case Fi(e):return hi(new Yo("Request timed out",{cause:e}));case Hi(e):return hi(new $o("Unable to make request",{cause:e}));default:return hi(new Vo("Unexpected HTTP client error",{cause:e}))}})}},Zi=/^(application|text)\/([^+]+\+)*json.*/,Qi=/^(application|text)\/([^+]+\+)*(jsonl|x-ndjson)\b.*/,er=class extends Ko{constructor(e,t){e&&(e+=": "),e+=`Status ${t.response.status}`;const n=t.response.headers.get("content-type")||'""';"application/json"!==n&&(e+=` Content-Type ${n.includes(" ")?`"${n}"`:n}`);const o=t.body||'""';e+=o.length>100?"\n":". ";let i=o;o.length>1e4&&(i=`${o.substring(0,1e4)}...and ${o.length-1e4} more chars`),super(e=(e+=`Body: ${i}`).trim(),t),this.name="GoogleGenAiDefaultError"}};function tr(e){try{return JSON.parse(e)}catch(vr){return e}}var nr=class extends ReadableStream{constructor(e,t,n){var o;const i=e.getReader();let r=/* @__PURE__ */new Uint8Array(4096),s=0,l=0;const a={eventId:void 0},u=null===(o=null==n?void 0:n.dataRequired)||void 0===o||o;super({async pull(e){try{for(;;){const n=lr(r,s,l);if(!n){l=Math.max(0,s-sr+1);const t=await i.read();if(t.done)return e.close();if(s+t.value.length>r.length){const e=new Uint8Array(Math.max(2*r.length,s+t.value.length));e.set(r.subarray(0,s)),r=e}r.set(t.value,s),s+=t.value.length;continue}const o=r.slice(0,n.index);if(r.copyWithin(0,n.index+n.length,s),s-=n.index+n.length,r.length>4096&&s<=r.length>>2){const e=new Uint8Array(Math.max(4096,2*s));e.set(r.subarray(0,s)),r=e}l=0;const c=ar(o,t,a,u);if(c&&!c.done)return e.enqueue(c.value);if(null==c?void 0:c.done)return await i.cancel("done"),e.close()}}catch(n){e.error(n),await i.cancel(n)}},cancel:e=>i.cancel(e)})}[Symbol.asyncIterator](e){const t=ReadableStream.prototype[Symbol.asyncIterator];if("function"==typeof t)return t.call(this,e);const n=this.getReader(),o={next:async()=>{const e=await n.read();return e.done?(n.releaseLock(),{done:!0,value:void 0}):{done:!1,value:e.value}},throw:async e=>(await n.cancel(e),n.releaseLock(),{done:!0,value:void 0}),return:async()=>(await n.cancel("done"),n.releaseLock(),{done:!0,value:void 0}),[Symbol.asyncIterator](){return this}},i=Symbol.asyncDispose;return i&&(o[i]=async()=>{var e;await(null===(e=o.return)||void 0===e?void 0:e.call(o))}),o}values(e){return this[Symbol.asyncIterator](e)}},or=13,ir=10,rr=[[or,ir,or,ir],[or,ir,or],[or,ir,ir],[or,or,ir],[ir,or,ir],[or,or],[ir,or],[ir,ir]],sr=rr.reduce((e,t)=>Math.max(e,t.length),0);function lr(e,t,n){for(let o=n;o<t;o++)if(e[o]===or||e[o]===ir)for(const n of rr){if(o+n.length>t)continue;let i=!0;for(let t=0;t<n.length;t++)if(e[o+t]!==n[t]){i=!1;break}if(i)return{index:o,length:n.length}}return null}function ar(e,t,n,o){const i=(new TextDecoder).decode(e).split(/\r\n|\r|\n/),r=[],s={};let l=!0;for(const a of i){if(!a||a.startsWith(":"))continue;l=!1;const e=a.indexOf(":");let t=a,o="";e>0&&(t=a.slice(0,e),o=" "===a[e+1]?a.slice(e+2):a.slice(e+1)),"data"===t?r.push(o):"event"===t?s.event=o:"id"!==t||o.includes("\0")?"retry"===t&&/^\d+$/.test(o)&&(s.retry=Number(o)):n.eventId=o}if(!l){if(s.id=n.eventId,r.length)s.data=r.join("\n");else if(o)return;return t(s)}}var ur={jsonl:"application/jsonl",json:"application/json",text:"text/plain",bytes:"application/octet-stream",stream:"application/octet-stream",sse:"text/event-stream",nil:"*",fail:"*"};function cr(e,t,n){return Object.assign(Object.assign({},n),{err:!0,enc:"json",codes:e,errorClass:t})}function pr(e,t){return Object.assign(Object.assign({},t),{enc:"json",codes:e})}function dr(e,t,n){return Object.assign(Object.assign(Object.assign({},n),{enc:"sse",codes:e}),t?{sse:t}:{})}function mr(e){return{enc:"fail",codes:e}}function fr(...e){return async function(t,n,o){let i,r;for(const d of e){const{codes:e}=d,n="ctype"in d?d.ctype:ur[d.enc];if(n&&qi(t,e,n)){r=d;break}if(!n&&Li(t,e)){r=d;break}}if(!r)return[{ok:!1,error:new er("Unexpected Status or Content-Type",{response:t,request:n,body:await t.text().catch(()=>"")})},i];const s=r.enc;let l="";switch(s){case"json":l=await t.text();try{i=JSON.parse(l)}catch(p){if(!("err"in r))throw p;i=l}break;case"jsonl":case"stream":i=t.body;break;case"bytes":i=new Uint8Array(await t.arrayBuffer());break;case"text":case"fail":l=await t.text(),i=l;break;case"sse":if(t.body){const e="sse"in r&&r.sse||{};i=function(e,t={}){var n,o;const i=!0===t.flattened,r=null!==(n=t.sentinel)&&void 0!==n?n:"";return new nr(e,e=>""!==r&&e.data===r?{done:!0,value:void 0}:i?{done:!1,value:null==e.data?void 0:tr(e.data)}:{done:!1,value:Object.assign(Object.assign({},e),{data:null==e.data?e.data:tr(e.data)})},{dataRequired:null===(o=t.dataRequired)||void 0===o||o})}(t.body,e)}else i=null;break;case"nil":l=await t.text(),i=void 0;break;default:throw new Error(`Unsupported response type: ${s}`)}if("fail"===r.enc)return[{ok:!1,error:new er("API error occurred",{request:n,response:t,body:l})},i];const a=r.key||(null==o?void 0:o.resultKey);let u;const c=r.hdrs?{headers:gr(t.headers)}:null;return u="err"in r?Object.assign(Object.assign(Object.assign({},null==o?void 0:o.extraFields),c),Ii(i)?i:null):a?Object.assign(Object.assign(Object.assign({},null==o?void 0:o.extraFields),c),{[a]:i}):r.hdrs?Object.assign(Object.assign(Object.assign({},null==o?void 0:o.extraFields),c),Ii(i)?i:null):i,"err"in r?[{ok:!1,error:r.errorClass?new r.errorClass(u,{request:n,response:t,body:l}):u},i]:[{ok:!0,value:u},i]}}var hr=/, */;function gr(e){const t={};for(const[n,o]of e.entries())t[n]=o.split(hr);return t}var vr,_r=class e extends Error{constructor(e,t){super(t),this.code=e,this.name="SecurityError"}static incomplete(){return new e("incomplete","Security requirements not met in order to perform the operation")}static unrecognizedType(t){return new e("unrecognized_security_type",`Unrecognised security type: ${t}`)}};function Er(e,t){var n,o;return function(...e){const t={basic:{},headers:{},queryParams:{},cookies:{},oauth2:{type:"none"}},n=e.find(e=>e.every(e=>{if(null==e.value)return!1;if("http:basic"===e.type)return null!=e.value.username||null!=e.value.password;if("http:custom"===e.type)return null;if("oauth2:password"===e.type)return"string"==typeof e.value&&!!e.value;if("oauth2:client_credentials"===e.type)return"string"==typeof e.value?!!e.value:null!=e.value.client_id||null!=e.value.client_secret;if("string"==typeof e.value)return!!e.value;throw new Error(`Unrecognized security type: ${e.type} (value type: ${typeof e.value})`)}));return null==n?null:(n.forEach(e=>{if(null==e.value)return;const{type:n}=e;switch(n){case"apiKey:header":t.headers[e.fieldName]=e.value;break;case"apiKey:query":t.queryParams[e.fieldName]=e.value;break;case"apiKey:cookie":t.cookies[e.fieldName]=e.value;break;case"http:basic":!function(e,t){null!=t.value&&(e.basic=t.value)}(t,e);break;case"http:custom":case"oauth2:client_credentials":break;case"http:bearer":case"oauth2":case"oauth2:password":case"openIdConnect":!function(e,t){if("string"!=typeof t.value||!t.value)return;let n=t.value;"bearer "!==n.slice(0,7).toLowerCase()&&(n=`Bearer ${n}`),void 0!==t.fieldName&&(e.headers[t.fieldName]=n)}(t,e);break;default:throw _r.unrecognizedType(n)}}),t)}([{fieldName:"accessToken",type:"http:custom",value:null!==(n=null==e?void 0:e.access_token)&&void 0!==n?n:ko().GOOGLE_GENAI_ACCESS_TOKEN},{fieldName:"apiKey",type:"http:custom",value:null!==(o=null==e?void 0:e.api_key)&&void 0!==o?o:ko().GOOGLE_GENAI_API_KEY},{fieldName:"defaultHeaders",type:"http:custom",value:null==e?void 0:e.default_headers}])}async function yr(e){if(null!=e)return"function"==typeof e?e():e}var Ar=class e{constructor(e,t){this[vr]="APIPromise",this._promise=e instanceof Promise?e:Promise.resolve(e),this._unwrapped=e instanceof Promise?null:Promise.resolve(e[0]),this._callSource=null!=t?t:null}_getUnwrapped(){var e;return null!==(e=this._unwrapped)&&void 0!==e?e:this._unwrapped=this._promise.then(([e])=>e)}then(e,t){return this._promise.then(e?([t])=>e(t):void 0,t)}catch(e){return this._getUnwrapped().catch(e)}finally(e){return this._getUnwrapped().finally(e)}$inspect(){return this._promise}asResponse(){var e;return(null!==(e=this._callSource)&&void 0!==e?e:this._callSource=this._promise.then(([,e])=>e)).then(e=>{if(!e.response)throw new Error("APIPromise.asResponse: response unavailable");return e.response})}async withResponse(){const[[e],t]=await Promise.all([this._promise,this.asResponse()]);return{data:e,response:t}}_thenUnwrap(t){var n;const o=this._promise.then(([e,n])=>[t(e),n]);return o.catch(()=>{}),new e(o,null!==(n=this._callSource)&&void 0!==n?n:void 0)}};function Ir(e){const t=e.$inspect(),n=t.then(([e,t])=>{if(!e.ok)throw e.error;return[e.value,t]}),o=t.then(([e,t])=>{var n;if(!e.ok&&!(null===(n=t.response)||void 0===n?void 0:n.ok))throw e.error;return t});return n.catch(()=>{}),o.catch(()=>{}),new Ar(n,o)}function Tr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={body:t,api_version:n},a=Ci("body",l.body,{explode:!0}),u={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/agents")(u),p=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),d=Er(await yr(e._options.security)),m={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"CreateAgent",o_auth2_scopes:null,resolved_security:d,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},f=e._createRequest(m,{security:d,method:"POST",baseURL:null==o?void 0:o.server_url,path:c,headers:p,body:a,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!f.ok)return[f,{status:"invalid"}];const h=f.value,g=await e._do(h,{context:m,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:m.retry_config,retryCodes:m.retry_codes});if(!g.ok)return[g,{status:"request-error",request:h}];const v=g.value,[_]=await fr(mr("4XX"),mr("5XX"),pr("default"))(v,h);return _.ok,[_,{status:"complete",request:h,response:v}]}(e,t,n,o))}function Cr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/agents/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"DeleteAgent",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"DELETE",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Sr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/agents/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"GetAgent",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"GET",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Or(e,t,n,o,i,r){return new Ar(async function(e,t,n,o,i,r){var s,l,a;const u={api_version:t,page_size:n,page_token:o,parent:i},c={api_version:Si("api_version",null!==(s=null==u?void 0:u.api_version)&&void 0!==s?s:e._options.api_version,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/agents")(c),d=Di({page_size:null==u?void 0:u.page_size,page_token:null==u?void 0:u.page_token,parent:null==u?void 0:u.parent}),m=new Headers(Ai({Accept:"application/json"})),f=Er(await yr(e._options.security)),h={options:e._options,base_url:null!==(a=null!==(l=null==r?void 0:r.server_url)&&void 0!==l?l:e._baseURL)&&void 0!==a?a:"",operation_id:"ListAgents",o_auth2_scopes:null,resolved_security:f,security_source:e._options.security,retry_config:(null==r?void 0:r.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==r?void 0:r.retry_codes)||["408","409","429","5XX"]},g=e._createRequest(h,{security:f,method:"GET",baseURL:null==r?void 0:r.server_url,path:p,headers:m,query:d,body:null,userAgent:e._options.user_agent,timeout_ms:(null==r?void 0:r.timeout_ms)||e._options.timeout_ms||-1},r);if(!g.ok)return[g,{status:"invalid"}];const v=g.value,_=await e._do(v,{context:h,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:h.retry_config,retryCodes:h.retry_codes});if(!_.ok)return[_,{status:"request-error",request:v}];const E=_.value,[y]=await fr(mr("4XX"),mr("5XX"),pr("default"))(E,v);return y.ok,[y,{status:"complete",request:v,response:E}]}(e,t,n,o,i,r))}vr=Symbol.toStringTag;var br=class extends zi{list(e,t){return Ir(Or(this,null==e?void 0:e.api_version,null==e?void 0:e.page_size,null==e?void 0:e.page_token,null==e?void 0:e.parent,t))}create(e,t){const{api_version:n}=e;return Ir(Tr(this,In(e,["api_version"]),n,t))}delete(e,t,n){return Ir(Cr(this,e,null==t?void 0:t.api_version,n))}get(e,t,n){return Ir(Sr(this,e,null==t?void 0:t.api_version,n))}};function Pr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={body:t,api_version:n},a=Ci("body",l.body,{explode:!0}),u={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/environments")(u),p=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),d=Er(await yr(e._options.security)),m={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"CreateEnvironment",o_auth2_scopes:null,resolved_security:d,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},f=e._createRequest(m,{security:d,method:"POST",baseURL:null==o?void 0:o.server_url,path:c,headers:p,body:a,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!f.ok)return[f,{status:"invalid"}];const h=f.value,g=await e._do(h,{context:m,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:m.retry_config,retryCodes:m.retry_codes});if(!g.ok)return[g,{status:"request-error",request:h}];const v=g.value,[_]=await fr(mr("4XX"),mr("5XX"),pr("default"))(v,h);return _.ok,[_,{status:"complete",request:h,response:v}]}(e,t,n,o))}function wr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/environments/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"DeleteEnvironment",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"DELETE",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Rr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/environments/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"GetEnvironment",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"GET",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Nr(e,t,n,o,i){return new Ar(async function(e,t,n,o,i){var r,s,l;const a={api_version:t,page_size:n,page_token:o},u={api_version:Si("api_version",null!==(r=null==a?void 0:a.api_version)&&void 0!==r?r:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/environments")(u),p=Di({page_size:null==a?void 0:a.page_size,page_token:null==a?void 0:a.page_token}),d=new Headers(Ai({Accept:"application/json"})),m=Er(await yr(e._options.security)),f={options:e._options,base_url:null!==(l=null!==(s=null==i?void 0:i.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"ListEnvironments",o_auth2_scopes:null,resolved_security:m,security_source:e._options.security,retry_config:(null==i?void 0:i.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==i?void 0:i.retry_codes)||["408","409","429","5XX"]},h=e._createRequest(f,{security:m,method:"GET",baseURL:null==i?void 0:i.server_url,path:c,headers:d,query:p,body:null,userAgent:e._options.user_agent,timeout_ms:(null==i?void 0:i.timeout_ms)||e._options.timeout_ms||-1},i);if(!h.ok)return[h,{status:"invalid"}];const g=h.value,v=await e._do(g,{context:f,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:f.retry_config,retryCodes:f.retry_codes});if(!v.ok)return[v,{status:"request-error",request:g}];const _=v.value,[E]=await fr(mr("4XX"),mr("5XX"),pr("default"))(_,g);return E.ok,[E,{status:"complete",request:g,response:_}]}(e,t,n,o,i))}function Dr(e,t,n,o,i,r,s,l){return new Ar(async function(e,t,n,o,i,r,s,l){var a,u,c;const p={environment:t,path:n,api_version:o,page_size:i,page_token:r,recursive:s},d={api_version:Si("api_version",null!==(a=p.api_version)&&void 0!==a?a:e._options.api_version,{explode:!1,charEncoding:"percent"}),environment:Si("environment",p.environment,{explode:!1,charEncoding:"percent"}),path:Si("path",p.path,{explode:!1,charEncoding:"percent"})},m=_i("/{api_version}/environments/{environment}/files/{path}")(d),f=Di({page_size:p.page_size,page_token:p.page_token,recursive:p.recursive}),h=new Headers(Ai({Accept:"application/json"})),g=Er(await yr(e._options.security)),v={options:e._options,base_url:null!==(c=null!==(u=null==l?void 0:l.server_url)&&void 0!==u?u:e._baseURL)&&void 0!==c?c:"",operation_id:"GetEnvironmentFiles",o_auth2_scopes:null,resolved_security:g,security_source:e._options.security,retry_config:(null==l?void 0:l.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==l?void 0:l.retry_codes)||["408","409","429","5XX"]},_=e._createRequest(v,{security:g,method:"GET",baseURL:null==l?void 0:l.server_url,path:m,headers:h,query:f,body:null,userAgent:e._options.user_agent,timeout_ms:(null==l?void 0:l.timeout_ms)||e._options.timeout_ms||-1},l);if(!_.ok)return[_,{status:"invalid"}];const E=_.value,y=await e._do(E,{context:v,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:v.retry_config,retryCodes:v.retry_codes});if(!y.ok)return[y,{status:"request-error",request:E}];const A=y.value,[I]=await fr(pr(200),mr("4XX"),mr("5XX"))(A,E);return I.ok,[I,{status:"complete",request:E,response:A}]}(e,t,n,o,i,r,s,l))}var Gr=class extends zi{list(e,t,n,o){return Ir(Dr(this,e,t,null==n?void 0:n.api_version,null==n?void 0:n.page_size,null==n?void 0:n.page_token,null==n?void 0:n.recursive,o))}},kr=class extends zi{get files(){var e;return null!==(e=this._files)&&void 0!==e?e:this._files=new Gr(this._options)}listEnvironments(e,t){return Ir(Nr(this,null==e?void 0:e.api_version,null==e?void 0:e.page_size,null==e?void 0:e.page_token,t))}createEnvironment(e,t,n){return Ir(Pr(this,e,t,n))}deleteEnvironment(e,t,n){return Ir(wr(this,e,null==t?void 0:t.api_version,n))}getEnvironment(e,t,n){return Ir(Rr(this,e,null==t?void 0:t.api_version,n))}},Mr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="CancelInteractionByIdServerError"}},xr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="CancelInteractionByIdClientError"}},Ur=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="CreateInteractionServerError"}},Lr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="CreateInteractionClientError"}},qr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="DeleteInteractionServerError"}},Hr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="DeleteInteractionClientError"}},Fr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="GetInteractionByIdServerError"}},jr=class extends Ko{constructor(e,t){var n;super((null===(n=e.error)||void 0===n?void 0:n.message)||`API error occurred: ${JSON.stringify(e)}`,t),this.data$=e,this.error=e.error,this.name="GetInteractionByIdClientError"}};function Br(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/interactions/{id}/cancel")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"cancelInteractionById",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"POST",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,v={httpMeta:{response:g,request:f}},[_]=await fr(pr(200),cr("4XX",xr),cr("5XX",Mr))(g,f,{extraFields:v});return _.ok,[_,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Vr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s,l;const a={body:t,api_version:n},u=a,c=Ci("body",u.body,{explode:!0}),p={api_version:Si("api_version",null!==(i=u.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"})},d=_i("/{api_version}/interactions")(p),m=new Headers(Ai({"Content-Type":"application/json",Accept:(null===(r=null==a?void 0:a.body)||void 0===r?void 0:r.stream)?"text/event-stream":"application/json"})),f=Er(await yr(e._options.security)),h={options:e._options,base_url:null!==(l=null!==(s=null==o?void 0:o.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"CreateInteraction",o_auth2_scopes:null,resolved_security:f,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},g=e._createRequest(h,{security:f,method:"POST",baseURL:null==o?void 0:o.server_url,path:d,headers:m,body:c,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!g.ok)return[g,{status:"invalid"}];const v=g.value,_=await e._do(v,{context:h,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:h.retry_config,retryCodes:h.retry_codes});if(!_.ok)return[_,{status:"request-error",request:v}];const E=_.value,y={httpMeta:{response:E,request:v}},[A]=await fr(pr(200),dr(200,{sentinel:"[DONE]",flattened:!0}),cr("4XX",Lr),cr("5XX",Ur))(E,v,{extraFields:y});return A.ok,[A,{status:"complete",request:v,response:E}]}(e,t,n,o))}function Xr(e,t,n,o,i,r,s){return new Ar(async function(e,t,n,o,i,r,s){var l,a,u;const c={id:t,api_version:n,include_input:o,last_event_id:i,stream:r},p=c,d={api_version:Si("api_version",null!==(l=p.api_version)&&void 0!==l?l:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",p.id,{explode:!1,charEncoding:"percent"})},m=_i("/{api_version}/interactions/{id}")(d),f=Di({include_input:p.include_input,last_event_id:p.last_event_id,stream:p.stream}),h=new Headers(Ai({Accept:(null==c?void 0:c.stream)?"text/event-stream":"application/json"})),g=Er(await yr(e._options.security)),v={options:e._options,base_url:null!==(u=null!==(a=null==s?void 0:s.server_url)&&void 0!==a?a:e._baseURL)&&void 0!==u?u:"",operation_id:"getInteractionById",o_auth2_scopes:null,resolved_security:g,security_source:e._options.security,retry_config:(null==s?void 0:s.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==s?void 0:s.retry_codes)||["408","409","429","5XX"]},_=e._createRequest(v,{security:g,method:"GET",baseURL:null==s?void 0:s.server_url,path:m,headers:h,query:f,body:null,userAgent:e._options.user_agent,timeout_ms:(null==s?void 0:s.timeout_ms)||e._options.timeout_ms||-1},s);if(!_.ok)return[_,{status:"invalid"}];const E=_.value,y=await e._do(E,{context:v,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:v.retry_config,retryCodes:v.retry_codes});if(!y.ok)return[y,{status:"request-error",request:E}];const A=y.value,I={httpMeta:{response:A,request:E}},[T]=await fr(pr(200),dr(200,{sentinel:"[DONE]",flattened:!0}),cr("4XX",jr),cr("5XX",Fr))(A,E,{extraFields:I});return T.ok,[T,{status:"complete",request:E,response:A}]}(e,t,n,o,i,r,s))}var Jr=class extends zi{create(e,t){const{api_version:n}=e;return Ir(Vr(this,In(e,["api_version"]),n,t))}delete(e,t,n){return Ir(function(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/interactions/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"deleteInteraction",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"DELETE",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,v={httpMeta:{response:g,request:f}},[_]=await fr(Object.assign(Object.assign({},void 0),{enc:"nil",codes:200}),cr("4XX",Hr),cr("5XX",qr))(g,f,{extraFields:v});return _.ok,[_,{status:"complete",request:f,response:g}]}(e,t,n,o))}(this,e,null==t?void 0:t.api_version,n))}get(e,t,n){return Ir(Xr(this,e,null==t?void 0:t.api_version,null==t?void 0:t.include_input,null==t?void 0:t.last_event_id,null==t?void 0:t.stream,n))}cancel(e,t,n){return Ir(Br(this,e,null==t?void 0:t.api_version,n))}};function Yr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={body:t,api_version:n},a=Ci("body",l.body,{explode:!0}),u={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/triggers")(u),p=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),d=Er(await yr(e._options.security)),m={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"CreateTrigger",o_auth2_scopes:null,resolved_security:d,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},f=e._createRequest(m,{security:d,method:"POST",baseURL:null==o?void 0:o.server_url,path:c,headers:p,body:a,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!f.ok)return[f,{status:"invalid"}];const h=f.value,g=await e._do(h,{context:m,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:m.retry_config,retryCodes:m.retry_codes});if(!g.ok)return[g,{status:"request-error",request:h}];const v=g.value,[_]=await fr(pr(200),mr("4XX"),mr("5XX"))(v,h);return _.ok,[_,{status:"complete",request:h,response:v}]}(e,t,n,o))}function $r(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/triggers/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"DeleteTrigger",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"DELETE",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(pr(200),mr("4XX"),mr("5XX"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Kr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/triggers/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"GetTrigger",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"GET",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(pr(200),mr("4XX"),mr("5XX"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Wr(e,t,n,o,i,r){return new Ar(async function(e,t,n,o,i,r){var s,l,a;const u={trigger_id:t,api_version:n,page_size:o,page_token:i},c={api_version:Si("api_version",null!==(s=u.api_version)&&void 0!==s?s:e._options.api_version,{explode:!1,charEncoding:"percent"}),trigger_id:Si("trigger_id",u.trigger_id,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/triggers/{trigger_id}/executions")(c),d=Di({page_size:u.page_size,page_token:u.page_token}),m=new Headers(Ai({Accept:"application/json"})),f=Er(await yr(e._options.security)),h={options:e._options,base_url:null!==(a=null!==(l=null==r?void 0:r.server_url)&&void 0!==l?l:e._baseURL)&&void 0!==a?a:"",operation_id:"ListTriggerExecutions",o_auth2_scopes:null,resolved_security:f,security_source:e._options.security,retry_config:(null==r?void 0:r.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==r?void 0:r.retry_codes)||["408","409","429","5XX"]},g=e._createRequest(h,{security:f,method:"GET",baseURL:null==r?void 0:r.server_url,path:p,headers:m,query:d,body:null,userAgent:e._options.user_agent,timeout_ms:(null==r?void 0:r.timeout_ms)||e._options.timeout_ms||-1},r);if(!g.ok)return[g,{status:"invalid"}];const v=g.value,_=await e._do(v,{context:h,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:h.retry_config,retryCodes:h.retry_codes});if(!_.ok)return[_,{status:"request-error",request:v}];const E=_.value,[y]=await fr(pr(200),mr("4XX"),mr("5XX"))(E,v);return y.ok,[y,{status:"complete",request:v,response:E}]}(e,t,n,o,i,r))}function zr(e,t,n,o,i,r){return new Ar(async function(e,t,n,o,i,r){var s,l,a;const u={api_version:t,filter:n,page_size:o,page_token:i},c={api_version:Si("api_version",null!==(s=null==u?void 0:u.api_version)&&void 0!==s?s:e._options.api_version,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/triggers")(c),d=Di({filter:null==u?void 0:u.filter,page_size:null==u?void 0:u.page_size,page_token:null==u?void 0:u.page_token}),m=new Headers(Ai({Accept:"application/json"})),f=Er(await yr(e._options.security)),h={options:e._options,base_url:null!==(a=null!==(l=null==r?void 0:r.server_url)&&void 0!==l?l:e._baseURL)&&void 0!==a?a:"",operation_id:"ListTriggers",o_auth2_scopes:null,resolved_security:f,security_source:e._options.security,retry_config:(null==r?void 0:r.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==r?void 0:r.retry_codes)||["408","409","429","5XX"]},g=e._createRequest(h,{security:f,method:"GET",baseURL:null==r?void 0:r.server_url,path:p,headers:m,query:d,body:null,userAgent:e._options.user_agent,timeout_ms:(null==r?void 0:r.timeout_ms)||e._options.timeout_ms||-1},r);if(!g.ok)return[g,{status:"invalid"}];const v=g.value,_=await e._do(v,{context:h,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:h.retry_config,retryCodes:h.retry_codes});if(!_.ok)return[_,{status:"request-error",request:v}];const E=_.value,[y]=await fr(pr(200),mr("4XX"),mr("5XX"))(E,v);return y.ok,[y,{status:"complete",request:v,response:E}]}(e,t,n,o,i,r))}function Zr(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={trigger_id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),trigger_id:Si("trigger_id",l.trigger_id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/triggers/{trigger_id}/executions")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"RunTrigger",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"POST",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(pr(200),mr("4XX"),mr("5XX"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function Qr(e,t,n,o,i){return new Ar(async function(e,t,n,o,i){var r,s,l;const a={id:t,body:n,api_version:o},u=Ci("body",a.body,{explode:!0}),c={api_version:Si("api_version",null!==(r=a.api_version)&&void 0!==r?r:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",a.id,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/triggers/{id}")(c),d=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),m=Er(await yr(e._options.security)),f={options:e._options,base_url:null!==(l=null!==(s=null==i?void 0:i.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"UpdateTrigger",o_auth2_scopes:null,resolved_security:m,security_source:e._options.security,retry_config:(null==i?void 0:i.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==i?void 0:i.retry_codes)||["408","409","429","5XX"]},h=e._createRequest(f,{security:m,method:"PATCH",baseURL:null==i?void 0:i.server_url,path:p,headers:d,body:u,userAgent:e._options.user_agent,timeout_ms:(null==i?void 0:i.timeout_ms)||e._options.timeout_ms||-1},i);if(!h.ok)return[h,{status:"invalid"}];const g=h.value,v=await e._do(g,{context:f,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:f.retry_config,retryCodes:f.retry_codes});if(!v.ok)return[v,{status:"request-error",request:g}];const _=v.value,[E]=await fr(pr(200),mr("4XX"),mr("5XX"))(_,g);return E.ok,[E,{status:"complete",request:g,response:_}]}(e,t,n,o,i))}var es=class extends zi{list(e,t){return Ir(zr(this,null==e?void 0:e.api_version,null==e?void 0:e.filter,null==e?void 0:e.page_size,null==e?void 0:e.page_token,t))}create(e,t){const{api_version:n}=e;return Ir(Yr(this,In(e,["api_version"]),n,t))}delete(e,t,n){return Ir($r(this,e,null==t?void 0:t.api_version,n))}get(e,t,n){return Ir(Kr(this,e,null==t?void 0:t.api_version,n))}update(e,t,n){const{api_version:o}=t;return Ir(Qr(this,e,In(t,["api_version"]),o,n))}listExecutions(e,t,n){return Ir(Wr(this,e,null==t?void 0:t.api_version,null==t?void 0:t.page_size,null==t?void 0:t.page_token,n))}run(e,t,n){return Ir(Zr(this,e,null==t?void 0:t.api_version,n))}};function ts(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={body:t,api_version:n},a=Ci("body",l.body,{explode:!0}),u={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/webhooks")(u),p=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),d=Er(await yr(e._options.security)),m={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"CreateWebhook",o_auth2_scopes:null,resolved_security:d,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},f=e._createRequest(m,{security:d,method:"POST",baseURL:null==o?void 0:o.server_url,path:c,headers:p,body:a,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!f.ok)return[f,{status:"invalid"}];const h=f.value,g=await e._do(h,{context:m,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:m.retry_config,retryCodes:m.retry_codes});if(!g.ok)return[g,{status:"request-error",request:h}];const v=g.value,[_]=await fr(mr("4XX"),mr("5XX"),pr("default"))(v,h);return _.ok,[_,{status:"complete",request:h,response:v}]}(e,t,n,o))}function ns(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/webhooks/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"DeleteWebhook",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"DELETE",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function os(e,t,n,o){return new Ar(async function(e,t,n,o){var i,r,s;const l={id:t,api_version:n},a={api_version:Si("api_version",null!==(i=l.api_version)&&void 0!==i?i:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",l.id,{explode:!1,charEncoding:"percent"})},u=_i("/{api_version}/webhooks/{id}")(a),c=new Headers(Ai({Accept:"application/json"})),p=Er(await yr(e._options.security)),d={options:e._options,base_url:null!==(s=null!==(r=null==o?void 0:o.server_url)&&void 0!==r?r:e._baseURL)&&void 0!==s?s:"",operation_id:"GetWebhook",o_auth2_scopes:null,resolved_security:p,security_source:e._options.security,retry_config:(null==o?void 0:o.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==o?void 0:o.retry_codes)||["408","409","429","5XX"]},m=e._createRequest(d,{security:p,method:"GET",baseURL:null==o?void 0:o.server_url,path:u,headers:c,body:null,userAgent:e._options.user_agent,timeout_ms:(null==o?void 0:o.timeout_ms)||e._options.timeout_ms||-1},o);if(!m.ok)return[m,{status:"invalid"}];const f=m.value,h=await e._do(f,{context:d,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:d.retry_config,retryCodes:d.retry_codes});if(!h.ok)return[h,{status:"request-error",request:f}];const g=h.value,[v]=await fr(mr("4XX"),mr("5XX"),pr("default"))(g,f);return v.ok,[v,{status:"complete",request:f,response:g}]}(e,t,n,o))}function is(e,t,n,o,i){return new Ar(async function(e,t,n,o,i){var r,s,l;const a={api_version:t,page_size:n,page_token:o},u={api_version:Si("api_version",null!==(r=null==a?void 0:a.api_version)&&void 0!==r?r:e._options.api_version,{explode:!1,charEncoding:"percent"})},c=_i("/{api_version}/webhooks")(u),p=Di({page_size:null==a?void 0:a.page_size,page_token:null==a?void 0:a.page_token}),d=new Headers(Ai({Accept:"application/json"})),m=Er(await yr(e._options.security)),f={options:e._options,base_url:null!==(l=null!==(s=null==i?void 0:i.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"ListWebhooks",o_auth2_scopes:null,resolved_security:m,security_source:e._options.security,retry_config:(null==i?void 0:i.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==i?void 0:i.retry_codes)||["408","409","429","5XX"]},h=e._createRequest(f,{security:m,method:"GET",baseURL:null==i?void 0:i.server_url,path:c,headers:d,query:p,body:null,userAgent:e._options.user_agent,timeout_ms:(null==i?void 0:i.timeout_ms)||e._options.timeout_ms||-1},i);if(!h.ok)return[h,{status:"invalid"}];const g=h.value,v=await e._do(g,{context:f,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:f.retry_config,retryCodes:f.retry_codes});if(!v.ok)return[v,{status:"request-error",request:g}];const _=v.value,[E]=await fr(mr("4XX"),mr("5XX"),pr("default"))(_,g);return E.ok,[E,{status:"complete",request:g,response:_}]}(e,t,n,o,i))}function rs(e,t,n,o,i){return new Ar(async function(e,t,n,o,i){var r,s,l;const a={id:t,api_version:n,body:o},u=Ci("body",a.body,{explode:!0}),c={api_version:Si("api_version",null!==(r=a.api_version)&&void 0!==r?r:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",a.id,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/webhooks/{id}:ping")(c),d=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),m=Er(await yr(e._options.security)),f={options:e._options,base_url:null!==(l=null!==(s=null==i?void 0:i.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"PingWebhook",o_auth2_scopes:null,resolved_security:m,security_source:e._options.security,retry_config:(null==i?void 0:i.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==i?void 0:i.retry_codes)||["408","409","429","5XX"]},h=e._createRequest(f,{security:m,method:"POST",baseURL:null==i?void 0:i.server_url,path:p,headers:d,body:u,userAgent:e._options.user_agent,timeout_ms:(null==i?void 0:i.timeout_ms)||e._options.timeout_ms||-1},i);if(!h.ok)return[h,{status:"invalid"}];const g=h.value,v=await e._do(g,{context:f,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:f.retry_config,retryCodes:f.retry_codes});if(!v.ok)return[v,{status:"request-error",request:g}];const _=v.value,[E]=await fr(mr("4XX"),mr("5XX"),pr("default"))(_,g);return E.ok,[E,{status:"complete",request:g,response:_}]}(e,t,n,o,i))}function ss(e,t,n,o,i){return new Ar(async function(e,t,n,o,i){var r,s,l;const a={id:t,api_version:n,body:o},u=Ci("body",a.body,{explode:!0}),c={api_version:Si("api_version",null!==(r=a.api_version)&&void 0!==r?r:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",a.id,{explode:!1,charEncoding:"percent"})},p=_i("/{api_version}/webhooks/{id}:rotateSigningSecret")(c),d=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),m=Er(await yr(e._options.security)),f={options:e._options,base_url:null!==(l=null!==(s=null==i?void 0:i.server_url)&&void 0!==s?s:e._baseURL)&&void 0!==l?l:"",operation_id:"RotateSigningSecret",o_auth2_scopes:null,resolved_security:m,security_source:e._options.security,retry_config:(null==i?void 0:i.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==i?void 0:i.retry_codes)||["408","409","429","5XX"]},h=e._createRequest(f,{security:m,method:"POST",baseURL:null==i?void 0:i.server_url,path:p,headers:d,body:u,userAgent:e._options.user_agent,timeout_ms:(null==i?void 0:i.timeout_ms)||e._options.timeout_ms||-1},i);if(!h.ok)return[h,{status:"invalid"}];const g=h.value,v=await e._do(g,{context:f,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:f.retry_config,retryCodes:f.retry_codes});if(!v.ok)return[v,{status:"request-error",request:g}];const _=v.value,[E]=await fr(mr("4XX"),mr("5XX"),pr("default"))(_,g);return E.ok,[E,{status:"complete",request:g,response:_}]}(e,t,n,o,i))}function ls(e,t,n,o,i,r){return new Ar(async function(e,t,n,o,i,r){var s,l,a;const u={id:t,api_version:n,update_mask:o,body:i},c=Ci("body",u.body,{explode:!0}),p={api_version:Si("api_version",null!==(s=u.api_version)&&void 0!==s?s:e._options.api_version,{explode:!1,charEncoding:"percent"}),id:Si("id",u.id,{explode:!1,charEncoding:"percent"})},d=_i("/{api_version}/webhooks/{id}")(p),m=Di({update_mask:u.update_mask}),f=new Headers(Ai({"Content-Type":"application/json",Accept:"application/json"})),h=Er(await yr(e._options.security)),g={options:e._options,base_url:null!==(a=null!==(l=null==r?void 0:r.server_url)&&void 0!==l?l:e._baseURL)&&void 0!==a?a:"",operation_id:"UpdateWebhook",o_auth2_scopes:null,resolved_security:h,security_source:e._options.security,retry_config:(null==r?void 0:r.retries)||e._options.retry_config||{strategy:"attempt-count-backoff",backoff:{initialInterval:500,maxInterval:8e3,exponent:2,maxElapsedTime:3e4},retryConnectionErrors:!0,maxRetries:4},retry_codes:(null==r?void 0:r.retry_codes)||["408","409","429","5XX"]},v=e._createRequest(g,{security:h,method:"PATCH",baseURL:null==r?void 0:r.server_url,path:d,headers:f,query:m,body:c,userAgent:e._options.user_agent,timeout_ms:(null==r?void 0:r.timeout_ms)||e._options.timeout_ms||-1},r);if(!v.ok)return[v,{status:"invalid"}];const _=v.value,E=await e._do(_,{context:g,isErrorStatusCode:e=>Li({status:e},["4XX","5XX"]),retryConfig:g.retry_config,retryCodes:g.retry_codes});if(!E.ok)return[E,{status:"request-error",request:_}];const y=E.value,[A]=await fr(mr("4XX"),mr("5XX"),pr("default"))(y,_);return A.ok,[A,{status:"complete",request:_,response:y}]}(e,t,n,o,i,r))}var as=class extends zi{list(e,t){return Ir(is(this,null==e?void 0:e.api_version,null==e?void 0:e.page_size,null==e?void 0:e.page_token,t))}create(e,t){const{api_version:n}=e;return Ir(ts(this,In(e,["api_version"]),n,t))}delete(e,t,n){return Ir(ns(this,e,null==t?void 0:t.api_version,n))}get(e,t,n){return Ir(os(this,e,null==t?void 0:t.api_version,n))}update(e,t,n){const o=null!=t?t:{},{api_version:i,update_mask:r}=o,s=In(o,["api_version","update_mask"]);return Ir(ls(this,e,i,r,void 0===t||0===Object.keys(s).length?void 0:s,n))}ping(e,t,n,o){return Ir(rs(this,e,t,n,o))}rotateSigningSecret(e,t,n,o){return Ir(ss(this,e,t,n,o))}},us=class extends zi{get agents(){var e;return null!==(e=this._agents)&&void 0!==e?e:this._agents=new br(this._options)}get environments(){var e;return null!==(e=this._environments)&&void 0!==e?e:this._environments=new kr(this._options)}get interactions(){var e;return null!==(e=this._interactions)&&void 0!==e?e:this._interactions=new Jr(this._options)}get triggers(){var e;return null!==(e=this._triggers)&&void 0!==e?e:this._triggers=new es(this._options)}get webhooks(){var e;return null!==(e=this._webhooks)&&void 0!==e?e:this._webhooks=new as(this._options)}},cs=/* @__PURE__ */new Set(["lyria-3-pro-preview","lyria-3-clip-preview"]);function ps(e){const t=e.getBaseUrl();if(!t)throw new Error("Base URL must be set.");return t.replace(/\/+$/,"")}function ds(e){const t=e.getApiVersion().replace(/^\/+|\/+$/g,""),n=e.getProject(),o=e.getLocation();return e.isVertexAI()&&t&&n&&o?`${t}/projects/${encodeURIComponent(n)}/locations/${encodeURIComponent(o)}`:t}function ms(e,t={}){var n,o,i,r,s;return new us(Object.assign(Object.assign({},t),{api_version:null!==(n=t.api_version)&&void 0!==n?n:ds(e),security:null!==(o=t.security)&&void 0!==o?o:new Mo({defaultHeaders:Object.assign(Object.assign({},null===(i=e.getDefaultHeaders)||void 0===i?void 0:i.call(e)),null===(r=e.getHeaders)||void 0===r?void 0:r.call(e)),getAuthHeaders:t=>e.getAuthHeaders(t)}),server_url:null!==(s=t.server_url)&&void 0!==s?s:ps(e)}))}var fs=class{constructor(e){this.parentClient=e}async create(e,t){const{api_version:n}=e,o=In(e,["api_version"]);return!0===o.stream?As(await ys(()=>this.getClient(n).interactions.create(Object.assign(Object.assign({},o),{stream:!0,api_version:n}),_s(t,!0)))):Ts(await Es(Vr(this.getClient(n),o,n,_s(t))))}async get(e,t={},n){const{api_version:o,stream:i=!1,last_event_id:r,include_input:s}=null!=t?t:{};return!0===i?As(await ys(()=>this.getClient(o).interactions.get(e,{stream:i,last_event_id:r,include_input:s,api_version:o},_s(n,!0)))):Ts(await Es(Xr(this.getClient(o),e,o,s,r,i,_s(n))))}async delete(e,t={},n){return ys(()=>this.getClient(null==t?void 0:t.api_version).interactions.delete(e,{api_version:null==t?void 0:t.api_version},_s(n)))}async cancel(e,t={},n){return Ts(await Es(Br(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n))))}getClient(e){var t;return e?ms(this.parentClient,{api_version:e}):(null!==(t=this.sdk)&&void 0!==t||(this.sdk=ms(this.parentClient)),this.sdk)}},hs=class{constructor(e){this.parentClient=e}async create(e={},t){const n=null!=e?e:{},{api_version:o}=n,i=In(n,["api_version"]);return Es(Tr(this.getClient(o),i,o,_s(t)))}async list(e={},t){const{api_version:n,pageSize:o,pageToken:i,parent:r}=null!=e?e:{};return Es(Or(this.getClient(n),n,o,i,r,_s(t)))}async get(e,t={},n){return Es(Sr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}async delete(e,t={},n){return Es(Cr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}getClient(e){var t;return e?ms(this.parentClient,{api_version:e}):(null!==(t=this.sdk)&&void 0!==t||(this.sdk=ms(this.parentClient)),this.sdk)}},gs=class{constructor(e){this.parentClient=e}async create(e,t){const{api_version:n}=e,o=In(e,["api_version"]);return Es(ts(this.getClient(),o,n,_s(t)))}async list(e={},t){const{api_version:n,page_size:o,page_token:i}=null!=e?e:{};return Es(is(this.getClient(),n,o,i,_s(t)))}async get(e,t={},n){return Es(os(this.getClient(),e,null==t?void 0:t.api_version,_s(n)))}async update(e,t={},n){const o=null!=t?t:{},{api_version:i,update_mask:r}=o,s=In(o,["api_version","update_mask"]);return Es(ls(this.getClient(),e,i,r,s,_s(n)))}async delete(e,t={},n){return Es(ns(this.getClient(),e,null==t?void 0:t.api_version,_s(n)))}async rotateSigningSecret(e,t={},n){const o=null!=t?t:{},{api_version:i}=o,r=In(o,["api_version"]);return Es(ss(this.getClient(),e,i,r,_s(n)))}async ping(e,t=void 0,n){const{api_version:o,body:i}=null!=t?t:{};return Es(rs(this.getClient(),e,o,i,_s(n)))}getClient(){var e;return null!==(e=this.sdk)&&void 0!==e||(this.sdk=ms(this.parentClient)),this.sdk}},vs=class{constructor(e){this.parentClient=e}async create(e,t){const{api_version:n}=e,o=In(e,["api_version"]);return Es(Yr(this.getClient(n),o,n,_s(t)))}async list(e={},t){const{api_version:n,filter:o,pageSize:i,pageToken:r}=null!=e?e:{};return Es(zr(this.getClient(n),n,o,i,r,_s(t)))}async get(e,t={},n){return Es(Kr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}async update(e,t,n){const{api_version:o}=t,i=In(t,["api_version"]);return Es(Qr(this.getClient(o),e,i,o,_s(n)))}async delete(e,t={},n){return Es($r(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}async run(e,t={},n){return Es(Zr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}async listExecutions(e,t={},n){const{api_version:o,pageSize:i,pageToken:r}=null!=t?t:{};return Es(Wr(this.getClient(o),e,o,i,r,_s(n)))}getClient(e){var t;return e?ms(this.parentClient,{api_version:e}):(null!==(t=this.sdk)&&void 0!==t||(this.sdk=ms(this.parentClient)),this.sdk)}};function _s(e,t=!1){var n,o,i,r;if(!e&&!t)return;const s=null!=e?e:{},{timeout:l,maxRetries:a,defaultBaseURL:u,query:c,body:p,fetchOptions:d}=s,m=In(s,["timeout","maxRetries","defaultBaseURL","query","body","fetchOptions"]),f=Object.assign({},m);Cs(c)&&(f.extra_query=c),Cs(p)&&(f.extra_body=p);const h=null!==(n=m.fetch_options)&&void 0!==n?n:d;h&&(f.fetch_options=h);const g=null!==(o=m.server_url)&&void 0!==o?o:u;g&&(f.server_url=g);const v=null!==(i=m.timeout_ms)&&void 0!==i?i:l;if(void 0!==v&&(f.timeout_ms=v),void 0!==a&&(f.retries={strategy:"attempt-count-backoff",retryConnectionErrors:!0,maxRetries:a}),t){const e=new Headers(null!==(r=f.headers)&&void 0!==r?r:null==h?void 0:h.headers);e.set("Accept","text/event-stream"),f.headers=e}return f}async function Es(e){const[t,n]=await e.$inspect();if(!t.ok)throw ui(t.error);return function(e,t){return Cs(e)&&"complete"===t.status?Object.assign(Object.assign({},e),{sdkHttpResponse:Is(t.response,e)}):e}(t.value,n)}async function ys(e){try{return await e()}catch(t){throw ui(t)}}function As(e){const t=e;return new Proxy(e,{get(e,n){if(n!==Symbol.asyncIterator){const t=Reflect.get(e,n,e);return"function"==typeof t?t.bind(e):t}return function(){const e=t[Symbol.asyncIterator]();return{async next(...t){try{return await e.next(...t)}catch(n){throw ui(n)}},async return(t){if(!e.return)return{done:!0,value:t};try{return await e.return(t)}catch(n){throw ui(n)}},async throw(t){if(!e.throw)throw ui(t);try{return await e.throw(t)}catch(n){throw ui(n)}},[Symbol.asyncIterator](){return this}}}}})}function Is(e,t){const n={};for(const[o,i]of e.headers.entries())n[o]=i;return{headers:n,responseInternal:e,json:async()=>t}}function Ts(e){const t=function(e){if(Cs(e)){if(Array.isArray(e.steps))return e;if(function(e){const t=e.model;return"string"==typeof t&&cs.has(t)}(e)){const t=e.outputs;if(Array.isArray(t)){const{outputs:n}=e,o=In(e,["outputs"]);return Object.assign(Object.assign({},o),{steps:[{type:"model_output",content:t}]})}}return Object.assign(Object.assign({},e),{steps:[]})}}(e);return t?function(e){var t,n;const o=function(e){return Object.assign(Object.assign({},e),{created:Ss(e.created),updated:Ss(e.updated)})}(e),i=null!==(t=o.steps)&&void 0!==t?t:[],r=[];let s,l,a,u=!1;e:for(let p=i.length-1;p>=0;p--){const e=i[p];if("user_input"===e.type)break;if("model_output"!==e.type||!e.content){if(u)break;continue}const t=e.content;for(let o=t.length-1;o>=0;o--){const e=t[o];if("text"===e.type)u=!0,r.push(null!==(n=e.text)&&void 0!==n?n:"");else if(u)break e}}for(let p=i.length-1;p>=0;p--){const e=i[p];if("user_input"===e.type)break;if("model_output"===e.type&&e.content)for(let t=e.content.length-1;t>=0;t--){const n=e.content[t];"image"!==n.type||s||(s=n),"audio"!==n.type||l||(l=n),"video"!==n.type||a||(a=n)}}const c=r.reverse().join("");return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},o),c&&{output_text:c}),s?{output_image:s}:{}),l?{output_audio:l}:{}),a?{output_video:a}:{})}(t):e}function Cs(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Ss(e){return e instanceof Date?e.toISOString():e}var Os=class{constructor(e){this.resolveClient=e}async list(e,t){const{environment:n,path:o,page_size:i,page_token:r,recursive:s,api_version:l}=e;return Es(Dr(this.resolveClient(l),n,o,l,i,r,s,_s(t)))}},bs=class{constructor(e){this.parentClient=e,this.files=new Os(e=>this.getClient(e))}async create(e,t){const{api_version:n}=e,o=In(e,["api_version"]);return Es(Pr(this.getClient(n),o,n,_s(t)))}async list(e={},t){const{api_version:n,page_size:o,page_token:i}=null!=e?e:{};return Es(Nr(this.getClient(n),n,o,i,_s(t)))}async get(e,t={},n){return Es(Rr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}async delete(e,t={},n){return Es(wr(this.getClient(null==t?void 0:t.api_version),e,null==t?void 0:t.api_version,_s(n)))}getClient(e){var t;return e?ms(this.parentClient,{api_version:e}):(null!==(t=this.sdk)&&void 0!==t||(this.sdk=ms(this.parentClient)),this.sdk)}};function Ps(e,t){const n={},o=Ze(e,["parts"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=Ze(e,["mediaResolution"]);if(null!=n&&ze(t,["mediaResolution"],n),void 0!==Ze(e,["toolCall"]))throw new Error("toolCall parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");if(void 0!==Ze(e,["toolResponse"]))throw new Error("toolResponse parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const o=Ze(e,["audioTranscription"]);null!=o&&ze(t,["audioTranscription"],o);const i=Ze(e,["codeExecutionResult"]);null!=i&&ze(t,["codeExecutionResult"],i);const r=Ze(e,["executableCode"]);null!=r&&ze(t,["executableCode"],r);const s=Ze(e,["fileData"]);null!=s&&ze(t,["fileData"],s);const l=Ze(e,["functionCall"]);null!=l&&ze(t,["functionCall"],l);const a=Ze(e,["functionResponse"]);null!=a&&ze(t,["functionResponse"],a);const u=Ze(e,["inlineData"]);null!=u&&ze(t,["inlineData"],u);const c=Ze(e,["text"]);null!=c&&ze(t,["text"],c);const p=Ze(e,["thought"]);null!=p&&ze(t,["thought"],p);const d=Ze(e,["thoughtSignature"]);null!=d&&ze(t,["thoughtSignature"],d);const m=Ze(e,["videoMetadata"]);if(null!=m&&ze(t,["videoMetadata"],m),void 0!==Ze(e,["partMetadata"]))throw new Error("partMetadata parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.");const f=Ze(e,["mediaProcessing"]);return null!=f&&ze(t,["mediaProcessing"],f),t}(e))),ze(n,["parts"],e)}const i=Ze(e,["role"]);return null!=i&&ze(n,["role"],i),n}function ws(e,t){const n={},o=Ze(e,["epochCount"]);null!=o&&ze(n,["epochCount"],o);const i=Ze(e,["learningRateMultiplier"]);null!=i&&ze(n,["learningRateMultiplier"],i);const r=Ze(e,["adapterSize"]);null!=r&&ze(n,["adapterSize"],r);const s=Ze(e,["batchSize"]);null!=s&&ze(n,["batchSize"],s);const l=Ze(e,["learningRate"]);null!=l&&ze(n,["learningRate"],l);const a=Ze(e,["generationConfig"]);return null!=a&&ze(n,["generationConfig"],function(e){const t={},n=Ze(e,["modelConfig"]);null!=n&&ze(t,["modelSelectionConfig"],n);const o=Ze(e,["responseJsonSchema"]);null!=o&&ze(t,["responseJsonSchema"],o);const i=Ze(e,["audioTranscriptionConfig"]);null!=i&&ze(t,["audioTranscriptionConfig"],i);const r=Ze(e,["audioTimestamp"]);null!=r&&ze(t,["audioTimestamp"],r);const s=Ze(e,["candidateCount"]);null!=s&&ze(t,["candidateCount"],s);const l=Ze(e,["enableAffectiveDialog"]);null!=l&&ze(t,["enableAffectiveDialog"],l);const a=Ze(e,["frequencyPenalty"]);null!=a&&ze(t,["frequencyPenalty"],a);const u=Ze(e,["logprobs"]);null!=u&&ze(t,["logprobs"],u);const c=Ze(e,["maxOutputTokens"]);null!=c&&ze(t,["maxOutputTokens"],c);const p=Ze(e,["mediaResolution"]);null!=p&&ze(t,["mediaResolution"],p);const d=Ze(e,["presencePenalty"]);null!=d&&ze(t,["presencePenalty"],d);const m=Ze(e,["responseFormat"]);if(null!=m){let e=m;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["responseFormat"],e)}const f=Ze(e,["responseLogprobs"]);null!=f&&ze(t,["responseLogprobs"],f);const h=Ze(e,["responseMimeType"]);null!=h&&ze(t,["responseMimeType"],h);const g=Ze(e,["responseModalities"]);null!=g&&ze(t,["responseModalities"],g);const v=Ze(e,["responseSchema"]);null!=v&&ze(t,["responseSchema"],v);const _=Ze(e,["routingConfig"]);null!=_&&ze(t,["routingConfig"],_);const E=Ze(e,["seed"]);null!=E&&ze(t,["seed"],E);const y=Ze(e,["speechConfig"]);null!=y&&ze(t,["speechConfig"],y);const A=Ze(e,["stopSequences"]);null!=A&&ze(t,["stopSequences"],A);const I=Ze(e,["temperature"]);null!=I&&ze(t,["temperature"],I);const T=Ze(e,["thinkingConfig"]);null!=T&&ze(t,["thinkingConfig"],T);const C=Ze(e,["topK"]);null!=C&&ze(t,["topK"],C);const S=Ze(e,["topP"]);return null!=S&&ze(t,["topP"],S),t}(a)),n}function Rs(e,t){const n={},o=Ze(e,["sdkHttpResponse"]);null!=o&&ze(n,["sdkHttpResponse"],o);const i=Ze(e,["name"]);null!=i&&ze(n,["name"],i);const r=Ze(e,["state"]);null!=r&&ze(n,["state"],en(r));const s=Ze(e,["createTime"]);null!=s&&ze(n,["createTime"],s);const l=Ze(e,["startTime"]);null!=l&&ze(n,["startTime"],l);const a=Ze(e,["endTime"]);null!=a&&ze(n,["endTime"],a);const u=Ze(e,["updateTime"]);null!=u&&ze(n,["updateTime"],u);const c=Ze(e,["error"]);null!=c&&ze(n,["error"],c);const p=Ze(e,["description"]);null!=p&&ze(n,["description"],p);const d=Ze(e,["baseModel"]);null!=d&&ze(n,["baseModel"],d);const m=Ze(e,["tunedModel"]);null!=m&&ze(n,["tunedModel"],m);const f=Ze(e,["preTunedModel"]);null!=f&&ze(n,["preTunedModel"],f);const h=Ze(e,["supervisedTuningSpec"]);null!=h&&ze(n,["supervisedTuningSpec"],h);const g=Ze(e,["preferenceOptimizationSpec"]);null!=g&&ze(n,["preferenceOptimizationSpec"],g);const v=Ze(e,["distillationSamplingSpec"]);null!=v&&ze(n,["distillationSamplingSpec"],function(e){const t={},n=Ze(e,["promptDatasetUri"]);null!=n&&ze(t,["promptDatasetUri"],n);const o=Ze(e,["validationDatasetUri"]);null!=o&&ze(t,["validationDatasetUri"],o);const i=Ze(e,["baseTeacherModel"]);null!=i&&ze(t,["baseTeacherModel"],i);const r=Ze(e,["tunedTeacherModelSource"]);null!=r&&ze(t,["tunedTeacherModelSource"],r);const s=Ze(e,["hyperparameters"]);return null!=s&&ze(t,["hyperparameters"],ws(s)),t}(v));const _=Ze(e,["distillationSpec"]);null!=_&&ze(n,["distillationSpec"],function(e){const t={},n=Ze(e,["baseTeacherModel"]);null!=n&&ze(t,["baseTeacherModel"],n);const o=Ze(e,["hyperParameters"]);null!=o&&ze(t,["hyperParameters"],ws(o));const i=Ze(e,["pipelineRootDirectory"]);null!=i&&ze(t,["pipelineRootDirectory"],i);const r=Ze(e,["promptDatasetUri"]);null!=r&&ze(t,["promptDatasetUri"],r);const s=Ze(e,["studentModel"]);null!=s&&ze(t,["studentModel"],s);const l=Ze(e,["trainingDatasetUri"]);null!=l&&ze(t,["trainingDatasetUri"],l);const a=Ze(e,["tunedTeacherModelSource"]);null!=a&&ze(t,["tunedTeacherModelSource"],a);const u=Ze(e,["tuningMode"]);null!=u&&ze(t,["tuningMode"],u);const c=Ze(e,["validationDatasetUri"]);return null!=c&&ze(t,["validationDatasetUri"],c),t}(_));const E=Ze(e,["reinforcementTuningSpec"]);null!=E&&ze(n,["reinforcementTuningSpec"],E);const y=Ze(e,["tuningDataStats"]);null!=y&&ze(n,["tuningDataStats"],y);const A=Ze(e,["encryptionSpec"]);null!=A&&ze(n,["encryptionSpec"],A);const I=Ze(e,["partnerModelTuningSpec"]);null!=I&&ze(n,["partnerModelTuningSpec"],I);const T=Ze(e,["customBaseModel"]);null!=T&&ze(n,["customBaseModel"],T);const C=Ze(e,["evaluateDatasetRuns"]);if(null!=C){let e=C;Array.isArray(e)&&(e=e.map(e=>e)),ze(n,["evaluateDatasetRuns"],e)}const S=Ze(e,["experiment"]);null!=S&&ze(n,["experiment"],S);const O=Ze(e,["fullFineTuningSpec"]);null!=O&&ze(n,["fullFineTuningSpec"],O);const b=Ze(e,["labels"]);null!=b&&ze(n,["labels"],b);const P=Ze(e,["outputUri"]);null!=P&&ze(n,["outputUri"],P);const w=Ze(e,["pipelineJob"]);null!=w&&ze(n,["pipelineJob"],w);const R=Ze(e,["serviceAccount"]);null!=R&&ze(n,["serviceAccount"],R);const N=Ze(e,["tunedModelDisplayName"]);null!=N&&ze(n,["tunedModelDisplayName"],N);const D=Ze(e,["tuningJobMetadata"]);null!=D&&ze(n,["tuningJobMetadata"],D);const G=Ze(e,["tuningJobState"]);null!=G&&ze(n,["tuningJobState"],G);const k=Ze(e,["veoLoraTuningSpec"]);null!=k&&ze(n,["veoLoraTuningSpec"],k);const M=Ze(e,["veoTuningSpec"]);return null!=M&&ze(n,["veoTuningSpec"],M),n}function Ns(e,t){const n={},o=Ze(e,["gcsUri"]);null!=o&&ze(n,["validationDatasetUri"],o);const i=Ze(e,["vertexDatasetResource"]);return null!=i&&ze(n,["validationDatasetUri"],i),n}var Ds=class extends Ke{constructor(e){super(),this.apiClient=e,this.list=async(e={})=>new vn(nt.PAGED_ITEM_TUNING_JOBS,e=>this.listInternal(e),await this.listInternal(e),e),this.get=async e=>await this.getInternal(e),this.tune=async e=>{var t;if(this.apiClient.isVertexAI()){if(e.baseModel.startsWith("projects/")){const n={tunedModelName:e.baseModel};(null===(t=e.config)||void 0===t?void 0:t.preTunedModelCheckpointId)&&(n.checkpointId=e.config.preTunedModelCheckpointId);const o=Object.assign(Object.assign({},e),{preTunedModel:n});return o.baseModel=void 0,await this.tuneInternal(o)}{const t=Object.assign({},e);return await this.tuneInternal(t)}}{const t=Object.assign({},e),n=await this.tuneMldevInternal(t);let o="";return void 0!==n.metadata&&void 0!==n.metadata.tunedModel?o=n.metadata.tunedModel:void 0!==n.name&&n.name.includes("/operations/")&&(o=n.name.split("/operations/")[0]),{name:o,state:oe.JOB_STATE_QUEUED}}}}async getInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return s=We("{name}",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>Rs(e))}{const t=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return s=We("{name}",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"GET",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["name"]);null!=o&&ze(t,["name"],o);const i=Ze(e,["state"]);null!=i&&ze(t,["state"],en(i));const r=Ze(e,["createTime"]);null!=r&&ze(t,["createTime"],r);const s=Ze(e,["tuningTask","startTime"]);null!=s&&ze(t,["startTime"],s);const l=Ze(e,["tuningTask","completeTime"]);null!=l&&ze(t,["endTime"],l);const a=Ze(e,["updateTime"]);null!=a&&ze(t,["updateTime"],a);const u=Ze(e,["description"]);null!=u&&ze(t,["description"],u);const c=Ze(e,["baseModel"]);null!=c&&ze(t,["baseModel"],c);const p=Ze(e,["_self"]);return null!=p&&ze(t,["tunedModel"],function(e){const t={},n=Ze(e,["name"]);null!=n&&ze(t,["model"],n);const o=Ze(e,["name"]);return null!=o&&ze(t,["endpoint"],o),t}(p)),t}(e))}}async listInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e){const t={},n=Ze(e,["config"]);return null!=n&&function(e,t){const n=Ze(e,["pageSize"]);void 0!==t&&null!=n&&ze(t,["_query","pageSize"],n);const o=Ze(e,["pageToken"]);void 0!==t&&null!=o&&ze(t,["_query","pageToken"],o);const i=Ze(e,["filter"]);void 0!==t&&null!=i&&ze(t,["_query","filter"],i)}(n,t),t}(e);return i=We("tuningJobs",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["nextPageToken"]);null!=o&&ze(t,["nextPageToken"],o);const i=Ze(e,["tuningJobs"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>Rs(e))),ze(t,["tuningJobs"],e)}return t}(e),n=new gt;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async cancel(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return s=We("{name}:cancel",o._url),l=o._query,delete o._url,delete o._query,r=this.apiClient.request({path:s,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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new vt;return Object.assign(n,t),n})}{const t=function(e){const t={},n=Ze(e,["name"]);return null!=n&&ze(t,["_url","name"],n),t}(e);return s=We("{name}:cancel",t._url),l=t._query,delete t._url,delete t._query,r=this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(t),httpMethod:"POST",httpOptions:null===(o=e.config)||void 0===o?void 0:o.httpOptions,abortSignal:null===(i=e.config)||void 0===i?void 0:i.abortSignal}).then(e=>e.json().then(t=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),r.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);return null!=n&&ze(t,["sdkHttpResponse"],n),t}(e),n=new vt;return Object.assign(n,t),n})}}async tuneInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e,t){const n={},o=Ze(e,["baseModel"]);null!=o&&ze(n,["baseModel"],o);const i=Ze(e,["preTunedModel"]);null!=i&&ze(n,["preTunedModel"],i);const r=Ze(e,["trainingDataset"]);null!=r&&function(e,t,n){let o=Ze(n,["config","method"]);if(void 0===o&&(o="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===o){const n=Ze(e,["gcsUri"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","trainingDatasetUri"],n)}else if("PREFERENCE_TUNING"===o){const n=Ze(e,["gcsUri"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","trainingDatasetUri"],n)}else if("DISTILLATION"===o){const n=Ze(e,["gcsUri"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","promptDatasetUri"],n)}else if("REINFORCEMENT_TUNING"===o){const n=Ze(e,["gcsUri"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","trainingDatasetUri"],n)}let i=Ze(n,["config","method"]);if(void 0===i&&(i="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===i){const n=Ze(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","trainingDatasetUri"],n)}else if("PREFERENCE_TUNING"===i){const n=Ze(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","trainingDatasetUri"],n)}else if("DISTILLATION"===i){const n=Ze(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","promptDatasetUri"],n)}else if("REINFORCEMENT_TUNING"===i){const n=Ze(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","trainingDatasetUri"],n)}if(void 0!==Ze(e,["examples"]))throw new Error("examples parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.")}(r,n,t);const s=Ze(e,["config"]);return null!=s&&function(e,t,n){let o=Ze(n,["config","method"]);if(void 0===o&&(o="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===o){const n=Ze(e,["validationDataset"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec"],Ns(n))}else if("PREFERENCE_TUNING"===o){const n=Ze(e,["validationDataset"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec"],Ns(n))}else if("DISTILLATION"===o){const n=Ze(e,["validationDataset"]);void 0!==t&&null!=n&&ze(t,["distillationSpec"],Ns(n))}else if("REINFORCEMENT_TUNING"===o){const n=Ze(e,["validationDataset"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec"],Ns(n))}const i=Ze(e,["tunedModelDisplayName"]);void 0!==t&&null!=i&&ze(t,["tunedModelDisplayName"],i);const r=Ze(e,["description"]);void 0!==t&&null!=r&&ze(t,["description"],r);let s=Ze(n,["config","method"]);if(void 0===s&&(s="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===s){const n=Ze(e,["epochCount"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","hyperParameters","epochCount"],n)}else if("PREFERENCE_TUNING"===s){const n=Ze(e,["epochCount"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","hyperParameters","epochCount"],n)}else if("DISTILLATION"===s){const n=Ze(e,["epochCount"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","hyperParameters","epochCount"],n)}else if("REINFORCEMENT_TUNING"===s){const n=Ze(e,["epochCount"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","hyperParameters","epochCount"],n)}let l=Ze(n,["config","method"]);if(void 0===l&&(l="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===l){const n=Ze(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","hyperParameters","learningRateMultiplier"],n)}else if("PREFERENCE_TUNING"===l){const n=Ze(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","hyperParameters","learningRateMultiplier"],n)}else if("DISTILLATION"===l){const n=Ze(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","hyperParameters","learningRateMultiplier"],n)}else if("REINFORCEMENT_TUNING"===l){const n=Ze(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","hyperParameters","learningRateMultiplier"],n)}let a=Ze(n,["config","method"]);if(void 0===a&&(a="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===a){const n=Ze(e,["exportLastCheckpointOnly"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","exportLastCheckpointOnly"],n)}else if("PREFERENCE_TUNING"===a){const n=Ze(e,["exportLastCheckpointOnly"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","exportLastCheckpointOnly"],n)}else if("DISTILLATION"===a){const n=Ze(e,["exportLastCheckpointOnly"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","exportLastCheckpointOnly"],n)}let u=Ze(n,["config","method"]);if(void 0===u&&(u="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===u){const n=Ze(e,["adapterSize"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","hyperParameters","adapterSize"],n)}else if("PREFERENCE_TUNING"===u){const n=Ze(e,["adapterSize"]);void 0!==t&&null!=n&&ze(t,["preferenceOptimizationSpec","hyperParameters","adapterSize"],n)}else if("DISTILLATION"===u){const n=Ze(e,["adapterSize"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","hyperParameters","adapterSize"],n)}else if("REINFORCEMENT_TUNING"===u){const n=Ze(e,["adapterSize"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","hyperParameters","adapterSize"],n)}let c=Ze(n,["config","method"]);if(void 0===c&&(c="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===c){const n=Ze(e,["tuningMode"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","tuningMode"],n)}else if("DISTILLATION"===c){const n=Ze(e,["tuningMode"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","tuningMode"],n)}const p=Ze(e,["customBaseModel"]);void 0!==t&&null!=p&&ze(t,["customBaseModel"],p);let d=Ze(n,["config","method"]);if(void 0===d&&(d="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===d){const n=Ze(e,["batchSize"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","hyperParameters","batchSize"],n)}else if("DISTILLATION"===d){const n=Ze(e,["batchSize"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","hyperParameters","batchSize"],n)}else if("REINFORCEMENT_TUNING"===d){const n=Ze(e,["batchSize"]);void 0!==t&&null!=n&&ze(t,["reinforcementTuningSpec","hyperParameters","batchSize"],n)}let m=Ze(n,["config","method"]);if(void 0===m&&(m="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===m){const n=Ze(e,["learningRate"]);void 0!==t&&null!=n&&ze(t,["supervisedTuningSpec","hyperParameters","learningRate"],n)}else if("DISTILLATION"===m){const n=Ze(e,["learningRate"]);void 0!==t&&null!=n&&ze(t,["distillationSpec","hyperParameters","learningRate"],n)}const f=Ze(e,["labels"]);void 0!==t&&null!=f&&ze(t,["labels"],f);const h=Ze(e,["beta"]);void 0!==t&&null!=h&&ze(t,["preferenceOptimizationSpec","hyperParameters","beta"],h);const g=Ze(e,["baseTeacherModel"]);void 0!==t&&null!=g&&ze(t,["distillationSpec","baseTeacherModel"],g);const v=Ze(e,["tunedTeacherModelSource"]);void 0!==t&&null!=v&&ze(t,["distillationSpec","tunedTeacherModelSource"],v);const _=Ze(e,["sftLossWeightMultiplier"]);void 0!==t&&null!=_&&ze(t,["distillationSpec","hyperParameters","sftLossWeightMultiplier"],_);const E=Ze(e,["outputUri"]);void 0!==t&&null!=E&&ze(t,["outputUri"],E);const y=Ze(e,["rewardConfig"]);void 0!==t&&null!=y&&ze(t,["reinforcementTuningSpec","singleRewardConfig"],y);const A=Ze(e,["compositeRewardConfig"]);void 0!==t&&null!=A&&ze(t,["reinforcementTuningSpec","compositeRewardConfig"],A);const I=Ze(e,["samplesPerPrompt"]);void 0!==t&&null!=I&&ze(t,["reinforcementTuningSpec","hyperParameters","samplesPerPrompt"],I);const T=Ze(e,["evaluateInterval"]);void 0!==t&&null!=T&&ze(t,["reinforcementTuningSpec","hyperParameters","evaluateInterval"],T);const C=Ze(e,["checkpointInterval"]);void 0!==t&&null!=C&&ze(t,["reinforcementTuningSpec","hyperParameters","checkpointInterval"],C);const S=Ze(e,["maxOutputTokens"]);void 0!==t&&null!=S&&ze(t,["reinforcementTuningSpec","hyperParameters","maxOutputTokens"],S);const O=Ze(e,["thinkingLevel"]);void 0!==t&&null!=O&&ze(t,["reinforcementTuningSpec","hyperParameters","thinkingLevel"],O);const b=Ze(e,["validationDatasetUri"]);void 0!==t&&null!=b&&ze(t,["reinforcementTuningSpec","validationDatasetUri"],b);const P=Ze(e,["encryptionSpec"]);void 0!==t&&null!=P&&ze(t,["encryptionSpec"],P)}(s,n,t),n}(e,e);return i=We("tuningJobs",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>Rs(e))}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async tuneMldevInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=function(e){const t={},n=Ze(e,["baseModel"]);null!=n&&ze(t,["baseModel"],n);const o=Ze(e,["preTunedModel"]);null!=o&&ze(t,["preTunedModel"],o);const i=Ze(e,["trainingDataset"]);null!=i&&function(e){const t={};if(void 0!==Ze(e,["gcsUri"]))throw new Error("gcsUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["vertexDatasetResource"]))throw new Error("vertexDatasetResource parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["examples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ze(t,["examples","examples"],e)}}(i);const r=Ze(e,["config"]);return null!=r&&function(e,t){if(void 0!==Ze(e,["validationDataset"]))throw new Error("validationDataset parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const n=Ze(e,["tunedModelDisplayName"]);if(void 0!==t&&null!=n&&ze(t,["displayName"],n),void 0!==Ze(e,["description"]))throw new Error("description parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const o=Ze(e,["epochCount"]);void 0!==t&&null!=o&&ze(t,["tuningTask","hyperparameters","epochCount"],o);const i=Ze(e,["learningRateMultiplier"]);if(null!=i&&ze({},["tuningTask","hyperparameters","learningRateMultiplier"],i),void 0!==Ze(e,["exportLastCheckpointOnly"]))throw new Error("exportLastCheckpointOnly parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["preTunedModelCheckpointId"]))throw new Error("preTunedModelCheckpointId parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["adapterSize"]))throw new Error("adapterSize parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["tuningMode"]))throw new Error("tuningMode parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["customBaseModel"]))throw new Error("customBaseModel parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");const r=Ze(e,["batchSize"]);void 0!==t&&null!=r&&ze(t,["tuningTask","hyperparameters","batchSize"],r);const s=Ze(e,["learningRate"]);if(void 0!==t&&null!=s&&ze(t,["tuningTask","hyperparameters","learningRate"],s),void 0!==Ze(e,["labels"]))throw new Error("labels parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["beta"]))throw new Error("beta parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["baseTeacherModel"]))throw new Error("baseTeacherModel parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["tunedTeacherModelSource"]))throw new Error("tunedTeacherModelSource parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["sftLossWeightMultiplier"]))throw new Error("sftLossWeightMultiplier parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["outputUri"]))throw new Error("outputUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["rewardConfig"]))throw new Error("rewardConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["compositeRewardConfig"]))throw new Error("compositeRewardConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["samplesPerPrompt"]))throw new Error("samplesPerPrompt parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["evaluateInterval"]))throw new Error("evaluateInterval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["checkpointInterval"]))throw new Error("checkpointInterval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["maxOutputTokens"]))throw new Error("maxOutputTokens parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["thinkingLevel"]))throw new Error("thinkingLevel parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["validationDatasetUri"]))throw new Error("validationDatasetUri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.");if(void 0!==Ze(e,["encryptionSpec"]))throw new Error("encryptionSpec parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.")}(r,t),t}(e);return i=We("tunedModels",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["name"]);null!=o&&ze(t,["name"],o);const i=Ze(e,["metadata"]);null!=i&&ze(t,["metadata"],i);const r=Ze(e,["done"]);null!=r&&ze(t,["done"],r);const s=Ze(e,["error"]);return null!=s&&ze(t,["error"],s),t}(e))}}async validateReward(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=function(e){const t={},n=Ze(e,["parent"]);null!=n&&ze(t,["_url","parent"],n);const o=Ze(e,["sampleResponse"]);null!=o&&ze(t,["sampleResponse"],Ps(o));const i=Ze(e,["example"]);null!=i&&ze(t,["example"],function(e){const t={},n=Ze(e,["references"]);null!=n&&ze(t,["references"],n);const o=Ze(e,["contents"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>Ps(e))),ze(t,["contents"],e)}const i=Ze(e,["systemInstruction"]);return null!=i&&ze(t,["systemInstruction"],Ps(i)),t}(i));const r=Ze(e,["singleRewardConfig"]);null!=r&&ze(t,["singleRewardConfig"],r);const s=Ze(e,["compositeRewardConfig"]);return null!=s&&ze(t,["compositeRewardConfig"],s),t}(e);return i=We("{parent}/tuningJobs:validateReinforcementTuningReward",s._url),r=s._query,delete s._url,delete s._query,o=this.apiClient.request({path:i,queryParams:r,body:JSON.stringify(s),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=>{const n=t;return n.sdkHttpResponse={headers:e.headers},n})),o.then(e=>{const t=function(e){const t={},n=Ze(e,["sdkHttpResponse"]);null!=n&&ze(t,["sdkHttpResponse"],n);const o=Ze(e,["overallReward"]);null!=o&&ze(t,["overallReward"],o);const i=Ze(e,["error"]);null!=i&&ze(t,["error"],i);const r=Ze(e,["rewardInfoDetails"]);return null!=r&&ze(t,["rewardInfoDetails"],r),t}(e),n=new _t;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}},Gs=class{async download(e,t){throw new Error("Download to file is not supported in the browser, please use a browser compliant download like an <a> tag.")}},ks="x-goog-upload-status";async function Ms(e,t,n,o){var i,r,s;let l=t;const a=(null==o?void 0:o.baseUrl)||(null===(i=n.clientOptions.httpOptions)||void 0===i?void 0:i.baseUrl);if(a){const e=new URL(a),n=new URL(t);n.protocol=e.protocol,n.host=e.host,n.port=e.port,l=n.toString()}let u=0,c=0,p=new ot(new Response),d="upload";for(u=e.size;c<u;){const t=Math.min(8388608,u-c),i=e.slice(c,c+t);c+t>=u&&(d+=", finalize");let a=0,m=1e3;for(;a<3;){const e=Object.assign(Object.assign({},(null==o?void 0:o.headers)||{}),{"X-Goog-Upload-Command":d,"X-Goog-Upload-Offset":String(c)});if(p=await n.request({path:"",body:i,httpMethod:"POST",httpOptions:Object.assign(Object.assign({},o),{apiVersion:"",baseUrl:l,headers:e})}),null===(r=null==p?void 0:p.headers)||void 0===r?void 0:r[ks])break;a++,await xs(m),m*=2}if(c+=t,"active"!==(null===(s=null==p?void 0:p.headers)||void 0===s?void 0:s[ks]))break;if(u<=c)throw new Error("All content has been uploaded, but the upload status is not finalized.")}return p}function xs(e){return new Promise(t=>setTimeout(t,e))}var Us=class{async upload(e,t,n,o){if("string"==typeof e)throw new Error("File path is not supported in browser uploader.");return await async function(e,t,n,o){var i;const r=await Ms(e,t,n,o),s=await(null==r?void 0:r.json());if("final"!==(null===(i=null==r?void 0:r.headers)||void 0===i?void 0:i[ks]))throw new Error("Failed to upload file: Upload status is not finalized.");return s.file}(e,t,n,o)}async uploadToFileSearchStore(e,t,n,o){if("string"==typeof e)throw new Error("File path is not supported in browser uploader.");return await async function(e,t,n,o){var i;const r=await Ms(e,t,n,o),s=await(null==r?void 0:r.json());if("final"!==(null===(i=null==r?void 0:r.headers)||void 0===i?void 0:i[ks]))throw new Error("Failed to upload file: Upload status is not finalized.");const l=tt(s),a=new Dt;return Object.assign(a,l),a}(e,t,n,o)}async stat(e){if("string"==typeof e)throw new Error("File path is not supported in browser uploader.");return await async function(e){return{size:e.size,type:e.type}}(e)}},Ls=class{create(e,t,n){return new qs(e,t,n)}},qs=class{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 new Error("WebSocket is not connected");this.ws.send(e)}close(){if(void 0===this.ws)throw new Error("WebSocket is not connected");this.ws.close()}},Hs="x-goog-api-key",Fs=class{constructor(e){this.apiKey=e}async addAuthHeaders(e,t){if(null===e.get(Hs)){if(this.apiKey.startsWith("auth_tokens/"))throw new Error("Ephemeral tokens are only supported by the live API.");if(!this.apiKey)throw new Error("API key is missing. Please provide a valid API key.");e.append(Hs,this.apiKey)}}},js=class{getNextGenClient(){const e=this.httpOptions;return void 0===this._nextGenClient&&(this._nextGenClient=ms(this.apiClient,{timeout_ms:null==e?void 0:e.timeout})),null==e||e.extraBody,this._nextGenClient}get interactions(){return void 0!==this._interactions||(this._interactions=new fs(this.apiClient)),this._interactions}get webhooks(){return void 0!==this._webhooks||(this._webhooks=new gs(this.apiClient)),this._webhooks}get agents(){return void 0!==this._agents||(this._agents=new hs(this.apiClient)),this._agents}get triggers(){return void 0!==this._triggers||(this._triggers=new vs(this.apiClient)),this._triggers}get environments(){return void 0!==this._environments||(this._environments=new bs(this.apiClient)),this._environments}constructor(e={}){var t;if(null==e.apiKey)throw new Error("An API Key must be set when running in a browser");if(e.project||e.location)throw new 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;const n=function(e,t){var n,o;if(!(null==e?void 0:e.baseUrl)){const e={geminiUrl:void 0,vertexUrl:void 0};return t?null!==(n=e.vertexUrl)&&void 0!==n?n:void 0:null!==(o=e.geminiUrl)&&void 0!==o?o:void 0}return e.baseUrl}(e.httpOptions,e.vertexai);n&&(e.httpOptions?e.httpOptions.baseUrl=n:e.httpOptions={baseUrl:n}),this.apiVersion=e.apiVersion,this.httpOptions=e.httpOptions;const o=new Fs(this.apiKey);this.apiClient=new co({auth:o,apiVersion:this.apiVersion,apiKey:this.apiKey,vertexai:this.vertexai,httpOptions:this.httpOptions,userAgentExtra:"gl-node/web",uploader:new Us,downloader:new Gs}),this.models=new bo(this.apiClient),this.live=new yo(this.apiClient,o,new Ls),this.batches=new _n(this.apiClient),this.chats=new wn(this.models,this.apiClient),this.caches=new An(this.apiClient),this.files=new Dn(this.apiClient),this.operations=new Po(this.apiClient),this.authTokens=new Ro(this.apiClient),this.tunings=new Ds(this.apiClient),this.fileSearchStores=new Do(this.apiClient)}},Bs={THINKING_LEVEL_UNSPECIFIED:D.THINKING_LEVEL_UNSPECIFIED,MINIMAL:D.MINIMAL,LOW:D.LOW,MEDIUM:D.MEDIUM,HIGH:D.HIGH};function Vs(e,t){const n=e.thinkingLevelMap?.[t],o="string"==typeof n?n.toLowerCase():t;switch(o){case"minimal":case"low":case"medium":case"high":return o;default:throw new Error(`Unsupported Google thinking level mapping for ${e.provider}/${e.id}: ${t} -> ${String(n)}`)}}function Xs(e){const t=e.id.toLowerCase();return/gemini-3(?:\.\d+)?-(?:pro|flash)/.test(t)||/gemini-(?:[4-9]|[1-9]\d)/.test(t)||"gemini-flash-latest"===t||"gemini-flash-lite-latest"===t||/gemma-?4/.test(t)}function Js(e){switch(e){case"minimal":return"MINIMAL";case"low":return"LOW";case"medium":return"MEDIUM";case"high":return"HIGH"}}function Ys(e){return Bs[e]}function $s(e){return!0===e.thought}function Ks(e,t){return"string"==typeof t&&t.length>0?t:e}var Ws=/^[A-Za-z0-9+/]+={0,2}$/;function zs(e,t){return e&&function(e){return!!e&&e.length%4==0&&Ws.test(e)}(t)?t:void 0}function Zs(e){const t=Qs(e);return e.startsWith("claude-")||e.startsWith("gpt-oss-")||void 0!==t&&t>=3}function Qs(e){const t=e.toLowerCase().match(/^gemini(?:-live)?-(\d+)/);if(t)return Number.parseInt(t[1],10)}function el(e){const t=Qs(e);return void 0===t||t>=3}var tl=/* @__PURE__ */new Set(["$schema","$id","$anchor","$dynamicAnchor","$vocabulary","$comment","$defs","definitions"]);function nl(e){if("object"!=typeof e||null===e||Array.isArray(e))return e;const t={};for(const[n,o]of Object.entries(e))tl.has(n)||(t[n]=nl(o));return t}function ol(e,t=!1,n=!0){if(0!==e.length)return[{functionDeclarations:e.map(e=>{const o=g(e,n),i=m(e,o);return{name:e.name,description:e.description,...t?{parameters:nl(i)}:{parametersJsonSchema:i}}})}]}function il(e){switch(e){case"auto":default:return L.AUTO;case"none":return L.NONE;case"any":return L.ANY}}function rl(e){switch(e){case q.STOP:return"stop";case q.MAX_TOKENS:return"length";case q.BLOCKLIST:case q.PROHIBITED_CONTENT:case q.SPII:case q.SAFETY:case q.IMAGE_SAFETY:case q.IMAGE_PROHIBITED_CONTENT:case q.IMAGE_RECITATION:case q.IMAGE_OTHER:case q.RECITATION:case q.FINISH_REASON_UNSPECIFIED:case q.OTHER:case q.LANGUAGE:case q.MALFORMED_FUNCTION_CALL:case q.UNEXPECTED_TOOL_CALL:case q.TOO_MANY_TOOL_CALLS:case q.NO_IMAGE:return"error";default:throw new Error(`Unhandled stop reason: ${e}`)}}var sl=0,ll=(e,t,m)=>{const h=new o,y=a(t);return(async()=>{const t={role:"assistant",content:[],api:"google-generative-ai",provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()};try{if(m?.fetch&&m.fetch!==globalThis.fetch)throw new Error("Custom fetch is not supported by the Google Generative AI adapter");const o=m?.apiKey;if(!o)throw new Error(`No API key for provider: ${e.provider}`);const _=function(e,t,o,i){const r={};e.baseUrl&&(r.baseUrl=e.baseUrl,r.apiVersion="");const s=p(n(e,i),e.headers,o);return s&&(r.headers=s),new js({apiKey:t,httpOptions:Object.keys(r).length>0?r:void 0})}(e,o,m?.headers,m?.identity);let E=function(e,t,n={}){const o=function(e,t){const n=r(a(t).messages),o=[],i=v(n,e,t=>Zs(e.id)?t.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,64):t);for(const r of i)if("user"===r.role)if("string"==typeof r.content)o.push({role:"user",parts:[{text:f(r.content)}]});else{const e=r.content.map(e=>"text"===e.type?{text:f(e.text)}:{inlineData:{mimeType:e.mimeType,data:e.data}});if(0===e.length)continue;o.push({role:"user",parts:e})}else if("assistant"===r.role){const t=[],n=r.provider===e.provider&&r.model===e.id;for(const o of r.content)if("text"===o.type){const e=zs(n,o.textSignature);if(!(o.text&&""!==o.text.trim()||e))continue;t.push({text:f(o.text),...e&&{thoughtSignature:e}})}else if("thinking"===o.type)if(n){const e=zs(n,o.thinkingSignature);if(!(o.thinking&&""!==o.thinking.trim()||e))continue;t.push({thought:!0,text:f(o.thinking),...e&&{thoughtSignature:e}})}else{if(!o.thinking||""===o.thinking.trim())continue;t.push({text:f(o.thinking)})}else if("toolCall"===o.type){const i=zs(n,o.thoughtSignature),r={functionCall:{name:o.name,args:o.arguments??{},...Zs(e.id)?{id:o.id}:{}},...i&&{thoughtSignature:i}};t.push(r)}if(0===t.length)continue;o.push({role:"model",parts:t})}else if("toolResult"===r.role){const t=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),n=e.input.includes("image")?r.content.filter(e=>"image"===e.type):[],i=t.trim().length>0,s=n.length>0,l=el(e.id),a=i?f(t):s?"(see attached image)":"",u=n.map(e=>({inlineData:{mimeType:e.mimeType,data:e.data}})),c=Zs(e.id),p={functionResponse:{name:r.toolName,response:r.isError?{error:a}:{output:a},...s&&l&&{parts:u},...c?{id:r.toolCallId}:{}}},d=o[o.length-1];"user"===d?.role&&d.parts?.some(e=>e.functionResponse)?d.parts.push(p):o.push({role:"user",parts:[p]}),s&&!l&&o.push({role:"user",parts:[{text:"Tool result image:"},...u]})}return o}(e,t),s=i(t.messages),p=l(t.messages),d={};void 0!==n.temperature&&(d.temperature=n.temperature),void 0!==n.maxTokens&&(d.maxOutputTokens=n.maxTokens);const m=function(e){const t=Qs(e);return void 0!==t&&t>=3}(e.id),h=p.length>0?function(e,t,n){const o=e.some(e=>!0===g(e,n));return"none"===t||"any"===t?il(t):o?L.VALIDATED:t?il(t):void 0}(p,n.toolChoice,m):void 0,_=s?c(s):"",E={...Object.keys(d).length>0&&d,..._&&{systemInstruction:f(_)},...p.length>0&&{tools:ol(p,!1,m)},...void 0!==h&&{toolConfig:{functionCallingConfig:{mode:h}}}};if(n.thinking?.enabled&&e.reasoning){const e={includeThoughts:!0};void 0!==n.thinking.level?e.thinkingLevel=Ys(n.thinking.level):void 0!==n.thinking.budgetTokens&&(e.thinkingBudget=n.thinking.budgetTokens),E.thinkingConfig=e}else e.reasoning&&n.thinking&&!n.thinking.enabled&&(E.thinkingConfig=function(e){if(!Xs(e))return{thinkingBudget:0};const t=u(e,"off");return"off"===t?{thinkingBudget:0}:{thinkingLevel:Ys(Js(Vs(e,t)))}}(e));if(n.signal){if(n.signal.aborted)throw new Error("Request aborted");E.abortSignal=n.signal}return{model:e.id,contents:o,config:E}}(e,y,m);const A=await(m?.onPayload?.(E,e));void 0!==A&&(E=A);const I=await function(e,t){return d(async()=>{try{return await _.models.generateContentStream(E)}catch(e){throw e instanceof Error&&"status"in e&&!("headers"in e)&&(e.headers=void 0),e}},{maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,signal:t?.signal})}(0,m);h.push({type:"start",partial:t});let T=null;const C=t.content,S=()=>C.length-1;for await(const n of I){await(m?.onProviderStreamEvent?.(n,e)),t.responseId||=n.responseId;const o=n.candidates?.[0];if(o?.content?.parts)for(const e of o.content.parts){if(void 0!==e.text){const n=$s(e);(!T||n&&"thinking"!==T.type||!n&&"text"!==T.type)&&(T&&("text"===T.type?h.push({type:"text_end",contentIndex:C.length-1,content:T.text,partial:t}):h.push({type:"thinking_end",contentIndex:S(),content:T.thinking,partial:t})),n?(T={type:"thinking",thinking:"",thinkingSignature:void 0},t.content.push(T),h.push({type:"thinking_start",contentIndex:S(),partial:t})):(T={type:"text",text:""},t.content.push(T),h.push({type:"text_start",contentIndex:S(),partial:t}))),"thinking"===T.type?(T.thinking+=e.text,T.thinkingSignature=Ks(T.thinkingSignature,e.thoughtSignature),h.push({type:"thinking_delta",contentIndex:S(),delta:e.text,partial:t})):(T.text+=e.text,T.textSignature=Ks(T.textSignature,e.thoughtSignature),h.push({type:"text_delta",contentIndex:S(),delta:e.text,partial:t}))}if(e.functionCall){T&&("text"===T.type?h.push({type:"text_end",contentIndex:S(),content:T.text,partial:t}):h.push({type:"thinking_end",contentIndex:S(),content:T.thinking,partial:t}),T=null);const n=e.functionCall.id,o={type:"toolCall",id:!n||t.content.some(e=>"toolCall"===e.type&&e.id===n)?`${e.functionCall.name}_${Date.now()}_${++sl}`:n,name:e.functionCall.name||"",arguments:e.functionCall.args??{},...e.thoughtSignature&&{thoughtSignature:e.thoughtSignature}};t.content.push(o),h.push({type:"toolcall_start",contentIndex:S(),partial:t}),h.push({type:"toolcall_delta",contentIndex:S(),delta:JSON.stringify(o.arguments),partial:t}),h.push({type:"toolcall_end",contentIndex:S(),toolCall:o,partial:t})}}o?.finishReason&&(t.rawStopReason=o.finishReason,t.stopReason=rl(o.finishReason),t.content.some(e=>"toolCall"===e.type)&&"stop"===t.stopReason&&(t.stopReason="toolUse")),n.usageMetadata&&(t.usage={input:(n.usageMetadata.promptTokenCount||0)-(n.usageMetadata.cachedContentTokenCount||0),output:(n.usageMetadata.candidatesTokenCount||0)+(n.usageMetadata.thoughtsTokenCount||0),cacheRead:n.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,reasoning:n.usageMetadata.thoughtsTokenCount||0,totalTokens:n.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},s(e,t.usage))}if(T&&("text"===T.type?h.push({type:"text_end",contentIndex:S(),content:T.text,partial:t}):h.push({type:"thinking_end",contentIndex:S(),content:T.thinking,partial:t})),m?.signal?.aborted)throw new Error("Request was aborted");if("pending"===t.stopReason)throw new Error("Google stream ended without a finish reason");if("aborted"===t.stopReason||"error"===t.stopReason){const e=t.rawStopReason?`Provider stopped with: ${t.rawStopReason}`:"An unknown error occurred";throw new Error(e)}h.push({type:"done",reason:t.stopReason,message:t}),h.end()}catch(o){for(const e of t.content)"index"in e&&delete e.index;t.stopReason=m?.signal?.aborted?"aborted":"error",t.errorMessage=E(_(o)),h.push({type:"error",reason:t.stopReason,error:t}),h.end()}})(),h},al=(e,t,n)=>{const o=n?.apiKey;if(!o)throw new Error(`No API key for provider: ${e.provider}`);const i={...h(e,t,n,o),toolChoice:n?.toolChoice};if(!n?.reasoning)return ll(e,t,{...i,thinking:{enabled:!1}});const r=u(e,n.reasoning);if("off"===r)return ll(e,t,{...i,thinking:{enabled:!1}});const s=Vs(e,r);return Xs(e)?ll(e,t,{...i,thinking:{enabled:!0,level:Js(s)}}):ll(e,t,{...i,thinking:{enabled:!0,budgetTokens:ul(e,s,n.thinkingBudgets)}})};function ul(e,t,n){return void 0!==n?.[t]?n[t]:e.id.includes("2.5-pro")?{minimal:128,low:2048,medium:8192,high:32768}[t]:e.id.includes("2.5-flash-lite")?{minimal:512,low:2048,medium:8192,high:24576}[t]:e.id.includes("2.5-flash")?{minimal:128,low:2048,medium:8192,high:24576}[t]:-1}export{ll as stream,al as streamSimple};