@shumai-one/shumai-agent 0.4.2 → 0.4.3

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.
Files changed (91) hide show
  1. package/bin/chunk-115gx56y.js +12 -0
  2. package/bin/chunk-24s58f6x.js +11 -0
  3. package/bin/chunk-2mj5h53m.js +5 -0
  4. package/bin/chunk-3dr4h1df.js +16 -0
  5. package/bin/chunk-3mdhkfgq.js +3 -0
  6. package/bin/chunk-5axrg8rz.js +2 -0
  7. package/bin/chunk-5vk5pgxq.js +45 -0
  8. package/bin/chunk-7hkzk9pe.js +3 -0
  9. package/bin/chunk-7z62cgr7.js +3 -0
  10. package/bin/chunk-8cz84wva.js +4 -0
  11. package/bin/chunk-97avgejq.js +2 -0
  12. package/bin/chunk-avm8xsd8.js +3 -0
  13. package/bin/chunk-b5hbfteg.js +2 -0
  14. package/bin/chunk-c8vf5ezv.js +24 -0
  15. package/bin/chunk-caw017nc.js +3 -0
  16. package/bin/chunk-dak3e9js.js +2 -0
  17. package/bin/chunk-dpd0zpsp.js +3 -0
  18. package/bin/chunk-gkwywrkk.js +2 -0
  19. package/bin/chunk-gqvwjf6q.js +2 -0
  20. package/bin/chunk-hme2crct.js +2 -0
  21. package/bin/chunk-hyc2kn1w.js +8 -0
  22. package/bin/chunk-kvt13jb9.js +2 -0
  23. package/bin/chunk-m51y6s92.js +2 -0
  24. package/bin/chunk-p7sczpks.js +3 -0
  25. package/bin/chunk-phjnj6x5.js +3 -0
  26. package/bin/chunk-ptxcc9bv.js +2 -0
  27. package/bin/chunk-q7ypqj4c.js +2 -0
  28. package/bin/chunk-r8hcdypf.js +2 -0
  29. package/bin/chunk-rv0jkz1g.js +8 -0
  30. package/bin/chunk-shv0zdbp.js +4 -0
  31. package/bin/chunk-smv5ztx4.js +2 -0
  32. package/bin/chunk-spcaxtg5.js +7 -0
  33. package/bin/chunk-sxrz8e3j.js +3 -0
  34. package/bin/chunk-v8rxcp9h.js +2 -0
  35. package/bin/chunk-xmq8pwcp.js +13379 -0
  36. package/bin/chunk-y6h80xaa.js +13 -0
  37. package/bin/chunk-zcx3awzq.js +3 -0
  38. package/bin/shumai-agent-app.js +656 -449
  39. package/package.json +18 -18
  40. package/prisma/migrations/20260904022457_add_agent_id_to_assets_and_audit_logs/migration.sql +17 -0
  41. package/prisma/migrations/20260906081230_default_denied_tools_delete_asset/migration.sql +15 -0
  42. package/prisma/schema.prisma +9 -0
  43. package/bin/chunk-1ep7nnzp.js +0 -5
  44. package/bin/chunk-1jq2vgrd.js +0 -3
  45. package/bin/chunk-2ntm65jn.js +0 -3
  46. package/bin/chunk-3nh1p64q.js +0 -12
  47. package/bin/chunk-41gh01qj.js +0 -3
  48. package/bin/chunk-4n1309xp.js +0 -2
  49. package/bin/chunk-616f7y5x.js +0 -8
  50. package/bin/chunk-6a9h5d64.js +0 -3
  51. package/bin/chunk-6dp3ybh2.js +0 -3
  52. package/bin/chunk-6nd8f70y.js +0 -4
  53. package/bin/chunk-6vs3gb9g.js +0 -2
  54. package/bin/chunk-7dyx5m0f.js +0 -6
  55. package/bin/chunk-7j3qbvwc.js +0 -7
  56. package/bin/chunk-9h5qhgqx.js +0 -13
  57. package/bin/chunk-b9s67nd8.js +0 -2
  58. package/bin/chunk-c14kvr2r.js +0 -11
  59. package/bin/chunk-cb5p7shk.js +0 -12240
  60. package/bin/chunk-ccx6803n.js +0 -44
  61. package/bin/chunk-cm4dpd3k.js +0 -4
  62. package/bin/chunk-dd2tfwzy.js +0 -45
  63. package/bin/chunk-dk9vz5tv.js +0 -4
  64. package/bin/chunk-e6691p0v.js +0 -3
  65. package/bin/chunk-e9d2ah8y.js +0 -3
  66. package/bin/chunk-fvmb8en4.js +0 -24
  67. package/bin/chunk-gegf6d3m.js +0 -2
  68. package/bin/chunk-gx9vdcbm.js +0 -2
  69. package/bin/chunk-j427r7a5.js +0 -2
  70. package/bin/chunk-jperx2a8.js +0 -6
  71. package/bin/chunk-k4jm2gt4.js +0 -3
  72. package/bin/chunk-m29dphbf.js +0 -3
  73. package/bin/chunk-mpgy1y53.js +0 -3
  74. package/bin/chunk-n1t3he2k.js +0 -3
  75. package/bin/chunk-pmdb6y7t.js +0 -2
  76. package/bin/chunk-qx9njyk7.js +0 -3
  77. package/bin/chunk-r5h7vczc.js +0 -3
  78. package/bin/chunk-spm76160.js +0 -2
  79. package/bin/chunk-t8k09sgb.js +0 -3
  80. package/bin/chunk-tvef1ck8.js +0 -2
  81. package/bin/chunk-v4j6yxch.js +0 -3
  82. package/bin/chunk-vjzrmneg.js +0 -2
  83. package/bin/chunk-x25enwfz.js +0 -3
  84. package/bin/chunk-xg9xscqz.js +0 -1
  85. package/bin/chunk-xqg06q7q.js +0 -2
  86. package/bin/chunk-xvbd9e2b.js +0 -8
  87. package/bin/chunk-y2z3xj0m.js +0 -12
  88. package/bin/chunk-ywhrsshf.js +0 -2
  89. package/bin/chunk-z512b49m.js +0 -3
  90. package/bin/chunk-z58rb52r.js +0 -3
  91. package/bin/chunk-zazbsz25.js +0 -3
@@ -0,0 +1,16 @@
1
+ // @bun
2
+ import{je,We}from"./shumai-agent-app.js";import{h}from"./chunk-kvt13jb9.js";import{u,w,N}from"./chunk-dpd0zpsp.js";var Ze=h(je(),1),ko=h(We(),1);import{createWriteStream as dr}from"fs";import*as en from"fs/promises";import{writeFile as fr}from"fs/promises";import{Readable as cr}from"stream";import{finished as pr}from"stream/promises";import*as Fo from"ws";import*as Vo from"path";var hr=void 0,mr=void 0;function gr(){return{geminiUrl:hr,vertexUrl:mr}}function yr(e,n,t,o){var r,l;if(!(e===null||e===void 0?void 0:e.baseUrl)){let a=gr();if(n)return(r=a.vertexUrl)!==null&&r!==void 0?r:t;else return(l=a.geminiUrl)!==null&&l!==void 0?l:o}return e.baseUrl}class ne{}function S(e,n){let t=/\{([^}]+)\}/g;return e.replace(t,(o,r)=>{if(Object.prototype.hasOwnProperty.call(n,r)){let l=n[r];return l!==void 0&&l!==null?String(l):""}else throw Error(`Key '${r}' not found in valueMap.`)})}function s(e,n,t){for(let l=0;l<n.length-1;l++){let a=n[l];if(a.endsWith("[]")){let f=a.slice(0,-2);if(!(f in e))if(Array.isArray(t))e[f]=Array.from({length:t.length},()=>({}));else throw Error(`Value must be a list given an array path ${a}`);if(Array.isArray(e[f])){let d=e[f];if(Array.isArray(t))for(let c=0;c<d.length;c++){let m=d[c];s(m,n.slice(l+1),t[c])}else for(let c of d)s(c,n.slice(l+1),t)}return}else if(a.endsWith("[0]")){let f=a.slice(0,-3);if(!(f in e))e[f]=[{}];let d=e[f];s(d[0],n.slice(l+1),t);return}if(!e[a]||typeof e[a]!=="object")e[a]={};e=e[a]}let o=n[n.length-1],r=e[o];if(r!==void 0){if(!t||typeof t==="object"&&Object.keys(t).length===0)return;if(t===r)return;if(typeof r==="object"&&typeof t==="object"&&r!==null&&t!==null)Object.assign(r,t);else throw Error(`Cannot set value for an existing key. Key: ${o}`)}else if(o==="_self"&&typeof t==="object"&&t!==null&&!Array.isArray(t))Object.assign(e,t);else e[o]=t}function i(e,n,t=void 0){try{if(n.length===1&&n[0]==="_self")return e;for(let o=0;o<n.length;o++){if(typeof e!=="object"||e===null)return t;let r=n[o];if(r.endsWith("[]")){let l=r.slice(0,-2);if(l in e){let a=e[l];if(!Array.isArray(a))return t;return a.map((f)=>i(f,n.slice(o+1),t))}else return t}else e=e[r]}return e}catch(o){if(o instanceof TypeError)return t;throw o}}function Er(e,n){for(let[t,o]of Object.entries(n)){let r=t.split("."),l=o.split("."),a=new Set,f=-1;for(let d=0;d<r.length;d++)if(r[d]==="*"){f=d;break}if(f!==-1&&l.length>f)for(let d=f;d<l.length;d++){let c=l[d];if(c!=="*"&&!c.endsWith("[]")&&!c.endsWith("[0]"))a.add(c)}cn(e,r,l,0,a)}}function cn(e,n,t,o,r){if(o>=n.length)return;if(typeof e!=="object"||e===null)return;let l=n[o];if(l.endsWith("[]")){let a=l.slice(0,-2),f=e;if(a in f&&Array.isArray(f[a]))for(let d of f[a])cn(d,n,t,o+1,r)}else if(l==="*"){if(typeof e==="object"&&e!==null&&!Array.isArray(e)){let a=e,f=Object.keys(a).filter((c)=>!c.startsWith("_")&&!r.has(c)),d={};for(let c of f)d[c]=a[c];for(let[c,m]of Object.entries(d)){let p=[];for(let g of t.slice(o))if(g==="*")p.push(c);else p.push(g);s(a,p,m)}for(let c of f)delete a[c]}}else{let a=e;if(l in a)cn(a[l],n,t,o+1,r)}}function Un(e){if(typeof e!=="string")throw Error("fromImageBytes must be a string");return e}function Tr(e){let n={},t=i(e,["operationName"]);if(t!=null)s(n,["operationName"],t);let o=i(e,["resourceName"]);if(o!=null)s(n,["_url","resourceName"],o);return n}function _r(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["name"],t);let o=i(e,["metadata"]);if(o!=null)s(n,["metadata"],o);let r=i(e,["done"]);if(r!=null)s(n,["done"],r);let l=i(e,["error"]);if(l!=null)s(n,["error"],l);let a=i(e,["response","generateVideoResponse"]);if(a!=null)s(n,["response"],Cr(a));return n}function Ir(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["name"],t);let o=i(e,["metadata"]);if(o!=null)s(n,["metadata"],o);let r=i(e,["done"]);if(r!=null)s(n,["done"],r);let l=i(e,["error"]);if(l!=null)s(n,["error"],l);let a=i(e,["response"]);if(a!=null)s(n,["response"],Ar(a));return n}function Cr(e){let n={},t=i(e,["generatedSamples"]);if(t!=null){let l=t;if(Array.isArray(l))l=l.map((a)=>vr(a));s(n,["generatedVideos"],l)}let o=i(e,["raiMediaFilteredCount"]);if(o!=null)s(n,["raiMediaFilteredCount"],o);let r=i(e,["raiMediaFilteredReasons"]);if(r!=null)s(n,["raiMediaFilteredReasons"],r);return n}function Ar(e){let n={},t=i(e,["videos"]);if(t!=null){let l=t;if(Array.isArray(l))l=l.map((a)=>Sr(a));s(n,["generatedVideos"],l)}let o=i(e,["raiMediaFilteredCount"]);if(o!=null)s(n,["raiMediaFilteredCount"],o);let r=i(e,["raiMediaFilteredReasons"]);if(r!=null)s(n,["raiMediaFilteredReasons"],r);return n}function vr(e){let n={},t=i(e,["video"]);if(t!=null)s(n,["video"],Dr(t));return n}function Sr(e){let n={},t=i(e,["_self"]);if(t!=null)s(n,["video"],xr(t));return n}function Rr(e){let n={},t=i(e,["operationName"]);if(t!=null)s(n,["_url","operationName"],t);return n}function Pr(e){let n={},t=i(e,["operationName"]);if(t!=null)s(n,["_url","operationName"],t);return n}function wr(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["name"],t);let o=i(e,["metadata"]);if(o!=null)s(n,["metadata"],o);let r=i(e,["done"]);if(r!=null)s(n,["done"],r);let l=i(e,["error"]);if(l!=null)s(n,["error"],l);let a=i(e,["response"]);if(a!=null)s(n,["response"],Nr(a));return n}function Nr(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["parent"]);if(o!=null)s(n,["parent"],o);let r=i(e,["documentName"]);if(r!=null)s(n,["documentName"],r);return n}function Ln(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["name"],t);let o=i(e,["metadata"]);if(o!=null)s(n,["metadata"],o);let r=i(e,["done"]);if(r!=null)s(n,["done"],r);let l=i(e,["error"]);if(l!=null)s(n,["error"],l);let a=i(e,["response"]);if(a!=null)s(n,["response"],Mr(a));return n}function Mr(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["parent"]);if(o!=null)s(n,["parent"],o);let r=i(e,["documentName"]);if(r!=null)s(n,["documentName"],r);return n}function Dr(e){let n={},t=i(e,["uri"]);if(t!=null)s(n,["uri"],t);let o=i(e,["encodedVideo"]);if(o!=null)s(n,["videoBytes"],Un(o));let r=i(e,["encoding"]);if(r!=null)s(n,["mimeType"],r);return n}function xr(e){let n={},t=i(e,["gcsUri"]);if(t!=null)s(n,["uri"],t);let o=i(e,["bytesBase64Encoded"]);if(o!=null)s(n,["videoBytes"],Un(o));let r=i(e,["mimeType"]);if(r!=null)s(n,["mimeType"],r);return n}var rt;(function(e){e.LANGUAGE_UNSPECIFIED="LANGUAGE_UNSPECIFIED",e.PYTHON="PYTHON"})(rt||(rt={}));var st;(function(e){e.OUTCOME_UNSPECIFIED="OUTCOME_UNSPECIFIED",e.OUTCOME_OK="OUTCOME_OK",e.OUTCOME_FAILED="OUTCOME_FAILED",e.OUTCOME_DEADLINE_EXCEEDED="OUTCOME_DEADLINE_EXCEEDED"})(st||(st={}));var lt;(function(e){e.SCHEDULING_UNSPECIFIED="SCHEDULING_UNSPECIFIED",e.SILENT="SILENT",e.WHEN_IDLE="WHEN_IDLE",e.INTERRUPT="INTERRUPT"})(lt||(lt={}));var re;(function(e){e.TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",e.STRING="STRING",e.NUMBER="NUMBER",e.INTEGER="INTEGER",e.BOOLEAN="BOOLEAN",e.ARRAY="ARRAY",e.OBJECT="OBJECT",e.NULL="NULL"})(re||(re={}));var at;(function(e){e.ENVIRONMENT_UNSPECIFIED="ENVIRONMENT_UNSPECIFIED",e.ENVIRONMENT_BROWSER="ENVIRONMENT_BROWSER"})(at||(at={}));var ut;(function(e){e.AUTH_TYPE_UNSPECIFIED="AUTH_TYPE_UNSPECIFIED",e.NO_AUTH="NO_AUTH",e.API_KEY_AUTH="API_KEY_AUTH",e.HTTP_BASIC_AUTH="HTTP_BASIC_AUTH",e.GOOGLE_SERVICE_ACCOUNT_AUTH="GOOGLE_SERVICE_ACCOUNT_AUTH",e.OAUTH="OAUTH",e.OIDC_AUTH="OIDC_AUTH"})(ut||(ut={}));var dt;(function(e){e.HTTP_IN_UNSPECIFIED="HTTP_IN_UNSPECIFIED",e.HTTP_IN_QUERY="HTTP_IN_QUERY",e.HTTP_IN_HEADER="HTTP_IN_HEADER",e.HTTP_IN_PATH="HTTP_IN_PATH",e.HTTP_IN_BODY="HTTP_IN_BODY",e.HTTP_IN_COOKIE="HTTP_IN_COOKIE"})(dt||(dt={}));var ft;(function(e){e.API_SPEC_UNSPECIFIED="API_SPEC_UNSPECIFIED",e.SIMPLE_SEARCH="SIMPLE_SEARCH",e.ELASTIC_SEARCH="ELASTIC_SEARCH"})(ft||(ft={}));var ct;(function(e){e.PHISH_BLOCK_THRESHOLD_UNSPECIFIED="PHISH_BLOCK_THRESHOLD_UNSPECIFIED",e.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",e.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",e.BLOCK_HIGH_AND_ABOVE="BLOCK_HIGH_AND_ABOVE",e.BLOCK_HIGHER_AND_ABOVE="BLOCK_HIGHER_AND_ABOVE",e.BLOCK_VERY_HIGH_AND_ABOVE="BLOCK_VERY_HIGH_AND_ABOVE",e.BLOCK_ONLY_EXTREMELY_HIGH="BLOCK_ONLY_EXTREMELY_HIGH"})(ct||(ct={}));var pt;(function(e){e.UNSPECIFIED="UNSPECIFIED",e.BLOCKING="BLOCKING",e.NON_BLOCKING="NON_BLOCKING"})(pt||(pt={}));var ht;(function(e){e.MODE_UNSPECIFIED="MODE_UNSPECIFIED",e.MODE_DYNAMIC="MODE_DYNAMIC"})(ht||(ht={}));var ue;(function(e){e.MODE_UNSPECIFIED="MODE_UNSPECIFIED",e.AUTO="AUTO",e.ANY="ANY",e.NONE="NONE",e.VALIDATED="VALIDATED"})(ue||(ue={}));var H;(function(e){e.THINKING_LEVEL_UNSPECIFIED="THINKING_LEVEL_UNSPECIFIED",e.MINIMAL="MINIMAL",e.LOW="LOW",e.MEDIUM="MEDIUM",e.HIGH="HIGH"})(H||(H={}));var mt;(function(e){e.DONT_ALLOW="DONT_ALLOW",e.ALLOW_ADULT="ALLOW_ADULT",e.ALLOW_ALL="ALLOW_ALL"})(mt||(mt={}));var gt;(function(e){e.PROMINENT_PEOPLE_UNSPECIFIED="PROMINENT_PEOPLE_UNSPECIFIED",e.ALLOW_PROMINENT_PEOPLE="ALLOW_PROMINENT_PEOPLE",e.BLOCK_PROMINENT_PEOPLE="BLOCK_PROMINENT_PEOPLE"})(gt||(gt={}));var yt;(function(e){e.HARM_CATEGORY_UNSPECIFIED="HARM_CATEGORY_UNSPECIFIED",e.HARM_CATEGORY_HARASSMENT="HARM_CATEGORY_HARASSMENT",e.HARM_CATEGORY_HATE_SPEECH="HARM_CATEGORY_HATE_SPEECH",e.HARM_CATEGORY_SEXUALLY_EXPLICIT="HARM_CATEGORY_SEXUALLY_EXPLICIT",e.HARM_CATEGORY_DANGEROUS_CONTENT="HARM_CATEGORY_DANGEROUS_CONTENT",e.HARM_CATEGORY_CIVIC_INTEGRITY="HARM_CATEGORY_CIVIC_INTEGRITY",e.HARM_CATEGORY_IMAGE_HATE="HARM_CATEGORY_IMAGE_HATE",e.HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT="HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT",e.HARM_CATEGORY_IMAGE_HARASSMENT="HARM_CATEGORY_IMAGE_HARASSMENT",e.HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT="HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT",e.HARM_CATEGORY_JAILBREAK="HARM_CATEGORY_JAILBREAK"})(yt||(yt={}));var Et;(function(e){e.HARM_BLOCK_METHOD_UNSPECIFIED="HARM_BLOCK_METHOD_UNSPECIFIED",e.SEVERITY="SEVERITY",e.PROBABILITY="PROBABILITY"})(Et||(Et={}));var Tt;(function(e){e.HARM_BLOCK_THRESHOLD_UNSPECIFIED="HARM_BLOCK_THRESHOLD_UNSPECIFIED",e.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",e.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",e.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",e.BLOCK_NONE="BLOCK_NONE",e.OFF="OFF"})(Tt||(Tt={}));var k;(function(e){e.FINISH_REASON_UNSPECIFIED="FINISH_REASON_UNSPECIFIED",e.STOP="STOP",e.MAX_TOKENS="MAX_TOKENS",e.SAFETY="SAFETY",e.RECITATION="RECITATION",e.LANGUAGE="LANGUAGE",e.OTHER="OTHER",e.BLOCKLIST="BLOCKLIST",e.PROHIBITED_CONTENT="PROHIBITED_CONTENT",e.SPII="SPII",e.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",e.IMAGE_SAFETY="IMAGE_SAFETY",e.UNEXPECTED_TOOL_CALL="UNEXPECTED_TOOL_CALL",e.IMAGE_PROHIBITED_CONTENT="IMAGE_PROHIBITED_CONTENT",e.NO_IMAGE="NO_IMAGE",e.IMAGE_RECITATION="IMAGE_RECITATION",e.IMAGE_OTHER="IMAGE_OTHER"})(k||(k={}));var _t;(function(e){e.HARM_PROBABILITY_UNSPECIFIED="HARM_PROBABILITY_UNSPECIFIED",e.NEGLIGIBLE="NEGLIGIBLE",e.LOW="LOW",e.MEDIUM="MEDIUM",e.HIGH="HIGH"})(_t||(_t={}));var It;(function(e){e.HARM_SEVERITY_UNSPECIFIED="HARM_SEVERITY_UNSPECIFIED",e.HARM_SEVERITY_NEGLIGIBLE="HARM_SEVERITY_NEGLIGIBLE",e.HARM_SEVERITY_LOW="HARM_SEVERITY_LOW",e.HARM_SEVERITY_MEDIUM="HARM_SEVERITY_MEDIUM",e.HARM_SEVERITY_HIGH="HARM_SEVERITY_HIGH"})(It||(It={}));var Ct;(function(e){e.URL_RETRIEVAL_STATUS_UNSPECIFIED="URL_RETRIEVAL_STATUS_UNSPECIFIED",e.URL_RETRIEVAL_STATUS_SUCCESS="URL_RETRIEVAL_STATUS_SUCCESS",e.URL_RETRIEVAL_STATUS_ERROR="URL_RETRIEVAL_STATUS_ERROR",e.URL_RETRIEVAL_STATUS_PAYWALL="URL_RETRIEVAL_STATUS_PAYWALL",e.URL_RETRIEVAL_STATUS_UNSAFE="URL_RETRIEVAL_STATUS_UNSAFE"})(Ct||(Ct={}));var At;(function(e){e.BLOCKED_REASON_UNSPECIFIED="BLOCKED_REASON_UNSPECIFIED",e.SAFETY="SAFETY",e.OTHER="OTHER",e.BLOCKLIST="BLOCKLIST",e.PROHIBITED_CONTENT="PROHIBITED_CONTENT",e.IMAGE_SAFETY="IMAGE_SAFETY",e.MODEL_ARMOR="MODEL_ARMOR",e.JAILBREAK="JAILBREAK"})(At||(At={}));var vt;(function(e){e.TRAFFIC_TYPE_UNSPECIFIED="TRAFFIC_TYPE_UNSPECIFIED",e.ON_DEMAND="ON_DEMAND",e.ON_DEMAND_PRIORITY="ON_DEMAND_PRIORITY",e.ON_DEMAND_FLEX="ON_DEMAND_FLEX",e.PROVISIONED_THROUGHPUT="PROVISIONED_THROUGHPUT"})(vt||(vt={}));var $e;(function(e){e.MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",e.TEXT="TEXT",e.IMAGE="IMAGE",e.AUDIO="AUDIO",e.VIDEO="VIDEO"})($e||($e={}));var St;(function(e){e.MODEL_STAGE_UNSPECIFIED="MODEL_STAGE_UNSPECIFIED",e.UNSTABLE_EXPERIMENTAL="UNSTABLE_EXPERIMENTAL",e.EXPERIMENTAL="EXPERIMENTAL",e.PREVIEW="PREVIEW",e.STABLE="STABLE",e.LEGACY="LEGACY",e.DEPRECATED="DEPRECATED",e.RETIRED="RETIRED"})(St||(St={}));var Rt;(function(e){e.MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",e.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",e.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",e.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH"})(Rt||(Rt={}));var Pt;(function(e){e.TUNING_MODE_UNSPECIFIED="TUNING_MODE_UNSPECIFIED",e.TUNING_MODE_FULL="TUNING_MODE_FULL",e.TUNING_MODE_PEFT_ADAPTER="TUNING_MODE_PEFT_ADAPTER"})(Pt||(Pt={}));var wt;(function(e){e.ADAPTER_SIZE_UNSPECIFIED="ADAPTER_SIZE_UNSPECIFIED",e.ADAPTER_SIZE_ONE="ADAPTER_SIZE_ONE",e.ADAPTER_SIZE_TWO="ADAPTER_SIZE_TWO",e.ADAPTER_SIZE_FOUR="ADAPTER_SIZE_FOUR",e.ADAPTER_SIZE_EIGHT="ADAPTER_SIZE_EIGHT",e.ADAPTER_SIZE_SIXTEEN="ADAPTER_SIZE_SIXTEEN",e.ADAPTER_SIZE_THIRTY_TWO="ADAPTER_SIZE_THIRTY_TWO"})(wt||(wt={}));var pn;(function(e){e.JOB_STATE_UNSPECIFIED="JOB_STATE_UNSPECIFIED",e.JOB_STATE_QUEUED="JOB_STATE_QUEUED",e.JOB_STATE_PENDING="JOB_STATE_PENDING",e.JOB_STATE_RUNNING="JOB_STATE_RUNNING",e.JOB_STATE_SUCCEEDED="JOB_STATE_SUCCEEDED",e.JOB_STATE_FAILED="JOB_STATE_FAILED",e.JOB_STATE_CANCELLING="JOB_STATE_CANCELLING",e.JOB_STATE_CANCELLED="JOB_STATE_CANCELLED",e.JOB_STATE_PAUSED="JOB_STATE_PAUSED",e.JOB_STATE_EXPIRED="JOB_STATE_EXPIRED",e.JOB_STATE_UPDATING="JOB_STATE_UPDATING",e.JOB_STATE_PARTIALLY_SUCCEEDED="JOB_STATE_PARTIALLY_SUCCEEDED"})(pn||(pn={}));var Nt;(function(e){e.TUNING_JOB_STATE_UNSPECIFIED="TUNING_JOB_STATE_UNSPECIFIED",e.TUNING_JOB_STATE_WAITING_FOR_QUOTA="TUNING_JOB_STATE_WAITING_FOR_QUOTA",e.TUNING_JOB_STATE_PROCESSING_DATASET="TUNING_JOB_STATE_PROCESSING_DATASET",e.TUNING_JOB_STATE_WAITING_FOR_CAPACITY="TUNING_JOB_STATE_WAITING_FOR_CAPACITY",e.TUNING_JOB_STATE_TUNING="TUNING_JOB_STATE_TUNING",e.TUNING_JOB_STATE_POST_PROCESSING="TUNING_JOB_STATE_POST_PROCESSING"})(Nt||(Nt={}));var Mt;(function(e){e.AGGREGATION_METRIC_UNSPECIFIED="AGGREGATION_METRIC_UNSPECIFIED",e.AVERAGE="AVERAGE",e.MODE="MODE",e.STANDARD_DEVIATION="STANDARD_DEVIATION",e.VARIANCE="VARIANCE",e.MINIMUM="MINIMUM",e.MAXIMUM="MAXIMUM",e.MEDIAN="MEDIAN",e.PERCENTILE_P90="PERCENTILE_P90",e.PERCENTILE_P95="PERCENTILE_P95",e.PERCENTILE_P99="PERCENTILE_P99"})(Mt||(Mt={}));var Dt;(function(e){e.PAIRWISE_CHOICE_UNSPECIFIED="PAIRWISE_CHOICE_UNSPECIFIED",e.BASELINE="BASELINE",e.CANDIDATE="CANDIDATE",e.TIE="TIE"})(Dt||(Dt={}));var xt;(function(e){e.TUNING_TASK_UNSPECIFIED="TUNING_TASK_UNSPECIFIED",e.TUNING_TASK_I2V="TUNING_TASK_I2V",e.TUNING_TASK_T2V="TUNING_TASK_T2V",e.TUNING_TASK_R2V="TUNING_TASK_R2V"})(xt||(xt={}));var Ut;(function(e){e.STATE_UNSPECIFIED="STATE_UNSPECIFIED",e.STATE_PENDING="STATE_PENDING",e.STATE_ACTIVE="STATE_ACTIVE",e.STATE_FAILED="STATE_FAILED"})(Ut||(Ut={}));var Lt;(function(e){e.MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",e.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",e.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",e.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH",e.MEDIA_RESOLUTION_ULTRA_HIGH="MEDIA_RESOLUTION_ULTRA_HIGH"})(Lt||(Lt={}));var Gt;(function(e){e.TOOL_TYPE_UNSPECIFIED="TOOL_TYPE_UNSPECIFIED",e.GOOGLE_SEARCH_WEB="GOOGLE_SEARCH_WEB",e.GOOGLE_SEARCH_IMAGE="GOOGLE_SEARCH_IMAGE",e.URL_CONTEXT="URL_CONTEXT",e.GOOGLE_MAPS="GOOGLE_MAPS",e.FILE_SEARCH="FILE_SEARCH"})(Gt||(Gt={}));var Qe;(function(e){e.COLLECTION="COLLECTION"})(Qe||(Qe={}));var kt;(function(e){e.UNSPECIFIED="unspecified",e.FLEX="flex",e.STANDARD="standard",e.PRIORITY="priority"})(kt||(kt={}));var Ft;(function(e){e.FEATURE_SELECTION_PREFERENCE_UNSPECIFIED="FEATURE_SELECTION_PREFERENCE_UNSPECIFIED",e.PRIORITIZE_QUALITY="PRIORITIZE_QUALITY",e.BALANCED="BALANCED",e.PRIORITIZE_COST="PRIORITIZE_COST"})(Ft||(Ft={}));var Oe;(function(e){e.PREDICT="PREDICT",e.EMBED_CONTENT="EMBED_CONTENT"})(Oe||(Oe={}));var Vt;(function(e){e.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",e.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",e.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",e.BLOCK_NONE="BLOCK_NONE"})(Vt||(Vt={}));var qt;(function(e){e.auto="auto",e.en="en",e.ja="ja",e.ko="ko",e.hi="hi",e.zh="zh",e.pt="pt",e.es="es"})(qt||(qt={}));var Ht;(function(e){e.MASK_MODE_DEFAULT="MASK_MODE_DEFAULT",e.MASK_MODE_USER_PROVIDED="MASK_MODE_USER_PROVIDED",e.MASK_MODE_BACKGROUND="MASK_MODE_BACKGROUND",e.MASK_MODE_FOREGROUND="MASK_MODE_FOREGROUND",e.MASK_MODE_SEMANTIC="MASK_MODE_SEMANTIC"})(Ht||(Ht={}));var Bt;(function(e){e.CONTROL_TYPE_DEFAULT="CONTROL_TYPE_DEFAULT",e.CONTROL_TYPE_CANNY="CONTROL_TYPE_CANNY",e.CONTROL_TYPE_SCRIBBLE="CONTROL_TYPE_SCRIBBLE",e.CONTROL_TYPE_FACE_MESH="CONTROL_TYPE_FACE_MESH"})(Bt||(Bt={}));var Jt;(function(e){e.SUBJECT_TYPE_DEFAULT="SUBJECT_TYPE_DEFAULT",e.SUBJECT_TYPE_PERSON="SUBJECT_TYPE_PERSON",e.SUBJECT_TYPE_ANIMAL="SUBJECT_TYPE_ANIMAL",e.SUBJECT_TYPE_PRODUCT="SUBJECT_TYPE_PRODUCT"})(Jt||(Jt={}));var bt;(function(e){e.EDIT_MODE_DEFAULT="EDIT_MODE_DEFAULT",e.EDIT_MODE_INPAINT_REMOVAL="EDIT_MODE_INPAINT_REMOVAL",e.EDIT_MODE_INPAINT_INSERTION="EDIT_MODE_INPAINT_INSERTION",e.EDIT_MODE_OUTPAINT="EDIT_MODE_OUTPAINT",e.EDIT_MODE_CONTROLLED_EDITING="EDIT_MODE_CONTROLLED_EDITING",e.EDIT_MODE_STYLE="EDIT_MODE_STYLE",e.EDIT_MODE_BGSWAP="EDIT_MODE_BGSWAP",e.EDIT_MODE_PRODUCT_IMAGE="EDIT_MODE_PRODUCT_IMAGE"})(bt||(bt={}));var $t;(function(e){e.FOREGROUND="FOREGROUND",e.BACKGROUND="BACKGROUND",e.PROMPT="PROMPT",e.SEMANTIC="SEMANTIC",e.INTERACTIVE="INTERACTIVE"})($t||($t={}));var Ot;(function(e){e.ASSET="ASSET",e.STYLE="STYLE"})(Ot||(Ot={}));var Kt;(function(e){e.INSERT="INSERT",e.REMOVE="REMOVE",e.REMOVE_STATIC="REMOVE_STATIC",e.OUTPAINT="OUTPAINT"})(Kt||(Kt={}));var Yt;(function(e){e.OPTIMIZED="OPTIMIZED",e.LOSSLESS="LOSSLESS"})(Yt||(Yt={}));var Wt;(function(e){e.CROP="CROP",e.PAD="PAD"})(Wt||(Wt={}));var zt;(function(e){e.SUPERVISED_FINE_TUNING="SUPERVISED_FINE_TUNING",e.PREFERENCE_TUNING="PREFERENCE_TUNING",e.DISTILLATION="DISTILLATION"})(zt||(zt={}));var Xt;(function(e){e.STATE_UNSPECIFIED="STATE_UNSPECIFIED",e.PROCESSING="PROCESSING",e.ACTIVE="ACTIVE",e.FAILED="FAILED"})(Xt||(Xt={}));var Qt;(function(e){e.SOURCE_UNSPECIFIED="SOURCE_UNSPECIFIED",e.UPLOADED="UPLOADED",e.GENERATED="GENERATED",e.REGISTERED="REGISTERED"})(Qt||(Qt={}));var Zt;(function(e){e.TURN_COMPLETE_REASON_UNSPECIFIED="TURN_COMPLETE_REASON_UNSPECIFIED",e.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",e.RESPONSE_REJECTED="RESPONSE_REJECTED",e.NEED_MORE_INPUT="NEED_MORE_INPUT",e.PROHIBITED_INPUT_CONTENT="PROHIBITED_INPUT_CONTENT",e.IMAGE_PROHIBITED_INPUT_CONTENT="IMAGE_PROHIBITED_INPUT_CONTENT",e.INPUT_TEXT_CONTAIN_PROMINENT_PERSON_PROHIBITED="INPUT_TEXT_CONTAIN_PROMINENT_PERSON_PROHIBITED",e.INPUT_IMAGE_CELEBRITY="INPUT_IMAGE_CELEBRITY",e.INPUT_IMAGE_PHOTO_REALISTIC_CHILD_PROHIBITED="INPUT_IMAGE_PHOTO_REALISTIC_CHILD_PROHIBITED",e.INPUT_TEXT_NCII_PROHIBITED="INPUT_TEXT_NCII_PROHIBITED",e.INPUT_OTHER="INPUT_OTHER",e.INPUT_IP_PROHIBITED="INPUT_IP_PROHIBITED",e.BLOCKLIST="BLOCKLIST",e.UNSAFE_PROMPT_FOR_IMAGE_GENERATION="UNSAFE_PROMPT_FOR_IMAGE_GENERATION",e.GENERATED_IMAGE_SAFETY="GENERATED_IMAGE_SAFETY",e.GENERATED_CONTENT_SAFETY="GENERATED_CONTENT_SAFETY",e.GENERATED_AUDIO_SAFETY="GENERATED_AUDIO_SAFETY",e.GENERATED_VIDEO_SAFETY="GENERATED_VIDEO_SAFETY",e.GENERATED_CONTENT_PROHIBITED="GENERATED_CONTENT_PROHIBITED",e.GENERATED_CONTENT_BLOCKLIST="GENERATED_CONTENT_BLOCKLIST",e.GENERATED_IMAGE_PROHIBITED="GENERATED_IMAGE_PROHIBITED",e.GENERATED_IMAGE_CELEBRITY="GENERATED_IMAGE_CELEBRITY",e.GENERATED_IMAGE_PROMINENT_PEOPLE_DETECTED_BY_REWRITER="GENERATED_IMAGE_PROMINENT_PEOPLE_DETECTED_BY_REWRITER",e.GENERATED_IMAGE_IDENTIFIABLE_PEOPLE="GENERATED_IMAGE_IDENTIFIABLE_PEOPLE",e.GENERATED_IMAGE_MINORS="GENERATED_IMAGE_MINORS",e.OUTPUT_IMAGE_IP_PROHIBITED="OUTPUT_IMAGE_IP_PROHIBITED",e.GENERATED_OTHER="GENERATED_OTHER",e.MAX_REGENERATION_REACHED="MAX_REGENERATION_REACHED"})(Zt||(Zt={}));var jt;(function(e){e.MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",e.TEXT="TEXT",e.IMAGE="IMAGE",e.VIDEO="VIDEO",e.AUDIO="AUDIO",e.DOCUMENT="DOCUMENT"})(jt||(jt={}));var eo;(function(e){e.VAD_SIGNAL_TYPE_UNSPECIFIED="VAD_SIGNAL_TYPE_UNSPECIFIED",e.VAD_SIGNAL_TYPE_SOS="VAD_SIGNAL_TYPE_SOS",e.VAD_SIGNAL_TYPE_EOS="VAD_SIGNAL_TYPE_EOS"})(eo||(eo={}));var no;(function(e){e.TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",e.ACTIVITY_START="ACTIVITY_START",e.ACTIVITY_END="ACTIVITY_END"})(no||(no={}));var to;(function(e){e.START_SENSITIVITY_UNSPECIFIED="START_SENSITIVITY_UNSPECIFIED",e.START_SENSITIVITY_HIGH="START_SENSITIVITY_HIGH",e.START_SENSITIVITY_LOW="START_SENSITIVITY_LOW"})(to||(to={}));var oo;(function(e){e.END_SENSITIVITY_UNSPECIFIED="END_SENSITIVITY_UNSPECIFIED",e.END_SENSITIVITY_HIGH="END_SENSITIVITY_HIGH",e.END_SENSITIVITY_LOW="END_SENSITIVITY_LOW"})(oo||(oo={}));var io;(function(e){e.ACTIVITY_HANDLING_UNSPECIFIED="ACTIVITY_HANDLING_UNSPECIFIED",e.START_OF_ACTIVITY_INTERRUPTS="START_OF_ACTIVITY_INTERRUPTS",e.NO_INTERRUPTION="NO_INTERRUPTION"})(io||(io={}));var ro;(function(e){e.TURN_COVERAGE_UNSPECIFIED="TURN_COVERAGE_UNSPECIFIED",e.TURN_INCLUDES_ONLY_ACTIVITY="TURN_INCLUDES_ONLY_ACTIVITY",e.TURN_INCLUDES_ALL_INPUT="TURN_INCLUDES_ALL_INPUT",e.TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO="TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO"})(ro||(ro={}));var so;(function(e){e.SCALE_UNSPECIFIED="SCALE_UNSPECIFIED",e.C_MAJOR_A_MINOR="C_MAJOR_A_MINOR",e.D_FLAT_MAJOR_B_FLAT_MINOR="D_FLAT_MAJOR_B_FLAT_MINOR",e.D_MAJOR_B_MINOR="D_MAJOR_B_MINOR",e.E_FLAT_MAJOR_C_MINOR="E_FLAT_MAJOR_C_MINOR",e.E_MAJOR_D_FLAT_MINOR="E_MAJOR_D_FLAT_MINOR",e.F_MAJOR_D_MINOR="F_MAJOR_D_MINOR",e.G_FLAT_MAJOR_E_FLAT_MINOR="G_FLAT_MAJOR_E_FLAT_MINOR",e.G_MAJOR_E_MINOR="G_MAJOR_E_MINOR",e.A_FLAT_MAJOR_F_MINOR="A_FLAT_MAJOR_F_MINOR",e.A_MAJOR_G_FLAT_MINOR="A_MAJOR_G_FLAT_MINOR",e.B_FLAT_MAJOR_G_MINOR="B_FLAT_MAJOR_G_MINOR",e.B_MAJOR_A_FLAT_MINOR="B_MAJOR_A_FLAT_MINOR"})(so||(so={}));var lo;(function(e){e.MUSIC_GENERATION_MODE_UNSPECIFIED="MUSIC_GENERATION_MODE_UNSPECIFIED",e.QUALITY="QUALITY",e.DIVERSITY="DIVERSITY",e.VOCALIZATION="VOCALIZATION"})(lo||(lo={}));var ye;(function(e){e.PLAYBACK_CONTROL_UNSPECIFIED="PLAYBACK_CONTROL_UNSPECIFIED",e.PLAY="PLAY",e.PAUSE="PAUSE",e.STOP="STOP",e.RESET_CONTEXT="RESET_CONTEXT"})(ye||(ye={}));class me{constructor(e){let n={};for(let t of e.headers.entries())n[t[0]]=t[1];this.headers=n,this.responseInternal=e}json(){return this.responseInternal.json()}}class ge{get text(){var e,n,t,o,r,l,a,f;if(((o=(t=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||t===void 0?void 0:t.parts)===null||o===void 0?void 0:o.length)===0)return;if(this.candidates&&this.candidates.length>1)console.warn("there are multiple candidates in the response, returning text from the first one.");let d="",c=!1,m=[];for(let p of(f=(a=(l=(r=this.candidates)===null||r===void 0?void 0:r[0])===null||l===void 0?void 0:l.content)===null||a===void 0?void 0:a.parts)!==null&&f!==void 0?f:[]){for(let[g,y]of Object.entries(p))if(g!=="text"&&g!=="thought"&&g!=="thoughtSignature"&&(y!==null||y!==void 0))m.push(g);if(typeof p.text==="string"){if(typeof p.thought==="boolean"&&p.thought)continue;c=!0,d+=p.text}}if(m.length>0)console.warn(`there are non-text parts ${m} in the response, returning concatenation of all text parts. Please refer to the non text parts for a full response from model.`);return c?d:void 0}get data(){var e,n,t,o,r,l,a,f;if(((o=(t=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||t===void 0?void 0:t.parts)===null||o===void 0?void 0:o.length)===0)return;if(this.candidates&&this.candidates.length>1)console.warn("there are multiple candidates in the response, returning data from the first one.");let d="",c=[];for(let m of(f=(a=(l=(r=this.candidates)===null||r===void 0?void 0:r[0])===null||l===void 0?void 0:l.content)===null||a===void 0?void 0:a.parts)!==null&&f!==void 0?f:[]){for(let[p,g]of Object.entries(m))if(p!=="inlineData"&&(g!==null||g!==void 0))c.push(p);if(m.inlineData&&typeof m.inlineData.data==="string")d+=atob(m.inlineData.data)}if(c.length>0)console.warn(`there are non-data parts ${c} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`);return d.length>0?btoa(d):void 0}get functionCalls(){var e,n,t,o,r,l,a,f;if(((o=(t=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||t===void 0?void 0:t.parts)===null||o===void 0?void 0:o.length)===0)return;if(this.candidates&&this.candidates.length>1)console.warn("there are multiple candidates in the response, returning function calls from the first one.");let d=(f=(a=(l=(r=this.candidates)===null||r===void 0?void 0:r[0])===null||l===void 0?void 0:l.content)===null||a===void 0?void 0:a.parts)===null||f===void 0?void 0:f.filter((c)=>c.functionCall).map((c)=>c.functionCall).filter((c)=>c!==void 0);if((d===null||d===void 0?void 0:d.length)===0)return;return d}get executableCode(){var e,n,t,o,r,l,a,f,d;if(((o=(t=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||t===void 0?void 0:t.parts)===null||o===void 0?void 0:o.length)===0)return;if(this.candidates&&this.candidates.length>1)console.warn("there are multiple candidates in the response, returning executable code from the first one.");let c=(f=(a=(l=(r=this.candidates)===null||r===void 0?void 0:r[0])===null||l===void 0?void 0:l.content)===null||a===void 0?void 0:a.parts)===null||f===void 0?void 0:f.filter((m)=>m.executableCode).map((m)=>m.executableCode).filter((m)=>m!==void 0);if((c===null||c===void 0?void 0:c.length)===0)return;return(d=c===null||c===void 0?void 0:c[0])===null||d===void 0?void 0:d.code}get codeExecutionResult(){var e,n,t,o,r,l,a,f,d;if(((o=(t=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||t===void 0?void 0:t.parts)===null||o===void 0?void 0:o.length)===0)return;if(this.candidates&&this.candidates.length>1)console.warn("there are multiple candidates in the response, returning code execution result from the first one.");let c=(f=(a=(l=(r=this.candidates)===null||r===void 0?void 0:r[0])===null||l===void 0?void 0:l.content)===null||a===void 0?void 0:a.parts)===null||f===void 0?void 0:f.filter((m)=>m.codeExecutionResult).map((m)=>m.codeExecutionResult).filter((m)=>m!==void 0);if((c===null||c===void 0?void 0:c.length)===0)return;return(d=c===null||c===void 0?void 0:c[0])===null||d===void 0?void 0:d.output}}class hn{}class mn{}class qo{}class Ho{}class Bo{}class Jo{}class gn{}class yn{}class En{}class bo{}class Ke{_fromAPIResponse({apiResponse:e,_isVertexAI:n}){let t=new Ke,o,r=e;if(n)o=Ir(r);else o=_r(r);return Object.assign(t,o),t}}class $o{}class Tn{}class _n{}class In{}class Oo{}class Ko{}class Yo{}class Gn{_fromAPIResponse({apiResponse:e,_isVertexAI:n}){let t=new Gn,r=wr(e);return Object.assign(t,r),t}}class Wo{}class zo{}class Xo{}class Qo{}class Cn{}class Zo{get text(){var e,n,t;let o="",r=!1,l=[];for(let a of(t=(n=(e=this.serverContent)===null||e===void 0?void 0:e.modelTurn)===null||n===void 0?void 0:n.parts)!==null&&t!==void 0?t:[]){for(let[f,d]of Object.entries(a))if(f!=="text"&&f!=="thought"&&d!==null)l.push(f);if(typeof a.text==="string"){if(typeof a.thought==="boolean"&&a.thought)continue;r=!0,o+=a.text}}if(l.length>0)console.warn(`there are non-text parts ${l} in the response, returning concatenation of all text parts. Please refer to the non text parts for a full response from model.`);return r?o:void 0}get data(){var e,n,t;let o="",r=[];for(let l of(t=(n=(e=this.serverContent)===null||e===void 0?void 0:e.modelTurn)===null||n===void 0?void 0:n.parts)!==null&&t!==void 0?t:[]){for(let[a,f]of Object.entries(l))if(a!=="inlineData"&&f!==null)r.push(a);if(l.inlineData&&typeof l.inlineData.data==="string")o+=atob(l.inlineData.data)}if(r.length>0)console.warn(`there are non-data parts ${r} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`);return o.length>0?btoa(o):void 0}}class jo{get audioChunk(){if(this.serverContent&&this.serverContent.audioChunks&&this.serverContent.audioChunks.length>0)return this.serverContent.audioChunks[0];return}}class nn{_fromAPIResponse({apiResponse:e,_isVertexAI:n}){let t=new nn,r=Ln(e);return Object.assign(t,r),t}}function L(e,n){if(!n||typeof n!=="string")throw Error("model is required and must be a string");if(n.includes("..")||n.includes("?")||n.includes("&"))throw Error("invalid model parameter");if(e.isVertexAI())if(n.startsWith("publishers/")||n.startsWith("projects/")||n.startsWith("models/"))return n;else if(n.indexOf("/")>=0){let t=n.split("/",2);return`publishers/${t[0]}/models/${t[1]}`}else return`publishers/google/models/${n}`;else if(n.startsWith("models/")||n.startsWith("tunedModels/"))return n;else return`models/${n}`}function ei(e,n){let t=L(e,n);if(!t)return"";if(t.startsWith("publishers/")&&e.isVertexAI())return`projects/${e.getProject()}/locations/${e.getLocation()}/${t}`;else if(t.startsWith("models/")&&e.isVertexAI())return`projects/${e.getProject()}/locations/${e.getLocation()}/publishers/google/${t}`;else return t}function ni(e){if(Array.isArray(e))return e.map((n)=>Ye(n));else return[Ye(e)]}function Ye(e){if(typeof e==="object"&&e!==null)return e;throw Error(`Could not parse input as Blob. Unsupported blob type: ${typeof e}`)}function ti(e){let n=Ye(e);if(n.mimeType&&n.mimeType.startsWith("image/"))return n;throw Error(`Unsupported mime type: ${n.mimeType}`)}function oi(e){let n=Ye(e);if(n.mimeType&&n.mimeType.startsWith("audio/"))return n;throw Error(`Unsupported mime type: ${n.mimeType}`)}function ao(e){if(e===null||e===void 0)throw Error("PartUnion is required");if(typeof e==="object")return e;if(typeof e==="string")return{text:e};throw Error(`Unsupported part type: ${typeof e}`)}function ii(e){if(e===null||e===void 0||Array.isArray(e)&&e.length===0)throw Error("PartListUnion is required");if(Array.isArray(e))return e.map((n)=>ao(n));return[ao(e)]}function An(e){return e!==null&&e!==void 0&&typeof e==="object"&&"parts"in e&&Array.isArray(e.parts)}function uo(e){return e!==null&&e!==void 0&&typeof e==="object"&&"functionCall"in e}function fo(e){return e!==null&&e!==void 0&&typeof e==="object"&&"functionResponse"in e}function B(e){if(e===null||e===void 0)throw Error("ContentUnion is required");if(An(e))return e;return{role:"user",parts:ii(e)}}function kn(e,n){if(!n)return[];if(e.isVertexAI()&&Array.isArray(n))return n.flatMap((t)=>{let o=B(t);if(o.parts&&o.parts.length>0&&o.parts[0].text!==void 0)return[o.parts[0].text];return[]});else if(e.isVertexAI()){let t=B(n);if(t.parts&&t.parts.length>0&&t.parts[0].text!==void 0)return[t.parts[0].text];return[]}if(Array.isArray(n))return n.map((t)=>B(t));return[B(n)]}function O(e){if(e===null||e===void 0||Array.isArray(e)&&e.length===0)throw Error("contents are required");if(!Array.isArray(e)){if(uo(e)||fo(e))throw Error("To specify functionCall or functionResponse parts, please wrap them in a Content object, specifying the role for them");return[B(e)]}let n=[],t=[],o=An(e[0]);for(let r of e){let l=An(r);if(l!=o)throw Error("Mixing Content and Parts is not supported, please group the parts into a the appropriate Content objects and specify the roles for them");if(l)n.push(r);else if(uo(r)||fo(r))throw Error("To specify functionCall or functionResponse parts, please wrap them, and any other parts, in Content objects as appropriate, specifying the role for them");else t.push(r)}if(!o)n.push({role:"user",parts:ii(t)});return n}function Ur(e,n){if(e.includes("null"))n.nullable=!0;let t=e.filter((o)=>o!=="null");if(t.length===1)n.type=Object.values(re).includes(t[0].toUpperCase())?t[0].toUpperCase():re.TYPE_UNSPECIFIED;else{n.anyOf=[];for(let o of t)n.anyOf.push({type:Object.values(re).includes(o.toUpperCase())?o.toUpperCase():re.TYPE_UNSPECIFIED})}}function Te(e){let n={},t=["items"],o=["anyOf"],r=["properties"];if(e.type&&e.anyOf)throw Error("type and anyOf cannot be both populated.");let l=e.anyOf;if(l!=null&&l.length==2){if(l[0].type==="null")n.nullable=!0,e=l[1];else if(l[1].type==="null")n.nullable=!0,e=l[0]}if(e.type instanceof Array)Ur(e.type,n);for(let[a,f]of Object.entries(e)){if(f==null)continue;if(a=="type"){if(f==="null")throw Error("type: null can not be the only possible type for the field.");if(f instanceof Array)continue;n.type=Object.values(re).includes(f.toUpperCase())?f.toUpperCase():re.TYPE_UNSPECIFIED}else if(t.includes(a))n[a]=Te(f);else if(o.includes(a)){let d=[];for(let c of f){if(c.type=="null"){n.nullable=!0;continue}d.push(Te(c))}n[a]=d}else if(r.includes(a)){let d={};for(let[c,m]of Object.entries(f))d[c]=Te(m);n[a]=d}else{if(a==="additionalProperties")continue;n[a]=f}}return n}function Fn(e){return Te(e)}function Vn(e){if(typeof e==="object")return e;else if(typeof e==="string")return{voiceConfig:{prebuiltVoiceConfig:{voiceName:e}}};else throw Error(`Unsupported speechConfig type: ${typeof e}`)}function qn(e){if("multiSpeakerVoiceConfig"in e)throw Error("multiSpeakerVoiceConfig is not supported in the live API.");return e}function Ie(e){if(e.functionDeclarations)for(let n of e.functionDeclarations){if(n.parameters){if(!Object.keys(n.parameters).includes("$schema"))n.parameters=Te(n.parameters);else if(!n.parametersJsonSchema)n.parametersJsonSchema=n.parameters,delete n.parameters}if(n.response){if(!Object.keys(n.response).includes("$schema"))n.response=Te(n.response);else if(!n.responseJsonSchema)n.responseJsonSchema=n.response,delete n.response}}return e}function Ce(e){if(e===void 0||e===null)throw Error("tools is required");if(!Array.isArray(e))throw Error("tools is required and must be an array of Tools");let n=[];for(let t of e)n.push(t);return n}function Lr(e,n,t,o=1){let r=!n.startsWith(`${t}/`)&&n.split("/").length===o;if(e.isVertexAI())if(n.startsWith("projects/"))return n;else if(n.startsWith("locations/"))return`projects/${e.getProject()}/${n}`;else if(n.startsWith(`${t}/`))return`projects/${e.getProject()}/locations/${e.getLocation()}/${n}`;else if(r)return`projects/${e.getProject()}/locations/${e.getLocation()}/${t}/${n}`;else return n;if(r)return`${t}/${n}`;return n}function ie(e,n){if(typeof n!=="string")throw Error("name must be a string");return Lr(e,n,"cachedContents")}function ri(e){switch(e){case"STATE_UNSPECIFIED":return"JOB_STATE_UNSPECIFIED";case"CREATING":return"JOB_STATE_RUNNING";case"ACTIVE":return"JOB_STATE_SUCCEEDED";case"FAILED":return"JOB_STATE_FAILED";default:return e}}function de(e){return Un(e)}function Gr(e){return e!==null&&e!==void 0&&typeof e==="object"&&"name"in e}function si(e){return e!==null&&e!==void 0&&typeof e==="object"&&"video"in e}function li(e){return e!==null&&e!==void 0&&typeof e==="object"&&"uri"in e}function Hn(e){var n;let t;if(Gr(e))t=e.name;if(li(e)){if(t=e.uri,t===void 0)return}if(si(e)){if(t=(n=e.video)===null||n===void 0?void 0:n.uri,t===void 0)return}if(typeof e==="string")t=e;if(t===void 0)throw Error("Could not extract file name from the provided input.");if(t.startsWith("https://")){let r=t.split("files/")[1].match(/[a-z0-9]+/);if(r===null)throw Error(`Could not extract file name from URI ${t}`);t=r[0]}else if(t.startsWith("files/"))t=t.split("files/")[1];return t}function ai(e,n){let t;if(e.isVertexAI())t=n?"publishers/google/models":"models";else t=n?"models":"tunedModels";return t}function ui(e){for(let n of["models","tunedModels","publisherModels"])if(kr(e,n))return e[n];return[]}function kr(e,n){return e!==null&&typeof e==="object"&&n in e}function Fr(e,n={}){let t=e,o={name:t.name,description:t.description,parametersJsonSchema:t.inputSchema};if(t.outputSchema)o.responseJsonSchema=t.outputSchema;if(n.behavior)o.behavior=n.behavior;return{functionDeclarations:[o]}}function Vr(e,n={}){let t=[],o=new Set;for(let r of e){let l=r.name;if(o.has(l))throw Error(`Duplicate function name ${l} found in MCP tools. Please ensure function names are unique.`);o.add(l);let a=Fr(r,n);if(a.functionDeclarations)t.push(...a.functionDeclarations)}return{functionDeclarations:t}}function di(e,n){let t;if(typeof n==="string")if(e.isVertexAI())if(n.startsWith("gs://"))t={format:"jsonl",gcsUri:[n]};else if(n.startsWith("bq://"))t={format:"bigquery",bigqueryUri:n};else if(/^projects\/[^/]+\/locations\/[^/]+\/datasets\/[^/]+$/.test(n))t={format:"vertex-dataset",vertexDatasetName:n};else throw Error(`Unsupported string source for Vertex AI: ${n}`);else if(n.startsWith("files/"))t={fileName:n};else throw Error(`Unsupported string source for Gemini API: ${n}`);else if(Array.isArray(n)){if(e.isVertexAI())throw Error("InlinedRequest[] is not supported in Vertex AI.");t={inlinedRequests:n}}else t=n;let o=[t.gcsUri,t.bigqueryUri,t.vertexDatasetName].filter(Boolean).length,r=[t.inlinedRequests,t.fileName].filter(Boolean).length;if(e.isVertexAI()){if(r>0||o!==1)throw Error("Exactly one of `gcsUri`, `bigqueryUri`, or `vertexDatasetName` must be set for Vertex AI.")}else if(o>0||r!==1)throw Error("Exactly one of `inlinedRequests`, `fileName`, must be set for Gemini API.");return t}function qr(e){if(typeof e!=="string")return e;let n=e;if(n.startsWith("gs://"))return{format:"jsonl",gcsUri:n};else if(n.startsWith("bq://"))return{format:"bigquery",bigqueryUri:n};else throw Error(`Unsupported destination: ${n}`)}function fi(e){if(typeof e!=="object"||e===null)return{};let n=e,t=n.inlinedResponses;if(typeof t!=="object"||t===null)return e;let r=t.inlinedResponses;if(!Array.isArray(r)||r.length===0)return e;let l=!1;for(let a of r){if(typeof a!=="object"||a===null)continue;let d=a.response;if(typeof d!=="object"||d===null)continue;if(d.embedding!==void 0){l=!0;break}}if(l)n.inlinedEmbedContentResponses=n.inlinedResponses,delete n.inlinedResponses;return e}function ve(e,n){let t=n;if(!e.isVertexAI())if(/batches\/[^/]+$/.test(t))return t.split("/").pop();else throw Error(`Invalid batch job name: ${t}.`);if(/^projects\/[^/]+\/locations\/[^/]+\/batchPredictionJobs\/[^/]+$/.test(t))return t.split("/").pop();else if(/^\d+$/.test(t))return t;else throw Error(`Invalid batch job name: ${t}.`)}function ci(e){let n=e;if(n==="BATCH_STATE_UNSPECIFIED")return"JOB_STATE_UNSPECIFIED";else if(n==="BATCH_STATE_PENDING")return"JOB_STATE_PENDING";else if(n==="BATCH_STATE_RUNNING")return"JOB_STATE_RUNNING";else if(n==="BATCH_STATE_SUCCEEDED")return"JOB_STATE_SUCCEEDED";else if(n==="BATCH_STATE_FAILED")return"JOB_STATE_FAILED";else if(n==="BATCH_STATE_CANCELLED")return"JOB_STATE_CANCELLED";else if(n==="BATCH_STATE_EXPIRED")return"JOB_STATE_EXPIRED";else return n}function Hr(e){return e.includes("gemini")&&e!=="gemini-embedding-001"||e.includes("maas")}function Br(e){let n={},t=i(e,["apiKey"]);if(t!=null)s(n,["apiKey"],t);if(i(e,["apiKeyConfig"])!==void 0)throw Error("apiKeyConfig parameter is not supported in Gemini API.");if(i(e,["authType"])!==void 0)throw Error("authType parameter is not supported in Gemini API.");if(i(e,["googleServiceAccountConfig"])!==void 0)throw Error("googleServiceAccountConfig parameter is not supported in Gemini API.");if(i(e,["httpBasicAuthConfig"])!==void 0)throw Error("httpBasicAuthConfig parameter is not supported in Gemini API.");if(i(e,["oauthConfig"])!==void 0)throw Error("oauthConfig parameter is not supported in Gemini API.");if(i(e,["oidcConfig"])!==void 0)throw Error("oidcConfig parameter is not supported in Gemini API.");return n}function Jr(e){let n={},t=i(e,["responsesFile"]);if(t!=null)s(n,["fileName"],t);let o=i(e,["inlinedResponses","inlinedResponses"]);if(o!=null){let l=o;if(Array.isArray(l))l=l.map((a)=>Cs(a));s(n,["inlinedResponses"],l)}let r=i(e,["inlinedEmbedContentResponses","inlinedResponses"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>a);s(n,["inlinedEmbedContentResponses"],l)}return n}function br(e){let n={},t=i(e,["predictionsFormat"]);if(t!=null)s(n,["format"],t);let o=i(e,["gcsDestination","outputUriPrefix"]);if(o!=null)s(n,["gcsUri"],o);let r=i(e,["bigqueryDestination","outputUri"]);if(r!=null)s(n,["bigqueryUri"],r);let l=i(e,["vertexMultimodalDatasetDestination"]);if(l!=null)s(n,["vertexDataset"],Us(l));return n}function $r(e){let n={},t=i(e,["format"]);if(t!=null)s(n,["predictionsFormat"],t);let o=i(e,["gcsUri"]);if(o!=null)s(n,["gcsDestination","outputUriPrefix"],o);let r=i(e,["bigqueryUri"]);if(r!=null)s(n,["bigqueryDestination","outputUri"],r);if(i(e,["fileName"])!==void 0)throw Error("fileName parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");if(i(e,["inlinedResponses"])!==void 0)throw Error("inlinedResponses parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");if(i(e,["inlinedEmbedContentResponses"])!==void 0)throw Error("inlinedEmbedContentResponses parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");let l=i(e,["vertexDataset"]);if(l!=null)s(n,["vertexMultimodalDatasetDestination"],Ls(l));return n}function Je(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["name"],t);let o=i(e,["metadata","displayName"]);if(o!=null)s(n,["displayName"],o);let r=i(e,["metadata","state"]);if(r!=null)s(n,["state"],ci(r));let l=i(e,["metadata","createTime"]);if(l!=null)s(n,["createTime"],l);let a=i(e,["metadata","endTime"]);if(a!=null)s(n,["endTime"],a);let f=i(e,["metadata","updateTime"]);if(f!=null)s(n,["updateTime"],f);let d=i(e,["metadata","model"]);if(d!=null)s(n,["model"],d);let c=i(e,["metadata","output"]);if(c!=null)s(n,["dest"],Jr(fi(c)));return n}function vn(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["name"],t);let o=i(e,["displayName"]);if(o!=null)s(n,["displayName"],o);let r=i(e,["state"]);if(r!=null)s(n,["state"],ci(r));let l=i(e,["error"]);if(l!=null)s(n,["error"],l);let a=i(e,["createTime"]);if(a!=null)s(n,["createTime"],a);let f=i(e,["startTime"]);if(f!=null)s(n,["startTime"],f);let d=i(e,["endTime"]);if(d!=null)s(n,["endTime"],d);let c=i(e,["updateTime"]);if(c!=null)s(n,["updateTime"],c);let m=i(e,["model"]);if(m!=null)s(n,["model"],m);let p=i(e,["inputConfig"]);if(p!=null)s(n,["src"],Or(p));let g=i(e,["outputConfig"]);if(g!=null)s(n,["dest"],br(fi(g)));let y=i(e,["completionStats"]);if(y!=null)s(n,["completionStats"],y);let E=i(e,["outputInfo"]);if(E!=null)s(n,["outputInfo"],E);return n}function Or(e){let n={},t=i(e,["instancesFormat"]);if(t!=null)s(n,["format"],t);let o=i(e,["gcsSource","uris"]);if(o!=null)s(n,["gcsUri"],o);let r=i(e,["bigquerySource","inputUri"]);if(r!=null)s(n,["bigqueryUri"],r);let l=i(e,["vertexMultimodalDatasetSource","datasetName"]);if(l!=null)s(n,["vertexDatasetName"],l);return n}function Kr(e,n){let t={};if(i(n,["format"])!==void 0)throw Error("format parameter is not supported in Gemini API.");if(i(n,["gcsUri"])!==void 0)throw Error("gcsUri parameter is not supported in Gemini API.");if(i(n,["bigqueryUri"])!==void 0)throw Error("bigqueryUri parameter is not supported in Gemini API.");let o=i(n,["fileName"]);if(o!=null)s(t,["fileName"],o);let r=i(n,["inlinedRequests"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>Is(e,a));s(t,["requests","requests"],l)}if(i(n,["vertexDatasetName"])!==void 0)throw Error("vertexDatasetName parameter is not supported in Gemini API.");return t}function Yr(e){let n={},t=i(e,["format"]);if(t!=null)s(n,["instancesFormat"],t);let o=i(e,["gcsUri"]);if(o!=null)s(n,["gcsSource","uris"],o);let r=i(e,["bigqueryUri"]);if(r!=null)s(n,["bigquerySource","inputUri"],r);if(i(e,["fileName"])!==void 0)throw Error("fileName parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");if(i(e,["inlinedRequests"])!==void 0)throw Error("inlinedRequests parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");let l=i(e,["vertexDatasetName"]);if(l!=null)s(n,["vertexMultimodalDatasetSource","datasetName"],l);return n}function Wr(e){let n={},t=i(e,["data"]);if(t!=null)s(n,["data"],t);if(i(e,["displayName"])!==void 0)throw Error("displayName parameter is not supported in Gemini API.");let o=i(e,["mimeType"]);if(o!=null)s(n,["mimeType"],o);return n}function zr(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ve(e,o));return t}function Xr(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ve(e,o));return t}function Qr(e){let n={},t=i(e,["content"]);if(t!=null)s(n,["content"],t);let o=i(e,["citationMetadata"]);if(o!=null)s(n,["citationMetadata"],Zr(o));let r=i(e,["tokenCount"]);if(r!=null)s(n,["tokenCount"],r);let l=i(e,["finishReason"]);if(l!=null)s(n,["finishReason"],l);let a=i(e,["groundingMetadata"]);if(a!=null)s(n,["groundingMetadata"],a);let f=i(e,["avgLogprobs"]);if(f!=null)s(n,["avgLogprobs"],f);let d=i(e,["index"]);if(d!=null)s(n,["index"],d);let c=i(e,["logprobsResult"]);if(c!=null)s(n,["logprobsResult"],c);let m=i(e,["safetyRatings"]);if(m!=null){let g=m;if(Array.isArray(g))g=g.map((y)=>y);s(n,["safetyRatings"],g)}let p=i(e,["urlContextMetadata"]);if(p!=null)s(n,["urlContextMetadata"],p);return n}function Zr(e){let n={},t=i(e,["citationSources"]);if(t!=null){let o=t;if(Array.isArray(o))o=o.map((r)=>r);s(n,["citations"],o)}return n}function pi(e){let n={},t=i(e,["parts"]);if(t!=null){let r=t;if(Array.isArray(r))r=r.map((l)=>Ns(l));s(n,["parts"],r)}let o=i(e,["role"]);if(o!=null)s(n,["role"],o);return n}function jr(e,n){let t={},o=i(e,["displayName"]);if(n!==void 0&&o!=null)s(n,["batch","displayName"],o);if(i(e,["dest"])!==void 0)throw Error("dest parameter is not supported in Gemini API.");let r=i(e,["webhookConfig"]);if(n!==void 0&&r!=null)s(n,["batch","webhookConfig"],r);return t}function es(e,n){let t={},o=i(e,["displayName"]);if(n!==void 0&&o!=null)s(n,["displayName"],o);let r=i(e,["dest"]);if(n!==void 0&&r!=null)s(n,["outputConfig"],$r(qr(r)));if(i(e,["webhookConfig"])!==void 0)throw Error("webhookConfig parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return t}function co(e,n){let t={},o=i(n,["model"]);if(o!=null)s(t,["_url","model"],L(e,o));let r=i(n,["src"]);if(r!=null)s(t,["batch","inputConfig"],Kr(e,di(e,r)));let l=i(n,["config"]);if(l!=null)jr(l,t);return t}function ns(e,n){let t={},o=i(n,["model"]);if(o!=null)s(t,["model"],L(e,o));let r=i(n,["src"]);if(r!=null)s(t,["inputConfig"],Yr(di(e,r)));let l=i(n,["config"]);if(l!=null)es(l,t);return t}function ts(e,n){let t={},o=i(e,["displayName"]);if(n!==void 0&&o!=null)s(n,["batch","displayName"],o);return t}function os(e,n){let t={},o=i(n,["model"]);if(o!=null)s(t,["_url","model"],L(e,o));let r=i(n,["src"]);if(r!=null)s(t,["batch","inputConfig"],ds(e,r));let l=i(n,["config"]);if(l!=null)ts(l,t);return t}function is(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ve(e,o));return t}function rs(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ve(e,o));return t}function ss(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["name"]);if(o!=null)s(n,["name"],o);let r=i(e,["done"]);if(r!=null)s(n,["done"],r);let l=i(e,["error"]);if(l!=null)s(n,["error"],l);return n}function ls(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["name"]);if(o!=null)s(n,["name"],o);let r=i(e,["done"]);if(r!=null)s(n,["done"],r);let l=i(e,["error"]);if(l!=null)s(n,["error"],l);return n}function as(e,n){let t={},o=i(n,["contents"]);if(o!=null){let l=kn(e,o);if(Array.isArray(l))l=l.map((a)=>a);s(t,["requests[]","request","content"],l)}let r=i(n,["config"]);if(r!=null)s(t,["_self"],us(r,t)),Er(t,{"requests[].*":"requests[].request.*"});return t}function us(e,n){let t={},o=i(e,["taskType"]);if(n!==void 0&&o!=null)s(n,["requests[]","taskType"],o);let r=i(e,["title"]);if(n!==void 0&&r!=null)s(n,["requests[]","title"],r);let l=i(e,["outputDimensionality"]);if(n!==void 0&&l!=null)s(n,["requests[]","outputDimensionality"],l);if(i(e,["mimeType"])!==void 0)throw Error("mimeType parameter is not supported in Gemini API.");if(i(e,["autoTruncate"])!==void 0)throw Error("autoTruncate parameter is not supported in Gemini API.");if(i(e,["documentOcr"])!==void 0)throw Error("documentOcr parameter is not supported in Gemini API.");if(i(e,["audioTrackExtraction"])!==void 0)throw Error("audioTrackExtraction parameter is not supported in Gemini API.");return t}function ds(e,n){let t={},o=i(n,["fileName"]);if(o!=null)s(t,["file_name"],o);let r=i(n,["inlinedRequests"]);if(r!=null)s(t,["requests"],as(e,r));return t}function fs(e){let n={};if(i(e,["displayName"])!==void 0)throw Error("displayName parameter is not supported in Gemini API.");let t=i(e,["fileUri"]);if(t!=null)s(n,["fileUri"],t);let o=i(e,["mimeType"]);if(o!=null)s(n,["mimeType"],o);return n}function cs(e){let n={},t=i(e,["id"]);if(t!=null)s(n,["id"],t);let o=i(e,["args"]);if(o!=null)s(n,["args"],o);let r=i(e,["name"]);if(r!=null)s(n,["name"],r);if(i(e,["partialArgs"])!==void 0)throw Error("partialArgs parameter is not supported in Gemini API.");if(i(e,["willContinue"])!==void 0)throw Error("willContinue parameter is not supported in Gemini API.");return n}function ps(e){let n={},t=i(e,["allowedFunctionNames"]);if(t!=null)s(n,["allowedFunctionNames"],t);let o=i(e,["mode"]);if(o!=null)s(n,["mode"],o);if(i(e,["streamFunctionCallArguments"])!==void 0)throw Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return n}function hs(e,n,t){let o={},r=i(n,["systemInstruction"]);if(t!==void 0&&r!=null)s(t,["systemInstruction"],pi(B(r)));let l=i(n,["temperature"]);if(l!=null)s(o,["temperature"],l);let a=i(n,["topP"]);if(a!=null)s(o,["topP"],a);let f=i(n,["topK"]);if(f!=null)s(o,["topK"],f);let d=i(n,["candidateCount"]);if(d!=null)s(o,["candidateCount"],d);let c=i(n,["maxOutputTokens"]);if(c!=null)s(o,["maxOutputTokens"],c);let m=i(n,["stopSequences"]);if(m!=null)s(o,["stopSequences"],m);let p=i(n,["responseLogprobs"]);if(p!=null)s(o,["responseLogprobs"],p);let g=i(n,["logprobs"]);if(g!=null)s(o,["logprobs"],g);let y=i(n,["presencePenalty"]);if(y!=null)s(o,["presencePenalty"],y);let E=i(n,["frequencyPenalty"]);if(E!=null)s(o,["frequencyPenalty"],E);let T=i(n,["seed"]);if(T!=null)s(o,["seed"],T);let _=i(n,["responseMimeType"]);if(_!=null)s(o,["responseMimeType"],_);let C=i(n,["responseSchema"]);if(C!=null)s(o,["responseSchema"],Fn(C));let v=i(n,["responseJsonSchema"]);if(v!=null)s(o,["responseJsonSchema"],v);if(i(n,["routingConfig"])!==void 0)throw Error("routingConfig parameter is not supported in Gemini API.");if(i(n,["modelSelectionConfig"])!==void 0)throw Error("modelSelectionConfig parameter is not supported in Gemini API.");let R=i(n,["safetySettings"]);if(t!==void 0&&R!=null){let q=R;if(Array.isArray(q))q=q.map((V)=>Ms(V));s(t,["safetySettings"],q)}let P=i(n,["tools"]);if(t!==void 0&&P!=null){let q=Ce(P);if(Array.isArray(q))q=q.map((V)=>xs(Ie(V)));s(t,["tools"],q)}let x=i(n,["toolConfig"]);if(t!==void 0&&x!=null)s(t,["toolConfig"],Ds(x));if(i(n,["labels"])!==void 0)throw Error("labels parameter is not supported in Gemini API.");let I=i(n,["cachedContent"]);if(t!==void 0&&I!=null)s(t,["cachedContent"],ie(e,I));let U=i(n,["responseModalities"]);if(U!=null)s(o,["responseModalities"],U);let A=i(n,["mediaResolution"]);if(A!=null)s(o,["mediaResolution"],A);let M=i(n,["speechConfig"]);if(M!=null)s(o,["speechConfig"],Vn(M));if(i(n,["audioTimestamp"])!==void 0)throw Error("audioTimestamp parameter is not supported in Gemini API.");let G=i(n,["thinkingConfig"]);if(G!=null)s(o,["thinkingConfig"],G);let K=i(n,["imageConfig"]);if(K!=null)s(o,["imageConfig"],_s(K));let W=i(n,["enableEnhancedCivicAnswers"]);if(W!=null)s(o,["enableEnhancedCivicAnswers"],W);if(i(n,["modelArmorConfig"])!==void 0)throw Error("modelArmorConfig parameter is not supported in Gemini API.");let z=i(n,["serviceTier"]);if(t!==void 0&&z!=null)s(t,["serviceTier"],z);return o}function ms(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["candidates"]);if(o!=null){let c=o;if(Array.isArray(c))c=c.map((m)=>Qr(m));s(n,["candidates"],c)}let r=i(e,["modelVersion"]);if(r!=null)s(n,["modelVersion"],r);let l=i(e,["promptFeedback"]);if(l!=null)s(n,["promptFeedback"],l);let a=i(e,["responseId"]);if(a!=null)s(n,["responseId"],a);let f=i(e,["usageMetadata"]);if(f!=null)s(n,["usageMetadata"],f);let d=i(e,["modelStatus"]);if(d!=null)s(n,["modelStatus"],d);return n}function gs(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ve(e,o));return t}function ys(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ve(e,o));return t}function Es(e){let n={},t=i(e,["authConfig"]);if(t!=null)s(n,["authConfig"],Br(t));let o=i(e,["enableWidget"]);if(o!=null)s(n,["enableWidget"],o);return n}function Ts(e){let n={},t=i(e,["searchTypes"]);if(t!=null)s(n,["searchTypes"],t);if(i(e,["blockingConfidence"])!==void 0)throw Error("blockingConfidence parameter is not supported in Gemini API.");if(i(e,["excludeDomains"])!==void 0)throw Error("excludeDomains parameter is not supported in Gemini API.");let o=i(e,["timeRangeFilter"]);if(o!=null)s(n,["timeRangeFilter"],o);return n}function _s(e){let n={},t=i(e,["aspectRatio"]);if(t!=null)s(n,["aspectRatio"],t);let o=i(e,["imageSize"]);if(o!=null)s(n,["imageSize"],o);if(i(e,["personGeneration"])!==void 0)throw Error("personGeneration parameter is not supported in Gemini API.");if(i(e,["prominentPeople"])!==void 0)throw Error("prominentPeople parameter is not supported in Gemini API.");if(i(e,["outputMimeType"])!==void 0)throw Error("outputMimeType parameter is not supported in Gemini API.");if(i(e,["outputCompressionQuality"])!==void 0)throw Error("outputCompressionQuality parameter is not supported in Gemini API.");if(i(e,["imageOutputOptions"])!==void 0)throw Error("imageOutputOptions parameter is not supported in Gemini API.");return n}function Is(e,n){let t={},o=i(n,["model"]);if(o!=null)s(t,["request","model"],L(e,o));let r=i(n,["contents"]);if(r!=null){let f=O(r);if(Array.isArray(f))f=f.map((d)=>pi(d));s(t,["request","contents"],f)}let l=i(n,["metadata"]);if(l!=null)s(t,["metadata"],l);let a=i(n,["config"]);if(a!=null)s(t,["request","generationConfig"],hs(e,a,i(t,["request"],{})));return t}function Cs(e){let n={},t=i(e,["response"]);if(t!=null)s(n,["response"],ms(t));let o=i(e,["metadata"]);if(o!=null)s(n,["metadata"],o);let r=i(e,["error"]);if(r!=null)s(n,["error"],r);return n}function As(e,n){let t={},o=i(e,["pageSize"]);if(n!==void 0&&o!=null)s(n,["_query","pageSize"],o);let r=i(e,["pageToken"]);if(n!==void 0&&r!=null)s(n,["_query","pageToken"],r);if(i(e,["filter"])!==void 0)throw Error("filter parameter is not supported in Gemini API.");return t}function vs(e,n){let t={},o=i(e,["pageSize"]);if(n!==void 0&&o!=null)s(n,["_query","pageSize"],o);let r=i(e,["pageToken"]);if(n!==void 0&&r!=null)s(n,["_query","pageToken"],r);let l=i(e,["filter"]);if(n!==void 0&&l!=null)s(n,["_query","filter"],l);return t}function Ss(e){let n={},t=i(e,["config"]);if(t!=null)As(t,n);return n}function Rs(e){let n={},t=i(e,["config"]);if(t!=null)vs(t,n);return n}function Ps(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["nextPageToken"]);if(o!=null)s(n,["nextPageToken"],o);let r=i(e,["operations"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>Je(a));s(n,["batchJobs"],l)}return n}function ws(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["nextPageToken"]);if(o!=null)s(n,["nextPageToken"],o);let r=i(e,["batchPredictionJobs"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>vn(a));s(n,["batchJobs"],l)}return n}function Ns(e){let n={},t=i(e,["mediaResolution"]);if(t!=null)s(n,["mediaResolution"],t);let o=i(e,["codeExecutionResult"]);if(o!=null)s(n,["codeExecutionResult"],o);let r=i(e,["executableCode"]);if(r!=null)s(n,["executableCode"],r);let l=i(e,["fileData"]);if(l!=null)s(n,["fileData"],fs(l));let a=i(e,["functionCall"]);if(a!=null)s(n,["functionCall"],cs(a));let f=i(e,["functionResponse"]);if(f!=null)s(n,["functionResponse"],f);let d=i(e,["inlineData"]);if(d!=null)s(n,["inlineData"],Wr(d));let c=i(e,["text"]);if(c!=null)s(n,["text"],c);let m=i(e,["thought"]);if(m!=null)s(n,["thought"],m);let p=i(e,["thoughtSignature"]);if(p!=null)s(n,["thoughtSignature"],p);let g=i(e,["videoMetadata"]);if(g!=null)s(n,["videoMetadata"],g);let y=i(e,["toolCall"]);if(y!=null)s(n,["toolCall"],y);let E=i(e,["toolResponse"]);if(E!=null)s(n,["toolResponse"],E);let T=i(e,["partMetadata"]);if(T!=null)s(n,["partMetadata"],T);return n}function Ms(e){let n={},t=i(e,["category"]);if(t!=null)s(n,["category"],t);if(i(e,["method"])!==void 0)throw Error("method parameter is not supported in Gemini API.");let o=i(e,["threshold"]);if(o!=null)s(n,["threshold"],o);return n}function Ds(e){let n={},t=i(e,["retrievalConfig"]);if(t!=null)s(n,["retrievalConfig"],t);let o=i(e,["functionCallingConfig"]);if(o!=null)s(n,["functionCallingConfig"],ps(o));let r=i(e,["includeServerSideToolInvocations"]);if(r!=null)s(n,["includeServerSideToolInvocations"],r);return n}function xs(e){let n={};if(i(e,["retrieval"])!==void 0)throw Error("retrieval parameter is not supported in Gemini API.");let t=i(e,["computerUse"]);if(t!=null)s(n,["computerUse"],t);let o=i(e,["fileSearch"]);if(o!=null)s(n,["fileSearch"],o);let r=i(e,["googleSearch"]);if(r!=null)s(n,["googleSearch"],Ts(r));let l=i(e,["googleMaps"]);if(l!=null)s(n,["googleMaps"],Es(l));let a=i(e,["codeExecution"]);if(a!=null)s(n,["codeExecution"],a);if(i(e,["enterpriseWebSearch"])!==void 0)throw Error("enterpriseWebSearch parameter is not supported in Gemini API.");let f=i(e,["functionDeclarations"]);if(f!=null){let p=f;if(Array.isArray(p))p=p.map((g)=>g);s(n,["functionDeclarations"],p)}let d=i(e,["googleSearchRetrieval"]);if(d!=null)s(n,["googleSearchRetrieval"],d);if(i(e,["parallelAiSearch"])!==void 0)throw Error("parallelAiSearch parameter is not supported in Gemini API.");let c=i(e,["urlContext"]);if(c!=null)s(n,["urlContext"],c);let m=i(e,["mcpServers"]);if(m!=null){let p=m;if(Array.isArray(p))p=p.map((g)=>g);s(n,["mcpServers"],p)}return n}function Us(e){let n={},t=i(e,["bigqueryDestination","outputUri"]);if(t!=null)s(n,["bigqueryDestination"],t);let o=i(e,["displayName"]);if(o!=null)s(n,["displayName"],o);return n}function Ls(e){let n={},t=i(e,["bigqueryDestination"]);if(t!=null)s(n,["bigqueryDestination","outputUri"],t);let o=i(e,["displayName"]);if(o!=null)s(n,["displayName"],o);return n}var oe;(function(e){e.PAGED_ITEM_BATCH_JOBS="batchJobs",e.PAGED_ITEM_MODELS="models",e.PAGED_ITEM_TUNING_JOBS="tuningJobs",e.PAGED_ITEM_FILES="files",e.PAGED_ITEM_CACHED_CONTENTS="cachedContents",e.PAGED_ITEM_FILE_SEARCH_STORES="fileSearchStores",e.PAGED_ITEM_DOCUMENTS="documents"})(oe||(oe={}));class fe{constructor(e,n,t,o){this.pageInternal=[],this.paramsInternal={},this.requestInternal=n,this.init(e,t,o)}init(e,n,t){var o,r;this.nameInternal=e,this.pageInternal=n[this.nameInternal]||[],this.sdkHttpResponseInternal=n===null||n===void 0?void 0:n.sdkHttpResponse,this.idxInternal=0;let l={config:{}};if(!t||Object.keys(t).length===0)l={config:{}};else if(typeof t==="object")l=Object.assign({},t);else l=t;if(l.config)l.config.pageToken=n.nextPageToken;this.paramsInternal=l,this.pageInternalSize=(r=(o=l.config)===null||o===void 0?void 0:o.pageSize)!==null&&r!==void 0?r: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};let e=this.getItem(this.idxInternal);return this.idxInternal+=1,{value:e,done:!1}},return:async()=>({value:void 0,done:!0})}}async nextPage(){if(!this.hasNextPage())throw Error("No more pages to fetch.");let e=await this.requestInternal(this.params);return this.initNextPage(e),this.page}hasNextPage(){var e;if(((e=this.params.config)===null||e===void 0?void 0:e.pageToken)!==void 0)return!0;return!1}}class hi extends ne{constructor(e){super();this.apiClient=e,this.list=async(n={})=>new fe(oe.PAGED_ITEM_BATCH_JOBS,(t)=>this.listInternal(t),await this.listInternal(n),n),this.create=async(n)=>{if(this.apiClient.isVertexAI())n.config=this.formatDestination(n.src,n.config);return this.createInternal(n)},this.createEmbeddings=async(n)=>{if(console.warn("batches.createEmbeddings() is experimental and may change without notice."),this.apiClient.isVertexAI())throw Error("Gemini Enterprise Agent Platform (previously known as Vertex AI) does not support batches.createEmbeddings.");return this.createEmbeddingsInternal(n)}}createInlinedGenerateContentRequest(e){let n=co(this.apiClient,e),t=n._url,o=S("{model}:batchGenerateContent",t),a=n.batch.inputConfig.requests,f=a.requests,d=[];for(let c of f){let m=Object.assign({},c);if(m.systemInstruction){let p=m.systemInstruction;delete m.systemInstruction;let g=m.request;g.systemInstruction=p,m.request=g}d.push(m)}return a.requests=d,delete n.config,delete n._url,delete n._query,{path:o,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];return}getBigqueryUri(e){if(typeof e==="string")return e.startsWith("bq://")?e:void 0;if(!Array.isArray(e))return e.bigqueryUri;return}formatDestination(e,n){let t=n?Object.assign({},n):{},o=Date.now().toString();if(!t.displayName)t.displayName=`genaiBatchJob_${o}`;if(t.dest===void 0){let r=this.getGcsUri(e),l=this.getBigqueryUri(e);if(r)if(r.endsWith(".jsonl"))t.dest=`${r.slice(0,-6)}/dest`;else t.dest=`${r}_dest_${o}`;else if(l)t.dest=`${l}_dest_${o}`;else throw Error("Unsupported source for Gemini Enterprise Agent Platform (previously known as Vertex AI): No GCS or BigQuery URI found.")}return t}async createInternal(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=ns(this.apiClient,e);return a=S("batchPredictionJobs",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json()),l.then((c)=>vn(c))}else{let d=co(this.apiClient,e);return a=S("{model}:batchGenerateContent",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json()),l.then((c)=>Je(c))}}async createEmbeddingsInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=os(this.apiClient,e);return r=S("{model}:asyncBatchEmbedContent",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>Je(f))}}async get(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=ys(this.apiClient,e);return a=S("batchPredictionJobs/{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json()),l.then((c)=>vn(c))}else{let d=gs(this.apiClient,e);return a=S("batches/{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json()),l.then((c)=>Je(c))}}async cancel(e){var n,t,o,r;let l="",a={};if(this.apiClient.isVertexAI()){let f=Xr(this.apiClient,e);l=S("batchPredictionJobs/{name}:cancel",f._url),a=f._query,delete f._url,delete f._query,await this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(f),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal})}else{let f=zr(this.apiClient,e);l=S("batches/{name}:cancel",f._url),a=f._query,delete f._url,delete f._query,await this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(f),httpMethod:"POST",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal})}}async listInternal(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=Rs(e);return a=S("batchPredictionJobs",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=ws(c),p=new Cn;return Object.assign(p,m),p})}else{let d=Ss(e);return a=S("batches",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=Ps(c),p=new Cn;return Object.assign(p,m),p})}}async delete(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=rs(this.apiClient,e);return a=S("batchPredictionJobs/{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>ls(c))}else{let d=is(this.apiClient,e);return a=S("batches/{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>ss(c))}}}function Gs(e){let n={},t=i(e,["apiKey"]);if(t!=null)s(n,["apiKey"],t);if(i(e,["apiKeyConfig"])!==void 0)throw Error("apiKeyConfig parameter is not supported in Gemini API.");if(i(e,["authType"])!==void 0)throw Error("authType parameter is not supported in Gemini API.");if(i(e,["googleServiceAccountConfig"])!==void 0)throw Error("googleServiceAccountConfig parameter is not supported in Gemini API.");if(i(e,["httpBasicAuthConfig"])!==void 0)throw Error("httpBasicAuthConfig parameter is not supported in Gemini API.");if(i(e,["oauthConfig"])!==void 0)throw Error("oauthConfig parameter is not supported in Gemini API.");if(i(e,["oidcConfig"])!==void 0)throw Error("oidcConfig parameter is not supported in Gemini API.");return n}function ks(e){let n={},t=i(e,["data"]);if(t!=null)s(n,["data"],t);if(i(e,["displayName"])!==void 0)throw Error("displayName parameter is not supported in Gemini API.");let o=i(e,["mimeType"]);if(o!=null)s(n,["mimeType"],o);return n}function po(e){let n={},t=i(e,["parts"]);if(t!=null){let r=t;if(Array.isArray(r))r=r.map((l)=>rl(l));s(n,["parts"],r)}let o=i(e,["role"]);if(o!=null)s(n,["role"],o);return n}function ho(e){let n={},t=i(e,["parts"]);if(t!=null){let r=t;if(Array.isArray(r))r=r.map((l)=>sl(l));s(n,["parts"],r)}let o=i(e,["role"]);if(o!=null)s(n,["role"],o);return n}function Fs(e,n){let t={},o=i(e,["ttl"]);if(n!==void 0&&o!=null)s(n,["ttl"],o);let r=i(e,["expireTime"]);if(n!==void 0&&r!=null)s(n,["expireTime"],r);let l=i(e,["displayName"]);if(n!==void 0&&l!=null)s(n,["displayName"],l);let a=i(e,["contents"]);if(n!==void 0&&a!=null){let m=O(a);if(Array.isArray(m))m=m.map((p)=>po(p));s(n,["contents"],m)}let f=i(e,["systemInstruction"]);if(n!==void 0&&f!=null)s(n,["systemInstruction"],po(B(f)));let d=i(e,["tools"]);if(n!==void 0&&d!=null){let m=d;if(Array.isArray(m))m=m.map((p)=>ul(p));s(n,["tools"],m)}let c=i(e,["toolConfig"]);if(n!==void 0&&c!=null)s(n,["toolConfig"],ll(c));if(i(e,["kmsKeyName"])!==void 0)throw Error("kmsKeyName parameter is not supported in Gemini API.");return t}function Vs(e,n){let t={},o=i(e,["ttl"]);if(n!==void 0&&o!=null)s(n,["ttl"],o);let r=i(e,["expireTime"]);if(n!==void 0&&r!=null)s(n,["expireTime"],r);let l=i(e,["displayName"]);if(n!==void 0&&l!=null)s(n,["displayName"],l);let a=i(e,["contents"]);if(n!==void 0&&a!=null){let p=O(a);if(Array.isArray(p))p=p.map((g)=>ho(g));s(n,["contents"],p)}let f=i(e,["systemInstruction"]);if(n!==void 0&&f!=null)s(n,["systemInstruction"],ho(B(f)));let d=i(e,["tools"]);if(n!==void 0&&d!=null){let p=d;if(Array.isArray(p))p=p.map((g)=>dl(g));s(n,["tools"],p)}let c=i(e,["toolConfig"]);if(n!==void 0&&c!=null)s(n,["toolConfig"],al(c));let m=i(e,["kmsKeyName"]);if(n!==void 0&&m!=null)s(n,["encryption_spec","kmsKeyName"],m);return t}function qs(e,n){let t={},o=i(n,["model"]);if(o!=null)s(t,["model"],ei(e,o));let r=i(n,["config"]);if(r!=null)Fs(r,t);return t}function Hs(e,n){let t={},o=i(n,["model"]);if(o!=null)s(t,["model"],ei(e,o));let r=i(n,["config"]);if(r!=null)Vs(r,t);return t}function Bs(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ie(e,o));return t}function Js(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ie(e,o));return t}function bs(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);return n}function $s(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);return n}function Os(e){let n={};if(i(e,["displayName"])!==void 0)throw Error("displayName parameter is not supported in Gemini API.");let t=i(e,["fileUri"]);if(t!=null)s(n,["fileUri"],t);let o=i(e,["mimeType"]);if(o!=null)s(n,["mimeType"],o);return n}function Ks(e){let n={},t=i(e,["id"]);if(t!=null)s(n,["id"],t);let o=i(e,["args"]);if(o!=null)s(n,["args"],o);let r=i(e,["name"]);if(r!=null)s(n,["name"],r);if(i(e,["partialArgs"])!==void 0)throw Error("partialArgs parameter is not supported in Gemini API.");if(i(e,["willContinue"])!==void 0)throw Error("willContinue parameter is not supported in Gemini API.");return n}function Ys(e){let n={},t=i(e,["allowedFunctionNames"]);if(t!=null)s(n,["allowedFunctionNames"],t);let o=i(e,["mode"]);if(o!=null)s(n,["mode"],o);if(i(e,["streamFunctionCallArguments"])!==void 0)throw Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return n}function Ws(e){let n={},t=i(e,["description"]);if(t!=null)s(n,["description"],t);let o=i(e,["name"]);if(o!=null)s(n,["name"],o);let r=i(e,["parameters"]);if(r!=null)s(n,["parameters"],r);let l=i(e,["parametersJsonSchema"]);if(l!=null)s(n,["parametersJsonSchema"],l);let a=i(e,["response"]);if(a!=null)s(n,["response"],a);let f=i(e,["responseJsonSchema"]);if(f!=null)s(n,["responseJsonSchema"],f);if(i(e,["behavior"])!==void 0)throw Error("behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return n}function zs(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ie(e,o));return t}function Xs(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ie(e,o));return t}function Qs(e){let n={},t=i(e,["authConfig"]);if(t!=null)s(n,["authConfig"],Gs(t));let o=i(e,["enableWidget"]);if(o!=null)s(n,["enableWidget"],o);return n}function Zs(e){let n={},t=i(e,["searchTypes"]);if(t!=null)s(n,["searchTypes"],t);if(i(e,["blockingConfidence"])!==void 0)throw Error("blockingConfidence parameter is not supported in Gemini API.");if(i(e,["excludeDomains"])!==void 0)throw Error("excludeDomains parameter is not supported in Gemini API.");let o=i(e,["timeRangeFilter"]);if(o!=null)s(n,["timeRangeFilter"],o);return n}function js(e,n){let t={},o=i(e,["pageSize"]);if(n!==void 0&&o!=null)s(n,["_query","pageSize"],o);let r=i(e,["pageToken"]);if(n!==void 0&&r!=null)s(n,["_query","pageToken"],r);return t}function el(e,n){let t={},o=i(e,["pageSize"]);if(n!==void 0&&o!=null)s(n,["_query","pageSize"],o);let r=i(e,["pageToken"]);if(n!==void 0&&r!=null)s(n,["_query","pageToken"],r);return t}function nl(e){let n={},t=i(e,["config"]);if(t!=null)js(t,n);return n}function tl(e){let n={},t=i(e,["config"]);if(t!=null)el(t,n);return n}function ol(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["nextPageToken"]);if(o!=null)s(n,["nextPageToken"],o);let r=i(e,["cachedContents"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>a);s(n,["cachedContents"],l)}return n}function il(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["nextPageToken"]);if(o!=null)s(n,["nextPageToken"],o);let r=i(e,["cachedContents"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>a);s(n,["cachedContents"],l)}return n}function rl(e){let n={},t=i(e,["mediaResolution"]);if(t!=null)s(n,["mediaResolution"],t);let o=i(e,["codeExecutionResult"]);if(o!=null)s(n,["codeExecutionResult"],o);let r=i(e,["executableCode"]);if(r!=null)s(n,["executableCode"],r);let l=i(e,["fileData"]);if(l!=null)s(n,["fileData"],Os(l));let a=i(e,["functionCall"]);if(a!=null)s(n,["functionCall"],Ks(a));let f=i(e,["functionResponse"]);if(f!=null)s(n,["functionResponse"],f);let d=i(e,["inlineData"]);if(d!=null)s(n,["inlineData"],ks(d));let c=i(e,["text"]);if(c!=null)s(n,["text"],c);let m=i(e,["thought"]);if(m!=null)s(n,["thought"],m);let p=i(e,["thoughtSignature"]);if(p!=null)s(n,["thoughtSignature"],p);let g=i(e,["videoMetadata"]);if(g!=null)s(n,["videoMetadata"],g);let y=i(e,["toolCall"]);if(y!=null)s(n,["toolCall"],y);let E=i(e,["toolResponse"]);if(E!=null)s(n,["toolResponse"],E);let T=i(e,["partMetadata"]);if(T!=null)s(n,["partMetadata"],T);return n}function sl(e){let n={},t=i(e,["mediaResolution"]);if(t!=null)s(n,["mediaResolution"],t);let o=i(e,["codeExecutionResult"]);if(o!=null)s(n,["codeExecutionResult"],o);let r=i(e,["executableCode"]);if(r!=null)s(n,["executableCode"],r);let l=i(e,["fileData"]);if(l!=null)s(n,["fileData"],l);let a=i(e,["functionCall"]);if(a!=null)s(n,["functionCall"],a);let f=i(e,["functionResponse"]);if(f!=null)s(n,["functionResponse"],f);let d=i(e,["inlineData"]);if(d!=null)s(n,["inlineData"],d);let c=i(e,["text"]);if(c!=null)s(n,["text"],c);let m=i(e,["thought"]);if(m!=null)s(n,["thought"],m);let p=i(e,["thoughtSignature"]);if(p!=null)s(n,["thoughtSignature"],p);let g=i(e,["videoMetadata"]);if(g!=null)s(n,["videoMetadata"],g);if(i(e,["toolCall"])!==void 0)throw Error("toolCall parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");if(i(e,["toolResponse"])!==void 0)throw Error("toolResponse parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");if(i(e,["partMetadata"])!==void 0)throw Error("partMetadata parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return n}function ll(e){let n={},t=i(e,["retrievalConfig"]);if(t!=null)s(n,["retrievalConfig"],t);let o=i(e,["functionCallingConfig"]);if(o!=null)s(n,["functionCallingConfig"],Ys(o));let r=i(e,["includeServerSideToolInvocations"]);if(r!=null)s(n,["includeServerSideToolInvocations"],r);return n}function al(e){let n={},t=i(e,["retrievalConfig"]);if(t!=null)s(n,["retrievalConfig"],t);let o=i(e,["functionCallingConfig"]);if(o!=null)s(n,["functionCallingConfig"],o);if(i(e,["includeServerSideToolInvocations"])!==void 0)throw Error("includeServerSideToolInvocations parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return n}function ul(e){let n={};if(i(e,["retrieval"])!==void 0)throw Error("retrieval parameter is not supported in Gemini API.");let t=i(e,["computerUse"]);if(t!=null)s(n,["computerUse"],t);let o=i(e,["fileSearch"]);if(o!=null)s(n,["fileSearch"],o);let r=i(e,["googleSearch"]);if(r!=null)s(n,["googleSearch"],Zs(r));let l=i(e,["googleMaps"]);if(l!=null)s(n,["googleMaps"],Qs(l));let a=i(e,["codeExecution"]);if(a!=null)s(n,["codeExecution"],a);if(i(e,["enterpriseWebSearch"])!==void 0)throw Error("enterpriseWebSearch parameter is not supported in Gemini API.");let f=i(e,["functionDeclarations"]);if(f!=null){let p=f;if(Array.isArray(p))p=p.map((g)=>g);s(n,["functionDeclarations"],p)}let d=i(e,["googleSearchRetrieval"]);if(d!=null)s(n,["googleSearchRetrieval"],d);if(i(e,["parallelAiSearch"])!==void 0)throw Error("parallelAiSearch parameter is not supported in Gemini API.");let c=i(e,["urlContext"]);if(c!=null)s(n,["urlContext"],c);let m=i(e,["mcpServers"]);if(m!=null){let p=m;if(Array.isArray(p))p=p.map((g)=>g);s(n,["mcpServers"],p)}return n}function dl(e){let n={},t=i(e,["retrieval"]);if(t!=null)s(n,["retrieval"],t);let o=i(e,["computerUse"]);if(o!=null)s(n,["computerUse"],o);if(i(e,["fileSearch"])!==void 0)throw Error("fileSearch parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");let r=i(e,["googleSearch"]);if(r!=null)s(n,["googleSearch"],r);let l=i(e,["googleMaps"]);if(l!=null)s(n,["googleMaps"],l);let a=i(e,["codeExecution"]);if(a!=null)s(n,["codeExecution"],a);let f=i(e,["enterpriseWebSearch"]);if(f!=null)s(n,["enterpriseWebSearch"],f);let d=i(e,["functionDeclarations"]);if(d!=null){let g=d;if(Array.isArray(g))g=g.map((y)=>Ws(y));s(n,["functionDeclarations"],g)}let c=i(e,["googleSearchRetrieval"]);if(c!=null)s(n,["googleSearchRetrieval"],c);let m=i(e,["parallelAiSearch"]);if(m!=null)s(n,["parallelAiSearch"],m);let p=i(e,["urlContext"]);if(p!=null)s(n,["urlContext"],p);if(i(e,["mcpServers"])!==void 0)throw Error("mcpServers parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return n}function fl(e,n){let t={},o=i(e,["ttl"]);if(n!==void 0&&o!=null)s(n,["ttl"],o);let r=i(e,["expireTime"]);if(n!==void 0&&r!=null)s(n,["expireTime"],r);return t}function cl(e,n){let t={},o=i(e,["ttl"]);if(n!==void 0&&o!=null)s(n,["ttl"],o);let r=i(e,["expireTime"]);if(n!==void 0&&r!=null)s(n,["expireTime"],r);return t}function pl(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ie(e,o));let r=i(n,["config"]);if(r!=null)fl(r,t);return t}function hl(e,n){let t={},o=i(n,["name"]);if(o!=null)s(t,["_url","name"],ie(e,o));let r=i(n,["config"]);if(r!=null)cl(r,t);return t}class mi extends ne{constructor(e){super();this.apiClient=e,this.list=async(n={})=>new fe(oe.PAGED_ITEM_CACHED_CONTENTS,(t)=>this.listInternal(t),await this.listInternal(n),n)}async create(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=Hs(this.apiClient,e);return a=S("cachedContents",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json()),l.then((c)=>c)}else{let d=qs(this.apiClient,e);return a=S("cachedContents",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json()),l.then((c)=>c)}}async get(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=Xs(this.apiClient,e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json()),l.then((c)=>c)}else{let d=zs(this.apiClient,e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json()),l.then((c)=>c)}}async delete(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=Js(this.apiClient,e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=$s(c),p=new _n;return Object.assign(p,m),p})}else{let d=Bs(this.apiClient,e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=bs(c),p=new _n;return Object.assign(p,m),p})}}async update(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=hl(this.apiClient,e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"PATCH",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json()),l.then((c)=>c)}else{let d=pl(this.apiClient,e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"PATCH",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json()),l.then((c)=>c)}}async listInternal(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=tl(e);return a=S("cachedContents",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=il(c),p=new In;return Object.assign(p,m),p})}else{let d=nl(e);return a=S("cachedContents",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=ol(c),p=new In;return Object.assign(p,m),p})}}}function se(e,n){var t={};for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0)t[o]=e[o];if(e!=null&&typeof Object.getOwnPropertySymbols==="function"){for(var r=0,o=Object.getOwnPropertySymbols(e);r<o.length;r++)if(n.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r]))t[o[r]]=e[o[r]]}return t}function mo(e){var n=typeof Symbol==="function"&&Symbol.iterator,t=n&&e[n],o=0;if(t)return t.call(e);if(e&&typeof e.length==="number")return{next:function(){if(e&&o>=e.length)e=void 0;return{value:e&&e[o++],done:!e}}};throw TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}function D(e){return this instanceof D?(this.v=e,this):new D(e)}function Z(e,n,t){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var o=t.apply(e,n||[]),r,l=[];return r=Object.create((typeof AsyncIterator==="function"?AsyncIterator:Object).prototype),f("next"),f("throw"),f("return",a),r[Symbol.asyncIterator]=function(){return this},r;function a(y){return function(E){return Promise.resolve(E).then(y,p)}}function f(y,E){if(o[y]){if(r[y]=function(T){return new Promise(function(_,C){l.push([y,T,_,C])>1||d(y,T)})},E)r[y]=E(r[y])}}function d(y,E){try{c(o[y](E))}catch(T){g(l[0][3],T)}}function c(y){y.value instanceof D?Promise.resolve(y.value.v).then(m,p):g(l[0][2],y)}function m(y){d("next",y)}function p(y){d("throw",y)}function g(y,E){if(y(E),l.shift(),l.length)d(l[0][0],l[0][1])}}function j(e){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var n=e[Symbol.asyncIterator],t;return n?n.call(e):(e=typeof mo==="function"?mo(e):e[Symbol.iterator](),t={},o("next"),o("throw"),o("return"),t[Symbol.asyncIterator]=function(){return this},t);function o(l){t[l]=e[l]&&function(a){return new Promise(function(f,d){a=e[l](a),r(f,d,a.done,a.value)})}}function r(l,a,f,d){Promise.resolve(d).then(function(c){l({value:c,done:f})},a)}}function ml(e){var n;if(e.candidates==null||e.candidates.length===0)return!1;let t=(n=e.candidates[0])===null||n===void 0?void 0:n.content;if(t===void 0)return!1;return gi(t)}function gi(e){if(e.parts===void 0||e.parts.length===0)return!1;for(let n of e.parts)if(n===void 0||Object.keys(n).length===0)return!1;return!0}function gl(e){if(e.length===0)return;for(let n of e)if(n.role!=="user"&&n.role!=="model")throw Error(`Role must be user or model, but got ${n.role}.`)}function go(e){if(e===void 0||e.length===0)return[];let n=[],t=e.length,o=0;while(o<t)if(e[o].role==="user")n.push(e[o]),o++;else{let r=[],l=!0;while(o<t&&e[o].role==="model"){if(r.push(e[o]),l&&!gi(e[o]))l=!1;o++}if(l)n.push(...r);else n.pop()}return n}class yi{constructor(e,n){this.modelsModule=e,this.apiClient=n}create(e){return new Ei(this.apiClient,this.modelsModule,e.model,e.config,structuredClone(e.history))}}class Ei{constructor(e,n,t,o={},r=[]){this.apiClient=e,this.modelsModule=n,this.model=t,this.config=o,this.history=r,this.sendPromise=Promise.resolve(),gl(r)}async sendMessage(e){var n;await this.sendPromise;let t=B(e.message),o=this.modelsModule.generateContent({model:this.model,contents:this.getHistory(!0).concat(t),config:(n=e.config)!==null&&n!==void 0?n:this.config});return this.sendPromise=(async()=>{var r,l,a;let f=await o,d=(l=(r=f.candidates)===null||r===void 0?void 0:r[0])===null||l===void 0?void 0:l.content,c=f.automaticFunctionCallingHistory,m=this.getHistory(!0).length,p=[];if(c!=null)p=(a=c.slice(m))!==null&&a!==void 0?a:[];let g=d?[d]:[];this.recordHistory(t,g,p);return})(),await this.sendPromise.catch(()=>{this.sendPromise=Promise.resolve()}),o}async sendMessageStream(e){var n;await this.sendPromise;let t=B(e.message),o=this.modelsModule.generateContentStream({model:this.model,contents:this.getHistory(!0).concat(t),config:(n=e.config)!==null&&n!==void 0?n:this.config});this.sendPromise=o.then(()=>{return}).catch(()=>{return});let r=await o;return this.processStreamResponse(r,t)}getHistory(e=!1){let n=e?go(this.history):this.history;return structuredClone(n)}processStreamResponse(e,n){return Z(this,arguments,function*(){var o,r,l,a,f,d;let c=[];try{for(var m=!0,p=j(e),g;g=yield D(p.next()),o=g.done,!o;m=!0){a=g.value,m=!1;let y=a;if(ml(y)){let E=(d=(f=y.candidates)===null||f===void 0?void 0:f[0])===null||d===void 0?void 0:d.content;if(E!==void 0)c.push(E)}yield yield D(y)}}catch(y){r={error:y}}finally{try{if(!m&&!o&&(l=p.return))yield D(l.call(p))}finally{if(r)throw r.error}}this.recordHistory(n,c)})}recordHistory(e,n,t){let o=[];if(n.length>0&&n.every((r)=>r.role!==void 0))o=n;else o.push({role:"model",parts:[]});if(t&&t.length>0)this.history.push(...go(t));else this.history.push(e);this.history.push(...o)}}class tn extends Error{constructor(e){super(e.message);this.name="ApiError",this.status=e.status,Object.setPrototypeOf(this,tn.prototype)}}function yl(e){let n={},t=i(e,["file"]);if(t!=null)s(n,["file"],t);return n}function El(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);return n}function Tl(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["_url","file"],Hn(t));return n}function _l(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);return n}function Il(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["_url","file"],Hn(t));return n}function Cl(e){let n={},t=i(e,["uris"]);if(t!=null)s(n,["uris"],t);return n}function Al(e,n){let t={},o=i(e,["pageSize"]);if(n!==void 0&&o!=null)s(n,["_query","pageSize"],o);let r=i(e,["pageToken"]);if(n!==void 0&&r!=null)s(n,["_query","pageToken"],r);return t}function vl(e){let n={},t=i(e,["config"]);if(t!=null)Al(t,n);return n}function Sl(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["nextPageToken"]);if(o!=null)s(n,["nextPageToken"],o);let r=i(e,["files"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>a);s(n,["files"],l)}return n}function Rl(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["files"]);if(o!=null){let r=o;if(Array.isArray(r))r=r.map((l)=>l);s(n,["files"],r)}return n}class Ti extends ne{constructor(e){super();this.apiClient=e,this.list=async(n={})=>new fe(oe.PAGED_ITEM_FILES,(t)=>this.listInternal(t),await this.listInternal(n),n)}async upload(e){if(this.apiClient.isVertexAI())throw Error("Gemini Enterprise Agent Platform (previously known as Vertex AI) does not support uploading files. You can share files through a GCS bucket.");return this.apiClient.uploadFile(e.file,e.config).then((n)=>n)}async download(e){await this.apiClient.downloadFile(e)}async registerFiles(e){throw Error("registerFiles is only supported in Node.js environments.")}async _registerFiles(e){return this.registerFilesInternal(e)}async listInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=vl(e);return r=S("files",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json().then((d)=>{let c=d;return c.sdkHttpResponse={headers:f.headers},c})),o.then((f)=>{let d=Sl(f),c=new Wo;return Object.assign(c,d),c})}}async createInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=yl(e);return r=S("upload/v1beta/files",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>{let d=El(f),c=new zo;return Object.assign(c,d),c})}}async get(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=Il(e);return r=S("files/{file}",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>f)}}async delete(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=Tl(e);return r=S("files/{file}",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json().then((d)=>{let c=d;return c.sdkHttpResponse={headers:f.headers},c})),o.then((f)=>{let d=_l(f),c=new Xo;return Object.assign(c,d),c})}}async registerFilesInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=Cl(e);return r=S("files:register",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>{let d=Rl(f),c=new Qo;return Object.assign(c,d),c})}}}function yo(e){let n={};if(i(e,["languageCodes"])!==void 0)throw Error("languageCodes parameter is not supported in Gemini API.");return n}function Pl(e){let n={},t=i(e,["apiKey"]);if(t!=null)s(n,["apiKey"],t);if(i(e,["apiKeyConfig"])!==void 0)throw Error("apiKeyConfig parameter is not supported in Gemini API.");if(i(e,["authType"])!==void 0)throw Error("authType parameter is not supported in Gemini API.");if(i(e,["googleServiceAccountConfig"])!==void 0)throw Error("googleServiceAccountConfig parameter is not supported in Gemini API.");if(i(e,["httpBasicAuthConfig"])!==void 0)throw Error("httpBasicAuthConfig parameter is not supported in Gemini API.");if(i(e,["oauthConfig"])!==void 0)throw Error("oauthConfig parameter is not supported in Gemini API.");if(i(e,["oidcConfig"])!==void 0)throw Error("oidcConfig parameter is not supported in Gemini API.");return n}function be(e){let n={},t=i(e,["data"]);if(t!=null)s(n,["data"],t);if(i(e,["displayName"])!==void 0)throw Error("displayName parameter is not supported in Gemini API.");let o=i(e,["mimeType"]);if(o!=null)s(n,["mimeType"],o);return n}function wl(e){let n={},t=i(e,["parts"]);if(t!=null){let r=t;if(Array.isArray(r))r=r.map((l)=>Ol(l));s(n,["parts"],r)}let o=i(e,["role"]);if(o!=null)s(n,["role"],o);return n}function Nl(e){let n={},t=i(e,["parts"]);if(t!=null){let r=t;if(Array.isArray(r))r=r.map((l)=>Kl(l));s(n,["parts"],r)}let o=i(e,["role"]);if(o!=null)s(n,["role"],o);return n}function Ml(e){let n={};if(i(e,["displayName"])!==void 0)throw Error("displayName parameter is not supported in Gemini API.");let t=i(e,["fileUri"]);if(t!=null)s(n,["fileUri"],t);let o=i(e,["mimeType"]);if(o!=null)s(n,["mimeType"],o);return n}function Dl(e){let n={},t=i(e,["id"]);if(t!=null)s(n,["id"],t);let o=i(e,["args"]);if(o!=null)s(n,["args"],o);let r=i(e,["name"]);if(r!=null)s(n,["name"],r);if(i(e,["partialArgs"])!==void 0)throw Error("partialArgs parameter is not supported in Gemini API.");if(i(e,["willContinue"])!==void 0)throw Error("willContinue parameter is not supported in Gemini API.");return n}function xl(e){let n={},t=i(e,["description"]);if(t!=null)s(n,["description"],t);let o=i(e,["name"]);if(o!=null)s(n,["name"],o);let r=i(e,["parameters"]);if(r!=null)s(n,["parameters"],r);let l=i(e,["parametersJsonSchema"]);if(l!=null)s(n,["parametersJsonSchema"],l);let a=i(e,["response"]);if(a!=null)s(n,["response"],a);let f=i(e,["responseJsonSchema"]);if(f!=null)s(n,["responseJsonSchema"],f);if(i(e,["behavior"])!==void 0)throw Error("behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return n}function Ul(e){let n={},t=i(e,["modelSelectionConfig"]);if(t!=null)s(n,["modelConfig"],t);let o=i(e,["responseJsonSchema"]);if(o!=null)s(n,["responseJsonSchema"],o);let r=i(e,["audioTimestamp"]);if(r!=null)s(n,["audioTimestamp"],r);let l=i(e,["candidateCount"]);if(l!=null)s(n,["candidateCount"],l);let a=i(e,["enableAffectiveDialog"]);if(a!=null)s(n,["enableAffectiveDialog"],a);let f=i(e,["frequencyPenalty"]);if(f!=null)s(n,["frequencyPenalty"],f);let d=i(e,["logprobs"]);if(d!=null)s(n,["logprobs"],d);let c=i(e,["maxOutputTokens"]);if(c!=null)s(n,["maxOutputTokens"],c);let m=i(e,["mediaResolution"]);if(m!=null)s(n,["mediaResolution"],m);let p=i(e,["presencePenalty"]);if(p!=null)s(n,["presencePenalty"],p);let g=i(e,["responseLogprobs"]);if(g!=null)s(n,["responseLogprobs"],g);let y=i(e,["responseMimeType"]);if(y!=null)s(n,["responseMimeType"],y);let E=i(e,["responseModalities"]);if(E!=null)s(n,["responseModalities"],E);let T=i(e,["responseSchema"]);if(T!=null)s(n,["responseSchema"],T);let _=i(e,["routingConfig"]);if(_!=null)s(n,["routingConfig"],_);let C=i(e,["seed"]);if(C!=null)s(n,["seed"],C);let v=i(e,["speechConfig"]);if(v!=null)s(n,["speechConfig"],v);let R=i(e,["stopSequences"]);if(R!=null)s(n,["stopSequences"],R);let P=i(e,["temperature"]);if(P!=null)s(n,["temperature"],P);let x=i(e,["thinkingConfig"]);if(x!=null)s(n,["thinkingConfig"],x);let I=i(e,["topK"]);if(I!=null)s(n,["topK"],I);let U=i(e,["topP"]);if(U!=null)s(n,["topP"],U);if(i(e,["enableEnhancedCivicAnswers"])!==void 0)throw Error("enableEnhancedCivicAnswers parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return n}function Ll(e){let n={},t=i(e,["authConfig"]);if(t!=null)s(n,["authConfig"],Pl(t));let o=i(e,["enableWidget"]);if(o!=null)s(n,["enableWidget"],o);return n}function Gl(e){let n={},t=i(e,["searchTypes"]);if(t!=null)s(n,["searchTypes"],t);if(i(e,["blockingConfidence"])!==void 0)throw Error("blockingConfidence parameter is not supported in Gemini API.");if(i(e,["excludeDomains"])!==void 0)throw Error("excludeDomains parameter is not supported in Gemini API.");let o=i(e,["timeRangeFilter"]);if(o!=null)s(n,["timeRangeFilter"],o);return n}function kl(e,n){let t={},o=i(e,["generationConfig"]);if(n!==void 0&&o!=null)s(n,["setup","generationConfig"],o);let r=i(e,["responseModalities"]);if(n!==void 0&&r!=null)s(n,["setup","generationConfig","responseModalities"],r);let l=i(e,["temperature"]);if(n!==void 0&&l!=null)s(n,["setup","generationConfig","temperature"],l);let a=i(e,["topP"]);if(n!==void 0&&a!=null)s(n,["setup","generationConfig","topP"],a);let f=i(e,["topK"]);if(n!==void 0&&f!=null)s(n,["setup","generationConfig","topK"],f);let d=i(e,["maxOutputTokens"]);if(n!==void 0&&d!=null)s(n,["setup","generationConfig","maxOutputTokens"],d);let c=i(e,["mediaResolution"]);if(n!==void 0&&c!=null)s(n,["setup","generationConfig","mediaResolution"],c);let m=i(e,["seed"]);if(n!==void 0&&m!=null)s(n,["setup","generationConfig","seed"],m);let p=i(e,["speechConfig"]);if(n!==void 0&&p!=null)s(n,["setup","generationConfig","speechConfig"],qn(p));let g=i(e,["thinkingConfig"]);if(n!==void 0&&g!=null)s(n,["setup","generationConfig","thinkingConfig"],g);let y=i(e,["enableAffectiveDialog"]);if(n!==void 0&&y!=null)s(n,["setup","generationConfig","enableAffectiveDialog"],y);let E=i(e,["systemInstruction"]);if(n!==void 0&&E!=null)s(n,["setup","systemInstruction"],wl(B(E)));let T=i(e,["tools"]);if(n!==void 0&&T!=null){let A=Ce(T);if(Array.isArray(A))A=A.map((M)=>zl(Ie(M)));s(n,["setup","tools"],A)}let _=i(e,["sessionResumption"]);if(n!==void 0&&_!=null)s(n,["setup","sessionResumption"],Wl(_));let C=i(e,["inputAudioTranscription"]);if(n!==void 0&&C!=null)s(n,["setup","inputAudioTranscription"],yo(C));let v=i(e,["outputAudioTranscription"]);if(n!==void 0&&v!=null)s(n,["setup","outputAudioTranscription"],yo(v));let R=i(e,["realtimeInputConfig"]);if(n!==void 0&&R!=null)s(n,["setup","realtimeInputConfig"],R);let P=i(e,["contextWindowCompression"]);if(n!==void 0&&P!=null)s(n,["setup","contextWindowCompression"],P);let x=i(e,["proactivity"]);if(n!==void 0&&x!=null)s(n,["setup","proactivity"],x);if(i(e,["explicitVadSignal"])!==void 0)throw Error("explicitVadSignal parameter is not supported in Gemini API.");let I=i(e,["avatarConfig"]);if(n!==void 0&&I!=null)s(n,["setup","avatarConfig"],I);let U=i(e,["safetySettings"]);if(n!==void 0&&U!=null){let A=U;if(Array.isArray(A))A=A.map((M)=>Yl(M));s(n,["setup","safetySettings"],A)}return t}function Fl(e,n){let t={},o=i(e,["generationConfig"]);if(n!==void 0&&o!=null)s(n,["setup","generationConfig"],Ul(o));let r=i(e,["responseModalities"]);if(n!==void 0&&r!=null)s(n,["setup","generationConfig","responseModalities"],r);let l=i(e,["temperature"]);if(n!==void 0&&l!=null)s(n,["setup","generationConfig","temperature"],l);let a=i(e,["topP"]);if(n!==void 0&&a!=null)s(n,["setup","generationConfig","topP"],a);let f=i(e,["topK"]);if(n!==void 0&&f!=null)s(n,["setup","generationConfig","topK"],f);let d=i(e,["maxOutputTokens"]);if(n!==void 0&&d!=null)s(n,["setup","generationConfig","maxOutputTokens"],d);let c=i(e,["mediaResolution"]);if(n!==void 0&&c!=null)s(n,["setup","generationConfig","mediaResolution"],c);let m=i(e,["seed"]);if(n!==void 0&&m!=null)s(n,["setup","generationConfig","seed"],m);let p=i(e,["speechConfig"]);if(n!==void 0&&p!=null)s(n,["setup","generationConfig","speechConfig"],qn(p));let g=i(e,["thinkingConfig"]);if(n!==void 0&&g!=null)s(n,["setup","generationConfig","thinkingConfig"],g);let y=i(e,["enableAffectiveDialog"]);if(n!==void 0&&y!=null)s(n,["setup","generationConfig","enableAffectiveDialog"],y);let E=i(e,["systemInstruction"]);if(n!==void 0&&E!=null)s(n,["setup","systemInstruction"],Nl(B(E)));let T=i(e,["tools"]);if(n!==void 0&&T!=null){let M=Ce(T);if(Array.isArray(M))M=M.map((G)=>Xl(Ie(G)));s(n,["setup","tools"],M)}let _=i(e,["sessionResumption"]);if(n!==void 0&&_!=null)s(n,["setup","sessionResumption"],_);let C=i(e,["inputAudioTranscription"]);if(n!==void 0&&C!=null)s(n,["setup","inputAudioTranscription"],C);let v=i(e,["outputAudioTranscription"]);if(n!==void 0&&v!=null)s(n,["setup","outputAudioTranscription"],v);let R=i(e,["realtimeInputConfig"]);if(n!==void 0&&R!=null)s(n,["setup","realtimeInputConfig"],R);let P=i(e,["contextWindowCompression"]);if(n!==void 0&&P!=null)s(n,["setup","contextWindowCompression"],P);let x=i(e,["proactivity"]);if(n!==void 0&&x!=null)s(n,["setup","proactivity"],x);let I=i(e,["explicitVadSignal"]);if(n!==void 0&&I!=null)s(n,["setup","explicitVadSignal"],I);let U=i(e,["avatarConfig"]);if(n!==void 0&&U!=null)s(n,["setup","avatarConfig"],U);let A=i(e,["safetySettings"]);if(n!==void 0&&A!=null){let M=A;if(Array.isArray(M))M=M.map((G)=>G);s(n,["setup","safetySettings"],M)}return t}function Vl(e,n){let t={},o=i(n,["model"]);if(o!=null)s(t,["setup","model"],L(e,o));let r=i(n,["config"]);if(r!=null)s(t,["config"],kl(r,t));return t}function ql(e,n){let t={},o=i(n,["model"]);if(o!=null)s(t,["setup","model"],L(e,o));let r=i(n,["config"]);if(r!=null)s(t,["config"],Fl(r,t));return t}function Hl(e){let n={},t=i(e,["musicGenerationConfig"]);if(t!=null)s(n,["musicGenerationConfig"],t);return n}function Bl(e){let n={},t=i(e,["weightedPrompts"]);if(t!=null){let o=t;if(Array.isArray(o))o=o.map((r)=>r);s(n,["weightedPrompts"],o)}return n}function Jl(e){let n={},t=i(e,["media"]);if(t!=null){let c=ni(t);if(Array.isArray(c))c=c.map((m)=>be(m));s(n,["mediaChunks"],c)}let o=i(e,["audio"]);if(o!=null)s(n,["audio"],be(oi(o)));let r=i(e,["audioStreamEnd"]);if(r!=null)s(n,["audioStreamEnd"],r);let l=i(e,["video"]);if(l!=null)s(n,["video"],be(ti(l)));let a=i(e,["text"]);if(a!=null)s(n,["text"],a);let f=i(e,["activityStart"]);if(f!=null)s(n,["activityStart"],f);let d=i(e,["activityEnd"]);if(d!=null)s(n,["activityEnd"],d);return n}function bl(e){let n={},t=i(e,["media"]);if(t!=null){let c=ni(t);if(Array.isArray(c))c=c.map((m)=>m);s(n,["mediaChunks"],c)}let o=i(e,["audio"]);if(o!=null)s(n,["audio"],oi(o));let r=i(e,["audioStreamEnd"]);if(r!=null)s(n,["audioStreamEnd"],r);let l=i(e,["video"]);if(l!=null)s(n,["video"],ti(l));let a=i(e,["text"]);if(a!=null)s(n,["text"],a);let f=i(e,["activityStart"]);if(f!=null)s(n,["activityStart"],f);let d=i(e,["activityEnd"]);if(d!=null)s(n,["activityEnd"],d);return n}function $l(e){let n={},t=i(e,["setupComplete"]);if(t!=null)s(n,["setupComplete"],t);let o=i(e,["serverContent"]);if(o!=null)s(n,["serverContent"],o);let r=i(e,["toolCall"]);if(r!=null)s(n,["toolCall"],r);let l=i(e,["toolCallCancellation"]);if(l!=null)s(n,["toolCallCancellation"],l);let a=i(e,["usageMetadata"]);if(a!=null)s(n,["usageMetadata"],Ql(a));let f=i(e,["goAway"]);if(f!=null)s(n,["goAway"],f);let d=i(e,["sessionResumptionUpdate"]);if(d!=null)s(n,["sessionResumptionUpdate"],d);let c=i(e,["voiceActivityDetectionSignal"]);if(c!=null)s(n,["voiceActivityDetectionSignal"],c);let m=i(e,["voiceActivity"]);if(m!=null)s(n,["voiceActivity"],Zl(m));return n}function Ol(e){let n={},t=i(e,["mediaResolution"]);if(t!=null)s(n,["mediaResolution"],t);let o=i(e,["codeExecutionResult"]);if(o!=null)s(n,["codeExecutionResult"],o);let r=i(e,["executableCode"]);if(r!=null)s(n,["executableCode"],r);let l=i(e,["fileData"]);if(l!=null)s(n,["fileData"],Ml(l));let a=i(e,["functionCall"]);if(a!=null)s(n,["functionCall"],Dl(a));let f=i(e,["functionResponse"]);if(f!=null)s(n,["functionResponse"],f);let d=i(e,["inlineData"]);if(d!=null)s(n,["inlineData"],be(d));let c=i(e,["text"]);if(c!=null)s(n,["text"],c);let m=i(e,["thought"]);if(m!=null)s(n,["thought"],m);let p=i(e,["thoughtSignature"]);if(p!=null)s(n,["thoughtSignature"],p);let g=i(e,["videoMetadata"]);if(g!=null)s(n,["videoMetadata"],g);let y=i(e,["toolCall"]);if(y!=null)s(n,["toolCall"],y);let E=i(e,["toolResponse"]);if(E!=null)s(n,["toolResponse"],E);let T=i(e,["partMetadata"]);if(T!=null)s(n,["partMetadata"],T);return n}function Kl(e){let n={},t=i(e,["mediaResolution"]);if(t!=null)s(n,["mediaResolution"],t);let o=i(e,["codeExecutionResult"]);if(o!=null)s(n,["codeExecutionResult"],o);let r=i(e,["executableCode"]);if(r!=null)s(n,["executableCode"],r);let l=i(e,["fileData"]);if(l!=null)s(n,["fileData"],l);let a=i(e,["functionCall"]);if(a!=null)s(n,["functionCall"],a);let f=i(e,["functionResponse"]);if(f!=null)s(n,["functionResponse"],f);let d=i(e,["inlineData"]);if(d!=null)s(n,["inlineData"],d);let c=i(e,["text"]);if(c!=null)s(n,["text"],c);let m=i(e,["thought"]);if(m!=null)s(n,["thought"],m);let p=i(e,["thoughtSignature"]);if(p!=null)s(n,["thoughtSignature"],p);let g=i(e,["videoMetadata"]);if(g!=null)s(n,["videoMetadata"],g);if(i(e,["toolCall"])!==void 0)throw Error("toolCall parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");if(i(e,["toolResponse"])!==void 0)throw Error("toolResponse parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");if(i(e,["partMetadata"])!==void 0)throw Error("partMetadata parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return n}function Yl(e){let n={},t=i(e,["category"]);if(t!=null)s(n,["category"],t);if(i(e,["method"])!==void 0)throw Error("method parameter is not supported in Gemini API.");let o=i(e,["threshold"]);if(o!=null)s(n,["threshold"],o);return n}function Wl(e){let n={},t=i(e,["handle"]);if(t!=null)s(n,["handle"],t);if(i(e,["transparent"])!==void 0)throw Error("transparent parameter is not supported in Gemini API.");return n}function zl(e){let n={};if(i(e,["retrieval"])!==void 0)throw Error("retrieval parameter is not supported in Gemini API.");let t=i(e,["computerUse"]);if(t!=null)s(n,["computerUse"],t);let o=i(e,["fileSearch"]);if(o!=null)s(n,["fileSearch"],o);let r=i(e,["googleSearch"]);if(r!=null)s(n,["googleSearch"],Gl(r));let l=i(e,["googleMaps"]);if(l!=null)s(n,["googleMaps"],Ll(l));let a=i(e,["codeExecution"]);if(a!=null)s(n,["codeExecution"],a);if(i(e,["enterpriseWebSearch"])!==void 0)throw Error("enterpriseWebSearch parameter is not supported in Gemini API.");let f=i(e,["functionDeclarations"]);if(f!=null){let p=f;if(Array.isArray(p))p=p.map((g)=>g);s(n,["functionDeclarations"],p)}let d=i(e,["googleSearchRetrieval"]);if(d!=null)s(n,["googleSearchRetrieval"],d);if(i(e,["parallelAiSearch"])!==void 0)throw Error("parallelAiSearch parameter is not supported in Gemini API.");let c=i(e,["urlContext"]);if(c!=null)s(n,["urlContext"],c);let m=i(e,["mcpServers"]);if(m!=null){let p=m;if(Array.isArray(p))p=p.map((g)=>g);s(n,["mcpServers"],p)}return n}function Xl(e){let n={},t=i(e,["retrieval"]);if(t!=null)s(n,["retrieval"],t);let o=i(e,["computerUse"]);if(o!=null)s(n,["computerUse"],o);if(i(e,["fileSearch"])!==void 0)throw Error("fileSearch parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");let r=i(e,["googleSearch"]);if(r!=null)s(n,["googleSearch"],r);let l=i(e,["googleMaps"]);if(l!=null)s(n,["googleMaps"],l);let a=i(e,["codeExecution"]);if(a!=null)s(n,["codeExecution"],a);let f=i(e,["enterpriseWebSearch"]);if(f!=null)s(n,["enterpriseWebSearch"],f);let d=i(e,["functionDeclarations"]);if(d!=null){let g=d;if(Array.isArray(g))g=g.map((y)=>xl(y));s(n,["functionDeclarations"],g)}let c=i(e,["googleSearchRetrieval"]);if(c!=null)s(n,["googleSearchRetrieval"],c);let m=i(e,["parallelAiSearch"]);if(m!=null)s(n,["parallelAiSearch"],m);let p=i(e,["urlContext"]);if(p!=null)s(n,["urlContext"],p);if(i(e,["mcpServers"])!==void 0)throw Error("mcpServers parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return n}function Ql(e){let n={},t=i(e,["promptTokenCount"]);if(t!=null)s(n,["promptTokenCount"],t);let o=i(e,["cachedContentTokenCount"]);if(o!=null)s(n,["cachedContentTokenCount"],o);let r=i(e,["candidatesTokenCount"]);if(r!=null)s(n,["responseTokenCount"],r);let l=i(e,["toolUsePromptTokenCount"]);if(l!=null)s(n,["toolUsePromptTokenCount"],l);let a=i(e,["thoughtsTokenCount"]);if(a!=null)s(n,["thoughtsTokenCount"],a);let f=i(e,["totalTokenCount"]);if(f!=null)s(n,["totalTokenCount"],f);let d=i(e,["promptTokensDetails"]);if(d!=null){let y=d;if(Array.isArray(y))y=y.map((E)=>E);s(n,["promptTokensDetails"],y)}let c=i(e,["cacheTokensDetails"]);if(c!=null){let y=c;if(Array.isArray(y))y=y.map((E)=>E);s(n,["cacheTokensDetails"],y)}let m=i(e,["candidatesTokensDetails"]);if(m!=null){let y=m;if(Array.isArray(y))y=y.map((E)=>E);s(n,["responseTokensDetails"],y)}let p=i(e,["toolUsePromptTokensDetails"]);if(p!=null){let y=p;if(Array.isArray(y))y=y.map((E)=>E);s(n,["toolUsePromptTokensDetails"],y)}let g=i(e,["trafficType"]);if(g!=null)s(n,["trafficType"],g);return n}function Zl(e){let n={},t=i(e,["type"]);if(t!=null)s(n,["voiceActivityType"],t);return n}function jl(e,n){let t={},o=i(e,["apiKey"]);if(o!=null)s(t,["apiKey"],o);if(i(e,["apiKeyConfig"])!==void 0)throw Error("apiKeyConfig parameter is not supported in Gemini API.");if(i(e,["authType"])!==void 0)throw Error("authType parameter is not supported in Gemini API.");if(i(e,["googleServiceAccountConfig"])!==void 0)throw Error("googleServiceAccountConfig parameter is not supported in Gemini API.");if(i(e,["httpBasicAuthConfig"])!==void 0)throw Error("httpBasicAuthConfig parameter is not supported in Gemini API.");if(i(e,["oauthConfig"])!==void 0)throw Error("oauthConfig parameter is not supported in Gemini API.");if(i(e,["oidcConfig"])!==void 0)throw Error("oidcConfig parameter is not supported in Gemini API.");return t}function ea(e,n){let t={},o=i(e,["data"]);if(o!=null)s(t,["data"],o);if(i(e,["displayName"])!==void 0)throw Error("displayName parameter is not supported in Gemini API.");let r=i(e,["mimeType"]);if(r!=null)s(t,["mimeType"],r);return t}function na(e,n){let t={},o=i(e,["content"]);if(o!=null)s(t,["content"],o);let r=i(e,["citationMetadata"]);if(r!=null)s(t,["citationMetadata"],ta(r));let l=i(e,["tokenCount"]);if(l!=null)s(t,["tokenCount"],l);let a=i(e,["finishReason"]);if(a!=null)s(t,["finishReason"],a);let f=i(e,["groundingMetadata"]);if(f!=null)s(t,["groundingMetadata"],f);let d=i(e,["avgLogprobs"]);if(d!=null)s(t,["avgLogprobs"],d);let c=i(e,["index"]);if(c!=null)s(t,["index"],c);let m=i(e,["logprobsResult"]);if(m!=null)s(t,["logprobsResult"],m);let p=i(e,["safetyRatings"]);if(p!=null){let y=p;if(Array.isArray(y))y=y.map((E)=>E);s(t,["safetyRatings"],y)}let g=i(e,["urlContextMetadata"]);if(g!=null)s(t,["urlContextMetadata"],g);return t}function ta(e,n){let t={},o=i(e,["citationSources"]);if(o!=null){let r=o;if(Array.isArray(r))r=r.map((l)=>l);s(t,["citations"],r)}return t}function oa(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["contents"]);if(l!=null){let a=O(l);if(Array.isArray(a))a=a.map((f)=>Se(f));s(o,["contents"],a)}return o}function ia(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["tokensInfo"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>a);s(t,["tokensInfo"],l)}return t}function ra(e,n){let t={},o=i(e,["values"]);if(o!=null)s(t,["values"],o);let r=i(e,["statistics"]);if(r!=null)s(t,["statistics"],sa(r));return t}function sa(e,n){let t={},o=i(e,["truncated"]);if(o!=null)s(t,["truncated"],o);let r=i(e,["token_count"]);if(r!=null)s(t,["tokenCount"],r);return t}function Ue(e,n){let t={},o=i(e,["parts"]);if(o!=null){let l=o;if(Array.isArray(l))l=l.map((a)=>mu(a));s(t,["parts"],l)}let r=i(e,["role"]);if(r!=null)s(t,["role"],r);return t}function Se(e,n){let t={},o=i(e,["parts"]);if(o!=null){let l=o;if(Array.isArray(l))l=l.map((a)=>gu(a));s(t,["parts"],l)}let r=i(e,["role"]);if(r!=null)s(t,["role"],r);return t}function la(e,n){let t={},o=i(e,["controlType"]);if(o!=null)s(t,["controlType"],o);let r=i(e,["enableControlImageComputation"]);if(r!=null)s(t,["computeControl"],r);return t}function aa(e,n){let t={};if(i(e,["systemInstruction"])!==void 0)throw Error("systemInstruction parameter is not supported in Gemini API.");if(i(e,["tools"])!==void 0)throw Error("tools parameter is not supported in Gemini API.");if(i(e,["generationConfig"])!==void 0)throw Error("generationConfig parameter is not supported in Gemini API.");return t}function ua(e,n,t){let o={},r=i(e,["systemInstruction"]);if(n!==void 0&&r!=null)s(n,["systemInstruction"],Se(B(r)));let l=i(e,["tools"]);if(n!==void 0&&l!=null){let f=l;if(Array.isArray(f))f=f.map((d)=>Ai(d));s(n,["tools"],f)}let a=i(e,["generationConfig"]);if(n!==void 0&&a!=null)s(n,["generationConfig"],eu(a));return o}function da(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["contents"]);if(l!=null){let f=O(l);if(Array.isArray(f))f=f.map((d)=>Ue(d));s(o,["contents"],f)}let a=i(n,["config"]);if(a!=null)aa(a);return o}function fa(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["contents"]);if(l!=null){let f=O(l);if(Array.isArray(f))f=f.map((d)=>Se(d));s(o,["contents"],f)}let a=i(n,["config"]);if(a!=null)ua(a,o);return o}function ca(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["totalTokens"]);if(r!=null)s(t,["totalTokens"],r);let l=i(e,["cachedContentTokenCount"]);if(l!=null)s(t,["cachedContentTokenCount"],l);return t}function pa(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["totalTokens"]);if(r!=null)s(t,["totalTokens"],r);return t}function ha(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","name"],L(e,r));return o}function ma(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","name"],L(e,r));return o}function ga(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);return t}function ya(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);return t}function Ea(e,n,t){let o={},r=i(e,["outputGcsUri"]);if(n!==void 0&&r!=null)s(n,["parameters","storageUri"],r);let l=i(e,["negativePrompt"]);if(n!==void 0&&l!=null)s(n,["parameters","negativePrompt"],l);let a=i(e,["numberOfImages"]);if(n!==void 0&&a!=null)s(n,["parameters","sampleCount"],a);let f=i(e,["aspectRatio"]);if(n!==void 0&&f!=null)s(n,["parameters","aspectRatio"],f);let d=i(e,["guidanceScale"]);if(n!==void 0&&d!=null)s(n,["parameters","guidanceScale"],d);let c=i(e,["seed"]);if(n!==void 0&&c!=null)s(n,["parameters","seed"],c);let m=i(e,["safetyFilterLevel"]);if(n!==void 0&&m!=null)s(n,["parameters","safetySetting"],m);let p=i(e,["personGeneration"]);if(n!==void 0&&p!=null)s(n,["parameters","personGeneration"],p);let g=i(e,["includeSafetyAttributes"]);if(n!==void 0&&g!=null)s(n,["parameters","includeSafetyAttributes"],g);let y=i(e,["includeRaiReason"]);if(n!==void 0&&y!=null)s(n,["parameters","includeRaiReason"],y);let E=i(e,["language"]);if(n!==void 0&&E!=null)s(n,["parameters","language"],E);let T=i(e,["outputMimeType"]);if(n!==void 0&&T!=null)s(n,["parameters","outputOptions","mimeType"],T);let _=i(e,["outputCompressionQuality"]);if(n!==void 0&&_!=null)s(n,["parameters","outputOptions","compressionQuality"],_);let C=i(e,["addWatermark"]);if(n!==void 0&&C!=null)s(n,["parameters","addWatermark"],C);let v=i(e,["labels"]);if(n!==void 0&&v!=null)s(n,["labels"],v);let R=i(e,["editMode"]);if(n!==void 0&&R!=null)s(n,["parameters","editMode"],R);let P=i(e,["baseSteps"]);if(n!==void 0&&P!=null)s(n,["parameters","editConfig","baseSteps"],P);return o}function Ta(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["prompt"]);if(l!=null)s(o,["instances[0]","prompt"],l);let a=i(n,["referenceImages"]);if(a!=null){let d=a;if(Array.isArray(d))d=d.map((c)=>Cu(c));s(o,["instances[0]","referenceImages"],d)}let f=i(n,["config"]);if(f!=null)Ea(f,o);return o}function _a(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["predictions"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>on(a));s(t,["generatedImages"],l)}return t}function Ia(e,n,t){let o={},r=i(e,["taskType"]);if(n!==void 0&&r!=null)s(n,["requests[]","taskType"],r);let l=i(e,["title"]);if(n!==void 0&&l!=null)s(n,["requests[]","title"],l);let a=i(e,["outputDimensionality"]);if(n!==void 0&&a!=null)s(n,["requests[]","outputDimensionality"],a);if(i(e,["mimeType"])!==void 0)throw Error("mimeType parameter is not supported in Gemini API.");if(i(e,["autoTruncate"])!==void 0)throw Error("autoTruncate parameter is not supported in Gemini API.");if(i(e,["documentOcr"])!==void 0)throw Error("documentOcr parameter is not supported in Gemini API.");if(i(e,["audioTrackExtraction"])!==void 0)throw Error("audioTrackExtraction parameter is not supported in Gemini API.");return o}function Ca(e,n,t){let o={},r=i(t,["embeddingApiType"]);if(r===void 0)r="PREDICT";if(r==="PREDICT"){let p=i(e,["taskType"]);if(n!==void 0&&p!=null)s(n,["instances[]","task_type"],p)}else if(r==="EMBED_CONTENT"){let p=i(e,["taskType"]);if(n!==void 0&&p!=null)s(n,["embedContentConfig","taskType"],p)}let l=i(t,["embeddingApiType"]);if(l===void 0)l="PREDICT";if(l==="PREDICT"){let p=i(e,["title"]);if(n!==void 0&&p!=null)s(n,["instances[]","title"],p)}else if(l==="EMBED_CONTENT"){let p=i(e,["title"]);if(n!==void 0&&p!=null)s(n,["embedContentConfig","title"],p)}let a=i(t,["embeddingApiType"]);if(a===void 0)a="PREDICT";if(a==="PREDICT"){let p=i(e,["outputDimensionality"]);if(n!==void 0&&p!=null)s(n,["parameters","outputDimensionality"],p)}else if(a==="EMBED_CONTENT"){let p=i(e,["outputDimensionality"]);if(n!==void 0&&p!=null)s(n,["embedContentConfig","outputDimensionality"],p)}let f=i(t,["embeddingApiType"]);if(f===void 0)f="PREDICT";if(f==="PREDICT"){let p=i(e,["mimeType"]);if(n!==void 0&&p!=null)s(n,["instances[]","mimeType"],p)}let d=i(t,["embeddingApiType"]);if(d===void 0)d="PREDICT";if(d==="PREDICT"){let p=i(e,["autoTruncate"]);if(n!==void 0&&p!=null)s(n,["parameters","autoTruncate"],p)}else if(d==="EMBED_CONTENT"){let p=i(e,["autoTruncate"]);if(n!==void 0&&p!=null)s(n,["embedContentConfig","autoTruncate"],p)}let c=i(t,["embeddingApiType"]);if(c===void 0)c="PREDICT";if(c==="EMBED_CONTENT"){let p=i(e,["documentOcr"]);if(n!==void 0&&p!=null)s(n,["embedContentConfig","documentOcr"],p)}let m=i(t,["embeddingApiType"]);if(m===void 0)m="PREDICT";if(m==="EMBED_CONTENT"){let p=i(e,["audioTrackExtraction"]);if(n!==void 0&&p!=null)s(n,["embedContentConfig","audioTrackExtraction"],p)}return o}function Aa(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["contents"]);if(l!=null){let c=kn(e,l);if(Array.isArray(c))c=c.map((m)=>m);s(o,["requests[]","content"],c)}let a=i(n,["content"]);if(a!=null)Ue(B(a));let f=i(n,["config"]);if(f!=null)Ia(f,o);let d=i(n,["model"]);if(d!==void 0)s(o,["requests[]","model"],L(e,d));return o}function va(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(t,["embeddingApiType"]);if(l===void 0)l="PREDICT";if(l==="PREDICT"){let d=i(n,["contents"]);if(d!=null){let c=kn(e,d);if(Array.isArray(c))c=c.map((m)=>m);s(o,["instances[]","content"],c)}}let a=i(t,["embeddingApiType"]);if(a===void 0)a="PREDICT";if(a==="EMBED_CONTENT"){let d=i(n,["content"]);if(d!=null)s(o,["content"],Se(B(d)))}let f=i(n,["config"]);if(f!=null)Ca(f,o,t);return o}function Sa(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["embeddings"]);if(r!=null){let a=r;if(Array.isArray(a))a=a.map((f)=>f);s(t,["embeddings"],a)}let l=i(e,["metadata"]);if(l!=null)s(t,["metadata"],l);return t}function Ra(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["predictions[]","embeddings"]);if(r!=null){let a=r;if(Array.isArray(a))a=a.map((f)=>ra(f));s(t,["embeddings"],a)}let l=i(e,["metadata"]);if(l!=null)s(t,["metadata"],l);if(n&&i(n,["embeddingApiType"])==="EMBED_CONTENT"){let a=i(e,["embedding"]),f=i(e,["usageMetadata"]),d=i(e,["truncated"]);if(a){let c={};if(f&&f.promptTokenCount)c.tokenCount=f.promptTokenCount;if(d)c.truncated=d;a.statistics=c,s(t,["embeddings"],[a])}}return t}function Pa(e,n){let t={},o=i(e,["endpoint"]);if(o!=null)s(t,["name"],o);let r=i(e,["deployedModelId"]);if(r!=null)s(t,["deployedModelId"],r);return t}function wa(e,n){let t={};if(i(e,["displayName"])!==void 0)throw Error("displayName parameter is not supported in Gemini API.");let o=i(e,["fileUri"]);if(o!=null)s(t,["fileUri"],o);let r=i(e,["mimeType"]);if(r!=null)s(t,["mimeType"],r);return t}function Na(e,n){let t={},o=i(e,["id"]);if(o!=null)s(t,["id"],o);let r=i(e,["args"]);if(r!=null)s(t,["args"],r);let l=i(e,["name"]);if(l!=null)s(t,["name"],l);if(i(e,["partialArgs"])!==void 0)throw Error("partialArgs parameter is not supported in Gemini API.");if(i(e,["willContinue"])!==void 0)throw Error("willContinue parameter is not supported in Gemini API.");return t}function Ma(e,n){let t={},o=i(e,["allowedFunctionNames"]);if(o!=null)s(t,["allowedFunctionNames"],o);let r=i(e,["mode"]);if(r!=null)s(t,["mode"],r);if(i(e,["streamFunctionCallArguments"])!==void 0)throw Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return t}function Da(e,n){let t={},o=i(e,["description"]);if(o!=null)s(t,["description"],o);let r=i(e,["name"]);if(r!=null)s(t,["name"],r);let l=i(e,["parameters"]);if(l!=null)s(t,["parameters"],l);let a=i(e,["parametersJsonSchema"]);if(a!=null)s(t,["parametersJsonSchema"],a);let f=i(e,["response"]);if(f!=null)s(t,["response"],f);let d=i(e,["responseJsonSchema"]);if(d!=null)s(t,["responseJsonSchema"],d);if(i(e,["behavior"])!==void 0)throw Error("behavior parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return t}function xa(e,n,t,o){let r={},l=i(n,["systemInstruction"]);if(t!==void 0&&l!=null)s(t,["systemInstruction"],Ue(B(l)));let a=i(n,["temperature"]);if(a!=null)s(r,["temperature"],a);let f=i(n,["topP"]);if(f!=null)s(r,["topP"],f);let d=i(n,["topK"]);if(d!=null)s(r,["topK"],d);let c=i(n,["candidateCount"]);if(c!=null)s(r,["candidateCount"],c);let m=i(n,["maxOutputTokens"]);if(m!=null)s(r,["maxOutputTokens"],m);let p=i(n,["stopSequences"]);if(p!=null)s(r,["stopSequences"],p);let g=i(n,["responseLogprobs"]);if(g!=null)s(r,["responseLogprobs"],g);let y=i(n,["logprobs"]);if(y!=null)s(r,["logprobs"],y);let E=i(n,["presencePenalty"]);if(E!=null)s(r,["presencePenalty"],E);let T=i(n,["frequencyPenalty"]);if(T!=null)s(r,["frequencyPenalty"],T);let _=i(n,["seed"]);if(_!=null)s(r,["seed"],_);let C=i(n,["responseMimeType"]);if(C!=null)s(r,["responseMimeType"],C);let v=i(n,["responseSchema"]);if(v!=null)s(r,["responseSchema"],Fn(v));let R=i(n,["responseJsonSchema"]);if(R!=null)s(r,["responseJsonSchema"],R);if(i(n,["routingConfig"])!==void 0)throw Error("routingConfig parameter is not supported in Gemini API.");if(i(n,["modelSelectionConfig"])!==void 0)throw Error("modelSelectionConfig parameter is not supported in Gemini API.");let P=i(n,["safetySettings"]);if(t!==void 0&&P!=null){let V=P;if(Array.isArray(V))V=V.map((te)=>Au(te));s(t,["safetySettings"],V)}let x=i(n,["tools"]);if(t!==void 0&&x!=null){let V=Ce(x);if(Array.isArray(V))V=V.map((te)=>Du(Ie(te)));s(t,["tools"],V)}let I=i(n,["toolConfig"]);if(t!==void 0&&I!=null)s(t,["toolConfig"],Nu(I));if(i(n,["labels"])!==void 0)throw Error("labels parameter is not supported in Gemini API.");let U=i(n,["cachedContent"]);if(t!==void 0&&U!=null)s(t,["cachedContent"],ie(e,U));let A=i(n,["responseModalities"]);if(A!=null)s(r,["responseModalities"],A);let M=i(n,["mediaResolution"]);if(M!=null)s(r,["mediaResolution"],M);let G=i(n,["speechConfig"]);if(G!=null)s(r,["speechConfig"],Vn(G));if(i(n,["audioTimestamp"])!==void 0)throw Error("audioTimestamp parameter is not supported in Gemini API.");let K=i(n,["thinkingConfig"]);if(K!=null)s(r,["thinkingConfig"],K);let W=i(n,["imageConfig"]);if(W!=null)s(r,["imageConfig"],ru(W));let z=i(n,["enableEnhancedCivicAnswers"]);if(z!=null)s(r,["enableEnhancedCivicAnswers"],z);if(i(n,["modelArmorConfig"])!==void 0)throw Error("modelArmorConfig parameter is not supported in Gemini API.");let q=i(n,["serviceTier"]);if(t!==void 0&&q!=null)s(t,["serviceTier"],q);return r}function Ua(e,n,t,o){let r={},l=i(n,["systemInstruction"]);if(t!==void 0&&l!=null)s(t,["systemInstruction"],Se(B(l)));let a=i(n,["temperature"]);if(a!=null)s(r,["temperature"],a);let f=i(n,["topP"]);if(f!=null)s(r,["topP"],f);let d=i(n,["topK"]);if(d!=null)s(r,["topK"],d);let c=i(n,["candidateCount"]);if(c!=null)s(r,["candidateCount"],c);let m=i(n,["maxOutputTokens"]);if(m!=null)s(r,["maxOutputTokens"],m);let p=i(n,["stopSequences"]);if(p!=null)s(r,["stopSequences"],p);let g=i(n,["responseLogprobs"]);if(g!=null)s(r,["responseLogprobs"],g);let y=i(n,["logprobs"]);if(y!=null)s(r,["logprobs"],y);let E=i(n,["presencePenalty"]);if(E!=null)s(r,["presencePenalty"],E);let T=i(n,["frequencyPenalty"]);if(T!=null)s(r,["frequencyPenalty"],T);let _=i(n,["seed"]);if(_!=null)s(r,["seed"],_);let C=i(n,["responseMimeType"]);if(C!=null)s(r,["responseMimeType"],C);let v=i(n,["responseSchema"]);if(v!=null)s(r,["responseSchema"],Fn(v));let R=i(n,["responseJsonSchema"]);if(R!=null)s(r,["responseJsonSchema"],R);let P=i(n,["routingConfig"]);if(P!=null)s(r,["routingConfig"],P);let x=i(n,["modelSelectionConfig"]);if(x!=null)s(r,["modelConfig"],x);let I=i(n,["safetySettings"]);if(t!==void 0&&I!=null){let X=I;if(Array.isArray(X))X=X.map((an)=>an);s(t,["safetySettings"],X)}let U=i(n,["tools"]);if(t!==void 0&&U!=null){let X=Ce(U);if(Array.isArray(X))X=X.map((an)=>Ai(Ie(an)));s(t,["tools"],X)}let A=i(n,["toolConfig"]);if(t!==void 0&&A!=null)s(t,["toolConfig"],Mu(A));let M=i(n,["labels"]);if(t!==void 0&&M!=null)s(t,["labels"],M);let G=i(n,["cachedContent"]);if(t!==void 0&&G!=null)s(t,["cachedContent"],ie(e,G));let K=i(n,["responseModalities"]);if(K!=null)s(r,["responseModalities"],K);let W=i(n,["mediaResolution"]);if(W!=null)s(r,["mediaResolution"],W);let z=i(n,["speechConfig"]);if(z!=null)s(r,["speechConfig"],Vn(z));let q=i(n,["audioTimestamp"]);if(q!=null)s(r,["audioTimestamp"],q);let V=i(n,["thinkingConfig"]);if(V!=null)s(r,["thinkingConfig"],V);let te=i(n,["imageConfig"]);if(te!=null)s(r,["imageConfig"],su(te));if(i(n,["enableEnhancedCivicAnswers"])!==void 0)throw Error("enableEnhancedCivicAnswers parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");let Re=i(n,["modelArmorConfig"]);if(t!==void 0&&Re!=null)s(t,["modelArmorConfig"],Re);let ce=i(n,["serviceTier"]);if(t!==void 0&&ce!=null)s(t,["serviceTier"],ce);return r}function Eo(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["contents"]);if(l!=null){let f=O(l);if(Array.isArray(f))f=f.map((d)=>Ue(d));s(o,["contents"],f)}let a=i(n,["config"]);if(a!=null)s(o,["generationConfig"],xa(e,a,o));return o}function To(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["contents"]);if(l!=null){let f=O(l);if(Array.isArray(f))f=f.map((d)=>Se(d));s(o,["contents"],f)}let a=i(n,["config"]);if(a!=null)s(o,["generationConfig"],Ua(e,a,o));return o}function _o(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["candidates"]);if(r!=null){let m=r;if(Array.isArray(m))m=m.map((p)=>na(p));s(t,["candidates"],m)}let l=i(e,["modelVersion"]);if(l!=null)s(t,["modelVersion"],l);let a=i(e,["promptFeedback"]);if(a!=null)s(t,["promptFeedback"],a);let f=i(e,["responseId"]);if(f!=null)s(t,["responseId"],f);let d=i(e,["usageMetadata"]);if(d!=null)s(t,["usageMetadata"],d);let c=i(e,["modelStatus"]);if(c!=null)s(t,["modelStatus"],c);return t}function Io(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["candidates"]);if(r!=null){let m=r;if(Array.isArray(m))m=m.map((p)=>p);s(t,["candidates"],m)}let l=i(e,["createTime"]);if(l!=null)s(t,["createTime"],l);let a=i(e,["modelVersion"]);if(a!=null)s(t,["modelVersion"],a);let f=i(e,["promptFeedback"]);if(f!=null)s(t,["promptFeedback"],f);let d=i(e,["responseId"]);if(d!=null)s(t,["responseId"],d);let c=i(e,["usageMetadata"]);if(c!=null)s(t,["usageMetadata"],c);return t}function La(e,n,t){let o={};if(i(e,["outputGcsUri"])!==void 0)throw Error("outputGcsUri parameter is not supported in Gemini API.");if(i(e,["negativePrompt"])!==void 0)throw Error("negativePrompt parameter is not supported in Gemini API.");let r=i(e,["numberOfImages"]);if(n!==void 0&&r!=null)s(n,["parameters","sampleCount"],r);let l=i(e,["aspectRatio"]);if(n!==void 0&&l!=null)s(n,["parameters","aspectRatio"],l);let a=i(e,["guidanceScale"]);if(n!==void 0&&a!=null)s(n,["parameters","guidanceScale"],a);if(i(e,["seed"])!==void 0)throw Error("seed parameter is not supported in Gemini API.");let f=i(e,["safetyFilterLevel"]);if(n!==void 0&&f!=null)s(n,["parameters","safetySetting"],f);let d=i(e,["personGeneration"]);if(n!==void 0&&d!=null)s(n,["parameters","personGeneration"],d);let c=i(e,["includeSafetyAttributes"]);if(n!==void 0&&c!=null)s(n,["parameters","includeSafetyAttributes"],c);let m=i(e,["includeRaiReason"]);if(n!==void 0&&m!=null)s(n,["parameters","includeRaiReason"],m);let p=i(e,["language"]);if(n!==void 0&&p!=null)s(n,["parameters","language"],p);let g=i(e,["outputMimeType"]);if(n!==void 0&&g!=null)s(n,["parameters","outputOptions","mimeType"],g);let y=i(e,["outputCompressionQuality"]);if(n!==void 0&&y!=null)s(n,["parameters","outputOptions","compressionQuality"],y);if(i(e,["addWatermark"])!==void 0)throw Error("addWatermark parameter is not supported in Gemini API.");if(i(e,["labels"])!==void 0)throw Error("labels parameter is not supported in Gemini API.");let E=i(e,["imageSize"]);if(n!==void 0&&E!=null)s(n,["parameters","sampleImageSize"],E);if(i(e,["enhancePrompt"])!==void 0)throw Error("enhancePrompt parameter is not supported in Gemini API.");return o}function Ga(e,n,t){let o={},r=i(e,["outputGcsUri"]);if(n!==void 0&&r!=null)s(n,["parameters","storageUri"],r);let l=i(e,["negativePrompt"]);if(n!==void 0&&l!=null)s(n,["parameters","negativePrompt"],l);let a=i(e,["numberOfImages"]);if(n!==void 0&&a!=null)s(n,["parameters","sampleCount"],a);let f=i(e,["aspectRatio"]);if(n!==void 0&&f!=null)s(n,["parameters","aspectRatio"],f);let d=i(e,["guidanceScale"]);if(n!==void 0&&d!=null)s(n,["parameters","guidanceScale"],d);let c=i(e,["seed"]);if(n!==void 0&&c!=null)s(n,["parameters","seed"],c);let m=i(e,["safetyFilterLevel"]);if(n!==void 0&&m!=null)s(n,["parameters","safetySetting"],m);let p=i(e,["personGeneration"]);if(n!==void 0&&p!=null)s(n,["parameters","personGeneration"],p);let g=i(e,["includeSafetyAttributes"]);if(n!==void 0&&g!=null)s(n,["parameters","includeSafetyAttributes"],g);let y=i(e,["includeRaiReason"]);if(n!==void 0&&y!=null)s(n,["parameters","includeRaiReason"],y);let E=i(e,["language"]);if(n!==void 0&&E!=null)s(n,["parameters","language"],E);let T=i(e,["outputMimeType"]);if(n!==void 0&&T!=null)s(n,["parameters","outputOptions","mimeType"],T);let _=i(e,["outputCompressionQuality"]);if(n!==void 0&&_!=null)s(n,["parameters","outputOptions","compressionQuality"],_);let C=i(e,["addWatermark"]);if(n!==void 0&&C!=null)s(n,["parameters","addWatermark"],C);let v=i(e,["labels"]);if(n!==void 0&&v!=null)s(n,["labels"],v);let R=i(e,["imageSize"]);if(n!==void 0&&R!=null)s(n,["parameters","sampleImageSize"],R);let P=i(e,["enhancePrompt"]);if(n!==void 0&&P!=null)s(n,["parameters","enhancePrompt"],P);return o}function ka(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["prompt"]);if(l!=null)s(o,["instances[0]","prompt"],l);let a=i(n,["config"]);if(a!=null)La(a,o);return o}function Fa(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["prompt"]);if(l!=null)s(o,["instances[0]","prompt"],l);let a=i(n,["config"]);if(a!=null)Ga(a,o);return o}function Va(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["predictions"]);if(r!=null){let a=r;if(Array.isArray(a))a=a.map((f)=>Xa(f));s(t,["generatedImages"],a)}let l=i(e,["positivePromptSafetyAttributes"]);if(l!=null)s(t,["positivePromptSafetyAttributes"],Ii(l));return t}function qa(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["predictions"]);if(r!=null){let a=r;if(Array.isArray(a))a=a.map((f)=>on(f));s(t,["generatedImages"],a)}let l=i(e,["positivePromptSafetyAttributes"]);if(l!=null)s(t,["positivePromptSafetyAttributes"],Ci(l));return t}function Ha(e,n,t){let o={},r=i(e,["numberOfVideos"]);if(n!==void 0&&r!=null)s(n,["parameters","sampleCount"],r);if(i(e,["outputGcsUri"])!==void 0)throw Error("outputGcsUri parameter is not supported in Gemini API.");if(i(e,["fps"])!==void 0)throw Error("fps parameter is not supported in Gemini API.");let l=i(e,["durationSeconds"]);if(n!==void 0&&l!=null)s(n,["parameters","durationSeconds"],l);if(i(e,["seed"])!==void 0)throw Error("seed parameter is not supported in Gemini API.");let a=i(e,["aspectRatio"]);if(n!==void 0&&a!=null)s(n,["parameters","aspectRatio"],a);let f=i(e,["resolution"]);if(n!==void 0&&f!=null)s(n,["parameters","resolution"],f);let d=i(e,["personGeneration"]);if(n!==void 0&&d!=null)s(n,["parameters","personGeneration"],d);if(i(e,["pubsubTopic"])!==void 0)throw Error("pubsubTopic parameter is not supported in Gemini API.");let c=i(e,["negativePrompt"]);if(n!==void 0&&c!=null)s(n,["parameters","negativePrompt"],c);let m=i(e,["enhancePrompt"]);if(n!==void 0&&m!=null)s(n,["parameters","enhancePrompt"],m);if(i(e,["generateAudio"])!==void 0)throw Error("generateAudio parameter is not supported in Gemini API.");let p=i(e,["lastFrame"]);if(n!==void 0&&p!=null)s(n,["instances[0]","lastFrame"],rn(p));let g=i(e,["referenceImages"]);if(n!==void 0&&g!=null){let E=g;if(Array.isArray(E))E=E.map((T)=>$u(T));s(n,["instances[0]","referenceImages"],E)}if(i(e,["mask"])!==void 0)throw Error("mask parameter is not supported in Gemini API.");if(i(e,["compressionQuality"])!==void 0)throw Error("compressionQuality parameter is not supported in Gemini API.");if(i(e,["labels"])!==void 0)throw Error("labels parameter is not supported in Gemini API.");let y=i(e,["webhookConfig"]);if(n!==void 0&&y!=null)s(n,["webhookConfig"],y);if(i(e,["resizeMode"])!==void 0)throw Error("resizeMode parameter is not supported in Gemini API.");return o}function Ba(e,n,t){let o={},r=i(e,["numberOfVideos"]);if(n!==void 0&&r!=null)s(n,["parameters","sampleCount"],r);let l=i(e,["outputGcsUri"]);if(n!==void 0&&l!=null)s(n,["parameters","storageUri"],l);let a=i(e,["fps"]);if(n!==void 0&&a!=null)s(n,["parameters","fps"],a);let f=i(e,["durationSeconds"]);if(n!==void 0&&f!=null)s(n,["parameters","durationSeconds"],f);let d=i(e,["seed"]);if(n!==void 0&&d!=null)s(n,["parameters","seed"],d);let c=i(e,["aspectRatio"]);if(n!==void 0&&c!=null)s(n,["parameters","aspectRatio"],c);let m=i(e,["resolution"]);if(n!==void 0&&m!=null)s(n,["parameters","resolution"],m);let p=i(e,["personGeneration"]);if(n!==void 0&&p!=null)s(n,["parameters","personGeneration"],p);let g=i(e,["pubsubTopic"]);if(n!==void 0&&g!=null)s(n,["parameters","pubsubTopic"],g);let y=i(e,["negativePrompt"]);if(n!==void 0&&y!=null)s(n,["parameters","negativePrompt"],y);let E=i(e,["enhancePrompt"]);if(n!==void 0&&E!=null)s(n,["parameters","enhancePrompt"],E);let T=i(e,["generateAudio"]);if(n!==void 0&&T!=null)s(n,["parameters","generateAudio"],T);let _=i(e,["lastFrame"]);if(n!==void 0&&_!=null)s(n,["instances[0]","lastFrame"],ee(_));let C=i(e,["referenceImages"]);if(n!==void 0&&C!=null){let I=C;if(Array.isArray(I))I=I.map((U)=>Ou(U));s(n,["instances[0]","referenceImages"],I)}let v=i(e,["mask"]);if(n!==void 0&&v!=null)s(n,["instances[0]","mask"],bu(v));let R=i(e,["compressionQuality"]);if(n!==void 0&&R!=null)s(n,["parameters","compressionQuality"],R);let P=i(e,["labels"]);if(n!==void 0&&P!=null)s(n,["labels"],P);if(i(e,["webhookConfig"])!==void 0)throw Error("webhookConfig parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");let x=i(e,["resizeMode"]);if(n!==void 0&&x!=null)s(n,["parameters","resizeMode"],x);return o}function Ja(e,n){let t={},o=i(e,["name"]);if(o!=null)s(t,["name"],o);let r=i(e,["metadata"]);if(r!=null)s(t,["metadata"],r);let l=i(e,["done"]);if(l!=null)s(t,["done"],l);let a=i(e,["error"]);if(a!=null)s(t,["error"],a);let f=i(e,["response","generateVideoResponse"]);if(f!=null)s(t,["response"],Ka(f));return t}function ba(e,n){let t={},o=i(e,["name"]);if(o!=null)s(t,["name"],o);let r=i(e,["metadata"]);if(r!=null)s(t,["metadata"],r);let l=i(e,["done"]);if(l!=null)s(t,["done"],l);let a=i(e,["error"]);if(a!=null)s(t,["error"],a);let f=i(e,["response"]);if(f!=null)s(t,["response"],Ya(f));return t}function $a(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["prompt"]);if(l!=null)s(o,["instances[0]","prompt"],l);let a=i(n,["image"]);if(a!=null)s(o,["instances[0]","image"],rn(a));let f=i(n,["video"]);if(f!=null)s(o,["instances[0]","video"],vi(f));let d=i(n,["source"]);if(d!=null)Wa(d,o);let c=i(n,["config"]);if(c!=null)Ha(c,o);return o}function Oa(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["prompt"]);if(l!=null)s(o,["instances[0]","prompt"],l);let a=i(n,["image"]);if(a!=null)s(o,["instances[0]","image"],ee(a));let f=i(n,["video"]);if(f!=null)s(o,["instances[0]","video"],Si(f));let d=i(n,["source"]);if(d!=null)za(d,o);let c=i(n,["config"]);if(c!=null)Ba(c,o);return o}function Ka(e,n){let t={},o=i(e,["generatedSamples"]);if(o!=null){let a=o;if(Array.isArray(a))a=a.map((f)=>Za(f));s(t,["generatedVideos"],a)}let r=i(e,["raiMediaFilteredCount"]);if(r!=null)s(t,["raiMediaFilteredCount"],r);let l=i(e,["raiMediaFilteredReasons"]);if(l!=null)s(t,["raiMediaFilteredReasons"],l);return t}function Ya(e,n){let t={},o=i(e,["videos"]);if(o!=null){let a=o;if(Array.isArray(a))a=a.map((f)=>ja(f));s(t,["generatedVideos"],a)}let r=i(e,["raiMediaFilteredCount"]);if(r!=null)s(t,["raiMediaFilteredCount"],r);let l=i(e,["raiMediaFilteredReasons"]);if(l!=null)s(t,["raiMediaFilteredReasons"],l);return t}function Wa(e,n,t){let o={},r=i(e,["prompt"]);if(n!==void 0&&r!=null)s(n,["instances[0]","prompt"],r);let l=i(e,["image"]);if(n!==void 0&&l!=null)s(n,["instances[0]","image"],rn(l));let a=i(e,["video"]);if(n!==void 0&&a!=null)s(n,["instances[0]","video"],vi(a));return o}function za(e,n,t){let o={},r=i(e,["prompt"]);if(n!==void 0&&r!=null)s(n,["instances[0]","prompt"],r);let l=i(e,["image"]);if(n!==void 0&&l!=null)s(n,["instances[0]","image"],ee(l));let a=i(e,["video"]);if(n!==void 0&&a!=null)s(n,["instances[0]","video"],Si(a));return o}function Xa(e,n){let t={},o=i(e,["_self"]);if(o!=null)s(t,["image"],lu(o));let r=i(e,["raiFilteredReason"]);if(r!=null)s(t,["raiFilteredReason"],r);let l=i(e,["_self"]);if(l!=null)s(t,["safetyAttributes"],Ii(l));return t}function on(e,n){let t={},o=i(e,["_self"]);if(o!=null)s(t,["image"],_i(o));let r=i(e,["raiFilteredReason"]);if(r!=null)s(t,["raiFilteredReason"],r);let l=i(e,["_self"]);if(l!=null)s(t,["safetyAttributes"],Ci(l));let a=i(e,["prompt"]);if(a!=null)s(t,["enhancedPrompt"],a);return t}function Qa(e,n){let t={},o=i(e,["_self"]);if(o!=null)s(t,["mask"],_i(o));let r=i(e,["labels"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>a);s(t,["labels"],l)}return t}function Za(e,n){let t={},o=i(e,["video"]);if(o!=null)s(t,["video"],Bu(o));return t}function ja(e,n){let t={},o=i(e,["_self"]);if(o!=null)s(t,["video"],Ju(o));return t}function eu(e,n){let t={},o=i(e,["modelSelectionConfig"]);if(o!=null)s(t,["modelConfig"],o);let r=i(e,["responseJsonSchema"]);if(r!=null)s(t,["responseJsonSchema"],r);let l=i(e,["audioTimestamp"]);if(l!=null)s(t,["audioTimestamp"],l);let a=i(e,["candidateCount"]);if(a!=null)s(t,["candidateCount"],a);let f=i(e,["enableAffectiveDialog"]);if(f!=null)s(t,["enableAffectiveDialog"],f);let d=i(e,["frequencyPenalty"]);if(d!=null)s(t,["frequencyPenalty"],d);let c=i(e,["logprobs"]);if(c!=null)s(t,["logprobs"],c);let m=i(e,["maxOutputTokens"]);if(m!=null)s(t,["maxOutputTokens"],m);let p=i(e,["mediaResolution"]);if(p!=null)s(t,["mediaResolution"],p);let g=i(e,["presencePenalty"]);if(g!=null)s(t,["presencePenalty"],g);let y=i(e,["responseLogprobs"]);if(y!=null)s(t,["responseLogprobs"],y);let E=i(e,["responseMimeType"]);if(E!=null)s(t,["responseMimeType"],E);let T=i(e,["responseModalities"]);if(T!=null)s(t,["responseModalities"],T);let _=i(e,["responseSchema"]);if(_!=null)s(t,["responseSchema"],_);let C=i(e,["routingConfig"]);if(C!=null)s(t,["routingConfig"],C);let v=i(e,["seed"]);if(v!=null)s(t,["seed"],v);let R=i(e,["speechConfig"]);if(R!=null)s(t,["speechConfig"],R);let P=i(e,["stopSequences"]);if(P!=null)s(t,["stopSequences"],P);let x=i(e,["temperature"]);if(x!=null)s(t,["temperature"],x);let I=i(e,["thinkingConfig"]);if(I!=null)s(t,["thinkingConfig"],I);let U=i(e,["topK"]);if(U!=null)s(t,["topK"],U);let A=i(e,["topP"]);if(A!=null)s(t,["topP"],A);if(i(e,["enableEnhancedCivicAnswers"])!==void 0)throw Error("enableEnhancedCivicAnswers parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return t}function nu(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","name"],L(e,r));return o}function tu(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","name"],L(e,r));return o}function ou(e,n){let t={},o=i(e,["authConfig"]);if(o!=null)s(t,["authConfig"],jl(o));let r=i(e,["enableWidget"]);if(r!=null)s(t,["enableWidget"],r);return t}function iu(e,n){let t={},o=i(e,["searchTypes"]);if(o!=null)s(t,["searchTypes"],o);if(i(e,["blockingConfidence"])!==void 0)throw Error("blockingConfidence parameter is not supported in Gemini API.");if(i(e,["excludeDomains"])!==void 0)throw Error("excludeDomains parameter is not supported in Gemini API.");let r=i(e,["timeRangeFilter"]);if(r!=null)s(t,["timeRangeFilter"],r);return t}function ru(e,n){let t={},o=i(e,["aspectRatio"]);if(o!=null)s(t,["aspectRatio"],o);let r=i(e,["imageSize"]);if(r!=null)s(t,["imageSize"],r);if(i(e,["personGeneration"])!==void 0)throw Error("personGeneration parameter is not supported in Gemini API.");if(i(e,["prominentPeople"])!==void 0)throw Error("prominentPeople parameter is not supported in Gemini API.");if(i(e,["outputMimeType"])!==void 0)throw Error("outputMimeType parameter is not supported in Gemini API.");if(i(e,["outputCompressionQuality"])!==void 0)throw Error("outputCompressionQuality parameter is not supported in Gemini API.");if(i(e,["imageOutputOptions"])!==void 0)throw Error("imageOutputOptions parameter is not supported in Gemini API.");return t}function su(e,n){let t={},o=i(e,["aspectRatio"]);if(o!=null)s(t,["aspectRatio"],o);let r=i(e,["imageSize"]);if(r!=null)s(t,["imageSize"],r);let l=i(e,["personGeneration"]);if(l!=null)s(t,["personGeneration"],l);let a=i(e,["prominentPeople"]);if(a!=null)s(t,["prominentPeople"],a);let f=i(e,["outputMimeType"]);if(f!=null)s(t,["imageOutputOptions","mimeType"],f);let d=i(e,["outputCompressionQuality"]);if(d!=null)s(t,["imageOutputOptions","compressionQuality"],d);let c=i(e,["imageOutputOptions"]);if(c!=null)s(t,["imageOutputOptions"],c);return t}function lu(e,n){let t={},o=i(e,["bytesBase64Encoded"]);if(o!=null)s(t,["imageBytes"],de(o));let r=i(e,["mimeType"]);if(r!=null)s(t,["mimeType"],r);return t}function _i(e,n){let t={},o=i(e,["gcsUri"]);if(o!=null)s(t,["gcsUri"],o);let r=i(e,["bytesBase64Encoded"]);if(r!=null)s(t,["imageBytes"],de(r));let l=i(e,["mimeType"]);if(l!=null)s(t,["mimeType"],l);return t}function rn(e,n){let t={};if(i(e,["gcsUri"])!==void 0)throw Error("gcsUri parameter is not supported in Gemini API.");let o=i(e,["imageBytes"]);if(o!=null)s(t,["bytesBase64Encoded"],de(o));let r=i(e,["mimeType"]);if(r!=null)s(t,["mimeType"],r);return t}function ee(e,n){let t={},o=i(e,["gcsUri"]);if(o!=null)s(t,["gcsUri"],o);let r=i(e,["imageBytes"]);if(r!=null)s(t,["bytesBase64Encoded"],de(r));let l=i(e,["mimeType"]);if(l!=null)s(t,["mimeType"],l);return t}function au(e,n,t,o){let r={},l=i(n,["pageSize"]);if(t!==void 0&&l!=null)s(t,["_query","pageSize"],l);let a=i(n,["pageToken"]);if(t!==void 0&&a!=null)s(t,["_query","pageToken"],a);let f=i(n,["filter"]);if(t!==void 0&&f!=null)s(t,["_query","filter"],f);let d=i(n,["queryBase"]);if(t!==void 0&&d!=null)s(t,["_url","models_url"],ai(e,d));return r}function uu(e,n,t,o){let r={},l=i(n,["pageSize"]);if(t!==void 0&&l!=null)s(t,["_query","pageSize"],l);let a=i(n,["pageToken"]);if(t!==void 0&&a!=null)s(t,["_query","pageToken"],a);let f=i(n,["filter"]);if(t!==void 0&&f!=null)s(t,["_query","filter"],f);let d=i(n,["queryBase"]);if(t!==void 0&&d!=null)s(t,["_url","models_url"],ai(e,d));return r}function du(e,n,t){let o={},r=i(n,["config"]);if(r!=null)au(e,r,o);return o}function fu(e,n,t){let o={},r=i(n,["config"]);if(r!=null)uu(e,r,o);return o}function cu(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["nextPageToken"]);if(r!=null)s(t,["nextPageToken"],r);let l=i(e,["_self"]);if(l!=null){let a=ui(l);if(Array.isArray(a))a=a.map((f)=>Sn(f));s(t,["models"],a)}return t}function pu(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["nextPageToken"]);if(r!=null)s(t,["nextPageToken"],r);let l=i(e,["_self"]);if(l!=null){let a=ui(l);if(Array.isArray(a))a=a.map((f)=>Rn(f));s(t,["models"],a)}return t}function hu(e,n){let t={},o=i(e,["maskMode"]);if(o!=null)s(t,["maskMode"],o);let r=i(e,["segmentationClasses"]);if(r!=null)s(t,["maskClasses"],r);let l=i(e,["maskDilation"]);if(l!=null)s(t,["dilation"],l);return t}function Sn(e,n){let t={},o=i(e,["name"]);if(o!=null)s(t,["name"],o);let r=i(e,["displayName"]);if(r!=null)s(t,["displayName"],r);let l=i(e,["description"]);if(l!=null)s(t,["description"],l);let a=i(e,["version"]);if(a!=null)s(t,["version"],a);let f=i(e,["_self"]);if(f!=null)s(t,["tunedModelInfo"],xu(f));let d=i(e,["inputTokenLimit"]);if(d!=null)s(t,["inputTokenLimit"],d);let c=i(e,["outputTokenLimit"]);if(c!=null)s(t,["outputTokenLimit"],c);let m=i(e,["supportedGenerationMethods"]);if(m!=null)s(t,["supportedActions"],m);let p=i(e,["temperature"]);if(p!=null)s(t,["temperature"],p);let g=i(e,["maxTemperature"]);if(g!=null)s(t,["maxTemperature"],g);let y=i(e,["topP"]);if(y!=null)s(t,["topP"],y);let E=i(e,["topK"]);if(E!=null)s(t,["topK"],E);let T=i(e,["thinking"]);if(T!=null)s(t,["thinking"],T);return t}function Rn(e,n){let t={},o=i(e,["name"]);if(o!=null)s(t,["name"],o);let r=i(e,["displayName"]);if(r!=null)s(t,["displayName"],r);let l=i(e,["description"]);if(l!=null)s(t,["description"],l);let a=i(e,["versionId"]);if(a!=null)s(t,["version"],a);let f=i(e,["deployedModels"]);if(f!=null){let g=f;if(Array.isArray(g))g=g.map((y)=>Pa(y));s(t,["endpoints"],g)}let d=i(e,["labels"]);if(d!=null)s(t,["labels"],d);let c=i(e,["_self"]);if(c!=null)s(t,["tunedModelInfo"],Uu(c));let m=i(e,["defaultCheckpointId"]);if(m!=null)s(t,["defaultCheckpointId"],m);let p=i(e,["checkpoints"]);if(p!=null){let g=p;if(Array.isArray(g))g=g.map((y)=>y);s(t,["checkpoints"],g)}return t}function mu(e,n){let t={},o=i(e,["mediaResolution"]);if(o!=null)s(t,["mediaResolution"],o);let r=i(e,["codeExecutionResult"]);if(r!=null)s(t,["codeExecutionResult"],r);let l=i(e,["executableCode"]);if(l!=null)s(t,["executableCode"],l);let a=i(e,["fileData"]);if(a!=null)s(t,["fileData"],wa(a));let f=i(e,["functionCall"]);if(f!=null)s(t,["functionCall"],Na(f));let d=i(e,["functionResponse"]);if(d!=null)s(t,["functionResponse"],d);let c=i(e,["inlineData"]);if(c!=null)s(t,["inlineData"],ea(c));let m=i(e,["text"]);if(m!=null)s(t,["text"],m);let p=i(e,["thought"]);if(p!=null)s(t,["thought"],p);let g=i(e,["thoughtSignature"]);if(g!=null)s(t,["thoughtSignature"],g);let y=i(e,["videoMetadata"]);if(y!=null)s(t,["videoMetadata"],y);let E=i(e,["toolCall"]);if(E!=null)s(t,["toolCall"],E);let T=i(e,["toolResponse"]);if(T!=null)s(t,["toolResponse"],T);let _=i(e,["partMetadata"]);if(_!=null)s(t,["partMetadata"],_);return t}function gu(e,n){let t={},o=i(e,["mediaResolution"]);if(o!=null)s(t,["mediaResolution"],o);let r=i(e,["codeExecutionResult"]);if(r!=null)s(t,["codeExecutionResult"],r);let l=i(e,["executableCode"]);if(l!=null)s(t,["executableCode"],l);let a=i(e,["fileData"]);if(a!=null)s(t,["fileData"],a);let f=i(e,["functionCall"]);if(f!=null)s(t,["functionCall"],f);let d=i(e,["functionResponse"]);if(d!=null)s(t,["functionResponse"],d);let c=i(e,["inlineData"]);if(c!=null)s(t,["inlineData"],c);let m=i(e,["text"]);if(m!=null)s(t,["text"],m);let p=i(e,["thought"]);if(p!=null)s(t,["thought"],p);let g=i(e,["thoughtSignature"]);if(g!=null)s(t,["thoughtSignature"],g);let y=i(e,["videoMetadata"]);if(y!=null)s(t,["videoMetadata"],y);if(i(e,["toolCall"])!==void 0)throw Error("toolCall parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");if(i(e,["toolResponse"])!==void 0)throw Error("toolResponse parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");if(i(e,["partMetadata"])!==void 0)throw Error("partMetadata parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return t}function yu(e,n){let t={},o=i(e,["productImage"]);if(o!=null)s(t,["image"],ee(o));return t}function Eu(e,n,t){let o={},r=i(e,["numberOfImages"]);if(n!==void 0&&r!=null)s(n,["parameters","sampleCount"],r);let l=i(e,["baseSteps"]);if(n!==void 0&&l!=null)s(n,["parameters","baseSteps"],l);let a=i(e,["outputGcsUri"]);if(n!==void 0&&a!=null)s(n,["parameters","storageUri"],a);let f=i(e,["seed"]);if(n!==void 0&&f!=null)s(n,["parameters","seed"],f);let d=i(e,["safetyFilterLevel"]);if(n!==void 0&&d!=null)s(n,["parameters","safetySetting"],d);let c=i(e,["personGeneration"]);if(n!==void 0&&c!=null)s(n,["parameters","personGeneration"],c);let m=i(e,["addWatermark"]);if(n!==void 0&&m!=null)s(n,["parameters","addWatermark"],m);let p=i(e,["outputMimeType"]);if(n!==void 0&&p!=null)s(n,["parameters","outputOptions","mimeType"],p);let g=i(e,["outputCompressionQuality"]);if(n!==void 0&&g!=null)s(n,["parameters","outputOptions","compressionQuality"],g);let y=i(e,["enhancePrompt"]);if(n!==void 0&&y!=null)s(n,["parameters","enhancePrompt"],y);let E=i(e,["labels"]);if(n!==void 0&&E!=null)s(n,["labels"],E);return o}function Tu(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["source"]);if(l!=null)Iu(l,o);let a=i(n,["config"]);if(a!=null)Eu(a,o);return o}function _u(e,n){let t={},o=i(e,["predictions"]);if(o!=null){let r=o;if(Array.isArray(r))r=r.map((l)=>on(l));s(t,["generatedImages"],r)}return t}function Iu(e,n,t){let o={},r=i(e,["prompt"]);if(n!==void 0&&r!=null)s(n,["instances[0]","prompt"],r);let l=i(e,["personImage"]);if(n!==void 0&&l!=null)s(n,["instances[0]","personImage","image"],ee(l));let a=i(e,["productImages"]);if(n!==void 0&&a!=null){let f=a;if(Array.isArray(f))f=f.map((d)=>yu(d));s(n,["instances[0]","productImages"],f)}return o}function Cu(e,n){let t={},o=i(e,["referenceImage"]);if(o!=null)s(t,["referenceImage"],ee(o));let r=i(e,["referenceId"]);if(r!=null)s(t,["referenceId"],r);let l=i(e,["referenceType"]);if(l!=null)s(t,["referenceType"],l);let a=i(e,["maskImageConfig"]);if(a!=null)s(t,["maskImageConfig"],hu(a));let f=i(e,["controlImageConfig"]);if(f!=null)s(t,["controlImageConfig"],la(f));let d=i(e,["styleImageConfig"]);if(d!=null)s(t,["styleImageConfig"],d);let c=i(e,["subjectImageConfig"]);if(c!=null)s(t,["subjectImageConfig"],c);return t}function Ii(e,n){let t={},o=i(e,["safetyAttributes","categories"]);if(o!=null)s(t,["categories"],o);let r=i(e,["safetyAttributes","scores"]);if(r!=null)s(t,["scores"],r);let l=i(e,["contentType"]);if(l!=null)s(t,["contentType"],l);return t}function Ci(e,n){let t={},o=i(e,["safetyAttributes","categories"]);if(o!=null)s(t,["categories"],o);let r=i(e,["safetyAttributes","scores"]);if(r!=null)s(t,["scores"],r);let l=i(e,["contentType"]);if(l!=null)s(t,["contentType"],l);return t}function Au(e,n){let t={},o=i(e,["category"]);if(o!=null)s(t,["category"],o);if(i(e,["method"])!==void 0)throw Error("method parameter is not supported in Gemini API.");let r=i(e,["threshold"]);if(r!=null)s(t,["threshold"],r);return t}function vu(e,n){let t={},o=i(e,["image"]);if(o!=null)s(t,["image"],ee(o));return t}function Su(e,n,t){let o={},r=i(e,["mode"]);if(n!==void 0&&r!=null)s(n,["parameters","mode"],r);let l=i(e,["maxPredictions"]);if(n!==void 0&&l!=null)s(n,["parameters","maxPredictions"],l);let a=i(e,["confidenceThreshold"]);if(n!==void 0&&a!=null)s(n,["parameters","confidenceThreshold"],a);let f=i(e,["maskDilation"]);if(n!==void 0&&f!=null)s(n,["parameters","maskDilation"],f);let d=i(e,["binaryColorThreshold"]);if(n!==void 0&&d!=null)s(n,["parameters","binaryColorThreshold"],d);let c=i(e,["labels"]);if(n!==void 0&&c!=null)s(n,["labels"],c);return o}function Ru(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["source"]);if(l!=null)wu(l,o);let a=i(n,["config"]);if(a!=null)Su(a,o);return o}function Pu(e,n){let t={},o=i(e,["predictions"]);if(o!=null){let r=o;if(Array.isArray(r))r=r.map((l)=>Qa(l));s(t,["generatedMasks"],r)}return t}function wu(e,n,t){let o={},r=i(e,["prompt"]);if(n!==void 0&&r!=null)s(n,["instances[0]","prompt"],r);let l=i(e,["image"]);if(n!==void 0&&l!=null)s(n,["instances[0]","image"],ee(l));let a=i(e,["scribbleImage"]);if(n!==void 0&&a!=null)s(n,["instances[0]","scribble"],vu(a));return o}function Nu(e,n){let t={},o=i(e,["retrievalConfig"]);if(o!=null)s(t,["retrievalConfig"],o);let r=i(e,["functionCallingConfig"]);if(r!=null)s(t,["functionCallingConfig"],Ma(r));let l=i(e,["includeServerSideToolInvocations"]);if(l!=null)s(t,["includeServerSideToolInvocations"],l);return t}function Mu(e,n){let t={},o=i(e,["retrievalConfig"]);if(o!=null)s(t,["retrievalConfig"],o);let r=i(e,["functionCallingConfig"]);if(r!=null)s(t,["functionCallingConfig"],r);if(i(e,["includeServerSideToolInvocations"])!==void 0)throw Error("includeServerSideToolInvocations parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return t}function Du(e,n){let t={};if(i(e,["retrieval"])!==void 0)throw Error("retrieval parameter is not supported in Gemini API.");let o=i(e,["computerUse"]);if(o!=null)s(t,["computerUse"],o);let r=i(e,["fileSearch"]);if(r!=null)s(t,["fileSearch"],r);let l=i(e,["googleSearch"]);if(l!=null)s(t,["googleSearch"],iu(l));let a=i(e,["googleMaps"]);if(a!=null)s(t,["googleMaps"],ou(a));let f=i(e,["codeExecution"]);if(f!=null)s(t,["codeExecution"],f);if(i(e,["enterpriseWebSearch"])!==void 0)throw Error("enterpriseWebSearch parameter is not supported in Gemini API.");let d=i(e,["functionDeclarations"]);if(d!=null){let g=d;if(Array.isArray(g))g=g.map((y)=>y);s(t,["functionDeclarations"],g)}let c=i(e,["googleSearchRetrieval"]);if(c!=null)s(t,["googleSearchRetrieval"],c);if(i(e,["parallelAiSearch"])!==void 0)throw Error("parallelAiSearch parameter is not supported in Gemini API.");let m=i(e,["urlContext"]);if(m!=null)s(t,["urlContext"],m);let p=i(e,["mcpServers"]);if(p!=null){let g=p;if(Array.isArray(g))g=g.map((y)=>y);s(t,["mcpServers"],g)}return t}function Ai(e,n){let t={},o=i(e,["retrieval"]);if(o!=null)s(t,["retrieval"],o);let r=i(e,["computerUse"]);if(r!=null)s(t,["computerUse"],r);if(i(e,["fileSearch"])!==void 0)throw Error("fileSearch parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");let l=i(e,["googleSearch"]);if(l!=null)s(t,["googleSearch"],l);let a=i(e,["googleMaps"]);if(a!=null)s(t,["googleMaps"],a);let f=i(e,["codeExecution"]);if(f!=null)s(t,["codeExecution"],f);let d=i(e,["enterpriseWebSearch"]);if(d!=null)s(t,["enterpriseWebSearch"],d);let c=i(e,["functionDeclarations"]);if(c!=null){let y=c;if(Array.isArray(y))y=y.map((E)=>Da(E));s(t,["functionDeclarations"],y)}let m=i(e,["googleSearchRetrieval"]);if(m!=null)s(t,["googleSearchRetrieval"],m);let p=i(e,["parallelAiSearch"]);if(p!=null)s(t,["parallelAiSearch"],p);let g=i(e,["urlContext"]);if(g!=null)s(t,["urlContext"],g);if(i(e,["mcpServers"])!==void 0)throw Error("mcpServers parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return t}function xu(e,n){let t={},o=i(e,["baseModel"]);if(o!=null)s(t,["baseModel"],o);let r=i(e,["createTime"]);if(r!=null)s(t,["createTime"],r);let l=i(e,["updateTime"]);if(l!=null)s(t,["updateTime"],l);return t}function Uu(e,n){let t={},o=i(e,["labels","google-vertex-llm-tuning-base-model-id"]);if(o!=null)s(t,["baseModel"],o);let r=i(e,["createTime"]);if(r!=null)s(t,["createTime"],r);let l=i(e,["updateTime"]);if(l!=null)s(t,["updateTime"],l);return t}function Lu(e,n,t){let o={},r=i(e,["displayName"]);if(n!==void 0&&r!=null)s(n,["displayName"],r);let l=i(e,["description"]);if(n!==void 0&&l!=null)s(n,["description"],l);let a=i(e,["defaultCheckpointId"]);if(n!==void 0&&a!=null)s(n,["defaultCheckpointId"],a);return o}function Gu(e,n,t){let o={},r=i(e,["displayName"]);if(n!==void 0&&r!=null)s(n,["displayName"],r);let l=i(e,["description"]);if(n!==void 0&&l!=null)s(n,["description"],l);let a=i(e,["defaultCheckpointId"]);if(n!==void 0&&a!=null)s(n,["defaultCheckpointId"],a);return o}function ku(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","name"],L(e,r));let l=i(n,["config"]);if(l!=null)Lu(l,o);return o}function Fu(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["config"]);if(l!=null)Gu(l,o);return o}function Vu(e,n,t){let o={},r=i(e,["outputGcsUri"]);if(n!==void 0&&r!=null)s(n,["parameters","storageUri"],r);let l=i(e,["safetyFilterLevel"]);if(n!==void 0&&l!=null)s(n,["parameters","safetySetting"],l);let a=i(e,["personGeneration"]);if(n!==void 0&&a!=null)s(n,["parameters","personGeneration"],a);let f=i(e,["includeRaiReason"]);if(n!==void 0&&f!=null)s(n,["parameters","includeRaiReason"],f);let d=i(e,["outputMimeType"]);if(n!==void 0&&d!=null)s(n,["parameters","outputOptions","mimeType"],d);let c=i(e,["outputCompressionQuality"]);if(n!==void 0&&c!=null)s(n,["parameters","outputOptions","compressionQuality"],c);let m=i(e,["enhanceInputImage"]);if(n!==void 0&&m!=null)s(n,["parameters","upscaleConfig","enhanceInputImage"],m);let p=i(e,["imagePreservationFactor"]);if(n!==void 0&&p!=null)s(n,["parameters","upscaleConfig","imagePreservationFactor"],p);let g=i(e,["labels"]);if(n!==void 0&&g!=null)s(n,["labels"],g);let y=i(e,["numberOfImages"]);if(n!==void 0&&y!=null)s(n,["parameters","sampleCount"],y);let E=i(e,["mode"]);if(n!==void 0&&E!=null)s(n,["parameters","mode"],E);return o}function qu(e,n,t){let o={},r=i(n,["model"]);if(r!=null)s(o,["_url","model"],L(e,r));let l=i(n,["image"]);if(l!=null)s(o,["instances[0]","image"],ee(l));let a=i(n,["upscaleFactor"]);if(a!=null)s(o,["parameters","upscaleConfig","upscaleFactor"],a);let f=i(n,["config"]);if(f!=null)Vu(f,o);return o}function Hu(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["predictions"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>on(a));s(t,["generatedImages"],l)}return t}function Bu(e,n){let t={},o=i(e,["uri"]);if(o!=null)s(t,["uri"],o);let r=i(e,["encodedVideo"]);if(r!=null)s(t,["videoBytes"],de(r));let l=i(e,["encoding"]);if(l!=null)s(t,["mimeType"],l);return t}function Ju(e,n){let t={},o=i(e,["gcsUri"]);if(o!=null)s(t,["uri"],o);let r=i(e,["bytesBase64Encoded"]);if(r!=null)s(t,["videoBytes"],de(r));let l=i(e,["mimeType"]);if(l!=null)s(t,["mimeType"],l);return t}function bu(e,n){let t={},o=i(e,["image"]);if(o!=null)s(t,["_self"],ee(o));let r=i(e,["maskMode"]);if(r!=null)s(t,["maskMode"],r);return t}function $u(e,n){let t={},o=i(e,["image"]);if(o!=null)s(t,["image"],rn(o));let r=i(e,["referenceType"]);if(r!=null)s(t,["referenceType"],r);return t}function Ou(e,n){let t={},o=i(e,["image"]);if(o!=null)s(t,["image"],ee(o));let r=i(e,["referenceType"]);if(r!=null)s(t,["referenceType"],r);return t}function vi(e,n){let t={},o=i(e,["uri"]);if(o!=null)s(t,["uri"],o);let r=i(e,["videoBytes"]);if(r!=null)s(t,["encodedVideo"],de(r));let l=i(e,["mimeType"]);if(l!=null)s(t,["encoding"],l);return t}function Si(e,n){let t={},o=i(e,["uri"]);if(o!=null)s(t,["gcsUri"],o);let r=i(e,["videoBytes"]);if(r!=null)s(t,["bytesBase64Encoded"],de(r));let l=i(e,["mimeType"]);if(l!=null)s(t,["mimeType"],l);return t}function Ku(e,n,t){let o={},r=i(n,["displayName"]);if(t!==void 0&&r!=null)s(t,["displayName"],r);let l=i(n,["embeddingModel"]);if(t!==void 0&&l!=null)s(t,["embeddingModel"],L(e,l));return o}function Yu(e,n){let t={},o=i(n,["config"]);if(o!=null)Ku(e,o,t);return t}function Wu(e,n){let t={},o=i(e,["force"]);if(n!==void 0&&o!=null)s(n,["_query","force"],o);return t}function zu(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["_url","name"],t);let o=i(e,["config"]);if(o!=null)Wu(o,n);return n}function Xu(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["_url","name"],t);return n}function Qu(e,n){let t={},o=i(e,["customMetadata"]);if(n!==void 0&&o!=null){let l=o;if(Array.isArray(l))l=l.map((a)=>a);s(n,["customMetadata"],l)}let r=i(e,["chunkingConfig"]);if(n!==void 0&&r!=null)s(n,["chunkingConfig"],r);return t}function Zu(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["name"],t);let o=i(e,["metadata"]);if(o!=null)s(n,["metadata"],o);let r=i(e,["done"]);if(r!=null)s(n,["done"],r);let l=i(e,["error"]);if(l!=null)s(n,["error"],l);let a=i(e,["response"]);if(a!=null)s(n,["response"],ed(a));return n}function ju(e){let n={},t=i(e,["fileSearchStoreName"]);if(t!=null)s(n,["_url","file_search_store_name"],t);let o=i(e,["fileName"]);if(o!=null)s(n,["fileName"],o);let r=i(e,["config"]);if(r!=null)Qu(r,n);return n}function ed(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["parent"]);if(o!=null)s(n,["parent"],o);let r=i(e,["documentName"]);if(r!=null)s(n,["documentName"],r);return n}function nd(e,n){let t={},o=i(e,["pageSize"]);if(n!==void 0&&o!=null)s(n,["_query","pageSize"],o);let r=i(e,["pageToken"]);if(n!==void 0&&r!=null)s(n,["_query","pageToken"],r);return t}function td(e){let n={},t=i(e,["config"]);if(t!=null)nd(t,n);return n}function od(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["nextPageToken"]);if(o!=null)s(n,["nextPageToken"],o);let r=i(e,["fileSearchStores"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>a);s(n,["fileSearchStores"],l)}return n}function Ri(e,n){let t={},o=i(e,["mimeType"]);if(n!==void 0&&o!=null)s(n,["mimeType"],o);let r=i(e,["displayName"]);if(n!==void 0&&r!=null)s(n,["displayName"],r);let l=i(e,["customMetadata"]);if(n!==void 0&&l!=null){let f=l;if(Array.isArray(f))f=f.map((d)=>d);s(n,["customMetadata"],f)}let a=i(e,["chunkingConfig"]);if(n!==void 0&&a!=null)s(n,["chunkingConfig"],a);return t}function id(e){let n={},t=i(e,["fileSearchStoreName"]);if(t!=null)s(n,["_url","file_search_store_name"],t);let o=i(e,["config"]);if(o!=null)Ri(o,n);return n}function rd(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);return n}var sd="Content-Type",ld="X-Server-Timeout",ad="User-Agent",Pn="x-goog-api-client",ud="1.52.0",dd=`google-genai-sdk/${ud}`,fd="v1beta1",cd="v1beta",pd=new Set(["us","eu"]),hd=5,md=[408,429,500,502,503,504];class Pi{constructor(e){var n,t,o;if(this.clientOptions=Object.assign({},e),this.customBaseUrl=(n=e.httpOptions)===null||n===void 0?void 0:n.baseUrl,this.clientOptions.vertexai){if(this.clientOptions.project&&this.clientOptions.location)this.clientOptions.apiKey=void 0;else if(this.clientOptions.apiKey)this.clientOptions.project=void 0,this.clientOptions.location=void 0}let r={};if(this.clientOptions.vertexai){if(!this.clientOptions.location&&!this.clientOptions.apiKey&&!this.customBaseUrl)this.clientOptions.location="global";if(!(this.clientOptions.project&&this.clientOptions.location||this.clientOptions.apiKey)&&!this.customBaseUrl)throw Error("Authentication is not set up. Please provide either a project and location, or an API key, or a custom base URL.");let a=e.project&&e.location||!!e.apiKey;if(this.customBaseUrl&&!a)r.baseUrl=this.customBaseUrl,this.clientOptions.project=void 0,this.clientOptions.location=void 0;else if(this.clientOptions.apiKey||this.clientOptions.location==="global")r.baseUrl="https://aiplatform.googleapis.com/";else if(this.clientOptions.project&&this.clientOptions.location&&pd.has(this.clientOptions.location))r.baseUrl=`https://aiplatform.${this.clientOptions.location}.rep.googleapis.com/`;else if(this.clientOptions.project&&this.clientOptions.location)r.baseUrl=`https://${this.clientOptions.location}-aiplatform.googleapis.com/`;r.apiVersion=(t=this.clientOptions.apiVersion)!==null&&t!==void 0?t:fd}else{if(!this.clientOptions.apiKey)console.warn("API key should be set when using the Gemini API.");r.apiVersion=(o=this.clientOptions.apiVersion)!==null&&o!==void 0?o:cd,r.baseUrl="https://generativelanguage.googleapis.com/"}if(r.headers=this.getDefaultHeaders(),this.clientOptions.httpOptions=r,e.httpOptions)this.clientOptions.httpOptions=this.patchHttpOptions(r,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(){let 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 Error("API version is not set.")}getBaseUrl(){if(this.clientOptions.httpOptions&&this.clientOptions.httpOptions.baseUrl!==void 0)return this.clientOptions.httpOptions.baseUrl;throw 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;else throw Error("Headers are not set.")}getRequestUrlInternal(e){if(!e||e.baseUrl===void 0||e.apiVersion===void 0)throw Error("HTTP options are not correctly set.");let t=[e.baseUrl.endsWith("/")?e.baseUrl.slice(0,-1):e.baseUrl];if(e.apiVersion&&e.apiVersion!=="")t.push(e.apiVersion);return t.join("/")}getBaseResourcePath(){return`projects/${this.clientOptions.project}/locations/${this.clientOptions.location}`}getApiKey(){return this.clientOptions.apiKey}getWebsocketBaseUrl(){let 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 Error("HTTP options are not correctly set.")}constructUrl(e,n,t){let o=[this.getRequestUrlInternal(n)];if(t)o.push(this.getBaseResourcePath());if(e!=="")o.push(e);return new URL(`${o.join("/")}`)}shouldPrependVertexProjectPath(e,n){if(n.baseUrl&&n.baseUrlResourceScope===Qe.COLLECTION)return!1;if(this.clientOptions.apiKey)return!1;if(!this.clientOptions.vertexai)return!1;if(e.path.startsWith("projects/"))return!1;if(e.httpMethod==="GET"&&e.path.startsWith("publishers/google/models"))return!1;return!0}async request(e){let n=this.clientOptions.httpOptions;if(e.httpOptions)n=this.patchHttpOptions(this.clientOptions.httpOptions,e.httpOptions);let t=this.shouldPrependVertexProjectPath(e,n),o=this.constructUrl(e.path,n,t);if(e.queryParams)for(let[l,a]of Object.entries(e.queryParams))o.searchParams.append(l,String(a));let r={};if(e.httpMethod==="GET"){if(e.body&&e.body!=="{}")throw Error("Request body should be empty for GET request, but got non empty request body")}else r.body=e.body;return r=await this.includeExtraHttpOptionsToRequestInit(r,n,o.toString(),e.abortSignal),this.unaryApiCall(o,r,e.httpMethod)}patchHttpOptions(e,n){let t=JSON.parse(JSON.stringify(e));for(let[o,r]of Object.entries(n))if(typeof r==="object")t[o]=Object.assign(Object.assign({},t[o]),r);else if(r!==void 0)t[o]=r;return t}async requestStream(e){let n=this.clientOptions.httpOptions;if(e.httpOptions)n=this.patchHttpOptions(this.clientOptions.httpOptions,e.httpOptions);let t=this.shouldPrependVertexProjectPath(e,n),o=this.constructUrl(e.path,n,t);if(!o.searchParams.has("alt")||o.searchParams.get("alt")!=="sse")o.searchParams.set("alt","sse");let r={};return r.body=e.body,r=await this.includeExtraHttpOptionsToRequestInit(r,n,o.toString(),e.abortSignal),this.streamApiCall(o,r,e.httpMethod)}async includeExtraHttpOptionsToRequestInit(e,n,t,o){if(n&&n.timeout||o){let r=new AbortController,l=r.signal;if(n.timeout&&(n===null||n===void 0?void 0:n.timeout)>0){let a=setTimeout(()=>r.abort(),n.timeout);if(a&&typeof a.unref==="function")a.unref()}if(o)o.addEventListener("abort",()=>{r.abort()});e.signal=l}if(n&&n.extraBody!==null)gd(e,n.extraBody);return e.headers=await this.getHeadersInternal(n,t),e}async unaryApiCall(e,n,t){return this.apiCall(e.toString(),Object.assign(Object.assign({},n),{method:t})).then(async(o)=>(await Co(o),new me(o))).catch((o)=>{if(o instanceof Error)throw o;else throw Error(JSON.stringify(o))})}async streamApiCall(e,n,t){return this.apiCall(e.toString(),Object.assign(Object.assign({},n),{method:t})).then(async(o)=>(await Co(o),this.processStreamResponse(o))).catch((o)=>{if(o instanceof Error)throw o;else throw Error(JSON.stringify(o))})}processStreamResponse(e){return Z(this,arguments,function*(){var t;let o=(t=e===null||e===void 0?void 0:e.body)===null||t===void 0?void 0:t.getReader(),r=new TextDecoder("utf-8");if(!o)throw Error("Response body is empty");try{let l="",a="data:",f=[`
3
+
4
+ `,"\r\r",`\r
5
+ \r
6
+ `];while(!0){let{done:d,value:c}=yield D(o.read());if(d){if(l.trim().length>0)throw Error("Incomplete JSON segment at the end");break}let m=r.decode(c,{stream:!0});try{let y=JSON.parse(m);if("error"in y){let E=JSON.parse(JSON.stringify(y.error)),{status:T,code:_}=E,C=`got status: ${T}. ${JSON.stringify(y)}`;if(_>=400&&_<600)throw new tn({message:C,status:_})}}catch(y){if(y.name==="ApiError")throw y}l+=m;let p=-1,g=0;while(!0){p=-1,g=0;for(let T of f){let _=l.indexOf(T);if(_!==-1&&(p===-1||_<p))p=_,g=T.length}if(p===-1)break;let y=l.substring(0,p);l=l.substring(p+g);let E=y.trim();if(E.startsWith(a)){let T=E.substring(a.length).trim();try{let _=new Response(T,{headers:e===null||e===void 0?void 0:e.headers,status:e===null||e===void 0?void 0:e.status,statusText:e===null||e===void 0?void 0:e.statusText});yield yield D(new me(_))}catch(_){throw Error(`exception parsing stream chunk ${T}. ${_}`)}}}}}finally{o.releaseLock()}})}async apiCall(e,n){var t;if(!this.clientOptions.httpOptions||!this.clientOptions.httpOptions.retryOptions)return fetch(e,n);let o=this.clientOptions.httpOptions.retryOptions;return Ze.default(async()=>{let l=await fetch(e,n);if(l.ok)return l;if(md.includes(l.status))throw Error(`Retryable HTTP Error: ${l.statusText}`);throw new Ze.AbortError(`Non-retryable exception ${l.statusText} sending request`)},{retries:((t=o.attempts)!==null&&t!==void 0?t:hd)-1})}getDefaultHeaders(){let e={},n=dd+" "+this.clientOptions.userAgentExtra;return e[ad]=n,e[Pn]=n,e[sd]="application/json",e}async getHeadersInternal(e,n){let t=new Headers;if(e&&e.headers){for(let[o,r]of Object.entries(e.headers))t.append(o,r);if(e.timeout&&e.timeout>0)t.append(ld,String(Math.ceil(e.timeout/1000)))}return await this.clientOptions.auth.addAuthHeaders(t,n),t}getFileName(e){var n;let t="";if(typeof e==="string")t=e.replace(/[/\\]+$/,""),t=(n=t.split(/[/\\]/).pop())!==null&&n!==void 0?n:"";return t}async uploadFile(e,n){var t;let o={};if(n!=null)o.mimeType=n.mimeType,o.name=n.name,o.displayName=n.displayName;if(o.name&&!o.name.startsWith("files/"))o.name=`files/${o.name}`;let r=this.clientOptions.uploader,l=await r.stat(e);o.sizeBytes=String(l.size);let a=(t=n===null||n===void 0?void 0:n.mimeType)!==null&&t!==void 0?t:l.type;if(a===void 0||a==="")throw Error("Can not determine mimeType. Please provide mimeType in the config.");o.mimeType=a;let f={file:o},d=this.getFileName(e),c=S("upload/v1beta/files",f._url),m=await this.fetchUploadUrl(c,o.sizeBytes,o.mimeType,d,f,n===null||n===void 0?void 0:n.httpOptions);return r.upload(e,m,this)}async uploadFileToFileSearchStore(e,n,t){var o;let r=this.clientOptions.uploader,l=await r.stat(n),a=String(l.size),f=(o=t===null||t===void 0?void 0:t.mimeType)!==null&&o!==void 0?o:l.type;if(f===void 0||f==="")throw Error("Can not determine mimeType. Please provide mimeType in the config.");let d=`upload/v1beta/${e}:uploadToFileSearchStore`,c=this.getFileName(n),m={};if(t!=null)Ri(t,m);let p=await this.fetchUploadUrl(d,a,f,c,m,t===null||t===void 0?void 0:t.httpOptions);return r.uploadToFileSearchStore(n,p,this)}async downloadFile(e){await this.clientOptions.downloader.download(e,this)}async fetchUploadUrl(e,n,t,o,r,l){var a;let f={};if(l)f=l;else f={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":`${t}`},o?{"X-Goog-Upload-File-Name":o}:{})};let d=await this.request({path:e,body:JSON.stringify(r),httpMethod:"POST",httpOptions:f});if(!d||!(d===null||d===void 0?void 0:d.headers))throw Error("Server did not return an HttpResponse or the returned HttpResponse did not have headers.");let c=(a=d===null||d===void 0?void 0:d.headers)===null||a===void 0?void 0:a["x-goog-upload-url"];if(c===void 0)throw Error("Failed to get upload url. Server did not return the x-google-upload-url in the headers");return c}}async function Co(e){var n;if(e===void 0)throw Error("response is undefined");if(!e.ok){let t=e.status,o;if((n=e.headers.get("content-type"))===null||n===void 0?void 0:n.includes("application/json"))o=await e.json();else o={error:{message:await e.text(),code:e.status,status:e.statusText}};let r=JSON.stringify(o);if(t>=400&&t<600)throw new tn({message:r,status:t});throw Error(r)}}function gd(e,n){if(!n||Object.keys(n).length===0)return;if(e.body instanceof Blob){console.warn("includeExtraBodyToRequestInit: extraBody provided but current request body is a Blob. extraBody will be ignored as merging is not supported for Blob bodies.");return}let t={};if(typeof e.body==="string"&&e.body.length>0)try{let l=JSON.parse(e.body);if(typeof l==="object"&&l!==null&&!Array.isArray(l))t=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(l){console.warn("includeExtraBodyToRequestInit: Original request body is not valid JSON. Skip applying extraBody to the request body.");return}function o(l,a){let f=Object.assign({},l);for(let d in a)if(Object.prototype.hasOwnProperty.call(a,d)){let c=a[d],m=f[d];if(c&&typeof c==="object"&&!Array.isArray(c)&&m&&typeof m==="object"&&!Array.isArray(m))f[d]=o(m,c);else{if(m&&c&&typeof m!==typeof c)console.warn(`includeExtraBodyToRequestInit:deepMerge: Type mismatch for key "${d}". Original type: ${typeof m}, New type: ${typeof c}. Overwriting.`);f[d]=c}}return f}let r=o(t,n);e.body=JSON.stringify(r)}var yd="mcp_used/unknown",Ed=!1;function wi(e){for(let n of e){if(Td(n))return!0;if(typeof n==="object"&&"inputSchema"in n)return!0}return Ed}function Ni(e){var n;let t=(n=e[Pn])!==null&&n!==void 0?n:"";e[Pn]=(t+` ${yd}`).trimStart()}function Td(e){return e!==null&&typeof e==="object"&&e instanceof Bn}function _d(e){return Z(this,arguments,function*(t,o=100){let r=void 0,l=0;while(l<o){let a=yield D(t.listTools({cursor:r}));for(let f of a.tools)yield yield D(f),l++;if(!a.nextCursor)break;r=a.nextCursor}})}class Bn{constructor(e=[],n){this.mcpTools=[],this.functionNameToMcpClient={},this.mcpClients=e,this.config=n}static create(e,n){return new Bn(e,n)}async initialize(){var e,n,t,o;if(this.mcpTools.length>0)return;let r={},l=[];for(let c of this.mcpClients)try{for(var a=!0,f=(n=void 0,j(_d(c))),d;d=await f.next(),e=d.done,!e;a=!0){o=d.value,a=!1;let m=o;l.push(m);let p=m.name;if(r[p])throw Error(`Duplicate function name ${p} found in MCP tools. Please ensure function names are unique.`);r[p]=c}}catch(m){n={error:m}}finally{try{if(!a&&!e&&(t=f.return))await t.call(f)}finally{if(n)throw n.error}}this.mcpTools=l,this.functionNameToMcpClient=r}async tool(){return await this.initialize(),Vr(this.mcpTools,this.config)}async callTool(e){await this.initialize();let n=[];for(let t of e)if(t.name in this.functionNameToMcpClient){let o=this.functionNameToMcpClient[t.name],r=void 0;if(this.config.timeout)r={timeout:this.config.timeout};let l=await o.callTool({name:t.name,arguments:t.args},void 0,r);n.push({functionResponse:{name:t.name,response:l.isError?{error:l}:l}})}return n}}async function Id(e,n,t){let o=new jo,r;if(t.data instanceof Blob)r=JSON.parse(await t.data.text());else r=JSON.parse(t.data);Object.assign(o,r),n(o)}class Mi{constructor(e,n,t){this.apiClient=e,this.auth=n,this.webSocketFactory=t}async connect(e){var n,t;if(this.apiClient.isVertexAI())throw Error("Live music is not supported for Vertex AI.");console.warn("Live music generation is experimental and may change in future versions.");let o=this.apiClient.getWebsocketBaseUrl(),r=this.apiClient.getApiVersion(),l=Ad(this.apiClient.getDefaultHeaders()),a=this.apiClient.getApiKey(),f=`${o}/ws/google.ai.generativelanguage.${r}.GenerativeService.BidiGenerateMusic?key=${a}`,d=()=>{},c=new Promise((v)=>{d=v}),m=e.callbacks,p=function(){d({})},g=this.apiClient,y={onopen:p,onmessage:(v)=>{Id(g,m.onmessage,v)},onerror:(n=m===null||m===void 0?void 0:m.onerror)!==null&&n!==void 0?n:function(v){},onclose:(t=m===null||m===void 0?void 0:m.onclose)!==null&&t!==void 0?t:function(v){}},E=this.webSocketFactory.create(f,Cd(l),y);E.connect(),await c;let C={setup:{model:L(this.apiClient,e.model)}};return E.send(JSON.stringify(C)),new Di(E,this.apiClient)}}class Di{constructor(e,n){this.conn=e,this.apiClient=n}async setWeightedPrompts(e){if(!e.weightedPrompts||Object.keys(e.weightedPrompts).length===0)throw Error("Weighted prompts must be set and contain at least one entry.");let n=Bl(e);this.conn.send(JSON.stringify({clientContent:n}))}async setMusicGenerationConfig(e){if(!e.musicGenerationConfig)e.musicGenerationConfig={};let n=Hl(e);this.conn.send(JSON.stringify(n))}sendPlaybackControl(e){let n={playbackControl:e};this.conn.send(JSON.stringify(n))}play(){this.sendPlaybackControl(ye.PLAY)}pause(){this.sendPlaybackControl(ye.PAUSE)}stop(){this.sendPlaybackControl(ye.STOP)}resetContext(){this.sendPlaybackControl(ye.RESET_CONTEXT)}close(){this.conn.close()}}function Cd(e){let n={};return e.forEach((t,o)=>{n[o]=t}),n}function Ad(e){let n=new Headers;for(let[t,o]of Object.entries(e))n.append(t,o);return n}var vd="FunctionResponse request must have an `id` field from the response of a ToolCall.FunctionalCalls in Google AI.";async function Sd(e,n,t){let o=new Zo,r;if(t.data instanceof Blob)r=await t.data.text();else if(t.data instanceof ArrayBuffer)r=new TextDecoder().decode(t.data);else r=t.data;let l=JSON.parse(r);if(e.isVertexAI()){let a=$l(l);Object.assign(o,a)}else Object.assign(o,l);n(o)}class xi{constructor(e,n,t){this.apiClient=e,this.auth=n,this.webSocketFactory=t,this.music=new Mi(this.apiClient,this.auth,this.webSocketFactory)}async connect(e){var n,t,o,r,l,a;if(e.config&&e.config.httpOptions)throw Error("The Live module does not support httpOptions at request-level in LiveConnectConfig yet. Please use the client-level httpOptions configuration instead.");let f=this.apiClient.getWebsocketBaseUrl(),d=this.apiClient.getApiVersion(),c,m=this.apiClient.getHeaders();if(e.config&&e.config.tools&&wi(e.config.tools))Ni(m);let p=wd(m);if(this.apiClient.isVertexAI()){let A=this.apiClient.getProject(),M=this.apiClient.getLocation(),G=this.apiClient.getApiKey(),K=!!A&&!!M||!!G;if(this.apiClient.getCustomBaseUrl()&&!K)c=f;else c=`${f}/ws/google.cloud.aiplatform.${d}.LlmBidiService/BidiGenerateContent`,await this.auth.addAuthHeaders(p,c)}else{let A=this.apiClient.getApiKey(),M="BidiGenerateContent",G="key";if(A===null||A===void 0?void 0:A.startsWith("auth_tokens/")){if(console.warn("Warning: Ephemeral token support is experimental and may change in future versions."),d!=="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.");M="BidiGenerateContentConstrained",G="access_token"}c=`${f}/ws/google.ai.generativelanguage.${d}.GenerativeService.${M}?${G}=${A}`}let g=()=>{},y=new Promise((A)=>{g=A}),E=e.callbacks,T=function(){var A;(A=E===null||E===void 0?void 0:E.onopen)===null||A===void 0||A.call(E),g({})},_=this.apiClient,C={onopen:T,onmessage:(A)=>{Sd(_,E.onmessage,A)},onerror:(n=E===null||E===void 0?void 0:E.onerror)!==null&&n!==void 0?n:function(A){},onclose:(t=E===null||E===void 0?void 0:E.onclose)!==null&&t!==void 0?t:function(A){}},v=this.webSocketFactory.create(c,Pd(p),C);v.connect(),await y;let R=L(this.apiClient,e.model);if(this.apiClient.isVertexAI()&&R.startsWith("publishers/")){let A=this.apiClient.getProject(),M=this.apiClient.getLocation();if(A&&M)R=`projects/${A}/locations/${M}/`+R}let P={};if(this.apiClient.isVertexAI()&&((o=e.config)===null||o===void 0?void 0:o.responseModalities)===void 0)if(e.config===void 0)e.config={responseModalities:[$e.AUDIO]};else e.config.responseModalities=[$e.AUDIO];if((r=e.config)===null||r===void 0?void 0:r.generationConfig)console.warn("Setting `LiveConnectConfig.generation_config` is deprecated, please set the fields on `LiveConnectConfig` directly. This will become an error in a future version (not before Q3 2025).");let x=(a=(l=e.config)===null||l===void 0?void 0:l.tools)!==null&&a!==void 0?a:[],I=[];for(let A of x)if(this.isCallableTool(A)){let M=A;I.push(await M.tool())}else I.push(A);if(I.length>0)e.config.tools=I;let U={model:R,config:e.config,callbacks:e.callbacks};if(this.apiClient.isVertexAI())P=ql(this.apiClient,U);else P=Vl(this.apiClient,U);return delete P.config,v.send(JSON.stringify(P)),new Ui(v,this.apiClient)}isCallableTool(e){return"callTool"in e&&typeof e.callTool==="function"}}var Rd={turnComplete:!0};class Ui{constructor(e,n){this.conn=e,this.apiClient=n}tLiveClientContent(e,n){if(n.turns!==null&&n.turns!==void 0){let t=[];try{if(t=O(n.turns),!e.isVertexAI())t=t.map((o)=>Ue(o))}catch(o){throw Error(`Failed to parse client content "turns", type: '${typeof n.turns}'`)}return{clientContent:{turns:t,turnComplete:n.turnComplete}}}return{clientContent:{turnComplete:n.turnComplete}}}tLiveClienttToolResponse(e,n){let t=[];if(n.functionResponses==null)throw Error("functionResponses is required.");if(!Array.isArray(n.functionResponses))t=[n.functionResponses];else t=n.functionResponses;if(t.length===0)throw Error("functionResponses is required.");for(let r of t){if(typeof r!=="object"||r===null||!("name"in r)||!("response"in r))throw Error(`Could not parse function response, type '${typeof r}'.`);if(!e.isVertexAI()&&!("id"in r))throw Error(vd)}return{toolResponse:{functionResponses:t}}}sendClientContent(e){e=Object.assign(Object.assign({},Rd),e);let n=this.tLiveClientContent(this.apiClient,e);this.conn.send(JSON.stringify(n))}sendRealtimeInput(e){let n={};if(this.apiClient.isVertexAI())n={realtimeInput:bl(e)};else n={realtimeInput:Jl(e)};this.conn.send(JSON.stringify(n))}sendToolResponse(e){if(e.functionResponses==null)throw Error("Tool response parameters are required.");let n=this.tLiveClienttToolResponse(this.apiClient,e);this.conn.send(JSON.stringify(n))}close(){this.conn.close()}}function Pd(e){let n={};return e.forEach((t,o)=>{n[o]=t}),n}function wd(e){let n=new Headers;for(let[t,o]of Object.entries(e))n.append(t,o);return n}var Ao=10;function vo(e){var n,t,o;if((n=e===null||e===void 0?void 0:e.automaticFunctionCalling)===null||n===void 0?void 0:n.disable)return!0;let r=!1;for(let a of(t=e===null||e===void 0?void 0:e.tools)!==null&&t!==void 0?t:[])if(_e(a)){r=!0;break}if(!r)return!0;let l=(o=e===null||e===void 0?void 0:e.automaticFunctionCalling)===null||o===void 0?void 0:o.maximumRemoteCalls;if(l&&(l<0||!Number.isInteger(l))||l==0)return 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;return!1}function _e(e){return"callTool"in e&&typeof e.callTool==="function"}function Nd(e){var n,t,o;return(o=(t=(n=e.config)===null||n===void 0?void 0:n.tools)===null||t===void 0?void 0:t.some((r)=>_e(r)))!==null&&o!==void 0?o:!1}function So(e){var n;let t=[];if(!((n=e===null||e===void 0?void 0:e.config)===null||n===void 0?void 0:n.tools))return t;return e.config.tools.forEach((o,r)=>{if(_e(o))return;let l=o;if(l.functionDeclarations&&l.functionDeclarations.length>0)t.push(r)}),t}function Ro(e){var n;return!((n=e===null||e===void 0?void 0:e.automaticFunctionCalling)===null||n===void 0?void 0:n.ignoreCallHistory)}class Li extends ne{constructor(e){super();this.apiClient=e,this.embedContent=async(n)=>{if(!this.apiClient.isVertexAI()){if(n.model.includes("gemini-embedding-2"))n.contents=O(n.contents);return await this.embedContentInternal(n)}if(n.model.includes("gemini")&&n.model!=="gemini-embedding-001"||n.model.includes("maas")){let o=O(n.contents);if(o.length>1)throw Error("The embedContent API for this model only supports one content at a time.");let r=Object.assign(Object.assign({},n),{content:o[0],embeddingApiType:Oe.EMBED_CONTENT});return await this.embedContentInternal(r)}else{let o=Object.assign(Object.assign({},n),{embeddingApiType:Oe.PREDICT});return await this.embedContentInternal(o)}},this.generateContent=async(n)=>{var t,o,r,l,a;let f=await this.processParamsMaybeAddMcpUsage(n);if(this.maybeMoveToResponseJsonSchem(n),!Nd(n)||vo(n.config))return await this.generateContentInternal(f);let d=So(n);if(d.length>0){let E=d.map((T)=>`tools[${T}]`).join(", ");throw Error(`Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations is not yet supported. Incompatible tools found at ${E}.`)}let c,m,p=O(f.contents),g=(r=(o=(t=f.config)===null||t===void 0?void 0:t.automaticFunctionCalling)===null||o===void 0?void 0:o.maximumRemoteCalls)!==null&&r!==void 0?r:Ao,y=0;while(y<g){if(c=await this.generateContentInternal(f),!c.functionCalls||c.functionCalls.length===0)break;let E=c.candidates[0].content,T=[];for(let _ of(a=(l=n.config)===null||l===void 0?void 0:l.tools)!==null&&a!==void 0?a:[])if(_e(_)){let v=await _.callTool(c.functionCalls);T.push(...v)}if(y++,m={role:"user",parts:T},f.contents=O(f.contents),f.contents.push(E),f.contents.push(m),Ro(f.config))p.push(E),p.push(m)}if(Ro(f.config))c.automaticFunctionCallingHistory=p;return c},this.generateContentStream=async(n)=>{var t,o,r,l,a;if(this.maybeMoveToResponseJsonSchem(n),vo(n.config)){let m=await this.processParamsMaybeAddMcpUsage(n);return await this.generateContentStreamInternal(m)}let f=So(n);if(f.length>0){let m=f.map((p)=>`tools[${p}]`).join(", ");throw Error(`Incompatible tools found at ${m}. Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations" is not yet supported.`)}let d=(r=(o=(t=n===null||n===void 0?void 0:n.config)===null||t===void 0?void 0:t.toolConfig)===null||o===void 0?void 0:o.functionCallingConfig)===null||r===void 0?void 0:r.streamFunctionCallArguments,c=(a=(l=n===null||n===void 0?void 0:n.config)===null||l===void 0?void 0:l.automaticFunctionCalling)===null||a===void 0?void 0:a.disable;if(d&&!c)throw Error("Running in streaming mode with 'streamFunctionCallArguments' enabled, this feature is not compatible with automatic function calling (AFC). Please set 'config.automaticFunctionCalling.disable' to true to disable AFC or leave 'config.toolConfig.functionCallingConfig.streamFunctionCallArguments' to be undefined or set to false to disable streaming function call arguments feature.");return await this.processAfcStream(n)},this.generateImages=async(n)=>await this.generateImagesInternal(n).then((t)=>{var o;let r,l=[];if(t===null||t===void 0?void 0:t.generatedImages)for(let f of t.generatedImages)if(f&&(f===null||f===void 0?void 0:f.safetyAttributes)&&((o=f===null||f===void 0?void 0:f.safetyAttributes)===null||o===void 0?void 0:o.contentType)==="Positive Prompt")r=f===null||f===void 0?void 0:f.safetyAttributes;else l.push(f);let a;if(r)a={generatedImages:l,positivePromptSafetyAttributes:r,sdkHttpResponse:t.sdkHttpResponse};else a={generatedImages:l,sdkHttpResponse:t.sdkHttpResponse};return a}),this.list=async(n)=>{var t;let l={config:Object.assign(Object.assign({},{queryBase:!0}),n===null||n===void 0?void 0:n.config)};if(this.apiClient.isVertexAI()){if(!l.config.queryBase)if((t=l.config)===null||t===void 0?void 0:t.filter)throw Error("Filtering tuned models list for Gemini Enterprise Agent Platform (previously known as Vertex AI) is not currently supported");else l.config.filter="labels.tune-type:*"}return new fe(oe.PAGED_ITEM_MODELS,(a)=>this.listInternal(a),await this.listInternal(l),l)},this.editImage=async(n)=>{let t={model:n.model,prompt:n.prompt,referenceImages:[],config:n.config};if(n.referenceImages){if(n.referenceImages)t.referenceImages=n.referenceImages.map((o)=>o.toReferenceImageAPI())}return await this.editImageInternal(t)},this.upscaleImage=async(n)=>{let t={numberOfImages:1,mode:"upscale"};if(n.config)t=Object.assign(Object.assign({},t),n.config);let o={model:n.model,image:n.image,upscaleFactor:n.upscaleFactor,config:t};return await this.upscaleImageInternal(o)},this.generateVideos=async(n)=>{var t,o,r,l,a,f;if((n.prompt||n.image||n.video)&&n.source)throw Error("Source and prompt/image/video are mutually exclusive. Please only use source.");if(!this.apiClient.isVertexAI()){if(((t=n.video)===null||t===void 0?void 0:t.uri)&&((o=n.video)===null||o===void 0?void 0:o.videoBytes))n.video={uri:n.video.uri,mimeType:n.video.mimeType};else if(((l=(r=n.source)===null||r===void 0?void 0:r.video)===null||l===void 0?void 0:l.uri)&&((f=(a=n.source)===null||a===void 0?void 0:a.video)===null||f===void 0?void 0:f.videoBytes))n.source.video={uri:n.source.video.uri,mimeType:n.source.video.mimeType}}return await this.generateVideosInternal(n)}}maybeMoveToResponseJsonSchem(e){if(e.config&&e.config.responseSchema){if(!e.config.responseJsonSchema){if(Object.keys(e.config.responseSchema).includes("$schema"))e.config.responseJsonSchema=e.config.responseSchema,delete e.config.responseSchema}}return}async processParamsMaybeAddMcpUsage(e){var n,t,o;let r=(n=e.config)===null||n===void 0?void 0:n.tools;if(!r)return e;let l=await Promise.all(r.map(async(f)=>{if(_e(f))return await f.tool();return f})),a={model:e.model,contents:e.contents,config:Object.assign(Object.assign({},e.config),{tools:l})};if(a.config.tools=l,e.config&&e.config.tools&&wi(e.config.tools)){let f=(o=(t=e.config.httpOptions)===null||t===void 0?void 0:t.headers)!==null&&o!==void 0?o:{},d=Object.assign({},f);if(Object.keys(d).length===0)d=this.apiClient.getDefaultHeaders();Ni(d),a.config.httpOptions=Object.assign(Object.assign({},e.config.httpOptions),{headers:d})}return a}async initAfcToolsMap(e){var n,t,o;let r=new Map;for(let l of(t=(n=e.config)===null||n===void 0?void 0:n.tools)!==null&&t!==void 0?t:[])if(_e(l)){let a=l,f=await a.tool();for(let d of(o=f.functionDeclarations)!==null&&o!==void 0?o:[]){if(!d.name)throw Error("Function declaration name is required.");if(r.has(d.name))throw Error(`Duplicate tool declaration name: ${d.name}`);r.set(d.name,a)}}return r}async processAfcStream(e){var n,t,o;let r=(o=(t=(n=e.config)===null||n===void 0?void 0:n.automaticFunctionCalling)===null||t===void 0?void 0:t.maximumRemoteCalls)!==null&&o!==void 0?o:Ao,l=!1,a=0,f=await this.initAfcToolsMap(e);return function(d,c,m){return Z(this,arguments,function*(){var p,g,y,E,T,_;while(a<r){if(l)a++,l=!1;let P=yield D(d.processParamsMaybeAddMcpUsage(m)),x=yield D(d.generateContentStreamInternal(P)),I=[],U=[];try{for(var C=!0,v=(g=void 0,j(x)),R;R=yield D(v.next()),p=R.done,!p;C=!0){E=R.value,C=!1;let A=E;if(yield yield D(A),A.candidates&&((T=A.candidates[0])===null||T===void 0?void 0:T.content)){U.push(A.candidates[0].content);for(let M of(_=A.candidates[0].content.parts)!==null&&_!==void 0?_:[])if(a<r&&M.functionCall){if(!M.functionCall.name)throw Error("Function call name was not returned by the model.");if(!c.has(M.functionCall.name))throw Error(`Automatic function calling was requested, but not all the tools the model used implement the CallableTool interface. Available tools: ${c.keys()}, mising tool: ${M.functionCall.name}`);else{let G=yield D(c.get(M.functionCall.name).callTool([M.functionCall]));I.push(...G)}}}}}catch(A){g={error:A}}finally{try{if(!C&&!p&&(y=v.return))yield D(y.call(v))}finally{if(g)throw g.error}}if(I.length>0){l=!0;let A=new ge;A.candidates=[{content:{role:"user",parts:I}}],yield yield D(A);let M=[];M.push(...U),M.push({role:"user",parts:I});let G=O(m.contents).concat(M);m.contents=G}else break}})}(this,f,e)}async generateContentInternal(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=To(this.apiClient,e);return a=S("{model}:generateContent",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=Io(c),p=new ge;return Object.assign(p,m),p})}else{let d=Eo(this.apiClient,e);return a=S("{model}:generateContent",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=_o(c),p=new ge;return Object.assign(p,m),p})}}async generateContentStreamInternal(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=To(this.apiClient,e);return a=S("{model}:streamGenerateContent?alt=sse",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.requestStream({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}),l.then(function(m){return Z(this,arguments,function*(){var p,g,y,E;try{for(var T=!0,_=j(m),C;C=yield D(_.next()),p=C.done,!p;T=!0){E=C.value,T=!1;let v=E,R=Io(yield D(v.json()),e);R.sdkHttpResponse={headers:v.headers};let P=new ge;Object.assign(P,R),yield yield D(P)}}catch(v){g={error:v}}finally{try{if(!T&&!p&&(y=_.return))yield D(y.call(_))}finally{if(g)throw g.error}}})})}else{let d=Eo(this.apiClient,e);return a=S("{model}:streamGenerateContent?alt=sse",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.requestStream({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}),l.then(function(m){return Z(this,arguments,function*(){var p,g,y,E;try{for(var T=!0,_=j(m),C;C=yield D(_.next()),p=C.done,!p;T=!0){E=C.value,T=!1;let v=E,R=_o(yield D(v.json()),e);R.sdkHttpResponse={headers:v.headers};let P=new ge;Object.assign(P,R),yield yield D(P)}}catch(v){g={error:v}}finally{try{if(!T&&!p&&(y=_.return))yield D(y.call(_))}finally{if(g)throw g.error}}})})}}async embedContentInternal(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=va(this.apiClient,e,e),c=Hr(e.model)?"{model}:embedContent":"{model}:predict";return a=S(c,d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((m)=>m.json().then((p)=>{let g=p;return g.sdkHttpResponse={headers:m.headers},g})),l.then((m)=>{let p=Ra(m,e),g=new hn;return Object.assign(g,p),g})}else{let d=Aa(this.apiClient,e);return a=S("{model}:batchEmbedContents",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=Sa(c),p=new hn;return Object.assign(p,m),p})}}async generateImagesInternal(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=Fa(this.apiClient,e);return a=S("{model}:predict",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=qa(c),p=new mn;return Object.assign(p,m),p})}else{let d=ka(this.apiClient,e);return a=S("{model}:predict",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=Va(c),p=new mn;return Object.assign(p,m),p})}}async editImageInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI()){let a=Ta(this.apiClient,e);return r=S("{model}:predict",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json().then((d)=>{let c=d;return c.sdkHttpResponse={headers:f.headers},c})),o.then((f)=>{let d=_a(f),c=new qo;return Object.assign(c,d),c})}else throw Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async upscaleImageInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI()){let a=qu(this.apiClient,e);return r=S("{model}:predict",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json().then((d)=>{let c=d;return c.sdkHttpResponse={headers:f.headers},c})),o.then((f)=>{let d=Hu(f),c=new Ho;return Object.assign(c,d),c})}else throw Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async recontextImage(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI()){let a=Tu(this.apiClient,e);return r=S("{model}:predict",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>{let d=_u(f),c=new Bo;return Object.assign(c,d),c})}else throw Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async segmentImage(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI()){let a=Ru(this.apiClient,e);return r=S("{model}:predict",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>{let d=Pu(f),c=new Jo;return Object.assign(c,d),c})}else throw Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async get(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=tu(this.apiClient,e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json()),l.then((c)=>Rn(c))}else{let d=nu(this.apiClient,e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json()),l.then((c)=>Sn(c))}}async listInternal(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=fu(this.apiClient,e);return a=S("{models_url}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=pu(c),p=new gn;return Object.assign(p,m),p})}else{let d=du(this.apiClient,e);return a=S("{models_url}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=cu(c),p=new gn;return Object.assign(p,m),p})}}async update(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=Fu(this.apiClient,e);return a=S("{model}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"PATCH",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json()),l.then((c)=>Rn(c))}else{let d=ku(this.apiClient,e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"PATCH",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json()),l.then((c)=>Sn(c))}}async delete(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=ma(this.apiClient,e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=ya(c),p=new yn;return Object.assign(p,m),p})}else{let d=ha(this.apiClient,e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=ga(c),p=new yn;return Object.assign(p,m),p})}}async countTokens(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=fa(this.apiClient,e);return a=S("{model}:countTokens",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=pa(c),p=new En;return Object.assign(p,m),p})}else{let d=da(this.apiClient,e);return a=S("{model}:countTokens",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=ca(c),p=new En;return Object.assign(p,m),p})}}async computeTokens(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI()){let a=oa(this.apiClient,e);return r=S("{model}:computeTokens",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json().then((d)=>{let c=d;return c.sdkHttpResponse={headers:f.headers},c})),o.then((f)=>{let d=ia(f),c=new bo;return Object.assign(c,d),c})}else throw Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async generateVideosInternal(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=Oa(this.apiClient,e);return a=S("{model}:predictLongRunning",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json()),l.then((c)=>{let m=ba(c),p=new Ke;return Object.assign(p,m),p})}else{let d=$a(this.apiClient,e);return a=S("{model}:predictLongRunning",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json()),l.then((c)=>{let m=Ja(c),p=new Ke;return Object.assign(p,m),p})}}}class Gi extends ne{constructor(e){super();this.apiClient=e}async getVideosOperation(e){let{operation:n,config:t}=e;if(n.name===void 0||n.name==="")throw Error("Operation name is required.");if(this.apiClient.isVertexAI()){let o=n.name.split("/operations/")[0],r=void 0;if(t&&"httpOptions"in t)r=t.httpOptions;let l=await this.fetchPredictVideosOperationInternal({operationName:n.name,resourceName:o,config:{httpOptions:r}});return n._fromAPIResponse({apiResponse:l,_isVertexAI:!0})}else{let o=await this.getVideosOperationInternal({operationName:n.name,config:t});return n._fromAPIResponse({apiResponse:o,_isVertexAI:!1})}}async get(e){let{operation:n,config:t}=e;if(n.name===void 0||n.name==="")throw Error("Operation name is required.");if(this.apiClient.isVertexAI()){let o=n.name.split("/operations/")[0],r=void 0;if(t&&"httpOptions"in t)r=t.httpOptions;let l=await this.fetchPredictVideosOperationInternal({operationName:n.name,resourceName:o,config:{httpOptions:r}});return n._fromAPIResponse({apiResponse:l,_isVertexAI:!0})}else{let o=await this.getVideosOperationInternal({operationName:n.name,config:t});return n._fromAPIResponse({apiResponse:o,_isVertexAI:!1})}}async getVideosOperationInternal(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=Pr(e);return a=S("{operationName}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json()),l}else{let d=Rr(e);return a=S("{operationName}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json()),l}}async fetchPredictVideosOperationInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI()){let a=Tr(e);return r=S("{resourceName}:fetchPredictOperation",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o}else throw Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}}function Po(e){let n={};if(i(e,["languageCodes"])!==void 0)throw Error("languageCodes parameter is not supported in Gemini API.");return n}function Md(e){let n={},t=i(e,["apiKey"]);if(t!=null)s(n,["apiKey"],t);if(i(e,["apiKeyConfig"])!==void 0)throw Error("apiKeyConfig parameter is not supported in Gemini API.");if(i(e,["authType"])!==void 0)throw Error("authType parameter is not supported in Gemini API.");if(i(e,["googleServiceAccountConfig"])!==void 0)throw Error("googleServiceAccountConfig parameter is not supported in Gemini API.");if(i(e,["httpBasicAuthConfig"])!==void 0)throw Error("httpBasicAuthConfig parameter is not supported in Gemini API.");if(i(e,["oauthConfig"])!==void 0)throw Error("oauthConfig parameter is not supported in Gemini API.");if(i(e,["oidcConfig"])!==void 0)throw Error("oidcConfig parameter is not supported in Gemini API.");return n}function Dd(e){let n={},t=i(e,["data"]);if(t!=null)s(n,["data"],t);if(i(e,["displayName"])!==void 0)throw Error("displayName parameter is not supported in Gemini API.");let o=i(e,["mimeType"]);if(o!=null)s(n,["mimeType"],o);return n}function xd(e){let n={},t=i(e,["parts"]);if(t!=null){let r=t;if(Array.isArray(r))r=r.map((l)=>Bd(l));s(n,["parts"],r)}let o=i(e,["role"]);if(o!=null)s(n,["role"],o);return n}function Ud(e,n,t){let o={},r=i(n,["expireTime"]);if(t!==void 0&&r!=null)s(t,["expireTime"],r);let l=i(n,["newSessionExpireTime"]);if(t!==void 0&&l!=null)s(t,["newSessionExpireTime"],l);let a=i(n,["uses"]);if(t!==void 0&&a!=null)s(t,["uses"],a);let f=i(n,["liveConnectConstraints"]);if(t!==void 0&&f!=null)s(t,["bidiGenerateContentSetup"],Hd(e,f));let d=i(n,["lockAdditionalFields"]);if(t!==void 0&&d!=null)s(t,["fieldMask"],d);return o}function Ld(e,n){let t={},o=i(n,["config"]);if(o!=null)s(t,["config"],Ud(e,o,t));return t}function Gd(e){let n={};if(i(e,["displayName"])!==void 0)throw Error("displayName parameter is not supported in Gemini API.");let t=i(e,["fileUri"]);if(t!=null)s(n,["fileUri"],t);let o=i(e,["mimeType"]);if(o!=null)s(n,["mimeType"],o);return n}function kd(e){let n={},t=i(e,["id"]);if(t!=null)s(n,["id"],t);let o=i(e,["args"]);if(o!=null)s(n,["args"],o);let r=i(e,["name"]);if(r!=null)s(n,["name"],r);if(i(e,["partialArgs"])!==void 0)throw Error("partialArgs parameter is not supported in Gemini API.");if(i(e,["willContinue"])!==void 0)throw Error("willContinue parameter is not supported in Gemini API.");return n}function Fd(e){let n={},t=i(e,["authConfig"]);if(t!=null)s(n,["authConfig"],Md(t));let o=i(e,["enableWidget"]);if(o!=null)s(n,["enableWidget"],o);return n}function Vd(e){let n={},t=i(e,["searchTypes"]);if(t!=null)s(n,["searchTypes"],t);if(i(e,["blockingConfidence"])!==void 0)throw Error("blockingConfidence parameter is not supported in Gemini API.");if(i(e,["excludeDomains"])!==void 0)throw Error("excludeDomains parameter is not supported in Gemini API.");let o=i(e,["timeRangeFilter"]);if(o!=null)s(n,["timeRangeFilter"],o);return n}function qd(e,n){let t={},o=i(e,["generationConfig"]);if(n!==void 0&&o!=null)s(n,["setup","generationConfig"],o);let r=i(e,["responseModalities"]);if(n!==void 0&&r!=null)s(n,["setup","generationConfig","responseModalities"],r);let l=i(e,["temperature"]);if(n!==void 0&&l!=null)s(n,["setup","generationConfig","temperature"],l);let a=i(e,["topP"]);if(n!==void 0&&a!=null)s(n,["setup","generationConfig","topP"],a);let f=i(e,["topK"]);if(n!==void 0&&f!=null)s(n,["setup","generationConfig","topK"],f);let d=i(e,["maxOutputTokens"]);if(n!==void 0&&d!=null)s(n,["setup","generationConfig","maxOutputTokens"],d);let c=i(e,["mediaResolution"]);if(n!==void 0&&c!=null)s(n,["setup","generationConfig","mediaResolution"],c);let m=i(e,["seed"]);if(n!==void 0&&m!=null)s(n,["setup","generationConfig","seed"],m);let p=i(e,["speechConfig"]);if(n!==void 0&&p!=null)s(n,["setup","generationConfig","speechConfig"],qn(p));let g=i(e,["thinkingConfig"]);if(n!==void 0&&g!=null)s(n,["setup","generationConfig","thinkingConfig"],g);let y=i(e,["enableAffectiveDialog"]);if(n!==void 0&&y!=null)s(n,["setup","generationConfig","enableAffectiveDialog"],y);let E=i(e,["systemInstruction"]);if(n!==void 0&&E!=null)s(n,["setup","systemInstruction"],xd(B(E)));let T=i(e,["tools"]);if(n!==void 0&&T!=null){let A=Ce(T);if(Array.isArray(A))A=A.map((M)=>$d(Ie(M)));s(n,["setup","tools"],A)}let _=i(e,["sessionResumption"]);if(n!==void 0&&_!=null)s(n,["setup","sessionResumption"],bd(_));let C=i(e,["inputAudioTranscription"]);if(n!==void 0&&C!=null)s(n,["setup","inputAudioTranscription"],Po(C));let v=i(e,["outputAudioTranscription"]);if(n!==void 0&&v!=null)s(n,["setup","outputAudioTranscription"],Po(v));let R=i(e,["realtimeInputConfig"]);if(n!==void 0&&R!=null)s(n,["setup","realtimeInputConfig"],R);let P=i(e,["contextWindowCompression"]);if(n!==void 0&&P!=null)s(n,["setup","contextWindowCompression"],P);let x=i(e,["proactivity"]);if(n!==void 0&&x!=null)s(n,["setup","proactivity"],x);if(i(e,["explicitVadSignal"])!==void 0)throw Error("explicitVadSignal parameter is not supported in Gemini API.");let I=i(e,["avatarConfig"]);if(n!==void 0&&I!=null)s(n,["setup","avatarConfig"],I);let U=i(e,["safetySettings"]);if(n!==void 0&&U!=null){let A=U;if(Array.isArray(A))A=A.map((M)=>Jd(M));s(n,["setup","safetySettings"],A)}return t}function Hd(e,n){let t={},o=i(n,["model"]);if(o!=null)s(t,["setup","model"],L(e,o));let r=i(n,["config"]);if(r!=null)s(t,["config"],qd(r,t));return t}function Bd(e){let n={},t=i(e,["mediaResolution"]);if(t!=null)s(n,["mediaResolution"],t);let o=i(e,["codeExecutionResult"]);if(o!=null)s(n,["codeExecutionResult"],o);let r=i(e,["executableCode"]);if(r!=null)s(n,["executableCode"],r);let l=i(e,["fileData"]);if(l!=null)s(n,["fileData"],Gd(l));let a=i(e,["functionCall"]);if(a!=null)s(n,["functionCall"],kd(a));let f=i(e,["functionResponse"]);if(f!=null)s(n,["functionResponse"],f);let d=i(e,["inlineData"]);if(d!=null)s(n,["inlineData"],Dd(d));let c=i(e,["text"]);if(c!=null)s(n,["text"],c);let m=i(e,["thought"]);if(m!=null)s(n,["thought"],m);let p=i(e,["thoughtSignature"]);if(p!=null)s(n,["thoughtSignature"],p);let g=i(e,["videoMetadata"]);if(g!=null)s(n,["videoMetadata"],g);let y=i(e,["toolCall"]);if(y!=null)s(n,["toolCall"],y);let E=i(e,["toolResponse"]);if(E!=null)s(n,["toolResponse"],E);let T=i(e,["partMetadata"]);if(T!=null)s(n,["partMetadata"],T);return n}function Jd(e){let n={},t=i(e,["category"]);if(t!=null)s(n,["category"],t);if(i(e,["method"])!==void 0)throw Error("method parameter is not supported in Gemini API.");let o=i(e,["threshold"]);if(o!=null)s(n,["threshold"],o);return n}function bd(e){let n={},t=i(e,["handle"]);if(t!=null)s(n,["handle"],t);if(i(e,["transparent"])!==void 0)throw Error("transparent parameter is not supported in Gemini API.");return n}function $d(e){let n={};if(i(e,["retrieval"])!==void 0)throw Error("retrieval parameter is not supported in Gemini API.");let t=i(e,["computerUse"]);if(t!=null)s(n,["computerUse"],t);let o=i(e,["fileSearch"]);if(o!=null)s(n,["fileSearch"],o);let r=i(e,["googleSearch"]);if(r!=null)s(n,["googleSearch"],Vd(r));let l=i(e,["googleMaps"]);if(l!=null)s(n,["googleMaps"],Fd(l));let a=i(e,["codeExecution"]);if(a!=null)s(n,["codeExecution"],a);if(i(e,["enterpriseWebSearch"])!==void 0)throw Error("enterpriseWebSearch parameter is not supported in Gemini API.");let f=i(e,["functionDeclarations"]);if(f!=null){let p=f;if(Array.isArray(p))p=p.map((g)=>g);s(n,["functionDeclarations"],p)}let d=i(e,["googleSearchRetrieval"]);if(d!=null)s(n,["googleSearchRetrieval"],d);if(i(e,["parallelAiSearch"])!==void 0)throw Error("parallelAiSearch parameter is not supported in Gemini API.");let c=i(e,["urlContext"]);if(c!=null)s(n,["urlContext"],c);let m=i(e,["mcpServers"]);if(m!=null){let p=m;if(Array.isArray(p))p=p.map((g)=>g);s(n,["mcpServers"],p)}return n}function Od(e){let n=[];for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)){let o=e[t];if(typeof o==="object"&&o!=null&&Object.keys(o).length>0){let r=Object.keys(o).map((l)=>`${t}.${l}`);n.push(...r)}else n.push(t)}return n.join(",")}function Kd(e,n){let t=null,o=e.bidiGenerateContentSetup;if(typeof o==="object"&&o!==null&&"setup"in o){let l=o.setup;if(typeof l==="object"&&l!==null)e.bidiGenerateContentSetup=l,t=l;else delete e.bidiGenerateContentSetup}else if(o!==void 0)delete e.bidiGenerateContentSetup;let r=e.fieldMask;if(t){let l=Od(t);if(Array.isArray(n===null||n===void 0?void 0:n.lockAdditionalFields)&&(n===null||n===void 0?void 0:n.lockAdditionalFields.length)===0)if(l)e.fieldMask=l;else delete e.fieldMask;else if((n===null||n===void 0?void 0:n.lockAdditionalFields)&&n.lockAdditionalFields.length>0&&r!==null&&Array.isArray(r)&&r.length>0){let a=["temperature","topK","topP","maxOutputTokens","responseModalities","seed","speechConfig"],f=[];if(r.length>0)f=r.map((c)=>{if(a.includes(c))return`generationConfig.${c}`;return c});let d=[];if(l)d.push(l);if(f.length>0)d.push(...f);if(d.length>0)e.fieldMask=d.join(",");else delete e.fieldMask}else delete e.fieldMask}else if(r!==null&&Array.isArray(r)&&r.length>0)e.fieldMask=r.join(",");else delete e.fieldMask;return e}class ki extends ne{constructor(e){super();this.apiClient=e}async create(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("The client.tokens.create method is only supported by the Gemini Developer API.");else{let a=Ld(this.apiClient,e);r=S("auth_tokens",a._url),l=a._query,delete a.config,delete a._url,delete a._query;let f=Kd(a,e.config);return o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(f),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((d)=>d.json()),o.then((d)=>d)}}}function Yd(e,n){let t={},o=i(e,["force"]);if(n!==void 0&&o!=null)s(n,["_query","force"],o);return t}function Wd(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["_url","name"],t);let o=i(e,["config"]);if(o!=null)Yd(o,n);return n}function zd(e){let n={},t=i(e,["name"]);if(t!=null)s(n,["_url","name"],t);return n}function Xd(e,n){let t={},o=i(e,["pageSize"]);if(n!==void 0&&o!=null)s(n,["_query","pageSize"],o);let r=i(e,["pageToken"]);if(n!==void 0&&r!=null)s(n,["_query","pageToken"],r);return t}function Qd(e){let n={},t=i(e,["parent"]);if(t!=null)s(n,["_url","parent"],t);let o=i(e,["config"]);if(o!=null)Xd(o,n);return n}function Zd(e){let n={},t=i(e,["sdkHttpResponse"]);if(t!=null)s(n,["sdkHttpResponse"],t);let o=i(e,["nextPageToken"]);if(o!=null)s(n,["nextPageToken"],o);let r=i(e,["documents"]);if(r!=null){let l=r;if(Array.isArray(l))l=l.map((a)=>a);s(n,["documents"],l)}return n}class Fi extends ne{constructor(e){super();this.apiClient=e,this.list=async(n)=>new fe(oe.PAGED_ITEM_DOCUMENTS,(t)=>this.listInternal({parent:n.parent,config:t.config}),await this.listInternal(n),n)}async get(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=zd(e);return r=S("{name}",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>f)}}async delete(e){var n,t;let o="",r={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let l=Wd(e);o=S("{name}",l._url),r=l._query,delete l._url,delete l._query,await this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(l),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal})}}async listInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=Qd(e);return r=S("{parent}/documents",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>{let d=Zd(f),c=new Oo;return Object.assign(c,d),c})}}}class Vi extends ne{constructor(e,n=new Fi(e)){super();this.apiClient=e,this.documents=n,this.list=async(t={})=>new fe(oe.PAGED_ITEM_FILE_SEARCH_STORES,(o)=>this.listInternal(o),await this.listInternal(t),t)}async uploadToFileSearchStore(e){if(this.apiClient.isVertexAI())throw Error("Gemini Enterprise Agent Platform (previously known as Vertex AI) does not support uploading files to a file search store.");return this.apiClient.uploadFileToFileSearchStore(e.fileSearchStoreName,e.file,e.config)}async downloadMedia(e,n){if(this.apiClient.isVertexAI())throw Error("This method is only supported in the Gemini Developer client.");let t=new URL(e,"http://dummy.com"),o=t.pathname;if(o.startsWith("/"))o=o.slice(1);if(!o.includes("/media/"))throw Error(`Invalid uri format: ${e}. Expected to contain /media/`);let r={};t.searchParams.forEach((f,d)=>{r[d]=f}),r.alt="media";let l=Object.assign({},n===null||n===void 0?void 0:n.httpOptions),a=await this.apiClient.request({path:o,httpMethod:"GET",queryParams:r,httpOptions:l});if(a instanceof me){let f=await a.responseInternal.arrayBuffer();return new Uint8Array(f)}else throw Error("Unexpected response type from downloadMedia")}async create(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=Yu(this.apiClient,e);return r=S("fileSearchStores",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>f)}}async get(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=Xu(e);return r=S("{name}",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>f)}}async delete(e){var n,t;let o="",r={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let l=zu(e);o=S("{name}",l._url),r=l._query,delete l._url,delete l._query,await this.apiClient.request({path:o,queryParams:r,body:JSON.stringify(l),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal})}}async listInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=td(e);return r=S("fileSearchStores",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>{let d=od(f),c=new Ko;return Object.assign(c,d),c})}}async uploadToFileSearchStoreInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=id(e);return r=S("upload/v1beta/{file_search_store_name}:uploadToFileSearchStore",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>{let d=rd(f),c=new Yo;return Object.assign(c,d),c})}}async importFile(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=ju(e);return r=S("{file_search_store_name}:importFile",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json()),o.then((f)=>{let d=Zu(f),c=new Gn;return Object.assign(c,d),c})}}}var qi=function(){let{crypto:e}=globalThis;if(e===null||e===void 0?void 0:e.randomUUID)return qi=e.randomUUID.bind(e),e.randomUUID();let n=new Uint8Array(1),t=e?()=>e.getRandomValues(n)[0]:()=>Math.random()*255&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(o)=>(+o^t()&15>>+o/4).toString(16))},jd=()=>qi();function wn(e){return typeof e==="object"&&e!==null&&(("name"in e)&&e.name==="AbortError"||("message"in e)&&String(e.message).includes("FetchRequestCanceledException"))}var Nn=(e)=>{if(e instanceof Error)return e;if(typeof e==="object"&&e!==null){try{if(Object.prototype.toString.call(e)==="[object Error]"){let n=Error(e.message,e.cause?{cause:e.cause}:{});if(e.stack)n.stack=e.stack;if(e.cause&&!n.cause)n.cause=e.cause;if(e.name)n.name=e.name;return n}}catch(n){}try{return Error(JSON.stringify(e))}catch(n){}}return Error(e)};class Y extends Error{}class b extends Y{constructor(e,n,t,o){super(`${b.makeMessage(e,n,t)}`);this.status=e,this.headers=o,this.error=n}static makeMessage(e,n,t){let o=(n===null||n===void 0?void 0:n.message)?typeof n.message==="string"?n.message:JSON.stringify(n.message):n?JSON.stringify(n):t;if(e&&o)return`${e} ${o}`;if(e)return`${e} status code (no body)`;if(o)return o;return"(no status code or body)"}static generate(e,n,t,o){if(!e||!o)return new Fe({message:t,cause:Nn(n)});let r=n;if(e===400)return new bn(e,r,t,o);if(e===401)return new $n(e,r,t,o);if(e===403)return new On(e,r,t,o);if(e===404)return new Kn(e,r,t,o);if(e===409)return new Yn(e,r,t,o);if(e===422)return new Wn(e,r,t,o);if(e===429)return new zn(e,r,t,o);if(e>=500)return new Xn(e,r,t,o);return new b(e,r,t,o)}}class ze extends b{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}}class Fe extends b{constructor({message:e,cause:n}){super(void 0,void 0,e||"Connection error.",void 0);if(n)this.cause=n}}class Jn extends Fe{constructor({message:e}={}){super({message:e!==null&&e!==void 0?e:"Request timed out."})}}class bn extends b{}class $n extends b{}class On extends b{}class Kn extends b{}class Yn extends b{}class Wn extends b{}class zn extends b{}class Xn extends b{}var ef=/^[a-z][a-z0-9+.-]*:/i,nf=(e)=>ef.test(e),Mn=(e)=>(Mn=Array.isArray,Mn(e)),tf=Mn,of=tf,wo=of;function No(e){if(!e)return!0;for(let n in e)return!1;return!0}function rf(e,n){return Object.prototype.hasOwnProperty.call(e,n)}var sf=(e,n)=>{if(typeof n!=="number"||!Number.isInteger(n))throw new Y(`${e} must be an integer`);if(n<0)throw new Y(`${e} must be a positive integer`);return n},lf=(e)=>{try{return JSON.parse(e)}catch(n){return}},af=(e)=>new Promise((n)=>setTimeout(n,e));function uf(){if(typeof fetch<"u")return fetch;throw 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 Hi(...e){let n=globalThis.ReadableStream;if(typeof n>"u")throw Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new n(...e)}function df(e){let n=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator]();return Hi({start(){},async pull(t){let{done:o,value:r}=await n.next();if(o)t.close();else t.enqueue(r)},async cancel(){var t;await((t=n.return)===null||t===void 0?void 0:t.call(n))}})}function Bi(e){if(e[Symbol.asyncIterator])return e;let n=e.getReader();return{async next(){try{let t=await n.read();if(t===null||t===void 0?void 0:t.done)n.releaseLock();return t}catch(t){throw n.releaseLock(),t}},async return(){let t=n.cancel();return n.releaseLock(),await t,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function ff(e){var n,t;if(e===null||typeof e!=="object")return;if(e[Symbol.asyncIterator]){await((t=(n=e[Symbol.asyncIterator]()).return)===null||t===void 0?void 0:t.call(n));return}let o=e.getReader(),r=o.cancel();o.releaseLock(),await r}var cf=({headers:e,body:n})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(n)});function pf(e){return Object.entries(e).filter(([n,t])=>typeof t<"u").map(([n,t])=>{if(typeof t==="string"||typeof t==="number"||typeof t==="boolean")return`${encodeURIComponent(n)}=${encodeURIComponent(t)}`;if(t===null)return`${encodeURIComponent(n)}=`;throw new Y(`Cannot stringify type ${typeof t}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`)}).join("&")}var hf="0.0.1",Ji=()=>{var e;if(typeof File>"u"){let{process:n}=globalThis,t=typeof((e=n===null||n===void 0?void 0:n.versions)===null||e===void 0?void 0:e.node)==="string"&&parseInt(n.versions.node.split("."))<20;throw Error("`File` is not defined as a global, which is required for file uploads."+(t?" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`.":""))}};function un(e,n,t){return Ji(),new File(e,n!==null&&n!==void 0?n:"unknown_file",t)}function mf(e){return(typeof e==="object"&&e!==null&&(("name"in e)&&e.name&&String(e.name)||("url"in e)&&e.url&&String(e.url)||("filename"in e)&&e.filename&&String(e.filename)||("path"in e)&&e.path&&String(e.path))||"").split(/[\\/]/).pop()||void 0}var gf=(e)=>e!=null&&typeof e==="object"&&typeof e[Symbol.asyncIterator]==="function",bi=(e)=>e!=null&&typeof e==="object"&&typeof e.size==="number"&&typeof e.type==="string"&&typeof e.text==="function"&&typeof e.slice==="function"&&typeof e.arrayBuffer==="function",yf=(e)=>e!=null&&typeof e==="object"&&typeof e.name==="string"&&typeof e.lastModified==="number"&&bi(e),Ef=(e)=>e!=null&&typeof e==="object"&&typeof e.url==="string"&&typeof e.blob==="function";async function Tf(e,n,t){if(Ji(),e=await e,yf(e)){if(e instanceof File)return e;return un([await e.arrayBuffer()],e.name)}if(Ef(e)){let r=await e.blob();return n||(n=new URL(e.url).pathname.split(/[\\/]/).pop()),un(await Dn(r),n,t)}let o=await Dn(e);if(n||(n=mf(e)),!(t===null||t===void 0?void 0:t.type)){let r=o.find((l)=>typeof l==="object"&&("type"in l)&&l.type);if(typeof r==="string")t=Object.assign(Object.assign({},t),{type:r})}return un(o,n,t)}async function Dn(e){var n,t,o,r,l;let a=[];if(typeof e==="string"||ArrayBuffer.isView(e)||e instanceof ArrayBuffer)a.push(e);else if(bi(e))a.push(e instanceof Blob?e:await e.arrayBuffer());else if(gf(e))try{for(var f=!0,d=j(e),c;c=await d.next(),n=c.done,!n;f=!0){r=c.value,f=!1;let m=r;a.push(...await Dn(m))}}catch(m){t={error:m}}finally{try{if(!f&&!n&&(o=d.return))await o.call(d)}finally{if(t)throw t.error}}else{let m=(l=e===null||e===void 0?void 0:e.constructor)===null||l===void 0?void 0:l.name;throw Error(`Unexpected data type: ${typeof e}${m?`; constructor: ${m}`:""}${_f(e)}`)}return a}function _f(e){if(typeof e!=="object"||e===null)return"";return`; props: [${Object.getOwnPropertyNames(e).map((t)=>`"${t}"`).join(", ")}]`}class sn{constructor(e){this._client=e}}sn._key=[];function $i(e){return e.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g,encodeURIComponent)}var Mo=Object.freeze(Object.create(null)),If=(e=$i)=>function(t,...o){if(t.length===1)return t[0];let r=!1,l=[],a=t.reduce((m,p,g)=>{var y,E,T;if(/[?#]/.test(p))r=!0;let _=o[g],C=(r?encodeURIComponent:e)(""+_);if(g!==o.length&&(_==null||typeof _==="object"&&_.toString===((T=Object.getPrototypeOf((E=Object.getPrototypeOf((y=_.hasOwnProperty)!==null&&y!==void 0?y:Mo))!==null&&E!==void 0?E:Mo))===null||T===void 0?void 0:T.toString)))C=_+"",l.push({start:m.length+p.length,length:C.length,error:`Value of type ${Object.prototype.toString.call(_).slice(8,-1)} is not a valid path parameter`});return m+p+(g===o.length?"":C)},""),f=a.split(/[?#]/,1)[0],d=/(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi,c;while((c=d.exec(f))!==null){let m=c[0].startsWith("/"),p=m?1:0,g=m?c[0].slice(1):c[0];l.push({start:c.index+p,length:g.length,error:`Value "${g}" can't be safely passed as a path parameter`})}if(l.sort((m,p)=>m.start-p.start),l.length>0){let m=0,p=l.reduce((g,y)=>{let E=" ".repeat(y.start-m),T="^".repeat(y.length);return m=y.start+y.length,g+E+T},"");throw new Y(`Path parameters result in path with invalid segments:
7
+ ${l.map((g)=>g.error).join(`
8
+ `)}
9
+ ${a}
10
+ ${p}`)}return a},Q=If($i);class Qn extends sn{create(e,n){var t;let{api_version:o=this._client.apiVersion}=e,r=se(e,["api_version"]);if("model"in r&&"agent_config"in r)throw new Y("Invalid request: specified `model` and `agent_config`. If specifying `model`, use `generation_config`.");if("agent"in r&&"generation_config"in r)throw new Y("Invalid request: specified `agent` and `generation_config`. If specifying `agent`, use `agent_config`.");return this._client.post(Q`/${o}/interactions`,Object.assign(Object.assign({body:r},n),{stream:(t=e.stream)!==null&&t!==void 0?t:!1}))}delete(e,n={},t){let{api_version:o=this._client.apiVersion}=n!==null&&n!==void 0?n:{};return this._client.delete(Q`/${o}/interactions/${e}`,t)}cancel(e,n={},t){let{api_version:o=this._client.apiVersion}=n!==null&&n!==void 0?n:{};return this._client.post(Q`/${o}/interactions/${e}/cancel`,t)}get(e,n={},t){var o;let r=n!==null&&n!==void 0?n:{},{api_version:l=this._client.apiVersion}=r,a=se(r,["api_version"]);return this._client.get(Q`/${l}/interactions/${e}`,Object.assign(Object.assign({query:a},t),{stream:(o=n===null||n===void 0?void 0:n.stream)!==null&&o!==void 0?o:!1}))}}Qn._key=Object.freeze(["interactions"]);class Zn extends Qn{}class jn extends sn{create(e,n){let{api_version:t=this._client.apiVersion}=e,o=se(e,["api_version"]);return this._client.post(Q`/${t}/webhooks`,Object.assign({body:o},n))}update(e,n={},t){let o=n!==null&&n!==void 0?n:{},{api_version:r=this._client.apiVersion,update_mask:l}=o,a=se(o,["api_version","update_mask"]);return this._client.patch(Q`/${r}/webhooks/${e}`,Object.assign({query:{update_mask:l},body:a},t))}list(e={},n){let t=e!==null&&e!==void 0?e:{},{api_version:o=this._client.apiVersion}=t,r=se(t,["api_version"]);return this._client.get(Q`/${o}/webhooks`,Object.assign({query:r},n))}delete(e,n={},t){let{api_version:o=this._client.apiVersion}=n!==null&&n!==void 0?n:{};return this._client.delete(Q`/${o}/webhooks/${e}`,t)}get(e,n={},t){let{api_version:o=this._client.apiVersion}=n!==null&&n!==void 0?n:{};return this._client.get(Q`/${o}/webhooks/${e}`,t)}ping(e,n=void 0,t){let{api_version:o=this._client.apiVersion,body:r}=n!==null&&n!==void 0?n:{};return this._client.post(Q`/${o}/webhooks/${e}:ping`,Object.assign({body:r},t))}rotateSigningSecret(e,n={},t){let o=n!==null&&n!==void 0?n:{},{api_version:r=this._client.apiVersion}=o,l=se(o,["api_version"]);return this._client.post(Q`/${r}/webhooks/${e}:rotateSigningSecret`,Object.assign({body:l},t))}}jn._key=Object.freeze(["webhooks"]);class et extends jn{}function Cf(e){let n=0;for(let r of e)n+=r.length;let t=new Uint8Array(n),o=0;for(let r of e)t.set(r,o),o+=r.length;return t}var qe;function nt(e){let n;return(qe!==null&&qe!==void 0?qe:(n=new globalThis.TextEncoder,qe=n.encode.bind(n)))(e)}var He;function Do(e){let n;return(He!==null&&He!==void 0?He:(n=new globalThis.TextDecoder,He=n.decode.bind(n)))(e)}class Ve{constructor(){this.buffer=new Uint8Array,this.carriageReturnIndex=null,this.searchIndex=0}decode(e){var n;if(e==null)return[];let t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e==="string"?nt(e):e;this.buffer=Cf([this.buffer,t]);let o=[],r;while((r=Af(this.buffer,(n=this.carriageReturnIndex)!==null&&n!==void 0?n:this.searchIndex))!=null){if(r.carriage&&this.carriageReturnIndex==null){this.carriageReturnIndex=r.index;continue}if(this.carriageReturnIndex!=null&&(r.index!==this.carriageReturnIndex+1||r.carriage)){o.push(Do(this.buffer.subarray(0,this.carriageReturnIndex-1))),this.buffer=this.buffer.subarray(this.carriageReturnIndex),this.carriageReturnIndex=null,this.searchIndex=0;continue}let l=this.carriageReturnIndex!==null?r.preceding-1:r.preceding,a=Do(this.buffer.subarray(0,l));o.push(a),this.buffer=this.buffer.subarray(r.index),this.carriageReturnIndex=null,this.searchIndex=0}return this.searchIndex=Math.max(0,this.buffer.length-1),o}flush(){if(!this.buffer.length)return[];return this.decode(`
11
+ `)}}Ve.NEWLINE_CHARS=new Set([`
12
+ `,"\r"]);Ve.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function Af(e,n){let r=n!==null&&n!==void 0?n:0,l=e.indexOf(10,r),a=e.indexOf(13,r);if(l===-1&&a===-1)return null;let f;if(l!==-1&&a!==-1)f=Math.min(l,a);else f=l!==-1?l:a;if(e[f]===10)return{preceding:f,index:f+1,carriage:!1};return{preceding:f,index:f+1,carriage:!0}}var Xe={off:0,error:200,warn:300,info:400,debug:500},xo=(e,n,t)=>{if(!e)return;if(rf(Xe,e))return e;J(t).warn(`${n} was set to ${JSON.stringify(e)}, expected one of ${JSON.stringify(Object.keys(Xe))}`);return};function xe(){}function Be(e,n,t){if(!n||Xe[e]>Xe[t])return xe;else return n[e].bind(n)}var vf={error:xe,warn:xe,info:xe,debug:xe},Uo=new WeakMap;function J(e){var n;let t=e.logger,o=(n=e.logLevel)!==null&&n!==void 0?n:"off";if(!t)return vf;let r=Uo.get(t);if(r&&r[0]===o)return r[1];let l={error:Be("error",t,o),warn:Be("warn",t,o),info:Be("info",t,o),debug:Be("debug",t,o)};return Uo.set(t,[o,l]),l}var he=(e)=>{if(e.options)e.options=Object.assign({},e.options),delete e.options.headers;if(e.headers)e.headers=Object.fromEntries((e.headers instanceof Headers?[...e.headers]:Object.entries(e.headers)).map(([n,t])=>[n,n.toLowerCase()==="x-goog-api-key"||n.toLowerCase()==="authorization"||n.toLowerCase()==="cookie"||n.toLowerCase()==="set-cookie"?"***":t]));if("retryOfRequestLogID"in e){if(e.retryOfRequestLogID)e.retryOf=e.retryOfRequestLogID;delete e.retryOfRequestLogID}return e};class Ee{constructor(e,n,t){this.iterator=e,this.controller=n,this.client=t}static fromSSEResponse(e,n,t){let o=!1,r=t?J(t):console;function l(){return Z(this,arguments,function*(){var f,d,c,m;if(o)throw new Y("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");o=!0;let p=!1;try{try{for(var g=!0,y=j(Sf(e,n)),E;E=yield D(y.next()),f=E.done,!f;g=!0){m=E.value,g=!1;let T=m;if(p)continue;if(T.data.startsWith("[DONE]")){p=!0;continue}else try{yield yield D(JSON.parse(T.data))}catch(_){throw r.error("Could not parse message into JSON:",T.data),r.error("From chunk:",T.raw),_}}}catch(T){d={error:T}}finally{try{if(!g&&!f&&(c=y.return))yield D(c.call(y))}finally{if(d)throw d.error}}p=!0}catch(T){if(wn(T))return yield D(void 0);throw T}finally{if(!p)n.abort()}})}return new Ee(l,n,t)}static fromReadableStream(e,n,t){let o=!1;function r(){return Z(this,arguments,function*(){var f,d,c,m;let p=new Ve,g=Bi(e);try{for(var y=!0,E=j(g),T;T=yield D(E.next()),f=T.done,!f;y=!0){m=T.value,y=!1;let _=m;for(let C of p.decode(_))yield yield D(C)}}catch(_){d={error:_}}finally{try{if(!y&&!f&&(c=E.return))yield D(c.call(E))}finally{if(d)throw d.error}}for(let _ of p.flush())yield yield D(_)})}function l(){return Z(this,arguments,function*(){var f,d,c,m;if(o)throw new Y("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");o=!0;let p=!1;try{try{for(var g=!0,y=j(r()),E;E=yield D(y.next()),f=E.done,!f;g=!0){m=E.value,g=!1;let T=m;if(p)continue;if(T)yield yield D(JSON.parse(T))}}catch(T){d={error:T}}finally{try{if(!g&&!f&&(c=y.return))yield D(c.call(y))}finally{if(d)throw d.error}}p=!0}catch(T){if(wn(T))return yield D(void 0);throw T}finally{if(!p)n.abort()}})}return new Ee(l,n,t)}[Symbol.asyncIterator](){return this.iterator()}tee(){let e=[],n=[],t=this.iterator(),o=(r)=>({next:()=>{if(r.length===0){let l=t.next();e.push(l),n.push(l)}return r.shift()}});return[new Ee(()=>o(e),this.controller,this.client),new Ee(()=>o(n),this.controller,this.client)]}toReadableStream(){let e=this,n;return Hi({async start(){n=e[Symbol.asyncIterator]()},async pull(t){try{let{value:o,done:r}=await n.next();if(r)return t.close();let l=nt(JSON.stringify(o)+`
13
+ `);t.enqueue(l)}catch(o){t.error(o)}},async cancel(){var t;await((t=n.return)===null||t===void 0?void 0:t.call(n))}})}}function Sf(e,n){return Z(this,arguments,function*(){var o,r,l,a;if(!e.body){if(n.abort(),typeof globalThis.navigator<"u"&&globalThis.navigator.product==="ReactNative")throw new Y("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api");throw new Y("Attempted to iterate over a response with no body")}let f=new Oi,d=new Ve,c=Bi(e.body);try{for(var m=!0,p=j(Rf(c)),g;g=yield D(p.next()),o=g.done,!o;m=!0){a=g.value,m=!1;let y=a;for(let E of d.decode(y)){let T=f.decode(E);if(T)yield yield D(T)}}}catch(y){r={error:y}}finally{try{if(!m&&!o&&(l=p.return))yield D(l.call(p))}finally{if(r)throw r.error}}for(let y of d.flush()){let E=f.decode(y);if(E)yield yield D(E)}})}function Rf(e){return Z(this,arguments,function*(){var t,o,r,l;try{for(var a=!0,f=j(e),d;d=yield D(f.next()),t=d.done,!t;a=!0){l=d.value,a=!1;let c=l;if(c==null)continue;let m=c instanceof ArrayBuffer?new Uint8Array(c):typeof c==="string"?nt(c):c;yield yield D(m)}}catch(c){o={error:c}}finally{try{if(!a&&!t&&(r=f.return))yield D(r.call(f))}finally{if(o)throw o.error}}})}class Oi{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith("\r"))e=e.substring(0,e.length-1);if(!e){if(!this.event&&!this.data.length)return null;let r={event:this.event,data:this.data.join(`
14
+ `),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],r}if(this.chunks.push(e),e.startsWith(":"))return null;let[n,t,o]=Pf(e,":");if(o.startsWith(" "))o=o.substring(1);if(n==="event")this.event=o;else if(n==="data")this.data.push(o);return null}}function Pf(e,n){let t=e.indexOf(n);if(t!==-1)return[e.substring(0,t),n,e.substring(t+n.length)];return[e,"",""]}async function wf(e,n){let{response:t,requestLogID:o,retryOfRequestLogID:r,startTime:l}=n,a=await(async()=>{var f;if(n.options.stream){if(J(e).debug("response",t.status,t.url,t.headers,t.body),n.options.__streamClass)return n.options.__streamClass.fromSSEResponse(t,n.controller,e);return Ee.fromSSEResponse(t,n.controller,e)}if(t.status===204)return null;if(n.options.__binaryResponse)return t;let d=t.headers.get("content-type"),c=(f=d===null||d===void 0?void 0:d.split(";")[0])===null||f===void 0?void 0:f.trim();if((c===null||c===void 0?void 0:c.includes("application/json"))||(c===null||c===void 0?void 0:c.endsWith("+json"))){if(t.headers.get("content-length")==="0")return;return await t.json()}return await t.text()})();return J(e).debug(`[${o}] response parsed`,he({retryOfRequestLogID:r,url:t.url,status:t.status,body:a,durationMs:Date.now()-l})),a}class tt extends Promise{constructor(e,n,t=wf){super((o)=>{o(null)});this.responsePromise=n,this.parseResponse=t,this.client=e}_thenUnwrap(e){return new tt(this.client,this.responsePromise,async(n,t)=>e(await this.parseResponse(n,t),t))}asResponse(){return this.responsePromise.then((e)=>e.response)}async withResponse(){let[e,n]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:n}}parse(){if(!this.parsedPromise)this.parsedPromise=this.responsePromise.then((e)=>this.parseResponse(this.client,e));return 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)}}var Ki=Symbol("brand.privateNullableHeaders");function*Nf(e){if(!e)return;if(Ki in e){let{values:o,nulls:r}=e;yield*o.entries();for(let l of r)yield[l,null];return}let n=!1,t;if(e instanceof Headers)t=e.entries();else if(wo(e))t=e;else n=!0,t=Object.entries(e!==null&&e!==void 0?e:{});for(let o of t){let r=o[0];if(typeof r!=="string")throw TypeError("expected header name to be a string");let l=wo(o[1])?o[1]:[o[1]],a=!1;for(let f of l){if(f===void 0)continue;if(n&&!a)a=!0,yield[r,null];yield[r,f]}}}var Pe=(e)=>{let n=new Headers,t=new Set;for(let o of e){let r=new Set;for(let[l,a]of Nf(o)){let f=l.toLowerCase();if(!r.has(f))n.delete(l),r.add(f);if(a===null)n.delete(l),t.add(f);else n.append(l,a),t.delete(f)}}return{[Ki]:!0,values:n,nulls:t}},dn=(e)=>{var n,t,o,r,l;if(typeof globalThis.process<"u")return((t=(n=globalThis.process.env)===null||n===void 0?void 0:n[e])===null||t===void 0?void 0:t.trim())||void 0;if(typeof globalThis.Deno<"u")return((l=(r=(o=globalThis.Deno.env)===null||o===void 0?void 0:o.get)===null||r===void 0?void 0:r.call(o,e))===null||l===void 0?void 0:l.trim())||void 0;return},Yi;class ln{constructor(e){var n,t,o,r,l,a,f,{baseURL:d=dn("GEMINI_NEXT_GEN_API_BASE_URL"),apiKey:c=(n=dn("GEMINI_API_KEY"))!==null&&n!==void 0?n:null,apiVersion:m="v1beta"}=e,p=se(e,["baseURL","apiKey","apiVersion"]);let g=Object.assign(Object.assign({apiKey:c,apiVersion:m},p),{baseURL:d||"https://generativelanguage.googleapis.com"});this.baseURL=g.baseURL,this.timeout=(t=g.timeout)!==null&&t!==void 0?t:ln.DEFAULT_TIMEOUT,this.logger=(o=g.logger)!==null&&o!==void 0?o:console;let y="warn";this.logLevel=y,this.logLevel=(l=(r=xo(g.logLevel,"ClientOptions.logLevel",this))!==null&&r!==void 0?r:xo(dn("GEMINI_NEXT_GEN_API_LOG"),"process.env['GEMINI_NEXT_GEN_API_LOG']",this))!==null&&l!==void 0?l:y,this.fetchOptions=g.fetchOptions,this.maxRetries=(a=g.maxRetries)!==null&&a!==void 0?a:2,this.fetch=(f=g.fetch)!==null&&f!==void 0?f:uf(),this.encoder=cf,this._options=g,this.apiKey=c,this.apiVersion=m,this.clientAdapter=g.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"))return;if(this.apiKey&&e.get("x-goog-api-key"))return;if(n.has("x-goog-api-key"))return;throw 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){let n=Pe([e.headers]);if(n.values.has("authorization")||n.values.has("x-goog-api-key"))return;if(this.apiKey)return Pe([{"x-goog-api-key":this.apiKey}]);if(this.clientAdapter&&this.clientAdapter.isVertexAI())return Pe([await this.clientAdapter.getAuthHeaders()]);return}stringifyQuery(e){return pf(e)}getUserAgent(){return`${this.constructor.name}/JS ${hf}`}defaultIdempotencyKey(){return`stainless-node-retry-${jd()}`}makeStatusError(e,n,t,o){return b.generate(e,n,t,o)}buildURL(e,n,t){let o=!this.baseURLOverridden()&&t||this.baseURL,r=nf(e)?new URL(e):new URL(o+(o.endsWith("/")&&e.startsWith("/")?e.slice(1):e)),l=this.defaultQuery(),a=Object.fromEntries(r.searchParams);if(!No(l)||!No(a))n=Object.assign(Object.assign(Object.assign({},a),l),n);if(typeof n==="object"&&n&&!Array.isArray(n))r.search=this.stringifyQuery(n);return r.toString()}async prepareOptions(e){if(this.clientAdapter&&this.clientAdapter.isVertexAI()&&!e.path.startsWith(`/${this.apiVersion}/projects/`)){let 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:t}){}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,t){return this.request(Promise.resolve(t).then((o)=>Object.assign({method:e,path:n},o)))}request(e,n=null){return new tt(this,this.makeRequest(e,n,void 0))}async makeRequest(e,n,t){var o,r,l;let a=await e,f=(o=a.maxRetries)!==null&&o!==void 0?o:this.maxRetries;if(n==null)n=f;await this.prepareOptions(a);let{req:d,url:c,timeout:m}=await this.buildRequest(a,{retryCount:f-n});await this.prepareRequest(d,{url:c,options:a});let p="log_"+(Math.random()*16777216|0).toString(16).padStart(6,"0"),g=t===void 0?"":`, retryOf: ${t}`,y=Date.now();if(J(this).debug(`[${p}] sending request`,he({retryOfRequestLogID:t,method:a.method,url:c,options:a,headers:d.headers})),(r=a.signal)===null||r===void 0?void 0:r.aborted)throw new ze;let E=new AbortController,T=await this.fetchWithTimeout(c,d,m,E).catch(Nn),_=Date.now();if(T instanceof globalThis.Error){let v=`retrying, ${n} attempts remaining`;if((l=a.signal)===null||l===void 0?void 0:l.aborted)throw new ze;let R=wn(T)||/timed? ?out/i.test(String(T)+("cause"in T?String(T.cause):""));if(n)return J(this).info(`[${p}] connection ${R?"timed out":"failed"} - ${v}`),J(this).debug(`[${p}] connection ${R?"timed out":"failed"} (${v})`,he({retryOfRequestLogID:t,url:c,durationMs:_-y,message:T.message})),this.retryRequest(a,n,t!==null&&t!==void 0?t:p);if(J(this).info(`[${p}] connection ${R?"timed out":"failed"} - error; no more retries left`),J(this).debug(`[${p}] connection ${R?"timed out":"failed"} (error; no more retries left)`,he({retryOfRequestLogID:t,url:c,durationMs:_-y,message:T.message})),R)throw new Jn;throw new Fe({cause:T})}let C=`[${p}${g}] ${d.method} ${c} ${T.ok?"succeeded":"failed"} with status ${T.status} in ${_-y}ms`;if(!T.ok){let v=await this.shouldRetry(T);if(n&&v){let A=`retrying, ${n} attempts remaining`;return await ff(T.body),J(this).info(`${C} - ${A}`),J(this).debug(`[${p}] response error (${A})`,he({retryOfRequestLogID:t,url:T.url,status:T.status,headers:T.headers,durationMs:_-y})),this.retryRequest(a,n,t!==null&&t!==void 0?t:p,T.headers)}let R=v?"error; no more retries left":"error; not retryable";J(this).info(`${C} - ${R}`);let P=await T.text().catch((A)=>Nn(A).message),x=lf(P),I=x?void 0:P;throw J(this).debug(`[${p}] response error (${R})`,he({retryOfRequestLogID:t,url:T.url,status:T.status,headers:T.headers,message:I,durationMs:Date.now()-y})),this.makeStatusError(T.status,x,I,T.headers)}return J(this).info(C),J(this).debug(`[${p}] response start`,he({retryOfRequestLogID:t,url:T.url,status:T.status,headers:T.headers,durationMs:_-y})),{response:T,options:a,controller:E,requestLogID:p,retryOfRequestLogID:t,startTime:y}}async fetchWithTimeout(e,n,t,o){let r=n||{},{signal:l,method:a}=r,f=se(r,["signal","method"]),d=this._makeAbort(o);if(l)l.addEventListener("abort",d,{once:!0});let c=setTimeout(d,t),m=globalThis.ReadableStream&&f.body instanceof globalThis.ReadableStream||typeof f.body==="object"&&f.body!==null&&Symbol.asyncIterator in f.body,p=Object.assign(Object.assign(Object.assign({signal:o.signal},m?{duplex:"half"}:{}),{method:"GET"}),f);if(a)p.method=a.toUpperCase();try{return await this.fetch.call(void 0,e,p)}finally{clearTimeout(c)}}async shouldRetry(e){let n=e.headers.get("x-should-retry");if(n==="true")return!0;if(n==="false")return!1;if(e.status===408)return!0;if(e.status===409)return!0;if(e.status===429)return!0;if(e.status>=500)return!0;return!1}async retryRequest(e,n,t,o){var r;let l,a=o===null||o===void 0?void 0:o.get("retry-after-ms");if(a){let d=parseFloat(a);if(!Number.isNaN(d))l=d}let f=o===null||o===void 0?void 0:o.get("retry-after");if(f&&!l){let d=parseFloat(f);if(!Number.isNaN(d))l=d*1000;else l=Date.parse(f)-Date.now()}if(l===void 0){let d=(r=e.maxRetries)!==null&&r!==void 0?r:this.maxRetries;l=this.calculateDefaultRetryTimeoutMillis(n,d)}return await af(l),this.makeRequest(e,n-1,t)}calculateDefaultRetryTimeoutMillis(e,n){let r=n-e,l=Math.min(0.5*Math.pow(2,r),8),a=1-Math.random()*0.25;return l*a*1000}async buildRequest(e,{retryCount:n=0}={}){var t,o,r;let l=Object.assign({},e),{method:a,path:f,query:d,defaultBaseURL:c}=l,m=this.buildURL(f,d,c);if("timeout"in l)sf("timeout",l.timeout);l.timeout=(t=l.timeout)!==null&&t!==void 0?t:this.timeout;let{bodyHeaders:p,body:g}=this.buildBody({options:l}),y=await this.buildHeaders({options:e,method:a,bodyHeaders:p,retryCount:n});return{req:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({method:a,headers:y},l.signal&&{signal:l.signal}),globalThis.ReadableStream&&g instanceof globalThis.ReadableStream&&{duplex:"half"}),g&&{body:g}),(o=this.fetchOptions)!==null&&o!==void 0?o:{}),(r=l.fetchOptions)!==null&&r!==void 0?r:{}),url:m,timeout:l.timeout}}async buildHeaders({options:e,method:n,bodyHeaders:t,retryCount:o}){let r={};if(this.idempotencyHeader&&n!=="get"){if(!e.idempotencyKey)e.idempotencyKey=this.defaultIdempotencyKey();r[this.idempotencyHeader]=e.idempotencyKey}let l=await this.authHeaders(e),a=Pe([r,{Accept:"application/json","User-Agent":this.getUserAgent()},this._options.defaultHeaders,t,e.headers,l]);return this.validateHeaders(a),a.values}_makeAbort(e){return()=>e.abort()}buildBody({options:{body:e,headers:n}}){if(!e)return{bodyHeaders:void 0,body:void 0};let t=Pe([n]);if(ArrayBuffer.isView(e)||e instanceof ArrayBuffer||e instanceof DataView||typeof e==="string"&&t.values.has("content-type")||globalThis.Blob&&e instanceof globalThis.Blob||e instanceof FormData||e instanceof URLSearchParams||globalThis.ReadableStream&&e instanceof globalThis.ReadableStream)return{bodyHeaders:void 0,body:e};else if(typeof e==="object"&&((Symbol.asyncIterator in e)||(Symbol.iterator in e)&&("next"in e)&&typeof e.next==="function"))return{bodyHeaders:void 0,body:df(e)};else if(typeof e==="object"&&t.values.get("content-type")==="application/x-www-form-urlencoded")return{bodyHeaders:{"content-type":"application/x-www-form-urlencoded"},body:this.stringifyQuery(e)};else return this.encoder({body:e,headers:t})}}ln.DEFAULT_TIMEOUT=60000;class F extends ln{constructor(){super(...arguments);this.interactions=new Zn(this),this.webhooks=new et(this)}}Yi=F;F.GeminiNextGenAPIClient=Yi;F.GeminiNextGenAPIClientError=Y;F.APIError=b;F.APIConnectionError=Fe;F.APIConnectionTimeoutError=Jn;F.APIUserAbortError=ze;F.NotFoundError=Kn;F.ConflictError=Yn;F.RateLimitError=zn;F.BadRequestError=bn;F.AuthenticationError=$n;F.InternalServerError=Xn;F.PermissionDeniedError=On;F.UnprocessableEntityError=Wn;F.toFile=Tf;F.Interactions=Zn;F.Webhooks=et;var Lo="x-goog-api-key",Me="https://www.googleapis.com/auth/cloud-platform";class Wi{constructor(e){if(e.apiKey!==void 0){this.apiKey=e.apiKey;return}let n=Mf(e.googleAuthOptions);this.googleAuth=new ko.GoogleAuth(n)}async addAuthHeaders(e,n){if(this.apiKey!==void 0){if(this.apiKey.startsWith("auth_tokens/"))throw Error("Ephemeral tokens are only supported by the live API.");this.addKeyHeader(e);return}return this.addGoogleAuthHeaders(e,n)}addKeyHeader(e){if(e.get(Lo)!==null)return;if(this.apiKey===void 0)throw Error("Trying to set API key header but apiKey is not set");e.append(Lo,this.apiKey)}async addGoogleAuthHeaders(e,n){if(this.googleAuth===void 0)throw Error("Trying to set google-auth headers but googleAuth is unset");let t=await this.googleAuth.getRequestHeaders(n);for(let[o,r]of t){if(e.get(o)!==null)continue;e.append(o,r)}}}function Mf(e){let n;if(!e)return n={scopes:[Me]},n;else{if(n=e,!n.scopes)return n.scopes=[Me],n;else if(typeof n.scopes==="string"&&n.scopes!==Me||Array.isArray(n.scopes)&&n.scopes.indexOf(Me)<0)throw Error(`Invalid auth scopes. Scopes must include: ${Me}`);return n}}class zi{async download(e,n){if(e.downloadPath){let t=await Df(e,n);if(t instanceof me){let o=dr(e.downloadPath);cr.fromWeb(t.responseInternal.body).pipe(o),await pr(o)}else try{await fr(e.downloadPath,t,{encoding:"base64"})}catch(o){throw Error(`Failed to write file to ${e.downloadPath}: ${o}`)}}}}async function Df(e,n){var t,o,r;let l=Hn(e.file);if(l!==void 0)return await n.request({path:`files/${l}:download`,httpMethod:"GET",queryParams:{alt:"media"},httpOptions:(t=e.config)===null||t===void 0?void 0:t.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal});else if(si(e.file)){let a=(r=e.file.video)===null||r===void 0?void 0:r.videoBytes;if(typeof a==="string")return a;else throw Error("Failed to download generated video, Uri or videoBytes not found.")}else if(li(e.file)){let a=e.file.videoBytes;if(typeof a==="string")return a;else throw Error("Failed to download video, Uri or videoBytes not found.")}else throw Error("Unsupported file type")}class Xi{create(e,n,t){return new Qi(e,n,t)}}class Qi{constructor(e,n,t){this.url=e,this.headers=n,this.callbacks=t}connect(){this.ws=new Fo.WebSocket(this.url,{headers:this.headers}),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 Error("WebSocket is not connected");this.ws.send(e)}close(){if(this.ws===void 0)throw Error("WebSocket is not connected");this.ws.close()}}function xf(e,n){let t={},o=i(e,["name"]);if(o!=null)s(t,["_url","name"],o);return t}function Uf(e,n){let t={},o=i(e,["name"]);if(o!=null)s(t,["_url","name"],o);return t}function Lf(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);return t}function Gf(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);return t}function kf(e,n,t){let o={};if(i(e,["validationDataset"])!==void 0)throw Error("validationDataset parameter is not supported in Gemini API.");let r=i(e,["tunedModelDisplayName"]);if(n!==void 0&&r!=null)s(n,["displayName"],r);if(i(e,["description"])!==void 0)throw Error("description parameter is not supported in Gemini API.");let l=i(e,["epochCount"]);if(n!==void 0&&l!=null)s(n,["tuningTask","hyperparameters","epochCount"],l);let a=i(e,["learningRateMultiplier"]);if(a!=null)s(o,["tuningTask","hyperparameters","learningRateMultiplier"],a);if(i(e,["exportLastCheckpointOnly"])!==void 0)throw Error("exportLastCheckpointOnly parameter is not supported in Gemini API.");if(i(e,["preTunedModelCheckpointId"])!==void 0)throw Error("preTunedModelCheckpointId parameter is not supported in Gemini API.");if(i(e,["adapterSize"])!==void 0)throw Error("adapterSize parameter is not supported in Gemini API.");if(i(e,["tuningMode"])!==void 0)throw Error("tuningMode parameter is not supported in Gemini API.");if(i(e,["customBaseModel"])!==void 0)throw Error("customBaseModel parameter is not supported in Gemini API.");let f=i(e,["batchSize"]);if(n!==void 0&&f!=null)s(n,["tuningTask","hyperparameters","batchSize"],f);let d=i(e,["learningRate"]);if(n!==void 0&&d!=null)s(n,["tuningTask","hyperparameters","learningRate"],d);if(i(e,["labels"])!==void 0)throw Error("labels parameter is not supported in Gemini API.");if(i(e,["beta"])!==void 0)throw Error("beta parameter is not supported in Gemini API.");if(i(e,["baseTeacherModel"])!==void 0)throw Error("baseTeacherModel parameter is not supported in Gemini API.");if(i(e,["tunedTeacherModelSource"])!==void 0)throw Error("tunedTeacherModelSource parameter is not supported in Gemini API.");if(i(e,["sftLossWeightMultiplier"])!==void 0)throw Error("sftLossWeightMultiplier parameter is not supported in Gemini API.");if(i(e,["outputUri"])!==void 0)throw Error("outputUri parameter is not supported in Gemini API.");if(i(e,["encryptionSpec"])!==void 0)throw Error("encryptionSpec parameter is not supported in Gemini API.");return o}function Ff(e,n,t){let o={},r=i(t,["config","method"]);if(r===void 0)r="SUPERVISED_FINE_TUNING";if(r==="SUPERVISED_FINE_TUNING"){let I=i(e,["validationDataset"]);if(n!==void 0&&I!=null)s(n,["supervisedTuningSpec"],fn(I))}else if(r==="PREFERENCE_TUNING"){let I=i(e,["validationDataset"]);if(n!==void 0&&I!=null)s(n,["preferenceOptimizationSpec"],fn(I))}else if(r==="DISTILLATION"){let I=i(e,["validationDataset"]);if(n!==void 0&&I!=null)s(n,["distillationSpec"],fn(I))}let l=i(e,["tunedModelDisplayName"]);if(n!==void 0&&l!=null)s(n,["tunedModelDisplayName"],l);let a=i(e,["description"]);if(n!==void 0&&a!=null)s(n,["description"],a);let f=i(t,["config","method"]);if(f===void 0)f="SUPERVISED_FINE_TUNING";if(f==="SUPERVISED_FINE_TUNING"){let I=i(e,["epochCount"]);if(n!==void 0&&I!=null)s(n,["supervisedTuningSpec","hyperParameters","epochCount"],I)}else if(f==="PREFERENCE_TUNING"){let I=i(e,["epochCount"]);if(n!==void 0&&I!=null)s(n,["preferenceOptimizationSpec","hyperParameters","epochCount"],I)}else if(f==="DISTILLATION"){let I=i(e,["epochCount"]);if(n!==void 0&&I!=null)s(n,["distillationSpec","hyperParameters","epochCount"],I)}let d=i(t,["config","method"]);if(d===void 0)d="SUPERVISED_FINE_TUNING";if(d==="SUPERVISED_FINE_TUNING"){let I=i(e,["learningRateMultiplier"]);if(n!==void 0&&I!=null)s(n,["supervisedTuningSpec","hyperParameters","learningRateMultiplier"],I)}else if(d==="PREFERENCE_TUNING"){let I=i(e,["learningRateMultiplier"]);if(n!==void 0&&I!=null)s(n,["preferenceOptimizationSpec","hyperParameters","learningRateMultiplier"],I)}else if(d==="DISTILLATION"){let I=i(e,["learningRateMultiplier"]);if(n!==void 0&&I!=null)s(n,["distillationSpec","hyperParameters","learningRateMultiplier"],I)}let c=i(t,["config","method"]);if(c===void 0)c="SUPERVISED_FINE_TUNING";if(c==="SUPERVISED_FINE_TUNING"){let I=i(e,["exportLastCheckpointOnly"]);if(n!==void 0&&I!=null)s(n,["supervisedTuningSpec","exportLastCheckpointOnly"],I)}else if(c==="PREFERENCE_TUNING"){let I=i(e,["exportLastCheckpointOnly"]);if(n!==void 0&&I!=null)s(n,["preferenceOptimizationSpec","exportLastCheckpointOnly"],I)}else if(c==="DISTILLATION"){let I=i(e,["exportLastCheckpointOnly"]);if(n!==void 0&&I!=null)s(n,["distillationSpec","exportLastCheckpointOnly"],I)}let m=i(t,["config","method"]);if(m===void 0)m="SUPERVISED_FINE_TUNING";if(m==="SUPERVISED_FINE_TUNING"){let I=i(e,["adapterSize"]);if(n!==void 0&&I!=null)s(n,["supervisedTuningSpec","hyperParameters","adapterSize"],I)}else if(m==="PREFERENCE_TUNING"){let I=i(e,["adapterSize"]);if(n!==void 0&&I!=null)s(n,["preferenceOptimizationSpec","hyperParameters","adapterSize"],I)}else if(m==="DISTILLATION"){let I=i(e,["adapterSize"]);if(n!==void 0&&I!=null)s(n,["distillationSpec","hyperParameters","adapterSize"],I)}let p=i(t,["config","method"]);if(p===void 0)p="SUPERVISED_FINE_TUNING";if(p==="SUPERVISED_FINE_TUNING"){let I=i(e,["tuningMode"]);if(n!==void 0&&I!=null)s(n,["supervisedTuningSpec","tuningMode"],I)}else if(p==="DISTILLATION"){let I=i(e,["tuningMode"]);if(n!==void 0&&I!=null)s(n,["distillationSpec","tuningMode"],I)}let g=i(e,["customBaseModel"]);if(n!==void 0&&g!=null)s(n,["customBaseModel"],g);let y=i(t,["config","method"]);if(y===void 0)y="SUPERVISED_FINE_TUNING";if(y==="SUPERVISED_FINE_TUNING"){let I=i(e,["batchSize"]);if(n!==void 0&&I!=null)s(n,["supervisedTuningSpec","hyperParameters","batchSize"],I)}else if(y==="DISTILLATION"){let I=i(e,["batchSize"]);if(n!==void 0&&I!=null)s(n,["distillationSpec","hyperParameters","batchSize"],I)}let E=i(t,["config","method"]);if(E===void 0)E="SUPERVISED_FINE_TUNING";if(E==="SUPERVISED_FINE_TUNING"){let I=i(e,["learningRate"]);if(n!==void 0&&I!=null)s(n,["supervisedTuningSpec","hyperParameters","learningRate"],I)}else if(E==="DISTILLATION"){let I=i(e,["learningRate"]);if(n!==void 0&&I!=null)s(n,["distillationSpec","hyperParameters","learningRate"],I)}let T=i(e,["labels"]);if(n!==void 0&&T!=null)s(n,["labels"],T);let _=i(e,["beta"]);if(n!==void 0&&_!=null)s(n,["preferenceOptimizationSpec","hyperParameters","beta"],_);let C=i(e,["baseTeacherModel"]);if(n!==void 0&&C!=null)s(n,["distillationSpec","baseTeacherModel"],C);let v=i(e,["tunedTeacherModelSource"]);if(n!==void 0&&v!=null)s(n,["distillationSpec","tunedTeacherModelSource"],v);let R=i(e,["sftLossWeightMultiplier"]);if(n!==void 0&&R!=null)s(n,["distillationSpec","hyperParameters","sftLossWeightMultiplier"],R);let P=i(e,["outputUri"]);if(n!==void 0&&P!=null)s(n,["outputUri"],P);let x=i(e,["encryptionSpec"]);if(n!==void 0&&x!=null)s(n,["encryptionSpec"],x);return o}function Vf(e,n){let t={},o=i(e,["baseModel"]);if(o!=null)s(t,["baseModel"],o);let r=i(e,["preTunedModel"]);if(r!=null)s(t,["preTunedModel"],r);let l=i(e,["trainingDataset"]);if(l!=null)Kf(l);let a=i(e,["config"]);if(a!=null)kf(a,t);return t}function qf(e,n){let t={},o=i(e,["baseModel"]);if(o!=null)s(t,["baseModel"],o);let r=i(e,["preTunedModel"]);if(r!=null)s(t,["preTunedModel"],r);let l=i(e,["trainingDataset"]);if(l!=null)Yf(l,t,n);let a=i(e,["config"]);if(a!=null)Ff(a,t,n);return t}function Hf(e,n){let t={},o=i(e,["name"]);if(o!=null)s(t,["_url","name"],o);return t}function Bf(e,n){let t={},o=i(e,["name"]);if(o!=null)s(t,["_url","name"],o);return t}function Jf(e,n,t){let o={},r=i(e,["pageSize"]);if(n!==void 0&&r!=null)s(n,["_query","pageSize"],r);let l=i(e,["pageToken"]);if(n!==void 0&&l!=null)s(n,["_query","pageToken"],l);let a=i(e,["filter"]);if(n!==void 0&&a!=null)s(n,["_query","filter"],a);return o}function bf(e,n){let t={},o=i(e,["config"]);if(o!=null)Jf(o,t);return t}function $f(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["nextPageToken"]);if(r!=null)s(t,["nextPageToken"],r);let l=i(e,["tuningJobs"]);if(l!=null){let a=l;if(Array.isArray(a))a=a.map((f)=>xn(f));s(t,["tuningJobs"],a)}return t}function Of(e,n){let t={},o=i(e,["name"]);if(o!=null)s(t,["model"],o);let r=i(e,["name"]);if(r!=null)s(t,["endpoint"],r);return t}function Kf(e,n){let t={};if(i(e,["gcsUri"])!==void 0)throw Error("gcsUri parameter is not supported in Gemini API.");if(i(e,["vertexDatasetResource"])!==void 0)throw Error("vertexDatasetResource parameter is not supported in Gemini API.");let o=i(e,["examples"]);if(o!=null){let r=o;if(Array.isArray(r))r=r.map((l)=>l);s(t,["examples","examples"],r)}return t}function Yf(e,n,t){let o={},r=i(t,["config","method"]);if(r===void 0)r="SUPERVISED_FINE_TUNING";if(r==="SUPERVISED_FINE_TUNING"){let a=i(e,["gcsUri"]);if(n!==void 0&&a!=null)s(n,["supervisedTuningSpec","trainingDatasetUri"],a)}else if(r==="PREFERENCE_TUNING"){let a=i(e,["gcsUri"]);if(n!==void 0&&a!=null)s(n,["preferenceOptimizationSpec","trainingDatasetUri"],a)}else if(r==="DISTILLATION"){let a=i(e,["gcsUri"]);if(n!==void 0&&a!=null)s(n,["distillationSpec","promptDatasetUri"],a)}let l=i(t,["config","method"]);if(l===void 0)l="SUPERVISED_FINE_TUNING";if(l==="SUPERVISED_FINE_TUNING"){let a=i(e,["vertexDatasetResource"]);if(n!==void 0&&a!=null)s(n,["supervisedTuningSpec","trainingDatasetUri"],a)}else if(l==="PREFERENCE_TUNING"){let a=i(e,["vertexDatasetResource"]);if(n!==void 0&&a!=null)s(n,["preferenceOptimizationSpec","trainingDatasetUri"],a)}else if(l==="DISTILLATION"){let a=i(e,["vertexDatasetResource"]);if(n!==void 0&&a!=null)s(n,["distillationSpec","promptDatasetUri"],a)}if(i(e,["examples"])!==void 0)throw Error("examples parameter is not supported in Gemini Enterprise Agent Platform (previously known as Vertex AI).");return o}function Wf(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["name"]);if(r!=null)s(t,["name"],r);let l=i(e,["state"]);if(l!=null)s(t,["state"],ri(l));let a=i(e,["createTime"]);if(a!=null)s(t,["createTime"],a);let f=i(e,["tuningTask","startTime"]);if(f!=null)s(t,["startTime"],f);let d=i(e,["tuningTask","completeTime"]);if(d!=null)s(t,["endTime"],d);let c=i(e,["updateTime"]);if(c!=null)s(t,["updateTime"],c);let m=i(e,["description"]);if(m!=null)s(t,["description"],m);let p=i(e,["baseModel"]);if(p!=null)s(t,["baseModel"],p);let g=i(e,["_self"]);if(g!=null)s(t,["tunedModel"],Of(g));return t}function xn(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["name"]);if(r!=null)s(t,["name"],r);let l=i(e,["state"]);if(l!=null)s(t,["state"],ri(l));let a=i(e,["createTime"]);if(a!=null)s(t,["createTime"],a);let f=i(e,["startTime"]);if(f!=null)s(t,["startTime"],f);let d=i(e,["endTime"]);if(d!=null)s(t,["endTime"],d);let c=i(e,["updateTime"]);if(c!=null)s(t,["updateTime"],c);let m=i(e,["error"]);if(m!=null)s(t,["error"],m);let p=i(e,["description"]);if(p!=null)s(t,["description"],p);let g=i(e,["baseModel"]);if(g!=null)s(t,["baseModel"],g);let y=i(e,["tunedModel"]);if(y!=null)s(t,["tunedModel"],y);let E=i(e,["preTunedModel"]);if(E!=null)s(t,["preTunedModel"],E);let T=i(e,["supervisedTuningSpec"]);if(T!=null)s(t,["supervisedTuningSpec"],T);let _=i(e,["preferenceOptimizationSpec"]);if(_!=null)s(t,["preferenceOptimizationSpec"],_);let C=i(e,["distillationSpec"]);if(C!=null)s(t,["distillationSpec"],C);let v=i(e,["tuningDataStats"]);if(v!=null)s(t,["tuningDataStats"],v);let R=i(e,["encryptionSpec"]);if(R!=null)s(t,["encryptionSpec"],R);let P=i(e,["partnerModelTuningSpec"]);if(P!=null)s(t,["partnerModelTuningSpec"],P);let x=i(e,["customBaseModel"]);if(x!=null)s(t,["customBaseModel"],x);let I=i(e,["evaluateDatasetRuns"]);if(I!=null){let ce=I;if(Array.isArray(ce))ce=ce.map((X)=>X);s(t,["evaluateDatasetRuns"],ce)}let U=i(e,["experiment"]);if(U!=null)s(t,["experiment"],U);let A=i(e,["fullFineTuningSpec"]);if(A!=null)s(t,["fullFineTuningSpec"],A);let M=i(e,["labels"]);if(M!=null)s(t,["labels"],M);let G=i(e,["outputUri"]);if(G!=null)s(t,["outputUri"],G);let K=i(e,["pipelineJob"]);if(K!=null)s(t,["pipelineJob"],K);let W=i(e,["serviceAccount"]);if(W!=null)s(t,["serviceAccount"],W);let z=i(e,["tunedModelDisplayName"]);if(z!=null)s(t,["tunedModelDisplayName"],z);let q=i(e,["tuningJobState"]);if(q!=null)s(t,["tuningJobState"],q);let V=i(e,["veoTuningSpec"]);if(V!=null)s(t,["veoTuningSpec"],V);let te=i(e,["distillationSamplingSpec"]);if(te!=null)s(t,["distillationSamplingSpec"],te);let Re=i(e,["tuningJobMetadata"]);if(Re!=null)s(t,["tuningJobMetadata"],Re);return t}function zf(e,n){let t={},o=i(e,["sdkHttpResponse"]);if(o!=null)s(t,["sdkHttpResponse"],o);let r=i(e,["name"]);if(r!=null)s(t,["name"],r);let l=i(e,["metadata"]);if(l!=null)s(t,["metadata"],l);let a=i(e,["done"]);if(a!=null)s(t,["done"],a);let f=i(e,["error"]);if(f!=null)s(t,["error"],f);return t}function fn(e,n){let t={},o=i(e,["gcsUri"]);if(o!=null)s(t,["validationDatasetUri"],o);let r=i(e,["vertexDatasetResource"]);if(r!=null)s(t,["validationDatasetUri"],r);return t}class Zi extends ne{constructor(e){super();this.apiClient=e,this.list=async(n={})=>new fe(oe.PAGED_ITEM_TUNING_JOBS,(t)=>this.listInternal(t),await this.listInternal(n),n),this.get=async(n)=>await this.getInternal(n),this.tune=async(n)=>{var t;if(this.apiClient.isVertexAI())if(n.baseModel.startsWith("projects/")){let o={tunedModelName:n.baseModel};if((t=n.config)===null||t===void 0?void 0:t.preTunedModelCheckpointId)o.checkpointId=n.config.preTunedModelCheckpointId;let r=Object.assign(Object.assign({},n),{preTunedModel:o});return r.baseModel=void 0,await this.tuneInternal(r)}else{let o=Object.assign({},n);return await this.tuneInternal(o)}else{let o=Object.assign({},n),r=await this.tuneMldevInternal(o),l="";if(r.metadata!==void 0&&r.metadata.tunedModel!==void 0)l=r.metadata.tunedModel;else if(r.name!==void 0&&r.name.includes("/operations/"))l=r.name.split("/operations/")[0];return{name:l,state:pn.JOB_STATE_QUEUED}}}}async getInternal(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=Bf(e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>xn(c))}else{let d=Hf(e);return a=S("{name}",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>Wf(c))}}async listInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI()){let a=bf(e);return r=S("tuningJobs",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json().then((d)=>{let c=d;return c.sdkHttpResponse={headers:f.headers},c})),o.then((f)=>{let d=$f(f),c=new $o;return Object.assign(c,d),c})}else throw Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async cancel(e){var n,t,o,r;let l,a="",f={};if(this.apiClient.isVertexAI()){let d=Uf(e);return a=S("{name}:cancel",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=Gf(c),p=new Tn;return Object.assign(p,m),p})}else{let d=xf(e);return a=S("{name}:cancel",d._url),f=d._query,delete d._url,delete d._query,l=this.apiClient.request({path:a,queryParams:f,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(o=e.config)===null||o===void 0?void 0:o.httpOptions,abortSignal:(r=e.config)===null||r===void 0?void 0:r.abortSignal}).then((c)=>c.json().then((m)=>{let p=m;return p.sdkHttpResponse={headers:c.headers},p})),l.then((c)=>{let m=Lf(c),p=new Tn;return Object.assign(p,m),p})}}async tuneInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI()){let a=qf(e,e);return r=S("tuningJobs",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json().then((d)=>{let c=d;return c.sdkHttpResponse={headers:f.headers},c})),o.then((f)=>xn(f))}else throw Error("This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).")}async tuneMldevInternal(e){var n,t;let o,r="",l={};if(this.apiClient.isVertexAI())throw Error("This method is only supported by the Gemini Developer API.");else{let a=Vf(e);return r=S("tunedModels",a._url),l=a._query,delete a._url,delete a._query,o=this.apiClient.request({path:r,queryParams:l,body:JSON.stringify(a),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(t=e.config)===null||t===void 0?void 0:t.abortSignal}).then((f)=>f.json().then((d)=>{let c=d;return c.sdkHttpResponse={headers:f.headers},c})),o.then((f)=>zf(f))}}}var ji=8388608,er=3,nr=1000,tr=2,le="x-goog-upload-status";async function Xf(e,n,t,o){var r;let l=await or(e,n,t,o),a=await(l===null||l===void 0?void 0:l.json());if(((r=l===null||l===void 0?void 0:l.headers)===null||r===void 0?void 0:r[le])!=="final")throw Error("Failed to upload file: Upload status is not finalized.");return a.file}async function Qf(e,n,t,o){var r;let l=await or(e,n,t,o),a=await(l===null||l===void 0?void 0:l.json());if(((r=l===null||l===void 0?void 0:l.headers)===null||r===void 0?void 0:r[le])!=="final")throw Error("Failed to upload file: Upload status is not finalized.");let f=Ln(a),d=new nn;return Object.assign(d,f),d}async function or(e,n,t,o){var r,l,a;let f=n,d=(o===null||o===void 0?void 0:o.baseUrl)||((r=t.clientOptions.httpOptions)===null||r===void 0?void 0:r.baseUrl);if(d){let y=new URL(d),E=new URL(n);E.protocol=y.protocol,E.host=y.host,E.port=y.port,f=E.toString()}let c=0,m=0,p=new me(new Response),g="upload";c=e.size;while(m<c){let y=Math.min(ji,c-m),E=e.slice(m,m+y);if(m+y>=c)g+=", finalize";let T=0,_=nr;while(T<er){let C=Object.assign(Object.assign({},(o===null||o===void 0?void 0:o.headers)||{}),{"X-Goog-Upload-Command":g,"X-Goog-Upload-Offset":String(m),"Content-Length":String(y)});if(p=await t.request({path:"",body:E,httpMethod:"POST",httpOptions:Object.assign(Object.assign({},o),{apiVersion:"",baseUrl:f,headers:C})}),(l=p===null||p===void 0?void 0:p.headers)===null||l===void 0?void 0:l[le])break;T++,await ir(_),_=_*tr}if(m+=y,((a=p===null||p===void 0?void 0:p.headers)===null||a===void 0?void 0:a[le])!=="active")break;if(c<=m)throw Error("All content has been uploaded, but the upload status is not finalized.")}return p}async function Zf(e){return{size:e.size,type:e.type}}function ir(e){return new Promise((n)=>setTimeout(n,e))}class rr{async stat(e){let n={size:0,type:void 0};if(typeof e==="string"){let t=await en.stat(e);return n.size=t.size,n.type=this.inferMimeType(e),n}else return await Zf(e)}async upload(e,n,t,o){if(typeof e==="string")return await this.uploadFileFromPath(e,n,t,o);else return Xf(e,n,t,o)}async uploadToFileSearchStore(e,n,t,o){if(typeof e==="string")return await this.uploadFileToFileSearchStoreFromPath(e,n,t,o);else return Qf(e,n,t,o)}inferMimeType(e){let n=e.slice(e.lastIndexOf(".")+1);return{aac:"audio/aac",abw:"application/x-abiword",arc:"application/x-freearc",avi:"video/x-msvideo",azw:"application/vnd.amazon.ebook",bin:"application/octet-stream",bmp:"image/bmp",bz:"application/x-bzip",bz2:"application/x-bzip2",csh:"application/x-csh",css:"text/css",csv:"text/csv",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",eot:"application/vnd.ms-fontobject",epub:"application/epub+zip",gz:"application/gzip",gif:"image/gif",htm:"text/html",html:"text/html",ico:"image/vnd.microsoft.icon",ics:"text/calendar",jar:"application/java-archive",jpeg:"image/jpeg",jpg:"image/jpeg",js:"text/javascript",json:"application/json",jsonld:"application/ld+json",kml:"application/vnd.google-earth.kml+xml",kmz:"application/vnd.google-earth.kmz+xml",mjs:"text/javascript",mp3:"audio/mpeg",mp4:"video/mp4",mpeg:"video/mpeg",mpkg:"application/vnd.apple.installer+xml",odt:"application/vnd.oasis.opendocument.text",oga:"audio/ogg",ogv:"video/ogg",ogx:"application/ogg",opus:"audio/opus",otf:"font/otf",png:"image/png",pdf:"application/pdf",php:"application/x-httpd-php",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",rar:"application/vnd.rar",rtf:"application/rtf",sh:"application/x-sh",svg:"image/svg+xml",swf:"application/x-shockwave-flash",tar:"application/x-tar",tif:"image/tiff",tiff:"image/tiff",ts:"video/mp2t",ttf:"font/ttf",txt:"text/plain",vsd:"application/vnd.visio",wav:"audio/wav",weba:"audio/webm",webm:"video/webm",webp:"image/webp",woff:"font/woff",woff2:"font/woff2",xhtml:"application/xhtml+xml",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xml:"application/xml",xul:"application/vnd.mozilla.xul+xml",zip:"application/zip","3gp":"video/3gpp","3g2":"video/3gpp2","7z":"application/x-7z-compressed"}[n.toLowerCase()]}async uploadFileFromPath(e,n,t,o){var r;let l=await this.uploadFileFromPathInternal(e,n,t,o),a=await(l===null||l===void 0?void 0:l.json());if(((r=l===null||l===void 0?void 0:l.headers)===null||r===void 0?void 0:r[le])!=="final")throw Error("Failed to upload file: Upload status is not finalized.");return a.file}async uploadFileToFileSearchStoreFromPath(e,n,t,o){var r;let l=await this.uploadFileFromPathInternal(e,n,t,o),a=await(l===null||l===void 0?void 0:l.json());if(((r=l===null||l===void 0?void 0:l.headers)===null||r===void 0?void 0:r[le])!=="final")throw Error("Failed to upload file: Upload status is not finalized.");let f=Ln(a),d=new nn;return Object.assign(d,f),d}async uploadFileFromPathInternal(e,n,t,o){var r,l,a;let f=n,d=(o===null||o===void 0?void 0:o.baseUrl)||((r=t.clientOptions.httpOptions)===null||r===void 0?void 0:r.baseUrl);if(d){let T=new URL(d),_=new URL(n);_.protocol=T.protocol,_.host=T.host,_.port=T.port,f=_.toString()}let c=0,m=0,p=new me(new Response),g="upload",y,E=Vo.basename(e);try{if(y=await en.open(e,"r"),!y)throw Error("Failed to open file");c=(await y.stat()).size;while(m<c){let T=Math.min(ji,c-m);if(m+T>=c)g+=", finalize";let _=new Uint8Array(T),{bytesRead:C}=await y.read(_,0,T,m);if(C!==T)throw Error(`Failed to read ${T} bytes from file at offset ${m}. bytes actually read: ${C}`);let v=new Blob([_]),R=0,P=nr;while(R<er){let x=Object.assign(Object.assign({},(o===null||o===void 0?void 0:o.headers)||{}),{"X-Goog-Upload-Command":g,"X-Goog-Upload-Offset":String(m),"Content-Length":String(C),"X-Goog-Upload-File-Name":E});if(p=await t.request({path:"",body:v,httpMethod:"POST",httpOptions:Object.assign(Object.assign({},o),{apiVersion:"",baseUrl:f,headers:x})}),(l=p===null||p===void 0?void 0:p.headers)===null||l===void 0?void 0:l[le])break;R++,await ir(P),P=P*tr}if(m+=C,((a=p===null||p===void 0?void 0:p.headers)===null||a===void 0?void 0:a[le])!=="active")break;if(c<=m)throw Error("All content has been uploaded, but the upload status is not finalized.")}return p}finally{if(y)await y.close()}}}class sr extends Ti{async registerFiles(e){if(typeof process>"u"||!process.versions||!process.versions.node)throw Error("registerFiles is only supported in Node.js environments.");let t=await e.auth.getRequestHeaders(),o=e.config||{},r=o.httpOptions||{},l=Object.assign({},r.headers||{});if(t)if(typeof t[Symbol.iterator]==="function")for(let[a,f]of t)l[a]=f;else for(let[a,f]of Object.entries(t))l[a]=f;return this._registerFiles({uris:e.uris,config:Object.assign(Object.assign({},o),{httpOptions:Object.assign(Object.assign({},r),{headers:l})})})}}var jf="gl-node/";function ec(e){var n;if(e.enterprise!==void 0||e.vertexai!==void 0){if(e.enterprise!==void 0&&e.vertexai!==void 0&&e.enterprise!==e.vertexai)throw Error("enterprise and vertexAI flags have conflicting values, please set enterprise value only.");return(n=e.enterprise)!==null&&n!==void 0?n:e.vertexai}let t=ae("GOOGLE_GENAI_USE_ENTERPRISE"),o=ae("GOOGLE_GENAI_USE_VERTEXAI"),r=Go(t),l=Go(o);if(t!==void 0&&o!==void 0&&r!==l)console.warn("Warning: Both GOOGLE_GENAI_USE_ENTERPRISE and GOOGLE_GENAI_USE_VERTEXAI are set with conflicting values. The value of GOOGLE_GENAI_USE_ENTERPRISE will be used.");if(t!==void 0)return r;if(o!==void 0)return l;return!1}class pe{getNextGenClient(){var e;let n=this.httpOptions;if(this._nextGenClient===void 0)this._nextGenClient=new F({baseURL:this.apiClient.getBaseUrl(),apiKey:this.apiKey,apiVersion:this.apiClient.getApiVersion(),clientAdapter:this.apiClient,defaultHeaders:this.apiClient.getDefaultHeaders(),timeout:n===null||n===void 0?void 0:n.timeout,maxRetries:(e=n===null||n===void 0?void 0:n.retryOptions)===null||e===void 0?void 0:e.attempts});if(n===null||n===void 0?void 0:n.extraBody)console.warn("GoogleGenAI.interactions: Client level httpOptions.extraBody is not supported by the interactions client and will be ignored.");return this._nextGenClient}get interactions(){if(this._interactions!==void 0)return this._interactions;return console.warn("GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions."),this._interactions=this.getNextGenClient().interactions,this._interactions}get webhooks(){if(this._webhooks!==void 0)return this._webhooks;return this._webhooks=this.getNextGenClient().webhooks,this._webhooks}constructor(e){var n,t,o,r;if((e.project||e.location)&&e.apiKey)throw Error("Project/location and API key are mutually exclusive in the client initializer.");this.vertexai=ec(e);let l=nc(),a=ae("GOOGLE_CLOUD_PROJECT"),f=ae("GOOGLE_CLOUD_LOCATION");if(this.apiKey=(n=e.apiKey)!==null&&n!==void 0?n:l,this.project=(t=e.project)!==null&&t!==void 0?t:a,this.location=(o=e.location)!==null&&o!==void 0?o:f,!this.vertexai&&!this.apiKey)console.warn("API key should be set when using the Gemini API.");if(this.vertexai){if((r=e.googleAuthOptions)===null||r===void 0?void 0:r.credentials)console.debug("The user provided Google Cloud credentials will take precedence over the API key from the environment variable."),this.apiKey=void 0;if((a||f)&&e.apiKey)console.debug("The user provided Vertex AI API key will take precedence over the project/location from the environment variables."),this.project=void 0,this.location=void 0;else if((e.project||e.location)&&l)console.debug("The user provided project/location will take precedence over the API key from the environment variables."),this.apiKey=void 0;else if((a||f)&&l)console.debug("The project/location from the environment variables will take precedence over the API key from the environment variables."),this.apiKey=void 0;if(!this.location&&!this.apiKey)this.location="global"}let d=yr(e.httpOptions,this.vertexai,ae("GOOGLE_VERTEX_BASE_URL"),ae("GOOGLE_GEMINI_BASE_URL"));if(d)if(e.httpOptions)e.httpOptions.baseUrl=d;else e.httpOptions={baseUrl:d};this.apiVersion=e.apiVersion,this.httpOptions=e.httpOptions;let c=new Wi({apiKey:this.apiKey,googleAuthOptions:e.googleAuthOptions});this.apiClient=new Pi({auth:c,project:this.project,location:this.location,apiVersion:this.apiVersion,apiKey:this.apiKey,vertexai:this.vertexai,httpOptions:this.httpOptions,userAgentExtra:jf+process.version,uploader:new rr,downloader:new zi}),this.models=new Li(this.apiClient),this.live=new xi(this.apiClient,c,new Xi),this.batches=new hi(this.apiClient),this.chats=new yi(this.models,this.apiClient),this.caches=new mi(this.apiClient),this.files=new sr(this.apiClient),this.operations=new Gi(this.apiClient),this.authTokens=new ki(this.apiClient),this.tunings=new Zi(this.apiClient),this.fileSearchStores=new Vi(this.apiClient)}}function ae(e){var n,t,o;return(o=(t=(n=process===null||process===void 0?void 0:process.env)===null||n===void 0?void 0:n[e])===null||t===void 0?void 0:t.trim())!==null&&o!==void 0?o:void 0}function Go(e){if(e===void 0)return!1;return e.toLowerCase()==="true"}function nc(){let e=ae("GOOGLE_API_KEY"),n=ae("GEMINI_API_KEY");if(e&&n)console.warn("Both GOOGLE_API_KEY and GEMINI_API_KEY are set. Using GOOGLE_API_KEY.");return e||n||void 0}function we(e){return e.thought===!0}function Ae(e,n){if(typeof n==="string"&&n.length>0)return n;return e}var tc=/^[A-Za-z0-9+/]+={0,2}$/;function oc(e){if(!e)return!1;if(e.length%4!==0)return!1;return tc.test(e)}function ot(e,n){return e&&oc(n)?n:void 0}function it(e){return e.startsWith("claude-")||e.startsWith("gpt-oss-")}function ar(e){let n=e.toLowerCase().match(/^gemini(?:-live)?-(\d+)/);if(!n)return;return Number.parseInt(n[1],10)}function ic(e){let n=ar(e);if(n!==void 0)return n>=3;return!0}function Ne(e,n){let t=[],o=(l)=>{if(!it(e.id))return l;return l.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,64)},r=N(n.messages,e,o);for(let l of r)if(l.role==="user")if(typeof l.content==="string")t.push({role:"user",parts:[{text:u(l.content)}]});else{let a=l.content.map((f)=>{if(f.type==="text")return{text:u(f.text)};else return{inlineData:{mimeType:f.mimeType,data:f.data}}});if(a.length===0)continue;t.push({role:"user",parts:a})}else if(l.role==="assistant"){let a=[],f=l.provider===e.provider&&l.model===e.id;for(let d of l.content)if(d.type==="text"){if(!d.text||d.text.trim()==="")continue;let c=ot(f,d.textSignature);a.push({text:u(d.text),...c&&{thoughtSignature:c}})}else if(d.type==="thinking"){if(!d.thinking||d.thinking.trim()==="")continue;if(f){let c=ot(f,d.thinkingSignature);a.push({thought:!0,text:u(d.thinking),...c&&{thoughtSignature:c}})}else a.push({text:u(d.thinking)})}else if(d.type==="toolCall"){let c=ot(f,d.thoughtSignature),m={functionCall:{name:d.name,args:d.arguments??{},...it(e.id)?{id:d.id}:{}},...c&&{thoughtSignature:c}};a.push(m)}if(a.length===0)continue;t.push({role:"model",parts:a})}else if(l.role==="toolResult"){let f=l.content.filter((C)=>C.type==="text").map((C)=>C.text).join(`
15
+ `),d=e.input.includes("image")?l.content.filter((C)=>C.type==="image"):[],c=f.length>0,m=d.length>0,p=ic(e.id),g=c?u(f):m?"(see attached image)":"",y=d.map((C)=>({inlineData:{mimeType:C.mimeType,data:C.data}})),E=it(e.id),T={functionResponse:{name:l.toolName,response:l.isError?{error:g}:{output:g},...m&&p&&{parts:y},...E?{id:l.toolCallId}:{}}},_=t[t.length-1];if(_?.role==="user"&&_.parts?.some((C)=>C.functionResponse))_.parts.push(T);else t.push({role:"user",parts:[T]});if(m&&!p)t.push({role:"user",parts:[{text:"Tool result image:"},...y]})}return t}var rc=new Set(["$schema","$id","$anchor","$dynamicAnchor","$vocabulary","$comment","$defs","definitions"]);function ur(e){if(typeof e!=="object"||e===null||Array.isArray(e))return e;let n={};for(let[t,o]of Object.entries(e)){if(rc.has(t))continue;n[t]=ur(o)}return n}function Ge(e,n=!1){if(e.length===0)return;return[{functionDeclarations:e.map((t)=>({name:t.name,description:t.description,...n?{parameters:ur(t.parameters)}:{parametersJsonSchema:t.parameters}}))}]}function ke(e){let n=ar(e);return n!==void 0&&n>=3}function lr(e){switch(e){case"auto":return ue.AUTO;case"none":return ue.NONE;case"any":return ue.ANY;default:return ue.AUTO}}function De(e,n,t){let o=e.some((r)=>w(r,t)===!0);if(n==="none"||n==="any")return lr(n);if(o)return ue.VALIDATED;return n?lr(n):void 0}function Le(e){switch(e){case k.STOP:return"stop";case k.MAX_TOKENS:return"length";case k.BLOCKLIST:case k.PROHIBITED_CONTENT:case k.SPII:case k.SAFETY:case k.IMAGE_SAFETY:case k.IMAGE_PROHIBITED_CONTENT:case k.IMAGE_RECITATION:case k.IMAGE_OTHER:case k.RECITATION:case k.FINISH_REASON_UNSPECIFIED:case k.OTHER:case k.LANGUAGE:case k.MALFORMED_FUNCTION_CALL:case k.UNEXPECTED_TOOL_CALL:case k.NO_IMAGE:return"error";default:throw Error(`Unhandled stop reason: ${e}`)}}
16
+ export{H,Qe,pe,we,Ae,Ne,Ge,ke,De,Le};