@adaline/vertex 1.10.7 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ Message: ${ys(n)}`),this.name=kt,this.info=t,this.cause=n,this.name=i!=null?i:kt
|
|
|
12
12
|
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),n.forEach(r=>{if(!Object.keys(this.modelSchema.roles).includes(r.role))throw new C({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${r.role}',
|
|
13
13
|
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}),n.forEach(r=>{r.content=r.content.filter(d=>d.modality!=="error"&&d.modality!=="search-result");});let i={parts:[]},s=[];if(n.forEach(r=>{switch(r.role){case Ee:r.content.forEach(d=>{if(d.modality===B)i.parts.push({text:d.value});else throw new C({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${d.modality}'`)})});break;case E:{let d=[];r.content.forEach(l=>{if(l.modality===B)d.push({text:l.value});else if(l.modality===Y)d.push({function_call:{name:l.name,args:JSON.parse(l.arguments)}});else if(l.modality===ge)l.value.type==="thinking"&&l.value.thinking&&d.push({text:l.value.thinking,thought:!0,thought_signature:l.value.signature});else throw new C({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],parts:d});}break;case Q:{let d=[];r.content.forEach(l=>{if(l.modality===B)d.push({text:l.value});else if(l.modality===le){if(l.value.type==="base64"){let p=l.value.base64;p=t(p),d.push({inline_data:{mime_type:`image/${l.value.mediaType}`,data:p}});}else if(l.value.type==="url")throw new C({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${l.value.type}'`)})}else if(l.modality===ue)if(l.value.type==="base64"){let p=l.value.base64;p=t(p),d.push({inline_data:{mime_type:"application/pdf",data:p}});}else l.value.type==="url"&&d.push({file_data:{mime_type:"application/pdf",file_uri:l.value.url}});else throw new C({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],parts:d});}break;case re:{let d=[];r.content.forEach(l=>{if(l.modality===me)d.push({function_response:{name:l.name,response:JSON.parse(l.data)}});else throw new C({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${l.modality}'`)})}),s.push({role:this.modelSchema.roles[r.role],parts:d});}break;default:throw new C({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' is not supported,
|
|
14
14
|
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),s[0].role!==this.modelSchema.roles[Q])throw new C({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let m=r=>r===this.modelSchema.roles[Q]||r===this.modelSchema.roles[re]?[this.modelSchema.roles[E]]:[this.modelSchema.roles[Q],this.modelSchema.roles[re]];for(let r=1;r<s.length;r++)if(!m(s[r-1].role).includes(s[r].role))throw new C({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${s[r].role}' after message with role : '${s[r-1].role}'`)});if(s[s.length-1].role!==this.modelSchema.roles[Q]&&s[s.length-1].role!==this.modelSchema.roles[re])throw new C({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return S({contents:s},i.parts.length>0?{system_instruction:i}:{})}stripAdditionalProperties(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(n=>this.stripAdditionalProperties(n));let t={};for(let[n,i]of Object.entries(e))n!=="additionalProperties"&&(t[n]=this.stripAdditionalProperties(i));return t}transformTools(e,t){if(!this.modelSchema.modalities.includes(Y))throw new $t({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${Y}'`)});if((!e||e.length===0)&&!(t!=null&&t.googleSearchTool))return {tools:[]};let n=(e!=null?e:[]).map(i=>{let s=Cn().safeParse(i);if(!s.success)throw new $t({info:"Invalid tools",cause:s.error});return s.data}).map(i=>({name:i.definition.schema.name,description:i.definition.schema.description,parameters:this.stripAdditionalProperties(i.definition.schema.parameters)}));return {tools:[S(S({},n.length>0?{function_declarations:n}:{}),t!=null&&t.googleSearchTool?{google_search:{}}:{})]}}getCompleteChatUrl(e,t,n){return j(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(e,t,n){return j(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getCompleteChatData(e,t,n){return j(this,null,function*(){let i=this.transformConfig(e,t,n),s=yield this.transformPdfMessages(t),m=this.transformMessages(s);if(m.messages&&m.messages.length===0)throw new C({info:"Messages are required",cause:new Error("Messages are required")});let r=this.transformTools(n||[],e);return S(S(S(S({},this.getDefaultParams()),i),m),r)})}transformCompleteChatResponse(e){var t,n,i,s,m,r;let d=Fr.safeParse(e);if(d.success){if(d.data.candidates.length===0)throw new H({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(d.data)}`)});let l={messages:[],usage:void 0,logProbs:void 0},p=d.data;p.usageMetadata&&(l.usage={promptTokens:p.usageMetadata.promptTokenCount,totalTokens:p.usageMetadata.totalTokenCount,completionTokens:p.usageMetadata.candidatesTokenCount||0});let h=p.candidates[0];if(h.content){let u=h.content.parts.map((g,f)=>{if("text"in g&&g.text!==void 0)return g.thought===!0?On(g.text,""):wn(g.text);if("functionCall"in g&&g.functionCall!==void 0)return Gn(f,`${g.functionCall.name}_${f}`,g.functionCall.name,JSON.stringify(g.functionCall.args))});l.messages.push({role:E,content:u});}h.groundingMetadata&&(l.messages.length===0?l.messages.push({role:E,content:[Ut(((t=h.groundingMetadata.webSearchQueries)==null?void 0:t[0])||"",((n=h.groundingMetadata.groundingChunks)==null?void 0:n.map(u=>{var g,f;return {source:u.web?"web":"",url:((g=u.web)==null?void 0:g.uri)||"",title:((f=u.web)==null?void 0:f.title)||""}}))||[],((i=h.groundingMetadata.groundingSupports)==null?void 0:i.map(u=>{var g,f,_;return {text:((g=u.segment)==null?void 0:g.text)||"",responseIndices:u.groundingChunkIndices||[],startIndex:((f=u.segment)==null?void 0:f.startIndex)||void 0,endIndex:((_=u.segment)==null?void 0:_.endIndex)||void 0,confidenceScores:u.confidenceScores||void 0}}))||[])]}):l.messages[0].content.push(Ut(((s=h.groundingMetadata.webSearchQueries)==null?void 0:s[0])||"",((m=h.groundingMetadata.groundingChunks)==null?void 0:m.map(u=>{var g,f;return {source:u.web?"web":"",url:((g=u.web)==null?void 0:g.uri)||"",title:((f=u.web)==null?void 0:f.title)||""}}))||[],((r=h.groundingMetadata.groundingSupports)==null?void 0:r.map(u=>{var g,f,_;return {text:((g=u.segment)==null?void 0:g.text)||"",responseIndices:u.groundingChunkIndices||[],startIndex:((f=u.segment)==null?void 0:f.startIndex)||void 0,endIndex:((_=u.segment)==null?void 0:_.endIndex)||void 0,confidenceScores:u.confidenceScores||void 0}}))||[])));let y=h.safetyRatings;if(y&&y.length>0&&y.forEach(u=>{u.blocked&&(l.messages.length===0?l.messages.push({role:E,content:[Lt(u.category,u.probability,u.blocked,`Blocked content for category: ${u.category} with probability: ${u.probability}`)]}):l.messages[0].content.push(Lt(u.category,u.probability,u.blocked,`Blocked content for category: ${u.category} with probability: ${u.probability}`)));}),l.messages.length>0)return l;if(l.messages.length===0&&h.finishReason==="SAFETY")throw new H({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new H({info:"Invalid response from model",cause:d.error})}getStreamChatUrl(e,t,n){return j(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(e,t,n){return j(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getStreamChatData(e,t,n){return j(this,null,function*(){let i=this.transformConfig(e,t,n),s=yield this.transformPdfMessages(t),m=this.transformMessages(s);if(m.messages&&m.messages.length===0)throw new C({info:"Messages are required",cause:new Error("Messages are required")});let r=this.transformTools(n||[],e);return S(S(S(S({},this.getDefaultParams()),i),m),r)})}transformStreamChatResponseChunk(e,t){return di(this,null,function*(){var n,i,s;let m=(t+e).split(",\r").filter(r=>r.trim()!=="");for(let r of m){let d=r;if(d=d.replace(/\n/g,""),d.startsWith("[")||d.startsWith(",{"))d=d.slice(1);else if(d.endsWith("]")){if(d==="]")return;d=d.slice(0,-1);}let l;try{l=JSON.parse(d);}catch(h){if(h instanceof SyntaxError){t=d;continue}else throw h}t="";let p=ci.safeParse(l);if(p.success){let h={partialMessages:[]},y=p.data;if(y.candidates.length>0){let u=y.candidates[0].content;u&&"parts"in u&&u.parts.length>0&&u.parts.forEach((g,f)=>{if("text"in g&&g.text!==void 0&&(g.thought===!0?h.partialMessages.push(Ft(E,g.text,"")):h.partialMessages.push(It(E,g.text))),"functionCall"in g&&g.functionCall!==void 0){let _=g.functionCall;h.partialMessages.push(jt(E,f,`${_.name}_${f}`,_.name,JSON.stringify(_.args)));}});}if(y.usageMetadata&&(h.usage={promptTokens:y.usageMetadata.promptTokenCount,completionTokens:y.usageMetadata.candidatesTokenCount,totalTokens:y.usageMetadata.totalTokenCount}),y.candidates.length>0){let u=y.candidates[0];u.groundingMetadata&&h.partialMessages.push(Dt(E,((n=u.groundingMetadata.webSearchQueries)==null?void 0:n[0])||"",((i=u.groundingMetadata.groundingChunks)==null?void 0:i.map(f=>{var _,w;return {source:f.web?"web":"",url:((_=f.web)==null?void 0:_.uri)||"",title:((w=f.web)==null?void 0:w.title)||""}}))||[],((s=u.groundingMetadata.groundingSupports)==null?void 0:s.map(f=>{var _,w,q;return {text:((_=f.segment)==null?void 0:_.text)||"",responseIndices:f.groundingChunkIndices||[],startIndex:((w=f.segment)==null?void 0:w.startIndex)||void 0,endIndex:((q=f.segment)==null?void 0:q.endIndex)||void 0,confidenceScores:f.confidenceScores||void 0}}))||[]));let g=u.safetyRatings;g&&g.length>0&&g.forEach(f=>{f.blocked&&h.partialMessages.push(Nt(E,f.category,f.probability,f.blocked,`Blocked content for category: ${f.category} with probability: ${f.probability}`));});}yield {partialResponse:h,buffer:t};}else throw new H({info:"Invalid response from model",cause:p.error})}yield {partialResponse:{partialMessages:[]},buffer:t};})}transformProxyStreamChatResponseChunk(e,t,n,i,s){return di(this,null,function*(){var m,r,d;if((s==null?void 0:s.alt)!=="sse"){yield*rn(fr(this.transformStreamChatResponseChunk(e,t)));return}let l=t+e,p=[],h="",y=0;for(;y<l.length;){let u=l.indexOf(`
|
|
15
|
-
`,y);if(u===-1){h=l.substring(y);break}else {let g=l.substring(y,u).trim();g&&p.push(g),y=u+1;}}for(let u of p){if(u==="data: [DONE]")return;if(u.startsWith("data: ")){let g=u.substring(6);try{let f=JSON.parse(g),_=ci.safeParse(f);if(_.success){let w={partialMessages:[]},q=_.data;if(q.candidates.length>0){let X=q.candidates[0].content;X&&"parts"in X&&X.parts.length>0&&X.parts.forEach((z,G)=>{if("text"in z&&z.text!==void 0&&(z.thought===!0?w.partialMessages.push(Ft(E,z.text,"")):w.partialMessages.push(It(E,z.text))),"functionCall"in z&&z.functionCall!==void 0){let oe=z.functionCall;w.partialMessages.push(jt(E,G,`${oe.name}_${G}`,oe.name,JSON.stringify(oe.args)));}});}if(q.usageMetadata&&q.usageMetadata.totalTokenCount&&q.usageMetadata.promptTokenCount&&q.usageMetadata.candidatesTokenCount&&(w.usage={promptTokens:q.usageMetadata.promptTokenCount,completionTokens:q.usageMetadata.candidatesTokenCount,totalTokens:q.usageMetadata.totalTokenCount}),q.candidates.length>0){let X=q.candidates[0];X.groundingMetadata&&w.partialMessages.push(Dt(E,((m=X.groundingMetadata.webSearchQueries)==null?void 0:m[0])||"",((r=X.groundingMetadata.groundingChunks)==null?void 0:r.map(G=>{var oe,Se;return {source:G.web?"web":"",url:((oe=G.web)==null?void 0:oe.uri)||"",title:((Se=G.web)==null?void 0:Se.title)||""}}))||[],((d=X.groundingMetadata.groundingSupports)==null?void 0:d.map(G=>{var oe,Se,nn;return {text:((oe=G.segment)==null?void 0:oe.text)||"",responseIndices:G.groundingChunkIndices||[],startIndex:((Se=G.segment)==null?void 0:Se.startIndex)||void 0,endIndex:((nn=G.segment)==null?void 0:nn.endIndex)||void 0,confidenceScores:G.confidenceScores||void 0}}))||[]));let z=X.safetyRatings;z&&z.length>0&&z.forEach(G=>{G.blocked&&w.partialMessages.push(Nt(E,G.category,G.probability,G.blocked,`Blocked content for category: ${G.category} with probability: ${G.probability}`));});}yield {partialResponse:w,buffer:t};}else throw new H({info:"Invalid response from model",cause:_.error})}catch(f){throw new H({info:`Malformed JSON received in stream: ${g}`,cause:f})}}}yield {partialResponse:{partialMessages:[]},buffer:h};})}getProxyCompleteChatUrl(e,t,n){return j(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getProxyStreamChatUrl(e,t,n){return j(this,null,function*(){return new Promise(i=>{if(!n||Object.keys(n).length===0){i(this.streamChatUrl);return}let s=new URL(this.streamChatUrl);Object.entries(n).forEach(([m,r])=>{r!=null&&s.searchParams.set(m,r);}),i(s.toString());})})}getProxyCompleteChatHeaders(e,t,n){return j(this,null,function*(){if(!t)return {};let i=S({},t);return delete i.host,delete i["content-length"],i})}getProxyStreamChatHeaders(e,t,n){return j(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,t,n)})}getModelPricing(){if(!(this.modelName in R))throw new H({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return R[this.modelName]}},Yt="gemini-1.5-flash-001",Kr="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",De=I(L,D).parse({name:Yt,description:Kr,maxInputTokens:1e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Yt]}),Yr=$,Wr=class extends F{constructor(e){super(De,e);}},Wt="gemini-1.5-flash-002",Jr="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",$e=I(L,D).parse({name:Wt,description:Jr,maxInputTokens:1e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Wt]}),Xr=$,Zr=class extends F{constructor(e){super($e,e);}},Jt="gemini-1.5-flash-latest",Qr="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Be=I(L,D).parse({name:Jt,description:Qr,maxInputTokens:1e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Jt]}),el=$,tl=class extends F{constructor(e){super(Be,e);}},Xt="gemini-1.5-flash",ol="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Ae=I(L,D).parse({name:Xt,description:ol,maxInputTokens:1e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Xt]}),nl=$,il=class extends F{constructor(e){super(Ae,e);}},Zt="gemini-1.5-pro-001",al="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",qe=I(L,D).parse({name:Zt,description:al,maxInputTokens:2e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Zt]}),sl=$,rl=class extends F{constructor(e){super(qe,e);}},Qt="gemini-1.5-pro-002",ll="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",He=I(L,D).parse({name:Qt,description:ll,maxInputTokens:2e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Qt]}),ml=$,dl=class extends F{constructor(e){super(He,e);}},eo="gemini-1.5-pro-latest",cl="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",ze=I(L,D).parse({name:eo,description:cl,maxInputTokens:2e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[eo]}),pl=$,ul=class extends F{constructor(e){super(ze,e);}},to="gemini-1.5-pro",gl="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Ve=I(L,D).parse({name:to,description:gl,maxInputTokens:2e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[to]}),hl=$,fl=class extends F{constructor(e){super(Ve,e);}},yi="gemini-2.0-flash-exp",yl="Google's experimental multimodal model with enhanced capabilities. Designed for cutting-edge performance across complex and high-frequency tasks.",Di=I(L,D).parse({name:yi,description:yl,maxInputTokens:1e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[yi]});var oo="gemini-2.0-flash",bl="Google's Gemini 2.0 Flash model optimized for low-latency, high-performance tasks. Supports multimodal inputs including text, images, video, and audio with enhanced speed and efficiency.",Ke=I(L,D).parse({name:oo,description:bl,maxInputTokens:1048576,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[oo]}),Tl=$,Pl=class extends F{constructor(e){super(Ke,e);}},no="gemini-2.5-flash-lite",Ml="Google's most cost-efficient and fastest model in the 2.5 series. Optimized for high-volume, latency-sensitive tasks like translation and classification with enhanced reasoning capabilities.",Ye=I(L,D).parse({name:no,description:Ml,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.responseSchema(2,1,65536,4,.95).def,schema:k.responseSchema(2,1,65536,4,.95).schema},price:R[no]}),vl=$,kl=class extends F{constructor(e){super(Ye,e);}},io="gemini-2.5-flash-preview-04-17",_l="Google's best model in Gemini 2.5 family in terms of price-performance, offering well-rounded capabilities.",We=I(L,D).parse({name:io,description:_l,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.responseSchema(2,1,65536,4,.95).def,schema:k.responseSchema(2,1,65536,4,.95).schema},price:R[io]}),xl=$,Sl=class extends F{constructor(e){super(We,e);}},ao="gemini-2.5-flash",El="Google's Gemini 2.5 Flash model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Je=I(L,D).parse({name:ao,description:El,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.responseSchema(2,1,65536,4,.95).def,schema:k.responseSchema(2,1,65536,4,.95).schema},price:R[ao]}),Cl=$,wl=class extends F{constructor(e){super(Je,e);}},so="gemini-2.5-pro-preview-03-25",Gl="Google's preview model in Gemini 2.5 family for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Xe=I(L,D).parse({name:so,description:Gl,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.reasoning(2,1,65536,4,.95,1,65536).def,schema:k.reasoning(2,1,65536,4,.95,1,65536).schema},price:R[so]}),Ol=$,Rl=class extends F{constructor(e){super(Xe,e);}},ro="gemini-2.5-pro",Il="Google's Gemini 2.5 Pro model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Ze=I(L,D).parse({name:ro,description:Il,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.reasoning(2,1,65536,4,.95,1,65536).def,schema:k.reasoning(2,1,65536,4,.95,1,65536).schema},price:R[ro]}),jl=$,Fl=class extends F{constructor(e){super(Ze,e);}},lo="gemini-3-flash-preview",Ll="Google's Gemini 3 Flash Preview model - a lightweight and efficient AI model with enhanced multimodal understanding, reasoning, and advanced coding capabilities. Optimized for speed and cost-effectiveness. Supports Text, Image, Video, Audio, and PDF inputs. Knowledge cutoff: January 2025.",Qe=I(L,D).parse({name:lo,description:Ll,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.reasoning(2,1,65536,4,.95,1,65536).def,schema:k.reasoning(2,1,65536,4,.95,1,65536).schema},price:R[lo]}),Nl=$,Ul=class extends F{constructor(e){super(Qe,e);}},mo="gemini-3-pro-preview",Dl="Google's latest Gemini 3 Pro Preview model with enhanced multimodal understanding, reasoning, and thinking capabilities. Supports Text, Image, Video, Audio, and PDF inputs. Knowledge cutoff: January 2025.",et=I(L,D).parse({name:mo,description:Dl,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.reasoning(2,1,65536,4,.95,1,65536).def,schema:k.reasoning(2,1,65536,4,.95,1,65536).schema},price:R[mo]}),$l=$,Bl=class extends F{constructor(e){super(et,e);}},$i=[A],Bi=zod.z.enum([A]),Al=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))}),ql=zod.z.object({model:zod.z.string().min(1),content:zod.z.object({parts:zod.z.array(zod.z.object({text:zod.z.string().min(1)})).min(1)})}),Hl=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(ql).min(1),outputDimensionality:zod.z.number().int().min(1).optional()}),po=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),Ai=class{constructor(e,t){this.version="v1";let n=po.parse(t);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=xe(n.baseUrl||co.baseUrl),this.getEmbeddingsUrl=xe(n.getEmbeddingsUrl||`${this.baseUrl}/models/${this.modelName}:batchEmbedContents?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.requests.reduce((t,n)=>t+n.length,0)}transformModelRequest(e){let t=Hl.safeParse(e);if(!t.success)throw new ie({info:"Invalid model request",cause:t.error});let n=t.data,i=n.model,s={outputDimensionality:n.outputDimensionality},m=Ce().parse(Oe(s)),r={modality:A,requests:n.requests.reduce((d,l)=>(d.push(...l.content.parts.map(p=>p.text)),d),[])};return {modelName:i,config:m,embeddingRequests:r}}transformConfig(e,t){let n=this.modelSchema.config.schema.safeParse(e);if(!n.success)throw new V({info:`Invalid config for model : '${this.modelName}'`,cause:n.error});let i=n.data;return Object.keys(i).forEach(s=>{if(!this.modelSchema.config.def[s])throw new V({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${s}',
|
|
15
|
+
`,y);if(u===-1){h=l.substring(y);break}else {let g=l.substring(y,u).trim();g&&p.push(g),y=u+1;}}for(let u of p){if(u==="data: [DONE]")return;if(u.startsWith("data: ")){let g=u.substring(6);try{let f=JSON.parse(g),_=ci.safeParse(f);if(_.success){let w={partialMessages:[]},q=_.data;if(q.candidates.length>0){let X=q.candidates[0].content;X&&"parts"in X&&X.parts.length>0&&X.parts.forEach((z,G)=>{if("text"in z&&z.text!==void 0&&(z.thought===!0?w.partialMessages.push(Ft(E,z.text,"")):w.partialMessages.push(It(E,z.text))),"functionCall"in z&&z.functionCall!==void 0){let oe=z.functionCall;w.partialMessages.push(jt(E,G,`${oe.name}_${G}`,oe.name,JSON.stringify(oe.args)));}});}if(q.usageMetadata&&q.usageMetadata.totalTokenCount&&q.usageMetadata.promptTokenCount&&q.usageMetadata.candidatesTokenCount&&(w.usage={promptTokens:q.usageMetadata.promptTokenCount,completionTokens:q.usageMetadata.candidatesTokenCount,totalTokens:q.usageMetadata.totalTokenCount}),q.candidates.length>0){let X=q.candidates[0];X.groundingMetadata&&w.partialMessages.push(Dt(E,((m=X.groundingMetadata.webSearchQueries)==null?void 0:m[0])||"",((r=X.groundingMetadata.groundingChunks)==null?void 0:r.map(G=>{var oe,Se;return {source:G.web?"web":"",url:((oe=G.web)==null?void 0:oe.uri)||"",title:((Se=G.web)==null?void 0:Se.title)||""}}))||[],((d=X.groundingMetadata.groundingSupports)==null?void 0:d.map(G=>{var oe,Se,nn;return {text:((oe=G.segment)==null?void 0:oe.text)||"",responseIndices:G.groundingChunkIndices||[],startIndex:((Se=G.segment)==null?void 0:Se.startIndex)||void 0,endIndex:((nn=G.segment)==null?void 0:nn.endIndex)||void 0,confidenceScores:G.confidenceScores||void 0}}))||[]));let z=X.safetyRatings;z&&z.length>0&&z.forEach(G=>{G.blocked&&w.partialMessages.push(Nt(E,G.category,G.probability,G.blocked,`Blocked content for category: ${G.category} with probability: ${G.probability}`));});}yield {partialResponse:w,buffer:t};}else throw new H({info:"Invalid response from model",cause:_.error})}catch(f){throw new H({info:`Malformed JSON received in stream: ${g}`,cause:f})}}}yield {partialResponse:{partialMessages:[]},buffer:h};})}getProxyCompleteChatUrl(e,t,n){return j(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getProxyStreamChatUrl(e,t,n){return j(this,null,function*(){return new Promise(i=>{if(!n||Object.keys(n).length===0){i(this.streamChatUrl);return}let s=new URL(this.streamChatUrl);Object.entries(n).forEach(([m,r])=>{r!=null&&s.searchParams.set(m,r);}),i(s.toString());})})}getProxyCompleteChatHeaders(e,t,n){return j(this,null,function*(){if(!t)return {};let i=S({},t);return delete i.host,delete i["content-length"],i})}getProxyStreamChatHeaders(e,t,n){return j(this,null,function*(){return yield this.getProxyCompleteChatHeaders(e,t,n)})}getModelPricing(){if(!(this.modelName in R))throw new H({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return R[this.modelName]}},Yt="gemini-1.5-flash-001",Kr="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",De=I(L,D).parse({name:Yt,description:Kr,maxInputTokens:1e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Yt]}),Yr=$,Wr=class extends F{constructor(e){super(De,e);}},Wt="gemini-1.5-flash-002",Jr="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",$e=I(L,D).parse({name:Wt,description:Jr,maxInputTokens:1e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Wt]}),Xr=$,Zr=class extends F{constructor(e){super($e,e);}},Jt="gemini-1.5-flash-latest",Qr="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Be=I(L,D).parse({name:Jt,description:Qr,maxInputTokens:1e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Jt]}),el=$,tl=class extends F{constructor(e){super(Be,e);}},Xt="gemini-1.5-flash",ol="Google's fastest, most cost-efficient multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Ae=I(L,D).parse({name:Xt,description:ol,maxInputTokens:1e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Xt]}),nl=$,il=class extends F{constructor(e){super(Ae,e);}},Zt="gemini-1.5-pro-001",al="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",qe=I(L,D).parse({name:Zt,description:al,maxInputTokens:2e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Zt]}),sl=$,rl=class extends F{constructor(e){super(qe,e);}},Qt="gemini-1.5-pro-002",ll="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",He=I(L,D).parse({name:Qt,description:ll,maxInputTokens:2e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[Qt]}),ml=$,dl=class extends F{constructor(e){super(He,e);}},eo="gemini-1.5-pro-latest",cl="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",ze=I(L,D).parse({name:eo,description:cl,maxInputTokens:2e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[eo]}),pl=$,ul=class extends F{constructor(e){super(ze,e);}},to="gemini-1.5-pro",gl="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Ve=I(L,D).parse({name:to,description:gl,maxInputTokens:2e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[to]}),hl=$,fl=class extends F{constructor(e){super(Ve,e);}},yi="gemini-2.0-flash-exp",yl="Google's experimental multimodal model with enhanced capabilities. Designed for cutting-edge performance across complex and high-frequency tasks.",Di=I(L,D).parse({name:yi,description:yl,maxInputTokens:1e6,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[yi]});var oo="gemini-2.0-flash",bl="Google's Gemini 2.0 Flash model optimized for low-latency, high-performance tasks. Supports multimodal inputs including text, images, video, and audio with enhanced speed and efficiency.",Ke=I(L,D).parse({name:oo,description:bl,maxInputTokens:1048576,maxOutputTokens:8192,roles:N,modalities:U,config:{def:k.responseSchema(2,1,8192,4,.95).def,schema:k.responseSchema(2,1,8192,4,.95).schema},price:R[oo]}),Tl=$,Pl=class extends F{constructor(e){super(Ke,e);}},no="gemini-2.5-flash-lite",Ml="Google's most cost-efficient and fastest model in the 2.5 series. Optimized for high-volume, latency-sensitive tasks like translation and classification with enhanced reasoning capabilities.",Ye=I(L,D).parse({name:no,description:Ml,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.responseSchema(2,1,65536,4,.95).def,schema:k.responseSchema(2,1,65536,4,.95).schema},price:R[no]}),vl=$,kl=class extends F{constructor(e){super(Ye,e);}},io="gemini-2.5-flash-preview-04-17",_l="Google's best model in Gemini 2.5 family in terms of price-performance, offering well-rounded capabilities.",We=I(L,D).parse({name:io,description:_l,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.reasoning(2,1,65536,4,.95,1,24576).def,schema:k.reasoning(2,1,65536,4,.95,1,24576).schema},price:R[io]}),xl=$,Sl=class extends F{constructor(e){super(We,e);}},ao="gemini-2.5-flash",El="Google's Gemini 2.5 Flash model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Je=I(L,D).parse({name:ao,description:El,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.reasoning(2,1,65536,4,.95,1,24576).def,schema:k.reasoning(2,1,65536,4,.95,1,24576).schema},price:R[ao]}),Cl=$,wl=class extends F{constructor(e){super(Je,e);}},so="gemini-2.5-pro-preview-03-25",Gl="Google's preview model in Gemini 2.5 family for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Xe=I(L,D).parse({name:so,description:Gl,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.reasoning(2,1,65536,4,.95,1,65536).def,schema:k.reasoning(2,1,65536,4,.95,1,65536).schema},price:R[so]}),Ol=$,Rl=class extends F{constructor(e){super(Xe,e);}},ro="gemini-2.5-pro",Il="Google's Gemini 2.5 Pro model for enhanced thinking, reasoning, multimodal understanding, and advanced coding.",Ze=I(L,D).parse({name:ro,description:Il,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.reasoning(2,1,65536,4,.95,1,65536).def,schema:k.reasoning(2,1,65536,4,.95,1,65536).schema},price:R[ro]}),jl=$,Fl=class extends F{constructor(e){super(Ze,e);}},lo="gemini-3-flash-preview",Ll="Google's Gemini 3 Flash Preview model - a lightweight and efficient AI model with enhanced multimodal understanding, reasoning, and advanced coding capabilities. Optimized for speed and cost-effectiveness. Supports Text, Image, Video, Audio, and PDF inputs. Knowledge cutoff: January 2025.",Qe=I(L,D).parse({name:lo,description:Ll,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.reasoning(2,1,65536,4,.95,1,65536).def,schema:k.reasoning(2,1,65536,4,.95,1,65536).schema},price:R[lo]}),Nl=$,Ul=class extends F{constructor(e){super(Qe,e);}},mo="gemini-3-pro-preview",Dl="Google's latest Gemini 3 Pro Preview model with enhanced multimodal understanding, reasoning, and thinking capabilities. Supports Text, Image, Video, Audio, and PDF inputs. Knowledge cutoff: January 2025.",et=I(L,D).parse({name:mo,description:Dl,maxInputTokens:1048576,maxOutputTokens:65536,roles:N,modalities:U,config:{def:k.reasoning(2,1,65536,4,.95,1,65536).def,schema:k.reasoning(2,1,65536,4,.95,1,65536).schema},price:R[mo]}),$l=$,Bl=class extends F{constructor(e){super(et,e);}},$i=[A],Bi=zod.z.enum([A]),Al=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))}),ql=zod.z.object({model:zod.z.string().min(1),content:zod.z.object({parts:zod.z.array(zod.z.object({text:zod.z.string().min(1)})).min(1)})}),Hl=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(ql).min(1),outputDimensionality:zod.z.number().int().min(1).optional()}),po=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url().optional(),getEmbeddingsUrl:zod.z.string().url().optional()}),Ai=class{constructor(e,t){this.version="v1";let n=po.parse(t);this.modelSchema=e,this.modelName=n.modelName,this.apiKey=n.apiKey,this.baseUrl=xe(n.baseUrl||co.baseUrl),this.getEmbeddingsUrl=xe(n.getEmbeddingsUrl||`${this.baseUrl}/models/${this.modelName}:batchEmbedContents?key=${this.apiKey}`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelName}}getRetryDelay(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.requests.reduce((t,n)=>t+n.length,0)}transformModelRequest(e){let t=Hl.safeParse(e);if(!t.success)throw new ie({info:"Invalid model request",cause:t.error});let n=t.data,i=n.model,s={outputDimensionality:n.outputDimensionality},m=Ce().parse(Oe(s)),r={modality:A,requests:n.requests.reduce((d,l)=>(d.push(...l.content.parts.map(p=>p.text)),d),[])};return {modelName:i,config:m,embeddingRequests:r}}transformConfig(e,t){let n=this.modelSchema.config.schema.safeParse(e);if(!n.success)throw new V({info:`Invalid config for model : '${this.modelName}'`,cause:n.error});let i=n.data;return Object.keys(i).forEach(s=>{if(!this.modelSchema.config.def[s])throw new V({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${s}',
|
|
16
16
|
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((s,m)=>{let r=this.modelSchema.config.def[m].param,d=i[m];return s[r]=d,s},{})}transformEmbeddingRequests(e){let t=Fe().safeParse(e);if(!t.success)throw new de({info:"Invalid embedding requests",cause:t.error});if(e.modality!==A)throw new de({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${A}' modality is supported for model : '${this.modelName}'`)});return {requests:t.data.requests.map(n=>({model:`models/${this.modelName}`,content:{parts:[{text:n}]}}))}}getGetEmbeddingsUrl(e,t){return j(this,null,function*(){return new Promise(n=>{n(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,t){return j(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,t){return j(this,null,function*(){return new Promise(n=>{let i=this.transformConfig(e),s=this.transformEmbeddingRequests(t);if(t.requests.length===0)throw new de({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});i.outputDimensionality&&(s.requests.forEach(m=>{m.outputDimensionality=i.outputDimensionality;}),delete i.outputDimensionality),n(S(S(S({},this.getDefaultParams()),i),s));})})}transformGetEmbeddingsResponse(e){let t=Al.safeParse(e);if(t.success){let n=t.data.embeddings.map((i,s)=>({index:s,embedding:i.values}));return {encodingFormat:we,embeddings:n}}throw new H({info:"Invalid response from model",cause:t.error})}},qi="text-embedding-001",zl="text-embedding-001",Hi=J(Bi).parse({name:qi,description:zl,modalities:$i,maxInputTokens:2048,maxOutputTokens:768,config:{def:Ue.base(768).def,schema:Ue.base(768).schema}}),Vl=po,Kl=class extends Ai{constructor(e){super(Hi,e);}},zi="text-embedding-004",Yl="text-embedding-004",Vi=J(Bi).parse({name:zi,description:Yl,modalities:$i,maxInputTokens:2048,maxOutputTokens:768,config:{def:Ue.base(768).def,schema:Ue.base(768).schema}}),Wl=po,Jl=class extends Ai{constructor(e){super(Vi,e);}};var Xl="vertex",fe=class{constructor(){this.version="v1";this.name=Xl;this.chatModelFactories={[uo]:{model:tt,modelOptions:Ki,modelSchema:go},[ho]:{model:ot,modelOptions:Yi,modelSchema:fo},[xo]:{model:rt,modelOptions:Qi,modelSchema:So},[yo]:{model:nt,modelOptions:Wi,modelSchema:bo},[To]:{model:it,modelOptions:Ji,modelSchema:Po},[Mo]:{model:at,modelOptions:Xi,modelSchema:vo},[Eo]:{model:lt,modelOptions:ea,modelSchema:Co},[ko]:{model:st,modelOptions:Zi,modelSchema:_o},[wo]:{model:mt,modelOptions:ta,modelSchema:Go},[Oo]:{model:dt,modelOptions:oa,modelSchema:Ro},[Io]:{model:ct,modelOptions:na,modelSchema:jo},[Fo]:{model:pt,modelOptions:ia,modelSchema:Lo},[Do]:{model:gt,modelOptions:sa,modelSchema:$o},[No]:{model:ut,modelOptions:aa,modelSchema:Uo},[Bo]:{model:ht,modelOptions:ra,modelSchema:Ao},[qo]:{model:ft,modelOptions:la,modelSchema:Ho},[zo]:{model:yt,modelOptions:ma,modelSchema:Vo}};this.embeddingModelFactories={[Ko]:{model:bt,modelOptions:da,modelSchema:Yo},[Wo]:{model:Tt,modelOptions:ca,modelSchema:Jo},[Qo]:{model:Mt,modelOptions:ua,modelSchema:en},[Xo]:{model:Pt,modelOptions:pa,modelSchema:Zo}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((t,n)=>(t[n]=this.chatModelFactories[n].modelSchema,t),{})}chatModel(t){let n=t.modelName;if(!(n in this.chatModelFactories))throw new ve({info:`Vertex chat model: ${n} not found`,cause:new Error(`Vertex chat model: ${n} not found, available chat models:
|
|
17
17
|
${this.chatModelLiterals().join(", ")}`)});let i=this.chatModelFactories[n].model,s=this.chatModelFactories[n].modelOptions.parse(t);return new i(s)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((t,n)=>(t[n]=this.embeddingModelFactories[n].modelSchema,t),{})}embeddingModel(t){let n=t.modelName;if(!(n in this.embeddingModelFactories))throw new ve({info:`Vertex embedding model: ${n} not found`,cause:new Error(`Vertex embedding model: ${n} not found, available embedding models:
|
|
18
18
|
${this.embeddingModelLiterals().join(", ")}`)});let i=this.embeddingModelFactories[n].model,s=this.embeddingModelFactories[n].modelOptions.parse(t);return new i(s)}};fe.baseUrl=(t,n,i="google")=>`https://${t}-aiplatform.googleapis.com/v1/projects/${n}/locations/${t}/publishers/${i}`;var T={"gemini-1.0-pro-001":{modelName:"gemini-1.0-pro-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro-vision":{modelName:"gemini-1.0-pro-vision",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.0-pro":{modelName:"gemini-1.0-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:1.5}}}]},"gemini-1.5-flash-001":{modelName:"gemini-1.5-flash-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-flash-002":{modelName:"gemini-1.5-flash-002",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.0375,outputPricePerMillion:.15}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}}]},"gemini-1.5-flash":{modelName:"gemini-1.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.075,outputPricePerMillion:.3}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-1.5-pro-001":{modelName:"gemini-1.5-pro-001",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro-002":{modelName:"gemini-1.5-pro-002",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-1.5-pro":{modelName:"gemini-1.5-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:5}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:10}}}]},"gemini-2.0-flash-exp":{modelName:"gemini-2.0-flash-exp",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-2.0-flash":{modelName:"gemini-2.0-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.15,outputPricePerMillion:.6}}}]},"gemini-2.5-flash-lite":{modelName:"gemini-2.5-flash-lite",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.1,outputPricePerMillion:.4}}}]},"gemini-1.5-flash-latest":{modelName:"gemini-1.5-flash-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.01875,outputPricePerMillion:.075}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.0375,outputPricePerMillion:.15}}}]},"gemini-1.5-pro-latest":{modelName:"gemini-1.5-pro-latest",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:128e3,prices:{base:{inputPricePerMillion:.3125,outputPricePerMillion:1.25}}},{minTokens:128001,maxTokens:null,prices:{base:{inputPricePerMillion:.625,outputPricePerMillion:2.5}}}]},"gemini-2.5-flash-preview-04-17":{modelName:"gemini-2.5-flash-preview-04-17",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:2}}}]},"gemini-2.5-pro-preview-03-25":{modelName:"gemini-2.5-pro-preview-03-25",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:2e5,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}},{minTokens:200001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:15}}}]},"gemini-2.5-flash":{modelName:"gemini-2.5-flash",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.3,outputPricePerMillion:2.5}}}]},"gemini-2.5-pro":{modelName:"gemini-2.5-pro",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:2e5,prices:{base:{inputPricePerMillion:1.25,outputPricePerMillion:10}}},{minTokens:200001,maxTokens:null,prices:{base:{inputPricePerMillion:2.5,outputPricePerMillion:15}}}]},"gemini-3-pro-preview":{modelName:"gemini-3-pro-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:2e5,prices:{base:{inputPricePerMillion:2,outputPricePerMillion:12}}},{minTokens:200001,maxTokens:null,prices:{base:{inputPricePerMillion:4,outputPricePerMillion:18}}}]},"gemini-3-flash-preview":{modelName:"gemini-3-flash-preview",currency:"USD",tokenRanges:[{minTokens:0,maxTokens:null,prices:{base:{inputPricePerMillion:.5,outputPricePerMillion:3}}}]}};var v=zod.z.discriminatedUnion("authType",[zod.z.object({authType:zod.z.literal("accessToken"),accessToken:zod.z.string(),modelName:zod.z.string(),baseUrl:zod.z.string().url().optional(),location:zod.z.string().optional(),projectId:zod.z.string().optional(),publisher:zod.z.string().optional()}),zod.z.object({authType:zod.z.literal("serviceAccount"),serviceAccount:zod.z.object({client_email:zod.z.string().email(),private_key:zod.z.string(),type:zod.z.string().optional(),project_id:zod.z.string().optional(),private_key_id:zod.z.string().optional(),client_id:zod.z.string().optional(),auth_uri:zod.z.string().url().optional(),token_uri:zod.z.string().url().optional(),auth_provider_x509_cert_url:zod.z.string().url().optional(),client_x509_cert_url:zod.z.string().url().optional(),universe_domain:zod.z.string().optional()}),modelName:zod.z.string(),baseUrl:zod.z.string().url().optional(),location:zod.z.string().optional(),projectId:zod.z.string().optional(),publisher:zod.z.string().optional(),tokenLifetimeHours:zod.z.number().min(.1).max(24).default(1)})]),M=class extends F{constructor(n,i){let s=v.parse(i),m;if(s.baseUrl)m=s.baseUrl;else if(s.location&&s.projectId)m=fe.baseUrl(s.location,s.projectId,s.publisher);else throw new ke({info:"Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided",cause:new Error("Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided")});super(n,{modelName:s.modelName,apiKey:"random-api-key",completeChatUrl:`${m}/models/${s.modelName}:generateContent`,streamChatUrl:`${m}/models/${s.modelName}:streamGenerateContent`});this.version="v1";this.accessToken=null;this.tokenExpiry=null;this.modelSchema=n,this.modelName=s.modelName,this.authOptions=s,this.location=s.location,this.projectId=s.projectId,this.publisher=s.publisher,s.authType==="accessToken"&&(this.accessToken=s.accessToken);}getAccessToken(){return Z(this,null,function*(){if(this.accessToken&&this.tokenExpiry&&Date.now()<this.tokenExpiry)return this.accessToken;if(this.authOptions.authType==="serviceAccount")try{let n=this.authOptions.serviceAccount,i=Math.floor(Date.now()/1e3),s=yield new jose.SignJWT({scope:"https://www.googleapis.com/auth/cloud-platform",aud:"https://oauth2.googleapis.com/token"}).setProtectedHeader({alg:"RS256",typ:"JWT"}).setIssuedAt(i).setExpirationTime(i+this.authOptions.tokenLifetimeHours*3600).setIssuer(n.client_email).setSubject(n.client_email).sign(yield this.importPrivateKey(n.private_key)),m=yield fetch("https://oauth2.googleapis.com/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"urn:ietf:params:oauth:grant-type:jwt-bearer",assertion:s})});if(!m.ok){let d=yield m.text();throw new Error(`Token exchange failed: ${m.status} ${d}`)}let r=yield m.json();if(!r.access_token)throw new Error(`No access token received from Google OAuth: ${r.error||"Unknown error"}`);return this.tokenExpiry=Date.now()+this.authOptions.tokenLifetimeHours*3600*1e3-5*60*1e3,this.accessToken=r.access_token,this.accessToken}catch(n){throw new ke({info:`Failed to generate service account token: ${n instanceof Error?n.message:String(n)}`,cause:n instanceof Error?n:new Error(String(n))})}if(this.accessToken)return this.accessToken;throw new ke({info:"No valid access token available",cause:new Error("No valid access token available")})})}importPrivateKey(n){return Z(this,null,function*(){let i=n.replace(/-----BEGIN PRIVATE KEY-----/,"").replace(/-----END PRIVATE KEY-----/,"").replace(/\s/g,""),s=atob(i),m=new Uint8Array(s.length);for(let r=0;r<s.length;r++)m[r]=s.charCodeAt(r);return yield crypto.subtle.importKey("pkcs8",m,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["sign"])})}ensureToken(){return Z(this,null,function*(){this.authOptions.authType==="serviceAccount"&&(yield this.getAccessToken());})}getDefaultHeaders(){return P(b({},super.getDefaultHeaders()),{Authorization:`Bearer ${this.accessToken}`})}getCompleteChatHeaders(n,i,s){return Z(this,null,function*(){return yield this.ensureToken(),this.getDefaultHeaders()})}getStreamChatHeaders(n,i,s){return Z(this,null,function*(){return yield this.ensureToken(),this.getDefaultHeaders()})}getModelPricing(){if(!(this.modelName in T))throw new H({info:`Invalid model pricing for model : '${this.modelName}'`,cause:new Error(`No pricing configuration found for model "${this.modelName}"`)});return T[this.modelName]}};var uo="gemini-1.5-flash-001",go=P(b({},De),{price:T[uo]}),Ki=v,tt=class extends M{constructor(t){super(go,t);}};var ho="gemini-1.5-flash-002",fo=P(b({},$e),{price:T[ho]}),Yi=v,ot=class extends M{constructor(t){super(fo,t);}};var yo="gemini-1.5-flash",bo=P(b({},Ae),{price:T[yo]}),Wi=v,nt=class extends M{constructor(t){super(bo,t);}};var To="gemini-1.5-pro-001",Po=P(b({},qe),{price:T[To]}),Ji=v,it=class extends M{constructor(t){super(Po,t);}};var Mo="gemini-1.5-pro-002",vo=P(b({},He),{price:T[Mo]}),Xi=v,at=class extends M{constructor(t){super(vo,t);}};var ko="gemini-1.5-pro",_o=P(b({},Ve),{price:T[ko]}),Zi=v,st=class extends M{constructor(t){super(_o,t);}};var xo="gemini-1.5-flash-latest",So=P(b({},Be),{price:T[xo]}),Qi=v,rt=class extends M{constructor(t){super(So,t);}};var Eo="gemini-1.5-pro-latest",Co=P(b({},ze),{price:T[Eo]}),ea=v,lt=class extends M{constructor(t){super(Co,t);}};var wo="gemini-2.0-flash-exp",Go=P(b({},Di),{price:T[wo]}),ta=v,mt=class extends M{constructor(t){super(Go,t);}};var Oo="gemini-2.0-flash",Ro=P(b({},Ke),{price:T[Oo]}),oa=v,dt=class extends M{constructor(t){super(Ro,t);}};var Io="gemini-2.5-flash-lite",jo=P(b({},Ye),{price:T[Io]}),na=v,ct=class extends M{constructor(t){super(jo,t);}};var Fo="gemini-2.5-flash-preview-04-17",Lo=P(b({},We),{price:T[Fo]}),ia=v,pt=class extends M{constructor(t){super(Lo,t);}};var No="gemini-2.5-flash",Uo=P(b({},Je),{price:T[No]}),aa=v,ut=class extends M{constructor(t){super(Uo,t);}};var Do="gemini-2.5-pro-preview-03-25",$o=P(b({},Xe),{price:T[Do]}),sa=v,gt=class extends M{constructor(t){super($o,t);}};var Bo="gemini-2.5-pro",Ao=P(b({},Ze),{price:T[Bo]}),ra=v,ht=class extends M{constructor(t){super(Ao,t);}};var qo="gemini-3-flash-preview",Ho=P(b({},Qe),{price:T[qo]}),la=v,ft=class extends M{constructor(t){super(Ho,t);}};var zo="gemini-3-pro-preview",Vo=P(b({},et),{price:T[zo]}),ma=v,yt=class extends M{constructor(t){super(Vo,t);}};var ce=[A],pe=zod.z.enum([A]);var ga=zod.z.object({predictions:zod.z.array(zod.z.object({embeddings:zod.z.object({values:zod.z.array(zod.z.number()),statistics:zod.z.object({token_count:zod.z.number(),truncated:zod.z.boolean()})})}))});var ha=zod.z.object({model:zod.z.string().min(1).optional(),instances:zod.z.array(zod.z.object({content:zod.z.string().min(1)})).min(1),parameters:zod.z.object({auto_truncate:zod.z.boolean().optional(),output_dimensionality:zod.z.number().int().min(1).optional(),autoTruncate:zod.z.boolean().optional(),outputDimensionality:zod.z.number().int().min(1).optional()}).optional()});var se=zod.z.object({accessToken:zod.z.string(),modelName:zod.z.string(),baseUrl:zod.z.string().url().optional(),location:zod.z.string().optional(),projectId:zod.z.string().optional(),publisher:zod.z.string().optional()}),te=class{constructor(t,n){this.version="v1";let i=se.parse(n);this.modelSchema=t,this.modelName=i.modelName,this.accessToken=i.accessToken;let s;if(i.baseUrl)s=i.baseUrl;else if(i.location&&i.projectId)s=fe.baseUrl(i.location,i.projectId,i.publisher);else throw new ke({info:"Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided",cause:new Error("Either 'baseUrl' must be provided or 'location' and 'projectId' must be provided")});this.baseUrl=s,this.getEmbeddingsUrl=`${this.baseUrl}/models/${i.modelName}:predict`,this.location=i.location,this.projectId=i.projectId;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {"Content-Type":"application/json",Authorization:`Bearer ${this.accessToken}`}}getDefaultParams(){return {}}getRetryDelay(t){return {shouldRetry:!1,delayMs:0}}getTokenCount(t){return t.requests.reduce((n,i)=>n+i.length,0)}transformModelRequest(t){var l,p,h,y;let n=ha.safeParse(t);if(!n.success)throw new ie({info:"Invalid model request",cause:n.error});let i=n.data,s=i.model,m={autoTruncate:((l=i.parameters)==null?void 0:l.auto_truncate)||((p=i.parameters)==null?void 0:p.autoTruncate),dimensions:((h=i.parameters)==null?void 0:h.output_dimensionality)||((y=i.parameters)==null?void 0:y.outputDimensionality)},r=Ce().parse(Oe(m)),d={modality:A,requests:i.instances.map(u=>u.content)};return {modelName:s,config:r,embeddingRequests:d}}transformConfig(t,n){let i=this.modelSchema.config.schema.safeParse(t);if(!i.success)throw new V({info:`Invalid config for model : '${this.modelName}'`,cause:i.error});let s=i.data;return Object.keys(s).forEach(r=>{if(!this.modelSchema.config.def[r])throw new V({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${r}',
|