@adaline/vertex 0.8.0 → 0.8.1

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 CHANGED
@@ -10,7 +10,7 @@ Message: ${Vn(o)}`),this.name=Je,this.info=e,this.cause=o,this.name=i!=null?i:Je
10
10
  one of [${g.choices.join(", ")}]`)})}}return O(O({generation_config:d},c?{tool_config:c}:{}),m?{safety_settings:m}:{})}transformMessages(t){if(!t||t&&t.length===0)return {messages:[]};let e=t.map(r=>{let d=et().safeParse(r);if(!d.success)throw new T({info:"Invalid messages",cause:d.error});return d.data});e.forEach(r=>{r.content.forEach(d=>{if(!this.modelSchema.modalities.includes(d.modality))throw new T({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support modality : '${d.modality}',
11
11
  available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),e.forEach(r=>{if(!Object.keys(this.modelSchema.roles).includes(r.role))throw new T({info:`Invalid message content for model : '${this.modelName}'`,cause:new Error(`model : '${this.modelName}' does not support role : '${r.role}',
12
12
  available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})});let o={parts:[]},i=[];if(e.forEach(r=>{switch(r.role){case de:r.content.forEach(d=>{if(d.modality===_)o.parts.push({text:d.value});else throw new T({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 L:{let d=[];r.content.forEach(m=>{if(m.modality===_)d.push({text:m.value});else if(m.modality===w)d.push({function_call:{name:m.name,args:JSON.parse(m.arguments)}});else throw new T({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${m.modality}'`)})}),i.push({role:this.modelSchema.roles[r.role],parts:d});}break;case I:{let d=[];r.content.forEach(m=>{if(m.modality===_)d.push({text:m.value});else if(m.modality===U){if(m.value.type==="base64")d.push({inline_data:{mime_type:m.value.media_type,data:m.value.base64}});else if(m.value.type==="url")throw new T({info:`Invalid message 'modality' for model : ${this.modelName}`,cause:new Error(`model: '${this.modelName}' does not support image content type: '${m.value.type}'`)})}else throw new T({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${m.modality}'`)})}),i.push({role:this.modelSchema.roles[r.role],parts:d});}break;case Y:{let d=[];r.content.forEach(m=>{if(m.modality===A)d.push({function_response:{name:m.name,response:JSON.parse(m.data)}});else throw new T({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' cannot have content with modality : '${m.modality}'`)})}),i.push({role:this.modelSchema.roles[r.role],parts:d});}break;default:throw new T({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`role : '${r.role}' is not supported,
13
- available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),i[0].role!==this.modelSchema.roles[I])throw new T({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let s=r=>r===this.modelSchema.roles[I]||r===this.modelSchema.roles[Y]?[this.modelSchema.roles[L]]:[this.modelSchema.roles[I],this.modelSchema.roles[Y]];for(let r=1;r<i.length;r++)if(!s(i[r-1].role).includes(i[r].role))throw new T({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${i[r].role}' after message with role : '${i[r-1].role}'`)});if(i[i.length-1].role!==this.modelSchema.roles[I]&&i[i.length-1].role!==this.modelSchema.roles[Y])throw new T({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return O({contents:i},o.parts.length>0?{system_instruction:o}:{})}transformTools(t){if(!this.modelSchema.modalities.includes(w))throw new ot({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${w}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:t.map(e=>{let o=Vt().safeParse(e);if(!o.success)throw new ot({info:"Invalid tools",cause:o.error});return o.data}).map(e=>({function_declarations:[{name:e.definition.schema.name,description:e.definition.schema.description,parameters:e.definition.schema.parameters}]}))}}getCompleteChatUrl(t,e,o){return z(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(t,e,o){return z(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getCompleteChatData(t,e,o){return z(this,null,function*(){let i=this.transformConfig(t,e,o),s=this.transformMessages(e);if(s.messages&&s.messages.length===0)throw new T({info:"Messages are required",cause:new Error("Messages are required")});let r=o?this.transformTools(o):{};return new Promise(d=>{d(O(O(O(O({},this.getDefaultParams()),i),s),r));})})}transformCompleteChatResponse(t){let e=gi.safeParse(t);if(e.success){if(e.data.candidates.length===0)throw new D({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(e.data)}`)});let o=e.data,i=[],s,r=o.candidates[0].content;if(r){let m=r.parts.map((c,p)=>{if("text"in c&&c.text!==void 0)return Bt(c.text);if("functionCall"in c&&c.functionCall!==void 0)return Ut(p,`${c.functionCall.name}_${p}`,c.functionCall.name,JSON.stringify(c.functionCall.args))});return i.push({role:L,content:m}),o.usageMetadata&&(s={promptTokens:o.usageMetadata.promptTokenCount,totalTokens:o.usageMetadata.totalTokenCount,completionTokens:o.usageMetadata.candidatesTokenCount||0}),{messages:i,usage:s,logProbs:void 0}}let d=o.candidates[0].safetyRatings;if(d&&d.length>0&&d.forEach(m=>{if(m.blocked)throw new D({info:`Blocked content for category: ${m.category} with probability: ${m.probability}`,cause:new Error(`Blocked content for category: ${m.category} with probability: ${m.probability}`)})}),o.candidates[0].finishReason==="SAFETY")throw new D({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new D({info:"Invalid response from model",cause:e.error})}getStreamChatUrl(t,e,o){return z(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(t,e,o){return z(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getStreamChatData(t,e,o){return z(this,null,function*(){let i=this.transformConfig(t,e,o),s=this.transformMessages(e);if(s.messages&&s.messages.length===0)throw new T({info:"Messages are required",cause:new Error("Messages are required")});let r=o?this.transformTools(o):{};return new Promise(d=>{d(O(O(O(O({},this.getDefaultParams()),i),s),r));})})}transformStreamChatResponseChunk(t,e){return ni(this,null,function*(){let o=(e+t).split(",\r").filter(i=>i.trim()!=="");for(let i of o){let s=i;if(s=s.replace(/\n/g,""),s.startsWith("["))s=s.slice(1);else if(s.endsWith("]")){if(s==="]")return;s=s.slice(0,-1);}let r;try{r=JSON.parse(s);}catch(m){if(m instanceof SyntaxError){e=s;continue}else throw m}e="";let d=yi.safeParse(r);if(d.success){let m={partialMessages:[]},c=d.data;if(c.candidates.length>0){let p=c.candidates[0].content;p&&"parts"in p&&p.parts.length>0&&p.parts.forEach((g,f)=>{if("text"in g&&g.text!==void 0&&m.partialMessages.push(At(L,g.text)),"functionCall"in g&&g.functionCall!==void 0){let h=g.functionCall;m.partialMessages.push(Dt(L,f,`${h.name}_${f}`,h.name,JSON.stringify(h.args)));}});}c.usageMetadata&&(m.usage={promptTokens:c.usageMetadata.promptTokenCount,completionTokens:c.usageMetadata.candidatesTokenCount,totalTokens:c.usageMetadata.totalTokenCount}),yield {partialResponse:m,buffer:e};}else throw new D({info:"Invalid response from model",cause:d.error})}yield {partialResponse:{partialMessages:[]},buffer:e};})}},re=class extends N{transformMessages(t){let e=super.transformMessages(t);if(e.systemInstruction){let o={role:this.modelSchema.roles[I],parts:e.systemInstruction.parts};e.contents.unshift(o),delete e.systemInstruction;}return e}},qo="gemini-pro",Ci="A model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",Bo=x(S,Oe).parse({name:qo,description:Ci,maxInputTokens:30720,maxOutputTokens:2048,roles:G,modalities:Ce,config:{def:u.base(1,.9,2048,4,1).def,schema:u.base(1,.9,2048,4,1).schema}}),Oi=v,Si=class extends re{constructor(t){super(Bo,t);}},Uo="gemini-pro-vision",Gi="An image understanding model to handle a broad range of applications",Ao=x(S,Lo).parse({name:Uo,description:Gi,maxInputTokens:12288,maxOutputTokens:4096,roles:G,modalities:No,config:{def:u.c1(1,.4,4096,4,1,32).def,schema:u.c1(1,.4,4096,4,1,32).schema}}),Pi=v,wi=class extends re{constructor(t){super(Ao,t);}},Do="gemini-1.0-pro",ki="Google's predecessor to Gemini 1.5 Pro, a model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",Se=x(S,Oe).parse({name:Do,description:ki,maxInputTokens:30720,maxOutputTokens:2048,roles:G,modalities:Ce,config:{def:u.base(1,.9,2048,4,1).def,schema:u.base(1,.9,2048,4,1).schema}}),Ii=v,ji=class extends re{constructor(t){super(Se,t);}},Vo="gemini-1.0-pro-001",Ri="Google's predecessor to Gemini 1.5 Pro, a model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",Ge=x(S,Oe).parse({name:Vo,description:Ri,maxInputTokens:30720,maxOutputTokens:2048,roles:G,modalities:Ce,config:{def:u.base(1,.9,2048,4,1).def,schema:u.base(1,.9,2048,4,1).schema}}),Ni=v,Li=class extends re{constructor(t){super(Ge,t);}},zo="gemini-1.0-pro-latest",Fi="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for natural language tasks, multi-turn text and code chat, and code generation",Ho=x(S,Oe).parse({name:zo,description:Fi,maxInputTokens:30720,maxOutputTokens:2048,roles:G,modalities:Ce,config:{def:u.base(1,.9,2048,4,1).def,schema:u.base(1,.9,2048,4,1).schema}}),$i=v,qi=class extends re{constructor(t){super(Ho,t);}},Ko="gemini-1.0-pro-vision",Bi="Google's predecessor to Gemini 1.5 Pro, an image understanding model to handle a broad range of applications",Pe=x(S,Lo).parse({name:Ko,description:Bi,maxInputTokens:12288,maxOutputTokens:4096,roles:G,modalities:No,config:{def:u.c1(1,.4,4096,4,1,32).def,schema:u.c1(1,.4,4096,4,1,32).schema}}),Ui=v,Ai=class extends re{constructor(t){super(Pe,t);}},Yo="gemini-1.5-flash",Di="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",we=x(S,Z).parse({name:Yo,description:Di,maxInputTokens:1e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),Vi=v,zi=class extends N{constructor(t){super(we,t);}},Jo="gemini-1.5-flash-001",Hi="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",ke=x(S,Z).parse({name:Jo,description:Hi,maxInputTokens:1e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),Ki=v,Yi=class extends N{constructor(t){super(ke,t);}},Wo="gemini-1.5-flash-002",Ji="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",Ie=x(S,Z).parse({name:Wo,description:Ji,maxInputTokens:1e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,40).def,schema:u.c1(2,1,8192,4,.95,40).schema}}),Wi=v,Zi=class extends N{constructor(t){super(Ie,t);}},Zo="gemini-1.5-flash-latest",Xi="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Xo=x(S,Z).parse({name:Zo,description:Xi,maxInputTokens:1e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),Qi=v,es=class extends N{constructor(t){super(Xo,t);}},Qo="gemini-1.5-pro",ts="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",je=x(S,Z).parse({name:Qo,description:ts,maxInputTokens:2e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),os=v,ns=class extends N{constructor(t){super(je,t);}},en="gemini-1.5-pro-001",as="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Re=x(S,Z).parse({name:en,description:as,maxInputTokens:2e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),is=v,ss=class extends N{constructor(t){super(Re,t);}},tn="gemini-1.5-pro-002",rs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Ne=x(S,Z).parse({name:tn,description:rs,maxInputTokens:2e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,40).def,schema:u.c1(2,1,8192,4,.95,40).schema}}),ls=v,ms=class extends N{constructor(t){super(Ne,t);}},on="gemini-1.5-pro-latest",ds="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",nn=x(S,Z).parse({name:on,description:ds,maxInputTokens:2e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),cs=v,ps=class extends N{constructor(t){super(nn,t);}},an=[M],sn=zod.z.enum([M]),us=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))}),gs=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)})}),hs=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(gs).min(1),outputDimensionality:zod.z.number().int().min(1).optional()}),lt=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url(),getEmbeddingsUrl:zod.z.string().url().optional()}),rn=class{constructor(t,e){this.version="v1";let o=lt.parse(e);this.modelSchema=t,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=se(o.baseUrl),this.getEmbeddingsUrl=se(o.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(t){return {shouldRetry:!1,delayMs:0}}getTokenCount(t){return t.requests.reduce((e,o)=>e+o.length,0)}transformModelRequest(t){let e=hs.safeParse(t);if(!e.success)throw new V({info:"Invalid model request",cause:e.error});let o=e.data,i=o.model,s={outputDimensionality:o.outputDimensionality},r=ce().parse(ge(s)),d={modality:M,requests:o.requests.reduce((m,c)=>(m.push(...c.content.parts.map(p=>p.text)),m),[])};return {modelName:i,config:r,embeddingRequests:d}}transformConfig(t,e){let o=this.modelSchema.config.schema.safeParse(t);if(!o.success)throw new F({info:`Invalid config for model : '${this.modelName}'`,cause:o.error});let i=o.data;return Object.keys(i).forEach(s=>{if(!this.modelSchema.config.def[s])throw new F({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${s}',
13
+ available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}}),i[0].role!==this.modelSchema.roles[I])throw new T({info:`Invalid message 'role' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires first message to be from user`)});let s=r=>r===this.modelSchema.roles[I]||r===this.modelSchema.roles[Y]?[this.modelSchema.roles[L]]:[this.modelSchema.roles[I],this.modelSchema.roles[Y]];for(let r=1;r<i.length;r++)if(!s(i[r-1].role).includes(i[r].role))throw new T({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' cannot have message with role : '${i[r].role}' after message with role : '${i[r-1].role}'`)});if(i[i.length-1].role!==this.modelSchema.roles[I]&&i[i.length-1].role!==this.modelSchema.roles[Y])throw new T({info:`Invalid message format for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' requires last message to be from user`)});return O({contents:i},o.parts.length>0?{system_instruction:o}:{})}transformTools(t){if(!this.modelSchema.modalities.includes(w))throw new ot({info:`Invalid tool 'modality' for model : ${this.modelName}`,cause:new Error(`model : '${this.modelName}' does not support tool modality : '${w}'`)});return !t||t&&t.length===0?{tools:[]}:{tools:[{function_declarations:t.map(e=>{let o=Vt().safeParse(e);if(!o.success)throw new ot({info:"Invalid tools",cause:o.error});return o.data}).map(e=>({name:e.definition.schema.name,description:e.definition.schema.description,parameters:e.definition.schema.parameters}))}]}}getCompleteChatUrl(t,e,o){return z(this,null,function*(){return new Promise(i=>{i(this.completeChatUrl);})})}getCompleteChatHeaders(t,e,o){return z(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getCompleteChatData(t,e,o){return z(this,null,function*(){let i=this.transformConfig(t,e,o),s=this.transformMessages(e);if(s.messages&&s.messages.length===0)throw new T({info:"Messages are required",cause:new Error("Messages are required")});let r=o?this.transformTools(o):{};return new Promise(d=>{d(O(O(O(O({},this.getDefaultParams()),i),s),r));})})}transformCompleteChatResponse(t){let e=gi.safeParse(t);if(e.success){if(e.data.candidates.length===0)throw new D({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(e.data)}`)});let o=e.data,i=[],s,r=o.candidates[0].content;if(r){let m=r.parts.map((c,p)=>{if("text"in c&&c.text!==void 0)return Bt(c.text);if("functionCall"in c&&c.functionCall!==void 0)return Ut(p,`${c.functionCall.name}_${p}`,c.functionCall.name,JSON.stringify(c.functionCall.args))});return i.push({role:L,content:m}),o.usageMetadata&&(s={promptTokens:o.usageMetadata.promptTokenCount,totalTokens:o.usageMetadata.totalTokenCount,completionTokens:o.usageMetadata.candidatesTokenCount||0}),{messages:i,usage:s,logProbs:void 0}}let d=o.candidates[0].safetyRatings;if(d&&d.length>0&&d.forEach(m=>{if(m.blocked)throw new D({info:`Blocked content for category: ${m.category} with probability: ${m.probability}`,cause:new Error(`Blocked content for category: ${m.category} with probability: ${m.probability}`)})}),o.candidates[0].finishReason==="SAFETY")throw new D({info:"Blocked content, model response finished with safety reason",cause:new Error("Blocked content, model response finished with safety reason")})}throw new D({info:"Invalid response from model",cause:e.error})}getStreamChatUrl(t,e,o){return z(this,null,function*(){return new Promise(i=>{i(this.streamChatUrl);})})}getStreamChatHeaders(t,e,o){return z(this,null,function*(){return new Promise(i=>{i(this.getDefaultHeaders());})})}getStreamChatData(t,e,o){return z(this,null,function*(){let i=this.transformConfig(t,e,o),s=this.transformMessages(e);if(s.messages&&s.messages.length===0)throw new T({info:"Messages are required",cause:new Error("Messages are required")});let r=o?this.transformTools(o):{};return new Promise(d=>{d(O(O(O(O({},this.getDefaultParams()),i),s),r));})})}transformStreamChatResponseChunk(t,e){return ni(this,null,function*(){let o=(e+t).split(",\r").filter(i=>i.trim()!=="");for(let i of o){let s=i;if(s=s.replace(/\n/g,""),s.startsWith("["))s=s.slice(1);else if(s.endsWith("]")){if(s==="]")return;s=s.slice(0,-1);}let r;try{r=JSON.parse(s);}catch(m){if(m instanceof SyntaxError){e=s;continue}else throw m}e="";let d=yi.safeParse(r);if(d.success){let m={partialMessages:[]},c=d.data;if(c.candidates.length>0){let p=c.candidates[0].content;p&&"parts"in p&&p.parts.length>0&&p.parts.forEach((g,f)=>{if("text"in g&&g.text!==void 0&&m.partialMessages.push(At(L,g.text)),"functionCall"in g&&g.functionCall!==void 0){let h=g.functionCall;m.partialMessages.push(Dt(L,f,`${h.name}_${f}`,h.name,JSON.stringify(h.args)));}});}c.usageMetadata&&(m.usage={promptTokens:c.usageMetadata.promptTokenCount,completionTokens:c.usageMetadata.candidatesTokenCount,totalTokens:c.usageMetadata.totalTokenCount}),yield {partialResponse:m,buffer:e};}else throw new D({info:"Invalid response from model",cause:d.error})}yield {partialResponse:{partialMessages:[]},buffer:e};})}},re=class extends N{transformMessages(t){let e=super.transformMessages(t);if(e.systemInstruction){let o={role:this.modelSchema.roles[I],parts:e.systemInstruction.parts};e.contents.unshift(o),delete e.systemInstruction;}return e}},qo="gemini-pro",Ci="A model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",Bo=x(S,Oe).parse({name:qo,description:Ci,maxInputTokens:30720,maxOutputTokens:2048,roles:G,modalities:Ce,config:{def:u.base(1,.9,2048,4,1).def,schema:u.base(1,.9,2048,4,1).schema}}),Oi=v,Si=class extends re{constructor(t){super(Bo,t);}},Uo="gemini-pro-vision",Gi="An image understanding model to handle a broad range of applications",Ao=x(S,Lo).parse({name:Uo,description:Gi,maxInputTokens:12288,maxOutputTokens:4096,roles:G,modalities:No,config:{def:u.c1(1,.4,4096,4,1,32).def,schema:u.c1(1,.4,4096,4,1,32).schema}}),Pi=v,wi=class extends re{constructor(t){super(Ao,t);}},Do="gemini-1.0-pro",ki="Google's predecessor to Gemini 1.5 Pro, a model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",Se=x(S,Oe).parse({name:Do,description:ki,maxInputTokens:30720,maxOutputTokens:2048,roles:G,modalities:Ce,config:{def:u.base(1,.9,2048,4,1).def,schema:u.base(1,.9,2048,4,1).schema}}),Ii=v,ji=class extends re{constructor(t){super(Se,t);}},Vo="gemini-1.0-pro-001",Ri="Google's predecessor to Gemini 1.5 Pro, a model for scaling across a wide range of tasks Optimized for natural language tasks, multi-turn text and code chat, and code generation",Ge=x(S,Oe).parse({name:Vo,description:Ri,maxInputTokens:30720,maxOutputTokens:2048,roles:G,modalities:Ce,config:{def:u.base(1,.9,2048,4,1).def,schema:u.base(1,.9,2048,4,1).schema}}),Ni=v,Li=class extends re{constructor(t){super(Ge,t);}},zo="gemini-1.0-pro-latest",Fi="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for natural language tasks, multi-turn text and code chat, and code generation",Ho=x(S,Oe).parse({name:zo,description:Fi,maxInputTokens:30720,maxOutputTokens:2048,roles:G,modalities:Ce,config:{def:u.base(1,.9,2048,4,1).def,schema:u.base(1,.9,2048,4,1).schema}}),$i=v,qi=class extends re{constructor(t){super(Ho,t);}},Ko="gemini-1.0-pro-vision",Bi="Google's predecessor to Gemini 1.5 Pro, an image understanding model to handle a broad range of applications",Pe=x(S,Lo).parse({name:Ko,description:Bi,maxInputTokens:12288,maxOutputTokens:4096,roles:G,modalities:No,config:{def:u.c1(1,.4,4096,4,1,32).def,schema:u.c1(1,.4,4096,4,1,32).schema}}),Ui=v,Ai=class extends re{constructor(t){super(Pe,t);}},Yo="gemini-1.5-flash",Di="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",we=x(S,Z).parse({name:Yo,description:Di,maxInputTokens:1e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),Vi=v,zi=class extends N{constructor(t){super(we,t);}},Jo="gemini-1.5-flash-001",Hi="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",ke=x(S,Z).parse({name:Jo,description:Hi,maxInputTokens:1e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),Ki=v,Yi=class extends N{constructor(t){super(ke,t);}},Wo="gemini-1.5-flash-002",Ji="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",Ie=x(S,Z).parse({name:Wo,description:Ji,maxInputTokens:1e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,40).def,schema:u.c1(2,1,8192,4,.95,40).schema}}),Wi=v,Zi=class extends N{constructor(t){super(Ie,t);}},Zo="gemini-1.5-flash-latest",Xi="Google's latest multimodal model with great performance for high-frequency tasks. Optimized for fast and versatile performance across a diverse variety of tasks",Xo=x(S,Z).parse({name:Zo,description:Xi,maxInputTokens:1e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),Qi=v,es=class extends N{constructor(t){super(Xo,t);}},Qo="gemini-1.5-pro",ts="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",je=x(S,Z).parse({name:Qo,description:ts,maxInputTokens:2e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),os=v,ns=class extends N{constructor(t){super(je,t);}},en="gemini-1.5-pro-001",as="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Re=x(S,Z).parse({name:en,description:as,maxInputTokens:2e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),is=v,ss=class extends N{constructor(t){super(Re,t);}},tn="gemini-1.5-pro-002",rs="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",Ne=x(S,Z).parse({name:tn,description:rs,maxInputTokens:2e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,40).def,schema:u.c1(2,1,8192,4,.95,40).schema}}),ls=v,ms=class extends N{constructor(t){super(Ne,t);}},on="gemini-1.5-pro-latest",ds="Google's best performing multimodal model with features for a wide variety of reasoning tasks. Optimized for complex reasoning tasks requiring more intelligence",nn=x(S,Z).parse({name:on,description:ds,maxInputTokens:2e6,maxOutputTokens:8192,roles:G,modalities:W,config:{def:u.c1(2,1,8192,4,.95,64).def,schema:u.c1(2,1,8192,4,.95,64).schema}}),cs=v,ps=class extends N{constructor(t){super(nn,t);}},an=[M],sn=zod.z.enum([M]),us=zod.z.object({embeddings:zod.z.array(zod.z.object({values:zod.z.array(zod.z.number())}))}),gs=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)})}),hs=zod.z.object({model:zod.z.string().min(1).optional(),requests:zod.z.array(gs).min(1),outputDimensionality:zod.z.number().int().min(1).optional()}),lt=zod.z.object({modelName:zod.z.string(),apiKey:zod.z.string(),baseUrl:zod.z.string().url(),getEmbeddingsUrl:zod.z.string().url().optional()}),rn=class{constructor(t,e){this.version="v1";let o=lt.parse(e);this.modelSchema=t,this.modelName=o.modelName,this.apiKey=o.apiKey,this.baseUrl=se(o.baseUrl),this.getEmbeddingsUrl=se(o.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(t){return {shouldRetry:!1,delayMs:0}}getTokenCount(t){return t.requests.reduce((e,o)=>e+o.length,0)}transformModelRequest(t){let e=hs.safeParse(t);if(!e.success)throw new V({info:"Invalid model request",cause:e.error});let o=e.data,i=o.model,s={outputDimensionality:o.outputDimensionality},r=ce().parse(ge(s)),d={modality:M,requests:o.requests.reduce((m,c)=>(m.push(...c.content.parts.map(p=>p.text)),m),[])};return {modelName:i,config:r,embeddingRequests:d}}transformConfig(t,e){let o=this.modelSchema.config.schema.safeParse(t);if(!o.success)throw new F({info:`Invalid config for model : '${this.modelName}'`,cause:o.error});let i=o.data;return Object.keys(i).forEach(s=>{if(!this.modelSchema.config.def[s])throw new F({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${s}',
14
14
  available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(i).reduce((s,r)=>{let d=this.modelSchema.config.def[r].param,m=i[r];return s[d]=m,s},{})}transformEmbeddingRequests(t){let e=fe().safeParse(t);if(!e.success)throw new J({info:"Invalid embedding requests",cause:e.error});if(t.modality!==M)throw new J({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error(`Only '${M}' modality is supported for model : '${this.modelName}'`)});return {requests:e.data.requests.map(o=>({model:`models/${this.modelName}`,content:{parts:[{text:o}]}}))}}getGetEmbeddingsUrl(t,e){return z(this,null,function*(){return new Promise(o=>{o(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(t,e){return z(this,null,function*(){return new Promise(o=>{o(this.getDefaultHeaders());})})}getGetEmbeddingsData(t,e){return z(this,null,function*(){return new Promise(o=>{let i=this.transformConfig(t),s=this.transformEmbeddingRequests(e);if(e.requests.length===0)throw new J({info:`Invalid embedding requests for model : '${this.modelName}'`,cause:new Error("requests cannot be empty")});i.outputDimensionality&&(s.requests.forEach(r=>{r.outputDimensionality=i.outputDimensionality;}),delete i.outputDimensionality),o(O(O(O({},this.getDefaultParams()),i),s));})})}transformGetEmbeddingsResponse(t){let e=us.safeParse(t);if(e.success){let o=e.data.embeddings.map((i,s)=>({index:s,embedding:i.values}));return {encodingFormat:pe,embeddings:o}}throw new D({info:"Invalid response from model",cause:e.error})}},ln="text-embedding-001",fs="text-embedding-001",mn=R(sn).parse({name:ln,description:fs,modalities:an,maxInputTokens:2048,maxOutputTokens:768,config:{def:be.base(768).def,schema:be.base(768).schema}}),ys=lt,bs=class extends rn{constructor(t){super(mn,t);}},dn="text-embedding-004",_s="text-embedding-004",cn=R(sn).parse({name:dn,description:_s,modalities:an,maxInputTokens:2048,maxOutputTokens:768,config:{def:be.base(768).def,schema:be.base(768).schema}}),Es=lt,Ts=class extends rn{constructor(t){super(cn,t);}};var Ms="vertex",ee=class{constructor(){this.version="v1";this.name=Ms;this.chatModelFactories={[bn]:{model:qe,modelOptions:_n,modelSchema:pt},[En]:{model:Be,modelOptions:Tn,modelSchema:ut},[Mn]:{model:Ue,modelOptions:xn,modelSchema:gt},[vn]:{model:Ae,modelOptions:Cn,modelSchema:ht},[On]:{model:De,modelOptions:Sn,modelSchema:ft},[Gn]:{model:Ve,modelOptions:Pn,modelSchema:yt},[pn]:{model:Le,modelOptions:un,modelSchema:mt},[fn]:{model:$e,modelOptions:yn,modelSchema:ct},[gn]:{model:Fe,modelOptions:hn,modelSchema:dt}};this.embeddingModelFactories={[bt]:{model:ze,modelOptions:wn,modelSchema:_t},[Et]:{model:He,modelOptions:kn,modelSchema:Tt},[vt]:{model:Ye,modelOptions:jn,modelSchema:Ct},[Mt]:{model:Ke,modelOptions:In,modelSchema:xt}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,o)=>(e[o]=this.chatModelFactories[o].modelSchema,e),{})}chatModel(e){let o=e.modelName;if(!(o in this.chatModelFactories))throw new ae({info:`Vertex chat model: ${o} not found`,cause:new Error(`Vertex chat model: ${o} not found, available chat models:
15
15
  ${this.chatModelLiterals().join(", ")}`)});let i=this.chatModelFactories[o].model,s=this.chatModelFactories[o].modelOptions.parse(e);return new i(s)}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModelSchemas(){return Object.keys(this.embeddingModelFactories).reduce((e,o)=>(e[o]=this.embeddingModelFactories[o].modelSchema,e),{})}embeddingModel(e){let o=e.modelName;if(!(o in this.embeddingModelFactories))throw new ae({info:`Vertex embedding model: ${o} not found`,cause:new Error(`Vertex embedding model: ${o} not found, available embedding models:
16
16
  ${this.embeddingModelLiterals().join(", ")}`)});let i=this.embeddingModelFactories[o].model,s=this.embeddingModelFactories[o].modelOptions.parse(e);return new i(s)}};ee.baseUrl=(e,o,i="google")=>`https://${e}-aiplatform.googleapis.com/v1/projects/${o}/locations/${e}/publishers/${i}`;var b=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()}),y=class extends N{constructor(o,i){let s=b.parse(i),r;if(s.baseUrl)r=s.baseUrl;else if(s.location&&s.projectId)r=ee.baseUrl(s.location,s.projectId,s.publisher);else throw new ye({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(o,{modelName:s.modelName,apiKey:"random-api-key",completeChatUrl:`${r}/models/${s.modelName}:generateContent`,streamChatUrl:`${r}/models/${s.modelName}:streamGenerateContent`});this.version="v1";this.modelSchema=o,this.modelName=s.modelName,this.accessToken=s.accessToken,this.location=s.location,this.projectId=s.projectId,this.publisher=s.publisher;}getDefaultHeaders(){return wt(ne({},super.getDefaultHeaders()),{Authorization:`Bearer ${this.accessToken}`})}};var pn="gemini-1.0-pro",mt=Se,un=b,Le=class extends y{constructor(e){super(mt,e);}};var gn="gemini-1.0-pro-001",dt=Ge,hn=b,Fe=class extends y{constructor(e){super(dt,e);}};var fn="gemini-1.0-pro-vision",ct=Pe,yn=b,$e=class extends y{constructor(e){super(ct,e);}};var bn="gemini-1.5-flash-001",pt=ke,_n=b,qe=class extends y{constructor(e){super(pt,e);}};var En="gemini-1.5-flash-002",ut=Ie,Tn=b,Be=class extends y{constructor(e){super(ut,e);}};var Mn="gemini-1.5-flash",gt=we,xn=b,Ue=class extends y{constructor(e){super(gt,e);}};var vn="gemini-1.5-pro-001",ht=Re,Cn=b,Ae=class extends y{constructor(e){super(ht,e);}};var On="gemini-1.5-pro-002",ft=Ne,Sn=b,De=class extends y{constructor(e){super(ft,e);}};var Gn="gemini-1.5-pro",yt=je,Pn=b,Ve=class extends y{constructor(e){super(yt,e);}};var X=[M],Q=zod.z.enum([M]);var Rn=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 Nn=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 K=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()}),q=class{constructor(e,o){this.version="v1";let i=K.parse(o);this.modelSchema=e,this.modelName=i.modelName,this.accessToken=i.accessToken;let s;if(i.baseUrl)s=i.baseUrl;else if(i.location&&i.projectId)s=ee.baseUrl(i.location,i.projectId,i.publisher);else throw new ye({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(e){return {shouldRetry:!1,delayMs:0}}getTokenCount(e){return e.requests.reduce((o,i)=>o+i.length,0)}transformModelRequest(e){var c,p,g,f;let o=Nn.safeParse(e);if(!o.success)throw new V({info:"Invalid model request",cause:o.error});let i=o.data,s=i.model,r={autoTruncate:((c=i.parameters)==null?void 0:c.auto_truncate)||((p=i.parameters)==null?void 0:p.autoTruncate),dimensions:((g=i.parameters)==null?void 0:g.output_dimensionality)||((f=i.parameters)==null?void 0:f.outputDimensionality)},d=ce().parse(ge(r)),m={modality:M,requests:i.instances.map(h=>h.content)};return {modelName:s,config:d,embeddingRequests:m}}transformConfig(e,o){let i=this.modelSchema.config.schema.safeParse(e);if(!i.success)throw new F({info:`Invalid config for model : '${this.modelName}'`,cause:i.error});let s=i.data;return Object.keys(s).forEach(d=>{if(!this.modelSchema.config.def[d])throw new F({info:`Invalid config for model : '${this.modelName}'`,cause:new Error(`Invalid config key : '${d}',