PageSourceSearch

https://www.efuturanetworks.com/_next/static/chunks/06989220.84e93d467f3c8217.js

js efuturanetworks.com collected 2026-10-05 03:14:40 UTC 61,048 bytes, 1 lines download raw bytes

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

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.