@ag-ui/client 0.0.40-alpha.8 → 0.0.40-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- "use strict";var Ot=Object.create;var $=Object.defineProperty,wt=Object.defineProperties,Pt=Object.getOwnPropertyDescriptor,Dt=Object.getOwnPropertyDescriptors,Ht=Object.getOwnPropertyNames,pt=Object.getOwnPropertySymbols,Gt=Object.getPrototypeOf,mt=Object.prototype.hasOwnProperty,Ft=Object.prototype.propertyIsEnumerable;var dt=(i,s,e)=>s in i?$(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,L=(i,s)=>{for(var e in s||(s={}))mt.call(s,e)&&dt(i,e,s[e]);if(pt)for(var e of pt(s))Ft.call(s,e)&&dt(i,e,s[e]);return i},X=(i,s)=>wt(i,Dt(s));var Ut=(i,s)=>{for(var e in s)$(i,e,{get:s[e],enumerable:!0})},Y=(i,s,e,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let t of Ht(s))!mt.call(i,t)&&t!==e&&$(i,t,{get:()=>s[t],enumerable:!(a=Pt(s,t))||a.enumerable});return i},D=(i,s,e)=>(Y(i,s,"default"),e&&Y(e,s,"default")),W=(i,s,e)=>(e=i!=null?Ot(Gt(i)):{},Y(s||!i||!i.__esModule?$(e,"default",{value:i,enumerable:!0}):e,i)),Xt=i=>Y($({},"__esModule",{value:!0}),i);var P={};Ut(P,{AbstractAgent:()=>z,HttpAgent:()=>it,compactEvents:()=>Lt,convertToLegacyEvents:()=>ot,defaultApplyEvents:()=>Q,parseProtoStream:()=>nt,parseSSEStream:()=>et,randomUUID:()=>Bt,runHttpRequest:()=>tt,structuredClone_:()=>R,transformChunks:()=>V,transformHttpEventStream:()=>at,verifyEvents:()=>K});module.exports=Xt(P);var _=require("@ag-ui/core"),k=require("rxjs/operators"),q=require("rxjs");var ft=require("uuid");var R=i=>{if(typeof structuredClone=="function")return structuredClone(i);try{return JSON.parse(JSON.stringify(i))}catch(s){return L({},i)}};function Bt(){return(0,ft.v4)()}var gt=require("fast-json-patch");async function x(i,s,e,a){let t=s,n=e,r;for(let o of i)try{let l=await a(o,R(t),R(n));if(l===void 0)continue;if(l.messages!==void 0&&(t=l.messages),l.state!==void 0&&(n=l.state),r=l.stopPropagation,r===!0)break}catch(l){process.env.NODE_ENV==="test"||process.env.JEST_WORKER_ID!==void 0||console.error("Subscriber error:",l);continue}return L(L(L({},JSON.stringify(t)!==JSON.stringify(s)?{messages:t}:{}),JSON.stringify(n)!==JSON.stringify(e)?{state:n}:{}),r!==void 0?{stopPropagation:r}:{})}var Tt=W(require("untruncate-json"));var Q=(i,s,e,a)=>{let t=R(i.messages),n=R(i.state),r={},o=d=>{d.messages!==void 0&&(t=d.messages,r.messages=d.messages),d.state!==void 0&&(n=d.state,r.state=d.state)},l=()=>{let d=R(r);return r={},d.messages!==void 0||d.state!==void 0?(0,q.of)(d):q.EMPTY};return s.pipe((0,k.concatMap)(async d=>{var T,y,c;let A=await x(a,t,n,(u,g,p)=>{var m;return(m=u.onEvent)==null?void 0:m.call(u,{event:d,agent:e,input:i,messages:g,state:p})});if(o(A),A.stopPropagation===!0)return l();switch(d.type){case _.EventType.TEXT_MESSAGE_START:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onTextMessageStartEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});if(o(u),u.stopPropagation!==!0){let{messageId:g,role:p="assistant"}=d,m={id:g,role:p,content:""};t.push(m),o({messages:t})}return l()}case _.EventType.TEXT_MESSAGE_CONTENT:{let{messageId:u,delta:g}=d,p=t.find(E=>E.id===u);if(!p)return console.warn(`TEXT_MESSAGE_CONTENT: No message found with ID '${u}'`),l();let m=await x(a,t,n,(E,S,C)=>{var N;return(N=E.onTextMessageContentEvent)==null?void 0:N.call(E,{event:d,messages:S,state:C,agent:e,input:i,textMessageBuffer:typeof p.content=="string"?p.content:""})});if(o(m),m.stopPropagation!==!0){let E=typeof p.content=="string"?p.content:"";p.content=`${E}${g}`,o({messages:t})}return l()}case _.EventType.TEXT_MESSAGE_END:{let{messageId:u}=d,g=t.find(m=>m.id===u);if(!g)return console.warn(`TEXT_MESSAGE_END: No message found with ID '${u}'`),l();let p=await x(a,t,n,(m,E,S)=>{var C;return(C=m.onTextMessageEndEvent)==null?void 0:C.call(m,{event:d,messages:E,state:S,agent:e,input:i,textMessageBuffer:typeof g.content=="string"?g.content:""})});return o(p),await Promise.all(a.map(m=>{var E;(E=m.onNewMessage)==null||E.call(m,{message:g,messages:t,state:n,agent:e,input:i})})),l()}case _.EventType.TOOL_CALL_START:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onToolCallStartEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});if(o(u),u.stopPropagation!==!0){let{toolCallId:g,toolCallName:p,parentMessageId:m}=d,E;m&&t.length>0&&t[t.length-1].id===m?E=t[t.length-1]:(E={id:m||g,role:"assistant",toolCalls:[]},t.push(E)),(T=E.toolCalls)!=null||(E.toolCalls=[]),E.toolCalls.push({id:g,type:"function",function:{name:p,arguments:""}}),o({messages:t})}return l()}case _.EventType.TOOL_CALL_ARGS:{let{toolCallId:u,delta:g}=d,p=t.find(S=>{var C;return(C=S.toolCalls)==null?void 0:C.some(N=>N.id===u)});if(!p)return console.warn(`TOOL_CALL_ARGS: No message found containing tool call with ID '${u}'`),l();let m=p.toolCalls.find(S=>S.id===u);if(!m)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${u}'`),l();let E=await x(a,t,n,(S,C,N)=>{var lt;let w=m.function.arguments,b=m.function.name,J={};try{J=(0,Tt.default)(w)}catch(te){}return(lt=S.onToolCallArgsEvent)==null?void 0:lt.call(S,{event:d,messages:C,state:N,agent:e,input:i,toolCallBuffer:w,toolCallName:b,partialToolCallArgs:J})});return o(E),E.stopPropagation!==!0&&(m.function.arguments+=g,o({messages:t})),l()}case _.EventType.TOOL_CALL_END:{let{toolCallId:u}=d,g=t.find(E=>{var S;return(S=E.toolCalls)==null?void 0:S.some(C=>C.id===u)});if(!g)return console.warn(`TOOL_CALL_END: No message found containing tool call with ID '${u}'`),l();let p=g.toolCalls.find(E=>E.id===u);if(!p)return console.warn(`TOOL_CALL_END: No tool call found with ID '${u}'`),l();let m=await x(a,t,n,(E,S,C)=>{var J;let N=p.function.arguments,w=p.function.name,b={};try{b=JSON.parse(N)}catch(lt){}return(J=E.onToolCallEndEvent)==null?void 0:J.call(E,{event:d,messages:S,state:C,agent:e,input:i,toolCallName:w,toolCallArgs:b})});return o(m),await Promise.all(a.map(E=>{var S;(S=E.onNewToolCall)==null||S.call(E,{toolCall:p,messages:t,state:n,agent:e,input:i})})),l()}case _.EventType.TOOL_CALL_RESULT:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onToolCallResultEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});if(o(u),u.stopPropagation!==!0){let{messageId:g,toolCallId:p,content:m,role:E}=d,S={id:g,toolCallId:p,role:E||"tool",content:m};t.push(S),await Promise.all(a.map(C=>{var N;(N=C.onNewMessage)==null||N.call(C,{message:S,messages:t,state:n,agent:e,input:i})})),o({messages:t})}return l()}case _.EventType.STATE_SNAPSHOT:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onStateSnapshotEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});if(o(u),u.stopPropagation!==!0){let{snapshot:g}=d;n=g,o({state:n})}return l()}case _.EventType.STATE_DELTA:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onStateDeltaEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});if(o(u),u.stopPropagation!==!0){let{delta:g}=d;try{n=(0,gt.applyPatch)(n,g,!0,!1).newDocument,o({state:n})}catch(p){let m=p instanceof Error?p.message:String(p);console.warn(`Failed to apply state patch:
1
+ "use strict";var wt=Object.create;var b=Object.defineProperty,Pt=Object.defineProperties,Dt=Object.getOwnPropertyDescriptor,Ht=Object.getOwnPropertyDescriptors,Gt=Object.getOwnPropertyNames,dt=Object.getOwnPropertySymbols,Ft=Object.getPrototypeOf,ft=Object.prototype.hasOwnProperty,Ut=Object.prototype.propertyIsEnumerable;var mt=(l,s,e)=>s in l?b(l,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[s]=e,L=(l,s)=>{for(var e in s||(s={}))ft.call(s,e)&&mt(l,e,s[e]);if(dt)for(var e of dt(s))Ut.call(s,e)&&mt(l,e,s[e]);return l},k=(l,s)=>Pt(l,Ht(s));var Xt=(l,s)=>{for(var e in s)b(l,e,{get:s[e],enumerable:!0})},W=(l,s,e,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let t of Gt(s))!ft.call(l,t)&&t!==e&&b(l,t,{get:()=>s[t],enumerable:!(a=Dt(s,t))||a.enumerable});return l},D=(l,s,e)=>(W(l,s,"default"),e&&W(e,s,"default")),q=(l,s,e)=>(e=l!=null?wt(Ft(l)):{},W(s||!l||!l.__esModule?b(e,"default",{value:l,enumerable:!0}):e,l)),Bt=l=>W(b({},"__esModule",{value:!0}),l);var P={};Xt(P,{AbstractAgent:()=>$,HttpAgent:()=>lt,compactEvents:()=>Ot,convertToLegacyEvents:()=>rt,defaultApplyEvents:()=>Z,parseProtoStream:()=>st,parseSSEStream:()=>nt,randomUUID:()=>kt,runHttpRequest:()=>et,structuredClone_:()=>R,transformChunks:()=>Y,transformHttpEventStream:()=>ot,verifyEvents:()=>z});module.exports=Bt(P);var _=require("@ag-ui/core"),j=require("rxjs/operators"),Q=require("rxjs");var Tt=require("uuid");var R=l=>{if(typeof structuredClone=="function")return structuredClone(l);try{return JSON.parse(JSON.stringify(l))}catch(s){return L({},l)}};function kt(){return(0,Tt.v4)()}var ct=require("fast-json-patch");async function x(l,s,e,a){let t=s,n=e,r;for(let o of l)try{let g=await a(o,R(t),R(n));if(g===void 0)continue;if(g.messages!==void 0&&(t=g.messages),g.state!==void 0&&(n=g.state),r=g.stopPropagation,r===!0)break}catch(g){process.env.NODE_ENV==="test"||process.env.JEST_WORKER_ID!==void 0||console.error("Subscriber error:",g);continue}return L(L(L({},JSON.stringify(t)!==JSON.stringify(s)?{messages:t}:{}),JSON.stringify(n)!==JSON.stringify(e)?{state:n}:{}),r!==void 0?{stopPropagation:r}:{})}var St=q(require("untruncate-json"));var Z=(l,s,e,a)=>{let t=R(l.messages),n=R(l.state),r={},o=u=>{u.messages!==void 0&&(t=u.messages,r.messages=u.messages),u.state!==void 0&&(n=u.state,r.state=u.state)},g=()=>{let u=R(r);return r={},u.messages!==void 0||u.state!==void 0?(0,Q.of)(u):Q.EMPTY};return s.pipe((0,j.concatMap)(async u=>{var T,y,c,G;let S=await x(a,t,n,(p,i,d)=>{var m;return(m=p.onEvent)==null?void 0:m.call(p,{event:u,agent:e,input:l,messages:i,state:d})});if(o(S),S.stopPropagation===!0)return g();switch(u.type){case _.EventType.TEXT_MESSAGE_START:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onTextMessageStartEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});if(o(p),p.stopPropagation!==!0){let{messageId:i,role:d="assistant"}=u,m={id:i,role:d,content:""};t.push(m),o({messages:t})}return g()}case _.EventType.TEXT_MESSAGE_CONTENT:{let{messageId:p,delta:i}=u,d=t.find(E=>E.id===p);if(!d)return console.warn(`TEXT_MESSAGE_CONTENT: No message found with ID '${p}'`),g();let m=await x(a,t,n,(E,v,M)=>{var N;return(N=E.onTextMessageContentEvent)==null?void 0:N.call(E,{event:u,messages:v,state:M,agent:e,input:l,textMessageBuffer:typeof d.content=="string"?d.content:""})});if(o(m),m.stopPropagation!==!0){let E=typeof d.content=="string"?d.content:"";d.content=`${E}${i}`,o({messages:t})}return g()}case _.EventType.TEXT_MESSAGE_END:{let{messageId:p}=u,i=t.find(m=>m.id===p);if(!i)return console.warn(`TEXT_MESSAGE_END: No message found with ID '${p}'`),g();let d=await x(a,t,n,(m,E,v)=>{var M;return(M=m.onTextMessageEndEvent)==null?void 0:M.call(m,{event:u,messages:E,state:v,agent:e,input:l,textMessageBuffer:typeof i.content=="string"?i.content:""})});return o(d),await Promise.all(a.map(m=>{var E;(E=m.onNewMessage)==null||E.call(m,{message:i,messages:t,state:n,agent:e,input:l})})),g()}case _.EventType.TOOL_CALL_START:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onToolCallStartEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});if(o(p),p.stopPropagation!==!0){let{toolCallId:i,toolCallName:d,parentMessageId:m}=u,E;m&&t.length>0&&t[t.length-1].id===m?E=t[t.length-1]:(E={id:m||i,role:"assistant",toolCalls:[]},t.push(E)),(T=E.toolCalls)!=null||(E.toolCalls=[]),E.toolCalls.push({id:i,type:"function",function:{name:d,arguments:""}}),o({messages:t})}return g()}case _.EventType.TOOL_CALL_ARGS:{let{toolCallId:p,delta:i}=u,d=t.find(v=>{var M;return(M=v.toolCalls)==null?void 0:M.some(N=>N.id===p)});if(!d)return console.warn(`TOOL_CALL_ARGS: No message found containing tool call with ID '${p}'`),g();let m=d.toolCalls.find(v=>v.id===p);if(!m)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${p}'`),g();let E=await x(a,t,n,(v,M,N)=>{var gt;let w=m.function.arguments,F=m.function.name,V={};try{V=(0,St.default)(w)}catch(ee){}return(gt=v.onToolCallArgsEvent)==null?void 0:gt.call(v,{event:u,messages:M,state:N,agent:e,input:l,toolCallBuffer:w,toolCallName:F,partialToolCallArgs:V})});return o(E),E.stopPropagation!==!0&&(m.function.arguments+=i,o({messages:t})),g()}case _.EventType.TOOL_CALL_END:{let{toolCallId:p}=u,i=t.find(E=>{var v;return(v=E.toolCalls)==null?void 0:v.some(M=>M.id===p)});if(!i)return console.warn(`TOOL_CALL_END: No message found containing tool call with ID '${p}'`),g();let d=i.toolCalls.find(E=>E.id===p);if(!d)return console.warn(`TOOL_CALL_END: No tool call found with ID '${p}'`),g();let m=await x(a,t,n,(E,v,M)=>{var V;let N=d.function.arguments,w=d.function.name,F={};try{F=JSON.parse(N)}catch(gt){}return(V=E.onToolCallEndEvent)==null?void 0:V.call(E,{event:u,messages:v,state:M,agent:e,input:l,toolCallName:w,toolCallArgs:F})});return o(m),await Promise.all(a.map(E=>{var v;(v=E.onNewToolCall)==null||v.call(E,{toolCall:d,messages:t,state:n,agent:e,input:l})})),g()}case _.EventType.TOOL_CALL_RESULT:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onToolCallResultEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});if(o(p),p.stopPropagation!==!0){let{messageId:i,toolCallId:d,content:m,role:E}=u,v={id:i,toolCallId:d,role:E||"tool",content:m};t.push(v),await Promise.all(a.map(M=>{var N;(N=M.onNewMessage)==null||N.call(M,{message:v,messages:t,state:n,agent:e,input:l})})),o({messages:t})}return g()}case _.EventType.STATE_SNAPSHOT:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onStateSnapshotEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});if(o(p),p.stopPropagation!==!0){let{snapshot:i}=u;n=i,o({state:n})}return g()}case _.EventType.STATE_DELTA:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onStateDeltaEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});if(o(p),p.stopPropagation!==!0){let{delta:i}=u;try{n=(0,ct.applyPatch)(n,i,!0,!1).newDocument,o({state:n})}catch(d){let m=d instanceof Error?d.message:String(d);console.warn(`Failed to apply state patch:
2
2
  Current state: ${JSON.stringify(n,null,2)}
3
- Patch operations: ${JSON.stringify(g,null,2)}
4
- Error: ${m}`)}}return l()}case _.EventType.MESSAGES_SNAPSHOT:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onMessagesSnapshotEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});if(o(u),u.stopPropagation!==!0){let{messages:g}=d;t=g,o({messages:t})}return l()}case _.EventType.ACTIVITY_SNAPSHOT:{let u=d,g=t.findIndex(S=>S.id===u.messageId),p=g>=0?t[g]:void 0,m=(p==null?void 0:p.role)==="activity"?p:void 0,E=await x(a,t,n,(S,C,N)=>{var w;return(w=S.onActivitySnapshotEvent)==null?void 0:w.call(S,{event:u,messages:C,state:N,agent:e,input:i,activityMessage:m,existingMessage:p})});if(o(E),E.stopPropagation!==!0){let S={id:u.messageId,role:"activity",activityType:u.activityType,content:R(u.content)},C;g===-1?(t.push(S),C=S):m?t[g]=X(L({},m),{activityType:u.activityType,content:R(u.content)}):(t[g]=S,C=S),o({messages:t}),C&&await Promise.all(a.map(N=>{var w;return(w=N.onNewMessage)==null?void 0:w.call(N,{message:C,messages:t,state:n,agent:e,input:i})}))}return l()}case _.EventType.ACTIVITY_DELTA:{let u=d,g=t.findIndex(S=>S.id===u.messageId);if(g===-1)return console.warn(`ACTIVITY_DELTA: No message found with ID '${u.messageId}' to apply patch`),l();let p=t[g];if(p.role!=="activity")return console.warn(`ACTIVITY_DELTA: Message '${u.messageId}' is not an activity message`),l();let m=p,E=await x(a,t,n,(S,C,N)=>{var w;return(w=S.onActivityDeltaEvent)==null?void 0:w.call(S,{event:u,messages:C,state:N,agent:e,input:i,activityMessage:m})});if(o(E),E.stopPropagation!==!0)try{let S=R(m);S.activityType=u.activityType,(y=S.content)!=null||(S.content={});let N=(0,gt.applyPatch)(S,u.patch,!0,!1).newDocument;t[g]=X(L({},N),{id:m.id,role:"activity",activityType:u.activityType}),o({messages:t})}catch(S){let C=S instanceof Error?S.message:String(S);console.warn(`Failed to apply activity patch for '${u.messageId}': ${C}`)}return l()}case _.EventType.RAW:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onRawEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});return o(u),l()}case _.EventType.CUSTOM:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onCustomEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});return o(u),l()}case _.EventType.RUN_STARTED:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onRunStartedEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});if(o(u),u.stopPropagation!==!0){let g=d;if((c=g.input)!=null&&c.messages){for(let p of g.input.messages)t.find(E=>E.id===p.id)||t.push(p);o({messages:t})}}return l()}case _.EventType.RUN_FINISHED:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onRunFinishedEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i,result:d.result})});return o(u),l()}case _.EventType.RUN_ERROR:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onRunErrorEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});return o(u),l()}case _.EventType.STEP_STARTED:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onStepStartedEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});return o(u),l()}case _.EventType.STEP_FINISHED:{let u=await x(a,t,n,(g,p,m)=>{var E;return(E=g.onStepFinishedEvent)==null?void 0:E.call(g,{event:d,messages:p,state:m,agent:e,input:i})});return o(u),l()}case _.EventType.TEXT_MESSAGE_CHUNK:throw new Error("TEXT_MESSAGE_CHUNK must be tranformed before being applied");case _.EventType.TOOL_CALL_CHUNK:throw new Error("TOOL_CALL_CHUNK must be tranformed before being applied");case _.EventType.THINKING_START:return l();case _.EventType.THINKING_END:return l();case _.EventType.THINKING_TEXT_MESSAGE_START:return l();case _.EventType.THINKING_TEXT_MESSAGE_CONTENT:return l();case _.EventType.THINKING_TEXT_MESSAGE_END:return l()}let H=d.type;return l()}),(0,k.mergeAll)(),a.length>0?(0,k.defaultIfEmpty)({}):d=>d)};var v=require("@ag-ui/core"),h=require("rxjs"),St=require("rxjs/operators"),K=i=>s=>{let e=new Map,a=new Map,t=!1,n=!1,r=!1,o=new Map,l=!1,d=!1,A=!1,H=()=>{e.clear(),a.clear(),o.clear(),l=!1,d=!1,t=!1,n=!1,A=!0};return s.pipe((0,St.mergeMap)(T=>{let y=T.type;if(i&&console.debug("[VERIFY]:",JSON.stringify(T)),n)return(0,h.throwError)(()=>new v.AGUIError(`Cannot send event type '${y}': The run has already errored with 'RUN_ERROR'. No further events can be sent.`));if(t&&y!==v.EventType.RUN_ERROR&&y!==v.EventType.RUN_STARTED)return(0,h.throwError)(()=>new v.AGUIError(`Cannot send event type '${y}': The run has already finished with 'RUN_FINISHED'. Start a new run with 'RUN_STARTED'.`));if(r){if(y===v.EventType.RUN_STARTED){if(A&&!t)return(0,h.throwError)(()=>new v.AGUIError("Cannot send 'RUN_STARTED' while a run is still active. The previous run must be finished with 'RUN_FINISHED' before starting a new run."));t&&H()}}else if(r=!0,y!==v.EventType.RUN_STARTED&&y!==v.EventType.RUN_ERROR)return(0,h.throwError)(()=>new v.AGUIError("First event must be 'RUN_STARTED'"));switch(y){case v.EventType.TEXT_MESSAGE_START:{let c=T.messageId;return e.has(c)?(0,h.throwError)(()=>new v.AGUIError(`Cannot send 'TEXT_MESSAGE_START' event: A text message with ID '${c}' is already in progress. Complete it with 'TEXT_MESSAGE_END' first.`)):(e.set(c,!0),(0,h.of)(T))}case v.EventType.TEXT_MESSAGE_CONTENT:{let c=T.messageId;return e.has(c)?(0,h.of)(T):(0,h.throwError)(()=>new v.AGUIError(`Cannot send 'TEXT_MESSAGE_CONTENT' event: No active text message found with ID '${c}'. Start a text message with 'TEXT_MESSAGE_START' first.`))}case v.EventType.TEXT_MESSAGE_END:{let c=T.messageId;return e.has(c)?(e.delete(c),(0,h.of)(T)):(0,h.throwError)(()=>new v.AGUIError(`Cannot send 'TEXT_MESSAGE_END' event: No active text message found with ID '${c}'. A 'TEXT_MESSAGE_START' event must be sent first.`))}case v.EventType.TOOL_CALL_START:{let c=T.toolCallId;return a.has(c)?(0,h.throwError)(()=>new v.AGUIError(`Cannot send 'TOOL_CALL_START' event: A tool call with ID '${c}' is already in progress. Complete it with 'TOOL_CALL_END' first.`)):(a.set(c,!0),(0,h.of)(T))}case v.EventType.TOOL_CALL_ARGS:{let c=T.toolCallId;return a.has(c)?(0,h.of)(T):(0,h.throwError)(()=>new v.AGUIError(`Cannot send 'TOOL_CALL_ARGS' event: No active tool call found with ID '${c}'. Start a tool call with 'TOOL_CALL_START' first.`))}case v.EventType.TOOL_CALL_END:{let c=T.toolCallId;return a.has(c)?(a.delete(c),(0,h.of)(T)):(0,h.throwError)(()=>new v.AGUIError(`Cannot send 'TOOL_CALL_END' event: No active tool call found with ID '${c}'. A 'TOOL_CALL_START' event must be sent first.`))}case v.EventType.STEP_STARTED:{let c=T.stepName;return o.has(c)?(0,h.throwError)(()=>new v.AGUIError(`Step "${c}" is already active for 'STEP_STARTED'`)):(o.set(c,!0),(0,h.of)(T))}case v.EventType.STEP_FINISHED:{let c=T.stepName;return o.has(c)?(o.delete(c),(0,h.of)(T)):(0,h.throwError)(()=>new v.AGUIError(`Cannot send 'STEP_FINISHED' for step "${c}" that was not started`))}case v.EventType.RUN_STARTED:return A=!0,(0,h.of)(T);case v.EventType.RUN_FINISHED:{if(o.size>0){let c=Array.from(o.keys()).join(", ");return(0,h.throwError)(()=>new v.AGUIError(`Cannot send 'RUN_FINISHED' while steps are still active: ${c}`))}if(e.size>0){let c=Array.from(e.keys()).join(", ");return(0,h.throwError)(()=>new v.AGUIError(`Cannot send 'RUN_FINISHED' while text messages are still active: ${c}`))}if(a.size>0){let c=Array.from(a.keys()).join(", ");return(0,h.throwError)(()=>new v.AGUIError(`Cannot send 'RUN_FINISHED' while tool calls are still active: ${c}`))}return t=!0,(0,h.of)(T)}case v.EventType.RUN_ERROR:return n=!0,(0,h.of)(T);case v.EventType.CUSTOM:return(0,h.of)(T);case v.EventType.THINKING_TEXT_MESSAGE_START:return l?d?(0,h.throwError)(()=>new v.AGUIError("Cannot send 'THINKING_TEXT_MESSAGE_START' event: A thinking message is already in progress. Complete it with 'THINKING_TEXT_MESSAGE_END' first.")):(d=!0,(0,h.of)(T)):(0,h.throwError)(()=>new v.AGUIError("Cannot send 'THINKING_TEXT_MESSAGE_START' event: A thinking step is not in progress. Create one with 'THINKING_START' first."));case v.EventType.THINKING_TEXT_MESSAGE_CONTENT:return d?(0,h.of)(T):(0,h.throwError)(()=>new v.AGUIError("Cannot send 'THINKING_TEXT_MESSAGE_CONTENT' event: No active thinking message found. Start a message with 'THINKING_TEXT_MESSAGE_START' first."));case v.EventType.THINKING_TEXT_MESSAGE_END:return d?(d=!1,(0,h.of)(T)):(0,h.throwError)(()=>new v.AGUIError("Cannot send 'THINKING_TEXT_MESSAGE_END' event: No active thinking message found. A 'THINKING_TEXT_MESSAGE_START' event must be sent first."));case v.EventType.THINKING_START:return l?(0,h.throwError)(()=>new v.AGUIError("Cannot send 'THINKING_START' event: A thinking step is already in progress. End it with 'THINKING_END' first.")):(l=!0,(0,h.of)(T));case v.EventType.THINKING_END:return l?(l=!1,(0,h.of)(T)):(0,h.throwError)(()=>new v.AGUIError("Cannot send 'THINKING_END' event: No active thinking step found. A 'THINKING_START' event must be sent first."));default:return(0,h.of)(T)}}))};var yt=require("@ag-ui/core"),st=require("rxjs");var G=require("rxjs"),Z=require("rxjs/operators");var tt=(i,s)=>(0,G.defer)(()=>(0,G.from)(fetch(i,s))).pipe((0,Z.switchMap)(e=>{var n;if(!e.ok){let r=e.headers.get("content-type")||"";return(0,G.from)(e.text()).pipe((0,Z.mergeMap)(o=>{let l=o;if(r.includes("application/json"))try{l=JSON.parse(o)}catch(A){}let d=new Error(`HTTP ${e.status}: ${typeof l=="string"?l:JSON.stringify(l)}`);return d.status=e.status,d.payload=l,(0,G.throwError)(()=>d)}))}let a={type:"headers",status:e.status,headers:e.headers},t=(n=e.body)==null?void 0:n.getReader();return t?new G.Observable(r=>(r.next(a),(async()=>{try{for(;;){let{done:o,value:l}=await t.read();if(o)break;let d={type:"data",data:l};r.next(d)}r.complete()}catch(o){r.error(o)}})(),()=>{t.cancel().catch(o=>{if((o==null?void 0:o.name)!=="AbortError")throw o})})):(0,G.throwError)(()=>new Error("Failed to getReader() from response"))}));var At=require("rxjs");var et=i=>{let s=new At.Subject,e=new TextDecoder("utf-8",{fatal:!1}),a="";i.subscribe({next:n=>{if(n.type!=="headers"&&n.type==="data"&&n.data){let r=e.decode(n.data,{stream:!0});a+=r;let o=a.split(/\n\n/);a=o.pop()||"";for(let l of o)t(l)}},error:n=>s.error(n),complete:()=>{a&&(a+=e.decode(),t(a)),s.complete()}});function t(n){let r=n.split(`
5
- `),o=[];for(let l of r)l.startsWith("data: ")&&o.push(l.slice(6));if(o.length>0)try{let l=o.join(`
6
- `),d=JSON.parse(l);s.next(d)}catch(l){s.error(l)}}return s.asObservable()};var vt=require("rxjs");var ht=W(require("@ag-ui/proto")),nt=i=>{let s=new vt.Subject,e=new Uint8Array(0);i.subscribe({next:t=>{if(t.type!=="headers"&&t.type==="data"&&t.data){let n=new Uint8Array(e.length+t.data.length);n.set(e,0),n.set(t.data,e.length),e=n,a()}},error:t=>s.error(t),complete:()=>{if(e.length>0)try{a()}catch(t){console.warn("Incomplete or invalid protocol buffer data at stream end")}s.complete()}});function a(){for(;e.length>=4;){let r=4+new DataView(e.buffer,e.byteOffset,4).getUint32(0,!1);if(e.length<r)break;try{let o=e.slice(4,r),l=ht.decode(o);s.next(l),e=e.slice(r)}catch(o){let l=o instanceof Error?o.message:String(o);s.error(new Error(`Failed to decode protocol buffer message: ${l}`));return}}}return s.asObservable()};var Mt=W(require("@ag-ui/proto")),Ct=require("@ag-ui/core"),at=i=>{let s=new st.Subject,e=new st.ReplaySubject,a=!1;return i.subscribe({next:t=>{e.next(t),t.type==="headers"&&!a?(a=!0,t.headers.get("content-type")===Mt.AGUI_MEDIA_TYPE?nt(e).subscribe({next:r=>s.next(r),error:r=>s.error(r),complete:()=>s.complete()}):et(e).subscribe({next:r=>{try{let o=yt.EventSchemas.parse(r);s.next(o)}catch(o){s.error(o)}},error:r=>{if((r==null?void 0:r.name)==="AbortError"){s.next({type:Ct.EventType.RUN_ERROR,rawEvent:r}),s.complete();return}return s.error(r)},complete:()=>s.complete()})):a||s.error(new Error("No headers event received before data events"))},error:t=>{e.error(t),s.error(t)},complete:()=>{e.complete()}}),s.asObservable()};var Rt=require("rxjs/operators"),_t=require("fast-json-patch"),O=require("@ag-ui/core");var f=require("zod"),I=f.z.enum(["TextMessageStart","TextMessageContent","TextMessageEnd","ActionExecutionStart","ActionExecutionArgs","ActionExecutionEnd","ActionExecutionResult","AgentStateMessage","MetaEvent","RunStarted","RunFinished","RunError","NodeStarted","NodeFinished"]),kt=f.z.enum(["LangGraphInterruptEvent","PredictState","Exit"]),Kt=f.z.object({type:f.z.literal(I.enum.TextMessageStart),messageId:f.z.string(),parentMessageId:f.z.string().optional(),role:f.z.string().optional()}),jt=f.z.object({type:f.z.literal(I.enum.TextMessageContent),messageId:f.z.string(),content:f.z.string()}),zt=f.z.object({type:f.z.literal(I.enum.TextMessageEnd),messageId:f.z.string()}),Jt=f.z.object({type:f.z.literal(I.enum.ActionExecutionStart),actionExecutionId:f.z.string(),actionName:f.z.string(),parentMessageId:f.z.string().optional()}),$t=f.z.object({type:f.z.literal(I.enum.ActionExecutionArgs),actionExecutionId:f.z.string(),args:f.z.string()}),Vt=f.z.object({type:f.z.literal(I.enum.ActionExecutionEnd),actionExecutionId:f.z.string()}),bt=f.z.object({type:f.z.literal(I.enum.ActionExecutionResult),actionName:f.z.string(),actionExecutionId:f.z.string(),result:f.z.string()}),Yt=f.z.object({type:f.z.literal(I.enum.AgentStateMessage),threadId:f.z.string(),agentName:f.z.string(),nodeName:f.z.string(),runId:f.z.string(),active:f.z.boolean(),role:f.z.string(),state:f.z.string(),running:f.z.boolean()}),Wt=f.z.object({type:f.z.literal(I.enum.MetaEvent),name:kt,value:f.z.any()}),qt=f.z.object({type:f.z.literal(I.enum.RunError),message:f.z.string(),code:f.z.string().optional()}),un=f.z.discriminatedUnion("type",[Kt,jt,zt,Jt,$t,Vt,bt,Yt,Wt,qt]),pn=f.z.object({id:f.z.string(),role:f.z.string(),content:f.z.string(),parentMessageId:f.z.string().optional()}),dn=f.z.object({id:f.z.string(),name:f.z.string(),arguments:f.z.any(),parentMessageId:f.z.string().optional()}),mn=f.z.object({id:f.z.string(),result:f.z.any(),actionExecutionId:f.z.string(),actionName:f.z.string()});var It=W(require("untruncate-json"));var Qt=i=>{if(typeof i=="string")return i;if(!Array.isArray(i))return;let s=i.filter(e=>e.type==="text").map(e=>e.text).filter(e=>e.length>0);if(s.length!==0)return s.join(`
7
- `)},ot=(i,s,e)=>a=>{let t={},n=!0,r=!0,o="",l=null,d=null,A=[],H={},T=y=>{typeof y=="object"&&y!==null&&("messages"in y&&delete y.messages,t=y)};return a.pipe((0,Rt.mergeMap)(y=>{switch(y.type){case O.EventType.TEXT_MESSAGE_START:{let c=y;return[{type:I.enum.TextMessageStart,messageId:c.messageId,role:c.role}]}case O.EventType.TEXT_MESSAGE_CONTENT:{let c=y;return[{type:I.enum.TextMessageContent,messageId:c.messageId,content:c.delta}]}case O.EventType.TEXT_MESSAGE_END:{let c=y;return[{type:I.enum.TextMessageEnd,messageId:c.messageId}]}case O.EventType.TOOL_CALL_START:{let c=y;return A.push({id:c.toolCallId,type:"function",function:{name:c.toolCallName,arguments:""}}),r=!0,H[c.toolCallId]=c.toolCallName,[{type:I.enum.ActionExecutionStart,actionExecutionId:c.toolCallId,actionName:c.toolCallName,parentMessageId:c.parentMessageId}]}case O.EventType.TOOL_CALL_ARGS:{let c=y,u=A.find(p=>p.id===c.toolCallId);if(!u)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${c.toolCallId}'`),[];u.function.arguments+=c.delta;let g=!1;if(d){let p=d.find(m=>m.tool==u.function.name);if(p)try{let m=JSON.parse((0,It.default)(u.function.arguments));p.tool_argument&&p.tool_argument in m?(T(X(L({},t),{[p.state_key]:m[p.tool_argument]})),g=!0):p.tool_argument||(T(X(L({},t),{[p.state_key]:m})),g=!0)}catch(m){}}return[{type:I.enum.ActionExecutionArgs,actionExecutionId:c.toolCallId,args:c.delta},...g?[{type:I.enum.AgentStateMessage,threadId:i,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(t),active:r}]:[]]}case O.EventType.TOOL_CALL_END:{let c=y;return[{type:I.enum.ActionExecutionEnd,actionExecutionId:c.toolCallId}]}case O.EventType.TOOL_CALL_RESULT:{let c=y;return[{type:I.enum.ActionExecutionResult,actionExecutionId:c.toolCallId,result:c.content,actionName:H[c.toolCallId]||"unknown"}]}case O.EventType.RAW:return[];case O.EventType.CUSTOM:{let c=y;switch(c.name){case"Exit":n=!1;break;case"PredictState":d=c.value;break}return[{type:I.enum.MetaEvent,name:c.name,value:c.value}]}case O.EventType.STATE_SNAPSHOT:return T(y.snapshot),[{type:I.enum.AgentStateMessage,threadId:i,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(t),active:r}];case O.EventType.STATE_DELTA:{let u=(0,_t.applyPatch)(t,y.delta,!0,!1);return u?(T(u.newDocument),[{type:I.enum.AgentStateMessage,threadId:i,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(t),active:r}]):[]}case O.EventType.MESSAGES_SNAPSHOT:return l=y.messages,[{type:I.enum.AgentStateMessage,threadId:i,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(L(L({},t),l?{messages:l}:{})),active:!0}];case O.EventType.RUN_STARTED:return[];case O.EventType.RUN_FINISHED:return l&&(t.messages=l),Object.keys(t).length===0?[]:[{type:I.enum.AgentStateMessage,threadId:i,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(L(L({},t),l?{messages:Zt(l)}:{})),active:!1}];case O.EventType.RUN_ERROR:{let c=y;return[{type:I.enum.RunError,message:c.message,code:c.code}]}case O.EventType.STEP_STARTED:return o=y.stepName,A=[],d=null,[{type:I.enum.AgentStateMessage,threadId:i,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(t),active:!0}];case O.EventType.STEP_FINISHED:return A=[],d=null,[{type:I.enum.AgentStateMessage,threadId:i,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(t),active:!1}];default:return[]}}))};function Zt(i){var e;let s=[];for(let a of i)if(a.role==="assistant"||a.role==="user"||a.role==="system"){let t=Qt(a.content);if(t){let n={id:a.id,role:a.role,content:t};s.push(n)}if(a.role==="assistant"&&a.toolCalls&&a.toolCalls.length>0)for(let n of a.toolCalls){let r={id:n.id,name:n.function.name,arguments:JSON.parse(n.function.arguments),parentMessageId:a.id};s.push(r)}}else if(a.role==="tool"){let t="unknown";for(let r of i)if(r.role==="assistant"&&((e=r.toolCalls)!=null&&e.length)){for(let o of r.toolCalls)if(o.id===a.toolCallId){t=o.function.name;break}}let n={id:a.id,result:a.content,actionExecutionId:a.toolCallId,actionName:t};s.push(n)}return s}var j=require("uuid");var B=require("rxjs/operators"),ct=require("rxjs/operators"),F=require("rxjs");var Et=require("rxjs");var rt=require("rxjs"),M=require("@ag-ui/core"),V=i=>s=>{let e,a,t,n=()=>{if(!e||t!=="text")throw new Error("No text message to close");let l={type:M.EventType.TEXT_MESSAGE_END,messageId:e.messageId};return t=void 0,e=void 0,i&&console.debug("[TRANSFORM]: TEXT_MESSAGE_END",JSON.stringify(l)),l},r=()=>{if(!a||t!=="tool")throw new Error("No tool call to close");let l={type:M.EventType.TOOL_CALL_END,toolCallId:a.toolCallId};return t=void 0,a=void 0,i&&console.debug("[TRANSFORM]: TOOL_CALL_END",JSON.stringify(l)),l},o=()=>t==="text"?[n()]:t==="tool"?[r()]:[];return s.pipe((0,rt.mergeMap)(l=>{switch(l.type){case M.EventType.TEXT_MESSAGE_START:case M.EventType.TEXT_MESSAGE_CONTENT:case M.EventType.TEXT_MESSAGE_END:case M.EventType.TOOL_CALL_START:case M.EventType.TOOL_CALL_ARGS:case M.EventType.TOOL_CALL_END:case M.EventType.TOOL_CALL_RESULT:case M.EventType.STATE_SNAPSHOT:case M.EventType.STATE_DELTA:case M.EventType.MESSAGES_SNAPSHOT:case M.EventType.CUSTOM:case M.EventType.RUN_STARTED:case M.EventType.RUN_FINISHED:case M.EventType.RUN_ERROR:case M.EventType.STEP_STARTED:case M.EventType.STEP_FINISHED:case M.EventType.THINKING_START:case M.EventType.THINKING_END:case M.EventType.THINKING_TEXT_MESSAGE_START:case M.EventType.THINKING_TEXT_MESSAGE_CONTENT:case M.EventType.THINKING_TEXT_MESSAGE_END:return[...o(),l];case M.EventType.RAW:case M.EventType.ACTIVITY_SNAPSHOT:case M.EventType.ACTIVITY_DELTA:return[l];case M.EventType.TEXT_MESSAGE_CHUNK:let A=l,H=[];if((t!=="text"||A.messageId!==void 0&&A.messageId!==(e==null?void 0:e.messageId))&&H.push(...o()),t!=="text"){if(A.messageId===void 0)throw new Error("First TEXT_MESSAGE_CHUNK must have a messageId");e={messageId:A.messageId},t="text";let c={type:M.EventType.TEXT_MESSAGE_START,messageId:A.messageId,role:A.role||"assistant"};H.push(c),i&&console.debug("[TRANSFORM]: TEXT_MESSAGE_START",JSON.stringify(c))}if(A.delta!==void 0){let c={type:M.EventType.TEXT_MESSAGE_CONTENT,messageId:e.messageId,delta:A.delta};H.push(c),i&&console.debug("[TRANSFORM]: TEXT_MESSAGE_CONTENT",JSON.stringify(c))}return H;case M.EventType.TOOL_CALL_CHUNK:let T=l,y=[];if((t!=="tool"||T.toolCallId!==void 0&&T.toolCallId!==(a==null?void 0:a.toolCallId))&&y.push(...o()),t!=="tool"){if(T.toolCallId===void 0)throw new Error("First TOOL_CALL_CHUNK must have a toolCallId");if(T.toolCallName===void 0)throw new Error("First TOOL_CALL_CHUNK must have a toolCallName");a={toolCallId:T.toolCallId,toolCallName:T.toolCallName,parentMessageId:T.parentMessageId},t="tool";let c={type:M.EventType.TOOL_CALL_START,toolCallId:T.toolCallId,toolCallName:T.toolCallName,parentMessageId:T.parentMessageId};y.push(c),i&&console.debug("[TRANSFORM]: TOOL_CALL_START",JSON.stringify(c))}if(T.delta!==void 0){let c={type:M.EventType.TOOL_CALL_ARGS,toolCallId:a.toolCallId,delta:T.delta};y.push(c),i&&console.debug("[TRANSFORM]: TOOL_CALL_ARGS",JSON.stringify(c))}return y}let d=l.type;return[]}),(0,rt.finalize)(()=>{o()}))};var ut=require("@ag-ui/core"),z=class{constructor({agentId:s,description:e,threadId:a,initialMessages:t,initialState:n,debug:r}={}){this.debug=!1;this.subscribers=[];this.isRunning=!1;this.agentId=s,this.description=e!=null?e:"",this.threadId=a!=null?a:(0,j.v4)(),this.messages=R(t!=null?t:[]),this.state=R(n!=null?n:{}),this.debug=r!=null?r:!1}subscribe(s){return this.subscribers.push(s),{unsubscribe:()=>{this.subscribers=this.subscribers.filter(e=>e!==s)}}}async runAgent(s,e){var a;try{this.isRunning=!0,this.agentId=(a=this.agentId)!=null?a:(0,j.v4)();let t=this.prepareRunAgentInput(s),n,r=new Set(this.messages.map(A=>A.id)),o=[{onRunFinishedEvent:A=>{n=A.result}},...this.subscribers,e!=null?e:{}];await this.onInitialize(t,o);let l=(0,F.pipe)(()=>this.run(t),V(this.debug),K(this.debug),A=>this.apply(t,A,o),A=>this.processApplyEvents(t,A,o),(0,B.catchError)(A=>(this.isRunning=!1,this.onError(t,A,o))),(0,ct.finalize)(()=>{this.isRunning=!1,this.onFinalize(t,o)}));await(0,Et.lastValueFrom)(l((0,F.of)(null)));let d=R(this.messages).filter(A=>!r.has(A.id));return{result:n,newMessages:d}}finally{this.isRunning=!1}}connect(s){throw new ut.AGUIConnectNotImplementedError}async connectAgent(s,e){var a;try{this.isRunning=!0,this.agentId=(a=this.agentId)!=null?a:(0,j.v4)();let t=this.prepareRunAgentInput(s),n,r=new Set(this.messages.map(A=>A.id)),o=[{onRunFinishedEvent:A=>{n=A.result}},...this.subscribers,e!=null?e:{}];await this.onInitialize(t,o);let l=(0,F.pipe)(()=>this.connect(t),V(this.debug),K(this.debug),A=>this.apply(t,A,o),A=>this.processApplyEvents(t,A,o),(0,B.catchError)(A=>(this.isRunning=!1,A instanceof ut.AGUIConnectNotImplementedError?F.EMPTY:this.onError(t,A,o))),(0,ct.finalize)(()=>{this.isRunning=!1,this.onFinalize(t,o)}));await(0,Et.lastValueFrom)(l((0,F.of)(null)));let d=R(this.messages).filter(A=>!r.has(A.id));return{result:n,newMessages:d}}finally{this.isRunning=!1}}abortRun(){}apply(s,e,a){return Q(s,e,this,a)}processApplyEvents(s,e,a){return e.pipe((0,B.tap)(t=>{t.messages&&(this.messages=t.messages,a.forEach(n=>{var r;(r=n.onMessagesChanged)==null||r.call(n,{messages:this.messages,state:this.state,agent:this,input:s})})),t.state&&(this.state=t.state,a.forEach(n=>{var r;(r=n.onStateChanged)==null||r.call(n,{state:this.state,messages:this.messages,agent:this,input:s})}))}))}prepareRunAgentInput(s){var t,n,r;let a=R(this.messages).filter(o=>o.role!=="activity");return{threadId:this.threadId,runId:(s==null?void 0:s.runId)||(0,j.v4)(),tools:R((t=s==null?void 0:s.tools)!=null?t:[]),context:R((n=s==null?void 0:s.context)!=null?n:[]),forwardedProps:R((r=s==null?void 0:s.forwardedProps)!=null?r:{}),state:R(this.state),messages:a}}async onInitialize(s,e){let a=await x(e,this.messages,this.state,(t,n,r)=>{var o;return(o=t.onRunInitialized)==null?void 0:o.call(t,{messages:n,state:r,agent:this,input:s})});(a.messages!==void 0||a.state!==void 0)&&(a.messages&&(this.messages=a.messages,s.messages=a.messages,e.forEach(t=>{var n;(n=t.onMessagesChanged)==null||n.call(t,{messages:this.messages,state:this.state,agent:this,input:s})})),a.state&&(this.state=a.state,s.state=a.state,e.forEach(t=>{var n;(n=t.onStateChanged)==null||n.call(t,{state:this.state,messages:this.messages,agent:this,input:s})})))}onError(s,e,a){return(0,F.from)(x(a,this.messages,this.state,(t,n,r)=>{var o;return(o=t.onRunFailed)==null?void 0:o.call(t,{error:e,messages:n,state:r,agent:this,input:s})})).pipe((0,B.map)(t=>{let n=t;if((n.messages!==void 0||n.state!==void 0)&&(n.messages!==void 0&&(this.messages=n.messages,a.forEach(r=>{var o;(o=r.onMessagesChanged)==null||o.call(r,{messages:this.messages,state:this.state,agent:this,input:s})})),n.state!==void 0&&(this.state=n.state,a.forEach(r=>{var o;(o=r.onStateChanged)==null||o.call(r,{state:this.state,messages:this.messages,agent:this,input:s})}))),n.stopPropagation!==!0)throw console.error("Agent execution failed:",e),e;return{}}))}async onFinalize(s,e){let a=await x(e,this.messages,this.state,(t,n,r)=>{var o;return(o=t.onRunFinalized)==null?void 0:o.call(t,{messages:n,state:r,agent:this,input:s})});(a.messages!==void 0||a.state!==void 0)&&(a.messages!==void 0&&(this.messages=a.messages,e.forEach(t=>{var n;(n=t.onMessagesChanged)==null||n.call(t,{messages:this.messages,state:this.state,agent:this,input:s})})),a.state!==void 0&&(this.state=a.state,e.forEach(t=>{var n;(n=t.onStateChanged)==null||n.call(t,{state:this.state,messages:this.messages,agent:this,input:s})})))}clone(){let s=Object.create(Object.getPrototypeOf(this));return s.agentId=this.agentId,s.description=this.description,s.threadId=this.threadId,s.messages=R(this.messages),s.state=R(this.state),s.debug=this.debug,s.isRunning=this.isRunning,s.subscribers=[...this.subscribers],s}addMessage(s){this.messages.push(s),(async()=>{var e,a,t;for(let n of this.subscribers)await((e=n.onNewMessage)==null?void 0:e.call(n,{message:s,messages:this.messages,state:this.state,agent:this}));if(s.role==="assistant"&&s.toolCalls)for(let n of s.toolCalls)for(let r of this.subscribers)await((a=r.onNewToolCall)==null?void 0:a.call(r,{toolCall:n,messages:this.messages,state:this.state,agent:this}));for(let n of this.subscribers)await((t=n.onMessagesChanged)==null?void 0:t.call(n,{messages:this.messages,state:this.state,agent:this}))})()}addMessages(s){this.messages.push(...s),(async()=>{var e,a,t;for(let n of s){for(let r of this.subscribers)await((e=r.onNewMessage)==null?void 0:e.call(r,{message:n,messages:this.messages,state:this.state,agent:this}));if(n.role==="assistant"&&n.toolCalls)for(let r of n.toolCalls)for(let o of this.subscribers)await((a=o.onNewToolCall)==null?void 0:a.call(o,{toolCall:r,messages:this.messages,state:this.state,agent:this}))}for(let n of this.subscribers)await((t=n.onMessagesChanged)==null?void 0:t.call(n,{messages:this.messages,state:this.state,agent:this}))})()}setMessages(s){this.messages=R(s),(async()=>{var e;for(let a of this.subscribers)await((e=a.onMessagesChanged)==null?void 0:e.call(a,{messages:this.messages,state:this.state,agent:this}))})()}setState(s){this.state=R(s),(async()=>{var e;for(let a of this.subscribers)await((e=a.onStateChanged)==null?void 0:e.call(a,{messages:this.messages,state:this.state,agent:this}))})()}legacy_to_be_removed_runAgentBridged(s){var a;this.agentId=(a=this.agentId)!=null?a:(0,j.v4)();let e=this.prepareRunAgentInput(s);return this.run(e).pipe(V(this.debug),K(this.debug),ot(this.threadId,e.runId,this.agentId),t=>t.pipe((0,B.map)(n=>(this.debug&&console.debug("[LEGACY]:",JSON.stringify(n)),n))))}};var it=class extends z{constructor(e){var a;super(e);this.abortController=new AbortController;this.url=e.url,this.headers=R((a=e.headers)!=null?a:{})}requestInit(e){return{method:"POST",headers:X(L({},this.headers),{"Content-Type":"application/json",Accept:"text/event-stream"}),body:JSON.stringify(e),signal:this.abortController.signal}}runAgent(e,a){var t;return this.abortController=(t=e==null?void 0:e.abortController)!=null?t:new AbortController,super.runAgent(e,a)}abortRun(){this.abortController.abort(),super.abortRun()}run(e){let a=tt(this.url,this.requestInit(e));return at(a)}clone(){var n;let e=super.clone();e.url=this.url,e.headers=R((n=this.headers)!=null?n:{});let a=new AbortController,t=this.abortController.signal;return t.aborted&&a.abort(t.reason),e.abortController=a,e}};var U=require("@ag-ui/core");function Lt(i){let s=[],e=new Map,a=new Map;for(let t of i)if(t.type===U.EventType.TEXT_MESSAGE_START){let n=t,r=n.messageId;e.has(r)||e.set(r,{contents:[],otherEvents:[]});let o=e.get(r);o.start=n}else if(t.type===U.EventType.TEXT_MESSAGE_CONTENT){let n=t,r=n.messageId;e.has(r)||e.set(r,{contents:[],otherEvents:[]}),e.get(r).contents.push(n)}else if(t.type===U.EventType.TEXT_MESSAGE_END){let n=t,r=n.messageId;e.has(r)||e.set(r,{contents:[],otherEvents:[]});let o=e.get(r);o.end=n,xt(r,o,s),e.delete(r)}else if(t.type===U.EventType.TOOL_CALL_START){let n=t,r=n.toolCallId;a.has(r)||a.set(r,{args:[],otherEvents:[]});let o=a.get(r);o.start=n}else if(t.type===U.EventType.TOOL_CALL_ARGS){let n=t,r=n.toolCallId;a.has(r)||a.set(r,{args:[],otherEvents:[]}),a.get(r).args.push(n)}else if(t.type===U.EventType.TOOL_CALL_END){let n=t,r=n.toolCallId;a.has(r)||a.set(r,{args:[],otherEvents:[]});let o=a.get(r);o.end=n,Nt(r,o,s),a.delete(r)}else{let n=!1;for(let[r,o]of e)if(o.start&&!o.end){o.otherEvents.push(t),n=!0;break}if(!n){for(let[r,o]of a)if(o.start&&!o.end){o.otherEvents.push(t),n=!0;break}}n||s.push(t)}for(let[t,n]of e)xt(t,n,s);for(let[t,n]of a)Nt(t,n,s);return s}function xt(i,s,e){if(s.start&&e.push(s.start),s.contents.length>0){let a=s.contents.map(n=>n.delta).join(""),t={type:U.EventType.TEXT_MESSAGE_CONTENT,messageId:i,delta:a};e.push(t)}s.end&&e.push(s.end);for(let a of s.otherEvents)e.push(a)}function Nt(i,s,e){if(s.start&&e.push(s.start),s.args.length>0){let a=s.args.map(n=>n.delta).join(""),t={type:U.EventType.TOOL_CALL_ARGS,toolCallId:i,delta:a};e.push(t)}s.end&&e.push(s.end);for(let a of s.otherEvents)e.push(a)}D(P,require("@ag-ui/core"),module.exports);0&&(module.exports={AbstractAgent,HttpAgent,compactEvents,convertToLegacyEvents,defaultApplyEvents,parseProtoStream,parseSSEStream,randomUUID,runHttpRequest,structuredClone_,transformChunks,transformHttpEventStream,verifyEvents,...require("@ag-ui/core")});
3
+ Patch operations: ${JSON.stringify(i,null,2)}
4
+ Error: ${m}`)}}return g()}case _.EventType.MESSAGES_SNAPSHOT:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onMessagesSnapshotEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});if(o(p),p.stopPropagation!==!0){let{messages:i}=u;t=i,o({messages:t})}return g()}case _.EventType.ACTIVITY_SNAPSHOT:{let p=u,i=t.findIndex(M=>M.id===p.messageId),d=i>=0?t[i]:void 0,m=(d==null?void 0:d.role)==="activity"?d:void 0,E=(y=p.replace)!=null?y:!0,v=await x(a,t,n,(M,N,w)=>{var F;return(F=M.onActivitySnapshotEvent)==null?void 0:F.call(M,{event:p,messages:N,state:w,agent:e,input:l,activityMessage:m,existingMessage:d})});if(o(v),v.stopPropagation!==!0){let M={id:p.messageId,role:"activity",activityType:p.activityType,content:R(p.content)},N;i===-1?(t.push(M),N=M):m?E&&(t[i]=k(L({},m),{activityType:p.activityType,content:R(p.content)})):E&&(t[i]=M,N=M),o({messages:t}),N&&await Promise.all(a.map(w=>{var F;return(F=w.onNewMessage)==null?void 0:F.call(w,{message:N,messages:t,state:n,agent:e,input:l})}))}return g()}case _.EventType.ACTIVITY_DELTA:{let p=u,i=t.findIndex(v=>v.id===p.messageId);if(i===-1)return console.warn(`ACTIVITY_DELTA: No message found with ID '${p.messageId}' to apply patch`),g();let d=t[i];if(d.role!=="activity")return console.warn(`ACTIVITY_DELTA: Message '${p.messageId}' is not an activity message`),g();let m=d,E=await x(a,t,n,(v,M,N)=>{var w;return(w=v.onActivityDeltaEvent)==null?void 0:w.call(v,{event:p,messages:M,state:N,agent:e,input:l,activityMessage:m})});if(o(E),E.stopPropagation!==!0)try{let v=R(m);v.activityType=p.activityType,(c=v.content)!=null||(v.content={});let N=(0,ct.applyPatch)(v,p.patch,!0,!1).newDocument;t[i]=k(L({},N),{id:m.id,role:"activity",activityType:p.activityType}),o({messages:t})}catch(v){let M=v instanceof Error?v.message:String(v);console.warn(`Failed to apply activity patch for '${p.messageId}': ${M}`)}return g()}case _.EventType.RAW:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onRawEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});return o(p),g()}case _.EventType.CUSTOM:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onCustomEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});return o(p),g()}case _.EventType.RUN_STARTED:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onRunStartedEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});if(o(p),p.stopPropagation!==!0){let i=u;if((G=i.input)!=null&&G.messages){for(let d of i.input.messages)t.find(E=>E.id===d.id)||t.push(d);o({messages:t})}}return g()}case _.EventType.RUN_FINISHED:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onRunFinishedEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l,result:u.result})});return o(p),g()}case _.EventType.RUN_ERROR:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onRunErrorEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});return o(p),g()}case _.EventType.STEP_STARTED:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onStepStartedEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});return o(p),g()}case _.EventType.STEP_FINISHED:{let p=await x(a,t,n,(i,d,m)=>{var E;return(E=i.onStepFinishedEvent)==null?void 0:E.call(i,{event:u,messages:d,state:m,agent:e,input:l})});return o(p),g()}case _.EventType.TEXT_MESSAGE_CHUNK:throw new Error("TEXT_MESSAGE_CHUNK must be tranformed before being applied");case _.EventType.TOOL_CALL_CHUNK:throw new Error("TOOL_CALL_CHUNK must be tranformed before being applied");case _.EventType.THINKING_START:return g();case _.EventType.THINKING_END:return g();case _.EventType.THINKING_TEXT_MESSAGE_START:return g();case _.EventType.THINKING_TEXT_MESSAGE_CONTENT:return g();case _.EventType.THINKING_TEXT_MESSAGE_END:return g()}let H=u.type;return g()}),(0,j.mergeAll)(),a.length>0?(0,j.defaultIfEmpty)({}):u=>u)};var A=require("@ag-ui/core"),h=require("rxjs"),At=require("rxjs/operators"),z=l=>s=>{let e=new Map,a=new Map,t=!1,n=!1,r=!1,o=new Map,g=!1,u=!1,S=!1,H=()=>{e.clear(),a.clear(),o.clear(),g=!1,u=!1,t=!1,n=!1,S=!0};return s.pipe((0,At.mergeMap)(T=>{let y=T.type;if(l&&console.debug("[VERIFY]:",JSON.stringify(T)),n)return(0,h.throwError)(()=>new A.AGUIError(`Cannot send event type '${y}': The run has already errored with 'RUN_ERROR'. No further events can be sent.`));if(t&&y!==A.EventType.RUN_ERROR&&y!==A.EventType.RUN_STARTED)return(0,h.throwError)(()=>new A.AGUIError(`Cannot send event type '${y}': The run has already finished with 'RUN_FINISHED'. Start a new run with 'RUN_STARTED'.`));if(r){if(y===A.EventType.RUN_STARTED){if(S&&!t)return(0,h.throwError)(()=>new A.AGUIError("Cannot send 'RUN_STARTED' while a run is still active. The previous run must be finished with 'RUN_FINISHED' before starting a new run."));t&&H()}}else if(r=!0,y!==A.EventType.RUN_STARTED&&y!==A.EventType.RUN_ERROR)return(0,h.throwError)(()=>new A.AGUIError("First event must be 'RUN_STARTED'"));switch(y){case A.EventType.TEXT_MESSAGE_START:{let c=T.messageId;return e.has(c)?(0,h.throwError)(()=>new A.AGUIError(`Cannot send 'TEXT_MESSAGE_START' event: A text message with ID '${c}' is already in progress. Complete it with 'TEXT_MESSAGE_END' first.`)):(e.set(c,!0),(0,h.of)(T))}case A.EventType.TEXT_MESSAGE_CONTENT:{let c=T.messageId;return e.has(c)?(0,h.of)(T):(0,h.throwError)(()=>new A.AGUIError(`Cannot send 'TEXT_MESSAGE_CONTENT' event: No active text message found with ID '${c}'. Start a text message with 'TEXT_MESSAGE_START' first.`))}case A.EventType.TEXT_MESSAGE_END:{let c=T.messageId;return e.has(c)?(e.delete(c),(0,h.of)(T)):(0,h.throwError)(()=>new A.AGUIError(`Cannot send 'TEXT_MESSAGE_END' event: No active text message found with ID '${c}'. A 'TEXT_MESSAGE_START' event must be sent first.`))}case A.EventType.TOOL_CALL_START:{let c=T.toolCallId;return a.has(c)?(0,h.throwError)(()=>new A.AGUIError(`Cannot send 'TOOL_CALL_START' event: A tool call with ID '${c}' is already in progress. Complete it with 'TOOL_CALL_END' first.`)):(a.set(c,!0),(0,h.of)(T))}case A.EventType.TOOL_CALL_ARGS:{let c=T.toolCallId;return a.has(c)?(0,h.of)(T):(0,h.throwError)(()=>new A.AGUIError(`Cannot send 'TOOL_CALL_ARGS' event: No active tool call found with ID '${c}'. Start a tool call with 'TOOL_CALL_START' first.`))}case A.EventType.TOOL_CALL_END:{let c=T.toolCallId;return a.has(c)?(a.delete(c),(0,h.of)(T)):(0,h.throwError)(()=>new A.AGUIError(`Cannot send 'TOOL_CALL_END' event: No active tool call found with ID '${c}'. A 'TOOL_CALL_START' event must be sent first.`))}case A.EventType.STEP_STARTED:{let c=T.stepName;return o.has(c)?(0,h.throwError)(()=>new A.AGUIError(`Step "${c}" is already active for 'STEP_STARTED'`)):(o.set(c,!0),(0,h.of)(T))}case A.EventType.STEP_FINISHED:{let c=T.stepName;return o.has(c)?(o.delete(c),(0,h.of)(T)):(0,h.throwError)(()=>new A.AGUIError(`Cannot send 'STEP_FINISHED' for step "${c}" that was not started`))}case A.EventType.RUN_STARTED:return S=!0,(0,h.of)(T);case A.EventType.RUN_FINISHED:{if(o.size>0){let c=Array.from(o.keys()).join(", ");return(0,h.throwError)(()=>new A.AGUIError(`Cannot send 'RUN_FINISHED' while steps are still active: ${c}`))}if(e.size>0){let c=Array.from(e.keys()).join(", ");return(0,h.throwError)(()=>new A.AGUIError(`Cannot send 'RUN_FINISHED' while text messages are still active: ${c}`))}if(a.size>0){let c=Array.from(a.keys()).join(", ");return(0,h.throwError)(()=>new A.AGUIError(`Cannot send 'RUN_FINISHED' while tool calls are still active: ${c}`))}return t=!0,(0,h.of)(T)}case A.EventType.RUN_ERROR:return n=!0,(0,h.of)(T);case A.EventType.CUSTOM:return(0,h.of)(T);case A.EventType.THINKING_TEXT_MESSAGE_START:return g?u?(0,h.throwError)(()=>new A.AGUIError("Cannot send 'THINKING_TEXT_MESSAGE_START' event: A thinking message is already in progress. Complete it with 'THINKING_TEXT_MESSAGE_END' first.")):(u=!0,(0,h.of)(T)):(0,h.throwError)(()=>new A.AGUIError("Cannot send 'THINKING_TEXT_MESSAGE_START' event: A thinking step is not in progress. Create one with 'THINKING_START' first."));case A.EventType.THINKING_TEXT_MESSAGE_CONTENT:return u?(0,h.of)(T):(0,h.throwError)(()=>new A.AGUIError("Cannot send 'THINKING_TEXT_MESSAGE_CONTENT' event: No active thinking message found. Start a message with 'THINKING_TEXT_MESSAGE_START' first."));case A.EventType.THINKING_TEXT_MESSAGE_END:return u?(u=!1,(0,h.of)(T)):(0,h.throwError)(()=>new A.AGUIError("Cannot send 'THINKING_TEXT_MESSAGE_END' event: No active thinking message found. A 'THINKING_TEXT_MESSAGE_START' event must be sent first."));case A.EventType.THINKING_START:return g?(0,h.throwError)(()=>new A.AGUIError("Cannot send 'THINKING_START' event: A thinking step is already in progress. End it with 'THINKING_END' first.")):(g=!0,(0,h.of)(T));case A.EventType.THINKING_END:return g?(g=!1,(0,h.of)(T)):(0,h.throwError)(()=>new A.AGUIError("Cannot send 'THINKING_END' event: No active thinking step found. A 'THINKING_START' event must be sent first."));default:return(0,h.of)(T)}}))};var Mt=require("@ag-ui/core"),at=require("rxjs");var U=require("rxjs"),tt=require("rxjs/operators");var et=(l,s)=>(0,U.defer)(()=>(0,U.from)(fetch(l,s))).pipe((0,tt.switchMap)(e=>{var n;if(!e.ok){let r=e.headers.get("content-type")||"";return(0,U.from)(e.text()).pipe((0,tt.mergeMap)(o=>{let g=o;if(r.includes("application/json"))try{g=JSON.parse(o)}catch(S){}let u=new Error(`HTTP ${e.status}: ${typeof g=="string"?g:JSON.stringify(g)}`);return u.status=e.status,u.payload=g,(0,U.throwError)(()=>u)}))}let a={type:"headers",status:e.status,headers:e.headers},t=(n=e.body)==null?void 0:n.getReader();return t?new U.Observable(r=>(r.next(a),(async()=>{try{for(;;){let{done:o,value:g}=await t.read();if(o)break;let u={type:"data",data:g};r.next(u)}r.complete()}catch(o){r.error(o)}})(),()=>{t.cancel().catch(o=>{if((o==null?void 0:o.name)!=="AbortError")throw o})})):(0,U.throwError)(()=>new Error("Failed to getReader() from response"))}));var vt=require("rxjs");var nt=l=>{let s=new vt.Subject,e=new TextDecoder("utf-8",{fatal:!1}),a="";l.subscribe({next:n=>{if(n.type!=="headers"&&n.type==="data"&&n.data){let r=e.decode(n.data,{stream:!0});a+=r;let o=a.split(/\n\n/);a=o.pop()||"";for(let g of o)t(g)}},error:n=>s.error(n),complete:()=>{a&&(a+=e.decode(),t(a)),s.complete()}});function t(n){let r=n.split(`
5
+ `),o=[];for(let g of r)g.startsWith("data: ")&&o.push(g.slice(6));if(o.length>0)try{let g=o.join(`
6
+ `),u=JSON.parse(g);s.next(u)}catch(g){s.error(g)}}return s.asObservable()};var ht=require("rxjs");var yt=q(require("@ag-ui/proto")),st=l=>{let s=new ht.Subject,e=new Uint8Array(0);l.subscribe({next:t=>{if(t.type!=="headers"&&t.type==="data"&&t.data){let n=new Uint8Array(e.length+t.data.length);n.set(e,0),n.set(t.data,e.length),e=n,a()}},error:t=>s.error(t),complete:()=>{if(e.length>0)try{a()}catch(t){console.warn("Incomplete or invalid protocol buffer data at stream end")}s.complete()}});function a(){for(;e.length>=4;){let r=4+new DataView(e.buffer,e.byteOffset,4).getUint32(0,!1);if(e.length<r)break;try{let o=e.slice(4,r),g=yt.decode(o);s.next(g),e=e.slice(r)}catch(o){let g=o instanceof Error?o.message:String(o);s.error(new Error(`Failed to decode protocol buffer message: ${g}`));return}}}return s.asObservable()};var Ct=q(require("@ag-ui/proto")),Rt=require("@ag-ui/core"),ot=l=>{let s=new at.Subject,e=new at.ReplaySubject,a=!1;return l.subscribe({next:t=>{e.next(t),t.type==="headers"&&!a?(a=!0,t.headers.get("content-type")===Ct.AGUI_MEDIA_TYPE?st(e).subscribe({next:r=>s.next(r),error:r=>s.error(r),complete:()=>s.complete()}):nt(e).subscribe({next:r=>{try{let o=Mt.EventSchemas.parse(r);s.next(o)}catch(o){s.error(o)}},error:r=>{if((r==null?void 0:r.name)==="AbortError"){s.next({type:Rt.EventType.RUN_ERROR,rawEvent:r}),s.complete();return}return s.error(r)},complete:()=>s.complete()})):a||s.error(new Error("No headers event received before data events"))},error:t=>{e.error(t),s.error(t)},complete:()=>{e.complete()}}),s.asObservable()};var _t=require("rxjs/operators"),It=require("fast-json-patch"),O=require("@ag-ui/core");var f=require("zod"),I=f.z.enum(["TextMessageStart","TextMessageContent","TextMessageEnd","ActionExecutionStart","ActionExecutionArgs","ActionExecutionEnd","ActionExecutionResult","AgentStateMessage","MetaEvent","RunStarted","RunFinished","RunError","NodeStarted","NodeFinished"]),Kt=f.z.enum(["LangGraphInterruptEvent","PredictState","Exit"]),jt=f.z.object({type:f.z.literal(I.enum.TextMessageStart),messageId:f.z.string(),parentMessageId:f.z.string().optional(),role:f.z.string().optional()}),zt=f.z.object({type:f.z.literal(I.enum.TextMessageContent),messageId:f.z.string(),content:f.z.string()}),Jt=f.z.object({type:f.z.literal(I.enum.TextMessageEnd),messageId:f.z.string()}),$t=f.z.object({type:f.z.literal(I.enum.ActionExecutionStart),actionExecutionId:f.z.string(),actionName:f.z.string(),parentMessageId:f.z.string().optional()}),Vt=f.z.object({type:f.z.literal(I.enum.ActionExecutionArgs),actionExecutionId:f.z.string(),args:f.z.string()}),bt=f.z.object({type:f.z.literal(I.enum.ActionExecutionEnd),actionExecutionId:f.z.string()}),Yt=f.z.object({type:f.z.literal(I.enum.ActionExecutionResult),actionName:f.z.string(),actionExecutionId:f.z.string(),result:f.z.string()}),Wt=f.z.object({type:f.z.literal(I.enum.AgentStateMessage),threadId:f.z.string(),agentName:f.z.string(),nodeName:f.z.string(),runId:f.z.string(),active:f.z.boolean(),role:f.z.string(),state:f.z.string(),running:f.z.boolean()}),qt=f.z.object({type:f.z.literal(I.enum.MetaEvent),name:Kt,value:f.z.any()}),Qt=f.z.object({type:f.z.literal(I.enum.RunError),message:f.z.string(),code:f.z.string().optional()}),pn=f.z.discriminatedUnion("type",[jt,zt,Jt,$t,Vt,bt,Yt,Wt,qt,Qt]),dn=f.z.object({id:f.z.string(),role:f.z.string(),content:f.z.string(),parentMessageId:f.z.string().optional()}),mn=f.z.object({id:f.z.string(),name:f.z.string(),arguments:f.z.any(),parentMessageId:f.z.string().optional()}),fn=f.z.object({id:f.z.string(),result:f.z.any(),actionExecutionId:f.z.string(),actionName:f.z.string()});var xt=q(require("untruncate-json"));var Zt=l=>{if(typeof l=="string")return l;if(!Array.isArray(l))return;let s=l.filter(e=>e.type==="text").map(e=>e.text).filter(e=>e.length>0);if(s.length!==0)return s.join(`
7
+ `)},rt=(l,s,e)=>a=>{let t={},n=!0,r=!0,o="",g=null,u=null,S=[],H={},T=y=>{typeof y=="object"&&y!==null&&("messages"in y&&delete y.messages,t=y)};return a.pipe((0,_t.mergeMap)(y=>{switch(y.type){case O.EventType.TEXT_MESSAGE_START:{let c=y;return[{type:I.enum.TextMessageStart,messageId:c.messageId,role:c.role}]}case O.EventType.TEXT_MESSAGE_CONTENT:{let c=y;return[{type:I.enum.TextMessageContent,messageId:c.messageId,content:c.delta}]}case O.EventType.TEXT_MESSAGE_END:{let c=y;return[{type:I.enum.TextMessageEnd,messageId:c.messageId}]}case O.EventType.TOOL_CALL_START:{let c=y;return S.push({id:c.toolCallId,type:"function",function:{name:c.toolCallName,arguments:""}}),r=!0,H[c.toolCallId]=c.toolCallName,[{type:I.enum.ActionExecutionStart,actionExecutionId:c.toolCallId,actionName:c.toolCallName,parentMessageId:c.parentMessageId}]}case O.EventType.TOOL_CALL_ARGS:{let c=y,G=S.find(i=>i.id===c.toolCallId);if(!G)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${c.toolCallId}'`),[];G.function.arguments+=c.delta;let p=!1;if(u){let i=u.find(d=>d.tool==G.function.name);if(i)try{let d=JSON.parse((0,xt.default)(G.function.arguments));i.tool_argument&&i.tool_argument in d?(T(k(L({},t),{[i.state_key]:d[i.tool_argument]})),p=!0):i.tool_argument||(T(k(L({},t),{[i.state_key]:d})),p=!0)}catch(d){}}return[{type:I.enum.ActionExecutionArgs,actionExecutionId:c.toolCallId,args:c.delta},...p?[{type:I.enum.AgentStateMessage,threadId:l,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(t),active:r}]:[]]}case O.EventType.TOOL_CALL_END:{let c=y;return[{type:I.enum.ActionExecutionEnd,actionExecutionId:c.toolCallId}]}case O.EventType.TOOL_CALL_RESULT:{let c=y;return[{type:I.enum.ActionExecutionResult,actionExecutionId:c.toolCallId,result:c.content,actionName:H[c.toolCallId]||"unknown"}]}case O.EventType.RAW:return[];case O.EventType.CUSTOM:{let c=y;switch(c.name){case"Exit":n=!1;break;case"PredictState":u=c.value;break}return[{type:I.enum.MetaEvent,name:c.name,value:c.value}]}case O.EventType.STATE_SNAPSHOT:return T(y.snapshot),[{type:I.enum.AgentStateMessage,threadId:l,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(t),active:r}];case O.EventType.STATE_DELTA:{let G=(0,It.applyPatch)(t,y.delta,!0,!1);return G?(T(G.newDocument),[{type:I.enum.AgentStateMessage,threadId:l,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(t),active:r}]):[]}case O.EventType.MESSAGES_SNAPSHOT:return g=y.messages,[{type:I.enum.AgentStateMessage,threadId:l,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(L(L({},t),g?{messages:g}:{})),active:!0}];case O.EventType.RUN_STARTED:return[];case O.EventType.RUN_FINISHED:return g&&(t.messages=g),Object.keys(t).length===0?[]:[{type:I.enum.AgentStateMessage,threadId:l,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(L(L({},t),g?{messages:te(g)}:{})),active:!1}];case O.EventType.RUN_ERROR:{let c=y;return[{type:I.enum.RunError,message:c.message,code:c.code}]}case O.EventType.STEP_STARTED:return o=y.stepName,S=[],u=null,[{type:I.enum.AgentStateMessage,threadId:l,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(t),active:!0}];case O.EventType.STEP_FINISHED:return S=[],u=null,[{type:I.enum.AgentStateMessage,threadId:l,agentName:e,nodeName:o,runId:s,running:n,role:"assistant",state:JSON.stringify(t),active:!1}];default:return[]}}))};function te(l){var e;let s=[];for(let a of l)if(a.role==="assistant"||a.role==="user"||a.role==="system"){let t=Zt(a.content);if(t){let n={id:a.id,role:a.role,content:t};s.push(n)}if(a.role==="assistant"&&a.toolCalls&&a.toolCalls.length>0)for(let n of a.toolCalls){let r={id:n.id,name:n.function.name,arguments:JSON.parse(n.function.arguments),parentMessageId:a.id};s.push(r)}}else if(a.role==="tool"){let t="unknown";for(let r of l)if(r.role==="assistant"&&((e=r.toolCalls)!=null&&e.length)){for(let o of r.toolCalls)if(o.id===a.toolCallId){t=o.function.name;break}}let n={id:a.id,result:a.content,actionExecutionId:a.toolCallId,actionName:t};s.push(n)}return s}var J=require("uuid");var K=require("rxjs/operators"),Et=require("rxjs/operators"),X=require("rxjs");var ut=require("rxjs");var it=require("rxjs"),C=require("@ag-ui/core"),Y=l=>s=>{let e,a,t,n=()=>{if(!e||t!=="text")throw new Error("No text message to close");let g={type:C.EventType.TEXT_MESSAGE_END,messageId:e.messageId};return t=void 0,e=void 0,l&&console.debug("[TRANSFORM]: TEXT_MESSAGE_END",JSON.stringify(g)),g},r=()=>{if(!a||t!=="tool")throw new Error("No tool call to close");let g={type:C.EventType.TOOL_CALL_END,toolCallId:a.toolCallId};return t=void 0,a=void 0,l&&console.debug("[TRANSFORM]: TOOL_CALL_END",JSON.stringify(g)),g},o=()=>t==="text"?[n()]:t==="tool"?[r()]:[];return s.pipe((0,it.mergeMap)(g=>{switch(g.type){case C.EventType.TEXT_MESSAGE_START:case C.EventType.TEXT_MESSAGE_CONTENT:case C.EventType.TEXT_MESSAGE_END:case C.EventType.TOOL_CALL_START:case C.EventType.TOOL_CALL_ARGS:case C.EventType.TOOL_CALL_END:case C.EventType.TOOL_CALL_RESULT:case C.EventType.STATE_SNAPSHOT:case C.EventType.STATE_DELTA:case C.EventType.MESSAGES_SNAPSHOT:case C.EventType.CUSTOM:case C.EventType.RUN_STARTED:case C.EventType.RUN_FINISHED:case C.EventType.RUN_ERROR:case C.EventType.STEP_STARTED:case C.EventType.STEP_FINISHED:case C.EventType.THINKING_START:case C.EventType.THINKING_END:case C.EventType.THINKING_TEXT_MESSAGE_START:case C.EventType.THINKING_TEXT_MESSAGE_CONTENT:case C.EventType.THINKING_TEXT_MESSAGE_END:return[...o(),g];case C.EventType.RAW:case C.EventType.ACTIVITY_SNAPSHOT:case C.EventType.ACTIVITY_DELTA:return[g];case C.EventType.TEXT_MESSAGE_CHUNK:let S=g,H=[];if((t!=="text"||S.messageId!==void 0&&S.messageId!==(e==null?void 0:e.messageId))&&H.push(...o()),t!=="text"){if(S.messageId===void 0)throw new Error("First TEXT_MESSAGE_CHUNK must have a messageId");e={messageId:S.messageId},t="text";let c={type:C.EventType.TEXT_MESSAGE_START,messageId:S.messageId,role:S.role||"assistant"};H.push(c),l&&console.debug("[TRANSFORM]: TEXT_MESSAGE_START",JSON.stringify(c))}if(S.delta!==void 0){let c={type:C.EventType.TEXT_MESSAGE_CONTENT,messageId:e.messageId,delta:S.delta};H.push(c),l&&console.debug("[TRANSFORM]: TEXT_MESSAGE_CONTENT",JSON.stringify(c))}return H;case C.EventType.TOOL_CALL_CHUNK:let T=g,y=[];if((t!=="tool"||T.toolCallId!==void 0&&T.toolCallId!==(a==null?void 0:a.toolCallId))&&y.push(...o()),t!=="tool"){if(T.toolCallId===void 0)throw new Error("First TOOL_CALL_CHUNK must have a toolCallId");if(T.toolCallName===void 0)throw new Error("First TOOL_CALL_CHUNK must have a toolCallName");a={toolCallId:T.toolCallId,toolCallName:T.toolCallName,parentMessageId:T.parentMessageId},t="tool";let c={type:C.EventType.TOOL_CALL_START,toolCallId:T.toolCallId,toolCallName:T.toolCallName,parentMessageId:T.parentMessageId};y.push(c),l&&console.debug("[TRANSFORM]: TOOL_CALL_START",JSON.stringify(c))}if(T.delta!==void 0){let c={type:C.EventType.TOOL_CALL_ARGS,toolCallId:a.toolCallId,delta:T.delta};y.push(c),l&&console.debug("[TRANSFORM]: TOOL_CALL_ARGS",JSON.stringify(c))}return y}let u=g.type;return[]}),(0,it.finalize)(()=>{o()}))};var pt=require("@ag-ui/core"),$=class{constructor({agentId:s,description:e,threadId:a,initialMessages:t,initialState:n,debug:r}={}){this.debug=!1;this.subscribers=[];this.isRunning=!1;this.agentId=s,this.description=e!=null?e:"",this.threadId=a!=null?a:(0,J.v4)(),this.messages=R(t!=null?t:[]),this.state=R(n!=null?n:{}),this.debug=r!=null?r:!1}subscribe(s){return this.subscribers.push(s),{unsubscribe:()=>{this.subscribers=this.subscribers.filter(e=>e!==s)}}}async runAgent(s,e){var a;try{this.isRunning=!0,this.agentId=(a=this.agentId)!=null?a:(0,J.v4)();let t=this.prepareRunAgentInput(s),n,r=new Set(this.messages.map(S=>S.id)),o=[{onRunFinishedEvent:S=>{n=S.result}},...this.subscribers,e!=null?e:{}];await this.onInitialize(t,o);let g=(0,X.pipe)(()=>this.run(t),Y(this.debug),z(this.debug),S=>this.apply(t,S,o),S=>this.processApplyEvents(t,S,o),(0,K.catchError)(S=>(this.isRunning=!1,this.onError(t,S,o))),(0,Et.finalize)(()=>{this.isRunning=!1,this.onFinalize(t,o)}));await(0,ut.lastValueFrom)(g((0,X.of)(null)));let u=R(this.messages).filter(S=>!r.has(S.id));return{result:n,newMessages:u}}finally{this.isRunning=!1}}connect(s){throw new pt.AGUIConnectNotImplementedError}async connectAgent(s,e){var a;try{this.isRunning=!0,this.agentId=(a=this.agentId)!=null?a:(0,J.v4)();let t=this.prepareRunAgentInput(s),n,r=new Set(this.messages.map(S=>S.id)),o=[{onRunFinishedEvent:S=>{n=S.result}},...this.subscribers,e!=null?e:{}];await this.onInitialize(t,o);let g=(0,X.pipe)(()=>this.connect(t),Y(this.debug),z(this.debug),S=>this.apply(t,S,o),S=>this.processApplyEvents(t,S,o),(0,K.catchError)(S=>(this.isRunning=!1,S instanceof pt.AGUIConnectNotImplementedError?X.EMPTY:this.onError(t,S,o))),(0,Et.finalize)(()=>{this.isRunning=!1,this.onFinalize(t,o)}));await(0,ut.lastValueFrom)(g((0,X.of)(null)));let u=R(this.messages).filter(S=>!r.has(S.id));return{result:n,newMessages:u}}finally{this.isRunning=!1}}abortRun(){}apply(s,e,a){return Z(s,e,this,a)}processApplyEvents(s,e,a){return e.pipe((0,K.tap)(t=>{t.messages&&(this.messages=t.messages,a.forEach(n=>{var r;(r=n.onMessagesChanged)==null||r.call(n,{messages:this.messages,state:this.state,agent:this,input:s})})),t.state&&(this.state=t.state,a.forEach(n=>{var r;(r=n.onStateChanged)==null||r.call(n,{state:this.state,messages:this.messages,agent:this,input:s})}))}))}prepareRunAgentInput(s){var t,n,r;let a=R(this.messages).filter(o=>o.role!=="activity");return{threadId:this.threadId,runId:(s==null?void 0:s.runId)||(0,J.v4)(),tools:R((t=s==null?void 0:s.tools)!=null?t:[]),context:R((n=s==null?void 0:s.context)!=null?n:[]),forwardedProps:R((r=s==null?void 0:s.forwardedProps)!=null?r:{}),state:R(this.state),messages:a}}async onInitialize(s,e){let a=await x(e,this.messages,this.state,(t,n,r)=>{var o;return(o=t.onRunInitialized)==null?void 0:o.call(t,{messages:n,state:r,agent:this,input:s})});(a.messages!==void 0||a.state!==void 0)&&(a.messages&&(this.messages=a.messages,s.messages=a.messages,e.forEach(t=>{var n;(n=t.onMessagesChanged)==null||n.call(t,{messages:this.messages,state:this.state,agent:this,input:s})})),a.state&&(this.state=a.state,s.state=a.state,e.forEach(t=>{var n;(n=t.onStateChanged)==null||n.call(t,{state:this.state,messages:this.messages,agent:this,input:s})})))}onError(s,e,a){return(0,X.from)(x(a,this.messages,this.state,(t,n,r)=>{var o;return(o=t.onRunFailed)==null?void 0:o.call(t,{error:e,messages:n,state:r,agent:this,input:s})})).pipe((0,K.map)(t=>{let n=t;if((n.messages!==void 0||n.state!==void 0)&&(n.messages!==void 0&&(this.messages=n.messages,a.forEach(r=>{var o;(o=r.onMessagesChanged)==null||o.call(r,{messages:this.messages,state:this.state,agent:this,input:s})})),n.state!==void 0&&(this.state=n.state,a.forEach(r=>{var o;(o=r.onStateChanged)==null||o.call(r,{state:this.state,messages:this.messages,agent:this,input:s})}))),n.stopPropagation!==!0)throw console.error("Agent execution failed:",e),e;return{}}))}async onFinalize(s,e){let a=await x(e,this.messages,this.state,(t,n,r)=>{var o;return(o=t.onRunFinalized)==null?void 0:o.call(t,{messages:n,state:r,agent:this,input:s})});(a.messages!==void 0||a.state!==void 0)&&(a.messages!==void 0&&(this.messages=a.messages,e.forEach(t=>{var n;(n=t.onMessagesChanged)==null||n.call(t,{messages:this.messages,state:this.state,agent:this,input:s})})),a.state!==void 0&&(this.state=a.state,e.forEach(t=>{var n;(n=t.onStateChanged)==null||n.call(t,{state:this.state,messages:this.messages,agent:this,input:s})})))}clone(){let s=Object.create(Object.getPrototypeOf(this));return s.agentId=this.agentId,s.description=this.description,s.threadId=this.threadId,s.messages=R(this.messages),s.state=R(this.state),s.debug=this.debug,s.isRunning=this.isRunning,s.subscribers=[...this.subscribers],s}addMessage(s){this.messages.push(s),(async()=>{var e,a,t;for(let n of this.subscribers)await((e=n.onNewMessage)==null?void 0:e.call(n,{message:s,messages:this.messages,state:this.state,agent:this}));if(s.role==="assistant"&&s.toolCalls)for(let n of s.toolCalls)for(let r of this.subscribers)await((a=r.onNewToolCall)==null?void 0:a.call(r,{toolCall:n,messages:this.messages,state:this.state,agent:this}));for(let n of this.subscribers)await((t=n.onMessagesChanged)==null?void 0:t.call(n,{messages:this.messages,state:this.state,agent:this}))})()}addMessages(s){this.messages.push(...s),(async()=>{var e,a,t;for(let n of s){for(let r of this.subscribers)await((e=r.onNewMessage)==null?void 0:e.call(r,{message:n,messages:this.messages,state:this.state,agent:this}));if(n.role==="assistant"&&n.toolCalls)for(let r of n.toolCalls)for(let o of this.subscribers)await((a=o.onNewToolCall)==null?void 0:a.call(o,{toolCall:r,messages:this.messages,state:this.state,agent:this}))}for(let n of this.subscribers)await((t=n.onMessagesChanged)==null?void 0:t.call(n,{messages:this.messages,state:this.state,agent:this}))})()}setMessages(s){this.messages=R(s),(async()=>{var e;for(let a of this.subscribers)await((e=a.onMessagesChanged)==null?void 0:e.call(a,{messages:this.messages,state:this.state,agent:this}))})()}setState(s){this.state=R(s),(async()=>{var e;for(let a of this.subscribers)await((e=a.onStateChanged)==null?void 0:e.call(a,{messages:this.messages,state:this.state,agent:this}))})()}legacy_to_be_removed_runAgentBridged(s){var a;this.agentId=(a=this.agentId)!=null?a:(0,J.v4)();let e=this.prepareRunAgentInput(s);return this.run(e).pipe(Y(this.debug),z(this.debug),rt(this.threadId,e.runId,this.agentId),t=>t.pipe((0,K.map)(n=>(this.debug&&console.debug("[LEGACY]:",JSON.stringify(n)),n))))}};var lt=class extends ${constructor(e){var a;super(e);this.abortController=new AbortController;this.url=e.url,this.headers=R((a=e.headers)!=null?a:{})}requestInit(e){return{method:"POST",headers:k(L({},this.headers),{"Content-Type":"application/json",Accept:"text/event-stream"}),body:JSON.stringify(e),signal:this.abortController.signal}}runAgent(e,a){var t;return this.abortController=(t=e==null?void 0:e.abortController)!=null?t:new AbortController,super.runAgent(e,a)}abortRun(){this.abortController.abort(),super.abortRun()}run(e){let a=et(this.url,this.requestInit(e));return ot(a)}clone(){var n;let e=super.clone();e.url=this.url,e.headers=R((n=this.headers)!=null?n:{});let a=new AbortController,t=this.abortController.signal;return t.aborted&&a.abort(t.reason),e.abortController=a,e}};var B=require("@ag-ui/core");function Ot(l){let s=[],e=new Map,a=new Map;for(let t of l)if(t.type===B.EventType.TEXT_MESSAGE_START){let n=t,r=n.messageId;e.has(r)||e.set(r,{contents:[],otherEvents:[]});let o=e.get(r);o.start=n}else if(t.type===B.EventType.TEXT_MESSAGE_CONTENT){let n=t,r=n.messageId;e.has(r)||e.set(r,{contents:[],otherEvents:[]}),e.get(r).contents.push(n)}else if(t.type===B.EventType.TEXT_MESSAGE_END){let n=t,r=n.messageId;e.has(r)||e.set(r,{contents:[],otherEvents:[]});let o=e.get(r);o.end=n,Nt(r,o,s),e.delete(r)}else if(t.type===B.EventType.TOOL_CALL_START){let n=t,r=n.toolCallId;a.has(r)||a.set(r,{args:[],otherEvents:[]});let o=a.get(r);o.start=n}else if(t.type===B.EventType.TOOL_CALL_ARGS){let n=t,r=n.toolCallId;a.has(r)||a.set(r,{args:[],otherEvents:[]}),a.get(r).args.push(n)}else if(t.type===B.EventType.TOOL_CALL_END){let n=t,r=n.toolCallId;a.has(r)||a.set(r,{args:[],otherEvents:[]});let o=a.get(r);o.end=n,Lt(r,o,s),a.delete(r)}else{let n=!1;for(let[r,o]of e)if(o.start&&!o.end){o.otherEvents.push(t),n=!0;break}if(!n){for(let[r,o]of a)if(o.start&&!o.end){o.otherEvents.push(t),n=!0;break}}n||s.push(t)}for(let[t,n]of e)Nt(t,n,s);for(let[t,n]of a)Lt(t,n,s);return s}function Nt(l,s,e){if(s.start&&e.push(s.start),s.contents.length>0){let a=s.contents.map(n=>n.delta).join(""),t={type:B.EventType.TEXT_MESSAGE_CONTENT,messageId:l,delta:a};e.push(t)}s.end&&e.push(s.end);for(let a of s.otherEvents)e.push(a)}function Lt(l,s,e){if(s.start&&e.push(s.start),s.args.length>0){let a=s.args.map(n=>n.delta).join(""),t={type:B.EventType.TOOL_CALL_ARGS,toolCallId:l,delta:a};e.push(t)}s.end&&e.push(s.end);for(let a of s.otherEvents)e.push(a)}D(P,require("@ag-ui/core"),module.exports);0&&(module.exports={AbstractAgent,HttpAgent,compactEvents,convertToLegacyEvents,defaultApplyEvents,parseProtoStream,parseSSEStream,randomUUID,runHttpRequest,structuredClone_,transformChunks,transformHttpEventStream,verifyEvents,...require("@ag-ui/core")});
8
8
  //# sourceMappingURL=index.js.map