@artooi/ag-ui-web-component 0.45.0 → 0.47.0
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/CHANGELOG.md +146 -1
- package/README.md +191 -25
- package/dist/ag-ui-web-component.bundle.js +399 -157
- package/dist/ag-ui-web-component.bundle.js.map +4 -4
- package/dist/constants.d.ts +14 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/core/ag_ui_chat.d.ts +47 -4
- package/dist/core/ag_ui_chat.d.ts.map +1 -1
- package/dist/core/chat_registry.d.ts +23 -0
- package/dist/core/chat_registry.d.ts.map +1 -0
- package/dist/core/events/run_finished_detail.d.ts +6 -0
- package/dist/core/events/run_finished_detail.d.ts.map +1 -1
- package/dist/core/events/thread_detail.d.ts +27 -0
- package/dist/core/events/thread_detail.d.ts.map +1 -0
- package/dist/core/run_handlers.d.ts +6 -1
- package/dist/core/run_handlers.d.ts.map +1 -1
- package/dist/dom/animations.d.ts +21 -6
- package/dist/dom/animations.d.ts.map +1 -1
- package/dist/dom/highlight_overlay.d.ts +7 -1
- package/dist/dom/highlight_overlay.d.ts.map +1 -1
- package/dist/dom/ring_color.d.ts +14 -0
- package/dist/dom/ring_color.d.ts.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +857 -86
- package/dist/index.js.map +4 -4
- package/dist/tools/tool_catalog.d.ts +5 -0
- package/dist/tools/tool_catalog.d.ts.map +1 -1
- package/dist/tools/tool_dispatch.d.ts.map +1 -1
- package/dist/ui/history/conversation_history.d.ts +10 -1
- package/dist/ui/history/conversation_history.d.ts.map +1 -1
- package/dist/ui/interrupts/confirmation_styles.d.ts.map +1 -1
- package/dist/ui/placement/panel_placement.d.ts +6 -0
- package/dist/ui/placement/panel_placement.d.ts.map +1 -1
- package/dist/ui/placement/small_viewport_styles.d.ts.map +1 -1
- package/dist/ui/placement/surface_for.d.ts +12 -1
- package/dist/ui/placement/surface_for.d.ts.map +1 -1
- package/dist/ui/progress/thoughts_styles.d.ts.map +1 -1
- package/dist/ui/progress/tool_call_card.d.ts +8 -0
- package/dist/ui/progress/tool_call_card.d.ts.map +1 -1
- package/dist/ui/progress/tool_group_styles.d.ts +2 -0
- package/dist/ui/progress/tool_group_styles.d.ts.map +1 -0
- package/dist/ui/progress/tool_step_group.d.ts +47 -0
- package/dist/ui/progress/tool_step_group.d.ts.map +1 -0
- package/dist/ui/progress/tool_step_styles.d.ts.map +1 -1
- package/dist/ui/shell/token_styles.d.ts.map +1 -1
- package/dist/ui/styles.d.ts.map +1 -1
- package/dist/ui/themes/ledger_styles.d.ts.map +1 -1
- package/dist/ui/themes/soft_styles.d.ts.map +1 -1
- package/dist/ui/transcript/groups_tool_steps.d.ts +13 -0
- package/dist/ui/transcript/groups_tool_steps.d.ts.map +1 -0
- package/dist/ui/transcript/message_styles.d.ts.map +1 -1
- package/dist/ui/transcript/transcript.d.ts +16 -1
- package/dist/ui/transcript/transcript.d.ts.map +1 -1
- package/dist/ui/ui_strings.d.ts +18 -0
- package/dist/ui/ui_strings.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +15 -1
- package/src/core/ag_ui_chat.ts +122 -11
- package/src/core/chat_registry.ts +53 -0
- package/src/core/events/run_finished_detail.ts +6 -0
- package/src/core/events/thread_detail.ts +26 -0
- package/src/core/run_handlers.ts +9 -4
- package/src/dom/animations.ts +30 -31
- package/src/dom/highlight_overlay.ts +9 -5
- package/src/dom/ring_color.ts +85 -0
- package/src/index.ts +3 -0
- package/src/tools/tool_catalog.ts +23 -10
- package/src/tools/tool_dispatch.ts +26 -11
- package/src/ui/history/conversation_history.ts +28 -4
- package/src/ui/interrupts/confirmation_styles.ts +0 -2
- package/src/ui/placement/embedded_styles.ts +2 -2
- package/src/ui/placement/panel_placement.ts +34 -9
- package/src/ui/placement/preset_styles.ts +1 -1
- package/src/ui/placement/sidebar_styles.ts +1 -1
- package/src/ui/placement/small_viewport_styles.ts +5 -0
- package/src/ui/placement/surface_for.ts +12 -1
- package/src/ui/progress/thoughts_styles.ts +0 -2
- package/src/ui/progress/tool_call_card.ts +29 -8
- package/src/ui/progress/tool_group_styles.ts +232 -0
- package/src/ui/progress/tool_step_group.ts +272 -0
- package/src/ui/progress/tool_step_styles.ts +0 -2
- package/src/ui/shell/token_styles.ts +4 -2
- package/src/ui/styles.ts +5 -0
- package/src/ui/themes/ledger_styles.ts +15 -0
- package/src/ui/themes/soft_styles.ts +20 -0
- package/src/ui/transcript/groups_tool_steps.ts +16 -0
- package/src/ui/transcript/message_styles.ts +0 -2
- package/src/ui/transcript/transcript.ts +109 -3
- package/src/ui/ui_strings.ts +31 -0
- package/src/version.ts +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var kE=Object.defineProperty;var vl=(e,t)=>{for(var n in t)kE(e,n,{get:t[n],enumerable:!0})};var $o="ag-ui-chat",bl="ag-ui-submit",yl="ag-ui-toggle",wl="ag-ui-unread",El="ag-ui-state",xl="ag-ui-attachments",_l="ag-ui-run-finished",Sl="ag-ui-custom",Tl="ag-ui-invalidate",Al="ag-ui-feedback",kl="suggestions",Il="ag_ui.invalidate",wp="ag_ui.subagent",Un={STARTED:"started",TOOL_CALL:"tool_call",TOOL_RESULT:"tool_result",FINISHED:"finished",FAILED:"failed"},Ze={USER:"user",ASSISTANT:"assistant"},_r="x-destructive",Uo="x-confirm",Oe="x-summary",Sr="x-navigates",Ho="read_page",Hn=10,en={COPY:"copy",RETRY:"retry",FEEDBACK:"feedback"},te={PENDING:"pending",DEFERRED:"deferred",DONE:"done",ERROR:"error",DECLINED:"declined",INTERRUPTED:"interrupted"},Ve={SUCCESS:"success",FAILED:"failed",DENIED:"denied",INTERRUPTED:"interrupted"},Xe={UPLOADING:"uploading",READY:"ready",ERROR:"error"},Rl=10*1024*1024,Fn={INLINE:"inline",MINIMAL:"minimal",COMPACT:"compact",FULL:"full"},Cl="compaction",Nl="load_capability",Ep='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19.5V5m-6.5 6.5L12 5l6.5 6.5"/></svg>',xp='<svg class="glyph glyph--solid" viewBox="0 0 24 24" aria-hidden="true"><rect x="7" y="7" width="10" height="10" rx="2.5"/></svg>',_p='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M17 8.5V15a5 5 0 0 1-10 0V7a3 3 0 0 1 6 0v7.5a1 1 0 0 1-2 0V8.5"/></svg>',Sp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 4a3 3 0 0 1 3 3v5a3 3 0 0 1-6 0V7a3 3 0 0 1 3-3z"/><path d="M5 11v1a7 7 0 0 0 14 0v-1"/><path d="M12 19v3"/></svg>',Tp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 14.5A8.5 8.5 0 0 1 9.5 4a8.5 8.5 0 1 0 10.5 10.5z"/></svg>',Ap='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>',kp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 5.5A2.5 2.5 0 0 1 6.5 3h11A2.5 2.5 0 0 1 20 5.5v8a2.5 2.5 0 0 1-2.5 2.5H9l-5 4z"/></svg>',Ip='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V6a2 2 0 0 1 2-2h8"/></svg>',Rp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 12a8 8 0 1 1-2.5-5.8"/><path d="M20 4v4h-4"/></svg>',Cp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M7 10v10H4V10z"/><path d="M7 10l4.5-7a2 2 0 0 1 3.4 2L13.5 9H19a2 2 0 0 1 2 2.3l-1.1 6.4A2 2 0 0 1 17.9 20H7"/></svg>',Np='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M17 14V4h3v10z"/><path d="M17 14l-4.5 7a2 2 0 0 1-3.4-2l1.4-4H5a2 2 0 0 1-2-2.3l1.1-6.4A2 2 0 0 1 6.1 4H17"/></svg>',Op='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/></svg>',Pp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><rect x="3.5" y="4.5" width="17" height="15" rx="2.5"/><circle cx="9" cy="10" r="1.5"/><path d="M4.5 17.5 9 13.5l3.5 3 3-2.5 4.5 4"/></svg>',Mp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><rect class="glyph--solid" x="7.5" y="13.5" width="9" height="4.5" rx="1"/></svg>',zp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><path d="M8.5 13.5h7M8.5 17h4.5"/></svg>',Fo="chart",tn=24,Lp=150,Dp=2147483001,Go=5e3,st=8;var IE=/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;function ue(e,t){return e.replace(IE,(n,r)=>Object.hasOwn(t,r)?String(t[r]):n)}var RE=/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;function $p(e,t){let n=[];return{text:e.replace(RE,(o,i)=>{let a=t[i];return a==null||a===""?(n.includes(i)||n.push(i),o):String(a)}),missing:n}}function CE(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.name=="string"&&typeof t.title=="string"&&(t.prompt===void 0||typeof t.prompt=="string")}function Ol(e){return Array.isArray(e)?e.filter(CE):[]}var Bo=class{#e;#t=[];#n=[];#o=[];constructor(t){this.#e=t}setClientSkills(t){this.#o=t,this.#i()}init(){this.#e.menu.enableChips(this.#e.flag("data-prompt-chips")),this.#e.menu.enableSlash(this.#e.flag("data-slash-commands")),this.#n=this.#r(),this.#i()}async fetch(){let t=this.#e.element.getAttribute("data-skills-url");if(t!==null)try{let n=await fetch(t,this.#e.fetchInit(t));this.#t=Ol(await n.json()),this.#i()}catch{}}apply(t){let{input:n,hint:r}=this.#e;if(t.prompt===void 0){r.hidden=!0,this.#e.send(`/${t.name}`);return}let{text:o,missing:i}=$p(t.prompt,this.#e.context());if(i.length>0){r.textContent=ue(this.#e.strings().skillNeeds,{title:t.title,fields:i.join(", ")}),r.hidden=!1,n.value=o,this.#e.autoGrow(),n.focus(),this.#a(o);return}if(r.hidden=!0,n.value=o,this.#e.autoGrow(),t.sendImmediately===!1){n.focus();return}this.#e.submit()}#r(){return Ol(this.#e.readJsonAttribute("data-skills"))}#i(){let t=new Map;for(let n of[...this.#t,...this.#n,...this.#o])t.set(n.name,n);this.#e.menu.setSkills([...t.values()])}#a(t){let n=t.indexOf("{");this.#e.input.setSelectionRange(n,t.indexOf("}",n)+1)}};var Zo=["top-left","top-right","bottom-left","bottom-right"];function Up(e){return Zo.includes(e)}function Pl(e){return[{name:"read_chat_surface",description:"Describe the chat panel you are speaking from: its placement, whether it is collapsed, whether it can be moved, and the box it occupies. Read this before moving or minimising yourself, since a full-screen panel has nowhere to move to. Read-only.",parameters:{type:"object",properties:{},required:[],[Oe]:"Read the chat's own position"},handler:()=>e.describeSurface()},{name:"move_chat",description:"Move your own panel to a corner, to uncover something the user needs to see. `corner` is top-left, top-right, bottom-left or bottom-right. Answers `moved: false` with a reason when the placement owns its position or the panel fills the screen; check `read_chat_surface` first, and prefer minimise_chat when there is nowhere to move to.",parameters:{type:"object",properties:{corner:{type:"string",enum:[...Zo]}},required:["corner"],[Oe]:"Move the chat out of the way"},handler:t=>{let n=String(t.corner??""),r=e.describeSurface();return Up(n)?r.movable?{moved:e.moveTo(n,{announce:!0}),corner:n}:{moved:!1,reason:r.fullBleed?"the panel fills the screen, so there is nowhere to move it to":r.draggable===!1?"this page has turned off moving the panel":`the "${r.placement??""}" placement owns the panel's position`,suggestion:r.collapsible?"minimise_chat":null}:{moved:!1,reason:`"${n}" is not a corner; use one of ${Zo.join(", ")}`}}},{name:"minimise_chat",description:"Collapse your own panel to its launcher, so the user can see the whole page. The launcher stays visible and reopens it. Answers `minimised: false` when the placement has no collapsed state, which is the case for a full-page chat.",parameters:{type:"object",properties:{},required:[],[Oe]:"Minimise the chat"},handler:()=>e.describeSurface().collapsible?(e.setCollapsed(!0,{announce:!0}),{minimised:!0}):{minimised:!1,reason:"this placement has no collapsed state, so there is no launcher to return to"}},{name:"restore_chat",description:"Open your own panel again after minimising it.",parameters:{type:"object",properties:{},required:[],[Oe]:"Restore the chat"},handler:()=>(e.setCollapsed(!1),{restored:!0})}]}var Tr=class{#e=new Map;register(t){this.#e.set(t.name,t)}has(t){return this.#e.has(t)}get(t){let n=this.#e.get(t);if(n===void 0)throw new Error(`tool "${t}" is not registered`);return n}tools(){return[...this.#e.values()].map(t=>({name:t.name,description:t.description,parameters:t.parameters}))}};var NE="#4f46e5";function Gn(e,t,n){let r=window.getComputedStyle(e).getPropertyValue(t).trim();return r===""?n:r}var OE=4;function Ml(e,t={}){let n=document.createElement("div");n.setAttribute("data-ag-ui-highlight",""),n.setAttribute("aria-hidden","true"),n.style.cssText=["position: fixed","inset: 0","pointer-events: none",`z-index: ${Gn(e,"--ag-ui-highlight-z-index",String(Dp))}`].join(";");let r=document.createElement("div"),o=document.createElement("div");n.className="ag-ui-highlight",r.className="ag-ui-highlight-scrim",o.className="ag-ui-highlight-ring",t.scrim===!0&&n.append(r),n.append(o);let i=t.ringWidth??Number.parseFloat(Gn(e,"--ag-ui-highlight-ring-width","3")),a=t.flowMs??Number.parseFloat(Gn(e,"--ag-ui-highlight-flow-ms","2400")),s=()=>{let u=e.getBoundingClientRect(),f=t.padding??OE,m=t.radius??Number.parseFloat(getComputedStyle(e).borderRadius),p=u.left-f,h=u.top-f,E=u.width+f*2,g=u.height+f*2;t.scrim===!0&&(r.style.cssText=["position: absolute","inset: 0",`background: ${Gn(e,"--ag-ui-highlight-scrim","rgba(15, 15, 25, 0.45)")}`,`clip-path: path(evenodd, '${zE(p,h,E,g,m+f)}')`].join(";")),o.style.cssText=["position: absolute",`left: ${p}px`,`top: ${h}px`,`width: ${E}px`,`height: ${g}px`,`border-radius: ${m+f}px`,`border: ${i}px solid transparent`,"box-sizing: border-box",ME(e,t)].join(";")};s();let l=null;t.gradient===!0&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches&&(l=o.animate([{backgroundPosition:"100% 0"},{backgroundPosition:"-100% 0"}],{duration:a,iterations:Number.POSITIVE_INFINITY,easing:"linear"}));let c={capture:!0,passive:!0};return window.addEventListener("scroll",s,c),window.addEventListener("resize",s,c),document.body.appendChild(n),()=>{window.removeEventListener("scroll",s,c),window.removeEventListener("resize",s,c),l?.cancel(),n.remove()}}function PE(e){return e===void 0?null:CSS.supports("color",e)?e:null}function ME(e,t){let n=PE(t.color)??Gn(e,"--ag-ui-accent",NE);if(t.gradient!==!0)return`border-color: ${n}`;let r=Gn(e,"--ag-ui-highlight-gradient",`linear-gradient(115deg, transparent 20%, ${n} 50%, transparent 80%)`),o="linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)";return[`background-image: ${r}`,"background-origin: border-box","background-size: 300% 100%",`-webkit-mask: ${o}`,`mask: ${o}`,"-webkit-mask-composite: xor","mask-composite: exclude","background-position: 50% 0"].join(";")}function zE(e,t,n,r,o){let i=Math.max(0,Math.min(o,n/2,r/2)),a=e+n,s=t+r,l=`M 0 0 H ${window.innerWidth} V ${window.innerHeight} H 0 Z`,c=[`M ${e+i} ${t}`,`H ${a-i}`,`A ${i} ${i} 0 0 1 ${a} ${t+i}`,`V ${s-i}`,`A ${i} ${i} 0 0 1 ${a-i} ${s}`,`H ${e+i}`,`A ${i} ${i} 0 0 1 ${e} ${s-i}`,`V ${t+i}`,`A ${i} ${i} 0 0 1 ${e+i} ${t}`,"Z"].join(" ");return`${l} ${c}`}function Vo(e,t){return Object.getOwnPropertyDescriptor(e,t).set}var LE=Vo(HTMLInputElement.prototype,"value"),DE=Vo(HTMLTextAreaElement.prototype,"value"),$E=Vo(HTMLSelectElement.prototype,"value"),UE=Vo(HTMLInputElement.prototype,"checked");function nn(e,t){e instanceof HTMLTextAreaElement?DE.call(e,t):e instanceof HTMLSelectElement?$E.call(e,t):LE.call(e,t)}function Ar(e,t){UE.call(e,t)}var zl="#4f46e5",HE="rgba(79, 70, 229, 0.4)",FE="--ag-ui-accent";function Bn(e){return new Promise(t=>{setTimeout(t,e)})}function jo(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function Ll(e){return e<=0||jo()?Promise.resolve():Bn(e)}function Wo(e,t){let n=window.getComputedStyle(e).getPropertyValue(FE).trim();return n===""?t:n}function Hp(e){return`0 0 0 3px ${Wo(e,HE)}`}async function Dl(e,t,n={}){let r=n.charDelayMs??35;nn(e,""),e.dispatchEvent(new Event("input",{bubbles:!0}));for(let o of t)nn(e,e.value+o),e.dispatchEvent(new Event("input",{bubbles:!0})),r>0&&await Bn(r);e.dispatchEvent(new Event("change",{bubbles:!0}))}async function $l(e,t={}){let n=t.highlightMs??280,r=e.style.outline,o=e.style.outlineOffset;e.style.outline=`2px solid ${Wo(e,zl)}`,e.style.outlineOffset="2px",await Bn(n),e.style.outline=r,e.style.outlineOffset=o,e.click()}var GE=600,BE=100;function It(e,t={}){let n=jo();return e.scrollIntoView({block:"center",inline:"nearest",behavior:n?"auto":"smooth"}),n?Promise.resolve():new Promise(r=>{let o,i=()=>{clearTimeout(o),document.removeEventListener("scroll",a,!0),document.removeEventListener("scrollend",i,!0),r()},a=()=>{document.removeEventListener("scroll",a,!0),clearTimeout(o),o=setTimeout(i,t.settleMs??GE)};o=setTimeout(i,BE),document.addEventListener("scroll",a,!0),document.addEventListener("scrollend",i,!0)})}var ZE=1200,VE=1/3;async function Fp(e,t,n){(t.focus??n)&&e.focus({preventScroll:!0});let r=t.flashMs??ZE;if(r<=0)return;if(t.scrim===!0||t.gradient===!0){let c=Ml(e,{scrim:t.scrim===!0,gradient:t.gradient===!0,...t.color===void 0?{}:{color:t.color},...t.ringPadding===void 0?{}:{padding:t.ringPadding}});await Bn(r),c();return}let o=e.style.outline,i=e.style.outlineOffset,a=e.style.transition,s=t.color??Wo(e,zl);e.style.outline=`3px solid ${s}`,e.style.outlineOffset="2px";let l=jo()?0:Math.round(r*VE);await Bn(r-l),l>0&&(e.style.transition=`outline-color ${l}ms ease-out`,e.style.outline="3px solid transparent",await Bn(l)),e.style.outline=o,e.style.outlineOffset=i,e.style.transition=a}function jE(e,t={}){return Fp(e,t,!1)}function Ul(e,t={}){return Fp(e,t,!0)}async function Hl(e,t={}){let n=t.pressMs??140,r=e.style.transform,o=e.style.transition,i=e.style.boxShadow;e.style.transition="transform 80ms ease",e.style.transform="scale(0.96)",e.style.boxShadow=Hp(e),await Ll(n),e.style.transform=r,e.style.transition=o,e.style.boxShadow=i,e.click()}function WE(e,t){for(let n of Array.from(e.options))if(n.value===t||n.text===t)return n;return null}async function Fl(e,t,n={}){let r=WE(e,t);if(r===null)throw new Error(`no <option> matching "${t}"`);let o=n.highlightMs??220,i=e.style.outline,a=e.style.outlineOffset;e.style.outline=`2px solid ${Wo(e,zl)}`,e.style.outlineOffset="2px",await Ll(o),nn(e,r.value),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),e.style.outline=i,e.style.outlineOffset=a}async function Gl(e,t,n={}){let r=n.flashMs??200,o=e.style.boxShadow;e.style.boxShadow=Hp(e),await Ll(r),Ar(e,t),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),e.style.boxShadow=o}var Ir={SCROLL:"scroll",DRAG:"drag",CHAT:"chat"};function Bl(e,t){let n=[];return e.has(Ir.SCROLL)&&n.push(qE(t)),e.has(Ir.DRAG)&&n.push(YE(t)),n}function qE(e){return{name:"scroll_to",description:"Scroll a target into view. `target` is `top`, `bottom`, or a CSS selector / page-map element id. Read-only: it changes nothing on the page.",parameters:{type:"object",properties:{target:{type:"string"}},required:["target"],[Oe]:"Scroll into view"},handler:t=>{let n=String(t.target??"");if(n==="top"||n==="bottom"){let o=n==="top"?0:document.body.scrollHeight;return window.scrollTo({top:o,behavior:"smooth"}),{scrolled:!0,target:n}}let r=e(n);if(r===null)throw new Error(`no element matching "${n}"`);return It(r),{scrolled:!0,target:n}}}}function YE(e){return{name:"drag_and_drop",description:"Drag the `from` element onto the `to` element (CSS selectors or page-map element ids), firing the page's native drag-and-drop. Use for reordering sortable lists. The page decides what the drop commits.",parameters:{type:"object",properties:{from:{type:"string"},to:{type:"string"}},required:["from","to"],[Oe]:"Drag and drop"},handler:t=>{let n=String(t.from??""),r=String(t.to??""),o=e(n);if(o===null)throw new Error(`no element matching "${n}"`);let i=e(r);if(i===null)throw new Error(`no element matching "${r}"`);return XE(o,i),{dragged:!0,from:n,to:r}}}}function XE(e,t){let n=new DataTransfer;kr(e,"dragstart",n),kr(t,"dragenter",n),kr(t,"dragover",n),kr(t,"drop",n),kr(e,"dragend",n)}function kr(e,t,n){let r=new Event(t,{bubbles:!0,cancelable:!0});r.dataTransfer=n,e.dispatchEvent(r)}function Zl(e,t){return!t||e===null?[]:[{description:"page_map",value:JSON.stringify(e())}]}function qo(e){let t=[{name:`read_${e.name}`,description:`Read the "${e.name}" state.`,parameters:{type:"object",properties:{},required:[],[Oe]:`Read ${e.name}`},handler:()=>e.read()}],n=e.write;return n!==void 0&&t.push({name:`set_${e.name}`,description:`Update the "${e.name}" state.`,parameters:{...e.schema??{type:"object"},[_r]:!0,[Oe]:`Update ${e.name}`},handler:r=>n(r)}),t}var KE=qo;var Gp=/:([A-Za-z_][A-Za-z0-9_]*)/g;function JE(e){return[...e.matchAll(Gp)].map(t=>t[0].slice(1))}function QE(e,t,n){let r={...n};return{path:t.replace(Gp,(i,a)=>{let s=n[a];if(s==null||String(s)==="")throw new Error(`route "${e}" requires path param "${a}"`);return delete r[a],encodeURIComponent(String(s))}),leftover:r}}function ex(e,t){let n=new URLSearchParams;for(let[o,i]of Object.entries(t))n.set(o,String(i));let r=n.toString();return r===""?e:`${e}?${r}`}function Vl(e,t){return[{name:"list_routes",description:"List the routes the app can navigate to. Each route's `pathParams` names the dynamic segments to pass as `params` to `navigate_to_route`.",parameters:{type:"object",properties:{},required:[],[Oe]:"List pages"},handler:()=>e().map(n=>({...n,pathParams:JE(n.path)}))},{name:"navigate_to_route",description:"Navigate to one of the app's routes by its id, filling any dynamic `:name` path segments (and extra query params) from `params`.",parameters:{type:"object",properties:{route_id:{type:"string"},params:{type:"object"}},required:["route_id"],[Sr]:!0,[Oe]:"Navigate"},handler:n=>{let r=n.route_id,o=e().find(u=>u.id===r);if(o===void 0)throw new Error(`unknown route "${String(r)}"`);let i=n.params??{},{path:a,leftover:s}=QE(o.id,o.path,i),l=ex(a,s),c=t();return c!==null?c(l):window.location.assign(l),{navigated:!0,path:l}}}]}var Le=[];for(let e=0;e<256;++e)Le.push((e+256).toString(16).slice(1));function Bp(e,t=0){return(Le[e[t+0]]+Le[e[t+1]]+Le[e[t+2]]+Le[e[t+3]]+"-"+Le[e[t+4]]+Le[e[t+5]]+"-"+Le[e[t+6]]+Le[e[t+7]]+"-"+Le[e[t+8]]+Le[e[t+9]]+"-"+Le[e[t+10]]+Le[e[t+11]]+Le[e[t+12]]+Le[e[t+13]]+Le[e[t+14]]+Le[e[t+15]]).toLowerCase()}var jl,tx=new Uint8Array(16);function Wl(){if(!jl){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");jl=crypto.getRandomValues.bind(crypto)}return jl(tx)}var nx=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ql={randomUUID:nx};function rx(e,t,n){if(ql.randomUUID&&!t&&!e)return ql.randomUUID();e=e||{};let r=e.random??e.rng?.()??Wl();if(r.length<16)throw new Error("Random bytes length must be >= 16");if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){if(n=n||0,n<0||n+16>t.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let o=0;o<16;++o)t[n+o]=r[o];return t}return Bp(r)}var $t=rx;var v=(function(e){return e.TEXT_MESSAGE_START="TEXT_MESSAGE_START",e.TEXT_MESSAGE_CONTENT="TEXT_MESSAGE_CONTENT",e.TEXT_MESSAGE_END="TEXT_MESSAGE_END",e.TEXT_MESSAGE_CHUNK="TEXT_MESSAGE_CHUNK",e.TOOL_CALL_START="TOOL_CALL_START",e.TOOL_CALL_ARGS="TOOL_CALL_ARGS",e.TOOL_CALL_END="TOOL_CALL_END",e.TOOL_CALL_CHUNK="TOOL_CALL_CHUNK",e.TOOL_CALL_RESULT="TOOL_CALL_RESULT",e.STATE_SNAPSHOT="STATE_SNAPSHOT",e.STATE_DELTA="STATE_DELTA",e.MESSAGES_SNAPSHOT="MESSAGES_SNAPSHOT",e.ACTIVITY_SNAPSHOT="ACTIVITY_SNAPSHOT",e.ACTIVITY_DELTA="ACTIVITY_DELTA",e.RAW="RAW",e.CUSTOM="CUSTOM",e.RUN_STARTED="RUN_STARTED",e.RUN_FINISHED="RUN_FINISHED",e.RUN_ERROR="RUN_ERROR",e.STEP_STARTED="STEP_STARTED",e.STEP_FINISHED="STEP_FINISHED",e.REASONING_START="REASONING_START",e.REASONING_MESSAGE_START="REASONING_MESSAGE_START",e.REASONING_MESSAGE_CONTENT="REASONING_MESSAGE_CONTENT",e.REASONING_MESSAGE_END="REASONING_MESSAGE_END",e.REASONING_MESSAGE_CHUNK="REASONING_MESSAGE_CHUNK",e.REASONING_END="REASONING_END",e.REASONING_ENCRYPTED_VALUE="REASONING_ENCRYPTED_VALUE",e.SUBAGENT_STARTED="SUBAGENT_STARTED",e.SUBAGENT_FINISHED="SUBAGENT_FINISHED",e.SUBAGENT_ERROR="SUBAGENT_ERROR",e})({}),rn="1.0";var ox={TextMessageStartEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","role","name"],fields:{}},TextMessageContentEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},TextMessageEndEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},TextMessageChunkEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","messageId","role","delta","name"],fields:{}},ToolCallStartEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","parentMessageId"],fields:{}},ToolCallArgsEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ToolCallEndEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ToolCallChunkEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","toolCallId","toolCallName","parentMessageId","delta"],fields:{}},TextPart:{optional:["id","metadata"],fields:{}},DataSource:{optional:[],fields:{}},UrlSource:{optional:["mimeType"],fields:{}},FileSource:{optional:["provider","mimeType"],fields:{}},PartSource:{discriminator:"type",variants:{data:"DataSource",url:"UrlSource",file:"FileSource"}},ImagePart:{optional:["id","metadata"],fields:{source:"PartSource"}},AudioPart:{optional:["id","metadata"],fields:{source:"PartSource"}},VideoPart:{optional:["id","metadata"],fields:{source:"PartSource"}},DocumentPart:{optional:["id","metadata"],fields:{source:"PartSource"}},ContentPart:{discriminator:"type",variants:{text:"TextPart",image:"ImagePart",audio:"AudioPart",video:"VideoPart",document:"DocumentPart"}},ToolCallResultEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","role"],fields:{content:{array:"ContentPart"}}},StateSnapshotEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},AddOperation:{optional:[],fields:{}},RemoveOperation:{optional:[],fields:{}},ReplaceOperation:{optional:[],fields:{}},MoveOperation:{optional:[],fields:{}},CopyOperation:{optional:[],fields:{}},TestOperation:{optional:[],fields:{}},JsonPatchOperation:{discriminator:"op",variants:{add:"AddOperation",remove:"RemoveOperation",replace:"ReplaceOperation",move:"MoveOperation",copy:"CopyOperation",test:"TestOperation"}},StateDeltaEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{delta:{array:"JsonPatchOperation"}}},DeveloperMessage:{optional:["subagentRunId","name","encryptedValue","metadata"],fields:{}},SystemMessage:{optional:["subagentRunId","name","encryptedValue","metadata"],fields:{}},FunctionCall:{optional:[],fields:{}},ToolCall:{optional:["encryptedValue","metadata"],fields:{function:"FunctionCall"}},AssistantMessage:{optional:["subagentRunId","name","encryptedValue","metadata","content","toolCalls"],fields:{toolCalls:{array:"ToolCall"}}},UserMessage:{optional:["subagentRunId","name","encryptedValue","metadata"],fields:{content:{array:"ContentPart"}}},ToolMessage:{optional:["subagentRunId","error","encryptedValue","metadata"],fields:{content:{array:"ContentPart"}}},ActivityMessage:{optional:["subagentRunId","metadata"],fields:{}},ReasoningMessage:{optional:["subagentRunId","encryptedValue","metadata"],fields:{}},Message:{discriminator:"role",variants:{developer:"DeveloperMessage",system:"SystemMessage",assistant:"AssistantMessage",user:"UserMessage",tool:"ToolMessage",activity:"ActivityMessage",reasoning:"ReasoningMessage"}},MessagesSnapshotEvent:{optional:["timestamp","rawEvent","metadata"],fields:{messages:{array:"Message"}}},ActivitySnapshotEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","replace"],fields:{}},ActivityDeltaEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{patch:{array:"JsonPatchOperation"}}},RawEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","source"],fields:{}},CustomEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},Tool:{optional:["parameters","metadata"],fields:{}},Context:{optional:[],fields:{}},ResumeEntry:{optional:["payload","metadata"],fields:{}},RunAgentInput:{optional:["protocolVersion","parentRunId","state","tools","context","forwardedProps","resume"],fields:{messages:{array:"Message"},tools:{array:"Tool"},context:{array:"Context"},resume:{array:"ResumeEntry"}}},RunStartedEvent:{optional:["timestamp","rawEvent","metadata","protocolVersion","parentRunId","input"],fields:{input:"RunAgentInput"}},RunFinishedSuccessOutcome:{optional:["pendingToolCallIds"],fields:{}},Interrupt:{optional:["subagentRunId","message","toolCallId","responseSchema","expiresAt","metadata"],fields:{}},RunFinishedInterruptOutcome:{optional:[],fields:{interrupts:{array:"Interrupt"}}},RunFinishedCancelledOutcome:{optional:[],fields:{}},RunFinishedOutcome:{discriminator:"type",variants:{success:"RunFinishedSuccessOutcome",interrupt:"RunFinishedInterruptOutcome",cancelled:"RunFinishedCancelledOutcome"}},TokenUsage:{optional:["provider","model","inputTokens","outputTokens","totalTokens","reasoningTokens","cachedInputTokens","cacheWriteInputTokens"],fields:{}},RunFinishedEvent:{optional:["timestamp","rawEvent","metadata","result","outcome","usage"],fields:{outcome:"RunFinishedOutcome",usage:{array:"TokenUsage"}}},RunErrorEvent:{optional:["timestamp","rawEvent","metadata","code","usage"],fields:{usage:{array:"TokenUsage"}}},StepStartedEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},StepFinishedEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningStartEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningMessageStartEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningMessageContentEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningMessageEndEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningMessageChunkEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","messageId","delta"],fields:{}},ReasoningEndEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningEncryptedValueEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},SubagentStartedEvent:{optional:["timestamp","rawEvent","metadata","description","parentSubagentRunId","parentToolCallId","parentMessageId"],fields:{}},SubagentFinishedSuccessOutcome:{optional:[],fields:{}},SubagentFinishedSuspendedOutcome:{optional:["interruptIds"],fields:{}},SubagentFinishedOutcome:{discriminator:"type",variants:{success:"SubagentFinishedSuccessOutcome",suspended:"SubagentFinishedSuspendedOutcome"}},SubagentFinishedEvent:{optional:["timestamp","rawEvent","metadata","result","outcome"],fields:{outcome:"SubagentFinishedOutcome"}},SubagentErrorEvent:{optional:["timestamp","rawEvent","metadata","code"],fields:{}},Event:{discriminator:"type",variants:{TEXT_MESSAGE_START:"TextMessageStartEvent",TEXT_MESSAGE_CONTENT:"TextMessageContentEvent",TEXT_MESSAGE_END:"TextMessageEndEvent",TEXT_MESSAGE_CHUNK:"TextMessageChunkEvent",TOOL_CALL_START:"ToolCallStartEvent",TOOL_CALL_ARGS:"ToolCallArgsEvent",TOOL_CALL_END:"ToolCallEndEvent",TOOL_CALL_CHUNK:"ToolCallChunkEvent",TOOL_CALL_RESULT:"ToolCallResultEvent",STATE_SNAPSHOT:"StateSnapshotEvent",STATE_DELTA:"StateDeltaEvent",MESSAGES_SNAPSHOT:"MessagesSnapshotEvent",ACTIVITY_SNAPSHOT:"ActivitySnapshotEvent",ACTIVITY_DELTA:"ActivityDeltaEvent",RAW:"RawEvent",CUSTOM:"CustomEvent",RUN_STARTED:"RunStartedEvent",RUN_FINISHED:"RunFinishedEvent",RUN_ERROR:"RunErrorEvent",STEP_STARTED:"StepStartedEvent",STEP_FINISHED:"StepFinishedEvent",REASONING_START:"ReasoningStartEvent",REASONING_MESSAGE_START:"ReasoningMessageStartEvent",REASONING_MESSAGE_CONTENT:"ReasoningMessageContentEvent",REASONING_MESSAGE_END:"ReasoningMessageEndEvent",REASONING_MESSAGE_CHUNK:"ReasoningMessageChunkEvent",REASONING_END:"ReasoningEndEvent",REASONING_ENCRYPTED_VALUE:"ReasoningEncryptedValueEvent",SUBAGENT_STARTED:"SubagentStartedEvent",SUBAGENT_FINISHED:"SubagentFinishedEvent",SUBAGENT_ERROR:"SubagentErrorEvent"}},SubagentInfo:{optional:["description"],fields:{}},IdentityCapabilities:{optional:["name","type","description","version","provider","documentationUrl","metadata"],fields:{}},TransportCapabilities:{optional:["streaming","websocket","httpBinary","pushNotifications","resumable"],fields:{}},ToolsCapabilities:{optional:["supported","items","parallelCalls","clientProvided"],fields:{items:{array:"Tool"}}},OutputCapabilities:{optional:["structuredOutput","supportedMimeTypes"],fields:{}},StateCapabilities:{optional:["snapshots","deltas","memory","persistentState"],fields:{}},MultiAgentCapabilities:{optional:["supported","delegation","handoffs","subagents"],fields:{subagents:{array:"SubagentInfo"}}},ReasoningCapabilities:{optional:["supported","streaming","encrypted"],fields:{}},MultimodalInputCapabilities:{optional:["image","audio","video","pdf","file"],fields:{}},MultimodalOutputCapabilities:{optional:["image","audio"],fields:{}},MultimodalCapabilities:{optional:["input","output"],fields:{input:"MultimodalInputCapabilities",output:"MultimodalOutputCapabilities"}},ExecutionCapabilities:{optional:["codeExecution","sandboxed","maxIterations","maxExecutionTime"],fields:{}},HumanInTheLoopCapabilities:{optional:["supported","approvals","interventions","feedback","interrupts","approveWithEdits"],fields:{}},AgentCapabilities:{optional:["identity","transport","tools","output","state","multiAgent","reasoning","multimodal","execution","humanInTheLoop","custom"],fields:{identity:"IdentityCapabilities",transport:"TransportCapabilities",tools:"ToolsCapabilities",output:"OutputCapabilities",state:"StateCapabilities",multiAgent:"MultiAgentCapabilities",reasoning:"ReasoningCapabilities",multimodal:"MultimodalCapabilities",execution:"ExecutionCapabilities",humanInTheLoop:"HumanInTheLoopCapabilities"}}};function Rr(e,t){if(typeof t=="string")return Rr(e,ox[t]);if("array"in t){if(!Array.isArray(e))return e;let o=e.map(i=>Rr(i,t.array));return o.every((i,a)=>i===e[a])?e:o}if(typeof e!="object"||e===null||Array.isArray(e))return e;let n=e;if("discriminator"in t){let o=n[t.discriminator];return typeof o=="string"&&Object.prototype.hasOwnProperty.call(t.variants,o)?Rr(e,t.variants[o]):e}let r=n;for(let o of t.optional)Object.prototype.hasOwnProperty.call(n,o)&&n[o]===null&&(r===n&&(r={...n}),delete r[o]);for(let[o,i]of Object.entries(t.fields)){if(!Object.prototype.hasOwnProperty.call(r,o))continue;let a=Rr(r[o],i);a!==r[o]&&(r===n&&(r={...n}),r[o]=a)}return r}function Yl(e,t){return Rr(e,t)}var j=class extends Error{constructor(e){super(e)}},Xl=class extends j{constructor(){super("Connect not implemented. This method is not supported by the current agent.")}};function Zp(e,t){return t===void 0?e:e===void 0?{...t}:{...e,...t}}function Zn(e){return e===void 0?"":typeof e=="string"?e:e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Vp(e){return Array.isArray(e)&&e.some(t=>t.type!=="text")}var Kl={};vl(Kl,{JsonPatchError:()=>Te,_areEquals:()=>Or,applyOperation:()=>on,applyPatch:()=>ti,applyReducer:()=>cx,deepClone:()=>sx,getValueByPointer:()=>Qo,validate:()=>Wp,validator:()=>ei});var ix=(function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,o){r.__proto__=o}||function(r,o){for(var i in o)o.hasOwnProperty(i)&&(r[i]=o[i])},e(t,n)};return function(t,n){e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})(),ax=Object.prototype.hasOwnProperty;function Xo(e,t){return ax.call(e,t)}function Ko(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n<t.length;n++)t[n]=""+n;return t}if(Object.keys)return Object.keys(e);var r=[];for(var o in e)Xo(e,o)&&r.push(o);return r}function De(e){switch(typeof e){case"object":return JSON.parse(JSON.stringify(e));case"undefined":return null;default:return e}}function Jo(e){for(var t=0,n=e.length,r;t<n;){if(r=e.charCodeAt(t),r>=48&&r<=57){t++;continue}return!1}return!0}function bt(e){return e.indexOf("/")===-1&&e.indexOf("~")===-1?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function Cr(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Yo(e){if(e===void 0)return!0;if(e){if(Array.isArray(e)){for(var t=0,n=e.length;t<n;t++)if(Yo(e[t]))return!0}else if(typeof e=="object"){for(var r=Ko(e),o=r.length,i=0;i<o;i++)if(Yo(e[r[i]]))return!0}}return!1}function jp(e,t){var n=[e];for(var r in t){var o=typeof t[r]=="object"?JSON.stringify(t[r],null,2):t[r];typeof o<"u"&&n.push(r+": "+o)}return n.join(`
|
|
2
|
-
`)}var Nr=(function(e){ix(t,e);function t(n,r,o,i,a){var s=this.constructor,l=e.call(this,jp(n,{name:r,index:o,operation:i,tree:a}))||this;return l.name=r,l.index=o,l.operation=i,l.tree=a,Object.setPrototypeOf(l,s.prototype),l.message=jp(n,{name:r,index:o,operation:i,tree:a}),l}return t})(Error);var Te=Nr,sx=De,Vn={add:function(e,t,n){return e[t]=this.value,{newDocument:n}},remove:function(e,t,n){var r=e[t];return delete e[t],{newDocument:n,removed:r}},replace:function(e,t,n){var r=e[t];return e[t]=this.value,{newDocument:n,removed:r}},move:function(e,t,n){var r=Qo(n,this.path);r&&(r=De(r));var o=on(n,{op:"remove",path:this.from}).removed;return on(n,{op:"add",path:this.path,value:o}),{newDocument:n,removed:r}},copy:function(e,t,n){var r=Qo(n,this.from);return on(n,{op:"add",path:this.path,value:De(r)}),{newDocument:n}},test:function(e,t,n){return{newDocument:n,test:Or(e[t],this.value)}},_get:function(e,t,n){return this.value=e[t],{newDocument:n}}},lx={add:function(e,t,n){return Jo(t)?e.splice(t,0,this.value):e[t]=this.value,{newDocument:n,index:t}},remove:function(e,t,n){var r=e.splice(t,1);return{newDocument:n,removed:r[0]}},replace:function(e,t,n){var r=e[t];return e[t]=this.value,{newDocument:n,removed:r}},move:Vn.move,copy:Vn.copy,test:Vn.test,_get:Vn._get};function Qo(e,t){if(t=="")return e;var n={op:"_get",path:t};return on(e,n),n.value}function on(e,t,n,r,o,i){if(n===void 0&&(n=!1),r===void 0&&(r=!0),o===void 0&&(o=!0),i===void 0&&(i=0),n&&(typeof n=="function"?n(t,0,e,t.path):ei(t,0)),t.path===""){var a={newDocument:e};if(t.op==="add")return a.newDocument=t.value,a;if(t.op==="replace")return a.newDocument=t.value,a.removed=e,a;if(t.op==="move"||t.op==="copy")return a.newDocument=Qo(e,t.from),t.op==="move"&&(a.removed=e),a;if(t.op==="test"){if(a.test=Or(e,t.value),a.test===!1)throw new Te("Test operation failed","TEST_OPERATION_FAILED",i,t,e);return a.newDocument=e,a}else{if(t.op==="remove")return a.removed=e,a.newDocument=null,a;if(t.op==="_get")return t.value=e,a;if(n)throw new Te("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",i,t,e);return a}}else{r||(e=De(e));var s=t.path||"",l=s.split("/"),c=e,u=1,f=l.length,m=void 0,p=void 0,h=void 0;for(typeof n=="function"?h=n:h=ei;;){if(p=l[u],p&&p.indexOf("~")!=-1&&(p=Cr(p)),o&&(p=="__proto__"||p=="prototype"&&u>0&&l[u-1]=="constructor"))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(n&&m===void 0&&(c[p]===void 0?m=l.slice(0,u).join("/"):u==f-1&&(m=t.path),m!==void 0&&h(t,0,e,m)),u++,Array.isArray(c)){if(p==="-")p=c.length;else{if(n&&!Jo(p))throw new Te("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",i,t,e);Jo(p)&&(p=~~p)}if(u>=f){if(n&&t.op==="add"&&p>c.length)throw new Te("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",i,t,e);var a=lx[t.op].call(t,c,p,e);if(a.test===!1)throw new Te("Test operation failed","TEST_OPERATION_FAILED",i,t,e);return a}}else if(u>=f){var a=Vn[t.op].call(t,c,p,e);if(a.test===!1)throw new Te("Test operation failed","TEST_OPERATION_FAILED",i,t,e);return a}if(c=c[p],n&&u<f&&(!c||typeof c!="object"))throw new Te("Cannot perform operation at the desired path","OPERATION_PATH_UNRESOLVABLE",i,t,e)}}}function ti(e,t,n,r,o){if(r===void 0&&(r=!0),o===void 0&&(o=!0),n&&!Array.isArray(t))throw new Te("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");r||(e=De(e));for(var i=new Array(t.length),a=0,s=t.length;a<s;a++)i[a]=on(e,t[a],n,!0,o,a),e=i[a].newDocument;return i.newDocument=e,i}function cx(e,t,n){var r=on(e,t);if(r.test===!1)throw new Te("Test operation failed","TEST_OPERATION_FAILED",n,t,e);return r.newDocument}function ei(e,t,n,r){if(typeof e!="object"||e===null||Array.isArray(e))throw new Te("Operation is not an object","OPERATION_NOT_AN_OBJECT",t,e,n);if(Vn[e.op]){if(typeof e.path!="string")throw new Te("Operation `path` property is not a string","OPERATION_PATH_INVALID",t,e,n);if(e.path.indexOf("/")!==0&&e.path.length>0)throw new Te('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",t,e,n);if((e.op==="move"||e.op==="copy")&&typeof e.from!="string")throw new Te("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",t,e,n);if((e.op==="add"||e.op==="replace"||e.op==="test")&&e.value===void 0)throw new Te("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",t,e,n);if((e.op==="add"||e.op==="replace"||e.op==="test")&&Yo(e.value))throw new Te("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",t,e,n);if(n){if(e.op=="add"){var o=e.path.split("/").length,i=r.split("/").length;if(o!==i+1&&o!==i)throw new Te("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",t,e,n)}else if(e.op==="replace"||e.op==="remove"||e.op==="_get"){if(e.path!==r)throw new Te("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",t,e,n)}else if(e.op==="move"||e.op==="copy"){var a={op:"_get",path:e.from,value:void 0},s=Wp([a],n);if(s&&s.name==="OPERATION_PATH_UNRESOLVABLE")throw new Te("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",t,e,n)}}}else throw new Te("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",t,e,n)}function Wp(e,t,n){try{if(!Array.isArray(e))throw new Te("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(t)ti(De(t),De(e),n||!0);else{n=n||ei;for(var r=0;r<e.length;r++)n(e[r],r,t,void 0)}}catch(o){if(o instanceof Te)return o;throw o}}function Or(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){var n=Array.isArray(e),r=Array.isArray(t),o,i,a;if(n&&r){if(i=e.length,i!=t.length)return!1;for(o=i;o--!==0;)if(!Or(e[o],t[o]))return!1;return!0}if(n!=r)return!1;var s=Object.keys(e);if(i=s.length,i!==Object.keys(t).length)return!1;for(o=i;o--!==0;)if(!t.hasOwnProperty(s[o]))return!1;for(o=i;o--!==0;)if(a=s[o],!Or(e[a],t[a]))return!1;return!0}return e!==e&&t!==t}var tc={};vl(tc,{compare:()=>vx,generate:()=>Jl,observe:()=>gx,unobserve:()=>mx});var Ql=new WeakMap,ux=(function(){function e(t){this.observers=new Map,this.obj=t}return e})(),dx=(function(){function e(t,n){this.callback=t,this.observer=n}return e})();function px(e){return Ql.get(e)}function hx(e,t){return e.observers.get(t)}function fx(e,t){e.observers.delete(t.callback)}function mx(e,t){t.unobserve()}function gx(e,t){var n=[],r,o=px(e);if(!o)o=new ux(e),Ql.set(e,o);else{var i=hx(o,t);r=i&&i.observer}if(r)return r;if(r={},o.value=De(e),t){r.callback=t,r.next=null;var a=function(){Jl(r)},s=function(){clearTimeout(r.next),r.next=setTimeout(a)};typeof window<"u"&&(window.addEventListener("mouseup",s),window.addEventListener("keyup",s),window.addEventListener("mousedown",s),window.addEventListener("keydown",s),window.addEventListener("change",s))}return r.patches=n,r.object=e,r.unobserve=function(){Jl(r),clearTimeout(r.next),fx(o,r),typeof window<"u"&&(window.removeEventListener("mouseup",s),window.removeEventListener("keyup",s),window.removeEventListener("mousedown",s),window.removeEventListener("keydown",s),window.removeEventListener("change",s))},o.observers.set(t,new dx(t,r)),r}function Jl(e,t){t===void 0&&(t=!1);var n=Ql.get(e.object);ec(n.value,e.object,e.patches,"",t),e.patches.length&&ti(n.value,e.patches);var r=e.patches;return r.length>0&&(e.patches=[],e.callback&&e.callback(r)),r}function ec(e,t,n,r,o){if(t!==e){typeof t.toJSON=="function"&&(t=t.toJSON());for(var i=Ko(t),a=Ko(e),s=!1,l=!1,c=a.length-1;c>=0;c--){var u=a[c],f=e[u];if(Xo(t,u)&&!(t[u]===void 0&&f!==void 0&&Array.isArray(t)===!1)){var m=t[u];typeof f=="object"&&f!=null&&typeof m=="object"&&m!=null&&Array.isArray(f)===Array.isArray(m)?ec(f,m,n,r+"/"+bt(u),o):f!==m&&(s=!0,o&&n.push({op:"test",path:r+"/"+bt(u),value:De(f)}),n.push({op:"replace",path:r+"/"+bt(u),value:De(m)}))}else Array.isArray(e)===Array.isArray(t)?(o&&n.push({op:"test",path:r+"/"+bt(u),value:De(f)}),n.push({op:"remove",path:r+"/"+bt(u)}),l=!0):(o&&n.push({op:"test",path:r,value:e}),n.push({op:"replace",path:r,value:t}),s=!0)}if(!(!l&&i.length==a.length))for(var c=0;c<i.length;c++){var u=i[c];!Xo(e,u)&&t[u]!==void 0&&n.push({op:"add",path:r+"/"+bt(u),value:De(t[u])})}}}function vx(e,t,n){n===void 0&&(n=!1);var r=[];return ec(e,t,r,"",n),r}var ni=Object.assign({},Kl,tc,{JsonPatchError:Nr,deepClone:De,escapePathComponent:bt,unescapePathComponent:Cr});var nc=function(e,t){return nc=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[o]=r[o])},nc(e,t)};function yt(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");nc(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function qp(e,t,n,r){function o(i){return i instanceof n?i:new n(function(a){a(i)})}return new(n||(n=Promise))(function(i,a){function s(u){try{c(r.next(u))}catch(f){a(f)}}function l(u){try{c(r.throw(u))}catch(f){a(f)}}function c(u){u.done?i(u.value):o(u.value).then(s,l)}c((r=r.apply(e,t||[])).next())})}function ri(e,t){var n={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,o,i,a=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function s(c){return function(u){return l([c,u])}}function l(c){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(n=0)),n;)try{if(r=1,o&&(i=c[0]&2?o.return:c[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,c[1])).done)return i;switch(o=0,i&&(c=[c[0]&2,i.value]),c[0]){case 0:case 1:i=c;break;case 4:return n.label++,{value:c[1],done:!1};case 5:n.label++,o=c[1],c=[0];continue;case 7:c=n.ops.pop(),n.trys.pop();continue;default:if(i=n.trys,!(i=i.length>0&&i[i.length-1])&&(c[0]===6||c[0]===2)){n=0;continue}if(c[0]===3&&(!i||c[1]>i[0]&&c[1]<i[3])){n.label=c[1];break}if(c[0]===6&&n.label<i[1]){n.label=i[1],i=c;break}if(i&&n.label<i[2]){n.label=i[2],n.ops.push(c);break}i[2]&&n.ops.pop(),n.trys.pop();continue}c=t.call(e,n)}catch(u){c=[6,u],o=0}finally{r=i=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function Rt(e){var t=typeof Symbol=="function"&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function wt(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),o,i=[],a;try{for(;(t===void 0||t-- >0)&&!(o=r.next()).done;)i.push(o.value)}catch(s){a={error:s}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(a)throw a.error}}return i}function Et(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,i;r<o;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))}function an(e){return this instanceof an?(this.v=e,this):new an(e)}function Yp(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",a),o[Symbol.asyncIterator]=function(){return this},o;function a(p){return function(h){return Promise.resolve(h).then(p,f)}}function s(p,h){r[p]&&(o[p]=function(E){return new Promise(function(g,_){i.push([p,E,g,_])>1||l(p,E)})},h&&(o[p]=h(o[p])))}function l(p,h){try{c(r[p](h))}catch(E){m(i[0][3],E)}}function c(p){p.value instanceof an?Promise.resolve(p.value.v).then(u,f):m(i[0][2],p)}function u(p){l("next",p)}function f(p){l("throw",p)}function m(p,h){p(h),i.shift(),i.length&&l(i[0][0],i[0][1])}}function Xp(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof Rt=="function"?Rt(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(i){n[i]=e[i]&&function(a){return new Promise(function(s,l){a=e[i](a),o(s,l,a.done,a.value)})}}function o(i,a,s,l){Promise.resolve(l).then(function(c){i({value:c,done:s})},a)}}function J(e){return typeof e=="function"}function jn(e){var t=function(r){Error.call(r),r.stack=new Error().stack},n=e(t);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var oi=jn(function(e){return function(n){e(this),this.message=n?n.length+` errors occurred during unsubscription:
|
|
1
|
+
var UE=Object.defineProperty;var _l=(t,e)=>{for(var n in e)UE(t,n,{get:e[n],enumerable:!0})};var Bo="ag-ui-chat",Sl="ag-ui-submit",Tl="ag-ui-toggle",Al="ag-ui-unread",kl="ag-ui-state",Il="ag-ui-attachments",Rl="ag-ui-run-finished",Cl="ag-ui-thread",Nl="ag-ui-custom",Ol="ag-ui-invalidate",Pl="ag-ui-feedback",Ml="suggestions",Ll="ag_ui.invalidate",Ip="ag_ui.subagent",yt={STARTED:"started",TOOL_CALL:"tool_call",TOOL_RESULT:"tool_result",FINISHED:"finished",FAILED:"failed"},Ve={USER:"user",ASSISTANT:"assistant"},Tr="x-destructive",Zo="x-confirm",Pe="x-summary",Ar="x-navigates",Vo="read_page",Bn=10,rn={COPY:"copy",RETRY:"retry",FEEDBACK:"feedback"},K={PENDING:"pending",DEFERRED:"deferred",DONE:"done",ERROR:"error",DECLINED:"declined",INTERRUPTED:"interrupted"},je={SUCCESS:"success",FAILED:"failed",DENIED:"denied",INTERRUPTED:"interrupted"},Xe={UPLOADING:"uploading",READY:"ready",ERROR:"error"},zl=10*1024*1024,Ct={GROUPED:"grouped",INLINE:"inline",MINIMAL:"minimal",COMPACT:"compact",FULL:"full"},Dl="compaction",$l="load_capability",Rp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19.5V5m-6.5 6.5L12 5l6.5 6.5"/></svg>',Cp='<svg class="glyph glyph--solid" viewBox="0 0 24 24" aria-hidden="true"><rect x="7" y="7" width="10" height="10" rx="2.5"/></svg>',Np='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M17 8.5V15a5 5 0 0 1-10 0V7a3 3 0 0 1 6 0v7.5a1 1 0 0 1-2 0V8.5"/></svg>',Op='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 4a3 3 0 0 1 3 3v5a3 3 0 0 1-6 0V7a3 3 0 0 1 3-3z"/><path d="M5 11v1a7 7 0 0 0 14 0v-1"/><path d="M12 19v3"/></svg>',Pp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 14.5A8.5 8.5 0 0 1 9.5 4a8.5 8.5 0 1 0 10.5 10.5z"/></svg>',Mp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>',Lp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 5.5A2.5 2.5 0 0 1 6.5 3h11A2.5 2.5 0 0 1 20 5.5v8a2.5 2.5 0 0 1-2.5 2.5H9l-5 4z"/></svg>',zp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V6a2 2 0 0 1 2-2h8"/></svg>',Dp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 12a8 8 0 1 1-2.5-5.8"/><path d="M20 4v4h-4"/></svg>',$p='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M7 10v10H4V10z"/><path d="M7 10l4.5-7a2 2 0 0 1 3.4 2L13.5 9H19a2 2 0 0 1 2 2.3l-1.1 6.4A2 2 0 0 1 17.9 20H7"/></svg>',Up='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M17 14V4h3v10z"/><path d="M17 14l-4.5 7a2 2 0 0 1-3.4-2l1.4-4H5a2 2 0 0 1-2-2.3l1.1-6.4A2 2 0 0 1 6.1 4H17"/></svg>',Hp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/></svg>',Fp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><rect x="3.5" y="4.5" width="17" height="15" rx="2.5"/><circle cx="9" cy="10" r="1.5"/><path d="M4.5 17.5 9 13.5l3.5 3 3-2.5 4.5 4"/></svg>',Gp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><rect class="glyph--solid" x="7.5" y="13.5" width="9" height="4.5" rx="1"/></svg>',Bp='<svg class="glyph" viewBox="0 0 24 24" aria-hidden="true"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><path d="M8.5 13.5h7M8.5 17h4.5"/></svg>',jo="chart",on=24,Zp=150,Vp=2147483001,Wo=5e3,lt=8;var HE=/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;function re(t,e){return t.replace(HE,(n,r)=>Object.hasOwn(e,r)?String(e[r]):n)}var FE=/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;function jp(t,e){let n=[];return{text:t.replace(FE,(o,i)=>{let a=e[i];return a==null||a===""?(n.includes(i)||n.push(i),o):String(a)}),missing:n}}function GE(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.name=="string"&&typeof e.title=="string"&&(e.prompt===void 0||typeof e.prompt=="string")}function Ul(t){return Array.isArray(t)?t.filter(GE):[]}var qo=class{#e;#t=[];#n=[];#o=[];constructor(e){this.#e=e}setClientSkills(e){this.#o=e,this.#i()}init(){this.#e.menu.enableChips(this.#e.flag("data-prompt-chips")),this.#e.menu.enableSlash(this.#e.flag("data-slash-commands")),this.#n=this.#r(),this.#i()}async fetch(){let e=this.#e.element.getAttribute("data-skills-url");if(e!==null)try{let n=await fetch(e,this.#e.fetchInit(e));this.#t=Ul(await n.json()),this.#i()}catch{}}apply(e){let{input:n,hint:r}=this.#e;if(e.prompt===void 0){r.hidden=!0,this.#e.send(`/${e.name}`);return}let{text:o,missing:i}=jp(e.prompt,this.#e.context());if(i.length>0){r.textContent=re(this.#e.strings().skillNeeds,{title:e.title,fields:i.join(", ")}),r.hidden=!1,n.value=o,this.#e.autoGrow(),n.focus(),this.#a(o);return}if(r.hidden=!0,n.value=o,this.#e.autoGrow(),e.sendImmediately===!1){n.focus();return}this.#e.submit()}#r(){return Ul(this.#e.readJsonAttribute("data-skills"))}#i(){let e=new Map;for(let n of[...this.#t,...this.#n,...this.#o])e.set(n.name,n);this.#e.menu.setSkills([...e.values()])}#a(e){let n=e.indexOf("{");this.#e.input.setSelectionRange(n,e.indexOf("}",n)+1)}};var Yo=["top-left","top-right","bottom-left","bottom-right"];function Wp(t){return Yo.includes(t)}function Hl(t){return[{name:"read_chat_surface",description:"Describe the chat panel you are speaking from: its placement, whether it is collapsed, whether it can be moved, and the box it occupies. Read this before moving or minimising yourself, since a full-screen panel has nowhere to move to. Read-only.",parameters:{type:"object",properties:{},required:[],[Pe]:"Read the chat's own position"},handler:()=>t.describeSurface()},{name:"move_chat",description:"Move your own panel to a corner, to uncover something the user needs to see. `corner` is top-left, top-right, bottom-left or bottom-right. Answers `moved: false` with a reason when the placement owns its position or the panel fills the screen; check `read_chat_surface` first, and prefer minimise_chat when there is nowhere to move to.",parameters:{type:"object",properties:{corner:{type:"string",enum:[...Yo]}},required:["corner"],[Pe]:"Move the chat out of the way"},handler:e=>{let n=String(e.corner??""),r=t.describeSurface();return Wp(n)?r.movable?{moved:t.moveTo(n,{announce:!0}),corner:n}:{moved:!1,reason:r.fullBleed?"the panel fills the screen, so there is nowhere to move it to":r.draggable===!1?"this page has turned off moving the panel":`the "${r.placement??""}" placement owns the panel's position`,suggestion:r.collapsible?"minimise_chat":null}:{moved:!1,reason:`"${n}" is not a corner; use one of ${Yo.join(", ")}`}}},{name:"minimise_chat",description:"Collapse your own panel to its launcher, so the user can see the whole page. The launcher stays visible and reopens it. Answers `minimised: false` when the placement has no collapsed state, which is the case for a full-page chat.",parameters:{type:"object",properties:{},required:[],[Pe]:"Minimise the chat"},handler:()=>t.describeSurface().collapsible?(t.setCollapsed(!0,{announce:!0}),{minimised:!0}):{minimised:!1,reason:"this placement has no collapsed state, so there is no launcher to return to"}},{name:"restore_chat",description:"Open your own panel again after minimising it.",parameters:{type:"object",properties:{},required:[],[Pe]:"Restore the chat"},handler:()=>(t.setCollapsed(!1),{restored:!0})}]}var kr=class{#e=new Map;register(e){this.#e.set(e.name,e)}has(e){return this.#e.has(e)}get(e){let n=this.#e.get(e);if(n===void 0)throw new Error(`tool "${e}" is not registered`);return n}tools(){return[...this.#e.values()].map(e=>({name:e.name,description:e.description,parameters:e.parameters}))}};var Fl=new Set,Zn=class{#e;constructor(e){this.#e=e}join(){Fl.add(this.#e)}leave(){Fl.delete(this.#e)}static latest(){let e=null;for(let n of Fl)e=n;return e}};var qp="--ag-ui-highlight-ring-color",BE="--ag-ui-accent",ZE="--_accent",VE="#4f46e5";function an(t,e){let n=Gl(t,qp);if(n!=="")return n;let r=e??Zn.latest(),o=r===null?"":Yp(r,qp);if(o!=="")return o;let i=Gl(t,BE);if(i!=="")return i;let a=r===null?"":Yp(r,ZE);return a===""?VE:a}function Gl(t,e){return window.getComputedStyle(t).getPropertyValue(e).trim()}function Yp(t,e){let n=Gl(t,e),r=t.shadowRoot;if(n===""||r===null)return n;let o=document.createElement("span");if(o.hidden=!0,o.style.color=n,o.style.color==="")return"";r.appendChild(o);let i=window.getComputedStyle(o).color;return o.remove(),i}function Ir(t,e,n){let r=window.getComputedStyle(t).getPropertyValue(e).trim();return r===""?n:r}var jE=4;function Bl(t,e={}){let n=document.createElement("div");n.setAttribute("data-ag-ui-highlight",""),n.setAttribute("aria-hidden","true"),n.style.cssText=["position: fixed","inset: 0","pointer-events: none",`z-index: ${Ir(t,"--ag-ui-highlight-z-index",String(Vp))}`].join(";");let r=document.createElement("div"),o=document.createElement("div");n.className="ag-ui-highlight",r.className="ag-ui-highlight-scrim",o.className="ag-ui-highlight-ring",e.scrim===!0&&n.append(r),n.append(o);let i=e.ringWidth??Number.parseFloat(Ir(t,"--ag-ui-highlight-ring-width","3")),a=e.flowMs??Number.parseFloat(Ir(t,"--ag-ui-highlight-flow-ms","2400")),s=()=>{let u=t.getBoundingClientRect(),f=e.padding??jE,m=e.radius??Number.parseFloat(getComputedStyle(t).borderRadius),p=u.left-f,h=u.top-f,x=u.width+f*2,g=u.height+f*2;e.scrim===!0&&(r.style.cssText=["position: absolute","inset: 0",`background: ${Ir(t,"--ag-ui-highlight-scrim","rgba(15, 15, 25, 0.45)")}`,`clip-path: path(evenodd, '${YE(p,h,x,g,m+f)}')`].join(";")),o.style.cssText=["position: absolute",`left: ${p}px`,`top: ${h}px`,`width: ${x}px`,`height: ${g}px`,`border-radius: ${m+f}px`,`border: ${i}px solid transparent`,"box-sizing: border-box",qE(t,e)].join(";")};s();let c=null;e.gradient===!0&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches&&(c=o.animate([{backgroundPosition:"100% 0"},{backgroundPosition:"-100% 0"}],{duration:a,iterations:Number.POSITIVE_INFINITY,easing:"linear"}));let l={capture:!0,passive:!0};return window.addEventListener("scroll",s,l),window.addEventListener("resize",s,l),document.body.appendChild(n),()=>{window.removeEventListener("scroll",s,l),window.removeEventListener("resize",s,l),c?.cancel(),n.remove()}}function WE(t){return t===void 0?null:CSS.supports("color",t)?t:null}function qE(t,e){let n=WE(e.color)??an(t,e.chat);if(e.gradient!==!0)return`border-color: ${n}`;let r=Ir(t,"--ag-ui-highlight-gradient",`linear-gradient(115deg, transparent 20%, ${n} 50%, transparent 80%)`),o="linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)";return[`background-image: ${r}`,"background-origin: border-box","background-size: 300% 100%",`-webkit-mask: ${o}`,`mask: ${o}`,"-webkit-mask-composite: xor","mask-composite: exclude","background-position: 50% 0"].join(";")}function YE(t,e,n,r,o){let i=Math.max(0,Math.min(o,n/2,r/2)),a=t+n,s=e+r,c=`M 0 0 H ${window.innerWidth} V ${window.innerHeight} H 0 Z`,l=[`M ${t+i} ${e}`,`H ${a-i}`,`A ${i} ${i} 0 0 1 ${a} ${e+i}`,`V ${s-i}`,`A ${i} ${i} 0 0 1 ${a-i} ${s}`,`H ${t+i}`,`A ${i} ${i} 0 0 1 ${t} ${s-i}`,`V ${e+i}`,`A ${i} ${i} 0 0 1 ${t+i} ${e}`,"Z"].join(" ");return`${c} ${l}`}function Ko(t,e){return Object.getOwnPropertyDescriptor(t,e).set}var KE=Ko(HTMLInputElement.prototype,"value"),XE=Ko(HTMLTextAreaElement.prototype,"value"),JE=Ko(HTMLSelectElement.prototype,"value"),QE=Ko(HTMLInputElement.prototype,"checked");function sn(t,e){t instanceof HTMLTextAreaElement?XE.call(t,e):t instanceof HTMLSelectElement?JE.call(t,e):KE.call(t,e)}function Rr(t,e){QE.call(t,e)}function Vn(t){return new Promise(e=>{setTimeout(e,t)})}function Xo(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function Zl(t){return t<=0||Xo()?Promise.resolve():Vn(t)}function Kp(t,e){return`0 0 0 3px color-mix(in srgb, ${an(t,e)} 40%, transparent)`}async function Vl(t,e,n={}){let r=n.charDelayMs??35;sn(t,""),t.dispatchEvent(new Event("input",{bubbles:!0}));for(let o of e)sn(t,t.value+o),t.dispatchEvent(new Event("input",{bubbles:!0})),r>0&&await Vn(r);t.dispatchEvent(new Event("change",{bubbles:!0}))}async function jl(t,e={}){let n=e.highlightMs??280,r=t.style.outline,o=t.style.outlineOffset;t.style.outline=`2px solid ${an(t,e.chat)}`,t.style.outlineOffset="2px",await Vn(n),t.style.outline=r,t.style.outlineOffset=o,t.click()}var ex=600,tx=100;function Nt(t,e={}){let n=Xo();return t.scrollIntoView({block:"center",inline:"nearest",behavior:n?"auto":"smooth"}),n?Promise.resolve():new Promise(r=>{let o,i=()=>{clearTimeout(o),document.removeEventListener("scroll",a,!0),document.removeEventListener("scrollend",i,!0),r()},a=()=>{document.removeEventListener("scroll",a,!0),clearTimeout(o),o=setTimeout(i,e.settleMs??ex)};o=setTimeout(i,tx),document.addEventListener("scroll",a,!0),document.addEventListener("scrollend",i,!0)})}var nx=1200,rx=1/3;async function Xp(t,e,n){(e.focus??n)&&t.focus({preventScroll:!0});let r=e.flashMs??nx;if(r<=0)return;if(e.scrim===!0||e.gradient===!0){let l=Bl(t,{scrim:e.scrim===!0,gradient:e.gradient===!0,...e.color===void 0?{}:{color:e.color},...e.ringPadding===void 0?{}:{padding:e.ringPadding},...e.chat===void 0?{}:{chat:e.chat}});await Vn(r),l();return}let o=t.style.outline,i=t.style.outlineOffset,a=t.style.transition,s=e.color??an(t,e.chat);t.style.outline=`3px solid ${s}`,t.style.outlineOffset="2px";let c=Xo()?0:Math.round(r*rx);await Vn(r-c),c>0&&(t.style.transition=`outline-color ${c}ms ease-out`,t.style.outline="3px solid transparent",await Vn(c)),t.style.outline=o,t.style.outlineOffset=i,t.style.transition=a}function ox(t,e={}){return Xp(t,e,!1)}function Wl(t,e={}){return Xp(t,e,!0)}async function ql(t,e={}){let n=e.pressMs??140,r=t.style.transform,o=t.style.transition,i=t.style.boxShadow;t.style.transition="transform 80ms ease",t.style.transform="scale(0.96)",t.style.boxShadow=Kp(t,e.chat),await Zl(n),t.style.transform=r,t.style.transition=o,t.style.boxShadow=i,t.click()}function ix(t,e){for(let n of Array.from(t.options))if(n.value===e||n.text===e)return n;return null}async function Yl(t,e,n={}){let r=ix(t,e);if(r===null)throw new Error(`no <option> matching "${e}"`);let o=n.highlightMs??220,i=t.style.outline,a=t.style.outlineOffset;t.style.outline=`2px solid ${an(t,n.chat)}`,t.style.outlineOffset="2px",await Zl(o),sn(t,r.value),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),t.style.outline=i,t.style.outlineOffset=a}async function Kl(t,e,n={}){let r=n.flashMs??200,o=t.style.boxShadow;t.style.boxShadow=Kp(t,n.chat),await Zl(r),Rr(t,e),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),t.style.boxShadow=o}var Nr={SCROLL:"scroll",DRAG:"drag",CHAT:"chat"};function Xl(t,e){let n=[];return t.has(Nr.SCROLL)&&n.push(ax(e)),t.has(Nr.DRAG)&&n.push(sx(e)),n}function ax(t){return{name:"scroll_to",description:"Scroll a target into view. `target` is `top`, `bottom`, or a CSS selector / page-map element id. Read-only: it changes nothing on the page.",parameters:{type:"object",properties:{target:{type:"string"}},required:["target"],[Pe]:"Scroll into view"},handler:e=>{let n=String(e.target??"");if(n==="top"||n==="bottom"){let o=n==="top"?0:document.body.scrollHeight;return window.scrollTo({top:o,behavior:"smooth"}),{scrolled:!0,target:n}}let r=t(n);if(r===null)throw new Error(`no element matching "${n}"`);return Nt(r),{scrolled:!0,target:n}}}}function sx(t){return{name:"drag_and_drop",description:"Drag the `from` element onto the `to` element (CSS selectors or page-map element ids), firing the page's native drag-and-drop. Use for reordering sortable lists. The page decides what the drop commits.",parameters:{type:"object",properties:{from:{type:"string"},to:{type:"string"}},required:["from","to"],[Pe]:"Drag and drop"},handler:e=>{let n=String(e.from??""),r=String(e.to??""),o=t(n);if(o===null)throw new Error(`no element matching "${n}"`);let i=t(r);if(i===null)throw new Error(`no element matching "${r}"`);return lx(o,i),{dragged:!0,from:n,to:r}}}}function lx(t,e){let n=new DataTransfer;Cr(t,"dragstart",n),Cr(e,"dragenter",n),Cr(e,"dragover",n),Cr(e,"drop",n),Cr(t,"dragend",n)}function Cr(t,e,n){let r=new Event(e,{bubbles:!0,cancelable:!0});r.dataTransfer=n,t.dispatchEvent(r)}function Jl(t,e){return!e||t===null?[]:[{description:"page_map",value:JSON.stringify(t())}]}function Jo(t){let e=[{name:`read_${t.name}`,description:`Read the "${t.name}" state.`,parameters:{type:"object",properties:{},required:[],[Pe]:`Read ${t.name}`},handler:()=>t.read()}],n=t.write;return n!==void 0&&e.push({name:`set_${t.name}`,description:`Update the "${t.name}" state.`,parameters:{...t.schema??{type:"object"},[Tr]:!0,[Pe]:`Update ${t.name}`},handler:r=>n(r)}),e}var cx=Jo;var Jp=/:([A-Za-z_][A-Za-z0-9_]*)/g;function ux(t){return[...t.matchAll(Jp)].map(e=>e[0].slice(1))}function dx(t,e,n){let r={...n};return{path:e.replace(Jp,(i,a)=>{let s=n[a];if(s==null||String(s)==="")throw new Error(`route "${t}" requires path param "${a}"`);return delete r[a],encodeURIComponent(String(s))}),leftover:r}}function px(t,e){let n=new URLSearchParams;for(let[o,i]of Object.entries(e))n.set(o,String(i));let r=n.toString();return r===""?t:`${t}?${r}`}function Ql(t,e){return[{name:"list_routes",description:"List the routes the app can navigate to. Each route's `pathParams` names the dynamic segments to pass as `params` to `navigate_to_route`.",parameters:{type:"object",properties:{},required:[],[Pe]:"List pages"},handler:()=>t().map(n=>({...n,pathParams:ux(n.path)}))},{name:"navigate_to_route",description:"Navigate to one of the app's routes by its id, filling any dynamic `:name` path segments (and extra query params) from `params`.",parameters:{type:"object",properties:{route_id:{type:"string"},params:{type:"object"}},required:["route_id"],[Ar]:!0,[Pe]:"Navigate"},handler:n=>{let r=n.route_id,o=t().find(u=>u.id===r);if(o===void 0)throw new Error(`unknown route "${String(r)}"`);let i=n.params??{},{path:a,leftover:s}=dx(o.id,o.path,i),c=px(a,s),l=e();return l!==null?l(c):window.location.assign(c),{navigated:!0,path:c}}}]}var De=[];for(let t=0;t<256;++t)De.push((t+256).toString(16).slice(1));function Qp(t,e=0){return(De[t[e+0]]+De[t[e+1]]+De[t[e+2]]+De[t[e+3]]+"-"+De[t[e+4]]+De[t[e+5]]+"-"+De[t[e+6]]+De[t[e+7]]+"-"+De[t[e+8]]+De[t[e+9]]+"-"+De[t[e+10]]+De[t[e+11]]+De[t[e+12]]+De[t[e+13]]+De[t[e+14]]+De[t[e+15]]).toLowerCase()}var ec,hx=new Uint8Array(16);function tc(){if(!ec){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ec=crypto.getRandomValues.bind(crypto)}return ec(hx)}var fx=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),nc={randomUUID:fx};function mx(t,e,n){if(nc.randomUUID&&!e&&!t)return nc.randomUUID();t=t||{};let r=t.random??t.rng?.()??tc();if(r.length<16)throw new Error("Random bytes length must be >= 16");if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,e){if(n=n||0,n<0||n+16>e.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let o=0;o<16;++o)e[n+o]=r[o];return e}return Qp(r)}var Ft=mx;var v=(function(t){return t.TEXT_MESSAGE_START="TEXT_MESSAGE_START",t.TEXT_MESSAGE_CONTENT="TEXT_MESSAGE_CONTENT",t.TEXT_MESSAGE_END="TEXT_MESSAGE_END",t.TEXT_MESSAGE_CHUNK="TEXT_MESSAGE_CHUNK",t.TOOL_CALL_START="TOOL_CALL_START",t.TOOL_CALL_ARGS="TOOL_CALL_ARGS",t.TOOL_CALL_END="TOOL_CALL_END",t.TOOL_CALL_CHUNK="TOOL_CALL_CHUNK",t.TOOL_CALL_RESULT="TOOL_CALL_RESULT",t.STATE_SNAPSHOT="STATE_SNAPSHOT",t.STATE_DELTA="STATE_DELTA",t.MESSAGES_SNAPSHOT="MESSAGES_SNAPSHOT",t.ACTIVITY_SNAPSHOT="ACTIVITY_SNAPSHOT",t.ACTIVITY_DELTA="ACTIVITY_DELTA",t.RAW="RAW",t.CUSTOM="CUSTOM",t.RUN_STARTED="RUN_STARTED",t.RUN_FINISHED="RUN_FINISHED",t.RUN_ERROR="RUN_ERROR",t.STEP_STARTED="STEP_STARTED",t.STEP_FINISHED="STEP_FINISHED",t.REASONING_START="REASONING_START",t.REASONING_MESSAGE_START="REASONING_MESSAGE_START",t.REASONING_MESSAGE_CONTENT="REASONING_MESSAGE_CONTENT",t.REASONING_MESSAGE_END="REASONING_MESSAGE_END",t.REASONING_MESSAGE_CHUNK="REASONING_MESSAGE_CHUNK",t.REASONING_END="REASONING_END",t.REASONING_ENCRYPTED_VALUE="REASONING_ENCRYPTED_VALUE",t.SUBAGENT_STARTED="SUBAGENT_STARTED",t.SUBAGENT_FINISHED="SUBAGENT_FINISHED",t.SUBAGENT_ERROR="SUBAGENT_ERROR",t})({}),ln="1.0";var gx={TextMessageStartEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","role","name"],fields:{}},TextMessageContentEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},TextMessageEndEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},TextMessageChunkEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","messageId","role","delta","name"],fields:{}},ToolCallStartEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","parentMessageId"],fields:{}},ToolCallArgsEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ToolCallEndEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ToolCallChunkEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","toolCallId","toolCallName","parentMessageId","delta"],fields:{}},TextPart:{optional:["id","metadata"],fields:{}},DataSource:{optional:[],fields:{}},UrlSource:{optional:["mimeType"],fields:{}},FileSource:{optional:["provider","mimeType"],fields:{}},PartSource:{discriminator:"type",variants:{data:"DataSource",url:"UrlSource",file:"FileSource"}},ImagePart:{optional:["id","metadata"],fields:{source:"PartSource"}},AudioPart:{optional:["id","metadata"],fields:{source:"PartSource"}},VideoPart:{optional:["id","metadata"],fields:{source:"PartSource"}},DocumentPart:{optional:["id","metadata"],fields:{source:"PartSource"}},ContentPart:{discriminator:"type",variants:{text:"TextPart",image:"ImagePart",audio:"AudioPart",video:"VideoPart",document:"DocumentPart"}},ToolCallResultEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","role"],fields:{content:{array:"ContentPart"}}},StateSnapshotEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},AddOperation:{optional:[],fields:{}},RemoveOperation:{optional:[],fields:{}},ReplaceOperation:{optional:[],fields:{}},MoveOperation:{optional:[],fields:{}},CopyOperation:{optional:[],fields:{}},TestOperation:{optional:[],fields:{}},JsonPatchOperation:{discriminator:"op",variants:{add:"AddOperation",remove:"RemoveOperation",replace:"ReplaceOperation",move:"MoveOperation",copy:"CopyOperation",test:"TestOperation"}},StateDeltaEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{delta:{array:"JsonPatchOperation"}}},DeveloperMessage:{optional:["subagentRunId","name","encryptedValue","metadata"],fields:{}},SystemMessage:{optional:["subagentRunId","name","encryptedValue","metadata"],fields:{}},FunctionCall:{optional:[],fields:{}},ToolCall:{optional:["encryptedValue","metadata"],fields:{function:"FunctionCall"}},AssistantMessage:{optional:["subagentRunId","name","encryptedValue","metadata","content","toolCalls"],fields:{toolCalls:{array:"ToolCall"}}},UserMessage:{optional:["subagentRunId","name","encryptedValue","metadata"],fields:{content:{array:"ContentPart"}}},ToolMessage:{optional:["subagentRunId","error","encryptedValue","metadata"],fields:{content:{array:"ContentPart"}}},ActivityMessage:{optional:["subagentRunId","metadata"],fields:{}},ReasoningMessage:{optional:["subagentRunId","encryptedValue","metadata"],fields:{}},Message:{discriminator:"role",variants:{developer:"DeveloperMessage",system:"SystemMessage",assistant:"AssistantMessage",user:"UserMessage",tool:"ToolMessage",activity:"ActivityMessage",reasoning:"ReasoningMessage"}},MessagesSnapshotEvent:{optional:["timestamp","rawEvent","metadata"],fields:{messages:{array:"Message"}}},ActivitySnapshotEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","replace"],fields:{}},ActivityDeltaEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{patch:{array:"JsonPatchOperation"}}},RawEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","source"],fields:{}},CustomEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},Tool:{optional:["parameters","metadata"],fields:{}},Context:{optional:[],fields:{}},ResumeEntry:{optional:["payload","metadata"],fields:{}},RunAgentInput:{optional:["protocolVersion","parentRunId","state","tools","context","forwardedProps","resume"],fields:{messages:{array:"Message"},tools:{array:"Tool"},context:{array:"Context"},resume:{array:"ResumeEntry"}}},RunStartedEvent:{optional:["timestamp","rawEvent","metadata","protocolVersion","parentRunId","input"],fields:{input:"RunAgentInput"}},RunFinishedSuccessOutcome:{optional:["pendingToolCallIds"],fields:{}},Interrupt:{optional:["subagentRunId","message","toolCallId","responseSchema","expiresAt","metadata"],fields:{}},RunFinishedInterruptOutcome:{optional:[],fields:{interrupts:{array:"Interrupt"}}},RunFinishedCancelledOutcome:{optional:[],fields:{}},RunFinishedOutcome:{discriminator:"type",variants:{success:"RunFinishedSuccessOutcome",interrupt:"RunFinishedInterruptOutcome",cancelled:"RunFinishedCancelledOutcome"}},TokenUsage:{optional:["provider","model","inputTokens","outputTokens","totalTokens","reasoningTokens","cachedInputTokens","cacheWriteInputTokens"],fields:{}},RunFinishedEvent:{optional:["timestamp","rawEvent","metadata","result","outcome","usage"],fields:{outcome:"RunFinishedOutcome",usage:{array:"TokenUsage"}}},RunErrorEvent:{optional:["timestamp","rawEvent","metadata","code","usage"],fields:{usage:{array:"TokenUsage"}}},StepStartedEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},StepFinishedEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningStartEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningMessageStartEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningMessageContentEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningMessageEndEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningMessageChunkEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId","messageId","delta"],fields:{}},ReasoningEndEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},ReasoningEncryptedValueEvent:{optional:["timestamp","rawEvent","metadata","subagentRunId"],fields:{}},SubagentStartedEvent:{optional:["timestamp","rawEvent","metadata","description","parentSubagentRunId","parentToolCallId","parentMessageId"],fields:{}},SubagentFinishedSuccessOutcome:{optional:[],fields:{}},SubagentFinishedSuspendedOutcome:{optional:["interruptIds"],fields:{}},SubagentFinishedOutcome:{discriminator:"type",variants:{success:"SubagentFinishedSuccessOutcome",suspended:"SubagentFinishedSuspendedOutcome"}},SubagentFinishedEvent:{optional:["timestamp","rawEvent","metadata","result","outcome"],fields:{outcome:"SubagentFinishedOutcome"}},SubagentErrorEvent:{optional:["timestamp","rawEvent","metadata","code"],fields:{}},Event:{discriminator:"type",variants:{TEXT_MESSAGE_START:"TextMessageStartEvent",TEXT_MESSAGE_CONTENT:"TextMessageContentEvent",TEXT_MESSAGE_END:"TextMessageEndEvent",TEXT_MESSAGE_CHUNK:"TextMessageChunkEvent",TOOL_CALL_START:"ToolCallStartEvent",TOOL_CALL_ARGS:"ToolCallArgsEvent",TOOL_CALL_END:"ToolCallEndEvent",TOOL_CALL_CHUNK:"ToolCallChunkEvent",TOOL_CALL_RESULT:"ToolCallResultEvent",STATE_SNAPSHOT:"StateSnapshotEvent",STATE_DELTA:"StateDeltaEvent",MESSAGES_SNAPSHOT:"MessagesSnapshotEvent",ACTIVITY_SNAPSHOT:"ActivitySnapshotEvent",ACTIVITY_DELTA:"ActivityDeltaEvent",RAW:"RawEvent",CUSTOM:"CustomEvent",RUN_STARTED:"RunStartedEvent",RUN_FINISHED:"RunFinishedEvent",RUN_ERROR:"RunErrorEvent",STEP_STARTED:"StepStartedEvent",STEP_FINISHED:"StepFinishedEvent",REASONING_START:"ReasoningStartEvent",REASONING_MESSAGE_START:"ReasoningMessageStartEvent",REASONING_MESSAGE_CONTENT:"ReasoningMessageContentEvent",REASONING_MESSAGE_END:"ReasoningMessageEndEvent",REASONING_MESSAGE_CHUNK:"ReasoningMessageChunkEvent",REASONING_END:"ReasoningEndEvent",REASONING_ENCRYPTED_VALUE:"ReasoningEncryptedValueEvent",SUBAGENT_STARTED:"SubagentStartedEvent",SUBAGENT_FINISHED:"SubagentFinishedEvent",SUBAGENT_ERROR:"SubagentErrorEvent"}},SubagentInfo:{optional:["description"],fields:{}},IdentityCapabilities:{optional:["name","type","description","version","provider","documentationUrl","metadata"],fields:{}},TransportCapabilities:{optional:["streaming","websocket","httpBinary","pushNotifications","resumable"],fields:{}},ToolsCapabilities:{optional:["supported","items","parallelCalls","clientProvided"],fields:{items:{array:"Tool"}}},OutputCapabilities:{optional:["structuredOutput","supportedMimeTypes"],fields:{}},StateCapabilities:{optional:["snapshots","deltas","memory","persistentState"],fields:{}},MultiAgentCapabilities:{optional:["supported","delegation","handoffs","subagents"],fields:{subagents:{array:"SubagentInfo"}}},ReasoningCapabilities:{optional:["supported","streaming","encrypted"],fields:{}},MultimodalInputCapabilities:{optional:["image","audio","video","pdf","file"],fields:{}},MultimodalOutputCapabilities:{optional:["image","audio"],fields:{}},MultimodalCapabilities:{optional:["input","output"],fields:{input:"MultimodalInputCapabilities",output:"MultimodalOutputCapabilities"}},ExecutionCapabilities:{optional:["codeExecution","sandboxed","maxIterations","maxExecutionTime"],fields:{}},HumanInTheLoopCapabilities:{optional:["supported","approvals","interventions","feedback","interrupts","approveWithEdits"],fields:{}},AgentCapabilities:{optional:["identity","transport","tools","output","state","multiAgent","reasoning","multimodal","execution","humanInTheLoop","custom"],fields:{identity:"IdentityCapabilities",transport:"TransportCapabilities",tools:"ToolsCapabilities",output:"OutputCapabilities",state:"StateCapabilities",multiAgent:"MultiAgentCapabilities",reasoning:"ReasoningCapabilities",multimodal:"MultimodalCapabilities",execution:"ExecutionCapabilities",humanInTheLoop:"HumanInTheLoopCapabilities"}}};function Or(t,e){if(typeof e=="string")return Or(t,gx[e]);if("array"in e){if(!Array.isArray(t))return t;let o=t.map(i=>Or(i,e.array));return o.every((i,a)=>i===t[a])?t:o}if(typeof t!="object"||t===null||Array.isArray(t))return t;let n=t;if("discriminator"in e){let o=n[e.discriminator];return typeof o=="string"&&Object.prototype.hasOwnProperty.call(e.variants,o)?Or(t,e.variants[o]):t}let r=n;for(let o of e.optional)Object.prototype.hasOwnProperty.call(n,o)&&n[o]===null&&(r===n&&(r={...n}),delete r[o]);for(let[o,i]of Object.entries(e.fields)){if(!Object.prototype.hasOwnProperty.call(r,o))continue;let a=Or(r[o],i);a!==r[o]&&(r===n&&(r={...n}),r[o]=a)}return r}function rc(t,e){return Or(t,e)}var j=class extends Error{constructor(t){super(t)}},oc=class extends j{constructor(){super("Connect not implemented. This method is not supported by the current agent.")}};function eh(t,e){return e===void 0?t:t===void 0?{...e}:{...t,...e}}function jn(t){return t===void 0?"":typeof t=="string"?t:t.filter(e=>e.type==="text").map(e=>e.text).join("")}function th(t){return Array.isArray(t)&&t.some(e=>e.type!=="text")}var ic={};_l(ic,{JsonPatchError:()=>Ae,_areEquals:()=>Lr,applyOperation:()=>cn,applyPatch:()=>ii,applyReducer:()=>Ex,deepClone:()=>yx,getValueByPointer:()=>ri,validate:()=>rh,validator:()=>oi});var vx=(function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,o){r.__proto__=o}||function(r,o){for(var i in o)o.hasOwnProperty(i)&&(r[i]=o[i])},t(e,n)};return function(e,n){t(e,n);function r(){this.constructor=e}e.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})(),bx=Object.prototype.hasOwnProperty;function ei(t,e){return bx.call(t,e)}function ti(t){if(Array.isArray(t)){for(var e=new Array(t.length),n=0;n<e.length;n++)e[n]=""+n;return e}if(Object.keys)return Object.keys(t);var r=[];for(var o in t)ei(t,o)&&r.push(o);return r}function $e(t){switch(typeof t){case"object":return JSON.parse(JSON.stringify(t));case"undefined":return null;default:return t}}function ni(t){for(var e=0,n=t.length,r;e<n;){if(r=t.charCodeAt(e),r>=48&&r<=57){e++;continue}return!1}return!0}function wt(t){return t.indexOf("/")===-1&&t.indexOf("~")===-1?t:t.replace(/~/g,"~0").replace(/\//g,"~1")}function Pr(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function Qo(t){if(t===void 0)return!0;if(t){if(Array.isArray(t)){for(var e=0,n=t.length;e<n;e++)if(Qo(t[e]))return!0}else if(typeof t=="object"){for(var r=ti(t),o=r.length,i=0;i<o;i++)if(Qo(t[r[i]]))return!0}}return!1}function nh(t,e){var n=[t];for(var r in e){var o=typeof e[r]=="object"?JSON.stringify(e[r],null,2):e[r];typeof o<"u"&&n.push(r+": "+o)}return n.join(`
|
|
2
|
+
`)}var Mr=(function(t){vx(e,t);function e(n,r,o,i,a){var s=this.constructor,c=t.call(this,nh(n,{name:r,index:o,operation:i,tree:a}))||this;return c.name=r,c.index=o,c.operation=i,c.tree=a,Object.setPrototypeOf(c,s.prototype),c.message=nh(n,{name:r,index:o,operation:i,tree:a}),c}return e})(Error);var Ae=Mr,yx=$e,Wn={add:function(t,e,n){return t[e]=this.value,{newDocument:n}},remove:function(t,e,n){var r=t[e];return delete t[e],{newDocument:n,removed:r}},replace:function(t,e,n){var r=t[e];return t[e]=this.value,{newDocument:n,removed:r}},move:function(t,e,n){var r=ri(n,this.path);r&&(r=$e(r));var o=cn(n,{op:"remove",path:this.from}).removed;return cn(n,{op:"add",path:this.path,value:o}),{newDocument:n,removed:r}},copy:function(t,e,n){var r=ri(n,this.from);return cn(n,{op:"add",path:this.path,value:$e(r)}),{newDocument:n}},test:function(t,e,n){return{newDocument:n,test:Lr(t[e],this.value)}},_get:function(t,e,n){return this.value=t[e],{newDocument:n}}},wx={add:function(t,e,n){return ni(e)?t.splice(e,0,this.value):t[e]=this.value,{newDocument:n,index:e}},remove:function(t,e,n){var r=t.splice(e,1);return{newDocument:n,removed:r[0]}},replace:function(t,e,n){var r=t[e];return t[e]=this.value,{newDocument:n,removed:r}},move:Wn.move,copy:Wn.copy,test:Wn.test,_get:Wn._get};function ri(t,e){if(e=="")return t;var n={op:"_get",path:e};return cn(t,n),n.value}function cn(t,e,n,r,o,i){if(n===void 0&&(n=!1),r===void 0&&(r=!0),o===void 0&&(o=!0),i===void 0&&(i=0),n&&(typeof n=="function"?n(e,0,t,e.path):oi(e,0)),e.path===""){var a={newDocument:t};if(e.op==="add")return a.newDocument=e.value,a;if(e.op==="replace")return a.newDocument=e.value,a.removed=t,a;if(e.op==="move"||e.op==="copy")return a.newDocument=ri(t,e.from),e.op==="move"&&(a.removed=t),a;if(e.op==="test"){if(a.test=Lr(t,e.value),a.test===!1)throw new Ae("Test operation failed","TEST_OPERATION_FAILED",i,e,t);return a.newDocument=t,a}else{if(e.op==="remove")return a.removed=t,a.newDocument=null,a;if(e.op==="_get")return e.value=t,a;if(n)throw new Ae("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",i,e,t);return a}}else{r||(t=$e(t));var s=e.path||"",c=s.split("/"),l=t,u=1,f=c.length,m=void 0,p=void 0,h=void 0;for(typeof n=="function"?h=n:h=oi;;){if(p=c[u],p&&p.indexOf("~")!=-1&&(p=Pr(p)),o&&(p=="__proto__"||p=="prototype"&&u>0&&c[u-1]=="constructor"))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(n&&m===void 0&&(l[p]===void 0?m=c.slice(0,u).join("/"):u==f-1&&(m=e.path),m!==void 0&&h(e,0,t,m)),u++,Array.isArray(l)){if(p==="-")p=l.length;else{if(n&&!ni(p))throw new Ae("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",i,e,t);ni(p)&&(p=~~p)}if(u>=f){if(n&&e.op==="add"&&p>l.length)throw new Ae("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",i,e,t);var a=wx[e.op].call(e,l,p,t);if(a.test===!1)throw new Ae("Test operation failed","TEST_OPERATION_FAILED",i,e,t);return a}}else if(u>=f){var a=Wn[e.op].call(e,l,p,t);if(a.test===!1)throw new Ae("Test operation failed","TEST_OPERATION_FAILED",i,e,t);return a}if(l=l[p],n&&u<f&&(!l||typeof l!="object"))throw new Ae("Cannot perform operation at the desired path","OPERATION_PATH_UNRESOLVABLE",i,e,t)}}}function ii(t,e,n,r,o){if(r===void 0&&(r=!0),o===void 0&&(o=!0),n&&!Array.isArray(e))throw new Ae("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");r||(t=$e(t));for(var i=new Array(e.length),a=0,s=e.length;a<s;a++)i[a]=cn(t,e[a],n,!0,o,a),t=i[a].newDocument;return i.newDocument=t,i}function Ex(t,e,n){var r=cn(t,e);if(r.test===!1)throw new Ae("Test operation failed","TEST_OPERATION_FAILED",n,e,t);return r.newDocument}function oi(t,e,n,r){if(typeof t!="object"||t===null||Array.isArray(t))throw new Ae("Operation is not an object","OPERATION_NOT_AN_OBJECT",e,t,n);if(Wn[t.op]){if(typeof t.path!="string")throw new Ae("Operation `path` property is not a string","OPERATION_PATH_INVALID",e,t,n);if(t.path.indexOf("/")!==0&&t.path.length>0)throw new Ae('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",e,t,n);if((t.op==="move"||t.op==="copy")&&typeof t.from!="string")throw new Ae("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",e,t,n);if((t.op==="add"||t.op==="replace"||t.op==="test")&&t.value===void 0)throw new Ae("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",e,t,n);if((t.op==="add"||t.op==="replace"||t.op==="test")&&Qo(t.value))throw new Ae("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",e,t,n);if(n){if(t.op=="add"){var o=t.path.split("/").length,i=r.split("/").length;if(o!==i+1&&o!==i)throw new Ae("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",e,t,n)}else if(t.op==="replace"||t.op==="remove"||t.op==="_get"){if(t.path!==r)throw new Ae("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",e,t,n)}else if(t.op==="move"||t.op==="copy"){var a={op:"_get",path:t.from,value:void 0},s=rh([a],n);if(s&&s.name==="OPERATION_PATH_UNRESOLVABLE")throw new Ae("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",e,t,n)}}}else throw new Ae("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",e,t,n)}function rh(t,e,n){try{if(!Array.isArray(t))throw new Ae("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(e)ii($e(e),$e(t),n||!0);else{n=n||oi;for(var r=0;r<t.length;r++)n(t[r],r,e,void 0)}}catch(o){if(o instanceof Ae)return o;throw o}}function Lr(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var n=Array.isArray(t),r=Array.isArray(e),o,i,a;if(n&&r){if(i=t.length,i!=e.length)return!1;for(o=i;o--!==0;)if(!Lr(t[o],e[o]))return!1;return!0}if(n!=r)return!1;var s=Object.keys(t);if(i=s.length,i!==Object.keys(e).length)return!1;for(o=i;o--!==0;)if(!e.hasOwnProperty(s[o]))return!1;for(o=i;o--!==0;)if(a=s[o],!Lr(t[a],e[a]))return!1;return!0}return t!==t&&e!==e}var cc={};_l(cc,{compare:()=>Rx,generate:()=>ac,observe:()=>Ix,unobserve:()=>kx});var sc=new WeakMap,xx=(function(){function t(e){this.observers=new Map,this.obj=e}return t})(),_x=(function(){function t(e,n){this.callback=e,this.observer=n}return t})();function Sx(t){return sc.get(t)}function Tx(t,e){return t.observers.get(e)}function Ax(t,e){t.observers.delete(e.callback)}function kx(t,e){e.unobserve()}function Ix(t,e){var n=[],r,o=Sx(t);if(!o)o=new xx(t),sc.set(t,o);else{var i=Tx(o,e);r=i&&i.observer}if(r)return r;if(r={},o.value=$e(t),e){r.callback=e,r.next=null;var a=function(){ac(r)},s=function(){clearTimeout(r.next),r.next=setTimeout(a)};typeof window<"u"&&(window.addEventListener("mouseup",s),window.addEventListener("keyup",s),window.addEventListener("mousedown",s),window.addEventListener("keydown",s),window.addEventListener("change",s))}return r.patches=n,r.object=t,r.unobserve=function(){ac(r),clearTimeout(r.next),Ax(o,r),typeof window<"u"&&(window.removeEventListener("mouseup",s),window.removeEventListener("keyup",s),window.removeEventListener("mousedown",s),window.removeEventListener("keydown",s),window.removeEventListener("change",s))},o.observers.set(e,new _x(e,r)),r}function ac(t,e){e===void 0&&(e=!1);var n=sc.get(t.object);lc(n.value,t.object,t.patches,"",e),t.patches.length&&ii(n.value,t.patches);var r=t.patches;return r.length>0&&(t.patches=[],t.callback&&t.callback(r)),r}function lc(t,e,n,r,o){if(e!==t){typeof e.toJSON=="function"&&(e=e.toJSON());for(var i=ti(e),a=ti(t),s=!1,c=!1,l=a.length-1;l>=0;l--){var u=a[l],f=t[u];if(ei(e,u)&&!(e[u]===void 0&&f!==void 0&&Array.isArray(e)===!1)){var m=e[u];typeof f=="object"&&f!=null&&typeof m=="object"&&m!=null&&Array.isArray(f)===Array.isArray(m)?lc(f,m,n,r+"/"+wt(u),o):f!==m&&(s=!0,o&&n.push({op:"test",path:r+"/"+wt(u),value:$e(f)}),n.push({op:"replace",path:r+"/"+wt(u),value:$e(m)}))}else Array.isArray(t)===Array.isArray(e)?(o&&n.push({op:"test",path:r+"/"+wt(u),value:$e(f)}),n.push({op:"remove",path:r+"/"+wt(u)}),c=!0):(o&&n.push({op:"test",path:r,value:t}),n.push({op:"replace",path:r,value:e}),s=!0)}if(!(!c&&i.length==a.length))for(var l=0;l<i.length;l++){var u=i[l];!ei(t,u)&&e[u]!==void 0&&n.push({op:"add",path:r+"/"+wt(u),value:$e(e[u])})}}}function Rx(t,e,n){n===void 0&&(n=!1);var r=[];return lc(t,e,r,"",n),r}var ai=Object.assign({},ic,cc,{JsonPatchError:Mr,deepClone:$e,escapePathComponent:wt,unescapePathComponent:Pr});var uc=function(t,e){return uc=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[o]=r[o])},uc(t,e)};function Et(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");uc(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}function oh(t,e,n,r){function o(i){return i instanceof n?i:new n(function(a){a(i)})}return new(n||(n=Promise))(function(i,a){function s(u){try{l(r.next(u))}catch(f){a(f)}}function c(u){try{l(r.throw(u))}catch(f){a(f)}}function l(u){u.done?i(u.value):o(u.value).then(s,c)}l((r=r.apply(t,e||[])).next())})}function si(t,e){var n={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,o,i,a=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function s(l){return function(u){return c([l,u])}}function c(l){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(n=0)),n;)try{if(r=1,o&&(i=l[0]&2?o.return:l[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,l[1])).done)return i;switch(o=0,i&&(l=[l[0]&2,i.value]),l[0]){case 0:case 1:i=l;break;case 4:return n.label++,{value:l[1],done:!1};case 5:n.label++,o=l[1],l=[0];continue;case 7:l=n.ops.pop(),n.trys.pop();continue;default:if(i=n.trys,!(i=i.length>0&&i[i.length-1])&&(l[0]===6||l[0]===2)){n=0;continue}if(l[0]===3&&(!i||l[1]>i[0]&&l[1]<i[3])){n.label=l[1];break}if(l[0]===6&&n.label<i[1]){n.label=i[1],i=l;break}if(i&&n.label<i[2]){n.label=i[2],n.ops.push(l);break}i[2]&&n.ops.pop(),n.trys.pop();continue}l=e.call(t,n)}catch(u){l=[6,u],o=0}finally{r=i=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}function Ot(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function xt(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),o,i=[],a;try{for(;(e===void 0||e-- >0)&&!(o=r.next()).done;)i.push(o.value)}catch(s){a={error:s}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(a)throw a.error}}return i}function _t(t,e,n){if(n||arguments.length===2)for(var r=0,o=e.length,i;r<o;r++)(i||!(r in e))&&(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))}function un(t){return this instanceof un?(this.v=t,this):new un(t)}function ih(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(t,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",a),o[Symbol.asyncIterator]=function(){return this},o;function a(p){return function(h){return Promise.resolve(h).then(p,f)}}function s(p,h){r[p]&&(o[p]=function(x){return new Promise(function(g,w){i.push([p,x,g,w])>1||c(p,x)})},h&&(o[p]=h(o[p])))}function c(p,h){try{l(r[p](h))}catch(x){m(i[0][3],x)}}function l(p){p.value instanceof un?Promise.resolve(p.value.v).then(u,f):m(i[0][2],p)}function u(p){c("next",p)}function f(p){c("throw",p)}function m(p,h){p(h),i.shift(),i.length&&c(i[0][0],i[0][1])}}function ah(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],n;return e?e.call(t):(t=typeof Ot=="function"?Ot(t):t[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(i){n[i]=t[i]&&function(a){return new Promise(function(s,c){a=t[i](a),o(s,c,a.done,a.value)})}}function o(i,a,s,c){Promise.resolve(c).then(function(l){i({value:l,done:s})},a)}}function Q(t){return typeof t=="function"}function qn(t){var e=function(r){Error.call(r),r.stack=new Error().stack},n=t(e);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var li=qn(function(t){return function(n){t(this),this.message=n?n.length+` errors occurred during unsubscription:
|
|
3
3
|
`+n.map(function(r,o){return o+1+") "+r.toString()}).join(`
|
|
4
|
-
`):"",this.name="UnsubscriptionError",this.errors=n}});function Pr(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var Wn=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,n,r,o,i;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var s=Rt(a),l=s.next();!l.done;l=s.next()){var c=l.value;c.remove(this)}}catch(E){t={error:E}}finally{try{l&&!l.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}else a.remove(this);var u=this.initialTeardown;if(J(u))try{u()}catch(E){i=E instanceof oi?E.errors:[E]}var f=this._finalizers;if(f){this._finalizers=null;try{for(var m=Rt(f),p=m.next();!p.done;p=m.next()){var h=p.value;try{Kp(h)}catch(E){i=i??[],E instanceof oi?i=Et(Et([],wt(i)),wt(E.errors)):i.push(E)}}}catch(E){r={error:E}}finally{try{p&&!p.done&&(o=m.return)&&o.call(m)}finally{if(r)throw r.error}}}if(i)throw new oi(i)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)Kp(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(t)}},e.prototype._hasParent=function(t){var n=this._parentage;return n===t||Array.isArray(n)&&n.includes(t)},e.prototype._addParent=function(t){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(t),n):n?[n,t]:t},e.prototype._removeParent=function(t){var n=this._parentage;n===t?this._parentage=null:Array.isArray(n)&&Pr(n,t)},e.prototype.remove=function(t){var n=this._finalizers;n&&Pr(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})();var rc=Wn.EMPTY;function ii(e){return e instanceof Wn||e&&"closed"in e&&J(e.remove)&&J(e.add)&&J(e.unsubscribe)}function Kp(e){J(e)?e():e.unsubscribe()}var lt={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var qn={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=qn.delegate;return o?.setTimeout?o.setTimeout.apply(o,Et([e,t],wt(n))):setTimeout.apply(void 0,Et([e,t],wt(n)))},clearTimeout:function(e){var t=qn.delegate;return(t?.clearTimeout||clearTimeout)(e)},delegate:void 0};function ai(e){qn.setTimeout(function(){var t=lt.onUnhandledError;if(t)t(e);else throw e})}function Mr(){}var Jp=(function(){return oc("C",void 0,void 0)})();function Qp(e){return oc("E",void 0,e)}function eh(e){return oc("N",e,void 0)}function oc(e,t,n){return{kind:e,value:t,error:n}}var sn=null;function Yn(e){if(lt.useDeprecatedSynchronousErrorHandling){var t=!sn;if(t&&(sn={errorThrown:!1,error:null}),e(),t){var n=sn,r=n.errorThrown,o=n.error;if(sn=null,r)throw o}}else e()}function th(e){lt.useDeprecatedSynchronousErrorHandling&&sn&&(sn.errorThrown=!0,sn.error=e)}var zr=(function(e){yt(t,e);function t(n){var r=e.call(this)||this;return r.isStopped=!1,n?(r.destination=n,ii(n)&&n.add(r)):r.destination=Ex,r}return t.create=function(n,r,o){return new li(n,r,o)},t.prototype.next=function(n){this.isStopped?ac(eh(n),this):this._next(n)},t.prototype.error=function(n){this.isStopped?ac(Qp(n),this):(this.isStopped=!0,this._error(n))},t.prototype.complete=function(){this.isStopped?ac(Jp,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(n){this.destination.next(n)},t.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(Wn);var bx=Function.prototype.bind;function ic(e,t){return bx.call(e,t)}var yx=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var n=this.partialObserver;if(n.next)try{n.next(t)}catch(r){si(r)}},e.prototype.error=function(t){var n=this.partialObserver;if(n.error)try{n.error(t)}catch(r){si(r)}else si(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(n){si(n)}},e})(),li=(function(e){yt(t,e);function t(n,r,o){var i=e.call(this)||this,a;if(J(n)||!n)a={next:n??void 0,error:r??void 0,complete:o??void 0};else{var s;i&<.useDeprecatedNextContext?(s=Object.create(n),s.unsubscribe=function(){return i.unsubscribe()},a={next:n.next&&ic(n.next,s),error:n.error&&ic(n.error,s),complete:n.complete&&ic(n.complete,s)}):a=n}return i.destination=new yx(a),i}return t})(zr);function si(e){lt.useDeprecatedSynchronousErrorHandling?th(e):ai(e)}function wx(e){throw e}function ac(e,t){var n=lt.onStoppedNotification;n&&qn.setTimeout(function(){return n(e,t)})}var Ex={closed:!0,next:Mr,error:wx,complete:Mr};var Xn=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Kn(e){return e}function ci(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return sc(e)}function sc(e){return e.length===0?Kn:e.length===1?e[0]:function(n){return e.reduce(function(r,o){return o(r)},n)}}var ge=(function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(t,n,r){var o=this,i=_x(t)?t:new li(t,n,r);return Yn(function(){var a=o,s=a.operator,l=a.source;i.add(s?s.call(i,l):l?o._subscribe(i):o._trySubscribe(i))}),i},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(n){t.error(n)}},e.prototype.forEach=function(t,n){var r=this;return n=nh(n),new n(function(o,i){var a=new li({next:function(s){try{t(s)}catch(l){i(l),a.unsubscribe()}},error:i,complete:o});r.subscribe(a)})},e.prototype._subscribe=function(t){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(t)},e.prototype[Xn]=function(){return this},e.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return sc(t)(this)},e.prototype.toPromise=function(t){var n=this;return t=nh(t),new t(function(r,o){var i;n.subscribe(function(a){return i=a},function(a){return o(a)},function(){return r(i)})})},e.create=function(t){return new e(t)},e})();function nh(e){var t;return(t=e??lt.Promise)!==null&&t!==void 0?t:Promise}function xx(e){return e&&J(e.next)&&J(e.error)&&J(e.complete)}function _x(e){return e&&e instanceof zr||xx(e)&&ii(e)}function Sx(e){return J(e?.lift)}function we(e){return function(t){if(Sx(t))return t.lift(function(n){try{return e(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function ke(e,t,n,r,o){return new Tx(e,t,n,r,o)}var Tx=(function(e){yt(t,e);function t(n,r,o,i,a,s){var l=e.call(this,n)||this;return l.onFinalize=a,l.shouldUnsubscribe=s,l._next=r?function(c){try{r(c)}catch(u){n.error(u)}}:e.prototype._next,l._error=i?function(c){try{i(c)}catch(u){n.error(u)}finally{this.unsubscribe()}}:e.prototype._error,l._complete=o?function(){try{o()}catch(c){n.error(c)}finally{this.unsubscribe()}}:e.prototype._complete,l}return t.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;e.prototype.unsubscribe.call(this),!r&&((n=this.onFinalize)===null||n===void 0||n.call(this))}},t})(zr);var rh=jn(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var xt=(function(e){yt(t,e);function t(){var n=e.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return t.prototype.lift=function(n){var r=new oh(this,this);return r.operator=n,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new rh},t.prototype.next=function(n){var r=this;Yn(function(){var o,i;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var a=Rt(r.currentObservers),s=a.next();!s.done;s=a.next()){var l=s.value;l.next(n)}}catch(c){o={error:c}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}}})},t.prototype.error=function(n){var r=this;Yn(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var o=r.observers;o.length;)o.shift().error(n)}})},t.prototype.complete=function(){var n=this;Yn(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(n){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,n)},t.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},t.prototype._innerSubscribe=function(n){var r=this,o=this,i=o.hasError,a=o.isStopped,s=o.observers;return i||a?rc:(this.currentObservers=null,s.push(n),new Wn(function(){r.currentObservers=null,Pr(s,n)}))},t.prototype._checkFinalizedStatuses=function(n){var r=this,o=r.hasError,i=r.thrownError,a=r.isStopped;o?n.error(i):a&&n.complete()},t.prototype.asObservable=function(){var n=new ge;return n.source=this,n},t.create=function(n,r){return new oh(n,r)},t})(ge);var oh=(function(e){yt(t,e);function t(n,r){var o=e.call(this)||this;return o.destination=n,o.source=r,o}return t.prototype.next=function(n){var r,o;(o=(r=this.destination)===null||r===void 0?void 0:r.next)===null||o===void 0||o.call(r,n)},t.prototype.error=function(n){var r,o;(o=(r=this.destination)===null||r===void 0?void 0:r.error)===null||o===void 0||o.call(r,n)},t.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},t.prototype._subscribe=function(n){var r,o;return(o=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&o!==void 0?o:rc},t})(xt);var lc={now:function(){return(lc.delegate||Date).now()},delegate:void 0};var ui=(function(e){yt(t,e);function t(n,r,o){n===void 0&&(n=1/0),r===void 0&&(r=1/0),o===void 0&&(o=lc);var i=e.call(this)||this;return i._bufferSize=n,i._windowTime=r,i._timestampProvider=o,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=r===1/0,i._bufferSize=Math.max(1,n),i._windowTime=Math.max(1,r),i}return t.prototype.next=function(n){var r=this,o=r.isStopped,i=r._buffer,a=r._infiniteTimeWindow,s=r._timestampProvider,l=r._windowTime;o||(i.push(n),!a&&i.push(s.now()+l)),this._trimBuffer(),e.prototype.next.call(this,n)},t.prototype._subscribe=function(n){this._throwIfClosed(),this._trimBuffer();for(var r=this._innerSubscribe(n),o=this,i=o._infiniteTimeWindow,a=o._buffer,s=a.slice(),l=0;l<s.length&&!n.closed;l+=i?1:2)n.next(s[l]);return this._checkFinalizedStatuses(n),r},t.prototype._trimBuffer=function(){var n=this,r=n._bufferSize,o=n._timestampProvider,i=n._buffer,a=n._infiniteTimeWindow,s=(a?1:2)*r;if(r<1/0&&s<i.length&&i.splice(0,i.length-s),!a){for(var l=o.now(),c=0,u=1;u<i.length&&i[u]<=l;u+=2)c=u;c&&i.splice(0,c+1)}},t})(xt);var ln=new ge(function(e){return e.complete()});function ih(e){return e&&J(e.schedule)}function Ax(e){return e[e.length-1]}function di(e){return ih(Ax(e))?e.pop():void 0}var pi=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function hi(e){return J(e?.then)}function fi(e){return J(e[Xn])}function mi(e){return Symbol.asyncIterator&&J(e?.[Symbol.asyncIterator])}function gi(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function kx(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var vi=kx();function bi(e){return J(e?.[vi])}function yi(e){return Yp(this,arguments,function(){var n,r,o,i;return ri(this,function(a){switch(a.label){case 0:n=e.getReader(),a.label=1;case 1:a.trys.push([1,,9,10]),a.label=2;case 2:return[4,an(n.read())];case 3:return r=a.sent(),o=r.value,i=r.done,i?[4,an(void 0)]:[3,5];case 4:return[2,a.sent()];case 5:return[4,an(o)];case 6:return[4,a.sent()];case 7:return a.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}})})}function wi(e){return J(e?.getReader)}function Pe(e){if(e instanceof ge)return e;if(e!=null){if(fi(e))return Ix(e);if(pi(e))return Rx(e);if(hi(e))return Cx(e);if(mi(e))return ah(e);if(bi(e))return Nx(e);if(wi(e))return Ox(e)}throw gi(e)}function Ix(e){return new ge(function(t){var n=e[Xn]();if(J(n.subscribe))return n.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Rx(e){return new ge(function(t){for(var n=0;n<e.length&&!t.closed;n++)t.next(e[n]);t.complete()})}function Cx(e){return new ge(function(t){e.then(function(n){t.closed||(t.next(n),t.complete())},function(n){return t.error(n)}).then(null,ai)})}function Nx(e){return new ge(function(t){var n,r;try{for(var o=Rt(e),i=o.next();!i.done;i=o.next()){var a=i.value;if(t.next(a),t.closed)return}}catch(s){n={error:s}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}t.complete()})}function ah(e){return new ge(function(t){Px(e,t).catch(function(n){return t.error(n)})})}function Ox(e){return ah(yi(e))}function Px(e,t){var n,r,o,i;return qp(this,void 0,void 0,function(){var a,s;return ri(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),n=Xp(e),l.label=1;case 1:return[4,n.next()];case 2:if(r=l.sent(),!!r.done)return[3,4];if(a=r.value,t.next(a),t.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return s=l.sent(),o={error:s},[3,11];case 6:return l.trys.push([6,,9,10]),r&&!r.done&&(i=n.return)?[4,i.call(n)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function rt(e,t,n,r,o){r===void 0&&(r=0),o===void 0&&(o=!1);var i=t.schedule(function(){n(),o?e.add(this.schedule(null,r)):this.unsubscribe()},r);if(e.add(i),!o)return i}function Ei(e,t){return t===void 0&&(t=0),we(function(n,r){n.subscribe(ke(r,function(o){return rt(r,e,function(){return r.next(o)},t)},function(){return rt(r,e,function(){return r.complete()},t)},function(o){return rt(r,e,function(){return r.error(o)},t)}))})}function xi(e,t){return t===void 0&&(t=0),we(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function sh(e,t){return Pe(e).pipe(xi(t),Ei(t))}function lh(e,t){return Pe(e).pipe(xi(t),Ei(t))}function ch(e,t){return new ge(function(n){var r=0;return t.schedule(function(){r===e.length?n.complete():(n.next(e[r++]),n.closed||this.schedule())})})}function uh(e,t){return new ge(function(n){var r;return rt(n,t,function(){r=e[vi](),rt(n,t,function(){var o,i,a;try{o=r.next(),i=o.value,a=o.done}catch(s){n.error(s);return}a?n.complete():n.next(i)},0,!0)}),function(){return J(r?.return)&&r.return()}})}function _i(e,t){if(!e)throw new Error("Iterable cannot be null");return new ge(function(n){rt(n,t,function(){var r=e[Symbol.asyncIterator]();rt(n,t,function(){r.next().then(function(o){o.done?n.complete():n.next(o.value)})},0,!0)})})}function dh(e,t){return _i(yi(e),t)}function ph(e,t){if(e!=null){if(fi(e))return sh(e,t);if(pi(e))return ch(e,t);if(hi(e))return lh(e,t);if(mi(e))return _i(e,t);if(bi(e))return uh(e,t);if(wi(e))return dh(e,t)}throw gi(e)}function Ct(e,t){return t?ph(e,t):Pe(e)}function ce(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=di(e);return Ct(e,n)}function F(e,t){var n=J(e)?e:function(){return e},r=function(o){return o.error(n())};return new ge(t?function(o){return t.schedule(r,0,o)}:r)}var hh=jn(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function Si(e,t){var n=typeof t=="object";return new Promise(function(r,o){var i=!1,a;e.subscribe({next:function(s){a=s,i=!0},error:o,complete:function(){i?r(a):n?r(t.defaultValue):o(new hh)}})})}function _t(e,t){return we(function(n,r){var o=0;n.subscribe(ke(r,function(i){r.next(e.call(t,i,o++))}))})}function fh(e,t,n,r,o,i,a,s){var l=[],c=0,u=0,f=!1,m=function(){f&&!l.length&&!c&&t.complete()},p=function(E){return c<r?h(E):l.push(E)},h=function(E){i&&t.next(E),c++;var g=!1;Pe(n(E,u++)).subscribe(ke(t,function(_){o?.(_),i?p(_):t.next(_)},function(){g=!0},void 0,function(){if(g)try{c--;for(var _=function(){var b=l.shift();a?rt(t,a,function(){return h(b)}):h(b)};l.length&&c<r;)_();m()}catch(b){t.error(b)}}))};return e.subscribe(ke(t,p,function(){f=!0,m()})),function(){s?.()}}function je(e,t,n){return n===void 0&&(n=1/0),J(t)?je(function(r,o){return _t(function(i,a){return t(r,i,o,a)})(Pe(e(r,o)))},n):(typeof t=="number"&&(n=t),we(function(r,o){return fh(r,o,e,n)}))}function Lr(e){return e===void 0&&(e=1/0),je(Kn,e)}function mh(){return Lr(1)}function cn(e){return new ge(function(t){Pe(e()).subscribe(t)})}function cc(e,t){return we(function(n,r){var o=0;n.subscribe(ke(r,function(i){return e.call(t,i,o++)&&r.next(i)}))})}function Jn(e){return we(function(t,n){var r=null,o=!1,i;r=t.subscribe(ke(n,void 0,void 0,function(a){i=Pe(e(a,Jn(e)(t))),r?(r.unsubscribe(),r=null,i.subscribe(n)):o=!0})),o&&(r.unsubscribe(),r=null,i.subscribe(n))})}function Ti(e,t){return J(t)?je(e,t,1):je(e,1)}function gh(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=di(e);return we(function(r,o){mh()(Ct(Et([r],wt(e)),n)).subscribe(o)})}function uc(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return gh.apply(void 0,Et([],wt(e)))}function dc(e){return we(function(t,n){var r=!1;t.subscribe(ke(n,function(o){r=!0,n.next(o)},function(){r||n.next(e),n.complete()}))})}function un(e){return we(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function pc(e,t){return we(function(n,r){var o=null,i=0,a=!1,s=function(){return a&&!o&&r.complete()};n.subscribe(ke(r,function(l){o?.unsubscribe();var c=0,u=i++;Pe(e(l,u)).subscribe(o=ke(r,function(f){return r.next(t?t(l,f,u,c++):f)},function(){o=null,s()}))},function(){a=!0,s()}))})}function Ai(e){return we(function(t,n){Pe(e).subscribe(ke(n,function(){return n.complete()},Mr)),!n.closed&&t.subscribe(n)})}function ki(e,t,n){var r=J(e)||t||n?{next:e,error:t,complete:n}:e;return r?we(function(o,i){var a;(a=r.subscribe)===null||a===void 0||a.call(r);var s=!0;o.subscribe(ke(i,function(l){var c;(c=r.next)===null||c===void 0||c.call(r,l),i.next(l)},function(){var l;s=!1,(l=r.complete)===null||l===void 0||l.call(r),i.complete()},function(l){var c;s=!1,(c=r.error)===null||c===void 0||c.call(r,l),i.error(l)},function(){var l,c;s&&((l=r.unsubscribe)===null||l===void 0||l.call(r)),(c=r.finalize)===null||c===void 0||c.call(r)}))}):Kn}function vh(e){return` \r
|
|
5
|
-
`.indexOf(e)>=0}function Ii(e){for(var t=["topLevel"],n=0,r,o,i,a=function(b){return t.push(b)},s=function(b){return t[t.length-1]=b},l=function(b){r==null&&(r=n,o=t.length,i=b)},c=function(b){b===i&&(r=void 0,o=void 0,i=void 0)},u=function(){return t.pop()},f=function(){return n--},m=function(b){if("0"<=b&&b<="9"){a("number");return}switch(b){case'"':a("string");return;case"-":a("numberNeedsDigit");return;case"t":a("true");return;case"f":a("false");return;case"n":a("null");return;case"[":a("arrayNeedsValue");return;case"{":a("objectNeedsKey");return}},p=e.length;n<p;n++){var h=e[n];switch(t[t.length-1]){case"topLevel":m(h);break;case"string":switch(h){case'"':u();break;case"\\":l("stringEscape"),a("stringEscaped");break}break;case"stringEscaped":h==="u"?a("stringUnicode"):(c("stringEscape"),u());break;case"stringUnicode":n-e.lastIndexOf("u",n)===4&&(c("stringEscape"),u());break;case"number":h==="."?s("numberNeedsDigit"):h==="e"||h==="E"?s("numberNeedsExponent"):(h<"0"||h>"9")&&(f(),u());break;case"numberNeedsDigit":s("number");break;case"numberNeedsExponent":s(h==="+"||h==="-"?"numberNeedsDigit":"number");break;case"true":case"false":case"null":(h<"a"||h>"z")&&(f(),u());break;case"arrayNeedsValue":h==="]"?u():vh(h)||(c("collectionItem"),s("arrayNeedsComma"),m(h));break;case"arrayNeedsComma":h==="]"?u():h===","&&(l("collectionItem"),s("arrayNeedsValue"));break;case"objectNeedsKey":h==="}"?u():h==='"'&&(l("collectionItem"),s("objectNeedsColon"),a("string"));break;case"objectNeedsColon":h===":"&&s("objectNeedsValue");break;case"objectNeedsValue":vh(h)||(c("collectionItem"),s("objectNeedsComma"),m(h));break;case"objectNeedsComma":h==="}"?u():h===","&&(l("collectionItem"),s("objectNeedsKey"));break}}o!=null&&(t.length=o);for(var E=[r!=null?e.slice(0,r):e],g=function(b){return E.push(b.slice(e.length-e.lastIndexOf(b[0])))},_=t.length-1;_>=0;_--)switch(t[_]){case"string":E.push('"');break;case"numberNeedsDigit":case"numberNeedsExponent":E.push("0");break;case"true":g("true");break;case"false":g("false");break;case"null":g("null");break;case"arrayNeedsValue":case"arrayNeedsComma":E.push("]");break;case"objectNeedsKey":case"objectNeedsColon":case"objectNeedsValue":case"objectNeedsComma":E.push("}");break}return E.join("")}var Mx=Object.freeze({status:"aborted"});function A(e,t,n){function r(s,l){var c;Object.defineProperty(s,"_zod",{value:s._zod??{},enumerable:!1}),(c=s._zod).traits??(c.traits=new Set),s._zod.traits.add(e),t(s,l);for(let u in a.prototype)u in s||Object.defineProperty(s,u,{value:a.prototype[u].bind(s)});s._zod.constr=a,s._zod.def=l}let o=n?.Parent??Object;class i extends o{}Object.defineProperty(i,"name",{value:e});function a(s){var l;let c=n?.Parent?new i:this;r(c,s),(l=c._zod).deferred??(l.deferred=[]);for(let u of c._zod.deferred)u();return c}return Object.defineProperty(a,"init",{value:r}),Object.defineProperty(a,Symbol.hasInstance,{value:s=>n?.Parent&&s instanceof n.Parent?!0:s?._zod?.traits?.has(e)}),Object.defineProperty(a,"name",{value:e}),a}var Nt=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}},Ri={};function $e(e){return e&&Object.assign(Ri,e),Ri}var le={};vl(le,{BIGINT_FORMAT_RANGES:()=>yh,Class:()=>fc,NUMBER_FORMAT_RANGES:()=>xc,aborted:()=>pn,allowsEval:()=>yc,assert:()=>Ux,assertEqual:()=>zx,assertIs:()=>Dx,assertNever:()=>$x,assertNotEqual:()=>Lx,assignProp:()=>bc,cached:()=>$r,captureStackTrace:()=>Ni,cleanEnum:()=>Jx,cleanRegex:()=>Hr,clone:()=>ct,createTransparentProxy:()=>Vx,defineLazy:()=>se,esc:()=>dn,escapeRegex:()=>Ut,extend:()=>qx,finalizeIssue:()=>ut,floatSafeRemainder:()=>vc,getElementAtPath:()=>Hx,getEnumValues:()=>mc,getLengthableOrigin:()=>Fr,getParsedType:()=>Zx,getSizableOrigin:()=>wh,isObject:()=>Qn,isPlainObject:()=>er,issue:()=>_c,joinValues:()=>Ci,jsonStringifyReplacer:()=>gc,merge:()=>Yx,normalizeParams:()=>G,nullish:()=>Ur,numKeys:()=>Bx,omit:()=>Wx,optionalKeys:()=>Ec,partial:()=>Xx,pick:()=>jx,prefixIssues:()=>St,primitiveTypes:()=>bh,promiseAllObject:()=>Fx,propertyKeyTypes:()=>wc,randomString:()=>Gx,required:()=>Kx,stringifyPrimitive:()=>Oi,unwrapMessage:()=>Dr});function zx(e){return e}function Lx(e){return e}function Dx(e){}function $x(e){throw new Error}function Ux(e){}function mc(e){let t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,o])=>t.indexOf(+r)===-1).map(([r,o])=>o)}function Ci(e,t="|"){return e.map(n=>Oi(n)).join(t)}function gc(e,t){return typeof t=="bigint"?t.toString():t}function $r(e){return{get value(){{let n=e();return Object.defineProperty(this,"value",{value:n}),n}throw new Error("cached value already set")}}}function Ur(e){return e==null}function Hr(e){let t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function vc(e,t){let n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,o=n>r?n:r,i=Number.parseInt(e.toFixed(o).replace(".","")),a=Number.parseInt(t.toFixed(o).replace(".",""));return i%a/10**o}function se(e,t,n){Object.defineProperty(e,t,{get(){{let o=n();return e[t]=o,o}throw new Error("cached value already set")},set(o){Object.defineProperty(e,t,{value:o})},configurable:!0})}function bc(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Hx(e,t){return t?t.reduce((n,r)=>n?.[r],e):e}function Fx(e){let t=Object.keys(e),n=t.map(r=>e[r]);return Promise.all(n).then(r=>{let o={};for(let i=0;i<t.length;i++)o[t[i]]=r[i];return o})}function Gx(e=10){let t="abcdefghijklmnopqrstuvwxyz",n="";for(let r=0;r<e;r++)n+=t[Math.floor(Math.random()*t.length)];return n}function dn(e){return JSON.stringify(e)}var Ni=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function Qn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var yc=$r(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{let e=Function;return new e(""),!0}catch{return!1}});function er(e){if(Qn(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(Qn(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Bx(e){let t=0;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&t++;return t}var Zx=e=>{let t=typeof e;switch(t){case"undefined":return"undefined";case"string":return"string";case"number":return Number.isNaN(e)?"nan":"number";case"boolean":return"boolean";case"function":return"function";case"bigint":return"bigint";case"symbol":return"symbol";case"object":return Array.isArray(e)?"array":e===null?"null":e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?"promise":typeof Map<"u"&&e instanceof Map?"map":typeof Set<"u"&&e instanceof Set?"set":typeof Date<"u"&&e instanceof Date?"date":typeof File<"u"&&e instanceof File?"file":"object";default:throw new Error(`Unknown data type: ${t}`)}},wc=new Set(["string","number","symbol"]),bh=new Set(["string","number","bigint","boolean","symbol","undefined"]);function Ut(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ct(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function G(e){let t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Vx(e){let t;return new Proxy({},{get(n,r,o){return t??(t=e()),Reflect.get(t,r,o)},set(n,r,o,i){return t??(t=e()),Reflect.set(t,r,o,i)},has(n,r){return t??(t=e()),Reflect.has(t,r)},deleteProperty(n,r){return t??(t=e()),Reflect.deleteProperty(t,r)},ownKeys(n){return t??(t=e()),Reflect.ownKeys(t)},getOwnPropertyDescriptor(n,r){return t??(t=e()),Reflect.getOwnPropertyDescriptor(t,r)},defineProperty(n,r,o){return t??(t=e()),Reflect.defineProperty(t,r,o)}})}function Oi(e){return typeof e=="bigint"?e.toString()+"n":typeof e=="string"?`"${e}"`:`${e}`}function Ec(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var xc={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},yh={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function jx(e,t){let n={},r=e._zod.def;for(let o in t){if(!(o in r.shape))throw new Error(`Unrecognized key: "${o}"`);t[o]&&(n[o]=r.shape[o])}return ct(e,{...e._zod.def,shape:n,checks:[]})}function Wx(e,t){let n={...e._zod.def.shape},r=e._zod.def;for(let o in t){if(!(o in r.shape))throw new Error(`Unrecognized key: "${o}"`);t[o]&&delete n[o]}return ct(e,{...e._zod.def,shape:n,checks:[]})}function qx(e,t){if(!er(t))throw new Error("Invalid input to extend: expected a plain object");let n={...e._zod.def,get shape(){let r={...e._zod.def.shape,...t};return bc(this,"shape",r),r},checks:[]};return ct(e,n)}function Yx(e,t){return ct(e,{...e._zod.def,get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return bc(this,"shape",n),n},catchall:t._zod.def.catchall,checks:[]})}function Xx(e,t,n){let r=t._zod.def.shape,o={...r};if(n)for(let i in n){if(!(i in r))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(o[i]=e?new e({type:"optional",innerType:r[i]}):r[i])}else for(let i in r)o[i]=e?new e({type:"optional",innerType:r[i]}):r[i];return ct(t,{...t._zod.def,shape:o,checks:[]})}function Kx(e,t,n){let r=t._zod.def.shape,o={...r};if(n)for(let i in n){if(!(i in o))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(o[i]=new e({type:"nonoptional",innerType:r[i]}))}else for(let i in r)o[i]=new e({type:"nonoptional",innerType:r[i]});return ct(t,{...t._zod.def,shape:o,checks:[]})}function pn(e,t=0){for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function St(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function Dr(e){return typeof e=="string"?e:e?.message}function ut(e,t,n){let r={...e,path:e.path??[]};if(!e.message){let o=Dr(e.inst?._zod.def?.error?.(e))??Dr(t?.error?.(e))??Dr(n.customError?.(e))??Dr(n.localeError?.(e))??"Invalid input";r.message=o}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function wh(e){return e instanceof Set?"set":e instanceof Map?"map":e instanceof File?"file":"unknown"}function Fr(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function _c(...e){let[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}function Jx(e){return Object.entries(e).filter(([t,n])=>Number.isNaN(Number.parseInt(t,10))).map(t=>t[1])}var fc=class{constructor(...t){}};var Eh=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),Object.defineProperty(e,"message",{get(){return JSON.stringify(t,gc,2)},enumerable:!0}),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Pi=A("$ZodError",Eh),Sc=A("$ZodError",Eh,{Parent:Error});function Tc(e,t=n=>n.message){let n={},r=[];for(let o of e.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(t(o))):r.push(t(o));return{formErrors:r,fieldErrors:n}}function Ac(e,t){let n=t||function(i){return i.message},r={_errors:[]},o=i=>{for(let a of i.issues)if(a.code==="invalid_union"&&a.errors.length)a.errors.map(s=>o({issues:s}));else if(a.code==="invalid_key")o({issues:a.issues});else if(a.code==="invalid_element")o({issues:a.issues});else if(a.path.length===0)r._errors.push(n(a));else{let s=r,l=0;for(;l<a.path.length;){let c=a.path[l];l===a.path.length-1?(s[c]=s[c]||{_errors:[]},s[c]._errors.push(n(a))):s[c]=s[c]||{_errors:[]},s=s[c],l++}}};return o(e),r}var xh=e=>(t,n,r,o)=>{let i=r?Object.assign(r,{async:!1}):{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Nt;if(a.issues.length){let s=new(o?.Err??e)(a.issues.map(l=>ut(l,i,$e())));throw Ni(s,o?.callee),s}return a.value};var _h=e=>async(t,n,r,o)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise&&(a=await a),a.issues.length){let s=new(o?.Err??e)(a.issues.map(l=>ut(l,i,$e())));throw Ni(s,o?.callee),s}return a.value};var kc=e=>(t,n,r)=>{let o=r?{...r,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},o);if(i instanceof Promise)throw new Nt;return i.issues.length?{success:!1,error:new(e??Pi)(i.issues.map(a=>ut(a,o,$e())))}:{success:!0,data:i.value}},Sh=kc(Sc),Ic=e=>async(t,n,r)=>{let o=r?Object.assign(r,{async:!0}):{async:!0},i=t._zod.run({value:n,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(a=>ut(a,o,$e())))}:{success:!0,data:i.value}},Th=Ic(Sc);var Ah=/^[cC][^\s-]{8,}$/,kh=/^[0-9a-z]+$/,Ih=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Rh=/^[0-9a-vA-V]{20}$/,Ch=/^[A-Za-z0-9]{27}$/,Nh=/^[a-zA-Z0-9_-]{21}$/,Oh=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Ph=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Rc=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/;var Mh=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var e_="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function zh(){return new RegExp(e_,"u")}var Lh=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Dh=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,$h=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Uh=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Hh=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Cc=/^[A-Za-z0-9_-]*$/,Fh=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;var Gh=/^\+(?:[0-9]){6,14}[0-9]$/,Bh="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Zh=new RegExp(`^${Bh}$`);function Vh(e){let t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function jh(e){return new RegExp(`^${Vh(e)}$`)}function Wh(e){let t=Vh({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-]\\d{2}:\\d{2})");let r=`${t}(?:${n.join("|")})`;return new RegExp(`^${Bh}T(?:${r})$`)}var qh=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)};var Yh=/^\d+$/,Xh=/^-?\d+(?:\.\d+)?/i,Kh=/true|false/i;var Jh=/^[^A-Z]*$/,Qh=/^[^a-z]*$/;var Ge=A("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),ef={number:"number",bigint:"bigint",object:"date"},Nc=A("$ZodCheckLessThan",(e,t)=>{Ge.init(e,t);let n=ef[typeof t.value];e._zod.onattach.push(r=>{let o=r._zod.bag,i=(t.inclusive?o.maximum:o.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<i&&(t.inclusive?o.maximum=t.value:o.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Oc=A("$ZodCheckGreaterThan",(e,t)=>{Ge.init(e,t);let n=ef[typeof t.value];e._zod.onattach.push(r=>{let o=r._zod.bag,i=(t.inclusive?o.minimum:o.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>i&&(t.inclusive?o.minimum=t.value:o.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tf=A("$ZodCheckMultipleOf",(e,t)=>{Ge.init(e,t),e._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):vc(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),nf=A("$ZodCheckNumberFormat",(e,t)=>{Ge.init(e,t),t.format=t.format||"float64";let n=t.format?.includes("int"),r=n?"int":"number",[o,i]=xc[t.format];e._zod.onattach.push(a=>{let s=a._zod.bag;s.format=t.format,s.minimum=o,s.maximum=i,n&&(s.pattern=Yh)}),e._zod.check=a=>{let s=a.value;if(n){if(!Number.isInteger(s)){a.issues.push({expected:r,format:t.format,code:"invalid_type",input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?a.issues.push({input:s,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}):a.issues.push({input:s,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort});return}}s<o&&a.issues.push({origin:"number",input:s,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort}),s>i&&a.issues.push({origin:"number",input:s,code:"too_big",maximum:i,inst:e})}});var rf=A("$ZodCheckMaxLength",(e,t)=>{var n;Ge.init(e,t),(n=e._zod.def).when??(n.when=r=>{let o=r.value;return!Ur(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{let o=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<o&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{let o=r.value;if(o.length<=t.maximum)return;let a=Fr(o);r.issues.push({origin:a,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),of=A("$ZodCheckMinLength",(e,t)=>{var n;Ge.init(e,t),(n=e._zod.def).when??(n.when=r=>{let o=r.value;return!Ur(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{let o=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>o&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{let o=r.value;if(o.length>=t.minimum)return;let a=Fr(o);r.issues.push({origin:a,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),af=A("$ZodCheckLengthEquals",(e,t)=>{var n;Ge.init(e,t),(n=e._zod.def).when??(n.when=r=>{let o=r.value;return!Ur(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{let o=r._zod.bag;o.minimum=t.length,o.maximum=t.length,o.length=t.length}),e._zod.check=r=>{let o=r.value,i=o.length;if(i===t.length)return;let a=Fr(o),s=i>t.length;r.issues.push({origin:a,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),Gr=A("$ZodCheckStringFormat",(e,t)=>{var n,r;Ge.init(e,t),e._zod.onattach.push(o=>{let i=o._zod.bag;i.format=t.format,t.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=o=>{t.pattern.lastIndex=0,!t.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),sf=A("$ZodCheckRegex",(e,t)=>{Gr.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),lf=A("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Jh),Gr.init(e,t)}),cf=A("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Qh),Gr.init(e,t)}),uf=A("$ZodCheckIncludes",(e,t)=>{Ge.init(e,t);let n=Ut(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(o=>{let i=o._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),e._zod.check=o=>{o.value.includes(t.includes,t.position)||o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),df=A("$ZodCheckStartsWith",(e,t)=>{Ge.init(e,t);let n=new RegExp(`^${Ut(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{let o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),pf=A("$ZodCheckEndsWith",(e,t)=>{Ge.init(e,t);let n=new RegExp(`.*${Ut(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{let o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}});var hf=A("$ZodCheckOverwrite",(e,t)=>{Ge.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});var zi=class{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}let r=t.split(`
|
|
6
|
-
`).filter(a=>a),o=Math.min(...r.map(a=>a.length-a.trimStart().length)),i=r.map(a=>a.slice(o)).map(a=>" ".repeat(this.indent*2)+a);for(let a of i)this.content.push(a)}compile(){let
|
|
7
|
-
`))}};var
|
|
4
|
+
`):"",this.name="UnsubscriptionError",this.errors=n}});function zr(t,e){if(t){var n=t.indexOf(e);0<=n&&t.splice(n,1)}}var Yn=(function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var e,n,r,o,i;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var s=Ot(a),c=s.next();!c.done;c=s.next()){var l=c.value;l.remove(this)}}catch(x){e={error:x}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}else a.remove(this);var u=this.initialTeardown;if(Q(u))try{u()}catch(x){i=x instanceof li?x.errors:[x]}var f=this._finalizers;if(f){this._finalizers=null;try{for(var m=Ot(f),p=m.next();!p.done;p=m.next()){var h=p.value;try{sh(h)}catch(x){i=i??[],x instanceof li?i=_t(_t([],xt(i)),xt(x.errors)):i.push(x)}}}catch(x){r={error:x}}finally{try{p&&!p.done&&(o=m.return)&&o.call(m)}finally{if(r)throw r.error}}}if(i)throw new li(i)}},t.prototype.add=function(e){var n;if(e&&e!==this)if(this.closed)sh(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(e)}},t.prototype._hasParent=function(e){var n=this._parentage;return n===e||Array.isArray(n)&&n.includes(e)},t.prototype._addParent=function(e){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(e),n):n?[n,e]:e},t.prototype._removeParent=function(e){var n=this._parentage;n===e?this._parentage=null:Array.isArray(n)&&zr(n,e)},t.prototype.remove=function(e){var n=this._finalizers;n&&zr(n,e),e instanceof t&&e._removeParent(this)},t.EMPTY=(function(){var e=new t;return e.closed=!0,e})(),t})();var dc=Yn.EMPTY;function ci(t){return t instanceof Yn||t&&"closed"in t&&Q(t.remove)&&Q(t.add)&&Q(t.unsubscribe)}function sh(t){Q(t)?t():t.unsubscribe()}var ct={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var Kn={setTimeout:function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=Kn.delegate;return o?.setTimeout?o.setTimeout.apply(o,_t([t,e],xt(n))):setTimeout.apply(void 0,_t([t,e],xt(n)))},clearTimeout:function(t){var e=Kn.delegate;return(e?.clearTimeout||clearTimeout)(t)},delegate:void 0};function ui(t){Kn.setTimeout(function(){var e=ct.onUnhandledError;if(e)e(t);else throw t})}function Dr(){}var lh=(function(){return pc("C",void 0,void 0)})();function ch(t){return pc("E",void 0,t)}function uh(t){return pc("N",t,void 0)}function pc(t,e,n){return{kind:t,value:e,error:n}}var dn=null;function Xn(t){if(ct.useDeprecatedSynchronousErrorHandling){var e=!dn;if(e&&(dn={errorThrown:!1,error:null}),t(),e){var n=dn,r=n.errorThrown,o=n.error;if(dn=null,r)throw o}}else t()}function dh(t){ct.useDeprecatedSynchronousErrorHandling&&dn&&(dn.errorThrown=!0,dn.error=t)}var $r=(function(t){Et(e,t);function e(n){var r=t.call(this)||this;return r.isStopped=!1,n?(r.destination=n,ci(n)&&n.add(r)):r.destination=Px,r}return e.create=function(n,r,o){return new pi(n,r,o)},e.prototype.next=function(n){this.isStopped?fc(uh(n),this):this._next(n)},e.prototype.error=function(n){this.isStopped?fc(ch(n),this):(this.isStopped=!0,this._error(n))},e.prototype.complete=function(){this.isStopped?fc(lh,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(n){this.destination.next(n)},e.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e})(Yn);var Cx=Function.prototype.bind;function hc(t,e){return Cx.call(t,e)}var Nx=(function(){function t(e){this.partialObserver=e}return t.prototype.next=function(e){var n=this.partialObserver;if(n.next)try{n.next(e)}catch(r){di(r)}},t.prototype.error=function(e){var n=this.partialObserver;if(n.error)try{n.error(e)}catch(r){di(r)}else di(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(n){di(n)}},t})(),pi=(function(t){Et(e,t);function e(n,r,o){var i=t.call(this)||this,a;if(Q(n)||!n)a={next:n??void 0,error:r??void 0,complete:o??void 0};else{var s;i&&ct.useDeprecatedNextContext?(s=Object.create(n),s.unsubscribe=function(){return i.unsubscribe()},a={next:n.next&&hc(n.next,s),error:n.error&&hc(n.error,s),complete:n.complete&&hc(n.complete,s)}):a=n}return i.destination=new Nx(a),i}return e})($r);function di(t){ct.useDeprecatedSynchronousErrorHandling?dh(t):ui(t)}function Ox(t){throw t}function fc(t,e){var n=ct.onStoppedNotification;n&&Kn.setTimeout(function(){return n(t,e)})}var Px={closed:!0,next:Dr,error:Ox,complete:Dr};var Jn=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Qn(t){return t}function hi(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return mc(t)}function mc(t){return t.length===0?Qn:t.length===1?t[0]:function(n){return t.reduce(function(r,o){return o(r)},n)}}var ve=(function(){function t(e){e&&(this._subscribe=e)}return t.prototype.lift=function(e){var n=new t;return n.source=this,n.operator=e,n},t.prototype.subscribe=function(e,n,r){var o=this,i=Lx(e)?e:new pi(e,n,r);return Xn(function(){var a=o,s=a.operator,c=a.source;i.add(s?s.call(i,c):c?o._subscribe(i):o._trySubscribe(i))}),i},t.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(n){e.error(n)}},t.prototype.forEach=function(e,n){var r=this;return n=ph(n),new n(function(o,i){var a=new pi({next:function(s){try{e(s)}catch(c){i(c),a.unsubscribe()}},error:i,complete:o});r.subscribe(a)})},t.prototype._subscribe=function(e){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(e)},t.prototype[Jn]=function(){return this},t.prototype.pipe=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return mc(e)(this)},t.prototype.toPromise=function(e){var n=this;return e=ph(e),new e(function(r,o){var i;n.subscribe(function(a){return i=a},function(a){return o(a)},function(){return r(i)})})},t.create=function(e){return new t(e)},t})();function ph(t){var e;return(e=t??ct.Promise)!==null&&e!==void 0?e:Promise}function Mx(t){return t&&Q(t.next)&&Q(t.error)&&Q(t.complete)}function Lx(t){return t&&t instanceof $r||Mx(t)&&ci(t)}function zx(t){return Q(t?.lift)}function Ee(t){return function(e){if(zx(e))return e.lift(function(n){try{return t(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function Ie(t,e,n,r,o){return new Dx(t,e,n,r,o)}var Dx=(function(t){Et(e,t);function e(n,r,o,i,a,s){var c=t.call(this,n)||this;return c.onFinalize=a,c.shouldUnsubscribe=s,c._next=r?function(l){try{r(l)}catch(u){n.error(u)}}:t.prototype._next,c._error=i?function(l){try{i(l)}catch(u){n.error(u)}finally{this.unsubscribe()}}:t.prototype._error,c._complete=o?function(){try{o()}catch(l){n.error(l)}finally{this.unsubscribe()}}:t.prototype._complete,c}return e.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;t.prototype.unsubscribe.call(this),!r&&((n=this.onFinalize)===null||n===void 0||n.call(this))}},e})($r);var hh=qn(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var St=(function(t){Et(e,t);function e(){var n=t.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return e.prototype.lift=function(n){var r=new fh(this,this);return r.operator=n,r},e.prototype._throwIfClosed=function(){if(this.closed)throw new hh},e.prototype.next=function(n){var r=this;Xn(function(){var o,i;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var a=Ot(r.currentObservers),s=a.next();!s.done;s=a.next()){var c=s.value;c.next(n)}}catch(l){o={error:l}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}}})},e.prototype.error=function(n){var r=this;Xn(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var o=r.observers;o.length;)o.shift().error(n)}})},e.prototype.complete=function(){var n=this;Xn(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(n){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,n)},e.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},e.prototype._innerSubscribe=function(n){var r=this,o=this,i=o.hasError,a=o.isStopped,s=o.observers;return i||a?dc:(this.currentObservers=null,s.push(n),new Yn(function(){r.currentObservers=null,zr(s,n)}))},e.prototype._checkFinalizedStatuses=function(n){var r=this,o=r.hasError,i=r.thrownError,a=r.isStopped;o?n.error(i):a&&n.complete()},e.prototype.asObservable=function(){var n=new ve;return n.source=this,n},e.create=function(n,r){return new fh(n,r)},e})(ve);var fh=(function(t){Et(e,t);function e(n,r){var o=t.call(this)||this;return o.destination=n,o.source=r,o}return e.prototype.next=function(n){var r,o;(o=(r=this.destination)===null||r===void 0?void 0:r.next)===null||o===void 0||o.call(r,n)},e.prototype.error=function(n){var r,o;(o=(r=this.destination)===null||r===void 0?void 0:r.error)===null||o===void 0||o.call(r,n)},e.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},e.prototype._subscribe=function(n){var r,o;return(o=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&o!==void 0?o:dc},e})(St);var gc={now:function(){return(gc.delegate||Date).now()},delegate:void 0};var fi=(function(t){Et(e,t);function e(n,r,o){n===void 0&&(n=1/0),r===void 0&&(r=1/0),o===void 0&&(o=gc);var i=t.call(this)||this;return i._bufferSize=n,i._windowTime=r,i._timestampProvider=o,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=r===1/0,i._bufferSize=Math.max(1,n),i._windowTime=Math.max(1,r),i}return e.prototype.next=function(n){var r=this,o=r.isStopped,i=r._buffer,a=r._infiniteTimeWindow,s=r._timestampProvider,c=r._windowTime;o||(i.push(n),!a&&i.push(s.now()+c)),this._trimBuffer(),t.prototype.next.call(this,n)},e.prototype._subscribe=function(n){this._throwIfClosed(),this._trimBuffer();for(var r=this._innerSubscribe(n),o=this,i=o._infiniteTimeWindow,a=o._buffer,s=a.slice(),c=0;c<s.length&&!n.closed;c+=i?1:2)n.next(s[c]);return this._checkFinalizedStatuses(n),r},e.prototype._trimBuffer=function(){var n=this,r=n._bufferSize,o=n._timestampProvider,i=n._buffer,a=n._infiniteTimeWindow,s=(a?1:2)*r;if(r<1/0&&s<i.length&&i.splice(0,i.length-s),!a){for(var c=o.now(),l=0,u=1;u<i.length&&i[u]<=c;u+=2)l=u;l&&i.splice(0,l+1)}},e})(St);var pn=new ve(function(t){return t.complete()});function mh(t){return t&&Q(t.schedule)}function $x(t){return t[t.length-1]}function mi(t){return mh($x(t))?t.pop():void 0}var gi=(function(t){return t&&typeof t.length=="number"&&typeof t!="function"});function vi(t){return Q(t?.then)}function bi(t){return Q(t[Jn])}function yi(t){return Symbol.asyncIterator&&Q(t?.[Symbol.asyncIterator])}function wi(t){return new TypeError("You provided "+(t!==null&&typeof t=="object"?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Ux(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Ei=Ux();function xi(t){return Q(t?.[Ei])}function _i(t){return ih(this,arguments,function(){var n,r,o,i;return si(this,function(a){switch(a.label){case 0:n=t.getReader(),a.label=1;case 1:a.trys.push([1,,9,10]),a.label=2;case 2:return[4,un(n.read())];case 3:return r=a.sent(),o=r.value,i=r.done,i?[4,un(void 0)]:[3,5];case 4:return[2,a.sent()];case 5:return[4,un(o)];case 6:return[4,a.sent()];case 7:return a.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}})})}function Si(t){return Q(t?.getReader)}function Me(t){if(t instanceof ve)return t;if(t!=null){if(bi(t))return Hx(t);if(gi(t))return Fx(t);if(vi(t))return Gx(t);if(yi(t))return gh(t);if(xi(t))return Bx(t);if(Si(t))return Zx(t)}throw wi(t)}function Hx(t){return new ve(function(e){var n=t[Jn]();if(Q(n.subscribe))return n.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Fx(t){return new ve(function(e){for(var n=0;n<t.length&&!e.closed;n++)e.next(t[n]);e.complete()})}function Gx(t){return new ve(function(e){t.then(function(n){e.closed||(e.next(n),e.complete())},function(n){return e.error(n)}).then(null,ui)})}function Bx(t){return new ve(function(e){var n,r;try{for(var o=Ot(t),i=o.next();!i.done;i=o.next()){var a=i.value;if(e.next(a),e.closed)return}}catch(s){n={error:s}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}e.complete()})}function gh(t){return new ve(function(e){Vx(t,e).catch(function(n){return e.error(n)})})}function Zx(t){return gh(_i(t))}function Vx(t,e){var n,r,o,i;return oh(this,void 0,void 0,function(){var a,s;return si(this,function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),n=ah(t),c.label=1;case 1:return[4,n.next()];case 2:if(r=c.sent(),!!r.done)return[3,4];if(a=r.value,e.next(a),e.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return s=c.sent(),o={error:s},[3,11];case 6:return c.trys.push([6,,9,10]),r&&!r.done&&(i=n.return)?[4,i.call(n)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}function ot(t,e,n,r,o){r===void 0&&(r=0),o===void 0&&(o=!1);var i=e.schedule(function(){n(),o?t.add(this.schedule(null,r)):this.unsubscribe()},r);if(t.add(i),!o)return i}function Ti(t,e){return e===void 0&&(e=0),Ee(function(n,r){n.subscribe(Ie(r,function(o){return ot(r,t,function(){return r.next(o)},e)},function(){return ot(r,t,function(){return r.complete()},e)},function(o){return ot(r,t,function(){return r.error(o)},e)}))})}function Ai(t,e){return e===void 0&&(e=0),Ee(function(n,r){r.add(t.schedule(function(){return n.subscribe(r)},e))})}function vh(t,e){return Me(t).pipe(Ai(e),Ti(e))}function bh(t,e){return Me(t).pipe(Ai(e),Ti(e))}function yh(t,e){return new ve(function(n){var r=0;return e.schedule(function(){r===t.length?n.complete():(n.next(t[r++]),n.closed||this.schedule())})})}function wh(t,e){return new ve(function(n){var r;return ot(n,e,function(){r=t[Ei](),ot(n,e,function(){var o,i,a;try{o=r.next(),i=o.value,a=o.done}catch(s){n.error(s);return}a?n.complete():n.next(i)},0,!0)}),function(){return Q(r?.return)&&r.return()}})}function ki(t,e){if(!t)throw new Error("Iterable cannot be null");return new ve(function(n){ot(n,e,function(){var r=t[Symbol.asyncIterator]();ot(n,e,function(){r.next().then(function(o){o.done?n.complete():n.next(o.value)})},0,!0)})})}function Eh(t,e){return ki(_i(t),e)}function xh(t,e){if(t!=null){if(bi(t))return vh(t,e);if(gi(t))return yh(t,e);if(vi(t))return bh(t,e);if(yi(t))return ki(t,e);if(xi(t))return wh(t,e);if(Si(t))return Eh(t,e)}throw wi(t)}function Pt(t,e){return e?xh(t,e):Me(t)}function ue(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=mi(t);return Pt(t,n)}function F(t,e){var n=Q(t)?t:function(){return t},r=function(o){return o.error(n())};return new ve(e?function(o){return e.schedule(r,0,o)}:r)}var _h=qn(function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}});function Ii(t,e){var n=typeof e=="object";return new Promise(function(r,o){var i=!1,a;t.subscribe({next:function(s){a=s,i=!0},error:o,complete:function(){i?r(a):n?r(e.defaultValue):o(new _h)}})})}function Tt(t,e){return Ee(function(n,r){var o=0;n.subscribe(Ie(r,function(i){r.next(t.call(e,i,o++))}))})}function Sh(t,e,n,r,o,i,a,s){var c=[],l=0,u=0,f=!1,m=function(){f&&!c.length&&!l&&e.complete()},p=function(x){return l<r?h(x):c.push(x)},h=function(x){i&&e.next(x),l++;var g=!1;Me(n(x,u++)).subscribe(Ie(e,function(w){o?.(w),i?p(w):e.next(w)},function(){g=!0},void 0,function(){if(g)try{l--;for(var w=function(){var b=c.shift();a?ot(e,a,function(){return h(b)}):h(b)};c.length&&l<r;)w();m()}catch(b){e.error(b)}}))};return t.subscribe(Ie(e,p,function(){f=!0,m()})),function(){s?.()}}function We(t,e,n){return n===void 0&&(n=1/0),Q(e)?We(function(r,o){return Tt(function(i,a){return e(r,i,o,a)})(Me(t(r,o)))},n):(typeof e=="number"&&(n=e),Ee(function(r,o){return Sh(r,o,t,n)}))}function Ur(t){return t===void 0&&(t=1/0),We(Qn,t)}function Th(){return Ur(1)}function hn(t){return new ve(function(e){Me(t()).subscribe(e)})}function vc(t,e){return Ee(function(n,r){var o=0;n.subscribe(Ie(r,function(i){return t.call(e,i,o++)&&r.next(i)}))})}function er(t){return Ee(function(e,n){var r=null,o=!1,i;r=e.subscribe(Ie(n,void 0,void 0,function(a){i=Me(t(a,er(t)(e))),r?(r.unsubscribe(),r=null,i.subscribe(n)):o=!0})),o&&(r.unsubscribe(),r=null,i.subscribe(n))})}function Ri(t,e){return Q(e)?We(t,e,1):We(t,1)}function Ah(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=mi(t);return Ee(function(r,o){Th()(Pt(_t([r],xt(t)),n)).subscribe(o)})}function bc(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ah.apply(void 0,_t([],xt(t)))}function yc(t){return Ee(function(e,n){var r=!1;e.subscribe(Ie(n,function(o){r=!0,n.next(o)},function(){r||n.next(t),n.complete()}))})}function fn(t){return Ee(function(e,n){try{e.subscribe(n)}finally{n.add(t)}})}function wc(t,e){return Ee(function(n,r){var o=null,i=0,a=!1,s=function(){return a&&!o&&r.complete()};n.subscribe(Ie(r,function(c){o?.unsubscribe();var l=0,u=i++;Me(t(c,u)).subscribe(o=Ie(r,function(f){return r.next(e?e(c,f,u,l++):f)},function(){o=null,s()}))},function(){a=!0,s()}))})}function Ci(t){return Ee(function(e,n){Me(t).subscribe(Ie(n,function(){return n.complete()},Dr)),!n.closed&&e.subscribe(n)})}function Ni(t,e,n){var r=Q(t)||e||n?{next:t,error:e,complete:n}:t;return r?Ee(function(o,i){var a;(a=r.subscribe)===null||a===void 0||a.call(r);var s=!0;o.subscribe(Ie(i,function(c){var l;(l=r.next)===null||l===void 0||l.call(r,c),i.next(c)},function(){var c;s=!1,(c=r.complete)===null||c===void 0||c.call(r),i.complete()},function(c){var l;s=!1,(l=r.error)===null||l===void 0||l.call(r,c),i.error(c)},function(){var c,l;s&&((c=r.unsubscribe)===null||c===void 0||c.call(r)),(l=r.finalize)===null||l===void 0||l.call(r)}))}):Qn}function kh(t){return` \r
|
|
5
|
+
`.indexOf(t)>=0}function Oi(t){for(var e=["topLevel"],n=0,r,o,i,a=function(b){return e.push(b)},s=function(b){return e[e.length-1]=b},c=function(b){r==null&&(r=n,o=e.length,i=b)},l=function(b){b===i&&(r=void 0,o=void 0,i=void 0)},u=function(){return e.pop()},f=function(){return n--},m=function(b){if("0"<=b&&b<="9"){a("number");return}switch(b){case'"':a("string");return;case"-":a("numberNeedsDigit");return;case"t":a("true");return;case"f":a("false");return;case"n":a("null");return;case"[":a("arrayNeedsValue");return;case"{":a("objectNeedsKey");return}},p=t.length;n<p;n++){var h=t[n];switch(e[e.length-1]){case"topLevel":m(h);break;case"string":switch(h){case'"':u();break;case"\\":c("stringEscape"),a("stringEscaped");break}break;case"stringEscaped":h==="u"?a("stringUnicode"):(l("stringEscape"),u());break;case"stringUnicode":n-t.lastIndexOf("u",n)===4&&(l("stringEscape"),u());break;case"number":h==="."?s("numberNeedsDigit"):h==="e"||h==="E"?s("numberNeedsExponent"):(h<"0"||h>"9")&&(f(),u());break;case"numberNeedsDigit":s("number");break;case"numberNeedsExponent":s(h==="+"||h==="-"?"numberNeedsDigit":"number");break;case"true":case"false":case"null":(h<"a"||h>"z")&&(f(),u());break;case"arrayNeedsValue":h==="]"?u():kh(h)||(l("collectionItem"),s("arrayNeedsComma"),m(h));break;case"arrayNeedsComma":h==="]"?u():h===","&&(c("collectionItem"),s("arrayNeedsValue"));break;case"objectNeedsKey":h==="}"?u():h==='"'&&(c("collectionItem"),s("objectNeedsColon"),a("string"));break;case"objectNeedsColon":h===":"&&s("objectNeedsValue");break;case"objectNeedsValue":kh(h)||(l("collectionItem"),s("objectNeedsComma"),m(h));break;case"objectNeedsComma":h==="}"?u():h===","&&(c("collectionItem"),s("objectNeedsKey"));break}}o!=null&&(e.length=o);for(var x=[r!=null?t.slice(0,r):t],g=function(b){return x.push(b.slice(t.length-t.lastIndexOf(b[0])))},w=e.length-1;w>=0;w--)switch(e[w]){case"string":x.push('"');break;case"numberNeedsDigit":case"numberNeedsExponent":x.push("0");break;case"true":g("true");break;case"false":g("false");break;case"null":g("null");break;case"arrayNeedsValue":case"arrayNeedsComma":x.push("]");break;case"objectNeedsKey":case"objectNeedsColon":case"objectNeedsValue":case"objectNeedsComma":x.push("}");break}return x.join("")}var jx=Object.freeze({status:"aborted"});function A(t,e,n){function r(s,c){var l;Object.defineProperty(s,"_zod",{value:s._zod??{},enumerable:!1}),(l=s._zod).traits??(l.traits=new Set),s._zod.traits.add(t),e(s,c);for(let u in a.prototype)u in s||Object.defineProperty(s,u,{value:a.prototype[u].bind(s)});s._zod.constr=a,s._zod.def=c}let o=n?.Parent??Object;class i extends o{}Object.defineProperty(i,"name",{value:t});function a(s){var c;let l=n?.Parent?new i:this;r(l,s),(c=l._zod).deferred??(c.deferred=[]);for(let u of l._zod.deferred)u();return l}return Object.defineProperty(a,"init",{value:r}),Object.defineProperty(a,Symbol.hasInstance,{value:s=>n?.Parent&&s instanceof n.Parent?!0:s?._zod?.traits?.has(t)}),Object.defineProperty(a,"name",{value:t}),a}var Mt=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}},Pi={};function Ue(t){return t&&Object.assign(Pi,t),Pi}var ce={};_l(ce,{BIGINT_FORMAT_RANGES:()=>Rh,Class:()=>xc,NUMBER_FORMAT_RANGES:()=>Cc,aborted:()=>gn,allowsEval:()=>kc,assert:()=>Xx,assertEqual:()=>Wx,assertIs:()=>Yx,assertNever:()=>Kx,assertNotEqual:()=>qx,assignProp:()=>Ac,cached:()=>Fr,captureStackTrace:()=>Li,cleanEnum:()=>u_,cleanRegex:()=>Br,clone:()=>ut,createTransparentProxy:()=>r_,defineLazy:()=>le,esc:()=>mn,escapeRegex:()=>Gt,extend:()=>a_,finalizeIssue:()=>dt,floatSafeRemainder:()=>Tc,getElementAtPath:()=>Jx,getEnumValues:()=>_c,getLengthableOrigin:()=>Zr,getParsedType:()=>n_,getSizableOrigin:()=>Ch,isObject:()=>tr,isPlainObject:()=>nr,issue:()=>Nc,joinValues:()=>Mi,jsonStringifyReplacer:()=>Sc,merge:()=>s_,normalizeParams:()=>G,nullish:()=>Gr,numKeys:()=>t_,omit:()=>i_,optionalKeys:()=>Rc,partial:()=>l_,pick:()=>o_,prefixIssues:()=>At,primitiveTypes:()=>Ih,promiseAllObject:()=>Qx,propertyKeyTypes:()=>Ic,randomString:()=>e_,required:()=>c_,stringifyPrimitive:()=>zi,unwrapMessage:()=>Hr});function Wx(t){return t}function qx(t){return t}function Yx(t){}function Kx(t){throw new Error}function Xx(t){}function _c(t){let e=Object.values(t).filter(r=>typeof r=="number");return Object.entries(t).filter(([r,o])=>e.indexOf(+r)===-1).map(([r,o])=>o)}function Mi(t,e="|"){return t.map(n=>zi(n)).join(e)}function Sc(t,e){return typeof e=="bigint"?e.toString():e}function Fr(t){return{get value(){{let n=t();return Object.defineProperty(this,"value",{value:n}),n}throw new Error("cached value already set")}}}function Gr(t){return t==null}function Br(t){let e=t.startsWith("^")?1:0,n=t.endsWith("$")?t.length-1:t.length;return t.slice(e,n)}function Tc(t,e){let n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,o=n>r?n:r,i=Number.parseInt(t.toFixed(o).replace(".","")),a=Number.parseInt(e.toFixed(o).replace(".",""));return i%a/10**o}function le(t,e,n){Object.defineProperty(t,e,{get(){{let o=n();return t[e]=o,o}throw new Error("cached value already set")},set(o){Object.defineProperty(t,e,{value:o})},configurable:!0})}function Ac(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Jx(t,e){return e?e.reduce((n,r)=>n?.[r],t):t}function Qx(t){let e=Object.keys(t),n=e.map(r=>t[r]);return Promise.all(n).then(r=>{let o={};for(let i=0;i<e.length;i++)o[e[i]]=r[i];return o})}function e_(t=10){let e="abcdefghijklmnopqrstuvwxyz",n="";for(let r=0;r<t;r++)n+=e[Math.floor(Math.random()*e.length)];return n}function mn(t){return JSON.stringify(t)}var Li=Error.captureStackTrace?Error.captureStackTrace:(...t)=>{};function tr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}var kc=Fr(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{let t=Function;return new t(""),!0}catch{return!1}});function nr(t){if(tr(t)===!1)return!1;let e=t.constructor;if(e===void 0)return!0;let n=e.prototype;return!(tr(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function t_(t){let e=0;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&e++;return e}var n_=t=>{let e=typeof t;switch(e){case"undefined":return"undefined";case"string":return"string";case"number":return Number.isNaN(t)?"nan":"number";case"boolean":return"boolean";case"function":return"function";case"bigint":return"bigint";case"symbol":return"symbol";case"object":return Array.isArray(t)?"array":t===null?"null":t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?"promise":typeof Map<"u"&&t instanceof Map?"map":typeof Set<"u"&&t instanceof Set?"set":typeof Date<"u"&&t instanceof Date?"date":typeof File<"u"&&t instanceof File?"file":"object";default:throw new Error(`Unknown data type: ${e}`)}},Ic=new Set(["string","number","symbol"]),Ih=new Set(["string","number","bigint","boolean","symbol","undefined"]);function Gt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ut(t,e,n){let r=new t._zod.constr(e??t._zod.def);return(!e||n?.parent)&&(r._zod.parent=t),r}function G(t){let e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function r_(t){let e;return new Proxy({},{get(n,r,o){return e??(e=t()),Reflect.get(e,r,o)},set(n,r,o,i){return e??(e=t()),Reflect.set(e,r,o,i)},has(n,r){return e??(e=t()),Reflect.has(e,r)},deleteProperty(n,r){return e??(e=t()),Reflect.deleteProperty(e,r)},ownKeys(n){return e??(e=t()),Reflect.ownKeys(e)},getOwnPropertyDescriptor(n,r){return e??(e=t()),Reflect.getOwnPropertyDescriptor(e,r)},defineProperty(n,r,o){return e??(e=t()),Reflect.defineProperty(e,r,o)}})}function zi(t){return typeof t=="bigint"?t.toString()+"n":typeof t=="string"?`"${t}"`:`${t}`}function Rc(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}var Cc={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},Rh={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function o_(t,e){let n={},r=t._zod.def;for(let o in e){if(!(o in r.shape))throw new Error(`Unrecognized key: "${o}"`);e[o]&&(n[o]=r.shape[o])}return ut(t,{...t._zod.def,shape:n,checks:[]})}function i_(t,e){let n={...t._zod.def.shape},r=t._zod.def;for(let o in e){if(!(o in r.shape))throw new Error(`Unrecognized key: "${o}"`);e[o]&&delete n[o]}return ut(t,{...t._zod.def,shape:n,checks:[]})}function a_(t,e){if(!nr(e))throw new Error("Invalid input to extend: expected a plain object");let n={...t._zod.def,get shape(){let r={...t._zod.def.shape,...e};return Ac(this,"shape",r),r},checks:[]};return ut(t,n)}function s_(t,e){return ut(t,{...t._zod.def,get shape(){let n={...t._zod.def.shape,...e._zod.def.shape};return Ac(this,"shape",n),n},catchall:e._zod.def.catchall,checks:[]})}function l_(t,e,n){let r=e._zod.def.shape,o={...r};if(n)for(let i in n){if(!(i in r))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(o[i]=t?new t({type:"optional",innerType:r[i]}):r[i])}else for(let i in r)o[i]=t?new t({type:"optional",innerType:r[i]}):r[i];return ut(e,{...e._zod.def,shape:o,checks:[]})}function c_(t,e,n){let r=e._zod.def.shape,o={...r};if(n)for(let i in n){if(!(i in o))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(o[i]=new t({type:"nonoptional",innerType:r[i]}))}else for(let i in r)o[i]=new t({type:"nonoptional",innerType:r[i]});return ut(e,{...e._zod.def,shape:o,checks:[]})}function gn(t,e=0){for(let n=e;n<t.issues.length;n++)if(t.issues[n]?.continue!==!0)return!0;return!1}function At(t,e){return e.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(t),n})}function Hr(t){return typeof t=="string"?t:t?.message}function dt(t,e,n){let r={...t,path:t.path??[]};if(!t.message){let o=Hr(t.inst?._zod.def?.error?.(t))??Hr(e?.error?.(t))??Hr(n.customError?.(t))??Hr(n.localeError?.(t))??"Invalid input";r.message=o}return delete r.inst,delete r.continue,e?.reportInput||delete r.input,r}function Ch(t){return t instanceof Set?"set":t instanceof Map?"map":t instanceof File?"file":"unknown"}function Zr(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function Nc(...t){let[e,n,r]=t;return typeof e=="string"?{message:e,code:"custom",input:n,inst:r}:{...e}}function u_(t){return Object.entries(t).filter(([e,n])=>Number.isNaN(Number.parseInt(e,10))).map(e=>e[1])}var xc=class{constructor(...e){}};var Nh=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),Object.defineProperty(t,"message",{get(){return JSON.stringify(e,Sc,2)},enumerable:!0}),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Di=A("$ZodError",Nh),Oc=A("$ZodError",Nh,{Parent:Error});function Pc(t,e=n=>n.message){let n={},r=[];for(let o of t.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(e(o))):r.push(e(o));return{formErrors:r,fieldErrors:n}}function Mc(t,e){let n=e||function(i){return i.message},r={_errors:[]},o=i=>{for(let a of i.issues)if(a.code==="invalid_union"&&a.errors.length)a.errors.map(s=>o({issues:s}));else if(a.code==="invalid_key")o({issues:a.issues});else if(a.code==="invalid_element")o({issues:a.issues});else if(a.path.length===0)r._errors.push(n(a));else{let s=r,c=0;for(;c<a.path.length;){let l=a.path[c];c===a.path.length-1?(s[l]=s[l]||{_errors:[]},s[l]._errors.push(n(a))):s[l]=s[l]||{_errors:[]},s=s[l],c++}}};return o(t),r}var Oh=t=>(e,n,r,o)=>{let i=r?Object.assign(r,{async:!1}):{async:!1},a=e._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Mt;if(a.issues.length){let s=new(o?.Err??t)(a.issues.map(c=>dt(c,i,Ue())));throw Li(s,o?.callee),s}return a.value};var Ph=t=>async(e,n,r,o)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=e._zod.run({value:n,issues:[]},i);if(a instanceof Promise&&(a=await a),a.issues.length){let s=new(o?.Err??t)(a.issues.map(c=>dt(c,i,Ue())));throw Li(s,o?.callee),s}return a.value};var Lc=t=>(e,n,r)=>{let o=r?{...r,async:!1}:{async:!1},i=e._zod.run({value:n,issues:[]},o);if(i instanceof Promise)throw new Mt;return i.issues.length?{success:!1,error:new(t??Di)(i.issues.map(a=>dt(a,o,Ue())))}:{success:!0,data:i.value}},Mh=Lc(Oc),zc=t=>async(e,n,r)=>{let o=r?Object.assign(r,{async:!0}):{async:!0},i=e._zod.run({value:n,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new t(i.issues.map(a=>dt(a,o,Ue())))}:{success:!0,data:i.value}},Lh=zc(Oc);var zh=/^[cC][^\s-]{8,}$/,Dh=/^[0-9a-z]+$/,$h=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Uh=/^[0-9a-vA-V]{20}$/,Hh=/^[A-Za-z0-9]{27}$/,Fh=/^[a-zA-Z0-9_-]{21}$/,Gh=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Bh=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Dc=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/;var Zh=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var p_="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Vh(){return new RegExp(p_,"u")}var jh=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Wh=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,qh=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Yh=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Kh=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,$c=/^[A-Za-z0-9_-]*$/,Xh=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;var Jh=/^\+(?:[0-9]){6,14}[0-9]$/,Qh="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",ef=new RegExp(`^${Qh}$`);function tf(t){let e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function nf(t){return new RegExp(`^${tf(t)}$`)}function rf(t){let e=tf({precision:t.precision}),n=["Z"];t.local&&n.push(""),t.offset&&n.push("([+-]\\d{2}:\\d{2})");let r=`${e}(?:${n.join("|")})`;return new RegExp(`^${Qh}T(?:${r})$`)}var of=t=>{let e=t?`[\\s\\S]{${t?.minimum??0},${t?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)};var af=/^\d+$/,sf=/^-?\d+(?:\.\d+)?/i,lf=/true|false/i;var cf=/^[^A-Z]*$/,uf=/^[^a-z]*$/;var Be=A("$ZodCheck",(t,e)=>{var n;t._zod??(t._zod={}),t._zod.def=e,(n=t._zod).onattach??(n.onattach=[])}),df={number:"number",bigint:"bigint",object:"date"},Uc=A("$ZodCheckLessThan",(t,e)=>{Be.init(t,e);let n=df[typeof e.value];t._zod.onattach.push(r=>{let o=r._zod.bag,i=(e.inclusive?o.maximum:o.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<i&&(e.inclusive?o.maximum=e.value:o.exclusiveMaximum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value<=e.value:r.value<e.value)||r.issues.push({origin:n,code:"too_big",maximum:e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),Hc=A("$ZodCheckGreaterThan",(t,e)=>{Be.init(t,e);let n=df[typeof e.value];t._zod.onattach.push(r=>{let o=r._zod.bag,i=(e.inclusive?o.minimum:o.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>i&&(e.inclusive?o.minimum=e.value:o.exclusiveMinimum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value>=e.value:r.value>e.value)||r.issues.push({origin:n,code:"too_small",minimum:e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),pf=A("$ZodCheckMultipleOf",(t,e)=>{Be.init(t,e),t._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=e.value)}),t._zod.check=n=>{if(typeof n.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%e.value===BigInt(0):Tc(n.value,e.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:e.value,input:n.value,inst:t,continue:!e.abort})}}),hf=A("$ZodCheckNumberFormat",(t,e)=>{Be.init(t,e),e.format=e.format||"float64";let n=e.format?.includes("int"),r=n?"int":"number",[o,i]=Cc[e.format];t._zod.onattach.push(a=>{let s=a._zod.bag;s.format=e.format,s.minimum=o,s.maximum=i,n&&(s.pattern=af)}),t._zod.check=a=>{let s=a.value;if(n){if(!Number.isInteger(s)){a.issues.push({expected:r,format:e.format,code:"invalid_type",input:s,inst:t});return}if(!Number.isSafeInteger(s)){s>0?a.issues.push({input:s,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,continue:!e.abort}):a.issues.push({input:s,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,continue:!e.abort});return}}s<o&&a.issues.push({origin:"number",input:s,code:"too_small",minimum:o,inclusive:!0,inst:t,continue:!e.abort}),s>i&&a.issues.push({origin:"number",input:s,code:"too_big",maximum:i,inst:t})}});var ff=A("$ZodCheckMaxLength",(t,e)=>{var n;Be.init(t,e),(n=t._zod.def).when??(n.when=r=>{let o=r.value;return!Gr(o)&&o.length!==void 0}),t._zod.onattach.push(r=>{let o=r._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<o&&(r._zod.bag.maximum=e.maximum)}),t._zod.check=r=>{let o=r.value;if(o.length<=e.maximum)return;let a=Zr(o);r.issues.push({origin:a,code:"too_big",maximum:e.maximum,inclusive:!0,input:o,inst:t,continue:!e.abort})}}),mf=A("$ZodCheckMinLength",(t,e)=>{var n;Be.init(t,e),(n=t._zod.def).when??(n.when=r=>{let o=r.value;return!Gr(o)&&o.length!==void 0}),t._zod.onattach.push(r=>{let o=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>o&&(r._zod.bag.minimum=e.minimum)}),t._zod.check=r=>{let o=r.value;if(o.length>=e.minimum)return;let a=Zr(o);r.issues.push({origin:a,code:"too_small",minimum:e.minimum,inclusive:!0,input:o,inst:t,continue:!e.abort})}}),gf=A("$ZodCheckLengthEquals",(t,e)=>{var n;Be.init(t,e),(n=t._zod.def).when??(n.when=r=>{let o=r.value;return!Gr(o)&&o.length!==void 0}),t._zod.onattach.push(r=>{let o=r._zod.bag;o.minimum=e.length,o.maximum=e.length,o.length=e.length}),t._zod.check=r=>{let o=r.value,i=o.length;if(i===e.length)return;let a=Zr(o),s=i>e.length;r.issues.push({origin:a,...s?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:r.value,inst:t,continue:!e.abort})}}),Vr=A("$ZodCheckStringFormat",(t,e)=>{var n,r;Be.init(t,e),t._zod.onattach.push(o=>{let i=o._zod.bag;i.format=e.format,e.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(e.pattern))}),e.pattern?(n=t._zod).check??(n.check=o=>{e.pattern.lastIndex=0,!e.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:e.format,input:o.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(r=t._zod).check??(r.check=()=>{})}),vf=A("$ZodCheckRegex",(t,e)=>{Vr.init(t,e),t._zod.check=n=>{e.pattern.lastIndex=0,!e.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:e.pattern.toString(),inst:t,continue:!e.abort})}}),bf=A("$ZodCheckLowerCase",(t,e)=>{e.pattern??(e.pattern=cf),Vr.init(t,e)}),yf=A("$ZodCheckUpperCase",(t,e)=>{e.pattern??(e.pattern=uf),Vr.init(t,e)}),wf=A("$ZodCheckIncludes",(t,e)=>{Be.init(t,e);let n=Gt(e.includes),r=new RegExp(typeof e.position=="number"?`^.{${e.position}}${n}`:n);e.pattern=r,t._zod.onattach.push(o=>{let i=o._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),t._zod.check=o=>{o.value.includes(e.includes,e.position)||o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:e.includes,input:o.value,inst:t,continue:!e.abort})}}),Ef=A("$ZodCheckStartsWith",(t,e)=>{Be.init(t,e);let n=new RegExp(`^${Gt(e.prefix)}.*`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{let o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),t._zod.check=r=>{r.value.startsWith(e.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:e.prefix,input:r.value,inst:t,continue:!e.abort})}}),xf=A("$ZodCheckEndsWith",(t,e)=>{Be.init(t,e);let n=new RegExp(`.*${Gt(e.suffix)}$`);e.pattern??(e.pattern=n),t._zod.onattach.push(r=>{let o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),t._zod.check=r=>{r.value.endsWith(e.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:e.suffix,input:r.value,inst:t,continue:!e.abort})}});var _f=A("$ZodCheckOverwrite",(t,e)=>{Be.init(t,e),t._zod.check=n=>{n.value=e.tx(n.value)}});var Ui=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let r=e.split(`
|
|
6
|
+
`).filter(a=>a),o=Math.min(...r.map(a=>a.length-a.trimStart().length)),i=r.map(a=>a.slice(o)).map(a=>" ".repeat(this.indent*2)+a);for(let a of i)this.content.push(a)}compile(){let e=Function,n=this?.args,o=[...(this?.content??[""]).map(i=>` ${i}`)];return new e(...n,o.join(`
|
|
7
|
+
`))}};var Tf={major:4,minor:0,patch:0};var de=A("$ZodType",(t,e)=>{var n;t??(t={}),t._zod.def=e,t._zod.bag=t._zod.bag||{},t._zod.version=Tf;let r=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&r.unshift(t);for(let o of r)for(let i of o._zod.onattach)i(t);if(r.length===0)(n=t._zod).deferred??(n.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{let o=(i,a,s)=>{let c=gn(i),l;for(let u of a){if(u._zod.def.when){if(!u._zod.def.when(i))continue}else if(c)continue;let f=i.issues.length,m=u._zod.check(i);if(m instanceof Promise&&s?.async===!1)throw new Mt;if(l||m instanceof Promise)l=(l??Promise.resolve()).then(async()=>{await m,i.issues.length!==f&&(c||(c=gn(i,f)))});else{if(i.issues.length===f)continue;c||(c=gn(i,f))}}return l?l.then(()=>i):i};t._zod.run=(i,a)=>{let s=t._zod.parse(i,a);if(s instanceof Promise){if(a.async===!1)throw new Mt;return s.then(c=>o(c,r,a))}return o(s,r,a)}}t["~standard"]={validate:o=>{try{let i=Mh(t,o);return i.success?{value:i.data}:{issues:i.error?.issues}}catch{return Lh(t,o).then(a=>a.success?{value:a.data}:{issues:a.error?.issues})}},vendor:"zod",version:1}}),Fi=A("$ZodString",(t,e)=>{de.init(t,e),t._zod.pattern=[...t?._zod.bag?.patterns??[]].pop()??of(t._zod.bag),t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:t}),n}}),be=A("$ZodStringFormat",(t,e)=>{Vr.init(t,e),Fi.init(t,e)}),Lf=A("$ZodGUID",(t,e)=>{e.pattern??(e.pattern=Bh),be.init(t,e)}),zf=A("$ZodUUID",(t,e)=>{if(e.version){let r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[e.version];if(r===void 0)throw new Error(`Invalid UUID version: "${e.version}"`);e.pattern??(e.pattern=Dc(r))}else e.pattern??(e.pattern=Dc());be.init(t,e)}),Df=A("$ZodEmail",(t,e)=>{e.pattern??(e.pattern=Zh),be.init(t,e)}),$f=A("$ZodURL",(t,e)=>{be.init(t,e),t._zod.check=n=>{try{let r=n.value,o=new URL(r),i=o.href;e.hostname&&(e.hostname.lastIndex=0,e.hostname.test(o.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:Xh.source,input:n.value,inst:t,continue:!e.abort})),e.protocol&&(e.protocol.lastIndex=0,e.protocol.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:e.protocol.source,input:n.value,inst:t,continue:!e.abort})),!r.endsWith("/")&&i.endsWith("/")?n.value=i.slice(0,-1):n.value=i;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:t,continue:!e.abort})}}}),Uf=A("$ZodEmoji",(t,e)=>{e.pattern??(e.pattern=Vh()),be.init(t,e)}),Hf=A("$ZodNanoID",(t,e)=>{e.pattern??(e.pattern=Fh),be.init(t,e)}),Ff=A("$ZodCUID",(t,e)=>{e.pattern??(e.pattern=zh),be.init(t,e)}),Gf=A("$ZodCUID2",(t,e)=>{e.pattern??(e.pattern=Dh),be.init(t,e)}),Bf=A("$ZodULID",(t,e)=>{e.pattern??(e.pattern=$h),be.init(t,e)}),Zf=A("$ZodXID",(t,e)=>{e.pattern??(e.pattern=Uh),be.init(t,e)}),Vf=A("$ZodKSUID",(t,e)=>{e.pattern??(e.pattern=Hh),be.init(t,e)}),jf=A("$ZodISODateTime",(t,e)=>{e.pattern??(e.pattern=rf(e)),be.init(t,e)}),Wf=A("$ZodISODate",(t,e)=>{e.pattern??(e.pattern=ef),be.init(t,e)}),qf=A("$ZodISOTime",(t,e)=>{e.pattern??(e.pattern=nf(e)),be.init(t,e)}),Yf=A("$ZodISODuration",(t,e)=>{e.pattern??(e.pattern=Gh),be.init(t,e)}),Kf=A("$ZodIPv4",(t,e)=>{e.pattern??(e.pattern=jh),be.init(t,e),t._zod.onattach.push(n=>{let r=n._zod.bag;r.format="ipv4"})}),Xf=A("$ZodIPv6",(t,e)=>{e.pattern??(e.pattern=Wh),be.init(t,e),t._zod.onattach.push(n=>{let r=n._zod.bag;r.format="ipv6"}),t._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:t,continue:!e.abort})}}}),Jf=A("$ZodCIDRv4",(t,e)=>{e.pattern??(e.pattern=qh),be.init(t,e)}),Qf=A("$ZodCIDRv6",(t,e)=>{e.pattern??(e.pattern=Yh),be.init(t,e),t._zod.check=n=>{let[r,o]=n.value.split("/");try{if(!o)throw new Error;let i=Number(o);if(`${i}`!==o)throw new Error;if(i<0||i>128)throw new Error;new URL(`http://[${r}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:t,continue:!e.abort})}}});function em(t){if(t==="")return!0;if(t.length%4!==0)return!1;try{return atob(t),!0}catch{return!1}}var tm=A("$ZodBase64",(t,e)=>{e.pattern??(e.pattern=Kh),be.init(t,e),t._zod.onattach.push(n=>{n._zod.bag.contentEncoding="base64"}),t._zod.check=n=>{em(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:t,continue:!e.abort})}});function h_(t){if(!$c.test(t))return!1;let e=t.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=e.padEnd(Math.ceil(e.length/4)*4,"=");return em(n)}var nm=A("$ZodBase64URL",(t,e)=>{e.pattern??(e.pattern=$c),be.init(t,e),t._zod.onattach.push(n=>{n._zod.bag.contentEncoding="base64url"}),t._zod.check=n=>{h_(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:t,continue:!e.abort})}}),rm=A("$ZodE164",(t,e)=>{e.pattern??(e.pattern=Jh),be.init(t,e)});function f_(t,e=null){try{let n=t.split(".");if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let o=JSON.parse(atob(r));return!("typ"in o&&o?.typ!=="JWT"||!o.alg||e&&(!("alg"in o)||o.alg!==e))}catch{return!1}}var om=A("$ZodJWT",(t,e)=>{be.init(t,e),t._zod.check=n=>{f_(n.value,e.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:t,continue:!e.abort})}});var Gc=A("$ZodNumber",(t,e)=>{de.init(t,e),t._zod.pattern=t._zod.bag.pattern??sf,t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=Number(n.value)}catch{}let o=n.value;if(typeof o=="number"&&!Number.isNaN(o)&&Number.isFinite(o))return n;let i=typeof o=="number"?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:t,...i?{received:i}:{}}),n}}),im=A("$ZodNumber",(t,e)=>{hf.init(t,e),Gc.init(t,e)}),am=A("$ZodBoolean",(t,e)=>{de.init(t,e),t._zod.pattern=lf,t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=!!n.value}catch{}let o=n.value;return typeof o=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:t}),n}});var sm=A("$ZodAny",(t,e)=>{de.init(t,e),t._zod.parse=n=>n}),lm=A("$ZodUnknown",(t,e)=>{de.init(t,e),t._zod.parse=n=>n}),cm=A("$ZodNever",(t,e)=>{de.init(t,e),t._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:t}),n)});function Af(t,e,n){t.issues.length&&e.issues.push(...At(n,t.issues)),e.value[n]=t.value}var um=A("$ZodArray",(t,e)=>{de.init(t,e),t._zod.parse=(n,r)=>{let o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:t}),n;n.value=Array(o.length);let i=[];for(let a=0;a<o.length;a++){let s=o[a],c=e.element._zod.run({value:s,issues:[]},r);c instanceof Promise?i.push(c.then(l=>Af(l,n,a))):Af(c,n,a)}return i.length?Promise.all(i).then(()=>n):n}});function Hi(t,e,n){t.issues.length&&e.issues.push(...At(n,t.issues)),e.value[n]=t.value}function kf(t,e,n,r){t.issues.length?r[n]===void 0?n in r?e.value[n]=void 0:e.value[n]=t.value:e.issues.push(...At(n,t.issues)):t.value===void 0?n in r&&(e.value[n]=void 0):e.value[n]=t.value}var dm=A("$ZodObject",(t,e)=>{de.init(t,e);let n=Fr(()=>{let f=Object.keys(e.shape);for(let p of f)if(!(e.shape[p]instanceof de))throw new Error(`Invalid element at key "${p}": expected a Zod schema`);let m=Rc(e.shape);return{shape:e.shape,keys:f,keySet:new Set(f),numKeys:f.length,optionalKeys:new Set(m)}});le(t._zod,"propValues",()=>{let f=e.shape,m={};for(let p in f){let h=f[p]._zod;if(h.values){m[p]??(m[p]=new Set);for(let x of h.values)m[p].add(x)}}return m});let r=f=>{let m=new Ui(["shape","payload","ctx"]),p=n.value,h=b=>{let k=mn(b);return`shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`};m.write("const input = payload.value;");let x=Object.create(null),g=0;for(let b of p.keys)x[b]=`key_${g++}`;m.write("const newResult = {}");for(let b of p.keys)if(p.optionalKeys.has(b)){let k=x[b];m.write(`const ${k} = ${h(b)};`);let O=mn(b);m.write(`
|
|
8
8
|
if (${k}.issues.length) {
|
|
9
9
|
if (input[${O}] === undefined) {
|
|
10
10
|
if (${O} in input) {
|
|
@@ -23,27 +23,27 @@ var kE=Object.defineProperty;var vl=(e,t)=>{for(var n in t)kE(e,n,{get:t[n],enum
|
|
|
23
23
|
} else {
|
|
24
24
|
newResult[${O}] = ${k}.value;
|
|
25
25
|
}
|
|
26
|
-
`)}else{let k=
|
|
26
|
+
`)}else{let k=x[b];m.write(`const ${k} = ${h(b)};`),m.write(`
|
|
27
27
|
if (${k}.issues.length) payload.issues = payload.issues.concat(${k}.issues.map(iss => ({
|
|
28
28
|
...iss,
|
|
29
|
-
path: iss.path ? [${
|
|
30
|
-
})));`),m.write(`newResult[${dn(b)}] = ${k}.value`)}m.write("payload.value = newResult;"),m.write("return payload;");let _=m.compile();return(b,k)=>_(f,b,k)},o,i=Qn,a=!Ri.jitless,l=a&&yc.value,c=t.catchall,u;e._zod.parse=(f,m)=>{u??(u=n.value);let p=f.value;if(!i(p))return f.issues.push({expected:"object",code:"invalid_type",input:p,inst:e}),f;let h=[];if(a&&l&&m?.async===!1&&m.jitless!==!0)o||(o=r(t.shape)),f=o(f,m);else{f.value={};let k=u.shape;for(let O of u.keys){let w=k[O],S=w._zod.run({value:p[O],issues:[]},m),x=w._zod.optin==="optional"&&w._zod.optout==="optional";S instanceof Promise?h.push(S.then(I=>x?vf(I,f,O,p):Li(I,f,O))):x?vf(S,f,O,p):Li(S,f,O)}}if(!c)return h.length?Promise.all(h).then(()=>f):f;let E=[],g=u.keySet,_=c._zod,b=_.def.type;for(let k of Object.keys(p)){if(g.has(k))continue;if(b==="never"){E.push(k);continue}let O=_.run({value:p[k],issues:[]},m);O instanceof Promise?h.push(O.then(w=>Li(w,f,k))):Li(O,f,k)}return E.length&&f.issues.push({code:"unrecognized_keys",keys:E,input:p,inst:e}),h.length?Promise.all(h).then(()=>f):f}});function bf(e,t,n,r){for(let o of e)if(o.issues.length===0)return t.value=o.value,t;return t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(o=>o.issues.map(i=>ut(i,r,$e())))}),t}var zc=A("$ZodUnion",(e,t)=>{de.init(e,t),se(e._zod,"optin",()=>t.options.some(n=>n._zod.optin==="optional")?"optional":void 0),se(e._zod,"optout",()=>t.options.some(n=>n._zod.optout==="optional")?"optional":void 0),se(e._zod,"values",()=>{if(t.options.every(n=>n._zod.values))return new Set(t.options.flatMap(n=>Array.from(n._zod.values)))}),se(e._zod,"pattern",()=>{if(t.options.every(n=>n._zod.pattern)){let n=t.options.map(r=>r._zod.pattern);return new RegExp(`^(${n.map(r=>Hr(r.source)).join("|")})$`)}}),e._zod.parse=(n,r)=>{let o=!1,i=[];for(let a of t.options){let s=a._zod.run({value:n.value,issues:[]},r);if(s instanceof Promise)i.push(s),o=!0;else{if(s.issues.length===0)return s;i.push(s)}}return o?Promise.all(i).then(a=>bf(a,n,e,r)):bf(i,n,e,r)}}),nm=A("$ZodDiscriminatedUnion",(e,t)=>{zc.init(e,t);let n=e._zod.parse;se(e._zod,"propValues",()=>{let o={};for(let i of t.options){let a=i._zod.propValues;if(!a||Object.keys(a).length===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(i)}"`);for(let[s,l]of Object.entries(a)){o[s]||(o[s]=new Set);for(let c of l)o[s].add(c)}}return o});let r=$r(()=>{let o=t.options,i=new Map;for(let a of o){let s=a._zod.propValues[t.discriminator];if(!s||s.size===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(a)}"`);for(let l of s){if(i.has(l))throw new Error(`Duplicate discriminator value "${String(l)}"`);i.set(l,a)}}return i});e._zod.parse=(o,i)=>{let a=o.value;if(!Qn(a))return o.issues.push({code:"invalid_type",expected:"object",input:a,inst:e}),o;let s=r.value.get(a?.[t.discriminator]);return s?s._zod.run(o,i):t.unionFallback?n(o,i):(o.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",input:a,path:[t.discriminator],inst:e}),o)}}),rm=A("$ZodIntersection",(e,t)=>{de.init(e,t),e._zod.parse=(n,r)=>{let o=n.value,i=t.left._zod.run({value:o,issues:[]},r),a=t.right._zod.run({value:o,issues:[]},r);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([l,c])=>yf(n,l,c)):yf(n,i,a)}});function Pc(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(er(e)&&er(t)){let n=Object.keys(t),r=Object.keys(e).filter(i=>n.indexOf(i)!==-1),o={...e,...t};for(let i of r){let a=Pc(e[i],t[i]);if(!a.valid)return{valid:!1,mergeErrorPath:[i,...a.mergeErrorPath]};o[i]=a.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let o=e[r],i=t[r],a=Pc(o,i);if(!a.valid)return{valid:!1,mergeErrorPath:[r,...a.mergeErrorPath]};n.push(a.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function yf(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),pn(e))return e;let r=Pc(t.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}var om=A("$ZodRecord",(e,t)=>{de.init(e,t),e._zod.parse=(n,r)=>{let o=n.value;if(!er(o))return n.issues.push({expected:"record",code:"invalid_type",input:o,inst:e}),n;let i=[];if(t.keyType._zod.values){let a=t.keyType._zod.values;n.value={};for(let l of a)if(typeof l=="string"||typeof l=="number"||typeof l=="symbol"){let c=t.valueType._zod.run({value:o[l],issues:[]},r);c instanceof Promise?i.push(c.then(u=>{u.issues.length&&n.issues.push(...St(l,u.issues)),n.value[l]=u.value})):(c.issues.length&&n.issues.push(...St(l,c.issues)),n.value[l]=c.value)}let s;for(let l in o)a.has(l)||(s=s??[],s.push(l));s&&s.length>0&&n.issues.push({code:"unrecognized_keys",input:o,inst:e,keys:s})}else{n.value={};for(let a of Reflect.ownKeys(o)){if(a==="__proto__")continue;let s=t.keyType._zod.run({value:a,issues:[]},r);if(s instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(s.issues.length){n.issues.push({origin:"record",code:"invalid_key",issues:s.issues.map(c=>ut(c,r,$e())),input:a,path:[a],inst:e}),n.value[s.value]=s.value;continue}let l=t.valueType._zod.run({value:o[a],issues:[]},r);l instanceof Promise?i.push(l.then(c=>{c.issues.length&&n.issues.push(...St(a,c.issues)),n.value[s.value]=c.value})):(l.issues.length&&n.issues.push(...St(a,l.issues)),n.value[s.value]=l.value)}}return i.length?Promise.all(i).then(()=>n):n}});var im=A("$ZodEnum",(e,t)=>{de.init(e,t);let n=mc(t.entries);e._zod.values=new Set(n),e._zod.pattern=new RegExp(`^(${n.filter(r=>wc.has(typeof r)).map(r=>typeof r=="string"?Ut(r):r.toString()).join("|")})$`),e._zod.parse=(r,o)=>{let i=r.value;return e._zod.values.has(i)||r.issues.push({code:"invalid_value",values:n,input:i,inst:e}),r}}),am=A("$ZodLiteral",(e,t)=>{de.init(e,t),e._zod.values=new Set(t.values),e._zod.pattern=new RegExp(`^(${t.values.map(n=>typeof n=="string"?Ut(n):n?n.toString():String(n)).join("|")})$`),e._zod.parse=(n,r)=>{let o=n.value;return e._zod.values.has(o)||n.issues.push({code:"invalid_value",values:t.values,input:o,inst:e}),n}});var sm=A("$ZodTransform",(e,t)=>{de.init(e,t),e._zod.parse=(n,r)=>{let o=t.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(a=>(n.value=a,n));if(o instanceof Promise)throw new Nt;return n.value=o,n}}),lm=A("$ZodOptional",(e,t)=>{de.init(e,t),e._zod.optin="optional",e._zod.optout="optional",se(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),se(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${Hr(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>t.innerType._zod.optin==="optional"?t.innerType._zod.run(n,r):n.value===void 0?n:t.innerType._zod.run(n,r)}),cm=A("$ZodNullable",(e,t)=>{de.init(e,t),se(e._zod,"optin",()=>t.innerType._zod.optin),se(e._zod,"optout",()=>t.innerType._zod.optout),se(e._zod,"pattern",()=>{let n=t.innerType._zod.pattern;return n?new RegExp(`^(${Hr(n.source)}|null)$`):void 0}),se(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),um=A("$ZodDefault",(e,t)=>{de.init(e,t),e._zod.optin="optional",se(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(n.value===void 0)return n.value=t.defaultValue,n;let o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>wf(i,t)):wf(o,t)}});function wf(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var dm=A("$ZodPrefault",(e,t)=>{de.init(e,t),e._zod.optin="optional",se(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>(n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),pm=A("$ZodNonOptional",(e,t)=>{de.init(e,t),se(e._zod,"values",()=>{let n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{let o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>Ef(i,e)):Ef(o,e)}});function Ef(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}var hm=A("$ZodCatch",(e,t)=>{de.init(e,t),e._zod.optin="optional",se(e._zod,"optout",()=>t.innerType._zod.optout),se(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{let o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(a=>ut(a,r,$e()))},input:n.value}),n.issues=[]),n)):(n.value=o.value,o.issues.length&&(n.value=t.catchValue({...n,error:{issues:o.issues.map(i=>ut(i,r,$e()))},input:n.value}),n.issues=[]),n)}});var fm=A("$ZodPipe",(e,t)=>{de.init(e,t),se(e._zod,"values",()=>t.in._zod.values),se(e._zod,"optin",()=>t.in._zod.optin),se(e._zod,"optout",()=>t.out._zod.optout),e._zod.parse=(n,r)=>{let o=t.in._zod.run(n,r);return o instanceof Promise?o.then(i=>xf(i,t,r)):xf(o,t,r)}});function xf(e,t,n){return pn(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}var mm=A("$ZodReadonly",(e,t)=>{de.init(e,t),se(e._zod,"propValues",()=>t.innerType._zod.propValues),se(e._zod,"values",()=>t.innerType._zod.values),se(e._zod,"optin",()=>t.innerType._zod.optin),se(e._zod,"optout",()=>t.innerType._zod.optout),e._zod.parse=(n,r)=>{let o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(_f):_f(o)}});function _f(e){return e.value=Object.freeze(e.value),e}var gm=A("$ZodLazy",(e,t)=>{de.init(e,t),se(e._zod,"innerType",()=>t.getter()),se(e._zod,"pattern",()=>e._zod.innerType._zod.pattern),se(e._zod,"propValues",()=>e._zod.innerType._zod.propValues),se(e._zod,"optin",()=>e._zod.innerType._zod.optin),se(e._zod,"optout",()=>e._zod.innerType._zod.optout),e._zod.parse=(n,r)=>e._zod.innerType._zod.run(n,r)}),vm=A("$ZodCustom",(e,t)=>{Ge.init(e,t),de.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{let r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(i=>Sf(i,n,r,e));Sf(o,n,r,e)}});function Sf(e,t,n,r){if(!e){let o={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),t.issues.push(_c(o))}}var r_=e=>{let t=typeof e;switch(t){case"number":return Number.isNaN(e)?"NaN":"number";case"object":{if(Array.isArray(e))return"array";if(e===null)return"null";if(Object.getPrototypeOf(e)!==Object.prototype&&e.constructor)return e.constructor.name}}return t},o_=()=>{let e={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"}};function t(r){return e[r]??null}let n={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",jwt:"JWT",template_literal:"input"};return r=>{switch(r.code){case"invalid_type":return`Invalid input: expected ${r.expected}, received ${r_(r.input)}`;case"invalid_value":return r.values.length===1?`Invalid input: expected ${Oi(r.values[0])}`:`Invalid option: expected one of ${Ci(r.values,"|")}`;case"too_big":{let o=r.inclusive?"<=":"<",i=t(r.origin);return i?`Too big: expected ${r.origin??"value"} to have ${o}${r.maximum.toString()} ${i.unit??"elements"}`:`Too big: expected ${r.origin??"value"} to be ${o}${r.maximum.toString()}`}case"too_small":{let o=r.inclusive?">=":">",i=t(r.origin);return i?`Too small: expected ${r.origin} to have ${o}${r.minimum.toString()} ${i.unit}`:`Too small: expected ${r.origin} to be ${o}${r.minimum.toString()}`}case"invalid_format":{let o=r;return o.format==="starts_with"?`Invalid string: must start with "${o.prefix}"`:o.format==="ends_with"?`Invalid string: must end with "${o.suffix}"`:o.format==="includes"?`Invalid string: must include "${o.includes}"`:o.format==="regex"?`Invalid string: must match pattern ${o.pattern}`:`Invalid ${n[o.format]??r.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${r.divisor}`;case"unrecognized_keys":return`Unrecognized key${r.keys.length>1?"s":""}: ${Ci(r.keys,", ")}`;case"invalid_key":return`Invalid key in ${r.origin}`;case"invalid_union":return"Invalid input";case"invalid_element":return`Invalid value in ${r.origin}`;default:return"Invalid input"}}};function tr(){return{localeError:o_()}}var Lc=class{constructor(){this._map=new Map,this._idmap=new Map}add(t,...n){let r=n[0];if(this._map.set(t,r),r&&typeof r=="object"&&"id"in r){if(this._idmap.has(r.id))throw new Error(`ID ${r.id} already exists in the registry`);this._idmap.set(r.id,t)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(t){let n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){let n=t._zod.parent;if(n){let r={...this.get(n)??{}};return delete r.id,{...r,...this._map.get(t)}}return this._map.get(t)}has(t){return this._map.has(t)}};function bm(){return new Lc}var nr=bm();function ym(e,t){return new e({type:"string",...G(t)})}function wm(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...G(t)})}function Dc(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...G(t)})}function Em(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...G(t)})}function xm(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...G(t)})}function _m(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...G(t)})}function Sm(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...G(t)})}function Tm(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...G(t)})}function Am(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...G(t)})}function km(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...G(t)})}function Im(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...G(t)})}function Rm(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...G(t)})}function Cm(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...G(t)})}function Nm(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...G(t)})}function Om(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...G(t)})}function Pm(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...G(t)})}function Mm(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...G(t)})}function zm(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...G(t)})}function Lm(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...G(t)})}function Dm(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...G(t)})}function $m(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...G(t)})}function Um(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...G(t)})}function Hm(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...G(t)})}function Fm(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...G(t)})}function Gm(e,t){return new e({type:"string",format:"date",check:"string_format",...G(t)})}function Bm(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...G(t)})}function Zm(e,t){return new e({type:"string",format:"duration",check:"string_format",...G(t)})}function Vm(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...G(t)})}function jm(e,t){return new e({type:"boolean",...G(t)})}function Wm(e){return new e({type:"any"})}function qm(e){return new e({type:"unknown"})}function Ym(e,t){return new e({type:"never",...G(t)})}function $i(e,t){return new Nc({check:"less_than",...G(t),value:e,inclusive:!1})}function Br(e,t){return new Nc({check:"less_than",...G(t),value:e,inclusive:!0})}function Ui(e,t){return new Oc({check:"greater_than",...G(t),value:e,inclusive:!1})}function Zr(e,t){return new Oc({check:"greater_than",...G(t),value:e,inclusive:!0})}function Hi(e,t){return new tf({check:"multiple_of",...G(t),value:e})}function Fi(e,t){return new rf({check:"max_length",...G(t),maximum:e})}function rr(e,t){return new of({check:"min_length",...G(t),minimum:e})}function Gi(e,t){return new af({check:"length_equals",...G(t),length:e})}function $c(e,t){return new sf({check:"string_format",format:"regex",...G(t),pattern:e})}function Uc(e){return new lf({check:"string_format",format:"lowercase",...G(e)})}function Hc(e){return new cf({check:"string_format",format:"uppercase",...G(e)})}function Fc(e,t){return new uf({check:"string_format",format:"includes",...G(t),includes:e})}function Gc(e,t){return new df({check:"string_format",format:"starts_with",...G(t),prefix:e})}function Bc(e,t){return new pf({check:"string_format",format:"ends_with",...G(t),suffix:e})}function hn(e){return new hf({check:"overwrite",tx:e})}function Zc(e){return hn(t=>t.normalize(e))}function Vc(){return hn(e=>e.trim())}function jc(){return hn(e=>e.toLowerCase())}function Wc(){return hn(e=>e.toUpperCase())}function Xm(e,t,n){return new e({type:"array",element:t,...G(n)})}function Km(e,t,n){let r=G(n);return r.abort??(r.abort=!0),new e({type:"custom",check:"custom",fn:t,...r})}function Jm(e,t,n){return new e({type:"custom",check:"custom",fn:t,...G(n)})}var d_=A("ZodISODateTime",(e,t)=>{Lf.init(e,t),Ee.init(e,t)});function Qm(e){return Fm(d_,e)}var p_=A("ZodISODate",(e,t)=>{Df.init(e,t),Ee.init(e,t)});function eg(e){return Gm(p_,e)}var h_=A("ZodISOTime",(e,t)=>{$f.init(e,t),Ee.init(e,t)});function tg(e){return Bm(h_,e)}var f_=A("ZodISODuration",(e,t)=>{Uf.init(e,t),Ee.init(e,t)});function ng(e){return Zm(f_,e)}var og=(e,t)=>{Pi.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>Ac(e,n)},flatten:{value:n=>Tc(e,n)},addIssue:{value:n=>e.issues.push(n)},addIssues:{value:n=>e.issues.push(...n)},isEmpty:{get(){return e.issues.length===0}}})},wM=A("ZodError",og),jr=A("ZodError",og,{Parent:Error});var ig=xh(jr),ag=_h(jr),sg=kc(jr),lg=Ic(jr);var xe=A("ZodType",(e,t)=>(de.init(e,t),e.def=t,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),e.clone=(n,r)=>ct(e,n,r),e.brand=()=>e,e.register=((n,r)=>(n.add(e,r),e)),e.parse=(n,r)=>ig(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>sg(e,n,r),e.parseAsync=async(n,r)=>ag(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>lg(e,n,r),e.spa=e.safeParseAsync,e.refine=(n,r)=>e.check(eS(n,r)),e.superRefine=n=>e.check(tS(n)),e.overwrite=n=>e.check(hn(n)),e.optional=()=>ug(e),e.nullable=()=>dg(e),e.nullish=()=>ug(dg(e)),e.nonoptional=n=>X_(e,n),e.array=()=>Ie(e),e.or=n=>Wr([e,n]),e.and=n=>Z_(e,n),e.transform=n=>pg(e,j_(n)),e.default=n=>W_(e,n),e.prefault=n=>Y_(e,n),e.catch=n=>K_(e,n),e.pipe=n=>pg(e,n),e.readonly=()=>J_(e),e.describe=n=>{let r=e.clone();return nr.add(r,{description:n}),r},Object.defineProperty(e,"description",{get(){return nr.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return nr.get(e);let r=e.clone();return nr.add(r,n[0]),r},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),hg=A("_ZodString",(e,t)=>{Di.init(e,t),xe.init(e,t);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...r)=>e.check($c(...r)),e.includes=(...r)=>e.check(Fc(...r)),e.startsWith=(...r)=>e.check(Gc(...r)),e.endsWith=(...r)=>e.check(Bc(...r)),e.min=(...r)=>e.check(rr(...r)),e.max=(...r)=>e.check(Fi(...r)),e.length=(...r)=>e.check(Gi(...r)),e.nonempty=(...r)=>e.check(rr(1,...r)),e.lowercase=r=>e.check(Uc(r)),e.uppercase=r=>e.check(Hc(r)),e.trim=()=>e.check(Vc()),e.normalize=(...r)=>e.check(Zc(...r)),e.toLowerCase=()=>e.check(jc()),e.toUpperCase=()=>e.check(Wc())}),v_=A("ZodString",(e,t)=>{Di.init(e,t),hg.init(e,t),e.email=n=>e.check(wm(b_,n)),e.url=n=>e.check(Tm(y_,n)),e.jwt=n=>e.check(Hm(M_,n)),e.emoji=n=>e.check(Am(w_,n)),e.guid=n=>e.check(Dc(cg,n)),e.uuid=n=>e.check(Em(Bi,n)),e.uuidv4=n=>e.check(xm(Bi,n)),e.uuidv6=n=>e.check(_m(Bi,n)),e.uuidv7=n=>e.check(Sm(Bi,n)),e.nanoid=n=>e.check(km(E_,n)),e.guid=n=>e.check(Dc(cg,n)),e.cuid=n=>e.check(Im(x_,n)),e.cuid2=n=>e.check(Rm(__,n)),e.ulid=n=>e.check(Cm(S_,n)),e.base64=n=>e.check(Dm(N_,n)),e.base64url=n=>e.check($m(O_,n)),e.xid=n=>e.check(Nm(T_,n)),e.ksuid=n=>e.check(Om(A_,n)),e.ipv4=n=>e.check(Pm(k_,n)),e.ipv6=n=>e.check(Mm(I_,n)),e.cidrv4=n=>e.check(zm(R_,n)),e.cidrv6=n=>e.check(Lm(C_,n)),e.e164=n=>e.check(Um(P_,n)),e.datetime=n=>e.check(Qm(n)),e.date=n=>e.check(eg(n)),e.time=n=>e.check(tg(n)),e.duration=n=>e.check(ng(n))});function T(e){return ym(v_,e)}var Ee=A("ZodStringFormat",(e,t)=>{ve.init(e,t),hg.init(e,t)}),b_=A("ZodEmail",(e,t)=>{kf.init(e,t),Ee.init(e,t)});var cg=A("ZodGUID",(e,t)=>{Tf.init(e,t),Ee.init(e,t)});var Bi=A("ZodUUID",(e,t)=>{Af.init(e,t),Ee.init(e,t)});var y_=A("ZodURL",(e,t)=>{If.init(e,t),Ee.init(e,t)});var w_=A("ZodEmoji",(e,t)=>{Rf.init(e,t),Ee.init(e,t)});var E_=A("ZodNanoID",(e,t)=>{Cf.init(e,t),Ee.init(e,t)});var x_=A("ZodCUID",(e,t)=>{Nf.init(e,t),Ee.init(e,t)});var __=A("ZodCUID2",(e,t)=>{Of.init(e,t),Ee.init(e,t)});var S_=A("ZodULID",(e,t)=>{Pf.init(e,t),Ee.init(e,t)});var T_=A("ZodXID",(e,t)=>{Mf.init(e,t),Ee.init(e,t)});var A_=A("ZodKSUID",(e,t)=>{zf.init(e,t),Ee.init(e,t)});var k_=A("ZodIPv4",(e,t)=>{Hf.init(e,t),Ee.init(e,t)});var I_=A("ZodIPv6",(e,t)=>{Ff.init(e,t),Ee.init(e,t)});var R_=A("ZodCIDRv4",(e,t)=>{Gf.init(e,t),Ee.init(e,t)});var C_=A("ZodCIDRv6",(e,t)=>{Bf.init(e,t),Ee.init(e,t)});var N_=A("ZodBase64",(e,t)=>{Vf.init(e,t),Ee.init(e,t)});var O_=A("ZodBase64URL",(e,t)=>{jf.init(e,t),Ee.init(e,t)});var P_=A("ZodE164",(e,t)=>{Wf.init(e,t),Ee.init(e,t)});var M_=A("ZodJWT",(e,t)=>{qf.init(e,t),Ee.init(e,t)});var z_=A("ZodNumber",(e,t)=>{Mc.init(e,t),xe.init(e,t),e.gt=(r,o)=>e.check(Ui(r,o)),e.gte=(r,o)=>e.check(Zr(r,o)),e.min=(r,o)=>e.check(Zr(r,o)),e.lt=(r,o)=>e.check($i(r,o)),e.lte=(r,o)=>e.check(Br(r,o)),e.max=(r,o)=>e.check(Br(r,o)),e.int=r=>e.check(W(r)),e.safe=r=>e.check(W(r)),e.positive=r=>e.check(Ui(0,r)),e.nonnegative=r=>e.check(Zr(0,r)),e.negative=r=>e.check($i(0,r)),e.nonpositive=r=>e.check(Br(0,r)),e.multipleOf=(r,o)=>e.check(Hi(r,o)),e.step=(r,o)=>e.check(Hi(r,o)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});var L_=A("ZodNumberFormat",(e,t)=>{Yf.init(e,t),z_.init(e,t)});function W(e){return Vm(L_,e)}var D_=A("ZodBoolean",(e,t)=>{Xf.init(e,t),xe.init(e,t)});function ee(e){return jm(D_,e)}var $_=A("ZodAny",(e,t)=>{Kf.init(e,t),xe.init(e,t)});function B(){return Wm($_)}var U_=A("ZodUnknown",(e,t)=>{Jf.init(e,t),xe.init(e,t)});function qc(){return qm(U_)}var H_=A("ZodNever",(e,t)=>{Qf.init(e,t),xe.init(e,t)});function F_(e){return Ym(H_,e)}var Zi=A("ZodArray",(e,t)=>{em.init(e,t),xe.init(e,t),e.element=t.element,e.min=(n,r)=>e.check(rr(n,r)),e.nonempty=n=>e.check(rr(1,n)),e.max=(n,r)=>e.check(Fi(n,r)),e.length=(n,r)=>e.check(Gi(n,r)),e.unwrap=()=>e.element});function Ie(e,t){return Xm(Zi,e,t)}var or=A("ZodObject",(e,t)=>{tm.init(e,t),xe.init(e,t),le.defineLazy(e,"shape",()=>t.shape),e.keyof=()=>fn(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:qc()}),e.loose=()=>e.clone({...e._zod.def,catchall:qc()}),e.strict=()=>e.clone({...e._zod.def,catchall:F_()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>le.extend(e,n),e.merge=n=>le.merge(e,n),e.pick=n=>le.pick(e,n),e.omit=n=>le.omit(e,n),e.partial=(...n)=>le.partial(ji,e,n[0]),e.required=(...n)=>le.required(mg,e,n[0])});function L(e,t){return new or({type:"object",get shape(){return le.assignProp(this,"shape",{...e}),this.shape},catchall:qc(),...le.normalizeParams(t)})}var Vi=A("ZodUnion",(e,t)=>{zc.init(e,t),xe.init(e,t),e.options=t.options});function Wr(e,t){return new Vi({type:"union",options:e,...le.normalizeParams(t)})}var G_=A("ZodDiscriminatedUnion",(e,t)=>{Vi.init(e,t),nm.init(e,t)});function Ht(e,t,n){return new G_({type:"union",options:t,discriminator:e,...le.normalizeParams(n)})}var B_=A("ZodIntersection",(e,t)=>{rm.init(e,t),xe.init(e,t)});function Z_(e,t){return new B_({type:"intersection",left:e,right:t})}var fg=A("ZodRecord",(e,t)=>{om.init(e,t),xe.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});var Yc=A("ZodEnum",(e,t)=>{im.init(e,t),xe.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(r,o)=>{let i={};for(let a of r)if(n.has(a))i[a]=t.entries[a];else throw new Error(`Key ${a} not found in enum`);return new Yc({...t,checks:[],...le.normalizeParams(o),entries:i})},e.exclude=(r,o)=>{let i={...t.entries};for(let a of r)if(n.has(a))delete i[a];else throw new Error(`Key ${a} not found in enum`);return new Yc({...t,checks:[],...le.normalizeParams(o),entries:i})}});function fn(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new Yc({type:"enum",entries:n,...le.normalizeParams(t)})}var Xc=A("ZodLiteral",(e,t)=>{am.init(e,t),xe.init(e,t),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function $(e,t){return new Xc({type:"literal",values:Array.isArray(e)?e:[e],...le.normalizeParams(t)})}var V_=A("ZodTransform",(e,t)=>{sm.init(e,t),xe.init(e,t),e._zod.parse=(n,r)=>{n.addIssue=i=>{if(typeof i=="string")n.issues.push(le.issue(i,n.value,t));else{let a=i;a.fatal&&(a.continue=!1),a.code??(a.code="custom"),a.input??(a.input=n.value),a.inst??(a.inst=e),a.continue??(a.continue=!0),n.issues.push(le.issue(a))}};let o=t.transform(n.value,n);return o instanceof Promise?o.then(i=>(n.value=i,n)):(n.value=o,n)}});function j_(e){return new V_({type:"transform",transform:e})}var ji=A("ZodOptional",(e,t)=>{lm.init(e,t),xe.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ug(e){return new ji({type:"optional",innerType:e})}var Kc=A("ZodNullable",(e,t)=>{cm.init(e,t),xe.init(e,t),e.unwrap=()=>e._zod.def.innerType});function dg(e){return new Kc({type:"nullable",innerType:e})}var Jc=A("ZodDefault",(e,t)=>{um.init(e,t),xe.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function W_(e,t){return new Jc({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():t}})}var q_=A("ZodPrefault",(e,t)=>{dm.init(e,t),xe.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Y_(e,t){return new q_({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():t}})}var mg=A("ZodNonOptional",(e,t)=>{pm.init(e,t),xe.init(e,t),e.unwrap=()=>e._zod.def.innerType});function X_(e,t){return new mg({type:"nonoptional",innerType:e,...le.normalizeParams(t)})}var Qc=A("ZodCatch",(e,t)=>{hm.init(e,t),xe.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function K_(e,t){return new Qc({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}var eu=A("ZodPipe",(e,t)=>{fm.init(e,t),xe.init(e,t),e.in=t.in,e.out=t.out});function pg(e,t){return new eu({type:"pipe",in:e,out:t})}var tu=A("ZodReadonly",(e,t)=>{mm.init(e,t),xe.init(e,t)});function J_(e){return new tu({type:"readonly",innerType:e})}var gg=A("ZodLazy",(e,t)=>{gm.init(e,t),xe.init(e,t),e.unwrap=()=>e._zod.def.getter()});var vg=A("ZodCustom",(e,t)=>{vm.init(e,t),xe.init(e,t)});function Q_(e){let t=new Ge({check:"custom"});return t._zod.check=e,t}function ir(e,t){return Km(vg,e??(()=>!0),t)}function eS(e,t={}){return Jm(vg,e,t)}function tS(e){let t=Q_(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(le.issue(r,n.value,t._zod.def));else{let o=r;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=t),o.continue??(o.continue=!t._zod.def.abort),n.issues.push(le.issue(o))}},e(n.value,n)));return t}$e(tr());var rS=fn(v),V=ir(e=>typeof e=="object"&&e!==null&&!Array.isArray(e)),Q=T(),bg=fn(["developer","system","assistant","user"]),oS=L({type:$(v.TEXT_MESSAGE_START),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T(),role:bg.optional(),name:T().optional()}),iS=L({type:$(v.TEXT_MESSAGE_CONTENT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T(),delta:T()}),aS=L({type:$(v.TEXT_MESSAGE_END),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T()}),nu=L({type:$(v.TEXT_MESSAGE_CHUNK),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T().optional(),role:bg.optional(),delta:T().optional(),name:T().optional()}),sS=L({type:$(v.TOOL_CALL_START),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),toolCallId:T(),toolCallName:T(),parentMessageId:T().optional()}),lS=L({type:$(v.TOOL_CALL_ARGS),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),toolCallId:T(),delta:T()}),cS=L({type:$(v.TOOL_CALL_END),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),toolCallId:T()}),ru=L({type:$(v.TOOL_CALL_CHUNK),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),toolCallId:T().optional(),toolCallName:T().optional(),parentMessageId:T().optional(),delta:T().optional()}),uS=L({type:$("text"),id:T().optional(),text:T(),metadata:B().refine(e=>e!==null).optional()}),dS=L({type:$("data"),value:T(),mimeType:T()}),pS=L({type:$("url"),value:T(),mimeType:T().optional()}),hS=L({type:$("file"),value:T(),provider:T().optional(),mimeType:T().optional()}),Wi=Ht("type",[dS,pS,hS]),fS=L({type:$("image"),id:T().optional(),source:Wi,metadata:B().refine(e=>e!==null).optional()}),mS=L({type:$("audio"),id:T().optional(),source:Wi,metadata:B().refine(e=>e!==null).optional()}),gS=L({type:$("video"),id:T().optional(),source:Wi,metadata:B().refine(e=>e!==null).optional()}),vS=L({type:$("document"),id:T().optional(),source:Wi,metadata:B().refine(e=>e!==null).optional()}),ou=Ht("type",[uS,fS,mS,gS,vS]),bS=L({type:$(v.TOOL_CALL_RESULT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T(),toolCallId:T(),content:Wr([T(),Ie(ou)]),role:$("tool").optional()}),yg=B(),yS=L({type:$(v.STATE_SNAPSHOT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),snapshot:yg.refine(e=>e!==void 0)}),Ft=T().regex(new RegExp("^(/([^/~]|~[01])*)*$")),wS=L({op:$("add"),path:Ft,value:B().refine(e=>e!==void 0)}).meta({specOpen:!0}),ES=L({op:$("remove"),path:Ft}).meta({specOpen:!0}),xS=L({op:$("replace"),path:Ft,value:B().refine(e=>e!==void 0)}).meta({specOpen:!0}),_S=L({op:$("move"),from:Ft,path:Ft}).meta({specOpen:!0}),SS=L({op:$("copy"),from:Ft,path:Ft}).meta({specOpen:!0}),TS=L({op:$("test"),path:Ft,value:B().refine(e=>e!==void 0)}).meta({specOpen:!0}),AS=Ht("op",[wS,ES,xS,_S,SS,TS]),wg=Ie(AS),kS=L({type:$(v.STATE_DELTA),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),delta:wg}),IS=L({subagentRunId:Q.optional(),id:T(),role:$("developer"),name:T().optional(),encryptedValue:T().optional(),metadata:V.optional(),content:T()}),RS=L({subagentRunId:Q.optional(),id:T(),role:$("system"),name:T().optional(),encryptedValue:T().optional(),metadata:V.optional(),content:T()}),CS=L({name:T(),arguments:T()}),NS=L({id:T(),type:$("function"),function:CS,encryptedValue:T().optional(),metadata:V.optional()}),OS=L({subagentRunId:Q.optional(),id:T(),role:$("assistant"),name:T().optional(),encryptedValue:T().optional(),metadata:V.optional(),content:T().optional(),toolCalls:Ie(NS).optional()}),PS=L({subagentRunId:Q.optional(),id:T(),role:$("user"),name:T().optional(),encryptedValue:T().optional(),metadata:V.optional(),content:Wr([T(),Ie(ou)])}),MS=L({subagentRunId:Q.optional(),id:T(),role:$("tool"),content:Wr([T(),Ie(ou)]),toolCallId:T(),error:T().optional(),encryptedValue:T().optional(),metadata:V.optional()}),zS=L({subagentRunId:Q.optional(),id:T(),role:$("activity"),activityType:T(),content:ir(e=>typeof e=="object"&&e!==null&&!Array.isArray(e)),metadata:V.optional()}),LS=L({subagentRunId:Q.optional(),id:T(),role:$("reasoning"),content:T(),encryptedValue:T().optional(),metadata:V.optional()}),Eg=Ht("role",[IS,RS,OS,PS,MS,zS,LS]),DS=L({type:$(v.MESSAGES_SNAPSHOT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),messages:Ie(Eg)}),$S=L({type:$(v.ACTIVITY_SNAPSHOT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T(),activityType:T(),content:ir(e=>typeof e=="object"&&e!==null&&!Array.isArray(e)),replace:ee().optional()}),US=L({type:$(v.ACTIVITY_DELTA),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T(),activityType:T(),patch:wg}),HS=L({type:$(v.RAW),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),event:B().refine(e=>e!==void 0),source:T().optional()}),FS=L({type:$(v.CUSTOM),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),name:T(),value:B().refine(e=>e!==void 0)}),xg=L({name:T(),description:T(),parameters:B().refine(e=>e!==null).optional(),metadata:V.optional()}),GS=L({description:T(),value:T()}),BS=L({interruptId:T(),status:fn(["resolved","cancelled"]),payload:B().refine(e=>e!==null).optional(),metadata:V.optional()}),qi=L({threadId:T(),runId:T(),protocolVersion:T().optional(),parentRunId:T().optional(),state:yg.refine(e=>e!==null).nullable().transform(e=>e??void 0).optional(),messages:Ie(Eg),tools:Ie(xg).default(()=>[]),context:Ie(GS).default(()=>[]),forwardedProps:B().refine(e=>e!==null).optional(),resume:Ie(BS).optional()}),ZS=L({type:$(v.RUN_STARTED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),threadId:T(),runId:T(),protocolVersion:T().optional(),parentRunId:T().optional(),input:qi.optional()}),VS=L({type:$("success"),pendingToolCallIds:Ie(T()).optional()}),jS=L({subagentRunId:Q.optional(),id:T(),reason:T(),message:T().optional(),toolCallId:T().optional(),responseSchema:ir(e=>typeof e=="object"&&e!==null&&!Array.isArray(e)).optional(),expiresAt:T().optional(),metadata:V.optional()}),WS=L({type:$("interrupt"),interrupts:Ie(jS).min(1)}),qS=L({type:$("cancelled")}),YS=Ht("type",[VS,WS,qS]),_g=L({provider:T().optional(),model:T().optional(),inputTokens:W().min(0).max(9007199254740991).optional(),outputTokens:W().min(0).max(9007199254740991).optional(),totalTokens:W().min(0).max(9007199254740991).optional(),reasoningTokens:W().min(0).max(9007199254740991).optional(),cachedInputTokens:W().min(0).max(9007199254740991).optional(),cacheWriteInputTokens:W().min(0).max(9007199254740991).optional()}),XS=L({type:$(v.RUN_FINISHED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),threadId:T(),runId:T(),result:B().refine(e=>e!==null).optional(),outcome:YS.optional(),usage:Ie(_g).optional()}),KS=L({type:$(v.RUN_ERROR),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),message:T(),code:T().optional(),usage:Ie(_g).optional()}),JS=L({type:$(v.STEP_STARTED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),stepName:T()}),QS=L({type:$(v.STEP_FINISHED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),stepName:T()}),e0=L({type:$(v.REASONING_START),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T()}),t0=L({type:$(v.REASONING_MESSAGE_START),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T(),role:$("reasoning")}),n0=L({type:$(v.REASONING_MESSAGE_CONTENT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T(),delta:T()}),r0=L({type:$(v.REASONING_MESSAGE_END),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T()}),iu=L({type:$(v.REASONING_MESSAGE_CHUNK),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T().optional(),delta:T().optional()}),o0=L({type:$(v.REASONING_END),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),messageId:T()}),i0=fn(["tool-call","message"]),a0=L({type:$(v.REASONING_ENCRYPTED_VALUE),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q.optional(),subtype:i0,entityId:T(),encryptedValue:T()}),s0=L({type:$(v.SUBAGENT_STARTED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q,name:T(),description:T().optional(),parentSubagentRunId:Q.optional(),parentToolCallId:T().optional(),parentMessageId:T().optional()}),l0=L({type:$("success")}),c0=L({type:$("suspended"),interruptIds:Ie(T()).optional()}),u0=Ht("type",[l0,c0]),d0=L({type:$(v.SUBAGENT_FINISHED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q,result:B().refine(e=>e!==null).optional(),outcome:u0.optional()}),p0=L({type:$(v.SUBAGENT_ERROR),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional(),subagentRunId:Q,message:T(),code:T().optional()}),au=Ht("type",[oS,iS,aS,nu,sS,lS,cS,ru,bS,yS,kS,DS,$S,US,HS,FS,ZS,XS,KS,JS,QS,e0,t0,n0,r0,iu,o0,a0,s0,d0,p0]),xz=fn(["developer","system","assistant","user","tool","activity","reasoning"]),h0=L({name:T(),description:T().optional()}),f0=L({name:T().optional(),type:T().optional(),description:T().optional(),version:T().optional(),provider:T().optional(),documentationUrl:T().optional(),metadata:V.optional()}),m0=L({streaming:ee().optional(),websocket:ee().optional(),httpBinary:ee().optional(),pushNotifications:ee().optional(),resumable:ee().optional()}),g0=L({supported:ee().optional(),items:Ie(xg).optional(),parallelCalls:ee().optional(),clientProvided:ee().optional()}),v0=L({structuredOutput:ee().optional(),supportedMimeTypes:Ie(T()).optional()}),b0=L({snapshots:ee().optional(),deltas:ee().optional(),memory:ee().optional(),persistentState:ee().optional()}),y0=L({supported:ee().optional(),delegation:ee().optional(),handoffs:ee().optional(),subagents:Ie(h0).optional()}),w0=L({supported:ee().optional(),streaming:ee().optional(),encrypted:ee().optional()}),E0=L({image:ee().optional(),audio:ee().optional(),video:ee().optional(),pdf:ee().optional(),file:ee().optional()}),x0=L({image:ee().optional(),audio:ee().optional()}),_0=L({input:E0.optional(),output:x0.optional()}),S0=L({codeExecution:ee().optional(),sandboxed:ee().optional(),maxIterations:W().min(0).max(9007199254740991).optional(),maxExecutionTime:W().min(0).max(9007199254740991).optional()}),T0=L({supported:ee().optional(),approvals:ee().optional(),interventions:ee().optional(),feedback:ee().optional(),interrupts:ee().optional(),approveWithEdits:ee().optional()}),_z=L({identity:f0.optional(),transport:m0.optional(),tools:g0.optional(),output:v0.optional(),state:b0.optional(),multiAgent:y0.optional(),reasoning:w0.optional(),multimodal:_0.optional(),execution:S0.optional(),humanInTheLoop:T0.optional(),custom:ir(e=>typeof e=="object"&&e!==null&&!Array.isArray(e)).optional()}),Sz=L({subagentRunId:Q.optional()}),Tz=L({type:rS,timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(e=>e!==null).optional(),metadata:V.optional()}),Az=L({subagentRunId:Q.optional(),id:T(),role:T(),name:T().optional(),encryptedValue:T().optional(),metadata:V.optional()}),kz=V.optional();$e(tr());function Tg(){let e=this.buf,t=this.pos,n=0,r=0;for(let i=0;i<28;i+=7){let a=e[t++];if(n|=(a&127)<<i,(a&128)==0){this.pos=t,this.assertBounds(),this.varint64Lo=n,this.varint64Hi=r;return}}let o=e[t++];if(n|=(o&15)<<28,r=(o&112)>>4,(o&128)==0){this.pos=t,this.assertBounds(),this.varint64Lo=n,this.varint64Hi=r;return}for(let i=3;i<=31;i+=7){let a=e[t++];if(r|=(a&127)<<i,(a&128)==0){this.pos=t,this.assertBounds(),this.varint64Lo=n,this.varint64Hi=r;return}}throw new Error("invalid varint")}var Yi=4294967296;function su(e){let t=e[0]==="-";t&&(e=e.slice(1));let n=1e6,r=0,o=0;function i(a,s){let l=Number(e.slice(a,s));o*=n,r=r*n+l,r>=Yi&&(o=o+(r/Yi|0),r=r%Yi)}return i(-24,-18),i(-18,-12),i(-12,-6),i(-6),t?kg(r,o):cu(r,o)}function Ag(e,t){let n=cu(e,t),r=n.hi&2147483648;r&&(n=kg(n.lo,n.hi));let o=lu(n.lo,n.hi);return r?"-"+o:o}function lu(e,t){if({lo:e,hi:t}=A0(e,t),t<=2097151)return String(Yi*t+e);let n=e&16777215,r=(e>>>24|t<<8)&16777215,o=t>>16&65535,i=n+r*6777216+o*6710656,a=r+o*8147497,s=o*2,l=1e7;return i>=l&&(a+=Math.floor(i/l),i%=l),a>=l&&(s+=Math.floor(a/l),a%=l),s.toString()+Sg(a)+Sg(i)}function A0(e,t){return{lo:e>>>0,hi:t>>>0}}function cu(e,t){return{lo:e|0,hi:t|0}}function kg(e,t){return t=~t,e?e=~e+1:t+=1,cu(e,t)}var Sg=e=>{let t=String(e);return"0000000".slice(t.length)+t};function Ig(){let e=this.buf[this.pos++];if((e&128)===0)return this.assertBounds(),e;let t=e&127;if(e=this.buf[this.pos++],t|=(e&127)<<7,(e&128)===0)return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(e&127)<<14,(e&128)===0)return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(e&127)<<21,(e&128)===0)return this.assertBounds(),t;e=this.buf[this.pos++],t|=(e&15)<<28;for(let n=5;(e&128)!==0&&n<10;n++)e=this.buf[this.pos++];if((e&128)!==0)throw new Error("invalid varint");return this.assertBounds(),t>>>0}var dt=k0();function k0(){let e=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof e.getBigInt64=="function"&&typeof e.getBigUint64=="function"&&typeof e.setBigInt64=="function"&&typeof e.setBigUint64=="function"&&(!!globalThis.Deno||!!globalThis.Bun||typeof process!="object"||typeof process.env!="object"||process.env.BUF_BIGINT_DISABLE!=="1")){let n=BigInt("-9223372036854775808"),r=BigInt("9223372036854775807"),o=BigInt("0"),i=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(a){let s=typeof a=="bigint"?a:BigInt(a);if(s>r||s<n)throw new Error(`invalid int64: ${a}`);return s},uParse(a){let s=typeof a=="bigint"?a:BigInt(a);if(s>i||s<o)throw new Error(`invalid uint64: ${a}`);return s},enc(a){return e.setBigInt64(0,this.parse(a),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(a){return e.setBigInt64(0,this.uParse(a),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec(a,s){return e.setInt32(0,a,!0),e.setInt32(4,s,!0),e.getBigInt64(0,!0)},uDec(a,s){return e.setInt32(0,a,!0),e.setInt32(4,s,!0),e.getBigUint64(0,!0)}}}return{zero:"0",supported:!1,parse(n){return typeof n!="string"&&(n=n.toString()),Rg(n),n},uParse(n){return typeof n!="string"&&(n=n.toString()),Cg(n),n},enc(n){return typeof n!="string"&&(n=n.toString()),Rg(n),su(n)},uEnc(n){return typeof n!="string"&&(n=n.toString()),Cg(n),su(n)},dec(n,r){return Ag(n,r)},uDec(n,r){return lu(n,r)}}}function Rg(e){if(!/^-?[0-9]+$/.test(e))throw new Error("invalid int64: "+e)}function Cg(e){if(!/^[0-9]+$/.test(e))throw new Error("invalid uint64: "+e)}var uu;function I0(e){var t;uu=Object.assign(Object.assign({},e),{encodeUtf8Into:(t=e.encodeUtf8Into)!==null&&t!==void 0?t:pu(e.encodeUtf8.bind(e))})}function du(){if(!uu){let e=globalThis;if(!e.TextEncoder||!e.TextDecoder)throw new Error("encoding API missing: install TextEncoder and TextDecoder on globalThis");let t=new e.TextEncoder,n=new e.TextDecoder,r,o={encodeUtf8(a){return t.encode(a)},decodeUtf8(a,s){return s?(r||(r=new e.TextDecoder("utf-8",{fatal:!0})),r.decode(a)):n.decode(a)},checkUtf8(a){try{return encodeURIComponent(a),!0}catch{return!1}}};t.encodeInto&&(o.encodeUtf8Into=t.encodeInto.bind(t));let i=String.prototype.isWellFormed;i&&(o.checkUtf8=a=>i.call(a)),I0(o)}return uu}function pu(e){return(t,n)=>{let r=e(t);return n.set(r),{written:r.byteLength}}}var Gt;(function(e){e[e.Varint=0]="Varint",e[e.Bit64=1]="Bit64",e[e.LengthDelimited=2]="LengthDelimited",e[e.StartGroup=3]="StartGroup",e[e.EndGroup=4]="EndGroup",e[e.Bit32=5]="Bit32"})(Gt||(Gt={}));var R0=4294967295,C0=2147483647,N0=-2147483648,U=class{constructor(t){this.stackPos=[],this.encodeUtf8Into=t?pu(t):du().encodeUtf8Into,this.buffer=Og,this.viewCache=P0,this.pos=0}ensureCapacity(t){let n=this.pos+t;if(n>this.buffer.length){let r=this.buffer.length||O0;for(;r<n;)r*=2;let o=new Uint8Array(r);this.pos>0&&o.set(this.buffer),this.buffer=o}}view(){let t=this.buffer,n=this.viewCache;if(n.byteLength===t.byteLength)return n;let r=new DataView(t.buffer);return this.viewCache=r,r}finish(){let t=this.buffer.slice(0,this.pos);return this.pos=0,this.stackPos=[],t}fork(){return this.stackPos.push(this.pos),this.ensureCapacity(qr),this.buffer[this.pos++]=0,this}join(){let t=this.stackPos.pop();if(t===void 0)throw new Error("invalid state, fork stack empty");let n=this.pos-t-qr,r=hu(n);return r>qr&&(this.ensureCapacity(r-qr),this.buffer.copyWithin(t+r,t+qr,this.pos)),this.pos=t,this.uint32(n),this.pos+=n,this}tag(t,n){return this.uint32((t<<3|n)>>>0)}raw(t){return this.ensureCapacity(t.length),this.buffer.set(t,this.pos),this.pos+=t.length,this}uint32(t){if(Ng(t),this.ensureCapacity(5),t<128)return this.buffer[this.pos++]=t,this;for(;t>127;)this.buffer[this.pos++]=t&127|128,t>>>=7;return this.buffer[this.pos++]=t,this}int32(t){if(fu(t),t>=0)return this.uint32(t);this.ensureCapacity(10);for(let n=0;n<9;n++)this.buffer[this.pos++]=t&127|128,t>>=7;return this.buffer[this.pos++]=1,this}bool(t){return this.ensureCapacity(1),this.buffer[this.pos++]=t?1:0,this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){typeof t!="string"&&(t=String(t));let n=t.length;if(n<=Pg){this.ensureCapacity(n+1);let l=this.buffer,c=this.pos;l[c++]=n;let u=0;for(;u<n;u++){let f=t.charCodeAt(u);if(f>127)break;l[c++]=f}if(u==n)return this.pos=c,this}this.ensureCapacity(n*3+5);let r=hu(n),o=this.buffer,i=this.pos,{written:a}=this.encodeUtf8Into(t,o.subarray(i+r)),s=hu(a);return s!=r&&o.copyWithin(i+s,i+r,i+r+a),this.uint32(a),this.pos+=a,this}float(t){return M0(t),this.ensureCapacity(4),this.view().setFloat32(this.pos,t,!0),this.pos+=4,this}double(t){return this.ensureCapacity(8),this.view().setFloat64(this.pos,t,!0),this.pos+=8,this}fixed32(t){return Ng(t),this.ensureCapacity(4),this.view().setUint32(this.pos,t,!0),this.pos+=4,this}sfixed32(t){return fu(t),this.ensureCapacity(4),this.view().setInt32(this.pos,t,!0),this.pos+=4,this}sint32(t){return fu(t),this.uint32((t<<1^t>>31)>>>0)}sfixed64(t){let n=dt.enc(t);this.ensureCapacity(8);let r=this.view();return r.setInt32(this.pos,n.lo,!0),r.setInt32(this.pos+4,n.hi,!0),this.pos+=8,this}fixed64(t){let n=dt.uEnc(t);this.ensureCapacity(8);let r=this.view();return r.setInt32(this.pos,n.lo,!0),r.setInt32(this.pos+4,n.hi,!0),this.pos+=8,this}int64(t){let n=dt.enc(t);return this.writeVarint64(n.lo,n.hi)}sint64(t){let n=dt.enc(t),r=n.hi>>31,o=n.lo<<1^r,i=(n.hi<<1|n.lo>>>31)^r;return this.writeVarint64(o,i)}uint64(t){let n=dt.uEnc(t);return this.writeVarint64(n.lo,n.hi)}writeVarint64(t,n){this.ensureCapacity(10);let r=this.buffer,o=this.pos;for(let s=0;s<28;s=s+7){let l=t>>>s,c=!(!(l>>>7)&&n==0);if(r[o++]=(c?l|128:l)&255,!c)return this.pos=o,this}let i=t>>>28&15|(n&7)<<4,a=n>>3!=0;if(r[o++]=(a?i|128:i)&255,!a)return this.pos=o,this;for(let s=3;s<31;s=s+7){let l=n>>>s,c=!!(l>>>7);if(r[o++]=(c?l|128:l)&255,!c)return this.pos=o,this}return r[o++]=n>>>31&1,this.pos=o,this}},O0=128,qr=1,Og=new Uint8Array(0),P0=new DataView(Og.buffer),Pg=32;function hu(e){return e<128?1:e<16384?2:e<2097152?3:e<268435456?4:5}var R=class{constructor(t,n=du().decodeUtf8){this.decodeUtf8=n,this.varint64Lo=0,this.varint64Hi=0,this.varint64=Tg,this.uint32=Ig,this.buf=t,this.len=t.length,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}tag(){let t=this.pos,n=this.uint32(),r=this.pos-t;if(r>5||r==5&&this.buf[this.pos-1]>15)throw new Error("illegal tag: varint overflows uint32");let o=n>>>3,i=n&7;if(o<=0||i>5)throw new Error("illegal tag: field no "+o+" wire type "+i);return[o,i]}skip(t,n,r=100){let o=this.pos;switch(t){case Gt.Varint:for(;this.buf[this.pos++]&128;);break;case Gt.Bit64:this.pos+=4;case Gt.Bit32:this.pos+=4;break;case Gt.LengthDelimited:let i=this.uint32();this.pos+=i;break;case Gt.StartGroup:if(r<=0)throw new Error("maximum recursion depth reached");for(;;){let[a,s]=this.tag();if(s===Gt.EndGroup){if(n!==void 0&&a!==n)throw new Error("invalid end group tag");break}this.skip(s,a,r-1)}break;default:throw new Error("cant skip wire type "+t)}return this.assertBounds(),this.buf.subarray(o,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)}int64(){return this.varint64(),dt.dec(this.varint64Lo,this.varint64Hi)}uint64(){return this.varint64(),dt.uDec(this.varint64Lo,this.varint64Hi)}sint64(){this.varint64();let t=this.varint64Lo,n=this.varint64Hi,r=-(t&1);return t=(t>>>1|(n&1)<<31)^r,n=n>>>1^r,dt.dec(t,n)}bool(){let t=this.buf[this.pos];return t<128?(this.pos++,t!==0):(this.varint64(),this.varint64Lo!==0||this.varint64Hi!==0)}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return dt.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return dt.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let t=this.uint32(),n=this.pos;return this.pos+=t,this.assertBounds(),this.buf.subarray(n,n+t)}string(t){let n=this.bytes(),r=n.length;if(r<=Pg){let o=new Array(r);for(let i=0;i<r;i++){let a=n[i];if(a>127)return this.decodeUtf8(n,t);o[i]=a}return String.fromCharCode.apply(String,o)}return this.decodeUtf8(n,t)}};function fu(e){if(typeof e=="string")e=Number(e);else if(typeof e!="number")throw new Error("invalid int32: "+typeof e);if(!Number.isInteger(e)||e>C0||e<N0)throw new Error("invalid int32: "+e)}function Ng(e){if(typeof e=="string")e=Number(e);else if(typeof e!="number")throw new Error("invalid uint32: "+typeof e);if(!Number.isInteger(e)||e>R0||e<0)throw new Error("invalid uint32: "+e)}function M0(e){if(typeof e=="string"){let t=e;if(e=Number(e),Number.isNaN(e)&&t!=="NaN")throw new Error("invalid float32: "+t)}else if(typeof e!="number")throw new Error("invalid float32: "+typeof e);if(!Number.isFinite(Math.fround(e))&&Number.isFinite(e))throw new Error("invalid float32: "+e)}var z0=(function(e){return e[e.NULL_VALUE=0]="NULL_VALUE",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e})({});function mu(){return{fields:{}}}var re={encode(e,t=new U){return Object.entries(e.fields).forEach(([n,r])=>{r!==void 0&&bu.encode({key:n,value:r},t.uint32(10).fork()).join()}),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=mu();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:{if(i!==10)break;let a=bu.decode(n,n.uint32());a.value!==void 0&&(o.fields[a.key]=a.value);continue}}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return re.fromPartial(e??{})},fromPartial(e){let t=mu();return t.fields=Object.entries(e.fields??{}).reduce((n,[r,o])=>(o!==void 0&&(n[r]=o),n),{}),t},wrap(e){let t=mu();if(e!==void 0)for(let n of Object.keys(e))t.fields[n]=e[n];return t},unwrap(e){let t={};if(e.fields)for(let n of Object.keys(e.fields))t[n]=e.fields[n];return t}};function Mg(){return{key:"",value:void 0}}var bu={encode(e,t=new U){return e.key!==""&&t.uint32(10).string(e.key),e.value!==void 0&&D.encode(D.wrap(e.value),t.uint32(18).fork()).join(),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Mg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.key=n.string();continue;case 2:if(i!==18)break;o.value=D.unwrap(D.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return bu.fromPartial(e??{})},fromPartial(e){let t=Mg();return t.key=e.key??"",t.value=e.value??void 0,t}};function gu(){return{nullValue:void 0,numberValue:void 0,stringValue:void 0,boolValue:void 0,structValue:void 0,listValue:void 0}}var D={encode(e,t=new U){return e.nullValue!==void 0&&t.uint32(8).int32(e.nullValue),e.numberValue!==void 0&&t.uint32(17).double(e.numberValue),e.stringValue!==void 0&&t.uint32(26).string(e.stringValue),e.boolValue!==void 0&&t.uint32(32).bool(e.boolValue),e.structValue!==void 0&&re.encode(re.wrap(e.structValue),t.uint32(42).fork()).join(),e.listValue!==void 0&&Yr.encode(Yr.wrap(e.listValue),t.uint32(50).fork()).join(),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=gu();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.nullValue=n.int32();continue;case 2:if(i!==17)break;o.numberValue=n.double();continue;case 3:if(i!==26)break;o.stringValue=n.string();continue;case 4:if(i!==32)break;o.boolValue=n.bool();continue;case 5:if(i!==42)break;o.structValue=re.unwrap(re.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.listValue=Yr.unwrap(Yr.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return D.fromPartial(e??{})},fromPartial(e){let t=gu();return t.nullValue=e.nullValue??void 0,t.numberValue=e.numberValue??void 0,t.stringValue=e.stringValue??void 0,t.boolValue=e.boolValue??void 0,t.structValue=e.structValue??void 0,t.listValue=e.listValue??void 0,t},wrap(e){let t=gu();if(e===null)t.nullValue=z0.NULL_VALUE;else if(typeof e=="boolean")t.boolValue=e;else if(typeof e=="number")t.numberValue=e;else if(typeof e=="string")t.stringValue=e;else if(globalThis.Array.isArray(e))t.listValue=e;else if(typeof e=="object")t.structValue=e;else if(typeof e<"u")throw new globalThis.Error("Unsupported any value type: "+typeof e);return t},unwrap(e){if(e.stringValue!==void 0)return e.stringValue;if(e?.numberValue!==void 0)return e.numberValue;if(e?.boolValue!==void 0)return e.boolValue;if(e?.structValue!==void 0)return e.structValue;if(e?.listValue!==void 0)return e.listValue;if(e?.nullValue!==void 0)return null}};function vu(){return{values:[]}}var Yr={encode(e,t=new U){for(let n of e.values)D.encode(D.wrap(n),t.uint32(10).fork()).join();return t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=vu();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.values.push(D.unwrap(D.decode(n,n.uint32())));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Yr.fromPartial(e??{})},fromPartial(e){let t=vu();return t.values=e.values?.map(n=>n)||[],t},wrap(e){let t=vu();return t.values=e??[],t},unwrap(e){return e?.hasOwnProperty("values")&&globalThis.Array.isArray(e.values)?e.values:e}},zg=(function(e){return e[e.ADD=0]="ADD",e[e.REMOVE=1]="REMOVE",e[e.REPLACE=2]="REPLACE",e[e.MOVE=3]="MOVE",e[e.COPY=4]="COPY",e[e.TEST=5]="TEST",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e})({});function Lg(){return{op:0,path:"",from:void 0,value:void 0}}var vn={encode(e,t=new U){return e.op!==0&&t.uint32(8).int32(e.op),e.path!==""&&t.uint32(18).string(e.path),e.from!==void 0&&t.uint32(26).string(e.from),e.value!==void 0&&D.encode(D.wrap(e.value),t.uint32(34).fork()).join(),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Lg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.op=n.int32();continue;case 2:if(i!==18)break;o.path=n.string();continue;case 3:if(i!==26)break;o.from=n.string();continue;case 4:if(i!==34)break;o.value=D.unwrap(D.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return vn.fromPartial(e??{})},fromPartial(e){let t=Lg();return t.op=e.op??0,t.path=e.path??"",t.from=e.from??void 0,t.value=e.value??void 0,t}};function Dg(){return{text:"",id:void 0,metadata:void 0}}var Xi={encode(e,t=new U){return e.text!==""&&t.uint32(10).string(e.text),e.id!==void 0&&t.uint32(18).string(e.id),e.metadata!==void 0&&D.encode(D.wrap(e.metadata),t.uint32(26).fork()).join(),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Dg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.text=n.string();continue;case 2:if(i!==18)break;o.id=n.string();continue;case 3:if(i!==26)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Xi.fromPartial(e??{})},fromPartial(e){let t=Dg();return t.text=e.text??"",t.id=e.id??void 0,t.metadata=e.metadata??void 0,t}};function $g(){return{source:void 0,metadata:void 0,id:void 0}}var Ki={encode(e,t=new U){return e.source!==void 0&&Ke.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&D.encode(D.wrap(e.metadata),t.uint32(18).fork()).join(),e.id!==void 0&&t.uint32(26).string(e.id),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=$g();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ke.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.id=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Ki.fromPartial(e??{})},fromPartial(e){let t=$g();return t.source=e.source!==void 0&&e.source!==null?Ke.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t.id=e.id??void 0,t}};function Ug(){return{value:"",mimeType:""}}var Ji={encode(e,t=new U){return e.value!==""&&t.uint32(10).string(e.value),e.mimeType!==""&&t.uint32(18).string(e.mimeType),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Ug();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.value=n.string();continue;case 2:if(i!==18)break;o.mimeType=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Ji.fromPartial(e??{})},fromPartial(e){let t=Ug();return t.value=e.value??"",t.mimeType=e.mimeType??"",t}};function Hg(){return{value:"",mimeType:void 0}}var Qi={encode(e,t=new U){return e.value!==""&&t.uint32(10).string(e.value),e.mimeType!==void 0&&t.uint32(18).string(e.mimeType),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Hg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.value=n.string();continue;case 2:if(i!==18)break;o.mimeType=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Qi.fromPartial(e??{})},fromPartial(e){let t=Hg();return t.value=e.value??"",t.mimeType=e.mimeType??void 0,t}};function Fg(){return{value:"",provider:void 0,mimeType:void 0}}var ea={encode(e,t=new U){return e.value!==""&&t.uint32(10).string(e.value),e.provider!==void 0&&t.uint32(18).string(e.provider),e.mimeType!==void 0&&t.uint32(26).string(e.mimeType),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Fg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.value=n.string();continue;case 2:if(i!==18)break;o.provider=n.string();continue;case 3:if(i!==26)break;o.mimeType=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ea.fromPartial(e??{})},fromPartial(e){let t=Fg();return t.value=e.value??"",t.provider=e.provider??void 0,t.mimeType=e.mimeType??void 0,t}};function Gg(){return{data:void 0,url:void 0,file:void 0}}var Ke={encode(e,t=new U){return e.data!==void 0&&Ji.encode(e.data,t.uint32(10).fork()).join(),e.url!==void 0&&Qi.encode(e.url,t.uint32(18).fork()).join(),e.file!==void 0&&ea.encode(e.file,t.uint32(26).fork()).join(),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Gg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.data=Ji.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.url=Qi.decode(n,n.uint32());continue;case 3:if(i!==26)break;o.file=ea.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Ke.fromPartial(e??{})},fromPartial(e){let t=Gg();return t.data=e.data!==void 0&&e.data!==null?Ji.fromPartial(e.data):void 0,t.url=e.url!==void 0&&e.url!==null?Qi.fromPartial(e.url):void 0,t.file=e.file!==void 0&&e.file!==null?ea.fromPartial(e.file):void 0,t}};function Bg(){return{source:void 0,metadata:void 0,id:void 0}}var ta={encode(e,t=new U){return e.source!==void 0&&Ke.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&D.encode(D.wrap(e.metadata),t.uint32(18).fork()).join(),e.id!==void 0&&t.uint32(26).string(e.id),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Bg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ke.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.id=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ta.fromPartial(e??{})},fromPartial(e){let t=Bg();return t.source=e.source!==void 0&&e.source!==null?Ke.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t.id=e.id??void 0,t}};function Zg(){return{source:void 0,metadata:void 0,id:void 0}}var na={encode(e,t=new U){return e.source!==void 0&&Ke.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&D.encode(D.wrap(e.metadata),t.uint32(18).fork()).join(),e.id!==void 0&&t.uint32(26).string(e.id),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Zg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ke.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.id=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return na.fromPartial(e??{})},fromPartial(e){let t=Zg();return t.source=e.source!==void 0&&e.source!==null?Ke.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t.id=e.id??void 0,t}};function Vg(){return{source:void 0,metadata:void 0,id:void 0}}var ra={encode(e,t=new U){return e.source!==void 0&&Ke.encode(e.source,t.uint32(10).fork()).join(),e.metadata!==void 0&&D.encode(D.wrap(e.metadata),t.uint32(18).fork()).join(),e.id!==void 0&&t.uint32(26).string(e.id),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Vg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Ke.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.id=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ra.fromPartial(e??{})},fromPartial(e){let t=Vg();return t.source=e.source!==void 0&&e.source!==null?Ke.fromPartial(e.source):void 0,t.metadata=e.metadata??void 0,t.id=e.id??void 0,t}};function jg(){return{text:void 0,image:void 0,audio:void 0,video:void 0,document:void 0}}var bn={encode(e,t=new U){return e.text!==void 0&&Xi.encode(e.text,t.uint32(10).fork()).join(),e.image!==void 0&&Ki.encode(e.image,t.uint32(18).fork()).join(),e.audio!==void 0&&ta.encode(e.audio,t.uint32(26).fork()).join(),e.video!==void 0&&na.encode(e.video,t.uint32(34).fork()).join(),e.document!==void 0&&ra.encode(e.document,t.uint32(42).fork()).join(),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=jg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.text=Xi.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.image=Ki.decode(n,n.uint32());continue;case 3:if(i!==26)break;o.audio=ta.decode(n,n.uint32());continue;case 4:if(i!==34)break;o.video=na.decode(n,n.uint32());continue;case 5:if(i!==42)break;o.document=ra.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return bn.fromPartial(e??{})},fromPartial(e){let t=jg();return t.text=e.text!==void 0&&e.text!==null?Xi.fromPartial(e.text):void 0,t.image=e.image!==void 0&&e.image!==null?Ki.fromPartial(e.image):void 0,t.audio=e.audio!==void 0&&e.audio!==null?ta.fromPartial(e.audio):void 0,t.video=e.video!==void 0&&e.video!==null?na.fromPartial(e.video):void 0,t.document=e.document!==void 0&&e.document!==null?ra.fromPartial(e.document):void 0,t}};function Wg(){return{id:"",type:"",function:void 0,metadata:void 0,encryptedValue:void 0}}var oa={encode(e,t=new U){return e.id!==""&&t.uint32(10).string(e.id),e.type!==""&&t.uint32(18).string(e.type),e.function!==void 0&&ia.encode(e.function,t.uint32(26).fork()).join(),e.metadata!==void 0&&re.encode(re.wrap(e.metadata),t.uint32(34).fork()).join(),e.encryptedValue!==void 0&&t.uint32(42).string(e.encryptedValue),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Wg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.type=n.string();continue;case 3:if(i!==26)break;o.function=ia.decode(n,n.uint32());continue;case 4:if(i!==34)break;o.metadata=re.unwrap(re.decode(n,n.uint32()));continue;case 5:if(i!==42)break;o.encryptedValue=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return oa.fromPartial(e??{})},fromPartial(e){let t=Wg();return t.id=e.id??"",t.type=e.type??"",t.function=e.function!==void 0&&e.function!==null?ia.fromPartial(e.function):void 0,t.metadata=e.metadata??void 0,t.encryptedValue=e.encryptedValue??void 0,t}};function qg(){return{name:"",arguments:""}}var ia={encode(e,t=new U){return e.name!==""&&t.uint32(10).string(e.name),e.arguments!==""&&t.uint32(18).string(e.arguments),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=qg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.name=n.string();continue;case 2:if(i!==18)break;o.arguments=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ia.fromPartial(e??{})},fromPartial(e){let t=qg();return t.name=e.name??"",t.arguments=e.arguments??"",t}};function Yg(){return{id:"",role:"",content:void 0,name:void 0,toolCalls:[],toolCallId:void 0,error:void 0,contentParts:[],metadata:void 0,subagentRunId:void 0,encryptedValue:void 0,activityType:void 0,activityContent:void 0}}var yn={encode(e,t=new U){e.id!==""&&t.uint32(10).string(e.id),e.role!==""&&t.uint32(18).string(e.role),e.content!==void 0&&t.uint32(26).string(e.content),e.name!==void 0&&t.uint32(34).string(e.name);for(let n of e.toolCalls)oa.encode(n,t.uint32(42).fork()).join();e.toolCallId!==void 0&&t.uint32(50).string(e.toolCallId),e.error!==void 0&&t.uint32(58).string(e.error);for(let n of e.contentParts)bn.encode(n,t.uint32(66).fork()).join();return e.metadata!==void 0&&re.encode(re.wrap(e.metadata),t.uint32(74).fork()).join(),e.subagentRunId!==void 0&&t.uint32(82).string(e.subagentRunId),e.encryptedValue!==void 0&&t.uint32(90).string(e.encryptedValue),e.activityType!==void 0&&t.uint32(98).string(e.activityType),e.activityContent!==void 0&&re.encode(re.wrap(e.activityContent),t.uint32(106).fork()).join(),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Yg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.role=n.string();continue;case 3:if(i!==26)break;o.content=n.string();continue;case 4:if(i!==34)break;o.name=n.string();continue;case 5:if(i!==42)break;o.toolCalls.push(oa.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.toolCallId=n.string();continue;case 7:if(i!==58)break;o.error=n.string();continue;case 8:if(i!==66)break;o.contentParts.push(bn.decode(n,n.uint32()));continue;case 9:if(i!==74)break;o.metadata=re.unwrap(re.decode(n,n.uint32()));continue;case 10:if(i!==82)break;o.subagentRunId=n.string();continue;case 11:if(i!==90)break;o.encryptedValue=n.string();continue;case 12:if(i!==98)break;o.activityType=n.string();continue;case 13:if(i!==106)break;o.activityContent=re.unwrap(re.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return yn.fromPartial(e??{})},fromPartial(e){let t=Yg();return t.id=e.id??"",t.role=e.role??"",t.content=e.content??void 0,t.name=e.name??void 0,t.toolCalls=e.toolCalls?.map(n=>oa.fromPartial(n))||[],t.toolCallId=e.toolCallId??void 0,t.error=e.error??void 0,t.contentParts=e.contentParts?.map(n=>bn.fromPartial(n))||[],t.metadata=e.metadata??void 0,t.subagentRunId=e.subagentRunId??void 0,t.encryptedValue=e.encryptedValue??void 0,t.activityType=e.activityType??void 0,t.activityContent=e.activityContent??void 0,t}};function Xg(){return{name:"",description:"",parameters:void 0,metadata:void 0}}var aa={encode(e,t=new U){return e.name!==""&&t.uint32(10).string(e.name),e.description!==""&&t.uint32(18).string(e.description),e.parameters!==void 0&&D.encode(D.wrap(e.parameters),t.uint32(26).fork()).join(),e.metadata!==void 0&&re.encode(re.wrap(e.metadata),t.uint32(34).fork()).join(),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Xg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.name=n.string();continue;case 2:if(i!==18)break;o.description=n.string();continue;case 3:if(i!==26)break;o.parameters=D.unwrap(D.decode(n,n.uint32()));continue;case 4:if(i!==34)break;o.metadata=re.unwrap(re.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return aa.fromPartial(e??{})},fromPartial(e){let t=Xg();return t.name=e.name??"",t.description=e.description??"",t.parameters=e.parameters??void 0,t.metadata=e.metadata??void 0,t}};function Kg(){return{description:"",value:""}}var sa={encode(e,t=new U){return e.description!==""&&t.uint32(10).string(e.description),e.value!==""&&t.uint32(18).string(e.value),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Kg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.description=n.string();continue;case 2:if(i!==18)break;o.value=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return sa.fromPartial(e??{})},fromPartial(e){let t=Kg();return t.description=e.description??"",t.value=e.value??"",t}};function Jg(){return{interruptId:"",status:"",payload:void 0,metadata:void 0}}var la={encode(e,t=new U){return e.interruptId!==""&&t.uint32(10).string(e.interruptId),e.status!==""&&t.uint32(18).string(e.status),e.payload!==void 0&&D.encode(D.wrap(e.payload),t.uint32(26).fork()).join(),e.metadata!==void 0&&re.encode(re.wrap(e.metadata),t.uint32(34).fork()).join(),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Jg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.interruptId=n.string();continue;case 2:if(i!==18)break;o.status=n.string();continue;case 3:if(i!==26)break;o.payload=D.unwrap(D.decode(n,n.uint32()));continue;case 4:if(i!==34)break;o.metadata=re.unwrap(re.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return la.fromPartial(e??{})},fromPartial(e){let t=Jg();return t.interruptId=e.interruptId??"",t.status=e.status??"",t.payload=e.payload??void 0,t.metadata=e.metadata??void 0,t}};function Qg(){return{threadId:"",runId:"",parentRunId:void 0,state:void 0,messages:[],tools:[],context:[],forwardedProps:void 0,resume:[],protocolVersion:void 0}}var ca={encode(e,t=new U){e.threadId!==""&&t.uint32(10).string(e.threadId),e.runId!==""&&t.uint32(18).string(e.runId),e.parentRunId!==void 0&&t.uint32(26).string(e.parentRunId),e.state!==void 0&&D.encode(D.wrap(e.state),t.uint32(34).fork()).join();for(let n of e.messages)yn.encode(n,t.uint32(42).fork()).join();for(let n of e.tools)aa.encode(n,t.uint32(50).fork()).join();for(let n of e.context)sa.encode(n,t.uint32(58).fork()).join();e.forwardedProps!==void 0&&D.encode(D.wrap(e.forwardedProps),t.uint32(66).fork()).join();for(let n of e.resume)la.encode(n,t.uint32(74).fork()).join();return e.protocolVersion!==void 0&&t.uint32(82).string(e.protocolVersion),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Qg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.threadId=n.string();continue;case 2:if(i!==18)break;o.runId=n.string();continue;case 3:if(i!==26)break;o.parentRunId=n.string();continue;case 4:if(i!==34)break;o.state=D.unwrap(D.decode(n,n.uint32()));continue;case 5:if(i!==42)break;o.messages.push(yn.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.tools.push(aa.decode(n,n.uint32()));continue;case 7:if(i!==58)break;o.context.push(sa.decode(n,n.uint32()));continue;case 8:if(i!==66)break;o.forwardedProps=D.unwrap(D.decode(n,n.uint32()));continue;case 9:if(i!==74)break;o.resume.push(la.decode(n,n.uint32()));continue;case 10:if(i!==82)break;o.protocolVersion=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ca.fromPartial(e??{})},fromPartial(e){let t=Qg();return t.threadId=e.threadId??"",t.runId=e.runId??"",t.parentRunId=e.parentRunId??void 0,t.state=e.state??void 0,t.messages=e.messages?.map(n=>yn.fromPartial(n))||[],t.tools=e.tools?.map(n=>aa.fromPartial(n))||[],t.context=e.context?.map(n=>sa.fromPartial(n))||[],t.forwardedProps=e.forwardedProps??void 0,t.resume=e.resume?.map(n=>la.fromPartial(n))||[],t.protocolVersion=e.protocolVersion??void 0,t}};function ev(){return{id:"",reason:"",message:void 0,toolCallId:void 0,responseSchema:void 0,expiresAt:void 0,metadata:void 0,subagentRunId:void 0}}var ua={encode(e,t=new U){return e.id!==""&&t.uint32(10).string(e.id),e.reason!==""&&t.uint32(18).string(e.reason),e.message!==void 0&&t.uint32(26).string(e.message),e.toolCallId!==void 0&&t.uint32(34).string(e.toolCallId),e.responseSchema!==void 0&&D.encode(D.wrap(e.responseSchema),t.uint32(42).fork()).join(),e.expiresAt!==void 0&&t.uint32(50).string(e.expiresAt),e.metadata!==void 0&&D.encode(D.wrap(e.metadata),t.uint32(58).fork()).join(),e.subagentRunId!==void 0&&t.uint32(66).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=ev();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.reason=n.string();continue;case 3:if(i!==26)break;o.message=n.string();continue;case 4:if(i!==34)break;o.toolCallId=n.string();continue;case 5:if(i!==42)break;o.responseSchema=D.unwrap(D.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.expiresAt=n.string();continue;case 7:if(i!==58)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue;case 8:if(i!==66)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ua.fromPartial(e??{})},fromPartial(e){let t=ev();return t.id=e.id??"",t.reason=e.reason??"",t.message=e.message??void 0,t.toolCallId=e.toolCallId??void 0,t.responseSchema=e.responseSchema??void 0,t.expiresAt=e.expiresAt??void 0,t.metadata=e.metadata??void 0,t.subagentRunId=e.subagentRunId??void 0,t}},L0=(function(e){return e[e.TEXT_MESSAGE_START=0]="TEXT_MESSAGE_START",e[e.TEXT_MESSAGE_CONTENT=1]="TEXT_MESSAGE_CONTENT",e[e.TEXT_MESSAGE_END=2]="TEXT_MESSAGE_END",e[e.TOOL_CALL_START=3]="TOOL_CALL_START",e[e.TOOL_CALL_ARGS=4]="TOOL_CALL_ARGS",e[e.TOOL_CALL_END=5]="TOOL_CALL_END",e[e.STATE_SNAPSHOT=6]="STATE_SNAPSHOT",e[e.STATE_DELTA=7]="STATE_DELTA",e[e.MESSAGES_SNAPSHOT=8]="MESSAGES_SNAPSHOT",e[e.RAW=9]="RAW",e[e.CUSTOM=10]="CUSTOM",e[e.RUN_STARTED=11]="RUN_STARTED",e[e.RUN_FINISHED=12]="RUN_FINISHED",e[e.RUN_ERROR=13]="RUN_ERROR",e[e.STEP_STARTED=14]="STEP_STARTED",e[e.STEP_FINISHED=15]="STEP_FINISHED",e[e.SUBAGENT_STARTED=16]="SUBAGENT_STARTED",e[e.SUBAGENT_FINISHED=17]="SUBAGENT_FINISHED",e[e.SUBAGENT_ERROR=18]="SUBAGENT_ERROR",e[e.TEXT_MESSAGE_CHUNK=19]="TEXT_MESSAGE_CHUNK",e[e.TOOL_CALL_CHUNK=20]="TOOL_CALL_CHUNK",e[e.TOOL_CALL_RESULT=21]="TOOL_CALL_RESULT",e[e.ACTIVITY_SNAPSHOT=22]="ACTIVITY_SNAPSHOT",e[e.ACTIVITY_DELTA=23]="ACTIVITY_DELTA",e[e.REASONING_START=24]="REASONING_START",e[e.REASONING_MESSAGE_START=25]="REASONING_MESSAGE_START",e[e.REASONING_MESSAGE_CONTENT=26]="REASONING_MESSAGE_CONTENT",e[e.REASONING_MESSAGE_END=27]="REASONING_MESSAGE_END",e[e.REASONING_MESSAGE_CHUNK=28]="REASONING_MESSAGE_CHUNK",e[e.REASONING_END=29]="REASONING_END",e[e.REASONING_ENCRYPTED_VALUE=30]="REASONING_ENCRYPTED_VALUE",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e})({});function tv(){return{type:0,timestamp:void 0,rawEvent:void 0,metadata:void 0}}var M={encode(e,t=new U){return e.type!==0&&t.uint32(8).int32(e.type),e.timestamp!==void 0&&t.uint32(16).int64(e.timestamp),e.rawEvent!==void 0&&D.encode(D.wrap(e.rawEvent),t.uint32(26).fork()).join(),e.metadata!==void 0&&re.encode(re.wrap(e.metadata),t.uint32(34).fork()).join(),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=tv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.type=n.int32();continue;case 2:if(i!==16)break;o.timestamp=mn(n.int64());continue;case 3:if(i!==26)break;o.rawEvent=D.unwrap(D.decode(n,n.uint32()));continue;case 4:if(i!==34)break;o.metadata=re.unwrap(re.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return M.fromPartial(e??{})},fromPartial(e){let t=tv();return t.type=e.type??0,t.timestamp=e.timestamp??void 0,t.rawEvent=e.rawEvent??void 0,t.metadata=e.metadata??void 0,t}};function nv(){return{baseEvent:void 0,messageId:"",role:void 0,name:void 0,subagentRunId:void 0}}var da={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==""&&t.uint32(18).string(e.messageId),e.role!==void 0&&t.uint32(26).string(e.role),e.name!==void 0&&t.uint32(34).string(e.name),e.subagentRunId!==void 0&&t.uint32(42).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=nv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.role=n.string();continue;case 4:if(i!==34)break;o.name=n.string();continue;case 5:if(i!==42)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return da.fromPartial(e??{})},fromPartial(e){let t=nv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??"",t.role=e.role??void 0,t.name=e.name??void 0,t.subagentRunId=e.subagentRunId??void 0,t}};function rv(){return{baseEvent:void 0,messageId:"",delta:"",subagentRunId:void 0}}var pa={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==""&&t.uint32(18).string(e.messageId),e.delta!==""&&t.uint32(26).string(e.delta),e.subagentRunId!==void 0&&t.uint32(34).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=rv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.delta=n.string();continue;case 4:if(i!==34)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return pa.fromPartial(e??{})},fromPartial(e){let t=rv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??"",t.delta=e.delta??"",t.subagentRunId=e.subagentRunId??void 0,t}};function ov(){return{baseEvent:void 0,messageId:"",subagentRunId:void 0}}var ha={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==""&&t.uint32(18).string(e.messageId),e.subagentRunId!==void 0&&t.uint32(26).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=ov();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ha.fromPartial(e??{})},fromPartial(e){let t=ov();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??"",t.subagentRunId=e.subagentRunId??void 0,t}};function iv(){return{baseEvent:void 0,messageId:void 0,role:void 0,delta:void 0,name:void 0,subagentRunId:void 0}}var fa={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.messageId!==void 0&&t.uint32(18).string(e.messageId),e.role!==void 0&&t.uint32(26).string(e.role),e.delta!==void 0&&t.uint32(34).string(e.delta),e.name!==void 0&&t.uint32(42).string(e.name),e.subagentRunId!==void 0&&t.uint32(50).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=iv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.role=n.string();continue;case 4:if(i!==34)break;o.delta=n.string();continue;case 5:if(i!==42)break;o.name=n.string();continue;case 6:if(i!==50)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return fa.fromPartial(e??{})},fromPartial(e){let t=iv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.messageId=e.messageId??void 0,t.role=e.role??void 0,t.delta=e.delta??void 0,t.name=e.name??void 0,t.subagentRunId=e.subagentRunId??void 0,t}};function av(){return{baseEvent:void 0,toolCallId:"",toolCallName:"",parentMessageId:void 0,subagentRunId:void 0}}var ma={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==""&&t.uint32(18).string(e.toolCallId),e.toolCallName!==""&&t.uint32(26).string(e.toolCallName),e.parentMessageId!==void 0&&t.uint32(34).string(e.parentMessageId),e.subagentRunId!==void 0&&t.uint32(42).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=av();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.toolCallName=n.string();continue;case 4:if(i!==34)break;o.parentMessageId=n.string();continue;case 5:if(i!==42)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ma.fromPartial(e??{})},fromPartial(e){let t=av();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??"",t.toolCallName=e.toolCallName??"",t.parentMessageId=e.parentMessageId??void 0,t.subagentRunId=e.subagentRunId??void 0,t}};function sv(){return{baseEvent:void 0,toolCallId:"",delta:"",subagentRunId:void 0}}var ga={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==""&&t.uint32(18).string(e.toolCallId),e.delta!==""&&t.uint32(26).string(e.delta),e.subagentRunId!==void 0&&t.uint32(34).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=sv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.delta=n.string();continue;case 4:if(i!==34)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ga.fromPartial(e??{})},fromPartial(e){let t=sv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??"",t.delta=e.delta??"",t.subagentRunId=e.subagentRunId??void 0,t}};function lv(){return{baseEvent:void 0,toolCallId:"",subagentRunId:void 0}}var va={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==""&&t.uint32(18).string(e.toolCallId),e.subagentRunId!==void 0&&t.uint32(26).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=lv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return va.fromPartial(e??{})},fromPartial(e){let t=lv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??"",t.subagentRunId=e.subagentRunId??void 0,t}};function cv(){return{baseEvent:void 0,toolCallId:void 0,toolCallName:void 0,parentMessageId:void 0,delta:void 0,subagentRunId:void 0}}var ba={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.toolCallId!==void 0&&t.uint32(18).string(e.toolCallId),e.toolCallName!==void 0&&t.uint32(26).string(e.toolCallName),e.parentMessageId!==void 0&&t.uint32(34).string(e.parentMessageId),e.delta!==void 0&&t.uint32(42).string(e.delta),e.subagentRunId!==void 0&&t.uint32(50).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=cv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.toolCallName=n.string();continue;case 4:if(i!==34)break;o.parentMessageId=n.string();continue;case 5:if(i!==42)break;o.delta=n.string();continue;case 6:if(i!==50)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ba.fromPartial(e??{})},fromPartial(e){let t=cv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.toolCallId=e.toolCallId??void 0,t.toolCallName=e.toolCallName??void 0,t.parentMessageId=e.parentMessageId??void 0,t.delta=e.delta??void 0,t.subagentRunId=e.subagentRunId??void 0,t}};function uv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:"",toolCallId:"",content:void 0,role:void 0,contentParts:[]}}var ya={encode(e,t=new U){e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==void 0&&t.uint32(18).string(e.subagentRunId),e.messageId!==""&&t.uint32(26).string(e.messageId),e.toolCallId!==""&&t.uint32(34).string(e.toolCallId),e.content!==void 0&&t.uint32(42).string(e.content),e.role!==void 0&&t.uint32(50).string(e.role);for(let n of e.contentParts)bn.encode(n,t.uint32(58).fork()).join();return t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=uv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.toolCallId=n.string();continue;case 5:if(i!==42)break;o.content=n.string();continue;case 6:if(i!==50)break;o.role=n.string();continue;case 7:if(i!==58)break;o.contentParts.push(bn.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ya.fromPartial(e??{})},fromPartial(e){let t=uv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??void 0,t.messageId=e.messageId??"",t.toolCallId=e.toolCallId??"",t.content=e.content??void 0,t.role=e.role??void 0,t.contentParts=e.contentParts?.map(n=>bn.fromPartial(n))||[],t}};function dv(){return{baseEvent:void 0,snapshot:void 0,subagentRunId:void 0}}var wa={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.snapshot!==void 0&&D.encode(D.wrap(e.snapshot),t.uint32(18).fork()).join(),e.subagentRunId!==void 0&&t.uint32(26).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=dv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.snapshot=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return wa.fromPartial(e??{})},fromPartial(e){let t=dv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.snapshot=e.snapshot??void 0,t.subagentRunId=e.subagentRunId??void 0,t}};function pv(){return{baseEvent:void 0,delta:[],subagentRunId:void 0}}var Ea={encode(e,t=new U){e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join();for(let n of e.delta)vn.encode(n,t.uint32(18).fork()).join();return e.subagentRunId!==void 0&&t.uint32(26).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=pv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.delta.push(vn.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Ea.fromPartial(e??{})},fromPartial(e){let t=pv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.delta=e.delta?.map(n=>vn.fromPartial(n))||[],t.subagentRunId=e.subagentRunId??void 0,t}};function hv(){return{baseEvent:void 0,messages:[]}}var xa={encode(e,t=new U){e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join();for(let n of e.messages)yn.encode(n,t.uint32(18).fork()).join();return t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=hv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messages.push(yn.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return xa.fromPartial(e??{})},fromPartial(e){let t=hv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.messages=e.messages?.map(n=>yn.fromPartial(n))||[],t}};function fv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:"",activityType:"",content:void 0,replace:void 0}}var _a={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==void 0&&t.uint32(18).string(e.subagentRunId),e.messageId!==""&&t.uint32(26).string(e.messageId),e.activityType!==""&&t.uint32(34).string(e.activityType),e.content!==void 0&&re.encode(re.wrap(e.content),t.uint32(42).fork()).join(),e.replace!==void 0&&t.uint32(48).bool(e.replace),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=fv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.activityType=n.string();continue;case 5:if(i!==42)break;o.content=re.unwrap(re.decode(n,n.uint32()));continue;case 6:if(i!==48)break;o.replace=n.bool();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return _a.fromPartial(e??{})},fromPartial(e){let t=fv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??void 0,t.messageId=e.messageId??"",t.activityType=e.activityType??"",t.content=e.content??void 0,t.replace=e.replace??void 0,t}};function mv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:"",activityType:"",patch:[]}}var Sa={encode(e,t=new U){e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==void 0&&t.uint32(18).string(e.subagentRunId),e.messageId!==""&&t.uint32(26).string(e.messageId),e.activityType!==""&&t.uint32(34).string(e.activityType);for(let n of e.patch)vn.encode(n,t.uint32(42).fork()).join();return t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=mv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.activityType=n.string();continue;case 5:if(i!==42)break;o.patch.push(vn.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Sa.fromPartial(e??{})},fromPartial(e){let t=mv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??void 0,t.messageId=e.messageId??"",t.activityType=e.activityType??"",t.patch=e.patch?.map(n=>vn.fromPartial(n))||[],t}};function gv(){return{baseEvent:void 0,event:void 0,source:void 0,subagentRunId:void 0}}var Ta={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.event!==void 0&&D.encode(D.wrap(e.event),t.uint32(18).fork()).join(),e.source!==void 0&&t.uint32(26).string(e.source),e.subagentRunId!==void 0&&t.uint32(34).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=gv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.event=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.source=n.string();continue;case 4:if(i!==34)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Ta.fromPartial(e??{})},fromPartial(e){let t=gv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.event=e.event??void 0,t.source=e.source??void 0,t.subagentRunId=e.subagentRunId??void 0,t}};function vv(){return{baseEvent:void 0,name:"",value:void 0,subagentRunId:void 0}}var Aa={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.name!==""&&t.uint32(18).string(e.name),e.value!==void 0&&D.encode(D.wrap(e.value),t.uint32(26).fork()).join(),e.subagentRunId!==void 0&&t.uint32(34).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=vv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.name=n.string();continue;case 3:if(i!==26)break;o.value=D.unwrap(D.decode(n,n.uint32()));continue;case 4:if(i!==34)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Aa.fromPartial(e??{})},fromPartial(e){let t=vv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.name=e.name??"",t.value=e.value??void 0,t.subagentRunId=e.subagentRunId??void 0,t}};function bv(){return{baseEvent:void 0,threadId:"",runId:"",parentRunId:void 0,input:void 0,protocolVersion:void 0}}var ka={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.threadId!==""&&t.uint32(18).string(e.threadId),e.runId!==""&&t.uint32(26).string(e.runId),e.parentRunId!==void 0&&t.uint32(34).string(e.parentRunId),e.input!==void 0&&ca.encode(e.input,t.uint32(42).fork()).join(),e.protocolVersion!==void 0&&t.uint32(50).string(e.protocolVersion),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=bv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.threadId=n.string();continue;case 3:if(i!==26)break;o.runId=n.string();continue;case 4:if(i!==34)break;o.parentRunId=n.string();continue;case 5:if(i!==42)break;o.input=ca.decode(n,n.uint32());continue;case 6:if(i!==50)break;o.protocolVersion=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return ka.fromPartial(e??{})},fromPartial(e){let t=bv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.threadId=e.threadId??"",t.runId=e.runId??"",t.parentRunId=e.parentRunId??void 0,t.input=e.input!==void 0&&e.input!==null?ca.fromPartial(e.input):void 0,t.protocolVersion=e.protocolVersion??void 0,t}};function yv(){return{baseEvent:void 0,threadId:"",runId:"",result:void 0,outcome:"",interrupts:[],usage:[],pendingToolCallIds:[]}}var Ia={encode(e,t=new U){e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.threadId!==""&&t.uint32(18).string(e.threadId),e.runId!==""&&t.uint32(26).string(e.runId),e.result!==void 0&&D.encode(D.wrap(e.result),t.uint32(34).fork()).join(),e.outcome!==""&&t.uint32(42).string(e.outcome);for(let n of e.interrupts)ua.encode(n,t.uint32(50).fork()).join();for(let n of e.usage)wn.encode(n,t.uint32(58).fork()).join();for(let n of e.pendingToolCallIds)t.uint32(66).string(n);return t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=yv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.threadId=n.string();continue;case 3:if(i!==26)break;o.runId=n.string();continue;case 4:if(i!==34)break;o.result=D.unwrap(D.decode(n,n.uint32()));continue;case 5:if(i!==42)break;o.outcome=n.string();continue;case 6:if(i!==50)break;o.interrupts.push(ua.decode(n,n.uint32()));continue;case 7:if(i!==58)break;o.usage.push(wn.decode(n,n.uint32()));continue;case 8:if(i!==66)break;o.pendingToolCallIds.push(n.string());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Ia.fromPartial(e??{})},fromPartial(e){let t=yv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.threadId=e.threadId??"",t.runId=e.runId??"",t.result=e.result??void 0,t.outcome=e.outcome??"",t.interrupts=e.interrupts?.map(n=>ua.fromPartial(n))||[],t.usage=e.usage?.map(n=>wn.fromPartial(n))||[],t.pendingToolCallIds=e.pendingToolCallIds?.map(n=>n)||[],t}};function wv(){return{baseEvent:void 0,code:void 0,message:"",usage:[]}}var Ra={encode(e,t=new U){e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.code!==void 0&&t.uint32(18).string(e.code),e.message!==""&&t.uint32(26).string(e.message);for(let n of e.usage)wn.encode(n,t.uint32(34).fork()).join();return t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=wv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.code=n.string();continue;case 3:if(i!==26)break;o.message=n.string();continue;case 4:if(i!==34)break;o.usage.push(wn.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Ra.fromPartial(e??{})},fromPartial(e){let t=wv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.code=e.code??void 0,t.message=e.message??"",t.usage=e.usage?.map(n=>wn.fromPartial(n))||[],t}};function Ev(){return{baseEvent:void 0,stepName:"",subagentRunId:void 0}}var Ca={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.stepName!==""&&t.uint32(18).string(e.stepName),e.subagentRunId!==void 0&&t.uint32(26).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Ev();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.stepName=n.string();continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Ca.fromPartial(e??{})},fromPartial(e){let t=Ev();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.stepName=e.stepName??"",t.subagentRunId=e.subagentRunId??void 0,t}};function xv(){return{baseEvent:void 0,stepName:"",subagentRunId:void 0}}var Na={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.stepName!==""&&t.uint32(18).string(e.stepName),e.subagentRunId!==void 0&&t.uint32(26).string(e.subagentRunId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=xv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.stepName=n.string();continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Na.fromPartial(e??{})},fromPartial(e){let t=xv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.stepName=e.stepName??"",t.subagentRunId=e.subagentRunId??void 0,t}};function _v(){return{baseEvent:void 0,subagentRunId:void 0,messageId:""}}var Oa={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==void 0&&t.uint32(18).string(e.subagentRunId),e.messageId!==""&&t.uint32(26).string(e.messageId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=_v();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Oa.fromPartial(e??{})},fromPartial(e){let t=_v();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??void 0,t.messageId=e.messageId??"",t}};function Sv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:"",role:""}}var Pa={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==void 0&&t.uint32(18).string(e.subagentRunId),e.messageId!==""&&t.uint32(26).string(e.messageId),e.role!==""&&t.uint32(34).string(e.role),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Sv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.role=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Pa.fromPartial(e??{})},fromPartial(e){let t=Sv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??void 0,t.messageId=e.messageId??"",t.role=e.role??"",t}};function Tv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:"",delta:""}}var Ma={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==void 0&&t.uint32(18).string(e.subagentRunId),e.messageId!==""&&t.uint32(26).string(e.messageId),e.delta!==""&&t.uint32(34).string(e.delta),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Tv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.delta=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Ma.fromPartial(e??{})},fromPartial(e){let t=Tv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??void 0,t.messageId=e.messageId??"",t.delta=e.delta??"",t}};function Av(){return{baseEvent:void 0,subagentRunId:void 0,messageId:""}}var za={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==void 0&&t.uint32(18).string(e.subagentRunId),e.messageId!==""&&t.uint32(26).string(e.messageId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Av();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return za.fromPartial(e??{})},fromPartial(e){let t=Av();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??void 0,t.messageId=e.messageId??"",t}};function kv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:void 0,delta:void 0}}var La={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==void 0&&t.uint32(18).string(e.subagentRunId),e.messageId!==void 0&&t.uint32(26).string(e.messageId),e.delta!==void 0&&t.uint32(34).string(e.delta),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=kv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.delta=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return La.fromPartial(e??{})},fromPartial(e){let t=kv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??void 0,t.messageId=e.messageId??void 0,t.delta=e.delta??void 0,t}};function Iv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:""}}var Da={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==void 0&&t.uint32(18).string(e.subagentRunId),e.messageId!==""&&t.uint32(26).string(e.messageId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Iv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Da.fromPartial(e??{})},fromPartial(e){let t=Iv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??void 0,t.messageId=e.messageId??"",t}};function Rv(){return{baseEvent:void 0,subagentRunId:void 0,subtype:"",entityId:"",encryptedValue:""}}var $a={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==void 0&&t.uint32(18).string(e.subagentRunId),e.subtype!==""&&t.uint32(26).string(e.subtype),e.entityId!==""&&t.uint32(34).string(e.entityId),e.encryptedValue!==""&&t.uint32(42).string(e.encryptedValue),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Rv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.subtype=n.string();continue;case 4:if(i!==34)break;o.entityId=n.string();continue;case 5:if(i!==42)break;o.encryptedValue=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return $a.fromPartial(e??{})},fromPartial(e){let t=Rv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??void 0,t.subtype=e.subtype??"",t.entityId=e.entityId??"",t.encryptedValue=e.encryptedValue??"",t}};function Cv(){return{baseEvent:void 0,subagentRunId:"",name:"",description:void 0,parentSubagentRunId:void 0,parentToolCallId:void 0,parentMessageId:void 0}}var Ua={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==""&&t.uint32(18).string(e.subagentRunId),e.name!==""&&t.uint32(26).string(e.name),e.description!==void 0&&t.uint32(34).string(e.description),e.parentSubagentRunId!==void 0&&t.uint32(42).string(e.parentSubagentRunId),e.parentToolCallId!==void 0&&t.uint32(50).string(e.parentToolCallId),e.parentMessageId!==void 0&&t.uint32(58).string(e.parentMessageId),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Cv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.name=n.string();continue;case 4:if(i!==34)break;o.description=n.string();continue;case 5:if(i!==42)break;o.parentSubagentRunId=n.string();continue;case 6:if(i!==50)break;o.parentToolCallId=n.string();continue;case 7:if(i!==58)break;o.parentMessageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Ua.fromPartial(e??{})},fromPartial(e){let t=Cv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??"",t.name=e.name??"",t.description=e.description??void 0,t.parentSubagentRunId=e.parentSubagentRunId??void 0,t.parentToolCallId=e.parentToolCallId??void 0,t.parentMessageId=e.parentMessageId??void 0,t}};function Nv(){return{baseEvent:void 0,subagentRunId:"",result:void 0,outcome:"",interruptIds:[]}}var Ha={encode(e,t=new U){e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==""&&t.uint32(18).string(e.subagentRunId),e.result!==void 0&&D.encode(D.wrap(e.result),t.uint32(26).fork()).join(),e.outcome!==""&&t.uint32(34).string(e.outcome);for(let n of e.interruptIds)t.uint32(42).string(n);return t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Nv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.result=D.unwrap(D.decode(n,n.uint32()));continue;case 4:if(i!==34)break;o.outcome=n.string();continue;case 5:if(i!==42)break;o.interruptIds.push(n.string());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Ha.fromPartial(e??{})},fromPartial(e){let t=Nv();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??"",t.result=e.result??void 0,t.outcome=e.outcome??"",t.interruptIds=e.interruptIds?.map(n=>n)||[],t}};function Ov(){return{baseEvent:void 0,subagentRunId:"",message:"",code:void 0}}var Fa={encode(e,t=new U){return e.baseEvent!==void 0&&M.encode(e.baseEvent,t.uint32(10).fork()).join(),e.subagentRunId!==""&&t.uint32(18).string(e.subagentRunId),e.message!==""&&t.uint32(26).string(e.message),e.code!==void 0&&t.uint32(34).string(e.code),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Ov();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.message=n.string();continue;case 4:if(i!==34)break;o.code=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Fa.fromPartial(e??{})},fromPartial(e){let t=Ov();return t.baseEvent=e.baseEvent!==void 0&&e.baseEvent!==null?M.fromPartial(e.baseEvent):void 0,t.subagentRunId=e.subagentRunId??"",t.message=e.message??"",t.code=e.code??void 0,t}};function Pv(){return{textMessageStart:void 0,textMessageContent:void 0,textMessageEnd:void 0,toolCallStart:void 0,toolCallArgs:void 0,toolCallEnd:void 0,stateSnapshot:void 0,stateDelta:void 0,messagesSnapshot:void 0,raw:void 0,custom:void 0,runStarted:void 0,runFinished:void 0,runError:void 0,stepStarted:void 0,stepFinished:void 0,textMessageChunk:void 0,toolCallChunk:void 0,subagentStarted:void 0,subagentFinished:void 0,subagentError:void 0,toolCallResult:void 0,activitySnapshot:void 0,activityDelta:void 0,reasoningStart:void 0,reasoningMessageStart:void 0,reasoningMessageContent:void 0,reasoningMessageEnd:void 0,reasoningMessageChunk:void 0,reasoningEnd:void 0,reasoningEncryptedValue:void 0}}var Lv={encode(e,t=new U){return e.textMessageStart!==void 0&&da.encode(e.textMessageStart,t.uint32(10).fork()).join(),e.textMessageContent!==void 0&&pa.encode(e.textMessageContent,t.uint32(18).fork()).join(),e.textMessageEnd!==void 0&&ha.encode(e.textMessageEnd,t.uint32(26).fork()).join(),e.toolCallStart!==void 0&&ma.encode(e.toolCallStart,t.uint32(34).fork()).join(),e.toolCallArgs!==void 0&&ga.encode(e.toolCallArgs,t.uint32(42).fork()).join(),e.toolCallEnd!==void 0&&va.encode(e.toolCallEnd,t.uint32(50).fork()).join(),e.stateSnapshot!==void 0&&wa.encode(e.stateSnapshot,t.uint32(58).fork()).join(),e.stateDelta!==void 0&&Ea.encode(e.stateDelta,t.uint32(66).fork()).join(),e.messagesSnapshot!==void 0&&xa.encode(e.messagesSnapshot,t.uint32(74).fork()).join(),e.raw!==void 0&&Ta.encode(e.raw,t.uint32(82).fork()).join(),e.custom!==void 0&&Aa.encode(e.custom,t.uint32(90).fork()).join(),e.runStarted!==void 0&&ka.encode(e.runStarted,t.uint32(98).fork()).join(),e.runFinished!==void 0&&Ia.encode(e.runFinished,t.uint32(106).fork()).join(),e.runError!==void 0&&Ra.encode(e.runError,t.uint32(114).fork()).join(),e.stepStarted!==void 0&&Ca.encode(e.stepStarted,t.uint32(122).fork()).join(),e.stepFinished!==void 0&&Na.encode(e.stepFinished,t.uint32(130).fork()).join(),e.textMessageChunk!==void 0&&fa.encode(e.textMessageChunk,t.uint32(138).fork()).join(),e.toolCallChunk!==void 0&&ba.encode(e.toolCallChunk,t.uint32(146).fork()).join(),e.subagentStarted!==void 0&&Ua.encode(e.subagentStarted,t.uint32(154).fork()).join(),e.subagentFinished!==void 0&&Ha.encode(e.subagentFinished,t.uint32(162).fork()).join(),e.subagentError!==void 0&&Fa.encode(e.subagentError,t.uint32(170).fork()).join(),e.toolCallResult!==void 0&&ya.encode(e.toolCallResult,t.uint32(178).fork()).join(),e.activitySnapshot!==void 0&&_a.encode(e.activitySnapshot,t.uint32(186).fork()).join(),e.activityDelta!==void 0&&Sa.encode(e.activityDelta,t.uint32(194).fork()).join(),e.reasoningStart!==void 0&&Oa.encode(e.reasoningStart,t.uint32(202).fork()).join(),e.reasoningMessageStart!==void 0&&Pa.encode(e.reasoningMessageStart,t.uint32(210).fork()).join(),e.reasoningMessageContent!==void 0&&Ma.encode(e.reasoningMessageContent,t.uint32(218).fork()).join(),e.reasoningMessageEnd!==void 0&&za.encode(e.reasoningMessageEnd,t.uint32(226).fork()).join(),e.reasoningMessageChunk!==void 0&&La.encode(e.reasoningMessageChunk,t.uint32(234).fork()).join(),e.reasoningEnd!==void 0&&Da.encode(e.reasoningEnd,t.uint32(242).fork()).join(),e.reasoningEncryptedValue!==void 0&&$a.encode(e.reasoningEncryptedValue,t.uint32(250).fork()).join(),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Pv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.textMessageStart=da.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.textMessageContent=pa.decode(n,n.uint32());continue;case 3:if(i!==26)break;o.textMessageEnd=ha.decode(n,n.uint32());continue;case 4:if(i!==34)break;o.toolCallStart=ma.decode(n,n.uint32());continue;case 5:if(i!==42)break;o.toolCallArgs=ga.decode(n,n.uint32());continue;case 6:if(i!==50)break;o.toolCallEnd=va.decode(n,n.uint32());continue;case 7:if(i!==58)break;o.stateSnapshot=wa.decode(n,n.uint32());continue;case 8:if(i!==66)break;o.stateDelta=Ea.decode(n,n.uint32());continue;case 9:if(i!==74)break;o.messagesSnapshot=xa.decode(n,n.uint32());continue;case 10:if(i!==82)break;o.raw=Ta.decode(n,n.uint32());continue;case 11:if(i!==90)break;o.custom=Aa.decode(n,n.uint32());continue;case 12:if(i!==98)break;o.runStarted=ka.decode(n,n.uint32());continue;case 13:if(i!==106)break;o.runFinished=Ia.decode(n,n.uint32());continue;case 14:if(i!==114)break;o.runError=Ra.decode(n,n.uint32());continue;case 15:if(i!==122)break;o.stepStarted=Ca.decode(n,n.uint32());continue;case 16:if(i!==130)break;o.stepFinished=Na.decode(n,n.uint32());continue;case 17:if(i!==138)break;o.textMessageChunk=fa.decode(n,n.uint32());continue;case 18:if(i!==146)break;o.toolCallChunk=ba.decode(n,n.uint32());continue;case 19:if(i!==154)break;o.subagentStarted=Ua.decode(n,n.uint32());continue;case 20:if(i!==162)break;o.subagentFinished=Ha.decode(n,n.uint32());continue;case 21:if(i!==170)break;o.subagentError=Fa.decode(n,n.uint32());continue;case 22:if(i!==178)break;o.toolCallResult=ya.decode(n,n.uint32());continue;case 23:if(i!==186)break;o.activitySnapshot=_a.decode(n,n.uint32());continue;case 24:if(i!==194)break;o.activityDelta=Sa.decode(n,n.uint32());continue;case 25:if(i!==202)break;o.reasoningStart=Oa.decode(n,n.uint32());continue;case 26:if(i!==210)break;o.reasoningMessageStart=Pa.decode(n,n.uint32());continue;case 27:if(i!==218)break;o.reasoningMessageContent=Ma.decode(n,n.uint32());continue;case 28:if(i!==226)break;o.reasoningMessageEnd=za.decode(n,n.uint32());continue;case 29:if(i!==234)break;o.reasoningMessageChunk=La.decode(n,n.uint32());continue;case 30:if(i!==242)break;o.reasoningEnd=Da.decode(n,n.uint32());continue;case 31:if(i!==250)break;o.reasoningEncryptedValue=$a.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return Lv.fromPartial(e??{})},fromPartial(e){let t=Pv();return t.textMessageStart=e.textMessageStart!==void 0&&e.textMessageStart!==null?da.fromPartial(e.textMessageStart):void 0,t.textMessageContent=e.textMessageContent!==void 0&&e.textMessageContent!==null?pa.fromPartial(e.textMessageContent):void 0,t.textMessageEnd=e.textMessageEnd!==void 0&&e.textMessageEnd!==null?ha.fromPartial(e.textMessageEnd):void 0,t.toolCallStart=e.toolCallStart!==void 0&&e.toolCallStart!==null?ma.fromPartial(e.toolCallStart):void 0,t.toolCallArgs=e.toolCallArgs!==void 0&&e.toolCallArgs!==null?ga.fromPartial(e.toolCallArgs):void 0,t.toolCallEnd=e.toolCallEnd!==void 0&&e.toolCallEnd!==null?va.fromPartial(e.toolCallEnd):void 0,t.stateSnapshot=e.stateSnapshot!==void 0&&e.stateSnapshot!==null?wa.fromPartial(e.stateSnapshot):void 0,t.stateDelta=e.stateDelta!==void 0&&e.stateDelta!==null?Ea.fromPartial(e.stateDelta):void 0,t.messagesSnapshot=e.messagesSnapshot!==void 0&&e.messagesSnapshot!==null?xa.fromPartial(e.messagesSnapshot):void 0,t.raw=e.raw!==void 0&&e.raw!==null?Ta.fromPartial(e.raw):void 0,t.custom=e.custom!==void 0&&e.custom!==null?Aa.fromPartial(e.custom):void 0,t.runStarted=e.runStarted!==void 0&&e.runStarted!==null?ka.fromPartial(e.runStarted):void 0,t.runFinished=e.runFinished!==void 0&&e.runFinished!==null?Ia.fromPartial(e.runFinished):void 0,t.runError=e.runError!==void 0&&e.runError!==null?Ra.fromPartial(e.runError):void 0,t.stepStarted=e.stepStarted!==void 0&&e.stepStarted!==null?Ca.fromPartial(e.stepStarted):void 0,t.stepFinished=e.stepFinished!==void 0&&e.stepFinished!==null?Na.fromPartial(e.stepFinished):void 0,t.textMessageChunk=e.textMessageChunk!==void 0&&e.textMessageChunk!==null?fa.fromPartial(e.textMessageChunk):void 0,t.toolCallChunk=e.toolCallChunk!==void 0&&e.toolCallChunk!==null?ba.fromPartial(e.toolCallChunk):void 0,t.subagentStarted=e.subagentStarted!==void 0&&e.subagentStarted!==null?Ua.fromPartial(e.subagentStarted):void 0,t.subagentFinished=e.subagentFinished!==void 0&&e.subagentFinished!==null?Ha.fromPartial(e.subagentFinished):void 0,t.subagentError=e.subagentError!==void 0&&e.subagentError!==null?Fa.fromPartial(e.subagentError):void 0,t.toolCallResult=e.toolCallResult!==void 0&&e.toolCallResult!==null?ya.fromPartial(e.toolCallResult):void 0,t.activitySnapshot=e.activitySnapshot!==void 0&&e.activitySnapshot!==null?_a.fromPartial(e.activitySnapshot):void 0,t.activityDelta=e.activityDelta!==void 0&&e.activityDelta!==null?Sa.fromPartial(e.activityDelta):void 0,t.reasoningStart=e.reasoningStart!==void 0&&e.reasoningStart!==null?Oa.fromPartial(e.reasoningStart):void 0,t.reasoningMessageStart=e.reasoningMessageStart!==void 0&&e.reasoningMessageStart!==null?Pa.fromPartial(e.reasoningMessageStart):void 0,t.reasoningMessageContent=e.reasoningMessageContent!==void 0&&e.reasoningMessageContent!==null?Ma.fromPartial(e.reasoningMessageContent):void 0,t.reasoningMessageEnd=e.reasoningMessageEnd!==void 0&&e.reasoningMessageEnd!==null?za.fromPartial(e.reasoningMessageEnd):void 0,t.reasoningMessageChunk=e.reasoningMessageChunk!==void 0&&e.reasoningMessageChunk!==null?La.fromPartial(e.reasoningMessageChunk):void 0,t.reasoningEnd=e.reasoningEnd!==void 0&&e.reasoningEnd!==null?Da.fromPartial(e.reasoningEnd):void 0,t.reasoningEncryptedValue=e.reasoningEncryptedValue!==void 0&&e.reasoningEncryptedValue!==null?$a.fromPartial(e.reasoningEncryptedValue):void 0,t}};function Mv(){return{provider:void 0,model:void 0,inputTokens:void 0,outputTokens:void 0,totalTokens:void 0,reasoningTokens:void 0,cachedInputTokens:void 0,cacheWriteInputTokens:void 0}}var wn={encode(e,t=new U){return e.provider!==void 0&&t.uint32(10).string(e.provider),e.model!==void 0&&t.uint32(18).string(e.model),e.inputTokens!==void 0&&t.uint32(24).int64(e.inputTokens),e.outputTokens!==void 0&&t.uint32(32).int64(e.outputTokens),e.totalTokens!==void 0&&t.uint32(40).int64(e.totalTokens),e.reasoningTokens!==void 0&&t.uint32(48).int64(e.reasoningTokens),e.cachedInputTokens!==void 0&&t.uint32(56).int64(e.cachedInputTokens),e.cacheWriteInputTokens!==void 0&&t.uint32(64).int64(e.cacheWriteInputTokens),t},decode(e,t){let n=e instanceof R?e:new R(e),r=t===void 0?n.len:n.pos+t,o=Mv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.provider=n.string();continue;case 2:if(i!==18)break;o.model=n.string();continue;case 3:if(i!==24)break;o.inputTokens=mn(n.int64());continue;case 4:if(i!==32)break;o.outputTokens=mn(n.int64());continue;case 5:if(i!==40)break;o.totalTokens=mn(n.int64());continue;case 6:if(i!==48)break;o.reasoningTokens=mn(n.int64());continue;case 7:if(i!==56)break;o.cachedInputTokens=mn(n.int64());continue;case 8:if(i!==64)break;o.cacheWriteInputTokens=mn(n.int64());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(e){return wn.fromPartial(e??{})},fromPartial(e){let t=Mv();return t.provider=e.provider??void 0,t.model=e.model??void 0,t.inputTokens=e.inputTokens??void 0,t.outputTokens=e.outputTokens??void 0,t.totalTokens=e.totalTokens??void 0,t.reasoningTokens=e.reasoningTokens??void 0,t.cachedInputTokens=e.cachedInputTokens??void 0,t.cacheWriteInputTokens=e.cacheWriteInputTokens??void 0,t}};function mn(e){let t=globalThis.Number(e.toString());if(t>globalThis.Number.MAX_SAFE_INTEGER)throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");if(t<globalThis.Number.MIN_SAFE_INTEGER)throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");return t}var sr=e=>e&&typeof e=="object"?e:void 0,he=e=>Array.isArray(e)?e:[],D0=()=>typeof process<"u"&&typeof process.env<"u"&&!!process.env.SUPPRESS_TRANSFORMATION_WARNINGS,Dv=()=>{D0()||console.warn("[ag-ui][proto] Dropped a content part this build does not know: the protocol has a variant this SDK predates.")};var Fz=new Set(Object.values(v)),$0={textMessageStart:"TEXT_MESSAGE_START",textMessageContent:"TEXT_MESSAGE_CONTENT",textMessageEnd:"TEXT_MESSAGE_END",textMessageChunk:"TEXT_MESSAGE_CHUNK",toolCallStart:"TOOL_CALL_START",toolCallArgs:"TOOL_CALL_ARGS",toolCallEnd:"TOOL_CALL_END",toolCallChunk:"TOOL_CALL_CHUNK",toolCallResult:"TOOL_CALL_RESULT",stateSnapshot:"STATE_SNAPSHOT",stateDelta:"STATE_DELTA",messagesSnapshot:"MESSAGES_SNAPSHOT",activitySnapshot:"ACTIVITY_SNAPSHOT",activityDelta:"ACTIVITY_DELTA",raw:"RAW",custom:"CUSTOM",runStarted:"RUN_STARTED",runFinished:"RUN_FINISHED",runError:"RUN_ERROR",stepStarted:"STEP_STARTED",stepFinished:"STEP_FINISHED",reasoningStart:"REASONING_START",reasoningMessageStart:"REASONING_MESSAGE_START",reasoningMessageContent:"REASONING_MESSAGE_CONTENT",reasoningMessageEnd:"REASONING_MESSAGE_END",reasoningMessageChunk:"REASONING_MESSAGE_CHUNK",reasoningEnd:"REASONING_END",reasoningEncryptedValue:"REASONING_ENCRYPTED_VALUE",subagentStarted:"SUBAGENT_STARTED",subagentFinished:"SUBAGENT_FINISHED",subagentError:"SUBAGENT_ERROR"},gn=new Set([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]);var Bt=e=>{let t=sr(e);if(t){if([t.data,t.url,t.file].filter(Boolean).length>1)throw new Error("Invalid event: source carries more than one arm");if(t.data){let n=t.data;return{type:"data",value:n.value,mimeType:n.mimeType}}if(t.url){let n=t.url;return{type:"url",value:n.value,mimeType:n.mimeType}}if(t.file){let n=t.file;return{type:"file",value:n.value,provider:n.provider,mimeType:n.mimeType}}}};var $v=e=>{let t=sr(e);if(t){if([t.text,t.image,t.audio,t.video,t.document].filter(Boolean).length>1)throw new Error("Invalid event: content part carries more than one arm");if(t.text){let n=t.text;return{type:"text",id:n.id,text:n.text,metadata:n.metadata}}if(t.image){let n=t.image;return n.source!==void 0&&Bt(n.source)===void 0?void 0:{type:"image",id:n.id,source:Bt(n.source),metadata:n.metadata}}if(t.audio){let n=t.audio;return n.source!==void 0&&Bt(n.source)===void 0?void 0:{type:"audio",id:n.id,source:Bt(n.source),metadata:n.metadata}}if(t.video){let n=t.video;return n.source!==void 0&&Bt(n.source)===void 0?void 0:{type:"video",id:n.id,source:Bt(n.source),metadata:n.metadata}}if(t.document){let n=t.document;return n.source!==void 0&&Bt(n.source)===void 0?void 0:{type:"document",id:n.id,source:Bt(n.source),metadata:n.metadata}}}},U0=new Set(["activity"]),H0=new Set(["user","tool"]),F0=new Set(["developer","system","assistant","user","tool","activity","reasoning"]);var Uv=e=>{let t=sr(e)??{},n={...t},r=typeof t.role=="string"?t.role:"",o=F0.has(r),i=o?H0.has(r):he(t.contentParts).length>0,a=o?U0.has(r):!i&&t.activityContent!==void 0;if(!o&&(t.content!==void 0?1:0)+(he(t.contentParts).length>0?1:0)+(t.activityContent!==void 0?1:0)>1)throw new Error("Invalid event: message carries more than one content form");if(o){if(!i&&he(t.contentParts).length>0)throw new Error("Invalid event: message carries content parts for a role that has none");if(t.activityContent!==void 0&&!a)throw new Error("Invalid event: message carries activity content for a non-activity role");if(a&&t.content!==void 0)throw new Error("Invalid event: activity content cannot ride with other content forms");if(i&&t.content!==void 0&&he(t.contentParts).length>0)throw new Error("Invalid event: message carries both string content and content parts")}return i&&t.content===void 0&&(n.content=he(t.contentParts).map(s=>{let l=$v(s);return l===void 0&&Dv(),l}).filter(s=>s!==void 0)),a&&t.activityContent!==void 0&&(n.content=t.activityContent),delete n.activityContent,delete n.contentParts,he(t.toolCalls).length===0&&delete n.toolCalls,Object.keys(n).forEach(s=>{n[s]===void 0&&delete n[s]}),n},yu=e=>{if(Array.isArray(e)){for(let n of e)yu(n);return}let t=sr(e);if(t)for(let n of Object.keys(t))t[n]===void 0?delete t[n]:yu(t[n])};var G0=e=>{let t=sr(e);if(!t)return;let n={};return t.threadId!==void 0&&(n.threadId=t.threadId),t.runId!==void 0&&(n.runId=t.runId),t.protocolVersion!==void 0&&(n.protocolVersion=t.protocolVersion),t.parentRunId!==void 0&&(n.parentRunId=t.parentRunId),t.state!==void 0&&(n.state=t.state),n.messages=he(t.messages).map(Uv).filter(r=>r!==void 0),n.tools=he(t.tools),n.context=he(t.context),t.forwardedProps!==void 0&&(n.forwardedProps=t.forwardedProps),n.resume=he(t.resume),n};var wu={TextMessageStartEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},BaseEvent:{singular:new Set([3,4]),descend:{},google:{3:"google.protobuf.Value",4:"google.protobuf.Struct"}},TextMessageContentEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},TextMessageEndEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ToolCallStartEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ToolCallArgsEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ToolCallEndEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},StateSnapshotEvent:{singular:new Set([1,2]),descend:{1:"BaseEvent"},google:{2:"google.protobuf.Value"}},StateDeltaEvent:{singular:new Set([1]),descend:{1:"BaseEvent",2:"JsonPatchOperation"}},JsonPatchOperation:{singular:new Set([4]),descend:{},google:{4:"google.protobuf.Value"}},MessagesSnapshotEvent:{singular:new Set([1]),descend:{1:"BaseEvent",2:"Message"}},Message:{singular:new Set([9,13]),descend:{5:"ToolCall",8:"InputContent"},google:{9:"google.protobuf.Struct",13:"google.protobuf.Struct"}},ToolCall:{singular:new Set([3,4]),descend:{},google:{4:"google.protobuf.Struct"}},InputContent:{singular:new Set([1,2,3,4,5]),descend:{1:"TextInputPart",2:"ImageInputPart",3:"AudioInputPart",4:"VideoInputPart",5:"DocumentInputPart"},arms:new Set([1,2,3,4,5])},TextInputPart:{singular:new Set([3]),descend:{},google:{3:"google.protobuf.Value"}},ImageInputPart:{singular:new Set([1,2]),descend:{1:"InputContentSource"},google:{2:"google.protobuf.Value"}},InputContentSource:{singular:new Set([1,2,3]),descend:{},arms:new Set([1,2,3])},AudioInputPart:{singular:new Set([1,2]),descend:{1:"InputContentSource"},google:{2:"google.protobuf.Value"}},VideoInputPart:{singular:new Set([1,2]),descend:{1:"InputContentSource"},google:{2:"google.protobuf.Value"}},DocumentInputPart:{singular:new Set([1,2]),descend:{1:"InputContentSource"},google:{2:"google.protobuf.Value"}},RawEvent:{singular:new Set([1,2]),descend:{1:"BaseEvent"},google:{2:"google.protobuf.Value"}},CustomEvent:{singular:new Set([1,3]),descend:{1:"BaseEvent"},google:{3:"google.protobuf.Value"}},RunStartedEvent:{singular:new Set([1,5]),descend:{1:"BaseEvent",5:"RunAgentInput"}},RunAgentInput:{singular:new Set([4,8]),descend:{5:"Message",6:"Tool",9:"ResumeEntry"},google:{4:"google.protobuf.Value",8:"google.protobuf.Value"}},Tool:{singular:new Set([3,4]),descend:{},google:{3:"google.protobuf.Value",4:"google.protobuf.Struct"}},ResumeEntry:{singular:new Set([3,4]),descend:{},google:{3:"google.protobuf.Value",4:"google.protobuf.Struct"}},RunFinishedEvent:{singular:new Set([1,4]),descend:{1:"BaseEvent",6:"Interrupt"},google:{4:"google.protobuf.Value"}},Interrupt:{singular:new Set([5,7]),descend:{},google:{5:"google.protobuf.Value",7:"google.protobuf.Value"}},RunErrorEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},StepStartedEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},StepFinishedEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},TextMessageChunkEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ToolCallChunkEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},SubagentStartedEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},SubagentFinishedEvent:{singular:new Set([1,3]),descend:{1:"BaseEvent"},google:{3:"google.protobuf.Value"}},SubagentErrorEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ToolCallResultEvent:{singular:new Set([1]),descend:{1:"BaseEvent",7:"InputContent"}},ActivitySnapshotEvent:{singular:new Set([1,5]),descend:{1:"BaseEvent"},google:{5:"google.protobuf.Struct"}},ActivityDeltaEvent:{singular:new Set([1]),descend:{1:"BaseEvent",5:"JsonPatchOperation"}},ReasoningStartEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningMessageStartEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningMessageContentEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningMessageEndEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningMessageChunkEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningEndEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningEncryptedValueEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},"google.protobuf.Struct":{singular:new Set,descend:{1:"google.protobuf.Struct.FieldsEntry"}},"google.protobuf.Struct.FieldsEntry":{singular:new Set([2]),descend:{2:"google.protobuf.Value"}},"google.protobuf.Value":{singular:new Set([5,6]),descend:{5:"google.protobuf.Struct",6:"google.protobuf.ListValue"},arms:new Set([1,2,3,4,5,6]),armWireTypes:{1:0,2:1,3:2,4:0,5:2,6:2}},"google.protobuf.ListValue":{singular:new Set,descend:{1:"google.protobuf.Value"}}},Hv={1:"TextMessageStartEvent",2:"TextMessageContentEvent",3:"TextMessageEndEvent",4:"ToolCallStartEvent",5:"ToolCallArgsEvent",6:"ToolCallEndEvent",7:"StateSnapshotEvent",8:"StateDeltaEvent",9:"MessagesSnapshotEvent",10:"RawEvent",11:"CustomEvent",12:"RunStartedEvent",13:"RunFinishedEvent",14:"RunErrorEvent",15:"StepStartedEvent",16:"StepFinishedEvent",17:"TextMessageChunkEvent",18:"ToolCallChunkEvent",19:"SubagentStartedEvent",20:"SubagentFinishedEvent",21:"SubagentErrorEvent",22:"ToolCallResultEvent",23:"ActivitySnapshotEvent",24:"ActivityDeltaEvent",25:"ReasoningStartEvent",26:"ReasoningMessageStartEvent",27:"ReasoningMessageContentEvent",28:"ReasoningMessageEndEvent",29:"ReasoningMessageChunkEvent",30:"ReasoningEndEvent",31:"ReasoningEncryptedValueEvent"};function ar(e,t){let n=0,r=0;for(;;){if(t.offset>=e.length)throw new Error("Invalid event");let o=e[t.offset++];if(r<28?n+=(o&127)*2**r:r===28&&(n+=(o&15)*2**28),r+=7,(o&128)===0)return n}}function Fv(e,t){let n={offset:0},r=0,o=0;for(;n.offset<e.length;){let i=ar(e,n),a=Math.floor(i/8),s=i%8;if(a===0)throw new Error("Invalid event");if(s===3){r+=1;continue}if(s===4){if(r-=1,r<0)throw new Error("Invalid event");continue}if(s===0)ar(e,n);else if(s===1)n.offset+=8;else if(s===2){let l=ar(e,n);if(n.offset+l>e.length)throw new Error("Invalid event");if(r===0){if(t.arms?.has(a)){if(o!==0&&o!==a)throw new Error("Invalid event");o=a}let c=t.descend[a];if(c!==void 0){let u=wu[c];u!==void 0&&Fv(e.subarray(n.offset,n.offset+l),u)}}n.offset+=l}else if(s===5)n.offset+=4;else throw new Error("Invalid event");if(n.offset>e.length)throw new Error("Invalid event")}if(r!==0)throw new Error("Invalid event")}function B0(e){let t=new Set,n={offset:0},r=0;for(;n.offset<e.length;){let o=ar(e,n),i=Math.floor(o/8),a=o%8;if(i===0)throw new Error("Invalid event");if(a===3){r+=1;continue}if(a===4){if(r-=1,r<0)throw new Error("Invalid event");continue}if(r===0&&gn.has(i)){if(t.size>0&&!t.has(i))throw new Error("Invalid event");t.add(i)}if(a===0)ar(e,n);else if(a===1)n.offset+=8;else if(a===2){let s=ar(e,n);if(n.offset+s>e.length)throw new Error("Invalid event");if(r===0){let l=Hv[i];if(l!==void 0){let c=wu[l];c!==void 0&&Fv(e.subarray(n.offset,n.offset+s),c)}}n.offset+=s}else if(a===5)n.offset+=4;else throw new Error("Invalid event");if(n.offset>e.length)throw new Error("Invalid event")}if(r!==0)throw new Error("Invalid event")}function zv(e){if(e.length===1)return e[0];let t=new Uint8Array(e.reduce((r,o)=>r+o.length,0)),n=0;for(let r of e)t.set(r,n),n+=r.length;return t}function Gv(e,t){let n=new R(e),r=[],o=new Map,i,a=!1;for(;n.pos<n.len;){let l=n.pos,[c,u]=n.tag(),f=u===2?n.bytes():void 0;f===void 0&&n.skip(u,c);let m=t.arms?.has(c)&&u===(t.armWireTypes?.[c]??2);if(m){if(i!==void 0&&i!==c){let _=o.get(i);_!==void 0&&(r[_]=void 0),o.delete(i),a=!0}if(i=c,!t.singular.has(c)){let _=o.get(c);_!==void 0&&(r[_]=void 0,o.delete(c),a=!0)}}let p=t.descend[c]??t.google?.[c],h=f!==void 0&&(t.singular.has(c)||p!==void 0),E=o.get(c),g=E===void 0?void 0:r[E]?.payloads;if(h&&t.singular.has(c)&&g!==void 0){g.push(f),a=!0;continue}(h||m)&&o.set(c,r.length),r.push({number:c,raw:e.subarray(l,n.pos),...h&&{payloads:[f]},child:p===void 0?void 0:wu[p]})}let s=[];for(let l of r)if(l!==void 0){if(l.payloads!==void 0){let c=zv(l.payloads),u=l.child===void 0?c:Gv(c,l.child);if(l.payloads.length>1||u!==c){s.push(new U().uint32(l.number*8+2).bytes(u).finish()),a=!0;continue}}s.push(l.raw)}return a?zv(s):e}var Eu=class extends Error{constructor(e="Unknown event type"){super(e),this.name="AGUIUnknownEventTypeError"}};function Bv(e,t,n,r){let o=0,i=0,a=0;for(;;){if(t.offset>=e.length||a>=n)return-1;let s=e[t.offset++];if(a+=1,a===n&&s>r)return-1;if(o+=(s&127)*2**i,i+=7,(s&128)===0)return o}}var Ga=(e,t)=>Bv(e,t,5,15),Zv=(e,t)=>Bv(e,t,10,1);function Z0(e){let t={offset:0},n=[];for(;t.offset<e.length;){let r=Ga(e,t);if(r<0)return!1;let o=Math.floor(r/8),i=r%8;if(o===0)return!1;if(i===3)n.push(o);else if(i===4){if(n.pop()!==o)return!1}else if(i===0){if(Zv(e,t)<0)return!1}else if(i===1)t.offset+=8;else if(i===5)t.offset+=4;else if(i===2){let a=Ga(e,t);if(a<0||t.offset+a>e.length)return!1;t.offset+=a}else return!1;if(t.offset>e.length)return!1}return n.length===0}function V0(e){let t={offset:0},n=[],r=0;for(;t.offset<e.length;){let o=Ga(e,t);if(o<0)return!1;let i=Math.floor(o/8),a=o%8;if(i===0)return!1;let s=n.length===0;if(a===3){if(s&&gn.has(i))return!1;n.push(i)}else if(a===4){if(n.pop()!==i)return!1}else if(a===0){if(s&&gn.has(i)||Zv(e,t)<0)return!1}else if(a===1){if(s&&gn.has(i))return!1;t.offset+=8}else if(a===5){if(s&&gn.has(i))return!1;t.offset+=4}else if(a===2){let l=Ga(e,t);if(l<0||t.offset+l>e.length)return!1;if(s){if(gn.has(i)||!Z0(e.subarray(t.offset,t.offset+l)))return!1;r+=1}t.offset+=l}else return!1;if(t.offset>e.length)return!1}return n.length===0&&r>0}function Vv(e){B0(e);let t=Lv.decode(Gv(e,{singular:gn,descend:Hv})),n=Object.entries(t).filter(([,l])=>l!==void 0);if(n.length!==1)throw n.length===0&&V0(e)?new Eu:new Error("Invalid event");let r=n[0],o=$0[r[0]];if(o===void 0)throw new Error("Invalid event");let i=r[1],a=sr(i.baseEvent);if(!a)throw new Error("Invalid event");let s=L0[a.type];if(s!==o)throw new Error("Invalid event: envelope carries "+o+" but the base event declares "+String(s));if(i.type=o,i.timestamp=a.timestamp,i.rawEvent=a.rawEvent,a.metadata!==void 0&&(i.metadata=a.metadata),delete i.baseEvent,i.type==="MESSAGES_SNAPSHOT"&&Array.isArray(i.messages)&&(i.messages=i.messages.map(Uv).filter(l=>l!==void 0)),i.type==="RUN_FINISHED"){let l=i,c=typeof l.outcome=="string"&&l.outcome!==""?l.outcome:void 0,u={};u.pendingToolCallIds=l.pendingToolCallIds,delete l.pendingToolCallIds,u.interrupts=l.interrupts,delete l.interrupts,delete l.outcome,c===void 0&&(he(u.pendingToolCallIds).length>0&&(l.pendingToolCallIds=u.pendingToolCallIds),he(u.interrupts).length>0&&(l.interrupts=u.interrupts)),c==="success"&&(l.outcome={type:"success",...he(u.pendingToolCallIds).length>0?{pendingToolCallIds:u.pendingToolCallIds}:{},...he(u.interrupts).length>0?{interrupts:u.interrupts}:{}}),c==="interrupt"&&(l.outcome={type:"interrupt",interrupts:he(u.interrupts),...he(u.pendingToolCallIds).length>0?{pendingToolCallIds:u.pendingToolCallIds}:{}}),c==="cancelled"&&(l.outcome={type:"cancelled",...he(u.pendingToolCallIds).length>0?{pendingToolCallIds:u.pendingToolCallIds}:{},...he(u.interrupts).length>0?{interrupts:u.interrupts}:{}}),c!==void 0&&!["success","interrupt","cancelled"].includes(c)&&(l.outcome={type:c,...he(u.pendingToolCallIds).length>0?{pendingToolCallIds:u.pendingToolCallIds}:{},...he(u.interrupts).length>0?{interrupts:u.interrupts}:{}})}if(i.type==="SUBAGENT_FINISHED"){let l=i,c=typeof l.outcome=="string"&&l.outcome!==""?l.outcome:void 0,u={};u.interruptIds=l.interruptIds,delete l.interruptIds,delete l.outcome,c===void 0&&he(u.interruptIds).length>0&&(l.interruptIds=u.interruptIds),c==="success"&&(l.outcome={type:"success",...he(u.interruptIds).length>0?{interruptIds:u.interruptIds}:{}}),c==="suspended"&&(l.outcome={type:"suspended",...he(u.interruptIds).length>0?{interruptIds:u.interruptIds}:{}}),c!==void 0&&!["success","suspended"].includes(c)&&(l.outcome={type:c,...he(u.interruptIds).length>0?{interruptIds:u.interruptIds}:{}})}if(i.type==="STATE_DELTA"&&Array.isArray(i.delta)&&(i.delta=i.delta.map(l=>{let c=zg[l.op];return l.op=typeof c=="string"&&c!=="UNRECOGNIZED"?c.toLowerCase():String(l.op),Object.keys(l).forEach(u=>{l[u]===void 0&&delete l[u]}),l})),i.type==="ACTIVITY_DELTA"&&Array.isArray(i.patch)&&(i.patch=i.patch.map(l=>{let c=zg[l.op];return l.op=typeof c=="string"&&c!=="UNRECOGNIZED"?c.toLowerCase():String(l.op),Object.keys(l).forEach(u=>{l[u]===void 0&&delete l[u]}),l})),i.type==="RUN_FINISHED"&&Array.isArray(i.usage)&&i.usage.length===0&&delete i.usage,i.type==="RUN_ERROR"&&Array.isArray(i.usage)&&i.usage.length===0&&delete i.usage,i.type==="TOOL_CALL_RESULT"){let l=i;if(l.content!==void 0&&he(l.contentParts).length>0)throw new Error("Invalid event: content carries both string content and content parts");l.content===void 0&&(l.content=he(l.contentParts).map(c=>{let u=$v(c);return u===void 0&&Dv(),u}).filter(c=>c!==void 0)),delete l.contentParts}return i.type==="RUN_STARTED"&&i.input!==void 0&&(i.input=G0(i.input)),yu(i),i}var xu="application/vnd.ag-ui.event+proto";var _u=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,Su=e=>{if(typeof e!="string")throw new TypeError("Invalid argument expected string");let t=e.match(_u);if(!t)throw new Error(`Invalid argument not valid semver ('${e}' received)`);return t.shift(),t},jv=e=>e==="*"||e==="x"||e==="X",Wv=e=>{let t=parseInt(e,10);return isNaN(t)?e:t},W0=(e,t)=>typeof e!=typeof t?[String(e),String(t)]:[e,t],q0=(e,t)=>{if(jv(e)||jv(t))return 0;let[n,r]=W0(Wv(e),Wv(t));return n>r?1:n<r?-1:0},Tu=(e,t)=>{for(let n=0;n<Math.max(e.length,t.length);n++){let r=q0(e[n]||"0",t[n]||"0");if(r!==0)return r}return 0};var En=(e,t)=>{let n=Su(e),r=Su(t),o=n.pop(),i=r.pop(),a=Tu(n,r);return a!==0?a:o&&i?Tu(o.split("."),i.split(".")):o||i?o?-1:1:0};var Au=e=>typeof e=="string"&&/^[v\d]/.test(e)&&_u.test(e);var qv="@ag-ui/client";function Y0(e){if(!e.metadata||!Object.prototype.hasOwnProperty.call(e.metadata,qv))return;let t=e.metadata?.[qv];if(!t||typeof t!="object"||Array.isArray(t))return[];if(!Object.prototype.hasOwnProperty.call(t,"authoritativeActivityTypes"))return;let n=t.authoritativeActivityTypes;return n===null?null:Array.isArray(n)&&n.every(r=>typeof r=="string")?n:[]}var ne=e=>{if(typeof structuredClone=="function")return structuredClone(e);try{return JSON.parse(JSON.stringify(e))}catch{return Array.isArray(e)?[...e]:{...e}}};function _e(){return $t()}function X0(e){return e instanceof TypeError?/read[- ]?only|not extensible|cannot add property|cannot delete property|can't be deleted|unable to delete property|object is frozen|is not writable/i.test(e.message):!1}function Du(e){if(Object.freeze(e),typeof e=="object"&&e)for(let t of Object.values(e))typeof t=="object"&&t&&!Object.isFrozen(t)&&Du(t);return e}var Yv=512*1024;function Xv(e,t,n){let r=0,o=[e,t],i=new WeakSet;for(;o.length>0;){let a=o.pop();if(typeof a=="string"){if(r+=a.length,r>n)return!0}else if(typeof a=="object"&&a){if(i.has(a))continue;if(i.add(a),Array.isArray(a))for(let s=0;s<a.length;s++)o.push(a[s]);else{let s=Object.keys(a);for(let l=0;l<s.length;l++){let c=s[l];if(r+=c.length,r>n)return!0;o.push(a[c])}}}}return!1}async function ie(e,t,n,r){let o=typeof process<"u"&&process.env!==void 0,i=o&&!!process.env.VITEST_WORKER_ID,a=o&&!!process.env.VITEST_WORKER_ID,s=a&&!Xv(t,n,Yv),l=s?ne(t):t,c=s?ne(n):n,u=!1,f=!1,m;for(let p of e)try{s&&(Du(l),Du(c));let h=await r(p,l,c);if(h===void 0)continue;let E=!1;if(h.messages!==void 0&&h.messages!==l&&(l=ne(h.messages),u=!0,E=!0),h.state!==void 0&&h.state!==c&&(c=ne(h.state),f=!0,E=!0),s&&E&&Xv(l,c,Yv)&&(s=!1),m=h.stopPropagation,m===!0)break}catch(h){if(i&&h instanceof TypeError)throw h;s&&a&&X0(h)?console.error("AG-UI: Subscriber attempted to mutate frozen inputs in-place. Return mutations via AgentStateMutation instead of mutating directly.",h):console.error("Subscriber error:",h);continue}return{...u?{messages:Object.isFrozen(l)?ne(l):l}:{},...f?{state:Object.isFrozen(c)?ne(c):c}:{},...m===void 0?{}:{stopPropagation:m}}}function Va(e){if(!e)return{enabled:!1,events:!1,lifecycle:!1,verbose:!1};if(e===!0)return{enabled:!0,events:!0,lifecycle:!0,verbose:!0};let t=e.events??!0,n=e.lifecycle??!0,r=e.verbose??!1;return{enabled:t||n,events:t,lifecycle:n,verbose:r}}function _n(e){if(e instanceof $u)return e;if(e===!0)return new $u(Va(!0))}var $u=class{constructor(e){this.config=e}event(e,t,n,r){this.config.events&&(this.config.verbose?console.debug(`[${e}] ${t}`,typeof n=="string"?n:JSON.stringify(n)):console.debug(`[${e}] ${t}`,r??n))}lifecycle(e,t,n){this.config.lifecycle&&(n?console.debug(`[${e}] ${t}`,n):console.debug(`[${e}] ${t}`))}get eventsEnabled(){return this.config.events}get lifecycleEnabled(){return this.config.lifecycle}get enabled(){return this.config.enabled}};function ku(e){return e.enabled?new $u(e):void 0}function K0(e,t,n){if(t){let o=e.find(a=>a.id===t);if(o?.role==="assistant")return o;o&&console.warn(`TOOL_CALL_START: parentMessageId '${t}' matches a '${o.role}' message, not assistant \u2014 falling back to toolCallId`);let i={id:o?n:t,role:"assistant",toolCalls:[]};return e.push(i),i}let r={id:n,role:"assistant",toolCalls:[]};return e.push(r),r}function Je(e,t){return!e||t.metadata===void 0?!1:(e.metadata=Zp(e.metadata,ne(t.metadata)),!0)}var hb=(e,t,n,r,o)=>{let i=_n(o),a=ne(n.messages),s=ne(e.state),l={},c=[],u=new Set,f=h=>{let E=h.outcome?.type==="success"?h.outcome.pendingToolCallIds:void 0;return E!==void 0&&E.length>0?[...E]:c.filter(g=>!u.has(g))},m=h=>{h.messages!==void 0&&(a=h.messages,l.messages=h.messages),h.state!==void 0&&(s=h.state,l.state=h.state)},p=()=>{let h=ne(l);return l={},h.messages!==void 0||h.state!==void 0?ce(h):ln};return t.pipe(Ti(async h=>{let E=await ie(r,a,s,(g,_,b)=>g.onEvent?.({event:h,agent:n,input:e,messages:_,state:b}));if(m(E),E.stopPropagation===!0?i?.event("APPLY","Event dropped:",h,{type:h.type,reason:"stopPropagation by subscriber"}):i?.event("APPLY","Event applied:",h,{type:h.type,subscribers:r.length}),E.stopPropagation===!0)return p();switch(h.type){case v.TEXT_MESSAGE_START:{let g=await ie(r,a,s,(_,b,k)=>_.onTextMessageStartEvent?.({event:h,messages:b,state:k,agent:n,input:e}));if(m(g),g.stopPropagation!==!0){let{messageId:_,role:b="assistant",name:k,subagentRunId:O}=h,w=a.find(I=>I.id===_);if(w?.role==="activity")return console.warn(`TEXT_MESSAGE_START: Message '${_}' is an activity message \u2014 message ids must be unique across activity and text messages`),p();let S=w;if(!S){let I={id:_,role:b,content:"",...k!==void 0&&{name:k},...O!=null&&{subagentRunId:O}};a.push(I),S=I}let x=Je(S,h);(!w||x)&&m({messages:a})}return p()}case v.TEXT_MESSAGE_CONTENT:{let{messageId:g,delta:_}=h,b=a.find(O=>O.id===g);if(!b)return console.warn(`TEXT_MESSAGE_CONTENT: No message found with ID '${g}'`),p();if(b.role==="activity")return console.warn(`TEXT_MESSAGE_CONTENT: Message '${g}' is an activity message \u2014 message ids must be unique across activity and text messages`),p();let k=await ie(r,a,s,(O,w,S)=>O.onTextMessageContentEvent?.({event:h,messages:w,state:S,agent:n,input:e,textMessageBuffer:typeof b.content=="string"?b.content:""}));return m(k),k.stopPropagation!==!0&&(b.content=`${typeof b.content=="string"?b.content:""}${_}`,Je(b,h),m({messages:a})),p()}case v.TEXT_MESSAGE_END:{let{messageId:g}=h,_=a.find(k=>k.id===g);if(!_)return console.warn(`TEXT_MESSAGE_END: No message found with ID '${g}'`),p();if(_.role==="activity")return console.warn(`TEXT_MESSAGE_END: Message '${g}' is an activity message \u2014 message ids must be unique across activity and text messages`),p();let b=await ie(r,a,s,(k,O,w)=>k.onTextMessageEndEvent?.({event:h,messages:O,state:w,agent:n,input:e,textMessageBuffer:typeof _.content=="string"?_.content:""}));return m(b),b.stopPropagation!==!0&&Je(_,h)&&m({messages:a}),await Promise.all(r.map(k=>{k.onNewMessage?.({message:_,messages:a,state:s,agent:n,input:e})})),p()}case v.TOOL_CALL_START:{let g=await ie(r,a,s,(_,b,k)=>_.onToolCallStartEvent?.({event:h,messages:b,state:k,agent:n,input:e}));if(m(g),g.stopPropagation!==!0){let{toolCallId:_,toolCallName:b,parentMessageId:k,subagentRunId:O}=h;c.includes(_)||c.push(_);let w=a.find(z=>z.toolCalls?.some(Y=>Y.id===_))?.toolCalls?.find(z=>z.id===_);if(w){let z=w.function.name!==b;return z&&(console.warn(`TOOL_CALL_START: tool call '${_}' already exists with name '${w.function.name}' \u2014 updating it to '${b}'`),w.function.name=b),(Je(w,h)||z)&&m({messages:a}),p()}let S=new Set(a.map(z=>z.id)),x=K0(a,k,_);!S.has(x.id)&&O!=null&&x.subagentRunId===void 0&&(x.subagentRunId=O),x.toolCalls??=[];let I={id:_,type:"function",function:{name:b,arguments:""}};x.toolCalls.push(I),Je(I,h),m({messages:a})}return p()}case v.TOOL_CALL_ARGS:{let{toolCallId:g,delta:_}=h,b=a.find(w=>w.toolCalls?.some(S=>S.id===g));if(!b)return console.warn(`TOOL_CALL_ARGS: No message found containing tool call with ID '${g}'`),p();let k=b.toolCalls?.find(w=>w.id===g);if(!k)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${g}'`),p();let O=await ie(r,a,s,(w,S,x)=>{let I=k.function.arguments,z=k.function.name,Y={};try{Y=Ii(I)}catch{}return w.onToolCallArgsEvent?.({event:h,messages:S,state:x,agent:n,input:e,toolCallBuffer:I,toolCallName:z,partialToolCallArgs:Y})});return m(O),O.stopPropagation!==!0&&(k.function.arguments+=_,Je(k,h),m({messages:a})),p()}case v.TOOL_CALL_END:{let{toolCallId:g}=h,_=a.find(O=>O.toolCalls?.some(w=>w.id===g));if(!_)return console.warn(`TOOL_CALL_END: No message found containing tool call with ID '${g}'`),p();let b=_.toolCalls?.find(O=>O.id===g);if(!b)return console.warn(`TOOL_CALL_END: No tool call found with ID '${g}'`),p();let k=await ie(r,a,s,(O,w,S)=>{let x=b.function.arguments,I=b.function.name,z={};try{z=JSON.parse(x)}catch{}return O.onToolCallEndEvent?.({event:h,messages:w,state:S,agent:n,input:e,toolCallName:I,toolCallArgs:z})});return m(k),k.stopPropagation!==!0&&Je(b,h)&&m({messages:a}),await Promise.all(r.map(O=>{O.onNewToolCall?.({toolCall:b,messages:a,state:s,agent:n,input:e})})),p()}case v.TOOL_CALL_RESULT:{let g=await ie(r,a,s,(_,b,k)=>_.onToolCallResultEvent?.({event:h,messages:b,state:k,agent:n,input:e}));if(m(g),g.stopPropagation!==!0){let{messageId:_,toolCallId:b,content:k,role:O,subagentRunId:w}=h;u.add(b);let S=a.findIndex(I=>I.id===_&&I.role==="tool"&&I.toolCallId===b),x={...S===-1?{}:a[S],id:_,toolCallId:b,role:O||"tool",content:k,...w!=null&&{subagentRunId:w}};if(w??delete x.subagentRunId,Je(x,h),S!==-1)a[S]=x;else{let I=a.findIndex(z=>z.role==="assistant"&&z.toolCalls?.some(Y=>Y.id===b));if(I===-1)a.push(x);else{let z=I+1;for(;z<a.length&&a[z].role==="tool";)z++;a.splice(z,0,x)}await Promise.all(r.map(z=>{z.onNewMessage?.({message:x,messages:a,state:s,agent:n,input:e})}))}m({messages:a})}return p()}case v.STATE_SNAPSHOT:{let g=await ie(r,a,s,(_,b,k)=>_.onStateSnapshotEvent?.({event:h,messages:b,state:k,agent:n,input:e}));if(m(g),g.stopPropagation!==!0){let{snapshot:_}=h;s=_,m({state:s})}return p()}case v.STATE_DELTA:{let g=await ie(r,a,s,(_,b,k)=>_.onStateDeltaEvent?.({event:h,messages:b,state:k,agent:n,input:e}));if(m(g),g.stopPropagation!==!0){let{delta:_}=h;try{s=ni.applyPatch(s,_,!0,!1).newDocument,m({state:s})}catch(b){let k=b instanceof Error?b.message:String(b);console.warn(`Failed to apply state patch:
|
|
29
|
+
path: iss.path ? [${mn(b)}, ...iss.path] : [${mn(b)}]
|
|
30
|
+
})));`),m.write(`newResult[${mn(b)}] = ${k}.value`)}m.write("payload.value = newResult;"),m.write("return payload;");let w=m.compile();return(b,k)=>w(f,b,k)},o,i=tr,a=!Pi.jitless,c=a&&kc.value,l=e.catchall,u;t._zod.parse=(f,m)=>{u??(u=n.value);let p=f.value;if(!i(p))return f.issues.push({expected:"object",code:"invalid_type",input:p,inst:t}),f;let h=[];if(a&&c&&m?.async===!1&&m.jitless!==!0)o||(o=r(e.shape)),f=o(f,m);else{f.value={};let k=u.shape;for(let O of u.keys){let E=k[O],S=E._zod.run({value:p[O],issues:[]},m),_=E._zod.optin==="optional"&&E._zod.optout==="optional";S instanceof Promise?h.push(S.then(I=>_?kf(I,f,O,p):Hi(I,f,O))):_?kf(S,f,O,p):Hi(S,f,O)}}if(!l)return h.length?Promise.all(h).then(()=>f):f;let x=[],g=u.keySet,w=l._zod,b=w.def.type;for(let k of Object.keys(p)){if(g.has(k))continue;if(b==="never"){x.push(k);continue}let O=w.run({value:p[k],issues:[]},m);O instanceof Promise?h.push(O.then(E=>Hi(E,f,k))):Hi(O,f,k)}return x.length&&f.issues.push({code:"unrecognized_keys",keys:x,input:p,inst:t}),h.length?Promise.all(h).then(()=>f):f}});function If(t,e,n,r){for(let o of t)if(o.issues.length===0)return e.value=o.value,e;return e.issues.push({code:"invalid_union",input:e.value,inst:n,errors:t.map(o=>o.issues.map(i=>dt(i,r,Ue())))}),e}var Bc=A("$ZodUnion",(t,e)=>{de.init(t,e),le(t._zod,"optin",()=>e.options.some(n=>n._zod.optin==="optional")?"optional":void 0),le(t._zod,"optout",()=>e.options.some(n=>n._zod.optout==="optional")?"optional":void 0),le(t._zod,"values",()=>{if(e.options.every(n=>n._zod.values))return new Set(e.options.flatMap(n=>Array.from(n._zod.values)))}),le(t._zod,"pattern",()=>{if(e.options.every(n=>n._zod.pattern)){let n=e.options.map(r=>r._zod.pattern);return new RegExp(`^(${n.map(r=>Br(r.source)).join("|")})$`)}}),t._zod.parse=(n,r)=>{let o=!1,i=[];for(let a of e.options){let s=a._zod.run({value:n.value,issues:[]},r);if(s instanceof Promise)i.push(s),o=!0;else{if(s.issues.length===0)return s;i.push(s)}}return o?Promise.all(i).then(a=>If(a,n,t,r)):If(i,n,t,r)}}),pm=A("$ZodDiscriminatedUnion",(t,e)=>{Bc.init(t,e);let n=t._zod.parse;le(t._zod,"propValues",()=>{let o={};for(let i of e.options){let a=i._zod.propValues;if(!a||Object.keys(a).length===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(i)}"`);for(let[s,c]of Object.entries(a)){o[s]||(o[s]=new Set);for(let l of c)o[s].add(l)}}return o});let r=Fr(()=>{let o=e.options,i=new Map;for(let a of o){let s=a._zod.propValues[e.discriminator];if(!s||s.size===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(a)}"`);for(let c of s){if(i.has(c))throw new Error(`Duplicate discriminator value "${String(c)}"`);i.set(c,a)}}return i});t._zod.parse=(o,i)=>{let a=o.value;if(!tr(a))return o.issues.push({code:"invalid_type",expected:"object",input:a,inst:t}),o;let s=r.value.get(a?.[e.discriminator]);return s?s._zod.run(o,i):e.unionFallback?n(o,i):(o.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",input:a,path:[e.discriminator],inst:t}),o)}}),hm=A("$ZodIntersection",(t,e)=>{de.init(t,e),t._zod.parse=(n,r)=>{let o=n.value,i=e.left._zod.run({value:o,issues:[]},r),a=e.right._zod.run({value:o,issues:[]},r);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([c,l])=>Rf(n,c,l)):Rf(n,i,a)}});function Fc(t,e){if(t===e)return{valid:!0,data:t};if(t instanceof Date&&e instanceof Date&&+t==+e)return{valid:!0,data:t};if(nr(t)&&nr(e)){let n=Object.keys(e),r=Object.keys(t).filter(i=>n.indexOf(i)!==-1),o={...t,...e};for(let i of r){let a=Fc(t[i],e[i]);if(!a.valid)return{valid:!1,mergeErrorPath:[i,...a.mergeErrorPath]};o[i]=a.data}return{valid:!0,data:o}}if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<t.length;r++){let o=t[r],i=e[r],a=Fc(o,i);if(!a.valid)return{valid:!1,mergeErrorPath:[r,...a.mergeErrorPath]};n.push(a.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Rf(t,e,n){if(e.issues.length&&t.issues.push(...e.issues),n.issues.length&&t.issues.push(...n.issues),gn(t))return t;let r=Fc(e.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return t.value=r.data,t}var fm=A("$ZodRecord",(t,e)=>{de.init(t,e),t._zod.parse=(n,r)=>{let o=n.value;if(!nr(o))return n.issues.push({expected:"record",code:"invalid_type",input:o,inst:t}),n;let i=[];if(e.keyType._zod.values){let a=e.keyType._zod.values;n.value={};for(let c of a)if(typeof c=="string"||typeof c=="number"||typeof c=="symbol"){let l=e.valueType._zod.run({value:o[c],issues:[]},r);l instanceof Promise?i.push(l.then(u=>{u.issues.length&&n.issues.push(...At(c,u.issues)),n.value[c]=u.value})):(l.issues.length&&n.issues.push(...At(c,l.issues)),n.value[c]=l.value)}let s;for(let c in o)a.has(c)||(s=s??[],s.push(c));s&&s.length>0&&n.issues.push({code:"unrecognized_keys",input:o,inst:t,keys:s})}else{n.value={};for(let a of Reflect.ownKeys(o)){if(a==="__proto__")continue;let s=e.keyType._zod.run({value:a,issues:[]},r);if(s instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(s.issues.length){n.issues.push({origin:"record",code:"invalid_key",issues:s.issues.map(l=>dt(l,r,Ue())),input:a,path:[a],inst:t}),n.value[s.value]=s.value;continue}let c=e.valueType._zod.run({value:o[a],issues:[]},r);c instanceof Promise?i.push(c.then(l=>{l.issues.length&&n.issues.push(...At(a,l.issues)),n.value[s.value]=l.value})):(c.issues.length&&n.issues.push(...At(a,c.issues)),n.value[s.value]=c.value)}}return i.length?Promise.all(i).then(()=>n):n}});var mm=A("$ZodEnum",(t,e)=>{de.init(t,e);let n=_c(e.entries);t._zod.values=new Set(n),t._zod.pattern=new RegExp(`^(${n.filter(r=>Ic.has(typeof r)).map(r=>typeof r=="string"?Gt(r):r.toString()).join("|")})$`),t._zod.parse=(r,o)=>{let i=r.value;return t._zod.values.has(i)||r.issues.push({code:"invalid_value",values:n,input:i,inst:t}),r}}),gm=A("$ZodLiteral",(t,e)=>{de.init(t,e),t._zod.values=new Set(e.values),t._zod.pattern=new RegExp(`^(${e.values.map(n=>typeof n=="string"?Gt(n):n?n.toString():String(n)).join("|")})$`),t._zod.parse=(n,r)=>{let o=n.value;return t._zod.values.has(o)||n.issues.push({code:"invalid_value",values:e.values,input:o,inst:t}),n}});var vm=A("$ZodTransform",(t,e)=>{de.init(t,e),t._zod.parse=(n,r)=>{let o=e.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(a=>(n.value=a,n));if(o instanceof Promise)throw new Mt;return n.value=o,n}}),bm=A("$ZodOptional",(t,e)=>{de.init(t,e),t._zod.optin="optional",t._zod.optout="optional",le(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,void 0]):void 0),le(t._zod,"pattern",()=>{let n=e.innerType._zod.pattern;return n?new RegExp(`^(${Br(n.source)})?$`):void 0}),t._zod.parse=(n,r)=>e.innerType._zod.optin==="optional"?e.innerType._zod.run(n,r):n.value===void 0?n:e.innerType._zod.run(n,r)}),ym=A("$ZodNullable",(t,e)=>{de.init(t,e),le(t._zod,"optin",()=>e.innerType._zod.optin),le(t._zod,"optout",()=>e.innerType._zod.optout),le(t._zod,"pattern",()=>{let n=e.innerType._zod.pattern;return n?new RegExp(`^(${Br(n.source)}|null)$`):void 0}),le(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,null]):void 0),t._zod.parse=(n,r)=>n.value===null?n:e.innerType._zod.run(n,r)}),wm=A("$ZodDefault",(t,e)=>{de.init(t,e),t._zod.optin="optional",le(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{if(n.value===void 0)return n.value=e.defaultValue,n;let o=e.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>Cf(i,e)):Cf(o,e)}});function Cf(t,e){return t.value===void 0&&(t.value=e.defaultValue),t}var Em=A("$ZodPrefault",(t,e)=>{de.init(t,e),t._zod.optin="optional",le(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>(n.value===void 0&&(n.value=e.defaultValue),e.innerType._zod.run(n,r))}),xm=A("$ZodNonOptional",(t,e)=>{de.init(t,e),le(t._zod,"values",()=>{let n=e.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),t._zod.parse=(n,r)=>{let o=e.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>Nf(i,t)):Nf(o,t)}});function Nf(t,e){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:e}),t}var _m=A("$ZodCatch",(t,e)=>{de.init(t,e),t._zod.optin="optional",le(t._zod,"optout",()=>e.innerType._zod.optout),le(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{let o=e.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>(n.value=i.value,i.issues.length&&(n.value=e.catchValue({...n,error:{issues:i.issues.map(a=>dt(a,r,Ue()))},input:n.value}),n.issues=[]),n)):(n.value=o.value,o.issues.length&&(n.value=e.catchValue({...n,error:{issues:o.issues.map(i=>dt(i,r,Ue()))},input:n.value}),n.issues=[]),n)}});var Sm=A("$ZodPipe",(t,e)=>{de.init(t,e),le(t._zod,"values",()=>e.in._zod.values),le(t._zod,"optin",()=>e.in._zod.optin),le(t._zod,"optout",()=>e.out._zod.optout),t._zod.parse=(n,r)=>{let o=e.in._zod.run(n,r);return o instanceof Promise?o.then(i=>Of(i,e,r)):Of(o,e,r)}});function Of(t,e,n){return gn(t)?t:e.out._zod.run({value:t.value,issues:t.issues},n)}var Tm=A("$ZodReadonly",(t,e)=>{de.init(t,e),le(t._zod,"propValues",()=>e.innerType._zod.propValues),le(t._zod,"values",()=>e.innerType._zod.values),le(t._zod,"optin",()=>e.innerType._zod.optin),le(t._zod,"optout",()=>e.innerType._zod.optout),t._zod.parse=(n,r)=>{let o=e.innerType._zod.run(n,r);return o instanceof Promise?o.then(Pf):Pf(o)}});function Pf(t){return t.value=Object.freeze(t.value),t}var Am=A("$ZodLazy",(t,e)=>{de.init(t,e),le(t._zod,"innerType",()=>e.getter()),le(t._zod,"pattern",()=>t._zod.innerType._zod.pattern),le(t._zod,"propValues",()=>t._zod.innerType._zod.propValues),le(t._zod,"optin",()=>t._zod.innerType._zod.optin),le(t._zod,"optout",()=>t._zod.innerType._zod.optout),t._zod.parse=(n,r)=>t._zod.innerType._zod.run(n,r)}),km=A("$ZodCustom",(t,e)=>{Be.init(t,e),de.init(t,e),t._zod.parse=(n,r)=>n,t._zod.check=n=>{let r=n.value,o=e.fn(r);if(o instanceof Promise)return o.then(i=>Mf(i,n,r,t));Mf(o,n,r,t)}});function Mf(t,e,n,r){if(!t){let o={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),e.issues.push(Nc(o))}}var m_=t=>{let e=typeof t;switch(e){case"number":return Number.isNaN(t)?"NaN":"number";case"object":{if(Array.isArray(t))return"array";if(t===null)return"null";if(Object.getPrototypeOf(t)!==Object.prototype&&t.constructor)return t.constructor.name}}return e},g_=()=>{let t={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"}};function e(r){return t[r]??null}let n={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",jwt:"JWT",template_literal:"input"};return r=>{switch(r.code){case"invalid_type":return`Invalid input: expected ${r.expected}, received ${m_(r.input)}`;case"invalid_value":return r.values.length===1?`Invalid input: expected ${zi(r.values[0])}`:`Invalid option: expected one of ${Mi(r.values,"|")}`;case"too_big":{let o=r.inclusive?"<=":"<",i=e(r.origin);return i?`Too big: expected ${r.origin??"value"} to have ${o}${r.maximum.toString()} ${i.unit??"elements"}`:`Too big: expected ${r.origin??"value"} to be ${o}${r.maximum.toString()}`}case"too_small":{let o=r.inclusive?">=":">",i=e(r.origin);return i?`Too small: expected ${r.origin} to have ${o}${r.minimum.toString()} ${i.unit}`:`Too small: expected ${r.origin} to be ${o}${r.minimum.toString()}`}case"invalid_format":{let o=r;return o.format==="starts_with"?`Invalid string: must start with "${o.prefix}"`:o.format==="ends_with"?`Invalid string: must end with "${o.suffix}"`:o.format==="includes"?`Invalid string: must include "${o.includes}"`:o.format==="regex"?`Invalid string: must match pattern ${o.pattern}`:`Invalid ${n[o.format]??r.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${r.divisor}`;case"unrecognized_keys":return`Unrecognized key${r.keys.length>1?"s":""}: ${Mi(r.keys,", ")}`;case"invalid_key":return`Invalid key in ${r.origin}`;case"invalid_union":return"Invalid input";case"invalid_element":return`Invalid value in ${r.origin}`;default:return"Invalid input"}}};function rr(){return{localeError:g_()}}var Zc=class{constructor(){this._map=new Map,this._idmap=new Map}add(e,...n){let r=n[0];if(this._map.set(e,r),r&&typeof r=="object"&&"id"in r){if(this._idmap.has(r.id))throw new Error(`ID ${r.id} already exists in the registry`);this._idmap.set(r.id,e)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(e){let n=this._map.get(e);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(e),this}get(e){let n=e._zod.parent;if(n){let r={...this.get(n)??{}};return delete r.id,{...r,...this._map.get(e)}}return this._map.get(e)}has(e){return this._map.has(e)}};function Im(){return new Zc}var or=Im();function Rm(t,e){return new t({type:"string",...G(e)})}function Cm(t,e){return new t({type:"string",format:"email",check:"string_format",abort:!1,...G(e)})}function Vc(t,e){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...G(e)})}function Nm(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...G(e)})}function Om(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...G(e)})}function Pm(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...G(e)})}function Mm(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...G(e)})}function Lm(t,e){return new t({type:"string",format:"url",check:"string_format",abort:!1,...G(e)})}function zm(t,e){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...G(e)})}function Dm(t,e){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...G(e)})}function $m(t,e){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...G(e)})}function Um(t,e){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...G(e)})}function Hm(t,e){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...G(e)})}function Fm(t,e){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...G(e)})}function Gm(t,e){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...G(e)})}function Bm(t,e){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...G(e)})}function Zm(t,e){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...G(e)})}function Vm(t,e){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...G(e)})}function jm(t,e){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...G(e)})}function Wm(t,e){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...G(e)})}function qm(t,e){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...G(e)})}function Ym(t,e){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...G(e)})}function Km(t,e){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...G(e)})}function Xm(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...G(e)})}function Jm(t,e){return new t({type:"string",format:"date",check:"string_format",...G(e)})}function Qm(t,e){return new t({type:"string",format:"time",check:"string_format",precision:null,...G(e)})}function eg(t,e){return new t({type:"string",format:"duration",check:"string_format",...G(e)})}function tg(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...G(e)})}function ng(t,e){return new t({type:"boolean",...G(e)})}function rg(t){return new t({type:"any"})}function og(t){return new t({type:"unknown"})}function ig(t,e){return new t({type:"never",...G(e)})}function Gi(t,e){return new Uc({check:"less_than",...G(e),value:t,inclusive:!1})}function jr(t,e){return new Uc({check:"less_than",...G(e),value:t,inclusive:!0})}function Bi(t,e){return new Hc({check:"greater_than",...G(e),value:t,inclusive:!1})}function Wr(t,e){return new Hc({check:"greater_than",...G(e),value:t,inclusive:!0})}function Zi(t,e){return new pf({check:"multiple_of",...G(e),value:t})}function Vi(t,e){return new ff({check:"max_length",...G(e),maximum:t})}function ir(t,e){return new mf({check:"min_length",...G(e),minimum:t})}function ji(t,e){return new gf({check:"length_equals",...G(e),length:t})}function jc(t,e){return new vf({check:"string_format",format:"regex",...G(e),pattern:t})}function Wc(t){return new bf({check:"string_format",format:"lowercase",...G(t)})}function qc(t){return new yf({check:"string_format",format:"uppercase",...G(t)})}function Yc(t,e){return new wf({check:"string_format",format:"includes",...G(e),includes:t})}function Kc(t,e){return new Ef({check:"string_format",format:"starts_with",...G(e),prefix:t})}function Xc(t,e){return new xf({check:"string_format",format:"ends_with",...G(e),suffix:t})}function vn(t){return new _f({check:"overwrite",tx:t})}function Jc(t){return vn(e=>e.normalize(t))}function Qc(){return vn(t=>t.trim())}function eu(){return vn(t=>t.toLowerCase())}function tu(){return vn(t=>t.toUpperCase())}function ag(t,e,n){return new t({type:"array",element:e,...G(n)})}function sg(t,e,n){let r=G(n);return r.abort??(r.abort=!0),new t({type:"custom",check:"custom",fn:e,...r})}function lg(t,e,n){return new t({type:"custom",check:"custom",fn:e,...G(n)})}var __=A("ZodISODateTime",(t,e)=>{jf.init(t,e),xe.init(t,e)});function cg(t){return Xm(__,t)}var S_=A("ZodISODate",(t,e)=>{Wf.init(t,e),xe.init(t,e)});function ug(t){return Jm(S_,t)}var T_=A("ZodISOTime",(t,e)=>{qf.init(t,e),xe.init(t,e)});function dg(t){return Qm(T_,t)}var A_=A("ZodISODuration",(t,e)=>{Yf.init(t,e),xe.init(t,e)});function pg(t){return eg(A_,t)}var fg=(t,e)=>{Di.init(t,e),t.name="ZodError",Object.defineProperties(t,{format:{value:n=>Mc(t,n)},flatten:{value:n=>Pc(t,n)},addIssue:{value:n=>t.issues.push(n)},addIssues:{value:n=>t.issues.push(...n)},isEmpty:{get(){return t.issues.length===0}}})},FM=A("ZodError",fg),Yr=A("ZodError",fg,{Parent:Error});var mg=Oh(Yr),gg=Ph(Yr),vg=Lc(Yr),bg=zc(Yr);var _e=A("ZodType",(t,e)=>(de.init(t,e),t.def=e,Object.defineProperty(t,"_def",{value:e}),t.check=(...n)=>t.clone({...e,checks:[...e.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),t.clone=(n,r)=>ut(t,n,r),t.brand=()=>t,t.register=((n,r)=>(n.add(t,r),t)),t.parse=(n,r)=>mg(t,n,r,{callee:t.parse}),t.safeParse=(n,r)=>vg(t,n,r),t.parseAsync=async(n,r)=>gg(t,n,r,{callee:t.parseAsync}),t.safeParseAsync=async(n,r)=>bg(t,n,r),t.spa=t.safeParseAsync,t.refine=(n,r)=>t.check(pS(n,r)),t.superRefine=n=>t.check(hS(n)),t.overwrite=n=>t.check(vn(n)),t.optional=()=>wg(t),t.nullable=()=>Eg(t),t.nullish=()=>wg(Eg(t)),t.nonoptional=n=>lS(t,n),t.array=()=>Re(t),t.or=n=>Kr([t,n]),t.and=n=>nS(t,n),t.transform=n=>xg(t,oS(n)),t.default=n=>iS(t,n),t.prefault=n=>sS(t,n),t.catch=n=>cS(t,n),t.pipe=n=>xg(t,n),t.readonly=()=>uS(t),t.describe=n=>{let r=t.clone();return or.add(r,{description:n}),r},Object.defineProperty(t,"description",{get(){return or.get(t)?.description},configurable:!0}),t.meta=(...n)=>{if(n.length===0)return or.get(t);let r=t.clone();return or.add(r,n[0]),r},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t)),_g=A("_ZodString",(t,e)=>{Fi.init(t,e),_e.init(t,e);let n=t._zod.bag;t.format=n.format??null,t.minLength=n.minimum??null,t.maxLength=n.maximum??null,t.regex=(...r)=>t.check(jc(...r)),t.includes=(...r)=>t.check(Yc(...r)),t.startsWith=(...r)=>t.check(Kc(...r)),t.endsWith=(...r)=>t.check(Xc(...r)),t.min=(...r)=>t.check(ir(...r)),t.max=(...r)=>t.check(Vi(...r)),t.length=(...r)=>t.check(ji(...r)),t.nonempty=(...r)=>t.check(ir(1,...r)),t.lowercase=r=>t.check(Wc(r)),t.uppercase=r=>t.check(qc(r)),t.trim=()=>t.check(Qc()),t.normalize=(...r)=>t.check(Jc(...r)),t.toLowerCase=()=>t.check(eu()),t.toUpperCase=()=>t.check(tu())}),R_=A("ZodString",(t,e)=>{Fi.init(t,e),_g.init(t,e),t.email=n=>t.check(Cm(C_,n)),t.url=n=>t.check(Lm(N_,n)),t.jwt=n=>t.check(Km(j_,n)),t.emoji=n=>t.check(zm(O_,n)),t.guid=n=>t.check(Vc(yg,n)),t.uuid=n=>t.check(Nm(Wi,n)),t.uuidv4=n=>t.check(Om(Wi,n)),t.uuidv6=n=>t.check(Pm(Wi,n)),t.uuidv7=n=>t.check(Mm(Wi,n)),t.nanoid=n=>t.check(Dm(P_,n)),t.guid=n=>t.check(Vc(yg,n)),t.cuid=n=>t.check($m(M_,n)),t.cuid2=n=>t.check(Um(L_,n)),t.ulid=n=>t.check(Hm(z_,n)),t.base64=n=>t.check(Wm(B_,n)),t.base64url=n=>t.check(qm(Z_,n)),t.xid=n=>t.check(Fm(D_,n)),t.ksuid=n=>t.check(Gm($_,n)),t.ipv4=n=>t.check(Bm(U_,n)),t.ipv6=n=>t.check(Zm(H_,n)),t.cidrv4=n=>t.check(Vm(F_,n)),t.cidrv6=n=>t.check(jm(G_,n)),t.e164=n=>t.check(Ym(V_,n)),t.datetime=n=>t.check(cg(n)),t.date=n=>t.check(ug(n)),t.time=n=>t.check(dg(n)),t.duration=n=>t.check(pg(n))});function T(t){return Rm(R_,t)}var xe=A("ZodStringFormat",(t,e)=>{be.init(t,e),_g.init(t,e)}),C_=A("ZodEmail",(t,e)=>{Df.init(t,e),xe.init(t,e)});var yg=A("ZodGUID",(t,e)=>{Lf.init(t,e),xe.init(t,e)});var Wi=A("ZodUUID",(t,e)=>{zf.init(t,e),xe.init(t,e)});var N_=A("ZodURL",(t,e)=>{$f.init(t,e),xe.init(t,e)});var O_=A("ZodEmoji",(t,e)=>{Uf.init(t,e),xe.init(t,e)});var P_=A("ZodNanoID",(t,e)=>{Hf.init(t,e),xe.init(t,e)});var M_=A("ZodCUID",(t,e)=>{Ff.init(t,e),xe.init(t,e)});var L_=A("ZodCUID2",(t,e)=>{Gf.init(t,e),xe.init(t,e)});var z_=A("ZodULID",(t,e)=>{Bf.init(t,e),xe.init(t,e)});var D_=A("ZodXID",(t,e)=>{Zf.init(t,e),xe.init(t,e)});var $_=A("ZodKSUID",(t,e)=>{Vf.init(t,e),xe.init(t,e)});var U_=A("ZodIPv4",(t,e)=>{Kf.init(t,e),xe.init(t,e)});var H_=A("ZodIPv6",(t,e)=>{Xf.init(t,e),xe.init(t,e)});var F_=A("ZodCIDRv4",(t,e)=>{Jf.init(t,e),xe.init(t,e)});var G_=A("ZodCIDRv6",(t,e)=>{Qf.init(t,e),xe.init(t,e)});var B_=A("ZodBase64",(t,e)=>{tm.init(t,e),xe.init(t,e)});var Z_=A("ZodBase64URL",(t,e)=>{nm.init(t,e),xe.init(t,e)});var V_=A("ZodE164",(t,e)=>{rm.init(t,e),xe.init(t,e)});var j_=A("ZodJWT",(t,e)=>{om.init(t,e),xe.init(t,e)});var W_=A("ZodNumber",(t,e)=>{Gc.init(t,e),_e.init(t,e),t.gt=(r,o)=>t.check(Bi(r,o)),t.gte=(r,o)=>t.check(Wr(r,o)),t.min=(r,o)=>t.check(Wr(r,o)),t.lt=(r,o)=>t.check(Gi(r,o)),t.lte=(r,o)=>t.check(jr(r,o)),t.max=(r,o)=>t.check(jr(r,o)),t.int=r=>t.check(W(r)),t.safe=r=>t.check(W(r)),t.positive=r=>t.check(Bi(0,r)),t.nonnegative=r=>t.check(Wr(0,r)),t.negative=r=>t.check(Gi(0,r)),t.nonpositive=r=>t.check(jr(0,r)),t.multipleOf=(r,o)=>t.check(Zi(r,o)),t.step=(r,o)=>t.check(Zi(r,o)),t.finite=()=>t;let n=t._zod.bag;t.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),t.isFinite=!0,t.format=n.format??null});var q_=A("ZodNumberFormat",(t,e)=>{im.init(t,e),W_.init(t,e)});function W(t){return tg(q_,t)}var Y_=A("ZodBoolean",(t,e)=>{am.init(t,e),_e.init(t,e)});function te(t){return ng(Y_,t)}var K_=A("ZodAny",(t,e)=>{sm.init(t,e),_e.init(t,e)});function B(){return rg(K_)}var X_=A("ZodUnknown",(t,e)=>{lm.init(t,e),_e.init(t,e)});function nu(){return og(X_)}var J_=A("ZodNever",(t,e)=>{cm.init(t,e),_e.init(t,e)});function Q_(t){return ig(J_,t)}var qi=A("ZodArray",(t,e)=>{um.init(t,e),_e.init(t,e),t.element=e.element,t.min=(n,r)=>t.check(ir(n,r)),t.nonempty=n=>t.check(ir(1,n)),t.max=(n,r)=>t.check(Vi(n,r)),t.length=(n,r)=>t.check(ji(n,r)),t.unwrap=()=>t.element});function Re(t,e){return ag(qi,t,e)}var ar=A("ZodObject",(t,e)=>{dm.init(t,e),_e.init(t,e),ce.defineLazy(t,"shape",()=>e.shape),t.keyof=()=>bn(Object.keys(t._zod.def.shape)),t.catchall=n=>t.clone({...t._zod.def,catchall:n}),t.passthrough=()=>t.clone({...t._zod.def,catchall:nu()}),t.loose=()=>t.clone({...t._zod.def,catchall:nu()}),t.strict=()=>t.clone({...t._zod.def,catchall:Q_()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=n=>ce.extend(t,n),t.merge=n=>ce.merge(t,n),t.pick=n=>ce.pick(t,n),t.omit=n=>ce.omit(t,n),t.partial=(...n)=>ce.partial(Ki,t,n[0]),t.required=(...n)=>ce.required(Tg,t,n[0])});function z(t,e){return new ar({type:"object",get shape(){return ce.assignProp(this,"shape",{...t}),this.shape},catchall:nu(),...ce.normalizeParams(e)})}var Yi=A("ZodUnion",(t,e)=>{Bc.init(t,e),_e.init(t,e),t.options=e.options});function Kr(t,e){return new Yi({type:"union",options:t,...ce.normalizeParams(e)})}var eS=A("ZodDiscriminatedUnion",(t,e)=>{Yi.init(t,e),pm.init(t,e)});function Bt(t,e,n){return new eS({type:"union",options:e,discriminator:t,...ce.normalizeParams(n)})}var tS=A("ZodIntersection",(t,e)=>{hm.init(t,e),_e.init(t,e)});function nS(t,e){return new tS({type:"intersection",left:t,right:e})}var Sg=A("ZodRecord",(t,e)=>{fm.init(t,e),_e.init(t,e),t.keyType=e.keyType,t.valueType=e.valueType});var ru=A("ZodEnum",(t,e)=>{mm.init(t,e),_e.init(t,e),t.enum=e.entries,t.options=Object.values(e.entries);let n=new Set(Object.keys(e.entries));t.extract=(r,o)=>{let i={};for(let a of r)if(n.has(a))i[a]=e.entries[a];else throw new Error(`Key ${a} not found in enum`);return new ru({...e,checks:[],...ce.normalizeParams(o),entries:i})},t.exclude=(r,o)=>{let i={...e.entries};for(let a of r)if(n.has(a))delete i[a];else throw new Error(`Key ${a} not found in enum`);return new ru({...e,checks:[],...ce.normalizeParams(o),entries:i})}});function bn(t,e){let n=Array.isArray(t)?Object.fromEntries(t.map(r=>[r,r])):t;return new ru({type:"enum",entries:n,...ce.normalizeParams(e)})}var ou=A("ZodLiteral",(t,e)=>{gm.init(t,e),_e.init(t,e),t.values=new Set(e.values),Object.defineProperty(t,"value",{get(){if(e.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return e.values[0]}})});function $(t,e){return new ou({type:"literal",values:Array.isArray(t)?t:[t],...ce.normalizeParams(e)})}var rS=A("ZodTransform",(t,e)=>{vm.init(t,e),_e.init(t,e),t._zod.parse=(n,r)=>{n.addIssue=i=>{if(typeof i=="string")n.issues.push(ce.issue(i,n.value,e));else{let a=i;a.fatal&&(a.continue=!1),a.code??(a.code="custom"),a.input??(a.input=n.value),a.inst??(a.inst=t),a.continue??(a.continue=!0),n.issues.push(ce.issue(a))}};let o=e.transform(n.value,n);return o instanceof Promise?o.then(i=>(n.value=i,n)):(n.value=o,n)}});function oS(t){return new rS({type:"transform",transform:t})}var Ki=A("ZodOptional",(t,e)=>{bm.init(t,e),_e.init(t,e),t.unwrap=()=>t._zod.def.innerType});function wg(t){return new Ki({type:"optional",innerType:t})}var iu=A("ZodNullable",(t,e)=>{ym.init(t,e),_e.init(t,e),t.unwrap=()=>t._zod.def.innerType});function Eg(t){return new iu({type:"nullable",innerType:t})}var au=A("ZodDefault",(t,e)=>{wm.init(t,e),_e.init(t,e),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function iS(t,e){return new au({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():e}})}var aS=A("ZodPrefault",(t,e)=>{Em.init(t,e),_e.init(t,e),t.unwrap=()=>t._zod.def.innerType});function sS(t,e){return new aS({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():e}})}var Tg=A("ZodNonOptional",(t,e)=>{xm.init(t,e),_e.init(t,e),t.unwrap=()=>t._zod.def.innerType});function lS(t,e){return new Tg({type:"nonoptional",innerType:t,...ce.normalizeParams(e)})}var su=A("ZodCatch",(t,e)=>{_m.init(t,e),_e.init(t,e),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function cS(t,e){return new su({type:"catch",innerType:t,catchValue:typeof e=="function"?e:()=>e})}var lu=A("ZodPipe",(t,e)=>{Sm.init(t,e),_e.init(t,e),t.in=e.in,t.out=e.out});function xg(t,e){return new lu({type:"pipe",in:t,out:e})}var cu=A("ZodReadonly",(t,e)=>{Tm.init(t,e),_e.init(t,e)});function uS(t){return new cu({type:"readonly",innerType:t})}var Ag=A("ZodLazy",(t,e)=>{Am.init(t,e),_e.init(t,e),t.unwrap=()=>t._zod.def.getter()});var kg=A("ZodCustom",(t,e)=>{km.init(t,e),_e.init(t,e)});function dS(t){let e=new Be({check:"custom"});return e._zod.check=t,e}function sr(t,e){return sg(kg,t??(()=>!0),e)}function pS(t,e={}){return lg(kg,t,e)}function hS(t){let e=dS(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(ce.issue(r,n.value,e._zod.def));else{let o=r;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=e),o.continue??(o.continue=!e._zod.def.abort),n.issues.push(ce.issue(o))}},t(n.value,n)));return e}Ue(rr());var mS=bn(v),V=sr(t=>typeof t=="object"&&t!==null&&!Array.isArray(t)),ee=T(),Ig=bn(["developer","system","assistant","user"]),gS=z({type:$(v.TEXT_MESSAGE_START),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T(),role:Ig.optional(),name:T().optional()}),vS=z({type:$(v.TEXT_MESSAGE_CONTENT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T(),delta:T()}),bS=z({type:$(v.TEXT_MESSAGE_END),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T()}),uu=z({type:$(v.TEXT_MESSAGE_CHUNK),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T().optional(),role:Ig.optional(),delta:T().optional(),name:T().optional()}),yS=z({type:$(v.TOOL_CALL_START),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),toolCallId:T(),toolCallName:T(),parentMessageId:T().optional()}),wS=z({type:$(v.TOOL_CALL_ARGS),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),toolCallId:T(),delta:T()}),ES=z({type:$(v.TOOL_CALL_END),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),toolCallId:T()}),du=z({type:$(v.TOOL_CALL_CHUNK),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),toolCallId:T().optional(),toolCallName:T().optional(),parentMessageId:T().optional(),delta:T().optional()}),xS=z({type:$("text"),id:T().optional(),text:T(),metadata:B().refine(t=>t!==null).optional()}),_S=z({type:$("data"),value:T(),mimeType:T()}),SS=z({type:$("url"),value:T(),mimeType:T().optional()}),TS=z({type:$("file"),value:T(),provider:T().optional(),mimeType:T().optional()}),Xi=Bt("type",[_S,SS,TS]),AS=z({type:$("image"),id:T().optional(),source:Xi,metadata:B().refine(t=>t!==null).optional()}),kS=z({type:$("audio"),id:T().optional(),source:Xi,metadata:B().refine(t=>t!==null).optional()}),IS=z({type:$("video"),id:T().optional(),source:Xi,metadata:B().refine(t=>t!==null).optional()}),RS=z({type:$("document"),id:T().optional(),source:Xi,metadata:B().refine(t=>t!==null).optional()}),pu=Bt("type",[xS,AS,kS,IS,RS]),CS=z({type:$(v.TOOL_CALL_RESULT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T(),toolCallId:T(),content:Kr([T(),Re(pu)]),role:$("tool").optional()}),Rg=B(),NS=z({type:$(v.STATE_SNAPSHOT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),snapshot:Rg.refine(t=>t!==void 0)}),Zt=T().regex(new RegExp("^(/([^/~]|~[01])*)*$")),OS=z({op:$("add"),path:Zt,value:B().refine(t=>t!==void 0)}).meta({specOpen:!0}),PS=z({op:$("remove"),path:Zt}).meta({specOpen:!0}),MS=z({op:$("replace"),path:Zt,value:B().refine(t=>t!==void 0)}).meta({specOpen:!0}),LS=z({op:$("move"),from:Zt,path:Zt}).meta({specOpen:!0}),zS=z({op:$("copy"),from:Zt,path:Zt}).meta({specOpen:!0}),DS=z({op:$("test"),path:Zt,value:B().refine(t=>t!==void 0)}).meta({specOpen:!0}),$S=Bt("op",[OS,PS,MS,LS,zS,DS]),Cg=Re($S),US=z({type:$(v.STATE_DELTA),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),delta:Cg}),HS=z({subagentRunId:ee.optional(),id:T(),role:$("developer"),name:T().optional(),encryptedValue:T().optional(),metadata:V.optional(),content:T()}),FS=z({subagentRunId:ee.optional(),id:T(),role:$("system"),name:T().optional(),encryptedValue:T().optional(),metadata:V.optional(),content:T()}),GS=z({name:T(),arguments:T()}),BS=z({id:T(),type:$("function"),function:GS,encryptedValue:T().optional(),metadata:V.optional()}),ZS=z({subagentRunId:ee.optional(),id:T(),role:$("assistant"),name:T().optional(),encryptedValue:T().optional(),metadata:V.optional(),content:T().optional(),toolCalls:Re(BS).optional()}),VS=z({subagentRunId:ee.optional(),id:T(),role:$("user"),name:T().optional(),encryptedValue:T().optional(),metadata:V.optional(),content:Kr([T(),Re(pu)])}),jS=z({subagentRunId:ee.optional(),id:T(),role:$("tool"),content:Kr([T(),Re(pu)]),toolCallId:T(),error:T().optional(),encryptedValue:T().optional(),metadata:V.optional()}),WS=z({subagentRunId:ee.optional(),id:T(),role:$("activity"),activityType:T(),content:sr(t=>typeof t=="object"&&t!==null&&!Array.isArray(t)),metadata:V.optional()}),qS=z({subagentRunId:ee.optional(),id:T(),role:$("reasoning"),content:T(),encryptedValue:T().optional(),metadata:V.optional()}),Ng=Bt("role",[HS,FS,ZS,VS,jS,WS,qS]),YS=z({type:$(v.MESSAGES_SNAPSHOT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),messages:Re(Ng)}),KS=z({type:$(v.ACTIVITY_SNAPSHOT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T(),activityType:T(),content:sr(t=>typeof t=="object"&&t!==null&&!Array.isArray(t)),replace:te().optional()}),XS=z({type:$(v.ACTIVITY_DELTA),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T(),activityType:T(),patch:Cg}),JS=z({type:$(v.RAW),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),event:B().refine(t=>t!==void 0),source:T().optional()}),QS=z({type:$(v.CUSTOM),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),name:T(),value:B().refine(t=>t!==void 0)}),Og=z({name:T(),description:T(),parameters:B().refine(t=>t!==null).optional(),metadata:V.optional()}),e0=z({description:T(),value:T()}),t0=z({interruptId:T(),status:bn(["resolved","cancelled"]),payload:B().refine(t=>t!==null).optional(),metadata:V.optional()}),Ji=z({threadId:T(),runId:T(),protocolVersion:T().optional(),parentRunId:T().optional(),state:Rg.refine(t=>t!==null).nullable().transform(t=>t??void 0).optional(),messages:Re(Ng),tools:Re(Og).default(()=>[]),context:Re(e0).default(()=>[]),forwardedProps:B().refine(t=>t!==null).optional(),resume:Re(t0).optional()}),n0=z({type:$(v.RUN_STARTED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),threadId:T(),runId:T(),protocolVersion:T().optional(),parentRunId:T().optional(),input:Ji.optional()}),r0=z({type:$("success"),pendingToolCallIds:Re(T()).optional()}),o0=z({subagentRunId:ee.optional(),id:T(),reason:T(),message:T().optional(),toolCallId:T().optional(),responseSchema:sr(t=>typeof t=="object"&&t!==null&&!Array.isArray(t)).optional(),expiresAt:T().optional(),metadata:V.optional()}),i0=z({type:$("interrupt"),interrupts:Re(o0).min(1)}),a0=z({type:$("cancelled")}),s0=Bt("type",[r0,i0,a0]),Pg=z({provider:T().optional(),model:T().optional(),inputTokens:W().min(0).max(9007199254740991).optional(),outputTokens:W().min(0).max(9007199254740991).optional(),totalTokens:W().min(0).max(9007199254740991).optional(),reasoningTokens:W().min(0).max(9007199254740991).optional(),cachedInputTokens:W().min(0).max(9007199254740991).optional(),cacheWriteInputTokens:W().min(0).max(9007199254740991).optional()}),l0=z({type:$(v.RUN_FINISHED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),threadId:T(),runId:T(),result:B().refine(t=>t!==null).optional(),outcome:s0.optional(),usage:Re(Pg).optional()}),c0=z({type:$(v.RUN_ERROR),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),message:T(),code:T().optional(),usage:Re(Pg).optional()}),u0=z({type:$(v.STEP_STARTED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),stepName:T()}),d0=z({type:$(v.STEP_FINISHED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),stepName:T()}),p0=z({type:$(v.REASONING_START),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T()}),h0=z({type:$(v.REASONING_MESSAGE_START),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T(),role:$("reasoning")}),f0=z({type:$(v.REASONING_MESSAGE_CONTENT),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T(),delta:T()}),m0=z({type:$(v.REASONING_MESSAGE_END),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T()}),hu=z({type:$(v.REASONING_MESSAGE_CHUNK),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T().optional(),delta:T().optional()}),g0=z({type:$(v.REASONING_END),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),messageId:T()}),v0=bn(["tool-call","message"]),b0=z({type:$(v.REASONING_ENCRYPTED_VALUE),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee.optional(),subtype:v0,entityId:T(),encryptedValue:T()}),y0=z({type:$(v.SUBAGENT_STARTED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee,name:T(),description:T().optional(),parentSubagentRunId:ee.optional(),parentToolCallId:T().optional(),parentMessageId:T().optional()}),w0=z({type:$("success")}),E0=z({type:$("suspended"),interruptIds:Re(T()).optional()}),x0=Bt("type",[w0,E0]),_0=z({type:$(v.SUBAGENT_FINISHED),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee,result:B().refine(t=>t!==null).optional(),outcome:x0.optional()}),S0=z({type:$(v.SUBAGENT_ERROR),timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional(),subagentRunId:ee,message:T(),code:T().optional()}),fu=Bt("type",[gS,vS,bS,uu,yS,wS,ES,du,CS,NS,US,YS,KS,XS,JS,QS,n0,l0,c0,u0,d0,p0,h0,f0,m0,hu,g0,b0,y0,_0,S0]),BL=bn(["developer","system","assistant","user","tool","activity","reasoning"]),T0=z({name:T(),description:T().optional()}),A0=z({name:T().optional(),type:T().optional(),description:T().optional(),version:T().optional(),provider:T().optional(),documentationUrl:T().optional(),metadata:V.optional()}),k0=z({streaming:te().optional(),websocket:te().optional(),httpBinary:te().optional(),pushNotifications:te().optional(),resumable:te().optional()}),I0=z({supported:te().optional(),items:Re(Og).optional(),parallelCalls:te().optional(),clientProvided:te().optional()}),R0=z({structuredOutput:te().optional(),supportedMimeTypes:Re(T()).optional()}),C0=z({snapshots:te().optional(),deltas:te().optional(),memory:te().optional(),persistentState:te().optional()}),N0=z({supported:te().optional(),delegation:te().optional(),handoffs:te().optional(),subagents:Re(T0).optional()}),O0=z({supported:te().optional(),streaming:te().optional(),encrypted:te().optional()}),P0=z({image:te().optional(),audio:te().optional(),video:te().optional(),pdf:te().optional(),file:te().optional()}),M0=z({image:te().optional(),audio:te().optional()}),L0=z({input:P0.optional(),output:M0.optional()}),z0=z({codeExecution:te().optional(),sandboxed:te().optional(),maxIterations:W().min(0).max(9007199254740991).optional(),maxExecutionTime:W().min(0).max(9007199254740991).optional()}),D0=z({supported:te().optional(),approvals:te().optional(),interventions:te().optional(),feedback:te().optional(),interrupts:te().optional(),approveWithEdits:te().optional()}),ZL=z({identity:A0.optional(),transport:k0.optional(),tools:I0.optional(),output:R0.optional(),state:C0.optional(),multiAgent:N0.optional(),reasoning:O0.optional(),multimodal:L0.optional(),execution:z0.optional(),humanInTheLoop:D0.optional(),custom:sr(t=>typeof t=="object"&&t!==null&&!Array.isArray(t)).optional()}),VL=z({subagentRunId:ee.optional()}),jL=z({type:mS,timestamp:W().min(-9007199254740991).max(9007199254740991).optional(),rawEvent:B().refine(t=>t!==null).optional(),metadata:V.optional()}),WL=z({subagentRunId:ee.optional(),id:T(),role:T(),name:T().optional(),encryptedValue:T().optional(),metadata:V.optional()}),qL=V.optional();Ue(rr());function Lg(){let t=this.buf,e=this.pos,n=0,r=0;for(let i=0;i<28;i+=7){let a=t[e++];if(n|=(a&127)<<i,(a&128)==0){this.pos=e,this.assertBounds(),this.varint64Lo=n,this.varint64Hi=r;return}}let o=t[e++];if(n|=(o&15)<<28,r=(o&112)>>4,(o&128)==0){this.pos=e,this.assertBounds(),this.varint64Lo=n,this.varint64Hi=r;return}for(let i=3;i<=31;i+=7){let a=t[e++];if(r|=(a&127)<<i,(a&128)==0){this.pos=e,this.assertBounds(),this.varint64Lo=n,this.varint64Hi=r;return}}throw new Error("invalid varint")}var Qi=4294967296;function mu(t){let e=t[0]==="-";e&&(t=t.slice(1));let n=1e6,r=0,o=0;function i(a,s){let c=Number(t.slice(a,s));o*=n,r=r*n+c,r>=Qi&&(o=o+(r/Qi|0),r=r%Qi)}return i(-24,-18),i(-18,-12),i(-12,-6),i(-6),e?Dg(r,o):vu(r,o)}function zg(t,e){let n=vu(t,e),r=n.hi&2147483648;r&&(n=Dg(n.lo,n.hi));let o=gu(n.lo,n.hi);return r?"-"+o:o}function gu(t,e){if({lo:t,hi:e}=$0(t,e),e<=2097151)return String(Qi*e+t);let n=t&16777215,r=(t>>>24|e<<8)&16777215,o=e>>16&65535,i=n+r*6777216+o*6710656,a=r+o*8147497,s=o*2,c=1e7;return i>=c&&(a+=Math.floor(i/c),i%=c),a>=c&&(s+=Math.floor(a/c),a%=c),s.toString()+Mg(a)+Mg(i)}function $0(t,e){return{lo:t>>>0,hi:e>>>0}}function vu(t,e){return{lo:t|0,hi:e|0}}function Dg(t,e){return e=~e,t?t=~t+1:e+=1,vu(t,e)}var Mg=t=>{let e=String(t);return"0000000".slice(e.length)+e};function $g(){let t=this.buf[this.pos++];if((t&128)===0)return this.assertBounds(),t;let e=t&127;if(t=this.buf[this.pos++],e|=(t&127)<<7,(t&128)===0)return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(t&127)<<14,(t&128)===0)return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(t&127)<<21,(t&128)===0)return this.assertBounds(),e;t=this.buf[this.pos++],e|=(t&15)<<28;for(let n=5;(t&128)!==0&&n<10;n++)t=this.buf[this.pos++];if((t&128)!==0)throw new Error("invalid varint");return this.assertBounds(),e>>>0}var pt=U0();function U0(){let t=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof t.getBigInt64=="function"&&typeof t.getBigUint64=="function"&&typeof t.setBigInt64=="function"&&typeof t.setBigUint64=="function"&&(!!globalThis.Deno||!!globalThis.Bun||typeof process!="object"||typeof process.env!="object"||process.env.BUF_BIGINT_DISABLE!=="1")){let n=BigInt("-9223372036854775808"),r=BigInt("9223372036854775807"),o=BigInt("0"),i=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(a){let s=typeof a=="bigint"?a:BigInt(a);if(s>r||s<n)throw new Error(`invalid int64: ${a}`);return s},uParse(a){let s=typeof a=="bigint"?a:BigInt(a);if(s>i||s<o)throw new Error(`invalid uint64: ${a}`);return s},enc(a){return t.setBigInt64(0,this.parse(a),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},uEnc(a){return t.setBigInt64(0,this.uParse(a),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},dec(a,s){return t.setInt32(0,a,!0),t.setInt32(4,s,!0),t.getBigInt64(0,!0)},uDec(a,s){return t.setInt32(0,a,!0),t.setInt32(4,s,!0),t.getBigUint64(0,!0)}}}return{zero:"0",supported:!1,parse(n){return typeof n!="string"&&(n=n.toString()),Ug(n),n},uParse(n){return typeof n!="string"&&(n=n.toString()),Hg(n),n},enc(n){return typeof n!="string"&&(n=n.toString()),Ug(n),mu(n)},uEnc(n){return typeof n!="string"&&(n=n.toString()),Hg(n),mu(n)},dec(n,r){return zg(n,r)},uDec(n,r){return gu(n,r)}}}function Ug(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function Hg(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}var bu;function H0(t){var e;bu=Object.assign(Object.assign({},t),{encodeUtf8Into:(e=t.encodeUtf8Into)!==null&&e!==void 0?e:wu(t.encodeUtf8.bind(t))})}function yu(){if(!bu){let t=globalThis;if(!t.TextEncoder||!t.TextDecoder)throw new Error("encoding API missing: install TextEncoder and TextDecoder on globalThis");let e=new t.TextEncoder,n=new t.TextDecoder,r,o={encodeUtf8(a){return e.encode(a)},decodeUtf8(a,s){return s?(r||(r=new t.TextDecoder("utf-8",{fatal:!0})),r.decode(a)):n.decode(a)},checkUtf8(a){try{return encodeURIComponent(a),!0}catch{return!1}}};e.encodeInto&&(o.encodeUtf8Into=e.encodeInto.bind(e));let i=String.prototype.isWellFormed;i&&(o.checkUtf8=a=>i.call(a)),H0(o)}return bu}function wu(t){return(e,n)=>{let r=t(e);return n.set(r),{written:r.byteLength}}}var Vt;(function(t){t[t.Varint=0]="Varint",t[t.Bit64=1]="Bit64",t[t.LengthDelimited=2]="LengthDelimited",t[t.StartGroup=3]="StartGroup",t[t.EndGroup=4]="EndGroup",t[t.Bit32=5]="Bit32"})(Vt||(Vt={}));var F0=4294967295,G0=2147483647,B0=-2147483648,U=class{constructor(e){this.stackPos=[],this.encodeUtf8Into=e?wu(e):yu().encodeUtf8Into,this.buffer=Gg,this.viewCache=V0,this.pos=0}ensureCapacity(e){let n=this.pos+e;if(n>this.buffer.length){let r=this.buffer.length||Z0;for(;r<n;)r*=2;let o=new Uint8Array(r);this.pos>0&&o.set(this.buffer),this.buffer=o}}view(){let e=this.buffer,n=this.viewCache;if(n.byteLength===e.byteLength)return n;let r=new DataView(e.buffer);return this.viewCache=r,r}finish(){let e=this.buffer.slice(0,this.pos);return this.pos=0,this.stackPos=[],e}fork(){return this.stackPos.push(this.pos),this.ensureCapacity(Xr),this.buffer[this.pos++]=0,this}join(){let e=this.stackPos.pop();if(e===void 0)throw new Error("invalid state, fork stack empty");let n=this.pos-e-Xr,r=Eu(n);return r>Xr&&(this.ensureCapacity(r-Xr),this.buffer.copyWithin(e+r,e+Xr,this.pos)),this.pos=e,this.uint32(n),this.pos+=n,this}tag(e,n){return this.uint32((e<<3|n)>>>0)}raw(e){return this.ensureCapacity(e.length),this.buffer.set(e,this.pos),this.pos+=e.length,this}uint32(e){if(Fg(e),this.ensureCapacity(5),e<128)return this.buffer[this.pos++]=e,this;for(;e>127;)this.buffer[this.pos++]=e&127|128,e>>>=7;return this.buffer[this.pos++]=e,this}int32(e){if(xu(e),e>=0)return this.uint32(e);this.ensureCapacity(10);for(let n=0;n<9;n++)this.buffer[this.pos++]=e&127|128,e>>=7;return this.buffer[this.pos++]=1,this}bool(e){return this.ensureCapacity(1),this.buffer[this.pos++]=e?1:0,this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){typeof e!="string"&&(e=String(e));let n=e.length;if(n<=Bg){this.ensureCapacity(n+1);let c=this.buffer,l=this.pos;c[l++]=n;let u=0;for(;u<n;u++){let f=e.charCodeAt(u);if(f>127)break;c[l++]=f}if(u==n)return this.pos=l,this}this.ensureCapacity(n*3+5);let r=Eu(n),o=this.buffer,i=this.pos,{written:a}=this.encodeUtf8Into(e,o.subarray(i+r)),s=Eu(a);return s!=r&&o.copyWithin(i+s,i+r,i+r+a),this.uint32(a),this.pos+=a,this}float(e){return j0(e),this.ensureCapacity(4),this.view().setFloat32(this.pos,e,!0),this.pos+=4,this}double(e){return this.ensureCapacity(8),this.view().setFloat64(this.pos,e,!0),this.pos+=8,this}fixed32(e){return Fg(e),this.ensureCapacity(4),this.view().setUint32(this.pos,e,!0),this.pos+=4,this}sfixed32(e){return xu(e),this.ensureCapacity(4),this.view().setInt32(this.pos,e,!0),this.pos+=4,this}sint32(e){return xu(e),this.uint32((e<<1^e>>31)>>>0)}sfixed64(e){let n=pt.enc(e);this.ensureCapacity(8);let r=this.view();return r.setInt32(this.pos,n.lo,!0),r.setInt32(this.pos+4,n.hi,!0),this.pos+=8,this}fixed64(e){let n=pt.uEnc(e);this.ensureCapacity(8);let r=this.view();return r.setInt32(this.pos,n.lo,!0),r.setInt32(this.pos+4,n.hi,!0),this.pos+=8,this}int64(e){let n=pt.enc(e);return this.writeVarint64(n.lo,n.hi)}sint64(e){let n=pt.enc(e),r=n.hi>>31,o=n.lo<<1^r,i=(n.hi<<1|n.lo>>>31)^r;return this.writeVarint64(o,i)}uint64(e){let n=pt.uEnc(e);return this.writeVarint64(n.lo,n.hi)}writeVarint64(e,n){this.ensureCapacity(10);let r=this.buffer,o=this.pos;for(let s=0;s<28;s=s+7){let c=e>>>s,l=!(!(c>>>7)&&n==0);if(r[o++]=(l?c|128:c)&255,!l)return this.pos=o,this}let i=e>>>28&15|(n&7)<<4,a=n>>3!=0;if(r[o++]=(a?i|128:i)&255,!a)return this.pos=o,this;for(let s=3;s<31;s=s+7){let c=n>>>s,l=!!(c>>>7);if(r[o++]=(l?c|128:c)&255,!l)return this.pos=o,this}return r[o++]=n>>>31&1,this.pos=o,this}},Z0=128,Xr=1,Gg=new Uint8Array(0),V0=new DataView(Gg.buffer),Bg=32;function Eu(t){return t<128?1:t<16384?2:t<2097152?3:t<268435456?4:5}var R=class{constructor(e,n=yu().decodeUtf8){this.decodeUtf8=n,this.varint64Lo=0,this.varint64Hi=0,this.varint64=Lg,this.uint32=$g,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength)}tag(){let e=this.pos,n=this.uint32(),r=this.pos-e;if(r>5||r==5&&this.buf[this.pos-1]>15)throw new Error("illegal tag: varint overflows uint32");let o=n>>>3,i=n&7;if(o<=0||i>5)throw new Error("illegal tag: field no "+o+" wire type "+i);return[o,i]}skip(e,n,r=100){let o=this.pos;switch(e){case Vt.Varint:for(;this.buf[this.pos++]&128;);break;case Vt.Bit64:this.pos+=4;case Vt.Bit32:this.pos+=4;break;case Vt.LengthDelimited:let i=this.uint32();this.pos+=i;break;case Vt.StartGroup:if(r<=0)throw new Error("maximum recursion depth reached");for(;;){let[a,s]=this.tag();if(s===Vt.EndGroup){if(n!==void 0&&a!==n)throw new Error("invalid end group tag");break}this.skip(s,a,r-1)}break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(o,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return this.varint64(),pt.dec(this.varint64Lo,this.varint64Hi)}uint64(){return this.varint64(),pt.uDec(this.varint64Lo,this.varint64Hi)}sint64(){this.varint64();let e=this.varint64Lo,n=this.varint64Hi,r=-(e&1);return e=(e>>>1|(n&1)<<31)^r,n=n>>>1^r,pt.dec(e,n)}bool(){let e=this.buf[this.pos];return e<128?(this.pos++,e!==0):(this.varint64(),this.varint64Lo!==0||this.varint64Hi!==0)}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return pt.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return pt.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),n=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(n,n+e)}string(e){let n=this.bytes(),r=n.length;if(r<=Bg){let o=new Array(r);for(let i=0;i<r;i++){let a=n[i];if(a>127)return this.decodeUtf8(n,e);o[i]=a}return String.fromCharCode.apply(String,o)}return this.decodeUtf8(n,e)}};function xu(t){if(typeof t=="string")t=Number(t);else if(typeof t!="number")throw new Error("invalid int32: "+typeof t);if(!Number.isInteger(t)||t>G0||t<B0)throw new Error("invalid int32: "+t)}function Fg(t){if(typeof t=="string")t=Number(t);else if(typeof t!="number")throw new Error("invalid uint32: "+typeof t);if(!Number.isInteger(t)||t>F0||t<0)throw new Error("invalid uint32: "+t)}function j0(t){if(typeof t=="string"){let e=t;if(t=Number(t),Number.isNaN(t)&&e!=="NaN")throw new Error("invalid float32: "+e)}else if(typeof t!="number")throw new Error("invalid float32: "+typeof t);if(!Number.isFinite(Math.fround(t))&&Number.isFinite(t))throw new Error("invalid float32: "+t)}var W0=(function(t){return t[t.NULL_VALUE=0]="NULL_VALUE",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t})({});function _u(){return{fields:{}}}var oe={encode(t,e=new U){return Object.entries(t.fields).forEach(([n,r])=>{r!==void 0&&Au.encode({key:n,value:r},e.uint32(10).fork()).join()}),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=_u();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:{if(i!==10)break;let a=Au.decode(n,n.uint32());a.value!==void 0&&(o.fields[a.key]=a.value);continue}}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return oe.fromPartial(t??{})},fromPartial(t){let e=_u();return e.fields=Object.entries(t.fields??{}).reduce((n,[r,o])=>(o!==void 0&&(n[r]=o),n),{}),e},wrap(t){let e=_u();if(t!==void 0)for(let n of Object.keys(t))e.fields[n]=t[n];return e},unwrap(t){let e={};if(t.fields)for(let n of Object.keys(t.fields))e[n]=t.fields[n];return e}};function Zg(){return{key:"",value:void 0}}var Au={encode(t,e=new U){return t.key!==""&&e.uint32(10).string(t.key),t.value!==void 0&&D.encode(D.wrap(t.value),e.uint32(18).fork()).join(),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Zg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.key=n.string();continue;case 2:if(i!==18)break;o.value=D.unwrap(D.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Au.fromPartial(t??{})},fromPartial(t){let e=Zg();return e.key=t.key??"",e.value=t.value??void 0,e}};function Su(){return{nullValue:void 0,numberValue:void 0,stringValue:void 0,boolValue:void 0,structValue:void 0,listValue:void 0}}var D={encode(t,e=new U){return t.nullValue!==void 0&&e.uint32(8).int32(t.nullValue),t.numberValue!==void 0&&e.uint32(17).double(t.numberValue),t.stringValue!==void 0&&e.uint32(26).string(t.stringValue),t.boolValue!==void 0&&e.uint32(32).bool(t.boolValue),t.structValue!==void 0&&oe.encode(oe.wrap(t.structValue),e.uint32(42).fork()).join(),t.listValue!==void 0&&Jr.encode(Jr.wrap(t.listValue),e.uint32(50).fork()).join(),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Su();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.nullValue=n.int32();continue;case 2:if(i!==17)break;o.numberValue=n.double();continue;case 3:if(i!==26)break;o.stringValue=n.string();continue;case 4:if(i!==32)break;o.boolValue=n.bool();continue;case 5:if(i!==42)break;o.structValue=oe.unwrap(oe.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.listValue=Jr.unwrap(Jr.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return D.fromPartial(t??{})},fromPartial(t){let e=Su();return e.nullValue=t.nullValue??void 0,e.numberValue=t.numberValue??void 0,e.stringValue=t.stringValue??void 0,e.boolValue=t.boolValue??void 0,e.structValue=t.structValue??void 0,e.listValue=t.listValue??void 0,e},wrap(t){let e=Su();if(t===null)e.nullValue=W0.NULL_VALUE;else if(typeof t=="boolean")e.boolValue=t;else if(typeof t=="number")e.numberValue=t;else if(typeof t=="string")e.stringValue=t;else if(globalThis.Array.isArray(t))e.listValue=t;else if(typeof t=="object")e.structValue=t;else if(typeof t<"u")throw new globalThis.Error("Unsupported any value type: "+typeof t);return e},unwrap(t){if(t.stringValue!==void 0)return t.stringValue;if(t?.numberValue!==void 0)return t.numberValue;if(t?.boolValue!==void 0)return t.boolValue;if(t?.structValue!==void 0)return t.structValue;if(t?.listValue!==void 0)return t.listValue;if(t?.nullValue!==void 0)return null}};function Tu(){return{values:[]}}var Jr={encode(t,e=new U){for(let n of t.values)D.encode(D.wrap(n),e.uint32(10).fork()).join();return e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Tu();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.values.push(D.unwrap(D.decode(n,n.uint32())));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Jr.fromPartial(t??{})},fromPartial(t){let e=Tu();return e.values=t.values?.map(n=>n)||[],e},wrap(t){let e=Tu();return e.values=t??[],e},unwrap(t){return t?.hasOwnProperty("values")&&globalThis.Array.isArray(t.values)?t.values:t}},Vg=(function(t){return t[t.ADD=0]="ADD",t[t.REMOVE=1]="REMOVE",t[t.REPLACE=2]="REPLACE",t[t.MOVE=3]="MOVE",t[t.COPY=4]="COPY",t[t.TEST=5]="TEST",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t})({});function jg(){return{op:0,path:"",from:void 0,value:void 0}}var En={encode(t,e=new U){return t.op!==0&&e.uint32(8).int32(t.op),t.path!==""&&e.uint32(18).string(t.path),t.from!==void 0&&e.uint32(26).string(t.from),t.value!==void 0&&D.encode(D.wrap(t.value),e.uint32(34).fork()).join(),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=jg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.op=n.int32();continue;case 2:if(i!==18)break;o.path=n.string();continue;case 3:if(i!==26)break;o.from=n.string();continue;case 4:if(i!==34)break;o.value=D.unwrap(D.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return En.fromPartial(t??{})},fromPartial(t){let e=jg();return e.op=t.op??0,e.path=t.path??"",e.from=t.from??void 0,e.value=t.value??void 0,e}};function Wg(){return{text:"",id:void 0,metadata:void 0}}var ea={encode(t,e=new U){return t.text!==""&&e.uint32(10).string(t.text),t.id!==void 0&&e.uint32(18).string(t.id),t.metadata!==void 0&&D.encode(D.wrap(t.metadata),e.uint32(26).fork()).join(),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Wg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.text=n.string();continue;case 2:if(i!==18)break;o.id=n.string();continue;case 3:if(i!==26)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ea.fromPartial(t??{})},fromPartial(t){let e=Wg();return e.text=t.text??"",e.id=t.id??void 0,e.metadata=t.metadata??void 0,e}};function qg(){return{source:void 0,metadata:void 0,id:void 0}}var ta={encode(t,e=new U){return t.source!==void 0&&Je.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&D.encode(D.wrap(t.metadata),e.uint32(18).fork()).join(),t.id!==void 0&&e.uint32(26).string(t.id),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=qg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Je.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.id=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ta.fromPartial(t??{})},fromPartial(t){let e=qg();return e.source=t.source!==void 0&&t.source!==null?Je.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e.id=t.id??void 0,e}};function Yg(){return{value:"",mimeType:""}}var na={encode(t,e=new U){return t.value!==""&&e.uint32(10).string(t.value),t.mimeType!==""&&e.uint32(18).string(t.mimeType),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Yg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.value=n.string();continue;case 2:if(i!==18)break;o.mimeType=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return na.fromPartial(t??{})},fromPartial(t){let e=Yg();return e.value=t.value??"",e.mimeType=t.mimeType??"",e}};function Kg(){return{value:"",mimeType:void 0}}var ra={encode(t,e=new U){return t.value!==""&&e.uint32(10).string(t.value),t.mimeType!==void 0&&e.uint32(18).string(t.mimeType),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Kg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.value=n.string();continue;case 2:if(i!==18)break;o.mimeType=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ra.fromPartial(t??{})},fromPartial(t){let e=Kg();return e.value=t.value??"",e.mimeType=t.mimeType??void 0,e}};function Xg(){return{value:"",provider:void 0,mimeType:void 0}}var oa={encode(t,e=new U){return t.value!==""&&e.uint32(10).string(t.value),t.provider!==void 0&&e.uint32(18).string(t.provider),t.mimeType!==void 0&&e.uint32(26).string(t.mimeType),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Xg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.value=n.string();continue;case 2:if(i!==18)break;o.provider=n.string();continue;case 3:if(i!==26)break;o.mimeType=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return oa.fromPartial(t??{})},fromPartial(t){let e=Xg();return e.value=t.value??"",e.provider=t.provider??void 0,e.mimeType=t.mimeType??void 0,e}};function Jg(){return{data:void 0,url:void 0,file:void 0}}var Je={encode(t,e=new U){return t.data!==void 0&&na.encode(t.data,e.uint32(10).fork()).join(),t.url!==void 0&&ra.encode(t.url,e.uint32(18).fork()).join(),t.file!==void 0&&oa.encode(t.file,e.uint32(26).fork()).join(),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Jg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.data=na.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.url=ra.decode(n,n.uint32());continue;case 3:if(i!==26)break;o.file=oa.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Je.fromPartial(t??{})},fromPartial(t){let e=Jg();return e.data=t.data!==void 0&&t.data!==null?na.fromPartial(t.data):void 0,e.url=t.url!==void 0&&t.url!==null?ra.fromPartial(t.url):void 0,e.file=t.file!==void 0&&t.file!==null?oa.fromPartial(t.file):void 0,e}};function Qg(){return{source:void 0,metadata:void 0,id:void 0}}var ia={encode(t,e=new U){return t.source!==void 0&&Je.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&D.encode(D.wrap(t.metadata),e.uint32(18).fork()).join(),t.id!==void 0&&e.uint32(26).string(t.id),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Qg();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Je.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.id=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ia.fromPartial(t??{})},fromPartial(t){let e=Qg();return e.source=t.source!==void 0&&t.source!==null?Je.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e.id=t.id??void 0,e}};function ev(){return{source:void 0,metadata:void 0,id:void 0}}var aa={encode(t,e=new U){return t.source!==void 0&&Je.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&D.encode(D.wrap(t.metadata),e.uint32(18).fork()).join(),t.id!==void 0&&e.uint32(26).string(t.id),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=ev();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Je.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.id=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return aa.fromPartial(t??{})},fromPartial(t){let e=ev();return e.source=t.source!==void 0&&t.source!==null?Je.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e.id=t.id??void 0,e}};function tv(){return{source:void 0,metadata:void 0,id:void 0}}var sa={encode(t,e=new U){return t.source!==void 0&&Je.encode(t.source,e.uint32(10).fork()).join(),t.metadata!==void 0&&D.encode(D.wrap(t.metadata),e.uint32(18).fork()).join(),t.id!==void 0&&e.uint32(26).string(t.id),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=tv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.source=Je.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.id=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return sa.fromPartial(t??{})},fromPartial(t){let e=tv();return e.source=t.source!==void 0&&t.source!==null?Je.fromPartial(t.source):void 0,e.metadata=t.metadata??void 0,e.id=t.id??void 0,e}};function nv(){return{text:void 0,image:void 0,audio:void 0,video:void 0,document:void 0}}var xn={encode(t,e=new U){return t.text!==void 0&&ea.encode(t.text,e.uint32(10).fork()).join(),t.image!==void 0&&ta.encode(t.image,e.uint32(18).fork()).join(),t.audio!==void 0&&ia.encode(t.audio,e.uint32(26).fork()).join(),t.video!==void 0&&aa.encode(t.video,e.uint32(34).fork()).join(),t.document!==void 0&&sa.encode(t.document,e.uint32(42).fork()).join(),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=nv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.text=ea.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.image=ta.decode(n,n.uint32());continue;case 3:if(i!==26)break;o.audio=ia.decode(n,n.uint32());continue;case 4:if(i!==34)break;o.video=aa.decode(n,n.uint32());continue;case 5:if(i!==42)break;o.document=sa.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return xn.fromPartial(t??{})},fromPartial(t){let e=nv();return e.text=t.text!==void 0&&t.text!==null?ea.fromPartial(t.text):void 0,e.image=t.image!==void 0&&t.image!==null?ta.fromPartial(t.image):void 0,e.audio=t.audio!==void 0&&t.audio!==null?ia.fromPartial(t.audio):void 0,e.video=t.video!==void 0&&t.video!==null?aa.fromPartial(t.video):void 0,e.document=t.document!==void 0&&t.document!==null?sa.fromPartial(t.document):void 0,e}};function rv(){return{id:"",type:"",function:void 0,metadata:void 0,encryptedValue:void 0}}var la={encode(t,e=new U){return t.id!==""&&e.uint32(10).string(t.id),t.type!==""&&e.uint32(18).string(t.type),t.function!==void 0&&ca.encode(t.function,e.uint32(26).fork()).join(),t.metadata!==void 0&&oe.encode(oe.wrap(t.metadata),e.uint32(34).fork()).join(),t.encryptedValue!==void 0&&e.uint32(42).string(t.encryptedValue),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=rv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.type=n.string();continue;case 3:if(i!==26)break;o.function=ca.decode(n,n.uint32());continue;case 4:if(i!==34)break;o.metadata=oe.unwrap(oe.decode(n,n.uint32()));continue;case 5:if(i!==42)break;o.encryptedValue=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return la.fromPartial(t??{})},fromPartial(t){let e=rv();return e.id=t.id??"",e.type=t.type??"",e.function=t.function!==void 0&&t.function!==null?ca.fromPartial(t.function):void 0,e.metadata=t.metadata??void 0,e.encryptedValue=t.encryptedValue??void 0,e}};function ov(){return{name:"",arguments:""}}var ca={encode(t,e=new U){return t.name!==""&&e.uint32(10).string(t.name),t.arguments!==""&&e.uint32(18).string(t.arguments),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=ov();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.name=n.string();continue;case 2:if(i!==18)break;o.arguments=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ca.fromPartial(t??{})},fromPartial(t){let e=ov();return e.name=t.name??"",e.arguments=t.arguments??"",e}};function iv(){return{id:"",role:"",content:void 0,name:void 0,toolCalls:[],toolCallId:void 0,error:void 0,contentParts:[],metadata:void 0,subagentRunId:void 0,encryptedValue:void 0,activityType:void 0,activityContent:void 0}}var _n={encode(t,e=new U){t.id!==""&&e.uint32(10).string(t.id),t.role!==""&&e.uint32(18).string(t.role),t.content!==void 0&&e.uint32(26).string(t.content),t.name!==void 0&&e.uint32(34).string(t.name);for(let n of t.toolCalls)la.encode(n,e.uint32(42).fork()).join();t.toolCallId!==void 0&&e.uint32(50).string(t.toolCallId),t.error!==void 0&&e.uint32(58).string(t.error);for(let n of t.contentParts)xn.encode(n,e.uint32(66).fork()).join();return t.metadata!==void 0&&oe.encode(oe.wrap(t.metadata),e.uint32(74).fork()).join(),t.subagentRunId!==void 0&&e.uint32(82).string(t.subagentRunId),t.encryptedValue!==void 0&&e.uint32(90).string(t.encryptedValue),t.activityType!==void 0&&e.uint32(98).string(t.activityType),t.activityContent!==void 0&&oe.encode(oe.wrap(t.activityContent),e.uint32(106).fork()).join(),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=iv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.role=n.string();continue;case 3:if(i!==26)break;o.content=n.string();continue;case 4:if(i!==34)break;o.name=n.string();continue;case 5:if(i!==42)break;o.toolCalls.push(la.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.toolCallId=n.string();continue;case 7:if(i!==58)break;o.error=n.string();continue;case 8:if(i!==66)break;o.contentParts.push(xn.decode(n,n.uint32()));continue;case 9:if(i!==74)break;o.metadata=oe.unwrap(oe.decode(n,n.uint32()));continue;case 10:if(i!==82)break;o.subagentRunId=n.string();continue;case 11:if(i!==90)break;o.encryptedValue=n.string();continue;case 12:if(i!==98)break;o.activityType=n.string();continue;case 13:if(i!==106)break;o.activityContent=oe.unwrap(oe.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return _n.fromPartial(t??{})},fromPartial(t){let e=iv();return e.id=t.id??"",e.role=t.role??"",e.content=t.content??void 0,e.name=t.name??void 0,e.toolCalls=t.toolCalls?.map(n=>la.fromPartial(n))||[],e.toolCallId=t.toolCallId??void 0,e.error=t.error??void 0,e.contentParts=t.contentParts?.map(n=>xn.fromPartial(n))||[],e.metadata=t.metadata??void 0,e.subagentRunId=t.subagentRunId??void 0,e.encryptedValue=t.encryptedValue??void 0,e.activityType=t.activityType??void 0,e.activityContent=t.activityContent??void 0,e}};function av(){return{name:"",description:"",parameters:void 0,metadata:void 0}}var ua={encode(t,e=new U){return t.name!==""&&e.uint32(10).string(t.name),t.description!==""&&e.uint32(18).string(t.description),t.parameters!==void 0&&D.encode(D.wrap(t.parameters),e.uint32(26).fork()).join(),t.metadata!==void 0&&oe.encode(oe.wrap(t.metadata),e.uint32(34).fork()).join(),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=av();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.name=n.string();continue;case 2:if(i!==18)break;o.description=n.string();continue;case 3:if(i!==26)break;o.parameters=D.unwrap(D.decode(n,n.uint32()));continue;case 4:if(i!==34)break;o.metadata=oe.unwrap(oe.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ua.fromPartial(t??{})},fromPartial(t){let e=av();return e.name=t.name??"",e.description=t.description??"",e.parameters=t.parameters??void 0,e.metadata=t.metadata??void 0,e}};function sv(){return{description:"",value:""}}var da={encode(t,e=new U){return t.description!==""&&e.uint32(10).string(t.description),t.value!==""&&e.uint32(18).string(t.value),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=sv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.description=n.string();continue;case 2:if(i!==18)break;o.value=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return da.fromPartial(t??{})},fromPartial(t){let e=sv();return e.description=t.description??"",e.value=t.value??"",e}};function lv(){return{interruptId:"",status:"",payload:void 0,metadata:void 0}}var pa={encode(t,e=new U){return t.interruptId!==""&&e.uint32(10).string(t.interruptId),t.status!==""&&e.uint32(18).string(t.status),t.payload!==void 0&&D.encode(D.wrap(t.payload),e.uint32(26).fork()).join(),t.metadata!==void 0&&oe.encode(oe.wrap(t.metadata),e.uint32(34).fork()).join(),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=lv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.interruptId=n.string();continue;case 2:if(i!==18)break;o.status=n.string();continue;case 3:if(i!==26)break;o.payload=D.unwrap(D.decode(n,n.uint32()));continue;case 4:if(i!==34)break;o.metadata=oe.unwrap(oe.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return pa.fromPartial(t??{})},fromPartial(t){let e=lv();return e.interruptId=t.interruptId??"",e.status=t.status??"",e.payload=t.payload??void 0,e.metadata=t.metadata??void 0,e}};function cv(){return{threadId:"",runId:"",parentRunId:void 0,state:void 0,messages:[],tools:[],context:[],forwardedProps:void 0,resume:[],protocolVersion:void 0}}var ha={encode(t,e=new U){t.threadId!==""&&e.uint32(10).string(t.threadId),t.runId!==""&&e.uint32(18).string(t.runId),t.parentRunId!==void 0&&e.uint32(26).string(t.parentRunId),t.state!==void 0&&D.encode(D.wrap(t.state),e.uint32(34).fork()).join();for(let n of t.messages)_n.encode(n,e.uint32(42).fork()).join();for(let n of t.tools)ua.encode(n,e.uint32(50).fork()).join();for(let n of t.context)da.encode(n,e.uint32(58).fork()).join();t.forwardedProps!==void 0&&D.encode(D.wrap(t.forwardedProps),e.uint32(66).fork()).join();for(let n of t.resume)pa.encode(n,e.uint32(74).fork()).join();return t.protocolVersion!==void 0&&e.uint32(82).string(t.protocolVersion),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=cv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.threadId=n.string();continue;case 2:if(i!==18)break;o.runId=n.string();continue;case 3:if(i!==26)break;o.parentRunId=n.string();continue;case 4:if(i!==34)break;o.state=D.unwrap(D.decode(n,n.uint32()));continue;case 5:if(i!==42)break;o.messages.push(_n.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.tools.push(ua.decode(n,n.uint32()));continue;case 7:if(i!==58)break;o.context.push(da.decode(n,n.uint32()));continue;case 8:if(i!==66)break;o.forwardedProps=D.unwrap(D.decode(n,n.uint32()));continue;case 9:if(i!==74)break;o.resume.push(pa.decode(n,n.uint32()));continue;case 10:if(i!==82)break;o.protocolVersion=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ha.fromPartial(t??{})},fromPartial(t){let e=cv();return e.threadId=t.threadId??"",e.runId=t.runId??"",e.parentRunId=t.parentRunId??void 0,e.state=t.state??void 0,e.messages=t.messages?.map(n=>_n.fromPartial(n))||[],e.tools=t.tools?.map(n=>ua.fromPartial(n))||[],e.context=t.context?.map(n=>da.fromPartial(n))||[],e.forwardedProps=t.forwardedProps??void 0,e.resume=t.resume?.map(n=>pa.fromPartial(n))||[],e.protocolVersion=t.protocolVersion??void 0,e}};function uv(){return{id:"",reason:"",message:void 0,toolCallId:void 0,responseSchema:void 0,expiresAt:void 0,metadata:void 0,subagentRunId:void 0}}var fa={encode(t,e=new U){return t.id!==""&&e.uint32(10).string(t.id),t.reason!==""&&e.uint32(18).string(t.reason),t.message!==void 0&&e.uint32(26).string(t.message),t.toolCallId!==void 0&&e.uint32(34).string(t.toolCallId),t.responseSchema!==void 0&&D.encode(D.wrap(t.responseSchema),e.uint32(42).fork()).join(),t.expiresAt!==void 0&&e.uint32(50).string(t.expiresAt),t.metadata!==void 0&&D.encode(D.wrap(t.metadata),e.uint32(58).fork()).join(),t.subagentRunId!==void 0&&e.uint32(66).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=uv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.id=n.string();continue;case 2:if(i!==18)break;o.reason=n.string();continue;case 3:if(i!==26)break;o.message=n.string();continue;case 4:if(i!==34)break;o.toolCallId=n.string();continue;case 5:if(i!==42)break;o.responseSchema=D.unwrap(D.decode(n,n.uint32()));continue;case 6:if(i!==50)break;o.expiresAt=n.string();continue;case 7:if(i!==58)break;o.metadata=D.unwrap(D.decode(n,n.uint32()));continue;case 8:if(i!==66)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return fa.fromPartial(t??{})},fromPartial(t){let e=uv();return e.id=t.id??"",e.reason=t.reason??"",e.message=t.message??void 0,e.toolCallId=t.toolCallId??void 0,e.responseSchema=t.responseSchema??void 0,e.expiresAt=t.expiresAt??void 0,e.metadata=t.metadata??void 0,e.subagentRunId=t.subagentRunId??void 0,e}},q0=(function(t){return t[t.TEXT_MESSAGE_START=0]="TEXT_MESSAGE_START",t[t.TEXT_MESSAGE_CONTENT=1]="TEXT_MESSAGE_CONTENT",t[t.TEXT_MESSAGE_END=2]="TEXT_MESSAGE_END",t[t.TOOL_CALL_START=3]="TOOL_CALL_START",t[t.TOOL_CALL_ARGS=4]="TOOL_CALL_ARGS",t[t.TOOL_CALL_END=5]="TOOL_CALL_END",t[t.STATE_SNAPSHOT=6]="STATE_SNAPSHOT",t[t.STATE_DELTA=7]="STATE_DELTA",t[t.MESSAGES_SNAPSHOT=8]="MESSAGES_SNAPSHOT",t[t.RAW=9]="RAW",t[t.CUSTOM=10]="CUSTOM",t[t.RUN_STARTED=11]="RUN_STARTED",t[t.RUN_FINISHED=12]="RUN_FINISHED",t[t.RUN_ERROR=13]="RUN_ERROR",t[t.STEP_STARTED=14]="STEP_STARTED",t[t.STEP_FINISHED=15]="STEP_FINISHED",t[t.SUBAGENT_STARTED=16]="SUBAGENT_STARTED",t[t.SUBAGENT_FINISHED=17]="SUBAGENT_FINISHED",t[t.SUBAGENT_ERROR=18]="SUBAGENT_ERROR",t[t.TEXT_MESSAGE_CHUNK=19]="TEXT_MESSAGE_CHUNK",t[t.TOOL_CALL_CHUNK=20]="TOOL_CALL_CHUNK",t[t.TOOL_CALL_RESULT=21]="TOOL_CALL_RESULT",t[t.ACTIVITY_SNAPSHOT=22]="ACTIVITY_SNAPSHOT",t[t.ACTIVITY_DELTA=23]="ACTIVITY_DELTA",t[t.REASONING_START=24]="REASONING_START",t[t.REASONING_MESSAGE_START=25]="REASONING_MESSAGE_START",t[t.REASONING_MESSAGE_CONTENT=26]="REASONING_MESSAGE_CONTENT",t[t.REASONING_MESSAGE_END=27]="REASONING_MESSAGE_END",t[t.REASONING_MESSAGE_CHUNK=28]="REASONING_MESSAGE_CHUNK",t[t.REASONING_END=29]="REASONING_END",t[t.REASONING_ENCRYPTED_VALUE=30]="REASONING_ENCRYPTED_VALUE",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t})({});function dv(){return{type:0,timestamp:void 0,rawEvent:void 0,metadata:void 0}}var M={encode(t,e=new U){return t.type!==0&&e.uint32(8).int32(t.type),t.timestamp!==void 0&&e.uint32(16).int64(t.timestamp),t.rawEvent!==void 0&&D.encode(D.wrap(t.rawEvent),e.uint32(26).fork()).join(),t.metadata!==void 0&&oe.encode(oe.wrap(t.metadata),e.uint32(34).fork()).join(),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=dv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==8)break;o.type=n.int32();continue;case 2:if(i!==16)break;o.timestamp=yn(n.int64());continue;case 3:if(i!==26)break;o.rawEvent=D.unwrap(D.decode(n,n.uint32()));continue;case 4:if(i!==34)break;o.metadata=oe.unwrap(oe.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return M.fromPartial(t??{})},fromPartial(t){let e=dv();return e.type=t.type??0,e.timestamp=t.timestamp??void 0,e.rawEvent=t.rawEvent??void 0,e.metadata=t.metadata??void 0,e}};function pv(){return{baseEvent:void 0,messageId:"",role:void 0,name:void 0,subagentRunId:void 0}}var ma={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==""&&e.uint32(18).string(t.messageId),t.role!==void 0&&e.uint32(26).string(t.role),t.name!==void 0&&e.uint32(34).string(t.name),t.subagentRunId!==void 0&&e.uint32(42).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=pv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.role=n.string();continue;case 4:if(i!==34)break;o.name=n.string();continue;case 5:if(i!==42)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ma.fromPartial(t??{})},fromPartial(t){let e=pv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??"",e.role=t.role??void 0,e.name=t.name??void 0,e.subagentRunId=t.subagentRunId??void 0,e}};function hv(){return{baseEvent:void 0,messageId:"",delta:"",subagentRunId:void 0}}var ga={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==""&&e.uint32(18).string(t.messageId),t.delta!==""&&e.uint32(26).string(t.delta),t.subagentRunId!==void 0&&e.uint32(34).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=hv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.delta=n.string();continue;case 4:if(i!==34)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ga.fromPartial(t??{})},fromPartial(t){let e=hv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??"",e.delta=t.delta??"",e.subagentRunId=t.subagentRunId??void 0,e}};function fv(){return{baseEvent:void 0,messageId:"",subagentRunId:void 0}}var va={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==""&&e.uint32(18).string(t.messageId),t.subagentRunId!==void 0&&e.uint32(26).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=fv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return va.fromPartial(t??{})},fromPartial(t){let e=fv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??"",e.subagentRunId=t.subagentRunId??void 0,e}};function mv(){return{baseEvent:void 0,messageId:void 0,role:void 0,delta:void 0,name:void 0,subagentRunId:void 0}}var ba={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.messageId!==void 0&&e.uint32(18).string(t.messageId),t.role!==void 0&&e.uint32(26).string(t.role),t.delta!==void 0&&e.uint32(34).string(t.delta),t.name!==void 0&&e.uint32(42).string(t.name),t.subagentRunId!==void 0&&e.uint32(50).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=mv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messageId=n.string();continue;case 3:if(i!==26)break;o.role=n.string();continue;case 4:if(i!==34)break;o.delta=n.string();continue;case 5:if(i!==42)break;o.name=n.string();continue;case 6:if(i!==50)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ba.fromPartial(t??{})},fromPartial(t){let e=mv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messageId=t.messageId??void 0,e.role=t.role??void 0,e.delta=t.delta??void 0,e.name=t.name??void 0,e.subagentRunId=t.subagentRunId??void 0,e}};function gv(){return{baseEvent:void 0,toolCallId:"",toolCallName:"",parentMessageId:void 0,subagentRunId:void 0}}var ya={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==""&&e.uint32(18).string(t.toolCallId),t.toolCallName!==""&&e.uint32(26).string(t.toolCallName),t.parentMessageId!==void 0&&e.uint32(34).string(t.parentMessageId),t.subagentRunId!==void 0&&e.uint32(42).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=gv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.toolCallName=n.string();continue;case 4:if(i!==34)break;o.parentMessageId=n.string();continue;case 5:if(i!==42)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ya.fromPartial(t??{})},fromPartial(t){let e=gv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??"",e.toolCallName=t.toolCallName??"",e.parentMessageId=t.parentMessageId??void 0,e.subagentRunId=t.subagentRunId??void 0,e}};function vv(){return{baseEvent:void 0,toolCallId:"",delta:"",subagentRunId:void 0}}var wa={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==""&&e.uint32(18).string(t.toolCallId),t.delta!==""&&e.uint32(26).string(t.delta),t.subagentRunId!==void 0&&e.uint32(34).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=vv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.delta=n.string();continue;case 4:if(i!==34)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return wa.fromPartial(t??{})},fromPartial(t){let e=vv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??"",e.delta=t.delta??"",e.subagentRunId=t.subagentRunId??void 0,e}};function bv(){return{baseEvent:void 0,toolCallId:"",subagentRunId:void 0}}var Ea={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==""&&e.uint32(18).string(t.toolCallId),t.subagentRunId!==void 0&&e.uint32(26).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=bv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ea.fromPartial(t??{})},fromPartial(t){let e=bv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??"",e.subagentRunId=t.subagentRunId??void 0,e}};function yv(){return{baseEvent:void 0,toolCallId:void 0,toolCallName:void 0,parentMessageId:void 0,delta:void 0,subagentRunId:void 0}}var xa={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.toolCallId!==void 0&&e.uint32(18).string(t.toolCallId),t.toolCallName!==void 0&&e.uint32(26).string(t.toolCallName),t.parentMessageId!==void 0&&e.uint32(34).string(t.parentMessageId),t.delta!==void 0&&e.uint32(42).string(t.delta),t.subagentRunId!==void 0&&e.uint32(50).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=yv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.toolCallId=n.string();continue;case 3:if(i!==26)break;o.toolCallName=n.string();continue;case 4:if(i!==34)break;o.parentMessageId=n.string();continue;case 5:if(i!==42)break;o.delta=n.string();continue;case 6:if(i!==50)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return xa.fromPartial(t??{})},fromPartial(t){let e=yv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.toolCallId=t.toolCallId??void 0,e.toolCallName=t.toolCallName??void 0,e.parentMessageId=t.parentMessageId??void 0,e.delta=t.delta??void 0,e.subagentRunId=t.subagentRunId??void 0,e}};function wv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:"",toolCallId:"",content:void 0,role:void 0,contentParts:[]}}var _a={encode(t,e=new U){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==void 0&&e.uint32(18).string(t.subagentRunId),t.messageId!==""&&e.uint32(26).string(t.messageId),t.toolCallId!==""&&e.uint32(34).string(t.toolCallId),t.content!==void 0&&e.uint32(42).string(t.content),t.role!==void 0&&e.uint32(50).string(t.role);for(let n of t.contentParts)xn.encode(n,e.uint32(58).fork()).join();return e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=wv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.toolCallId=n.string();continue;case 5:if(i!==42)break;o.content=n.string();continue;case 6:if(i!==50)break;o.role=n.string();continue;case 7:if(i!==58)break;o.contentParts.push(xn.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return _a.fromPartial(t??{})},fromPartial(t){let e=wv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??void 0,e.messageId=t.messageId??"",e.toolCallId=t.toolCallId??"",e.content=t.content??void 0,e.role=t.role??void 0,e.contentParts=t.contentParts?.map(n=>xn.fromPartial(n))||[],e}};function Ev(){return{baseEvent:void 0,snapshot:void 0,subagentRunId:void 0}}var Sa={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.snapshot!==void 0&&D.encode(D.wrap(t.snapshot),e.uint32(18).fork()).join(),t.subagentRunId!==void 0&&e.uint32(26).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Ev();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.snapshot=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Sa.fromPartial(t??{})},fromPartial(t){let e=Ev();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.snapshot=t.snapshot??void 0,e.subagentRunId=t.subagentRunId??void 0,e}};function xv(){return{baseEvent:void 0,delta:[],subagentRunId:void 0}}var Ta={encode(t,e=new U){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join();for(let n of t.delta)En.encode(n,e.uint32(18).fork()).join();return t.subagentRunId!==void 0&&e.uint32(26).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=xv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.delta.push(En.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ta.fromPartial(t??{})},fromPartial(t){let e=xv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.delta=t.delta?.map(n=>En.fromPartial(n))||[],e.subagentRunId=t.subagentRunId??void 0,e}};function _v(){return{baseEvent:void 0,messages:[]}}var Aa={encode(t,e=new U){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join();for(let n of t.messages)_n.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=_v();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.messages.push(_n.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Aa.fromPartial(t??{})},fromPartial(t){let e=_v();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.messages=t.messages?.map(n=>_n.fromPartial(n))||[],e}};function Sv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:"",activityType:"",content:void 0,replace:void 0}}var ka={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==void 0&&e.uint32(18).string(t.subagentRunId),t.messageId!==""&&e.uint32(26).string(t.messageId),t.activityType!==""&&e.uint32(34).string(t.activityType),t.content!==void 0&&oe.encode(oe.wrap(t.content),e.uint32(42).fork()).join(),t.replace!==void 0&&e.uint32(48).bool(t.replace),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Sv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.activityType=n.string();continue;case 5:if(i!==42)break;o.content=oe.unwrap(oe.decode(n,n.uint32()));continue;case 6:if(i!==48)break;o.replace=n.bool();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return ka.fromPartial(t??{})},fromPartial(t){let e=Sv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??void 0,e.messageId=t.messageId??"",e.activityType=t.activityType??"",e.content=t.content??void 0,e.replace=t.replace??void 0,e}};function Tv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:"",activityType:"",patch:[]}}var Ia={encode(t,e=new U){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==void 0&&e.uint32(18).string(t.subagentRunId),t.messageId!==""&&e.uint32(26).string(t.messageId),t.activityType!==""&&e.uint32(34).string(t.activityType);for(let n of t.patch)En.encode(n,e.uint32(42).fork()).join();return e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Tv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.activityType=n.string();continue;case 5:if(i!==42)break;o.patch.push(En.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ia.fromPartial(t??{})},fromPartial(t){let e=Tv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??void 0,e.messageId=t.messageId??"",e.activityType=t.activityType??"",e.patch=t.patch?.map(n=>En.fromPartial(n))||[],e}};function Av(){return{baseEvent:void 0,event:void 0,source:void 0,subagentRunId:void 0}}var Ra={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.event!==void 0&&D.encode(D.wrap(t.event),e.uint32(18).fork()).join(),t.source!==void 0&&e.uint32(26).string(t.source),t.subagentRunId!==void 0&&e.uint32(34).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Av();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.event=D.unwrap(D.decode(n,n.uint32()));continue;case 3:if(i!==26)break;o.source=n.string();continue;case 4:if(i!==34)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ra.fromPartial(t??{})},fromPartial(t){let e=Av();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.event=t.event??void 0,e.source=t.source??void 0,e.subagentRunId=t.subagentRunId??void 0,e}};function kv(){return{baseEvent:void 0,name:"",value:void 0,subagentRunId:void 0}}var Ca={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.name!==""&&e.uint32(18).string(t.name),t.value!==void 0&&D.encode(D.wrap(t.value),e.uint32(26).fork()).join(),t.subagentRunId!==void 0&&e.uint32(34).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=kv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.name=n.string();continue;case 3:if(i!==26)break;o.value=D.unwrap(D.decode(n,n.uint32()));continue;case 4:if(i!==34)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ca.fromPartial(t??{})},fromPartial(t){let e=kv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.name=t.name??"",e.value=t.value??void 0,e.subagentRunId=t.subagentRunId??void 0,e}};function Iv(){return{baseEvent:void 0,threadId:"",runId:"",parentRunId:void 0,input:void 0,protocolVersion:void 0}}var Na={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.threadId!==""&&e.uint32(18).string(t.threadId),t.runId!==""&&e.uint32(26).string(t.runId),t.parentRunId!==void 0&&e.uint32(34).string(t.parentRunId),t.input!==void 0&&ha.encode(t.input,e.uint32(42).fork()).join(),t.protocolVersion!==void 0&&e.uint32(50).string(t.protocolVersion),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Iv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.threadId=n.string();continue;case 3:if(i!==26)break;o.runId=n.string();continue;case 4:if(i!==34)break;o.parentRunId=n.string();continue;case 5:if(i!==42)break;o.input=ha.decode(n,n.uint32());continue;case 6:if(i!==50)break;o.protocolVersion=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Na.fromPartial(t??{})},fromPartial(t){let e=Iv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.threadId=t.threadId??"",e.runId=t.runId??"",e.parentRunId=t.parentRunId??void 0,e.input=t.input!==void 0&&t.input!==null?ha.fromPartial(t.input):void 0,e.protocolVersion=t.protocolVersion??void 0,e}};function Rv(){return{baseEvent:void 0,threadId:"",runId:"",result:void 0,outcome:"",interrupts:[],usage:[],pendingToolCallIds:[]}}var Oa={encode(t,e=new U){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.threadId!==""&&e.uint32(18).string(t.threadId),t.runId!==""&&e.uint32(26).string(t.runId),t.result!==void 0&&D.encode(D.wrap(t.result),e.uint32(34).fork()).join(),t.outcome!==""&&e.uint32(42).string(t.outcome);for(let n of t.interrupts)fa.encode(n,e.uint32(50).fork()).join();for(let n of t.usage)Sn.encode(n,e.uint32(58).fork()).join();for(let n of t.pendingToolCallIds)e.uint32(66).string(n);return e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Rv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.threadId=n.string();continue;case 3:if(i!==26)break;o.runId=n.string();continue;case 4:if(i!==34)break;o.result=D.unwrap(D.decode(n,n.uint32()));continue;case 5:if(i!==42)break;o.outcome=n.string();continue;case 6:if(i!==50)break;o.interrupts.push(fa.decode(n,n.uint32()));continue;case 7:if(i!==58)break;o.usage.push(Sn.decode(n,n.uint32()));continue;case 8:if(i!==66)break;o.pendingToolCallIds.push(n.string());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Oa.fromPartial(t??{})},fromPartial(t){let e=Rv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.threadId=t.threadId??"",e.runId=t.runId??"",e.result=t.result??void 0,e.outcome=t.outcome??"",e.interrupts=t.interrupts?.map(n=>fa.fromPartial(n))||[],e.usage=t.usage?.map(n=>Sn.fromPartial(n))||[],e.pendingToolCallIds=t.pendingToolCallIds?.map(n=>n)||[],e}};function Cv(){return{baseEvent:void 0,code:void 0,message:"",usage:[]}}var Pa={encode(t,e=new U){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.code!==void 0&&e.uint32(18).string(t.code),t.message!==""&&e.uint32(26).string(t.message);for(let n of t.usage)Sn.encode(n,e.uint32(34).fork()).join();return e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Cv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.code=n.string();continue;case 3:if(i!==26)break;o.message=n.string();continue;case 4:if(i!==34)break;o.usage.push(Sn.decode(n,n.uint32()));continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Pa.fromPartial(t??{})},fromPartial(t){let e=Cv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.code=t.code??void 0,e.message=t.message??"",e.usage=t.usage?.map(n=>Sn.fromPartial(n))||[],e}};function Nv(){return{baseEvent:void 0,stepName:"",subagentRunId:void 0}}var Ma={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.stepName!==""&&e.uint32(18).string(t.stepName),t.subagentRunId!==void 0&&e.uint32(26).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Nv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.stepName=n.string();continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ma.fromPartial(t??{})},fromPartial(t){let e=Nv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.stepName=t.stepName??"",e.subagentRunId=t.subagentRunId??void 0,e}};function Ov(){return{baseEvent:void 0,stepName:"",subagentRunId:void 0}}var La={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.stepName!==""&&e.uint32(18).string(t.stepName),t.subagentRunId!==void 0&&e.uint32(26).string(t.subagentRunId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Ov();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.stepName=n.string();continue;case 3:if(i!==26)break;o.subagentRunId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return La.fromPartial(t??{})},fromPartial(t){let e=Ov();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.stepName=t.stepName??"",e.subagentRunId=t.subagentRunId??void 0,e}};function Pv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:""}}var za={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==void 0&&e.uint32(18).string(t.subagentRunId),t.messageId!==""&&e.uint32(26).string(t.messageId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Pv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return za.fromPartial(t??{})},fromPartial(t){let e=Pv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??void 0,e.messageId=t.messageId??"",e}};function Mv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:"",role:""}}var Da={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==void 0&&e.uint32(18).string(t.subagentRunId),t.messageId!==""&&e.uint32(26).string(t.messageId),t.role!==""&&e.uint32(34).string(t.role),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Mv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.role=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Da.fromPartial(t??{})},fromPartial(t){let e=Mv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??void 0,e.messageId=t.messageId??"",e.role=t.role??"",e}};function Lv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:"",delta:""}}var $a={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==void 0&&e.uint32(18).string(t.subagentRunId),t.messageId!==""&&e.uint32(26).string(t.messageId),t.delta!==""&&e.uint32(34).string(t.delta),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Lv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.delta=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return $a.fromPartial(t??{})},fromPartial(t){let e=Lv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??void 0,e.messageId=t.messageId??"",e.delta=t.delta??"",e}};function zv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:""}}var Ua={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==void 0&&e.uint32(18).string(t.subagentRunId),t.messageId!==""&&e.uint32(26).string(t.messageId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=zv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ua.fromPartial(t??{})},fromPartial(t){let e=zv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??void 0,e.messageId=t.messageId??"",e}};function Dv(){return{baseEvent:void 0,subagentRunId:void 0,messageId:void 0,delta:void 0}}var Ha={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==void 0&&e.uint32(18).string(t.subagentRunId),t.messageId!==void 0&&e.uint32(26).string(t.messageId),t.delta!==void 0&&e.uint32(34).string(t.delta),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Dv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue;case 4:if(i!==34)break;o.delta=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ha.fromPartial(t??{})},fromPartial(t){let e=Dv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??void 0,e.messageId=t.messageId??void 0,e.delta=t.delta??void 0,e}};function $v(){return{baseEvent:void 0,subagentRunId:void 0,messageId:""}}var Fa={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==void 0&&e.uint32(18).string(t.subagentRunId),t.messageId!==""&&e.uint32(26).string(t.messageId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=$v();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.messageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Fa.fromPartial(t??{})},fromPartial(t){let e=$v();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??void 0,e.messageId=t.messageId??"",e}};function Uv(){return{baseEvent:void 0,subagentRunId:void 0,subtype:"",entityId:"",encryptedValue:""}}var Ga={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==void 0&&e.uint32(18).string(t.subagentRunId),t.subtype!==""&&e.uint32(26).string(t.subtype),t.entityId!==""&&e.uint32(34).string(t.entityId),t.encryptedValue!==""&&e.uint32(42).string(t.encryptedValue),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Uv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.subtype=n.string();continue;case 4:if(i!==34)break;o.entityId=n.string();continue;case 5:if(i!==42)break;o.encryptedValue=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ga.fromPartial(t??{})},fromPartial(t){let e=Uv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??void 0,e.subtype=t.subtype??"",e.entityId=t.entityId??"",e.encryptedValue=t.encryptedValue??"",e}};function Hv(){return{baseEvent:void 0,subagentRunId:"",name:"",description:void 0,parentSubagentRunId:void 0,parentToolCallId:void 0,parentMessageId:void 0}}var Ba={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==""&&e.uint32(18).string(t.subagentRunId),t.name!==""&&e.uint32(26).string(t.name),t.description!==void 0&&e.uint32(34).string(t.description),t.parentSubagentRunId!==void 0&&e.uint32(42).string(t.parentSubagentRunId),t.parentToolCallId!==void 0&&e.uint32(50).string(t.parentToolCallId),t.parentMessageId!==void 0&&e.uint32(58).string(t.parentMessageId),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Hv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.name=n.string();continue;case 4:if(i!==34)break;o.description=n.string();continue;case 5:if(i!==42)break;o.parentSubagentRunId=n.string();continue;case 6:if(i!==50)break;o.parentToolCallId=n.string();continue;case 7:if(i!==58)break;o.parentMessageId=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Ba.fromPartial(t??{})},fromPartial(t){let e=Hv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??"",e.name=t.name??"",e.description=t.description??void 0,e.parentSubagentRunId=t.parentSubagentRunId??void 0,e.parentToolCallId=t.parentToolCallId??void 0,e.parentMessageId=t.parentMessageId??void 0,e}};function Fv(){return{baseEvent:void 0,subagentRunId:"",result:void 0,outcome:"",interruptIds:[]}}var Za={encode(t,e=new U){t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==""&&e.uint32(18).string(t.subagentRunId),t.result!==void 0&&D.encode(D.wrap(t.result),e.uint32(26).fork()).join(),t.outcome!==""&&e.uint32(34).string(t.outcome);for(let n of t.interruptIds)e.uint32(42).string(n);return e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Fv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.result=D.unwrap(D.decode(n,n.uint32()));continue;case 4:if(i!==34)break;o.outcome=n.string();continue;case 5:if(i!==42)break;o.interruptIds.push(n.string());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Za.fromPartial(t??{})},fromPartial(t){let e=Fv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??"",e.result=t.result??void 0,e.outcome=t.outcome??"",e.interruptIds=t.interruptIds?.map(n=>n)||[],e}};function Gv(){return{baseEvent:void 0,subagentRunId:"",message:"",code:void 0}}var Va={encode(t,e=new U){return t.baseEvent!==void 0&&M.encode(t.baseEvent,e.uint32(10).fork()).join(),t.subagentRunId!==""&&e.uint32(18).string(t.subagentRunId),t.message!==""&&e.uint32(26).string(t.message),t.code!==void 0&&e.uint32(34).string(t.code),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Gv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.baseEvent=M.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.subagentRunId=n.string();continue;case 3:if(i!==26)break;o.message=n.string();continue;case 4:if(i!==34)break;o.code=n.string();continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Va.fromPartial(t??{})},fromPartial(t){let e=Gv();return e.baseEvent=t.baseEvent!==void 0&&t.baseEvent!==null?M.fromPartial(t.baseEvent):void 0,e.subagentRunId=t.subagentRunId??"",e.message=t.message??"",e.code=t.code??void 0,e}};function Bv(){return{textMessageStart:void 0,textMessageContent:void 0,textMessageEnd:void 0,toolCallStart:void 0,toolCallArgs:void 0,toolCallEnd:void 0,stateSnapshot:void 0,stateDelta:void 0,messagesSnapshot:void 0,raw:void 0,custom:void 0,runStarted:void 0,runFinished:void 0,runError:void 0,stepStarted:void 0,stepFinished:void 0,textMessageChunk:void 0,toolCallChunk:void 0,subagentStarted:void 0,subagentFinished:void 0,subagentError:void 0,toolCallResult:void 0,activitySnapshot:void 0,activityDelta:void 0,reasoningStart:void 0,reasoningMessageStart:void 0,reasoningMessageContent:void 0,reasoningMessageEnd:void 0,reasoningMessageChunk:void 0,reasoningEnd:void 0,reasoningEncryptedValue:void 0}}var jv={encode(t,e=new U){return t.textMessageStart!==void 0&&ma.encode(t.textMessageStart,e.uint32(10).fork()).join(),t.textMessageContent!==void 0&&ga.encode(t.textMessageContent,e.uint32(18).fork()).join(),t.textMessageEnd!==void 0&&va.encode(t.textMessageEnd,e.uint32(26).fork()).join(),t.toolCallStart!==void 0&&ya.encode(t.toolCallStart,e.uint32(34).fork()).join(),t.toolCallArgs!==void 0&&wa.encode(t.toolCallArgs,e.uint32(42).fork()).join(),t.toolCallEnd!==void 0&&Ea.encode(t.toolCallEnd,e.uint32(50).fork()).join(),t.stateSnapshot!==void 0&&Sa.encode(t.stateSnapshot,e.uint32(58).fork()).join(),t.stateDelta!==void 0&&Ta.encode(t.stateDelta,e.uint32(66).fork()).join(),t.messagesSnapshot!==void 0&&Aa.encode(t.messagesSnapshot,e.uint32(74).fork()).join(),t.raw!==void 0&&Ra.encode(t.raw,e.uint32(82).fork()).join(),t.custom!==void 0&&Ca.encode(t.custom,e.uint32(90).fork()).join(),t.runStarted!==void 0&&Na.encode(t.runStarted,e.uint32(98).fork()).join(),t.runFinished!==void 0&&Oa.encode(t.runFinished,e.uint32(106).fork()).join(),t.runError!==void 0&&Pa.encode(t.runError,e.uint32(114).fork()).join(),t.stepStarted!==void 0&&Ma.encode(t.stepStarted,e.uint32(122).fork()).join(),t.stepFinished!==void 0&&La.encode(t.stepFinished,e.uint32(130).fork()).join(),t.textMessageChunk!==void 0&&ba.encode(t.textMessageChunk,e.uint32(138).fork()).join(),t.toolCallChunk!==void 0&&xa.encode(t.toolCallChunk,e.uint32(146).fork()).join(),t.subagentStarted!==void 0&&Ba.encode(t.subagentStarted,e.uint32(154).fork()).join(),t.subagentFinished!==void 0&&Za.encode(t.subagentFinished,e.uint32(162).fork()).join(),t.subagentError!==void 0&&Va.encode(t.subagentError,e.uint32(170).fork()).join(),t.toolCallResult!==void 0&&_a.encode(t.toolCallResult,e.uint32(178).fork()).join(),t.activitySnapshot!==void 0&&ka.encode(t.activitySnapshot,e.uint32(186).fork()).join(),t.activityDelta!==void 0&&Ia.encode(t.activityDelta,e.uint32(194).fork()).join(),t.reasoningStart!==void 0&&za.encode(t.reasoningStart,e.uint32(202).fork()).join(),t.reasoningMessageStart!==void 0&&Da.encode(t.reasoningMessageStart,e.uint32(210).fork()).join(),t.reasoningMessageContent!==void 0&&$a.encode(t.reasoningMessageContent,e.uint32(218).fork()).join(),t.reasoningMessageEnd!==void 0&&Ua.encode(t.reasoningMessageEnd,e.uint32(226).fork()).join(),t.reasoningMessageChunk!==void 0&&Ha.encode(t.reasoningMessageChunk,e.uint32(234).fork()).join(),t.reasoningEnd!==void 0&&Fa.encode(t.reasoningEnd,e.uint32(242).fork()).join(),t.reasoningEncryptedValue!==void 0&&Ga.encode(t.reasoningEncryptedValue,e.uint32(250).fork()).join(),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Bv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.textMessageStart=ma.decode(n,n.uint32());continue;case 2:if(i!==18)break;o.textMessageContent=ga.decode(n,n.uint32());continue;case 3:if(i!==26)break;o.textMessageEnd=va.decode(n,n.uint32());continue;case 4:if(i!==34)break;o.toolCallStart=ya.decode(n,n.uint32());continue;case 5:if(i!==42)break;o.toolCallArgs=wa.decode(n,n.uint32());continue;case 6:if(i!==50)break;o.toolCallEnd=Ea.decode(n,n.uint32());continue;case 7:if(i!==58)break;o.stateSnapshot=Sa.decode(n,n.uint32());continue;case 8:if(i!==66)break;o.stateDelta=Ta.decode(n,n.uint32());continue;case 9:if(i!==74)break;o.messagesSnapshot=Aa.decode(n,n.uint32());continue;case 10:if(i!==82)break;o.raw=Ra.decode(n,n.uint32());continue;case 11:if(i!==90)break;o.custom=Ca.decode(n,n.uint32());continue;case 12:if(i!==98)break;o.runStarted=Na.decode(n,n.uint32());continue;case 13:if(i!==106)break;o.runFinished=Oa.decode(n,n.uint32());continue;case 14:if(i!==114)break;o.runError=Pa.decode(n,n.uint32());continue;case 15:if(i!==122)break;o.stepStarted=Ma.decode(n,n.uint32());continue;case 16:if(i!==130)break;o.stepFinished=La.decode(n,n.uint32());continue;case 17:if(i!==138)break;o.textMessageChunk=ba.decode(n,n.uint32());continue;case 18:if(i!==146)break;o.toolCallChunk=xa.decode(n,n.uint32());continue;case 19:if(i!==154)break;o.subagentStarted=Ba.decode(n,n.uint32());continue;case 20:if(i!==162)break;o.subagentFinished=Za.decode(n,n.uint32());continue;case 21:if(i!==170)break;o.subagentError=Va.decode(n,n.uint32());continue;case 22:if(i!==178)break;o.toolCallResult=_a.decode(n,n.uint32());continue;case 23:if(i!==186)break;o.activitySnapshot=ka.decode(n,n.uint32());continue;case 24:if(i!==194)break;o.activityDelta=Ia.decode(n,n.uint32());continue;case 25:if(i!==202)break;o.reasoningStart=za.decode(n,n.uint32());continue;case 26:if(i!==210)break;o.reasoningMessageStart=Da.decode(n,n.uint32());continue;case 27:if(i!==218)break;o.reasoningMessageContent=$a.decode(n,n.uint32());continue;case 28:if(i!==226)break;o.reasoningMessageEnd=Ua.decode(n,n.uint32());continue;case 29:if(i!==234)break;o.reasoningMessageChunk=Ha.decode(n,n.uint32());continue;case 30:if(i!==242)break;o.reasoningEnd=Fa.decode(n,n.uint32());continue;case 31:if(i!==250)break;o.reasoningEncryptedValue=Ga.decode(n,n.uint32());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return jv.fromPartial(t??{})},fromPartial(t){let e=Bv();return e.textMessageStart=t.textMessageStart!==void 0&&t.textMessageStart!==null?ma.fromPartial(t.textMessageStart):void 0,e.textMessageContent=t.textMessageContent!==void 0&&t.textMessageContent!==null?ga.fromPartial(t.textMessageContent):void 0,e.textMessageEnd=t.textMessageEnd!==void 0&&t.textMessageEnd!==null?va.fromPartial(t.textMessageEnd):void 0,e.toolCallStart=t.toolCallStart!==void 0&&t.toolCallStart!==null?ya.fromPartial(t.toolCallStart):void 0,e.toolCallArgs=t.toolCallArgs!==void 0&&t.toolCallArgs!==null?wa.fromPartial(t.toolCallArgs):void 0,e.toolCallEnd=t.toolCallEnd!==void 0&&t.toolCallEnd!==null?Ea.fromPartial(t.toolCallEnd):void 0,e.stateSnapshot=t.stateSnapshot!==void 0&&t.stateSnapshot!==null?Sa.fromPartial(t.stateSnapshot):void 0,e.stateDelta=t.stateDelta!==void 0&&t.stateDelta!==null?Ta.fromPartial(t.stateDelta):void 0,e.messagesSnapshot=t.messagesSnapshot!==void 0&&t.messagesSnapshot!==null?Aa.fromPartial(t.messagesSnapshot):void 0,e.raw=t.raw!==void 0&&t.raw!==null?Ra.fromPartial(t.raw):void 0,e.custom=t.custom!==void 0&&t.custom!==null?Ca.fromPartial(t.custom):void 0,e.runStarted=t.runStarted!==void 0&&t.runStarted!==null?Na.fromPartial(t.runStarted):void 0,e.runFinished=t.runFinished!==void 0&&t.runFinished!==null?Oa.fromPartial(t.runFinished):void 0,e.runError=t.runError!==void 0&&t.runError!==null?Pa.fromPartial(t.runError):void 0,e.stepStarted=t.stepStarted!==void 0&&t.stepStarted!==null?Ma.fromPartial(t.stepStarted):void 0,e.stepFinished=t.stepFinished!==void 0&&t.stepFinished!==null?La.fromPartial(t.stepFinished):void 0,e.textMessageChunk=t.textMessageChunk!==void 0&&t.textMessageChunk!==null?ba.fromPartial(t.textMessageChunk):void 0,e.toolCallChunk=t.toolCallChunk!==void 0&&t.toolCallChunk!==null?xa.fromPartial(t.toolCallChunk):void 0,e.subagentStarted=t.subagentStarted!==void 0&&t.subagentStarted!==null?Ba.fromPartial(t.subagentStarted):void 0,e.subagentFinished=t.subagentFinished!==void 0&&t.subagentFinished!==null?Za.fromPartial(t.subagentFinished):void 0,e.subagentError=t.subagentError!==void 0&&t.subagentError!==null?Va.fromPartial(t.subagentError):void 0,e.toolCallResult=t.toolCallResult!==void 0&&t.toolCallResult!==null?_a.fromPartial(t.toolCallResult):void 0,e.activitySnapshot=t.activitySnapshot!==void 0&&t.activitySnapshot!==null?ka.fromPartial(t.activitySnapshot):void 0,e.activityDelta=t.activityDelta!==void 0&&t.activityDelta!==null?Ia.fromPartial(t.activityDelta):void 0,e.reasoningStart=t.reasoningStart!==void 0&&t.reasoningStart!==null?za.fromPartial(t.reasoningStart):void 0,e.reasoningMessageStart=t.reasoningMessageStart!==void 0&&t.reasoningMessageStart!==null?Da.fromPartial(t.reasoningMessageStart):void 0,e.reasoningMessageContent=t.reasoningMessageContent!==void 0&&t.reasoningMessageContent!==null?$a.fromPartial(t.reasoningMessageContent):void 0,e.reasoningMessageEnd=t.reasoningMessageEnd!==void 0&&t.reasoningMessageEnd!==null?Ua.fromPartial(t.reasoningMessageEnd):void 0,e.reasoningMessageChunk=t.reasoningMessageChunk!==void 0&&t.reasoningMessageChunk!==null?Ha.fromPartial(t.reasoningMessageChunk):void 0,e.reasoningEnd=t.reasoningEnd!==void 0&&t.reasoningEnd!==null?Fa.fromPartial(t.reasoningEnd):void 0,e.reasoningEncryptedValue=t.reasoningEncryptedValue!==void 0&&t.reasoningEncryptedValue!==null?Ga.fromPartial(t.reasoningEncryptedValue):void 0,e}};function Zv(){return{provider:void 0,model:void 0,inputTokens:void 0,outputTokens:void 0,totalTokens:void 0,reasoningTokens:void 0,cachedInputTokens:void 0,cacheWriteInputTokens:void 0}}var Sn={encode(t,e=new U){return t.provider!==void 0&&e.uint32(10).string(t.provider),t.model!==void 0&&e.uint32(18).string(t.model),t.inputTokens!==void 0&&e.uint32(24).int64(t.inputTokens),t.outputTokens!==void 0&&e.uint32(32).int64(t.outputTokens),t.totalTokens!==void 0&&e.uint32(40).int64(t.totalTokens),t.reasoningTokens!==void 0&&e.uint32(48).int64(t.reasoningTokens),t.cachedInputTokens!==void 0&&e.uint32(56).int64(t.cachedInputTokens),t.cacheWriteInputTokens!==void 0&&e.uint32(64).int64(t.cacheWriteInputTokens),e},decode(t,e){let n=t instanceof R?t:new R(t),r=e===void 0?n.len:n.pos+e,o=Zv();for(;n.pos<r;){let i=n.uint32();switch(i>>>3){case 1:if(i!==10)break;o.provider=n.string();continue;case 2:if(i!==18)break;o.model=n.string();continue;case 3:if(i!==24)break;o.inputTokens=yn(n.int64());continue;case 4:if(i!==32)break;o.outputTokens=yn(n.int64());continue;case 5:if(i!==40)break;o.totalTokens=yn(n.int64());continue;case 6:if(i!==48)break;o.reasoningTokens=yn(n.int64());continue;case 7:if(i!==56)break;o.cachedInputTokens=yn(n.int64());continue;case 8:if(i!==64)break;o.cacheWriteInputTokens=yn(n.int64());continue}if((i&7)===4||i===0)break;n.skip(i&7)}return o},create(t){return Sn.fromPartial(t??{})},fromPartial(t){let e=Zv();return e.provider=t.provider??void 0,e.model=t.model??void 0,e.inputTokens=t.inputTokens??void 0,e.outputTokens=t.outputTokens??void 0,e.totalTokens=t.totalTokens??void 0,e.reasoningTokens=t.reasoningTokens??void 0,e.cachedInputTokens=t.cachedInputTokens??void 0,e.cacheWriteInputTokens=t.cacheWriteInputTokens??void 0,e}};function yn(t){let e=globalThis.Number(t.toString());if(e>globalThis.Number.MAX_SAFE_INTEGER)throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");if(e<globalThis.Number.MIN_SAFE_INTEGER)throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");return e}var cr=t=>t&&typeof t=="object"?t:void 0,he=t=>Array.isArray(t)?t:[],Y0=()=>typeof process<"u"&&typeof process.env<"u"&&!!process.env.SUPPRESS_TRANSFORMATION_WARNINGS,Wv=()=>{Y0()||console.warn("[ag-ui][proto] Dropped a content part this build does not know: the protocol has a variant this SDK predates.")};var lz=new Set(Object.values(v)),K0={textMessageStart:"TEXT_MESSAGE_START",textMessageContent:"TEXT_MESSAGE_CONTENT",textMessageEnd:"TEXT_MESSAGE_END",textMessageChunk:"TEXT_MESSAGE_CHUNK",toolCallStart:"TOOL_CALL_START",toolCallArgs:"TOOL_CALL_ARGS",toolCallEnd:"TOOL_CALL_END",toolCallChunk:"TOOL_CALL_CHUNK",toolCallResult:"TOOL_CALL_RESULT",stateSnapshot:"STATE_SNAPSHOT",stateDelta:"STATE_DELTA",messagesSnapshot:"MESSAGES_SNAPSHOT",activitySnapshot:"ACTIVITY_SNAPSHOT",activityDelta:"ACTIVITY_DELTA",raw:"RAW",custom:"CUSTOM",runStarted:"RUN_STARTED",runFinished:"RUN_FINISHED",runError:"RUN_ERROR",stepStarted:"STEP_STARTED",stepFinished:"STEP_FINISHED",reasoningStart:"REASONING_START",reasoningMessageStart:"REASONING_MESSAGE_START",reasoningMessageContent:"REASONING_MESSAGE_CONTENT",reasoningMessageEnd:"REASONING_MESSAGE_END",reasoningMessageChunk:"REASONING_MESSAGE_CHUNK",reasoningEnd:"REASONING_END",reasoningEncryptedValue:"REASONING_ENCRYPTED_VALUE",subagentStarted:"SUBAGENT_STARTED",subagentFinished:"SUBAGENT_FINISHED",subagentError:"SUBAGENT_ERROR"},wn=new Set([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]);var jt=t=>{let e=cr(t);if(e){if([e.data,e.url,e.file].filter(Boolean).length>1)throw new Error("Invalid event: source carries more than one arm");if(e.data){let n=e.data;return{type:"data",value:n.value,mimeType:n.mimeType}}if(e.url){let n=e.url;return{type:"url",value:n.value,mimeType:n.mimeType}}if(e.file){let n=e.file;return{type:"file",value:n.value,provider:n.provider,mimeType:n.mimeType}}}};var qv=t=>{let e=cr(t);if(e){if([e.text,e.image,e.audio,e.video,e.document].filter(Boolean).length>1)throw new Error("Invalid event: content part carries more than one arm");if(e.text){let n=e.text;return{type:"text",id:n.id,text:n.text,metadata:n.metadata}}if(e.image){let n=e.image;return n.source!==void 0&&jt(n.source)===void 0?void 0:{type:"image",id:n.id,source:jt(n.source),metadata:n.metadata}}if(e.audio){let n=e.audio;return n.source!==void 0&&jt(n.source)===void 0?void 0:{type:"audio",id:n.id,source:jt(n.source),metadata:n.metadata}}if(e.video){let n=e.video;return n.source!==void 0&&jt(n.source)===void 0?void 0:{type:"video",id:n.id,source:jt(n.source),metadata:n.metadata}}if(e.document){let n=e.document;return n.source!==void 0&&jt(n.source)===void 0?void 0:{type:"document",id:n.id,source:jt(n.source),metadata:n.metadata}}}},X0=new Set(["activity"]),J0=new Set(["user","tool"]),Q0=new Set(["developer","system","assistant","user","tool","activity","reasoning"]);var Yv=t=>{let e=cr(t)??{},n={...e},r=typeof e.role=="string"?e.role:"",o=Q0.has(r),i=o?J0.has(r):he(e.contentParts).length>0,a=o?X0.has(r):!i&&e.activityContent!==void 0;if(!o&&(e.content!==void 0?1:0)+(he(e.contentParts).length>0?1:0)+(e.activityContent!==void 0?1:0)>1)throw new Error("Invalid event: message carries more than one content form");if(o){if(!i&&he(e.contentParts).length>0)throw new Error("Invalid event: message carries content parts for a role that has none");if(e.activityContent!==void 0&&!a)throw new Error("Invalid event: message carries activity content for a non-activity role");if(a&&e.content!==void 0)throw new Error("Invalid event: activity content cannot ride with other content forms");if(i&&e.content!==void 0&&he(e.contentParts).length>0)throw new Error("Invalid event: message carries both string content and content parts")}return i&&e.content===void 0&&(n.content=he(e.contentParts).map(s=>{let c=qv(s);return c===void 0&&Wv(),c}).filter(s=>s!==void 0)),a&&e.activityContent!==void 0&&(n.content=e.activityContent),delete n.activityContent,delete n.contentParts,he(e.toolCalls).length===0&&delete n.toolCalls,Object.keys(n).forEach(s=>{n[s]===void 0&&delete n[s]}),n},ku=t=>{if(Array.isArray(t)){for(let n of t)ku(n);return}let e=cr(t);if(e)for(let n of Object.keys(e))e[n]===void 0?delete e[n]:ku(e[n])};var eT=t=>{let e=cr(t);if(!e)return;let n={};return e.threadId!==void 0&&(n.threadId=e.threadId),e.runId!==void 0&&(n.runId=e.runId),e.protocolVersion!==void 0&&(n.protocolVersion=e.protocolVersion),e.parentRunId!==void 0&&(n.parentRunId=e.parentRunId),e.state!==void 0&&(n.state=e.state),n.messages=he(e.messages).map(Yv).filter(r=>r!==void 0),n.tools=he(e.tools),n.context=he(e.context),e.forwardedProps!==void 0&&(n.forwardedProps=e.forwardedProps),n.resume=he(e.resume),n};var Iu={TextMessageStartEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},BaseEvent:{singular:new Set([3,4]),descend:{},google:{3:"google.protobuf.Value",4:"google.protobuf.Struct"}},TextMessageContentEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},TextMessageEndEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ToolCallStartEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ToolCallArgsEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ToolCallEndEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},StateSnapshotEvent:{singular:new Set([1,2]),descend:{1:"BaseEvent"},google:{2:"google.protobuf.Value"}},StateDeltaEvent:{singular:new Set([1]),descend:{1:"BaseEvent",2:"JsonPatchOperation"}},JsonPatchOperation:{singular:new Set([4]),descend:{},google:{4:"google.protobuf.Value"}},MessagesSnapshotEvent:{singular:new Set([1]),descend:{1:"BaseEvent",2:"Message"}},Message:{singular:new Set([9,13]),descend:{5:"ToolCall",8:"InputContent"},google:{9:"google.protobuf.Struct",13:"google.protobuf.Struct"}},ToolCall:{singular:new Set([3,4]),descend:{},google:{4:"google.protobuf.Struct"}},InputContent:{singular:new Set([1,2,3,4,5]),descend:{1:"TextInputPart",2:"ImageInputPart",3:"AudioInputPart",4:"VideoInputPart",5:"DocumentInputPart"},arms:new Set([1,2,3,4,5])},TextInputPart:{singular:new Set([3]),descend:{},google:{3:"google.protobuf.Value"}},ImageInputPart:{singular:new Set([1,2]),descend:{1:"InputContentSource"},google:{2:"google.protobuf.Value"}},InputContentSource:{singular:new Set([1,2,3]),descend:{},arms:new Set([1,2,3])},AudioInputPart:{singular:new Set([1,2]),descend:{1:"InputContentSource"},google:{2:"google.protobuf.Value"}},VideoInputPart:{singular:new Set([1,2]),descend:{1:"InputContentSource"},google:{2:"google.protobuf.Value"}},DocumentInputPart:{singular:new Set([1,2]),descend:{1:"InputContentSource"},google:{2:"google.protobuf.Value"}},RawEvent:{singular:new Set([1,2]),descend:{1:"BaseEvent"},google:{2:"google.protobuf.Value"}},CustomEvent:{singular:new Set([1,3]),descend:{1:"BaseEvent"},google:{3:"google.protobuf.Value"}},RunStartedEvent:{singular:new Set([1,5]),descend:{1:"BaseEvent",5:"RunAgentInput"}},RunAgentInput:{singular:new Set([4,8]),descend:{5:"Message",6:"Tool",9:"ResumeEntry"},google:{4:"google.protobuf.Value",8:"google.protobuf.Value"}},Tool:{singular:new Set([3,4]),descend:{},google:{3:"google.protobuf.Value",4:"google.protobuf.Struct"}},ResumeEntry:{singular:new Set([3,4]),descend:{},google:{3:"google.protobuf.Value",4:"google.protobuf.Struct"}},RunFinishedEvent:{singular:new Set([1,4]),descend:{1:"BaseEvent",6:"Interrupt"},google:{4:"google.protobuf.Value"}},Interrupt:{singular:new Set([5,7]),descend:{},google:{5:"google.protobuf.Value",7:"google.protobuf.Value"}},RunErrorEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},StepStartedEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},StepFinishedEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},TextMessageChunkEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ToolCallChunkEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},SubagentStartedEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},SubagentFinishedEvent:{singular:new Set([1,3]),descend:{1:"BaseEvent"},google:{3:"google.protobuf.Value"}},SubagentErrorEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ToolCallResultEvent:{singular:new Set([1]),descend:{1:"BaseEvent",7:"InputContent"}},ActivitySnapshotEvent:{singular:new Set([1,5]),descend:{1:"BaseEvent"},google:{5:"google.protobuf.Struct"}},ActivityDeltaEvent:{singular:new Set([1]),descend:{1:"BaseEvent",5:"JsonPatchOperation"}},ReasoningStartEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningMessageStartEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningMessageContentEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningMessageEndEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningMessageChunkEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningEndEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},ReasoningEncryptedValueEvent:{singular:new Set([1]),descend:{1:"BaseEvent"}},"google.protobuf.Struct":{singular:new Set,descend:{1:"google.protobuf.Struct.FieldsEntry"}},"google.protobuf.Struct.FieldsEntry":{singular:new Set([2]),descend:{2:"google.protobuf.Value"}},"google.protobuf.Value":{singular:new Set([5,6]),descend:{5:"google.protobuf.Struct",6:"google.protobuf.ListValue"},arms:new Set([1,2,3,4,5,6]),armWireTypes:{1:0,2:1,3:2,4:0,5:2,6:2}},"google.protobuf.ListValue":{singular:new Set,descend:{1:"google.protobuf.Value"}}},Kv={1:"TextMessageStartEvent",2:"TextMessageContentEvent",3:"TextMessageEndEvent",4:"ToolCallStartEvent",5:"ToolCallArgsEvent",6:"ToolCallEndEvent",7:"StateSnapshotEvent",8:"StateDeltaEvent",9:"MessagesSnapshotEvent",10:"RawEvent",11:"CustomEvent",12:"RunStartedEvent",13:"RunFinishedEvent",14:"RunErrorEvent",15:"StepStartedEvent",16:"StepFinishedEvent",17:"TextMessageChunkEvent",18:"ToolCallChunkEvent",19:"SubagentStartedEvent",20:"SubagentFinishedEvent",21:"SubagentErrorEvent",22:"ToolCallResultEvent",23:"ActivitySnapshotEvent",24:"ActivityDeltaEvent",25:"ReasoningStartEvent",26:"ReasoningMessageStartEvent",27:"ReasoningMessageContentEvent",28:"ReasoningMessageEndEvent",29:"ReasoningMessageChunkEvent",30:"ReasoningEndEvent",31:"ReasoningEncryptedValueEvent"};function lr(t,e){let n=0,r=0;for(;;){if(e.offset>=t.length)throw new Error("Invalid event");let o=t[e.offset++];if(r<28?n+=(o&127)*2**r:r===28&&(n+=(o&15)*2**28),r+=7,(o&128)===0)return n}}function Xv(t,e){let n={offset:0},r=0,o=0;for(;n.offset<t.length;){let i=lr(t,n),a=Math.floor(i/8),s=i%8;if(a===0)throw new Error("Invalid event");if(s===3){r+=1;continue}if(s===4){if(r-=1,r<0)throw new Error("Invalid event");continue}if(s===0)lr(t,n);else if(s===1)n.offset+=8;else if(s===2){let c=lr(t,n);if(n.offset+c>t.length)throw new Error("Invalid event");if(r===0){if(e.arms?.has(a)){if(o!==0&&o!==a)throw new Error("Invalid event");o=a}let l=e.descend[a];if(l!==void 0){let u=Iu[l];u!==void 0&&Xv(t.subarray(n.offset,n.offset+c),u)}}n.offset+=c}else if(s===5)n.offset+=4;else throw new Error("Invalid event");if(n.offset>t.length)throw new Error("Invalid event")}if(r!==0)throw new Error("Invalid event")}function tT(t){let e=new Set,n={offset:0},r=0;for(;n.offset<t.length;){let o=lr(t,n),i=Math.floor(o/8),a=o%8;if(i===0)throw new Error("Invalid event");if(a===3){r+=1;continue}if(a===4){if(r-=1,r<0)throw new Error("Invalid event");continue}if(r===0&&wn.has(i)){if(e.size>0&&!e.has(i))throw new Error("Invalid event");e.add(i)}if(a===0)lr(t,n);else if(a===1)n.offset+=8;else if(a===2){let s=lr(t,n);if(n.offset+s>t.length)throw new Error("Invalid event");if(r===0){let c=Kv[i];if(c!==void 0){let l=Iu[c];l!==void 0&&Xv(t.subarray(n.offset,n.offset+s),l)}}n.offset+=s}else if(a===5)n.offset+=4;else throw new Error("Invalid event");if(n.offset>t.length)throw new Error("Invalid event")}if(r!==0)throw new Error("Invalid event")}function Vv(t){if(t.length===1)return t[0];let e=new Uint8Array(t.reduce((r,o)=>r+o.length,0)),n=0;for(let r of t)e.set(r,n),n+=r.length;return e}function Jv(t,e){let n=new R(t),r=[],o=new Map,i,a=!1;for(;n.pos<n.len;){let c=n.pos,[l,u]=n.tag(),f=u===2?n.bytes():void 0;f===void 0&&n.skip(u,l);let m=e.arms?.has(l)&&u===(e.armWireTypes?.[l]??2);if(m){if(i!==void 0&&i!==l){let w=o.get(i);w!==void 0&&(r[w]=void 0),o.delete(i),a=!0}if(i=l,!e.singular.has(l)){let w=o.get(l);w!==void 0&&(r[w]=void 0,o.delete(l),a=!0)}}let p=e.descend[l]??e.google?.[l],h=f!==void 0&&(e.singular.has(l)||p!==void 0),x=o.get(l),g=x===void 0?void 0:r[x]?.payloads;if(h&&e.singular.has(l)&&g!==void 0){g.push(f),a=!0;continue}(h||m)&&o.set(l,r.length),r.push({number:l,raw:t.subarray(c,n.pos),...h&&{payloads:[f]},child:p===void 0?void 0:Iu[p]})}let s=[];for(let c of r)if(c!==void 0){if(c.payloads!==void 0){let l=Vv(c.payloads),u=c.child===void 0?l:Jv(l,c.child);if(c.payloads.length>1||u!==l){s.push(new U().uint32(c.number*8+2).bytes(u).finish()),a=!0;continue}}s.push(c.raw)}return a?Vv(s):t}var Ru=class extends Error{constructor(t="Unknown event type"){super(t),this.name="AGUIUnknownEventTypeError"}};function Qv(t,e,n,r){let o=0,i=0,a=0;for(;;){if(e.offset>=t.length||a>=n)return-1;let s=t[e.offset++];if(a+=1,a===n&&s>r)return-1;if(o+=(s&127)*2**i,i+=7,(s&128)===0)return o}}var ja=(t,e)=>Qv(t,e,5,15),eb=(t,e)=>Qv(t,e,10,1);function nT(t){let e={offset:0},n=[];for(;e.offset<t.length;){let r=ja(t,e);if(r<0)return!1;let o=Math.floor(r/8),i=r%8;if(o===0)return!1;if(i===3)n.push(o);else if(i===4){if(n.pop()!==o)return!1}else if(i===0){if(eb(t,e)<0)return!1}else if(i===1)e.offset+=8;else if(i===5)e.offset+=4;else if(i===2){let a=ja(t,e);if(a<0||e.offset+a>t.length)return!1;e.offset+=a}else return!1;if(e.offset>t.length)return!1}return n.length===0}function rT(t){let e={offset:0},n=[],r=0;for(;e.offset<t.length;){let o=ja(t,e);if(o<0)return!1;let i=Math.floor(o/8),a=o%8;if(i===0)return!1;let s=n.length===0;if(a===3){if(s&&wn.has(i))return!1;n.push(i)}else if(a===4){if(n.pop()!==i)return!1}else if(a===0){if(s&&wn.has(i)||eb(t,e)<0)return!1}else if(a===1){if(s&&wn.has(i))return!1;e.offset+=8}else if(a===5){if(s&&wn.has(i))return!1;e.offset+=4}else if(a===2){let c=ja(t,e);if(c<0||e.offset+c>t.length)return!1;if(s){if(wn.has(i)||!nT(t.subarray(e.offset,e.offset+c)))return!1;r+=1}e.offset+=c}else return!1;if(e.offset>t.length)return!1}return n.length===0&&r>0}function tb(t){tT(t);let e=jv.decode(Jv(t,{singular:wn,descend:Kv})),n=Object.entries(e).filter(([,c])=>c!==void 0);if(n.length!==1)throw n.length===0&&rT(t)?new Ru:new Error("Invalid event");let r=n[0],o=K0[r[0]];if(o===void 0)throw new Error("Invalid event");let i=r[1],a=cr(i.baseEvent);if(!a)throw new Error("Invalid event");let s=q0[a.type];if(s!==o)throw new Error("Invalid event: envelope carries "+o+" but the base event declares "+String(s));if(i.type=o,i.timestamp=a.timestamp,i.rawEvent=a.rawEvent,a.metadata!==void 0&&(i.metadata=a.metadata),delete i.baseEvent,i.type==="MESSAGES_SNAPSHOT"&&Array.isArray(i.messages)&&(i.messages=i.messages.map(Yv).filter(c=>c!==void 0)),i.type==="RUN_FINISHED"){let c=i,l=typeof c.outcome=="string"&&c.outcome!==""?c.outcome:void 0,u={};u.pendingToolCallIds=c.pendingToolCallIds,delete c.pendingToolCallIds,u.interrupts=c.interrupts,delete c.interrupts,delete c.outcome,l===void 0&&(he(u.pendingToolCallIds).length>0&&(c.pendingToolCallIds=u.pendingToolCallIds),he(u.interrupts).length>0&&(c.interrupts=u.interrupts)),l==="success"&&(c.outcome={type:"success",...he(u.pendingToolCallIds).length>0?{pendingToolCallIds:u.pendingToolCallIds}:{},...he(u.interrupts).length>0?{interrupts:u.interrupts}:{}}),l==="interrupt"&&(c.outcome={type:"interrupt",interrupts:he(u.interrupts),...he(u.pendingToolCallIds).length>0?{pendingToolCallIds:u.pendingToolCallIds}:{}}),l==="cancelled"&&(c.outcome={type:"cancelled",...he(u.pendingToolCallIds).length>0?{pendingToolCallIds:u.pendingToolCallIds}:{},...he(u.interrupts).length>0?{interrupts:u.interrupts}:{}}),l!==void 0&&!["success","interrupt","cancelled"].includes(l)&&(c.outcome={type:l,...he(u.pendingToolCallIds).length>0?{pendingToolCallIds:u.pendingToolCallIds}:{},...he(u.interrupts).length>0?{interrupts:u.interrupts}:{}})}if(i.type==="SUBAGENT_FINISHED"){let c=i,l=typeof c.outcome=="string"&&c.outcome!==""?c.outcome:void 0,u={};u.interruptIds=c.interruptIds,delete c.interruptIds,delete c.outcome,l===void 0&&he(u.interruptIds).length>0&&(c.interruptIds=u.interruptIds),l==="success"&&(c.outcome={type:"success",...he(u.interruptIds).length>0?{interruptIds:u.interruptIds}:{}}),l==="suspended"&&(c.outcome={type:"suspended",...he(u.interruptIds).length>0?{interruptIds:u.interruptIds}:{}}),l!==void 0&&!["success","suspended"].includes(l)&&(c.outcome={type:l,...he(u.interruptIds).length>0?{interruptIds:u.interruptIds}:{}})}if(i.type==="STATE_DELTA"&&Array.isArray(i.delta)&&(i.delta=i.delta.map(c=>{let l=Vg[c.op];return c.op=typeof l=="string"&&l!=="UNRECOGNIZED"?l.toLowerCase():String(c.op),Object.keys(c).forEach(u=>{c[u]===void 0&&delete c[u]}),c})),i.type==="ACTIVITY_DELTA"&&Array.isArray(i.patch)&&(i.patch=i.patch.map(c=>{let l=Vg[c.op];return c.op=typeof l=="string"&&l!=="UNRECOGNIZED"?l.toLowerCase():String(c.op),Object.keys(c).forEach(u=>{c[u]===void 0&&delete c[u]}),c})),i.type==="RUN_FINISHED"&&Array.isArray(i.usage)&&i.usage.length===0&&delete i.usage,i.type==="RUN_ERROR"&&Array.isArray(i.usage)&&i.usage.length===0&&delete i.usage,i.type==="TOOL_CALL_RESULT"){let c=i;if(c.content!==void 0&&he(c.contentParts).length>0)throw new Error("Invalid event: content carries both string content and content parts");c.content===void 0&&(c.content=he(c.contentParts).map(l=>{let u=qv(l);return u===void 0&&Wv(),u}).filter(l=>l!==void 0)),delete c.contentParts}return i.type==="RUN_STARTED"&&i.input!==void 0&&(i.input=eT(i.input)),ku(i),i}var Cu="application/vnd.ag-ui.event+proto";var Nu=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,Ou=t=>{if(typeof t!="string")throw new TypeError("Invalid argument expected string");let e=t.match(Nu);if(!e)throw new Error(`Invalid argument not valid semver ('${t}' received)`);return e.shift(),e},nb=t=>t==="*"||t==="x"||t==="X",rb=t=>{let e=parseInt(t,10);return isNaN(e)?t:e},iT=(t,e)=>typeof t!=typeof e?[String(t),String(e)]:[t,e],aT=(t,e)=>{if(nb(t)||nb(e))return 0;let[n,r]=iT(rb(t),rb(e));return n>r?1:n<r?-1:0},Pu=(t,e)=>{for(let n=0;n<Math.max(t.length,e.length);n++){let r=aT(t[n]||"0",e[n]||"0");if(r!==0)return r}return 0};var Tn=(t,e)=>{let n=Ou(t),r=Ou(e),o=n.pop(),i=r.pop(),a=Pu(n,r);return a!==0?a:o&&i?Pu(o.split("."),i.split(".")):o||i?o?-1:1:0};var Mu=t=>typeof t=="string"&&/^[v\d]/.test(t)&&Nu.test(t);var ob="@ag-ui/client";function sT(t){if(!t.metadata||!Object.prototype.hasOwnProperty.call(t.metadata,ob))return;let e=t.metadata?.[ob];if(!e||typeof e!="object"||Array.isArray(e))return[];if(!Object.prototype.hasOwnProperty.call(e,"authoritativeActivityTypes"))return;let n=e.authoritativeActivityTypes;return n===null?null:Array.isArray(n)&&n.every(r=>typeof r=="string")?n:[]}var ne=t=>{if(typeof structuredClone=="function")return structuredClone(t);try{return JSON.parse(JSON.stringify(t))}catch{return Array.isArray(t)?[...t]:{...t}}};function Se(){return Ft()}function lT(t){return t instanceof TypeError?/read[- ]?only|not extensible|cannot add property|cannot delete property|can't be deleted|unable to delete property|object is frozen|is not writable/i.test(t.message):!1}function Vu(t){if(Object.freeze(t),typeof t=="object"&&t)for(let e of Object.values(t))typeof e=="object"&&e&&!Object.isFrozen(e)&&Vu(e);return t}var ib=512*1024;function ab(t,e,n){let r=0,o=[t,e],i=new WeakSet;for(;o.length>0;){let a=o.pop();if(typeof a=="string"){if(r+=a.length,r>n)return!0}else if(typeof a=="object"&&a){if(i.has(a))continue;if(i.add(a),Array.isArray(a))for(let s=0;s<a.length;s++)o.push(a[s]);else{let s=Object.keys(a);for(let c=0;c<s.length;c++){let l=s[c];if(r+=l.length,r>n)return!0;o.push(a[l])}}}}return!1}async function ae(t,e,n,r){let o=typeof process<"u"&&process.env!==void 0,i=o&&!!process.env.VITEST_WORKER_ID,a=o&&!!process.env.VITEST_WORKER_ID,s=a&&!ab(e,n,ib),c=s?ne(e):e,l=s?ne(n):n,u=!1,f=!1,m;for(let p of t)try{s&&(Vu(c),Vu(l));let h=await r(p,c,l);if(h===void 0)continue;let x=!1;if(h.messages!==void 0&&h.messages!==c&&(c=ne(h.messages),u=!0,x=!0),h.state!==void 0&&h.state!==l&&(l=ne(h.state),f=!0,x=!0),s&&x&&ab(c,l,ib)&&(s=!1),m=h.stopPropagation,m===!0)break}catch(h){if(i&&h instanceof TypeError)throw h;s&&a&&lT(h)?console.error("AG-UI: Subscriber attempted to mutate frozen inputs in-place. Return mutations via AgentStateMutation instead of mutating directly.",h):console.error("Subscriber error:",h);continue}return{...u?{messages:Object.isFrozen(c)?ne(c):c}:{},...f?{state:Object.isFrozen(l)?ne(l):l}:{},...m===void 0?{}:{stopPropagation:m}}}function Ya(t){if(!t)return{enabled:!1,events:!1,lifecycle:!1,verbose:!1};if(t===!0)return{enabled:!0,events:!0,lifecycle:!0,verbose:!0};let e=t.events??!0,n=t.lifecycle??!0,r=t.verbose??!1;return{enabled:e||n,events:e,lifecycle:n,verbose:r}}function kn(t){if(t instanceof ju)return t;if(t===!0)return new ju(Ya(!0))}var ju=class{constructor(t){this.config=t}event(t,e,n,r){this.config.events&&(this.config.verbose?console.debug(`[${t}] ${e}`,typeof n=="string"?n:JSON.stringify(n)):console.debug(`[${t}] ${e}`,r??n))}lifecycle(t,e,n){this.config.lifecycle&&(n?console.debug(`[${t}] ${e}`,n):console.debug(`[${t}] ${e}`))}get eventsEnabled(){return this.config.events}get lifecycleEnabled(){return this.config.lifecycle}get enabled(){return this.config.enabled}};function Lu(t){return t.enabled?new ju(t):void 0}function cT(t,e,n){if(e){let o=t.find(a=>a.id===e);if(o?.role==="assistant")return o;o&&console.warn(`TOOL_CALL_START: parentMessageId '${e}' matches a '${o.role}' message, not assistant \u2014 falling back to toolCallId`);let i={id:o?n:e,role:"assistant",toolCalls:[]};return t.push(i),i}let r={id:n,role:"assistant",toolCalls:[]};return t.push(r),r}function Qe(t,e){return!t||e.metadata===void 0?!1:(t.metadata=eh(t.metadata,ne(e.metadata)),!0)}var _b=(t,e,n,r,o)=>{let i=kn(o),a=ne(n.messages),s=ne(t.state),c={},l=[],u=new Set,f=h=>{let x=h.outcome?.type==="success"?h.outcome.pendingToolCallIds:void 0;return x!==void 0&&x.length>0?[...x]:l.filter(g=>!u.has(g))},m=h=>{h.messages!==void 0&&(a=h.messages,c.messages=h.messages),h.state!==void 0&&(s=h.state,c.state=h.state)},p=()=>{let h=ne(c);return c={},h.messages!==void 0||h.state!==void 0?ue(h):pn};return e.pipe(Ri(async h=>{let x=await ae(r,a,s,(g,w,b)=>g.onEvent?.({event:h,agent:n,input:t,messages:w,state:b}));if(m(x),x.stopPropagation===!0?i?.event("APPLY","Event dropped:",h,{type:h.type,reason:"stopPropagation by subscriber"}):i?.event("APPLY","Event applied:",h,{type:h.type,subscribers:r.length}),x.stopPropagation===!0)return p();switch(h.type){case v.TEXT_MESSAGE_START:{let g=await ae(r,a,s,(w,b,k)=>w.onTextMessageStartEvent?.({event:h,messages:b,state:k,agent:n,input:t}));if(m(g),g.stopPropagation!==!0){let{messageId:w,role:b="assistant",name:k,subagentRunId:O}=h,E=a.find(I=>I.id===w);if(E?.role==="activity")return console.warn(`TEXT_MESSAGE_START: Message '${w}' is an activity message \u2014 message ids must be unique across activity and text messages`),p();let S=E;if(!S){let I={id:w,role:b,content:"",...k!==void 0&&{name:k},...O!=null&&{subagentRunId:O}};a.push(I),S=I}let _=Qe(S,h);(!E||_)&&m({messages:a})}return p()}case v.TEXT_MESSAGE_CONTENT:{let{messageId:g,delta:w}=h,b=a.find(O=>O.id===g);if(!b)return console.warn(`TEXT_MESSAGE_CONTENT: No message found with ID '${g}'`),p();if(b.role==="activity")return console.warn(`TEXT_MESSAGE_CONTENT: Message '${g}' is an activity message \u2014 message ids must be unique across activity and text messages`),p();let k=await ae(r,a,s,(O,E,S)=>O.onTextMessageContentEvent?.({event:h,messages:E,state:S,agent:n,input:t,textMessageBuffer:typeof b.content=="string"?b.content:""}));return m(k),k.stopPropagation!==!0&&(b.content=`${typeof b.content=="string"?b.content:""}${w}`,Qe(b,h),m({messages:a})),p()}case v.TEXT_MESSAGE_END:{let{messageId:g}=h,w=a.find(k=>k.id===g);if(!w)return console.warn(`TEXT_MESSAGE_END: No message found with ID '${g}'`),p();if(w.role==="activity")return console.warn(`TEXT_MESSAGE_END: Message '${g}' is an activity message \u2014 message ids must be unique across activity and text messages`),p();let b=await ae(r,a,s,(k,O,E)=>k.onTextMessageEndEvent?.({event:h,messages:O,state:E,agent:n,input:t,textMessageBuffer:typeof w.content=="string"?w.content:""}));return m(b),b.stopPropagation!==!0&&Qe(w,h)&&m({messages:a}),await Promise.all(r.map(k=>{k.onNewMessage?.({message:w,messages:a,state:s,agent:n,input:t})})),p()}case v.TOOL_CALL_START:{let g=await ae(r,a,s,(w,b,k)=>w.onToolCallStartEvent?.({event:h,messages:b,state:k,agent:n,input:t}));if(m(g),g.stopPropagation!==!0){let{toolCallId:w,toolCallName:b,parentMessageId:k,subagentRunId:O}=h;l.includes(w)||l.push(w);let E=a.find(L=>L.toolCalls?.some(Y=>Y.id===w))?.toolCalls?.find(L=>L.id===w);if(E){let L=E.function.name!==b;return L&&(console.warn(`TOOL_CALL_START: tool call '${w}' already exists with name '${E.function.name}' \u2014 updating it to '${b}'`),E.function.name=b),(Qe(E,h)||L)&&m({messages:a}),p()}let S=new Set(a.map(L=>L.id)),_=cT(a,k,w);!S.has(_.id)&&O!=null&&_.subagentRunId===void 0&&(_.subagentRunId=O),_.toolCalls??=[];let I={id:w,type:"function",function:{name:b,arguments:""}};_.toolCalls.push(I),Qe(I,h),m({messages:a})}return p()}case v.TOOL_CALL_ARGS:{let{toolCallId:g,delta:w}=h,b=a.find(E=>E.toolCalls?.some(S=>S.id===g));if(!b)return console.warn(`TOOL_CALL_ARGS: No message found containing tool call with ID '${g}'`),p();let k=b.toolCalls?.find(E=>E.id===g);if(!k)return console.warn(`TOOL_CALL_ARGS: No tool call found with ID '${g}'`),p();let O=await ae(r,a,s,(E,S,_)=>{let I=k.function.arguments,L=k.function.name,Y={};try{Y=Oi(I)}catch{}return E.onToolCallArgsEvent?.({event:h,messages:S,state:_,agent:n,input:t,toolCallBuffer:I,toolCallName:L,partialToolCallArgs:Y})});return m(O),O.stopPropagation!==!0&&(k.function.arguments+=w,Qe(k,h),m({messages:a})),p()}case v.TOOL_CALL_END:{let{toolCallId:g}=h,w=a.find(O=>O.toolCalls?.some(E=>E.id===g));if(!w)return console.warn(`TOOL_CALL_END: No message found containing tool call with ID '${g}'`),p();let b=w.toolCalls?.find(O=>O.id===g);if(!b)return console.warn(`TOOL_CALL_END: No tool call found with ID '${g}'`),p();let k=await ae(r,a,s,(O,E,S)=>{let _=b.function.arguments,I=b.function.name,L={};try{L=JSON.parse(_)}catch{}return O.onToolCallEndEvent?.({event:h,messages:E,state:S,agent:n,input:t,toolCallName:I,toolCallArgs:L})});return m(k),k.stopPropagation!==!0&&Qe(b,h)&&m({messages:a}),await Promise.all(r.map(O=>{O.onNewToolCall?.({toolCall:b,messages:a,state:s,agent:n,input:t})})),p()}case v.TOOL_CALL_RESULT:{let g=await ae(r,a,s,(w,b,k)=>w.onToolCallResultEvent?.({event:h,messages:b,state:k,agent:n,input:t}));if(m(g),g.stopPropagation!==!0){let{messageId:w,toolCallId:b,content:k,role:O,subagentRunId:E}=h;u.add(b);let S=a.findIndex(I=>I.id===w&&I.role==="tool"&&I.toolCallId===b),_={...S===-1?{}:a[S],id:w,toolCallId:b,role:O||"tool",content:k,...E!=null&&{subagentRunId:E}};if(E??delete _.subagentRunId,Qe(_,h),S!==-1)a[S]=_;else{let I=a.findIndex(L=>L.role==="assistant"&&L.toolCalls?.some(Y=>Y.id===b));if(I===-1)a.push(_);else{let L=I+1;for(;L<a.length&&a[L].role==="tool";)L++;a.splice(L,0,_)}await Promise.all(r.map(L=>{L.onNewMessage?.({message:_,messages:a,state:s,agent:n,input:t})}))}m({messages:a})}return p()}case v.STATE_SNAPSHOT:{let g=await ae(r,a,s,(w,b,k)=>w.onStateSnapshotEvent?.({event:h,messages:b,state:k,agent:n,input:t}));if(m(g),g.stopPropagation!==!0){let{snapshot:w}=h;s=w,m({state:s})}return p()}case v.STATE_DELTA:{let g=await ae(r,a,s,(w,b,k)=>w.onStateDeltaEvent?.({event:h,messages:b,state:k,agent:n,input:t}));if(m(g),g.stopPropagation!==!0){let{delta:w}=h;try{s=ai.applyPatch(s,w,!0,!1).newDocument,m({state:s})}catch(b){let k=b instanceof Error?b.message:String(b);console.warn(`Failed to apply state patch:
|
|
31
31
|
Current state: ${JSON.stringify(s,null,2)}
|
|
32
|
-
Patch operations: ${JSON.stringify(
|
|
33
|
-
Error: ${k}`)}}return p()}case v.MESSAGES_SNAPSHOT:{let g=await ie(r,a,s,(_,b,k)=>_.onMessagesSnapshotEvent?.({event:h,messages:b,state:k,agent:n,input:e}));if(m(g),g.stopPropagation!==!0){let{messages:_}=h,b=_.map(z=>{if(z.subagentRunId!==null)return z;let Y={...z};return delete Y.subagentRunId,Y}),k=new Map(b.map(z=>[z.id,z])),O=Y0(h),w=b.some(z=>z.role==="activity"),S=b.some(z=>z.role==="reasoning"),x=z=>z.role==="activity"&&(O?!O.includes(z.activityType):O!==null&&!w)||z.role==="reasoning"&&!S;a=a.filter(z=>k.has(z.id)||x(z)).map(z=>k.get(z.id)??z);let I=new Set(a.map(z=>z.id));for(let z of b)I.has(z.id)||a.push(z);m({messages:a})}return p()}case v.ACTIVITY_SNAPSHOT:{let g=h,_=a.findIndex(S=>S.id===g.messageId),b=_>=0?a[_]:void 0,k=b?.role==="activity"?b:void 0,O=g.replace??!0,w=await ie(r,a,s,(S,x,I)=>S.onActivitySnapshotEvent?.({event:g,messages:x,state:I,agent:n,input:e,activityMessage:k,existingMessage:b}));if(m(w),w.stopPropagation!==!0){let S={id:g.messageId,role:"activity",activityType:g.activityType,content:ne(g.content),...g.subagentRunId!=null&&{subagentRunId:g.subagentRunId}},x,I;_===-1?(a.push(S),x=S,I=S):k?(O&&(a[_]={...k,activityType:g.activityType,content:ne(g.content),subagentRunId:g.subagentRunId},g.subagentRunId??delete a[_].subagentRunId),I=a[_]):O&&(a[_]=S,x=S,I=S),Je(I,g),m({messages:a}),x&&await Promise.all(r.map(z=>z.onNewMessage?.({message:x,messages:a,state:s,agent:n,input:e})))}return p()}case v.ACTIVITY_DELTA:{let g=h,_=a.findIndex(w=>w.id===g.messageId);if(_===-1)return p();let b=a[_];if(b.role!=="activity")return console.warn(`ACTIVITY_DELTA: Message '${g.messageId}' is not an activity message`),p();let k=b,O=await ie(r,a,s,(w,S,x)=>w.onActivityDeltaEvent?.({event:g,messages:S,state:x,agent:n,input:e,activityMessage:k}));if(m(O),O.stopPropagation!==!0)try{Je(k,g)&&m({messages:a});let w=ne(k.content??{}),S=ni.applyPatch(w,g.patch??[],!0,!1).newDocument;a[_]={...k,content:ne(S),activityType:g.activityType},m({messages:a})}catch(w){let S=w instanceof Error?w.message:String(w);console.warn(`Failed to apply activity patch for '${g.messageId}': ${S}`)}return p()}case v.RAW:return m(await ie(r,a,s,(g,_,b)=>g.onRawEvent?.({event:h,messages:_,state:b,agent:n,input:e}))),p();case v.CUSTOM:return m(await ie(r,a,s,(g,_,b)=>g.onCustomEvent?.({event:h,messages:_,state:b,agent:n,input:e}))),p();case v.RUN_STARTED:{let g=await ie(r,a,s,(_,b,k)=>_.onRunStartedEvent?.({event:h,messages:b,state:k,agent:n,input:e}));if(m(g),c=[],u=new Set,g.stopPropagation!==!0){let _=h;if(_.input?.messages){for(let b of _.input.messages){let k=b;if(b.subagentRunId===null){let O={...b};delete O.subagentRunId,k=O}a.find(O=>O.id===k.id)||a.push(k)}m({messages:a})}}return p()}case v.RUN_FINISHED:{let g=h,_=g.outcome?.type==="interrupt"?{event:g,outcome:"interrupt",interrupts:g.outcome.interrupts}:g.outcome?.type==="cancelled"?{event:g,outcome:"cancelled"}:{event:g,outcome:"success",result:g.result,pendingToolCallIds:f(g)},b=await ie(r,a,s,(k,O,w)=>k.onRunFinishedEvent?.({..._,messages:O,state:w,agent:n,input:e}));return m(b),b.stopPropagation!==!0&&(n.pendingInterrupts=_.outcome==="interrupt"?_.interrupts.map(k=>{if(k.subagentRunId!==null)return k;let O={...k};return delete O.subagentRunId,O}):[]),p()}case v.RUN_ERROR:return m(await ie(r,a,s,(g,_,b)=>g.onRunErrorEvent?.({event:h,messages:_,state:b,agent:n,input:e}))),p();case v.STEP_STARTED:return m(await ie(r,a,s,(g,_,b)=>g.onStepStartedEvent?.({event:h,messages:_,state:b,agent:n,input:e}))),p();case v.STEP_FINISHED:return m(await ie(r,a,s,(g,_,b)=>g.onStepFinishedEvent?.({event:h,messages:_,state:b,agent:n,input:e}))),p();case v.TEXT_MESSAGE_CHUNK:throw Error("TEXT_MESSAGE_CHUNK must be transformed before being applied");case v.TOOL_CALL_CHUNK:throw Error("TOOL_CALL_CHUNK must be transformed before being applied");case v.REASONING_START:return m(await ie(r,a,s,(g,_,b)=>g.onReasoningStartEvent?.({event:h,messages:_,state:b,agent:n,input:e}))),p();case v.REASONING_MESSAGE_START:{let g=await ie(r,a,s,(_,b,k)=>_.onReasoningMessageStartEvent?.({event:h,messages:b,state:k,agent:n,input:e}));if(m(g),g.stopPropagation!==!0){let{messageId:_,subagentRunId:b}=h,k=a.find(S=>S.id===_);if(k?.role==="activity")return console.warn(`REASONING_MESSAGE_START: Message '${_}' is an activity message \u2014 message ids must be unique across activity and reasoning messages`),p();let O=k;if(!O){let S={id:_,role:"reasoning",content:"",...b!=null&&{subagentRunId:b}};a.push(S),O=S}let w=Je(O,h);(!k||w)&&m({messages:a})}return p()}case v.REASONING_MESSAGE_CONTENT:{let{messageId:g,delta:_}=h,b=a.find(O=>O.id===g);if(!b)return console.warn(`REASONING_MESSAGE_CONTENT: No message found with ID '${g}'`),p();if(b.role==="activity")return console.warn(`REASONING_MESSAGE_CONTENT: Message '${g}' is an activity message \u2014 message ids must be unique across activity and reasoning messages`),p();let k=await ie(r,a,s,(O,w,S)=>O.onReasoningMessageContentEvent?.({event:h,messages:w,state:S,agent:n,input:e,reasoningMessageBuffer:typeof b.content=="string"?b.content:""}));return m(k),k.stopPropagation!==!0&&(b.content=`${typeof b.content=="string"?b.content:""}${_}`,Je(b,h),m({messages:a})),p()}case v.REASONING_MESSAGE_END:{let{messageId:g}=h,_=a.find(k=>k.id===g);if(!_)return console.warn(`REASONING_MESSAGE_END: No message found with ID '${g}'`),p();if(_.role==="activity")return console.warn(`REASONING_MESSAGE_END: Message '${g}' is an activity message \u2014 message ids must be unique across activity and reasoning messages`),p();let b=await ie(r,a,s,(k,O,w)=>k.onReasoningMessageEndEvent?.({event:h,messages:O,state:w,agent:n,input:e,reasoningMessageBuffer:typeof _.content=="string"?_.content:""}));return m(b),b.stopPropagation!==!0&&Je(_,h)&&m({messages:a}),await Promise.all(r.map(k=>{k.onNewMessage?.({message:_,messages:a,state:s,agent:n,input:e})})),p()}case v.REASONING_MESSAGE_CHUNK:throw Error("REASONING_MESSAGE_CHUNK must be transformed before being applied");case v.REASONING_END:return m(await ie(r,a,s,(g,_,b)=>g.onReasoningEndEvent?.({event:h,messages:_,state:b,agent:n,input:e}))),p();case v.REASONING_ENCRYPTED_VALUE:{let{subtype:g,entityId:_,encryptedValue:b}=h,k=await ie(r,a,s,(O,w,S)=>O.onReasoningEncryptedValueEvent?.({event:h,messages:w,state:S,agent:n,input:e}));if(m(k),k.stopPropagation!==!0){let O=!1;if(g==="tool-call"){for(let w of a)if(w.role==="assistant"&&w.toolCalls){let S=w.toolCalls.find(x=>x.id===_);if(S){S.encryptedValue=b,O=!0;break}}}else{let w=a.find(S=>S.id===_);w?.role!=="activity"&&w&&(w.encryptedValue=b,O=!0)}O&&(l.messages=a)}return p()}case v.SUBAGENT_STARTED:return m(await ie(r,a,s,(g,_,b)=>g.onSubagentStartedEvent?.({event:h,messages:_,state:b,agent:n,input:e}))),p();case v.SUBAGENT_FINISHED:return m(await ie(r,a,s,(g,_,b)=>g.onSubagentFinishedEvent?.({event:h,messages:_,state:b,agent:n,input:e}))),p();case v.SUBAGENT_ERROR:return m(await ie(r,a,s,(g,_,b)=>g.onSubagentErrorEvent?.({event:h,messages:_,state:b,agent:n,input:e}))),p()}return h.type,p()}),Lr(),r.length>0?dc({}):h=>h)};function Ya(e,t){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`[ag-ui][compat] Converting deprecated ${e} to ${t}. The old shape leaves the protocol after its shim window \u2014 see the repo-root DEPRECATIONS.md. Set SUPPRESS_TRANSFORMATION_WARNINGS=true to silence.`)}var Iu=e=>t=>{let n=_n(e),r=new Set,o=new Set,i=new Set,a=new Set,s={message:new Map,toolCall:new Map,activity:new Map,reasoning:new Map},l=!1,c=!1,u=!1,f=new Map,m=w=>{let S=f.get(w);return S||(S=new Map,f.set(w,S)),S},p=()=>{for(let w of f.values())if(w.size>0)return!0;return!1},h=new Map,E=new Set,g=!1,_=!1,b=()=>{_=!1,r.clear(),o.clear(),i.clear(),a.clear(),s.message.clear(),s.toolCall.clear(),s.activity.clear(),s.reasoning.clear(),f.clear(),h.clear(),E.clear(),l=!1,c=!1,g=!0},k=(w,S)=>{let x=w??[];if(Array.isArray(x))for(let I of x){if(!I||typeof I.id!="string")continue;if(I.subagentRunId===null)return new j(`Cannot send a message (id '${I.id}') with 'subagentRunId: null'. The field is optional \u2014 omit it entirely.`);let z=I.role==="reasoning"?s.reasoning:I.role==="activity"?s.activity:s.message;(S||!z.has(I.id))&&z.set(I.id,{subagentRunId:I.subagentRunId});for(let Y of I.toolCalls??[])Y&&typeof Y.id=="string"&&(S||!s.toolCall.has(Y.id))&&s.toolCall.set(Y.id,{subagentRunId:I.subagentRunId??void 0})}},O=(w,S,x,I,z)=>{if(S!==void 0&&x&&x.subagentRunId!==S)return new j(`Cannot send '${w}': subagentRunId '${S}' does not match the ${I} '${z}' opener's subagent '${x.subagentRunId??"(the parent agent)"}'.`)};return t.pipe(je(w=>{let S=w.type;if(n?.event("VERIFY","Event:",w,{type:w.type}),c&&S!==v.RUN_STARTED)return F(()=>new j(`Cannot send event type '${S}': The run has already errored with 'RUN_ERROR'. No further events can be sent.`));if(l&&S!==v.RUN_ERROR&&S!==v.RUN_STARTED)return F(()=>new j(`Cannot send event type '${S}': The run has already finished with 'RUN_FINISHED'. Start a new run with 'RUN_STARTED'.`));if(u){if(S===v.RUN_STARTED){if(g&&!l&&!c)return F(()=>new j("Cannot send 'RUN_STARTED' while a run is still active. The previous run must be finished with 'RUN_FINISHED' before starting a new run."));(l||c)&&b()}}else if(u=!0,S!==v.RUN_STARTED&&S!==v.RUN_ERROR)return F(()=>new j("First event must be 'RUN_STARTED'"));if(w.subagentRunId===null){_||(_=!0,Ya("subagentRunId: null","an absent field"));let{subagentRunId:x,...I}=w;w=I}if(S===v.SUBAGENT_STARTED||S===v.SUBAGENT_FINISHED||S===v.SUBAGENT_ERROR){let x=S===v.SUBAGENT_STARTED?["description","parentSubagentRunId","parentToolCallId","parentMessageId"]:S===v.SUBAGENT_FINISHED?["outcome"]:["code"];for(let z of x)if(w[z]===null)return F(()=>new j(`Cannot send '${S}' with '${z}: null'. The field is optional \u2014 omit it entirely.`));let I=w.outcome;if(I!=null&&I.type!=="success"&&I.type!=="suspended")return F(()=>new j(`Cannot send '${S}' with outcome type '${String(I.type)}'. The outcome is either { type: "success" } or { type: "suspended" }.`));if(I&&I.interruptIds===null)return F(()=>new j(`Cannot send '${S}' with 'outcome.interruptIds: null'. The field is optional \u2014 omit it entirely.`));if(I&&Array.isArray(I.interruptIds)&&I.interruptIds.some(z=>typeof z!="string"))return F(()=>new j(`Cannot send '${S}' with a non-string entry in 'outcome.interruptIds'. Interrupt ids are strings.`))}if(S===v.RUN_FINISHED){let x=w.outcome;if(x?.type==="interrupt"&&Array.isArray(x.interrupts)){for(let I of x.interrupts)if(I&&I.subagentRunId===null)return F(()=>new j(`Cannot send 'RUN_FINISHED' with an interrupt (id '${I.id}') carrying 'subagentRunId: null'. The field is optional \u2014 omit it entirely.`))}}switch(S){case v.TEXT_MESSAGE_START:{let x=w.messageId;if(r.has(x))return F(()=>new j(`Cannot send 'TEXT_MESSAGE_START' event: A text message with ID '${x}' is already in progress. Complete it with 'TEXT_MESSAGE_END' first.`));let I=s.message.get(x);if(I){let z=O(S,w.subagentRunId,I,"message",x);if(z)return F(()=>z)}return r.add(x),I||s.message.set(x,{subagentRunId:w.subagentRunId}),ce(w)}case v.TEXT_MESSAGE_CONTENT:{let x=w.messageId;if(!r.has(x))return F(()=>new j(`Cannot send 'TEXT_MESSAGE_CONTENT' event: No active text message found with ID '${x}'. Start a text message with 'TEXT_MESSAGE_START' first.`));let I=O(S,w.subagentRunId,s.message.get(x),"message",x);return I?F(()=>I):ce(w)}case v.TEXT_MESSAGE_END:{let x=w.messageId;if(!r.has(x))return F(()=>new j(`Cannot send 'TEXT_MESSAGE_END' event: No active text message found with ID '${x}'. A 'TEXT_MESSAGE_START' event must be sent first.`));let I=O(S,w.subagentRunId,s.message.get(x),"message",x);return I?F(()=>I):(r.delete(x),ce(w))}case v.TOOL_CALL_START:{let x=w.toolCallId;if(o.has(x))return F(()=>new j(`Cannot send 'TOOL_CALL_START' event: A tool call with ID '${x}' is already in progress. Complete it with 'TOOL_CALL_END' first.`));let I=w.parentMessageId,z=w.subagentRunId,Y;if(I!==void 0){let Ce=s.message.get(I);if(Ce){if(z!==void 0&&z!==Ce.subagentRunId)return F(()=>new j(`Cannot send 'TOOL_CALL_START': subagentRunId '${z}' does not match its parent message '${I}' owner '${Ce.subagentRunId??"(the parent agent)"}'. A tool call belongs to the message that carries it.`));Y=Ce}}let X=s.toolCall.get(x);if(X){let Ce=O(S,z,X,"tool call",x);if(Ce)return F(()=>Ce);if(z===void 0&&Y&&Y.subagentRunId!==X.subagentRunId)return F(()=>new j(`Cannot send 'TOOL_CALL_START': tool call '${x}' is owned by '${X.subagentRunId??"(the parent agent)"}' but its parent message '${I}' is owned by '${Y.subagentRunId??"(the parent agent)"}'. A tool call belongs to the message that carries it.`))}return o.add(x),X||s.toolCall.set(x,z===void 0?Y??{subagentRunId:void 0}:{subagentRunId:z}),ce(w)}case v.TOOL_CALL_ARGS:{let x=w.toolCallId;if(!o.has(x))return F(()=>new j(`Cannot send 'TOOL_CALL_ARGS' event: No active tool call found with ID '${x}'. Start a tool call with 'TOOL_CALL_START' first.`));let I=O(S,w.subagentRunId,s.toolCall.get(x),"tool call",x);return I?F(()=>I):ce(w)}case v.TOOL_CALL_END:{let x=w.toolCallId;if(!o.has(x))return F(()=>new j(`Cannot send 'TOOL_CALL_END' event: No active tool call found with ID '${x}'. A 'TOOL_CALL_START' event must be sent first.`));let I=O(S,w.subagentRunId,s.toolCall.get(x),"tool call",x);return I?F(()=>I):(o.delete(x),ce(w))}case v.STEP_STARTED:{let x=w.stepName,I=w.subagentRunId;return m(I).has(x)?F(()=>new j(`Step "${x}" is already active for 'STEP_STARTED'${I===void 0?"":` in subagent '${I}'`}`)):(m(I).set(x,!0),ce(w))}case v.STEP_FINISHED:{let x=w.stepName,I=w.subagentRunId;if(!m(I).has(x)){let z,Y=!1;for(let[X,Ce]of f)if(X!==I&&Ce.has(x)){z=X,Y=!0;break}return F(Y?()=>new j(`Cannot send 'STEP_FINISHED' for step "${x}" attributed to ${I===void 0?"the parent agent":`subagent '${I}'`}: that step is open under ${z===void 0?"the parent agent":`subagent '${z}'`}. A step must be finished by whoever started it.`):()=>new j(`Cannot send 'STEP_FINISHED' for step "${x}" that was not started`))}return m(I).delete(x),ce(w)}case v.ACTIVITY_SNAPSHOT:{let x=w.messageId;return(!s.activity.has(x)||w.replace!==!1)&&s.activity.set(x,{subagentRunId:w.subagentRunId}),ce(w)}case v.TOOL_CALL_RESULT:{let x=w.messageId;return typeof x=="string"&&s.message.set(x,{subagentRunId:w.subagentRunId}),ce(w)}case v.REASONING_START:case v.REASONING_MESSAGE_START:{let x=w.messageId,I=S===v.REASONING_START,z=I?i:a;if(z.has(x))return F(()=>new j(I?`Cannot send 'REASONING_START' event: A reasoning span with ID '${x}' is already in progress. Complete it with 'REASONING_END' first.`:`Cannot send 'REASONING_MESSAGE_START' event: A reasoning message with ID '${x}' is already in progress. Complete it with 'REASONING_MESSAGE_END' first.`));let Y=s.reasoning.get(x);if(Y){let X=O(S,w.subagentRunId,Y,"reasoning message",x);if(X)return F(()=>X)}return z.add(x),Y||s.reasoning.set(x,{subagentRunId:w.subagentRunId}),ce(w)}case v.REASONING_MESSAGE_CONTENT:case v.REASONING_MESSAGE_END:case v.REASONING_END:{let x=w.messageId,I=S===v.REASONING_END,z=I?i:a;if(!z.has(x))return F(()=>new j(I?`Cannot send 'REASONING_END' event: No active reasoning span found with ID '${x}'. A 'REASONING_START' event must be sent first.`:`Cannot send '${S}' event: No active reasoning message found with ID '${x}'. Start a reasoning message with 'REASONING_MESSAGE_START' first.`));let Y=O(S,w.subagentRunId,s.reasoning.get(x),"reasoning message",x);return Y?F(()=>Y):((S===v.REASONING_END||S===v.REASONING_MESSAGE_END)&&z.delete(x),ce(w))}case v.REASONING_ENCRYPTED_VALUE:{let x=w.entityId,I=w.subtype,z=I==="tool-call"?s.toolCall.get(x):I==="message"?s.message.get(x)??s.reasoning.get(x):s.reasoning.get(x),Y=I==="tool-call"?"tool call":I==="message"?"message":"reasoning message",X=O(S,w.subagentRunId,z,Y,x);return X?F(()=>X):ce(w)}case v.ACTIVITY_DELTA:{let x=w.messageId,I=O(S,w.subagentRunId,s.activity.get(x),"activity",x);return I?F(()=>I):ce(w)}case v.SUBAGENT_STARTED:{if(typeof w.subagentRunId!="string")return F(()=>new j("Cannot send 'SUBAGENT_STARTED' without a 'subagentRunId'."));if(typeof w.name!="string")return F(()=>new j("Cannot send 'SUBAGENT_STARTED' without a 'name'."));let x=w.subagentRunId,I=w.parentSubagentRunId;return h.has(x)?F(()=>new j(`Cannot send 'SUBAGENT_STARTED': subagent '${x}' is already active. Finish it with 'SUBAGENT_FINISHED' first.`)):E.has(x)?F(()=>new j(`Cannot send 'SUBAGENT_STARTED': subagent '${x}' has already finished in this run. Subagent IDs are per-invocation and cannot be reused.`)):I!==void 0&&!h.has(I)&&!E.has(I)?F(()=>new j(`Cannot send 'SUBAGENT_STARTED': parentSubagentRunId '${I}' has not been started in this run.`)):(h.set(x,!0),ce(w))}case v.SUBAGENT_FINISHED:case v.SUBAGENT_ERROR:{if(typeof w.subagentRunId!="string")return F(()=>new j(`Cannot send '${S}' without a 'subagentRunId'.`));if(S===v.SUBAGENT_ERROR&&typeof w.message!="string")return F(()=>new j("Cannot send 'SUBAGENT_ERROR' without a 'message'."));let x=w.subagentRunId;return h.has(x)?(h.delete(x),E.add(x),ce(w)):F(()=>new j(`Cannot send '${S}': no active subagent found with ID '${x}'. A 'SUBAGENT_STARTED' event must be sent first.`))}case v.MESSAGES_SNAPSHOT:{let x=k(w.messages,!0);if(x)return F(()=>x)}return ce(w);case v.RUN_STARTED:g=!0;{let x=k((w.input??{}).messages,!1);if(x)return F(()=>x)}return ce(w);case v.RUN_FINISHED:if(p()){let x=[];for(let[z,Y]of f)for(let X of Y.keys())x.push(z===void 0?X:`${X} (subagent '${z}')`);let I=x.join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while steps are still active: ${I}`))}if(r.size>0){let x=Array.from(r.keys()).join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while text messages are still active: ${x}`))}if(a.size>0){let x=Array.from(a.keys()).join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while reasoning messages are still active: ${x}`))}if(i.size>0){let x=Array.from(i.keys()).join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while reasoning spans are still active: ${x}`))}if(o.size>0){let x=Array.from(o.keys()).join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while tool calls are still active: ${x}`))}if(h.size>0){let x=Array.from(h.keys()).join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while subagents are still active: ${x}`))}return l=!0,ce(w);case v.RUN_ERROR:return c=!0,ce(w);case v.CUSTOM:return ce(w);default:return ce(w)}}))},xn=(function(e){return e.HEADERS="headers",e.DATA="data",e})({}),J0=e=>cn(()=>Ct(e())).pipe(pc(t=>{if(!t.ok){let o=t.headers.get("content-type")||"";return Ct(t.text()).pipe(je(i=>{let a=i;if(o.includes("application/json"))try{a=JSON.parse(i)}catch{}let s=Error(`HTTP ${t.status}: ${typeof a=="string"?a:JSON.stringify(a)}`);return s.status=t.status,s.payload=a,F(()=>s)}))}let n={type:xn.HEADERS,status:t.status,headers:t.headers},r=t.body?.getReader();return r?new ge(o=>{let i=!1;return o.next(n),(async()=>{try{for(;!o.closed;){let{done:a,value:s}=await r.read();if(a){i=!0;break}let l={type:xn.DATA,data:s};o.next(l)}o.complete()}catch(a){i=!0,o.error(a)}})(),()=>{i||r.cancel().catch(a=>{a?.name!=="AbortError"&&console.warn("Failed to cancel HTTP response stream:",a)})}}):F(()=>Error("Failed to getReader() from response"))})),Kv=10*1024*1024,Q0=(e,t)=>{let n=_n(t),r=new xt,o=new TextDecoder("utf-8",{fatal:!1}),i="";e.subscribe({next:s=>{if(s.type!==xn.HEADERS&&s.type===xn.DATA&&s.data){let l=o.decode(s.data,{stream:!0});i+=l;let c=i.split(/\n\n/);i=c.pop()||"";for(let u of c)a(u);if(i.length>Kv){r.error(Error(`SSE buffer size exceeded maximum limit of ${Kv/(1024*1024)} MB`));return}}},error:s=>r.error(s),complete:()=>{i&&(i+=o.decode(),a(i)),r.complete()}});function a(s){let l=s.split(`
|
|
34
|
-
`),
|
|
35
|
-
`),f=JSON.parse(u);n?.event("SSE","Event received:",f,{type:f?.type}),r.next(f)}catch(u){r.error(u)}}return r.asObservable()},
|
|
36
|
-
`)};function
|
|
32
|
+
Patch operations: ${JSON.stringify(w,null,2)}
|
|
33
|
+
Error: ${k}`)}}return p()}case v.MESSAGES_SNAPSHOT:{let g=await ae(r,a,s,(w,b,k)=>w.onMessagesSnapshotEvent?.({event:h,messages:b,state:k,agent:n,input:t}));if(m(g),g.stopPropagation!==!0){let{messages:w}=h,b=w.map(L=>{if(L.subagentRunId!==null)return L;let Y={...L};return delete Y.subagentRunId,Y}),k=new Map(b.map(L=>[L.id,L])),O=sT(h),E=b.some(L=>L.role==="activity"),S=b.some(L=>L.role==="reasoning"),_=L=>L.role==="activity"&&(O?!O.includes(L.activityType):O!==null&&!E)||L.role==="reasoning"&&!S;a=a.filter(L=>k.has(L.id)||_(L)).map(L=>k.get(L.id)??L);let I=new Set(a.map(L=>L.id));for(let L of b)I.has(L.id)||a.push(L);m({messages:a})}return p()}case v.ACTIVITY_SNAPSHOT:{let g=h,w=a.findIndex(S=>S.id===g.messageId),b=w>=0?a[w]:void 0,k=b?.role==="activity"?b:void 0,O=g.replace??!0,E=await ae(r,a,s,(S,_,I)=>S.onActivitySnapshotEvent?.({event:g,messages:_,state:I,agent:n,input:t,activityMessage:k,existingMessage:b}));if(m(E),E.stopPropagation!==!0){let S={id:g.messageId,role:"activity",activityType:g.activityType,content:ne(g.content),...g.subagentRunId!=null&&{subagentRunId:g.subagentRunId}},_,I;w===-1?(a.push(S),_=S,I=S):k?(O&&(a[w]={...k,activityType:g.activityType,content:ne(g.content),subagentRunId:g.subagentRunId},g.subagentRunId??delete a[w].subagentRunId),I=a[w]):O&&(a[w]=S,_=S,I=S),Qe(I,g),m({messages:a}),_&&await Promise.all(r.map(L=>L.onNewMessage?.({message:_,messages:a,state:s,agent:n,input:t})))}return p()}case v.ACTIVITY_DELTA:{let g=h,w=a.findIndex(E=>E.id===g.messageId);if(w===-1)return p();let b=a[w];if(b.role!=="activity")return console.warn(`ACTIVITY_DELTA: Message '${g.messageId}' is not an activity message`),p();let k=b,O=await ae(r,a,s,(E,S,_)=>E.onActivityDeltaEvent?.({event:g,messages:S,state:_,agent:n,input:t,activityMessage:k}));if(m(O),O.stopPropagation!==!0)try{Qe(k,g)&&m({messages:a});let E=ne(k.content??{}),S=ai.applyPatch(E,g.patch??[],!0,!1).newDocument;a[w]={...k,content:ne(S),activityType:g.activityType},m({messages:a})}catch(E){let S=E instanceof Error?E.message:String(E);console.warn(`Failed to apply activity patch for '${g.messageId}': ${S}`)}return p()}case v.RAW:return m(await ae(r,a,s,(g,w,b)=>g.onRawEvent?.({event:h,messages:w,state:b,agent:n,input:t}))),p();case v.CUSTOM:return m(await ae(r,a,s,(g,w,b)=>g.onCustomEvent?.({event:h,messages:w,state:b,agent:n,input:t}))),p();case v.RUN_STARTED:{let g=await ae(r,a,s,(w,b,k)=>w.onRunStartedEvent?.({event:h,messages:b,state:k,agent:n,input:t}));if(m(g),l=[],u=new Set,g.stopPropagation!==!0){let w=h;if(w.input?.messages){for(let b of w.input.messages){let k=b;if(b.subagentRunId===null){let O={...b};delete O.subagentRunId,k=O}a.find(O=>O.id===k.id)||a.push(k)}m({messages:a})}}return p()}case v.RUN_FINISHED:{let g=h,w=g.outcome?.type==="interrupt"?{event:g,outcome:"interrupt",interrupts:g.outcome.interrupts}:g.outcome?.type==="cancelled"?{event:g,outcome:"cancelled"}:{event:g,outcome:"success",result:g.result,pendingToolCallIds:f(g)},b=await ae(r,a,s,(k,O,E)=>k.onRunFinishedEvent?.({...w,messages:O,state:E,agent:n,input:t}));return m(b),b.stopPropagation!==!0&&(n.pendingInterrupts=w.outcome==="interrupt"?w.interrupts.map(k=>{if(k.subagentRunId!==null)return k;let O={...k};return delete O.subagentRunId,O}):[]),p()}case v.RUN_ERROR:return m(await ae(r,a,s,(g,w,b)=>g.onRunErrorEvent?.({event:h,messages:w,state:b,agent:n,input:t}))),p();case v.STEP_STARTED:return m(await ae(r,a,s,(g,w,b)=>g.onStepStartedEvent?.({event:h,messages:w,state:b,agent:n,input:t}))),p();case v.STEP_FINISHED:return m(await ae(r,a,s,(g,w,b)=>g.onStepFinishedEvent?.({event:h,messages:w,state:b,agent:n,input:t}))),p();case v.TEXT_MESSAGE_CHUNK:throw Error("TEXT_MESSAGE_CHUNK must be transformed before being applied");case v.TOOL_CALL_CHUNK:throw Error("TOOL_CALL_CHUNK must be transformed before being applied");case v.REASONING_START:return m(await ae(r,a,s,(g,w,b)=>g.onReasoningStartEvent?.({event:h,messages:w,state:b,agent:n,input:t}))),p();case v.REASONING_MESSAGE_START:{let g=await ae(r,a,s,(w,b,k)=>w.onReasoningMessageStartEvent?.({event:h,messages:b,state:k,agent:n,input:t}));if(m(g),g.stopPropagation!==!0){let{messageId:w,subagentRunId:b}=h,k=a.find(S=>S.id===w);if(k?.role==="activity")return console.warn(`REASONING_MESSAGE_START: Message '${w}' is an activity message \u2014 message ids must be unique across activity and reasoning messages`),p();let O=k;if(!O){let S={id:w,role:"reasoning",content:"",...b!=null&&{subagentRunId:b}};a.push(S),O=S}let E=Qe(O,h);(!k||E)&&m({messages:a})}return p()}case v.REASONING_MESSAGE_CONTENT:{let{messageId:g,delta:w}=h,b=a.find(O=>O.id===g);if(!b)return console.warn(`REASONING_MESSAGE_CONTENT: No message found with ID '${g}'`),p();if(b.role==="activity")return console.warn(`REASONING_MESSAGE_CONTENT: Message '${g}' is an activity message \u2014 message ids must be unique across activity and reasoning messages`),p();let k=await ae(r,a,s,(O,E,S)=>O.onReasoningMessageContentEvent?.({event:h,messages:E,state:S,agent:n,input:t,reasoningMessageBuffer:typeof b.content=="string"?b.content:""}));return m(k),k.stopPropagation!==!0&&(b.content=`${typeof b.content=="string"?b.content:""}${w}`,Qe(b,h),m({messages:a})),p()}case v.REASONING_MESSAGE_END:{let{messageId:g}=h,w=a.find(k=>k.id===g);if(!w)return console.warn(`REASONING_MESSAGE_END: No message found with ID '${g}'`),p();if(w.role==="activity")return console.warn(`REASONING_MESSAGE_END: Message '${g}' is an activity message \u2014 message ids must be unique across activity and reasoning messages`),p();let b=await ae(r,a,s,(k,O,E)=>k.onReasoningMessageEndEvent?.({event:h,messages:O,state:E,agent:n,input:t,reasoningMessageBuffer:typeof w.content=="string"?w.content:""}));return m(b),b.stopPropagation!==!0&&Qe(w,h)&&m({messages:a}),await Promise.all(r.map(k=>{k.onNewMessage?.({message:w,messages:a,state:s,agent:n,input:t})})),p()}case v.REASONING_MESSAGE_CHUNK:throw Error("REASONING_MESSAGE_CHUNK must be transformed before being applied");case v.REASONING_END:return m(await ae(r,a,s,(g,w,b)=>g.onReasoningEndEvent?.({event:h,messages:w,state:b,agent:n,input:t}))),p();case v.REASONING_ENCRYPTED_VALUE:{let{subtype:g,entityId:w,encryptedValue:b}=h,k=await ae(r,a,s,(O,E,S)=>O.onReasoningEncryptedValueEvent?.({event:h,messages:E,state:S,agent:n,input:t}));if(m(k),k.stopPropagation!==!0){let O=!1;if(g==="tool-call"){for(let E of a)if(E.role==="assistant"&&E.toolCalls){let S=E.toolCalls.find(_=>_.id===w);if(S){S.encryptedValue=b,O=!0;break}}}else{let E=a.find(S=>S.id===w);E?.role!=="activity"&&E&&(E.encryptedValue=b,O=!0)}O&&(c.messages=a)}return p()}case v.SUBAGENT_STARTED:return m(await ae(r,a,s,(g,w,b)=>g.onSubagentStartedEvent?.({event:h,messages:w,state:b,agent:n,input:t}))),p();case v.SUBAGENT_FINISHED:return m(await ae(r,a,s,(g,w,b)=>g.onSubagentFinishedEvent?.({event:h,messages:w,state:b,agent:n,input:t}))),p();case v.SUBAGENT_ERROR:return m(await ae(r,a,s,(g,w,b)=>g.onSubagentErrorEvent?.({event:h,messages:w,state:b,agent:n,input:t}))),p()}return h.type,p()}),Ur(),r.length>0?yc({}):h=>h)};function Qa(t,e){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`[ag-ui][compat] Converting deprecated ${t} to ${e}. The old shape leaves the protocol after its shim window \u2014 see the repo-root DEPRECATIONS.md. Set SUPPRESS_TRANSFORMATION_WARNINGS=true to silence.`)}var zu=t=>e=>{let n=kn(t),r=new Set,o=new Set,i=new Set,a=new Set,s={message:new Map,toolCall:new Map,activity:new Map,reasoning:new Map},c=!1,l=!1,u=!1,f=new Map,m=E=>{let S=f.get(E);return S||(S=new Map,f.set(E,S)),S},p=()=>{for(let E of f.values())if(E.size>0)return!0;return!1},h=new Map,x=new Set,g=!1,w=!1,b=()=>{w=!1,r.clear(),o.clear(),i.clear(),a.clear(),s.message.clear(),s.toolCall.clear(),s.activity.clear(),s.reasoning.clear(),f.clear(),h.clear(),x.clear(),c=!1,l=!1,g=!0},k=(E,S)=>{let _=E??[];if(Array.isArray(_))for(let I of _){if(!I||typeof I.id!="string")continue;if(I.subagentRunId===null)return new j(`Cannot send a message (id '${I.id}') with 'subagentRunId: null'. The field is optional \u2014 omit it entirely.`);let L=I.role==="reasoning"?s.reasoning:I.role==="activity"?s.activity:s.message;(S||!L.has(I.id))&&L.set(I.id,{subagentRunId:I.subagentRunId});for(let Y of I.toolCalls??[])Y&&typeof Y.id=="string"&&(S||!s.toolCall.has(Y.id))&&s.toolCall.set(Y.id,{subagentRunId:I.subagentRunId??void 0})}},O=(E,S,_,I,L)=>{if(S!==void 0&&_&&_.subagentRunId!==S)return new j(`Cannot send '${E}': subagentRunId '${S}' does not match the ${I} '${L}' opener's subagent '${_.subagentRunId??"(the parent agent)"}'.`)};return e.pipe(We(E=>{let S=E.type;if(n?.event("VERIFY","Event:",E,{type:E.type}),l&&S!==v.RUN_STARTED)return F(()=>new j(`Cannot send event type '${S}': The run has already errored with 'RUN_ERROR'. No further events can be sent.`));if(c&&S!==v.RUN_ERROR&&S!==v.RUN_STARTED)return F(()=>new j(`Cannot send event type '${S}': The run has already finished with 'RUN_FINISHED'. Start a new run with 'RUN_STARTED'.`));if(u){if(S===v.RUN_STARTED){if(g&&!c&&!l)return F(()=>new j("Cannot send 'RUN_STARTED' while a run is still active. The previous run must be finished with 'RUN_FINISHED' before starting a new run."));(c||l)&&b()}}else if(u=!0,S!==v.RUN_STARTED&&S!==v.RUN_ERROR)return F(()=>new j("First event must be 'RUN_STARTED'"));if(E.subagentRunId===null){w||(w=!0,Qa("subagentRunId: null","an absent field"));let{subagentRunId:_,...I}=E;E=I}if(S===v.SUBAGENT_STARTED||S===v.SUBAGENT_FINISHED||S===v.SUBAGENT_ERROR){let _=S===v.SUBAGENT_STARTED?["description","parentSubagentRunId","parentToolCallId","parentMessageId"]:S===v.SUBAGENT_FINISHED?["outcome"]:["code"];for(let L of _)if(E[L]===null)return F(()=>new j(`Cannot send '${S}' with '${L}: null'. The field is optional \u2014 omit it entirely.`));let I=E.outcome;if(I!=null&&I.type!=="success"&&I.type!=="suspended")return F(()=>new j(`Cannot send '${S}' with outcome type '${String(I.type)}'. The outcome is either { type: "success" } or { type: "suspended" }.`));if(I&&I.interruptIds===null)return F(()=>new j(`Cannot send '${S}' with 'outcome.interruptIds: null'. The field is optional \u2014 omit it entirely.`));if(I&&Array.isArray(I.interruptIds)&&I.interruptIds.some(L=>typeof L!="string"))return F(()=>new j(`Cannot send '${S}' with a non-string entry in 'outcome.interruptIds'. Interrupt ids are strings.`))}if(S===v.RUN_FINISHED){let _=E.outcome;if(_?.type==="interrupt"&&Array.isArray(_.interrupts)){for(let I of _.interrupts)if(I&&I.subagentRunId===null)return F(()=>new j(`Cannot send 'RUN_FINISHED' with an interrupt (id '${I.id}') carrying 'subagentRunId: null'. The field is optional \u2014 omit it entirely.`))}}switch(S){case v.TEXT_MESSAGE_START:{let _=E.messageId;if(r.has(_))return F(()=>new j(`Cannot send 'TEXT_MESSAGE_START' event: A text message with ID '${_}' is already in progress. Complete it with 'TEXT_MESSAGE_END' first.`));let I=s.message.get(_);if(I){let L=O(S,E.subagentRunId,I,"message",_);if(L)return F(()=>L)}return r.add(_),I||s.message.set(_,{subagentRunId:E.subagentRunId}),ue(E)}case v.TEXT_MESSAGE_CONTENT:{let _=E.messageId;if(!r.has(_))return F(()=>new j(`Cannot send 'TEXT_MESSAGE_CONTENT' event: No active text message found with ID '${_}'. Start a text message with 'TEXT_MESSAGE_START' first.`));let I=O(S,E.subagentRunId,s.message.get(_),"message",_);return I?F(()=>I):ue(E)}case v.TEXT_MESSAGE_END:{let _=E.messageId;if(!r.has(_))return F(()=>new j(`Cannot send 'TEXT_MESSAGE_END' event: No active text message found with ID '${_}'. A 'TEXT_MESSAGE_START' event must be sent first.`));let I=O(S,E.subagentRunId,s.message.get(_),"message",_);return I?F(()=>I):(r.delete(_),ue(E))}case v.TOOL_CALL_START:{let _=E.toolCallId;if(o.has(_))return F(()=>new j(`Cannot send 'TOOL_CALL_START' event: A tool call with ID '${_}' is already in progress. Complete it with 'TOOL_CALL_END' first.`));let I=E.parentMessageId,L=E.subagentRunId,Y;if(I!==void 0){let Ne=s.message.get(I);if(Ne){if(L!==void 0&&L!==Ne.subagentRunId)return F(()=>new j(`Cannot send 'TOOL_CALL_START': subagentRunId '${L}' does not match its parent message '${I}' owner '${Ne.subagentRunId??"(the parent agent)"}'. A tool call belongs to the message that carries it.`));Y=Ne}}let X=s.toolCall.get(_);if(X){let Ne=O(S,L,X,"tool call",_);if(Ne)return F(()=>Ne);if(L===void 0&&Y&&Y.subagentRunId!==X.subagentRunId)return F(()=>new j(`Cannot send 'TOOL_CALL_START': tool call '${_}' is owned by '${X.subagentRunId??"(the parent agent)"}' but its parent message '${I}' is owned by '${Y.subagentRunId??"(the parent agent)"}'. A tool call belongs to the message that carries it.`))}return o.add(_),X||s.toolCall.set(_,L===void 0?Y??{subagentRunId:void 0}:{subagentRunId:L}),ue(E)}case v.TOOL_CALL_ARGS:{let _=E.toolCallId;if(!o.has(_))return F(()=>new j(`Cannot send 'TOOL_CALL_ARGS' event: No active tool call found with ID '${_}'. Start a tool call with 'TOOL_CALL_START' first.`));let I=O(S,E.subagentRunId,s.toolCall.get(_),"tool call",_);return I?F(()=>I):ue(E)}case v.TOOL_CALL_END:{let _=E.toolCallId;if(!o.has(_))return F(()=>new j(`Cannot send 'TOOL_CALL_END' event: No active tool call found with ID '${_}'. A 'TOOL_CALL_START' event must be sent first.`));let I=O(S,E.subagentRunId,s.toolCall.get(_),"tool call",_);return I?F(()=>I):(o.delete(_),ue(E))}case v.STEP_STARTED:{let _=E.stepName,I=E.subagentRunId;return m(I).has(_)?F(()=>new j(`Step "${_}" is already active for 'STEP_STARTED'${I===void 0?"":` in subagent '${I}'`}`)):(m(I).set(_,!0),ue(E))}case v.STEP_FINISHED:{let _=E.stepName,I=E.subagentRunId;if(!m(I).has(_)){let L,Y=!1;for(let[X,Ne]of f)if(X!==I&&Ne.has(_)){L=X,Y=!0;break}return F(Y?()=>new j(`Cannot send 'STEP_FINISHED' for step "${_}" attributed to ${I===void 0?"the parent agent":`subagent '${I}'`}: that step is open under ${L===void 0?"the parent agent":`subagent '${L}'`}. A step must be finished by whoever started it.`):()=>new j(`Cannot send 'STEP_FINISHED' for step "${_}" that was not started`))}return m(I).delete(_),ue(E)}case v.ACTIVITY_SNAPSHOT:{let _=E.messageId;return(!s.activity.has(_)||E.replace!==!1)&&s.activity.set(_,{subagentRunId:E.subagentRunId}),ue(E)}case v.TOOL_CALL_RESULT:{let _=E.messageId;return typeof _=="string"&&s.message.set(_,{subagentRunId:E.subagentRunId}),ue(E)}case v.REASONING_START:case v.REASONING_MESSAGE_START:{let _=E.messageId,I=S===v.REASONING_START,L=I?i:a;if(L.has(_))return F(()=>new j(I?`Cannot send 'REASONING_START' event: A reasoning span with ID '${_}' is already in progress. Complete it with 'REASONING_END' first.`:`Cannot send 'REASONING_MESSAGE_START' event: A reasoning message with ID '${_}' is already in progress. Complete it with 'REASONING_MESSAGE_END' first.`));let Y=s.reasoning.get(_);if(Y){let X=O(S,E.subagentRunId,Y,"reasoning message",_);if(X)return F(()=>X)}return L.add(_),Y||s.reasoning.set(_,{subagentRunId:E.subagentRunId}),ue(E)}case v.REASONING_MESSAGE_CONTENT:case v.REASONING_MESSAGE_END:case v.REASONING_END:{let _=E.messageId,I=S===v.REASONING_END,L=I?i:a;if(!L.has(_))return F(()=>new j(I?`Cannot send 'REASONING_END' event: No active reasoning span found with ID '${_}'. A 'REASONING_START' event must be sent first.`:`Cannot send '${S}' event: No active reasoning message found with ID '${_}'. Start a reasoning message with 'REASONING_MESSAGE_START' first.`));let Y=O(S,E.subagentRunId,s.reasoning.get(_),"reasoning message",_);return Y?F(()=>Y):((S===v.REASONING_END||S===v.REASONING_MESSAGE_END)&&L.delete(_),ue(E))}case v.REASONING_ENCRYPTED_VALUE:{let _=E.entityId,I=E.subtype,L=I==="tool-call"?s.toolCall.get(_):I==="message"?s.message.get(_)??s.reasoning.get(_):s.reasoning.get(_),Y=I==="tool-call"?"tool call":I==="message"?"message":"reasoning message",X=O(S,E.subagentRunId,L,Y,_);return X?F(()=>X):ue(E)}case v.ACTIVITY_DELTA:{let _=E.messageId,I=O(S,E.subagentRunId,s.activity.get(_),"activity",_);return I?F(()=>I):ue(E)}case v.SUBAGENT_STARTED:{if(typeof E.subagentRunId!="string")return F(()=>new j("Cannot send 'SUBAGENT_STARTED' without a 'subagentRunId'."));if(typeof E.name!="string")return F(()=>new j("Cannot send 'SUBAGENT_STARTED' without a 'name'."));let _=E.subagentRunId,I=E.parentSubagentRunId;return h.has(_)?F(()=>new j(`Cannot send 'SUBAGENT_STARTED': subagent '${_}' is already active. Finish it with 'SUBAGENT_FINISHED' first.`)):x.has(_)?F(()=>new j(`Cannot send 'SUBAGENT_STARTED': subagent '${_}' has already finished in this run. Subagent IDs are per-invocation and cannot be reused.`)):I!==void 0&&!h.has(I)&&!x.has(I)?F(()=>new j(`Cannot send 'SUBAGENT_STARTED': parentSubagentRunId '${I}' has not been started in this run.`)):(h.set(_,!0),ue(E))}case v.SUBAGENT_FINISHED:case v.SUBAGENT_ERROR:{if(typeof E.subagentRunId!="string")return F(()=>new j(`Cannot send '${S}' without a 'subagentRunId'.`));if(S===v.SUBAGENT_ERROR&&typeof E.message!="string")return F(()=>new j("Cannot send 'SUBAGENT_ERROR' without a 'message'."));let _=E.subagentRunId;return h.has(_)?(h.delete(_),x.add(_),ue(E)):F(()=>new j(`Cannot send '${S}': no active subagent found with ID '${_}'. A 'SUBAGENT_STARTED' event must be sent first.`))}case v.MESSAGES_SNAPSHOT:{let _=k(E.messages,!0);if(_)return F(()=>_)}return ue(E);case v.RUN_STARTED:g=!0;{let _=k((E.input??{}).messages,!1);if(_)return F(()=>_)}return ue(E);case v.RUN_FINISHED:if(p()){let _=[];for(let[L,Y]of f)for(let X of Y.keys())_.push(L===void 0?X:`${X} (subagent '${L}')`);let I=_.join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while steps are still active: ${I}`))}if(r.size>0){let _=Array.from(r.keys()).join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while text messages are still active: ${_}`))}if(a.size>0){let _=Array.from(a.keys()).join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while reasoning messages are still active: ${_}`))}if(i.size>0){let _=Array.from(i.keys()).join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while reasoning spans are still active: ${_}`))}if(o.size>0){let _=Array.from(o.keys()).join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while tool calls are still active: ${_}`))}if(h.size>0){let _=Array.from(h.keys()).join(", ");return F(()=>new j(`Cannot send 'RUN_FINISHED' while subagents are still active: ${_}`))}return c=!0,ue(E);case v.RUN_ERROR:return l=!0,ue(E);case v.CUSTOM:return ue(E);default:return ue(E)}}))},An=(function(t){return t.HEADERS="headers",t.DATA="data",t})({}),uT=t=>hn(()=>Pt(t())).pipe(wc(e=>{if(!e.ok){let o=e.headers.get("content-type")||"";return Pt(e.text()).pipe(We(i=>{let a=i;if(o.includes("application/json"))try{a=JSON.parse(i)}catch{}let s=Error(`HTTP ${e.status}: ${typeof a=="string"?a:JSON.stringify(a)}`);return s.status=e.status,s.payload=a,F(()=>s)}))}let n={type:An.HEADERS,status:e.status,headers:e.headers},r=e.body?.getReader();return r?new ve(o=>{let i=!1;return o.next(n),(async()=>{try{for(;!o.closed;){let{done:a,value:s}=await r.read();if(a){i=!0;break}let c={type:An.DATA,data:s};o.next(c)}o.complete()}catch(a){i=!0,o.error(a)}})(),()=>{i||r.cancel().catch(a=>{a?.name!=="AbortError"&&console.warn("Failed to cancel HTTP response stream:",a)})}}):F(()=>Error("Failed to getReader() from response"))})),sb=10*1024*1024,dT=(t,e)=>{let n=kn(e),r=new St,o=new TextDecoder("utf-8",{fatal:!1}),i="";t.subscribe({next:s=>{if(s.type!==An.HEADERS&&s.type===An.DATA&&s.data){let c=o.decode(s.data,{stream:!0});i+=c;let l=i.split(/\n\n/);i=l.pop()||"";for(let u of l)a(u);if(i.length>sb){r.error(Error(`SSE buffer size exceeded maximum limit of ${sb/(1024*1024)} MB`));return}}},error:s=>r.error(s),complete:()=>{i&&(i+=o.decode(),a(i)),r.complete()}});function a(s){let c=s.split(`
|
|
34
|
+
`),l=[];for(let u of c)u.startsWith("data:")&&l.push(u.slice(5).replace(/^ /,""));if(l.length>0)try{let u=l.join(`
|
|
35
|
+
`),f=JSON.parse(u);n?.event("SSE","Event received:",f,{type:f?.type}),r.next(f)}catch(u){r.error(u)}}return r.asObservable()},lb=10*1024*1024,pT=()=>typeof process<"u"&&process.env!==void 0&&!!process.env.SUPPRESS_TRANSFORMATION_WARNINGS,hT=(t,e)=>{let n=kn(e),r=new St,o=new Uint8Array,i=!1;t.subscribe({next:s=>{if(s.type!==An.HEADERS&&s.type===An.DATA&&s.data){let c=new Uint8Array(o.length+s.data.length);c.set(o,0),c.set(s.data,o.length),o=c,a()}},error:s=>r.error(s),complete:()=>{if(a(),!i){if(o.length>0){r.error(Error(`The binary stream ended mid-frame: ${o.length} trailing bytes could not be read as a complete message.`));return}r.complete()}}});function a(){if(!i)for(;o.length>=4;){let s=4+new DataView(o.buffer,o.byteOffset,4).getUint32(0,!1);if(s>lb){r.error(Error(`Protobuf message size exceeded maximum limit of ${lb/(1024*1024)} MB`));return}if(o.length<s)break;try{let c=o.slice(4,s),l=tb(c);n?.event("PROTO","Event received:",l,{type:l.type}),r.next(l)}catch(c){if(c instanceof Ru)pT()||console.warn("[ag-ui][proto] Dropped an event this build does not know: the protocol has a variant this SDK predates.");else{let l=c instanceof Error?c.message:String(c);i=!0,r.error(Error(`Failed to decode protocol buffer message: ${l}`));return}}o=o.slice(s)}}return r.asObservable()},fT=(t,e)=>{let n=kn(e),r=new St,o=new fi(1),i=!1,a,s=!1,c=()=>{s=!0,a?.unsubscribe()},l=f=>{c(),r.error(f)},u=()=>{c(),r.complete()};return a=t.subscribe({next:f=>{if(o.next(f),f.type===An.HEADERS&&!i){i=!0;let m=f.headers.get("content-type");n?.lifecycle("HTTP","Stream format detected:",{contentType:m,parser:m===Cu?"protobuf":"sse"}),m===Cu?hT(o,n).subscribe({next:p=>r.next(p),error:p=>l(p),complete:()=>u()}):dT(o,n).subscribe({next:p=>{if(typeof p!="object"||!p||Array.isArray(p)){let x=Error("Invalid event: the frame is not a JSON object.");n?.event("HTTP","Event invalid:",{json:p,error:String(x)}),l(x);return}let h=p;if(typeof h.type!="string"||h.type.length===0){let x=Error("Invalid event: the frame carries no event type.");n?.event("HTTP","Event invalid:",{json:p,error:String(x)}),l(x);return}n?.event("HTTP","Event received:",p,{type:h.type}),r.next(p)},error:p=>{if(p?.name==="AbortError"){r.next({type:v.RUN_ERROR,message:p.message||"Request aborted",code:"abort",rawEvent:p}),u();return}return l(p)},complete:()=>u()})}else i||l(Error("No headers event received before data events"))},error:f=>{o.error(f),l(f)},complete:()=>{o.complete()}}),s&&a.unsubscribe(),r.asObservable()},He={TextMessageStart:"TextMessageStart",TextMessageContent:"TextMessageContent",TextMessageEnd:"TextMessageEnd",ActionExecutionStart:"ActionExecutionStart",ActionExecutionArgs:"ActionExecutionArgs",ActionExecutionEnd:"ActionExecutionEnd",ActionExecutionResult:"ActionExecutionResult",AgentStateMessage:"AgentStateMessage",MetaEvent:"MetaEvent",RunStarted:"RunStarted",RunFinished:"RunFinished",RunError:"RunError",NodeStarted:"NodeStarted",NodeFinished:"NodeFinished"},mT=t=>{if(typeof t=="string")return t;if(!Array.isArray(t))return;let e=t.filter(n=>n.type==="text").map(n=>n.text).filter(n=>n.length>0);if(e.length!==0)return e.join(`
|
|
36
|
+
`)};function Sb(t,e){return th(e)&&Qr(`[ag-ui][legacy] The result of tool call '${t}' carries content parts the legacy protocol cannot represent; only its text parts are bridged and the rest is dropped.`),jn(e)}var Qr=t=>{typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(t)},gT=(t,e,n)=>r=>{let o={},i=!0,a=!0,s="",c=null,l=null,u=[],f={},m=!1,p=h=>{typeof h=="object"&&h&&("messages"in h&&delete h.messages,o=h)};return r.pipe(We(h=>{switch(h.type){case v.TEXT_MESSAGE_START:{let x=h;return[{type:He.TextMessageStart,messageId:x.messageId,role:x.role}]}case v.TEXT_MESSAGE_CONTENT:{let x=h;return[{type:He.TextMessageContent,messageId:x.messageId,content:x.delta}]}case v.TEXT_MESSAGE_END:{let x=h;return[{type:He.TextMessageEnd,messageId:x.messageId}]}case v.TOOL_CALL_START:{let x=h;return u.push({id:x.toolCallId,type:"function",function:{name:x.toolCallName,arguments:""}}),a=!0,f[x.toolCallId]=x.toolCallName,[{type:He.ActionExecutionStart,actionExecutionId:x.toolCallId,actionName:x.toolCallName,parentMessageId:x.parentMessageId}]}case v.TOOL_CALL_ARGS:{let x=h,g=u.find(b=>b.id===x.toolCallId);if(!g)return Qr(`[ag-ui][legacy] TOOL_CALL_ARGS: No tool call found with ID '${x.toolCallId}'`),[];g.function.arguments+=x.delta;let w=!1;if(l){let b=l.find(k=>k.tool==g.function.name);if(b)try{let k=JSON.parse(Oi(g.function.arguments));b.tool_argument&&b.tool_argument in k?(p({...o,[b.state_key]:k[b.tool_argument]}),w=!0):b.tool_argument||(p({...o,[b.state_key]:k}),w=!0)}catch{}}return[{type:He.ActionExecutionArgs,actionExecutionId:x.toolCallId,args:x.delta},...w?[{type:He.AgentStateMessage,threadId:t,agentName:n,nodeName:s,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:a}]:[]]}case v.TOOL_CALL_END:{let x=h;return[{type:He.ActionExecutionEnd,actionExecutionId:x.toolCallId}]}case v.TOOL_CALL_RESULT:{let x=h,g=f[x.toolCallId];return(g===void 0||g==="")&&Qr(`[ag-ui][legacy] No usable tool name was seen for tool call '${x.toolCallId}' (${g===void 0?"no TOOL_CALL_START reached this bridge":"its TOOL_CALL_START carried an empty toolCallName"}), so its result is being bridged with the fabricated action name "unknown". Downstream consumers route on that name.`),[{type:He.ActionExecutionResult,actionExecutionId:x.toolCallId,result:Sb(x.toolCallId,x.content),actionName:g||"unknown"}]}case v.RAW:return m||(m=!0,Qr("[ag-ui][legacy] Dropping RAW events: the legacy runtime protocol has no equivalent, so the provider payloads they carry do not reach the legacy stream. Reported once per stream.")),[];case v.CUSTOM:{let x=h;switch(x.name){case"Exit":i=!1;break;case"PredictState":l=x.value;break}return[{type:He.MetaEvent,name:x.name,value:x.value}]}case v.STATE_SNAPSHOT:return p(h.snapshot),[{type:He.AgentStateMessage,threadId:t,agentName:n,nodeName:s,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:a}];case v.STATE_DELTA:{let x=h,g;try{g=ai.applyPatch(o,x.delta,!0,!1).newDocument}catch(w){let b=w instanceof Error?w.message:String(w);return Qr(`[ag-ui][legacy] Failed to apply state patch:
|
|
37
37
|
Current state: ${JSON.stringify(o,null,2)}
|
|
38
|
-
Patch operations: ${JSON.stringify(
|
|
39
|
-
Error: ${b}`),[]}return p(g),[{type:Ue.AgentStateMessage,threadId:e,agentName:n,nodeName:s,runId:t,running:i,role:"assistant",state:JSON.stringify(o),active:a}]}case v.MESSAGES_SNAPSHOT:return l=h.messages,[{type:Ue.AgentStateMessage,threadId:e,agentName:n,nodeName:s,runId:t,running:i,role:"assistant",state:JSON.stringify({...o,...l?{messages:l}:{}}),active:!0}];case v.RUN_STARTED:return[];case v.RUN_FINISHED:{if(l&&(o.messages=l),Object.keys(o).length===0)return[];let E=null;if(l)try{E=iT(l)}catch(g){return[{type:Ue.RunError,message:g.message}]}return[{type:Ue.AgentStateMessage,threadId:e,agentName:n,nodeName:s,runId:t,running:i,role:"assistant",state:JSON.stringify({...o,...E?{messages:E}:{}}),active:!1}]}case v.RUN_ERROR:{let E=h;return[{type:Ue.RunError,message:E.message,code:E.code}]}case v.STEP_STARTED:return s=h.stepName,u=[],c=null,[{type:Ue.AgentStateMessage,threadId:e,agentName:n,nodeName:s,runId:t,running:i,role:"assistant",state:JSON.stringify(o),active:!0}];case v.STEP_FINISHED:return u=[],c=null,[{type:Ue.AgentStateMessage,threadId:e,agentName:n,nodeName:s,runId:t,running:i,role:"assistant",state:JSON.stringify(o),active:!1}];default:return[]}}))};function iT(e){let t=[];for(let n of e)if(n.role==="assistant"||n.role==="user"||n.role==="system"){let r=rT(n.content);if(r){let o={id:n.id,role:n.role,content:r};t.push(o)}if(n.role==="assistant"&&n.toolCalls&&n.toolCalls.length>0)for(let o of n.toolCalls){let i;try{i=JSON.parse(o.function.arguments)}catch(s){throw Error(`Failed to parse arguments for tool call '${o.id}' (${o.function.name}): ${s.message}`)}let a={id:o.id,name:o.function.name,arguments:i,parentMessageId:n.id};t.push(a)}}else if(n.role==="tool"){let r="unknown";for(let i of e)if(i.role==="assistant"&&i.toolCalls?.length){for(let a of i.toolCalls)if(a.id===n.toolCallId){r=a.function.name;break}}let o={id:n.id,result:fb(n.toolCallId,n.content),actionExecutionId:n.toolCallId,actionName:r};t.push(o)}return t}var aT=e=>e.kind==="tool"?e.fields.toolCallId:e.fields.messageId,sT=e=>e==="tool"?"toolCallId":"messageId",Ba=(e,t,n,r,o)=>{if(r!==void 0&&r!==o)throw Error(`Cannot continue ${e} '${t}': chunk ${n} '${r}' does not match the open stream's ${n} ${o===void 0?"(absent)":`'${o}'`}.`)},ja=(e,t)=>t.metadata===void 0?e:{...e,metadata:t.metadata},Ru=(e,t)=>{let n=ja(e,t);return t.rawEvent===void 0?n:{...n,rawEvent:t.rawEvent}},Fu=e=>new Set(Object.keys(e.shape)),lT=Fu(nu),cT=Fu(ru),uT=Fu(iu),Cu=(e,t)=>{let n;for(let r of Object.keys(e))t.has(r)||((n??={})[r]=e[r]);return n},dT=e=>{typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`[ag-ui][transform] ${e} Set SUPPRESS_TRANSFORMATION_WARNINGS=true to silence.`)},Nu=(e,t,n,r)=>{if(t===void 0||n||e.length===0)return;let o=e[e.length-1],i=Object.keys(t).filter(a=>Object.prototype.hasOwnProperty.call(o,a));i.length>0&&dT(`A ${r} carried ${i.map(a=>`'${a}'`).join(", ")}, which the synthesized ${String(o.type)} already describes. The synthesized value is kept and the chunk's is dropped \u2014 this stage does not judge a described field, so the producer's value cannot be substituted for its own.`),e[e.length-1]={...t,...o}},Wa=e=>t=>{let n=_n(e),r=new Map,o=l=>{let c=r.get(l);if(!c)return[];switch(r.delete(l),c.kind){case"text":{let u={type:v.TEXT_MESSAGE_END,messageId:c.fields.messageId,...c.fields.subagentRunId!==void 0&&{subagentRunId:c.fields.subagentRunId}};return n?.event("TRANSFORM","TEXT_MESSAGE_END",u,{messageId:u.messageId}),[u]}case"tool":{let u={type:v.TOOL_CALL_END,toolCallId:c.fields.toolCallId,...c.fields.subagentRunId!==void 0&&{subagentRunId:c.fields.subagentRunId}};return n?.event("TRANSFORM","TOOL_CALL_END",u,{toolCallId:u.toolCallId}),[u]}case"reasoning":{let u={type:v.REASONING_MESSAGE_END,messageId:c.fields.messageId,...c.fields.subagentRunId!==void 0&&{subagentRunId:c.fields.subagentRunId}};return n?.event("TRANSFORM","REASONING_MESSAGE_END",u,{messageId:u.messageId}),[u]}}},i=()=>[...r.keys()].flatMap(l=>o(l)),a=(l,c)=>{for(let[u,f]of r)if(f.kind===l&&aT(f)===c)return{owner:u}},s=(l,c,u,f,m)=>{if(c!==void 0){let h=a(l,c);if(h){if(u!==void 0&&u!==h.owner)throw Error(`Cannot continue ${m} '${c}': chunk subagentRunId '${u}' does not match the open stream's subagent '${h.owner??"(the parent agent)"}'.`);return h.owner}return u}if(u!==void 0)return u;if(r.get(void 0)?.kind===l)return;let p=[...r.entries()].filter(([,h])=>h.kind===l);if(p.length===1)return p[0][0];if(p.length>1)throw Error(`Ambiguous ${f}: it carries neither a ${sT(l)} nor a subagentRunId, but ${p.length} lanes have an open ${m}. Attribute the chunk to the subagent it belongs to.`)};return t.pipe(je(l=>{switch(l.type){case v.TEXT_MESSAGE_START:case v.TEXT_MESSAGE_CONTENT:case v.TEXT_MESSAGE_END:case v.TOOL_CALL_START:case v.TOOL_CALL_ARGS:case v.TOOL_CALL_END:case v.TOOL_CALL_RESULT:case v.STATE_SNAPSHOT:case v.STATE_DELTA:case v.CUSTOM:case v.STEP_STARTED:case v.STEP_FINISHED:case v.REASONING_START:case v.REASONING_MESSAGE_START:case v.REASONING_MESSAGE_CONTENT:case v.REASONING_MESSAGE_END:case v.REASONING_END:return[...o(l.subagentRunId??void 0),l];case v.RUN_STARTED:case v.RUN_FINISHED:case v.RUN_ERROR:case v.MESSAGES_SNAPSHOT:return[...i(),l];case v.RAW:case v.ACTIVITY_SNAPSHOT:case v.ACTIVITY_DELTA:case v.REASONING_ENCRYPTED_VALUE:case v.SUBAGENT_STARTED:return[l];case v.SUBAGENT_FINISHED:case v.SUBAGENT_ERROR:{let c=l.subagentRunId;return c==null?[l]:[...o(c),l]}case v.TEXT_MESSAGE_CHUNK:{let c=l,u=Cu(l,lT),f=s("text",c.messageId,c.subagentRunId??void 0,"TEXT_MESSAGE_CHUNK","text message"),m=r.get(f),p=[],h=!1,E;if(m?.kind==="text"&&(c.messageId===void 0||c.messageId===m.fields.messageId))Ba("text message",m.fields.messageId,"role",c.role,m.fields.role),Ba("text message",m.fields.messageId,"name",c.name,m.fields.name),E=m.fields;else{if(p.push(...o(f)),c.messageId===void 0)throw Error("First TEXT_MESSAGE_CHUNK must have a messageId");E={messageId:c.messageId,role:c.role===void 0?"assistant":c.role,name:c.name,subagentRunId:c.subagentRunId},r.set(f,{kind:"text",fields:E});let g=ja({type:v.TEXT_MESSAGE_START,messageId:c.messageId,role:E.role,...c.name!==void 0&&{name:c.name},...c.subagentRunId!==void 0&&{subagentRunId:c.subagentRunId}},c);p.push(g),n?.event("TRANSFORM","TEXT_MESSAGE_START",g,{messageId:c.messageId})}if(c.delta!==void 0||c.rawEvent!==void 0){let g=c.subagentRunId===void 0?E.subagentRunId:c.subagentRunId,_=Ru({...u,type:v.TEXT_MESSAGE_CONTENT,messageId:E.messageId,delta:c.delta===void 0?"":c.delta,...g!==void 0&&{subagentRunId:g}},c);p.push(_),h=!0,n?.event("TRANSFORM","TEXT_MESSAGE_CONTENT",_,{messageId:E.messageId})}if(p.length===0&&(c.metadata!==void 0||c.rawEvent!==void 0||c.subagentRunId===null||u!==void 0)){let g=c.subagentRunId===void 0?E.subagentRunId:c.subagentRunId;p.push({...u,type:v.TEXT_MESSAGE_CONTENT,messageId:E.messageId,delta:"",...c.metadata!==void 0&&{metadata:c.metadata},...c.rawEvent!==void 0&&{rawEvent:c.rawEvent},...g!==void 0&&{subagentRunId:g}}),h=!0}return Nu(p,u,h,"TEXT_MESSAGE_CHUNK"),p}case v.TOOL_CALL_CHUNK:{let c=l,u=Cu(l,cT),f=s("tool",c.toolCallId,c.subagentRunId??void 0,"TOOL_CALL_CHUNK","tool call"),m=r.get(f),p=[],h=!1,E;if(m?.kind==="tool"&&(c.toolCallId===void 0||c.toolCallId===m.fields.toolCallId))Ba("tool call",m.fields.toolCallId,"toolCallName",c.toolCallName,m.fields.toolCallName),Ba("tool call",m.fields.toolCallId,"parentMessageId",c.parentMessageId,m.fields.parentMessageId),E=m.fields;else{if(p.push(...o(f)),c.toolCallId===void 0)throw Error("First TOOL_CALL_CHUNK must have a toolCallId");if(c.toolCallName===void 0)throw Error("First TOOL_CALL_CHUNK must have a toolCallName");E={toolCallId:c.toolCallId,toolCallName:c.toolCallName,parentMessageId:c.parentMessageId,subagentRunId:c.subagentRunId},r.set(f,{kind:"tool",fields:E});let g=ja({type:v.TOOL_CALL_START,toolCallId:c.toolCallId,toolCallName:c.toolCallName,...c.parentMessageId!==void 0&&{parentMessageId:c.parentMessageId},...c.subagentRunId!==void 0&&{subagentRunId:c.subagentRunId}},c);p.push(g),n?.event("TRANSFORM","TOOL_CALL_START",g,{toolCallId:c.toolCallId,toolCallName:c.toolCallName})}if(c.delta!==void 0||c.rawEvent!==void 0){let g=c.subagentRunId===void 0?E.subagentRunId:c.subagentRunId,_=Ru({...u,type:v.TOOL_CALL_ARGS,toolCallId:E.toolCallId,delta:c.delta===void 0?"":c.delta,...g!==void 0&&{subagentRunId:g}},c);p.push(_),h=!0,n?.event("TRANSFORM","TOOL_CALL_ARGS",_,{toolCallId:E.toolCallId})}if(p.length===0&&(c.metadata!==void 0||c.rawEvent!==void 0||c.subagentRunId===null||u!==void 0)){let g=c.subagentRunId===void 0?E.subagentRunId:c.subagentRunId;p.push({...u,type:v.TOOL_CALL_ARGS,toolCallId:E.toolCallId,delta:"",...c.metadata!==void 0&&{metadata:c.metadata},...c.rawEvent!==void 0&&{rawEvent:c.rawEvent},...g!==void 0&&{subagentRunId:g}}),h=!0}return Nu(p,u,h,"TOOL_CALL_CHUNK"),p}case v.REASONING_MESSAGE_CHUNK:{let c=l,u=Cu(l,uT),f=s("reasoning",c.messageId,c.subagentRunId??void 0,"REASONING_MESSAGE_CHUNK","reasoning message"),m=r.get(f),p=[],h=!1,E;if(m?.kind==="reasoning"&&(c.messageId===void 0||c.messageId===m.fields.messageId))E=m.fields;else{if(p.push(...o(f)),c.messageId===void 0)throw Error("First REASONING_MESSAGE_CHUNK must have a messageId");E={messageId:c.messageId,subagentRunId:c.subagentRunId},r.set(f,{kind:"reasoning",fields:E});let g=ja({type:v.REASONING_MESSAGE_START,messageId:c.messageId,role:"reasoning",...c.subagentRunId!==void 0&&{subagentRunId:c.subagentRunId}},c);p.push(g),n?.event("TRANSFORM","REASONING_MESSAGE_START",g,{messageId:c.messageId})}if(c.delta!==void 0||c.rawEvent!==void 0){let g=c.subagentRunId===void 0?E.subagentRunId:c.subagentRunId,_=Ru({...u,type:v.REASONING_MESSAGE_CONTENT,messageId:E.messageId,delta:c.delta===void 0?"":c.delta,...g!==void 0&&{subagentRunId:g}},c);p.push(_),h=!0,n?.event("TRANSFORM","REASONING_MESSAGE_CONTENT",_,{messageId:E.messageId})}if(p.length===0&&(c.metadata!==void 0||c.rawEvent!==void 0||c.subagentRunId===null||u!==void 0)){let g=c.subagentRunId===void 0?E.subagentRunId:c.subagentRunId;p.push({...u,type:v.REASONING_MESSAGE_CONTENT,messageId:E.messageId,delta:"",...c.metadata!==void 0&&{metadata:c.metadata},...c.rawEvent!==void 0&&{rawEvent:c.rawEvent},...g!==void 0&&{subagentRunId:g}}),h=!0}return Nu(p,u,h,"REASONING_MESSAGE_CHUNK"),p}}return l.type,[l]}),un(()=>{i()}))},lr=Symbol("agui.strip.drop");function Kr(e){let t=e;for(;;){if(t instanceof ji||t instanceof Kc||t instanceof Jc||t instanceof tu||t instanceof Qc){t=t.unwrap();continue}if(t instanceof eu){t=t.def.in;continue}if(t instanceof gg){t=t.def.getter();continue}return t}}function pT(e){let t=e.def;return typeof t?.discriminator=="string"?t.discriminator:void 0}function mb(e){let t=e,n=Array.isArray(t.def?.values)?t.def.values:t.values?Array.from(t.values):void 0;return n&&n.length===1?n[0]:t.value}function hT(e){let t=Kr(e);return t instanceof Xc?mb(t):void 0}function cr(e,t,n,r){let o=Kr(t);if(o instanceof or){if(typeof e!="object"||!e||Array.isArray(e))return e;let i=o.shape,a=e,s={},l=o.meta()?.specOpen===!0;for(let c of Object.keys(a)){let u=Object.prototype.hasOwnProperty.call(i,c)?i[c]:void 0;if(u===void 0){if(l){s[c]=a[c];continue}r.push(`${n}/${c}`);continue}let f=r.length,m=cr(a[c],u,`${n}/${c}`,r);if(m===lr){if(r.length=f,u.safeParse(void 0).success){r.push(`${n}/${c}`);continue}return lr}s[c]=m}return s}if(o instanceof Zi){if(!Array.isArray(e))return e;let i=o.element,a=[];return e.forEach((s,l)=>{let c=r.length,u=cr(s,i,`${n}/${l}`,r);if(u===lr){r.length=c,r.push(`${n}/${l}`);return}a.push(u)}),a}if(o instanceof fg){if(typeof e!="object"||!e||Array.isArray(e))return e;let i=o.def.valueType,a=e,s={};for(let l of Object.keys(a)){let c=r.length,u=cr(a[l],i,`${n}/${l}`,r);if(u===lr){r.length=c,r.push(`${n}/${l}`);continue}s[l]=u}return s}if(o instanceof Vi){let i=o.options,a=pT(o);if(a!==void 0){if(typeof e!="object"||!e||Array.isArray(e))return e;let c=e[a];for(let u of i){let f=Kr(u);if(!(f instanceof or))continue;let m=f.shape;if(hT(m[a])===c)return cr(e,u,n,r)}return lr}let s=i.filter(c=>Kr(c)instanceof or),l=typeof e=="object"&&!!e&&!Array.isArray(e);if(s.length>1&&l)return e;for(let c of i){let u=Kr(c);if(u instanceof Zi&&Array.isArray(e)||u instanceof or&&l)return cr(e,c,n,r)}return e}return e}function gb(e,t){let n=[],r=cr(e,t,"",n);if(r===lr)throw Error("Internal error: the stripper found the whole value unrecognisable, which the schemas are not supposed to allow \u2014 schema/stripper mismatch.");return{value:r,stripped:n}}var fT=new Set(Object.values(v));function mT(e){return fT.has(e.type)}var gT=new Map(au.options.map(e=>{let t=e.shape;return[String(mb(t.type)),e]})),vT=()=>typeof process<"u"&&process.env!==void 0&&!!process.env.SUPPRESS_TRANSFORMATION_WARNINGS;function Uu(e){vT()||console.warn(`[ag-ui][enforce] ${e}`)}var Ou=e=>t=>{let n=_n(e);return t.pipe(je(r=>{if(!mT(r))return Uu(`Dropping unrecognised event '${String(r.type)}': no middleware translated it and the protocol does not describe it.`),n?.event("ENFORCE","Unrecognised event dropped:",r,{type:r.type}),ln;let o=gT.get(r.type);if(o===void 0)throw Error(`No validator for recognised event type '${String(r.type)}'`);let{value:i,stripped:a}=gb(r,o);for(let s of a)Uu(`Removed unrecognised material at '${s}' on ${String(r.type)}. Nothing handled it; see the repo-root DEPRECATIONS.md if it is a retired shape.`);return ce(o.parse(i))}))};function bT(e){let{value:t,stripped:n}=gb(Yl(e,"RunAgentInput"),qi);for(let r of n)Uu(`Removed unrecognised material at '${r}' from the outgoing input.`);return qi.parse(t)}var Qr=class{runNext(e,t){return t.run(e).pipe(Wa(!1))}runNextWithState(e,t){let n=ne(e.messages||[]),r=ne(e.state===void 0?{}:e.state),o=new ui;return hb(e,o,t,[]).subscribe({next:i=>{i.messages!==void 0&&(n=i.messages),i.state!==void 0&&(r=i.state)},error:()=>{}}),this.runNext(e,t).pipe(Ti(async i=>(o.next(i),await new Promise(a=>setTimeout(a,0)),{event:i,messages:ne(n),state:ne(r)})))}},yT=class extends Qr{constructor(e){super(),this.fn=e}run(e,t){return this.fn(e,t)}};function wT(e){return e.startsWith("image/")?"image":e.startsWith("audio/")?"audio":e.startsWith("video/")?"video":"document"}function ET(e){return typeof e=="object"&&!!e&&"type"in e&&e.type==="binary"&&"mimeType"in e&&typeof e.mimeType=="string"}function xT(e){let t=wT(e.mimeType);return e.data?{type:t,source:{type:"data",value:e.data,mimeType:e.mimeType},...e.filename?{metadata:{filename:e.filename}}:{}}:e.url?{type:t,source:{type:"url",value:e.url,mimeType:e.mimeType},...e.filename?{metadata:{filename:e.filename}}:{}}:((typeof process>"u"||process.env===void 0||!process.env.SUPPRESS_TRANSFORMATION_WARNINGS)&&console.warn(`[ag-ui][compat] A binary content part carries only an id ('${e.id??""}') and cannot be converted to a modern media part; a 1.0 peer will not accept it. Provide data or a url. See the repo-root DEPRECATIONS.md.`),e)}function _T(e,t,n){if(typeof e!="object"||!e||!("type"in e)||e.type!==t.type||!("source"in e))return!1;let r=e.source;return typeof r!="object"||!r||!("type"in r)||r.type!==t.source.type||!("value"in r)||r.value!==t.source.value||!("mimeType"in r)||r.mimeType!==t.source.mimeType?!1:!n||"metadata"in e&&typeof e.metadata=="object"&&e.metadata!==null&&"filename"in e.metadata&&e.metadata.filename===n}function Qv(e){let t=e.content;if(!Array.isArray(t))return e;let n=t.flatMap(r=>{if(ET(r)){let o=xT(r);return o.type!=="binary"&&t.some(i=>_T(i,o,r.filename))?[]:[o]}return[r]});return{...e,content:n}}var Pu="THINKING_START",Mu="THINKING_END",eb="THINKING_TEXT_MESSAGE_START",zu="THINKING_TEXT_MESSAGE_CONTENT",Lu="THINKING_TEXT_MESSAGE_END";function Gu(e){return typeof e=="object"&&!!e&&!Array.isArray(e)}var Vt={event:["rawEvent","subagentRunId"],[v.RUN_STARTED]:["parentRunId","input"],[v.RUN_FINISHED]:["result","outcome"],[v.RUN_ERROR]:["usage"],[v.SUBAGENT_FINISHED]:["result"],[v.TOOL_CALL_START]:["parentMessageId"],[v.TOOL_CALL_CHUNK]:["parentMessageId"],[v.TOOL_CALL_RESULT]:["role"],"RUN_FINISHED.outcome":["pendingToolCallIds"],"RUN_FINISHED.usage[]":["provider","reasoningTokens","cachedInputTokens","cacheWriteInputTokens"],RunAgentInput:["forwardedProps"],Tool:["parameters"],ResumeEntry:["payload"],"input content":["metadata"]},ST=new Map(Object.entries(Vt).filter(([e])=>Object.values(v).includes(e))),TT=e=>Ya(e,"an absent field");function Zt(e,t,n,r){if(!Gu(e))return e;let o;for(let i of t)e[i]===null&&(r(n===void 0?`${i}: null`:`${n}.${i}: null`),o??={...e},delete o[i]);return o??e}function Jr(e,t,n){if(!Gu(e)||!Array.isArray(e[t]))return e;let r=e[t],o=r.map(n);return o.some((i,a)=>i!==r[a])?{...e,[t]:o}:e}function vb(e,t){return Jr(e,"content",n=>{if(!Gu(n))return n;switch(n.type){case"image":case"audio":case"video":case"document":return Zt(n,Vt["input content"],`${n.type} input content`,t);default:return n}})}function AT(e,t=TT){let n=Zt(e,Vt.RunAgentInput,"RunAgentInput",t);return n=Jr(n,"tools",r=>Zt(r,Vt.Tool,"Tool",t)),n=Jr(n,"resume",r=>Zt(r,Vt.ResumeEntry,"ResumeEntry",t)),Jr(n,"messages",r=>vb(r,t))}var Hu=class extends Qr{constructor(...e){super(...e),this.currentReasoningId=null,this.currentMessageId=null,this.nullsNoticedThisRun=new Set,this.noticeNullOncePerRun=t=>{this.nullsNoticedThisRun.has(t)||(this.nullsNoticedThisRun.add(t),Ya(t,"an absent field"))}}warn(e,t){Ya(e,t)}mintedContinuationId(e,t){if(t!==null)return t;let n=_e();return this.warnAside(`Minting a messageId ('${n}') for ${e}: no THINKING opener preceded it, so there was no id to continue. The id is this client's invention, not the producer's, and verification will reject the translated event for naming something nothing opened.`),n}warnAside(e){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`[ag-ui][compat] ${e} Set SUPPRESS_TRANSFORMATION_WARNINGS=true to silence.`)}run(e,t){return this.currentReasoningId=null,this.currentMessageId=null,this.nullsNoticedThisRun.clear(),e.messages=e.messages.map(Qv),t.run(e).pipe(_t(n=>this.transformEvent(n)))}transformEvent(e){let t=this.noticeNullOncePerRun;e.type===v.RUN_STARTED&&this.nullsNoticedThisRun.clear(),e=Zt(e,Vt.event,void 0,t);let n=ST.get(e.type);switch(n&&(e=Zt(e,n,e.type,t)),e.type){case Pu:{this.currentReasoningId=_e();let{title:r,...o}=e;return this.warn(Pu,v.REASONING_START),r!==void 0&&this.warnAside(`Dropping ${Pu}.title ${JSON.stringify(r)}: ${v.REASONING_START} has no title field, so the span's label cannot be carried and nothing downstream can recover it.`),{...o,type:v.REASONING_START,messageId:this.currentReasoningId}}case eb:return this.currentMessageId=_e(),this.warn(eb,v.REASONING_MESSAGE_START),{...e,type:v.REASONING_MESSAGE_START,messageId:this.currentMessageId,role:"reasoning"};case zu:{let{delta:r,...o}=e;return this.warn(zu,v.REASONING_MESSAGE_CONTENT),{...o,type:v.REASONING_MESSAGE_CONTENT,messageId:this.mintedContinuationId(zu,this.currentMessageId),delta:r}}case Lu:{let r=this.mintedContinuationId(Lu,this.currentMessageId);return this.currentMessageId=null,this.warn(Lu,v.REASONING_MESSAGE_END),{...e,type:v.REASONING_MESSAGE_END,messageId:r}}case Mu:{let r=this.mintedContinuationId(Mu,this.currentReasoningId);return this.currentReasoningId=null,this.warn(Mu,v.REASONING_END),{...e,type:v.REASONING_END,messageId:r}}case v.RUN_FINISHED:{let r=e,o=Zt(r.outcome,Vt["RUN_FINISHED.outcome"],"RUN_FINISHED.outcome",t);return Jr(o===r.outcome?r:{...r,outcome:o},"usage",i=>Zt(i,Vt["RUN_FINISHED.usage[]"],"RUN_FINISHED.usage[]",t))}case v.MESSAGES_SNAPSHOT:{let r=e;return Array.isArray(r.messages)?{...r,messages:r.messages.map(o=>this.upgradeInboundMessage(o))}:e}case v.RUN_STARTED:{let r=AT(e.input,t),o=r===e.input?e:{...e,input:r},i=o;return!i.input||!Array.isArray(i.input.messages)?o:{...i,input:{...i.input,messages:i.input.messages.map(a=>this.upgradeInboundMessage(a))}}}default:return e}}upgradeInboundMessage(e){e=vb(e,this.noticeNullOncePerRun);let t=e.content;return!Array.isArray(t)||!t.some(n=>typeof n=="object"&&!!n&&n.type==="binary")?e:(this.warn("binary input content","the modern media content parts"),Qv(e))}},kT=()=>e=>cn(()=>{let t=new Hu;return e.pipe(_t(n=>t.transformEvent(n)))});function IT(e,t=new Date){return e.expiresAt===void 0?!1:new Date(e.expiresAt)<=t}function bb(e,t){let n=new Set(e.map(a=>a.id)),r=new Set(Object.keys(t)),o=[...n].filter(a=>!r.has(a));if(o.length>0)throw Error(`buildResumeArray: missing responses for open interrupts: ${o.join(", ")}`);let i=[...r].filter(a=>!n.has(a));if(i.length>0)throw Error(`buildResumeArray: responses reference unknown interrupt ids: ${i.join(", ")}`);return e.map(a=>{let s=t[a.id],l={interruptId:a.id,status:s.status};return s.status==="resolved"&&s.payload!==void 0&&(l.payload=s.payload),s.metadata!==void 0&&(l.metadata=s.metadata),l})}function yb(){return typeof process<"u"&&process.env!==void 0&&!!process.env.SUPPRESS_TRANSFORMATION_WARNINGS}function RT(e){yb()||console.warn(`[ag-ui][compat] Flattening message content for a <=0.0.39 peer DROPS non-text parts (${e.join(", ")}). The peer cannot receive them; upgrade it to keep media content. See the repo-root DEPRECATIONS.md.`)}function CT(e){yb()||console.warn(`[ag-ui][compat] Not flattening message content for a <=0.0.39 peer: ${e} content part(s) claim type "text" but carry a malformed 'text' value. That is a defect in the message, not media the peer cannot represent, and a downgrade must not repair it \u2014 the content is passed on unchanged so the outgoing enforcement boundary reports it. See the repo-root DEPRECATIONS.md.`)}function NT(e){let t=e.content;if(Array.isArray(t)){let n=s=>typeof s=="object"&&!!s&&"type"in s&&s.type==="text",r=s=>n(s)&&typeof s.text=="string",o=t.filter(s=>n(s)&&!r(s));if(o.length>0)return CT(o.length),e;let i=t.filter(s=>!r(s)).map(s=>typeof s=="object"&&s&&"type"in s?String(s.type):typeof s);i.length>0&&RT(i);let a=t.filter(r).map(s=>s.text).join("");return{...e,content:a}}return typeof t=="string"?e:t===void 0?{...e,content:""}:e}var OT=class extends Qr{run(e,t){let{parentRunId:n,...r}=e,o={...r,messages:r.messages.map(NT)};return this.runNext(o,t)}},tb="THINKING_START",nb="THINKING_END",rb="THINKING_TEXT_MESSAGE_START",ob="THINKING_TEXT_MESSAGE_CONTENT",ib="THINKING_TEXT_MESSAGE_END",PT=class extends Qr{constructor(...e){super(...e),this.currentReasoningId=null,this.currentMessageId=null}warnAboutTransformation(e,t){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`AG-UI is converting ${e} to ${t}. To remove this warning, upgrade your AG-UI integration package (e.g. @ag-ui/langgraph). To surpress it, set SUPPRESS_TRANSFORMATION_WARNINGS=true in your .env file.`)}run(e,t){return this.currentReasoningId=null,this.currentMessageId=null,this.runNext(e,t).pipe(_t(n=>this.transformEvent(n)))}transformEvent(e){switch(e.type){case tb:{this.currentReasoningId=_e();let{title:t,...n}=e;return this.warnAboutTransformation(tb,v.REASONING_START),{...n,type:v.REASONING_START,messageId:this.currentReasoningId}}case rb:return this.currentMessageId=_e(),this.warnAboutTransformation(rb,v.REASONING_MESSAGE_START),{...e,type:v.REASONING_MESSAGE_START,messageId:this.currentMessageId,role:"reasoning"};case ob:{let{delta:t,...n}=e;return this.warnAboutTransformation(ob,v.REASONING_MESSAGE_CONTENT),{...n,type:v.REASONING_MESSAGE_CONTENT,messageId:this.currentMessageId??_e(),delta:t}}case ib:{let t=this.currentMessageId??_e();return this.warnAboutTransformation(ib,v.REASONING_MESSAGE_END),{...e,type:v.REASONING_MESSAGE_END,messageId:t}}case nb:{let t=this.currentReasoningId??_e();return this.warnAboutTransformation(nb,v.REASONING_END),{...e,type:v.REASONING_END,messageId:t}}default:return e}}},ab="SUBAGENT_STARTED",sb="SUBAGENT_FINISHED",lb="SUBAGENT_ERROR";function qa(e){if(e&&typeof e=="object"&&"subagentRunId"in e){let{subagentRunId:t,...n}=e;return n}return e}function cb(e){return e.map(t=>qa(t))}var MT=class extends Qr{warnDroppedLifecycleEvent(e){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`AG-UI is dropping ${e} because the target agent predates subagent support. To remove this warning, upgrade your AG-UI integration package. To suppress it, set SUPPRESS_TRANSFORMATION_WARNINGS=true in your .env file.`)}run(e,t){let n={...e,messages:(e.messages??[]).map(r=>qa(r))};return this.runNext(n,t).pipe(ki(r=>{let o=r.type;(o===ab||o===sb||o===lb)&&this.warnDroppedLifecycleEvent(o)}),cc(r=>{let o=r.type;return o!==ab&&o!==sb&&o!==lb}),_t(r=>{let o=qa(r);if(o.type===v.MESSAGES_SNAPSHOT){let i=o;if(Array.isArray(i.messages))return{...i,messages:cb(i.messages)}}if(o.type===v.RUN_FINISHED){let i=o;if(i.outcome&&Array.isArray(i.outcome.interrupts))return{...i,outcome:{...i.outcome,interrupts:i.outcome.interrupts.map(a=>qa(a))}}}if(o.type===v.RUN_STARTED){let i=o;if(i.input&&Array.isArray(i.input.messages))return{...i,input:{...i.input,messages:cb(i.input.messages)}}}return o}))}},Za="1.0.3",ub=!1,db=new WeakSet,zT=(e,t)=>/^\d+\.\d+$/.test(e)?En(e,t)>0?"newer":"not-newer":"uninterpretable",pb=e=>{let t=e.protocolVersion;if(!(t===void 0||t===rn))switch(zT(t,rn)){case"uninterpretable":console.warn(`[ag-ui] The producer declared protocol version '${t}', which this client cannot interpret.`);return;case"newer":console.warn(`[ag-ui] The producer speaks protocol ${t}; this client speaks ${rn}. Unrecognised material will be stripped with warnings.`);return;case"not-newer":return}},LT=class wb{resolvePeerCeiling(t){if(this.resolvingPeerCeiling)return Za;let n=Object.getOwnPropertyDescriptor(this,"maxVersion"),r=Object.getOwnPropertyDescriptor(this,"maxProtocolVersion"),o=Object.getPrototypeOf(this);for(;o&&o!==wb.prototype;)n??=Object.getOwnPropertyDescriptor(o,"maxVersion"),r??=Object.getOwnPropertyDescriptor(o,"maxProtocolVersion"),o=Object.getPrototypeOf(o);if(t==="maxVersion"&&n)return Za;let i=t==="maxProtocolVersion"?n:r;if(!i)return Za;this.resolvingPeerCeiling=!0;try{return i.get?i.get.call(this):i.value}finally{this.resolvingPeerCeiling=!1}}get maxProtocolVersion(){return this.resolvePeerCeiling("maxProtocolVersion")}get maxVersion(){return!this.resolvingPeerCeiling&&!ub&&(ub=!0,console.warn("[ag-ui] AbstractAgent.maxVersion is deprecated \u2014 use maxProtocolVersion. Same value; the new name says whose version it is and that it is a ceiling.")),this.resolvePeerCeiling("maxVersion")}get debug(){return this._debug}set debug(t){this._debug=Va(t),this._debugLogger=ku(this._debug)}get debugLogger(){return this._debugLogger}set debugLogger(t){typeof t=="boolean"?this._debugLogger=t?ku(Va(!0)):void 0:this._debugLogger=t}resolvedCeilingDuringConstruction(){let t=this.maxProtocolVersion;if(typeof t!="string"||!Au(t))throw new j(`maxProtocolVersion resolved to ${JSON.stringify(t)} during construction, which is not a version this client can compare. A ceiling read from an instance field is not available yet \u2014 return a literal from the getter.`);return t}constructor({agentId:t,description:n,threadId:r,initialMessages:o,initialState:i,debug:a}={}){this.subscribers=[],this.isRunning=!1,this.pendingInterrupts=[],this.middlewares=[],this.resolvingPeerCeiling=!1,this.agentId=t,this.description=n??"",this.threadId=r??$t(),this.messages=ne(o??[]),this.state=ne(i??{}),this._debug=Va(a),this._debugLogger=ku(this._debug);let s=this.resolvedCeilingDuringConstruction();En(s,"0.0.39")<=0&&this.middlewares.unshift(new OT),En(s,"0.0.45")<=0&&this.middlewares.unshift(new PT),En(s,"0.0.57")<=0&&this.middlewares.unshift(new MT)}subscribe(t){return this.subscribers.push(t),{unsubscribe:()=>{this.subscribers=this.subscribers.filter(n=>n!==t)}}}use(...t){let n=t.map(r=>typeof r=="function"?new yT(r):r);return this.middlewares.push(...n),this}async runAgent(t,n){try{this.isRunning=!0,this.agentId=this.agentId??$t();let r=this.prepareRunAgentInput(t);this.debugLogger?.lifecycle("LIFECYCLE","Run started:",{agentId:this.agentId,threadId:this.threadId});let o,i=new Set(this.messages.map(c=>c.id)),a=[{onRunStartedEvent:({event:c})=>pb(c),onRunFinishedEvent:c=>{c.outcome==="success"&&(o=c.result)}},...this.subscribers,n??{}];db.add(r),await this.onInitialize(r,a),this.activeRunDetach$=new xt;let s;this.activeRunCompletionPromise=new Promise(c=>{s=c}),await Si(ci(()=>[...this.middlewares,new Hu].reduceRight((c,u)=>({run:f=>u.run(f,c),get messages(){return c.messages},get state(){return c.state}}),this).run(r),Ou(this.debugLogger),Wa(this.debugLogger),Iu(this.debugLogger),c=>c.pipe(Ai(this.activeRunDetach$)),c=>this.applyBeforeSourceError(r,c,a),Jn(c=>(this.debugLogger?.lifecycle("LIFECYCLE","Run errored:",{agentId:this.agentId,error:c instanceof Error?c.message:String(c)}),this.isRunning=!1,this.onError(r,c,a))),un(()=>{this.debugLogger?.lifecycle("LIFECYCLE","Run finished:",{agentId:this.agentId,threadId:this.threadId}),this.isRunning=!1,this.onFinalize(r,a),s?.(),s=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(ce(null)));let l=ne(this.messages).filter(c=>!i.has(c.id));return{result:o,newMessages:l}}finally{this.isRunning=!1}}connect(t){throw new Xl}async connectAgent(t,n){try{this.isRunning=!0,this.agentId=this.agentId??$t();let r=this.prepareRunAgentInput(t),o,i=new Set(this.messages.map(c=>c.id)),a=[{onRunStartedEvent:({event:c})=>pb(c),onRunFinishedEvent:c=>{c.outcome==="success"&&(o=c.result)}},...this.subscribers,n??{}];await this.onInitialize(r,a),this.activeRunDetach$=new xt;let s;this.activeRunCompletionPromise=new Promise(c=>{s=c}),await Si(ci(()=>cn(()=>this.connect(r)),c=>Ou(this.debugLogger)(kT()(c)),Wa(this.debugLogger),Iu(this.debugLogger),c=>c.pipe(Ai(this.activeRunDetach$)),c=>this.applyBeforeSourceError(r,c,a),Jn(c=>(this.isRunning=!1,c instanceof Xl?ln:this.onError(r,c,a))),un(()=>{this.isRunning=!1,this.onFinalize(r,a),s?.(),s=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(ce(null)),{defaultValue:void 0});let l=ne(this.messages).filter(c=>!i.has(c.id));return{result:o,newMessages:l}}finally{this.isRunning=!1}}abortRun(){}async detachActiveRun(){if(!this.activeRunDetach$)return;let t=this.activeRunCompletionPromise??Promise.resolve();this.activeRunDetach$.next(),this.activeRunDetach$?.complete(),await t}applyBeforeSourceError(t,n,r){return cn(()=>{let o,i=n.pipe(Jn(a=>(o={error:a},ln)));return this.processApplyEvents(t,this.apply(t,i,r),r).pipe(uc(cn(()=>{let a=o;return a?F(()=>a.error):ln})))})}apply(t,n,r){return hb(t,n,this,r,this.debugLogger)}processApplyEvents(t,n,r){return n.pipe(ki(o=>{o.messages&&(this.messages=o.messages,r.forEach(i=>{i.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),o.state!==void 0&&(this.state=o.state,r.forEach(i=>{i.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})}))}))}prepareRunAgentInput(t){let n=ne(this.messages);for(let o of n)o.subagentRunId===null&&delete o.subagentRunId;let r=n.filter(o=>o.role!=="activity");return{threadId:this.threadId,runId:t?.runId||$t(),...En(this.maxProtocolVersion,Za)>=0&&{protocolVersion:rn},tools:ne(t?.tools??[]),context:ne(t?.context??[]),forwardedProps:ne(t?.forwardedProps??{}),state:ne(this.state),messages:r,...t?.resume===void 0?{}:{resume:ne(t.resume)}}}async onInitialize(t,n){if(db.has(t)&&this.pendingInterrupts.length>0){let o=new Set((t.resume??[]).map(a=>a.interruptId)),i=this.pendingInterrupts.map(a=>a.id).filter(a=>!o.has(a));if(i.length>0)throw new j(`Thread has ${i.length} pending interrupt(s) not addressed by resume: ${i.join(", ")}`);for(let a of this.pendingInterrupts)if(IT(a)&&(t.resume??[]).find(s=>s.interruptId===a.id)?.status!=="cancelled")throw new j(`Interrupt ${a.id} expired at ${a.expiresAt} and can no longer be answered. Cancel it to continue the thread.`)}let r=await ie(n,this.messages,this.state,(o,i,a)=>o.onRunInitialized?.({messages:i,state:a,agent:this,input:t}));if(r.messages!==void 0||r.state!==void 0){if(r.messages){this.messages=r.messages;for(let o of r.messages)o.subagentRunId===null&&delete o.subagentRunId;t.messages=r.messages.filter(o=>o.role!=="activity"),n.forEach(o=>{o.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})}r.state!==void 0&&(this.state=r.state,t.state=r.state,n.forEach(o=>{o.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})}))}}onError(t,n,r){return Ct(ie(r,this.messages,this.state,(o,i,a)=>o.onRunFailed?.({error:n,messages:i,state:a,agent:this,input:t}))).pipe(_t(o=>{let i=o;if((i.messages!==void 0||i.state!==void 0)&&(i.messages!==void 0&&(this.messages=i.messages,r.forEach(a=>{a.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),i.state!==void 0&&(this.state=i.state,r.forEach(a=>{a.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})}))),i.stopPropagation!==!0){let a=String(n);if(!(n.name==="AbortError"||n.message==="Fetch is aborted"||n.message==="signal is aborted without reason"||n.message==="component unmounted"||a==="component unmounted"))throw console.error("Agent execution failed:",n),n}return{}}))}async onFinalize(t,n){let r=await ie(n,this.messages,this.state,(o,i,a)=>o.onRunFinalized?.({messages:i,state:a,agent:this,input:t}));(r.messages!==void 0||r.state!==void 0)&&(r.messages!==void 0&&(this.messages=r.messages,n.forEach(o=>{o.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:t})})),r.state!==void 0&&(this.state=r.state,n.forEach(o=>{o.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:t})})))}clone(){let t=Object.create(Object.getPrototypeOf(this));return t.agentId=this.agentId,t.description=this.description,t.threadId=this.threadId,t.messages=ne(this.messages),t.state=ne(this.state),t._debug=this._debug,t._debugLogger=this._debugLogger,t.isRunning=this.isRunning,t.subscribers=[...this.subscribers],t.middlewares=[...this.middlewares],t.pendingInterrupts=ne(this.pendingInterrupts),t}addMessage(t){this.messages.push(t),(async()=>{for(let n of this.subscribers)await n.onNewMessage?.({message:t,messages:this.messages,state:this.state,agent:this});if(t.role==="assistant"&&t.toolCalls)for(let n of t.toolCalls)for(let r of this.subscribers)await r.onNewToolCall?.({toolCall:n,messages:this.messages,state:this.state,agent:this});for(let n of this.subscribers)await n.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}addMessages(t){this.messages.push(...t),(async()=>{for(let n of t){for(let r of this.subscribers)await r.onNewMessage?.({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 o.onNewToolCall?.({toolCall:r,messages:this.messages,state:this.state,agent:this})}for(let n of this.subscribers)await n.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setMessages(t){this.messages=ne(t),(async()=>{for(let n of this.subscribers)await n.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setState(t){this.state=ne(t),(async()=>{for(let n of this.subscribers)await n.onStateChanged?.({messages:this.messages,state:this.state,agent:this})})()}legacy_to_be_removed_runAgentBridged(t){this.agentId=this.agentId??$t();let n=this.prepareRunAgentInput(t);return[...this.middlewares,new Hu].reduceRight((r,o)=>({run:i=>o.run(i,r),get messages(){return r.messages},get state(){return r.state}}),this).run(n).pipe(Ou(this.debugLogger),Wa(this.debugLogger),Iu(this.debugLogger),oT(this.threadId,n.runId,this.agentId),r=>r.pipe(_t(o=>(this.debugLogger?.event("LEGACY","Event:",o,{type:o.type}),o))))}};function DT(e){if(!Array.isArray(e.messages))return e;let t=!1,n=e.messages.map(r=>{if(r.subagentRunId===null){t=!0;let o={...r};return delete o.subagentRunId,o}return r});return t?{...e,messages:n}:e}var Eb=class extends LT{requestInit(e){return{method:"POST",headers:{...this.headers,"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify(DT(e)),signal:this.abortController.signal}}runAgent(e,t){return this.abortController=e?.abortController??new AbortController,super.runAgent(e,t)}abortRun(){this.abortController.abort(),super.abortRun()}constructor(e){super(e),this.abortController=new AbortController,this.url=e.url,this.headers=ne(e.headers??{}),this.fetch=e.fetch??((t,n)=>fetch(t,n))}run(e){return nT(J0(()=>this.fetch(this.url,this.requestInit(bT(e)))),this.debugLogger)}clone(){let e=super.clone();e.url=this.url,e.headers=ne(this.headers??{}),e.fetch=this.fetch;let t=new AbortController,n=this.abortController.signal;return n.aborted&&t.abort(n.reason),e.abortController=t,e}};$e(tr());function ot(e,t){return t===void 0?e:{...e,credentials:t}}function Xa(e){if(e.newThread!==void 0)return e.newThread();let t=_e();return e.setActiveThread(t),t}function Ka(e,t,n,r){if(t.length===0)return;let o=new URL(String(e),location.href).origin;o===location.origin||n.includes(o)||r.has(o)||(r.add(o),console.warn(`<ag-ui-chat>: sending host credentials (${t.join(", ")}) to ${o}, which is not this page's origin (${location.origin}). Those headers are the page's own authentication, and whichever server answers the browser's preflight receives them \u2014 so a URL attribute built from a query parameter or from tenant-authored configuration is a channel for the token to leave on. If this destination is deliberate, name it in \`trustedOrigins\` to confirm it and silence this notice. Reported once per origin.`))}function ur(e){return e.split(",").map(t=>t.trim()).filter(t=>t!=="")}function Ja(e,t,n=new Set){let r=new Set(n);for(let s of e)s.role==="tool"&&r.add(s.toolCallId);let o=[],i=[],a=!1;for(let s of e){let l=s.role==="assistant"?$T(s.toolCalls):[];s.role==="tool"||l.length>0&&!a||(o.push(...i.map(t)),i=[]),o.push(s),a=s.role==="tool";for(let u of l)r.has(u)||(r.add(u),i.push(u))}return o.length+i.length===e.length?e:(o.push(...i.map(t)),o)}function $T(e){return Array.isArray(e)?e.map(t=>Object(t).id).filter(t=>typeof t=="string"):[]}function Qa(e,t){return Object(e.metadata)[t]??e[t]}var fe={title:"Assistant",chatHistory:"Chat history",closeHistory:"Close history",searchConversations:"Search conversations",queued:"Waiting to send",removeQueued:'Do not send "{text}"',noMatches:"No conversations match that.",chatMoved:"Moved this panel out of the way",chatMinimised:"Minimised this panel",undo:"Undo",newChat:"New chat",collapse:"Collapse",expand:"Expand",expandUnread:"Expand \u2014 {count} unread",toggleTheme:"Toggle theme",copyCode:"Copy",copied:"Copied",copyFailed:"Copy failed",checkpoints:"Continue a run",noCheckpoints:"Nothing to continue yet.",resumeRun:"Resume",forkRun:"Fork",forkedRun:"branched",greeting:"Hello, {name}",greetingNoName:"Hello there",conversation:"Conversation",jumpToLatest:"Jump to latest",announceResponding:"Assistant is responding",announceAnswerReady:"Assistant answered",announceAwaitingDecision:"{count} action is waiting for your approval",announceStopped:"Response stopped",announceFailed:"The response failed",thinking:"Assistant is thinking\u2026",thoughts:"Thoughts",stopped:"\u23F9 Stopped",connectionLost:"Connection lost",noResult:"No result returned.",callNotFinished:"Not finished: the run ended or moved on before this tool call returned a result.",declinedAction:"User declined the action.",confirmCheckFailed:"Not run: the check that decides whether this action needs the user's confirmation failed.",navigating:"Navigating\u2026",historyReplaced:"The server replaced this conversation's history. Reload to see the updated transcript.",chartUndrawable:"A chart could not be drawn from the data sent, so it was removed.",historyCompacted:"Earlier turns condensed to fit the context window ({count} removed)",usingSkill:"Using skill {name}",runInterrupted:"The previous response didn\u2019t finish \u2014 the page changed before it arrived.",pageMoved:"The page changed since you last looked at it. Call read_page to see the current page, then retry.",attachmentsStillUploading:"{n} file still uploading \u2014 it was not sent with this message and is still attached.",notConnected:"This chat isn\u2019t connected to an agent, so the message wasn\u2019t sent.",continueNeedsTurn:"Type the next turn in the composer first, then pick a run to continue.",continueWhileRunning:"Wait for the current answer or stop it, then pick a run to continue.",continueWhileLoading:"Wait for the conversation to finish loading, then pick a run to continue.",skillNeeds:"\u201C{title}\u201D needs {fields} \u2014 fill it in below, then send.",message:"Message",inputPlaceholder:"Ask anything\u2026",send:"Send",stop:"Stop",attachFiles:"Attach files",recordVoice:"Record voice",stopRecording:"Stop recording",transcribing:"Transcribing\u2026",transcriptionFailed:"Transcription failed",recordingLimit:"Stopped at the {n}-minute limit \u2014 transcribing what was recorded.",toolRunning:"running\u2026",toolDeferred:"waiting for you",toolDone:"\u2713 done",toolError:"\u26A0 error",toolDeclined:"\u2298 declined",toolInterrupted:"\u25CC not finished",resizePanel:"Resize the chat panel",decisionApproved:"approved by you",decisionDeclined:"declined by you",argumentsLabel:"Arguments",resultLabel:"Result",errorLabel:"Error",declinedLabel:"Declined",interruptedLabel:"Not finished",details:"Details",subAgentWorking:"Working\u2026",subAgentDelegatedTo:"Delegated to {agent}",subAgentFinished:"{agent} finished",subAgentFailed:"The sub-agent failed",subAgentSteps:"Steps the sub-agent took",approvalEditArgs:"Edit the arguments before approving",approvalArgsInvalid:"That is not valid JSON, so nothing was sent.",approvalArgsNotAnObject:"Arguments have to be a JSON object.",suggestions:"Suggested follow-ups",messageActions:"Message actions",quoteSelection:"Quote",copyMessage:"Copy message",retryMessage:"Try again",feedbackUp:"Good answer",feedbackDown:"Poor answer",confirmAction:"Confirm action",confirmAlways:"Always allow",confirmRun:"Run \u201C{tool}\u201D?",confirm:"Confirm",cancel:"Cancel",approveAction:"Approve action",approvalPrompt:"Approve this action?",approve:"Approve",deny:"Deny",askUserAction:"Question",otherOption:"Other\u2026",answerPlaceholder:"Type your answer\u2026",submit:"Submit",chats:"Chats",noConversations:"No conversations yet.",rename:"Rename",renameConversation:"Rename conversation",delete:"Delete",deleteConversation:"Delete conversation",deletePrompt:"Delete?",tooLarge:"Too large (max {size})",fileTypeNotAllowed:"File type not allowed",uploadFailed:"upload failed",retry:"Retry",retryUpload:"Retry upload",remove:"Remove",removeAttachment:"Remove attachment",justNow:"just now",minutesAgo:"{n}m ago",hoursAgo:"{n}h ago",daysAgo:"{n}d ago",weeksAgo:"{n}w ago"};function Bu(e){let t={...fe};for(let n of Object.keys(e)){let r=e[n];r!==void 0&&(t[n]=r)}return t}function UT(e){let t=document.createElement("input");return t.type="text",t.className="question-input",t.setAttribute("part","question-input"),t.placeholder=e,t}function Zu(e,t,n={}){let r=n.strings??fe,o=t.options??[],i=o.length>0,a=!i||t.allowCustom===!0;return new Promise(s=>{let l=document.createElement("div");l.className="question",l.setAttribute("part","question"),l.setAttribute("role","group"),l.setAttribute("aria-label",r.askUserAction);let c=document.createElement("div");c.className="question-body",c.setAttribute("part","question-body"),c.textContent=t.question;let u=document.createElement("div");u.className="question-options",u.setAttribute("part","question-options");let f=`q-${o.length}-${t.question.length}`,m=[];for(let w of o){let S=document.createElement("label");S.className="question-choice",S.setAttribute("part","question-choice");let x=document.createElement("input");x.type="radio",x.name=f,x.value=w,x.setAttribute("part","question-radio");let I=document.createElement("span");I.setAttribute("part","question-choice-text"),I.textContent=w,S.append(x,I),u.appendChild(S),m.push(x)}let p=null,h=null;if(a){if(h=UT(r.answerPlaceholder),i){let w=document.createElement("label");w.className="question-choice",w.setAttribute("part","question-choice"),p=document.createElement("input"),p.type="radio",p.name=f,p.value="",p.setAttribute("part","question-radio");let S=document.createElement("span");S.setAttribute("part","question-choice-text"),S.textContent=r.otherOption,w.append(p,S),u.appendChild(w),h.disabled=!0}u.appendChild(h)}let E=document.createElement("div");E.className="question-actions",E.setAttribute("part","question-actions");let g=document.createElement("button");g.type="button",g.className="question-btn",g.setAttribute("part","question-button"),g.textContent=r.submit,E.appendChild(g);let _=!1,b=()=>{let w=m.find(S=>S.checked);if(w!==void 0)return w.value;if(h!==null&&(p===null||p.checked)){let S=h.value.trim();return S===""?null:S}return null},k=()=>{h!==null&&p!==null&&(h.disabled=!p.checked),g.disabled=b()===null},O=w=>{if(!_){_=!0,g.disabled=!0;for(let S of m)S.disabled=!0;p!==null&&(p.disabled=!0),h!==null&&(h.disabled=!0),l.setAttribute("data-resolved",w===""?"cancelled":"answered"),s(w)}};for(let w of[...m,...p!==null?[p]:[]])w.addEventListener("change",k);if(h?.addEventListener("input",k),h?.addEventListener("keydown",w=>{if(w.key==="Enter"){w.preventDefault();let S=b();S!==null&&O(S)}}),g.addEventListener("click",()=>{let w=b();w!==null&&O(w)}),n.signal?.addEventListener("abort",()=>O(""),{once:!0}),l.append(c,u,E),e.appendChild(l),n.signal?.aborted===!0){O("");return}k(),(i?m[0]:h)?.focus()})}function Vu(e){let t={};if(!Array.isArray(e))return t;for(let n of e){if(n===null||typeof n!="object")continue;let r=n,o=r.name,i=r.summary,a=r.description;typeof o=="string"&&typeof i=="string"&&(t[o]=typeof a=="string"?{name:o,summary:i,description:a}:{name:o,summary:i})}return t}var es=class{#e;#t={};#n=new Set;#o=new Tr;constructor(t){this.#e=t}register(t){this.#o.register(t)}registerPageState(t){for(let n of qo(t))this.#o.register(n)}has(t){return this.#o.has(t)}defaultTools(){return[...this.#s().map(t=>({name:t.name,description:t.description,parameters:t.parameters})),...this.#o.tools()]}advertise(){let t=this.#e.getTools();return this.#n=new Set(t.map(n=>n.name)),t}wasAdvertised(t){return this.#n.has(t)}resolve(t){let n=this.#s().find(r=>r.name===t);return n!==void 0?n:this.#o.has(t)?this.#o.get(t):null}summary(t){return this.#t[t]?.summary}async fetchCatalog(){let t=this.#e.element.getAttribute("data-tools-url");if(t!==null)try{let n=await fetch(t,this.#e.fetchInit(t));this.#t=Vu(await n.json())}catch{}}#r(){return this.#e.routeMap().length===0?[]:Vl(()=>this.#e.routeMap(),()=>this.#e.navigate())}#i(){let t=this.#e.getPageMap();return t===null?[]:[{name:Ho,description:"Read the current page's structure (fields, buttons, route). Call after acting to observe the result within the same turn.",parameters:{type:"object",properties:{},required:[],[Oe]:"Read the page"},handler:()=>t()}]}#a(){let t=this.#e.element.getAttribute("data-page-actions");if(t===null)return[];let n=new Set(ur(t));return[...Bl(n,r=>this.#e.resolvePageTarget(r)),...n.has(Ir.CHAT)?Pl(this.#e.element):[]]}#s(){return[...this.#r(),...this.#i(),...this.#a(),...this.#c()]}#c(){return this.#e.askUser()?[{name:"ask_user",description:"Ask the user a question and wait for their answer. Provide `options` for a multiple-choice prompt; set `allow_custom` to also accept a free-text answer.",parameters:{type:"object",properties:{question:{type:"string",description:"The question to ask the user."},options:{type:"array",items:{type:"string"},description:"Preset choices offered as radio buttons."},allow_custom:{type:"boolean",description:"Allow a free-text answer in addition to any options."}},required:["question"]},handler:(t,n)=>this.#u(t,n)}]:[]}async#u(t,n){let o={question:typeof t.question=="string"?t.question:""},i=t.options;Array.isArray(i)&&(o.options=i.filter(u=>typeof u=="string")),t.allow_custom===!0&&(o.allowCustom=!0);let a=this.#e.decision.open();this.#e.hidePending();let s=()=>Zu(this.#e.ensureGroup(),o,{signal:a,strings:this.#e.strings()}),l=this.#e.askUserRenderer(),c;if(l===null)c=await s();else try{c=await l.call(this.#e.element,o,{signal:a})}catch(u){c=await this.#d(u,a,n,s)}return this.#e.decision.close(),this.#e.updateEmptyState(),this.#e.follow(),c}#d(t,n,r,o){return n.aborted?Promise.resolve(""):(console.warn(`ag-ui-chat: askUserRenderer failed for tool call ${r}, so the built-in question card asks instead`,t),o())}};function ts(e){if(e.name!==Nl)return null;let t=e.args?.id;return typeof t=="string"&&t!==""?t:null}function xb(e,t){let n=document.createElement("button");return n.type="button",n.className=`approval-btn approval-btn--${e}`,n.setAttribute("part",`approval-button approval-${e}`),n.textContent=t,n}function ju(e,t,n={}){let r=n.strings??fe;return new Promise(o=>{let i=document.createElement("div");i.className="approval",i.setAttribute("part","approval"),t.toolName!==void 0&&i.setAttribute("data-tool-name",t.toolName),i.setAttribute("role","group"),i.setAttribute("aria-label",r.approveAction);let a=document.createElement("div");a.className="approval-body",a.setAttribute("part","approval-body"),a.textContent=t.message??r.approvalPrompt;let s=HT(t,n,r),l=document.createElement("div");l.className="approval-actions",l.setAttribute("part","approval-actions");let c=xb("deny",r.deny),u=xb("approve",r.approve),f=!1,m=p=>{f||(f=!0,c.disabled=!0,u.disabled=!0,i.setAttribute("data-resolved",p?"approved":"denied"),o(p))};if(c.addEventListener("click",()=>m(!1)),u.addEventListener("click",()=>{s!==null&&!s.commit()||m(!0)}),n.signal?.addEventListener("abort",()=>m(!1),{once:!0}),l.append(c,u),i.append(a,...s===null?[]:[s.root],l),e.appendChild(i),n.signal?.aborted===!0){m(!1);return}u.focus()})}function HT(e,t,n){let{onEdit:r}=t;if(r===void 0||e.args===void 0)return null;let o=JSON.stringify(e.args,null,2),i=document.createElement("div");i.className="approval-edit",i.setAttribute("part","approval-edit");let a=document.createElement("textarea");a.className="approval-args",a.setAttribute("part","approval-args"),a.setAttribute("aria-label",n.approvalEditArgs),a.rows=Math.min(10,o.split(`
|
|
40
|
-
`).length),a.value=o;let s=document.createElement("div");return s.className="approval-error",s.setAttribute("part","approval-error"),s.setAttribute("role","alert"),s.hidden=!0,i.append(a,s),{root:i,commit:()=>{if(a.value===o)return!0;let l;try{l=JSON.parse(a.value)}catch{return s.textContent=n.approvalArgsInvalid,s.hidden=!1,a.focus(),!1}return typeof l!="object"||l===null||Array.isArray(l)?(s.textContent=n.approvalArgsNotAnObject,s.hidden=!1,a.focus(),!1):(s.hidden=!0,r(l),!0)}}}function Wu(e,t){let n=document.createElement("button");return n.type="button",n.className=`confirm-btn confirm-btn--${e}`,n.setAttribute("part",`confirm-button confirm-${e}`),n.textContent=t,n}function qu(e,t,n={}){let r=n.strings??fe;return new Promise(o=>{let i=document.createElement("div");i.className="confirm",i.setAttribute("part","confirm"),i.setAttribute("data-tool-name",t.toolName),i.setAttribute("role","group"),i.setAttribute("aria-label",r.confirmAction);let a=document.createElement("div");a.className="confirm-body",a.setAttribute("part","confirm-body"),a.textContent=t.message??ue(r.confirmRun,{tool:t.toolName});let s=document.createElement("pre");s.className="confirm-args",s.setAttribute("part","confirm-args"),s.textContent=JSON.stringify(t.args,null,2),s.hidden=Object.keys(t.args).length===0;let l=document.createElement("div");l.className="confirm-actions",l.setAttribute("part","confirm-actions");let c=Wu("cancel",r.cancel),u=n.onAlwaysAllow===void 0?null:Wu("always",ue(r.confirmAlways,{tool:t.toolName})),f=Wu("confirm",r.confirm),m=!1,p=h=>{m||(m=!0,i.remove(),o(h))};if(c.addEventListener("click",()=>p(!1)),f.addEventListener("click",()=>p(!0)),u?.addEventListener("click",()=>{n.onAlwaysAllow?.(),p(!0)}),n.signal?.addEventListener("abort",()=>p(!1),{once:!0}),l.append(c,...u===null?[]:[u],f),i.append(a,s,l),e.appendChild(i),n.signal?.aborted===!0){p(!1);return}f.focus()})}function Yu(e){return e[_r]===!0}function ns(e){return e[Sr]===!0}var rs=class{#e;#t=new Set;#n=null;constructor(t){this.#e=t}forgetWaivers(){this.#t.clear()}buildContext(){return this.#n=window.location.href,this.#e.getContext()}async execute(t){if(ts(t)!==null)return null;let n=this.#e.tenure(),r=this.#e.conversation(),o=this.#e.threadId(),i=this.#e.transcript.cardFor(t);this.#e.transcript.forgetCard(t.id),this.#e.transcript.setCardElement(t.id,i.element);let a=this.#e.tools.wasAdvertised(t.name)?this.#e.tools.resolve(t.name):null;if(a===null)return this.#e.transcript.isServerSettled(t.id)||i.settle(te.INTERRUPTED,this.#e.strings().callNotFinished),null;if(this.#e.getPageMap()!==null&&t.name!==Ho&&!ns(a.parameters)&&this.#a()){let u=this.#e.strings().pageMoved;return i.settle(te.ERROR,u),this.#e.transcript.showPending(),{content:`Error: ${u}`,error:u,outcome:Ve.FAILED}}let s=this.#e.decision.open(),l=await this.#r(t,a);if(this.#e.decision.close(),s.aborted)return this.#i(i);if(l==="unanswered"){let u=this.#e.strings().confirmCheckFailed;return i.settle(te.DECLINED,u),this.#e.transcript.showPending(),{content:u,outcome:Ve.DENIED}}if(l!==null){let u={toolName:t.name,args:t.args},f=a.parameters[Uo];typeof f=="string"&&(u.message=f);let m=this.#e.decision.open(),p=qu(this.#e.transcript.ensureGroup(),u,{signal:m,strings:this.#e.strings(),...l==="destructive"?{onAlwaysAllow:()=>this.#t.add(t.name)}:{}});this.#e.transcript.updateEmptyState(),this.#e.transcript.follow();let h=await p;if(this.#e.decision.close(),this.#e.tenure()!==n)return null;if(i.recordDecision(h?"approved":"declined"),!h){let E=this.#e.strings().declinedAction;return i.settle(te.DECLINED,E),this.#e.conversation()===r&&this.#e.transcript.showPending(),{content:E,outcome:Ve.DENIED}}if(m.aborted)return this.#i(i)}let c=ns(a.parameters)&&this.#e.navigate()===null;c&&this.#e.conversationStore().saveCheckpoint(o,{toolCallId:t.id});try{let u=await a.handler(t.args,t.id);if(this.#e.tenure()!==n)return null;if(a.render!==void 0&&this.#e.transcript.renderToolOutput(a.render,t),c)return i.settle(te.DONE,this.#e.strings().navigating),{content:"",halt:!0};let f=JSON.stringify(u??null);return i.settle(te.DONE,f),this.#e.conversation()===r&&this.#e.transcript.showPending(),{content:f}}catch(u){if(this.#e.tenure()!==n)return null;c&&this.#e.conversationStore().saveCheckpoint(o,null);let f=u instanceof Error?u.message:String(u);return i.settle(te.ERROR,f),this.#e.conversation()===r&&this.#e.transcript.showPending(),{content:`Error: ${f}`,error:f,outcome:Ve.FAILED}}}async resolveInterrupts(t){let n=this.#e.decision.open();this.#e.announce(ue(this.#e.strings().announceAwaitingDecision,{count:t.length})),this.#e.transcript.hidePending();let r=await Promise.all(t.map(async i=>{let a=i.toolCallId!==void 0?this.#e.transcript.card(i.toolCallId):void 0,s={},l=FT(i)??i.message;l!==void 0&&(s.message=l);let c=a?.element.getAttribute("data-tool-name");c!=null&&(s.toolName=c);let u,f=this.#e.approveWithEdits()&&a!==void 0;f&&(s.args=a.args),a?.mark(te.DEFERRED);let m=()=>ju(a?.approvalSlot??this.#e.transcript.ensureGroup(),s,{signal:n,strings:this.#e.strings(),...f?{onEdit:E=>{u=E}}:{}}),p=this.#e.approvalRenderer(),h;if(p===null)h=await m();else try{h=await p.call(this.#e.element,s,{signal:n})}catch(E){h=await this.#o(E,n,i.id,m)}return a?.recordDecision(h?"approved":"declined"),h?a?.mark(te.PENDING):a?.settle(te.DECLINED,this.#e.strings().declinedAction),{id:i.id,approved:h,editedArgs:u}}));this.#e.transcript.updateEmptyState(),this.#e.transcript.follow(),this.#e.decision.close();let o={};for(let{id:i,approved:a,editedArgs:s}of r)o[i]=a?{status:"resolved",payload:s===void 0?{approved:!0}:{approved:!0,editedArgs:s}}:{status:"cancelled"};return o}#o(t,n,r,o){return n.aborted?Promise.resolve(!1):(console.warn(`ag-ui-chat: approvalRenderer failed for interrupt ${r}, so the built-in approval card asks instead`,t),o())}async#r(t,n){if(this.#e.autoConfirm())return null;let r=this.#e.confirmPredicate();if(r!==null)try{return await r.call(this.#e.element,t.name,t.args)===!0?"predicate":null}catch(o){return console.warn(`ag-ui-chat: confirmPredicate failed for tool ${t.name}, so the call was refused`,o),"unanswered"}return this.#t.has(t.name)?null:Yu(n.parameters)?"destructive":null}#i(t){return t.settle(te.INTERRUPTED,this.#e.strings().callNotFinished),null}#a(){return this.#n!==null&&this.#n!==window.location.href}};function FT(e){let t=e.metadata?.[Uo];return typeof t=="string"&&t.trim()!==""?t:void 0}var GT="http://www.w3.org/2000/svg",Qe={top:20,right:12,bottom:30,left:44},BT=480,ZT=220,VT=220/480,jT=160,WT=320,_b=8,qT=5.6,Sb=["var(--_chart-1)","var(--_chart-2)","var(--_chart-3)","var(--_chart-4)","var(--_chart-5)","var(--_chart-6)"];function Sn(e){return Sb[e%Sb.length]}function Tb(e){let t=Math.max(ZT,e),n=Math.min(WT,Math.max(jT,Math.round(t*VT)));return{width:t,height:n,plotW:t-Qe.left-Qe.right,plotH:n-Qe.top-Qe.bottom}}function Tt(e,t){let n=document.createElementNS(GT,e);for(let[r,o]of Object.entries(t))n.setAttribute(r,String(o));return n}function Ab(e,t){let n=Tt("text",{"font-size":10,fill:"currentColor","fill-opacity":.65,...t});return n.textContent=e,n}function YT(e){let t=[];return e.labels.forEach((n,r)=>{let o=0;for(let i of e.series)o+=i.points[r]??0,t.push(o)}),t}function XT(e){let t=e.kind==="stacked"?YT(e):e.series.flatMap(o=>[...o.points]),n=Math.max(0,...t),r=Math.min(0,...t);return n===r?{min:r,max:n+1}:{min:r,max:n}}function Tn(e,t,n,r){return Qe.top+r.plotH-(e-t)/(n-t)*r.plotH}function Xu(e,t,n){let r=n.plotW/t;return Qe.left+r*e+r/2}function KT(e,t){let n=t.plotW/e.length,r=Math.max(...e.map(o=>o.length))*qT;return Math.max(1,Math.ceil(r/n))}function JT(e,t,n,r,o){for(let a of[r,o]){let s=Tn(a,r,o,n);e.appendChild(Tt("line",{x1:Qe.left,y1:s,x2:n.width-Qe.right,y2:s,stroke:"currentColor","stroke-opacity":a===r?.35:.12})),e.appendChild(Ab(String(Math.round(a)),{x:Qe.left-6,y:s+4,"text-anchor":"end"}))}let i=KT(t.labels,n);t.labels.forEach((a,s)=>{s%i===0&&e.appendChild(Ab(a,{x:Xu(s,t.labels.length,n),y:n.height-Qe.bottom+16,"text-anchor":"middle"}))})}function QT(e,t,n,r,o){let i=n.plotW/t.labels.length,a=i*.7/t.series.length,s=Tn(r,r,o,n);t.series.forEach((l,c)=>{l.points.forEach((u,f)=>{let m=Tn(u,r,o,n);e.appendChild(Tt("rect",{x:Qe.left+i*f+i*.15+a*c,y:m,width:a,height:Math.max(1,s-m),fill:Sn(c),rx:2}))})})}function eA(e,t,n,r,o){let i=n.plotW/t.labels.length,a=i*.7,s=t.labels.map(()=>0);t.series.forEach((l,c)=>{l.points.forEach((u,f)=>{let m=s[f]??0,p=m+u;s[f]=p;let h=Tn(p,r,o,n);e.appendChild(Tt("rect",{x:Qe.left+i*f+i*.15,y:h,width:a,height:Math.max(1,Tn(m,r,o,n)-h),fill:Sn(c)}))})})}function tA(e,t,n,r,o){t.series.forEach((i,a)=>{let s=i.points.map((l,c)=>`${Xu(c,t.labels.length,n)},${Tn(l,r,o,n)}`).join(" ");e.appendChild(Tt("polyline",{points:s,fill:"none",stroke:Sn(a),"stroke-width":2,"stroke-linejoin":"round"}))})}function nA(e,t,n,r,o){t.series.forEach((i,a)=>{i.points.forEach((s,l)=>{e.appendChild(Tt("circle",{cx:Xu(l,t.labels.length,n),cy:Tn(s,r,o,n),r:4,fill:Sn(a),"fill-opacity":.85}))})})}function rA(e,t,n){let r=t.reduce((l,c)=>l+c,0),o=n.width/2,i=Qe.top+n.plotH/2,a=Math.min(n.plotW,n.plotH)/2;if(r===0){e.appendChild(Tt("circle",{cx:o,cy:i,r:a,fill:"none",stroke:"currentColor","stroke-opacity":.3}));return}let s=-Math.PI/2;t.forEach((l,c)=>{let u=l/r*Math.PI*2,f=s+u;if(u>=Math.PI*2)e.appendChild(Tt("circle",{cx:o,cy:i,r:a,fill:Sn(c)}));else{let m=o+a*Math.cos(s),p=i+a*Math.sin(s),h=o+a*Math.cos(f),E=i+a*Math.sin(f),g=u>Math.PI?1:0;e.appendChild(Tt("path",{d:`M ${o} ${i} L ${m} ${p} A ${a} ${a} 0 ${g} 1 ${h} ${E} Z`,fill:Sn(c)}))}s=f})}function kb(e,t){let n=Tt("svg",{viewBox:`0 0 ${t.width} ${t.height}`,width:"100%",role:"img"});if(n.setAttribute("aria-label",e.title??`${e.kind} chart`),e.kind==="pie"){let i=e.series[0];return rA(n,i.points.map(a=>Math.max(0,a)),t),n}let{min:r,max:o}=XT(e);return JT(n,e,t,r,o),e.kind==="bar"?QT(n,e,t,r,o):e.kind==="stacked"?eA(n,e,t,r,o):e.kind==="line"?tA(n,e,t,r,o):nA(n,e,t,r,o),n}function oA(e){if(e.length<2)return null;let t=document.createElement("div");return t.className="chart-legend",t.setAttribute("part","chart-legend"),e.forEach((n,r)=>{let o=document.createElement("span");o.className="chart-legend-item";let i=document.createElement("span");i.className="chart-legend-swatch",i.style.background=Sn(r),o.append(i,document.createTextNode(n)),t.appendChild(o)}),t}function iA(e,t){new ResizeObserver(()=>{t(Math.round(e.clientWidth/_b)*_b)}).observe(e)}function eo(e){if(e.labels.length===0||e.series.length===0)return null;let t=document.createElement("div");if(t.className="chart-block",t.setAttribute("part","chart-block"),e.title!==void 0&&e.title!==""){let i=document.createElement("div");i.className="chart-title",i.setAttribute("part","chart-title"),i.textContent=e.title,t.appendChild(i)}let n=BT,r=kb(e,Tb(n));t.appendChild(r);let o=oA(e.kind==="pie"?e.labels:e.series.map(i=>i.label));return o!==null&&t.appendChild(o),iA(t,i=>{if(i===n)return;n=i;let a=kb(e,Tb(n));r.replaceWith(a),r=a}),t}var aA=["bar","line","pie","scatter","stacked"];function sA(e){return aA.includes(e)?e:"bar"}function lA(e){if(!Array.isArray(e))return null;let t=[];for(let n of e){if(typeof n!="number"||!Number.isFinite(n)||Math.abs(n)>1e15)return null;t.push(n)}return t}function cA(e){if(!Array.isArray(e))return null;for(let t=0;t<e.length;t+=1)if(typeof e[t]!="string")return null;return e}function dr(e){if(typeof e!="object"||e===null)return null;let t=e,n=cA(t.labels);if(n===null||!Array.isArray(t.series))return null;let r=[];for(let a of t.series){if(typeof a!="object"||a===null)return null;let s=a,l=lA(s.points);if(l===null||l.length!==n.length)return null;r.push({label:typeof s.label=="string"?s.label:"",points:l})}if(r.length===0||r.length*n.length>2e4||n.length>2e3)return null;let o=sA(t.kind),i=t.title;return typeof i=="string"?{kind:o,title:i,labels:n,series:r}:{kind:o,labels:n,series:r}}var os="render_chart";function uA(e){let t=dr(e);return t===null?null:eo(t)}function dA(e){let t=dr(e);return t!==null&&t.labels.length>0&&t.series.length>0}var pA="chart not rendered: expected labels (strings) and series, each with one finite number per label";function Ib(){return{name:os,description:"Show a chart in the conversation. Supply the data and the page draws it. Every series must have exactly one point per label.",parameters:{type:"object",properties:{kind:{type:"string",enum:["bar","line","pie","scatter","stacked"]},title:{type:"string"},labels:{type:"array",items:{type:"string"}},series:{type:"array",items:{type:"object",properties:{label:{type:"string"},points:{type:"array",items:{type:"number"}}},required:["points"]}}},required:["labels","series"],"x-summary":"Draw a chart"},handler:e=>dA(e)?"chart rendered":pA,render:uA}}function jt(e){e.style.height="auto",e.style.height=`${e.scrollHeight}px`}function is(e,t,n){let r=document.createElement("slot");return r.name=e,r.className=t,r.innerHTML=n,r}function Rb(e){let{input:t,send:n,attachButton:r,fileInput:o,strings:i,signal:a}=e,s=e.queuedRow;s.className="queued",s.setAttribute("part","queued"),s.setAttribute("role","group"),s.setAttribute("aria-label",i.queued),s.hidden=!0;let l=document.createElement("div");l.className="input-row",l.setAttribute("part","composer");let c=document.createElement("div");c.className="composer",c.setAttribute("part","composer-surface");let u=document.createElement("div");u.className="composer-tools",u.setAttribute("part","composer-tools"),t.className="input",t.setAttribute("part","input"),t.setAttribute("aria-label",i.message),t.rows=1,t.placeholder=i.inputPlaceholder,t.addEventListener("keydown",e.onKeydown,{signal:a}),t.addEventListener("input",e.onInput,{signal:a}),n.className="send",n.type="button",n.setAttribute("part","send"),n.replaceChildren(is("icon-send","send-send",Ep),is("icon-stop","send-stop",xp)),n.title=i.send,n.setAttribute("aria-label",i.send),n.dataset.state="idle",n.addEventListener("click",e.onSend,{signal:a});let f=e.hint;return f.className="skill-hint",f.setAttribute("part","skill-hint"),f.hidden=!0,r.className="attach-btn",r.type="button",r.setAttribute("part","attach-button"),r.replaceChildren(is("icon-attach","attach-glyph",_p)),r.title=i.attachFiles,r.setAttribute("aria-label",i.attachFiles),r.hidden=!0,r.addEventListener("click",()=>o.click(),{signal:a}),o.className="attach-input",o.type="file",o.multiple=!0,o.hidden=!0,o.addEventListener("change",e.onFilesPicked,{signal:a}),e.attachSlot.className="attachment-slot",e.voiceSlot.className="voice-slot",u.append(r,e.voiceSlot,n),c.append(t,u),l.append(c,o),l}function Ku(e,t){return new Promise((n,r)=>{let o=new FormData;o.append("file",e);let i=new XMLHttpRequest;i.open("POST",t.url),i.withCredentials=t.credentials==="include";for(let[l,c]of Object.entries(t.headers??{}))i.setRequestHeader(l,c);let a=t.onProgress;a!==void 0&&i.upload.addEventListener("progress",l=>{l.lengthComputable&&a(l.total===0?0:l.loaded/l.total)}),i.addEventListener("load",()=>{if(i.status>=200&&i.status<300)try{n(hA(JSON.parse(i.responseText)))}catch{r(new Error("upload returned an unreadable response"))}else r(new Error(fA(i)))}),i.addEventListener("error",()=>r(new Error("upload failed"))),i.addEventListener("abort",()=>r(new Error("upload cancelled")));let s=t.signal;s!==void 0&&s.addEventListener("abort",()=>i.abort()),i.send(o)})}function hA(e){if(typeof e!="object"||e===null)throw new Error("not an object");let t=e,n=t.id,r=t.name,o=t.mime,i=t.size,a=t.url;if(typeof n!="string"||typeof r!="string"||typeof o!="string"||typeof i!="number")throw new Error("missing fields");return typeof a=="string"?{id:n,name:r,mime:o,size:i,url:a}:{id:n,name:r,mime:o,size:i}}function fA(e){try{let t=JSON.parse(e.responseText);if(typeof t.error=="string")return t.error}catch{}return`upload failed (${e.status})`}function as(e){let t=document.createElement("div");t.className="attachment-chips",t.setAttribute("part","attachment-chips");for(let n of e)t.appendChild(mA(n));return t}function mA(e){let t=document.createElement("div");t.className="attachment-chip attachment-chip--ready",t.setAttribute("part","attachment-chip");let n=document.createElement("span");n.className="attachment-chip-icon",n.setAttribute("part","attachment-chip-icon"),n.innerHTML=Ju(e.mime),n.setAttribute("aria-hidden","true");let r=document.createElement("span");r.className="attachment-chip-name",r.setAttribute("part","attachment-chip-name"),r.textContent=e.name,r.title=e.name;let o=document.createElement("span");return o.className="attachment-chip-size",o.setAttribute("part","attachment-chip-size"),o.textContent=ss(e.size),t.append(n,r,o),t}function Ju(e){return e.startsWith("image/")?Pp:e==="application/pdf"?Mp:e.startsWith("text/")?zp:Op}function ss(e){if(e<1024)return`${e} B`;let t=["KB","MB","GB"],n=e/1024,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;return`${n<10?Math.round(n*10)/10:Math.round(n)} ${t[r]}`}var ls=class{element;#e;#t;#n=[];constructor(t){this.#e=t,this.#t=t.strings??fe,this.element=document.createElement("div"),this.element.className="attachment-tray",this.element.setAttribute("part","attachment-tray"),this.element.hidden=!0}add(t){let n={localId:_e(),file:t,status:Xe.UPLOADING,progress:0,ref:null,error:"",controller:null};this.#n.push(n);let r=this.#o(t);if(r!==null){n.status=Xe.ERROR,n.error=r,this.#a(),this.#e.onChange?.();return}this.#a(),this.#e.onChange?.(),this.#r(n)}readyRefs(){let t=[];for(let n of this.#n)n.ref!==null&&t.push(n.ref);return t}hasPending(){return this.#n.some(t=>t.status===Xe.UPLOADING)}pendingCount(){return this.#n.filter(t=>t.status===Xe.UPLOADING).length}isEmpty(){return this.#n.length===0}clearReady(){this.#n=this.#n.filter(t=>t.status===Xe.UPLOADING),this.#a()}clear(){for(let t of this.#n)t.controller?.abort();this.#n=[],this.#a()}dispose(){for(let t of this.#n)t.controller?.abort()}#o(t){return this.#e.maxBytes>0&&t.size>this.#e.maxBytes?ue(this.#t.tooLarge,{size:ss(this.#e.maxBytes)}):gA(this.#e.accept,t)?null:this.#t.fileTypeNotAllowed}#r(t){let n=this.#o(t.file);if(n!==null){t.status=Xe.ERROR,t.error=n,this.#a(),this.#e.onChange?.();return}t.status=Xe.UPLOADING,t.progress=0,t.error="";let r=new AbortController;t.controller=r,this.#a(),this.#e.upload(t.file,o=>{t.progress=o,this.#a()},r.signal).then(o=>{t.status=Xe.READY,t.ref=o}).catch(o=>{t.status=Xe.ERROR,t.error=o instanceof Error?o.message:this.#t.uploadFailed}).finally(()=>{t.controller=null,this.#a(),this.#e.onChange?.()})}#i(t){t.controller?.abort(),this.#n=this.#n.filter(n=>n!==t),this.#a(),this.#e.onChange?.()}#a(){this.element.replaceChildren(),this.element.hidden=this.#n.length===0;for(let t of this.#n)this.element.appendChild(this.#s(t))}#s(t){let n=document.createElement("div");n.className=`attachment-chip attachment-chip--${t.status}`,n.setAttribute("part","attachment-chip");let r=document.createElement("span");r.className="attachment-chip-icon",r.setAttribute("part","attachment-chip-icon"),r.innerHTML=Ju(t.file.type),r.setAttribute("aria-hidden","true");let o=document.createElement("span");o.className="attachment-chip-name",o.setAttribute("part","attachment-chip-name"),o.textContent=t.file.name,o.title=t.file.name;let i=document.createElement("span");if(i.className="attachment-chip-size",i.setAttribute("part","attachment-chip-size"),i.textContent=t.status===Xe.ERROR?t.error:ss(t.file.size),n.append(r,o,i),t.status===Xe.UPLOADING){let s=document.createElement("div");s.className="attachment-chip-bar",s.setAttribute("part","attachment-chip-bar");let l=document.createElement("div");l.className="attachment-chip-bar-fill",l.setAttribute("part","attachment-chip-bar-fill"),l.style.width=`${Math.round(t.progress*100)}%`,s.appendChild(l),n.appendChild(s)}if(t.status===Xe.ERROR){let s=document.createElement("button");s.type="button",s.className="attachment-chip-retry",s.setAttribute("part","attachment-chip-retry"),s.title=this.#t.retry,s.setAttribute("aria-label",this.#t.retryUpload),s.textContent="\u21BB",s.addEventListener("click",()=>this.#r(t)),n.appendChild(s)}let a=document.createElement("button");return a.type="button",a.className="attachment-chip-remove",a.setAttribute("part","attachment-chip-remove"),a.title=this.#t.remove,a.setAttribute("aria-label",this.#t.removeAttachment),a.textContent="\u2715",a.addEventListener("click",()=>this.#i(t)),n.appendChild(a),n}};function gA(e,t){let n=ur(e).map(i=>i.toLowerCase());if(n.length===0)return!0;let r=t.type.toLowerCase(),o=t.name.toLowerCase();return n.some(i=>i.startsWith(".")?o.endsWith(i):i.endsWith("/*")?r.startsWith(i.slice(0,-1)):r===i)}var cs=class{#e;#t=null;constructor(t){this.#e=t}get tray(){return this.#t}wire(t){this.#t?.element.remove(),this.#t=null;let n=this.#e.element.getAttribute("data-attachments-url"),r=this.#e.uploadHandler()??this.#n(n);if(r===null)return;let o=this.#e.element.getAttribute("data-attachment-accept")??"",i=new ls({upload:r,maxBytes:this.#o(),accept:o,strings:this.#e.strings(),onChange:()=>this.#c(i)});this.#t=i,this.#e.slot.appendChild(this.#t.element),this.#e.fileInput.accept=o,this.#e.button.hidden=!1,this.#r(t),this.#s(i,t)}attach(t){return this.#t===null?!1:(this.#t.add(t),!0)}onFilesPicked(){let t=this.#e.fileInput,n=t.files;if(n!==null)for(let r of Array.from(n))this.#t?.add(r);t.value=""}#n(t){return t===null?null:(n,r,o)=>Ku(n,{url:t,headers:this.#e.headersFor(t),...this.#e.credentialsOption(),onProgress:r,signal:o})}#o(){let t=this.#e.element.getAttribute("data-attachment-max-bytes");if(t===null)return Rl;let n=Number.parseInt(t,10);return Number.isFinite(n)&&n>=0?n:Rl}#r(t){let n=this.#e.chat;n.addEventListener("dragover",r=>{r.preventDefault(),n.classList.add("chat--dragover")},{signal:t}),n.addEventListener("dragleave",()=>{n.classList.remove("chat--dragover")},{signal:t}),n.addEventListener("drop",r=>{r.preventDefault(),n.classList.remove("chat--dragover");let o=r.dataTransfer?.files;if(o!==void 0)for(let i of Array.from(o))this.#t?.add(i)},{signal:t})}#i(t,n,r){let o=this.#a(),i=n.getData("text/plain");o===null||i.length<o||(t.preventDefault(),r.add(new File([i],`pasted-${Cb()}.txt`,{type:"text/plain"})))}#a(){let t=this.#e.element.getAttribute("data-paste-attach");if(t===null)return Go;if(t==="off")return null;let n=Number.parseInt(t,10);return Number.isNaN(n)||n<=0?(console.warn(`<ag-ui-chat>: data-paste-attach="${t}" is neither "off" nor a positive number of characters, so the default of ${Go} is used.`),Go):n}#s(t,n){this.#e.chat.addEventListener("paste",r=>{let o=r.clipboardData??null;if(o===null)return;let i=Array.from(o.files);if(i.length===0){this.#i(r,o,t);return}o.getData("text/plain")===""&&r.preventDefault();for(let a of i)this.#t?.add(vA(a))},{signal:n})}#c(t){this.#e.element.dispatchEvent(new CustomEvent(xl,{detail:{attachments:t.readyRefs(),pending:t.pendingCount()},bubbles:!0,composed:!0}))}};function Cb(){return new Date().toISOString().replace(/[:.]/g,"-")}function vA(e){if(e.name!=="")return e;let t=e.type.split("/")[1]??e.type,n=Cb();return new File([e],t===""?`pasted-${n}`:`pasted-${n}.${t}`,{type:e.type})}async function Qu(e,t){let n=new FormData;n.append("audio",e,"recording.webm");let r=await fetch(t.url,ot({method:"POST",headers:{...t.headers??{}},body:n},t.credentials));if(!r.ok)throw new Error(await bA(r));let o=await r.json();if(typeof o=="object"&&o!==null&&typeof o.text=="string")return o.text;throw new Error("transcription returned an unreadable response")}async function bA(e){try{let t=await e.json();if(typeof t.error=="string")return t.error}catch{}return`transcription failed (${e.status})`}var Nb=12e4,us=class{element;#e;#t;#n;#o="idle";#r=null;#i=null;#a=[];#s=null;#c=!1;#u=!1;#d={};constructor(t){this.#e=t.transcribe,this.#t=t.onText,this.#n=t.strings??fe,this.element=document.createElement("button"),this.element.type="button",this.element.className="voice-btn",this.element.setAttribute("part","voice-button");let n=document.createElement("slot");n.name="icon-voice",n.innerHTML=Sp,this.element.append(n),this.#y("idle"),this.element.addEventListener("click",()=>{this.toggle()})}async toggle(){if(this.#o==="recording"){this.#p();return}this.#o!=="transcribing"&&await this.#f()}async#f(){let t={};this.#d=t;let n;try{n=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{n=null}if(t!==this.#d||this.#u){for(let o of n?.getTracks()??[])o.stop();return}if(n===null){this.#g(this.#n.transcriptionFailed);return}this.#i=n,this.#a=[],this.#c=!1;let r;try{r=new MediaRecorder(n),r.addEventListener("dataavailable",o=>{this.#a.push(o.data)}),r.addEventListener("stop",()=>{this.#l(r.mimeType)}),this.#r=r,r.start()}catch{this.#g(this.#n.transcriptionFailed);return}this.#s=setTimeout(()=>{this.#c=!0,this.#p()},Nb),this.#y("recording")}#p(){this.#m(),this.#r?.stop()}#m(){this.#s!==null&&(clearTimeout(this.#s),this.#s=null)}dispose(){this.#u=!0,this.#m(),this.#r!==null&&this.#r.state!=="inactive"&&this.#r.stop(),this.#r=null,this.#b()}async#l(t){if(this.#u)return;this.#b(),this.#y("transcribing");let n=new Blob(this.#a,{type:t||"audio/webm"});try{let r=await this.#e(n);if(this.#u)return;this.#y("idle"),this.#c&&(this.element.title=ue(this.#n.recordingLimit,{n:Nb/6e4})),r!==""&&this.#t(r)}catch(r){this.#g(r instanceof Error?r.message:this.#n.transcriptionFailed)}finally{this.#r=null}}#b(){for(let t of this.#i?.getTracks()??[])t.stop();this.#i=null}#g(t){this.#u||(this.#b(),this.#r=null,this.#y("idle"),this.element.title=t)}#y(t){this.#o=t,this.element.dataset.state=t;let n=this.#E(t);this.element.title=n,this.element.setAttribute("aria-label",n),this.element.setAttribute("aria-pressed",String(t==="recording")),this.element.disabled=t==="transcribing"}#E(t){return t==="recording"?this.#n.stopRecording:t==="transcribing"?this.#n.transcribing:this.#n.recordVoice}};var ds=class{#e;#t=null;constructor(t){this.#e=t}wire(){this.#t?.element.remove(),this.#t=null;let t=this.#e.element.getAttribute("data-transcribe-url"),n=this.#e.transcribeHandler()??this.#n(t);n!==null&&(this.#t=new us({transcribe:n,onText:r=>this.#o(r),strings:this.#e.strings()}),this.#e.slot.appendChild(this.#t.element))}dispose(){this.#t?.dispose()}#n(t){return t===null?null:n=>Qu(n,{url:t,headers:this.#e.headersFor(t),...this.#e.credentialsOption()})}#o(t){let n=this.#e.input,r=n.value.trim();n.value=r===""?t:`${r} ${t}`,this.#e.onInput(),n.focus()}};var ps=class{chips;palette;#e;#t=[];#n=!1;#o=!1;#r=[];#i=0;constructor(t){this.#e=t,this.chips=document.createElement("div"),this.chips.className="skill-chips",this.chips.setAttribute("part","skill-chips"),this.chips.hidden=!0,this.palette=document.createElement("div"),this.palette.className="skill-palette",this.palette.setAttribute("part","skill-palette"),this.palette.setAttribute("role","listbox"),this.palette.hidden=!0}setSkills(t){this.#t=t,this.#u()}enableChips(t){this.#n=t,this.#u()}enableSlash(t){this.#o=t}isOpen(){return!this.palette.hidden}onInput(t){this.#o&&t.startsWith("/")?this.#a(t.slice(1)):this.close()}onKeydown(t){return this.isOpen()?t.key==="ArrowDown"?(this.#s(1),!0):t.key==="ArrowUp"?(this.#s(-1),!0):t.key==="Escape"?(this.close(),!0):t.key==="Enter"?(this.#r.slice(this.#i,this.#i+1).forEach(n=>{this.#c(n)}),!0):!1:!1}close(){this.palette.hidden=!0,this.palette.replaceChildren()}#a(t){let n=t.trim().toLowerCase(),r=this.#t.filter(o=>o.name.toLowerCase().includes(n)||o.title.toLowerCase().includes(n));if(r.length===0){this.close();return}this.#r=r,this.#i=0,this.#d(),this.palette.hidden=!1}#s(t){let n=this.#r.length;this.#i=(this.#i+t+n)%n,this.#d()}#c(t){this.close(),this.#e(t)}#u(){this.chips.replaceChildren();let t=this.#n?this.#t.filter(n=>n.chip===!0):[];this.chips.hidden=t.length===0;for(let n of t){let r=document.createElement("button");r.type="button",r.className="skill-chip",r.setAttribute("part","skill-chip"),r.textContent=n.title,r.title=`/${n.name}`,r.addEventListener("click",()=>this.#c(n)),this.chips.appendChild(r)}}#d(){this.palette.replaceChildren(),this.#r.forEach((t,n)=>{let r=document.createElement("button");r.type="button",r.className="skill-item",r.setAttribute("part","skill-item"),r.setAttribute("role","option"),r.setAttribute("aria-selected",n===this.#i?"true":"false");let o=document.createElement("span");o.className="skill-item-title",o.setAttribute("part","skill-item-title");let i=document.createElement("code");if(i.className="skill-item-token",i.setAttribute("part","skill-item-token"),i.textContent=`/${t.name}`,o.append(i,document.createTextNode(` ${t.title}`)),r.appendChild(o),t.description!==void 0){let a=document.createElement("span");a.className="skill-item-desc",a.setAttribute("part","skill-item-desc"),a.textContent=t.description,r.appendChild(a)}r.addEventListener("click",()=>this.#c(t)),this.palette.appendChild(r)})}};var yA=500;function to(e,t=[],n){for(let r of CA(t)){if(!e.contains(r.startContainer)||!e.contains(r.endContainer))continue;let o=document.createRange();o.setStart(r.startContainer,r.startOffset),o.setEnd(r.endContainer,r.endOffset);let i=_A(o).trim();if(i!=="")return{text:i,rect:RA(o,n)}}return null}function ed(e){let t=wA(e);return t.length===0?"":`${xA(t.join(`
|
|
38
|
+
Patch operations: ${JSON.stringify(x.delta,null,2)}
|
|
39
|
+
Error: ${b}`),[]}return p(g),[{type:He.AgentStateMessage,threadId:t,agentName:n,nodeName:s,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:a}]}case v.MESSAGES_SNAPSHOT:return c=h.messages,[{type:He.AgentStateMessage,threadId:t,agentName:n,nodeName:s,runId:e,running:i,role:"assistant",state:JSON.stringify({...o,...c?{messages:c}:{}}),active:!0}];case v.RUN_STARTED:return[];case v.RUN_FINISHED:{if(c&&(o.messages=c),Object.keys(o).length===0)return[];let x=null;if(c)try{x=vT(c)}catch(g){return[{type:He.RunError,message:g.message}]}return[{type:He.AgentStateMessage,threadId:t,agentName:n,nodeName:s,runId:e,running:i,role:"assistant",state:JSON.stringify({...o,...x?{messages:x}:{}}),active:!1}]}case v.RUN_ERROR:{let x=h;return[{type:He.RunError,message:x.message,code:x.code}]}case v.STEP_STARTED:return s=h.stepName,u=[],l=null,[{type:He.AgentStateMessage,threadId:t,agentName:n,nodeName:s,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:!0}];case v.STEP_FINISHED:return u=[],l=null,[{type:He.AgentStateMessage,threadId:t,agentName:n,nodeName:s,runId:e,running:i,role:"assistant",state:JSON.stringify(o),active:!1}];default:return[]}}))};function vT(t){let e=[];for(let n of t)if(n.role==="assistant"||n.role==="user"||n.role==="system"){let r=mT(n.content);if(r){let o={id:n.id,role:n.role,content:r};e.push(o)}if(n.role==="assistant"&&n.toolCalls&&n.toolCalls.length>0)for(let o of n.toolCalls){let i;try{i=JSON.parse(o.function.arguments)}catch(s){throw Error(`Failed to parse arguments for tool call '${o.id}' (${o.function.name}): ${s.message}`)}let a={id:o.id,name:o.function.name,arguments:i,parentMessageId:n.id};e.push(a)}}else if(n.role==="tool"){let r="unknown";for(let i of t)if(i.role==="assistant"&&i.toolCalls?.length){for(let a of i.toolCalls)if(a.id===n.toolCallId){r=a.function.name;break}}let o={id:n.id,result:Sb(n.toolCallId,n.content),actionExecutionId:n.toolCallId,actionName:r};e.push(o)}return e}var bT=t=>t.kind==="tool"?t.fields.toolCallId:t.fields.messageId,yT=t=>t==="tool"?"toolCallId":"messageId",Wa=(t,e,n,r,o)=>{if(r!==void 0&&r!==o)throw Error(`Cannot continue ${t} '${e}': chunk ${n} '${r}' does not match the open stream's ${n} ${o===void 0?"(absent)":`'${o}'`}.`)},Ka=(t,e)=>e.metadata===void 0?t:{...t,metadata:e.metadata},Du=(t,e)=>{let n=Ka(t,e);return e.rawEvent===void 0?n:{...n,rawEvent:e.rawEvent}},Yu=t=>new Set(Object.keys(t.shape)),wT=Yu(uu),ET=Yu(du),xT=Yu(hu),$u=(t,e)=>{let n;for(let r of Object.keys(t))e.has(r)||((n??={})[r]=t[r]);return n},_T=t=>{typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`[ag-ui][transform] ${t} Set SUPPRESS_TRANSFORMATION_WARNINGS=true to silence.`)},Uu=(t,e,n,r)=>{if(e===void 0||n||t.length===0)return;let o=t[t.length-1],i=Object.keys(e).filter(a=>Object.prototype.hasOwnProperty.call(o,a));i.length>0&&_T(`A ${r} carried ${i.map(a=>`'${a}'`).join(", ")}, which the synthesized ${String(o.type)} already describes. The synthesized value is kept and the chunk's is dropped \u2014 this stage does not judge a described field, so the producer's value cannot be substituted for its own.`),t[t.length-1]={...e,...o}},Xa=t=>e=>{let n=kn(t),r=new Map,o=c=>{let l=r.get(c);if(!l)return[];switch(r.delete(c),l.kind){case"text":{let u={type:v.TEXT_MESSAGE_END,messageId:l.fields.messageId,...l.fields.subagentRunId!==void 0&&{subagentRunId:l.fields.subagentRunId}};return n?.event("TRANSFORM","TEXT_MESSAGE_END",u,{messageId:u.messageId}),[u]}case"tool":{let u={type:v.TOOL_CALL_END,toolCallId:l.fields.toolCallId,...l.fields.subagentRunId!==void 0&&{subagentRunId:l.fields.subagentRunId}};return n?.event("TRANSFORM","TOOL_CALL_END",u,{toolCallId:u.toolCallId}),[u]}case"reasoning":{let u={type:v.REASONING_MESSAGE_END,messageId:l.fields.messageId,...l.fields.subagentRunId!==void 0&&{subagentRunId:l.fields.subagentRunId}};return n?.event("TRANSFORM","REASONING_MESSAGE_END",u,{messageId:u.messageId}),[u]}}},i=()=>[...r.keys()].flatMap(c=>o(c)),a=(c,l)=>{for(let[u,f]of r)if(f.kind===c&&bT(f)===l)return{owner:u}},s=(c,l,u,f,m)=>{if(l!==void 0){let h=a(c,l);if(h){if(u!==void 0&&u!==h.owner)throw Error(`Cannot continue ${m} '${l}': chunk subagentRunId '${u}' does not match the open stream's subagent '${h.owner??"(the parent agent)"}'.`);return h.owner}return u}if(u!==void 0)return u;if(r.get(void 0)?.kind===c)return;let p=[...r.entries()].filter(([,h])=>h.kind===c);if(p.length===1)return p[0][0];if(p.length>1)throw Error(`Ambiguous ${f}: it carries neither a ${yT(c)} nor a subagentRunId, but ${p.length} lanes have an open ${m}. Attribute the chunk to the subagent it belongs to.`)};return e.pipe(We(c=>{switch(c.type){case v.TEXT_MESSAGE_START:case v.TEXT_MESSAGE_CONTENT:case v.TEXT_MESSAGE_END:case v.TOOL_CALL_START:case v.TOOL_CALL_ARGS:case v.TOOL_CALL_END:case v.TOOL_CALL_RESULT:case v.STATE_SNAPSHOT:case v.STATE_DELTA:case v.CUSTOM:case v.STEP_STARTED:case v.STEP_FINISHED:case v.REASONING_START:case v.REASONING_MESSAGE_START:case v.REASONING_MESSAGE_CONTENT:case v.REASONING_MESSAGE_END:case v.REASONING_END:return[...o(c.subagentRunId??void 0),c];case v.RUN_STARTED:case v.RUN_FINISHED:case v.RUN_ERROR:case v.MESSAGES_SNAPSHOT:return[...i(),c];case v.RAW:case v.ACTIVITY_SNAPSHOT:case v.ACTIVITY_DELTA:case v.REASONING_ENCRYPTED_VALUE:case v.SUBAGENT_STARTED:return[c];case v.SUBAGENT_FINISHED:case v.SUBAGENT_ERROR:{let l=c.subagentRunId;return l==null?[c]:[...o(l),c]}case v.TEXT_MESSAGE_CHUNK:{let l=c,u=$u(c,wT),f=s("text",l.messageId,l.subagentRunId??void 0,"TEXT_MESSAGE_CHUNK","text message"),m=r.get(f),p=[],h=!1,x;if(m?.kind==="text"&&(l.messageId===void 0||l.messageId===m.fields.messageId))Wa("text message",m.fields.messageId,"role",l.role,m.fields.role),Wa("text message",m.fields.messageId,"name",l.name,m.fields.name),x=m.fields;else{if(p.push(...o(f)),l.messageId===void 0)throw Error("First TEXT_MESSAGE_CHUNK must have a messageId");x={messageId:l.messageId,role:l.role===void 0?"assistant":l.role,name:l.name,subagentRunId:l.subagentRunId},r.set(f,{kind:"text",fields:x});let g=Ka({type:v.TEXT_MESSAGE_START,messageId:l.messageId,role:x.role,...l.name!==void 0&&{name:l.name},...l.subagentRunId!==void 0&&{subagentRunId:l.subagentRunId}},l);p.push(g),n?.event("TRANSFORM","TEXT_MESSAGE_START",g,{messageId:l.messageId})}if(l.delta!==void 0||l.rawEvent!==void 0){let g=l.subagentRunId===void 0?x.subagentRunId:l.subagentRunId,w=Du({...u,type:v.TEXT_MESSAGE_CONTENT,messageId:x.messageId,delta:l.delta===void 0?"":l.delta,...g!==void 0&&{subagentRunId:g}},l);p.push(w),h=!0,n?.event("TRANSFORM","TEXT_MESSAGE_CONTENT",w,{messageId:x.messageId})}if(p.length===0&&(l.metadata!==void 0||l.rawEvent!==void 0||l.subagentRunId===null||u!==void 0)){let g=l.subagentRunId===void 0?x.subagentRunId:l.subagentRunId;p.push({...u,type:v.TEXT_MESSAGE_CONTENT,messageId:x.messageId,delta:"",...l.metadata!==void 0&&{metadata:l.metadata},...l.rawEvent!==void 0&&{rawEvent:l.rawEvent},...g!==void 0&&{subagentRunId:g}}),h=!0}return Uu(p,u,h,"TEXT_MESSAGE_CHUNK"),p}case v.TOOL_CALL_CHUNK:{let l=c,u=$u(c,ET),f=s("tool",l.toolCallId,l.subagentRunId??void 0,"TOOL_CALL_CHUNK","tool call"),m=r.get(f),p=[],h=!1,x;if(m?.kind==="tool"&&(l.toolCallId===void 0||l.toolCallId===m.fields.toolCallId))Wa("tool call",m.fields.toolCallId,"toolCallName",l.toolCallName,m.fields.toolCallName),Wa("tool call",m.fields.toolCallId,"parentMessageId",l.parentMessageId,m.fields.parentMessageId),x=m.fields;else{if(p.push(...o(f)),l.toolCallId===void 0)throw Error("First TOOL_CALL_CHUNK must have a toolCallId");if(l.toolCallName===void 0)throw Error("First TOOL_CALL_CHUNK must have a toolCallName");x={toolCallId:l.toolCallId,toolCallName:l.toolCallName,parentMessageId:l.parentMessageId,subagentRunId:l.subagentRunId},r.set(f,{kind:"tool",fields:x});let g=Ka({type:v.TOOL_CALL_START,toolCallId:l.toolCallId,toolCallName:l.toolCallName,...l.parentMessageId!==void 0&&{parentMessageId:l.parentMessageId},...l.subagentRunId!==void 0&&{subagentRunId:l.subagentRunId}},l);p.push(g),n?.event("TRANSFORM","TOOL_CALL_START",g,{toolCallId:l.toolCallId,toolCallName:l.toolCallName})}if(l.delta!==void 0||l.rawEvent!==void 0){let g=l.subagentRunId===void 0?x.subagentRunId:l.subagentRunId,w=Du({...u,type:v.TOOL_CALL_ARGS,toolCallId:x.toolCallId,delta:l.delta===void 0?"":l.delta,...g!==void 0&&{subagentRunId:g}},l);p.push(w),h=!0,n?.event("TRANSFORM","TOOL_CALL_ARGS",w,{toolCallId:x.toolCallId})}if(p.length===0&&(l.metadata!==void 0||l.rawEvent!==void 0||l.subagentRunId===null||u!==void 0)){let g=l.subagentRunId===void 0?x.subagentRunId:l.subagentRunId;p.push({...u,type:v.TOOL_CALL_ARGS,toolCallId:x.toolCallId,delta:"",...l.metadata!==void 0&&{metadata:l.metadata},...l.rawEvent!==void 0&&{rawEvent:l.rawEvent},...g!==void 0&&{subagentRunId:g}}),h=!0}return Uu(p,u,h,"TOOL_CALL_CHUNK"),p}case v.REASONING_MESSAGE_CHUNK:{let l=c,u=$u(c,xT),f=s("reasoning",l.messageId,l.subagentRunId??void 0,"REASONING_MESSAGE_CHUNK","reasoning message"),m=r.get(f),p=[],h=!1,x;if(m?.kind==="reasoning"&&(l.messageId===void 0||l.messageId===m.fields.messageId))x=m.fields;else{if(p.push(...o(f)),l.messageId===void 0)throw Error("First REASONING_MESSAGE_CHUNK must have a messageId");x={messageId:l.messageId,subagentRunId:l.subagentRunId},r.set(f,{kind:"reasoning",fields:x});let g=Ka({type:v.REASONING_MESSAGE_START,messageId:l.messageId,role:"reasoning",...l.subagentRunId!==void 0&&{subagentRunId:l.subagentRunId}},l);p.push(g),n?.event("TRANSFORM","REASONING_MESSAGE_START",g,{messageId:l.messageId})}if(l.delta!==void 0||l.rawEvent!==void 0){let g=l.subagentRunId===void 0?x.subagentRunId:l.subagentRunId,w=Du({...u,type:v.REASONING_MESSAGE_CONTENT,messageId:x.messageId,delta:l.delta===void 0?"":l.delta,...g!==void 0&&{subagentRunId:g}},l);p.push(w),h=!0,n?.event("TRANSFORM","REASONING_MESSAGE_CONTENT",w,{messageId:x.messageId})}if(p.length===0&&(l.metadata!==void 0||l.rawEvent!==void 0||l.subagentRunId===null||u!==void 0)){let g=l.subagentRunId===void 0?x.subagentRunId:l.subagentRunId;p.push({...u,type:v.REASONING_MESSAGE_CONTENT,messageId:x.messageId,delta:"",...l.metadata!==void 0&&{metadata:l.metadata},...l.rawEvent!==void 0&&{rawEvent:l.rawEvent},...g!==void 0&&{subagentRunId:g}}),h=!0}return Uu(p,u,h,"REASONING_MESSAGE_CHUNK"),p}}return c.type,[c]}),fn(()=>{i()}))},ur=Symbol("agui.strip.drop");function eo(t){let e=t;for(;;){if(e instanceof Ki||e instanceof iu||e instanceof au||e instanceof cu||e instanceof su){e=e.unwrap();continue}if(e instanceof lu){e=e.def.in;continue}if(e instanceof Ag){e=e.def.getter();continue}return e}}function ST(t){let e=t.def;return typeof e?.discriminator=="string"?e.discriminator:void 0}function Tb(t){let e=t,n=Array.isArray(e.def?.values)?e.def.values:e.values?Array.from(e.values):void 0;return n&&n.length===1?n[0]:e.value}function TT(t){let e=eo(t);return e instanceof ou?Tb(e):void 0}function dr(t,e,n,r){let o=eo(e);if(o instanceof ar){if(typeof t!="object"||!t||Array.isArray(t))return t;let i=o.shape,a=t,s={},c=o.meta()?.specOpen===!0;for(let l of Object.keys(a)){let u=Object.prototype.hasOwnProperty.call(i,l)?i[l]:void 0;if(u===void 0){if(c){s[l]=a[l];continue}r.push(`${n}/${l}`);continue}let f=r.length,m=dr(a[l],u,`${n}/${l}`,r);if(m===ur){if(r.length=f,u.safeParse(void 0).success){r.push(`${n}/${l}`);continue}return ur}s[l]=m}return s}if(o instanceof qi){if(!Array.isArray(t))return t;let i=o.element,a=[];return t.forEach((s,c)=>{let l=r.length,u=dr(s,i,`${n}/${c}`,r);if(u===ur){r.length=l,r.push(`${n}/${c}`);return}a.push(u)}),a}if(o instanceof Sg){if(typeof t!="object"||!t||Array.isArray(t))return t;let i=o.def.valueType,a=t,s={};for(let c of Object.keys(a)){let l=r.length,u=dr(a[c],i,`${n}/${c}`,r);if(u===ur){r.length=l,r.push(`${n}/${c}`);continue}s[c]=u}return s}if(o instanceof Yi){let i=o.options,a=ST(o);if(a!==void 0){if(typeof t!="object"||!t||Array.isArray(t))return t;let l=t[a];for(let u of i){let f=eo(u);if(!(f instanceof ar))continue;let m=f.shape;if(TT(m[a])===l)return dr(t,u,n,r)}return ur}let s=i.filter(l=>eo(l)instanceof ar),c=typeof t=="object"&&!!t&&!Array.isArray(t);if(s.length>1&&c)return t;for(let l of i){let u=eo(l);if(u instanceof qi&&Array.isArray(t)||u instanceof ar&&c)return dr(t,l,n,r)}return t}return t}function Ab(t,e){let n=[],r=dr(t,e,"",n);if(r===ur)throw Error("Internal error: the stripper found the whole value unrecognisable, which the schemas are not supposed to allow \u2014 schema/stripper mismatch.");return{value:r,stripped:n}}var AT=new Set(Object.values(v));function kT(t){return AT.has(t.type)}var IT=new Map(fu.options.map(t=>{let e=t.shape;return[String(Tb(e.type)),t]})),RT=()=>typeof process<"u"&&process.env!==void 0&&!!process.env.SUPPRESS_TRANSFORMATION_WARNINGS;function Wu(t){RT()||console.warn(`[ag-ui][enforce] ${t}`)}var Hu=t=>e=>{let n=kn(t);return e.pipe(We(r=>{if(!kT(r))return Wu(`Dropping unrecognised event '${String(r.type)}': no middleware translated it and the protocol does not describe it.`),n?.event("ENFORCE","Unrecognised event dropped:",r,{type:r.type}),pn;let o=IT.get(r.type);if(o===void 0)throw Error(`No validator for recognised event type '${String(r.type)}'`);let{value:i,stripped:a}=Ab(r,o);for(let s of a)Wu(`Removed unrecognised material at '${s}' on ${String(r.type)}. Nothing handled it; see the repo-root DEPRECATIONS.md if it is a retired shape.`);return ue(o.parse(i))}))};function CT(t){let{value:e,stripped:n}=Ab(rc(t,"RunAgentInput"),Ji);for(let r of n)Wu(`Removed unrecognised material at '${r}' from the outgoing input.`);return Ji.parse(e)}var no=class{runNext(t,e){return e.run(t).pipe(Xa(!1))}runNextWithState(t,e){let n=ne(t.messages||[]),r=ne(t.state===void 0?{}:t.state),o=new fi;return _b(t,o,e,[]).subscribe({next:i=>{i.messages!==void 0&&(n=i.messages),i.state!==void 0&&(r=i.state)},error:()=>{}}),this.runNext(t,e).pipe(Ri(async i=>(o.next(i),await new Promise(a=>setTimeout(a,0)),{event:i,messages:ne(n),state:ne(r)})))}},NT=class extends no{constructor(t){super(),this.fn=t}run(t,e){return this.fn(t,e)}};function OT(t){return t.startsWith("image/")?"image":t.startsWith("audio/")?"audio":t.startsWith("video/")?"video":"document"}function PT(t){return typeof t=="object"&&!!t&&"type"in t&&t.type==="binary"&&"mimeType"in t&&typeof t.mimeType=="string"}function MT(t){let e=OT(t.mimeType);return t.data?{type:e,source:{type:"data",value:t.data,mimeType:t.mimeType},...t.filename?{metadata:{filename:t.filename}}:{}}:t.url?{type:e,source:{type:"url",value:t.url,mimeType:t.mimeType},...t.filename?{metadata:{filename:t.filename}}:{}}:((typeof process>"u"||process.env===void 0||!process.env.SUPPRESS_TRANSFORMATION_WARNINGS)&&console.warn(`[ag-ui][compat] A binary content part carries only an id ('${t.id??""}') and cannot be converted to a modern media part; a 1.0 peer will not accept it. Provide data or a url. See the repo-root DEPRECATIONS.md.`),t)}function LT(t,e,n){if(typeof t!="object"||!t||!("type"in t)||t.type!==e.type||!("source"in t))return!1;let r=t.source;return typeof r!="object"||!r||!("type"in r)||r.type!==e.source.type||!("value"in r)||r.value!==e.source.value||!("mimeType"in r)||r.mimeType!==e.source.mimeType?!1:!n||"metadata"in t&&typeof t.metadata=="object"&&t.metadata!==null&&"filename"in t.metadata&&t.metadata.filename===n}function cb(t){let e=t.content;if(!Array.isArray(e))return t;let n=e.flatMap(r=>{if(PT(r)){let o=MT(r);return o.type!=="binary"&&e.some(i=>LT(i,o,r.filename))?[]:[o]}return[r]});return{...t,content:n}}var Fu="THINKING_START",Gu="THINKING_END",ub="THINKING_TEXT_MESSAGE_START",Bu="THINKING_TEXT_MESSAGE_CONTENT",Zu="THINKING_TEXT_MESSAGE_END";function Ku(t){return typeof t=="object"&&!!t&&!Array.isArray(t)}var qt={event:["rawEvent","subagentRunId"],[v.RUN_STARTED]:["parentRunId","input"],[v.RUN_FINISHED]:["result","outcome"],[v.RUN_ERROR]:["usage"],[v.SUBAGENT_FINISHED]:["result"],[v.TOOL_CALL_START]:["parentMessageId"],[v.TOOL_CALL_CHUNK]:["parentMessageId"],[v.TOOL_CALL_RESULT]:["role"],"RUN_FINISHED.outcome":["pendingToolCallIds"],"RUN_FINISHED.usage[]":["provider","reasoningTokens","cachedInputTokens","cacheWriteInputTokens"],RunAgentInput:["forwardedProps"],Tool:["parameters"],ResumeEntry:["payload"],"input content":["metadata"]},zT=new Map(Object.entries(qt).filter(([t])=>Object.values(v).includes(t))),DT=t=>Qa(t,"an absent field");function Wt(t,e,n,r){if(!Ku(t))return t;let o;for(let i of e)t[i]===null&&(r(n===void 0?`${i}: null`:`${n}.${i}: null`),o??={...t},delete o[i]);return o??t}function to(t,e,n){if(!Ku(t)||!Array.isArray(t[e]))return t;let r=t[e],o=r.map(n);return o.some((i,a)=>i!==r[a])?{...t,[e]:o}:t}function kb(t,e){return to(t,"content",n=>{if(!Ku(n))return n;switch(n.type){case"image":case"audio":case"video":case"document":return Wt(n,qt["input content"],`${n.type} input content`,e);default:return n}})}function $T(t,e=DT){let n=Wt(t,qt.RunAgentInput,"RunAgentInput",e);return n=to(n,"tools",r=>Wt(r,qt.Tool,"Tool",e)),n=to(n,"resume",r=>Wt(r,qt.ResumeEntry,"ResumeEntry",e)),to(n,"messages",r=>kb(r,e))}var qu=class extends no{constructor(...t){super(...t),this.currentReasoningId=null,this.currentMessageId=null,this.nullsNoticedThisRun=new Set,this.noticeNullOncePerRun=e=>{this.nullsNoticedThisRun.has(e)||(this.nullsNoticedThisRun.add(e),Qa(e,"an absent field"))}}warn(t,e){Qa(t,e)}mintedContinuationId(t,e){if(e!==null)return e;let n=Se();return this.warnAside(`Minting a messageId ('${n}') for ${t}: no THINKING opener preceded it, so there was no id to continue. The id is this client's invention, not the producer's, and verification will reject the translated event for naming something nothing opened.`),n}warnAside(t){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`[ag-ui][compat] ${t} Set SUPPRESS_TRANSFORMATION_WARNINGS=true to silence.`)}run(t,e){return this.currentReasoningId=null,this.currentMessageId=null,this.nullsNoticedThisRun.clear(),t.messages=t.messages.map(cb),e.run(t).pipe(Tt(n=>this.transformEvent(n)))}transformEvent(t){let e=this.noticeNullOncePerRun;t.type===v.RUN_STARTED&&this.nullsNoticedThisRun.clear(),t=Wt(t,qt.event,void 0,e);let n=zT.get(t.type);switch(n&&(t=Wt(t,n,t.type,e)),t.type){case Fu:{this.currentReasoningId=Se();let{title:r,...o}=t;return this.warn(Fu,v.REASONING_START),r!==void 0&&this.warnAside(`Dropping ${Fu}.title ${JSON.stringify(r)}: ${v.REASONING_START} has no title field, so the span's label cannot be carried and nothing downstream can recover it.`),{...o,type:v.REASONING_START,messageId:this.currentReasoningId}}case ub:return this.currentMessageId=Se(),this.warn(ub,v.REASONING_MESSAGE_START),{...t,type:v.REASONING_MESSAGE_START,messageId:this.currentMessageId,role:"reasoning"};case Bu:{let{delta:r,...o}=t;return this.warn(Bu,v.REASONING_MESSAGE_CONTENT),{...o,type:v.REASONING_MESSAGE_CONTENT,messageId:this.mintedContinuationId(Bu,this.currentMessageId),delta:r}}case Zu:{let r=this.mintedContinuationId(Zu,this.currentMessageId);return this.currentMessageId=null,this.warn(Zu,v.REASONING_MESSAGE_END),{...t,type:v.REASONING_MESSAGE_END,messageId:r}}case Gu:{let r=this.mintedContinuationId(Gu,this.currentReasoningId);return this.currentReasoningId=null,this.warn(Gu,v.REASONING_END),{...t,type:v.REASONING_END,messageId:r}}case v.RUN_FINISHED:{let r=t,o=Wt(r.outcome,qt["RUN_FINISHED.outcome"],"RUN_FINISHED.outcome",e);return to(o===r.outcome?r:{...r,outcome:o},"usage",i=>Wt(i,qt["RUN_FINISHED.usage[]"],"RUN_FINISHED.usage[]",e))}case v.MESSAGES_SNAPSHOT:{let r=t;return Array.isArray(r.messages)?{...r,messages:r.messages.map(o=>this.upgradeInboundMessage(o))}:t}case v.RUN_STARTED:{let r=$T(t.input,e),o=r===t.input?t:{...t,input:r},i=o;return!i.input||!Array.isArray(i.input.messages)?o:{...i,input:{...i.input,messages:i.input.messages.map(a=>this.upgradeInboundMessage(a))}}}default:return t}}upgradeInboundMessage(t){t=kb(t,this.noticeNullOncePerRun);let e=t.content;return!Array.isArray(e)||!e.some(n=>typeof n=="object"&&!!n&&n.type==="binary")?t:(this.warn("binary input content","the modern media content parts"),cb(t))}},UT=()=>t=>hn(()=>{let e=new qu;return t.pipe(Tt(n=>e.transformEvent(n)))});function HT(t,e=new Date){return t.expiresAt===void 0?!1:new Date(t.expiresAt)<=e}function Ib(t,e){let n=new Set(t.map(a=>a.id)),r=new Set(Object.keys(e)),o=[...n].filter(a=>!r.has(a));if(o.length>0)throw Error(`buildResumeArray: missing responses for open interrupts: ${o.join(", ")}`);let i=[...r].filter(a=>!n.has(a));if(i.length>0)throw Error(`buildResumeArray: responses reference unknown interrupt ids: ${i.join(", ")}`);return t.map(a=>{let s=e[a.id],c={interruptId:a.id,status:s.status};return s.status==="resolved"&&s.payload!==void 0&&(c.payload=s.payload),s.metadata!==void 0&&(c.metadata=s.metadata),c})}function Rb(){return typeof process<"u"&&process.env!==void 0&&!!process.env.SUPPRESS_TRANSFORMATION_WARNINGS}function FT(t){Rb()||console.warn(`[ag-ui][compat] Flattening message content for a <=0.0.39 peer DROPS non-text parts (${t.join(", ")}). The peer cannot receive them; upgrade it to keep media content. See the repo-root DEPRECATIONS.md.`)}function GT(t){Rb()||console.warn(`[ag-ui][compat] Not flattening message content for a <=0.0.39 peer: ${t} content part(s) claim type "text" but carry a malformed 'text' value. That is a defect in the message, not media the peer cannot represent, and a downgrade must not repair it \u2014 the content is passed on unchanged so the outgoing enforcement boundary reports it. See the repo-root DEPRECATIONS.md.`)}function BT(t){let e=t.content;if(Array.isArray(e)){let n=s=>typeof s=="object"&&!!s&&"type"in s&&s.type==="text",r=s=>n(s)&&typeof s.text=="string",o=e.filter(s=>n(s)&&!r(s));if(o.length>0)return GT(o.length),t;let i=e.filter(s=>!r(s)).map(s=>typeof s=="object"&&s&&"type"in s?String(s.type):typeof s);i.length>0&&FT(i);let a=e.filter(r).map(s=>s.text).join("");return{...t,content:a}}return typeof e=="string"?t:e===void 0?{...t,content:""}:t}var ZT=class extends no{run(t,e){let{parentRunId:n,...r}=t,o={...r,messages:r.messages.map(BT)};return this.runNext(o,e)}},db="THINKING_START",pb="THINKING_END",hb="THINKING_TEXT_MESSAGE_START",fb="THINKING_TEXT_MESSAGE_CONTENT",mb="THINKING_TEXT_MESSAGE_END",VT=class extends no{constructor(...t){super(...t),this.currentReasoningId=null,this.currentMessageId=null}warnAboutTransformation(t,e){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`AG-UI is converting ${t} to ${e}. To remove this warning, upgrade your AG-UI integration package (e.g. @ag-ui/langgraph). To surpress it, set SUPPRESS_TRANSFORMATION_WARNINGS=true in your .env file.`)}run(t,e){return this.currentReasoningId=null,this.currentMessageId=null,this.runNext(t,e).pipe(Tt(n=>this.transformEvent(n)))}transformEvent(t){switch(t.type){case db:{this.currentReasoningId=Se();let{title:e,...n}=t;return this.warnAboutTransformation(db,v.REASONING_START),{...n,type:v.REASONING_START,messageId:this.currentReasoningId}}case hb:return this.currentMessageId=Se(),this.warnAboutTransformation(hb,v.REASONING_MESSAGE_START),{...t,type:v.REASONING_MESSAGE_START,messageId:this.currentMessageId,role:"reasoning"};case fb:{let{delta:e,...n}=t;return this.warnAboutTransformation(fb,v.REASONING_MESSAGE_CONTENT),{...n,type:v.REASONING_MESSAGE_CONTENT,messageId:this.currentMessageId??Se(),delta:e}}case mb:{let e=this.currentMessageId??Se();return this.warnAboutTransformation(mb,v.REASONING_MESSAGE_END),{...t,type:v.REASONING_MESSAGE_END,messageId:e}}case pb:{let e=this.currentReasoningId??Se();return this.warnAboutTransformation(pb,v.REASONING_END),{...t,type:v.REASONING_END,messageId:e}}default:return t}}},gb="SUBAGENT_STARTED",vb="SUBAGENT_FINISHED",bb="SUBAGENT_ERROR";function Ja(t){if(t&&typeof t=="object"&&"subagentRunId"in t){let{subagentRunId:e,...n}=t;return n}return t}function yb(t){return t.map(e=>Ja(e))}var jT=class extends no{warnDroppedLifecycleEvent(t){typeof process<"u"&&process.env!==void 0&&process.env.SUPPRESS_TRANSFORMATION_WARNINGS||console.warn(`AG-UI is dropping ${t} because the target agent predates subagent support. To remove this warning, upgrade your AG-UI integration package. To suppress it, set SUPPRESS_TRANSFORMATION_WARNINGS=true in your .env file.`)}run(t,e){let n={...t,messages:(t.messages??[]).map(r=>Ja(r))};return this.runNext(n,e).pipe(Ni(r=>{let o=r.type;(o===gb||o===vb||o===bb)&&this.warnDroppedLifecycleEvent(o)}),vc(r=>{let o=r.type;return o!==gb&&o!==vb&&o!==bb}),Tt(r=>{let o=Ja(r);if(o.type===v.MESSAGES_SNAPSHOT){let i=o;if(Array.isArray(i.messages))return{...i,messages:yb(i.messages)}}if(o.type===v.RUN_FINISHED){let i=o;if(i.outcome&&Array.isArray(i.outcome.interrupts))return{...i,outcome:{...i.outcome,interrupts:i.outcome.interrupts.map(a=>Ja(a))}}}if(o.type===v.RUN_STARTED){let i=o;if(i.input&&Array.isArray(i.input.messages))return{...i,input:{...i.input,messages:yb(i.input.messages)}}}return o}))}},qa="1.0.3",wb=!1,Eb=new WeakSet,WT=(t,e)=>/^\d+\.\d+$/.test(t)?Tn(t,e)>0?"newer":"not-newer":"uninterpretable",xb=t=>{let e=t.protocolVersion;if(!(e===void 0||e===ln))switch(WT(e,ln)){case"uninterpretable":console.warn(`[ag-ui] The producer declared protocol version '${e}', which this client cannot interpret.`);return;case"newer":console.warn(`[ag-ui] The producer speaks protocol ${e}; this client speaks ${ln}. Unrecognised material will be stripped with warnings.`);return;case"not-newer":return}},qT=class Cb{resolvePeerCeiling(e){if(this.resolvingPeerCeiling)return qa;let n=Object.getOwnPropertyDescriptor(this,"maxVersion"),r=Object.getOwnPropertyDescriptor(this,"maxProtocolVersion"),o=Object.getPrototypeOf(this);for(;o&&o!==Cb.prototype;)n??=Object.getOwnPropertyDescriptor(o,"maxVersion"),r??=Object.getOwnPropertyDescriptor(o,"maxProtocolVersion"),o=Object.getPrototypeOf(o);if(e==="maxVersion"&&n)return qa;let i=e==="maxProtocolVersion"?n:r;if(!i)return qa;this.resolvingPeerCeiling=!0;try{return i.get?i.get.call(this):i.value}finally{this.resolvingPeerCeiling=!1}}get maxProtocolVersion(){return this.resolvePeerCeiling("maxProtocolVersion")}get maxVersion(){return!this.resolvingPeerCeiling&&!wb&&(wb=!0,console.warn("[ag-ui] AbstractAgent.maxVersion is deprecated \u2014 use maxProtocolVersion. Same value; the new name says whose version it is and that it is a ceiling.")),this.resolvePeerCeiling("maxVersion")}get debug(){return this._debug}set debug(e){this._debug=Ya(e),this._debugLogger=Lu(this._debug)}get debugLogger(){return this._debugLogger}set debugLogger(e){typeof e=="boolean"?this._debugLogger=e?Lu(Ya(!0)):void 0:this._debugLogger=e}resolvedCeilingDuringConstruction(){let e=this.maxProtocolVersion;if(typeof e!="string"||!Mu(e))throw new j(`maxProtocolVersion resolved to ${JSON.stringify(e)} during construction, which is not a version this client can compare. A ceiling read from an instance field is not available yet \u2014 return a literal from the getter.`);return e}constructor({agentId:e,description:n,threadId:r,initialMessages:o,initialState:i,debug:a}={}){this.subscribers=[],this.isRunning=!1,this.pendingInterrupts=[],this.middlewares=[],this.resolvingPeerCeiling=!1,this.agentId=e,this.description=n??"",this.threadId=r??Ft(),this.messages=ne(o??[]),this.state=ne(i??{}),this._debug=Ya(a),this._debugLogger=Lu(this._debug);let s=this.resolvedCeilingDuringConstruction();Tn(s,"0.0.39")<=0&&this.middlewares.unshift(new ZT),Tn(s,"0.0.45")<=0&&this.middlewares.unshift(new VT),Tn(s,"0.0.57")<=0&&this.middlewares.unshift(new jT)}subscribe(e){return this.subscribers.push(e),{unsubscribe:()=>{this.subscribers=this.subscribers.filter(n=>n!==e)}}}use(...e){let n=e.map(r=>typeof r=="function"?new NT(r):r);return this.middlewares.push(...n),this}async runAgent(e,n){try{this.isRunning=!0,this.agentId=this.agentId??Ft();let r=this.prepareRunAgentInput(e);this.debugLogger?.lifecycle("LIFECYCLE","Run started:",{agentId:this.agentId,threadId:this.threadId});let o,i=new Set(this.messages.map(l=>l.id)),a=[{onRunStartedEvent:({event:l})=>xb(l),onRunFinishedEvent:l=>{l.outcome==="success"&&(o=l.result)}},...this.subscribers,n??{}];Eb.add(r),await this.onInitialize(r,a),this.activeRunDetach$=new St;let s;this.activeRunCompletionPromise=new Promise(l=>{s=l}),await Ii(hi(()=>[...this.middlewares,new qu].reduceRight((l,u)=>({run:f=>u.run(f,l),get messages(){return l.messages},get state(){return l.state}}),this).run(r),Hu(this.debugLogger),Xa(this.debugLogger),zu(this.debugLogger),l=>l.pipe(Ci(this.activeRunDetach$)),l=>this.applyBeforeSourceError(r,l,a),er(l=>(this.debugLogger?.lifecycle("LIFECYCLE","Run errored:",{agentId:this.agentId,error:l instanceof Error?l.message:String(l)}),this.isRunning=!1,this.onError(r,l,a))),fn(()=>{this.debugLogger?.lifecycle("LIFECYCLE","Run finished:",{agentId:this.agentId,threadId:this.threadId}),this.isRunning=!1,this.onFinalize(r,a),s?.(),s=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(ue(null)));let c=ne(this.messages).filter(l=>!i.has(l.id));return{result:o,newMessages:c}}finally{this.isRunning=!1}}connect(e){throw new oc}async connectAgent(e,n){try{this.isRunning=!0,this.agentId=this.agentId??Ft();let r=this.prepareRunAgentInput(e),o,i=new Set(this.messages.map(l=>l.id)),a=[{onRunStartedEvent:({event:l})=>xb(l),onRunFinishedEvent:l=>{l.outcome==="success"&&(o=l.result)}},...this.subscribers,n??{}];await this.onInitialize(r,a),this.activeRunDetach$=new St;let s;this.activeRunCompletionPromise=new Promise(l=>{s=l}),await Ii(hi(()=>hn(()=>this.connect(r)),l=>Hu(this.debugLogger)(UT()(l)),Xa(this.debugLogger),zu(this.debugLogger),l=>l.pipe(Ci(this.activeRunDetach$)),l=>this.applyBeforeSourceError(r,l,a),er(l=>(this.isRunning=!1,l instanceof oc?pn:this.onError(r,l,a))),fn(()=>{this.isRunning=!1,this.onFinalize(r,a),s?.(),s=void 0,this.activeRunCompletionPromise=void 0,this.activeRunDetach$=void 0}))(ue(null)),{defaultValue:void 0});let c=ne(this.messages).filter(l=>!i.has(l.id));return{result:o,newMessages:c}}finally{this.isRunning=!1}}abortRun(){}async detachActiveRun(){if(!this.activeRunDetach$)return;let e=this.activeRunCompletionPromise??Promise.resolve();this.activeRunDetach$.next(),this.activeRunDetach$?.complete(),await e}applyBeforeSourceError(e,n,r){return hn(()=>{let o,i=n.pipe(er(a=>(o={error:a},pn)));return this.processApplyEvents(e,this.apply(e,i,r),r).pipe(bc(hn(()=>{let a=o;return a?F(()=>a.error):pn})))})}apply(e,n,r){return _b(e,n,this,r,this.debugLogger)}processApplyEvents(e,n,r){return n.pipe(Ni(o=>{o.messages&&(this.messages=o.messages,r.forEach(i=>{i.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})),o.state!==void 0&&(this.state=o.state,r.forEach(i=>{i.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})}))}))}prepareRunAgentInput(e){let n=ne(this.messages);for(let o of n)o.subagentRunId===null&&delete o.subagentRunId;let r=n.filter(o=>o.role!=="activity");return{threadId:this.threadId,runId:e?.runId||Ft(),...Tn(this.maxProtocolVersion,qa)>=0&&{protocolVersion:ln},tools:ne(e?.tools??[]),context:ne(e?.context??[]),forwardedProps:ne(e?.forwardedProps??{}),state:ne(this.state),messages:r,...e?.resume===void 0?{}:{resume:ne(e.resume)}}}async onInitialize(e,n){if(Eb.has(e)&&this.pendingInterrupts.length>0){let o=new Set((e.resume??[]).map(a=>a.interruptId)),i=this.pendingInterrupts.map(a=>a.id).filter(a=>!o.has(a));if(i.length>0)throw new j(`Thread has ${i.length} pending interrupt(s) not addressed by resume: ${i.join(", ")}`);for(let a of this.pendingInterrupts)if(HT(a)&&(e.resume??[]).find(s=>s.interruptId===a.id)?.status!=="cancelled")throw new j(`Interrupt ${a.id} expired at ${a.expiresAt} and can no longer be answered. Cancel it to continue the thread.`)}let r=await ae(n,this.messages,this.state,(o,i,a)=>o.onRunInitialized?.({messages:i,state:a,agent:this,input:e}));if(r.messages!==void 0||r.state!==void 0){if(r.messages){this.messages=r.messages;for(let o of r.messages)o.subagentRunId===null&&delete o.subagentRunId;e.messages=r.messages.filter(o=>o.role!=="activity"),n.forEach(o=>{o.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})}r.state!==void 0&&(this.state=r.state,e.state=r.state,n.forEach(o=>{o.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})}))}}onError(e,n,r){return Pt(ae(r,this.messages,this.state,(o,i,a)=>o.onRunFailed?.({error:n,messages:i,state:a,agent:this,input:e}))).pipe(Tt(o=>{let i=o;if((i.messages!==void 0||i.state!==void 0)&&(i.messages!==void 0&&(this.messages=i.messages,r.forEach(a=>{a.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})),i.state!==void 0&&(this.state=i.state,r.forEach(a=>{a.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})}))),i.stopPropagation!==!0){let a=String(n);if(!(n.name==="AbortError"||n.message==="Fetch is aborted"||n.message==="signal is aborted without reason"||n.message==="component unmounted"||a==="component unmounted"))throw console.error("Agent execution failed:",n),n}return{}}))}async onFinalize(e,n){let r=await ae(n,this.messages,this.state,(o,i,a)=>o.onRunFinalized?.({messages:i,state:a,agent:this,input:e}));(r.messages!==void 0||r.state!==void 0)&&(r.messages!==void 0&&(this.messages=r.messages,n.forEach(o=>{o.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this,input:e})})),r.state!==void 0&&(this.state=r.state,n.forEach(o=>{o.onStateChanged?.({state:this.state,messages:this.messages,agent:this,input:e})})))}clone(){let e=Object.create(Object.getPrototypeOf(this));return e.agentId=this.agentId,e.description=this.description,e.threadId=this.threadId,e.messages=ne(this.messages),e.state=ne(this.state),e._debug=this._debug,e._debugLogger=this._debugLogger,e.isRunning=this.isRunning,e.subscribers=[...this.subscribers],e.middlewares=[...this.middlewares],e.pendingInterrupts=ne(this.pendingInterrupts),e}addMessage(e){this.messages.push(e),(async()=>{for(let n of this.subscribers)await n.onNewMessage?.({message:e,messages:this.messages,state:this.state,agent:this});if(e.role==="assistant"&&e.toolCalls)for(let n of e.toolCalls)for(let r of this.subscribers)await r.onNewToolCall?.({toolCall:n,messages:this.messages,state:this.state,agent:this});for(let n of this.subscribers)await n.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}addMessages(e){this.messages.push(...e),(async()=>{for(let n of e){for(let r of this.subscribers)await r.onNewMessage?.({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 o.onNewToolCall?.({toolCall:r,messages:this.messages,state:this.state,agent:this})}for(let n of this.subscribers)await n.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setMessages(e){this.messages=ne(e),(async()=>{for(let n of this.subscribers)await n.onMessagesChanged?.({messages:this.messages,state:this.state,agent:this})})()}setState(e){this.state=ne(e),(async()=>{for(let n of this.subscribers)await n.onStateChanged?.({messages:this.messages,state:this.state,agent:this})})()}legacy_to_be_removed_runAgentBridged(e){this.agentId=this.agentId??Ft();let n=this.prepareRunAgentInput(e);return[...this.middlewares,new qu].reduceRight((r,o)=>({run:i=>o.run(i,r),get messages(){return r.messages},get state(){return r.state}}),this).run(n).pipe(Hu(this.debugLogger),Xa(this.debugLogger),zu(this.debugLogger),gT(this.threadId,n.runId,this.agentId),r=>r.pipe(Tt(o=>(this.debugLogger?.event("LEGACY","Event:",o,{type:o.type}),o))))}};function YT(t){if(!Array.isArray(t.messages))return t;let e=!1,n=t.messages.map(r=>{if(r.subagentRunId===null){e=!0;let o={...r};return delete o.subagentRunId,o}return r});return e?{...t,messages:n}:t}var Nb=class extends qT{requestInit(t){return{method:"POST",headers:{...this.headers,"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify(YT(t)),signal:this.abortController.signal}}runAgent(t,e){return this.abortController=t?.abortController??new AbortController,super.runAgent(t,e)}abortRun(){this.abortController.abort(),super.abortRun()}constructor(t){super(t),this.abortController=new AbortController,this.url=t.url,this.headers=ne(t.headers??{}),this.fetch=t.fetch??((e,n)=>fetch(e,n))}run(t){return fT(uT(()=>this.fetch(this.url,this.requestInit(CT(t)))),this.debugLogger)}clone(){let t=super.clone();t.url=this.url,t.headers=ne(this.headers??{}),t.fetch=this.fetch;let e=new AbortController,n=this.abortController.signal;return n.aborted&&e.abort(n.reason),t.abortController=e,t}};Ue(rr());function it(t,e){return e===void 0?t:{...t,credentials:e}}function es(t){if(t.newThread!==void 0)return t.newThread();let e=Se();return t.setActiveThread(e),e}function ts(t,e,n,r){if(e.length===0)return;let o=new URL(String(t),location.href).origin;o===location.origin||n.includes(o)||r.has(o)||(r.add(o),console.warn(`<ag-ui-chat>: sending host credentials (${e.join(", ")}) to ${o}, which is not this page's origin (${location.origin}). Those headers are the page's own authentication, and whichever server answers the browser's preflight receives them \u2014 so a URL attribute built from a query parameter or from tenant-authored configuration is a channel for the token to leave on. If this destination is deliberate, name it in \`trustedOrigins\` to confirm it and silence this notice. Reported once per origin.`))}function pr(t){return t.split(",").map(e=>e.trim()).filter(e=>e!=="")}function ns(t,e,n=new Set){let r=new Set(n);for(let s of t)s.role==="tool"&&r.add(s.toolCallId);let o=[],i=[],a=!1;for(let s of t){let c=s.role==="assistant"?KT(s.toolCalls):[];s.role==="tool"||c.length>0&&!a||(o.push(...i.map(e)),i=[]),o.push(s),a=s.role==="tool";for(let u of c)r.has(u)||(r.add(u),i.push(u))}return o.length+i.length===t.length?t:(o.push(...i.map(e)),o)}function KT(t){return Array.isArray(t)?t.map(e=>Object(e).id).filter(e=>typeof e=="string"):[]}function rs(t,e){return Object(t.metadata)[e]??t[e]}var fe={title:"Assistant",chatHistory:"Chat history",closeHistory:"Close history",searchConversations:"Search conversations",queued:"Waiting to send",removeQueued:'Do not send "{text}"',noMatches:"No conversations match that.",chatMoved:"Moved this panel out of the way",chatMinimised:"Minimised this panel",undo:"Undo",newChat:"New chat",collapse:"Collapse",expand:"Expand",expandUnread:"Expand \u2014 {count} unread",toggleTheme:"Toggle theme",copyCode:"Copy",copied:"Copied",copyFailed:"Copy failed",checkpoints:"Continue a run",noCheckpoints:"Nothing to continue yet.",resumeRun:"Resume",forkRun:"Fork",forkedRun:"branched",greeting:"Hello, {name}",greetingNoName:"Hello there",conversation:"Conversation",jumpToLatest:"Jump to latest",announceResponding:"Assistant is responding",announceAnswerReady:"Assistant answered",announceAwaitingDecision:"{count} action is waiting for your approval",announceStopped:"Response stopped",announceFailed:"The response failed",thinking:"Assistant is thinking\u2026",thoughts:"Thoughts",stopped:"\u23F9 Stopped",connectionLost:"Connection lost",noResult:"No result returned.",callNotFinished:"Not finished: the run ended or moved on before this tool call returned a result.",declinedAction:"User declined the action.",confirmCheckFailed:"Not run: the check that decides whether this action needs the user's confirmation failed.",navigating:"Navigating\u2026",historyReplaced:"The server replaced this conversation's history. Reload to see the updated transcript.",chartUndrawable:"A chart could not be drawn from the data sent, so it was removed.",historyCompacted:"Earlier turns condensed to fit the context window ({count} removed)",usingSkill:"Using skill {name}",runInterrupted:"The previous response didn\u2019t finish \u2014 the page changed before it arrived.",pageMoved:"The page changed since you last looked at it. Call read_page to see the current page, then retry.",attachmentsStillUploading:"{n} file still uploading \u2014 it was not sent with this message and is still attached.",notConnected:"This chat isn\u2019t connected to an agent, so the message wasn\u2019t sent.",continueNeedsTurn:"Type the next turn in the composer first, then pick a run to continue.",continueWhileRunning:"Wait for the current answer or stop it, then pick a run to continue.",continueWhileLoading:"Wait for the conversation to finish loading, then pick a run to continue.",skillNeeds:"\u201C{title}\u201D needs {fields} \u2014 fill it in below, then send.",message:"Message",inputPlaceholder:"Ask anything\u2026",send:"Send",stop:"Stop",attachFiles:"Attach files",recordVoice:"Record voice",stopRecording:"Stop recording",transcribing:"Transcribing\u2026",transcriptionFailed:"Transcription failed",recordingLimit:"Stopped at the {n}-minute limit \u2014 transcribing what was recorded.",toolRunning:"running\u2026",toolDeferred:"waiting for you",toolDone:"\u2713 done",toolError:"\u26A0 error",toolDeclined:"\u2298 declined",toolInterrupted:"\u25CC not finished",resizePanel:"Resize the chat panel",decisionApproved:"approved by you",decisionDeclined:"declined by you",argumentsLabel:"Arguments",resultLabel:"Result",errorLabel:"Error",declinedLabel:"Declined",interruptedLabel:"Not finished",details:"Details",toolGroupSteps:"{count} steps",toolGroupWorking:"Working through {count} steps",toolGroupWorked:"Worked through {count} steps",toolGroupWaiting:"{count} waiting for you",toolGroupFailed:"{count} failed",toolGroupDeclined:"{count} declined",toolStepRepeat:"({n})",subAgentWorking:"Working\u2026",subAgentDelegatedTo:"Delegated to {agent}",subAgentFinished:"{agent} finished",subAgentFailed:"The sub-agent failed",subAgentSteps:"Steps the sub-agent took",approvalEditArgs:"Edit the arguments before approving",approvalArgsInvalid:"That is not valid JSON, so nothing was sent.",approvalArgsNotAnObject:"Arguments have to be a JSON object.",suggestions:"Suggested follow-ups",messageActions:"Message actions",quoteSelection:"Quote",copyMessage:"Copy message",retryMessage:"Try again",feedbackUp:"Good answer",feedbackDown:"Poor answer",confirmAction:"Confirm action",confirmAlways:"Always allow",confirmRun:"Run \u201C{tool}\u201D?",confirm:"Confirm",cancel:"Cancel",approveAction:"Approve action",approvalPrompt:"Approve this action?",approve:"Approve",deny:"Deny",askUserAction:"Question",otherOption:"Other\u2026",answerPlaceholder:"Type your answer\u2026",submit:"Submit",chats:"Chats",noConversations:"No conversations yet.",rename:"Rename",renameConversation:"Rename conversation",delete:"Delete",deleteConversation:"Delete conversation",deletePrompt:"Delete?",tooLarge:"Too large (max {size})",fileTypeNotAllowed:"File type not allowed",uploadFailed:"upload failed",retry:"Retry",retryUpload:"Retry upload",remove:"Remove",removeAttachment:"Remove attachment",justNow:"just now",minutesAgo:"{n}m ago",hoursAgo:"{n}h ago",daysAgo:"{n}d ago",weeksAgo:"{n}w ago"};function Xu(t){let e={...fe};for(let n of Object.keys(t)){let r=t[n];r!==void 0&&(e[n]=r)}return e}function XT(t){let e=document.createElement("input");return e.type="text",e.className="question-input",e.setAttribute("part","question-input"),e.placeholder=t,e}function Ju(t,e,n={}){let r=n.strings??fe,o=e.options??[],i=o.length>0,a=!i||e.allowCustom===!0;return new Promise(s=>{let c=document.createElement("div");c.className="question",c.setAttribute("part","question"),c.setAttribute("role","group"),c.setAttribute("aria-label",r.askUserAction);let l=document.createElement("div");l.className="question-body",l.setAttribute("part","question-body"),l.textContent=e.question;let u=document.createElement("div");u.className="question-options",u.setAttribute("part","question-options");let f=`q-${o.length}-${e.question.length}`,m=[];for(let E of o){let S=document.createElement("label");S.className="question-choice",S.setAttribute("part","question-choice");let _=document.createElement("input");_.type="radio",_.name=f,_.value=E,_.setAttribute("part","question-radio");let I=document.createElement("span");I.setAttribute("part","question-choice-text"),I.textContent=E,S.append(_,I),u.appendChild(S),m.push(_)}let p=null,h=null;if(a){if(h=XT(r.answerPlaceholder),i){let E=document.createElement("label");E.className="question-choice",E.setAttribute("part","question-choice"),p=document.createElement("input"),p.type="radio",p.name=f,p.value="",p.setAttribute("part","question-radio");let S=document.createElement("span");S.setAttribute("part","question-choice-text"),S.textContent=r.otherOption,E.append(p,S),u.appendChild(E),h.disabled=!0}u.appendChild(h)}let x=document.createElement("div");x.className="question-actions",x.setAttribute("part","question-actions");let g=document.createElement("button");g.type="button",g.className="question-btn",g.setAttribute("part","question-button"),g.textContent=r.submit,x.appendChild(g);let w=!1,b=()=>{let E=m.find(S=>S.checked);if(E!==void 0)return E.value;if(h!==null&&(p===null||p.checked)){let S=h.value.trim();return S===""?null:S}return null},k=()=>{h!==null&&p!==null&&(h.disabled=!p.checked),g.disabled=b()===null},O=E=>{if(!w){w=!0,g.disabled=!0;for(let S of m)S.disabled=!0;p!==null&&(p.disabled=!0),h!==null&&(h.disabled=!0),c.setAttribute("data-resolved",E===""?"cancelled":"answered"),s(E)}};for(let E of[...m,...p!==null?[p]:[]])E.addEventListener("change",k);if(h?.addEventListener("input",k),h?.addEventListener("keydown",E=>{if(E.key==="Enter"){E.preventDefault();let S=b();S!==null&&O(S)}}),g.addEventListener("click",()=>{let E=b();E!==null&&O(E)}),n.signal?.addEventListener("abort",()=>O(""),{once:!0}),c.append(l,u,x),t.appendChild(c),n.signal?.aborted===!0){O("");return}k(),(i?m[0]:h)?.focus()})}function Qu(t){let e={};if(!Array.isArray(t))return e;for(let n of t){if(n===null||typeof n!="object")continue;let r=n,o=r.name,i=r.summary,a=r.description;typeof o=="string"&&typeof i=="string"&&(e[o]=typeof a=="string"?{name:o,summary:i,description:a}:{name:o,summary:i})}return e}var os=class{#e;#t={};#n=new Set;#o=new kr;constructor(e){this.#e=e}register(e){this.#o.register(e)}registerPageState(e){for(let n of Jo(e))this.#o.register(n)}has(e){return this.#o.has(e)}defaultTools(){return[...this.#s().map(e=>({name:e.name,description:e.description,parameters:e.parameters})),...this.#o.tools()]}advertise(){let e=this.#e.getTools();return this.#n=new Set(e.map(n=>n.name)),e}wasAdvertised(e){return this.#n.has(e)}resolve(e){let n=this.#s().find(r=>r.name===e);return n!==void 0?n:this.#o.has(e)?this.#o.get(e):null}summary(e){return this.#t[e]?.summary}async fetchCatalog(){let e=this.#e.element.getAttribute("data-tools-url");if(e!==null)try{let n=await fetch(e,this.#e.fetchInit(e));this.#t=Qu(await n.json())}catch{}}#r(){return this.#e.routeMap().length===0?[]:Ql(()=>this.#e.routeMap(),()=>this.#e.navigate())}#i(){let e=this.#e.getPageMap();return e===null?[]:[{name:Vo,description:"Read the current page's structure (fields, buttons, route). Call after acting to observe the result within the same turn.",parameters:{type:"object",properties:{},required:[],[Pe]:"Read the page"},handler:()=>e()}]}#a(){let e=this.#e.element.getAttribute("data-page-actions");if(e===null)return[];let n=new Set(pr(e));return[...Xl(n,r=>this.#e.resolvePageTarget(r)),...n.has(Nr.CHAT)?Hl(this.#e.element):[]]}#s(){return[...this.#r(),...this.#i(),...this.#a(),...this.#l()]}#l(){return this.#e.askUser()?[{name:"ask_user",description:"Ask the user a question and wait for their answer. Provide `options` for a multiple-choice prompt; set `allow_custom` to also accept a free-text answer.",parameters:{type:"object",properties:{question:{type:"string",description:"The question to ask the user."},options:{type:"array",items:{type:"string"},description:"Preset choices offered as radio buttons."},allow_custom:{type:"boolean",description:"Allow a free-text answer in addition to any options."}},required:["question"]},handler:(e,n)=>this.#u(e,n)}]:[]}async#u(e,n){let o={question:typeof e.question=="string"?e.question:""},i=e.options;Array.isArray(i)&&(o.options=i.filter(u=>typeof u=="string")),e.allow_custom===!0&&(o.allowCustom=!0);let a=this.#e.decision.open();this.#e.hidePending();let s=()=>Ju(this.#e.ensureGroup(),o,{signal:a,strings:this.#e.strings()}),c=this.#e.askUserRenderer(),l;this.#e.setAsking(n,!0);try{if(c===null)l=await s();else try{l=await c.call(this.#e.element,o,{signal:a})}catch(u){l=await this.#d(u,a,n,s)}}finally{this.#e.setAsking(n,!1)}return this.#e.decision.close(),this.#e.updateEmptyState(),this.#e.follow(),l}#d(e,n,r,o){return n.aborted?Promise.resolve(""):(console.warn(`ag-ui-chat: askUserRenderer failed for tool call ${r}, so the built-in question card asks instead`,e),o())}};function is(t){if(t.name!==$l)return null;let e=t.args?.id;return typeof e=="string"&&e!==""?e:null}function Ob(t,e){let n=document.createElement("button");return n.type="button",n.className=`approval-btn approval-btn--${t}`,n.setAttribute("part",`approval-button approval-${t}`),n.textContent=e,n}function ed(t,e,n={}){let r=n.strings??fe;return new Promise(o=>{let i=document.createElement("div");i.className="approval",i.setAttribute("part","approval"),e.toolName!==void 0&&i.setAttribute("data-tool-name",e.toolName),i.setAttribute("role","group"),i.setAttribute("aria-label",r.approveAction);let a=document.createElement("div");a.className="approval-body",a.setAttribute("part","approval-body"),a.textContent=e.message??r.approvalPrompt;let s=JT(e,n,r),c=document.createElement("div");c.className="approval-actions",c.setAttribute("part","approval-actions");let l=Ob("deny",r.deny),u=Ob("approve",r.approve),f=!1,m=p=>{f||(f=!0,l.disabled=!0,u.disabled=!0,i.setAttribute("data-resolved",p?"approved":"denied"),o(p))};if(l.addEventListener("click",()=>m(!1)),u.addEventListener("click",()=>{s!==null&&!s.commit()||m(!0)}),n.signal?.addEventListener("abort",()=>m(!1),{once:!0}),c.append(l,u),i.append(a,...s===null?[]:[s.root],c),t.appendChild(i),n.signal?.aborted===!0){m(!1);return}u.focus()})}function JT(t,e,n){let{onEdit:r}=e;if(r===void 0||t.args===void 0)return null;let o=JSON.stringify(t.args,null,2),i=document.createElement("div");i.className="approval-edit",i.setAttribute("part","approval-edit");let a=document.createElement("textarea");a.className="approval-args",a.setAttribute("part","approval-args"),a.setAttribute("aria-label",n.approvalEditArgs),a.rows=Math.min(10,o.split(`
|
|
40
|
+
`).length),a.value=o;let s=document.createElement("div");return s.className="approval-error",s.setAttribute("part","approval-error"),s.setAttribute("role","alert"),s.hidden=!0,i.append(a,s),{root:i,commit:()=>{if(a.value===o)return!0;let c;try{c=JSON.parse(a.value)}catch{return s.textContent=n.approvalArgsInvalid,s.hidden=!1,a.focus(),!1}return typeof c!="object"||c===null||Array.isArray(c)?(s.textContent=n.approvalArgsNotAnObject,s.hidden=!1,a.focus(),!1):(s.hidden=!0,r(c),!0)}}}function td(t,e){let n=document.createElement("button");return n.type="button",n.className=`confirm-btn confirm-btn--${t}`,n.setAttribute("part",`confirm-button confirm-${t}`),n.textContent=e,n}function nd(t,e,n={}){let r=n.strings??fe;return new Promise(o=>{let i=document.createElement("div");i.className="confirm",i.setAttribute("part","confirm"),i.setAttribute("data-tool-name",e.toolName),i.setAttribute("role","group"),i.setAttribute("aria-label",r.confirmAction);let a=document.createElement("div");a.className="confirm-body",a.setAttribute("part","confirm-body"),a.textContent=e.message??re(r.confirmRun,{tool:e.toolName});let s=document.createElement("pre");s.className="confirm-args",s.setAttribute("part","confirm-args"),s.textContent=JSON.stringify(e.args,null,2),s.hidden=Object.keys(e.args).length===0;let c=document.createElement("div");c.className="confirm-actions",c.setAttribute("part","confirm-actions");let l=td("cancel",r.cancel),u=n.onAlwaysAllow===void 0?null:td("always",re(r.confirmAlways,{tool:e.toolName})),f=td("confirm",r.confirm),m=!1,p=h=>{m||(m=!0,i.remove(),o(h))};if(l.addEventListener("click",()=>p(!1)),f.addEventListener("click",()=>p(!0)),u?.addEventListener("click",()=>{n.onAlwaysAllow?.(),p(!0)}),n.signal?.addEventListener("abort",()=>p(!1),{once:!0}),c.append(l,...u===null?[]:[u],f),i.append(a,s,c),t.appendChild(i),n.signal?.aborted===!0){p(!1);return}f.focus()})}function rd(t){return t[Tr]===!0}function as(t){return t[Ar]===!0}var ss=class{#e;#t=new Set;#n=null;constructor(e){this.#e=e}forgetWaivers(){this.#t.clear()}buildContext(){return this.#n=window.location.href,this.#e.getContext()}async execute(e){if(is(e)!==null)return null;let n=this.#e.tenure(),r=this.#e.conversation(),o=this.#e.threadId(),i=this.#e.transcript.cardFor(e);this.#e.transcript.forgetCard(e.id),this.#e.transcript.setCardElement(e.id,i.element),this.#e.transcript.holdRunning(e.id,i);let a=this.#e.tools.wasAdvertised(e.name)?this.#e.tools.resolve(e.name):null;if(a===null)return this.#e.transcript.isServerSettled(e.id)||i.settle(K.INTERRUPTED,this.#e.strings().callNotFinished),null;if(this.#e.getPageMap()!==null&&e.name!==Vo&&!as(a.parameters)&&this.#a()){let u=this.#e.strings().pageMoved;return i.settle(K.ERROR,u),this.#e.transcript.showPending(),{content:`Error: ${u}`,error:u,outcome:je.FAILED}}let s=this.#e.decision.open(),c=await this.#r(e,a);if(this.#e.decision.close(),s.aborted)return this.#i(i);if(c==="unanswered"){let u=this.#e.strings().confirmCheckFailed;return i.settle(K.DECLINED,u),this.#e.transcript.showPending(),{content:u,outcome:je.DENIED}}if(c!==null){let u={toolName:e.name,args:e.args},f=a.parameters[Zo];typeof f=="string"&&(u.message=f);let m=this.#e.decision.open();i.setAsking(!0);let p;try{let h=nd(this.#e.transcript.ensureGroup(),u,{signal:m,strings:this.#e.strings(),...c==="destructive"?{onAlwaysAllow:()=>this.#t.add(e.name)}:{}});this.#e.transcript.updateEmptyState(),this.#e.transcript.follow(),p=await h}finally{i.setAsking(!1)}if(this.#e.decision.close(),this.#e.tenure()!==n)return null;if(i.recordDecision(p?"approved":"declined"),!p){let h=this.#e.strings().declinedAction;return i.settle(K.DECLINED,h),this.#e.conversation()===r&&this.#e.transcript.showPending(),{content:h,outcome:je.DENIED}}if(m.aborted)return this.#i(i)}let l=as(a.parameters)&&this.#e.navigate()===null;l&&this.#e.conversationStore().saveCheckpoint(o,{toolCallId:e.id});try{let u=await a.handler(e.args,e.id);if(this.#e.tenure()!==n)return null;if(a.render!==void 0&&this.#e.transcript.renderToolOutput(a.render,e),l)return i.settle(K.DONE,this.#e.strings().navigating),{content:"",halt:!0};let f=JSON.stringify(u??null);return i.settle(K.DONE,f),this.#e.conversation()===r&&this.#e.transcript.showPending(),{content:f}}catch(u){if(this.#e.tenure()!==n)return null;l&&this.#e.conversationStore().saveCheckpoint(o,null);let f=u instanceof Error?u.message:String(u);return i.settle(K.ERROR,f),this.#e.conversation()===r&&this.#e.transcript.showPending(),{content:`Error: ${f}`,error:f,outcome:je.FAILED}}}async resolveInterrupts(e){let n=this.#e.decision.open();this.#e.announce(re(this.#e.strings().announceAwaitingDecision,{count:e.length})),this.#e.transcript.hidePending();let r=await Promise.all(e.map(async i=>{let a=i.toolCallId!==void 0?this.#e.transcript.card(i.toolCallId):void 0,s={},c=QT(i)??i.message;c!==void 0&&(s.message=c);let l=a?.element.getAttribute("data-tool-name");l!=null&&(s.toolName=l);let u,f=this.#e.approveWithEdits()&&a!==void 0;f&&(s.args=a.args),a?.mark(K.DEFERRED),a!==void 0&&this.#e.transcript.revealStep(a);let m=()=>ed(a?.approvalSlot??this.#e.transcript.ensureGroup(),s,{signal:n,strings:this.#e.strings(),...f?{onEdit:x=>{u=x}}:{}}),p=this.#e.approvalRenderer(),h;if(p===null)h=await m();else try{h=await p.call(this.#e.element,s,{signal:n})}catch(x){h=await this.#o(x,n,i.id,m)}return a?.recordDecision(h?"approved":"declined"),h?a?.mark(K.PENDING):a?.settle(K.DECLINED,this.#e.strings().declinedAction),{id:i.id,approved:h,editedArgs:u}}));this.#e.transcript.updateEmptyState(),this.#e.transcript.follow(),this.#e.decision.close();let o={};for(let{id:i,approved:a,editedArgs:s}of r)o[i]=a?{status:"resolved",payload:s===void 0?{approved:!0}:{approved:!0,editedArgs:s}}:{status:"cancelled"};return o}#o(e,n,r,o){return n.aborted?Promise.resolve(!1):(console.warn(`ag-ui-chat: approvalRenderer failed for interrupt ${r}, so the built-in approval card asks instead`,e),o())}async#r(e,n){if(this.#e.autoConfirm())return null;let r=this.#e.confirmPredicate();if(r!==null)try{return await r.call(this.#e.element,e.name,e.args)===!0?"predicate":null}catch(o){return console.warn(`ag-ui-chat: confirmPredicate failed for tool ${e.name}, so the call was refused`,o),"unanswered"}return this.#t.has(e.name)?null:rd(n.parameters)?"destructive":null}#i(e){return e.settle(K.INTERRUPTED,this.#e.strings().callNotFinished),null}#a(){return this.#n!==null&&this.#n!==window.location.href}};function QT(t){let e=t.metadata?.[Zo];return typeof e=="string"&&e.trim()!==""?e:void 0}var eA="http://www.w3.org/2000/svg",et={top:20,right:12,bottom:30,left:44},tA=480,nA=220,rA=220/480,oA=160,iA=320,Pb=8,aA=5.6,Mb=["var(--_chart-1)","var(--_chart-2)","var(--_chart-3)","var(--_chart-4)","var(--_chart-5)","var(--_chart-6)"];function In(t){return Mb[t%Mb.length]}function Lb(t){let e=Math.max(nA,t),n=Math.min(iA,Math.max(oA,Math.round(e*rA)));return{width:e,height:n,plotW:e-et.left-et.right,plotH:n-et.top-et.bottom}}function kt(t,e){let n=document.createElementNS(eA,t);for(let[r,o]of Object.entries(e))n.setAttribute(r,String(o));return n}function zb(t,e){let n=kt("text",{"font-size":10,fill:"currentColor","fill-opacity":.65,...e});return n.textContent=t,n}function sA(t){let e=[];return t.labels.forEach((n,r)=>{let o=0;for(let i of t.series)o+=i.points[r]??0,e.push(o)}),e}function lA(t){let e=t.kind==="stacked"?sA(t):t.series.flatMap(o=>[...o.points]),n=Math.max(0,...e),r=Math.min(0,...e);return n===r?{min:r,max:n+1}:{min:r,max:n}}function Rn(t,e,n,r){return et.top+r.plotH-(t-e)/(n-e)*r.plotH}function od(t,e,n){let r=n.plotW/e;return et.left+r*t+r/2}function cA(t,e){let n=e.plotW/t.length,r=Math.max(...t.map(o=>o.length))*aA;return Math.max(1,Math.ceil(r/n))}function uA(t,e,n,r,o){for(let a of[r,o]){let s=Rn(a,r,o,n);t.appendChild(kt("line",{x1:et.left,y1:s,x2:n.width-et.right,y2:s,stroke:"currentColor","stroke-opacity":a===r?.35:.12})),t.appendChild(zb(String(Math.round(a)),{x:et.left-6,y:s+4,"text-anchor":"end"}))}let i=cA(e.labels,n);e.labels.forEach((a,s)=>{s%i===0&&t.appendChild(zb(a,{x:od(s,e.labels.length,n),y:n.height-et.bottom+16,"text-anchor":"middle"}))})}function dA(t,e,n,r,o){let i=n.plotW/e.labels.length,a=i*.7/e.series.length,s=Rn(r,r,o,n);e.series.forEach((c,l)=>{c.points.forEach((u,f)=>{let m=Rn(u,r,o,n);t.appendChild(kt("rect",{x:et.left+i*f+i*.15+a*l,y:m,width:a,height:Math.max(1,s-m),fill:In(l),rx:2}))})})}function pA(t,e,n,r,o){let i=n.plotW/e.labels.length,a=i*.7,s=e.labels.map(()=>0);e.series.forEach((c,l)=>{c.points.forEach((u,f)=>{let m=s[f]??0,p=m+u;s[f]=p;let h=Rn(p,r,o,n);t.appendChild(kt("rect",{x:et.left+i*f+i*.15,y:h,width:a,height:Math.max(1,Rn(m,r,o,n)-h),fill:In(l)}))})})}function hA(t,e,n,r,o){e.series.forEach((i,a)=>{let s=i.points.map((c,l)=>`${od(l,e.labels.length,n)},${Rn(c,r,o,n)}`).join(" ");t.appendChild(kt("polyline",{points:s,fill:"none",stroke:In(a),"stroke-width":2,"stroke-linejoin":"round"}))})}function fA(t,e,n,r,o){e.series.forEach((i,a)=>{i.points.forEach((s,c)=>{t.appendChild(kt("circle",{cx:od(c,e.labels.length,n),cy:Rn(s,r,o,n),r:4,fill:In(a),"fill-opacity":.85}))})})}function mA(t,e,n){let r=e.reduce((c,l)=>c+l,0),o=n.width/2,i=et.top+n.plotH/2,a=Math.min(n.plotW,n.plotH)/2;if(r===0){t.appendChild(kt("circle",{cx:o,cy:i,r:a,fill:"none",stroke:"currentColor","stroke-opacity":.3}));return}let s=-Math.PI/2;e.forEach((c,l)=>{let u=c/r*Math.PI*2,f=s+u;if(u>=Math.PI*2)t.appendChild(kt("circle",{cx:o,cy:i,r:a,fill:In(l)}));else{let m=o+a*Math.cos(s),p=i+a*Math.sin(s),h=o+a*Math.cos(f),x=i+a*Math.sin(f),g=u>Math.PI?1:0;t.appendChild(kt("path",{d:`M ${o} ${i} L ${m} ${p} A ${a} ${a} 0 ${g} 1 ${h} ${x} Z`,fill:In(l)}))}s=f})}function Db(t,e){let n=kt("svg",{viewBox:`0 0 ${e.width} ${e.height}`,width:"100%",role:"img"});if(n.setAttribute("aria-label",t.title??`${t.kind} chart`),t.kind==="pie"){let i=t.series[0];return mA(n,i.points.map(a=>Math.max(0,a)),e),n}let{min:r,max:o}=lA(t);return uA(n,t,e,r,o),t.kind==="bar"?dA(n,t,e,r,o):t.kind==="stacked"?pA(n,t,e,r,o):t.kind==="line"?hA(n,t,e,r,o):fA(n,t,e,r,o),n}function gA(t){if(t.length<2)return null;let e=document.createElement("div");return e.className="chart-legend",e.setAttribute("part","chart-legend"),t.forEach((n,r)=>{let o=document.createElement("span");o.className="chart-legend-item";let i=document.createElement("span");i.className="chart-legend-swatch",i.style.background=In(r),o.append(i,document.createTextNode(n)),e.appendChild(o)}),e}function vA(t,e){new ResizeObserver(()=>{e(Math.round(t.clientWidth/Pb)*Pb)}).observe(t)}function ro(t){if(t.labels.length===0||t.series.length===0)return null;let e=document.createElement("div");if(e.className="chart-block",e.setAttribute("part","chart-block"),t.title!==void 0&&t.title!==""){let i=document.createElement("div");i.className="chart-title",i.setAttribute("part","chart-title"),i.textContent=t.title,e.appendChild(i)}let n=tA,r=Db(t,Lb(n));e.appendChild(r);let o=gA(t.kind==="pie"?t.labels:t.series.map(i=>i.label));return o!==null&&e.appendChild(o),vA(e,i=>{if(i===n)return;n=i;let a=Db(t,Lb(n));r.replaceWith(a),r=a}),e}var bA=["bar","line","pie","scatter","stacked"];function yA(t){return bA.includes(t)?t:"bar"}function wA(t){if(!Array.isArray(t))return null;let e=[];for(let n of t){if(typeof n!="number"||!Number.isFinite(n)||Math.abs(n)>1e15)return null;e.push(n)}return e}function EA(t){if(!Array.isArray(t))return null;for(let e=0;e<t.length;e+=1)if(typeof t[e]!="string")return null;return t}function hr(t){if(typeof t!="object"||t===null)return null;let e=t,n=EA(e.labels);if(n===null||!Array.isArray(e.series))return null;let r=[];for(let a of e.series){if(typeof a!="object"||a===null)return null;let s=a,c=wA(s.points);if(c===null||c.length!==n.length)return null;r.push({label:typeof s.label=="string"?s.label:"",points:c})}if(r.length===0||r.length*n.length>2e4||n.length>2e3)return null;let o=yA(e.kind),i=e.title;return typeof i=="string"?{kind:o,title:i,labels:n,series:r}:{kind:o,labels:n,series:r}}var ls="render_chart";function xA(t){let e=hr(t);return e===null?null:ro(e)}function _A(t){let e=hr(t);return e!==null&&e.labels.length>0&&e.series.length>0}var SA="chart not rendered: expected labels (strings) and series, each with one finite number per label";function $b(){return{name:ls,description:"Show a chart in the conversation. Supply the data and the page draws it. Every series must have exactly one point per label.",parameters:{type:"object",properties:{kind:{type:"string",enum:["bar","line","pie","scatter","stacked"]},title:{type:"string"},labels:{type:"array",items:{type:"string"}},series:{type:"array",items:{type:"object",properties:{label:{type:"string"},points:{type:"array",items:{type:"number"}}},required:["points"]}}},required:["labels","series"],"x-summary":"Draw a chart"},handler:t=>_A(t)?"chart rendered":SA,render:xA}}function Yt(t){t.style.height="auto",t.style.height=`${t.scrollHeight}px`}function cs(t,e,n){let r=document.createElement("slot");return r.name=t,r.className=e,r.innerHTML=n,r}function Ub(t){let{input:e,send:n,attachButton:r,fileInput:o,strings:i,signal:a}=t,s=t.queuedRow;s.className="queued",s.setAttribute("part","queued"),s.setAttribute("role","group"),s.setAttribute("aria-label",i.queued),s.hidden=!0;let c=document.createElement("div");c.className="input-row",c.setAttribute("part","composer");let l=document.createElement("div");l.className="composer",l.setAttribute("part","composer-surface");let u=document.createElement("div");u.className="composer-tools",u.setAttribute("part","composer-tools"),e.className="input",e.setAttribute("part","input"),e.setAttribute("aria-label",i.message),e.rows=1,e.placeholder=i.inputPlaceholder,e.addEventListener("keydown",t.onKeydown,{signal:a}),e.addEventListener("input",t.onInput,{signal:a}),n.className="send",n.type="button",n.setAttribute("part","send"),n.replaceChildren(cs("icon-send","send-send",Rp),cs("icon-stop","send-stop",Cp)),n.title=i.send,n.setAttribute("aria-label",i.send),n.dataset.state="idle",n.addEventListener("click",t.onSend,{signal:a});let f=t.hint;return f.className="skill-hint",f.setAttribute("part","skill-hint"),f.hidden=!0,r.className="attach-btn",r.type="button",r.setAttribute("part","attach-button"),r.replaceChildren(cs("icon-attach","attach-glyph",Np)),r.title=i.attachFiles,r.setAttribute("aria-label",i.attachFiles),r.hidden=!0,r.addEventListener("click",()=>o.click(),{signal:a}),o.className="attach-input",o.type="file",o.multiple=!0,o.hidden=!0,o.addEventListener("change",t.onFilesPicked,{signal:a}),t.attachSlot.className="attachment-slot",t.voiceSlot.className="voice-slot",u.append(r,t.voiceSlot,n),l.append(e,u),c.append(l,o),c}function id(t,e){return new Promise((n,r)=>{let o=new FormData;o.append("file",t);let i=new XMLHttpRequest;i.open("POST",e.url),i.withCredentials=e.credentials==="include";for(let[c,l]of Object.entries(e.headers??{}))i.setRequestHeader(c,l);let a=e.onProgress;a!==void 0&&i.upload.addEventListener("progress",c=>{c.lengthComputable&&a(c.total===0?0:c.loaded/c.total)}),i.addEventListener("load",()=>{if(i.status>=200&&i.status<300)try{n(TA(JSON.parse(i.responseText)))}catch{r(new Error("upload returned an unreadable response"))}else r(new Error(AA(i)))}),i.addEventListener("error",()=>r(new Error("upload failed"))),i.addEventListener("abort",()=>r(new Error("upload cancelled")));let s=e.signal;s!==void 0&&s.addEventListener("abort",()=>i.abort()),i.send(o)})}function TA(t){if(typeof t!="object"||t===null)throw new Error("not an object");let e=t,n=e.id,r=e.name,o=e.mime,i=e.size,a=e.url;if(typeof n!="string"||typeof r!="string"||typeof o!="string"||typeof i!="number")throw new Error("missing fields");return typeof a=="string"?{id:n,name:r,mime:o,size:i,url:a}:{id:n,name:r,mime:o,size:i}}function AA(t){try{let e=JSON.parse(t.responseText);if(typeof e.error=="string")return e.error}catch{}return`upload failed (${t.status})`}function us(t){let e=document.createElement("div");e.className="attachment-chips",e.setAttribute("part","attachment-chips");for(let n of t)e.appendChild(kA(n));return e}function kA(t){let e=document.createElement("div");e.className="attachment-chip attachment-chip--ready",e.setAttribute("part","attachment-chip");let n=document.createElement("span");n.className="attachment-chip-icon",n.setAttribute("part","attachment-chip-icon"),n.innerHTML=ad(t.mime),n.setAttribute("aria-hidden","true");let r=document.createElement("span");r.className="attachment-chip-name",r.setAttribute("part","attachment-chip-name"),r.textContent=t.name,r.title=t.name;let o=document.createElement("span");return o.className="attachment-chip-size",o.setAttribute("part","attachment-chip-size"),o.textContent=ds(t.size),e.append(n,r,o),e}function ad(t){return t.startsWith("image/")?Fp:t==="application/pdf"?Gp:t.startsWith("text/")?Bp:Hp}function ds(t){if(t<1024)return`${t} B`;let e=["KB","MB","GB"],n=t/1024,r=0;for(;n>=1024&&r<e.length-1;)n/=1024,r+=1;return`${n<10?Math.round(n*10)/10:Math.round(n)} ${e[r]}`}var ps=class{element;#e;#t;#n=[];constructor(e){this.#e=e,this.#t=e.strings??fe,this.element=document.createElement("div"),this.element.className="attachment-tray",this.element.setAttribute("part","attachment-tray"),this.element.hidden=!0}add(e){let n={localId:Se(),file:e,status:Xe.UPLOADING,progress:0,ref:null,error:"",controller:null};this.#n.push(n);let r=this.#o(e);if(r!==null){n.status=Xe.ERROR,n.error=r,this.#a(),this.#e.onChange?.();return}this.#a(),this.#e.onChange?.(),this.#r(n)}readyRefs(){let e=[];for(let n of this.#n)n.ref!==null&&e.push(n.ref);return e}hasPending(){return this.#n.some(e=>e.status===Xe.UPLOADING)}pendingCount(){return this.#n.filter(e=>e.status===Xe.UPLOADING).length}isEmpty(){return this.#n.length===0}clearReady(){this.#n=this.#n.filter(e=>e.status===Xe.UPLOADING),this.#a()}clear(){for(let e of this.#n)e.controller?.abort();this.#n=[],this.#a()}dispose(){for(let e of this.#n)e.controller?.abort()}#o(e){return this.#e.maxBytes>0&&e.size>this.#e.maxBytes?re(this.#t.tooLarge,{size:ds(this.#e.maxBytes)}):IA(this.#e.accept,e)?null:this.#t.fileTypeNotAllowed}#r(e){let n=this.#o(e.file);if(n!==null){e.status=Xe.ERROR,e.error=n,this.#a(),this.#e.onChange?.();return}e.status=Xe.UPLOADING,e.progress=0,e.error="";let r=new AbortController;e.controller=r,this.#a(),this.#e.upload(e.file,o=>{e.progress=o,this.#a()},r.signal).then(o=>{e.status=Xe.READY,e.ref=o}).catch(o=>{e.status=Xe.ERROR,e.error=o instanceof Error?o.message:this.#t.uploadFailed}).finally(()=>{e.controller=null,this.#a(),this.#e.onChange?.()})}#i(e){e.controller?.abort(),this.#n=this.#n.filter(n=>n!==e),this.#a(),this.#e.onChange?.()}#a(){this.element.replaceChildren(),this.element.hidden=this.#n.length===0;for(let e of this.#n)this.element.appendChild(this.#s(e))}#s(e){let n=document.createElement("div");n.className=`attachment-chip attachment-chip--${e.status}`,n.setAttribute("part","attachment-chip");let r=document.createElement("span");r.className="attachment-chip-icon",r.setAttribute("part","attachment-chip-icon"),r.innerHTML=ad(e.file.type),r.setAttribute("aria-hidden","true");let o=document.createElement("span");o.className="attachment-chip-name",o.setAttribute("part","attachment-chip-name"),o.textContent=e.file.name,o.title=e.file.name;let i=document.createElement("span");if(i.className="attachment-chip-size",i.setAttribute("part","attachment-chip-size"),i.textContent=e.status===Xe.ERROR?e.error:ds(e.file.size),n.append(r,o,i),e.status===Xe.UPLOADING){let s=document.createElement("div");s.className="attachment-chip-bar",s.setAttribute("part","attachment-chip-bar");let c=document.createElement("div");c.className="attachment-chip-bar-fill",c.setAttribute("part","attachment-chip-bar-fill"),c.style.width=`${Math.round(e.progress*100)}%`,s.appendChild(c),n.appendChild(s)}if(e.status===Xe.ERROR){let s=document.createElement("button");s.type="button",s.className="attachment-chip-retry",s.setAttribute("part","attachment-chip-retry"),s.title=this.#t.retry,s.setAttribute("aria-label",this.#t.retryUpload),s.textContent="\u21BB",s.addEventListener("click",()=>this.#r(e)),n.appendChild(s)}let a=document.createElement("button");return a.type="button",a.className="attachment-chip-remove",a.setAttribute("part","attachment-chip-remove"),a.title=this.#t.remove,a.setAttribute("aria-label",this.#t.removeAttachment),a.textContent="\u2715",a.addEventListener("click",()=>this.#i(e)),n.appendChild(a),n}};function IA(t,e){let n=pr(t).map(i=>i.toLowerCase());if(n.length===0)return!0;let r=e.type.toLowerCase(),o=e.name.toLowerCase();return n.some(i=>i.startsWith(".")?o.endsWith(i):i.endsWith("/*")?r.startsWith(i.slice(0,-1)):r===i)}var hs=class{#e;#t=null;constructor(e){this.#e=e}get tray(){return this.#t}wire(e){this.#t?.element.remove(),this.#t=null;let n=this.#e.element.getAttribute("data-attachments-url"),r=this.#e.uploadHandler()??this.#n(n);if(r===null)return;let o=this.#e.element.getAttribute("data-attachment-accept")??"",i=new ps({upload:r,maxBytes:this.#o(),accept:o,strings:this.#e.strings(),onChange:()=>this.#l(i)});this.#t=i,this.#e.slot.appendChild(this.#t.element),this.#e.fileInput.accept=o,this.#e.button.hidden=!1,this.#r(e),this.#s(i,e)}attach(e){return this.#t===null?!1:(this.#t.add(e),!0)}onFilesPicked(){let e=this.#e.fileInput,n=e.files;if(n!==null)for(let r of Array.from(n))this.#t?.add(r);e.value=""}#n(e){return e===null?null:(n,r,o)=>id(n,{url:e,headers:this.#e.headersFor(e),...this.#e.credentialsOption(),onProgress:r,signal:o})}#o(){let e=this.#e.element.getAttribute("data-attachment-max-bytes");if(e===null)return zl;let n=Number.parseInt(e,10);return Number.isFinite(n)&&n>=0?n:zl}#r(e){let n=this.#e.chat;n.addEventListener("dragover",r=>{r.preventDefault(),n.classList.add("chat--dragover")},{signal:e}),n.addEventListener("dragleave",()=>{n.classList.remove("chat--dragover")},{signal:e}),n.addEventListener("drop",r=>{r.preventDefault(),n.classList.remove("chat--dragover");let o=r.dataTransfer?.files;if(o!==void 0)for(let i of Array.from(o))this.#t?.add(i)},{signal:e})}#i(e,n,r){let o=this.#a(),i=n.getData("text/plain");o===null||i.length<o||(e.preventDefault(),r.add(new File([i],`pasted-${Hb()}.txt`,{type:"text/plain"})))}#a(){let e=this.#e.element.getAttribute("data-paste-attach");if(e===null)return Wo;if(e==="off")return null;let n=Number.parseInt(e,10);return Number.isNaN(n)||n<=0?(console.warn(`<ag-ui-chat>: data-paste-attach="${e}" is neither "off" nor a positive number of characters, so the default of ${Wo} is used.`),Wo):n}#s(e,n){this.#e.chat.addEventListener("paste",r=>{let o=r.clipboardData??null;if(o===null)return;let i=Array.from(o.files);if(i.length===0){this.#i(r,o,e);return}o.getData("text/plain")===""&&r.preventDefault();for(let a of i)this.#t?.add(RA(a))},{signal:n})}#l(e){this.#e.element.dispatchEvent(new CustomEvent(Il,{detail:{attachments:e.readyRefs(),pending:e.pendingCount()},bubbles:!0,composed:!0}))}};function Hb(){return new Date().toISOString().replace(/[:.]/g,"-")}function RA(t){if(t.name!=="")return t;let e=t.type.split("/")[1]??t.type,n=Hb();return new File([t],e===""?`pasted-${n}`:`pasted-${n}.${e}`,{type:t.type})}async function sd(t,e){let n=new FormData;n.append("audio",t,"recording.webm");let r=await fetch(e.url,it({method:"POST",headers:{...e.headers??{}},body:n},e.credentials));if(!r.ok)throw new Error(await CA(r));let o=await r.json();if(typeof o=="object"&&o!==null&&typeof o.text=="string")return o.text;throw new Error("transcription returned an unreadable response")}async function CA(t){try{let e=await t.json();if(typeof e.error=="string")return e.error}catch{}return`transcription failed (${t.status})`}var Fb=12e4,fs=class{element;#e;#t;#n;#o="idle";#r=null;#i=null;#a=[];#s=null;#l=!1;#u=!1;#d={};constructor(e){this.#e=e.transcribe,this.#t=e.onText,this.#n=e.strings??fe,this.element=document.createElement("button"),this.element.type="button",this.element.className="voice-btn",this.element.setAttribute("part","voice-button");let n=document.createElement("slot");n.name="icon-voice",n.innerHTML=Op,this.element.append(n),this.#y("idle"),this.element.addEventListener("click",()=>{this.toggle()})}async toggle(){if(this.#o==="recording"){this.#p();return}this.#o!=="transcribing"&&await this.#f()}async#f(){let e={};this.#d=e;let n;try{n=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{n=null}if(e!==this.#d||this.#u){for(let o of n?.getTracks()??[])o.stop();return}if(n===null){this.#g(this.#n.transcriptionFailed);return}this.#i=n,this.#a=[],this.#l=!1;let r;try{r=new MediaRecorder(n),r.addEventListener("dataavailable",o=>{this.#a.push(o.data)}),r.addEventListener("stop",()=>{this.#c(r.mimeType)}),this.#r=r,r.start()}catch{this.#g(this.#n.transcriptionFailed);return}this.#s=setTimeout(()=>{this.#l=!0,this.#p()},Fb),this.#y("recording")}#p(){this.#m(),this.#r?.stop()}#m(){this.#s!==null&&(clearTimeout(this.#s),this.#s=null)}dispose(){this.#u=!0,this.#m(),this.#r!==null&&this.#r.state!=="inactive"&&this.#r.stop(),this.#r=null,this.#b()}async#c(e){if(this.#u)return;this.#b(),this.#y("transcribing");let n=new Blob(this.#a,{type:e||"audio/webm"});try{let r=await this.#e(n);if(this.#u)return;this.#y("idle"),this.#l&&(this.element.title=re(this.#n.recordingLimit,{n:Fb/6e4})),r!==""&&this.#t(r)}catch(r){this.#g(r instanceof Error?r.message:this.#n.transcriptionFailed)}finally{this.#r=null}}#b(){for(let e of this.#i?.getTracks()??[])e.stop();this.#i=null}#g(e){this.#u||(this.#b(),this.#r=null,this.#y("idle"),this.element.title=e)}#y(e){this.#o=e,this.element.dataset.state=e;let n=this.#E(e);this.element.title=n,this.element.setAttribute("aria-label",n),this.element.setAttribute("aria-pressed",String(e==="recording")),this.element.disabled=e==="transcribing"}#E(e){return e==="recording"?this.#n.stopRecording:e==="transcribing"?this.#n.transcribing:this.#n.recordVoice}};var ms=class{#e;#t=null;constructor(e){this.#e=e}wire(){this.#t?.element.remove(),this.#t=null;let e=this.#e.element.getAttribute("data-transcribe-url"),n=this.#e.transcribeHandler()??this.#n(e);n!==null&&(this.#t=new fs({transcribe:n,onText:r=>this.#o(r),strings:this.#e.strings()}),this.#e.slot.appendChild(this.#t.element))}dispose(){this.#t?.dispose()}#n(e){return e===null?null:n=>sd(n,{url:e,headers:this.#e.headersFor(e),...this.#e.credentialsOption()})}#o(e){let n=this.#e.input,r=n.value.trim();n.value=r===""?e:`${r} ${e}`,this.#e.onInput(),n.focus()}};var gs=class{chips;palette;#e;#t=[];#n=!1;#o=!1;#r=[];#i=0;constructor(e){this.#e=e,this.chips=document.createElement("div"),this.chips.className="skill-chips",this.chips.setAttribute("part","skill-chips"),this.chips.hidden=!0,this.palette=document.createElement("div"),this.palette.className="skill-palette",this.palette.setAttribute("part","skill-palette"),this.palette.setAttribute("role","listbox"),this.palette.hidden=!0}setSkills(e){this.#t=e,this.#u()}enableChips(e){this.#n=e,this.#u()}enableSlash(e){this.#o=e}isOpen(){return!this.palette.hidden}onInput(e){this.#o&&e.startsWith("/")?this.#a(e.slice(1)):this.close()}onKeydown(e){return this.isOpen()?e.key==="ArrowDown"?(this.#s(1),!0):e.key==="ArrowUp"?(this.#s(-1),!0):e.key==="Escape"?(this.close(),!0):e.key==="Enter"?(this.#r.slice(this.#i,this.#i+1).forEach(n=>{this.#l(n)}),!0):!1:!1}close(){this.palette.hidden=!0,this.palette.replaceChildren()}#a(e){let n=e.trim().toLowerCase(),r=this.#t.filter(o=>o.name.toLowerCase().includes(n)||o.title.toLowerCase().includes(n));if(r.length===0){this.close();return}this.#r=r,this.#i=0,this.#d(),this.palette.hidden=!1}#s(e){let n=this.#r.length;this.#i=(this.#i+e+n)%n,this.#d()}#l(e){this.close(),this.#e(e)}#u(){this.chips.replaceChildren();let e=this.#n?this.#t.filter(n=>n.chip===!0):[];this.chips.hidden=e.length===0;for(let n of e){let r=document.createElement("button");r.type="button",r.className="skill-chip",r.setAttribute("part","skill-chip"),r.textContent=n.title,r.title=`/${n.name}`,r.addEventListener("click",()=>this.#l(n)),this.chips.appendChild(r)}}#d(){this.palette.replaceChildren(),this.#r.forEach((e,n)=>{let r=document.createElement("button");r.type="button",r.className="skill-item",r.setAttribute("part","skill-item"),r.setAttribute("role","option"),r.setAttribute("aria-selected",n===this.#i?"true":"false");let o=document.createElement("span");o.className="skill-item-title",o.setAttribute("part","skill-item-title");let i=document.createElement("code");if(i.className="skill-item-token",i.setAttribute("part","skill-item-token"),i.textContent=`/${e.name}`,o.append(i,document.createTextNode(` ${e.title}`)),r.appendChild(o),e.description!==void 0){let a=document.createElement("span");a.className="skill-item-desc",a.setAttribute("part","skill-item-desc"),a.textContent=e.description,r.appendChild(a)}r.addEventListener("click",()=>this.#l(e)),this.palette.appendChild(r)})}};var NA=500;function oo(t,e=[],n){for(let r of GA(e)){if(!t.contains(r.startContainer)||!t.contains(r.endContainer))continue;let o=document.createRange();o.setStart(r.startContainer,r.startOffset),o.setEnd(r.endContainer,r.endOffset);let i=LA(o).trim();if(i!=="")return{text:i,rect:FA(o,n)}}return null}function ld(t){let e=OA(t);return e.length===0?"":`${MA(e.join(`
|
|
41
41
|
`)).split(`
|
|
42
42
|
`).map(o=>`> ${o}`.trimEnd()).join(`
|
|
43
43
|
`)}
|
|
44
44
|
|
|
45
|
-
`}function
|
|
46
|
-
`).replace(/[^\S\n]+/g," ")}var
|
|
45
|
+
`}function OA(t){let e=t.split(/\r\n?|\n/).map(i=>i.trimEnd()),n=e.filter(i=>i!=="").map(PA),r=n.length===0?0:Math.min(...n),o=[];for(let i of e){let a=i.slice(r);a===""&&(o.length===0||o[o.length-1]==="")||o.push(a)}for(;o[o.length-1]==="";)o.pop();return o}function PA(t){return t.length-t.trimStart().length}function MA(t){return t.length>500?`${t.slice(0,500).trimEnd()}...`:t}function LA(t){let e="";for(let n of UA(t)){let r=n.parentElement;if(!HA(r))continue;let o=n===t.startContainer?t.startOffset:0,i=n===t.endContainer?t.endOffset:n.data.length;e+=zA(n.data.slice(o,i),r)}return e}function zA(t,e){return DA.has($A(e))?t:t.replace(/[^\S\n]*\n[^\S\n]*/g,`
|
|
46
|
+
`).replace(/[^\S\n]+/g," ")}var DA=new Set(["pre","pre-wrap","break-spaces"]);function $A(t){return window.getComputedStyle(t).whiteSpace}function UA(t){let e=t.commonAncestorContainer;if(e.nodeType===Node.TEXT_NODE)return[e];let n=[],r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(let o=r.nextNode();o!==null;o=r.nextNode())t.intersectsNode(o)&&n.push(o);return n}function HA(t){return typeof t.checkVisibility!="function"?!0:t.checkVisibility({contentVisibilityAuto:!0,opacityProperty:!0,visibilityProperty:!0})}function FA(t,e){let n=[...t.getClientRects()];if(n.length===0)return t.getBoundingClientRect();if(e===void 0)return n[0];let r=n[0],o=Gb(r,e);for(let i of n.slice(1)){let a=Gb(i,e);a<o&&(o=a,r=i)}return r}function Gb(t,e){let n=Math.max(t.left-e.x,0,e.x-t.right),r=Math.max(t.top-e.y,0,e.y-t.bottom);return Math.hypot(n,r)}function GA(t){let e=window.getSelection();if(e===null)return[];let n=[...BA(e,t)];return e.rangeCount>0&&n.push(e.getRangeAt(0)),n}function BA(t,e){let n=t.getComposedRanges;if(n===void 0)return[];try{return n.call(t,{shadowRoots:e})}catch{return n.call(t,...e)}}var cd=6,ZA=`
|
|
47
47
|
.ag-ui-quote-offer {
|
|
48
48
|
position: fixed;
|
|
49
49
|
z-index: 2147483000;
|
|
@@ -65,9 +65,9 @@ Error: ${b}`),[]}return p(g),[{type:Ue.AgentStateMessage,threadId:e,agentName:n,
|
|
|
65
65
|
.ag-ui-quote-offer[data-below="true"] {
|
|
66
66
|
transform: translate(-50%, 0);
|
|
67
67
|
}
|
|
68
|
-
`;function
|
|
68
|
+
`;function ud(t){let{within:e,exclude:n,onQuote:r}=t,o=new CSSStyleSheet;o.replaceSync(ZA),document.adoptedStyleSheets=[...document.adoptedStyleSheets,o];let i=document.createElement("button");i.type="button",i.className="ag-ui-quote-offer",i.textContent=t.label,i.hidden=!0,document.body.append(i);let a="",s=()=>{i.hidden=!0,a=""},c=u=>{if(u.composedPath().includes(n)){s();return}if(VA()){s();return}let f=u instanceof MouseEvent?{x:u.clientX,y:u.clientY}:void 0,m=oo(e,[],f);if(m===null){s();return}a=m.text,jA(i,m.rect)},l=u=>{i.contains(u.target)||s()};return e.addEventListener("mouseup",c),e.addEventListener("keyup",c),e.addEventListener("mousedown",l),document.addEventListener("scroll",s,!0),window.addEventListener("resize",s),i.addEventListener("mousedown",u=>{u.preventDefault()}),i.addEventListener("click",()=>{let u=a;window.getSelection()?.removeAllRanges(),s(),r(u)}),{element:i,detach(){e.removeEventListener("mouseup",c),e.removeEventListener("keyup",c),e.removeEventListener("mousedown",l),document.removeEventListener("scroll",s,!0),window.removeEventListener("resize",s),i.remove(),document.adoptedStyleSheets=document.adoptedStyleSheets.filter(u=>u!==o)}}}function VA(){let t=document.activeElement;return t===null?!1:t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.isContentEditable===!0}function jA(t,e){t.hidden=!1;let n=e.top<cd+t.offsetHeight;t.dataset.below=String(n),t.style.top=`${n?e.bottom+cd:e.top-cd}px`;let r=t.offsetWidth/2,o=e.left+e.width/2,i=document.documentElement.clientWidth;t.style.left=`${Math.min(Math.max(o,r),i-r)}px`}var dd=6,vs=class{button=document.createElement("button");#e;#t="";#n=null;constructor(e){this.#e=e}insert(e){let n=ld(e);if(n==="")return;let r=this.#e.input,o=r.value.replace(/\s+$/,"");r.value=o===""?n:`${o}
|
|
69
69
|
|
|
70
|
-
${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)}offerInPage(t){this.#n?.detach();let n=nd({within:t,label:this.#e.strings().quoteSelection,exclude:this.#e.element,onQuote:r=>this.#e.quote(r)});return this.#n=n,()=>{n.detach(),this.#n===n&&(this.#n=null)}}detachPageOffer(){this.#n?.detach(),this.#n=null}mount(t){let n=this.button;n.className="quote-selection",n.type="button",n.setAttribute("part","quote-selection"),n.textContent=this.#e.strings().quoteSelection,n.hidden=!0,n.addEventListener("mousedown",o=>{o.preventDefault()},{signal:t}),n.addEventListener("click",()=>{this.#e.quote(this.#t),window.getSelection()?.removeAllRanges(),this.#a()},{signal:t});let r=this.#e.messages;r.addEventListener("mouseup",o=>this.#r(o),{signal:t}),r.addEventListener("keyup",()=>this.#r(),{signal:t}),r.addEventListener("mousedown",()=>this.#a(),{signal:t})}#o(){return this.#e.element.getAttribute("data-quote-selection")!=="false"}#r(t){if(!this.#o())return;let n=t===void 0?void 0:{x:t.clientX,y:t.clientY},r=to(this.#e.messages,[this.#e.root],n);if(r===null){this.#a();return}this.#t=r.text,this.#i(r.rect)}#i(t){let n=this.button;n.hidden=!1;let r=this.#e.messagesWrap.getBoundingClientRect(),o=t.top-r.top,i=o<rd+n.offsetHeight;n.dataset.below=String(i),n.style.top=`${i?t.bottom-r.top+rd:o-rd}px`;let a=n.offsetWidth/2,s=t.left+t.width/2-r.left;n.style.left=`${Math.min(Math.max(s,a),r.width-a)}px`}#a(){this.button.hidden=!0,this.#t=""}};function no(e,t=Date.now(),n=fe){if(!Number.isFinite(e))return n.justNow;let r=Math.round((t-e)/1e3);if(r<60)return n.justNow;let o=Math.round(r/60);if(o<60)return ue(n.minutesAgo,{n:o});let i=Math.round(o/60);if(i<24)return ue(n.hoursAgo,{n:i});let a=Math.round(i/24);return a<7?ue(n.daysAgo,{n:a}):ue(n.weeksAgo,{n:Math.round(a/7)})}function Pb(e){return e.preview!==void 0&&e.preview!==null&&e.preview!==""?e.preview:null}function Mb(e){return e.replace(/\s+/g," ").trim()}var ro=class{element;#e;#t;#n;#o=null;#r=null;#i;#a=[];constructor(t,n=fe){this.#e=t,this.#i=n,this.element=document.createElement("div"),this.element.className="checkpoints",this.element.setAttribute("part","checkpoints"),this.element.setAttribute("role","dialog"),this.element.setAttribute("aria-label",n.checkpoints),this.element.tabIndex=-1,this.element.hidden=!0;let r=document.createElement("div");r.className="checkpoints-header",r.setAttribute("part","checkpoints-header"),this.#n=document.createElement("span"),this.#n.className="checkpoints-title",this.#n.setAttribute("part","checkpoints-title"),this.#n.textContent=n.checkpoints,r.append(this.#n),this.#t=document.createElement("div"),this.#t.className="checkpoints-list",this.#t.setAttribute("part","checkpoints-list"),this.element.append(r,this.#t),this.element.addEventListener("keydown",o=>this.#d(o))}setRuns(t){this.#a=t,this.#f()}setRelativeTimeFormatter(t){this.#r=t}#s(t){return this.#r!==null?this.#r(t):no(t,Date.now(),this.#i)}setStrings(t){this.#i=t,this.element.setAttribute("aria-label",t.checkpoints),this.#n.textContent=t.checkpoints,this.#f()}open(){this.open_||(this.#o=this.#c(),this.element.hidden=!1,(this.#u()[0]??this.element).focus())}close(){this.open_&&(this.element.hidden=!0,this.#o?.focus(),this.#o=null)}#c(){return this.element.getRootNode().activeElement}#u(){return Array.from(this.element.querySelectorAll("button, [tabindex]")).filter(t=>!t.hidden)}#d(t){if(t.key==="Escape"){t.stopPropagation(),this.close();return}if(t.key!=="Tab")return;let n=this.#u(),r=n[0],o=n[n.length-1],i=this.#c();t.shiftKey&&i===r?(t.preventDefault(),o?.focus()):!t.shiftKey&&i===o&&(t.preventDefault(),r?.focus())}get open_(){return!this.element.hidden}#f(){if(this.#t.replaceChildren(),this.#a.length===0){let n=document.createElement("div");n.className="checkpoints-empty",n.setAttribute("part","checkpoints-empty"),n.textContent=this.#i.noCheckpoints,this.#t.append(n);return}let t=this.#p();for(let n of this.#a)this.#t.append(this.#m(n,t))}#p(){let t=new Set,n=new Set;for(let r of this.#a){let o=Pb(r);if(o===null)continue;let i=Mb(o);t.has(i)&&n.add(i),t.add(i)}return n}#m(t,n){let r=document.createElement("div");r.className="checkpoint-row",r.setAttribute("part","checkpoint-row");let o=Pb(t),i=t.started_at===null?null:this.#s(Date.parse(t.started_at)),a=document.createElement("span");if(a.className="checkpoint-label",a.setAttribute("part","checkpoint-label"),a.textContent=o??i??t.run_id,r.append(a),o!==null&&i!==null){let l=document.createElement("span");l.className="checkpoint-time",l.setAttribute("part","checkpoint-time"),l.textContent=i,r.append(l)}if((o===null?i!==null:n.has(Mb(o)))&&t.run_id!==""){let l=document.createElement("span");l.className="checkpoint-id",l.setAttribute("part","checkpoint-id"),l.textContent=t.run_id.slice(0,8),l.title=t.run_id,r.append(l)}if(t.parent_run_id!==null){let l=document.createElement("span");l.className="checkpoint-branch",l.setAttribute("part","checkpoint-branch"),l.textContent=this.#i.forkedRun,l.title=t.parent_run_id,r.append(l)}return r.append(this.#l(t.run_id,"resume",this.#i.resumeRun),this.#l(t.run_id,"fork",this.#i.forkRun)),r}#l(t,n,r){let o=document.createElement("button");return o.type="button",o.className=`checkpoint-action checkpoint-${n}`,o.setAttribute("part",`checkpoint-action checkpoint-${n}`),o.textContent=r,o.addEventListener("click",()=>{this.close(),this.#e(t,n)}),o}};function od(e){let t=Qa(e,"attachments");return Array.isArray(t)?t.filter(zA):[]}function zA(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.id=="string"&&typeof t.name=="string"&&typeof t.mime=="string"&&typeof t.size=="number"&&(t.url===void 0||typeof t.url=="string")}var oo=class{#e;#t;#n;constructor(t,n=()=>({}),r=()=>{}){this.#e=t.endsWith("/")?t:`${t}/`,this.#t=n,this.#n=r}async list(){try{let t=await fetch(this.#e,ot({method:"GET",headers:{Accept:"application/json",...this.#t()}},this.#n()));return t.ok?(await t.json()).runs??[]:[]}catch{return[]}}async continuable(){return(await this.list()).filter(t=>t.continuable)}resumeUrl(t){return this.#o("resume",t)}forkUrl(t){return this.#o("fork",t)}#o(t,n){return`${this.#e.slice(0,-5)}${t}/${encodeURIComponent(n)}/`}};function io(e){return e===Ve.FAILED?te.ERROR:e===Ve.DENIED?te.DECLINED:e===Ve.INTERRUPTED?te.INTERRUPTED:te.DONE}var fs=class{#e;#t="";#n=[];#o=0;#r=0;#i=null;#a=null;#s=null;#c=null;constructor(t){this.#e=t}get threadId(){return this.#t}get restored(){return this.#n}get continuation(){return this.#s}adoptActiveThread(){this.#t=this.#e.conversationStore().threadId()}startThread(){this.#t=Xa(this.#e.conversationStore())}stopContinuation(){this.#s?.cancel(),this.#s=null}forgetRestored(){this.#n=[],this.#o+=1,this.#r+=1,this.#u()}#u(){let t=this.#c;this.#c=null,t?.()}reapUnsent(){this.#e.conversationStore().isUnsent?.(this.#t)===!0&&this.#e.conversationStore().clear(this.#t)}runs(){let t=this.#e.element.getAttribute("data-runs-url");return t===null||t===""?null:(this.#a===null&&(this.#a=new oo(t,()=>this.#e.headersFor(t),()=>this.#e.requestCredentials())),this.#a)}openThreads(){this.#e.checkpoints.close(),this.refreshDrawer(),this.#e.drawer.open()}openCheckpoints(){this.#e.drawer.close(),this.#d(),this.#e.checkpoints.open()}async switchThread(t){t!==this.#t&&(this.#e.cancelRun(),this.#e.resetState(),this.#e.conversationStore().setActiveThread(t),this.#t=t,this.#e.setRunning(!1),await this.rehydrate())}renameThread(t,n){this.#e.conversationStore().renameThread(t,n),this.refreshDrawer()}deleteThread(t){let n=t===this.#t;n&&this.#e.cancelRun(),this.#e.conversationStore().clear(t),n&&(this.#e.resetState(),this.adoptActiveThread(),this.#e.setRunning(!1)),this.refreshDrawer()}async refreshDrawer(){this.#e.drawer.setRelativeTimeFormatter(this.#e.formatRelativeTime()),this.#e.drawer.setThreads(await this.#e.conversationStore().listThreads(),this.#t)}async#d(){let t=this.runs();this.#e.checkpoints.setRelativeTimeFormatter(this.#e.formatRelativeTime()),this.#e.checkpoints.setRuns(t===null?[]:await t.continuable())}async continueRun(t,n){let r=this.runs();if(r===null)return;if(this.#e.running()||this.#s!==null){let s=this.#e.strings();this.#f(this.#c===null?s.continueWhileRunning:s.continueWhileLoading);return}let o=this.#e.input.value.trim();if(o===""){this.#f(this.#e.strings().continueNeedsTurn);return}this.#e.recordTurn(o),this.#e.input.value="",this.#e.autoGrow();let i=this.#o,a=this.#e.buildClient({endpoint:n==="resume"?r.resumeUrl(t):r.forkUrl(t),initialMessages:[],follows:this.#e.client()?.messages??this.#n,onSaved:s=>{i===this.#o&&(this.#n=s,this.#e.releaseClient())}});this.#s=a;try{if(this.#e.announceTurn(o),this.#s!==a)return;await a.send(o)}finally{this.#s===a&&(this.#s=null,this.#e.continuationEnded())}}#f(t){this.#e.hint.textContent=t,this.#e.hint.hidden=!1,this.#e.input.focus()}async rehydrate(){this.#r+=1;let t=this.#r,n=this.#t,r=this.#e.conversationStore();this.#i={generation:t,store:r,threadId:n};let o=r.loadCheckpoint(n),i=o===null?new Promise(l=>{this.#c=l}):null,a=this.#c,s=this.#e.holdRun(i);try{this.#e.element.setAttribute("data-restoring","");let l;try{l=await r.loadMessages(n)}finally{t===this.#r&&this.#e.element.removeAttribute("data-restoring")}if(!this.#p(t)){this.#m(r,n,o);return}if(l!==null){let c=this.#e.strings().callNotFinished,u=Ja(l,f=>({id:_e(),role:"tool",content:c,toolCallId:f,metadata:{outcome:Ve.INTERRUPTED}}),new Set(o===null?[]:[o.toolCallId]));this.#n=u;for(let f of u)if(this.replay(f),!this.#p(t)){this.#m(r,n,o);return}}if(o!==null){await this.#y(o,t);return}this.#b(l)}finally{s.release(),this.#c===a&&this.#u()}}#p(t){return t===this.#r&&this.#e.element.isConnected}#m(t,n,r){r!==null&&!this.#l(t,n)&&t.saveCheckpoint(n,null)}#l(t,n){let r=this.#i;return r?.generation===this.#r&&r.store===t&&r.threadId===n}#b(t){let n=t?.at(-1);n===void 0||n.role!==Ze.USER||this.#e.transcript.appendNotice("\u26A0",this.#e.strings().runInterrupted,"interrupted")}replay(t){let n=typeof t.content=="string"?t.content:"";if(t.role===Ze.USER){let r=od(t);if(n!==""||r.length>0){let o=this.#e.appendMessage(Ze.USER,n);r.length>0&&o.appendChild(as(r))}return}if(t.role===Ze.ASSISTANT){if(n!==""){let r=this.#e.appendMessage(Ze.ASSISTANT,n);r.classList.add("message--restored");let o=t.id;this.#e.actions.attach(r,typeof o=="string"&&o!==""?{messageId:o}:{rateable:!1})}for(let r of LA(t.toolCalls)){let o={id:r.id,name:r.function.name,args:this.#g(r.function.arguments)};if(this.#e.transcript.noticeIfSkillLoad(o))continue;this.#e.transcript.setCardElement(o.id,this.#e.transcript.cardFor(o).element);let i=this.#e.tools.resolve(o.name)?.render;i!==void 0&&this.#e.transcript.renderToolOutput(i,o)}return}if(t.role==="activity"){let r=t;typeof r.activityType=="string"&&this.#e.activities.draw(t.id,r.activityType,r.content);return}if(t.role==="tool"){let r=this.#e.transcript.card(t.toolCallId);r!==void 0&&r.settle(io(Qa(t,"outcome")),Zn(t.content))}}#g(t){if(typeof t!="string")return{};try{let n=JSON.parse(t);if(typeof n=="object"&&n!==null)return n}catch{}return{}}async#y(t,n){this.#e.conversationStore().saveCheckpoint(this.#t,null);let r=this.#e.ensureClient(),o=JSON.stringify(this.#e.navigationResult().call(this.#e.element,t));this.#p(n)&&(r.addToolResult(t.toolCallId,o),this.#e.transcript.card(t.toolCallId)?.settle(te.DONE,o),await r.resume())}};function LA(e){return Array.isArray(e)?e.filter(DA):[]}function DA(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.id=="string"&&typeof t.function?.name=="string"}var $A=8,ms=class{element;#e;#t;#n;#o;#r;#i=null;#a;#s=[];#c="";#u;#d;#f="";#p=null;constructor(t,n=fe){this.#e=t,this.#a=n,this.element=document.createElement("div"),this.element.className="drawer",this.element.setAttribute("part","drawer"),this.element.hidden=!0;let r=document.createElement("div");r.className="drawer-backdrop",r.setAttribute("part","drawer-backdrop"),r.addEventListener("click",()=>this.close()),this.#t=document.createElement("div"),this.#t.className="drawer-panel",this.#t.setAttribute("part","drawer-panel"),this.#t.setAttribute("role","dialog"),this.#t.setAttribute("aria-modal","true"),this.#t.setAttribute("aria-label",n.chatHistory),this.#t.addEventListener("keydown",i=>this.#b(i));let o=document.createElement("div");o.className="drawer-header",o.setAttribute("part","drawer-header"),this.#n=document.createElement("span"),this.#n.className="drawer-title",this.#n.setAttribute("part","drawer-title"),this.#n.textContent=n.chats,this.#o=document.createElement("button"),this.#o.type="button",this.#o.className="drawer-new",this.#o.setAttribute("part","drawer-new"),this.#o.textContent=n.newChat,this.#o.addEventListener("click",()=>{this.close(),this.#e.onNew()}),this.#u=document.createElement("button"),this.#u.type="button",this.#u.className="drawer-close",this.#u.setAttribute("part","drawer-close"),this.#u.title=n.closeHistory,this.#u.setAttribute("aria-label",n.closeHistory),this.#u.append(document.createTextNode("\xD7")),this.#u.addEventListener("click",()=>this.close()),o.append(this.#n,this.#o,this.#u),this.#d=document.createElement("input"),this.#d.type="search",this.#d.className="drawer-filter",this.#d.setAttribute("part","drawer-filter"),this.#d.placeholder=n.searchConversations,this.#d.setAttribute("aria-label",n.searchConversations),this.#d.addEventListener("input",()=>{this.#f=this.#d.value.trim().toLowerCase(),this.#g()}),this.#r=document.createElement("div"),this.#r.className="drawer-list",this.#r.setAttribute("part","drawer-list"),this.#t.append(o,this.#d,this.#r),this.element.append(r,this.#t)}setRelativeTimeFormatter(t){this.#i=t}#m(t){return this.#i!==null?this.#i(t):no(t,void 0,this.#a)}setStrings(t){this.#a=t,this.#t.setAttribute("aria-label",t.chatHistory),this.#n.textContent=t.chats,this.#o.textContent=t.newChat,this.#u.title=t.closeHistory,this.#u.setAttribute("aria-label",t.closeHistory),this.#d.placeholder=t.searchConversations,this.#d.setAttribute("aria-label",t.searchConversations),this.#g()}isOpen(){return!this.element.hidden}open(){this.isOpen()||(this.#p=this.#l(),this.element.hidden=!1,this.#o.focus())}close(){this.isOpen()&&(this.element.hidden=!0,this.#p?.focus(),this.#p=null)}toggle(){this.isOpen()?this.close():this.open()}#l(){return this.element.getRootNode().activeElement}#b(t){if(t.key==="Escape"){t.preventDefault(),this.close();return}if(t.key!=="Tab")return;let n=Array.from(this.#t.querySelectorAll("button, input, [tabindex]")).filter(a=>!a.hidden),r=n[0],o=n[n.length-1],i=this.#l();t.shiftKey&&i===r?(t.preventDefault(),o?.focus()):!t.shiftKey&&i===o&&(t.preventDefault(),r?.focus())}setThreads(t,n){this.#s=t,this.#c=n,this.#g()}#g(){this.#r.replaceChildren();let t=this.#s.length<$A;this.#d.hidden=t,t&&this.#f!==""&&(this.#d.value="",this.#f="");let n=this.#y();if(n.length===0){let r=document.createElement("div");r.className="drawer-empty",r.setAttribute("part","drawer-empty"),r.textContent=this.#s.length===0?this.#a.noConversations:this.#a.noMatches,this.#r.appendChild(r);return}for(let r of n)this.#r.appendChild(this.#E(r))}#y(){return this.#f===""?this.#s:this.#s.filter(t=>t.title.toLowerCase().includes(this.#f)||t.preview.toLowerCase().includes(this.#f))}#E(t){let n=document.createElement("div");n.className="drawer-row",n.setAttribute("part","drawer-row"),t.threadId===this.#c&&n.classList.add("drawer-row--active");let r=document.createElement("button");r.type="button",r.className="drawer-row-select",r.setAttribute("part","drawer-row-select");let o=document.createElement("span");o.className="drawer-row-title",o.setAttribute("part","drawer-row-title"),o.textContent=t.title;let i=document.createElement("span");i.className="drawer-row-time",i.setAttribute("part","drawer-row-time"),i.textContent=this.#m(t.updatedAt);let a=document.createElement("span");a.className="drawer-row-preview",a.setAttribute("part","drawer-row-preview"),a.textContent=t.preview,r.append(o,i,a),r.addEventListener("click",()=>{this.close(),this.#e.onSelect(t.threadId)});let s=document.createElement("button");s.type="button",s.className="drawer-row-rename",s.setAttribute("part","drawer-row-rename"),s.title=this.#a.rename,s.setAttribute("aria-label",this.#a.renameConversation),s.textContent="\u270E",s.addEventListener("click",()=>this.#_(n,t));let l=document.createElement("button");l.type="button",l.className="drawer-row-delete",l.setAttribute("part","drawer-row-delete"),l.title=this.#a.delete,l.setAttribute("aria-label",this.#a.deleteConversation),l.textContent="\u{1F5D1}",l.addEventListener("click",()=>this.#h(n,t));let c=document.createElement("div");return c.className="drawer-row-actions",c.setAttribute("part","drawer-row-actions"),c.append(s,l),n.append(r,c),n}#_(t,n){let r=document.createElement("input");r.type="text",r.className="drawer-rename-input",r.setAttribute("part","drawer-rename-input"),r.value=n.title;let o=!1,i=()=>{if(o)return;o=!0;let s=r.value.trim();s===""||s===n.title?this.#g():this.#e.onRename(n.threadId,s)},a=()=>{o||(o=!0,this.#g())};r.addEventListener("keydown",s=>{s.key==="Enter"?(s.preventDefault(),i()):s.key==="Escape"&&(s.preventDefault(),s.stopPropagation(),a())}),r.addEventListener("blur",()=>i()),t.replaceChildren(r),r.focus(),r.select()}#h(t,n){let r=document.createElement("div");r.className="drawer-confirm",r.setAttribute("part","drawer-confirm");let o=document.createElement("span");o.className="drawer-confirm-label",o.setAttribute("part","drawer-confirm-label"),o.textContent=this.#a.deletePrompt;let i=document.createElement("button");i.type="button",i.className="drawer-confirm-yes",i.setAttribute("part","drawer-confirm-yes"),i.textContent=this.#a.delete,i.addEventListener("click",()=>this.#e.onDelete(n.threadId));let a=document.createElement("button");a.type="button",a.className="drawer-confirm-no",a.setAttribute("part","drawer-confirm-no"),a.textContent=this.#a.cancel,a.addEventListener("click",()=>this.#g()),r.append(o,i,a),t.replaceChildren(r)}};var gs=class{#e=null;open(){return this.#e=new AbortController,this.#e.signal}close(){this.#e=null}abort(){this.#e?.abort()}};function Wt(e,t,n=st){let r=Math.min(n,Math.max(0,(t.width-e.width)/2)),o=Math.min(n,Math.max(0,(t.height-e.height)/2));return{left:Math.max(t.left+r,Math.min(e.left,t.left+t.width-e.width-r)),top:Math.max(t.top+o,Math.min(e.top,t.top+t.height-e.height-o))}}function ao(e,t,n=tn){let r=e.right-e.left,o=e.bottom-e.top,i=Math.max(t.left+n,Math.min(e.left,t.left+t.width-n-r)),a=Math.max(t.top+n,Math.min(e.top,t.top+t.height-n-o));return{left:i,top:a,right:i+r,bottom:a+o}}var UA=4,HA=16,FA=64;function zb(e,t){let n=!1,{signal:r}=t;e.addEventListener("click",a=>{!n||a.detail===0||(n=!1,a.stopPropagation(),a.preventDefault())},{capture:!0,signal:r}),e.addEventListener("pointerdown",a=>{if(n=!1,!t.enabled())return;let s=t.rect(),l=a.clientX,c=a.clientY,u=!1,f=p=>{let h=p.clientX-l,E=p.clientY-c;if(!u&&Math.hypot(h,E)<UA)return;u=!0,e.setAttribute("data-dragging","true");let g=Wt({...s,left:s.left+h,top:s.top+E},t.viewport());t.apply(g.left,g.top)},m=p=>{if(window.removeEventListener("pointermove",f),window.removeEventListener("pointerup",m),window.removeEventListener("pointercancel",m),!u)return;e.removeAttribute("data-dragging"),n=!0;let h=Wt({...s,left:s.left+(p.clientX-l),top:s.top+(p.clientY-c)},t.viewport());t.commit(h.left,h.top)};window.addEventListener("pointermove",f),window.addEventListener("pointerup",m),window.addEventListener("pointercancel",m)},{signal:r});let o=null,i=()=>{if(o===null)return;let{left:a,top:s}=o;o=null,t.commit(a,s)};e.addEventListener("keydown",a=>{if(!t.enabled())return;let s=a.shiftKey?FA:HA,l=t.rect(),c=null;if(a.key==="ArrowLeft"?c={left:l.left-s,top:l.top}:a.key==="ArrowRight"?c={left:l.left+s,top:l.top}:a.key==="ArrowUp"?c={left:l.left,top:l.top-s}:a.key==="ArrowDown"&&(c={left:l.left,top:l.top+s}),c===null)return;a.preventDefault();let u=Wt({...l,...c},t.viewport());t.apply(u.left,u.top),o=u},{signal:r}),e.addEventListener("keyup",i,{signal:r}),e.addEventListener("blur",i,{signal:r})}function so(e,t,n,r){return{hostInset:Lb({top:n.y==="top"?e.top:null,right:n.x==="right"?r.width-e.right:null,bottom:n.y==="bottom"?r.height-e.bottom:null,left:n.x==="left"?e.left:null}),launcherInset:Lb({top:n.y==="top"?t.top-e.top:null,right:n.x==="right"?e.right-(t.left+t.width):null,bottom:n.y==="bottom"?e.bottom-(t.top+t.height):null,left:n.x==="left"?t.left-e.left:null})}}function Lb(e){let t=n=>n===null?"auto":`${Math.round(n)}px`;return`${t(e.top)} ${t(e.right)} ${t(e.bottom)} ${t(e.left)}`}function id(e,t,n,r,o=st){let i=n.left+n.width-e.left,a=e.left+e.width-n.left,s=n.top+n.height-e.top,l=e.top+e.height-n.top,c={x:i>=a?"left":"right",y:s>=l?"top":"bottom"},u=c.x==="left"?e.left:e.left+e.width-t.width,f=c.y==="top"?e.top:e.top+e.height-t.height,m=ao({left:u,top:f,right:u+t.width,bottom:f+t.height},n,o);return{corner:c,...so(m,e,c,r)}}var GA="button, a[href], input, select, textarea, [contenteditable]";function Db(e,t){e.addEventListener("pointerdown",n=>{if(n.button!==0||!t.enabled()||BA(n,e))return;let r=t.rect(),o=n.clientX,i=n.clientY,a=!1,s=(u,f)=>{let m=u-o,p=f-i;return{left:r.left+m,top:r.top+p,right:r.right+m,bottom:r.bottom+p}},l=u=>{!a&&Math.hypot(u.clientX-o,u.clientY-i)<4||(a=!0,e.setAttribute("data-dragging","true"),t.apply(s(u.clientX,u.clientY),r))},c=u=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",c),window.removeEventListener("pointercancel",c),a&&(e.removeAttribute("data-dragging"),t.commit(s(u.clientX,u.clientY),r))};n.preventDefault(),window.addEventListener("pointermove",l),window.addEventListener("pointerup",c),window.addEventListener("pointercancel",c)})}function BA(e,t){let n=e.composedPath();return n.slice(0,n.indexOf(t)).some(r=>r instanceof Element&&r.matches(GA))}function Ub(e,t){let n=document.createElement("div");n.className=`resize-handle resize-handle--${vs(e)}`,n.setAttribute("part",`resize-handle resize-handle-${vs(e)}`),n.setAttribute("role","separator"),e.x===void 0?n.setAttribute("aria-orientation","horizontal"):e.y===void 0&&n.setAttribute("aria-orientation","vertical"),n.setAttribute("aria-label",t.label),n.tabIndex=0,n.addEventListener("pointerdown",i=>{let a=t.axis();if(a==="none"||!$b(e,a))return;let s=t.rect(),l=u=>{t.apply(ad(e,a,s,u.clientX,u.clientY))},c=u=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",c),n.removeAttribute("data-dragging"),t.commit(ad(e,a,s,u.clientX,u.clientY))};n.setAttribute("data-dragging","true"),window.addEventListener("pointermove",l),window.addEventListener("pointerup",c),i.preventDefault()});let r=null,o=()=>{if(r===null)return;let i=r;r=null,t.commit(i)};return n.addEventListener("keydown",i=>{let a=t.axis();if(a==="none"||!$b(e,a))return;let s=i.shiftKey?64:16,l=t.rect(),c=ZA[i.key];if(c===void 0||c.x!==0&&e.x===void 0||c.y!==0&&e.y===void 0)return;i.preventDefault();let u=(e.x==="left"?l.left:l.right)+c.x*s,f=(e.y==="top"?l.top:l.bottom)+c.y*s,m=ad(e,a,l,u,f);t.apply(m),r=m}),n.addEventListener("keyup",o),n.addEventListener("blur",o),n}var ZA={ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0},ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1}};function vs(e){return[e.y,e.x].filter(t=>t!==void 0).join("-")}function $b(e,t){return t==="both"||e.x!==void 0}function ad(e,t,n,r,o){let i=e.x==="left"?Math.min(r,n.right-280):n.left,a=e.x==="right"?Math.max(r,n.left+280):n.right,s=t==="both",l=s&&e.y==="top"?Math.min(o,n.bottom-240):n.top,c=s&&e.y==="bottom"?Math.max(o,n.top+240):n.bottom;return{left:i,top:l,right:a,bottom:c}}var bs={collapseTo:"launcher",launcherDraggable:!0,resizeAxis:"both",startsCollapsed:!0},Hb={collapseTo:"launcher",launcherDraggable:!1,resizeAxis:"width",startsCollapsed:!1},VA=new Map([[null,bs],["",bs],["floating",bs],["bottom-left",bs],["side",Hb],["sidebar",{...Hb,collapseTo:"rail"}],["full",{collapseTo:"launcher",launcherDraggable:!1,resizeAxis:"none",startsCollapsed:!1}],["page",{collapseTo:null,launcherDraggable:!1,resizeAxis:"none",startsCollapsed:!1}],["embedded",{collapseTo:"header",launcherDraggable:!1,resizeAxis:"both",startsCollapsed:!1}]]),jA={collapseTo:"launcher",launcherDraggable:!1,resizeAxis:"both",startsCollapsed:!1};function Ot(e){return VA.get(e)??jA}var Fb="ag-ui-chat:size",sd="ag-ui-chat:launcher";function WA(e){if(typeof e!="object"||e===null)return null;let{left:t,top:n}=e;return typeof t=="number"&&typeof n=="number"?{left:t,top:n}:null}function Gb(e,t){return e.width>=t.width-1&&e.height>=t.height-1}function Bb(e,t,n){let r=o=>`${Math.round(o)}px`;return[e.y==="top"?r(t.top):"auto",e.x==="right"?r(n.width-t.right):"auto",e.y==="bottom"?r(n.height-t.bottom):"auto",e.x==="left"?r(t.left):"auto"].join(" ")}var qA=[{y:"top"},{y:"bottom"},{x:"left"},{x:"right"},{x:"left",y:"top"},{x:"right",y:"top"},{x:"left",y:"bottom"},{x:"right",y:"bottom"}],ys=class{#e;constructor(t){this.#e=t}enablePanelDrag(t){Db(t,{enabled:()=>!this.#e.collapsed()&&this.#m(),rect:()=>this.#e.element.getBoundingClientRect(),apply:(n,r)=>this.#h(n,r),commit:(n,r)=>this.#C(n,r)})}enableLauncherDrag(t){zb(this.#e.launcher,{signal:t,enabled:()=>this.#e.collapsed()&&this.#m(),rect:()=>this.#g(),viewport:()=>this.#l(),apply:(n,r)=>this.#E(n,r),commit:(n,r)=>this.#_(n,r)})}mountResizeGrips(t){for(let n of qA){let r=Ub(n,{axis:()=>this.#c(),rect:()=>this.#e.element.getBoundingClientRect(),apply:o=>this.#k(n,o),commit:o=>this.#M(n,o),label:this.#e.strings().resizePanel});r.tabIndex=-1,r.setAttribute("aria-hidden","true"),this.#i.set(vs(n),r),t.appendChild(r)}this.#V()}restoreSize(){this.#p(this.#z())}probe=document.createElement("div");#t=null;#n=null;#o=null;#r={x:"right",y:"bottom"};#i=new Map;#a(t){let n=this.#l(),r=n.left+st,o=n.top+st,i=n.left+n.width-st,a=n.top+n.height-st;return{left:Math.min(Math.max(t.left,r),t.right),top:Math.min(Math.max(t.top,o),t.bottom),right:Math.max(Math.min(t.right,i),t.left),bottom:Math.max(Math.min(t.bottom,a),t.top)}}dragging(){return this.#e.launcher.hasAttribute("data-dragging")||this.#e.root.querySelector(".header[data-dragging]")!==null}describeSurface(){let t=this.#e.element.getBoundingClientRect(),n=this.#l(),r=Gb(t,n);return{placement:this.#e.element.getAttribute("placement"),collapsed:this.#e.collapsed(),collapsible:this.#e.collapsible(),movable:this.#m()&&!r,draggable:this.#m(),fullBleed:r,box:{left:Math.round(t.left),top:Math.round(t.top),width:Math.round(t.width),height:Math.round(t.height)},viewport:{left:Math.round(n.left),top:Math.round(n.top),width:Math.round(n.width),height:Math.round(n.height)}}}moveTo(t,n={}){if(!this.#m())return!1;let r=n.announce===!0?this.#s():null,o=this.#l(),i=this.#e.element.getBoundingClientRect();if(Gb(i,o))return!1;let[a,s]=t.split("-"),l=o.left+tn,c=o.top+tn,u=s==="left"?l:Math.max(l,o.left+o.width-tn-i.width),f=a==="top"?c:Math.max(c,o.top+o.height-tn-i.height),m={left:u,top:f,right:u+i.width,bottom:f+i.height},p=this.#e.launcher.offsetWidth,h=this.#e.launcher.offsetHeight;return this.#P(m,{left:s==="left"?m.left:m.right-p,top:a==="top"?m.top:m.bottom-h,width:p,height:h}),this.#A(),r!==null&&this.#e.announceSurfaceChange(this.#e.strings().chatMoved,r),!0}#s(){let t=this.#e.element.style.getPropertyValue("--ag-ui-inset"),n=this.#e.element.style.getPropertyValue("--ag-ui-launcher-inset"),r=this.#e.element.getAttribute("data-expand-corner"),o=this.#t,i=this.#n,a=this.#o;return()=>{this.#f("--ag-ui-inset",t),this.#f("--ag-ui-launcher-inset",n),r===null?this.#e.element.removeAttribute("data-expand-corner"):this.#e.element.setAttribute("data-expand-corner",r),this.#t=o,this.#n=i,this.#o=a,o===null?this.#e.clearPreference(sd):this.#A(),this.syncResizeAnchor()}}#c(){return Ot(this.#e.element.getAttribute("placement")).resizeAxis}#u(){let t=this.#e.element.getBoundingClientRect(),n=this.#e.element.style.getPropertyValue("--ag-ui-width"),r=this.#e.element.style.getPropertyValue("--ag-ui-height"),o=this.#d(t,-1),i=o.x===null||o.y===null?this.#d(t,1):o;return this.#f("--ag-ui-width",n),this.#f("--ag-ui-height",r),{x:o.x??i.x??"right",y:o.y??i.y??"bottom"}}#d(t,n){this.#p({width:t.width+n,height:t.height+n});let r=this.#e.element.getBoundingClientRect(),o=(i,a)=>Math.abs(i-a)>=.5;return{x:o(r.width,t.width)?o(r.left,t.left)?"right":"left":null,y:o(r.height,t.height)?o(r.top,t.top)?"bottom":"top":null}}syncResizeAnchor(){if(!this.#e.connected())return;let t=this.#o??this.#u();this.#r=t,this.#e.element.setAttribute("data-resize-anchor",`${t.y}-${t.x}`),this.#V()}#f(t,n){if(n===""){this.#e.element.style.removeProperty(t);return}this.#e.element.style.setProperty(t,n)}#p(t){let n=this.#c();n!=="none"&&(t.width!==void 0&&this.#e.element.style.setProperty("--ag-ui-width",`${t.width}px`),t.height!==void 0&&n==="both"&&this.#e.element.style.setProperty("--ag-ui-height",`${t.height}px`))}releaseOwnedAxes(){let t=this.#c();t!=="both"&&this.#e.element.style.removeProperty("--ag-ui-height"),t==="none"&&this.#e.element.style.removeProperty("--ag-ui-width")}#m(){return this.#e.element.getAttribute("data-launcher-drag")!=="false"&&Ot(this.#e.element.getAttribute("placement")).launcherDraggable}#l(){let t=window.visualViewport,n=t?.width??window.innerWidth,r=t?.height??window.innerHeight,o=getComputedStyle(this.probe),i=l=>{let c=Number.parseFloat(o.getPropertyValue(l));return Number.isFinite(c)?c:0},a=i("padding-left"),s=i("padding-top");return{left:a,top:s,width:Math.max(0,n-a-i("padding-right")),height:Math.max(0,r-s-i("padding-bottom"))}}#b(){let t=document.documentElement;return{width:t.clientWidth||window.innerWidth,height:t.clientHeight||window.innerHeight}}publishVisualViewport(){let t=window.visualViewport;if(t==null)return;let n=this.#b().height;if(Math.abs(t.height-n)<1){this.#e.element.style.removeProperty("--ag-ui-visual-viewport-height"),this.#e.element.style.removeProperty("--ag-ui-visual-viewport-inset-bottom"),this.#e.element.style.removeProperty("--ag-ui-visual-viewport-inset-top");return}this.#e.element.style.setProperty("--ag-ui-visual-viewport-height",`${Math.round(t.height)}px`);let r=n-t.height-t.offsetTop;this.#e.element.style.setProperty("--ag-ui-visual-viewport-inset-bottom",`${Math.max(0,Math.round(r))}px`),this.#e.element.style.setProperty("--ag-ui-visual-viewport-inset-top",`${Math.max(0,Math.round(t.offsetTop))}px`)}#g(){let t=this.#e.launcher.offsetWidth,n=this.#e.launcher.offsetHeight,r=this.#t;if(r!==null)return{left:r.left,top:r.top,width:t,height:n};let o=this.#e.launcher.getBoundingClientRect();return{left:o.left+o.width/2-t/2,top:o.top+o.height/2-n/2,width:t,height:n}}#y(t){if(!this.#m())return;this.#t=t,this.#n=null;let n=this.#e.element.getBoundingClientRect(),r=id(this.#g(),{width:n.width,height:n.height},this.#l(),this.#b());this.#e.element.style.setProperty("--ag-ui-inset",r.hostInset),this.#e.element.style.setProperty("--ag-ui-launcher-inset",r.launcherInset),this.#o=r.corner,this.#e.element.setAttribute("data-expand-corner",`${r.corner.y}-${r.corner.x}`),this.syncResizeAnchor()}#E(t,n){this.#y({left:t,top:n})}#_(t,n){this.#E(t,n),this.#A()}#h(t,n){if(!this.#m())return{held:t,launcher:null};if(this.#t===null){let l=this.#g();this.#t={left:l.left,top:l.top}}let r=this.#t,o=ao(t,this.#l(),st),i=this.#o??this.#r;this.#e.element.style.setProperty("--ag-ui-inset",Bb(i,o,this.#b())),this.#n={left:o.left,top:o.top};let a={...this.#g(),left:r.left+(o.left-n.left),top:r.top+(o.top-n.top)},s={...a,...Wt(a,this.#l())};return this.#e.element.style.setProperty("--ag-ui-launcher-inset",so(o,s,i,this.#b()).launcherInset),{held:o,launcher:s}}#C(t,n){let{held:r,launcher:o}=this.#h(t,n);o!==null&&(this.#P(r,o),this.#A())}#P(t,n){let r=this.#l(),o=this.#b(),i={width:t.right-t.left,height:t.bottom-t.top},{corner:a}=id(n,i,r,o),s=so(t,n,a,o);this.#e.element.style.setProperty("--ag-ui-inset",s.hostInset),this.#e.element.style.setProperty("--ag-ui-launcher-inset",s.launcherInset),this.#t={left:n.left,top:n.top},this.#n={left:t.left,top:t.top},this.#o=a,this.#e.element.setAttribute("data-expand-corner",`${a.y}-${a.x}`),this.syncResizeAnchor()}#B(t){if(!this.#m())return;let n=this.#e.element.getBoundingClientRect(),r=ao({left:t.left,top:t.top,right:t.left+n.width,bottom:t.top+n.height},this.#l(),st),o=this.#g(),i={...o,left:o.left+(r.left-t.left),top:o.top+(r.top-t.top)};this.#P(r,{...i,...Wt(i,this.#l())})}#A(){let t=this.#t;if(t===null)return;let n=this.#n;this.#e.writePreference(sd,JSON.stringify(n===null?t:{...t,panel:n}))}restoreLauncherPosition(){let t=this.#Z(),n=this.#t??t;if(n===null)return;let r=this.#n??t?.panel??null;if(r!==null){this.#t={left:n.left,top:n.top},this.#B(r);return}let o=this.#g();this.#y(Wt({...o,left:n.left,top:n.top},this.#l()))}#Z(){let t=this.#e.readPreference(sd);if(t===null)return null;try{let n=JSON.parse(t);if(typeof n!="object"||n===null)return null;let{left:r,top:o,panel:i}=n;if(typeof r!="number"||typeof o!="number")return null;let a=WA(i);return a===null?{left:r,top:o}:{left:r,top:o,panel:a}}catch{return null}}releaseLauncherPosition(){this.#m()||(this.#t=null,this.#n=null,this.#o=null,this.#e.element.style.removeProperty("--ag-ui-inset"),this.#e.element.style.removeProperty("--ag-ui-launcher-inset"),this.#e.element.removeAttribute("data-expand-corner"))}#k(t,n){if(n=this.#a(n),this.#p({width:n.right-n.left,height:n.bottom-n.top}),t.x!==this.#r.x&&t.y!==this.#r.y)return n;let r=this.#r;if(this.#e.element.style.setProperty("--ag-ui-inset",Bb(r,n,this.#b())),this.#t!==null){let o=this.#e.launcher.offsetWidth;this.#t={left:r.x==="left"?n.left:n.right-o,top:r.y==="top"?n.top:n.bottom-o}}return this.#n!==null&&(this.#n={left:n.left,top:n.top}),n}#M(t,n){let r=this.#k(t,n);this.#U({width:r.right-r.left,height:r.bottom-r.top}),this.#A(),this.syncResizeAnchor()}#V(){let t=`${this.#r.y==="top"?"bottom":"top"}-${this.#r.x==="left"?"right":"left"}`;for(let[n,r]of this.#i){let o=n===t;r.tabIndex=o?0:-1,o?r.removeAttribute("aria-hidden"):r.setAttribute("aria-hidden","true")}}#U(t){let n={...this.#z(),...t};this.#e.writePreference(Fb,JSON.stringify(n))}#z(){let t=this.#e.readPreference(Fb);if(t===null)return{};try{let n=JSON.parse(t);return typeof n=="object"&&n!==null?n:{}}catch{return{}}}};var ws=class{region=document.createElement("div");#e=null;mount(){this.region.className="sr-only",this.region.setAttribute("role","status"),this.region.setAttribute("aria-live","polite"),this.region.setAttribute("aria-atomic","true")}announce(t){this.#e!==null&&clearTimeout(this.#e),this.region.textContent=t,this.#e=setTimeout(()=>{this.#e=null,this.region.textContent=""},Lp)}dispose(){this.#e!==null&&(clearTimeout(this.#e),this.#e=null)}};function Es(e,t,n,r){let o=document.createElement("div");o.className=`run-notice run-notice--${n}`,o.setAttribute("part",`run-notice run-notice-${n}`),o.setAttribute("role","status");let i=document.createElement("span");i.className="run-notice-icon",i.setAttribute("part","run-notice-icon"),i.textContent=e,i.setAttribute("aria-hidden","true");let a=document.createElement("span");if(a.className="run-notice-text",a.setAttribute("part","run-notice-text"),a.textContent=t,o.append(i,a),r!==void 0){let s=document.createElement("button");s.type="button",s.className="run-notice-undo",s.setAttribute("part","run-notice-undo"),s.textContent=r.label,s.addEventListener("click",()=>{s.disabled=!0,r.onActivate()}),o.append(s)}return o}var xs=class{element;get agent(){return this.#r}#e;#t;#n;#o=new Map;#r=null;constructor(t=fe){this.element=document.createElement("div"),this.element.className="subagent",this.element.setAttribute("part","subagent"),this.#e=document.createElement("button"),this.#e.type="button",this.#e.className="subagent-row",this.#e.setAttribute("part","subagent-row"),this.#e.setAttribute("aria-expanded","false"),this.#e.disabled=!0;let n=document.createElement("span");n.className="subagent-icon",n.setAttribute("part","subagent-icon"),n.setAttribute("aria-hidden","true"),this.#t=document.createElement("span"),this.#t.className="subagent-status",this.#t.setAttribute("part","subagent-status"),this.#t.textContent=t.subAgentWorking,this.#e.append(n,this.#t),this.#n=document.createElement("div"),this.#n.className="subagent-steps",this.#n.setAttribute("part","subagent-steps"),this.#n.setAttribute("role","list"),this.#n.setAttribute("aria-label",t.subAgentSteps),this.#n.hidden=!0,this.#e.addEventListener("click",()=>{this.#s(this.#e.getAttribute("aria-expanded")!=="true")}),this.element.append(this.#e,this.#n)}report(t){this.element.setAttribute("data-phase",t.phase),t.agent!==null&&(this.#r=t.agent,this.element.setAttribute("data-agent",t.agent)),t.status!==null&&(this.#t.textContent=t.status),t.tool!==null&&this.#i(t.tool)}#i(t){let n=this.#o.get(t.toolCallId)??this.#a(t);if(t.ok===null){n.removeAttribute("data-ok");return}n.setAttribute("data-ok",String(t.ok))}#a(t){let n=document.createElement("div");n.className="subagent-step",n.setAttribute("part","subagent-step"),n.setAttribute("role","listitem"),n.setAttribute("data-tool-call-id",t.toolCallId);let r=document.createElement("span");r.className="subagent-step-icon",r.setAttribute("part","subagent-step-icon"),r.setAttribute("aria-hidden","true");let o=document.createElement("span");return o.className="subagent-step-name",o.setAttribute("part","subagent-step-name"),o.textContent=t.name,n.append(r,o),this.#n.appendChild(n),this.#o.set(t.toolCallId,n),this.#e.disabled=!1,n}#s(t){this.#n.hidden=!t,this.#e.setAttribute("aria-expanded",String(t))}};var YA=Object.values(Un);function Zb(e){return typeof e!="object"||e===null||Array.isArray(e)?null:e}function lo(e){return typeof e=="string"&&e!==""?e:null}function XA(e){let t=Zb(e);if(t===null)return null;let n=lo(t.toolCallId),r=lo(t.name),o=t.ok;return n===null||r===null||o!==null&&typeof o!="boolean"?null:{toolCallId:n,name:r,ok:o}}function Vb(e){let t=Zb(e);if(t===null)return null;let n=lo(t.delegationId),r=t.phase;return n===null||typeof r!="string"||!YA.includes(r)?null:{delegationId:n,phase:r,agent:lo(t.agent),status:lo(t.status),tool:XA(t.tool)}}var _s=class{#e;#t=new Map;#n=new Map;constructor(t){this.#e=t}report(t){let n=Vb(t);n!==null&&this.#i(n)}start(t,n,r){r!==null&&(this.#n.set(t,r),this.#i({delegationId:r,agent:n===""?null:n,phase:Un.STARTED,status:ue(this.#e.strings().subAgentDelegatedTo,{agent:n}),tool:null}))}finish(t){this.#o(t,Un.FINISHED,null)}fail(t,n){this.#o(t,Un.FAILED,n===""?this.#e.strings().subAgentFailed:n)}clear(){this.#t.clear(),this.#n.clear()}#o(t,n,r){let o=this.#n.get(t);if(o===void 0)return;let i=this.#t.get(o)?.agent??null;this.#i({delegationId:o,agent:i,phase:n,status:r===null?this.#r(i):r,tool:null})}#r(t){let n=this.#e.strings();return t===null?n.subAgentWorking:ue(n.subAgentFinished,{agent:t})}#i(t){let n=this.#e.card(t.delegationId);if(n===void 0)return;let r=this.#t.get(t.delegationId);r===void 0&&(r=new xs(this.#e.strings()),this.#t.set(t.delegationId,r),n.subagentSlot.appendChild(r.element)),r.report(t),this.#e.follow()}};function ld(e){return{[te.PENDING]:e.toolRunning,[te.DEFERRED]:e.toolDeferred,[te.DONE]:e.toolDone,[te.ERROR]:e.toolError,[te.DECLINED]:e.toolDeclined,[te.INTERRUPTED]:e.toolInterrupted}}function KA(e){return{[te.DONE]:e.resultLabel,[te.ERROR]:e.errorLabel,[te.DECLINED]:e.declinedLabel,[te.INTERRUPTED]:e.interruptedLabel}}function JA(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}var co=class{element;approvalSlot;subagentSlot;#e;#t;#n;#o;#r;#i;#a;args;#s;#c;#u=!1;constructor(t,n,r,o=fe,i={}){this.#a=o,this.args=n,this.#s=t,this.#c=i.formatPayload??null,this.element=document.createElement("div"),this.element.className="tool-call",this.element.setAttribute("part","tool-card"),this.element.setAttribute("data-tool-name",t),this.element.setAttribute("data-status",te.PENDING),this.element.setAttribute("data-expanded","false");let a=document.createElement("div");a.className="tool-call-head",a.setAttribute("part","tool-card-head");let s=document.createElement("span");s.className="tool-call-icon",s.setAttribute("part","tool-card-icon"),s.setAttribute("aria-hidden","true");let l=document.createElement("span");l.className="tool-call-name",l.setAttribute("part","tool-card-name"),l.textContent=r??t,this.#e=document.createElement("span"),this.#e.className="tool-call-status",this.#e.setAttribute("part","tool-card-status"),this.#e.textContent=ld(o)[te.PENDING],this.#t=document.createElement("span"),this.#t.className="tool-call-decision",this.#t.setAttribute("part","tool-card-decision"),this.#t.hidden=!0,a.append(s,l,this.#e,this.#t);let c=this.#f("args",o.argumentsLabel);this.#d(c.body,{kind:"arguments",toolName:t,args:n},JSON.stringify(n,null,2)),c.root.hidden=Object.keys(n).length===0;let u=this.#f("result",o.resultLabel);this.#o=u.root,this.#r=u.label,this.#i=u.body,u.root.hidden=!0,this.#n=document.createElement("button"),this.#n.type="button",this.#n.className="tool-call-toggle",this.#n.setAttribute("part","tool-card-toggle"),this.#n.setAttribute("aria-expanded","false"),this.#n.textContent=o.details,this.#n.addEventListener("click",()=>this.#m(!this.#p()));let f=document.createElement("div");f.className="tool-call-body",f.setAttribute("part","tool-card-body"),f.append(c.root,u.root),this.approvalSlot=document.createElement("div"),this.approvalSlot.className="tool-call-approval",this.approvalSlot.setAttribute("part","tool-card-approval"),this.subagentSlot=document.createElement("div"),this.subagentSlot.className="tool-call-subagent",this.subagentSlot.setAttribute("part","tool-card-subagent"),this.element.append(a,this.subagentSlot,this.#n,f,this.approvalSlot)}mark(t){this.#u||(this.element.setAttribute("data-status",t),this.#e.textContent=ld(this.#a)[t])}recordDecision(t){this.element.setAttribute("data-decision",t),this.#t.textContent=t==="approved"?this.#a.decisionApproved:this.#a.decisionDeclined,this.#t.hidden=!1}get settled(){return this.#u}settle(t,n){this.#u||(this.#u=!0,this.element.setAttribute("data-status",t),this.#e.textContent=ld(this.#a)[t],this.#r.textContent=KA(this.#a)[t],this.#d(this.#i,{kind:"result",toolName:this.#s,status:t,text:n},JA(n)),this.#o.hidden=!1)}#d(t,n,r){let o=this.#c===null?null:this.#c(n);if(o===null){t.textContent=r;return}if(t.setAttribute("data-formatted","true"),typeof o=="string"){t.textContent=o;return}t.replaceChildren(o)}#f(t,n){let r=document.createElement("div");r.className=`tool-call-section tool-call-section--${t}`,r.setAttribute("part",`tool-card-section tool-card-${t}-section`);let o=document.createElement("span");o.className="tool-call-section-label",o.setAttribute("part",`tool-card-section-label tool-card-${t}-label`),o.textContent=n;let i=document.createElement("pre");return i.className=`tool-call-${t}`,i.setAttribute("part",`tool-card-${t}`),r.append(o,i),{root:r,label:o,body:i}}#p(){return this.element.getAttribute("data-expanded")==="true"}#m(t){this.element.setAttribute("data-expanded",String(t)),this.#n.setAttribute("aria-expanded",String(t))}};var jb=`
|
|
70
|
+
${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)}offerInPage(e){this.#n?.detach();let n=ud({within:e,label:this.#e.strings().quoteSelection,exclude:this.#e.element,onQuote:r=>this.#e.quote(r)});return this.#n=n,()=>{n.detach(),this.#n===n&&(this.#n=null)}}detachPageOffer(){this.#n?.detach(),this.#n=null}mount(e){let n=this.button;n.className="quote-selection",n.type="button",n.setAttribute("part","quote-selection"),n.textContent=this.#e.strings().quoteSelection,n.hidden=!0,n.addEventListener("mousedown",o=>{o.preventDefault()},{signal:e}),n.addEventListener("click",()=>{this.#e.quote(this.#t),window.getSelection()?.removeAllRanges(),this.#a()},{signal:e});let r=this.#e.messages;r.addEventListener("mouseup",o=>this.#r(o),{signal:e}),r.addEventListener("keyup",()=>this.#r(),{signal:e}),r.addEventListener("mousedown",()=>this.#a(),{signal:e})}#o(){return this.#e.element.getAttribute("data-quote-selection")!=="false"}#r(e){if(!this.#o())return;let n=e===void 0?void 0:{x:e.clientX,y:e.clientY},r=oo(this.#e.messages,[this.#e.root],n);if(r===null){this.#a();return}this.#t=r.text,this.#i(r.rect)}#i(e){let n=this.button;n.hidden=!1;let r=this.#e.messagesWrap.getBoundingClientRect(),o=e.top-r.top,i=o<dd+n.offsetHeight;n.dataset.below=String(i),n.style.top=`${i?e.bottom-r.top+dd:o-dd}px`;let a=n.offsetWidth/2,s=e.left+e.width/2-r.left;n.style.left=`${Math.min(Math.max(s,a),r.width-a)}px`}#a(){this.button.hidden=!0,this.#t=""}};function io(t,e=Date.now(),n=fe){if(!Number.isFinite(t))return n.justNow;let r=Math.round((e-t)/1e3);if(r<60)return n.justNow;let o=Math.round(r/60);if(o<60)return re(n.minutesAgo,{n:o});let i=Math.round(o/60);if(i<24)return re(n.hoursAgo,{n:i});let a=Math.round(i/24);return a<7?re(n.daysAgo,{n:a}):re(n.weeksAgo,{n:Math.round(a/7)})}function Bb(t){return t.preview!==void 0&&t.preview!==null&&t.preview!==""?t.preview:null}function Zb(t){return t.replace(/\s+/g," ").trim()}var ao=class{element;#e;#t;#n;#o=null;#r=null;#i;#a=[];constructor(e,n=fe){this.#e=e,this.#i=n,this.element=document.createElement("div"),this.element.className="checkpoints",this.element.setAttribute("part","checkpoints"),this.element.setAttribute("role","dialog"),this.element.setAttribute("aria-label",n.checkpoints),this.element.tabIndex=-1,this.element.hidden=!0;let r=document.createElement("div");r.className="checkpoints-header",r.setAttribute("part","checkpoints-header"),this.#n=document.createElement("span"),this.#n.className="checkpoints-title",this.#n.setAttribute("part","checkpoints-title"),this.#n.textContent=n.checkpoints,r.append(this.#n),this.#t=document.createElement("div"),this.#t.className="checkpoints-list",this.#t.setAttribute("part","checkpoints-list"),this.element.append(r,this.#t),this.element.addEventListener("keydown",o=>this.#d(o))}setRuns(e){this.#a=e,this.#f()}setRelativeTimeFormatter(e){this.#r=e}#s(e){return this.#r!==null?this.#r(e):io(e,Date.now(),this.#i)}setStrings(e){this.#i=e,this.element.setAttribute("aria-label",e.checkpoints),this.#n.textContent=e.checkpoints,this.#f()}open(){this.open_||(this.#o=this.#l(),this.element.hidden=!1,(this.#u()[0]??this.element).focus())}close(){this.open_&&(this.element.hidden=!0,this.#o?.focus(),this.#o=null)}#l(){return this.element.getRootNode().activeElement}#u(){return Array.from(this.element.querySelectorAll("button, [tabindex]")).filter(e=>!e.hidden)}#d(e){if(e.key==="Escape"){e.stopPropagation(),this.close();return}if(e.key!=="Tab")return;let n=this.#u(),r=n[0],o=n[n.length-1],i=this.#l();e.shiftKey&&i===r?(e.preventDefault(),o?.focus()):!e.shiftKey&&i===o&&(e.preventDefault(),r?.focus())}get open_(){return!this.element.hidden}#f(){if(this.#t.replaceChildren(),this.#a.length===0){let n=document.createElement("div");n.className="checkpoints-empty",n.setAttribute("part","checkpoints-empty"),n.textContent=this.#i.noCheckpoints,this.#t.append(n);return}let e=this.#p();for(let n of this.#a)this.#t.append(this.#m(n,e))}#p(){let e=new Set,n=new Set;for(let r of this.#a){let o=Bb(r);if(o===null)continue;let i=Zb(o);e.has(i)&&n.add(i),e.add(i)}return n}#m(e,n){let r=document.createElement("div");r.className="checkpoint-row",r.setAttribute("part","checkpoint-row");let o=Bb(e),i=e.started_at===null?null:this.#s(Date.parse(e.started_at)),a=document.createElement("span");if(a.className="checkpoint-label",a.setAttribute("part","checkpoint-label"),a.textContent=o??i??e.run_id,r.append(a),o!==null&&i!==null){let c=document.createElement("span");c.className="checkpoint-time",c.setAttribute("part","checkpoint-time"),c.textContent=i,r.append(c)}if((o===null?i!==null:n.has(Zb(o)))&&e.run_id!==""){let c=document.createElement("span");c.className="checkpoint-id",c.setAttribute("part","checkpoint-id"),c.textContent=e.run_id.slice(0,8),c.title=e.run_id,r.append(c)}if(e.parent_run_id!==null){let c=document.createElement("span");c.className="checkpoint-branch",c.setAttribute("part","checkpoint-branch"),c.textContent=this.#i.forkedRun,c.title=e.parent_run_id,r.append(c)}return r.append(this.#c(e.run_id,"resume",this.#i.resumeRun),this.#c(e.run_id,"fork",this.#i.forkRun)),r}#c(e,n,r){let o=document.createElement("button");return o.type="button",o.className=`checkpoint-action checkpoint-${n}`,o.setAttribute("part",`checkpoint-action checkpoint-${n}`),o.textContent=r,o.addEventListener("click",()=>{this.close(),this.#e(e,n)}),o}};function pd(t){let e=rs(t,"attachments");return Array.isArray(e)?e.filter(WA):[]}function WA(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.id=="string"&&typeof e.name=="string"&&typeof e.mime=="string"&&typeof e.size=="number"&&(e.url===void 0||typeof e.url=="string")}var so=class{#e;#t;#n;constructor(e,n=()=>({}),r=()=>{}){this.#e=e.endsWith("/")?e:`${e}/`,this.#t=n,this.#n=r}async list(){try{let e=await fetch(this.#e,it({method:"GET",headers:{Accept:"application/json",...this.#t()}},this.#n()));return e.ok?(await e.json()).runs??[]:[]}catch{return[]}}async continuable(){return(await this.list()).filter(e=>e.continuable)}resumeUrl(e){return this.#o("resume",e)}forkUrl(e){return this.#o("fork",e)}#o(e,n){return`${this.#e.slice(0,-5)}${e}/${encodeURIComponent(n)}/`}};function lo(t){return t===je.FAILED?K.ERROR:t===je.DENIED?K.DECLINED:t===je.INTERRUPTED?K.INTERRUPTED:K.DONE}var bs=class{#e;#t="";#n=[];#o=0;#r=0;#i=null;#a=null;#s=null;#l=null;constructor(e){this.#e=e}get threadId(){return this.#t}get restored(){return this.#n}get continuation(){return this.#s}adoptActiveThread(){this.#t=this.#e.conversationStore().threadId()}startThread(){this.#t=es(this.#e.conversationStore())}stopContinuation(){this.#s?.cancel(),this.#s=null}forgetRestored(){this.#n=[],this.#o+=1,this.#r+=1,this.#u()}#u(){let e=this.#l;this.#l=null,e?.()}reapUnsent(){this.#e.conversationStore().isUnsent?.(this.#t)===!0&&this.#e.conversationStore().clear(this.#t)}runs(){let e=this.#e.element.getAttribute("data-runs-url");return e===null||e===""?null:(this.#a===null&&(this.#a=new so(e,()=>this.#e.headersFor(e),()=>this.#e.requestCredentials())),this.#a)}openThreads(){this.#e.checkpoints.close(),this.refreshDrawer(),this.#e.drawer.open()}openCheckpoints(){this.#e.drawer.close(),this.#d(),this.#e.checkpoints.open()}async switchThread(e){e!==this.#t&&(this.#e.cancelRun(),this.#e.resetState(),this.#e.conversationStore().setActiveThread(e),this.#t=e,this.#e.setRunning(!1),await this.rehydrate("switch"))}renameThread(e,n){this.#e.conversationStore().renameThread(e,n),this.refreshDrawer()}deleteThread(e){let n=e===this.#t;n&&this.#e.cancelRun(),this.#e.conversationStore().clear(e),n&&(this.#e.resetState(),this.adoptActiveThread(),this.#e.setRunning(!1),this.#e.threadChanged(this.#t,"delete")),this.refreshDrawer()}async refreshDrawer(){this.#e.drawer.setRelativeTimeFormatter(this.#e.formatRelativeTime()),this.#e.drawer.setThreads(await this.#e.conversationStore().listThreads(),this.#t)}async#d(){let e=this.runs();this.#e.checkpoints.setRelativeTimeFormatter(this.#e.formatRelativeTime()),this.#e.checkpoints.setRuns(e===null?[]:await e.continuable())}async continueRun(e,n){let r=this.runs();if(r===null)return;if(this.#e.running()||this.#s!==null){let s=this.#e.strings();this.#f(this.#l===null?s.continueWhileRunning:s.continueWhileLoading);return}let o=this.#e.input.value.trim();if(o===""){this.#f(this.#e.strings().continueNeedsTurn);return}this.#e.recordTurn(o),this.#e.input.value="",this.#e.autoGrow();let i=this.#o,a=this.#e.buildClient({endpoint:n==="resume"?r.resumeUrl(e):r.forkUrl(e),initialMessages:[],follows:this.#e.client()?.messages??this.#n,onSaved:s=>{i===this.#o&&(this.#n=s,this.#e.releaseClient())}});this.#s=a;try{if(this.#e.announceTurn(o),this.#s!==a)return;await a.send(o)}finally{this.#s===a&&(this.#s=null,this.#e.continuationEnded())}}#f(e){this.#e.hint.textContent=e,this.#e.hint.hidden=!1,this.#e.input.focus()}async rehydrate(e){this.#r+=1;let n=this.#r,r=this.#t,o=this.#e.conversationStore();this.#i={generation:n,store:o,threadId:r};let i=o.loadCheckpoint(r),a=i===null?new Promise(l=>{this.#l=l}):null,s=this.#l,c=this.#e.holdRun(a);try{this.#e.element.setAttribute("data-restoring","");let l;try{l=await o.loadMessages(r)}finally{n===this.#r&&this.#e.element.removeAttribute("data-restoring")}if(!this.#p(n)){this.#m(o,r,i);return}if(l!==null){let u=this.#e.strings().callNotFinished,f=ns(l,m=>({id:Se(),role:"tool",content:u,toolCallId:m,metadata:{outcome:je.INTERRUPTED}}),new Set(i===null?[]:[i.toolCallId]));this.#n=f;for(let m of f)if(this.replay(m),!this.#p(n)){this.#m(o,r,i);return}}if(i===null&&this.#b(l),this.#e.threadChanged(r,e),i!==null){if(!this.#p(n)){this.#m(o,r,i);return}await this.#y(i,n)}}finally{c.release(),this.#l===s&&this.#u()}}#p(e){return e===this.#r&&this.#e.element.isConnected}#m(e,n,r){r!==null&&!this.#c(e,n)&&e.saveCheckpoint(n,null)}#c(e,n){let r=this.#i;return r?.generation===this.#r&&r.store===e&&r.threadId===n}#b(e){let n=e?.at(-1);n===void 0||n.role!==Ve.USER||this.#e.transcript.appendNotice("\u26A0",this.#e.strings().runInterrupted,"interrupted")}replay(e){let n=typeof e.content=="string"?e.content:"";if(e.role===Ve.USER){let r=pd(e);if(n!==""||r.length>0){let o=this.#e.appendMessage(Ve.USER,n);r.length>0&&o.appendChild(us(r))}return}if(e.role===Ve.ASSISTANT){if(n!==""){let r=this.#e.appendMessage(Ve.ASSISTANT,n);r.classList.add("message--restored");let o=e.id;this.#e.actions.attach(r,typeof o=="string"&&o!==""?{messageId:o}:{rateable:!1})}for(let r of qA(e.toolCalls)){let o={id:r.id,name:r.function.name,args:this.#g(r.function.arguments)};if(this.#e.transcript.noticeIfSkillLoad(o))continue;this.#e.transcript.setCardElement(o.id,this.#e.transcript.cardFor(o).element);let i=this.#e.tools.resolve(o.name)?.render;i!==void 0&&this.#e.transcript.renderToolOutput(i,o)}return}if(e.role==="activity"){let r=e;typeof r.activityType=="string"&&this.#e.activities.draw(e.id,r.activityType,r.content);return}if(e.role==="tool"){let r=this.#e.transcript.card(e.toolCallId);r!==void 0&&r.settle(lo(rs(e,"outcome")),jn(e.content))}}#g(e){if(typeof e!="string")return{};try{let n=JSON.parse(e);if(typeof n=="object"&&n!==null)return n}catch{}return{}}async#y(e,n){this.#e.conversationStore().saveCheckpoint(this.#t,null);let r=this.#e.ensureClient(),o=JSON.stringify(this.#e.navigationResult().call(this.#e.element,e));this.#p(n)&&(r.addToolResult(e.toolCallId,o),this.#e.transcript.card(e.toolCallId)?.settle(K.DONE,o),await r.resume())}};function qA(t){return Array.isArray(t)?t.filter(YA):[]}function YA(t){if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.id=="string"&&typeof e.function?.name=="string"}var KA=8,ys=class{element;#e;#t;#n;#o;#r;#i=null;#a;#s=[];#l="";#u;#d;#f="";#p=null;constructor(e,n=fe){this.#e=e,this.#a=n,this.element=document.createElement("div"),this.element.className="drawer",this.element.setAttribute("part","drawer"),this.element.hidden=!0;let r=document.createElement("div");r.className="drawer-backdrop",r.setAttribute("part","drawer-backdrop"),r.addEventListener("click",()=>this.close()),this.#t=document.createElement("div"),this.#t.className="drawer-panel",this.#t.setAttribute("part","drawer-panel"),this.#t.setAttribute("role","dialog"),this.#t.setAttribute("aria-modal","true"),this.#t.setAttribute("aria-label",n.chatHistory),this.#t.addEventListener("keydown",i=>this.#b(i));let o=document.createElement("div");o.className="drawer-header",o.setAttribute("part","drawer-header"),this.#n=document.createElement("span"),this.#n.className="drawer-title",this.#n.setAttribute("part","drawer-title"),this.#n.textContent=n.chats,this.#o=document.createElement("button"),this.#o.type="button",this.#o.className="drawer-new",this.#o.setAttribute("part","drawer-new"),this.#o.textContent=n.newChat,this.#o.addEventListener("click",()=>{this.close(),this.#e.onNew()}),this.#u=document.createElement("button"),this.#u.type="button",this.#u.className="drawer-close",this.#u.setAttribute("part","drawer-close"),this.#u.title=n.closeHistory,this.#u.setAttribute("aria-label",n.closeHistory),this.#u.append(document.createTextNode("\xD7")),this.#u.addEventListener("click",()=>this.close()),o.append(this.#n,this.#o,this.#u),this.#d=document.createElement("input"),this.#d.type="search",this.#d.className="drawer-filter",this.#d.setAttribute("part","drawer-filter"),this.#d.placeholder=n.searchConversations,this.#d.setAttribute("aria-label",n.searchConversations),this.#d.addEventListener("input",()=>{this.#f=this.#d.value.trim().toLowerCase(),this.#g()}),this.#r=document.createElement("div"),this.#r.className="drawer-list",this.#r.setAttribute("part","drawer-list"),this.#t.append(o,this.#d,this.#r),this.element.append(r,this.#t)}setRelativeTimeFormatter(e){this.#i=e}#m(e){return this.#i!==null?this.#i(e):io(e,void 0,this.#a)}setStrings(e){this.#a=e,this.#t.setAttribute("aria-label",e.chatHistory),this.#n.textContent=e.chats,this.#o.textContent=e.newChat,this.#u.title=e.closeHistory,this.#u.setAttribute("aria-label",e.closeHistory),this.#d.placeholder=e.searchConversations,this.#d.setAttribute("aria-label",e.searchConversations),this.#g()}isOpen(){return!this.element.hidden}open(){this.isOpen()||(this.#p=this.#c(),this.element.hidden=!1,this.#o.focus())}close(){this.isOpen()&&(this.element.hidden=!0,this.#p?.focus(),this.#p=null)}toggle(){this.isOpen()?this.close():this.open()}#c(){return this.element.getRootNode().activeElement}#b(e){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let n=Array.from(this.#t.querySelectorAll("button, input, [tabindex]")).filter(a=>!a.hidden),r=n[0],o=n[n.length-1],i=this.#c();e.shiftKey&&i===r?(e.preventDefault(),o?.focus()):!e.shiftKey&&i===o&&(e.preventDefault(),r?.focus())}setThreads(e,n){this.#s=e,this.#l=n,this.#g()}#g(){this.#r.replaceChildren();let e=this.#s.length<KA;this.#d.hidden=e,e&&this.#f!==""&&(this.#d.value="",this.#f="");let n=this.#y();if(n.length===0){let r=document.createElement("div");r.className="drawer-empty",r.setAttribute("part","drawer-empty"),r.textContent=this.#s.length===0?this.#a.noConversations:this.#a.noMatches,this.#r.appendChild(r);return}for(let r of n)this.#r.appendChild(this.#E(r))}#y(){return this.#f===""?this.#s:this.#s.filter(e=>e.title.toLowerCase().includes(this.#f)||e.preview.toLowerCase().includes(this.#f))}#E(e){let n=document.createElement("div");n.className="drawer-row",n.setAttribute("part","drawer-row"),e.threadId===this.#l&&n.classList.add("drawer-row--active");let r=document.createElement("button");r.type="button",r.className="drawer-row-select",r.setAttribute("part","drawer-row-select");let o=document.createElement("span");o.className="drawer-row-title",o.setAttribute("part","drawer-row-title"),o.textContent=e.title;let i=document.createElement("span");i.className="drawer-row-time",i.setAttribute("part","drawer-row-time"),i.textContent=this.#m(e.updatedAt);let a=document.createElement("span");a.className="drawer-row-preview",a.setAttribute("part","drawer-row-preview"),a.textContent=e.preview,r.append(o,i,a),r.addEventListener("click",()=>{this.close(),this.#e.onSelect(e.threadId)});let s=document.createElement("button");s.type="button",s.className="drawer-row-rename",s.setAttribute("part","drawer-row-rename"),s.title=this.#a.rename,s.setAttribute("aria-label",this.#a.renameConversation),s.textContent="\u270E",s.addEventListener("click",()=>this.#_(n,e));let c=document.createElement("button");c.type="button",c.className="drawer-row-delete",c.setAttribute("part","drawer-row-delete"),c.title=this.#a.delete,c.setAttribute("aria-label",this.#a.deleteConversation),c.textContent="\u{1F5D1}",c.addEventListener("click",()=>this.#h(n,e));let l=document.createElement("div");return l.className="drawer-row-actions",l.setAttribute("part","drawer-row-actions"),l.append(s,c),n.append(r,l),n}#_(e,n){let r=document.createElement("input");r.type="text",r.className="drawer-rename-input",r.setAttribute("part","drawer-rename-input"),r.value=n.title;let o=!1,i=()=>{if(o)return;o=!0;let s=r.value.trim();s===""||s===n.title?this.#g():this.#e.onRename(n.threadId,s)},a=()=>{o||(o=!0,this.#g())};r.addEventListener("keydown",s=>{s.key==="Enter"?(s.preventDefault(),i()):s.key==="Escape"&&(s.preventDefault(),s.stopPropagation(),a())}),r.addEventListener("blur",()=>i()),e.replaceChildren(r),r.focus(),r.select()}#h(e,n){let r=document.createElement("div");r.className="drawer-confirm",r.setAttribute("part","drawer-confirm");let o=document.createElement("span");o.className="drawer-confirm-label",o.setAttribute("part","drawer-confirm-label"),o.textContent=this.#a.deletePrompt;let i=document.createElement("button");i.type="button",i.className="drawer-confirm-yes",i.setAttribute("part","drawer-confirm-yes"),i.textContent=this.#a.delete,i.addEventListener("click",()=>this.#e.onDelete(n.threadId));let a=document.createElement("button");a.type="button",a.className="drawer-confirm-no",a.setAttribute("part","drawer-confirm-no"),a.textContent=this.#a.cancel,a.addEventListener("click",()=>this.#g()),r.append(o,i,a),e.replaceChildren(r)}};var ws=class{#e=null;open(){return this.#e=new AbortController,this.#e.signal}close(){this.#e=null}abort(){this.#e?.abort()}};function Kt(t,e,n=lt){let r=Math.min(n,Math.max(0,(e.width-t.width)/2)),o=Math.min(n,Math.max(0,(e.height-t.height)/2));return{left:Math.max(e.left+r,Math.min(t.left,e.left+e.width-t.width-r)),top:Math.max(e.top+o,Math.min(t.top,e.top+e.height-t.height-o))}}function co(t,e,n=on){let r=t.right-t.left,o=t.bottom-t.top,i=Math.max(e.left+n,Math.min(t.left,e.left+e.width-n-r)),a=Math.max(e.top+n,Math.min(t.top,e.top+e.height-n-o));return{left:i,top:a,right:i+r,bottom:a+o}}var XA=4,JA=16,QA=64;function Vb(t,e){let n=!1,{signal:r}=e;t.addEventListener("click",a=>{!n||a.detail===0||(n=!1,a.stopPropagation(),a.preventDefault())},{capture:!0,signal:r}),t.addEventListener("pointerdown",a=>{if(n=!1,!e.enabled())return;let s=e.rect(),c=a.clientX,l=a.clientY,u=!1,f=p=>{let h=p.clientX-c,x=p.clientY-l;if(!u&&Math.hypot(h,x)<XA)return;u=!0,t.setAttribute("data-dragging","true");let g=Kt({...s,left:s.left+h,top:s.top+x},e.viewport());e.apply(g.left,g.top)},m=p=>{if(window.removeEventListener("pointermove",f),window.removeEventListener("pointerup",m),window.removeEventListener("pointercancel",m),!u)return;t.removeAttribute("data-dragging"),n=!0;let h=Kt({...s,left:s.left+(p.clientX-c),top:s.top+(p.clientY-l)},e.viewport());e.commit(h.left,h.top)};window.addEventListener("pointermove",f),window.addEventListener("pointerup",m),window.addEventListener("pointercancel",m)},{signal:r});let o=null,i=()=>{if(o===null)return;let{left:a,top:s}=o;o=null,e.commit(a,s)};t.addEventListener("keydown",a=>{if(!e.enabled())return;let s=a.shiftKey?QA:JA,c=e.rect(),l=null;if(a.key==="ArrowLeft"?l={left:c.left-s,top:c.top}:a.key==="ArrowRight"?l={left:c.left+s,top:c.top}:a.key==="ArrowUp"?l={left:c.left,top:c.top-s}:a.key==="ArrowDown"&&(l={left:c.left,top:c.top+s}),l===null)return;a.preventDefault();let u=Kt({...c,...l},e.viewport());e.apply(u.left,u.top),o=u},{signal:r}),t.addEventListener("keyup",i,{signal:r}),t.addEventListener("blur",i,{signal:r})}function uo(t,e,n,r){return{hostInset:jb({top:n.y==="top"?t.top:null,right:n.x==="right"?r.width-t.right:null,bottom:n.y==="bottom"?r.height-t.bottom:null,left:n.x==="left"?t.left:null}),launcherInset:jb({top:n.y==="top"?e.top-t.top:null,right:n.x==="right"?t.right-(e.left+e.width):null,bottom:n.y==="bottom"?t.bottom-(e.top+e.height):null,left:n.x==="left"?e.left-t.left:null})}}function jb(t){let e=n=>n===null?"auto":`${Math.round(n)}px`;return`${e(t.top)} ${e(t.right)} ${e(t.bottom)} ${e(t.left)}`}function hd(t,e,n,r,o=lt){let i=n.left+n.width-t.left,a=t.left+t.width-n.left,s=n.top+n.height-t.top,c=t.top+t.height-n.top,l={x:i>=a?"left":"right",y:s>=c?"top":"bottom"},u=l.x==="left"?t.left:t.left+t.width-e.width,f=l.y==="top"?t.top:t.top+t.height-e.height,m=co({left:u,top:f,right:u+e.width,bottom:f+e.height},n,o);return{corner:l,...uo(m,t,l,r)}}var ek="button, a[href], input, select, textarea, [contenteditable]";function Wb(t,e){t.addEventListener("pointerdown",n=>{if(n.button!==0||!e.enabled()||tk(n,t))return;let r=e.rect(),o=n.clientX,i=n.clientY,a=!1,s=(u,f)=>{let m=u-o,p=f-i;return{left:r.left+m,top:r.top+p,right:r.right+m,bottom:r.bottom+p}},c=u=>{!a&&Math.hypot(u.clientX-o,u.clientY-i)<4||(a=!0,t.setAttribute("data-dragging","true"),e.apply(s(u.clientX,u.clientY),r))},l=u=>{window.removeEventListener("pointermove",c),window.removeEventListener("pointerup",l),window.removeEventListener("pointercancel",l),a&&(t.removeAttribute("data-dragging"),e.commit(s(u.clientX,u.clientY),r))};n.preventDefault(),window.addEventListener("pointermove",c),window.addEventListener("pointerup",l),window.addEventListener("pointercancel",l)})}function tk(t,e){let n=t.composedPath();return n.slice(0,n.indexOf(e)).some(r=>r instanceof Element&&r.matches(ek))}function Yb(t,e){let n=document.createElement("div");n.className=`resize-handle resize-handle--${Es(t)}`,n.setAttribute("part",`resize-handle resize-handle-${Es(t)}`),n.setAttribute("role","separator"),t.x===void 0?n.setAttribute("aria-orientation","horizontal"):t.y===void 0&&n.setAttribute("aria-orientation","vertical"),n.setAttribute("aria-label",e.label),n.tabIndex=0,n.addEventListener("pointerdown",i=>{let a=e.axis();if(a==="none"||!qb(t,a))return;let s=e.rect(),c=u=>{e.apply(fd(t,a,s,u.clientX,u.clientY))},l=u=>{window.removeEventListener("pointermove",c),window.removeEventListener("pointerup",l),n.removeAttribute("data-dragging"),e.commit(fd(t,a,s,u.clientX,u.clientY))};n.setAttribute("data-dragging","true"),window.addEventListener("pointermove",c),window.addEventListener("pointerup",l),i.preventDefault()});let r=null,o=()=>{if(r===null)return;let i=r;r=null,e.commit(i)};return n.addEventListener("keydown",i=>{let a=e.axis();if(a==="none"||!qb(t,a))return;let s=i.shiftKey?64:16,c=e.rect(),l=nk[i.key];if(l===void 0||l.x!==0&&t.x===void 0||l.y!==0&&t.y===void 0)return;i.preventDefault();let u=(t.x==="left"?c.left:c.right)+l.x*s,f=(t.y==="top"?c.top:c.bottom)+l.y*s,m=fd(t,a,c,u,f);e.apply(m),r=m}),n.addEventListener("keyup",o),n.addEventListener("blur",o),n}var nk={ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0},ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1}};function Es(t){return[t.y,t.x].filter(e=>e!==void 0).join("-")}function qb(t,e){return e==="both"||t.x!==void 0}function fd(t,e,n,r,o){let i=t.x==="left"?Math.min(r,n.right-280):n.left,a=t.x==="right"?Math.max(r,n.left+280):n.right,s=e==="both",c=s&&t.y==="top"?Math.min(o,n.bottom-240):n.top,l=s&&t.y==="bottom"?Math.max(o,n.top+240):n.bottom;return{left:i,top:c,right:a,bottom:l}}var xs={collapseTo:"launcher",launcherDraggable:!0,resizeAxis:"both",startsCollapsed:!0},Kb={collapseTo:"launcher",launcherDraggable:!1,resizeAxis:"width",startsCollapsed:!1},rk=new Map([[null,xs],["",xs],["floating",xs],["bottom-left",xs],["side",Kb],["sidebar",{...Kb,collapseTo:"rail"}],["full",{collapseTo:"launcher",launcherDraggable:!1,resizeAxis:"none",startsCollapsed:!1}],["page",{collapseTo:null,launcherDraggable:!1,resizeAxis:"none",startsCollapsed:!1}],["embedded",{collapseTo:"header",launcherDraggable:!1,resizeAxis:"both",startsCollapsed:!1}]]),ok={collapseTo:"launcher",launcherDraggable:!1,resizeAxis:"both",startsCollapsed:!1};function Lt(t){return rk.get(t)??ok}var md="ag-ui-chat:size",po="--_drag-width",ho="--_drag-height",gd="ag-ui-chat:launcher";function ik(t){if(typeof t!="object"||t===null)return null;let{left:e,top:n}=t;return typeof e=="number"&&typeof n=="number"?{left:e,top:n}:null}function Xb(t,e){return t.width>=e.width-1&&t.height>=e.height-1}function Jb(t,e,n){let r=o=>`${Math.round(o)}px`;return[t.y==="top"?r(e.top):"auto",t.x==="right"?r(n.width-e.right):"auto",t.y==="bottom"?r(n.height-e.bottom):"auto",t.x==="left"?r(e.left):"auto"].join(" ")}var ak=[{y:"top"},{y:"bottom"},{x:"left"},{x:"right"},{x:"left",y:"top"},{x:"right",y:"top"},{x:"left",y:"bottom"},{x:"right",y:"bottom"}],_s=class{#e;constructor(e){this.#e=e}enablePanelDrag(e){Wb(e,{enabled:()=>!this.#e.collapsed()&&this.#m(),rect:()=>this.#e.element.getBoundingClientRect(),apply:(n,r)=>this.#h(n,r),commit:(n,r)=>this.#N(n,r)})}enableLauncherDrag(e){Vb(this.#e.launcher,{signal:e,enabled:()=>this.#e.collapsed()&&this.#m(),rect:()=>this.#g(),viewport:()=>this.#c(),apply:(n,r)=>this.#E(n,r),commit:(n,r)=>this.#_(n,r)})}mountResizeGrips(e){for(let n of ak){let r=Yb(n,{axis:()=>this.#l(),rect:()=>this.#e.element.getBoundingClientRect(),apply:o=>this.#I(n,o),commit:o=>this.#L(n,o),label:this.#e.strings().resizePanel});r.tabIndex=-1,r.setAttribute("aria-hidden","true"),this.#i.set(Es(n),r),e.appendChild(r)}this.#V()}restoreSize(){this.#p(this.#z())}resetSize(){this.#e.element.style.removeProperty(po),this.#e.element.style.removeProperty(ho),this.#e.clearPreference(md),this.syncResizeAnchor()}probe=document.createElement("div");#t=null;#n=null;#o=null;#r={x:"right",y:"bottom"};#i=new Map;#a(e){let n=this.#c(),r=n.left+lt,o=n.top+lt,i=n.left+n.width-lt,a=n.top+n.height-lt;return{left:Math.min(Math.max(e.left,r),e.right),top:Math.min(Math.max(e.top,o),e.bottom),right:Math.max(Math.min(e.right,i),e.left),bottom:Math.max(Math.min(e.bottom,a),e.top)}}dragging(){return this.#e.launcher.hasAttribute("data-dragging")||this.#e.root.querySelector(".header[data-dragging]")!==null}describeSurface(){let e=this.#e.element.getBoundingClientRect(),n=this.#c(),r=Xb(e,n);return{placement:this.#e.element.getAttribute("placement"),collapsed:this.#e.collapsed(),collapsible:this.#e.collapsible(),movable:this.#m()&&!r,draggable:this.#m(),fullBleed:r,box:{left:Math.round(e.left),top:Math.round(e.top),width:Math.round(e.width),height:Math.round(e.height)},viewport:{left:Math.round(n.left),top:Math.round(n.top),width:Math.round(n.width),height:Math.round(n.height)}}}moveTo(e,n={}){if(!this.#m())return!1;let r=n.announce===!0?this.#s():null,o=this.#c(),i=this.#e.element.getBoundingClientRect();if(Xb(i,o))return!1;let[a,s]=e.split("-"),c=o.left+on,l=o.top+on,u=s==="left"?c:Math.max(c,o.left+o.width-on-i.width),f=a==="top"?l:Math.max(l,o.top+o.height-on-i.height),m={left:u,top:f,right:u+i.width,bottom:f+i.height},p=this.#e.launcher.offsetWidth,h=this.#e.launcher.offsetHeight;return this.#M(m,{left:s==="left"?m.left:m.right-p,top:a==="top"?m.top:m.bottom-h,width:p,height:h}),this.#k(),r!==null&&this.#e.announceSurfaceChange(this.#e.strings().chatMoved,r),!0}#s(){let e=this.#e.element.style.getPropertyValue("--ag-ui-inset"),n=this.#e.element.style.getPropertyValue("--ag-ui-launcher-inset"),r=this.#e.element.getAttribute("data-expand-corner"),o=this.#t,i=this.#n,a=this.#o;return()=>{this.#f("--ag-ui-inset",e),this.#f("--ag-ui-launcher-inset",n),r===null?this.#e.element.removeAttribute("data-expand-corner"):this.#e.element.setAttribute("data-expand-corner",r),this.#t=o,this.#n=i,this.#o=a,o===null?this.#e.clearPreference(gd):this.#k(),this.syncResizeAnchor()}}#l(){return Lt(this.#e.element.getAttribute("placement")).resizeAxis}#u(){let e=this.#e.element.getBoundingClientRect(),n=this.#e.element.style.getPropertyValue(po),r=this.#e.element.style.getPropertyValue(ho),o=this.#d(e,-1),i=o.x===null||o.y===null?this.#d(e,1):o;return this.#f(po,n),this.#f(ho,r),{x:o.x??i.x??"right",y:o.y??i.y??"bottom"}}#d(e,n){this.#p({width:e.width+n,height:e.height+n});let r=this.#e.element.getBoundingClientRect(),o=(i,a)=>Math.abs(i-a)>=.5;return{x:o(r.width,e.width)?o(r.left,e.left)?"right":"left":null,y:o(r.height,e.height)?o(r.top,e.top)?"bottom":"top":null}}syncResizeAnchor(){if(!this.#e.connected())return;let e=this.#o??this.#u();this.#r=e,this.#e.element.setAttribute("data-resize-anchor",`${e.y}-${e.x}`),this.#V()}#f(e,n){if(n===""){this.#e.element.style.removeProperty(e);return}this.#e.element.style.setProperty(e,n)}#p(e){let n=this.#l();n!=="none"&&(e.width!==void 0&&this.#e.element.style.setProperty(po,`${e.width}px`),e.height!==void 0&&n==="both"&&this.#e.element.style.setProperty(ho,`${e.height}px`))}releaseOwnedAxes(){let e=this.#l();e!=="both"&&this.#e.element.style.removeProperty(ho),e==="none"&&this.#e.element.style.removeProperty(po)}#m(){return this.#e.element.getAttribute("data-launcher-drag")!=="false"&&Lt(this.#e.element.getAttribute("placement")).launcherDraggable}#c(){let e=window.visualViewport,n=e?.width??window.innerWidth,r=e?.height??window.innerHeight,o=getComputedStyle(this.probe),i=c=>{let l=Number.parseFloat(o.getPropertyValue(c));return Number.isFinite(l)?l:0},a=i("padding-left"),s=i("padding-top");return{left:a,top:s,width:Math.max(0,n-a-i("padding-right")),height:Math.max(0,r-s-i("padding-bottom"))}}#b(){let e=document.documentElement;return{width:e.clientWidth||window.innerWidth,height:e.clientHeight||window.innerHeight}}publishVisualViewport(){let e=window.visualViewport;if(e==null)return;let n=this.#b().height;if(Math.abs(e.height-n)<1){this.#e.element.style.removeProperty("--ag-ui-visual-viewport-height"),this.#e.element.style.removeProperty("--ag-ui-visual-viewport-inset-bottom"),this.#e.element.style.removeProperty("--ag-ui-visual-viewport-inset-top");return}this.#e.element.style.setProperty("--ag-ui-visual-viewport-height",`${Math.round(e.height)}px`);let r=n-e.height-e.offsetTop;this.#e.element.style.setProperty("--ag-ui-visual-viewport-inset-bottom",`${Math.max(0,Math.round(r))}px`),this.#e.element.style.setProperty("--ag-ui-visual-viewport-inset-top",`${Math.max(0,Math.round(e.offsetTop))}px`)}#g(){let e=this.#e.launcher.offsetWidth,n=this.#e.launcher.offsetHeight,r=this.#t;if(r!==null)return{left:r.left,top:r.top,width:e,height:n};let o=this.#e.launcher.getBoundingClientRect();return{left:o.left+o.width/2-e/2,top:o.top+o.height/2-n/2,width:e,height:n}}#y(e){if(!this.#m())return;this.#t=e,this.#n=null;let n=this.#e.element.getBoundingClientRect(),r=hd(this.#g(),{width:n.width,height:n.height},this.#c(),this.#b());this.#e.element.style.setProperty("--ag-ui-inset",r.hostInset),this.#e.element.style.setProperty("--ag-ui-launcher-inset",r.launcherInset),this.#o=r.corner,this.#e.element.setAttribute("data-expand-corner",`${r.corner.y}-${r.corner.x}`),this.syncResizeAnchor()}#E(e,n){this.#y({left:e,top:n})}#_(e,n){this.#E(e,n),this.#k()}#h(e,n){if(!this.#m())return{held:e,launcher:null};if(this.#t===null){let c=this.#g();this.#t={left:c.left,top:c.top}}let r=this.#t,o=co(e,this.#c(),lt),i=this.#o??this.#r;this.#e.element.style.setProperty("--ag-ui-inset",Jb(i,o,this.#b())),this.#n={left:o.left,top:o.top};let a={...this.#g(),left:r.left+(o.left-n.left),top:r.top+(o.top-n.top)},s={...a,...Kt(a,this.#c())};return this.#e.element.style.setProperty("--ag-ui-launcher-inset",uo(o,s,i,this.#b()).launcherInset),{held:o,launcher:s}}#N(e,n){let{held:r,launcher:o}=this.#h(e,n);o!==null&&(this.#M(r,o),this.#k())}#M(e,n){let r=this.#c(),o=this.#b(),i={width:e.right-e.left,height:e.bottom-e.top},{corner:a}=hd(n,i,r,o),s=uo(e,n,a,o);this.#e.element.style.setProperty("--ag-ui-inset",s.hostInset),this.#e.element.style.setProperty("--ag-ui-launcher-inset",s.launcherInset),this.#t={left:n.left,top:n.top},this.#n={left:e.left,top:e.top},this.#o=a,this.#e.element.setAttribute("data-expand-corner",`${a.y}-${a.x}`),this.syncResizeAnchor()}#B(e){if(!this.#m())return;let n=this.#e.element.getBoundingClientRect(),r=co({left:e.left,top:e.top,right:e.left+n.width,bottom:e.top+n.height},this.#c(),lt),o=this.#g(),i={...o,left:o.left+(r.left-e.left),top:o.top+(r.top-e.top)};this.#M(r,{...i,...Kt(i,this.#c())})}#k(){let e=this.#t;if(e===null)return;let n=this.#n;this.#e.writePreference(gd,JSON.stringify(n===null?e:{...e,panel:n}))}restoreLauncherPosition(){let e=this.#Z(),n=this.#t??e;if(n===null)return;let r=this.#n??e?.panel??null;if(r!==null){this.#t={left:n.left,top:n.top},this.#B(r);return}let o=this.#g();this.#y(Kt({...o,left:n.left,top:n.top},this.#c()))}#Z(){let e=this.#e.readPreference(gd);if(e===null)return null;try{let n=JSON.parse(e);if(typeof n!="object"||n===null)return null;let{left:r,top:o,panel:i}=n;if(typeof r!="number"||typeof o!="number")return null;let a=ik(i);return a===null?{left:r,top:o}:{left:r,top:o,panel:a}}catch{return null}}releaseLauncherPosition(){this.#m()||(this.#t=null,this.#n=null,this.#o=null,this.#e.element.style.removeProperty("--ag-ui-inset"),this.#e.element.style.removeProperty("--ag-ui-launcher-inset"),this.#e.element.removeAttribute("data-expand-corner"))}#I(e,n){if(n=this.#a(n),this.#p({width:n.right-n.left,height:n.bottom-n.top}),e.x!==this.#r.x&&e.y!==this.#r.y)return n;let r=this.#r;if(this.#e.element.style.setProperty("--ag-ui-inset",Jb(r,n,this.#b())),this.#t!==null){let o=this.#e.launcher.offsetWidth;this.#t={left:r.x==="left"?n.left:n.right-o,top:r.y==="top"?n.top:n.bottom-o}}return this.#n!==null&&(this.#n={left:n.left,top:n.top}),n}#L(e,n){let r=this.#I(e,n);this.#U({width:r.right-r.left,height:r.bottom-r.top}),this.#k(),this.syncResizeAnchor()}#V(){let e=`${this.#r.y==="top"?"bottom":"top"}-${this.#r.x==="left"?"right":"left"}`;for(let[n,r]of this.#i){let o=n===e;r.tabIndex=o?0:-1,o?r.removeAttribute("aria-hidden"):r.setAttribute("aria-hidden","true")}}#U(e){let n={...this.#z(),...e};this.#e.writePreference(md,JSON.stringify(n))}#z(){let e=this.#e.readPreference(md);if(e===null)return{};try{let n=JSON.parse(e);return typeof n=="object"&&n!==null?n:{}}catch{return{}}}};var Ss=class{region=document.createElement("div");#e=null;mount(){this.region.className="sr-only",this.region.setAttribute("role","status"),this.region.setAttribute("aria-live","polite"),this.region.setAttribute("aria-atomic","true")}announce(e){this.#e!==null&&clearTimeout(this.#e),this.region.textContent=e,this.#e=setTimeout(()=>{this.#e=null,this.region.textContent=""},Zp)}dispose(){this.#e!==null&&(clearTimeout(this.#e),this.#e=null)}};function Ts(t,e,n,r){let o=document.createElement("div");o.className=`run-notice run-notice--${n}`,o.setAttribute("part",`run-notice run-notice-${n}`),o.setAttribute("role","status");let i=document.createElement("span");i.className="run-notice-icon",i.setAttribute("part","run-notice-icon"),i.textContent=t,i.setAttribute("aria-hidden","true");let a=document.createElement("span");if(a.className="run-notice-text",a.setAttribute("part","run-notice-text"),a.textContent=e,o.append(i,a),r!==void 0){let s=document.createElement("button");s.type="button",s.className="run-notice-undo",s.setAttribute("part","run-notice-undo"),s.textContent=r.label,s.addEventListener("click",()=>{s.disabled=!0,r.onActivate()}),o.append(s)}return o}var As=class{element;get agent(){return this.#r}#e;#t;#n;#o=new Map;#r=null;constructor(e=fe){this.element=document.createElement("div"),this.element.className="subagent",this.element.setAttribute("part","subagent"),this.#e=document.createElement("button"),this.#e.type="button",this.#e.className="subagent-row",this.#e.setAttribute("part","subagent-row"),this.#e.setAttribute("aria-expanded","false"),this.#e.disabled=!0;let n=document.createElement("span");n.className="subagent-icon",n.setAttribute("part","subagent-icon"),n.setAttribute("aria-hidden","true"),this.#t=document.createElement("span"),this.#t.className="subagent-status",this.#t.setAttribute("part","subagent-status"),this.#t.textContent=e.subAgentWorking,this.#e.append(n,this.#t),this.#n=document.createElement("div"),this.#n.className="subagent-steps",this.#n.setAttribute("part","subagent-steps"),this.#n.setAttribute("role","list"),this.#n.setAttribute("aria-label",e.subAgentSteps),this.#n.hidden=!0,this.#e.addEventListener("click",()=>{this.#s(this.#e.getAttribute("aria-expanded")!=="true")}),this.element.append(this.#e,this.#n)}report(e){this.element.setAttribute("data-phase",e.phase),e.agent!==null&&(this.#r=e.agent,this.element.setAttribute("data-agent",e.agent)),e.status!==null&&(this.#t.textContent=e.status),e.tool!==null&&this.#i(e.tool)}#i(e){let n=this.#o.get(e.toolCallId)??this.#a(e);if(e.ok===null){n.removeAttribute("data-ok");return}n.setAttribute("data-ok",String(e.ok))}#a(e){let n=document.createElement("div");n.className="subagent-step",n.setAttribute("part","subagent-step"),n.setAttribute("role","listitem"),n.setAttribute("data-tool-call-id",e.toolCallId);let r=document.createElement("span");r.className="subagent-step-icon",r.setAttribute("part","subagent-step-icon"),r.setAttribute("aria-hidden","true");let o=document.createElement("span");return o.className="subagent-step-name",o.setAttribute("part","subagent-step-name"),o.textContent=e.name,n.append(r,o),this.#n.appendChild(n),this.#o.set(e.toolCallId,n),this.#e.disabled=!1,n}#s(e){this.#n.hidden=!e,this.#e.setAttribute("aria-expanded",String(e))}};var sk=Object.values(yt);function Qb(t){return typeof t!="object"||t===null||Array.isArray(t)?null:t}function fo(t){return typeof t=="string"&&t!==""?t:null}function lk(t){let e=Qb(t);if(e===null)return null;let n=fo(e.toolCallId),r=fo(e.name),o=e.ok;return n===null||r===null||o!==null&&typeof o!="boolean"?null:{toolCallId:n,name:r,ok:o}}function ey(t){let e=Qb(t);if(e===null)return null;let n=fo(e.delegationId),r=e.phase;return n===null||typeof r!="string"||!sk.includes(r)?null:{delegationId:n,phase:r,agent:fo(e.agent),status:fo(e.status),tool:lk(e.tool)}}var ks=class{#e;#t=new Map;#n=new Map;constructor(e){this.#e=e}report(e){let n=ey(e);n!==null&&this.#i(n)}start(e,n,r){r!==null&&(this.#n.set(e,r),this.#i({delegationId:r,agent:n===""?null:n,phase:yt.STARTED,status:re(this.#e.strings().subAgentDelegatedTo,{agent:n}),tool:null}))}finish(e){this.#o(e,yt.FINISHED,null)}fail(e,n){this.#o(e,yt.FAILED,n===""?this.#e.strings().subAgentFailed:n)}clear(){this.#t.clear(),this.#n.clear()}#o(e,n,r){let o=this.#n.get(e);if(o===void 0)return;let i=this.#t.get(o)?.agent??null;this.#i({delegationId:o,agent:i,phase:n,status:r===null?this.#r(i):r,tool:null})}#r(e){let n=this.#e.strings();return e===null?n.subAgentWorking:re(n.subAgentFinished,{agent:e})}#i(e){let n=this.#e.card(e.delegationId);if(n===void 0)return;let r=this.#t.get(e.delegationId);r===void 0&&(r=new As(this.#e.strings()),this.#t.set(e.delegationId,r),n.subagentSlot.appendChild(r.element)),r.report(e),this.#e.follow()}};function ck(t){return{[K.PENDING]:t.toolRunning,[K.DEFERRED]:t.toolDeferred,[K.DONE]:t.toolDone,[K.ERROR]:t.toolError,[K.DECLINED]:t.toolDeclined,[K.INTERRUPTED]:t.toolInterrupted}}function uk(t){return{[K.DONE]:t.resultLabel,[K.ERROR]:t.errorLabel,[K.DECLINED]:t.declinedLabel,[K.INTERRUPTED]:t.interruptedLabel}}function dk(t){try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}}var mo=class{element;approvalSlot;subagentSlot;#e;#t;#n;#o;#r;#i;#a;args;#s;#l;#u=!1;constructor(e,n,r,o=fe,i={}){this.#a=o,this.args=n,this.#s=e,this.#l=i.formatPayload??null,this.element=document.createElement("div"),this.element.className="tool-call",this.element.setAttribute("data-tool-name",e),this.element.setAttribute("data-expanded","false");let a=document.createElement("div");a.className="tool-call-head",a.setAttribute("part","tool-card-head");let s=document.createElement("span");s.className="tool-call-icon",s.setAttribute("part","tool-card-icon"),s.setAttribute("aria-hidden","true");let c=document.createElement("span");c.className="tool-call-name",c.setAttribute("part","tool-card-name"),c.textContent=r??e,this.#e=document.createElement("span"),this.#e.className="tool-call-status",this.#d(K.PENDING),this.#t=document.createElement("span"),this.#t.className="tool-call-decision",this.#t.setAttribute("part","tool-card-decision"),this.#t.hidden=!0,a.append(s,c,this.#e,this.#t);let l=this.#p("args",o.argumentsLabel);this.#f(l.body,{kind:"arguments",toolName:e,args:n},JSON.stringify(n,null,2)),l.root.hidden=Object.keys(n).length===0;let u=this.#p("result",o.resultLabel);this.#o=u.root,this.#r=u.label,this.#i=u.body,u.root.hidden=!0,this.#n=document.createElement("button"),this.#n.type="button",this.#n.className="tool-call-toggle",this.#n.setAttribute("part","tool-card-toggle"),this.#n.setAttribute("aria-expanded","false"),this.#n.textContent=o.details,this.#n.addEventListener("click",()=>this.#c(!this.#m()));let f=document.createElement("div");f.className="tool-call-body",f.setAttribute("part","tool-card-body"),f.append(l.root,u.root),this.approvalSlot=document.createElement("div"),this.approvalSlot.className="tool-call-approval",this.approvalSlot.setAttribute("part","tool-card-approval"),this.subagentSlot=document.createElement("div"),this.subagentSlot.className="tool-call-subagent",this.subagentSlot.setAttribute("part","tool-card-subagent"),this.element.append(a,this.subagentSlot,this.#n,f,this.approvalSlot)}mark(e){this.#u||this.#d(e)}setAsking(e){this.element.toggleAttribute("data-asking",e)}recordDecision(e){this.element.setAttribute("data-decision",e),this.#t.textContent=e==="approved"?this.#a.decisionApproved:this.#a.decisionDeclined,this.#t.hidden=!1}get settled(){return this.#u}settle(e,n){this.#u||(this.#u=!0,this.#d(e),this.#r.textContent=uk(this.#a)[e],this.#f(this.#i,{kind:"result",toolName:this.#s,status:e,text:n},dk(n)),this.#o.hidden=!1)}#d(e){this.element.setAttribute("data-status",e),this.element.setAttribute("part",`tool-card tool-card-${e}`),this.#e.setAttribute("part",`tool-card-status tool-card-status-${e}`),this.#e.textContent=ck(this.#a)[e]}#f(e,n,r){let o=this.#l===null?null:this.#l(n);if(o===null){e.textContent=r;return}if(e.setAttribute("data-formatted","true"),typeof o=="string"){e.textContent=o;return}e.replaceChildren(o)}#p(e,n){let r=document.createElement("div");r.className=`tool-call-section tool-call-section--${e}`,r.setAttribute("part",`tool-card-section tool-card-${e}-section`);let o=document.createElement("span");o.className="tool-call-section-label",o.setAttribute("part",`tool-card-section-label tool-card-${e}-label`),o.textContent=n;let i=document.createElement("pre");return i.className=`tool-call-${e}`,i.setAttribute("part",`tool-card-${e}`),r.append(o,i),{root:r,label:o,body:i}}#m(){return this.element.getAttribute("data-expanded")==="true"}#c(e){this.element.setAttribute("data-expanded",String(e)),this.#n.setAttribute("aria-expanded",String(e))}};var ty=`
|
|
71
71
|
/* Charts.
|
|
72
72
|
*
|
|
73
73
|
* The SVG scales to the column and carries no colours of its own beyond the
|
|
@@ -128,7 +128,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
128
128
|
border-radius: 2px;
|
|
129
129
|
flex: 0 0 auto;
|
|
130
130
|
}
|
|
131
|
-
`;var
|
|
131
|
+
`;var ny=`
|
|
132
132
|
/* \u2500\u2500 File attachments \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
133
133
|
/* The picker button sits in the composer's tool row; hidden until
|
|
134
134
|
data-attachments-url. */
|
|
@@ -197,7 +197,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
197
197
|
gap: 6px;
|
|
198
198
|
margin-top: 6px;
|
|
199
199
|
}
|
|
200
|
-
`;var
|
|
200
|
+
`;var ry=`
|
|
201
201
|
/* \u2500\u2500 Composer \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
202
202
|
One surface owns the border, the background and the focus ring; the field
|
|
203
203
|
and its tool row sit inside it, rather than being siblings stretched to the
|
|
@@ -368,7 +368,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
368
368
|
width: 100%;
|
|
369
369
|
height: 100%;
|
|
370
370
|
}
|
|
371
|
-
`;var
|
|
371
|
+
`;var oy=`
|
|
372
372
|
/* Skills \u2014 chips row + the /-command palette, above the input. */
|
|
373
373
|
.skill-chips {
|
|
374
374
|
display: flex;
|
|
@@ -486,7 +486,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
486
486
|
line-height: 1.4;
|
|
487
487
|
color: var(--_danger);
|
|
488
488
|
}
|
|
489
|
-
`;var
|
|
489
|
+
`;var iy=`
|
|
490
490
|
/* Chat-history drawer \u2014 a slide-over within the chat panel.
|
|
491
491
|
The hidden attribute stays the single source of truth for open/closed (no
|
|
492
492
|
JS-driven animation state): display is transitioned discretely, so on close
|
|
@@ -966,7 +966,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
966
966
|
border-right: none;
|
|
967
967
|
box-shadow: none;
|
|
968
968
|
}
|
|
969
|
-
`;var
|
|
969
|
+
`;var ay=`
|
|
970
970
|
/* Approval card \u2014 the server-side-tool gate (approve/deny an interrupt). */
|
|
971
971
|
.approval {
|
|
972
972
|
align-self: stretch;
|
|
@@ -1016,7 +1016,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1016
1016
|
background: var(--_accent);
|
|
1017
1017
|
color: var(--_on-accent);
|
|
1018
1018
|
}
|
|
1019
|
-
`;var
|
|
1019
|
+
`;var sy=`
|
|
1020
1020
|
/* Inline confirmation card \u2014 lives in the transcript, no focus-stealing overlay. */
|
|
1021
1021
|
.confirm {
|
|
1022
1022
|
align-self: stretch;
|
|
@@ -1044,8 +1044,6 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1044
1044
|
padding: 8px 10px;
|
|
1045
1045
|
max-height: 140px;
|
|
1046
1046
|
overflow: auto;
|
|
1047
|
-
/* Scrolling past the end of this must not scroll the page behind it. */
|
|
1048
|
-
overscroll-behavior: contain;
|
|
1049
1047
|
font-size: 12px;
|
|
1050
1048
|
font-family: ui-monospace, "SF Mono", Menlo, monospace;
|
|
1051
1049
|
background: var(--_assistant-bg);
|
|
@@ -1129,7 +1127,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1129
1127
|
}
|
|
1130
1128
|
|
|
1131
1129
|
/* Message action row. Sits under a finished assistant bubble.
|
|
1132
|
-
`;var
|
|
1130
|
+
`;var ly=`
|
|
1133
1131
|
/* Question card \u2014 the built-in ask_user prompt (radios and/or free text). */
|
|
1134
1132
|
.question {
|
|
1135
1133
|
align-self: stretch;
|
|
@@ -1200,7 +1198,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1200
1198
|
cursor: default;
|
|
1201
1199
|
opacity: 0.6;
|
|
1202
1200
|
}
|
|
1203
|
-
`;var
|
|
1201
|
+
`;var cy=`
|
|
1204
1202
|
/* \u2500\u2500 Collapse \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
1205
1203
|
Collapsing shrinks the widget to the round floating launcher: the panel
|
|
1206
1204
|
scales toward the launcher's corner and fades, the launcher pops in from the
|
|
@@ -1334,19 +1332,19 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1334
1332
|
transform: none;
|
|
1335
1333
|
visibility: visible;
|
|
1336
1334
|
}
|
|
1337
|
-
`;var
|
|
1335
|
+
`;var uy=`
|
|
1338
1336
|
/* Embedded: drop the floating chrome and the high z-index stacking context so
|
|
1339
1337
|
the widget lives in the host's own layout (fixes overlay/z-index clashes). */
|
|
1340
1338
|
:host([placement="embedded"]) {
|
|
1341
1339
|
--_position: var(--ag-ui-position, static);
|
|
1342
|
-
--_width: var(--ag-ui-width, 100%);
|
|
1343
|
-
--_height: var(--ag-ui-height, 100%);
|
|
1340
|
+
--_width: var(--_drag-width, var(--ag-ui-width, 100%));
|
|
1341
|
+
--_height: var(--_drag-height, var(--ag-ui-height, 100%));
|
|
1344
1342
|
--_max-width: var(--ag-ui-max-width, 100%);
|
|
1345
1343
|
--_max-height: var(--ag-ui-max-height, 100%);
|
|
1346
1344
|
--_shadow: var(--ag-ui-shadow, none);
|
|
1347
1345
|
--_z-index: var(--ag-ui-z-index, auto);
|
|
1348
1346
|
}
|
|
1349
|
-
`;var
|
|
1347
|
+
`;var dy=`
|
|
1350
1348
|
/* \u2500\u2500 Launcher \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
1351
1349
|
What a collapsed widget shrinks to: a round floating button by default, the
|
|
1352
1350
|
sidebar's slim edge rail under that placement. A sibling of the panel, so it
|
|
@@ -1532,7 +1530,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1532
1530
|
--_motion: var(--ag-ui-motion, 0.001s);
|
|
1533
1531
|
}
|
|
1534
1532
|
}
|
|
1535
|
-
`;var
|
|
1533
|
+
`;var py=`
|
|
1536
1534
|
/* Page: full-bleed background with a centred reading column capped at
|
|
1537
1535
|
--ag-ui-content-max-width, where "full" is edge-to-edge and left-aligned.
|
|
1538
1536
|
The column comes from symmetric auto padding on the scroll area and
|
|
@@ -1577,7 +1575,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1577
1575
|
:host([placement="page"]) .message--assistant {
|
|
1578
1576
|
max-width: 100%;
|
|
1579
1577
|
}
|
|
1580
|
-
`;var
|
|
1578
|
+
`;var hy=`
|
|
1581
1579
|
/* \u2500\u2500 Placement presets \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
1582
1580
|
:host([placement="bottom-left"]) {
|
|
1583
1581
|
--_inset: var(
|
|
@@ -1589,7 +1587,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1589
1587
|
|
|
1590
1588
|
:host([placement="side"]) {
|
|
1591
1589
|
--_inset: var(--ag-ui-inset, calc(var(--_viewport-inset-top) + var(--_keyboard-inset-top)) var(--_viewport-inset-right) var(--_viewport-inset-bottom) auto);
|
|
1592
|
-
--_width: var(--ag-ui-width, 420px);
|
|
1590
|
+
--_width: var(--_drag-width, var(--ag-ui-width, 420px));
|
|
1593
1591
|
--_height: var(--ag-ui-height, var(--_viewport-height));
|
|
1594
1592
|
--_max-height: var(--ag-ui-max-height, var(--_viewport-height));
|
|
1595
1593
|
--_panel-radius: var(--ag-ui-panel-radius, 0);
|
|
@@ -1607,7 +1605,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1607
1605
|
--_max-height: var(--ag-ui-max-height, var(--_viewport-height));
|
|
1608
1606
|
--_panel-radius: var(--ag-ui-panel-radius, 0);
|
|
1609
1607
|
}
|
|
1610
|
-
`;var
|
|
1608
|
+
`;var fy=`
|
|
1611
1609
|
/* Resize grips: every edge and every corner, so the panel can be dragged from
|
|
1612
1610
|
whichever side the reader is already near. Absent entirely where the
|
|
1613
1611
|
placement is full-bleed, since there is nothing to drag.
|
|
@@ -1791,7 +1789,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1791
1789
|
.resize-handle[data-dragging]::after {
|
|
1792
1790
|
opacity: 0.9;
|
|
1793
1791
|
}
|
|
1794
|
-
`;var
|
|
1792
|
+
`;var my=`
|
|
1795
1793
|
/* Sidebar: a full-height docked panel that slides open/closed and
|
|
1796
1794
|
collapses to a slim icon rail (not the floating launcher). Docked right by
|
|
1797
1795
|
default; data-side="left" docks it left. Overlay by default \u2014 set
|
|
@@ -1799,7 +1797,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1799
1797
|
host-managed push instead. */
|
|
1800
1798
|
:host([placement="sidebar"]) {
|
|
1801
1799
|
--_inset: var(--ag-ui-inset, calc(var(--_viewport-inset-top) + var(--_keyboard-inset-top)) var(--_viewport-inset-right) var(--_viewport-inset-bottom) auto);
|
|
1802
|
-
--_width: var(--ag-ui-width, 420px);
|
|
1800
|
+
--_width: var(--_drag-width, var(--ag-ui-width, 420px));
|
|
1803
1801
|
--_height: var(--ag-ui-height, var(--_viewport-height));
|
|
1804
1802
|
--_max-height: var(--ag-ui-max-height, var(--_viewport-height));
|
|
1805
1803
|
--_panel-radius: var(--ag-ui-panel-radius, 0);
|
|
@@ -1877,7 +1875,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1877
1875
|
transition: none;
|
|
1878
1876
|
}
|
|
1879
1877
|
}
|
|
1880
|
-
`;var
|
|
1878
|
+
`;var gy=`
|
|
1881
1879
|
/* Small viewports: one shape, reached from whichever placement the host chose.
|
|
1882
1880
|
|
|
1883
1881
|
A phone is not an eighth placement, it is an override that collapses the
|
|
@@ -1895,6 +1893,11 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1895
1893
|
fine-pointered and small, and conflating the two gets both wrong. What the
|
|
1896
1894
|
pointer decides is which controls make sense, further down.
|
|
1897
1895
|
|
|
1896
|
+
The size the user dragged is deliberately not read here. The desktop
|
|
1897
|
+
placements read it before the host token, and this block restates the sizes
|
|
1898
|
+
without it, so a persisted or freshly dragged size cannot change the shape
|
|
1899
|
+
of a phone, and a window narrowed after a drag goes full-bleed.
|
|
1900
|
+
|
|
1898
1901
|
Two placements are left alone. "page" is already this shape. "embedded" sits
|
|
1899
1902
|
in a box the host sized and placed, and taking that over would break the app
|
|
1900
1903
|
shell it was embedded into -- the host is the only party that knows whether
|
|
@@ -1931,7 +1934,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1931
1934
|
display: none;
|
|
1932
1935
|
}
|
|
1933
1936
|
}
|
|
1934
|
-
`;var
|
|
1937
|
+
`;var vy=`
|
|
1935
1938
|
.run-notice {
|
|
1936
1939
|
display: inline-flex;
|
|
1937
1940
|
align-items: center;
|
|
@@ -1981,7 +1984,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
1981
1984
|
min-width: 0;
|
|
1982
1985
|
overflow-wrap: anywhere;
|
|
1983
1986
|
}
|
|
1984
|
-
`;var
|
|
1987
|
+
`;var by=`
|
|
1985
1988
|
/* \u2500\u2500 Thoughts region \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
1986
1989
|
A muted, collapsible chain-of-thought at the top of the answer group: open
|
|
1987
1990
|
while the model reasons, folded once the answer text starts. */
|
|
@@ -2030,8 +2033,6 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
2030
2033
|
border-left: 2px solid var(--_border);
|
|
2031
2034
|
max-height: 220px;
|
|
2032
2035
|
overflow: auto;
|
|
2033
|
-
/* Scrolling past the end of this must not scroll the page behind it. */
|
|
2034
|
-
overscroll-behavior: contain;
|
|
2035
2036
|
white-space: pre-wrap;
|
|
2036
2037
|
word-break: break-word;
|
|
2037
2038
|
font-family: inherit;
|
|
@@ -2046,7 +2047,215 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
2046
2047
|
animation: none;
|
|
2047
2048
|
}
|
|
2048
2049
|
}
|
|
2049
|
-
`;var
|
|
2050
|
+
`;var yy=['[data-tool-display="inline"]','[data-tool-display="minimal"]','[data-tool-display="compact"]','[data-tool-display="full"]'].join(", "),me=`:host(:where(:not(${yy})))`,Is=`:host(:is(${yy}))`,wy=`
|
|
2051
|
+
/* \u2500\u2500 The folded tool-step group \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
2052
|
+
One quiet row per run of consecutive calls, the cards one click down as
|
|
2053
|
+
plain lines rather than boxes. Every rule is scoped to grouped mode, so
|
|
2054
|
+
none of it reaches a group drawn earlier once the host moves to a card
|
|
2055
|
+
mode. */
|
|
2056
|
+
${me} .tool-group {
|
|
2057
|
+
align-self: stretch;
|
|
2058
|
+
display: flex;
|
|
2059
|
+
flex-direction: column;
|
|
2060
|
+
min-width: 0;
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
${me} .tool-group-head {
|
|
2064
|
+
appearance: none;
|
|
2065
|
+
align-self: flex-start;
|
|
2066
|
+
max-width: 100%;
|
|
2067
|
+
display: inline-flex;
|
|
2068
|
+
align-items: center;
|
|
2069
|
+
gap: 8px;
|
|
2070
|
+
margin: 0 0 0 -6px;
|
|
2071
|
+
padding: 4px 6px;
|
|
2072
|
+
border: 0;
|
|
2073
|
+
border-radius: 6px;
|
|
2074
|
+
background: transparent;
|
|
2075
|
+
color: var(--_muted);
|
|
2076
|
+
font: inherit;
|
|
2077
|
+
font-size: var(--_text-sm);
|
|
2078
|
+
line-height: 1.3;
|
|
2079
|
+
text-align: left;
|
|
2080
|
+
cursor: pointer;
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
${me} .tool-group-head:hover {
|
|
2084
|
+
background: var(--_hover);
|
|
2085
|
+
color: var(--_fg);
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
${me} .tool-group-head:focus-visible {
|
|
2089
|
+
outline: 2px solid var(--_ring);
|
|
2090
|
+
outline-offset: 1px;
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
${me} .tool-group-label {
|
|
2094
|
+
min-width: 0;
|
|
2095
|
+
font-weight: 500;
|
|
2096
|
+
color: var(--_ink-2);
|
|
2097
|
+
overflow-wrap: anywhere;
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
${me} .tool-group-meta {
|
|
2101
|
+
min-width: 0;
|
|
2102
|
+
color: var(--_muted);
|
|
2103
|
+
overflow-wrap: anywhere;
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
/* Each note opens with a middle dot, which also parts the first note from
|
|
2107
|
+
the label. */
|
|
2108
|
+
${me} .tool-group-note::before {
|
|
2109
|
+
content: "\\00B7";
|
|
2110
|
+
margin: 0 6px 0 2px;
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
${me} .tool-group[data-state="error"] .tool-group-meta {
|
|
2114
|
+
color: var(--_danger);
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
${me} .tool-group-icon {
|
|
2118
|
+
flex: none;
|
|
2119
|
+
box-sizing: border-box;
|
|
2120
|
+
width: 14px;
|
|
2121
|
+
height: 14px;
|
|
2122
|
+
background: currentColor;
|
|
2123
|
+
mask: var(--_ico-check) center / contain no-repeat;
|
|
2124
|
+
color: var(--_success);
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
${me} .tool-group[data-state="error"] .tool-group-icon {
|
|
2128
|
+
mask-image: var(--_ico-error);
|
|
2129
|
+
color: var(--_danger);
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
${me} .tool-group[data-state="running"] .tool-group-icon {
|
|
2133
|
+
mask: none;
|
|
2134
|
+
background: none;
|
|
2135
|
+
border: 2px solid var(--_muted);
|
|
2136
|
+
border-top-color: transparent;
|
|
2137
|
+
border-radius: 50%;
|
|
2138
|
+
animation: ag-ui-tool-spin var(--_tool-spin-duration) linear infinite;
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
/* Waiting on the user: a steady accent dot rather than a spinner, and the
|
|
2142
|
+
count in the accent's ink. */
|
|
2143
|
+
${me} .tool-group[data-state="waiting"] .tool-group-icon {
|
|
2144
|
+
mask: none;
|
|
2145
|
+
border-radius: 50%;
|
|
2146
|
+
transform: scale(0.6);
|
|
2147
|
+
background: var(--_accent);
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
${me} .tool-group[data-state="waiting"] .tool-group-meta {
|
|
2151
|
+
color: var(--_accent-ink);
|
|
2152
|
+
font-weight: 500;
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
${me} .tool-group-chevron {
|
|
2156
|
+
flex: none;
|
|
2157
|
+
width: 12px;
|
|
2158
|
+
height: 12px;
|
|
2159
|
+
background: currentColor;
|
|
2160
|
+
mask: var(--_ico-chevron) center / contain no-repeat;
|
|
2161
|
+
opacity: 0.7;
|
|
2162
|
+
transition: transform var(--_motion) var(--_ease);
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
${me} .tool-group[data-open="true"] .tool-group-chevron {
|
|
2166
|
+
transform: rotate(90deg);
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
@media (prefers-reduced-motion: reduce) {
|
|
2170
|
+
${me} .tool-group[data-state="running"] .tool-group-icon {
|
|
2171
|
+
animation: none;
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
${me} .tool-group-list {
|
|
2176
|
+
display: flex;
|
|
2177
|
+
flex-direction: column;
|
|
2178
|
+
gap: 2px;
|
|
2179
|
+
margin: 2px 0 4px 6px;
|
|
2180
|
+
padding-left: 13px;
|
|
2181
|
+
border-left: 1px solid var(--_border);
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
${me} .tool-group[data-open="false"] .tool-group-list {
|
|
2185
|
+
display: none;
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
/* A card inside the group is one line of the list: icon, name, and its
|
|
2189
|
+
Details control at the end, with the arguments and result opening under
|
|
2190
|
+
the whole row. */
|
|
2191
|
+
${me} .tool-group .tool-call {
|
|
2192
|
+
max-width: 100%;
|
|
2193
|
+
align-self: stretch;
|
|
2194
|
+
flex-flow: row wrap;
|
|
2195
|
+
align-items: center;
|
|
2196
|
+
gap: 2px 10px;
|
|
2197
|
+
padding: 3px 0;
|
|
2198
|
+
border: 0;
|
|
2199
|
+
border-radius: 0;
|
|
2200
|
+
background: transparent;
|
|
2201
|
+
color: var(--_ink-2);
|
|
2202
|
+
font-family: inherit;
|
|
2203
|
+
font-size: var(--_text-sm);
|
|
2204
|
+
}
|
|
2205
|
+
|
|
2206
|
+
${me} .tool-group .tool-call-head {
|
|
2207
|
+
flex: 1 1 auto;
|
|
2208
|
+
justify-content: flex-start;
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
${me} .tool-group .tool-call-name {
|
|
2212
|
+
flex: 0 1 auto;
|
|
2213
|
+
font-weight: 450;
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
/* The repeat ordinal on a step whose label an earlier step has. */
|
|
2217
|
+
${me} .tool-call-repeat {
|
|
2218
|
+
color: var(--_muted);
|
|
2219
|
+
font-variant-numeric: tabular-nums;
|
|
2220
|
+
}
|
|
2221
|
+
|
|
2222
|
+
${me} .tool-group .tool-call-toggle {
|
|
2223
|
+
font-family: inherit;
|
|
2224
|
+
font-size: var(--_text-xs);
|
|
2225
|
+
color: var(--_muted);
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
${me} .tool-group .tool-call-body,
|
|
2229
|
+
${me} .tool-group .tool-call-approval,
|
|
2230
|
+
${me} .tool-group .tool-call-subagent {
|
|
2231
|
+
flex-basis: 100%;
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
/* Grouping is decided as each card is built, so a card mode set afterwards
|
|
2235
|
+
finds groups already drawn. It flattens them: the group and its list stop
|
|
2236
|
+
generating boxes, the row and the repeat ordinals go, and every card lays
|
|
2237
|
+
out as a direct child of the answer, exactly as a card built in that mode
|
|
2238
|
+
does. */
|
|
2239
|
+
${Is} .tool-group,
|
|
2240
|
+
${Is} .tool-group-list {
|
|
2241
|
+
display: contents;
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
${Is} .tool-group-head,
|
|
2245
|
+
${Is} .tool-call-repeat {
|
|
2246
|
+
display: none;
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
/* Each of these declares its own display, which beats the user-agent rule for
|
|
2250
|
+
the hidden attribute, so each needs its own. The host prefix is there for
|
|
2251
|
+
weight, not scope: it lifts these over the card-mode rules above that set
|
|
2252
|
+
display, which are heavier than a bare class and attribute. */
|
|
2253
|
+
:host .tool-group[hidden],
|
|
2254
|
+
:host .tool-group-head[hidden],
|
|
2255
|
+
:host .tool-group-list[hidden] {
|
|
2256
|
+
display: none;
|
|
2257
|
+
}
|
|
2258
|
+
`;var Ey=`
|
|
2050
2259
|
.tool-call {
|
|
2051
2260
|
align-self: flex-start;
|
|
2052
2261
|
max-width: 80%;
|
|
@@ -2241,8 +2450,6 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
2241
2450
|
padding: 6px 8px;
|
|
2242
2451
|
max-height: 160px;
|
|
2243
2452
|
overflow: auto;
|
|
2244
|
-
/* Scrolling past the end of this must not scroll the page behind it. */
|
|
2245
|
-
overscroll-behavior: contain;
|
|
2246
2453
|
background: var(--_bg);
|
|
2247
2454
|
border: 1px solid var(--_border);
|
|
2248
2455
|
border-radius: 6px;
|
|
@@ -2516,7 +2723,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
2516
2723
|
.tool-call-toggle[aria-expanded="true"]::before {
|
|
2517
2724
|
content: var(--_disclosure-expanded) " ";
|
|
2518
2725
|
}
|
|
2519
|
-
`;var
|
|
2726
|
+
`;var xy=`
|
|
2520
2727
|
.chat {
|
|
2521
2728
|
position: relative;
|
|
2522
2729
|
display: flex;
|
|
@@ -2633,7 +2840,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
2633
2840
|
opacity: 1;
|
|
2634
2841
|
background: rgba(255, 255, 255, 0.18);
|
|
2635
2842
|
}
|
|
2636
|
-
`;var
|
|
2843
|
+
`;var _y=`
|
|
2637
2844
|
/* \u2500\u2500 Density \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
2638
2845
|
:host([density="compact"]) {
|
|
2639
2846
|
--_font-size: var(--ag-ui-font-size, 13px);
|
|
@@ -2642,7 +2849,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
2642
2849
|
--_msg-pad: var(--ag-ui-msg-pad, 5px 9px);
|
|
2643
2850
|
--_msg-radius: var(--ag-ui-msg-radius, 10px);
|
|
2644
2851
|
}
|
|
2645
|
-
`;var
|
|
2852
|
+
`;var Sy=`
|
|
2646
2853
|
/* \u2500\u2500 Token defaults \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
2647
2854
|
Every public --ag-ui-* token is read here into a private --_* alias, and
|
|
2648
2855
|
only the alias is used by the rules below.
|
|
@@ -2679,6 +2886,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
2679
2886
|
--_line-strong: var(--ag-ui-line-strong, color-mix(in oklch, var(--_fg) 20%, var(--_bg)));
|
|
2680
2887
|
--_wash: var(--ag-ui-wash, color-mix(in oklch, var(--_fg) 4.5%, var(--_bg)));
|
|
2681
2888
|
--_accent-ink: var(--ag-ui-accent-ink, color-mix(in oklch, var(--_accent) 82%, var(--_fg)));
|
|
2889
|
+
--_ring: var(--ag-ui-ring, color-mix(in oklch, var(--_accent) 55%, transparent));
|
|
2682
2890
|
/* The user's turn is the accent at a whisper. With Quiet's graphite accent
|
|
2683
2891
|
that is a neutral wash; once a host sets a brand accent it becomes a tint
|
|
2684
2892
|
of the brand, which is the one thing Soft does that Quiet keeps. */
|
|
@@ -2941,8 +3149,8 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
2941
3149
|
grid/flex layout) to embed it in the page flow instead of floating. */
|
|
2942
3150
|
--_position: var(--ag-ui-position, fixed);
|
|
2943
3151
|
--_z-index: var(--ag-ui-z-index, 2147483000);
|
|
2944
|
-
--_width: var(--ag-ui-width, 380px);
|
|
2945
|
-
--_height: var(--ag-ui-height, 560px);
|
|
3152
|
+
--_width: var(--_drag-width, var(--ag-ui-width, 380px));
|
|
3153
|
+
--_height: var(--_drag-height, var(--ag-ui-height, 560px));
|
|
2946
3154
|
/* The gutter a resting floating panel keeps between itself and the edge of
|
|
2947
3155
|
the box the host left free. One number, because the inset below spends it
|
|
2948
3156
|
and the cap beneath has to know it was spent. */
|
|
@@ -3010,6 +3218,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
3010
3218
|
--_ico-check: var(--ag-ui-ico-check, url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 8.5l3 3 6-7'/%3E%3C/svg%3E"));
|
|
3011
3219
|
--_ico-error: var(--ag-ui-ico-error, url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='6.2'/%3E%3Cpath d='M8 4.9v3.7M8 11.1v.1'/%3E%3C/svg%3E"));
|
|
3012
3220
|
--_ico-declined: var(--ag-ui-ico-declined, url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='6.2'/%3E%3Cpath d='M3.8 12.2l8.4-8.4'/%3E%3C/svg%3E"));
|
|
3221
|
+
--_ico-chevron: var(--ag-ui-ico-chevron, url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 3.5l4.5 4.5L6 12.5'/%3E%3C/svg%3E"));
|
|
3013
3222
|
}
|
|
3014
3223
|
|
|
3015
3224
|
/* The colour drawn on the accent, from the accent's own luminance: white on
|
|
@@ -3043,7 +3252,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
3043
3252
|
--_on-accent: var(--ag-ui-on-accent, #ffffff);
|
|
3044
3253
|
}
|
|
3045
3254
|
}
|
|
3046
|
-
`;var
|
|
3255
|
+
`;var Ty=`
|
|
3047
3256
|
/* \u2500\u2500 Classic \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3048
3257
|
The status pill draws its state's colour on a grey wash, which measured
|
|
3049
3258
|
3.75:1 for done in the light scheme and under 2.5:1 in the dark one. Each
|
|
@@ -3072,7 +3281,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
3072
3281
|
color: var(--_muted);
|
|
3073
3282
|
opacity: 1;
|
|
3074
3283
|
}
|
|
3075
|
-
`;var
|
|
3284
|
+
`;var Ay=`
|
|
3076
3285
|
/* \u2500\u2500 Classic \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3077
3286
|
Today's indigo header, accent user bubble, round launcher and heavy
|
|
3078
3287
|
shadow, in both schemes. The code theme starts from these as well, since
|
|
@@ -3119,7 +3328,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
3119
3328
|
--_tool-fg: var(--ag-ui-tool-fg, light-dark(var(--_accent), color-mix(in oklch, var(--_accent) 50%, var(--_fg))));
|
|
3120
3329
|
--_success: var(--ag-ui-success, light-dark(#15803d, #4ade80));
|
|
3121
3330
|
}
|
|
3122
|
-
`;var
|
|
3331
|
+
`;var ky=`
|
|
3123
3332
|
/* \u2500\u2500 Code \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3124
3333
|
Dark only, monospace, green accent. Restates the colours classic sets,
|
|
3125
3334
|
after it, so code wins wherever the two would both apply. */
|
|
@@ -3137,7 +3346,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
3137
3346
|
--_font: var(--ag-ui-font, var(--_code-font));
|
|
3138
3347
|
--_frame-shadow: var(--ag-ui-frame-shadow, 0 12px 32px rgba(0, 0, 0, 0.6));
|
|
3139
3348
|
}
|
|
3140
|
-
`;var
|
|
3349
|
+
`;var Iy=`
|
|
3141
3350
|
/* \u2500\u2500 Ledger \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3142
3351
|
Structure only; the tokens are in ledger_tokens. Serif for what the
|
|
3143
3352
|
agent says, monospace for what the machine did. */
|
|
@@ -3216,6 +3425,21 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
3216
3425
|
letter-spacing: 0.01em;
|
|
3217
3426
|
}
|
|
3218
3427
|
|
|
3428
|
+
/* The step group's row reads as a ledger heading. Unscoped to grouped mode:
|
|
3429
|
+
a card mode hides the row and drops the list's box, so neither reaches a
|
|
3430
|
+
flattened card. */
|
|
3431
|
+
:host([theme~="ledger"]) .tool-group-head {
|
|
3432
|
+
font-family: var(--_code-font);
|
|
3433
|
+
font-size: var(--_text-xs);
|
|
3434
|
+
border-radius: 2px;
|
|
3435
|
+
text-transform: uppercase;
|
|
3436
|
+
letter-spacing: 0.06em;
|
|
3437
|
+
}
|
|
3438
|
+
|
|
3439
|
+
:host([theme~="ledger"]) .tool-group-list {
|
|
3440
|
+
border-left: 1px dashed var(--_line-strong);
|
|
3441
|
+
}
|
|
3442
|
+
|
|
3219
3443
|
:host([theme~="ledger"]) .chart-block {
|
|
3220
3444
|
border-top: 1px solid var(--_line-strong);
|
|
3221
3445
|
border-bottom: 1px solid var(--_line);
|
|
@@ -3288,7 +3512,7 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
3288
3512
|
:host([theme~="ledger"]) .launcher {
|
|
3289
3513
|
border: 0;
|
|
3290
3514
|
}
|
|
3291
|
-
`;var
|
|
3515
|
+
`;var Ry=`
|
|
3292
3516
|
/* \u2500\u2500 Ledger \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3293
3517
|
A smaller type scale than the other themes, because density is the point.
|
|
3294
3518
|
Set before the density presets, so density="compact" still wins. */
|
|
@@ -3318,11 +3542,11 @@ ${n}`,this.#e.autoGrow(),r.focus();let i=r.value.length;r.setSelectionRange(i,i)
|
|
|
3318
3542
|
--_chart-1: var(--ag-ui-chart-1, var(--_fg));
|
|
3319
3543
|
--_chart-2: var(--ag-ui-chart-2, var(--_accent));
|
|
3320
3544
|
}
|
|
3321
|
-
`;var
|
|
3545
|
+
`;var se={modern:':host(:not([theme~="classic"], [theme~="code"]))',quiet:':host(:not([theme~="classic"], [theme~="code"], [theme~="soft"], [theme~="ledger"]))'};var Cy=`
|
|
3322
3546
|
/* \u2500\u2500 status as an icon, never a pill \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3323
3547
|
The word stays for assistive technology through the card's own label; the
|
|
3324
3548
|
pill only ever repeated what the icon said. */
|
|
3325
|
-
${
|
|
3549
|
+
${se.modern} .tool-call-status {
|
|
3326
3550
|
position: absolute;
|
|
3327
3551
|
width: 1px;
|
|
3328
3552
|
height: 1px;
|
|
@@ -3331,7 +3555,7 @@ ${ae.modern} .tool-call-status {
|
|
|
3331
3555
|
white-space: nowrap;
|
|
3332
3556
|
}
|
|
3333
3557
|
|
|
3334
|
-
${
|
|
3558
|
+
${se.modern} .tool-call:is([data-status="done"], [data-status="error"], [data-status="declined"]) .tool-call-icon::before {
|
|
3335
3559
|
content: "";
|
|
3336
3560
|
width: 14px;
|
|
3337
3561
|
height: 14px;
|
|
@@ -3339,32 +3563,32 @@ ${ae.modern} .tool-call:is([data-status="done"], [data-status="error"], [data-st
|
|
|
3339
3563
|
mask: var(--_ico-check) center / contain no-repeat;
|
|
3340
3564
|
}
|
|
3341
3565
|
|
|
3342
|
-
${
|
|
3566
|
+
${se.modern} .tool-call[data-status="done"] .tool-call-icon {
|
|
3343
3567
|
color: var(--_success);
|
|
3344
3568
|
}
|
|
3345
3569
|
|
|
3346
|
-
${
|
|
3570
|
+
${se.modern} .tool-call[data-status="error"] .tool-call-icon {
|
|
3347
3571
|
color: var(--_danger);
|
|
3348
3572
|
}
|
|
3349
3573
|
|
|
3350
|
-
${
|
|
3574
|
+
${se.modern} .tool-call[data-status="error"] .tool-call-icon::before {
|
|
3351
3575
|
mask-image: var(--_ico-error);
|
|
3352
3576
|
}
|
|
3353
3577
|
|
|
3354
3578
|
/* An interrupted call is muted like a declined one but keeps the base glyph
|
|
3355
3579
|
rather than taking the declined mark: nobody refused it, it only did not
|
|
3356
3580
|
finish. */
|
|
3357
|
-
${
|
|
3581
|
+
${se.modern} .tool-call:is([data-status="declined"], [data-status="interrupted"]) .tool-call-icon {
|
|
3358
3582
|
color: var(--_muted);
|
|
3359
3583
|
}
|
|
3360
3584
|
|
|
3361
|
-
${
|
|
3585
|
+
${se.modern} .tool-call[data-status="declined"] .tool-call-icon::before {
|
|
3362
3586
|
mask-image: var(--_ico-declined);
|
|
3363
3587
|
}
|
|
3364
3588
|
|
|
3365
3589
|
/* The settled icon inherits colour from the icon box, so the box's own glyph
|
|
3366
3590
|
colour from the base rules must not win. */
|
|
3367
|
-
${
|
|
3591
|
+
${se.modern} .tool-call .tool-call-icon::before {
|
|
3368
3592
|
color: inherit;
|
|
3369
3593
|
}
|
|
3370
3594
|
|
|
@@ -3379,106 +3603,106 @@ ${ae.modern} .tool-call .tool-call-icon::before {
|
|
|
3379
3603
|
/* \u2500\u2500 one action row per answer \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3380
3604
|
Copy and retry under every interim sentence of a long turn read as noise;
|
|
3381
3605
|
only the row after the last bubble of a turn stays. */
|
|
3382
|
-
${
|
|
3606
|
+
${se.modern} .message-actions:has(~ .message--assistant) {
|
|
3383
3607
|
display: none;
|
|
3384
3608
|
}
|
|
3385
3609
|
|
|
3386
|
-
${
|
|
3610
|
+
${se.modern} .chart-block {
|
|
3387
3611
|
box-sizing: border-box;
|
|
3388
3612
|
}
|
|
3389
3613
|
|
|
3390
3614
|
/* The baseline placeholder is the browser default, which measured under
|
|
3391
3615
|
4.5:1 on every dark surface. A derived ink clears it in both schemes. */
|
|
3392
|
-
${
|
|
3616
|
+
${se.modern} .input::placeholder {
|
|
3393
3617
|
color: var(--_ink-3);
|
|
3394
3618
|
opacity: 1;
|
|
3395
3619
|
}
|
|
3396
|
-
`;var
|
|
3620
|
+
`;var Ny=`
|
|
3397
3621
|
/* \u2500\u2500 Quiet \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3398
3622
|
The default. Its tokens are the token defaults; this is the little
|
|
3399
3623
|
structure it adds on top: no bubble for the agent, hairlines, and a
|
|
3400
3624
|
composer that sits on the panel rather than in a band. */
|
|
3401
3625
|
|
|
3402
|
-
${
|
|
3626
|
+
${se.quiet} .chat {
|
|
3403
3627
|
font-feature-settings: "cv11", "ss01";
|
|
3404
3628
|
letter-spacing: -0.003em;
|
|
3405
3629
|
line-height: var(--_leading);
|
|
3406
3630
|
}
|
|
3407
3631
|
|
|
3408
|
-
${
|
|
3632
|
+
${se.quiet} .header {
|
|
3409
3633
|
padding: 12px 14px 12px 18px;
|
|
3410
3634
|
}
|
|
3411
3635
|
|
|
3412
|
-
${
|
|
3636
|
+
${se.quiet} .header-title {
|
|
3413
3637
|
font-size: var(--_text-md);
|
|
3414
3638
|
font-weight: 600;
|
|
3415
3639
|
letter-spacing: -0.01em;
|
|
3416
3640
|
}
|
|
3417
3641
|
|
|
3418
|
-
${
|
|
3642
|
+
${se.quiet} .header-btn {
|
|
3419
3643
|
color: var(--_ink-3);
|
|
3420
3644
|
border-radius: 8px;
|
|
3421
3645
|
}
|
|
3422
3646
|
|
|
3423
|
-
${
|
|
3647
|
+
${se.quiet} .header-btn:hover {
|
|
3424
3648
|
color: var(--_fg);
|
|
3425
3649
|
background: var(--_hover);
|
|
3426
3650
|
}
|
|
3427
3651
|
|
|
3428
|
-
${
|
|
3652
|
+
${se.quiet} .message--user {
|
|
3429
3653
|
border-radius: var(--_msg-radius);
|
|
3430
3654
|
padding: 8px 12px;
|
|
3431
3655
|
}
|
|
3432
3656
|
|
|
3433
|
-
${
|
|
3657
|
+
${se.quiet} .message--assistant {
|
|
3434
3658
|
padding: 0;
|
|
3435
3659
|
max-width: 100%;
|
|
3436
3660
|
}
|
|
3437
3661
|
|
|
3438
|
-
${
|
|
3662
|
+
${se.quiet} .message--assistant a {
|
|
3439
3663
|
color: inherit;
|
|
3440
3664
|
text-decoration: underline;
|
|
3441
3665
|
text-decoration-color: var(--_line-strong);
|
|
3442
3666
|
text-underline-offset: 3px;
|
|
3443
3667
|
}
|
|
3444
3668
|
|
|
3445
|
-
${
|
|
3669
|
+
${se.quiet} .thoughts-toggle {
|
|
3446
3670
|
color: var(--_muted);
|
|
3447
3671
|
font-size: var(--_text-sm);
|
|
3448
3672
|
}
|
|
3449
3673
|
|
|
3450
|
-
${
|
|
3674
|
+
${se.quiet} .input-row {
|
|
3451
3675
|
border-top: 0;
|
|
3452
3676
|
padding-top: 4px;
|
|
3453
3677
|
}
|
|
3454
3678
|
|
|
3455
|
-
${
|
|
3679
|
+
${se.quiet} .composer {
|
|
3456
3680
|
border-color: var(--_line-strong);
|
|
3457
3681
|
box-shadow: 0 1px 2px rgb(0 0 0 / 0.04);
|
|
3458
3682
|
}
|
|
3459
3683
|
|
|
3460
|
-
${
|
|
3684
|
+
${se.quiet} .composer:focus-within {
|
|
3461
3685
|
border-color: var(--_ink-3);
|
|
3462
3686
|
box-shadow: 0 0 0 3px var(--_wash);
|
|
3463
3687
|
}
|
|
3464
3688
|
|
|
3465
|
-
${
|
|
3689
|
+
${se.quiet} .send {
|
|
3466
3690
|
border-radius: 9px;
|
|
3467
3691
|
}
|
|
3468
3692
|
|
|
3469
|
-
${
|
|
3693
|
+
${se.quiet} :is(.suggestion-chip, .skill-chip) {
|
|
3470
3694
|
background: transparent;
|
|
3471
3695
|
border: 1px solid var(--_line);
|
|
3472
3696
|
color: var(--_ink-2);
|
|
3473
3697
|
border-radius: 999px;
|
|
3474
3698
|
}
|
|
3475
3699
|
|
|
3476
|
-
${
|
|
3700
|
+
${se.quiet} :is(.suggestion-chip, .skill-chip):hover {
|
|
3477
3701
|
background: var(--_hover);
|
|
3478
3702
|
color: var(--_fg);
|
|
3479
3703
|
}
|
|
3480
3704
|
|
|
3481
|
-
${
|
|
3705
|
+
${se.quiet} .confirm {
|
|
3482
3706
|
border: 1px solid var(--_line-strong);
|
|
3483
3707
|
border-radius: var(--_radius);
|
|
3484
3708
|
padding: 14px;
|
|
@@ -3486,7 +3710,7 @@ ${ae.quiet} .confirm {
|
|
|
3486
3710
|
box-shadow: 0 1px 2px rgb(0 0 0 / 0.04);
|
|
3487
3711
|
}
|
|
3488
3712
|
|
|
3489
|
-
${
|
|
3713
|
+
${se.quiet} .confirm-btn {
|
|
3490
3714
|
border-radius: 8px;
|
|
3491
3715
|
padding: 7px 14px;
|
|
3492
3716
|
font-weight: 500;
|
|
@@ -3494,16 +3718,16 @@ ${ae.quiet} .confirm-btn {
|
|
|
3494
3718
|
border-color: var(--_line-strong);
|
|
3495
3719
|
}
|
|
3496
3720
|
|
|
3497
|
-
${
|
|
3721
|
+
${se.quiet} .confirm-btn--confirm {
|
|
3498
3722
|
border-color: var(--_accent);
|
|
3499
3723
|
font-weight: 600;
|
|
3500
3724
|
}
|
|
3501
3725
|
|
|
3502
|
-
${
|
|
3726
|
+
${se.quiet} .launcher {
|
|
3503
3727
|
border: 1px solid var(--_line-strong);
|
|
3504
3728
|
box-shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 8px 24px -10px rgb(0 0 0 / 0.25);
|
|
3505
3729
|
}
|
|
3506
|
-
`;var
|
|
3730
|
+
`;var Oy=`
|
|
3507
3731
|
/* \u2500\u2500 Scheme \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3508
3732
|
Every theme declares its colours with light-dark, so the scheme is one
|
|
3509
3733
|
property. Matched as a word, so dark works alone (the default theme,
|
|
@@ -3518,7 +3742,7 @@ ${ae.quiet} .launcher {
|
|
|
3518
3742
|
:host([theme~="auto"]) {
|
|
3519
3743
|
color-scheme: light dark;
|
|
3520
3744
|
}
|
|
3521
|
-
`;var
|
|
3745
|
+
`;var Py=`
|
|
3522
3746
|
/* \u2500\u2500 Soft \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3523
3747
|
Structure only; the tokens are in soft_tokens, set before the density
|
|
3524
3748
|
presets. */
|
|
@@ -3578,6 +3802,26 @@ ${ae.quiet} .launcher {
|
|
|
3578
3802
|
color: var(--_accent-ink);
|
|
3579
3803
|
}
|
|
3580
3804
|
|
|
3805
|
+
/* The step group's row as a tinted pill. Unscoped to grouped mode: a card
|
|
3806
|
+
mode hides the row and drops the list's box, so neither reaches a
|
|
3807
|
+
flattened card. */
|
|
3808
|
+
:host([theme~="soft"]) .tool-group-head {
|
|
3809
|
+
background: var(--_tint);
|
|
3810
|
+
border: 1px solid var(--_border);
|
|
3811
|
+
border-radius: 999px;
|
|
3812
|
+
padding: 5px 12px 5px 9px;
|
|
3813
|
+
margin-left: 0;
|
|
3814
|
+
}
|
|
3815
|
+
|
|
3816
|
+
:host([theme~="soft"]) .tool-group-head:hover {
|
|
3817
|
+
background: var(--_tint-2);
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3820
|
+
:host([theme~="soft"]) .tool-group-list {
|
|
3821
|
+
border-left-color: var(--_tint-2);
|
|
3822
|
+
margin-left: 14px;
|
|
3823
|
+
}
|
|
3824
|
+
|
|
3581
3825
|
:host([theme~="soft"]) .chart-block {
|
|
3582
3826
|
background: var(--_bg);
|
|
3583
3827
|
border: 1px solid var(--_border);
|
|
@@ -3644,7 +3888,7 @@ ${ae.quiet} .launcher {
|
|
|
3644
3888
|
border: 0;
|
|
3645
3889
|
box-shadow: 0 14px 30px -12px color-mix(in oklch, var(--_accent) 70%, transparent);
|
|
3646
3890
|
}
|
|
3647
|
-
`;var
|
|
3891
|
+
`;var My=`
|
|
3648
3892
|
/* \u2500\u2500 Soft \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3649
3893
|
Seeds, plus two surfaces mixed from the accent: a faint wash for the panel
|
|
3650
3894
|
chrome and a stronger tint for the user's turns. */
|
|
@@ -3670,7 +3914,7 @@ ${ae.quiet} .launcher {
|
|
|
3670
3914
|
--_chart-1: var(--ag-ui-chart-1, var(--_accent));
|
|
3671
3915
|
--_chart-2: var(--ag-ui-chart-2, color-mix(in oklch, var(--_accent) 38%, var(--_bg)));
|
|
3672
3916
|
}
|
|
3673
|
-
`;var
|
|
3917
|
+
`;var Ly=`
|
|
3674
3918
|
/* A chip carries its own text colour because it carries its own background.
|
|
3675
3919
|
The same chip renders in two places with opposite inherited colours: the
|
|
3676
3920
|
composer tray gives it the panel's, a sent user bubble gives it the user
|
|
@@ -3782,7 +4026,7 @@ ${ae.quiet} .launcher {
|
|
|
3782
4026
|
font-size: 12px;
|
|
3783
4027
|
padding: 2px 4px;
|
|
3784
4028
|
}
|
|
3785
|
-
`;var
|
|
4029
|
+
`;var zy=`
|
|
3786
4030
|
/* Empty-state region (slot): centred while it's the only thing in the
|
|
3787
4031
|
list, hidden as soon as a message, card, or pending indicator renders. */
|
|
3788
4032
|
.empty {
|
|
@@ -3950,7 +4194,7 @@ ${ae.quiet} .launcher {
|
|
|
3950
4194
|
:host([data-restoring]) .greeting {
|
|
3951
4195
|
visibility: hidden;
|
|
3952
4196
|
}
|
|
3953
|
-
`;var
|
|
4197
|
+
`;var Dy=`
|
|
3954
4198
|
The wrap is insurance rather than a fix: these buttons are glyph-only, so at
|
|
3955
4199
|
every width tested they fit on one line and removing the wrap changes
|
|
3956
4200
|
nothing. It is here because the confirmation row one release earlier did
|
|
@@ -4101,7 +4345,7 @@ ${ae.quiet} .launcher {
|
|
|
4101
4345
|
opacity: 1;
|
|
4102
4346
|
color: var(--_accent);
|
|
4103
4347
|
}
|
|
4104
|
-
`;var
|
|
4348
|
+
`;var $y=`
|
|
4105
4349
|
/* \u2500\u2500 Answer group / well \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
4106
4350
|
One .answer per assistant turn wraps the streamed text, its tool cards,
|
|
4107
4351
|
and the pending indicator so a whole answer reads (and can be boxed) as one
|
|
@@ -4231,8 +4475,6 @@ ${ae.quiet} .launcher {
|
|
|
4231
4475
|
.message--assistant pre {
|
|
4232
4476
|
padding: 8px 10px;
|
|
4233
4477
|
overflow: auto;
|
|
4234
|
-
/* Scrolling past the end of this must not scroll the page behind it. */
|
|
4235
|
-
overscroll-behavior: contain;
|
|
4236
4478
|
background: var(--_bg);
|
|
4237
4479
|
border: 1px solid var(--_border);
|
|
4238
4480
|
border-radius: 6px;
|
|
@@ -4362,7 +4604,7 @@ ${ae.quiet} .launcher {
|
|
|
4362
4604
|
opacity: 0.6;
|
|
4363
4605
|
}
|
|
4364
4606
|
}
|
|
4365
|
-
`;var
|
|
4607
|
+
`;var Uy=`
|
|
4366
4608
|
/* Jump-to-latest: shown only once the reader has scrolled away *and* missed
|
|
4367
4609
|
something. Anchored to the panel rather than the list so it does not scroll
|
|
4368
4610
|
with the content it is offering to scroll to. */
|
|
@@ -4499,95 +4741,95 @@ ${ae.quiet} .launcher {
|
|
|
4499
4741
|
flex-direction: column;
|
|
4500
4742
|
gap: var(--_space);
|
|
4501
4743
|
}
|
|
4502
|
-
`;var
|
|
4744
|
+
`;var Hy=[Sy,Ay,ky,My,Ry,Oy,_y,hy,py,gy,my,dy,uy,xy,cy,Uy,zy,$y,by,Ey,fy,ry,ny,ty,vy,Ly,sy,Dy,ay,ly,oy,iy,wy,Ty,Cy,Ny,Py,Iy].join("");function Fy(t,e=[]){let n=new CSSStyleSheet;return n.replaceSync(Hy),t.adoptedStyleSheets=[n,...e],n}function go(t,e,n){let r=document.createElement("button");r.type="button",r.className=`header-btn header-btn--${t}`,r.setAttribute("part",`header-button ${t}-button`),r.title=e,r.setAttribute("aria-label",e);let o=document.createElement("slot");return o.name=`icon-${t}`,o.append(document.createTextNode(n)),r.append(o),r}function fr(t,e,n,r){let o=document.createElement("span");o.className="icon-holder",o.setAttribute("part",e);let i=document.createElement("slot");if(i.name=t,r!==null){let a=document.createElement("img");a.className="icon-img",a.src=r,a.alt="",i.append(a)}else n!==null&&(i.innerHTML=n);return o.append(i),o}function Gy(t){let{strings:e}=t,n=document.createElement("div");n.className="header",n.setAttribute("part","header");let r=t.title;r.className="header-title",r.setAttribute("part","title"),r.textContent=t.titleText,(t.host.querySelector('[slot="icon"]')!==null||t.iconUrl!==null)&&n.append(fr("icon","icon",null,t.iconUrl));let o=document.createElement("slot");o.name="header-actions";let i=document.createElement("div");i.className="header-controls",i.setAttribute("part","header-controls");let a=go("history",e.chatHistory,"\u2630");a.addEventListener("click",t.onHistory);let s=go("checkpoints",e.checkpoints,"\u21BA");s.addEventListener("click",t.onCheckpoints);let c=go("new",e.newChat,"\u271A");c.addEventListener("click",t.onNewChat);let l=go("collapse",e.collapse,"\u2014");l.addEventListener("click",t.onCollapse),t.withCheckpoints?i.append(a,s,c):i.append(a,c);let u=t.themeToggle;return u!==null&&(u.type="button",u.className="header-btn header-btn--theme",u.setAttribute("part","header-button theme-toggle"),u.title=e.toggleTheme,u.setAttribute("aria-label",e.toggleTheme),u.addEventListener("click",t.onToggleTheme,{signal:t.signal}),i.append(u)),i.append(l),n.append(r,o,i),{header:n,checkpoints:s}}function By(t){let{launcher:e,badge:n,railLabel:r}=t;e.className="launcher",e.type="button",e.setAttribute("part","launcher"),e.setAttribute("aria-label",t.strings.expand),n.className="launcher-badge",n.setAttribute("part","launcher-badge"),n.setAttribute("aria-hidden","true"),n.hidden=!0,r.className="rail-label",r.setAttribute("part","rail-label"),r.setAttribute("aria-hidden","true"),r.textContent=t.titleText,e.replaceChildren(fr("launcher","launcher-icon",Lp,t.iconUrl),r,n),e.addEventListener("click",t.onOpen,{signal:t.signal})}function Zy(t){return t.getAttribute("data-unread-badge")!=="false"}function Vy(t){return t.getAttribute("data-launcher-icon-url")??t.getAttribute("data-icon-url")}var pk=new Set(["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DD","DIV","DL","DT","FIGCAPTION","FIGURE","FOOTER","H1","H2","H3","H4","H5","H6","HEADER","HR","MAIN","NAV","OL","P","SECTION","UL"]);function Rs(t){let e=t.cloneNode(!0);for(let n of Array.from(e.querySelectorAll("button")))n.remove();return{text:mk(jy(e)),html:e.innerHTML}}function jy(t){if(t.nodeType===Node.TEXT_NODE)return t.nodeValue.replace(/\s+/g," ");if(t.nodeType!==Node.ELEMENT_NODE)return"";let e=t,n=e.tagName;if(n==="BR")return`
|
|
4503
4745
|
`;if(n==="PRE")return`
|
|
4504
4746
|
|
|
4505
|
-
${
|
|
4747
|
+
${qy(e)}
|
|
4506
4748
|
|
|
4507
4749
|
`;if(n==="TABLE")return`
|
|
4508
4750
|
|
|
4509
|
-
${
|
|
4751
|
+
${fk(e)}
|
|
4510
4752
|
|
|
4511
4753
|
`;if(n==="UL"||n==="OL")return`
|
|
4512
4754
|
|
|
4513
|
-
${
|
|
4755
|
+
${hk(e,n==="OL")}
|
|
4514
4756
|
|
|
4515
|
-
`;let r=
|
|
4757
|
+
`;let r=Wy(e);return pk.has(n)?`
|
|
4516
4758
|
|
|
4517
4759
|
${r}
|
|
4518
4760
|
|
|
4519
|
-
`:r}function
|
|
4520
|
-
`)}function
|
|
4521
|
-
`)}function
|
|
4761
|
+
`:r}function Wy(t){let e="";for(let n of Array.from(t.childNodes))e+=jy(n);return e}function hk(t,e){return Array.from(t.children).map((n,r)=>`${e?`${r+1}. `:"- "}${Wy(n).trim()}`).join(`
|
|
4762
|
+
`)}function fk(t){return Array.from(t.querySelectorAll("tr")).map(e=>Array.from(e.children).map(n=>qy(n).replace(/\s+/g," ").trim()).join(" ")).join(`
|
|
4763
|
+
`)}function qy(t){return t.textContent}function mk(t){return t.replace(/[^\S\n]+\n/g,`
|
|
4522
4764
|
`).replace(/\n{3,}/g,`
|
|
4523
4765
|
|
|
4524
|
-
`).trim()}var
|
|
4525
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function dk(e,t){return lk(e)||ck(e,t)||pk(e,t)||uk()}function pk(e,t){if(e){if(typeof e=="string")return Hy(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Hy(e,t):void 0}}function Is(e){var t,n;function r(i,a){try{var s=e[i](a),l=s.value,c=l instanceof sk;Promise.resolve(c?l.v:l).then(function(u){if(c){var f=i==="return"&&l.k?i:"next";if(!l.k||u.done)return r(f,u);u=e[f](u).value}o(!!s.done,u)},function(u){r("throw",u)})}catch(u){o(2,u)}}function o(i,a){i===2?t.reject(a):t.resolve({value:a,done:i}),(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(i,a){return new Promise(function(s,l){var c={key:i,arg:a,resolve:s,reject:l,next:null};n?n=n.next=c:(t=n=c,r(i,a))})},typeof e.return!="function"&&(this.return=void 0)}Is.prototype[typeof Symbol=="function"&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},Is.prototype.next=function(e){return this._invoke("next",e)},Is.prototype.throw=function(e){return this._invoke("throw",e)},Is.prototype.return=function(e){return this._invoke("return",e)};var tw=Object.entries,Fy=Object.setPrototypeOf,hk=Object.isFrozen,nw=Object.getPrototypeOf,rw=Object.getOwnPropertyDescriptor,Me=Object.freeze,Fe=Object.seal,hr=Object.create,ow=typeof Reflect<"u"&&Reflect,wd=ow.apply,Ed=ow.construct;Me||(Me=function(t){return t});Fe||(Fe=function(t){return t});wd||(wd=function(t,n){for(var r=arguments.length,o=new Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];return t.apply(n,o)});Ed||(Ed=function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return new t(...r)});var Pt=Se(Array.prototype.forEach);Array.prototype.indexOf;var fk=Se(Array.prototype.lastIndexOf),Gy=Se(Array.prototype.pop),po=Se(Array.prototype.push),mk=Se(Array.prototype.slice),gk=Se(Array.prototype.splice),fr=Array.isArray,dd=iw(Set),pd=Se(Set.prototype.add),ho=Se(Set.prototype.has),An=Se(String.prototype.toLowerCase),hd=Se(String.prototype.toString),By=Se(String.prototype.match),fo=Se(String.prototype.replace),Zy=Se(String.prototype.indexOf),vk=Se(String.prototype.trim),bk=Se(Number.prototype.toString),yk=Se(Boolean.prototype.toString),Vy=typeof BigInt>"u"?null:Se(BigInt.prototype.toString),jy=typeof Symbol>"u"?null:Se(Symbol.prototype.toString),Ye=Se(Object.prototype.hasOwnProperty),mo=Se(Object.prototype.toString),He=Se(RegExp.prototype.test),Mt=iw(TypeError);function Se(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return wd(e,t,r)}}function iw(e){return function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return Ed(e,n)}}function oe(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:An;if(Fy&&Fy(e,null),!fr(t))return e;let r=t.length;for(;r--;){let o=t[r];if(typeof o=="string"){let i=n(o);i!==o&&(hk(t)||(t[r]=i),o=i)}e[o]=!0}return e}function wk(e){for(let t=0;t<e.length;t++)Ye(e,t)||(e[t]=null);return e}function et(e){let t=hr(null);for(let r of tw(e)){var n=dk(r,2);let o=n[0],i=n[1];Ye(e,o)&&(fr(i)?t[o]=wk(i):i&&typeof i=="object"&&i.constructor===Object?t[o]=et(i):t[o]=i)}return t}function Ek(e){switch(typeof e){case"string":return e;case"number":return bk(e);case"boolean":return yk(e);case"bigint":return Vy?Vy(e):"0";case"symbol":return jy?jy(e):"Symbol()";case"undefined":return mo(e);case"function":case"object":{if(e===null)return mo(e);let t=e,n=it(t,"toString");if(typeof n=="function"){let r=n(t);return typeof r=="string"?r:mo(r)}return mo(e)}default:return mo(e)}}function it(e,t){for(;e!==null;){let r=rw(e,t);if(r){if(r.get)return Se(r.get);if(typeof r.value=="function")return Se(r.value)}e=nw(e)}function n(){return null}return n}function xk(e,t){for(;e!==null;){let n=rw(e,t);if(n)return n.get?Se(n.get):null;e=nw(e)}return null}function _k(e){try{return He(e,""),!0}catch{return!1}}var Wy=Me(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),fd=Me(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),md=Me(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),Sk=Me(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),gd=Me(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),Tk=Me(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),qy=Me(["#text"]),Yy=Me(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),vd=Me(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dominant-baseline","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","pointer-events","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-orientation","text-rendering","textlength","type","u1","u2","unicode","values","vector-effect","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Xy=Me(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),Rs=Me(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),Ak=Fe(/{{[\w\W]*|^[\w\W]*}}/g),kk=Fe(/<%[\w\W]*|^[\w\W]*%>/g),Ik=Fe(/\${[\w\W]*/g),Rk=Fe(/^data-[\-\w.\u00B7-\uFFFF]+$/),Ck=Fe(/^aria-[\-\w]+$/),Ky=Fe(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Nk=Fe(/^(?:\w+script|data):/i),Ok=Fe(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Pk=Fe(/^html$/i),Mk=Fe(/^[a-z][.\w]*(-[.\w]+)+$/i),bd=Fe(/<[/\w!]/g),Jy=Fe(/<[/\w]/g),zk=Fe(/<\/no(script|embed|frames)/i),Qy=Fe(/\/>/i),Re={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Lk=Me(oe({},["style","script","xmp","iframe","noembed","noframes","plaintext","noscript"])),Dk=function(){return typeof window>"u"?null:window},$k=function(t,n){if(typeof t!="object"||typeof t.createPolicy!="function")return null;let r=null,o="data-tt-policy-suffix";n&&n.hasAttribute(o)&&(r=n.getAttribute(o));let i="dompurify"+(r?"#"+r:"");try{return t.createPolicy(i,{createHTML(a){return a},createScriptURL(a){return a}})}catch{return console.warn("TrustedTypes policy "+i+" could not be created."),null}},ew=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},qt=function(t,n,r,o){return Ye(t,n)&&fr(t[n])?oe(o.base?et(o.base):{},t[n],o.transform):r},yd=function(t,n,r){let o=Ye(t,n)?t[n]:void 0;return o&&typeof o=="object"?et(o):r()};function aw(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Dk(),t=P=>aw(P);if(t.version="3.4.17",t.removed=[],!e||!e.document||e.document.nodeType!==Re.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,o=r.currentScript;e.DocumentFragment;let i=e.HTMLTemplateElement,a=e.Node,s=e.Element,l=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let c=e.DOMParser,u=e.trustedTypes,f=s.prototype,m=it(f,"cloneNode"),p=it(f,"remove"),h=it(f,"removeAttributeNode"),E=it(f,"nextSibling"),g=it(f,"childNodes"),_=it(f,"parentNode"),b=it(f,"shadowRoot"),k=it(f,"attributes"),O=a&&a.prototype?it(a.prototype,"nodeType"):null,w=a&&a.prototype?it(a.prototype,"nodeName"):null,S=a&&a.prototype?it(a.prototype,"ownerDocument"):null,x=function(d){return O?O(d):d.nodeType},I=function(d){return w?w(d):d.nodeName},z=xk(f,"namespaceURI"),Y=function(d){return z?z(d):d.namespaceURI};if(typeof i=="function"){let P=n.createElement("template");P.content&&P.content.ownerDocument&&(n=P.content.ownerDocument)}let X,Ce="",Ws,Gd=!1,br=0,Bd=function(){if(br>0)throw Mt('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},Nn=function(d){Bd(),br++;try{return X.createHTML(d)}finally{br--}},Yw=function(d){Bd(),br++;try{return X.createScriptURL(d)}finally{br--}},Xw=function(){return Gd||(Ws=$k(u,o),Gd=!0),Ws},Io=n,qs=Io.implementation,Zd=Io.createNodeIterator,Kw=Io.createDocumentFragment,Jw=Io.getElementsByTagName,Qw=r.importNode,me=ew();t.isSupported=typeof tw=="function"&&typeof _=="function"&&qs&&qs.createHTMLDocument!==void 0;let eE=Ak,tE=kk,nE=Ik,rE=Rk,oE=Ck,iE=Nk,Vd=Ok,aE=Mk,jd=Ky,be=null,Ys=oe({},[...Wy,...fd,...md,...gd,...qy]),ye=null,Xs=oe({},[...Yy,...vd,...Xy,...Rs]),mt=Object.seal(hr(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),yr=null,Wd=null,zt=Object.seal(hr(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),qd=!0,Ks=!0,Yd=!1,Js=!0,kt=!1,Xt=!0,Kt=!1,Qs=!1,Ro=null,Co=null,el=!1,On=!1,No=!1,Oo=!1,Xd=!0,Kd=!1,Jd="user-content-",tl=!0,nl=!1,Jt=null,Pn={},Qt=null,Qd=oe({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]),ep=null,tp=oe({},["audio","video","img","source","image","track"]),np=null,rp=oe({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Po="http://www.w3.org/1998/Math/MathML",Mo="http://www.w3.org/2000/svg",gt="http://www.w3.org/1999/xhtml",Mn=gt,rl=!1,ol=null,sE=oe({},[Po,Mo,gt],hd),op=Me(["mi","mo","mn","ms","mtext"]),il=oe({},op),ip=Me(["annotation-xml"]),al=oe({},ip),lE=oe({},["title","style","font","a","script"]),wr=null,cE=["application/xhtml+xml","text/html"],uE="text/html",Ae=null,zn=null,dE=n.createElement("form"),ap=function(d){return d instanceof RegExp||d instanceof Function},sl=function(){let d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(zn&&zn===d)return;(!d||typeof d!="object")&&(d={}),d=et(d),wr=cE.indexOf(d.PARSER_MEDIA_TYPE)===-1?uE:d.PARSER_MEDIA_TYPE,Ae=wr==="application/xhtml+xml"?hd:An,be=qt(d,"ALLOWED_TAGS",Ys,{transform:Ae}),ye=qt(d,"ALLOWED_ATTR",Xs,{transform:Ae}),ol=qt(d,"ALLOWED_NAMESPACES",sE,{transform:hd}),np=qt(d,"ADD_URI_SAFE_ATTR",rp,{transform:Ae,base:rp}),ep=qt(d,"ADD_DATA_URI_TAGS",tp,{transform:Ae,base:tp}),Qt=qt(d,"FORBID_CONTENTS",Qd,{transform:Ae}),yr=qt(d,"FORBID_TAGS",et({}),{transform:Ae}),Wd=qt(d,"FORBID_ATTR",et({}),{transform:Ae}),Pn=Ye(d,"USE_PROFILES")?d.USE_PROFILES&&typeof d.USE_PROFILES=="object"?et(d.USE_PROFILES):d.USE_PROFILES:!1,qd=d.ALLOW_ARIA_ATTR!==!1,Ks=d.ALLOW_DATA_ATTR!==!1,Yd=d.ALLOW_UNKNOWN_PROTOCOLS||!1,Js=d.ALLOW_SELF_CLOSE_IN_ATTR!==!1,kt=d.SAFE_FOR_TEMPLATES||!1,Xt=d.SAFE_FOR_XML!==!1,Kt=d.WHOLE_DOCUMENT||!1,On=d.RETURN_DOM||!1,No=d.RETURN_DOM_FRAGMENT||!1,Oo=d.RETURN_TRUSTED_TYPE||!1,el=d.FORCE_BODY||!1,Xd=d.SANITIZE_DOM!==!1,Kd=d.SANITIZE_NAMED_PROPS||!1,tl=d.KEEP_CONTENT!==!1,nl=d.IN_PLACE||!1,jd=_k(d.ALLOWED_URI_REGEXP)?d.ALLOWED_URI_REGEXP:Ky,Mn=typeof d.NAMESPACE=="string"?d.NAMESPACE:gt,il=yd(d,"MATHML_TEXT_INTEGRATION_POINTS",()=>oe({},op)),al=yd(d,"HTML_INTEGRATION_POINTS",()=>oe({},ip));let y=yd(d,"CUSTOM_ELEMENT_HANDLING",()=>hr(null));if(mt=hr(null),Ye(y,"tagNameCheck")&&ap(y.tagNameCheck)&&(mt.tagNameCheck=y.tagNameCheck),Ye(y,"attributeNameCheck")&&ap(y.attributeNameCheck)&&(mt.attributeNameCheck=y.attributeNameCheck),Ye(y,"allowCustomizedBuiltInElements")&&typeof y.allowCustomizedBuiltInElements=="boolean"&&(mt.allowCustomizedBuiltInElements=y.allowCustomizedBuiltInElements),Fe(mt),kt&&(Ks=!1),No&&(On=!0),Pn&&(be=oe({},qy),ye=hr(null),Pn.html===!0&&(oe(be,Wy),oe(ye,Yy)),Pn.svg===!0&&(oe(be,fd),oe(ye,vd),oe(ye,Rs)),Pn.svgFilters===!0&&(oe(be,md),oe(ye,vd),oe(ye,Rs)),Pn.mathMl===!0&&(oe(be,gd),oe(ye,Xy),oe(ye,Rs))),zt.tagCheck=null,zt.attributeCheck=null,Ye(d,"ADD_TAGS")&&(typeof d.ADD_TAGS=="function"?zt.tagCheck=d.ADD_TAGS:fr(d.ADD_TAGS)&&(be===Ys&&(be=et(be)),oe(be,d.ADD_TAGS,Ae))),Ye(d,"ADD_ATTR")&&(typeof d.ADD_ATTR=="function"?zt.attributeCheck=d.ADD_ATTR:fr(d.ADD_ATTR)&&(ye===Xs&&(ye=et(ye)),oe(ye,d.ADD_ATTR,Ae))),Ye(d,"ADD_FORBID_CONTENTS")&&fr(d.ADD_FORBID_CONTENTS)&&(Qt===Qd&&(Qt=et(Qt)),oe(Qt,d.ADD_FORBID_CONTENTS,Ae)),tl&&(be["#text"]=!0),Kt&&oe(be,["html","head","body"]),be.table&&(oe(be,["tbody"]),delete yr.tbody),d.TRUSTED_TYPES_POLICY){if(typeof d.TRUSTED_TYPES_POLICY.createHTML!="function")throw Mt('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof d.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Mt('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');let C=X;X=d.TRUSTED_TYPES_POLICY;try{Ce=Nn("")}catch(N){throw X=C,N}}else d.TRUSTED_TYPES_POLICY===null?(X=void 0,Ce=""):(X===void 0&&(X=Xw()),X&&typeof Ce=="string"&&(Ce=Nn("")));Me&&Me(d),zn=d},sp=oe({},[...fd,...md,...Sk]),lp=oe({},[...gd,...Tk]),pE=function(d,y,C){return y.namespaceURI===gt?d==="svg":y.namespaceURI===Po?d==="svg"&&(C==="annotation-xml"||il[C]):!!sp[d]},hE=function(d,y,C){return y.namespaceURI===gt?d==="math":y.namespaceURI===Mo?d==="math"&&al[C]:!!lp[d]},fE=function(d,y,C){return y.namespaceURI===Mo&&!al[C]||y.namespaceURI===Po&&!il[C]?!1:!lp[d]&&(lE[d]||!sp[d])},mE=function(d){let y=Y(d),C=An(I(d)),N=_(d),H,Z;return N&&x(N)===Re.element?(H={namespaceURI:Y(N)},Z=An(I(N))):(H={namespaceURI:Mn},Z="template"),ol[y]?y===Mo?pE(C,H,Z):y===Po?hE(C,H,Z):y===gt?fE(C,H,Z):!!(wr==="application/xhtml+xml"&&ol[y]):!1},Lt=function(d){po(t.removed,{element:d});try{_(d).removeChild(d)}catch{if(p(d),!_(d))throw Mt("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},cp=function(d,y,C){try{h(d,y)}catch{try{d.removeAttribute(C)}catch{}}},ll=function(d){ul(d);let y=g(d);y&&Pt(mk(y),N=>{try{p(N)}catch{}});let C=x(d)===Re.element?k(d):null;if(C)for(let N=C.length-1;N>=0;--N){let H=C[N],Z=H&&H.name;typeof Z=="string"&&cp(d,H,Z)}},Ln=function(d,y,C){if(!C)try{C=y.getAttributeNode(d)}catch{C=null}po(t.removed,{attribute:C||null,from:y});try{C?h(y,C):y.removeAttribute(d)}catch{try{y.removeAttribute(d)}catch{}}if(d==="is")if(On||No)try{Lt(y)}catch{}else try{y.setAttribute(d,"")}catch{}},up=function(d){let y=k(d);if(y)for(let C=y.length-1;C>=0;--C){let N=y[C],H=N&&N.name;typeof H!="string"||ye[Ae(H)]||cp(d,N,H)}},cl=function(d,y){let C=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1,N=[d];for(;N.length>0;){let H=N.pop();if(y(H)===!1)continue;if(C&&x(H)===Re.element){let K=b(H);Dt(K)&&N.push(K)}let Z=g(H);if(Z)for(let K=Z.length-1;K>=0;--K)N.push(Z[K])}},ul=function(d){cl(d,y=>{x(y)===Re.element&&up(y)})},dl=function(d){let y=[];return cl(d,C=>{y.push(C)},!0),y},gE=function(d,y){let C=dd();Pt(dl(d),N=>{x(N)===Re.element&&pd(C,N)}),Pt(y,N=>{x(N)===Re.element&&!ho(C,N)&&up(N)})},dp=function(d,y){let C=!1;return Pt(t.removed,N=>{N.element&&(C=C||N.element===d,ul(N.element))}),gE(d,y),C},vE=8,bE=function(d,y){let C=Jt,N=null,H=()=>(N||(N=dd(),Pt(y,Z=>{pd(N,Z)})),N);for(let Z=0;;Z++){let K=dl(d),Ne=[d],vt=!1;if(Pt(K,Be=>{x(Be)===Re.documentFragment?po(Ne,Be):!vt&&!ho(C,Be)&&(vt=ho(H(),Be))}),!vt)return;if(Z>=vE)throw Mt("the tree kept changing during in-place sanitization; refusing to return it");Pt(Ne,(Be,We)=>{yE(Be,We>0,d,H())})}},yE=function(d,y,C,N){let H=pl(d),Z;for(;Z=H.nextNode();)!ho(N,Z)||ho(Jt,Z)||(y&&at(me.uponSanitizeShadowNode,Z,null),fl(Z,C),ml(Z,C),Dt(Z.content)&&xr(Z.content))},wE=function(d){Jt&&pd(Jt,d)},pp=function(d,y){return Xt?d==="patchsrc"?!0:d==="for"&&y!=="label"&&y!=="output":!1},EE=function(d){Xt&&cl(d,y=>{let C=x(y);if(C===Re.processingInstruction||C===Re.comment&&He(Jy,y.data)){try{p(y)}catch{}return!1}if(C===Re.element){let N=y,H=Ae(I(y));try{N.hasAttribute&&N.hasAttribute("patchsrc")&&N.removeAttribute("patchsrc"),N.hasAttribute&&N.hasAttribute("for")&&pp("for",H)&&N.removeAttribute("for")}catch{}}return!0})},hp=function(d){let y=null,C=null;if(el)d="<remove></remove>"+d;else{let Z=By(d,/^[\r\n\t ]+/);C=Z&&Z[0]}wr==="application/xhtml+xml"&&Mn===gt&&(d='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+d+"</body></html>");let N=X?Nn(d):d;if(Mn===gt)try{y=new c().parseFromString(N,wr)}catch{}if(!y||!y.documentElement){y=qs.createDocument(Mn,"template",null);try{y.documentElement.innerHTML=rl?Ce:N}catch{}}let H=y.body||y.documentElement;return d&&C&&H.insertBefore(n.createTextNode(C),H.childNodes[0]||null),Mn===gt?Jw.call(y,Kt?"html":"body")[0]:Kt?y.documentElement:H},pl=function(d){let y=S?S(d):d.ownerDocument;return Zd.call(y||d,d,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},zo=function(d){return d=fo(d,eE," "),d=fo(d,tE," "),d=fo(d,nE," "),d},hl=function(d){var y;fp(d);let C=(y=d.querySelectorAll)===null||y===void 0?void 0:y.call(d,"template");C&&Pt(C,N=>{Dt(N.content)&&hl(N.content)})},fp=function(d){d.normalize();let y=S?S(d):d.ownerDocument,C=Zd.call(y||d,d,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null),N=C.nextNode();for(;N;)N.data=zo(N.data),N=C.nextNode()},Lo=function(d){let y=w?w(d):null;return typeof y!="string"||Ae(y)!=="form"?!1:typeof d.nodeName!="string"||typeof d.textContent!="string"||typeof d.removeChild!="function"||d.attributes!==k(d)||typeof d.removeAttribute!="function"||typeof d.removeAttributeNode!="function"||typeof d.getAttributeNode!="function"||typeof d.setAttribute!="function"||typeof d.namespaceURI!="string"||typeof d.insertBefore!="function"||typeof d.hasChildNodes!="function"||d.nodeType!==O(d)||d.childNodes!==g(d)},Dt=function(d){if(!O||typeof d!="object"||d===null)return!1;try{return O(d)===Re.documentFragment}catch{return!1}},Er=function(d){if(!O||typeof d!="object"||d===null)return!1;try{return typeof O(d)=="number"}catch{return!1}};function at(P,d,y){P.length!==0&&Pt(P,C=>{C.call(t,d,y,zn)})}let xE=function(d,y){return!!(Xt&&d.hasChildNodes()&&!Er(d.firstElementChild)&&He(bd,d.textContent)&&He(bd,d.innerHTML)||Xt&&Lk[y]&&x(d)===Re.element&&Y(d)===gt&&(Er(d.firstElementChild)||typeof d.textContent=="string"&&He(bd,d.textContent))||d.nodeType===Re.processingInstruction||Xt&&d.nodeType===Re.comment&&He(Jy,d.data))},Do=function(d,y){if(d instanceof RegExp)return He(d,y);if(d instanceof Function){for(var C=arguments.length,N=new Array(C>2?C-2:0),H=2;H<C;H++)N[H-2]=arguments[H];return!!d(y,...N)}return!1},_E=function(d,y,C){if(!yr[y]&&vp(y)&&Do(mt.tagNameCheck,y))return!1;if(tl&&!Qt[y]&&!Qt[An(y)]){let N=_(d),H=g(d);if(H&&N){let Z=H.length;for(let K=Z-1;K>=0;--K){let Ne=d===C?m(H[K],!0):H[K];N.insertBefore(Ne,E(d))}}}return Lt(d),!0},mp=function(d,y,C,N){return d.length===0?y:y===C||y===N?et(y):y},Dn=function(d,y){return d===y||_(d)!==null?!1:(nl&&ul(d),!0)},fl=function(d,y){if(wE(d),at(me.beforeSanitizeElements,d,null),Dn(d,y))return!0;if(Lo(d))return Lt(d),!0;let C=Ae(I(d));if(be=mp(me.uponSanitizeElement,be,Ys,Ro),at(me.uponSanitizeElement,d,{tagName:C,allowedTags:be}),Dn(d,y))return!0;if(xE(d,C))return Lt(d),!0;if(yr[C]||!(zt.tagCheck instanceof Function&&zt.tagCheck(C))&&!be[C]){let N=_E(d,C,y);return N===!1&&(at(me.afterSanitizeElements,d,null),Dn(d,y))?!0:N}if(x(d)===Re.element&&!mE(d)||(C==="noscript"||C==="noembed"||C==="noframes")&&He(zk,d.innerHTML))return Lt(d),!0;if(kt&&d.nodeType===Re.text){let N=zo(d.textContent);d.textContent!==N&&(po(t.removed,{element:d.cloneNode()}),d.textContent=N)}return at(me.afterSanitizeElements,d,null),Dn(d,y)},gp=function(d,y,C){if(Wd[y]||pp(y,d)||Xd&&(y==="id"||y==="name")&&(C in n||C in dE))return!1;let N=ye[y]||zt.attributeCheck instanceof Function&&zt.attributeCheck(y,d);return Ks&&He(rE,y)||qd&&He(oE,y)?!0:N?np[y]||He(jd,fo(C,Vd,""))||(y==="src"||y==="xlink:href"||y==="href")&&d!=="script"&&Zy(C,"data:")===0&&ep[d]||Yd&&!He(iE,fo(C,Vd,""))?!0:!C:vp(d)&&Do(mt.tagNameCheck,d)&&Do(mt.attributeNameCheck,y,d)||y==="is"&&mt.allowCustomizedBuiltInElements&&Do(mt.tagNameCheck,C)},SE=oe({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),vp=function(d){return!SE[An(d)]&&He(aE,d)},TE=function(d,y,C,N){if(X&&typeof u=="object"&&typeof u.getAttributeType=="function"&&!C)switch(u.getAttributeType(d,y)){case"TrustedHTML":return Nn(N);case"TrustedScriptURL":return Yw(N)}return N},AE=function(d,y,C,N){try{return C?d.setAttributeNS(C,y,N):d.setAttribute(y,N),Lo(d)?(Lt(d),!1):!0}catch{return Ln(y,d),!1}},bp=function(d,y){return Xt&&He(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,y)?!0:An(d)==="attributename"&&By(y,"href")!==null},ml=function(d,y){if(at(me.beforeSanitizeAttributes,d,null),Dn(d,y))return;let C=d.attributes;if(!C||Lo(d))return;ye=mp(me.uponSanitizeAttribute,ye,Xs,Co);let N={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ye,forceKeepAttr:void 0},H=C.length,Z=Ae(d.nodeName);for(;H--;){let K=C[H],Ne=K.name,vt=K.namespaceURI,Be=K.value,We=Ae(Ne),$n=Be,qe=Ne==="value"?$n:vk($n),yp=!1;if(N.attrName=We,N.attrValue=qe,N.keepAttr=!0,N.forceKeepAttr=void 0,at(me.uponSanitizeAttribute,d,N),qe=N.attrValue,Kd&&(We==="id"||We==="name")&&Zy(qe,Jd)!==0&&(Ln(Ne,d,K),qe=Jd+qe,yp=!0),bp(Ne,qe)){Ln(Ne,d,K);continue}if(!N.forceKeepAttr){if(!N.keepAttr){Ln(Ne,d,K);continue}if(!Js&&He(Qy,qe)){Ln(Ne,d,K);continue}if(kt&&(qe=zo(qe)),!gp(Z,We,qe)){Ln(Ne,d,K);continue}qe=TE(Z,We,vt,qe),qe!==$n&&AE(d,Ne,vt,qe)&&yp&&Gy(t.removed)}}at(me.afterSanitizeAttributes,d,null),Dn(d,y)},xr=function(d){let y=null,C=pl(d);for(at(me.beforeSanitizeShadowDOM,d,null);y=C.nextNode();)if(at(me.uponSanitizeShadowNode,y,null),fl(y,d),ml(y,d),Dt(y.content)&&xr(y.content),x(y)===Re.element){let N=b(y);Dt(N)&&(gl(N),xr(N))}kt&&fp(d),at(me.afterSanitizeShadowDOM,d,null)},gl=function(d){let y=[{node:d,shadow:null}];for(;y.length>0;){let C=y.pop();if(C.shadow){xr(C.shadow);continue}let N=C.node,H=x(N)===Re.element,Z=g(N);if(Z)for(let K=Z.length-1;K>=0;--K)y.push({node:Z[K],shadow:null});if(H){let K=w?w(N):null;if(typeof K=="string"&&Ae(K)==="template"){let Ne=N.content;Dt(Ne)&&y.push({node:Ne,shadow:null})}}if(H){let K=b(N);Dt(K)&&y.push({node:null,shadow:K},{node:K,shadow:null})}}};return t.sanitize=function(P){let d=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},y=null,C=null,N=null,H=null;if(rl=!P,rl&&(P="<!-->"),typeof P!="string"&&!Er(P)&&(P=Ek(P),typeof P!="string"))throw Mt("dirty is not a string, aborting");if(!t.isSupported)return P;Qs?(be=Ro,ye=Co):sl(d),(me.uponSanitizeElement.length>0||me.uponSanitizeAttribute.length>0)&&(be=et(be)),me.uponSanitizeAttribute.length>0&&(ye=et(ye)),t.removed=[];let Z=nl&&typeof P!="string"&&Er(P),K=[],Ne=Jt;if(Z){EE(P);let We=I(P);if(typeof We=="string"){let $n=Ae(We);if(!be[$n]||yr[$n])throw ll(P),Mt("root node is forbidden and cannot be sanitized in-place")}if(Lo(P))throw ll(P),Mt("root node is clobbered and cannot be sanitized in-place");K=dl(P),Jt=dd()}else if(Er(P))y=hp("<!---->"),C=y.ownerDocument.importNode(P,!0),C.nodeType===Re.element&&C.nodeName==="BODY"||C.nodeName==="HTML"?y=C:y.appendChild(C),gl(y);else{if(!On&&!kt&&!Kt&&P.indexOf("<")===-1)return X&&Oo?Nn(P):P;if(y=hp(P),!y)return On?null:Oo?Ce:""}y&&el&&Lt(y.firstChild);let vt=Z?P:y;try{Z&&gl(P);let We=pl(vt);for(;N=We.nextNode();)fl(N,vt),ml(N,vt),Dt(N.content)&&xr(N.content);Z&&bE(P,K)}catch(We){throw Z&&(ll(P),dp(P,K)),We}finally{Jt=Ne}if(Z){if(dp(P,K))throw Mt("a node selected for removal could not be safely returned; refusing to sanitize in place");return kt&&hl(P),P}if(On){if(kt&&hl(y),No)for(H=Kw.call(y.ownerDocument);y.firstChild;)H.appendChild(y.firstChild);else H=y;return(ye.shadowroot||ye.shadowrootmode)&&(H=Qw.call(r,H,!0)),H}let Be=Kt?y.outerHTML:y.innerHTML;return Kt&&be["!doctype"]&&y.ownerDocument&&y.ownerDocument.doctype&&y.ownerDocument.doctype.name&&He(Pk,y.ownerDocument.doctype.name)&&(Be="<!DOCTYPE "+y.ownerDocument.doctype.name+`>
|
|
4526
|
-
`+
|
|
4527
|
-
]`).replace("lheading",
|
|
4528
|
-
`),n=
|
|
4529
|
-
`)}function
|
|
4766
|
+
`).trim()}var gk=1500;function bd(t,e){if(Ky(t)!==null)return;let n=Cs(t,e.strings),r=e.text;r!==void 0&&n.appendChild(vk(e.strings,r,e.html)),e.onFeedback!==void 0&&n.append(Yy("up",e.strings.feedbackUp,e.onFeedback),Yy("down",e.strings.feedbackDown,e.onFeedback))}function Cs(t,e){let n=Ky(t);if(n!==null)return n;let r=document.createElement("div");return r.className="message-actions",r.setAttribute("part","message-actions"),r.setAttribute("role","group"),r.setAttribute("aria-label",e.messageActions),t.after(r),r}function Ky(t){let e=t.nextElementSibling;return e?.classList.contains("message-actions")===!0?e:null}function Ns(t,e,n){let r=document.createElement("button");r.type="button",r.className=`message-action message-action--${t}`,r.setAttribute("part",`message-action message-action-${t}`),vd(r,e);let o=document.createElement("span");return o.className="message-action-icon",o.setAttribute("part",`message-action-icon message-action-icon-${t}`),o.setAttribute("aria-hidden","true"),o.innerHTML=n,r.appendChild(o),r}function vd(t,e){t.title=e,t.setAttribute("aria-label",e),t.dataset.tooltip=e}function vk(t,e,n){let r=Ns("copy",t.copyMessage,zp);return r.addEventListener("click",()=>{bk(e(),n?.()).then(o=>{yk(r,o?t.copied:t.copyFailed,t.copyMessage)})}),r}async function bk(t,e){let n=navigator.clipboard;if(n===void 0)return!1;if(e!==void 0&&typeof ClipboardItem=="function")try{return await n.write([new ClipboardItem({"text/plain":new Blob([t],{type:"text/plain"}),"text/html":new Blob([e],{type:"text/html"})})]),!0}catch{}try{return await n.writeText(t),!0}catch{return!1}}function Yy(t,e,n){let r=Ns(t==="up"?"up":"down",e,t==="up"?$p:Up);return r.addEventListener("click",()=>{let o=r.getAttribute("aria-pressed")==="true";r.setAttribute("aria-pressed",o?"false":"true"),n(t)}),r.setAttribute("aria-pressed","false"),r}function yk(t,e,n){vd(t,e),t.classList.add("message-action--confirmed"),setTimeout(()=>{vd(t,n),t.classList.remove("message-action--confirmed")},gk)}var Os=class{#e;#t=null;constructor(e){this.#e=e}forget(){this.#t=null}attach(e,n){let r=this.#o(),o=r.has(rn.COPY),i="messageId"in n?n:null,a=i!==null&&r.has(rn.FEEDBACK),s=this.#e.threadId();(o||a)&&bd(e,{strings:this.#e.strings(),...o?{text:()=>Rs(e).text,html:()=>Rs(e).html}:{},...a?{onFeedback:c=>{this.#e.element.dispatchEvent(new CustomEvent(Pl,{detail:{content:Rs(e).text,rating:c,messageId:i.messageId,threadId:s,...i.runId===void 0?{}:{runId:i.runId}},bubbles:!0,composed:!0}))}}:{}}),r.has(rn.RETRY)&&this.#n(Cs(e,this.#e.strings()))}#n(e){this.#t?.querySelector(".message-action--retry")?.remove();let n=Ns("retry",this.#e.strings().retryMessage,Dp);n.addEventListener("click",()=>{this.#e.retry()}),e.prepend(n),this.#t=e}#o(){let e=this.#e.element.getAttribute("data-message-actions");return e===null?new Set([rn.COPY,rn.RETRY]):new Set(pr(e))}};function wk(t,e){this.v=t,this.k=e}function Xy(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function Ek(t){if(Array.isArray(t))return t}function xk(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r,o,i,a,s=[],c=!0,l=!1;try{if(i=(n=n.call(t)).next,e===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=i.call(n)).done)&&(s.push(r.value),s.length!==e);c=!0);}catch(u){l=!0,o=u}finally{try{if(!c&&n.return!=null&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw o}}return s}}function _k(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
4767
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Sk(t,e){return Ek(t)||xk(t,e)||Tk(t,e)||_k()}function Tk(t,e){if(t){if(typeof t=="string")return Xy(t,e);var n={}.toString.call(t).slice(8,-1);return n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set"?Array.from(t):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Xy(t,e):void 0}}function Ps(t){var e,n;function r(i,a){try{var s=t[i](a),c=s.value,l=c instanceof wk;Promise.resolve(l?c.v:c).then(function(u){if(l){var f=i==="return"&&c.k?i:"next";if(!c.k||u.done)return r(f,u);u=t[f](u).value}o(!!s.done,u)},function(u){r("throw",u)})}catch(u){o(2,u)}}function o(i,a){i===2?e.reject(a):e.resolve({value:a,done:i}),(e=e.next)?r(e.key,e.arg):n=null}this._invoke=function(i,a){return new Promise(function(s,c){var l={key:i,arg:a,resolve:s,reject:c,next:null};n?n=n.next=l:(e=n=l,r(i,a))})},typeof t.return!="function"&&(this.return=void 0)}Ps.prototype[typeof Symbol=="function"&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},Ps.prototype.next=function(t){return this._invoke("next",t)},Ps.prototype.throw=function(t){return this._invoke("throw",t)},Ps.prototype.return=function(t){return this._invoke("return",t)};var pw=Object.entries,Jy=Object.setPrototypeOf,Ak=Object.isFrozen,hw=Object.getPrototypeOf,fw=Object.getOwnPropertyDescriptor,Le=Object.freeze,Ge=Object.seal,mr=Object.create,mw=typeof Reflect<"u"&&Reflect,Id=mw.apply,Rd=mw.construct;Le||(Le=function(e){return e});Ge||(Ge=function(e){return e});Id||(Id=function(e,n){for(var r=arguments.length,o=new Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];return e.apply(n,o)});Rd||(Rd=function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return new e(...r)});var zt=Te(Array.prototype.forEach);Array.prototype.indexOf;var kk=Te(Array.prototype.lastIndexOf),Qy=Te(Array.prototype.pop),vo=Te(Array.prototype.push),Ik=Te(Array.prototype.slice),Rk=Te(Array.prototype.splice),gr=Array.isArray,yd=gw(Set),wd=Te(Set.prototype.add),bo=Te(Set.prototype.has),Cn=Te(String.prototype.toLowerCase),Ed=Te(String.prototype.toString),ew=Te(String.prototype.match),yo=Te(String.prototype.replace),tw=Te(String.prototype.indexOf),Ck=Te(String.prototype.trim),Nk=Te(Number.prototype.toString),Ok=Te(Boolean.prototype.toString),nw=typeof BigInt>"u"?null:Te(BigInt.prototype.toString),rw=typeof Symbol>"u"?null:Te(Symbol.prototype.toString),Ke=Te(Object.prototype.hasOwnProperty),wo=Te(Object.prototype.toString),Fe=Te(RegExp.prototype.test),Dt=gw(TypeError);function Te(t){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return Id(t,e,r)}}function gw(t){return function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return Rd(t,n)}}function ie(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Cn;if(Jy&&Jy(t,null),!gr(e))return t;let r=e.length;for(;r--;){let o=e[r];if(typeof o=="string"){let i=n(o);i!==o&&(Ak(e)||(e[r]=i),o=i)}t[o]=!0}return t}function Pk(t){for(let e=0;e<t.length;e++)Ke(t,e)||(t[e]=null);return t}function tt(t){let e=mr(null);for(let r of pw(t)){var n=Sk(r,2);let o=n[0],i=n[1];Ke(t,o)&&(gr(i)?e[o]=Pk(i):i&&typeof i=="object"&&i.constructor===Object?e[o]=tt(i):e[o]=i)}return e}function Mk(t){switch(typeof t){case"string":return t;case"number":return Nk(t);case"boolean":return Ok(t);case"bigint":return nw?nw(t):"0";case"symbol":return rw?rw(t):"Symbol()";case"undefined":return wo(t);case"function":case"object":{if(t===null)return wo(t);let e=t,n=at(e,"toString");if(typeof n=="function"){let r=n(e);return typeof r=="string"?r:wo(r)}return wo(t)}default:return wo(t)}}function at(t,e){for(;t!==null;){let r=fw(t,e);if(r){if(r.get)return Te(r.get);if(typeof r.value=="function")return Te(r.value)}t=hw(t)}function n(){return null}return n}function Lk(t,e){for(;t!==null;){let n=fw(t,e);if(n)return n.get?Te(n.get):null;t=hw(t)}return null}function zk(t){try{return Fe(t,""),!0}catch{return!1}}var ow=Le(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),xd=Le(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),_d=Le(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),Dk=Le(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),Sd=Le(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),$k=Le(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),iw=Le(["#text"]),aw=Le(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),Td=Le(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dominant-baseline","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","pointer-events","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-orientation","text-rendering","textlength","type","u1","u2","unicode","values","vector-effect","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),sw=Le(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),Ms=Le(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),Uk=Ge(/{{[\w\W]*|^[\w\W]*}}/g),Hk=Ge(/<%[\w\W]*|^[\w\W]*%>/g),Fk=Ge(/\${[\w\W]*/g),Gk=Ge(/^data-[\-\w.\u00B7-\uFFFF]+$/),Bk=Ge(/^aria-[\-\w]+$/),lw=Ge(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Zk=Ge(/^(?:\w+script|data):/i),Vk=Ge(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),jk=Ge(/^html$/i),Wk=Ge(/^[a-z][.\w]*(-[.\w]+)+$/i),Ad=Ge(/<[/\w!]/g),cw=Ge(/<[/\w]/g),qk=Ge(/<\/no(script|embed|frames)/i),uw=Ge(/\/>/i),Ce={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Yk=Le(ie({},["style","script","xmp","iframe","noembed","noframes","plaintext","noscript"])),Kk=function(){return typeof window>"u"?null:window},Xk=function(e,n){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let r=null,o="data-tt-policy-suffix";n&&n.hasAttribute(o)&&(r=n.getAttribute(o));let i="dompurify"+(r?"#"+r:"");try{return e.createPolicy(i,{createHTML(a){return a},createScriptURL(a){return a}})}catch{return console.warn("TrustedTypes policy "+i+" could not be created."),null}},dw=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Xt=function(e,n,r,o){return Ke(e,n)&&gr(e[n])?ie(o.base?tt(o.base):{},e[n],o.transform):r},kd=function(e,n,r){let o=Ke(e,n)?e[n]:void 0;return o&&typeof o=="object"?tt(o):r()};function vw(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Kk(),e=P=>vw(P);if(e.version="3.4.17",e.removed=[],!t||!t.document||t.document.nodeType!==Ce.document||!t.Element)return e.isSupported=!1,e;let n=t.document,r=n,o=r.currentScript;t.DocumentFragment;let i=t.HTMLTemplateElement,a=t.Node,s=t.Element,c=t.NodeFilter;t.NamedNodeMap===void 0&&(t.NamedNodeMap||t.MozNamedAttrMap),t.HTMLFormElement;let l=t.DOMParser,u=t.trustedTypes,f=s.prototype,m=at(f,"cloneNode"),p=at(f,"remove"),h=at(f,"removeAttributeNode"),x=at(f,"nextSibling"),g=at(f,"childNodes"),w=at(f,"parentNode"),b=at(f,"shadowRoot"),k=at(f,"attributes"),O=a&&a.prototype?at(a.prototype,"nodeType"):null,E=a&&a.prototype?at(a.prototype,"nodeName"):null,S=a&&a.prototype?at(a.prototype,"ownerDocument"):null,_=function(d){return O?O(d):d.nodeType},I=function(d){return E?E(d):d.nodeName},L=Lk(f,"namespaceURI"),Y=function(d){return L?L(d):d.namespaceURI};if(typeof i=="function"){let P=n.createElement("template");P.content&&P.content.ownerDocument&&(n=P.content.ownerDocument)}let X,Ne="",Qs,Kd=!1,wr=0,Xd=function(){if(wr>0)throw Dt('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},Ln=function(d){Xd(),wr++;try{return X.createHTML(d)}finally{wr--}},sE=function(d){Xd(),wr++;try{return X.createScriptURL(d)}finally{wr--}},lE=function(){return Kd||(Qs=Xk(u,o),Kd=!0),Qs},Po=n,el=Po.implementation,Jd=Po.createNodeIterator,cE=Po.createDocumentFragment,uE=Po.getElementsByTagName,dE=r.importNode,ge=dw();e.isSupported=typeof pw=="function"&&typeof w=="function"&&el&&el.createHTMLDocument!==void 0;let pE=Uk,hE=Hk,fE=Fk,mE=Gk,gE=Bk,vE=Zk,Qd=Vk,bE=Wk,ep=lw,ye=null,tl=ie({},[...ow,...xd,..._d,...Sd,...iw]),we=null,nl=ie({},[...aw,...Td,...sw,...Ms]),gt=Object.seal(mr(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),Er=null,tp=null,$t=Object.seal(mr(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),np=!0,rl=!0,rp=!1,ol=!0,Rt=!1,Qt=!0,en=!1,il=!1,Mo=null,Lo=null,al=!1,zn=!1,zo=!1,Do=!1,op=!0,ip=!1,ap="user-content-",sl=!0,ll=!1,tn=null,Dn={},nn=null,sp=ie({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]),lp=null,cp=ie({},["audio","video","img","source","image","track"]),up=null,dp=ie({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),$o="http://www.w3.org/1998/Math/MathML",Uo="http://www.w3.org/2000/svg",vt="http://www.w3.org/1999/xhtml",$n=vt,cl=!1,ul=null,yE=ie({},[$o,Uo,vt],Ed),pp=Le(["mi","mo","mn","ms","mtext"]),dl=ie({},pp),hp=Le(["annotation-xml"]),pl=ie({},hp),wE=ie({},["title","style","font","a","script"]),xr=null,EE=["application/xhtml+xml","text/html"],xE="text/html",ke=null,Un=null,_E=n.createElement("form"),fp=function(d){return d instanceof RegExp||d instanceof Function},hl=function(){let d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Un&&Un===d)return;(!d||typeof d!="object")&&(d={}),d=tt(d),xr=EE.indexOf(d.PARSER_MEDIA_TYPE)===-1?xE:d.PARSER_MEDIA_TYPE,ke=xr==="application/xhtml+xml"?Ed:Cn,ye=Xt(d,"ALLOWED_TAGS",tl,{transform:ke}),we=Xt(d,"ALLOWED_ATTR",nl,{transform:ke}),ul=Xt(d,"ALLOWED_NAMESPACES",yE,{transform:Ed}),up=Xt(d,"ADD_URI_SAFE_ATTR",dp,{transform:ke,base:dp}),lp=Xt(d,"ADD_DATA_URI_TAGS",cp,{transform:ke,base:cp}),nn=Xt(d,"FORBID_CONTENTS",sp,{transform:ke}),Er=Xt(d,"FORBID_TAGS",tt({}),{transform:ke}),tp=Xt(d,"FORBID_ATTR",tt({}),{transform:ke}),Dn=Ke(d,"USE_PROFILES")?d.USE_PROFILES&&typeof d.USE_PROFILES=="object"?tt(d.USE_PROFILES):d.USE_PROFILES:!1,np=d.ALLOW_ARIA_ATTR!==!1,rl=d.ALLOW_DATA_ATTR!==!1,rp=d.ALLOW_UNKNOWN_PROTOCOLS||!1,ol=d.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Rt=d.SAFE_FOR_TEMPLATES||!1,Qt=d.SAFE_FOR_XML!==!1,en=d.WHOLE_DOCUMENT||!1,zn=d.RETURN_DOM||!1,zo=d.RETURN_DOM_FRAGMENT||!1,Do=d.RETURN_TRUSTED_TYPE||!1,al=d.FORCE_BODY||!1,op=d.SANITIZE_DOM!==!1,ip=d.SANITIZE_NAMED_PROPS||!1,sl=d.KEEP_CONTENT!==!1,ll=d.IN_PLACE||!1,ep=zk(d.ALLOWED_URI_REGEXP)?d.ALLOWED_URI_REGEXP:lw,$n=typeof d.NAMESPACE=="string"?d.NAMESPACE:vt,dl=kd(d,"MATHML_TEXT_INTEGRATION_POINTS",()=>ie({},pp)),pl=kd(d,"HTML_INTEGRATION_POINTS",()=>ie({},hp));let y=kd(d,"CUSTOM_ELEMENT_HANDLING",()=>mr(null));if(gt=mr(null),Ke(y,"tagNameCheck")&&fp(y.tagNameCheck)&&(gt.tagNameCheck=y.tagNameCheck),Ke(y,"attributeNameCheck")&&fp(y.attributeNameCheck)&&(gt.attributeNameCheck=y.attributeNameCheck),Ke(y,"allowCustomizedBuiltInElements")&&typeof y.allowCustomizedBuiltInElements=="boolean"&&(gt.allowCustomizedBuiltInElements=y.allowCustomizedBuiltInElements),Ge(gt),Rt&&(rl=!1),zo&&(zn=!0),Dn&&(ye=ie({},iw),we=mr(null),Dn.html===!0&&(ie(ye,ow),ie(we,aw)),Dn.svg===!0&&(ie(ye,xd),ie(we,Td),ie(we,Ms)),Dn.svgFilters===!0&&(ie(ye,_d),ie(we,Td),ie(we,Ms)),Dn.mathMl===!0&&(ie(ye,Sd),ie(we,sw),ie(we,Ms))),$t.tagCheck=null,$t.attributeCheck=null,Ke(d,"ADD_TAGS")&&(typeof d.ADD_TAGS=="function"?$t.tagCheck=d.ADD_TAGS:gr(d.ADD_TAGS)&&(ye===tl&&(ye=tt(ye)),ie(ye,d.ADD_TAGS,ke))),Ke(d,"ADD_ATTR")&&(typeof d.ADD_ATTR=="function"?$t.attributeCheck=d.ADD_ATTR:gr(d.ADD_ATTR)&&(we===nl&&(we=tt(we)),ie(we,d.ADD_ATTR,ke))),Ke(d,"ADD_FORBID_CONTENTS")&&gr(d.ADD_FORBID_CONTENTS)&&(nn===sp&&(nn=tt(nn)),ie(nn,d.ADD_FORBID_CONTENTS,ke)),sl&&(ye["#text"]=!0),en&&ie(ye,["html","head","body"]),ye.table&&(ie(ye,["tbody"]),delete Er.tbody),d.TRUSTED_TYPES_POLICY){if(typeof d.TRUSTED_TYPES_POLICY.createHTML!="function")throw Dt('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof d.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Dt('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');let C=X;X=d.TRUSTED_TYPES_POLICY;try{Ne=Ln("")}catch(N){throw X=C,N}}else d.TRUSTED_TYPES_POLICY===null?(X=void 0,Ne=""):(X===void 0&&(X=lE()),X&&typeof Ne=="string"&&(Ne=Ln("")));Le&&Le(d),Un=d},mp=ie({},[...xd,..._d,...Dk]),gp=ie({},[...Sd,...$k]),SE=function(d,y,C){return y.namespaceURI===vt?d==="svg":y.namespaceURI===$o?d==="svg"&&(C==="annotation-xml"||dl[C]):!!mp[d]},TE=function(d,y,C){return y.namespaceURI===vt?d==="math":y.namespaceURI===Uo?d==="math"&&pl[C]:!!gp[d]},AE=function(d,y,C){return y.namespaceURI===Uo&&!pl[C]||y.namespaceURI===$o&&!dl[C]?!1:!gp[d]&&(wE[d]||!mp[d])},kE=function(d){let y=Y(d),C=Cn(I(d)),N=w(d),H,Z;return N&&_(N)===Ce.element?(H={namespaceURI:Y(N)},Z=Cn(I(N))):(H={namespaceURI:$n},Z="template"),ul[y]?y===Uo?SE(C,H,Z):y===$o?TE(C,H,Z):y===vt?AE(C,H,Z):!!(xr==="application/xhtml+xml"&&ul[y]):!1},Ut=function(d){vo(e.removed,{element:d});try{w(d).removeChild(d)}catch{if(p(d),!w(d))throw Dt("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},vp=function(d,y,C){try{h(d,y)}catch{try{d.removeAttribute(C)}catch{}}},fl=function(d){gl(d);let y=g(d);y&&zt(Ik(y),N=>{try{p(N)}catch{}});let C=_(d)===Ce.element?k(d):null;if(C)for(let N=C.length-1;N>=0;--N){let H=C[N],Z=H&&H.name;typeof Z=="string"&&vp(d,H,Z)}},Hn=function(d,y,C){if(!C)try{C=y.getAttributeNode(d)}catch{C=null}vo(e.removed,{attribute:C||null,from:y});try{C?h(y,C):y.removeAttribute(d)}catch{try{y.removeAttribute(d)}catch{}}if(d==="is")if(zn||zo)try{Ut(y)}catch{}else try{y.setAttribute(d,"")}catch{}},bp=function(d){let y=k(d);if(y)for(let C=y.length-1;C>=0;--C){let N=y[C],H=N&&N.name;typeof H!="string"||we[ke(H)]||vp(d,N,H)}},ml=function(d,y){let C=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1,N=[d];for(;N.length>0;){let H=N.pop();if(y(H)===!1)continue;if(C&&_(H)===Ce.element){let J=b(H);Ht(J)&&N.push(J)}let Z=g(H);if(Z)for(let J=Z.length-1;J>=0;--J)N.push(Z[J])}},gl=function(d){ml(d,y=>{_(y)===Ce.element&&bp(y)})},vl=function(d){let y=[];return ml(d,C=>{y.push(C)},!0),y},IE=function(d,y){let C=yd();zt(vl(d),N=>{_(N)===Ce.element&&wd(C,N)}),zt(y,N=>{_(N)===Ce.element&&!bo(C,N)&&bp(N)})},yp=function(d,y){let C=!1;return zt(e.removed,N=>{N.element&&(C=C||N.element===d,gl(N.element))}),IE(d,y),C},RE=8,CE=function(d,y){let C=tn,N=null,H=()=>(N||(N=yd(),zt(y,Z=>{wd(N,Z)})),N);for(let Z=0;;Z++){let J=vl(d),Oe=[d],bt=!1;if(zt(J,Ze=>{_(Ze)===Ce.documentFragment?vo(Oe,Ze):!bt&&!bo(C,Ze)&&(bt=bo(H(),Ze))}),!bt)return;if(Z>=RE)throw Dt("the tree kept changing during in-place sanitization; refusing to return it");zt(Oe,(Ze,qe)=>{NE(Ze,qe>0,d,H())})}},NE=function(d,y,C,N){let H=bl(d),Z;for(;Z=H.nextNode();)!bo(N,Z)||bo(tn,Z)||(y&&st(ge.uponSanitizeShadowNode,Z,null),wl(Z,C),El(Z,C),Ht(Z.content)&&Sr(Z.content))},OE=function(d){tn&&wd(tn,d)},wp=function(d,y){return Qt?d==="patchsrc"?!0:d==="for"&&y!=="label"&&y!=="output":!1},PE=function(d){Qt&&ml(d,y=>{let C=_(y);if(C===Ce.processingInstruction||C===Ce.comment&&Fe(cw,y.data)){try{p(y)}catch{}return!1}if(C===Ce.element){let N=y,H=ke(I(y));try{N.hasAttribute&&N.hasAttribute("patchsrc")&&N.removeAttribute("patchsrc"),N.hasAttribute&&N.hasAttribute("for")&&wp("for",H)&&N.removeAttribute("for")}catch{}}return!0})},Ep=function(d){let y=null,C=null;if(al)d="<remove></remove>"+d;else{let Z=ew(d,/^[\r\n\t ]+/);C=Z&&Z[0]}xr==="application/xhtml+xml"&&$n===vt&&(d='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+d+"</body></html>");let N=X?Ln(d):d;if($n===vt)try{y=new l().parseFromString(N,xr)}catch{}if(!y||!y.documentElement){y=el.createDocument($n,"template",null);try{y.documentElement.innerHTML=cl?Ne:N}catch{}}let H=y.body||y.documentElement;return d&&C&&H.insertBefore(n.createTextNode(C),H.childNodes[0]||null),$n===vt?uE.call(y,en?"html":"body")[0]:en?y.documentElement:H},bl=function(d){let y=S?S(d):d.ownerDocument;return Jd.call(y||d,d,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Ho=function(d){return d=yo(d,pE," "),d=yo(d,hE," "),d=yo(d,fE," "),d},yl=function(d){var y;xp(d);let C=(y=d.querySelectorAll)===null||y===void 0?void 0:y.call(d,"template");C&&zt(C,N=>{Ht(N.content)&&yl(N.content)})},xp=function(d){d.normalize();let y=S?S(d):d.ownerDocument,C=Jd.call(y||d,d,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),N=C.nextNode();for(;N;)N.data=Ho(N.data),N=C.nextNode()},Fo=function(d){let y=E?E(d):null;return typeof y!="string"||ke(y)!=="form"?!1:typeof d.nodeName!="string"||typeof d.textContent!="string"||typeof d.removeChild!="function"||d.attributes!==k(d)||typeof d.removeAttribute!="function"||typeof d.removeAttributeNode!="function"||typeof d.getAttributeNode!="function"||typeof d.setAttribute!="function"||typeof d.namespaceURI!="string"||typeof d.insertBefore!="function"||typeof d.hasChildNodes!="function"||d.nodeType!==O(d)||d.childNodes!==g(d)},Ht=function(d){if(!O||typeof d!="object"||d===null)return!1;try{return O(d)===Ce.documentFragment}catch{return!1}},_r=function(d){if(!O||typeof d!="object"||d===null)return!1;try{return typeof O(d)=="number"}catch{return!1}};function st(P,d,y){P.length!==0&&zt(P,C=>{C.call(e,d,y,Un)})}let ME=function(d,y){return!!(Qt&&d.hasChildNodes()&&!_r(d.firstElementChild)&&Fe(Ad,d.textContent)&&Fe(Ad,d.innerHTML)||Qt&&Yk[y]&&_(d)===Ce.element&&Y(d)===vt&&(_r(d.firstElementChild)||typeof d.textContent=="string"&&Fe(Ad,d.textContent))||d.nodeType===Ce.processingInstruction||Qt&&d.nodeType===Ce.comment&&Fe(cw,d.data))},Go=function(d,y){if(d instanceof RegExp)return Fe(d,y);if(d instanceof Function){for(var C=arguments.length,N=new Array(C>2?C-2:0),H=2;H<C;H++)N[H-2]=arguments[H];return!!d(y,...N)}return!1},LE=function(d,y,C){if(!Er[y]&&Tp(y)&&Go(gt.tagNameCheck,y))return!1;if(sl&&!nn[y]&&!nn[Cn(y)]){let N=w(d),H=g(d);if(H&&N){let Z=H.length;for(let J=Z-1;J>=0;--J){let Oe=d===C?m(H[J],!0):H[J];N.insertBefore(Oe,x(d))}}}return Ut(d),!0},_p=function(d,y,C,N){return d.length===0?y:y===C||y===N?tt(y):y},Fn=function(d,y){return d===y||w(d)!==null?!1:(ll&&gl(d),!0)},wl=function(d,y){if(OE(d),st(ge.beforeSanitizeElements,d,null),Fn(d,y))return!0;if(Fo(d))return Ut(d),!0;let C=ke(I(d));if(ye=_p(ge.uponSanitizeElement,ye,tl,Mo),st(ge.uponSanitizeElement,d,{tagName:C,allowedTags:ye}),Fn(d,y))return!0;if(ME(d,C))return Ut(d),!0;if(Er[C]||!($t.tagCheck instanceof Function&&$t.tagCheck(C))&&!ye[C]){let N=LE(d,C,y);return N===!1&&(st(ge.afterSanitizeElements,d,null),Fn(d,y))?!0:N}if(_(d)===Ce.element&&!kE(d)||(C==="noscript"||C==="noembed"||C==="noframes")&&Fe(qk,d.innerHTML))return Ut(d),!0;if(Rt&&d.nodeType===Ce.text){let N=Ho(d.textContent);d.textContent!==N&&(vo(e.removed,{element:d.cloneNode()}),d.textContent=N)}return st(ge.afterSanitizeElements,d,null),Fn(d,y)},Sp=function(d,y,C){if(tp[y]||wp(y,d)||op&&(y==="id"||y==="name")&&(C in n||C in _E))return!1;let N=we[y]||$t.attributeCheck instanceof Function&&$t.attributeCheck(y,d);return rl&&Fe(mE,y)||np&&Fe(gE,y)?!0:N?up[y]||Fe(ep,yo(C,Qd,""))||(y==="src"||y==="xlink:href"||y==="href")&&d!=="script"&&tw(C,"data:")===0&&lp[d]||rp&&!Fe(vE,yo(C,Qd,""))?!0:!C:Tp(d)&&Go(gt.tagNameCheck,d)&&Go(gt.attributeNameCheck,y,d)||y==="is"&>.allowCustomizedBuiltInElements&&Go(gt.tagNameCheck,C)},zE=ie({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),Tp=function(d){return!zE[Cn(d)]&&Fe(bE,d)},DE=function(d,y,C,N){if(X&&typeof u=="object"&&typeof u.getAttributeType=="function"&&!C)switch(u.getAttributeType(d,y)){case"TrustedHTML":return Ln(N);case"TrustedScriptURL":return sE(N)}return N},$E=function(d,y,C,N){try{return C?d.setAttributeNS(C,y,N):d.setAttribute(y,N),Fo(d)?(Ut(d),!1):!0}catch{return Hn(y,d),!1}},Ap=function(d,y){return Qt&&Fe(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,y)?!0:Cn(d)==="attributename"&&ew(y,"href")!==null},El=function(d,y){if(st(ge.beforeSanitizeAttributes,d,null),Fn(d,y))return;let C=d.attributes;if(!C||Fo(d))return;we=_p(ge.uponSanitizeAttribute,we,nl,Lo);let N={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:we,forceKeepAttr:void 0},H=C.length,Z=ke(d.nodeName);for(;H--;){let J=C[H],Oe=J.name,bt=J.namespaceURI,Ze=J.value,qe=ke(Oe),Gn=Ze,Ye=Oe==="value"?Gn:Ck(Gn),kp=!1;if(N.attrName=qe,N.attrValue=Ye,N.keepAttr=!0,N.forceKeepAttr=void 0,st(ge.uponSanitizeAttribute,d,N),Ye=N.attrValue,ip&&(qe==="id"||qe==="name")&&tw(Ye,ap)!==0&&(Hn(Oe,d,J),Ye=ap+Ye,kp=!0),Ap(Oe,Ye)){Hn(Oe,d,J);continue}if(!N.forceKeepAttr){if(!N.keepAttr){Hn(Oe,d,J);continue}if(!ol&&Fe(uw,Ye)){Hn(Oe,d,J);continue}if(Rt&&(Ye=Ho(Ye)),!Sp(Z,qe,Ye)){Hn(Oe,d,J);continue}Ye=DE(Z,qe,bt,Ye),Ye!==Gn&&$E(d,Oe,bt,Ye)&&kp&&Qy(e.removed)}}st(ge.afterSanitizeAttributes,d,null),Fn(d,y)},Sr=function(d){let y=null,C=bl(d);for(st(ge.beforeSanitizeShadowDOM,d,null);y=C.nextNode();)if(st(ge.uponSanitizeShadowNode,y,null),wl(y,d),El(y,d),Ht(y.content)&&Sr(y.content),_(y)===Ce.element){let N=b(y);Ht(N)&&(xl(N),Sr(N))}Rt&&xp(d),st(ge.afterSanitizeShadowDOM,d,null)},xl=function(d){let y=[{node:d,shadow:null}];for(;y.length>0;){let C=y.pop();if(C.shadow){Sr(C.shadow);continue}let N=C.node,H=_(N)===Ce.element,Z=g(N);if(Z)for(let J=Z.length-1;J>=0;--J)y.push({node:Z[J],shadow:null});if(H){let J=E?E(N):null;if(typeof J=="string"&&ke(J)==="template"){let Oe=N.content;Ht(Oe)&&y.push({node:Oe,shadow:null})}}if(H){let J=b(N);Ht(J)&&y.push({node:null,shadow:J},{node:J,shadow:null})}}};return e.sanitize=function(P){let d=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},y=null,C=null,N=null,H=null;if(cl=!P,cl&&(P="<!-->"),typeof P!="string"&&!_r(P)&&(P=Mk(P),typeof P!="string"))throw Dt("dirty is not a string, aborting");if(!e.isSupported)return P;il?(ye=Mo,we=Lo):hl(d),(ge.uponSanitizeElement.length>0||ge.uponSanitizeAttribute.length>0)&&(ye=tt(ye)),ge.uponSanitizeAttribute.length>0&&(we=tt(we)),e.removed=[];let Z=ll&&typeof P!="string"&&_r(P),J=[],Oe=tn;if(Z){PE(P);let qe=I(P);if(typeof qe=="string"){let Gn=ke(qe);if(!ye[Gn]||Er[Gn])throw fl(P),Dt("root node is forbidden and cannot be sanitized in-place")}if(Fo(P))throw fl(P),Dt("root node is clobbered and cannot be sanitized in-place");J=vl(P),tn=yd()}else if(_r(P))y=Ep("<!---->"),C=y.ownerDocument.importNode(P,!0),C.nodeType===Ce.element&&C.nodeName==="BODY"||C.nodeName==="HTML"?y=C:y.appendChild(C),xl(y);else{if(!zn&&!Rt&&!en&&P.indexOf("<")===-1)return X&&Do?Ln(P):P;if(y=Ep(P),!y)return zn?null:Do?Ne:""}y&&al&&Ut(y.firstChild);let bt=Z?P:y;try{Z&&xl(P);let qe=bl(bt);for(;N=qe.nextNode();)wl(N,bt),El(N,bt),Ht(N.content)&&Sr(N.content);Z&&CE(P,J)}catch(qe){throw Z&&(fl(P),yp(P,J)),qe}finally{tn=Oe}if(Z){if(yp(P,J))throw Dt("a node selected for removal could not be safely returned; refusing to sanitize in place");return Rt&&yl(P),P}if(zn){if(Rt&&yl(y),zo)for(H=cE.call(y.ownerDocument);y.firstChild;)H.appendChild(y.firstChild);else H=y;return(we.shadowroot||we.shadowrootmode)&&(H=dE.call(r,H,!0)),H}let Ze=en?y.outerHTML:y.innerHTML;return en&&ye["!doctype"]&&y.ownerDocument&&y.ownerDocument.doctype&&y.ownerDocument.doctype.name&&Fe(jk,y.ownerDocument.doctype.name)&&(Ze="<!DOCTYPE "+y.ownerDocument.doctype.name+`>
|
|
4768
|
+
`+Ze),Rt&&(Ze=Ho(Ze)),X&&Do?Ln(Ze):Ze},e.setConfig=function(){let P=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};hl(P),il=!0,Mo=ye,Lo=we},e.clearConfig=function(){Un=null,il=!1,Mo=null,Lo=null,X=Qs,Ne=""},e.isValidAttribute=function(P,d,y){Un||hl({});let C=ke(P),N=ke(d);return typeof y=="string"&&(Ap(d,y)||!ol&&Fe(uw,y))?!1:Sp(C,N,y)},e.addHook=function(P,d){typeof d=="function"&&Ke(ge,P)&&vo(ge[P],d)},e.removeHook=function(P,d){if(Ke(ge,P)){if(d!==void 0){let y=kk(ge[P],d);return y===-1?void 0:Rk(ge[P],y,1)[0]}return Qy(ge[P])}},e.removeHooks=function(P){Ke(ge,P)&&(ge[P]=[])},e.removeAllHooks=function(){ge=dw()},e}var bw=vw();function Md(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Mn=Md();function Rw(t){Mn=t}var On={exec:()=>null};function vr(t){let e=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),o=e[r];return o||(o=t(r),e[r]=o),o}}function q(t,e=""){let n=typeof t=="string"?t:t.source,r={replace:(o,i)=>{let a=typeof i=="string"?i:i.source;return a=a.replace(ze.caret,"$1"),n=n.replace(o,a),r},getRegex:()=>new RegExp(n,e)};return r}var Jk=((t="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+t)}catch{return!1}})(),ze={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/,numericCharacterReferenceOrAmpersand:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:vr(t=>new RegExp(`^ {0,${t}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:vr(t=>new RegExp(`^ {0,${t}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:vr(t=>new RegExp(`^ {0,${t}}(?:\`\`\`|~~~)`)),headingBeginRegex:vr(t=>new RegExp(`^ {0,${t}}#`)),htmlBeginRegex:vr(t=>new RegExp(`^ {0,${t}}(?:</?(?:${So})(?: +|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`,"i")),blockquoteBeginRegex:vr(t=>new RegExp(`^ {0,${t}}>`))},Qk=/^(?:[ \t]*(?:\n|$))+/,eI=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,tI=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,_o=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,nI=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Ld=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Cw=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Nw=q(Cw).replace(/bull/g,Ld).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),rI=q(Cw).replace(/bull/g,Ld).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),zd=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,oI=/^[^\n]+/,Dd=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,iI=q(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Dd).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),aI=q(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,Ld).getRegex(),So="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",$d=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,sI=q("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!(?:script|pre|style|textarea)(?![a-z0-9-]))([a-z][a-z0-9-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",$d).replace("tag",So).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ow=t=>q(zd).replace("hr",_o).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list",t).replace("html"," {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",So).getRegex(),lI=Ow(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),cI=Ow(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),uI=q(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",cI).getRegex(),Ud={blockquote:uI,code:eI,def:iI,fences:tI,heading:nI,hr:_o,html:sI,lheading:Nw,list:aI,newline:Qk,paragraph:lI,table:On,text:oI},yw=q("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",_o).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html"," {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",So).getRegex(),dI={...Ud,lheading:rI,table:yw,paragraph:q(zd).replace("hr",_o).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",yw).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html"," {0,3}(?:</?(?:tag)(?: +|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)").replace("tag",So).getRegex()},pI={...Ud,html:q(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",$d).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:On,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:q(zd).replace("hr",_o).replace("heading",` *#{1,6} *[^
|
|
4769
|
+
]`).replace("lheading",Nw).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},hI=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,fI=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Pw=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,mI=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,It=/[\p{P}\p{S}]/u,br=/[\s\p{P}\p{S}]/u,To=/[^\s\p{P}\p{S}]/u,gI=q(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,br).getRegex(),vI=/[\p{Pi}\p{Ps}"']/u,Mw=/(?!~)[\p{P}\p{S}]/u,bI=/(?!~)[\s\p{P}\p{S}]/u,yI=/(?:[^\s\p{P}\p{S}]|~)/u,wI=q(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Jk?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Lw=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,EI=q(Lw,"u").replace(/punct/g,It).getRegex(),xI=q(Lw,"u").replace(/punct/g,Mw).getRegex(),_I=/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,SI=q(_I,"u").replace(/openQuote/g,vI).replace(/punct/g,It).getRegex(),zw="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",TI=q(zw,"gu").replace(/notPunctSpace/g,To).replace(/punctSpace/g,br).replace(/punct/g,It).getRegex(),AI=q(zw,"gu").replace(/notPunctSpace/g,yI).replace(/punctSpace/g,bI).replace(/punct/g,Mw).getRegex(),kI="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)",II=q(kI,"gu").replace(/notPunctSpace/g,To).replace(/punctSpace/g,br).replace(/punct/g,It).getRegex(),RI=q("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,To).replace(/punctSpace/g,br).replace(/punct/g,It).getRegex(),CI="^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)",NI=q(CI,"gu").replace(/notPunctSpace/g,To).replace(/punctSpace/g,br).replace(/punct/g,It).getRegex(),OI=q(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,It).getRegex(),PI="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",MI=q(PI,"gu").replace(/notPunctSpace/g,To).replace(/punctSpace/g,br).replace(/punct/g,It).getRegex(),LI=q(/\\(punct)/,"gu").replace(/punct/g,It).getRegex(),zI=q(/(`+)(?:[^`]|[^`][\s\S]*?[^`])\1(?!`)|`+|\\(punct)/,"gu").replace(/punct/g,It).getRegex(),DI=q(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),$I=q($d).replace("(?:-->|$)","-->").getRegex(),UI=q("^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",$I).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Dw=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,zs=q(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace("brackets",Dw).getRegex(),HI=q(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace("label",zs).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),FI=q(/^!?\[(label)\]\[(ref)\]/).replace("label",zs).replace("ref",Dd).getRegex(),GI=q(/^!?\[(ref)\](?:\[\])?/).replace("ref",Dd).getRegex(),ww=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,BI=q(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace("brackets",Dw).getRegex(),ZI=q("reflink|nolink(?!\\()","g").replace("reflink",q(/^!?\[(label)\]\[(ref)\]/).replace("label",BI).replace("ref",ww).getRegex()).replace("nolink",q(/^!?\[(ref)\](?:\[\])?/).replace("ref",ww).getRegex()).getRegex(),Ew=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,VI=/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/,jI=q(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,VI).getRegex(),Hd={_backpedal:On,anyPunctuation:LI,anyPunctuationOutsideCode:zI,autolink:DI,blockSkip:wI,br:Pw,code:fI,del:On,delLDelim:On,delRDelim:On,emStrongLDelim:EI,emStrongRDelimAst:TI,emStrongRDelimUnd:RI,escape:hI,link:HI,nolink:GI,punctuation:gI,reflink:FI,reflinkSearch:ZI,tag:UI,text:mI,url:On},WI={...Hd,emStrongLDelim:SI,emStrongRDelimAst:II,emStrongRDelimUnd:NI,link:q(/^!?\[(label)\]\((.*?)\)/).replace("label",zs).getRegex(),reflink:q(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",zs).getRegex()},Nd={...Hd,emStrongRDelimAst:AI,emStrongLDelim:xI,delLDelim:OI,delRDelim:MI,url:q(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("emailProtocol",jI).replace("protocol",Ew).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:q(/^(?:[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace("protocol",Ew).replace(/emailProtocol/g,/(?:mailto|xmpp):/).getRegex()},qI={...Nd,br:q(Pw).replace("{2,}","*").getRegex(),text:q(Nd.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Ls={normal:Ud,gfm:dI,pedantic:pI},Eo={normal:Hd,gfm:Nd,breaks:qI,pedantic:WI},YI={"&":"&","<":"<",">":">",'"':""","'":"'"},xw=t=>YI[t];function nt(t,e){if(e){if(ze.escapeTest.test(t))return t.replace(ze.escapeReplace,xw)}else if(ze.escapeTestNoEncode.test(t))return t.replace(ze.escapeReplaceNoEncode,xw);return t}function KI(t){return ze.numericCharacterReference.test(t)?t.replace(ze.numericCharacterReferenceOrAmpersand,(e,n,r)=>{if(n===void 0&&r===void 0)return"&";let o=n===void 0?Number.parseInt(r,16):Number.parseInt(n,10);return o===0||o>1114111||o>=55296&&o<=57343?"\uFFFD":o===38?"&":String.fromCodePoint(o)}):t}function _w(t){try{t=encodeURI(t).replace(ze.percentDecode,"%")}catch{return null}return t}function Sw(t,e){let n=t.replace(ze.findPipe,(i,a,s)=>{let c=!1,l=a;for(;--l>=0&&s[l]==="\\";)c=!c;return c?"|":" |"}),r=n.split(ze.splitPipe),o=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),e)if(r.length>e)r.splice(e);else for(;r.length<e;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(ze.slashPipe,"|");return r}function Jt(t,e,n){let r=t.length;if(r===0)return"";let o=0;for(;o<r;){let i=t.charAt(r-o-1);if(i===e&&!n)o++;else if(i!==e&&n)o++;else break}return t.slice(0,r-o)}function Tw(t){let e=t.split(`
|
|
4770
|
+
`),n=e.length-1;for(;n>=0&&ze.blankLine.test(e[n]);)n--;return e.length-n<=2?t:e.slice(0,n+1).join(`
|
|
4771
|
+
`)}function Ds(t){return t.trim().toLowerCase().toUpperCase().toLowerCase()}function Aw(t,e){if(t.indexOf(e[0])===-1&&t.indexOf(e[1])===-1)return-1;let n=0;for(let r=0;r<t.length;r++)if(t[r]==="\\")r++;else if(t[r]===e[0])n++;else if(t[r]===e[1]&&(n--,n<0))return r;return n>0?-2:-1}function Cd(t,e=0){let n=e,r="";for(let o of t)if(o===" "){let i=4-n%4;r+=" ".repeat(i),n+=i}else r+=o,n++;return r}function kw(t,e,n,r,o){let i=e.href,a=e.title||null,s=t[1].replace(o.other.outputLinkReplace,"$1"),c=t[0].charAt(0)==="!",l=r.state.inLink,u=r.state.linkEmitted,f=r.state.inRawBlock;r.state.inLink=!0,r.state.linkEmitted=!1;let m=r.inlineTokens(s),p=r.state.linkEmitted;if(r.state.linkEmitted=u,r.state.inLink=l,!c){if(p){r.state.inRawBlock=f;return}r.state.linkEmitted=!0}return{type:c?"image":"link",raw:n,href:i,title:a,text:s,tokens:m}}function XI(t,e,n){let r=t.match(n.other.indentCodeCompensation);if(r===null)return e;let o=r[1];return e.split(`
|
|
4530
4772
|
`).map(i=>{let a=i.match(n.other.beginningSpace);if(a===null)return i;let[s]=a;return i.slice(Math.min(s.length,o.length))}).join(`
|
|
4531
|
-
`)}function
|
|
4532
|
-
`),depth:
|
|
4533
|
-
`)}}blockquote(
|
|
4773
|
+
`)}function Iw(t,e,n,r){if(!e.includes("<"))return!1;for(let o=0;o<e.length;o++){if(e[o]==="\\"){o++;continue}if(e[o]==="`"){let s=r.inline.code.exec(e.slice(o));if(s){o+=s[0].length-1;continue}}if(e[o]!=="<")continue;let i=t.slice(n+o),a=r.inline.tag.exec(i)||r.inline.autolink.exec(i);if(a){if(a[0].length>e.length-o)return!0;o+=a[0].length-1}}return!1}var $s=class{options;rules;lexer;constructor(t){this.options=t||Mn}space(t){let e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){let e=this.rules.block.code.exec(t);if(e){let n=this.options.pedantic?e[0]:Tw(e[0]),r=n.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n,codeBlockStyle:"indented",text:r}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],r=XI(n,e[3]||"",this.rules);return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:r}}}heading(t){let e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(this.rules.other.endingHash.test(n)){let r=Jt(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceTabChar.test(r))&&(n=r.trim())}return{type:"heading",raw:Jt(e[0],`
|
|
4774
|
+
`),depth:e[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(t){let e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:Jt(e[0],`
|
|
4775
|
+
`)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=Jt(e[0],`
|
|
4534
4776
|
`).split(`
|
|
4535
|
-
`),r="",o="",i=[];for(;n.length>0;){let a=!1,s=[],
|
|
4536
|
-
`),u=
|
|
4777
|
+
`),r="",o="",i=[];for(;n.length>0;){let a=!1,s=[],c;for(c=0;c<n.length;c++)if(this.rules.other.blockquoteStart.test(n[c]))s.push(n[c]),a=!0;else if(!a)s.push(n[c]);else break;n=n.slice(c);let l=s.join(`
|
|
4778
|
+
`),u=l.replace(this.rules.other.blockquoteSetextReplace,`
|
|
4537
4779
|
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
|
|
4538
|
-
${
|
|
4780
|
+
${l}`:l,o=o?`${o}
|
|
4539
4781
|
${u}`:u;let f=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(u,i,!0),this.lexer.state.top=f,n.length===0)break;let m=i.at(-1);if(m?.type==="code"||m?.type==="heading"||m?.type==="hr"||m?.type==="html")break;if(m?.type==="blockquote"){let p=m,h=n.join(`
|
|
4540
|
-
`),
|
|
4541
|
-
`+h.replace(this.rules.other.blockquoteSetextReplace2,""),g=this.blockquote(
|
|
4782
|
+
`),x=p.raw+`
|
|
4783
|
+
`+h.replace(this.rules.other.blockquoteSetextReplace2,""),g=this.blockquote(x);i[i.length-1]=g;let w=x.substring(g.raw.length).replace(/^\n/,""),b=w?w.split(`
|
|
4542
4784
|
`).length:0,k=b?n.slice(0,-b):n;k.length>0&&(r=`${r}
|
|
4543
4785
|
${k.join(`
|
|
4544
4786
|
`)}`),o=o.substring(0,o.length-p.text.length)+g.text;break}else if(m?.type==="list"){let p=m,h=p.raw+`
|
|
4545
4787
|
`+n.join(`
|
|
4546
|
-
`),
|
|
4547
|
-
`);continue}}return{type:"blockquote",raw:r,tokens:i,text:o}}}list(
|
|
4548
|
-
`,1)[0],h=
|
|
4549
|
-
`,1)[0],
|
|
4550
|
-
`,1)[0],X;if(g=Y,this.options.pedantic?(g=g.replace(this.rules.other.listReplaceNesting," "),X=g):X=g.replace(this.rules.other.leadingSpaceTab,
|
|
4551
|
-
`+X.slice(b);else{if(
|
|
4552
|
-
`+g}
|
|
4553
|
-
`),href:r,title:o}}}table(
|
|
4554
|
-
`):[],i={type:"table",raw:
|
|
4555
|
-
`),header:[],align:[],rows:[]};if(n.length===r.length){for(let a of r)this.rules.other.tableAlignRight.test(a)?i.align.push("right"):this.rules.other.tableAlignCenter.test(a)?i.align.push("center"):this.rules.other.tableAlignLeft.test(a)?i.align.push("left"):i.align.push(null);for(let a=0;a<n.length;a++)i.header.push({text:n[a],tokens:this.lexer.inline(n[a]),header:!0,align:i.align[a]});for(let a of o)i.rows.push(
|
|
4556
|
-
`),depth:
|
|
4557
|
-
`?
|
|
4558
|
-
`),this.blockTokens(
|
|
4559
|
-
`:n.push(i);continue}if(i=this.tokenizer.code(
|
|
4788
|
+
`),x=this.list(h);i[i.length-1]=x,r=r.substring(0,r.length-m.raw.length)+x.raw,o=o.substring(0,o.length-p.raw.length)+x.raw,n=h.substring(i.at(-1).raw.length).split(`
|
|
4789
|
+
`);continue}}return{type:"blockquote",raw:r,tokens:i,text:o}}}list(t){let e=this.rules.block.list.exec(t);if(e){let n=t,r=()=>n.length-t.length,o=e[1].trim(),i=o.length>1,a={type:"list",raw:"",ordered:i,start:i?+o.slice(0,-1):"",loose:!1,items:[]};o=i?`\\d{1,9}\\${o.slice(-1)}`:`\\${o}`,this.options.pedantic&&(o=i?o:"[*+-]");let s=this.rules.other.listItemRegex(o),c=!1;for(;t;){let u=!1,f="";if(!(e=s.exec(t))||this.rules.block.hr.test(t))break;let m=r();t=t.substring(e[0].length);let p=e[2].split(`
|
|
4790
|
+
`,1)[0],h=e[1].length,x=this.options.pedantic?Cd(p,h):p.replace(this.rules.other.leadingSpaceTab,O=>Cd(O,h)),g=t.split(`
|
|
4791
|
+
`,1)[0],w=!x.trim(),b=0;if(this.options.pedantic?(b=2,f=x.trimStart()):w?b=h+1:(b=x.search(this.rules.other.nonSpaceChar),b=b>4?1:b,f=x.slice(b),b+=h),w&&this.rules.other.blankLine.test(g)&&(t=t.substring(g.length+1),u=!0),!u){let O=this.rules.other.nextBulletRegex(b),E=this.rules.other.hrRegex(b),S=this.rules.other.fencesBeginRegex(b),_=this.rules.other.headingBeginRegex(b),I=this.rules.other.htmlBeginRegex(b),L=this.rules.other.blockquoteBeginRegex(b);for(;t;){let Y=t.split(`
|
|
4792
|
+
`,1)[0],X;if(g=Y,this.options.pedantic?(g=g.replace(this.rules.other.listReplaceNesting," "),X=g):X=g.replace(this.rules.other.leadingSpaceTab,Ne=>Cd(Ne)),S.test(g)||_.test(g)||I.test(g)||L.test(g)||O.test(g)||E.test(g))break;if(X.search(this.rules.other.nonSpaceChar)>=b||!g.trim())f+=`
|
|
4793
|
+
`+X.slice(b);else{if(w||x.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||S.test(x)||_.test(x)||E.test(x))break;f+=`
|
|
4794
|
+
`+g}w=!g.trim(),t=t.substring(Y.length+1),x=X.slice(b)}}let k=n.slice(m,r());a.loose||(c?a.loose=!0:this.rules.other.doubleBlankLine.test(k)&&(c=!0)),a.items.push({type:"list_item",raw:k,task:!!this.options.gfm&&this.rules.other.listIsTask.test(f),loose:!1,text:f,tokens:[]})}let l=a.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;a.raw=n.slice(0,r()).trimEnd();for(let u of a.items)if(this.lexer.state.top=!1,u.tokens=this.lexer.blockTokens(u.text,[]),!a.loose){let f=u.tokens.filter(p=>p.type==="space"),m=f.length>0&&f.some(p=>this.rules.other.anyLine.test(p.raw));a.loose=m}for(let u of a.items){let f=u.tokens[0];if(u.task&&(f?.type==="text"||f?.type==="paragraph")){u.text=u.text.replace(this.rules.other.listReplaceTask,""),f.raw=f.raw.replace(this.rules.other.listReplaceTask,""),f.text=f.text.replace(this.rules.other.listReplaceTask,"");for(let p=this.lexer.inlineQueue.length-1;p>=0;p--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[p].src)){this.lexer.inlineQueue[p].src=this.lexer.inlineQueue[p].src.replace(this.rules.other.listReplaceTask,"");break}let m=this.rules.other.listTaskCheckbox.exec(u.raw);if(m){let p={type:"checkbox",raw:m[0]+" ",checked:m[0]!=="[ ]"};u.checked=p.checked,a.loose?u.tokens[0]&&["paragraph","text"].includes(u.tokens[0].type)&&"tokens"in u.tokens[0]&&u.tokens[0].tokens?(u.tokens[0].raw=p.raw+u.tokens[0].raw,u.tokens[0].text=p.raw+u.tokens[0].text,u.tokens[0].tokens.unshift(p)):u.tokens.unshift({type:"paragraph",raw:p.raw,text:p.raw,tokens:[p]}):u.tokens.unshift(p)}}else u.task&&(u.task=!1)}if(a.loose)for(let u of a.items){u.loose=!0;for(let f of u.tokens)f.type==="text"&&(f.type="paragraph")}return a}}html(t){let e=this.rules.block.html.exec(t);if(e){let n=Tw(e[0]);return{type:"html",block:!0,raw:n,pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:n}}}def(t){let e=this.rules.block.def.exec(t);if(e){if(!this.rules.other.startAngleBracket.test(e[2])&&Aw(e[2],"()")!==-1)return;let n=Ds(e[1]).replace(this.rules.other.multipleSpaceGlobal," "),r=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",o=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:n,raw:Jt(e[0],`
|
|
4795
|
+
`),href:r,title:o}}}table(t){let e=this.rules.block.table.exec(t);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let n=Sw(e[1]),r=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),o=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
4796
|
+
`):[],i={type:"table",raw:Jt(e[0],`
|
|
4797
|
+
`),header:[],align:[],rows:[]};if(n.length===r.length){for(let a of r)this.rules.other.tableAlignRight.test(a)?i.align.push("right"):this.rules.other.tableAlignCenter.test(a)?i.align.push("center"):this.rules.other.tableAlignLeft.test(a)?i.align.push("left"):i.align.push(null);for(let a=0;a<n.length;a++)i.header.push({text:n[a],tokens:this.lexer.inline(n[a]),header:!0,align:i.align[a]});for(let a of o)i.rows.push(Sw(a,i.header.length).map((s,c)=>({text:s,tokens:this.lexer.inline(s),header:!1,align:i.align[c]})));return i}}lheading(t){let e=this.rules.block.lheading.exec(t);if(e){let n=e[1].trim();return{type:"heading",raw:Jt(e[0],`
|
|
4798
|
+
`),depth:e[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(t){let e=this.rules.block.paragraph.exec(t);if(e){let n=e[1].charAt(e[1].length-1)===`
|
|
4799
|
+
`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){let e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){let e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){if(this.lexer.state.linkParenPossible===!1)return;let e=this.rules.inline.link.exec(t);if(e){let n=e[0].charAt(0)==="!"?2:1;if(!this.options.pedantic&&Iw(t,e[1],n,this.rules))return;let r=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(r)){if(!this.rules.other.endAngleBracket.test(r))return;let a=Jt(r.slice(0,-1),"\\");if((r.length-a.length)%2===0)return}else{let a=Aw(e[2],"()");if(a===-2)return;if(a>-1){let s=(e[0].indexOf("!")===0?5:4)+e[1].length+a;e[2]=e[2].substring(0,a),e[0]=e[0].substring(0,s).trim(),e[3]=""}}let o=e[2],i="";if(this.options.pedantic){let a=this.rules.other.pedanticHrefTitle.exec(o);a&&(o=a[1],i=a[3])}else i=e[3]?e[3].slice(1,-1):"";return o=o.trim(),this.rules.other.startAngleBracket.test(o)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(r)?o=o.slice(1):o=o.slice(1,-1)),kw(e,{href:o&&o.replace(this.rules.inline.anyPunctuation,"$1"),title:i&&i.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let n;if((n=this.rules.inline.reflink.exec(t))||(n=this.rules.inline.nolink.exec(t))){let r=n[0].charAt(0)==="!"?2:1;if(!this.options.pedantic&&Iw(t,n[1],r,this.rules))return;let o=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),i=e[Ds(o)];if(!i){let a=n[0].charAt(0);return{type:"text",raw:a,text:a}}return kw(n,i,n[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let r=this.rules.inline.emStrongLDelim.exec(t);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n))){let o=[...r[0]].length-1,i,a,s=o,c=0,l=r[0][0],u=n===l,f=l==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(f.lastIndex=0,e=e.slice(-1*t.length+o);(r=f.exec(e))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){s+=a;continue}else if(r[5]||r[6]){if(o%3&&!((o+a)%3)){c+=a;continue}if(u)break}if(s-=a,s>0)continue;a=Math.min(a,a+s+c);let m=[...r[0]][0].length,p=t.slice(0,o+r.index+m+a);if(Math.min(o,a)%2){let x=p.slice(1,-1);return{type:"em",raw:p,text:x,tokens:this.lexer.inlineTokens(x)}}let h=p.slice(2,-2);return{type:"strong",raw:p,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(t){let e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," "),r=this.rules.other.nonSpaceChar.test(n),o=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&o&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:e[0],text:n}}}br(t){let e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t,e,n=""){let r=this.rules.inline.delLDelim.exec(t);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let o=[...r[0]].length-1,i,a,s=o,c=this.rules.inline.delRDelim;for(c.lastIndex=0,e=e.slice(-1*t.length+o);(r=c.exec(e))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(a=[...i].length,a!==o))continue;if(r[3]||r[4]){s+=a;continue}if(s-=a,s>0)continue;a=Math.min(a,a+s);let l=[...r[0]][0].length,u=t.slice(0,o+r.index+l+a),f=u.slice(o,-o);return{type:"del",raw:u,text:f,tokens:this.lexer.inlineTokens(f)}}}}autolink(t){let e=this.rules.inline.autolink.exec(t);if(e){let n,r;return e[2]==="@"?(n=e[1],r="mailto:"+n):(n=e[1],r=n),{type:"link",raw:e[0],text:n,href:r,autolink:!0,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,r;if(e[2]==="@")n=e[0],r="mailto:"+n;else{let o;do o=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(o!==e[0]);n=e[0],e[1]==="www."?r="http://"+e[0]:r=e[0]}return{type:"link",raw:e[0],text:n,href:r,autolink:!0,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(t){let e=this.rules.inline.text.exec(t);if(e){let n=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:n?e[0]:KI(e[0]),escaped:n}}}},ht=class Od{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Mn,this.options.tokenizer=this.options.tokenizer||new $s,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,linkEmitted:!1,linkParenPossible:!0,top:!0};let n={other:ze,block:Ls.normal,inline:Eo.normal};this.options.pedantic?(n.block=Ls.pedantic,n.inline=Eo.pedantic):this.options.gfm&&(n.block=Ls.gfm,this.options.breaks?n.inline=Eo.breaks:n.inline=Eo.gfm),this.tokenizer.rules=n}static get rules(){return{block:Ls,inline:Eo}}static lex(e,n){return new Od(n).lex(e)}static lexInline(e,n){return new Od(n).inlineTokens(e)}lex(e){e=e.replace(ze.carriageReturn,`
|
|
4800
|
+
`),this.blockTokens(e,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let r=this.inlineQueue[n];this.inlineTokens(r.src,r.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,n=[],r=!1){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(ze.tabCharGlobal," ").replace(ze.spaceLine,""));let o=1/0;for(;e;){if(e.length<o)o=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(s=>(i=s.call({lexer:this},e,n))?(e=e.substring(i.raw.length),n.push(i),!0):!1))continue;if(i=this.tokenizer.space(e)){e=e.substring(i.raw.length);let s=n.at(-1);i.raw.length===1&&s!==void 0?s.raw+=`
|
|
4801
|
+
`:n.push(i);continue}if(i=this.tokenizer.code(e)){e=e.substring(i.raw.length);let s=n.at(-1);s?.type==="paragraph"||s?.type==="text"?(s.raw+=(s.raw.endsWith(`
|
|
4560
4802
|
`)?"":`
|
|
4561
4803
|
`)+i.raw,s.text+=`
|
|
4562
|
-
`+i.text,this.inlineQueue.at(-1).src=s.text):n.push(i);continue}if(i=this.tokenizer.fences(
|
|
4804
|
+
`+i.text,this.inlineQueue.at(-1).src=s.text):n.push(i);continue}if(i=this.tokenizer.fences(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.heading(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.hr(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.blockquote(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.list(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.html(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.def(e)){e=e.substring(i.raw.length);let s=n.at(-1);s?.type==="paragraph"||s?.type==="text"?(s.raw+=(s.raw.endsWith(`
|
|
4563
4805
|
`)?"":`
|
|
4564
4806
|
`)+i.raw,s.text+=`
|
|
4565
|
-
`+i.raw,this.inlineQueue.at(-1).src=s.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},n.push(i));continue}if(i=this.tokenizer.table(
|
|
4807
|
+
`+i.raw,this.inlineQueue.at(-1).src=s.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},n.push(i));continue}if(i=this.tokenizer.table(e)){e=e.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.lheading(e)){e=e.substring(i.raw.length),n.push(i);continue}let a=e;if(this.options.extensions?.startBlock){let s=1/0,c=e.slice(1),l;this.options.extensions.startBlock.forEach(u=>{l=u.call({lexer:this},c),typeof l=="number"&&l>=0&&(s=Math.min(s,l))}),s<1/0&&s>=0&&(a=e.substring(0,s+1))}if(this.state.top&&(i=this.tokenizer.paragraph(a))){let s=n.at(-1);r&&s?.type==="paragraph"?(s.raw+=(s.raw.endsWith(`
|
|
4566
4808
|
`)?"":`
|
|
4567
4809
|
`)+i.raw,s.text+=`
|
|
4568
|
-
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=s.text):n.push(i),r=a.length!==
|
|
4810
|
+
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=s.text):n.push(i),r=a.length!==e.length,e=e.substring(i.raw.length);continue}if(i=this.tokenizer.text(e)){e=e.substring(i.raw.length);let s=n.at(-1);s?.type==="text"?(s.raw+=(s.raw.endsWith(`
|
|
4569
4811
|
`)?"":`
|
|
4570
4812
|
`)+i.raw,s.text+=`
|
|
4571
|
-
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=s.text):n.push(i);continue}if(
|
|
4572
|
-
`:"";return r?'<pre><code class="language-'+
|
|
4573
|
-
`:"<pre><code>"+(n?o:
|
|
4574
|
-
`}blockquote({tokens:
|
|
4575
|
-
${this.parser.parse(
|
|
4576
|
-
`}html({text:
|
|
4577
|
-
`}hr(
|
|
4578
|
-
`}list(
|
|
4813
|
+
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=s.text):n.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}linkInText(e){if(!e.includes("["))return!1;let n=this.tokenizer.rules.inline.link;for(let r of e.matchAll(this.tokenizer.rules.inline.blockSkip))if(n.test(r[0])&&e.charAt(r.index-1)!=="!")return!0;for(let r of e.matchAll(this.tokenizer.rules.inline.reflinkSearch)){let o=r[0],i=o.lastIndexOf("[");if(!(o.charAt(0)==="!"||!Object.hasOwn(this.tokens.links,Ds(o.slice(i+1,-1))))&&!(i>1&&this.linkInText(o.slice(1,i-1))))return!0}return!1}inlineTokens(e,n=[]){this.tokenizer.lexer=this;let r=this.state.linkParenPossible;this.state.linkParenPossible=r&&e.includes(")");try{return this.#e(e,n)}finally{this.state.linkParenPossible=r}}#e(e,n){let r=e;if(this.tokens.links&&e.includes("[")){let s=this.tokenizer.rules.inline.reflinkSearch,c=l=>{let u=l.lastIndexOf("[");if(!Object.hasOwn(this.tokens.links,Ds(l.slice(u+1,-1))))return l;if(u>1&&l.charAt(0)!=="!"){let f=l.slice(1,u-1);if(this.linkInText(f))return"["+f.replace(s,c)+"]["+"a".repeat(l.length-u-2)+"]"}return"["+"a".repeat(l.length-2)+"]"};r=r.replace(s,c)}r=r.replace(this.tokenizer.rules.inline.anyPunctuationOutsideCode,(s,c,l)=>l?"+".repeat(s.length):c?c+s.slice(c.length,-c.length).replace(/`/g,"+")+c:s),r=r.replace(this.tokenizer.rules.inline.blockSkip,(s,c,l)=>{let u=l?l.length:0;return s.slice(0,u)+"["+"a".repeat(s.length-u-2)+"]"}),r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let o=!1,i="",a=1/0;for(;e;){if(e.length<a)a=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}o||(i=""),o=!1;let s;if(this.options.extensions?.inline?.some(l=>(s=l.call({lexer:this},e,n))?(e=e.substring(s.raw.length),n.push(s),!0):!1))continue;if(s=this.tokenizer.escape(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.tag(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.link(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(s.raw.length);let l=n.at(-1);s.type==="text"&&l?.type==="text"?(l.raw+=s.raw,l.text+=s.text):n.push(s);continue}if(s=this.tokenizer.emStrong(e,r,i)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.codespan(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.br(e)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.del(e,r,i)){e=e.substring(s.raw.length),n.push(s);continue}if(s=this.tokenizer.autolink(e)){e=e.substring(s.raw.length),n.push(s);continue}if(!this.state.inLink&&(s=this.tokenizer.url(e))){e=e.substring(s.raw.length),n.push(s);continue}let c=e;if(this.options.extensions?.startInline){let l=1/0,u=e.slice(1),f;this.options.extensions.startInline.forEach(m=>{f=m.call({lexer:this},u),typeof f=="number"&&f>=0&&(l=Math.min(l,f))}),l<1/0&&l>=0&&(c=e.substring(0,l+1))}if(s=this.tokenizer.inlineText(c)){e=e.substring(s.raw.length),s.raw.slice(-1)!=="_"&&(i=s.raw.slice(-1)),o=!0;let l=n.at(-1);l?.type==="text"?(l.raw+=s.raw,l.text+=s.text):n.push(s);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return n}infiniteLoopError(e){let n="Infinite loop on byte: "+e;if(this.options.silent)console.error(n);else throw new Error(n)}},Us=class{options;parser;constructor(t){this.options=t||Mn}space(t){return""}code({text:t,lang:e,escaped:n}){let r=(e||"").match(ze.notSpaceStart)?.[0],o=t?t.replace(ze.endingNewline,"")+`
|
|
4814
|
+
`:"";return r?'<pre><code class="language-'+nt(r)+'">'+(n?o:nt(o,!0))+`</code></pre>
|
|
4815
|
+
`:"<pre><code>"+(n?o:nt(o,!0))+`</code></pre>
|
|
4816
|
+
`}blockquote({tokens:t}){return`<blockquote>
|
|
4817
|
+
${this.parser.parse(t)}</blockquote>
|
|
4818
|
+
`}html({text:t}){return t}def(t){return""}heading({tokens:t,depth:e}){return`<h${e}>${this.parser.parseInline(t)}</h${e}>
|
|
4819
|
+
`}hr(t){return`<hr>
|
|
4820
|
+
`}list(t){let e=t.ordered,n=t.start,r="";for(let a=0;a<t.items.length;a++){let s=t.items[a];r+=this.listitem(s)}let o=e?"ol":"ul",i=e&&n!==1?' start="'+n+'"':"";return"<"+o+i+`>
|
|
4579
4821
|
`+r+"</"+o+`>
|
|
4580
|
-
`}listitem(
|
|
4581
|
-
`}checkbox({checked:
|
|
4582
|
-
`}table(
|
|
4822
|
+
`}listitem(t){return`<li>${this.parser.parse(t.tokens)}</li>
|
|
4823
|
+
`}checkbox({checked:t}){return"<input "+(t?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:t}){return`<p>${this.parser.parseInline(t)}</p>
|
|
4824
|
+
`}table(t){let e="",n="";for(let o=0;o<t.header.length;o++)n+=this.tablecell(t.header[o]);e+=this.tablerow({text:n});let r="";for(let o=0;o<t.rows.length;o++){let i=t.rows[o];n="";for(let a=0;a<i.length;a++)n+=this.tablecell(i[a]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),`<table>
|
|
4583
4825
|
<thead>
|
|
4584
|
-
`+
|
|
4826
|
+
`+e+`</thead>
|
|
4585
4827
|
`+r+`</table>
|
|
4586
|
-
`}tablerow({text:
|
|
4587
|
-
${
|
|
4588
|
-
`}tablecell(
|
|
4589
|
-
`}strong({tokens:
|
|
4590
|
-
Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error occurred:</p><pre>"+tt(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},Rn=new Md;function pe(e,t){return Rn.parse(e,t)}pe.options=pe.setOptions=function(e){return Rn.setOptions(e),pe.defaults=Rn.defaults,bw(pe.defaults),pe};pe.getDefaults=Ad;pe.defaults=Cn;function UI(...e){return Rn.use(...e),pe.defaults=Rn.defaults,bw(pe.defaults),pe}pe.use=UI;pe.walkTokens=function(e,t){return Rn.walkTokens(e,t)};pe.parseInline=Rn.parseInline;pe.Parser=ht;pe.parser=ht.parse;pe.Renderer=Ms;pe.TextRenderer=Pd;pe.Lexer=pt;pe.lexer=pt.lex;pe.Tokenizer=Ps;pe.Hooks=vo;pe.parse=pe;var U3=pe.options,H3=pe.setOptions,F3=pe.walkTokens,G3=pe.parseInline;var B3=ht.parse,Z3=pt.lex;var HI=new Md({gfm:!0,breaks:!0}),kw=["a","p","br","strong","em","b","i","u","s","del","code","pre","ul","ol","li","blockquote","h1","h2","h3","h4","h5","h6","hr","span","table","thead","tbody","tr","th","td"],Iw=["href","title","class","target","rel"],Rw={ALLOWED_TAGS:kw,ALLOWED_ATTR:Iw,ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!1},FI={...Rw,ALLOWED_TAGS:[...kw,"img"],ALLOWED_ATTR:[...Iw,"src","alt","width","height"]},GI=/^language-[A-Za-z0-9_+#.-]+$/,BI=new Set(["CODE","PRE"]);function ZI(e){e.nodeName==="A"&&e.hasAttribute("href")?(e.setAttribute("target","_blank"),e.setAttribute("rel","noopener noreferrer")):(e.removeAttribute("target"),e.removeAttribute("rel"));let t=e.getAttribute("class");if(t===null)return;let n=BI.has(e.nodeName)?t.split(/\s+/).filter(r=>GI.test(r)):[];if(n.length===0){e.removeAttribute("class");return}e.setAttribute("class",n.join(" "))}var zs=null;function VI(){return zs===null&&(zs=sw(),zs.addHook("afterSanitizeAttributes",ZI)),zs}function Eo(e,t){let n=t?.allowImages===!0,r=HI.parse(e,{async:!1});return VI().sanitize(r,n?FI:Rw).trim()}var Ls=class{#e;#t=null;#n=0;#o="";#r=null;constructor(t){this.#e=t}get deltas(){return this.#n}countDelta(){this.#n+=1}queue(t){this.#o=t,this.#i(),this.#r===null&&(this.#r=requestAnimationFrame(()=>{this.#r=null,this.into(this.#o)}))}into(t){this.#r!==null&&(cancelAnimationFrame(this.#r),this.#r=null),this.#o=t;let n=this.#i();return n.innerHTML=Eo(t,{allowImages:this.#e.allowImages()}),this.#e.follow(),n}end(){this.#r!==null&&this.into(this.#o),this.#t=null}#i(){return this.#t===null&&(this.#t=this.#e.openBubble(),this.#n=0),this.#t}};function Cw(e){let{messages:t,jumpButton:n,emptyWrap:r,strings:o}=e;t.className="messages",t.setAttribute("part","messages"),t.setAttribute("role","log"),t.setAttribute("aria-live","off"),t.setAttribute("aria-label",o.conversation),n.className="jump-latest",n.type="button",n.setAttribute("part","jump-latest"),n.textContent=o.jumpToLatest,r.className="empty",r.setAttribute("part","empty");let i=document.createElement("div");i.className="greeting",i.setAttribute("part","greeting");let a=document.createElement("slot");a.name="greeting",a.append(e.greetingText),i.append(a);let s=document.createElement("slot");s.name="empty",e.starters!==null&&s.append(e.starters),r.replaceChildren(i,s)}var jI=4,WI=120;function Nw(e){if(typeof e!="object"||e===null)return null;let t=e.prompts;if(!Array.isArray(t))return null;let n=t.filter(r=>typeof r=="string").map(r=>r.trim()).filter(r=>r!==""&&r.length<=120).slice(0,4);return n.length===0?null:n}function xo(e,t,n){let r=Nw(e);if(r===null)return null;let o=document.createElement("div");o.className="suggestions",o.setAttribute("part","suggestions"),o.setAttribute("role","group"),o.setAttribute("aria-label",t.suggestions);for(let i of r){let a=document.createElement("button");a.type="button",a.className="suggestion-chip",a.setAttribute("part","suggestion-chip"),a.textContent=i,a.addEventListener("click",()=>n(i)),o.appendChild(a)}return o}function Ow(e,t,n){let r=e.getAttribute("data-starters");if(r===null)return null;let o;try{o=JSON.parse(r)}catch{return console.warn(`<ag-ui-chat>: data-starters is not valid JSON, so no starters are shown. It takes an array of strings, e.g. data-starters='["Summarise this page"]'.`),null}return xo({prompts:o},t,n)}function Ds(e,t){for(let n of Array.from(e.querySelectorAll("pre"))){let r=n.querySelector("code");r===null||n.querySelector(".code-copy")!==null||(n.classList.add("has-copy"),n.append(qI(r,t)))}}function qI(e,t){let n=e.textContent,r=document.createElement("button");return r.type="button",r.className="code-copy",r.setAttribute("part","code-copy"),r.textContent=t.copyCode,r.title=t.copyCode,r.setAttribute("aria-label",t.copyCode),r.addEventListener("click",()=>{YI(n).then(o=>{XI(r,o?t.copied:t.copyFailed,t)})}),r}async function YI(e){let t=navigator.clipboard;if(t===void 0)return!1;try{return await t.writeText(e),!0}catch{return!1}}function XI(e,t,n){e.textContent=t,e.dataset.state=t===n.copied?"copied":"failed",setTimeout(()=>{e.textContent=n.copyCode,delete e.dataset.state},1500)}function zd(e){let t=e.replace(/[._-]+/g," ").trim();return t===""?e:t.charAt(0).toUpperCase()+t.slice(1)}var $s=class{element;#e;#t;#n;#o;#r=!1;constructor(t=fe){this.#o=t,this.element=document.createElement("div"),this.element.className="thoughts",this.element.setAttribute("part","thoughts"),this.element.setAttribute("data-streaming",""),this.#n=document.createElement("button"),this.#n.type="button",this.#n.className="thoughts-toggle",this.#n.setAttribute("part","thoughts-toggle"),this.#n.setAttribute("aria-expanded","true"),this.#e=document.createElement("span"),this.#e.className="thoughts-label",this.#e.setAttribute("part","thoughts-label"),this.#e.textContent=t.thinking,this.#n.append(this.#e),this.#t=document.createElement("pre"),this.#t.className="thoughts-body",this.#t.setAttribute("part","thoughts-body"),this.#n.addEventListener("click",()=>{this.#i(!this.#r)}),this.element.append(this.#n,this.#t)}stream(t){this.#t.textContent=t}collapse(){this.#r||(this.element.removeAttribute("data-streaming"),this.#e.textContent=this.#o.thoughts,this.#i(!0))}#i(t){this.#r=t,this.#t.hidden=t,this.#n.setAttribute("aria-expanded",String(!t))}};function Us(e,t){try{return e()}catch(n){return console.warn(`ag-ui-chat: render failed for ${t}`,n),null}}function Pw(e,t){for(let n of Array.from(e.childNodes))n.nodeType===Node.TEXT_NODE?t.push({node:n,parent:e}):Pw(n,t)}function Mw(e){let t=[];Pw(e,t);let n=0;for(let{node:r,parent:o}of t){let i=document.createDocumentFragment();for(let a of r.data.split(/(\s+)/)){if(a==="")continue;if(/\s/.test(a)){i.appendChild(document.createTextNode(a));continue}let s=document.createElement("span");s.className="word",s.style.setProperty("--ag-ui-word-index",String(n)),s.textContent=a,i.appendChild(s),n+=1}o.replaceChild(i,r)}}function zw({viewport:e,onMissedContent:t}){let n=!0,r=!1,o=()=>e.scrollHeight-e.scrollTop-e.clientHeight<=4,i=u=>{u!==r&&(r=u,t(r))},a=()=>{e.scrollTop=e.scrollHeight},s=()=>{n=o(),n&&i(!1)},l=()=>{if(n){a();return}i(!0)};e.addEventListener("scroll",s,{passive:!0});let c=new ResizeObserver(()=>{n&&a()});return c.observe(e),{follow:l,jump:()=>{n=!0,i(!1),a()},following:()=>n,dispose:()=>{e.removeEventListener("scroll",s),c.disconnect()}}}var Hs=class{#e;#t=new Map;#n=new Map;#o=new Set;#r;#i=null;#a=null;#s=null;constructor(t){this.#e=t}mountScroller(t,n){t.addEventListener("click",()=>{this.jump()},{signal:n}),this.#r=zw({viewport:this.#e.messages,onMissedContent:r=>{t.dataset.missed=String(r)}})}disposeScroller(){this.#r.dispose()}follow(){this.#r.follow()}jump(){this.#r.jump()}isEmpty(){return!this.#e.emptyWrap.hidden}card(t){return this.#t.get(t)}cards(){return this.#t.values()}forgetCard(t){this.#t.delete(t)}setCardElement(t,n){this.#n.set(t,n)}markServerSettled(t){this.#o.add(t)}isServerSettled(t){return this.#o.has(t)}collapseThoughts(){this.#s?.collapse()}closeGroup(){this.#a!==null&&this.#a.childElementCount===0&&(this.#a.remove(),this.updateEmptyState()),this.#a=null,this.#s=null}releaseTurn(){this.#a=null,this.#s=null,this.hidePending(),this.#t.clear()}forgetCards(){this.#o.clear(),this.#n.clear()}empty(){this.#e.messages.replaceChildren(this.#e.emptyWrap),this.updateEmptyState()}append(t,n){let r=document.createElement("div");return r.className=`message message--${t}`,r.setAttribute("part",`message message-${t}`),t===Ze.ASSISTANT?(r.innerHTML=Eo(n,{allowImages:this.#e.allowImages()}),Ds(r,this.#e.strings()),this.ensureGroup().appendChild(r)):(this.#a=null,r.textContent=n,this.#e.messages.appendChild(r)),this.updateEmptyState(),t===Ze.USER?this.jump():this.follow(),r}ensureGroup(){if(this.#a===null){let t=document.createElement("div");t.className="answer",t.setAttribute("part","answer"),this.#a=t,this.#e.messages.appendChild(t),this.updateEmptyState()}return this.#a}revealWords(t){this.#e.element.getAttribute("data-text-animation")==="word"&&Mw(t)}updateEmptyState(){this.#e.emptyWrap.hidden=this.#e.messages.childElementCount>1,this.#e.element.toggleAttribute("data-empty",!this.#e.emptyWrap.hidden)}appendStoppedNote(){let t=document.createElement("div");t.className="stopped-note",t.setAttribute("part","stopped"),t.setAttribute("role","status"),t.textContent=this.#e.strings().stopped,this.ensureGroup().appendChild(t),this.updateEmptyState(),this.follow()}showPending(){if(this.#i!==null)return;let t=document.createElement("div");t.className="pending",t.setAttribute("part","pending"),t.setAttribute("role","status"),t.setAttribute("aria-label",this.#e.strings().thinking);for(let n=0;n<3;n+=1){let r=document.createElement("span");r.className="pending-dot",t.appendChild(r)}this.#i=t,this.ensureGroup().appendChild(t),this.updateEmptyState(),this.follow()}hidePending(){this.#i?.remove(),this.#i=null}showThoughts(){if(this.#s===null){this.#s=new $s(this.#e.strings());let t=this.ensureGroup();t.insertBefore(this.#s.element,t.firstChild),this.updateEmptyState(),this.follow()}return this.#s}noticeIfSkillLoad(t){let n=ts(t);return n===null?!1:(this.appendNotice("\u2728",ue(this.#e.strings().usingSkill,{name:n}),"skill"),!0)}appendNotice(t,n,r,o){this.ensureGroup().appendChild(Es(t,n,r,o)),this.updateEmptyState(),this.follow()}renderToolOutput(t,n){let r=Us(()=>t(n.args),`tool ${n.name}`);r!==null&&(this.#n.get(n.id)?.after(r),this.afterGrew())}afterGrew(){this.updateEmptyState(),this.follow()}cardFor(t){let n=this.#t.get(t.id);if(n!==void 0)return n;let r=this.#e.resolveTool(t.name)?.parameters[Oe],o=typeof r=="string"?r:this.#e.toolSummaries()[t.name]??this.#e.serverSummary(t.name)??zd(t.name),i=new co(t.name,t.args,o,this.#e.strings(),{formatPayload:a=>this.#e.formatToolPayload(a)});return this.#t.set(t.id,i),this.ensureGroup().appendChild(i.element),this.updateEmptyState(),this.follow(),i}};var Fs=class{#e;#t=new Map;#n=new Set;#o=new Map;constructor(t){this.#e=t}register(t){this.#t.set(t.type,t),this.#n.delete(t.type)}has(t){return this.#t.has(t)}unhandledTypes(){return[...this.#n]}clearBlocks(){this.#o.clear()}draw(t,n,r){let o=this.#t.get(n);if(o===void 0){this.#n.add(n);return}let i=Us(()=>o.render(r),`activity ${n}`);if(i===null){this.#r(t,n,o.removedNotice,r);return}let a=this.#o.get(t);a===void 0?this.#e.ensureGroup().appendChild(i):a.replaceWith(i),this.#o.set(t,i),this.#e.afterTranscriptGrew()}#r(t,n,r,o){let i=this.#o.has(t);this.#o.get(t)?.remove(),this.#o.delete(t),console.warn(`ag-ui-chat: activity ${t} (${n}) was not drawable and has been removed. A chart's points must each be a finite JSON number; a numeric column serialised as a string (a Decimal, typically) is rejected rather than coerced.`,o),i&&r!==void 0&&this.#e.appendNotice("\u{1F4C9}",r,"chart-undrawable")}};var Gs=class extends Error{constructor(t){super(t),this.name="ConnectionLostError"}},_o=class{#e;#t;#n;#o;#r;#i;#a;#s=new Set;#c;#u;#d;#f;#p=!1;constructor(t){this.#e=t.agent,this.#t=t.handlers,this.#n=t.getTools??(()=>[]),this.#o=t.getContext??(()=>[]),this.#r=t.executeTool??null,this.#i=t.resolveInterrupts??null,this.#a=t.onPersist??(()=>{}),this.#c=t.connectionLostMessage??"Connection lost",this.#u=t.unfinishedMessage??"Not finished: the run ended or moved on before this tool call returned a result.",this.#d=t.declinedMessage??"User declined the action.";let n=t.maxToolRounds??Hn;this.#f=n>=1?Math.floor(n):Hn,this.#b();let r=t.onStateChanged;r!==void 0&&this.#e.subscribe({onStateChanged:({state:o})=>{r(o)}})}get state(){return this.#e.state}setState(t){this.#e.setState({...t})}get running(){return this.#e.isRunning}get messages(){return this.#e.messages}async send(t,n=[]){this.#p=!1;let r={id:_e(),role:"user",content:t,...n.length>0?{metadata:{attachments:n}}:{}};this.#e.addMessage(r),this.#E(),await this.#m()}truncateToLastUser(){let t=[...this.#e.messages],n=-1;for(let[o,i]of t.entries())i.role==="user"&&(n=o);if(n===-1)return null;let r=t.slice(0,n+1);return this.#a(r),this.#e.setMessages(r),r}async resume(){this.#p=!1,await this.#m()}addToolResult(t,n){this.#e.addMessage({id:_e(),role:"tool",content:n,toolCallId:t}),this.#E()}cancel(){this.#p=!0,this.#e.abortRun()}async#m(){try{await this.#_(),this.#p&&this.#l()}catch(t){this.#p||KI(t)?this.#l():this.#t.onError(t instanceof Error?t.message:String(t))}finally{this.#t.onSettled()}}#l(){this.#E(),this.#t.onCancelled()}#b(){let t=this.#e.messages,n=t.map(JI);n.some((r,o)=>r!==t[o])&&this.#e.setMessages(n)}#g(t){let n=this.#e.messages,r=Ja(n,o=>({id:_e(),role:"tool",content:this.#u,toolCallId:o,metadata:{outcome:Ve.INTERRUPTED}}),t);r!==n&&(this.#e.setMessages([...r]),this.#E())}#y(t,n){for(let r of t){let o=r.toolCallId;o!==void 0&&n[r.id]?.status==="cancelled"&&this.#e.addMessage({id:_e(),role:"tool",content:this.#d,toolCallId:o,metadata:{outcome:Ve.DENIED}})}this.#E()}#E(){this.#a(this.#e.messages)}get annotatedMessages(){return this.messages}async#_(){let t,n=new Set;for(let r=0;r<this.#f;r+=1){if(this.#p)return;let o=[],i={terminal:!1,errored:!1,interrupts:[]},a={tools:this.#n(),context:this.#o()};if(t!==void 0&&(a.resume=t),this.#g(n),this.#p||(await this.#e.runAgent(a,this.#h(o,i)),t=void 0,n=new Set,this.#E(),this.#p))return;if(!i.terminal)throw new Gs(this.#c);if(i.errored)return;if(i.interrupts.length>0){if(this.#i===null)return;let l=await this.#i(i.interrupts);if(this.#p){this.#y(i.interrupts,l);return}t=bb(i.interrupts,l),n=new Set(i.interrupts.flatMap(({toolCallId:c})=>c??[]));continue}if(this.#r===null||o.length===0)return;let s=!1;for(let l of o){if(this.#p)return;let c=await this.#r(l);if(c!==null){if(c.halt===!0)return;this.#e.addMessage({id:_e(),role:"tool",content:c.content,toolCallId:l.id,...c.outcome===void 0?{}:{metadata:{outcome:c.outcome}}}),this.#E(),s=!0}}if(!s)return}}#h(t,n){let r=this.#t,o=this.#s,i=()=>this.#p,a=new Set,s;return{onRunInitialized(){r.onRunStart()},onRunStartedEvent({event:l}){s=l.runId},onTextMessageStartEvent({event:l}){o.has(l.messageId)&&console.warn(`<ag-ui-chat>: the server reused message id "${l.messageId}", which was already closed. Its content will be appended to that earlier message rather than starting a new one, and the merged result is what gets persisted. Issue a fresh id per message.`)},onTextMessageContentEvent({textMessageBuffer:l}){r.onTextDelta(l)},onTextMessageEndEvent({event:l,textMessageBuffer:c}){o.add(l.messageId),r.onTextEnd(c,{messageId:l.messageId,...s===void 0?{}:{runId:s}})},onToolCallEndEvent({event:l,toolCallName:c,toolCallArgs:u}){let f={id:l.toolCallId,name:c,args:u};t.push(f),r.onToolCall(f)},onToolCallResultEvent({event:l}){let c=l.metadata?.outcome;r.onToolResult(l.toolCallId,Zn(l.content),c)},onActivitySnapshotEvent({event:l,messages:c}){if(c.some(f=>f.id===l.messageId&&f.role==="activity")){r.onActivityChanged(l.messageId,l.activityType,l.content);return}r.onActivity(l.activityType,l.content,l.messageId)},onActivityDeltaEvent({event:l}){a.add(l.messageId)},onCustomEvent({event:l}){r.onCustomEvent(l.name,l.value)},onSubagentStartedEvent({event:l}){r.onSubAgentStarted(l.subagentRunId,l.name,l.parentToolCallId??null)},onSubagentFinishedEvent({event:l}){r.onSubAgentFinished(l.subagentRunId)},onSubagentErrorEvent({event:l}){r.onSubAgentError(l.subagentRunId,l.message)},onMessagesSnapshotEvent({event:l}){r.onMessagesSnapshot(l.messages)},onMessagesChanged({messages:l}){if(a.size!==0){for(let c of a){let u=l.find(f=>f.id===c);u!==void 0&&u.role==="activity"&&r.onActivityChanged(c,u.activityType,u.content)}a.clear()}},onReasoningStartEvent(){r.onReasoningStart()},onReasoningMessageContentEvent({reasoningMessageBuffer:l}){r.onReasoningDelta(l)},onReasoningMessageEndEvent({reasoningMessageBuffer:l}){r.onReasoningDelta(l)},onReasoningEndEvent(){r.onReasoningEnd()},onRunFinishedEvent(l){n.terminal=!0,l.outcome==="interrupt"&&(n.interrupts=l.interrupts)},onRunErrorEvent({event:l}){n.terminal=!0,n.errored=!0,!i()&&r.onError(l.message)},onRunFinalized(){n.terminal=!0,r.onRunEnd()}}}};function KI(e){return e instanceof Error?e.name==="AbortError"||e instanceof TypeError&&/abort/i.test(e.message):!1}function JI(e){let{outcome:t,attachments:n,...r}=e;if(t===void 0&&n===void 0)return e;let o=r.metadata;return{...r,metadata:{...t===void 0?{}:{outcome:t},...n===void 0?{}:{attachments:n},...typeof o=="object"?o:{}}}}var Lw="ag-ui-chat",vr="thread",Ld="threads",So="messages:",Zs="checkpoint:",To="minted:",QI=60,eR=100,tR="New conversation",Dw=!1;function ft(e,t){try{sessionStorage.setItem(e,t)}catch{if(Dw)return;Dw=!0,console.warn("<ag-ui-chat>: the browser refused a sessionStorage write \u2014 the quota is full, or storage is disabled for this context. The conversation continues, but it will not survive a page reload. Deleting a long conversation from the history drawer frees the quota.")}}function Bs(e){return e===""?Lw:`${Lw}@${e}`}var nt=class e{#e;constructor(t=""){this.#e=Bs(t),t!==""&&e.adopt("",t)}static adopt(t,n){let r=`${Bs(t)}:`,o=`${Bs(n)}:`;for(let[i,a]of $w(r)){let s=sessionStorage.getItem(i),l=o+a;s!==null&&sessionStorage.getItem(l)===null&&ft(l,s),sessionStorage.removeItem(i)}}static purge(t){for(let[n]of $w(`${Bs(t)}:`))sessionStorage.removeItem(n)}threadId(){return sessionStorage.getItem(this.#r(vr))??this.newThread()}newThread(){let t=_e();return ft(this.#r(vr),t),ft(this.#r(To+t),"1"),t}isUnsent(t){return sessionStorage.getItem(this.#r(To+t))!==null&&sessionStorage.getItem(this.#r(So+t))===null}loadMessages(t){return Promise.resolve(this.#i(this.#r(So+t)))}saveMessages(t,n){ft(this.#r(So+t),JSON.stringify(n)),sessionStorage.removeItem(this.#r(To+t)),this.#t(t,n)}loadCheckpoint(t){return this.#i(this.#r(Zs+t))}saveCheckpoint(t,n){let r=this.#r(Zs+t);if(n===null){sessionStorage.removeItem(r);return}ft(r,JSON.stringify(n))}clear(t){sessionStorage.removeItem(this.#r(So+t)),sessionStorage.removeItem(this.#r(Zs+t)),sessionStorage.removeItem(this.#r(To+t)),this.#o(this.#n().filter(n=>n.threadId!==t)),sessionStorage.getItem(this.#r(vr))===t&&sessionStorage.removeItem(this.#r(vr))}listThreads(){let t=this.#n().sort((n,r)=>r.updatedAt-n.updatedAt).map(({threadId:n,title:r,updatedAt:o,preview:i})=>({threadId:n,title:r,updatedAt:o,preview:i}));return Promise.resolve(t)}setActiveThread(t){ft(this.#r(vr),t)}renameThread(t,n){let r=this.#n(),o=r.find(i=>i.threadId===t);o!==void 0&&(o.title=n,o.titleCustom=!0,this.#o(r))}#t(t,n){let r=this.#n(),o=r.find(s=>s.threadId===t),i=rR(n),a=Date.now();o===void 0?r.push({threadId:t,title:Uw(n),titleCustom:!1,preview:i,updatedAt:a}):(o.preview=i,o.updatedAt=a,o.titleCustom||(o.title=Uw(n))),this.#o(r)}#n(){return this.#i(this.#r(Ld))??[]}#o(t){let n=this.#r(Ld);if(t.length===0){sessionStorage.removeItem(n);return}ft(n,JSON.stringify(t))}#r(t){return`${this.#e}:${t}`}#i(t){let n=sessionStorage.getItem(t);if(n===null)return null;try{return JSON.parse(n)}catch{return null}}};function $w(e){let t=[];for(let n=0;n<sessionStorage.length;n+=1){let r=sessionStorage.key(n);if(r===null||!r.startsWith(e))continue;let o=r.slice(e.length);nR(o)&&t.push([r,o])}return t}function nR(e){return e===vr||e===Ld||e.startsWith(So)||e.startsWith(Zs)||e.startsWith(To)}function Uw(e){for(let t of e)if(t.role==="user"){let n=Hw(t.content);if(n!=="")return Fw(n,QI)}return tR}function rR(e){for(let t of[...e].reverse()){let n=Hw(t.content);if(n!=="")return Fw(n,eR)}return""}function Hw(e){return typeof e=="string"?e.replace(/\s+/g," ").trim():""}function Fw(e,t){return e.length<=t?e:`${e.slice(0,t-1).trimEnd()}\u2026`}function Dd(e){let t=e.headers??{},n=new Set;return new Eb({url:e.endpoint,headers:t,initialState:{...e.initialState??{}},fetch:(r,o)=>{let i=e.getHeaders?.(),a=[...new Set([...Object.keys(t),...Object.keys(i??{})])].sort();if(Ka(r,a,e.trustedOrigins??[],n),i===void 0)return fetch(r,ot(o,e.credentials));let s=new Headers(o?.headers);for(let[l,c]of Object.entries(i))s.set(l,c);return fetch(r,ot({...o,headers:s},e.credentials))},...e.threadId!==void 0?{threadId:e.threadId}:{},...e.initialMessages!==void 0?{initialMessages:[...e.initialMessages]}:{}})}function Gw(e,t){let n=e.getAttribute(t);return n!==null&&n!=="false"}function $d(e,t){let n=e.getAttribute(t);if(n===null)return null;try{return JSON.parse(n)}catch{return console.warn(`<ag-ui-chat>: ${t} is not valid JSON, so it was ignored entirely and the built-in default is being used. Check the quoting -- JSON inside an HTML attribute needs single quotes around the attribute value, or its own double quotes escaped.`),null}}function Bw(e){let t=e.getAttribute("data-max-tool-rounds");return t===null?Hn:Number.parseInt(t,10)}var Ao=class{#e;#t;#n;#o;#r;#i=new Set;#a=new Map;constructor(t,n=()=>({}),r=new nt,o=()=>{},i=!0){this.#e=t.endsWith("/")?t:`${t}/`,this.#t=n,this.#n=r,this.#o=o,this.#r=i}threadId(){return this.#n.threadId()}setActiveThread(t){this.#n.setActiveThread(t)}newThread(){return Xa(this.#n)}isUnsent(t){return this.#n.isUnsent?.(t)===!0}saveMessages(t,n){this.#n.saveMessages(t,this.#r?n:[])}loadCheckpoint(t){return this.#n.loadCheckpoint(t)}saveCheckpoint(t,n){this.#n.saveCheckpoint(t,n)}renameThread(t,n){this.#n.renameThread(t,n),this.#a.set(t,n),this.#f(t,"PATCH",{title:n})}clear(t){this.#n.clear(t),this.#i.add(t),this.#f(t,"DELETE")}async listThreads(){let t=await this.#s();return t===null?this.#n.listThreads():t.filter(n=>!this.#i.has(n.thread_id)).map(n=>this.#u(n))}async loadMessages(t){if(this.#n.isUnsent?.(t)===!0)return null;let n=await this.#d(`${this.#e}${encodeURIComponent(t)}/`);if(n===null||!n.ok)return this.#n.loadMessages(t);let r=await this.#c(n);return r===null?this.#n.loadMessages(t):r.messages??null}async#s(){let t=await this.#d(this.#e);if(t===null||!t.ok)return null;let n=await this.#c(t);return n===null?null:n.threads??[]}async#c(t){try{return await t.json()}catch{return null}}#u(t){return{threadId:t.thread_id,title:this.#a.get(t.thread_id)??t.title,updatedAt:t.updated_at===null?Number.NaN:Date.parse(t.updated_at),preview:t.preview}}async#d(t){try{return await fetch(t,ot({headers:this.#t()},this.#o()))}catch{return null}}async#f(t,n,r){let o=this.#t();try{await fetch(`${this.#e}${encodeURIComponent(t)}/`,ot({method:n,headers:r===void 0?o:{...o,"content-type":"application/json"},body:r===void 0?null:JSON.stringify(r)},this.#o()))}catch{}}};function Zw(){return{tools:[],serverSettled:new Set,invalidated:new Set,announcedOutcome:!1}}function oR(e,t){let n={};for(let[r,o]of Object.entries(e))n[r]=(...i)=>{t()&&o(...i)};return n}var Vs=class{#e;#t=Zw();constructor(t){this.#e=t}detach(){this.#t=Zw()}forClient(){let t=this.#t,n=()=>t===this.#t,{onSettled:r,...o}=this.#n(t);return{...oR(o,n),onSettled:()=>{n()&&r(),this.#o(t)}}}#n(t){return{onRunStart:()=>{this.#e.running()||(t.announcedOutcome=!1,this.#e.announcer.announce(this.#e.strings().announceResponding)),this.#e.setRunning(!0),this.#e.transcript.ensureGroup(),this.#e.transcript.showPending()},onReasoningStart:()=>{this.#e.transcript.hidePending(),this.#e.transcript.showThoughts()},onReasoningDelta:n=>{this.#e.transcript.showThoughts().stream(n)},onReasoningEnd:()=>{},onTextDelta:n=>{this.#e.transcript.hidePending(),this.#e.transcript.collapseThoughts(),this.#e.stream.queue(n),this.#e.stream.countDelta()},onTextEnd:(n,r)=>{if(n===""){this.#e.stream.end();return}let o=this.#e.stream.into(n);this.#e.stream.deltas<=1&&this.#e.transcript.revealWords(o),Ds(o,this.#e.strings()),this.#e.actions.attach(o,r),this.#e.stream.end(),this.#e.noteUnread()},onToolCall:n=>{this.#e.transcript.hidePending(),!this.#e.transcript.noticeIfSkillLoad(n)&&(t.tools.push({id:n.id,name:n.name}),this.#e.transcript.cardFor(n))},onActivity:(n,r,o)=>{this.#e.activities.draw(o,n,r)},onCustomEvent:(n,r)=>{if(n===Il){this.#r(t,r);return}if(n===wp){this.#e.subagents.report(r);return}this.#e.element.dispatchEvent(new CustomEvent(Sl,{detail:{name:n,value:r},bubbles:!0,composed:!0}))},onSubAgentStarted:(n,r,o)=>{this.#e.subagents.start(n,r,o)},onSubAgentFinished:n=>{this.#e.subagents.finish(n)},onSubAgentError:(n,r)=>{this.#e.subagents.fail(n,r)},onMessagesSnapshot:()=>{this.#e.transcript.appendNotice("\u{1F504}",this.#e.strings().historyReplaced,"history-replaced")},onToolResult:(n,r,o)=>{let i=this.#e.transcript.card(n);i!==void 0&&(i.settle(io(o),r),this.#e.transcript.markServerSettled(n),t.serverSettled.add(n),this.#e.transcript.showPending())},onActivityChanged:(n,r,o)=>{this.#e.activities.draw(n,r,o)},onRunEnd:()=>{this.#e.transcript.hidePending(),this.#e.stream.end()},onError:n=>{t.announcedOutcome=!0,this.#e.announcer.announce(this.#e.strings().announceFailed),this.#e.transcript.hidePending();let r=this.#e.appendMessage(Ze.ASSISTANT,`\u26A0\uFE0F ${n}`);r.classList.add("message--failed"),this.#e.actions.attach(r,{rateable:!1}),this.#e.transcript.revealWords(r),this.#e.stream.end()},onCancelled:()=>{t.announcedOutcome=!0,this.#e.announcer.announce(this.#e.strings().announceStopped),this.#e.transcript.hidePending(),this.#e.transcript.appendStoppedNote(),this.#e.stream.end()},onSettled:()=>{t.announcedOutcome||this.#e.announcer.announce(this.#e.strings().announceAnswerReady),this.#e.transcript.hidePending(),this.#e.setRunning(!1),this.#e.stream.end();for(let n of this.#e.transcript.cards())n.settled||n.settle(te.INTERRUPTED,this.#e.strings().callNotFinished);this.#e.transcript.closeGroup()}}}#o(t){let n=t.tools.map(({id:o,name:i})=>({name:i,side:t.serverSettled.has(o)?"server":"client"})),r=[...t.invalidated];t.tools.length=0,t.serverSettled.clear(),t.invalidated.clear(),this.#e.element.dispatchEvent(new CustomEvent(_l,{detail:{tools:n,invalidated:r},bubbles:!0,composed:!0}))}#r(t,n){let r=n??{},o=Array.isArray(r.keys)?r.keys.filter(i=>typeof i=="string"):[];if(o.length!==0){for(let i of o)t.invalidated.add(i);this.#e.element.dispatchEvent(new CustomEvent(Tl,{detail:{keys:o,reason:typeof r.reason=="string"?r.reason:null},bubbles:!0,composed:!0}))}}};var Ud=new Set,js=class{#e;#t="";#n=null;#o="";#r="";#i=null;constructor(t){this.#e=t}claim(){this.#t=this.#a()}release(){this.#n!==null&&(Ud.delete(this.#n),this.#n=null)}conversationNamespace(t){return t===""?this.#t:`${this.#t}#${t}`}scopeStore(t,n){if(!(t instanceof nt))return t;let r=this.conversationNamespace(n);return this.#i=r===""?t:new nt(r),this.#i}rescopeStore(t,n){return t!==this.#i?null:(this.#i=new nt(n),this.#i)}key(t){return this.#t===""?t:`${t}:${this.#t}`}readScopedItem(t){let n=sessionStorage.getItem(this.key(t));return n!==null||this.#t===""?n:sessionStorage.getItem(t)}readPreference(t){try{let n=localStorage.getItem(this.key(t));if(n!==null)return n}catch{}return this.readScopedItem(t)}writePreference(t,n){let r=this.key(t);try{localStorage.setItem(r,n)}catch{}ft(r,n)}clearPreference(t){let n=this.key(t);try{localStorage.removeItem(n)}catch{}try{sessionStorage.removeItem(n)}catch{}}#a(){let t=this.#e.id(),n=t!==""?t:this.#e.endpoint();return n===""?"":this.#r===n?this.#o:Ud.has(n)?(this.#r=n,this.#o=`${n}~${_e()}`,console.warn(`<ag-ui-chat>: another element on this page already stores its conversation under "${n}", so this one has been given a throwaway namespace of its own \u2014 the two would otherwise share a thread pointer, a history drawer and every message. Give each <ag-ui-chat> its own id to keep them apart and let this one restore its conversation across reloads.`),this.#o):(Ud.add(n),this.#n=n,n)}};var iR=["data-attachments-url","data-attachment-accept","data-attachment-max-bytes","data-transcribe-url","data-threads-url","data-threads-cache","data-tools-url","data-skills-url","data-skills","data-prompt-chips","data-slash-commands","data-theme-toggle","data-strings","data-icon-url"],Fd=["omit","same-origin","include"];function Hd(e){return Fd.includes(e)}var Vw="ag-ui-chat:collapsed",jw="ag-ui-chat:theme",qw=["light","dark","auto"];function aR(e){return e.split(/\s+/).filter(t=>qw.includes(t)).at(-1)}function Ww(e,t){return[...e.split(/\s+/).filter(r=>r!==""&&!qw.includes(r)),t].join(" ")}var ko=class extends HTMLElement{agentFactory=Dd;headers={};getHeaders=null;trustedOrigins=[];allowImages=!1;formatRelativeTime=null;autoConfirm=!1;askUser=!1;askUserRenderer=null;approvalRenderer=null;approveWithEdits=!1;confirmPredicate=null;getTools=()=>this.#T.defaultTools();getContext=()=>[...Zl(this.getPageMap,this.autoInjectPageMap)];routeMap=[];navigate=null;getPageMap=null;autoInjectPageMap=!0;conversationStore=new nt;uploadHandler=null;transcribeHandler=null;navigationResult=()=>({navigated:!0,url:window.location.href});skillContext=()=>({});toolSummaries={};formatToolPayload=null;strings={};resolvePageTarget=t=>document.querySelector(t);#e=new Set;#t=fe;#n=new _s({card:t=>this.#v.card(t),strings:()=>this.#t,follow:()=>this.#v.follow()});#o=new Fs({ensureGroup:()=>this.#v.ensureGroup(),afterTranscriptGrew:()=>this.#v.afterGrew(),appendNotice:(t,n,r)=>this.#v.appendNotice(t,n,r)});#r=new ks({element:this,strings:()=>this.#t,retry:()=>{this.retryLastTurn()},threadId:()=>this.#h.threadId});#i;#a=null;#s=[];#c=new ws;#u=document.createElement("button");#d;#f=document.createElement("div");#p;#m;#l;#b;#g;#y;#E;#_;#h;#C;#P;#B;#A;#Z;#k;#M;#V=document.createElement("span");#U=0;#z;#v;#j;#ie;#me=document.createElement("span");#I;#x;#Q=[];#H=[];#W=document.createElement("div");#N=null;#ge="";#F=()=>{this.#x.publishVisualViewport(),!this.#x.dragging()&&this.#x.restoreLauncherPosition()};#ae;#q;#L=!1;#ee=new AbortController;#ve=!1;#se=null;#Y={};#be={};#le=null;#O=null;#D={};#R=!1;#w=null;#ye=null;#ce=new gs;#T=new es({element:this,routeMap:()=>this.routeMap,navigate:()=>this.navigate,getPageMap:()=>this.getPageMap,resolvePageTarget:t=>this.resolvePageTarget(t),getTools:()=>this.getTools(),askUser:()=>this.askUser,askUserRenderer:()=>this.askUserRenderer,decision:this.#ce,ensureGroup:()=>this.#v.ensureGroup(),strings:()=>this.#t,hidePending:()=>this.#v.hidePending(),updateEmptyState:()=>this.#v.updateEmptyState(),follow:()=>this.#v.follow(),fetchInit:t=>this.#_e(t)});#we=new Ls({openBubble:()=>this.appendMessage(Ze.ASSISTANT,""),allowImages:()=>this.allowImages,follow:()=>this.#v.follow()});#S=new js({id:()=>this.id,endpoint:()=>this.endpoint});#G;constructor(){super(),this.#i=this.attachShadow({mode:"open"}),this.#p=document.createElement("div"),this.#m=document.createElement("div"),this.#l=document.createElement("textarea"),this.#b=document.createElement("button"),this.#g=document.createElement("span"),this.#C=document.createElement("div"),this.#P=document.createElement("button"),this.#B=document.createElement("input"),this.#A=document.createElement("div"),this.#ae=document.createElement("span"),this.#Z=document.createElement("button"),this.#k=document.createElement("button"),this.#M=document.createElement("span"),this.#z=document.createElement("div"),this.#v=new Hs({element:this,messages:this.#m,emptyWrap:this.#z,strings:()=>this.#t,allowImages:()=>this.allowImages,resolveTool:t=>this.#T.resolve(t),toolSummaries:()=>this.toolSummaries,serverSummary:t=>this.#T.summary(t),formatToolPayload:t=>this.formatToolPayload?.(t)??null}),this.#j=new rs({element:this,transcript:this.#v,tools:this.#T,decision:this.#ce,strings:()=>this.#t,announce:t=>this.#c.announce(t),autoConfirm:()=>this.autoConfirm,confirmPredicate:()=>this.confirmPredicate,getPageMap:()=>this.getPageMap,navigate:()=>this.navigate,approveWithEdits:()=>this.approveWithEdits,approvalRenderer:()=>this.approvalRenderer,getContext:()=>this.getContext(),conversationStore:()=>this.conversationStore,threadId:()=>this.#h.threadId,tenure:()=>this.#Y,conversation:()=>this.#be}),this.#ie=new Vs({element:this,transcript:this.#v,stream:this.#we,actions:this.#r,activities:this.#o,subagents:this.#n,announcer:this.#c,strings:()=>this.#t,running:()=>this.#R,setRunning:t=>this.#K(t),appendMessage:(t,n)=>this.appendMessage(t,n),noteUnread:()=>this.#He()}),this.#x=new ys({element:this,launcher:this.#k,root:this.#i,connected:()=>this.#L,collapsed:()=>this.collapsed,collapsible:()=>Ot(this.getAttribute("placement")).collapseTo!==null,strings:()=>this.#t,readPreference:t=>this.#S.readPreference(t),writePreference:(t,n)=>this.#S.writePreference(t,n),clearPreference:t=>this.#S.clearPreference(t),announceSurfaceChange:(t,n)=>this.#ze(t,n)}),this.#d=new hs({element:this,root:this.#i,messages:this.#m,messagesWrap:this.#f,input:this.#l,strings:()=>this.#t,autoGrow:()=>jt(this.#l),quote:t=>this.quote(t)}),this.#I=new cs({element:this,chat:this.#p,slot:this.#A,fileInput:this.#B,button:this.#P,strings:()=>this.#t,uploadHandler:()=>this.uploadHandler,headersFor:t=>this.#X(t),credentialsOption:()=>this.#de()}),this.#q=new ds({element:this,slot:this.#ae,input:this.#l,strings:()=>this.#t,transcribeHandler:()=>this.transcribeHandler,headersFor:t=>this.#X(t),credentialsOption:()=>this.#de(),onInput:()=>this.#pe()}),this.registerActivityRenderer({type:Cl,render:t=>{let n=sR(t);return n===null?null:Es("\u{1F5DC}",ue(this.#t.historyCompacted,{count:n}),"compaction")}}),this.registerActivityRenderer({type:kl,render:t=>xo(t,this.#t,n=>{this.sendMessage(n)})}),this.#y=new ps(t=>this.#G.apply(t)),this.#G=new Bo({element:this,menu:this.#y,input:this.#l,hint:this.#C,strings:()=>this.#t,context:()=>this.skillContext(),flag:t=>Gw(this,t),readJsonAttribute:t=>$d(this,t),fetchInit:t=>this.#_e(t),send:t=>{this.sendMessage(t)},submit:()=>{this.#he()},autoGrow:()=>jt(this.#l)}),this.#E=new ms({onSelect:t=>{this.#h.switchThread(t)},onNew:()=>{this.newChat(),this.#h.refreshDrawer()},onRename:(t,n)=>{this.#h.renameThread(t,n)},onDelete:t=>{this.#h.deleteThread(t)}}),this.#_=new ro((t,n)=>{this.#h.continueRun(t,n).catch(r=>{console.warn("<ag-ui-chat>: continuing a run failed",r)})}),this.#h=new fs({element:this,drawer:this.#E,checkpoints:this.#_,transcript:this.#v,actions:this.#r,activities:this.#o,tools:this.#T,input:this.#l,hint:this.#C,strings:()=>this.#t,conversationStore:()=>this.conversationStore,formatRelativeTime:()=>this.formatRelativeTime,navigationResult:()=>this.navigationResult,headersFor:t=>this.#X(t),requestCredentials:()=>this.#te(),appendMessage:(t,n)=>this.appendMessage(t,n),announceTurn:t=>this.#Pe(t,[]),recordTurn:t=>this.#Oe(t),autoGrow:()=>jt(this.#l),continuationEnded:()=>this.#J(),client:()=>this.#O,ensureClient:()=>this.#fe(),buildClient:t=>this.#Me(t),releaseClient:()=>{this.#O=null},running:()=>this.#R||this.#w!==null,holdRun:t=>{let n={};return this.#w=n,this.#ye=t===null?null:{hold:n,restored:t},{release:()=>{this.#w===n&&(this.#w=null,this.#J())}}},cancelRun:()=>this.#$(),resetState:()=>this.#ne(),setRunning:t=>this.#K(t)})}static get observedAttributes(){return["title-text","placement","credentials","user-key","user-name",...iR]}attributeChangedCallback(t,n,r){if(t==="credentials"){r!==null&&!Hd(r)&&console.error(`<ag-ui-chat>: credentials="${r}" is not a fetch credentials mode (${Fd.join(" / ")}) \u2014 it is being ignored, so requests use the browser default and cross-origin cookies will not be sent.`);return}if(t==="placement"){this.#x.releaseOwnedAxes(),this.#x.releaseLauncherPosition(),Ot(this.getAttribute("placement")).collapseTo===null&&this.collapsed&&this.setCollapsed(!1),requestAnimationFrame(()=>this.#x.syncResizeAnchor());return}if(t==="title-text"){this.#g.textContent=r??this.#t.title,this.#V.textContent=this.#g.textContent;return}if(t==="user-name"){this.#xe();return}if(t==="user-key"){this.#L&&(n??"")!==(r??"")&&this.#Ae(n??"",r??"");return}n===r||!this.#L||console.warn(`<ag-ui-chat>: "${t}" was changed after the element connected, and is read only while connecting \u2014 this assignment has no effect. Set it before the element enters the DOM (in the markup, or on the element before appending it); frameworks that patch attributes after mount should bind it at creation. To apply a new value now, remove and re-insert the element.`)}registerTool(t){this.#T.register(t)}get sharedState(){return this.#Ee()?.state??this.#D}set sharedState(t){this.#D={...t},this.#Ee()?.setState(this.#D)}#Ee(){return this.#h.continuation??this.#O}registerPageState(t){this.#T.registerPageState(t)}registerStateHook(t){this.registerPageState(t)}get endpoint(){return this.getAttribute("endpoint")??""}set endpoint(t){this.setAttribute("endpoint",t)}get userKey(){return this.getAttribute("user-key")??""}set userKey(t){this.setAttribute("user-key",t)}get userName(){return this.getAttribute("user-name")??""}set userName(t){this.setAttribute("user-name",t)}#xe(){let t=this.userName.trim();this.#me.textContent=t===""?this.#t.greetingNoName:ue(this.#t.greeting,{name:t})}get credentials(){let t=this.getAttribute("credentials");return t!==null&&Hd(t)?t:null}set credentials(t){if(t===null){this.removeAttribute("credentials");return}if(!Hd(t))throw new TypeError(`<ag-ui-chat>: credentials must be one of ${Fd.map(n=>`"${n}"`).join(", ")} (got ${JSON.stringify(t)}).`);this.setAttribute("credentials",t)}#ue(){return{...this.headers,...this.getHeaders?.()}}#X(t){let n=this.#ue();return Ka(t,Object.keys(n),this.trustedOrigins,this.#e),n}#te(){return this.credentials??void 0}#de(){let t=this.#te();return t===void 0?{}:{credentials:t}}#_e(t){return ot({headers:this.#X(t)},this.#te())}get toolDisplay(){let t=this.getAttribute("data-tool-display");return t===Fn.INLINE||t===Fn.MINIMAL||t===Fn.COMPACT?t:Fn.FULL}set toolDisplay(t){this.setAttribute("data-tool-display",t)}get extraStyles(){return this.#s}set extraStyles(t){this.#s=[...t],this.#a!==null&&(this.#i.adoptedStyleSheets=[this.#a,...this.#s])}connectedCallback(){if(this.#ee=new AbortController,this.#ve&&this.#Re(),this.#ve=!0,this.#S.claim(),this.#x.restoreSize(),requestAnimationFrame(()=>{this.#x.restoreLauncherPosition(),this.#x.syncResizeAnchor()}),this.#t=Bu({...this.#De(),...this.strings}),this.getAttribute("data-theme-toggle")!==null){let r=this.#S.readPreference(jw),o=r===null?void 0:aR(r);o!==void 0&&this.setAttribute("theme",Ww(this.getAttribute("theme")??"",o))}this.#Ue(),this.#E.setStrings(this.#t),this.#_.setStrings(this.#t),Ot(this.getAttribute("placement")).collapseTo!==null&&this.#$e()&&this.setAttribute("collapsed",""),this.#Ne(),this.#G.init();let t=this.#se,n=t!==null&&t!==this.userKey;n&&this.#Ae(t,this.userKey),this.#se=this.userKey,this.conversationStore=this.#S.scopeStore(this.#Te(),this.userKey),window.addEventListener("resize",this.#F),window.visualViewport?.addEventListener("resize",this.#F),window.visualViewport?.addEventListener("scroll",this.#F),this.#x.publishVisualViewport(),this.#Se(),this.#I.wire(this.#ee.signal),this.#q.wire(),this.#h.adoptActiveThread(),queueMicrotask(()=>this.#Le()),this.#h.rehydrate(),n&&this.#h.refreshDrawer(),this.#L=!0}#Le(){this.#L&&(this.#T.fetchCatalog(),this.#G.fetch())}async reload(){this.#$(),this.#ne(),this.#K(!1),await Promise.all([this.#T.fetchCatalog(),this.#G.fetch(),this.#h.rehydrate()])}disconnectedCallback(){this.#L=!1,this.#ee.abort(),window.removeEventListener("resize",this.#F),window.visualViewport?.removeEventListener("resize",this.#F),window.visualViewport?.removeEventListener("scroll",this.#F),this.#S.release(),this.#$(),this.#d.detachPageOffer(),this.#I.tray?.dispose(),this.#q.dispose(),this.#v.disposeScroller(),this.#c.dispose()}#De(){let t=$d(this,"data-strings");return typeof t=="object"&&t!==null?t:{}}quote(t){this.#d.insert(t)}offerQuoteInPage(t=document.body){return this.#d.offerInPage(t)}#Se(){this.#le=null;let t=this.getAttribute("data-threads-url");if(t!==null){let n=this.conversationStore,r=new Ao(t,()=>this.#X(t),n,()=>this.#te(),this.getAttribute("data-threads-cache")!=="false");this.#le={remote:r,inner:n},this.conversationStore=r}}#Te(){let t=this.#le;return t!==null&&this.conversationStore===t.remote?t.inner:this.conversationStore}setSkills(t){this.#G.setClientSkills(t)}get collapsed(){return this.hasAttribute("collapsed")}set collapsed(t){this.setCollapsed(t)}setCollapsed(t,n={}){t&&Ot(this.getAttribute("placement")).collapseTo===null||(n.announce===!0&&t&&!this.collapsed&&this.#ze(this.#t.chatMinimised,null),t||this.#x.restoreLauncherPosition(),t?this.setAttribute("collapsed",""):this.removeAttribute("collapsed"),ft(this.#S.key(Vw),t?"1":"0"),this.#re(0),this.dispatchEvent(new CustomEvent(yl,{detail:{collapsed:t},bubbles:!0,composed:!0})))}get unread(){return this.#U}#$e(){let t=this.#S.readScopedItem(Vw);return t!==null?t==="1":Ot(this.getAttribute("placement")).startsCollapsed&&!this.hasAttribute("data-start-open")}describeSurface(){return this.#x.describeSurface()}moveTo(t,n={}){return this.#x.moveTo(t,n)}toggleCollapsed(){this.setCollapsed(!this.collapsed)}toggleTheme(){let t=this.getAttribute("theme")??"",n=t.split(/\s+/).includes("dark")?"light":"dark";this.setAttribute("theme",Ww(t,n)),this.#S.writePreference(jw,n),this.#Ie()}#Ae(t,n){this.#se=n;let r=this.#L,o=this.#S.conversationNamespace(t),i=this.#S.conversationNamespace(n);if(t===""){nt.adopt(o,i),r&&this.#ke(i);return}this.#Y={},nt.purge(o),r&&this.#ke(i),this.#j.forgetWaivers(),this.#$(),this.#ne(),this.#D={},this.#l.value="",this.#pe(),this.#K(!1),this.#re(0),r&&(this.#q.dispose(),this.#q.wire(),this.#h.adoptActiveThread(),this.#h.rehydrate(),this.#h.refreshDrawer())}#ke(t){let n=this.#S.rescopeStore(this.#Te(),t);n!==null&&(this.conversationStore=n,this.#Se())}#Ie(){let t=(this.getAttribute("theme")??"").split(/\s+/).includes("dark");this.#Z.replaceChildren(pr("theme","theme-icon",t?Ap:Tp,null))}openThreads(){this.#h.openThreads()}openCheckpoints(){this.#h.openCheckpoints()}closeThreads(){this.#E.close()}closeCheckpoints(){this.#_.close()}toggleCheckpoints(){if(this.#_.open_){this.#_.close();return}this.openCheckpoints()}newChat(){this.#$(),this.#h.reapUnsent(),this.#ne(),this.#h.startThread(),this.#K(!1),this.#re(0),this.collapsed||this.#l.focus({preventScroll:!0})}#ne(){this.#Re(),this.#Q.length=0,this.#N=null}#Re(){this.#O=null,this.#ie.detach(),this.#be={},this.#Ce(),this.#h.forgetRestored()}#Ce(){this.#we.end(),this.#v.releaseTurn(),this.#n.clear(),this.#v.forgetCards(),this.#o.clearBlocks(),this.#r.forget(),this.#I.tray?.clear(),this.removeAttribute("data-composer-settling"),this.removeAttribute("data-restoring"),this.#v.empty()}async retryLastTurn(){if(this.#R||this.#w!==null||this.#h.continuation!==null)return!1;let t={};this.#w=t;try{let n=this.#fe(),r=n.truncateToLastUser();if(r===null||this.#w!==t)return!1;this.#Ce();for(let o of r)if(this.#h.replay(o),this.#w!==t)return!1;return await n.resume(),!0}finally{this.#w===t&&(this.#w=null,this.#J())}}appendMessage(t,n){return this.#v.append(t,n)}#Ue(){let{signal:t}=this.#ee;this.#p.className="chat",this.#p.setAttribute("part","panel");let n=this.getAttribute("title-text")??this.#t.title,r=this.getAttribute("data-theme-toggle")!==null,{header:o,checkpoints:i}=Ny({host:this,title:this.#g,titleText:n,iconUrl:this.getAttribute("data-icon-url"),strings:this.#t,withCheckpoints:this.#h.runs()!==null,themeToggle:r?this.#Z:null,signal:t,onHistory:()=>this.openThreads(),onCheckpoints:()=>this.toggleCheckpoints(),onNewChat:()=>this.newChat(),onCollapse:()=>this.toggleCollapsed(),onToggleTheme:()=>this.toggleTheme()});r&&this.#Ie(),this.#x.enablePanelDrag(o),Cw({messages:this.#m,jumpButton:this.#u,emptyWrap:this.#z,greetingText:this.#me,starters:Ow(this,this.#t,c=>{this.sendMessage(c)}),strings:this.#t}),this.#xe(),this.#d.mount(t),this.#v.mountScroller(this.#u,t),this.#c.mount(),this.#m.append(this.#z),this.#v.updateEmptyState();let a=Rb({input:this.#l,send:this.#b,attachButton:this.#P,fileInput:this.#B,voiceSlot:this.#ae,hint:this.#C,queuedRow:this.#W,attachSlot:this.#A,strings:this.#t,signal:t,onKeydown:c=>this.#Fe(c),onInput:()=>this.#pe(),onSend:()=>{if(this.#R){this.#$();return}this.#he()},onFilesPicked:()=>this.#I.onFilesPicked()}),s=document.createElement("slot");s.name="footer",this.#f.className="messages-wrap",this.#f.replaceChildren(this.#m,this.#u,this.#d.button),this.#p.replaceChildren(o,this.#f,this.#y.palette,this.#y.chips,this.#C,this.#W,this.#A,a,s,this.#E.element,this.#_.element),this.#p.addEventListener("pointerdown",c=>{if(!this.#_.open_)return;let u=c.composedPath();u.includes(this.#_.element)||u.includes(i)||this.#_.close()},{signal:t}),Oy({launcher:this.#k,badge:this.#M,railLabel:this.#V,titleText:n,iconUrl:My(this),strings:this.#t,signal:t,onOpen:()=>this.setCollapsed(!1)}),this.#x.enableLauncherDrag(t),this.#x.mountResizeGrips(this.#p),this.#a=Cy(this.#i,this.#s);let l=this.#x.probe;l.className="viewport-probe",l.setAttribute("aria-hidden","true"),this.#i.replaceChildren(l,this.#c.region,this.#p,this.#k)}#Ne(){this.#k.setAttribute("aria-expanded",String(!this.collapsed));let t=this.#U;this.#M.textContent=t>9?"9+":String(t),this.#M.hidden=t===0||!Py(this);let n=this.#M.hidden?this.#t.expand:ue(this.#t.expandUnread,{count:t});this.#k.setAttribute("aria-label",n),this.#k.title=n}#re(t){this.#U=t,this.#Ne(),this.dispatchEvent(new CustomEvent(wl,{detail:{unread:t},bubbles:!0,composed:!0}))}#He(){this.collapsed&&this.#re(this.#U+1)}#pe(){this.#y.onInput(this.#l.value),this.#C.hidden=!0,jt(this.#l),this.#N=null}#Fe(t){if(this.#y.onKeydown(t)){t.preventDefault();return}if(t.key==="Escape"&&this.#R){t.preventDefault(),this.#$();return}if(t.key==="Enter"&&!t.shiftKey){t.preventDefault(),this.#he();return}this.#Ge(t)}#Ge(t){let n=t.key==="ArrowUp";if(!n&&t.key!=="ArrowDown"||this.#y.isOpen())return;let r=this.#Q;if(r.length===0||(this.#l.value!==this.#ge&&(this.#N=null),this.#N===null&&(!n||this.#l.value!=="")))return;let o=this.#N===null?0:this.#N+(n?1:-1);o>=r.length||(t.preventDefault(),this.#N=o<0?null:o,this.#l.value=o<0?"":r[o],this.#ge=this.#l.value,this.#l.setSelectionRange(this.#l.value.length,this.#l.value.length),jt(this.#l))}#$(){this.#H.length=0,this.#oe(),this.#ce.abort(),this.#O?.cancel(),this.#w=null,this.#h.stopContinuation()}#K(t){let n=this.#R&&!t;this.#R=t,t&&(this.#w=null);let r=t?this.#t.stop:this.#t.send;this.#b.title=r,this.#b.setAttribute("aria-label",r),this.#b.dataset.state=t?"running":"idle",n&&this.#J()}#J(){if(this.#R||this.#h.continuation!==null)return;let t=this.#H.shift();this.#oe(),t!==void 0&&this.sendMessage(t)}#oe(){this.#W.replaceChildren(),this.#W.hidden=this.#H.length===0;for(let[t,n]of this.#H.entries()){let r=document.createElement("button");r.type="button",r.className="queued-chip",r.setAttribute("part","queued-chip"),r.textContent=n,r.title=ue(this.#t.removeQueued,{text:n}),r.setAttribute("aria-label",r.title),r.addEventListener("click",()=>{this.#H.splice(t,1),this.#oe()}),this.#W.appendChild(r)}}#Oe(t){t!==""&&this.#Q[0]!==t&&this.#Q.unshift(t),this.#N=null}async#he(){let t=this.#l.value.trim(),n=this.#I.tray?.readyRefs()??[];if(!(t===""&&n.length===0)){if(this.#Oe(t),this.#R||this.#w!==null||this.#h.continuation!==null){t!==""&&(this.#H.push(t),this.#oe(),this.#l.value="",jt(this.#l));return}this.#l.value="",jt(this.#l),this.#I.tray?.hasPending()===!0&&this.#v.appendNotice("\u{1F4CE}",ue(this.#t.attachmentsStillUploading,{n:this.#I.tray.pendingCount()}),"attachment-pending"),this.#I.tray?.clearReady(),await this.sendMessage(t,n)}}async sendMessage(t,n=[]){if(t===""&&n.length===0)return!1;let r=this.#ye;if(r!==null&&this.#w===r.hold){let i={};return this.#w=i,await r.restored,this.#w!==i?!1:(this.#w=null,this.sendMessage(t,n))}if(this.#R||this.#w!==null||this.#h.continuation!==null)return!1;let o={};this.#w=o;try{if(this.#v.isEmpty()&&this.setAttribute("data-composer-settling",""),this.#Pe(t,n),this.#w!==o)return!1;let i=this.endpoint!=="";return await this.#Be(t,n),i}finally{this.#w===o&&(this.#w=null,this.#J())}}#Pe(t,n){let r=this.appendMessage(Ze.USER,t);n.length>0&&r.appendChild(as(n)),this.dispatchEvent(new CustomEvent(bl,{detail:{content:t,attachments:n},bubbles:!0,composed:!0}))}attachFile(t){return this.#I.attach(t)}async#Be(t,n){if(this.endpoint===""){console.error('<ag-ui-chat>: no endpoint is set, so this message was not sent and no request was made. Point the element at your AG-UI mount with the endpoint attribute (endpoint="/agent/"), or assign chat.endpoint before sending.'),this.#v.appendNotice("\u26A0",this.#t.notConnected,"not-connected");return}await this.#fe().send(t,n)}#fe(){return this.#O===null&&(this.#O=this.#Me({endpoint:this.endpoint,initialMessages:this.#h.restored,follows:[]})),this.#O}#Me(t){let n=this.#h.threadId,r=this.#Y,o=this.agentFactory({endpoint:t.endpoint,headers:this.#ue(),getHeaders:()=>this.#ue(),trustedOrigins:this.trustedOrigins,...this.#de(),threadId:n,initialMessages:t.initialMessages,initialState:this.#D});return new _o({agent:o,handlers:this.#ie.forClient(),getTools:()=>this.#T.advertise(),getContext:()=>this.#j.buildContext(),executeTool:i=>this.#j.execute(i),resolveInterrupts:i=>this.#j.resolveInterrupts(i),onPersist:i=>{if(r!==this.#Y)return;let a=[...t.follows,...i];this.conversationStore.saveMessages(n,a),t.onSaved?.(a)},onStateChanged:i=>{r===this.#Y&&this.#Ze(i)},connectionLostMessage:this.#t.connectionLost,unfinishedMessage:this.#t.callNotFinished,declinedMessage:this.#t.declinedAction,maxToolRounds:Bw(this)})}#Ze(t){this.#D={...t},this.dispatchEvent(new CustomEvent(El,{detail:{state:this.#D},bubbles:!0,composed:!0}))}#ze(t,n){this.#v.appendNotice("\u2922",t,"surface",n===null?void 0:{label:this.#t.undo,onActivate:n})}enableCharts(t=["tool","activity"]){let n=!this.#o.has(Fo)&&!this.#T.has(os);t.includes("activity")&&this.registerActivityRenderer({type:Fo,render:r=>{let o=dr(r);return o===null?null:eo(o)},removedNotice:this.#t.chartUndrawable}),t.includes("tool")&&this.registerTool(Ib()),n&&this.isConnected&&this.reload()}registerActivityRenderer(t){this.#o.register(t)}get unhandledActivityTypes(){return this.#o.unhandledTypes()}};function sR(e){let t=e?.removed;return typeof t=="number"?t:null}function lR(){customElements.get($o)===void 0&&customElements.define($o,ko)}async function cR(e,t,n={}){await It(e),await Ul(e,{...n,flashMs:n.flashMs??0}),await Dl(e,t,n)}async function uR(e,t={}){await It(e),await $l(e,t)}async function dR(e,t={}){await It(e),await Hl(e,t)}async function pR(e,t,n={}){await It(e),await Fl(e,t,n)}async function hR(e,t,n={}){await It(e),await Gl(e,t,n)}function fR(e,t){e instanceof HTMLInputElement&&e.type==="checkbox"?Ar(e,!!t):nn(e,String(t)),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}var mR="0.45.0";export{xl as ATTACHMENT_EVENT,ko as AgUiChat,_o as AgUiClient,Fo as CHART_ACTIVITY_TYPE,os as CHART_TOOL_NAME,Zo as CHAT_CORNERS,Cl as COMPACTION_ACTIVITY_TYPE,Sl as CUSTOM_AGENT_EVENT,ro as CheckpointMenu,Tr as ClientToolRegistry,Gs as ConnectionLostError,fe as DEFAULT_UI_STRINGS,$o as ELEMENT_TAG,Al as FEEDBACK_EVENT,Il as INVALIDATE_CUSTOM_NAME,Tl as INVALIDATE_EVENT,Nl as LOAD_CAPABILITY_TOOL,yA as MAX_QUOTE_CHARS,jI as MAX_SUGGESTIONS,WI as MAX_SUGGESTION_CHARS,Hn as MAX_TOOL_ROUNDS,en as MESSAGE_ACTIONS,Ze as MESSAGE_ROLE,Ir as PAGE_ACTIONS,_l as RUN_FINISHED_EVENT,Ao as RemoteConversationStore,oo as RunIndex,El as STATE_EVENT,bl as SUBMIT_EVENT,kl as SUGGESTIONS_ACTIVITY_TYPE,nt as SessionStorageStore,yl as TOGGLE_EVENT,te as TOOL_CALL_STATUS,Fn as TOOL_DISPLAY,Ve as TOOL_OUTCOME,co as ToolCallCard,wl as UNREAD_EVENT,mR as VERSION,Uo as X_CONFIRM_KEY,_r as X_DESTRUCTIVE_KEY,Sr as X_NAVIGATES_KEY,Oe as X_SUMMARY_KEY,ed as asQuote,ud as attachMessageActions,nd as attachQuoteOffer,dr as chartSpecFrom,uR as clickElement,Pl as createChatSurfaceTools,Dd as createHttpAgent,Bl as createPageActionTools,Zl as createPageMapContext,qo as createPageStateTools,Vl as createRouteTools,KE as createStateHookTools,lR as defineAgUiChat,cR as fillField,jE as flash,Ul as focusWithFlash,$l as highlightThenClick,Up as isChatCorner,Yu as isDestructive,ns as isNavigates,Bu as mergeUiStrings,Ts as messageActionBar,od as messageAttachments,Vu as parseToolCatalog,jo as prefersReducedMotion,dR as pressButton,Hl as pressThenClick,zd as prettifyToolName,to as quotableSelection,no as relativeTime,eo as renderChart,Eo as renderMarkdown,xo as renderSuggestionChips,ju as requestApproval,qu as requestConfirmation,Zu as requestQuestion,It as scrollIntoCenterView,pR as selectControl,Fl as selectOption,fR as setControlValue,Ar as setNativeChecked,nn as setNativeValue,Ml as showHighlightOverlay,Nw as suggestionPrompts,hR as toggleCheckbox,Gl as toggleControl,io as toolStatusFromOutcome,Qu as transcribeAudio,Dl as typeInto,Ku as uploadAttachment};
|
|
4828
|
+
`}tablerow({text:t}){return`<tr>
|
|
4829
|
+
${t}</tr>
|
|
4830
|
+
`}tablecell(t){let e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
|
|
4831
|
+
`}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${nt(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,text:n,tokens:r,autolink:o}){let i=o?nt(n,!0):this.parser.parseInline(r),a=_w(t);if(a===null)return i;t=nt(a,o);let s='<a href="'+t+'"';return e&&(s+=' title="'+nt(e)+'"'),s+=">"+i+"</a>",s}image({href:t,title:e,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let o=_w(t);if(o===null)return nt(n);t=o;let i=`<img src="${nt(t)}" alt="${nt(n)}"`;return e&&(i+=` title="${nt(e)}"`),i+=">",i}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:nt(t.text)}},Fd=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}checkbox({raw:t}){return t}},ft=class Pd{options;renderer;textRenderer;constructor(e){this.options=e||Mn,this.options.renderer=this.options.renderer||new Us,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Fd}static parse(e,n){return new Pd(n).parse(e)}static parseInline(e,n){return new Pd(n).parseInline(e)}parse(e){this.renderer.parser=this;let n="";for(let r=0;r<e.length;r++){let o=e[r];if(this.options.extensions?.renderers?.[o.type]){let a=o,s=this.options.extensions.renderers[a.type].call({parser:this},a);if(s!==!1||!["space","hr","heading","code","table","blockquote","list","checkbox","html","def","paragraph","text"].includes(a.type)){n+=s||"";continue}}let i=o;switch(i.type){case"space":{n+=this.renderer.space(i);break}case"hr":{n+=this.renderer.hr(i);break}case"heading":{n+=this.renderer.heading(i);break}case"code":{n+=this.renderer.code(i);break}case"table":{n+=this.renderer.table(i);break}case"blockquote":{n+=this.renderer.blockquote(i);break}case"list":{n+=this.renderer.list(i);break}case"checkbox":{n+=this.renderer.checkbox(i);break}case"html":{n+=this.renderer.html(i);break}case"def":{n+=this.renderer.def(i);break}case"paragraph":{n+=this.renderer.paragraph(i);break}case"text":{n+=this.renderer.text(i);break}default:{let a='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return n}parseInline(e,n=this.renderer){this.renderer.parser=this;let r="";for(let o=0;o<e.length;o++){let i=e[o];if(this.options.extensions?.renderers?.[i.type]){let s=this.options.extensions.renderers[i.type].call({parser:this},i);if(s!==!1||!["escape","html","link","image","checkbox","strong","em","codespan","br","del","text"].includes(i.type)){r+=s||"";continue}}let a=i;switch(a.type){case"escape":{r+=n.text(a);break}case"html":{r+=n.html(a);break}case"link":{r+=n.link(a);break}case"image":{r+=n.image(a);break}case"checkbox":{r+=n.checkbox(a);break}case"strong":{r+=n.strong(a);break}case"em":{r+=n.em(a);break}case"codespan":{r+=n.codespan(a);break}case"br":{r+=n.br(a);break}case"del":{r+=n.del(a);break}case"text":{r+=n.text(a);break}default:{let s='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return r}},xo=class{options;block;constructor(t){this.options=t||Mn}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(t=this.block){return t?ht.lex:ht.lexInline}provideParser(t=this.block){return t?ft.parse:ft.parseInline}};function Nn(t,e){if(Array.isArray(e))for(let n=0;n<e.length;n++)t.push(e[n]);else t.push(e)}var Gd=class{defaults=Md();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=ft;Renderer=Us;TextRenderer=Fd;Lexer=ht;Tokenizer=$s;Hooks=xo;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let r of t)switch(Nn(n,e.call(this,r)),r.type){case"table":{let o=r;for(let i of o.header)Nn(n,this.walkTokens(i.tokens,e));for(let i of o.rows)for(let a of i)Nn(n,this.walkTokens(a.tokens,e));break}case"list":{let o=r;Nn(n,this.walkTokens(o.items,e));break}default:{let o=r;this.defaults.extensions?.childTokens?.[o.type]?this.defaults.extensions.childTokens[o.type].forEach(i=>{let a=o[i].flat(1/0);Nn(n,this.walkTokens(a,e))}):o.tokens&&Nn(n,this.walkTokens(o.tokens,e))}}return n}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{let r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if("renderer"in o){let i=e.renderers[o.name];i?e.renderers[o.name]=function(...a){let s=o.renderer.apply(this,a);return s===!1&&(s=i.apply(this,a)),s}:e.renderers[o.name]=o.renderer}if("tokenizer"in o){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=e[o.level];i?i.unshift(o.tokenizer):e[o.level]=[o.tokenizer],o.start&&(o.level==="block"?e.startBlock?e.startBlock.push(o.start):e.startBlock=[o.start]:o.level==="inline"&&(e.startInline?e.startInline.push(o.start):e.startInline=[o.start]))}"childTokens"in o&&o.childTokens&&(e.childTokens[o.name]=o.childTokens)}),r.extensions=e),n.renderer){let o=this.defaults.renderer||new Us(this.defaults);for(let i in n.renderer){if(!(i in o))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let a=i,s=n.renderer[a],c=o[a];o[a]=(...l)=>{let u=s.apply(o,l);return u===!1&&(u=c.apply(o,l)),u||""}}r.renderer=o}if(n.tokenizer){let o=this.defaults.tokenizer||new $s(this.defaults);for(let i in n.tokenizer){if(!(i in o))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let a=i,s=n.tokenizer[a],c=o[a];o[a]=(...l)=>{let u=s.apply(o,l);return u===!1&&(u=c.apply(o,l)),u}}r.tokenizer=o}if(n.hooks){let o=this.defaults.hooks||new xo;for(let i in n.hooks){if(!(i in o))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let a=i,s=n.hooks[a],c=o[a];xo.passThroughHooks.has(i)?o[a]=l=>{if(this.defaults.async&&xo.passThroughHooksRespectAsync.has(i))return(async()=>{let f=await s.call(o,l);return c.call(o,f)})();let u=s.call(o,l);return c.call(o,u)}:o[a]=(...l)=>{if(this.defaults.async)return(async()=>{let f=await s.apply(o,l);return f===!1&&(f=await c.apply(o,l)),f})();let u=s.apply(o,l);return u===!1&&(u=c.apply(o,l)),u}}r.hooks=o}if(n.walkTokens){let o=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(a){let s=[];return s.push(i.call(this,a)),o&&Nn(s,o.call(this,a)),s}}this.defaults={...this.defaults,...r}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return ht.lex(t,e??this.defaults)}parser(t,e){return ft.parse(t,e??this.defaults)}parseMarkdown(t){return(e,n)=>{let r={...n},o={...this.defaults,...r},i=this.onError(!!o.silent,!!o.async);if(this.defaults.async===!0&&r.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(o.hooks&&(o.hooks.options=o,o.hooks.block=t),o.async)return(async()=>{let a=o.hooks?await o.hooks.preprocess(e):e,s=await(o.hooks?await o.hooks.provideLexer(t):t?ht.lex:ht.lexInline)(a,o),c=o.hooks?await o.hooks.processAllTokens(s):s;o.walkTokens&&await Promise.all(this.walkTokens(c,o.walkTokens));let l=await(o.hooks?await o.hooks.provideParser(t):t?ft.parse:ft.parseInline)(c,o);return o.hooks?await o.hooks.postprocess(l):l})().catch(i);try{o.hooks&&(e=o.hooks.preprocess(e));let a=(o.hooks?o.hooks.provideLexer(t):t?ht.lex:ht.lexInline)(e,o);o.hooks&&(a=o.hooks.processAllTokens(a)),o.walkTokens&&this.walkTokens(a,o.walkTokens);let s=(o.hooks?o.hooks.provideParser(t):t?ft.parse:ft.parseInline)(a,o);return o.hooks&&(s=o.hooks.postprocess(s)),s}catch(a){return i(a)}}}onError(t,e){return n=>{if(n.message+=`
|
|
4832
|
+
Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error occurred:</p><pre>"+nt(n.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(n);throw n}}},Pn=new Gd;function pe(t,e){return Pn.parse(t,e)}pe.options=pe.setOptions=function(t){return Pn.setOptions(t),pe.defaults=Pn.defaults,Rw(pe.defaults),pe};pe.getDefaults=Md;pe.defaults=Mn;function JI(...t){return Pn.use(...t),pe.defaults=Pn.defaults,Rw(pe.defaults),pe}pe.use=JI;pe.walkTokens=function(t,e){return Pn.walkTokens(t,e)};pe.parseInline=Pn.parseInline;pe.Parser=ft;pe.parser=ft.parse;pe.Renderer=Us;pe.TextRenderer=Fd;pe.Lexer=ht;pe.lexer=ht.lex;pe.Tokenizer=$s;pe.Hooks=xo;pe.parse=pe;var lU=pe.options,cU=pe.setOptions,uU=pe.walkTokens,dU=pe.parseInline;var pU=ft.parse,hU=ht.lex;var QI=new Gd({gfm:!0,breaks:!0}),$w=["a","p","br","strong","em","b","i","u","s","del","code","pre","ul","ol","li","blockquote","h1","h2","h3","h4","h5","h6","hr","span","table","thead","tbody","tr","th","td"],Uw=["href","title","class","target","rel"],Hw={ALLOWED_TAGS:$w,ALLOWED_ATTR:Uw,ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!1},eR={...Hw,ALLOWED_TAGS:[...$w,"img"],ALLOWED_ATTR:[...Uw,"src","alt","width","height"]},tR=/^language-[A-Za-z0-9_+#.-]+$/,nR=new Set(["CODE","PRE"]);function rR(t){t.nodeName==="A"&&t.hasAttribute("href")?(t.setAttribute("target","_blank"),t.setAttribute("rel","noopener noreferrer")):(t.removeAttribute("target"),t.removeAttribute("rel"));let e=t.getAttribute("class");if(e===null)return;let n=nR.has(t.nodeName)?e.split(/\s+/).filter(r=>tR.test(r)):[];if(n.length===0){t.removeAttribute("class");return}t.setAttribute("class",n.join(" "))}var Hs=null;function oR(){return Hs===null&&(Hs=bw(),Hs.addHook("afterSanitizeAttributes",rR)),Hs}function Ao(t,e){let n=e?.allowImages===!0,r=QI.parse(t,{async:!1});return oR().sanitize(r,n?eR:Hw).trim()}var Fs=class{#e;#t=null;#n=0;#o="";#r=null;constructor(e){this.#e=e}get deltas(){return this.#n}countDelta(){this.#n+=1}queue(e){this.#o=e,this.#i(),this.#r===null&&(this.#r=requestAnimationFrame(()=>{this.#r=null,this.into(this.#o)}))}into(e){this.#r!==null&&(cancelAnimationFrame(this.#r),this.#r=null),this.#o=e;let n=this.#i();return n.innerHTML=Ao(e,{allowImages:this.#e.allowImages()}),this.#e.follow(),n}end(){this.#r!==null&&this.into(this.#o),this.#t=null}#i(){return this.#t===null&&(this.#t=this.#e.openBubble(),this.#n=0),this.#t}};function Fw(t){let{messages:e,jumpButton:n,emptyWrap:r,strings:o}=t;e.className="messages",e.setAttribute("part","messages"),e.setAttribute("role","log"),e.setAttribute("aria-live","off"),e.setAttribute("aria-label",o.conversation),n.className="jump-latest",n.type="button",n.setAttribute("part","jump-latest"),n.textContent=o.jumpToLatest,r.className="empty",r.setAttribute("part","empty");let i=document.createElement("div");i.className="greeting",i.setAttribute("part","greeting");let a=document.createElement("slot");a.name="greeting",a.append(t.greetingText),i.append(a);let s=document.createElement("slot");s.name="empty",t.starters!==null&&s.append(t.starters),r.replaceChildren(i,s)}var iR=4,aR=120;function Gw(t){if(typeof t!="object"||t===null)return null;let e=t.prompts;if(!Array.isArray(e))return null;let n=e.filter(r=>typeof r=="string").map(r=>r.trim()).filter(r=>r!==""&&r.length<=120).slice(0,4);return n.length===0?null:n}function ko(t,e,n){let r=Gw(t);if(r===null)return null;let o=document.createElement("div");o.className="suggestions",o.setAttribute("part","suggestions"),o.setAttribute("role","group"),o.setAttribute("aria-label",e.suggestions);for(let i of r){let a=document.createElement("button");a.type="button",a.className="suggestion-chip",a.setAttribute("part","suggestion-chip"),a.textContent=i,a.addEventListener("click",()=>n(i)),o.appendChild(a)}return o}function Bw(t,e,n){let r=t.getAttribute("data-starters");if(r===null)return null;let o;try{o=JSON.parse(r)}catch{return console.warn(`<ag-ui-chat>: data-starters is not valid JSON, so no starters are shown. It takes an array of strings, e.g. data-starters='["Summarise this page"]'.`),null}return ko({prompts:o},e,n)}function Gs(t,e){for(let n of Array.from(t.querySelectorAll("pre"))){let r=n.querySelector("code");r===null||n.querySelector(".code-copy")!==null||(n.classList.add("has-copy"),n.append(sR(r,e)))}}function sR(t,e){let n=t.textContent,r=document.createElement("button");return r.type="button",r.className="code-copy",r.setAttribute("part","code-copy"),r.textContent=e.copyCode,r.title=e.copyCode,r.setAttribute("aria-label",e.copyCode),r.addEventListener("click",()=>{lR(n).then(o=>{cR(r,o?e.copied:e.copyFailed,e)})}),r}async function lR(t){let e=navigator.clipboard;if(e===void 0)return!1;try{return await e.writeText(t),!0}catch{return!1}}function cR(t,e,n){t.textContent=e,t.dataset.state=e===n.copied?"copied":"failed",setTimeout(()=>{t.textContent=n.copyCode,delete t.dataset.state},1500)}function Bd(t){let e=t.replace(/[._-]+/g," ").trim();return e===""?t:e.charAt(0).toUpperCase()+e.slice(1)}var Bs=class{element;#e;#t;#n;#o;#r=!1;constructor(e=fe){this.#o=e,this.element=document.createElement("div"),this.element.className="thoughts",this.element.setAttribute("part","thoughts"),this.element.setAttribute("data-streaming",""),this.#n=document.createElement("button"),this.#n.type="button",this.#n.className="thoughts-toggle",this.#n.setAttribute("part","thoughts-toggle"),this.#n.setAttribute("aria-expanded","true"),this.#e=document.createElement("span"),this.#e.className="thoughts-label",this.#e.setAttribute("part","thoughts-label"),this.#e.textContent=e.thinking,this.#n.append(this.#e),this.#t=document.createElement("pre"),this.#t.className="thoughts-body",this.#t.setAttribute("part","thoughts-body"),this.#n.addEventListener("click",()=>{this.#i(!this.#r)}),this.element.append(this.#n,this.#t)}stream(e){this.#t.textContent=e}collapse(){this.#r||(this.element.removeAttribute("data-streaming"),this.#e.textContent=this.#o.thoughts,this.#i(!0))}#i(e){this.#r=e,this.#t.hidden=e,this.#n.setAttribute("aria-expanded",String(!e))}};var uR=new Set([K.PENDING,K.DEFERRED]),dR=`.tool-call-subagent > .subagent:is(${[yt.STARTED,yt.TOOL_CALL,yt.TOOL_RESULT].map(t=>`[data-phase="${t}"]`).join(", ")})`,pR=["data-status","data-asking","data-phase","data-agent"],Zs=class{element;#e;#t;#n;#o;#r;#i=[];#a=!1;constructor(e){this.#e=e,this.element=document.createElement("div"),this.element.className="tool-group",this.element.setAttribute("part","tool-group"),this.element.setAttribute("data-open","false"),this.#n=document.createElement("button"),this.#n.type="button",this.#n.className="tool-group-head",this.#n.setAttribute("part","tool-group-head"),this.#n.setAttribute("aria-expanded","false");let n=document.createElement("span");n.className="tool-group-icon",n.setAttribute("part","tool-group-icon"),n.setAttribute("aria-hidden","true"),this.#o=document.createElement("span"),this.#o.className="tool-group-label",this.#o.setAttribute("part","tool-group-label"),this.#r=document.createElement("span"),this.#r.className="tool-group-meta",this.#r.setAttribute("part","tool-group-meta");let r=document.createElement("span");r.className="tool-group-chevron",r.setAttribute("aria-hidden","true"),this.#n.append(n,this.#o,this.#r,r),this.#n.addEventListener("click",()=>{this.setOpen(this.element.getAttribute("data-open")!=="true")}),this.#t=document.createElement("div"),this.#t.className="tool-group-list",this.#t.setAttribute("part","tool-group-list"),this.element.append(this.#n,this.#t),new MutationObserver(()=>{this.#l()}).observe(this.#t,{attributes:!0,attributeFilter:[...pR],subtree:!0})}add(e,n){let r=this.#i.filter(i=>i.name===n).length+1,o=n;if(r>1){let i=document.createElement("span");i.className="tool-call-repeat",i.setAttribute("part","tool-card-repeat"),i.textContent=re(this.#e.toolStepRepeat,{n:r}),e.querySelector(".tool-call-name")?.after(i),o=`${n} ${i.textContent}`}this.#i.push({element:e,name:n,label:o}),this.#t.append(e),this.#l()}setOpen(e){this.element.setAttribute("data-open",String(e)),this.#n.setAttribute("aria-expanded",String(e))}reveal(){this.#a=!0,this.setOpen(!0)}#s(){for(let{element:e}of this.#i){let n=e.getAttribute("data-status")===K.PENDING?e.querySelector(dR):null;if(n!==null){let r=n.getAttribute("data-agent");return r===null?this.#e.subAgentWorking:re(this.#e.subAgentDelegatedTo,{agent:r})}}return null}#l(){let e=this.#e,n=this.#i,r=n.map(w=>w.element.getAttribute("data-status")??""),o=n.filter((w,b)=>uR.has(r[b])),i=w=>r.filter(b=>b===w).length,a=i(K.ERROR),s=i(K.DECLINED),c=i(K.DEFERRED),l=n.filter(w=>w.element.hasAttribute("data-asking")).length,u=c+l,f=n.length;c>0&&!this.#a?(this.#a=!0,this.setOpen(!0)):c===0&&(this.#a=!1);let m="done";u>0?m="waiting":o.length>0?m="running":a>0&&(m="error"),this.element.setAttribute("data-state",m),this.element.setAttribute("part",`tool-group tool-group-${m}`),this.element.setAttribute("data-count",String(f));let p=f===1?n[0]:void 0;if(p!==void 0)this.#o.textContent=p.label;else{let w=m==="waiting"?e.toolGroupSteps:m==="running"?e.toolGroupWorking:e.toolGroupWorked;this.#o.textContent=re(w,{count:f})}let h=[],x=this.#s(),g=o[0];u>0?h.push(re(e.toolGroupWaiting,{count:u})):x!==null?h.push(x):g!==void 0&&f>1&&h.push(g.label),a>0&&h.push(re(e.toolGroupFailed,{count:a})),s>0&&h.push(re(e.toolGroupDeclined,{count:s})),this.#r.replaceChildren(...h.map(w=>{let b=document.createElement("span");return b.className="tool-group-note",b.textContent=w,b})),this.#r.hidden=h.length===0}};function Zw(t){return t===Ct.GROUPED}function Vs(t,e){try{return t()}catch(n){return console.warn(`ag-ui-chat: render failed for ${e}`,n),null}}function Vw(t,e){for(let n of Array.from(t.childNodes))n.nodeType===Node.TEXT_NODE?e.push({node:n,parent:t}):Vw(n,e)}function jw(t){let e=[];Vw(t,e);let n=0;for(let{node:r,parent:o}of e){let i=document.createDocumentFragment();for(let a of r.data.split(/(\s+)/)){if(a==="")continue;if(/\s/.test(a)){i.appendChild(document.createTextNode(a));continue}let s=document.createElement("span");s.className="word",s.style.setProperty("--ag-ui-word-index",String(n)),s.textContent=a,i.appendChild(s),n+=1}o.replaceChild(i,r)}}function Ww({viewport:t,onMissedContent:e}){let n=!0,r=!1,o=()=>t.scrollHeight-t.scrollTop-t.clientHeight<=4,i=u=>{u!==r&&(r=u,e(r))},a=()=>{t.scrollTop=t.scrollHeight},s=()=>{n=o(),n&&i(!1)},c=()=>{if(n){a();return}i(!0)};t.addEventListener("scroll",s,{passive:!0});let l=new ResizeObserver(()=>{n&&a()});return l.observe(t),{follow:c,jump:()=>{n=!0,i(!1),a()},following:()=>n,dispose:()=>{t.removeEventListener("scroll",s),l.disconnect()}}}var js=class{#e;#t=new Map;#n=new Map;#o=new Map;#r=new Set;#i;#a=null;#s=null;#l=null;#u=new WeakMap;#d=new WeakMap;#f=new WeakMap;constructor(e){this.#e=e}mountScroller(e,n){e.addEventListener("click",()=>{this.jump()},{signal:n}),this.#i=Ww({viewport:this.#e.messages,onMissedContent:r=>{e.dataset.missed=String(r)}})}disposeScroller(){this.#i.dispose()}follow(){this.#i.follow()}jump(){this.#i.jump()}isEmpty(){return!this.#e.emptyWrap.hidden}card(e){return this.#t.get(e)}cards(){return this.#t.values()}forgetCard(e){this.#t.delete(e)}setCardElement(e,n){this.#n.set(e,n)}markServerSettled(e){this.#r.add(e)}isServerSettled(e){return this.#r.has(e)}collapseThoughts(){this.#l?.collapse()}closeGroup(){this.#s!==null&&this.#s.childElementCount===0&&(this.#s.remove(),this.updateEmptyState()),this.#s=null,this.#l=null}releaseTurn(){this.#s=null,this.#l=null,this.hidePending(),this.#t.clear()}forgetCards(){this.#r.clear(),this.#n.clear(),this.#o.clear()}holdRunning(e,n){this.#o.set(e,n)}setAsking(e,n){this.#o.get(e)?.setAsking(n)}empty(){this.#e.messages.replaceChildren(this.#e.emptyWrap),this.updateEmptyState()}append(e,n){let r=document.createElement("div");return r.className=`message message--${e}`,r.setAttribute("part",`message message-${e}`),e===Ve.ASSISTANT?(r.innerHTML=Ao(n,{allowImages:this.#e.allowImages()}),Gs(r,this.#e.strings()),this.ensureGroup().appendChild(r)):(this.#s=null,r.textContent=n,this.#e.messages.appendChild(r)),this.updateEmptyState(),e===Ve.USER?this.jump():this.follow(),r}ensureGroup(){if(this.#s===null){let e=document.createElement("div");e.className="answer",e.setAttribute("part","answer"),this.#s=e,this.#e.messages.appendChild(e),this.updateEmptyState()}return this.#s}revealWords(e){this.#e.element.getAttribute("data-text-animation")==="word"&&jw(e)}updateEmptyState(){this.#e.emptyWrap.hidden=this.#e.messages.childElementCount>1,this.#e.element.toggleAttribute("data-empty",!this.#e.emptyWrap.hidden)}appendStoppedNote(){let e=document.createElement("div");e.className="stopped-note",e.setAttribute("part","stopped"),e.setAttribute("role","status"),e.textContent=this.#e.strings().stopped,this.ensureGroup().appendChild(e),this.updateEmptyState(),this.follow()}showPending(){if(this.#a!==null)return;let e=document.createElement("div");e.className="pending",e.setAttribute("part","pending"),e.setAttribute("role","status"),e.setAttribute("aria-label",this.#e.strings().thinking);for(let n=0;n<3;n+=1){let r=document.createElement("span");r.className="pending-dot",e.appendChild(r)}this.#a=e,this.ensureGroup().appendChild(e),this.updateEmptyState(),this.follow()}hidePending(){this.#a?.remove(),this.#a=null}showThoughts(){if(this.#l===null){this.#l=new Bs(this.#e.strings());let e=this.ensureGroup();e.insertBefore(this.#l.element,e.firstChild),this.updateEmptyState(),this.follow()}return this.#l}noticeIfSkillLoad(e){let n=is(e);return n===null?!1:(this.appendNotice("\u2728",re(this.#e.strings().usingSkill,{name:n}),"skill"),!0)}appendNotice(e,n,r,o){this.ensureGroup().appendChild(Ts(e,n,r,o)),this.updateEmptyState(),this.follow()}renderToolOutput(e,n){let r=Vs(()=>e(n.args),`tool ${n.name}`);if(r===null)return;let o=this.#n.get(n.id),i=o?.closest(".tool-group");if(i==null)o?.after(r);else{let a=this.#d.get(i);a===void 0&&(a=document.createComment(""),i.after(a),this.#d.set(i,a));let s=r instanceof DocumentFragment?[...r.children]:[r];a.before(r);for(let c of s)this.#f.set(c,i)}this.afterGrew()}afterGrew(){this.updateEmptyState(),this.follow()}cardFor(e){let n=this.#t.get(e.id);if(n!==void 0)return n;let r=this.#e.resolveTool(e.name)?.parameters[Pe],o=typeof r=="string"?r:this.#e.toolSummaries()[e.name]??this.#e.serverSummary(e.name)??Bd(e.name),i=new mo(e.name,e.args,o,this.#e.strings(),{formatPayload:a=>this.#e.formatToolPayload(a)});return this.#t.set(e.id,i),Zw(this.#e.toolDisplay())?this.#p().add(i.element,o):this.ensureGroup().appendChild(i.element),this.updateEmptyState(),this.follow(),i}revealStep(e){let n=e.element.closest(".tool-group");(n===null?void 0:this.#u.get(n))?.reveal()}#p(){let e=this.ensureGroup(),n=e.lastElementChild,r=n===null?void 0:this.#u.get(this.#f.get(n)??n);if(r!==void 0)return r;let o=new Zs(this.#e.strings());return this.#u.set(o.element,o),n===null?e.prepend(o.element):n.after(o.element),o}};var Ws=class{#e;#t=new Map;#n=new Set;#o=new Map;constructor(e){this.#e=e}register(e){this.#t.set(e.type,e),this.#n.delete(e.type)}has(e){return this.#t.has(e)}unhandledTypes(){return[...this.#n]}clearBlocks(){this.#o.clear()}draw(e,n,r){let o=this.#t.get(n);if(o===void 0){this.#n.add(n);return}let i=Vs(()=>o.render(r),`activity ${n}`);if(i===null){this.#r(e,n,o.removedNotice,r);return}let a=this.#o.get(e);a===void 0?this.#e.ensureGroup().appendChild(i):a.replaceWith(i),this.#o.set(e,i),this.#e.afterTranscriptGrew()}#r(e,n,r,o){let i=this.#o.has(e);this.#o.get(e)?.remove(),this.#o.delete(e),console.warn(`ag-ui-chat: activity ${e} (${n}) was not drawable and has been removed. A chart's points must each be a finite JSON number; a numeric column serialised as a string (a Decimal, typically) is rejected rather than coerced.`,o),i&&r!==void 0&&this.#e.appendNotice("\u{1F4C9}",r,"chart-undrawable")}};var qs=class extends Error{constructor(e){super(e),this.name="ConnectionLostError"}},Io=class{#e;#t;#n;#o;#r;#i;#a;#s=new Set;#l;#u;#d;#f;#p=!1;constructor(e){this.#e=e.agent,this.#t=e.handlers,this.#n=e.getTools??(()=>[]),this.#o=e.getContext??(()=>[]),this.#r=e.executeTool??null,this.#i=e.resolveInterrupts??null,this.#a=e.onPersist??(()=>{}),this.#l=e.connectionLostMessage??"Connection lost",this.#u=e.unfinishedMessage??"Not finished: the run ended or moved on before this tool call returned a result.",this.#d=e.declinedMessage??"User declined the action.";let n=e.maxToolRounds??Bn;this.#f=n>=1?Math.floor(n):Bn,this.#b();let r=e.onStateChanged;r!==void 0&&this.#e.subscribe({onStateChanged:({state:o})=>{r(o)}})}get state(){return this.#e.state}setState(e){this.#e.setState({...e})}get running(){return this.#e.isRunning}get messages(){return this.#e.messages}async send(e,n=[]){this.#p=!1;let r={id:Se(),role:"user",content:e,...n.length>0?{metadata:{attachments:n}}:{}};this.#e.addMessage(r),this.#E(),await this.#m()}truncateToLastUser(){let e=[...this.#e.messages],n=-1;for(let[o,i]of e.entries())i.role==="user"&&(n=o);if(n===-1)return null;let r=e.slice(0,n+1);return this.#a(r),this.#e.setMessages(r),r}async resume(){this.#p=!1,await this.#m()}addToolResult(e,n){this.#e.addMessage({id:Se(),role:"tool",content:n,toolCallId:e}),this.#E()}cancel(){this.#p=!0,this.#e.abortRun()}async#m(){try{await this.#_(),this.#p&&this.#c()}catch(e){this.#p||hR(e)?this.#c():this.#t.onError(e instanceof Error?e.message:String(e))}finally{this.#t.onSettled()}}#c(){this.#E(),this.#t.onCancelled()}#b(){let e=this.#e.messages,n=e.map(fR);n.some((r,o)=>r!==e[o])&&this.#e.setMessages(n)}#g(e){let n=this.#e.messages,r=ns(n,o=>({id:Se(),role:"tool",content:this.#u,toolCallId:o,metadata:{outcome:je.INTERRUPTED}}),e);r!==n&&(this.#e.setMessages([...r]),this.#E())}#y(e,n){for(let r of e){let o=r.toolCallId;o!==void 0&&n[r.id]?.status==="cancelled"&&this.#e.addMessage({id:Se(),role:"tool",content:this.#d,toolCallId:o,metadata:{outcome:je.DENIED}})}this.#E()}#E(){this.#a(this.#e.messages)}get annotatedMessages(){return this.messages}async#_(){let e,n=new Set;for(let r=0;r<this.#f;r+=1){if(this.#p)return;let o=[],i={terminal:!1,errored:!1,interrupts:[]},a={tools:this.#n(),context:this.#o()};if(e!==void 0&&(a.resume=e),this.#g(n),this.#p||(await this.#e.runAgent(a,this.#h(o,i)),e=void 0,n=new Set,this.#E(),this.#p))return;if(!i.terminal)throw new qs(this.#l);if(i.errored)return;if(i.interrupts.length>0){if(this.#i===null)return;let c=await this.#i(i.interrupts);if(this.#p){this.#y(i.interrupts,c);return}e=Ib(i.interrupts,c),n=new Set(i.interrupts.flatMap(({toolCallId:l})=>l??[]));continue}if(this.#r===null||o.length===0)return;let s=!1;for(let c of o){if(this.#p)return;let l=await this.#r(c);if(l!==null){if(l.halt===!0)return;this.#e.addMessage({id:Se(),role:"tool",content:l.content,toolCallId:c.id,...l.outcome===void 0?{}:{metadata:{outcome:l.outcome}}}),this.#E(),s=!0}}if(!s)return}}#h(e,n){let r=this.#t,o=this.#s,i=()=>this.#p,a=new Set,s;return{onRunInitialized(){r.onRunStart()},onRunStartedEvent({event:c}){s=c.runId},onTextMessageStartEvent({event:c}){o.has(c.messageId)&&console.warn(`<ag-ui-chat>: the server reused message id "${c.messageId}", which was already closed. Its content will be appended to that earlier message rather than starting a new one, and the merged result is what gets persisted. Issue a fresh id per message.`)},onTextMessageContentEvent({textMessageBuffer:c}){r.onTextDelta(c)},onTextMessageEndEvent({event:c,textMessageBuffer:l}){o.add(c.messageId),r.onTextEnd(l,{messageId:c.messageId,...s===void 0?{}:{runId:s}})},onToolCallEndEvent({event:c,toolCallName:l,toolCallArgs:u}){let f={id:c.toolCallId,name:l,args:u};e.push(f),r.onToolCall(f)},onToolCallResultEvent({event:c}){let l=c.metadata?.outcome;r.onToolResult(c.toolCallId,jn(c.content),l)},onActivitySnapshotEvent({event:c,messages:l}){if(l.some(f=>f.id===c.messageId&&f.role==="activity")){r.onActivityChanged(c.messageId,c.activityType,c.content);return}r.onActivity(c.activityType,c.content,c.messageId)},onActivityDeltaEvent({event:c}){a.add(c.messageId)},onCustomEvent({event:c}){r.onCustomEvent(c.name,c.value)},onSubagentStartedEvent({event:c}){r.onSubAgentStarted(c.subagentRunId,c.name,c.parentToolCallId??null)},onSubagentFinishedEvent({event:c}){r.onSubAgentFinished(c.subagentRunId)},onSubagentErrorEvent({event:c}){r.onSubAgentError(c.subagentRunId,c.message)},onMessagesSnapshotEvent({event:c}){r.onMessagesSnapshot(c.messages)},onMessagesChanged({messages:c}){if(a.size!==0){for(let l of a){let u=c.find(f=>f.id===l);u!==void 0&&u.role==="activity"&&r.onActivityChanged(l,u.activityType,u.content)}a.clear()}},onReasoningStartEvent(){r.onReasoningStart()},onReasoningMessageContentEvent({reasoningMessageBuffer:c}){r.onReasoningDelta(c)},onReasoningMessageEndEvent({reasoningMessageBuffer:c}){r.onReasoningDelta(c)},onReasoningEndEvent(){r.onReasoningEnd()},onRunFinishedEvent(c){n.terminal=!0,c.outcome==="interrupt"&&(n.interrupts=c.interrupts)},onRunErrorEvent({event:c}){n.terminal=!0,n.errored=!0,!i()&&r.onError(c.message)},onRunFinalized(){n.terminal=!0,r.onRunEnd()}}}};function hR(t){return t instanceof Error?t.name==="AbortError"||t instanceof TypeError&&/abort/i.test(t.message):!1}function fR(t){let{outcome:e,attachments:n,...r}=t;if(e===void 0&&n===void 0)return t;let o=r.metadata;return{...r,metadata:{...e===void 0?{}:{outcome:e},...n===void 0?{}:{attachments:n},...typeof o=="object"?o:{}}}}var qw="ag-ui-chat",yr="thread",Zd="threads",Ro="messages:",Ks="checkpoint:",Co="minted:",mR=60,gR=100,vR="New conversation",Yw=!1;function mt(t,e){try{sessionStorage.setItem(t,e)}catch{if(Yw)return;Yw=!0,console.warn("<ag-ui-chat>: the browser refused a sessionStorage write \u2014 the quota is full, or storage is disabled for this context. The conversation continues, but it will not survive a page reload. Deleting a long conversation from the history drawer frees the quota.")}}function Ys(t){return t===""?qw:`${qw}@${t}`}var rt=class t{#e;constructor(e=""){this.#e=Ys(e),e!==""&&t.adopt("",e)}static adopt(e,n){let r=`${Ys(e)}:`,o=`${Ys(n)}:`;for(let[i,a]of Kw(r)){let s=sessionStorage.getItem(i),c=o+a;s!==null&&sessionStorage.getItem(c)===null&&mt(c,s),sessionStorage.removeItem(i)}}static purge(e){for(let[n]of Kw(`${Ys(e)}:`))sessionStorage.removeItem(n)}threadId(){return sessionStorage.getItem(this.#r(yr))??this.newThread()}newThread(){let e=Se();return mt(this.#r(yr),e),mt(this.#r(Co+e),"1"),e}isUnsent(e){return sessionStorage.getItem(this.#r(Co+e))!==null&&sessionStorage.getItem(this.#r(Ro+e))===null}loadMessages(e){return Promise.resolve(this.#i(this.#r(Ro+e)))}saveMessages(e,n){mt(this.#r(Ro+e),JSON.stringify(n)),sessionStorage.removeItem(this.#r(Co+e)),this.#t(e,n)}loadCheckpoint(e){return this.#i(this.#r(Ks+e))}saveCheckpoint(e,n){let r=this.#r(Ks+e);if(n===null){sessionStorage.removeItem(r);return}mt(r,JSON.stringify(n))}clear(e){sessionStorage.removeItem(this.#r(Ro+e)),sessionStorage.removeItem(this.#r(Ks+e)),sessionStorage.removeItem(this.#r(Co+e)),this.#o(this.#n().filter(n=>n.threadId!==e)),sessionStorage.getItem(this.#r(yr))===e&&sessionStorage.removeItem(this.#r(yr))}listThreads(){let e=this.#n().sort((n,r)=>r.updatedAt-n.updatedAt).map(({threadId:n,title:r,updatedAt:o,preview:i})=>({threadId:n,title:r,updatedAt:o,preview:i}));return Promise.resolve(e)}setActiveThread(e){mt(this.#r(yr),e)}renameThread(e,n){let r=this.#n(),o=r.find(i=>i.threadId===e);o!==void 0&&(o.title=n,o.titleCustom=!0,this.#o(r))}#t(e,n){let r=this.#n(),o=r.find(s=>s.threadId===e),i=yR(n),a=Date.now();o===void 0?r.push({threadId:e,title:Xw(n),titleCustom:!1,preview:i,updatedAt:a}):(o.preview=i,o.updatedAt=a,o.titleCustom||(o.title=Xw(n))),this.#o(r)}#n(){return this.#i(this.#r(Zd))??[]}#o(e){let n=this.#r(Zd);if(e.length===0){sessionStorage.removeItem(n);return}mt(n,JSON.stringify(e))}#r(e){return`${this.#e}:${e}`}#i(e){let n=sessionStorage.getItem(e);if(n===null)return null;try{return JSON.parse(n)}catch{return null}}};function Kw(t){let e=[];for(let n=0;n<sessionStorage.length;n+=1){let r=sessionStorage.key(n);if(r===null||!r.startsWith(t))continue;let o=r.slice(t.length);bR(o)&&e.push([r,o])}return e}function bR(t){return t===yr||t===Zd||t.startsWith(Ro)||t.startsWith(Ks)||t.startsWith(Co)}function Xw(t){for(let e of t)if(e.role==="user"){let n=Jw(e.content);if(n!=="")return Qw(n,mR)}return vR}function yR(t){for(let e of[...t].reverse()){let n=Jw(e.content);if(n!=="")return Qw(n,gR)}return""}function Jw(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():""}function Qw(t,e){return t.length<=e?t:`${t.slice(0,e-1).trimEnd()}\u2026`}function Vd(t){let e=t.headers??{},n=new Set;return new Nb({url:t.endpoint,headers:e,initialState:{...t.initialState??{}},fetch:(r,o)=>{let i=t.getHeaders?.(),a=[...new Set([...Object.keys(e),...Object.keys(i??{})])].sort();if(ts(r,a,t.trustedOrigins??[],n),i===void 0)return fetch(r,it(o,t.credentials));let s=new Headers(o?.headers);for(let[c,l]of Object.entries(i))s.set(c,l);return fetch(r,it({...o,headers:s},t.credentials))},...t.threadId!==void 0?{threadId:t.threadId}:{},...t.initialMessages!==void 0?{initialMessages:[...t.initialMessages]}:{}})}function eE(t,e){let n=t.getAttribute(e);return n!==null&&n!=="false"}function jd(t,e){let n=t.getAttribute(e);if(n===null)return null;try{return JSON.parse(n)}catch{return console.warn(`<ag-ui-chat>: ${e} is not valid JSON, so it was ignored entirely and the built-in default is being used. Check the quoting -- JSON inside an HTML attribute needs single quotes around the attribute value, or its own double quotes escaped.`),null}}function tE(t){let e=t.getAttribute("data-max-tool-rounds");return e===null?Bn:Number.parseInt(e,10)}var No=class{#e;#t;#n;#o;#r;#i=new Set;#a=new Map;constructor(e,n=()=>({}),r=new rt,o=()=>{},i=!0){this.#e=e.endsWith("/")?e:`${e}/`,this.#t=n,this.#n=r,this.#o=o,this.#r=i}threadId(){return this.#n.threadId()}setActiveThread(e){this.#n.setActiveThread(e)}newThread(){return es(this.#n)}isUnsent(e){return this.#n.isUnsent?.(e)===!0}saveMessages(e,n){this.#n.saveMessages(e,this.#r?n:[])}loadCheckpoint(e){return this.#n.loadCheckpoint(e)}saveCheckpoint(e,n){this.#n.saveCheckpoint(e,n)}renameThread(e,n){this.#n.renameThread(e,n),this.#a.set(e,n),this.#f(e,"PATCH",{title:n})}clear(e){this.#n.clear(e),this.#i.add(e),this.#f(e,"DELETE")}async listThreads(){let e=await this.#s();return e===null?this.#n.listThreads():e.filter(n=>!this.#i.has(n.thread_id)).map(n=>this.#u(n))}async loadMessages(e){if(this.#n.isUnsent?.(e)===!0)return null;let n=await this.#d(`${this.#e}${encodeURIComponent(e)}/`);if(n===null||!n.ok)return this.#n.loadMessages(e);let r=await this.#l(n);return r===null?this.#n.loadMessages(e):r.messages??null}async#s(){let e=await this.#d(this.#e);if(e===null||!e.ok)return null;let n=await this.#l(e);return n===null?null:n.threads??[]}async#l(e){try{return await e.json()}catch{return null}}#u(e){return{threadId:e.thread_id,title:this.#a.get(e.thread_id)??e.title,updatedAt:e.updated_at===null?Number.NaN:Date.parse(e.updated_at),preview:e.preview}}async#d(e){try{return await fetch(e,it({headers:this.#t()},this.#o()))}catch{return null}}async#f(e,n,r){let o=this.#t();try{await fetch(`${this.#e}${encodeURIComponent(e)}/`,it({method:n,headers:r===void 0?o:{...o,"content-type":"application/json"},body:r===void 0?null:JSON.stringify(r)},this.#o()))}catch{}}};function nE(){return{tools:[],serverSettled:new Set,invalidated:new Set,announcedOutcome:!1}}function wR(t,e){let n={};for(let[r,o]of Object.entries(t))n[r]=(...i)=>{e()&&o(...i)};return n}var Xs=class{#e;#t=nE();constructor(e){this.#e=e}detach(){this.#t=nE()}forClient(e){let n=this.#t,r=()=>n===this.#t,{onSettled:o,...i}=this.#n(n);return{...wR(i,r),onSettled:()=>{r()&&o(),this.#o(n,e)}}}#n(e){return{onRunStart:()=>{this.#e.running()||(e.announcedOutcome=!1,this.#e.announcer.announce(this.#e.strings().announceResponding)),this.#e.setRunning(!0),this.#e.transcript.ensureGroup(),this.#e.transcript.showPending()},onReasoningStart:()=>{this.#e.transcript.hidePending(),this.#e.transcript.showThoughts()},onReasoningDelta:n=>{this.#e.transcript.showThoughts().stream(n)},onReasoningEnd:()=>{},onTextDelta:n=>{this.#e.transcript.hidePending(),this.#e.transcript.collapseThoughts(),this.#e.stream.queue(n),this.#e.stream.countDelta()},onTextEnd:(n,r)=>{if(n===""){this.#e.stream.end();return}let o=this.#e.stream.into(n);this.#e.stream.deltas<=1&&this.#e.transcript.revealWords(o),Gs(o,this.#e.strings()),this.#e.actions.attach(o,r),this.#e.stream.end(),this.#e.noteUnread()},onToolCall:n=>{this.#e.transcript.hidePending(),!this.#e.transcript.noticeIfSkillLoad(n)&&(e.tools.push({id:n.id,name:n.name}),this.#e.transcript.cardFor(n))},onActivity:(n,r,o)=>{this.#e.activities.draw(o,n,r)},onCustomEvent:(n,r)=>{if(n===Ll){this.#r(e,r);return}if(n===Ip){this.#e.subagents.report(r);return}this.#e.element.dispatchEvent(new CustomEvent(Nl,{detail:{name:n,value:r},bubbles:!0,composed:!0}))},onSubAgentStarted:(n,r,o)=>{this.#e.subagents.start(n,r,o)},onSubAgentFinished:n=>{this.#e.subagents.finish(n)},onSubAgentError:(n,r)=>{this.#e.subagents.fail(n,r)},onMessagesSnapshot:()=>{this.#e.transcript.appendNotice("\u{1F504}",this.#e.strings().historyReplaced,"history-replaced")},onToolResult:(n,r,o)=>{let i=this.#e.transcript.card(n);i!==void 0&&(i.settle(lo(o),r),this.#e.transcript.markServerSettled(n),e.serverSettled.add(n),this.#e.transcript.showPending())},onActivityChanged:(n,r,o)=>{this.#e.activities.draw(n,r,o)},onRunEnd:()=>{this.#e.transcript.hidePending(),this.#e.stream.end()},onError:n=>{e.announcedOutcome=!0,this.#e.announcer.announce(this.#e.strings().announceFailed),this.#e.transcript.hidePending();let r=this.#e.appendMessage(Ve.ASSISTANT,`\u26A0\uFE0F ${n}`);r.classList.add("message--failed"),this.#e.actions.attach(r,{rateable:!1}),this.#e.transcript.revealWords(r),this.#e.stream.end()},onCancelled:()=>{e.announcedOutcome=!0,this.#e.announcer.announce(this.#e.strings().announceStopped),this.#e.transcript.hidePending(),this.#e.transcript.appendStoppedNote(),this.#e.stream.end()},onSettled:()=>{e.announcedOutcome||this.#e.announcer.announce(this.#e.strings().announceAnswerReady),this.#e.transcript.hidePending(),this.#e.setRunning(!1),this.#e.stream.end();for(let n of this.#e.transcript.cards())n.settled||n.settle(K.INTERRUPTED,this.#e.strings().callNotFinished);this.#e.transcript.closeGroup()}}}#o(e,n){let r=e.tools.map(({id:i,name:a})=>({name:a,side:e.serverSettled.has(i)?"server":"client"})),o=[...e.invalidated];e.tools.length=0,e.serverSettled.clear(),e.invalidated.clear(),this.#e.element.dispatchEvent(new CustomEvent(Rl,{detail:{threadId:n,tools:r,invalidated:o},bubbles:!0,composed:!0}))}#r(e,n){let r=n??{},o=Array.isArray(r.keys)?r.keys.filter(i=>typeof i=="string"):[];if(o.length!==0){for(let i of o)e.invalidated.add(i);this.#e.element.dispatchEvent(new CustomEvent(Ol,{detail:{keys:o,reason:typeof r.reason=="string"?r.reason:null},bubbles:!0,composed:!0}))}}};var Wd=new Set,Js=class{#e;#t="";#n=null;#o="";#r="";#i=null;constructor(e){this.#e=e}claim(){this.#t=this.#a()}release(){this.#n!==null&&(Wd.delete(this.#n),this.#n=null)}conversationNamespace(e){return e===""?this.#t:`${this.#t}#${e}`}scopeStore(e,n){if(!(e instanceof rt))return e;let r=this.conversationNamespace(n);return this.#i=r===""?e:new rt(r),this.#i}rescopeStore(e,n){return e!==this.#i?null:(this.#i=new rt(n),this.#i)}key(e){return this.#t===""?e:`${e}:${this.#t}`}readScopedItem(e){let n=sessionStorage.getItem(this.key(e));return n!==null||this.#t===""?n:sessionStorage.getItem(e)}readPreference(e){try{let n=localStorage.getItem(this.key(e));if(n!==null)return n}catch{}return this.readScopedItem(e)}writePreference(e,n){let r=this.key(e);try{localStorage.setItem(r,n)}catch{}mt(r,n)}clearPreference(e){let n=this.key(e);try{localStorage.removeItem(n)}catch{}try{sessionStorage.removeItem(n)}catch{}}#a(){let e=this.#e.id(),n=e!==""?e:this.#e.endpoint();return n===""?"":this.#r===n?this.#o:Wd.has(n)?(this.#r=n,this.#o=`${n}~${Se()}`,console.warn(`<ag-ui-chat>: another element on this page already stores its conversation under "${n}", so this one has been given a throwaway namespace of its own \u2014 the two would otherwise share a thread pointer, a history drawer and every message. Give each <ag-ui-chat> its own id to keep them apart and let this one restore its conversation across reloads.`),this.#o):(Wd.add(n),this.#n=n,n)}};var ER=["data-attachments-url","data-attachment-accept","data-attachment-max-bytes","data-transcribe-url","data-threads-url","data-threads-cache","data-tools-url","data-skills-url","data-skills","data-prompt-chips","data-slash-commands","data-theme-toggle","data-strings","data-icon-url"],Yd=["omit","same-origin","include"];function qd(t){return Yd.includes(t)}var rE="ag-ui-chat:collapsed",oE="ag-ui-chat:theme",aE=["light","dark","auto"];function xR(t){return t.split(/\s+/).filter(e=>aE.includes(e)).at(-1)}function iE(t,e){return[...t.split(/\s+/).filter(r=>r!==""&&!aE.includes(r)),e].join(" ")}var Oo=class extends HTMLElement{agentFactory=Vd;headers={};getHeaders=null;trustedOrigins=[];allowImages=!1;formatRelativeTime=null;autoConfirm=!1;askUser=!1;askUserRenderer=null;approvalRenderer=null;approveWithEdits=!1;confirmPredicate=null;getTools=()=>this.#A.defaultTools();getContext=()=>[...Jl(this.getPageMap,this.autoInjectPageMap)];routeMap=[];navigate=null;getPageMap=null;autoInjectPageMap=!0;conversationStore=new rt;uploadHandler=null;transcribeHandler=null;navigationResult=()=>({navigated:!0,url:window.location.href});skillContext=()=>({});toolSummaries={};formatToolPayload=null;strings={};resolvePageTarget=e=>document.querySelector(e);#e=new Set;#t=fe;#n=new ks({card:e=>this.#v.card(e),strings:()=>this.#t,follow:()=>this.#v.follow()});#o=new Ws({ensureGroup:()=>this.#v.ensureGroup(),afterTranscriptGrew:()=>this.#v.afterGrew(),appendNotice:(e,n,r)=>this.#v.appendNotice(e,n,r)});#r=new Os({element:this,strings:()=>this.#t,retry:()=>{this.retryLastTurn()},threadId:()=>this.#h.threadId});#i;#a=null;#s=[];#l=new Ss;#u=document.createElement("button");#d;#f=document.createElement("div");#p;#m;#c;#b;#g;#y;#E;#_;#h;#N;#M;#B;#k;#Z;#I;#L;#V=document.createElement("span");#U=0;#z;#v;#j;#ie;#me=document.createElement("span");#R;#x;#Q=[];#H=[];#W=document.createElement("div");#O=null;#ge="";#F=()=>{this.#x.publishVisualViewport(),!this.#x.dragging()&&this.#x.restoreLauncherPosition()};#ae;#q;#C=!1;#ee=new AbortController;#ve=!1;#se=null;#Y={};#be={};#le=null;#P=null;#D={};#T=!1;#w=null;#ye=null;#we=null;#ce=new ws;#A=new os({element:this,routeMap:()=>this.routeMap,navigate:()=>this.navigate,getPageMap:()=>this.getPageMap,resolvePageTarget:e=>this.resolvePageTarget(e),getTools:()=>this.getTools(),askUser:()=>this.askUser,askUserRenderer:()=>this.askUserRenderer,decision:this.#ce,setAsking:(e,n)=>this.#v.setAsking(e,n),ensureGroup:()=>this.#v.ensureGroup(),strings:()=>this.#t,hidePending:()=>this.#v.hidePending(),updateEmptyState:()=>this.#v.updateEmptyState(),follow:()=>this.#v.follow(),fetchInit:e=>this.#Te(e)});#Ee=new Fs({openBubble:()=>this.appendMessage(Ve.ASSISTANT,""),allowImages:()=>this.allowImages,follow:()=>this.#v.follow()});#xe=new Zn(this);#S=new Js({id:()=>this.id,endpoint:()=>this.endpoint});#G;constructor(){super(),this.#i=this.attachShadow({mode:"open"}),this.#p=document.createElement("div"),this.#m=document.createElement("div"),this.#c=document.createElement("textarea"),this.#b=document.createElement("button"),this.#g=document.createElement("span"),this.#N=document.createElement("div"),this.#M=document.createElement("button"),this.#B=document.createElement("input"),this.#k=document.createElement("div"),this.#ae=document.createElement("span"),this.#Z=document.createElement("button"),this.#I=document.createElement("button"),this.#L=document.createElement("span"),this.#z=document.createElement("div"),this.#v=new js({element:this,messages:this.#m,emptyWrap:this.#z,strings:()=>this.#t,allowImages:()=>this.allowImages,resolveTool:e=>this.#A.resolve(e),toolSummaries:()=>this.toolSummaries,serverSummary:e=>this.#A.summary(e),toolDisplay:()=>this.toolDisplay,formatToolPayload:e=>this.formatToolPayload?.(e)??null}),this.#j=new ss({element:this,transcript:this.#v,tools:this.#A,decision:this.#ce,strings:()=>this.#t,announce:e=>this.#l.announce(e),autoConfirm:()=>this.autoConfirm,confirmPredicate:()=>this.confirmPredicate,getPageMap:()=>this.getPageMap,navigate:()=>this.navigate,approveWithEdits:()=>this.approveWithEdits,approvalRenderer:()=>this.approvalRenderer,getContext:()=>this.getContext(),conversationStore:()=>this.conversationStore,threadId:()=>this.#h.threadId,tenure:()=>this.#Y,conversation:()=>this.#be}),this.#ie=new Xs({element:this,transcript:this.#v,stream:this.#Ee,actions:this.#r,activities:this.#o,subagents:this.#n,announcer:this.#l,strings:()=>this.#t,running:()=>this.#T,setRunning:e=>this.#X(e),appendMessage:(e,n)=>this.appendMessage(e,n),noteUnread:()=>this.#Be()}),this.#x=new _s({element:this,launcher:this.#I,root:this.#i,connected:()=>this.#C,collapsed:()=>this.collapsed,collapsible:()=>Lt(this.getAttribute("placement")).collapseTo!==null,strings:()=>this.#t,readPreference:e=>this.#S.readPreference(e),writePreference:(e,n)=>this.#S.writePreference(e,n),clearPreference:e=>this.#S.clearPreference(e),announceSurfaceChange:(e,n)=>this.#$e(e,n)}),this.#d=new vs({element:this,root:this.#i,messages:this.#m,messagesWrap:this.#f,input:this.#c,strings:()=>this.#t,autoGrow:()=>Yt(this.#c),quote:e=>this.quote(e)}),this.#R=new hs({element:this,chat:this.#p,slot:this.#k,fileInput:this.#B,button:this.#M,strings:()=>this.#t,uploadHandler:()=>this.uploadHandler,headersFor:e=>this.#K(e),credentialsOption:()=>this.#de()}),this.#q=new ms({element:this,slot:this.#ae,input:this.#c,strings:()=>this.#t,transcribeHandler:()=>this.transcribeHandler,headersFor:e=>this.#K(e),credentialsOption:()=>this.#de(),onInput:()=>this.#pe()}),this.registerActivityRenderer({type:Dl,render:e=>{let n=_R(e);return n===null?null:Ts("\u{1F5DC}",re(this.#t.historyCompacted,{count:n}),"compaction")}}),this.registerActivityRenderer({type:Ml,render:e=>ko(e,this.#t,n=>{this.sendMessage(n)})}),this.#y=new gs(e=>this.#G.apply(e)),this.#G=new qo({element:this,menu:this.#y,input:this.#c,hint:this.#N,strings:()=>this.#t,context:()=>this.skillContext(),flag:e=>eE(this,e),readJsonAttribute:e=>jd(this,e),fetchInit:e=>this.#Te(e),send:e=>{this.sendMessage(e)},submit:()=>{this.#he()},autoGrow:()=>Yt(this.#c)}),this.#E=new ys({onSelect:e=>{this.#h.switchThread(e)},onNew:()=>{this.newChat(),this.#h.refreshDrawer()},onRename:(e,n)=>{this.#h.renameThread(e,n)},onDelete:e=>{this.#h.deleteThread(e)}}),this.#_=new ao((e,n)=>{this.#h.continueRun(e,n).catch(r=>{console.warn("<ag-ui-chat>: continuing a run failed",r)})}),this.#h=new bs({element:this,drawer:this.#E,checkpoints:this.#_,transcript:this.#v,actions:this.#r,activities:this.#o,tools:this.#A,input:this.#c,hint:this.#N,strings:()=>this.#t,conversationStore:()=>this.conversationStore,formatRelativeTime:()=>this.formatRelativeTime,navigationResult:()=>this.navigationResult,headersFor:e=>this.#K(e),requestCredentials:()=>this.#te(),appendMessage:(e,n)=>this.appendMessage(e,n),announceTurn:e=>this.#ze(e,[]),recordTurn:e=>this.#Le(e),autoGrow:()=>Yt(this.#c),continuationEnded:()=>this.#J(),client:()=>this.#P,ensureClient:()=>this.#fe(),buildClient:e=>this.#De(e),releaseClient:()=>{this.#P=null},running:()=>this.#T||this.#w!==null,holdRun:e=>{let n={};return this.#w=n,this.#ye=e===null?null:{hold:n,restored:e},{release:()=>{this.#w===n&&(this.#w=null,this.#J())}}},cancelRun:()=>this.#$(),resetState:()=>this.#ne(),setRunning:e=>this.#X(e),threadChanged:(e,n)=>this.#Me(e,n)})}static get observedAttributes(){return["title-text","placement","credentials","user-key","user-name",...ER]}attributeChangedCallback(e,n,r){if(e==="credentials"){r!==null&&!qd(r)&&console.error(`<ag-ui-chat>: credentials="${r}" is not a fetch credentials mode (${Yd.join(" / ")}) \u2014 it is being ignored, so requests use the browser default and cross-origin cookies will not be sent.`);return}if(e==="placement"){this.#x.releaseOwnedAxes(),this.#x.releaseLauncherPosition(),Lt(this.getAttribute("placement")).collapseTo===null&&this.collapsed&&this.setCollapsed(!1),requestAnimationFrame(()=>this.#x.syncResizeAnchor());return}if(e==="title-text"){this.#g.textContent=r??this.#t.title,this.#V.textContent=this.#g.textContent;return}if(e==="user-name"){this.#Se();return}if(e==="user-key"){this.#C&&(n??"")!==(r??"")&&this.#Ie(n??"",r??"");return}n===r||!this.#C||console.warn(`<ag-ui-chat>: "${e}" was changed after the element connected, and is read only while connecting \u2014 this assignment has no effect. Set it before the element enters the DOM (in the markup, or on the element before appending it); frameworks that patch attributes after mount should bind it at creation. To apply a new value now, remove and re-insert the element.`)}registerTool(e){this.#A.register(e)}get sharedState(){return this.#_e()?.state??this.#D}set sharedState(e){this.#D={...e},this.#_e()?.setState(this.#D)}#_e(){return this.#h.continuation??this.#P}registerPageState(e){this.#A.registerPageState(e)}registerStateHook(e){this.registerPageState(e)}get endpoint(){return this.getAttribute("endpoint")??""}set endpoint(e){this.setAttribute("endpoint",e)}get userKey(){return this.getAttribute("user-key")??""}set userKey(e){this.setAttribute("user-key",e)}get userName(){return this.getAttribute("user-name")??""}set userName(e){this.setAttribute("user-name",e)}#Se(){let e=this.userName.trim();this.#me.textContent=e===""?this.#t.greetingNoName:re(this.#t.greeting,{name:e})}get credentials(){let e=this.getAttribute("credentials");return e!==null&&qd(e)?e:null}set credentials(e){if(e===null){this.removeAttribute("credentials");return}if(!qd(e))throw new TypeError(`<ag-ui-chat>: credentials must be one of ${Yd.map(n=>`"${n}"`).join(", ")} (got ${JSON.stringify(e)}).`);this.setAttribute("credentials",e)}#ue(){return{...this.headers,...this.getHeaders?.()}}#K(e){let n=this.#ue();return ts(e,Object.keys(n),this.trustedOrigins,this.#e),n}#te(){return this.credentials??void 0}#de(){let e=this.#te();return e===void 0?{}:{credentials:e}}#Te(e){return it({headers:this.#K(e)},this.#te())}get toolDisplay(){let e=this.getAttribute("data-tool-display");return e===Ct.INLINE||e===Ct.MINIMAL||e===Ct.COMPACT||e===Ct.FULL?e:Ct.GROUPED}set toolDisplay(e){this.setAttribute("data-tool-display",e)}get extraStyles(){return this.#s}set extraStyles(e){this.#s=[...e],this.#a!==null&&(this.#i.adoptedStyleSheets=[this.#a,...this.#s])}connectedCallback(){if(this.#ee=new AbortController,this.#ve&&this.#Ne(),this.#ve=!0,this.#S.claim(),this.#xe.join(),this.#x.restoreSize(),requestAnimationFrame(()=>{this.#x.restoreLauncherPosition(),this.#x.syncResizeAnchor()}),this.#t=Xu({...this.#He(),...this.strings}),this.getAttribute("data-theme-toggle")!==null){let r=this.#S.readPreference(oE),o=r===null?void 0:xR(r);o!==void 0&&this.setAttribute("theme",iE(this.getAttribute("theme")??"",o))}this.#Ge(),this.#E.setStrings(this.#t),this.#_.setStrings(this.#t),Lt(this.getAttribute("placement")).collapseTo!==null&&this.#Fe()&&this.setAttribute("collapsed",""),this.#Pe(),this.#G.init();let e=this.#se,n=e!==null&&e!==this.userKey;n&&this.#Ie(e,this.userKey),this.#se=this.userKey,this.conversationStore=this.#S.scopeStore(this.#ke(),this.userKey),window.addEventListener("resize",this.#F),window.visualViewport?.addEventListener("resize",this.#F),window.visualViewport?.addEventListener("scroll",this.#F),this.#x.publishVisualViewport(),this.#Ae(),this.#R.wire(this.#ee.signal),this.#q.wire(),this.#h.adoptActiveThread(),queueMicrotask(()=>this.#Ue()),this.#h.rehydrate(n&&e!==""?"rescope":"restore"),n&&this.#h.refreshDrawer(),this.#C=!0}#Ue(){this.#C&&(this.#A.fetchCatalog(),this.#G.fetch())}async reload(){this.#$(),this.#ne(),this.#X(!1),await Promise.all([this.#A.fetchCatalog(),this.#G.fetch(),this.#h.rehydrate("restore")])}disconnectedCallback(){this.#C=!1,this.#ee.abort(),window.removeEventListener("resize",this.#F),window.visualViewport?.removeEventListener("resize",this.#F),window.visualViewport?.removeEventListener("scroll",this.#F),this.#S.release(),this.#xe.leave(),this.#$(),this.#d.detachPageOffer(),this.#R.tray?.dispose(),this.#q.dispose(),this.#v.disposeScroller(),this.#l.dispose()}#He(){let e=jd(this,"data-strings");return typeof e=="object"&&e!==null?e:{}}quote(e){this.#d.insert(e)}offerQuoteInPage(e=document.body){return this.#d.offerInPage(e)}#Ae(){this.#le=null;let e=this.getAttribute("data-threads-url");if(e!==null){let n=this.conversationStore,r=new No(e,()=>this.#K(e),n,()=>this.#te(),this.getAttribute("data-threads-cache")!=="false");this.#le={remote:r,inner:n},this.conversationStore=r}}#ke(){let e=this.#le;return e!==null&&this.conversationStore===e.remote?e.inner:this.conversationStore}setSkills(e){this.#G.setClientSkills(e)}get collapsed(){return this.hasAttribute("collapsed")}set collapsed(e){this.setCollapsed(e)}setCollapsed(e,n={}){e&&Lt(this.getAttribute("placement")).collapseTo===null||(n.announce===!0&&e&&!this.collapsed&&this.#$e(this.#t.chatMinimised,null),e||this.#x.restoreLauncherPosition(),e?this.setAttribute("collapsed",""):this.removeAttribute("collapsed"),mt(this.#S.key(rE),e?"1":"0"),this.#re(0),this.dispatchEvent(new CustomEvent(Tl,{detail:{collapsed:e},bubbles:!0,composed:!0})))}get unread(){return this.#U}get threadId(){let e=this.#h.threadId;return e===""?null:e}get running(){return this.#T}#Fe(){let e=this.#S.readScopedItem(rE);return e!==null?e==="1":Lt(this.getAttribute("placement")).startsCollapsed&&!this.hasAttribute("data-start-open")}describeSurface(){return this.#x.describeSurface()}moveTo(e,n={}){return this.#x.moveTo(e,n)}resetSize(){this.#x.resetSize()}toggleCollapsed(){this.setCollapsed(!this.collapsed)}toggleTheme(){let e=this.getAttribute("theme")??"",n=e.split(/\s+/).includes("dark")?"light":"dark";this.setAttribute("theme",iE(e,n)),this.#S.writePreference(oE,n),this.#Ce()}#Ie(e,n){this.#se=n;let r=this.#C,o=this.#S.conversationNamespace(e),i=this.#S.conversationNamespace(n);if(e===""){rt.adopt(o,i),r&&this.#Re(i);return}this.#Y={},rt.purge(o),r&&this.#Re(i),this.#j.forgetWaivers(),this.#$(),this.#ne(),this.#D={},this.#c.value="",this.#pe(),this.#X(!1),this.#re(0),r&&(this.#q.dispose(),this.#q.wire(),this.#h.adoptActiveThread(),this.#h.rehydrate("rescope"),this.#h.refreshDrawer())}#Re(e){let n=this.#S.rescopeStore(this.#ke(),e);n!==null&&(this.conversationStore=n,this.#Ae())}#Ce(){let e=(this.getAttribute("theme")??"").split(/\s+/).includes("dark");this.#Z.replaceChildren(fr("theme","theme-icon",e?Mp:Pp,null))}openThreads(){this.#h.openThreads()}openCheckpoints(){this.#h.openCheckpoints()}closeThreads(){this.#E.close()}closeCheckpoints(){this.#_.close()}async switchThread(e){this.#C&&await this.#h.switchThread(e)}deleteThread(e){this.#C&&this.#h.deleteThread(e)}toggleCheckpoints(){if(this.#_.open_){this.#_.close();return}this.openCheckpoints()}newChat(){this.#$(),this.#h.reapUnsent(),this.#ne(),this.#h.startThread(),this.#X(!1),this.#re(0),this.#Me(this.#h.threadId,"new"),this.collapsed||this.#c.focus({preventScroll:!0})}#ne(){this.#Ne(),this.#Q.length=0,this.#O=null}#Ne(){this.#P=null,this.#ie.detach(),this.#be={},this.#Oe(),this.#h.forgetRestored()}#Oe(){this.#Ee.end(),this.#v.releaseTurn(),this.#n.clear(),this.#v.forgetCards(),this.#o.clearBlocks(),this.#r.forget(),this.#R.tray?.clear(),this.removeAttribute("data-composer-settling"),this.removeAttribute("data-restoring"),this.#v.empty()}async retryLastTurn(){if(this.#T||this.#w!==null||this.#h.continuation!==null)return!1;let e={};this.#w=e;try{let n=this.#fe(),r=n.truncateToLastUser();if(r===null||this.#w!==e)return!1;this.#Oe();for(let o of r)if(this.#h.replay(o),this.#w!==e)return!1;return await n.resume(),!0}finally{this.#w===e&&(this.#w=null,this.#J())}}appendMessage(e,n){return this.#v.append(e,n)}#Ge(){let{signal:e}=this.#ee;this.#p.className="chat",this.#p.setAttribute("part","panel");let n=this.getAttribute("title-text")??this.#t.title,r=this.getAttribute("data-theme-toggle")!==null,{header:o,checkpoints:i}=Gy({host:this,title:this.#g,titleText:n,iconUrl:this.getAttribute("data-icon-url"),strings:this.#t,withCheckpoints:this.#h.runs()!==null,themeToggle:r?this.#Z:null,signal:e,onHistory:()=>this.openThreads(),onCheckpoints:()=>this.toggleCheckpoints(),onNewChat:()=>this.newChat(),onCollapse:()=>this.toggleCollapsed(),onToggleTheme:()=>this.toggleTheme()});r&&this.#Ce(),this.#x.enablePanelDrag(o),Fw({messages:this.#m,jumpButton:this.#u,emptyWrap:this.#z,greetingText:this.#me,starters:Bw(this,this.#t,u=>{this.sendMessage(u)}),strings:this.#t}),this.#Se(),this.#d.mount(e),this.#v.mountScroller(this.#u,e),this.#l.mount(),this.#m.append(this.#z),this.#v.updateEmptyState();let a=Ub({input:this.#c,send:this.#b,attachButton:this.#M,fileInput:this.#B,voiceSlot:this.#ae,hint:this.#N,queuedRow:this.#W,attachSlot:this.#k,strings:this.#t,signal:e,onKeydown:u=>this.#Ze(u),onInput:()=>this.#pe(),onSend:()=>{if(this.#T){this.#$();return}this.#he()},onFilesPicked:()=>this.#R.onFilesPicked()}),s=document.createElement("slot");s.name="above-composer";let c=document.createElement("slot");c.name="footer",this.#f.className="messages-wrap",this.#f.replaceChildren(this.#m,this.#u,this.#d.button),this.#p.replaceChildren(o,this.#f,this.#y.palette,this.#y.chips,this.#N,this.#W,this.#k,s,a,c,this.#E.element,this.#_.element),this.#p.addEventListener("pointerdown",u=>{if(!this.#_.open_)return;let f=u.composedPath();f.includes(this.#_.element)||f.includes(i)||this.#_.close()},{signal:e}),By({launcher:this.#I,badge:this.#L,railLabel:this.#V,titleText:n,iconUrl:Vy(this),strings:this.#t,signal:e,onOpen:()=>this.setCollapsed(!1)}),this.#x.enableLauncherDrag(e),this.#x.mountResizeGrips(this.#p),this.#a=Fy(this.#i,this.#s);let l=this.#x.probe;l.className="viewport-probe",l.setAttribute("aria-hidden","true"),this.#i.replaceChildren(l,this.#l.region,this.#p,this.#I)}#Pe(){this.#I.setAttribute("aria-expanded",String(!this.collapsed));let e=this.#U;this.#L.textContent=e>9?"9+":String(e),this.#L.hidden=e===0||!Zy(this);let n=this.#L.hidden?this.#t.expand:re(this.#t.expandUnread,{count:e});this.#I.setAttribute("aria-label",n),this.#I.title=n}#re(e){this.#U=e,this.#Pe(),this.dispatchEvent(new CustomEvent(Al,{detail:{unread:e},bubbles:!0,composed:!0}))}#Be(){this.collapsed&&this.#re(this.#U+1)}#pe(){this.#y.onInput(this.#c.value),this.#N.hidden=!0,Yt(this.#c),this.#O=null}#Ze(e){if(this.#y.onKeydown(e)){e.preventDefault();return}if(e.key==="Escape"&&this.#T){e.preventDefault(),this.#$();return}if(e.key==="Enter"&&!e.shiftKey){e.preventDefault(),this.#he();return}this.#Ve(e)}#Ve(e){let n=e.key==="ArrowUp";if(!n&&e.key!=="ArrowDown"||this.#y.isOpen())return;let r=this.#Q;if(r.length===0||(this.#c.value!==this.#ge&&(this.#O=null),this.#O===null&&(!n||this.#c.value!=="")))return;let o=this.#O===null?0:this.#O+(n?1:-1);o>=r.length||(e.preventDefault(),this.#O=o<0?null:o,this.#c.value=o<0?"":r[o],this.#ge=this.#c.value,this.#c.setSelectionRange(this.#c.value.length,this.#c.value.length),Yt(this.#c))}#$(){this.#H.length=0,this.#oe(),this.#ce.abort(),this.#P?.cancel(),this.#w=null,this.#h.stopContinuation()}#Me(e,n){let r={threadId:e,previousThreadId:this.#we,reason:n};this.#we=e,this.dispatchEvent(new CustomEvent(Cl,{detail:r,bubbles:!0,composed:!0}))}#X(e){let n=this.#T&&!e;this.#T=e,e&&(this.#w=null);let r=e?this.#t.stop:this.#t.send;this.#b.title=r,this.#b.setAttribute("aria-label",r),this.#b.dataset.state=e?"running":"idle",this.toggleAttribute("data-running",e),n&&this.#J()}#J(){if(this.#T||this.#h.continuation!==null)return;let e=this.#H.shift();this.#oe(),e!==void 0&&this.sendMessage(e)}#oe(){this.#W.replaceChildren(),this.#W.hidden=this.#H.length===0;for(let[e,n]of this.#H.entries()){let r=document.createElement("button");r.type="button",r.className="queued-chip",r.setAttribute("part","queued-chip"),r.textContent=n,r.title=re(this.#t.removeQueued,{text:n}),r.setAttribute("aria-label",r.title),r.addEventListener("click",()=>{this.#H.splice(e,1),this.#oe()}),this.#W.appendChild(r)}}#Le(e){e!==""&&this.#Q[0]!==e&&this.#Q.unshift(e),this.#O=null}async#he(){let e=this.#c.value.trim(),n=this.#R.tray?.readyRefs()??[];if(!(e===""&&n.length===0)){if(this.#Le(e),this.#T||this.#w!==null||this.#h.continuation!==null){e!==""&&(this.#H.push(e),this.#oe(),this.#c.value="",Yt(this.#c));return}this.#c.value="",Yt(this.#c),this.#R.tray?.hasPending()===!0&&this.#v.appendNotice("\u{1F4CE}",re(this.#t.attachmentsStillUploading,{n:this.#R.tray.pendingCount()}),"attachment-pending"),this.#R.tray?.clearReady(),await this.sendMessage(e,n)}}async sendMessage(e,n=[]){if(e===""&&n.length===0)return!1;let r=this.#ye;if(r!==null&&this.#w===r.hold){let i={};return this.#w=i,await r.restored,this.#w!==i?!1:(this.#w=null,this.sendMessage(e,n))}if(this.#T||this.#w!==null||this.#h.continuation!==null)return!1;let o={};this.#w=o;try{if(this.#v.isEmpty()&&this.setAttribute("data-composer-settling",""),this.#ze(e,n),this.#w!==o)return!1;let i=this.endpoint!=="";return await this.#je(e,n),i}finally{this.#w===o&&(this.#w=null,this.#J())}}#ze(e,n){let r=this.appendMessage(Ve.USER,e);n.length>0&&r.appendChild(us(n)),this.dispatchEvent(new CustomEvent(Sl,{detail:{content:e,attachments:n},bubbles:!0,composed:!0}))}attachFile(e){return this.#R.attach(e)}async#je(e,n){if(this.endpoint===""){console.error('<ag-ui-chat>: no endpoint is set, so this message was not sent and no request was made. Point the element at your AG-UI mount with the endpoint attribute (endpoint="/agent/"), or assign chat.endpoint before sending.'),this.#v.appendNotice("\u26A0",this.#t.notConnected,"not-connected");return}await this.#fe().send(e,n)}#fe(){return this.#P===null&&(this.#P=this.#De({endpoint:this.endpoint,initialMessages:this.#h.restored,follows:[]})),this.#P}#De(e){let n=this.#h.threadId,r=this.#Y,o=this.agentFactory({endpoint:e.endpoint,headers:this.#ue(),getHeaders:()=>this.#ue(),trustedOrigins:this.trustedOrigins,...this.#de(),threadId:n,initialMessages:e.initialMessages,initialState:this.#D});return new Io({agent:o,handlers:this.#ie.forClient(n),getTools:()=>this.#A.advertise(),getContext:()=>this.#j.buildContext(),executeTool:i=>this.#j.execute(i),resolveInterrupts:i=>this.#j.resolveInterrupts(i),onPersist:i=>{if(r!==this.#Y)return;let a=[...e.follows,...i];this.conversationStore.saveMessages(n,a),e.onSaved?.(a)},onStateChanged:i=>{r===this.#Y&&this.#We(i)},connectionLostMessage:this.#t.connectionLost,unfinishedMessage:this.#t.callNotFinished,declinedMessage:this.#t.declinedAction,maxToolRounds:tE(this)})}#We(e){this.#D={...e},this.dispatchEvent(new CustomEvent(kl,{detail:{state:this.#D},bubbles:!0,composed:!0}))}#$e(e,n){this.#v.appendNotice("\u2922",e,"surface",n===null?void 0:{label:this.#t.undo,onActivate:n})}enableCharts(e=["tool","activity"]){let n=!this.#o.has(jo)&&!this.#A.has(ls);e.includes("activity")&&this.registerActivityRenderer({type:jo,render:r=>{let o=hr(r);return o===null?null:ro(o)},removedNotice:this.#t.chartUndrawable}),e.includes("tool")&&this.registerTool($b()),n&&this.isConnected&&this.reload()}registerActivityRenderer(e){this.#o.register(e)}get unhandledActivityTypes(){return this.#o.unhandledTypes()}};function _R(t){let e=t?.removed;return typeof e=="number"?e:null}function SR(){customElements.get(Bo)===void 0&&customElements.define(Bo,Oo)}async function TR(t,e,n={}){await Nt(t),await Wl(t,{...n,flashMs:n.flashMs??0}),await Vl(t,e,n)}async function AR(t,e={}){await Nt(t),await jl(t,e)}async function kR(t,e={}){await Nt(t),await ql(t,e)}async function IR(t,e,n={}){await Nt(t),await Yl(t,e,n)}async function RR(t,e,n={}){await Nt(t),await Kl(t,e,n)}function CR(t,e){t instanceof HTMLInputElement&&t.type==="checkbox"?Rr(t,!!e):sn(t,String(e)),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0}))}var NR="0.47.0";export{Il as ATTACHMENT_EVENT,Oo as AgUiChat,Io as AgUiClient,jo as CHART_ACTIVITY_TYPE,ls as CHART_TOOL_NAME,Yo as CHAT_CORNERS,Dl as COMPACTION_ACTIVITY_TYPE,Nl as CUSTOM_AGENT_EVENT,ao as CheckpointMenu,kr as ClientToolRegistry,qs as ConnectionLostError,fe as DEFAULT_UI_STRINGS,Bo as ELEMENT_TAG,Pl as FEEDBACK_EVENT,Ll as INVALIDATE_CUSTOM_NAME,Ol as INVALIDATE_EVENT,$l as LOAD_CAPABILITY_TOOL,NA as MAX_QUOTE_CHARS,iR as MAX_SUGGESTIONS,aR as MAX_SUGGESTION_CHARS,Bn as MAX_TOOL_ROUNDS,rn as MESSAGE_ACTIONS,Ve as MESSAGE_ROLE,Nr as PAGE_ACTIONS,Rl as RUN_FINISHED_EVENT,No as RemoteConversationStore,so as RunIndex,kl as STATE_EVENT,Sl as SUBMIT_EVENT,Ml as SUGGESTIONS_ACTIVITY_TYPE,rt as SessionStorageStore,Cl as THREAD_EVENT,Tl as TOGGLE_EVENT,K as TOOL_CALL_STATUS,Ct as TOOL_DISPLAY,je as TOOL_OUTCOME,mo as ToolCallCard,Al as UNREAD_EVENT,NR as VERSION,Zo as X_CONFIRM_KEY,Tr as X_DESTRUCTIVE_KEY,Ar as X_NAVIGATES_KEY,Pe as X_SUMMARY_KEY,ld as asQuote,bd as attachMessageActions,ud as attachQuoteOffer,hr as chartSpecFrom,AR as clickElement,Hl as createChatSurfaceTools,Vd as createHttpAgent,Xl as createPageActionTools,Jl as createPageMapContext,Jo as createPageStateTools,Ql as createRouteTools,cx as createStateHookTools,SR as defineAgUiChat,TR as fillField,ox as flash,Wl as focusWithFlash,jl as highlightThenClick,Wp as isChatCorner,rd as isDestructive,as as isNavigates,Xu as mergeUiStrings,Cs as messageActionBar,pd as messageAttachments,Qu as parseToolCatalog,Xo as prefersReducedMotion,kR as pressButton,ql as pressThenClick,Bd as prettifyToolName,oo as quotableSelection,io as relativeTime,ro as renderChart,Ao as renderMarkdown,ko as renderSuggestionChips,ed as requestApproval,nd as requestConfirmation,Ju as requestQuestion,Nt as scrollIntoCenterView,IR as selectControl,Yl as selectOption,CR as setControlValue,Rr as setNativeChecked,sn as setNativeValue,Bl as showHighlightOverlay,Gw as suggestionPrompts,RR as toggleCheckbox,Kl as toggleControl,lo as toolStatusFromOutcome,sd as transcribeAudio,Vl as typeInto,id as uploadAttachment};
|
|
4591
4833
|
/*! Bundled license information:
|
|
4592
4834
|
|
|
4593
4835
|
fast-json-patch/module/helpers.mjs:
|