UNPKG

@adaline/types

Version:
8 lines (6 loc) 26.5 kB
import { z } from 'zod'; var Sn=Object.defineProperty;var cn=Object.getOwnPropertySymbols;var Ln=Object.prototype.hasOwnProperty,vn=Object.prototype.propertyIsEnumerable;var mn=(e,n,t)=>n in e?Sn(e,n,{enumerable:true,configurable:true,writable:true,value:t}):e[n]=t,ve=(e,n)=>{for(var t in n||(n={}))Ln.call(n,t)&&mn(e,t,n[t]);if(cn)for(var t of cn(n))vn.call(n,t)&&mn(e,t,n[t]);return e};var An="system",In="user",pe="assistant",jn="tool",Vn=[An,In,pe,jn],gn=z.enum(Vn),wn=[pe],fn=z.enum(wn);var O="error",ye="safety",Fn=z.object({type:z.literal(ye),value:z.object({category:z.string(),probability:z.string(),blocked:z.boolean(),message:z.string()})}),ue="response_error",qn=z.object({type:z.literal(ue),value:z.object({code:z.string(),message:z.string(),provider:z.string().optional()})}),Te=(e=z.undefined())=>z.object({modality:z.literal(O),value:z.discriminatedUnion("type",[Fn,qn]),metadata:e}),q="partial-error",Bn=z.object({type:z.literal(ye),category:z.string().optional(),probability:z.string().optional(),blocked:z.boolean().optional(),message:z.string().optional()}),$n=z.object({type:z.literal(ue),code:z.string().optional(),message:z.string().optional(),provider:z.string().optional()}),te=(e=z.undefined())=>z.object({modality:z.literal(q),value:z.discriminatedUnion("type",[Bn,$n]),metadata:e});var ce="image",Ae="base64",Dn=["png","jpeg","webp","gif"],Nn=z.object({type:z.literal(Ae),base64:z.string(),mediaType:z.enum(Dn)}),Ie="url",_n=z.object({type:z.literal(Ie),url:z.string()}),On=z.discriminatedUnion("type",[Nn,_n]),Gn=["low","medium","high","auto"],Hn=z.enum(Gn),ge=(e=z.undefined())=>z.object({modality:z.literal(ce),detail:Hn,value:On,metadata:e});var je="pdf",Jn="base64",Wn=z.object({type:z.literal(Jn),base64:z.string()}),Qn="url",Kn=z.object({type:z.literal(Qn),url:z.string()}),Xn=z.discriminatedUnion("type",[Wn,Kn]),Cn=(e=z.undefined())=>z.object({modality:z.literal(je),value:Xn,file:z.object({name:z.string(),id:z.string(),size:z.number().optional()}),metadata:e});var B="reasoning",I="partial-reasoning",k="thinking",S="redacted",Ve=z.object({type:z.literal(k),thinking:z.string(),signature:z.string()}),Mn=z.object({type:z.literal(S),data:z.string()}),Yn=z.discriminatedUnion("type",[Ve,Mn]),oe=(e=z.undefined())=>z.object({modality:z.literal(B),value:Yn,metadata:e}),et=z.object({type:z.literal(k),thinking:Ve.shape.thinking.optional(),signature:Ve.shape.signature.optional()}),nt=z.discriminatedUnion("type",[et,Mn]),fe=(e=z.undefined())=>z.object({modality:z.literal(I),value:nt,metadata:e});var ae="search-result",tt=z.object({type:z.string().optional(),query:z.string(),responses:z.array(z.object({source:z.string(),url:z.string(),title:z.string(),snippet:z.string().optional()})),references:z.array(z.object({text:z.string(),responseIndices:z.array(z.number()),startIndex:z.number().optional(),endIndex:z.number().optional(),confidenceScores:z.array(z.number()).optional()}))}),he=(e=z.undefined())=>z.object({modality:z.literal(ae),value:tt,metadata:e}),G="partial-search-result",ot=z.object({type:z.string().optional(),query:z.string().optional(),responses:z.array(z.object({source:z.string().optional(),url:z.string().optional(),title:z.string().optional(),snippet:z.string().optional()})).optional(),references:z.array(z.object({text:z.string().optional(),responseIndices:z.array(z.number()).optional(),startIndex:z.number().optional(),endIndex:z.number().optional(),confidenceScores:z.array(z.number()).optional()})).optional()}),Ce=(e=z.undefined())=>z.object({modality:z.literal(G),value:ot,metadata:e});var K="text",Me=(e=z.undefined())=>z.object({modality:z.literal(K),value:z.string(),metadata:e}),X="partial-text",Ze=(e=z.undefined())=>z.object({modality:z.literal(X),value:z.string(),metadata:e});var Y="tool-call",Re=(e=z.undefined())=>z.object({modality:z.literal(Y),index:z.number().int().nonnegative(),id:z.string().min(1),name:z.string().min(1),arguments:z.string(),serverName:z.string().optional(),thoughtSignature:z.string().optional(),metadata:e}),V="partial-tool-call",Ee=(e=z.undefined())=>z.object({modality:z.literal(V),index:z.number().int().nonnegative(),id:z.string().optional(),name:z.string().optional(),arguments:z.string().optional(),serverName:z.string().optional(),thoughtSignature:z.string().optional(),metadata:e});var ee="tool-response",ze=(e=z.undefined())=>z.object({modality:z.literal(ee),index:z.number().int().nonnegative(),id:z.string().min(1),name:z.string().min(1),data:z.string(),apiResponse:z.object({statusCode:z.number().int().nonnegative()}).optional(),metadata:e}),D="partial-tool-response",Ue=(e=z.undefined())=>z.object({modality:z.literal(D),index:z.number().int().nonnegative(),id:z.string().optional(),name:z.string().optional(),data:z.string().optional(),apiResponse:z.object({statusCode:z.number().int().nonnegative()}).optional(),metadata:e});var at=[K,ce,je,Y,ee,B,O,ae],lo=z.enum(at),Rn=(e=z.undefined(),n=z.undefined(),t=z.undefined(),o=z.undefined(),r=z.undefined(),y=z.undefined(),E=z.undefined(),F=z.undefined())=>z.discriminatedUnion("modality",[Me(e),ge(n),Cn(t),Re(o),ze(r),oe(y),Te(E),he(F)]),rt=[X,V,I,q,G],po=z.enum(rt),zn=(e=z.undefined(),n=z.undefined(),t=z.undefined(),o=z.undefined(),r=z.undefined(),y=z.undefined())=>z.discriminatedUnion("modality",[Ze(e),Ee(n),fe(o),Ue(t),te(r),Ce(y)]);var it="token",co=(e=z.undefined())=>z.object({modality:z.literal(it),value:z.array(z.number().int().nonnegative()),metadata:e});var N=(e=gn,n=z.undefined(),t=z.undefined(),o=z.undefined(),r=z.undefined(),y=z.undefined(),E=z.undefined(),F=z.undefined())=>z.object({role:e,content:z.array(Rn(n,t,o,r,E,y)),metadata:F}),$=(e=fn,n=z.undefined(),t=z.undefined(),o=z.undefined(),r=z.undefined(),y=z.undefined())=>z.object({role:e,partialContent:zn(n,t,o,y),metadata:r});var st=z.object({promptTokens:z.number().nonnegative(),completionTokens:z.number().nonnegative(),totalTokens:z.number().nonnegative()}),bn=z.object({token:z.string(),logProb:z.number(),bytes:z.array(z.number().int()).nullable()}),lt=bn.extend({topLogProbs:z.array(bn)}),Pn=z.array(lt),zo=z.object({messages:z.array(N()),usage:st.optional(),logProbs:Pn.optional()}),dt=z.object({promptTokens:z.number().nonnegative().optional(),completionTokens:z.number().nonnegative().optional(),totalTokens:z.number().nonnegative().optional()}),bo=z.object({partialMessages:z.array($()),usage:dt.optional(),logProbs:Pn.optional()});var ho=(e=z.record(z.string(),z.any()).optional())=>e;var pt=z.object({enabled:z.boolean().default(true),allowedTools:z.array(z.string().min(1))}),Uo=z.object({type:z.literal("url"),url:z.string().url().refine(e=>e.startsWith("https://"),{message:"MCP server URL must start with https://"}),name:z.string().min(1),toolConfiguration:pt.optional(),authorizationToken:z.string().min(1).optional()});var yt=["object","array","number","string","boolean","enum"],xn=z.enum(yt),ut=z.object({anyOf:z.array(z.any()).optional(),type:z.union([xn,z.array(z.union([xn,z.literal("null")]))]).optional(),default:z.any().optional(),title:z.string().optional(),description:z.string().max(4096).optional(),properties:z.record(z.any()).optional(),required:z.array(z.string()).optional(),minItems:z.number().int().min(0).optional(),maxItems:z.number().int().optional(),items:z.record(z.any()).optional(),enum:z.array(z.union([z.string(),z.number(),z.boolean(),z.null()])).optional(),minimum:z.number().optional(),maximum:z.number().optional(),minLength:z.number().int().min(0).optional(),maxLength:z.number().int().optional(),$ref:z.string().optional()}),ct=z.object({type:z.enum(["object"]),required:z.array(z.string()),$defs:z.record(z.any()).optional(),properties:z.record(ut),additionalProperties:z.literal(false)}),Lo=z.object({name:z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:z.string().max(4096),strict:z.boolean().optional(),schema:ct}).optional();var hn="text",Zn="token",mt=[hn,Zn],Io=z.enum(mt),Tt=z.array(z.string().min(1)),gt=z.array(z.array(z.number().int().nonnegative())),jo=(e=z.undefined())=>z.discriminatedUnion("modality",[z.object({modality:z.literal(hn),metadata:e,requests:Tt}),z.object({modality:z.literal(Zn),metadata:e,requests:gt})]);var ft="float",Ct=z.object({index:z.number().int().nonnegative(),embedding:z.array(z.number())}),Mt="base64",Rt=z.object({index:z.number().int().nonnegative(),embedding:z.string().base64()}),En=z.object({totalTokens:z.number().int().nonnegative()}),Fo=z.discriminatedUnion("encodingFormat",[z.object({encodingFormat:z.literal(ft),embeddings:z.array(Ct),usage:En.optional()}),z.object({encodingFormat:z.literal(Mt),embeddings:z.array(Rt),usage:En.optional()})]);var zt=e=>{let n=new WeakSet;return JSON.stringify(e,(t,o)=>{if(typeof o=="object"&&o!==null){if(n.has(o))return;n.add(o);}return o})},bt=e=>e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:zt(e),Fe="GatewayBaseError",_=class e extends Error{constructor({info:t,cause:o},r){super(`[${r!=null?r:Fe}]: ${t} Message: ${bt(o)}`);this.name=Fe;this.info=t,this.cause=o,this.name=r!=null?r:Fe,Object.setPrototypeOf(this,new.target.prototype);}static isGatewayBaseError(t){return t instanceof e}toJSON(){return {name:this.name,info:this.info,cause:this.cause,message:this.message,stack:this.stack}}};var Pt=z.object({inputPricePerMillion:z.number().nonnegative().describe("Price per 1M input tokens"),outputPricePerMillion:z.number().nonnegative().describe("Price per 1M output tokens")}).describe("Input/output price pair (per 1M tokens) for a specific category within a ChatModel pricing tier."),xt=z.object({base:Pt.describe("Base (uncached, non\u2011reasoning) rates")}).describe("Holds the `ChatModelTokenPairPrice` for different categories (e.g., base) within a single pricing tier."),ht=z.object({minTokens:z.number().int().nonnegative().describe("Inclusive lower token bound for this tier."),maxTokens:z.number().int().nullable().optional().describe("Exclusive upper token bound; `null` means \u221E."),prices:xt.describe("Price categories and rates for this specific token range.")}).refine(e=>e.maxTokens===null||typeof e.maxTokens=="number"&&e.maxTokens>e.minTokens,{message:"maxTokens must be > minTokens (or null for infinite).",path:["maxTokens"]}).describe("A single pricing tier defined by a token range and associated prices."),Do=z.object({modelName:z.string().describe("Model name this schedule applies to."),currency:z.string().default("USD").describe("Currency code (e.g., USD)."),tokenRanges:z.array(ht).min(1).describe("Pricing tiers (`ChatModelTokenRangePrice`) schedule, sorted by minTokens.")}).superRefine((e,n)=>{let{tokenRanges:t}=e;t[0].minTokens!==0&&n.addIssue({code:z.ZodIssueCode.custom,path:["tokenRanges",0,"minTokens"],message:"The first tier must have minTokens = 0."});for(let r=1;r<t.length;r++){let y=t[r-1],E=t[r];if(y.maxTokens===null){n.addIssue({code:z.ZodIssueCode.custom,path:["tokenRanges",r-1,"maxTokens"],message:"Cannot define any tokenRanges after an infinite tier (maxTokens = null)."});break}E.minTokens!==y.maxTokens&&n.addIssue({code:z.ZodIssueCode.custom,path:["tokenRanges",r,"minTokens"],message:`Tier ${r} minTokens (${E.minTokens}) must equal previous tier's maxTokens (${y.maxTokens}) for contiguity.`}),E.minTokens<y.minTokens&&n.addIssue({code:z.ZodIssueCode.custom,path:["tokenRanges",r,"minTokens"],message:`tokenRanges must be sorted by ascending minTokens. Tier ${r} (${E.minTokens}) starts before Tier ${r-1} (${y.minTokens}).`});}let o=t[t.length-1];t.every(r=>r.maxTokens!==null||r===o)&&o.maxTokens!==null&&n.addIssue({code:z.ZodIssueCode.custom,path:["tokenRanges",t.length-1,"maxTokens"],message:"The final tier must have maxTokens = null (representing infinity)."});}).describe("Complete pricing schedule for a single chat model, including all its token-based tiers.");var Oo=z.object({modelName:z.string().min(1).describe("Model name this price applies to."),currency:z.string().default("USD").describe("Currency code (e.g., USD)."),inputPricePerMillion:z.number().nonnegative().describe("Price per 1M input tokens.")}).describe("Complete (flat) pricing for a single embedding model.");var Un="function",Jo=["object","array","number","string","boolean","null"],Zt=z.enum(["object","array","number","string","boolean","null"]),Et=z.object({anyOf:z.array(z.any()).optional(),type:Zt.optional(),default:z.any().optional(),title:z.string().optional(),description:z.string().max(4096).optional(),properties:z.record(z.any()).optional(),required:z.array(z.string()).optional(),minItems:z.number().int().min(0).optional(),maxItems:z.number().int().optional(),items:z.record(z.any()).optional(),enum:z.array(z.union([z.string(),z.number(),z.boolean(),z.null()])).optional(),minimum:z.number().optional(),maximum:z.number().optional(),minLength:z.number().int().min(0).optional(),maxLength:z.number().int().optional()}),Wo=z.object({type:z.enum(["object"]),title:z.string().optional(),$defs:z.record(z.any()).optional(),properties:z.record(Et).optional(),required:z.array(z.string()).optional()}),Ut=z.object({name:z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:z.string().max(4096),parameters:z.any(),strict:z.boolean().optional()}),Qo=["function"],kt=z.enum(["function"]),St=z.object({maxAttempts:z.number().int().positive(),initialDelay:z.number().int().positive(),exponentialFactor:z.number().int().positive()}),Lt=z.object({type:z.literal("http"),method:z.enum(["get","post"]),url:z.string().url(),headers:z.record(z.string()).optional(),query:z.record(z.string()).optional(),body:z.record(z.any()).optional(),proxyUrl:z.string().url().optional(),proxyHeaders:z.record(z.string()).optional(),retry:St.optional()}),vt=z.discriminatedUnion("type",[Lt]),kn=z.object({type:kt,definition:z.object({schema:Ut}),request:vt.optional()});var At=[Un],ea=z.enum(At),na=(e=z.undefined())=>z.discriminatedUnion("type",[kn.extend({metadata:e})]);var ya=e=>Me().parse({modality:K,value:e}),ua=(e,n,t,o,r,y)=>Re().parse({modality:Y,index:e,id:n,name:t,arguments:o,serverName:r,thoughtSignature:y}),ca=(e,n,t,o,r,y)=>ze().parse({modality:ee,index:e,id:n,name:t,data:o,apiResponse:r,metadata:y}),ma=(e,n)=>N().parse({role:e,content:[Me().parse({modality:K,value:n})]}),Ta=(e,n,t)=>N().parse({role:e,content:[ge().parse({modality:ce,detail:t,value:{type:Ie,url:n}})]}),ga=(e,n,t)=>N().parse({role:e,content:[ge().parse({modality:ce,detail:t,value:{type:Ae,base64:n}})]}),fa=(e,n,t,o,r,y)=>N().parse({role:e,content:[Re().parse({modality:Y,index:n,id:t,name:o,arguments:r,thoughtSignature:y})]}),Ca=(e,n,t,o,r)=>N().parse({role:e,content:[ze().parse({modality:ee,index:n,id:t,name:o,data:r})]}),Ma=(e,n)=>$().parse({role:e,partialContent:Ze().parse({modality:X,value:n})}),Ra=(e,n,t,o,r,y,E)=>$().parse({role:e,partialContent:Ee().parse({modality:V,index:n,id:t,name:o,arguments:r,serverName:y,thoughtSignature:E})}),za=(e,n,t,o,r)=>$().parse({role:e,partialContent:Ue().parse({modality:D,index:n,id:t,name:o,data:r})}),ba=(e,n)=>oe().parse({modality:B,value:{type:k,thinking:e,signature:n}}),Pa=(e,n,t)=>N().parse({role:e,content:[oe().parse({modality:B,value:{type:k,thinking:n,signature:t}})]}),xa=e=>oe().parse({modality:B,value:{type:S,data:e}}),ha=(e,n)=>N().parse({role:e,content:[oe().parse({modality:B,value:{type:S,data:n}})]}),Za=(e,n,t)=>$().parse({role:e,partialContent:fe().parse({modality:I,value:{type:k,thinking:n,signature:t}})}),Ea=(e,n)=>$().parse({role:e,partialContent:fe().parse({modality:I,value:{type:S,data:n}})}),Ua=(e,n,t,o)=>Te().parse({modality:O,value:{type:ye,value:{category:e,probability:n,blocked:t,message:o}}}),ka=(e,n,t,o)=>te().parse({modality:q,value:{type:ye,category:e,probability:n,blocked:t,message:o}}),Sa=(e,n,t,o,r)=>$().parse({role:e,partialContent:te().parse({modality:q,value:{type:ye,category:n,probability:t,blocked:o,message:r}})}),La=(e,n,t)=>Te().parse({modality:O,value:{type:ue,value:{code:e,message:n,provider:t}}}),va=(e,n,t)=>te().parse({modality:q,value:{type:ue,code:e,message:n,provider:t}}),Aa=(e,n,t,o)=>$().parse({role:e,partialContent:te().parse({modality:q,value:{type:ue,code:n,message:t,provider:o}})}),Ia=(e,n,t,o)=>he().parse({modality:ae,value:{type:e,query:n,responses:t,references:o}}),ja=(e,n,t,o)=>Ce().parse({modality:G,value:{type:e,query:n,responses:t,references:o}}),Va=(e,n,t,o,r)=>$().parse({role:e,partialContent:Ce().parse({modality:G,value:{type:n,query:t,responses:o,references:r}})});var Qa=e=>{var De;let n={messages:[]};if(!e||e.length===0)return n;let t=[],o=null,r=null,y,E,F=null,m=null,g=null,u=null,f=null,T=null,Pe=()=>{var L,ne,ie,v,c,se,le,de,Le;let h=null;if(o===X&&F!==null)h={modality:K,value:F};else if(o===V&&m)if(m.id&&m.name&&m.arguments!==void 0&&m.index!==void 0)h=ve({modality:Y,index:m.index,id:m.id,name:m.name,arguments:m.arguments},m.thoughtSignature?{thoughtSignature:m.thoughtSignature}:{});else throw new _({info:"Incomplete tool call data encountered during finalization. Required fields (id, name, arguments, index) were missing or incomplete.",cause:{currentToolCall:m}});else if(o===D&&g)if(g.id&&g.name&&g.data!==void 0&&g.index!==void 0)h={modality:ee,index:g.index,id:g.id,name:g.name,data:g.data,apiResponse:g.apiResponse};else throw new _({info:"Incomplete tool response data encountered during finalization. Required fields (id, name, data, index) were missing or incomplete.",cause:{currentToolResponse:g}});else if(o===I&&u){if(u.type===k)if(u.thinking!==void 0&&u.signature!==void 0)h={modality:B,value:{type:k,thinking:u.thinking,signature:u.signature}};else throw new _({info:"Incomplete 'thinking' reasoning data encountered during finalization. Required fields (thinking, signature) were missing or incomplete.",cause:{currentReasoning:u}});else if(u.type===S)if(u.data!==void 0)h={modality:B,value:{type:S,data:u.data}};else throw new _({info:"Incomplete 'redacted' reasoning data encountered during finalization. Required field (data) was missing or incomplete.",cause:{currentReasoning:u}})}else if(o===G&&f){let Ne=f.query&&f.query.length>0,_e=f.responses&&f.responses.length>0,Oe=f.references&&f.references.length>0;(Ne||_e||Oe)&&(h={modality:ae,value:{type:f.type,query:(L=f.query)!=null?L:"",responses:((ne=f.responses)!=null?ne:[]).map(A=>{var J,W,me;return {source:(J=A.source)!=null?J:"",url:(W=A.url)!=null?W:"",title:(me=A.title)!=null?me:"",snippet:A.snippet}}),references:((ie=f.references)!=null?ie:[]).map(A=>{var J,W;return {text:(J=A.text)!=null?J:"",responseIndices:(W=A.responseIndices)!=null?W:[],startIndex:A.startIndex,endIndex:A.endIndex,confidenceScores:A.confidenceScores}})}});}else o===q&&T&&(T.type==="safety"?h={modality:O,value:{type:"safety",value:{category:(v=T.category)!=null?v:"",probability:(c=T.probability)!=null?c:"",blocked:(se=T.blocked)!=null?se:false,message:(le=T.message)!=null?le:""}}}:T.type==="response_error"&&(h={modality:O,value:{type:"response_error",value:ve({code:(de=T.code)!=null?de:"",message:(Le=T.message)!=null?Le:""},T.provider!==void 0?{provider:T.provider}:{})}}));h&&t.push(h),F=null,m=null,g=null,u=null,f=null,T=null,o=null,r=null,y=void 0,E=void 0;};e.forEach((h,L)=>{h.partialMessages&&h.partialMessages.forEach((ne,ie)=>{var A,J,W,me,Ge,He,Je,We,Qe,Ke,Xe,Ye,en,nn,tn,on,an,rn,sn,ln,dn,pn,yn,un;if(ne.role!==pe)throw new _({info:`Unexpected message role encountered while merging partial messages. Expected '${pe}'.`,cause:{role:ne.role,chunkIndex:L,messageIndex:ie,message:ne}});let v=ne.partialContent,c=v.modality,se=null,le,de;if(c===I&&(se=v.value.type),c===V&&(le=v.index),c===D&&(de=v.index),(c!==o||c===I&&o===I&&se!==r||c===V&&o===V&&le!==y||c===D&&o===D&&de!==E)&&o!==null&&Pe(),o===null&&(o=c,c===I&&(r=se),c===V&&(y=le),c===D&&(E=de)),c===X){let p=v;F=(F!=null?F:"")+((A=p.value)!=null?A:"");}else if(c===V){let p=v;m?(m.id+=p.id||"",m.name+=p.name||"",m.arguments+=p.arguments||"",!m.thoughtSignature&&p.thoughtSignature&&(m.thoughtSignature=p.thoughtSignature)):m={index:p.index,id:(J=p.id)!=null?J:"",name:(W=p.name)!=null?W:"",arguments:(me=p.arguments)!=null?me:"",thoughtSignature:p.thoughtSignature};}else if(c===D){let p=v;g?(g.id+=p.id||"",g.name+=p.name||"",g.data+=p.data||"",!g.apiResponse&&p.apiResponse&&(g.apiResponse=p.apiResponse)):g={index:p.index,id:(Ge=p.id)!=null?Ge:"",name:(He=p.name)!=null?He:"",data:(Je=p.data)!=null?Je:"",apiResponse:p.apiResponse};}else if(c===I){let l=v.value;if(u)if(u.type===S&&l.type===S)Pe(),u={type:S,data:(Xe=l.data)!=null?Xe:""},o=c,r=l.type;else if(u.type===k&&l.type===k)u.thinking=((Ye=u.thinking)!=null?Ye:"")+((en=l.thinking)!=null?en:""),u.signature=((nn=u.signature)!=null?nn:"")+((tn=l.signature)!=null?tn:"");else throw new _({info:"Logic error: Mismatched reasoning types during accumulation.",cause:{currentReasoning:u,valuePart:l,chunkIndex:L,messageIndex:ie}});else if(l.type===k)u={type:k,thinking:(We=l.thinking)!=null?We:"",signature:(Qe=l.signature)!=null?Qe:""};else if(l.type===S)u={type:S,data:(Ke=l.data)!=null?Ke:""};else throw new _({info:`Unknown reasoning type encountered during initialization. Expected '${k}' or '${S}'.`,cause:{valuePart:l,chunkIndex:L,messageIndex:ie}})}else if(c===G){let l=v.value;f?(l.query&&l.query.length>0&&(f.query=l.query),l.responses&&l.responses.length>0&&(f.responses=[...(sn=f.responses)!=null?sn:[],...l.responses]),l.references&&l.references.length>0&&(f.references=[...(ln=f.references)!=null?ln:[],...l.references])):f={type:l.type,query:(on=l.query)!=null?on:"",responses:[...(an=l.responses)!=null?an:[]],references:[...(rn=l.references)!=null?rn:[]]};}else if(c===q){let l=v.value;T?T.type==="response_error"&&l.type==="response_error"?T={type:"response_error",code:(dn=T.code)!=null?dn:l.code,message:((pn=T.message)!=null?pn:"")+((yn=l.message)!=null?yn:""),provider:(un=T.provider)!=null?un:l.provider}:(Pe(),o=c,T=l):T=l;}});}),Pe(),n.messages=[{role:pe,content:t}];let Se,xe,Be=0,$e=false,re={promptTokens:0,completionTokens:0,totalTokens:0};for(let h of e){let L=h.usage;L&&($e=true,L.promptTokens!=null&&(Se===void 0&&(Se=L.promptTokens),xe=L.promptTokens),L.completionTokens!=null&&(Be+=L.completionTokens));}return $e?(re.promptTokens=(De=xe!=null?xe:Se)!=null?De:0,re.completionTokens=Be,re.totalTokens=re.promptTokens+re.completionTokens,n.usage=re):n.usage=void 0,n}; export { pe as AssistantRoleLiteral, Rt as Base64Embedding, Mt as Base64EmbeddingLiteral, Dn as Base64ImageContentMediaTypeLiterals, Ae as Base64ImageContentTypeLiteral, Nn as Base64ImageContentValue, Jn as Base64PdfContentTypeLiteral, Wn as Base64PdfContentValue, bn as ChatBaseLogProb, lt as ChatLogProb, Pn as ChatLogProbs, Do as ChatModelPrice, Pt as ChatModelTokenPairPrice, ht as ChatModelTokenRangePrice, xt as ChatModelTokenTypePrice, zo as ChatResponse, st as ChatUsage, ho as Config, Rn as Content, Io as EmbeddingModalityEnum, mt as EmbeddingModalityLiterals, Oo as EmbeddingModelPrice, jo as EmbeddingRequests, Fo as EmbeddingResponse, hn as EmbeddingTextModalityLiteral, Zn as EmbeddingTokenModalityLiteral, En as EmbeddingsUsage, Te as ErrorContent, O as ErrorModalityLiteral, Ct as FloatEmbedding, ft as FloatEmbeddingLiteral, Ut as Function, Et as FunctionParameter, Jo as FunctionParameterTypes, Zt as FunctionParameterTypesLiteral, Wo as FunctionParameters, vt as FunctionRequest, Lt as FunctionRequestHttp, St as FunctionRequestRetry, kn as FunctionTool, Un as FunctionToolLiteral, _ as GatewayBaseError, ge as ImageContent, Gn as ImageContentDetails, Hn as ImageContentDetailsLiteral, ce as ImageModalityLiteral, Uo as McpServer, pt as McpServerToolConfiguration, N as Message, lo as ModalityEnum, at as ModalityLiterals, bo as PartialChatResponse, dt as PartialChatUsage, zn as PartialContent, te as PartialErrorContent, q as PartialErrorModalityLiteral, $ as PartialMessage, po as PartialModalityEnum, rt as PartialModalityLiterals, fe as PartialReasoningContent, et as PartialReasoningContentValue, nt as PartialReasoningContentValueUnion, I as PartialReasoningModalityLiteral, $n as PartialResponseErrorContentValue, fn as PartialRoleEnum, wn as PartialRoleLiterals, Ce as PartialSearchResultContent, ot as PartialSearchResultContentValue, G as PartialSearchResultModalityLiteral, Ze as PartialTextContent, X as PartialTextModalityLiteral, Ee as PartialToolCallContent, V as PartialToolCallModalityLiteral, Ue as PartialToolResponseContent, D as PartialToolResponseModalityLiteral, Cn as PdfContent, je as PdfModalityLiteral, oe as ReasoningContent, k as ReasoningContentTypeLiteral, Ve as ReasoningContentValue, Yn as ReasoningContentValueUnion, B as ReasoningModalityLiteral, S as RedactedReasoningContentTypeLiteral, Mn as RedactedReasoningContentValue, qn as ResponseErrorContentValue, ue as ResponseErrorTypeLiteral, Lo as ResponseSchema, ut as ResponseSchemaProperty, ct as ResponseSchemaStructure, yt as ResponseSchemaTypes, xn as ResponseSchemaTypesLiteral, gn as RoleEnum, Vn as RoleLiterals, Fn as SafetyErrorContentValue, ye as SafetyErrorTypeLiteral, he as SearchResultContent, tt as SearchResultContentValue, ae as SearchResultModalityLiteral, An as SystemRoleLiteral, Me as TextContent, Tt as TextEmbeddingRequests, K as TextModalityLiteral, co as TokenContent, gt as TokenEmbeddingRequests, it as TokenModalityLiteral, na as Tool, Re as ToolCallContent, Y as ToolCallModalityLiteral, ea as ToolEnum, At as ToolLiterals, ze as ToolResponseContent, ee as ToolResponseModalityLiteral, jn as ToolRoleLiteral, Qo as ToolTypes, kt as ToolTypesLiteral, Ie as UrlImageContentTypeLiteral, _n as UrlImageContentValue, Qn as UrlPdfContentTypeLiteral, Kn as UrlPdfContentValue, In as UserRoleLiteral, ga as createBase64ImageMessage, Za as createPartialReasoningMessage, Ea as createPartialRedactedReasoningMessage, va as createPartialResponseErrorContent, Aa as createPartialResponseErrorMessage, ka as createPartialSafetyErrorContent, Sa as createPartialSafetyErrorMessage, ja as createPartialSearchResultContent, Va as createPartialSearchResultMessage, Ma as createPartialTextMessage, Ra as createPartialToolCallMessage, za as createPartialToolResponseMessage, ba as createReasoningContent, Pa as createReasoningMessage, xa as createRedactedReasoningContent, ha as createRedactedReasoningMessage, La as createResponseErrorContent, Ua as createSafetyErrorContent, Ia as createSearchResultContent, ya as createTextContent, ma as createTextMessage, ua as createToolCallContent, fa as createToolCallMessage, ca as createToolResponseContent, Ca as createToolResponseMessage, Ta as createUrlImageMessage, Qa as mergePartialMessages }; //# sourceMappingURL=index.mjs.map //# sourceMappingURL=index.mjs.map