swerasty_editor 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,286 +0,0 @@
1
- (function(ge,N){typeof exports=="object"&&typeof module<"u"?N(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],N):(ge=typeof globalThis<"u"?globalThis:ge||self,N(ge.SwerastyEditor={},ge.React))})(this,function(ge,N){"use strict";var ut={exports:{}},Me={};/**
2
- * @license React
3
- * react-jsx-runtime.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var Wt;function Bi(){if(Wt)return Me;Wt=1;var t=N,e=Symbol.for("react.element"),n=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,s=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function a(u,c,d){var f,h={},p=null,m=null;d!==void 0&&(p=""+d),c.key!==void 0&&(p=""+c.key),c.ref!==void 0&&(m=c.ref);for(f in c)o.call(c,f)&&!l.hasOwnProperty(f)&&(h[f]=c[f]);if(u&&u.defaultProps)for(f in c=u.defaultProps,c)h[f]===void 0&&(h[f]=c[f]);return{$$typeof:e,type:u,key:p,ref:m,props:h,_owner:s.current}}return Me.Fragment=n,Me.jsx=a,Me.jsxs=a,Me}var ke={};/**
10
- * @license React
11
- * react-jsx-runtime.development.js
12
- *
13
- * Copyright (c) Facebook, Inc. and its affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var Yt;function Ji(){return Yt||(Yt=1,process.env.NODE_ENV!=="production"&&function(){var t=N,e=Symbol.for("react.element"),n=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),l=Symbol.for("react.profiler"),a=Symbol.for("react.provider"),u=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),T=Symbol.iterator,E="@@iterator";function v(y){if(y===null||typeof y!="object")return null;var I=T&&y[T]||y[E];return typeof I=="function"?I:null}var S=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function _(y){{for(var I=arguments.length,P=new Array(I>1?I-1:0),b=1;b<I;b++)P[b-1]=arguments[b];C("error",y,P)}}function C(y,I,P){{var b=S.ReactDebugCurrentFrame,J=b.getStackAddendum();J!==""&&(I+="%s",P=P.concat([J]));var Y=P.map(function(H){return String(H)});Y.unshift("Warning: "+I),Function.prototype.apply.call(console[y],console,Y)}}var x=!1,R=!1,M=!1,k=!1,V=!1,w;w=Symbol.for("react.module.reference");function L(y){return!!(typeof y=="string"||typeof y=="function"||y===o||y===l||V||y===s||y===d||y===f||k||y===m||x||R||M||typeof y=="object"&&y!==null&&(y.$$typeof===p||y.$$typeof===h||y.$$typeof===a||y.$$typeof===u||y.$$typeof===c||y.$$typeof===w||y.getModuleId!==void 0))}function B(y,I,P){var b=y.displayName;if(b)return b;var J=I.displayName||I.name||"";return J!==""?P+"("+J+")":P}function $(y){return y.displayName||"Context"}function F(y){if(y==null)return null;if(typeof y.tag=="number"&&_("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof y=="function")return y.displayName||y.name||null;if(typeof y=="string")return y;switch(y){case o:return"Fragment";case n:return"Portal";case l:return"Profiler";case s:return"StrictMode";case d:return"Suspense";case f:return"SuspenseList"}if(typeof y=="object")switch(y.$$typeof){case u:var I=y;return $(I)+".Consumer";case a:var P=y;return $(P._context)+".Provider";case c:return B(y,y.render,"ForwardRef");case h:var b=y.displayName||null;return b!==null?b:F(y.type)||"Memo";case p:{var J=y,Y=J._payload,H=J._init;try{return F(H(Y))}catch{return null}}}return null}var O=Object.assign,D=0,W,K,se,we,Le,Fe,pe;function Ai(){}Ai.__reactDisabledLog=!0;function cf(){{if(D===0){W=console.log,K=console.info,se=console.warn,we=console.error,Le=console.group,Fe=console.groupCollapsed,pe=console.groupEnd;var y={configurable:!0,enumerable:!0,value:Ai,writable:!0};Object.defineProperties(console,{info:y,log:y,warn:y,error:y,group:y,groupCollapsed:y,groupEnd:y})}D++}}function ff(){{if(D--,D===0){var y={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},y,{value:W}),info:O({},y,{value:K}),warn:O({},y,{value:se}),error:O({},y,{value:we}),group:O({},y,{value:Le}),groupCollapsed:O({},y,{value:Fe}),groupEnd:O({},y,{value:pe})})}D<0&&_("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Lt=S.ReactCurrentDispatcher,Ft;function st(y,I,P){{if(Ft===void 0)try{throw Error()}catch(J){var b=J.stack.trim().match(/\n( *(at )?)/);Ft=b&&b[1]||""}return`
18
- `+Ft+y}}var Vt=!1,rt;{var pf=typeof WeakMap=="function"?WeakMap:Map;rt=new pf}function Ri(y,I){if(!y||Vt)return"";{var P=rt.get(y);if(P!==void 0)return P}var b;Vt=!0;var J=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Y;Y=Lt.current,Lt.current=null,cf();try{if(I){var H=function(){throw Error()};if(Object.defineProperty(H.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(H,[])}catch(ne){b=ne}Reflect.construct(y,[],H)}else{try{H.call()}catch(ne){b=ne}y.call(H.prototype)}}else{try{throw Error()}catch(ne){b=ne}y()}}catch(ne){if(ne&&b&&typeof ne.stack=="string"){for(var G=ne.stack.split(`
19
- `),te=b.stack.split(`
20
- `),z=G.length-1,X=te.length-1;z>=1&&X>=0&&G[z]!==te[X];)X--;for(;z>=1&&X>=0;z--,X--)if(G[z]!==te[X]){if(z!==1||X!==1)do if(z--,X--,X<0||G[z]!==te[X]){var re=`
21
- `+G[z].replace(" at new "," at ");return y.displayName&&re.includes("<anonymous>")&&(re=re.replace("<anonymous>",y.displayName)),typeof y=="function"&&rt.set(y,re),re}while(z>=1&&X>=0);break}}}finally{Vt=!1,Lt.current=Y,ff(),Error.prepareStackTrace=J}var Ne=y?y.displayName||y.name:"",ve=Ne?st(Ne):"";return typeof y=="function"&&rt.set(y,ve),ve}function hf(y,I,P){return Ri(y,!1)}function mf(y){var I=y.prototype;return!!(I&&I.isReactComponent)}function lt(y,I,P){if(y==null)return"";if(typeof y=="function")return Ri(y,mf(y));if(typeof y=="string")return st(y);switch(y){case d:return st("Suspense");case f:return st("SuspenseList")}if(typeof y=="object")switch(y.$$typeof){case c:return hf(y.render);case h:return lt(y.type,I,P);case p:{var b=y,J=b._payload,Y=b._init;try{return lt(Y(J),I,P)}catch{}}}return""}var Ve=Object.prototype.hasOwnProperty,wi={},Pi=S.ReactDebugCurrentFrame;function at(y){if(y){var I=y._owner,P=lt(y.type,y._source,I?I.type:null);Pi.setExtraStackFrame(P)}else Pi.setExtraStackFrame(null)}function gf(y,I,P,b,J){{var Y=Function.call.bind(Ve);for(var H in y)if(Y(y,H)){var G=void 0;try{if(typeof y[H]!="function"){var te=Error((b||"React class")+": "+P+" type `"+H+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof y[H]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw te.name="Invariant Violation",te}G=y[H](I,H,b,P,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(z){G=z}G&&!(G instanceof Error)&&(at(J),_("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",b||"React class",P,H,typeof G),at(null)),G instanceof Error&&!(G.message in wi)&&(wi[G.message]=!0,at(J),_("Failed %s type: %s",P,G.message),at(null))}}}var yf=Array.isArray;function Gt(y){return yf(y)}function Tf(y){{var I=typeof Symbol=="function"&&Symbol.toStringTag,P=I&&y[Symbol.toStringTag]||y.constructor.name||"Object";return P}}function vf(y){try{return Ni(y),!1}catch{return!0}}function Ni(y){return""+y}function Mi(y){if(vf(y))return _("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Tf(y)),Ni(y)}var ki=S.ReactCurrentOwner,_f={key:!0,ref:!0,__self:!0,__source:!0},Di,bi;function Ef(y){if(Ve.call(y,"ref")){var I=Object.getOwnPropertyDescriptor(y,"ref").get;if(I&&I.isReactWarning)return!1}return y.ref!==void 0}function Cf(y){if(Ve.call(y,"key")){var I=Object.getOwnPropertyDescriptor(y,"key").get;if(I&&I.isReactWarning)return!1}return y.key!==void 0}function xf(y,I){typeof y.ref=="string"&&ki.current}function Sf(y,I){{var P=function(){Di||(Di=!0,_("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",I))};P.isReactWarning=!0,Object.defineProperty(y,"key",{get:P,configurable:!0})}}function If(y,I){{var P=function(){bi||(bi=!0,_("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",I))};P.isReactWarning=!0,Object.defineProperty(y,"ref",{get:P,configurable:!0})}}var Af=function(y,I,P,b,J,Y,H){var G={$$typeof:e,type:y,key:I,ref:P,props:H,_owner:Y};return G._store={},Object.defineProperty(G._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(G,"_self",{configurable:!1,enumerable:!1,writable:!1,value:b}),Object.defineProperty(G,"_source",{configurable:!1,enumerable:!1,writable:!1,value:J}),Object.freeze&&(Object.freeze(G.props),Object.freeze(G)),G};function Rf(y,I,P,b,J){{var Y,H={},G=null,te=null;P!==void 0&&(Mi(P),G=""+P),Cf(I)&&(Mi(I.key),G=""+I.key),Ef(I)&&(te=I.ref,xf(I,J));for(Y in I)Ve.call(I,Y)&&!_f.hasOwnProperty(Y)&&(H[Y]=I[Y]);if(y&&y.defaultProps){var z=y.defaultProps;for(Y in z)H[Y]===void 0&&(H[Y]=z[Y])}if(G||te){var X=typeof y=="function"?y.displayName||y.name||"Unknown":y;G&&Sf(H,X),te&&If(H,X)}return Af(y,G,te,J,b,ki.current,H)}}var Ht=S.ReactCurrentOwner,Ui=S.ReactDebugCurrentFrame;function Pe(y){if(y){var I=y._owner,P=lt(y.type,y._source,I?I.type:null);Ui.setExtraStackFrame(P)}else Ui.setExtraStackFrame(null)}var qt;qt=!1;function Bt(y){return typeof y=="object"&&y!==null&&y.$$typeof===e}function Li(){{if(Ht.current){var y=F(Ht.current.type);if(y)return`
22
-
23
- Check the render method of \``+y+"`."}return""}}function wf(y){return""}var Fi={};function Pf(y){{var I=Li();if(!I){var P=typeof y=="string"?y:y.displayName||y.name;P&&(I=`
24
-
25
- Check the top-level render call using <`+P+">.")}return I}}function Vi(y,I){{if(!y._store||y._store.validated||y.key!=null)return;y._store.validated=!0;var P=Pf(I);if(Fi[P])return;Fi[P]=!0;var b="";y&&y._owner&&y._owner!==Ht.current&&(b=" It was passed a child from "+F(y._owner.type)+"."),Pe(y),_('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',P,b),Pe(null)}}function Gi(y,I){{if(typeof y!="object")return;if(Gt(y))for(var P=0;P<y.length;P++){var b=y[P];Bt(b)&&Vi(b,I)}else if(Bt(y))y._store&&(y._store.validated=!0);else if(y){var J=v(y);if(typeof J=="function"&&J!==y.entries)for(var Y=J.call(y),H;!(H=Y.next()).done;)Bt(H.value)&&Vi(H.value,I)}}}function Nf(y){{var I=y.type;if(I==null||typeof I=="string")return;var P;if(typeof I=="function")P=I.propTypes;else if(typeof I=="object"&&(I.$$typeof===c||I.$$typeof===h))P=I.propTypes;else return;if(P){var b=F(I);gf(P,y.props,"prop",b,y)}else if(I.PropTypes!==void 0&&!qt){qt=!0;var J=F(I);_("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",J||"Unknown")}typeof I.getDefaultProps=="function"&&!I.getDefaultProps.isReactClassApproved&&_("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Mf(y){{for(var I=Object.keys(y.props),P=0;P<I.length;P++){var b=I[P];if(b!=="children"&&b!=="key"){Pe(y),_("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",b),Pe(null);break}}y.ref!==null&&(Pe(y),_("Invalid attribute `ref` supplied to `React.Fragment`."),Pe(null))}}var Hi={};function qi(y,I,P,b,J,Y){{var H=L(y);if(!H){var G="";(y===void 0||typeof y=="object"&&y!==null&&Object.keys(y).length===0)&&(G+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var te=wf();te?G+=te:G+=Li();var z;y===null?z="null":Gt(y)?z="array":y!==void 0&&y.$$typeof===e?(z="<"+(F(y.type)||"Unknown")+" />",G=" Did you accidentally export a JSX literal instead of a component?"):z=typeof y,_("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",z,G)}var X=Rf(y,I,P,J,Y);if(X==null)return X;if(H){var re=I.children;if(re!==void 0)if(b)if(Gt(re)){for(var Ne=0;Ne<re.length;Ne++)Gi(re[Ne],y);Object.freeze&&Object.freeze(re)}else _("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Gi(re,y)}if(Ve.call(I,"key")){var ve=F(y),ne=Object.keys(I).filter(function(Ff){return Ff!=="key"}),Jt=ne.length>0?"{key: someKey, "+ne.join(": ..., ")+": ...}":"{key: someKey}";if(!Hi[ve+Jt]){var Lf=ne.length>0?"{"+ne.join(": ..., ")+": ...}":"{}";_(`A props object containing a "key" prop is being spread into JSX:
26
- let props = %s;
27
- <%s {...props} />
28
- React keys must be passed directly to JSX without using spread:
29
- let props = %s;
30
- <%s key={someKey} {...props} />`,Jt,ve,Lf,ve),Hi[ve+Jt]=!0}}return y===o?Mf(X):Nf(X),X}}function kf(y,I,P){return qi(y,I,P,!0)}function Df(y,I,P){return qi(y,I,P,!1)}var bf=Df,Uf=kf;ke.Fragment=o,ke.jsx=bf,ke.jsxs=Uf}()),ke}process.env.NODE_ENV==="production"?ut.exports=Bi():ut.exports=Ji();var g=ut.exports;const Wi=({isOpen:t,onClose:e,onInsert:n})=>{const[o,s]=N.useState(3),[l,a]=N.useState(3);if(!t)return null;const u=()=>{o>0&&l>0&&n(o,l)};return g.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black bg-opacity-50 backdrop-blur-sm",onClick:e,children:g.jsxs("div",{className:"bg-white rounded-lg shadow-xl p-6 w-full max-w-sm",onClick:c=>c.stopPropagation(),children:[g.jsx("h3",{className:"text-lg font-semibold text-gray-800 mb-4",children:"Insert Table"}),g.jsxs("div",{className:"space-y-4",children:[g.jsxs("div",{children:[g.jsx("label",{htmlFor:"rows",className:"block text-sm font-medium text-gray-700 mb-1",children:"Rows"}),g.jsx("input",{type:"number",id:"rows",value:o,onChange:c=>s(Math.max(1,parseInt(c.target.value,10))),className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 text-black"})]}),g.jsxs("div",{children:[g.jsx("label",{htmlFor:"cols",className:"block text-sm font-medium text-gray-700 mb-1",children:"Columns"}),g.jsx("input",{type:"number",id:"cols",value:l,onChange:c=>a(Math.max(1,parseInt(c.target.value,10))),className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 text-black"})]})]}),g.jsxs("div",{className:"mt-6 flex justify-end space-x-3",children:[g.jsx("button",{onClick:e,className:"px-4 py-2 bg-gray-200 text-gray-800 rounded-md hover:bg-gray-300 transition",children:"Cancel"}),g.jsx("button",{onClick:u,className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition",children:"Insert"})]})]})})},Ot={"10px":"1","12px":"2","14px":"3","16px":"4","20px":"5","24px":"6","32px":"7"},Yi=({onOpenHandwritingModal:t,onApplyStyle:e,onUndo:n,onRedo:o,canUndo:s,canRedo:l})=>{const[a,u]=N.useState(!1),c=N.useRef(null),d=p=>{var T;const m=(T=p.target.files)==null?void 0:T[0];if(m){const E=new FileReader;E.onload=v=>{var _;const S=(_=v.target)==null?void 0:_.result;e("insertImage",S)},E.readAsDataURL(m)}p.target&&(p.target.value="")},f=(p,m)=>{let T='<table style="border-collapse: collapse; width: 100%;">';for(let E=0;E<p;E++){T+="<tr>";for(let v=0;v<m;v++)T+='<td style="border: 1px solid #ccc; padding: 8px;"><br></td>';T+="</tr>"}T+="</table><p><br></p>",e("insertHTML",T),u(!1)},h=(p,m,T)=>{p.preventDefault(),e(m,T)};return g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"bg-gray-50 p-2 flex flex-wrap items-center gap-2 border-b border-gray-200 sticky top-0 z-10",children:[g.jsxs("div",{className:"relative",children:[g.jsxs("select",{onChange:p=>e("fontName",p.target.value),defaultValue:"Arial",className:"appearance-none bg-white border border-gray-300 rounded px-2 py-1.5 pr-6 text-sm text-black outline-none focus:ring-1 focus:ring-blue-500",children:[g.jsx("option",{value:"Arial",children:"Arial"}),g.jsx("option",{value:"Verdana",children:"Verdana"}),g.jsx("option",{value:"Times New Roman",children:"Times New Roman"}),g.jsx("option",{value:"Courier New",children:"Courier New"}),g.jsx("option",{value:"Georgia",children:"Georgia"})]}),g.jsx("div",{className:"absolute right-2 top-1/2 transform -translate-y-1/2 pointer-events-none",children:g.jsx("svg",{className:"w-4 h-4 text-black",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 9l-7 7-7-7"})})})]}),g.jsxs("div",{className:"relative",children:[g.jsx("select",{onChange:p=>e("fontSize",Ot[p.target.value]),defaultValue:"14px",className:"appearance-none bg-white border border-gray-300 rounded px-2 py-1.5 pr-6 text-sm text-black outline-none focus:ring-1 focus:ring-blue-500",children:Object.keys(Ot).map(p=>g.jsx("option",{value:p,children:p==="14px"?"Normal":p},p))}),g.jsx("div",{className:"absolute right-2 top-1/2 transform -translate-y-1/2 pointer-events-none",children:g.jsx("svg",{className:"w-4 h-4 text-black",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 9l-7 7-7-7"})})})]}),g.jsxs("div",{className:"flex bg-white border border-gray-300 rounded overflow-hidden shadow-sm text-black",children:[g.jsx("button",{onClick:p=>{p.preventDefault(),n()},disabled:!s,onMouseDown:p=>p.preventDefault(),title:"Undo",className:"p-2 hover:bg-gray-100 disabled:opacity-30 disabled:hover:bg-transparent border-r border-gray-200",children:g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M10 19l-7-7m0 0l7-7m-7 7h18"})})}),g.jsx("button",{onClick:p=>{p.preventDefault(),o()},disabled:!l,onMouseDown:p=>p.preventDefault(),title:"Redo",className:"p-2 hover:bg-gray-100 disabled:opacity-30 disabled:hover:bg-transparent",children:g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M14 5l7 7m0 0l-7 7m7-7H3"})})})]}),g.jsxs("div",{className:"flex bg-white border border-gray-300 rounded overflow-hidden shadow-sm text-black",children:[g.jsx("button",{onClick:p=>h(p,"bold"),onMouseDown:p=>p.preventDefault(),title:"Bold",className:"p-2 hover:bg-gray-100 border-r border-gray-200",children:g.jsxs("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:"2.5",children:[g.jsx("path",{d:"M6 4h8a4 4 0 014 4 4 4 0 01-4 4H6z"}),g.jsx("path",{d:"M6 12h9a4 4 0 014 4 4 4 0 01-4 4H6z"})]})}),g.jsx("button",{onClick:p=>h(p,"italic"),onMouseDown:p=>p.preventDefault(),title:"Italic",className:"p-2 hover:bg-gray-100 border-r border-gray-200",children:g.jsxs("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:"2.5",children:[g.jsx("path",{d:"M11 4h6"}),g.jsx("path",{d:"M7 20h6"}),g.jsx("path",{d:"M14 4L10 20"})]})}),g.jsx("button",{onClick:p=>h(p,"underline"),onMouseDown:p=>p.preventDefault(),title:"Underline",className:"p-2 hover:bg-gray-100 border-r border-gray-200",children:g.jsxs("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:"2.5",children:[g.jsx("path",{d:"M6 3v7a6 6 0 006 6 6 6 0 006-6V3"}),g.jsx("path",{d:"M4 21h16"})]})}),g.jsx("button",{onClick:p=>h(p,"strikeThrough"),onMouseDown:p=>p.preventDefault(),title:"Strikethrough",className:"p-2 hover:bg-gray-100",children:g.jsxs("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:"2.5",children:[g.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),g.jsx("path",{d:"M7 5v9a5 5 0 0 0 10 0v-9"}),g.jsx("path",{d:"M5 12h14"})]})})]}),g.jsxs("div",{className:"flex bg-white border border-gray-300 rounded overflow-hidden shadow-sm text-black",children:[g.jsxs("label",{className:"p-2 hover:bg-gray-100 border-r border-gray-200 cursor-pointer relative",title:"Font Color",children:[g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M7 20l4-16 4 16m-8.25-8h8.5M4 20h16"})}),g.jsx("input",{type:"color",defaultValue:"#000000",onInput:p=>e("foreColor",p.target.value),onMouseDown:p=>p.preventDefault(),className:"opacity-0 absolute inset-0 cursor-pointer w-full h-full"})]}),g.jsxs("label",{className:"p-2 hover:bg-gray-100 cursor-pointer relative",title:"Highlight Color",children:[g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.5L15.232 5.232z"})}),g.jsx("input",{type:"color",defaultValue:"#FFFF00",onInput:p=>e("backColor",p.target.value),onMouseDown:p=>p.preventDefault(),className:"opacity-0 absolute inset-0 cursor-pointer w-full h-full"})]})]}),g.jsxs("div",{className:"flex bg-white border border-gray-300 rounded overflow-hidden shadow-sm text-black",children:[g.jsx("button",{onClick:p=>h(p,"insertOrderedList"),onMouseDown:p=>p.preventDefault(),title:"Ordered List",className:"p-2 hover:bg-gray-100 border-r border-gray-200",children:g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:"2",children:g.jsx("path",{d:"M10 6h10M10 12h10M10 18h10M4 6h1v4M4 12h1v4M4 18h1v4"})})}),g.jsx("button",{onClick:p=>h(p,"insertUnorderedList"),onMouseDown:p=>p.preventDefault(),title:"Unordered List",className:"p-2 hover:bg-gray-100",children:g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:"2",children:g.jsx("path",{d:"M9 6h11M9 12h11M9 18h11M5 6h.01M5 12h.01M5 18h.01"})})})]}),g.jsxs("div",{className:"flex bg-white border border-gray-300 rounded overflow-hidden shadow-sm text-black",children:[g.jsx("button",{onClick:()=>{var p;return(p=c.current)==null?void 0:p.click()},onMouseDown:p=>p.preventDefault(),title:"Insert Image",className:"p-2 hover:bg-gray-100 border-r border-gray-200",children:g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})})}),g.jsx("input",{type:"file",ref:c,onChange:d,accept:"image/*",className:"hidden"}),g.jsx("button",{onClick:()=>u(!0),onMouseDown:p=>p.preventDefault(),title:"Insert Table",className:"p-2 hover:bg-gray-100",children:g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M3 6h18M3 12h18M3 18h18M8 3v18m8-18v18"})})})]}),g.jsx("div",{className:"flex items-center ml-auto pl-2 border-l border-gray-200",children:g.jsx("button",{onClick:t,title:"AI Math Pad",className:"p-2 bg-blue-50 border border-blue-200 hover:bg-blue-100 text-blue-600 rounded flex items-center justify-center transition-colors shadow-sm",children:g.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[g.jsx("path",{d:"M3 12h2l4 8 4-16h6"}),g.jsx("path",{d:"m17 8 4 4"}),g.jsx("path",{d:"m21 8-4 4"})]})})})]}),g.jsx(Wi,{isOpen:a,onClose:()=>u(!1),onInsert:f})]})},$t=N.forwardRef(({onHistoryChange:t},e)=>{const n=N.useRef(null),o=N.useRef(null),[s,l]=N.useState(!1),[a,u]=N.useState(!1),c=N.useRef(null),[d,f]=N.useState([]),[h,p]=N.useState(-1),m=N.useCallback(()=>{const _=n.current,C=c.current;if(!_||!C)return;const x=C.getImageData(0,0,_.width,_.height),R=d.slice(0,h+1);f([...R,x]),p(R.length)},[d,h]);N.useEffect(()=>{t==null||t({canUndo:h>0,canRedo:h<d.length-1})},[d,h,t]),N.useEffect(()=>{const _=n.current,C=o.current;if(!_||!C)return;c.current=_.getContext("2d");const x=new ResizeObserver(R=>{var L;const{width:M,height:k}=R[0].contentRect,V=(L=c.current)==null?void 0:L.getImageData(0,0,_.width,_.height);_.width=M,_.height=k;const w=c.current;if(w&&(w.lineCap="round",w.strokeStyle="#000",w.lineWidth=2,V&&w.putImageData(V,0,0)),d.length===0){const B=w==null?void 0:w.getImageData(0,0,M,k);B&&(f([B]),p(0))}});return x.observe(C),()=>{x.disconnect()}},[]);const T=_=>{const C=n.current;if(!C)return{offsetX:0,offsetY:0};const x=C.getBoundingClientRect(),R="touches"in _?_.touches[0].clientX:_.clientX,M="touches"in _?_.touches[0].clientY:_.clientY;return{offsetX:R-x.left,offsetY:M-x.top}},E=_=>{_.preventDefault();const C=c.current;if(!C)return;const{offsetX:x,offsetY:R}=T(_);C.beginPath(),C.moveTo(x,R),l(!0),u(!0)},v=()=>{const _=c.current;!_||!s||(_.closePath(),l(!1),m())},S=_=>{if(!s||!c.current)return;_.preventDefault();const{offsetX:C,offsetY:x}=T(_);c.current.lineTo(C,x),c.current.stroke()};return N.useImperativeHandle(e,()=>({clear(){const _=c.current,C=n.current;if(_&&C){_.clearRect(0,0,C.width,C.height),u(!1);const x=_.getImageData(0,0,C.width,C.height);f([x]),p(0)}},undo(){var _;if(h>0){const C=h-1;p(C);const x=d[C];(_=c.current)==null||_.putImageData(x,0,0),u(C>0)}},redo(){var _;if(h<d.length-1){const C=h+1;p(C);const x=d[C];(_=c.current)==null||_.putImageData(x,0,0),u(!0)}},getTrimmedImageData(){const _=n.current,C=c.current;if(!a||!_||!C)return null;const x=_.width,R=_.height,k=C.getImageData(0,0,x,R).data;let V=x,w=R,L=0,B=0;for(let K=0;K<R;K++)for(let se=0;se<x;se++)k[(x*K+se)*4+3]>0&&(V=Math.min(V,se),w=Math.min(w,K),L=Math.max(L,se),B=Math.max(B,K));if(V===x)return null;const $=15;V=Math.max(0,V-$),w=Math.max(0,w-$),L=Math.min(x,L+$),B=Math.min(R,B+$);const F=L-V,O=B-w,D=document.createElement("canvas");D.width=F,D.height=O;const W=D.getContext("2d");return W?(W.drawImage(_,V,w,F,O,0,0,F,O),D.toDataURL("image/png")):null}})),g.jsx("div",{ref:o,className:"absolute inset-0 w-full h-full",children:g.jsx("canvas",{ref:n,onMouseDown:E,onMouseUp:v,onMouseMove:S,onMouseLeave:v,onTouchStart:E,onTouchEnd:v,onTouchMove:S,className:"w-full h-full",style:{cursor:"crosshair",touchAction:"none"}})})});$t.displayName="Canvas";/**
31
- * @license
32
- * Copyright 2025 Google LLC
33
- * SPDX-License-Identifier: Apache-2.0
34
- */let Oi,$i;function Ki(){return{geminiUrl:Oi,vertexUrl:$i}}function zi(t,e,n,o){var s,l;if(!(t!=null&&t.baseUrl)){const a=Ki();return e?(s=a.vertexUrl)!==null&&s!==void 0?s:n:(l=a.geminiUrl)!==null&&l!==void 0?l:o}return t.baseUrl}/**
35
- * @license
36
- * Copyright 2025 Google LLC
37
- * SPDX-License-Identifier: Apache-2.0
38
- */class de{}function A(t,e){const n=/\{([^}]+)\}/g;return t.replace(n,(o,s)=>{if(Object.prototype.hasOwnProperty.call(e,s)){const l=e[s];return l!=null?String(l):""}else throw new Error(`Key '${s}' not found in valueMap.`)})}function r(t,e,n){for(let l=0;l<e.length-1;l++){const a=e[l];if(a.endsWith("[]")){const u=a.slice(0,-2);if(!(u in t))if(Array.isArray(n))t[u]=Array.from({length:n.length},()=>({}));else throw new Error(`Value must be a list given an array path ${a}`);if(Array.isArray(t[u])){const c=t[u];if(Array.isArray(n))for(let d=0;d<c.length;d++){const f=c[d];r(f,e.slice(l+1),n[d])}else for(const d of c)r(d,e.slice(l+1),n)}return}else if(a.endsWith("[0]")){const u=a.slice(0,-3);u in t||(t[u]=[{}]);const c=t[u];r(c[0],e.slice(l+1),n);return}(!t[a]||typeof t[a]!="object")&&(t[a]={}),t=t[a]}const o=e[e.length-1],s=t[o];if(s!==void 0){if(!n||typeof n=="object"&&Object.keys(n).length===0||n===s)return;if(typeof s=="object"&&typeof n=="object"&&s!==null&&n!==null)Object.assign(s,n);else throw new Error(`Cannot set value for an existing key. Key: ${o}`)}else o==="_self"&&typeof n=="object"&&n!==null&&!Array.isArray(n)?Object.assign(t,n):t[o]=n}function i(t,e,n=void 0){try{if(e.length===1&&e[0]==="_self")return t;for(let o=0;o<e.length;o++){if(typeof t!="object"||t===null)return n;const s=e[o];if(s.endsWith("[]")){const l=s.slice(0,-2);if(l in t){const a=t[l];return Array.isArray(a)?a.map(u=>i(u,e.slice(o+1),n)):n}else return n}else t=t[s]}return t}catch(o){if(o instanceof TypeError)return n;throw o}}function Xi(t,e){for(const[n,o]of Object.entries(e)){const s=n.split("."),l=o.split("."),a=new Set;let u=-1;for(let c=0;c<s.length;c++)if(s[c]==="*"){u=c;break}if(u!==-1&&l.length>u)for(let c=u;c<l.length;c++){const d=l[c];d!=="*"&&!d.endsWith("[]")&&!d.endsWith("[0]")&&a.add(d)}dt(t,s,l,0,a)}}function dt(t,e,n,o,s){if(o>=e.length||typeof t!="object"||t===null)return;const l=e[o];if(l.endsWith("[]")){const a=l.slice(0,-2),u=t;if(a in u&&Array.isArray(u[a]))for(const c of u[a])dt(c,e,n,o+1,s)}else if(l==="*"){if(typeof t=="object"&&t!==null&&!Array.isArray(t)){const a=t,u=Object.keys(a).filter(d=>!d.startsWith("_")&&!s.has(d)),c={};for(const d of u)c[d]=a[d];for(const[d,f]of Object.entries(c)){const h=[];for(const p of n.slice(o))p==="*"?h.push(d):h.push(p);r(a,h,f)}for(const d of u)delete a[d]}}else{const a=t;l in a&&dt(a[l],e,n,o+1,s)}}/**
39
- * @license
40
- * Copyright 2025 Google LLC
41
- * SPDX-License-Identifier: Apache-2.0
42
- */function ct(t){if(typeof t!="string")throw new Error("fromImageBytes must be a string");return t}/**
43
- * @license
44
- * Copyright 2025 Google LLC
45
- * SPDX-License-Identifier: Apache-2.0
46
- */function Qi(t){const e={},n=i(t,["operationName"]);n!=null&&r(e,["operationName"],n);const o=i(t,["resourceName"]);return o!=null&&r(e,["_url","resourceName"],o),e}function Zi(t){const e={},n=i(t,["name"]);n!=null&&r(e,["name"],n);const o=i(t,["metadata"]);o!=null&&r(e,["metadata"],o);const s=i(t,["done"]);s!=null&&r(e,["done"],s);const l=i(t,["error"]);l!=null&&r(e,["error"],l);const a=i(t,["response","generateVideoResponse"]);return a!=null&&r(e,["response"],es(a)),e}function ji(t){const e={},n=i(t,["name"]);n!=null&&r(e,["name"],n);const o=i(t,["metadata"]);o!=null&&r(e,["metadata"],o);const s=i(t,["done"]);s!=null&&r(e,["done"],s);const l=i(t,["error"]);l!=null&&r(e,["error"],l);const a=i(t,["response"]);return a!=null&&r(e,["response"],ts(a)),e}function es(t){const e={},n=i(t,["generatedSamples"]);if(n!=null){let l=n;Array.isArray(l)&&(l=l.map(a=>ns(a))),r(e,["generatedVideos"],l)}const o=i(t,["raiMediaFilteredCount"]);o!=null&&r(e,["raiMediaFilteredCount"],o);const s=i(t,["raiMediaFilteredReasons"]);return s!=null&&r(e,["raiMediaFilteredReasons"],s),e}function ts(t){const e={},n=i(t,["videos"]);if(n!=null){let l=n;Array.isArray(l)&&(l=l.map(a=>os(a))),r(e,["generatedVideos"],l)}const o=i(t,["raiMediaFilteredCount"]);o!=null&&r(e,["raiMediaFilteredCount"],o);const s=i(t,["raiMediaFilteredReasons"]);return s!=null&&r(e,["raiMediaFilteredReasons"],s),e}function ns(t){const e={},n=i(t,["video"]);return n!=null&&r(e,["video"],us(n)),e}function os(t){const e={},n=i(t,["_self"]);return n!=null&&r(e,["video"],ds(n)),e}function is(t){const e={},n=i(t,["operationName"]);return n!=null&&r(e,["_url","operationName"],n),e}function ss(t){const e={},n=i(t,["operationName"]);return n!=null&&r(e,["_url","operationName"],n),e}function rs(t){const e={},n=i(t,["name"]);n!=null&&r(e,["name"],n);const o=i(t,["metadata"]);o!=null&&r(e,["metadata"],o);const s=i(t,["done"]);s!=null&&r(e,["done"],s);const l=i(t,["error"]);l!=null&&r(e,["error"],l);const a=i(t,["response"]);return a!=null&&r(e,["response"],ls(a)),e}function ls(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["parent"]);o!=null&&r(e,["parent"],o);const s=i(t,["documentName"]);return s!=null&&r(e,["documentName"],s),e}function Kt(t){const e={},n=i(t,["name"]);n!=null&&r(e,["name"],n);const o=i(t,["metadata"]);o!=null&&r(e,["metadata"],o);const s=i(t,["done"]);s!=null&&r(e,["done"],s);const l=i(t,["error"]);l!=null&&r(e,["error"],l);const a=i(t,["response"]);return a!=null&&r(e,["response"],as(a)),e}function as(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["parent"]);o!=null&&r(e,["parent"],o);const s=i(t,["documentName"]);return s!=null&&r(e,["documentName"],s),e}function us(t){const e={},n=i(t,["uri"]);n!=null&&r(e,["uri"],n);const o=i(t,["encodedVideo"]);o!=null&&r(e,["videoBytes"],ct(o));const s=i(t,["encoding"]);return s!=null&&r(e,["mimeType"],s),e}function ds(t){const e={},n=i(t,["gcsUri"]);n!=null&&r(e,["uri"],n);const o=i(t,["bytesBase64Encoded"]);o!=null&&r(e,["videoBytes"],ct(o));const s=i(t,["mimeType"]);return s!=null&&r(e,["mimeType"],s),e}/**
47
- * @license
48
- * Copyright 2025 Google LLC
49
- * SPDX-License-Identifier: Apache-2.0
50
- */var zt;(function(t){t.OUTCOME_UNSPECIFIED="OUTCOME_UNSPECIFIED",t.OUTCOME_OK="OUTCOME_OK",t.OUTCOME_FAILED="OUTCOME_FAILED",t.OUTCOME_DEADLINE_EXCEEDED="OUTCOME_DEADLINE_EXCEEDED"})(zt||(zt={}));var Xt;(function(t){t.LANGUAGE_UNSPECIFIED="LANGUAGE_UNSPECIFIED",t.PYTHON="PYTHON"})(Xt||(Xt={}));var Qt;(function(t){t.SCHEDULING_UNSPECIFIED="SCHEDULING_UNSPECIFIED",t.SILENT="SILENT",t.WHEN_IDLE="WHEN_IDLE",t.INTERRUPT="INTERRUPT"})(Qt||(Qt={}));var he;(function(t){t.TYPE_UNSPECIFIED="TYPE_UNSPECIFIED",t.STRING="STRING",t.NUMBER="NUMBER",t.INTEGER="INTEGER",t.BOOLEAN="BOOLEAN",t.ARRAY="ARRAY",t.OBJECT="OBJECT",t.NULL="NULL"})(he||(he={}));var Zt;(function(t){t.MODE_UNSPECIFIED="MODE_UNSPECIFIED",t.MODE_DYNAMIC="MODE_DYNAMIC"})(Zt||(Zt={}));var jt;(function(t){t.API_SPEC_UNSPECIFIED="API_SPEC_UNSPECIFIED",t.SIMPLE_SEARCH="SIMPLE_SEARCH",t.ELASTIC_SEARCH="ELASTIC_SEARCH"})(jt||(jt={}));var en;(function(t){t.AUTH_TYPE_UNSPECIFIED="AUTH_TYPE_UNSPECIFIED",t.NO_AUTH="NO_AUTH",t.API_KEY_AUTH="API_KEY_AUTH",t.HTTP_BASIC_AUTH="HTTP_BASIC_AUTH",t.GOOGLE_SERVICE_ACCOUNT_AUTH="GOOGLE_SERVICE_ACCOUNT_AUTH",t.OAUTH="OAUTH",t.OIDC_AUTH="OIDC_AUTH"})(en||(en={}));var tn;(function(t){t.HTTP_IN_UNSPECIFIED="HTTP_IN_UNSPECIFIED",t.HTTP_IN_QUERY="HTTP_IN_QUERY",t.HTTP_IN_HEADER="HTTP_IN_HEADER",t.HTTP_IN_PATH="HTTP_IN_PATH",t.HTTP_IN_BODY="HTTP_IN_BODY",t.HTTP_IN_COOKIE="HTTP_IN_COOKIE"})(tn||(tn={}));var nn;(function(t){t.PHISH_BLOCK_THRESHOLD_UNSPECIFIED="PHISH_BLOCK_THRESHOLD_UNSPECIFIED",t.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",t.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",t.BLOCK_HIGH_AND_ABOVE="BLOCK_HIGH_AND_ABOVE",t.BLOCK_HIGHER_AND_ABOVE="BLOCK_HIGHER_AND_ABOVE",t.BLOCK_VERY_HIGH_AND_ABOVE="BLOCK_VERY_HIGH_AND_ABOVE",t.BLOCK_ONLY_EXTREMELY_HIGH="BLOCK_ONLY_EXTREMELY_HIGH"})(nn||(nn={}));var on;(function(t){t.THINKING_LEVEL_UNSPECIFIED="THINKING_LEVEL_UNSPECIFIED",t.LOW="LOW",t.MEDIUM="MEDIUM",t.HIGH="HIGH",t.MINIMAL="MINIMAL"})(on||(on={}));var sn;(function(t){t.HARM_CATEGORY_UNSPECIFIED="HARM_CATEGORY_UNSPECIFIED",t.HARM_CATEGORY_HARASSMENT="HARM_CATEGORY_HARASSMENT",t.HARM_CATEGORY_HATE_SPEECH="HARM_CATEGORY_HATE_SPEECH",t.HARM_CATEGORY_SEXUALLY_EXPLICIT="HARM_CATEGORY_SEXUALLY_EXPLICIT",t.HARM_CATEGORY_DANGEROUS_CONTENT="HARM_CATEGORY_DANGEROUS_CONTENT",t.HARM_CATEGORY_CIVIC_INTEGRITY="HARM_CATEGORY_CIVIC_INTEGRITY",t.HARM_CATEGORY_IMAGE_HATE="HARM_CATEGORY_IMAGE_HATE",t.HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT="HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT",t.HARM_CATEGORY_IMAGE_HARASSMENT="HARM_CATEGORY_IMAGE_HARASSMENT",t.HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT="HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT",t.HARM_CATEGORY_JAILBREAK="HARM_CATEGORY_JAILBREAK"})(sn||(sn={}));var rn;(function(t){t.HARM_BLOCK_METHOD_UNSPECIFIED="HARM_BLOCK_METHOD_UNSPECIFIED",t.SEVERITY="SEVERITY",t.PROBABILITY="PROBABILITY"})(rn||(rn={}));var ln;(function(t){t.HARM_BLOCK_THRESHOLD_UNSPECIFIED="HARM_BLOCK_THRESHOLD_UNSPECIFIED",t.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",t.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",t.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",t.BLOCK_NONE="BLOCK_NONE",t.OFF="OFF"})(ln||(ln={}));var an;(function(t){t.FINISH_REASON_UNSPECIFIED="FINISH_REASON_UNSPECIFIED",t.STOP="STOP",t.MAX_TOKENS="MAX_TOKENS",t.SAFETY="SAFETY",t.RECITATION="RECITATION",t.LANGUAGE="LANGUAGE",t.OTHER="OTHER",t.BLOCKLIST="BLOCKLIST",t.PROHIBITED_CONTENT="PROHIBITED_CONTENT",t.SPII="SPII",t.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",t.IMAGE_SAFETY="IMAGE_SAFETY",t.UNEXPECTED_TOOL_CALL="UNEXPECTED_TOOL_CALL",t.IMAGE_PROHIBITED_CONTENT="IMAGE_PROHIBITED_CONTENT",t.NO_IMAGE="NO_IMAGE",t.IMAGE_RECITATION="IMAGE_RECITATION",t.IMAGE_OTHER="IMAGE_OTHER"})(an||(an={}));var un;(function(t){t.HARM_PROBABILITY_UNSPECIFIED="HARM_PROBABILITY_UNSPECIFIED",t.NEGLIGIBLE="NEGLIGIBLE",t.LOW="LOW",t.MEDIUM="MEDIUM",t.HIGH="HIGH"})(un||(un={}));var dn;(function(t){t.HARM_SEVERITY_UNSPECIFIED="HARM_SEVERITY_UNSPECIFIED",t.HARM_SEVERITY_NEGLIGIBLE="HARM_SEVERITY_NEGLIGIBLE",t.HARM_SEVERITY_LOW="HARM_SEVERITY_LOW",t.HARM_SEVERITY_MEDIUM="HARM_SEVERITY_MEDIUM",t.HARM_SEVERITY_HIGH="HARM_SEVERITY_HIGH"})(dn||(dn={}));var cn;(function(t){t.URL_RETRIEVAL_STATUS_UNSPECIFIED="URL_RETRIEVAL_STATUS_UNSPECIFIED",t.URL_RETRIEVAL_STATUS_SUCCESS="URL_RETRIEVAL_STATUS_SUCCESS",t.URL_RETRIEVAL_STATUS_ERROR="URL_RETRIEVAL_STATUS_ERROR",t.URL_RETRIEVAL_STATUS_PAYWALL="URL_RETRIEVAL_STATUS_PAYWALL",t.URL_RETRIEVAL_STATUS_UNSAFE="URL_RETRIEVAL_STATUS_UNSAFE"})(cn||(cn={}));var fn;(function(t){t.BLOCKED_REASON_UNSPECIFIED="BLOCKED_REASON_UNSPECIFIED",t.SAFETY="SAFETY",t.OTHER="OTHER",t.BLOCKLIST="BLOCKLIST",t.PROHIBITED_CONTENT="PROHIBITED_CONTENT",t.IMAGE_SAFETY="IMAGE_SAFETY",t.MODEL_ARMOR="MODEL_ARMOR",t.JAILBREAK="JAILBREAK"})(fn||(fn={}));var pn;(function(t){t.TRAFFIC_TYPE_UNSPECIFIED="TRAFFIC_TYPE_UNSPECIFIED",t.ON_DEMAND="ON_DEMAND",t.PROVISIONED_THROUGHPUT="PROVISIONED_THROUGHPUT"})(pn||(pn={}));var Ge;(function(t){t.MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",t.TEXT="TEXT",t.IMAGE="IMAGE",t.AUDIO="AUDIO"})(Ge||(Ge={}));var hn;(function(t){t.MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",t.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",t.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",t.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH"})(hn||(hn={}));var mn;(function(t){t.TUNING_MODE_UNSPECIFIED="TUNING_MODE_UNSPECIFIED",t.TUNING_MODE_FULL="TUNING_MODE_FULL",t.TUNING_MODE_PEFT_ADAPTER="TUNING_MODE_PEFT_ADAPTER"})(mn||(mn={}));var gn;(function(t){t.ADAPTER_SIZE_UNSPECIFIED="ADAPTER_SIZE_UNSPECIFIED",t.ADAPTER_SIZE_ONE="ADAPTER_SIZE_ONE",t.ADAPTER_SIZE_TWO="ADAPTER_SIZE_TWO",t.ADAPTER_SIZE_FOUR="ADAPTER_SIZE_FOUR",t.ADAPTER_SIZE_EIGHT="ADAPTER_SIZE_EIGHT",t.ADAPTER_SIZE_SIXTEEN="ADAPTER_SIZE_SIXTEEN",t.ADAPTER_SIZE_THIRTY_TWO="ADAPTER_SIZE_THIRTY_TWO"})(gn||(gn={}));var ft;(function(t){t.JOB_STATE_UNSPECIFIED="JOB_STATE_UNSPECIFIED",t.JOB_STATE_QUEUED="JOB_STATE_QUEUED",t.JOB_STATE_PENDING="JOB_STATE_PENDING",t.JOB_STATE_RUNNING="JOB_STATE_RUNNING",t.JOB_STATE_SUCCEEDED="JOB_STATE_SUCCEEDED",t.JOB_STATE_FAILED="JOB_STATE_FAILED",t.JOB_STATE_CANCELLING="JOB_STATE_CANCELLING",t.JOB_STATE_CANCELLED="JOB_STATE_CANCELLED",t.JOB_STATE_PAUSED="JOB_STATE_PAUSED",t.JOB_STATE_EXPIRED="JOB_STATE_EXPIRED",t.JOB_STATE_UPDATING="JOB_STATE_UPDATING",t.JOB_STATE_PARTIALLY_SUCCEEDED="JOB_STATE_PARTIALLY_SUCCEEDED"})(ft||(ft={}));var yn;(function(t){t.TUNING_TASK_UNSPECIFIED="TUNING_TASK_UNSPECIFIED",t.TUNING_TASK_I2V="TUNING_TASK_I2V",t.TUNING_TASK_T2V="TUNING_TASK_T2V",t.TUNING_TASK_R2V="TUNING_TASK_R2V"})(yn||(yn={}));var Tn;(function(t){t.MEDIA_RESOLUTION_UNSPECIFIED="MEDIA_RESOLUTION_UNSPECIFIED",t.MEDIA_RESOLUTION_LOW="MEDIA_RESOLUTION_LOW",t.MEDIA_RESOLUTION_MEDIUM="MEDIA_RESOLUTION_MEDIUM",t.MEDIA_RESOLUTION_HIGH="MEDIA_RESOLUTION_HIGH",t.MEDIA_RESOLUTION_ULTRA_HIGH="MEDIA_RESOLUTION_ULTRA_HIGH"})(Tn||(Tn={}));var vn;(function(t){t.FEATURE_SELECTION_PREFERENCE_UNSPECIFIED="FEATURE_SELECTION_PREFERENCE_UNSPECIFIED",t.PRIORITIZE_QUALITY="PRIORITIZE_QUALITY",t.BALANCED="BALANCED",t.PRIORITIZE_COST="PRIORITIZE_COST"})(vn||(vn={}));var _n;(function(t){t.UNSPECIFIED="UNSPECIFIED",t.BLOCKING="BLOCKING",t.NON_BLOCKING="NON_BLOCKING"})(_n||(_n={}));var En;(function(t){t.MODE_UNSPECIFIED="MODE_UNSPECIFIED",t.MODE_DYNAMIC="MODE_DYNAMIC"})(En||(En={}));var Cn;(function(t){t.ENVIRONMENT_UNSPECIFIED="ENVIRONMENT_UNSPECIFIED",t.ENVIRONMENT_BROWSER="ENVIRONMENT_BROWSER"})(Cn||(Cn={}));var xn;(function(t){t.MODE_UNSPECIFIED="MODE_UNSPECIFIED",t.AUTO="AUTO",t.ANY="ANY",t.NONE="NONE",t.VALIDATED="VALIDATED"})(xn||(xn={}));var Sn;(function(t){t.BLOCK_LOW_AND_ABOVE="BLOCK_LOW_AND_ABOVE",t.BLOCK_MEDIUM_AND_ABOVE="BLOCK_MEDIUM_AND_ABOVE",t.BLOCK_ONLY_HIGH="BLOCK_ONLY_HIGH",t.BLOCK_NONE="BLOCK_NONE"})(Sn||(Sn={}));var In;(function(t){t.DONT_ALLOW="DONT_ALLOW",t.ALLOW_ADULT="ALLOW_ADULT",t.ALLOW_ALL="ALLOW_ALL"})(In||(In={}));var An;(function(t){t.auto="auto",t.en="en",t.ja="ja",t.ko="ko",t.hi="hi",t.zh="zh",t.pt="pt",t.es="es"})(An||(An={}));var Rn;(function(t){t.MASK_MODE_DEFAULT="MASK_MODE_DEFAULT",t.MASK_MODE_USER_PROVIDED="MASK_MODE_USER_PROVIDED",t.MASK_MODE_BACKGROUND="MASK_MODE_BACKGROUND",t.MASK_MODE_FOREGROUND="MASK_MODE_FOREGROUND",t.MASK_MODE_SEMANTIC="MASK_MODE_SEMANTIC"})(Rn||(Rn={}));var wn;(function(t){t.CONTROL_TYPE_DEFAULT="CONTROL_TYPE_DEFAULT",t.CONTROL_TYPE_CANNY="CONTROL_TYPE_CANNY",t.CONTROL_TYPE_SCRIBBLE="CONTROL_TYPE_SCRIBBLE",t.CONTROL_TYPE_FACE_MESH="CONTROL_TYPE_FACE_MESH"})(wn||(wn={}));var Pn;(function(t){t.SUBJECT_TYPE_DEFAULT="SUBJECT_TYPE_DEFAULT",t.SUBJECT_TYPE_PERSON="SUBJECT_TYPE_PERSON",t.SUBJECT_TYPE_ANIMAL="SUBJECT_TYPE_ANIMAL",t.SUBJECT_TYPE_PRODUCT="SUBJECT_TYPE_PRODUCT"})(Pn||(Pn={}));var Nn;(function(t){t.EDIT_MODE_DEFAULT="EDIT_MODE_DEFAULT",t.EDIT_MODE_INPAINT_REMOVAL="EDIT_MODE_INPAINT_REMOVAL",t.EDIT_MODE_INPAINT_INSERTION="EDIT_MODE_INPAINT_INSERTION",t.EDIT_MODE_OUTPAINT="EDIT_MODE_OUTPAINT",t.EDIT_MODE_CONTROLLED_EDITING="EDIT_MODE_CONTROLLED_EDITING",t.EDIT_MODE_STYLE="EDIT_MODE_STYLE",t.EDIT_MODE_BGSWAP="EDIT_MODE_BGSWAP",t.EDIT_MODE_PRODUCT_IMAGE="EDIT_MODE_PRODUCT_IMAGE"})(Nn||(Nn={}));var Mn;(function(t){t.FOREGROUND="FOREGROUND",t.BACKGROUND="BACKGROUND",t.PROMPT="PROMPT",t.SEMANTIC="SEMANTIC",t.INTERACTIVE="INTERACTIVE"})(Mn||(Mn={}));var kn;(function(t){t.ASSET="ASSET",t.STYLE="STYLE"})(kn||(kn={}));var Dn;(function(t){t.INSERT="INSERT",t.REMOVE="REMOVE",t.REMOVE_STATIC="REMOVE_STATIC",t.OUTPAINT="OUTPAINT"})(Dn||(Dn={}));var bn;(function(t){t.OPTIMIZED="OPTIMIZED",t.LOSSLESS="LOSSLESS"})(bn||(bn={}));var Un;(function(t){t.SUPERVISED_FINE_TUNING="SUPERVISED_FINE_TUNING",t.PREFERENCE_TUNING="PREFERENCE_TUNING"})(Un||(Un={}));var Ln;(function(t){t.STATE_UNSPECIFIED="STATE_UNSPECIFIED",t.STATE_PENDING="STATE_PENDING",t.STATE_ACTIVE="STATE_ACTIVE",t.STATE_FAILED="STATE_FAILED"})(Ln||(Ln={}));var Fn;(function(t){t.STATE_UNSPECIFIED="STATE_UNSPECIFIED",t.PROCESSING="PROCESSING",t.ACTIVE="ACTIVE",t.FAILED="FAILED"})(Fn||(Fn={}));var Vn;(function(t){t.SOURCE_UNSPECIFIED="SOURCE_UNSPECIFIED",t.UPLOADED="UPLOADED",t.GENERATED="GENERATED"})(Vn||(Vn={}));var Gn;(function(t){t.TURN_COMPLETE_REASON_UNSPECIFIED="TURN_COMPLETE_REASON_UNSPECIFIED",t.MALFORMED_FUNCTION_CALL="MALFORMED_FUNCTION_CALL",t.RESPONSE_REJECTED="RESPONSE_REJECTED",t.NEED_MORE_INPUT="NEED_MORE_INPUT"})(Gn||(Gn={}));var Hn;(function(t){t.MODALITY_UNSPECIFIED="MODALITY_UNSPECIFIED",t.TEXT="TEXT",t.IMAGE="IMAGE",t.VIDEO="VIDEO",t.AUDIO="AUDIO",t.DOCUMENT="DOCUMENT"})(Hn||(Hn={}));var qn;(function(t){t.VAD_SIGNAL_TYPE_UNSPECIFIED="VAD_SIGNAL_TYPE_UNSPECIFIED",t.VAD_SIGNAL_TYPE_SOS="VAD_SIGNAL_TYPE_SOS",t.VAD_SIGNAL_TYPE_EOS="VAD_SIGNAL_TYPE_EOS"})(qn||(qn={}));var Bn;(function(t){t.START_SENSITIVITY_UNSPECIFIED="START_SENSITIVITY_UNSPECIFIED",t.START_SENSITIVITY_HIGH="START_SENSITIVITY_HIGH",t.START_SENSITIVITY_LOW="START_SENSITIVITY_LOW"})(Bn||(Bn={}));var Jn;(function(t){t.END_SENSITIVITY_UNSPECIFIED="END_SENSITIVITY_UNSPECIFIED",t.END_SENSITIVITY_HIGH="END_SENSITIVITY_HIGH",t.END_SENSITIVITY_LOW="END_SENSITIVITY_LOW"})(Jn||(Jn={}));var Wn;(function(t){t.ACTIVITY_HANDLING_UNSPECIFIED="ACTIVITY_HANDLING_UNSPECIFIED",t.START_OF_ACTIVITY_INTERRUPTS="START_OF_ACTIVITY_INTERRUPTS",t.NO_INTERRUPTION="NO_INTERRUPTION"})(Wn||(Wn={}));var Yn;(function(t){t.TURN_COVERAGE_UNSPECIFIED="TURN_COVERAGE_UNSPECIFIED",t.TURN_INCLUDES_ONLY_ACTIVITY="TURN_INCLUDES_ONLY_ACTIVITY",t.TURN_INCLUDES_ALL_INPUT="TURN_INCLUDES_ALL_INPUT"})(Yn||(Yn={}));var On;(function(t){t.SCALE_UNSPECIFIED="SCALE_UNSPECIFIED",t.C_MAJOR_A_MINOR="C_MAJOR_A_MINOR",t.D_FLAT_MAJOR_B_FLAT_MINOR="D_FLAT_MAJOR_B_FLAT_MINOR",t.D_MAJOR_B_MINOR="D_MAJOR_B_MINOR",t.E_FLAT_MAJOR_C_MINOR="E_FLAT_MAJOR_C_MINOR",t.E_MAJOR_D_FLAT_MINOR="E_MAJOR_D_FLAT_MINOR",t.F_MAJOR_D_MINOR="F_MAJOR_D_MINOR",t.G_FLAT_MAJOR_E_FLAT_MINOR="G_FLAT_MAJOR_E_FLAT_MINOR",t.G_MAJOR_E_MINOR="G_MAJOR_E_MINOR",t.A_FLAT_MAJOR_F_MINOR="A_FLAT_MAJOR_F_MINOR",t.A_MAJOR_G_FLAT_MINOR="A_MAJOR_G_FLAT_MINOR",t.B_FLAT_MAJOR_G_MINOR="B_FLAT_MAJOR_G_MINOR",t.B_MAJOR_A_FLAT_MINOR="B_MAJOR_A_FLAT_MINOR"})(On||(On={}));var $n;(function(t){t.MUSIC_GENERATION_MODE_UNSPECIFIED="MUSIC_GENERATION_MODE_UNSPECIFIED",t.QUALITY="QUALITY",t.DIVERSITY="DIVERSITY",t.VOCALIZATION="VOCALIZATION"})($n||($n={}));var _e;(function(t){t.PLAYBACK_CONTROL_UNSPECIFIED="PLAYBACK_CONTROL_UNSPECIFIED",t.PLAY="PLAY",t.PAUSE="PAUSE",t.STOP="STOP",t.RESET_CONTEXT="RESET_CONTEXT"})(_e||(_e={}));class pt{constructor(e){const n={};for(const o of e.headers.entries())n[o[0]]=o[1];this.headers=n,this.responseInternal=e}json(){return this.responseInternal.json()}}class De{get text(){var e,n,o,s,l,a,u,c;if(((s=(o=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||o===void 0?void 0:o.parts)===null||s===void 0?void 0:s.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning text from the first one.");let d="",f=!1;const h=[];for(const p of(c=(u=(a=(l=this.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content)===null||u===void 0?void 0:u.parts)!==null&&c!==void 0?c:[]){for(const[m,T]of Object.entries(p))m!=="text"&&m!=="thought"&&m!=="thoughtSignature"&&(T!==null||T!==void 0)&&h.push(m);if(typeof p.text=="string"){if(typeof p.thought=="boolean"&&p.thought)continue;f=!0,d+=p.text}}return h.length>0&&console.warn(`there are non-text parts ${h} in the response, returning concatenation of all text parts. Please refer to the non text parts for a full response from model.`),f?d:void 0}get data(){var e,n,o,s,l,a,u,c;if(((s=(o=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||o===void 0?void 0:o.parts)===null||s===void 0?void 0:s.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning data from the first one.");let d="";const f=[];for(const h of(c=(u=(a=(l=this.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content)===null||u===void 0?void 0:u.parts)!==null&&c!==void 0?c:[]){for(const[p,m]of Object.entries(h))p!=="inlineData"&&(m!==null||m!==void 0)&&f.push(p);h.inlineData&&typeof h.inlineData.data=="string"&&(d+=atob(h.inlineData.data))}return f.length>0&&console.warn(`there are non-data parts ${f} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`),d.length>0?btoa(d):void 0}get functionCalls(){var e,n,o,s,l,a,u,c;if(((s=(o=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||o===void 0?void 0:o.parts)===null||s===void 0?void 0:s.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning function calls from the first one.");const d=(c=(u=(a=(l=this.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content)===null||u===void 0?void 0:u.parts)===null||c===void 0?void 0:c.filter(f=>f.functionCall).map(f=>f.functionCall).filter(f=>f!==void 0);if((d==null?void 0:d.length)!==0)return d}get executableCode(){var e,n,o,s,l,a,u,c,d;if(((s=(o=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||o===void 0?void 0:o.parts)===null||s===void 0?void 0:s.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning executable code from the first one.");const f=(c=(u=(a=(l=this.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content)===null||u===void 0?void 0:u.parts)===null||c===void 0?void 0:c.filter(h=>h.executableCode).map(h=>h.executableCode).filter(h=>h!==void 0);if((f==null?void 0:f.length)!==0)return(d=f==null?void 0:f[0])===null||d===void 0?void 0:d.code}get codeExecutionResult(){var e,n,o,s,l,a,u,c,d;if(((s=(o=(n=(e=this.candidates)===null||e===void 0?void 0:e[0])===null||n===void 0?void 0:n.content)===null||o===void 0?void 0:o.parts)===null||s===void 0?void 0:s.length)===0)return;this.candidates&&this.candidates.length>1&&console.warn("there are multiple candidates in the response, returning code execution result from the first one.");const f=(c=(u=(a=(l=this.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content)===null||u===void 0?void 0:u.parts)===null||c===void 0?void 0:c.filter(h=>h.codeExecutionResult).map(h=>h.codeExecutionResult).filter(h=>h!==void 0);if((f==null?void 0:f.length)!==0)return(d=f==null?void 0:f[0])===null||d===void 0?void 0:d.output}}class Kn{}class zn{}class cs{}class fs{}class ps{}class hs{}class Xn{}class Qn{}class Zn{}class ms{}class He{_fromAPIResponse({apiResponse:e,_isVertexAI:n}){const o=new He;let s;const l=e;return n?s=ji(l):s=Zi(l),Object.assign(o,s),o}}class jn{}class eo{}class to{}class no{}class gs{}class ys{}class Ts{}class ht{_fromAPIResponse({apiResponse:e,_isVertexAI:n}){const o=new ht,l=rs(e);return Object.assign(o,l),o}}class vs{}class _s{}class Es{}class oo{}class Cs{get text(){var e,n,o;let s="",l=!1;const a=[];for(const u of(o=(n=(e=this.serverContent)===null||e===void 0?void 0:e.modelTurn)===null||n===void 0?void 0:n.parts)!==null&&o!==void 0?o:[]){for(const[c,d]of Object.entries(u))c!=="text"&&c!=="thought"&&d!==null&&a.push(c);if(typeof u.text=="string"){if(typeof u.thought=="boolean"&&u.thought)continue;l=!0,s+=u.text}}return a.length>0&&console.warn(`there are non-text parts ${a} in the response, returning concatenation of all text parts. Please refer to the non text parts for a full response from model.`),l?s:void 0}get data(){var e,n,o;let s="";const l=[];for(const a of(o=(n=(e=this.serverContent)===null||e===void 0?void 0:e.modelTurn)===null||n===void 0?void 0:n.parts)!==null&&o!==void 0?o:[]){for(const[u,c]of Object.entries(a))u!=="inlineData"&&c!==null&&l.push(u);a.inlineData&&typeof a.inlineData.data=="string"&&(s+=atob(a.inlineData.data))}return l.length>0&&console.warn(`there are non-data parts ${l} in the response, returning concatenation of all data parts. Please refer to the non data parts for a full response from model.`),s.length>0?btoa(s):void 0}}class xs{get audioChunk(){if(this.serverContent&&this.serverContent.audioChunks&&this.serverContent.audioChunks.length>0)return this.serverContent.audioChunks[0]}}class mt{_fromAPIResponse({apiResponse:e,_isVertexAI:n}){const o=new mt,l=Kt(e);return Object.assign(o,l),o}}/**
51
- * @license
52
- * Copyright 2025 Google LLC
53
- * SPDX-License-Identifier: Apache-2.0
54
- */function q(t,e){if(!e||typeof e!="string")throw new Error("model is required and must be a string");if(e.includes("..")||e.includes("?")||e.includes("&"))throw new Error("invalid model parameter");if(t.isVertexAI()){if(e.startsWith("publishers/")||e.startsWith("projects/")||e.startsWith("models/"))return e;if(e.indexOf("/")>=0){const n=e.split("/",2);return`publishers/${n[0]}/models/${n[1]}`}else return`publishers/google/models/${e}`}else return e.startsWith("models/")||e.startsWith("tunedModels/")?e:`models/${e}`}function io(t,e){const n=q(t,e);return n?n.startsWith("publishers/")&&t.isVertexAI()?`projects/${t.getProject()}/locations/${t.getLocation()}/${n}`:n.startsWith("models/")&&t.isVertexAI()?`projects/${t.getProject()}/locations/${t.getLocation()}/publishers/google/${n}`:n:""}function so(t){return Array.isArray(t)?t.map(e=>qe(e)):[qe(t)]}function qe(t){if(typeof t=="object"&&t!==null)return t;throw new Error(`Could not parse input as Blob. Unsupported blob type: ${typeof t}`)}function ro(t){const e=qe(t);if(e.mimeType&&e.mimeType.startsWith("image/"))return e;throw new Error(`Unsupported mime type: ${e.mimeType}`)}function lo(t){const e=qe(t);if(e.mimeType&&e.mimeType.startsWith("audio/"))return e;throw new Error(`Unsupported mime type: ${e.mimeType}`)}function ao(t){if(t==null)throw new Error("PartUnion is required");if(typeof t=="object")return t;if(typeof t=="string")return{text:t};throw new Error(`Unsupported part type: ${typeof t}`)}function uo(t){if(t==null||Array.isArray(t)&&t.length===0)throw new Error("PartListUnion is required");return Array.isArray(t)?t.map(e=>ao(e)):[ao(t)]}function gt(t){return t!=null&&typeof t=="object"&&"parts"in t&&Array.isArray(t.parts)}function co(t){return t!=null&&typeof t=="object"&&"functionCall"in t}function fo(t){return t!=null&&typeof t=="object"&&"functionResponse"in t}function Z(t){if(t==null)throw new Error("ContentUnion is required");return gt(t)?t:{role:"user",parts:uo(t)}}function yt(t,e){if(!e)return[];if(t.isVertexAI()&&Array.isArray(e))return e.flatMap(n=>{const o=Z(n);return o.parts&&o.parts.length>0&&o.parts[0].text!==void 0?[o.parts[0].text]:[]});if(t.isVertexAI()){const n=Z(e);return n.parts&&n.parts.length>0&&n.parts[0].text!==void 0?[n.parts[0].text]:[]}return Array.isArray(e)?e.map(n=>Z(n)):[Z(e)]}function oe(t){if(t==null||Array.isArray(t)&&t.length===0)throw new Error("contents are required");if(!Array.isArray(t)){if(co(t)||fo(t))throw new Error("To specify functionCall or functionResponse parts, please wrap them in a Content object, specifying the role for them");return[Z(t)]}const e=[],n=[],o=gt(t[0]);for(const s of t){const l=gt(s);if(l!=o)throw new Error("Mixing Content and Parts is not supported, please group the parts into a the appropriate Content objects and specify the roles for them");if(l)e.push(s);else{if(co(s)||fo(s))throw new Error("To specify functionCall or functionResponse parts, please wrap them, and any other parts, in Content objects as appropriate, specifying the role for them");n.push(s)}}return o||e.push({role:"user",parts:uo(n)}),e}function Ss(t,e){t.includes("null")&&(e.nullable=!0);const n=t.filter(o=>o!=="null");if(n.length===1)e.type=Object.values(he).includes(n[0].toUpperCase())?n[0].toUpperCase():he.TYPE_UNSPECIFIED;else{e.anyOf=[];for(const o of n)e.anyOf.push({type:Object.values(he).includes(o.toUpperCase())?o.toUpperCase():he.TYPE_UNSPECIFIED})}}function Ee(t){const e={},n=["items"],o=["anyOf"],s=["properties"];if(t.type&&t.anyOf)throw new Error("type and anyOf cannot be both populated.");const l=t.anyOf;l!=null&&l.length==2&&(l[0].type==="null"?(e.nullable=!0,t=l[1]):l[1].type==="null"&&(e.nullable=!0,t=l[0])),t.type instanceof Array&&Ss(t.type,e);for(const[a,u]of Object.entries(t))if(u!=null)if(a=="type"){if(u==="null")throw new Error("type: null can not be the only possible type for the field.");if(u instanceof Array)continue;e.type=Object.values(he).includes(u.toUpperCase())?u.toUpperCase():he.TYPE_UNSPECIFIED}else if(n.includes(a))e[a]=Ee(u);else if(o.includes(a)){const c=[];for(const d of u){if(d.type=="null"){e.nullable=!0;continue}c.push(Ee(d))}e[a]=c}else if(s.includes(a)){const c={};for(const[d,f]of Object.entries(u))c[d]=Ee(f);e[a]=c}else{if(a==="additionalProperties")continue;e[a]=u}return e}function Tt(t){return Ee(t)}function vt(t){if(typeof t=="object")return t;if(typeof t=="string")return{voiceConfig:{prebuiltVoiceConfig:{voiceName:t}}};throw new Error(`Unsupported speechConfig type: ${typeof t}`)}function _t(t){if("multiSpeakerVoiceConfig"in t)throw new Error("multiSpeakerVoiceConfig is not supported in the live API.");return t}function Ce(t){if(t.functionDeclarations)for(const e of t.functionDeclarations)e.parameters&&(Object.keys(e.parameters).includes("$schema")?e.parametersJsonSchema||(e.parametersJsonSchema=e.parameters,delete e.parameters):e.parameters=Ee(e.parameters)),e.response&&(Object.keys(e.response).includes("$schema")?e.responseJsonSchema||(e.responseJsonSchema=e.response,delete e.response):e.response=Ee(e.response));return t}function xe(t){if(t==null)throw new Error("tools is required");if(!Array.isArray(t))throw new Error("tools is required and must be an array of Tools");const e=[];for(const n of t)e.push(n);return e}function Is(t,e,n,o=1){const s=!e.startsWith(`${n}/`)&&e.split("/").length===o;return t.isVertexAI()?e.startsWith("projects/")?e:e.startsWith("locations/")?`projects/${t.getProject()}/${e}`:e.startsWith(`${n}/`)?`projects/${t.getProject()}/locations/${t.getLocation()}/${e}`:s?`projects/${t.getProject()}/locations/${t.getLocation()}/${n}/${e}`:e:s?`${n}/${e}`:e}function ce(t,e){if(typeof e!="string")throw new Error("name must be a string");return Is(t,e,"cachedContents")}function po(t){switch(t){case"STATE_UNSPECIFIED":return"JOB_STATE_UNSPECIFIED";case"CREATING":return"JOB_STATE_RUNNING";case"ACTIVE":return"JOB_STATE_SUCCEEDED";case"FAILED":return"JOB_STATE_FAILED";default:return t}}function me(t){return ct(t)}function As(t){return t!=null&&typeof t=="object"&&"name"in t}function Rs(t){return t!=null&&typeof t=="object"&&"video"in t}function ws(t){return t!=null&&typeof t=="object"&&"uri"in t}function ho(t){var e;let n;if(As(t)&&(n=t.name),!(ws(t)&&(n=t.uri,n===void 0))&&!(Rs(t)&&(n=(e=t.video)===null||e===void 0?void 0:e.uri,n===void 0))){if(typeof t=="string"&&(n=t),n===void 0)throw new Error("Could not extract file name from the provided input.");if(n.startsWith("https://")){const s=n.split("files/")[1].match(/[a-z0-9]+/);if(s===null)throw new Error(`Could not extract file name from URI ${n}`);n=s[0]}else n.startsWith("files/")&&(n=n.split("files/")[1]);return n}}function mo(t,e){let n;return t.isVertexAI()?n=e?"publishers/google/models":"models":n=e?"models":"tunedModels",n}function go(t){for(const e of["models","tunedModels","publisherModels"])if(Ps(t,e))return t[e];return[]}function Ps(t,e){return t!==null&&typeof t=="object"&&e in t}function Ns(t,e={}){const n=t,o={name:n.name,description:n.description,parametersJsonSchema:n.inputSchema};return n.outputSchema&&(o.responseJsonSchema=n.outputSchema),e.behavior&&(o.behavior=e.behavior),{functionDeclarations:[o]}}function Ms(t,e={}){const n=[],o=new Set;for(const s of t){const l=s.name;if(o.has(l))throw new Error(`Duplicate function name ${l} found in MCP tools. Please ensure function names are unique.`);o.add(l);const a=Ns(s,e);a.functionDeclarations&&n.push(...a.functionDeclarations)}return{functionDeclarations:n}}function yo(t,e){let n;if(typeof e=="string")if(t.isVertexAI())if(e.startsWith("gs://"))n={format:"jsonl",gcsUri:[e]};else if(e.startsWith("bq://"))n={format:"bigquery",bigqueryUri:e};else throw new Error(`Unsupported string source for Vertex AI: ${e}`);else if(e.startsWith("files/"))n={fileName:e};else throw new Error(`Unsupported string source for Gemini API: ${e}`);else if(Array.isArray(e)){if(t.isVertexAI())throw new Error("InlinedRequest[] is not supported in Vertex AI.");n={inlinedRequests:e}}else n=e;const o=[n.gcsUri,n.bigqueryUri].filter(Boolean).length,s=[n.inlinedRequests,n.fileName].filter(Boolean).length;if(t.isVertexAI()){if(s>0||o!==1)throw new Error("Exactly one of `gcsUri` or `bigqueryUri` must be set for Vertex AI.")}else if(o>0||s!==1)throw new Error("Exactly one of `inlinedRequests`, `fileName`, must be set for Gemini API.");return n}function ks(t){if(typeof t!="string")return t;const e=t;if(e.startsWith("gs://"))return{format:"jsonl",gcsUri:e};if(e.startsWith("bq://"))return{format:"bigquery",bigqueryUri:e};throw new Error(`Unsupported destination: ${e}`)}function To(t){if(typeof t!="object"||t===null)return{};const e=t,n=e.inlinedResponses;if(typeof n!="object"||n===null)return t;const s=n.inlinedResponses;if(!Array.isArray(s)||s.length===0)return t;let l=!1;for(const a of s){if(typeof a!="object"||a===null)continue;const c=a.response;if(typeof c!="object"||c===null)continue;if(c.embedding!==void 0){l=!0;break}}return l&&(e.inlinedEmbedContentResponses=e.inlinedResponses,delete e.inlinedResponses),t}function Se(t,e){const n=e;if(!t.isVertexAI()){if(/batches\/[^/]+$/.test(n))return n.split("/").pop();throw new Error(`Invalid batch job name: ${n}.`)}if(/^projects\/[^/]+\/locations\/[^/]+\/batchPredictionJobs\/[^/]+$/.test(n))return n.split("/").pop();if(/^\d+$/.test(n))return n;throw new Error(`Invalid batch job name: ${n}.`)}function vo(t){const e=t;return e==="BATCH_STATE_UNSPECIFIED"?"JOB_STATE_UNSPECIFIED":e==="BATCH_STATE_PENDING"?"JOB_STATE_PENDING":e==="BATCH_STATE_RUNNING"?"JOB_STATE_RUNNING":e==="BATCH_STATE_SUCCEEDED"?"JOB_STATE_SUCCEEDED":e==="BATCH_STATE_FAILED"?"JOB_STATE_FAILED":e==="BATCH_STATE_CANCELLED"?"JOB_STATE_CANCELLED":e==="BATCH_STATE_EXPIRED"?"JOB_STATE_EXPIRED":e}/**
55
- * @license
56
- * Copyright 2025 Google LLC
57
- * SPDX-License-Identifier: Apache-2.0
58
- */function Ds(t){const e={},n=i(t,["responsesFile"]);n!=null&&r(e,["fileName"],n);const o=i(t,["inlinedResponses","inlinedResponses"]);if(o!=null){let l=o;Array.isArray(l)&&(l=l.map(a=>pr(a))),r(e,["inlinedResponses"],l)}const s=i(t,["inlinedEmbedContentResponses","inlinedResponses"]);if(s!=null){let l=s;Array.isArray(l)&&(l=l.map(a=>a)),r(e,["inlinedEmbedContentResponses"],l)}return e}function bs(t){const e={},n=i(t,["predictionsFormat"]);n!=null&&r(e,["format"],n);const o=i(t,["gcsDestination","outputUriPrefix"]);o!=null&&r(e,["gcsUri"],o);const s=i(t,["bigqueryDestination","outputUri"]);return s!=null&&r(e,["bigqueryUri"],s),e}function Us(t){const e={},n=i(t,["format"]);n!=null&&r(e,["predictionsFormat"],n);const o=i(t,["gcsUri"]);o!=null&&r(e,["gcsDestination","outputUriPrefix"],o);const s=i(t,["bigqueryUri"]);if(s!=null&&r(e,["bigqueryDestination","outputUri"],s),i(t,["fileName"])!==void 0)throw new Error("fileName parameter is not supported in Vertex AI.");if(i(t,["inlinedResponses"])!==void 0)throw new Error("inlinedResponses parameter is not supported in Vertex AI.");if(i(t,["inlinedEmbedContentResponses"])!==void 0)throw new Error("inlinedEmbedContentResponses parameter is not supported in Vertex AI.");return e}function Be(t){const e={},n=i(t,["name"]);n!=null&&r(e,["name"],n);const o=i(t,["metadata","displayName"]);o!=null&&r(e,["displayName"],o);const s=i(t,["metadata","state"]);s!=null&&r(e,["state"],vo(s));const l=i(t,["metadata","createTime"]);l!=null&&r(e,["createTime"],l);const a=i(t,["metadata","endTime"]);a!=null&&r(e,["endTime"],a);const u=i(t,["metadata","updateTime"]);u!=null&&r(e,["updateTime"],u);const c=i(t,["metadata","model"]);c!=null&&r(e,["model"],c);const d=i(t,["metadata","output"]);return d!=null&&r(e,["dest"],Ds(To(d))),e}function Et(t){const e={},n=i(t,["name"]);n!=null&&r(e,["name"],n);const o=i(t,["displayName"]);o!=null&&r(e,["displayName"],o);const s=i(t,["state"]);s!=null&&r(e,["state"],vo(s));const l=i(t,["error"]);l!=null&&r(e,["error"],l);const a=i(t,["createTime"]);a!=null&&r(e,["createTime"],a);const u=i(t,["startTime"]);u!=null&&r(e,["startTime"],u);const c=i(t,["endTime"]);c!=null&&r(e,["endTime"],c);const d=i(t,["updateTime"]);d!=null&&r(e,["updateTime"],d);const f=i(t,["model"]);f!=null&&r(e,["model"],f);const h=i(t,["inputConfig"]);h!=null&&r(e,["src"],Ls(h));const p=i(t,["outputConfig"]);p!=null&&r(e,["dest"],bs(To(p)));const m=i(t,["completionStats"]);return m!=null&&r(e,["completionStats"],m),e}function Ls(t){const e={},n=i(t,["instancesFormat"]);n!=null&&r(e,["format"],n);const o=i(t,["gcsSource","uris"]);o!=null&&r(e,["gcsUri"],o);const s=i(t,["bigquerySource","inputUri"]);return s!=null&&r(e,["bigqueryUri"],s),e}function Fs(t,e){const n={};if(i(e,["format"])!==void 0)throw new Error("format parameter is not supported in Gemini API.");if(i(e,["gcsUri"])!==void 0)throw new Error("gcsUri parameter is not supported in Gemini API.");if(i(e,["bigqueryUri"])!==void 0)throw new Error("bigqueryUri parameter is not supported in Gemini API.");const o=i(e,["fileName"]);o!=null&&r(n,["fileName"],o);const s=i(e,["inlinedRequests"]);if(s!=null){let l=s;Array.isArray(l)&&(l=l.map(a=>fr(t,a))),r(n,["requests","requests"],l)}return n}function Vs(t){const e={},n=i(t,["format"]);n!=null&&r(e,["instancesFormat"],n);const o=i(t,["gcsUri"]);o!=null&&r(e,["gcsSource","uris"],o);const s=i(t,["bigqueryUri"]);if(s!=null&&r(e,["bigquerySource","inputUri"],s),i(t,["fileName"])!==void 0)throw new Error("fileName parameter is not supported in Vertex AI.");if(i(t,["inlinedRequests"])!==void 0)throw new Error("inlinedRequests parameter is not supported in Vertex AI.");return e}function Gs(t){const e={},n=i(t,["data"]);if(n!=null&&r(e,["data"],n),i(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function Hs(t,e){const n={},o=i(e,["name"]);return o!=null&&r(n,["_url","name"],Se(t,o)),n}function qs(t,e){const n={},o=i(e,["name"]);return o!=null&&r(n,["_url","name"],Se(t,o)),n}function Bs(t){const e={},n=i(t,["content"]);n!=null&&r(e,["content"],n);const o=i(t,["citationMetadata"]);o!=null&&r(e,["citationMetadata"],Js(o));const s=i(t,["tokenCount"]);s!=null&&r(e,["tokenCount"],s);const l=i(t,["finishReason"]);l!=null&&r(e,["finishReason"],l);const a=i(t,["avgLogprobs"]);a!=null&&r(e,["avgLogprobs"],a);const u=i(t,["groundingMetadata"]);u!=null&&r(e,["groundingMetadata"],u);const c=i(t,["index"]);c!=null&&r(e,["index"],c);const d=i(t,["logprobsResult"]);d!=null&&r(e,["logprobsResult"],d);const f=i(t,["safetyRatings"]);if(f!=null){let p=f;Array.isArray(p)&&(p=p.map(m=>m)),r(e,["safetyRatings"],p)}const h=i(t,["urlContextMetadata"]);return h!=null&&r(e,["urlContextMetadata"],h),e}function Js(t){const e={},n=i(t,["citationSources"]);if(n!=null){let o=n;Array.isArray(o)&&(o=o.map(s=>s)),r(e,["citations"],o)}return e}function _o(t){const e={},n=i(t,["parts"]);if(n!=null){let s=n;Array.isArray(s)&&(s=s.map(l=>_r(l))),r(e,["parts"],s)}const o=i(t,["role"]);return o!=null&&r(e,["role"],o),e}function Ws(t,e){const n={},o=i(t,["displayName"]);if(e!==void 0&&o!=null&&r(e,["batch","displayName"],o),i(t,["dest"])!==void 0)throw new Error("dest parameter is not supported in Gemini API.");return n}function Ys(t,e){const n={},o=i(t,["displayName"]);e!==void 0&&o!=null&&r(e,["displayName"],o);const s=i(t,["dest"]);return e!==void 0&&s!=null&&r(e,["outputConfig"],Us(ks(s))),n}function Eo(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["src"]);s!=null&&r(n,["batch","inputConfig"],Fs(t,yo(t,s)));const l=i(e,["config"]);return l!=null&&Ws(l,n),n}function Os(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["model"],q(t,o));const s=i(e,["src"]);s!=null&&r(n,["inputConfig"],Vs(yo(t,s)));const l=i(e,["config"]);return l!=null&&Ys(l,n),n}function $s(t,e){const n={},o=i(t,["displayName"]);return e!==void 0&&o!=null&&r(e,["batch","displayName"],o),n}function Ks(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["src"]);s!=null&&r(n,["batch","inputConfig"],tr(t,s));const l=i(e,["config"]);return l!=null&&$s(l,n),n}function zs(t,e){const n={},o=i(e,["name"]);return o!=null&&r(n,["_url","name"],Se(t,o)),n}function Xs(t,e){const n={},o=i(e,["name"]);return o!=null&&r(n,["_url","name"],Se(t,o)),n}function Qs(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["name"]);o!=null&&r(e,["name"],o);const s=i(t,["done"]);s!=null&&r(e,["done"],s);const l=i(t,["error"]);return l!=null&&r(e,["error"],l),e}function Zs(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["name"]);o!=null&&r(e,["name"],o);const s=i(t,["done"]);s!=null&&r(e,["done"],s);const l=i(t,["error"]);return l!=null&&r(e,["error"],l),e}function js(t,e){const n={},o=i(e,["contents"]);if(o!=null){let l=yt(t,o);Array.isArray(l)&&(l=l.map(a=>a)),r(n,["requests[]","request","content"],l)}const s=i(e,["config"]);return s!=null&&(r(n,["_self"],er(s,n)),Xi(n,{"requests[].*":"requests[].request.*"})),n}function er(t,e){const n={},o=i(t,["taskType"]);e!==void 0&&o!=null&&r(e,["requests[]","taskType"],o);const s=i(t,["title"]);e!==void 0&&s!=null&&r(e,["requests[]","title"],s);const l=i(t,["outputDimensionality"]);if(e!==void 0&&l!=null&&r(e,["requests[]","outputDimensionality"],l),i(t,["mimeType"])!==void 0)throw new Error("mimeType parameter is not supported in Gemini API.");if(i(t,["autoTruncate"])!==void 0)throw new Error("autoTruncate parameter is not supported in Gemini API.");return n}function tr(t,e){const n={},o=i(e,["fileName"]);o!=null&&r(n,["file_name"],o);const s=i(e,["inlinedRequests"]);return s!=null&&r(n,["requests"],js(t,s)),n}function nr(t){const e={};if(i(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const n=i(t,["fileUri"]);n!=null&&r(e,["fileUri"],n);const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function or(t){const e={},n=i(t,["id"]);n!=null&&r(e,["id"],n);const o=i(t,["args"]);o!=null&&r(e,["args"],o);const s=i(t,["name"]);if(s!=null&&r(e,["name"],s),i(t,["partialArgs"])!==void 0)throw new Error("partialArgs parameter is not supported in Gemini API.");if(i(t,["willContinue"])!==void 0)throw new Error("willContinue parameter is not supported in Gemini API.");return e}function ir(t){const e={},n=i(t,["mode"]);n!=null&&r(e,["mode"],n);const o=i(t,["allowedFunctionNames"]);if(o!=null&&r(e,["allowedFunctionNames"],o),i(t,["streamFunctionCallArguments"])!==void 0)throw new Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return e}function sr(t,e,n){const o={},s=i(e,["systemInstruction"]);n!==void 0&&s!=null&&r(n,["systemInstruction"],_o(Z(s)));const l=i(e,["temperature"]);l!=null&&r(o,["temperature"],l);const a=i(e,["topP"]);a!=null&&r(o,["topP"],a);const u=i(e,["topK"]);u!=null&&r(o,["topK"],u);const c=i(e,["candidateCount"]);c!=null&&r(o,["candidateCount"],c);const d=i(e,["maxOutputTokens"]);d!=null&&r(o,["maxOutputTokens"],d);const f=i(e,["stopSequences"]);f!=null&&r(o,["stopSequences"],f);const h=i(e,["responseLogprobs"]);h!=null&&r(o,["responseLogprobs"],h);const p=i(e,["logprobs"]);p!=null&&r(o,["logprobs"],p);const m=i(e,["presencePenalty"]);m!=null&&r(o,["presencePenalty"],m);const T=i(e,["frequencyPenalty"]);T!=null&&r(o,["frequencyPenalty"],T);const E=i(e,["seed"]);E!=null&&r(o,["seed"],E);const v=i(e,["responseMimeType"]);v!=null&&r(o,["responseMimeType"],v);const S=i(e,["responseSchema"]);S!=null&&r(o,["responseSchema"],Tt(S));const _=i(e,["responseJsonSchema"]);if(_!=null&&r(o,["responseJsonSchema"],_),i(e,["routingConfig"])!==void 0)throw new Error("routingConfig parameter is not supported in Gemini API.");if(i(e,["modelSelectionConfig"])!==void 0)throw new Error("modelSelectionConfig parameter is not supported in Gemini API.");const C=i(e,["safetySettings"]);if(n!==void 0&&C!=null){let F=C;Array.isArray(F)&&(F=F.map(O=>Er(O))),r(n,["safetySettings"],F)}const x=i(e,["tools"]);if(n!==void 0&&x!=null){let F=xe(x);Array.isArray(F)&&(F=F.map(O=>xr(Ce(O)))),r(n,["tools"],F)}const R=i(e,["toolConfig"]);if(n!==void 0&&R!=null&&r(n,["toolConfig"],Cr(R)),i(e,["labels"])!==void 0)throw new Error("labels parameter is not supported in Gemini API.");const M=i(e,["cachedContent"]);n!==void 0&&M!=null&&r(n,["cachedContent"],ce(t,M));const k=i(e,["responseModalities"]);k!=null&&r(o,["responseModalities"],k);const V=i(e,["mediaResolution"]);V!=null&&r(o,["mediaResolution"],V);const w=i(e,["speechConfig"]);if(w!=null&&r(o,["speechConfig"],vt(w)),i(e,["audioTimestamp"])!==void 0)throw new Error("audioTimestamp parameter is not supported in Gemini API.");const L=i(e,["thinkingConfig"]);L!=null&&r(o,["thinkingConfig"],L);const B=i(e,["imageConfig"]);B!=null&&r(o,["imageConfig"],cr(B));const $=i(e,["enableEnhancedCivicAnswers"]);return $!=null&&r(o,["enableEnhancedCivicAnswers"],$),o}function rr(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["candidates"]);if(o!=null){let c=o;Array.isArray(c)&&(c=c.map(d=>Bs(d))),r(e,["candidates"],c)}const s=i(t,["modelVersion"]);s!=null&&r(e,["modelVersion"],s);const l=i(t,["promptFeedback"]);l!=null&&r(e,["promptFeedback"],l);const a=i(t,["responseId"]);a!=null&&r(e,["responseId"],a);const u=i(t,["usageMetadata"]);return u!=null&&r(e,["usageMetadata"],u),e}function lr(t,e){const n={},o=i(e,["name"]);return o!=null&&r(n,["_url","name"],Se(t,o)),n}function ar(t,e){const n={},o=i(e,["name"]);return o!=null&&r(n,["_url","name"],Se(t,o)),n}function ur(t){const e={};if(i(t,["authConfig"])!==void 0)throw new Error("authConfig parameter is not supported in Gemini API.");const n=i(t,["enableWidget"]);return n!=null&&r(e,["enableWidget"],n),e}function dr(t){const e={};if(i(t,["excludeDomains"])!==void 0)throw new Error("excludeDomains parameter is not supported in Gemini API.");if(i(t,["blockingConfidence"])!==void 0)throw new Error("blockingConfidence parameter is not supported in Gemini API.");const n=i(t,["timeRangeFilter"]);return n!=null&&r(e,["timeRangeFilter"],n),e}function cr(t){const e={},n=i(t,["aspectRatio"]);n!=null&&r(e,["aspectRatio"],n);const o=i(t,["imageSize"]);if(o!=null&&r(e,["imageSize"],o),i(t,["outputMimeType"])!==void 0)throw new Error("outputMimeType parameter is not supported in Gemini API.");if(i(t,["outputCompressionQuality"])!==void 0)throw new Error("outputCompressionQuality parameter is not supported in Gemini API.");return e}function fr(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["request","model"],q(t,o));const s=i(e,["contents"]);if(s!=null){let u=oe(s);Array.isArray(u)&&(u=u.map(c=>_o(c))),r(n,["request","contents"],u)}const l=i(e,["metadata"]);l!=null&&r(n,["metadata"],l);const a=i(e,["config"]);return a!=null&&r(n,["request","generationConfig"],sr(t,a,i(n,["request"],{}))),n}function pr(t){const e={},n=i(t,["response"]);n!=null&&r(e,["response"],rr(n));const o=i(t,["error"]);return o!=null&&r(e,["error"],o),e}function hr(t,e){const n={},o=i(t,["pageSize"]);e!==void 0&&o!=null&&r(e,["_query","pageSize"],o);const s=i(t,["pageToken"]);if(e!==void 0&&s!=null&&r(e,["_query","pageToken"],s),i(t,["filter"])!==void 0)throw new Error("filter parameter is not supported in Gemini API.");return n}function mr(t,e){const n={},o=i(t,["pageSize"]);e!==void 0&&o!=null&&r(e,["_query","pageSize"],o);const s=i(t,["pageToken"]);e!==void 0&&s!=null&&r(e,["_query","pageToken"],s);const l=i(t,["filter"]);return e!==void 0&&l!=null&&r(e,["_query","filter"],l),n}function gr(t){const e={},n=i(t,["config"]);return n!=null&&hr(n,e),e}function yr(t){const e={},n=i(t,["config"]);return n!=null&&mr(n,e),e}function Tr(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["nextPageToken"]);o!=null&&r(e,["nextPageToken"],o);const s=i(t,["operations"]);if(s!=null){let l=s;Array.isArray(l)&&(l=l.map(a=>Be(a))),r(e,["batchJobs"],l)}return e}function vr(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["nextPageToken"]);o!=null&&r(e,["nextPageToken"],o);const s=i(t,["batchPredictionJobs"]);if(s!=null){let l=s;Array.isArray(l)&&(l=l.map(a=>Et(a))),r(e,["batchJobs"],l)}return e}function _r(t){const e={},n=i(t,["mediaResolution"]);n!=null&&r(e,["mediaResolution"],n);const o=i(t,["codeExecutionResult"]);o!=null&&r(e,["codeExecutionResult"],o);const s=i(t,["executableCode"]);s!=null&&r(e,["executableCode"],s);const l=i(t,["fileData"]);l!=null&&r(e,["fileData"],nr(l));const a=i(t,["functionCall"]);a!=null&&r(e,["functionCall"],or(a));const u=i(t,["functionResponse"]);u!=null&&r(e,["functionResponse"],u);const c=i(t,["inlineData"]);c!=null&&r(e,["inlineData"],Gs(c));const d=i(t,["text"]);d!=null&&r(e,["text"],d);const f=i(t,["thought"]);f!=null&&r(e,["thought"],f);const h=i(t,["thoughtSignature"]);h!=null&&r(e,["thoughtSignature"],h);const p=i(t,["videoMetadata"]);return p!=null&&r(e,["videoMetadata"],p),e}function Er(t){const e={},n=i(t,["category"]);if(n!=null&&r(e,["category"],n),i(t,["method"])!==void 0)throw new Error("method parameter is not supported in Gemini API.");const o=i(t,["threshold"]);return o!=null&&r(e,["threshold"],o),e}function Cr(t){const e={},n=i(t,["functionCallingConfig"]);n!=null&&r(e,["functionCallingConfig"],ir(n));const o=i(t,["retrievalConfig"]);return o!=null&&r(e,["retrievalConfig"],o),e}function xr(t){const e={},n=i(t,["functionDeclarations"]);if(n!=null){let f=n;Array.isArray(f)&&(f=f.map(h=>h)),r(e,["functionDeclarations"],f)}if(i(t,["retrieval"])!==void 0)throw new Error("retrieval parameter is not supported in Gemini API.");const o=i(t,["googleSearchRetrieval"]);o!=null&&r(e,["googleSearchRetrieval"],o);const s=i(t,["computerUse"]);s!=null&&r(e,["computerUse"],s);const l=i(t,["fileSearch"]);l!=null&&r(e,["fileSearch"],l);const a=i(t,["codeExecution"]);if(a!=null&&r(e,["codeExecution"],a),i(t,["enterpriseWebSearch"])!==void 0)throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const u=i(t,["googleMaps"]);u!=null&&r(e,["googleMaps"],ur(u));const c=i(t,["googleSearch"]);c!=null&&r(e,["googleSearch"],dr(c));const d=i(t,["urlContext"]);return d!=null&&r(e,["urlContext"],d),e}/**
59
- * @license
60
- * Copyright 2025 Google LLC
61
- * SPDX-License-Identifier: Apache-2.0
62
- */var fe;(function(t){t.PAGED_ITEM_BATCH_JOBS="batchJobs",t.PAGED_ITEM_MODELS="models",t.PAGED_ITEM_TUNING_JOBS="tuningJobs",t.PAGED_ITEM_FILES="files",t.PAGED_ITEM_CACHED_CONTENTS="cachedContents",t.PAGED_ITEM_FILE_SEARCH_STORES="fileSearchStores",t.PAGED_ITEM_DOCUMENTS="documents"})(fe||(fe={}));class ye{constructor(e,n,o,s){this.pageInternal=[],this.paramsInternal={},this.requestInternal=n,this.init(e,o,s)}init(e,n,o){var s,l;this.nameInternal=e,this.pageInternal=n[this.nameInternal]||[],this.sdkHttpResponseInternal=n==null?void 0:n.sdkHttpResponse,this.idxInternal=0;let a={config:{}};!o||Object.keys(o).length===0?a={config:{}}:typeof o=="object"?a=Object.assign({},o):a=o,a.config&&(a.config.pageToken=n.nextPageToken),this.paramsInternal=a,this.pageInternalSize=(l=(s=a.config)===null||s===void 0?void 0:s.pageSize)!==null&&l!==void 0?l:this.pageInternal.length}initNextPage(e){this.init(this.nameInternal,e,this.paramsInternal)}get page(){return this.pageInternal}get name(){return this.nameInternal}get pageSize(){return this.pageInternalSize}get sdkHttpResponse(){return this.sdkHttpResponseInternal}get params(){return this.paramsInternal}get pageLength(){return this.pageInternal.length}getItem(e){return this.pageInternal[e]}[Symbol.asyncIterator](){return{next:async()=>{if(this.idxInternal>=this.pageLength)if(this.hasNextPage())await this.nextPage();else return{value:void 0,done:!0};const e=this.getItem(this.idxInternal);return this.idxInternal+=1,{value:e,done:!1}},return:async()=>({value:void 0,done:!0})}}async nextPage(){if(!this.hasNextPage())throw new Error("No more pages to fetch.");const e=await this.requestInternal(this.params);return this.initNextPage(e),this.page}hasNextPage(){var e;return((e=this.params.config)===null||e===void 0?void 0:e.pageToken)!==void 0}}/**
63
- * @license
64
- * Copyright 2025 Google LLC
65
- * SPDX-License-Identifier: Apache-2.0
66
- */class Sr extends de{constructor(e){super(),this.apiClient=e,this.list=async(n={})=>new ye(fe.PAGED_ITEM_BATCH_JOBS,o=>this.listInternal(o),await this.listInternal(n),n),this.create=async n=>(this.apiClient.isVertexAI()&&(n.config=this.formatDestination(n.src,n.config)),this.createInternal(n)),this.createEmbeddings=async n=>{if(console.warn("batches.createEmbeddings() is experimental and may change without notice."),this.apiClient.isVertexAI())throw new Error("Vertex AI does not support batches.createEmbeddings.");return this.createEmbeddingsInternal(n)}}createInlinedGenerateContentRequest(e){const n=Eo(this.apiClient,e),o=n._url,s=A("{model}:batchGenerateContent",o),u=n.batch.inputConfig.requests,c=u.requests,d=[];for(const f of c){const h=Object.assign({},f);if(h.systemInstruction){const p=h.systemInstruction;delete h.systemInstruction;const m=h.request;m.systemInstruction=p,h.request=m}d.push(h)}return u.requests=d,delete n.config,delete n._url,delete n._query,{path:s,body:n}}getGcsUri(e){if(typeof e=="string")return e.startsWith("gs://")?e:void 0;if(!Array.isArray(e)&&e.gcsUri&&e.gcsUri.length>0)return e.gcsUri[0]}getBigqueryUri(e){if(typeof e=="string")return e.startsWith("bq://")?e:void 0;if(!Array.isArray(e))return e.bigqueryUri}formatDestination(e,n){const o=n?Object.assign({},n):{},s=Date.now().toString();if(o.displayName||(o.displayName=`genaiBatchJob_${s}`),o.dest===void 0){const l=this.getGcsUri(e),a=this.getBigqueryUri(e);if(l)l.endsWith(".jsonl")?o.dest=`${l.slice(0,-6)}/dest`:o.dest=`${l}_dest_${s}`;else if(a)o.dest=`${a}_dest_${s}`;else throw new Error("Unsupported source for Vertex AI: No GCS or BigQuery URI found.")}return o}async createInternal(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Os(this.apiClient,e);return u=A("batchPredictionJobs",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>Et(f))}else{const d=Eo(this.apiClient,e);return u=A("{model}:batchGenerateContent",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>Be(f))}}async createEmbeddingsInternal(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Ks(this.apiClient,e);return l=A("{model}:asyncBatchEmbedContent",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>Be(c))}}async get(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=ar(this.apiClient,e);return u=A("batchPredictionJobs/{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>Et(f))}else{const d=lr(this.apiClient,e);return u=A("batches/{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>Be(f))}}async cancel(e){var n,o,s,l;let a="",u={};if(this.apiClient.isVertexAI()){const c=qs(this.apiClient,e);a=A("batchPredictionJobs/{name}:cancel",c._url),u=c._query,delete c._url,delete c._query,await this.apiClient.request({path:a,queryParams:u,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal})}else{const c=Hs(this.apiClient,e);a=A("batches/{name}:cancel",c._url),u=c._query,delete c._url,delete c._query,await this.apiClient.request({path:a,queryParams:u,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal})}}async listInternal(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=yr(e);return u=A("batchPredictionJobs",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=vr(f),p=new oo;return Object.assign(p,h),p})}else{const d=gr(e);return u=A("batches",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Tr(f),p=new oo;return Object.assign(p,h),p})}}async delete(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Xs(this.apiClient,e);return u=A("batchPredictionJobs/{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>Zs(f))}else{const d=zs(this.apiClient,e);return u=A("batches/{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>Qs(f))}}}/**
67
- * @license
68
- * Copyright 2025 Google LLC
69
- * SPDX-License-Identifier: Apache-2.0
70
- */function Ir(t){const e={},n=i(t,["data"]);if(n!=null&&r(e,["data"],n),i(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function Co(t){const e={},n=i(t,["parts"]);if(n!=null){let s=n;Array.isArray(s)&&(s=s.map(l=>Kr(l))),r(e,["parts"],s)}const o=i(t,["role"]);return o!=null&&r(e,["role"],o),e}function Ar(t,e){const n={},o=i(t,["ttl"]);e!==void 0&&o!=null&&r(e,["ttl"],o);const s=i(t,["expireTime"]);e!==void 0&&s!=null&&r(e,["expireTime"],s);const l=i(t,["displayName"]);e!==void 0&&l!=null&&r(e,["displayName"],l);const a=i(t,["contents"]);if(e!==void 0&&a!=null){let f=oe(a);Array.isArray(f)&&(f=f.map(h=>Co(h))),r(e,["contents"],f)}const u=i(t,["systemInstruction"]);e!==void 0&&u!=null&&r(e,["systemInstruction"],Co(Z(u)));const c=i(t,["tools"]);if(e!==void 0&&c!=null){let f=c;Array.isArray(f)&&(f=f.map(h=>Xr(h))),r(e,["tools"],f)}const d=i(t,["toolConfig"]);if(e!==void 0&&d!=null&&r(e,["toolConfig"],zr(d)),i(t,["kmsKeyName"])!==void 0)throw new Error("kmsKeyName parameter is not supported in Gemini API.");return n}function Rr(t,e){const n={},o=i(t,["ttl"]);e!==void 0&&o!=null&&r(e,["ttl"],o);const s=i(t,["expireTime"]);e!==void 0&&s!=null&&r(e,["expireTime"],s);const l=i(t,["displayName"]);e!==void 0&&l!=null&&r(e,["displayName"],l);const a=i(t,["contents"]);if(e!==void 0&&a!=null){let h=oe(a);Array.isArray(h)&&(h=h.map(p=>p)),r(e,["contents"],h)}const u=i(t,["systemInstruction"]);e!==void 0&&u!=null&&r(e,["systemInstruction"],Z(u));const c=i(t,["tools"]);if(e!==void 0&&c!=null){let h=c;Array.isArray(h)&&(h=h.map(p=>Qr(p))),r(e,["tools"],h)}const d=i(t,["toolConfig"]);e!==void 0&&d!=null&&r(e,["toolConfig"],d);const f=i(t,["kmsKeyName"]);return e!==void 0&&f!=null&&r(e,["encryption_spec","kmsKeyName"],f),n}function wr(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["model"],io(t,o));const s=i(e,["config"]);return s!=null&&Ar(s,n),n}function Pr(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["model"],io(t,o));const s=i(e,["config"]);return s!=null&&Rr(s,n),n}function Nr(t,e){const n={},o=i(e,["name"]);return o!=null&&r(n,["_url","name"],ce(t,o)),n}function Mr(t,e){const n={},o=i(e,["name"]);return o!=null&&r(n,["_url","name"],ce(t,o)),n}function kr(t){const e={},n=i(t,["sdkHttpResponse"]);return n!=null&&r(e,["sdkHttpResponse"],n),e}function Dr(t){const e={},n=i(t,["sdkHttpResponse"]);return n!=null&&r(e,["sdkHttpResponse"],n),e}function br(t){const e={};if(i(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const n=i(t,["fileUri"]);n!=null&&r(e,["fileUri"],n);const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function Ur(t){const e={},n=i(t,["id"]);n!=null&&r(e,["id"],n);const o=i(t,["args"]);o!=null&&r(e,["args"],o);const s=i(t,["name"]);if(s!=null&&r(e,["name"],s),i(t,["partialArgs"])!==void 0)throw new Error("partialArgs parameter is not supported in Gemini API.");if(i(t,["willContinue"])!==void 0)throw new Error("willContinue parameter is not supported in Gemini API.");return e}function Lr(t){const e={},n=i(t,["mode"]);n!=null&&r(e,["mode"],n);const o=i(t,["allowedFunctionNames"]);if(o!=null&&r(e,["allowedFunctionNames"],o),i(t,["streamFunctionCallArguments"])!==void 0)throw new Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return e}function Fr(t){const e={};if(i(t,["behavior"])!==void 0)throw new Error("behavior parameter is not supported in Vertex AI.");const n=i(t,["description"]);n!=null&&r(e,["description"],n);const o=i(t,["name"]);o!=null&&r(e,["name"],o);const s=i(t,["parameters"]);s!=null&&r(e,["parameters"],s);const l=i(t,["parametersJsonSchema"]);l!=null&&r(e,["parametersJsonSchema"],l);const a=i(t,["response"]);a!=null&&r(e,["response"],a);const u=i(t,["responseJsonSchema"]);return u!=null&&r(e,["responseJsonSchema"],u),e}function Vr(t,e){const n={},o=i(e,["name"]);return o!=null&&r(n,["_url","name"],ce(t,o)),n}function Gr(t,e){const n={},o=i(e,["name"]);return o!=null&&r(n,["_url","name"],ce(t,o)),n}function Hr(t){const e={};if(i(t,["authConfig"])!==void 0)throw new Error("authConfig parameter is not supported in Gemini API.");const n=i(t,["enableWidget"]);return n!=null&&r(e,["enableWidget"],n),e}function qr(t){const e={};if(i(t,["excludeDomains"])!==void 0)throw new Error("excludeDomains parameter is not supported in Gemini API.");if(i(t,["blockingConfidence"])!==void 0)throw new Error("blockingConfidence parameter is not supported in Gemini API.");const n=i(t,["timeRangeFilter"]);return n!=null&&r(e,["timeRangeFilter"],n),e}function Br(t,e){const n={},o=i(t,["pageSize"]);e!==void 0&&o!=null&&r(e,["_query","pageSize"],o);const s=i(t,["pageToken"]);return e!==void 0&&s!=null&&r(e,["_query","pageToken"],s),n}function Jr(t,e){const n={},o=i(t,["pageSize"]);e!==void 0&&o!=null&&r(e,["_query","pageSize"],o);const s=i(t,["pageToken"]);return e!==void 0&&s!=null&&r(e,["_query","pageToken"],s),n}function Wr(t){const e={},n=i(t,["config"]);return n!=null&&Br(n,e),e}function Yr(t){const e={},n=i(t,["config"]);return n!=null&&Jr(n,e),e}function Or(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["nextPageToken"]);o!=null&&r(e,["nextPageToken"],o);const s=i(t,["cachedContents"]);if(s!=null){let l=s;Array.isArray(l)&&(l=l.map(a=>a)),r(e,["cachedContents"],l)}return e}function $r(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["nextPageToken"]);o!=null&&r(e,["nextPageToken"],o);const s=i(t,["cachedContents"]);if(s!=null){let l=s;Array.isArray(l)&&(l=l.map(a=>a)),r(e,["cachedContents"],l)}return e}function Kr(t){const e={},n=i(t,["mediaResolution"]);n!=null&&r(e,["mediaResolution"],n);const o=i(t,["codeExecutionResult"]);o!=null&&r(e,["codeExecutionResult"],o);const s=i(t,["executableCode"]);s!=null&&r(e,["executableCode"],s);const l=i(t,["fileData"]);l!=null&&r(e,["fileData"],br(l));const a=i(t,["functionCall"]);a!=null&&r(e,["functionCall"],Ur(a));const u=i(t,["functionResponse"]);u!=null&&r(e,["functionResponse"],u);const c=i(t,["inlineData"]);c!=null&&r(e,["inlineData"],Ir(c));const d=i(t,["text"]);d!=null&&r(e,["text"],d);const f=i(t,["thought"]);f!=null&&r(e,["thought"],f);const h=i(t,["thoughtSignature"]);h!=null&&r(e,["thoughtSignature"],h);const p=i(t,["videoMetadata"]);return p!=null&&r(e,["videoMetadata"],p),e}function zr(t){const e={},n=i(t,["functionCallingConfig"]);n!=null&&r(e,["functionCallingConfig"],Lr(n));const o=i(t,["retrievalConfig"]);return o!=null&&r(e,["retrievalConfig"],o),e}function Xr(t){const e={},n=i(t,["functionDeclarations"]);if(n!=null){let f=n;Array.isArray(f)&&(f=f.map(h=>h)),r(e,["functionDeclarations"],f)}if(i(t,["retrieval"])!==void 0)throw new Error("retrieval parameter is not supported in Gemini API.");const o=i(t,["googleSearchRetrieval"]);o!=null&&r(e,["googleSearchRetrieval"],o);const s=i(t,["computerUse"]);s!=null&&r(e,["computerUse"],s);const l=i(t,["fileSearch"]);l!=null&&r(e,["fileSearch"],l);const a=i(t,["codeExecution"]);if(a!=null&&r(e,["codeExecution"],a),i(t,["enterpriseWebSearch"])!==void 0)throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const u=i(t,["googleMaps"]);u!=null&&r(e,["googleMaps"],Hr(u));const c=i(t,["googleSearch"]);c!=null&&r(e,["googleSearch"],qr(c));const d=i(t,["urlContext"]);return d!=null&&r(e,["urlContext"],d),e}function Qr(t){const e={},n=i(t,["functionDeclarations"]);if(n!=null){let h=n;Array.isArray(h)&&(h=h.map(p=>Fr(p))),r(e,["functionDeclarations"],h)}const o=i(t,["retrieval"]);o!=null&&r(e,["retrieval"],o);const s=i(t,["googleSearchRetrieval"]);s!=null&&r(e,["googleSearchRetrieval"],s);const l=i(t,["computerUse"]);if(l!=null&&r(e,["computerUse"],l),i(t,["fileSearch"])!==void 0)throw new Error("fileSearch parameter is not supported in Vertex AI.");const a=i(t,["codeExecution"]);a!=null&&r(e,["codeExecution"],a);const u=i(t,["enterpriseWebSearch"]);u!=null&&r(e,["enterpriseWebSearch"],u);const c=i(t,["googleMaps"]);c!=null&&r(e,["googleMaps"],c);const d=i(t,["googleSearch"]);d!=null&&r(e,["googleSearch"],d);const f=i(t,["urlContext"]);return f!=null&&r(e,["urlContext"],f),e}function Zr(t,e){const n={},o=i(t,["ttl"]);e!==void 0&&o!=null&&r(e,["ttl"],o);const s=i(t,["expireTime"]);return e!==void 0&&s!=null&&r(e,["expireTime"],s),n}function jr(t,e){const n={},o=i(t,["ttl"]);e!==void 0&&o!=null&&r(e,["ttl"],o);const s=i(t,["expireTime"]);return e!==void 0&&s!=null&&r(e,["expireTime"],s),n}function el(t,e){const n={},o=i(e,["name"]);o!=null&&r(n,["_url","name"],ce(t,o));const s=i(e,["config"]);return s!=null&&Zr(s,n),n}function tl(t,e){const n={},o=i(e,["name"]);o!=null&&r(n,["_url","name"],ce(t,o));const s=i(e,["config"]);return s!=null&&jr(s,n),n}/**
71
- * @license
72
- * Copyright 2025 Google LLC
73
- * SPDX-License-Identifier: Apache-2.0
74
- */class nl extends de{constructor(e){super(),this.apiClient=e,this.list=async(n={})=>new ye(fe.PAGED_ITEM_CACHED_CONTENTS,o=>this.listInternal(o),await this.listInternal(n),n)}async create(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Pr(this.apiClient,e);return u=A("cachedContents",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>f)}else{const d=wr(this.apiClient,e);return u=A("cachedContents",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>f)}}async get(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Gr(this.apiClient,e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>f)}else{const d=Vr(this.apiClient,e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>f)}}async delete(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Mr(this.apiClient,e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Dr(f),p=new to;return Object.assign(p,h),p})}else{const d=Nr(this.apiClient,e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=kr(f),p=new to;return Object.assign(p,h),p})}}async update(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=tl(this.apiClient,e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"PATCH",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>f)}else{const d=el(this.apiClient,e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"PATCH",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>f)}}async listInternal(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Yr(e);return u=A("cachedContents",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=$r(f),p=new no;return Object.assign(p,h),p})}else{const d=Wr(e);return u=A("cachedContents",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Or(f),p=new no;return Object.assign(p,h),p})}}}function Je(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,o=Object.getOwnPropertySymbols(t);s<o.length;s++)e.indexOf(o[s])<0&&Object.prototype.propertyIsEnumerable.call(t,o[s])&&(n[o[s]]=t[o[s]]);return n}function xo(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],o=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function U(t){return this instanceof U?(this.v=t,this):new U(t)}function le(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o=n.apply(t,e||[]),s,l=[];return s=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),u("next"),u("throw"),u("return",a),s[Symbol.asyncIterator]=function(){return this},s;function a(m){return function(T){return Promise.resolve(T).then(m,h)}}function u(m,T){o[m]&&(s[m]=function(E){return new Promise(function(v,S){l.push([m,E,v,S])>1||c(m,E)})},T&&(s[m]=T(s[m])))}function c(m,T){try{d(o[m](T))}catch(E){p(l[0][3],E)}}function d(m){m.value instanceof U?Promise.resolve(m.value.v).then(f,h):p(l[0][2],m)}function f(m){c("next",m)}function h(m){c("throw",m)}function p(m,T){m(T),l.shift(),l.length&&c(l[0][0],l[0][1])}}function ae(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],n;return e?e.call(t):(t=typeof xo=="function"?xo(t):t[Symbol.iterator](),n={},o("next"),o("throw"),o("return"),n[Symbol.asyncIterator]=function(){return this},n);function o(l){n[l]=t[l]&&function(a){return new Promise(function(u,c){a=t[l](a),s(u,c,a.done,a.value)})}}function s(l,a,u,c){Promise.resolve(c).then(function(d){l({value:d,done:u})},a)}}typeof SuppressedError=="function"&&SuppressedError;/**
75
- * @license
76
- * Copyright 2025 Google LLC
77
- * SPDX-License-Identifier: Apache-2.0
78
- */function ol(t){var e;if(t.candidates==null||t.candidates.length===0)return!1;const n=(e=t.candidates[0])===null||e===void 0?void 0:e.content;return n===void 0?!1:So(n)}function So(t){if(t.parts===void 0||t.parts.length===0)return!1;for(const e of t.parts)if(e===void 0||Object.keys(e).length===0)return!1;return!0}function il(t){if(t.length!==0){for(const e of t)if(e.role!=="user"&&e.role!=="model")throw new Error(`Role must be user or model, but got ${e.role}.`)}}function Io(t){if(t===void 0||t.length===0)return[];const e=[],n=t.length;let o=0;for(;o<n;)if(t[o].role==="user")e.push(t[o]),o++;else{const s=[];let l=!0;for(;o<n&&t[o].role==="model";)s.push(t[o]),l&&!So(t[o])&&(l=!1),o++;l?e.push(...s):e.pop()}return e}class sl{constructor(e,n){this.modelsModule=e,this.apiClient=n}create(e){return new rl(this.apiClient,this.modelsModule,e.model,e.config,structuredClone(e.history))}}class rl{constructor(e,n,o,s={},l=[]){this.apiClient=e,this.modelsModule=n,this.model=o,this.config=s,this.history=l,this.sendPromise=Promise.resolve(),il(l)}async sendMessage(e){var n;await this.sendPromise;const o=Z(e.message),s=this.modelsModule.generateContent({model:this.model,contents:this.getHistory(!0).concat(o),config:(n=e.config)!==null&&n!==void 0?n:this.config});return this.sendPromise=(async()=>{var l,a,u;const c=await s,d=(a=(l=c.candidates)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.content,f=c.automaticFunctionCallingHistory,h=this.getHistory(!0).length;let p=[];f!=null&&(p=(u=f.slice(h))!==null&&u!==void 0?u:[]);const m=d?[d]:[];this.recordHistory(o,m,p)})(),await this.sendPromise.catch(()=>{this.sendPromise=Promise.resolve()}),s}async sendMessageStream(e){var n;await this.sendPromise;const o=Z(e.message),s=this.modelsModule.generateContentStream({model:this.model,contents:this.getHistory(!0).concat(o),config:(n=e.config)!==null&&n!==void 0?n:this.config});this.sendPromise=s.then(()=>{}).catch(()=>{});const l=await s;return this.processStreamResponse(l,o)}getHistory(e=!1){const n=e?Io(this.history):this.history;return structuredClone(n)}processStreamResponse(e,n){return le(this,arguments,function*(){var s,l,a,u,c,d;const f=[];try{for(var h=!0,p=ae(e),m;m=yield U(p.next()),s=m.done,!s;h=!0){u=m.value,h=!1;const T=u;if(ol(T)){const E=(d=(c=T.candidates)===null||c===void 0?void 0:c[0])===null||d===void 0?void 0:d.content;E!==void 0&&f.push(E)}yield yield U(T)}}catch(T){l={error:T}}finally{try{!h&&!s&&(a=p.return)&&(yield U(a.call(p)))}finally{if(l)throw l.error}}this.recordHistory(n,f)})}recordHistory(e,n,o){let s=[];n.length>0&&n.every(l=>l.role!==void 0)?s=n:s.push({role:"model",parts:[]}),o&&o.length>0?this.history.push(...Io(o)):this.history.push(e),this.history.push(...s)}}/**
79
- * @license
80
- * Copyright 2025 Google LLC
81
- * SPDX-License-Identifier: Apache-2.0
82
- */class We extends Error{constructor(e){super(e.message),this.name="ApiError",this.status=e.status,Object.setPrototypeOf(this,We.prototype)}}/**
83
- * @license
84
- * Copyright 2025 Google LLC
85
- * SPDX-License-Identifier: Apache-2.0
86
- */function ll(t){const e={},n=i(t,["file"]);return n!=null&&r(e,["file"],n),e}function al(t){const e={},n=i(t,["sdkHttpResponse"]);return n!=null&&r(e,["sdkHttpResponse"],n),e}function ul(t){const e={},n=i(t,["name"]);return n!=null&&r(e,["_url","file"],ho(n)),e}function dl(t){const e={},n=i(t,["sdkHttpResponse"]);return n!=null&&r(e,["sdkHttpResponse"],n),e}function cl(t){const e={},n=i(t,["name"]);return n!=null&&r(e,["_url","file"],ho(n)),e}function fl(t,e){const n={},o=i(t,["pageSize"]);e!==void 0&&o!=null&&r(e,["_query","pageSize"],o);const s=i(t,["pageToken"]);return e!==void 0&&s!=null&&r(e,["_query","pageToken"],s),n}function pl(t){const e={},n=i(t,["config"]);return n!=null&&fl(n,e),e}function hl(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["nextPageToken"]);o!=null&&r(e,["nextPageToken"],o);const s=i(t,["files"]);if(s!=null){let l=s;Array.isArray(l)&&(l=l.map(a=>a)),r(e,["files"],l)}return e}/**
87
- * @license
88
- * Copyright 2025 Google LLC
89
- * SPDX-License-Identifier: Apache-2.0
90
- */class ml extends de{constructor(e){super(),this.apiClient=e,this.list=async(n={})=>new ye(fe.PAGED_ITEM_FILES,o=>this.listInternal(o),await this.listInternal(n),n)}async upload(e){if(this.apiClient.isVertexAI())throw new Error("Vertex AI does not support uploading files. You can share files through a GCS bucket.");return this.apiClient.uploadFile(e.file,e.config).then(n=>n)}async download(e){await this.apiClient.downloadFile(e)}async listInternal(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=pl(e);return l=A("files",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json().then(d=>{const f=d;return f.sdkHttpResponse={headers:c.headers},f})),s.then(c=>{const d=hl(c),f=new vs;return Object.assign(f,d),f})}}async createInternal(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=ll(e);return l=A("upload/v1beta/files",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>{const d=al(c),f=new _s;return Object.assign(f,d),f})}}async get(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=cl(e);return l=A("files/{file}",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>c)}}async delete(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=ul(e);return l=A("files/{file}",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json().then(d=>{const f=d;return f.sdkHttpResponse={headers:c.headers},f})),s.then(c=>{const d=dl(c),f=new Es;return Object.assign(f,d),f})}}}/**
91
- * @license
92
- * Copyright 2025 Google LLC
93
- * SPDX-License-Identifier: Apache-2.0
94
- */function Ye(t){const e={},n=i(t,["data"]);if(n!=null&&r(e,["data"],n),i(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function gl(t){const e={},n=i(t,["parts"]);if(n!=null){let s=n;Array.isArray(s)&&(s=s.map(l=>kl(l))),r(e,["parts"],s)}const o=i(t,["role"]);return o!=null&&r(e,["role"],o),e}function yl(t){const e={};if(i(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const n=i(t,["fileUri"]);n!=null&&r(e,["fileUri"],n);const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function Tl(t){const e={},n=i(t,["id"]);n!=null&&r(e,["id"],n);const o=i(t,["args"]);o!=null&&r(e,["args"],o);const s=i(t,["name"]);if(s!=null&&r(e,["name"],s),i(t,["partialArgs"])!==void 0)throw new Error("partialArgs parameter is not supported in Gemini API.");if(i(t,["willContinue"])!==void 0)throw new Error("willContinue parameter is not supported in Gemini API.");return e}function vl(t){const e={};if(i(t,["behavior"])!==void 0)throw new Error("behavior parameter is not supported in Vertex AI.");const n=i(t,["description"]);n!=null&&r(e,["description"],n);const o=i(t,["name"]);o!=null&&r(e,["name"],o);const s=i(t,["parameters"]);s!=null&&r(e,["parameters"],s);const l=i(t,["parametersJsonSchema"]);l!=null&&r(e,["parametersJsonSchema"],l);const a=i(t,["response"]);a!=null&&r(e,["response"],a);const u=i(t,["responseJsonSchema"]);return u!=null&&r(e,["responseJsonSchema"],u),e}function _l(t){const e={},n=i(t,["modelSelectionConfig"]);n!=null&&r(e,["modelConfig"],n);const o=i(t,["responseJsonSchema"]);o!=null&&r(e,["responseJsonSchema"],o);const s=i(t,["audioTimestamp"]);s!=null&&r(e,["audioTimestamp"],s);const l=i(t,["candidateCount"]);l!=null&&r(e,["candidateCount"],l);const a=i(t,["enableAffectiveDialog"]);a!=null&&r(e,["enableAffectiveDialog"],a);const u=i(t,["frequencyPenalty"]);u!=null&&r(e,["frequencyPenalty"],u);const c=i(t,["logprobs"]);c!=null&&r(e,["logprobs"],c);const d=i(t,["maxOutputTokens"]);d!=null&&r(e,["maxOutputTokens"],d);const f=i(t,["mediaResolution"]);f!=null&&r(e,["mediaResolution"],f);const h=i(t,["presencePenalty"]);h!=null&&r(e,["presencePenalty"],h);const p=i(t,["responseLogprobs"]);p!=null&&r(e,["responseLogprobs"],p);const m=i(t,["responseMimeType"]);m!=null&&r(e,["responseMimeType"],m);const T=i(t,["responseModalities"]);T!=null&&r(e,["responseModalities"],T);const E=i(t,["responseSchema"]);E!=null&&r(e,["responseSchema"],E);const v=i(t,["routingConfig"]);v!=null&&r(e,["routingConfig"],v);const S=i(t,["seed"]);S!=null&&r(e,["seed"],S);const _=i(t,["speechConfig"]);_!=null&&r(e,["speechConfig"],_);const C=i(t,["stopSequences"]);C!=null&&r(e,["stopSequences"],C);const x=i(t,["temperature"]);x!=null&&r(e,["temperature"],x);const R=i(t,["thinkingConfig"]);R!=null&&r(e,["thinkingConfig"],R);const M=i(t,["topK"]);M!=null&&r(e,["topK"],M);const k=i(t,["topP"]);if(k!=null&&r(e,["topP"],k),i(t,["enableEnhancedCivicAnswers"])!==void 0)throw new Error("enableEnhancedCivicAnswers parameter is not supported in Vertex AI.");return e}function El(t){const e={};if(i(t,["authConfig"])!==void 0)throw new Error("authConfig parameter is not supported in Gemini API.");const n=i(t,["enableWidget"]);return n!=null&&r(e,["enableWidget"],n),e}function Cl(t){const e={};if(i(t,["excludeDomains"])!==void 0)throw new Error("excludeDomains parameter is not supported in Gemini API.");if(i(t,["blockingConfidence"])!==void 0)throw new Error("blockingConfidence parameter is not supported in Gemini API.");const n=i(t,["timeRangeFilter"]);return n!=null&&r(e,["timeRangeFilter"],n),e}function xl(t,e){const n={},o=i(t,["generationConfig"]);e!==void 0&&o!=null&&r(e,["setup","generationConfig"],o);const s=i(t,["responseModalities"]);e!==void 0&&s!=null&&r(e,["setup","generationConfig","responseModalities"],s);const l=i(t,["temperature"]);e!==void 0&&l!=null&&r(e,["setup","generationConfig","temperature"],l);const a=i(t,["topP"]);e!==void 0&&a!=null&&r(e,["setup","generationConfig","topP"],a);const u=i(t,["topK"]);e!==void 0&&u!=null&&r(e,["setup","generationConfig","topK"],u);const c=i(t,["maxOutputTokens"]);e!==void 0&&c!=null&&r(e,["setup","generationConfig","maxOutputTokens"],c);const d=i(t,["mediaResolution"]);e!==void 0&&d!=null&&r(e,["setup","generationConfig","mediaResolution"],d);const f=i(t,["seed"]);e!==void 0&&f!=null&&r(e,["setup","generationConfig","seed"],f);const h=i(t,["speechConfig"]);e!==void 0&&h!=null&&r(e,["setup","generationConfig","speechConfig"],_t(h));const p=i(t,["thinkingConfig"]);e!==void 0&&p!=null&&r(e,["setup","generationConfig","thinkingConfig"],p);const m=i(t,["enableAffectiveDialog"]);e!==void 0&&m!=null&&r(e,["setup","generationConfig","enableAffectiveDialog"],m);const T=i(t,["systemInstruction"]);e!==void 0&&T!=null&&r(e,["setup","systemInstruction"],gl(Z(T)));const E=i(t,["tools"]);if(e!==void 0&&E!=null){let M=xe(E);Array.isArray(M)&&(M=M.map(k=>bl(Ce(k)))),r(e,["setup","tools"],M)}const v=i(t,["sessionResumption"]);e!==void 0&&v!=null&&r(e,["setup","sessionResumption"],Dl(v));const S=i(t,["inputAudioTranscription"]);e!==void 0&&S!=null&&r(e,["setup","inputAudioTranscription"],S);const _=i(t,["outputAudioTranscription"]);e!==void 0&&_!=null&&r(e,["setup","outputAudioTranscription"],_);const C=i(t,["realtimeInputConfig"]);e!==void 0&&C!=null&&r(e,["setup","realtimeInputConfig"],C);const x=i(t,["contextWindowCompression"]);e!==void 0&&x!=null&&r(e,["setup","contextWindowCompression"],x);const R=i(t,["proactivity"]);if(e!==void 0&&R!=null&&r(e,["setup","proactivity"],R),i(t,["explicitVadSignal"])!==void 0)throw new Error("explicitVadSignal parameter is not supported in Gemini API.");return n}function Sl(t,e){const n={},o=i(t,["generationConfig"]);e!==void 0&&o!=null&&r(e,["setup","generationConfig"],_l(o));const s=i(t,["responseModalities"]);e!==void 0&&s!=null&&r(e,["setup","generationConfig","responseModalities"],s);const l=i(t,["temperature"]);e!==void 0&&l!=null&&r(e,["setup","generationConfig","temperature"],l);const a=i(t,["topP"]);e!==void 0&&a!=null&&r(e,["setup","generationConfig","topP"],a);const u=i(t,["topK"]);e!==void 0&&u!=null&&r(e,["setup","generationConfig","topK"],u);const c=i(t,["maxOutputTokens"]);e!==void 0&&c!=null&&r(e,["setup","generationConfig","maxOutputTokens"],c);const d=i(t,["mediaResolution"]);e!==void 0&&d!=null&&r(e,["setup","generationConfig","mediaResolution"],d);const f=i(t,["seed"]);e!==void 0&&f!=null&&r(e,["setup","generationConfig","seed"],f);const h=i(t,["speechConfig"]);e!==void 0&&h!=null&&r(e,["setup","generationConfig","speechConfig"],_t(h));const p=i(t,["thinkingConfig"]);e!==void 0&&p!=null&&r(e,["setup","generationConfig","thinkingConfig"],p);const m=i(t,["enableAffectiveDialog"]);e!==void 0&&m!=null&&r(e,["setup","generationConfig","enableAffectiveDialog"],m);const T=i(t,["systemInstruction"]);e!==void 0&&T!=null&&r(e,["setup","systemInstruction"],Z(T));const E=i(t,["tools"]);if(e!==void 0&&E!=null){let k=xe(E);Array.isArray(k)&&(k=k.map(V=>Ul(Ce(V)))),r(e,["setup","tools"],k)}const v=i(t,["sessionResumption"]);e!==void 0&&v!=null&&r(e,["setup","sessionResumption"],v);const S=i(t,["inputAudioTranscription"]);e!==void 0&&S!=null&&r(e,["setup","inputAudioTranscription"],S);const _=i(t,["outputAudioTranscription"]);e!==void 0&&_!=null&&r(e,["setup","outputAudioTranscription"],_);const C=i(t,["realtimeInputConfig"]);e!==void 0&&C!=null&&r(e,["setup","realtimeInputConfig"],C);const x=i(t,["contextWindowCompression"]);e!==void 0&&x!=null&&r(e,["setup","contextWindowCompression"],x);const R=i(t,["proactivity"]);e!==void 0&&R!=null&&r(e,["setup","proactivity"],R);const M=i(t,["explicitVadSignal"]);return e!==void 0&&M!=null&&r(e,["setup","explicitVadSignal"],M),n}function Il(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["setup","model"],q(t,o));const s=i(e,["config"]);return s!=null&&r(n,["config"],xl(s,n)),n}function Al(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["setup","model"],q(t,o));const s=i(e,["config"]);return s!=null&&r(n,["config"],Sl(s,n)),n}function Rl(t){const e={},n=i(t,["musicGenerationConfig"]);return n!=null&&r(e,["musicGenerationConfig"],n),e}function wl(t){const e={},n=i(t,["weightedPrompts"]);if(n!=null){let o=n;Array.isArray(o)&&(o=o.map(s=>s)),r(e,["weightedPrompts"],o)}return e}function Pl(t){const e={},n=i(t,["media"]);if(n!=null){let d=so(n);Array.isArray(d)&&(d=d.map(f=>Ye(f))),r(e,["mediaChunks"],d)}const o=i(t,["audio"]);o!=null&&r(e,["audio"],Ye(lo(o)));const s=i(t,["audioStreamEnd"]);s!=null&&r(e,["audioStreamEnd"],s);const l=i(t,["video"]);l!=null&&r(e,["video"],Ye(ro(l)));const a=i(t,["text"]);a!=null&&r(e,["text"],a);const u=i(t,["activityStart"]);u!=null&&r(e,["activityStart"],u);const c=i(t,["activityEnd"]);return c!=null&&r(e,["activityEnd"],c),e}function Nl(t){const e={},n=i(t,["media"]);if(n!=null){let d=so(n);Array.isArray(d)&&(d=d.map(f=>f)),r(e,["mediaChunks"],d)}const o=i(t,["audio"]);o!=null&&r(e,["audio"],lo(o));const s=i(t,["audioStreamEnd"]);s!=null&&r(e,["audioStreamEnd"],s);const l=i(t,["video"]);l!=null&&r(e,["video"],ro(l));const a=i(t,["text"]);a!=null&&r(e,["text"],a);const u=i(t,["activityStart"]);u!=null&&r(e,["activityStart"],u);const c=i(t,["activityEnd"]);return c!=null&&r(e,["activityEnd"],c),e}function Ml(t){const e={},n=i(t,["setupComplete"]);n!=null&&r(e,["setupComplete"],n);const o=i(t,["serverContent"]);o!=null&&r(e,["serverContent"],o);const s=i(t,["toolCall"]);s!=null&&r(e,["toolCall"],s);const l=i(t,["toolCallCancellation"]);l!=null&&r(e,["toolCallCancellation"],l);const a=i(t,["usageMetadata"]);a!=null&&r(e,["usageMetadata"],Ll(a));const u=i(t,["goAway"]);u!=null&&r(e,["goAway"],u);const c=i(t,["sessionResumptionUpdate"]);c!=null&&r(e,["sessionResumptionUpdate"],c);const d=i(t,["voiceActivityDetectionSignal"]);return d!=null&&r(e,["voiceActivityDetectionSignal"],d),e}function kl(t){const e={},n=i(t,["mediaResolution"]);n!=null&&r(e,["mediaResolution"],n);const o=i(t,["codeExecutionResult"]);o!=null&&r(e,["codeExecutionResult"],o);const s=i(t,["executableCode"]);s!=null&&r(e,["executableCode"],s);const l=i(t,["fileData"]);l!=null&&r(e,["fileData"],yl(l));const a=i(t,["functionCall"]);a!=null&&r(e,["functionCall"],Tl(a));const u=i(t,["functionResponse"]);u!=null&&r(e,["functionResponse"],u);const c=i(t,["inlineData"]);c!=null&&r(e,["inlineData"],Ye(c));const d=i(t,["text"]);d!=null&&r(e,["text"],d);const f=i(t,["thought"]);f!=null&&r(e,["thought"],f);const h=i(t,["thoughtSignature"]);h!=null&&r(e,["thoughtSignature"],h);const p=i(t,["videoMetadata"]);return p!=null&&r(e,["videoMetadata"],p),e}function Dl(t){const e={},n=i(t,["handle"]);if(n!=null&&r(e,["handle"],n),i(t,["transparent"])!==void 0)throw new Error("transparent parameter is not supported in Gemini API.");return e}function bl(t){const e={},n=i(t,["functionDeclarations"]);if(n!=null){let f=n;Array.isArray(f)&&(f=f.map(h=>h)),r(e,["functionDeclarations"],f)}if(i(t,["retrieval"])!==void 0)throw new Error("retrieval parameter is not supported in Gemini API.");const o=i(t,["googleSearchRetrieval"]);o!=null&&r(e,["googleSearchRetrieval"],o);const s=i(t,["computerUse"]);s!=null&&r(e,["computerUse"],s);const l=i(t,["fileSearch"]);l!=null&&r(e,["fileSearch"],l);const a=i(t,["codeExecution"]);if(a!=null&&r(e,["codeExecution"],a),i(t,["enterpriseWebSearch"])!==void 0)throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const u=i(t,["googleMaps"]);u!=null&&r(e,["googleMaps"],El(u));const c=i(t,["googleSearch"]);c!=null&&r(e,["googleSearch"],Cl(c));const d=i(t,["urlContext"]);return d!=null&&r(e,["urlContext"],d),e}function Ul(t){const e={},n=i(t,["functionDeclarations"]);if(n!=null){let h=n;Array.isArray(h)&&(h=h.map(p=>vl(p))),r(e,["functionDeclarations"],h)}const o=i(t,["retrieval"]);o!=null&&r(e,["retrieval"],o);const s=i(t,["googleSearchRetrieval"]);s!=null&&r(e,["googleSearchRetrieval"],s);const l=i(t,["computerUse"]);if(l!=null&&r(e,["computerUse"],l),i(t,["fileSearch"])!==void 0)throw new Error("fileSearch parameter is not supported in Vertex AI.");const a=i(t,["codeExecution"]);a!=null&&r(e,["codeExecution"],a);const u=i(t,["enterpriseWebSearch"]);u!=null&&r(e,["enterpriseWebSearch"],u);const c=i(t,["googleMaps"]);c!=null&&r(e,["googleMaps"],c);const d=i(t,["googleSearch"]);d!=null&&r(e,["googleSearch"],d);const f=i(t,["urlContext"]);return f!=null&&r(e,["urlContext"],f),e}function Ll(t){const e={},n=i(t,["promptTokenCount"]);n!=null&&r(e,["promptTokenCount"],n);const o=i(t,["cachedContentTokenCount"]);o!=null&&r(e,["cachedContentTokenCount"],o);const s=i(t,["candidatesTokenCount"]);s!=null&&r(e,["responseTokenCount"],s);const l=i(t,["toolUsePromptTokenCount"]);l!=null&&r(e,["toolUsePromptTokenCount"],l);const a=i(t,["thoughtsTokenCount"]);a!=null&&r(e,["thoughtsTokenCount"],a);const u=i(t,["totalTokenCount"]);u!=null&&r(e,["totalTokenCount"],u);const c=i(t,["promptTokensDetails"]);if(c!=null){let m=c;Array.isArray(m)&&(m=m.map(T=>T)),r(e,["promptTokensDetails"],m)}const d=i(t,["cacheTokensDetails"]);if(d!=null){let m=d;Array.isArray(m)&&(m=m.map(T=>T)),r(e,["cacheTokensDetails"],m)}const f=i(t,["candidatesTokensDetails"]);if(f!=null){let m=f;Array.isArray(m)&&(m=m.map(T=>T)),r(e,["responseTokensDetails"],m)}const h=i(t,["toolUsePromptTokensDetails"]);if(h!=null){let m=h;Array.isArray(m)&&(m=m.map(T=>T)),r(e,["toolUsePromptTokensDetails"],m)}const p=i(t,["trafficType"]);return p!=null&&r(e,["trafficType"],p),e}/**
95
- * @license
96
- * Copyright 2025 Google LLC
97
- * SPDX-License-Identifier: Apache-2.0
98
- */function Fl(t){const e={},n=i(t,["data"]);if(n!=null&&r(e,["data"],n),i(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function Vl(t){const e={},n=i(t,["content"]);n!=null&&r(e,["content"],n);const o=i(t,["citationMetadata"]);o!=null&&r(e,["citationMetadata"],Gl(o));const s=i(t,["tokenCount"]);s!=null&&r(e,["tokenCount"],s);const l=i(t,["finishReason"]);l!=null&&r(e,["finishReason"],l);const a=i(t,["avgLogprobs"]);a!=null&&r(e,["avgLogprobs"],a);const u=i(t,["groundingMetadata"]);u!=null&&r(e,["groundingMetadata"],u);const c=i(t,["index"]);c!=null&&r(e,["index"],c);const d=i(t,["logprobsResult"]);d!=null&&r(e,["logprobsResult"],d);const f=i(t,["safetyRatings"]);if(f!=null){let p=f;Array.isArray(p)&&(p=p.map(m=>m)),r(e,["safetyRatings"],p)}const h=i(t,["urlContextMetadata"]);return h!=null&&r(e,["urlContextMetadata"],h),e}function Gl(t){const e={},n=i(t,["citationSources"]);if(n!=null){let o=n;Array.isArray(o)&&(o=o.map(s=>s)),r(e,["citations"],o)}return e}function Hl(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["contents"]);if(s!=null){let l=oe(s);Array.isArray(l)&&(l=l.map(a=>a)),r(n,["contents"],l)}return n}function ql(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["tokensInfo"]);if(o!=null){let s=o;Array.isArray(s)&&(s=s.map(l=>l)),r(e,["tokensInfo"],s)}return e}function Bl(t){const e={},n=i(t,["values"]);n!=null&&r(e,["values"],n);const o=i(t,["statistics"]);return o!=null&&r(e,["statistics"],Jl(o)),e}function Jl(t){const e={},n=i(t,["truncated"]);n!=null&&r(e,["truncated"],n);const o=i(t,["token_count"]);return o!=null&&r(e,["tokenCount"],o),e}function Oe(t){const e={},n=i(t,["parts"]);if(n!=null){let s=n;Array.isArray(s)&&(s=s.map(l=>Za(l))),r(e,["parts"],s)}const o=i(t,["role"]);return o!=null&&r(e,["role"],o),e}function Wl(t){const e={},n=i(t,["controlType"]);n!=null&&r(e,["controlType"],n);const o=i(t,["enableControlImageComputation"]);return o!=null&&r(e,["computeControl"],o),e}function Yl(t){const e={};if(i(t,["systemInstruction"])!==void 0)throw new Error("systemInstruction parameter is not supported in Gemini API.");if(i(t,["tools"])!==void 0)throw new Error("tools parameter is not supported in Gemini API.");if(i(t,["generationConfig"])!==void 0)throw new Error("generationConfig parameter is not supported in Gemini API.");return e}function Ol(t,e){const n={},o=i(t,["systemInstruction"]);e!==void 0&&o!=null&&r(e,["systemInstruction"],Z(o));const s=i(t,["tools"]);if(e!==void 0&&s!=null){let a=s;Array.isArray(a)&&(a=a.map(u=>Do(u))),r(e,["tools"],a)}const l=i(t,["generationConfig"]);return e!==void 0&&l!=null&&r(e,["generationConfig"],Fa(l)),n}function $l(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["contents"]);if(s!=null){let a=oe(s);Array.isArray(a)&&(a=a.map(u=>Oe(u))),r(n,["contents"],a)}const l=i(e,["config"]);return l!=null&&Yl(l),n}function Kl(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["contents"]);if(s!=null){let a=oe(s);Array.isArray(a)&&(a=a.map(u=>u)),r(n,["contents"],a)}const l=i(e,["config"]);return l!=null&&Ol(l,n),n}function zl(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["totalTokens"]);o!=null&&r(e,["totalTokens"],o);const s=i(t,["cachedContentTokenCount"]);return s!=null&&r(e,["cachedContentTokenCount"],s),e}function Xl(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["totalTokens"]);return o!=null&&r(e,["totalTokens"],o),e}function Ql(t,e){const n={},o=i(e,["model"]);return o!=null&&r(n,["_url","name"],q(t,o)),n}function Zl(t,e){const n={},o=i(e,["model"]);return o!=null&&r(n,["_url","name"],q(t,o)),n}function jl(t){const e={},n=i(t,["sdkHttpResponse"]);return n!=null&&r(e,["sdkHttpResponse"],n),e}function ea(t){const e={},n=i(t,["sdkHttpResponse"]);return n!=null&&r(e,["sdkHttpResponse"],n),e}function ta(t,e){const n={},o=i(t,["outputGcsUri"]);e!==void 0&&o!=null&&r(e,["parameters","storageUri"],o);const s=i(t,["negativePrompt"]);e!==void 0&&s!=null&&r(e,["parameters","negativePrompt"],s);const l=i(t,["numberOfImages"]);e!==void 0&&l!=null&&r(e,["parameters","sampleCount"],l);const a=i(t,["aspectRatio"]);e!==void 0&&a!=null&&r(e,["parameters","aspectRatio"],a);const u=i(t,["guidanceScale"]);e!==void 0&&u!=null&&r(e,["parameters","guidanceScale"],u);const c=i(t,["seed"]);e!==void 0&&c!=null&&r(e,["parameters","seed"],c);const d=i(t,["safetyFilterLevel"]);e!==void 0&&d!=null&&r(e,["parameters","safetySetting"],d);const f=i(t,["personGeneration"]);e!==void 0&&f!=null&&r(e,["parameters","personGeneration"],f);const h=i(t,["includeSafetyAttributes"]);e!==void 0&&h!=null&&r(e,["parameters","includeSafetyAttributes"],h);const p=i(t,["includeRaiReason"]);e!==void 0&&p!=null&&r(e,["parameters","includeRaiReason"],p);const m=i(t,["language"]);e!==void 0&&m!=null&&r(e,["parameters","language"],m);const T=i(t,["outputMimeType"]);e!==void 0&&T!=null&&r(e,["parameters","outputOptions","mimeType"],T);const E=i(t,["outputCompressionQuality"]);e!==void 0&&E!=null&&r(e,["parameters","outputOptions","compressionQuality"],E);const v=i(t,["addWatermark"]);e!==void 0&&v!=null&&r(e,["parameters","addWatermark"],v);const S=i(t,["labels"]);e!==void 0&&S!=null&&r(e,["labels"],S);const _=i(t,["editMode"]);e!==void 0&&_!=null&&r(e,["parameters","editMode"],_);const C=i(t,["baseSteps"]);return e!==void 0&&C!=null&&r(e,["parameters","editConfig","baseSteps"],C),n}function na(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["prompt"]);s!=null&&r(n,["instances[0]","prompt"],s);const l=i(e,["referenceImages"]);if(l!=null){let u=l;Array.isArray(u)&&(u=u.map(c=>iu(c))),r(n,["instances[0]","referenceImages"],u)}const a=i(e,["config"]);return a!=null&&ta(a,n),n}function oa(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["predictions"]);if(o!=null){let s=o;Array.isArray(s)&&(s=s.map(l=>$e(l))),r(e,["generatedImages"],s)}return e}function ia(t,e){const n={},o=i(t,["taskType"]);e!==void 0&&o!=null&&r(e,["requests[]","taskType"],o);const s=i(t,["title"]);e!==void 0&&s!=null&&r(e,["requests[]","title"],s);const l=i(t,["outputDimensionality"]);if(e!==void 0&&l!=null&&r(e,["requests[]","outputDimensionality"],l),i(t,["mimeType"])!==void 0)throw new Error("mimeType parameter is not supported in Gemini API.");if(i(t,["autoTruncate"])!==void 0)throw new Error("autoTruncate parameter is not supported in Gemini API.");return n}function sa(t,e){const n={},o=i(t,["taskType"]);e!==void 0&&o!=null&&r(e,["instances[]","task_type"],o);const s=i(t,["title"]);e!==void 0&&s!=null&&r(e,["instances[]","title"],s);const l=i(t,["outputDimensionality"]);e!==void 0&&l!=null&&r(e,["parameters","outputDimensionality"],l);const a=i(t,["mimeType"]);e!==void 0&&a!=null&&r(e,["instances[]","mimeType"],a);const u=i(t,["autoTruncate"]);return e!==void 0&&u!=null&&r(e,["parameters","autoTruncate"],u),n}function ra(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["contents"]);if(s!=null){let u=yt(t,s);Array.isArray(u)&&(u=u.map(c=>c)),r(n,["requests[]","content"],u)}const l=i(e,["config"]);l!=null&&ia(l,n);const a=i(e,["model"]);return a!==void 0&&r(n,["requests[]","model"],q(t,a)),n}function la(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["contents"]);if(s!=null){let a=yt(t,s);Array.isArray(a)&&(a=a.map(u=>u)),r(n,["instances[]","content"],a)}const l=i(e,["config"]);return l!=null&&sa(l,n),n}function aa(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["embeddings"]);if(o!=null){let l=o;Array.isArray(l)&&(l=l.map(a=>a)),r(e,["embeddings"],l)}const s=i(t,["metadata"]);return s!=null&&r(e,["metadata"],s),e}function ua(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["predictions[]","embeddings"]);if(o!=null){let l=o;Array.isArray(l)&&(l=l.map(a=>Bl(a))),r(e,["embeddings"],l)}const s=i(t,["metadata"]);return s!=null&&r(e,["metadata"],s),e}function da(t){const e={},n=i(t,["endpoint"]);n!=null&&r(e,["name"],n);const o=i(t,["deployedModelId"]);return o!=null&&r(e,["deployedModelId"],o),e}function ca(t){const e={};if(i(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const n=i(t,["fileUri"]);n!=null&&r(e,["fileUri"],n);const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function fa(t){const e={},n=i(t,["id"]);n!=null&&r(e,["id"],n);const o=i(t,["args"]);o!=null&&r(e,["args"],o);const s=i(t,["name"]);if(s!=null&&r(e,["name"],s),i(t,["partialArgs"])!==void 0)throw new Error("partialArgs parameter is not supported in Gemini API.");if(i(t,["willContinue"])!==void 0)throw new Error("willContinue parameter is not supported in Gemini API.");return e}function pa(t){const e={},n=i(t,["mode"]);n!=null&&r(e,["mode"],n);const o=i(t,["allowedFunctionNames"]);if(o!=null&&r(e,["allowedFunctionNames"],o),i(t,["streamFunctionCallArguments"])!==void 0)throw new Error("streamFunctionCallArguments parameter is not supported in Gemini API.");return e}function ha(t){const e={};if(i(t,["behavior"])!==void 0)throw new Error("behavior parameter is not supported in Vertex AI.");const n=i(t,["description"]);n!=null&&r(e,["description"],n);const o=i(t,["name"]);o!=null&&r(e,["name"],o);const s=i(t,["parameters"]);s!=null&&r(e,["parameters"],s);const l=i(t,["parametersJsonSchema"]);l!=null&&r(e,["parametersJsonSchema"],l);const a=i(t,["response"]);a!=null&&r(e,["response"],a);const u=i(t,["responseJsonSchema"]);return u!=null&&r(e,["responseJsonSchema"],u),e}function ma(t,e,n){const o={},s=i(e,["systemInstruction"]);n!==void 0&&s!=null&&r(n,["systemInstruction"],Oe(Z(s)));const l=i(e,["temperature"]);l!=null&&r(o,["temperature"],l);const a=i(e,["topP"]);a!=null&&r(o,["topP"],a);const u=i(e,["topK"]);u!=null&&r(o,["topK"],u);const c=i(e,["candidateCount"]);c!=null&&r(o,["candidateCount"],c);const d=i(e,["maxOutputTokens"]);d!=null&&r(o,["maxOutputTokens"],d);const f=i(e,["stopSequences"]);f!=null&&r(o,["stopSequences"],f);const h=i(e,["responseLogprobs"]);h!=null&&r(o,["responseLogprobs"],h);const p=i(e,["logprobs"]);p!=null&&r(o,["logprobs"],p);const m=i(e,["presencePenalty"]);m!=null&&r(o,["presencePenalty"],m);const T=i(e,["frequencyPenalty"]);T!=null&&r(o,["frequencyPenalty"],T);const E=i(e,["seed"]);E!=null&&r(o,["seed"],E);const v=i(e,["responseMimeType"]);v!=null&&r(o,["responseMimeType"],v);const S=i(e,["responseSchema"]);S!=null&&r(o,["responseSchema"],Tt(S));const _=i(e,["responseJsonSchema"]);if(_!=null&&r(o,["responseJsonSchema"],_),i(e,["routingConfig"])!==void 0)throw new Error("routingConfig parameter is not supported in Gemini API.");if(i(e,["modelSelectionConfig"])!==void 0)throw new Error("modelSelectionConfig parameter is not supported in Gemini API.");const C=i(e,["safetySettings"]);if(n!==void 0&&C!=null){let F=C;Array.isArray(F)&&(F=F.map(O=>su(O))),r(n,["safetySettings"],F)}const x=i(e,["tools"]);if(n!==void 0&&x!=null){let F=xe(x);Array.isArray(F)&&(F=F.map(O=>fu(Ce(O)))),r(n,["tools"],F)}const R=i(e,["toolConfig"]);if(n!==void 0&&R!=null&&r(n,["toolConfig"],cu(R)),i(e,["labels"])!==void 0)throw new Error("labels parameter is not supported in Gemini API.");const M=i(e,["cachedContent"]);n!==void 0&&M!=null&&r(n,["cachedContent"],ce(t,M));const k=i(e,["responseModalities"]);k!=null&&r(o,["responseModalities"],k);const V=i(e,["mediaResolution"]);V!=null&&r(o,["mediaResolution"],V);const w=i(e,["speechConfig"]);if(w!=null&&r(o,["speechConfig"],vt(w)),i(e,["audioTimestamp"])!==void 0)throw new Error("audioTimestamp parameter is not supported in Gemini API.");const L=i(e,["thinkingConfig"]);L!=null&&r(o,["thinkingConfig"],L);const B=i(e,["imageConfig"]);B!=null&&r(o,["imageConfig"],Ba(B));const $=i(e,["enableEnhancedCivicAnswers"]);return $!=null&&r(o,["enableEnhancedCivicAnswers"],$),o}function ga(t,e,n){const o={},s=i(e,["systemInstruction"]);n!==void 0&&s!=null&&r(n,["systemInstruction"],Z(s));const l=i(e,["temperature"]);l!=null&&r(o,["temperature"],l);const a=i(e,["topP"]);a!=null&&r(o,["topP"],a);const u=i(e,["topK"]);u!=null&&r(o,["topK"],u);const c=i(e,["candidateCount"]);c!=null&&r(o,["candidateCount"],c);const d=i(e,["maxOutputTokens"]);d!=null&&r(o,["maxOutputTokens"],d);const f=i(e,["stopSequences"]);f!=null&&r(o,["stopSequences"],f);const h=i(e,["responseLogprobs"]);h!=null&&r(o,["responseLogprobs"],h);const p=i(e,["logprobs"]);p!=null&&r(o,["logprobs"],p);const m=i(e,["presencePenalty"]);m!=null&&r(o,["presencePenalty"],m);const T=i(e,["frequencyPenalty"]);T!=null&&r(o,["frequencyPenalty"],T);const E=i(e,["seed"]);E!=null&&r(o,["seed"],E);const v=i(e,["responseMimeType"]);v!=null&&r(o,["responseMimeType"],v);const S=i(e,["responseSchema"]);S!=null&&r(o,["responseSchema"],Tt(S));const _=i(e,["responseJsonSchema"]);_!=null&&r(o,["responseJsonSchema"],_);const C=i(e,["routingConfig"]);C!=null&&r(o,["routingConfig"],C);const x=i(e,["modelSelectionConfig"]);x!=null&&r(o,["modelConfig"],x);const R=i(e,["safetySettings"]);if(n!==void 0&&R!=null){let W=R;Array.isArray(W)&&(W=W.map(K=>K)),r(n,["safetySettings"],W)}const M=i(e,["tools"]);if(n!==void 0&&M!=null){let W=xe(M);Array.isArray(W)&&(W=W.map(K=>Do(Ce(K)))),r(n,["tools"],W)}const k=i(e,["toolConfig"]);n!==void 0&&k!=null&&r(n,["toolConfig"],k);const V=i(e,["labels"]);n!==void 0&&V!=null&&r(n,["labels"],V);const w=i(e,["cachedContent"]);n!==void 0&&w!=null&&r(n,["cachedContent"],ce(t,w));const L=i(e,["responseModalities"]);L!=null&&r(o,["responseModalities"],L);const B=i(e,["mediaResolution"]);B!=null&&r(o,["mediaResolution"],B);const $=i(e,["speechConfig"]);$!=null&&r(o,["speechConfig"],vt($));const F=i(e,["audioTimestamp"]);F!=null&&r(o,["audioTimestamp"],F);const O=i(e,["thinkingConfig"]);O!=null&&r(o,["thinkingConfig"],O);const D=i(e,["imageConfig"]);if(D!=null&&r(o,["imageConfig"],Ja(D)),i(e,["enableEnhancedCivicAnswers"])!==void 0)throw new Error("enableEnhancedCivicAnswers parameter is not supported in Vertex AI.");return o}function Ao(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["contents"]);if(s!=null){let a=oe(s);Array.isArray(a)&&(a=a.map(u=>Oe(u))),r(n,["contents"],a)}const l=i(e,["config"]);return l!=null&&r(n,["generationConfig"],ma(t,l,n)),n}function Ro(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["contents"]);if(s!=null){let a=oe(s);Array.isArray(a)&&(a=a.map(u=>u)),r(n,["contents"],a)}const l=i(e,["config"]);return l!=null&&r(n,["generationConfig"],ga(t,l,n)),n}function wo(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["candidates"]);if(o!=null){let c=o;Array.isArray(c)&&(c=c.map(d=>Vl(d))),r(e,["candidates"],c)}const s=i(t,["modelVersion"]);s!=null&&r(e,["modelVersion"],s);const l=i(t,["promptFeedback"]);l!=null&&r(e,["promptFeedback"],l);const a=i(t,["responseId"]);a!=null&&r(e,["responseId"],a);const u=i(t,["usageMetadata"]);return u!=null&&r(e,["usageMetadata"],u),e}function Po(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["candidates"]);if(o!=null){let d=o;Array.isArray(d)&&(d=d.map(f=>f)),r(e,["candidates"],d)}const s=i(t,["createTime"]);s!=null&&r(e,["createTime"],s);const l=i(t,["modelVersion"]);l!=null&&r(e,["modelVersion"],l);const a=i(t,["promptFeedback"]);a!=null&&r(e,["promptFeedback"],a);const u=i(t,["responseId"]);u!=null&&r(e,["responseId"],u);const c=i(t,["usageMetadata"]);return c!=null&&r(e,["usageMetadata"],c),e}function ya(t,e){const n={};if(i(t,["outputGcsUri"])!==void 0)throw new Error("outputGcsUri parameter is not supported in Gemini API.");if(i(t,["negativePrompt"])!==void 0)throw new Error("negativePrompt parameter is not supported in Gemini API.");const o=i(t,["numberOfImages"]);e!==void 0&&o!=null&&r(e,["parameters","sampleCount"],o);const s=i(t,["aspectRatio"]);e!==void 0&&s!=null&&r(e,["parameters","aspectRatio"],s);const l=i(t,["guidanceScale"]);if(e!==void 0&&l!=null&&r(e,["parameters","guidanceScale"],l),i(t,["seed"])!==void 0)throw new Error("seed parameter is not supported in Gemini API.");const a=i(t,["safetyFilterLevel"]);e!==void 0&&a!=null&&r(e,["parameters","safetySetting"],a);const u=i(t,["personGeneration"]);e!==void 0&&u!=null&&r(e,["parameters","personGeneration"],u);const c=i(t,["includeSafetyAttributes"]);e!==void 0&&c!=null&&r(e,["parameters","includeSafetyAttributes"],c);const d=i(t,["includeRaiReason"]);e!==void 0&&d!=null&&r(e,["parameters","includeRaiReason"],d);const f=i(t,["language"]);e!==void 0&&f!=null&&r(e,["parameters","language"],f);const h=i(t,["outputMimeType"]);e!==void 0&&h!=null&&r(e,["parameters","outputOptions","mimeType"],h);const p=i(t,["outputCompressionQuality"]);if(e!==void 0&&p!=null&&r(e,["parameters","outputOptions","compressionQuality"],p),i(t,["addWatermark"])!==void 0)throw new Error("addWatermark parameter is not supported in Gemini API.");if(i(t,["labels"])!==void 0)throw new Error("labels parameter is not supported in Gemini API.");const m=i(t,["imageSize"]);if(e!==void 0&&m!=null&&r(e,["parameters","sampleImageSize"],m),i(t,["enhancePrompt"])!==void 0)throw new Error("enhancePrompt parameter is not supported in Gemini API.");return n}function Ta(t,e){const n={},o=i(t,["outputGcsUri"]);e!==void 0&&o!=null&&r(e,["parameters","storageUri"],o);const s=i(t,["negativePrompt"]);e!==void 0&&s!=null&&r(e,["parameters","negativePrompt"],s);const l=i(t,["numberOfImages"]);e!==void 0&&l!=null&&r(e,["parameters","sampleCount"],l);const a=i(t,["aspectRatio"]);e!==void 0&&a!=null&&r(e,["parameters","aspectRatio"],a);const u=i(t,["guidanceScale"]);e!==void 0&&u!=null&&r(e,["parameters","guidanceScale"],u);const c=i(t,["seed"]);e!==void 0&&c!=null&&r(e,["parameters","seed"],c);const d=i(t,["safetyFilterLevel"]);e!==void 0&&d!=null&&r(e,["parameters","safetySetting"],d);const f=i(t,["personGeneration"]);e!==void 0&&f!=null&&r(e,["parameters","personGeneration"],f);const h=i(t,["includeSafetyAttributes"]);e!==void 0&&h!=null&&r(e,["parameters","includeSafetyAttributes"],h);const p=i(t,["includeRaiReason"]);e!==void 0&&p!=null&&r(e,["parameters","includeRaiReason"],p);const m=i(t,["language"]);e!==void 0&&m!=null&&r(e,["parameters","language"],m);const T=i(t,["outputMimeType"]);e!==void 0&&T!=null&&r(e,["parameters","outputOptions","mimeType"],T);const E=i(t,["outputCompressionQuality"]);e!==void 0&&E!=null&&r(e,["parameters","outputOptions","compressionQuality"],E);const v=i(t,["addWatermark"]);e!==void 0&&v!=null&&r(e,["parameters","addWatermark"],v);const S=i(t,["labels"]);e!==void 0&&S!=null&&r(e,["labels"],S);const _=i(t,["imageSize"]);e!==void 0&&_!=null&&r(e,["parameters","sampleImageSize"],_);const C=i(t,["enhancePrompt"]);return e!==void 0&&C!=null&&r(e,["parameters","enhancePrompt"],C),n}function va(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["prompt"]);s!=null&&r(n,["instances[0]","prompt"],s);const l=i(e,["config"]);return l!=null&&ya(l,n),n}function _a(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["prompt"]);s!=null&&r(n,["instances[0]","prompt"],s);const l=i(e,["config"]);return l!=null&&Ta(l,n),n}function Ea(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["predictions"]);if(o!=null){let l=o;Array.isArray(l)&&(l=l.map(a=>Da(a))),r(e,["generatedImages"],l)}const s=i(t,["positivePromptSafetyAttributes"]);return s!=null&&r(e,["positivePromptSafetyAttributes"],Mo(s)),e}function Ca(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["predictions"]);if(o!=null){let l=o;Array.isArray(l)&&(l=l.map(a=>$e(a))),r(e,["generatedImages"],l)}const s=i(t,["positivePromptSafetyAttributes"]);return s!=null&&r(e,["positivePromptSafetyAttributes"],ko(s)),e}function xa(t,e){const n={},o=i(t,["numberOfVideos"]);if(e!==void 0&&o!=null&&r(e,["parameters","sampleCount"],o),i(t,["outputGcsUri"])!==void 0)throw new Error("outputGcsUri parameter is not supported in Gemini API.");if(i(t,["fps"])!==void 0)throw new Error("fps parameter is not supported in Gemini API.");const s=i(t,["durationSeconds"]);if(e!==void 0&&s!=null&&r(e,["parameters","durationSeconds"],s),i(t,["seed"])!==void 0)throw new Error("seed parameter is not supported in Gemini API.");const l=i(t,["aspectRatio"]);e!==void 0&&l!=null&&r(e,["parameters","aspectRatio"],l);const a=i(t,["resolution"]);e!==void 0&&a!=null&&r(e,["parameters","resolution"],a);const u=i(t,["personGeneration"]);if(e!==void 0&&u!=null&&r(e,["parameters","personGeneration"],u),i(t,["pubsubTopic"])!==void 0)throw new Error("pubsubTopic parameter is not supported in Gemini API.");const c=i(t,["negativePrompt"]);e!==void 0&&c!=null&&r(e,["parameters","negativePrompt"],c);const d=i(t,["enhancePrompt"]);if(e!==void 0&&d!=null&&r(e,["parameters","enhancePrompt"],d),i(t,["generateAudio"])!==void 0)throw new Error("generateAudio parameter is not supported in Gemini API.");const f=i(t,["lastFrame"]);e!==void 0&&f!=null&&r(e,["instances[0]","lastFrame"],Ke(f));const h=i(t,["referenceImages"]);if(e!==void 0&&h!=null){let p=h;Array.isArray(p)&&(p=p.map(m=>Iu(m))),r(e,["instances[0]","referenceImages"],p)}if(i(t,["mask"])!==void 0)throw new Error("mask parameter is not supported in Gemini API.");if(i(t,["compressionQuality"])!==void 0)throw new Error("compressionQuality parameter is not supported in Gemini API.");return n}function Sa(t,e){const n={},o=i(t,["numberOfVideos"]);e!==void 0&&o!=null&&r(e,["parameters","sampleCount"],o);const s=i(t,["outputGcsUri"]);e!==void 0&&s!=null&&r(e,["parameters","storageUri"],s);const l=i(t,["fps"]);e!==void 0&&l!=null&&r(e,["parameters","fps"],l);const a=i(t,["durationSeconds"]);e!==void 0&&a!=null&&r(e,["parameters","durationSeconds"],a);const u=i(t,["seed"]);e!==void 0&&u!=null&&r(e,["parameters","seed"],u);const c=i(t,["aspectRatio"]);e!==void 0&&c!=null&&r(e,["parameters","aspectRatio"],c);const d=i(t,["resolution"]);e!==void 0&&d!=null&&r(e,["parameters","resolution"],d);const f=i(t,["personGeneration"]);e!==void 0&&f!=null&&r(e,["parameters","personGeneration"],f);const h=i(t,["pubsubTopic"]);e!==void 0&&h!=null&&r(e,["parameters","pubsubTopic"],h);const p=i(t,["negativePrompt"]);e!==void 0&&p!=null&&r(e,["parameters","negativePrompt"],p);const m=i(t,["enhancePrompt"]);e!==void 0&&m!=null&&r(e,["parameters","enhancePrompt"],m);const T=i(t,["generateAudio"]);e!==void 0&&T!=null&&r(e,["parameters","generateAudio"],T);const E=i(t,["lastFrame"]);e!==void 0&&E!=null&&r(e,["instances[0]","lastFrame"],ue(E));const v=i(t,["referenceImages"]);if(e!==void 0&&v!=null){let C=v;Array.isArray(C)&&(C=C.map(x=>Au(x))),r(e,["instances[0]","referenceImages"],C)}const S=i(t,["mask"]);e!==void 0&&S!=null&&r(e,["instances[0]","mask"],Su(S));const _=i(t,["compressionQuality"]);return e!==void 0&&_!=null&&r(e,["parameters","compressionQuality"],_),n}function Ia(t){const e={},n=i(t,["name"]);n!=null&&r(e,["name"],n);const o=i(t,["metadata"]);o!=null&&r(e,["metadata"],o);const s=i(t,["done"]);s!=null&&r(e,["done"],s);const l=i(t,["error"]);l!=null&&r(e,["error"],l);const a=i(t,["response","generateVideoResponse"]);return a!=null&&r(e,["response"],Pa(a)),e}function Aa(t){const e={},n=i(t,["name"]);n!=null&&r(e,["name"],n);const o=i(t,["metadata"]);o!=null&&r(e,["metadata"],o);const s=i(t,["done"]);s!=null&&r(e,["done"],s);const l=i(t,["error"]);l!=null&&r(e,["error"],l);const a=i(t,["response"]);return a!=null&&r(e,["response"],Na(a)),e}function Ra(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["prompt"]);s!=null&&r(n,["instances[0]","prompt"],s);const l=i(e,["image"]);l!=null&&r(n,["instances[0]","image"],Ke(l));const a=i(e,["video"]);a!=null&&r(n,["instances[0]","video"],bo(a));const u=i(e,["source"]);u!=null&&Ma(u,n);const c=i(e,["config"]);return c!=null&&xa(c,n),n}function wa(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["prompt"]);s!=null&&r(n,["instances[0]","prompt"],s);const l=i(e,["image"]);l!=null&&r(n,["instances[0]","image"],ue(l));const a=i(e,["video"]);a!=null&&r(n,["instances[0]","video"],Uo(a));const u=i(e,["source"]);u!=null&&ka(u,n);const c=i(e,["config"]);return c!=null&&Sa(c,n),n}function Pa(t){const e={},n=i(t,["generatedSamples"]);if(n!=null){let l=n;Array.isArray(l)&&(l=l.map(a=>Ua(a))),r(e,["generatedVideos"],l)}const o=i(t,["raiMediaFilteredCount"]);o!=null&&r(e,["raiMediaFilteredCount"],o);const s=i(t,["raiMediaFilteredReasons"]);return s!=null&&r(e,["raiMediaFilteredReasons"],s),e}function Na(t){const e={},n=i(t,["videos"]);if(n!=null){let l=n;Array.isArray(l)&&(l=l.map(a=>La(a))),r(e,["generatedVideos"],l)}const o=i(t,["raiMediaFilteredCount"]);o!=null&&r(e,["raiMediaFilteredCount"],o);const s=i(t,["raiMediaFilteredReasons"]);return s!=null&&r(e,["raiMediaFilteredReasons"],s),e}function Ma(t,e){const n={},o=i(t,["prompt"]);e!==void 0&&o!=null&&r(e,["instances[0]","prompt"],o);const s=i(t,["image"]);e!==void 0&&s!=null&&r(e,["instances[0]","image"],Ke(s));const l=i(t,["video"]);return e!==void 0&&l!=null&&r(e,["instances[0]","video"],bo(l)),n}function ka(t,e){const n={},o=i(t,["prompt"]);e!==void 0&&o!=null&&r(e,["instances[0]","prompt"],o);const s=i(t,["image"]);e!==void 0&&s!=null&&r(e,["instances[0]","image"],ue(s));const l=i(t,["video"]);return e!==void 0&&l!=null&&r(e,["instances[0]","video"],Uo(l)),n}function Da(t){const e={},n=i(t,["_self"]);n!=null&&r(e,["image"],Wa(n));const o=i(t,["raiFilteredReason"]);o!=null&&r(e,["raiFilteredReason"],o);const s=i(t,["_self"]);return s!=null&&r(e,["safetyAttributes"],Mo(s)),e}function $e(t){const e={},n=i(t,["_self"]);n!=null&&r(e,["image"],No(n));const o=i(t,["raiFilteredReason"]);o!=null&&r(e,["raiFilteredReason"],o);const s=i(t,["_self"]);s!=null&&r(e,["safetyAttributes"],ko(s));const l=i(t,["prompt"]);return l!=null&&r(e,["enhancedPrompt"],l),e}function ba(t){const e={},n=i(t,["_self"]);n!=null&&r(e,["mask"],No(n));const o=i(t,["labels"]);if(o!=null){let s=o;Array.isArray(s)&&(s=s.map(l=>l)),r(e,["labels"],s)}return e}function Ua(t){const e={},n=i(t,["video"]);return n!=null&&r(e,["video"],Cu(n)),e}function La(t){const e={},n=i(t,["_self"]);return n!=null&&r(e,["video"],xu(n)),e}function Fa(t){const e={},n=i(t,["modelSelectionConfig"]);n!=null&&r(e,["modelConfig"],n);const o=i(t,["responseJsonSchema"]);o!=null&&r(e,["responseJsonSchema"],o);const s=i(t,["audioTimestamp"]);s!=null&&r(e,["audioTimestamp"],s);const l=i(t,["candidateCount"]);l!=null&&r(e,["candidateCount"],l);const a=i(t,["enableAffectiveDialog"]);a!=null&&r(e,["enableAffectiveDialog"],a);const u=i(t,["frequencyPenalty"]);u!=null&&r(e,["frequencyPenalty"],u);const c=i(t,["logprobs"]);c!=null&&r(e,["logprobs"],c);const d=i(t,["maxOutputTokens"]);d!=null&&r(e,["maxOutputTokens"],d);const f=i(t,["mediaResolution"]);f!=null&&r(e,["mediaResolution"],f);const h=i(t,["presencePenalty"]);h!=null&&r(e,["presencePenalty"],h);const p=i(t,["responseLogprobs"]);p!=null&&r(e,["responseLogprobs"],p);const m=i(t,["responseMimeType"]);m!=null&&r(e,["responseMimeType"],m);const T=i(t,["responseModalities"]);T!=null&&r(e,["responseModalities"],T);const E=i(t,["responseSchema"]);E!=null&&r(e,["responseSchema"],E);const v=i(t,["routingConfig"]);v!=null&&r(e,["routingConfig"],v);const S=i(t,["seed"]);S!=null&&r(e,["seed"],S);const _=i(t,["speechConfig"]);_!=null&&r(e,["speechConfig"],_);const C=i(t,["stopSequences"]);C!=null&&r(e,["stopSequences"],C);const x=i(t,["temperature"]);x!=null&&r(e,["temperature"],x);const R=i(t,["thinkingConfig"]);R!=null&&r(e,["thinkingConfig"],R);const M=i(t,["topK"]);M!=null&&r(e,["topK"],M);const k=i(t,["topP"]);if(k!=null&&r(e,["topP"],k),i(t,["enableEnhancedCivicAnswers"])!==void 0)throw new Error("enableEnhancedCivicAnswers parameter is not supported in Vertex AI.");return e}function Va(t,e){const n={},o=i(e,["model"]);return o!=null&&r(n,["_url","name"],q(t,o)),n}function Ga(t,e){const n={},o=i(e,["model"]);return o!=null&&r(n,["_url","name"],q(t,o)),n}function Ha(t){const e={};if(i(t,["authConfig"])!==void 0)throw new Error("authConfig parameter is not supported in Gemini API.");const n=i(t,["enableWidget"]);return n!=null&&r(e,["enableWidget"],n),e}function qa(t){const e={};if(i(t,["excludeDomains"])!==void 0)throw new Error("excludeDomains parameter is not supported in Gemini API.");if(i(t,["blockingConfidence"])!==void 0)throw new Error("blockingConfidence parameter is not supported in Gemini API.");const n=i(t,["timeRangeFilter"]);return n!=null&&r(e,["timeRangeFilter"],n),e}function Ba(t){const e={},n=i(t,["aspectRatio"]);n!=null&&r(e,["aspectRatio"],n);const o=i(t,["imageSize"]);if(o!=null&&r(e,["imageSize"],o),i(t,["outputMimeType"])!==void 0)throw new Error("outputMimeType parameter is not supported in Gemini API.");if(i(t,["outputCompressionQuality"])!==void 0)throw new Error("outputCompressionQuality parameter is not supported in Gemini API.");return e}function Ja(t){const e={},n=i(t,["aspectRatio"]);n!=null&&r(e,["aspectRatio"],n);const o=i(t,["imageSize"]);o!=null&&r(e,["imageSize"],o);const s=i(t,["outputMimeType"]);s!=null&&r(e,["imageOutputOptions","mimeType"],s);const l=i(t,["outputCompressionQuality"]);return l!=null&&r(e,["imageOutputOptions","compressionQuality"],l),e}function Wa(t){const e={},n=i(t,["bytesBase64Encoded"]);n!=null&&r(e,["imageBytes"],me(n));const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function No(t){const e={},n=i(t,["gcsUri"]);n!=null&&r(e,["gcsUri"],n);const o=i(t,["bytesBase64Encoded"]);o!=null&&r(e,["imageBytes"],me(o));const s=i(t,["mimeType"]);return s!=null&&r(e,["mimeType"],s),e}function Ke(t){const e={};if(i(t,["gcsUri"])!==void 0)throw new Error("gcsUri parameter is not supported in Gemini API.");const n=i(t,["imageBytes"]);n!=null&&r(e,["bytesBase64Encoded"],me(n));const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function ue(t){const e={},n=i(t,["gcsUri"]);n!=null&&r(e,["gcsUri"],n);const o=i(t,["imageBytes"]);o!=null&&r(e,["bytesBase64Encoded"],me(o));const s=i(t,["mimeType"]);return s!=null&&r(e,["mimeType"],s),e}function Ya(t,e,n){const o={},s=i(e,["pageSize"]);n!==void 0&&s!=null&&r(n,["_query","pageSize"],s);const l=i(e,["pageToken"]);n!==void 0&&l!=null&&r(n,["_query","pageToken"],l);const a=i(e,["filter"]);n!==void 0&&a!=null&&r(n,["_query","filter"],a);const u=i(e,["queryBase"]);return n!==void 0&&u!=null&&r(n,["_url","models_url"],mo(t,u)),o}function Oa(t,e,n){const o={},s=i(e,["pageSize"]);n!==void 0&&s!=null&&r(n,["_query","pageSize"],s);const l=i(e,["pageToken"]);n!==void 0&&l!=null&&r(n,["_query","pageToken"],l);const a=i(e,["filter"]);n!==void 0&&a!=null&&r(n,["_query","filter"],a);const u=i(e,["queryBase"]);return n!==void 0&&u!=null&&r(n,["_url","models_url"],mo(t,u)),o}function $a(t,e){const n={},o=i(e,["config"]);return o!=null&&Ya(t,o,n),n}function Ka(t,e){const n={},o=i(e,["config"]);return o!=null&&Oa(t,o,n),n}function za(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["nextPageToken"]);o!=null&&r(e,["nextPageToken"],o);const s=i(t,["_self"]);if(s!=null){let l=go(s);Array.isArray(l)&&(l=l.map(a=>Ct(a))),r(e,["models"],l)}return e}function Xa(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["nextPageToken"]);o!=null&&r(e,["nextPageToken"],o);const s=i(t,["_self"]);if(s!=null){let l=go(s);Array.isArray(l)&&(l=l.map(a=>xt(a))),r(e,["models"],l)}return e}function Qa(t){const e={},n=i(t,["maskMode"]);n!=null&&r(e,["maskMode"],n);const o=i(t,["segmentationClasses"]);o!=null&&r(e,["maskClasses"],o);const s=i(t,["maskDilation"]);return s!=null&&r(e,["dilation"],s),e}function Ct(t){const e={},n=i(t,["name"]);n!=null&&r(e,["name"],n);const o=i(t,["displayName"]);o!=null&&r(e,["displayName"],o);const s=i(t,["description"]);s!=null&&r(e,["description"],s);const l=i(t,["version"]);l!=null&&r(e,["version"],l);const a=i(t,["_self"]);a!=null&&r(e,["tunedModelInfo"],pu(a));const u=i(t,["inputTokenLimit"]);u!=null&&r(e,["inputTokenLimit"],u);const c=i(t,["outputTokenLimit"]);c!=null&&r(e,["outputTokenLimit"],c);const d=i(t,["supportedGenerationMethods"]);d!=null&&r(e,["supportedActions"],d);const f=i(t,["temperature"]);f!=null&&r(e,["temperature"],f);const h=i(t,["maxTemperature"]);h!=null&&r(e,["maxTemperature"],h);const p=i(t,["topP"]);p!=null&&r(e,["topP"],p);const m=i(t,["topK"]);m!=null&&r(e,["topK"],m);const T=i(t,["thinking"]);return T!=null&&r(e,["thinking"],T),e}function xt(t){const e={},n=i(t,["name"]);n!=null&&r(e,["name"],n);const o=i(t,["displayName"]);o!=null&&r(e,["displayName"],o);const s=i(t,["description"]);s!=null&&r(e,["description"],s);const l=i(t,["versionId"]);l!=null&&r(e,["version"],l);const a=i(t,["deployedModels"]);if(a!=null){let h=a;Array.isArray(h)&&(h=h.map(p=>da(p))),r(e,["endpoints"],h)}const u=i(t,["labels"]);u!=null&&r(e,["labels"],u);const c=i(t,["_self"]);c!=null&&r(e,["tunedModelInfo"],hu(c));const d=i(t,["defaultCheckpointId"]);d!=null&&r(e,["defaultCheckpointId"],d);const f=i(t,["checkpoints"]);if(f!=null){let h=f;Array.isArray(h)&&(h=h.map(p=>p)),r(e,["checkpoints"],h)}return e}function Za(t){const e={},n=i(t,["mediaResolution"]);n!=null&&r(e,["mediaResolution"],n);const o=i(t,["codeExecutionResult"]);o!=null&&r(e,["codeExecutionResult"],o);const s=i(t,["executableCode"]);s!=null&&r(e,["executableCode"],s);const l=i(t,["fileData"]);l!=null&&r(e,["fileData"],ca(l));const a=i(t,["functionCall"]);a!=null&&r(e,["functionCall"],fa(a));const u=i(t,["functionResponse"]);u!=null&&r(e,["functionResponse"],u);const c=i(t,["inlineData"]);c!=null&&r(e,["inlineData"],Fl(c));const d=i(t,["text"]);d!=null&&r(e,["text"],d);const f=i(t,["thought"]);f!=null&&r(e,["thought"],f);const h=i(t,["thoughtSignature"]);h!=null&&r(e,["thoughtSignature"],h);const p=i(t,["videoMetadata"]);return p!=null&&r(e,["videoMetadata"],p),e}function ja(t){const e={},n=i(t,["productImage"]);return n!=null&&r(e,["image"],ue(n)),e}function eu(t,e){const n={},o=i(t,["numberOfImages"]);e!==void 0&&o!=null&&r(e,["parameters","sampleCount"],o);const s=i(t,["baseSteps"]);e!==void 0&&s!=null&&r(e,["parameters","baseSteps"],s);const l=i(t,["outputGcsUri"]);e!==void 0&&l!=null&&r(e,["parameters","storageUri"],l);const a=i(t,["seed"]);e!==void 0&&a!=null&&r(e,["parameters","seed"],a);const u=i(t,["safetyFilterLevel"]);e!==void 0&&u!=null&&r(e,["parameters","safetySetting"],u);const c=i(t,["personGeneration"]);e!==void 0&&c!=null&&r(e,["parameters","personGeneration"],c);const d=i(t,["addWatermark"]);e!==void 0&&d!=null&&r(e,["parameters","addWatermark"],d);const f=i(t,["outputMimeType"]);e!==void 0&&f!=null&&r(e,["parameters","outputOptions","mimeType"],f);const h=i(t,["outputCompressionQuality"]);e!==void 0&&h!=null&&r(e,["parameters","outputOptions","compressionQuality"],h);const p=i(t,["enhancePrompt"]);e!==void 0&&p!=null&&r(e,["parameters","enhancePrompt"],p);const m=i(t,["labels"]);return e!==void 0&&m!=null&&r(e,["labels"],m),n}function tu(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["source"]);s!=null&&ou(s,n);const l=i(e,["config"]);return l!=null&&eu(l,n),n}function nu(t){const e={},n=i(t,["predictions"]);if(n!=null){let o=n;Array.isArray(o)&&(o=o.map(s=>$e(s))),r(e,["generatedImages"],o)}return e}function ou(t,e){const n={},o=i(t,["prompt"]);e!==void 0&&o!=null&&r(e,["instances[0]","prompt"],o);const s=i(t,["personImage"]);e!==void 0&&s!=null&&r(e,["instances[0]","personImage","image"],ue(s));const l=i(t,["productImages"]);if(e!==void 0&&l!=null){let a=l;Array.isArray(a)&&(a=a.map(u=>ja(u))),r(e,["instances[0]","productImages"],a)}return n}function iu(t){const e={},n=i(t,["referenceImage"]);n!=null&&r(e,["referenceImage"],ue(n));const o=i(t,["referenceId"]);o!=null&&r(e,["referenceId"],o);const s=i(t,["referenceType"]);s!=null&&r(e,["referenceType"],s);const l=i(t,["maskImageConfig"]);l!=null&&r(e,["maskImageConfig"],Qa(l));const a=i(t,["controlImageConfig"]);a!=null&&r(e,["controlImageConfig"],Wl(a));const u=i(t,["styleImageConfig"]);u!=null&&r(e,["styleImageConfig"],u);const c=i(t,["subjectImageConfig"]);return c!=null&&r(e,["subjectImageConfig"],c),e}function Mo(t){const e={},n=i(t,["safetyAttributes","categories"]);n!=null&&r(e,["categories"],n);const o=i(t,["safetyAttributes","scores"]);o!=null&&r(e,["scores"],o);const s=i(t,["contentType"]);return s!=null&&r(e,["contentType"],s),e}function ko(t){const e={},n=i(t,["safetyAttributes","categories"]);n!=null&&r(e,["categories"],n);const o=i(t,["safetyAttributes","scores"]);o!=null&&r(e,["scores"],o);const s=i(t,["contentType"]);return s!=null&&r(e,["contentType"],s),e}function su(t){const e={},n=i(t,["category"]);if(n!=null&&r(e,["category"],n),i(t,["method"])!==void 0)throw new Error("method parameter is not supported in Gemini API.");const o=i(t,["threshold"]);return o!=null&&r(e,["threshold"],o),e}function ru(t){const e={},n=i(t,["image"]);return n!=null&&r(e,["image"],ue(n)),e}function lu(t,e){const n={},o=i(t,["mode"]);e!==void 0&&o!=null&&r(e,["parameters","mode"],o);const s=i(t,["maxPredictions"]);e!==void 0&&s!=null&&r(e,["parameters","maxPredictions"],s);const l=i(t,["confidenceThreshold"]);e!==void 0&&l!=null&&r(e,["parameters","confidenceThreshold"],l);const a=i(t,["maskDilation"]);e!==void 0&&a!=null&&r(e,["parameters","maskDilation"],a);const u=i(t,["binaryColorThreshold"]);e!==void 0&&u!=null&&r(e,["parameters","binaryColorThreshold"],u);const c=i(t,["labels"]);return e!==void 0&&c!=null&&r(e,["labels"],c),n}function au(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["source"]);s!=null&&du(s,n);const l=i(e,["config"]);return l!=null&&lu(l,n),n}function uu(t){const e={},n=i(t,["predictions"]);if(n!=null){let o=n;Array.isArray(o)&&(o=o.map(s=>ba(s))),r(e,["generatedMasks"],o)}return e}function du(t,e){const n={},o=i(t,["prompt"]);e!==void 0&&o!=null&&r(e,["instances[0]","prompt"],o);const s=i(t,["image"]);e!==void 0&&s!=null&&r(e,["instances[0]","image"],ue(s));const l=i(t,["scribbleImage"]);return e!==void 0&&l!=null&&r(e,["instances[0]","scribble"],ru(l)),n}function cu(t){const e={},n=i(t,["functionCallingConfig"]);n!=null&&r(e,["functionCallingConfig"],pa(n));const o=i(t,["retrievalConfig"]);return o!=null&&r(e,["retrievalConfig"],o),e}function fu(t){const e={},n=i(t,["functionDeclarations"]);if(n!=null){let f=n;Array.isArray(f)&&(f=f.map(h=>h)),r(e,["functionDeclarations"],f)}if(i(t,["retrieval"])!==void 0)throw new Error("retrieval parameter is not supported in Gemini API.");const o=i(t,["googleSearchRetrieval"]);o!=null&&r(e,["googleSearchRetrieval"],o);const s=i(t,["computerUse"]);s!=null&&r(e,["computerUse"],s);const l=i(t,["fileSearch"]);l!=null&&r(e,["fileSearch"],l);const a=i(t,["codeExecution"]);if(a!=null&&r(e,["codeExecution"],a),i(t,["enterpriseWebSearch"])!==void 0)throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const u=i(t,["googleMaps"]);u!=null&&r(e,["googleMaps"],Ha(u));const c=i(t,["googleSearch"]);c!=null&&r(e,["googleSearch"],qa(c));const d=i(t,["urlContext"]);return d!=null&&r(e,["urlContext"],d),e}function Do(t){const e={},n=i(t,["functionDeclarations"]);if(n!=null){let h=n;Array.isArray(h)&&(h=h.map(p=>ha(p))),r(e,["functionDeclarations"],h)}const o=i(t,["retrieval"]);o!=null&&r(e,["retrieval"],o);const s=i(t,["googleSearchRetrieval"]);s!=null&&r(e,["googleSearchRetrieval"],s);const l=i(t,["computerUse"]);if(l!=null&&r(e,["computerUse"],l),i(t,["fileSearch"])!==void 0)throw new Error("fileSearch parameter is not supported in Vertex AI.");const a=i(t,["codeExecution"]);a!=null&&r(e,["codeExecution"],a);const u=i(t,["enterpriseWebSearch"]);u!=null&&r(e,["enterpriseWebSearch"],u);const c=i(t,["googleMaps"]);c!=null&&r(e,["googleMaps"],c);const d=i(t,["googleSearch"]);d!=null&&r(e,["googleSearch"],d);const f=i(t,["urlContext"]);return f!=null&&r(e,["urlContext"],f),e}function pu(t){const e={},n=i(t,["baseModel"]);n!=null&&r(e,["baseModel"],n);const o=i(t,["createTime"]);o!=null&&r(e,["createTime"],o);const s=i(t,["updateTime"]);return s!=null&&r(e,["updateTime"],s),e}function hu(t){const e={},n=i(t,["labels","google-vertex-llm-tuning-base-model-id"]);n!=null&&r(e,["baseModel"],n);const o=i(t,["createTime"]);o!=null&&r(e,["createTime"],o);const s=i(t,["updateTime"]);return s!=null&&r(e,["updateTime"],s),e}function mu(t,e){const n={},o=i(t,["displayName"]);e!==void 0&&o!=null&&r(e,["displayName"],o);const s=i(t,["description"]);e!==void 0&&s!=null&&r(e,["description"],s);const l=i(t,["defaultCheckpointId"]);return e!==void 0&&l!=null&&r(e,["defaultCheckpointId"],l),n}function gu(t,e){const n={},o=i(t,["displayName"]);e!==void 0&&o!=null&&r(e,["displayName"],o);const s=i(t,["description"]);e!==void 0&&s!=null&&r(e,["description"],s);const l=i(t,["defaultCheckpointId"]);return e!==void 0&&l!=null&&r(e,["defaultCheckpointId"],l),n}function yu(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","name"],q(t,o));const s=i(e,["config"]);return s!=null&&mu(s,n),n}function Tu(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["config"]);return s!=null&&gu(s,n),n}function vu(t,e){const n={},o=i(t,["outputGcsUri"]);e!==void 0&&o!=null&&r(e,["parameters","storageUri"],o);const s=i(t,["safetyFilterLevel"]);e!==void 0&&s!=null&&r(e,["parameters","safetySetting"],s);const l=i(t,["personGeneration"]);e!==void 0&&l!=null&&r(e,["parameters","personGeneration"],l);const a=i(t,["includeRaiReason"]);e!==void 0&&a!=null&&r(e,["parameters","includeRaiReason"],a);const u=i(t,["outputMimeType"]);e!==void 0&&u!=null&&r(e,["parameters","outputOptions","mimeType"],u);const c=i(t,["outputCompressionQuality"]);e!==void 0&&c!=null&&r(e,["parameters","outputOptions","compressionQuality"],c);const d=i(t,["enhanceInputImage"]);e!==void 0&&d!=null&&r(e,["parameters","upscaleConfig","enhanceInputImage"],d);const f=i(t,["imagePreservationFactor"]);e!==void 0&&f!=null&&r(e,["parameters","upscaleConfig","imagePreservationFactor"],f);const h=i(t,["labels"]);e!==void 0&&h!=null&&r(e,["labels"],h);const p=i(t,["numberOfImages"]);e!==void 0&&p!=null&&r(e,["parameters","sampleCount"],p);const m=i(t,["mode"]);return e!==void 0&&m!=null&&r(e,["parameters","mode"],m),n}function _u(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["_url","model"],q(t,o));const s=i(e,["image"]);s!=null&&r(n,["instances[0]","image"],ue(s));const l=i(e,["upscaleFactor"]);l!=null&&r(n,["parameters","upscaleConfig","upscaleFactor"],l);const a=i(e,["config"]);return a!=null&&vu(a,n),n}function Eu(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["predictions"]);if(o!=null){let s=o;Array.isArray(s)&&(s=s.map(l=>$e(l))),r(e,["generatedImages"],s)}return e}function Cu(t){const e={},n=i(t,["uri"]);n!=null&&r(e,["uri"],n);const o=i(t,["encodedVideo"]);o!=null&&r(e,["videoBytes"],me(o));const s=i(t,["encoding"]);return s!=null&&r(e,["mimeType"],s),e}function xu(t){const e={},n=i(t,["gcsUri"]);n!=null&&r(e,["uri"],n);const o=i(t,["bytesBase64Encoded"]);o!=null&&r(e,["videoBytes"],me(o));const s=i(t,["mimeType"]);return s!=null&&r(e,["mimeType"],s),e}function Su(t){const e={},n=i(t,["image"]);n!=null&&r(e,["_self"],ue(n));const o=i(t,["maskMode"]);return o!=null&&r(e,["maskMode"],o),e}function Iu(t){const e={},n=i(t,["image"]);n!=null&&r(e,["image"],Ke(n));const o=i(t,["referenceType"]);return o!=null&&r(e,["referenceType"],o),e}function Au(t){const e={},n=i(t,["image"]);n!=null&&r(e,["image"],ue(n));const o=i(t,["referenceType"]);return o!=null&&r(e,["referenceType"],o),e}function bo(t){const e={},n=i(t,["uri"]);n!=null&&r(e,["uri"],n);const o=i(t,["videoBytes"]);o!=null&&r(e,["encodedVideo"],me(o));const s=i(t,["mimeType"]);return s!=null&&r(e,["encoding"],s),e}function Uo(t){const e={},n=i(t,["uri"]);n!=null&&r(e,["gcsUri"],n);const o=i(t,["videoBytes"]);o!=null&&r(e,["bytesBase64Encoded"],me(o));const s=i(t,["mimeType"]);return s!=null&&r(e,["mimeType"],s),e}/**
99
- * @license
100
- * Copyright 2025 Google LLC
101
- * SPDX-License-Identifier: Apache-2.0
102
- */function Ru(t,e){const n={},o=i(t,["displayName"]);return e!==void 0&&o!=null&&r(e,["displayName"],o),n}function wu(t){const e={},n=i(t,["config"]);return n!=null&&Ru(n,e),e}function Pu(t,e){const n={},o=i(t,["force"]);return e!==void 0&&o!=null&&r(e,["_query","force"],o),n}function Nu(t){const e={},n=i(t,["name"]);n!=null&&r(e,["_url","name"],n);const o=i(t,["config"]);return o!=null&&Pu(o,e),e}function Mu(t){const e={},n=i(t,["name"]);return n!=null&&r(e,["_url","name"],n),e}function ku(t,e){const n={},o=i(t,["customMetadata"]);if(e!==void 0&&o!=null){let l=o;Array.isArray(l)&&(l=l.map(a=>a)),r(e,["customMetadata"],l)}const s=i(t,["chunkingConfig"]);return e!==void 0&&s!=null&&r(e,["chunkingConfig"],s),n}function Du(t){const e={},n=i(t,["name"]);n!=null&&r(e,["name"],n);const o=i(t,["metadata"]);o!=null&&r(e,["metadata"],o);const s=i(t,["done"]);s!=null&&r(e,["done"],s);const l=i(t,["error"]);l!=null&&r(e,["error"],l);const a=i(t,["response"]);return a!=null&&r(e,["response"],Uu(a)),e}function bu(t){const e={},n=i(t,["fileSearchStoreName"]);n!=null&&r(e,["_url","file_search_store_name"],n);const o=i(t,["fileName"]);o!=null&&r(e,["fileName"],o);const s=i(t,["config"]);return s!=null&&ku(s,e),e}function Uu(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["parent"]);o!=null&&r(e,["parent"],o);const s=i(t,["documentName"]);return s!=null&&r(e,["documentName"],s),e}function Lu(t,e){const n={},o=i(t,["pageSize"]);e!==void 0&&o!=null&&r(e,["_query","pageSize"],o);const s=i(t,["pageToken"]);return e!==void 0&&s!=null&&r(e,["_query","pageToken"],s),n}function Fu(t){const e={},n=i(t,["config"]);return n!=null&&Lu(n,e),e}function Vu(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["nextPageToken"]);o!=null&&r(e,["nextPageToken"],o);const s=i(t,["fileSearchStores"]);if(s!=null){let l=s;Array.isArray(l)&&(l=l.map(a=>a)),r(e,["fileSearchStores"],l)}return e}function Lo(t,e){const n={},o=i(t,["mimeType"]);e!==void 0&&o!=null&&r(e,["mimeType"],o);const s=i(t,["displayName"]);e!==void 0&&s!=null&&r(e,["displayName"],s);const l=i(t,["customMetadata"]);if(e!==void 0&&l!=null){let u=l;Array.isArray(u)&&(u=u.map(c=>c)),r(e,["customMetadata"],u)}const a=i(t,["chunkingConfig"]);return e!==void 0&&a!=null&&r(e,["chunkingConfig"],a),n}function Gu(t){const e={},n=i(t,["fileSearchStoreName"]);n!=null&&r(e,["_url","file_search_store_name"],n);const o=i(t,["config"]);return o!=null&&Lo(o,e),e}function Hu(t){const e={},n=i(t,["sdkHttpResponse"]);return n!=null&&r(e,["sdkHttpResponse"],n),e}/**
103
- * @license
104
- * Copyright 2025 Google LLC
105
- * SPDX-License-Identifier: Apache-2.0
106
- */const qu="Content-Type",Bu="X-Server-Timeout",Ju="User-Agent",St="x-goog-api-client",Wu="google-genai-sdk/1.34.0",Yu="v1beta1",Ou="v1beta";class $u{constructor(e){var n,o;this.clientOptions=Object.assign(Object.assign({},e),{project:e.project,location:e.location,apiKey:e.apiKey,vertexai:e.vertexai});const s={};this.clientOptions.vertexai?(s.apiVersion=(n=this.clientOptions.apiVersion)!==null&&n!==void 0?n:Yu,s.baseUrl=this.baseUrlFromProjectLocation(),this.normalizeAuthParameters()):(s.apiVersion=(o=this.clientOptions.apiVersion)!==null&&o!==void 0?o:Ou,s.baseUrl="https://generativelanguage.googleapis.com/"),s.headers=this.getDefaultHeaders(),this.clientOptions.httpOptions=s,e.httpOptions&&(this.clientOptions.httpOptions=this.patchHttpOptions(s,e.httpOptions))}baseUrlFromProjectLocation(){return this.clientOptions.project&&this.clientOptions.location&&this.clientOptions.location!=="global"?`https://${this.clientOptions.location}-aiplatform.googleapis.com/`:"https://aiplatform.googleapis.com/"}normalizeAuthParameters(){if(this.clientOptions.project&&this.clientOptions.location){this.clientOptions.apiKey=void 0;return}this.clientOptions.project=void 0,this.clientOptions.location=void 0}isVertexAI(){var e;return(e=this.clientOptions.vertexai)!==null&&e!==void 0?e:!1}getProject(){return this.clientOptions.project}getLocation(){return this.clientOptions.location}async getAuthHeaders(){const e=new Headers;return await this.clientOptions.auth.addAuthHeaders(e),e}getApiVersion(){if(this.clientOptions.httpOptions&&this.clientOptions.httpOptions.apiVersion!==void 0)return this.clientOptions.httpOptions.apiVersion;throw new Error("API version is not set.")}getBaseUrl(){if(this.clientOptions.httpOptions&&this.clientOptions.httpOptions.baseUrl!==void 0)return this.clientOptions.httpOptions.baseUrl;throw new Error("Base URL is not set.")}getRequestUrl(){return this.getRequestUrlInternal(this.clientOptions.httpOptions)}getHeaders(){if(this.clientOptions.httpOptions&&this.clientOptions.httpOptions.headers!==void 0)return this.clientOptions.httpOptions.headers;throw new Error("Headers are not set.")}getRequestUrlInternal(e){if(!e||e.baseUrl===void 0||e.apiVersion===void 0)throw new Error("HTTP options are not correctly set.");const o=[e.baseUrl.endsWith("/")?e.baseUrl.slice(0,-1):e.baseUrl];return e.apiVersion&&e.apiVersion!==""&&o.push(e.apiVersion),o.join("/")}getBaseResourcePath(){return`projects/${this.clientOptions.project}/locations/${this.clientOptions.location}`}getApiKey(){return this.clientOptions.apiKey}getWebsocketBaseUrl(){const e=this.getBaseUrl(),n=new URL(e);return n.protocol=n.protocol=="http:"?"ws":"wss",n.toString()}setBaseUrl(e){if(this.clientOptions.httpOptions)this.clientOptions.httpOptions.baseUrl=e;else throw new Error("HTTP options are not correctly set.")}constructUrl(e,n,o){const s=[this.getRequestUrlInternal(n)];return o&&s.push(this.getBaseResourcePath()),e!==""&&s.push(e),new URL(`${s.join("/")}`)}shouldPrependVertexProjectPath(e){return!(this.clientOptions.apiKey||!this.clientOptions.vertexai||e.path.startsWith("projects/")||e.httpMethod==="GET"&&e.path.startsWith("publishers/google/models"))}async request(e){let n=this.clientOptions.httpOptions;e.httpOptions&&(n=this.patchHttpOptions(this.clientOptions.httpOptions,e.httpOptions));const o=this.shouldPrependVertexProjectPath(e),s=this.constructUrl(e.path,n,o);if(e.queryParams)for(const[a,u]of Object.entries(e.queryParams))s.searchParams.append(a,String(u));let l={};if(e.httpMethod==="GET"){if(e.body&&e.body!=="{}")throw new Error("Request body should be empty for GET request, but got non empty request body")}else l.body=e.body;return l=await this.includeExtraHttpOptionsToRequestInit(l,n,s.toString(),e.abortSignal),this.unaryApiCall(s,l,e.httpMethod)}patchHttpOptions(e,n){const o=JSON.parse(JSON.stringify(e));for(const[s,l]of Object.entries(n))typeof l=="object"?o[s]=Object.assign(Object.assign({},o[s]),l):l!==void 0&&(o[s]=l);return o}async requestStream(e){let n=this.clientOptions.httpOptions;e.httpOptions&&(n=this.patchHttpOptions(this.clientOptions.httpOptions,e.httpOptions));const o=this.shouldPrependVertexProjectPath(e),s=this.constructUrl(e.path,n,o);(!s.searchParams.has("alt")||s.searchParams.get("alt")!=="sse")&&s.searchParams.set("alt","sse");let l={};return l.body=e.body,l=await this.includeExtraHttpOptionsToRequestInit(l,n,s.toString(),e.abortSignal),this.streamApiCall(s,l,e.httpMethod)}async includeExtraHttpOptionsToRequestInit(e,n,o,s){if(n&&n.timeout||s){const l=new AbortController,a=l.signal;if(n.timeout&&(n==null?void 0:n.timeout)>0){const u=setTimeout(()=>l.abort(),n.timeout);u&&typeof u.unref=="function"&&u.unref()}s&&s.addEventListener("abort",()=>{l.abort()}),e.signal=a}return n&&n.extraBody!==null&&Ku(e,n.extraBody),e.headers=await this.getHeadersInternal(n,o),e}async unaryApiCall(e,n,o){return this.apiCall(e.toString(),Object.assign(Object.assign({},n),{method:o})).then(async s=>(await Fo(s),new pt(s))).catch(s=>{throw s instanceof Error?s:new Error(JSON.stringify(s))})}async streamApiCall(e,n,o){return this.apiCall(e.toString(),Object.assign(Object.assign({},n),{method:o})).then(async s=>(await Fo(s),this.processStreamResponse(s))).catch(s=>{throw s instanceof Error?s:new Error(JSON.stringify(s))})}processStreamResponse(e){return le(this,arguments,function*(){var o;const s=(o=e==null?void 0:e.body)===null||o===void 0?void 0:o.getReader(),l=new TextDecoder("utf-8");if(!s)throw new Error("Response body is empty");try{let a="";const u="data:",c=[`
107
-
108
- `,"\r\r",`\r
109
- \r
110
- `];for(;;){const{done:d,value:f}=yield U(s.read());if(d){if(a.trim().length>0)throw new Error("Incomplete JSON segment at the end");break}const h=l.decode(f,{stream:!0});try{const T=JSON.parse(h);if("error"in T){const E=JSON.parse(JSON.stringify(T.error)),v=E.status,S=E.code,_=`got status: ${v}. ${JSON.stringify(T)}`;if(S>=400&&S<600)throw new We({message:_,status:S})}}catch(T){if(T.name==="ApiError")throw T}a+=h;let p=-1,m=0;for(;;){p=-1,m=0;for(const v of c){const S=a.indexOf(v);S!==-1&&(p===-1||S<p)&&(p=S,m=v.length)}if(p===-1)break;const T=a.substring(0,p);a=a.substring(p+m);const E=T.trim();if(E.startsWith(u)){const v=E.substring(u.length).trim();try{const S=new Response(v,{headers:e==null?void 0:e.headers,status:e==null?void 0:e.status,statusText:e==null?void 0:e.statusText});yield yield U(new pt(S))}catch(S){throw new Error(`exception parsing stream chunk ${v}. ${S}`)}}}}}finally{s.releaseLock()}})}async apiCall(e,n){return fetch(e,n).catch(o=>{throw new Error(`exception ${o} sending request`)})}getDefaultHeaders(){const e={},n=Wu+" "+this.clientOptions.userAgentExtra;return e[Ju]=n,e[St]=n,e[qu]="application/json",e}async getHeadersInternal(e,n){const o=new Headers;if(e&&e.headers){for(const[s,l]of Object.entries(e.headers))o.append(s,l);e.timeout&&e.timeout>0&&o.append(Bu,String(Math.ceil(e.timeout/1e3)))}return await this.clientOptions.auth.addAuthHeaders(o,n),o}getFileName(e){var n;let o="";return typeof e=="string"&&(o=e.replace(/[/\\]+$/,""),o=(n=o.split(/[/\\]/).pop())!==null&&n!==void 0?n:""),o}async uploadFile(e,n){var o;const s={};n!=null&&(s.mimeType=n.mimeType,s.name=n.name,s.displayName=n.displayName),s.name&&!s.name.startsWith("files/")&&(s.name=`files/${s.name}`);const l=this.clientOptions.uploader,a=await l.stat(e);s.sizeBytes=String(a.size);const u=(o=n==null?void 0:n.mimeType)!==null&&o!==void 0?o:a.type;if(u===void 0||u==="")throw new Error("Can not determine mimeType. Please provide mimeType in the config.");s.mimeType=u;const c={file:s},d=this.getFileName(e),f=A("upload/v1beta/files",c._url),h=await this.fetchUploadUrl(f,s.sizeBytes,s.mimeType,d,c,n==null?void 0:n.httpOptions);return l.upload(e,h,this)}async uploadFileToFileSearchStore(e,n,o){var s;const l=this.clientOptions.uploader,a=await l.stat(n),u=String(a.size),c=(s=o==null?void 0:o.mimeType)!==null&&s!==void 0?s:a.type;if(c===void 0||c==="")throw new Error("Can not determine mimeType. Please provide mimeType in the config.");const d=`upload/v1beta/${e}:uploadToFileSearchStore`,f=this.getFileName(n),h={};o!=null&&Lo(o,h);const p=await this.fetchUploadUrl(d,u,c,f,h,o==null?void 0:o.httpOptions);return l.uploadToFileSearchStore(n,p,this)}async downloadFile(e){await this.clientOptions.downloader.download(e,this)}async fetchUploadUrl(e,n,o,s,l,a){var u;let c={};a?c=a:c={apiVersion:"",headers:Object.assign({"Content-Type":"application/json","X-Goog-Upload-Protocol":"resumable","X-Goog-Upload-Command":"start","X-Goog-Upload-Header-Content-Length":`${n}`,"X-Goog-Upload-Header-Content-Type":`${o}`},s?{"X-Goog-Upload-File-Name":s}:{})};const d=await this.request({path:e,body:JSON.stringify(l),httpMethod:"POST",httpOptions:c});if(!d||!(d!=null&&d.headers))throw new Error("Server did not return an HttpResponse or the returned HttpResponse did not have headers.");const f=(u=d==null?void 0:d.headers)===null||u===void 0?void 0:u["x-goog-upload-url"];if(f===void 0)throw new Error("Failed to get upload url. Server did not return the x-google-upload-url in the headers");return f}}async function Fo(t){var e;if(t===void 0)throw new Error("response is undefined");if(!t.ok){const n=t.status;let o;!((e=t.headers.get("content-type"))===null||e===void 0)&&e.includes("application/json")?o=await t.json():o={error:{message:await t.text(),code:t.status,status:t.statusText}};const s=JSON.stringify(o);throw n>=400&&n<600?new We({message:s,status:n}):new Error(s)}}function Ku(t,e){if(!e||Object.keys(e).length===0)return;if(t.body instanceof Blob){console.warn("includeExtraBodyToRequestInit: extraBody provided but current request body is a Blob. extraBody will be ignored as merging is not supported for Blob bodies.");return}let n={};if(typeof t.body=="string"&&t.body.length>0)try{const l=JSON.parse(t.body);if(typeof l=="object"&&l!==null&&!Array.isArray(l))n=l;else{console.warn("includeExtraBodyToRequestInit: Original request body is valid JSON but not a non-array object. Skip applying extraBody to the request body.");return}}catch{console.warn("includeExtraBodyToRequestInit: Original request body is not valid JSON. Skip applying extraBody to the request body.");return}function o(l,a){const u=Object.assign({},l);for(const c in a)if(Object.prototype.hasOwnProperty.call(a,c)){const d=a[c],f=u[c];d&&typeof d=="object"&&!Array.isArray(d)&&f&&typeof f=="object"&&!Array.isArray(f)?u[c]=o(f,d):(f&&d&&typeof f!=typeof d&&console.warn(`includeExtraBodyToRequestInit:deepMerge: Type mismatch for key "${c}". Original type: ${typeof f}, New type: ${typeof d}. Overwriting.`),u[c]=d)}return u}const s=o(n,e);t.body=JSON.stringify(s)}/**
111
- * @license
112
- * Copyright 2025 Google LLC
113
- * SPDX-License-Identifier: Apache-2.0
114
- */const zu="mcp_used/unknown";let Xu=!1;function Vo(t){for(const e of t)if(Qu(e)||typeof e=="object"&&"inputSchema"in e)return!0;return Xu}function Go(t){var e;const n=(e=t[St])!==null&&e!==void 0?e:"";t[St]=(n+` ${zu}`).trimStart()}function Qu(t){return t!==null&&typeof t=="object"&&t instanceof It}function Zu(t){return le(this,arguments,function*(n,o=100){let s,l=0;for(;l<o;){const a=yield U(n.listTools({cursor:s}));for(const u of a.tools)yield yield U(u),l++;if(!a.nextCursor)break;s=a.nextCursor}})}class It{constructor(e=[],n){this.mcpTools=[],this.functionNameToMcpClient={},this.mcpClients=e,this.config=n}static create(e,n){return new It(e,n)}async initialize(){var e,n,o,s;if(this.mcpTools.length>0)return;const l={},a=[];for(const f of this.mcpClients)try{for(var u=!0,c=(n=void 0,ae(Zu(f))),d;d=await c.next(),e=d.done,!e;u=!0){s=d.value,u=!1;const h=s;a.push(h);const p=h.name;if(l[p])throw new Error(`Duplicate function name ${p} found in MCP tools. Please ensure function names are unique.`);l[p]=f}}catch(h){n={error:h}}finally{try{!u&&!e&&(o=c.return)&&await o.call(c)}finally{if(n)throw n.error}}this.mcpTools=a,this.functionNameToMcpClient=l}async tool(){return await this.initialize(),Ms(this.mcpTools,this.config)}async callTool(e){await this.initialize();const n=[];for(const o of e)if(o.name in this.functionNameToMcpClient){const s=this.functionNameToMcpClient[o.name];let l;this.config.timeout&&(l={timeout:this.config.timeout});const a=await s.callTool({name:o.name,arguments:o.args},void 0,l);n.push({functionResponse:{name:o.name,response:a.isError?{error:a}:a}})}return n}}/**
115
- * @license
116
- * Copyright 2025 Google LLC
117
- * SPDX-License-Identifier: Apache-2.0
118
- */async function ju(t,e,n){const o=new xs;let s;n.data instanceof Blob?s=JSON.parse(await n.data.text()):s=JSON.parse(n.data),Object.assign(o,s),e(o)}class ed{constructor(e,n,o){this.apiClient=e,this.auth=n,this.webSocketFactory=o}async connect(e){var n,o;if(this.apiClient.isVertexAI())throw new Error("Live music is not supported for Vertex AI.");console.warn("Live music generation is experimental and may change in future versions.");const s=this.apiClient.getWebsocketBaseUrl(),l=this.apiClient.getApiVersion(),a=od(this.apiClient.getDefaultHeaders()),u=this.apiClient.getApiKey(),c=`${s}/ws/google.ai.generativelanguage.${l}.GenerativeService.BidiGenerateMusic?key=${u}`;let d=()=>{};const f=new Promise(C=>{d=C}),h=e.callbacks,p=function(){d({})},m=this.apiClient,T={onopen:p,onmessage:C=>{ju(m,h.onmessage,C)},onerror:(n=h==null?void 0:h.onerror)!==null&&n!==void 0?n:function(C){},onclose:(o=h==null?void 0:h.onclose)!==null&&o!==void 0?o:function(C){}},E=this.webSocketFactory.create(c,nd(a),T);E.connect(),await f;const _={setup:{model:q(this.apiClient,e.model)}};return E.send(JSON.stringify(_)),new td(E,this.apiClient)}}class td{constructor(e,n){this.conn=e,this.apiClient=n}async setWeightedPrompts(e){if(!e.weightedPrompts||Object.keys(e.weightedPrompts).length===0)throw new Error("Weighted prompts must be set and contain at least one entry.");const n=wl(e);this.conn.send(JSON.stringify({clientContent:n}))}async setMusicGenerationConfig(e){e.musicGenerationConfig||(e.musicGenerationConfig={});const n=Rl(e);this.conn.send(JSON.stringify(n))}sendPlaybackControl(e){const n={playbackControl:e};this.conn.send(JSON.stringify(n))}play(){this.sendPlaybackControl(_e.PLAY)}pause(){this.sendPlaybackControl(_e.PAUSE)}stop(){this.sendPlaybackControl(_e.STOP)}resetContext(){this.sendPlaybackControl(_e.RESET_CONTEXT)}close(){this.conn.close()}}function nd(t){const e={};return t.forEach((n,o)=>{e[o]=n}),e}function od(t){const e=new Headers;for(const[n,o]of Object.entries(t))e.append(n,o);return e}/**
119
- * @license
120
- * Copyright 2025 Google LLC
121
- * SPDX-License-Identifier: Apache-2.0
122
- */const id="FunctionResponse request must have an `id` field from the response of a ToolCall.FunctionalCalls in Google AI.";async function sd(t,e,n){const o=new Cs;let s;n.data instanceof Blob?s=await n.data.text():n.data instanceof ArrayBuffer?s=new TextDecoder().decode(n.data):s=n.data;const l=JSON.parse(s);if(t.isVertexAI()){const a=Ml(l);Object.assign(o,a)}else Object.assign(o,l);e(o)}class rd{constructor(e,n,o){this.apiClient=e,this.auth=n,this.webSocketFactory=o,this.music=new ed(this.apiClient,this.auth,this.webSocketFactory)}async connect(e){var n,o,s,l,a,u;if(e.config&&e.config.httpOptions)throw new Error("The Live module does not support httpOptions at request-level in LiveConnectConfig yet. Please use the client-level httpOptions configuration instead.");const c=this.apiClient.getWebsocketBaseUrl(),d=this.apiClient.getApiVersion();let f;const h=this.apiClient.getHeaders();e.config&&e.config.tools&&Vo(e.config.tools)&&Go(h);const p=dd(h);if(this.apiClient.isVertexAI())f=`${c}/ws/google.cloud.aiplatform.${d}.LlmBidiService/BidiGenerateContent`,await this.auth.addAuthHeaders(p,f);else{const w=this.apiClient.getApiKey();let L="BidiGenerateContent",B="key";w!=null&&w.startsWith("auth_tokens/")&&(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."),L="BidiGenerateContentConstrained",B="access_token"),f=`${c}/ws/google.ai.generativelanguage.${d}.GenerativeService.${L}?${B}=${w}`}let m=()=>{};const T=new Promise(w=>{m=w}),E=e.callbacks,v=function(){var w;(w=E==null?void 0:E.onopen)===null||w===void 0||w.call(E),m({})},S=this.apiClient,_={onopen:v,onmessage:w=>{sd(S,E.onmessage,w)},onerror:(n=E==null?void 0:E.onerror)!==null&&n!==void 0?n:function(w){},onclose:(o=E==null?void 0:E.onclose)!==null&&o!==void 0?o:function(w){}},C=this.webSocketFactory.create(f,ud(p),_);C.connect(),await T;let x=q(this.apiClient,e.model);if(this.apiClient.isVertexAI()&&x.startsWith("publishers/")){const w=this.apiClient.getProject(),L=this.apiClient.getLocation();x=`projects/${w}/locations/${L}/`+x}let R={};this.apiClient.isVertexAI()&&((s=e.config)===null||s===void 0?void 0:s.responseModalities)===void 0&&(e.config===void 0?e.config={responseModalities:[Ge.AUDIO]}:e.config.responseModalities=[Ge.AUDIO]),!((l=e.config)===null||l===void 0)&&l.generationConfig&&console.warn("Setting `LiveConnectConfig.generation_config` is deprecated, please set the fields on `LiveConnectConfig` directly. This will become an error in a future version (not before Q3 2025).");const M=(u=(a=e.config)===null||a===void 0?void 0:a.tools)!==null&&u!==void 0?u:[],k=[];for(const w of M)if(this.isCallableTool(w)){const L=w;k.push(await L.tool())}else k.push(w);k.length>0&&(e.config.tools=k);const V={model:x,config:e.config,callbacks:e.callbacks};return this.apiClient.isVertexAI()?R=Al(this.apiClient,V):R=Il(this.apiClient,V),delete R.config,C.send(JSON.stringify(R)),new ad(C,this.apiClient)}isCallableTool(e){return"callTool"in e&&typeof e.callTool=="function"}}const ld={turnComplete:!0};class ad{constructor(e,n){this.conn=e,this.apiClient=n}tLiveClientContent(e,n){if(n.turns!==null&&n.turns!==void 0){let o=[];try{o=oe(n.turns),e.isVertexAI()||(o=o.map(s=>Oe(s)))}catch{throw new Error(`Failed to parse client content "turns", type: '${typeof n.turns}'`)}return{clientContent:{turns:o,turnComplete:n.turnComplete}}}return{clientContent:{turnComplete:n.turnComplete}}}tLiveClienttToolResponse(e,n){let o=[];if(n.functionResponses==null)throw new Error("functionResponses is required.");if(Array.isArray(n.functionResponses)?o=n.functionResponses:o=[n.functionResponses],o.length===0)throw new Error("functionResponses is required.");for(const l of o){if(typeof l!="object"||l===null||!("name"in l)||!("response"in l))throw new Error(`Could not parse function response, type '${typeof l}'.`);if(!e.isVertexAI()&&!("id"in l))throw new Error(id)}return{toolResponse:{functionResponses:o}}}sendClientContent(e){e=Object.assign(Object.assign({},ld),e);const n=this.tLiveClientContent(this.apiClient,e);this.conn.send(JSON.stringify(n))}sendRealtimeInput(e){let n={};this.apiClient.isVertexAI()?n={realtimeInput:Nl(e)}:n={realtimeInput:Pl(e)},this.conn.send(JSON.stringify(n))}sendToolResponse(e){if(e.functionResponses==null)throw new Error("Tool response parameters are required.");const n=this.tLiveClienttToolResponse(this.apiClient,e);this.conn.send(JSON.stringify(n))}close(){this.conn.close()}}function ud(t){const e={};return t.forEach((n,o)=>{e[o]=n}),e}function dd(t){const e=new Headers;for(const[n,o]of Object.entries(t))e.append(n,o);return e}/**
123
- * @license
124
- * Copyright 2025 Google LLC
125
- * SPDX-License-Identifier: Apache-2.0
126
- */const Ho=10;function qo(t){var e,n,o;if(!((e=t==null?void 0:t.automaticFunctionCalling)===null||e===void 0)&&e.disable)return!0;let s=!1;for(const a of(n=t==null?void 0:t.tools)!==null&&n!==void 0?n:[])if(Ie(a)){s=!0;break}if(!s)return!0;const l=(o=t==null?void 0:t.automaticFunctionCalling)===null||o===void 0?void 0:o.maximumRemoteCalls;return l&&(l<0||!Number.isInteger(l))||l==0?(console.warn("Invalid maximumRemoteCalls value provided for automatic function calling. Disabled automatic function calling. Please provide a valid integer value greater than 0. maximumRemoteCalls provided:",l),!0):!1}function Ie(t){return"callTool"in t&&typeof t.callTool=="function"}function cd(t){var e,n,o;return(o=(n=(e=t.config)===null||e===void 0?void 0:e.tools)===null||n===void 0?void 0:n.some(s=>Ie(s)))!==null&&o!==void 0?o:!1}function Bo(t){var e;const n=[];return!((e=t==null?void 0:t.config)===null||e===void 0)&&e.tools&&t.config.tools.forEach((o,s)=>{if(Ie(o))return;const l=o;l.functionDeclarations&&l.functionDeclarations.length>0&&n.push(s)}),n}function Jo(t){var e;return!(!((e=t==null?void 0:t.automaticFunctionCalling)===null||e===void 0)&&e.ignoreCallHistory)}/**
127
- * @license
128
- * Copyright 2025 Google LLC
129
- * SPDX-License-Identifier: Apache-2.0
130
- */class fd extends de{constructor(e){super(),this.apiClient=e,this.generateContent=async n=>{var o,s,l,a,u;const c=await this.processParamsMaybeAddMcpUsage(n);if(this.maybeMoveToResponseJsonSchem(n),!cd(n)||qo(n.config))return await this.generateContentInternal(c);const d=Bo(n);if(d.length>0){const E=d.map(v=>`tools[${v}]`).join(", ");throw new Error(`Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations is not yet supported. Incompatible tools found at ${E}.`)}let f,h;const p=oe(c.contents),m=(l=(s=(o=c.config)===null||o===void 0?void 0:o.automaticFunctionCalling)===null||s===void 0?void 0:s.maximumRemoteCalls)!==null&&l!==void 0?l:Ho;let T=0;for(;T<m&&(f=await this.generateContentInternal(c),!(!f.functionCalls||f.functionCalls.length===0));){const E=f.candidates[0].content,v=[];for(const S of(u=(a=n.config)===null||a===void 0?void 0:a.tools)!==null&&u!==void 0?u:[])if(Ie(S)){const C=await S.callTool(f.functionCalls);v.push(...C)}T++,h={role:"user",parts:v},c.contents=oe(c.contents),c.contents.push(E),c.contents.push(h),Jo(c.config)&&(p.push(E),p.push(h))}return Jo(c.config)&&(f.automaticFunctionCallingHistory=p),f},this.generateContentStream=async n=>{var o,s,l,a,u;if(this.maybeMoveToResponseJsonSchem(n),qo(n.config)){const h=await this.processParamsMaybeAddMcpUsage(n);return await this.generateContentStreamInternal(h)}const c=Bo(n);if(c.length>0){const h=c.map(p=>`tools[${p}]`).join(", ");throw new Error(`Incompatible tools found at ${h}. Automatic function calling with CallableTools (or MCP objects) and basic FunctionDeclarations" is not yet supported.`)}const d=(l=(s=(o=n==null?void 0:n.config)===null||o===void 0?void 0:o.toolConfig)===null||s===void 0?void 0:s.functionCallingConfig)===null||l===void 0?void 0:l.streamFunctionCallArguments,f=(u=(a=n==null?void 0:n.config)===null||a===void 0?void 0:a.automaticFunctionCalling)===null||u===void 0?void 0:u.disable;if(d&&!f)throw new Error("Running in streaming mode with 'streamFunctionCallArguments' enabled, this feature is not compatible with automatic function calling (AFC). Please set 'config.automaticFunctionCalling.disable' to true to disable AFC or leave 'config.toolConfig.functionCallingConfig.streamFunctionCallArguments' to be undefined or set to false to disable streaming function call arguments feature.");return await this.processAfcStream(n)},this.generateImages=async n=>await this.generateImagesInternal(n).then(o=>{var s;let l;const a=[];if(o!=null&&o.generatedImages)for(const c of o.generatedImages)c&&(c!=null&&c.safetyAttributes)&&((s=c==null?void 0:c.safetyAttributes)===null||s===void 0?void 0:s.contentType)==="Positive Prompt"?l=c==null?void 0:c.safetyAttributes:a.push(c);let u;return l?u={generatedImages:a,positivePromptSafetyAttributes:l,sdkHttpResponse:o.sdkHttpResponse}:u={generatedImages:a,sdkHttpResponse:o.sdkHttpResponse},u}),this.list=async n=>{var o;const a={config:Object.assign(Object.assign({},{queryBase:!0}),n==null?void 0:n.config)};if(this.apiClient.isVertexAI()&&!a.config.queryBase){if(!((o=a.config)===null||o===void 0)&&o.filter)throw new Error("Filtering tuned models list for Vertex AI is not currently supported");a.config.filter="labels.tune-type:*"}return new ye(fe.PAGED_ITEM_MODELS,u=>this.listInternal(u),await this.listInternal(a),a)},this.editImage=async n=>{const o={model:n.model,prompt:n.prompt,referenceImages:[],config:n.config};return n.referenceImages&&n.referenceImages&&(o.referenceImages=n.referenceImages.map(s=>s.toReferenceImageAPI())),await this.editImageInternal(o)},this.upscaleImage=async n=>{let o={numberOfImages:1,mode:"upscale"};n.config&&(o=Object.assign(Object.assign({},o),n.config));const s={model:n.model,image:n.image,upscaleFactor:n.upscaleFactor,config:o};return await this.upscaleImageInternal(s)},this.generateVideos=async n=>{var o,s,l,a,u,c;if((n.prompt||n.image||n.video)&&n.source)throw new Error("Source and prompt/image/video are mutually exclusive. Please only use source.");return this.apiClient.isVertexAI()||(!((o=n.video)===null||o===void 0)&&o.uri&&(!((s=n.video)===null||s===void 0)&&s.videoBytes)?n.video={uri:n.video.uri,mimeType:n.video.mimeType}:!((a=(l=n.source)===null||l===void 0?void 0:l.video)===null||a===void 0)&&a.uri&&(!((c=(u=n.source)===null||u===void 0?void 0:u.video)===null||c===void 0)&&c.videoBytes)&&(n.source.video={uri:n.source.video.uri,mimeType:n.source.video.mimeType})),await this.generateVideosInternal(n)}}maybeMoveToResponseJsonSchem(e){e.config&&e.config.responseSchema&&(e.config.responseJsonSchema||Object.keys(e.config.responseSchema).includes("$schema")&&(e.config.responseJsonSchema=e.config.responseSchema,delete e.config.responseSchema))}async processParamsMaybeAddMcpUsage(e){var n,o,s;const l=(n=e.config)===null||n===void 0?void 0:n.tools;if(!l)return e;const a=await Promise.all(l.map(async c=>Ie(c)?await c.tool():c)),u={model:e.model,contents:e.contents,config:Object.assign(Object.assign({},e.config),{tools:a})};if(u.config.tools=a,e.config&&e.config.tools&&Vo(e.config.tools)){const c=(s=(o=e.config.httpOptions)===null||o===void 0?void 0:o.headers)!==null&&s!==void 0?s:{};let d=Object.assign({},c);Object.keys(d).length===0&&(d=this.apiClient.getDefaultHeaders()),Go(d),u.config.httpOptions=Object.assign(Object.assign({},e.config.httpOptions),{headers:d})}return u}async initAfcToolsMap(e){var n,o,s;const l=new Map;for(const a of(o=(n=e.config)===null||n===void 0?void 0:n.tools)!==null&&o!==void 0?o:[])if(Ie(a)){const u=a,c=await u.tool();for(const d of(s=c.functionDeclarations)!==null&&s!==void 0?s:[]){if(!d.name)throw new Error("Function declaration name is required.");if(l.has(d.name))throw new Error(`Duplicate tool declaration name: ${d.name}`);l.set(d.name,u)}}return l}async processAfcStream(e){var n,o,s;const l=(s=(o=(n=e.config)===null||n===void 0?void 0:n.automaticFunctionCalling)===null||o===void 0?void 0:o.maximumRemoteCalls)!==null&&s!==void 0?s:Ho;let a=!1,u=0;const c=await this.initAfcToolsMap(e);return function(d,f,h){return le(this,arguments,function*(){for(var p,m,T,E,v,S;u<l;){a&&(u++,a=!1);const R=yield U(d.processParamsMaybeAddMcpUsage(h)),M=yield U(d.generateContentStreamInternal(R)),k=[],V=[];try{for(var _=!0,C=(m=void 0,ae(M)),x;x=yield U(C.next()),p=x.done,!p;_=!0){E=x.value,_=!1;const w=E;if(yield yield U(w),w.candidates&&(!((v=w.candidates[0])===null||v===void 0)&&v.content)){V.push(w.candidates[0].content);for(const L of(S=w.candidates[0].content.parts)!==null&&S!==void 0?S:[])if(u<l&&L.functionCall){if(!L.functionCall.name)throw new Error("Function call name was not returned by the model.");if(f.has(L.functionCall.name)){const B=yield U(f.get(L.functionCall.name).callTool([L.functionCall]));k.push(...B)}else throw new Error(`Automatic function calling was requested, but not all the tools the model used implement the CallableTool interface. Available tools: ${f.keys()}, mising tool: ${L.functionCall.name}`)}}}}catch(w){m={error:w}}finally{try{!_&&!p&&(T=C.return)&&(yield U(T.call(C)))}finally{if(m)throw m.error}}if(k.length>0){a=!0;const w=new De;w.candidates=[{content:{role:"user",parts:k}}],yield yield U(w);const L=[];L.push(...V),L.push({role:"user",parts:k});const B=oe(h.contents).concat(L);h.contents=B}else break}})}(this,c,e)}async generateContentInternal(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Ro(this.apiClient,e);return u=A("{model}:generateContent",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Po(f),p=new De;return Object.assign(p,h),p})}else{const d=Ao(this.apiClient,e);return u=A("{model}:generateContent",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=wo(f),p=new De;return Object.assign(p,h),p})}}async generateContentStreamInternal(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Ro(this.apiClient,e);return u=A("{model}:streamGenerateContent?alt=sse",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.requestStream({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}),a.then(function(h){return le(this,arguments,function*(){var p,m,T,E;try{for(var v=!0,S=ae(h),_;_=yield U(S.next()),p=_.done,!p;v=!0){E=_.value,v=!1;const C=E,x=Po(yield U(C.json()));x.sdkHttpResponse={headers:C.headers};const R=new De;Object.assign(R,x),yield yield U(R)}}catch(C){m={error:C}}finally{try{!v&&!p&&(T=S.return)&&(yield U(T.call(S)))}finally{if(m)throw m.error}}})})}else{const d=Ao(this.apiClient,e);return u=A("{model}:streamGenerateContent?alt=sse",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.requestStream({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}),a.then(function(h){return le(this,arguments,function*(){var p,m,T,E;try{for(var v=!0,S=ae(h),_;_=yield U(S.next()),p=_.done,!p;v=!0){E=_.value,v=!1;const C=E,x=wo(yield U(C.json()));x.sdkHttpResponse={headers:C.headers};const R=new De;Object.assign(R,x),yield yield U(R)}}catch(C){m={error:C}}finally{try{!v&&!p&&(T=S.return)&&(yield U(T.call(S)))}finally{if(m)throw m.error}}})})}}async embedContent(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=la(this.apiClient,e);return u=A("{model}:predict",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=ua(f),p=new Kn;return Object.assign(p,h),p})}else{const d=ra(this.apiClient,e);return u=A("{model}:batchEmbedContents",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=aa(f),p=new Kn;return Object.assign(p,h),p})}}async generateImagesInternal(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=_a(this.apiClient,e);return u=A("{model}:predict",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Ca(f),p=new zn;return Object.assign(p,h),p})}else{const d=va(this.apiClient,e);return u=A("{model}:predict",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Ea(f),p=new zn;return Object.assign(p,h),p})}}async editImageInternal(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI()){const u=na(this.apiClient,e);return l=A("{model}:predict",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json().then(d=>{const f=d;return f.sdkHttpResponse={headers:c.headers},f})),s.then(c=>{const d=oa(c),f=new cs;return Object.assign(f,d),f})}else throw new Error("This method is only supported by the Vertex AI.")}async upscaleImageInternal(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI()){const u=_u(this.apiClient,e);return l=A("{model}:predict",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json().then(d=>{const f=d;return f.sdkHttpResponse={headers:c.headers},f})),s.then(c=>{const d=Eu(c),f=new fs;return Object.assign(f,d),f})}else throw new Error("This method is only supported by the Vertex AI.")}async recontextImage(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI()){const u=tu(this.apiClient,e);return l=A("{model}:predict",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>{const d=nu(c),f=new ps;return Object.assign(f,d),f})}else throw new Error("This method is only supported by the Vertex AI.")}async segmentImage(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI()){const u=au(this.apiClient,e);return l=A("{model}:predict",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>{const d=uu(c),f=new hs;return Object.assign(f,d),f})}else throw new Error("This method is only supported by the Vertex AI.")}async get(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Ga(this.apiClient,e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>xt(f))}else{const d=Va(this.apiClient,e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>Ct(f))}}async listInternal(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Ka(this.apiClient,e);return u=A("{models_url}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Xa(f),p=new Xn;return Object.assign(p,h),p})}else{const d=$a(this.apiClient,e);return u=A("{models_url}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=za(f),p=new Xn;return Object.assign(p,h),p})}}async update(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Tu(this.apiClient,e);return u=A("{model}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"PATCH",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>xt(f))}else{const d=yu(this.apiClient,e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"PATCH",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>Ct(f))}}async delete(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Zl(this.apiClient,e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=ea(f),p=new Qn;return Object.assign(p,h),p})}else{const d=Ql(this.apiClient,e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"DELETE",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=jl(f),p=new Qn;return Object.assign(p,h),p})}}async countTokens(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Kl(this.apiClient,e);return u=A("{model}:countTokens",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Xl(f),p=new Zn;return Object.assign(p,h),p})}else{const d=$l(this.apiClient,e);return u=A("{model}:countTokens",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=zl(f),p=new Zn;return Object.assign(p,h),p})}}async computeTokens(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI()){const u=Hl(this.apiClient,e);return l=A("{model}:computeTokens",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json().then(d=>{const f=d;return f.sdkHttpResponse={headers:c.headers},f})),s.then(c=>{const d=ql(c),f=new ms;return Object.assign(f,d),f})}else throw new Error("This method is only supported by the Vertex AI.")}async generateVideosInternal(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=wa(this.apiClient,e);return u=A("{model}:predictLongRunning",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a.then(f=>{const h=Aa(f),p=new He;return Object.assign(p,h),p})}else{const d=Ra(this.apiClient,e);return u=A("{model}:predictLongRunning",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a.then(f=>{const h=Ia(f),p=new He;return Object.assign(p,h),p})}}}/**
131
- * @license
132
- * Copyright 2025 Google LLC
133
- * SPDX-License-Identifier: Apache-2.0
134
- */class pd extends de{constructor(e){super(),this.apiClient=e}async getVideosOperation(e){const n=e.operation,o=e.config;if(n.name===void 0||n.name==="")throw new Error("Operation name is required.");if(this.apiClient.isVertexAI()){const s=n.name.split("/operations/")[0];let l;o&&"httpOptions"in o&&(l=o.httpOptions);const a=await this.fetchPredictVideosOperationInternal({operationName:n.name,resourceName:s,config:{httpOptions:l}});return n._fromAPIResponse({apiResponse:a,_isVertexAI:!0})}else{const s=await this.getVideosOperationInternal({operationName:n.name,config:o});return n._fromAPIResponse({apiResponse:s,_isVertexAI:!1})}}async get(e){const n=e.operation,o=e.config;if(n.name===void 0||n.name==="")throw new Error("Operation name is required.");if(this.apiClient.isVertexAI()){const s=n.name.split("/operations/")[0];let l;o&&"httpOptions"in o&&(l=o.httpOptions);const a=await this.fetchPredictVideosOperationInternal({operationName:n.name,resourceName:s,config:{httpOptions:l}});return n._fromAPIResponse({apiResponse:a,_isVertexAI:!0})}else{const s=await this.getVideosOperationInternal({operationName:n.name,config:o});return n._fromAPIResponse({apiResponse:s,_isVertexAI:!1})}}async getVideosOperationInternal(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=ss(e);return u=A("{operationName}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json()),a}else{const d=is(e);return u=A("{operationName}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json()),a}}async fetchPredictVideosOperationInternal(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI()){const u=Qi(e);return l=A("{resourceName}:fetchPredictOperation",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s}else throw new Error("This method is only supported by the Vertex AI.")}}/**
135
- * @license
136
- * Copyright 2025 Google LLC
137
- * SPDX-License-Identifier: Apache-2.0
138
- */function hd(t){const e={},n=i(t,["data"]);if(n!=null&&r(e,["data"],n),i(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function md(t){const e={},n=i(t,["parts"]);if(n!=null){let s=n;Array.isArray(s)&&(s=s.map(l=>Sd(l))),r(e,["parts"],s)}const o=i(t,["role"]);return o!=null&&r(e,["role"],o),e}function gd(t,e,n){const o={},s=i(e,["expireTime"]);n!==void 0&&s!=null&&r(n,["expireTime"],s);const l=i(e,["newSessionExpireTime"]);n!==void 0&&l!=null&&r(n,["newSessionExpireTime"],l);const a=i(e,["uses"]);n!==void 0&&a!=null&&r(n,["uses"],a);const u=i(e,["liveConnectConstraints"]);n!==void 0&&u!=null&&r(n,["bidiGenerateContentSetup"],xd(t,u));const c=i(e,["lockAdditionalFields"]);return n!==void 0&&c!=null&&r(n,["fieldMask"],c),o}function yd(t,e){const n={},o=i(e,["config"]);return o!=null&&r(n,["config"],gd(t,o,n)),n}function Td(t){const e={};if(i(t,["displayName"])!==void 0)throw new Error("displayName parameter is not supported in Gemini API.");const n=i(t,["fileUri"]);n!=null&&r(e,["fileUri"],n);const o=i(t,["mimeType"]);return o!=null&&r(e,["mimeType"],o),e}function vd(t){const e={},n=i(t,["id"]);n!=null&&r(e,["id"],n);const o=i(t,["args"]);o!=null&&r(e,["args"],o);const s=i(t,["name"]);if(s!=null&&r(e,["name"],s),i(t,["partialArgs"])!==void 0)throw new Error("partialArgs parameter is not supported in Gemini API.");if(i(t,["willContinue"])!==void 0)throw new Error("willContinue parameter is not supported in Gemini API.");return e}function _d(t){const e={};if(i(t,["authConfig"])!==void 0)throw new Error("authConfig parameter is not supported in Gemini API.");const n=i(t,["enableWidget"]);return n!=null&&r(e,["enableWidget"],n),e}function Ed(t){const e={};if(i(t,["excludeDomains"])!==void 0)throw new Error("excludeDomains parameter is not supported in Gemini API.");if(i(t,["blockingConfidence"])!==void 0)throw new Error("blockingConfidence parameter is not supported in Gemini API.");const n=i(t,["timeRangeFilter"]);return n!=null&&r(e,["timeRangeFilter"],n),e}function Cd(t,e){const n={},o=i(t,["generationConfig"]);e!==void 0&&o!=null&&r(e,["setup","generationConfig"],o);const s=i(t,["responseModalities"]);e!==void 0&&s!=null&&r(e,["setup","generationConfig","responseModalities"],s);const l=i(t,["temperature"]);e!==void 0&&l!=null&&r(e,["setup","generationConfig","temperature"],l);const a=i(t,["topP"]);e!==void 0&&a!=null&&r(e,["setup","generationConfig","topP"],a);const u=i(t,["topK"]);e!==void 0&&u!=null&&r(e,["setup","generationConfig","topK"],u);const c=i(t,["maxOutputTokens"]);e!==void 0&&c!=null&&r(e,["setup","generationConfig","maxOutputTokens"],c);const d=i(t,["mediaResolution"]);e!==void 0&&d!=null&&r(e,["setup","generationConfig","mediaResolution"],d);const f=i(t,["seed"]);e!==void 0&&f!=null&&r(e,["setup","generationConfig","seed"],f);const h=i(t,["speechConfig"]);e!==void 0&&h!=null&&r(e,["setup","generationConfig","speechConfig"],_t(h));const p=i(t,["thinkingConfig"]);e!==void 0&&p!=null&&r(e,["setup","generationConfig","thinkingConfig"],p);const m=i(t,["enableAffectiveDialog"]);e!==void 0&&m!=null&&r(e,["setup","generationConfig","enableAffectiveDialog"],m);const T=i(t,["systemInstruction"]);e!==void 0&&T!=null&&r(e,["setup","systemInstruction"],md(Z(T)));const E=i(t,["tools"]);if(e!==void 0&&E!=null){let M=xe(E);Array.isArray(M)&&(M=M.map(k=>Ad(Ce(k)))),r(e,["setup","tools"],M)}const v=i(t,["sessionResumption"]);e!==void 0&&v!=null&&r(e,["setup","sessionResumption"],Id(v));const S=i(t,["inputAudioTranscription"]);e!==void 0&&S!=null&&r(e,["setup","inputAudioTranscription"],S);const _=i(t,["outputAudioTranscription"]);e!==void 0&&_!=null&&r(e,["setup","outputAudioTranscription"],_);const C=i(t,["realtimeInputConfig"]);e!==void 0&&C!=null&&r(e,["setup","realtimeInputConfig"],C);const x=i(t,["contextWindowCompression"]);e!==void 0&&x!=null&&r(e,["setup","contextWindowCompression"],x);const R=i(t,["proactivity"]);if(e!==void 0&&R!=null&&r(e,["setup","proactivity"],R),i(t,["explicitVadSignal"])!==void 0)throw new Error("explicitVadSignal parameter is not supported in Gemini API.");return n}function xd(t,e){const n={},o=i(e,["model"]);o!=null&&r(n,["setup","model"],q(t,o));const s=i(e,["config"]);return s!=null&&r(n,["config"],Cd(s,n)),n}function Sd(t){const e={},n=i(t,["mediaResolution"]);n!=null&&r(e,["mediaResolution"],n);const o=i(t,["codeExecutionResult"]);o!=null&&r(e,["codeExecutionResult"],o);const s=i(t,["executableCode"]);s!=null&&r(e,["executableCode"],s);const l=i(t,["fileData"]);l!=null&&r(e,["fileData"],Td(l));const a=i(t,["functionCall"]);a!=null&&r(e,["functionCall"],vd(a));const u=i(t,["functionResponse"]);u!=null&&r(e,["functionResponse"],u);const c=i(t,["inlineData"]);c!=null&&r(e,["inlineData"],hd(c));const d=i(t,["text"]);d!=null&&r(e,["text"],d);const f=i(t,["thought"]);f!=null&&r(e,["thought"],f);const h=i(t,["thoughtSignature"]);h!=null&&r(e,["thoughtSignature"],h);const p=i(t,["videoMetadata"]);return p!=null&&r(e,["videoMetadata"],p),e}function Id(t){const e={},n=i(t,["handle"]);if(n!=null&&r(e,["handle"],n),i(t,["transparent"])!==void 0)throw new Error("transparent parameter is not supported in Gemini API.");return e}function Ad(t){const e={},n=i(t,["functionDeclarations"]);if(n!=null){let f=n;Array.isArray(f)&&(f=f.map(h=>h)),r(e,["functionDeclarations"],f)}if(i(t,["retrieval"])!==void 0)throw new Error("retrieval parameter is not supported in Gemini API.");const o=i(t,["googleSearchRetrieval"]);o!=null&&r(e,["googleSearchRetrieval"],o);const s=i(t,["computerUse"]);s!=null&&r(e,["computerUse"],s);const l=i(t,["fileSearch"]);l!=null&&r(e,["fileSearch"],l);const a=i(t,["codeExecution"]);if(a!=null&&r(e,["codeExecution"],a),i(t,["enterpriseWebSearch"])!==void 0)throw new Error("enterpriseWebSearch parameter is not supported in Gemini API.");const u=i(t,["googleMaps"]);u!=null&&r(e,["googleMaps"],_d(u));const c=i(t,["googleSearch"]);c!=null&&r(e,["googleSearch"],Ed(c));const d=i(t,["urlContext"]);return d!=null&&r(e,["urlContext"],d),e}/**
139
- * @license
140
- * Copyright 2025 Google LLC
141
- * SPDX-License-Identifier: Apache-2.0
142
- */function Rd(t){const e=[];for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)){const o=t[n];if(typeof o=="object"&&o!=null&&Object.keys(o).length>0){const s=Object.keys(o).map(l=>`${n}.${l}`);e.push(...s)}else e.push(n)}return e.join(",")}function wd(t,e){let n=null;const o=t.bidiGenerateContentSetup;if(typeof o=="object"&&o!==null&&"setup"in o){const l=o.setup;typeof l=="object"&&l!==null?(t.bidiGenerateContentSetup=l,n=l):delete t.bidiGenerateContentSetup}else o!==void 0&&delete t.bidiGenerateContentSetup;const s=t.fieldMask;if(n){const l=Rd(n);if(Array.isArray(e==null?void 0:e.lockAdditionalFields)&&(e==null?void 0:e.lockAdditionalFields.length)===0)l?t.fieldMask=l:delete t.fieldMask;else if(e!=null&&e.lockAdditionalFields&&e.lockAdditionalFields.length>0&&s!==null&&Array.isArray(s)&&s.length>0){const a=["temperature","topK","topP","maxOutputTokens","responseModalities","seed","speechConfig"];let u=[];s.length>0&&(u=s.map(d=>a.includes(d)?`generationConfig.${d}`:d));const c=[];l&&c.push(l),u.length>0&&c.push(...u),c.length>0?t.fieldMask=c.join(","):delete t.fieldMask}else delete t.fieldMask}else s!==null&&Array.isArray(s)&&s.length>0?t.fieldMask=s.join(","):delete t.fieldMask;return t}class Pd extends de{constructor(e){super(),this.apiClient=e}async create(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("The client.tokens.create method is only supported by the Gemini Developer API.");{const u=yd(this.apiClient,e);l=A("auth_tokens",u._url),a=u._query,delete u.config,delete u._url,delete u._query;const c=wd(u,e.config);return s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(c),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(d=>d.json()),s.then(d=>d)}}}/**
143
- * @license
144
- * Copyright 2025 Google LLC
145
- * SPDX-License-Identifier: Apache-2.0
146
- */function Nd(t,e){const n={},o=i(t,["force"]);return e!==void 0&&o!=null&&r(e,["_query","force"],o),n}function Md(t){const e={},n=i(t,["name"]);n!=null&&r(e,["_url","name"],n);const o=i(t,["config"]);return o!=null&&Nd(o,e),e}function kd(t){const e={},n=i(t,["name"]);return n!=null&&r(e,["_url","name"],n),e}function Dd(t,e){const n={},o=i(t,["pageSize"]);e!==void 0&&o!=null&&r(e,["_query","pageSize"],o);const s=i(t,["pageToken"]);return e!==void 0&&s!=null&&r(e,["_query","pageToken"],s),n}function bd(t){const e={},n=i(t,["parent"]);n!=null&&r(e,["_url","parent"],n);const o=i(t,["config"]);return o!=null&&Dd(o,e),e}function Ud(t){const e={},n=i(t,["sdkHttpResponse"]);n!=null&&r(e,["sdkHttpResponse"],n);const o=i(t,["nextPageToken"]);o!=null&&r(e,["nextPageToken"],o);const s=i(t,["documents"]);if(s!=null){let l=s;Array.isArray(l)&&(l=l.map(a=>a)),r(e,["documents"],l)}return e}/**
147
- * @license
148
- * Copyright 2025 Google LLC
149
- * SPDX-License-Identifier: Apache-2.0
150
- */class Ld extends de{constructor(e){super(),this.apiClient=e,this.list=async n=>new ye(fe.PAGED_ITEM_DOCUMENTS,o=>this.listInternal({parent:n.parent,config:o.config}),await this.listInternal(n),n)}async get(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=kd(e);return l=A("{name}",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>c)}}async delete(e){var n,o;let s="",l={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const a=Md(e);s=A("{name}",a._url),l=a._query,delete a._url,delete a._query,await this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(a),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal})}}async listInternal(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=bd(e);return l=A("{parent}/documents",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>{const d=Ud(c),f=new gs;return Object.assign(f,d),f})}}}/**
151
- * @license
152
- * Copyright 2025 Google LLC
153
- * SPDX-License-Identifier: Apache-2.0
154
- */class Fd extends de{constructor(e,n=new Ld(e)){super(),this.apiClient=e,this.documents=n,this.list=async(o={})=>new ye(fe.PAGED_ITEM_FILE_SEARCH_STORES,s=>this.listInternal(s),await this.listInternal(o),o)}async uploadToFileSearchStore(e){if(this.apiClient.isVertexAI())throw new Error("Vertex AI does not support uploading files to a file search store.");return this.apiClient.uploadFileToFileSearchStore(e.fileSearchStoreName,e.file,e.config)}async create(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=wu(e);return l=A("fileSearchStores",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>c)}}async get(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Mu(e);return l=A("{name}",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>c)}}async delete(e){var n,o;let s="",l={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const a=Nu(e);s=A("{name}",a._url),l=a._query,delete a._url,delete a._query,await this.apiClient.request({path:s,queryParams:l,body:JSON.stringify(a),httpMethod:"DELETE",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal})}}async listInternal(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Fu(e);return l=A("fileSearchStores",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>{const d=Vu(c),f=new ys;return Object.assign(f,d),f})}}async uploadToFileSearchStoreInternal(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Gu(e);return l=A("upload/v1beta/{file_search_store_name}:uploadToFileSearchStore",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>{const d=Hu(c),f=new Ts;return Object.assign(f,d),f})}}async importFile(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=bu(e);return l=A("{file_search_store_name}:importFile",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json()),s.then(c=>{const d=Du(c),f=new ht;return Object.assign(f,d),f})}}}/**
155
- * @license
156
- * Copyright 2025 Google LLC
157
- * SPDX-License-Identifier: Apache-2.0
158
- */let Wo=function(){const{crypto:t}=globalThis;if(t!=null&&t.randomUUID)return Wo=t.randomUUID.bind(t),t.randomUUID();const e=new Uint8Array(1),n=t?()=>t.getRandomValues(e)[0]:()=>Math.random()*255&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,o=>(+o^n()&15>>+o/4).toString(16))};const Vd=()=>Wo();/**
159
- * @license
160
- * Copyright 2025 Google LLC
161
- * SPDX-License-Identifier: Apache-2.0
162
- */function At(t){return typeof t=="object"&&t!==null&&("name"in t&&t.name==="AbortError"||"message"in t&&String(t.message).includes("FetchRequestCanceledException"))}const Rt=t=>{if(t instanceof Error)return t;if(typeof t=="object"&&t!==null){try{if(Object.prototype.toString.call(t)==="[object Error]"){const e=new Error(t.message,t.cause?{cause:t.cause}:{});return t.stack&&(e.stack=t.stack),t.cause&&!e.cause&&(e.cause=t.cause),t.name&&(e.name=t.name),e}}catch{}try{return new Error(JSON.stringify(t))}catch{}}return new Error(t)};/**
163
- * @license
164
- * Copyright 2025 Google LLC
165
- * SPDX-License-Identifier: Apache-2.0
166
- */class ie extends Error{}class j extends ie{constructor(e,n,o,s){super(`${j.makeMessage(e,n,o)}`),this.status=e,this.headers=s,this.error=n}static makeMessage(e,n,o){const s=n!=null&&n.message?typeof n.message=="string"?n.message:JSON.stringify(n.message):n?JSON.stringify(n):o;return e&&s?`${e} ${s}`:e?`${e} status code (no body)`:s||"(no status code or body)"}static generate(e,n,o,s){if(!e||!s)return new ze({message:o,cause:Rt(n)});const l=n;return e===400?new Oo(e,l,o,s):e===401?new $o(e,l,o,s):e===403?new Ko(e,l,o,s):e===404?new zo(e,l,o,s):e===409?new Xo(e,l,o,s):e===422?new Qo(e,l,o,s):e===429?new Zo(e,l,o,s):e>=500?new jo(e,l,o,s):new j(e,l,o,s)}}class wt extends j{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}}class ze extends j{constructor({message:e,cause:n}){super(void 0,void 0,e||"Connection error.",void 0),n&&(this.cause=n)}}class Yo extends ze{constructor({message:e}={}){super({message:e??"Request timed out."})}}class Oo extends j{}class $o extends j{}class Ko extends j{}class zo extends j{}class Xo extends j{}class Qo extends j{}class Zo extends j{}class jo extends j{}/**
167
- * @license
168
- * Copyright 2025 Google LLC
169
- * SPDX-License-Identifier: Apache-2.0
170
- */const Gd=/^[a-z][a-z0-9+.-]*:/i,Hd=t=>Gd.test(t);let Pt=t=>(Pt=Array.isArray,Pt(t));const ei=Pt;function qd(t){if(!t)return!0;for(const e in t)return!1;return!0}function Bd(t,e){return Object.prototype.hasOwnProperty.call(t,e)}const Jd=(t,e)=>{if(typeof e!="number"||!Number.isInteger(e))throw new ie(`${t} must be an integer`);if(e<0)throw new ie(`${t} must be a positive integer`);return e},Wd=t=>{try{return JSON.parse(t)}catch{return}};/**
171
- * @license
172
- * Copyright 2025 Google LLC
173
- * SPDX-License-Identifier: Apache-2.0
174
- */const Yd=t=>new Promise(e=>setTimeout(e,t));/**
175
- * @license
176
- * Copyright 2025 Google LLC
177
- * SPDX-License-Identifier: Apache-2.0
178
- */const Ae="0.0.1";/**
179
- * @license
180
- * Copyright 2025 Google LLC
181
- * SPDX-License-Identifier: Apache-2.0
182
- */function Od(){return typeof Deno<"u"&&Deno.build!=null?"deno":typeof EdgeRuntime<"u"?"edge":Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]"?"node":"unknown"}const $d=()=>{var t,e,n,o,s;const l=Od();if(l==="deno")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Ae,"X-Stainless-OS":ni(Deno.build.os),"X-Stainless-Arch":ti(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":typeof Deno.version=="string"?Deno.version:(e=(t=Deno.version)===null||t===void 0?void 0:t.deno)!==null&&e!==void 0?e:"unknown"};if(typeof EdgeRuntime<"u")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Ae,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process.version};if(l==="node")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Ae,"X-Stainless-OS":ni((n=globalThis.process.platform)!==null&&n!==void 0?n:"unknown"),"X-Stainless-Arch":ti((o=globalThis.process.arch)!==null&&o!==void 0?o:"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":(s=globalThis.process.version)!==null&&s!==void 0?s:"unknown"};const a=Kd();return a?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Ae,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${a.browser}`,"X-Stainless-Runtime-Version":a.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":Ae,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};function Kd(){if(typeof navigator>"u"||!navigator)return null;const t=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(const{key:e,pattern:n}of t){const o=n.exec(navigator.userAgent);if(o){const s=o[1]||0,l=o[2]||0,a=o[3]||0;return{browser:e,version:`${s}.${l}.${a}`}}}return null}const ti=t=>t==="x32"?"x32":t==="x86_64"||t==="x64"?"x64":t==="arm"?"arm":t==="aarch64"||t==="arm64"?"arm64":t?`other:${t}`:"unknown",ni=t=>(t=t.toLowerCase(),t.includes("ios")?"iOS":t==="android"?"Android":t==="darwin"?"MacOS":t==="win32"?"Windows":t==="freebsd"?"FreeBSD":t==="openbsd"?"OpenBSD":t==="linux"?"Linux":t?`Other:${t}`:"Unknown");let Xe;const zd=()=>Xe??(Xe=$d());/**
183
- * @license
184
- * Copyright 2025 Google LLC
185
- * SPDX-License-Identifier: Apache-2.0
186
- */function Xd(){if(typeof fetch<"u")return fetch;throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new GeminiNextGenAPIClient({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function oi(...t){const e=globalThis.ReadableStream;if(typeof e>"u")throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new e(...t)}function Qd(t){let e=Symbol.asyncIterator in t?t[Symbol.asyncIterator]():t[Symbol.iterator]();return oi({start(){},async pull(n){const{done:o,value:s}=await e.next();o?n.close():n.enqueue(s)},async cancel(){var n;await((n=e.return)===null||n===void 0?void 0:n.call(e))}})}function ii(t){if(t[Symbol.asyncIterator])return t;const e=t.getReader();return{async next(){try{const n=await e.read();return n!=null&&n.done&&e.releaseLock(),n}catch(n){throw e.releaseLock(),n}},async return(){const n=e.cancel();return e.releaseLock(),await n,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function Zd(t){var e,n;if(t===null||typeof t!="object")return;if(t[Symbol.asyncIterator]){await((n=(e=t[Symbol.asyncIterator]()).return)===null||n===void 0?void 0:n.call(e));return}const o=t.getReader(),s=o.cancel();o.releaseLock(),await s}/**
187
- * @license
188
- * Copyright 2025 Google LLC
189
- * SPDX-License-Identifier: Apache-2.0
190
- */const jd=({headers:t,body:e})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(e)});/**
191
- * @license
192
- * Copyright 2025 Google LLC
193
- * SPDX-License-Identifier: Apache-2.0
194
- */const si=()=>{var t;if(typeof File>"u"){const{process:e}=globalThis,n=typeof((t=e==null?void 0:e.versions)===null||t===void 0?void 0:t.node)=="string"&&parseInt(e.versions.node.split("."))<20;throw new Error("`File` is not defined as a global, which is required for file uploads."+(n?" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`.":""))}};function Nt(t,e,n){return si(),new File(t,e??"unknown_file",n)}function ec(t){return(typeof t=="object"&&t!==null&&("name"in t&&t.name&&String(t.name)||"url"in t&&t.url&&String(t.url)||"filename"in t&&t.filename&&String(t.filename)||"path"in t&&t.path&&String(t.path))||"").split(/[\\/]/).pop()||void 0}const tc=t=>t!=null&&typeof t=="object"&&typeof t[Symbol.asyncIterator]=="function";/**
195
- * @license
196
- * Copyright 2025 Google LLC
197
- * SPDX-License-Identifier: Apache-2.0
198
- */const ri=t=>t!=null&&typeof t=="object"&&typeof t.size=="number"&&typeof t.type=="string"&&typeof t.text=="function"&&typeof t.slice=="function"&&typeof t.arrayBuffer=="function",nc=t=>t!=null&&typeof t=="object"&&typeof t.name=="string"&&typeof t.lastModified=="number"&&ri(t),oc=t=>t!=null&&typeof t=="object"&&typeof t.url=="string"&&typeof t.blob=="function";async function ic(t,e,n){if(si(),t=await t,nc(t))return t instanceof File?t:Nt([await t.arrayBuffer()],t.name);if(oc(t)){const s=await t.blob();return e||(e=new URL(t.url).pathname.split(/[\\/]/).pop()),Nt(await Mt(s),e,n)}const o=await Mt(t);if(e||(e=ec(t)),!(n!=null&&n.type)){const s=o.find(l=>typeof l=="object"&&"type"in l&&l.type);typeof s=="string"&&(n=Object.assign(Object.assign({},n),{type:s}))}return Nt(o,e,n)}async function Mt(t){var e,n,o,s,l;let a=[];if(typeof t=="string"||ArrayBuffer.isView(t)||t instanceof ArrayBuffer)a.push(t);else if(ri(t))a.push(t instanceof Blob?t:await t.arrayBuffer());else if(tc(t))try{for(var u=!0,c=ae(t),d;d=await c.next(),e=d.done,!e;u=!0){s=d.value,u=!1;const f=s;a.push(...await Mt(f))}}catch(f){n={error:f}}finally{try{!u&&!e&&(o=c.return)&&await o.call(c)}finally{if(n)throw n.error}}else{const f=(l=t==null?void 0:t.constructor)===null||l===void 0?void 0:l.name;throw new Error(`Unexpected data type: ${typeof t}${f?`; constructor: ${f}`:""}${sc(t)}`)}return a}function sc(t){return typeof t!="object"||t===null?"":`; props: [${Object.getOwnPropertyNames(t).map(n=>`"${n}"`).join(", ")}]`}/**
199
- * @license
200
- * Copyright 2025 Google LLC
201
- * SPDX-License-Identifier: Apache-2.0
202
- */class li{constructor(e){this._client=e}}li._key=[];/**
203
- * @license
204
- * Copyright 2025 Google LLC
205
- * SPDX-License-Identifier: Apache-2.0
206
- */function ai(t){return t.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g,encodeURIComponent)}const ui=Object.freeze(Object.create(null)),Qe=((t=ai)=>function(n,...o){if(n.length===1)return n[0];let s=!1;const l=[],a=n.reduce((f,h,p)=>{var m,T,E;/[?#]/.test(h)&&(s=!0);const v=o[p];let S=(s?encodeURIComponent:t)(""+v);return p!==o.length&&(v==null||typeof v=="object"&&v.toString===((E=Object.getPrototypeOf((T=Object.getPrototypeOf((m=v.hasOwnProperty)!==null&&m!==void 0?m:ui))!==null&&T!==void 0?T:ui))===null||E===void 0?void 0:E.toString))&&(S=v+"",l.push({start:f.length+h.length,length:S.length,error:`Value of type ${Object.prototype.toString.call(v).slice(8,-1)} is not a valid path parameter`})),f+h+(p===o.length?"":S)},""),u=a.split(/[?#]/,1)[0],c=new RegExp("(?<=^|\\/)(?:\\.|%2e){1,2}(?=\\/|$)","gi");let d;for(;(d=c.exec(u))!==null;)l.push({start:d.index,length:d[0].length,error:`Value "${d[0]}" can't be safely passed as a path parameter`});if(l.sort((f,h)=>f.start-h.start),l.length>0){let f=0;const h=l.reduce((p,m)=>{const T=" ".repeat(m.start-f),E="^".repeat(m.length);return f=m.start+m.length,p+T+E},"");throw new ie(`Path parameters result in path with invalid segments:
207
- ${l.map(p=>p.error).join(`
208
- `)}
209
- ${a}
210
- ${h}`)}return a})(ai);/**
211
- * @license
212
- * Copyright 2025 Google LLC
213
- * SPDX-License-Identifier: Apache-2.0
214
- */class di extends li{create(e,n){var o;const{api_version:s=this._client.apiVersion}=e,l=Je(e,["api_version"]);if("model"in l&&"agent_config"in l)throw new ie("Invalid request: specified `model` and `agent_config`. If specifying `model`, use `generation_config`.");if("agent"in l&&"generation_config"in l)throw new ie("Invalid request: specified `agent` and `generation_config`. If specifying `agent`, use `agent_config`.");return this._client.post(Qe`/${s}/interactions`,Object.assign(Object.assign({body:l},n),{stream:(o=e.stream)!==null&&o!==void 0?o:!1}))}delete(e,n={},o){const{api_version:s=this._client.apiVersion}=n??{};return this._client.delete(Qe`/${s}/interactions/${e}`,o)}cancel(e,n={},o){const{api_version:s=this._client.apiVersion}=n??{};return this._client.post(Qe`/${s}/interactions/${e}/cancel`,o)}get(e,n={},o){var s;const l=n??{},{api_version:a=this._client.apiVersion}=l,u=Je(l,["api_version"]);return this._client.get(Qe`/${a}/interactions/${e}`,Object.assign(Object.assign({query:u},o),{stream:(s=n==null?void 0:n.stream)!==null&&s!==void 0?s:!1}))}}di._key=Object.freeze(["interactions"]);class ci extends di{}/**
215
- * @license
216
- * Copyright 2025 Google LLC
217
- * SPDX-License-Identifier: Apache-2.0
218
- */function rc(t){let e=0;for(const s of t)e+=s.length;const n=new Uint8Array(e);let o=0;for(const s of t)n.set(s,o),o+=s.length;return n}let Ze;function kt(t){let e;return(Ze??(e=new globalThis.TextEncoder,Ze=e.encode.bind(e)))(t)}let je;function fi(t){let e;return(je??(e=new globalThis.TextDecoder,je=e.decode.bind(e)))(t)}/**
219
- * @license
220
- * Copyright 2025 Google LLC
221
- * SPDX-License-Identifier: Apache-2.0
222
- */class et{constructor(){this.buffer=new Uint8Array,this.carriageReturnIndex=null}decode(e){if(e==null)return[];const n=e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?kt(e):e;this.buffer=rc([this.buffer,n]);const o=[];let s;for(;(s=lc(this.buffer,this.carriageReturnIndex))!=null;){if(s.carriage&&this.carriageReturnIndex==null){this.carriageReturnIndex=s.index;continue}if(this.carriageReturnIndex!=null&&(s.index!==this.carriageReturnIndex+1||s.carriage)){o.push(fi(this.buffer.subarray(0,this.carriageReturnIndex-1))),this.buffer=this.buffer.subarray(this.carriageReturnIndex),this.carriageReturnIndex=null;continue}const l=this.carriageReturnIndex!==null?s.preceding-1:s.preceding,a=fi(this.buffer.subarray(0,l));o.push(a),this.buffer=this.buffer.subarray(s.index),this.carriageReturnIndex=null}return o}flush(){return this.buffer.length?this.decode(`
223
- `):[]}}et.NEWLINE_CHARS=new Set([`
224
- `,"\r"]),et.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function lc(t,e){for(let s=e??0;s<t.length;s++){if(t[s]===10)return{preceding:s,index:s+1,carriage:!1};if(t[s]===13)return{preceding:s,index:s+1,carriage:!0}}return null}function ac(t){for(let o=0;o<t.length-1;o++){if(t[o]===10&&t[o+1]===10||t[o]===13&&t[o+1]===13)return o+2;if(t[o]===13&&t[o+1]===10&&o+3<t.length&&t[o+2]===13&&t[o+3]===10)return o+4}return-1}/**
225
- * @license
226
- * Copyright 2025 Google LLC
227
- * SPDX-License-Identifier: Apache-2.0
228
- */const tt={off:0,error:200,warn:300,info:400,debug:500},pi=(t,e,n)=>{if(t){if(Bd(tt,t))return t;ee(n).warn(`${e} was set to ${JSON.stringify(t)}, expected one of ${JSON.stringify(Object.keys(tt))}`)}};function be(){}function nt(t,e,n){return!e||tt[t]>tt[n]?be:e[t].bind(e)}const uc={error:be,warn:be,info:be,debug:be};let hi=new WeakMap;function ee(t){var e;const n=t.logger,o=(e=t.logLevel)!==null&&e!==void 0?e:"off";if(!n)return uc;const s=hi.get(n);if(s&&s[0]===o)return s[1];const l={error:nt("error",n,o),warn:nt("warn",n,o),info:nt("info",n,o),debug:nt("debug",n,o)};return hi.set(n,[o,l]),l}const Te=t=>(t.options&&(t.options=Object.assign({},t.options),delete t.options.headers),t.headers&&(t.headers=Object.fromEntries((t.headers instanceof Headers?[...t.headers]:Object.entries(t.headers)).map(([e,n])=>[e,e.toLowerCase()==="x-goog-api-key"||e.toLowerCase()==="authorization"||e.toLowerCase()==="cookie"||e.toLowerCase()==="set-cookie"?"***":n]))),"retryOfRequestLogID"in t&&(t.retryOfRequestLogID&&(t.retryOf=t.retryOfRequestLogID),delete t.retryOfRequestLogID),t);/**
229
- * @license
230
- * Copyright 2025 Google LLC
231
- * SPDX-License-Identifier: Apache-2.0
232
- */class Re{constructor(e,n,o){this.iterator=e,this.controller=n,this.client=o}static fromSSEResponse(e,n,o){let s=!1;const l=o?ee(o):console;function a(){return le(this,arguments,function*(){var c,d,f,h;if(s)throw new ie("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");s=!0;let p=!1;try{try{for(var m=!0,T=ae(dc(e,n)),E;E=yield U(T.next()),c=E.done,!c;m=!0){h=E.value,m=!1;const v=h;if(!p)if(v.data.startsWith("[DONE]")){p=!0;continue}else try{yield yield U(JSON.parse(v.data))}catch(S){throw l.error("Could not parse message into JSON:",v.data),l.error("From chunk:",v.raw),S}}}catch(v){d={error:v}}finally{try{!m&&!c&&(f=T.return)&&(yield U(f.call(T)))}finally{if(d)throw d.error}}p=!0}catch(v){if(At(v))return yield U(void 0);throw v}finally{p||n.abort()}})}return new Re(a,n,o)}static fromReadableStream(e,n,o){let s=!1;function l(){return le(this,arguments,function*(){var c,d,f,h;const p=new et,m=ii(e);try{for(var T=!0,E=ae(m),v;v=yield U(E.next()),c=v.done,!c;T=!0){h=v.value,T=!1;const S=h;for(const _ of p.decode(S))yield yield U(_)}}catch(S){d={error:S}}finally{try{!T&&!c&&(f=E.return)&&(yield U(f.call(E)))}finally{if(d)throw d.error}}for(const S of p.flush())yield yield U(S)})}function a(){return le(this,arguments,function*(){var c,d,f,h;if(s)throw new ie("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");s=!0;let p=!1;try{try{for(var m=!0,T=ae(l()),E;E=yield U(T.next()),c=E.done,!c;m=!0){h=E.value,m=!1;const v=h;p||v&&(yield yield U(JSON.parse(v)))}}catch(v){d={error:v}}finally{try{!m&&!c&&(f=T.return)&&(yield U(f.call(T)))}finally{if(d)throw d.error}}p=!0}catch(v){if(At(v))return yield U(void 0);throw v}finally{p||n.abort()}})}return new Re(a,n,o)}[Symbol.asyncIterator](){return this.iterator()}tee(){const e=[],n=[],o=this.iterator(),s=l=>({next:()=>{if(l.length===0){const a=o.next();e.push(a),n.push(a)}return l.shift()}});return[new Re(()=>s(e),this.controller,this.client),new Re(()=>s(n),this.controller,this.client)]}toReadableStream(){const e=this;let n;return oi({async start(){n=e[Symbol.asyncIterator]()},async pull(o){try{const{value:s,done:l}=await n.next();if(l)return o.close();const a=kt(JSON.stringify(s)+`
233
- `);o.enqueue(a)}catch(s){o.error(s)}},async cancel(){var o;await((o=n.return)===null||o===void 0?void 0:o.call(n))}})}}function dc(t,e){return le(this,arguments,function*(){var o,s,l,a;if(!t.body)throw e.abort(),typeof globalThis.navigator<"u"&&globalThis.navigator.product==="ReactNative"?new ie("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api"):new ie("Attempted to iterate over a response with no body");const u=new fc,c=new et,d=ii(t.body);try{for(var f=!0,h=ae(cc(d)),p;p=yield U(h.next()),o=p.done,!o;f=!0){a=p.value,f=!1;const m=a;for(const T of c.decode(m)){const E=u.decode(T);E&&(yield yield U(E))}}}catch(m){s={error:m}}finally{try{!f&&!o&&(l=h.return)&&(yield U(l.call(h)))}finally{if(s)throw s.error}}for(const m of c.flush()){const T=u.decode(m);T&&(yield yield U(T))}})}function cc(t){return le(this,arguments,function*(){var n,o,s,l;let a=new Uint8Array;try{for(var u=!0,c=ae(t),d;d=yield U(c.next()),n=d.done,!n;u=!0){l=d.value,u=!1;const f=l;if(f==null)continue;const h=f instanceof ArrayBuffer?new Uint8Array(f):typeof f=="string"?kt(f):f;let p=new Uint8Array(a.length+h.length);p.set(a),p.set(h,a.length),a=p;let m;for(;(m=ac(a))!==-1;)yield yield U(a.slice(0,m)),a=a.slice(m)}}catch(f){o={error:f}}finally{try{!u&&!n&&(s=c.return)&&(yield U(s.call(c)))}finally{if(o)throw o.error}}a.length>0&&(yield yield U(a))})}class fc{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith("\r")&&(e=e.substring(0,e.length-1)),!e){if(!this.event&&!this.data.length)return null;const l={event:this.event,data:this.data.join(`
234
- `),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],l}if(this.chunks.push(e),e.startsWith(":"))return null;let[n,o,s]=pc(e,":");return s.startsWith(" ")&&(s=s.substring(1)),n==="event"?this.event=s:n==="data"&&this.data.push(s),null}}function pc(t,e){const n=t.indexOf(e);return n!==-1?[t.substring(0,n),e,t.substring(n+e.length)]:[t,"",""]}/**
235
- * @license
236
- * Copyright 2025 Google LLC
237
- * SPDX-License-Identifier: Apache-2.0
238
- */async function hc(t,e){const{response:n,requestLogID:o,retryOfRequestLogID:s,startTime:l}=e,a=await(async()=>{var u;if(e.options.stream)return ee(t).debug("response",n.status,n.url,n.headers,n.body),e.options.__streamClass?e.options.__streamClass.fromSSEResponse(n,e.controller,t):Re.fromSSEResponse(n,e.controller,t);if(n.status===204)return null;if(e.options.__binaryResponse)return n;const c=n.headers.get("content-type"),d=(u=c==null?void 0:c.split(";")[0])===null||u===void 0?void 0:u.trim();return(d==null?void 0:d.includes("application/json"))||(d==null?void 0:d.endsWith("+json"))?await n.json():await n.text()})();return ee(t).debug(`[${o}] response parsed`,Te({retryOfRequestLogID:s,url:n.url,status:n.status,body:a,durationMs:Date.now()-l})),a}/**
239
- * @license
240
- * Copyright 2025 Google LLC
241
- * SPDX-License-Identifier: Apache-2.0
242
- */class Dt extends Promise{constructor(e,n,o=hc){super(s=>{s(null)}),this.responsePromise=n,this.parseResponse=o,this.client=e}_thenUnwrap(e){return new Dt(this.client,this.responsePromise,async(n,o)=>e(await this.parseResponse(n,o),o))}asResponse(){return this.responsePromise.then(e=>e.response)}async withResponse(){const[e,n]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:n}}parse(){return this.parsedPromise||(this.parsedPromise=this.responsePromise.then(e=>this.parseResponse(this.client,e))),this.parsedPromise}then(e,n){return this.parse().then(e,n)}catch(e){return this.parse().catch(e)}finally(e){return this.parse().finally(e)}}/**
243
- * @license
244
- * Copyright 2025 Google LLC
245
- * SPDX-License-Identifier: Apache-2.0
246
- */const mi=Symbol("brand.privateNullableHeaders");function*mc(t){if(!t)return;if(mi in t){const{values:o,nulls:s}=t;yield*o.entries();for(const l of s)yield[l,null];return}let e=!1,n;t instanceof Headers?n=t.entries():ei(t)?n=t:(e=!0,n=Object.entries(t??{}));for(let o of n){const s=o[0];if(typeof s!="string")throw new TypeError("expected header name to be a string");const l=ei(o[1])?o[1]:[o[1]];let a=!1;for(const u of l)u!==void 0&&(e&&!a&&(a=!0,yield[s,null]),yield[s,u])}}const Ue=t=>{const e=new Headers,n=new Set;for(const o of t){const s=new Set;for(const[l,a]of mc(o)){const u=l.toLowerCase();s.has(u)||(e.delete(l),s.add(u)),a===null?(e.delete(l),n.add(u)):(e.append(l,a),n.delete(u))}}return{[mi]:!0,values:e,nulls:n}};/**
247
- * @license
248
- * Copyright 2025 Google LLC
249
- * SPDX-License-Identifier: Apache-2.0
250
- */const bt=t=>{var e,n,o,s,l,a;if(typeof globalThis.process<"u")return(o=(n=(e=globalThis.process.env)===null||e===void 0?void 0:e[t])===null||n===void 0?void 0:n.trim())!==null&&o!==void 0?o:void 0;if(typeof globalThis.Deno<"u")return(a=(l=(s=globalThis.Deno.env)===null||s===void 0?void 0:s.get)===null||l===void 0?void 0:l.call(s,t))===null||a===void 0?void 0:a.trim()};/**
251
- * @license
252
- * Copyright 2025 Google LLC
253
- * SPDX-License-Identifier: Apache-2.0
254
- */var gi;class ot{constructor(e){var n,o,s,l,a,u,c,{baseURL:d=bt("GEMINI_NEXT_GEN_API_BASE_URL"),apiKey:f=(n=bt("GEMINI_API_KEY"))!==null&&n!==void 0?n:null,apiVersion:h="v1beta"}=e,p=Je(e,["baseURL","apiKey","apiVersion"]);const m=Object.assign(Object.assign({apiKey:f,apiVersion:h},p),{baseURL:d||"https://generativelanguage.googleapis.com"});this.baseURL=m.baseURL,this.timeout=(o=m.timeout)!==null&&o!==void 0?o:ot.DEFAULT_TIMEOUT,this.logger=(s=m.logger)!==null&&s!==void 0?s:console;const T="warn";this.logLevel=T,this.logLevel=(a=(l=pi(m.logLevel,"ClientOptions.logLevel",this))!==null&&l!==void 0?l:pi(bt("GEMINI_NEXT_GEN_API_LOG"),"process.env['GEMINI_NEXT_GEN_API_LOG']",this))!==null&&a!==void 0?a:T,this.fetchOptions=m.fetchOptions,this.maxRetries=(u=m.maxRetries)!==null&&u!==void 0?u:2,this.fetch=(c=m.fetch)!==null&&c!==void 0?c:Xd(),this.encoder=jd,this._options=m,this.apiKey=f,this.apiVersion=h,this.clientAdapter=m.clientAdapter}withOptions(e){return new this.constructor(Object.assign(Object.assign(Object.assign({},this._options),{baseURL:this.baseURL,maxRetries:this.maxRetries,timeout:this.timeout,logger:this.logger,logLevel:this.logLevel,fetch:this.fetch,fetchOptions:this.fetchOptions,apiKey:this.apiKey,apiVersion:this.apiVersion}),e))}baseURLOverridden(){return this.baseURL!=="https://generativelanguage.googleapis.com"}defaultQuery(){return this._options.defaultQuery}validateHeaders({values:e,nulls:n}){if(!(e.has("authorization")||e.has("x-goog-api-key"))&&!(this.apiKey&&e.get("x-goog-api-key"))&&!n.has("x-goog-api-key"))throw new Error('Could not resolve authentication method. Expected the apiKey to be set. Or for the "x-goog-api-key" headers to be explicitly omitted')}async authHeaders(e){const n=Ue([e.headers]);if(!(n.values.has("authorization")||n.values.has("x-goog-api-key"))){if(this.apiKey)return Ue([{"x-goog-api-key":this.apiKey}]);if(this.clientAdapter.isVertexAI())return Ue([await this.clientAdapter.getAuthHeaders()])}}stringifyQuery(e){return Object.entries(e).filter(([n,o])=>typeof o<"u").map(([n,o])=>{if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return`${encodeURIComponent(n)}=${encodeURIComponent(o)}`;if(o===null)return`${encodeURIComponent(n)}=`;throw new ie(`Cannot stringify type ${typeof o}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`)}).join("&")}getUserAgent(){return`${this.constructor.name}/JS ${Ae}`}defaultIdempotencyKey(){return`stainless-node-retry-${Vd()}`}makeStatusError(e,n,o,s){return j.generate(e,n,o,s)}buildURL(e,n,o){const s=!this.baseURLOverridden()&&o||this.baseURL,l=Hd(e)?new URL(e):new URL(s+(s.endsWith("/")&&e.startsWith("/")?e.slice(1):e)),a=this.defaultQuery();return qd(a)||(n=Object.assign(Object.assign({},a),n)),typeof n=="object"&&n&&!Array.isArray(n)&&(l.search=this.stringifyQuery(n)),l.toString()}async prepareOptions(e){if(this.clientAdapter&&this.clientAdapter.isVertexAI()&&!e.path.startsWith(`/${this.apiVersion}/projects/`)){const n=e.path.slice(this.apiVersion.length+1);e.path=`/${this.apiVersion}/projects/${this.clientAdapter.getProject()}/locations/${this.clientAdapter.getLocation()}${n}`}}async prepareRequest(e,{url:n,options:o}){}get(e,n){return this.methodRequest("get",e,n)}post(e,n){return this.methodRequest("post",e,n)}patch(e,n){return this.methodRequest("patch",e,n)}put(e,n){return this.methodRequest("put",e,n)}delete(e,n){return this.methodRequest("delete",e,n)}methodRequest(e,n,o){return this.request(Promise.resolve(o).then(s=>Object.assign({method:e,path:n},s)))}request(e,n=null){return new Dt(this,this.makeRequest(e,n,void 0))}async makeRequest(e,n,o){var s,l,a;const u=await e,c=(s=u.maxRetries)!==null&&s!==void 0?s:this.maxRetries;n==null&&(n=c),await this.prepareOptions(u);const{req:d,url:f,timeout:h}=await this.buildRequest(u,{retryCount:c-n});await this.prepareRequest(d,{url:f,options:u});const p="log_"+(Math.random()*(1<<24)|0).toString(16).padStart(6,"0"),m=o===void 0?"":`, retryOf: ${o}`,T=Date.now();if(ee(this).debug(`[${p}] sending request`,Te({retryOfRequestLogID:o,method:u.method,url:f,options:u,headers:d.headers})),!((l=u.signal)===null||l===void 0)&&l.aborted)throw new wt;const E=new AbortController,v=await this.fetchWithTimeout(f,d,h,E).catch(Rt),S=Date.now();if(v instanceof globalThis.Error){const C=`retrying, ${n} attempts remaining`;if(!((a=u.signal)===null||a===void 0)&&a.aborted)throw new wt;const x=At(v)||/timed? ?out/i.test(String(v)+("cause"in v?String(v.cause):""));if(n)return ee(this).info(`[${p}] connection ${x?"timed out":"failed"} - ${C}`),ee(this).debug(`[${p}] connection ${x?"timed out":"failed"} (${C})`,Te({retryOfRequestLogID:o,url:f,durationMs:S-T,message:v.message})),this.retryRequest(u,n,o??p);throw ee(this).info(`[${p}] connection ${x?"timed out":"failed"} - error; no more retries left`),ee(this).debug(`[${p}] connection ${x?"timed out":"failed"} (error; no more retries left)`,Te({retryOfRequestLogID:o,url:f,durationMs:S-T,message:v.message})),x?new Yo:new ze({cause:v})}const _=`[${p}${m}] ${d.method} ${f} ${v.ok?"succeeded":"failed"} with status ${v.status} in ${S-T}ms`;if(!v.ok){const C=await this.shouldRetry(v);if(n&&C){const w=`retrying, ${n} attempts remaining`;return await Zd(v.body),ee(this).info(`${_} - ${w}`),ee(this).debug(`[${p}] response error (${w})`,Te({retryOfRequestLogID:o,url:v.url,status:v.status,headers:v.headers,durationMs:S-T})),this.retryRequest(u,n,o??p,v.headers)}const x=C?"error; no more retries left":"error; not retryable";ee(this).info(`${_} - ${x}`);const R=await v.text().catch(w=>Rt(w).message),M=Wd(R),k=M?void 0:R;throw ee(this).debug(`[${p}] response error (${x})`,Te({retryOfRequestLogID:o,url:v.url,status:v.status,headers:v.headers,message:k,durationMs:Date.now()-T})),this.makeStatusError(v.status,M,k,v.headers)}return ee(this).info(_),ee(this).debug(`[${p}] response start`,Te({retryOfRequestLogID:o,url:v.url,status:v.status,headers:v.headers,durationMs:S-T})),{response:v,options:u,controller:E,requestLogID:p,retryOfRequestLogID:o,startTime:T}}async fetchWithTimeout(e,n,o,s){const l=n||{},{signal:a,method:u}=l,c=Je(l,["signal","method"]);a&&a.addEventListener("abort",()=>s.abort());const d=setTimeout(()=>s.abort(),o),f=globalThis.ReadableStream&&c.body instanceof globalThis.ReadableStream||typeof c.body=="object"&&c.body!==null&&Symbol.asyncIterator in c.body,h=Object.assign(Object.assign(Object.assign({signal:s.signal},f?{duplex:"half"}:{}),{method:"GET"}),c);u&&(h.method=u.toUpperCase());try{return await this.fetch.call(void 0,e,h)}finally{clearTimeout(d)}}async shouldRetry(e){const n=e.headers.get("x-should-retry");return n==="true"?!0:n==="false"?!1:e.status===408||e.status===409||e.status===429||e.status>=500}async retryRequest(e,n,o,s){var l;let a;const u=s==null?void 0:s.get("retry-after-ms");if(u){const d=parseFloat(u);Number.isNaN(d)||(a=d)}const c=s==null?void 0:s.get("retry-after");if(c&&!a){const d=parseFloat(c);Number.isNaN(d)?a=Date.parse(c)-Date.now():a=d*1e3}if(!(a&&0<=a&&a<60*1e3)){const d=(l=e.maxRetries)!==null&&l!==void 0?l:this.maxRetries;a=this.calculateDefaultRetryTimeoutMillis(n,d)}return await Yd(a),this.makeRequest(e,n-1,o)}calculateDefaultRetryTimeoutMillis(e,n){const l=n-e,a=Math.min(.5*Math.pow(2,l),8),u=1-Math.random()*.25;return a*u*1e3}async buildRequest(e,{retryCount:n=0}={}){var o,s,l;const a=Object.assign({},e),{method:u,path:c,query:d,defaultBaseURL:f}=a,h=this.buildURL(c,d,f);"timeout"in a&&Jd("timeout",a.timeout),a.timeout=(o=a.timeout)!==null&&o!==void 0?o:this.timeout;const{bodyHeaders:p,body:m}=this.buildBody({options:a}),T=await this.buildHeaders({options:e,method:u,bodyHeaders:p,retryCount:n});return{req:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({method:u,headers:T},a.signal&&{signal:a.signal}),globalThis.ReadableStream&&m instanceof globalThis.ReadableStream&&{duplex:"half"}),m&&{body:m}),(s=this.fetchOptions)!==null&&s!==void 0?s:{}),(l=a.fetchOptions)!==null&&l!==void 0?l:{}),url:h,timeout:a.timeout}}async buildHeaders({options:e,method:n,bodyHeaders:o,retryCount:s}){let l={};this.idempotencyHeader&&n!=="get"&&(e.idempotencyKey||(e.idempotencyKey=this.defaultIdempotencyKey()),l[this.idempotencyHeader]=e.idempotencyKey);const a=await this.authHeaders(e);let u=Ue([l,Object.assign(Object.assign({Accept:"application/json","User-Agent":this.getUserAgent(),"X-Stainless-Retry-Count":String(s)},e.timeout?{"X-Stainless-Timeout":String(Math.trunc(e.timeout/1e3))}:{}),zd()),this._options.defaultHeaders,o,e.headers,a]);return this.validateHeaders(u),u.values}buildBody({options:{body:e,headers:n}}){if(!e)return{bodyHeaders:void 0,body:void 0};const o=Ue([n]);return ArrayBuffer.isView(e)||e instanceof ArrayBuffer||e instanceof DataView||typeof e=="string"&&o.values.has("content-type")||globalThis.Blob&&e instanceof globalThis.Blob||e instanceof FormData||e instanceof URLSearchParams||globalThis.ReadableStream&&e instanceof globalThis.ReadableStream?{bodyHeaders:void 0,body:e}:typeof e=="object"&&(Symbol.asyncIterator in e||Symbol.iterator in e&&"next"in e&&typeof e.next=="function")?{bodyHeaders:void 0,body:Qd(e)}:this.encoder({body:e,headers:o})}}ot.DEFAULT_TIMEOUT=6e4;class Q extends ot{constructor(){super(...arguments),this.interactions=new ci(this)}}gi=Q,Q.GeminiNextGenAPIClient=gi,Q.GeminiNextGenAPIClientError=ie,Q.APIError=j,Q.APIConnectionError=ze,Q.APIConnectionTimeoutError=Yo,Q.APIUserAbortError=wt,Q.NotFoundError=zo,Q.ConflictError=Xo,Q.RateLimitError=Zo,Q.BadRequestError=Oo,Q.AuthenticationError=$o,Q.InternalServerError=jo,Q.PermissionDeniedError=Ko,Q.UnprocessableEntityError=Qo,Q.toFile=ic,Q.Interactions=ci;/**
255
- * @license
256
- * Copyright 2025 Google LLC
257
- * SPDX-License-Identifier: Apache-2.0
258
- */function gc(t,e){const n={},o=i(t,["name"]);return o!=null&&r(n,["_url","name"],o),n}function yc(t,e){const n={},o=i(t,["name"]);return o!=null&&r(n,["_url","name"],o),n}function Tc(t,e){const n={},o=i(t,["sdkHttpResponse"]);return o!=null&&r(n,["sdkHttpResponse"],o),n}function vc(t,e){const n={},o=i(t,["sdkHttpResponse"]);return o!=null&&r(n,["sdkHttpResponse"],o),n}function _c(t,e,n){const o={};if(i(t,["validationDataset"])!==void 0)throw new Error("validationDataset parameter is not supported in Gemini API.");const s=i(t,["tunedModelDisplayName"]);if(e!==void 0&&s!=null&&r(e,["displayName"],s),i(t,["description"])!==void 0)throw new Error("description parameter is not supported in Gemini API.");const l=i(t,["epochCount"]);e!==void 0&&l!=null&&r(e,["tuningTask","hyperparameters","epochCount"],l);const a=i(t,["learningRateMultiplier"]);if(a!=null&&r(o,["tuningTask","hyperparameters","learningRateMultiplier"],a),i(t,["exportLastCheckpointOnly"])!==void 0)throw new Error("exportLastCheckpointOnly parameter is not supported in Gemini API.");if(i(t,["preTunedModelCheckpointId"])!==void 0)throw new Error("preTunedModelCheckpointId parameter is not supported in Gemini API.");if(i(t,["adapterSize"])!==void 0)throw new Error("adapterSize parameter is not supported in Gemini API.");const u=i(t,["batchSize"]);e!==void 0&&u!=null&&r(e,["tuningTask","hyperparameters","batchSize"],u);const c=i(t,["learningRate"]);if(e!==void 0&&c!=null&&r(e,["tuningTask","hyperparameters","learningRate"],c),i(t,["labels"])!==void 0)throw new Error("labels parameter is not supported in Gemini API.");if(i(t,["beta"])!==void 0)throw new Error("beta parameter is not supported in Gemini API.");return o}function Ec(t,e,n){const o={};let s=i(n,["config","method"]);if(s===void 0&&(s="SUPERVISED_FINE_TUNING"),s==="SUPERVISED_FINE_TUNING"){const m=i(t,["validationDataset"]);e!==void 0&&m!=null&&r(e,["supervisedTuningSpec"],Ti(m))}else if(s==="PREFERENCE_TUNING"){const m=i(t,["validationDataset"]);e!==void 0&&m!=null&&r(e,["preferenceOptimizationSpec"],Ti(m))}const l=i(t,["tunedModelDisplayName"]);e!==void 0&&l!=null&&r(e,["tunedModelDisplayName"],l);const a=i(t,["description"]);e!==void 0&&a!=null&&r(e,["description"],a);let u=i(n,["config","method"]);if(u===void 0&&(u="SUPERVISED_FINE_TUNING"),u==="SUPERVISED_FINE_TUNING"){const m=i(t,["epochCount"]);e!==void 0&&m!=null&&r(e,["supervisedTuningSpec","hyperParameters","epochCount"],m)}else if(u==="PREFERENCE_TUNING"){const m=i(t,["epochCount"]);e!==void 0&&m!=null&&r(e,["preferenceOptimizationSpec","hyperParameters","epochCount"],m)}let c=i(n,["config","method"]);if(c===void 0&&(c="SUPERVISED_FINE_TUNING"),c==="SUPERVISED_FINE_TUNING"){const m=i(t,["learningRateMultiplier"]);e!==void 0&&m!=null&&r(e,["supervisedTuningSpec","hyperParameters","learningRateMultiplier"],m)}else if(c==="PREFERENCE_TUNING"){const m=i(t,["learningRateMultiplier"]);e!==void 0&&m!=null&&r(e,["preferenceOptimizationSpec","hyperParameters","learningRateMultiplier"],m)}let d=i(n,["config","method"]);if(d===void 0&&(d="SUPERVISED_FINE_TUNING"),d==="SUPERVISED_FINE_TUNING"){const m=i(t,["exportLastCheckpointOnly"]);e!==void 0&&m!=null&&r(e,["supervisedTuningSpec","exportLastCheckpointOnly"],m)}else if(d==="PREFERENCE_TUNING"){const m=i(t,["exportLastCheckpointOnly"]);e!==void 0&&m!=null&&r(e,["preferenceOptimizationSpec","exportLastCheckpointOnly"],m)}let f=i(n,["config","method"]);if(f===void 0&&(f="SUPERVISED_FINE_TUNING"),f==="SUPERVISED_FINE_TUNING"){const m=i(t,["adapterSize"]);e!==void 0&&m!=null&&r(e,["supervisedTuningSpec","hyperParameters","adapterSize"],m)}else if(f==="PREFERENCE_TUNING"){const m=i(t,["adapterSize"]);e!==void 0&&m!=null&&r(e,["preferenceOptimizationSpec","hyperParameters","adapterSize"],m)}if(i(t,["batchSize"])!==void 0)throw new Error("batchSize parameter is not supported in Vertex AI.");if(i(t,["learningRate"])!==void 0)throw new Error("learningRate parameter is not supported in Vertex AI.");const h=i(t,["labels"]);e!==void 0&&h!=null&&r(e,["labels"],h);const p=i(t,["beta"]);return e!==void 0&&p!=null&&r(e,["preferenceOptimizationSpec","hyperParameters","beta"],p),o}function Cc(t,e){const n={},o=i(t,["baseModel"]);o!=null&&r(n,["baseModel"],o);const s=i(t,["preTunedModel"]);s!=null&&r(n,["preTunedModel"],s);const l=i(t,["trainingDataset"]);l!=null&&Dc(l);const a=i(t,["config"]);return a!=null&&_c(a,n),n}function xc(t,e){const n={},o=i(t,["baseModel"]);o!=null&&r(n,["baseModel"],o);const s=i(t,["preTunedModel"]);s!=null&&r(n,["preTunedModel"],s);const l=i(t,["trainingDataset"]);l!=null&&bc(l,n,e);const a=i(t,["config"]);return a!=null&&Ec(a,n,e),n}function Sc(t,e){const n={},o=i(t,["name"]);return o!=null&&r(n,["_url","name"],o),n}function Ic(t,e){const n={},o=i(t,["name"]);return o!=null&&r(n,["_url","name"],o),n}function Ac(t,e,n){const o={},s=i(t,["pageSize"]);e!==void 0&&s!=null&&r(e,["_query","pageSize"],s);const l=i(t,["pageToken"]);e!==void 0&&l!=null&&r(e,["_query","pageToken"],l);const a=i(t,["filter"]);return e!==void 0&&a!=null&&r(e,["_query","filter"],a),o}function Rc(t,e,n){const o={},s=i(t,["pageSize"]);e!==void 0&&s!=null&&r(e,["_query","pageSize"],s);const l=i(t,["pageToken"]);e!==void 0&&l!=null&&r(e,["_query","pageToken"],l);const a=i(t,["filter"]);return e!==void 0&&a!=null&&r(e,["_query","filter"],a),o}function wc(t,e){const n={},o=i(t,["config"]);return o!=null&&Ac(o,n),n}function Pc(t,e){const n={},o=i(t,["config"]);return o!=null&&Rc(o,n),n}function Nc(t,e){const n={},o=i(t,["sdkHttpResponse"]);o!=null&&r(n,["sdkHttpResponse"],o);const s=i(t,["nextPageToken"]);s!=null&&r(n,["nextPageToken"],s);const l=i(t,["tunedModels"]);if(l!=null){let a=l;Array.isArray(a)&&(a=a.map(u=>yi(u))),r(n,["tuningJobs"],a)}return n}function Mc(t,e){const n={},o=i(t,["sdkHttpResponse"]);o!=null&&r(n,["sdkHttpResponse"],o);const s=i(t,["nextPageToken"]);s!=null&&r(n,["nextPageToken"],s);const l=i(t,["tuningJobs"]);if(l!=null){let a=l;Array.isArray(a)&&(a=a.map(u=>Ut(u))),r(n,["tuningJobs"],a)}return n}function kc(t,e){const n={},o=i(t,["name"]);o!=null&&r(n,["model"],o);const s=i(t,["name"]);return s!=null&&r(n,["endpoint"],s),n}function Dc(t,e){const n={};if(i(t,["gcsUri"])!==void 0)throw new Error("gcsUri parameter is not supported in Gemini API.");if(i(t,["vertexDatasetResource"])!==void 0)throw new Error("vertexDatasetResource parameter is not supported in Gemini API.");const o=i(t,["examples"]);if(o!=null){let s=o;Array.isArray(s)&&(s=s.map(l=>l)),r(n,["examples","examples"],s)}return n}function bc(t,e,n){const o={};let s=i(n,["config","method"]);if(s===void 0&&(s="SUPERVISED_FINE_TUNING"),s==="SUPERVISED_FINE_TUNING"){const a=i(t,["gcsUri"]);e!==void 0&&a!=null&&r(e,["supervisedTuningSpec","trainingDatasetUri"],a)}else if(s==="PREFERENCE_TUNING"){const a=i(t,["gcsUri"]);e!==void 0&&a!=null&&r(e,["preferenceOptimizationSpec","trainingDatasetUri"],a)}let l=i(n,["config","method"]);if(l===void 0&&(l="SUPERVISED_FINE_TUNING"),l==="SUPERVISED_FINE_TUNING"){const a=i(t,["vertexDatasetResource"]);e!==void 0&&a!=null&&r(e,["supervisedTuningSpec","trainingDatasetUri"],a)}else if(l==="PREFERENCE_TUNING"){const a=i(t,["vertexDatasetResource"]);e!==void 0&&a!=null&&r(e,["preferenceOptimizationSpec","trainingDatasetUri"],a)}if(i(t,["examples"])!==void 0)throw new Error("examples parameter is not supported in Vertex AI.");return o}function yi(t,e){const n={},o=i(t,["sdkHttpResponse"]);o!=null&&r(n,["sdkHttpResponse"],o);const s=i(t,["name"]);s!=null&&r(n,["name"],s);const l=i(t,["state"]);l!=null&&r(n,["state"],po(l));const a=i(t,["createTime"]);a!=null&&r(n,["createTime"],a);const u=i(t,["tuningTask","startTime"]);u!=null&&r(n,["startTime"],u);const c=i(t,["tuningTask","completeTime"]);c!=null&&r(n,["endTime"],c);const d=i(t,["updateTime"]);d!=null&&r(n,["updateTime"],d);const f=i(t,["description"]);f!=null&&r(n,["description"],f);const h=i(t,["baseModel"]);h!=null&&r(n,["baseModel"],h);const p=i(t,["_self"]);return p!=null&&r(n,["tunedModel"],kc(p)),n}function Ut(t,e){const n={},o=i(t,["sdkHttpResponse"]);o!=null&&r(n,["sdkHttpResponse"],o);const s=i(t,["name"]);s!=null&&r(n,["name"],s);const l=i(t,["state"]);l!=null&&r(n,["state"],po(l));const a=i(t,["createTime"]);a!=null&&r(n,["createTime"],a);const u=i(t,["startTime"]);u!=null&&r(n,["startTime"],u);const c=i(t,["endTime"]);c!=null&&r(n,["endTime"],c);const d=i(t,["updateTime"]);d!=null&&r(n,["updateTime"],d);const f=i(t,["error"]);f!=null&&r(n,["error"],f);const h=i(t,["description"]);h!=null&&r(n,["description"],h);const p=i(t,["baseModel"]);p!=null&&r(n,["baseModel"],p);const m=i(t,["tunedModel"]);m!=null&&r(n,["tunedModel"],m);const T=i(t,["preTunedModel"]);T!=null&&r(n,["preTunedModel"],T);const E=i(t,["supervisedTuningSpec"]);E!=null&&r(n,["supervisedTuningSpec"],E);const v=i(t,["preferenceOptimizationSpec"]);v!=null&&r(n,["preferenceOptimizationSpec"],v);const S=i(t,["tuningDataStats"]);S!=null&&r(n,["tuningDataStats"],S);const _=i(t,["encryptionSpec"]);_!=null&&r(n,["encryptionSpec"],_);const C=i(t,["partnerModelTuningSpec"]);C!=null&&r(n,["partnerModelTuningSpec"],C);const x=i(t,["customBaseModel"]);x!=null&&r(n,["customBaseModel"],x);const R=i(t,["experiment"]);R!=null&&r(n,["experiment"],R);const M=i(t,["labels"]);M!=null&&r(n,["labels"],M);const k=i(t,["outputUri"]);k!=null&&r(n,["outputUri"],k);const V=i(t,["pipelineJob"]);V!=null&&r(n,["pipelineJob"],V);const w=i(t,["serviceAccount"]);w!=null&&r(n,["serviceAccount"],w);const L=i(t,["tunedModelDisplayName"]);L!=null&&r(n,["tunedModelDisplayName"],L);const B=i(t,["veoTuningSpec"]);return B!=null&&r(n,["veoTuningSpec"],B),n}function Uc(t,e){const n={},o=i(t,["sdkHttpResponse"]);o!=null&&r(n,["sdkHttpResponse"],o);const s=i(t,["name"]);s!=null&&r(n,["name"],s);const l=i(t,["metadata"]);l!=null&&r(n,["metadata"],l);const a=i(t,["done"]);a!=null&&r(n,["done"],a);const u=i(t,["error"]);return u!=null&&r(n,["error"],u),n}function Ti(t,e){const n={},o=i(t,["gcsUri"]);o!=null&&r(n,["validationDatasetUri"],o);const s=i(t,["vertexDatasetResource"]);return s!=null&&r(n,["validationDatasetUri"],s),n}/**
259
- * @license
260
- * Copyright 2025 Google LLC
261
- * SPDX-License-Identifier: Apache-2.0
262
- */class Lc extends de{constructor(e){super(),this.apiClient=e,this.list=async(n={})=>new ye(fe.PAGED_ITEM_TUNING_JOBS,o=>this.listInternal(o),await this.listInternal(n),n),this.get=async n=>await this.getInternal(n),this.tune=async n=>{var o;if(this.apiClient.isVertexAI())if(n.baseModel.startsWith("projects/")){const s={tunedModelName:n.baseModel};!((o=n.config)===null||o===void 0)&&o.preTunedModelCheckpointId&&(s.checkpointId=n.config.preTunedModelCheckpointId);const l=Object.assign(Object.assign({},n),{preTunedModel:s});return l.baseModel=void 0,await this.tuneInternal(l)}else{const s=Object.assign({},n);return await this.tuneInternal(s)}else{const s=Object.assign({},n),l=await this.tuneMldevInternal(s);let a="";return l.metadata!==void 0&&l.metadata.tunedModel!==void 0?a=l.metadata.tunedModel:l.name!==void 0&&l.name.includes("/operations/")&&(a=l.name.split("/operations/")[0]),{name:a,state:ft.JOB_STATE_QUEUED}}}}async getInternal(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Ic(e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>Ut(f))}else{const d=Sc(e);return u=A("{name}",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>yi(f))}}async listInternal(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=Pc(e);return u=A("tuningJobs",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Mc(f),p=new jn;return Object.assign(p,h),p})}else{const d=wc(e);return u=A("tunedModels",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"GET",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Nc(f),p=new jn;return Object.assign(p,h),p})}}async cancel(e){var n,o,s,l;let a,u="",c={};if(this.apiClient.isVertexAI()){const d=yc(e);return u=A("{name}:cancel",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=vc(f),p=new eo;return Object.assign(p,h),p})}else{const d=gc(e);return u=A("{name}:cancel",d._url),c=d._query,delete d._url,delete d._query,a=this.apiClient.request({path:u,queryParams:c,body:JSON.stringify(d),httpMethod:"POST",httpOptions:(s=e.config)===null||s===void 0?void 0:s.httpOptions,abortSignal:(l=e.config)===null||l===void 0?void 0:l.abortSignal}).then(f=>f.json().then(h=>{const p=h;return p.sdkHttpResponse={headers:f.headers},p})),a.then(f=>{const h=Tc(f),p=new eo;return Object.assign(p,h),p})}}async tuneInternal(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI()){const u=xc(e,e);return l=A("tuningJobs",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json().then(d=>{const f=d;return f.sdkHttpResponse={headers:c.headers},f})),s.then(c=>Ut(c))}else throw new Error("This method is only supported by the Vertex AI.")}async tuneMldevInternal(e){var n,o;let s,l="",a={};if(this.apiClient.isVertexAI())throw new Error("This method is only supported by the Gemini Developer API.");{const u=Cc(e);return l=A("tunedModels",u._url),a=u._query,delete u._url,delete u._query,s=this.apiClient.request({path:l,queryParams:a,body:JSON.stringify(u),httpMethod:"POST",httpOptions:(n=e.config)===null||n===void 0?void 0:n.httpOptions,abortSignal:(o=e.config)===null||o===void 0?void 0:o.abortSignal}).then(c=>c.json().then(d=>{const f=d;return f.sdkHttpResponse={headers:c.headers},f})),s.then(c=>Uc(c))}}}/**
263
- * @license
264
- * Copyright 2025 Google LLC
265
- * SPDX-License-Identifier: Apache-2.0
266
- */class Fc{async download(e,n){throw new Error("Download to file is not supported in the browser, please use a browser compliant download like an <a> tag.")}}const Vc=1024*1024*8,Gc=3,Hc=1e3,qc=2,it="x-goog-upload-status";async function Bc(t,e,n){var o;const s=await vi(t,e,n),l=await(s==null?void 0:s.json());if(((o=s==null?void 0:s.headers)===null||o===void 0?void 0:o[it])!=="final")throw new Error("Failed to upload file: Upload status is not finalized.");return l.file}async function Jc(t,e,n){var o;const s=await vi(t,e,n),l=await(s==null?void 0:s.json());if(((o=s==null?void 0:s.headers)===null||o===void 0?void 0:o[it])!=="final")throw new Error("Failed to upload file: Upload status is not finalized.");const a=Kt(l),u=new mt;return Object.assign(u,a),u}async function vi(t,e,n){var o,s;let l=0,a=0,u=new pt(new Response),c="upload";for(l=t.size;a<l;){const d=Math.min(Vc,l-a),f=t.slice(a,a+d);a+d>=l&&(c+=", finalize");let h=0,p=Hc;for(;h<Gc&&(u=await n.request({path:"",body:f,httpMethod:"POST",httpOptions:{apiVersion:"",baseUrl:e,headers:{"X-Goog-Upload-Command":c,"X-Goog-Upload-Offset":String(a),"Content-Length":String(d)}}}),!(!((o=u==null?void 0:u.headers)===null||o===void 0)&&o[it]));)h++,await Yc(p),p=p*qc;if(a+=d,((s=u==null?void 0:u.headers)===null||s===void 0?void 0:s[it])!=="active")break;if(l<=a)throw new Error("All content has been uploaded, but the upload status is not finalized.")}return u}async function Wc(t){return{size:t.size,type:t.type}}function Yc(t){return new Promise(e=>setTimeout(e,t))}class Oc{async upload(e,n,o){if(typeof e=="string")throw new Error("File path is not supported in browser uploader.");return await Bc(e,n,o)}async uploadToFileSearchStore(e,n,o){if(typeof e=="string")throw new Error("File path is not supported in browser uploader.");return await Jc(e,n,o)}async stat(e){if(typeof e=="string")throw new Error("File path is not supported in browser uploader.");return await Wc(e)}}/**
267
- * @license
268
- * Copyright 2025 Google LLC
269
- * SPDX-License-Identifier: Apache-2.0
270
- */class $c{create(e,n,o){return new Kc(e,n,o)}}class Kc{constructor(e,n,o){this.url=e,this.headers=n,this.callbacks=o}connect(){this.ws=new WebSocket(this.url),this.ws.onopen=this.callbacks.onopen,this.ws.onerror=this.callbacks.onerror,this.ws.onclose=this.callbacks.onclose,this.ws.onmessage=this.callbacks.onmessage}send(e){if(this.ws===void 0)throw new Error("WebSocket is not connected");this.ws.send(e)}close(){if(this.ws===void 0)throw new Error("WebSocket is not connected");this.ws.close()}}/**
271
- * @license
272
- * Copyright 2025 Google LLC
273
- * SPDX-License-Identifier: Apache-2.0
274
- */const _i="x-goog-api-key";class zc{constructor(e){this.apiKey=e}async addAuthHeaders(e,n){if(e.get(_i)===null){if(this.apiKey.startsWith("auth_tokens/"))throw new Error("Ephemeral tokens are only supported by the live API.");if(!this.apiKey)throw new Error("API key is missing. Please provide a valid API key.");e.append(_i,this.apiKey)}}}/**
275
- * @license
276
- * Copyright 2025 Google LLC
277
- * SPDX-License-Identifier: Apache-2.0
278
- */const Xc="gl-node/";class Qc{get interactions(){if(this._interactions!==void 0)return this._interactions;console.warn("GoogleGenAI.interactions: Interactions usage is experimental and may change in future versions.");const e=this.httpOptions;e!=null&&e.extraBody&&console.warn("GoogleGenAI.interactions: Client level httpOptions.extraBody is not supported by the interactions client and will be ignored.");const n=new Q({baseURL:this.apiClient.getBaseUrl(),apiKey:this.apiKey,apiVersion:this.apiClient.getApiVersion(),clientAdapter:this.apiClient,defaultHeaders:this.apiClient.getDefaultHeaders(),timeout:e==null?void 0:e.timeout});return this._interactions=n.interactions,this._interactions}constructor(e){var n;if(e.apiKey==null)throw new Error("An API Key must be set when running in a browser");if(e.project||e.location)throw new Error("Vertex AI project based authentication is not supported on browser runtimes. Please do not provide a project or location.");this.vertexai=(n=e.vertexai)!==null&&n!==void 0?n:!1,this.apiKey=e.apiKey;const o=zi(e.httpOptions,e.vertexai,void 0,void 0);o&&(e.httpOptions?e.httpOptions.baseUrl=o:e.httpOptions={baseUrl:o}),this.apiVersion=e.apiVersion,this.httpOptions=e.httpOptions;const s=new zc(this.apiKey);this.apiClient=new $u({auth:s,apiVersion:this.apiVersion,apiKey:this.apiKey,vertexai:this.vertexai,httpOptions:this.httpOptions,userAgentExtra:Xc+"web",uploader:new Oc,downloader:new Fc}),this.models=new fd(this.apiClient),this.live=new rd(this.apiClient,s,new $c),this.batches=new Sr(this.apiClient),this.chats=new sl(this.models,this.apiClient),this.caches=new nl(this.apiClient),this.files=new ml(this.apiClient),this.operations=new pd(this.apiClient),this.authTokens=new Pd(this.apiClient),this.tunings=new Lc(this.apiClient),this.fileSearchStores=new Fd(this.apiClient)}}const Zc=async(t,e)=>{if(!e)throw new Error("API key is not provided. Please provide an API key to use the AI features.");const n=new Qc({apiKey:e});try{const o="gemini-3-pro-preview",l={text:`Analyze the handwritten formula in the image. Your ONLY task is to return a single, valid line of LaTeX code that represents the formula.
279
-
280
- IMPORTANT RULES:
281
- 1. **SINGLE OUTPUT ONLY:** Provide only one LaTeX transcription. Do NOT give alternatives or variations. For example, if you see a fraction, output '\\frac{a}{b}', not '\\frac{a}{b} or a/b'.
282
- 2. **CODE ONLY:** Your entire response must be ONLY the LaTeX code. No explanations, no introductory text like "Here is the LaTeX:", no markdown, no dollar signs.
283
- 3. **ACCURACY:** Transcribe the symbols and structure as precisely as possible.
284
-
285
- Example: For an image showing 'x squared', your literal output must be: x^2`},a={inlineData:{mimeType:"image/png",data:t}};let c=(await n.models.generateContent({model:o,contents:{parts:[l,a]}})).text;if(!c)throw new Error("API returned no text. The drawing might be unclear or empty.");return c=c.trim().split(`
286
- `)[0],c.startsWith("```latex")?(c=c.substring(7).trim(),c.endsWith("```")&&(c=c.slice(0,-3).trim())):c.startsWith("```")&&(c=c.substring(3).trim(),c.endsWith("```")&&(c=c.slice(0,-3).trim())),c.startsWith("$$")&&c.endsWith("$$")?c=c.substring(2,c.length-2).trim():c.startsWith("$")&&c.endsWith("$")&&(c=c.substring(1,c.length-1).trim()),c}catch(o){throw console.error("Error calling Gemini API:",o),o instanceof Error&&(o.message.includes("API key not valid")||o.message.includes("400"))?new Error("The API key is not valid. Please check your configuration."):new Error("Failed to recognize handwriting. The model may be unavailable or the drawing is unclear.")}},Ei=()=>g.jsxs("span",{className:"text-sm leading-tight flex flex-col items-center text-black -mt-0.5",children:[g.jsx("span",{children:"□"}),g.jsx("span",{className:"w-2 h-px bg-black my-[1px]"}),g.jsx("span",{children:"□"})]}),Ci=()=>g.jsxs("span",{className:"text-black text-lg",children:["√",g.jsx("span",{className:"border-t border-black -ml-1",children:"□"})]}),jc=()=>g.jsxs("span",{className:"text-black text-lg",children:[g.jsx("sup",{className:"-mr-1",children:"□"}),"√",g.jsx("span",{className:"border-t border-black -ml-1",children:"□"})]}),ef=({symbol:t,onInsert:e})=>g.jsx("button",{onClick:()=>e(t.latex),title:t.title||(typeof t.display=="string"?t.display:t.latex),className:`w-8 h-7 bg-white hover:bg-gray-100 border border-transparent hover:border-blue-400 flex items-center justify-center text-black transition-colors text-base rounded ${t.className||""}`,children:t.display}),tf=({onClick:t,isActive:e,children:n,title:o})=>g.jsx("button",{onClick:t,title:o,className:`px-2 h-7 flex items-center justify-center rounded transition-all select-none border ${e?"bg-white text-black border-gray-300 shadow-inner":"bg-transparent text-black border-transparent hover:bg-white/60"}`,children:n}),nf=[{key:"layout",display:g.jsxs("div",{className:"flex items-center gap-1",children:[g.jsx(Ci,{})," ",g.jsx(Ei,{})]}),title:"Layout Templates"},{key:"symbols",display:g.jsx("span",{className:"text-lg",children:"∈∞"}),title:"Symbols"},{key:"arrows",display:g.jsx("span",{className:"text-lg font-mono",children:"→…"}),title:"Arrows"},{key:"greek",display:g.jsx("span",{className:"text-lg",children:"αΩ"}),title:"Greek Symbols"},{key:"matrices",display:g.jsx("span",{className:"text-lg",children:"[□]"}),title:"Matrix Templates"},{key:"fences",display:g.jsx("span",{className:"text-lg",children:"(□)"}),title:"Fences & Accents"},{key:"sums",display:g.jsx("span",{className:"text-lg",children:"Σ∪"}),title:"Sums & Set Theory"},{key:"integrals",display:g.jsx("span",{className:"text-lg",children:"∫ lim"}),title:"Integrals & Functions"}],xi={layout:[[[{display:g.jsx(Ei,{}),latex:"\\frac{}{}"}],[{display:"%",latex:"\\%"}]],[[{display:g.jsx(Ci,{}),latex:"\\sqrt{}"}],[{display:g.jsx(jc,{}),latex:"\\sqrt[]{}"}]],[[{display:"□²",latex:"^{}"}],[{display:"□₂",latex:"_{}"}],[{display:"□₂²",latex:"_{}^{}"}]],[[{display:"(□)",latex:"({})"}],[{display:"[□]",latex:"[]"}],[{display:"{□}",latex:"\\{\\}"}]],[[{display:"|□|",latex:"|{}|"}],[{display:"||□||",latex:"\\|{}|\\|"}]]],symbols:[[[{display:"∅",latex:"\\emptyset"},{display:"+",latex:"+"},{display:"×",latex:"\\times"},{display:"·",latex:"\\cdot"},{display:"π",latex:"\\pi"},{display:"∂",latex:"\\partial"},{display:"°",latex:"^\\circ"}],[{display:"−",latex:"-"},{display:"÷",latex:"\\div"},{display:"/",latex:"/"},{display:"∞",latex:"\\infty"},{display:"Δ",latex:"\\Delta"},{display:"′",latex:"\\prime"}],[{display:"±",latex:"\\pm"},{display:"∓",latex:"\\mp"},{display:"∘",latex:"\\circ"},{display:"ø",latex:"\\o"},{display:"∇",latex:"\\nabla"},{display:"″",latex:"\\prime\\prime"}]],[[{display:"=",latex:"="},{display:"≡",latex:"\\equiv"},{display:">",latex:">"},{display:"<",latex:"<"}],[{display:"≠",latex:"\\neq"},{display:"≈",latex:"\\approx"},{display:"≥",latex:"\\geq"},{display:"≤",latex:"\\leq"}],[{display:"∼",latex:"\\sim"},{display:"≃",latex:"\\simeq"},{display:"≫",latex:"\\gg"},{display:"≪",latex:"\\ll"}]],[[{display:"∈",latex:"\\in"},{display:"∃",latex:"\\exists"},{display:"∧",latex:"\\land"},{display:"∨",latex:"\\lor"}],[{display:"∪",latex:"\\cup"},{display:"∩",latex:"\\cap"},{display:"∀",latex:"\\forall"},{display:"¬",latex:"\\neg"}],[{display:"⊂",latex:"\\subset"},{display:"⊃",latex:"\\supset"},{display:"∃!",latex:"\\exists!"},{display:"⊥",latex:"\\perp"}]],[[{display:"∠",latex:"\\angle"},{display:"□",latex:"\\square"},{display:"⊕",latex:"\\oplus"}],[{display:"∥",latex:"\\parallel"},{display:"△",latex:"\\triangle"},{display:"⊗",latex:"\\otimes"}],[{display:"○",latex:"\\circ"},{display:"⊙",latex:"\\odot"}]]],arrows:[[[{display:"←",latex:"\\leftarrow"},{display:"⇐",latex:"\\Leftarrow"},{display:"↖",latex:"\\nwarrow"}],[{display:"→",latex:"\\rightarrow"},{display:"⇒",latex:"\\Rightarrow"},{display:"↗",latex:"\\nearrow"}],[{display:"↔",latex:"\\leftrightarrow"},{display:"⇔",latex:"\\Leftrightarrow"},{display:"↘",latex:"\\searrow"}],[{display:"↦",latex:"\\mapsto"},{display:"↼",latex:"\\leftharpoonup"},{display:"↙",latex:"\\swarrow"}]],[[{display:"…",latex:"\\dots"},{display:"⋮",latex:"\\vdots"},{display:"⋯",latex:"\\cdots"},{display:"⋱",latex:"\\ddots"}]]],greek:[[[{display:"α",latex:"\\alpha"},{display:"κ",latex:"\\kappa"},{display:"σ",latex:"\\sigma"}],[{display:"β",latex:"\\beta"},{display:"λ",latex:"\\lambda"},{display:"τ",latex:"\\tau"}],[{display:"γ",latex:"\\gamma"},{display:"μ",latex:"\\mu"},{display:"υ",latex:"\\upsilon"}],[{display:"δ",latex:"\\delta"},{display:"ν",latex:"\\nu"},{display:"φ",latex:"\\phi"}],[{display:"ε",latex:"\\epsilon"},{display:"ξ",latex:"\\xi"},{display:"χ",latex:"\\chi"}],[{display:"ζ",latex:"\\zeta"},{display:"ο",latex:"\\omicron"},{display:"ψ",latex:"\\psi"}],[{display:"η",latex:"\\eta"},{display:"π",latex:"\\pi"},{display:"ω",latex:"\\omega"}],[{display:"θ",latex:"\\theta"},{display:"ρ",latex:"\\rho"}],[{display:"ι",latex:"\\iota"},{display:"ς",latex:"\\varsigma"}]],[[{display:"Α",latex:"A"},{display:"Κ",latex:"K"},{display:"Σ",latex:"\\Sigma"}],[{display:"Β",latex:"B"},{display:"Λ",latex:"\\Lambda"},{display:"Τ",latex:"T"}],[{display:"Γ",latex:"\\Gamma"},{display:"Μ",latex:"M"},{display:"Υ",latex:"\\Upsilon"}],[{display:"Δ",latex:"\\Delta"},{display:"Ν",latex:"N"},{display:"Φ",latex:"\\Phi"}],[{display:"Ε",latex:"E"},{display:"Ξ",latex:"\\Xi"},{display:"Χ",latex:"X"}],[{display:"Ζ",latex:"Z"},{display:"Ο",latex:"O"},{display:"Ψ",latex:"\\Psi"}],[{display:"Η",latex:"H"},{display:"Π",latex:"\\Pi"},{display:"Ω",latex:"\\Omega"}],[{display:"Θ",latex:"\\Theta"},{display:"Ρ",latex:"P"}],[{display:"Ι",latex:"I"},{display:"Σ",latex:"\\Sigma"}]]],matrices:[[[{display:"[□]",latex:"\\begin{bmatrix} {} \\end{bmatrix}"},{display:"(□)",latex:"\\begin{pmatrix} {} \\end{pmatrix}"},{display:"|□|",latex:"\\begin{vmatrix} {} \\end{vmatrix}"},{display:"||□||",latex:"\\begin{Vmatrix} {} \\end{Vmatrix}"}],[{display:"[□,□]",latex:"\\begin{bmatrix} {} & {} \\end{bmatrix}"},{display:"(□,□)",latex:"\\begin{pmatrix} {} & {} \\end{pmatrix}"}],[{display:"[□;□]",latex:"\\begin{bmatrix} {} \\\\ {} \\end{bmatrix}"},{display:"(□;□)",latex:"\\begin{pmatrix} {} \\\\ {} \\end{pmatrix}"}]],[[{display:"[::]",latex:"\\begin{bmatrix} {} & {} \\\\ {} & {} \\end{bmatrix}"}],[{display:"⋮",latex:"\\vdots"},{display:"⋯",latex:"\\cdots"},{display:"⋱",latex:"\\ddots"}]]],fences:[[[{display:"(□)",latex:"({})"},{display:"|□|",latex:"|{}|"},{display:"⟨□⟩",latex:"\\langle {} \\rangle"}],[{display:"[□]",latex:"[{}]"},{display:"||□||",latex:"\\|{}|\\|"},{display:"{□}",latex:"\\{{}\\}"}]],[[{display:"◯",latex:"\\enclose{circle}{}"},{display:"□",latex:"\\enclose{box}{}"},{display:"╱",latex:"\\enclose{updiagonalstrike}{}"},{display:"⃫",latex:"\\enclose{updiagonalstrike,downdiagonalstrike}{}"}],[{display:"()",latex:"\\enclose{actuarial}{}"},{display:"╳",latex:"\\enclose{downdiagonalstrike}{}"},{display:"│",latex:"\\enclose{verticalstrike}{}"},{display:"─",latex:"\\enclose{horizontalstrike}{}"}]],[[{display:g.jsx("span",{className:"text-xl",children:"ô"}),latex:"\\hat{}"},{display:g.jsx("span",{className:"text-xl",children:"ō"}),latex:"\\bar{}"},{display:g.jsx("span",{className:"text-xl",children:"ò"}),latex:"\\vec{}"}],[{display:g.jsx("span",{className:"text-xl",children:"õ"}),latex:"\\tilde{}"},{display:g.jsx("span",{className:"text-xl",children:"ó"}),latex:"\\acute{}"},{display:g.jsx("span",{className:"text-xl",children:"ö"}),latex:"\\ddot{}"}]]],sums:[[[{display:"∑",latex:"\\sum"},{display:"∑ límites",latex:"\\sum_{}^{}"}],[{display:"∏",latex:"\\prod"},{display:"∏ límites",latex:"\\prod_{}^{}"}],[{display:"∐",latex:"\\coprod"},{display:"∐ límites",latex:"\\coprod_{}^{}"}]],[[{display:"∪",latex:"\\cup"},{display:"∩",latex:"\\cap"}],[{display:"⋃",latex:"\\bigcup"},{display:"⋂",latex:"\\bigcap"}]]],integrals:[[[{display:"∫",latex:"\\int"},{display:"∫ límites",latex:"\\int_{}^{}"}],[{display:"∬",latex:"\\iint"},{display:"∬ límites",latex:"\\iint_{}^{}"}],[{display:"∮",latex:"\\oint"},{display:"∮ límites",latex:"\\oint_{}^{}"}],[{display:"∯",latex:"\\oiint"},{display:"∯ límites",latex:"\\oiint_{}^{}"}]],[[{display:"d",latex:"d"},{display:"∂",latex:"\\partial"},{display:"∇",latex:"\\nabla"},{display:"Δ",latex:"\\Delta"}]],[[{display:"lim",latex:"\\lim"},{display:"lim →",latex:"\\lim_{x \\to {} }"}]],[[{display:"sin",latex:"\\sin"},{display:"cos",latex:"\\cos"},{display:"tan",latex:"\\tan"}],[{display:"log",latex:"\\log"},{display:"log base",latex:"\\log_{}"},{display:"ln",latex:"\\ln"}]]],products:[]},of=({onInsert:t})=>{const[e,n]=N.useState("layout");return g.jsxs("div",{className:"bg-[#e9eff1] px-2 py-1 flex flex-col space-y-1 shrink-0 border-b border-gray-300",children:[g.jsxs("div",{className:"flex flex-wrap gap-1 items-center",children:[nf.map(o=>g.jsx(tf,{onClick:()=>n(o.key),isActive:e===o.key,title:o.title,children:o.display},o.key)),g.jsx("div",{className:"flex-grow"}),g.jsx("button",{title:"Help",className:"w-8 h-8 rounded-full bg-gray-400 hover:bg-gray-500 text-white flex items-center justify-center shadow-sm transition-all",children:g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})]}),g.jsxs("div",{className:"flex items-start bg-white rounded border border-gray-300 min-h-[5rem] shadow-inner p-1 overflow-x-auto",children:[g.jsx("div",{className:"flex items-start",children:xi[e].map((o,s)=>g.jsxs(N.Fragment,{children:[g.jsx("div",{className:"flex flex-col",children:o.map((l,a)=>g.jsx("div",{className:"flex",children:l.map((u,c)=>g.jsx(ef,{symbol:u,onInsert:t},c))},a))}),s<xi[e].length-1&&g.jsx("div",{className:"w-px bg-gray-300 mx-1 self-stretch"})]},s))}),g.jsx("div",{className:"flex-grow"}),g.jsx("div",{className:"flex items-center space-x-2 shrink-0 self-center pr-2",children:g.jsxs("div",{className:"flex flex-col space-y-1",children:[g.jsx("select",{disabled:!0,className:"text-sm border border-gray-300 rounded h-6 w-32 px-1 text-black opacity-50",children:g.jsx("option",{children:"Font..."})}),g.jsx("select",{disabled:!0,className:"text-sm border border-gray-300 rounded h-6 w-32 px-1 text-black opacity-50",children:g.jsx("option",{children:"Size..."})})]})})]})]})},sf=({symbol:t,onInsert:e})=>g.jsx("button",{onClick:()=>e(t.latex),title:t.title||(typeof t.display=="string"?t.display:t.latex),className:`w-8 h-7 bg-white hover:bg-gray-100 border border-transparent hover:border-blue-400 flex items-center justify-center text-black transition-colors text-base rounded ${t.className||""}`,children:t.display}),rf=({onClick:t,isActive:e,children:n,title:o})=>g.jsx("button",{onClick:t,title:o,className:`px-2 h-7 flex items-center justify-center rounded transition-all select-none border ${e?"bg-white text-black border-gray-300 shadow-inner":"bg-transparent text-black border-transparent hover:bg-white/60"}`,children:n}),lf=[{key:"chem",display:g.jsx("span",{className:"text-base",children:"H₂O"}),title:"Chemistry"},{key:"symbols",display:g.jsx("span",{className:"text-lg",children:"∈∞"}),title:"Symbols"},{key:"arrows",display:g.jsx("span",{className:"text-lg font-mono",children:"→…"}),title:"Arrows"},{key:"greek",display:g.jsx("span",{className:"text-lg",children:"αΩ"}),title:"Greek Symbols"},{key:"matrices",display:g.jsx("span",{className:"text-lg",children:"[□]"}),title:"Matrix Templates"},{key:"fences",display:g.jsx("span",{className:"text-lg",children:"(□)"}),title:"Fences & Accents"}],Si={chem:[[[{display:"H",latex:"H"},{display:"C",latex:"C"}],[{display:"N",latex:"N"},{display:"O",latex:"O"}],[{display:"F",latex:"F"},{display:"S",latex:"S"}]],[[{display:"°",latex:"^{\\circ}"}],[{display:"Δ",latex:"\\Delta "}],[{display:"mol",latex:"\\text{mol}"}]],[[{display:"→",latex:"\\rightarrow "}],[{display:"⇌",latex:"\\rightleftharpoons"}],[{display:"↔",latex:"\\leftrightarrow "}]],[[{display:g.jsxs("span",{className:"text-lg",children:["→",g.jsx("sup",{className:"-top-1.5 text-[8px]",children:"□"})]}),latex:"\\xrightarrow{}"}],[{display:g.jsxs("span",{className:"text-lg",children:["⇌",g.jsx("sup",{className:"-top-1.5 text-[8px]",children:"□"})]}),latex:"\\xrightleftharpoons{}"}]],[[{display:"□²",latex:"^{}"}],[{display:"□₂",latex:"_{}"}],[{display:"□₂²",latex:"_{}^{}"}]],[[{display:"(□)",latex:"({})"}],[{display:"[□]",latex:"[]"}],[{display:"{□}",latex:"\\{\\}"}]]],symbols:[[[{display:"∅",latex:"\\emptyset"},{display:"+",latex:"+"},{display:"×",latex:"\\times"},{display:"·",latex:"\\cdot"},{display:"π",latex:"\\pi"},{display:"∂",latex:"\\partial"},{display:"°",latex:"^\\circ"}],[{display:"−",latex:"-"},{display:"÷",latex:"\\div"},{display:"/",latex:"/"},{display:"∞",latex:"\\infty"},{display:"Δ",latex:"\\Delta"},{display:"′",latex:"\\prime"}],[{display:"±",latex:"\\pm"},{display:"∓",latex:"\\mp"},{display:"∘",latex:"\\circ"},{display:"ø",latex:"\\o"},{display:"∇",latex:"\\nabla"},{display:"″",latex:"\\prime\\prime"}]],[[{display:"=",latex:"="},{display:"≡",latex:"\\equiv"},{display:">",latex:">"},{display:"<",latex:"<"}],[{display:"≠",latex:"\\neq"},{display:"≈",latex:"\\approx"},{display:"≥",latex:"\\geq"},{display:"≤",latex:"\\leq"}],[{display:"∼",latex:"\\sim"},{display:"≃",latex:"\\simeq"},{display:"≫",latex:"\\gg"},{display:"≪",latex:"\\ll"}]],[[{display:"∈",latex:"\\in"},{display:"∃",latex:"\\exists"},{display:"∧",latex:"\\land"},{display:"∨",latex:"\\lor"}],[{display:"∪",latex:"\\cup"},{display:"∩",latex:"\\cap"},{display:"∀",latex:"\\forall"},{display:"¬",latex:"\\neg"}],[{display:"⊂",latex:"\\subset"},{display:"⊃",latex:"\\supset"},{display:"∃!",latex:"\\exists!"},{display:"⊥",latex:"\\perp"}]]],arrows:[[[{display:"←",latex:"\\leftarrow"},{display:"⇐",latex:"\\Leftarrow"},{display:"↖",latex:"\\nwarrow"}],[{display:"→",latex:"\\rightarrow"},{display:"⇒",latex:"\\Rightarrow"},{display:"↗",latex:"\\nearrow"}],[{display:"↔",latex:"\\leftrightarrow"},{display:"⇔",latex:"\\Leftrightarrow"},{display:"↘",latex:"\\searrow"}],[{display:"↦",latex:"\\mapsto"},{display:"↼",latex:"\\leftharpoonup"},{display:"↙",latex:"\\swarrow"}]],[[{display:"…",latex:"\\dots"},{display:"⋮",latex:"\\vdots"},{display:"⋯",latex:"\\cdots"},{display:"⋱",latex:"\\ddots"}]]],greek:[[[{display:"α",latex:"\\alpha"},{display:"κ",latex:"\\kappa"},{display:"σ",latex:"\\sigma"}],[{display:"β",latex:"\\beta"},{display:"λ",latex:"\\lambda"},{display:"τ",latex:"\\tau"}],[{display:"γ",latex:"\\gamma"},{display:"μ",latex:"\\mu"},{display:"υ",latex:"\\upsilon"}],[{display:"δ",latex:"\\delta"},{display:"ν",latex:"\\nu"},{display:"φ",latex:"\\phi"}],[{display:"ε",latex:"\\epsilon"},{display:"ξ",latex:"\\xi"},{display:"χ",latex:"\\chi"}],[{display:"ζ",latex:"\\zeta"},{display:"ο",latex:"\\omicron"},{display:"ψ",latex:"\\psi"}],[{display:"η",latex:"\\eta"},{display:"π",latex:"\\pi"},{display:"ω",latex:"\\omega"}],[{display:"θ",latex:"\\theta"},{display:"ρ",latex:"\\rho"}]],[[{display:"Α",latex:"A"},{display:"Κ",latex:"K"},{display:"Σ",latex:"\\Sigma"}],[{display:"Β",latex:"B"},{display:"Λ",latex:"\\Lambda"},{display:"Τ",latex:"T"}],[{display:"Γ",latex:"\\Gamma"},{display:"Μ",latex:"M"},{display:"Υ",latex:"\\Upsilon"}],[{display:"Δ",latex:"\\Delta"},{display:"Ν",latex:"N"},{display:"Φ",latex:"\\Phi"}]]],matrices:[[[{display:"[::]",latex:"\\begin{bmatrix} {} & {} \\\\ {} & {} \\end{bmatrix}"}],[{display:"⋮",latex:"\\vdots"},{display:"⋯",latex:"\\cdots"},{display:"⋱",latex:"\\ddots"}]]],fences:[[[{display:"(□)",latex:"({})"},{display:"|□|",latex:"|{}|"},{display:"⟨□⟩",latex:"\\langle {} \\rangle"}],[{display:"[□]",latex:"[{}]"},{display:"||□||",latex:"\\|{}|\\|"},{display:"{□}",latex:"\\{{}\\}"}]],[[{display:g.jsx("span",{className:"text-xl",children:"ô"}),latex:"\\hat{}"},{display:g.jsx("span",{className:"text-xl",children:"ō"}),latex:"\\bar{}"},{display:g.jsx("span",{className:"text-xl",children:"ò"}),latex:"\\vec{}"}]]]},af=({onInsert:t})=>{const[e,n]=N.useState("chem");return g.jsxs("div",{className:"bg-[#e9eff1] px-2 py-1 flex flex-col space-y-1 shrink-0 border-b border-gray-300",children:[g.jsxs("div",{className:"flex flex-wrap gap-1 items-center",children:[lf.map(o=>g.jsx(rf,{onClick:()=>n(o.key),isActive:e===o.key,title:o.title,children:o.display},o.key)),g.jsx("div",{className:"flex-grow"}),g.jsx("button",{title:"Help",className:"w-8 h-8 rounded-full bg-gray-400 hover:bg-gray-500 text-white flex items-center justify-center shadow-sm transition-all",children:g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})})]}),g.jsxs("div",{className:"flex items-start bg-white rounded border border-gray-300 min-h-[5rem] shadow-inner p-1 overflow-x-auto",children:[g.jsx("div",{className:"flex items-start",children:Si[e].map((o,s)=>g.jsxs(N.Fragment,{children:[g.jsx("div",{className:"flex flex-col",children:o.map((l,a)=>g.jsx("div",{className:"flex",children:l.map((u,c)=>g.jsx(sf,{symbol:u,onInsert:t},c))},a))}),s<Si[e].length-1&&g.jsx("div",{className:"w-px bg-gray-300 mx-1 self-stretch"})]},s))}),g.jsx("div",{className:"flex-grow"}),g.jsx("div",{className:"flex items-center space-x-2 shrink-0 self-center pr-2",children:g.jsxs("div",{className:"flex flex-col space-y-1",children:[g.jsx("select",{disabled:!0,className:"text-sm border border-gray-300 rounded h-6 w-32 px-1 text-black opacity-50",children:g.jsx("option",{children:"Font..."})}),g.jsx("select",{disabled:!0,className:"text-sm border border-gray-300 rounded h-6 w-32 px-1 text-black opacity-50",children:g.jsx("option",{children:"Size..."})})]})})]})]})},uf=({isOpen:t,onClose:e,onInsert:n,apiKey:o=""})=>{const s=N.useRef(null),l=N.useRef(null),[a,u]=N.useState(!1),[c,d]=N.useState(null),[f,h]=N.useState(""),[p,m]=N.useState("keyboard"),[T,E]=N.useState("math"),[v,S]=N.useState(!1),[_,C]=N.useState(!1),[x,R]=N.useState(""),[M,k]=N.useState(!1);N.useEffect(()=>{if(p==="keyboard"&&f.trim()&&window.katex)try{const D=window.katex.renderToString(f,{throwOnError:!0,displayMode:!1,output:"mathml"});R(D),k(!0)}catch(D){const W=D instanceof Error?D.message.replace(/</g,"&lt;"):"Invalid LaTeX";R(`<span style="color: red; font-size: 0.75rem;">${W}</span>`),k(!1)}else R(""),k(!1)},[f,p]);const V=D=>{E(D),D==="chem"&&m("keyboard")},w=N.useCallback(()=>{var D;(D=s.current)==null||D.clear(),h(""),d(null),u(!1)},[]),L=N.useCallback(()=>{w(),e()},[w,e]),B=N.useCallback(({canUndo:D,canRedo:W})=>{S(D),C(W)},[]),$=N.useCallback(D=>{const W=l.current;if(!W){h(Fe=>Fe+D);return}const K=W.selectionStart,se=W.selectionEnd,we=f,Le=we.substring(0,K)+D+we.substring(se);h(Le),setTimeout(()=>{W.focus();let pe=Le.indexOf("{}",K);pe===-1?pe=K+D.length:pe=pe+1,W.selectionStart=pe,W.selectionEnd=pe},0)},[f]),F=N.useCallback(async()=>{var W;if(!o){d("API key is not configured. Please provide an API key to use the AI Math Pad feature.");return}if(!s.current)return;const D=s.current.getTrimmedImageData();if(!D){d("Please draw something before recognizing.");return}u(!0),d(null);try{const K=D.split(",")[1],se=await Zc(K,o);$(se+" "),m("keyboard"),(W=s.current)==null||W.clear()}catch(K){d(K instanceof Error?K.message:"An unknown error occurred.")}finally{u(!1)}},[o,$]),O=N.useCallback(()=>{M&&x?(n(x),L()):d(f&&!M?"The current LaTeX is invalid and cannot be inserted.":"There is no formula to insert.")},[n,L,f,M,x]);return N.useEffect(()=>{d(null)},[f,p,T]),t?g.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50 backdrop-blur-sm p-4",tabIndex:-1,role:"dialog","aria-modal":"true",children:g.jsxs("div",{className:"bg-[#e9eff1] rounded-lg shadow-2xl flex flex-col w-full max-w-5xl h-auto max-h-[95vh] border border-gray-400 overflow-hidden",onClick:D=>D.stopPropagation(),children:[g.jsxs("header",{className:"bg-[#778e9a] text-black px-3 py-1 flex justify-between items-center select-none shrink-0 relative",children:[g.jsx("h6",{className:"text-[14px] font-bold",children:T==="math"?"Sweraty Math Pad":"Sweraty Chem Pad"}),g.jsxs("div",{className:"absolute left-1/2 -translate-x-1/2 bg-[#556e7b] p-0.5 rounded-md flex items-center",children:[g.jsx("button",{onClick:()=>V("math"),className:`px-3 py-0.5 text-xs rounded-sm transition-all ${T==="math"?"bg-white text-black font-semibold shadow":"bg-transparent text-gray-200 hover:bg-white/20"}`,children:"Math"}),g.jsx("button",{onClick:()=>V("chem"),className:`px-3 py-0.5 text-xs rounded-sm transition-all ${T==="chem"?"bg-white text-black font-semibold shadow":"bg-transparent text-gray-200 hover:bg-white/20"}`,children:"Chemistry"})]}),g.jsxs("div",{className:"flex items-center space-x-5",children:[g.jsx("button",{className:"text-black hover:opacity-80 transition-opacity","aria-label":"Minimize",children:g.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M20 12H4"})})}),g.jsx("button",{onClick:L,className:"text-black hover:opacity-80 transition-opacity p-1 -mr-1","aria-label":"Close",children:g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]})]}),p==="keyboard"&&(T==="math"?g.jsx(of,{onInsert:$}):g.jsx(af,{onInsert:$})),g.jsxs("div",{className:"flex flex-grow overflow-hidden",children:[g.jsx("div",{className:"flex-grow p-2 relative h-[25rem] sm:h-[30rem]",children:p==="keyboard"?g.jsxs(g.Fragment,{children:[g.jsx("textarea",{ref:l,value:f,onChange:D=>h(D.target.value),className:"w-full h-full p-4 border border-gray-300 rounded shadow-inner text-black outline-none focus:ring-2 focus:ring-blue-400 font-mono text-lg resize-none placeholder-gray-500",placeholder:`Type ${T==="math"?"LaTeX":"Chem Formula"} here...`}),x&&g.jsx("div",{className:"absolute bottom-4 right-4 bg-white bg-opacity-90 p-2 border border-gray-200 rounded shadow-lg max-w-sm overflow-x-auto z-10 transition-all text-black",children:g.jsx("div",{dangerouslySetInnerHTML:{__html:x}})})]}):g.jsxs("div",{className:"w-full h-full border border-gray-300 bg-white relative rounded shadow-inner overflow-hidden",children:[g.jsx("div",{className:"absolute inset-0 pointer-events-none opacity-20",style:{backgroundImage:"linear-gradient(#c8c8c8 1px, transparent 1px), linear-gradient(90deg, #c8c8c8 1px, transparent 1px)",backgroundSize:"20px 20px"}}),g.jsx($t,{ref:s,onHistoryChange:B}),g.jsxs("div",{className:"absolute bottom-2 left-2 flex gap-2",children:[g.jsx("button",{onClick:F,disabled:a,className:"px-4 py-1.5 bg-white border border-gray-300 hover:bg-gray-100 text-black rounded shadow-sm text-sm font-semibold transition-colors disabled:opacity-50",children:a?"Recognizing...":"Recognize"}),g.jsx("button",{onClick:()=>{var D;return(D=s.current)==null?void 0:D.clear()},className:"px-4 py-1.5 bg-white border border-gray-300 hover:bg-gray-100 text-black rounded shadow-sm text-sm font-semibold transition-colors",children:"Clear"})]}),g.jsxs("div",{className:"absolute top-2 right-2 flex flex-col gap-1",children:[g.jsx("button",{onClick:()=>{var D;return(D=s.current)==null?void 0:D.undo()},disabled:!v,className:"p-1.5 bg-white border border-gray-300 hover:bg-gray-100 text-black disabled:opacity-30 rounded shadow-sm",children:g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M10 19l-7-7m0 0l7-7m-7 7h18"})})}),g.jsx("button",{onClick:()=>{var D;return(D=s.current)==null?void 0:D.redo()},disabled:!_,className:"p-1.5 bg-white border border-gray-300 hover:bg-gray-100 text-black disabled:opacity-30 rounded shadow-sm",children:g.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M14 5l7 7m0 0l-7 7m7-7H3"})})})]})]})}),T==="math"&&g.jsxs("div",{className:"w-14 sm:w-16 flex flex-col items-center py-2 space-y-2 border-l border-gray-300 shrink-0",children:[g.jsx("button",{onClick:()=>m("keyboard"),title:"Keyboard",className:`p-2 rounded-lg shadow-sm transition-all ${p==="keyboard"?"bg-[#556e7b] text-black scale-110":"bg-gray-200 text-black hover:bg-gray-300"}`,children:g.jsxs("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M8 3H16a2 2 0 012 2v14a2 2 0 01-2 2H8a2 2 0 01-2-2V5a2 2 0 012-2z"}),g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 18h.01M8 14h8"})]})}),g.jsx("button",{onClick:()=>m("handwriting"),title:"Handwriting",className:`p-2 rounded-lg shadow-sm transition-all ${p==="handwriting"?"bg-[#556e7b] text-black scale-110":"bg-gray-200 text-black hover:bg-gray-300"}`,children:g.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[g.jsx("path",{d:"M3 12h2l4 8 4-16h6"}),g.jsx("path",{d:"m17 8 4 4"}),g.jsx("path",{d:"m21 8-4 4"})]})})]})]}),c&&g.jsx("div",{className:"bg-red-100 border-t border-red-200 text-red-700 px-4 py-1.5 text-center text-sm font-medium",children:c}),g.jsxs("footer",{className:"p-2 border-t border-gray-300 flex justify-end space-x-2 bg-gray-50 shrink-0",children:[g.jsx("button",{onClick:O,disabled:!M,className:"px-6 py-1.5 bg-[#556e7b] hover:bg-[#435964] text-black rounded font-bold shadow transition-colors disabled:opacity-50",children:"Insert"}),g.jsx("button",{onClick:L,className:"px-6 py-1.5 bg-white border border-gray-300 hover:bg-gray-100 text-black rounded font-bold shadow-sm transition-colors",children:"Cancel"})]})]})}):null},df=50,Ii=N.forwardRef(({initialContent:t="",onChange:e,apiKey:n},o)=>{const s=N.useRef(null),[l,a]=N.useState(!1),u=N.useRef(null),[c,d]=N.useState([t]),[f,h]=N.useState(0),p=f>0,m=f<c.length-1;N.useImperativeHandle(o,()=>({getContent:()=>{var x;return((x=s.current)==null?void 0:x.innerHTML)||""},setContent:x=>{s.current&&(s.current.innerHTML=x,T(x))}}));const T=N.useCallback(x=>{if(x===c[f])return;const R=c.slice(0,f+1);for(R.push(x);R.length>df;)R.shift();d(R),h(R.length-1),e==null||e(x)},[c,f,e]);N.useEffect(()=>{s.current&&t&&s.current.innerHTML!==t&&(s.current.innerHTML=t)},[t]);const E=(x,R)=>{s.current&&(s.current.focus(),document.execCommand(x,!1,R),T(s.current.innerHTML))},v=()=>{if(p){const x=f-1;h(x),s.current&&(s.current.innerHTML=c[x],e==null||e(c[x]))}},S=()=>{if(m){const x=f+1;h(x),s.current&&(s.current.innerHTML=c[x],e==null||e(c[x]))}},_=x=>{if(s.current){s.current.focus();const R=`<span contenteditable="false" class="math-container" style="display: inline-block; white-space: nowrap; font-size: 1.1em;">${x}</span>&nbsp;`;document.execCommand("insertHTML",!1,R),a(!1),T(s.current.innerHTML)}},C=()=>{u.current&&clearTimeout(u.current),u.current=window.setTimeout(()=>{s.current&&T(s.current.innerHTML)},400)};return g.jsxs("div",{className:"w-full max-w-5xl mx-auto bg-white rounded-xl shadow-xl border border-slate-200 overflow-hidden flex flex-col min-h-[600px]",children:[g.jsx(Yi,{onApplyStyle:E,onOpenHandwritingModal:()=>a(!0),onUndo:v,onRedo:S,canUndo:p,canRedo:m}),g.jsx("div",{ref:s,contentEditable:!0,onInput:C,className:"flex-1 p-8 outline-none text-slate-800 prose prose-slate max-w-none text-lg leading-relaxed",style:{minHeight:"70vh"}}),l&&g.jsx(uf,{isOpen:l,onClose:()=>a(!1),onInsert:_,apiKey:n})]})});Ii.displayName="Editor",ge.Editor=Ii,Object.defineProperty(ge,Symbol.toStringTag,{value:"Module"})});