// @bun
var n="vercel.ai.error",Pz=Symbol.for(n),N,R,X=class z extends(R=Error,N=Pz,R){constructor({name:Q,message:W,cause:G}){super(W);this[N]=!0,this.name=Q,this.cause=G}static isInstance(Q){return z.hasMarker(Q,n)}static hasMarker(Q,W){let G=Symbol.for(W);return Q!=null&&typeof Q==="object"&&G in Q&&typeof Q[G]==="boolean"&&Q[G]===!0}},a="AI_APICallError",o=`vercel.ai.error.${a}`,Sz=Symbol.for(o),V,T,iz=class extends(T=X,V=Sz,T){constructor({message:z,url:Q,requestBodyValues:W,statusCode:G,responseHeaders:Y,responseBody:Z,cause:A,isRetryable:q=G!=null&&(G===408||G===409||G===429||G>=500),data:K}){super({name:a,message:z,cause:A});this[V]=!0,this.url=Q,this.requestBodyValues=W,this.statusCode=G,this.responseHeaders=Y,this.responseBody=Z,this.isRetryable=q,this.data=K}static isInstance(z){return X.hasMarker(z,o)}},r="AI_EmptyResponseBodyError",e=`vercel.ai.error.${r}`,_z=Symbol.for(e),L,b,cz=class extends(b=X,L=_z,b){constructor({message:z="Empty response body"}={}){super({name:r,message:z});this[L]=!0}static isInstance(z){return X.hasMarker(z,e)}};function zz(z){if(z==null)return"unknown error";if(typeof z==="string")return z;if(z instanceof Error)return z.message;return JSON.stringify(z)}var Gz="AI_InvalidArgumentError",Qz=`vercel.ai.error.${Gz}`,Cz=Symbol.for(Qz),P,S,uz=class extends(S=X,P=Cz,S){constructor({message:z,cause:Q,argument:W}){super({name:Gz,message:z,cause:Q});this[P]=!0,this.argument=W}static isInstance(z){return X.hasMarker(z,Qz)}},Wz="AI_InvalidPromptError",Xz=`vercel.ai.error.${Wz}`,Iz=Symbol.for(Xz),_,C,lz=class extends(C=X,_=Iz,C){constructor({prompt:z,message:Q,cause:W}){super({name:Wz,message:`Invalid prompt: ${Q}`,cause:W});this[_]=!0,this.prompt=z}static isInstance(z){return X.hasMarker(z,Xz)}},Yz="AI_InvalidResponseDataError",Zz=`vercel.ai.error.${Yz}`,gz=Symbol.for(Zz),I,g,sz=class extends(g=X,I=gz,g){constructor({data:z,message:Q=`Invalid response data: ${JSON.stringify(z)}.`}){super({name:Yz,message:Q});this[I]=!0,this.data=z}static isInstance(z){return X.hasMarker(z,Zz)}},$z="AI_JSONParseError",Az=`vercel.ai.error.${$z}`,fz=Symbol.for(Az),f,E,tz=class extends(E=X,f=fz,E){constructor({text:z,cause:Q}){super({name:$z,message:`JSON parsing failed: Text: ${z}.
Error message: ${zz(Q)}`,cause:Q});this[f]=!0,this.text=z}static isInstance(z){return X.hasMarker(z,Az)}},Dz="AI_LoadAPIKeyError",Kz=`vercel.ai.error.${Dz}`,Ez=Symbol.for(Kz),y,h,nz=class extends(h=X,y=Ez,h){constructor({message:z}){super({name:Dz,message:z});this[y]=!0}static isInstance(z){return X.hasMarker(z,Kz)}},qz="AI_LoadSettingError",Hz=`vercel.ai.error.${qz}`,yz=Symbol.for(Hz),k,v,az=class extends(v=X,k=yz,v){constructor({message:z}){super({name:qz,message:z});this[k]=!0}static isInstance(z){return X.hasMarker(z,Hz)}},Uz="AI_NoContentGeneratedError",Mz=`vercel.ai.error.${Uz}`,hz=Symbol.for(Mz),m,p,oz=class extends(p=X,m=hz,p){constructor({message:z="No content generated."}={}){super({name:Uz,message:z});this[m]=!0}static isInstance(z){return X.hasMarker(z,Mz)}},jz="AI_NoSuchModelError",wz=`vercel.ai.error.${jz}`,kz=Symbol.for(wz),x,d,rz=class extends(d=X,x=kz,d){constructor({errorName:z=jz,modelId:Q,modelType:W,message:G=`No such ${W}: ${Q}`}){super({name:z,message:G});this[x]=!0,this.modelId=Q,this.modelType=W}static isInstance(z){return X.hasMarker(z,wz)}},Bz="AI_TooManyEmbeddingValuesForCallError",Jz=`vercel.ai.error.${Bz}`,vz=Symbol.for(Jz),i,c,ez=class extends(c=X,i=vz,c){constructor(z){super({name:Bz,message:`Too many values for a single embedding call. The ${z.provider} model "${z.modelId}" can only embed up to ${z.maxEmbeddingsPerCall} values per call, but ${z.values.length} values were provided.`});this[i]=!0,this.provider=z.provider,this.modelId=z.modelId,this.maxEmbeddingsPerCall=z.maxEmbeddingsPerCall,this.values=z.values}static isInstance(z){return X.hasMarker(z,Jz)}},Oz="AI_TypeValidationError",Fz=`vercel.ai.error.${Oz}`,mz=Symbol.for(Fz),u,l,zG=class z extends(l=X,u=mz,l){constructor({value:Q,cause:W,context:G}){let Y="Type validation failed";if(G==null?void 0:G.field)Y+=` for ${G.field}`;if((G==null?void 0:G.entityName)||(G==null?void 0:G.entityId)){Y+=" (";let Z=[];if(G.entityName)Z.push(G.entityName);if(G.entityId)Z.push(`id: "${G.entityId}"`);Y+=Z.join(", "),Y+=")"}super({name:Oz,message:`${Y}: Value: ${JSON.stringify(Q)}.
Error message: ${zz(W)}`,cause:W});this[u]=!0,this.value=Q,this.context=G}static isInstance(Q){return X.hasMarker(Q,Fz)}static wrap({value:Q,cause:W,context:G}){var Y,Z,A;if(z.isInstance(W)&&W.value===Q&&((Y=W.context)==null?void 0:Y.field)===(G==null?void 0:G.field)&&((Z=W.context)==null?void 0:Z.entityName)===(G==null?void 0:G.entityName)&&((A=W.context)==null?void 0:A.entityId)===(G==null?void 0:G.entityId))return W;return new z({value:Q,cause:W,context:G})}},Nz="AI_UnsupportedFunctionalityError",Rz=`vercel.ai.error.${Nz}`,pz=Symbol.for(Rz),s,t,GG=class extends(t=X,s=pz,t){constructor({functionality:z,message:Q=`'${z}' functionality not supported.`}){super({name:Nz,message:Q});this[s]=!0,this.functionality=z}static isInstance(z){return X.hasMarker(z,Rz)}};function M(z){if(z===null||typeof z==="string"||typeof z==="number"||typeof z==="boolean")return!0;if(Array.isArray(z))return z.every(M);if(typeof z==="object")return Object.entries(z).every(([Q,W])=>typeof Q==="string"&&(W===void 0||M(W)));return!1}function QG(z){return Array.isArray(z)&&z.every(M)}function WG(z){return z!=null&&typeof z==="object"&&Object.entries(z).every(([Q,W])=>typeof Q==="string"&&(W===void 0||M(W)))}class J extends Error{constructor(z,Q){super(z),this.name="ParseError",this.type=Q.type,this.field=Q.field,this.value=Q.value,this.line=Q.line}}function B(z){}function Vz(z){if(typeof z=="function")throw TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");let{onEvent:Q=B,onError:W=B,onRetry:G=B,onComment:Y}=z,Z="",A=!0,q,K="",U="";function Tz($){let D=A?$.replace(/^\xEF\xBB\xBF/,""):$,[H,j]=xz(`${Z}${D}`);for(let w of H)O(w);Z=j,A=!1}function O($){if($===""){Lz();return}if($.startsWith(":")){Y&&Y($.slice($.startsWith(": ")?2:1));return}let D=$.indexOf(":");if(D!==-1){let H=$.slice(0,D),j=$[D+1]===" "?2:1,w=$.slice(D+j);F(H,w,$);return}F($,"",$)}function F($,D,H){switch($){case"event":U=D;break;case"data":K=`${K}${D}
`;break;case"id":q=D.includes("\x00")?void 0:D;break;case"retry":/^\d+$/.test(D)?G(parseInt(D,10)):W(new J(`Invalid \`retry\` value: "${D}"`,{type:"invalid-retry",value:D,line:H}));break;default:W(new J(`Unknown field "${$.length>20?`${$.slice(0,20)}\u2026`:$}"`,{type:"unknown-field",field:$,value:D,line:H}));break}}function Lz(){K.length>0&&Q({id:q,event:U||void 0,data:K.endsWith(`
`)?K.slice(0,-1):K}),q=void 0,K="",U=""}function bz($={}){Z&&$.consume&&O(Z),A=!0,q=void 0,K="",U="",Z=""}return{feed:Tz,reset:bz}}function xz(z){let Q=[],W="",G=0;for(;G<z.length;){let Y=z.indexOf("\r",G),Z=z.indexOf(`
`,G),A=-1;if(Y!==-1&&Z!==-1?A=Math.min(Y,Z):Y!==-1?Y===z.length-1?A=-1:A=Y:Z!==-1&&(A=Z),A===-1){W=z.slice(G);break}else{let q=z.slice(G,A);Q.push(q),G=A+1,z[G-1]==="\r"&&z[G]===`
`&&G++}}return[Q,W]}class dz extends TransformStream{constructor({onError:z,onRetry:Q,onComment:W}={}){let G;super({start(Y){G=Vz({onEvent:(Z)=>{Y.enqueue(Z)},onError(Z){z==="terminate"?Y.error(Z):typeof z=="function"&&z(Z)},onRetry:Q,onComment:W})},transform(Y){G.feed(Y)}})}}
export{X as Su,iz as Tu,cz as Uu,zz as Vu,uz as Wu,lz as Xu,sz as Yu,tz as Zu,nz as _u,az as $u,rz as av,ez as bv,zG as cv,GG as dv,QG as ev,WG as fv,Vz as gv,dz as hv};
