sliccy 1.23.3 → 1.24.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/node-server/index.js +6 -0
- package/dist/node-server/runtime-flags.d.ts +1 -0
- package/dist/node-server/runtime-flags.js +6 -0
- package/dist/ui/assets/{___vite-browser-external_commonjs-proxy-BZRJ6_X4.js → ___vite-browser-external_commonjs-proxy-BWNVNhfA.js} +1 -1
- package/dist/ui/assets/anthropic-DpIVtAz7.js +41 -0
- package/dist/ui/assets/azure-openai-responses-DM6ZhYp3.js +1 -0
- package/dist/ui/assets/{bsh-watchdog-BHj7Fs8o.js → bsh-watchdog-u_kfEll6.js} +1 -1
- package/dist/ui/assets/google-DxQyzZcF.js +1 -0
- package/dist/ui/assets/google-gemini-cli-D8wlpibe.js +2 -0
- package/dist/ui/assets/google-shared-DdOR1KIz.js +250 -0
- package/dist/ui/assets/google-vertex-EcFAaDcq.js +1 -0
- package/dist/ui/assets/{index-BbFB6aZt.js → index-BX1RqpKx.js} +2 -2
- package/dist/ui/assets/{index-C7KXlIoI.js → index-BxsPIYVT.js} +1 -1
- package/dist/ui/assets/{index-C9qsgFXA.js → index-CWnZsBG7.js} +1 -1
- package/dist/ui/assets/index-Dw4MBGs3.js +14665 -0
- package/dist/ui/assets/{index-CmZETbUD.js → index-J5ks5yhg.js} +9 -9
- package/dist/ui/assets/{json-parse-BRxcI2Wj.js → json-parse-0sc64RJd.js} +1 -1
- package/dist/ui/assets/mistral-7wTQY92Z.js +12 -0
- package/dist/ui/assets/{offscreen-client-DdMA5sAC.js → offscreen-client-Ch5qQdZk.js} +1 -1
- package/dist/ui/assets/{openai-codex-responses-DXePmJ37.js → openai-codex-responses-BKiIVXQr.js} +1 -1
- package/dist/ui/assets/{openai-completions-BJ5tXvNF.js → openai-completions-X6jnU-kX.js} +3 -3
- package/dist/ui/assets/openai-responses-BH3tsCV7.js +1 -0
- package/dist/ui/assets/{openai-responses-shared-CCp4pUoS.js → openai-responses-shared-DCfz91fA.js} +1 -1
- package/dist/ui/assets/sanitize-unicode-cmozpu7l.js +1 -0
- package/dist/ui/assets/{sql-wasm-WyohJvyK.js → sql-wasm-bQNzDNj9.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/dist/ui/packages/webapp/index.html +1 -1
- package/package.json +1 -1
- package/dist/ui/assets/anthropic-CFRG0Hfe.js +0 -2
- package/dist/ui/assets/anthropic-h0YkYJvY.js +0 -2
- package/dist/ui/assets/azure-openai-responses-B72ahkq2.js +0 -1
- package/dist/ui/assets/azure-openai-responses-DiuVg7QC.js +0 -1
- package/dist/ui/assets/client-CLc9DbbF.js +0 -23
- package/dist/ui/assets/github-copilot-headers-Dz44zqGk.js +0 -1
- package/dist/ui/assets/google-CVSsY19W.js +0 -1
- package/dist/ui/assets/google-FJTEoy_e.js +0 -1
- package/dist/ui/assets/google-gemini-cli-T80C305w.js +0 -2
- package/dist/ui/assets/google-gemini-cli-gF7kFWc4.js +0 -2
- package/dist/ui/assets/google-shared-BjArPveV.js +0 -2
- package/dist/ui/assets/google-shared-CYYiav7i.js +0 -2
- package/dist/ui/assets/google-vertex-6VDNXf5n.js +0 -1
- package/dist/ui/assets/google-vertex-CjjOIg6q.js +0 -1
- package/dist/ui/assets/hash-k-C9KAKF.js +0 -1
- package/dist/ui/assets/index-BTBHJQVY.js +0 -131
- package/dist/ui/assets/index-CMitoXJI.js +0 -45
- package/dist/ui/assets/index-CYH9nDaE.js +0 -15023
- package/dist/ui/assets/index-Et7zk9Rb.js +0 -3
- package/dist/ui/assets/index-TCK0ykMx.js +0 -1
- package/dist/ui/assets/index-uz_REvSi.js +0 -5
- package/dist/ui/assets/json-parse-zqPLE5kv.js +0 -1
- package/dist/ui/assets/mistral-BnNh3LzR.js +0 -8
- package/dist/ui/assets/mistral-DBk4zmZV.js +0 -8
- package/dist/ui/assets/openai-codex-responses-BRTJp-Ny.js +0 -7
- package/dist/ui/assets/openai-completions-CFS00Zu3.js +0 -6
- package/dist/ui/assets/openai-responses-D0cbe-PZ.js +0 -1
- package/dist/ui/assets/openai-responses-GLrZ6X81.js +0 -1
- package/dist/ui/assets/openai-responses-shared-B_0Hvupy.js +0 -10
- package/dist/ui/assets/stream-lEC9OYG2.js +0 -1
- package/dist/ui/assets/transform-messages-BkE2P08Y.js +0 -1
- package/dist/ui/assets/transform-messages-DqxXnsXK.js +0 -1
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import{G as Ko,t as zo}from"./index-Dw4MBGs3.js";import{s as te}from"./sanitize-unicode-cmozpu7l.js";var de={exports:{}},Ge={},Ve,vt;function Xo(){if(vt)return Ve;vt=1;function t(e,n){typeof n=="boolean"&&(n={forever:n}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=n||{},this._maxRetryTime=n&&n.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 Ve=t,t.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},t.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},t.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var n=new Date().getTime();if(e&&n-this._operationStart>=this._maxRetryTime)return this._errors.push(e),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var o=this._timeouts.shift();if(o===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),o=this._cachedTimeouts.slice(-1);else return!1;var i=this;return this._timer=setTimeout(function(){i._attempts++,i._operationTimeoutCb&&(i._timeout=setTimeout(function(){i._operationTimeoutCb(i._attempts)},i._operationTimeout),i._options.unref&&i._timeout.unref()),i._fn(i._attempts)},o),this._options.unref&&this._timer.unref(),!0},t.prototype.attempt=function(e,n){this._fn=e,n&&(n.timeout&&(this._operationTimeout=n.timeout),n.cb&&(this._operationTimeoutCb=n.cb));var o=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){o._operationTimeoutCb()},o._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)},t.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)},t.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)},t.prototype.start=t.prototype.try,t.prototype.errors=function(){return this._errors},t.prototype.attempts=function(){return this._attempts},t.prototype.mainError=function(){if(this._errors.length===0)return null;for(var e={},n=null,o=0,i=0;i<this._errors.length;i++){var l=this._errors[i],a=l.message,u=(e[a]||0)+1;e[a]=u,u>=o&&(n=l,o=u)}return n},Ve}var Tt;function Qo(){return Tt||(Tt=1,(function(t){var e=Xo();t.operation=function(n){var o=t.timeouts(n);return new e(o,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},t.timeouts=function(n){if(n instanceof Array)return[].concat(n);var o={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var i in n)o[i]=n[i];if(o.minTimeout>o.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var l=[],a=0;a<o.retries;a++)l.push(this.createTimeout(a,o));return n&&n.forever&&!l.length&&l.push(this.createTimeout(a,o)),l.sort(function(u,d){return u-d}),l},t.createTimeout=function(n,o){var i=o.randomize?Math.random()+1:1,l=Math.round(i*Math.max(o.minTimeout,1)*Math.pow(o.factor,n));return l=Math.min(l,o.maxTimeout),l},t.wrap=function(n,o,i){if(o instanceof Array&&(i=o,o=null),!i){i=[];for(var l in n)typeof n[l]=="function"&&i.push(l)}for(var a=0;a<i.length;a++){var u=i[a],d=n[u];n[u]=function(f){var h=t.operation(o),p=Array.prototype.slice.call(arguments,1),m=p.pop();p.push(function(g){h.retry(g)||(g&&(arguments[0]=h.mainError()),m.apply(this,arguments))}),h.attempt(function(){f.apply(n,p)})}.bind(n,d),n[u].options=o}}})(Ge)),Ge}var He,_t;function Zo(){return _t||(_t=1,He=Qo()),He}var Et;function jo(){if(Et)return de.exports;Et=1;const t=Zo(),e=["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"];class n extends Error{constructor(u){super(),u instanceof Error?(this.originalError=u,{message:u}=u):(this.originalError=new Error(u),this.originalError.stack=this.stack),this.name="AbortError",this.message=u}}const o=(a,u,d)=>{const c=d.retries-(u-1);return a.attemptNumber=u,a.retriesLeft=c,a},i=a=>e.includes(a),l=(a,u)=>new Promise((d,c)=>{u={onFailedAttempt:()=>{},retries:10,...u};const f=t.operation(u);f.attempt(async h=>{try{d(await a(h))}catch(p){if(!(p instanceof Error)){c(new TypeError(`Non-error was thrown: "${p}". You should only throw errors.`));return}if(p instanceof n)f.stop(),c(p.originalError);else if(p instanceof TypeError&&!i(p.message))f.stop(),c(p);else{o(p,h,u);try{await u.onFailedAttempt(p)}catch(m){c(m);return}f.retry(p)||c(f.mainError())}}})});return de.exports=l,de.exports.default=l,de.exports.AbortError=n,de.exports}var eo=jo();const ei=Ko(eo);var ti={};/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/let ni,oi;function ii(){return{geminiUrl:ni,vertexUrl:oi}}function ri(t,e,n,o){var i,l;if(!t?.baseUrl){const a=ii();return e?(i=a.vertexUrl)!==null&&i!==void 0?i:n:(l=a.geminiUrl)!==null&&l!==void 0?l:o}return t.baseUrl}/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2025 Google LLC
|
|
8
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/class K{}function E(t,e){const n=/\{([^}]+)\}/g;return t.replace(n,(o,i)=>{if(Object.prototype.hasOwnProperty.call(e,i)){const l=e[i];return l!=null?String(l):""}else throw new Error(`Key '${i}' not found in valueMap.`)})}function s(t,e,n){for(let l=0;l<e.length-1;l++){const a=e[l];if(a.endsWith("[]")){const u=a.slice(0,-2);if(!(u in t))if(Array.isArray(n))t[u]=Array.from({length:n.length},()=>({}));else throw new Error(`Value must be a list given an array path ${a}`);if(Array.isArray(t[u])){const d=t[u];if(Array.isArray(n))for(let c=0;c<d.length;c++){const f=d[c];s(f,e.slice(l+1),n[c])}else for(const c of d)s(c,e.slice(l+1),n)}return}else if(a.endsWith("[0]")){const u=a.slice(0,-3);u in t||(t[u]=[{}]);const d=t[u];s(d[0],e.slice(l+1),n);return}(!t[a]||typeof t[a]!="object")&&(t[a]={}),t=t[a]}const o=e[e.length-1],i=t[o];if(i!==void 0){if(!n||typeof n=="object"&&Object.keys(n).length===0||n===i)return;if(typeof i=="object"&&typeof n=="object"&&i!==null&&n!==null)Object.assign(i,n);else throw new Error(`Cannot set value for an existing key. Key: ${o}`)}else o==="_self"&&typeof n=="object"&&n!==null&&!Array.isArray(n)?Object.assign(t,n):t[o]=n}function r(t,e,n=void 0){try{if(e.length===1&&e[0]==="_self")return t;for(let o=0;o<e.length;o++){if(typeof t!="object"||t===null)return n;const i=e[o];if(i.endsWith("[]")){const l=i.slice(0,-2);if(l in t){const a=t[l];return Array.isArray(a)?a.map(u=>r(u,e.slice(o+1),n)):n}else return n}else t=t[i]}return t}catch(o){if(o instanceof TypeError)return n;throw o}}function si(t,e){for(const[n,o]of Object.entries(e)){const i=n.split("."),l=o.split("."),a=new Set;let u=-1;for(let d=0;d<i.length;d++)if(i[d]==="*"){u=d;break}if(u!==-1&&l.length>u)for(let d=u;d<l.length;d++){const c=l[d];c!=="*"&&!c.endsWith("[]")&&!c.endsWith("[0]")&&a.add(c)}Oe(t,i,l,0,a)}}function Oe(t,e,n,o,i){if(o>=e.length||typeof t!="object"||t===null)return;const l=e[o];if(l.endsWith("[]")){const a=l.slice(0,-2),u=t;if(a in u&&Array.isArray(u[a]))for(const d of u[a])Oe(d,e,n,o+1,i)}else if(l==="*"){if(typeof t=="object"&&t!==null&&!Array.isArray(t)){const a=t,u=Object.keys(a).filter(c=>!c.startsWith("_")&&!i.has(c)),d={};for(const c of u)d[c]=a[c];for(const[c,f]of Object.entries(d)){const h=[];for(const p of n.slice(o))p==="*"?h.push(c):h.push(p);s(a,h,f)}for(const c of u)delete a[c]}}else{const a=t;l in a&&Oe(a[l],e,n,o+1,i)}}/**
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright 2025 Google LLC
|
|
12
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
13
|
+
*/function st(t){if(typeof t!="string")throw new Error("fromImageBytes must be a string");return t}/**
|
|
14
|
+
* @license
|
|
15
|
+
* Copyright 2025 Google LLC
|
|
16
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
*/function li(t){const e={},n=r(t,["operationName"]);n!=null&&s(e,["operationName"],n);const o=r(t,["resourceName"]);return o!=null&&s(e,["_url","resourceName"],o),e}function ai(t){const e={},n=r(t,["name"]);n!=null&&s(e,["name"],n);const o=r(t,["metadata"]);o!=null&&s(e,["metadata"],o);const i=r(t,["done"]);i!=null&&s(e,["done"],i);const l=r(t,["error"]);l!=null&&s(e,["error"],l);const a=r(t,["response","generateVideoResponse"]);return a!=null&&s(e,["response"],ci(a)),e}function ui(t){const e={},n=r(t,["name"]);n!=null&&s(e,["name"],n);const o=r(t,["metadata"]);o!=null&&s(e,["metadata"],o);const i=r(t,["done"]);i!=null&&s(e,["done"],i);const l=r(t,["error"]);l!=null&&s(e,["error"],l);const a=r(t,["response"]);return a!=null&&s(e,["response"],di(a)),e}function ci(t){const e={},n=r(t,["generatedSamples"]);if(n!=null){let l=n;Array.isArray(l)&&(l=l.map(a=>fi(a))),s(e,["generatedVideos"],l)}const o=r(t,["raiMediaFilteredCount"]);o!=null&&s(e,["raiMediaFilteredCount"],o);const i=r(t,["raiMediaFilteredReasons"]);return i!=null&&s(e,["raiMediaFilteredReasons"],i),e}function di(t){const e={},n=r(t,["videos"]);if(n!=null){let l=n;Array.isArray(l)&&(l=l.map(a=>pi(a))),s(e,["generatedVideos"],l)}const o=r(t,["raiMediaFilteredCount"]);o!=null&&s(e,["raiMediaFilteredCount"],o);const i=r(t,["raiMediaFilteredReasons"]);return i!=null&&s(e,["raiMediaFilteredReasons"],i),e}function fi(t){const e={},n=r(t,["video"]);return n!=null&&s(e,["video"],Ti(n)),e}function pi(t){const e={},n=r(t,["_self"]);return n!=null&&s(e,["video"],_i(n)),e}function hi(t){const e={},n=r(t,["operationName"]);return n!=null&&s(e,["_url","operationName"],n),e}function mi(t){const e={},n=r(t,["operationName"]);return n!=null&&s(e,["_url","operationName"],n),e}function gi(t){const e={},n=r(t,["name"]);n!=null&&s(e,["name"],n);const o=r(t,["metadata"]);o!=null&&s(e,["metadata"],o);const i=r(t,["done"]);i!=null&&s(e,["done"],i);const l=r(t,["error"]);l!=null&&s(e,["error"],l);const a=r(t,["response"]);return a!=null&&s(e,["response"],yi(a)),e}function yi(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["parent"]);o!=null&&s(e,["parent"],o);const i=r(t,["documentName"]);return i!=null&&s(e,["documentName"],i),e}function to(t){const e={},n=r(t,["name"]);n!=null&&s(e,["name"],n);const o=r(t,["metadata"]);o!=null&&s(e,["metadata"],o);const i=r(t,["done"]);i!=null&&s(e,["done"],i);const l=r(t,["error"]);l!=null&&s(e,["error"],l);const a=r(t,["response"]);return a!=null&&s(e,["response"],vi(a)),e}function vi(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["parent"]);o!=null&&s(e,["parent"],o);const i=r(t,["documentName"]);return i!=null&&s(e,["documentName"],i),e}function Ti(t){const e={},n=r(t,["uri"]);n!=null&&s(e,["uri"],n);const o=r(t,["encodedVideo"]);o!=null&&s(e,["videoBytes"],st(o));const i=r(t,["encoding"]);return i!=null&&s(e,["mimeType"],i),e}function _i(t){const e={},n=r(t,["gcsUri"]);n!=null&&s(e,["uri"],n);const o=r(t,["bytesBase64Encoded"]);o!=null&&s(e,["videoBytes"],st(o));const i=r(t,["mimeType"]);return i!=null&&s(e,["mimeType"],i),e}/**
|
|
18
|
+
* @license
|
|
19
|
+
* Copyright 2025 Google LLC
|
|
20
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
21
|
+
*/var Ct;(function(t){t.OUTCOME_UNSPECIFIED="OUTCOME_UNSPECIFIED",t.OUTCOME_OK="OUTCOME_OK",t.OUTCOME_FAILED="OUTCOME_FAILED",t.OUTCOME_DEADLINE_EXCEEDED="OUTCOME_DEADLINE_EXCEEDED"})(Ct||(Ct={}));var St;(function(t){t.LANGUAGE_UNSPECIFIED="LANGUAGE_UNSPECIFIED",t.PYTHON="PYTHON"})(St||(St={}));var It;(function(t){t.SCHEDULING_UNSPECIFIED="SCHEDULING_UNSPECIFIED",t.SILENT="SILENT",t.WHEN_IDLE="WHEN_IDLE",t.INTERRUPT="INTERRUPT"})(It||(It={}));var X;(function(t){t.TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",t.STRING="STRING",t.NUMBER="NUMBER",t.INTEGER="INTEGER",t.BOOLEAN="BOOLEAN",t.ARRAY="ARRAY",t.OBJECT="OBJECT",t.NULL="NULL"})(X||(X={}));var At;(function(t){t.PHISH_BLOCK_THRESHOLD_UNSPECIFIED="PHISH_BLOCK_THRESHOLD_UNSPECIFIED",t.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",t.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",t.BLOCK_HIGH_AND_ABOVE="BLOCK_HIGH_AND_ABOVE",t.BLOCK_HIGHER_AND_ABOVE="BLOCK_HIGHER_AND_ABOVE",t.BLOCK_VERY_HIGH_AND_ABOVE="BLOCK_VERY_HIGH_AND_ABOVE",t.BLOCK_ONLY_EXTREMELY_HIGH="BLOCK_ONLY_EXTREMELY_HIGH"})(At||(At={}));var Rt;(function(t){t.API_SPEC_UNSPECIFIED="API_SPEC_UNSPECIFIED",t.SIMPLE_SEARCH="SIMPLE_SEARCH",t.ELASTIC_SEARCH="ELASTIC_SEARCH"})(Rt||(Rt={}));var Pt;(function(t){t.AUTH_TYPE_UNSPECIFIED="AUTH_TYPE_UNSPECIFIED",t.NO_AUTH="NO_AUTH",t.API_KEY_AUTH="API_KEY_AUTH",t.HTTP_BASIC_AUTH="HTTP_BASIC_AUTH",t.GOOGLE_SERVICE_ACCOUNT_AUTH="GOOGLE_SERVICE_ACCOUNT_AUTH",t.OAUTH="OAUTH",t.OIDC_AUTH="OIDC_AUTH"})(Pt||(Pt={}));var Mt;(function(t){t.HTTP_IN_UNSPECIFIED="HTTP_IN_UNSPECIFIED",t.HTTP_IN_QUERY="HTTP_IN_QUERY",t.HTTP_IN_HEADER="HTTP_IN_HEADER",t.HTTP_IN_PATH="HTTP_IN_PATH",t.HTTP_IN_BODY="HTTP_IN_BODY",t.HTTP_IN_COOKIE="HTTP_IN_COOKIE"})(Mt||(Mt={}));var wt;(function(t){t.UNSPECIFIED="UNSPECIFIED",t.BLOCKING="BLOCKING",t.NON_BLOCKING="NON_BLOCKING"})(wt||(wt={}));var Nt;(function(t){t.MODE_UNSPECIFIED="MODE_UNSPECIFIED",t.MODE_DYNAMIC="MODE_DYNAMIC"})(Nt||(Nt={}));var oe;(function(t){t.MODE_UNSPECIFIED="MODE_UNSPECIFIED",t.AUTO="AUTO",t.ANY="ANY",t.NONE="NONE",t.VALIDATED="VALIDATED"})(oe||(oe={}));var Dt;(function(t){t.THINKING_LEVEL_UNSPECIFIED="THINKING_LEVEL_UNSPECIFIED",t.LOW="LOW",t.MEDIUM="MEDIUM",t.HIGH="HIGH",t.MINIMAL="MINIMAL"})(Dt||(Dt={}));var xt;(function(t){t.HARM_CATEGORY_UNSPECIFIED="HARM_CATEGORY_UNSPECIFIED",t.HARM_CATEGORY_HARASSMENT="HARM_CATEGORY_HARASSMENT",t.HARM_CATEGORY_HATE_SPEECH="HARM_CATEGORY_HATE_SPEECH",t.HARM_CATEGORY_SEXUALLY_EXPLICIT="HARM_CATEGORY_SEXUALLY_EXPLICIT",t.HARM_CATEGORY_DANGEROUS_CONTENT="HARM_CATEGORY_DANGEROUS_CONTENT",t.HARM_CATEGORY_CIVIC_INTEGRITY="HARM_CATEGORY_CIVIC_INTEGRITY",t.HARM_CATEGORY_IMAGE_HATE="HARM_CATEGORY_IMAGE_HATE",t.HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT="HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT",t.HARM_CATEGORY_IMAGE_HARASSMENT="HARM_CATEGORY_IMAGE_HARASSMENT",t.HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT="HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT",t.HARM_CATEGORY_JAILBREAK="HARM_CATEGORY_JAILBREAK"})(xt||(xt={}));var Ut;(function(t){t.HARM_BLOCK_METHOD_UNSPECIFIED="HARM_BLOCK_METHOD_UNSPECIFIED",t.SEVERITY="SEVERITY",t.PROBABILITY="PROBABILITY"})(Ut||(Ut={}));var Lt;(function(t){t.HARM_BLOCK_THRESHOLD_UNSPECIFIED="HARM_BLOCK_THRESHOLD_UNSPECIFIED",t.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",t.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",t.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",t.BLOCK_NONE="BLOCK_NONE",t.OFF="OFF"})(Lt||(Lt={}));var U;(function(t){t.FINISH_REASON_UNSPECIFIED="FINISH_REASON_UNSPECIFIED",t.STOP="STOP",t.MAX_TOKENS="MAX_TOKENS",t.SAFETY="SAFETY",t.RECITATION="RECITATION",t.LANGUAGE="LANGUAGE",t.OTHER="OTHER",t.BLOCKLIST="BLOCKLIST",t.PROHIBITED_CONTENT="PROHIBITED_CONTENT",t.SPII="SPII",t.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",t.IMAGE_SAFETY="IMAGE_SAFETY",t.UNEXPECTED_TOOL_CALL="UNEXPECTED_TOOL_CALL",t.IMAGE_PROHIBITED_CONTENT="IMAGE_PROHIBITED_CONTENT",t.NO_IMAGE="NO_IMAGE",t.IMAGE_RECITATION="IMAGE_RECITATION",t.IMAGE_OTHER="IMAGE_OTHER"})(U||(U={}));var kt;(function(t){t.HARM_PROBABILITY_UNSPECIFIED="HARM_PROBABILITY_UNSPECIFIED",t.NEGLIGIBLE="NEGLIGIBLE",t.LOW="LOW",t.MEDIUM="MEDIUM",t.HIGH="HIGH"})(kt||(kt={}));var Ft;(function(t){t.HARM_SEVERITY_UNSPECIFIED="HARM_SEVERITY_UNSPECIFIED",t.HARM_SEVERITY_NEGLIGIBLE="HARM_SEVERITY_NEGLIGIBLE",t.HARM_SEVERITY_LOW="HARM_SEVERITY_LOW",t.HARM_SEVERITY_MEDIUM="HARM_SEVERITY_MEDIUM",t.HARM_SEVERITY_HIGH="HARM_SEVERITY_HIGH"})(Ft||(Ft={}));var Gt;(function(t){t.URL_RETRIEVAL_STATUS_UNSPECIFIED="URL_RETRIEVAL_STATUS_UNSPECIFIED",t.URL_RETRIEVAL_STATUS_SUCCESS="URL_RETRIEVAL_STATUS_SUCCESS",t.URL_RETRIEVAL_STATUS_ERROR="URL_RETRIEVAL_STATUS_ERROR",t.URL_RETRIEVAL_STATUS_PAYWALL="URL_RETRIEVAL_STATUS_PAYWALL",t.URL_RETRIEVAL_STATUS_UNSAFE="URL_RETRIEVAL_STATUS_UNSAFE"})(Gt||(Gt={}));var Vt;(function(t){t.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"})(Vt||(Vt={}));var Ht;(function(t){t.TRAFFIC_TYPE_UNSPECIFIED="TRAFFIC_TYPE_UNSPECIFIED",t.ON_DEMAND="ON_DEMAND",t.PROVISIONED_THROUGHPUT="PROVISIONED_THROUGHPUT"})(Ht||(Ht={}));var Ie;(function(t){t.MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",t.TEXT="TEXT",t.IMAGE="IMAGE",t.AUDIO="AUDIO"})(Ie||(Ie={}));var qt;(function(t){t.MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",t.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",t.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",t.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH"})(qt||(qt={}));var bt;(function(t){t.TUNING_MODE_UNSPECIFIED="TUNING_MODE_UNSPECIFIED",t.TUNING_MODE_FULL="TUNING_MODE_FULL",t.TUNING_MODE_PEFT_ADAPTER="TUNING_MODE_PEFT_ADAPTER"})(bt||(bt={}));var Bt;(function(t){t.ADAPTER_SIZE_UNSPECIFIED="ADAPTER_SIZE_UNSPECIFIED",t.ADAPTER_SIZE_ONE="ADAPTER_SIZE_ONE",t.ADAPTER_SIZE_TWO="ADAPTER_SIZE_TWO",t.ADAPTER_SIZE_FOUR="ADAPTER_SIZE_FOUR",t.ADAPTER_SIZE_EIGHT="ADAPTER_SIZE_EIGHT",t.ADAPTER_SIZE_SIXTEEN="ADAPTER_SIZE_SIXTEEN",t.ADAPTER_SIZE_THIRTY_TWO="ADAPTER_SIZE_THIRTY_TWO"})(Bt||(Bt={}));var We;(function(t){t.JOB_STATE_UNSPECIFIED="JOB_STATE_UNSPECIFIED",t.JOB_STATE_QUEUED="JOB_STATE_QUEUED",t.JOB_STATE_PENDING="JOB_STATE_PENDING",t.JOB_STATE_RUNNING="JOB_STATE_RUNNING",t.JOB_STATE_SUCCEEDED="JOB_STATE_SUCCEEDED",t.JOB_STATE_FAILED="JOB_STATE_FAILED",t.JOB_STATE_CANCELLING="JOB_STATE_CANCELLING",t.JOB_STATE_CANCELLED="JOB_STATE_CANCELLED",t.JOB_STATE_PAUSED="JOB_STATE_PAUSED",t.JOB_STATE_EXPIRED="JOB_STATE_EXPIRED",t.JOB_STATE_UPDATING="JOB_STATE_UPDATING",t.JOB_STATE_PARTIALLY_SUCCEEDED="JOB_STATE_PARTIALLY_SUCCEEDED"})(We||(We={}));var Jt;(function(t){t.TUNING_TASK_UNSPECIFIED="TUNING_TASK_UNSPECIFIED",t.TUNING_TASK_I2V="TUNING_TASK_I2V",t.TUNING_TASK_T2V="TUNING_TASK_T2V",t.TUNING_TASK_R2V="TUNING_TASK_R2V"})(Jt||(Jt={}));var $t;(function(t){t.MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",t.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",t.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",t.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH",t.MEDIA_RESOLUTION_ULTRA_HIGH="MEDIA_RESOLUTION_ULTRA_HIGH"})($t||($t={}));var Ye;(function(t){t.COLLECTION="COLLECTION"})(Ye||(Ye={}));var Ot;(function(t){t.FEATURE_SELECTION_PREFERENCE_UNSPECIFIED="FEATURE_SELECTION_PREFERENCE_UNSPECIFIED",t.PRIORITIZE_QUALITY="PRIORITIZE_QUALITY",t.BALANCED="BALANCED",t.PRIORITIZE_COST="PRIORITIZE_COST"})(Ot||(Ot={}));var Wt;(function(t){t.ENVIRONMENT_UNSPECIFIED="ENVIRONMENT_UNSPECIFIED",t.ENVIRONMENT_BROWSER="ENVIRONMENT_BROWSER"})(Wt||(Wt={}));var Yt;(function(t){t.PROMINENT_PEOPLE_UNSPECIFIED="PROMINENT_PEOPLE_UNSPECIFIED",t.ALLOW_PROMINENT_PEOPLE="ALLOW_PROMINENT_PEOPLE",t.BLOCK_PROMINENT_PEOPLE="BLOCK_PROMINENT_PEOPLE"})(Yt||(Yt={}));var Ae;(function(t){t.PREDICT="PREDICT",t.EMBED_CONTENT="EMBED_CONTENT"})(Ae||(Ae={}));var Kt;(function(t){t.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",t.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",t.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",t.BLOCK_NONE="BLOCK_NONE"})(Kt||(Kt={}));var zt;(function(t){t.DONT_ALLOW="DONT_ALLOW",t.ALLOW_ADULT="ALLOW_ADULT",t.ALLOW_ALL="ALLOW_ALL"})(zt||(zt={}));var Xt;(function(t){t.auto="auto",t.en="en",t.ja="ja",t.ko="ko",t.hi="hi",t.zh="zh",t.pt="pt",t.es="es"})(Xt||(Xt={}));var Qt;(function(t){t.MASK_MODE_DEFAULT="MASK_MODE_DEFAULT",t.MASK_MODE_USER_PROVIDED="MASK_MODE_USER_PROVIDED",t.MASK_MODE_BACKGROUND="MASK_MODE_BACKGROUND",t.MASK_MODE_FOREGROUND="MASK_MODE_FOREGROUND",t.MASK_MODE_SEMANTIC="MASK_MODE_SEMANTIC"})(Qt||(Qt={}));var Zt;(function(t){t.CONTROL_TYPE_DEFAULT="CONTROL_TYPE_DEFAULT",t.CONTROL_TYPE_CANNY="CONTROL_TYPE_CANNY",t.CONTROL_TYPE_SCRIBBLE="CONTROL_TYPE_SCRIBBLE",t.CONTROL_TYPE_FACE_MESH="CONTROL_TYPE_FACE_MESH"})(Zt||(Zt={}));var jt;(function(t){t.SUBJECT_TYPE_DEFAULT="SUBJECT_TYPE_DEFAULT",t.SUBJECT_TYPE_PERSON="SUBJECT_TYPE_PERSON",t.SUBJECT_TYPE_ANIMAL="SUBJECT_TYPE_ANIMAL",t.SUBJECT_TYPE_PRODUCT="SUBJECT_TYPE_PRODUCT"})(jt||(jt={}));var en;(function(t){t.EDIT_MODE_DEFAULT="EDIT_MODE_DEFAULT",t.EDIT_MODE_INPAINT_REMOVAL="EDIT_MODE_INPAINT_REMOVAL",t.EDIT_MODE_INPAINT_INSERTION="EDIT_MODE_INPAINT_INSERTION",t.EDIT_MODE_OUTPAINT="EDIT_MODE_OUTPAINT",t.EDIT_MODE_CONTROLLED_EDITING="EDIT_MODE_CONTROLLED_EDITING",t.EDIT_MODE_STYLE="EDIT_MODE_STYLE",t.EDIT_MODE_BGSWAP="EDIT_MODE_BGSWAP",t.EDIT_MODE_PRODUCT_IMAGE="EDIT_MODE_PRODUCT_IMAGE"})(en||(en={}));var tn;(function(t){t.FOREGROUND="FOREGROUND",t.BACKGROUND="BACKGROUND",t.PROMPT="PROMPT",t.SEMANTIC="SEMANTIC",t.INTERACTIVE="INTERACTIVE"})(tn||(tn={}));var nn;(function(t){t.ASSET="ASSET",t.STYLE="STYLE"})(nn||(nn={}));var on;(function(t){t.INSERT="INSERT",t.REMOVE="REMOVE",t.REMOVE_STATIC="REMOVE_STATIC",t.OUTPAINT="OUTPAINT"})(on||(on={}));var rn;(function(t){t.OPTIMIZED="OPTIMIZED",t.LOSSLESS="LOSSLESS"})(rn||(rn={}));var sn;(function(t){t.SUPERVISED_FINE_TUNING="SUPERVISED_FINE_TUNING",t.PREFERENCE_TUNING="PREFERENCE_TUNING",t.DISTILLATION="DISTILLATION"})(sn||(sn={}));var ln;(function(t){t.STATE_UNSPECIFIED="STATE_UNSPECIFIED",t.STATE_PENDING="STATE_PENDING",t.STATE_ACTIVE="STATE_ACTIVE",t.STATE_FAILED="STATE_FAILED"})(ln||(ln={}));var an;(function(t){t.STATE_UNSPECIFIED="STATE_UNSPECIFIED",t.PROCESSING="PROCESSING",t.ACTIVE="ACTIVE",t.FAILED="FAILED"})(an||(an={}));var un;(function(t){t.SOURCE_UNSPECIFIED="SOURCE_UNSPECIFIED",t.UPLOADED="UPLOADED",t.GENERATED="GENERATED",t.REGISTERED="REGISTERED"})(un||(un={}));var cn;(function(t){t.TURN_COMPLETE_REASON_UNSPECIFIED="TURN_COMPLETE_REASON_UNSPECIFIED",t.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",t.RESPONSE_REJECTED="RESPONSE_REJECTED",t.NEED_MORE_INPUT="NEED_MORE_INPUT"})(cn||(cn={}));var dn;(function(t){t.MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",t.TEXT="TEXT",t.IMAGE="IMAGE",t.VIDEO="VIDEO",t.AUDIO="AUDIO",t.DOCUMENT="DOCUMENT"})(dn||(dn={}));var fn;(function(t){t.VAD_SIGNAL_TYPE_UNSPECIFIED="VAD_SIGNAL_TYPE_UNSPECIFIED",t.VAD_SIGNAL_TYPE_SOS="VAD_SIGNAL_TYPE_SOS",t.VAD_SIGNAL_TYPE_EOS="VAD_SIGNAL_TYPE_EOS"})(fn||(fn={}));var pn;(function(t){t.TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",t.ACTIVITY_START="ACTIVITY_START",t.ACTIVITY_END="ACTIVITY_END"})(pn||(pn={}));var hn;(function(t){t.START_SENSITIVITY_UNSPECIFIED="START_SENSITIVITY_UNSPECIFIED",t.START_SENSITIVITY_HIGH="START_SENSITIVITY_HIGH",t.START_SENSITIVITY_LOW="START_SENSITIVITY_LOW"})(hn||(hn={}));var mn;(function(t){t.END_SENSITIVITY_UNSPECIFIED="END_SENSITIVITY_UNSPECIFIED",t.END_SENSITIVITY_HIGH="END_SENSITIVITY_HIGH",t.END_SENSITIVITY_LOW="END_SENSITIVITY_LOW"})(mn||(mn={}));var gn;(function(t){t.ACTIVITY_HANDLING_UNSPECIFIED="ACTIVITY_HANDLING_UNSPECIFIED",t.START_OF_ACTIVITY_INTERRUPTS="START_OF_ACTIVITY_INTERRUPTS",t.NO_INTERRUPTION="NO_INTERRUPTION"})(gn||(gn={}));var yn;(function(t){t.TURN_COVERAGE_UNSPECIFIED="TURN_COVERAGE_UNSPECIFIED",t.TURN_INCLUDES_ONLY_ACTIVITY="TURN_INCLUDES_ONLY_ACTIVITY",t.TURN_INCLUDES_ALL_INPUT="TURN_INCLUDES_ALL_INPUT"})(yn||(yn={}));var vn;(function(t){t.SCALE_UNSPECIFIED="SCALE_UNSPECIFIED",t.C_MAJOR_A_MINOR="C_MAJOR_A_MINOR",t.D_FLAT_MAJOR_B_FLAT_MINOR="D_FLAT_MAJOR_B_FLAT_MINOR",t.D_MAJOR_B_MINOR="D_MAJOR_B_MINOR",t.E_FLAT_MAJOR_C_MINOR="E_FLAT_MAJOR_C_MINOR",t.E_MAJOR_D_FLAT_MINOR="E_MAJOR_D_FLAT_MINOR",t.F_MAJOR_D_MINOR="F_MAJOR_D_MINOR",t.G_FLAT_MAJOR_E_FLAT_MINOR="G_FLAT_MAJOR_E_FLAT_MINOR",t.G_MAJOR_E_MINOR="G_MAJOR_E_MINOR",t.A_FLAT_MAJOR_F_MINOR="A_FLAT_MAJOR_F_MINOR",t.A_MAJOR_G_FLAT_MINOR="A_MAJOR_G_FLAT_MINOR",t.B_FLAT_MAJOR_G_MINOR="B_FLAT_MAJOR_G_MINOR",t.B_MAJOR_A_FLAT_MINOR="B_MAJOR_A_FLAT_MINOR"})(vn||(vn={}));var Tn;(function(t){t.MUSIC_GENERATION_MODE_UNSPECIFIED="MUSIC_GENERATION_MODE_UNSPECIFIED",t.QUALITY="QUALITY",t.DIVERSITY="DIVERSITY",t.VOCALIZATION="VOCALIZATION"})(Tn||(Tn={}));var ie;(function(t){t.PLAYBACK_CONTROL_UNSPECIFIED="PLAYBACK_CONTROL_UNSPECIFIED",t.PLAY="PLAY",t.PAUSE="PAUSE",t.STOP="STOP",t.RESET_CONTEXT="RESET_CONTEXT"})(ie||(ie={}));class Ke{constructor(e){const n={};for(const o of e.headers.entries())n[o[0]]=o[1];this.headers=n,this.responseInternal=e}json(){return this.responseInternal.json()}}class fe{get text(){var e,n,o,i,l,a,u,d;if(((i=(o=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||o===void 0?void 0:o.parts)===null||i===void 0?void 0:i.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning text from the first one.");let c="",f=!1;const h=[];for(const p of(d=(u=(a=(l=this.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content)===null||u===void 0?void 0:u.parts)!==null&&d!==void 0?d:[]){for(const[m,g]of Object.entries(p))m!=="text"&&m!=="thought"&&m!=="thoughtSignature"&&(g!==null||g!==void 0)&&h.push(m);if(typeof p.text=="string"){if(typeof p.thought=="boolean"&&p.thought)continue;f=!0,c+=p.text}}return h.length>0&&console.warn(`there are non-text parts ${h} in the response, returning concatenation of all text parts. Please refer to the non text parts for a full response from model.`),f?c:void 0}get data(){var e,n,o,i,l,a,u,d;if(((i=(o=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||o===void 0?void 0:o.parts)===null||i===void 0?void 0:i.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning data from the first one.");let c="";const f=[];for(const h of(d=(u=(a=(l=this.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content)===null||u===void 0?void 0:u.parts)!==null&&d!==void 0?d:[]){for(const[p,m]of Object.entries(h))p!=="inlineData"&&(m!==null||m!==void 0)&&f.push(p);h.inlineData&&typeof h.inlineData.data=="string"&&(c+=atob(h.inlineData.data))}return f.length>0&&console.warn(`there are non-data parts ${f} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`),c.length>0?btoa(c):void 0}get functionCalls(){var e,n,o,i,l,a,u,d;if(((i=(o=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||o===void 0?void 0:o.parts)===null||i===void 0?void 0:i.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning function calls from the first one.");const c=(d=(u=(a=(l=this.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content)===null||u===void 0?void 0:u.parts)===null||d===void 0?void 0:d.filter(f=>f.functionCall).map(f=>f.functionCall).filter(f=>f!==void 0);if(c?.length!==0)return c}get executableCode(){var e,n,o,i,l,a,u,d,c;if(((i=(o=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||o===void 0?void 0:o.parts)===null||i===void 0?void 0:i.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning executable code from the first one.");const f=(d=(u=(a=(l=this.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content)===null||u===void 0?void 0:u.parts)===null||d===void 0?void 0:d.filter(h=>h.executableCode).map(h=>h.executableCode).filter(h=>h!==void 0);if(f?.length!==0)return(c=f?.[0])===null||c===void 0?void 0:c.code}get codeExecutionResult(){var e,n,o,i,l,a,u,d,c;if(((i=(o=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||o===void 0?void 0:o.parts)===null||i===void 0?void 0:i.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning code execution result from the first one.");const f=(d=(u=(a=(l=this.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content)===null||u===void 0?void 0:u.parts)===null||d===void 0?void 0:d.filter(h=>h.codeExecutionResult).map(h=>h.codeExecutionResult).filter(h=>h!==void 0);if(f?.length!==0)return(c=f?.[0])===null||c===void 0?void 0:c.output}}class _n{}class En{}class Ei{}class Ci{}class Si{}class Ii{}class Cn{}class Sn{}class In{}class Ai{}class Re{_fromAPIResponse({apiResponse:e,_isVertexAI:n}){const o=new Re;let i;const l=e;return n?i=ui(l):i=ai(l),Object.assign(o,i),o}}class An{}class Rn{}class Pn{}class Mn{}class Ri{}class Pi{}class Mi{}class lt{_fromAPIResponse({apiResponse:e,_isVertexAI:n}){const o=new lt,l=gi(e);return Object.assign(o,l),o}}class wi{}class Ni{}class Di{}class xi{}class wn{}class Ui{get text(){var e,n,o;let i="",l=!1;const a=[];for(const u of(o=(n=(e=this.serverContent)===null||e===void 0?void 0:e.modelTurn)===null||n===void 0?void 0:n.parts)!==null&&o!==void 0?o:[]){for(const[d,c]of Object.entries(u))d!=="text"&&d!=="thought"&&c!==null&&a.push(d);if(typeof u.text=="string"){if(typeof u.thought=="boolean"&&u.thought)continue;l=!0,i+=u.text}}return a.length>0&&console.warn(`there are non-text parts ${a} in the response, returning concatenation of all text parts. Please refer to the non text parts for a full response from model.`),l?i:void 0}get data(){var e,n,o;let i="";const l=[];for(const a of(o=(n=(e=this.serverContent)===null||e===void 0?void 0:e.modelTurn)===null||n===void 0?void 0:n.parts)!==null&&o!==void 0?o:[]){for(const[u,d]of Object.entries(a))u!=="inlineData"&&d!==null&&l.push(u);a.inlineData&&typeof a.inlineData.data=="string"&&(i+=atob(a.inlineData.data))}return l.length>0&&console.warn(`there are non-data parts ${l} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`),i.length>0?btoa(i):void 0}}class Li{get audioChunk(){if(this.serverContent&&this.serverContent.audioChunks&&this.serverContent.audioChunks.length>0)return this.serverContent.audioChunks[0]}}class at{_fromAPIResponse({apiResponse:e,_isVertexAI:n}){const o=new at,l=to(e);return Object.assign(o,l),o}}/**
|
|
22
|
+
* @license
|
|
23
|
+
* Copyright 2025 Google LLC
|
|
24
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
25
|
+
*/function N(t,e){if(!e||typeof e!="string")throw new Error("model is required and must be a string");if(e.includes("..")||e.includes("?")||e.includes("&"))throw new Error("invalid model parameter");if(t.isVertexAI()){if(e.startsWith("publishers/")||e.startsWith("projects/")||e.startsWith("models/"))return e;if(e.indexOf("/")>=0){const n=e.split("/",2);return`publishers/${n[0]}/models/${n[1]}`}else return`publishers/google/models/${e}`}else return e.startsWith("models/")||e.startsWith("tunedModels/")?e:`models/${e}`}function no(t,e){const n=N(t,e);return n?n.startsWith("publishers/")&&t.isVertexAI()?`projects/${t.getProject()}/locations/${t.getLocation()}/${n}`:n.startsWith("models/")&&t.isVertexAI()?`projects/${t.getProject()}/locations/${t.getLocation()}/publishers/google/${n}`:n:""}function oo(t){return Array.isArray(t)?t.map(e=>Pe(e)):[Pe(t)]}function Pe(t){if(typeof t=="object"&&t!==null)return t;throw new Error(`Could not parse input as Blob. Unsupported blob type: ${typeof t}`)}function io(t){const e=Pe(t);if(e.mimeType&&e.mimeType.startsWith("image/"))return e;throw new Error(`Unsupported mime type: ${e.mimeType}`)}function ro(t){const e=Pe(t);if(e.mimeType&&e.mimeType.startsWith("audio/"))return e;throw new Error(`Unsupported mime type: ${e.mimeType}`)}function Nn(t){if(t==null)throw new Error("PartUnion is required");if(typeof t=="object")return t;if(typeof t=="string")return{text:t};throw new Error(`Unsupported part type: ${typeof t}`)}function so(t){if(t==null||Array.isArray(t)&&t.length===0)throw new Error("PartListUnion is required");return Array.isArray(t)?t.map(e=>Nn(e)):[Nn(t)]}function ze(t){return t!=null&&typeof t=="object"&&"parts"in t&&Array.isArray(t.parts)}function Dn(t){return t!=null&&typeof t=="object"&&"functionCall"in t}function xn(t){return t!=null&&typeof t=="object"&&"functionResponse"in t}function L(t){if(t==null)throw new Error("ContentUnion is required");return ze(t)?t:{role:"user",parts:so(t)}}function ut(t,e){if(!e)return[];if(t.isVertexAI()&&Array.isArray(e))return e.flatMap(n=>{const o=L(n);return o.parts&&o.parts.length>0&&o.parts[0].text!==void 0?[o.parts[0].text]:[]});if(t.isVertexAI()){const n=L(e);return n.parts&&n.parts.length>0&&n.parts[0].text!==void 0?[n.parts[0].text]:[]}return Array.isArray(e)?e.map(n=>L(n)):[L(e)]}function b(t){if(t==null||Array.isArray(t)&&t.length===0)throw new Error("contents are required");if(!Array.isArray(t)){if(Dn(t)||xn(t))throw new Error("To specify functionCall or functionResponse parts, please wrap them in a Content object, specifying the role for them");return[L(t)]}const e=[],n=[],o=ze(t[0]);for(const i of t){const l=ze(i);if(l!=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(l)e.push(i);else{if(Dn(i)||xn(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||e.push({role:"user",parts:so(n)}),e}function ki(t,e){t.includes("null")&&(e.nullable=!0);const n=t.filter(o=>o!=="null");if(n.length===1)e.type=Object.values(X).includes(n[0].toUpperCase())?n[0].toUpperCase():X.TYPE_UNSPECIFIED;else{e.anyOf=[];for(const o of n)e.anyOf.push({type:Object.values(X).includes(o.toUpperCase())?o.toUpperCase():X.TYPE_UNSPECIFIED})}}function se(t){const e={},n=["items"],o=["anyOf"],i=["properties"];if(t.type&&t.anyOf)throw new Error("type and anyOf cannot be both populated.");const l=t.anyOf;l!=null&&l.length==2&&(l[0].type==="null"?(e.nullable=!0,t=l[1]):l[1].type==="null"&&(e.nullable=!0,t=l[0])),t.type instanceof Array&&ki(t.type,e);for(const[a,u]of Object.entries(t))if(u!=null)if(a=="type"){if(u==="null")throw new Error("type: null can not be the only possible type for the field.");if(u instanceof Array)continue;e.type=Object.values(X).includes(u.toUpperCase())?u.toUpperCase():X.TYPE_UNSPECIFIED}else if(n.includes(a))e[a]=se(u);else if(o.includes(a)){const d=[];for(const c of u){if(c.type=="null"){e.nullable=!0;continue}d.push(se(c))}e[a]=d}else if(i.includes(a)){const d={};for(const[c,f]of Object.entries(u))d[c]=se(f);e[a]=d}else{if(a==="additionalProperties")continue;e[a]=u}return e}function ct(t){return se(t)}function dt(t){if(typeof t=="object")return t;if(typeof t=="string")return{voiceConfig:{prebuiltVoiceConfig:{voiceName:t}}};throw new Error(`Unsupported speechConfig type: ${typeof t}`)}function ft(t){if("multiSpeakerVoiceConfig"in t)throw new Error("multiSpeakerVoiceConfig is not supported in the live API.");return t}function ae(t){if(t.functionDeclarations)for(const e of t.functionDeclarations)e.parameters&&(Object.keys(e.parameters).includes("$schema")?e.parametersJsonSchema||(e.parametersJsonSchema=e.parameters,delete e.parameters):e.parameters=se(e.parameters)),e.response&&(Object.keys(e.response).includes("$schema")?e.responseJsonSchema||(e.responseJsonSchema=e.response,delete e.response):e.response=se(e.response));return t}function ue(t){if(t==null)throw new Error("tools is required");if(!Array.isArray(t))throw new Error("tools is required and must be an array of Tools");const e=[];for(const n of t)e.push(n);return e}function Fi(t,e,n,o=1){const i=!e.startsWith(`${n}/`)&&e.split("/").length===o;return t.isVertexAI()?e.startsWith("projects/")?e:e.startsWith("locations/")?`projects/${t.getProject()}/${e}`:e.startsWith(`${n}/`)?`projects/${t.getProject()}/locations/${t.getLocation()}/${e}`:i?`projects/${t.getProject()}/locations/${t.getLocation()}/${n}/${e}`:e:i?`${n}/${e}`:e}function z(t,e){if(typeof e!="string")throw new Error("name must be a string");return Fi(t,e,"cachedContents")}function lo(t){switch(t){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 t}}function Q(t){return st(t)}function Gi(t){return t!=null&&typeof t=="object"&&"name"in t}function Vi(t){return t!=null&&typeof t=="object"&&"video"in t}function Hi(t){return t!=null&&typeof t=="object"&&"uri"in t}function ao(t){var e;let n;if(Gi(t)&&(n=t.name),!(Hi(t)&&(n=t.uri,n===void 0))&&!(Vi(t)&&(n=(e=t.video)===null||e===void 0?void 0:e.uri,n===void 0))){if(typeof t=="string"&&(n=t),n===void 0)throw new Error("Could not extract file name from the provided input.");if(n.startsWith("https://")){const i=n.split("files/")[1].match(/[a-z0-9]+/);if(i===null)throw new Error(`Could not extract file name from URI ${n}`);n=i[0]}else n.startsWith("files/")&&(n=n.split("files/")[1]);return n}}function uo(t,e){let n;return t.isVertexAI()?n=e?"publishers/google/models":"models":n=e?"models":"tunedModels",n}function co(t){for(const e of["models","tunedModels","publisherModels"])if(qi(t,e))return t[e];return[]}function qi(t,e){return t!==null&&typeof t=="object"&&e in t}function bi(t,e={}){const n=t,o={name:n.name,description:n.description,parametersJsonSchema:n.inputSchema};return n.outputSchema&&(o.responseJsonSchema=n.outputSchema),e.behavior&&(o.behavior=e.behavior),{functionDeclarations:[o]}}function Bi(t,e={}){const n=[],o=new Set;for(const i of t){const l=i.name;if(o.has(l))throw new Error(`Duplicate function name ${l} found in MCP tools. Please ensure function names are unique.`);o.add(l);const a=bi(i,e);a.functionDeclarations&&n.push(...a.functionDeclarations)}return{functionDeclarations:n}}function fo(t,e){let n;if(typeof e=="string")if(t.isVertexAI())if(e.startsWith("gs://"))n={format:"jsonl",gcsUri:[e]};else if(e.startsWith("bq://"))n={format:"bigquery",bigqueryUri:e};else throw new Error(`Unsupported string source for Vertex AI: ${e}`);else if(e.startsWith("files/"))n={fileName:e};else throw new Error(`Unsupported string source for Gemini API: ${e}`);else if(Array.isArray(e)){if(t.isVertexAI())throw new Error("InlinedRequest[] is not supported in Vertex AI.");n={inlinedRequests:e}}else n=e;const o=[n.gcsUri,n.bigqueryUri].filter(Boolean).length,i=[n.inlinedRequests,n.fileName].filter(Boolean).length;if(t.isVertexAI()){if(i>0||o!==1)throw new Error("Exactly one of `gcsUri` or `bigqueryUri` must be set for Vertex AI.")}else if(o>0||i!==1)throw new Error("Exactly one of `inlinedRequests`, `fileName`, must be set for Gemini API.");return n}function Ji(t){if(typeof t!="string")return t;const e=t;if(e.startsWith("gs://"))return{format:"jsonl",gcsUri:e};if(e.startsWith("bq://"))return{format:"bigquery",bigqueryUri:e};throw new Error(`Unsupported destination: ${e}`)}function po(t){if(typeof t!="object"||t===null)return{};const e=t,n=e.inlinedResponses;if(typeof n!="object"||n===null)return t;const i=n.inlinedResponses;if(!Array.isArray(i)||i.length===0)return t;let l=!1;for(const a of i){if(typeof a!="object"||a===null)continue;const d=a.response;if(typeof d!="object"||d===null)continue;if(d.embedding!==void 0){l=!0;break}}return l&&(e.inlinedEmbedContentResponses=e.inlinedResponses,delete e.inlinedResponses),t}function ce(t,e){const n=e;if(!t.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 ho(t){const e=t;return e==="BATCH_STATE_UNSPECIFIED"?"JOB_STATE_UNSPECIFIED":e==="BATCH_STATE_PENDING"?"JOB_STATE_PENDING":e==="BATCH_STATE_RUNNING"?"JOB_STATE_RUNNING":e==="BATCH_STATE_SUCCEEDED"?"JOB_STATE_SUCCEEDED":e==="BATCH_STATE_FAILED"?"JOB_STATE_FAILED":e==="BATCH_STATE_CANCELLED"?"JOB_STATE_CANCELLED":e==="BATCH_STATE_EXPIRED"?"JOB_STATE_EXPIRED":e}function $i(t){return t.includes("gemini")&&t!=="gemini-embedding-001"||t.includes("maas")}/**
|
|
26
|
+
* @license
|
|
27
|
+
* Copyright 2025 Google LLC
|
|
28
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
29
|
+
*/function Oi(t){const e={},n=r(t,["responsesFile"]);n!=null&&s(e,["fileName"],n);const o=r(t,["inlinedResponses","inlinedResponses"]);if(o!=null){let l=o;Array.isArray(l)&&(l=l.map(a=>Ar(a))),s(e,["inlinedResponses"],l)}const i=r(t,["inlinedEmbedContentResponses","inlinedResponses"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>a)),s(e,["inlinedEmbedContentResponses"],l)}return e}function Wi(t){const e={},n=r(t,["predictionsFormat"]);n!=null&&s(e,["format"],n);const o=r(t,["gcsDestination","outputUriPrefix"]);o!=null&&s(e,["gcsUri"],o);const i=r(t,["bigqueryDestination","outputUri"]);return i!=null&&s(e,["bigqueryUri"],i),e}function Yi(t){const e={},n=r(t,["format"]);n!=null&&s(e,["predictionsFormat"],n);const o=r(t,["gcsUri"]);o!=null&&s(e,["gcsDestination","outputUriPrefix"],o);const i=r(t,["bigqueryUri"]);if(i!=null&&s(e,["bigqueryDestination","outputUri"],i),r(t,["fileName"])!==void 0)throw new Error("fileName parameter is not supported in Vertex AI.");if(r(t,["inlinedResponses"])!==void 0)throw new Error("inlinedResponses parameter is not supported in Vertex AI.");if(r(t,["inlinedEmbedContentResponses"])!==void 0)throw new Error("inlinedEmbedContentResponses parameter is not supported in Vertex AI.");return e}function Ce(t){const e={},n=r(t,["name"]);n!=null&&s(e,["name"],n);const o=r(t,["metadata","displayName"]);o!=null&&s(e,["displayName"],o);const i=r(t,["metadata","state"]);i!=null&&s(e,["state"],ho(i));const l=r(t,["metadata","createTime"]);l!=null&&s(e,["createTime"],l);const a=r(t,["metadata","endTime"]);a!=null&&s(e,["endTime"],a);const u=r(t,["metadata","updateTime"]);u!=null&&s(e,["updateTime"],u);const d=r(t,["metadata","model"]);d!=null&&s(e,["model"],d);const c=r(t,["metadata","output"]);return c!=null&&s(e,["dest"],Oi(po(c))),e}function Xe(t){const e={},n=r(t,["name"]);n!=null&&s(e,["name"],n);const o=r(t,["displayName"]);o!=null&&s(e,["displayName"],o);const i=r(t,["state"]);i!=null&&s(e,["state"],ho(i));const l=r(t,["error"]);l!=null&&s(e,["error"],l);const a=r(t,["createTime"]);a!=null&&s(e,["createTime"],a);const u=r(t,["startTime"]);u!=null&&s(e,["startTime"],u);const d=r(t,["endTime"]);d!=null&&s(e,["endTime"],d);const c=r(t,["updateTime"]);c!=null&&s(e,["updateTime"],c);const f=r(t,["model"]);f!=null&&s(e,["model"],f);const h=r(t,["inputConfig"]);h!=null&&s(e,["src"],Ki(h));const p=r(t,["outputConfig"]);p!=null&&s(e,["dest"],Wi(po(p)));const m=r(t,["completionStats"]);return m!=null&&s(e,["completionStats"],m),e}function Ki(t){const e={},n=r(t,["instancesFormat"]);n!=null&&s(e,["format"],n);const o=r(t,["gcsSource","uris"]);o!=null&&s(e,["gcsUri"],o);const i=r(t,["bigquerySource","inputUri"]);return i!=null&&s(e,["bigqueryUri"],i),e}function zi(t,e){const n={};if(r(e,["format"])!==void 0)throw new Error("format parameter is not supported in Gemini API.");if(r(e,["gcsUri"])!==void 0)throw new Error("gcsUri parameter is not supported in Gemini API.");if(r(e,["bigqueryUri"])!==void 0)throw new Error("bigqueryUri parameter is not supported in Gemini API.");const o=r(e,["fileName"]);o!=null&&s(n,["fileName"],o);const i=r(e,["inlinedRequests"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>Ir(t,a))),s(n,["requests","requests"],l)}return n}function Xi(t){const e={},n=r(t,["format"]);n!=null&&s(e,["instancesFormat"],n);const o=r(t,["gcsUri"]);o!=null&&s(e,["gcsSource","uris"],o);const i=r(t,["bigqueryUri"]);if(i!=null&&s(e,["bigquerySource","inputUri"],i),r(t,["fileName"])!==void 0)throw new Error("fileName parameter is not supported in Vertex AI.");if(r(t,["inlinedRequests"])!==void 0)throw new Error("inlinedRequests parameter is not supported in Vertex AI.");return e}function Qi(t){const e={},n=r(t,["data"]);if(n!=null&&s(e,["data"],n),r(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const o=r(t,["mimeType"]);return o!=null&&s(e,["mimeType"],o),e}function Zi(t,e){const n={},o=r(e,["name"]);return o!=null&&s(n,["_url","name"],ce(t,o)),n}function ji(t,e){const n={},o=r(e,["name"]);return o!=null&&s(n,["_url","name"],ce(t,o)),n}function er(t){const e={},n=r(t,["content"]);n!=null&&s(e,["content"],n);const o=r(t,["citationMetadata"]);o!=null&&s(e,["citationMetadata"],tr(o));const i=r(t,["tokenCount"]);i!=null&&s(e,["tokenCount"],i);const l=r(t,["finishReason"]);l!=null&&s(e,["finishReason"],l);const a=r(t,["groundingMetadata"]);a!=null&&s(e,["groundingMetadata"],a);const u=r(t,["avgLogprobs"]);u!=null&&s(e,["avgLogprobs"],u);const d=r(t,["index"]);d!=null&&s(e,["index"],d);const c=r(t,["logprobsResult"]);c!=null&&s(e,["logprobsResult"],c);const f=r(t,["safetyRatings"]);if(f!=null){let p=f;Array.isArray(p)&&(p=p.map(m=>m)),s(e,["safetyRatings"],p)}const h=r(t,["urlContextMetadata"]);return h!=null&&s(e,["urlContextMetadata"],h),e}function tr(t){const e={},n=r(t,["citationSources"]);if(n!=null){let o=n;Array.isArray(o)&&(o=o.map(i=>i)),s(e,["citations"],o)}return e}function mo(t){const e={},n=r(t,["parts"]);if(n!=null){let i=n;Array.isArray(i)&&(i=i.map(l=>xr(l))),s(e,["parts"],i)}const o=r(t,["role"]);return o!=null&&s(e,["role"],o),e}function nr(t,e){const n={},o=r(t,["displayName"]);if(e!==void 0&&o!=null&&s(e,["batch","displayName"],o),r(t,["dest"])!==void 0)throw new Error("dest parameter is not supported in Gemini API.");return n}function or(t,e){const n={},o=r(t,["displayName"]);e!==void 0&&o!=null&&s(e,["displayName"],o);const i=r(t,["dest"]);return e!==void 0&&i!=null&&s(e,["outputConfig"],Yi(Ji(i))),n}function Un(t,e){const n={},o=r(e,["model"]);o!=null&&s(n,["_url","model"],N(t,o));const i=r(e,["src"]);i!=null&&s(n,["batch","inputConfig"],zi(t,fo(t,i)));const l=r(e,["config"]);return l!=null&&nr(l,n),n}function ir(t,e){const n={},o=r(e,["model"]);o!=null&&s(n,["model"],N(t,o));const i=r(e,["src"]);i!=null&&s(n,["inputConfig"],Xi(fo(t,i)));const l=r(e,["config"]);return l!=null&&or(l,n),n}function rr(t,e){const n={},o=r(t,["displayName"]);return e!==void 0&&o!=null&&s(e,["batch","displayName"],o),n}function sr(t,e){const n={},o=r(e,["model"]);o!=null&&s(n,["_url","model"],N(t,o));const i=r(e,["src"]);i!=null&&s(n,["batch","inputConfig"],pr(t,i));const l=r(e,["config"]);return l!=null&&rr(l,n),n}function lr(t,e){const n={},o=r(e,["name"]);return o!=null&&s(n,["_url","name"],ce(t,o)),n}function ar(t,e){const n={},o=r(e,["name"]);return o!=null&&s(n,["_url","name"],ce(t,o)),n}function ur(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["name"]);o!=null&&s(e,["name"],o);const i=r(t,["done"]);i!=null&&s(e,["done"],i);const l=r(t,["error"]);return l!=null&&s(e,["error"],l),e}function cr(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["name"]);o!=null&&s(e,["name"],o);const i=r(t,["done"]);i!=null&&s(e,["done"],i);const l=r(t,["error"]);return l!=null&&s(e,["error"],l),e}function dr(t,e){const n={},o=r(e,["contents"]);if(o!=null){let l=ut(t,o);Array.isArray(l)&&(l=l.map(a=>a)),s(n,["requests[]","request","content"],l)}const i=r(e,["config"]);return i!=null&&(s(n,["_self"],fr(i,n)),si(n,{"requests[].*":"requests[].request.*"})),n}function fr(t,e){const n={},o=r(t,["taskType"]);e!==void 0&&o!=null&&s(e,["requests[]","taskType"],o);const i=r(t,["title"]);e!==void 0&&i!=null&&s(e,["requests[]","title"],i);const l=r(t,["outputDimensionality"]);if(e!==void 0&&l!=null&&s(e,["requests[]","outputDimensionality"],l),r(t,["mimeType"])!==void 0)throw new Error("mimeType parameter is not supported in Gemini API.");if(r(t,["autoTruncate"])!==void 0)throw new Error("autoTruncate parameter is not supported in Gemini API.");return n}function pr(t,e){const n={},o=r(e,["fileName"]);o!=null&&s(n,["file_name"],o);const i=r(e,["inlinedRequests"]);return i!=null&&s(n,["requests"],dr(t,i)),n}function hr(t){const e={};if(r(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const n=r(t,["fileUri"]);n!=null&&s(e,["fileUri"],n);const o=r(t,["mimeType"]);return o!=null&&s(e,["mimeType"],o),e}function mr(t){const e={},n=r(t,["id"]);n!=null&&s(e,["id"],n);const o=r(t,["args"]);o!=null&&s(e,["args"],o);const i=r(t,["name"]);if(i!=null&&s(e,["name"],i),r(t,["partialArgs"])!==void 0)throw new Error("partialArgs parameter is not supported in Gemini API.");if(r(t,["willContinue"])!==void 0)throw new Error("willContinue parameter is not supported in Gemini API.");return e}function gr(t){const e={},n=r(t,["allowedFunctionNames"]);n!=null&&s(e,["allowedFunctionNames"],n);const o=r(t,["mode"]);if(o!=null&&s(e,["mode"],o),r(t,["streamFunctionCallArguments"])!==void 0)throw new Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return e}function yr(t,e,n){const o={},i=r(e,["systemInstruction"]);n!==void 0&&i!=null&&s(n,["systemInstruction"],mo(L(i)));const l=r(e,["temperature"]);l!=null&&s(o,["temperature"],l);const a=r(e,["topP"]);a!=null&&s(o,["topP"],a);const u=r(e,["topK"]);u!=null&&s(o,["topK"],u);const d=r(e,["candidateCount"]);d!=null&&s(o,["candidateCount"],d);const c=r(e,["maxOutputTokens"]);c!=null&&s(o,["maxOutputTokens"],c);const f=r(e,["stopSequences"]);f!=null&&s(o,["stopSequences"],f);const h=r(e,["responseLogprobs"]);h!=null&&s(o,["responseLogprobs"],h);const p=r(e,["logprobs"]);p!=null&&s(o,["logprobs"],p);const m=r(e,["presencePenalty"]);m!=null&&s(o,["presencePenalty"],m);const g=r(e,["frequencyPenalty"]);g!=null&&s(o,["frequencyPenalty"],g);const v=r(e,["seed"]);v!=null&&s(o,["seed"],v);const y=r(e,["responseMimeType"]);y!=null&&s(o,["responseMimeType"],y);const T=r(e,["responseSchema"]);T!=null&&s(o,["responseSchema"],ct(T));const I=r(e,["responseJsonSchema"]);if(I!=null&&s(o,["responseJsonSchema"],I),r(e,["routingConfig"])!==void 0)throw new Error("routingConfig parameter is not supported in Gemini API.");if(r(e,["modelSelectionConfig"])!==void 0)throw new Error("modelSelectionConfig parameter is not supported in Gemini API.");const C=r(e,["safetySettings"]);if(n!==void 0&&C!=null){let G=C;Array.isArray(G)&&(G=G.map(F=>Ur(F))),s(n,["safetySettings"],G)}const S=r(e,["tools"]);if(n!==void 0&&S!=null){let G=ue(S);Array.isArray(G)&&(G=G.map(F=>kr(ae(F)))),s(n,["tools"],G)}const R=r(e,["toolConfig"]);if(n!==void 0&&R!=null&&s(n,["toolConfig"],Lr(R)),r(e,["labels"])!==void 0)throw new Error("labels parameter is not supported in Gemini API.");const _=r(e,["cachedContent"]);n!==void 0&&_!=null&&s(n,["cachedContent"],z(t,_));const M=r(e,["responseModalities"]);M!=null&&s(o,["responseModalities"],M);const D=r(e,["mediaResolution"]);D!=null&&s(o,["mediaResolution"],D);const A=r(e,["speechConfig"]);if(A!=null&&s(o,["speechConfig"],dt(A)),r(e,["audioTimestamp"])!==void 0)throw new Error("audioTimestamp parameter is not supported in Gemini API.");const w=r(e,["thinkingConfig"]);w!=null&&s(o,["thinkingConfig"],w);const x=r(e,["imageConfig"]);x!=null&&s(o,["imageConfig"],Sr(x));const q=r(e,["enableEnhancedCivicAnswers"]);if(q!=null&&s(o,["enableEnhancedCivicAnswers"],q),r(e,["modelArmorConfig"])!==void 0)throw new Error("modelArmorConfig parameter is not supported in Gemini API.");return o}function vr(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["candidates"]);if(o!=null){let d=o;Array.isArray(d)&&(d=d.map(c=>er(c))),s(e,["candidates"],d)}const i=r(t,["modelVersion"]);i!=null&&s(e,["modelVersion"],i);const l=r(t,["promptFeedback"]);l!=null&&s(e,["promptFeedback"],l);const a=r(t,["responseId"]);a!=null&&s(e,["responseId"],a);const u=r(t,["usageMetadata"]);return u!=null&&s(e,["usageMetadata"],u),e}function Tr(t,e){const n={},o=r(e,["name"]);return o!=null&&s(n,["_url","name"],ce(t,o)),n}function _r(t,e){const n={},o=r(e,["name"]);return o!=null&&s(n,["_url","name"],ce(t,o)),n}function Er(t){const e={};if(r(t,["authConfig"])!==void 0)throw new Error("authConfig parameter is not supported in Gemini API.");const n=r(t,["enableWidget"]);return n!=null&&s(e,["enableWidget"],n),e}function Cr(t){const e={},n=r(t,["searchTypes"]);if(n!=null&&s(e,["searchTypes"],n),r(t,["excludeDomains"])!==void 0)throw new Error("excludeDomains parameter is not supported in Gemini API.");if(r(t,["blockingConfidence"])!==void 0)throw new Error("blockingConfidence parameter is not supported in Gemini API.");const o=r(t,["timeRangeFilter"]);return o!=null&&s(e,["timeRangeFilter"],o),e}function Sr(t){const e={},n=r(t,["aspectRatio"]);n!=null&&s(e,["aspectRatio"],n);const o=r(t,["imageSize"]);if(o!=null&&s(e,["imageSize"],o),r(t,["personGeneration"])!==void 0)throw new Error("personGeneration parameter is not supported in Gemini API.");if(r(t,["prominentPeople"])!==void 0)throw new Error("prominentPeople parameter is not supported in Gemini API.");if(r(t,["outputMimeType"])!==void 0)throw new Error("outputMimeType parameter is not supported in Gemini API.");if(r(t,["outputCompressionQuality"])!==void 0)throw new Error("outputCompressionQuality parameter is not supported in Gemini API.");return e}function Ir(t,e){const n={},o=r(e,["model"]);o!=null&&s(n,["request","model"],N(t,o));const i=r(e,["contents"]);if(i!=null){let u=b(i);Array.isArray(u)&&(u=u.map(d=>mo(d))),s(n,["request","contents"],u)}const l=r(e,["metadata"]);l!=null&&s(n,["metadata"],l);const a=r(e,["config"]);return a!=null&&s(n,["request","generationConfig"],yr(t,a,r(n,["request"],{}))),n}function Ar(t){const e={},n=r(t,["response"]);n!=null&&s(e,["response"],vr(n));const o=r(t,["metadata"]);o!=null&&s(e,["metadata"],o);const i=r(t,["error"]);return i!=null&&s(e,["error"],i),e}function Rr(t,e){const n={},o=r(t,["pageSize"]);e!==void 0&&o!=null&&s(e,["_query","pageSize"],o);const i=r(t,["pageToken"]);if(e!==void 0&&i!=null&&s(e,["_query","pageToken"],i),r(t,["filter"])!==void 0)throw new Error("filter parameter is not supported in Gemini API.");return n}function Pr(t,e){const n={},o=r(t,["pageSize"]);e!==void 0&&o!=null&&s(e,["_query","pageSize"],o);const i=r(t,["pageToken"]);e!==void 0&&i!=null&&s(e,["_query","pageToken"],i);const l=r(t,["filter"]);return e!==void 0&&l!=null&&s(e,["_query","filter"],l),n}function Mr(t){const e={},n=r(t,["config"]);return n!=null&&Rr(n,e),e}function wr(t){const e={},n=r(t,["config"]);return n!=null&&Pr(n,e),e}function Nr(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["nextPageToken"]);o!=null&&s(e,["nextPageToken"],o);const i=r(t,["operations"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>Ce(a))),s(e,["batchJobs"],l)}return e}function Dr(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["nextPageToken"]);o!=null&&s(e,["nextPageToken"],o);const i=r(t,["batchPredictionJobs"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>Xe(a))),s(e,["batchJobs"],l)}return e}function xr(t){const e={},n=r(t,["mediaResolution"]);n!=null&&s(e,["mediaResolution"],n);const o=r(t,["codeExecutionResult"]);o!=null&&s(e,["codeExecutionResult"],o);const i=r(t,["executableCode"]);i!=null&&s(e,["executableCode"],i);const l=r(t,["fileData"]);l!=null&&s(e,["fileData"],hr(l));const a=r(t,["functionCall"]);a!=null&&s(e,["functionCall"],mr(a));const u=r(t,["functionResponse"]);u!=null&&s(e,["functionResponse"],u);const d=r(t,["inlineData"]);d!=null&&s(e,["inlineData"],Qi(d));const c=r(t,["text"]);c!=null&&s(e,["text"],c);const f=r(t,["thought"]);f!=null&&s(e,["thought"],f);const h=r(t,["thoughtSignature"]);h!=null&&s(e,["thoughtSignature"],h);const p=r(t,["videoMetadata"]);return p!=null&&s(e,["videoMetadata"],p),e}function Ur(t){const e={},n=r(t,["category"]);if(n!=null&&s(e,["category"],n),r(t,["method"])!==void 0)throw new Error("method parameter is not supported in Gemini API.");const o=r(t,["threshold"]);return o!=null&&s(e,["threshold"],o),e}function Lr(t){const e={},n=r(t,["retrievalConfig"]);n!=null&&s(e,["retrievalConfig"],n);const o=r(t,["functionCallingConfig"]);return o!=null&&s(e,["functionCallingConfig"],gr(o)),e}function kr(t){const e={};if(r(t,["retrieval"])!==void 0)throw new Error("retrieval parameter is not supported in Gemini API.");const n=r(t,["computerUse"]);n!=null&&s(e,["computerUse"],n);const o=r(t,["fileSearch"]);o!=null&&s(e,["fileSearch"],o);const i=r(t,["googleSearch"]);i!=null&&s(e,["googleSearch"],Cr(i));const l=r(t,["codeExecution"]);if(l!=null&&s(e,["codeExecution"],l),r(t,["enterpriseWebSearch"])!==void 0)throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const a=r(t,["functionDeclarations"]);if(a!=null){let h=a;Array.isArray(h)&&(h=h.map(p=>p)),s(e,["functionDeclarations"],h)}const u=r(t,["googleMaps"]);u!=null&&s(e,["googleMaps"],Er(u));const d=r(t,["googleSearchRetrieval"]);d!=null&&s(e,["googleSearchRetrieval"],d);const c=r(t,["urlContext"]);c!=null&&s(e,["urlContext"],c);const f=r(t,["mcpServers"]);if(f!=null){let h=f;Array.isArray(h)&&(h=h.map(p=>p)),s(e,["mcpServers"],h)}return e}/**
|
|
30
|
+
* @license
|
|
31
|
+
* Copyright 2025 Google LLC
|
|
32
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
33
|
+
*/var Y;(function(t){t.PAGED_ITEM_BATCH_JOBS="batchJobs",t.PAGED_ITEM_MODELS="models",t.PAGED_ITEM_TUNING_JOBS="tuningJobs",t.PAGED_ITEM_FILES="files",t.PAGED_ITEM_CACHED_CONTENTS="cachedContents",t.PAGED_ITEM_FILE_SEARCH_STORES="fileSearchStores",t.PAGED_ITEM_DOCUMENTS="documents"})(Y||(Y={}));class j{constructor(e,n,o,i){this.pageInternal=[],this.paramsInternal={},this.requestInternal=n,this.init(e,o,i)}init(e,n,o){var i,l;this.nameInternal=e,this.pageInternal=n[this.nameInternal]||[],this.sdkHttpResponseInternal=n?.sdkHttpResponse,this.idxInternal=0;let a={config:{}};!o||Object.keys(o).length===0?a={config:{}}:typeof o=="object"?a=Object.assign({},o):a=o,a.config&&(a.config.pageToken=n.nextPageToken),this.paramsInternal=a,this.pageInternalSize=(l=(i=a.config)===null||i===void 0?void 0:i.pageSize)!==null&&l!==void 0?l:this.pageInternal.length}initNextPage(e){this.init(this.nameInternal,e,this.paramsInternal)}get page(){return this.pageInternal}get name(){return this.nameInternal}get pageSize(){return this.pageInternalSize}get sdkHttpResponse(){return this.sdkHttpResponseInternal}get params(){return this.paramsInternal}get pageLength(){return this.pageInternal.length}getItem(e){return this.pageInternal[e]}[Symbol.asyncIterator](){return{next:async()=>{if(this.idxInternal>=this.pageLength)if(this.hasNextPage())await this.nextPage();else return{value:void 0,done:!0};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((e=this.params.config)===null||e===void 0?void 0:e.pageToken)!==void 0}}/**
|
|
34
|
+
* @license
|
|
35
|
+
* Copyright 2025 Google LLC
|
|
36
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
*/class Fr extends K{constructor(e){super(),this.apiClient=e,this.list=async(n={})=>new j(Y.PAGED_ITEM_BATCH_JOBS,o=>this.listInternal(o),await this.listInternal(n),n),this.create=async n=>(this.apiClient.isVertexAI()&&(n.config=this.formatDestination(n.src,n.config)),this.createInternal(n)),this.createEmbeddings=async n=>{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(n)}}createInlinedGenerateContentRequest(e){const n=Un(this.apiClient,e),o=n._url,i=E("{model}:batchGenerateContent",o),u=n.batch.inputConfig.requests,d=u.requests,c=[];for(const f of d){const h=Object.assign({},f);if(h.systemInstruction){const p=h.systemInstruction;delete h.systemInstruction;const m=h.request;m.systemInstruction=p,h.request=m}c.push(h)}return u.requests=c,delete n.config,delete n._url,delete n._query,{path:i,body:n}}getGcsUri(e){if(typeof e=="string")return e.startsWith("gs://")?e:void 0;if(!Array.isArray(e)&&e.gcsUri&&e.gcsUri.length>0)return e.gcsUri[0]}getBigqueryUri(e){if(typeof e=="string")return e.startsWith("bq://")?e:void 0;if(!Array.isArray(e))return e.bigqueryUri}formatDestination(e,n){const o=n?Object.assign({},n):{},i=Date.now().toString();if(o.displayName||(o.displayName=`genaiBatchJob_${i}`),o.dest===void 0){const l=this.getGcsUri(e),a=this.getBigqueryUri(e);if(l)l.endsWith(".jsonl")?o.dest=`${l.slice(0,-6)}/dest`:o.dest=`${l}_dest_${i}`;else if(a)o.dest=`${a}_dest_${i}`;else throw new Error("Unsupported source for Vertex AI: No GCS or BigQuery URI found.")}return o}async createInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=ir(this.apiClient,e);return u=E("batchPredictionJobs",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>Xe(f))}else{const c=Un(this.apiClient,e);return u=E("{model}:batchGenerateContent",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>Ce(f))}}async createEmbeddingsInternal(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=sr(this.apiClient,e);return l=E("{model}:asyncBatchEmbedContent",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>Ce(d))}}async get(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=_r(this.apiClient,e);return u=E("batchPredictionJobs/{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>Xe(f))}else{const c=Tr(this.apiClient,e);return u=E("batches/{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>Ce(f))}}async cancel(e){var n,o,i,l;let a="",u={};if(this.apiClient.isVertexAI()){const d=ji(this.apiClient,e);a=E("batchPredictionJobs/{name}:cancel",d._url),u=d._query,delete d._url,delete d._query,await this.apiClient.request({path:a,queryParams:u,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal})}else{const d=Zi(this.apiClient,e);a=E("batches/{name}:cancel",d._url),u=d._query,delete d._url,delete d._query,await this.apiClient.request({path:a,queryParams:u,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal})}}async listInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=wr(e);return u=E("batchPredictionJobs",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Dr(f),p=new wn;return Object.assign(p,h),p})}else{const c=Mr(e);return u=E("batches",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Nr(f),p=new wn;return Object.assign(p,h),p})}}async delete(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=ar(this.apiClient,e);return u=E("batchPredictionJobs/{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>cr(f))}else{const c=lr(this.apiClient,e);return u=E("batches/{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"DELETE",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>ur(f))}}}/**
|
|
38
|
+
* @license
|
|
39
|
+
* Copyright 2025 Google LLC
|
|
40
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
41
|
+
*/function Gr(t){const e={},n=r(t,["data"]);if(n!=null&&s(e,["data"],n),r(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const o=r(t,["mimeType"]);return o!=null&&s(e,["mimeType"],o),e}function Ln(t){const e={},n=r(t,["parts"]);if(n!=null){let i=n;Array.isArray(i)&&(i=i.map(l=>ss(l))),s(e,["parts"],i)}const o=r(t,["role"]);return o!=null&&s(e,["role"],o),e}function Vr(t,e){const n={},o=r(t,["ttl"]);e!==void 0&&o!=null&&s(e,["ttl"],o);const i=r(t,["expireTime"]);e!==void 0&&i!=null&&s(e,["expireTime"],i);const l=r(t,["displayName"]);e!==void 0&&l!=null&&s(e,["displayName"],l);const a=r(t,["contents"]);if(e!==void 0&&a!=null){let f=b(a);Array.isArray(f)&&(f=f.map(h=>Ln(h))),s(e,["contents"],f)}const u=r(t,["systemInstruction"]);e!==void 0&&u!=null&&s(e,["systemInstruction"],Ln(L(u)));const d=r(t,["tools"]);if(e!==void 0&&d!=null){let f=d;Array.isArray(f)&&(f=f.map(h=>as(h))),s(e,["tools"],f)}const c=r(t,["toolConfig"]);if(e!==void 0&&c!=null&&s(e,["toolConfig"],ls(c)),r(t,["kmsKeyName"])!==void 0)throw new Error("kmsKeyName parameter is not supported in Gemini API.");return n}function Hr(t,e){const n={},o=r(t,["ttl"]);e!==void 0&&o!=null&&s(e,["ttl"],o);const i=r(t,["expireTime"]);e!==void 0&&i!=null&&s(e,["expireTime"],i);const l=r(t,["displayName"]);e!==void 0&&l!=null&&s(e,["displayName"],l);const a=r(t,["contents"]);if(e!==void 0&&a!=null){let h=b(a);Array.isArray(h)&&(h=h.map(p=>p)),s(e,["contents"],h)}const u=r(t,["systemInstruction"]);e!==void 0&&u!=null&&s(e,["systemInstruction"],L(u));const d=r(t,["tools"]);if(e!==void 0&&d!=null){let h=d;Array.isArray(h)&&(h=h.map(p=>us(p))),s(e,["tools"],h)}const c=r(t,["toolConfig"]);e!==void 0&&c!=null&&s(e,["toolConfig"],c);const f=r(t,["kmsKeyName"]);return e!==void 0&&f!=null&&s(e,["encryption_spec","kmsKeyName"],f),n}function qr(t,e){const n={},o=r(e,["model"]);o!=null&&s(n,["model"],no(t,o));const i=r(e,["config"]);return i!=null&&Vr(i,n),n}function br(t,e){const n={},o=r(e,["model"]);o!=null&&s(n,["model"],no(t,o));const i=r(e,["config"]);return i!=null&&Hr(i,n),n}function Br(t,e){const n={},o=r(e,["name"]);return o!=null&&s(n,["_url","name"],z(t,o)),n}function Jr(t,e){const n={},o=r(e,["name"]);return o!=null&&s(n,["_url","name"],z(t,o)),n}function $r(t){const e={},n=r(t,["sdkHttpResponse"]);return n!=null&&s(e,["sdkHttpResponse"],n),e}function Or(t){const e={},n=r(t,["sdkHttpResponse"]);return n!=null&&s(e,["sdkHttpResponse"],n),e}function Wr(t){const e={};if(r(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const n=r(t,["fileUri"]);n!=null&&s(e,["fileUri"],n);const o=r(t,["mimeType"]);return o!=null&&s(e,["mimeType"],o),e}function Yr(t){const e={},n=r(t,["id"]);n!=null&&s(e,["id"],n);const o=r(t,["args"]);o!=null&&s(e,["args"],o);const i=r(t,["name"]);if(i!=null&&s(e,["name"],i),r(t,["partialArgs"])!==void 0)throw new Error("partialArgs parameter is not supported in Gemini API.");if(r(t,["willContinue"])!==void 0)throw new Error("willContinue parameter is not supported in Gemini API.");return e}function Kr(t){const e={},n=r(t,["allowedFunctionNames"]);n!=null&&s(e,["allowedFunctionNames"],n);const o=r(t,["mode"]);if(o!=null&&s(e,["mode"],o),r(t,["streamFunctionCallArguments"])!==void 0)throw new Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return e}function zr(t){const e={},n=r(t,["description"]);n!=null&&s(e,["description"],n);const o=r(t,["name"]);o!=null&&s(e,["name"],o);const i=r(t,["parameters"]);i!=null&&s(e,["parameters"],i);const l=r(t,["parametersJsonSchema"]);l!=null&&s(e,["parametersJsonSchema"],l);const a=r(t,["response"]);a!=null&&s(e,["response"],a);const u=r(t,["responseJsonSchema"]);if(u!=null&&s(e,["responseJsonSchema"],u),r(t,["behavior"])!==void 0)throw new Error("behavior parameter is not supported in Vertex AI.");return e}function Xr(t,e){const n={},o=r(e,["name"]);return o!=null&&s(n,["_url","name"],z(t,o)),n}function Qr(t,e){const n={},o=r(e,["name"]);return o!=null&&s(n,["_url","name"],z(t,o)),n}function Zr(t){const e={};if(r(t,["authConfig"])!==void 0)throw new Error("authConfig parameter is not supported in Gemini API.");const n=r(t,["enableWidget"]);return n!=null&&s(e,["enableWidget"],n),e}function jr(t){const e={},n=r(t,["searchTypes"]);if(n!=null&&s(e,["searchTypes"],n),r(t,["excludeDomains"])!==void 0)throw new Error("excludeDomains parameter is not supported in Gemini API.");if(r(t,["blockingConfidence"])!==void 0)throw new Error("blockingConfidence parameter is not supported in Gemini API.");const o=r(t,["timeRangeFilter"]);return o!=null&&s(e,["timeRangeFilter"],o),e}function es(t,e){const n={},o=r(t,["pageSize"]);e!==void 0&&o!=null&&s(e,["_query","pageSize"],o);const i=r(t,["pageToken"]);return e!==void 0&&i!=null&&s(e,["_query","pageToken"],i),n}function ts(t,e){const n={},o=r(t,["pageSize"]);e!==void 0&&o!=null&&s(e,["_query","pageSize"],o);const i=r(t,["pageToken"]);return e!==void 0&&i!=null&&s(e,["_query","pageToken"],i),n}function ns(t){const e={},n=r(t,["config"]);return n!=null&&es(n,e),e}function os(t){const e={},n=r(t,["config"]);return n!=null&&ts(n,e),e}function is(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["nextPageToken"]);o!=null&&s(e,["nextPageToken"],o);const i=r(t,["cachedContents"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>a)),s(e,["cachedContents"],l)}return e}function rs(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["nextPageToken"]);o!=null&&s(e,["nextPageToken"],o);const i=r(t,["cachedContents"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>a)),s(e,["cachedContents"],l)}return e}function ss(t){const e={},n=r(t,["mediaResolution"]);n!=null&&s(e,["mediaResolution"],n);const o=r(t,["codeExecutionResult"]);o!=null&&s(e,["codeExecutionResult"],o);const i=r(t,["executableCode"]);i!=null&&s(e,["executableCode"],i);const l=r(t,["fileData"]);l!=null&&s(e,["fileData"],Wr(l));const a=r(t,["functionCall"]);a!=null&&s(e,["functionCall"],Yr(a));const u=r(t,["functionResponse"]);u!=null&&s(e,["functionResponse"],u);const d=r(t,["inlineData"]);d!=null&&s(e,["inlineData"],Gr(d));const c=r(t,["text"]);c!=null&&s(e,["text"],c);const f=r(t,["thought"]);f!=null&&s(e,["thought"],f);const h=r(t,["thoughtSignature"]);h!=null&&s(e,["thoughtSignature"],h);const p=r(t,["videoMetadata"]);return p!=null&&s(e,["videoMetadata"],p),e}function ls(t){const e={},n=r(t,["retrievalConfig"]);n!=null&&s(e,["retrievalConfig"],n);const o=r(t,["functionCallingConfig"]);return o!=null&&s(e,["functionCallingConfig"],Kr(o)),e}function as(t){const e={};if(r(t,["retrieval"])!==void 0)throw new Error("retrieval parameter is not supported in Gemini API.");const n=r(t,["computerUse"]);n!=null&&s(e,["computerUse"],n);const o=r(t,["fileSearch"]);o!=null&&s(e,["fileSearch"],o);const i=r(t,["googleSearch"]);i!=null&&s(e,["googleSearch"],jr(i));const l=r(t,["codeExecution"]);if(l!=null&&s(e,["codeExecution"],l),r(t,["enterpriseWebSearch"])!==void 0)throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const a=r(t,["functionDeclarations"]);if(a!=null){let h=a;Array.isArray(h)&&(h=h.map(p=>p)),s(e,["functionDeclarations"],h)}const u=r(t,["googleMaps"]);u!=null&&s(e,["googleMaps"],Zr(u));const d=r(t,["googleSearchRetrieval"]);d!=null&&s(e,["googleSearchRetrieval"],d);const c=r(t,["urlContext"]);c!=null&&s(e,["urlContext"],c);const f=r(t,["mcpServers"]);if(f!=null){let h=f;Array.isArray(h)&&(h=h.map(p=>p)),s(e,["mcpServers"],h)}return e}function us(t){const e={},n=r(t,["retrieval"]);n!=null&&s(e,["retrieval"],n);const o=r(t,["computerUse"]);if(o!=null&&s(e,["computerUse"],o),r(t,["fileSearch"])!==void 0)throw new Error("fileSearch parameter is not supported in Vertex AI.");const i=r(t,["googleSearch"]);i!=null&&s(e,["googleSearch"],i);const l=r(t,["codeExecution"]);l!=null&&s(e,["codeExecution"],l);const a=r(t,["enterpriseWebSearch"]);a!=null&&s(e,["enterpriseWebSearch"],a);const u=r(t,["functionDeclarations"]);if(u!=null){let h=u;Array.isArray(h)&&(h=h.map(p=>zr(p))),s(e,["functionDeclarations"],h)}const d=r(t,["googleMaps"]);d!=null&&s(e,["googleMaps"],d);const c=r(t,["googleSearchRetrieval"]);c!=null&&s(e,["googleSearchRetrieval"],c);const f=r(t,["urlContext"]);if(f!=null&&s(e,["urlContext"],f),r(t,["mcpServers"])!==void 0)throw new Error("mcpServers parameter is not supported in Vertex AI.");return e}function cs(t,e){const n={},o=r(t,["ttl"]);e!==void 0&&o!=null&&s(e,["ttl"],o);const i=r(t,["expireTime"]);return e!==void 0&&i!=null&&s(e,["expireTime"],i),n}function ds(t,e){const n={},o=r(t,["ttl"]);e!==void 0&&o!=null&&s(e,["ttl"],o);const i=r(t,["expireTime"]);return e!==void 0&&i!=null&&s(e,["expireTime"],i),n}function fs(t,e){const n={},o=r(e,["name"]);o!=null&&s(n,["_url","name"],z(t,o));const i=r(e,["config"]);return i!=null&&cs(i,n),n}function ps(t,e){const n={},o=r(e,["name"]);o!=null&&s(n,["_url","name"],z(t,o));const i=r(e,["config"]);return i!=null&&ds(i,n),n}/**
|
|
42
|
+
* @license
|
|
43
|
+
* Copyright 2025 Google LLC
|
|
44
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
45
|
+
*/class hs extends K{constructor(e){super(),this.apiClient=e,this.list=async(n={})=>new j(Y.PAGED_ITEM_CACHED_CONTENTS,o=>this.listInternal(o),await this.listInternal(n),n)}async create(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=br(this.apiClient,e);return u=E("cachedContents",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>f)}else{const c=qr(this.apiClient,e);return u=E("cachedContents",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>f)}}async get(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=Qr(this.apiClient,e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>f)}else{const c=Xr(this.apiClient,e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>f)}}async delete(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=Jr(this.apiClient,e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Or(f),p=new Pn;return Object.assign(p,h),p})}else{const c=Br(this.apiClient,e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"DELETE",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=$r(f),p=new Pn;return Object.assign(p,h),p})}}async update(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=ps(this.apiClient,e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"PATCH",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>f)}else{const c=fs(this.apiClient,e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"PATCH",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>f)}}async listInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=os(e);return u=E("cachedContents",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=rs(f),p=new Mn;return Object.assign(p,h),p})}else{const c=ns(e);return u=E("cachedContents",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=is(f),p=new Mn;return Object.assign(p,h),p})}}}function Me(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]]);return n}function kn(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],o=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function P(t){return this instanceof P?(this.v=t,this):new P(t)}function J(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o=n.apply(t,e||[]),i,l=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),u("next"),u("throw"),u("return",a),i[Symbol.asyncIterator]=function(){return this},i;function a(m){return function(g){return Promise.resolve(g).then(m,h)}}function u(m,g){o[m]&&(i[m]=function(v){return new Promise(function(y,T){l.push([m,v,y,T])>1||d(m,v)})},g&&(i[m]=g(i[m])))}function d(m,g){try{c(o[m](g))}catch(v){p(l[0][3],v)}}function c(m){m.value instanceof P?Promise.resolve(m.value.v).then(f,h):p(l[0][2],m)}function f(m){d("next",m)}function h(m){d("throw",m)}function p(m,g){m(g),l.shift(),l.length&&d(l[0][0],l[0][1])}}function $(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],n;return e?e.call(t):(t=typeof kn=="function"?kn(t):t[Symbol.iterator](),n={},o("next"),o("throw"),o("return"),n[Symbol.asyncIterator]=function(){return this},n);function o(l){n[l]=t[l]&&function(a){return new Promise(function(u,d){a=t[l](a),i(u,d,a.done,a.value)})}}function i(l,a,u,d){Promise.resolve(d).then(function(c){l({value:c,done:u})},a)}}/**
|
|
46
|
+
* @license
|
|
47
|
+
* Copyright 2025 Google LLC
|
|
48
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
49
|
+
*/function ms(t){var e;if(t.candidates==null||t.candidates.length===0)return!1;const n=(e=t.candidates[0])===null||e===void 0?void 0:e.content;return n===void 0?!1:go(n)}function go(t){if(t.parts===void 0||t.parts.length===0)return!1;for(const e of t.parts)if(e===void 0||Object.keys(e).length===0)return!1;return!0}function gs(t){if(t.length!==0){for(const e of t)if(e.role!=="user"&&e.role!=="model")throw new Error(`Role must be user or model, but got ${e.role}.`)}}function Fn(t){if(t===void 0||t.length===0)return[];const e=[],n=t.length;let o=0;for(;o<n;)if(t[o].role==="user")e.push(t[o]),o++;else{const i=[];let l=!0;for(;o<n&&t[o].role==="model";)i.push(t[o]),l&&!go(t[o])&&(l=!1),o++;l?e.push(...i):e.pop()}return e}class ys{constructor(e,n){this.modelsModule=e,this.apiClient=n}create(e){return new vs(this.apiClient,this.modelsModule,e.model,e.config,structuredClone(e.history))}}class vs{constructor(e,n,o,i={},l=[]){this.apiClient=e,this.modelsModule=n,this.model=o,this.config=i,this.history=l,this.sendPromise=Promise.resolve(),gs(l)}async sendMessage(e){var n;await this.sendPromise;const o=L(e.message),i=this.modelsModule.generateContent({model:this.model,contents:this.getHistory(!0).concat(o),config:(n=e.config)!==null&&n!==void 0?n:this.config});return this.sendPromise=(async()=>{var l,a,u;const d=await i,c=(a=(l=d.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content,f=d.automaticFunctionCallingHistory,h=this.getHistory(!0).length;let p=[];f!=null&&(p=(u=f.slice(h))!==null&&u!==void 0?u:[]);const m=c?[c]:[];this.recordHistory(o,m,p)})(),await this.sendPromise.catch(()=>{this.sendPromise=Promise.resolve()}),i}async sendMessageStream(e){var n;await this.sendPromise;const o=L(e.message),i=this.modelsModule.generateContentStream({model:this.model,contents:this.getHistory(!0).concat(o),config:(n=e.config)!==null&&n!==void 0?n:this.config});this.sendPromise=i.then(()=>{}).catch(()=>{});const l=await i;return this.processStreamResponse(l,o)}getHistory(e=!1){const n=e?Fn(this.history):this.history;return structuredClone(n)}processStreamResponse(e,n){return J(this,arguments,function*(){var i,l,a,u,d,c;const f=[];try{for(var h=!0,p=$(e),m;m=yield P(p.next()),i=m.done,!i;h=!0){u=m.value,h=!1;const g=u;if(ms(g)){const v=(c=(d=g.candidates)===null||d===void 0?void 0:d[0])===null||c===void 0?void 0:c.content;v!==void 0&&f.push(v)}yield yield P(g)}}catch(g){l={error:g}}finally{try{!h&&!i&&(a=p.return)&&(yield P(a.call(p)))}finally{if(l)throw l.error}}this.recordHistory(n,f)})}recordHistory(e,n,o){let i=[];n.length>0&&n.every(l=>l.role!==void 0)?i=n:i.push({role:"model",parts:[]}),o&&o.length>0?this.history.push(...Fn(o)):this.history.push(e),this.history.push(...i)}}/**
|
|
50
|
+
* @license
|
|
51
|
+
* Copyright 2025 Google LLC
|
|
52
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
53
|
+
*/class me extends Error{constructor(e){super(e.message),this.name="ApiError",this.status=e.status,Object.setPrototypeOf(this,me.prototype)}}/**
|
|
54
|
+
* @license
|
|
55
|
+
* Copyright 2025 Google LLC
|
|
56
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
57
|
+
*/function Ts(t){const e={},n=r(t,["file"]);return n!=null&&s(e,["file"],n),e}function _s(t){const e={},n=r(t,["sdkHttpResponse"]);return n!=null&&s(e,["sdkHttpResponse"],n),e}function Es(t){const e={},n=r(t,["name"]);return n!=null&&s(e,["_url","file"],ao(n)),e}function Cs(t){const e={},n=r(t,["sdkHttpResponse"]);return n!=null&&s(e,["sdkHttpResponse"],n),e}function Ss(t){const e={},n=r(t,["name"]);return n!=null&&s(e,["_url","file"],ao(n)),e}function Is(t){const e={},n=r(t,["uris"]);return n!=null&&s(e,["uris"],n),e}function As(t,e){const n={},o=r(t,["pageSize"]);e!==void 0&&o!=null&&s(e,["_query","pageSize"],o);const i=r(t,["pageToken"]);return e!==void 0&&i!=null&&s(e,["_query","pageToken"],i),n}function Rs(t){const e={},n=r(t,["config"]);return n!=null&&As(n,e),e}function Ps(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["nextPageToken"]);o!=null&&s(e,["nextPageToken"],o);const i=r(t,["files"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>a)),s(e,["files"],l)}return e}function Ms(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["files"]);if(o!=null){let i=o;Array.isArray(i)&&(i=i.map(l=>l)),s(e,["files"],i)}return e}/**
|
|
58
|
+
* @license
|
|
59
|
+
* Copyright 2025 Google LLC
|
|
60
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
61
|
+
*/class ws extends K{constructor(e){super(),this.apiClient=e,this.list=async(n={})=>new j(Y.PAGED_ITEM_FILES,o=>this.listInternal(o),await this.listInternal(n),n)}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(n=>n)}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 n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Rs(e);return l=E("files",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json().then(c=>{const f=c;return f.sdkHttpResponse={headers:d.headers},f})),i.then(d=>{const c=Ps(d),f=new wi;return Object.assign(f,c),f})}}async createInternal(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Ts(e);return l=E("upload/v1beta/files",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>{const c=_s(d),f=new Ni;return Object.assign(f,c),f})}}async get(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Ss(e);return l=E("files/{file}",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>d)}}async delete(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Es(e);return l=E("files/{file}",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json().then(c=>{const f=c;return f.sdkHttpResponse={headers:d.headers},f})),i.then(d=>{const c=Cs(d),f=new Di;return Object.assign(f,c),f})}}async registerFilesInternal(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Is(e);return l=E("files:register",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>{const c=Ms(d),f=new xi;return Object.assign(f,c),f})}}}/**
|
|
62
|
+
* @license
|
|
63
|
+
* Copyright 2025 Google LLC
|
|
64
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
65
|
+
*/function Se(t){const e={},n=r(t,["data"]);if(n!=null&&s(e,["data"],n),r(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const o=r(t,["mimeType"]);return o!=null&&s(e,["mimeType"],o),e}function Ns(t){const e={},n=r(t,["parts"]);if(n!=null){let i=n;Array.isArray(i)&&(i=i.map(l=>Ws(l))),s(e,["parts"],i)}const o=r(t,["role"]);return o!=null&&s(e,["role"],o),e}function Ds(t){const e={};if(r(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const n=r(t,["fileUri"]);n!=null&&s(e,["fileUri"],n);const o=r(t,["mimeType"]);return o!=null&&s(e,["mimeType"],o),e}function xs(t){const e={},n=r(t,["id"]);n!=null&&s(e,["id"],n);const o=r(t,["args"]);o!=null&&s(e,["args"],o);const i=r(t,["name"]);if(i!=null&&s(e,["name"],i),r(t,["partialArgs"])!==void 0)throw new Error("partialArgs parameter is not supported in Gemini API.");if(r(t,["willContinue"])!==void 0)throw new Error("willContinue parameter is not supported in Gemini API.");return e}function Us(t){const e={},n=r(t,["description"]);n!=null&&s(e,["description"],n);const o=r(t,["name"]);o!=null&&s(e,["name"],o);const i=r(t,["parameters"]);i!=null&&s(e,["parameters"],i);const l=r(t,["parametersJsonSchema"]);l!=null&&s(e,["parametersJsonSchema"],l);const a=r(t,["response"]);a!=null&&s(e,["response"],a);const u=r(t,["responseJsonSchema"]);if(u!=null&&s(e,["responseJsonSchema"],u),r(t,["behavior"])!==void 0)throw new Error("behavior parameter is not supported in Vertex AI.");return e}function Ls(t){const e={},n=r(t,["modelSelectionConfig"]);n!=null&&s(e,["modelConfig"],n);const o=r(t,["responseJsonSchema"]);o!=null&&s(e,["responseJsonSchema"],o);const i=r(t,["audioTimestamp"]);i!=null&&s(e,["audioTimestamp"],i);const l=r(t,["candidateCount"]);l!=null&&s(e,["candidateCount"],l);const a=r(t,["enableAffectiveDialog"]);a!=null&&s(e,["enableAffectiveDialog"],a);const u=r(t,["frequencyPenalty"]);u!=null&&s(e,["frequencyPenalty"],u);const d=r(t,["logprobs"]);d!=null&&s(e,["logprobs"],d);const c=r(t,["maxOutputTokens"]);c!=null&&s(e,["maxOutputTokens"],c);const f=r(t,["mediaResolution"]);f!=null&&s(e,["mediaResolution"],f);const h=r(t,["presencePenalty"]);h!=null&&s(e,["presencePenalty"],h);const p=r(t,["responseLogprobs"]);p!=null&&s(e,["responseLogprobs"],p);const m=r(t,["responseMimeType"]);m!=null&&s(e,["responseMimeType"],m);const g=r(t,["responseModalities"]);g!=null&&s(e,["responseModalities"],g);const v=r(t,["responseSchema"]);v!=null&&s(e,["responseSchema"],v);const y=r(t,["routingConfig"]);y!=null&&s(e,["routingConfig"],y);const T=r(t,["seed"]);T!=null&&s(e,["seed"],T);const I=r(t,["speechConfig"]);I!=null&&s(e,["speechConfig"],I);const C=r(t,["stopSequences"]);C!=null&&s(e,["stopSequences"],C);const S=r(t,["temperature"]);S!=null&&s(e,["temperature"],S);const R=r(t,["thinkingConfig"]);R!=null&&s(e,["thinkingConfig"],R);const _=r(t,["topK"]);_!=null&&s(e,["topK"],_);const M=r(t,["topP"]);if(M!=null&&s(e,["topP"],M),r(t,["enableEnhancedCivicAnswers"])!==void 0)throw new Error("enableEnhancedCivicAnswers parameter is not supported in Vertex AI.");return e}function ks(t){const e={};if(r(t,["authConfig"])!==void 0)throw new Error("authConfig parameter is not supported in Gemini API.");const n=r(t,["enableWidget"]);return n!=null&&s(e,["enableWidget"],n),e}function Fs(t){const e={},n=r(t,["searchTypes"]);if(n!=null&&s(e,["searchTypes"],n),r(t,["excludeDomains"])!==void 0)throw new Error("excludeDomains parameter is not supported in Gemini API.");if(r(t,["blockingConfidence"])!==void 0)throw new Error("blockingConfidence parameter is not supported in Gemini API.");const o=r(t,["timeRangeFilter"]);return o!=null&&s(e,["timeRangeFilter"],o),e}function Gs(t,e){const n={},o=r(t,["generationConfig"]);e!==void 0&&o!=null&&s(e,["setup","generationConfig"],o);const i=r(t,["responseModalities"]);e!==void 0&&i!=null&&s(e,["setup","generationConfig","responseModalities"],i);const l=r(t,["temperature"]);e!==void 0&&l!=null&&s(e,["setup","generationConfig","temperature"],l);const a=r(t,["topP"]);e!==void 0&&a!=null&&s(e,["setup","generationConfig","topP"],a);const u=r(t,["topK"]);e!==void 0&&u!=null&&s(e,["setup","generationConfig","topK"],u);const d=r(t,["maxOutputTokens"]);e!==void 0&&d!=null&&s(e,["setup","generationConfig","maxOutputTokens"],d);const c=r(t,["mediaResolution"]);e!==void 0&&c!=null&&s(e,["setup","generationConfig","mediaResolution"],c);const f=r(t,["seed"]);e!==void 0&&f!=null&&s(e,["setup","generationConfig","seed"],f);const h=r(t,["speechConfig"]);e!==void 0&&h!=null&&s(e,["setup","generationConfig","speechConfig"],ft(h));const p=r(t,["thinkingConfig"]);e!==void 0&&p!=null&&s(e,["setup","generationConfig","thinkingConfig"],p);const m=r(t,["enableAffectiveDialog"]);e!==void 0&&m!=null&&s(e,["setup","generationConfig","enableAffectiveDialog"],m);const g=r(t,["systemInstruction"]);e!==void 0&&g!=null&&s(e,["setup","systemInstruction"],Ns(L(g)));const v=r(t,["tools"]);if(e!==void 0&&v!=null){let _=ue(v);Array.isArray(_)&&(_=_.map(M=>Ks(ae(M)))),s(e,["setup","tools"],_)}const y=r(t,["sessionResumption"]);e!==void 0&&y!=null&&s(e,["setup","sessionResumption"],Ys(y));const T=r(t,["inputAudioTranscription"]);e!==void 0&&T!=null&&s(e,["setup","inputAudioTranscription"],T);const I=r(t,["outputAudioTranscription"]);e!==void 0&&I!=null&&s(e,["setup","outputAudioTranscription"],I);const C=r(t,["realtimeInputConfig"]);e!==void 0&&C!=null&&s(e,["setup","realtimeInputConfig"],C);const S=r(t,["contextWindowCompression"]);e!==void 0&&S!=null&&s(e,["setup","contextWindowCompression"],S);const R=r(t,["proactivity"]);if(e!==void 0&&R!=null&&s(e,["setup","proactivity"],R),r(t,["explicitVadSignal"])!==void 0)throw new Error("explicitVadSignal parameter is not supported in Gemini API.");return n}function Vs(t,e){const n={},o=r(t,["generationConfig"]);e!==void 0&&o!=null&&s(e,["setup","generationConfig"],Ls(o));const i=r(t,["responseModalities"]);e!==void 0&&i!=null&&s(e,["setup","generationConfig","responseModalities"],i);const l=r(t,["temperature"]);e!==void 0&&l!=null&&s(e,["setup","generationConfig","temperature"],l);const a=r(t,["topP"]);e!==void 0&&a!=null&&s(e,["setup","generationConfig","topP"],a);const u=r(t,["topK"]);e!==void 0&&u!=null&&s(e,["setup","generationConfig","topK"],u);const d=r(t,["maxOutputTokens"]);e!==void 0&&d!=null&&s(e,["setup","generationConfig","maxOutputTokens"],d);const c=r(t,["mediaResolution"]);e!==void 0&&c!=null&&s(e,["setup","generationConfig","mediaResolution"],c);const f=r(t,["seed"]);e!==void 0&&f!=null&&s(e,["setup","generationConfig","seed"],f);const h=r(t,["speechConfig"]);e!==void 0&&h!=null&&s(e,["setup","generationConfig","speechConfig"],ft(h));const p=r(t,["thinkingConfig"]);e!==void 0&&p!=null&&s(e,["setup","generationConfig","thinkingConfig"],p);const m=r(t,["enableAffectiveDialog"]);e!==void 0&&m!=null&&s(e,["setup","generationConfig","enableAffectiveDialog"],m);const g=r(t,["systemInstruction"]);e!==void 0&&g!=null&&s(e,["setup","systemInstruction"],L(g));const v=r(t,["tools"]);if(e!==void 0&&v!=null){let M=ue(v);Array.isArray(M)&&(M=M.map(D=>zs(ae(D)))),s(e,["setup","tools"],M)}const y=r(t,["sessionResumption"]);e!==void 0&&y!=null&&s(e,["setup","sessionResumption"],y);const T=r(t,["inputAudioTranscription"]);e!==void 0&&T!=null&&s(e,["setup","inputAudioTranscription"],T);const I=r(t,["outputAudioTranscription"]);e!==void 0&&I!=null&&s(e,["setup","outputAudioTranscription"],I);const C=r(t,["realtimeInputConfig"]);e!==void 0&&C!=null&&s(e,["setup","realtimeInputConfig"],C);const S=r(t,["contextWindowCompression"]);e!==void 0&&S!=null&&s(e,["setup","contextWindowCompression"],S);const R=r(t,["proactivity"]);e!==void 0&&R!=null&&s(e,["setup","proactivity"],R);const _=r(t,["explicitVadSignal"]);return e!==void 0&&_!=null&&s(e,["setup","explicitVadSignal"],_),n}function Hs(t,e){const n={},o=r(e,["model"]);o!=null&&s(n,["setup","model"],N(t,o));const i=r(e,["config"]);return i!=null&&s(n,["config"],Gs(i,n)),n}function qs(t,e){const n={},o=r(e,["model"]);o!=null&&s(n,["setup","model"],N(t,o));const i=r(e,["config"]);return i!=null&&s(n,["config"],Vs(i,n)),n}function bs(t){const e={},n=r(t,["musicGenerationConfig"]);return n!=null&&s(e,["musicGenerationConfig"],n),e}function Bs(t){const e={},n=r(t,["weightedPrompts"]);if(n!=null){let o=n;Array.isArray(o)&&(o=o.map(i=>i)),s(e,["weightedPrompts"],o)}return e}function Js(t){const e={},n=r(t,["media"]);if(n!=null){let c=oo(n);Array.isArray(c)&&(c=c.map(f=>Se(f))),s(e,["mediaChunks"],c)}const o=r(t,["audio"]);o!=null&&s(e,["audio"],Se(ro(o)));const i=r(t,["audioStreamEnd"]);i!=null&&s(e,["audioStreamEnd"],i);const l=r(t,["video"]);l!=null&&s(e,["video"],Se(io(l)));const a=r(t,["text"]);a!=null&&s(e,["text"],a);const u=r(t,["activityStart"]);u!=null&&s(e,["activityStart"],u);const d=r(t,["activityEnd"]);return d!=null&&s(e,["activityEnd"],d),e}function $s(t){const e={},n=r(t,["media"]);if(n!=null){let c=oo(n);Array.isArray(c)&&(c=c.map(f=>f)),s(e,["mediaChunks"],c)}const o=r(t,["audio"]);o!=null&&s(e,["audio"],ro(o));const i=r(t,["audioStreamEnd"]);i!=null&&s(e,["audioStreamEnd"],i);const l=r(t,["video"]);l!=null&&s(e,["video"],io(l));const a=r(t,["text"]);a!=null&&s(e,["text"],a);const u=r(t,["activityStart"]);u!=null&&s(e,["activityStart"],u);const d=r(t,["activityEnd"]);return d!=null&&s(e,["activityEnd"],d),e}function Os(t){const e={},n=r(t,["setupComplete"]);n!=null&&s(e,["setupComplete"],n);const o=r(t,["serverContent"]);o!=null&&s(e,["serverContent"],o);const i=r(t,["toolCall"]);i!=null&&s(e,["toolCall"],i);const l=r(t,["toolCallCancellation"]);l!=null&&s(e,["toolCallCancellation"],l);const a=r(t,["usageMetadata"]);a!=null&&s(e,["usageMetadata"],Xs(a));const u=r(t,["goAway"]);u!=null&&s(e,["goAway"],u);const d=r(t,["sessionResumptionUpdate"]);d!=null&&s(e,["sessionResumptionUpdate"],d);const c=r(t,["voiceActivityDetectionSignal"]);c!=null&&s(e,["voiceActivityDetectionSignal"],c);const f=r(t,["voiceActivity"]);return f!=null&&s(e,["voiceActivity"],Qs(f)),e}function Ws(t){const e={},n=r(t,["mediaResolution"]);n!=null&&s(e,["mediaResolution"],n);const o=r(t,["codeExecutionResult"]);o!=null&&s(e,["codeExecutionResult"],o);const i=r(t,["executableCode"]);i!=null&&s(e,["executableCode"],i);const l=r(t,["fileData"]);l!=null&&s(e,["fileData"],Ds(l));const a=r(t,["functionCall"]);a!=null&&s(e,["functionCall"],xs(a));const u=r(t,["functionResponse"]);u!=null&&s(e,["functionResponse"],u);const d=r(t,["inlineData"]);d!=null&&s(e,["inlineData"],Se(d));const c=r(t,["text"]);c!=null&&s(e,["text"],c);const f=r(t,["thought"]);f!=null&&s(e,["thought"],f);const h=r(t,["thoughtSignature"]);h!=null&&s(e,["thoughtSignature"],h);const p=r(t,["videoMetadata"]);return p!=null&&s(e,["videoMetadata"],p),e}function Ys(t){const e={},n=r(t,["handle"]);if(n!=null&&s(e,["handle"],n),r(t,["transparent"])!==void 0)throw new Error("transparent parameter is not supported in Gemini API.");return e}function Ks(t){const e={};if(r(t,["retrieval"])!==void 0)throw new Error("retrieval parameter is not supported in Gemini API.");const n=r(t,["computerUse"]);n!=null&&s(e,["computerUse"],n);const o=r(t,["fileSearch"]);o!=null&&s(e,["fileSearch"],o);const i=r(t,["googleSearch"]);i!=null&&s(e,["googleSearch"],Fs(i));const l=r(t,["codeExecution"]);if(l!=null&&s(e,["codeExecution"],l),r(t,["enterpriseWebSearch"])!==void 0)throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const a=r(t,["functionDeclarations"]);if(a!=null){let h=a;Array.isArray(h)&&(h=h.map(p=>p)),s(e,["functionDeclarations"],h)}const u=r(t,["googleMaps"]);u!=null&&s(e,["googleMaps"],ks(u));const d=r(t,["googleSearchRetrieval"]);d!=null&&s(e,["googleSearchRetrieval"],d);const c=r(t,["urlContext"]);c!=null&&s(e,["urlContext"],c);const f=r(t,["mcpServers"]);if(f!=null){let h=f;Array.isArray(h)&&(h=h.map(p=>p)),s(e,["mcpServers"],h)}return e}function zs(t){const e={},n=r(t,["retrieval"]);n!=null&&s(e,["retrieval"],n);const o=r(t,["computerUse"]);if(o!=null&&s(e,["computerUse"],o),r(t,["fileSearch"])!==void 0)throw new Error("fileSearch parameter is not supported in Vertex AI.");const i=r(t,["googleSearch"]);i!=null&&s(e,["googleSearch"],i);const l=r(t,["codeExecution"]);l!=null&&s(e,["codeExecution"],l);const a=r(t,["enterpriseWebSearch"]);a!=null&&s(e,["enterpriseWebSearch"],a);const u=r(t,["functionDeclarations"]);if(u!=null){let h=u;Array.isArray(h)&&(h=h.map(p=>Us(p))),s(e,["functionDeclarations"],h)}const d=r(t,["googleMaps"]);d!=null&&s(e,["googleMaps"],d);const c=r(t,["googleSearchRetrieval"]);c!=null&&s(e,["googleSearchRetrieval"],c);const f=r(t,["urlContext"]);if(f!=null&&s(e,["urlContext"],f),r(t,["mcpServers"])!==void 0)throw new Error("mcpServers parameter is not supported in Vertex AI.");return e}function Xs(t){const e={},n=r(t,["promptTokenCount"]);n!=null&&s(e,["promptTokenCount"],n);const o=r(t,["cachedContentTokenCount"]);o!=null&&s(e,["cachedContentTokenCount"],o);const i=r(t,["candidatesTokenCount"]);i!=null&&s(e,["responseTokenCount"],i);const l=r(t,["toolUsePromptTokenCount"]);l!=null&&s(e,["toolUsePromptTokenCount"],l);const a=r(t,["thoughtsTokenCount"]);a!=null&&s(e,["thoughtsTokenCount"],a);const u=r(t,["totalTokenCount"]);u!=null&&s(e,["totalTokenCount"],u);const d=r(t,["promptTokensDetails"]);if(d!=null){let m=d;Array.isArray(m)&&(m=m.map(g=>g)),s(e,["promptTokensDetails"],m)}const c=r(t,["cacheTokensDetails"]);if(c!=null){let m=c;Array.isArray(m)&&(m=m.map(g=>g)),s(e,["cacheTokensDetails"],m)}const f=r(t,["candidatesTokensDetails"]);if(f!=null){let m=f;Array.isArray(m)&&(m=m.map(g=>g)),s(e,["responseTokensDetails"],m)}const h=r(t,["toolUsePromptTokensDetails"]);if(h!=null){let m=h;Array.isArray(m)&&(m=m.map(g=>g)),s(e,["toolUsePromptTokensDetails"],m)}const p=r(t,["trafficType"]);return p!=null&&s(e,["trafficType"],p),e}function Qs(t){const e={},n=r(t,["type"]);return n!=null&&s(e,["voiceActivityType"],n),e}/**
|
|
66
|
+
* @license
|
|
67
|
+
* Copyright 2025 Google LLC
|
|
68
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
69
|
+
*/function Zs(t,e){const n={},o=r(t,["data"]);if(o!=null&&s(n,["data"],o),r(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const i=r(t,["mimeType"]);return i!=null&&s(n,["mimeType"],i),n}function js(t,e){const n={},o=r(t,["content"]);o!=null&&s(n,["content"],o);const i=r(t,["citationMetadata"]);i!=null&&s(n,["citationMetadata"],el(i));const l=r(t,["tokenCount"]);l!=null&&s(n,["tokenCount"],l);const a=r(t,["finishReason"]);a!=null&&s(n,["finishReason"],a);const u=r(t,["groundingMetadata"]);u!=null&&s(n,["groundingMetadata"],u);const d=r(t,["avgLogprobs"]);d!=null&&s(n,["avgLogprobs"],d);const c=r(t,["index"]);c!=null&&s(n,["index"],c);const f=r(t,["logprobsResult"]);f!=null&&s(n,["logprobsResult"],f);const h=r(t,["safetyRatings"]);if(h!=null){let m=h;Array.isArray(m)&&(m=m.map(g=>g)),s(n,["safetyRatings"],m)}const p=r(t,["urlContextMetadata"]);return p!=null&&s(n,["urlContextMetadata"],p),n}function el(t,e){const n={},o=r(t,["citationSources"]);if(o!=null){let i=o;Array.isArray(i)&&(i=i.map(l=>l)),s(n,["citations"],i)}return n}function tl(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["contents"]);if(l!=null){let a=b(l);Array.isArray(a)&&(a=a.map(u=>u)),s(o,["contents"],a)}return o}function nl(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["tokensInfo"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>a)),s(n,["tokensInfo"],l)}return n}function ol(t,e){const n={},o=r(t,["values"]);o!=null&&s(n,["values"],o);const i=r(t,["statistics"]);return i!=null&&s(n,["statistics"],il(i)),n}function il(t,e){const n={},o=r(t,["truncated"]);o!=null&&s(n,["truncated"],o);const i=r(t,["token_count"]);return i!=null&&s(n,["tokenCount"],i),n}function ge(t,e){const n={},o=r(t,["parts"]);if(o!=null){let l=o;Array.isArray(l)&&(l=l.map(a=>pa(a))),s(n,["parts"],l)}const i=r(t,["role"]);return i!=null&&s(n,["role"],i),n}function rl(t,e){const n={},o=r(t,["controlType"]);o!=null&&s(n,["controlType"],o);const i=r(t,["enableControlImageComputation"]);return i!=null&&s(n,["computeControl"],i),n}function sl(t,e){const n={};if(r(t,["systemInstruction"])!==void 0)throw new Error("systemInstruction parameter is not supported in Gemini API.");if(r(t,["tools"])!==void 0)throw new Error("tools parameter is not supported in Gemini API.");if(r(t,["generationConfig"])!==void 0)throw new Error("generationConfig parameter is not supported in Gemini API.");return n}function ll(t,e,n){const o={},i=r(t,["systemInstruction"]);e!==void 0&&i!=null&&s(e,["systemInstruction"],L(i));const l=r(t,["tools"]);if(e!==void 0&&l!=null){let u=l;Array.isArray(u)&&(u=u.map(d=>_o(d))),s(e,["tools"],u)}const a=r(t,["generationConfig"]);return e!==void 0&&a!=null&&s(e,["generationConfig"],Zl(a)),o}function al(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["contents"]);if(l!=null){let u=b(l);Array.isArray(u)&&(u=u.map(d=>ge(d))),s(o,["contents"],u)}const a=r(e,["config"]);return a!=null&&sl(a),o}function ul(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["contents"]);if(l!=null){let u=b(l);Array.isArray(u)&&(u=u.map(d=>d)),s(o,["contents"],u)}const a=r(e,["config"]);return a!=null&&ll(a,o),o}function cl(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["totalTokens"]);i!=null&&s(n,["totalTokens"],i);const l=r(t,["cachedContentTokenCount"]);return l!=null&&s(n,["cachedContentTokenCount"],l),n}function dl(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["totalTokens"]);return i!=null&&s(n,["totalTokens"],i),n}function fl(t,e,n){const o={},i=r(e,["model"]);return i!=null&&s(o,["_url","name"],N(t,i)),o}function pl(t,e,n){const o={},i=r(e,["model"]);return i!=null&&s(o,["_url","name"],N(t,i)),o}function hl(t,e){const n={},o=r(t,["sdkHttpResponse"]);return o!=null&&s(n,["sdkHttpResponse"],o),n}function ml(t,e){const n={},o=r(t,["sdkHttpResponse"]);return o!=null&&s(n,["sdkHttpResponse"],o),n}function gl(t,e,n){const o={},i=r(t,["outputGcsUri"]);e!==void 0&&i!=null&&s(e,["parameters","storageUri"],i);const l=r(t,["negativePrompt"]);e!==void 0&&l!=null&&s(e,["parameters","negativePrompt"],l);const a=r(t,["numberOfImages"]);e!==void 0&&a!=null&&s(e,["parameters","sampleCount"],a);const u=r(t,["aspectRatio"]);e!==void 0&&u!=null&&s(e,["parameters","aspectRatio"],u);const d=r(t,["guidanceScale"]);e!==void 0&&d!=null&&s(e,["parameters","guidanceScale"],d);const c=r(t,["seed"]);e!==void 0&&c!=null&&s(e,["parameters","seed"],c);const f=r(t,["safetyFilterLevel"]);e!==void 0&&f!=null&&s(e,["parameters","safetySetting"],f);const h=r(t,["personGeneration"]);e!==void 0&&h!=null&&s(e,["parameters","personGeneration"],h);const p=r(t,["includeSafetyAttributes"]);e!==void 0&&p!=null&&s(e,["parameters","includeSafetyAttributes"],p);const m=r(t,["includeRaiReason"]);e!==void 0&&m!=null&&s(e,["parameters","includeRaiReason"],m);const g=r(t,["language"]);e!==void 0&&g!=null&&s(e,["parameters","language"],g);const v=r(t,["outputMimeType"]);e!==void 0&&v!=null&&s(e,["parameters","outputOptions","mimeType"],v);const y=r(t,["outputCompressionQuality"]);e!==void 0&&y!=null&&s(e,["parameters","outputOptions","compressionQuality"],y);const T=r(t,["addWatermark"]);e!==void 0&&T!=null&&s(e,["parameters","addWatermark"],T);const I=r(t,["labels"]);e!==void 0&&I!=null&&s(e,["labels"],I);const C=r(t,["editMode"]);e!==void 0&&C!=null&&s(e,["parameters","editMode"],C);const S=r(t,["baseSteps"]);return e!==void 0&&S!=null&&s(e,["parameters","editConfig","baseSteps"],S),o}function yl(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["prompt"]);l!=null&&s(o,["instances[0]","prompt"],l);const a=r(e,["referenceImages"]);if(a!=null){let d=a;Array.isArray(d)&&(d=d.map(c=>Ta(c))),s(o,["instances[0]","referenceImages"],d)}const u=r(e,["config"]);return u!=null&&gl(u,o),o}function vl(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["predictions"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>De(a))),s(n,["generatedImages"],l)}return n}function Tl(t,e,n){const o={},i=r(t,["taskType"]);e!==void 0&&i!=null&&s(e,["requests[]","taskType"],i);const l=r(t,["title"]);e!==void 0&&l!=null&&s(e,["requests[]","title"],l);const a=r(t,["outputDimensionality"]);if(e!==void 0&&a!=null&&s(e,["requests[]","outputDimensionality"],a),r(t,["mimeType"])!==void 0)throw new Error("mimeType parameter is not supported in Gemini API.");if(r(t,["autoTruncate"])!==void 0)throw new Error("autoTruncate parameter is not supported in Gemini API.");return o}function _l(t,e,n){const o={};let i=r(n,["embeddingApiType"]);if(i===void 0&&(i="PREDICT"),i==="PREDICT"){const c=r(t,["taskType"]);e!==void 0&&c!=null&&s(e,["instances[]","task_type"],c)}else if(i==="EMBED_CONTENT"){const c=r(t,["taskType"]);e!==void 0&&c!=null&&s(e,["taskType"],c)}let l=r(n,["embeddingApiType"]);if(l===void 0&&(l="PREDICT"),l==="PREDICT"){const c=r(t,["title"]);e!==void 0&&c!=null&&s(e,["instances[]","title"],c)}else if(l==="EMBED_CONTENT"){const c=r(t,["title"]);e!==void 0&&c!=null&&s(e,["title"],c)}let a=r(n,["embeddingApiType"]);if(a===void 0&&(a="PREDICT"),a==="PREDICT"){const c=r(t,["outputDimensionality"]);e!==void 0&&c!=null&&s(e,["parameters","outputDimensionality"],c)}else if(a==="EMBED_CONTENT"){const c=r(t,["outputDimensionality"]);e!==void 0&&c!=null&&s(e,["outputDimensionality"],c)}let u=r(n,["embeddingApiType"]);if(u===void 0&&(u="PREDICT"),u==="PREDICT"){const c=r(t,["mimeType"]);e!==void 0&&c!=null&&s(e,["instances[]","mimeType"],c)}let d=r(n,["embeddingApiType"]);if(d===void 0&&(d="PREDICT"),d==="PREDICT"){const c=r(t,["autoTruncate"]);e!==void 0&&c!=null&&s(e,["parameters","autoTruncate"],c)}else if(d==="EMBED_CONTENT"){const c=r(t,["autoTruncate"]);e!==void 0&&c!=null&&s(e,["autoTruncate"],c)}return o}function El(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["contents"]);if(l!=null){let c=ut(t,l);Array.isArray(c)&&(c=c.map(f=>f)),s(o,["requests[]","content"],c)}const a=r(e,["content"]);a!=null&&ge(L(a));const u=r(e,["config"]);u!=null&&Tl(u,o);const d=r(e,["model"]);return d!==void 0&&s(o,["requests[]","model"],N(t,d)),o}function Cl(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));let l=r(n,["embeddingApiType"]);if(l===void 0&&(l="PREDICT"),l==="PREDICT"){const d=r(e,["contents"]);if(d!=null){let c=ut(t,d);Array.isArray(c)&&(c=c.map(f=>f)),s(o,["instances[]","content"],c)}}let a=r(n,["embeddingApiType"]);if(a===void 0&&(a="PREDICT"),a==="EMBED_CONTENT"){const d=r(e,["content"]);d!=null&&s(o,["content"],L(d))}const u=r(e,["config"]);return u!=null&&_l(u,o,n),o}function Sl(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["embeddings"]);if(i!=null){let a=i;Array.isArray(a)&&(a=a.map(u=>u)),s(n,["embeddings"],a)}const l=r(t,["metadata"]);return l!=null&&s(n,["metadata"],l),n}function Il(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["predictions[]","embeddings"]);if(i!=null){let a=i;Array.isArray(a)&&(a=a.map(u=>ol(u))),s(n,["embeddings"],a)}const l=r(t,["metadata"]);if(l!=null&&s(n,["metadata"],l),e&&r(e,["embeddingApiType"])==="EMBED_CONTENT"){const a=r(t,["embedding"]),u=r(t,["usageMetadata"]),d=r(t,["truncated"]);if(a){const c={};u&&u.promptTokenCount&&(c.tokenCount=u.promptTokenCount),d&&(c.truncated=d),a.statistics=c,s(n,["embeddings"],[a])}}return n}function Al(t,e){const n={},o=r(t,["endpoint"]);o!=null&&s(n,["name"],o);const i=r(t,["deployedModelId"]);return i!=null&&s(n,["deployedModelId"],i),n}function Rl(t,e){const n={};if(r(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const o=r(t,["fileUri"]);o!=null&&s(n,["fileUri"],o);const i=r(t,["mimeType"]);return i!=null&&s(n,["mimeType"],i),n}function Pl(t,e){const n={},o=r(t,["id"]);o!=null&&s(n,["id"],o);const i=r(t,["args"]);i!=null&&s(n,["args"],i);const l=r(t,["name"]);if(l!=null&&s(n,["name"],l),r(t,["partialArgs"])!==void 0)throw new Error("partialArgs parameter is not supported in Gemini API.");if(r(t,["willContinue"])!==void 0)throw new Error("willContinue parameter is not supported in Gemini API.");return n}function Ml(t,e){const n={},o=r(t,["allowedFunctionNames"]);o!=null&&s(n,["allowedFunctionNames"],o);const i=r(t,["mode"]);if(i!=null&&s(n,["mode"],i),r(t,["streamFunctionCallArguments"])!==void 0)throw new Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return n}function wl(t,e){const n={},o=r(t,["description"]);o!=null&&s(n,["description"],o);const i=r(t,["name"]);i!=null&&s(n,["name"],i);const l=r(t,["parameters"]);l!=null&&s(n,["parameters"],l);const a=r(t,["parametersJsonSchema"]);a!=null&&s(n,["parametersJsonSchema"],a);const u=r(t,["response"]);u!=null&&s(n,["response"],u);const d=r(t,["responseJsonSchema"]);if(d!=null&&s(n,["responseJsonSchema"],d),r(t,["behavior"])!==void 0)throw new Error("behavior parameter is not supported in Vertex AI.");return n}function Nl(t,e,n,o){const i={},l=r(e,["systemInstruction"]);n!==void 0&&l!=null&&s(n,["systemInstruction"],ge(L(l)));const a=r(e,["temperature"]);a!=null&&s(i,["temperature"],a);const u=r(e,["topP"]);u!=null&&s(i,["topP"],u);const d=r(e,["topK"]);d!=null&&s(i,["topK"],d);const c=r(e,["candidateCount"]);c!=null&&s(i,["candidateCount"],c);const f=r(e,["maxOutputTokens"]);f!=null&&s(i,["maxOutputTokens"],f);const h=r(e,["stopSequences"]);h!=null&&s(i,["stopSequences"],h);const p=r(e,["responseLogprobs"]);p!=null&&s(i,["responseLogprobs"],p);const m=r(e,["logprobs"]);m!=null&&s(i,["logprobs"],m);const g=r(e,["presencePenalty"]);g!=null&&s(i,["presencePenalty"],g);const v=r(e,["frequencyPenalty"]);v!=null&&s(i,["frequencyPenalty"],v);const y=r(e,["seed"]);y!=null&&s(i,["seed"],y);const T=r(e,["responseMimeType"]);T!=null&&s(i,["responseMimeType"],T);const I=r(e,["responseSchema"]);I!=null&&s(i,["responseSchema"],ct(I));const C=r(e,["responseJsonSchema"]);if(C!=null&&s(i,["responseJsonSchema"],C),r(e,["routingConfig"])!==void 0)throw new Error("routingConfig parameter is not supported in Gemini API.");if(r(e,["modelSelectionConfig"])!==void 0)throw new Error("modelSelectionConfig parameter is not supported in Gemini API.");const S=r(e,["safetySettings"]);if(n!==void 0&&S!=null){let F=S;Array.isArray(F)&&(F=F.map(ee=>_a(ee))),s(n,["safetySettings"],F)}const R=r(e,["tools"]);if(n!==void 0&&R!=null){let F=ue(R);Array.isArray(F)&&(F=F.map(ee=>Pa(ae(ee)))),s(n,["tools"],F)}const _=r(e,["toolConfig"]);if(n!==void 0&&_!=null&&s(n,["toolConfig"],Ra(_)),r(e,["labels"])!==void 0)throw new Error("labels parameter is not supported in Gemini API.");const M=r(e,["cachedContent"]);n!==void 0&&M!=null&&s(n,["cachedContent"],z(t,M));const D=r(e,["responseModalities"]);D!=null&&s(i,["responseModalities"],D);const A=r(e,["mediaResolution"]);A!=null&&s(i,["mediaResolution"],A);const w=r(e,["speechConfig"]);if(w!=null&&s(i,["speechConfig"],dt(w)),r(e,["audioTimestamp"])!==void 0)throw new Error("audioTimestamp parameter is not supported in Gemini API.");const x=r(e,["thinkingConfig"]);x!=null&&s(i,["thinkingConfig"],x);const q=r(e,["imageConfig"]);q!=null&&s(i,["imageConfig"],oa(q));const G=r(e,["enableEnhancedCivicAnswers"]);if(G!=null&&s(i,["enableEnhancedCivicAnswers"],G),r(e,["modelArmorConfig"])!==void 0)throw new Error("modelArmorConfig parameter is not supported in Gemini API.");return i}function Dl(t,e,n,o){const i={},l=r(e,["systemInstruction"]);n!==void 0&&l!=null&&s(n,["systemInstruction"],L(l));const a=r(e,["temperature"]);a!=null&&s(i,["temperature"],a);const u=r(e,["topP"]);u!=null&&s(i,["topP"],u);const d=r(e,["topK"]);d!=null&&s(i,["topK"],d);const c=r(e,["candidateCount"]);c!=null&&s(i,["candidateCount"],c);const f=r(e,["maxOutputTokens"]);f!=null&&s(i,["maxOutputTokens"],f);const h=r(e,["stopSequences"]);h!=null&&s(i,["stopSequences"],h);const p=r(e,["responseLogprobs"]);p!=null&&s(i,["responseLogprobs"],p);const m=r(e,["logprobs"]);m!=null&&s(i,["logprobs"],m);const g=r(e,["presencePenalty"]);g!=null&&s(i,["presencePenalty"],g);const v=r(e,["frequencyPenalty"]);v!=null&&s(i,["frequencyPenalty"],v);const y=r(e,["seed"]);y!=null&&s(i,["seed"],y);const T=r(e,["responseMimeType"]);T!=null&&s(i,["responseMimeType"],T);const I=r(e,["responseSchema"]);I!=null&&s(i,["responseSchema"],ct(I));const C=r(e,["responseJsonSchema"]);C!=null&&s(i,["responseJsonSchema"],C);const S=r(e,["routingConfig"]);S!=null&&s(i,["routingConfig"],S);const R=r(e,["modelSelectionConfig"]);R!=null&&s(i,["modelConfig"],R);const _=r(e,["safetySettings"]);if(n!==void 0&&_!=null){let W=_;Array.isArray(W)&&(W=W.map(Fe=>Fe)),s(n,["safetySettings"],W)}const M=r(e,["tools"]);if(n!==void 0&&M!=null){let W=ue(M);Array.isArray(W)&&(W=W.map(Fe=>_o(ae(Fe)))),s(n,["tools"],W)}const D=r(e,["toolConfig"]);n!==void 0&&D!=null&&s(n,["toolConfig"],D);const A=r(e,["labels"]);n!==void 0&&A!=null&&s(n,["labels"],A);const w=r(e,["cachedContent"]);n!==void 0&&w!=null&&s(n,["cachedContent"],z(t,w));const x=r(e,["responseModalities"]);x!=null&&s(i,["responseModalities"],x);const q=r(e,["mediaResolution"]);q!=null&&s(i,["mediaResolution"],q);const G=r(e,["speechConfig"]);G!=null&&s(i,["speechConfig"],dt(G));const F=r(e,["audioTimestamp"]);F!=null&&s(i,["audioTimestamp"],F);const ee=r(e,["thinkingConfig"]);ee!=null&&s(i,["thinkingConfig"],ee);const gt=r(e,["imageConfig"]);if(gt!=null&&s(i,["imageConfig"],ia(gt)),r(e,["enableEnhancedCivicAnswers"])!==void 0)throw new Error("enableEnhancedCivicAnswers parameter is not supported in Vertex AI.");const yt=r(e,["modelArmorConfig"]);return n!==void 0&&yt!=null&&s(n,["modelArmorConfig"],yt),i}function Gn(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["contents"]);if(l!=null){let u=b(l);Array.isArray(u)&&(u=u.map(d=>ge(d))),s(o,["contents"],u)}const a=r(e,["config"]);return a!=null&&s(o,["generationConfig"],Nl(t,a,o)),o}function Vn(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["contents"]);if(l!=null){let u=b(l);Array.isArray(u)&&(u=u.map(d=>d)),s(o,["contents"],u)}const a=r(e,["config"]);return a!=null&&s(o,["generationConfig"],Dl(t,a,o)),o}function Hn(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["candidates"]);if(i!=null){let c=i;Array.isArray(c)&&(c=c.map(f=>js(f))),s(n,["candidates"],c)}const l=r(t,["modelVersion"]);l!=null&&s(n,["modelVersion"],l);const a=r(t,["promptFeedback"]);a!=null&&s(n,["promptFeedback"],a);const u=r(t,["responseId"]);u!=null&&s(n,["responseId"],u);const d=r(t,["usageMetadata"]);return d!=null&&s(n,["usageMetadata"],d),n}function qn(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["candidates"]);if(i!=null){let f=i;Array.isArray(f)&&(f=f.map(h=>h)),s(n,["candidates"],f)}const l=r(t,["createTime"]);l!=null&&s(n,["createTime"],l);const a=r(t,["modelVersion"]);a!=null&&s(n,["modelVersion"],a);const u=r(t,["promptFeedback"]);u!=null&&s(n,["promptFeedback"],u);const d=r(t,["responseId"]);d!=null&&s(n,["responseId"],d);const c=r(t,["usageMetadata"]);return c!=null&&s(n,["usageMetadata"],c),n}function xl(t,e,n){const o={};if(r(t,["outputGcsUri"])!==void 0)throw new Error("outputGcsUri parameter is not supported in Gemini API.");if(r(t,["negativePrompt"])!==void 0)throw new Error("negativePrompt parameter is not supported in Gemini API.");const i=r(t,["numberOfImages"]);e!==void 0&&i!=null&&s(e,["parameters","sampleCount"],i);const l=r(t,["aspectRatio"]);e!==void 0&&l!=null&&s(e,["parameters","aspectRatio"],l);const a=r(t,["guidanceScale"]);if(e!==void 0&&a!=null&&s(e,["parameters","guidanceScale"],a),r(t,["seed"])!==void 0)throw new Error("seed parameter is not supported in Gemini API.");const u=r(t,["safetyFilterLevel"]);e!==void 0&&u!=null&&s(e,["parameters","safetySetting"],u);const d=r(t,["personGeneration"]);e!==void 0&&d!=null&&s(e,["parameters","personGeneration"],d);const c=r(t,["includeSafetyAttributes"]);e!==void 0&&c!=null&&s(e,["parameters","includeSafetyAttributes"],c);const f=r(t,["includeRaiReason"]);e!==void 0&&f!=null&&s(e,["parameters","includeRaiReason"],f);const h=r(t,["language"]);e!==void 0&&h!=null&&s(e,["parameters","language"],h);const p=r(t,["outputMimeType"]);e!==void 0&&p!=null&&s(e,["parameters","outputOptions","mimeType"],p);const m=r(t,["outputCompressionQuality"]);if(e!==void 0&&m!=null&&s(e,["parameters","outputOptions","compressionQuality"],m),r(t,["addWatermark"])!==void 0)throw new Error("addWatermark parameter is not supported in Gemini API.");if(r(t,["labels"])!==void 0)throw new Error("labels parameter is not supported in Gemini API.");const g=r(t,["imageSize"]);if(e!==void 0&&g!=null&&s(e,["parameters","sampleImageSize"],g),r(t,["enhancePrompt"])!==void 0)throw new Error("enhancePrompt parameter is not supported in Gemini API.");return o}function Ul(t,e,n){const o={},i=r(t,["outputGcsUri"]);e!==void 0&&i!=null&&s(e,["parameters","storageUri"],i);const l=r(t,["negativePrompt"]);e!==void 0&&l!=null&&s(e,["parameters","negativePrompt"],l);const a=r(t,["numberOfImages"]);e!==void 0&&a!=null&&s(e,["parameters","sampleCount"],a);const u=r(t,["aspectRatio"]);e!==void 0&&u!=null&&s(e,["parameters","aspectRatio"],u);const d=r(t,["guidanceScale"]);e!==void 0&&d!=null&&s(e,["parameters","guidanceScale"],d);const c=r(t,["seed"]);e!==void 0&&c!=null&&s(e,["parameters","seed"],c);const f=r(t,["safetyFilterLevel"]);e!==void 0&&f!=null&&s(e,["parameters","safetySetting"],f);const h=r(t,["personGeneration"]);e!==void 0&&h!=null&&s(e,["parameters","personGeneration"],h);const p=r(t,["includeSafetyAttributes"]);e!==void 0&&p!=null&&s(e,["parameters","includeSafetyAttributes"],p);const m=r(t,["includeRaiReason"]);e!==void 0&&m!=null&&s(e,["parameters","includeRaiReason"],m);const g=r(t,["language"]);e!==void 0&&g!=null&&s(e,["parameters","language"],g);const v=r(t,["outputMimeType"]);e!==void 0&&v!=null&&s(e,["parameters","outputOptions","mimeType"],v);const y=r(t,["outputCompressionQuality"]);e!==void 0&&y!=null&&s(e,["parameters","outputOptions","compressionQuality"],y);const T=r(t,["addWatermark"]);e!==void 0&&T!=null&&s(e,["parameters","addWatermark"],T);const I=r(t,["labels"]);e!==void 0&&I!=null&&s(e,["labels"],I);const C=r(t,["imageSize"]);e!==void 0&&C!=null&&s(e,["parameters","sampleImageSize"],C);const S=r(t,["enhancePrompt"]);return e!==void 0&&S!=null&&s(e,["parameters","enhancePrompt"],S),o}function Ll(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["prompt"]);l!=null&&s(o,["instances[0]","prompt"],l);const a=r(e,["config"]);return a!=null&&xl(a,o),o}function kl(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["prompt"]);l!=null&&s(o,["instances[0]","prompt"],l);const a=r(e,["config"]);return a!=null&&Ul(a,o),o}function Fl(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["predictions"]);if(i!=null){let a=i;Array.isArray(a)&&(a=a.map(u=>Kl(u))),s(n,["generatedImages"],a)}const l=r(t,["positivePromptSafetyAttributes"]);return l!=null&&s(n,["positivePromptSafetyAttributes"],vo(l)),n}function Gl(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["predictions"]);if(i!=null){let a=i;Array.isArray(a)&&(a=a.map(u=>De(u))),s(n,["generatedImages"],a)}const l=r(t,["positivePromptSafetyAttributes"]);return l!=null&&s(n,["positivePromptSafetyAttributes"],To(l)),n}function Vl(t,e,n){const o={},i=r(t,["numberOfVideos"]);if(e!==void 0&&i!=null&&s(e,["parameters","sampleCount"],i),r(t,["outputGcsUri"])!==void 0)throw new Error("outputGcsUri parameter is not supported in Gemini API.");if(r(t,["fps"])!==void 0)throw new Error("fps parameter is not supported in Gemini API.");const l=r(t,["durationSeconds"]);if(e!==void 0&&l!=null&&s(e,["parameters","durationSeconds"],l),r(t,["seed"])!==void 0)throw new Error("seed parameter is not supported in Gemini API.");const a=r(t,["aspectRatio"]);e!==void 0&&a!=null&&s(e,["parameters","aspectRatio"],a);const u=r(t,["resolution"]);e!==void 0&&u!=null&&s(e,["parameters","resolution"],u);const d=r(t,["personGeneration"]);if(e!==void 0&&d!=null&&s(e,["parameters","personGeneration"],d),r(t,["pubsubTopic"])!==void 0)throw new Error("pubsubTopic parameter is not supported in Gemini API.");const c=r(t,["negativePrompt"]);e!==void 0&&c!=null&&s(e,["parameters","negativePrompt"],c);const f=r(t,["enhancePrompt"]);if(e!==void 0&&f!=null&&s(e,["parameters","enhancePrompt"],f),r(t,["generateAudio"])!==void 0)throw new Error("generateAudio parameter is not supported in Gemini API.");const h=r(t,["lastFrame"]);e!==void 0&&h!=null&&s(e,["instances[0]","lastFrame"],xe(h));const p=r(t,["referenceImages"]);if(e!==void 0&&p!=null){let m=p;Array.isArray(m)&&(m=m.map(g=>qa(g))),s(e,["instances[0]","referenceImages"],m)}if(r(t,["mask"])!==void 0)throw new Error("mask parameter is not supported in Gemini API.");if(r(t,["compressionQuality"])!==void 0)throw new Error("compressionQuality parameter is not supported in Gemini API.");return o}function Hl(t,e,n){const o={},i=r(t,["numberOfVideos"]);e!==void 0&&i!=null&&s(e,["parameters","sampleCount"],i);const l=r(t,["outputGcsUri"]);e!==void 0&&l!=null&&s(e,["parameters","storageUri"],l);const a=r(t,["fps"]);e!==void 0&&a!=null&&s(e,["parameters","fps"],a);const u=r(t,["durationSeconds"]);e!==void 0&&u!=null&&s(e,["parameters","durationSeconds"],u);const d=r(t,["seed"]);e!==void 0&&d!=null&&s(e,["parameters","seed"],d);const c=r(t,["aspectRatio"]);e!==void 0&&c!=null&&s(e,["parameters","aspectRatio"],c);const f=r(t,["resolution"]);e!==void 0&&f!=null&&s(e,["parameters","resolution"],f);const h=r(t,["personGeneration"]);e!==void 0&&h!=null&&s(e,["parameters","personGeneration"],h);const p=r(t,["pubsubTopic"]);e!==void 0&&p!=null&&s(e,["parameters","pubsubTopic"],p);const m=r(t,["negativePrompt"]);e!==void 0&&m!=null&&s(e,["parameters","negativePrompt"],m);const g=r(t,["enhancePrompt"]);e!==void 0&&g!=null&&s(e,["parameters","enhancePrompt"],g);const v=r(t,["generateAudio"]);e!==void 0&&v!=null&&s(e,["parameters","generateAudio"],v);const y=r(t,["lastFrame"]);e!==void 0&&y!=null&&s(e,["instances[0]","lastFrame"],O(y));const T=r(t,["referenceImages"]);if(e!==void 0&&T!=null){let S=T;Array.isArray(S)&&(S=S.map(R=>ba(R))),s(e,["instances[0]","referenceImages"],S)}const I=r(t,["mask"]);e!==void 0&&I!=null&&s(e,["instances[0]","mask"],Ha(I));const C=r(t,["compressionQuality"]);return e!==void 0&&C!=null&&s(e,["parameters","compressionQuality"],C),o}function ql(t,e){const n={},o=r(t,["name"]);o!=null&&s(n,["name"],o);const i=r(t,["metadata"]);i!=null&&s(n,["metadata"],i);const l=r(t,["done"]);l!=null&&s(n,["done"],l);const a=r(t,["error"]);a!=null&&s(n,["error"],a);const u=r(t,["response","generateVideoResponse"]);return u!=null&&s(n,["response"],$l(u)),n}function bl(t,e){const n={},o=r(t,["name"]);o!=null&&s(n,["name"],o);const i=r(t,["metadata"]);i!=null&&s(n,["metadata"],i);const l=r(t,["done"]);l!=null&&s(n,["done"],l);const a=r(t,["error"]);a!=null&&s(n,["error"],a);const u=r(t,["response"]);return u!=null&&s(n,["response"],Ol(u)),n}function Bl(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["prompt"]);l!=null&&s(o,["instances[0]","prompt"],l);const a=r(e,["image"]);a!=null&&s(o,["instances[0]","image"],xe(a));const u=r(e,["video"]);u!=null&&s(o,["instances[0]","video"],Eo(u));const d=r(e,["source"]);d!=null&&Wl(d,o);const c=r(e,["config"]);return c!=null&&Vl(c,o),o}function Jl(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["prompt"]);l!=null&&s(o,["instances[0]","prompt"],l);const a=r(e,["image"]);a!=null&&s(o,["instances[0]","image"],O(a));const u=r(e,["video"]);u!=null&&s(o,["instances[0]","video"],Co(u));const d=r(e,["source"]);d!=null&&Yl(d,o);const c=r(e,["config"]);return c!=null&&Hl(c,o),o}function $l(t,e){const n={},o=r(t,["generatedSamples"]);if(o!=null){let a=o;Array.isArray(a)&&(a=a.map(u=>Xl(u))),s(n,["generatedVideos"],a)}const i=r(t,["raiMediaFilteredCount"]);i!=null&&s(n,["raiMediaFilteredCount"],i);const l=r(t,["raiMediaFilteredReasons"]);return l!=null&&s(n,["raiMediaFilteredReasons"],l),n}function Ol(t,e){const n={},o=r(t,["videos"]);if(o!=null){let a=o;Array.isArray(a)&&(a=a.map(u=>Ql(u))),s(n,["generatedVideos"],a)}const i=r(t,["raiMediaFilteredCount"]);i!=null&&s(n,["raiMediaFilteredCount"],i);const l=r(t,["raiMediaFilteredReasons"]);return l!=null&&s(n,["raiMediaFilteredReasons"],l),n}function Wl(t,e,n){const o={},i=r(t,["prompt"]);e!==void 0&&i!=null&&s(e,["instances[0]","prompt"],i);const l=r(t,["image"]);e!==void 0&&l!=null&&s(e,["instances[0]","image"],xe(l));const a=r(t,["video"]);return e!==void 0&&a!=null&&s(e,["instances[0]","video"],Eo(a)),o}function Yl(t,e,n){const o={},i=r(t,["prompt"]);e!==void 0&&i!=null&&s(e,["instances[0]","prompt"],i);const l=r(t,["image"]);e!==void 0&&l!=null&&s(e,["instances[0]","image"],O(l));const a=r(t,["video"]);return e!==void 0&&a!=null&&s(e,["instances[0]","video"],Co(a)),o}function Kl(t,e){const n={},o=r(t,["_self"]);o!=null&&s(n,["image"],ra(o));const i=r(t,["raiFilteredReason"]);i!=null&&s(n,["raiFilteredReason"],i);const l=r(t,["_self"]);return l!=null&&s(n,["safetyAttributes"],vo(l)),n}function De(t,e){const n={},o=r(t,["_self"]);o!=null&&s(n,["image"],yo(o));const i=r(t,["raiFilteredReason"]);i!=null&&s(n,["raiFilteredReason"],i);const l=r(t,["_self"]);l!=null&&s(n,["safetyAttributes"],To(l));const a=r(t,["prompt"]);return a!=null&&s(n,["enhancedPrompt"],a),n}function zl(t,e){const n={},o=r(t,["_self"]);o!=null&&s(n,["mask"],yo(o));const i=r(t,["labels"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>a)),s(n,["labels"],l)}return n}function Xl(t,e){const n={},o=r(t,["video"]);return o!=null&&s(n,["video"],Ga(o)),n}function Ql(t,e){const n={},o=r(t,["_self"]);return o!=null&&s(n,["video"],Va(o)),n}function Zl(t,e){const n={},o=r(t,["modelSelectionConfig"]);o!=null&&s(n,["modelConfig"],o);const i=r(t,["responseJsonSchema"]);i!=null&&s(n,["responseJsonSchema"],i);const l=r(t,["audioTimestamp"]);l!=null&&s(n,["audioTimestamp"],l);const a=r(t,["candidateCount"]);a!=null&&s(n,["candidateCount"],a);const u=r(t,["enableAffectiveDialog"]);u!=null&&s(n,["enableAffectiveDialog"],u);const d=r(t,["frequencyPenalty"]);d!=null&&s(n,["frequencyPenalty"],d);const c=r(t,["logprobs"]);c!=null&&s(n,["logprobs"],c);const f=r(t,["maxOutputTokens"]);f!=null&&s(n,["maxOutputTokens"],f);const h=r(t,["mediaResolution"]);h!=null&&s(n,["mediaResolution"],h);const p=r(t,["presencePenalty"]);p!=null&&s(n,["presencePenalty"],p);const m=r(t,["responseLogprobs"]);m!=null&&s(n,["responseLogprobs"],m);const g=r(t,["responseMimeType"]);g!=null&&s(n,["responseMimeType"],g);const v=r(t,["responseModalities"]);v!=null&&s(n,["responseModalities"],v);const y=r(t,["responseSchema"]);y!=null&&s(n,["responseSchema"],y);const T=r(t,["routingConfig"]);T!=null&&s(n,["routingConfig"],T);const I=r(t,["seed"]);I!=null&&s(n,["seed"],I);const C=r(t,["speechConfig"]);C!=null&&s(n,["speechConfig"],C);const S=r(t,["stopSequences"]);S!=null&&s(n,["stopSequences"],S);const R=r(t,["temperature"]);R!=null&&s(n,["temperature"],R);const _=r(t,["thinkingConfig"]);_!=null&&s(n,["thinkingConfig"],_);const M=r(t,["topK"]);M!=null&&s(n,["topK"],M);const D=r(t,["topP"]);if(D!=null&&s(n,["topP"],D),r(t,["enableEnhancedCivicAnswers"])!==void 0)throw new Error("enableEnhancedCivicAnswers parameter is not supported in Vertex AI.");return n}function jl(t,e,n){const o={},i=r(e,["model"]);return i!=null&&s(o,["_url","name"],N(t,i)),o}function ea(t,e,n){const o={},i=r(e,["model"]);return i!=null&&s(o,["_url","name"],N(t,i)),o}function ta(t,e){const n={};if(r(t,["authConfig"])!==void 0)throw new Error("authConfig parameter is not supported in Gemini API.");const o=r(t,["enableWidget"]);return o!=null&&s(n,["enableWidget"],o),n}function na(t,e){const n={},o=r(t,["searchTypes"]);if(o!=null&&s(n,["searchTypes"],o),r(t,["excludeDomains"])!==void 0)throw new Error("excludeDomains parameter is not supported in Gemini API.");if(r(t,["blockingConfidence"])!==void 0)throw new Error("blockingConfidence parameter is not supported in Gemini API.");const i=r(t,["timeRangeFilter"]);return i!=null&&s(n,["timeRangeFilter"],i),n}function oa(t,e){const n={},o=r(t,["aspectRatio"]);o!=null&&s(n,["aspectRatio"],o);const i=r(t,["imageSize"]);if(i!=null&&s(n,["imageSize"],i),r(t,["personGeneration"])!==void 0)throw new Error("personGeneration parameter is not supported in Gemini API.");if(r(t,["prominentPeople"])!==void 0)throw new Error("prominentPeople parameter is not supported in Gemini API.");if(r(t,["outputMimeType"])!==void 0)throw new Error("outputMimeType parameter is not supported in Gemini API.");if(r(t,["outputCompressionQuality"])!==void 0)throw new Error("outputCompressionQuality parameter is not supported in Gemini API.");return n}function ia(t,e){const n={},o=r(t,["aspectRatio"]);o!=null&&s(n,["aspectRatio"],o);const i=r(t,["imageSize"]);i!=null&&s(n,["imageSize"],i);const l=r(t,["personGeneration"]);l!=null&&s(n,["personGeneration"],l);const a=r(t,["prominentPeople"]);a!=null&&s(n,["prominentPeople"],a);const u=r(t,["outputMimeType"]);u!=null&&s(n,["imageOutputOptions","mimeType"],u);const d=r(t,["outputCompressionQuality"]);return d!=null&&s(n,["imageOutputOptions","compressionQuality"],d),n}function ra(t,e){const n={},o=r(t,["bytesBase64Encoded"]);o!=null&&s(n,["imageBytes"],Q(o));const i=r(t,["mimeType"]);return i!=null&&s(n,["mimeType"],i),n}function yo(t,e){const n={},o=r(t,["gcsUri"]);o!=null&&s(n,["gcsUri"],o);const i=r(t,["bytesBase64Encoded"]);i!=null&&s(n,["imageBytes"],Q(i));const l=r(t,["mimeType"]);return l!=null&&s(n,["mimeType"],l),n}function xe(t,e){const n={};if(r(t,["gcsUri"])!==void 0)throw new Error("gcsUri parameter is not supported in Gemini API.");const o=r(t,["imageBytes"]);o!=null&&s(n,["bytesBase64Encoded"],Q(o));const i=r(t,["mimeType"]);return i!=null&&s(n,["mimeType"],i),n}function O(t,e){const n={},o=r(t,["gcsUri"]);o!=null&&s(n,["gcsUri"],o);const i=r(t,["imageBytes"]);i!=null&&s(n,["bytesBase64Encoded"],Q(i));const l=r(t,["mimeType"]);return l!=null&&s(n,["mimeType"],l),n}function sa(t,e,n,o){const i={},l=r(e,["pageSize"]);n!==void 0&&l!=null&&s(n,["_query","pageSize"],l);const a=r(e,["pageToken"]);n!==void 0&&a!=null&&s(n,["_query","pageToken"],a);const u=r(e,["filter"]);n!==void 0&&u!=null&&s(n,["_query","filter"],u);const d=r(e,["queryBase"]);return n!==void 0&&d!=null&&s(n,["_url","models_url"],uo(t,d)),i}function la(t,e,n,o){const i={},l=r(e,["pageSize"]);n!==void 0&&l!=null&&s(n,["_query","pageSize"],l);const a=r(e,["pageToken"]);n!==void 0&&a!=null&&s(n,["_query","pageToken"],a);const u=r(e,["filter"]);n!==void 0&&u!=null&&s(n,["_query","filter"],u);const d=r(e,["queryBase"]);return n!==void 0&&d!=null&&s(n,["_url","models_url"],uo(t,d)),i}function aa(t,e,n){const o={},i=r(e,["config"]);return i!=null&&sa(t,i,o),o}function ua(t,e,n){const o={},i=r(e,["config"]);return i!=null&&la(t,i,o),o}function ca(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["nextPageToken"]);i!=null&&s(n,["nextPageToken"],i);const l=r(t,["_self"]);if(l!=null){let a=co(l);Array.isArray(a)&&(a=a.map(u=>Qe(u))),s(n,["models"],a)}return n}function da(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["nextPageToken"]);i!=null&&s(n,["nextPageToken"],i);const l=r(t,["_self"]);if(l!=null){let a=co(l);Array.isArray(a)&&(a=a.map(u=>Ze(u))),s(n,["models"],a)}return n}function fa(t,e){const n={},o=r(t,["maskMode"]);o!=null&&s(n,["maskMode"],o);const i=r(t,["segmentationClasses"]);i!=null&&s(n,["maskClasses"],i);const l=r(t,["maskDilation"]);return l!=null&&s(n,["dilation"],l),n}function Qe(t,e){const n={},o=r(t,["name"]);o!=null&&s(n,["name"],o);const i=r(t,["displayName"]);i!=null&&s(n,["displayName"],i);const l=r(t,["description"]);l!=null&&s(n,["description"],l);const a=r(t,["version"]);a!=null&&s(n,["version"],a);const u=r(t,["_self"]);u!=null&&s(n,["tunedModelInfo"],Ma(u));const d=r(t,["inputTokenLimit"]);d!=null&&s(n,["inputTokenLimit"],d);const c=r(t,["outputTokenLimit"]);c!=null&&s(n,["outputTokenLimit"],c);const f=r(t,["supportedGenerationMethods"]);f!=null&&s(n,["supportedActions"],f);const h=r(t,["temperature"]);h!=null&&s(n,["temperature"],h);const p=r(t,["maxTemperature"]);p!=null&&s(n,["maxTemperature"],p);const m=r(t,["topP"]);m!=null&&s(n,["topP"],m);const g=r(t,["topK"]);g!=null&&s(n,["topK"],g);const v=r(t,["thinking"]);return v!=null&&s(n,["thinking"],v),n}function Ze(t,e){const n={},o=r(t,["name"]);o!=null&&s(n,["name"],o);const i=r(t,["displayName"]);i!=null&&s(n,["displayName"],i);const l=r(t,["description"]);l!=null&&s(n,["description"],l);const a=r(t,["versionId"]);a!=null&&s(n,["version"],a);const u=r(t,["deployedModels"]);if(u!=null){let p=u;Array.isArray(p)&&(p=p.map(m=>Al(m))),s(n,["endpoints"],p)}const d=r(t,["labels"]);d!=null&&s(n,["labels"],d);const c=r(t,["_self"]);c!=null&&s(n,["tunedModelInfo"],wa(c));const f=r(t,["defaultCheckpointId"]);f!=null&&s(n,["defaultCheckpointId"],f);const h=r(t,["checkpoints"]);if(h!=null){let p=h;Array.isArray(p)&&(p=p.map(m=>m)),s(n,["checkpoints"],p)}return n}function pa(t,e){const n={},o=r(t,["mediaResolution"]);o!=null&&s(n,["mediaResolution"],o);const i=r(t,["codeExecutionResult"]);i!=null&&s(n,["codeExecutionResult"],i);const l=r(t,["executableCode"]);l!=null&&s(n,["executableCode"],l);const a=r(t,["fileData"]);a!=null&&s(n,["fileData"],Rl(a));const u=r(t,["functionCall"]);u!=null&&s(n,["functionCall"],Pl(u));const d=r(t,["functionResponse"]);d!=null&&s(n,["functionResponse"],d);const c=r(t,["inlineData"]);c!=null&&s(n,["inlineData"],Zs(c));const f=r(t,["text"]);f!=null&&s(n,["text"],f);const h=r(t,["thought"]);h!=null&&s(n,["thought"],h);const p=r(t,["thoughtSignature"]);p!=null&&s(n,["thoughtSignature"],p);const m=r(t,["videoMetadata"]);return m!=null&&s(n,["videoMetadata"],m),n}function ha(t,e){const n={},o=r(t,["productImage"]);return o!=null&&s(n,["image"],O(o)),n}function ma(t,e,n){const o={},i=r(t,["numberOfImages"]);e!==void 0&&i!=null&&s(e,["parameters","sampleCount"],i);const l=r(t,["baseSteps"]);e!==void 0&&l!=null&&s(e,["parameters","baseSteps"],l);const a=r(t,["outputGcsUri"]);e!==void 0&&a!=null&&s(e,["parameters","storageUri"],a);const u=r(t,["seed"]);e!==void 0&&u!=null&&s(e,["parameters","seed"],u);const d=r(t,["safetyFilterLevel"]);e!==void 0&&d!=null&&s(e,["parameters","safetySetting"],d);const c=r(t,["personGeneration"]);e!==void 0&&c!=null&&s(e,["parameters","personGeneration"],c);const f=r(t,["addWatermark"]);e!==void 0&&f!=null&&s(e,["parameters","addWatermark"],f);const h=r(t,["outputMimeType"]);e!==void 0&&h!=null&&s(e,["parameters","outputOptions","mimeType"],h);const p=r(t,["outputCompressionQuality"]);e!==void 0&&p!=null&&s(e,["parameters","outputOptions","compressionQuality"],p);const m=r(t,["enhancePrompt"]);e!==void 0&&m!=null&&s(e,["parameters","enhancePrompt"],m);const g=r(t,["labels"]);return e!==void 0&&g!=null&&s(e,["labels"],g),o}function ga(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["source"]);l!=null&&va(l,o);const a=r(e,["config"]);return a!=null&&ma(a,o),o}function ya(t,e){const n={},o=r(t,["predictions"]);if(o!=null){let i=o;Array.isArray(i)&&(i=i.map(l=>De(l))),s(n,["generatedImages"],i)}return n}function va(t,e,n){const o={},i=r(t,["prompt"]);e!==void 0&&i!=null&&s(e,["instances[0]","prompt"],i);const l=r(t,["personImage"]);e!==void 0&&l!=null&&s(e,["instances[0]","personImage","image"],O(l));const a=r(t,["productImages"]);if(e!==void 0&&a!=null){let u=a;Array.isArray(u)&&(u=u.map(d=>ha(d))),s(e,["instances[0]","productImages"],u)}return o}function Ta(t,e){const n={},o=r(t,["referenceImage"]);o!=null&&s(n,["referenceImage"],O(o));const i=r(t,["referenceId"]);i!=null&&s(n,["referenceId"],i);const l=r(t,["referenceType"]);l!=null&&s(n,["referenceType"],l);const a=r(t,["maskImageConfig"]);a!=null&&s(n,["maskImageConfig"],fa(a));const u=r(t,["controlImageConfig"]);u!=null&&s(n,["controlImageConfig"],rl(u));const d=r(t,["styleImageConfig"]);d!=null&&s(n,["styleImageConfig"],d);const c=r(t,["subjectImageConfig"]);return c!=null&&s(n,["subjectImageConfig"],c),n}function vo(t,e){const n={},o=r(t,["safetyAttributes","categories"]);o!=null&&s(n,["categories"],o);const i=r(t,["safetyAttributes","scores"]);i!=null&&s(n,["scores"],i);const l=r(t,["contentType"]);return l!=null&&s(n,["contentType"],l),n}function To(t,e){const n={},o=r(t,["safetyAttributes","categories"]);o!=null&&s(n,["categories"],o);const i=r(t,["safetyAttributes","scores"]);i!=null&&s(n,["scores"],i);const l=r(t,["contentType"]);return l!=null&&s(n,["contentType"],l),n}function _a(t,e){const n={},o=r(t,["category"]);if(o!=null&&s(n,["category"],o),r(t,["method"])!==void 0)throw new Error("method parameter is not supported in Gemini API.");const i=r(t,["threshold"]);return i!=null&&s(n,["threshold"],i),n}function Ea(t,e){const n={},o=r(t,["image"]);return o!=null&&s(n,["image"],O(o)),n}function Ca(t,e,n){const o={},i=r(t,["mode"]);e!==void 0&&i!=null&&s(e,["parameters","mode"],i);const l=r(t,["maxPredictions"]);e!==void 0&&l!=null&&s(e,["parameters","maxPredictions"],l);const a=r(t,["confidenceThreshold"]);e!==void 0&&a!=null&&s(e,["parameters","confidenceThreshold"],a);const u=r(t,["maskDilation"]);e!==void 0&&u!=null&&s(e,["parameters","maskDilation"],u);const d=r(t,["binaryColorThreshold"]);e!==void 0&&d!=null&&s(e,["parameters","binaryColorThreshold"],d);const c=r(t,["labels"]);return e!==void 0&&c!=null&&s(e,["labels"],c),o}function Sa(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["source"]);l!=null&&Aa(l,o);const a=r(e,["config"]);return a!=null&&Ca(a,o),o}function Ia(t,e){const n={},o=r(t,["predictions"]);if(o!=null){let i=o;Array.isArray(i)&&(i=i.map(l=>zl(l))),s(n,["generatedMasks"],i)}return n}function Aa(t,e,n){const o={},i=r(t,["prompt"]);e!==void 0&&i!=null&&s(e,["instances[0]","prompt"],i);const l=r(t,["image"]);e!==void 0&&l!=null&&s(e,["instances[0]","image"],O(l));const a=r(t,["scribbleImage"]);return e!==void 0&&a!=null&&s(e,["instances[0]","scribble"],Ea(a)),o}function Ra(t,e){const n={},o=r(t,["retrievalConfig"]);o!=null&&s(n,["retrievalConfig"],o);const i=r(t,["functionCallingConfig"]);return i!=null&&s(n,["functionCallingConfig"],Ml(i)),n}function Pa(t,e){const n={};if(r(t,["retrieval"])!==void 0)throw new Error("retrieval parameter is not supported in Gemini API.");const o=r(t,["computerUse"]);o!=null&&s(n,["computerUse"],o);const i=r(t,["fileSearch"]);i!=null&&s(n,["fileSearch"],i);const l=r(t,["googleSearch"]);l!=null&&s(n,["googleSearch"],na(l));const a=r(t,["codeExecution"]);if(a!=null&&s(n,["codeExecution"],a),r(t,["enterpriseWebSearch"])!==void 0)throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const u=r(t,["functionDeclarations"]);if(u!=null){let p=u;Array.isArray(p)&&(p=p.map(m=>m)),s(n,["functionDeclarations"],p)}const d=r(t,["googleMaps"]);d!=null&&s(n,["googleMaps"],ta(d));const c=r(t,["googleSearchRetrieval"]);c!=null&&s(n,["googleSearchRetrieval"],c);const f=r(t,["urlContext"]);f!=null&&s(n,["urlContext"],f);const h=r(t,["mcpServers"]);if(h!=null){let p=h;Array.isArray(p)&&(p=p.map(m=>m)),s(n,["mcpServers"],p)}return n}function _o(t,e){const n={},o=r(t,["retrieval"]);o!=null&&s(n,["retrieval"],o);const i=r(t,["computerUse"]);if(i!=null&&s(n,["computerUse"],i),r(t,["fileSearch"])!==void 0)throw new Error("fileSearch parameter is not supported in Vertex AI.");const l=r(t,["googleSearch"]);l!=null&&s(n,["googleSearch"],l);const a=r(t,["codeExecution"]);a!=null&&s(n,["codeExecution"],a);const u=r(t,["enterpriseWebSearch"]);u!=null&&s(n,["enterpriseWebSearch"],u);const d=r(t,["functionDeclarations"]);if(d!=null){let p=d;Array.isArray(p)&&(p=p.map(m=>wl(m))),s(n,["functionDeclarations"],p)}const c=r(t,["googleMaps"]);c!=null&&s(n,["googleMaps"],c);const f=r(t,["googleSearchRetrieval"]);f!=null&&s(n,["googleSearchRetrieval"],f);const h=r(t,["urlContext"]);if(h!=null&&s(n,["urlContext"],h),r(t,["mcpServers"])!==void 0)throw new Error("mcpServers parameter is not supported in Vertex AI.");return n}function Ma(t,e){const n={},o=r(t,["baseModel"]);o!=null&&s(n,["baseModel"],o);const i=r(t,["createTime"]);i!=null&&s(n,["createTime"],i);const l=r(t,["updateTime"]);return l!=null&&s(n,["updateTime"],l),n}function wa(t,e){const n={},o=r(t,["labels","google-vertex-llm-tuning-base-model-id"]);o!=null&&s(n,["baseModel"],o);const i=r(t,["createTime"]);i!=null&&s(n,["createTime"],i);const l=r(t,["updateTime"]);return l!=null&&s(n,["updateTime"],l),n}function Na(t,e,n){const o={},i=r(t,["displayName"]);e!==void 0&&i!=null&&s(e,["displayName"],i);const l=r(t,["description"]);e!==void 0&&l!=null&&s(e,["description"],l);const a=r(t,["defaultCheckpointId"]);return e!==void 0&&a!=null&&s(e,["defaultCheckpointId"],a),o}function Da(t,e,n){const o={},i=r(t,["displayName"]);e!==void 0&&i!=null&&s(e,["displayName"],i);const l=r(t,["description"]);e!==void 0&&l!=null&&s(e,["description"],l);const a=r(t,["defaultCheckpointId"]);return e!==void 0&&a!=null&&s(e,["defaultCheckpointId"],a),o}function xa(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","name"],N(t,i));const l=r(e,["config"]);return l!=null&&Na(l,o),o}function Ua(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["config"]);return l!=null&&Da(l,o),o}function La(t,e,n){const o={},i=r(t,["outputGcsUri"]);e!==void 0&&i!=null&&s(e,["parameters","storageUri"],i);const l=r(t,["safetyFilterLevel"]);e!==void 0&&l!=null&&s(e,["parameters","safetySetting"],l);const a=r(t,["personGeneration"]);e!==void 0&&a!=null&&s(e,["parameters","personGeneration"],a);const u=r(t,["includeRaiReason"]);e!==void 0&&u!=null&&s(e,["parameters","includeRaiReason"],u);const d=r(t,["outputMimeType"]);e!==void 0&&d!=null&&s(e,["parameters","outputOptions","mimeType"],d);const c=r(t,["outputCompressionQuality"]);e!==void 0&&c!=null&&s(e,["parameters","outputOptions","compressionQuality"],c);const f=r(t,["enhanceInputImage"]);e!==void 0&&f!=null&&s(e,["parameters","upscaleConfig","enhanceInputImage"],f);const h=r(t,["imagePreservationFactor"]);e!==void 0&&h!=null&&s(e,["parameters","upscaleConfig","imagePreservationFactor"],h);const p=r(t,["labels"]);e!==void 0&&p!=null&&s(e,["labels"],p);const m=r(t,["numberOfImages"]);e!==void 0&&m!=null&&s(e,["parameters","sampleCount"],m);const g=r(t,["mode"]);return e!==void 0&&g!=null&&s(e,["parameters","mode"],g),o}function ka(t,e,n){const o={},i=r(e,["model"]);i!=null&&s(o,["_url","model"],N(t,i));const l=r(e,["image"]);l!=null&&s(o,["instances[0]","image"],O(l));const a=r(e,["upscaleFactor"]);a!=null&&s(o,["parameters","upscaleConfig","upscaleFactor"],a);const u=r(e,["config"]);return u!=null&&La(u,o),o}function Fa(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["predictions"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>De(a))),s(n,["generatedImages"],l)}return n}function Ga(t,e){const n={},o=r(t,["uri"]);o!=null&&s(n,["uri"],o);const i=r(t,["encodedVideo"]);i!=null&&s(n,["videoBytes"],Q(i));const l=r(t,["encoding"]);return l!=null&&s(n,["mimeType"],l),n}function Va(t,e){const n={},o=r(t,["gcsUri"]);o!=null&&s(n,["uri"],o);const i=r(t,["bytesBase64Encoded"]);i!=null&&s(n,["videoBytes"],Q(i));const l=r(t,["mimeType"]);return l!=null&&s(n,["mimeType"],l),n}function Ha(t,e){const n={},o=r(t,["image"]);o!=null&&s(n,["_self"],O(o));const i=r(t,["maskMode"]);return i!=null&&s(n,["maskMode"],i),n}function qa(t,e){const n={},o=r(t,["image"]);o!=null&&s(n,["image"],xe(o));const i=r(t,["referenceType"]);return i!=null&&s(n,["referenceType"],i),n}function ba(t,e){const n={},o=r(t,["image"]);o!=null&&s(n,["image"],O(o));const i=r(t,["referenceType"]);return i!=null&&s(n,["referenceType"],i),n}function Eo(t,e){const n={},o=r(t,["uri"]);o!=null&&s(n,["uri"],o);const i=r(t,["videoBytes"]);i!=null&&s(n,["encodedVideo"],Q(i));const l=r(t,["mimeType"]);return l!=null&&s(n,["encoding"],l),n}function Co(t,e){const n={},o=r(t,["uri"]);o!=null&&s(n,["gcsUri"],o);const i=r(t,["videoBytes"]);i!=null&&s(n,["bytesBase64Encoded"],Q(i));const l=r(t,["mimeType"]);return l!=null&&s(n,["mimeType"],l),n}/**
|
|
70
|
+
* @license
|
|
71
|
+
* Copyright 2025 Google LLC
|
|
72
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
73
|
+
*/function Ba(t,e){const n={},o=r(t,["displayName"]);return e!==void 0&&o!=null&&s(e,["displayName"],o),n}function Ja(t){const e={},n=r(t,["config"]);return n!=null&&Ba(n,e),e}function $a(t,e){const n={},o=r(t,["force"]);return e!==void 0&&o!=null&&s(e,["_query","force"],o),n}function Oa(t){const e={},n=r(t,["name"]);n!=null&&s(e,["_url","name"],n);const o=r(t,["config"]);return o!=null&&$a(o,e),e}function Wa(t){const e={},n=r(t,["name"]);return n!=null&&s(e,["_url","name"],n),e}function Ya(t,e){const n={},o=r(t,["customMetadata"]);if(e!==void 0&&o!=null){let l=o;Array.isArray(l)&&(l=l.map(a=>a)),s(e,["customMetadata"],l)}const i=r(t,["chunkingConfig"]);return e!==void 0&&i!=null&&s(e,["chunkingConfig"],i),n}function Ka(t){const e={},n=r(t,["name"]);n!=null&&s(e,["name"],n);const o=r(t,["metadata"]);o!=null&&s(e,["metadata"],o);const i=r(t,["done"]);i!=null&&s(e,["done"],i);const l=r(t,["error"]);l!=null&&s(e,["error"],l);const a=r(t,["response"]);return a!=null&&s(e,["response"],Xa(a)),e}function za(t){const e={},n=r(t,["fileSearchStoreName"]);n!=null&&s(e,["_url","file_search_store_name"],n);const o=r(t,["fileName"]);o!=null&&s(e,["fileName"],o);const i=r(t,["config"]);return i!=null&&Ya(i,e),e}function Xa(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["parent"]);o!=null&&s(e,["parent"],o);const i=r(t,["documentName"]);return i!=null&&s(e,["documentName"],i),e}function Qa(t,e){const n={},o=r(t,["pageSize"]);e!==void 0&&o!=null&&s(e,["_query","pageSize"],o);const i=r(t,["pageToken"]);return e!==void 0&&i!=null&&s(e,["_query","pageToken"],i),n}function Za(t){const e={},n=r(t,["config"]);return n!=null&&Qa(n,e),e}function ja(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["nextPageToken"]);o!=null&&s(e,["nextPageToken"],o);const i=r(t,["fileSearchStores"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>a)),s(e,["fileSearchStores"],l)}return e}function So(t,e){const n={},o=r(t,["mimeType"]);e!==void 0&&o!=null&&s(e,["mimeType"],o);const i=r(t,["displayName"]);e!==void 0&&i!=null&&s(e,["displayName"],i);const l=r(t,["customMetadata"]);if(e!==void 0&&l!=null){let u=l;Array.isArray(u)&&(u=u.map(d=>d)),s(e,["customMetadata"],u)}const a=r(t,["chunkingConfig"]);return e!==void 0&&a!=null&&s(e,["chunkingConfig"],a),n}function eu(t){const e={},n=r(t,["fileSearchStoreName"]);n!=null&&s(e,["_url","file_search_store_name"],n);const o=r(t,["config"]);return o!=null&&So(o,e),e}function tu(t){const e={},n=r(t,["sdkHttpResponse"]);return n!=null&&s(e,["sdkHttpResponse"],n),e}/**
|
|
74
|
+
* @license
|
|
75
|
+
* Copyright 2025 Google LLC
|
|
76
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
77
|
+
*/const nu="Content-Type",ou="X-Server-Timeout",iu="User-Agent",je="x-goog-api-client",ru="1.43.0",su=`google-genai-sdk/${ru}`,lu="v1beta1",au="v1beta",uu=5,cu=[408,429,500,502,503,504];class du{constructor(e){var n,o,i;this.clientOptions=Object.assign({},e),this.customBaseUrl=(n=e.httpOptions)===null||n===void 0?void 0:n.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 l={};if(this.clientOptions.vertexai){if(!this.clientOptions.location&&!this.clientOptions.apiKey&&!this.customBaseUrl&&(this.clientOptions.location="global"),!(this.clientOptions.project&&this.clientOptions.location||this.clientOptions.apiKey)&&!this.customBaseUrl)throw new Error("Authentication is not set up. Please provide either a project and location, or an API key, or a custom base URL.");const u=e.project&&e.location||!!e.apiKey;this.customBaseUrl&&!u?(l.baseUrl=this.customBaseUrl,this.clientOptions.project=void 0,this.clientOptions.location=void 0):this.clientOptions.apiKey||this.clientOptions.location==="global"?l.baseUrl="https://aiplatform.googleapis.com/":this.clientOptions.project&&this.clientOptions.location&&(l.baseUrl=`https://${this.clientOptions.location}-aiplatform.googleapis.com/`),l.apiVersion=(o=this.clientOptions.apiVersion)!==null&&o!==void 0?o:lu}else{if(!this.clientOptions.apiKey)throw new me({message:"API key must be set when using the Gemini API.",status:403});l.apiVersion=(i=this.clientOptions.apiVersion)!==null&&i!==void 0?i:au,l.baseUrl="https://generativelanguage.googleapis.com/"}l.headers=this.getDefaultHeaders(),this.clientOptions.httpOptions=l,e.httpOptions&&(this.clientOptions.httpOptions=this.patchHttpOptions(l,e.httpOptions))}isVertexAI(){var e;return(e=this.clientOptions.vertexai)!==null&&e!==void 0?e:!1}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&&this.clientOptions.httpOptions.apiVersion!==void 0)return this.clientOptions.httpOptions.apiVersion;throw new Error("API version is not set.")}getBaseUrl(){if(this.clientOptions.httpOptions&&this.clientOptions.httpOptions.baseUrl!==void 0)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&&this.clientOptions.httpOptions.headers!==void 0)return this.clientOptions.httpOptions.headers;throw new Error("Headers are not set.")}getRequestUrlInternal(e){if(!e||e.baseUrl===void 0||e.apiVersion===void 0)throw new Error("HTTP options are not correctly set.");const o=[e.baseUrl.endsWith("/")?e.baseUrl.slice(0,-1):e.baseUrl];return e.apiVersion&&e.apiVersion!==""&&o.push(e.apiVersion),o.join("/")}getBaseResourcePath(){return`projects/${this.clientOptions.project}/locations/${this.clientOptions.location}`}getApiKey(){return this.clientOptions.apiKey}getWebsocketBaseUrl(){const e=this.getBaseUrl(),n=new URL(e);return n.protocol=n.protocol=="http:"?"ws":"wss",n.toString()}setBaseUrl(e){if(this.clientOptions.httpOptions)this.clientOptions.httpOptions.baseUrl=e;else throw new Error("HTTP options are not correctly set.")}constructUrl(e,n,o){const i=[this.getRequestUrlInternal(n)];return o&&i.push(this.getBaseResourcePath()),e!==""&&i.push(e),new URL(`${i.join("/")}`)}shouldPrependVertexProjectPath(e,n){return!(n.baseUrl&&n.baseUrlResourceScope===Ye.COLLECTION||this.clientOptions.apiKey||!this.clientOptions.vertexai||e.path.startsWith("projects/")||e.httpMethod==="GET"&&e.path.startsWith("publishers/google/models"))}async request(e){let n=this.clientOptions.httpOptions;e.httpOptions&&(n=this.patchHttpOptions(this.clientOptions.httpOptions,e.httpOptions));const o=this.shouldPrependVertexProjectPath(e,n),i=this.constructUrl(e.path,n,o);if(e.queryParams)for(const[a,u]of Object.entries(e.queryParams))i.searchParams.append(a,String(u));let l={};if(e.httpMethod==="GET"){if(e.body&&e.body!=="{}")throw new Error("Request body should be empty for GET request, but got non empty request body")}else l.body=e.body;return l=await this.includeExtraHttpOptionsToRequestInit(l,n,i.toString(),e.abortSignal),this.unaryApiCall(i,l,e.httpMethod)}patchHttpOptions(e,n){const o=JSON.parse(JSON.stringify(e));for(const[i,l]of Object.entries(n))typeof l=="object"?o[i]=Object.assign(Object.assign({},o[i]),l):l!==void 0&&(o[i]=l);return o}async requestStream(e){let n=this.clientOptions.httpOptions;e.httpOptions&&(n=this.patchHttpOptions(this.clientOptions.httpOptions,e.httpOptions));const o=this.shouldPrependVertexProjectPath(e,n),i=this.constructUrl(e.path,n,o);(!i.searchParams.has("alt")||i.searchParams.get("alt")!=="sse")&&i.searchParams.set("alt","sse");let l={};return l.body=e.body,l=await this.includeExtraHttpOptionsToRequestInit(l,n,i.toString(),e.abortSignal),this.streamApiCall(i,l,e.httpMethod)}async includeExtraHttpOptionsToRequestInit(e,n,o,i){if(n&&n.timeout||i){const l=new AbortController,a=l.signal;if(n.timeout&&n?.timeout>0){const u=setTimeout(()=>l.abort(),n.timeout);u&&typeof u.unref=="function"&&u.unref()}i&&i.addEventListener("abort",()=>{l.abort()}),e.signal=a}return n&&n.extraBody!==null&&fu(e,n.extraBody),e.headers=await this.getHeadersInternal(n,o),e}async unaryApiCall(e,n,o){return this.apiCall(e.toString(),Object.assign(Object.assign({},n),{method:o})).then(async i=>(await bn(i),new Ke(i))).catch(i=>{throw i instanceof Error?i:new Error(JSON.stringify(i))})}async streamApiCall(e,n,o){return this.apiCall(e.toString(),Object.assign(Object.assign({},n),{method:o})).then(async i=>(await bn(i),this.processStreamResponse(i))).catch(i=>{throw i instanceof Error?i:new Error(JSON.stringify(i))})}processStreamResponse(e){return J(this,arguments,function*(){var o;const i=(o=e?.body)===null||o===void 0?void 0:o.getReader(),l=new TextDecoder("utf-8");if(!i)throw new Error("Response body is empty");try{let a="";const u="data:",d=[`
|
|
78
|
+
|
|
79
|
+
`,"\r\r",`\r
|
|
80
|
+
\r
|
|
81
|
+
`];for(;;){const{done:c,value:f}=yield P(i.read());if(c){if(a.trim().length>0)throw new Error("Incomplete JSON segment at the end");break}const h=l.decode(f,{stream:!0});try{const g=JSON.parse(h);if("error"in g){const v=JSON.parse(JSON.stringify(g.error)),y=v.status,T=v.code,I=`got status: ${y}. ${JSON.stringify(g)}`;if(T>=400&&T<600)throw new me({message:I,status:T})}}catch(g){if(g.name==="ApiError")throw g}a+=h;let p=-1,m=0;for(;;){p=-1,m=0;for(const y of d){const T=a.indexOf(y);T!==-1&&(p===-1||T<p)&&(p=T,m=y.length)}if(p===-1)break;const g=a.substring(0,p);a=a.substring(p+m);const v=g.trim();if(v.startsWith(u)){const y=v.substring(u.length).trim();try{const T=new Response(y,{headers:e?.headers,status:e?.status,statusText:e?.statusText});yield yield P(new Ke(T))}catch(T){throw new Error(`exception parsing stream chunk ${y}. ${T}`)}}}}}finally{i.releaseLock()}})}async apiCall(e,n){var o;if(!this.clientOptions.httpOptions||!this.clientOptions.httpOptions.retryOptions)return fetch(e,n);const i=this.clientOptions.httpOptions.retryOptions;return ei(async()=>{const a=await fetch(e,n);if(a.ok)return a;throw cu.includes(a.status)?new Error(`Retryable HTTP Error: ${a.statusText}`):new eo.AbortError(`Non-retryable exception ${a.statusText} sending request`)},{retries:((o=i.attempts)!==null&&o!==void 0?o:uu)-1})}getDefaultHeaders(){const e={},n=su+" "+this.clientOptions.userAgentExtra;return e[iu]=n,e[je]=n,e[nu]="application/json",e}async getHeadersInternal(e,n){const o=new Headers;if(e&&e.headers){for(const[i,l]of Object.entries(e.headers))o.append(i,l);e.timeout&&e.timeout>0&&o.append(ou,String(Math.ceil(e.timeout/1e3)))}return await this.clientOptions.auth.addAuthHeaders(o,n),o}getFileName(e){var n;let o="";return typeof e=="string"&&(o=e.replace(/[/\\]+$/,""),o=(n=o.split(/[/\\]/).pop())!==null&&n!==void 0?n:""),o}async uploadFile(e,n){var o;const i={};n!=null&&(i.mimeType=n.mimeType,i.name=n.name,i.displayName=n.displayName),i.name&&!i.name.startsWith("files/")&&(i.name=`files/${i.name}`);const l=this.clientOptions.uploader,a=await l.stat(e);i.sizeBytes=String(a.size);const u=(o=n?.mimeType)!==null&&o!==void 0?o:a.type;if(u===void 0||u==="")throw new Error("Can not determine mimeType. Please provide mimeType in the config.");i.mimeType=u;const d={file:i},c=this.getFileName(e),f=E("upload/v1beta/files",d._url),h=await this.fetchUploadUrl(f,i.sizeBytes,i.mimeType,c,d,n?.httpOptions);return l.upload(e,h,this)}async uploadFileToFileSearchStore(e,n,o){var i;const l=this.clientOptions.uploader,a=await l.stat(n),u=String(a.size),d=(i=o?.mimeType)!==null&&i!==void 0?i:a.type;if(d===void 0||d==="")throw new Error("Can not determine mimeType. Please provide mimeType in the config.");const c=`upload/v1beta/${e}:uploadToFileSearchStore`,f=this.getFileName(n),h={};o!=null&&So(o,h);const p=await this.fetchUploadUrl(c,u,d,f,h,o?.httpOptions);return l.uploadToFileSearchStore(n,p,this)}async downloadFile(e){await this.clientOptions.downloader.download(e,this)}async fetchUploadUrl(e,n,o,i,l,a){var u;let d={};a?d=a:d={apiVersion:"",headers:Object.assign({"Content-Type":"application/json","X-Goog-Upload-Protocol":"resumable","X-Goog-Upload-Command":"start","X-Goog-Upload-Header-Content-Length":`${n}`,"X-Goog-Upload-Header-Content-Type":`${o}`},i?{"X-Goog-Upload-File-Name":i}:{})};const c=await this.request({path:e,body:JSON.stringify(l),httpMethod:"POST",httpOptions:d});if(!c||!c?.headers)throw new Error("Server did not return an HttpResponse or the returned HttpResponse did not have headers.");const f=(u=c?.headers)===null||u===void 0?void 0:u["x-goog-upload-url"];if(f===void 0)throw new Error("Failed to get upload url. Server did not return the x-google-upload-url in the headers");return f}}async function bn(t){var e;if(t===void 0)throw new Error("response is undefined");if(!t.ok){const n=t.status;let o;!((e=t.headers.get("content-type"))===null||e===void 0)&&e.includes("application/json")?o=await t.json():o={error:{message:await t.text(),code:t.status,status:t.statusText}};const i=JSON.stringify(o);throw n>=400&&n<600?new me({message:i,status:n}):new Error(i)}}function fu(t,e){if(!e||Object.keys(e).length===0)return;if(t.body instanceof Blob){console.warn("includeExtraBodyToRequestInit: extraBody provided but current request body is a Blob. extraBody will be ignored as merging is not supported for Blob bodies.");return}let n={};if(typeof t.body=="string"&&t.body.length>0)try{const l=JSON.parse(t.body);if(typeof l=="object"&&l!==null&&!Array.isArray(l))n=l;else{console.warn("includeExtraBodyToRequestInit: Original request body is valid JSON but not a non-array object. Skip applying extraBody to the request body.");return}}catch{console.warn("includeExtraBodyToRequestInit: Original request body is not valid JSON. Skip applying extraBody to the request body.");return}function o(l,a){const u=Object.assign({},l);for(const d in a)if(Object.prototype.hasOwnProperty.call(a,d)){const c=a[d],f=u[d];c&&typeof c=="object"&&!Array.isArray(c)&&f&&typeof f=="object"&&!Array.isArray(f)?u[d]=o(f,c):(f&&c&&typeof f!=typeof c&&console.warn(`includeExtraBodyToRequestInit:deepMerge: Type mismatch for key "${d}". Original type: ${typeof f}, New type: ${typeof c}. Overwriting.`),u[d]=c)}return u}const i=o(n,e);t.body=JSON.stringify(i)}/**
|
|
82
|
+
* @license
|
|
83
|
+
* Copyright 2025 Google LLC
|
|
84
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
85
|
+
*/const pu="mcp_used/unknown";let hu=!1;function Io(t){for(const e of t)if(mu(e)||typeof e=="object"&&"inputSchema"in e)return!0;return hu}function Ao(t){var e;const n=(e=t[je])!==null&&e!==void 0?e:"";t[je]=(n+` ${pu}`).trimStart()}function mu(t){return t!==null&&typeof t=="object"&&t instanceof pt}function gu(t){return J(this,arguments,function*(n,o=100){let i,l=0;for(;l<o;){const a=yield P(n.listTools({cursor:i}));for(const u of a.tools)yield yield P(u),l++;if(!a.nextCursor)break;i=a.nextCursor}})}class pt{constructor(e=[],n){this.mcpTools=[],this.functionNameToMcpClient={},this.mcpClients=e,this.config=n}static create(e,n){return new pt(e,n)}async initialize(){var e,n,o,i;if(this.mcpTools.length>0)return;const l={},a=[];for(const f of this.mcpClients)try{for(var u=!0,d=(n=void 0,$(gu(f))),c;c=await d.next(),e=c.done,!e;u=!0){i=c.value,u=!1;const h=i;a.push(h);const p=h.name;if(l[p])throw new Error(`Duplicate function name ${p} found in MCP tools. Please ensure function names are unique.`);l[p]=f}}catch(h){n={error:h}}finally{try{!u&&!e&&(o=d.return)&&await o.call(d)}finally{if(n)throw n.error}}this.mcpTools=a,this.functionNameToMcpClient=l}async tool(){return await this.initialize(),Bi(this.mcpTools,this.config)}async callTool(e){await this.initialize();const n=[];for(const o of e)if(o.name in this.functionNameToMcpClient){const i=this.functionNameToMcpClient[o.name];let l;this.config.timeout&&(l={timeout:this.config.timeout});const a=await i.callTool({name:o.name,arguments:o.args},void 0,l);n.push({functionResponse:{name:o.name,response:a.isError?{error:a}:a}})}return n}}/**
|
|
86
|
+
* @license
|
|
87
|
+
* Copyright 2025 Google LLC
|
|
88
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
89
|
+
*/async function yu(t,e,n){const o=new Li;let i;n.data instanceof Blob?i=JSON.parse(await n.data.text()):i=JSON.parse(n.data),Object.assign(o,i),e(o)}class vu{constructor(e,n,o){this.apiClient=e,this.auth=n,this.webSocketFactory=o}async connect(e){var n,o;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 i=this.apiClient.getWebsocketBaseUrl(),l=this.apiClient.getApiVersion(),a=Eu(this.apiClient.getDefaultHeaders()),u=this.apiClient.getApiKey(),d=`${i}/ws/google.ai.generativelanguage.${l}.GenerativeService.BidiGenerateMusic?key=${u}`;let c=()=>{};const f=new Promise(C=>{c=C}),h=e.callbacks,p=function(){c({})},m=this.apiClient,g={onopen:p,onmessage:C=>{yu(m,h.onmessage,C)},onerror:(n=h?.onerror)!==null&&n!==void 0?n:function(C){},onclose:(o=h?.onclose)!==null&&o!==void 0?o:function(C){}},v=this.webSocketFactory.create(d,_u(a),g);v.connect(),await f;const I={setup:{model:N(this.apiClient,e.model)}};return v.send(JSON.stringify(I)),new Tu(v,this.apiClient)}}class Tu{constructor(e,n){this.conn=e,this.apiClient=n}async setWeightedPrompts(e){if(!e.weightedPrompts||Object.keys(e.weightedPrompts).length===0)throw new Error("Weighted prompts must be set and contain at least one entry.");const n=Bs(e);this.conn.send(JSON.stringify({clientContent:n}))}async setMusicGenerationConfig(e){e.musicGenerationConfig||(e.musicGenerationConfig={});const n=bs(e);this.conn.send(JSON.stringify(n))}sendPlaybackControl(e){const n={playbackControl:e};this.conn.send(JSON.stringify(n))}play(){this.sendPlaybackControl(ie.PLAY)}pause(){this.sendPlaybackControl(ie.PAUSE)}stop(){this.sendPlaybackControl(ie.STOP)}resetContext(){this.sendPlaybackControl(ie.RESET_CONTEXT)}close(){this.conn.close()}}function _u(t){const e={};return t.forEach((n,o)=>{e[o]=n}),e}function Eu(t){const e=new Headers;for(const[n,o]of Object.entries(t))e.append(n,o);return e}/**
|
|
90
|
+
* @license
|
|
91
|
+
* Copyright 2025 Google LLC
|
|
92
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
93
|
+
*/const Cu="FunctionResponse request must have an `id` field from the response of a ToolCall.FunctionalCalls in Google AI.";async function Su(t,e,n){const o=new Ui;let i;n.data instanceof Blob?i=await n.data.text():n.data instanceof ArrayBuffer?i=new TextDecoder().decode(n.data):i=n.data;const l=JSON.parse(i);if(t.isVertexAI()){const a=Os(l);Object.assign(o,a)}else Object.assign(o,l);e(o)}class Iu{constructor(e,n,o){this.apiClient=e,this.auth=n,this.webSocketFactory=o,this.music=new vu(this.apiClient,this.auth,this.webSocketFactory)}async connect(e){var n,o,i,l,a,u;if(e.config&&e.config.httpOptions)throw new Error("The Live module does not support httpOptions at request-level in LiveConnectConfig yet. Please use the client-level httpOptions configuration instead.");const d=this.apiClient.getWebsocketBaseUrl(),c=this.apiClient.getApiVersion();let f;const h=this.apiClient.getHeaders();e.config&&e.config.tools&&Io(e.config.tools)&&Ao(h);const p=Mu(h);if(this.apiClient.isVertexAI()){const A=this.apiClient.getProject(),w=this.apiClient.getLocation(),x=this.apiClient.getApiKey(),q=!!A&&!!w||!!x;this.apiClient.getCustomBaseUrl()&&!q?f=d:(f=`${d}/ws/google.cloud.aiplatform.${c}.LlmBidiService/BidiGenerateContent`,await this.auth.addAuthHeaders(p,f))}else{const A=this.apiClient.getApiKey();let w="BidiGenerateContent",x="key";A?.startsWith("auth_tokens/")&&(console.warn("Warning: Ephemeral token support is experimental and may change in future versions."),c!=="v1alpha"&&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."),w="BidiGenerateContentConstrained",x="access_token"),f=`${d}/ws/google.ai.generativelanguage.${c}.GenerativeService.${w}?${x}=${A}`}let m=()=>{};const g=new Promise(A=>{m=A}),v=e.callbacks,y=function(){var A;(A=v?.onopen)===null||A===void 0||A.call(v),m({})},T=this.apiClient,I={onopen:y,onmessage:A=>{Su(T,v.onmessage,A)},onerror:(n=v?.onerror)!==null&&n!==void 0?n:function(A){},onclose:(o=v?.onclose)!==null&&o!==void 0?o:function(A){}},C=this.webSocketFactory.create(f,Pu(p),I);C.connect(),await g;let S=N(this.apiClient,e.model);if(this.apiClient.isVertexAI()&&S.startsWith("publishers/")){const A=this.apiClient.getProject(),w=this.apiClient.getLocation();A&&w&&(S=`projects/${A}/locations/${w}/`+S)}let R={};this.apiClient.isVertexAI()&&((i=e.config)===null||i===void 0?void 0:i.responseModalities)===void 0&&(e.config===void 0?e.config={responseModalities:[Ie.AUDIO]}:e.config.responseModalities=[Ie.AUDIO]),!((l=e.config)===null||l===void 0)&&l.generationConfig&&console.warn("Setting `LiveConnectConfig.generation_config` is deprecated, please set the fields on `LiveConnectConfig` directly. This will become an error in a future version (not before Q3 2025).");const _=(u=(a=e.config)===null||a===void 0?void 0:a.tools)!==null&&u!==void 0?u:[],M=[];for(const A of _)if(this.isCallableTool(A)){const w=A;M.push(await w.tool())}else M.push(A);M.length>0&&(e.config.tools=M);const D={model:S,config:e.config,callbacks:e.callbacks};return this.apiClient.isVertexAI()?R=qs(this.apiClient,D):R=Hs(this.apiClient,D),delete R.config,C.send(JSON.stringify(R)),new Ru(C,this.apiClient)}isCallableTool(e){return"callTool"in e&&typeof e.callTool=="function"}}const Au={turnComplete:!0};class Ru{constructor(e,n){this.conn=e,this.apiClient=n}tLiveClientContent(e,n){if(n.turns!==null&&n.turns!==void 0){let o=[];try{o=b(n.turns),e.isVertexAI()||(o=o.map(i=>ge(i)))}catch{throw new Error(`Failed to parse client content "turns", type: '${typeof n.turns}'`)}return{clientContent:{turns:o,turnComplete:n.turnComplete}}}return{clientContent:{turnComplete:n.turnComplete}}}tLiveClienttToolResponse(e,n){let o=[];if(n.functionResponses==null)throw new Error("functionResponses is required.");if(Array.isArray(n.functionResponses)?o=n.functionResponses:o=[n.functionResponses],o.length===0)throw new Error("functionResponses is required.");for(const l of o){if(typeof l!="object"||l===null||!("name"in l)||!("response"in l))throw new Error(`Could not parse function response, type '${typeof l}'.`);if(!e.isVertexAI()&&!("id"in l))throw new Error(Cu)}return{toolResponse:{functionResponses:o}}}sendClientContent(e){e=Object.assign(Object.assign({},Au),e);const n=this.tLiveClientContent(this.apiClient,e);this.conn.send(JSON.stringify(n))}sendRealtimeInput(e){let n={};this.apiClient.isVertexAI()?n={realtimeInput:$s(e)}:n={realtimeInput:Js(e)},this.conn.send(JSON.stringify(n))}sendToolResponse(e){if(e.functionResponses==null)throw new Error("Tool response parameters are required.");const n=this.tLiveClienttToolResponse(this.apiClient,e);this.conn.send(JSON.stringify(n))}close(){this.conn.close()}}function Pu(t){const e={};return t.forEach((n,o)=>{e[o]=n}),e}function Mu(t){const e=new Headers;for(const[n,o]of Object.entries(t))e.append(n,o);return e}/**
|
|
94
|
+
* @license
|
|
95
|
+
* Copyright 2025 Google LLC
|
|
96
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
97
|
+
*/const Bn=10;function Jn(t){var e,n,o;if(!((e=t?.automaticFunctionCalling)===null||e===void 0)&&e.disable)return!0;let i=!1;for(const a of(n=t?.tools)!==null&&n!==void 0?n:[])if(le(a)){i=!0;break}if(!i)return!0;const l=(o=t?.automaticFunctionCalling)===null||o===void 0?void 0:o.maximumRemoteCalls;return l&&(l<0||!Number.isInteger(l))||l==0?(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:",l),!0):!1}function le(t){return"callTool"in t&&typeof t.callTool=="function"}function wu(t){var e,n,o;return(o=(n=(e=t.config)===null||e===void 0?void 0:e.tools)===null||n===void 0?void 0:n.some(i=>le(i)))!==null&&o!==void 0?o:!1}function $n(t){var e;const n=[];return!((e=t?.config)===null||e===void 0)&&e.tools&&t.config.tools.forEach((o,i)=>{if(le(o))return;const l=o;l.functionDeclarations&&l.functionDeclarations.length>0&&n.push(i)}),n}function On(t){var e;return!(!((e=t?.automaticFunctionCalling)===null||e===void 0)&&e.ignoreCallHistory)}/**
|
|
98
|
+
* @license
|
|
99
|
+
* Copyright 2025 Google LLC
|
|
100
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
101
|
+
*/class Nu extends K{constructor(e){super(),this.apiClient=e,this.embedContent=async n=>{if(!this.apiClient.isVertexAI())return await this.embedContentInternal(n);if(n.model.includes("gemini")&&n.model!=="gemini-embedding-001"||n.model.includes("maas")){const i=b(n.contents);if(i.length>1)throw new Error("The embedContent API for this model only supports one content at a time.");const l=Object.assign(Object.assign({},n),{content:i[0],embeddingApiType:Ae.EMBED_CONTENT});return await this.embedContentInternal(l)}else{const i=Object.assign(Object.assign({},n),{embeddingApiType:Ae.PREDICT});return await this.embedContentInternal(i)}},this.generateContent=async n=>{var o,i,l,a,u;const d=await this.processParamsMaybeAddMcpUsage(n);if(this.maybeMoveToResponseJsonSchem(n),!wu(n)||Jn(n.config))return await this.generateContentInternal(d);const c=$n(n);if(c.length>0){const v=c.map(y=>`tools[${y}]`).join(", ");throw new Error(`Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations is not yet supported. Incompatible tools found at ${v}.`)}let f,h;const p=b(d.contents),m=(l=(i=(o=d.config)===null||o===void 0?void 0:o.automaticFunctionCalling)===null||i===void 0?void 0:i.maximumRemoteCalls)!==null&&l!==void 0?l:Bn;let g=0;for(;g<m&&(f=await this.generateContentInternal(d),!(!f.functionCalls||f.functionCalls.length===0));){const v=f.candidates[0].content,y=[];for(const T of(u=(a=n.config)===null||a===void 0?void 0:a.tools)!==null&&u!==void 0?u:[])if(le(T)){const C=await T.callTool(f.functionCalls);y.push(...C)}g++,h={role:"user",parts:y},d.contents=b(d.contents),d.contents.push(v),d.contents.push(h),On(d.config)&&(p.push(v),p.push(h))}return On(d.config)&&(f.automaticFunctionCallingHistory=p),f},this.generateContentStream=async n=>{var o,i,l,a,u;if(this.maybeMoveToResponseJsonSchem(n),Jn(n.config)){const h=await this.processParamsMaybeAddMcpUsage(n);return await this.generateContentStreamInternal(h)}const d=$n(n);if(d.length>0){const h=d.map(p=>`tools[${p}]`).join(", ");throw new Error(`Incompatible tools found at ${h}. Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations" is not yet supported.`)}const c=(l=(i=(o=n?.config)===null||o===void 0?void 0:o.toolConfig)===null||i===void 0?void 0:i.functionCallingConfig)===null||l===void 0?void 0:l.streamFunctionCallArguments,f=(u=(a=n?.config)===null||a===void 0?void 0:a.automaticFunctionCalling)===null||u===void 0?void 0:u.disable;if(c&&!f)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(n)},this.generateImages=async n=>await this.generateImagesInternal(n).then(o=>{var i;let l;const a=[];if(o?.generatedImages)for(const d of o.generatedImages)d&&d?.safetyAttributes&&((i=d?.safetyAttributes)===null||i===void 0?void 0:i.contentType)==="Positive Prompt"?l=d?.safetyAttributes:a.push(d);let u;return l?u={generatedImages:a,positivePromptSafetyAttributes:l,sdkHttpResponse:o.sdkHttpResponse}:u={generatedImages:a,sdkHttpResponse:o.sdkHttpResponse},u}),this.list=async n=>{var o;const a={config:Object.assign(Object.assign({},{queryBase:!0}),n?.config)};if(this.apiClient.isVertexAI()&&!a.config.queryBase){if(!((o=a.config)===null||o===void 0)&&o.filter)throw new Error("Filtering tuned models list for Vertex AI is not currently supported");a.config.filter="labels.tune-type:*"}return new j(Y.PAGED_ITEM_MODELS,u=>this.listInternal(u),await this.listInternal(a),a)},this.editImage=async n=>{const o={model:n.model,prompt:n.prompt,referenceImages:[],config:n.config};return n.referenceImages&&n.referenceImages&&(o.referenceImages=n.referenceImages.map(i=>i.toReferenceImageAPI())),await this.editImageInternal(o)},this.upscaleImage=async n=>{let o={numberOfImages:1,mode:"upscale"};n.config&&(o=Object.assign(Object.assign({},o),n.config));const i={model:n.model,image:n.image,upscaleFactor:n.upscaleFactor,config:o};return await this.upscaleImageInternal(i)},this.generateVideos=async n=>{var o,i,l,a,u,d;if((n.prompt||n.image||n.video)&&n.source)throw new Error("Source and prompt/image/video are mutually exclusive. Please only use source.");return this.apiClient.isVertexAI()||(!((o=n.video)===null||o===void 0)&&o.uri&&(!((i=n.video)===null||i===void 0)&&i.videoBytes)?n.video={uri:n.video.uri,mimeType:n.video.mimeType}:!((a=(l=n.source)===null||l===void 0?void 0:l.video)===null||a===void 0)&&a.uri&&(!((d=(u=n.source)===null||u===void 0?void 0:u.video)===null||d===void 0)&&d.videoBytes)&&(n.source.video={uri:n.source.video.uri,mimeType:n.source.video.mimeType})),await this.generateVideosInternal(n)}}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 n,o,i;const l=(n=e.config)===null||n===void 0?void 0:n.tools;if(!l)return e;const a=await Promise.all(l.map(async d=>le(d)?await d.tool():d)),u={model:e.model,contents:e.contents,config:Object.assign(Object.assign({},e.config),{tools:a})};if(u.config.tools=a,e.config&&e.config.tools&&Io(e.config.tools)){const d=(i=(o=e.config.httpOptions)===null||o===void 0?void 0:o.headers)!==null&&i!==void 0?i:{};let c=Object.assign({},d);Object.keys(c).length===0&&(c=this.apiClient.getDefaultHeaders()),Ao(c),u.config.httpOptions=Object.assign(Object.assign({},e.config.httpOptions),{headers:c})}return u}async initAfcToolsMap(e){var n,o,i;const l=new Map;for(const a of(o=(n=e.config)===null||n===void 0?void 0:n.tools)!==null&&o!==void 0?o:[])if(le(a)){const u=a,d=await u.tool();for(const c of(i=d.functionDeclarations)!==null&&i!==void 0?i:[]){if(!c.name)throw new Error("Function declaration name is required.");if(l.has(c.name))throw new Error(`Duplicate tool declaration name: ${c.name}`);l.set(c.name,u)}}return l}async processAfcStream(e){var n,o,i;const l=(i=(o=(n=e.config)===null||n===void 0?void 0:n.automaticFunctionCalling)===null||o===void 0?void 0:o.maximumRemoteCalls)!==null&&i!==void 0?i:Bn;let a=!1,u=0;const d=await this.initAfcToolsMap(e);return(function(c,f,h){return J(this,arguments,function*(){for(var p,m,g,v,y,T;u<l;){a&&(u++,a=!1);const R=yield P(c.processParamsMaybeAddMcpUsage(h)),_=yield P(c.generateContentStreamInternal(R)),M=[],D=[];try{for(var I=!0,C=(m=void 0,$(_)),S;S=yield P(C.next()),p=S.done,!p;I=!0){v=S.value,I=!1;const A=v;if(yield yield P(A),A.candidates&&(!((y=A.candidates[0])===null||y===void 0)&&y.content)){D.push(A.candidates[0].content);for(const w of(T=A.candidates[0].content.parts)!==null&&T!==void 0?T:[])if(u<l&&w.functionCall){if(!w.functionCall.name)throw new Error("Function call name was not returned by the model.");if(f.has(w.functionCall.name)){const x=yield P(f.get(w.functionCall.name).callTool([w.functionCall]));M.push(...x)}else throw new Error(`Automatic function calling was requested, but not all the tools the model used implement the CallableTool interface. Available tools: ${f.keys()}, mising tool: ${w.functionCall.name}`)}}}}catch(A){m={error:A}}finally{try{!I&&!p&&(g=C.return)&&(yield P(g.call(C)))}finally{if(m)throw m.error}}if(M.length>0){a=!0;const A=new fe;A.candidates=[{content:{role:"user",parts:M}}],yield yield P(A);const w=[];w.push(...D),w.push({role:"user",parts:M});const x=b(h.contents).concat(w);h.contents=x}else break}})})(this,d,e)}async generateContentInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=Vn(this.apiClient,e);return u=E("{model}:generateContent",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=qn(f),p=new fe;return Object.assign(p,h),p})}else{const c=Gn(this.apiClient,e);return u=E("{model}:generateContent",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Hn(f),p=new fe;return Object.assign(p,h),p})}}async generateContentStreamInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=Vn(this.apiClient,e);return u=E("{model}:streamGenerateContent?alt=sse",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.requestStream({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}),a.then(function(h){return J(this,arguments,function*(){var p,m,g,v;try{for(var y=!0,T=$(h),I;I=yield P(T.next()),p=I.done,!p;y=!0){v=I.value,y=!1;const C=v,S=qn(yield P(C.json()),e);S.sdkHttpResponse={headers:C.headers};const R=new fe;Object.assign(R,S),yield yield P(R)}}catch(C){m={error:C}}finally{try{!y&&!p&&(g=T.return)&&(yield P(g.call(T)))}finally{if(m)throw m.error}}})})}else{const c=Gn(this.apiClient,e);return u=E("{model}:streamGenerateContent?alt=sse",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.requestStream({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}),a.then(function(h){return J(this,arguments,function*(){var p,m,g,v;try{for(var y=!0,T=$(h),I;I=yield P(T.next()),p=I.done,!p;y=!0){v=I.value,y=!1;const C=v,S=Hn(yield P(C.json()),e);S.sdkHttpResponse={headers:C.headers};const R=new fe;Object.assign(R,S),yield yield P(R)}}catch(C){m={error:C}}finally{try{!y&&!p&&(g=T.return)&&(yield P(g.call(T)))}finally{if(m)throw m.error}}})})}}async embedContentInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=Cl(this.apiClient,e,e),f=$i(e.model)?"{model}:embedContent":"{model}:predict";return u=E(f,c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(h=>h.json().then(p=>{const m=p;return m.sdkHttpResponse={headers:h.headers},m})),a.then(h=>{const p=Il(h,e),m=new _n;return Object.assign(m,p),m})}else{const c=El(this.apiClient,e);return u=E("{model}:batchEmbedContents",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Sl(f),p=new _n;return Object.assign(p,h),p})}}async generateImagesInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=kl(this.apiClient,e);return u=E("{model}:predict",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Gl(f),p=new En;return Object.assign(p,h),p})}else{const c=Ll(this.apiClient,e);return u=E("{model}:predict",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Fl(f),p=new En;return Object.assign(p,h),p})}}async editImageInternal(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI()){const u=yl(this.apiClient,e);return l=E("{model}:predict",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json().then(c=>{const f=c;return f.sdkHttpResponse={headers:d.headers},f})),i.then(d=>{const c=vl(d),f=new Ei;return Object.assign(f,c),f})}else throw new Error("This method is only supported by the Vertex AI.")}async upscaleImageInternal(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI()){const u=ka(this.apiClient,e);return l=E("{model}:predict",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json().then(c=>{const f=c;return f.sdkHttpResponse={headers:d.headers},f})),i.then(d=>{const c=Fa(d),f=new Ci;return Object.assign(f,c),f})}else throw new Error("This method is only supported by the Vertex AI.")}async recontextImage(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI()){const u=ga(this.apiClient,e);return l=E("{model}:predict",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>{const c=ya(d),f=new Si;return Object.assign(f,c),f})}else throw new Error("This method is only supported by the Vertex AI.")}async segmentImage(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI()){const u=Sa(this.apiClient,e);return l=E("{model}:predict",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>{const c=Ia(d),f=new Ii;return Object.assign(f,c),f})}else throw new Error("This method is only supported by the Vertex AI.")}async get(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=ea(this.apiClient,e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>Ze(f))}else{const c=jl(this.apiClient,e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>Qe(f))}}async listInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=ua(this.apiClient,e);return u=E("{models_url}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=da(f),p=new Cn;return Object.assign(p,h),p})}else{const c=aa(this.apiClient,e);return u=E("{models_url}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=ca(f),p=new Cn;return Object.assign(p,h),p})}}async update(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=Ua(this.apiClient,e);return u=E("{model}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"PATCH",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>Ze(f))}else{const c=xa(this.apiClient,e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"PATCH",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>Qe(f))}}async delete(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=pl(this.apiClient,e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=ml(f),p=new Sn;return Object.assign(p,h),p})}else{const c=fl(this.apiClient,e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"DELETE",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=hl(f),p=new Sn;return Object.assign(p,h),p})}}async countTokens(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=ul(this.apiClient,e);return u=E("{model}:countTokens",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=dl(f),p=new In;return Object.assign(p,h),p})}else{const c=al(this.apiClient,e);return u=E("{model}:countTokens",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=cl(f),p=new In;return Object.assign(p,h),p})}}async computeTokens(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI()){const u=tl(this.apiClient,e);return l=E("{model}:computeTokens",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json().then(c=>{const f=c;return f.sdkHttpResponse={headers:d.headers},f})),i.then(d=>{const c=nl(d),f=new Ai;return Object.assign(f,c),f})}else throw new Error("This method is only supported by the Vertex AI.")}async generateVideosInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=Jl(this.apiClient,e);return u=E("{model}:predictLongRunning",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>{const h=bl(f),p=new Re;return Object.assign(p,h),p})}else{const c=Bl(this.apiClient,e);return u=E("{model}:predictLongRunning",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>{const h=ql(f),p=new Re;return Object.assign(p,h),p})}}}/**
|
|
102
|
+
* @license
|
|
103
|
+
* Copyright 2025 Google LLC
|
|
104
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
105
|
+
*/class Du extends K{constructor(e){super(),this.apiClient=e}async getVideosOperation(e){const n=e.operation,o=e.config;if(n.name===void 0||n.name==="")throw new Error("Operation name is required.");if(this.apiClient.isVertexAI()){const i=n.name.split("/operations/")[0];let l;o&&"httpOptions"in o&&(l=o.httpOptions);const a=await this.fetchPredictVideosOperationInternal({operationName:n.name,resourceName:i,config:{httpOptions:l}});return n._fromAPIResponse({apiResponse:a,_isVertexAI:!0})}else{const i=await this.getVideosOperationInternal({operationName:n.name,config:o});return n._fromAPIResponse({apiResponse:i,_isVertexAI:!1})}}async get(e){const n=e.operation,o=e.config;if(n.name===void 0||n.name==="")throw new Error("Operation name is required.");if(this.apiClient.isVertexAI()){const i=n.name.split("/operations/")[0];let l;o&&"httpOptions"in o&&(l=o.httpOptions);const a=await this.fetchPredictVideosOperationInternal({operationName:n.name,resourceName:i,config:{httpOptions:l}});return n._fromAPIResponse({apiResponse:a,_isVertexAI:!0})}else{const i=await this.getVideosOperationInternal({operationName:n.name,config:o});return n._fromAPIResponse({apiResponse:i,_isVertexAI:!1})}}async getVideosOperationInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=mi(e);return u=E("{operationName}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a}else{const c=hi(e);return u=E("{operationName}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a}}async fetchPredictVideosOperationInternal(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI()){const u=li(e);return l=E("{resourceName}:fetchPredictOperation",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i}else throw new Error("This method is only supported by the Vertex AI.")}}/**
|
|
106
|
+
* @license
|
|
107
|
+
* Copyright 2025 Google LLC
|
|
108
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
109
|
+
*/function xu(t){const e={},n=r(t,["data"]);if(n!=null&&s(e,["data"],n),r(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const o=r(t,["mimeType"]);return o!=null&&s(e,["mimeType"],o),e}function Uu(t){const e={},n=r(t,["parts"]);if(n!=null){let i=n;Array.isArray(i)&&(i=i.map(l=>Bu(l))),s(e,["parts"],i)}const o=r(t,["role"]);return o!=null&&s(e,["role"],o),e}function Lu(t,e,n){const o={},i=r(e,["expireTime"]);n!==void 0&&i!=null&&s(n,["expireTime"],i);const l=r(e,["newSessionExpireTime"]);n!==void 0&&l!=null&&s(n,["newSessionExpireTime"],l);const a=r(e,["uses"]);n!==void 0&&a!=null&&s(n,["uses"],a);const u=r(e,["liveConnectConstraints"]);n!==void 0&&u!=null&&s(n,["bidiGenerateContentSetup"],bu(t,u));const d=r(e,["lockAdditionalFields"]);return n!==void 0&&d!=null&&s(n,["fieldMask"],d),o}function ku(t,e){const n={},o=r(e,["config"]);return o!=null&&s(n,["config"],Lu(t,o,n)),n}function Fu(t){const e={};if(r(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const n=r(t,["fileUri"]);n!=null&&s(e,["fileUri"],n);const o=r(t,["mimeType"]);return o!=null&&s(e,["mimeType"],o),e}function Gu(t){const e={},n=r(t,["id"]);n!=null&&s(e,["id"],n);const o=r(t,["args"]);o!=null&&s(e,["args"],o);const i=r(t,["name"]);if(i!=null&&s(e,["name"],i),r(t,["partialArgs"])!==void 0)throw new Error("partialArgs parameter is not supported in Gemini API.");if(r(t,["willContinue"])!==void 0)throw new Error("willContinue parameter is not supported in Gemini API.");return e}function Vu(t){const e={};if(r(t,["authConfig"])!==void 0)throw new Error("authConfig parameter is not supported in Gemini API.");const n=r(t,["enableWidget"]);return n!=null&&s(e,["enableWidget"],n),e}function Hu(t){const e={},n=r(t,["searchTypes"]);if(n!=null&&s(e,["searchTypes"],n),r(t,["excludeDomains"])!==void 0)throw new Error("excludeDomains parameter is not supported in Gemini API.");if(r(t,["blockingConfidence"])!==void 0)throw new Error("blockingConfidence parameter is not supported in Gemini API.");const o=r(t,["timeRangeFilter"]);return o!=null&&s(e,["timeRangeFilter"],o),e}function qu(t,e){const n={},o=r(t,["generationConfig"]);e!==void 0&&o!=null&&s(e,["setup","generationConfig"],o);const i=r(t,["responseModalities"]);e!==void 0&&i!=null&&s(e,["setup","generationConfig","responseModalities"],i);const l=r(t,["temperature"]);e!==void 0&&l!=null&&s(e,["setup","generationConfig","temperature"],l);const a=r(t,["topP"]);e!==void 0&&a!=null&&s(e,["setup","generationConfig","topP"],a);const u=r(t,["topK"]);e!==void 0&&u!=null&&s(e,["setup","generationConfig","topK"],u);const d=r(t,["maxOutputTokens"]);e!==void 0&&d!=null&&s(e,["setup","generationConfig","maxOutputTokens"],d);const c=r(t,["mediaResolution"]);e!==void 0&&c!=null&&s(e,["setup","generationConfig","mediaResolution"],c);const f=r(t,["seed"]);e!==void 0&&f!=null&&s(e,["setup","generationConfig","seed"],f);const h=r(t,["speechConfig"]);e!==void 0&&h!=null&&s(e,["setup","generationConfig","speechConfig"],ft(h));const p=r(t,["thinkingConfig"]);e!==void 0&&p!=null&&s(e,["setup","generationConfig","thinkingConfig"],p);const m=r(t,["enableAffectiveDialog"]);e!==void 0&&m!=null&&s(e,["setup","generationConfig","enableAffectiveDialog"],m);const g=r(t,["systemInstruction"]);e!==void 0&&g!=null&&s(e,["setup","systemInstruction"],Uu(L(g)));const v=r(t,["tools"]);if(e!==void 0&&v!=null){let _=ue(v);Array.isArray(_)&&(_=_.map(M=>$u(ae(M)))),s(e,["setup","tools"],_)}const y=r(t,["sessionResumption"]);e!==void 0&&y!=null&&s(e,["setup","sessionResumption"],Ju(y));const T=r(t,["inputAudioTranscription"]);e!==void 0&&T!=null&&s(e,["setup","inputAudioTranscription"],T);const I=r(t,["outputAudioTranscription"]);e!==void 0&&I!=null&&s(e,["setup","outputAudioTranscription"],I);const C=r(t,["realtimeInputConfig"]);e!==void 0&&C!=null&&s(e,["setup","realtimeInputConfig"],C);const S=r(t,["contextWindowCompression"]);e!==void 0&&S!=null&&s(e,["setup","contextWindowCompression"],S);const R=r(t,["proactivity"]);if(e!==void 0&&R!=null&&s(e,["setup","proactivity"],R),r(t,["explicitVadSignal"])!==void 0)throw new Error("explicitVadSignal parameter is not supported in Gemini API.");return n}function bu(t,e){const n={},o=r(e,["model"]);o!=null&&s(n,["setup","model"],N(t,o));const i=r(e,["config"]);return i!=null&&s(n,["config"],qu(i,n)),n}function Bu(t){const e={},n=r(t,["mediaResolution"]);n!=null&&s(e,["mediaResolution"],n);const o=r(t,["codeExecutionResult"]);o!=null&&s(e,["codeExecutionResult"],o);const i=r(t,["executableCode"]);i!=null&&s(e,["executableCode"],i);const l=r(t,["fileData"]);l!=null&&s(e,["fileData"],Fu(l));const a=r(t,["functionCall"]);a!=null&&s(e,["functionCall"],Gu(a));const u=r(t,["functionResponse"]);u!=null&&s(e,["functionResponse"],u);const d=r(t,["inlineData"]);d!=null&&s(e,["inlineData"],xu(d));const c=r(t,["text"]);c!=null&&s(e,["text"],c);const f=r(t,["thought"]);f!=null&&s(e,["thought"],f);const h=r(t,["thoughtSignature"]);h!=null&&s(e,["thoughtSignature"],h);const p=r(t,["videoMetadata"]);return p!=null&&s(e,["videoMetadata"],p),e}function Ju(t){const e={},n=r(t,["handle"]);if(n!=null&&s(e,["handle"],n),r(t,["transparent"])!==void 0)throw new Error("transparent parameter is not supported in Gemini API.");return e}function $u(t){const e={};if(r(t,["retrieval"])!==void 0)throw new Error("retrieval parameter is not supported in Gemini API.");const n=r(t,["computerUse"]);n!=null&&s(e,["computerUse"],n);const o=r(t,["fileSearch"]);o!=null&&s(e,["fileSearch"],o);const i=r(t,["googleSearch"]);i!=null&&s(e,["googleSearch"],Hu(i));const l=r(t,["codeExecution"]);if(l!=null&&s(e,["codeExecution"],l),r(t,["enterpriseWebSearch"])!==void 0)throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const a=r(t,["functionDeclarations"]);if(a!=null){let h=a;Array.isArray(h)&&(h=h.map(p=>p)),s(e,["functionDeclarations"],h)}const u=r(t,["googleMaps"]);u!=null&&s(e,["googleMaps"],Vu(u));const d=r(t,["googleSearchRetrieval"]);d!=null&&s(e,["googleSearchRetrieval"],d);const c=r(t,["urlContext"]);c!=null&&s(e,["urlContext"],c);const f=r(t,["mcpServers"]);if(f!=null){let h=f;Array.isArray(h)&&(h=h.map(p=>p)),s(e,["mcpServers"],h)}return e}/**
|
|
110
|
+
* @license
|
|
111
|
+
* Copyright 2025 Google LLC
|
|
112
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
113
|
+
*/function Ou(t){const e=[];for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const o=t[n];if(typeof o=="object"&&o!=null&&Object.keys(o).length>0){const i=Object.keys(o).map(l=>`${n}.${l}`);e.push(...i)}else e.push(n)}return e.join(",")}function Wu(t,e){let n=null;const o=t.bidiGenerateContentSetup;if(typeof o=="object"&&o!==null&&"setup"in o){const l=o.setup;typeof l=="object"&&l!==null?(t.bidiGenerateContentSetup=l,n=l):delete t.bidiGenerateContentSetup}else o!==void 0&&delete t.bidiGenerateContentSetup;const i=t.fieldMask;if(n){const l=Ou(n);if(Array.isArray(e?.lockAdditionalFields)&&e?.lockAdditionalFields.length===0)l?t.fieldMask=l:delete t.fieldMask;else if(e?.lockAdditionalFields&&e.lockAdditionalFields.length>0&&i!==null&&Array.isArray(i)&&i.length>0){const a=["temperature","topK","topP","maxOutputTokens","responseModalities","seed","speechConfig"];let u=[];i.length>0&&(u=i.map(c=>a.includes(c)?`generationConfig.${c}`:c));const d=[];l&&d.push(l),u.length>0&&d.push(...u),d.length>0?t.fieldMask=d.join(","):delete t.fieldMask}else delete t.fieldMask}else i!==null&&Array.isArray(i)&&i.length>0?t.fieldMask=i.join(","):delete t.fieldMask;return t}class Yu extends K{constructor(e){super(),this.apiClient=e}async create(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("The client.tokens.create method is only supported by the Gemini Developer API.");{const u=ku(this.apiClient,e);l=E("auth_tokens",u._url),a=u._query,delete u.config,delete u._url,delete u._query;const d=Wu(u,e.config);return i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),i.then(c=>c)}}}/**
|
|
114
|
+
* @license
|
|
115
|
+
* Copyright 2025 Google LLC
|
|
116
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
117
|
+
*/function Ku(t,e){const n={},o=r(t,["force"]);return e!==void 0&&o!=null&&s(e,["_query","force"],o),n}function zu(t){const e={},n=r(t,["name"]);n!=null&&s(e,["_url","name"],n);const o=r(t,["config"]);return o!=null&&Ku(o,e),e}function Xu(t){const e={},n=r(t,["name"]);return n!=null&&s(e,["_url","name"],n),e}function Qu(t,e){const n={},o=r(t,["pageSize"]);e!==void 0&&o!=null&&s(e,["_query","pageSize"],o);const i=r(t,["pageToken"]);return e!==void 0&&i!=null&&s(e,["_query","pageToken"],i),n}function Zu(t){const e={},n=r(t,["parent"]);n!=null&&s(e,["_url","parent"],n);const o=r(t,["config"]);return o!=null&&Qu(o,e),e}function ju(t){const e={},n=r(t,["sdkHttpResponse"]);n!=null&&s(e,["sdkHttpResponse"],n);const o=r(t,["nextPageToken"]);o!=null&&s(e,["nextPageToken"],o);const i=r(t,["documents"]);if(i!=null){let l=i;Array.isArray(l)&&(l=l.map(a=>a)),s(e,["documents"],l)}return e}/**
|
|
118
|
+
* @license
|
|
119
|
+
* Copyright 2025 Google LLC
|
|
120
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
121
|
+
*/class ec extends K{constructor(e){super(),this.apiClient=e,this.list=async n=>new j(Y.PAGED_ITEM_DOCUMENTS,o=>this.listInternal({parent:n.parent,config:o.config}),await this.listInternal(n),n)}async get(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Xu(e);return l=E("{name}",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>d)}}async delete(e){var n,o;let i="",l={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const a=zu(e);i=E("{name}",a._url),l=a._query,delete a._url,delete a._query,await this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(a),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal})}}async listInternal(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Zu(e);return l=E("{parent}/documents",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>{const c=ju(d),f=new Ri;return Object.assign(f,c),f})}}}/**
|
|
122
|
+
* @license
|
|
123
|
+
* Copyright 2025 Google LLC
|
|
124
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
125
|
+
*/class tc extends K{constructor(e,n=new ec(e)){super(),this.apiClient=e,this.documents=n,this.list=async(o={})=>new j(Y.PAGED_ITEM_FILE_SEARCH_STORES,i=>this.listInternal(i),await this.listInternal(o),o)}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 n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Ja(e);return l=E("fileSearchStores",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>d)}}async get(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Wa(e);return l=E("{name}",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>d)}}async delete(e){var n,o;let i="",l={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const a=Oa(e);i=E("{name}",a._url),l=a._query,delete a._url,delete a._query,await this.apiClient.request({path:i,queryParams:l,body:JSON.stringify(a),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal})}}async listInternal(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Za(e);return l=E("fileSearchStores",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>{const c=ja(d),f=new Pi;return Object.assign(f,c),f})}}async uploadToFileSearchStoreInternal(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=eu(e);return l=E("upload/v1beta/{file_search_store_name}:uploadToFileSearchStore",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>{const c=tu(d),f=new Mi;return Object.assign(f,c),f})}}async importFile(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=za(e);return l=E("{file_search_store_name}:importFile",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),i.then(d=>{const c=Ka(d),f=new lt;return Object.assign(f,c),f})}}}/**
|
|
126
|
+
* @license
|
|
127
|
+
* Copyright 2025 Google LLC
|
|
128
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
129
|
+
*/let Ro=function(){const{crypto:t}=globalThis;if(t?.randomUUID)return Ro=t.randomUUID.bind(t),t.randomUUID();const e=new Uint8Array(1),n=t?()=>t.getRandomValues(e)[0]:()=>Math.random()*255&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,o=>(+o^n()&15>>+o/4).toString(16))};const nc=()=>Ro();/**
|
|
130
|
+
* @license
|
|
131
|
+
* Copyright 2025 Google LLC
|
|
132
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
133
|
+
*/function et(t){return typeof t=="object"&&t!==null&&("name"in t&&t.name==="AbortError"||"message"in t&&String(t.message).includes("FetchRequestCanceledException"))}const tt=t=>{if(t instanceof Error)return t;if(typeof t=="object"&&t!==null){try{if(Object.prototype.toString.call(t)==="[object Error]"){const e=new Error(t.message,t.cause?{cause:t.cause}:{});return t.stack&&(e.stack=t.stack),t.cause&&!e.cause&&(e.cause=t.cause),t.name&&(e.name=t.name),e}}catch{}try{return new Error(JSON.stringify(t))}catch{}}return new Error(t)};/**
|
|
134
|
+
* @license
|
|
135
|
+
* Copyright 2025 Google LLC
|
|
136
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
137
|
+
*/class B extends Error{}class H extends B{constructor(e,n,o,i){super(`${H.makeMessage(e,n,o)}`),this.status=e,this.headers=i,this.error=n}static makeMessage(e,n,o){const i=n?.message?typeof n.message=="string"?n.message:JSON.stringify(n.message):n?JSON.stringify(n):o;return e&&i?`${e} ${i}`:e?`${e} status code (no body)`:i||"(no status code or body)"}static generate(e,n,o,i){if(!e||!i)return new Ue({message:o,cause:tt(n)});const l=n;return e===400?new Mo(e,l,o,i):e===401?new wo(e,l,o,i):e===403?new No(e,l,o,i):e===404?new Do(e,l,o,i):e===409?new xo(e,l,o,i):e===422?new Uo(e,l,o,i):e===429?new Lo(e,l,o,i):e>=500?new ko(e,l,o,i):new H(e,l,o,i)}}class nt extends H{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}}class Ue extends H{constructor({message:e,cause:n}){super(void 0,void 0,e||"Connection error.",void 0),n&&(this.cause=n)}}class Po extends Ue{constructor({message:e}={}){super({message:e??"Request timed out."})}}class Mo extends H{}class wo extends H{}class No extends H{}class Do extends H{}class xo extends H{}class Uo extends H{}class Lo extends H{}class ko extends H{}/**
|
|
138
|
+
* @license
|
|
139
|
+
* Copyright 2025 Google LLC
|
|
140
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
141
|
+
*/const oc=/^[a-z][a-z0-9+.-]*:/i,ic=t=>oc.test(t);let ot=t=>(ot=Array.isArray,ot(t));const rc=ot;let sc=rc;const Wn=sc;function lc(t){if(!t)return!0;for(const e in t)return!1;return!0}function ac(t,e){return Object.prototype.hasOwnProperty.call(t,e)}const uc=(t,e)=>{if(typeof e!="number"||!Number.isInteger(e))throw new B(`${t} must be an integer`);if(e<0)throw new B(`${t} must be a positive integer`);return e},cc=t=>{try{return JSON.parse(t)}catch{return}};/**
|
|
142
|
+
* @license
|
|
143
|
+
* Copyright 2025 Google LLC
|
|
144
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
145
|
+
*/const dc=t=>new Promise(e=>setTimeout(e,t));/**
|
|
146
|
+
* @license
|
|
147
|
+
* Copyright 2025 Google LLC
|
|
148
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
149
|
+
*/const ne="0.0.1";/**
|
|
150
|
+
* @license
|
|
151
|
+
* Copyright 2025 Google LLC
|
|
152
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
153
|
+
*/function fc(){return typeof Deno<"u"&&Deno.build!=null?"deno":typeof EdgeRuntime<"u"?"edge":Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]"?"node":"unknown"}const pc=()=>{var t,e,n,o,i;const l=fc();if(l==="deno")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ne,"X-Stainless-OS":Kn(Deno.build.os),"X-Stainless-Arch":Yn(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":typeof Deno.version=="string"?Deno.version:(e=(t=Deno.version)===null||t===void 0?void 0:t.deno)!==null&&e!==void 0?e:"unknown"};if(typeof EdgeRuntime<"u")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ne,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process.version};if(l==="node")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ne,"X-Stainless-OS":Kn((n=globalThis.process.platform)!==null&&n!==void 0?n:"unknown"),"X-Stainless-Arch":Yn((o=globalThis.process.arch)!==null&&o!==void 0?o:"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":(i=globalThis.process.version)!==null&&i!==void 0?i:"unknown"};const a=hc();return a?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ne,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${a.browser}`,"X-Stainless-Runtime-Version":a.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":ne,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};function hc(){if(typeof navigator>"u"||!navigator)return null;const t=[{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:e,pattern:n}of t){const o=n.exec(navigator.userAgent);if(o){const i=o[1]||0,l=o[2]||0,a=o[3]||0;return{browser:e,version:`${i}.${l}.${a}`}}}return null}const Yn=t=>t==="x32"?"x32":t==="x86_64"||t==="x64"?"x64":t==="arm"?"arm":t==="aarch64"||t==="arm64"?"arm64":t?`other:${t}`:"unknown",Kn=t=>(t=t.toLowerCase(),t.includes("ios")?"iOS":t==="android"?"Android":t==="darwin"?"MacOS":t==="win32"?"Windows":t==="freebsd"?"FreeBSD":t==="openbsd"?"OpenBSD":t==="linux"?"Linux":t?`Other:${t}`:"Unknown");let ye;const mc=()=>ye??(ye=pc());/**
|
|
154
|
+
* @license
|
|
155
|
+
* Copyright 2025 Google LLC
|
|
156
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
157
|
+
*/function gc(){if(typeof fetch<"u")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`")}function Fo(...t){const e=globalThis.ReadableStream;if(typeof e>"u")throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new e(...t)}function yc(t){let e=Symbol.asyncIterator in t?t[Symbol.asyncIterator]():t[Symbol.iterator]();return Fo({start(){},async pull(n){const{done:o,value:i}=await e.next();o?n.close():n.enqueue(i)},async cancel(){var n;await((n=e.return)===null||n===void 0?void 0:n.call(e))}})}function Go(t){if(t[Symbol.asyncIterator])return t;const e=t.getReader();return{async next(){try{const n=await e.read();return n?.done&&e.releaseLock(),n}catch(n){throw e.releaseLock(),n}},async return(){const n=e.cancel();return e.releaseLock(),await n,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function vc(t){var e,n;if(t===null||typeof t!="object")return;if(t[Symbol.asyncIterator]){await((n=(e=t[Symbol.asyncIterator]()).return)===null||n===void 0?void 0:n.call(e));return}const o=t.getReader(),i=o.cancel();o.releaseLock(),await i}/**
|
|
158
|
+
* @license
|
|
159
|
+
* Copyright 2025 Google LLC
|
|
160
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
161
|
+
*/const Tc=({headers:t,body:e})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(e)});/**
|
|
162
|
+
* @license
|
|
163
|
+
* Copyright 2025 Google LLC
|
|
164
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
165
|
+
*/const Vo=()=>{var t;if(typeof File>"u"){const{process:e}=globalThis,n=typeof((t=e?.versions)===null||t===void 0?void 0:t.node)=="string"&&parseInt(e.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`.":""))}};function qe(t,e,n){return Vo(),new File(t,e??"unknown_file",n)}function _c(t){return(typeof t=="object"&&t!==null&&("name"in t&&t.name&&String(t.name)||"url"in t&&t.url&&String(t.url)||"filename"in t&&t.filename&&String(t.filename)||"path"in t&&t.path&&String(t.path))||"").split(/[\\/]/).pop()||void 0}const Ec=t=>t!=null&&typeof t=="object"&&typeof t[Symbol.asyncIterator]=="function";/**
|
|
166
|
+
* @license
|
|
167
|
+
* Copyright 2025 Google LLC
|
|
168
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
169
|
+
*/const Ho=t=>t!=null&&typeof t=="object"&&typeof t.size=="number"&&typeof t.type=="string"&&typeof t.text=="function"&&typeof t.slice=="function"&&typeof t.arrayBuffer=="function",Cc=t=>t!=null&&typeof t=="object"&&typeof t.name=="string"&&typeof t.lastModified=="number"&&Ho(t),Sc=t=>t!=null&&typeof t=="object"&&typeof t.url=="string"&&typeof t.blob=="function";async function Ic(t,e,n){if(Vo(),t=await t,Cc(t))return t instanceof File?t:qe([await t.arrayBuffer()],t.name);if(Sc(t)){const i=await t.blob();return e||(e=new URL(t.url).pathname.split(/[\\/]/).pop()),qe(await it(i),e,n)}const o=await it(t);if(e||(e=_c(t)),!n?.type){const i=o.find(l=>typeof l=="object"&&"type"in l&&l.type);typeof i=="string"&&(n=Object.assign(Object.assign({},n),{type:i}))}return qe(o,e,n)}async function it(t){var e,n,o,i,l;let a=[];if(typeof t=="string"||ArrayBuffer.isView(t)||t instanceof ArrayBuffer)a.push(t);else if(Ho(t))a.push(t instanceof Blob?t:await t.arrayBuffer());else if(Ec(t))try{for(var u=!0,d=$(t),c;c=await d.next(),e=c.done,!e;u=!0){i=c.value,u=!1;const f=i;a.push(...await it(f))}}catch(f){n={error:f}}finally{try{!u&&!e&&(o=d.return)&&await o.call(d)}finally{if(n)throw n.error}}else{const f=(l=t?.constructor)===null||l===void 0?void 0:l.name;throw new Error(`Unexpected data type: ${typeof t}${f?`; constructor: ${f}`:""}${Ac(t)}`)}return a}function Ac(t){return typeof t!="object"||t===null?"":`; props: [${Object.getOwnPropertyNames(t).map(n=>`"${n}"`).join(", ")}]`}/**
|
|
170
|
+
* @license
|
|
171
|
+
* Copyright 2025 Google LLC
|
|
172
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
173
|
+
*/class qo{constructor(e){this._client=e}}qo._key=[];/**
|
|
174
|
+
* @license
|
|
175
|
+
* Copyright 2025 Google LLC
|
|
176
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
177
|
+
*/function bo(t){return t.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g,encodeURIComponent)}const zn=Object.freeze(Object.create(null)),Rc=(t=bo)=>(function(n,...o){if(n.length===1)return n[0];let i=!1;const l=[],a=n.reduce((f,h,p)=>{var m,g,v;/[?#]/.test(h)&&(i=!0);const y=o[p];let T=(i?encodeURIComponent:t)(""+y);return p!==o.length&&(y==null||typeof y=="object"&&y.toString===((v=Object.getPrototypeOf((g=Object.getPrototypeOf((m=y.hasOwnProperty)!==null&&m!==void 0?m:zn))!==null&&g!==void 0?g:zn))===null||v===void 0?void 0:v.toString))&&(T=y+"",l.push({start:f.length+h.length,length:T.length,error:`Value of type ${Object.prototype.toString.call(y).slice(8,-1)} is not a valid path parameter`})),f+h+(p===o.length?"":T)},""),u=a.split(/[?#]/,1)[0],d=/(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;let c;for(;(c=d.exec(u))!==null;){const f=c[0].startsWith("/"),h=f?1:0,p=f?c[0].slice(1):c[0];l.push({start:c.index+h,length:p.length,error:`Value "${p}" can't be safely passed as a path parameter`})}if(l.sort((f,h)=>f.start-h.start),l.length>0){let f=0;const h=l.reduce((p,m)=>{const g=" ".repeat(m.start-f),v="^".repeat(m.length);return f=m.start+m.length,p+g+v},"");throw new B(`Path parameters result in path with invalid segments:
|
|
178
|
+
${l.map(p=>p.error).join(`
|
|
179
|
+
`)}
|
|
180
|
+
${a}
|
|
181
|
+
${h}`)}return a}),ve=Rc(bo);/**
|
|
182
|
+
* @license
|
|
183
|
+
* Copyright 2025 Google LLC
|
|
184
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
185
|
+
*/class Bo extends qo{create(e,n){var o;const{api_version:i=this._client.apiVersion}=e,l=Me(e,["api_version"]);if("model"in l&&"agent_config"in l)throw new B("Invalid request: specified `model` and `agent_config`. If specifying `model`, use `generation_config`.");if("agent"in l&&"generation_config"in l)throw new B("Invalid request: specified `agent` and `generation_config`. If specifying `agent`, use `agent_config`.");return this._client.post(ve`/${i}/interactions`,Object.assign(Object.assign({body:l},n),{stream:(o=e.stream)!==null&&o!==void 0?o:!1}))}delete(e,n={},o){const{api_version:i=this._client.apiVersion}=n??{};return this._client.delete(ve`/${i}/interactions/${e}`,o)}cancel(e,n={},o){const{api_version:i=this._client.apiVersion}=n??{};return this._client.post(ve`/${i}/interactions/${e}/cancel`,o)}get(e,n={},o){var i;const l=n??{},{api_version:a=this._client.apiVersion}=l,u=Me(l,["api_version"]);return this._client.get(ve`/${a}/interactions/${e}`,Object.assign(Object.assign({query:u},o),{stream:(i=n?.stream)!==null&&i!==void 0?i:!1}))}}Bo._key=Object.freeze(["interactions"]);class Jo extends Bo{}/**
|
|
186
|
+
* @license
|
|
187
|
+
* Copyright 2025 Google LLC
|
|
188
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
189
|
+
*/function Pc(t){let e=0;for(const i of t)e+=i.length;const n=new Uint8Array(e);let o=0;for(const i of t)n.set(i,o),o+=i.length;return n}let Te;function ht(t){let e;return(Te??(e=new globalThis.TextEncoder,Te=e.encode.bind(e)))(t)}let _e;function Xn(t){let e;return(_e??(e=new globalThis.TextDecoder,_e=e.decode.bind(e)))(t)}/**
|
|
190
|
+
* @license
|
|
191
|
+
* Copyright 2025 Google LLC
|
|
192
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
193
|
+
*/class Le{constructor(){this.buffer=new Uint8Array,this.carriageReturnIndex=null}decode(e){if(e==null)return[];const n=e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?ht(e):e;this.buffer=Pc([this.buffer,n]);const o=[];let i;for(;(i=Mc(this.buffer,this.carriageReturnIndex))!=null;){if(i.carriage&&this.carriageReturnIndex==null){this.carriageReturnIndex=i.index;continue}if(this.carriageReturnIndex!=null&&(i.index!==this.carriageReturnIndex+1||i.carriage)){o.push(Xn(this.buffer.subarray(0,this.carriageReturnIndex-1))),this.buffer=this.buffer.subarray(this.carriageReturnIndex),this.carriageReturnIndex=null;continue}const l=this.carriageReturnIndex!==null?i.preceding-1:i.preceding,a=Xn(this.buffer.subarray(0,l));o.push(a),this.buffer=this.buffer.subarray(i.index),this.carriageReturnIndex=null}return o}flush(){return this.buffer.length?this.decode(`
|
|
194
|
+
`):[]}}Le.NEWLINE_CHARS=new Set([`
|
|
195
|
+
`,"\r"]);Le.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function Mc(t,e){for(let i=e??0;i<t.length;i++){if(t[i]===10)return{preceding:i,index:i+1,carriage:!1};if(t[i]===13)return{preceding:i,index:i+1,carriage:!0}}return null}function wc(t){for(let o=0;o<t.length-1;o++){if(t[o]===10&&t[o+1]===10||t[o]===13&&t[o+1]===13)return o+2;if(t[o]===13&&t[o+1]===10&&o+3<t.length&&t[o+2]===13&&t[o+3]===10)return o+4}return-1}/**
|
|
196
|
+
* @license
|
|
197
|
+
* Copyright 2025 Google LLC
|
|
198
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
199
|
+
*/const we={off:0,error:200,warn:300,info:400,debug:500},Qn=(t,e,n)=>{if(t){if(ac(we,t))return t;V(n).warn(`${e} was set to ${JSON.stringify(t)}, expected one of ${JSON.stringify(Object.keys(we))}`)}};function he(){}function Ee(t,e,n){return!e||we[t]>we[n]?he:e[t].bind(e)}const Nc={error:he,warn:he,info:he,debug:he};let Zn=new WeakMap;function V(t){var e;const n=t.logger,o=(e=t.logLevel)!==null&&e!==void 0?e:"off";if(!n)return Nc;const i=Zn.get(n);if(i&&i[0]===o)return i[1];const l={error:Ee("error",n,o),warn:Ee("warn",n,o),info:Ee("info",n,o),debug:Ee("debug",n,o)};return Zn.set(n,[o,l]),l}const Z=t=>(t.options&&(t.options=Object.assign({},t.options),delete t.options.headers),t.headers&&(t.headers=Object.fromEntries((t.headers instanceof Headers?[...t.headers]:Object.entries(t.headers)).map(([e,n])=>[e,e.toLowerCase()==="x-goog-api-key"||e.toLowerCase()==="authorization"||e.toLowerCase()==="cookie"||e.toLowerCase()==="set-cookie"?"***":n]))),"retryOfRequestLogID"in t&&(t.retryOfRequestLogID&&(t.retryOf=t.retryOfRequestLogID),delete t.retryOfRequestLogID),t);/**
|
|
200
|
+
* @license
|
|
201
|
+
* Copyright 2025 Google LLC
|
|
202
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
203
|
+
*/class re{constructor(e,n,o){this.iterator=e,this.controller=n,this.client=o}static fromSSEResponse(e,n,o){let i=!1;const l=o?V(o):console;function a(){return J(this,arguments,function*(){var d,c,f,h;if(i)throw new B("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let p=!1;try{try{for(var m=!0,g=$(Dc(e,n)),v;v=yield P(g.next()),d=v.done,!d;m=!0){h=v.value,m=!1;const y=h;if(!p)if(y.data.startsWith("[DONE]")){p=!0;continue}else try{yield yield P(JSON.parse(y.data))}catch(T){throw l.error("Could not parse message into JSON:",y.data),l.error("From chunk:",y.raw),T}}}catch(y){c={error:y}}finally{try{!m&&!d&&(f=g.return)&&(yield P(f.call(g)))}finally{if(c)throw c.error}}p=!0}catch(y){if(et(y))return yield P(void 0);throw y}finally{p||n.abort()}})}return new re(a,n,o)}static fromReadableStream(e,n,o){let i=!1;function l(){return J(this,arguments,function*(){var d,c,f,h;const p=new Le,m=Go(e);try{for(var g=!0,v=$(m),y;y=yield P(v.next()),d=y.done,!d;g=!0){h=y.value,g=!1;const T=h;for(const I of p.decode(T))yield yield P(I)}}catch(T){c={error:T}}finally{try{!g&&!d&&(f=v.return)&&(yield P(f.call(v)))}finally{if(c)throw c.error}}for(const T of p.flush())yield yield P(T)})}function a(){return J(this,arguments,function*(){var d,c,f,h;if(i)throw new B("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let p=!1;try{try{for(var m=!0,g=$(l()),v;v=yield P(g.next()),d=v.done,!d;m=!0){h=v.value,m=!1;const y=h;p||y&&(yield yield P(JSON.parse(y)))}}catch(y){c={error:y}}finally{try{!m&&!d&&(f=g.return)&&(yield P(f.call(g)))}finally{if(c)throw c.error}}p=!0}catch(y){if(et(y))return yield P(void 0);throw y}finally{p||n.abort()}})}return new re(a,n,o)}[Symbol.asyncIterator](){return this.iterator()}tee(){const e=[],n=[],o=this.iterator(),i=l=>({next:()=>{if(l.length===0){const a=o.next();e.push(a),n.push(a)}return l.shift()}});return[new re(()=>i(e),this.controller,this.client),new re(()=>i(n),this.controller,this.client)]}toReadableStream(){const e=this;let n;return Fo({async start(){n=e[Symbol.asyncIterator]()},async pull(o){try{const{value:i,done:l}=await n.next();if(l)return o.close();const a=ht(JSON.stringify(i)+`
|
|
204
|
+
`);o.enqueue(a)}catch(i){o.error(i)}},async cancel(){var o;await((o=n.return)===null||o===void 0?void 0:o.call(n))}})}}function Dc(t,e){return J(this,arguments,function*(){var o,i,l,a;if(!t.body)throw e.abort(),typeof globalThis.navigator<"u"&&globalThis.navigator.product==="ReactNative"?new B("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api"):new B("Attempted to iterate over a response with no body");const u=new Uc,d=new Le,c=Go(t.body);try{for(var f=!0,h=$(xc(c)),p;p=yield P(h.next()),o=p.done,!o;f=!0){a=p.value,f=!1;const m=a;for(const g of d.decode(m)){const v=u.decode(g);v&&(yield yield P(v))}}}catch(m){i={error:m}}finally{try{!f&&!o&&(l=h.return)&&(yield P(l.call(h)))}finally{if(i)throw i.error}}for(const m of d.flush()){const g=u.decode(m);g&&(yield yield P(g))}})}function xc(t){return J(this,arguments,function*(){var n,o,i,l;let a=new Uint8Array;try{for(var u=!0,d=$(t),c;c=yield P(d.next()),n=c.done,!n;u=!0){l=c.value,u=!1;const f=l;if(f==null)continue;const h=f instanceof ArrayBuffer?new Uint8Array(f):typeof f=="string"?ht(f):f;let p=new Uint8Array(a.length+h.length);p.set(a),p.set(h,a.length),a=p;let m;for(;(m=wc(a))!==-1;)yield yield P(a.slice(0,m)),a=a.slice(m)}}catch(f){o={error:f}}finally{try{!u&&!n&&(i=d.return)&&(yield P(i.call(d)))}finally{if(o)throw o.error}}a.length>0&&(yield yield P(a))})}class Uc{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 l={event:this.event,data:this.data.join(`
|
|
205
|
+
`),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],l}if(this.chunks.push(e),e.startsWith(":"))return null;let[n,o,i]=Lc(e,":");return i.startsWith(" ")&&(i=i.substring(1)),n==="event"?this.event=i:n==="data"&&this.data.push(i),null}}function Lc(t,e){const n=t.indexOf(e);return n!==-1?[t.substring(0,n),e,t.substring(n+e.length)]:[t,"",""]}/**
|
|
206
|
+
* @license
|
|
207
|
+
* Copyright 2025 Google LLC
|
|
208
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
209
|
+
*/async function kc(t,e){const{response:n,requestLogID:o,retryOfRequestLogID:i,startTime:l}=e,a=await(async()=>{var u;if(e.options.stream)return V(t).debug("response",n.status,n.url,n.headers,n.body),e.options.__streamClass?e.options.__streamClass.fromSSEResponse(n,e.controller,t):re.fromSSEResponse(n,e.controller,t);if(n.status===204)return null;if(e.options.__binaryResponse)return n;const d=n.headers.get("content-type"),c=(u=d?.split(";")[0])===null||u===void 0?void 0:u.trim();return c?.includes("application/json")||c?.endsWith("+json")?n.headers.get("content-length")==="0"?void 0:await n.json():await n.text()})();return V(t).debug(`[${o}] response parsed`,Z({retryOfRequestLogID:i,url:n.url,status:n.status,body:a,durationMs:Date.now()-l})),a}/**
|
|
210
|
+
* @license
|
|
211
|
+
* Copyright 2025 Google LLC
|
|
212
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
213
|
+
*/class mt extends Promise{constructor(e,n,o=kc){super(i=>{i(null)}),this.responsePromise=n,this.parseResponse=o,this.client=e}_thenUnwrap(e){return new mt(this.client,this.responsePromise,async(n,o)=>e(await this.parseResponse(n,o),o))}asResponse(){return this.responsePromise.then(e=>e.response)}async withResponse(){const[e,n]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:n}}parse(){return this.parsedPromise||(this.parsedPromise=this.responsePromise.then(e=>this.parseResponse(this.client,e))),this.parsedPromise}then(e,n){return this.parse().then(e,n)}catch(e){return this.parse().catch(e)}finally(e){return this.parse().finally(e)}}/**
|
|
214
|
+
* @license
|
|
215
|
+
* Copyright 2025 Google LLC
|
|
216
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
217
|
+
*/const $o=Symbol("brand.privateNullableHeaders");function*Fc(t){if(!t)return;if($o in t){const{values:o,nulls:i}=t;yield*o.entries();for(const l of i)yield[l,null];return}let e=!1,n;t instanceof Headers?n=t.entries():Wn(t)?n=t:(e=!0,n=Object.entries(t??{}));for(let o of n){const i=o[0];if(typeof i!="string")throw new TypeError("expected header name to be a string");const l=Wn(o[1])?o[1]:[o[1]];let a=!1;for(const u of l)u!==void 0&&(e&&!a&&(a=!0,yield[i,null]),yield[i,u])}}const pe=t=>{const e=new Headers,n=new Set;for(const o of t){const i=new Set;for(const[l,a]of Fc(o)){const u=l.toLowerCase();i.has(u)||(e.delete(l),i.add(u)),a===null?(e.delete(l),n.add(u)):(e.append(l,a),n.delete(u))}}return{[$o]:!0,values:e,nulls:n}};/**
|
|
218
|
+
* @license
|
|
219
|
+
* Copyright 2025 Google LLC
|
|
220
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
221
|
+
*/const be=t=>{var e,n,o,i,l,a;if(typeof globalThis.process<"u")return(o=(n=(e=ti)===null||e===void 0?void 0:e[t])===null||n===void 0?void 0:n.trim())!==null&&o!==void 0?o:void 0;if(typeof globalThis.Deno<"u")return(a=(l=(i=globalThis.Deno.env)===null||i===void 0?void 0:i.get)===null||l===void 0?void 0:l.call(i,t))===null||a===void 0?void 0:a.trim()};/**
|
|
222
|
+
* @license
|
|
223
|
+
* Copyright 2025 Google LLC
|
|
224
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
225
|
+
*/var Oo;class ke{constructor(e){var n,o,i,l,a,u,d,{baseURL:c=be("GEMINI_NEXT_GEN_API_BASE_URL"),apiKey:f=(n=be("GEMINI_API_KEY"))!==null&&n!==void 0?n:null,apiVersion:h="v1beta"}=e,p=Me(e,["baseURL","apiKey","apiVersion"]);const m=Object.assign(Object.assign({apiKey:f,apiVersion:h},p),{baseURL:c||"https://generativelanguage.googleapis.com"});this.baseURL=m.baseURL,this.timeout=(o=m.timeout)!==null&&o!==void 0?o:ke.DEFAULT_TIMEOUT,this.logger=(i=m.logger)!==null&&i!==void 0?i:console;const g="warn";this.logLevel=g,this.logLevel=(a=(l=Qn(m.logLevel,"ClientOptions.logLevel",this))!==null&&l!==void 0?l:Qn(be("GEMINI_NEXT_GEN_API_LOG"),"process.env['GEMINI_NEXT_GEN_API_LOG']",this))!==null&&a!==void 0?a:g,this.fetchOptions=m.fetchOptions,this.maxRetries=(u=m.maxRetries)!==null&&u!==void 0?u:2,this.fetch=(d=m.fetch)!==null&&d!==void 0?d:gc(),this.encoder=Tc,this._options=m,this.apiKey=f,this.apiVersion=h,this.clientAdapter=m.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 this.baseURL!=="https://generativelanguage.googleapis.com"}defaultQuery(){return this._options.defaultQuery}validateHeaders({values:e,nulls:n}){if(!(e.has("authorization")||e.has("x-goog-api-key"))&&!(this.apiKey&&e.get("x-goog-api-key"))&&!n.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 n=pe([e.headers]);if(!(n.values.has("authorization")||n.values.has("x-goog-api-key"))){if(this.apiKey)return pe([{"x-goog-api-key":this.apiKey}]);if(this.clientAdapter.isVertexAI())return pe([await this.clientAdapter.getAuthHeaders()])}}stringifyQuery(e){return Object.entries(e).filter(([n,o])=>typeof o<"u").map(([n,o])=>{if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return`${encodeURIComponent(n)}=${encodeURIComponent(o)}`;if(o===null)return`${encodeURIComponent(n)}=`;throw new B(`Cannot stringify type ${typeof o}; 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 ${ne}`}defaultIdempotencyKey(){return`stainless-node-retry-${nc()}`}makeStatusError(e,n,o,i){return H.generate(e,n,o,i)}buildURL(e,n,o){const i=!this.baseURLOverridden()&&o||this.baseURL,l=ic(e)?new URL(e):new URL(i+(i.endsWith("/")&&e.startsWith("/")?e.slice(1):e)),a=this.defaultQuery();return lc(a)||(n=Object.assign(Object.assign({},a),n)),typeof n=="object"&&n&&!Array.isArray(n)&&(l.search=this.stringifyQuery(n)),l.toString()}async prepareOptions(e){if(this.clientAdapter&&this.clientAdapter.isVertexAI()&&!e.path.startsWith(`/${this.apiVersion}/projects/`)){const n=e.path.slice(this.apiVersion.length+1);e.path=`/${this.apiVersion}/projects/${this.clientAdapter.getProject()}/locations/${this.clientAdapter.getLocation()}${n}`}}async prepareRequest(e,{url:n,options:o}){}get(e,n){return this.methodRequest("get",e,n)}post(e,n){return this.methodRequest("post",e,n)}patch(e,n){return this.methodRequest("patch",e,n)}put(e,n){return this.methodRequest("put",e,n)}delete(e,n){return this.methodRequest("delete",e,n)}methodRequest(e,n,o){return this.request(Promise.resolve(o).then(i=>Object.assign({method:e,path:n},i)))}request(e,n=null){return new mt(this,this.makeRequest(e,n,void 0))}async makeRequest(e,n,o){var i,l,a;const u=await e,d=(i=u.maxRetries)!==null&&i!==void 0?i:this.maxRetries;n==null&&(n=d),await this.prepareOptions(u);const{req:c,url:f,timeout:h}=await this.buildRequest(u,{retryCount:d-n});await this.prepareRequest(c,{url:f,options:u});const p="log_"+(Math.random()*(1<<24)|0).toString(16).padStart(6,"0"),m=o===void 0?"":`, retryOf: ${o}`,g=Date.now();if(V(this).debug(`[${p}] sending request`,Z({retryOfRequestLogID:o,method:u.method,url:f,options:u,headers:c.headers})),!((l=u.signal)===null||l===void 0)&&l.aborted)throw new nt;const v=new AbortController,y=await this.fetchWithTimeout(f,c,h,v).catch(tt),T=Date.now();if(y instanceof globalThis.Error){const C=`retrying, ${n} attempts remaining`;if(!((a=u.signal)===null||a===void 0)&&a.aborted)throw new nt;const S=et(y)||/timed? ?out/i.test(String(y)+("cause"in y?String(y.cause):""));if(n)return V(this).info(`[${p}] connection ${S?"timed out":"failed"} - ${C}`),V(this).debug(`[${p}] connection ${S?"timed out":"failed"} (${C})`,Z({retryOfRequestLogID:o,url:f,durationMs:T-g,message:y.message})),this.retryRequest(u,n,o??p);throw V(this).info(`[${p}] connection ${S?"timed out":"failed"} - error; no more retries left`),V(this).debug(`[${p}] connection ${S?"timed out":"failed"} (error; no more retries left)`,Z({retryOfRequestLogID:o,url:f,durationMs:T-g,message:y.message})),S?new Po:new Ue({cause:y})}const I=`[${p}${m}] ${c.method} ${f} ${y.ok?"succeeded":"failed"} with status ${y.status} in ${T-g}ms`;if(!y.ok){const C=await this.shouldRetry(y);if(n&&C){const A=`retrying, ${n} attempts remaining`;return await vc(y.body),V(this).info(`${I} - ${A}`),V(this).debug(`[${p}] response error (${A})`,Z({retryOfRequestLogID:o,url:y.url,status:y.status,headers:y.headers,durationMs:T-g})),this.retryRequest(u,n,o??p,y.headers)}const S=C?"error; no more retries left":"error; not retryable";V(this).info(`${I} - ${S}`);const R=await y.text().catch(A=>tt(A).message),_=cc(R),M=_?void 0:R;throw V(this).debug(`[${p}] response error (${S})`,Z({retryOfRequestLogID:o,url:y.url,status:y.status,headers:y.headers,message:M,durationMs:Date.now()-g})),this.makeStatusError(y.status,_,M,y.headers)}return V(this).info(I),V(this).debug(`[${p}] response start`,Z({retryOfRequestLogID:o,url:y.url,status:y.status,headers:y.headers,durationMs:T-g})),{response:y,options:u,controller:v,requestLogID:p,retryOfRequestLogID:o,startTime:g}}async fetchWithTimeout(e,n,o,i){const l=n||{},{signal:a,method:u}=l,d=Me(l,["signal","method"]),c=this._makeAbort(i);a&&a.addEventListener("abort",c,{once:!0});const f=setTimeout(c,o),h=globalThis.ReadableStream&&d.body instanceof globalThis.ReadableStream||typeof d.body=="object"&&d.body!==null&&Symbol.asyncIterator in d.body,p=Object.assign(Object.assign(Object.assign({signal:i.signal},h?{duplex:"half"}:{}),{method:"GET"}),d);u&&(p.method=u.toUpperCase());try{return await this.fetch.call(void 0,e,p)}finally{clearTimeout(f)}}async shouldRetry(e){const n=e.headers.get("x-should-retry");return n==="true"?!0:n==="false"?!1:e.status===408||e.status===409||e.status===429||e.status>=500}async retryRequest(e,n,o,i){var l;let a;const u=i?.get("retry-after-ms");if(u){const c=parseFloat(u);Number.isNaN(c)||(a=c)}const d=i?.get("retry-after");if(d&&!a){const c=parseFloat(d);Number.isNaN(c)?a=Date.parse(d)-Date.now():a=c*1e3}if(!(a&&0<=a&&a<60*1e3)){const c=(l=e.maxRetries)!==null&&l!==void 0?l:this.maxRetries;a=this.calculateDefaultRetryTimeoutMillis(n,c)}return await dc(a),this.makeRequest(e,n-1,o)}calculateDefaultRetryTimeoutMillis(e,n){const l=n-e,a=Math.min(.5*Math.pow(2,l),8),u=1-Math.random()*.25;return a*u*1e3}async buildRequest(e,{retryCount:n=0}={}){var o,i,l;const a=Object.assign({},e),{method:u,path:d,query:c,defaultBaseURL:f}=a,h=this.buildURL(d,c,f);"timeout"in a&&uc("timeout",a.timeout),a.timeout=(o=a.timeout)!==null&&o!==void 0?o:this.timeout;const{bodyHeaders:p,body:m}=this.buildBody({options:a}),g=await this.buildHeaders({options:e,method:u,bodyHeaders:p,retryCount:n});return{req:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({method:u,headers:g},a.signal&&{signal:a.signal}),globalThis.ReadableStream&&m instanceof globalThis.ReadableStream&&{duplex:"half"}),m&&{body:m}),(i=this.fetchOptions)!==null&&i!==void 0?i:{}),(l=a.fetchOptions)!==null&&l!==void 0?l:{}),url:h,timeout:a.timeout}}async buildHeaders({options:e,method:n,bodyHeaders:o,retryCount:i}){let l={};this.idempotencyHeader&&n!=="get"&&(e.idempotencyKey||(e.idempotencyKey=this.defaultIdempotencyKey()),l[this.idempotencyHeader]=e.idempotencyKey);const a=await this.authHeaders(e);let u=pe([l,Object.assign(Object.assign({Accept:"application/json","User-Agent":this.getUserAgent(),"X-Stainless-Retry-Count":String(i)},e.timeout?{"X-Stainless-Timeout":String(Math.trunc(e.timeout/1e3))}:{}),mc()),this._options.defaultHeaders,o,e.headers,a]);return this.validateHeaders(u),u.values}_makeAbort(e){return()=>e.abort()}buildBody({options:{body:e,headers:n}}){if(!e)return{bodyHeaders:void 0,body:void 0};const o=pe([n]);return ArrayBuffer.isView(e)||e instanceof ArrayBuffer||e instanceof DataView||typeof e=="string"&&o.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}:typeof e=="object"&&(Symbol.asyncIterator in e||Symbol.iterator in e&&"next"in e&&typeof e.next=="function")?{bodyHeaders:void 0,body:yc(e)}:typeof e=="object"&&o.values.get("content-type")==="application/x-www-form-urlencoded"?{bodyHeaders:{"content-type":"application/x-www-form-urlencoded"},body:this.stringifyQuery(e)}:this.encoder({body:e,headers:o})}}ke.DEFAULT_TIMEOUT=6e4;class k extends ke{constructor(){super(...arguments),this.interactions=new Jo(this)}}Oo=k;k.GeminiNextGenAPIClient=Oo;k.GeminiNextGenAPIClientError=B;k.APIError=H;k.APIConnectionError=Ue;k.APIConnectionTimeoutError=Po;k.APIUserAbortError=nt;k.NotFoundError=Do;k.ConflictError=xo;k.RateLimitError=Lo;k.BadRequestError=Mo;k.AuthenticationError=wo;k.InternalServerError=ko;k.PermissionDeniedError=No;k.UnprocessableEntityError=Uo;k.toFile=Ic;k.Interactions=Jo;/**
|
|
226
|
+
* @license
|
|
227
|
+
* Copyright 2025 Google LLC
|
|
228
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
229
|
+
*/function Gc(t,e){const n={},o=r(t,["name"]);return o!=null&&s(n,["_url","name"],o),n}function Vc(t,e){const n={},o=r(t,["name"]);return o!=null&&s(n,["_url","name"],o),n}function Hc(t,e){const n={},o=r(t,["sdkHttpResponse"]);return o!=null&&s(n,["sdkHttpResponse"],o),n}function qc(t,e){const n={},o=r(t,["sdkHttpResponse"]);return o!=null&&s(n,["sdkHttpResponse"],o),n}function bc(t,e,n){const o={};if(r(t,["validationDataset"])!==void 0)throw new Error("validationDataset parameter is not supported in Gemini API.");const i=r(t,["tunedModelDisplayName"]);if(e!==void 0&&i!=null&&s(e,["displayName"],i),r(t,["description"])!==void 0)throw new Error("description parameter is not supported in Gemini API.");const l=r(t,["epochCount"]);e!==void 0&&l!=null&&s(e,["tuningTask","hyperparameters","epochCount"],l);const a=r(t,["learningRateMultiplier"]);if(a!=null&&s(o,["tuningTask","hyperparameters","learningRateMultiplier"],a),r(t,["exportLastCheckpointOnly"])!==void 0)throw new Error("exportLastCheckpointOnly parameter is not supported in Gemini API.");if(r(t,["preTunedModelCheckpointId"])!==void 0)throw new Error("preTunedModelCheckpointId parameter is not supported in Gemini API.");if(r(t,["adapterSize"])!==void 0)throw new Error("adapterSize parameter is not supported in Gemini API.");if(r(t,["tuningMode"])!==void 0)throw new Error("tuningMode parameter is not supported in Gemini API.");if(r(t,["customBaseModel"])!==void 0)throw new Error("customBaseModel parameter is not supported in Gemini API.");const u=r(t,["batchSize"]);e!==void 0&&u!=null&&s(e,["tuningTask","hyperparameters","batchSize"],u);const d=r(t,["learningRate"]);if(e!==void 0&&d!=null&&s(e,["tuningTask","hyperparameters","learningRate"],d),r(t,["labels"])!==void 0)throw new Error("labels parameter is not supported in Gemini API.");if(r(t,["beta"])!==void 0)throw new Error("beta parameter is not supported in Gemini API.");if(r(t,["baseTeacherModel"])!==void 0)throw new Error("baseTeacherModel parameter is not supported in Gemini API.");if(r(t,["tunedTeacherModelSource"])!==void 0)throw new Error("tunedTeacherModelSource parameter is not supported in Gemini API.");if(r(t,["sftLossWeightMultiplier"])!==void 0)throw new Error("sftLossWeightMultiplier parameter is not supported in Gemini API.");if(r(t,["outputUri"])!==void 0)throw new Error("outputUri parameter is not supported in Gemini API.");if(r(t,["encryptionSpec"])!==void 0)throw new Error("encryptionSpec parameter is not supported in Gemini API.");return o}function Bc(t,e,n){const o={};let i=r(n,["config","method"]);if(i===void 0&&(i="SUPERVISED_FINE_TUNING"),i==="SUPERVISED_FINE_TUNING"){const _=r(t,["validationDataset"]);e!==void 0&&_!=null&&s(e,["supervisedTuningSpec"],Be(_))}else if(i==="PREFERENCE_TUNING"){const _=r(t,["validationDataset"]);e!==void 0&&_!=null&&s(e,["preferenceOptimizationSpec"],Be(_))}else if(i==="DISTILLATION"){const _=r(t,["validationDataset"]);e!==void 0&&_!=null&&s(e,["distillationSpec"],Be(_))}const l=r(t,["tunedModelDisplayName"]);e!==void 0&&l!=null&&s(e,["tunedModelDisplayName"],l);const a=r(t,["description"]);e!==void 0&&a!=null&&s(e,["description"],a);let u=r(n,["config","method"]);if(u===void 0&&(u="SUPERVISED_FINE_TUNING"),u==="SUPERVISED_FINE_TUNING"){const _=r(t,["epochCount"]);e!==void 0&&_!=null&&s(e,["supervisedTuningSpec","hyperParameters","epochCount"],_)}else if(u==="PREFERENCE_TUNING"){const _=r(t,["epochCount"]);e!==void 0&&_!=null&&s(e,["preferenceOptimizationSpec","hyperParameters","epochCount"],_)}else if(u==="DISTILLATION"){const _=r(t,["epochCount"]);e!==void 0&&_!=null&&s(e,["distillationSpec","hyperParameters","epochCount"],_)}let d=r(n,["config","method"]);if(d===void 0&&(d="SUPERVISED_FINE_TUNING"),d==="SUPERVISED_FINE_TUNING"){const _=r(t,["learningRateMultiplier"]);e!==void 0&&_!=null&&s(e,["supervisedTuningSpec","hyperParameters","learningRateMultiplier"],_)}else if(d==="PREFERENCE_TUNING"){const _=r(t,["learningRateMultiplier"]);e!==void 0&&_!=null&&s(e,["preferenceOptimizationSpec","hyperParameters","learningRateMultiplier"],_)}else if(d==="DISTILLATION"){const _=r(t,["learningRateMultiplier"]);e!==void 0&&_!=null&&s(e,["distillationSpec","hyperParameters","learningRateMultiplier"],_)}let c=r(n,["config","method"]);if(c===void 0&&(c="SUPERVISED_FINE_TUNING"),c==="SUPERVISED_FINE_TUNING"){const _=r(t,["exportLastCheckpointOnly"]);e!==void 0&&_!=null&&s(e,["supervisedTuningSpec","exportLastCheckpointOnly"],_)}else if(c==="PREFERENCE_TUNING"){const _=r(t,["exportLastCheckpointOnly"]);e!==void 0&&_!=null&&s(e,["preferenceOptimizationSpec","exportLastCheckpointOnly"],_)}else if(c==="DISTILLATION"){const _=r(t,["exportLastCheckpointOnly"]);e!==void 0&&_!=null&&s(e,["distillationSpec","exportLastCheckpointOnly"],_)}let f=r(n,["config","method"]);if(f===void 0&&(f="SUPERVISED_FINE_TUNING"),f==="SUPERVISED_FINE_TUNING"){const _=r(t,["adapterSize"]);e!==void 0&&_!=null&&s(e,["supervisedTuningSpec","hyperParameters","adapterSize"],_)}else if(f==="PREFERENCE_TUNING"){const _=r(t,["adapterSize"]);e!==void 0&&_!=null&&s(e,["preferenceOptimizationSpec","hyperParameters","adapterSize"],_)}else if(f==="DISTILLATION"){const _=r(t,["adapterSize"]);e!==void 0&&_!=null&&s(e,["distillationSpec","hyperParameters","adapterSize"],_)}let h=r(n,["config","method"]);if(h===void 0&&(h="SUPERVISED_FINE_TUNING"),h==="SUPERVISED_FINE_TUNING"){const _=r(t,["tuningMode"]);e!==void 0&&_!=null&&s(e,["supervisedTuningSpec","tuningMode"],_)}const p=r(t,["customBaseModel"]);e!==void 0&&p!=null&&s(e,["customBaseModel"],p);let m=r(n,["config","method"]);if(m===void 0&&(m="SUPERVISED_FINE_TUNING"),m==="SUPERVISED_FINE_TUNING"){const _=r(t,["batchSize"]);e!==void 0&&_!=null&&s(e,["supervisedTuningSpec","hyperParameters","batchSize"],_)}let g=r(n,["config","method"]);if(g===void 0&&(g="SUPERVISED_FINE_TUNING"),g==="SUPERVISED_FINE_TUNING"){const _=r(t,["learningRate"]);e!==void 0&&_!=null&&s(e,["supervisedTuningSpec","hyperParameters","learningRate"],_)}const v=r(t,["labels"]);e!==void 0&&v!=null&&s(e,["labels"],v);const y=r(t,["beta"]);e!==void 0&&y!=null&&s(e,["preferenceOptimizationSpec","hyperParameters","beta"],y);const T=r(t,["baseTeacherModel"]);e!==void 0&&T!=null&&s(e,["distillationSpec","baseTeacherModel"],T);const I=r(t,["tunedTeacherModelSource"]);e!==void 0&&I!=null&&s(e,["distillationSpec","tunedTeacherModelSource"],I);const C=r(t,["sftLossWeightMultiplier"]);e!==void 0&&C!=null&&s(e,["distillationSpec","hyperParameters","sftLossWeightMultiplier"],C);const S=r(t,["outputUri"]);e!==void 0&&S!=null&&s(e,["outputUri"],S);const R=r(t,["encryptionSpec"]);return e!==void 0&&R!=null&&s(e,["encryptionSpec"],R),o}function Jc(t,e){const n={},o=r(t,["baseModel"]);o!=null&&s(n,["baseModel"],o);const i=r(t,["preTunedModel"]);i!=null&&s(n,["preTunedModel"],i);const l=r(t,["trainingDataset"]);l!=null&&ed(l);const a=r(t,["config"]);return a!=null&&bc(a,n),n}function $c(t,e){const n={},o=r(t,["baseModel"]);o!=null&&s(n,["baseModel"],o);const i=r(t,["preTunedModel"]);i!=null&&s(n,["preTunedModel"],i);const l=r(t,["trainingDataset"]);l!=null&&td(l,n,e);const a=r(t,["config"]);return a!=null&&Bc(a,n,e),n}function Oc(t,e){const n={},o=r(t,["name"]);return o!=null&&s(n,["_url","name"],o),n}function Wc(t,e){const n={},o=r(t,["name"]);return o!=null&&s(n,["_url","name"],o),n}function Yc(t,e,n){const o={},i=r(t,["pageSize"]);e!==void 0&&i!=null&&s(e,["_query","pageSize"],i);const l=r(t,["pageToken"]);e!==void 0&&l!=null&&s(e,["_query","pageToken"],l);const a=r(t,["filter"]);return e!==void 0&&a!=null&&s(e,["_query","filter"],a),o}function Kc(t,e,n){const o={},i=r(t,["pageSize"]);e!==void 0&&i!=null&&s(e,["_query","pageSize"],i);const l=r(t,["pageToken"]);e!==void 0&&l!=null&&s(e,["_query","pageToken"],l);const a=r(t,["filter"]);return e!==void 0&&a!=null&&s(e,["_query","filter"],a),o}function zc(t,e){const n={},o=r(t,["config"]);return o!=null&&Yc(o,n),n}function Xc(t,e){const n={},o=r(t,["config"]);return o!=null&&Kc(o,n),n}function Qc(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["nextPageToken"]);i!=null&&s(n,["nextPageToken"],i);const l=r(t,["tunedModels"]);if(l!=null){let a=l;Array.isArray(a)&&(a=a.map(u=>Wo(u))),s(n,["tuningJobs"],a)}return n}function Zc(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["nextPageToken"]);i!=null&&s(n,["nextPageToken"],i);const l=r(t,["tuningJobs"]);if(l!=null){let a=l;Array.isArray(a)&&(a=a.map(u=>rt(u))),s(n,["tuningJobs"],a)}return n}function jc(t,e){const n={},o=r(t,["name"]);o!=null&&s(n,["model"],o);const i=r(t,["name"]);return i!=null&&s(n,["endpoint"],i),n}function ed(t,e){const n={};if(r(t,["gcsUri"])!==void 0)throw new Error("gcsUri parameter is not supported in Gemini API.");if(r(t,["vertexDatasetResource"])!==void 0)throw new Error("vertexDatasetResource parameter is not supported in Gemini API.");const o=r(t,["examples"]);if(o!=null){let i=o;Array.isArray(i)&&(i=i.map(l=>l)),s(n,["examples","examples"],i)}return n}function td(t,e,n){const o={};let i=r(n,["config","method"]);if(i===void 0&&(i="SUPERVISED_FINE_TUNING"),i==="SUPERVISED_FINE_TUNING"){const a=r(t,["gcsUri"]);e!==void 0&&a!=null&&s(e,["supervisedTuningSpec","trainingDatasetUri"],a)}else if(i==="PREFERENCE_TUNING"){const a=r(t,["gcsUri"]);e!==void 0&&a!=null&&s(e,["preferenceOptimizationSpec","trainingDatasetUri"],a)}else if(i==="DISTILLATION"){const a=r(t,["gcsUri"]);e!==void 0&&a!=null&&s(e,["distillationSpec","promptDatasetUri"],a)}let l=r(n,["config","method"]);if(l===void 0&&(l="SUPERVISED_FINE_TUNING"),l==="SUPERVISED_FINE_TUNING"){const a=r(t,["vertexDatasetResource"]);e!==void 0&&a!=null&&s(e,["supervisedTuningSpec","trainingDatasetUri"],a)}else if(l==="PREFERENCE_TUNING"){const a=r(t,["vertexDatasetResource"]);e!==void 0&&a!=null&&s(e,["preferenceOptimizationSpec","trainingDatasetUri"],a)}else if(l==="DISTILLATION"){const a=r(t,["vertexDatasetResource"]);e!==void 0&&a!=null&&s(e,["distillationSpec","promptDatasetUri"],a)}if(r(t,["examples"])!==void 0)throw new Error("examples parameter is not supported in Vertex AI.");return o}function Wo(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["name"]);i!=null&&s(n,["name"],i);const l=r(t,["state"]);l!=null&&s(n,["state"],lo(l));const a=r(t,["createTime"]);a!=null&&s(n,["createTime"],a);const u=r(t,["tuningTask","startTime"]);u!=null&&s(n,["startTime"],u);const d=r(t,["tuningTask","completeTime"]);d!=null&&s(n,["endTime"],d);const c=r(t,["updateTime"]);c!=null&&s(n,["updateTime"],c);const f=r(t,["description"]);f!=null&&s(n,["description"],f);const h=r(t,["baseModel"]);h!=null&&s(n,["baseModel"],h);const p=r(t,["_self"]);return p!=null&&s(n,["tunedModel"],jc(p)),n}function rt(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["name"]);i!=null&&s(n,["name"],i);const l=r(t,["state"]);l!=null&&s(n,["state"],lo(l));const a=r(t,["createTime"]);a!=null&&s(n,["createTime"],a);const u=r(t,["startTime"]);u!=null&&s(n,["startTime"],u);const d=r(t,["endTime"]);d!=null&&s(n,["endTime"],d);const c=r(t,["updateTime"]);c!=null&&s(n,["updateTime"],c);const f=r(t,["error"]);f!=null&&s(n,["error"],f);const h=r(t,["description"]);h!=null&&s(n,["description"],h);const p=r(t,["baseModel"]);p!=null&&s(n,["baseModel"],p);const m=r(t,["tunedModel"]);m!=null&&s(n,["tunedModel"],m);const g=r(t,["preTunedModel"]);g!=null&&s(n,["preTunedModel"],g);const v=r(t,["supervisedTuningSpec"]);v!=null&&s(n,["supervisedTuningSpec"],v);const y=r(t,["preferenceOptimizationSpec"]);y!=null&&s(n,["preferenceOptimizationSpec"],y);const T=r(t,["distillationSpec"]);T!=null&&s(n,["distillationSpec"],T);const I=r(t,["tuningDataStats"]);I!=null&&s(n,["tuningDataStats"],I);const C=r(t,["encryptionSpec"]);C!=null&&s(n,["encryptionSpec"],C);const S=r(t,["partnerModelTuningSpec"]);S!=null&&s(n,["partnerModelTuningSpec"],S);const R=r(t,["customBaseModel"]);R!=null&&s(n,["customBaseModel"],R);const _=r(t,["experiment"]);_!=null&&s(n,["experiment"],_);const M=r(t,["labels"]);M!=null&&s(n,["labels"],M);const D=r(t,["outputUri"]);D!=null&&s(n,["outputUri"],D);const A=r(t,["pipelineJob"]);A!=null&&s(n,["pipelineJob"],A);const w=r(t,["serviceAccount"]);w!=null&&s(n,["serviceAccount"],w);const x=r(t,["tunedModelDisplayName"]);x!=null&&s(n,["tunedModelDisplayName"],x);const q=r(t,["veoTuningSpec"]);return q!=null&&s(n,["veoTuningSpec"],q),n}function nd(t,e){const n={},o=r(t,["sdkHttpResponse"]);o!=null&&s(n,["sdkHttpResponse"],o);const i=r(t,["name"]);i!=null&&s(n,["name"],i);const l=r(t,["metadata"]);l!=null&&s(n,["metadata"],l);const a=r(t,["done"]);a!=null&&s(n,["done"],a);const u=r(t,["error"]);return u!=null&&s(n,["error"],u),n}function Be(t,e){const n={},o=r(t,["gcsUri"]);o!=null&&s(n,["validationDatasetUri"],o);const i=r(t,["vertexDatasetResource"]);return i!=null&&s(n,["validationDatasetUri"],i),n}/**
|
|
230
|
+
* @license
|
|
231
|
+
* Copyright 2025 Google LLC
|
|
232
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
233
|
+
*/class od extends K{constructor(e){super(),this.apiClient=e,this.list=async(n={})=>new j(Y.PAGED_ITEM_TUNING_JOBS,o=>this.listInternal(o),await this.listInternal(n),n),this.get=async n=>await this.getInternal(n),this.tune=async n=>{var o;if(this.apiClient.isVertexAI())if(n.baseModel.startsWith("projects/")){const i={tunedModelName:n.baseModel};!((o=n.config)===null||o===void 0)&&o.preTunedModelCheckpointId&&(i.checkpointId=n.config.preTunedModelCheckpointId);const l=Object.assign(Object.assign({},n),{preTunedModel:i});return l.baseModel=void 0,await this.tuneInternal(l)}else{const i=Object.assign({},n);return await this.tuneInternal(i)}else{const i=Object.assign({},n),l=await this.tuneMldevInternal(i);let a="";return l.metadata!==void 0&&l.metadata.tunedModel!==void 0?a=l.metadata.tunedModel:l.name!==void 0&&l.name.includes("/operations/")&&(a=l.name.split("/operations/")[0]),{name:a,state:We.JOB_STATE_QUEUED}}}}async getInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=Wc(e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>rt(f))}else{const c=Oc(e);return u=E("{name}",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>Wo(f))}}async listInternal(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=Xc(e);return u=E("tuningJobs",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Zc(f),p=new An;return Object.assign(p,h),p})}else{const c=zc(e);return u=E("tunedModels",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"GET",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Qc(f),p=new An;return Object.assign(p,h),p})}}async cancel(e){var n,o,i,l;let a,u="",d={};if(this.apiClient.isVertexAI()){const c=Vc(e);return u=E("{name}:cancel",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=qc(f),p=new Rn;return Object.assign(p,h),p})}else{const c=Gc(e);return u=E("{name}:cancel",c._url),d=c._query,delete c._url,delete c._query,a=this.apiClient.request({path:u,queryParams:d,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(i=e.config)===null||i===void 0?void 0:i.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Hc(f),p=new Rn;return Object.assign(p,h),p})}}async tuneInternal(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI()){const u=$c(e,e);return l=E("tuningJobs",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json().then(c=>{const f=c;return f.sdkHttpResponse={headers:d.headers},f})),i.then(d=>rt(d))}else throw new Error("This method is only supported by the Vertex AI.")}async tuneMldevInternal(e){var n,o;let i,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Jc(e);return l=E("tunedModels",u._url),a=u._query,delete u._url,delete u._query,i=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json().then(c=>{const f=c;return f.sdkHttpResponse={headers:d.headers},f})),i.then(d=>nd(d))}}}/**
|
|
234
|
+
* @license
|
|
235
|
+
* Copyright 2025 Google LLC
|
|
236
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
237
|
+
*/class id{async download(e,n){throw new Error("Download to file is not supported in the browser, please use a browser compliant download like an <a> tag.")}}const rd=1024*1024*8,sd=3,ld=1e3,ad=2,Ne="x-goog-upload-status";async function ud(t,e,n){var o;const i=await Yo(t,e,n),l=await i?.json();if(((o=i?.headers)===null||o===void 0?void 0:o[Ne])!=="final")throw new Error("Failed to upload file: Upload status is not finalized.");return l.file}async function cd(t,e,n){var o;const i=await Yo(t,e,n),l=await i?.json();if(((o=i?.headers)===null||o===void 0?void 0:o[Ne])!=="final")throw new Error("Failed to upload file: Upload status is not finalized.");const a=to(l),u=new at;return Object.assign(u,a),u}async function Yo(t,e,n){var o,i;let l=0,a=0,u=new Ke(new Response),d="upload";for(l=t.size;a<l;){const c=Math.min(rd,l-a),f=t.slice(a,a+c);a+c>=l&&(d+=", finalize");let h=0,p=ld;for(;h<sd&&(u=await n.request({path:"",body:f,httpMethod:"POST",httpOptions:{apiVersion:"",baseUrl:e,headers:{"X-Goog-Upload-Command":d,"X-Goog-Upload-Offset":String(a),"Content-Length":String(c)}}}),!(!((o=u?.headers)===null||o===void 0)&&o[Ne]));)h++,await fd(p),p=p*ad;if(a+=c,((i=u?.headers)===null||i===void 0?void 0:i[Ne])!=="active")break;if(l<=a)throw new Error("All content has been uploaded, but the upload status is not finalized.")}return u}async function dd(t){return{size:t.size,type:t.type}}function fd(t){return new Promise(e=>setTimeout(e,t))}class pd{async upload(e,n,o){if(typeof e=="string")throw new Error("File path is not supported in browser uploader.");return await ud(e,n,o)}async uploadToFileSearchStore(e,n,o){if(typeof e=="string")throw new Error("File path is not supported in browser uploader.");return await cd(e,n,o)}async stat(e){if(typeof e=="string")throw new Error("File path is not supported in browser uploader.");return await dd(e)}}/**
|
|
238
|
+
* @license
|
|
239
|
+
* Copyright 2025 Google LLC
|
|
240
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
241
|
+
*/class hd{create(e,n,o){return new md(e,n,o)}}class md{constructor(e,n,o){this.url=e,this.headers=n,this.callbacks=o}connect(){this.ws=new WebSocket(this.url),this.ws.onopen=this.callbacks.onopen,this.ws.onerror=this.callbacks.onerror,this.ws.onclose=this.callbacks.onclose,this.ws.onmessage=this.callbacks.onmessage}send(e){if(this.ws===void 0)throw new Error("WebSocket is not connected");this.ws.send(e)}close(){if(this.ws===void 0)throw new Error("WebSocket is not connected");this.ws.close()}}/**
|
|
242
|
+
* @license
|
|
243
|
+
* Copyright 2025 Google LLC
|
|
244
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
245
|
+
*/const jn="x-goog-api-key";class gd{constructor(e){this.apiKey=e}async addAuthHeaders(e,n){if(e.get(jn)===null){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(jn,this.apiKey)}}}/**
|
|
246
|
+
* @license
|
|
247
|
+
* Copyright 2025 Google LLC
|
|
248
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
249
|
+
*/const yd="gl-node/";class Ad{get interactions(){var e;if(this._interactions!==void 0)return this._interactions;console.warn("GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.");const n=this.httpOptions;n?.extraBody&&console.warn("GoogleGenAI.interactions: Client level httpOptions.extraBody is not supported by the interactions client and will be ignored.");const o=new k({baseURL:this.apiClient.getBaseUrl(),apiKey:this.apiKey,apiVersion:this.apiClient.getApiVersion(),clientAdapter:this.apiClient,defaultHeaders:this.apiClient.getDefaultHeaders(),timeout:n?.timeout,maxRetries:(e=n?.retryOptions)===null||e===void 0?void 0:e.attempts});return this._interactions=o.interactions,this._interactions}constructor(e){var n;if(e.apiKey==null)throw new Error("An API Key must be set when running in a browser");if(e.project||e.location)throw new Error("Vertex AI project based authentication is not supported on browser runtimes. Please do not provide a project or location.");this.vertexai=(n=e.vertexai)!==null&&n!==void 0?n:!1,this.apiKey=e.apiKey;const o=ri(e.httpOptions,e.vertexai,void 0,void 0);o&&(e.httpOptions?e.httpOptions.baseUrl=o:e.httpOptions={baseUrl:o}),this.apiVersion=e.apiVersion,this.httpOptions=e.httpOptions;const i=new gd(this.apiKey);this.apiClient=new du({auth:i,apiVersion:this.apiVersion,apiKey:this.apiKey,vertexai:this.vertexai,httpOptions:this.httpOptions,userAgentExtra:yd+"web",uploader:new pd,downloader:new id}),this.models=new Nu(this.apiClient),this.live=new Iu(this.apiClient,i,new hd),this.batches=new Fr(this.apiClient),this.chats=new ys(this.models,this.apiClient),this.caches=new hs(this.apiClient),this.files=new ws(this.apiClient),this.operations=new Du(this.apiClient),this.authTokens=new Yu(this.apiClient),this.tunings=new od(this.apiClient),this.fileSearchStores=new tc(this.apiClient)}}function Rd(t){return t.thought===!0}function Pd(t,e){return typeof e=="string"&&e.length>0?e:t}const vd=/^[A-Za-z0-9+/]+={0,2}$/,Td="skip_thought_signature_validator";function _d(t){return!t||t.length%4!==0?!1:vd.test(t)}function Je(t,e){return t&&_d(e)?e:void 0}function $e(t){return t.startsWith("claude-")||t.startsWith("gpt-oss-")}function Ed(t){const e=t.toLowerCase().match(/^gemini(?:-live)?-(\d+)/);if(e)return Number.parseInt(e[1],10)}function Cd(t){const e=Ed(t);return e!==void 0?e>=3:!0}function Md(t,e){const n=[],o=l=>$e(t.id)?l.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,64):l,i=zo(e.messages,t,o);for(const l of i)if(l.role==="user")if(typeof l.content=="string")n.push({role:"user",parts:[{text:te(l.content)}]});else{const a=l.content.map(d=>d.type==="text"?{text:te(d.text)}:{inlineData:{mimeType:d.mimeType,data:d.data}}),u=t.input.includes("image")?a:a.filter(d=>d.text!==void 0);if(u.length===0)continue;n.push({role:"user",parts:u})}else if(l.role==="assistant"){const a=[],u=l.provider===t.provider&&l.model===t.id;for(const d of l.content)if(d.type==="text"){if(!d.text||d.text.trim()==="")continue;const c=Je(u,d.textSignature);a.push({text:te(d.text),...c&&{thoughtSignature:c}})}else if(d.type==="thinking"){if(!d.thinking||d.thinking.trim()==="")continue;if(u){const c=Je(u,d.thinkingSignature);a.push({thought:!0,text:te(d.thinking),...c&&{thoughtSignature:c}})}else a.push({text:te(d.thinking)})}else if(d.type==="toolCall"){const c=Je(u,d.thoughtSignature),f=t.id.toLowerCase().includes("gemini-3"),h=c||(f?Td:void 0),p={functionCall:{name:d.name,args:d.arguments??{},...$e(t.id)?{id:d.id}:{}},...h&&{thoughtSignature:h}};a.push(p)}if(a.length===0)continue;n.push({role:"model",parts:a})}else if(l.role==="toolResult"){const u=l.content.filter(T=>T.type==="text").map(T=>T.text).join(`
|
|
250
|
+
`),d=t.input.includes("image")?l.content.filter(T=>T.type==="image"):[],c=u.length>0,f=d.length>0,h=Cd(t.id),p=c?te(u):f?"(see attached image)":"",m=d.map(T=>({inlineData:{mimeType:T.mimeType,data:T.data}})),g=$e(t.id),v={functionResponse:{name:l.toolName,response:l.isError?{error:p}:{output:p},...f&&h&&{parts:m},...g?{id:l.toolCallId}:{}}},y=n[n.length-1];y?.role==="user"&&y.parts?.some(T=>T.functionResponse)?y.parts.push(v):n.push({role:"user",parts:[v]}),f&&!h&&n.push({role:"user",parts:[{text:"Tool result image:"},...m]})}return n}function wd(t,e=!1){if(t.length!==0)return[{functionDeclarations:t.map(n=>({name:n.name,description:n.description,...e?{parameters:n.parameters}:{parametersJsonSchema:n.parameters}}))}]}function Nd(t){switch(t){case"auto":return oe.AUTO;case"none":return oe.NONE;case"any":return oe.ANY;default:return oe.AUTO}}function Dd(t){switch(t){case U.STOP:return"stop";case U.MAX_TOKENS:return"length";case U.BLOCKLIST:case U.PROHIBITED_CONTENT:case U.SPII:case U.SAFETY:case U.IMAGE_SAFETY:case U.IMAGE_PROHIBITED_CONTENT:case U.IMAGE_RECITATION:case U.IMAGE_OTHER:case U.RECITATION:case U.FINISH_REASON_UNSPECIFIED:case U.OTHER:case U.LANGUAGE:case U.MALFORMED_FUNCTION_CALL:case U.UNEXPECTED_TOOL_CALL:case U.NO_IMAGE:return"error";default:{const e=t;throw new Error(`Unhandled stop reason: ${e}`)}}}function xd(t){switch(t){case"STOP":return"stop";case"MAX_TOKENS":return"length";default:return"error"}}export{Ad as G,Dt as T,wd as a,Nd as b,Md as c,xd as d,Rd as i,Dd as m,Pd as r};
|