PageSourceSearch

https://www.leadsblaster.ai/_next/static/chunks/b633a0c8-f945b754ff43b05b.js

js leadsblaster.ai collected 2026-10-05 15:16:24 UTC 64,990 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1407],{80846:(t,e,a)=>{a.d(e,{lW:()=>tu,rL:()=>tg,vl:()=>tm});var o,s,r=a(93045),i=a(60023),l=a(44254);a(41463);var n=Object.defineProperty,p=Symbol.for("vercel.ai.error.AI_InvalidArgumentError");i.bD;Symbol.for("vercel.ai.error.AI_InvalidStreamPartError");i.bD;Symbol.for("vercel.ai.error.AI_InvalidToolApprovalError");i.bD;Symbol.for("vercel.ai.error.AI_InvalidToolApprovalSignatureError");i.bD;Symbol.for("vercel.ai.error.AI_InvalidToolInputError");i.bD;Symbol.for("vercel.ai.error.AI_ToolCallNotFoundForApprovalError");i.bD;Symbol.for("vercel.ai.error.AI_MissingToolResultsError");i.bD;Symbol.for("vercel.ai.error.AI_NoImageGeneratedError");i.bD;var u="AI_NoObjectGeneratedError",d=`vercel.ai.error.${u}`,c=Symbol.for(d),h=class extends i.bD{constructor({message:t="No object generated.",cause:e,text:a,response:s,usage:r,finishReason:i}){super({name:u,message:t,cause:e}),this[o]=!0,this.text=a,this.response=s,this.usage=r,this.finishReason=i}static isInstance(t){return i.bD.hasMarker(t,d)}};o=c;Symbol.for("vercel.ai.error.AI_NoOutputGeneratedError");i.bD;Symbol.for("vercel.ai.error.AI_NoSpeechGeneratedError");i.bD;Symbol.for("vercel.ai.error.AI_NoTranscriptGeneratedError");i.bD;Symbol.for("vercel.ai.error.AI_NoTranslationGeneratedError");i.bD;Symbol.for("vercel.ai.error.AI_NoVideoGeneratedError");i.bD;Symbol.for("vercel.ai.error.AI_NoSuchToolError");i.bD;Symbol.for("vercel.ai.error.AI_ToolCallRepairError");i.bD,i.bD;var g="AI_UIMessageStreamError",m=`vercel.ai.error.${g}`,v=Symbol.for(m),y=class extends i.bD{constructor({chunkType:t,chunkId:e,message:a}){super({name:g,message:a}),this[s]=!0,this.chunkType=t,this.chunkId=e}static isInstance(t){return i.bD.hasMarker(t,m)}};s=v;Symbol.for("vercel.ai.error.AI_InvalidDataContentError");i.bD;Symbol.for("vercel.ai.error.AI_InvalidMessageRoleError");i.bD;Symbol.for("vercel.ai.error.AI_MessageConversionError");i.bD;Symbol.for("vercel.ai.error.AI_RetryError");i.bD;var b=async({url:t,maxBytes:e,abortSignal:a})=>{var o;let s=t.toString();try{let t=(0,r.WZ)({},"ai-sdk/7.0.58",(0,r.G1)()),i=await (0,r.ek)({url:s,headers:t,abortSignal:a});if(!i.ok)throw await (0,r.aI)(i),new r.nV({url:s,statusCode:i.status,statusText:i.statusText});return{data:await (0,r.cS)({response:i,url:s,maxBytes:null!=e?e:r.W}),mediaType:null!=(o=i.headers.get("content-type"))?o:void 0}}catch(t){if(r.nV.isInstance(t))throw t;throw new r.nV({url:s,cause:t})}},f={array:l.YO,boolean:l.zM,custom:l.Ie,discriminatedUnion:l.gM,enum:l.k5,instanceof:l.Nl,lazy:l.RZ,literal:l.eu,looseObject:l._H,never:l.Zm,null:l.ch,number:l.ai,object:l.Ik,record:l.g1,string:l.Yj,union:l.KC,unknown:l.L5},I=f.lazy(()=>f.union([f.null(),f.string(),f.number(),f.boolean(),f.record(f.string(),I.optional()),f.array(I)])),E=f.record(f.string(),f.record(f.string(),I.optional())),x=f.union([f.string(),f.instanceof(Uint8Array),f.instanceof(ArrayBuffer),f.custom(r.Pe,{message:"Must be a Buffer"})]),M=f.record(f.string(),f.string()),T=f.object({type:f.literal("text"),text:f.string(),providerOptions:E.optional()}),C=f.object({type:f.literal("image"),image:f.union([x,f.instanceof(URL),M]),mediaType:f.string().optional(),providerOptions:E.optional()}),w=f.discriminatedUnion("type",[f.object({type:f.literal("data"),data:x}),f.object({type:f.literal("url"),url:f.instanceof(URL)}),f.object({type:f.literal("reference"),reference:M}),f.object({type:f.literal("text"),text:f.string()})]),S=f.discriminatedUnion("type",[f.object({type:f.literal("data"),data:x}),f.object({type:f.literal("url"),url:f.instanceof(URL)})]),k=f.object({type:f.literal("file"),data:f.union([w,x,f.instanceof(URL),M]),filename:f.string().optional(),mediaType:f.string(),providerOptions:E.optional()}),A=f.object({type:f.literal("reasoning"),text:f.string(),providerOptions:E.optional()}),R=f.object({type:f.literal("custom"),kind:f.string().transform(t=>t),providerOptions:E.optional()}),j=f.object({type:f.literal("reasoning-file"),data:f.union([S,x,f.instanceof(URL)]),mediaType:f.string(),providerOptions:E.optional()}),N=f.object({type:f.literal("tool-call"),toolCallId:f.string(),toolName:f.string(),input
1:f.unknown(),providerOptions:E.optional(),providerExecuted:f.boolean().optional()}),_=f.discriminatedUnion("type",[f.object({type:f.literal("text"),value:f.string(),providerOptions:E.optional()}),f.object({type:f.literal("json"),value:I,providerOptions:E.optional()}),f.object({type:f.literal("execution-denied"),reason:f.string().optional(),providerOptions:E.optional()}),f.object({type:f.literal("error-text"),value:f.string(),providerOptions:E.optional()}),f.object({type:f.literal("error-json"),value:I,providerOptions:E.optional()}),f.object({type:f.literal("content"),value:f.array(f.union([f.object({type:f.literal("text"),text:f.string(),providerOptions:E.optional()}),f.object({type:f.literal("file"),data:w,mediaType:f.string(),filename:f.string().optional(),providerOptions:E.optional()}),f.object({type:f.literal("file-data"),data:f.string(),mediaType:f.string(),filename:f.string().optional(),providerOptions:E.optional()}),f.object({type:f.literal("file-url"),url:f.string(),mediaType:f.string().optional(),providerOptions:E.optional()}),f.object({type:f.literal("file-id"),fileId:f.union([f.string(),f.record(f.string(),f.string())]),providerOptions:E.optional()}),f.object({type:f.literal("file-reference"),providerReference:f.record(f.string(),f.string()),providerOptions:E.optional()}),f.object({type:f.literal("image-data"),data:f.string(),mediaType:f.string(),providerOptions:E.optional()}),f.object({type:f.literal("image-url"),url:f.string(),providerOptions:E.optional()}),f.object({type:f.literal("image-file-id"),fileId:f.union([f.string(),f.record(f.string(),f.string())]),providerOptions:E.optional()}),f.object({type:f.literal("image-file-reference"),providerReference:f.record(f.string(),f.string()),providerOptions:E.optional()}),f.object({type:f.literal("custom"),providerOptions:E.optional()})]))})]),O=f.object({type:f.literal("tool-result"),toolCallId:f.string(),toolName:f.string(),output:_,providerOptions:E.optional()}),P=f.object({type:f.literal("tool-approval-request"),approvalId:f.string(),toolCallId:f.string()}),D=f.object({type:f.literal("tool-approval-response"),approvalId:f.string(),approved:f.boolean(),reason:f.string().optional()}),F=f.object({role:f.literal("system"),content:f.string(),providerOptions:E.optional()}),q=f.object({role:f.literal("user"),content:f.union([f.string(),f.array(f.union([T,C,k]))]),providerOptions:E.optional()}),L=f.object({role:f.literal("assistant"),content:f.union([f.string(),f.array(f.union([T,R,k,A,j,N,O,P]))]),providerOptions:E.optional()}),B=f.object({role:f.literal("tool"),content:f.array(f.union([O,D])),providerOptions:E.optional()});f.union([F,q,L,B]);var U={},W={array:()=>z,choice:()=>K,json:()=>G,object:()=>V,text:()=>Y};for(var $ in W)n(U,$,{get:W[$],enumerable:!0});async function J(t){if(void 0===t)return{value:void 0,state:"undefined-input"};let e=await (0,r.N8)({text:t});return e.success?{value:e.value,state:"successful-parse"}:(e=await (0,r.N8)({text:function(t){let e=["ROOT"],a=-1,o=null,s=0;function r(t,s,r){switch(t){case'"':a=s,e.pop(),e.push(r),e.push("INSIDE_STRING");break;case"f":case"t":case"n":a=s,o=s,e.pop(),e.push(r),e.push("INSIDE_LITERAL");break;case"-":e.pop(),e.push(r),e.push("INSIDE_NUMBER");break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":a=s,e.pop(),e.push(r),e.push("INSIDE_NUMBER");break;case"{":a=s,e.pop(),e.push(r),e.push("INSIDE_OBJECT_START");break;case"[":a=s,e.pop(),e.push(r),e.push("INSIDE_ARRAY_START")}}function i(t,o){switch(t){case",":e.pop(),e.push("INSIDE_OBJECT_AFTER_COMMA");break;case"}":a=o,e.pop()}}function l(t,o){switch(t){case",":e.pop(),e.push("INSIDE_ARRAY_AFTER_COMMA");break;case"]":a=o,e.pop()}}for(let n=0;n<t.length;n++){let p=t[n];switch(e[e.length-1]){case"ROOT":r(p,n,"FINISH");break;case"INSIDE_OBJECT_START":switch(p){case'"':e.pop(),e.push("INSIDE_OBJECT_KEY");break;case"}":a=n,e.pop()}break;case"INSIDE_OBJECT_AFTER_COMMA":'"'===p&&(e.pop(),e.push("INSIDE_OBJECT_KEY"));break;case"INSIDE_OBJECT_KEY":'"'===p&&(e.pop(),e.push("INSIDE_OBJECT_AFTER_KEY"));break;
1case"INSIDE_OBJECT_AFTER_KEY":":"===p&&(e.pop(),e.push("INSIDE_OBJECT_BEFORE_VALUE"));break;case"INSIDE_OBJECT_BEFORE_VALUE":r(p,n,"INSIDE_OBJECT_AFTER_VALUE");break;case"INSIDE_OBJECT_AFTER_VALUE":i(p,n);break;case"INSIDE_STRING":switch(p){case'"':e.pop(),a=n;break;case"\\":e.push("INSIDE_STRING_ESCAPE");break;default:a=n}break;case"INSIDE_ARRAY_START":"]"===p?(a=n,e.pop()):(a=n,r(p,n,"INSIDE_ARRAY_AFTER_VALUE"));break;case"INSIDE_ARRAY_AFTER_VALUE":switch(p){case",":e.pop(),e.push("INSIDE_ARRAY_AFTER_COMMA");break;case"]":a=n,e.pop();break;default:a=n}break;case"INSIDE_ARRAY_AFTER_COMMA":r(p,n,"INSIDE_ARRAY_AFTER_VALUE");break;case"INSIDE_STRING_ESCAPE":e.pop(),"u"===p?(s=0,e.push("INSIDE_STRING_UNICODE_ESCAPE")):a=n;break;case"INSIDE_STRING_UNICODE_ESCAPE":(p>="0"&&p<="9"||p>="A"&&p<="F"||p>="a"&&p<="f")&&4==++s&&(e.pop(),a=n);break;case"INSIDE_NUMBER":switch(p){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":a=n;break;case"e":case"E":case"-":case".":break;case",":e.pop(),"INSIDE_ARRAY_AFTER_VALUE"===e[e.length-1]&&l(p,n),"INSIDE_OBJECT_AFTER_VALUE"===e[e.length-1]&&i(p,n);break;case"}":e.pop(),"INSIDE_OBJECT_AFTER_VALUE"===e[e.length-1]&&i(p,n);break;case"]":e.pop(),"INSIDE_ARRAY_AFTER_VALUE"===e[e.length-1]&&l(p,n);break;default:e.pop()}break;case"INSIDE_LITERAL":{let s=t.substring(o,n+1);"false".startsWith(s)||"true".startsWith(s)||"null".startsWith(s)?a=n:(e.pop(),"INSIDE_OBJECT_AFTER_VALUE"===e[e.length-1]?i(p,n):"INSIDE_ARRAY_AFTER_VALUE"===e[e.length-1]&&l(p,n))}}}let n=t.slice(0,a+1);for(let a=e.length-1;a>=0;a--)switch(e[a]){case"INSIDE_STRING":n+='"';break;case"INSIDE_OBJECT_KEY":case"INSIDE_OBJECT_AFTER_KEY":case"INSIDE_OBJECT_AFTER_COMMA":case"INSIDE_OBJECT_START":case"INSIDE_OBJECT_BEFORE_VALUE":case"INSIDE_OBJECT_AFTER_VALUE":n+="}";break;case"INSIDE_ARRAY_START":case"INSIDE_ARRAY_AFTER_COMMA":case"INSIDE_ARRAY_AFTER_VALUE":n+="]";break;case"INSIDE_LITERAL":{let e=t.substring(o,t.length);"true".startsWith(e)?n+="true".slice(e.length):"false".startsWith(e)?n+="false".slice(e.length):"null".startsWith(e)&&(n+="null".slice(e.length))}}return n}(t)})).success?{value:e.value,state:"repaired-parse"}:{value:void 0,state:"failed-parse"}}var Y=()=>({name:"text",responseFormat:Promise.resolve({type:"text"}),parseCompleteOutput:async({text:t})=>t,parsePartialOutput:async({text:t})=>({partial:t}),createElementStreamTransform(){}}),V=({schema:t,name:e,description:a})=>{let o=(0,r.mD)(t);return{name:"object",responseFormat:(0,r.hd)(o.jsonSchema).then(t=>({type:"json",schema:t,...null!=e&&{name:e},...null!=a&&{description:a}})),async parseCompleteOutput({text:t},e){let a=await (0,r.N8)({text:t});if(!a.success)throw new h({message:"No object generated: could not parse the response.",cause:a.error,text:t,response:e.response,usage:e.usage,finishReason:e.finishReason});let s=await (0,r.ZZ)({value:a.value,schema:o});if(!s.success)throw new h({message:"No object generated: response did not match schema.",cause:s.error,text:t,response:e.response,usage:e.usage,finishReason:e.finishReason});return s.value},async parsePartialOutput({text:t}){let e=await J(t);switch(e.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return{partial:e.value}}},createElementStreamTransform(){}}},z=({element:t,name:e,description:a})=>{let o=(0,r.mD)(t);return{name:"array",responseFormat:(0,r.hd)(o.jsonSchema).then(t=>{let{$schema:o,...s}=t;return{type:"json",schema:{$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{elements:{type:"array",items:s}},required:["elements"],additionalProperties:!1},...null!=e&&{name:e},...null!=a&&{description:a}}}),async parseCompleteOutput({text:t},e){let a=await (0,r.N8)({text:t});if(!a.success)throw new h({message:"No object generated: could not parse the response.",cause:a.error,text:t,response:e.response,usage:e.usage,finishReason:e.finishReason});let s=a.value;if(null==s||"object"!=typeof s||!("elements"in s)||!Array.isArray(s.elements))throw new h({message:"No object generated: response did not match schema.",cause:new i.iM({value:s,cause:"response must be an object with an elements array"}),text:t,response:e.response,usage:e.usage,finishReason:e.finishReason});let l=[];for(let a of s.elements){let s=await (0,r.ZZ)({value:a,schema:o});if(!s.success)throw new h({message:"No object generated: response did not match sc
1hema.",cause:s.error,text:t,response:e.response,usage:e.usage,finishReason:e.finishReason});l.push(s.value)}return l},async parsePartialOutput({text:t}){let e=await J(t);switch(e.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":{let t=e.value;if(null==t||"object"!=typeof t||!("elements"in t)||!Array.isArray(t.elements))return;let a="repaired-parse"===e.state&&t.elements.length>0?t.elements.slice(0,-1):t.elements,s=[];for(let t of a){let e=await (0,r.ZZ)({value:t,schema:o});e.success&&s.push(e.value)}return{partial:s}}}},createElementStreamTransform(){let t=0;return new TransformStream({transform({partialOutput:e},a){if(null!=e)for(;t<e.length;t++)a.enqueue(e[t])}})}}},K=({options:t,name:e,description:a})=>({name:"choice",responseFormat:Promise.resolve({type:"json",schema:{$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{result:{type:"string",enum:t}},required:["result"],additionalProperties:!1},...null!=e&&{name:e},...null!=a&&{description:a}}),async parseCompleteOutput({text:e},a){let o=await (0,r.N8)({text:e});if(!o.success)throw new h({message:"No object generated: could not parse the response.",cause:o.error,text:e,response:a.response,usage:a.usage,finishReason:a.finishReason});let s=o.value;if(null==s||"object"!=typeof s||!("result"in s)||"string"!=typeof s.result||!t.includes(s.result))throw new h({message:"No object generated: response did not match schema.",cause:new i.iM({value:s,cause:"response must be an object that contains a choice value."}),text:e,response:a.response,usage:a.usage,finishReason:a.finishReason});return s.result},async parsePartialOutput({text:e}){let a=await J(e);switch(a.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":{let e=a.value;if(null==e||"object"!=typeof e||!("result"in e)||"string"!=typeof e.result)return;let o=t.filter(t=>t.startsWith(e.result));if("successful-parse"===a.state)return o.includes(e.result)?{partial:e.result}:void 0;return 1===o.length?{partial:o[0]}:void 0}}},createElementStreamTransform(){}}),G=({name:t,description:e}={})=>({name:"json",responseFormat:Promise.resolve({type:"json",...null!=t&&{name:t},...null!=e&&{description:e}}),async parseCompleteOutput({text:t},e){let a=await (0,r.N8)({text:t});if(!a.success)throw new h({message:"No object generated: could not parse the response.",cause:a.error,text:t,response:e.response,usage:e.usage,finishReason:e.finishReason});return a.value},async parsePartialOutput({text:t}){let e=await J(t);switch(e.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return void 0===e.value?void 0:{partial:e.value}}},createElementStreamTransform(){}});new TextEncoder,new TextEncoder,(0,r.hK)({prefix:"aitxt",size:24}),(0,r.hK)({prefix:"call",size:24}),TransformStream;var Q=f.record(f.string(),I.optional()),Z=(0,r.ID)(()=>(0,r.jN)(f.union([f.looseObject({type:f.literal("text-start"),id:f.string(),providerMetadata:E.optional()}),f.looseObject({type:f.literal("text-delta"),id:f.string(),delta:f.string(),providerMetadata:E.optional()}),f.looseObject({type:f.literal("text-end"),id:f.string(),providerMetadata:E.optional()}),f.looseObject({type:f.literal("error"),errorText:f.string()}),f.looseObject({type:f.literal("tool-input-start"),toolCallId:f.string(),toolName:f.string(),providerExecuted:f.boolean().optional(),providerMetadata:E.optional(),toolMetadata:Q.optional(),dynamic:f.boolean().optional(),title:f.string().optional()}),f.looseObject({type:f.literal("tool-input-delta"),toolCallId:f.string(),inputTextDelta:f.string()}),f.looseObject({type:f.literal("tool-input-available"),toolCallId:f.string(),toolName:f.string(),input:f.unknown(),providerExecuted:f.boolean().optional(),providerMetadata:E.optional(),toolMetadata:Q.optional(),dynamic:f.boolean().optional(),title:f.string().optional()}),f.looseObject({type:f.literal("tool-input-error"),toolCallId:f.string(),toolName:f.string(),input:f.unknown(),providerExecuted:f.boolean().optional(),providerMetadata:E.optional(),toolMetadata:Q.optional(),dynamic:f.boolean().optional(),errorText:f.string(),title:f.string().optional()}),f.looseObject({type:f.literal("tool-approval-request"),approvalId:f.string(),toolCallId:f.string(),isAutomatic:f.boolean().optional(),signature:f.string().optional()}),f.looseObject({type:f.literal("tool-approval-response"),approvalId:f.string(),approved:f.boolean(),reason:f.string().optional(),providerExecuted:f.boolean().optional(),providerMetadata:E.optional()}),f.looseObject({type:f.literal("tool-output-available"),toolCallId:f.string(),output:f.unknown(),providerExecuted:f.boolean().optional(),providerMetadata:E.optional(),toolMetadata:Q.optional(),dynamic:f.boolean().optional(),preliminary:f.boolean().optional()}),f.looseObject({type:f.literal("tool-output-error"),toolCallId:f.string(),errorText:f.string(),providerExecuted:f.boolean().optional(),providerMetadata:E.optional(),toolMetadata:Q.optional(),dynamic:f.boolean().optional()}),f.looseObject({type:f.literal("tool-output-denied"),toolCallId:f.string()}),f.looseObject({type:f.literal("reasoning-start"),id:f.string(),providerMetadata:E.optional()}),f.looseObject({type:f.literal("reasoning-delta"),id:f.string(),delta:f.string(),providerMetadata:E.optional()}),f.looseObject({type:f.literal("reasoning-end"),id:f.string(),providerMetadata:E.optional()}),f.looseObject({type:f.literal("custom"),kind:f.string().transform(t=>t),providerMetadata:E.optional()}),f.looseObject({type:f.literal("source-url"),sourceId:f.string(),url:f.string(),title:f.string().optional(),providerMetadata:E.optional()}),f.looseObject({type:f.literal("source-document"),sourceId:f.string(),mediaType:f.string(),title:f.string(),filename:f.string().optional(),providerMetadata:E.optional()}),f.looseObject({type:f.literal("file"),url:f.string(),mediaType:f.string(),providerMetadata:E.optional()}),f.looseObject({type:f.literal("reasoning-file"),url:f.string(),mediaType:f.string(),providerMetadata:E.optional()}),f.looseObject({type:f.custom(t=>"string"==typeof t&&t.startsWith("data-"),{message:'Type must start with "data-"'}),id:f.string().optional(),data:f.unknown(),transient:f.boolean().optional()}),f.looseObject({type:f.literal("start-step")}),f.looseObject({type:f.literal("finish-step")}),f.looseObject({type:f.literal("start"),messageId:f.string().optional(),messageMetadata:f.unknown().optional()}),f.looseObject({type:f.literal("finish"),finishReason:f.enum(["stop","length","content-filter","tool-calls","error","other"]).optional(),messageMetadata:f.unknown().optional()}),f.looseObject({type:f.literal("abort"),reason:f.string().optional()}),f.looseObject({type:f.literal("message-metadata"),messageMetadata:f.unknown()})])));function H(){return Object.create(null)}function X(t){return t.type.startsWith("tool-")}function tt(t){return X(t)||"dynamic-tool"===t.type}function te(t){return t.type.split("-").slice(1).join("-")}async function ta({stream:t,onError:e,abortSignal:a}){let o=t.getReader(),s=()=>{o.cancel().catch(()=>{})};(null==a?void 0:a.aborted)?s():null==a||a.addEventListener("abort",s,{once:!0});try{for(;;){let{done:t}=await o.read();if(t)break}}catch(t){null==e||e(t)}finally{null==a||a.removeEventListener("abort",s),o.releaseLock()}}(0,r.hK)({prefix:"aitxt",size:24}),(0,r.hK)({prefix:"call",size:24}),(0,r.hK)({prefix:"aitxt",size:24}),(0,r.hK)({prefix:"call",size:24});var to=f.record(f.string(),I.optional()),ts=f.record(f.string(),f.string());function tr(t){return({url:e,abortSignal:a})=>b({url:e,maxBytes:null==t?void 0:t.maxBytes,abortSignal:a})}(0,r.ID)(()=>(0,r.jN)(f.array(f.object({id:f.string(),role:f.enum(["system","user","assistant"]),metadata:f.unknown().optional(),parts:f.array(f.union([f.object({type:f.literal("text"),text:f.string(),state:f.enum(["streaming","done"]).optional(),providerMetadata:E.optional()}),f.object({type:f.literal("reasoning"),text:f.string(),state:f.enum(["streaming","done"]).optional(),providerMetadata:E.optional()}),f.object({type:f.literal("custom"),kind:f.string(),providerMetadata:E.optional()}),f.object({type:f.literal("source-url"),sourceId:f.string(),url:f.string(),title:f.string().optional(),providerMetadata:E.optional()}),f.object({type:f.literal("source-document"),sourceId:f.string(),mediaType:f.string(),title:f.string(),filename:f.string().optional(),providerMetadata:E.optional()}),f.object({type:f.literal("file"),mediaType:f.string(),filename:f.string().optional(),url:f.string(),providerReference:ts.optional(),providerMetadata:E.optional()}),f.object({type:f.literal("reasoning-file"),mediaType:f.string(),url:f.string(),providerMetadata:E.optional()}),f.object({type:f.literal("step-start")}),f.object({type:f.string().startsWith("data-"),id:f.string().optional(),data:f.unknown()}),f.object({type:f.literal("dynamic-tool"),toolName:f.string(),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("input-streaming"),input:f.unknown().optional(),providerExecuted:f.boolean().optional(),callProviderMetadata:E.optional(),output:f.never().optional(),errorText:f.never().optional(),approval:f.never().optional()}),f.object({type:f.literal("dynamic-tool"),toolName:f.string(),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("input-available"),input:f.unknown(),providerExecuted:f.boolean().optional(),output:f.never().optional(),errorText:f.never().optional(),callProviderMetadata:E.optional(),approval:f.never().optional()}),f.object({type:f.literal("dynamic-tool"),toolName:f.string(),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("approval-requested"),input:f.unknown(),providerExecuted:f.boolean().optional(),output:f.never().optional(),errorText:f.never().optional(),callProviderMetadata:E.optional(),approval:f.object({id:f.string(),approved:f.never().optional(),reason:f.never().optional(),isAutomatic:f.boolean().optional(),signature:f.string().optional()})}),f.object({type:f.literal("dynamic-tool"),toolName:f.string(),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("approval-responded"),input:f.unknown(),providerExecuted:f.boolean().optional(),output:f.never().optional(),errorText:f.never().optional(),callProviderMetadata:E.optional(),approval:f.object({id:f.string(),approved:f.boolean(),reason:f.string().optional(),isAutomatic:f.boolean().optional(),signature:f.string().optional()})}),f.object({type:f.literal("dynamic-tool"),toolName:f.string(),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("output-available"),input:f.unknown(),providerExecuted:f.boolean().optional(),output:f.unknown(),errorText:f.never().optional(),callProviderMetadata:E.optional(),resultProviderMetadata:E.optional(),preliminary:f.boolean().optional(),approval:f.object({id:f.string(),approved:f.literal(!0),reason:f.string().optional(),isAutomatic:f.boolean().optional(),signature:f.string().optional()}).optional()}),f.object({type:f.literal("dynamic-tool"),toolName:f.string(),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("output-error"),input:f.unknown().optional(),rawInput:f.unknown().optional(),providerExecuted:f.boolean().optional(),output:f.never().optional(),errorText:f.string(),callProviderMetadata:E.optional(),resultProviderMetadata:E.optional(),approval:f.object({id:f.string(),approved:f.literal(!0),reason:f.string().optional(),isAutomatic:f.boolean().optional(),signature:f.string().optional()}).optional()}),f.object({type:f.literal("dynamic-tool"),toolName:f.string(),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("output-denied"),input:f.unknown(),providerExecuted:f.boolean().optional(),output:f.never().optional(),errorText:f.never().optional(),callProviderMetadata:E.optional(),approval:f.object({id:f.string(),approved:f.literal(!1),reason:f.string().optional(),isAutomatic:f.boolean().optional(),signature:f.string().optional()})}),f.object({type:f.string().startsWith("tool-"),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("input-streaming"),providerExecuted:f.boolean().optional(),callProviderMetadata:E.optional(),input
1:f.unknown().optional(),output:f.never().optional(),errorText:f.never().optional(),approval:f.never().optional()}),f.object({type:f.string().startsWith("tool-"),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("input-available"),providerExecuted:f.boolean().optional(),input:f.unknown(),output:f.never().optional(),errorText:f.never().optional(),callProviderMetadata:E.optional(),approval:f.never().optional()}),f.object({type:f.string().startsWith("tool-"),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("approval-requested"),input:f.unknown(),providerExecuted:f.boolean().optional(),output:f.never().optional(),errorText:f.never().optional(),callProviderMetadata:E.optional(),approval:f.object({id:f.string(),approved:f.never().optional(),reason:f.never().optional(),isAutomatic:f.boolean().optional(),signature:f.string().optional()})}),f.object({type:f.string().startsWith("tool-"),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("approval-responded"),input:f.unknown(),providerExecuted:f.boolean().optional(),output:f.never().optional(),errorText:f.never().optional(),callProviderMetadata:E.optional(),approval:f.object({id:f.string(),approved:f.boolean(),reason:f.string().optional(),isAutomatic:f.boolean().optional(),signature:f.string().optional()})}),f.object({type:f.string().startsWith("tool-"),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("output-available"),providerExecuted:f.boolean().optional(),input:f.unknown(),output:f.unknown(),errorText:f.never().optional(),callProviderMetadata:E.optional(),resultProviderMetadata:E.optional(),preliminary:f.boolean().optional(),approval:f.object({id:f.string(),approved:f.literal(!0),reason:f.string().optional(),isAutomatic:f.boolean().optional(),signature:f.string().optional()}).optional()}),f.object({type:f.string().startsWith("tool-"),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("output-error"),providerExecuted:f.boolean().optional(),input:f.unknown().optional(),rawInput:f.unknown().optional(),output:f.never().optional(),errorText:f.string(),callProviderMetadata:E.optional(),resultProviderMetadata:E.optional(),approval:f.object({id:f.string(),approved:f.literal(!0),reason:f.string().optional(),isAutomatic:f.boolean().optional(),signature:f.string().optional()}).optional()}),f.object({type:f.string().startsWith("tool-"),toolCallId:f.string(),toolMetadata:to.optional(),state:f.literal("output-denied"),providerExecuted:f.boolean().optional(),input:f.unknown(),output:f.never().optional(),errorText:f.never().optional(),callProviderMetadata:E.optional(),approval:f.object({id:f.string(),approved:f.literal(!1),reason:f.string().optional(),isAutomatic:f.boolean().optional(),signature:f.string().optional()})})]))}).superRefine((t,e)=>{"assistant"!==t.role&&0===t.parts.length&&e.addIssue({origin:"array",code:"too_small",minimum:1,inclusive:!0,input:t.parts,path:["parts"],message:"Message must contain at least one part"})})).nonempty("Messages array must not be empty"))),(0,r.hK)({prefix:"call",size:24}),(0,r.hK)({prefix:"call",size:24}),(0,r.hK)({prefix:"aiobj",size:24});var ti=class{constructor(){this.queue=[],this.isProcessing=!1}async processQueue(){if(!this.isProcessing){for(this.isProcessing=!0;this.queue.length>0;)await this.queue[0](),this.queue.shift();this.isProcessing=!1}}async run(t){return new Promise((e,a)=>{this.queue.push(async()=>{try{await t(),e()}catch(t){a(t)}}),this.processQueue()})}};(0,r.hK)({prefix:"aiobj",size:24}),tr();var tl=class{constructor(t){this.captureContext=null,this.captureProcessor=null,this.captureSource=null,this.captureStream=null,this.playbackContext=null,this.playbackQueue=[],this.playbackTime=0,this.playbackStartTime=0,this.activeSources=new Set,this.isPlaying=!1,this.captureSampleRate=t.captureSampleRate,this.playbackSampleRate=t.playbackSampleRate,this.onAudio=t.onAudio,this.onPlayingChange=t.onPlayingChange,this.onCapturingChange=t.onCapturingChange}ensurePlaybackContext(){null==this.playbackContext&&(this.playbackContext=new AudioContext({sampleRate:this.playbackSampleRate}))}startCapture(t){let e=new AudioContext({sampleRate:this.captureSampleRate});this.captureContext=e,this.captureStream=t;let a=e.createMediaStreamSource(t);this.captureSource=a;let o=e.createScriptProcessor(4096,1,1);this.captureProcessor=o,o.onaudioprocess=t=>{let a=function(t,e,a){if(e===a)return t;let o=e/a,s=Math.round(t.length/o),r=new Float32Array(s);for(let e=0;e<s;e++){let a=e*o,s=Math.floor(a),i=Math.min(s+1,t.length-1),l=a-s;r[e]=t[s]*(1-l)+t[i]*l}return r}(new Float32Array(t.inputBuffer.getChannelData(0)),e.sampleRate,this.captureSampleRate);this.onAudio(function(t){let e=new ArrayBuffer(2*t.length),a=new DataView(e);for(let e=0;e<t.length;e++){let o=Math.max(-1,Math.min(1,t[e]));a.setInt16(2*e,o<0?32768*o:32767*o,!0)}let o=new Uint8Array(e),s="";for(let t=0;t<o.length;t+=32768)s+=String.fromCharCode(...o.subarray(t,t+32768));return btoa(s)}(a))},a.connect(o),o.connect(e.destination),this.onCapturingChange(!0)}stopCapture(){var t,e,a,o;null==(t=this.captureProcessor)||t.disconnect(),null==(e=this.captureSource)||e.disconnect(),null==(a=this.captureContext)||a.close(),null==(o=this.captureStream)||o.getTracks().forEac
1h(t=>t.stop()),this.captureProcessor=null,this.captureSource=null,this.captureContext=null,this.captureStream=null,this.onCapturingChange(!1)}playAudio(t){this.ensurePlaybackContext(),this.playbackQueue.push(function(t){let e=atob(t),a=new Uint8Array(e.length);for(let t=0;t<e.length;t++)a[t]=e.charCodeAt(t);let o=new Int16Array(a.buffer),s=new Float32Array(o.length);for(let t=0;t<o.length;t++)s[t]=o[t]/32768;return s}(t)),this.schedulePlayback()}stopPlayback(){for(let t of(this.playbackQueue=[],this.activeSources))try{t.stop()}catch(t){}this.activeSources.clear(),null!=this.playbackContext&&(this.playbackTime=this.playbackContext.currentTime),this.setPlaying(!1)}getPlaybackOffsetMs(){let t=this.playbackContext;return null==t?0:(t.currentTime-this.playbackStartTime)*1e3}dispose(){var t;this.stopCapture(),this.stopPlayback(),null==(t=this.playbackContext)||t.close(),this.playbackContext=null}setPlaying(t){var e,a;t&&!this.isPlaying&&(this.playbackStartTime=null!=(a=null==(e=this.playbackContext)?void 0:e.currentTime)?a:0),this.isPlaying!==t&&(this.isPlaying=t,this.onPlayingChange(t))}schedulePlayback(){let t=this.playbackContext;if(null!=t&&0!==this.playbackQueue.length)for(;this.playbackQueue.length>0;){let e=this.playbackQueue.shift(),a=t.createBuffer(1,e.length,this.playbackSampleRate);a.getChannelData(0).set(e);let o=t.createBufferSource();o.buffer=a,o.connect(t.destination);let s=Math.max(this.playbackTime,t.currentTime);o.start(s),this.playbackTime=s+a.duration,this.activeSources.add(o),this.setPlaying(!0),o.onended=()=>{this.activeSources.delete(o),0===this.playbackQueue.length&&0===this.activeSources.size&&this.setPlaying(!1)}}}},tn=class{constructor(t){this.ws=null,this.sendQueue=Promise.resolve(),this.model=t.model,this.onServerEvent=t.onServerEvent,this.onError=t.onError,this.onClose=t.onClose}connect({token:t,url:e,onOpen:a}){var o;null==(o=this.ws)||o.close(),this.ws=null;let s=this.model.getWebSocketConfig({token:t,url:e}),r=new WebSocket(s.url,s.protocols);this.ws=r,r.onopen=()=>{this.ws===r&&a()},r.onmessage=t=>{this.handleMessage(t)},r.onerror=()=>{this.onError(Error("WebSocket connection error"))},r.onclose=()=>{this.ws===r&&(this.ws=null,this.onClose())}}disconnect(){var t;null==(t=this.ws)||t.close(),this.ws=null}sendEvent(t){this.sendQueue=this.sendQueue.then(async()=>{let e=await this.model.serializeClientEvent(t);null!=e&&this.sendRaw(e)}).catch(t=>{this.onError(t instanceof Error?t:Error(`Failed to send realtime event: ${String(t)}`))})}sendRaw(t){var e;(null==(e=this.ws)?void 0:e.readyState)===WebSocket.OPEN&&("string"==typeof t||t instanceof ArrayBuffer||ArrayBuffer.isView(t)||t instanceof Blob?this.ws.send(t):this.ws.send(JSON.stringify(t)))}dispose(){this.disconnect()}async handleMessage(t){let e;e="string"==typeof t.data?t.data:t.data instanceof Blob?await t.data.text():new TextDecoder().decode(t.data);let a=await (0,r.N8)({text:e});if(!a.success)return;let o=a.value;if(null!=this.model.getHealthCheckResponse){let t=this.model.getHealthCheckResponse(o);null!=t&&this.sendRaw(t)}let s=this.model.parseServerEvent(o);for(let t of Array.isArray(s)?s:[s])await this.onServerEvent(t)}},tp=class{constructor(t=500){this.maxEvents=t,this.currentAssistantMessageId=null,this.textAccumulators=new Map,this.toolArgAccumulators=new Map,this.toolCallIdToMessageId=new Map,this.toolCallIdToName=new Map,this.inputAudioMessageInsertIndex=new Map,this.itemIdToPartLocation=new Map}setStatus(t,e){return{...t,status:e}}setCapturing(t,e){return{...t,isCapturing:e}}setPlaying(t,e){return{...t,isPlaying:e}}addUserTextMessage(t,e){return{...t,messages:[...t.messages,{id:`user-${Date.now()}`,role:"user",parts:[{type:"text",text:e,state:"done"}]}]}}addToolOutput(t,e,a){return{state:this.updateToolPartState(t,e,a),output:{callId:e,name:this.toolCallIdToName.get(e),output:JSON.stringify(a)}}}async reduceServerEvent(t,e){var a;let o=this.pushEvent(t,e),s=[];switch(e.type){case"session-created":case"session-updated":"connecting"===o.status&&(o=this.setStatus(o,"connected"));break;case"audio-delta":s.push({type:"play-audio",itemId:e.itemId,delta:e.delta});break;case"audio-committed":null!=e.itemId&&this.inputAudioMessageInsertIndex.set(e.itemId,o.messages.length);break;case"audio-transcript-delta":case"text-delta":o=this.appendTextDelta(o,e.itemId,e.delta);break;case"audio-transcript-done":o=this.finalizeText(o,e.itemId,e.transcript);break;case"text-done":o=this.finalizeText(o,e.itemId,e.text);break;case"input-transcription-completed":o=this.addInputTranscriptionMessage(o,e.itemId,e.transcript);break;case"response-created":case"response-done":this.currentAssistantMessageId=null;break;case"speech-started":this.currentAssistantMessageId=null,s.push({type:"speech-started"});break;case"function-call-arguments-delta":{let{state:t,messageId:s}=this.getOrCreateAssistantMessage(o);o=t,this.toolCallIdToMessageId.set(e.callId,s);let r=null!=(a=this.toolArgAccumulators.get(e.callId))?a:"";this.toolArgAccumulators.set(e.callId,r+e.delta),o=this.ensureToolPart(o,s,e.callId);break}case"function-call-arguments-done":{this.toolArgAccumulators.delete(e.callId),this.toolCallIdToName.set(e.callId,e.name);let t=await (0,r.N8)({text:e.arguments}),a=t.success?t.value:{},i=this.toolCallIdToMessageId.get(e.callId);null!=i&&(o=this.markToolInputAvailable(o,i,e.callId,e.name,a)),t.success?s.push({type:"tool-call",callId:e.callId,name:e.name,args:a,rawArguments:e.arguments}):s.push({type:"error",error:Error(`Failed to parse tool arguments: ${e.arguments}`)});break}case"error":s.push({type:"error",error:Error(e.message)})}return{state:o,effects:s}}pushEvent(t,e){let a=[...t.events,e];return{...t,events:a.length>this.maxEvents?a.slice(-this.maxEvents):a}}getOrCreateAssistantMessage(t){if(null!=this.currentAssistantMessageId)return{state:t,messageId:this.currentAssistantMessageId};let e=`assistant-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;return this.currentAssistantMessageId=e,{state:{...t,messages:[...t.messages,{id:e,role:"assistant",parts:[]}]},messageId:e}}
1addInputTranscriptionMessage(t,e,a){var o;let s=`user-${e}`;if(null!=t.messages.find(t=>t.id===s))return{...t,messages:t.messages.map(t=>t.id===s?{...t,parts:[{type:"text",text:a,state:"done"}]}:t)};let r=Math.min(null!=(o=this.inputAudioMessageInsertIndex.get(e))?o:t.messages.length,t.messages.length),i=[...t.messages];return i.splice(r,0,{id:s,role:"user",parts:[{type:"text",text:a,state:"done"}]}),{...t,messages:i}}appendTextDelta(t,e,a){var o;let{state:s,messageId:r}=this.getOrCreateAssistantMessage(t),i=(null!=(o=this.textAccumulators.get(e))?o:"")+a;this.textAccumulators.set(e,i);let l=this.itemIdToPartLocation.get(e);return null!=l?this.updateMessagePart(s,l.messageId,l.partIndex,{type:"text",text:i,state:"streaming"}):{...s,messages:s.messages.map(t=>{if(t.id!==r)return t;let a=t.parts.length;return this.itemIdToPartLocation.set(e,{messageId:r,partIndex:a}),{...t,parts:[...t.parts,{type:"text",text:i,state:"streaming"}]}})}}finalizeText(t,e,a){var o;let s=null!=(o=null!=a?a:this.textAccumulators.get(e))?o:"";this.textAccumulators.delete(e);let r=this.itemIdToPartLocation.get(e);return null==r?t:(this.itemIdToPartLocation.delete(e),this.updateMessagePart(t,r.messageId,r.partIndex,{type:"text",text:s,state:"done"}))}ensureToolPart(t,e,a){return{...t,messages:t.messages.map(t=>t.id!==e||null!=t.parts.find(t=>"dynamic-tool"===t.type&&t.toolCallId===a)?t:{...t,parts:[...t.parts,{type:"dynamic-tool",toolName:"",toolCallId:a,state:"input-streaming",input:void 0}]})}}markToolInputAvailable(t,e,a,o,s){return{...t,messages:t.messages.map(t=>t.id!==e?t:{...t,parts:t.parts.map(t=>"dynamic-tool"!==t.type||t.toolCallId!==a?t:{...t,toolName:o,state:"input-available",input:s})})}}updateToolPartState(t,e,a){let o=this.toolCallIdToMessageId.get(e);return null==o?t:{...t,messages:t.messages.map(t=>t.id!==o?t:{...t,parts:t.parts.map(t=>"dynamic-tool"!==t.type||t.toolCallId!==e?t:{...t,state:"output-available",output:a})})}}updateMessagePart(t,e,a,o){return{...t,messages:t.messages.map(t=>{if(t.id!==e)return t;let s=[...t.parts];return s[a]=o,{...t,parts:s}})}}},tu=class{constructor(t){var e,a,o,s,r,i,l,n;this.state={status:"disconnected",messages:[],events:[],isCapturing:!1,isPlaying:!1},this.currentResponseItemId=null,this.toolCallsInResponse=new Set,this.submittedToolOutputs=new Set,this.responseToolCallsClosed=!1,this.model=t.model,this.api=t.api,this.sessionConfig=t.sessionConfig,this.maxEvents=null!=(e=t.maxEvents)?e:500,this.reducer=new tp(this.maxEvents),this.onToolCall=t.onToolCall,this.onEvent=t.onEvent,this.onError=t.onError;const p=null!=(a=t.sampleRate)?a:24e3,u=null!=(r=null==(s=null==(o=t.sessionConfig)?void 0:o.inputAudioFormat)?void 0:s.rate)?r:p,d=null!=(n=null==(l=null==(i=t.sessionConfig)?void 0:i.outputAudioFormat)?void 0:l.rate)?n:p;this.transport=new tn({model:this.model,onServerEvent:t=>this.handleServerEvent(t),onError:t=>{var e;this.applyState(this.reducer.setStatus(this.state,"error")),null==(e=this.onError)||e.call(this,t)},onClose:()=>{this.applyState(this.reducer.setStatus(this.state,"disconnected"))}}),this.audio=new tl({captureSampleRate:u,playbackSampleRate:d,onAudio:t=>this.sendAudio(t),onCapturingChange:t=>{this.applyState(this.reducer.setCapturing(this.state,t))},onPlayingChange:t=>{this.applyState(this.reducer.setPlaying(this.state,t))}})}async connect(){var t;this.applyState(this.reducer.setStatus(this.state,"connecting"));try{let t=await fetch(this.api.token,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionConfig:this.sessionConfig})});if(!t.ok)throw Error(`Failed to fetch realtime setup: ${t.status}`);let{token:e,url:a,tools:o}=await t.json(),s={...this.sessionConfig,tools:o};this.audio.ensurePlaybackContext(),this.transport.connect({token:e,url:a,onOpen:()=>{this.sendEvent({type:"session-update",config:s})}})}catch(e){this.applyState(this.reducer.setStatus(this.state,"error")),null==(t=this.onError)||t.call(this,e instanceof Error?e:Error(`Connection failed: ${String(e)}`))}}disconnect(){this.transport.disconnect(),this.applyState(this.reducer.setStatus(this.state,"disconnected"))}sendEvent(t){this.transport.sendEvent(t)}sendTextMessage(t){this.sendEvent({type:"conversation-item-create",item:{type:"text-message",role:"user",text:t}}),this.sendEvent({type:"response-create"}),this.applyState(this.reducer.addUserTextMessage(this.state,t))}sendAudio(t){this.sendEvent({type:"input-audio-append",audio:t})}commitAudio(){this.sendEvent({type:"input-audio-commit"})}clearAudioBuffer(){this.sendEvent({type:"input-audio-clear"})}requestResponse(t){this.sendEvent({type:"response-create",...null!=t?{options:t}:{}})}cancelResponse(){this.sendEvent({type:"response-cancel"})}addToolOutput(t,e){let{state:a,output:o}=this.reducer.addToolOutput(this.state,t,e);this.applyState(a),this.sendEvent({type:"conversation-item-create",item:{type:"function-call-output",callId:o.callId,name:o.name,output:o.output}}),this.submittedToolOutputs.add(t),this.maybeRequestToolResponse()}maybeRequestToolResponse(){if(this.responseToolCallsClosed&&0!==this.toolCallsInResponse.size){for(let t of this.toolCallsInResponse)if(!this.submittedToolOutputs.has(t))return;this.sendEvent({type:"response-create"}),this.toolCallsInResponse.clear(),this.submittedToolOutputs.clear(),this.responseToolCallsClosed=!1}
1}startAudioCapture(t){this.audio.startCapture(t)}stopAudioCapture(){this.audio.stopCapture()}stopPlayback(){this.audio.stopPlayback()}dispose(){this.transport.dispose(),this.audio.dispose(),this.applyState(this.reducer.setStatus(this.reducer.setPlaying(this.reducer.setCapturing(this.state,!1),!1),"disconnected"))}applyState(t){let e=this.state;this.state=t,e.status!==t.status&&this.setState("status",t.status),e.messages!==t.messages&&this.setState("messages",t.messages),e.events!==t.events&&this.setState("events",t.events),e.isCapturing!==t.isCapturing&&this.setState("isCapturing",t.isCapturing),e.isPlaying!==t.isPlaying&&this.setState("isPlaying",t.isPlaying)}async executeToolCall({name:t,args:e,callId:a}){var o,s;if(null==this.onToolCall){null==(o=this.onError)||o.call(this,Error(`No handler provided for tool "${t}"`));return}try{let o=await this.onToolCall({toolCall:{toolCallId:a,toolName:t,args:e}});void 0!==o&&this.addToolOutput(a,o)}catch(t){null==(s=this.onError)||s.call(this,t instanceof Error?t:Error(`Client tool execution failed: ${String(t)}`))}}async handleServerEvent(t){var e;let a=await this.reducer.reduceServerEvent(this.state,t);for(let o of(this.applyState(a.state),null==(e=this.onEvent)||e.call(this,t),a.effects))this.handleReducerEffect(o);"response-done"===t.type&&this.toolCallsInResponse.size>0&&(this.responseToolCallsClosed=!0,this.maybeRequestToolResponse())}handleReducerEffect(t){var e;switch(t.type){case"play-audio":this.currentResponseItemId=t.itemId,this.audio.playAudio(t.delta);break;case"speech-started":if(this.state.isPlaying){let t=this.audio.getPlaybackOffsetMs();this.audio.stopPlayback(),null!=this.currentResponseItemId&&this.sendEvent({type:"conversation-item-truncate",itemId:this.currentResponseItemId,contentIndex:0,audioEndMs:Math.round(t)})}break;case"tool-call":this.toolCallsInResponse.add(t.callId),this.executeToolCall({name:t.name,args:t.args,callId:t.callId});break;case"error":null==(e=this.onError)||e.call(this,t.error)}}},td=Symbol.for("vercel.ai.error.AI_NoSuchProviderError");async function tc(t){if(null==t)return[];if(!globalThis.FileList||!(t instanceof globalThis.FileList))throw Error("FileList is not supported in the current environment");return Promise.all(Array.from(t).map(async t=>{let{name:e,type:a}=t;return{type:"file",mediaType:a,filename:e,url:await new Promise((e,a)=>{let o=new FileReader;o.onload=t=>{var a;e(null==(a=t.target)?void 0:a.result)},o.onerror=t=>a(t),o.readAsDataURL(t)})}}))}i.eM,(0,r.hK)({prefix:"call",size:24}),tr();var th=class{constructor({api:t="/api/chat",credentials:e,headers:a,body:o,fetch:s,prepareSendMessagesRequest:r,prepareReconnectToStreamRequest:i}){this.api=t,this.credentials=e,this.headers=a,this.body=o,this.fetch=s,this.prepareSendMessagesRequest=r,this.prepareReconnectToStreamRequest=i}async sendMessages({abortSignal:t,...e}){var a,o,s,i,l;let n=await (0,r.hd)(this.body),p=await (0,r.hd)(this.headers),u=await (0,r.hd)(this.credentials),d={...(0,r.qx)(p),...(0,r.qx)(e.headers)},c=await (null==(a=this.prepareSendMessagesRequest)?void 0:a.call(this,{api:this.api,id:e.chatId,messages:e.messages,body:{...n,...e.body},headers:d,credentials:u,requestMetadata:e.metadata,trigger:e.trigger,messageId:e.messageId})),h=null!=(o=null==c?void 0:c.api)?o:this.api,g=(null==c?void 0:c.headers)!==void 0?(0,r.qx)(c.headers):d,m=(null==c?void 0:c.body)!==void 0?c.body:{...n,...e.body,id:e.chatId,messages:e.messages,trigger:e.trigger,messageId:e.messageId},v=null!=(s=null==c?void 0:c.credentials)?s:u,y=null!=(i=this.fetch)?i:globalThis.fetch,b=await y(h,{method:"POST",headers:{"Content-Type":"application/json",...g},body:JSON.stringify(m),credentials:v,signal:t});if(!b.ok)throw Error(null!=(l=await b.text())?l:"Failed to fetch the chat response.");if(!b.body)throw Error("The response body is empty.");return this.processResponseStream(b.body)}async reconnectToStream(t){var e,a,o,s,i;let l=await (0,r.hd)(this.body),n=await (0,r.hd)(this.headers),p=await (0,r.hd)(this.credentials),u={...(0,r.qx)(n),...(0,r.qx)(t.headers)},d=await (null==(e=this.prepareReconnectToStreamRequest)?void 0:e.call(this,{api:this.api,id:t.chatId,body:{...l,...t.body},headers:u,credentials:p,requestMetadata:t.metadata})),c=null!=(a=null==d?void 0:d.api)?a:`${this.api}/${t.chatId}/stream`,h=(null==d?void 0:d.headers)!==void 0?(0,r.qx)(d.headers):u,g=null!=(o=null==d?void 0:d.credentials)?o:p,m=null!=(s=this.fetch)?s:globalThis.fetch,v=await m(c,{method:"GET",headers:h,credentials:g,signal:t.abortSignal});if(204===v.status)return null;if(!v.ok)throw Error(null!=(i=await v.text())?i:"Failed to fetch the chat response.");if(!v.body)throw Error("The response body is empty.");return this.processResponseStream(v.body)}},tg=class extends th{constructor(t={}){super(t)}processResponseStream(t){return(0,r._Z)({stream:t,schema:Z}).pipeThrough(new TransformStream({async transform(t,e){if(!t.success)throw t.error;e.enqueue(t.value)}}))}},tm=class{constructor({generateId:t=r.$C,id:e=t(),transport:a=new tg,messageMetadataSchema:o,dataPartSchemas:s,state:i,onError:l,onToolCall:n,onFinish:p,onData:u,sendAutomaticallyWhen:d}){this.activeResponse=void 0,this.activeResumeRequest=void 0,this.jobExecutor=new ti,this.sendMessage=async(t,e)=>{var a,o,s,r;let i;
1if(null==t)return void await this.makeRequest({trigger:"submit-message",messageId:null==(a=this.lastMessage)?void 0:a.id,...e});if(i="text"in t||"files"in t?{parts:[...Array.isArray(t.files)?t.files:await tc(t.files),..."text"in t&&null!=t.text?[{type:"text",text:t.text}]:[]]}:t,null!=t.messageId){let e=this.state.messages.findIndex(e=>e.id===t.messageId);if(-1===e)throw Error(`message with id ${t.messageId} not found`);if("user"!==this.state.messages[e].role)throw Error(`message with id ${t.messageId} is not a user message`);this.state.messages=this.state.messages.slice(0,e+1),this.state.replaceMessage(e,{...i,id:t.messageId,role:null!=(o=i.role)?o:"user",metadata:t.metadata})}else this.state.pushMessage({...i,id:null!=(s=i.id)?s:this.generateId(),role:null!=(r=i.role)?r:"user",metadata:t.metadata});await this.makeRequest({trigger:"submit-message",messageId:t.messageId,...e})},this.regenerate=async({messageId:t,...e}={})=>{let a=null==t?this.state.messages.length-1:this.state.messages.findIndex(e=>e.id===t);if(-1===a)throw Error(`message ${t} not found`);this.state.messages=this.state.messages.slice(0,"assistant"===this.messages[a].role?a:a+1),await this.makeRequest({trigger:"regenerate-message",messageId:t,...e})},this.resumeStream=async(t={})=>{await this.makeRequest({trigger:"resume-stream",...t})},this.clearError=()=>{"error"===this.status&&(this.state.error=void 0,this.setStatus({status:"ready"}))},this.addToolApprovalResponse=async({id:t,approved:e,reason:a,options:o})=>this.jobExecutor.run(async()=>{let s=this.state.messages,r=s[s.length-1],i=o=>tt(o)&&"approval-requested"===o.state&&o.approval.id===t?{...o,state:"approval-responded",approval:{...o.approval,id:t,approved:e,reason:a}}:o;this.state.replaceMessage(s.length-1,{...r,parts:r.parts.map(i)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(i)),"streaming"!==this.status&&"submitted"!==this.status&&this.sendAutomaticallyWhen&&this.shouldSendAutomatically().then(t=>{var e;t&&this.makeRequest({trigger:"submit-message",messageId:null==(e=this.lastMessage)?void 0:e.id,...o})})}),this.addToolOutput=async({state:t="output-available",toolCallId:e,output:a,errorText:o,options:s})=>this.jobExecutor.run(async()=>{let r=this.state.messages,i=r[r.length-1],l=s=>tt(s)&&s.toolCallId===e?{...s,state:t,output:a,errorText:o}:s;this.state.replaceMessage(r.length-1,{...i,parts:i.parts.map(l)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(l)),"streaming"!==this.status&&"submitted"!==this.status&&this.sendAutomaticallyWhen&&this.shouldSendAutomatically().then(t=>{var e;t&&this.makeRequest({trigger:"submit-message",messageId:null==(e=this.lastMessage)?void 0:e.id,...s})})}),this.addToolResult=this.addToolOutput,this.stop=async()=>{var t,e;null==(t=this.activeResumeRequest)||t.abortController.abort(),null==(e=this.activeResponse)||e.abortController.abort()},this.id=e,this.transport=a,this.generateId=t,this.messageMetadataSchema=o,this.dataPartSchemas=s,this.state=i,this.onError=l,this.onToolCall=n,this.onFinish=p,this.onData=u,this.sendAutomaticallyWhen=d}get status(){return this.state.status}setStatus({status:t,error:e}){this.status!==t&&(this.state.status=t,this.state.error=e)}get error(){return this.state.error}get messages(){return this.state.messages}get lastMessage(){return this.state.messages[this.state.messages.length-1]}set messages(t){this.state.messages=t}async shouldSendAutomatically(){if(!this.sendAutomaticallyWhen)return!1;let t=this.sendAutomaticallyWhen({messages:this.state.messages});return t&&"object"==typeof t&&"then"in t?await t:t}async makeRequest({trigger:t,metadata:e,headers:a,body:o,messageId:s}){var i,l,n;let p,u,d=new AbortController,c="resume-stream"===t?{abortController:d}:void 0;c&&(null==(i=this.activeResumeRequest)||i.abortController.abort(),this.activeResumeRequest=c);let h=()=>null==c||this.activeResumeRequest===c,g=()=>{this.activeResumeRequest===c&&(this.activeResumeRequest=void 0)};if("resume-stream"===t)try{let t=await this.transport.reconnectToStream({chatId:this.id,abortSignal:d.signal,metadata:e,headers:a,body:o});if(d.signal.aborted||!h()){await (null==t?void 0:t.cancel().catch(()=>{})),h()&&this.setStatus({status:"ready"}),g();return}if(null==t){this.setStatus({status:"ready"}),g();return}p=t}catch(t){if(d.signal.aborted||"AbortError"===t.name){h()&&this.setStatus({status:"ready"}),g();return}if(!h())return;this.onError&&t instanceof Error&&this.onError(t),this.setStatus({status:"error",error:t}),g();return}this.setStatus({status:"submitted",error:void 0});let m=this.lastMessage,v=!1,b=!1,f=!1;try{let i,l={state:function({lastMessage:t,messageId:e}){return{message:(null==t?void 0:t.role)==="assistant"?t:{id:e,metadata:void 0,role:"assistant",parts:[]},activeTextParts:H(),activeReasoningParts:H(),partialToolCalls:H()}}({lastMessage:"regenerate-message"===t?void 0:this.state.snapshot(m),messageId:this.generateId()}),abortController:d};u=l,l.abortController.signal.addEventListener("abort",()=>{v=!0}
1),this.activeResponse=l,i="resume-stream"===t?p:await this.transport.sendMessages({chatId:this.id,messages:this.state.messages,abortSignal:l.abortController.signal,metadata:e,headers:a,body:o,trigger:t,messageId:s});let n=t=>this.jobExecutor.run(()=>l.abortController.signal.aborted?Promise.resolve():t({state:l.state,write:()=>{var t;l.abortController.signal.aborted||(this.setStatus({status:"streaming"}),l.state.message.id===(null==(t=this.lastMessage)?void 0:t.id)?this.state.replaceMessage(this.state.messages.length-1,l.state.message):this.state.pushMessage(l.state.message))}}));if(await ta({stream:function({stream:t,messageMetadataSchema:e,dataPartSchemas:a,runUpdateMessageJob:o,onError:s,onToolCall:i,onData:l}){return t.pipeThrough(new TransformStream({async transform(t,n){await o(async({state:o,write:p})=>{var u,d,c,h;function g(){let t=o.message.parts,e=t.length-1;for(;e>=0&&"step-start"!==t[e].type;)e--;return t.slice(e+1)}function m(t){let e=g().filter(tt).find(e=>e.toolCallId===t);if(null==e){let a=o.message.parts;for(let o=a.length-1;o>=0;o--){let s=a[o];if(tt(s)&&s.toolCallId===t){e=s;break}}}if(null==e)throw new y({chunkType:"tool-invocation",chunkId:t,message:`No tool invocation found for tool call ID "${t}".`});return e}function v(t,e){var a;let s=null!=e?e:g().find(e=>X(e)&&e.toolCallId===t.toolCallId);if(null!=s){s.state=t.state,s.input=t.input,s.output=t.output,s.errorText=t.errorText,s.rawInput=t.rawInput,s.preliminary=t.preliminary,void 0!==t.title&&(s.title=t.title),void 0!==t.toolMetadata&&(s.toolMetadata=t.toolMetadata),s.providerExecuted=null!=(a=t.providerExecuted)?a:s.providerExecuted;let e=t.providerMetadata;null!=e&&("output-available"===t.state||"output-error"===t.state?s.resultProviderMetadata=e:s.callProviderMetadata=e)}else o.message.parts.push({type:`tool-${t.toolName}`,toolCallId:t.toolCallId,state:t.state,title:t.title,...void 0!==t.toolMetadata?{toolMetadata:t.toolMetadata}:{},input:t.input,output:t.output,rawInput:t.rawInput,errorText:t.errorText,providerExecuted:t.providerExecuted,preliminary:t.preliminary,...null!=t.providerMetadata&&("output-available"===t.state||"output-error"===t.state)?{resultProviderMetadata:t.providerMetadata}:{},...null!=t.providerMetadata&&"output-available"!==t.state&&"output-error"!==t.state?{callProviderMetadata:t.providerMetadata}:{}})}function b(t,e){var a,s;let r=null!=e?e:g().find(e=>"dynamic-tool"===e.type&&e.toolCallId===t.toolCallId);if(null!=r){r.state=t.state,r.toolName=t.toolName,r.input=t.input,r.output=t.output,r.errorText=t.errorText,r.rawInput=null!=(a=t.rawInput)?a:r.rawInput,r.preliminary=t.preliminary,void 0!==t.title&&(r.title=t.title),void 0!==t.toolMetadata&&(r.toolMetadata=t.toolMetadata),r.providerExecuted=null!=(s=t.providerExecuted)?s:r.providerExecuted;let e=t.providerMetadata;null!=e&&("output-available"===t.state||"output-error"===t.state?r.resultProviderMetadata=e:r.callProviderMetadata=e)}else o.message.parts.push({type:"dynamic-tool",toolName:t.toolName,toolCallId:t.toolCallId,state:t.state,input:t.input,output:t.output,errorText:t.errorText,preliminary:t.preliminary,providerExecuted:t.providerExecuted,title:t.title,...void 0!==t.toolMetadata?{toolMetadata:t.toolMetadata}:{},...null!=t.providerMetadata&&("output-available"===t.state||"output-error"===t.state)?{resultProviderMetadata:t.providerMetadata}:{},...null!=t.providerMetadata&&"output-available"!==t.state&&"output-error"!==t.state?{callProviderMetadata:t.providerMetadata}:{}})}async function f(t){if(null!=t){let a=null!=o.message.metadata?function t(e,a){if(void 0===e&&void 0===a)return;if(void 0===e)return a;
1if(void 0===a)return e;let o={...e};for(let s in a)if("__proto__"!==s&&"constructor"!==s&&"prototype"!==s&&Object.prototype.hasOwnProperty.call(a,s)){let r=a[s];if(void 0===r)continue;let i=s in e?e[s]:void 0,l=null!==r&&"object"==typeof r&&!Array.isArray(r)&&!(r instanceof Date)&&!(r instanceof RegExp),n=null!=i&&"object"==typeof i&&!Array.isArray(i)&&!(i instanceof Date)&&!(i instanceof RegExp);l&&n?o[s]=t(i,r):o[s]=r}return o}(o.message.metadata,t):t;null!=e&&await (0,r.k5)({value:a,schema:e,context:{field:"message.metadata",entityId:o.message.id}}),o.message.metadata=a}}switch(t.type){case"text-start":{let e={type:"text",text:"",providerMetadata:t.providerMetadata,state:"streaming"};o.activeTextParts[t.id]=e,o.message.parts.push(e),p();break}case"text-delta":{let e=o.activeTextParts[t.id];if(null==e)throw new y({chunkType:"text-delta",chunkId:t.id,message:`Received text-delta for missing text part with ID "${t.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`});e.text+=t.delta,e.providerMetadata=null!=(u=t.providerMetadata)?u:e.providerMetadata,p();break}case"text-end":{let e=o.activeTextParts[t.id];if(null==e)throw new y({chunkType:"text-end",chunkId:t.id,message:`Received text-end for missing text part with ID "${t.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`});e.state="done",e.providerMetadata=null!=(d=t.providerMetadata)?d:e.providerMetadata,delete o.activeTextParts[t.id],p();break}case"custom":{let e={type:"custom",kind:t.kind,providerMetadata:t.providerMetadata};o.message.parts.push(e),p();break}case"reasoning-start":{let e={type:"reasoning",text:"",providerMetadata:t.providerMetadata,state:"streaming"};o.activeReasoningParts[t.id]=e,o.message.parts.push(e),p();break}case"reasoning-delta":{let e=o.activeReasoningParts[t.id];if(null==e)throw new y({chunkType:"reasoning-delta",chunkId:t.id,message:`Received reasoning-delta for missing reasoning part with ID "${t.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`});e.text+=t.delta,e.providerMetadata=null!=(c=t.providerMetadata)?c:e.providerMetadata,p();break}case"reasoning-end":{let e=o.activeReasoningParts[t.id];if(null==e)throw new y({chunkType:"reasoning-end",chunkId:t.id,message:`Received reasoning-end for missing reasoning part with ID "${t.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`});e.providerMetadata=null!=(h=t.providerMetadata)?h:e.providerMetadata,e.state="done",delete o.activeReasoningParts[t.id],p();break}case"file":case"reasoning-file":o.message.parts.push({type:t.type,mediaType:t.mediaType,url:t.url,...null!=t.providerMetadata?{providerMetadata:t.providerMetadata}:{}}),p();break;case"source-url":o.message.parts.push({type:"source-url",sourceId:t.sourceId,url:t.url,title:t.title,providerMetadata:t.providerMetadata}),p();break;case"source-document":o.message.parts.push({type:"source-document",sourceId:t.sourceId,mediaType:t.mediaType,title:t.title,filename:t.filename,providerMetadata:t.providerMetadata}),p();break;case"tool-input-start":{let e=g().filter(X);o.partialToolCalls[t.toolCallId]={text:"",toolName:t.toolName,index:e.length,dynamic:t.dynamic,title:t.title,toolMetadata:t.toolMetadata},t.dynamic?b({toolCallId:t.toolCallId,toolName:t.toolName,state:"input-streaming",input:void 0,providerExecuted:t.providerExecuted,title:t.title,toolMetadata:t.toolMetadata,providerMetadata:t.providerMetadata}):v({toolCallId:t.toolCallId,toolName:t.toolName,state:"input-streaming",input:void 0,providerExecuted:t.providerExecuted,title:t.title,toolMetadata:t.toolMetadata,providerMetadata:t.providerMetadata}),p();break}case"tool-input-delta":{let e=o.partialToolCalls[t.toolCallId];if(null==e)throw new y({chunkType:"tool-input-delta",chunkId:t.toolCallId,message:`Received tool-input-delta for missing tool call with ID "${t.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`});e.text+=t.inputTextDelta;let{value:a}=await J(e.text);e.dynamic?b({toolCallId:t.toolCallId,toolName:e.toolName,state:"input-streaming",input:a,title:e.title,toolMetadata:e.toolMetadata}):v({toolCallId:t.toolCallId,toolName:e.toolName,state:"input-streaming",input:a,title:e.title,toolMetadata:e.toolMetadata}),p();break}case"tool-input-available":t.dynamic?b({toolCallId:t.toolCallId,toolName:t.toolName,state:"input-available",input:t.input,providerExecuted:t.providerExecuted,providerMetadata:t.providerMetadata,title:t.title,toolMetadata:t.toolMetadata}):v({toolCallId:t.toolCallId,toolName:t.toolName,state:"input-available",input:t.input,providerExecuted:t.providerExecuted,providerMetadata:t.providerMetadata,title:t.title,toolMetadata:t.toolMetadata}),p(),i&&!t.providerExecuted&&await i({toolCall:t});break;case"tool-input-error":{let e=g().filter(tt).find(e=>e.toolCallId===t.toolCallId);(null!=e?"dynamic-tool"===e.type:t.dynamic)?b({toolCallId:t.toolCallId,toolName:t.toolName,state:"output-error",input:t.input,errorText:t.errorText,providerExecuted:t.providerExecuted,providerMetadata:t.providerMetadata,toolMetadata:t.toolMetadata}):v({toolCallId:t.toolCallId,toolName:t.toolName,state:"output-error",input:void 0,rawInput:t.input,errorText:t.errorText,providerExecuted:t.providerExecuted,providerMetadata:t.providerMetadata,toolMetadata:t.toolMetadata}),p();break}case"tool-approval-request":{let e=m(t.toolCallId);e.state="approval-requested",e.approval={id:t.approvalId,...!0===t.isAutomatic?{isAutomatic:!0}:{},...null!=t.signature?{signature:t.signature}:{}},p();break}case"tool-approval-response":{let e=function(t){let e=o.message.parts.filter(tt).find(e=>{var a;return(null==(a=e.approval)?void 0:a.id)===t});if(null==e)throw new y({chunkType:"tool-approval-response",chunkId:t,message:`No tool invocation found for approval ID "${t}".`});return e}(t.approvalId),a=null==e.approval?{id:t.approvalId}:e.approval;e.state="approval-responded",e.approval={id:t.approvalId,approved:t.approved,...null!=t.reason?{reason:t.reason}:{},...!0===a.isAutomatic?{isAutomatic:!0}:{},...null!=a.signature?{signature:a.signature}:{}},null!=t.providerExecuted&&(e.providerExecuted=t.providerExecuted),null!=t.providerMetadata&&(e.callProviderMetadata=t.providerMetadata),p();break}case"tool-output-denied":m(t.toolCallId).state="output-denied",p();break;case"tool-output-available":{let e=m(t.toolCallId);"dynamic-tool"===e.type?b({toolCallId:t.toolCallId,toolName:e.toolName,state:"output-available",input:e.input,output:t.output,preliminary:t.preliminary,providerExecuted:t.providerExecuted,providerMetadata:t.providerMetadata,title:e.title,toolMetadata:e.toolMetadata},e):v({toolCallId:t.toolCallId,toolName:te(e),state:"output-available",input:e.input,output:t.output,providerExecuted:t.providerExecuted,preliminary:t.preliminary,providerMetadata:t.providerMetadata,title:e.title,toolMetadata:e.toolMetadata},e),p();break}case"tool-output-error":{let e=m(t.toolCallId);"dynamic-tool"===e.type?b({toolCallId:t.toolCallId,toolName:e.toolName,state:"output-error",input:e.input,errorText:t.errorText,providerExecuted:t.providerExecuted,providerMetadata:t.providerMetadata,title:e.title,toolMetadata:e.toolMetadata},e):v({toolCallId:t.toolCallId,toolName:te(e),state:"output-error",input:e.input,rawInput:e.rawInput,errorText:t.errorText,providerExecuted:t.providerExecuted,providerMetadata:t.providerMetadata,title:e.title,toolMetadata:e.toolMetadata},e),p();break}case"start-step":o.message.parts.push({type:"step-start"});break;case"finish-step":o.activeTextParts=H(),o.activeReasoningParts=H();break;case"start":null!=t.messageId&&(o.message.id=t.messageId),await f(t.messageMetadata),(null!=t.messageId||null!=t.messageMetadata)&&p();break;case"finish":null!=t.finishReason&&(o.finishReason=t.finishReason),await f(t.messageMetadata),null!=t.messageMetadata&&p();break;case"message-metadata":await f(t.messageMetadata),null!=t.messageMetadata&&p();break;case"error":null==s||s(Error(t.errorText));break;default:if(t.type.startsWith("data-")){if((null==a?void 0:a[t.type])!=null){let e=o.message.parts.findIndex(e=>
1"id"in e&&"data"in e&&e.id===t.id&&e.type===t.type),s=e>=0?e:o.message.parts.length;await (0,r.k5)({value:t.data,schema:a[t.type],context:{field:`message.parts[${s}].data`,entityName:t.type,entityId:t.id}})}if(t.transient){null==l||l(t);break}let e=null!=t.id?o.message.parts.find(e=>t.type===e.type&&t.id===e.id):void 0;null!=e?e.data=t.data:o.message.parts.push(t),null==l||l(t),p()}}n.enqueue(t)})}}))}({stream:i,onToolCall:this.onToolCall,onData:this.onData,messageMetadataSchema:this.messageMetadataSchema,dataPartSchemas:this.dataPartSchemas,runUpdateMessageJob:n,onError:t=>{throw t}}),abortSignal:l.abortController.signal,onError:t=>{throw t}}),v)return h()&&this.setStatus({status:"ready"}),null;h()&&this.setStatus({status:"ready"})}catch(t){if(v||"AbortError"===t.name)return v=!0,h()&&this.setStatus({status:"ready"}),null;if(!h())return null;f=!0,t instanceof TypeError&&(t.message.toLowerCase().includes("fetch")||t.message.toLowerCase().includes("network"))&&(b=!0),this.onError&&t instanceof Error&&this.onError(t),this.setStatus({status:"error",error:t})}finally{try{u&&(null==(l=this.onFinish)||l.call(this,{message:u.state.message,messages:this.state.messages,isAbort:v,isDisconnect:b,isError:f,finishReason:u.state.finishReason}))}catch(t){console.error(t)}this.activeResponse===u&&(this.activeResponse=void 0),g()}!f&&await this.shouldSendAutomatically()&&await this.makeRequest({trigger:"submit-message",messageId:null==(n=this.lastMessage)?void 0:n.id,metadata:e,headers:a,body:o})}}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.