@omniyat/aimodule 1.0.0

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.
package/dist/index.cjs ADDED
@@ -0,0 +1,300 @@
1
+ "use strict";var e=require("file-type");function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n,o,i,r,s,l,a,u,c,p,d,h,f,m,g,y={},v={exports:{}},E={};function T(){return i||(i=1,e=E,t=function(){if(o)return n;function e(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))}return o=1,n=e,e.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},e.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},e.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=(new Date).getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(e),this._errors.unshift(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},e.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=(new Date).getTime(),this._fn(this._attempts)},e.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)},e.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)},e.prototype.start=e.prototype.try,e.prototype.errors=function(){return this._errors},e.prototype.attempts=function(){return this._attempts},e.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},n}(),e.operation=function(n){var o=e.timeouts(n);return new t(o,{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 o=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}}),E;var e,t}function I(){return s?r:(s=1,r=T())}function _(){if(l)return v.exports;l=1;const e=I(),t=["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"];class n 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}}const o=(o,i)=>new Promise((r,s)=>{i={onFailedAttempt:()=>{},retries:10,...i};const l=e.operation(i);l.attempt(async e=>{try{r(await o(e))}catch(o){if(!(o instanceof Error))return void s(new TypeError(`Non-error was thrown: "${o}". You should only throw errors.`));if(o instanceof n)l.stop(),s(o.originalError);else if(o instanceof TypeError&&(a=o.message,!t.includes(a)))l.stop(),s(o);else{((e,t,n)=>{const o=n.retries-(t-1);e.attemptNumber=t,e.retriesLeft=o})(o,e,i);try{await i.onFailedAttempt(o)}catch(e){return void s(e)}l.retry(o)||s(l.mainError())}}var a})});return v.exports=o,v.exports.default=o,v.exports.AbortError=n,v.exports}function S(){return a||(a=1,function(e){var t,n,o,i,r,s,l,a,u,c,p,d,h,f,m,g,y,v,E,T,I,S,A,C,O,b,R,w,N,P,M,D,U,x,L,k,q,G,F,H,j,V,B,J,$,Y,K,W,z,X,Q,Z,ee,te,ne,oe,ie,re,se=_();
2
+ /**
3
+ * @license
4
+ * Copyright 2025 Google LLC
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+ /**
8
+ * @license
9
+ * Copyright 2025 Google LLC
10
+ * SPDX-License-Identifier: Apache-2.0
11
+ */
12
+ class le{}function ae(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 ue(e,t,n){for(let o=0;o<t.length-1;o++){const i=t[o];if(i.endsWith("[]")){const r=i.slice(0,-2);if(!(r in e)){if(!Array.isArray(n))throw new Error(`Value must be a list given an array path ${i}`);e[r]=Array.from({length:n.length},()=>({}))}if(Array.isArray(e[r])){const i=e[r];if(Array.isArray(n))for(let e=0;e<i.length;e++){ue(i[e],t.slice(o+1),n[e])}else for(const e of i)ue(e,t.slice(o+1),n)}return}if(i.endsWith("[0]")){const r=i.slice(0,-3);r in e||(e[r]=[{}]);return void ue(e[r][0],t.slice(o+1),n)}e[i]&&"object"==typeof e[i]||(e[i]={}),e=e[i]}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 if("_self"!==o||"object"!=typeof n||null===n||Array.isArray(n))e[o]=n;else{const t=n;Object.assign(e,t)}}function ce(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=>ce(e,t.slice(o+1),n)):n}return n}e=e[i]}return e}catch(e){if(e instanceof TypeError)return n;throw e}}function pe(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])pe(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);ue(t,r,i)}for(const e of r)delete t[e]}}else{r in e&&pe(e[r],t,n,o+1,i)}}
13
+ /**
14
+ * @license
15
+ * Copyright 2025 Google LLC
16
+ * SPDX-License-Identifier: Apache-2.0
17
+ */function de(e){if("string"!=typeof e)throw new Error("fromImageBytes must be a string");return e}
18
+ /**
19
+ * @license
20
+ * Copyright 2025 Google LLC
21
+ * SPDX-License-Identifier: Apache-2.0
22
+ */function he(e){const t={},n=ce(e,["name"]);null!=n&&ue(t,["name"],n);const o=ce(e,["metadata"]);null!=o&&ue(t,["metadata"],o);const i=ce(e,["done"]);null!=i&&ue(t,["done"],i);const r=ce(e,["error"]);null!=r&&ue(t,["error"],r);const s=ce(e,["response","generateVideoResponse"]);return null!=s&&ue(t,["response"],function(e){const t={},n=ce(e,["generatedSamples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["video"]);null!=n&&ue(t,["video"],function(e){const t={},n=ce(e,["uri"]);null!=n&&ue(t,["uri"],n);const o=ce(e,["encodedVideo"]);null!=o&&ue(t,["videoBytes"],de(o));const i=ce(e,["encoding"]);null!=i&&ue(t,["mimeType"],i);return t}(n));return t}(e))),ue(t,["generatedVideos"],e)}const o=ce(e,["raiMediaFilteredCount"]);null!=o&&ue(t,["raiMediaFilteredCount"],o);const i=ce(e,["raiMediaFilteredReasons"]);null!=i&&ue(t,["raiMediaFilteredReasons"],i);return t}(s)),t}function fe(e){const t={},n=ce(e,["name"]);null!=n&&ue(t,["name"],n);const o=ce(e,["metadata"]);null!=o&&ue(t,["metadata"],o);const i=ce(e,["done"]);null!=i&&ue(t,["done"],i);const r=ce(e,["error"]);null!=r&&ue(t,["error"],r);const s=ce(e,["response"]);return null!=s&&ue(t,["response"],function(e){const t={},n=ce(e,["videos"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["_self"]);null!=n&&ue(t,["video"],function(e){const t={},n=ce(e,["gcsUri"]);null!=n&&ue(t,["uri"],n);const o=ce(e,["bytesBase64Encoded"]);null!=o&&ue(t,["videoBytes"],de(o));const i=ce(e,["mimeType"]);null!=i&&ue(t,["mimeType"],i);return t}
23
+ /**
24
+ * @license
25
+ * Copyright 2025 Google LLC
26
+ * SPDX-License-Identifier: Apache-2.0
27
+ */(n));return t}(e))),ue(t,["generatedVideos"],e)}const o=ce(e,["raiMediaFilteredCount"]);null!=o&&ue(t,["raiMediaFilteredCount"],o);const i=ce(e,["raiMediaFilteredReasons"]);null!=i&&ue(t,["raiMediaFilteredReasons"],i);return t}(s)),t}function me(e){const t={},n=ce(e,["name"]);null!=n&&ue(t,["name"],n);const o=ce(e,["metadata"]);null!=o&&ue(t,["metadata"],o);const i=ce(e,["done"]);null!=i&&ue(t,["done"],i);const r=ce(e,["error"]);null!=r&&ue(t,["error"],r);const s=ce(e,["response"]);return null!=s&&ue(t,["response"],function(e){const t={},n=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["parent"]);null!=o&&ue(t,["parent"],o);const i=ce(e,["documentName"]);null!=i&&ue(t,["documentName"],i);return t}(s)),t}function ge(e){const t={},n=ce(e,["name"]);null!=n&&ue(t,["name"],n);const o=ce(e,["metadata"]);null!=o&&ue(t,["metadata"],o);const i=ce(e,["done"]);null!=i&&ue(t,["done"],i);const r=ce(e,["error"]);null!=r&&ue(t,["error"],r);const s=ce(e,["response"]);return null!=s&&ue(t,["response"],function(e){const t={},n=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["parent"]);null!=o&&ue(t,["parent"],o);const i=ce(e,["documentName"]);null!=i&&ue(t,["documentName"],i);return t}(s)),t}e.Outcome=void 0,(t=e.Outcome||(e.Outcome={})).OUTCOME_UNSPECIFIED="OUTCOME_UNSPECIFIED",t.OUTCOME_OK="OUTCOME_OK",t.OUTCOME_FAILED="OUTCOME_FAILED",t.OUTCOME_DEADLINE_EXCEEDED="OUTCOME_DEADLINE_EXCEEDED",e.Language=void 0,(n=e.Language||(e.Language={})).LANGUAGE_UNSPECIFIED="LANGUAGE_UNSPECIFIED",n.PYTHON="PYTHON",e.FunctionResponseScheduling=void 0,(o=e.FunctionResponseScheduling||(e.FunctionResponseScheduling={})).SCHEDULING_UNSPECIFIED="SCHEDULING_UNSPECIFIED",o.SILENT="SILENT",o.WHEN_IDLE="WHEN_IDLE",o.INTERRUPT="INTERRUPT",e.Type=void 0,(i=e.Type||(e.Type={})).TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",i.STRING="STRING",i.NUMBER="NUMBER",i.INTEGER="INTEGER",i.BOOLEAN="BOOLEAN",i.ARRAY="ARRAY",i.OBJECT="OBJECT",i.NULL="NULL",e.ApiSpec=void 0,(r=e.ApiSpec||(e.ApiSpec={})).API_SPEC_UNSPECIFIED="API_SPEC_UNSPECIFIED",r.SIMPLE_SEARCH="SIMPLE_SEARCH",r.ELASTIC_SEARCH="ELASTIC_SEARCH",e.AuthType=void 0,(s=e.AuthType||(e.AuthType={})).AUTH_TYPE_UNSPECIFIED="AUTH_TYPE_UNSPECIFIED",s.NO_AUTH="NO_AUTH",s.API_KEY_AUTH="API_KEY_AUTH",s.HTTP_BASIC_AUTH="HTTP_BASIC_AUTH",s.GOOGLE_SERVICE_ACCOUNT_AUTH="GOOGLE_SERVICE_ACCOUNT_AUTH",s.OAUTH="OAUTH",s.OIDC_AUTH="OIDC_AUTH",e.HttpElementLocation=void 0,(l=e.HttpElementLocation||(e.HttpElementLocation={})).HTTP_IN_UNSPECIFIED="HTTP_IN_UNSPECIFIED",l.HTTP_IN_QUERY="HTTP_IN_QUERY",l.HTTP_IN_HEADER="HTTP_IN_HEADER",l.HTTP_IN_PATH="HTTP_IN_PATH",l.HTTP_IN_BODY="HTTP_IN_BODY",l.HTTP_IN_COOKIE="HTTP_IN_COOKIE",e.PhishBlockThreshold=void 0,(a=e.PhishBlockThreshold||(e.PhishBlockThreshold={})).PHISH_BLOCK_THRESHOLD_UNSPECIFIED="PHISH_BLOCK_THRESHOLD_UNSPECIFIED",a.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",a.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",a.BLOCK_HIGH_AND_ABOVE="BLOCK_HIGH_AND_ABOVE",a.BLOCK_HIGHER_AND_ABOVE="BLOCK_HIGHER_AND_ABOVE",a.BLOCK_VERY_HIGH_AND_ABOVE="BLOCK_VERY_HIGH_AND_ABOVE",a.BLOCK_ONLY_EXTREMELY_HIGH="BLOCK_ONLY_EXTREMELY_HIGH",e.Behavior=void 0,(u=e.Behavior||(e.Behavior={})).UNSPECIFIED="UNSPECIFIED",u.BLOCKING="BLOCKING",u.NON_BLOCKING="NON_BLOCKING",e.DynamicRetrievalConfigMode=void 0,(c=e.DynamicRetrievalConfigMode||(e.DynamicRetrievalConfigMode={})).MODE_UNSPECIFIED="MODE_UNSPECIFIED",c.MODE_DYNAMIC="MODE_DYNAMIC",e.FunctionCallingConfigMode=void 0,(p=e.FunctionCallingConfigMode||(e.FunctionCallingConfigMode={})).MODE_UNSPECIFIED="MODE_UNSPECIFIED",p.AUTO="AUTO",p.ANY="ANY",p.NONE="NONE",p.VALIDATED="VALIDATED",e.ThinkingLevel=void 0,(d=e.ThinkingLevel||(e.ThinkingLevel={})).THINKING_LEVEL_UNSPECIFIED="THINKING_LEVEL_UNSPECIFIED",d.LOW="LOW",d.MEDIUM="MEDIUM",d.HIGH="HIGH",d.MINIMAL="MINIMAL",e.HarmCategory=void 0,(h=e.HarmCategory||(e.HarmCategory={})).HARM_CATEGORY_UNSPECIFIED="HARM_CATEGORY_UNSPECIFIED",h.HARM_CATEGORY_HARASSMENT="HARM_CATEGORY_HARASSMENT",h.HARM_CATEGORY_HATE_SPEECH="HARM_CATEGORY_HATE_SPEECH",h.HARM_CATEGORY_SEXUALLY_EXPLICIT="HARM_CATEGORY_SEXUALLY_EXPLICIT",h.HARM_CATEGORY_DANGEROUS_CONTENT="HARM_CATEGORY_DANGEROUS_CONTENT",h.HARM_CATEGORY_CIVIC_INTEGRITY="HARM_CATEGORY_CIVIC_INTEGRITY",h.HARM_CATEGORY_IMAGE_HATE="HARM_CATEGORY_IMAGE_HATE",h.HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT="HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT",h.HARM_CATEGORY_IMAGE_HARASSMENT="HARM_CATEGORY_IMAGE_HARASSMENT",h.HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT="HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT",h.HARM_CATEGORY_JAILBREAK="HARM_CATEGORY_JAILBREAK",e.HarmBlockMethod=void 0,(f=e.HarmBlockMethod||(e.HarmBlockMethod={})).HARM_BLOCK_METHOD_UNSPECIFIED="HARM_BLOCK_METHOD_UNSPECIFIED",f.SEVERITY="SEVERITY",f.PROBABILITY="PROBABILITY",e.HarmBlockThreshold=void 0,(m=e.HarmBlockThreshold||(e.HarmBlockThreshold={})).HARM_BLOCK_THRESHOLD_UNSPECIFIED="HARM_BLOCK_THRESHOLD_UNSPECIFIED",m.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",m.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",m.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",m.BLOCK_NONE="BLOCK_NONE",m.OFF="OFF",e.FinishReason=void 0,(g=e.FinishReason||(e.FinishReason={})).FINISH_REASON_UNSPECIFIED="FINISH_REASON_UNSPECIFIED",g.STOP="STOP",g.MAX_TOKENS="MAX_TOKENS",g.SAFETY="SAFETY",g.RECITATION="RECITATION",g.LANGUAGE="LANGUAGE",g.OTHER="OTHER",g.BLOCKLIST="BLOCKLIST",g.PROHIBITED_CONTENT="PROHIBITED_CONTENT",g.SPII="SPII",g.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",g.IMAGE_SAFETY="IMAGE_SAFETY",g.UNEXPECTED_TOOL_CALL="UNEXPECTED_TOOL_CALL",g.IMAGE_PROHIBITED_CONTENT="IMAGE_PROHIBITED_CONTENT",g.NO_IMAGE="NO_IMAGE",g.IMAGE_RECITATION="IMAGE_RECITATION",g.IMAGE_OTHER="IMAGE_OTHER",e.HarmProbability=void 0,(y=e.HarmProbability||(e.HarmProbability={})).HARM_PROBABILITY_UNSPECIFIED="HARM_PROBABILITY_UNSPECIFIED",y.NEGLIGIBLE="NEGLIGIBLE",y.LOW="LOW",y.MEDIUM="MEDIUM",y.HIGH="HIGH",e.HarmSeverity=void 0,(v=e.HarmSeverity||(e.HarmSeverity={})).HARM_SEVERITY_UNSPECIFIED="HARM_SEVERITY_UNSPECIFIED",v.HARM_SEVERITY_NEGLIGIBLE="HARM_SEVERITY_NEGLIGIBLE",v.HARM_SEVERITY_LOW="HARM_SEVERITY_LOW",v.HARM_SEVERITY_MEDIUM="HARM_SEVERITY_MEDIUM",v.HARM_SEVERITY_HIGH="HARM_SEVERITY_HIGH",e.UrlRetrievalStatus=void 0,(E=e.UrlRetrievalStatus||(e.UrlRetrievalStatus={})).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",e.BlockedReason=void 0,(T=e.BlockedReason||(e.BlockedReason={})).BLOCKED_REASON_UNSPECIFIED="BLOCKED_REASON_UNSPECIFIED",T.SAFETY="SAFETY",T.OTHER="OTHER",T.BLOCKLIST="BLOCKLIST",T.PROHIBITED_CONTENT="PROHIBITED_CONTENT",T.IMAGE_SAFETY="IMAGE_SAFETY",T.MODEL_ARMOR="MODEL_ARMOR",T.JAILBREAK="JAILBREAK",e.TrafficType=void 0,(I=e.TrafficType||(e.TrafficType={})).TRAFFIC_TYPE_UNSPECIFIED="TRAFFIC_TYPE_UNSPECIFIED",I.ON_DEMAND="ON_DEMAND",I.PROVISIONED_THROUGHPUT="PROVISIONED_THROUGHPUT",e.Modality=void 0,(S=e.Modality||(e.Modality={})).MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",S.TEXT="TEXT",S.IMAGE="IMAGE",S.AUDIO="AUDIO",e.MediaResolution=void 0,(A=e.MediaResolution||(e.MediaResolution={})).MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",A.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",A.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",A.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH",e.TuningMode=void 0,(C=e.TuningMode||(e.TuningMode={})).TUNING_MODE_UNSPECIFIED="TUNING_MODE_UNSPECIFIED",C.TUNING_MODE_FULL="TUNING_MODE_FULL",C.TUNING_MODE_PEFT_ADAPTER="TUNING_MODE_PEFT_ADAPTER",e.AdapterSize=void 0,(O=e.AdapterSize||(e.AdapterSize={})).ADAPTER_SIZE_UNSPECIFIED="ADAPTER_SIZE_UNSPECIFIED",O.ADAPTER_SIZE_ONE="ADAPTER_SIZE_ONE",O.ADAPTER_SIZE_TWO="ADAPTER_SIZE_TWO",O.ADAPTER_SIZE_FOUR="ADAPTER_SIZE_FOUR",O.ADAPTER_SIZE_EIGHT="ADAPTER_SIZE_EIGHT",O.ADAPTER_SIZE_SIXTEEN="ADAPTER_SIZE_SIXTEEN",O.ADAPTER_SIZE_THIRTY_TWO="ADAPTER_SIZE_THIRTY_TWO",e.JobState=void 0,(b=e.JobState||(e.JobState={})).JOB_STATE_UNSPECIFIED="JOB_STATE_UNSPECIFIED",b.JOB_STATE_QUEUED="JOB_STATE_QUEUED",b.JOB_STATE_PENDING="JOB_STATE_PENDING",b.JOB_STATE_RUNNING="JOB_STATE_RUNNING",b.JOB_STATE_SUCCEEDED="JOB_STATE_SUCCEEDED",b.JOB_STATE_FAILED="JOB_STATE_FAILED",b.JOB_STATE_CANCELLING="JOB_STATE_CANCELLING",b.JOB_STATE_CANCELLED="JOB_STATE_CANCELLED",b.JOB_STATE_PAUSED="JOB_STATE_PAUSED",b.JOB_STATE_EXPIRED="JOB_STATE_EXPIRED",b.JOB_STATE_UPDATING="JOB_STATE_UPDATING",b.JOB_STATE_PARTIALLY_SUCCEEDED="JOB_STATE_PARTIALLY_SUCCEEDED",e.TuningTask=void 0,(R=e.TuningTask||(e.TuningTask={})).TUNING_TASK_UNSPECIFIED="TUNING_TASK_UNSPECIFIED",R.TUNING_TASK_I2V="TUNING_TASK_I2V",R.TUNING_TASK_T2V="TUNING_TASK_T2V",R.TUNING_TASK_R2V="TUNING_TASK_R2V",e.PartMediaResolutionLevel=void 0,(w=e.PartMediaResolutionLevel||(e.PartMediaResolutionLevel={})).MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",w.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",w.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",w.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH",w.MEDIA_RESOLUTION_ULTRA_HIGH="MEDIA_RESOLUTION_ULTRA_HIGH",e.ResourceScope=void 0,(e.ResourceScope||(e.ResourceScope={})).COLLECTION="COLLECTION",e.FeatureSelectionPreference=void 0,(N=e.FeatureSelectionPreference||(e.FeatureSelectionPreference={})).FEATURE_SELECTION_PREFERENCE_UNSPECIFIED="FEATURE_SELECTION_PREFERENCE_UNSPECIFIED",N.PRIORITIZE_QUALITY="PRIORITIZE_QUALITY",N.BALANCED="BALANCED",N.PRIORITIZE_COST="PRIORITIZE_COST",e.Environment=void 0,(P=e.Environment||(e.Environment={})).ENVIRONMENT_UNSPECIFIED="ENVIRONMENT_UNSPECIFIED",P.ENVIRONMENT_BROWSER="ENVIRONMENT_BROWSER",e.EmbeddingApiType=void 0,(M=e.EmbeddingApiType||(e.EmbeddingApiType={})).PREDICT="PREDICT",M.EMBED_CONTENT="EMBED_CONTENT",e.SafetyFilterLevel=void 0,(D=e.SafetyFilterLevel||(e.SafetyFilterLevel={})).BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",D.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",D.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",D.BLOCK_NONE="BLOCK_NONE",e.PersonGeneration=void 0,(U=e.PersonGeneration||(e.PersonGeneration={})).DONT_ALLOW="DONT_ALLOW",U.ALLOW_ADULT="ALLOW_ADULT",U.ALLOW_ALL="ALLOW_ALL",e.ImagePromptLanguage=void 0,(x=e.ImagePromptLanguage||(e.ImagePromptLanguage={})).auto="auto",x.en="en",x.ja="ja",x.ko="ko",x.hi="hi",x.zh="zh",x.pt="pt",x.es="es",e.MaskReferenceMode=void 0,(L=e.MaskReferenceMode||(e.MaskReferenceMode={})).MASK_MODE_DEFAULT="MASK_MODE_DEFAULT",L.MASK_MODE_USER_PROVIDED="MASK_MODE_USER_PROVIDED",L.MASK_MODE_BACKGROUND="MASK_MODE_BACKGROUND",L.MASK_MODE_FOREGROUND="MASK_MODE_FOREGROUND",L.MASK_MODE_SEMANTIC="MASK_MODE_SEMANTIC",e.ControlReferenceType=void 0,(k=e.ControlReferenceType||(e.ControlReferenceType={})).CONTROL_TYPE_DEFAULT="CONTROL_TYPE_DEFAULT",k.CONTROL_TYPE_CANNY="CONTROL_TYPE_CANNY",k.CONTROL_TYPE_SCRIBBLE="CONTROL_TYPE_SCRIBBLE",k.CONTROL_TYPE_FACE_MESH="CONTROL_TYPE_FACE_MESH",e.SubjectReferenceType=void 0,(q=e.SubjectReferenceType||(e.SubjectReferenceType={})).SUBJECT_TYPE_DEFAULT="SUBJECT_TYPE_DEFAULT",q.SUBJECT_TYPE_PERSON="SUBJECT_TYPE_PERSON",q.SUBJECT_TYPE_ANIMAL="SUBJECT_TYPE_ANIMAL",q.SUBJECT_TYPE_PRODUCT="SUBJECT_TYPE_PRODUCT",e.EditMode=void 0,(G=e.EditMode||(e.EditMode={})).EDIT_MODE_DEFAULT="EDIT_MODE_DEFAULT",G.EDIT_MODE_INPAINT_REMOVAL="EDIT_MODE_INPAINT_REMOVAL",G.EDIT_MODE_INPAINT_INSERTION="EDIT_MODE_INPAINT_INSERTION",G.EDIT_MODE_OUTPAINT="EDIT_MODE_OUTPAINT",G.EDIT_MODE_CONTROLLED_EDITING="EDIT_MODE_CONTROLLED_EDITING",G.EDIT_MODE_STYLE="EDIT_MODE_STYLE",G.EDIT_MODE_BGSWAP="EDIT_MODE_BGSWAP",G.EDIT_MODE_PRODUCT_IMAGE="EDIT_MODE_PRODUCT_IMAGE",e.SegmentMode=void 0,(F=e.SegmentMode||(e.SegmentMode={})).FOREGROUND="FOREGROUND",F.BACKGROUND="BACKGROUND",F.PROMPT="PROMPT",F.SEMANTIC="SEMANTIC",F.INTERACTIVE="INTERACTIVE",e.VideoGenerationReferenceType=void 0,(H=e.VideoGenerationReferenceType||(e.VideoGenerationReferenceType={})).ASSET="ASSET",H.STYLE="STYLE",e.VideoGenerationMaskMode=void 0,(j=e.VideoGenerationMaskMode||(e.VideoGenerationMaskMode={})).INSERT="INSERT",j.REMOVE="REMOVE",j.REMOVE_STATIC="REMOVE_STATIC",j.OUTPAINT="OUTPAINT",e.VideoCompressionQuality=void 0,(V=e.VideoCompressionQuality||(e.VideoCompressionQuality={})).OPTIMIZED="OPTIMIZED",V.LOSSLESS="LOSSLESS",e.TuningMethod=void 0,(B=e.TuningMethod||(e.TuningMethod={})).SUPERVISED_FINE_TUNING="SUPERVISED_FINE_TUNING",B.PREFERENCE_TUNING="PREFERENCE_TUNING",B.DISTILLATION="DISTILLATION",e.DocumentState=void 0,(J=e.DocumentState||(e.DocumentState={})).STATE_UNSPECIFIED="STATE_UNSPECIFIED",J.STATE_PENDING="STATE_PENDING",J.STATE_ACTIVE="STATE_ACTIVE",J.STATE_FAILED="STATE_FAILED",e.FileState=void 0,($=e.FileState||(e.FileState={})).STATE_UNSPECIFIED="STATE_UNSPECIFIED",$.PROCESSING="PROCESSING",$.ACTIVE="ACTIVE",$.FAILED="FAILED",e.FileSource=void 0,(Y=e.FileSource||(e.FileSource={})).SOURCE_UNSPECIFIED="SOURCE_UNSPECIFIED",Y.UPLOADED="UPLOADED",Y.GENERATED="GENERATED",Y.REGISTERED="REGISTERED",e.TurnCompleteReason=void 0,(K=e.TurnCompleteReason||(e.TurnCompleteReason={})).TURN_COMPLETE_REASON_UNSPECIFIED="TURN_COMPLETE_REASON_UNSPECIFIED",K.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",K.RESPONSE_REJECTED="RESPONSE_REJECTED",K.NEED_MORE_INPUT="NEED_MORE_INPUT",e.MediaModality=void 0,(W=e.MediaModality||(e.MediaModality={})).MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",W.TEXT="TEXT",W.IMAGE="IMAGE",W.VIDEO="VIDEO",W.AUDIO="AUDIO",W.DOCUMENT="DOCUMENT",e.VadSignalType=void 0,(z=e.VadSignalType||(e.VadSignalType={})).VAD_SIGNAL_TYPE_UNSPECIFIED="VAD_SIGNAL_TYPE_UNSPECIFIED",z.VAD_SIGNAL_TYPE_SOS="VAD_SIGNAL_TYPE_SOS",z.VAD_SIGNAL_TYPE_EOS="VAD_SIGNAL_TYPE_EOS",e.VoiceActivityType=void 0,(X=e.VoiceActivityType||(e.VoiceActivityType={})).TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",X.ACTIVITY_START="ACTIVITY_START",X.ACTIVITY_END="ACTIVITY_END",e.StartSensitivity=void 0,(Q=e.StartSensitivity||(e.StartSensitivity={})).START_SENSITIVITY_UNSPECIFIED="START_SENSITIVITY_UNSPECIFIED",Q.START_SENSITIVITY_HIGH="START_SENSITIVITY_HIGH",Q.START_SENSITIVITY_LOW="START_SENSITIVITY_LOW",e.EndSensitivity=void 0,(Z=e.EndSensitivity||(e.EndSensitivity={})).END_SENSITIVITY_UNSPECIFIED="END_SENSITIVITY_UNSPECIFIED",Z.END_SENSITIVITY_HIGH="END_SENSITIVITY_HIGH",Z.END_SENSITIVITY_LOW="END_SENSITIVITY_LOW",e.ActivityHandling=void 0,(ee=e.ActivityHandling||(e.ActivityHandling={})).ACTIVITY_HANDLING_UNSPECIFIED="ACTIVITY_HANDLING_UNSPECIFIED",ee.START_OF_ACTIVITY_INTERRUPTS="START_OF_ACTIVITY_INTERRUPTS",ee.NO_INTERRUPTION="NO_INTERRUPTION",e.TurnCoverage=void 0,(te=e.TurnCoverage||(e.TurnCoverage={})).TURN_COVERAGE_UNSPECIFIED="TURN_COVERAGE_UNSPECIFIED",te.TURN_INCLUDES_ONLY_ACTIVITY="TURN_INCLUDES_ONLY_ACTIVITY",te.TURN_INCLUDES_ALL_INPUT="TURN_INCLUDES_ALL_INPUT",e.Scale=void 0,(ne=e.Scale||(e.Scale={})).SCALE_UNSPECIFIED="SCALE_UNSPECIFIED",ne.C_MAJOR_A_MINOR="C_MAJOR_A_MINOR",ne.D_FLAT_MAJOR_B_FLAT_MINOR="D_FLAT_MAJOR_B_FLAT_MINOR",ne.D_MAJOR_B_MINOR="D_MAJOR_B_MINOR",ne.E_FLAT_MAJOR_C_MINOR="E_FLAT_MAJOR_C_MINOR",ne.E_MAJOR_D_FLAT_MINOR="E_MAJOR_D_FLAT_MINOR",ne.F_MAJOR_D_MINOR="F_MAJOR_D_MINOR",ne.G_FLAT_MAJOR_E_FLAT_MINOR="G_FLAT_MAJOR_E_FLAT_MINOR",ne.G_MAJOR_E_MINOR="G_MAJOR_E_MINOR",ne.A_FLAT_MAJOR_F_MINOR="A_FLAT_MAJOR_F_MINOR",ne.A_MAJOR_G_FLAT_MINOR="A_MAJOR_G_FLAT_MINOR",ne.B_FLAT_MAJOR_G_MINOR="B_FLAT_MAJOR_G_MINOR",ne.B_MAJOR_A_FLAT_MINOR="B_MAJOR_A_FLAT_MINOR",e.MusicGenerationMode=void 0,(oe=e.MusicGenerationMode||(e.MusicGenerationMode={})).MUSIC_GENERATION_MODE_UNSPECIFIED="MUSIC_GENERATION_MODE_UNSPECIFIED",oe.QUALITY="QUALITY",oe.DIVERSITY="DIVERSITY",oe.VOCALIZATION="VOCALIZATION",e.LiveMusicPlaybackControl=void 0,(ie=e.LiveMusicPlaybackControl||(e.LiveMusicPlaybackControl={})).PLAYBACK_CONTROL_UNSPECIFIED="PLAYBACK_CONTROL_UNSPECIFIED",ie.PLAY="PLAY",ie.PAUSE="PAUSE",ie.STOP="STOP",ie.RESET_CONTEXT="RESET_CONTEXT";function ye(e){return{text:e}}function ve(e){return"object"==typeof e&&null!==e&&("fileData"in e||"text"in e||"functionCall"in e||"functionResponse"in e||"inlineData"in e||"videoMetadata"in e||"codeExecutionResult"in e||"executableCode"in e)}function Ee(e){const t=[];if("string"==typeof e)t.push(ye(e));else if(ve(e))t.push(e);else{if(!Array.isArray(e))throw new Error("partOrString must be a Part object, string, or array");if(0===e.length)throw new Error("partOrString cannot be an empty array");for(const n of e)if("string"==typeof n)t.push(ye(n));else{if(!ve(n))throw new Error("element in PartUnion must be a Part object or string");t.push(n)}}return t}class Te{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()}}class Ie{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>1&&console.warn("there are multiple candidates in the response, returning text from the first one.");let a="",u=!1;const c=[];for(const e 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[t,n]of Object.entries(e))"text"===t||"thought"===t||"thoughtSignature"===t||null===n&&void 0===n||c.push(t);if("string"==typeof e.text){if("boolean"==typeof e.thought&&e.thought)continue;u=!0,a+=e.text}}return c.length>0&&console.warn(`there are non-text parts ${c} in the response, returning concatenation of all text parts. Please refer to the non text parts for a full response from model.`),u?a:void 0}get data(){var e,t,n,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>1&&console.warn("there are multiple candidates in the response, returning data from the first one.");let a="";const u=[];for(const e 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[t,n]of Object.entries(e))"inlineData"===t||null===n&&void 0===n||u.push(t);e.inlineData&&"string"==typeof e.inlineData.data&&(a+=atob(e.inlineData.data))}return u.length>0&&console.warn(`there are non-data parts ${u} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`),a.length>0?btoa(a):void 0}get functionCalls(){var e,t,n,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>1&&console.warn("there are multiple candidates in the response, returning function calls from the first one.");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>1&&console.warn("there are multiple candidates in the response, returning executable code from the first one.");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>1&&console.warn("there are multiple candidates in the response, returning code execution result from the first one.");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}}class _e{}class Se{}class Ae{}class Ce{}class Oe{}class be{}class Re{}class we{}class Ne{}class Pe{}class Me{_fromAPIResponse({apiResponse:e,_isVertexAI:t}){const n=new Me;let o;const i=e;return o=t?fe(i):he(i),Object.assign(n,o),n}}class De{}class Ue{}class xe{}class Le{}class ke{}class qe{}class Ge{}class Fe{_fromAPIResponse({apiResponse:e,_isVertexAI:t}){const n=new Fe,o=me(e);return Object.assign(n,o),n}}class He{}class je{}class Ve{}class Be{}class Je{}class $e{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>0&&console.warn(`there are non-text parts ${r} in the response, returning concatenation of all text parts. Please refer to the non text parts for a full response from model.`),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>0&&console.warn(`there are non-data parts ${i} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`),o.length>0?btoa(o):void 0}}class Ye{get audioChunk(){if(this.serverContent&&this.serverContent.audioChunks&&this.serverContent.audioChunks.length>0)return this.serverContent.audioChunks[0]}}class Ke{_fromAPIResponse({apiResponse:e,_isVertexAI:t}){const n=new Ke,o=ge(e);return Object.assign(n,o),n}}
28
+ /**
29
+ * @license
30
+ * Copyright 2025 Google LLC
31
+ * SPDX-License-Identifier: Apache-2.0
32
+ */function We(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 ze(e,t){const n=We(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 Xe(e){return Array.isArray(e)?e.map(e=>Qe(e)):[Qe(e)]}function Qe(e){if("object"==typeof e&&null!==e)return e;throw new Error("Could not parse input as Blob. Unsupported blob type: "+typeof e)}function Ze(e){const t=Qe(e);if(t.mimeType&&t.mimeType.startsWith("image/"))return t;throw new Error(`Unsupported mime type: ${t.mimeType}`)}function et(e){const t=Qe(e);if(t.mimeType&&t.mimeType.startsWith("audio/"))return t;throw new Error(`Unsupported mime type: ${t.mimeType}`)}function tt(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 nt(e){if(null==e||Array.isArray(e)&&0===e.length)throw new Error("PartListUnion is required");return Array.isArray(e)?e.map(e=>tt(e)):[tt(e)]}function ot(e){return null!=e&&"object"==typeof e&&"parts"in e&&Array.isArray(e.parts)}function it(e){return null!=e&&"object"==typeof e&&"functionCall"in e}function rt(e){return null!=e&&"object"==typeof e&&"functionResponse"in e}function st(e){if(null==e)throw new Error("ContentUnion is required");return ot(e)?e:{role:"user",parts:nt(e)}}function lt(e,t){if(!t)return[];if(e.isVertexAI()&&Array.isArray(t))return t.flatMap(e=>{const t=st(e);return t.parts&&t.parts.length>0&&void 0!==t.parts[0].text?[t.parts[0].text]:[]});if(e.isVertexAI()){const e=st(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=>st(e)):[st(t)]}function at(e){if(null==e||Array.isArray(e)&&0===e.length)throw new Error("contents are required");if(!Array.isArray(e)){if(it(e)||rt(e))throw new Error("To specify functionCall or functionResponse parts, please wrap them in a Content object, specifying the role for them");return[st(e)]}const t=[],n=[],o=ot(e[0]);for(const i of e){const e=ot(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(it(i)||rt(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:nt(n)}),t}function ut(t){const n={},o=["items"],i=["anyOf"],r=["properties"];if(t.type&&t.anyOf)throw new Error("type and anyOf cannot be both populated.");const s=t.anyOf;null!=s&&2==s.length&&("null"===s[0].type?(n.nullable=!0,t=s[1]):"null"===s[1].type&&(n.nullable=!0,t=s[0])),t.type instanceof Array&&function(t,n){t.includes("null")&&(n.nullable=!0);const o=t.filter(e=>"null"!==e);if(1===o.length)n.type=Object.values(e.Type).includes(o[0].toUpperCase())?o[0].toUpperCase():e.Type.TYPE_UNSPECIFIED;else{n.anyOf=[];for(const t of o)n.anyOf.push({type:Object.values(e.Type).includes(t.toUpperCase())?t.toUpperCase():e.Type.TYPE_UNSPECIFIED})}}(t.type,n);for(const[s,l]of Object.entries(t))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;n.type=Object.values(e.Type).includes(l.toUpperCase())?l.toUpperCase():e.Type.TYPE_UNSPECIFIED}else if(o.includes(s))n[s]=ut(l);else if(i.includes(s)){const e=[];for(const t of l)"null"!=t.type?e.push(ut(t)):n.nullable=!0;n[s]=e}else if(r.includes(s)){const e={};for(const[t,n]of Object.entries(l))e[t]=ut(n);n[s]=e}else{if("additionalProperties"===s)continue;n[s]=l}return n}function ct(e){return ut(e)}function pt(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 dt(e){if("multiSpeakerVoiceConfig"in e)throw new Error("multiSpeakerVoiceConfig is not supported in the live API.");return e}function ht(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=ut(t.parameters)),t.response&&(Object.keys(t.response).includes("$schema")?t.responseJsonSchema||(t.responseJsonSchema=t.response,delete t.response):t.response=ut(t.response));return e}function ft(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 mt(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 gt(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 yt(e){return de(e)}function vt(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 Et(e,t){let n;return n=e.isVertexAI()?t?"publishers/google/models":"models":t?"models":"tunedModels",n}function Tt(e){for(const t of["models","tunedModels","publisherModels"])if(It(e,t))return e[t];return[]}function It(e,t){return null!==e&&"object"==typeof e&&t in e}function _t(e,t={}){const n=e,o={name:n.name,description:n.description,parametersJsonSchema:n.inputSchema};n.outputSchema&&(o.responseJsonSchema=n.outputSchema),t.behavior&&(o.behavior=t.behavior);return{functionDeclarations:[o]}}function St(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://"))throw new Error(`Unsupported string source for Vertex AI: ${t}`);n={format:"bigquery",bigqueryUri: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].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` or `bigqueryUri` 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 At(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 e of o){if("object"!=typeof e||null===e)continue;const t=e.response;if("object"!=typeof t||null===t)continue;if(void 0!==t.embedding){i=!0;break}}return i&&(t.inlinedEmbedContentResponses=t.inlinedResponses,delete t.inlinedResponses),e}function Ct(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 Ot(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}
33
+ /**
34
+ * @license
35
+ * Copyright 2025 Google LLC
36
+ * SPDX-License-Identifier: Apache-2.0
37
+ */
38
+ function bt(e){const t={},n=ce(e,["responsesFile"]);null!=n&&ue(t,["fileName"],n);const o=ce(e,["inlinedResponses","inlinedResponses"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["response"]);null!=n&&ue(t,["response"],function(e){const t={},n=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["candidates"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["content"]);null!=n&&ue(t,["content"],n);const o=ce(e,["citationMetadata"]);null!=o&&ue(t,["citationMetadata"],function(e){const t={},n=ce(e,["citationSources"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["citations"],e)}return t}(o));const i=ce(e,["tokenCount"]);null!=i&&ue(t,["tokenCount"],i);const r=ce(e,["finishReason"]);null!=r&&ue(t,["finishReason"],r);const s=ce(e,["avgLogprobs"]);null!=s&&ue(t,["avgLogprobs"],s);const l=ce(e,["groundingMetadata"]);null!=l&&ue(t,["groundingMetadata"],l);const a=ce(e,["index"]);null!=a&&ue(t,["index"],a);const u=ce(e,["logprobsResult"]);null!=u&&ue(t,["logprobsResult"],u);const c=ce(e,["safetyRatings"]);if(null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["safetyRatings"],e)}const p=ce(e,["urlContextMetadata"]);null!=p&&ue(t,["urlContextMetadata"],p);return t}(e))),ue(t,["candidates"],e)}const i=ce(e,["modelVersion"]);null!=i&&ue(t,["modelVersion"],i);const r=ce(e,["promptFeedback"]);null!=r&&ue(t,["promptFeedback"],r);const s=ce(e,["responseId"]);null!=s&&ue(t,["responseId"],s);const l=ce(e,["usageMetadata"]);null!=l&&ue(t,["usageMetadata"],l);return t}(n));const o=ce(e,["metadata"]);null!=o&&ue(t,["metadata"],o);const i=ce(e,["error"]);null!=i&&ue(t,["error"],i);return t}(e))),ue(t,["inlinedResponses"],e)}const i=ce(e,["inlinedEmbedContentResponses","inlinedResponses"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["inlinedEmbedContentResponses"],e)}return t}function Rt(e){const t={},n=ce(e,["name"]);null!=n&&ue(t,["name"],n);const o=ce(e,["metadata","displayName"]);null!=o&&ue(t,["displayName"],o);const i=ce(e,["metadata","state"]);null!=i&&ue(t,["state"],Ot(i));const r=ce(e,["metadata","createTime"]);null!=r&&ue(t,["createTime"],r);const s=ce(e,["metadata","endTime"]);null!=s&&ue(t,["endTime"],s);const l=ce(e,["metadata","updateTime"]);null!=l&&ue(t,["updateTime"],l);const a=ce(e,["metadata","model"]);null!=a&&ue(t,["model"],a);const u=ce(e,["metadata","output"]);return null!=u&&ue(t,["dest"],bt(At(u))),t}function wt(e){const t={},n=ce(e,["name"]);null!=n&&ue(t,["name"],n);const o=ce(e,["displayName"]);null!=o&&ue(t,["displayName"],o);const i=ce(e,["state"]);null!=i&&ue(t,["state"],Ot(i));const r=ce(e,["error"]);null!=r&&ue(t,["error"],r);const s=ce(e,["createTime"]);null!=s&&ue(t,["createTime"],s);const l=ce(e,["startTime"]);null!=l&&ue(t,["startTime"],l);const a=ce(e,["endTime"]);null!=a&&ue(t,["endTime"],a);const u=ce(e,["updateTime"]);null!=u&&ue(t,["updateTime"],u);const c=ce(e,["model"]);null!=c&&ue(t,["model"],c);const p=ce(e,["inputConfig"]);null!=p&&ue(t,["src"],function(e){const t={},n=ce(e,["instancesFormat"]);null!=n&&ue(t,["format"],n);const o=ce(e,["gcsSource","uris"]);null!=o&&ue(t,["gcsUri"],o);const i=ce(e,["bigquerySource","inputUri"]);null!=i&&ue(t,["bigqueryUri"],i);return t}(p));const d=ce(e,["outputConfig"]);null!=d&&ue(t,["dest"],function(e){const t={},n=ce(e,["predictionsFormat"]);null!=n&&ue(t,["format"],n);const o=ce(e,["gcsDestination","outputUriPrefix"]);null!=o&&ue(t,["gcsUri"],o);const i=ce(e,["bigqueryDestination","outputUri"]);return null!=i&&ue(t,["bigqueryUri"],i),t}(At(d)));const h=ce(e,["completionStats"]);return null!=h&&ue(t,["completionStats"],h),t}function Nt(e,t){const n={};if(void 0!==ce(t,["format"]))throw new Error("format parameter is not supported in Gemini API.");if(void 0!==ce(t,["gcsUri"]))throw new Error("gcsUri parameter is not supported in Gemini API.");if(void 0!==ce(t,["bigqueryUri"]))throw new Error("bigqueryUri parameter is not supported in Gemini API.");const o=ce(t,["fileName"]);null!=o&&ue(n,["fileName"],o);const i=ce(t,["inlinedRequests"]);if(null!=i){let t=i;Array.isArray(t)&&(t=t.map(t=>function(e,t){const n={},o=ce(t,["model"]);null!=o&&ue(n,["request","model"],We(e,o));const i=ce(t,["contents"]);if(null!=i){let e=at(i);Array.isArray(e)&&(e=e.map(e=>Pt(e))),ue(n,["request","contents"],e)}const r=ce(t,["metadata"]);null!=r&&ue(n,["metadata"],r);const s=ce(t,["config"]);null!=s&&ue(n,["request","generationConfig"],function(e,t,n){const o={},i=ce(t,["systemInstruction"]);void 0!==n&&null!=i&&ue(n,["systemInstruction"],Pt(st(i)));const r=ce(t,["temperature"]);null!=r&&ue(o,["temperature"],r);const s=ce(t,["topP"]);null!=s&&ue(o,["topP"],s);const l=ce(t,["topK"]);null!=l&&ue(o,["topK"],l);const a=ce(t,["candidateCount"]);null!=a&&ue(o,["candidateCount"],a);const u=ce(t,["maxOutputTokens"]);null!=u&&ue(o,["maxOutputTokens"],u);const c=ce(t,["stopSequences"]);null!=c&&ue(o,["stopSequences"],c);const p=ce(t,["responseLogprobs"]);null!=p&&ue(o,["responseLogprobs"],p);const d=ce(t,["logprobs"]);null!=d&&ue(o,["logprobs"],d);const h=ce(t,["presencePenalty"]);null!=h&&ue(o,["presencePenalty"],h);const f=ce(t,["frequencyPenalty"]);null!=f&&ue(o,["frequencyPenalty"],f);const m=ce(t,["seed"]);null!=m&&ue(o,["seed"],m);const g=ce(t,["responseMimeType"]);null!=g&&ue(o,["responseMimeType"],g);const y=ce(t,["responseSchema"]);null!=y&&ue(o,["responseSchema"],ct(y));const v=ce(t,["responseJsonSchema"]);null!=v&&ue(o,["responseJsonSchema"],v);if(void 0!==ce(t,["routingConfig"]))throw new Error("routingConfig parameter is not supported in Gemini API.");if(void 0!==ce(t,["modelSelectionConfig"]))throw new Error("modelSelectionConfig parameter is not supported in Gemini API.");const E=ce(t,["safetySettings"]);if(void 0!==n&&null!=E){let e=E;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["category"]);null!=n&&ue(t,["category"],n);if(void 0!==ce(e,["method"]))throw new Error("method parameter is not supported in Gemini API.");const o=ce(e,["threshold"]);null!=o&&ue(t,["threshold"],o);return t}(e))),ue(n,["safetySettings"],e)}const T=ce(t,["tools"]);if(void 0!==n&&null!=T){let e=ft(T);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==ce(e,["retrieval"]))throw new Error("retrieval parameter is not supported in Gemini API.");const n=ce(e,["computerUse"]);null!=n&&ue(t,["computerUse"],n);const o=ce(e,["fileSearch"]);null!=o&&ue(t,["fileSearch"],o);const i=ce(e,["codeExecution"]);null!=i&&ue(t,["codeExecution"],i);if(void 0!==ce(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const r=ce(e,["functionDeclarations"]);if(null!=r){let e=r;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["functionDeclarations"],e)}const s=ce(e,["googleMaps"]);null!=s&&ue(t,["googleMaps"],function(e){const t={};if(void 0!==ce(e,["authConfig"]))throw new Error("authConfig parameter is not supported in Gemini API.");const n=ce(e,["enableWidget"]);null!=n&&ue(t,["enableWidget"],n);return t}(s));const l=ce(e,["googleSearch"]);null!=l&&ue(t,["googleSearch"],function(e){const t={};if(void 0!==ce(e,["excludeDomains"]))throw new Error("excludeDomains parameter is not supported in Gemini API.");if(void 0!==ce(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is not supported in Gemini API.");const n=ce(e,["timeRangeFilter"]);null!=n&&ue(t,["timeRangeFilter"],n);return t}(l));const a=ce(e,["googleSearchRetrieval"]);null!=a&&ue(t,["googleSearchRetrieval"],a);const u=ce(e,["urlContext"]);null!=u&&ue(t,["urlContext"],u);return t}
39
+ /**
40
+ * @license
41
+ * Copyright 2025 Google LLC
42
+ * SPDX-License-Identifier: Apache-2.0
43
+ */(ht(e)))),ue(n,["tools"],e)}const I=ce(t,["toolConfig"]);void 0!==n&&null!=I&&ue(n,["toolConfig"],function(e){const t={},n=ce(e,["retrievalConfig"]);null!=n&&ue(t,["retrievalConfig"],n);const o=ce(e,["functionCallingConfig"]);null!=o&&ue(t,["functionCallingConfig"],function(e){const t={},n=ce(e,["allowedFunctionNames"]);null!=n&&ue(t,["allowedFunctionNames"],n);const o=ce(e,["mode"]);null!=o&&ue(t,["mode"],o);if(void 0!==ce(e,["streamFunctionCallArguments"]))throw new Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return t}(o));return t}(I));if(void 0!==ce(t,["labels"]))throw new Error("labels parameter is not supported in Gemini API.");const _=ce(t,["cachedContent"]);void 0!==n&&null!=_&&ue(n,["cachedContent"],mt(e,_));const S=ce(t,["responseModalities"]);null!=S&&ue(o,["responseModalities"],S);const A=ce(t,["mediaResolution"]);null!=A&&ue(o,["mediaResolution"],A);const C=ce(t,["speechConfig"]);null!=C&&ue(o,["speechConfig"],pt(C));if(void 0!==ce(t,["audioTimestamp"]))throw new Error("audioTimestamp parameter is not supported in Gemini API.");const O=ce(t,["thinkingConfig"]);null!=O&&ue(o,["thinkingConfig"],O);const b=ce(t,["imageConfig"]);null!=b&&ue(o,["imageConfig"],function(e){const t={},n=ce(e,["aspectRatio"]);null!=n&&ue(t,["aspectRatio"],n);const o=ce(e,["imageSize"]);null!=o&&ue(t,["imageSize"],o);if(void 0!==ce(e,["personGeneration"]))throw new Error("personGeneration parameter is not supported in Gemini API.");if(void 0!==ce(e,["outputMimeType"]))throw new Error("outputMimeType parameter is not supported in Gemini API.");if(void 0!==ce(e,["outputCompressionQuality"]))throw new Error("outputCompressionQuality parameter is not supported in Gemini API.");return t}(b));const R=ce(t,["enableEnhancedCivicAnswers"]);null!=R&&ue(o,["enableEnhancedCivicAnswers"],R);if(void 0!==ce(t,["modelArmorConfig"]))throw new Error("modelArmorConfig parameter is not supported in Gemini API.");return o}(e,s,ce(n,["request"],{})));return n}(e,t))),ue(n,["requests","requests"],t)}return n}function Pt(e){const t={},n=ce(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["mediaResolution"]);null!=n&&ue(t,["mediaResolution"],n);const o=ce(e,["codeExecutionResult"]);null!=o&&ue(t,["codeExecutionResult"],o);const i=ce(e,["executableCode"]);null!=i&&ue(t,["executableCode"],i);const r=ce(e,["fileData"]);null!=r&&ue(t,["fileData"],function(e){const t={};if(void 0!==ce(e,["displayName"]))throw new Error("displayName parameter is not supported in Gemini API.");const n=ce(e,["fileUri"]);null!=n&&ue(t,["fileUri"],n);const o=ce(e,["mimeType"]);null!=o&&ue(t,["mimeType"],o);return t}(r));const s=ce(e,["functionCall"]);null!=s&&ue(t,["functionCall"],function(e){const t={},n=ce(e,["id"]);null!=n&&ue(t,["id"],n);const o=ce(e,["args"]);null!=o&&ue(t,["args"],o);const i=ce(e,["name"]);null!=i&&ue(t,["name"],i);if(void 0!==ce(e,["partialArgs"]))throw new Error("partialArgs parameter is not supported in Gemini API.");if(void 0!==ce(e,["willContinue"]))throw new Error("willContinue parameter is not supported in Gemini API.");return t}(s));const l=ce(e,["functionResponse"]);null!=l&&ue(t,["functionResponse"],l);const a=ce(e,["inlineData"]);null!=a&&ue(t,["inlineData"],function(e){const t={},n=ce(e,["data"]);if(null!=n&&ue(t,["data"],n),void 0!==ce(e,["displayName"]))throw new Error("displayName parameter is not supported in Gemini API.");const o=ce(e,["mimeType"]);return null!=o&&ue(t,["mimeType"],o),t}(a));const u=ce(e,["text"]);null!=u&&ue(t,["text"],u);const c=ce(e,["thought"]);null!=c&&ue(t,["thought"],c);const p=ce(e,["thoughtSignature"]);null!=p&&ue(t,["thoughtSignature"],p);const d=ce(e,["videoMetadata"]);null!=d&&ue(t,["videoMetadata"],d);return t}(e))),ue(t,["parts"],e)}const o=ce(e,["role"]);return null!=o&&ue(t,["role"],o),t}function Mt(e,t){const n=ce(e,["displayName"]);void 0!==t&&null!=n&&ue(t,["displayName"],n);const o=ce(e,["dest"]);return void 0!==t&&null!=o&&ue(t,["outputConfig"],function(e){const t={},n=ce(e,["format"]);null!=n&&ue(t,["predictionsFormat"],n);const o=ce(e,["gcsUri"]);null!=o&&ue(t,["gcsDestination","outputUriPrefix"],o);const i=ce(e,["bigqueryUri"]);if(null!=i&&ue(t,["bigqueryDestination","outputUri"],i),void 0!==ce(e,["fileName"]))throw new Error("fileName parameter is not supported in Vertex AI.");if(void 0!==ce(e,["inlinedResponses"]))throw new Error("inlinedResponses parameter is not supported in Vertex AI.");if(void 0!==ce(e,["inlinedEmbedContentResponses"]))throw new Error("inlinedEmbedContentResponses parameter is not supported in Vertex AI.");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))),{}}function Dt(e,t){const n={},o=ce(t,["model"]);null!=o&&ue(n,["_url","model"],We(e,o));const i=ce(t,["src"]);null!=i&&ue(n,["batch","inputConfig"],Nt(e,St(e,i)));const r=ce(t,["config"]);return null!=r&&function(e,t){const n=ce(e,["displayName"]);if(void 0!==t&&null!=n&&ue(t,["batch","displayName"],n),void 0!==ce(e,["dest"]))throw new Error("dest parameter is not supported in Gemini API.")}(r,n),n}function Ut(e,t){const n={},o=ce(t,["model"]);null!=o&&ue(n,["model"],We(e,o));const i=ce(t,["src"]);null!=i&&ue(n,["inputConfig"],function(e){const t={},n=ce(e,["format"]);null!=n&&ue(t,["instancesFormat"],n);const o=ce(e,["gcsUri"]);null!=o&&ue(t,["gcsSource","uris"],o);const i=ce(e,["bigqueryUri"]);if(null!=i&&ue(t,["bigquerySource","inputUri"],i),void 0!==ce(e,["fileName"]))throw new Error("fileName parameter is not supported in Vertex AI.");if(void 0!==ce(e,["inlinedRequests"]))throw new Error("inlinedRequests parameter is not supported in Vertex AI.");return t}(St(e,i)));const r=ce(t,["config"]);return null!=r&&Mt(r,n),n}function xt(e,t){const n={},o=ce(t,["model"]);null!=o&&ue(n,["_url","model"],We(e,o));const i=ce(t,["src"]);null!=i&&ue(n,["batch","inputConfig"],function(e,t){const n={},o=ce(t,["fileName"]);null!=o&&ue(n,["file_name"],o);const i=ce(t,["inlinedRequests"]);null!=i&&ue(n,["requests"],function(e,t){const n={},o=ce(t,["contents"]);if(null!=o){let t=lt(e,o);Array.isArray(t)&&(t=t.map(e=>e)),ue(n,["requests[]","request","content"],t)}const i=ce(t,["config"]);null!=i&&(ue(n,["_self"],function(e,t){const n={},o=ce(e,["taskType"]);void 0!==t&&null!=o&&ue(t,["requests[]","taskType"],o);const i=ce(e,["title"]);void 0!==t&&null!=i&&ue(t,["requests[]","title"],i);const r=ce(e,["outputDimensionality"]);void 0!==t&&null!=r&&ue(t,["requests[]","outputDimensionality"],r);if(void 0!==ce(e,["mimeType"]))throw new Error("mimeType parameter is not supported in Gemini API.");if(void 0!==ce(e,["autoTruncate"]))throw new Error("autoTruncate parameter is not supported in Gemini API.");return n}(i,n)),function(e,t){for(const[n,o]of Object.entries(t)){const t=n.split("."),i=o.split("."),r=new Set;let s=-1;for(let e=0;e<t.length;e++)if("*"===t[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)}pe(e,t,i,0,r)}}(n,{"requests[].*":"requests[].request.*"}));return n}(e,i));return n}(e,i));const r=ce(t,["config"]);return null!=r&&function(e,t){const n=ce(e,["displayName"]);void 0!==t&&null!=n&&ue(t,["batch","displayName"],n)}(r,n),n}function Lt(e){const t={},n=ce(e,["config"]);return null!=n&&function(e,t){const n=ce(e,["pageSize"]);void 0!==t&&null!=n&&ue(t,["_query","pageSize"],n);const o=ce(e,["pageToken"]);if(void 0!==t&&null!=o&&ue(t,["_query","pageToken"],o),void 0!==ce(e,["filter"]))throw new Error("filter parameter is not supported in Gemini API.")}(n,t),t}function kt(e){const t={},n=ce(e,["config"]);return null!=n&&function(e,t){const n=ce(e,["pageSize"]);void 0!==t&&null!=n&&ue(t,["_query","pageSize"],n);const o=ce(e,["pageToken"]);void 0!==t&&null!=o&&ue(t,["_query","pageToken"],o);const i=ce(e,["filter"]);void 0!==t&&null!=i&&ue(t,["_query","filter"],i)}(n,t),t}e.PagedItem=void 0,(re=e.PagedItem||(e.PagedItem={})).PAGED_ITEM_BATCH_JOBS="batchJobs",re.PAGED_ITEM_MODELS="models",re.PAGED_ITEM_TUNING_JOBS="tuningJobs",re.PAGED_ITEM_FILES="files",re.PAGED_ITEM_CACHED_CONTENTS="cachedContents",re.PAGED_ITEM_FILE_SEARCH_STORES="fileSearchStores",re.PAGED_ITEM_DOCUMENTS="documents";class qt{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)}}
44
+ /**
45
+ * @license
46
+ * Copyright 2025 Google LLC
47
+ * SPDX-License-Identifier: Apache-2.0
48
+ */class Gt extends le{constructor(t){super(),this.apiClient=t,this.list=async(t={})=>new qt(e.PagedItem.PAGED_ITEM_BATCH_JOBS,e=>this.listInternal(e),await this.listInternal(t),t),this.create=async e=>(this.apiClient.isVertexAI()&&(e.config=this.formatDestination(e.src,e.config)),this.createInternal(e)),this.createEmbeddings=async e=>{if(console.warn("batches.createEmbeddings() is experimental and may change without notice."),this.apiClient.isVertexAI())throw new Error("Vertex AI does not support batches.createEmbeddings.");return this.createEmbeddingsInternal(e)}}createInlinedGenerateContentRequest(e){const t=Dt(this.apiClient,e),n=ae("{model}:batchGenerateContent",t._url),o=t.batch.inputConfig.requests,i=o.requests,r=[];for(const e of i){const t=Object.assign({},e);if(t.systemInstruction){const e=t.systemInstruction;delete t.systemInstruction;const n=t.request;n.systemInstruction=e,t.request=n}r.push(t)}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 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=Ut(this.apiClient,e);return s=ae("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=>wt(e))}{const t=Dt(this.apiClient,e);return s=ae("{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=>Rt(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=xt(this.apiClient,e);return i=ae("{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=>Rt(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=ce(t,["name"]);return null!=o&&ue(n,["_url","name"],Ct(e,o)),n}(this.apiClient,e);return s=ae("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=>wt(e))}{const t=function(e,t){const n={},o=ce(t,["name"]);return null!=o&&ue(n,["_url","name"],Ct(e,o)),n}(this.apiClient,e);return s=ae("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=>Rt(e))}}async cancel(e){var t,n,o,i;let r="",s={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=ce(t,["name"]);return null!=o&&ue(n,["_url","name"],Ct(e,o)),n}(this.apiClient,e);r=ae("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=ce(t,["name"]);return null!=o&&ue(n,["_url","name"],Ct(e,o)),n}(this.apiClient,e);r=ae("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=kt(e);return s=ae("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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["nextPageToken"]);null!=o&&ue(t,["nextPageToken"],o);const i=ce(e,["batchPredictionJobs"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>wt(e))),ue(t,["batchJobs"],e)}return t}(e),n=new Je;return Object.assign(n,t),n})}{const t=Lt(e);return s=ae("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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["nextPageToken"]);null!=o&&ue(t,["nextPageToken"],o);const i=ce(e,["operations"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>Rt(e))),ue(t,["batchJobs"],e)}return t}(e),n=new Je;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=ce(t,["name"]);return null!=o&&ue(n,["_url","name"],Ct(e,o)),n}(this.apiClient,e);return s=ae("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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["name"]);null!=o&&ue(t,["name"],o);const i=ce(e,["done"]);null!=i&&ue(t,["done"],i);const r=ce(e,["error"]);return null!=r&&ue(t,["error"],r),t}(e))}{const t=function(e,t){const n={},o=ce(t,["name"]);return null!=o&&ue(n,["_url","name"],Ct(e,o)),n}(this.apiClient,e);return s=ae("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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["name"]);null!=o&&ue(t,["name"],o);const i=ce(e,["done"]);null!=i&&ue(t,["done"],i);const r=ce(e,["error"]);return null!=r&&ue(t,["error"],r),t}(e))}}}
49
+ /**
50
+ * @license
51
+ * Copyright 2025 Google LLC
52
+ * SPDX-License-Identifier: Apache-2.0
53
+ */function Ft(e){const t={},n=ce(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["mediaResolution"]);null!=n&&ue(t,["mediaResolution"],n);const o=ce(e,["codeExecutionResult"]);null!=o&&ue(t,["codeExecutionResult"],o);const i=ce(e,["executableCode"]);null!=i&&ue(t,["executableCode"],i);const r=ce(e,["fileData"]);null!=r&&ue(t,["fileData"],function(e){const t={};if(void 0!==ce(e,["displayName"]))throw new Error("displayName parameter is not supported in Gemini API.");const n=ce(e,["fileUri"]);null!=n&&ue(t,["fileUri"],n);const o=ce(e,["mimeType"]);null!=o&&ue(t,["mimeType"],o);return t}(r));const s=ce(e,["functionCall"]);null!=s&&ue(t,["functionCall"],function(e){const t={},n=ce(e,["id"]);null!=n&&ue(t,["id"],n);const o=ce(e,["args"]);null!=o&&ue(t,["args"],o);const i=ce(e,["name"]);null!=i&&ue(t,["name"],i);if(void 0!==ce(e,["partialArgs"]))throw new Error("partialArgs parameter is not supported in Gemini API.");if(void 0!==ce(e,["willContinue"]))throw new Error("willContinue parameter is not supported in Gemini API.");return t}(s));const l=ce(e,["functionResponse"]);null!=l&&ue(t,["functionResponse"],l);const a=ce(e,["inlineData"]);null!=a&&ue(t,["inlineData"],function(e){const t={},n=ce(e,["data"]);if(null!=n&&ue(t,["data"],n),void 0!==ce(e,["displayName"]))throw new Error("displayName parameter is not supported in Gemini API.");const o=ce(e,["mimeType"]);return null!=o&&ue(t,["mimeType"],o),t}(a));const u=ce(e,["text"]);null!=u&&ue(t,["text"],u);const c=ce(e,["thought"]);null!=c&&ue(t,["thought"],c);const p=ce(e,["thoughtSignature"]);null!=p&&ue(t,["thoughtSignature"],p);const d=ce(e,["videoMetadata"]);null!=d&&ue(t,["videoMetadata"],d);return t}(e))),ue(t,["parts"],e)}const o=ce(e,["role"]);return null!=o&&ue(t,["role"],o),t}function Ht(e,t){const n=ce(e,["ttl"]);void 0!==t&&null!=n&&ue(t,["ttl"],n);const o=ce(e,["expireTime"]);void 0!==t&&null!=o&&ue(t,["expireTime"],o);const i=ce(e,["displayName"]);void 0!==t&&null!=i&&ue(t,["displayName"],i);const r=ce(e,["contents"]);if(void 0!==t&&null!=r){let e=at(r);Array.isArray(e)&&(e=e.map(e=>Ft(e))),ue(t,["contents"],e)}const s=ce(e,["systemInstruction"]);void 0!==t&&null!=s&&ue(t,["systemInstruction"],Ft(st(s)));const l=ce(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!==ce(e,["retrieval"]))throw new Error("retrieval parameter is not supported in Gemini API.");const n=ce(e,["computerUse"]);null!=n&&ue(t,["computerUse"],n);const o=ce(e,["fileSearch"]);null!=o&&ue(t,["fileSearch"],o);const i=ce(e,["codeExecution"]);null!=i&&ue(t,["codeExecution"],i);if(void 0!==ce(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const r=ce(e,["functionDeclarations"]);if(null!=r){let e=r;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["functionDeclarations"],e)}const s=ce(e,["googleMaps"]);null!=s&&ue(t,["googleMaps"],function(e){const t={};if(void 0!==ce(e,["authConfig"]))throw new Error("authConfig parameter is not supported in Gemini API.");const n=ce(e,["enableWidget"]);null!=n&&ue(t,["enableWidget"],n);return t}(s));const l=ce(e,["googleSearch"]);null!=l&&ue(t,["googleSearch"],function(e){const t={};if(void 0!==ce(e,["excludeDomains"]))throw new Error("excludeDomains parameter is not supported in Gemini API.");if(void 0!==ce(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is not supported in Gemini API.");const n=ce(e,["timeRangeFilter"]);null!=n&&ue(t,["timeRangeFilter"],n);return t}(l));const a=ce(e,["googleSearchRetrieval"]);null!=a&&ue(t,["googleSearchRetrieval"],a);const u=ce(e,["urlContext"]);null!=u&&ue(t,["urlContext"],u);return t}(e))),ue(t,["tools"],e)}const a=ce(e,["toolConfig"]);if(void 0!==t&&null!=a&&ue(t,["toolConfig"],function(e){const t={},n=ce(e,["retrievalConfig"]);null!=n&&ue(t,["retrievalConfig"],n);const o=ce(e,["functionCallingConfig"]);null!=o&&ue(t,["functionCallingConfig"],function(e){const t={},n=ce(e,["allowedFunctionNames"]);null!=n&&ue(t,["allowedFunctionNames"],n);const o=ce(e,["mode"]);null!=o&&ue(t,["mode"],o);if(void 0!==ce(e,["streamFunctionCallArguments"]))throw new Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return t}(o));return t}(a)),void 0!==ce(e,["kmsKeyName"]))throw new Error("kmsKeyName parameter is not supported in Gemini API.");return{}}function jt(e,t){const n=ce(e,["ttl"]);void 0!==t&&null!=n&&ue(t,["ttl"],n);const o=ce(e,["expireTime"]);void 0!==t&&null!=o&&ue(t,["expireTime"],o);const i=ce(e,["displayName"]);void 0!==t&&null!=i&&ue(t,["displayName"],i);const r=ce(e,["contents"]);if(void 0!==t&&null!=r){let e=at(r);Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["contents"],e)}const s=ce(e,["systemInstruction"]);void 0!==t&&null!=s&&ue(t,["systemInstruction"],st(s));const l=ce(e,["tools"]);if(void 0!==t&&null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["retrieval"]);null!=n&&ue(t,["retrieval"],n);const o=ce(e,["computerUse"]);null!=o&&ue(t,["computerUse"],o);if(void 0!==ce(e,["fileSearch"]))throw new Error("fileSearch parameter is not supported in Vertex AI.");const i=ce(e,["codeExecution"]);null!=i&&ue(t,["codeExecution"],i);const r=ce(e,["enterpriseWebSearch"]);null!=r&&ue(t,["enterpriseWebSearch"],r);const s=ce(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["description"]);null!=n&&ue(t,["description"],n);const o=ce(e,["name"]);null!=o&&ue(t,["name"],o);const i=ce(e,["parameters"]);null!=i&&ue(t,["parameters"],i);const r=ce(e,["parametersJsonSchema"]);null!=r&&ue(t,["parametersJsonSchema"],r);const s=ce(e,["response"]);null!=s&&ue(t,["response"],s);const l=ce(e,["responseJsonSchema"]);null!=l&&ue(t,["responseJsonSchema"],l);if(void 0!==ce(e,["behavior"]))throw new Error("behavior parameter is not supported in Vertex AI.");return t}(e))),ue(t,["functionDeclarations"],e)}const l=ce(e,["googleMaps"]);null!=l&&ue(t,["googleMaps"],l);const a=ce(e,["googleSearch"]);null!=a&&ue(t,["googleSearch"],a);const u=ce(e,["googleSearchRetrieval"]);null!=u&&ue(t,["googleSearchRetrieval"],u);const c=ce(e,["urlContext"]);null!=c&&ue(t,["urlContext"],c);return t}(e))),ue(t,["tools"],e)}const a=ce(e,["toolConfig"]);void 0!==t&&null!=a&&ue(t,["toolConfig"],a);const u=ce(e,["kmsKeyName"]);return void 0!==t&&null!=u&&ue(t,["encryption_spec","kmsKeyName"],u),{}}function Vt(e){const t={},n=ce(e,["config"]);return null!=n&&function(e,t){const n=ce(e,["pageSize"]);void 0!==t&&null!=n&&ue(t,["_query","pageSize"],n);const o=ce(e,["pageToken"]);void 0!==t&&null!=o&&ue(t,["_query","pageToken"],o)}(n,t),t}function Bt(e){const t={},n=ce(e,["config"]);return null!=n&&function(e,t){const n=ce(e,["pageSize"]);void 0!==t&&null!=n&&ue(t,["_query","pageSize"],n);const o=ce(e,["pageToken"]);void 0!==t&&null!=o&&ue(t,["_query","pageToken"],o)}(n,t),t}function Jt(e,t){const n={},o=ce(t,["name"]);null!=o&&ue(n,["_url","name"],mt(e,o));const i=ce(t,["config"]);return null!=i&&function(e,t){const n=ce(e,["ttl"]);void 0!==t&&null!=n&&ue(t,["ttl"],n);const o=ce(e,["expireTime"]);void 0!==t&&null!=o&&ue(t,["expireTime"],o)}(i,n),n}function $t(e,t){const n={},o=ce(t,["name"]);null!=o&&ue(n,["_url","name"],mt(e,o));const i=ce(t,["config"]);return null!=i&&function(e,t){const n=ce(e,["ttl"]);void 0!==t&&null!=n&&ue(t,["ttl"],n);const o=ce(e,["expireTime"]);void 0!==t&&null!=o&&ue(t,["expireTime"],o)}(i,n),n}
54
+ /**
55
+ * @license
56
+ * Copyright 2025 Google LLC
57
+ * SPDX-License-Identifier: Apache-2.0
58
+ */class Yt extends le{constructor(t){super(),this.apiClient=t,this.list=async(t={})=>new qt(e.PagedItem.PAGED_ITEM_CACHED_CONTENTS,e=>this.listInternal(e),await this.listInternal(t),t)}async create(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e,t){const n={},o=ce(t,["model"]);null!=o&&ue(n,["model"],ze(e,o));const i=ce(t,["config"]);return null!=i&&jt(i,n),n}(this.apiClient,e);return s=ae("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=ce(t,["model"]);null!=o&&ue(n,["model"],ze(e,o));const i=ce(t,["config"]);return null!=i&&Ht(i,n),n}(this.apiClient,e);return s=ae("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=ce(t,["name"]);return null!=o&&ue(n,["_url","name"],mt(e,o)),n}(this.apiClient,e);return s=ae("{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=ce(t,["name"]);return null!=o&&ue(n,["_url","name"],mt(e,o)),n}(this.apiClient,e);return s=ae("{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=ce(t,["name"]);return null!=o&&ue(n,["_url","name"],mt(e,o)),n}(this.apiClient,e);return s=ae("{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=ce(e,["sdkHttpResponse"]);return null!=n&&ue(t,["sdkHttpResponse"],n),t}(e),n=new xe;return Object.assign(n,t),n})}{const t=function(e,t){const n={},o=ce(t,["name"]);return null!=o&&ue(n,["_url","name"],mt(e,o)),n}(this.apiClient,e);return s=ae("{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=ce(e,["sdkHttpResponse"]);return null!=n&&ue(t,["sdkHttpResponse"],n),t}(e),n=new xe;return Object.assign(n,t),n})}}async update(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=$t(this.apiClient,e);return s=ae("{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=Jt(this.apiClient,e);return s=ae("{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=Bt(e);return s=ae("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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["nextPageToken"]);null!=o&&ue(t,["nextPageToken"],o);const i=ce(e,["cachedContents"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["cachedContents"],e)}return t}(e),n=new Le;return Object.assign(n,t),n})}{const t=Vt(e);return s=ae("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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["nextPageToken"]);null!=o&&ue(t,["nextPageToken"],o);const i=ce(e,["cachedContents"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["cachedContents"],e)}return t}(e),n=new Le;return Object.assign(n,t),n})}}}function Kt(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 Wt(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.")}function zt(e){return this instanceof zt?(this.v=e,this):new zt(e)}function Xt(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 zt?Promise.resolve(n.value.v).then(a,u):c(r[0][2],n)}catch(e){c(r[0][3],e)}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 Qt(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=Wt(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)})}}}
59
+ /**
60
+ * @license
61
+ * Copyright 2025 Google LLC
62
+ * SPDX-License-Identifier: Apache-2.0
63
+ */
64
+ function Zt(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&&en(n)}function en(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 tn(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&&!en(e[o])&&(r=!1),o++;r?t.push(...i):t.pop()}return t}"function"==typeof SuppressedError&&SuppressedError;class nn{constructor(e,t){this.modelsModule=e,this.apiClient=t}create(e){return new on(this.apiClient,this.modelsModule,e.model,e.config,structuredClone(e.history))}}class on{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=st(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=st(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?tn(this.history):this.history;return structuredClone(t)}processStreamResponse(e,t){return Xt(this,arguments,function*(){var n,o,i,r,s,l;const a=[];try{for(var u,c=!0,p=Qt(e);!(n=(u=yield zt(p.next())).done);c=!0){r=u.value,c=!1;const e=r;if(Zt(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 zt(e)}}catch(e){o={error:e}}finally{try{c||n||!(i=p.return)||(yield zt(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(...tn(n)):this.history.push(e),this.history.push(...o)}}
65
+ /**
66
+ * @license
67
+ * Copyright 2025 Google LLC
68
+ * SPDX-License-Identifier: Apache-2.0
69
+ */function rn(e){const t={},n=ce(e,["config"]);return null!=n&&function(e,t){const n=ce(e,["displayName"]);void 0!==t&&null!=n&&ue(t,["displayName"],n)}(n,t),t}function sn(e){const t={},n=ce(e,["name"]);null!=n&&ue(t,["_url","name"],n);const o=ce(e,["config"]);return null!=o&&function(e,t){const n=ce(e,["force"]);void 0!==t&&null!=n&&ue(t,["_query","force"],n)}(o,t),t}function ln(e){const t={},n=ce(e,["name"]);null!=n&&ue(t,["name"],n);const o=ce(e,["metadata"]);null!=o&&ue(t,["metadata"],o);const i=ce(e,["done"]);null!=i&&ue(t,["done"],i);const r=ce(e,["error"]);null!=r&&ue(t,["error"],r);const s=ce(e,["response"]);return null!=s&&ue(t,["response"],function(e){const t={},n=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["parent"]);null!=o&&ue(t,["parent"],o);const i=ce(e,["documentName"]);null!=i&&ue(t,["documentName"],i);return t}(s)),t}function an(e){const t={},n=ce(e,["fileSearchStoreName"]);null!=n&&ue(t,["_url","file_search_store_name"],n);const o=ce(e,["fileName"]);null!=o&&ue(t,["fileName"],o);const i=ce(e,["config"]);return null!=i&&function(e,t){const n=ce(e,["customMetadata"]);if(void 0!==t&&null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["customMetadata"],e)}const o=ce(e,["chunkingConfig"]);void 0!==t&&null!=o&&ue(t,["chunkingConfig"],o)}(i,t),t}function un(e){const t={},n=ce(e,["config"]);return null!=n&&function(e,t){const n=ce(e,["pageSize"]);void 0!==t&&null!=n&&ue(t,["_query","pageSize"],n);const o=ce(e,["pageToken"]);void 0!==t&&null!=o&&ue(t,["_query","pageToken"],o)}(n,t),t}function cn(e,t){const n=ce(e,["mimeType"]);void 0!==t&&null!=n&&ue(t,["mimeType"],n);const o=ce(e,["displayName"]);void 0!==t&&null!=o&&ue(t,["displayName"],o);const i=ce(e,["customMetadata"]);if(void 0!==t&&null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["customMetadata"],e)}const r=ce(e,["chunkingConfig"]);return void 0!==t&&null!=r&&ue(t,["chunkingConfig"],r),{}}
70
+ /**
71
+ * @license
72
+ * Copyright 2025 Google LLC
73
+ * SPDX-License-Identifier: Apache-2.0
74
+ */
75
+ class pn extends Error{constructor(e){super(e.message),this.name="ApiError",this.status=e.status,Object.setPrototypeOf(this,pn.prototype)}}
76
+ /**
77
+ * @license
78
+ * Copyright 2025 Google LLC
79
+ * SPDX-License-Identifier: Apache-2.0
80
+ */const dn="x-goog-api-client",hn=[408,429,500,502,503,504];class fn{constructor(e){var t,n,o;this.clientOptions=Object.assign({},e),this.customBaseUrl=null===(t=e.httpOptions)||void 0===t?void 0:t.baseUrl,this.clientOptions.vertexai&&(this.clientOptions.project&&this.clientOptions.location?this.clientOptions.apiKey=void 0:this.clientOptions.apiKey&&(this.clientOptions.project=void 0,this.clientOptions.location=void 0));const i={};if(this.clientOptions.vertexai){this.clientOptions.location||this.clientOptions.apiKey||this.customBaseUrl||(this.clientOptions.location="global");if(!(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||"global"===this.clientOptions.location?i.baseUrl="https://aiplatform.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{if(!this.clientOptions.apiKey)throw new pn({message:"API key must be set when using the Gemini API.",status:403});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)];n&&o.push(this.getBaseResourcePath()),""!==e&&o.push(e);return new URL(`${o.join("/")}`)}shouldPrependVertexProjectPath(t,n){return(!n.baseUrl||n.baseUrlResourceScope!==e.ResourceScope.COLLECTION)&&(!this.clientOptions.apiKey&&(!!this.clientOptions.vertexai&&(!t.path.startsWith("projects/")&&("GET"!==t.httpMethod||!t.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[t,n]of Object.entries(e.queryParams))o.searchParams.append(t,String(n));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(),e.abortSignal),this.unaryApiCall(o,i,e.httpMethod)}patchHttpOptions(e,t){const n=JSON.parse(JSON.stringify(e));for(const[e,o]of Object.entries(t))"object"==typeof o?n[e]=Object.assign(Object.assign({},n[e]),o):void 0!==o&&(n[e]=o);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(),e.abortSignal),this.streamApiCall(o,i,e.httpMethod)}async includeExtraHttpOptionsToRequestInit(e,t,n,o){if(t&&t.timeout||o){const n=new AbortController,i=n.signal;if(t.timeout&&(null==t?void 0:t.timeout)>0){const e=setTimeout(()=>n.abort(),t.timeout);e&&"function"==typeof e.unref&&e.unref()}o&&o.addEventListener("abort",()=>{n.abort()}),e.signal=i}return t&&null!==t.extraBody&&function(e,t){if(!t||0===Object.keys(t).length)return;if(e.body instanceof Blob)return void console.warn("includeExtraBodyToRequestInit: extraBody provided but current request body is a Blob. extraBody will be ignored as merging is not supported for Blob bodies.");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 void console.warn("includeExtraBodyToRequestInit: Original request body is valid JSON but not a non-array object. Skip applying extraBody to the request body.");n=t}catch(e){return void console.warn("includeExtraBodyToRequestInit: Original request body is not valid JSON. Skip applying extraBody to the request body.")}function o(e,t){const n=Object.assign({},e);for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const i=t[e],r=n[e];i&&"object"==typeof i&&!Array.isArray(i)&&r&&"object"==typeof r&&!Array.isArray(r)?n[e]=o(r,i):(r&&i&&typeof r!=typeof i&&console.warn(`includeExtraBodyToRequestInit:deepMerge: Type mismatch for key "${e}". Original type: ${typeof r}, New type: ${typeof i}. Overwriting.`),n[e]=i)}return n}const i=o(n,t);e.body=JSON.stringify(i)}
81
+ /**
82
+ * @license
83
+ * Copyright 2025 Google LLC
84
+ * SPDX-License-Identifier: Apache-2.0
85
+ */(e,t.extraBody),e.headers=await this.getHeadersInternal(t,n),e}async unaryApiCall(e,t,n){return this.apiCall(e.toString(),Object.assign(Object.assign({},t),{method:n})).then(async e=>(await mn(e),new Te(e))).catch(e=>{throw e instanceof Error?e:new Error(JSON.stringify(e))})}async streamApiCall(e,t,n){return this.apiCall(e.toString(),Object.assign(Object.assign({},t),{method:n})).then(async e=>(await mn(e),this.processStreamResponse(e))).catch(e=>{throw e instanceof Error?e:new Error(JSON.stringify(e))})}processStreamResponse(e){return Xt(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 i="data:",r=["\n\n","\r\r","\r\n\r\n"];for(;;){const{done:s,value:l}=yield zt(n.read());if(s){if(t.trim().length>0)throw new Error("Incomplete JSON segment at the end");break}const a=o.decode(l,{stream:!0});try{const e=JSON.parse(a);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 pn({message:i,status:o})}}}catch(e){if("ApiError"===e.name)throw e}t+=a;let u=-1,c=0;for(;;){u=-1,c=0;for(const e of r){const n=t.indexOf(e);-1!==n&&(-1===u||n<u)&&(u=n,c=e.length)}if(-1===u)break;const n=t.substring(0,u);t=t.substring(u+c);const o=n.trim();if(o.startsWith(i)){const t=o.substring(i.length).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 zt(new Te(n))}catch(e){throw new Error(`exception parsing stream chunk ${t}. ${e}`)}}}}}finally{n.releaseLock()}})}async apiCall(e,t){var n;if(!this.clientOptions.httpOptions||!this.clientOptions.httpOptions.retryOptions)return fetch(e,t);const o=this.clientOptions.httpOptions.retryOptions;return se(async()=>{const n=await fetch(e,t);if(n.ok)return n;if(hn.includes(n.status))throw new Error(`Retryable HTTP Error: ${n.statusText}`);throw new se.AbortError(`Non-retryable exception ${n.statusText} sending request`)},{retries:(null!==(n=o.attempts)&&void 0!==n?n:5)-1})}getDefaultHeaders(){const e={},t="google-genai-sdk/1.42.0 "+this.clientOptions.userAgentExtra;return e["User-Agent"]=t,e[dn]=t,e["Content-Type"]="application/json",e}async getHeadersInternal(e,t){const n=new Headers;if(e&&e.headers){for(const[t,o]of Object.entries(e.headers))n.append(t,o);e.timeout&&e.timeout>0&&n.append("X-Server-Timeout",String(Math.ceil(e.timeout/1e3)))}return await this.clientOptions.auth.addAuthHeaders(n,t),n}getFileName(e){var t;let n="";return"string"==typeof e&&(n=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=ae("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&&cn(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){const t=this.clientOptions.downloader;await t.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 mn(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 pn({message:i,status:n})}throw new Error(i)}}function gn(){return new Error("This feature requires the web or Node specific @google/genai implementation, you can fix this by either:\n\n*Enabling conditional exports for your project [recommended]*\n\n*Using a platform specific import* - Make sure your code imports either '@google/genai/web' or '@google/genai/node' instead of '@google/genai'.\n")}
86
+ /**
87
+ * @license
88
+ * Copyright 2025 Google LLC
89
+ * SPDX-License-Identifier: Apache-2.0
90
+ */class yn{async download(e,t){throw gn()}}const vn="x-goog-upload-status";class En{async upload(e,t,n){if("string"==typeof e)throw gn();return async function(e,t,n){var o;const i=await Tn(e,t,n),r=await(null==i?void 0:i.json());if("final"!==(null===(o=null==i?void 0:i.headers)||void 0===o?void 0:o[vn]))throw new Error("Failed to upload file: Upload status is not finalized.");return r.file}(e,t,n)}async uploadToFileSearchStore(e,t,n){if("string"==typeof e)throw gn();return async function(e,t,n){var o;const i=await Tn(e,t,n),r=await(null==i?void 0:i.json());if("final"!==(null===(o=null==i?void 0:i.headers)||void 0===o?void 0:o[vn]))throw new Error("Failed to upload file: Upload status is not finalized.");const s=ge(r),l=new Ke;return Object.assign(l,s),l}(e,t,n)}async stat(e){if("string"==typeof e)throw gn();return async function(e){const t={size:e.size,type:e.type};return t}(e)}}async function Tn(e,t,n){var o,i;let r=0,s=0,l=new Te(new Response),a="upload";for(r=e.size;s<r;){const u=Math.min(8388608,r-s),c=e.slice(s,s+u);s+u>=r&&(a+=", finalize");let p=0,d=1e3;for(;p<3&&(l=await n.request({path:"",body:c,httpMethod:"POST",httpOptions:{apiVersion:"",baseUrl:t,headers:{"X-Goog-Upload-Command":a,"X-Goog-Upload-Offset":String(s),"Content-Length":String(u)}}}),!(null===(o=null==l?void 0:l.headers)||void 0===o?void 0:o[vn]));)p++,await In(d),d*=2;if(s+=u,"active"!==(null===(i=null==l?void 0:l.headers)||void 0===i?void 0:i[vn]))break;if(r<=s)throw new Error("All content has been uploaded, but the upload status is not finalized.")}return l}function In(e){return new Promise(t=>setTimeout(t,e))}
91
+ /**
92
+ * @license
93
+ * Copyright 2025 Google LLC
94
+ * SPDX-License-Identifier: Apache-2.0
95
+ */class _n{create(e,t,n){throw gn()}}
96
+ /**
97
+ * @license
98
+ * Copyright 2025 Google LLC
99
+ * SPDX-License-Identifier: Apache-2.0
100
+ */function Sn(e){const t={},n=ce(e,["config"]);return null!=n&&function(e,t){const n=ce(e,["pageSize"]);void 0!==t&&null!=n&&ue(t,["_query","pageSize"],n);const o=ce(e,["pageToken"]);void 0!==t&&null!=o&&ue(t,["_query","pageToken"],o)}(n,t),t}
101
+ /**
102
+ * @license
103
+ * Copyright 2025 Google LLC
104
+ * SPDX-License-Identifier: Apache-2.0
105
+ */
106
+ class An extends le{constructor(t){super(),this.apiClient=t,this.list=async(t={})=>new qt(e.PagedItem.PAGED_ITEM_FILES,e=>this.listInternal(e),await this.listInternal(t),t)}async upload(e){if(this.apiClient.isVertexAI())throw new Error("Vertex AI does not support uploading files. You can share files through a GCS bucket.");return this.apiClient.uploadFile(e.file,e.config).then(e=>e)}async download(e){await this.apiClient.downloadFile(e)}async 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=Sn(e);return i=ae("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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["nextPageToken"]);null!=o&&ue(t,["nextPageToken"],o);const i=ce(e,["files"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["files"],e)}return t}(e),n=new He;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=ce(e,["file"]);return null!=n&&ue(t,["file"],n),t}(e);return i=ae("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=ce(e,["sdkHttpResponse"]);return null!=n&&ue(t,["sdkHttpResponse"],n),t}(e),n=new je;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=ce(e,["name"]);return null!=n&&ue(t,["_url","file"],vt(n)),t}(e);return i=ae("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=ce(e,["name"]);return null!=n&&ue(t,["_url","file"],vt(n)),t}(e);return i=ae("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=ce(e,["sdkHttpResponse"]);return null!=n&&ue(t,["sdkHttpResponse"],n),t}(e),n=new Ve;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=ce(e,["uris"]);return null!=n&&ue(t,["uris"],n),t}(e);return i=ae("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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["files"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["files"],e)}return t}(e),n=new Be;return Object.assign(n,t),n})}}}
107
+ /**
108
+ * @license
109
+ * Copyright 2025 Google LLC
110
+ * SPDX-License-Identifier: Apache-2.0
111
+ */function Cn(e){const t={},n=ce(e,["name"]);null!=n&&ue(t,["_url","name"],n);const o=ce(e,["config"]);return null!=o&&function(e,t){const n=ce(e,["force"]);void 0!==t&&null!=n&&ue(t,["_query","force"],n)}(o,t),t}function On(e){const t={},n=ce(e,["parent"]);null!=n&&ue(t,["_url","parent"],n);const o=ce(e,["config"]);return null!=o&&function(e,t){const n=ce(e,["pageSize"]);void 0!==t&&null!=n&&ue(t,["_query","pageSize"],n);const o=ce(e,["pageToken"]);void 0!==t&&null!=o&&ue(t,["_query","pageToken"],o)}(o,t),t}
112
+ /**
113
+ * @license
114
+ * Copyright 2025 Google LLC
115
+ * SPDX-License-Identifier: Apache-2.0
116
+ */
117
+ class bn extends le{constructor(t){super(),this.apiClient=t,this.list=async t=>new qt(e.PagedItem.PAGED_ITEM_DOCUMENTS,e=>this.listInternal({parent:t.parent,config:e.config}),await this.listInternal(t),t)}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=ce(e,["name"]);return null!=n&&ue(t,["_url","name"],n),t}(e);return i=ae("{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=Cn(e);o=ae("{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=On(e);return i=ae("{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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["nextPageToken"]);null!=o&&ue(t,["nextPageToken"],o);const i=ce(e,["documents"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["documents"],e)}return t}(e),n=new ke;return Object.assign(n,t),n})}}}
118
+ /**
119
+ * @license
120
+ * Copyright 2025 Google LLC
121
+ * SPDX-License-Identifier: Apache-2.0
122
+ */class Rn extends le{constructor(t,n=new bn(t)){super(),this.apiClient=t,this.documents=n,this.list=async(t={})=>new qt(e.PagedItem.PAGED_ITEM_FILE_SEARCH_STORES,e=>this.listInternal(e),await this.listInternal(t),t)}async uploadToFileSearchStore(e){if(this.apiClient.isVertexAI())throw new Error("Vertex AI does not support uploading files to a file search store.");return this.apiClient.uploadFileToFileSearchStore(e.fileSearchStoreName,e.file,e.config)}async create(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const s=rn(e);return i=ae("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=ce(e,["name"]);return null!=n&&ue(t,["_url","name"],n),t}(e);return i=ae("{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=sn(e);o=ae("{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=un(e);return i=ae("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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["nextPageToken"]);null!=o&&ue(t,["nextPageToken"],o);const i=ce(e,["fileSearchStores"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["fileSearchStores"],e)}return t}(e),n=new qe;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=ce(e,["fileSearchStoreName"]);null!=n&&ue(t,["_url","file_search_store_name"],n);const o=ce(e,["config"]);return null!=o&&cn(o,t),t}(e);return i=ae("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=ce(e,["sdkHttpResponse"]);return null!=n&&ue(t,["sdkHttpResponse"],n),t}(e),n=new Ge;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=an(e);return i=ae("{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=ln(e),n=new Fe;return Object.assign(n,t),n})}}}
123
+ /**
124
+ * @license
125
+ * Copyright 2025 Google LLC
126
+ * SPDX-License-Identifier: Apache-2.0
127
+ */let wn=function(){const{crypto:e}=globalThis;if(null==e?void 0:e.randomUUID)return wn=e.randomUUID.bind(e),e.randomUUID();const t=new Uint8Array(1),n=e?()=>e.getRandomValues(t)[0]:()=>255*Math.random()&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,e=>(+e^n()&15>>+e/4).toString(16))};
128
+ /**
129
+ * @license
130
+ * Copyright 2025 Google LLC
131
+ * SPDX-License-Identifier: Apache-2.0
132
+ */
133
+ function Nn(e){return"object"==typeof e&&null!==e&&("name"in e&&"AbortError"===e.name||"message"in e&&String(e.message).includes("FetchRequestCanceledException"))}const Pn=e=>{if(e instanceof Error)return e;if("object"==typeof e&&null!==e){try{if("[object Error]"===Object.prototype.toString.call(e)){const t=new Error(e.message,e.cause?{cause:e.cause}:{});return e.stack&&(t.stack=e.stack),e.cause&&!t.cause&&(t.cause=e.cause),e.name&&(t.name=e.name),t}}catch(e){}try{return new Error(JSON.stringify(e))}catch(e){}}return new Error(e)};
134
+ /**
135
+ * @license
136
+ * Copyright 2025 Google LLC
137
+ * SPDX-License-Identifier: Apache-2.0
138
+ */class Mn extends Error{}class Dn extends Mn{constructor(e,t,n,o){super(`${Dn.makeMessage(e,t,n)}`),this.status=e,this.headers=o,this.error=t}static makeMessage(e,t,n){const o=(null==t?void 0:t.message)?"string"==typeof t.message?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&o?`${e} ${o}`:e?`${e} status code (no body)`:o||"(no status code or body)"}static generate(e,t,n,o){if(!e||!o)return new xn({message:n,cause:Pn(t)});const i=t;return 400===e?new kn(e,i,n,o):401===e?new qn(e,i,n,o):403===e?new Gn(e,i,n,o):404===e?new Fn(e,i,n,o):409===e?new Hn(e,i,n,o):422===e?new jn(e,i,n,o):429===e?new Vn(e,i,n,o):e>=500?new Bn(e,i,n,o):new Dn(e,i,n,o)}}class Un extends Dn{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}}class xn extends Dn{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),t&&(this.cause=t)}}class Ln extends xn{constructor({message:e}={}){super({message:null!=e?e:"Request timed out."})}}class kn extends Dn{}class qn extends Dn{}class Gn extends Dn{}class Fn extends Dn{}class Hn extends Dn{}class jn extends Dn{}class Vn extends Dn{}class Bn extends Dn{}
139
+ /**
140
+ * @license
141
+ * Copyright 2025 Google LLC
142
+ * SPDX-License-Identifier: Apache-2.0
143
+ */const Jn=/^[a-z][a-z0-9+.-]*:/i;let $n=e=>($n=Array.isArray,$n(e));const Yn=$n;const Kn="0.0.1";const Wn=()=>{var e,t,n,o,i;const r="undefined"!=typeof Deno&&null!=Deno.build?"deno":"undefined"!=typeof EdgeRuntime?"edge":"[object process]"===Object.prototype.toString.call(void 0!==globalThis.process?globalThis.process:0)?"node":"unknown";if("deno"===r)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kn,"X-Stainless-OS":Xn(Deno.build.os),"X-Stainless-Arch":zn(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":"string"==typeof Deno.version?Deno.version:null!==(t=null===(e=Deno.version)||void 0===e?void 0:e.deno)&&void 0!==t?t:"unknown"};if("undefined"!=typeof EdgeRuntime)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kn,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process.version};if("node"===r)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kn,"X-Stainless-OS":Xn(null!==(n=globalThis.process.platform)&&void 0!==n?n:"unknown"),"X-Stainless-Arch":zn(null!==(o=globalThis.process.arch)&&void 0!==o?o:"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":null!==(i=globalThis.process.version)&&void 0!==i?i:"unknown"};const s=function(){if("undefined"==typeof navigator||!navigator)return null;const e=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(const{key:t,pattern:n}of e){const e=n.exec(navigator.userAgent);if(e){return{browser:t,version:`${e[1]||0}.${e[2]||0}.${e[3]||0}`}}}return null}();return s?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kn,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${s.browser}`,"X-Stainless-Runtime-Version":s.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Kn,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};const zn=e=>"x32"===e?"x32":"x86_64"===e||"x64"===e?"x64":"arm"===e?"arm":"aarch64"===e||"arm64"===e?"arm64":e?`other:${e}`:"unknown",Xn=e=>(e=e.toLowerCase()).includes("ios")?"iOS":"android"===e?"Android":"darwin"===e?"MacOS":"win32"===e?"Windows":"freebsd"===e?"FreeBSD":"openbsd"===e?"OpenBSD":"linux"===e?"Linux":e?`Other:${e}`:"Unknown";let Qn;function Zn(...e){const t=globalThis.ReadableStream;if(void 0===t)throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new t(...e)}function eo(e){let t=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator]();return Zn({start(){},async pull(e){const{done:n,value:o}=await t.next();n?e.close():e.enqueue(o)},async cancel(){var e;await(null===(e=t.return)||void 0===e?void 0:e.call(t))}})}function to(e){if(e[Symbol.asyncIterator])return e;const t=e.getReader();return{async next(){try{const e=await t.read();return(null==e?void 0:e.done)&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){const e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}
144
+ /**
145
+ * @license
146
+ * Copyright 2025 Google LLC
147
+ * SPDX-License-Identifier: Apache-2.0
148
+ */
149
+ const no=({headers:e,body:t})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(t)}),oo=()=>{var e;if("undefined"==typeof File){const{process:t}=globalThis,n="string"==typeof(null===(e=null==t?void 0:t.versions)||void 0===e?void 0:e.node)&&parseInt(t.versions.node.split("."))<20;throw new Error("`File` is not defined as a global, which is required for file uploads."+(n?" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`.":""))}};
150
+ /**
151
+ * @license
152
+ * Copyright 2025 Google LLC
153
+ * SPDX-License-Identifier: Apache-2.0
154
+ */function io(e,t,n){return oo(),new File(e,null!=t?t:"unknown_file",n)}const ro=e=>null!=e&&"object"==typeof e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.text&&"function"==typeof e.slice&&"function"==typeof e.arrayBuffer;
155
+ /**
156
+ * @license
157
+ * Copyright 2025 Google LLC
158
+ * SPDX-License-Identifier: Apache-2.0
159
+ */async function so(e){var t,n,o,i,r;let s=[];if("string"==typeof e||ArrayBuffer.isView(e)||e instanceof ArrayBuffer)s.push(e);else if(ro(e))s.push(e instanceof Blob?e:await e.arrayBuffer());else{if(!(e=>null!=e&&"object"==typeof e&&"function"==typeof e[Symbol.asyncIterator])(e)){const t=null===(r=null==e?void 0:e.constructor)||void 0===r?void 0:r.name;throw new Error(`Unexpected data type: ${typeof e}${t?`; constructor: ${t}`:""}${function(e){if("object"!=typeof e||null===e)return"";const t=Object.getOwnPropertyNames(e);return`; props: [${t.map(e=>`"${e}"`).join(", ")}]`}
160
+ /**
161
+ * @license
162
+ * Copyright 2025 Google LLC
163
+ * SPDX-License-Identifier: Apache-2.0
164
+ */(e)}`)}try{for(var l,a=!0,u=Qt(e);!(t=(l=await u.next()).done);a=!0){i=l.value,a=!1;const e=i;s.push(...await so(e))}}catch(e){n={error:e}}finally{try{a||t||!(o=u.return)||await o.call(u)}finally{if(n)throw n.error}}}return s}class lo{constructor(e){this._client=e}}
165
+ /**
166
+ * @license
167
+ * Copyright 2025 Google LLC
168
+ * SPDX-License-Identifier: Apache-2.0
169
+ */
170
+ function ao(e){return e.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g,encodeURIComponent)}lo._key=[];const uo=Object.freeze(Object.create(null)),co=(e=ao)=>function(t,...n){if(1===t.length)return t[0];let o=!1;const i=[],r=t.reduce((t,r,s)=>{var l,a,u;/[?#]/.test(r)&&(o=!0);const c=n[s];let p=(o?encodeURIComponent:e)(""+c);return s!==n.length&&(null==c||"object"==typeof c&&c.toString===(null===(u=Object.getPrototypeOf(null!==(a=Object.getPrototypeOf(null!==(l=c.hasOwnProperty)&&void 0!==l?l:uo))&&void 0!==a?a:uo))||void 0===u?void 0:u.toString))&&(p=c+"",i.push({start:t.length+r.length,length:p.length,error:`Value of type ${Object.prototype.toString.call(c).slice(8,-1)} is not a valid path parameter`})),t+r+(s===n.length?"":p)},""),s=r.split(/[?#]/,1)[0],l=/(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;let a;for(;null!==(a=l.exec(s));)i.push({start:a.index,length:a[0].length,error:`Value "${a[0]}" can't be safely passed as a path parameter`});if(i.sort((e,t)=>e.start-t.start),i.length>0){let e=0;const t=i.reduce((t,n)=>{const o=" ".repeat(n.start-e),i="^".repeat(n.length);return e=n.start+n.length,t+o+i},"");throw new Mn(`Path parameters result in path with invalid segments:\n${i.map(e=>e.error).join("\n")}\n${r}\n${t}`)}return r},po=co(ao);
171
+ /**
172
+ * @license
173
+ * Copyright 2025 Google LLC
174
+ * SPDX-License-Identifier: Apache-2.0
175
+ */
176
+ class ho extends lo{create(e,t){var n;const{api_version:o=this._client.apiVersion}=e,i=Kt(e,["api_version"]);if("model"in i&&"agent_config"in i)throw new Mn("Invalid request: specified `model` and `agent_config`. If specifying `model`, use `generation_config`.");if("agent"in i&&"generation_config"in i)throw new Mn("Invalid request: specified `agent` and `generation_config`. If specifying `agent`, use `agent_config`.");return this._client.post(po`/${o}/interactions`,Object.assign(Object.assign({body:i},t),{stream:null!==(n=e.stream)&&void 0!==n&&n}))}delete(e,t={},n){const{api_version:o=this._client.apiVersion}=null!=t?t:{};return this._client.delete(po`/${o}/interactions/${e}`,n)}cancel(e,t={},n){const{api_version:o=this._client.apiVersion}=null!=t?t:{};return this._client.post(po`/${o}/interactions/${e}/cancel`,n)}get(e,t={},n){var o;const i=null!=t?t:{},{api_version:r=this._client.apiVersion}=i,s=Kt(i,["api_version"]);return this._client.get(po`/${r}/interactions/${e}`,Object.assign(Object.assign({query:s},n),{stream:null!==(o=null==t?void 0:t.stream)&&void 0!==o&&o}))}}ho._key=Object.freeze(["interactions"]);class fo extends ho{}
177
+ /**
178
+ * @license
179
+ * Copyright 2025 Google LLC
180
+ * SPDX-License-Identifier: Apache-2.0
181
+ */let mo,go;function yo(e){let t;return(null!=mo?mo:(t=new globalThis.TextEncoder,mo=t.encode.bind(t)))(e)}function vo(e){let t;return(null!=go?go:(t=new globalThis.TextDecoder,go=t.decode.bind(t)))(e)}
182
+ /**
183
+ * @license
184
+ * Copyright 2025 Google LLC
185
+ * SPDX-License-Identifier: Apache-2.0
186
+ */class Eo{constructor(){this.buffer=new Uint8Array,this.carriageReturnIndex=null}decode(e){if(null==e)return[];const t=e instanceof ArrayBuffer?new Uint8Array(e):"string"==typeof e?yo(e):e;this.buffer=function(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let o=0;for(const t of e)n.set(t,o),o+=t.length;return n}([this.buffer,t]);const n=[];let o;for(;null!=(o=To(this.buffer,this.carriageReturnIndex));){if(o.carriage&&null==this.carriageReturnIndex){this.carriageReturnIndex=o.index;continue}if(null!=this.carriageReturnIndex&&(o.index!==this.carriageReturnIndex+1||o.carriage)){n.push(vo(this.buffer.subarray(0,this.carriageReturnIndex-1))),this.buffer=this.buffer.subarray(this.carriageReturnIndex),this.carriageReturnIndex=null;continue}const e=null!==this.carriageReturnIndex?o.preceding-1:o.preceding,t=vo(this.buffer.subarray(0,e));n.push(t),this.buffer=this.buffer.subarray(o.index),this.carriageReturnIndex=null}return n}flush(){return this.buffer.length?this.decode("\n"):[]}}function To(e,t){for(let n=null!=t?t:0;n<e.length;n++){if(10===e[n])return{preceding:n,index:n+1,carriage:!1};if(13===e[n])return{preceding:n,index:n+1,carriage:!0}}return null}function Io(e){for(let t=0;t<e.length-1;t++){if(10===e[t]&&10===e[t+1])return t+2;if(13===e[t]&&13===e[t+1])return t+2;if(13===e[t]&&10===e[t+1]&&t+3<e.length&&13===e[t+2]&&10===e[t+3])return t+4}return-1}
187
+ /**
188
+ * @license
189
+ * Copyright 2025 Google LLC
190
+ * SPDX-License-Identifier: Apache-2.0
191
+ */Eo.NEWLINE_CHARS=new Set(["\n","\r"]),Eo.NEWLINE_REGEXP=/\r\n|[\n\r]/g;const _o={off:0,error:200,warn:300,info:400,debug:500},So=(e,t,n)=>{var o,i;if(e)return o=_o,i=e,Object.prototype.hasOwnProperty.call(o,i)?e:void Ro(n).warn(`${t} was set to ${JSON.stringify(e)}, expected one of ${JSON.stringify(Object.keys(_o))}`)};function Ao(){}function Co(e,t,n){return!t||_o[e]>_o[n]?Ao:t[e].bind(t)}const Oo={error:Ao,warn:Ao,info:Ao,debug:Ao};let bo=new WeakMap;function Ro(e){var t;const n=e.logger,o=null!==(t=e.logLevel)&&void 0!==t?t:"off";if(!n)return Oo;const i=bo.get(n);if(i&&i[0]===o)return i[1];const r={error:Co("error",n,o),warn:Co("warn",n,o),info:Co("info",n,o),debug:Co("debug",n,o)};return bo.set(n,[o,r]),r}const wo=e=>(e.options&&(e.options=Object.assign({},e.options),delete e.options.headers),e.headers&&(e.headers=Object.fromEntries((e.headers instanceof Headers?[...e.headers]:Object.entries(e.headers)).map(([e,t])=>[e,"x-goog-api-key"===e.toLowerCase()||"authorization"===e.toLowerCase()||"cookie"===e.toLowerCase()||"set-cookie"===e.toLowerCase()?"***":t]))),"retryOfRequestLogID"in e&&(e.retryOfRequestLogID&&(e.retryOf=e.retryOfRequestLogID),delete e.retryOfRequestLogID),e);
192
+ /**
193
+ * @license
194
+ * Copyright 2025 Google LLC
195
+ * SPDX-License-Identifier: Apache-2.0
196
+ */class No{constructor(e,t,n){this.iterator=e,this.controller=t,this.client=n}static fromSSEResponse(e,t,n){let o=!1;const i=n?Ro(n):console;return new No(function(){return Xt(this,arguments,function*(){var n,r,s,l;if(o)throw new Mn("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");o=!0;let a=!1;try{try{for(var u,c=!0,p=Qt(function(e,t){return Xt(this,arguments,function*(){var n,o,i,r;if(!e.body){if(t.abort(),void 0!==globalThis.navigator&&"ReactNative"===globalThis.navigator.product)throw new Mn("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api");throw new Mn("Attempted to iterate over a response with no body")}const s=new Po,l=new Eo,a=to(e.body);try{for(var u,c=!0,p=Qt(function(e){return Xt(this,arguments,function*(){var t,n,o,i;let r=new Uint8Array;try{for(var s,l=!0,a=Qt(e);!(t=(s=yield zt(a.next())).done);l=!0){i=s.value,l=!1;const e=i;if(null==e)continue;const t=e instanceof ArrayBuffer?new Uint8Array(e):"string"==typeof e?yo(e):e;let n,o=new Uint8Array(r.length+t.length);for(o.set(r),o.set(t,r.length),r=o;-1!==(n=Io(r));)yield yield zt(r.slice(0,n)),r=r.slice(n)}}catch(e){n={error:e}}finally{try{l||t||!(o=a.return)||(yield zt(o.call(a)))}finally{if(n)throw n.error}}r.length>0&&(yield yield zt(r))})}(a));!(n=(u=yield zt(p.next())).done);c=!0){r=u.value,c=!1;const e=r;for(const t of l.decode(e)){const e=s.decode(t);e&&(yield yield zt(e))}}}catch(e){o={error:e}}finally{try{c||n||!(i=p.return)||(yield zt(i.call(p)))}finally{if(o)throw o.error}}for(const e of l.flush()){const t=s.decode(e);t&&(yield yield zt(t))}})}(e,t));!(n=(u=yield zt(p.next())).done);c=!0){l=u.value,c=!1;const e=l;if(!a)if(e.data.startsWith("[DONE]"))a=!0;else try{yield yield zt(JSON.parse(e.data))}catch(t){throw i.error("Could not parse message into JSON:",e.data),i.error("From chunk:",e.raw),t}}}catch(e){r={error:e}}finally{try{c||n||!(s=p.return)||(yield zt(s.call(p)))}finally{if(r)throw r.error}}a=!0}catch(e){if(Nn(e))return yield zt(void 0);throw e}finally{a||t.abort()}})},t,n)}static fromReadableStream(e,t,n){let o=!1;return new No(function(){return Xt(this,arguments,function*(){var n,i,r,s;if(o)throw new Mn("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");o=!0;let l=!1;try{try{for(var a,u=!0,c=Qt(function(){return Xt(this,arguments,function*(){var t,n,o,i;const r=new Eo,s=to(e);try{for(var l,a=!0,u=Qt(s);!(t=(l=yield zt(u.next())).done);a=!0){i=l.value,a=!1;const e=i;for(const t of r.decode(e))yield yield zt(t)}}catch(e){n={error:e}}finally{try{a||t||!(o=u.return)||(yield zt(o.call(u)))}finally{if(n)throw n.error}}for(const e of r.flush())yield yield zt(e)})}());!(n=(a=yield zt(c.next())).done);u=!0){s=a.value,u=!1;const e=s;l||e&&(yield yield zt(JSON.parse(e)))}}catch(e){i={error:e}}finally{try{u||n||!(r=c.return)||(yield zt(r.call(c)))}finally{if(i)throw i.error}}l=!0}catch(e){if(Nn(e))return yield zt(void 0);throw e}finally{l||t.abort()}})},t,n)}[Symbol.asyncIterator](){return this.iterator()}tee(){const e=[],t=[],n=this.iterator(),o=o=>({next:()=>{if(0===o.length){const o=n.next();e.push(o),t.push(o)}return o.shift()}});return[new No(()=>o(e),this.controller,this.client),new No(()=>o(t),this.controller,this.client)]}toReadableStream(){const e=this;let t;return Zn({async start(){t=e[Symbol.asyncIterator]()},async pull(e){try{const{value:n,done:o}=await t.next();if(o)return e.close();const i=yo(JSON.stringify(n)+"\n");e.enqueue(i)}catch(t){e.error(t)}},async cancel(){var e;await(null===(e=t.return)||void 0===e?void 0:e.call(t))}})}}class Po{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith("\r")&&(e=e.substring(0,e.length-1)),!e){if(!this.event&&!this.data.length)return null;const e={event:this.event,data:this.data.join("\n"),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],e}if(this.chunks.push(e),e.startsWith(":"))return null;let[t,n,o]=function(e,t){const n=e.indexOf(t);if(-1!==n)return[e.substring(0,n),t,e.substring(n+t.length)];return[e,"",""]}
197
+ /**
198
+ * @license
199
+ * Copyright 2025 Google LLC
200
+ * SPDX-License-Identifier: Apache-2.0
201
+ */(e,":");return o.startsWith(" ")&&(o=o.substring(1)),"event"===t?this.event=o:"data"===t&&this.data.push(o),null}}async function Mo(e,t){const{response:n,requestLogID:o,retryOfRequestLogID:i,startTime:r}=t,s=await(async()=>{var o;if(t.options.stream)return Ro(e).debug("response",n.status,n.url,n.headers,n.body),t.options.__streamClass?t.options.__streamClass.fromSSEResponse(n,t.controller,e):No.fromSSEResponse(n,t.controller,e);if(204===n.status)return null;if(t.options.__binaryResponse)return n;const i=n.headers.get("content-type"),r=null===(o=null==i?void 0:i.split(";")[0])||void 0===o?void 0:o.trim();if((null==r?void 0:r.includes("application/json"))||(null==r?void 0:r.endsWith("+json"))){if("0"===n.headers.get("content-length"))return;return await n.json()}return await n.text()})();return Ro(e).debug(`[${o}] response parsed`,wo({retryOfRequestLogID:i,url:n.url,status:n.status,body:s,durationMs:Date.now()-r})),s}
202
+ /**
203
+ * @license
204
+ * Copyright 2025 Google LLC
205
+ * SPDX-License-Identifier: Apache-2.0
206
+ */class Do extends Promise{constructor(e,t,n=Mo){super(e=>{e(null)}),this.responsePromise=t,this.parseResponse=n,this.client=e}_thenUnwrap(e){return new Do(this.client,this.responsePromise,async(t,n)=>e(await this.parseResponse(t,n),n))}asResponse(){return this.responsePromise.then(e=>e.response)}async withResponse(){const[e,t]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:t}}parse(){return this.parsedPromise||(this.parsedPromise=this.responsePromise.then(e=>this.parseResponse(this.client,e))),this.parsedPromise}then(e,t){return this.parse().then(e,t)}catch(e){return this.parse().catch(e)}finally(e){return this.parse().finally(e)}}
207
+ /**
208
+ * @license
209
+ * Copyright 2025 Google LLC
210
+ * SPDX-License-Identifier: Apache-2.0
211
+ */const Uo=Symbol("brand.privateNullableHeaders");function*xo(e){if(!e)return;if(Uo in e){const{values:t,nulls:n}=e;yield*t.entries();for(const e of n)yield[e,null];return}let t,n=!1;e instanceof Headers?t=e.entries():Yn(e)?t=e:(n=!0,t=Object.entries(null!=e?e:{}));for(let e of t){const t=e[0];if("string"!=typeof t)throw new TypeError("expected header name to be a string");const o=Yn(e[1])?e[1]:[e[1]];let i=!1;for(const e of o)void 0!==e&&(n&&!i&&(i=!0,yield[t,null]),yield[t,e])}}const Lo=e=>{const t=new Headers,n=new Set;for(const o of e){const e=new Set;for(const[i,r]of xo(o)){const o=i.toLowerCase();e.has(o)||(t.delete(i),e.add(o)),null===r?(t.delete(i),n.add(o)):(t.append(i,r),n.delete(o))}}return{[Uo]:!0,values:t,nulls:n}},ko=e=>{var t,n,o,i,r,s;return void 0!==globalThis.process?null!==(o=null===(n=null===(t=globalThis.process.env)||void 0===t?void 0:t[e])||void 0===n?void 0:n.trim())&&void 0!==o?o:void 0:void 0!==globalThis.Deno?null===(s=null===(r=null===(i=globalThis.Deno.env)||void 0===i?void 0:i.get)||void 0===r?void 0:r.call(i,e))||void 0===s?void 0:s.trim():void 0};
212
+ /**
213
+ * @license
214
+ * Copyright 2025 Google LLC
215
+ * SPDX-License-Identifier: Apache-2.0
216
+ */
217
+ /**
218
+ * @license
219
+ * Copyright 2025 Google LLC
220
+ * SPDX-License-Identifier: Apache-2.0
221
+ */
222
+ var qo;class Go{constructor(e){var t,n,o,i,r,s,l,{baseURL:a=ko("GEMINI_NEXT_GEN_API_BASE_URL"),apiKey:u=(null!==(t=ko("GEMINI_API_KEY"))&&void 0!==t?t:null),apiVersion:c="v1beta"}=e,p=Kt(e,["baseURL","apiKey","apiVersion"]);const d=Object.assign(Object.assign({apiKey:u,apiVersion:c},p),{baseURL:a||"https://generativelanguage.googleapis.com"});this.baseURL=d.baseURL,this.timeout=null!==(n=d.timeout)&&void 0!==n?n:Go.DEFAULT_TIMEOUT,this.logger=null!==(o=d.logger)&&void 0!==o?o:console;const h="warn";this.logLevel=h,this.logLevel=null!==(r=null!==(i=So(d.logLevel,"ClientOptions.logLevel",this))&&void 0!==i?i:So(ko("GEMINI_NEXT_GEN_API_LOG"),"process.env['GEMINI_NEXT_GEN_API_LOG']",this))&&void 0!==r?r:h,this.fetchOptions=d.fetchOptions,this.maxRetries=null!==(s=d.maxRetries)&&void 0!==s?s:2,this.fetch=null!==(l=d.fetch)&&void 0!==l?l:
223
+ /**
224
+ * @license
225
+ * Copyright 2025 Google LLC
226
+ * SPDX-License-Identifier: Apache-2.0
227
+ */
228
+ function(){if("undefined"!=typeof fetch)return fetch;throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new GeminiNextGenAPIClient({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}(),this.encoder=no,this._options=d,this.apiKey=u,this.apiVersion=c,this.clientAdapter=d.clientAdapter}withOptions(e){return new this.constructor(Object.assign(Object.assign(Object.assign({},this._options),{baseURL:this.baseURL,maxRetries:this.maxRetries,timeout:this.timeout,logger:this.logger,logLevel:this.logLevel,fetch:this.fetch,fetchOptions:this.fetchOptions,apiKey:this.apiKey,apiVersion:this.apiVersion}),e))}baseURLOverridden(){return"https://generativelanguage.googleapis.com"!==this.baseURL}defaultQuery(){return this._options.defaultQuery}validateHeaders({values:e,nulls:t}){if(!e.has("authorization")&&!e.has("x-goog-api-key")&&!(this.apiKey&&e.get("x-goog-api-key")||t.has("x-goog-api-key")))throw new Error('Could not resolve authentication method. Expected the apiKey to be set. Or for the "x-goog-api-key" headers to be explicitly omitted')}async authHeaders(e){const t=Lo([e.headers]);if(!t.values.has("authorization")&&!t.values.has("x-goog-api-key"))return this.apiKey?Lo([{"x-goog-api-key":this.apiKey}]):this.clientAdapter.isVertexAI()?Lo([await this.clientAdapter.getAuthHeaders()]):void 0}stringifyQuery(e){return Object.entries(e).filter(([e,t])=>void 0!==t).map(([e,t])=>{if("string"==typeof t||"number"==typeof t||"boolean"==typeof t)return`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;if(null===t)return`${encodeURIComponent(e)}=`;throw new Mn(`Cannot stringify type ${typeof t}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`)}).join("&")}getUserAgent(){return`${this.constructor.name}/JS ${Kn}`}defaultIdempotencyKey(){return`stainless-node-retry-${wn()}`}makeStatusError(e,t,n,o){return Dn.generate(e,t,n,o)}buildURL(e,t,n){const o=!this.baseURLOverridden()&&n||this.baseURL,i=(e=>Jn.test(e))(e)?new URL(e):new URL(o+(o.endsWith("/")&&e.startsWith("/")?e.slice(1):e)),r=this.defaultQuery();return function(e){if(!e)return!0;for(const t in e)return!1;return!0}(r)||(t=Object.assign(Object.assign({},r),t)),"object"==typeof t&&t&&!Array.isArray(t)&&(i.search=this.stringifyQuery(t)),i.toString()}async prepareOptions(e){if(this.clientAdapter&&this.clientAdapter.isVertexAI()&&!e.path.startsWith(`/${this.apiVersion}/projects/`)){const t=e.path.slice(this.apiVersion.length+1);e.path=`/${this.apiVersion}/projects/${this.clientAdapter.getProject()}/locations/${this.clientAdapter.getLocation()}${t}`}}async prepareRequest(e,{url:t,options:n}){}get(e,t){return this.methodRequest("get",e,t)}post(e,t){return this.methodRequest("post",e,t)}patch(e,t){return this.methodRequest("patch",e,t)}put(e,t){return this.methodRequest("put",e,t)}delete(e,t){return this.methodRequest("delete",e,t)}methodRequest(e,t,n){return this.request(Promise.resolve(n).then(n=>Object.assign({method:e,path:t},n)))}request(e,t=null){return new Do(this,this.makeRequest(e,t,void 0))}async makeRequest(e,t,n){var o,i,r;const s=await e,l=null!==(o=s.maxRetries)&&void 0!==o?o:this.maxRetries;null==t&&(t=l),await this.prepareOptions(s);const{req:a,url:u,timeout:c}=await this.buildRequest(s,{retryCount:l-t});await this.prepareRequest(a,{url:u,options:s});const p="log_"+(Math.random()*(1<<24)|0).toString(16).padStart(6,"0"),d=void 0===n?"":`, retryOf: ${n}`,h=Date.now();if(Ro(this).debug(`[${p}] sending request`,wo({retryOfRequestLogID:n,method:s.method,url:u,options:s,headers:a.headers})),null===(i=s.signal)||void 0===i?void 0:i.aborted)throw new Un;const f=new AbortController,m=await this.fetchWithTimeout(u,a,c,f).catch(Pn),g=Date.now();if(m instanceof globalThis.Error){const e=`retrying, ${t} attempts remaining`;if(null===(r=s.signal)||void 0===r?void 0:r.aborted)throw new Un;const o=Nn(m)||/timed? ?out/i.test(String(m)+("cause"in m?String(m.cause):""));if(t)return Ro(this).info(`[${p}] connection ${o?"timed out":"failed"} - ${e}`),Ro(this).debug(`[${p}] connection ${o?"timed out":"failed"} (${e})`,wo({retryOfRequestLogID:n,url:u,durationMs:g-h,message:m.message})),this.retryRequest(s,t,null!=n?n:p);if(Ro(this).info(`[${p}] connection ${o?"timed out":"failed"} - error; no more retries left`),Ro(this).debug(`[${p}] connection ${o?"timed out":"failed"} (error; no more retries left)`,wo({retryOfRequestLogID:n,url:u,durationMs:g-h,message:m.message})),o)throw new Ln;throw new xn({cause:m})}const y=`[${p}${d}] ${a.method} ${u} ${m.ok?"succeeded":"failed"} with status ${m.status} in ${g-h}ms`;if(!m.ok){const e=await this.shouldRetry(m);if(t&&e){const e=`retrying, ${t} attempts remaining`;return await async function(e){var t,n;if(null===e||"object"!=typeof e)return;if(e[Symbol.asyncIterator])return void await(null===(n=(t=e[Symbol.asyncIterator]()).return)||void 0===n?void 0:n.call(t));const o=e.getReader(),i=o.cancel();o.releaseLock(),await i}(m.body),Ro(this).info(`${y} - ${e}`),Ro(this).debug(`[${p}] response error (${e})`,wo({retryOfRequestLogID:n,url:m.url,status:m.status,headers:m.headers,durationMs:g-h})),this.retryRequest(s,t,null!=n?n:p,m.headers)}const o=e?"error; no more retries left":"error; not retryable";Ro(this).info(`${y} - ${o}`);const i=await m.text().catch(e=>Pn(e).message),r=(e=>{try{return JSON.parse(e)}catch(e){return}})(i),l=r?void 0:i;Ro(this).debug(`[${p}] response error (${o})`,wo({retryOfRequestLogID:n,url:m.url,status:m.status,headers:m.headers,message:l,durationMs:Date.now()-h}));throw this.makeStatusError(m.status,r,l,m.headers)}return Ro(this).info(y),Ro(this).debug(`[${p}] response start`,wo({retryOfRequestLogID:n,url:m.url,status:m.status,headers:m.headers,durationMs:g-h})),{response:m,options:s,controller:f,requestLogID:p,retryOfRequestLogID:n,startTime:h}}async fetchWithTimeout(e,t,n,o){const i=t||{},{signal:r,method:s}=i,l=Kt(i,["signal","method"]),a=this._makeAbort(o);r&&r.addEventListener("abort",a,{once:!0});const u=setTimeout(a,n),c=globalThis.ReadableStream&&l.body instanceof globalThis.ReadableStream||"object"==typeof l.body&&null!==l.body&&Symbol.asyncIterator in l.body,p=Object.assign(Object.assign(Object.assign({signal:o.signal},c?{duplex:"half"}:{}),{method:"GET"}),l);s&&(p.method=s.toUpperCase());try{return await this.fetch.call(void 0,e,p)}finally{clearTimeout(u)}}async shouldRetry(e){const t=e.headers.get("x-should-retry");return"true"===t||"false"!==t&&(408===e.status||(409===e.status||(429===e.status||e.status>=500)))}async retryRequest(e,t,n,o){var i;let r;const s=null==o?void 0:o.get("retry-after-ms");if(s){const e=parseFloat(s);Number.isNaN(e)||(r=e)}const l=null==o?void 0:o.get("retry-after");if(l&&!r){const e=parseFloat(l);r=Number.isNaN(e)?Date.parse(l)-Date.now():1e3*e}if(!(r&&0<=r&&r<6e4)){const n=null!==(i=e.maxRetries)&&void 0!==i?i:this.maxRetries;r=this.calculateDefaultRetryTimeoutMillis(t,n)}var a;return await(a=r,new Promise(e=>setTimeout(e,a))),this.makeRequest(e,t-1,n)}calculateDefaultRetryTimeoutMillis(e,t){const n=t-e;return Math.min(.5*Math.pow(2,n),8)*(1-.25*Math.random())*1e3}async buildRequest(e,{retryCount:t=0}={}){var n,o,i;const r=Object.assign({},e),{method:s,path:l,query:a,defaultBaseURL:u}=r,c=this.buildURL(l,a,u);"timeout"in r&&((e,t)=>{if("number"!=typeof t||!Number.isInteger(t))throw new Mn(`${e} must be an integer`);if(t<0)throw new Mn(`${e} must be a positive integer`)})("timeout",r.timeout),r.timeout=null!==(n=r.timeout)&&void 0!==n?n:this.timeout;const{bodyHeaders:p,body:d}=this.buildBody({options:r}),h=await this.buildHeaders({options:e,method:s,bodyHeaders:p,retryCount:t});return{req:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({method:s,headers:h},r.signal&&{signal:r.signal}),globalThis.ReadableStream&&d instanceof globalThis.ReadableStream&&{duplex:"half"}),d&&{body:d}),null!==(o=this.fetchOptions)&&void 0!==o?o:{}),null!==(i=r.fetchOptions)&&void 0!==i?i:{}),url:c,timeout:r.timeout}}async buildHeaders({options:e,method:t,bodyHeaders:n,retryCount:o}){let i={};this.idempotencyHeader&&"get"!==t&&(e.idempotencyKey||(e.idempotencyKey=this.defaultIdempotencyKey()),i[this.idempotencyHeader]=e.idempotencyKey);const r=await this.authHeaders(e);let s=Lo([i,Object.assign(Object.assign({Accept:"application/json","User-Agent":this.getUserAgent(),"X-Stainless-Retry-Count":String(o)},e.timeout?{"X-Stainless-Timeout":String(Math.trunc(e.timeout/1e3))}:{}),null!=Qn?Qn:Qn=Wn()),this._options.defaultHeaders,n,e.headers,r]);return this.validateHeaders(s),s.values}_makeAbort(e){return()=>e.abort()}buildBody({options:{body:e,headers:t}}){if(!e)return{bodyHeaders:void 0,body:void 0};const n=Lo([t]);return ArrayBuffer.isView(e)||e instanceof ArrayBuffer||e instanceof DataView||"string"==typeof e&&n.values.has("content-type")||globalThis.Blob&&e instanceof globalThis.Blob||e instanceof FormData||e instanceof URLSearchParams||globalThis.ReadableStream&&e instanceof globalThis.ReadableStream?{bodyHeaders:void 0,body:e}:"object"==typeof e&&(Symbol.asyncIterator in e||Symbol.iterator in e&&"next"in e&&"function"==typeof e.next)?{bodyHeaders:void 0,body:eo(e)}:"object"==typeof e&&"application/x-www-form-urlencoded"===n.values.get("content-type")?{bodyHeaders:{"content-type":"application/x-www-form-urlencoded"},body:this.stringifyQuery(e)}:this.encoder({body:e,headers:n})}}Go.DEFAULT_TIMEOUT=6e4;class Fo extends Go{constructor(){super(...arguments),this.interactions=new fo(this)}}
229
+ /**
230
+ * @license
231
+ * Copyright 2025 Google LLC
232
+ * SPDX-License-Identifier: Apache-2.0
233
+ */
234
+ function Ho(e){const t={},n=ce(e,["data"]);if(null!=n&&ue(t,["data"],n),void 0!==ce(e,["displayName"]))throw new Error("displayName parameter is not supported in Gemini API.");const o=ce(e,["mimeType"]);return null!=o&&ue(t,["mimeType"],o),t}function jo(e){const t={},n=ce(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["mediaResolution"]);null!=n&&ue(t,["mediaResolution"],n);const o=ce(e,["codeExecutionResult"]);null!=o&&ue(t,["codeExecutionResult"],o);const i=ce(e,["executableCode"]);null!=i&&ue(t,["executableCode"],i);const r=ce(e,["fileData"]);null!=r&&ue(t,["fileData"],function(e){const t={};if(void 0!==ce(e,["displayName"]))throw new Error("displayName parameter is not supported in Gemini API.");const n=ce(e,["fileUri"]);null!=n&&ue(t,["fileUri"],n);const o=ce(e,["mimeType"]);null!=o&&ue(t,["mimeType"],o);return t}(r));const s=ce(e,["functionCall"]);null!=s&&ue(t,["functionCall"],function(e){const t={},n=ce(e,["id"]);null!=n&&ue(t,["id"],n);const o=ce(e,["args"]);null!=o&&ue(t,["args"],o);const i=ce(e,["name"]);null!=i&&ue(t,["name"],i);if(void 0!==ce(e,["partialArgs"]))throw new Error("partialArgs parameter is not supported in Gemini API.");if(void 0!==ce(e,["willContinue"]))throw new Error("willContinue parameter is not supported in Gemini API.");return t}(s));const l=ce(e,["functionResponse"]);null!=l&&ue(t,["functionResponse"],l);const a=ce(e,["inlineData"]);null!=a&&ue(t,["inlineData"],Ho(a));const u=ce(e,["text"]);null!=u&&ue(t,["text"],u);const c=ce(e,["thought"]);null!=c&&ue(t,["thought"],c);const p=ce(e,["thoughtSignature"]);null!=p&&ue(t,["thoughtSignature"],p);const d=ce(e,["videoMetadata"]);null!=d&&ue(t,["videoMetadata"],d);return t}(e))),ue(t,["parts"],e)}const o=ce(e,["role"]);return null!=o&&ue(t,["role"],o),t}function Vo(e,t){const n=ce(e,["generationConfig"]);void 0!==t&&null!=n&&ue(t,["setup","generationConfig"],n);const o=ce(e,["responseModalities"]);void 0!==t&&null!=o&&ue(t,["setup","generationConfig","responseModalities"],o);const i=ce(e,["temperature"]);void 0!==t&&null!=i&&ue(t,["setup","generationConfig","temperature"],i);const r=ce(e,["topP"]);void 0!==t&&null!=r&&ue(t,["setup","generationConfig","topP"],r);const s=ce(e,["topK"]);void 0!==t&&null!=s&&ue(t,["setup","generationConfig","topK"],s);const l=ce(e,["maxOutputTokens"]);void 0!==t&&null!=l&&ue(t,["setup","generationConfig","maxOutputTokens"],l);const a=ce(e,["mediaResolution"]);void 0!==t&&null!=a&&ue(t,["setup","generationConfig","mediaResolution"],a);const u=ce(e,["seed"]);void 0!==t&&null!=u&&ue(t,["setup","generationConfig","seed"],u);const c=ce(e,["speechConfig"]);void 0!==t&&null!=c&&ue(t,["setup","generationConfig","speechConfig"],dt(c));const p=ce(e,["thinkingConfig"]);void 0!==t&&null!=p&&ue(t,["setup","generationConfig","thinkingConfig"],p);const d=ce(e,["enableAffectiveDialog"]);void 0!==t&&null!=d&&ue(t,["setup","generationConfig","enableAffectiveDialog"],d);const h=ce(e,["systemInstruction"]);void 0!==t&&null!=h&&ue(t,["setup","systemInstruction"],jo(st(h)));const f=ce(e,["tools"]);if(void 0!==t&&null!=f){let e=ft(f);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==ce(e,["retrieval"]))throw new Error("retrieval parameter is not supported in Gemini API.");const n=ce(e,["computerUse"]);null!=n&&ue(t,["computerUse"],n);const o=ce(e,["fileSearch"]);null!=o&&ue(t,["fileSearch"],o);const i=ce(e,["codeExecution"]);null!=i&&ue(t,["codeExecution"],i);if(void 0!==ce(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const r=ce(e,["functionDeclarations"]);if(null!=r){let e=r;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["functionDeclarations"],e)}const s=ce(e,["googleMaps"]);null!=s&&ue(t,["googleMaps"],function(e){const t={};if(void 0!==ce(e,["authConfig"]))throw new Error("authConfig parameter is not supported in Gemini API.");const n=ce(e,["enableWidget"]);return null!=n&&ue(t,["enableWidget"],n),t}(s));const l=ce(e,["googleSearch"]);null!=l&&ue(t,["googleSearch"],function(e){const t={};if(void 0!==ce(e,["excludeDomains"]))throw new Error("excludeDomains parameter is not supported in Gemini API.");if(void 0!==ce(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is not supported in Gemini API.");const n=ce(e,["timeRangeFilter"]);return null!=n&&ue(t,["timeRangeFilter"],n),t}(l));const a=ce(e,["googleSearchRetrieval"]);null!=a&&ue(t,["googleSearchRetrieval"],a);const u=ce(e,["urlContext"]);null!=u&&ue(t,["urlContext"],u);return t}(ht(e)))),ue(t,["setup","tools"],e)}const m=ce(e,["sessionResumption"]);void 0!==t&&null!=m&&ue(t,["setup","sessionResumption"],function(e){const t={},n=ce(e,["handle"]);null!=n&&ue(t,["handle"],n);if(void 0!==ce(e,["transparent"]))throw new Error("transparent parameter is not supported in Gemini API.");return t}(m));const g=ce(e,["inputAudioTranscription"]);void 0!==t&&null!=g&&ue(t,["setup","inputAudioTranscription"],g);const y=ce(e,["outputAudioTranscription"]);void 0!==t&&null!=y&&ue(t,["setup","outputAudioTranscription"],y);const v=ce(e,["realtimeInputConfig"]);void 0!==t&&null!=v&&ue(t,["setup","realtimeInputConfig"],v);const E=ce(e,["contextWindowCompression"]);void 0!==t&&null!=E&&ue(t,["setup","contextWindowCompression"],E);const T=ce(e,["proactivity"]);if(void 0!==t&&null!=T&&ue(t,["setup","proactivity"],T),void 0!==ce(e,["explicitVadSignal"]))throw new Error("explicitVadSignal parameter is not supported in Gemini API.");return{}}function Bo(e,t){const n=ce(e,["generationConfig"]);void 0!==t&&null!=n&&ue(t,["setup","generationConfig"],function(e){const t={},n=ce(e,["modelSelectionConfig"]);null!=n&&ue(t,["modelConfig"],n);const o=ce(e,["responseJsonSchema"]);null!=o&&ue(t,["responseJsonSchema"],o);const i=ce(e,["audioTimestamp"]);null!=i&&ue(t,["audioTimestamp"],i);const r=ce(e,["candidateCount"]);null!=r&&ue(t,["candidateCount"],r);const s=ce(e,["enableAffectiveDialog"]);null!=s&&ue(t,["enableAffectiveDialog"],s);const l=ce(e,["frequencyPenalty"]);null!=l&&ue(t,["frequencyPenalty"],l);const a=ce(e,["logprobs"]);null!=a&&ue(t,["logprobs"],a);const u=ce(e,["maxOutputTokens"]);null!=u&&ue(t,["maxOutputTokens"],u);const c=ce(e,["mediaResolution"]);null!=c&&ue(t,["mediaResolution"],c);const p=ce(e,["presencePenalty"]);null!=p&&ue(t,["presencePenalty"],p);const d=ce(e,["responseLogprobs"]);null!=d&&ue(t,["responseLogprobs"],d);const h=ce(e,["responseMimeType"]);null!=h&&ue(t,["responseMimeType"],h);const f=ce(e,["responseModalities"]);null!=f&&ue(t,["responseModalities"],f);const m=ce(e,["responseSchema"]);null!=m&&ue(t,["responseSchema"],m);const g=ce(e,["routingConfig"]);null!=g&&ue(t,["routingConfig"],g);const y=ce(e,["seed"]);null!=y&&ue(t,["seed"],y);const v=ce(e,["speechConfig"]);null!=v&&ue(t,["speechConfig"],v);const E=ce(e,["stopSequences"]);null!=E&&ue(t,["stopSequences"],E);const T=ce(e,["temperature"]);null!=T&&ue(t,["temperature"],T);const I=ce(e,["thinkingConfig"]);null!=I&&ue(t,["thinkingConfig"],I);const _=ce(e,["topK"]);null!=_&&ue(t,["topK"],_);const S=ce(e,["topP"]);if(null!=S&&ue(t,["topP"],S),void 0!==ce(e,["enableEnhancedCivicAnswers"]))throw new Error("enableEnhancedCivicAnswers parameter is not supported in Vertex AI.");return t}(n));const o=ce(e,["responseModalities"]);void 0!==t&&null!=o&&ue(t,["setup","generationConfig","responseModalities"],o);const i=ce(e,["temperature"]);void 0!==t&&null!=i&&ue(t,["setup","generationConfig","temperature"],i);const r=ce(e,["topP"]);void 0!==t&&null!=r&&ue(t,["setup","generationConfig","topP"],r);const s=ce(e,["topK"]);void 0!==t&&null!=s&&ue(t,["setup","generationConfig","topK"],s);const l=ce(e,["maxOutputTokens"]);void 0!==t&&null!=l&&ue(t,["setup","generationConfig","maxOutputTokens"],l);const a=ce(e,["mediaResolution"]);void 0!==t&&null!=a&&ue(t,["setup","generationConfig","mediaResolution"],a);const u=ce(e,["seed"]);void 0!==t&&null!=u&&ue(t,["setup","generationConfig","seed"],u);const c=ce(e,["speechConfig"]);void 0!==t&&null!=c&&ue(t,["setup","generationConfig","speechConfig"],dt(c));const p=ce(e,["thinkingConfig"]);void 0!==t&&null!=p&&ue(t,["setup","generationConfig","thinkingConfig"],p);const d=ce(e,["enableAffectiveDialog"]);void 0!==t&&null!=d&&ue(t,["setup","generationConfig","enableAffectiveDialog"],d);const h=ce(e,["systemInstruction"]);void 0!==t&&null!=h&&ue(t,["setup","systemInstruction"],st(h));const f=ce(e,["tools"]);if(void 0!==t&&null!=f){let e=ft(f);Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["retrieval"]);null!=n&&ue(t,["retrieval"],n);const o=ce(e,["computerUse"]);null!=o&&ue(t,["computerUse"],o);if(void 0!==ce(e,["fileSearch"]))throw new Error("fileSearch parameter is not supported in Vertex AI.");const i=ce(e,["codeExecution"]);null!=i&&ue(t,["codeExecution"],i);const r=ce(e,["enterpriseWebSearch"]);null!=r&&ue(t,["enterpriseWebSearch"],r);const s=ce(e,["functionDeclarations"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["description"]);null!=n&&ue(t,["description"],n);const o=ce(e,["name"]);null!=o&&ue(t,["name"],o);const i=ce(e,["parameters"]);null!=i&&ue(t,["parameters"],i);const r=ce(e,["parametersJsonSchema"]);null!=r&&ue(t,["parametersJsonSchema"],r);const s=ce(e,["response"]);null!=s&&ue(t,["response"],s);const l=ce(e,["responseJsonSchema"]);if(null!=l&&ue(t,["responseJsonSchema"],l),void 0!==ce(e,["behavior"]))throw new Error("behavior parameter is not supported in Vertex AI.");return t}(e))),ue(t,["functionDeclarations"],e)}const l=ce(e,["googleMaps"]);null!=l&&ue(t,["googleMaps"],l);const a=ce(e,["googleSearch"]);null!=a&&ue(t,["googleSearch"],a);const u=ce(e,["googleSearchRetrieval"]);null!=u&&ue(t,["googleSearchRetrieval"],u);const c=ce(e,["urlContext"]);null!=c&&ue(t,["urlContext"],c);return t}(ht(e)))),ue(t,["setup","tools"],e)}const m=ce(e,["sessionResumption"]);void 0!==t&&null!=m&&ue(t,["setup","sessionResumption"],m);const g=ce(e,["inputAudioTranscription"]);void 0!==t&&null!=g&&ue(t,["setup","inputAudioTranscription"],g);const y=ce(e,["outputAudioTranscription"]);void 0!==t&&null!=y&&ue(t,["setup","outputAudioTranscription"],y);const v=ce(e,["realtimeInputConfig"]);void 0!==t&&null!=v&&ue(t,["setup","realtimeInputConfig"],v);const E=ce(e,["contextWindowCompression"]);void 0!==t&&null!=E&&ue(t,["setup","contextWindowCompression"],E);const T=ce(e,["proactivity"]);void 0!==t&&null!=T&&ue(t,["setup","proactivity"],T);const I=ce(e,["explicitVadSignal"]);return void 0!==t&&null!=I&&ue(t,["setup","explicitVadSignal"],I),{}}function Jo(e){const t={},n=ce(e,["media"]);if(null!=n){let e=Xe(n);Array.isArray(e)&&(e=e.map(e=>Ho(e))),ue(t,["mediaChunks"],e)}const o=ce(e,["audio"]);null!=o&&ue(t,["audio"],Ho(et(o)));const i=ce(e,["audioStreamEnd"]);null!=i&&ue(t,["audioStreamEnd"],i);const r=ce(e,["video"]);null!=r&&ue(t,["video"],Ho(Ze(r)));const s=ce(e,["text"]);null!=s&&ue(t,["text"],s);const l=ce(e,["activityStart"]);null!=l&&ue(t,["activityStart"],l);const a=ce(e,["activityEnd"]);return null!=a&&ue(t,["activityEnd"],a),t}function $o(e){const t={},n=ce(e,["media"]);if(null!=n){let e=Xe(n);Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["mediaChunks"],e)}const o=ce(e,["audio"]);null!=o&&ue(t,["audio"],et(o));const i=ce(e,["audioStreamEnd"]);null!=i&&ue(t,["audioStreamEnd"],i);const r=ce(e,["video"]);null!=r&&ue(t,["video"],Ze(r));const s=ce(e,["text"]);null!=s&&ue(t,["text"],s);const l=ce(e,["activityStart"]);null!=l&&ue(t,["activityStart"],l);const a=ce(e,["activityEnd"]);return null!=a&&ue(t,["activityEnd"],a),t}function Yo(e){const t={},n=ce(e,["setupComplete"]);null!=n&&ue(t,["setupComplete"],n);const o=ce(e,["serverContent"]);null!=o&&ue(t,["serverContent"],o);const i=ce(e,["toolCall"]);null!=i&&ue(t,["toolCall"],i);const r=ce(e,["toolCallCancellation"]);null!=r&&ue(t,["toolCallCancellation"],r);const s=ce(e,["usageMetadata"]);null!=s&&ue(t,["usageMetadata"],function(e){const t={},n=ce(e,["promptTokenCount"]);null!=n&&ue(t,["promptTokenCount"],n);const o=ce(e,["cachedContentTokenCount"]);null!=o&&ue(t,["cachedContentTokenCount"],o);const i=ce(e,["candidatesTokenCount"]);null!=i&&ue(t,["responseTokenCount"],i);const r=ce(e,["toolUsePromptTokenCount"]);null!=r&&ue(t,["toolUsePromptTokenCount"],r);const s=ce(e,["thoughtsTokenCount"]);null!=s&&ue(t,["thoughtsTokenCount"],s);const l=ce(e,["totalTokenCount"]);null!=l&&ue(t,["totalTokenCount"],l);const a=ce(e,["promptTokensDetails"]);if(null!=a){let e=a;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["promptTokensDetails"],e)}const u=ce(e,["cacheTokensDetails"]);if(null!=u){let e=u;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["cacheTokensDetails"],e)}const c=ce(e,["candidatesTokensDetails"]);if(null!=c){let e=c;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["responseTokensDetails"],e)}const p=ce(e,["toolUsePromptTokensDetails"]);if(null!=p){let e=p;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["toolUsePromptTokensDetails"],e)}const d=ce(e,["trafficType"]);null!=d&&ue(t,["trafficType"],d);return t}(s));const l=ce(e,["goAway"]);null!=l&&ue(t,["goAway"],l);const a=ce(e,["sessionResumptionUpdate"]);null!=a&&ue(t,["sessionResumptionUpdate"],a);const u=ce(e,["voiceActivityDetectionSignal"]);null!=u&&ue(t,["voiceActivityDetectionSignal"],u);const c=ce(e,["voiceActivity"]);return null!=c&&ue(t,["voiceActivity"],function(e){const t={},n=ce(e,["type"]);null!=n&&ue(t,["voiceActivityType"],n);return t}
235
+ /**
236
+ * @license
237
+ * Copyright 2025 Google LLC
238
+ * SPDX-License-Identifier: Apache-2.0
239
+ */(c)),t}function Ko(e,t){const n={},o=ce(e,["content"]);null!=o&&ue(n,["content"],o);const i=ce(e,["citationMetadata"]);null!=i&&ue(n,["citationMetadata"],function(e){const t={},n=ce(e,["citationSources"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["citations"],e)}return t}(i));const r=ce(e,["tokenCount"]);null!=r&&ue(n,["tokenCount"],r);const s=ce(e,["finishReason"]);null!=s&&ue(n,["finishReason"],s);const l=ce(e,["avgLogprobs"]);null!=l&&ue(n,["avgLogprobs"],l);const a=ce(e,["groundingMetadata"]);null!=a&&ue(n,["groundingMetadata"],a);const u=ce(e,["index"]);null!=u&&ue(n,["index"],u);const c=ce(e,["logprobsResult"]);null!=c&&ue(n,["logprobsResult"],c);const p=ce(e,["safetyRatings"]);if(null!=p){let e=p;Array.isArray(e)&&(e=e.map(e=>e)),ue(n,["safetyRatings"],e)}const d=ce(e,["urlContextMetadata"]);return null!=d&&ue(n,["urlContextMetadata"],d),n}function Wo(e,t){const n={},o=ce(e,["values"]);null!=o&&ue(n,["values"],o);const i=ce(e,["statistics"]);return null!=i&&ue(n,["statistics"],function(e){const t={},n=ce(e,["truncated"]);null!=n&&ue(t,["truncated"],n);const o=ce(e,["token_count"]);null!=o&&ue(t,["tokenCount"],o);return t}(i)),n}function zo(e,t){const n={},o=ce(e,["parts"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["mediaResolution"]);null!=n&&ue(t,["mediaResolution"],n);const o=ce(e,["codeExecutionResult"]);null!=o&&ue(t,["codeExecutionResult"],o);const i=ce(e,["executableCode"]);null!=i&&ue(t,["executableCode"],i);const r=ce(e,["fileData"]);null!=r&&ue(t,["fileData"],function(e){const t={};if(void 0!==ce(e,["displayName"]))throw new Error("displayName parameter is not supported in Gemini API.");const n=ce(e,["fileUri"]);null!=n&&ue(t,["fileUri"],n);const o=ce(e,["mimeType"]);null!=o&&ue(t,["mimeType"],o);return t}(r));const s=ce(e,["functionCall"]);null!=s&&ue(t,["functionCall"],function(e){const t={},n=ce(e,["id"]);null!=n&&ue(t,["id"],n);const o=ce(e,["args"]);null!=o&&ue(t,["args"],o);const i=ce(e,["name"]);null!=i&&ue(t,["name"],i);if(void 0!==ce(e,["partialArgs"]))throw new Error("partialArgs parameter is not supported in Gemini API.");if(void 0!==ce(e,["willContinue"]))throw new Error("willContinue parameter is not supported in Gemini API.");return t}(s));const l=ce(e,["functionResponse"]);null!=l&&ue(t,["functionResponse"],l);const a=ce(e,["inlineData"]);null!=a&&ue(t,["inlineData"],function(e){const t={},n=ce(e,["data"]);if(null!=n&&ue(t,["data"],n),void 0!==ce(e,["displayName"]))throw new Error("displayName parameter is not supported in Gemini API.");const o=ce(e,["mimeType"]);return null!=o&&ue(t,["mimeType"],o),t}(a));const u=ce(e,["text"]);null!=u&&ue(t,["text"],u);const c=ce(e,["thought"]);null!=c&&ue(t,["thought"],c);const p=ce(e,["thoughtSignature"]);null!=p&&ue(t,["thoughtSignature"],p);const d=ce(e,["videoMetadata"]);null!=d&&ue(t,["videoMetadata"],d);return t}(e))),ue(n,["parts"],e)}const i=ce(e,["role"]);return null!=i&&ue(n,["role"],i),n}function Xo(e,t,n){const o=ce(e,["systemInstruction"]);void 0!==t&&null!=o&&ue(t,["systemInstruction"],st(o));const i=ce(e,["tools"]);if(void 0!==t&&null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>Ni(e))),ue(t,["tools"],e)}const r=ce(e,["generationConfig"]);return void 0!==t&&null!=r&&ue(t,["generationConfig"],function(e){const t={},n=ce(e,["modelSelectionConfig"]);null!=n&&ue(t,["modelConfig"],n);const o=ce(e,["responseJsonSchema"]);null!=o&&ue(t,["responseJsonSchema"],o);const i=ce(e,["audioTimestamp"]);null!=i&&ue(t,["audioTimestamp"],i);const r=ce(e,["candidateCount"]);null!=r&&ue(t,["candidateCount"],r);const s=ce(e,["enableAffectiveDialog"]);null!=s&&ue(t,["enableAffectiveDialog"],s);const l=ce(e,["frequencyPenalty"]);null!=l&&ue(t,["frequencyPenalty"],l);const a=ce(e,["logprobs"]);null!=a&&ue(t,["logprobs"],a);const u=ce(e,["maxOutputTokens"]);null!=u&&ue(t,["maxOutputTokens"],u);const c=ce(e,["mediaResolution"]);null!=c&&ue(t,["mediaResolution"],c);const p=ce(e,["presencePenalty"]);null!=p&&ue(t,["presencePenalty"],p);const d=ce(e,["responseLogprobs"]);null!=d&&ue(t,["responseLogprobs"],d);const h=ce(e,["responseMimeType"]);null!=h&&ue(t,["responseMimeType"],h);const f=ce(e,["responseModalities"]);null!=f&&ue(t,["responseModalities"],f);const m=ce(e,["responseSchema"]);null!=m&&ue(t,["responseSchema"],m);const g=ce(e,["routingConfig"]);null!=g&&ue(t,["routingConfig"],g);const y=ce(e,["seed"]);null!=y&&ue(t,["seed"],y);const v=ce(e,["speechConfig"]);null!=v&&ue(t,["speechConfig"],v);const E=ce(e,["stopSequences"]);null!=E&&ue(t,["stopSequences"],E);const T=ce(e,["temperature"]);null!=T&&ue(t,["temperature"],T);const I=ce(e,["thinkingConfig"]);null!=I&&ue(t,["thinkingConfig"],I);const _=ce(e,["topK"]);null!=_&&ue(t,["topK"],_);const S=ce(e,["topP"]);null!=S&&ue(t,["topP"],S);if(void 0!==ce(e,["enableEnhancedCivicAnswers"]))throw new Error("enableEnhancedCivicAnswers parameter is not supported in Vertex AI.");return t}(r)),{}}function Qo(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["contents"]);if(null!=r){let e=at(r);Array.isArray(e)&&(e=e.map(e=>zo(e))),ue(o,["contents"],e)}const s=ce(t,["config"]);return null!=s&&function(e){if(void 0!==ce(e,["systemInstruction"]))throw new Error("systemInstruction parameter is not supported in Gemini API.");if(void 0!==ce(e,["tools"]))throw new Error("tools parameter is not supported in Gemini API.");if(void 0!==ce(e,["generationConfig"]))throw new Error("generationConfig parameter is not supported in Gemini API.")}(s),o}function Zo(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["prompt"]);null!=r&&ue(o,["instances[0]","prompt"],r);const s=ce(t,["referenceImages"]);if(null!=s){let e=s;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["referenceImage"]);null!=n&&ue(t,["referenceImage"],Ti(n));const o=ce(e,["referenceId"]);null!=o&&ue(t,["referenceId"],o);const i=ce(e,["referenceType"]);null!=i&&ue(t,["referenceType"],i);const r=ce(e,["maskImageConfig"]);null!=r&&ue(t,["maskImageConfig"],function(e){const t={},n=ce(e,["maskMode"]);null!=n&&ue(t,["maskMode"],n);const o=ce(e,["segmentationClasses"]);null!=o&&ue(t,["maskClasses"],o);const i=ce(e,["maskDilation"]);null!=i&&ue(t,["dilation"],i);return t}(r));const s=ce(e,["controlImageConfig"]);null!=s&&ue(t,["controlImageConfig"],function(e){const t={},n=ce(e,["controlType"]);null!=n&&ue(t,["controlType"],n);const o=ce(e,["enableControlImageComputation"]);return null!=o&&ue(t,["computeControl"],o),t}(s));const l=ce(e,["styleImageConfig"]);null!=l&&ue(t,["styleImageConfig"],l);const a=ce(e,["subjectImageConfig"]);null!=a&&ue(t,["subjectImageConfig"],a);return t}(e))),ue(o,["instances[0]","referenceImages"],e)}const l=ce(t,["config"]);return null!=l&&function(e,t){const n=ce(e,["outputGcsUri"]);void 0!==t&&null!=n&&ue(t,["parameters","storageUri"],n);const o=ce(e,["negativePrompt"]);void 0!==t&&null!=o&&ue(t,["parameters","negativePrompt"],o);const i=ce(e,["numberOfImages"]);void 0!==t&&null!=i&&ue(t,["parameters","sampleCount"],i);const r=ce(e,["aspectRatio"]);void 0!==t&&null!=r&&ue(t,["parameters","aspectRatio"],r);const s=ce(e,["guidanceScale"]);void 0!==t&&null!=s&&ue(t,["parameters","guidanceScale"],s);const l=ce(e,["seed"]);void 0!==t&&null!=l&&ue(t,["parameters","seed"],l);const a=ce(e,["safetyFilterLevel"]);void 0!==t&&null!=a&&ue(t,["parameters","safetySetting"],a);const u=ce(e,["personGeneration"]);void 0!==t&&null!=u&&ue(t,["parameters","personGeneration"],u);const c=ce(e,["includeSafetyAttributes"]);void 0!==t&&null!=c&&ue(t,["parameters","includeSafetyAttributes"],c);const p=ce(e,["includeRaiReason"]);void 0!==t&&null!=p&&ue(t,["parameters","includeRaiReason"],p);const d=ce(e,["language"]);void 0!==t&&null!=d&&ue(t,["parameters","language"],d);const h=ce(e,["outputMimeType"]);void 0!==t&&null!=h&&ue(t,["parameters","outputOptions","mimeType"],h);const f=ce(e,["outputCompressionQuality"]);void 0!==t&&null!=f&&ue(t,["parameters","outputOptions","compressionQuality"],f);const m=ce(e,["addWatermark"]);void 0!==t&&null!=m&&ue(t,["parameters","addWatermark"],m);const g=ce(e,["labels"]);void 0!==t&&null!=g&&ue(t,["labels"],g);const y=ce(e,["editMode"]);void 0!==t&&null!=y&&ue(t,["parameters","editMode"],y);const v=ce(e,["baseSteps"]);void 0!==t&&null!=v&&ue(t,["parameters","editConfig","baseSteps"],v)}(l,o),o}function ei(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["contents"]);if(null!=r){let t=lt(e,r);Array.isArray(t)&&(t=t.map(e=>e)),ue(o,["requests[]","content"],t)}const s=ce(t,["content"]);null!=s&&zo(st(s));const l=ce(t,["config"]);null!=l&&function(e,t){const n=ce(e,["taskType"]);void 0!==t&&null!=n&&ue(t,["requests[]","taskType"],n);const o=ce(e,["title"]);void 0!==t&&null!=o&&ue(t,["requests[]","title"],o);const i=ce(e,["outputDimensionality"]);if(void 0!==t&&null!=i&&ue(t,["requests[]","outputDimensionality"],i),void 0!==ce(e,["mimeType"]))throw new Error("mimeType parameter is not supported in Gemini API.");if(void 0!==ce(e,["autoTruncate"]))throw new Error("autoTruncate parameter is not supported in Gemini API.")}(l,o);const a=ce(t,["model"]);return void 0!==a&&ue(o,["requests[]","model"],We(e,a)),o}function ti(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));let r=ce(n,["embeddingApiType"]);if(void 0===r&&(r="PREDICT"),"PREDICT"===r){const n=ce(t,["contents"]);if(null!=n){let t=lt(e,n);Array.isArray(t)&&(t=t.map(e=>e)),ue(o,["instances[]","content"],t)}}let s=ce(n,["embeddingApiType"]);if(void 0===s&&(s="PREDICT"),"EMBED_CONTENT"===s){const e=ce(t,["content"]);null!=e&&ue(o,["content"],st(e))}const l=ce(t,["config"]);return null!=l&&function(e,t,n){let o=ce(n,["embeddingApiType"]);if(void 0===o&&(o="PREDICT"),"PREDICT"===o){const n=ce(e,["taskType"]);void 0!==t&&null!=n&&ue(t,["instances[]","task_type"],n)}else if("EMBED_CONTENT"===o){const n=ce(e,["taskType"]);void 0!==t&&null!=n&&ue(t,["taskType"],n)}let i=ce(n,["embeddingApiType"]);if(void 0===i&&(i="PREDICT"),"PREDICT"===i){const n=ce(e,["title"]);void 0!==t&&null!=n&&ue(t,["instances[]","title"],n)}else if("EMBED_CONTENT"===i){const n=ce(e,["title"]);void 0!==t&&null!=n&&ue(t,["title"],n)}let r=ce(n,["embeddingApiType"]);if(void 0===r&&(r="PREDICT"),"PREDICT"===r){const n=ce(e,["outputDimensionality"]);void 0!==t&&null!=n&&ue(t,["parameters","outputDimensionality"],n)}else if("EMBED_CONTENT"===r){const n=ce(e,["outputDimensionality"]);void 0!==t&&null!=n&&ue(t,["outputDimensionality"],n)}let s=ce(n,["embeddingApiType"]);if(void 0===s&&(s="PREDICT"),"PREDICT"===s){const n=ce(e,["mimeType"]);void 0!==t&&null!=n&&ue(t,["instances[]","mimeType"],n)}let l=ce(n,["embeddingApiType"]);if(void 0===l&&(l="PREDICT"),"PREDICT"===l){const n=ce(e,["autoTruncate"]);void 0!==t&&null!=n&&ue(t,["parameters","autoTruncate"],n)}else if("EMBED_CONTENT"===l){const n=ce(e,["autoTruncate"]);void 0!==t&&null!=n&&ue(t,["autoTruncate"],n)}}(l,o,n),o}function ni(e,t,n,o){const i={},r=ce(t,["systemInstruction"]);void 0!==n&&null!=r&&ue(n,["systemInstruction"],zo(st(r)));const s=ce(t,["temperature"]);null!=s&&ue(i,["temperature"],s);const l=ce(t,["topP"]);null!=l&&ue(i,["topP"],l);const a=ce(t,["topK"]);null!=a&&ue(i,["topK"],a);const u=ce(t,["candidateCount"]);null!=u&&ue(i,["candidateCount"],u);const c=ce(t,["maxOutputTokens"]);null!=c&&ue(i,["maxOutputTokens"],c);const p=ce(t,["stopSequences"]);null!=p&&ue(i,["stopSequences"],p);const d=ce(t,["responseLogprobs"]);null!=d&&ue(i,["responseLogprobs"],d);const h=ce(t,["logprobs"]);null!=h&&ue(i,["logprobs"],h);const f=ce(t,["presencePenalty"]);null!=f&&ue(i,["presencePenalty"],f);const m=ce(t,["frequencyPenalty"]);null!=m&&ue(i,["frequencyPenalty"],m);const g=ce(t,["seed"]);null!=g&&ue(i,["seed"],g);const y=ce(t,["responseMimeType"]);null!=y&&ue(i,["responseMimeType"],y);const v=ce(t,["responseSchema"]);null!=v&&ue(i,["responseSchema"],ct(v));const E=ce(t,["responseJsonSchema"]);if(null!=E&&ue(i,["responseJsonSchema"],E),void 0!==ce(t,["routingConfig"]))throw new Error("routingConfig parameter is not supported in Gemini API.");if(void 0!==ce(t,["modelSelectionConfig"]))throw new Error("modelSelectionConfig parameter is not supported in Gemini API.");const T=ce(t,["safetySettings"]);if(void 0!==n&&null!=T){let e=T;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["category"]);null!=n&&ue(t,["category"],n);if(void 0!==ce(e,["method"]))throw new Error("method parameter is not supported in Gemini API.");const o=ce(e,["threshold"]);null!=o&&ue(t,["threshold"],o);return t}(e))),ue(n,["safetySettings"],e)}const I=ce(t,["tools"]);if(void 0!==n&&null!=I){let e=ft(I);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==ce(e,["retrieval"]))throw new Error("retrieval parameter is not supported in Gemini API.");const n=ce(e,["computerUse"]);null!=n&&ue(t,["computerUse"],n);const o=ce(e,["fileSearch"]);null!=o&&ue(t,["fileSearch"],o);const i=ce(e,["codeExecution"]);null!=i&&ue(t,["codeExecution"],i);if(void 0!==ce(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const r=ce(e,["functionDeclarations"]);if(null!=r){let e=r;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["functionDeclarations"],e)}const s=ce(e,["googleMaps"]);null!=s&&ue(t,["googleMaps"],function(e){const t={};if(void 0!==ce(e,["authConfig"]))throw new Error("authConfig parameter is not supported in Gemini API.");const n=ce(e,["enableWidget"]);null!=n&&ue(t,["enableWidget"],n);return t}(s));const l=ce(e,["googleSearch"]);null!=l&&ue(t,["googleSearch"],function(e){const t={};if(void 0!==ce(e,["excludeDomains"]))throw new Error("excludeDomains parameter is not supported in Gemini API.");if(void 0!==ce(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is not supported in Gemini API.");const n=ce(e,["timeRangeFilter"]);null!=n&&ue(t,["timeRangeFilter"],n);return t}(l));const a=ce(e,["googleSearchRetrieval"]);null!=a&&ue(t,["googleSearchRetrieval"],a);const u=ce(e,["urlContext"]);null!=u&&ue(t,["urlContext"],u);return t}(ht(e)))),ue(n,["tools"],e)}const _=ce(t,["toolConfig"]);if(void 0!==n&&null!=_&&ue(n,["toolConfig"],function(e){const t={},n=ce(e,["retrievalConfig"]);null!=n&&ue(t,["retrievalConfig"],n);const o=ce(e,["functionCallingConfig"]);null!=o&&ue(t,["functionCallingConfig"],function(e){const t={},n=ce(e,["allowedFunctionNames"]);null!=n&&ue(t,["allowedFunctionNames"],n);const o=ce(e,["mode"]);if(null!=o&&ue(t,["mode"],o),void 0!==ce(e,["streamFunctionCallArguments"]))throw new Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return t}(o));return t}(_)),void 0!==ce(t,["labels"]))throw new Error("labels parameter is not supported in Gemini API.");const S=ce(t,["cachedContent"]);void 0!==n&&null!=S&&ue(n,["cachedContent"],mt(e,S));const A=ce(t,["responseModalities"]);null!=A&&ue(i,["responseModalities"],A);const C=ce(t,["mediaResolution"]);null!=C&&ue(i,["mediaResolution"],C);const O=ce(t,["speechConfig"]);if(null!=O&&ue(i,["speechConfig"],pt(O)),void 0!==ce(t,["audioTimestamp"]))throw new Error("audioTimestamp parameter is not supported in Gemini API.");const b=ce(t,["thinkingConfig"]);null!=b&&ue(i,["thinkingConfig"],b);const R=ce(t,["imageConfig"]);null!=R&&ue(i,["imageConfig"],function(e){const t={},n=ce(e,["aspectRatio"]);null!=n&&ue(t,["aspectRatio"],n);const o=ce(e,["imageSize"]);null!=o&&ue(t,["imageSize"],o);if(void 0!==ce(e,["personGeneration"]))throw new Error("personGeneration parameter is not supported in Gemini API.");if(void 0!==ce(e,["outputMimeType"]))throw new Error("outputMimeType parameter is not supported in Gemini API.");if(void 0!==ce(e,["outputCompressionQuality"]))throw new Error("outputCompressionQuality parameter is not supported in Gemini API.");return t}(R));const w=ce(t,["enableEnhancedCivicAnswers"]);if(null!=w&&ue(i,["enableEnhancedCivicAnswers"],w),void 0!==ce(t,["modelArmorConfig"]))throw new Error("modelArmorConfig parameter is not supported in Gemini API.");return i}function oi(e,t,n,o){const i={},r=ce(t,["systemInstruction"]);void 0!==n&&null!=r&&ue(n,["systemInstruction"],st(r));const s=ce(t,["temperature"]);null!=s&&ue(i,["temperature"],s);const l=ce(t,["topP"]);null!=l&&ue(i,["topP"],l);const a=ce(t,["topK"]);null!=a&&ue(i,["topK"],a);const u=ce(t,["candidateCount"]);null!=u&&ue(i,["candidateCount"],u);const c=ce(t,["maxOutputTokens"]);null!=c&&ue(i,["maxOutputTokens"],c);const p=ce(t,["stopSequences"]);null!=p&&ue(i,["stopSequences"],p);const d=ce(t,["responseLogprobs"]);null!=d&&ue(i,["responseLogprobs"],d);const h=ce(t,["logprobs"]);null!=h&&ue(i,["logprobs"],h);const f=ce(t,["presencePenalty"]);null!=f&&ue(i,["presencePenalty"],f);const m=ce(t,["frequencyPenalty"]);null!=m&&ue(i,["frequencyPenalty"],m);const g=ce(t,["seed"]);null!=g&&ue(i,["seed"],g);const y=ce(t,["responseMimeType"]);null!=y&&ue(i,["responseMimeType"],y);const v=ce(t,["responseSchema"]);null!=v&&ue(i,["responseSchema"],ct(v));const E=ce(t,["responseJsonSchema"]);null!=E&&ue(i,["responseJsonSchema"],E);const T=ce(t,["routingConfig"]);null!=T&&ue(i,["routingConfig"],T);const I=ce(t,["modelSelectionConfig"]);null!=I&&ue(i,["modelConfig"],I);const _=ce(t,["safetySettings"]);if(void 0!==n&&null!=_){let e=_;Array.isArray(e)&&(e=e.map(e=>e)),ue(n,["safetySettings"],e)}const S=ce(t,["tools"]);if(void 0!==n&&null!=S){let e=ft(S);Array.isArray(e)&&(e=e.map(e=>Ni(ht(e)))),ue(n,["tools"],e)}const A=ce(t,["toolConfig"]);void 0!==n&&null!=A&&ue(n,["toolConfig"],A);const C=ce(t,["labels"]);void 0!==n&&null!=C&&ue(n,["labels"],C);const O=ce(t,["cachedContent"]);void 0!==n&&null!=O&&ue(n,["cachedContent"],mt(e,O));const b=ce(t,["responseModalities"]);null!=b&&ue(i,["responseModalities"],b);const R=ce(t,["mediaResolution"]);null!=R&&ue(i,["mediaResolution"],R);const w=ce(t,["speechConfig"]);null!=w&&ue(i,["speechConfig"],pt(w));const N=ce(t,["audioTimestamp"]);null!=N&&ue(i,["audioTimestamp"],N);const P=ce(t,["thinkingConfig"]);null!=P&&ue(i,["thinkingConfig"],P);const M=ce(t,["imageConfig"]);if(null!=M&&ue(i,["imageConfig"],function(e){const t={},n=ce(e,["aspectRatio"]);null!=n&&ue(t,["aspectRatio"],n);const o=ce(e,["imageSize"]);null!=o&&ue(t,["imageSize"],o);const i=ce(e,["personGeneration"]);null!=i&&ue(t,["personGeneration"],i);const r=ce(e,["outputMimeType"]);null!=r&&ue(t,["imageOutputOptions","mimeType"],r);const s=ce(e,["outputCompressionQuality"]);null!=s&&ue(t,["imageOutputOptions","compressionQuality"],s);return t}(M)),void 0!==ce(t,["enableEnhancedCivicAnswers"]))throw new Error("enableEnhancedCivicAnswers parameter is not supported in Vertex AI.");const D=ce(t,["modelArmorConfig"]);return void 0!==n&&null!=D&&ue(n,["modelArmorConfig"],D),i}function ii(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["contents"]);if(null!=r){let e=at(r);Array.isArray(e)&&(e=e.map(e=>zo(e))),ue(o,["contents"],e)}const s=ce(t,["config"]);return null!=s&&ue(o,["generationConfig"],ni(e,s,o)),o}function ri(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["contents"]);if(null!=r){let e=at(r);Array.isArray(e)&&(e=e.map(e=>e)),ue(o,["contents"],e)}const s=ce(t,["config"]);return null!=s&&ue(o,["generationConfig"],oi(e,s,o)),o}function si(e,t){const n={},o=ce(e,["sdkHttpResponse"]);null!=o&&ue(n,["sdkHttpResponse"],o);const i=ce(e,["candidates"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>Ko(e))),ue(n,["candidates"],e)}const r=ce(e,["modelVersion"]);null!=r&&ue(n,["modelVersion"],r);const s=ce(e,["promptFeedback"]);null!=s&&ue(n,["promptFeedback"],s);const l=ce(e,["responseId"]);null!=l&&ue(n,["responseId"],l);const a=ce(e,["usageMetadata"]);return null!=a&&ue(n,["usageMetadata"],a),n}function li(e,t){const n={},o=ce(e,["sdkHttpResponse"]);null!=o&&ue(n,["sdkHttpResponse"],o);const i=ce(e,["candidates"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>e)),ue(n,["candidates"],e)}const r=ce(e,["createTime"]);null!=r&&ue(n,["createTime"],r);const s=ce(e,["modelVersion"]);null!=s&&ue(n,["modelVersion"],s);const l=ce(e,["promptFeedback"]);null!=l&&ue(n,["promptFeedback"],l);const a=ce(e,["responseId"]);null!=a&&ue(n,["responseId"],a);const u=ce(e,["usageMetadata"]);return null!=u&&ue(n,["usageMetadata"],u),n}function ai(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["prompt"]);null!=r&&ue(o,["instances[0]","prompt"],r);const s=ce(t,["config"]);return null!=s&&function(e,t){if(void 0!==ce(e,["outputGcsUri"]))throw new Error("outputGcsUri parameter is not supported in Gemini API.");if(void 0!==ce(e,["negativePrompt"]))throw new Error("negativePrompt parameter is not supported in Gemini API.");const n=ce(e,["numberOfImages"]);void 0!==t&&null!=n&&ue(t,["parameters","sampleCount"],n);const o=ce(e,["aspectRatio"]);void 0!==t&&null!=o&&ue(t,["parameters","aspectRatio"],o);const i=ce(e,["guidanceScale"]);if(void 0!==t&&null!=i&&ue(t,["parameters","guidanceScale"],i),void 0!==ce(e,["seed"]))throw new Error("seed parameter is not supported in Gemini API.");const r=ce(e,["safetyFilterLevel"]);void 0!==t&&null!=r&&ue(t,["parameters","safetySetting"],r);const s=ce(e,["personGeneration"]);void 0!==t&&null!=s&&ue(t,["parameters","personGeneration"],s);const l=ce(e,["includeSafetyAttributes"]);void 0!==t&&null!=l&&ue(t,["parameters","includeSafetyAttributes"],l);const a=ce(e,["includeRaiReason"]);void 0!==t&&null!=a&&ue(t,["parameters","includeRaiReason"],a);const u=ce(e,["language"]);void 0!==t&&null!=u&&ue(t,["parameters","language"],u);const c=ce(e,["outputMimeType"]);void 0!==t&&null!=c&&ue(t,["parameters","outputOptions","mimeType"],c);const p=ce(e,["outputCompressionQuality"]);if(void 0!==t&&null!=p&&ue(t,["parameters","outputOptions","compressionQuality"],p),void 0!==ce(e,["addWatermark"]))throw new Error("addWatermark parameter is not supported in Gemini API.");if(void 0!==ce(e,["labels"]))throw new Error("labels parameter is not supported in Gemini API.");const d=ce(e,["imageSize"]);if(void 0!==t&&null!=d&&ue(t,["parameters","sampleImageSize"],d),void 0!==ce(e,["enhancePrompt"]))throw new Error("enhancePrompt parameter is not supported in Gemini API.")}(s,o),o}function ui(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["prompt"]);null!=r&&ue(o,["instances[0]","prompt"],r);const s=ce(t,["config"]);return null!=s&&function(e,t){const n=ce(e,["outputGcsUri"]);void 0!==t&&null!=n&&ue(t,["parameters","storageUri"],n);const o=ce(e,["negativePrompt"]);void 0!==t&&null!=o&&ue(t,["parameters","negativePrompt"],o);const i=ce(e,["numberOfImages"]);void 0!==t&&null!=i&&ue(t,["parameters","sampleCount"],i);const r=ce(e,["aspectRatio"]);void 0!==t&&null!=r&&ue(t,["parameters","aspectRatio"],r);const s=ce(e,["guidanceScale"]);void 0!==t&&null!=s&&ue(t,["parameters","guidanceScale"],s);const l=ce(e,["seed"]);void 0!==t&&null!=l&&ue(t,["parameters","seed"],l);const a=ce(e,["safetyFilterLevel"]);void 0!==t&&null!=a&&ue(t,["parameters","safetySetting"],a);const u=ce(e,["personGeneration"]);void 0!==t&&null!=u&&ue(t,["parameters","personGeneration"],u);const c=ce(e,["includeSafetyAttributes"]);void 0!==t&&null!=c&&ue(t,["parameters","includeSafetyAttributes"],c);const p=ce(e,["includeRaiReason"]);void 0!==t&&null!=p&&ue(t,["parameters","includeRaiReason"],p);const d=ce(e,["language"]);void 0!==t&&null!=d&&ue(t,["parameters","language"],d);const h=ce(e,["outputMimeType"]);void 0!==t&&null!=h&&ue(t,["parameters","outputOptions","mimeType"],h);const f=ce(e,["outputCompressionQuality"]);void 0!==t&&null!=f&&ue(t,["parameters","outputOptions","compressionQuality"],f);const m=ce(e,["addWatermark"]);void 0!==t&&null!=m&&ue(t,["parameters","addWatermark"],m);const g=ce(e,["labels"]);void 0!==t&&null!=g&&ue(t,["labels"],g);const y=ce(e,["imageSize"]);void 0!==t&&null!=y&&ue(t,["parameters","sampleImageSize"],y);const v=ce(e,["enhancePrompt"]);void 0!==t&&null!=v&&ue(t,["parameters","enhancePrompt"],v)}(s,o),o}function ci(e,t){const n={},o=ce(e,["sdkHttpResponse"]);null!=o&&ue(n,["sdkHttpResponse"],o);const i=ce(e,["predictions"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["_self"]);null!=n&&ue(t,["image"],function(e){const t={},n=ce(e,["bytesBase64Encoded"]);null!=n&&ue(t,["imageBytes"],yt(n));const o=ce(e,["mimeType"]);null!=o&&ue(t,["mimeType"],o);return t}(n));const o=ce(e,["raiFilteredReason"]);null!=o&&ue(t,["raiFilteredReason"],o);const i=ce(e,["_self"]);null!=i&&ue(t,["safetyAttributes"],Oi(i));return t}(e))),ue(n,["generatedImages"],e)}const r=ce(e,["positivePromptSafetyAttributes"]);return null!=r&&ue(n,["positivePromptSafetyAttributes"],Oi(r)),n}function pi(e,t,n){const o=ce(e,["numberOfVideos"]);if(void 0!==t&&null!=o&&ue(t,["parameters","sampleCount"],o),void 0!==ce(e,["outputGcsUri"]))throw new Error("outputGcsUri parameter is not supported in Gemini API.");if(void 0!==ce(e,["fps"]))throw new Error("fps parameter is not supported in Gemini API.");const i=ce(e,["durationSeconds"]);if(void 0!==t&&null!=i&&ue(t,["parameters","durationSeconds"],i),void 0!==ce(e,["seed"]))throw new Error("seed parameter is not supported in Gemini API.");const r=ce(e,["aspectRatio"]);void 0!==t&&null!=r&&ue(t,["parameters","aspectRatio"],r);const s=ce(e,["resolution"]);void 0!==t&&null!=s&&ue(t,["parameters","resolution"],s);const l=ce(e,["personGeneration"]);if(void 0!==t&&null!=l&&ue(t,["parameters","personGeneration"],l),void 0!==ce(e,["pubsubTopic"]))throw new Error("pubsubTopic parameter is not supported in Gemini API.");const a=ce(e,["negativePrompt"]);void 0!==t&&null!=a&&ue(t,["parameters","negativePrompt"],a);const u=ce(e,["enhancePrompt"]);if(void 0!==t&&null!=u&&ue(t,["parameters","enhancePrompt"],u),void 0!==ce(e,["generateAudio"]))throw new Error("generateAudio parameter is not supported in Gemini API.");const c=ce(e,["lastFrame"]);void 0!==t&&null!=c&&ue(t,["instances[0]","lastFrame"],Ei(c));const p=ce(e,["referenceImages"]);if(void 0!==t&&null!=p){let e=p;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["image"]);null!=n&&ue(t,["image"],Ei(n));const o=ce(e,["referenceType"]);null!=o&&ue(t,["referenceType"],o);return t}(e))),ue(t,["instances[0]","referenceImages"],e)}if(void 0!==ce(e,["mask"]))throw new Error("mask parameter is not supported in Gemini API.");if(void 0!==ce(e,["compressionQuality"]))throw new Error("compressionQuality parameter is not supported in Gemini API.");return{}}function di(e,t,n){const o=ce(e,["numberOfVideos"]);void 0!==t&&null!=o&&ue(t,["parameters","sampleCount"],o);const i=ce(e,["outputGcsUri"]);void 0!==t&&null!=i&&ue(t,["parameters","storageUri"],i);const r=ce(e,["fps"]);void 0!==t&&null!=r&&ue(t,["parameters","fps"],r);const s=ce(e,["durationSeconds"]);void 0!==t&&null!=s&&ue(t,["parameters","durationSeconds"],s);const l=ce(e,["seed"]);void 0!==t&&null!=l&&ue(t,["parameters","seed"],l);const a=ce(e,["aspectRatio"]);void 0!==t&&null!=a&&ue(t,["parameters","aspectRatio"],a);const u=ce(e,["resolution"]);void 0!==t&&null!=u&&ue(t,["parameters","resolution"],u);const c=ce(e,["personGeneration"]);void 0!==t&&null!=c&&ue(t,["parameters","personGeneration"],c);const p=ce(e,["pubsubTopic"]);void 0!==t&&null!=p&&ue(t,["parameters","pubsubTopic"],p);const d=ce(e,["negativePrompt"]);void 0!==t&&null!=d&&ue(t,["parameters","negativePrompt"],d);const h=ce(e,["enhancePrompt"]);void 0!==t&&null!=h&&ue(t,["parameters","enhancePrompt"],h);const f=ce(e,["generateAudio"]);void 0!==t&&null!=f&&ue(t,["parameters","generateAudio"],f);const m=ce(e,["lastFrame"]);void 0!==t&&null!=m&&ue(t,["instances[0]","lastFrame"],Ti(m));const g=ce(e,["referenceImages"]);if(void 0!==t&&null!=g){let e=g;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["image"]);null!=n&&ue(t,["image"],Ti(n));const o=ce(e,["referenceType"]);null!=o&&ue(t,["referenceType"],o);return t}(e))),ue(t,["instances[0]","referenceImages"],e)}const y=ce(e,["mask"]);void 0!==t&&null!=y&&ue(t,["instances[0]","mask"],function(e){const t={},n=ce(e,["image"]);null!=n&&ue(t,["_self"],Ti(n));const o=ce(e,["maskMode"]);null!=o&&ue(t,["maskMode"],o);return t}(y));const v=ce(e,["compressionQuality"]);return void 0!==t&&null!=v&&ue(t,["parameters","compressionQuality"],v),{}}function hi(e,t){const n={},o=ce(e,["name"]);null!=o&&ue(n,["name"],o);const i=ce(e,["metadata"]);null!=i&&ue(n,["metadata"],i);const r=ce(e,["done"]);null!=r&&ue(n,["done"],r);const s=ce(e,["error"]);null!=s&&ue(n,["error"],s);const l=ce(e,["response","generateVideoResponse"]);return null!=l&&ue(n,["response"],function(e){const t={},n=ce(e,["generatedSamples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["video"]);null!=n&&ue(t,["video"],function(e){const t={},n=ce(e,["uri"]);null!=n&&ue(t,["uri"],n);const o=ce(e,["encodedVideo"]);null!=o&&ue(t,["videoBytes"],yt(o));const i=ce(e,["encoding"]);null!=i&&ue(t,["mimeType"],i);return t}(n));return t}(e))),ue(t,["generatedVideos"],e)}const o=ce(e,["raiMediaFilteredCount"]);null!=o&&ue(t,["raiMediaFilteredCount"],o);const i=ce(e,["raiMediaFilteredReasons"]);null!=i&&ue(t,["raiMediaFilteredReasons"],i);return t}(l)),n}function fi(e,t){const n={},o=ce(e,["name"]);null!=o&&ue(n,["name"],o);const i=ce(e,["metadata"]);null!=i&&ue(n,["metadata"],i);const r=ce(e,["done"]);null!=r&&ue(n,["done"],r);const s=ce(e,["error"]);null!=s&&ue(n,["error"],s);const l=ce(e,["response"]);return null!=l&&ue(n,["response"],function(e){const t={},n=ce(e,["videos"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["_self"]);null!=n&&ue(t,["video"],function(e){const t={},n=ce(e,["gcsUri"]);null!=n&&ue(t,["uri"],n);const o=ce(e,["bytesBase64Encoded"]);null!=o&&ue(t,["videoBytes"],yt(o));const i=ce(e,["mimeType"]);null!=i&&ue(t,["mimeType"],i);return t}(n));return t}(e))),ue(t,["generatedVideos"],e)}const o=ce(e,["raiMediaFilteredCount"]);null!=o&&ue(t,["raiMediaFilteredCount"],o);const i=ce(e,["raiMediaFilteredReasons"]);null!=i&&ue(t,["raiMediaFilteredReasons"],i);return t}(l)),n}function mi(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["prompt"]);null!=r&&ue(o,["instances[0]","prompt"],r);const s=ce(t,["image"]);null!=s&&ue(o,["instances[0]","image"],Ei(s));const l=ce(t,["video"]);null!=l&&ue(o,["instances[0]","video"],Ui(l));const a=ce(t,["source"]);null!=a&&function(e,t){const n={},o=ce(e,["prompt"]);void 0!==t&&null!=o&&ue(t,["instances[0]","prompt"],o);const i=ce(e,["image"]);void 0!==t&&null!=i&&ue(t,["instances[0]","image"],Ei(i));const r=ce(e,["video"]);void 0!==t&&null!=r&&ue(t,["instances[0]","video"],Ui(r))}(a,o);const u=ce(t,["config"]);return null!=u&&pi(u,o),o}function gi(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["prompt"]);null!=r&&ue(o,["instances[0]","prompt"],r);const s=ce(t,["image"]);null!=s&&ue(o,["instances[0]","image"],Ti(s));const l=ce(t,["video"]);null!=l&&ue(o,["instances[0]","video"],xi(l));const a=ce(t,["source"]);null!=a&&function(e,t){const n={},o=ce(e,["prompt"]);void 0!==t&&null!=o&&ue(t,["instances[0]","prompt"],o);const i=ce(e,["image"]);void 0!==t&&null!=i&&ue(t,["instances[0]","image"],Ti(i));const r=ce(e,["video"]);void 0!==t&&null!=r&&ue(t,["instances[0]","video"],xi(r))}(a,o);const u=ce(t,["config"]);return null!=u&&di(u,o),o}function yi(e,t){const n={},o=ce(e,["_self"]);null!=o&&ue(n,["image"],vi(o));const i=ce(e,["raiFilteredReason"]);null!=i&&ue(n,["raiFilteredReason"],i);const r=ce(e,["_self"]);null!=r&&ue(n,["safetyAttributes"],bi(r));const s=ce(e,["prompt"]);return null!=s&&ue(n,["enhancedPrompt"],s),n}function vi(e,t){const n={},o=ce(e,["gcsUri"]);null!=o&&ue(n,["gcsUri"],o);const i=ce(e,["bytesBase64Encoded"]);null!=i&&ue(n,["imageBytes"],yt(i));const r=ce(e,["mimeType"]);return null!=r&&ue(n,["mimeType"],r),n}function Ei(e,t){const n={};if(void 0!==ce(e,["gcsUri"]))throw new Error("gcsUri parameter is not supported in Gemini API.");const o=ce(e,["imageBytes"]);null!=o&&ue(n,["bytesBase64Encoded"],yt(o));const i=ce(e,["mimeType"]);return null!=i&&ue(n,["mimeType"],i),n}function Ti(e,t){const n={},o=ce(e,["gcsUri"]);null!=o&&ue(n,["gcsUri"],o);const i=ce(e,["imageBytes"]);null!=i&&ue(n,["bytesBase64Encoded"],yt(i));const r=ce(e,["mimeType"]);return null!=r&&ue(n,["mimeType"],r),n}function Ii(e,t,n){const o={},i=ce(t,["config"]);return null!=i&&function(e,t,n){const o=ce(t,["pageSize"]);void 0!==n&&null!=o&&ue(n,["_query","pageSize"],o);const i=ce(t,["pageToken"]);void 0!==n&&null!=i&&ue(n,["_query","pageToken"],i);const r=ce(t,["filter"]);void 0!==n&&null!=r&&ue(n,["_query","filter"],r);const s=ce(t,["queryBase"]);void 0!==n&&null!=s&&ue(n,["_url","models_url"],Et(e,s))}(e,i,o),o}function _i(e,t,n){const o={},i=ce(t,["config"]);return null!=i&&function(e,t,n){const o=ce(t,["pageSize"]);void 0!==n&&null!=o&&ue(n,["_query","pageSize"],o);const i=ce(t,["pageToken"]);void 0!==n&&null!=i&&ue(n,["_query","pageToken"],i);const r=ce(t,["filter"]);void 0!==n&&null!=r&&ue(n,["_query","filter"],r);const s=ce(t,["queryBase"]);void 0!==n&&null!=s&&ue(n,["_url","models_url"],Et(e,s))}(e,i,o),o}function Si(e,t){const n={},o=ce(e,["name"]);null!=o&&ue(n,["name"],o);const i=ce(e,["displayName"]);null!=i&&ue(n,["displayName"],i);const r=ce(e,["description"]);null!=r&&ue(n,["description"],r);const s=ce(e,["version"]);null!=s&&ue(n,["version"],s);const l=ce(e,["_self"]);null!=l&&ue(n,["tunedModelInfo"],function(e){const t={},n=ce(e,["baseModel"]);null!=n&&ue(t,["baseModel"],n);const o=ce(e,["createTime"]);null!=o&&ue(t,["createTime"],o);const i=ce(e,["updateTime"]);null!=i&&ue(t,["updateTime"],i);return t}(l));const a=ce(e,["inputTokenLimit"]);null!=a&&ue(n,["inputTokenLimit"],a);const u=ce(e,["outputTokenLimit"]);null!=u&&ue(n,["outputTokenLimit"],u);const c=ce(e,["supportedGenerationMethods"]);null!=c&&ue(n,["supportedActions"],c);const p=ce(e,["temperature"]);null!=p&&ue(n,["temperature"],p);const d=ce(e,["maxTemperature"]);null!=d&&ue(n,["maxTemperature"],d);const h=ce(e,["topP"]);null!=h&&ue(n,["topP"],h);const f=ce(e,["topK"]);null!=f&&ue(n,["topK"],f);const m=ce(e,["thinking"]);return null!=m&&ue(n,["thinking"],m),n}function Ai(e,t){const n={},o=ce(e,["name"]);null!=o&&ue(n,["name"],o);const i=ce(e,["displayName"]);null!=i&&ue(n,["displayName"],i);const r=ce(e,["description"]);null!=r&&ue(n,["description"],r);const s=ce(e,["versionId"]);null!=s&&ue(n,["version"],s);const l=ce(e,["deployedModels"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["endpoint"]);null!=n&&ue(t,["name"],n);const o=ce(e,["deployedModelId"]);return null!=o&&ue(t,["deployedModelId"],o),t}(e))),ue(n,["endpoints"],e)}const a=ce(e,["labels"]);null!=a&&ue(n,["labels"],a);const u=ce(e,["_self"]);null!=u&&ue(n,["tunedModelInfo"],function(e){const t={},n=ce(e,["labels","google-vertex-llm-tuning-base-model-id"]);null!=n&&ue(t,["baseModel"],n);const o=ce(e,["createTime"]);null!=o&&ue(t,["createTime"],o);const i=ce(e,["updateTime"]);null!=i&&ue(t,["updateTime"],i);return t}(u));const c=ce(e,["defaultCheckpointId"]);null!=c&&ue(n,["defaultCheckpointId"],c);const p=ce(e,["checkpoints"]);if(null!=p){let e=p;Array.isArray(e)&&(e=e.map(e=>e)),ue(n,["checkpoints"],e)}return n}function Ci(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["source"]);null!=r&&function(e,t){const n={},o=ce(e,["prompt"]);void 0!==t&&null!=o&&ue(t,["instances[0]","prompt"],o);const i=ce(e,["personImage"]);void 0!==t&&null!=i&&ue(t,["instances[0]","personImage","image"],Ti(i));const r=ce(e,["productImages"]);if(void 0!==t&&null!=r){let e=r;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["productImage"]);return null!=n&&ue(t,["image"],Ti(n)),t}(e))),ue(t,["instances[0]","productImages"],e)}}(r,o);const s=ce(t,["config"]);return null!=s&&function(e,t){const n=ce(e,["numberOfImages"]);void 0!==t&&null!=n&&ue(t,["parameters","sampleCount"],n);const o=ce(e,["baseSteps"]);void 0!==t&&null!=o&&ue(t,["parameters","baseSteps"],o);const i=ce(e,["outputGcsUri"]);void 0!==t&&null!=i&&ue(t,["parameters","storageUri"],i);const r=ce(e,["seed"]);void 0!==t&&null!=r&&ue(t,["parameters","seed"],r);const s=ce(e,["safetyFilterLevel"]);void 0!==t&&null!=s&&ue(t,["parameters","safetySetting"],s);const l=ce(e,["personGeneration"]);void 0!==t&&null!=l&&ue(t,["parameters","personGeneration"],l);const a=ce(e,["addWatermark"]);void 0!==t&&null!=a&&ue(t,["parameters","addWatermark"],a);const u=ce(e,["outputMimeType"]);void 0!==t&&null!=u&&ue(t,["parameters","outputOptions","mimeType"],u);const c=ce(e,["outputCompressionQuality"]);void 0!==t&&null!=c&&ue(t,["parameters","outputOptions","compressionQuality"],c);const p=ce(e,["enhancePrompt"]);void 0!==t&&null!=p&&ue(t,["parameters","enhancePrompt"],p);const d=ce(e,["labels"]);void 0!==t&&null!=d&&ue(t,["labels"],d)}(s,o),o}function Oi(e,t){const n={},o=ce(e,["safetyAttributes","categories"]);null!=o&&ue(n,["categories"],o);const i=ce(e,["safetyAttributes","scores"]);null!=i&&ue(n,["scores"],i);const r=ce(e,["contentType"]);return null!=r&&ue(n,["contentType"],r),n}function bi(e,t){const n={},o=ce(e,["safetyAttributes","categories"]);null!=o&&ue(n,["categories"],o);const i=ce(e,["safetyAttributes","scores"]);null!=i&&ue(n,["scores"],i);const r=ce(e,["contentType"]);return null!=r&&ue(n,["contentType"],r),n}function Ri(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["source"]);null!=r&&function(e,t){const n={},o=ce(e,["prompt"]);void 0!==t&&null!=o&&ue(t,["instances[0]","prompt"],o);const i=ce(e,["image"]);void 0!==t&&null!=i&&ue(t,["instances[0]","image"],Ti(i));const r=ce(e,["scribbleImage"]);void 0!==t&&null!=r&&ue(t,["instances[0]","scribble"],function(e){const t={},n=ce(e,["image"]);return null!=n&&ue(t,["image"],Ti(n)),t}(r))}(r,o);const s=ce(t,["config"]);return null!=s&&function(e,t){const n=ce(e,["mode"]);void 0!==t&&null!=n&&ue(t,["parameters","mode"],n);const o=ce(e,["maxPredictions"]);void 0!==t&&null!=o&&ue(t,["parameters","maxPredictions"],o);const i=ce(e,["confidenceThreshold"]);void 0!==t&&null!=i&&ue(t,["parameters","confidenceThreshold"],i);const r=ce(e,["maskDilation"]);void 0!==t&&null!=r&&ue(t,["parameters","maskDilation"],r);const s=ce(e,["binaryColorThreshold"]);void 0!==t&&null!=s&&ue(t,["parameters","binaryColorThreshold"],s);const l=ce(e,["labels"]);void 0!==t&&null!=l&&ue(t,["labels"],l)}(s,o),o}function wi(e,t){const n={},o=ce(e,["predictions"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["_self"]);null!=n&&ue(t,["mask"],vi(n));const o=ce(e,["labels"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["labels"],e)}return t}(e))),ue(n,["generatedMasks"],e)}return n}function Ni(e,t){const n={},o=ce(e,["retrieval"]);null!=o&&ue(n,["retrieval"],o);const i=ce(e,["computerUse"]);if(null!=i&&ue(n,["computerUse"],i),void 0!==ce(e,["fileSearch"]))throw new Error("fileSearch parameter is not supported in Vertex AI.");const r=ce(e,["codeExecution"]);null!=r&&ue(n,["codeExecution"],r);const s=ce(e,["enterpriseWebSearch"]);null!=s&&ue(n,["enterpriseWebSearch"],s);const l=ce(e,["functionDeclarations"]);if(null!=l){let e=l;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["description"]);null!=n&&ue(t,["description"],n);const o=ce(e,["name"]);null!=o&&ue(t,["name"],o);const i=ce(e,["parameters"]);null!=i&&ue(t,["parameters"],i);const r=ce(e,["parametersJsonSchema"]);null!=r&&ue(t,["parametersJsonSchema"],r);const s=ce(e,["response"]);null!=s&&ue(t,["response"],s);const l=ce(e,["responseJsonSchema"]);if(null!=l&&ue(t,["responseJsonSchema"],l),void 0!==ce(e,["behavior"]))throw new Error("behavior parameter is not supported in Vertex AI.");return t}(e))),ue(n,["functionDeclarations"],e)}const a=ce(e,["googleMaps"]);null!=a&&ue(n,["googleMaps"],a);const u=ce(e,["googleSearch"]);null!=u&&ue(n,["googleSearch"],u);const c=ce(e,["googleSearchRetrieval"]);null!=c&&ue(n,["googleSearchRetrieval"],c);const p=ce(e,["urlContext"]);return null!=p&&ue(n,["urlContext"],p),n}function Pi(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","name"],We(e,i));const r=ce(t,["config"]);return null!=r&&function(e,t){const n=ce(e,["displayName"]);void 0!==t&&null!=n&&ue(t,["displayName"],n);const o=ce(e,["description"]);void 0!==t&&null!=o&&ue(t,["description"],o);const i=ce(e,["defaultCheckpointId"]);void 0!==t&&null!=i&&ue(t,["defaultCheckpointId"],i)}(r,o),o}function Mi(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["config"]);return null!=r&&function(e,t){const n=ce(e,["displayName"]);void 0!==t&&null!=n&&ue(t,["displayName"],n);const o=ce(e,["description"]);void 0!==t&&null!=o&&ue(t,["description"],o);const i=ce(e,["defaultCheckpointId"]);void 0!==t&&null!=i&&ue(t,["defaultCheckpointId"],i)}(r,o),o}function Di(e,t,n){const o={},i=ce(t,["model"]);null!=i&&ue(o,["_url","model"],We(e,i));const r=ce(t,["image"]);null!=r&&ue(o,["instances[0]","image"],Ti(r));const s=ce(t,["upscaleFactor"]);null!=s&&ue(o,["parameters","upscaleConfig","upscaleFactor"],s);const l=ce(t,["config"]);return null!=l&&function(e,t){const n=ce(e,["outputGcsUri"]);void 0!==t&&null!=n&&ue(t,["parameters","storageUri"],n);const o=ce(e,["safetyFilterLevel"]);void 0!==t&&null!=o&&ue(t,["parameters","safetySetting"],o);const i=ce(e,["personGeneration"]);void 0!==t&&null!=i&&ue(t,["parameters","personGeneration"],i);const r=ce(e,["includeRaiReason"]);void 0!==t&&null!=r&&ue(t,["parameters","includeRaiReason"],r);const s=ce(e,["outputMimeType"]);void 0!==t&&null!=s&&ue(t,["parameters","outputOptions","mimeType"],s);const l=ce(e,["outputCompressionQuality"]);void 0!==t&&null!=l&&ue(t,["parameters","outputOptions","compressionQuality"],l);const a=ce(e,["enhanceInputImage"]);void 0!==t&&null!=a&&ue(t,["parameters","upscaleConfig","enhanceInputImage"],a);const u=ce(e,["imagePreservationFactor"]);void 0!==t&&null!=u&&ue(t,["parameters","upscaleConfig","imagePreservationFactor"],u);const c=ce(e,["labels"]);void 0!==t&&null!=c&&ue(t,["labels"],c);const p=ce(e,["numberOfImages"]);void 0!==t&&null!=p&&ue(t,["parameters","sampleCount"],p);const d=ce(e,["mode"]);void 0!==t&&null!=d&&ue(t,["parameters","mode"],d)}(l,o),o}function Ui(e,t){const n={},o=ce(e,["uri"]);null!=o&&ue(n,["uri"],o);const i=ce(e,["videoBytes"]);null!=i&&ue(n,["encodedVideo"],yt(i));const r=ce(e,["mimeType"]);return null!=r&&ue(n,["encoding"],r),n}function xi(e,t){const n={},o=ce(e,["uri"]);null!=o&&ue(n,["gcsUri"],o);const i=ce(e,["videoBytes"]);null!=i&&ue(n,["bytesBase64Encoded"],yt(i));const r=ce(e,["mimeType"]);return null!=r&&ue(n,["mimeType"],r),n}
240
+ /**
241
+ * @license
242
+ * Copyright 2025 Google LLC
243
+ * SPDX-License-Identifier: Apache-2.0
244
+ */qo=Fo,Fo.GeminiNextGenAPIClient=qo,Fo.GeminiNextGenAPIClientError=Mn,Fo.APIError=Dn,Fo.APIConnectionError=xn,Fo.APIConnectionTimeoutError=Ln,Fo.APIUserAbortError=Un,Fo.NotFoundError=Fn,Fo.ConflictError=Hn,Fo.RateLimitError=Vn,Fo.BadRequestError=kn,Fo.AuthenticationError=qn,Fo.InternalServerError=Bn,Fo.PermissionDeniedError=Gn,Fo.UnprocessableEntityError=jn,Fo.toFile=async function(e,t,n){if(oo(),(e=>null!=e&&"object"==typeof e&&"string"==typeof e.name&&"number"==typeof e.lastModified&&ro(e))(e=await e))return e instanceof File?e:io([await e.arrayBuffer()],e.name);if((e=>null!=e&&"object"==typeof e&&"string"==typeof e.url&&"function"==typeof e.blob)(e)){const o=await e.blob();return t||(t=new URL(e.url).pathname.split(/[\\/]/).pop()),io(await so(o),t,n)}const o=await so(e);if(t||(t=function(e){return("object"==typeof e&&null!==e&&("name"in e&&e.name&&String(e.name)||"url"in e&&e.url&&String(e.url)||"filename"in e&&e.filename&&String(e.filename)||"path"in e&&e.path&&String(e.path))||"").split(/[\\/]/).pop()||void 0}(e)),!(null==n?void 0:n.type)){const e=o.find(e=>"object"==typeof e&&"type"in e&&e.type);"string"==typeof e&&(n=Object.assign(Object.assign({},n),{type:e}))}return io(o,t,n)},Fo.Interactions=fo;let Li=!1;function ki(e){for(const t of e){if(Gi(t))return!0;if("object"==typeof t&&"inputSchema"in t)return!0}return Li}function qi(e){var t;const n=null!==(t=e[dn])&&void 0!==t?t:"";e[dn]=(n+" mcp_used/unknown").trimStart()}function Gi(e){return null!==e&&"object"==typeof e&&e instanceof Hi}function Fi(e){return Xt(this,arguments,function*(e,t=100){let n,o=0;for(;o<t;){const t=yield zt(e.listTools({cursor:n}));for(const e of t.tools)yield yield zt(e),o++;if(!t.nextCursor)break;n=t.nextCursor}})}class Hi{constructor(e=[],t){this.mcpTools=[],this.functionNameToMcpClient={},this.mcpClients=e,this.config=t}static create(e,t){return new Hi(e,t)}async initialize(){var e,t,n,o;if(this.mcpTools.length>0)return;const i={},r=[];for(const u of this.mcpClients)try{for(var s,l=!0,a=(t=void 0,Qt(Fi(u)));!(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]=u}}catch(e){t={error:e}}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=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=_t(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}}class ji{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.");console.warn("Live music generation is experimental and may change in future versions.");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}
245
+ /**
246
+ * @license
247
+ * Copyright 2025 Google LLC
248
+ * SPDX-License-Identifier: Apache-2.0
249
+ */(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=>{!
250
+ /**
251
+ * @license
252
+ * Copyright 2025 Google LLC
253
+ * SPDX-License-Identifier: Apache-2.0
254
+ */
255
+ async function(e,t,n){const o=new Ye;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:We(this.apiClient,e.model)}};return p.send(JSON.stringify(d)),new Vi(p,this.apiClient)}}class Vi{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=ce(e,["weightedPrompts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ue(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=ce(e,["musicGenerationConfig"]);return null!=n&&ue(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(e.LiveMusicPlaybackControl.PLAY)}pause(){this.sendPlaybackControl(e.LiveMusicPlaybackControl.PAUSE)}stop(){this.sendPlaybackControl(e.LiveMusicPlaybackControl.STOP)}resetContext(){this.sendPlaybackControl(e.LiveMusicPlaybackControl.RESET_CONTEXT)}close(){this.conn.close()}}class Bi{constructor(e,t,n){this.apiClient=e,this.auth=t,this.webSocketFactory=n,this.music=new ji(this.apiClient,this.auth,this.webSocketFactory)}async connect(t){var n,o,i,r,s,l;if(t.config&&t.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 a=this.apiClient.getWebsocketBaseUrl(),u=this.apiClient.getApiVersion();let c;const p=this.apiClient.getHeaders();t.config&&t.config.tools&&ki(t.config.tools)&&qi(p);const d=function(e){const t=new Headers;for(const[n,o]of Object.entries(e))t.append(n,o);return t}
256
+ /**
257
+ * @license
258
+ * Copyright 2025 Google LLC
259
+ * SPDX-License-Identifier: Apache-2.0
260
+ */(p);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?c=a:(c=`${a}/ws/google.cloud.aiplatform.${u}.LlmBidiService/BidiGenerateContent`,await this.auth.addAuthHeaders(d,c))}else{const e=this.apiClient.getApiKey();let t="BidiGenerateContent",n="key";(null==e?void 0:e.startsWith("auth_tokens/"))&&(console.warn("Warning: Ephemeral token support is experimental and may change in future versions."),"v1alpha"!==u&&console.warn("Warning: The SDK's ephemeral token support is in v1alpha only. Please use const ai = new GoogleGenAI({apiKey: token.name, httpOptions: { apiVersion: 'v1alpha' }}); before session connection."),t="BidiGenerateContentConstrained",n="access_token"),c=`${a}/ws/google.ai.generativelanguage.${u}.GenerativeService.${t}?${n}=${e}`}let h=()=>{};const f=new Promise(e=>{h=e}),m=t.callbacks,g=this.apiClient,y={onopen:function(){var e;null===(e=null==m?void 0:m.onopen)||void 0===e||e.call(m),h({})},onmessage:e=>{!async function(e,t,n){const o=new $e;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=Yo(r);Object.assign(o,e)}else{const e=r;Object.assign(o,e)}t(o)}(g,m.onmessage,e)},onerror:null!==(n=null==m?void 0:m.onerror)&&void 0!==n?n:function(e){},onclose:null!==(o=null==m?void 0:m.onclose)&&void 0!==o?o:function(e){}},v=this.webSocketFactory.create(c,function(e){const t={};return e.forEach((e,n)=>{t[n]=e}),t}(d),y);v.connect(),await f;let E=We(this.apiClient,t.model);if(this.apiClient.isVertexAI()&&E.startsWith("publishers/")){const e=this.apiClient.getProject(),t=this.apiClient.getLocation();e&&t&&(E=`projects/${e}/locations/${t}/`+E)}let T={};this.apiClient.isVertexAI()&&void 0===(null===(i=t.config)||void 0===i?void 0:i.responseModalities)&&(void 0===t.config?t.config={responseModalities:[e.Modality.AUDIO]}:t.config.responseModalities=[e.Modality.AUDIO]),(null===(r=t.config)||void 0===r?void 0:r.generationConfig)&&console.warn("Setting `LiveConnectConfig.generation_config` is deprecated, please set the fields on `LiveConnectConfig` directly. This will become an error in a future version (not before Q3 2025).");const I=null!==(l=null===(s=t.config)||void 0===s?void 0:s.tools)&&void 0!==l?l:[],_=[];for(const e of I)if(this.isCallableTool(e)){const t=e;_.push(await t.tool())}else _.push(e);_.length>0&&(t.config.tools=_);const S={model:E,config:t.config,callbacks:t.callbacks};return T=this.apiClient.isVertexAI()?function(e,t){const n={},o=ce(t,["model"]);null!=o&&ue(n,["setup","model"],We(e,o));const i=ce(t,["config"]);return null!=i&&ue(n,["config"],Bo(i,n)),n}(this.apiClient,S):function(e,t){const n={},o=ce(t,["model"]);null!=o&&ue(n,["setup","model"],We(e,o));const i=ce(t,["config"]);return null!=i&&ue(n,["config"],Vo(i,n)),n}(this.apiClient,S),delete T.config,v.send(JSON.stringify(T)),new $i(v,this.apiClient)}isCallableTool(e){return"callTool"in e&&"function"==typeof e.callTool}}const Ji={turnComplete:!0};class $i{constructor(e,t){this.conn=e,this.apiClient=t}tLiveClientContent(e,t){if(null!==t.turns&&void 0!==t.turns){let n=[];try{n=at(t.turns),e.isVertexAI()||(n=n.map(e=>zo(e)))}catch(e){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 t of n){if("object"!=typeof t||null===t||!("name"in t)||!("response"in t))throw new Error(`Could not parse function response, type '${typeof t}'.`);if(!e.isVertexAI()&&!("id"in t))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({},Ji),e);const t=this.tLiveClientContent(this.apiClient,e);this.conn.send(JSON.stringify(t))}sendRealtimeInput(e){let t={};t=this.apiClient.isVertexAI()?{realtimeInput:$o(e)}:{realtimeInput:Jo(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 Yi(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 t of null!==(n=null==e?void 0:e.tools)&&void 0!==n?n:[])if(Ki(t)){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)&&(console.warn("Invalid maximumRemoteCalls value provided for automatic function calling. Disabled automatic function calling. Please provide a valid integer value greater than 0. maximumRemoteCalls provided:",r),!0)}function Ki(e){return"callTool"in e&&"function"==typeof e.callTool}function Wi(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(Ki(e))return;const o=e;o.functionDeclarations&&o.functionDeclarations.length>0&&n.push(t)}),n):n}function zi(e){var t;return!(null===(t=null==e?void 0:e.automaticFunctionCalling)||void 0===t?void 0:t.ignoreCallHistory)}
261
+ /**
262
+ * @license
263
+ * Copyright 2025 Google LLC
264
+ * SPDX-License-Identifier: Apache-2.0
265
+ */class Xi extends le{constructor(t){super(),this.apiClient=t,this.embedContent=async t=>{if(!this.apiClient.isVertexAI())return await this.embedContentInternal(t);if(t.model.includes("gemini")&&"gemini-embedding-001"!==t.model||t.model.includes("maas")){const n=at(t.contents);if(n.length>1)throw new Error("The embedContent API for this model only supports one content at a time.");const o=Object.assign(Object.assign({},t),{content:n[0],embeddingApiType:e.EmbeddingApiType.EMBED_CONTENT});return await this.embedContentInternal(o)}{const n=Object.assign(Object.assign({},t),{embeddingApiType:e.EmbeddingApiType.PREDICT});return await this.embedContentInternal(n)}},this.generateContent=async e=>{var t,n,o,i,r;const s=await this.processParamsMaybeAddMcpUsage(e);if(this.maybeMoveToResponseJsonSchem(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=>Ki(e)))&&void 0!==o&&o}(e)||Yi(e.config))return await this.generateContentInternal(s);const l=Wi(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=at(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 t of null!==(r=null===(i=e.config)||void 0===i?void 0:i.tools)&&void 0!==r?r:[])if(Ki(t)){const e=t,o=await e.callTool(a.functionCalls);n.push(...o)}d++,u={role:"user",parts:n},s.contents=at(s.contents),s.contents.push(t),s.contents.push(u),zi(s.config)&&(c.push(t),c.push(u))}return zi(s.config)&&(a.automaticFunctionCallingHistory=c),a},this.generateContentStream=async e=>{var t,n,o,i,r;if(this.maybeMoveToResponseJsonSchem(e),Yi(e.config)){const t=await this.processParamsMaybeAddMcpUsage(e);return await this.generateContentStreamInternal(t)}const s=Wi(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 e=>await this.generateImagesInternal(e).then(e=>{var t;let n;const o=[];if(null==e?void 0:e.generatedImages)for(const i of e.generatedImages)i&&(null==i?void 0:i.safetyAttributes)&&"Positive Prompt"===(null===(t=null==i?void 0:i.safetyAttributes)||void 0===t?void 0:t.contentType)?n=null==i?void 0:i.safetyAttributes:o.push(i);let i;return i=n?{generatedImages:o,positivePromptSafetyAttributes:n,sdkHttpResponse:e.sdkHttpResponse}:{generatedImages:o,sdkHttpResponse:e.sdkHttpResponse},i}),this.list=async t=>{var n;const o={config:Object.assign(Object.assign({},{queryBase:!0}),null==t?void 0:t.config)};if(this.apiClient.isVertexAI()&&!o.config.queryBase){if(null===(n=o.config)||void 0===n?void 0:n.filter)throw new Error("Filtering tuned models list for Vertex AI is not currently supported");o.config.filter="labels.tune-type:*"}return new qt(e.PagedItem.PAGED_ITEM_MODELS,e=>this.listInternal(e),await this.listInternal(o),o)},this.editImage=async e=>{const t={model:e.model,prompt:e.prompt,referenceImages:[],config:e.config};return e.referenceImages&&e.referenceImages&&(t.referenceImages=e.referenceImages.map(e=>e.toReferenceImageAPI())),await this.editImageInternal(t)},this.upscaleImage=async e=>{let t={numberOfImages:1,mode:"upscale"};e.config&&(t=Object.assign(Object.assign({},t),e.config));const n={model:e.model,image:e.image,upscaleFactor:e.upscaleFactor,config:t};return await this.upscaleImageInternal(n)},this.generateVideos=async e=>{var t,n,o,i,r,s;if((e.prompt||e.image||e.video)&&e.source)throw new Error("Source and prompt/image/video are mutually exclusive. Please only use source.");return this.apiClient.isVertexAI()||((null===(t=e.video)||void 0===t?void 0:t.uri)&&(null===(n=e.video)||void 0===n?void 0:n.videoBytes)?e.video={uri:e.video.uri,mimeType:e.video.mimeType}:(null===(i=null===(o=e.source)||void 0===o?void 0:o.video)||void 0===i?void 0:i.uri)&&(null===(s=null===(r=e.source)||void 0===r?void 0:r.video)||void 0===s?void 0:s.videoBytes)&&(e.source.video={uri:e.source.video.uri,mimeType:e.source.video.mimeType})),await this.generateVideosInternal(e)}}maybeMoveToResponseJsonSchem(e){e.config&&e.config.responseSchema&&(e.config.responseJsonSchema||Object.keys(e.config.responseSchema).includes("$schema")&&(e.config.responseJsonSchema=e.config.responseSchema,delete e.config.responseSchema))}async processParamsMaybeAddMcpUsage(e){var t,n,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=>{if(Ki(e)){const t=e;return await t.tool()}return 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&&ki(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()),qi(i),s.config.httpOptions=Object.assign(Object.assign({},e.config.httpOptions),{headers:i})}return s}async initAfcToolsMap(e){var t,n,o;const i=new Map;for(const r of null!==(n=null===(t=e.config)||void 0===t?void 0:t.tools)&&void 0!==n?n:[])if(Ki(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 Xt(this,arguments,function*(){for(var o,l,a,u,c,p;s<i;){r&&(s++,r=!1);const m=yield zt(e.processParamsMaybeAddMcpUsage(n)),g=yield zt(e.generateContentStreamInternal(m)),y=[],v=[];try{for(var d,h=!0,f=(l=void 0,Qt(g));!(o=(d=yield zt(f.next())).done);h=!0){u=d.value,h=!1;const e=u;if(yield yield zt(e),e.candidates&&(null===(c=e.candidates[0])||void 0===c?void 0:c.content)){v.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()}, mising tool: ${n.functionCall.name}`);{const e=yield zt(t.get(n.functionCall.name).callTool([n.functionCall]));y.push(...e)}}}}}catch(e){l={error:e}}finally{try{h||o||!(a=f.return)||(yield zt(a.call(f)))}finally{if(l)throw l.error}}if(!(y.length>0))break;{r=!0;const e=new Ie;e.candidates=[{content:{role:"user",parts:y}}],yield yield zt(e);const t=[];t.push(...v),t.push({role:"user",parts:y});const o=at(n.contents).concat(t);n.contents=o}}})}(this,await this.initAfcToolsMap(e),e)}async generateContentInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=ri(this.apiClient,e);return s=ae("{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=li(e),n=new Ie;return Object.assign(n,t),n})}{const t=ii(this.apiClient,e);return s=ae("{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=si(e),n=new Ie;return Object.assign(n,t),n})}}async generateContentStreamInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=ri(this.apiClient,e);s=ae("{model}:streamGenerateContent?alt=sse",o._url),l=o._query,delete o._url,delete o._query;return 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 Xt(this,arguments,function*(){var t,n,o,i;try{for(var r,s=!0,l=Qt(e);!(t=(r=yield zt(l.next())).done);s=!0){i=r.value,s=!1;const e=i,t=li(yield zt(e.json()));t.sdkHttpResponse={headers:e.headers};const n=new Ie;Object.assign(n,t),yield yield zt(n)}}catch(e){n={error:e}}finally{try{s||t||!(o=l.return)||(yield zt(o.call(l)))}finally{if(n)throw n.error}}})})}{const t=ii(this.apiClient,e);s=ae("{model}:streamGenerateContent?alt=sse",t._url),l=t._query,delete t._url,delete t._query;return 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 Xt(this,arguments,function*(){var t,n,o,i;try{for(var r,s=!0,l=Qt(e);!(t=(r=yield zt(l.next())).done);s=!0){i=r.value,s=!1;const e=i,t=si(yield zt(e.json()));t.sdkHttpResponse={headers:e.headers};const n=new Ie;Object.assign(n,t),yield yield zt(n)}}catch(e){n={error:e}}finally{try{s||t||!(o=l.return)||(yield zt(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=ti(this.apiClient,e,e);return s=ae((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=ce(e,["sdkHttpResponse"]);null!=o&&ue(n,["sdkHttpResponse"],o);const i=ce(e,["predictions[]","embeddings"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>Wo(e))),ue(n,["embeddings"],e)}const r=ce(e,["metadata"]);if(null!=r&&ue(n,["metadata"],r),t&&"EMBED_CONTENT"===ce(t,["embeddingApiType"])){const t=ce(e,["embedding"]),o=ce(e,["usageMetadata"]),i=ce(e,["truncated"]);if(t){const e={};o&&o.promptTokenCount&&(e.tokenCount=o.promptTokenCount),i&&(e.truncated=i),t.statistics=e,ue(n,["embeddings"],[t])}}return n}(t,e),o=new _e;return Object.assign(o,n),o})}{const t=ei(this.apiClient,e);return s=ae("{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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["embeddings"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["embeddings"],e)}const i=ce(e,["metadata"]);return null!=i&&ue(t,["metadata"],i),t}(e),n=new _e;return Object.assign(n,t),n})}var a}async generateImagesInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=ui(this.apiClient,e);return s=ae("{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(e=>{const t=function(e){const t={},n=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["predictions"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>yi(e))),ue(t,["generatedImages"],e)}const i=ce(e,["positivePromptSafetyAttributes"]);return null!=i&&ue(t,["positivePromptSafetyAttributes"],bi(i)),t}(e),n=new Se;return Object.assign(n,t),n})}{const t=ai(this.apiClient,e);return s=ae("{model}:predict",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=ci(e),n=new Se;return Object.assign(n,t),n})}}async editImageInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=Zo(this.apiClient,e);return i=ae("{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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["predictions"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>yi(e))),ue(t,["generatedImages"],e)}return t}(e),n=new Ae;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Vertex AI.")}async upscaleImageInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=Di(this.apiClient,e);return i=ae("{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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["predictions"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>yi(e))),ue(t,["generatedImages"],e)}return t}(e),n=new Ce;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Vertex AI.")}async recontextImage(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=Ci(this.apiClient,e);return i=ae("{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=ce(e,["predictions"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>yi(e))),ue(t,["generatedImages"],e)}return t}(e),n=new Oe;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Vertex AI.")}async segmentImage(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=Ri(this.apiClient,e);return i=ae("{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=wi(e),n=new be;return Object.assign(n,t),n})}throw new Error("This method is only supported by the 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=ce(t,["model"]);return null!=o&&ue(n,["_url","name"],We(e,o)),n}(this.apiClient,e);return s=ae("{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=>Ai(e))}{const t=function(e,t){const n={},o=ce(t,["model"]);return null!=o&&ue(n,["_url","name"],We(e,o)),n}(this.apiClient,e);return s=ae("{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=>Si(e))}}async listInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=_i(this.apiClient,e);return s=ae("{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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["nextPageToken"]);null!=o&&ue(t,["nextPageToken"],o);const i=ce(e,["_self"]);if(null!=i){let e=Tt(i);Array.isArray(e)&&(e=e.map(e=>Ai(e))),ue(t,["models"],e)}return t}(e),n=new Re;return Object.assign(n,t),n})}{const t=Ii(this.apiClient,e);return s=ae("{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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["nextPageToken"]);null!=o&&ue(t,["nextPageToken"],o);const i=ce(e,["_self"]);if(null!=i){let e=Tt(i);Array.isArray(e)&&(e=e.map(e=>Si(e))),ue(t,["models"],e)}return t}(e),n=new Re;return Object.assign(n,t),n})}}async update(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=Mi(this.apiClient,e);return s=ae("{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=>Ai(e))}{const t=Pi(this.apiClient,e);return s=ae("{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=>Si(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=ce(t,["model"]);return null!=o&&ue(n,["_url","name"],We(e,o)),n}(this.apiClient,e);return s=ae("{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=ce(e,["sdkHttpResponse"]);return null!=n&&ue(t,["sdkHttpResponse"],n),t}(e),n=new we;return Object.assign(n,t),n})}{const t=function(e,t){const n={},o=ce(t,["model"]);return null!=o&&ue(n,["_url","name"],We(e,o)),n}(this.apiClient,e);return s=ae("{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=ce(e,["sdkHttpResponse"]);return null!=n&&ue(t,["sdkHttpResponse"],n),t}(e),n=new we;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=ce(t,["model"]);null!=o&&ue(n,["_url","model"],We(e,o));const i=ce(t,["contents"]);if(null!=i){let e=at(i);Array.isArray(e)&&(e=e.map(e=>e)),ue(n,["contents"],e)}const r=ce(t,["config"]);return null!=r&&Xo(r,n),n}(this.apiClient,e);return s=ae("{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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["totalTokens"]);return null!=o&&ue(t,["totalTokens"],o),t}(e),n=new Ne;return Object.assign(n,t),n})}{const t=Qo(this.apiClient,e);return s=ae("{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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["totalTokens"]);null!=o&&ue(t,["totalTokens"],o);const i=ce(e,["cachedContentTokenCount"]);return null!=i&&ue(t,["cachedContentTokenCount"],i),t}(e),n=new Ne;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=ce(t,["model"]);null!=o&&ue(n,["_url","model"],We(e,o));const i=ce(t,["contents"]);if(null!=i){let e=at(i);Array.isArray(e)&&(e=e.map(e=>e)),ue(n,["contents"],e)}return n}(this.apiClient,e);return i=ae("{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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["tokensInfo"]);if(null!=o){let e=o;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["tokensInfo"],e)}return t}(e),n=new Pe;return Object.assign(n,t),n})}throw new Error("This method is only supported by the Vertex AI.")}async generateVideosInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=gi(this.apiClient,e);return s=ae("{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=fi(e),n=new Me;return Object.assign(n,t),n})}{const t=mi(this.apiClient,e);return s=ae("{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=hi(e),n=new Me;return Object.assign(n,t),n})}}}
266
+ /**
267
+ * @license
268
+ * Copyright 2025 Google LLC
269
+ * SPDX-License-Identifier: Apache-2.0
270
+ */class Qi extends le{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=ce(e,["operationName"]);return null!=n&&ue(t,["_url","operationName"],n),t}(e);return s=ae("{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=ce(e,["operationName"]);return null!=n&&ue(t,["_url","operationName"],n),t}(e);return s=ae("{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=ce(e,["operationName"]);null!=n&&ue(t,["operationName"],n);const o=ce(e,["resourceName"]);return null!=o&&ue(t,["_url","resourceName"],o),t}(e);return i=ae("{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 Vertex AI.")}}
271
+ /**
272
+ * @license
273
+ * Copyright 2025 Google LLC
274
+ * SPDX-License-Identifier: Apache-2.0
275
+ */function Zi(e){const t={},n=ce(e,["parts"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>function(e){const t={},n=ce(e,["mediaResolution"]);null!=n&&ue(t,["mediaResolution"],n);const o=ce(e,["codeExecutionResult"]);null!=o&&ue(t,["codeExecutionResult"],o);const i=ce(e,["executableCode"]);null!=i&&ue(t,["executableCode"],i);const r=ce(e,["fileData"]);null!=r&&ue(t,["fileData"],function(e){const t={};if(void 0!==ce(e,["displayName"]))throw new Error("displayName parameter is not supported in Gemini API.");const n=ce(e,["fileUri"]);null!=n&&ue(t,["fileUri"],n);const o=ce(e,["mimeType"]);null!=o&&ue(t,["mimeType"],o);return t}(r));const s=ce(e,["functionCall"]);null!=s&&ue(t,["functionCall"],function(e){const t={},n=ce(e,["id"]);null!=n&&ue(t,["id"],n);const o=ce(e,["args"]);null!=o&&ue(t,["args"],o);const i=ce(e,["name"]);null!=i&&ue(t,["name"],i);if(void 0!==ce(e,["partialArgs"]))throw new Error("partialArgs parameter is not supported in Gemini API.");if(void 0!==ce(e,["willContinue"]))throw new Error("willContinue parameter is not supported in Gemini API.");return t}(s));const l=ce(e,["functionResponse"]);null!=l&&ue(t,["functionResponse"],l);const a=ce(e,["inlineData"]);null!=a&&ue(t,["inlineData"],function(e){const t={},n=ce(e,["data"]);if(null!=n&&ue(t,["data"],n),void 0!==ce(e,["displayName"]))throw new Error("displayName parameter is not supported in Gemini API.");const o=ce(e,["mimeType"]);return null!=o&&ue(t,["mimeType"],o),t}(a));const u=ce(e,["text"]);null!=u&&ue(t,["text"],u);const c=ce(e,["thought"]);null!=c&&ue(t,["thought"],c);const p=ce(e,["thoughtSignature"]);null!=p&&ue(t,["thoughtSignature"],p);const d=ce(e,["videoMetadata"]);null!=d&&ue(t,["videoMetadata"],d);return t}(e))),ue(t,["parts"],e)}const o=ce(e,["role"]);return null!=o&&ue(t,["role"],o),t}function er(e,t,n){const o=ce(t,["expireTime"]);void 0!==n&&null!=o&&ue(n,["expireTime"],o);const i=ce(t,["newSessionExpireTime"]);void 0!==n&&null!=i&&ue(n,["newSessionExpireTime"],i);const r=ce(t,["uses"]);void 0!==n&&null!=r&&ue(n,["uses"],r);const s=ce(t,["liveConnectConstraints"]);void 0!==n&&null!=s&&ue(n,["bidiGenerateContentSetup"],function(e,t){const n={},o=ce(t,["model"]);null!=o&&ue(n,["setup","model"],We(e,o));const i=ce(t,["config"]);null!=i&&ue(n,["config"],function(e,t){const n={},o=ce(e,["generationConfig"]);void 0!==t&&null!=o&&ue(t,["setup","generationConfig"],o);const i=ce(e,["responseModalities"]);void 0!==t&&null!=i&&ue(t,["setup","generationConfig","responseModalities"],i);const r=ce(e,["temperature"]);void 0!==t&&null!=r&&ue(t,["setup","generationConfig","temperature"],r);const s=ce(e,["topP"]);void 0!==t&&null!=s&&ue(t,["setup","generationConfig","topP"],s);const l=ce(e,["topK"]);void 0!==t&&null!=l&&ue(t,["setup","generationConfig","topK"],l);const a=ce(e,["maxOutputTokens"]);void 0!==t&&null!=a&&ue(t,["setup","generationConfig","maxOutputTokens"],a);const u=ce(e,["mediaResolution"]);void 0!==t&&null!=u&&ue(t,["setup","generationConfig","mediaResolution"],u);const c=ce(e,["seed"]);void 0!==t&&null!=c&&ue(t,["setup","generationConfig","seed"],c);const p=ce(e,["speechConfig"]);void 0!==t&&null!=p&&ue(t,["setup","generationConfig","speechConfig"],dt(p));const d=ce(e,["thinkingConfig"]);void 0!==t&&null!=d&&ue(t,["setup","generationConfig","thinkingConfig"],d);const h=ce(e,["enableAffectiveDialog"]);void 0!==t&&null!=h&&ue(t,["setup","generationConfig","enableAffectiveDialog"],h);const f=ce(e,["systemInstruction"]);void 0!==t&&null!=f&&ue(t,["setup","systemInstruction"],Zi(st(f)));const m=ce(e,["tools"]);if(void 0!==t&&null!=m){let e=ft(m);Array.isArray(e)&&(e=e.map(e=>function(e){const t={};if(void 0!==ce(e,["retrieval"]))throw new Error("retrieval parameter is not supported in Gemini API.");const n=ce(e,["computerUse"]);null!=n&&ue(t,["computerUse"],n);const o=ce(e,["fileSearch"]);null!=o&&ue(t,["fileSearch"],o);const i=ce(e,["codeExecution"]);null!=i&&ue(t,["codeExecution"],i);if(void 0!==ce(e,["enterpriseWebSearch"]))throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const r=ce(e,["functionDeclarations"]);if(null!=r){let e=r;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["functionDeclarations"],e)}const s=ce(e,["googleMaps"]);null!=s&&ue(t,["googleMaps"],function(e){const t={};if(void 0!==ce(e,["authConfig"]))throw new Error("authConfig parameter is not supported in Gemini API.");const n=ce(e,["enableWidget"]);null!=n&&ue(t,["enableWidget"],n);return t}(s));const l=ce(e,["googleSearch"]);null!=l&&ue(t,["googleSearch"],function(e){const t={};if(void 0!==ce(e,["excludeDomains"]))throw new Error("excludeDomains parameter is not supported in Gemini API.");if(void 0!==ce(e,["blockingConfidence"]))throw new Error("blockingConfidence parameter is not supported in Gemini API.");const n=ce(e,["timeRangeFilter"]);null!=n&&ue(t,["timeRangeFilter"],n);return t}(l));const a=ce(e,["googleSearchRetrieval"]);null!=a&&ue(t,["googleSearchRetrieval"],a);const u=ce(e,["urlContext"]);null!=u&&ue(t,["urlContext"],u);return t}
276
+ /**
277
+ * @license
278
+ * Copyright 2025 Google LLC
279
+ * SPDX-License-Identifier: Apache-2.0
280
+ */(ht(e)))),ue(t,["setup","tools"],e)}const g=ce(e,["sessionResumption"]);void 0!==t&&null!=g&&ue(t,["setup","sessionResumption"],function(e){const t={},n=ce(e,["handle"]);null!=n&&ue(t,["handle"],n);if(void 0!==ce(e,["transparent"]))throw new Error("transparent parameter is not supported in Gemini API.");return t}(g));const y=ce(e,["inputAudioTranscription"]);void 0!==t&&null!=y&&ue(t,["setup","inputAudioTranscription"],y);const v=ce(e,["outputAudioTranscription"]);void 0!==t&&null!=v&&ue(t,["setup","outputAudioTranscription"],v);const E=ce(e,["realtimeInputConfig"]);void 0!==t&&null!=E&&ue(t,["setup","realtimeInputConfig"],E);const T=ce(e,["contextWindowCompression"]);void 0!==t&&null!=T&&ue(t,["setup","contextWindowCompression"],T);const I=ce(e,["proactivity"]);void 0!==t&&null!=I&&ue(t,["setup","proactivity"],I);if(void 0!==ce(e,["explicitVadSignal"]))throw new Error("explicitVadSignal parameter is not supported in Gemini API.");return n}(i,n));return n}(e,s));const l=ce(t,["lockAdditionalFields"]);return void 0!==n&&null!=l&&ue(n,["fieldMask"],l),{}}function tr(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}class nr extends le{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=ce(t,["config"]);return null!=o&&ue(n,["config"],er(e,o,n)),n}(this.apiClient,e);i=ae("auth_tokens",s._url),r=s._query,delete s.config,delete s._url,delete s._query;const l=tr(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)}}}
281
+ /**
282
+ * @license
283
+ * Copyright 2025 Google LLC
284
+ * SPDX-License-Identifier: Apache-2.0
285
+ */function or(e,t){const n={},o=ce(e,["baseModel"]);null!=o&&ue(n,["baseModel"],o);const i=ce(e,["preTunedModel"]);null!=i&&ue(n,["preTunedModel"],i);const r=ce(e,["trainingDataset"]);null!=r&&function(e){const t={};if(void 0!==ce(e,["gcsUri"]))throw new Error("gcsUri parameter is not supported in Gemini API.");if(void 0!==ce(e,["vertexDatasetResource"]))throw new Error("vertexDatasetResource parameter is not supported in Gemini API.");const n=ce(e,["examples"]);if(null!=n){let e=n;Array.isArray(e)&&(e=e.map(e=>e)),ue(t,["examples","examples"],e)}}(r);const s=ce(e,["config"]);return null!=s&&function(e,t){const n={};if(void 0!==ce(e,["validationDataset"]))throw new Error("validationDataset parameter is not supported in Gemini API.");const o=ce(e,["tunedModelDisplayName"]);if(void 0!==t&&null!=o&&ue(t,["displayName"],o),void 0!==ce(e,["description"]))throw new Error("description parameter is not supported in Gemini API.");const i=ce(e,["epochCount"]);void 0!==t&&null!=i&&ue(t,["tuningTask","hyperparameters","epochCount"],i);const r=ce(e,["learningRateMultiplier"]);if(null!=r&&ue(n,["tuningTask","hyperparameters","learningRateMultiplier"],r),void 0!==ce(e,["exportLastCheckpointOnly"]))throw new Error("exportLastCheckpointOnly parameter is not supported in Gemini API.");if(void 0!==ce(e,["preTunedModelCheckpointId"]))throw new Error("preTunedModelCheckpointId parameter is not supported in Gemini API.");if(void 0!==ce(e,["adapterSize"]))throw new Error("adapterSize parameter is not supported in Gemini API.");if(void 0!==ce(e,["tuningMode"]))throw new Error("tuningMode parameter is not supported in Gemini API.");if(void 0!==ce(e,["customBaseModel"]))throw new Error("customBaseModel parameter is not supported in Gemini API.");const s=ce(e,["batchSize"]);void 0!==t&&null!=s&&ue(t,["tuningTask","hyperparameters","batchSize"],s);const l=ce(e,["learningRate"]);if(void 0!==t&&null!=l&&ue(t,["tuningTask","hyperparameters","learningRate"],l),void 0!==ce(e,["labels"]))throw new Error("labels parameter is not supported in Gemini API.");if(void 0!==ce(e,["beta"]))throw new Error("beta parameter is not supported in Gemini API.");if(void 0!==ce(e,["baseTeacherModel"]))throw new Error("baseTeacherModel parameter is not supported in Gemini API.");if(void 0!==ce(e,["tunedTeacherModelSource"]))throw new Error("tunedTeacherModelSource parameter is not supported in Gemini API.");if(void 0!==ce(e,["sftLossWeightMultiplier"]))throw new Error("sftLossWeightMultiplier parameter is not supported in Gemini API.");if(void 0!==ce(e,["outputUri"]))throw new Error("outputUri parameter is not supported in Gemini API.");if(void 0!==ce(e,["encryptionSpec"]))throw new Error("encryptionSpec parameter is not supported in Gemini API.")}(s,n),n}function ir(e,t){const n={},o=ce(e,["baseModel"]);null!=o&&ue(n,["baseModel"],o);const i=ce(e,["preTunedModel"]);null!=i&&ue(n,["preTunedModel"],i);const r=ce(e,["trainingDataset"]);null!=r&&function(e,t,n){const o={};let i=ce(n,["config","method"]);void 0===i&&(i="SUPERVISED_FINE_TUNING");if("SUPERVISED_FINE_TUNING"===i){const n=ce(e,["gcsUri"]);void 0!==t&&null!=n&&ue(t,["supervisedTuningSpec","trainingDatasetUri"],n)}else if("PREFERENCE_TUNING"===i){const n=ce(e,["gcsUri"]);void 0!==t&&null!=n&&ue(t,["preferenceOptimizationSpec","trainingDatasetUri"],n)}else if("DISTILLATION"===i){const n=ce(e,["gcsUri"]);void 0!==t&&null!=n&&ue(t,["distillationSpec","promptDatasetUri"],n)}let r=ce(n,["config","method"]);void 0===r&&(r="SUPERVISED_FINE_TUNING");if("SUPERVISED_FINE_TUNING"===r){const n=ce(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&ue(t,["supervisedTuningSpec","trainingDatasetUri"],n)}else if("PREFERENCE_TUNING"===r){const n=ce(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&ue(t,["preferenceOptimizationSpec","trainingDatasetUri"],n)}else if("DISTILLATION"===r){const n=ce(e,["vertexDatasetResource"]);void 0!==t&&null!=n&&ue(t,["distillationSpec","promptDatasetUri"],n)}if(void 0!==ce(e,["examples"]))throw new Error("examples parameter is not supported in Vertex AI.")}(r,n,t);const s=ce(e,["config"]);return null!=s&&function(e,t,n){let o=ce(n,["config","method"]);if(void 0===o&&(o="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===o){const n=ce(e,["validationDataset"]);void 0!==t&&null!=n&&ue(t,["supervisedTuningSpec"],ur(n))}else if("PREFERENCE_TUNING"===o){const n=ce(e,["validationDataset"]);void 0!==t&&null!=n&&ue(t,["preferenceOptimizationSpec"],ur(n))}else if("DISTILLATION"===o){const n=ce(e,["validationDataset"]);void 0!==t&&null!=n&&ue(t,["distillationSpec"],ur(n))}const i=ce(e,["tunedModelDisplayName"]);void 0!==t&&null!=i&&ue(t,["tunedModelDisplayName"],i);const r=ce(e,["description"]);void 0!==t&&null!=r&&ue(t,["description"],r);let s=ce(n,["config","method"]);if(void 0===s&&(s="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===s){const n=ce(e,["epochCount"]);void 0!==t&&null!=n&&ue(t,["supervisedTuningSpec","hyperParameters","epochCount"],n)}else if("PREFERENCE_TUNING"===s){const n=ce(e,["epochCount"]);void 0!==t&&null!=n&&ue(t,["preferenceOptimizationSpec","hyperParameters","epochCount"],n)}else if("DISTILLATION"===s){const n=ce(e,["epochCount"]);void 0!==t&&null!=n&&ue(t,["distillationSpec","hyperParameters","epochCount"],n)}let l=ce(n,["config","method"]);if(void 0===l&&(l="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===l){const n=ce(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&ue(t,["supervisedTuningSpec","hyperParameters","learningRateMultiplier"],n)}else if("PREFERENCE_TUNING"===l){const n=ce(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&ue(t,["preferenceOptimizationSpec","hyperParameters","learningRateMultiplier"],n)}else if("DISTILLATION"===l){const n=ce(e,["learningRateMultiplier"]);void 0!==t&&null!=n&&ue(t,["distillationSpec","hyperParameters","learningRateMultiplier"],n)}let a=ce(n,["config","method"]);if(void 0===a&&(a="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===a){const n=ce(e,["exportLastCheckpointOnly"]);void 0!==t&&null!=n&&ue(t,["supervisedTuningSpec","exportLastCheckpointOnly"],n)}else if("PREFERENCE_TUNING"===a){const n=ce(e,["exportLastCheckpointOnly"]);void 0!==t&&null!=n&&ue(t,["preferenceOptimizationSpec","exportLastCheckpointOnly"],n)}else if("DISTILLATION"===a){const n=ce(e,["exportLastCheckpointOnly"]);void 0!==t&&null!=n&&ue(t,["distillationSpec","exportLastCheckpointOnly"],n)}let u=ce(n,["config","method"]);if(void 0===u&&(u="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===u){const n=ce(e,["adapterSize"]);void 0!==t&&null!=n&&ue(t,["supervisedTuningSpec","hyperParameters","adapterSize"],n)}else if("PREFERENCE_TUNING"===u){const n=ce(e,["adapterSize"]);void 0!==t&&null!=n&&ue(t,["preferenceOptimizationSpec","hyperParameters","adapterSize"],n)}else if("DISTILLATION"===u){const n=ce(e,["adapterSize"]);void 0!==t&&null!=n&&ue(t,["distillationSpec","hyperParameters","adapterSize"],n)}let c=ce(n,["config","method"]);if(void 0===c&&(c="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===c){const n=ce(e,["tuningMode"]);void 0!==t&&null!=n&&ue(t,["supervisedTuningSpec","tuningMode"],n)}const p=ce(e,["customBaseModel"]);void 0!==t&&null!=p&&ue(t,["customBaseModel"],p);let d=ce(n,["config","method"]);if(void 0===d&&(d="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===d){const n=ce(e,["batchSize"]);void 0!==t&&null!=n&&ue(t,["supervisedTuningSpec","hyperParameters","batchSize"],n)}let h=ce(n,["config","method"]);if(void 0===h&&(h="SUPERVISED_FINE_TUNING"),"SUPERVISED_FINE_TUNING"===h){const n=ce(e,["learningRate"]);void 0!==t&&null!=n&&ue(t,["supervisedTuningSpec","hyperParameters","learningRate"],n)}const f=ce(e,["labels"]);void 0!==t&&null!=f&&ue(t,["labels"],f);const m=ce(e,["beta"]);void 0!==t&&null!=m&&ue(t,["preferenceOptimizationSpec","hyperParameters","beta"],m);const g=ce(e,["baseTeacherModel"]);void 0!==t&&null!=g&&ue(t,["distillationSpec","baseTeacherModel"],g);const y=ce(e,["tunedTeacherModelSource"]);void 0!==t&&null!=y&&ue(t,["distillationSpec","tunedTeacherModelSource"],y);const v=ce(e,["sftLossWeightMultiplier"]);void 0!==t&&null!=v&&ue(t,["distillationSpec","hyperParameters","sftLossWeightMultiplier"],v);const E=ce(e,["outputUri"]);void 0!==t&&null!=E&&ue(t,["outputUri"],E);const T=ce(e,["encryptionSpec"]);void 0!==t&&null!=T&&ue(t,["encryptionSpec"],T)}(s,n,t),n}function rr(e,t){const n={},o=ce(e,["config"]);return null!=o&&function(e,t){const n=ce(e,["pageSize"]);void 0!==t&&null!=n&&ue(t,["_query","pageSize"],n);const o=ce(e,["pageToken"]);void 0!==t&&null!=o&&ue(t,["_query","pageToken"],o);const i=ce(e,["filter"]);void 0!==t&&null!=i&&ue(t,["_query","filter"],i)}(o,n),n}function sr(e,t){const n={},o=ce(e,["config"]);return null!=o&&function(e,t){const n=ce(e,["pageSize"]);void 0!==t&&null!=n&&ue(t,["_query","pageSize"],n);const o=ce(e,["pageToken"]);void 0!==t&&null!=o&&ue(t,["_query","pageToken"],o);const i=ce(e,["filter"]);void 0!==t&&null!=i&&ue(t,["_query","filter"],i)}(o,n),n}function lr(e,t){const n={},o=ce(e,["sdkHttpResponse"]);null!=o&&ue(n,["sdkHttpResponse"],o);const i=ce(e,["name"]);null!=i&&ue(n,["name"],i);const r=ce(e,["state"]);null!=r&&ue(n,["state"],gt(r));const s=ce(e,["createTime"]);null!=s&&ue(n,["createTime"],s);const l=ce(e,["tuningTask","startTime"]);null!=l&&ue(n,["startTime"],l);const a=ce(e,["tuningTask","completeTime"]);null!=a&&ue(n,["endTime"],a);const u=ce(e,["updateTime"]);null!=u&&ue(n,["updateTime"],u);const c=ce(e,["description"]);null!=c&&ue(n,["description"],c);const p=ce(e,["baseModel"]);null!=p&&ue(n,["baseModel"],p);const d=ce(e,["_self"]);return null!=d&&ue(n,["tunedModel"],function(e){const t={},n=ce(e,["name"]);null!=n&&ue(t,["model"],n);const o=ce(e,["name"]);return null!=o&&ue(t,["endpoint"],o),t}(d)),n}function ar(e,t){const n={},o=ce(e,["sdkHttpResponse"]);null!=o&&ue(n,["sdkHttpResponse"],o);const i=ce(e,["name"]);null!=i&&ue(n,["name"],i);const r=ce(e,["state"]);null!=r&&ue(n,["state"],gt(r));const s=ce(e,["createTime"]);null!=s&&ue(n,["createTime"],s);const l=ce(e,["startTime"]);null!=l&&ue(n,["startTime"],l);const a=ce(e,["endTime"]);null!=a&&ue(n,["endTime"],a);const u=ce(e,["updateTime"]);null!=u&&ue(n,["updateTime"],u);const c=ce(e,["error"]);null!=c&&ue(n,["error"],c);const p=ce(e,["description"]);null!=p&&ue(n,["description"],p);const d=ce(e,["baseModel"]);null!=d&&ue(n,["baseModel"],d);const h=ce(e,["tunedModel"]);null!=h&&ue(n,["tunedModel"],h);const f=ce(e,["preTunedModel"]);null!=f&&ue(n,["preTunedModel"],f);const m=ce(e,["supervisedTuningSpec"]);null!=m&&ue(n,["supervisedTuningSpec"],m);const g=ce(e,["preferenceOptimizationSpec"]);null!=g&&ue(n,["preferenceOptimizationSpec"],g);const y=ce(e,["distillationSpec"]);null!=y&&ue(n,["distillationSpec"],y);const v=ce(e,["tuningDataStats"]);null!=v&&ue(n,["tuningDataStats"],v);const E=ce(e,["encryptionSpec"]);null!=E&&ue(n,["encryptionSpec"],E);const T=ce(e,["partnerModelTuningSpec"]);null!=T&&ue(n,["partnerModelTuningSpec"],T);const I=ce(e,["customBaseModel"]);null!=I&&ue(n,["customBaseModel"],I);const _=ce(e,["experiment"]);null!=_&&ue(n,["experiment"],_);const S=ce(e,["labels"]);null!=S&&ue(n,["labels"],S);const A=ce(e,["outputUri"]);null!=A&&ue(n,["outputUri"],A);const C=ce(e,["pipelineJob"]);null!=C&&ue(n,["pipelineJob"],C);const O=ce(e,["serviceAccount"]);null!=O&&ue(n,["serviceAccount"],O);const b=ce(e,["tunedModelDisplayName"]);null!=b&&ue(n,["tunedModelDisplayName"],b);const R=ce(e,["veoTuningSpec"]);return null!=R&&ue(n,["veoTuningSpec"],R),n}function ur(e,t){const n={},o=ce(e,["gcsUri"]);null!=o&&ue(n,["validationDatasetUri"],o);const i=ce(e,["vertexDatasetResource"]);return null!=i&&ue(n,["validationDatasetUri"],i),n}
286
+ /**
287
+ * @license
288
+ * Copyright 2025 Google LLC
289
+ * SPDX-License-Identifier: Apache-2.0
290
+ */class cr extends le{constructor(t){super(),this.apiClient=t,this.list=async(t={})=>new qt(e.PagedItem.PAGED_ITEM_TUNING_JOBS,e=>this.listInternal(e),await this.listInternal(t),t),this.get=async e=>await this.getInternal(e),this.tune=async t=>{var n;if(this.apiClient.isVertexAI()){if(t.baseModel.startsWith("projects/")){const e={tunedModelName:t.baseModel};(null===(n=t.config)||void 0===n?void 0:n.preTunedModelCheckpointId)&&(e.checkpointId=t.config.preTunedModelCheckpointId);const o=Object.assign(Object.assign({},t),{preTunedModel:e});return o.baseModel=void 0,await this.tuneInternal(o)}{const e=Object.assign({},t);return await this.tuneInternal(e)}}{const n=Object.assign({},t),o=await this.tuneMldevInternal(n);let i="";void 0!==o.metadata&&void 0!==o.metadata.tunedModel?i=o.metadata.tunedModel:void 0!==o.name&&o.name.includes("/operations/")&&(i=o.name.split("/operations/")[0]);return{name:i,state:e.JobState.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=ce(e,["name"]);return null!=n&&ue(t,["_url","name"],n),t}(e);return s=ae("{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=>ar(e))}{const t=function(e){const t={},n=ce(e,["name"]);return null!=n&&ue(t,["_url","name"],n),t}(e);return s=ae("{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=>lr(e))}}async listInternal(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=sr(e);return s=ae("tuningJobs",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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["nextPageToken"]);null!=o&&ue(t,["nextPageToken"],o);const i=ce(e,["tuningJobs"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>ar(e))),ue(t,["tuningJobs"],e)}return t}(e),n=new De;return Object.assign(n,t),n})}{const t=rr(e);return s=ae("tunedModels",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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["nextPageToken"]);null!=o&&ue(t,["nextPageToken"],o);const i=ce(e,["tunedModels"]);if(null!=i){let e=i;Array.isArray(e)&&(e=e.map(e=>lr(e))),ue(t,["tuningJobs"],e)}return t}(e),n=new De;return Object.assign(n,t),n})}}async cancel(e){var t,n,o,i;let r,s="",l={};if(this.apiClient.isVertexAI()){const o=function(e){const t={},n=ce(e,["name"]);return null!=n&&ue(t,["_url","name"],n),t}(e);return s=ae("{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=ce(e,["sdkHttpResponse"]);return null!=n&&ue(t,["sdkHttpResponse"],n),t}(e),n=new Ue;return Object.assign(n,t),n})}{const t=function(e){const t={},n=ce(e,["name"]);return null!=n&&ue(t,["_url","name"],n),t}(e);return s=ae("{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=ce(e,["sdkHttpResponse"]);return null!=n&&ue(t,["sdkHttpResponse"],n),t}(e),n=new Ue;return Object.assign(n,t),n})}}async tuneInternal(e){var t,n;let o,i="",r={};if(this.apiClient.isVertexAI()){const s=ir(e,e);return i=ae("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=>ar(e))}throw new Error("This method is only supported by the 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=or(e);return i=ae("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=ce(e,["sdkHttpResponse"]);null!=n&&ue(t,["sdkHttpResponse"],n);const o=ce(e,["name"]);null!=o&&ue(t,["name"],o);const i=ce(e,["metadata"]);null!=i&&ue(t,["metadata"],i);const r=ce(e,["done"]);null!=r&&ue(t,["done"],r);const s=ce(e,["error"]);return null!=s&&ue(t,["error"],s),t}(e))}}}
291
+ /**
292
+ * @license
293
+ * Copyright 2025 Google LLC
294
+ * SPDX-License-Identifier: Apache-2.0
295
+ */const pr="x-goog-api-key";class dr{constructor(e){this.apiKey=e}async addAuthHeaders(e,t){if(null===e.get(pr)){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(pr,this.apiKey)}}}
296
+ /**
297
+ * @license
298
+ * Copyright 2025 Google LLC
299
+ * SPDX-License-Identifier: Apache-2.0
300
+ */e.ApiError=pn,e.Batches=Gt,e.Caches=Yt,e.CancelTuningJobResponse=Ue,e.Chat=on,e.Chats=nn,e.ComputeTokensResponse=Pe,e.ContentReferenceImage=class{toReferenceImageAPI(){return{referenceType:"REFERENCE_TYPE_CONTENT",referenceImage:this.referenceImage,referenceId:this.referenceId}}},e.ControlReferenceImage=class{toReferenceImageAPI(){return{referenceType:"REFERENCE_TYPE_CONTROL",referenceImage:this.referenceImage,referenceId:this.referenceId,controlImageConfig:this.config}}},e.CountTokensResponse=Ne,e.CreateFileResponse=je,e.DeleteCachedContentResponse=xe,e.DeleteFileResponse=Ve,e.DeleteModelResponse=we,e.EditImageResponse=Ae,e.EmbedContentResponse=_e,e.Files=An,e.FunctionResponse=class{},e.FunctionResponseBlob=class{},e.FunctionResponseFileData=class{},e.FunctionResponsePart=class{},e.GenerateContentResponse=Ie,e.GenerateContentResponsePromptFeedback=class{},e.GenerateContentResponseUsageMetadata=class{},e.GenerateImagesResponse=Se,e.GenerateVideosOperation=Me,e.GenerateVideosResponse=class{},e.GoogleGenAI=class{get interactions(){var e;if(void 0!==this._interactions)return this._interactions;if(console.warn("GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions."),this.vertexai)throw new Error("This version of the GenAI SDK does not support Vertex AI API for interactions.");const t=this.httpOptions;(null==t?void 0:t.extraBody)&&console.warn("GoogleGenAI.interactions: Client level httpOptions.extraBody is not supported by the interactions client and will be ignored.");const n=new Fo({baseURL:this.apiClient.getBaseUrl(),apiKey:this.apiKey,apiVersion:this.apiClient.getApiVersion(),clientAdapter:this.apiClient,defaultHeaders:this.apiClient.getDefaultHeaders(),timeout:null==t?void 0:t.timeout,maxRetries:null===(e=null==t?void 0:t.retryOptions)||void 0===e?void 0:e.attempts});return this._interactions=n.interactions,this._interactions}constructor(e){var t;if(null==e.apiKey)throw new Error(`An API Key must be set when running in an unspecified environment.\n + ${gn().message}`);this.vertexai=null!==(t=e.vertexai)&&void 0!==t&&t,this.apiKey=e.apiKey,this.apiVersion=e.apiVersion,this.httpOptions=e.httpOptions;const n=new dr(this.apiKey);this.apiClient=new fn({auth:n,apiVersion:this.apiVersion,apiKey:this.apiKey,vertexai:this.vertexai,httpOptions:this.httpOptions,userAgentExtra:"gl-node/cross",uploader:new En,downloader:new yn}),this.models=new Xi(this.apiClient),this.live=new Bi(this.apiClient,n,new _n),this.chats=new nn(this.models,this.apiClient),this.batches=new Gt(this.apiClient),this.caches=new Yt(this.apiClient),this.files=new An(this.apiClient),this.operations=new Qi(this.apiClient),this.authTokens=new nr(this.apiClient),this.tunings=new cr(this.apiClient),this.fileSearchStores=new Rn(this.apiClient)}},e.HttpResponse=Te,e.ImportFileOperation=Fe,e.ImportFileResponse=class{},e.InlinedEmbedContentResponse=class{},e.InlinedResponse=class{},e.ListBatchJobsResponse=Je,e.ListCachedContentsResponse=Le,e.ListDocumentsResponse=ke,e.ListFileSearchStoresResponse=qe,e.ListFilesResponse=He,e.ListModelsResponse=Re,e.ListTuningJobsResponse=De,e.Live=Bi,e.LiveClientToolResponse=class{},e.LiveMusicServerMessage=Ye,e.LiveSendToolResponseParameters=class{constructor(){this.functionResponses=[]}},e.LiveServerMessage=$e,e.MaskReferenceImage=class{toReferenceImageAPI(){return{referenceType:"REFERENCE_TYPE_MASK",referenceImage:this.referenceImage,referenceId:this.referenceId,maskImageConfig:this.config}}},e.Models=Xi,e.Operations=Qi,e.Pager=qt,e.RawReferenceImage=class{toReferenceImageAPI(){return{referenceType:"REFERENCE_TYPE_RAW",referenceImage:this.referenceImage,referenceId:this.referenceId}}},e.RecontextImageResponse=Oe,e.RegisterFilesResponse=Be,e.ReplayResponse=class{},e.SegmentImageResponse=be,e.Session=$i,e.SingleEmbedContentResponse=class{},e.StyleReferenceImage=class{toReferenceImageAPI(){return{referenceType:"REFERENCE_TYPE_STYLE",referenceImage:this.referenceImage,referenceId:this.referenceId,styleImageConfig:this.config}}},e.SubjectReferenceImage=class{toReferenceImageAPI(){return{referenceType:"REFERENCE_TYPE_SUBJECT",referenceImage:this.referenceImage,referenceId:this.referenceId,subjectImageConfig:this.config}}},e.Tokens=nr,e.UploadToFileSearchStoreOperation=Ke,e.UploadToFileSearchStoreResponse=class{},e.UploadToFileSearchStoreResumableResponse=Ge,e.UpscaleImageResponse=Ce,e.createFunctionResponsePartFromBase64=function(e,t){return{inlineData:{data:e,mimeType:t}}},e.createFunctionResponsePartFromUri=function(e,t){return{fileData:{fileUri:e,mimeType:t}}},e.createModelContent=function(e){return{role:"model",parts:Ee(e)}},e.createPartFromBase64=function(e,t,n){return Object.assign({inlineData:{data:e,mimeType:t}},n&&{mediaResolution:{level:n}})},e.createPartFromCodeExecutionResult=function(e,t){return{codeExecutionResult:{outcome:e,output:t}}},e.createPartFromExecutableCode=function(e,t){return{executableCode:{code:e,language:t}}},e.createPartFromFunctionCall=function(e,t){return{functionCall:{name:e,args:t}}},e.createPartFromFunctionResponse=function(e,t,n,o=[]){return{functionResponse:Object.assign({id:e,name:t,response:n},o.length>0&&{parts:o})}},e.createPartFromText=ye,e.createPartFromUri=function(e,t,n){return Object.assign({fileData:{fileUri:e,mimeType:t}},n&&{mediaResolution:{level:n}})},e.createUserContent=function(e){return{role:"user",parts:Ee(e)}},e.mcpToTool=function(...e){if(Li=!0,0===e.length)throw new Error("No MCP clients provided");const t=e[e.length-1];return null!==(n=t)&&"object"==typeof n&&"listTools"in n&&"function"==typeof n.listTools?Hi.create(e,{}):Hi.create(e.slice(0,e.length-1),t);var n},e.setDefaultBaseUrls=function(e){e.geminiUrl,e.vertexUrl}}(y)),y}function A(){if(c)return u;return c=1,u={getExtractionPrompt:function(){return'\nTu es un moteur d\'extraction et de classification spécialisé dans les factures du secteur mécanique automobile.\n\nTa tâche est d’analyser le texte fourni.\n\nIMPORTANT :\n- Si le document n’est PAS clairement une facture, retourne STRICTEMENT : null\n- Sinon retourne UNIQUEMENT un JSON valide correspondant au schéma.\nLe JSON doit respecter STRICTEMENT cette structure :\n\n{\n "reference": string | null,\n "date": string | null,\n "supplier": string | null,\n "customer": string | null,\n "totalAmount": number | null,\n "currency": string | null,\n "address": string | null,\n "items": [\n {\n "description": string,\n "quantity": number | null,\n "unitPrice": number | null,\n "totalPrice": number | null,\n "category": string | null\n }\n ],\n "taxAmount": number | null,\n "language": string | null\n}\n\nCATEGORIES AUTORISÉES (liste fermée) :\n\n- carrosserie\n- depannage\n- entretien_preventif\n- reparation_curative\n- diagnostic_electronique\n- autre\n\nRÈGLES DE CLASSIFICATION :\n\nAnalyse la description de chaque article et classe-le dans UNE SEULE catégorie :\n\n- carrosserie → peinture, tôle, choc, pare-chocs, aile, redressage\n- depannage → remorquage, dépannage route, batterie à plat\n- entretien_preventif → vidange, filtres, révision, entretien périodique\n- reparation_curative → remplacement pièce, réparation moteur, frein, embrayage\n- diagnostic_electronique → valise, scanner OBD, diagnostic calculateur\n\nSi aucune catégorie ne correspond clairement → "autre".\n\nRÈGLES GÉNÉRALES :\n\n1. Retourne UNIQUEMENT :\n - soit null\n - soit un JSON valide.\n2. Aucun texte explicatif.\n3. Aucun markdown.\n4. Si une donnée est absente → null.\n5. Les montants doivent être des NOMBRES.\n6. Utilise "." comme séparateur décimal.\n7. Date format YYYY-MM-DD ou null.\n8. Devise normalisée (EUR, USD, MAD...).\n9. Ne déduis aucune information absente explicitement.\n10. Une seule catégorie par item.\n\nAnalyse maintenant le texte suivant :\n'},getTasksCreationPrompt:function(e,t){return`\n CONTEXTE: Creation de tâches dans une solution de fleet management system.\n Tu es le responsable de park en maintenance de flottes(automobiles, camions, vehicules). \n Les taches sont le moyen de communiquer entre les personnes impliquées dans la gestion de resolution de l'intervention.\n Tu reçois les signalement des chauffeurs sur l'état de leurs véhicules. \n\n À partir de l'intervention, génère un tableau JSON de tâches détaillées et structurées.\n Tu pourrais recevoir un audio ou une photo descriptive de l'intervention ou de la panne.\n Il faudra les analyser pour en extraire des informations utiles à la création des tâches.\n Genere uniquement des taches principales relatives à la resolution de l'intervention.'\n \n **Titre :** ${e}\n **Description :** ${t}\n Réponds UNIQUEMENT avec un tableau JSON valide (sans markdown, sans explication), en suivant exactement ce format :\n [\n {\n "title": "Titre de la tâche",\n "description": "Description détaillée",\n "category": "catégorie de la tache(exemple: mécanique, electric, pneumatique,..)"\n }\n ]`},cleanJsonResponse:function(e){return e.replace(/```json/g,"").replace(/```/g,"").trim()},getMimeType:function(e){return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp",mp3:"audio/mpeg",wav:"audio/wav"}[e.replace(".","").toLowerCase()]}}}var C=t(function(){if(g)return m;g=1;const{GoogleGenAI:t}=S(),{extractFromBase64:n}=function(){if(d)return p;d=1;const t=e,{getExtractionPrompt:n}=A();return p={extractFromBase64:async function(e,o,i){if(!i)return null;if(!e)throw new Error("InvoiceExtractor not initialized. Call init() first.");let r,s=i;const l=i.match(/^data:(.*);base64,(.*)$/);if(l)r=l[1],s=l[2];else{const e=Buffer.from(i,"base64"),n=await t(e);if(!n)throw new Error("Unable to detect file type");r=n.mime}const a=await e.models.generateContent({model:o,contents:[{role:"user",parts:[{inlineData:{mimeType:r,data:s}},{text:n()}]}]});if(!a?.text)return null;const u=a.text.replace(/```json|```/g,"").trim();return JSON.parse(u)}}}(),{generateTasks:o}=function(){if(f)return h;f=1;const{cleanJsonResponse:e,getMimeType:t,getTasksCreationPrompt:n}=A();return h={generateTasks:async function(o,i,r,s,l,a){if(!r||!s)throw new Error("Le titre et la description sont obligatoires.");if(!o)throw new Error("TasksGenerator not initialized. Call init() first.");const u=[];l&&u.push({inlineData:{mimeType:t(l.extension),data:Buffer.from(l.buffer).toString("base64")}}),a&&u.push({inlineData:{mimeType:t(a.extension),data:Buffer.from(a.buffer).toString("base64")}}),u.push({text:n(r,s)});const c=await o.models.generateContent({model:i,contents:[{role:"user",parts:u}],generationConfig:{maxOutputTokens:2048,temperature:.2}}),p=c.candidates?.[0]?.content?.parts?.[0]?.text?.trim();if(!p)throw new Error("Réponse vide du modèle.");const d=JSON.parse(e(p));if(!Array.isArray(d))throw new Error("La réponse n'est pas un tableau JSON.");return d}}}();return m=new class{#e;#t;init({apiKey:e,model:n}={}){const o=e??process.env.AI_API_KEY,i=n??process.env.AI_MODEL??"gemini-2.5-flash";if(!o)throw new Error("API key is required. Provide it via init() or AI_API_KEY env variable.");return this.#e=new t({apiKey:o}),this.#t=i,this}extract(e){if(!this.#e)throw new Error("AiModule not initialized. Call init() first.");return n(this.#e,this.#t,e)}generateTasks(e,t,n,i){if(!this.#e)throw new Error("AiModule not initialized. Call init() first.");return o(this.#e,this.#t,e,t,n,i)}}}());module.exports=C;